From 6baea5aaaaed37773f85cb93426599e6ef4b5d46 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 29 Aug 2026 01:24:29 +0300 Subject: [PATCH 01/88] version bump --- build/next-release.txt | 2 +- configure.ac | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/next-release.txt b/build/next-release.txt index 6953c91a73..7f4e7278ae 100644 --- a/build/next-release.txt +++ b/build/next-release.txt @@ -1 +1 @@ -1.11.3-dev +1.11.4-dev diff --git a/configure.ac b/configure.ac index f241153aab..ae42b22f6f 100644 --- a/configure.ac +++ b/configure.ac @@ -3,10 +3,10 @@ # Must change all of the below together # For a release, set revision for that tagged release as well and uncomment -AC_INIT([freeswitch], [1.11.3-dev], bugs@freeswitch.org) +AC_INIT([freeswitch], [1.11.4-dev], bugs@freeswitch.org) AC_SUBST(SWITCH_VERSION_MAJOR, [1]) AC_SUBST(SWITCH_VERSION_MINOR, [11]) -AC_SUBST(SWITCH_VERSION_MICRO, [3-dev]) +AC_SUBST(SWITCH_VERSION_MICRO, [4-dev]) AC_SUBST(SWITCH_VERSION_REVISION, []) AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, []) From 33f9f4db7c7d7c35d51244b8bfecbfa3ab2b2ce4 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 4 Sep 2026 00:12:07 +0300 Subject: [PATCH 02/88] [Build-System] Update expired Certificate Thumbprint on Windows. (#3144) --- w32/Setup/Setup.2017.wixproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/w32/Setup/Setup.2017.wixproj b/w32/Setup/Setup.2017.wixproj index 9340448182..ee7ea91c97 100644 --- a/w32/Setup/Setup.2017.wixproj +++ b/w32/Setup/Setup.2017.wixproj @@ -13,7 +13,7 @@ 2.0 FreeSWITCH Package - 076ce3c57198fc39443bd87f4aab86dac0aab62d + e0dad9125302803aa4fe4ba2fdf9edeb99a42ea9 http://timestamp.comodoca.com $(WindowsSDK80Path)bin\x86\signtool.exe $(WindowsSDK80Path)bin\x64\signtool.exe From 4fa2630a5bf45b6164aa0989ae5f835cf6038b82 Mon Sep 17 00:00:00 2001 From: Calvin Ellison <32909984+celliso1@users.noreply.github.com> Date: Fri, 4 Sep 2026 09:43:23 -0700 Subject: [PATCH 03/88] [Core] Avoid O(n^2) header dedup when cloning EF_UNIQ_HEADERS events (#3061) * events: avoid O(n^2) header dedup when cloning EF_UNIQ_HEADERS events switch_event_dup() copies a source event header by header via switch_event_add_header_string(). When the source carries EF_UNIQ_HEADERS (SWITCH_EVENT_CHANNEL_DATA / REQUEST_PARAMS / MESSAGE -- e.g. a channel's variable list), the destination inherits the flag, so switch_event_base_add_header() runs a full switch_event_del_header() linear scan of the partially-built list on every add to enforce uniqueness. Cloning an N-header event is therefore O(n^2). That scan is redundant while cloning: the source already enforced uniqueness on insert, so copying it cannot introduce duplicates regardless of the per-add scan. Clear EF_UNIQ_HEADERS on the destination for the duration of the copy loop, then restore it. This is a hot path. switch_channel_execute_on() -- invoked on ring, answer, media, transfer, park, record and playback -- calls switch_core_get_variables() and switch_channel_get_variables(), each of which dup()s an EF_UNIQ_HEADERS event. On a production voicemail server carrying ~191 channel variables per call, switch_event_del_header_val() accounted for 47-69% of all FreeSWITCH CPU time in on-box perf profiles. Microbenchmark (tests/unit/switch_event.c, switch_event_dup of an N-header CHANNEL_DATA event, 4000 iterations, time per dup): N before after 50 4.80 us 3.19 us 100 11.34 us 5.88 us 191 28.29 us 10.99 us (2.6x) 400 107.05 us 23.27 us (4.6x) "before" scales ~O(n^2); "after" is linear. Behaviour is unchanged: the clone has identical headers, values and order, keeps EF_UNIQ_HEADERS, and still enforces uniqueness on subsequent adds (covered by the test). Signed-off-by: Calvin Ellison * tests: cover switch_event_dup uniqueness and add a dup benchmark Adds a dup_uniq_bench case to the switch_event unit test. For an EF_UNIQ_HEADERS (CHANNEL_DATA) source event it verifies the clone preserves header count, values and the EF_UNIQ_HEADERS flag, and that re-setting an existing key does not produce a duplicate in the clone. It also prints a switch_event_dup timing sweep across header counts, used to validate the O(n^2) -> O(n) change in switch_event_dup(). Signed-off-by: Calvin Ellison * tests: add dup_faithful_copy regression for switch_event_dup Covers the EF_UNIQ_HEADERS edge case for the O(n^2)->O(n) dup change: a well-formed EF_UNIQ source stays unique through dup, and a malformed source already holding duplicate names (only possible if headers were added before the flag was set) is copied faithfully rather than silently collapsed to the last value. Signed-off-by: Calvin Ellison * tests: gate dup_uniq_bench behind #ifdef BENCHMARK The dup_uniq_bench timing sweep is a benchmark rather than a pass/fail correctness test. Guard the whole test with #ifdef BENCHMARK (matching the existing benchmark in this file) so it stays out of normal test runs; dup_faithful_copy continues to cover correctness of the switch_event_dup change. Signed-off-by: Calvin Ellison * switch_event: clarify EF_UNIQ_HEADERS dup comment, brace one-line test loops Address review feedback on the switch_event_dup change: - src/switch_event.c: the fast-path comment claimed todup's headers are "already unique" unconditionally. That only holds when EF_UNIQ_HEADERS is set (names are deduped on insert); reword to scope the claim to that case and to the verbatim-copy intent. - tests/unit/switch_event.c: expand one-line loops to braced form per the SignalWire coding guidelines. Signed-off-by: Calvin Ellison --------- Signed-off-by: Calvin Ellison Co-authored-by: Calvin Ellison --- src/switch_event.c | 18 +++++ tests/unit/switch_event.c | 154 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) diff --git a/src/switch_event.c b/src/switch_event.c index 9d8907d09a..701bda2325 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -1335,6 +1335,7 @@ SWITCH_DECLARE(void) switch_event_merge(switch_event_t *event, switch_event_t *t SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_event_t *todup) { switch_event_header_t *hp; + int restore_uniq_headers = 0; if (switch_event_create_subclass(event, SWITCH_EVENT_CLONE, todup->subclass_name) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_GENERR; @@ -1344,6 +1345,19 @@ SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_ (*event)->event_user_data = todup->event_user_data; (*event)->bind_user_data = todup->bind_user_data; (*event)->flags = todup->flags; + + /* The destination inherited todup's flags above. When EF_UNIQ_HEADERS is set, + * switch_event_base_add_header() rescans the partial header list on every add + * to keep names unique, making this copy loop O(n^2). A clone should reproduce + * todup's list verbatim rather than run a fresh uniqueness pass, and a + * well-formed EF_UNIQ_HEADERS source is already unique (its names were deduped + * on insert), so that scan only adds cost here. Suppress it for the copy, then + * restore the flag so later adds enforce uniqueness again. */ + if (switch_test_flag((*event), EF_UNIQ_HEADERS)) { + switch_clear_flag((*event), EF_UNIQ_HEADERS); + restore_uniq_headers = 1; + } + for (hp = todup->headers; hp; hp = hp->next) { if (todup->subclass_name && !strcmp(hp->name, "Event-Subclass")) { continue; @@ -1359,6 +1373,10 @@ SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_ } } + if (restore_uniq_headers) { + switch_set_flag((*event), EF_UNIQ_HEADERS); + } + if (todup->body) { (*event)->body = DUP(todup->body); } diff --git a/tests/unit/switch_event.c b/tests/unit/switch_event.c index 4ee17d5eb8..0268d5762b 100644 --- a/tests/unit/switch_event.c +++ b/tests/unit/switch_event.c @@ -161,6 +161,160 @@ FST_TEST_BEGIN(expand_headers_offset) } FST_TEST_END() +#ifdef BENCHMARK +FST_TEST_BEGIN(dup_uniq_bench) +{ + switch_event_t *src = NULL, *dup = NULL; + switch_status_t status; + const int loops = 4000; + const int Ns[4] = {50, 100, 191, 400}; + int i, j, count, k, S, Nv; + char name[32], val[64]; + switch_event_header_t *hp; + switch_time_t start_ts, end_ts; + double per_us; + + /* A channel's variables are a SWITCH_EVENT_CHANNEL_DATA event => EF_UNIQ_HEADERS. + * switch_event_create() also adds the standard event headers, so the source + * count is (191 added + standard); assert relative to the actual source count. */ + status = switch_event_create(&src, SWITCH_EVENT_CHANNEL_DATA); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "create CHANNEL_DATA event"); + fst_xcheck(switch_test_flag(src, EF_UNIQ_HEADERS) != 0, "CHANNEL_DATA event is EF_UNIQ_HEADERS"); + + for (i = 0; i < 191; i++) { + switch_snprintf(name, sizeof(name), "var_%d", i); + switch_snprintf(val, sizeof(val), "value_%d_some_padding_payload", i); + switch_event_add_header_string(src, SWITCH_STACK_BOTTOM, name, val); + } + S = 0; + for (hp = src->headers; hp; hp = hp->next) { + S++; + } + fst_xcheck(S >= 191, "source has at least the 191 added headers"); + + /* correctness: dup preserves header count, the uniq flag, and values */ + status = switch_event_dup(&dup, src); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "dup ok"); + count = 0; + for (hp = dup->headers; hp; hp = hp->next) { + count++; + } + fst_xcheck(count == S, "dup header count equals source"); + fst_xcheck(switch_test_flag(dup, EF_UNIQ_HEADERS) != 0, "dup keeps EF_UNIQ_HEADERS"); + fst_check_string_equals(switch_event_get_header(dup, "var_0"), "value_0_some_padding_payload"); + fst_check_string_equals(switch_event_get_header(dup, "var_190"), "value_190_some_padding_payload"); + switch_event_destroy(&dup); + + /* correctness: uniqueness preserved (re-setting a key must not duplicate it in the dup) */ + switch_event_add_header_string(src, SWITCH_STACK_BOTTOM, "var_0", "REPLACED"); + status = switch_event_dup(&dup, src); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "dup ok (2)"); + k = 0; + for (hp = dup->headers; hp; hp = hp->next) { + if (!strcmp(hp->name, "var_0")) { + k++; + } + } + fst_xcheck(k == 1, "var_0 present exactly once after re-set + dup"); + fst_check_string_equals(switch_event_get_header(dup, "var_0"), "REPLACED"); + switch_event_destroy(&dup); + switch_event_destroy(&src); + + /* timing sweep: dup cost vs header count (baseline ~O(n^2), patched ~O(n)) */ + for (j = 0; j < 4; j++) { + Nv = Ns[j]; + switch_event_create(&src, SWITCH_EVENT_CHANNEL_DATA); + for (i = 0; i < Nv; i++) { + switch_snprintf(name, sizeof(name), "var_%d", i); + switch_snprintf(val, sizeof(val), "value_%d_some_padding_payload", i); + switch_event_add_header_string(src, SWITCH_STACK_BOTTOM, name, val); + } + start_ts = switch_time_now(); + for (i = 0; i < loops; i++) { + switch_event_dup(&dup, src); + switch_event_destroy(&dup); + } + end_ts = switch_time_now(); + per_us = (double)(end_ts - start_ts) / (double)loops; + printf("DUP_BENCH N=%d loops=%d total=%" SWITCH_UINT64_T_FMT "us per_dup=%.3f us\n", + Nv, loops, (uint64_t)(end_ts - start_ts), per_us); + switch_event_destroy(&src); + } +} +FST_TEST_END() +#endif /* BENCHMARK */ + +FST_TEST_BEGIN(dup_faithful_copy) +{ + /* Regression for the switch_event_dup O(n^2)->O(n) change (suppressing the + * per-add EF_UNIQ_HEADERS dedup scan while cloning). dup must reproduce the + * source faithfully: + * (1) a well-formed EF_UNIQ source stays unique through dup (the real case); + * (2) a malformed source that already holds duplicate names (only possible + * if headers were added before EF_UNIQ_HEADERS was set) is copied + * faithfully -- dup PRESERVES the duplicates rather than silently + * collapsing to the last value. A dup-bearing EF_UNIQ event is already + * a bug upstream of here; a copy must not silently drop data. */ + switch_event_t *src = NULL, *dup = NULL; + switch_event_header_t *hp; + switch_status_t status; + int n; + + /* (1) well-formed EF_UNIQ source -> unique dup */ + status = switch_event_create(&src, SWITCH_EVENT_CHANNEL_DATA); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "create CHANNEL_DATA"); + fst_xcheck(switch_test_flag(src, EF_UNIQ_HEADERS) != 0, "CHANNEL_DATA is EF_UNIQ"); + switch_event_add_header_string(src, SWITCH_STACK_BOTTOM, "k", "v1"); + switch_event_add_header_string(src, SWITCH_STACK_BOTTOM, "k", "v2"); + n = 0; + for (hp = src->headers; hp; hp = hp->next) { + if (!strcmp(hp->name, "k")) { + n++; + } + } + fst_xcheck(n == 1, "EF_UNIQ source keeps 'k' unique (collapsed to last)"); + status = switch_event_dup(&dup, src); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "dup ok (unique)"); + n = 0; + for (hp = dup->headers; hp; hp = hp->next) { + if (!strcmp(hp->name, "k")) { + n++; + } + } + fst_xcheck(n == 1, "dup of unique source stays unique"); + fst_check_string_equals(switch_event_get_header(dup, "k"), "v2"); + switch_event_destroy(&dup); + switch_event_destroy(&src); + + /* (2) malformed source (duplicate names under EF_UNIQ) -> faithful copy */ + status = switch_event_create(&src, SWITCH_EVENT_GENERAL); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "create GENERAL"); + fst_xcheck(switch_test_flag(src, EF_UNIQ_HEADERS) == 0, "GENERAL is not EF_UNIQ"); + switch_event_add_header_string(src, SWITCH_STACK_BOTTOM, "dupkey", "first"); + switch_event_add_header_string(src, SWITCH_STACK_BOTTOM, "dupkey", "second"); + switch_set_flag(src, EF_UNIQ_HEADERS); + n = 0; + for (hp = src->headers; hp; hp = hp->next) { + if (!strcmp(hp->name, "dupkey")) { + n++; + } + } + fst_xcheck(n == 2, "malformed source holds 2 'dupkey' headers"); + status = switch_event_dup(&dup, src); + fst_xcheck(status == SWITCH_STATUS_SUCCESS, "dup ok (malformed)"); + fst_xcheck(switch_test_flag(dup, EF_UNIQ_HEADERS) != 0, "dup keeps EF_UNIQ flag"); + n = 0; + for (hp = dup->headers; hp; hp = hp->next) { + if (!strcmp(hp->name, "dupkey")) { + n++; + } + } + fst_xcheck(n == 2, "dup faithfully preserves both 'dupkey' headers (no silent collapse)"); + switch_event_destroy(&dup); + switch_event_destroy(&src); +} +FST_TEST_END() + FST_SUITE_END() FST_MINCORE_END() From e6d261c069f8e962243fe0bfdd8ed309bf10cd06 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 9 Sep 2026 01:33:47 +0300 Subject: [PATCH 04/88] [mod_opus] Windows: update opus library to v1.5.2 and use pre-compiled binaries (#3149) --- Freeswitch.2017.sln | 78 ----- libs/.gitignore | 1 + libs/win32/opus/opus.2017.vcxproj | 255 -------------- libs/win32/opus/opus.celt.2017.vcxproj | 258 --------------- libs/win32/opus/opus.silk_common.2017.vcxproj | 313 ------------------ libs/win32/opus/opus.silk_fixed.2017.vcxproj | 205 ------------ libs/win32/opus/opus.silk_float.2017.vcxproj | 253 -------------- src/mod/codecs/mod_opus/mod_opus.2017.vcxproj | 26 +- w32/download_opus.props | 40 --- w32/opus-version.props | 19 ++ w32/opus.props | 85 +++++ 11 files changed, 110 insertions(+), 1423 deletions(-) delete mode 100644 libs/win32/opus/opus.2017.vcxproj delete mode 100644 libs/win32/opus/opus.celt.2017.vcxproj delete mode 100644 libs/win32/opus/opus.silk_common.2017.vcxproj delete mode 100644 libs/win32/opus/opus.silk_fixed.2017.vcxproj delete mode 100644 libs/win32/opus/opus.silk_float.2017.vcxproj delete mode 100644 w32/download_opus.props create mode 100644 w32/opus-version.props create mode 100644 w32/opus.props diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index 3d67ec12c2..5efcf1dd3a 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -428,18 +428,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_math_fixed_tables", "l EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_cielab_luts", "libs\win32\spandsp\make_cielab_luts.2017.vcxproj", "{85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "opus", "opus", "{ED2CA8B5-8E91-4296-A120-02BB0B674652}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opus", "libs\win32\opus\opus.2017.vcxproj", "{FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opus.celt", "libs\win32\opus\opus.celt.2017.vcxproj", "{245603E3-F580-41A5-9632-B25FE3372CBF}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opus.silk_common", "libs\win32\opus\opus.silk_common.2017.vcxproj", "{C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opus.silk_fixed", "libs\win32\opus\opus.silk_fixed.2017.vcxproj", "{8484C90D-1561-402F-A91D-2DB10F8C5171}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opus.silk_float", "libs\win32\opus\opus.silk_float.2017.vcxproj", "{9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_opus", "src\mod\codecs\mod_opus\mod_opus.2017.vcxproj", "{64E99CCA-3C6F-4AEB-9FA3-CFAC711257BB}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_t43_gray_code_tables", "libs\win32\spandsp\make_t43_gray_code_tables.2017.vcxproj", "{EDDB8AB9-C53E-44C0-A620-0E86C2CBD5D5}" @@ -1831,66 +1819,6 @@ Global {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|Win32.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64.Build.0 = All|Win32 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.All|Win32.ActiveCfg = Release|Win32 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.All|Win32.Build.0 = Release|Win32 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.All|x64.ActiveCfg = Release|x64 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.All|x64.Build.0 = Release|x64 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.Debug|Win32.ActiveCfg = Debug|Win32 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.Debug|Win32.Build.0 = Debug|Win32 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.Debug|x64.ActiveCfg = Debug|x64 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.Debug|x64.Build.0 = Debug|x64 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.Release|Win32.ActiveCfg = Release|Win32 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.Release|Win32.Build.0 = Release|Win32 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.Release|x64.ActiveCfg = Release|x64 - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E}.Release|x64.Build.0 = Release|x64 - {245603E3-F580-41A5-9632-B25FE3372CBF}.All|Win32.ActiveCfg = Release|Win32 - {245603E3-F580-41A5-9632-B25FE3372CBF}.All|Win32.Build.0 = Release|Win32 - {245603E3-F580-41A5-9632-B25FE3372CBF}.All|x64.ActiveCfg = Release|x64 - {245603E3-F580-41A5-9632-B25FE3372CBF}.All|x64.Build.0 = Release|x64 - {245603E3-F580-41A5-9632-B25FE3372CBF}.Debug|Win32.ActiveCfg = Debug|Win32 - {245603E3-F580-41A5-9632-B25FE3372CBF}.Debug|Win32.Build.0 = Debug|Win32 - {245603E3-F580-41A5-9632-B25FE3372CBF}.Debug|x64.ActiveCfg = Debug|x64 - {245603E3-F580-41A5-9632-B25FE3372CBF}.Debug|x64.Build.0 = Debug|x64 - {245603E3-F580-41A5-9632-B25FE3372CBF}.Release|Win32.ActiveCfg = Release|Win32 - {245603E3-F580-41A5-9632-B25FE3372CBF}.Release|Win32.Build.0 = Release|Win32 - {245603E3-F580-41A5-9632-B25FE3372CBF}.Release|x64.ActiveCfg = Release|x64 - {245603E3-F580-41A5-9632-B25FE3372CBF}.Release|x64.Build.0 = Release|x64 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.All|Win32.ActiveCfg = Release|Win32 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.All|Win32.Build.0 = Release|Win32 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.All|x64.ActiveCfg = Release|x64 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.All|x64.Build.0 = Release|x64 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.Debug|Win32.ActiveCfg = Debug|Win32 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.Debug|Win32.Build.0 = Debug|Win32 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.Debug|x64.ActiveCfg = Debug|x64 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.Debug|x64.Build.0 = Debug|x64 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.Release|Win32.ActiveCfg = Release|Win32 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.Release|Win32.Build.0 = Release|Win32 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.Release|x64.ActiveCfg = Release|x64 - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16}.Release|x64.Build.0 = Release|x64 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.All|Win32.ActiveCfg = Release|Win32 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.All|Win32.Build.0 = Release|Win32 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.All|x64.ActiveCfg = Release|x64 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.All|x64.Build.0 = Release|x64 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.Debug|Win32.ActiveCfg = Debug|Win32 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.Debug|Win32.Build.0 = Debug|Win32 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.Debug|x64.ActiveCfg = Debug|x64 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.Debug|x64.Build.0 = Debug|x64 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.Release|Win32.ActiveCfg = Release|Win32 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.Release|Win32.Build.0 = Release|Win32 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.Release|x64.ActiveCfg = Release|x64 - {8484C90D-1561-402F-A91D-2DB10F8C5171}.Release|x64.Build.0 = Release|x64 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.All|Win32.ActiveCfg = Release|Win32 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.All|Win32.Build.0 = Release|Win32 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.All|x64.ActiveCfg = Release|x64 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.All|x64.Build.0 = Release|x64 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.Debug|Win32.ActiveCfg = Debug|Win32 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.Debug|Win32.Build.0 = Debug|Win32 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.Debug|x64.ActiveCfg = Debug|x64 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.Debug|x64.Build.0 = Debug|x64 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.Release|Win32.ActiveCfg = Release|Win32 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.Release|Win32.Build.0 = Release|Win32 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.Release|x64.ActiveCfg = Release|x64 - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782}.Release|x64.Build.0 = Release|x64 {64E99CCA-3C6F-4AEB-9FA3-CFAC711257BB}.All|Win32.ActiveCfg = Release|Win32 {64E99CCA-3C6F-4AEB-9FA3-CFAC711257BB}.All|Win32.Build.0 = Release|Win32 {64E99CCA-3C6F-4AEB-9FA3-CFAC711257BB}.All|x64.ActiveCfg = Release|x64 @@ -2511,12 +2439,6 @@ Global {B535402E-38D2-4D54-8360-423ACBD17192} = {9DE35039-A8F6-4FBF-B1B6-EB527F802411} {2386B892-35F5-46CF-A0F0-10394D2FBF9B} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} - {ED2CA8B5-8E91-4296-A120-02BB0B674652} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E} = {ED2CA8B5-8E91-4296-A120-02BB0B674652} - {245603E3-F580-41A5-9632-B25FE3372CBF} = {ED2CA8B5-8E91-4296-A120-02BB0B674652} - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16} = {ED2CA8B5-8E91-4296-A120-02BB0B674652} - {8484C90D-1561-402F-A91D-2DB10F8C5171} = {ED2CA8B5-8E91-4296-A120-02BB0B674652} - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782} = {ED2CA8B5-8E91-4296-A120-02BB0B674652} {64E99CCA-3C6F-4AEB-9FA3-CFAC711257BB} = {F881ADA2-2F1A-4046-9FEB-191D9422D781} {EDDB8AB9-C53E-44C0-A620-0E86C2CBD5D5} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {5BA0D5BD-330D-4EE2-B959-CAFEA04E50E0} = {0C808854-54D1-4230-BFF5-77B5FD905000} diff --git a/libs/.gitignore b/libs/.gitignore index 48d9e2286b..06b712abd4 100644 --- a/libs/.gitignore +++ b/libs/.gitignore @@ -577,3 +577,4 @@ win32/spandsp/spandsp.h win32/spandsp/win32 libcodec2-* ffmpeg-* +opus-* diff --git a/libs/win32/opus/opus.2017.vcxproj b/libs/win32/opus/opus.2017.vcxproj deleted file mode 100644 index 92c222eb2d..0000000000 --- a/libs/win32/opus/opus.2017.vcxproj +++ /dev/null @@ -1,255 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - Win32Proj - opus - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E} - - - - StaticLibrary - true - $(DefaultPlatformToolset) - - - StaticLibrary - true - $(DefaultPlatformToolset) - - - false - StaticLibrary - true - $(DefaultPlatformToolset) - - - StaticLibrary - false - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - true - opus - $(Platform)\$(Configuration)\opus\ - - - true - opus - $(Platform)\$(Configuration)\opus\ - - - false - opus - $(Platform)\$(Configuration)\opus\ - - - false - - - opus - $(Platform)\$(Configuration)\opus\ - - - - _CRT_SECURE_NO_WARNINGS;HAVE_CONFIG_H;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk;..\..\opus-1.1\celt;..\..\opus-1.1\win32;..\..\opus-1.1\include;%(AdditionalIncludeDirectories) - MultiThreadedDebugDLL - Level3 - ProgramDatabase - Disabled - 4334;4244;%(DisableSpecificWarnings) - - - MachineX86 - true - Console - $(SolutionDir)$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories) - celt.lib;silk_common.lib;silk_fixed.lib;silk_float.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - _CRT_SECURE_NO_WARNINGS;HAVE_CONFIG_H;WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk;..\..\opus-1.1\celt;..\..\opus-1.1\win32;..\..\opus-1.1\include;%(AdditionalIncludeDirectories) - MultiThreadedDebugDLL - Level3 - ProgramDatabase - Disabled - 4334;4244;%(DisableSpecificWarnings) - - - true - Console - $(SolutionDir)$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories) - celt.lib;silk_common.lib;silk_fixed.lib;silk_float.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - _CRT_SECURE_NO_WARNINGS;HAVE_CONFIG_H;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk;..\..\opus-1.1\celt;..\..\opus-1.1\win32;..\..\opus-1.1\include;%(AdditionalIncludeDirectories) - MultiThreadedDLL - Level3 - ProgramDatabase - true - 4334;4244;%(DisableSpecificWarnings) - - - MachineX86 - false - Console - true - true - celt.lib;silk_common.lib;silk_fixed.lib;silk_float.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - $(SolutionDir)$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories) - false - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - _CRT_SECURE_NO_WARNINGS;HAVE_CONFIG_H;WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk;..\..\opus-1.1\celt;..\..\opus-1.1\win32;..\..\opus-1.1\include;%(AdditionalIncludeDirectories) - MultiThreadedDLL - Level3 - ProgramDatabase - 4334;4244;%(DisableSpecificWarnings) - - - false - Console - true - true - celt.lib;silk_common.lib;silk_fixed.lib;silk_float.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - $(SolutionDir)$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories) - false - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {245603e3-f580-41a5-9632-b25fe3372cbf} - - - {c303d2fc-ff97-49b8-9ddd-467b4c9a0b16} - - - {8484c90d-1561-402f-a91d-2db10f8c5171} - - - {9c4961d2-5ddb-40c7-9be8-ca918dc4e782} - - - - - - \ No newline at end of file diff --git a/libs/win32/opus/opus.celt.2017.vcxproj b/libs/win32/opus/opus.celt.2017.vcxproj deleted file mode 100644 index 34d0ed772a..0000000000 --- a/libs/win32/opus/opus.celt.2017.vcxproj +++ /dev/null @@ -1,258 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {245603E3-F580-41A5-9632-B25FE3372CBF} - Win32Proj - opus.celt - opus.celt - - - - StaticLibrary - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - celt - $(Platform)\$(Configuration)\opus.celt\ - - - - celt - $(Platform)\$(Configuration)\opus.celt\ - - - - celt - $(Platform)\$(Configuration)\opus.celt\ - - - celt - $(Platform)\$(Configuration)\opus.celt\ - - - - - - Level3 - Disabled - HAVE_CONFIG_H;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\win32;..\..\opus-1.1\include;%(AdditionalIncludeDirectories) - MultiThreadedDebugDLL - ProgramDatabase - - - Windows - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - - - Level3 - Disabled - HAVE_CONFIG_H;WIN32;WIN64;_DEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\win32;..\..\opus-1.1\include;%(AdditionalIncludeDirectories) - MultiThreadedDebugDLL - ProgramDatabase - - - Windows - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - Level3 - - - true - true - HAVE_CONFIG_H;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\win32;..\..\opus-1.1\include;%(AdditionalIncludeDirectories) - MultiThreadedDLL - - - Windows - true - true - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - Level3 - - - MaxSpeed - true - true - HAVE_CONFIG_H;WIN32;WIN64;NDEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\win32;..\..\opus-1.1\include;%(AdditionalIncludeDirectories) - MultiThreadedDLL - - - Windows - true - true - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/libs/win32/opus/opus.silk_common.2017.vcxproj b/libs/win32/opus/opus.silk_common.2017.vcxproj deleted file mode 100644 index 7d333196be..0000000000 --- a/libs/win32/opus/opus.silk_common.2017.vcxproj +++ /dev/null @@ -1,313 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {C303D2FC-FF97-49B8-9DDD-467B4C9A0B16} - Win32Proj - src_common - opus.silk_common - - - - - StaticLibrary - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - silk_common - $(Platform)\$(Configuration)\opus.silk_common\ - - - silk_common - $(Platform)\$(Configuration)\opus.silk_common\ - - - silk_common - $(Platform)\$(Configuration)\opus.silk_common\ - - - - - silk_common - $(Platform)\$(Configuration)\opus.silk_common\ - - - - - - Level3 - Disabled - HAVE_CONFIG_H;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk\fixed;..\..\opus-1.1\silk\float;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDebugDLL - ProgramDatabase - - - Windows - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - - - Level3 - Disabled - HAVE_CONFIG_H;WIN32;WIN64;_DEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk\fixed;..\..\opus-1.1\silk\float;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDebugDLL - ProgramDatabase - - - Windows - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - Level3 - - - true - true - HAVE_CONFIG_H;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk\fixed;..\..\opus-1.1\silk\float;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDLL - Fast - - - Windows - true - true - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - Level3 - - - MaxSpeed - true - true - HAVE_CONFIG_H;WIN32;WIN64;NDEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk\fixed;..\..\opus-1.1\silk\float;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDLL - Fast - - - Windows - true - true - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/libs/win32/opus/opus.silk_fixed.2017.vcxproj b/libs/win32/opus/opus.silk_fixed.2017.vcxproj deleted file mode 100644 index 10e760b119..0000000000 --- a/libs/win32/opus/opus.silk_fixed.2017.vcxproj +++ /dev/null @@ -1,205 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {8484C90D-1561-402F-A91D-2DB10F8C5171} - Win32Proj - src_FIX - opus.silk_fixed - - - - - StaticLibrary - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - silk_fixed - $(Platform)\$(Configuration)\silk_fixed\ - - - silk_fixed - $(Platform)\$(Configuration)\silk_fixed\ - - - silk_fixed - $(Platform)\$(Configuration)\silk_fixed\ - - - silk_fixed - $(Platform)\$(Configuration)\silk_fixed\ - - - - - - Level3 - Disabled - HAVE_CONFIG_H;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk\;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDebugDLL - 4244;4133;%(DisableSpecificWarnings) - ProgramDatabase - - - Windows - true - - - - - - - Level3 - Disabled - HAVE_CONFIG_H;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk\;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDebugDLL - 4244;4133;%(DisableSpecificWarnings) - ProgramDatabase - - - Windows - true - - - - - Level3 - - - true - true - HAVE_CONFIG_H;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk\;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDLL - 4244;4133;%(DisableSpecificWarnings) - - - Windows - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - HAVE_CONFIG_H;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk\;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDLL - 4244;4133;%(DisableSpecificWarnings) - - - Windows - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {c303d2fc-ff97-49b8-9ddd-467b4c9a0b16} - - - {9c4961d2-5ddb-40c7-9be8-ca918dc4e782} - - - - - - \ No newline at end of file diff --git a/libs/win32/opus/opus.silk_float.2017.vcxproj b/libs/win32/opus/opus.silk_float.2017.vcxproj deleted file mode 100644 index c6bbabfc65..0000000000 --- a/libs/win32/opus/opus.silk_float.2017.vcxproj +++ /dev/null @@ -1,253 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {9C4961D2-5DDB-40C7-9BE8-CA918DC4E782} - Win32Proj - src_FLP - opus.silk_float - - - - - StaticLibrary - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - silk_float - $(Platform)\$(Configuration)\silk_float\ - - - silk_float - $(Platform)\$(Configuration)\silk_float\ - - - silk_float - $(Platform)\$(Configuration)\silk_float\ - - - Compile - silk_float - $(Platform)\$(Configuration)\silk_float\ - - - - - - Level3 - Disabled - HAVE_CONFIG_H;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk;..\..\opus-1.1\silk\fixed;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDebugDLL - ProgramDatabase - - - Windows - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - - - Level3 - Disabled - HAVE_CONFIG_H;WIN32;WIN64;_DEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk;..\..\opus-1.1\silk\fixed;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDebugDLL - ProgramDatabase - - - Windows - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - Level3 - - - true - true - HAVE_CONFIG_H;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk;..\..\opus-1.1\silk\fixed;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDLL - - - Windows - true - true - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - Level3 - - - MaxSpeed - true - true - HAVE_CONFIG_H;WIN32;WIN64;NDEBUG;_LIB;%(PreprocessorDefinitions) - ..\..\opus-1.1\silk;..\..\opus-1.1\silk\fixed;..\..\opus-1.1\win32;..\..\opus-1.1\celt;..\..\opus-1.1\include - MultiThreadedDLL - - - Windows - true - true - true - - - "$(ProjectDir)..\..\opus-1.1\win32\genversion.bat" "$(ProjectDir)..\..\opus-1.1\win32\version.h" OPUS_VERSION - Generating version.h - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {c303d2fc-ff97-49b8-9ddd-467b4c9a0b16} - - - - - - \ No newline at end of file diff --git a/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj b/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj index 18478701c8..f7c8d57891 100644 --- a/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj +++ b/src/mod/codecs/mod_opus/mod_opus.2017.vcxproj @@ -46,6 +46,7 @@ $(DefaultPlatformToolset) + @@ -70,7 +71,7 @@ - ..\..\..\..\libs\opus-1.1\include;%(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) 6031;6053;6340;6246;6011;6387;%(DisableSpecificWarnings) @@ -86,7 +87,7 @@ X64 - ..\..\..\..\libs\opus-1.1\include;%(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) 6031;6053;6340;6246;6011;6387;%(DisableSpecificWarnings) @@ -100,7 +101,7 @@ - ..\..\..\..\libs\opus-1.1\include;%(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) 6031;6053;6340;6246;6011;6387;%(DisableSpecificWarnings) @@ -116,7 +117,7 @@ X64 - ..\..\..\..\libs\opus-1.1\include;%(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) 6031;6053;6340;6246;6011;6387;%(DisableSpecificWarnings) @@ -136,23 +137,6 @@ - - {FD60942F-72D6-4CA1-8B57-EA1D1B95A89E} - true - false - false - true - false - - - {245603e3-f580-41a5-9632-b25fe3372cbf} - - - {c303d2fc-ff97-49b8-9ddd-467b4c9a0b16} - - - {9c4961d2-5ddb-40c7-9be8-ca918dc4e782} - {202d7a4e-760d-4d0e-afa1-d7459ced30ff} false diff --git a/w32/download_opus.props b/w32/download_opus.props deleted file mode 100644 index a1859f3dbd..0000000000 --- a/w32/download_opus.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/opus-version.props b/w32/opus-version.props new file mode 100644 index 0000000000..738bd0c3a9 --- /dev/null +++ b/w32/opus-version.props @@ -0,0 +1,19 @@ + + + + + + + 1.5.2 + + + true + + + + + + $(opusVersion) + + + diff --git a/w32/opus.props b/w32/opus.props new file mode 100644 index 0000000000..82cfb5f5af --- /dev/null +++ b/w32/opus.props @@ -0,0 +1,85 @@ + + + + + + + + + true + + + + $(BaseDir)libs\opus-$(opusVersion) + $(opusDir)\binaries\$(Platform)\$(Configuration) + https://github.com/freeswitch/opus-packaging/releases/download/opus-v$(opusVersion) + + + + + + + + + + + + + + + + + + + + + + + + + + + $(opusDir)\include;$(opusDir)\include\opus;%(AdditionalIncludeDirectories) + + + $(opusBinDir);%(AdditionalLibraryDirectories) + opus.lib;%(AdditionalDependencies) + + + From 3af21e69e551a73e580551e774f2c2132cdb01ae Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 9 Sep 2026 20:47:24 +0500 Subject: [PATCH 05/88] [mod_json_cdr] Fix malformed JSON in URL-encoded POST bodies (#3152) `switch_url_encode()` encodes with `double_encode` false, so a `%XX` already present in `json_text` was emitted unchanged and became indistinguishable from the escapes the body encoding added itself. Decoding the body then consumed the values' own escapes as well, and the document no longer parsed. Values arrive pre-encoded whenever `encode-values` is on, and can hold percent-hex text regardless of it. Encode with `switch_url_encode_opt(..., SWITCH_TRUE)` so `%` is encoded too and the body decodes back to exactly the serialized document. `mod_xml_cdr` and `mod_format_cdr` already encode their bodies this way. - Size the escape buffer `* 3 + 1`. `switch_url_encode_opt()` reserves the terminator from the length it is given, so `* 3` dropped the last escaped character when every byte needed encoding. The base64 call now takes that length directly. - Warn at load when `encode` and `encode-values` are both on, since the values stay encoded after the body is decoded. - Correct both encoding config comments; the `encode` one described only `base64`. Adds core coverage in `tests/unit/switch_utils.c` for both `switch_url_encode_opt()` modes, its output bounds, and a JSON body encoded and decoded once. --- .../conf/autoload_configs/json_cdr.conf.xml | 7 +- .../mod_json_cdr/mod_json_cdr.c | 14 +- tests/unit/switch_utils.c | 141 ++++++++++++++++++ 3 files changed, 157 insertions(+), 5 deletions(-) diff --git a/src/mod/event_handlers/mod_json_cdr/conf/autoload_configs/json_cdr.conf.xml b/src/mod/event_handlers/mod_json_cdr/conf/autoload_configs/json_cdr.conf.xml index af30c67c07..ea5cc06caa 100644 --- a/src/mod/event_handlers/mod_json_cdr/conf/autoload_configs/json_cdr.conf.xml +++ b/src/mod/event_handlers/mod_json_cdr/conf/autoload_configs/json_cdr.conf.xml @@ -6,7 +6,8 @@ - + - + diff --git a/src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c b/src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c index 7f66aa425a..ed216841d2 100644 --- a/src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c +++ b/src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c @@ -473,15 +473,17 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) json_text = cJSON_PrintUnformatted(json_cdr); if (globals.url_count && globals.encode) { - switch_size_t need_bytes = strlen(json_text) * 3; + switch_size_t json_len = strlen(json_text); + switch_size_t need_bytes = json_len * 3 + 1; json_text_escaped = malloc(need_bytes); switch_assert(json_text_escaped); memset(json_text_escaped, 0, need_bytes); if (globals.encode == ENCODING_DEFAULT) { - switch_url_encode(json_text, json_text_escaped, need_bytes); + /* json_text may already hold %XX, so '%' is encoded rather than passed through. */ + switch_url_encode_opt(json_text, json_text_escaped, need_bytes, SWITCH_TRUE); } else { - switch_b64_encode((unsigned char *) json_text, need_bytes / 3, (unsigned char *) json_text_escaped, need_bytes); + switch_b64_encode((unsigned char *) json_text, json_len, (unsigned char *) json_text_escaped, need_bytes); } } @@ -723,6 +725,12 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_json_cdr_load) globals.delay = 5; } + if (globals.encode == ENCODING_DEFAULT && globals.encode_values == ENCODING_DEFAULT) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "encode=true with encode-values=true: values stay percent-encoded after the body is " + "decoded, so each value needs decoding too. Set encode-values=false to send them as-is.\n"); + } + globals.retries++; set_json_cdr_log_dirs(); diff --git a/tests/unit/switch_utils.c b/tests/unit/switch_utils.c index bbd250bb11..07657141d5 100644 --- a/tests/unit/switch_utils.c +++ b/tests/unit/switch_utils.c @@ -62,6 +62,147 @@ FST_TEST_BEGIN(benchmark) } FST_TEST_END() +FST_TEST_BEGIN(url_encode_double_encode) +{ + static const struct { + const char *in; + const char *plain; + const char *doubled; + const char *rule; + } cases[] = { + { "ABCD", "ABCD", "ABCD", "nothing unsafe is copied through unchanged" }, + { "50% off", "50%25%20off", "50%25%20off", "a '%' without two hex digits after it is encoded either way" }, + { "50%20off", "50%20off", "50%2520off", "a '%' with two hex digits after it is the case the modes differ on" }, + { "x%22y", "x%22y", "x%2522y", "an encoded quote is either passed through or protected" }, + { "abc%2", "abc%252", "abc%252", "too few characters follow the '%' for it to be an escape" }, + { "%2a", "%252a", "%252a", "only uppercase hex counts as an existing escape" } + }; + char plain[64]; + char doubled[64]; + char msg[192]; + + for (int i = 0; i < (int) (sizeof(cases) / sizeof(cases[0])); i++) { + switch_url_encode_opt(cases[i].in, plain, sizeof(plain), SWITCH_FALSE); + switch_url_encode_opt(cases[i].in, doubled, sizeof(doubled), SWITCH_TRUE); + + switch_snprintf(msg, sizeof(msg), "[%s] without double_encode: %s", cases[i].in, cases[i].rule); + fst_xcheck(!strcmp(plain, cases[i].plain), msg); + + switch_snprintf(msg, sizeof(msg), "[%s] with double_encode: %s", cases[i].in, cases[i].rule); + fst_xcheck(!strcmp(doubled, cases[i].doubled), msg); + } +} +FST_TEST_END() + +FST_TEST_BEGIN(url_encode_opt_output_bounds) +{ + /* The 0xAA sentinel across the destination catches any write outside the region the + encode call is allowed to touch. */ + char guarded[32]; + const char *all_unsafe = "\"\"\""; + + /* Every input character encodes to three bytes, so a buffer of strlen * 3 + 1 is the + smallest that holds the result and its terminator. */ + memset(guarded, 0xAA, sizeof(guarded)); + switch_url_encode_opt(all_unsafe, guarded, strlen(all_unsafe) * 3 + 1, SWITCH_FALSE); + fst_check_string_equals(guarded, "%22%22%22"); + fst_xcheck(guarded[9] == '\0', "the terminator must land right after the last encoded byte"); + for (int i = 10; i < (int) sizeof(guarded); i++) { + fst_xcheck(guarded[i] == (char) 0xAA, "encode must not write past the terminator"); + } + + /* One byte short of that, the last group does not fit and the output stops early + rather than overrunning. */ + memset(guarded, 0xAA, sizeof(guarded)); + switch_url_encode_opt(all_unsafe, guarded, strlen(all_unsafe) * 3, SWITCH_FALSE); + fst_check_string_equals(guarded, "%22%22"); + for (int i = 7; i < (int) sizeof(guarded); i++) { + fst_xcheck(guarded[i] == (char) 0xAA, "a bounded encode must not write past the terminator"); + } +} +FST_TEST_END() + +FST_TEST_BEGIN(url_encoded_json_body_round_trip) +{ + /* Mirrors how a CDR body is assembled: each value may be URL encoded, the document is + serialized, the whole body is URL encoded, and the receiver decodes it once. The two + cases differ only in where the %XX inside the value comes from. */ + static const struct { + const char *value; + switch_bool_t encode_value; + const char *rule; + } cases[] = { + { "\"6140\" ;tag=x", SWITCH_TRUE, "value encoded by the value layer" }, + { "x%22y", SWITCH_FALSE, "value holding percent-hex text of its own" } + }; + char stored[512]; + char body[4096]; + char decoded[4096]; + char msg[192]; + cJSON *json = NULL; + cJSON *parsed = NULL; + char *json_text = NULL; + + for (int i = 0; i < (int) (sizeof(cases) / sizeof(cases[0])); i++) { + if (cases[i].encode_value) { + switch_url_encode(cases[i].value, stored, sizeof(stored)); + } else { + switch_set_string(stored, cases[i].value); + } + + json = cJSON_CreateObject(); + cJSON_AddItemToObject(json, "v", cJSON_CreateString(stored)); + json_text = cJSON_PrintUnformatted(json); + if (!json_text) { + switch_snprintf(msg, sizeof(msg), "failed to serialize the document for a %s", cases[i].rule); + fst_fail(msg); + goto url_encoded_json_body_round_trip_done; + } + + /* double_encode protects the escapes in the value, so one decode returns the document + unchanged and the value keeps its own text. */ + switch_url_encode_opt(json_text, body, sizeof(body), SWITCH_TRUE); + switch_set_string(decoded, body); + switch_url_decode(decoded); + switch_snprintf(msg, sizeof(msg), "a double encoded body must decode back to the document: %s", cases[i].rule); + fst_xcheck(!strcmp(decoded, json_text), msg); + + parsed = cJSON_Parse(decoded); + switch_snprintf(msg, sizeof(msg), "a double encoded body must parse after one decode: %s", cases[i].rule); + fst_xcheck(parsed != NULL, msg); + if (parsed) { + switch_snprintf(msg, sizeof(msg), "the value must survive unchanged: %s", cases[i].rule); + fst_xcheck(!strcmp(cJSON_GetObjectCstr(parsed, "v"), stored), msg); + cJSON_Delete(parsed); + parsed = NULL; + } + + /* Without it the single decode reaches into the value as well, and the document no + longer parses. */ + switch_url_encode_opt(json_text, body, sizeof(body), SWITCH_FALSE); + switch_set_string(decoded, body); + switch_url_decode(decoded); + switch_snprintf(msg, sizeof(msg), "a singly encoded body must not decode back to the document: %s", cases[i].rule); + fst_xcheck(strcmp(decoded, json_text), msg); + + parsed = cJSON_Parse(decoded); + switch_snprintf(msg, sizeof(msg), "a singly encoded body must not survive one decode: %s", cases[i].rule); + fst_xcheck(parsed == NULL, msg); + cJSON_Delete(parsed); + parsed = NULL; + + cJSON_Delete(json); + json = NULL; + switch_safe_free(json_text); + } + +url_encoded_json_body_round_trip_done: + cJSON_Delete(parsed); + cJSON_Delete(json); + switch_safe_free(json_text); +} +FST_TEST_END() + FST_TEST_BEGIN(b64) { switch_size_t size; From 7c2a5d0be76132e9b1e8e5e7e9ec8e1916445613 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 10 Sep 2026 01:34:17 +0300 Subject: [PATCH 06/88] [mod_sndfile] Windows: update libsndfile to v1.2.2 from GitHub. Add test_sndfile visual studio project to the solution. (#3155) --- .gitignore | 4 + Freeswitch.2017.sln | 19 ++ src/mod/formats/mod_sndfile/test/GitInfo | 0 .../test/test_sndfile.2017.vcxproj | 203 ++++++++++++++++++ .../formats/mod_sndfile/test/test_sndfile.c | 26 ++- w32/libsndfile-version.props | 2 +- w32/libsndfile.props | 52 ++--- 7 files changed, 275 insertions(+), 31 deletions(-) create mode 100644 src/mod/formats/mod_sndfile/test/GitInfo create mode 100644 src/mod/formats/mod_sndfile/test/test_sndfile.2017.vcxproj diff --git a/.gitignore b/.gitignore index 1b9dcb1551..d8bafdb3bd 100644 --- a/.gitignore +++ b/.gitignore @@ -268,6 +268,10 @@ src/mod/applications/mod_http_cache/test/test_aws.log src/mod/applications/mod_http_cache/test/test_aws.trs src/mod/formats/mod_sndfile/test/test_sndfile src/mod/formats/mod_sndfile/test/test_sndfile_conf +# Recordings test_sndfile writes here on Windows, named .. A passing run +# unlinks them, but libsndfile also writes a ._.sd2 resource fork that nothing +# removes, and a failing run leaves the lot behind. +src/mod/formats/mod_sndfile/test/*-*-*-*-* src/mod/*/*/test/*.log src/mod/*/*/test/*.trs src/mod/*/*/test/[0-9]*/* diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index 5efcf1dd3a..2cbc4833f8 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -516,6 +516,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_test", "src\mod\applica EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_switch_xml", "tests\unit\test_switch_xml.2017.vcxproj", "{FED39CFF-E6CD-1C09-844D-F1174B8A5C18}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_sndfile", "src\mod\formats\mod_sndfile\test\test_sndfile.2017.vcxproj", "{19D12A4C-1036-4695-85B0-6030F6048233}" + ProjectSection(ProjectDependencies) = postProject + {AFAC0568-7548-42D5-9F6A-8D3400A1E4F6} = {AFAC0568-7548-42D5-9F6A-8D3400A1E4F6} + {B3F424EC-3D8F-417C-B244-3919D5E1A577} = {B3F424EC-3D8F-417C-B244-3919D5E1A577} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution All|Win32 = All|Win32 @@ -2300,6 +2306,18 @@ Global {FED39CFF-E6CD-1C09-844D-F1174B8A5C18}.Release|Win32.Build.0 = Release|Win32 {FED39CFF-E6CD-1C09-844D-F1174B8A5C18}.Release|x64.ActiveCfg = Release|x64 {FED39CFF-E6CD-1C09-844D-F1174B8A5C18}.Release|x64.Build.0 = Release|x64 + {19D12A4C-1036-4695-85B0-6030F6048233}.All|Win32.ActiveCfg = Debug|Win32 + {19D12A4C-1036-4695-85B0-6030F6048233}.All|Win32.Build.0 = Debug|Win32 + {19D12A4C-1036-4695-85B0-6030F6048233}.All|x64.ActiveCfg = Debug|x64 + {19D12A4C-1036-4695-85B0-6030F6048233}.All|x64.Build.0 = Debug|x64 + {19D12A4C-1036-4695-85B0-6030F6048233}.Debug|Win32.ActiveCfg = Debug|Win32 + {19D12A4C-1036-4695-85B0-6030F6048233}.Debug|Win32.Build.0 = Debug|Win32 + {19D12A4C-1036-4695-85B0-6030F6048233}.Debug|x64.ActiveCfg = Debug|x64 + {19D12A4C-1036-4695-85B0-6030F6048233}.Debug|x64.Build.0 = Debug|x64 + {19D12A4C-1036-4695-85B0-6030F6048233}.Release|Win32.ActiveCfg = Release|Win32 + {19D12A4C-1036-4695-85B0-6030F6048233}.Release|Win32.Build.0 = Release|Win32 + {19D12A4C-1036-4695-85B0-6030F6048233}.Release|x64.ActiveCfg = Release|x64 + {19D12A4C-1036-4695-85B0-6030F6048233}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2480,6 +2498,7 @@ Global {3745B86B-6BE8-3E67-FCB9-BE62A6131D67} = {9388C266-C3FC-468A-92EF-0CBC35941412} {E9FF8127-D5F0-2398-59EB-702CE55F7800} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {FED39CFF-E6CD-1C09-844D-F1174B8A5C18} = {9388C266-C3FC-468A-92EF-0CBC35941412} + {19D12A4C-1036-4695-85B0-6030F6048233} = {9388C266-C3FC-468A-92EF-0CBC35941412} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {09840DE7-9208-45AA-9667-1A71EE93BD1E} diff --git a/src/mod/formats/mod_sndfile/test/GitInfo b/src/mod/formats/mod_sndfile/test/GitInfo new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/mod/formats/mod_sndfile/test/test_sndfile.2017.vcxproj b/src/mod/formats/mod_sndfile/test/test_sndfile.2017.vcxproj new file mode 100644 index 0000000000..2bc16da062 --- /dev/null +++ b/src/mod/formats/mod_sndfile/test/test_sndfile.2017.vcxproj @@ -0,0 +1,203 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + test_sndfile + test_sndfile + Win32Proj + 10.0 + {19D12A4C-1036-4695-85B0-6030F6048233} + + + + Application + MultiByte + $(DefaultPlatformToolset) + + + Application + MultiByte + $(DefaultPlatformToolset) + + + Application + MultiByte + $(DefaultPlatformToolset) + + + Application + MultiByte + $(DefaultPlatformToolset) + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)$(PlatformName)\$(Configuration)\ + $(PlatformName)\$(Configuration)\ + false + $(SolutionDir)$(PlatformName)\$(Configuration)\ + $(Platform)\$(Configuration)\ + false + $(SolutionDir)$(PlatformName)\$(Configuration)\ + $(PlatformName)\$(Configuration)\ + false + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + false + + + + $(SolutionDir)src\include;%(AdditionalIncludeDirectories) + SWITCH_TEST_BASE_DIR_FOR_CONF="..\\..\\src\\mod\\formats\\mod_sndfile\\test\\";%(PreprocessorDefinitions) + + + + + + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + ProgramDatabase + true + 6031;6340;6246;6011;6387;%(DisableSpecificWarnings) + + + $(OutDir);%(AdditionalLibraryDirectories) + true + Console + true + + + MachineX86 + + + + + + X64 + + + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + ProgramDatabase + true + 6031;6340;6246;6011;6387;%(DisableSpecificWarnings) + + + $(OutDir);%(AdditionalLibraryDirectories) + true + Console + true + + + MachineX64 + + + + + + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + + Level4 + ProgramDatabase + 6031;6340;6246;6011;6387;%(DisableSpecificWarnings) + + + $(OutDir);%(AdditionalLibraryDirectories) + false + Console + true + true + true + + + MachineX86 + + + + + + X64 + + + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + + + Level4 + ProgramDatabase + 6031;6340;6246;6011;6387;%(DisableSpecificWarnings) + + + $(OutDir);%(AdditionalLibraryDirectories) + false + Console + true + true + true + + + MachineX64 + + + + + + + + {202d7a4e-760d-4d0e-afa1-d7459ced30ff} + + + + + + \ No newline at end of file diff --git a/src/mod/formats/mod_sndfile/test/test_sndfile.c b/src/mod/formats/mod_sndfile/test/test_sndfile.c index 8a6d790207..ce01b18ec8 100644 --- a/src/mod/formats/mod_sndfile/test/test_sndfile.c +++ b/src/mod/formats/mod_sndfile/test/test_sndfile.c @@ -109,6 +109,24 @@ typedef struct { #define thread_bail_out(x, msg) if (!(x)) {params->status = SWITCH_STATUS_FALSE; params->err_detail = strdup(msg); return NULL;} +/* Where to write the recording this test makes and reads back. */ +static char *test_recording_path(switch_core_session_t *session, const char *ext) +{ +#ifdef WIN32 + /* Windows has no /tmp, so record into the test folder, which is conf_dir's parent. + * Anchor it on base_dir to keep it absolute: conf_dir on its own is relative, and + * switch_is_file_path() only accepts a drive letter, a leading separator or a URL. + * A path it rejects makes switch_ivr_record_session() prepend sound_prefix to the + * whole string - in front of the "{force_channels=2}" the stereo tests pass - which + * then defeats the brace stripping it does before creating the parent directory. */ + return switch_mprintf("%s%s%s%s..%s%s.%s", SWITCH_GLOBAL_dirs.base_dir, SWITCH_PATH_SEPARATOR, + SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, SWITCH_PATH_SEPARATOR, + switch_core_session_get_uuid(session), ext); +#else + return switch_mprintf("/tmp/%s.%s", switch_core_session_get_uuid(session), ext); +#endif +} + static void *SWITCH_THREAD_FUNC sndfile_write_read_mono_thread_run(switch_thread_t *thread, void *obj) { /* play mono, record mono, open mono */ @@ -136,7 +154,7 @@ static void *SWITCH_THREAD_FUNC sndfile_write_read_mono_thread_run(switch_thread switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Testing media file extension: [%s]\n", params->ext); - recording = switch_mprintf("/tmp/%s.%s", switch_core_session_get_uuid(session), params->ext); + recording = test_recording_path(session, params->ext); status = switch_ivr_record_session(session, recording, duration, NULL); thread_bail_out(status == SWITCH_STATUS_SUCCESS, "switch_ivr_record_session() status != SWITCH_STATUS_SUCCESS"); @@ -207,7 +225,7 @@ static void *SWITCH_THREAD_FUNC sndfile_write_read_m2s_thread_run(switch_thread_ status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", timeout_sec, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); thread_bail_out(status == SWITCH_STATUS_SUCCESS, "switch_ivr_originate() status != SWITCH_STATUS_SUCCESS"); - recording = switch_mprintf("/tmp/%s.%s", switch_core_session_get_uuid(session), params->ext); + recording = test_recording_path(session, params->ext); status = switch_ivr_record_session(session, recording, duration, NULL); thread_bail_out(status == SWITCH_STATUS_SUCCESS, "switch_ivr_record_session() status != SWITCH_STATUS_SUCCESS"); @@ -278,7 +296,7 @@ static void *SWITCH_THREAD_FUNC sndfile_write_read_s2m_thread_run(switch_thread_ status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", timeout_sec, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); thread_bail_out(status == SWITCH_STATUS_SUCCESS, "switch_ivr_originate() status != SWITCH_STATUS_SUCCESS"); - rec_path = switch_mprintf("/tmp/%s.%s", switch_core_session_get_uuid(session), params->ext); + rec_path = test_recording_path(session, params->ext); recording = switch_mprintf("{force_channels=2}%s", rec_path); channel = switch_core_session_get_channel(session); @@ -351,7 +369,7 @@ static void *SWITCH_THREAD_FUNC sndfile_write_read_stereo_thread_run(switch_thre status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", timeout_sec, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); thread_bail_out(status == SWITCH_STATUS_SUCCESS, "switch_ivr_play_file() status != SWITCH_STATUS_SUCCESS"); - rec_path = switch_mprintf("/tmp/%s.%s", switch_core_session_get_uuid(session), params->ext); + rec_path = test_recording_path(session, params->ext); recording = switch_mprintf("{force_channels=2}%s", rec_path); channel = switch_core_session_get_channel(session); diff --git a/w32/libsndfile-version.props b/w32/libsndfile-version.props index c30e080fef..753ba4a413 100644 --- a/w32/libsndfile-version.props +++ b/w32/libsndfile-version.props @@ -4,7 +4,7 @@ - 1.0.28.1.fda9c8d + 1.2.2 true diff --git a/w32/libsndfile.props b/w32/libsndfile.props index 03dbd5a9bd..26f1700a51 100644 --- a/w32/libsndfile.props +++ b/w32/libsndfile.props @@ -8,13 +8,13 @@ - - Debug - Release - - - $(BaseDir)libs\libsndfile-$(libsndfileVersion) + + win64 + win32 + $(BaseDir)libs\libsndfile-$(libsndfileVersion)-$(libsndfileArch) + https://github.com/libsndfile/libsndfile/releases/download/$(libsndfileVersion) - + + - - - - + + - + - - $(SolutionDir)libs\libsndfile-$(libsndfileVersion)\include;%(AdditionalIncludeDirectories) + $(libsndfileDir)\include;%(AdditionalIncludeDirectories) - $(SolutionDir)libs\libsndfile-$(libsndfileVersion)\binaries\$(Platform)\$(LibraryConfiguration)\lib;%(AdditionalLibraryDirectories) - libsndfile-1.lib;%(AdditionalDependencies) + $(libsndfileDir)\lib;%(AdditionalLibraryDirectories) + sndfile.lib;%(AdditionalDependencies) - \ No newline at end of file + From b3ba603f495b58baad52af1307136584b1eb76e3 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Mon, 14 Sep 2026 18:03:54 +0500 Subject: [PATCH 07/88] [mod_sofia] Compare display updates against the value actually stored (#3165) The caller profile fields hold the output of `switch_sanitize_number()`, but the unchanged check compared them against the raw candidate, so a value the sanitizer alters never matched and the update repeated on every message. Sanitize once before the comparison, and reuse the result for the stores and the log. Cleanups in the same function: - Stop reading the name and number channel variables up front. Those reads allocate from the session pool and are discarded whenever a SIP field supplies the value; the fallbacks below cover the rest. The number's `sip_to` branch moves there too, keeping the channel variable ahead of the To user. - Take the scratch copy the comparison needs from the heap rather than the pool, so an update that changes nothing costs the session no memory. - Declare `name` as `const char *` and retarget the display quote strip at `dup`, which owns the buffer. Removes four casts that handed out a writable pointer into the parsed message. --- src/mod/endpoints/mod_sofia/sofia.c | 54 +++++++++++++++++------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index f5bc04de26..98c0becf6f 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1209,10 +1209,10 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro { switch_channel_t *channel = switch_core_session_get_channel(session); sip_p_asserted_identity_t *passerted = NULL; - char *name = NULL; - const char *number, *tmp; + const char *name = NULL; + const char *number = NULL, *tmp; switch_caller_profile_t *caller_profile; - char *dup = NULL; + char *dup = NULL, *name_dup = NULL, *number_dup = NULL; switch_event_t *event; const char *val; int fs = 0, lazy = 0, att = 0; @@ -1230,13 +1230,6 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro } - number = (char *) switch_channel_get_variable(channel, num_var); - name = (char *) switch_channel_get_variable(channel, name_var); - - if (zstr(number) && sip->sip_to) { - number = sip->sip_to->a_url->url_user; - } - if (switch_channel_var_true(channel, "sip_ignore_remote_cid")) { fs++; } else { @@ -1246,7 +1239,7 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro } if ((val = sofia_glue_get_unknown_header(sip, "X-FS-Display-Name"))) { - name = (char *) val; + name = val; check_decode(name, session); fs++; } @@ -1264,6 +1257,7 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro if (!fs) { sip_remote_party_id_t *rpid; + if ((passerted = sip_p_asserted_identity(sip))) { if (passerted->paid_url->url_user) { number = passerted->paid_url->url_user; @@ -1276,8 +1270,8 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro } else { name = dup; } - if (end_of(name) == '"') { - end_of(name) = '\0'; + if (end_of(dup) == '"') { + end_of(dup) = '\0'; } } } else if ((rpid = sip_remote_party_id(sip))) { @@ -1292,8 +1286,8 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro } else { name = dup; } - if (end_of(name) == '"') { - end_of(name) = '\0'; + if (end_of(dup) == '"') { + end_of(dup) = '\0'; } } } @@ -1302,7 +1296,12 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro if (zstr(number)) { if ((tmp = switch_channel_get_variable(channel, num_var)) && !zstr(tmp)) { - number = (char *) tmp; + number = tmp; + } + + /* The To user ranks below the channel variable, so it is only consulted once that misses. */ + if (zstr(number) && sip->sip_to) { + number = sip->sip_to->a_url->url_user; } if (zstr(number)) { @@ -1312,12 +1311,12 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro if (zstr(name)) { if ((tmp = switch_channel_get_variable(channel, name_var)) && !zstr(tmp)) { - name = (char *) tmp; + name = tmp; } } if (zstr(name)) { - name = (char *) number; + name = number; } if (zstr(name) || zstr(number)) { @@ -1326,14 +1325,23 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro caller_profile = switch_channel_get_caller_profile(channel); + /* Sanitized before the comparisons, not at the stores: the fields hold sanitized values, so a + raw candidate never matches. Scratch is heap so an unchanged update costs the session + nothing, and the originals are freed since sanitizing returns a pointer into them. */ + name_dup = strdup(name); + number_dup = strdup(number); + switch_assert(name_dup && number_dup); + name = switch_sanitize_number(name_dup); + number = switch_sanitize_number(number_dup); + if (switch_channel_inbound_display(channel)) { if (!strcmp(caller_profile->caller_id_name, name) && !strcmp(caller_profile->caller_id_number, number)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "%s Same Caller ID \"%s\" <%s>\n", switch_channel_get_name(channel), name, number); send = 0; } else { - caller_profile->caller_id_name = switch_sanitize_number(switch_core_strdup(caller_profile->pool, name)); - caller_profile->caller_id_number = switch_sanitize_number(switch_core_strdup(caller_profile->pool, number)); + caller_profile->caller_id_name = switch_core_strdup(caller_profile->pool, name); + caller_profile->caller_id_number = switch_core_strdup(caller_profile->pool, number); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Update Caller ID to \"%s\" <%s>\n", switch_channel_get_name(channel), name, number); } @@ -1343,8 +1351,8 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "%s Same Callee ID \"%s\" <%s>\n", switch_channel_get_name(channel), name, number); send = 0; } else { - caller_profile->callee_id_name = switch_sanitize_number(switch_core_strdup(caller_profile->pool, name)); - caller_profile->callee_id_number = switch_sanitize_number(switch_core_strdup(caller_profile->pool, number)); + caller_profile->callee_id_name = switch_core_strdup(caller_profile->pool, name); + caller_profile->callee_id_number = switch_core_strdup(caller_profile->pool, number); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s Update Callee ID to \"%s\" <%s>\n", switch_channel_get_name(channel), name, number); if (lazy || (att && !switch_channel_get_partner_uuid(channel))) { @@ -1370,6 +1378,8 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro end: switch_safe_free(dup); + switch_safe_free(name_dup); + switch_safe_free(number_dup); } static void tech_send_ack(nua_handle_t *nh, private_object_t *tech_pvt, const char *r_sdp) From f1edcccb92f174eebbca481221d12eb78ffbf7ba Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 15 Sep 2026 18:10:59 +0300 Subject: [PATCH 08/88] [Build-System] Windows: Upgrade OpenSSL to v3.4.7_1, libpq to v17.11_1, rabbitmq-c to v0.17.0_1, zlib to v1.3.2_1, libpng to v1.6.58_1, curl to v7.88.1_1, libks to v2.0.11_1, signalwire-client-c to v2.0.5_2. (#3167) --- .gitignore | 18 ++ Freeswitch.2017.sln | 15 -- libs/win32/libpng/cleancount | 1 - libs/win32/libpng/libpng.2017.vcxproj | 236 ------------------- src/mod/formats/mod_png/mod_png.2017.vcxproj | 13 +- w32/Library/FreeSwitchCore.2017.vcxproj | 12 +- w32/curl-version.props | 4 +- w32/curl.props | 6 +- w32/download_ffmpeg.props | 41 ---- w32/download_libpng.props | 40 ---- w32/libks-version.props | 2 +- w32/libks.props | 6 +- w32/libpng-version.props | 24 ++ w32/libpng.props | 99 +++++++- w32/libpq-version.props | 4 +- w32/libpq.props | 6 +- w32/openssl-version.props | 5 +- w32/openssl.props | 4 +- w32/rabbitmq-c-version.props | 4 +- w32/rabbitmq-c.props | 11 +- w32/signalwire-client-c-version.props | 2 +- w32/signalwire-client-c.props | 6 +- w32/zlib-version.props | 3 +- w32/zlib.props | 10 +- 24 files changed, 183 insertions(+), 389 deletions(-) delete mode 100644 libs/win32/libpng/cleancount delete mode 100644 libs/win32/libpng/libpng.2017.vcxproj delete mode 100644 w32/download_ffmpeg.props delete mode 100644 w32/download_libpng.props create mode 100644 w32/libpng-version.props diff --git a/.gitignore b/.gitignore index d8bafdb3bd..5a9f8a4628 100644 --- a/.gitignore +++ b/.gitignore @@ -250,6 +250,24 @@ libs/libcodec2-*/ libs/libsilk-*/ libs/rabbitmq-c-*/ libs/rabbitmq-c-*.zip +# Dependency packages w32\*.props download from freeswitch/windows-deps +# into libs\-_\ (rabbitmq-c is listed above). +libs/zlib-*/ +libs/zlib-*.zip +libs/openssl-*/ +libs/openssl-*.zip +libs/libpng-*/ +libs/libpng-*.zip +libs/libks-*/ +libs/libks-*.zip +libs/signalwire-client-c-*/ +libs/signalwire-client-c-*.zip +libs/curl-*/ +libs/curl-*.zip +libs/libpcap-*/ +libs/libpcap-*.zip +libs/libpq-*/ +libs/libpq-*.zip libs/SharpZipLib.*/ libs/SharpZipLib.*.nupkg libs/nasm-*/ diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index 2cbc4833f8..c08e5b1f6c 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -444,8 +444,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libyuv", "libs\win32\libyuv EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libvpx", "libs\win32\libvpx\libvpx.2017.vcxproj", "{DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "libs\win32\libpng\libpng.2017.vcxproj", "{D6973076-9317-4EF2-A0B8-B7A18AC0713E}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "freetype.2017", "libs\win32\freetype\freetype.2017.vcxproj", "{78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_png", "src\mod\formats\mod_png\mod_png.2017.vcxproj", "{FBC7E2A4-B989-4289-BA7F-68F440E9EF8B}" @@ -1900,18 +1898,6 @@ Global {DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74}.Release|Win32.Build.0 = Release|Win32 {DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74}.Release|x64.ActiveCfg = Release|x64 {DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74}.Release|x64.Build.0 = Release|x64 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.All|Win32.ActiveCfg = Release|Win32 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.All|Win32.Build.0 = Release|Win32 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.All|x64.ActiveCfg = Release|x64 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.All|x64.Build.0 = Release|x64 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug|Win32.ActiveCfg = Debug|Win32 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug|Win32.Build.0 = Debug|Win32 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug|x64.ActiveCfg = Debug|x64 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug|x64.Build.0 = Debug|x64 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release|Win32.ActiveCfg = Release|Win32 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release|Win32.Build.0 = Release|Win32 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release|x64.ActiveCfg = Release|x64 - {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release|x64.Build.0 = Release|x64 {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.All|Win32.ActiveCfg = Release|Win32 {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.All|Win32.Build.0 = Release|Win32 {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.All|x64.ActiveCfg = Release|x64 @@ -2464,7 +2450,6 @@ Global {5B2BACE4-0F5A-4A21-930D-C0F4B1F58FA6} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C} {B6E22500-3DB6-4E6E-8CD5-591B781D7D99} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} - {D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {FBC7E2A4-B989-4289-BA7F-68F440E9EF8B} = {A5A27244-AD24-46E5-B01B-840CD296C91D} {7AEE504B-23B6-4B05-829E-7CD34855F146} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} diff --git a/libs/win32/libpng/cleancount b/libs/win32/libpng/cleancount deleted file mode 100644 index 56a6051ca2..0000000000 --- a/libs/win32/libpng/cleancount +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/libs/win32/libpng/libpng.2017.vcxproj b/libs/win32/libpng/libpng.2017.vcxproj deleted file mode 100644 index 0dddfd22b6..0000000000 --- a/libs/win32/libpng/libpng.2017.vcxproj +++ /dev/null @@ -1,236 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - libpng - {D6973076-9317-4EF2-A0B8-B7A18AC0713E} - Win32Proj - libpng - - - - - DynamicLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - DynamicLibrary - true - MultiByte - $(DefaultPlatformToolset) - - - DynamicLibrary - $(DefaultPlatformToolset) - false - - - DynamicLibrary - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - false - $(ProjectName)16 - - - false - $(ProjectName)16 - - - false - $(ProjectName)16 - - - false - $(ProjectName)16 - - - - Use - $(WarningLevel) - false - ProgramDatabase - EnableFastChecks - WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - true - false - false - pngpriv.h - true - CompileAsC - true - $(DisableSpecificWarnings) - $(TreatWarningAsError) - Disabled - MultiThreadedDebugDLL - - - Windows - true - 16 - - - - - $(WarningLevel) - Use - ProgramDatabase - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - false - false - pngpriv.h - true - CompileAsC - true - false - $(DisableSpecificWarnings) - $(TreatWarningAsError) - Full - - - Windows - false - true - true - 16 - - - - - X64 - - - Use - $(WarningLevel) - false - ProgramDatabase - EnableFastChecks - WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - true - false - false - pngpriv.h - true - CompileAsC - true - $(DisableSpecificWarnings) - $(TreatWarningAsError) - Disabled - MultiThreadedDebugDLL - - - Windows - true - 16 - - - - - X64 - - - $(WarningLevel) - Use - ProgramDatabase - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - false - false - pngpriv.h - true - CompileAsC - true - false - $(DisableSpecificWarnings) - $(TreatWarningAsError) - Full - - - Windows - false - true - true - 16 - - - - - Document - Generating pnglibconf.h - copy $(ProjectDir)..\..\libpng\scripts\pnglibconf.h.prebuilt $(ProjectDir)..\..\libpng\pnglibconf.h - $(ProjectDir)..\..\libpng\pnglibconf.h;%(Outputs) - - - Create - Create - Create - Create - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/mod/formats/mod_png/mod_png.2017.vcxproj b/src/mod/formats/mod_png/mod_png.2017.vcxproj index e54bbd5f87..13e00c2127 100644 --- a/src/mod/formats/mod_png/mod_png.2017.vcxproj +++ b/src/mod/formats/mod_png/mod_png.2017.vcxproj @@ -46,6 +46,7 @@ $(DefaultPlatformToolset) + @@ -70,13 +71,11 @@ - %(RootDir)%(Directory)..\..\..\..\libs\win32\libpng\;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS;%(PreprocessorDefinitions) - ..\..\..\..\libs\libpng\Win32\$(OutDir);%(AdditionalLibraryDirectories) false @@ -87,13 +86,11 @@ X64 - %(RootDir)%(Directory)..\..\..\..\libs\win32\libpng\;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS;%(PreprocessorDefinitions) - ..\..\..\..\libs\libpng\Win32\$(OutDir);%(AdditionalLibraryDirectories) false @@ -102,12 +99,10 @@ - %(RootDir)%(Directory)..\..\..\..\libs\win32\libpng\;%(AdditionalIncludeDirectories) - ..\..\..\..\libs\libpng\Win32\$(OutDir);%(AdditionalLibraryDirectories) false @@ -118,12 +113,10 @@ X64 - %(RootDir)%(Directory)..\..\..\..\libs\win32\libpng\;%(AdditionalIncludeDirectories) - ..\..\..\..\libs\libpng\Win32\$(OutDir);%(AdditionalLibraryDirectories) false @@ -134,10 +127,6 @@ - - {D6973076-9317-4EF2-A0B8-B7A18AC0713E} - false - {202d7a4e-760d-4d0e-afa1-d7459ced30ff} false diff --git a/w32/Library/FreeSwitchCore.2017.vcxproj b/w32/Library/FreeSwitchCore.2017.vcxproj index 12045cd190..0564441bcc 100644 --- a/w32/Library/FreeSwitchCore.2017.vcxproj +++ b/w32/Library/FreeSwitchCore.2017.vcxproj @@ -51,6 +51,7 @@ + @@ -128,7 +129,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" Disabled - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) true EnableFastChecks @@ -178,7 +179,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" Disabled - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) true EnableFastChecks @@ -219,7 +220,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" MaxSpeed - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) MultiThreadedDLL Create @@ -257,7 +258,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" MaxSpeed - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libpng;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) MultiThreadedDLL Create @@ -777,9 +778,6 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" {78b079bd-9fc7-4b9e-b4a6-96da0f00248b} - - {d6973076-9317-4ef2-a0b8-b7a18ac0713e} - {dce19daf-69ac-46db-b14a-39f0faa5db74} diff --git a/w32/curl-version.props b/w32/curl-version.props index 06675d08bf..e2995b4b6c 100644 --- a/w32/curl-version.props +++ b/w32/curl-version.props @@ -2,8 +2,8 @@ - 7.88.0 - 2 + 7.88.1 + 1 true diff --git a/w32/curl.props b/w32/curl.props index 5b306aa417..fb0abc4741 100644 --- a/w32/curl.props +++ b/w32/curl.props @@ -16,7 +16,7 @@ - $(SolutionDir)libs\curl-$(curlVersion) + $(SolutionDir)libs\curl-$(curlVersion)_$(curlBuildNumber) - - - - - - diff --git a/w32/download_libpng.props b/w32/download_libpng.props deleted file mode 100644 index faa7a17716..0000000000 --- a/w32/download_libpng.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/libks-version.props b/w32/libks-version.props index c541afa58d..f40f433372 100644 --- a/w32/libks-version.props +++ b/w32/libks-version.props @@ -5,7 +5,7 @@ 2.0.11 - 0 + 1 true diff --git a/w32/libks.props b/w32/libks.props index 781f6495f5..e2a8745272 100644 --- a/w32/libks.props +++ b/w32/libks.props @@ -10,7 +10,7 @@ - $(BaseDir)libs\libks-$(libksVersion) + $(BaseDir)libs\libks-$(libksVersion)_$(libksBuildNumber) @@ -36,7 +36,7 @@ + + + + + + + 1.6.58 + 1 + + + true + + + + + + $(libpngVersion) + + + $(libpngBuildNumber) + + + diff --git a/w32/libpng.props b/w32/libpng.props index b1521acf67..1f64248d80 100644 --- a/w32/libpng.props +++ b/w32/libpng.props @@ -1,9 +1,102 @@ - + + + + true + + + + + + + + + + + Debug + Release + libpng16d + libpng16 + + + + + libpng-$(libpngVersion)_$(libpngBuildNumber) + $(BaseDir)libs\$(libpngPkg) + $(libpngLibDir)\binaries\$(Platform)\$(LibraryConfiguration) + + https://github.com/freeswitch/windows-deps/releases/download/libpng-v$(libpngVersion)_$(libpngBuildNumber) + + + + + + + + + + + + + + + + + + + - $(SolutionDir)libs\libpng\;%(AdditionalIncludeDirectories) + + $(libpngLibDir)\include;%(AdditionalIncludeDirectories) HAVE_LIBPNG;LIBPNG_DYNAMICLIB;%(PreprocessorDefinitions) + + + $(libpngBinDir)\lib;%(AdditionalLibraryDirectories) + $(libpngLibraryFileName).lib;%(AdditionalDependencies) + - \ No newline at end of file + diff --git a/w32/libpq-version.props b/w32/libpq-version.props index 40ed99afc9..78e20e96dd 100644 --- a/w32/libpq-version.props +++ b/w32/libpq-version.props @@ -4,8 +4,8 @@ - 10.23 - 2 + 17.11 + 1 true diff --git a/w32/libpq.props b/w32/libpq.props index e55b68dc2c..7a74ff2373 100644 --- a/w32/libpq.props +++ b/w32/libpq.props @@ -10,7 +10,7 @@ - $(BaseDir)libs\libpq-$(libpqVersion) + $(BaseDir)libs\libpq-$(libpqVersion)_$(libpqBuildNumber) + - $(BaseDir)libs\rabbitmq-c-$(rabbitmq_cVersion) + $(BaseDir)libs\rabbitmq-c-$(rabbitmq_cVersion)_$(rabbitmq_cBuildNumber) + + + + + + + + + + + + + + - $(broadvoiceLibDir);$(broadvoiceLibDir)\floating\common;$(broadvoiceLibDir)\floating\bv16;$(broadvoiceLibDir)\floating\bv32;$(broadvoiceLibDir)\broadvoice;$(broadvoiceLibDir)\msvc;%(AdditionalIncludeDirectories) + $(broadvoiceLibDir)\include;$(broadvoiceLibDir)\include\broadvoice;%(AdditionalIncludeDirectories) + + $(broadvoiceLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + libbroadvoice.lib;%(AdditionalDependencies) + - \ No newline at end of file + diff --git a/w32/download_broadvoice.props b/w32/download_broadvoice.props deleted file mode 100644 index ed2c8a0200..0000000000 --- a/w32/download_broadvoice.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/download_g722_1.props b/w32/download_g722_1.props deleted file mode 100644 index 14a6c816aa..0000000000 --- a/w32/download_g722_1.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/g722_1-version.props b/w32/g722_1-version.props index c667830c03..b7a288e561 100644 --- a/w32/g722_1-version.props +++ b/w32/g722_1-version.props @@ -3,6 +3,7 @@ 0.2.0 + 1 true @@ -13,5 +14,8 @@ $(G722_1_Version) + + $(G722_1_BuildNumber) + - \ No newline at end of file + diff --git a/w32/g722_1.props b/w32/g722_1.props index 62e1652b63..b335919082 100644 --- a/w32/g722_1.props +++ b/w32/g722_1.props @@ -2,13 +2,58 @@ + - $(SolutionDir)libs\g722_1-$(G722_1_Version) + $(BaseDir)libs\g722_1-$(G722_1_Version)_$(G722_1_BuildNumber) + + + + + + + + + + - $(g722_1LibDir)\src\msvc\;$(g722_1LibDir)\src\g722_1;$(g722_1LibDir)\src\generated\;%(AdditionalIncludeDirectories) + $(g722_1LibDir)\include;$(g722_1LibDir)\include\g722_1;%(AdditionalIncludeDirectories) + + $(g722_1LibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + libg722_1.lib;%(AdditionalDependencies) + - \ No newline at end of file + From 1a11192acfbcd05f7e8611ee4810eea15efcde61 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 16 Sep 2026 22:32:02 +0300 Subject: [PATCH 13/88] [Build-System] Windows: Get ilbc v0.0.1_1 pre-compiled package from freeswitch/windows-deps releases instead of building it in tree (#3174) --- .gitignore | 1 + Freeswitch.2017.sln | 14 -- libs/win32/ilbc/libilbc.2017.vcxproj | 173 ------------------ src/mod/codecs/mod_ilbc/mod_ilbc.2017.vcxproj | 4 - w32/download_iLBC.props | 40 ---- w32/ilbc-version.props | 6 +- w32/ilbc.props | 52 +++++- 7 files changed, 54 insertions(+), 236 deletions(-) delete mode 100644 libs/win32/ilbc/libilbc.2017.vcxproj delete mode 100644 w32/download_iLBC.props diff --git a/.gitignore b/.gitignore index f6770717d5..032feaa108 100644 --- a/.gitignore +++ b/.gitignore @@ -279,6 +279,7 @@ libs/opencv-*.zip libs/broadvoice-*.zip libs/lua-*.zip libs/g722_1-*.zip +libs/ilbc-*.zip libs/SharpZipLib.*/ libs/SharpZipLib.*.nupkg libs/nasm-*/ diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index 14e239bfaf..2771e97af6 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -319,8 +319,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspeex", "libs\win32\spee EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspeexdsp", "libs\win32\speex\libspeexdsp.2017.vcxproj", "{03207781-0D1C-4DB3-A71D-45C608F28DBD}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libilbc", "libs\win32\ilbc\libilbc.2017.vcxproj", "{9A5DDF08-C88C-4A35-B7F6-D605228446BD}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_opal", "src\mod\endpoints\mod_opal\mod_opal.2017.vcxproj", "{05C9FB27-480E-4D53-B3B7-6338E2526666}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_skinny", "src\mod\endpoints\mod_skinny\mod_skinny.2017.vcxproj", "{CC1DD008-9406-448D-A0AD-33C3186CFADB}" @@ -1334,17 +1332,6 @@ Global {03207781-0D1C-4DB3-A71D-45C608F28DBD}.Release|Win32.Build.0 = Release|Win32 {03207781-0D1C-4DB3-A71D-45C608F28DBD}.Release|x64.ActiveCfg = Release|x64 {03207781-0D1C-4DB3-A71D-45C608F28DBD}.Release|x64.Build.0 = Release|x64 - {9A5DDF08-C88C-4A35-B7F6-D605228446BD}.All|Win32.ActiveCfg = Release|x64 - {9A5DDF08-C88C-4A35-B7F6-D605228446BD}.All|x64.ActiveCfg = Release|x64 - {9A5DDF08-C88C-4A35-B7F6-D605228446BD}.All|x64.Build.0 = Release|x64 - {9A5DDF08-C88C-4A35-B7F6-D605228446BD}.Debug|Win32.ActiveCfg = Debug|Win32 - {9A5DDF08-C88C-4A35-B7F6-D605228446BD}.Debug|Win32.Build.0 = Debug|Win32 - {9A5DDF08-C88C-4A35-B7F6-D605228446BD}.Debug|x64.ActiveCfg = Debug|x64 - {9A5DDF08-C88C-4A35-B7F6-D605228446BD}.Debug|x64.Build.0 = Debug|x64 - {9A5DDF08-C88C-4A35-B7F6-D605228446BD}.Release|Win32.ActiveCfg = Release|Win32 - {9A5DDF08-C88C-4A35-B7F6-D605228446BD}.Release|Win32.Build.0 = Release|Win32 - {9A5DDF08-C88C-4A35-B7F6-D605228446BD}.Release|x64.ActiveCfg = Release|x64 - {9A5DDF08-C88C-4A35-B7F6-D605228446BD}.Release|x64.Build.0 = Release|x64 {05C9FB27-480E-4D53-B3B7-6338E2526666}.All|Win32.ActiveCfg = Release|Win32 {05C9FB27-480E-4D53-B3B7-6338E2526666}.All|Win32.Build.0 = Release|Win32 {05C9FB27-480E-4D53-B3B7-6338E2526666}.All|x64.ActiveCfg = Release|Win32 @@ -2372,7 +2359,6 @@ Global {1CBB0077-18C5-455F-801C-0A0CE7B0BBF5} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {E972C52F-9E85-4D65-B19C-031E511E9DB4} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {03207781-0D1C-4DB3-A71D-45C608F28DBD} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} - {9A5DDF08-C88C-4A35-B7F6-D605228446BD} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {05C9FB27-480E-4D53-B3B7-6338E2526666} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C} {CC1DD008-9406-448D-A0AD-33C3186CFADB} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C} {48414740-C693-4968-9846-EE058020C64F} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C} diff --git a/libs/win32/ilbc/libilbc.2017.vcxproj b/libs/win32/ilbc/libilbc.2017.vcxproj deleted file mode 100644 index 23d5c3fa7e..0000000000 --- a/libs/win32/ilbc/libilbc.2017.vcxproj +++ /dev/null @@ -1,173 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - libilbc - {9A5DDF08-C88C-4A35-B7F6-D605228446BD} - libilbc - Win32Proj - - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - - - - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBilbc_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - Level4 - 4127;%(DisableSpecificWarnings) - - - - - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBilbc_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) - MultiThreadedDLL - Level4 - 4127;%(DisableSpecificWarnings) - - - - - X64 - - - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBilbc_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - Level4 - 4127;%(DisableSpecificWarnings) - - - - - X64 - - - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBilbc_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) - MultiThreadedDLL - Level4 - 4127;%(DisableSpecificWarnings) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/mod/codecs/mod_ilbc/mod_ilbc.2017.vcxproj b/src/mod/codecs/mod_ilbc/mod_ilbc.2017.vcxproj index e754881e9d..38d24f1b37 100644 --- a/src/mod/codecs/mod_ilbc/mod_ilbc.2017.vcxproj +++ b/src/mod/codecs/mod_ilbc/mod_ilbc.2017.vcxproj @@ -125,10 +125,6 @@ - - {9a5ddf08-c88c-4a35-b7f6-d605228446bd} - false - {202d7a4e-760d-4d0e-afa1-d7459ced30ff} false diff --git a/w32/download_iLBC.props b/w32/download_iLBC.props deleted file mode 100644 index 20bf9f014a..0000000000 --- a/w32/download_iLBC.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/ilbc-version.props b/w32/ilbc-version.props index 76d35e0705..5841849523 100644 --- a/w32/ilbc-version.props +++ b/w32/ilbc-version.props @@ -3,6 +3,7 @@ 0.0.1 + 1 true @@ -13,5 +14,8 @@ $(iLBC_Version) + + $(iLBC_BuildNumber) + - \ No newline at end of file + diff --git a/w32/ilbc.props b/w32/ilbc.props index 9e516c1485..36e0068692 100644 --- a/w32/ilbc.props +++ b/w32/ilbc.props @@ -2,14 +2,58 @@ + - $(SolutionDir)libs\iLBC-$(iLBC_Version) + $(BaseDir)libs\ilbc-$(iLBC_Version)_$(iLBC_BuildNumber) + + + + + + + + + + - $(iLBCLibDir)\src;$(iLBCLibDir)\src\ilbc;$(iLBCLibDir)\src\msvc;%(AdditionalIncludeDirectories) - $(SolutionDir)\libs\codec\ilbc\$(OutDir);%(AdditionalLibraryDirectories) + $(iLBCLibDir)\include;$(iLBCLibDir)\include\ilbc;%(AdditionalIncludeDirectories) + + $(iLBCLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + libilbc.lib;%(AdditionalDependencies) + - \ No newline at end of file + From 4d35c430137e90881e18b09c638459bec6370dab Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 16 Sep 2026 23:26:01 +0300 Subject: [PATCH 14/88] [Build-System] Windows: Get libsilk v1.0.9_1 pre-compiled package from freeswitch/windows-deps releases instead of building it in tree (#3175) --- .gitignore | 1 + Freeswitch.2017.sln | 14 - libs/win32/libsilk/Silk_FIX.2017.vcxproj | 271 ------------------ src/mod/codecs/mod_silk/mod_silk.2017.vcxproj | 4 - w32/download_libsilk.props | 40 --- w32/libsilk-version.props | 8 +- w32/libsilk.props | 51 +++- 7 files changed, 55 insertions(+), 334 deletions(-) delete mode 100644 libs/win32/libsilk/Silk_FIX.2017.vcxproj delete mode 100644 w32/download_libsilk.props diff --git a/.gitignore b/.gitignore index 032feaa108..9f4e691cb3 100644 --- a/.gitignore +++ b/.gitignore @@ -280,6 +280,7 @@ libs/broadvoice-*.zip libs/lua-*.zip libs/g722_1-*.zip libs/ilbc-*.zip +libs/libsilk-*.zip libs/SharpZipLib.*/ libs/SharpZipLib.*.nupkg libs/nasm-*/ diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index 2771e97af6..cee8bb0c20 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -353,8 +353,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_curl", "src\mod\applica EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_silk", "src\mod\codecs\mod_silk\mod_silk.2017.vcxproj", "{AFA983D6-4569-4F88-BA94-555ED00FD9A8}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Silk_FIX", "libs\win32\libsilk\Silk_FIX.2017.vcxproj", "{56B91D01-9150-4BBF-AFA1-5B68AB991B76}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_avmd", "src\mod\applications\mod_avmd\mod_avmd.2017.vcxproj", "{990BAA76-89D3-4E38-8479-C7B28784EFC8}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_spandsp", "src\mod\applications\mod_spandsp\mod_spandsp.2017.vcxproj", "{1E21AFE0-6FDB-41D2-942D-863607C24B91}" @@ -1500,17 +1498,6 @@ Global {AFA983D6-4569-4F88-BA94-555ED00FD9A8}.Release|Win32.Build.0 = Release|Win32 {AFA983D6-4569-4F88-BA94-555ED00FD9A8}.Release|x64.ActiveCfg = Release|x64 {AFA983D6-4569-4F88-BA94-555ED00FD9A8}.Release|x64.Build.0 = Release|x64 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.All|Win32.ActiveCfg = Release|Win32 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.All|Win32.Build.0 = Release|Win32 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.All|x64.ActiveCfg = Release|Win32 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug|Win32.ActiveCfg = Debug|Win32 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug|Win32.Build.0 = Debug|Win32 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug|x64.ActiveCfg = Debug|x64 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Debug|x64.Build.0 = Debug|x64 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Release|Win32.ActiveCfg = Release|Win32 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Release|Win32.Build.0 = Release|Win32 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Release|x64.ActiveCfg = Release|x64 - {56B91D01-9150-4BBF-AFA1-5B68AB991B76}.Release|x64.Build.0 = Release|x64 {990BAA76-89D3-4E38-8479-C7B28784EFC8}.All|Win32.ActiveCfg = Release|Win32 {990BAA76-89D3-4E38-8479-C7B28784EFC8}.All|Win32.Build.0 = Release|Win32 {990BAA76-89D3-4E38-8479-C7B28784EFC8}.All|x64.ActiveCfg = Release|Win32 @@ -2375,7 +2362,6 @@ Global {ABB71A76-42B0-47A4-973A-42E3D920C6FD} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {EF300386-A8DF-4372-B6D8-FB9BFFCA9AED} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {AFA983D6-4569-4F88-BA94-555ED00FD9A8} = {F881ADA2-2F1A-4046-9FEB-191D9422D781} - {56B91D01-9150-4BBF-AFA1-5B68AB991B76} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {990BAA76-89D3-4E38-8479-C7B28784EFC8} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {1E21AFE0-6FDB-41D2-942D-863607C24B91} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {2E250296-0C08-4342-9C8A-BCBDD0E7DF65} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} diff --git a/libs/win32/libsilk/Silk_FIX.2017.vcxproj b/libs/win32/libsilk/Silk_FIX.2017.vcxproj deleted file mode 100644 index 23dc50fdf4..0000000000 --- a/libs/win32/libsilk/Silk_FIX.2017.vcxproj +++ /dev/null @@ -1,271 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - Silk_FIX - {56B91D01-9150-4BBF-AFA1-5B68AB991B76} - Silk - Win32Proj - - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - - - - Disabled - Neither - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - Fast - Level3 - - - - - MaxSpeed - Default - Neither - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - false - false - MultiThreadedDLL - Fast - Level3 - - - - - X64 - - - Disabled - Neither - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - Fast - Level3 - - - - - - - - - X64 - - - MaxSpeed - Default - Neither - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - false - false - MultiThreadedDLL - Fast - Level3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/mod/codecs/mod_silk/mod_silk.2017.vcxproj b/src/mod/codecs/mod_silk/mod_silk.2017.vcxproj index 4a92174b83..b078b43ce5 100644 --- a/src/mod/codecs/mod_silk/mod_silk.2017.vcxproj +++ b/src/mod/codecs/mod_silk/mod_silk.2017.vcxproj @@ -126,10 +126,6 @@ - - {56b91d01-9150-4bbf-afa1-5b68ab991b76} - false - {202d7a4e-760d-4d0e-afa1-d7459ced30ff} false diff --git a/w32/download_libsilk.props b/w32/download_libsilk.props deleted file mode 100644 index dc9d99c6bb..0000000000 --- a/w32/download_libsilk.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/libsilk-version.props b/w32/libsilk-version.props index 67515cff76..18ea2041db 100644 --- a/w32/libsilk-version.props +++ b/w32/libsilk-version.props @@ -2,7 +2,8 @@ - 1.0.8 + 1.0.9 + 1 true @@ -13,5 +14,8 @@ $(libsilk_Version) + + $(libsilk_BuildNumber) + - \ No newline at end of file + diff --git a/w32/libsilk.props b/w32/libsilk.props index cafe473a2b..af85a6e5d5 100644 --- a/w32/libsilk.props +++ b/w32/libsilk.props @@ -2,13 +2,58 @@ + - $(SolutionDir)libs\libsilk-$(libsilk_Version)\src + $(BaseDir)libs\libsilk-$(libsilk_Version)_$(libsilk_BuildNumber) + + + + + + + + + + - $(libsilkLibDir)\..\interface;%(AdditionalIncludeDirectories) + $(libsilkLibDir)\include;$(libsilkLibDir)\include\silk;%(AdditionalIncludeDirectories) + + $(libsilkLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + libsilk.lib;%(AdditionalDependencies) + - \ No newline at end of file + From 31e7333e2afdc03ad4d7d231ef8a39456ddf7ceb Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 17 Sep 2026 16:45:36 +0300 Subject: [PATCH 15/88] [Build-System] Get sphinxbase, pocketsphinx and the communicator model from freeswitch/windows-deps releases instead of files.freeswitch.org, upgrade Windows build to sphinxbase/pocketsphinx v0.8 (#3176) --- debian/util.sh | 6 +- freeswitch.spec | 6 +- .../pocketsphinx/pocketsphinx.2017.vcxproj | 122 ++++---- libs/win32/sphinxbase/sphinxbase.2017.vcxproj | 267 ++++++++++-------- scripts/freeswitch.pkg_deps.sh | 2 +- .../mod_pocketsphinx.2017.vcxproj | 5 +- w32/download_pocketsphinx.props | 5 +- w32/download_sphinxbase.props | 5 +- w32/download_sphinxmodel.props | 2 +- w32/pocketsphinx-version.props | 2 +- w32/pocketsphinx.props | 2 +- w32/sphinxbase-version.props | 19 ++ w32/sphinxbase.props | 17 ++ 13 files changed, 265 insertions(+), 195 deletions(-) create mode 100644 w32/sphinxbase-version.props create mode 100644 w32/sphinxbase.props diff --git a/debian/util.sh b/debian/util.sh index 5f3dadcc20..2a826cf63c 100755 --- a/debian/util.sh +++ b/debian/util.sh @@ -100,9 +100,9 @@ getlib () { getlibs () { # get pinned libraries - getlib http://files.freeswitch.org/downloads/libs/sphinxbase-0.8.tar.gz - getlib http://files.freeswitch.org/downloads/libs/pocketsphinx-0.8.tar.gz - getlib http://files.freeswitch.org/downloads/libs/communicator_semi_6000_20080321.tar.gz + getlib https://github.com/freeswitch/windows-deps/releases/download/sphinxbase-0.8/sphinxbase-0.8.tar.gz + getlib https://github.com/freeswitch/windows-deps/releases/download/pocketsphinx-0.8/pocketsphinx-0.8.tar.gz + getlib https://github.com/freeswitch/windows-deps/releases/download/communicator_semi_6000_20080321/communicator_semi_6000_20080321.tar.gz #getlib http://download.zeromq.org/zeromq-2.1.9.tar.gz \ # || getlib http://download.zeromq.org/historic/zeromq-2.1.9.tar.gz #getlib http://files.freeswitch.org/downloads/libs/v8-3.24.14.tar.bz2 diff --git a/freeswitch.spec b/freeswitch.spec index 50cbe8ec96..8c0597701d 100755 --- a/freeswitch.spec +++ b/freeswitch.spec @@ -110,9 +110,9 @@ Vendor: http://www.freeswitch.org/ # ###################################################################################################################### Source0: http://files.freeswitch.org/%{name}-%{nonparsedversion}.tar.bz2 -Source1: http://files.freeswitch.org/downloads/libs/communicator_semi_6000_20080321.tar.gz -Source2: http://files.freeswitch.org/downloads/libs/pocketsphinx-0.8.tar.gz -Source3: http://files.freeswitch.org/downloads/libs/sphinxbase-0.8.tar.gz +Source1: https://github.com/freeswitch/windows-deps/releases/download/communicator_semi_6000_20080321/communicator_semi_6000_20080321.tar.gz +Source2: https://github.com/freeswitch/windows-deps/releases/download/pocketsphinx-0.8/pocketsphinx-0.8.tar.gz +Source3: https://github.com/freeswitch/windows-deps/releases/download/sphinxbase-0.8/sphinxbase-0.8.tar.gz Prefix: %{prefix} diff --git a/libs/win32/pocketsphinx/pocketsphinx.2017.vcxproj b/libs/win32/pocketsphinx/pocketsphinx.2017.vcxproj index bc3c995e7d..3d3ef0a07d 100644 --- a/libs/win32/pocketsphinx/pocketsphinx.2017.vcxproj +++ b/libs/win32/pocketsphinx/pocketsphinx.2017.vcxproj @@ -24,6 +24,8 @@ pocketsphinx + + DynamicLibrary @@ -88,7 +90,6 @@ MaxSpeed OnlyExplicitInline - ../../../include;../../../../sphinxbase/include;../../../../sphinxbase/include/win32;..\..\pocketsphinx-0.7/src/libpocketsphinx;..\..\sphinxbase-0.7\include;..\..\pocketsphinx-0.7\include;%(AdditionalIncludeDirectories) NDEBUG;WIN32;_WINDOWS;_USRDLL;POCKETSPHINX_EXPORTS;SPHINXDLL;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -118,7 +119,6 @@ MaxSpeed OnlyExplicitInline - ../../../include;../../../../sphinxbase/include;../../../../sphinxbase/include/win32;..\..\pocketsphinx-0.7/src/libpocketsphinx;..\..\sphinxbase-0.7\include;..\..\pocketsphinx-0.7\include;%(AdditionalIncludeDirectories) NDEBUG;WIN32;_WINDOWS;_USRDLL;POCKETSPHINX_EXPORTS;SPHINXDLL;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -148,7 +148,6 @@ Disabled - ../../../include;../../../../sphinxbase/include;../../../../sphinxbase/include/win32;..\..\pocketsphinx-0.7/src/libpocketsphinx;..\..\sphinxbase-0.7\include;..\..\pocketsphinx-0.7\include;%(AdditionalIncludeDirectories) _DEBUG;WIN32;_WINDOWS;_USRDLL;POCKETSPHINX_EXPORTS;SPHINXDLL;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true EnableFastChecks @@ -182,7 +181,6 @@ Disabled - ../../../include;../../../../sphinxbase/include;../../../../sphinxbase/include/win32;..\..\pocketsphinx-0.7/src/libpocketsphinx;..\..\sphinxbase-0.7\include;..\..\pocketsphinx-0.7\include;%(AdditionalIncludeDirectories) _DEBUG;WIN32;_WINDOWS;_USRDLL;POCKETSPHINX_EXPORTS;SPHINXDLL;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true EnableFastChecks @@ -208,47 +206,47 @@ - - - + + + - - - - - - - + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -258,7 +256,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -268,9 +266,9 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - - - + + + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -280,7 +278,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -290,7 +288,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -300,7 +298,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -310,7 +308,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -320,7 +318,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -330,7 +328,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -340,7 +338,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -350,15 +348,15 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - - - - - - - - - + + + + + + + + + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -368,7 +366,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -378,7 +376,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) diff --git a/libs/win32/sphinxbase/sphinxbase.2017.vcxproj b/libs/win32/sphinxbase/sphinxbase.2017.vcxproj index b6740664a8..f6cfd655b4 100644 --- a/libs/win32/sphinxbase/sphinxbase.2017.vcxproj +++ b/libs/win32/sphinxbase/sphinxbase.2017.vcxproj @@ -24,6 +24,7 @@ sphinxbase + @@ -89,7 +90,6 @@ MaxSpeed OnlyExplicitInline - ..\..\sphinxbase-0.7\include\win32;..\..\sphinxbase-0.7\include;%(AdditionalIncludeDirectories) NDEBUG;WIN32;_WINDOWS;_USRDLL;SPHINXBASE_EXPORTS;HAVE_CONFIG_H;SPHINXDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -119,7 +119,6 @@ MaxSpeed OnlyExplicitInline - ..\..\sphinxbase-0.7\include\win32;..\..\sphinxbase-0.7\include;%(AdditionalIncludeDirectories) NDEBUG;WIN32;_WINDOWS;_USRDLL;SPHINXBASE_EXPORTS;HAVE_CONFIG_H;SPHINXDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -149,7 +148,6 @@ Disabled - ..\..\sphinxbase-0.7\include\win32;..\..\sphinxbase-0.7\include;%(AdditionalIncludeDirectories) _DEBUG;WIN32;_WINDOWS;_USRDLL;SPHINXBASE_EXPORTS;HAVE_CONFIG_H;SPHINXDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true EnableFastChecks @@ -182,7 +180,6 @@ Disabled - ..\..\sphinxbase-0.7\include\win32;..\..\sphinxbase-0.7\include;%(AdditionalIncludeDirectories) _DEBUG;WIN32;_WINDOWS;_USRDLL;SPHINXBASE_EXPORTS;HAVE_CONFIG_H;SPHINXDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true EnableFastChecks @@ -207,7 +204,7 @@ - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -217,7 +214,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -227,7 +224,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -237,7 +234,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -247,7 +244,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -257,7 +254,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -267,7 +264,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -277,7 +274,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -287,7 +284,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -297,7 +294,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -307,8 +304,8 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - - + + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -318,7 +315,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -328,7 +325,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -338,7 +335,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -348,7 +345,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -358,7 +355,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -368,7 +365,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -378,7 +375,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -388,7 +385,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -398,7 +395,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -408,7 +405,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -418,8 +415,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -429,7 +425,8 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -439,7 +436,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -449,7 +446,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -459,7 +456,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -469,10 +466,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - - - - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -482,10 +476,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - - - - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -495,13 +486,10 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - - - - - - - + + + + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -511,7 +499,10 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + + + + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -521,7 +512,13 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + + + + + + + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -531,7 +528,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -541,8 +538,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -552,7 +548,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -562,7 +558,8 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -572,7 +569,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) %(AdditionalIncludeDirectories) @@ -582,68 +579,108 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/freeswitch.pkg_deps.sh b/scripts/freeswitch.pkg_deps.sh index d057083993..45add46dd8 100755 --- a/scripts/freeswitch.pkg_deps.sh +++ b/scripts/freeswitch.pkg_deps.sh @@ -15,6 +15,6 @@ wget -c https://github.com/freeswitch/freeswitch-sounds/releases/download/en-us- wget -c https://github.com/freeswitch/freeswitch-sounds/releases/download/en-us-callie-1.0.53/freeswitch-sounds-en-us-callie-16000-1.0.53.tar.gz wget -c https://github.com/freeswitch/freeswitch-sounds/releases/download/en-us-callie-1.0.53/freeswitch-sounds-en-us-callie-32000-1.0.53.tar.gz wget -c https://github.com/freeswitch/freeswitch-sounds/releases/download/en-us-callie-1.0.53/freeswitch-sounds-en-us-callie-48000-1.0.53.tar.gz -wget -c http://svn.freeswitch.org/downloads/libs/communicator_semi_6000_20080321.tar.gz +wget -c https://github.com/freeswitch/windows-deps/releases/download/communicator_semi_6000_20080321/communicator_semi_6000_20080321.tar.gz diff --git a/src/mod/asr_tts/mod_pocketsphinx/mod_pocketsphinx.2017.vcxproj b/src/mod/asr_tts/mod_pocketsphinx/mod_pocketsphinx.2017.vcxproj index 05c38b75ca..f82fb70d67 100644 --- a/src/mod/asr_tts/mod_pocketsphinx/mod_pocketsphinx.2017.vcxproj +++ b/src/mod/asr_tts/mod_pocketsphinx/mod_pocketsphinx.2017.vcxproj @@ -49,6 +49,7 @@ + @@ -78,7 +79,6 @@ Disabled - ..\..\..\..\libs\sphinxbase-0.7\include;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS;%(PreprocessorDefinitions) true EnableFastChecks @@ -104,7 +104,6 @@ Disabled - ..\..\..\..\libs\sphinxbase-0.7\include;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS;%(PreprocessorDefinitions) true EnableFastChecks @@ -127,7 +126,6 @@ MaxSpeed true - ..\..\..\..\libs\sphinxbase-0.7\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS;%(PreprocessorDefinitions) MultiThreadedDLL true @@ -157,7 +155,6 @@ MaxSpeed true - ..\..\..\..\libs\sphinxbase-0.7\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_POCKETSPHINX_EXPORTS;%(PreprocessorDefinitions) MultiThreadedDLL true diff --git a/w32/download_pocketsphinx.props b/w32/download_pocketsphinx.props index 87c99f57fa..acdd0709aa 100644 --- a/w32/download_pocketsphinx.props +++ b/w32/download_pocketsphinx.props @@ -1,6 +1,7 @@ + @@ -29,8 +30,8 @@ + @@ -29,8 +30,8 @@ 0 - 0.7 + 0.8 true diff --git a/w32/pocketsphinx.props b/w32/pocketsphinx.props index 623e36354f..f86c817c54 100644 --- a/w32/pocketsphinx.props +++ b/w32/pocketsphinx.props @@ -10,7 +10,7 @@ - $(pocketsphinx_libDir)\include;%(AdditionalIncludeDirectories) + $(pocketsphinx_libDir)\include;$(pocketsphinx_libDir)\src\libpocketsphinx;%(AdditionalIncludeDirectories) POCKETSPHINX_MAJOR_VERSION=$(pocketsphinxMajorVersion);%(PreprocessorDefinitions) diff --git a/w32/sphinxbase-version.props b/w32/sphinxbase-version.props new file mode 100644 index 0000000000..55ede42d32 --- /dev/null +++ b/w32/sphinxbase-version.props @@ -0,0 +1,19 @@ + + + + + + + 0.8 + + + true + + + + + + $(sphinxbaseVersion) + + + diff --git a/w32/sphinxbase.props b/w32/sphinxbase.props new file mode 100644 index 0000000000..b5eab97095 --- /dev/null +++ b/w32/sphinxbase.props @@ -0,0 +1,17 @@ + + + + + + + + $(BaseDir)libs\sphinxbase-$(sphinxbaseVersion) + + + + + $(sphinxbase_libDir)\include\win32;$(sphinxbase_libDir)\include;%(AdditionalIncludeDirectories) + + + + From bea7c0f81033b5f60052c30a0205393b0ccbb064 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 17 Sep 2026 19:06:14 +0300 Subject: [PATCH 16/88] [Build-System] Windows: Upgrade lame to v3.101_1 and libtiff to v4.7.2_1 and use pre-compiled binaries (#3179) --- .gitignore | 4 + Freeswitch.2017.sln | 28 -- libs/win32/libmp3lame/config.h | 120 ----- libs/win32/libmp3lame/libmp3lame.2017.vcxproj | 473 ------------------ libs/win32/libtiff/libtiff.2017.vcxproj | 207 -------- libs/win32/spandsp/libspandsp.2017.vcxproj | 4 - .../formats/mod_shout/mod_shout.2017.vcxproj | 13 +- w32/download_LAME.props | 40 -- w32/download_tiff.props | 40 -- w32/lame-version.props | 21 + w32/lame.props | 59 +++ w32/tiff-version.props | 8 +- w32/tiff.props | 61 ++- 13 files changed, 152 insertions(+), 926 deletions(-) delete mode 100644 libs/win32/libmp3lame/config.h delete mode 100644 libs/win32/libmp3lame/libmp3lame.2017.vcxproj delete mode 100644 libs/win32/libtiff/libtiff.2017.vcxproj delete mode 100644 w32/download_LAME.props delete mode 100644 w32/download_tiff.props create mode 100644 w32/lame-version.props create mode 100644 w32/lame.props diff --git a/.gitignore b/.gitignore index 9f4e691cb3..34c37949f2 100644 --- a/.gitignore +++ b/.gitignore @@ -281,6 +281,10 @@ libs/lua-*.zip libs/g722_1-*.zip libs/ilbc-*.zip libs/libsilk-*.zip +libs/libtiff-*/ +libs/libtiff-*.zip +libs/lame-*/ +libs/lame-*.zip libs/SharpZipLib.*/ libs/SharpZipLib.*.nupkg libs/nasm-*/ diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index cee8bb0c20..e2a0fa7597 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -278,8 +278,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "32khz", "libs\win32\Sound_F EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_flite", "src\mod\asr_tts\mod_flite\mod_flite.2017.vcxproj", "{66444AEE-554C-11DD-A9F0-8C5D56D89593}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmp3lame", "libs\win32\libmp3lame\libmp3lame.2017.vcxproj", "{E316772F-5D8F-4F2A-8F71-094C3E859D34}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libshout", "libs\win32\libshout\libshout.2017.vcxproj", "{D3D8B329-20BE-475E-9E83-653CEA0E0EF5}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_shout", "src\mod\formats\mod_shout\mod_shout.2017.vcxproj", "{38FE0559-9910-43A8-9E45-3E5004C27692}" @@ -311,8 +309,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_easyroute", "src\mod\ap EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_lcr", "src\mod\applications\mod_lcr\mod_lcr.2017.vcxproj", "{1A3793D1-05D1-4B57-9B0F-5AF3E79DC439}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtiff", "libs\win32\libtiff\libtiff.2017.vcxproj", "{401A40CD-5DB4-4E34-AC68-FA99E9FAC014}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspandsp", "libs\win32\spandsp\libspandsp.2017.vcxproj", "{1CBB0077-18C5-455F-801C-0A0CE7B0BBF5}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspeex", "libs\win32\speex\libspeex.2017.vcxproj", "{E972C52F-9E85-4D65-B19C-031E511E9DB4}" @@ -1121,17 +1117,6 @@ Global {66444AEE-554C-11DD-A9F0-8C5D56D89593}.Release|Win32.Build.0 = Release|Win32 {66444AEE-554C-11DD-A9F0-8C5D56D89593}.Release|x64.ActiveCfg = Release|x64 {66444AEE-554C-11DD-A9F0-8C5D56D89593}.Release|x64.Build.0 = Release|x64 - {E316772F-5D8F-4F2A-8F71-094C3E859D34}.All|Win32.ActiveCfg = Debug|x64 - {E316772F-5D8F-4F2A-8F71-094C3E859D34}.All|x64.ActiveCfg = Debug|x64 - {E316772F-5D8F-4F2A-8F71-094C3E859D34}.All|x64.Build.0 = Debug|x64 - {E316772F-5D8F-4F2A-8F71-094C3E859D34}.Debug|Win32.ActiveCfg = Debug|Win32 - {E316772F-5D8F-4F2A-8F71-094C3E859D34}.Debug|Win32.Build.0 = Debug|Win32 - {E316772F-5D8F-4F2A-8F71-094C3E859D34}.Debug|x64.ActiveCfg = Debug|x64 - {E316772F-5D8F-4F2A-8F71-094C3E859D34}.Debug|x64.Build.0 = Debug|x64 - {E316772F-5D8F-4F2A-8F71-094C3E859D34}.Release|Win32.ActiveCfg = Release|Win32 - {E316772F-5D8F-4F2A-8F71-094C3E859D34}.Release|Win32.Build.0 = Release|Win32 - {E316772F-5D8F-4F2A-8F71-094C3E859D34}.Release|x64.ActiveCfg = Release|x64 - {E316772F-5D8F-4F2A-8F71-094C3E859D34}.Release|x64.Build.0 = Release|x64 {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.All|Win32.ActiveCfg = Debug|x64 {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.All|x64.ActiveCfg = Debug|x64 {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.All|x64.Build.0 = Debug|x64 @@ -1285,17 +1270,6 @@ Global {1A3793D1-05D1-4B57-9B0F-5AF3E79DC439}.Release|Win32.Build.0 = Release|Win32 {1A3793D1-05D1-4B57-9B0F-5AF3E79DC439}.Release|x64.ActiveCfg = Release|x64 {1A3793D1-05D1-4B57-9B0F-5AF3E79DC439}.Release|x64.Build.0 = Release|x64 - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014}.All|Win32.ActiveCfg = Release|x64 - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014}.All|x64.ActiveCfg = Release|x64 - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014}.All|x64.Build.0 = Release|x64 - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014}.Debug|Win32.ActiveCfg = Debug|Win32 - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014}.Debug|Win32.Build.0 = Debug|Win32 - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014}.Debug|x64.ActiveCfg = Debug|x64 - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014}.Debug|x64.Build.0 = Debug|x64 - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014}.Release|Win32.ActiveCfg = Release|Win32 - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014}.Release|Win32.Build.0 = Release|Win32 - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014}.Release|x64.ActiveCfg = Release|x64 - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014}.Release|x64.Build.0 = Release|x64 {1CBB0077-18C5-455F-801C-0A0CE7B0BBF5}.All|Win32.ActiveCfg = Release|x64 {1CBB0077-18C5-455F-801C-0A0CE7B0BBF5}.All|x64.ActiveCfg = Release|x64 {1CBB0077-18C5-455F-801C-0A0CE7B0BBF5}.All|x64.Build.0 = Release|x64 @@ -2328,7 +2302,6 @@ Global {7EB71250-F002-4ED8-92CA-CA218114537A} = {4F227C26-768F-46A3-8684-1D08A46FB374} {464AAB78-5489-4916-BE51-BF8D61822311} = {4F227C26-768F-46A3-8684-1D08A46FB374} {66444AEE-554C-11DD-A9F0-8C5D56D89593} = {4CF6A6AC-07DE-4B9E-ABE1-7F98B64E0BB0} - {E316772F-5D8F-4F2A-8F71-094C3E859D34} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {D3D8B329-20BE-475E-9E83-653CEA0E0EF5} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {38FE0559-9910-43A8-9E45-3E5004C27692} = {A5A27244-AD24-46E5-B01B-840CD296C91D} {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} @@ -2342,7 +2315,6 @@ Global {CF405366-9558-4AE8-90EF-5E21B51CCB4E} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {329FD5B0-EF28-4606-86D0-F6EA21CF8E36} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {1A3793D1-05D1-4B57-9B0F-5AF3E79DC439} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {1CBB0077-18C5-455F-801C-0A0CE7B0BBF5} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {E972C52F-9E85-4D65-B19C-031E511E9DB4} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {03207781-0D1C-4DB3-A71D-45C608F28DBD} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} diff --git a/libs/win32/libmp3lame/config.h b/libs/win32/libmp3lame/config.h deleted file mode 100644 index 67e88fecfa..0000000000 --- a/libs/win32/libmp3lame/config.h +++ /dev/null @@ -1,120 +0,0 @@ -/* The number of bytes in a double. */ -#define SIZEOF_DOUBLE 8 - -/* The number of bytes in a float. */ -#define SIZEOF_FLOAT 4 - -/* The number of bytes in a int. */ -#define SIZEOF_INT 4 - -/* The number of bytes in a long. */ -#define SIZEOF_LONG 4 - -/* The number of bytes in a long double. */ -#define SIZEOF_LONG_DOUBLE 12 - -/* The number of bytes in a short. */ -#define SIZEOF_SHORT 2 - -/* The number of bytes in a unsigned int. */ -#define SIZEOF_UNSIGNED_INT 4 - -/* The number of bytes in a unsigned long. */ -#define SIZEOF_UNSIGNED_LONG 4 - -/* The number of bytes in a unsigned short. */ -#define SIZEOF_UNSIGNED_SHORT 2 - -/* Define if you have the ANSI C header files. */ -#define STDC_HEADERS - -/* Define if you have the header file. */ -#define HAVE_ERRNO_H - -/* Define if you have the header file. */ -#define HAVE_FCNTL_H - -/* Define if you have the header file. */ -#define HAVE_LIMITS_H - -/* Name of package */ -#define PACKAGE "lame" - -/* Version number of package */ -#define VERSION "3.97" - -/* Define if compiler has function prototypes */ -#define PROTOTYPES 1 - -/* enable VBR bitrate histogram */ -#define BRHIST 1 - -/* IEEE754 compatible machine */ -#define TAKEHIRO_IEEE754_HACK 1 - -/* faster log implementation with less but enough precission */ -#define USE_FAST_LOG 1 - -#define HAVE_STRCHR -#define HAVE_MEMCPY - -#if defined(_MSC_VER) || defined(__BORLANDC__) -#pragma warning( disable : 4305 ) - typedef __int8 int8_t; - typedef __int16 int16_t; - typedef __int32 int32_t; - typedef __int64 int64_t; - - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; - typedef unsigned __int64 uint64_t; - - typedef float float32_t; - typedef double float64_t; -#elif defined (__GNUC__) -#define __int8_t_defined -#define uint8_t unsigned char -#define uint16_t unsigned short -#define uint32_t unsigned int -#define uint64_t unsigned long long - -#define int8_t signed char -#define int16_t signed short -#define int32_t signed int -#define int64_t signed long long -#endif - -typedef long double ieee854_float80_t; -typedef double ieee754_float64_t; -typedef float ieee754_float32_t; - -#ifdef HAVE_MPGLIB -# define DECODE_ON_THE_FLY 1 -#endif - -#ifdef LAME_ACM -/* memory hacking for driver purposes */ -#define calloc(x,y) acm_Calloc(x,y) -#define free(x) acm_Free(x) -#define malloc(x) acm_Malloc(x) - -#include -void *acm_Calloc( size_t num, size_t size ); -void *acm_Malloc( size_t size ); -void acm_Free( void * mem); -#endif /* LAME_ACM */ - -#define LAME_LIBRARY_BUILD - - -#ifdef HAVE_NASM - #if (defined(__ICL) && (__ICL >= 450)) - #define HAVE_XMMINTRIN_H - #elif defined(_MSC_VER) - #include - #ifdef _mm_malloc - #define HAVE_XMMINTRIN_H - #endif - #endif -#endif diff --git a/libs/win32/libmp3lame/libmp3lame.2017.vcxproj b/libs/win32/libmp3lame/libmp3lame.2017.vcxproj deleted file mode 100644 index cd039c4797..0000000000 --- a/libs/win32/libmp3lame/libmp3lame.2017.vcxproj +++ /dev/null @@ -1,473 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - libmp3lame - {E316772F-5D8F-4F2A-8F71-094C3E859D34} - libmp3lame - - - - StaticLibrary - false - $(DefaultPlatformToolset) - - - StaticLibrary - false - $(DefaultPlatformToolset) - - - StaticLibrary - false - $(DefaultPlatformToolset) - - - StaticLibrary - false - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - - - - /GAy %(AdditionalOptions) - MaxSpeed - .;..\..\lame-3.98.4;..\..\lame-3.98.4\include;%(AdditionalIncludeDirectories) - NDEBUG;_WINDOWS;WIN32;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - MultiThreaded - true - TurnOffAllWarnings - true - - - 0x0409 - - - $(OutDir)libmp3lame.lib - true - - - - - X64 - - - /GAy %(AdditionalOptions) - MaxSpeed - .;..\..\lame-3.98.4;..\..\lame-3.98.4\include;%(AdditionalIncludeDirectories) - NDEBUG;_WINDOWS;WIN32;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - MultiThreaded - true - TurnOffAllWarnings - true - - - 0x0409 - - - $(OutDir)libmp3lame.lib - true - - - - - Disabled - .;..\..\lame-3.98.4;..\..\lame-3.98.4\include;%(AdditionalIncludeDirectories) - _DEBUG;_WINDOWS;WIN32;HAVE_CONFIG_H;%(PreprocessorDefinitions) - MultiThreadedDebug - TurnOffAllWarnings - true - - - 0x0409 - - - $(OutDir)libmp3lame.lib - true - - - - - X64 - - - Disabled - .;..\..\lame-3.98.4;..\..\lame-3.98.4\include;%(AdditionalIncludeDirectories) - _DEBUG;_WINDOWS;WIN32;HAVE_CONFIG_H;%(PreprocessorDefinitions) - MultiThreadedDebug - TurnOffAllWarnings - true - - - 0x0409 - - - $(OutDir)libmp3lame.lib - true - - - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Level1 - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Level1 - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Level1 - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Level1 - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Disabled - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - MaxSpeed - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/libs/win32/libtiff/libtiff.2017.vcxproj b/libs/win32/libtiff/libtiff.2017.vcxproj deleted file mode 100644 index b81974e7b5..0000000000 --- a/libs/win32/libtiff/libtiff.2017.vcxproj +++ /dev/null @@ -1,207 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - libtiff - {401A40CD-5DB4-4E34-AC68-FA99E9FAC014} - libtiff - Win32Proj - - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(PlatformName)\libtiff\$(Configuration)\ - $(PlatformName)\libtiff\$(Configuration)\ - $(PlatformName)\libtiff\$(Configuration)\ - $(PlatformName)\libtiff\$(Configuration)\ - - - - $(IntDir)BuildLog $(ProjectName).htm - - - if not exist "$(TiffDir)/tiffconf.h" copy "$(TiffDir)\tiffconf.vc.h" "$(TiffDir)\tiffconf.h" /Y -if not exist "$(TiffDir)/tif_config.h" copy "$(TiffDir)\tif_config.vc.h" "$(TiffDir)\tif_config.h" /Y - - - - .;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;FILLODER_LSB2MSB;TIF_PLATFORM_CONSOLE;CCITT_SUPPORT;PACKBITS_SUPPORT;LZW_SUPPORT;THUNDER_SUPPORT;NEXT_SUPPORT;LOGLUV_SUPPORT;TRIPCHOP_DEFAULT=TIFF_STRIPCHOP;STRIP_SIZE_DEFAULT=8192;DEFAULT_EXTRASAMPLE_AS_ALPHA;CHECK_JPEG_YCBCR_SUBSAMPLING;AVOID_WIN32_FILEIO;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - TurnOffAllWarnings - CompileAsC - Disabled - - - - - if not exist "$(TiffDir)/tiffconf.h" copy "$(TiffDir)\tiffconf.vc.h" "$(TiffDir)\tiffconf.h" /Y -if not exist "$(TiffDir)/tif_config.h" copy "$(TiffDir)\tif_config.vc.h" "$(TiffDir)\tif_config.h" /Y - - - - X64 - - - Disabled - .;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;FILLODER_LSB2MSB;TIF_PLATFORM_CONSOLE;CCITT_SUPPORT;PACKBITS_SUPPORT;LZW_SUPPORT;THUNDER_SUPPORT;NEXT_SUPPORT;LOGLUV_SUPPORT;TRIPCHOP_DEFAULT=TIFF_STRIPCHOP;STRIP_SIZE_DEFAULT=8192;DEFAULT_EXTRASAMPLE_AS_ALPHA;CHECK_JPEG_YCBCR_SUBSAMPLING;AVOID_WIN32_FILEIO;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - TurnOffAllWarnings - CompileAsC - - - - - $(IntDir)BuildLog $(ProjectName).htm - - - if not exist "$(TiffDir)/tiffconf.h" copy "$(TiffDir)\tiffconf.vc.h" "$(TiffDir)\tiffconf.h" /Y -if not exist "$(TiffDir)/tif_config.h" copy "$(TiffDir)\tif_config.vc.h" "$(TiffDir)\tif_config.h" /Y - - - - .;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;FILLODER_LSB2MSB;TIF_PLATFORM_CONSOLE;CCITT_SUPPORT;PACKBITS_SUPPORT;LZW_SUPPORT;THUNDER_SUPPORT;NEXT_SUPPORT;LOGLUV_SUPPORT;TRIPCHOP_DEFAULT=TIFF_STRIPCHOP;STRIP_SIZE_DEFAULT=8192;DEFAULT_EXTRASAMPLE_AS_ALPHA;CHECK_JPEG_YCBCR_SUBSAMPLING;AVOID_WIN32_FILEIO;%(PreprocessorDefinitions) - MultiThreadedDLL - TurnOffAllWarnings - - - - - if not exist "$(TiffDir)/tiffconf.h" copy "$(TiffDir)\tiffconf.vc.h" "$(TiffDir)\tiffconf.h" /Y -if not exist "$(TiffDir)/tif_config.h" copy "$(TiffDir)\tif_config.vc.h" "$(TiffDir)\tif_config.h" /Y - - - - X64 - - - .;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;FILLODER_LSB2MSB;TIF_PLATFORM_CONSOLE;CCITT_SUPPORT;PACKBITS_SUPPORT;LZW_SUPPORT;THUNDER_SUPPORT;NEXT_SUPPORT;LOGLUV_SUPPORT;TRIPCHOP_DEFAULT=TIFF_STRIPCHOP;STRIP_SIZE_DEFAULT=8192;DEFAULT_EXTRASAMPLE_AS_ALPHA;CHECK_JPEG_YCBCR_SUBSAMPLING;AVOID_WIN32_FILEIO;%(PreprocessorDefinitions) - MultiThreadedDLL - TurnOffAllWarnings - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/libs/win32/spandsp/libspandsp.2017.vcxproj b/libs/win32/spandsp/libspandsp.2017.vcxproj index b97c7fa2a8..2010c70166 100644 --- a/libs/win32/spandsp/libspandsp.2017.vcxproj +++ b/libs/win32/spandsp/libspandsp.2017.vcxproj @@ -459,10 +459,6 @@ true false - - {401a40cd-5db4-4e34-ac68-fa99e9fac014} - false - {dee932ab-5911-4700-9eeb-8c7090a0a330} false diff --git a/src/mod/formats/mod_shout/mod_shout.2017.vcxproj b/src/mod/formats/mod_shout/mod_shout.2017.vcxproj index 66a47191f9..10a06d52ad 100644 --- a/src/mod/formats/mod_shout/mod_shout.2017.vcxproj +++ b/src/mod/formats/mod_shout/mod_shout.2017.vcxproj @@ -47,6 +47,7 @@ $(DefaultPlatformToolset) + @@ -74,7 +75,7 @@ Disabled - ../../../../libs/lame-3.98.4/include;..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) + ..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) _TIMESPEC_DEFINED;%(PreprocessorDefinitions) true EnableFastChecks @@ -95,7 +96,7 @@ Disabled - ../../../../libs/lame-3.98.4/include;..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) + ..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) %(PreprocessorDefinitions) true EnableFastChecks @@ -114,7 +115,7 @@ MaxSpeed true - ../../../../libs/lame-3.98.4/include;..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) + ..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) _TIMESPEC_DEFINED;%(PreprocessorDefinitions) MultiThreadedDLL true @@ -137,7 +138,7 @@ MaxSpeed true - ../../../../libs/lame-3.98.4/include;..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) + ..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) %(PreprocessorDefinitions) MultiThreadedDLL true @@ -162,10 +163,6 @@ - - {e316772f-5d8f-4f2a-8f71-094c3e859d34} - false - {0feeaec6-4399-4c46-b7db-62ece80d15b4} diff --git a/w32/download_LAME.props b/w32/download_LAME.props deleted file mode 100644 index c3f5177665..0000000000 --- a/w32/download_LAME.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/download_tiff.props b/w32/download_tiff.props deleted file mode 100644 index 5b2e0a09af..0000000000 --- a/w32/download_tiff.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/lame-version.props b/w32/lame-version.props new file mode 100644 index 0000000000..1cddf91019 --- /dev/null +++ b/w32/lame-version.props @@ -0,0 +1,21 @@ + + + + + 3.101 + 1 + + + true + + + + + + $(LameVersion) + + + $(LameBuildNumber) + + + diff --git a/w32/lame.props b/w32/lame.props new file mode 100644 index 0000000000..d32b61f306 --- /dev/null +++ b/w32/lame.props @@ -0,0 +1,59 @@ + + + + + + + + $(BaseDir)libs\lame-$(LameVersion)_$(LameBuildNumber) + + + + + + + + + + + + + + $(LameLibDir)\include;$(LameLibDir)\include\lame;%(AdditionalIncludeDirectories) + + + $(LameLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + libmp3lame.lib;%(AdditionalDependencies) + + + diff --git a/w32/tiff-version.props b/w32/tiff-version.props index 3378831aea..363dd7479c 100644 --- a/w32/tiff-version.props +++ b/w32/tiff-version.props @@ -2,7 +2,8 @@ - 4.0.7 + 4.7.2 + 1 true @@ -13,5 +14,8 @@ $(TiffVersion) + + $(TiffBuildNumber) + - \ No newline at end of file + diff --git a/w32/tiff.props b/w32/tiff.props index 2978d52e42..69aff2b250 100644 --- a/w32/tiff.props +++ b/w32/tiff.props @@ -2,14 +2,67 @@ + - $(SolutionDir)libs\tiff-$(TiffVersion) - $(TiffLibDir)\libtiff + $(BaseDir)libs\libtiff-$(TiffVersion)_$(TiffBuildNumber) + Debug + Release + Release + tiffd + tiff + + + + + + + + + + + - $(TiffDir);%(AdditionalIncludeDirectories) + $(TiffLibDir)\include;%(AdditionalIncludeDirectories) - \ No newline at end of file + + + $(TiffLibDir)\binaries\$(Platform)\$(LibraryConfiguration);%(AdditionalLibraryDirectories) + $(TiffLibraryFileName).lib;%(AdditionalDependencies) + + + From 501965c547a918183535f5a7f9c876a58860c875 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 18 Sep 2026 14:34:54 +0300 Subject: [PATCH 17/88] [Build-System] Windows: Upgrade libshout to v2.4.6_1, mpg123 to v1.33.7_1, libogg to v1.3.6_1, and use pre-compiled packages for them and for pthreads-w32 v2.9.1_1 (#3180) --- .gitignore | 8 + Freeswitch.2017.sln | 56 - libs/win32/libogg/libogg.2017.vcxproj | 204 --- libs/win32/libshout/compat.h | 1 - libs/win32/libshout/libshout.2017.vcxproj | 192 --- libs/win32/libshout/shout/shout.h | 220 --- libs/win32/mpg123/libmpg123.2017.vcxproj | 1332 ----------------- libs/win32/mpg123/libmpg123/config.h | 35 - libs/win32/mpg123/libmpg123/mpg123.h | 790 ---------- libs/win32/pthread/cleancount | 1 - libs/win32/pthread/pthread.2017.vcxproj | 451 ------ .../sofia/libsofia_sip_ua_static.2017.vcxproj | 13 +- .../mod_sofia/mod_sofia.2017.vcxproj | 5 +- .../mod_verto/mod_verto.2017.vcxproj | 13 +- .../formats/mod_shout/mod_shout.2017.vcxproj | 21 +- w32/download_OGG.props | 40 - w32/download_libshout.props | 40 - w32/download_mpg123.props | 46 - w32/download_pthreads.props | 40 - w32/libshout-version.props | 21 + w32/libshout.props | 62 + w32/mpg123-version.props | 21 + w32/mpg123.props | 68 + w32/ogg-version.props | 21 + w32/ogg.props | 59 + w32/pthreads-version.props | 21 + w32/pthreads.props | 71 + 27 files changed, 365 insertions(+), 3487 deletions(-) delete mode 100644 libs/win32/libogg/libogg.2017.vcxproj delete mode 100644 libs/win32/libshout/compat.h delete mode 100644 libs/win32/libshout/libshout.2017.vcxproj delete mode 100644 libs/win32/libshout/shout/shout.h delete mode 100644 libs/win32/mpg123/libmpg123.2017.vcxproj delete mode 100644 libs/win32/mpg123/libmpg123/config.h delete mode 100644 libs/win32/mpg123/libmpg123/mpg123.h delete mode 100644 libs/win32/pthread/cleancount delete mode 100644 libs/win32/pthread/pthread.2017.vcxproj delete mode 100644 w32/download_OGG.props delete mode 100644 w32/download_libshout.props delete mode 100644 w32/download_mpg123.props delete mode 100644 w32/download_pthreads.props create mode 100644 w32/libshout-version.props create mode 100644 w32/libshout.props create mode 100644 w32/mpg123-version.props create mode 100644 w32/mpg123.props create mode 100644 w32/ogg-version.props create mode 100644 w32/ogg.props create mode 100644 w32/pthreads-version.props create mode 100644 w32/pthreads.props diff --git a/.gitignore b/.gitignore index 34c37949f2..a086940a54 100644 --- a/.gitignore +++ b/.gitignore @@ -285,6 +285,14 @@ libs/libtiff-*/ libs/libtiff-*.zip libs/lame-*/ libs/lame-*.zip +libs/libshout-*/ +libs/libshout-*.zip +libs/libogg-*/ +libs/libogg-*.zip +libs/pthreads-*/ +libs/pthreads-*.zip +libs/mpg123-*/ +libs/mpg123-*.zip libs/SharpZipLib.*/ libs/SharpZipLib.*.nupkg libs/nasm-*/ diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index e2a0fa7597..2d27d5b591 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -212,8 +212,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libapr", "libs\win32\apr\li EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_sofia", "src\mod\endpoints\mod_sofia\mod_sofia.2017.vcxproj", "{0DF3ABD0-DDC0-4265-B778-07C66780979B}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pthread", "libs\win32\pthread\pthread.2017.vcxproj", "{DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_g723_1", "src\mod\codecs\mod_g723_1\mod_g723_1.2017.vcxproj", "{FEA1EEF7-876F-48DE-88BF-C0E3E606D758}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_native_file", "src\mod\formats\mod_native_file\mod_native_file.2017.vcxproj", "{9254C4B0-6F60-42B6-BB3A-36D63FC001C7}" @@ -278,20 +276,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "32khz", "libs\win32\Sound_F EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_flite", "src\mod\asr_tts\mod_flite\mod_flite.2017.vcxproj", "{66444AEE-554C-11DD-A9F0-8C5D56D89593}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libshout", "libs\win32\libshout\libshout.2017.vcxproj", "{D3D8B329-20BE-475E-9E83-653CEA0E0EF5}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_shout", "src\mod\formats\mod_shout\mod_shout.2017.vcxproj", "{38FE0559-9910-43A8-9E45-3E5004C27692}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libogg", "libs\win32\libogg\libogg.2017.vcxproj", "{0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_say_zh", "src\mod\say\mod_say_zh\mod_say_zh.2017.vcxproj", "{B6A9FB7A-1CC4-442B-812D-EC33E4E4A36E}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_managed", "src\mod\languages\mod_managed\mod_managed.2017.vcxproj", "{7B42BDA1-72C0-4378-A9B6-5C530F8CD61E}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FreeSWITCH.Managed.2017", "src\mod\languages\mod_managed\managed\FreeSWITCH.Managed.2017.csproj", "{834E2B2F-5483-4B80-8FE3-FE48FF76E5C0}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmpg123", "libs\win32\mpg123\libmpg123.2017.vcxproj", "{419C8F80-D858-4B48-A25C-AF4007608137}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_loopback", "src\mod\endpoints\mod_loopback\mod_loopback.2017.vcxproj", "{B3F424EC-3D8F-417C-B244-3919D5E1A577}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_vmd", "src\mod\applications\mod_vmd\mod_vmd.2017.vcxproj", "{14E4A972-9CFB-436D-B0A5-4943F3F80D47}" @@ -762,17 +754,6 @@ Global {0DF3ABD0-DDC0-4265-B778-07C66780979B}.Release|Win32.Build.0 = Release|Win32 {0DF3ABD0-DDC0-4265-B778-07C66780979B}.Release|x64.ActiveCfg = Release|x64 {0DF3ABD0-DDC0-4265-B778-07C66780979B}.Release|x64.Build.0 = Release|x64 - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}.All|Win32.ActiveCfg = Release DLL|x64 - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}.All|x64.ActiveCfg = Release DLL|x64 - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}.All|x64.Build.0 = Release DLL|x64 - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}.Debug|Win32.ActiveCfg = Debug DLL|Win32 - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}.Debug|Win32.Build.0 = Debug DLL|Win32 - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}.Debug|x64.ActiveCfg = Debug DLL|x64 - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}.Debug|x64.Build.0 = Debug DLL|x64 - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}.Release|Win32.ActiveCfg = Release DLL|Win32 - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}.Release|Win32.Build.0 = Release DLL|Win32 - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}.Release|x64.ActiveCfg = Release DLL|x64 - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4}.Release|x64.Build.0 = Release DLL|x64 {FEA1EEF7-876F-48DE-88BF-C0E3E606D758}.All|Win32.ActiveCfg = Release Passthrough|x64 {FEA1EEF7-876F-48DE-88BF-C0E3E606D758}.All|x64.ActiveCfg = Release Passthrough|x64 {FEA1EEF7-876F-48DE-88BF-C0E3E606D758}.All|x64.Build.0 = Release Passthrough|x64 @@ -1117,17 +1098,6 @@ Global {66444AEE-554C-11DD-A9F0-8C5D56D89593}.Release|Win32.Build.0 = Release|Win32 {66444AEE-554C-11DD-A9F0-8C5D56D89593}.Release|x64.ActiveCfg = Release|x64 {66444AEE-554C-11DD-A9F0-8C5D56D89593}.Release|x64.Build.0 = Release|x64 - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.All|Win32.ActiveCfg = Debug|x64 - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.All|x64.ActiveCfg = Debug|x64 - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.All|x64.Build.0 = Debug|x64 - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.Debug|Win32.ActiveCfg = Debug|Win32 - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.Debug|Win32.Build.0 = Debug|Win32 - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.Debug|x64.ActiveCfg = Debug|x64 - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.Debug|x64.Build.0 = Debug|x64 - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.Release|Win32.ActiveCfg = Release|Win32 - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.Release|Win32.Build.0 = Release|Win32 - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.Release|x64.ActiveCfg = Release|x64 - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5}.Release|x64.Build.0 = Release|x64 {38FE0559-9910-43A8-9E45-3E5004C27692}.All|Win32.ActiveCfg = Release|x64 {38FE0559-9910-43A8-9E45-3E5004C27692}.All|x64.ActiveCfg = Release|x64 {38FE0559-9910-43A8-9E45-3E5004C27692}.All|x64.Build.0 = Release|x64 @@ -1139,17 +1109,6 @@ Global {38FE0559-9910-43A8-9E45-3E5004C27692}.Release|Win32.Build.0 = Release|Win32 {38FE0559-9910-43A8-9E45-3E5004C27692}.Release|x64.ActiveCfg = Release|x64 {38FE0559-9910-43A8-9E45-3E5004C27692}.Release|x64.Build.0 = Release|x64 - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}.All|Win32.ActiveCfg = Debug|x64 - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}.All|x64.ActiveCfg = Debug|x64 - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}.All|x64.Build.0 = Debug|x64 - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}.Debug|Win32.ActiveCfg = Debug|Win32 - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}.Debug|Win32.Build.0 = Debug|Win32 - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}.Debug|x64.ActiveCfg = Debug|x64 - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}.Debug|x64.Build.0 = Debug|x64 - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}.Release|Win32.ActiveCfg = Release|Win32 - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}.Release|Win32.Build.0 = Release|Win32 - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}.Release|x64.ActiveCfg = Release|x64 - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4}.Release|x64.Build.0 = Release|x64 {B6A9FB7A-1CC4-442B-812D-EC33E4E4A36E}.All|Win32.ActiveCfg = Release|x64 {B6A9FB7A-1CC4-442B-812D-EC33E4E4A36E}.All|x64.ActiveCfg = Release|x64 {B6A9FB7A-1CC4-442B-812D-EC33E4E4A36E}.All|x64.Build.0 = Release|x64 @@ -1182,17 +1141,6 @@ Global {834E2B2F-5483-4B80-8FE3-FE48FF76E5C0}.Release|Win32.Build.0 = Release|Any CPU {834E2B2F-5483-4B80-8FE3-FE48FF76E5C0}.Release|x64.ActiveCfg = Release|x64 {834E2B2F-5483-4B80-8FE3-FE48FF76E5C0}.Release|x64.Build.0 = Release|x64 - {419C8F80-D858-4B48-A25C-AF4007608137}.All|Win32.ActiveCfg = Debug_Generic_Dll|Win32 - {419C8F80-D858-4B48-A25C-AF4007608137}.All|Win32.Build.0 = Debug_Generic_Dll|Win32 - {419C8F80-D858-4B48-A25C-AF4007608137}.All|x64.ActiveCfg = Debug_Generic_Dll|Win32 - {419C8F80-D858-4B48-A25C-AF4007608137}.Debug|Win32.ActiveCfg = Debug_Generic|Win32 - {419C8F80-D858-4B48-A25C-AF4007608137}.Debug|Win32.Build.0 = Debug_Generic|Win32 - {419C8F80-D858-4B48-A25C-AF4007608137}.Debug|x64.ActiveCfg = Debug_Generic|x64 - {419C8F80-D858-4B48-A25C-AF4007608137}.Debug|x64.Build.0 = Debug_Generic|x64 - {419C8F80-D858-4B48-A25C-AF4007608137}.Release|Win32.ActiveCfg = Release_Generic|Win32 - {419C8F80-D858-4B48-A25C-AF4007608137}.Release|Win32.Build.0 = Release_Generic|Win32 - {419C8F80-D858-4B48-A25C-AF4007608137}.Release|x64.ActiveCfg = Release_Generic|x64 - {419C8F80-D858-4B48-A25C-AF4007608137}.Release|x64.Build.0 = Release_Generic|x64 {B3F424EC-3D8F-417C-B244-3919D5E1A577}.All|Win32.ActiveCfg = Release|x64 {B3F424EC-3D8F-417C-B244-3919D5E1A577}.All|x64.ActiveCfg = Release|x64 {B3F424EC-3D8F-417C-B244-3919D5E1A577}.All|x64.Build.0 = Release|x64 @@ -2269,7 +2217,6 @@ Global {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {F6C55D93-B927-4483-BB69-15AEF3DD2DFF} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {0DF3ABD0-DDC0-4265-B778-07C66780979B} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C} - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {FEA1EEF7-876F-48DE-88BF-C0E3E606D758} = {F881ADA2-2F1A-4046-9FEB-191D9422D781} {9254C4B0-6F60-42B6-BB3A-36D63FC001C7} = {A5A27244-AD24-46E5-B01B-840CD296C91D} {4043FC6A-9A30-4577-8AD5-9B233C9575D8} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} @@ -2302,13 +2249,10 @@ Global {7EB71250-F002-4ED8-92CA-CA218114537A} = {4F227C26-768F-46A3-8684-1D08A46FB374} {464AAB78-5489-4916-BE51-BF8D61822311} = {4F227C26-768F-46A3-8684-1D08A46FB374} {66444AEE-554C-11DD-A9F0-8C5D56D89593} = {4CF6A6AC-07DE-4B9E-ABE1-7F98B64E0BB0} - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {38FE0559-9910-43A8-9E45-3E5004C27692} = {A5A27244-AD24-46E5-B01B-840CD296C91D} - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {B6A9FB7A-1CC4-442B-812D-EC33E4E4A36E} = {6CD61A1D-797C-470A-BE08-8C31B68BB336} {7B42BDA1-72C0-4378-A9B6-5C530F8CD61E} = {0C808854-54D1-4230-BFF5-77B5FD905000} {834E2B2F-5483-4B80-8FE3-FE48FF76E5C0} = {0C808854-54D1-4230-BFF5-77B5FD905000} - {419C8F80-D858-4B48-A25C-AF4007608137} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {B3F424EC-3D8F-417C-B244-3919D5E1A577} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C} {14E4A972-9CFB-436D-B0A5-4943F3F80D47} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {0B6C905B-142E-4999-B39D-92FF7951E921} = {F881ADA2-2F1A-4046-9FEB-191D9422D781} diff --git a/libs/win32/libogg/libogg.2017.vcxproj b/libs/win32/libogg/libogg.2017.vcxproj deleted file mode 100644 index 96176a3dbd..0000000000 --- a/libs/win32/libogg/libogg.2017.vcxproj +++ /dev/null @@ -1,204 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - libogg - {0FEEAEC6-4399-4C46-B7DB-62ECE80D15B4} - libogg - - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - - - - MaxSpeed - OnlyExplicitInline - ..\..\libogg-1.1.3\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - true - MultiThreaded - true - TurnOffAllWarnings - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0409 - - - $(OutDir)libogg.lib - true - - - true - .\Static_Release/ogg_static.bsc - - - - - X64 - - - MaxSpeed - OnlyExplicitInline - ..\..\libogg-1.1.3\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - true - MultiThreaded - true - TurnOffAllWarnings - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0409 - - - $(OutDir)libogg.lib - true - - - true - .\Static_Release/ogg_static.bsc - - - - - Disabled - ..\..\libogg-1.1.3\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebug - TurnOffAllWarnings - true - - - _DEBUG;%(PreprocessorDefinitions) - 0x0409 - - - $(OutDir)libogg.lib - true - - - true - .\Static_Debug/ogg_static.bsc - - - - - X64 - - - Disabled - ..\..\libogg-1.1.3\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebug - TurnOffAllWarnings - true - - - _DEBUG;%(PreprocessorDefinitions) - 0x0409 - - - $(OutDir)libogg.lib - true - - - true - .\Static_Debug/ogg_static.bsc - - - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - - - - - - - - \ No newline at end of file diff --git a/libs/win32/libshout/compat.h b/libs/win32/libshout/compat.h deleted file mode 100644 index d0d814ebba..0000000000 --- a/libs/win32/libshout/compat.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/libs/win32/libshout/libshout.2017.vcxproj b/libs/win32/libshout/libshout.2017.vcxproj deleted file mode 100644 index c7790e7f0f..0000000000 --- a/libs/win32/libshout/libshout.2017.vcxproj +++ /dev/null @@ -1,192 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {D3D8B329-20BE-475E-9E83-653CEA0E0EF5} - libshout - libshout - - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - - - - MaxSpeed - OnlyExplicitInline - .\;..\..\libshout-2.2.2\src;..\..\libshout-2.2.2\include;..\..\libogg-1.1.3\include;..\..\pthreads-w32-2-9-1;..\..\libshout-2.2.2\win32\include;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;WIN32;_LIB;_WIN32;VERSION="2.0.0";LIBSHOUT_MAJOR=2;LIBSHOUT_MINOR=0;LIBSHOUT_MICRO=0;HAVE_WINSOCK2_H;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) - true - MultiThreaded - true - TurnOffAllWarnings - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0409 - - - true - - - - - X64 - - - MaxSpeed - OnlyExplicitInline - .\;..\..\libshout-2.2.2\src;..\..\libshout-2.2.2\include;..\..\libogg-1.1.3\include;..\..\pthreads-w32-2-9-1;..\..\libshout-2.2.2\win32\include;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;WIN32;_LIB;_WIN32;VERSION="2.0.0";LIBSHOUT_MAJOR=2;LIBSHOUT_MINOR=0;LIBSHOUT_MICRO=0;HAVE_WINSOCK2_H;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) - true - MultiThreaded - true - TurnOffAllWarnings - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x0409 - - - true - - - - - Disabled - .\;..\..\libshout-2.2.2\src;..\..\libshout-2.2.2\include;..\..\libogg-1.1.3\include;..\..\pthreads-w32-2-9-1;..\..\libshout-2.2.2\win32\include;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;WIN32;_DEBUG;_LIB;_WIN32;VERSION="2.0.0";LIBSHOUT_MAJOR=2;LIBSHOUT_MINOR=0;LIBSHOUT_MICRO=0;HAVE_WINSOCK2_H;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebug - TurnOffAllWarnings - true - - - _DEBUG;%(PreprocessorDefinitions) - 0x0409 - - - true - - - - - X64 - - - Disabled - .\;..\..\libshout-2.2.2\src;..\..\libshout-2.2.2\include;..\..\libogg-1.1.3\include;..\..\pthreads-w32-2-9-1;..\..\libshout-2.2.2\win32\include;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;WIN32;_DEBUG;_LIB;_WIN32;VERSION="2.0.0";LIBSHOUT_MAJOR=2;LIBSHOUT_MINOR=0;LIBSHOUT_MICRO=0;HAVE_WINSOCK2_H;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebug - TurnOffAllWarnings - true - - - _DEBUG;%(PreprocessorDefinitions) - 0x0409 - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {0feeaec6-4399-4c46-b7db-62ece80d15b4} - false - - - {df018947-0fff-4eb3-bdee-441dc81da7a4} - - - - - - \ No newline at end of file diff --git a/libs/win32/libshout/shout/shout.h b/libs/win32/libshout/shout/shout.h deleted file mode 100644 index 30473e6f8d..0000000000 --- a/libs/win32/libshout/shout/shout.h +++ /dev/null @@ -1,220 +0,0 @@ -/* shout.h - * - * API for libshout, the streaming library for icecast - * - * Copyright (C) 2002-2003 the Icecast team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef __LIBSHOUT_SHOUT_H__ -#define __LIBSHOUT_SHOUT_H__ - -#include -#ifdef WIN32 -#include -# ifdef _MSC_VER -# undef inline -# define inline __inline -#if (_MSC_VER >= 1400) // VC8+ -#ifndef _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_DEPRECATE -#endif -#ifndef _CRT_NONSTDC_NO_DEPRECATE -#define _CRT_NONSTDC_NO_DEPRECATE -#endif -#endif // VC8+ -# endif -#if !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER < 1900) -#define va_copy(ap1, ap2) memcpy(&ap1, &ap2, sizeof(va_list)) -#endif - -#endif - -#define SHOUTERR_SUCCESS (0) -#define SHOUTERR_INSANE (-1) -#define SHOUTERR_NOCONNECT (-2) -#define SHOUTERR_NOLOGIN (-3) -#define SHOUTERR_SOCKET (-4) -#define SHOUTERR_MALLOC (-5) -#define SHOUTERR_METADATA (-6) -#define SHOUTERR_CONNECTED (-7) -#define SHOUTERR_UNCONNECTED (-8) -#define SHOUTERR_UNSUPPORTED (-9) - -#define SHOUTERR_BUSY (-10) - -#define SHOUT_FORMAT_OGG (0) -#define SHOUT_FORMAT_MP3 (1) -/* backward-compatibility alias */ -#define SHOUT_FORMAT_VORBIS SHOUT_FORMAT_OGG - -#define SHOUT_PROTOCOL_HTTP (0) -#define SHOUT_PROTOCOL_XAUDIOCAST (1) -#define SHOUT_PROTOCOL_ICY (2) - -#define SHOUT_AI_BITRATE "bitrate" -#define SHOUT_AI_SAMPLERATE "samplerate" -#define SHOUT_AI_CHANNELS "channels" -#define SHOUT_AI_QUALITY "quality" - -typedef struct shout shout_t; -typedef struct _util_dict shout_metadata_t; - -#ifdef __cplusplus -extern "C" { -#endif - -/* initializes the shout library. Must be called before anything else */ -void shout_init(void); - -/* shuts down the shout library, deallocating any global storage. Don't call - * anything afterwards */ -void shout_shutdown(void); - -/* returns a static version string. Non-null parameters will be set to the - * value of the library major, minor, and patch levels, respectively */ -const char *shout_version(int *major, int *minor, int *patch); - -/* Allocates and sets up a new shout_t. Returns NULL if it can't get enough - * memory. The returns shout_t must be disposed of with shout_free. */ -shout_t *shout_new(void); - -/* Free all memory allocated by a shout_t */ -void shout_free(shout_t *self); - -/* Returns a statically allocated string describing the last shout error - * to occur. Only valid until the next libshout call on this shout_t */ -const char *shout_get_error(shout_t *self); - -/* Return the error code (e.g. SHOUTERR_SOCKET) for this shout instance */ -int shout_get_errno(shout_t *self); - -/* returns SHOUTERR_CONNECTED or SHOUTERR_UNCONNECTED */ -int shout_get_connected(shout_t *self); - -/* Parameter manipulation functions. libshout makes copies of all parameters, - * the caller may free its copies after giving them to libshout. May return - * SHOUTERR_MALLOC */ - -int shout_set_host(shout_t *self, const char *host); -const char *shout_get_host(shout_t *self); - -int shout_set_port(shout_t *self, unsigned short port); -unsigned short shout_get_port(shout_t *self); - -int shout_set_password(shout_t *, const char *password); -const char *shout_get_password(shout_t *self); - -int shout_set_mount(shout_t *self, const char *mount); -const char *shout_get_mount(shout_t *self); - -int shout_set_name(shout_t *self, const char *name); -const char *shout_get_name(shout_t *self); - -int shout_set_url(shout_t *self, const char *url); -const char *shout_get_url(shout_t *self); - -int shout_set_genre(shout_t *self, const char *genre); -const char *shout_get_genre(shout_t *self); - -int shout_set_user(shout_t *self, const char *username); -const char *shout_get_user(shout_t *self); - -int shout_set_agent(shout_t *self, const char *username); -const char *shout_get_agent(shout_t *self); - -int shout_set_description(shout_t *self, const char *description); -const char *shout_get_description(shout_t *self); - -int shout_set_dumpfile(shout_t *self, const char *dumpfile); -const char *shout_get_dumpfile(shout_t *self); - -int shout_set_audio_info(shout_t *self, const char *name, const char *value); -const char *shout_get_audio_info(shout_t *self, const char *name); - -int shout_set_public(shout_t *self, unsigned int make_public); -unsigned int shout_get_public(shout_t *self); - -/* takes a SHOUT_FORMAT_xxxx argument */ -int shout_set_format(shout_t *self, unsigned int format); -unsigned int shout_get_format(shout_t *self); - -/* takes a SHOUT_PROTOCOL_xxxxx argument */ -int shout_set_protocol(shout_t *self, unsigned int protocol); -unsigned int shout_get_protocol(shout_t *self); - -/* Instructs libshout to use nonblocking I/O. Must be called before - * shout_open (no switching back and forth midstream at the moment). */ -int shout_set_nonblocking(shout_t* self, unsigned int nonblocking); -unsigned int shout_get_nonblocking(shout_t *self); - -/* Opens a connection to the server. All parameters must already be set */ -int shout_open(shout_t *self); - -/* Closes a connection to the server */ -int shout_close(shout_t *self); - -/* Send data to the server, parsing it for format specific timing info */ -int shout_send(shout_t *self, const unsigned char *data, size_t len); - -/* Send unparsed data to the server. Do not use this unless you know - * what you are doing. - * Returns the number of bytes written, or < 0 on error. - */ -ssize_t shout_send_raw(shout_t *self, const unsigned char *data, size_t len); - -/* return the number of bytes currently on the write queue (only makes sense in - * nonblocking mode). */ -ssize_t shout_queuelen(shout_t *self); - -/* Puts caller to sleep until it is time to send more data to the server */ -void shout_sync(shout_t *self); - -/* Amount of time in ms caller should wait before sending again */ -int shout_delay(shout_t *self); - -/* Sets MP3 metadata. - * Returns: - * SHOUTERR_SUCCESS - * SHOUTERR_UNSUPPORTED if format isn't MP3 - * SHOUTERR_MALLOC - * SHOUTERR_INSANE - * SHOUTERR_NOCONNECT - * SHOUTERR_SOCKET - */ -int shout_set_metadata(shout_t *self, shout_metadata_t *metadata); - -/* Allocates a new metadata structure. Must be freed by shout_metadata_free. */ -shout_metadata_t *shout_metadata_new(void); - -/* Free resources allocated by shout_metadata_t */ -void shout_metadata_free(shout_metadata_t *self); - -/* Add a parameter to the metadata structure. - * Returns: - * SHOUTERR_SUCCESS on success - * SHOUTERR_INSANE if self isn't a valid shout_metadata_t* or name is null - * SHOUTERR_MALLOC if memory can't be allocated */ -int shout_metadata_add(shout_metadata_t *self, const char *name, const char *value); - -#ifdef __cplusplus -} -#endif - -/* --- Compiled features --- */ - -#define SHOUT_THREADSAFE @SHOUT_THREADSAFE@ - -#endif /* __LIBSHOUT_SHOUT_H__ */ diff --git a/libs/win32/mpg123/libmpg123.2017.vcxproj b/libs/win32/mpg123/libmpg123.2017.vcxproj deleted file mode 100644 index 5c28af93b1..0000000000 --- a/libs/win32/mpg123/libmpg123.2017.vcxproj +++ /dev/null @@ -1,1332 +0,0 @@ - - - - - Debug_Generic_Dll - Win32 - - - Debug_Generic_Dll - x64 - - - Debug_Generic - Win32 - - - Debug_Generic - x64 - - - Debug_x86_Dll - Win32 - - - Debug_x86_Dll - x64 - - - Debug_x86 - Win32 - - - Debug_x86 - x64 - - - Release_Generic_Dll - Win32 - - - Release_Generic_Dll - x64 - - - Release_Generic - Win32 - - - Release_Generic - x64 - - - Release_x86_Dll - Win32 - - - Release_x86_Dll - x64 - - - Release_x86 - Win32 - - - Release_x86 - x64 - - - - {419C8F80-D858-4B48-A25C-AF4007608137} - libmpg123 - libmpg123 - - - - DynamicLibrary - Unicode - true - $(DefaultPlatformToolset) - - - DynamicLibrary - Unicode - true - $(DefaultPlatformToolset) - - - DynamicLibrary - Unicode - $(DefaultPlatformToolset) - - - DynamicLibrary - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - DynamicLibrary - Unicode - true - $(DefaultPlatformToolset) - - - DynamicLibrary - Unicode - true - $(DefaultPlatformToolset) - - - DynamicLibrary - Unicode - $(DefaultPlatformToolset) - - - DynamicLibrary - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.21006.1 - false - false - - - - Disabled - ../../libmpg123/ports\MSVC++;../../libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;OPT_GENERIC;_DEBUG;%(PreprocessorDefinitions) - false - - - EnableFastChecks - MultiThreadedDebugDLL - false - Level3 - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - - - - Disabled - ../../libmpg123/ports\MSVC++;../../libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;OPT_GENERIC;_DEBUG;%(PreprocessorDefinitions) - false - - - EnableFastChecks - MultiThreadedDebugDLL - false - Level3 - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - - - - MaxSpeed - AnySuitable - true - Speed - true - ../../libmpg123/ports\MSVC++;../../libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;OPT_GENERIC;%(PreprocessorDefinitions) - - - MultiThreadedDLL - false - false - StreamingSIMDExtensions - Precise - false - Level3 - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - - - - MaxSpeed - AnySuitable - true - Speed - true - ../../libmpg123/ports\MSVC++;../../libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;OPT_GENERIC;%(PreprocessorDefinitions) - - - MultiThreadedDLL - false - false - NotSet - Precise - false - Level3 - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - - - - Disabled - ../../libmpg123/ports\MSVC++;../../libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;OPT_GENERIC;_DEBUG;BUILD_MPG123_DLL;ACCURATE_ROUNDING;IEEE_FLOAT;%(PreprocessorDefinitions) - false - - - EnableFastChecks - MultiThreadedDebugDLL - false - Level3 - false - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - $(ProjectDir)Debug\$(ProjectName).dll - $(ProjectDir)\Debug;%(AdditionalLibraryDirectories) - true - true - 0x63000000 - false - true - - - - - Disabled - ../../libmpg123/ports\MSVC++;../../libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;OPT_GENERIC;_DEBUG;BUILD_MPG123_DLL;ACCURATE_ROUNDING;IEEE_FLOAT;%(PreprocessorDefinitions) - false - - - EnableFastChecks - MultiThreadedDebugDLL - false - Level3 - false - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - $(ProjectDir)Debug\$(ProjectName).dll - $(ProjectDir)\Debug;%(AdditionalLibraryDirectories) - true - true - 0x63000000 - false - true - - - - - MaxSpeed - AnySuitable - true - Speed - true - ../../libmpg123/ports\MSVC++;../..//libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;OPT_GENERIC;BUILD_MPG123_DLL;%(PreprocessorDefinitions) - - - MultiThreadedDLL - false - false - StreamingSIMDExtensions - Precise - false - Level3 - false - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - $(ProjectDir)Release\$(ProjectName).dll - true - 0x63000000 - false - true - - - - - MaxSpeed - AnySuitable - true - Speed - true - ../../libmpg123/ports\MSVC++;../..//libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;OPT_GENERIC;BUILD_MPG123_DLL;%(PreprocessorDefinitions) - - - MultiThreadedDLL - false - false - StreamingSIMDExtensions - Precise - false - Level3 - false - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - $(ProjectDir)Release\$(ProjectName).dll - true - 0x63000000 - false - true - - - - - Disabled - ../../libmpg123/ports\MSVC++;../..//libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;OPT_MULTI;OPT_GENERIC;OPT_I386;OPT_I586;OPT_MMX;OPT_3DNOW;OPT_3DNOWEXT;OPT_SSE;%(PreprocessorDefinitions) - false - - - EnableFastChecks - MultiThreadedDebugDLL - false - Level3 - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.o" "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_sse.o" "$(ProjectDir)..\libmpg123\Debug\dct64_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\equalizer_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\getcpuflags.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\getcpuflags.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\getcpuflags.o" "$(ProjectDir)..\libmpg123\Debug\getcpuflags.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_i586.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_i586.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_i586.o" "$(ProjectDir)..\libmpg123\Debug\synth_i586.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_mmx.o" "$(ProjectDir)..\libmpg123\Debug\synth_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\tabinit_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.o" "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.asm" - - - - dct36_3dnow.o;dct36_3dnowext.o;dct64_3dnow.o;dct64_3dnowext.o;dct64_mmx.o;dct64_sse.o;dct64_sse_float.o;equalizer_3dnow.o;getcpuflags.o;synth_3dnow.o;synth_3dnowext.o;synth_i586.o;synth_mmx.o;synth_sse.o;synth_sse_float.o;synth_stereo_sse_float.o;tabinit_mmx.o;synth_sse_accurate.o;synth_sse_s32.o;synth_stereo_sse_accurate.o;synth_stereo_sse_s32.o;%(AdditionalDependencies) - $(ProjectDir)Debug\$(ProjectName).lib - $(ProjectDir)\Debug;%(AdditionalLibraryDirectories) - - - - - Disabled - ../../libmpg123/ports\MSVC++;../..//libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;OPT_MULTI;OPT_GENERIC;OPT_I386;OPT_I586;OPT_MMX;OPT_3DNOW;OPT_3DNOWEXT;OPT_SSE;%(PreprocessorDefinitions) - false - - - EnableFastChecks - MultiThreadedDebugDLL - false - Level3 - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.o" "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_sse.o" "$(ProjectDir)..\libmpg123\Debug\dct64_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\equalizer_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\getcpuflags.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\getcpuflags.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\getcpuflags.o" "$(ProjectDir)..\libmpg123\Debug\getcpuflags.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_i586.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_i586.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_i586.o" "$(ProjectDir)..\libmpg123\Debug\synth_i586.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_mmx.o" "$(ProjectDir)..\libmpg123\Debug\synth_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\tabinit_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.o" "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.asm" - - - - dct36_3dnow.o;dct36_3dnowext.o;dct64_3dnow.o;dct64_3dnowext.o;dct64_mmx.o;dct64_sse.o;dct64_sse_float.o;equalizer_3dnow.o;getcpuflags.o;synth_3dnow.o;synth_3dnowext.o;synth_i586.o;synth_mmx.o;synth_sse.o;synth_sse_float.o;synth_stereo_sse_float.o;tabinit_mmx.o;synth_sse_accurate.o;synth_sse_s32.o;synth_stereo_sse_accurate.o;synth_stereo_sse_s32.o;%(AdditionalDependencies) - $(ProjectDir)Debug\$(ProjectName).lib - $(ProjectDir)\Debug;%(AdditionalLibraryDirectories) - - - - - MaxSpeed - AnySuitable - true - Speed - true - ../../libmpg123/ports\MSVC++;../..//libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;OPT_MULTI;OPT_GENERIC;OPT_I386;OPT_I586;OPT_MMX;OPT_3DNOW;OPT_3DNOWEXT;OPT_SSE;%(PreprocessorDefinitions) - - - MultiThreadedDLL - false - false - StreamingSIMDExtensions - Precise - false - Level3 - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.o" "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.o" "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_mmx.o" "$(ProjectDir)..\libmpg123\Release\dct64_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_sse.o" "$(ProjectDir)..\libmpg123\Release\dct64_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.o" "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\equalizer_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.o" "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\getcpuflags.S" /nologo > "$(ProjectDir)..\libmpg123\Release\getcpuflags.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\getcpuflags.o" "$(ProjectDir)..\libmpg123\Release\getcpuflags.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_3dnow.o" "$(ProjectDir)..\libmpg123\Release\synth_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_i586.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_i586.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_i586.o" "$(ProjectDir)..\libmpg123\Release\synth_i586.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_mmx.o" "$(ProjectDir)..\libmpg123\Release\synth_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse.o" "$(ProjectDir)..\libmpg123\Release\synth_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_float.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\tabinit_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.o" "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.asm" - - - - dct36_3dnow.o;dct36_3dnowext.o;dct64_3dnow.o;dct64_3dnowext.o;dct64_mmx.o;dct64_sse.o;dct64_sse_float.o;equalizer_3dnow.o;getcpuflags.o;synth_3dnow.o;synth_3dnowext.o;synth_i586.o;synth_mmx.o;synth_sse.o;synth_sse_float.o;synth_stereo_sse_float.o;tabinit_mmx.o;synth_sse_accurate.o;synth_sse_s32.o;synth_stereo_sse_accurate.o;synth_stereo_sse_s32.o;%(AdditionalDependencies) - $(ProjectDir)Release\$(ProjectName).lib - $(ProjectDir)\Release;%(AdditionalLibraryDirectories) - - - - - MaxSpeed - AnySuitable - true - Speed - true - ../../libmpg123/ports\MSVC++;../..//libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;OPT_MULTI;OPT_GENERIC;OPT_I386;OPT_I586;OPT_MMX;OPT_3DNOW;OPT_3DNOWEXT;OPT_SSE;%(PreprocessorDefinitions) - - - MultiThreadedDLL - false - false - StreamingSIMDExtensions - Precise - false - Level3 - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.o" "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.o" "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_mmx.o" "$(ProjectDir)..\libmpg123\Release\dct64_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_sse.o" "$(ProjectDir)..\libmpg123\Release\dct64_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.o" "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\equalizer_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.o" "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\getcpuflags.S" /nologo > "$(ProjectDir)..\libmpg123\Release\getcpuflags.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\getcpuflags.o" "$(ProjectDir)..\libmpg123\Release\getcpuflags.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_3dnow.o" "$(ProjectDir)..\libmpg123\Release\synth_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_i586.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_i586.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_i586.o" "$(ProjectDir)..\libmpg123\Release\synth_i586.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_mmx.o" "$(ProjectDir)..\libmpg123\Release\synth_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse.o" "$(ProjectDir)..\libmpg123\Release\synth_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_float.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\tabinit_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.o" "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.asm" - - - - dct36_3dnow.o;dct36_3dnowext.o;dct64_3dnow.o;dct64_3dnowext.o;dct64_mmx.o;dct64_sse.o;dct64_sse_float.o;equalizer_3dnow.o;getcpuflags.o;synth_3dnow.o;synth_3dnowext.o;synth_i586.o;synth_mmx.o;synth_sse.o;synth_sse_float.o;synth_stereo_sse_float.o;tabinit_mmx.o;synth_sse_accurate.o;synth_sse_s32.o;synth_stereo_sse_accurate.o;synth_stereo_sse_s32.o;%(AdditionalDependencies) - $(ProjectDir)Release\$(ProjectName).lib - $(ProjectDir)\Release;%(AdditionalLibraryDirectories) - - - - - Disabled - ../../libmpg123/ports\MSVC++;../..//libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;BUILD_MPG123_DLL;OPT_MULTI;OPT_GENERIC;OPT_I386;OPT_I586;OPT_MMX;OPT_3DNOW;OPT_3DNOWEXT;OPT_SSE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) - false - - - EnableFastChecks - MultiThreadedDebugDLL - Precise - false - Level3 - false - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.o" "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_sse.o" "$(ProjectDir)..\libmpg123\Debug\dct64_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\equalizer_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\getcpuflags.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\getcpuflags.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\getcpuflags.o" "$(ProjectDir)..\libmpg123\Debug\getcpuflags.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_i586.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_i586.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_i586.o" "$(ProjectDir)..\libmpg123\Debug\synth_i586.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_mmx.o" "$(ProjectDir)..\libmpg123\Debug\synth_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\tabinit_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.o" "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.asm" - - - - dct36_3dnow.o;dct36_3dnowext.o;dct64_3dnow.o;dct64_3dnowext.o;dct64_mmx.o;dct64_sse.o;dct64_sse_float.o;equalizer_3dnow.o;getcpuflags.o;synth_3dnow.o;synth_3dnowext.o;synth_i586.o;synth_mmx.o;synth_sse.o;synth_sse_float.o;synth_stereo_sse_float.o;tabinit_mmx.o;synth_sse_accurate.o;synth_sse_s32.o;synth_stereo_sse_accurate.o;synth_stereo_sse_s32.o;%(AdditionalDependencies) - $(ProjectDir)Debug\$(ProjectName).dll - $(ProjectDir)\Debug;%(AdditionalLibraryDirectories) - true - true - 0x63000000 - true - false - - - - - Disabled - ../../libmpg123/ports\MSVC++;../..//libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;BUILD_MPG123_DLL;OPT_MULTI;OPT_GENERIC;OPT_I386;OPT_I586;OPT_MMX;OPT_3DNOW;OPT_3DNOWEXT;OPT_SSE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) - false - - - EnableFastChecks - MultiThreadedDebugDLL - Precise - false - Level3 - false - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\dct36_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct36_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\dct36_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\dct64_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\dct64_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.o" "$(ProjectDir)..\libmpg123\Debug\dct64_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_sse.o" "$(ProjectDir)..\libmpg123\Debug\dct64_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\dct64_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\dct64_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\equalizer_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\equalizer_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\getcpuflags.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\getcpuflags.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\getcpuflags.o" "$(ProjectDir)..\libmpg123\Debug\getcpuflags.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.o" "$(ProjectDir)..\libmpg123\Debug\synth_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.o" "$(ProjectDir)..\libmpg123\Debug\synth_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_i586.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_i586.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_i586.o" "$(ProjectDir)..\libmpg123\Debug\synth_i586.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_mmx.o" "$(ProjectDir)..\libmpg123\Debug\synth_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\tabinit_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.o" "$(ProjectDir)..\libmpg123\Debug\tabinit_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.o" "$(ProjectDir)..\libmpg123\Debug\synth_sse_s32.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\libmpg123\src\libmpg123\synth_stereo_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.o" "$(ProjectDir)..\libmpg123\Debug\synth_stereo_sse_s32.asm" - - - - dct36_3dnow.o;dct36_3dnowext.o;dct64_3dnow.o;dct64_3dnowext.o;dct64_mmx.o;dct64_sse.o;dct64_sse_float.o;equalizer_3dnow.o;getcpuflags.o;synth_3dnow.o;synth_3dnowext.o;synth_i586.o;synth_mmx.o;synth_sse.o;synth_sse_float.o;synth_stereo_sse_float.o;tabinit_mmx.o;synth_sse_accurate.o;synth_sse_s32.o;synth_stereo_sse_accurate.o;synth_stereo_sse_s32.o;%(AdditionalDependencies) - $(ProjectDir)Debug\$(ProjectName).dll - $(ProjectDir)\Debug;%(AdditionalLibraryDirectories) - true - true - 0x63000000 - true - false - - - - - - - - - MaxSpeed - AnySuitable - true - Speed - true - ../../libmpg123/ports\MSVC++;../..//libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;BUILD_MPG123_DLL;OPT_MULTI;OPT_GENERIC;OPT_I386;OPT_I586;OPT_MMX;OPT_3DNOW;OPT_3DNOWEXT;OPT_SSE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) - - - MultiThreadedDLL - false - false - StreamingSIMDExtensions - Precise - false - Level3 - false - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct36_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.o" "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct36_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct64_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.o" "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct64_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct64_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_mmx.o" "$(ProjectDir)..\libmpg123\Release\dct64_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct64_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_sse.o" "$(ProjectDir)..\libmpg123\Release\dct64_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct64_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.o" "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\equalizer_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.o" "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\getcpuflags.S" /nologo > "$(ProjectDir)..\libmpg123\Release\getcpuflags.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\getcpuflags.o" "$(ProjectDir)..\libmpg123\Release\getcpuflags.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_3dnow.o" "$(ProjectDir)..\libmpg123\Release\synth_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_i586.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_i586.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_i586.o" "$(ProjectDir)..\libmpg123\Release\synth_i586.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_mmx.o" "$(ProjectDir)..\libmpg123\Release\synth_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse.o" "$(ProjectDir)..\libmpg123\Release\synth_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_float.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_stereo_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\tabinit_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.o" "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_stereo_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_stereo_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.asm" - - - - dct36_3dnow.o;dct36_3dnowext.o;dct64_3dnow.o;dct64_3dnowext.o;dct64_mmx.o;dct64_sse.o;dct64_sse_float.o;equalizer_3dnow.o;getcpuflags.o;synth_3dnow.o;synth_3dnowext.o;synth_i586.o;synth_mmx.o;synth_sse.o;synth_sse_float.o;synth_stereo_sse_float.o;tabinit_mmx.o;synth_sse_accurate.o;synth_sse_s32.o;synth_stereo_sse_accurate.o;synth_stereo_sse_s32.o;%(AdditionalDependencies) - $(ProjectDir)Release\$(ProjectName).dll - $(ProjectDir)\Release;%(AdditionalLibraryDirectories) - true - 0x63000000 - false - true - - - - - - - - - - - - - MaxSpeed - AnySuitable - true - Speed - true - ../../libmpg123/ports\MSVC++;../..//libmpg123/src/libmpg123;%(AdditionalIncludeDirectories) - WIN32;_CRT_SECURE_NO_WARNINGS;BUILD_MPG123_DLL;OPT_MULTI;OPT_GENERIC;OPT_I386;OPT_I586;OPT_MMX;OPT_3DNOW;OPT_3DNOWEXT;OPT_SSE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) - - - MultiThreadedDLL - false - false - StreamingSIMDExtensions - Precise - false - Level3 - false - ProgramDatabase - CompileAsC - 4477;4028;4334;4267;4996;%(DisableSpecificWarnings) - - - cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct36_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.o" "$(ProjectDir)..\libmpg123\Release\dct36_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct36_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\dct36_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct64_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.o" "$(ProjectDir)..\libmpg123\Release\dct64_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct64_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\dct64_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct64_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_mmx.o" "$(ProjectDir)..\libmpg123\Release\dct64_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct64_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_sse.o" "$(ProjectDir)..\libmpg123\Release\dct64_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\dct64_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.o" "$(ProjectDir)..\libmpg123\Release\dct64_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\equalizer_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.o" "$(ProjectDir)..\libmpg123\Release\equalizer_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\getcpuflags.S" /nologo > "$(ProjectDir)..\libmpg123\Release\getcpuflags.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\getcpuflags.o" "$(ProjectDir)..\libmpg123\Release\getcpuflags.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_3dnow.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_3dnow.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_3dnow.o" "$(ProjectDir)..\libmpg123\Release\synth_3dnow.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_3dnowext.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.o" "$(ProjectDir)..\libmpg123\Release\synth_3dnowext.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_i586.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_i586.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_i586.o" "$(ProjectDir)..\libmpg123\Release\synth_i586.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_mmx.o" "$(ProjectDir)..\libmpg123\Release\synth_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_sse.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse.o" "$(ProjectDir)..\libmpg123\Release\synth_sse.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_float.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_stereo_sse_float.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_float.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\tabinit_mmx.S" /nologo > "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.o" "$(ProjectDir)..\libmpg123\Release\tabinit_mmx.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.o" "$(ProjectDir)..\libmpg123\Release\synth_sse_s32.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_stereo_sse_accurate.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_accurate.asm" - -cl /I "..\.." /EP /TC "$(ProjectDir)..\..\libmpg123\src\libmpg123\synth_stereo_sse_s32.S" /nologo > "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.asm" -yasm -a x86 -p gas -r raw -f win32 -g null -m x86 -o "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.o" "$(ProjectDir)..\libmpg123\Release\synth_stereo_sse_s32.asm" - - - - dct36_3dnow.o;dct36_3dnowext.o;dct64_3dnow.o;dct64_3dnowext.o;dct64_mmx.o;dct64_sse.o;dct64_sse_float.o;equalizer_3dnow.o;getcpuflags.o;synth_3dnow.o;synth_3dnowext.o;synth_i586.o;synth_mmx.o;synth_sse.o;synth_sse_float.o;synth_stereo_sse_float.o;tabinit_mmx.o;synth_sse_accurate.o;synth_sse_s32.o;synth_stereo_sse_accurate.o;synth_stereo_sse_s32.o;%(AdditionalDependencies) - $(ProjectDir)Release\$(ProjectName).dll - $(ProjectDir)\Release;%(AdditionalLibraryDirectories) - true - 0x63000000 - false - true - - - - - - - - - - - true - true - true - true - true - true - true - true - - - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - - - - - - - - - - - - - - - - - - - - - - - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/libs/win32/mpg123/libmpg123/config.h b/libs/win32/mpg123/libmpg123/config.h deleted file mode 100644 index e79d420b50..0000000000 --- a/libs/win32/mpg123/libmpg123/config.h +++ /dev/null @@ -1,35 +0,0 @@ -/* basic config.h to reproduce pre-autoconf days */ - -#define HAVE_SYS_TYPES_H 1 -#define HAVE_SYS_WAIT_H -#define HAVE_SYS_RESOURCE_H -#define HAVE_SIGNAL_H 1 - -/* C99 integer types header... needed for ID3 parsing */ -//#define HAVE_INTTYPES_H 1 - -/* aggresive and realtime options were enabled per default... unless for generic build */ -#ifndef GENERIC -#define HAVE_SETPRIORITY -#ifndef NO_RT - #define HAVE_SCHED_H - #define HAVE_SCHED_SETSCHEDULER -#endif -#endif - -#define INDEX_SIZE 1000 - -/* Use this (or similar) if does not define or typedef off_t */ -/* #define off_t long int */ - -/* Use this (or similar) if does not define or typedef size_t. */ -/* #define size_t unsigned long int */ - -/* Use this (or similar) if does not define or typedef ssize_t. */ -/* #define ssize_t long int */ - -#ifndef HAVE_NO_STRERROR -#define HAVE_STRERROR 1 -#endif - -#include \ No newline at end of file diff --git a/libs/win32/mpg123/libmpg123/mpg123.h b/libs/win32/mpg123/libmpg123/mpg123.h deleted file mode 100644 index ae5dad9a71..0000000000 --- a/libs/win32/mpg123/libmpg123/mpg123.h +++ /dev/null @@ -1,790 +0,0 @@ -/* - libmpg123: MPEG Audio Decoder library (version @PACKAGE_VERSION@) - - copyright 1995-2007 by the mpg123 project - free software under the terms of the LGPL 2.1 - see COPYING and AUTHORS files in distribution or http://mpg123.org -*/ - -#ifndef MPG123_LIB_H -#define MPG123_LIB_H - -/** \file mpg123.h The header file for the libmpg123 MPEG Audio decoder */ - -/* These aren't actually in use... seems to work without using libtool. */ -#ifdef BUILD_MPG123_DLL -/* The dll exports. */ -#define EXPORT __declspec(dllexport) -#else -#ifdef LINK_MPG123_DLL -/* The exe imports. */ -#define EXPORT __declspec(dllimport) -#else -/* Nothing on normal/UNIX builds */ -#define EXPORT -#endif -#endif - -#include -#include -typedef int ssize_t; - -#ifdef __cplusplus -extern "C" { -#endif - -/** \defgroup mpg123_init mpg123 library and handle setup - * - * Functions to initialise and shutdown the mpg123 library and handles. - * The parameters of handles have workable defaults, you only have to tune them when you want to tune something;-) - * Tip: Use a RVA setting... - * - * @{ - */ - -/** Opaque structure for the libmpg123 decoder handle. */ -struct mpg123_handle_struct; - -/** Opaque structure for the libmpg123 decoder handle. - * Most functions take a pointer to a mpg123_handle as first argument and operate on its data in an object-oriented manner. - */ -typedef struct mpg123_handle_struct mpg123_handle; - -/** Function to initialise the mpg123 library. - * This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library. - * - * \return MPG123_OK if successful, otherwise an error number. - */ -EXPORT int mpg123_init(void); - -/** Function to close down the mpg123 library. - * This function is not thread-safe. Call it exactly once per process, before any other (possibly threaded) work with the library. */ -EXPORT void mpg123_exit(void); - -/** Create a handle with optional choice of decoder (named by a string, see mpg123_decoders() or mpg123_supported_decoders()). - * and optional retrieval of an error code to feed to mpg123_plain_strerror(). - * Optional means: Any of or both the parameters may be NULL. - * - * \return Non-NULL pointer when successful. - */ -EXPORT mpg123_handle *mpg123_new(const char* decoder, int *error); - -/** Delete handle, mh is either a valid mpg123 handle or NULL. */ -EXPORT void mpg123_delete(mpg123_handle *mh); - -/** Enumeration of the parameters types that it is possible to set/get. */ -enum mpg123_parms -{ - MPG123_VERBOSE, /**< set verbosity value for enabling messages to stderr, >= 0 makes sense */ - MPG123_FLAGS, /**< set all flags, p.ex val = MPG123_GAPLESS|MPG123_MONO_MIX */ - MPG123_ADD_FLAGS, /**< add some flags */ - MPG123_FORCE_RATE, /**< when value > 0, force output rate to that value */ - MPG123_DOWN_SAMPLE, /**< 0=native rate, 1=half rate, 2=quarter rate */ - MPG123_RVA, /**< one of the RVA choices above */ - MPG123_DOWNSPEED, /**< play a frame N times */ - MPG123_UPSPEED, /**< play every Nth frame */ - MPG123_START_FRAME, /**< start with this frame (skip frames before that) */ - MPG123_DECODE_FRAMES, /**< decode only this number of frames */ - MPG123_ICY_INTERVAL, /**< stream contains ICY metadata with this interval */ - MPG123_OUTSCALE, /**< the scale for output samples (amplitude) */ - MPG123_TIMEOUT, /**< timeout for reading from a stream (not supported on win32) */ - MPG123_REMOVE_FLAGS, /**< remove some flags (inverse of MPG123_ADD_FLAGS) */ - MPG123_RESYNC_LIMIT /**< Try resync on frame parsing for that many bytes or until end of stream (<0). */ -}; - -/** Flag bits for MPG123_FLAGS, use the usual binary or to combine. */ -enum mpg123_param_flags -{ - MPG123_FORCE_MONO = 0x7 /**< 0111 Force some mono mode: This is a test bitmask for seeing if any mono forcing is active. */ - ,MPG123_MONO_LEFT = 0x1 /**< 0001 Force playback of left channel only. */ - ,MPG123_MONO_RIGHT = 0x2 /**< 0010 Force playback of right channel only. */ - ,MPG123_MONO_MIX = 0x4 /**< 0100 Force playback of mixed mono. */ - ,MPG123_FORCE_STEREO = 0x8 /**< 1000 Force stereo output. */ - ,MPG123_FORCE_8BIT = 0x10 /**< 00010000 Force 8bit formats. */ - ,MPG123_QUIET = 0x20 /**< 00100000 Suppress any printouts (overrules verbose). */ - ,MPG123_GAPLESS = 0x40 /**< 01000000 Enable gapless decoding (default on if libmpg123 has support). */ - ,MPG123_NO_RESYNC = 0x80 /**< 10000000 Disable resync stream after error. */ - ,MPG123_SEEKBUFFER = 0x100 /**< 000100000000 Enable small buffer on non-seekable streams to allow some peek-ahead (for better MPEG sync). */ -}; - -/** choices for MPG123_RVA */ -enum mpg123_param_rva -{ - MPG123_RVA_OFF = 0 /**< RVA disabled (default). */ - ,MPG123_RVA_MIX = 1 /**< Use mix/track/radio gain. */ - ,MPG123_RVA_ALBUM = 2 /**< Use album/audiophile gain */ - ,MPG123_RVA_MAX = MPG123_RVA_ALBUM /**< The maximum RVA code, may increase in future. */ -}; - -/* TODO: Assess the possibilities and troubles of changing parameters during playback. */ - -/** Set a specific parameter, for a specific mpg123_handle, using a parameter - * type key chosen from the mpg123_parms enumeration, to the specified value. */ -EXPORT int mpg123_param(mpg123_handle *mh, enum mpg123_parms type, long value, double fvalue); - -/** Get a specific parameter, for a specific mpg123_handle. - * See the mpg123_parms enumeration for a list of available parameters. */ -EXPORT int mpg123_getparam(mpg123_handle *mh, enum mpg123_parms type, long *val, double *fval); - -/* @} */ - - -/** \defgroup mpg123_error mpg123 error handling - * - * Functions to get text version of the error numbers and an enumeration - * of the error codes returned by libmpg123. - * - * Most functions operating on a mpg123_handle simply return MPG123_OK on success and MPG123_ERR on failure (setting the internal error variable of the handle to the specific error code). - * Decoding/seek functions may also return message codes MPG123_DONE, MPG123_NEW_FORMAT and MPG123_NEED_MORE. - * The positive range of return values is used for "useful" values when appropriate. - * - * @{ - */ - -/** Enumeration of the message and error codes and returned by libmpg123 functions. */ -enum mpg123_errors -{ - MPG123_DONE=-12, /**< Message: Track ended. */ - MPG123_NEW_FORMAT=-11, /**< Message: Output format will be different on next call. */ - MPG123_NEED_MORE=-10, /**< Message: For feed reader: "Feed me more!" */ - MPG123_ERR=-1, /**< Generic Error */ - MPG123_OK=0, /**< Success */ - MPG123_BAD_OUTFORMAT, /**< Unable to set up output format! */ - MPG123_BAD_CHANNEL, /**< Invalid channel number specified. */ - MPG123_BAD_RATE, /**< Invalid sample rate specified. */ - MPG123_ERR_16TO8TABLE, /**< Unable to allocate memory for 16 to 8 converter table! */ - MPG123_BAD_PARAM, /**< Bad parameter id! */ - MPG123_BAD_BUFFER, /**< Bad buffer given -- invalid pointer or too small size. */ - MPG123_OUT_OF_MEM, /**< Out of memory -- some malloc() failed. */ - MPG123_NOT_INITIALIZED, /**< You didn't initialize the library! */ - MPG123_BAD_DECODER, /**< Invalid decoder choice. */ - MPG123_BAD_HANDLE, /**< Invalid mpg123 handle. */ - MPG123_NO_BUFFERS, /**< Unable to initialize frame buffers (out of memory?). */ - MPG123_BAD_RVA, /**< Invalid RVA mode. */ - MPG123_NO_GAPLESS, /**< This build doesn't support gapless decoding. */ - MPG123_NO_SPACE, /**< Not enough buffer space. */ - MPG123_BAD_TYPES, /**< Incompatible numeric data types. */ - MPG123_BAD_BAND, /**< Bad equalizer band. */ - MPG123_ERR_NULL, /**< Null pointer given where valid storage address needed. */ - MPG123_ERR_READER, /**< Error reading the stream. */ - MPG123_NO_SEEK_FROM_END,/**< Cannot seek from end (end is not known). */ - MPG123_BAD_WHENCE, /**< Invalid 'whence' for seek function.*/ - MPG123_NO_TIMEOUT, /**< Build does not support stream timeouts. */ - MPG123_BAD_FILE, /**< File access error. */ - MPG123_NO_SEEK, /**< Seek not supported by stream. */ - MPG123_NO_READER, /**< No stream opened. */ - MPG123_BAD_PARS, /**< Bad parameter handle. */ - MPG123_BAD_INDEX_PAR, /**< Bad parameters to mpg123_index() */ - MPG123_OUT_OF_SYNC, /**< Lost track in bytestream and did not try to resync. */ - MPG123_RESYNC_FAIL, /**< Resync failed to find valid MPEG data. */ - MPG123_NO_8BIT, /**< No 8bit encoding possible. */ - MPG123_BAD_ALIGN, /**< Stack aligmnent error */ - MPG123_NULL_BUFFER /**< NULL input buffer with non-zero size... */ -}; - -/** Return a string describing that error errcode means. */ -EXPORT const char* mpg123_plain_strerror(int errcode); - -/** Give string describing what error has occured in the context of handle mh. - * When a function operating on an mpg123 handle returns MPG123_ERR, you should check for the actual reason via - * char *errmsg = mpg123_strerror(mh) - * This function will catch mh == NULL and return the message for MPG123_BAD_HANDLE. */ -EXPORT const char* mpg123_strerror(mpg123_handle *mh); - -/** Return the plain errcode intead of a string. */ -EXPORT int mpg123_errcode(mpg123_handle *mh); - -/*@}*/ - - -/** \defgroup mpg123_decoder mpg123 decoder selection - * - * Functions to list and select the available decoders. - * Perhaps the most prominent feature of mpg123: You have several (optimized) decoders to choose from (on x86 and PPC (MacOS) systems, that is). - * - * @{ - */ - -/** Return a NULL-terminated array of generally available decoder names (plain 8bit ASCII). */ -EXPORT char **mpg123_decoders(); - -/** Return a NULL-terminated array of the decoders supported by the CPU (plain 8bit ASCII). */ -EXPORT char **mpg123_supported_decoders(); - -/** Set the chosen decoder to 'decoder_name' */ -EXPORT int mpg123_decoder(mpg123_handle *mh, const char* decoder_name); - -/*@}*/ - - -/** \defgroup mpg123_output mpg123 output audio format - * - * Functions to get and select the format of the decoded audio. - * - * @{ - */ - -/** 16 or 8 bits, signed or unsigned... all flags fit into 15 bits and are designed to have meaningful binary AND/OR. - * Adding float and 32bit int definitions for experimental fun. Only 32bit (and possibly 64bit) float is - * somewhat there with a dedicated library build. */ -enum mpg123_enc_enum -{ - MPG123_ENC_8 = 0x00f /**< 0000 0000 1111 Some 8 bit integer encoding. */ - ,MPG123_ENC_16 = 0x040 /**< 0000 0100 0000 Some 16 bit integer encoding. */ - ,MPG123_ENC_32 = 0x100 /**< 0001 0000 0000 Some 32 bit integer encoding. */ - ,MPG123_ENC_SIGNED = 0x080 /**< 0000 1000 0000 Some signed integer encoding. */ - ,MPG123_ENC_FLOAT = 0x800 /**< 1110 0000 0000 Some float encoding. */ - ,MPG123_ENC_SIGNED_16 = (MPG123_ENC_16|MPG123_ENC_SIGNED|0x10) /**< 0000 1101 0000 signed 16 bit */ - ,MPG123_ENC_UNSIGNED_16 = (MPG123_ENC_16|0x20) /**< 0000 0110 0000 unsigned 16 bit*/ - ,MPG123_ENC_UNSIGNED_8 = 0x01 /**< 0000 0000 0001 unsigned 8 bit*/ - ,MPG123_ENC_SIGNED_8 = (MPG123_ENC_SIGNED|0x02) /**< 0000 1000 0010 signed 8 bit*/ - ,MPG123_ENC_ULAW_8 = 0x04 /**< 0000 0000 0100 ulaw 8 bit*/ - ,MPG123_ENC_ALAW_8 = 0x08 /**< 0000 0000 1000 alaw 8 bit */ - ,MPG123_ENC_SIGNED_32 = MPG123_ENC_32|MPG123_ENC_SIGNED|0x10 /**< 0001 1001 0000 signed 32 bit */ - ,MPG123_ENC_UNSIGNED_32 = MPG123_ENC_32|0x20 /**< 0001 0010 0000 unsigned 32 bit */ - ,MPG123_ENC_FLOAT_32 = 0x200 /**< 0010 0000 0000 32bit float */ - ,MPG123_ENC_FLOAT_64 = 0x400 /**< 0100 0000 0000 64bit float */ - ,MPG123_ENC_ANY = ( MPG123_ENC_SIGNED_16 | MPG123_ENC_UNSIGNED_16 | MPG123_ENC_UNSIGNED_8 - | MPG123_ENC_SIGNED_8 | MPG123_ENC_ULAW_8 | MPG123_ENC_ALAW_8 - | MPG123_ENC_FLOAT_32 | MPG123_ENC_FLOAT_64 ) /**< any encoding */ -}; - -/** They can be combined into one number (3) to indicate mono and stereo... */ -enum mpg123_channelcount -{ - MPG123_MONO = 1 - ,MPG123_STEREO = 2 -}; - -/** An array of supported standard sample rates - * These are possible native sample rates of MPEG audio files. - * You can still force mpg123 to resample to a different one, but by default you will only get audio in one of these samplings. - * \param list Store a pointer to the sample rates array there. - * \param number Store the number of sample rates there. */ -EXPORT void mpg123_rates(const long **list, size_t *number); - -/** An array of supported audio encodings. - * An audio encoding is one of the fully qualified members of mpg123_enc_enum (MPG123_ENC_SIGNED_16, not MPG123_SIGNED). - * \param list Store a pointer to the encodings array there. - * \param number Store the number of encodings there. */ -EXPORT void mpg123_encodings(const int **list, size_t *number); - -/** Configure a mpg123 handle to accept no output format at all, - * use before specifying supported formats with mpg123_format */ -EXPORT int mpg123_format_none(mpg123_handle *mh); - -/** Configure mpg123 handle to accept all formats - * (also any custom rate you may set) -- this is default. */ -EXPORT int mpg123_format_all(mpg123_handle *mh); - -/** Set the audio format support of a mpg123_handle in detail: - * \param mh audio decoder handle - * \param rate The sample rate value (in Hertz). - * \param channels A combination of MPG123_STEREO and MPG123_MONO. - * \param encodings A combination of accepted encodings for rate and channels, p.ex MPG123_ENC_SIGNED16 | MPG123_ENC_ULAW_8 (or 0 for no support). Please note that some encodings may not be supported in the library build and thus will be ignored here. - * \return MPG123_OK on success, MPG123_ERR if there was an error. */ -EXPORT int mpg123_format(mpg123_handle *mh, long rate, int channels, int encodings); - -/** Check to see if a specific format at a specific rate is supported - * by mpg123_handle. - * \return 0 for no support (that includes invalid parameters), MPG123_STEREO, - * MPG123_MONO or MPG123_STEREO|MPG123_MONO. */ -EXPORT int mpg123_format_support(mpg123_handle *mh, long rate, int encoding); - -/** Get the current output format written to the addresses givenr. */ -EXPORT int mpg123_getformat(mpg123_handle *mh, long *rate, int *channels, int *encoding); - -/*@}*/ - - -/** \defgroup mpg123_input mpg123 file input and decoding - * - * Functions for input bitstream and decoding operations. - * - * @{ - */ - -/* reading samples / triggering decoding, possible return values: */ -/** Enumeration of the error codes returned by libmpg123 functions. */ - -/** Open and prepare to decode the specified file by filesystem path. - * This does not open HTTP urls; libmpg123 contains no networking code. - * If you want to decode internet streams, use mpg123_open_fd() or mpg123_open_feed(). - */ -EXPORT int mpg123_open(mpg123_handle *mh, const char *path); - -/** Use an already opened file descriptor as the bitstream input - * mpg123_close() will _not_ close the file descriptor. - */ -EXPORT int mpg123_open_fd(mpg123_handle *mh, int fd); - -/** Open a new bitstream and prepare for direct feeding - * This works together with mpg123_decode(); you are responsible for reading and feeding the input bitstream. - */ -EXPORT int mpg123_open_feed(mpg123_handle *mh); - -/** Closes the source, if libmpg123 opened it. */ -EXPORT int mpg123_close(mpg123_handle *mh); - -/** Read from stream and decode up to outmemsize bytes. - * \param outmemory address of output buffer to write to - * \param outmemsize maximum number of bytes to write - * \param done address to store the number of actually decoded bytes to - * \return error/message code (watch out for MPG123_DONE and friends!) */ -EXPORT int mpg123_read(mpg123_handle *mh, unsigned char *outmemory, size_t outmemsize, size_t *done); - -/** Feed data for a stream that has been opened with mpg123_open_feed(). - * It's give and take: You provide the bytestream, mpg123 gives you the decoded samples. - * \param in input buffer - * \param size number of input bytes - * \return error/message code. */ -EXPORT int mpg123_feed(mpg123_handle *mh, const unsigned char *in, size_t size); - -/** Decode MPEG Audio from inmemory to outmemory. - * This is very close to a drop-in replacement for old mpglib. - * When you give zero-sized output buffer the input will be parsed until - * decoded data is available. This enables you to get MPG123_NEW_FORMAT (and query it) - * without taking decoded data. - * Think of this function being the union of mpg123_read() and mpg123_feed() (which it actually is, sort of;-). - * You can actually always decide if you want those specialized functions in separate steps or one call this one here. - * \param inmemory input buffer - * \param inmemsize number of input bytes - * \param outmemory output buffer - * \param outmemsize maximum number of output bytes - * \param done address to store the number of actually decoded bytes to - * \return error/message code (watch out especially for MPG123_NEED_MORE) - */ -EXPORT int mpg123_decode(mpg123_handle *mh, const unsigned char *inmemory, size_t inmemsize, - unsigned char *outmemory, size_t outmemsize, size_t *done); - -/** Decode next MPEG frame to internal buffer - * or read a frame and return after setting a new format. - * \param num current frame offset gets stored there - * \param audio This pointer is set to the internal buffer to read the decoded audio from. - * \param bytes number of output bytes ready in the buffer - */ -EXPORT int mpg123_decode_frame(mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes); - -/*@}*/ - - -/** \defgroup mpg123_seek mpg123 position and seeking - * - * Functions querying and manipulating position in the decoded audio bitstream. - * The position is measured in decoded audio samples, or MPEG frame offset for the specific functions. - * If gapless code is in effect, the positions are adjusted to compensate the skipped padding/delay - meaning, you should not care about that at all and just use the position defined for the samples you get out of the decoder;-) - * The general usage is modelled after stdlib's ftell() and fseek(). - * Especially, the whence parameter for the seek functions has the same meaning as the one for fseek() and needs the same constants from stdlib.h: - * - SEEK_SET: set position to (or near to) specified offset - * - SEEK_CUR: change position by offset from now - * - SEEK_END: set position to offset from end - * - * Note that sample-afccurate seek only works when gapless support has been enabled at compile time; seek is frame-accurate otherwise. - * Also, seeking is not guaranteed to work for all streams (underlying stream may not support it). - * - * @{ - */ - -/** Returns the current position in samples. - * On the next read, you'd get that sample. */ -EXPORT off_t mpg123_tell(mpg123_handle *mh); - -/** Returns the frame number that the next read will give you data from. */ -EXPORT off_t mpg123_tellframe(mpg123_handle *mh); - -/** Seek to a desired sample offset. - * Set whence to SEEK_SET, SEEK_CUR or SEEK_END. - * \return The resulting offset >= 0 or error/message code */ -EXPORT off_t mpg123_seek(mpg123_handle *mh, off_t sampleoff, int whence); - -/** Seek to a desired sample offset in data feeding mode. - * This just prepares things to be right only if you ensure that the next chunk of input data will be from input_offset byte position. - * \param input_offset The position it expects to be at the - * next time data is fed to mpg123_decode(). - * \return The resulting offset >= 0 or error/message code */ -EXPORT off_t mpg123_feedseek(mpg123_handle *mh, off_t sampleoff, int whence, off_t *input_offset); - -/** Seek to a desired MPEG frame index. - * Set whence to SEEK_SET, SEEK_CUR or SEEK_END. - * \return The resulting offset >= 0 or error/message code */ -EXPORT off_t mpg123_seek_frame(mpg123_handle *mh, off_t frameoff, int whence); - -/** Return a MPEG frame offset corresponding to an offset in seconds. - * This assumes that the samples per frame do not change in the file/stream, which is a good assumption for any sane file/stream only. - * \return frame offset >= 0 or error/message code */ -EXPORT off_t mpg123_timeframe(mpg123_handle *mh, double sec); - -/** Give access to the frame index table that is managed for seeking. - * You are asked not to modify the values... unless you are really aware of what you are doing. - * \param offsets pointer to the index array - * \param step one index byte offset advances this many MPEG frames - * \param fill number of recorded index offsets; size of the array */ -EXPORT int mpg123_index(mpg123_handle *mh, off_t **offsets, off_t *step, size_t *fill); - -/** Get information about current and remaining frames/seconds. - * WARNING: This function is there because of special usage by standalone mpg123 and may be removed in the final version of libmpg123! - * You provide an offset (in frames) from now and a number of output bytes - * served by libmpg123 but not yet played. You get the projected current frame - * and seconds, as well as the remaining frames/seconds. This does _not_ care - * about skipped samples due to gapless playback. */ -EXPORT int mpg123_position( mpg123_handle *mh, off_t frame_offset, - off_t buffered_bytes, off_t *current_frame, - off_t *frames_left, double *current_seconds, - double *seconds_left); - -/*@}*/ - - -/** \defgroup mpg123_voleq mpg123 volume and equalizer - * - * @{ - */ - -enum mpg123_channels -{ - MPG123_LEFT=0x1 /**< The Left Channel. */ - ,MPG123_RIGHT=0x2 /**< The Right Channel. */ - ,MPG123_LR=0x3 /**< Both left and right channel; same as MPG123_LEFT|MPG123_RIGHT */ -}; - -/** Set the 32 Band Audio Equalizer settings. - * \param channel Can be MPG123_LEFT, MPG123_RIGHT or MPG123_LEFT|MPG123_RIGHT for both. - * \param band The equaliser band to change (from 0 to 31) - * \param val The (linear) adjustment factor. */ -EXPORT int mpg123_eq(mpg123_handle *mh, enum mpg123_channels channel, int band, double val); - -/** Reset the 32 Band Audio Equalizer settings to flat */ -EXPORT int mpg123_reset_eq(mpg123_handle *mh); - -/** Set the absolute output volume including the RVA setting, - * vol<0 just applies (a possibly changed) RVA setting. */ -EXPORT int mpg123_volume(mpg123_handle *mh, double vol); - -/** Adjust output volume including the RVA setting by chosen amount */ -EXPORT int mpg123_volume_change(mpg123_handle *mh, double change); - -/** Return current volume setting, the actual value due to RVA, and the RVA - * adjustment itself. It's all as double float value to abstract the sample - * format. The volume values are linear factors / amplitudes (not percent) - * and the RVA value is in decibels. */ -EXPORT int mpg123_getvolume(mpg123_handle *mh, double *base, double *really, double *rva_db); - -/* TODO: Set some preamp in addition / to replace internal RVA handling? */ - -/*@}*/ - - -/** \defgroup mpg123_status mpg123 status and information - * - * @{ - */ - -/** Enumeration of the mode types of Variable Bitrate */ -enum mpg123_vbr { - MPG123_CBR=0, /**< Constant Bitrate Mode (default) */ - MPG123_VBR, /**< Variable Bitrate Mode */ - MPG123_ABR /**< Average Bitrate Mode */ -}; - -/** Enumeration of the MPEG Versions */ -enum mpg123_version { - MPG123_1_0=0, /**< MPEG Version 1.0 */ - MPG123_2_0, /**< MPEG Version 2.0 */ - MPG123_2_5 /**< MPEG Version 2.5 */ -}; - - -/** Enumeration of the MPEG Audio mode. - * Only the mono mode has 1 channel, the others have 2 channels. */ -enum mpg123_mode { - MPG123_M_STEREO=0, /**< Standard Stereo. */ - MPG123_M_JOINT, /**< Joint Stereo. */ - MPG123_M_DUAL, /**< Dual Channel. */ - MPG123_M_MONO /**< Single Channel. */ -}; - - -/** Enumeration of the MPEG Audio flag bits */ -enum mpg123_flags { - MPG123_CRC=0x1, /**< The bitstream is error protected using 16-bit CRC. */ - MPG123_COPYRIGHT=0x2, /**< The bitstream is copyrighted. */ - MPG123_PRIVATE=0x4, /**< The private bit has been set. */ - MPG123_ORIGINAL=0x8 /**< The bitstream is an original, not a copy. */ -}; - -/** Data structure for storing information about a frame of MPEG Audio */ -struct mpg123_frameinfo -{ - enum mpg123_version version; /**< The MPEG version (1.0/2.0/2.5). */ - int layer; /**< The MPEG Audio Layer (MP1/MP2/MP3). */ - long rate; /**< The sampling rate in Hz. */ - enum mpg123_mode mode; /**< The audio mode (Mono, Stereo, Joint-stero, Dual Channel). */ - int mode_ext; /**< The mode extension bit flag. */ - int framesize; /**< The size of the frame (in bytes). */ - enum mpg123_flags flags; /**< MPEG Audio flag bits. */ - int emphasis; /**< The emphasis type. */ - int bitrate; /**< Bitrate of the frame (kbps). */ - int abr_rate; /**< The target average bitrate. */ - enum mpg123_vbr vbr; /**< The VBR mode. */ -}; - -/** Get frame information about the MPEG audio bitstream and store it in a mpg123_frameinfo structure. */ -EXPORT int mpg123_info(mpg123_handle *mh, struct mpg123_frameinfo *mi); - -/** Get the safe output buffer size for all cases (when you want to replace the internal buffer) */ -EXPORT size_t mpg123_safe_buffer(); - -/** Make a full parsing scan of each frame in the file. ID3 tags are found. An accurate length - * value is stored. Seek index will be filled. A seek back to current position - * is performed. At all, this function refuses work when stream is - * not seekable. - * \return MPG123_OK or MPG123_ERR. - */ -EXPORT int mpg123_scan(mpg123_handle *mh); - -/** Return, if possible, the full (expected) length of current track in samples. - * \return length >= 0 or MPG123_ERR if there is no length guess possible. */ -EXPORT off_t mpg123_length(mpg123_handle *mh); - -/** Override the value for file size in bytes. - * Useful for getting sensible track length values in feed mode or for HTTP streams. - * \return MPG123_OK or MPG123_ERR */ -EXPORT int mpg123_set_filesize(mpg123_handle *mh, off_t size); - -/** Returns the time (seconds) per frame; <0 is error. */ -EXPORT double mpg123_tpf(mpg123_handle *mh); - -/** Get and reset the clip count. */ -EXPORT long mpg123_clip(mpg123_handle *mh); - -/*@}*/ - - -/** \defgroup mpg123_metadata mpg123 metadata handling - * - * Functions to retrieve the metadata from MPEG Audio files and streams. - * Also includes string handling functions. - * - * @{ - */ - -/** Data structure for storing strings in a safer way than a standard C-String. - * Can also hold a number of null-terminated strings. */ -typedef struct -{ - char* p; /**< pointer to the string data */ - size_t size; /**< raw number of bytes allocated */ - size_t fill; /**< number of used bytes (including closing zero byte) */ -} mpg123_string; - -/** Create and allocate memory for a new mpg123_string */ -EXPORT void mpg123_init_string(mpg123_string* sb); - -/** Free-up mempory for an existing mpg123_string */ -EXPORT void mpg123_free_string(mpg123_string* sb); - -/** Change the size of a mpg123_string - * \return 0 on error, 1 on success */ -EXPORT int mpg123_resize_string(mpg123_string* sb, size_t news); - -/** Increase size of a mpg123_string if necessary (it may stay larger). - * Note that the functions for adding and setting in current libmpg123 use this instead of mpg123_resize_string(). - * That way, you can preallocate memory and safely work afterwards with pieces. - * \return 0 on error, 1 on success */ -EXPORT int mpg123_grow_string(mpg123_string* sb, size_t news); - -/** Copy the contents of one mpg123_string string to another. - * \return 0 on error, 1 on success */ -EXPORT int mpg123_copy_string(mpg123_string* from, mpg123_string* to); - -/** Append a C-String to an mpg123_string - * \return 0 on error, 1 on success */ -EXPORT int mpg123_add_string(mpg123_string* sb, const char* stuff); - -/** Append a C-substring to an mpg123 string - * \return 0 on error, 1 on success - * \param from offset to copy from - * \param count number of characters to copy (a null-byte is always appended) */ -EXPORT int mpg123_add_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count); - -/** Set the conents of a mpg123_string to a C-string - * \return 0 on error, 1 on success */ -EXPORT int mpg123_set_string(mpg123_string* sb, const char* stuff); - -/** Set the contents of a mpg123_string to a C-substring - * \return 0 on error, 1 on success - * \param from offset to copy from - * \param count number of characters to copy (a null-byte is always appended) */ -EXPORT int mpg123_set_substring(mpg123_string *sb, const char *stuff, size_t from, size_t count); - - -/** Sub data structure for ID3v2, for storing various text fields (including comments). - * This is for ID3v2 COMM, TXXX and all the other text fields. - * Only COMM and TXXX have a description, only COMM has a language. - * You should consult the ID3v2 specification for the use of the various text fields ("frames" in ID3v2 documentation, I use "fields" here to separate from MPEG frames). */ -typedef struct -{ - char lang[3]; /**< Three-letter language code (not terminated). */ - char id[4]; /**< The ID3v2 text field id, like TALB, TPE2, ... (4 characters, no string termination). */ - mpg123_string description; /**< Empty for the generic comment... */ - mpg123_string text; /**< ... */ -} mpg123_text; - -/** Data structure for storing IDV3v2 tags. - * This structure is not a direct binary mapping with the file contents. - * The ID3v2 text frames are allowed to contain multiple strings. - * So check for null bytes until you reach the mpg123_string fill. - * All text is encoded in UTF-8. */ -typedef struct -{ - unsigned char version; /**< 3 or 4 for ID3v2.3 or ID3v2.4. */ - mpg123_string *title; /**< Title string (pointer into text_list). */ - mpg123_string *artist; /**< Artist string (pointer into text_list). */ - mpg123_string *album; /**< Album string (pointer into text_list). */ - mpg123_string *year; /**< The year as a string (pointer into text_list). */ - mpg123_string *genre; /**< Genre String (pointer into text_list). The genre string(s) may very well need postprocessing, esp. for ID3v2.3. */ - mpg123_string *comment; /**< Pointer to last encountered comment text with empty description. */ - /* Encountered ID3v2 fields are appended to these lists. - There can be multiple occurences, the pointers above always point to the last encountered data. */ - mpg123_text *comment_list; /**< Array of comments. */ - size_t comments; /**< Number of comments. */ - mpg123_text *text; /**< Array of ID3v2 text fields */ - size_t texts; /**< Numer of text fields. */ - mpg123_text *extra; /**< The array of extra (TXXX) fields. */ - size_t extras; /**< Number of extra text (TXXX) fields. */ -} mpg123_id3v2; - -/** Data structure for ID3v1 tags (the last 128 bytes of a file). - * Don't take anything for granted (like string termination)! - * Also note the change ID3v1.1 did: comment[28] = 0; comment[19] = track_number - * It is your task to support ID3v1 only or ID3v1.1 ...*/ -typedef struct -{ - char tag[3]; /**< Always the string "TAG", the classic intro. */ - char title[30]; /**< Title string. */ - char artist[30]; /**< Artist string. */ - char album[30]; /**< Album string. */ - char year[4]; /**< Year string. */ - char comment[30]; /**< Comment string. */ - unsigned char genre; /**< Genre index. */ -} mpg123_id3v1; - -#define MPG123_ID3 0x3 /**< 0011 There is some ID3 info. Also matches 0010 or NEW_ID3. */ -#define MPG123_NEW_ID3 0x1 /**< 0001 There is ID3 info that changed since last call to mpg123_id3. */ -#define MPG123_ICY 0xc /**< 1100 There is some ICY info. Also matches 0100 or NEW_ICY.*/ -#define MPG123_NEW_ICY 0x4 /**< 0100 There is ICY info that changed since last call to mpg123_icy. */ - -/** Query if there is (new) meta info, be it ID3 or ICY (or something new in future). - The check function returns a combination of flags. */ -EXPORT int mpg123_meta_check(mpg123_handle *mh); /* On error (no valid handle) just 0 is returned. */ - -/** Point v1 and v2 to existing data structures wich may change on any next read/decode function call. - * v1 and/or v2 can be set to NULL when there is no corresponding data. - * \return Return value is MPG123_OK or MPG123_ERR, */ -EXPORT int mpg123_id3(mpg123_handle *mh, mpg123_id3v1 **v1, mpg123_id3v2 **v2); - -/** Point icy_meta to existing data structure wich may change on any next read/decode function call. - * \return Return value is MPG123_OK or MPG123_ERR, */ -EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta); /* same for ICY meta string */ - -/** Decode from windows-1252 (the encoding ICY metainfo used) to UTF-8. - * \param icy_text The input data in ICY encoding - * \return pointer to newly allocated buffer with UTF-8 data (You free() it!) */ -EXPORT char* mpg123_icy2utf8(const char* icy_text); - - -/* @} */ - - -/** \defgroup mpg123_advpar mpg123 advanced parameter API - * - * Direct access to a parameter set without full handle around it. - * Possible uses: - * - Influence behaviour of library _during_ initialization of handle (MPG123_VERBOSE). - * - Use one set of parameters for multiple handles. - * - * The functions for handling mpg123_pars (mpg123_par() and mpg123_fmt() - * family) directly return a fully qualified mpg123 error code, the ones - * operating on full handles normally MPG123_OK or MPG123_ERR, storing the - * specific error code itseld inside the handle. - * - * @{ - */ - -/** Opaque structure for the libmpg123 decoder parameters. */ -struct mpg123_pars_struct; - -/** Opaque structure for the libmpg123 decoder parameters. */ -typedef struct mpg123_pars_struct mpg123_pars; - -/** Create a handle with preset parameters. */ -EXPORT mpg123_handle *mpg123_parnew(mpg123_pars *mp, const char* decoder, int *error); - -/** Allocate memory for and return a pointer to a new mpg123_pars */ -EXPORT mpg123_pars *mpg123_new_pars(int *error); - -/** Delete and free up memory used by a mpg123_pars data structure */ -EXPORT void mpg123_delete_pars(mpg123_pars* mp); - -/** Configure mpg123 parameters to accept no output format at all, - * use before specifying supported formats with mpg123_format */ -EXPORT int mpg123_fmt_none(mpg123_pars *mp); - -/** Configure mpg123 parameters to accept all formats - * (also any custom rate you may set) -- this is default. */ -EXPORT int mpg123_fmt_all(mpg123_pars *mp); - -/** Set the audio format support of a mpg123_pars in detail: - \param rate The sample rate value (in Hertz). - \param channels A combination of MPG123_STEREO and MPG123_MONO. - \param encodings A combination of accepted encodings for rate and channels, p.ex MPG123_ENC_SIGNED16|MPG123_ENC_ULAW_8 (or 0 for no support). - \return 0 on success, -1 if there was an error. / -*/ -EXPORT int mpg123_fmt(mpg123_pars *mh, long rate, int channels, int encodings); /* 0 is good, -1 is error */ - -/** Check to see if a specific format at a specific rate is supported - * by mpg123_pars. - * \return 0 for no support (that includes invalid parameters), MPG123_STEREO, - * MPG123_MONO or MPG123_STEREO|MPG123_MONO. */ -EXPORT int mpg123_fmt_support(mpg123_pars *mh, long rate, int encoding); - -/** Set a specific parameter, for a specific mpg123_pars, using a parameter - * type key chosen from the mpg123_parms enumeration, to the specified value. */ -EXPORT int mpg123_par(mpg123_pars *mp, enum mpg123_parms type, long value, double fvalue); - -/** Get a specific parameter, for a specific mpg123_pars. - * See the mpg123_parms enumeration for a list of available parameters. */ -EXPORT int mpg123_getpar(mpg123_pars *mp, enum mpg123_parms type, long *val, double *fval); - -/* @} */ - - -/** \defgroup mpg123_lowio mpg123 low level I/O - * You may want to do tricky stuff with I/O that does not work with mpg123's default file access or you want to make it decode into your own pocket... - * - * @{ */ - -/** Replace default internal buffer with user-supplied buffer. - * Instead of working on it's own private buffer, mpg123 will directly use the one you provide for storing decoded audio. */ -EXPORT int mpg123_replace_buffer(mpg123_handle *mh, unsigned char *data, size_t size); - -/** The max size of one frame's decoded output with current settings. - * Use that to determine an appropriate minimum buffer size for decoding one frame. */ -EXPORT size_t mpg123_outblock(mpg123_handle *mh); - -/** Replace low-level stream access functions; read and lseek as known in POSIX. - * You can use this to make any fancy file opening/closing yourself, - * using open_fd to set the file descriptor for your read/lseek (doesn't need to be a "real" file descriptor...). - * Setting a function to NULL means that the default internal read is - * used (active from next mpg123_open call on). */ -EXPORT int mpg123_replace_reader( mpg123_handle *mh, - ssize_t (*r_read) (int, void *, size_t), - off_t (*r_lseek)(int, off_t, int) ); - -/* @} */ - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libs/win32/pthread/cleancount b/libs/win32/pthread/cleancount deleted file mode 100644 index 56a6051ca2..0000000000 --- a/libs/win32/pthread/cleancount +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/libs/win32/pthread/pthread.2017.vcxproj b/libs/win32/pthread/pthread.2017.vcxproj deleted file mode 100644 index e33f2881fe..0000000000 --- a/libs/win32/pthread/pthread.2017.vcxproj +++ /dev/null @@ -1,451 +0,0 @@ - - - - - Debug DLL - Win32 - - - Debug DLL - x64 - - - Debug - Win32 - - - Debug - x64 - - - Release DLL - Win32 - - - Release DLL - x64 - - - Release - Win32 - - - Release - x64 - - - - pthread - {DF018947-0FFF-4EB3-BDEE-441DC81DA7A4} - pthread - - - - - DynamicLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - DynamicLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - DynamicLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - DynamicLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(Platform)\$(Configuration)\ - $(Platform)\pthread\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\pthread\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\pthread\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\pthread\$(Configuration)\ - true - true - false - false - $(SolutionDir)$(PlatformName)\debug\ - $(SolutionDir)$(PlatformName)\release\ - $(SolutionDir)$(PlatformName)\release\ - $(SolutionDir)$(PlatformName)\debug\ - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Win32 - .\./pthread.tlb - - - - - MaxSpeed - OnlyExplicitInline - ../../pthreads-w32-2-9-1/;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;HAVE_CONFIG_H;__CLEANUP_C;WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;PTW32_STATIC_LIB;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - .\./pthread.pch - $(IntDir) - $(IntDir) - $(IntDir)vc80.pdb - false - Level3 - true - - - NDEBUG;PTW32_RC_MSC;PTW32_ARCHx86;%(PreprocessorDefinitions) - 0x0409 - .;%(AdditionalIncludeDirectories) - - - true - .\./pthread.bsc - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - X64 - .\./pthread.tlb - - - - - MaxSpeed - OnlyExplicitInline - ../../pthreads-w32-2-9-1/;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;HAVE_CONFIG_H;__CLEANUP_C;WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;PTW32_STATIC_LIB;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - .\./pthread.pch - $(IntDir) - $(IntDir) - $(IntDir)vc80.pdb - false - Level3 - true - - - NDEBUG;PTW32_RC_MSC;PTW32_ARCHx64;WIN64;%(PreprocessorDefinitions) - 0x0409 - .;%(AdditionalIncludeDirectories) - - - true - .\./pthread.bsc - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - Win32 - .\./pthread.tlb - - - - - Disabled - ../../pthreads-w32-2-9-1/;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;HAVE_CONFIG_H;__CLEANUP_C;WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;PTW32_STATIC_LIB;%(PreprocessorDefinitions) - false - Default - MultiThreadedDebugDLL - .\./pthread.pch - $(IntDir) - $(IntDir) - $(IntDir)vc80.pdb - false - Level3 - true - ProgramDatabase - - - _DEBUG;PTW32_RC_MSC;PTW32_ARCHx86;%(PreprocessorDefinitions) - 0x0409 - .;%(AdditionalIncludeDirectories) - - - true - .\./pthread.bsc - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - X64 - .\./pthread.tlb - - - - - Disabled - ../../pthreads-w32-2-9-1/;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;HAVE_CONFIG_H;__CLEANUP_C;WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;PTW32_STATIC_LIB;%(PreprocessorDefinitions) - false - Default - MultiThreadedDebugDLL - .\./pthread.pch - $(IntDir) - $(IntDir) - $(IntDir)vc80.pdb - false - Level3 - true - ProgramDatabase - - - _DEBUG;PTW32_RC_MSC;PTW32_ARCHx64;WIN64;%(PreprocessorDefinitions) - 0x0409 - .;%(AdditionalIncludeDirectories) - - - true - .\./pthread.bsc - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - Win32 - - - Disabled - ../../pthreads-w32-2-9-1/;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;HAVE_CONFIG_H;__CLEANUP_C;WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - Level3 - true - - - _DEBUG;PTW32_RC_MSC;PTW32_ARCHx86;%(PreprocessorDefinitions) - 0x0409 - .;%(AdditionalIncludeDirectories) - - - ws2_32.lib;%(AdditionalDependencies) - true - true - false - MachineX86 - - - true - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - X64 - - - Disabled - ../../pthreads-w32-2-9-1/;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;HAVE_CONFIG_H;__CLEANUP_C;WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - Level3 - true - - - _DEBUG;PTW32_RC_MSC;PTW32_ARCHx64;WIN64;%(PreprocessorDefinitions) - 0x0409 - .;%(AdditionalIncludeDirectories) - - - ws2_32.lib;%(AdditionalDependencies) - true - true - false - MachineX64 - - - true - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Win32 - - - MaxSpeed - OnlyExplicitInline - ../../pthreads-w32-2-9-1/;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;HAVE_CONFIG_H;__CLEANUP_C;WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - Level3 - true - - - NDEBUG;PTW32_RC_MSC;PTW32_ARCHx86;%(PreprocessorDefinitions) - 0x0409 - .;%(AdditionalIncludeDirectories) - - - ws2_32.lib;%(AdditionalDependencies) - true - false - MachineX86 - - - true - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - X64 - - - MaxSpeed - OnlyExplicitInline - ../../pthreads-w32-2-9-1/;%(AdditionalIncludeDirectories) - _TIMESPEC_DEFINED;HAVE_CONFIG_H;__CLEANUP_C;WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - Level3 - true - - - NDEBUG;PTW32_RC_MSC;PTW32_ARCHx64;WIN64;%(PreprocessorDefinitions) - 0x0409 - .;%(AdditionalIncludeDirectories) - - - ws2_32.lib;%(AdditionalDependencies) - true - false - MachineX64 - - - true - - - - - - - - - - - - - - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - - - - - - \ No newline at end of file diff --git a/libs/win32/sofia/libsofia_sip_ua_static.2017.vcxproj b/libs/win32/sofia/libsofia_sip_ua_static.2017.vcxproj index d47c3975c5..ba2bd00bdb 100644 --- a/libs/win32/sofia/libsofia_sip_ua_static.2017.vcxproj +++ b/libs/win32/sofia/libsofia_sip_ua_static.2017.vcxproj @@ -49,6 +49,7 @@ $(DefaultPlatformToolset) + @@ -85,7 +86,7 @@ if not exist "$(ProjectDir)$(IntDir)\auth_client.obj" "autogen.cmd" Disabled - ..\..\sofia-sip\win32;..\..\sofia-sip\libsofia-sip-ua\su;..\..\sofia-sip\libsofia-sip-ua\ipt;..\..\sofia-sip\libsofia-sip-ua\sresolv;..\..\sofia-sip\libsofia-sip-ua\bnf;..\..\sofia-sip\libsofia-sip-ua\url;..\..\sofia-sip\libsofia-sip-ua\msg;..\..\sofia-sip\libsofia-sip-ua\sip;..\..\sofia-sip\libsofia-sip-ua\nta;..\..\sofia-sip\libsofia-sip-ua\nua;..\..\sofia-sip\libsofia-sip-ua\iptsec;..\..\sofia-sip\libsofia-sip-ua\http;..\..\sofia-sip\libsofia-sip-ua\nth;..\..\sofia-sip\libsofia-sip-ua\nea;..\..\sofia-sip\libsofia-sip-ua\sdp;..\..\sofia-sip\libsofia-sip-ua\soa;..\..\sofia-sip\libsofia-sip-ua\stun;..\..\sofia-sip\libsofia-sip-ua\tport;..\..\sofia-sip\libsofia-sip-ua\tport\include;..\..\sofia-sip\libsofia-sip-ua\features;..\..\pthreads-w32-2-9-1;.;..\..\..\src\include;%(AdditionalIncludeDirectories) + ..\..\sofia-sip\win32;..\..\sofia-sip\libsofia-sip-ua\su;..\..\sofia-sip\libsofia-sip-ua\ipt;..\..\sofia-sip\libsofia-sip-ua\sresolv;..\..\sofia-sip\libsofia-sip-ua\bnf;..\..\sofia-sip\libsofia-sip-ua\url;..\..\sofia-sip\libsofia-sip-ua\msg;..\..\sofia-sip\libsofia-sip-ua\sip;..\..\sofia-sip\libsofia-sip-ua\nta;..\..\sofia-sip\libsofia-sip-ua\nua;..\..\sofia-sip\libsofia-sip-ua\iptsec;..\..\sofia-sip\libsofia-sip-ua\http;..\..\sofia-sip\libsofia-sip-ua\nth;..\..\sofia-sip\libsofia-sip-ua\nea;..\..\sofia-sip\libsofia-sip-ua\sdp;..\..\sofia-sip\libsofia-sip-ua\soa;..\..\sofia-sip\libsofia-sip-ua\stun;..\..\sofia-sip\libsofia-sip-ua\tport;..\..\sofia-sip\libsofia-sip-ua\tport\include;..\..\sofia-sip\libsofia-sip-ua\features;.;..\..\..\src\include;%(AdditionalIncludeDirectories) _TIMESPEC_DEFINED;WIN32;_DEBUG;_LIB;IN_LIBSOFIA_SIP_UA_STATIC;LIBSOFIA_SIP_UA_STATIC;LIBSRES_STATIC;PTW32_STATIC_LIB;HAVE_IPHLPAPI_H;SU_DEBUG=0;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -121,7 +122,7 @@ if not exist "$(ProjectDir)$(IntDir)\auth_client.obj" "autogen.cmd" Disabled - ..\..\sofia-sip\win32;..\..\sofia-sip\libsofia-sip-ua\su;..\..\sofia-sip\libsofia-sip-ua\ipt;..\..\sofia-sip\libsofia-sip-ua\sresolv;..\..\sofia-sip\libsofia-sip-ua\bnf;..\..\sofia-sip\libsofia-sip-ua\url;..\..\sofia-sip\libsofia-sip-ua\msg;..\..\sofia-sip\libsofia-sip-ua\sip;..\..\sofia-sip\libsofia-sip-ua\nta;..\..\sofia-sip\libsofia-sip-ua\nua;..\..\sofia-sip\libsofia-sip-ua\iptsec;..\..\sofia-sip\libsofia-sip-ua\http;..\..\sofia-sip\libsofia-sip-ua\nth;..\..\sofia-sip\libsofia-sip-ua\nea;..\..\sofia-sip\libsofia-sip-ua\sdp;..\..\sofia-sip\libsofia-sip-ua\soa;..\..\sofia-sip\libsofia-sip-ua\stun;..\..\sofia-sip\libsofia-sip-ua\tport;..\..\sofia-sip\libsofia-sip-ua\tport\include;..\..\sofia-sip\libsofia-sip-ua\features;..\..\pthreads-w32-2-9-1;.;..\..\..\src\include;%(AdditionalIncludeDirectories) + ..\..\sofia-sip\win32;..\..\sofia-sip\libsofia-sip-ua\su;..\..\sofia-sip\libsofia-sip-ua\ipt;..\..\sofia-sip\libsofia-sip-ua\sresolv;..\..\sofia-sip\libsofia-sip-ua\bnf;..\..\sofia-sip\libsofia-sip-ua\url;..\..\sofia-sip\libsofia-sip-ua\msg;..\..\sofia-sip\libsofia-sip-ua\sip;..\..\sofia-sip\libsofia-sip-ua\nta;..\..\sofia-sip\libsofia-sip-ua\nua;..\..\sofia-sip\libsofia-sip-ua\iptsec;..\..\sofia-sip\libsofia-sip-ua\http;..\..\sofia-sip\libsofia-sip-ua\nth;..\..\sofia-sip\libsofia-sip-ua\nea;..\..\sofia-sip\libsofia-sip-ua\sdp;..\..\sofia-sip\libsofia-sip-ua\soa;..\..\sofia-sip\libsofia-sip-ua\stun;..\..\sofia-sip\libsofia-sip-ua\tport;..\..\sofia-sip\libsofia-sip-ua\tport\include;..\..\sofia-sip\libsofia-sip-ua\features;.;..\..\..\src\include;%(AdditionalIncludeDirectories) _TIMESPEC_DEFINED;_WIN64;WIN32;_DEBUG;_LIB;IN_LIBSOFIA_SIP_UA_STATIC;LIBSOFIA_SIP_UA_STATIC;LIBSRES_STATIC;PTW32_STATIC_LIB;HAVE_IPHLPAPI_H;SU_DEBUG=0;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -155,7 +156,7 @@ if not exist "$(ProjectDir)$(IntDir)\auth_client.obj" "autogen.cmd" MaxSpeed OnlyExplicitInline - ..\..\sofia-sip\win32;..\..\sofia-sip\libsofia-sip-ua\su;..\..\sofia-sip\libsofia-sip-ua\ipt;..\..\sofia-sip\libsofia-sip-ua\sresolv;..\..\sofia-sip\libsofia-sip-ua\bnf;..\..\sofia-sip\libsofia-sip-ua\url;..\..\sofia-sip\libsofia-sip-ua\msg;..\..\sofia-sip\libsofia-sip-ua\sip;..\..\sofia-sip\libsofia-sip-ua\nta;..\..\sofia-sip\libsofia-sip-ua\nua;..\..\sofia-sip\libsofia-sip-ua\iptsec;..\..\sofia-sip\libsofia-sip-ua\http;..\..\sofia-sip\libsofia-sip-ua\nth;..\..\sofia-sip\libsofia-sip-ua\nea;..\..\sofia-sip\libsofia-sip-ua\sdp;..\..\sofia-sip\libsofia-sip-ua\soa;..\..\sofia-sip\libsofia-sip-ua\stun;..\..\sofia-sip\libsofia-sip-ua\tport;..\..\sofia-sip\libsofia-sip-ua\tport\include;..\..\sofia-sip\libsofia-sip-ua\features;..\..\pthreads-w32-2-9-1;.;..\..\..\src\include;%(AdditionalIncludeDirectories) + ..\..\sofia-sip\win32;..\..\sofia-sip\libsofia-sip-ua\su;..\..\sofia-sip\libsofia-sip-ua\ipt;..\..\sofia-sip\libsofia-sip-ua\sresolv;..\..\sofia-sip\libsofia-sip-ua\bnf;..\..\sofia-sip\libsofia-sip-ua\url;..\..\sofia-sip\libsofia-sip-ua\msg;..\..\sofia-sip\libsofia-sip-ua\sip;..\..\sofia-sip\libsofia-sip-ua\nta;..\..\sofia-sip\libsofia-sip-ua\nua;..\..\sofia-sip\libsofia-sip-ua\iptsec;..\..\sofia-sip\libsofia-sip-ua\http;..\..\sofia-sip\libsofia-sip-ua\nth;..\..\sofia-sip\libsofia-sip-ua\nea;..\..\sofia-sip\libsofia-sip-ua\sdp;..\..\sofia-sip\libsofia-sip-ua\soa;..\..\sofia-sip\libsofia-sip-ua\stun;..\..\sofia-sip\libsofia-sip-ua\tport;..\..\sofia-sip\libsofia-sip-ua\tport\include;..\..\sofia-sip\libsofia-sip-ua\features;.;..\..\..\src\include;%(AdditionalIncludeDirectories) _TIMESPEC_DEFINED;WIN32;NDEBUG;_LIB;IN_LIBSOFIA_SIP_UA_STATIC;LIBSOFIA_SIP_UA_STATIC;LIBSRES_STATIC;PTW32_STATIC_LIB;HAVE_IPHLPAPI_H;SU_DEBUG=0;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -192,7 +193,7 @@ if not exist "$(ProjectDir)$(IntDir)\auth_client.obj" "autogen.cmd" MaxSpeed OnlyExplicitInline - ..\..\sofia-sip\win32;..\..\sofia-sip\libsofia-sip-ua\su;..\..\sofia-sip\libsofia-sip-ua\ipt;..\..\sofia-sip\libsofia-sip-ua\sresolv;..\..\sofia-sip\libsofia-sip-ua\bnf;..\..\sofia-sip\libsofia-sip-ua\url;..\..\sofia-sip\libsofia-sip-ua\msg;..\..\sofia-sip\libsofia-sip-ua\sip;..\..\sofia-sip\libsofia-sip-ua\nta;..\..\sofia-sip\libsofia-sip-ua\nua;..\..\sofia-sip\libsofia-sip-ua\iptsec;..\..\sofia-sip\libsofia-sip-ua\http;..\..\sofia-sip\libsofia-sip-ua\nth;..\..\sofia-sip\libsofia-sip-ua\nea;..\..\sofia-sip\libsofia-sip-ua\sdp;..\..\sofia-sip\libsofia-sip-ua\soa;..\..\sofia-sip\libsofia-sip-ua\stun;..\..\sofia-sip\libsofia-sip-ua\tport;..\..\sofia-sip\libsofia-sip-ua\tport\include;..\..\sofia-sip\libsofia-sip-ua\features;..\..\pthreads-w32-2-9-1;.;..\..\..\src\include;%(AdditionalIncludeDirectories) + ..\..\sofia-sip\win32;..\..\sofia-sip\libsofia-sip-ua\su;..\..\sofia-sip\libsofia-sip-ua\ipt;..\..\sofia-sip\libsofia-sip-ua\sresolv;..\..\sofia-sip\libsofia-sip-ua\bnf;..\..\sofia-sip\libsofia-sip-ua\url;..\..\sofia-sip\libsofia-sip-ua\msg;..\..\sofia-sip\libsofia-sip-ua\sip;..\..\sofia-sip\libsofia-sip-ua\nta;..\..\sofia-sip\libsofia-sip-ua\nua;..\..\sofia-sip\libsofia-sip-ua\iptsec;..\..\sofia-sip\libsofia-sip-ua\http;..\..\sofia-sip\libsofia-sip-ua\nth;..\..\sofia-sip\libsofia-sip-ua\nea;..\..\sofia-sip\libsofia-sip-ua\sdp;..\..\sofia-sip\libsofia-sip-ua\soa;..\..\sofia-sip\libsofia-sip-ua\stun;..\..\sofia-sip\libsofia-sip-ua\tport;..\..\sofia-sip\libsofia-sip-ua\tport\include;..\..\sofia-sip\libsofia-sip-ua\features;.;..\..\..\src\include;%(AdditionalIncludeDirectories) _TIMESPEC_DEFINED;_WIN64;WIN32;NDEBUG;_LIB;IN_LIBSOFIA_SIP_UA_STATIC;LIBSOFIA_SIP_UA_STATIC;LIBSRES_STATIC;PTW32_STATIC_LIB;HAVE_IPHLPAPI_H;SU_DEBUG=0;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -513,10 +514,6 @@ if not exist "$(ProjectDir)$(IntDir)\auth_client.obj" "autogen.cmd" - - {df018947-0fff-4eb3-bdee-441dc81da7a4} - false - diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.2017.vcxproj b/src/mod/endpoints/mod_sofia/mod_sofia.2017.vcxproj index 8d07b50687..050781028b 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.2017.vcxproj +++ b/src/mod/endpoints/mod_sofia/mod_sofia.2017.vcxproj @@ -46,6 +46,7 @@ $(DefaultPlatformToolset) + @@ -180,10 +181,6 @@ {f6c55d93-b927-4483-bb69-15aef3dd2dff} false - - {df018947-0fff-4eb3-bdee-441dc81da7a4} - false - {70a49bc2-7500-41d0-b75d-edcc5be987a0} diff --git a/src/mod/endpoints/mod_verto/mod_verto.2017.vcxproj b/src/mod/endpoints/mod_verto/mod_verto.2017.vcxproj index ff3b53037f..75b49b66a4 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.2017.vcxproj +++ b/src/mod/endpoints/mod_verto/mod_verto.2017.vcxproj @@ -46,6 +46,7 @@ $(DefaultPlatformToolset) + @@ -74,7 +75,7 @@ - $(SolutionDir)\src\include;%(AdditionalIncludeDirectories);$(ProjectDir)..\..\..\..\libs\pthreads-w32-2-9-1;.\;.\mcast + $(SolutionDir)\src\include;%(AdditionalIncludeDirectories);.\;.\mcast _TIMESPEC_DEFINED;_DEBUG;DEBUG;%(PreprocessorDefinitions) 6053;6031;6340;6246;6011;6387;%(DisableSpecificWarnings) @@ -91,7 +92,7 @@ - $(SolutionDir)\src\include;%(AdditionalIncludeDirectories);$(ProjectDir)..\..\..\..\libs\pthreads-w32-2-9-1;.\;.\mcast + $(SolutionDir)\src\include;%(AdditionalIncludeDirectories);.\;.\mcast _TIMESPEC_DEFINED;_DEBUG;DEBUG;%(PreprocessorDefinitions) 6053;6031;6340;6246;6011;6387;%(DisableSpecificWarnings) @@ -106,7 +107,7 @@ - $(SolutionDir)\src\include;%(AdditionalIncludeDirectories);$(ProjectDir)..\..\..\..\libs\pthreads-w32-2-9-1;.\;.\mcast + $(SolutionDir)\src\include;%(AdditionalIncludeDirectories);.\;.\mcast _TIMESPEC_DEFINED;NDEBUG;%(PreprocessorDefinitions) 6053;6031;6340;6246;6011;6387;%(DisableSpecificWarnings) @@ -123,7 +124,7 @@ - $(SolutionDir)\src\include;%(AdditionalIncludeDirectories);$(ProjectDir)..\..\..\..\libs\pthreads-w32-2-9-1;.\;.\mcast + $(SolutionDir)\src\include;%(AdditionalIncludeDirectories);.\;.\mcast _TIMESPEC_DEFINED;NDEBUG;%(PreprocessorDefinitions) 6053;6031;6340;6246;6011;6387;%(DisableSpecificWarnings) @@ -144,10 +145,6 @@ {202d7a4e-760d-4d0e-afa1-d7459ced30ff} false - - {df018947-0fff-4eb3-bdee-441dc81da7a4} - false - diff --git a/src/mod/formats/mod_shout/mod_shout.2017.vcxproj b/src/mod/formats/mod_shout/mod_shout.2017.vcxproj index 10a06d52ad..6556f99489 100644 --- a/src/mod/formats/mod_shout/mod_shout.2017.vcxproj +++ b/src/mod/formats/mod_shout/mod_shout.2017.vcxproj @@ -48,6 +48,8 @@ + + @@ -75,7 +77,6 @@ Disabled - ..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) _TIMESPEC_DEFINED;%(PreprocessorDefinitions) true EnableFastChecks @@ -96,7 +97,6 @@ Disabled - ..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) %(PreprocessorDefinitions) true EnableFastChecks @@ -115,7 +115,6 @@ MaxSpeed true - ..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) _TIMESPEC_DEFINED;%(PreprocessorDefinitions) MultiThreadedDLL true @@ -138,7 +137,6 @@ MaxSpeed true - ..\..\..\..\libs\win32\libshout;..\..\..\..\libs\libshout-2.2.2\include;..\..\..\..\libs\mpg123\src;..\..\..\..\libs\win32\mpg123;..\..\..\..\libs\win32\mpg123\libmpg123;%(AdditionalIncludeDirectories) %(PreprocessorDefinitions) MultiThreadedDLL true @@ -163,21 +161,6 @@ - - {0feeaec6-4399-4c46-b7db-62ece80d15b4} - - - {d3d8b329-20be-475e-9e83-653cea0e0ef5} - false - - - {419c8f80-d858-4b48-a25c-af4007608137} - false - - - {df018947-0fff-4eb3-bdee-441dc81da7a4} - false - {202d7a4e-760d-4d0e-afa1-d7459ced30ff} false diff --git a/w32/download_OGG.props b/w32/download_OGG.props deleted file mode 100644 index cd9c91f62a..0000000000 --- a/w32/download_OGG.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/download_libshout.props b/w32/download_libshout.props deleted file mode 100644 index 0832ca2cd4..0000000000 --- a/w32/download_libshout.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/download_mpg123.props b/w32/download_mpg123.props deleted file mode 100644 index 7e3353c5e8..0000000000 --- a/w32/download_mpg123.props +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - true - - - - - - - - - - - - diff --git a/w32/download_pthreads.props b/w32/download_pthreads.props deleted file mode 100644 index 1c653e2962..0000000000 --- a/w32/download_pthreads.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/libshout-version.props b/w32/libshout-version.props new file mode 100644 index 0000000000..513de17976 --- /dev/null +++ b/w32/libshout-version.props @@ -0,0 +1,21 @@ + + + + + 2.4.6 + 1 + + + true + + + + + + $(libshoutVersion) + + + $(libshoutBuildNumber) + + + diff --git a/w32/libshout.props b/w32/libshout.props new file mode 100644 index 0000000000..393eb9ce04 --- /dev/null +++ b/w32/libshout.props @@ -0,0 +1,62 @@ + + + + + + + + + + + $(BaseDir)libs\libshout-$(libshoutVersion)_$(libshoutBuildNumber) + + + + + + + + + + + + + + $(libshoutLibDir)\include;%(AdditionalIncludeDirectories) + + + $(libshoutLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + libshout.lib;ws2_32.lib;%(AdditionalDependencies) + + + diff --git a/w32/mpg123-version.props b/w32/mpg123-version.props new file mode 100644 index 0000000000..93a39bbff2 --- /dev/null +++ b/w32/mpg123-version.props @@ -0,0 +1,21 @@ + + + + + 1.33.7 + 1 + + + true + + + + + + $(mpg123Version) + + + $(mpg123BuildNumber) + + + diff --git a/w32/mpg123.props b/w32/mpg123.props new file mode 100644 index 0000000000..91df286af6 --- /dev/null +++ b/w32/mpg123.props @@ -0,0 +1,68 @@ + + + + + + + + $(BaseDir)libs\mpg123-$(mpg123Version)_$(mpg123BuildNumber) + + + + + + + + + + + + + + + + + + + + $(mpg123LibDir)\include;%(AdditionalIncludeDirectories) + + + $(mpg123LibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + mpg123.lib;%(AdditionalDependencies) + + + diff --git a/w32/ogg-version.props b/w32/ogg-version.props new file mode 100644 index 0000000000..735bb68923 --- /dev/null +++ b/w32/ogg-version.props @@ -0,0 +1,21 @@ + + + + + 1.3.6 + 1 + + + true + + + + + + $(OggVersion) + + + $(OggBuildNumber) + + + diff --git a/w32/ogg.props b/w32/ogg.props new file mode 100644 index 0000000000..32dbc121fc --- /dev/null +++ b/w32/ogg.props @@ -0,0 +1,59 @@ + + + + + + + + $(BaseDir)libs\libogg-$(OggVersion)_$(OggBuildNumber) + + + + + + + + + + + + + + $(OggLibDir)\include;%(AdditionalIncludeDirectories) + + + $(OggLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + ogg.lib;%(AdditionalDependencies) + + + diff --git a/w32/pthreads-version.props b/w32/pthreads-version.props new file mode 100644 index 0000000000..953aff0e55 --- /dev/null +++ b/w32/pthreads-version.props @@ -0,0 +1,21 @@ + + + + + 2.9.1 + 1 + + + true + + + + + + $(PthreadsVersion) + + + $(PthreadsBuildNumber) + + + diff --git a/w32/pthreads.props b/w32/pthreads.props new file mode 100644 index 0000000000..0b3158f298 --- /dev/null +++ b/w32/pthreads.props @@ -0,0 +1,71 @@ + + + + + + + + $(BaseDir)libs\pthreads-$(PthreadsVersion)_$(PthreadsBuildNumber) + + + + + + + + + + + + + + + + + + + + $(PthreadsLibDir)\include;%(AdditionalIncludeDirectories) + + _TIMESPEC_DEFINED;%(PreprocessorDefinitions) + + + $(PthreadsLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + pthread.lib;%(AdditionalDependencies) + + + From 288705f7cddbc7b436a8c11c50b92091366050de Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 22 Sep 2026 13:28:52 +0300 Subject: [PATCH 18/88] [Build-System] Windows: Upgrade sqlite to v3.53.4_1 and use pre-compiled binaries (#3183) --- Freeswitch.2017.sln | 14 - libs/win32/sqlite/cleancount | 1 - libs/win32/sqlite/sqlite.2017.vcxproj | 334 ------------------------ w32/Library/FreeSwitchCore.2017.vcxproj | 21 +- w32/download_sqlite.props | 44 ---- w32/sqlite-version.props | 21 ++ w32/sqlite.props | 59 +++++ 7 files changed, 89 insertions(+), 405 deletions(-) delete mode 100644 libs/win32/sqlite/cleancount delete mode 100644 libs/win32/sqlite/sqlite.2017.vcxproj delete mode 100644 w32/download_sqlite.props create mode 100644 w32/sqlite-version.props create mode 100644 w32/sqlite.props diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index 2d27d5b591..833a468451 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -206,8 +206,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_event_socket", "src\mod EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsrtp", "libs\srtp\libsrtp.2017.vcxproj", "{EEF031CB-FED8-451E-A471-91EC8D4F6750}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsqlite", "libs\win32\sqlite\sqlite.2017.vcxproj", "{6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libapr", "libs\win32\apr\libapr.2017.vcxproj", "{F6C55D93-B927-4483-BB69-15AEF3DD2DFF}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_sofia", "src\mod\endpoints\mod_sofia\mod_sofia.2017.vcxproj", "{0DF3ABD0-DDC0-4265-B778-07C66780979B}" @@ -721,17 +719,6 @@ Global {EEF031CB-FED8-451E-A471-91EC8D4F6750}.Release|Win32.Build.0 = Release|Win32 {EEF031CB-FED8-451E-A471-91EC8D4F6750}.Release|x64.ActiveCfg = Release|x64 {EEF031CB-FED8-451E-A471-91EC8D4F6750}.Release|x64.Build.0 = Release|x64 - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}.All|Win32.ActiveCfg = Release DLL|x64 - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}.All|x64.ActiveCfg = Release DLL|x64 - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}.All|x64.Build.0 = Release DLL|x64 - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}.Debug|Win32.ActiveCfg = Debug|Win32 - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}.Debug|Win32.Build.0 = Debug|Win32 - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}.Debug|x64.ActiveCfg = Debug|x64 - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}.Debug|x64.Build.0 = Debug|x64 - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}.Release|Win32.ActiveCfg = Release|Win32 - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}.Release|Win32.Build.0 = Release|Win32 - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}.Release|x64.ActiveCfg = Release|x64 - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3}.Release|x64.Build.0 = Release|x64 {F6C55D93-B927-4483-BB69-15AEF3DD2DFF}.All|Win32.ActiveCfg = Release|x64 {F6C55D93-B927-4483-BB69-15AEF3DD2DFF}.All|x64.ActiveCfg = Release|x64 {F6C55D93-B927-4483-BB69-15AEF3DD2DFF}.All|x64.Build.0 = Release|x64 @@ -2214,7 +2201,6 @@ Global {B5881A85-FE70-4F64-8607-2CAAE52669C6} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {05515420-16DE-4E63-BE73-85BE85BA5142} = {9ADF1E48-2F5C-4ED7-A893-596259FABFE0} {EEF031CB-FED8-451E-A471-91EC8D4F6750} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {F6C55D93-B927-4483-BB69-15AEF3DD2DFF} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {0DF3ABD0-DDC0-4265-B778-07C66780979B} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C} {FEA1EEF7-876F-48DE-88BF-C0E3E606D758} = {F881ADA2-2F1A-4046-9FEB-191D9422D781} diff --git a/libs/win32/sqlite/cleancount b/libs/win32/sqlite/cleancount deleted file mode 100644 index 56a6051ca2..0000000000 --- a/libs/win32/sqlite/cleancount +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/libs/win32/sqlite/sqlite.2017.vcxproj b/libs/win32/sqlite/sqlite.2017.vcxproj deleted file mode 100644 index 22becd5fff..0000000000 --- a/libs/win32/sqlite/sqlite.2017.vcxproj +++ /dev/null @@ -1,334 +0,0 @@ - - - - - Debug DLL - Win32 - - - Debug DLL - x64 - - - Debug - Win32 - - - Debug - x64 - - - Release DLL - Win32 - - - Release DLL - x64 - - - Release - Win32 - - - Release - x64 - - - - libsqlite - {6EDFEFD5-3596-4FA9-8EBA-B331547B35A3} - libsqlite - Win32Proj - - - - - DynamicLibrary - MultiByte - $(DefaultPlatformToolset) - - - DynamicLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - DynamicLibrary - MultiByte - $(DefaultPlatformToolset) - - - DynamicLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(SolutionDir)$(Platform)\$(Configuration)\ - $(Platform)\sqlite\$(Configuration)\ - false - $(SolutionDir)$(Platform)\$(Configuration)\ - $(Platform)\sqlite\$(Configuration)\ - false - $(SolutionDir)$(Platform)\$(Configuration)\ - $(Platform)\sqlite\$(Configuration)\ - false - $(SolutionDir)$(Platform)\$(Configuration)\ - $(Platform)\sqlite\$(Configuration)\ - false - - - - - - Disabled - %(AdditionalIncludeDirectories) - _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_LIB;SQLITE_DEBUG;THREADSAFE=1;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - TurnOffAllWarnings - /FS %(AdditionalOptions) - - - - - - - - - - - X64 - - - Disabled - %(AdditionalIncludeDirectories) - _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_LIB;SQLITE_DEBUG;THREADSAFE=1;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - TurnOffAllWarnings - /FS %(AdditionalOptions) - - - - - - - - - - - %(AdditionalIncludeDirectories) - _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_LIB;THREADSAFE=1;%(PreprocessorDefinitions) - MultiThreadedDLL - TurnOffAllWarnings - /FS %(AdditionalOptions) - - - - - - - - - - - X64 - - - %(AdditionalIncludeDirectories) - _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_LIB;THREADSAFE=1;%(PreprocessorDefinitions) - MultiThreadedDLL - TurnOffAllWarnings - /FS %(AdditionalOptions) - - - - - - - - - - - Disabled - %(AdditionalIncludeDirectories) - _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_LIB;SQLITE_DEBUG;THREADSAFE=1;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - - - TurnOffAllWarnings - ProgramDatabase - /FS %(AdditionalOptions) - - - sqlite3.def - true - $(IntDir)$(ProjectName).pdb - Windows - false - - - $(IntDir)$(TargetName).lib - MachineX86 - - - - - - - - - - - X64 - - - Disabled - %(AdditionalIncludeDirectories) - _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;_DEBUG;_LIB;SQLITE_DEBUG;THREADSAFE=1;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - - - TurnOffAllWarnings - ProgramDatabase - /FS %(AdditionalOptions) - - - sqlite3.def - true - $(IntDir)$(ProjectName).pdb - Windows - false - - - $(IntDir)$(TargetName).lib - MachineX64 - - - - - - - - - - - %(AdditionalIncludeDirectories) - _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_LIB;THREADSAFE=1;%(PreprocessorDefinitions) - MultiThreadedDLL - - - TurnOffAllWarnings - ProgramDatabase - /FS %(AdditionalOptions) - - - sqlite3.def - false - - - $(IntDir)$(TargetName).lib - - - - - - - - - - - X64 - - - %(AdditionalIncludeDirectories) - _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;WIN32;NDEBUG;_LIB;THREADSAFE=1;%(PreprocessorDefinitions) - MultiThreadedDLL - - - TurnOffAllWarnings - ProgramDatabase - /FS %(AdditionalOptions) - - - sqlite3.def - false - - - $(IntDir)$(TargetName).lib - MachineX64 - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/w32/Library/FreeSwitchCore.2017.vcxproj b/w32/Library/FreeSwitchCore.2017.vcxproj index 0564441bcc..43e28e04e1 100644 --- a/w32/Library/FreeSwitchCore.2017.vcxproj +++ b/w32/Library/FreeSwitchCore.2017.vcxproj @@ -52,6 +52,7 @@ + @@ -129,7 +130,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" Disabled - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) true EnableFastChecks @@ -152,7 +153,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" rpcrt4.lib;%(AdditionalDependencies) - $(ProjectDir)..\..\libs\apr\$(OutDir);$(ProjectDir)..\..\libs\sqlite\$(OutDir) DLL;$(ProjectDir)..\..\libs\apr-util\$(OutDir);$(ProjectDir)..\..\libs\apr-iconv\$(OutDir);$(ProjectDir)..\..\libs\libresample\win;$(ProjectDir)..\..\libs\srtp\$(OutDir);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\libs\apr\$(OutDir);$(ProjectDir)..\..\libs\apr-util\$(OutDir);$(ProjectDir)..\..\libs\apr-iconv\$(OutDir);$(ProjectDir)..\..\libs\libresample\win;$(ProjectDir)..\..\libs\srtp\$(OutDir);%(AdditionalLibraryDirectories) %(AddModuleNamesToAssembly) true Windows @@ -179,7 +180,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" Disabled - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) true EnableFastChecks @@ -201,7 +202,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" rpcrt4.lib;%(AdditionalDependencies) - $(ProjectDir)..\..\libs\apr\$(OutDir);$(ProjectDir)..\..\libs\sqlite\$(OutDir) DLL;$(ProjectDir)..\..\libs\apr-util\$(OutDir);$(ProjectDir)..\..\libs\apr-iconv\$(OutDir);$(ProjectDir)..\..\libs\libresample\win;$(ProjectDir)..\..\libs\srtp\$(OutDir);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\libs\apr\$(OutDir);$(ProjectDir)..\..\libs\apr-util\$(OutDir);$(ProjectDir)..\..\libs\apr-iconv\$(OutDir);$(ProjectDir)..\..\libs\libresample\win;$(ProjectDir)..\..\libs\srtp\$(OutDir);%(AdditionalLibraryDirectories) %(AddModuleNamesToAssembly) true Windows @@ -220,7 +221,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" MaxSpeed - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) MultiThreadedDLL Create @@ -239,7 +240,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" rpcrt4.lib;%(AdditionalDependencies) - $(ProjectDir)..\..\libs\apr\$(OutDir);$(ProjectDir)..\..\libs\sqlite\$(OutDir) DLL;$(ProjectDir)..\..\libs\apr-util\$(OutDir);$(ProjectDir)..\..\libs\apr-iconv\$(OutDir);$(ProjectDir)..\..\libs\libresample\win;$(ProjectDir)..\..\libs\srtp\$(OutDir);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\libs\apr\$(OutDir);$(ProjectDir)..\..\libs\apr-util\$(OutDir);$(ProjectDir)..\..\libs\apr-iconv\$(OutDir);$(ProjectDir)..\..\libs\libresample\win;$(ProjectDir)..\..\libs\srtp\$(OutDir);%(AdditionalLibraryDirectories) false Windows true @@ -258,7 +259,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" MaxSpeed - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\sqlite;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) MultiThreadedDLL Create @@ -277,7 +278,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" rpcrt4.lib;%(AdditionalDependencies) - $(ProjectDir)..\..\libs\apr\$(OutDir);$(ProjectDir)..\..\libs\sqlite\$(OutDir) DLL;$(ProjectDir)..\..\libs\apr-util\$(OutDir);$(ProjectDir)..\..\libs\apr-iconv\$(OutDir);$(ProjectDir)..\..\libs\libresample\win;$(ProjectDir)..\..\libs\srtp\$(OutDir);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\libs\apr\$(OutDir);$(ProjectDir)..\..\libs\apr-util\$(OutDir);$(ProjectDir)..\..\libs\apr-iconv\$(OutDir);$(ProjectDir)..\..\libs\libresample\win;$(ProjectDir)..\..\libs\srtp\$(OutDir);%(AdditionalLibraryDirectories) false Windows true @@ -806,10 +807,6 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" true false - - {6edfefd5-3596-4fa9-8eba-b331547b35a3} - false - diff --git a/w32/download_sqlite.props b/w32/download_sqlite.props deleted file mode 100644 index 19f7fb7ac7..0000000000 --- a/w32/download_sqlite.props +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - true - 3.53.3 - - $([System.String]::Format('{0}{1:00}{2:00}00', $([System.Version]::Parse('$(sqliteVersion)').Major), $([System.Version]::Parse('$(sqliteVersion)').Minor), $([System.Version]::Parse('$(sqliteVersion)').Build))) - - - - - - - - - diff --git a/w32/sqlite-version.props b/w32/sqlite-version.props new file mode 100644 index 0000000000..1b1c583062 --- /dev/null +++ b/w32/sqlite-version.props @@ -0,0 +1,21 @@ + + + + + 3.53.4 + 1 + + + true + + + + + + $(sqliteVersion) + + + $(sqliteBuildNumber) + + + diff --git a/w32/sqlite.props b/w32/sqlite.props new file mode 100644 index 0000000000..5eb5fbb192 --- /dev/null +++ b/w32/sqlite.props @@ -0,0 +1,59 @@ + + + + + + + + $(BaseDir)libs\sqlite-$(sqliteVersion)_$(sqliteBuildNumber) + + + + + + + + + + + + + + $(sqliteLibDir)\include;%(AdditionalIncludeDirectories) + + + $(sqliteLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + sqlite3.lib;%(AdditionalDependencies) + + + From fd1cab5117cd4c711293439354885a559ef783bb Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 24 Sep 2026 00:31:38 +0300 Subject: [PATCH 19/88] [Build-System] Fix build against OpenSSL 4 (#3185) --- configure.ac | 6 +++++- src/switch_core_cert.c | 13 ++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index ae42b22f6f..16af18ce2d 100644 --- a/configure.ac +++ b/configure.ac @@ -1726,7 +1726,11 @@ if test x$HAVE_OPENSSL = x1; then openssl_CFLAGS="$openssl_CFLAGS -DHAVE_OPENSSL"; APR_ADDTO(SWITCH_AM_CFLAGS, -DHAVE_OPENSSL) AC_CHECK_LIB(ssl, SSL_CTX_set_tlsext_use_srtp, AC_DEFINE_UNQUOTED(HAVE_OPENSSL_DTLS_SRTP, 1, HAVE_OPENSSL_DTLS_SRTP), AC_MSG_ERROR([OpenSSL >= 1.0.1e and associated developement headers required])) - AC_CHECK_LIB(ssl, DTLSv1_method, AC_DEFINE_UNQUOTED(HAVE_OPENSSL_DTLS, 1, HAVE_OPENSSL_DTLS), AC_MSG_ERROR([OpenSSL >= 1.0.1e and associaed developement headers required])) + dnl DTLS_method is what the code calls from OpenSSL 1.1.0 on; DTLSv1_method is + dnl the pre 1.1.0 spelling, deprecated since and gone from OpenSSL 4. + AC_CHECK_LIB(ssl, DTLS_method, AC_DEFINE_UNQUOTED(HAVE_OPENSSL_DTLS, 1, HAVE_OPENSSL_DTLS), + [AC_CHECK_LIB(ssl, DTLSv1_method, AC_DEFINE_UNQUOTED(HAVE_OPENSSL_DTLS, 1, HAVE_OPENSSL_DTLS), + AC_MSG_ERROR([OpenSSL >= 1.0.1e and associated development headers required]))]) AC_CHECK_LIB(ssl, DTLSv1_2_method, AC_DEFINE_UNQUOTED(HAVE_OPENSSL_DTLSv1_2_method, 1, [DTLS version 1.2 is available])) else AC_MSG_ERROR([OpenSSL >= 1.0.1e and associated developement headers required]) diff --git a/src/switch_core_cert.c b/src/switch_core_cert.c index 218016e63b..174a2b1809 100644 --- a/src/switch_core_cert.c +++ b/src/switch_core_cert.c @@ -496,7 +496,12 @@ static int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days X509_gmtime_adj(X509_get_notAfter(x), (long)60*60*24*days); X509_set_pubkey(x, pk); - name = X509_get_subject_name(x); + /* OpenSSL 4 hands out the certificate's own name as const, so build one + * here and set it instead of filling in the one inside the certificate. + */ + if ((name = X509_NAME_new()) == NULL) { + goto err; + } /* This function creates and adds the entry, working out the * correct string type and performing checks on its length. @@ -505,11 +510,13 @@ static int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, (unsigned char *)"US", -1, -1, 0); X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (unsigned char *)"FreeSWITCH", -1, -1, 0); - /* Its self signed so set the issuer name to be the same as the - * subject. + * subject. Both calls copy the name, so ours is ours to free. */ + X509_set_subject_name(x, name); X509_set_issuer_name(x, name); + X509_NAME_free(name); + name = NULL; #if OPENSSL_VERSION_NUMBER >= 0x30000000 if (!X509_sign(x, pk, EVP_sha256())) { From 3097732e75e6e5548d107d1803ee2b38aa6f0bea Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 24 Sep 2026 17:42:39 +0300 Subject: [PATCH 20/88] [Build-System] Windows: Upgrade ldns to v1.9.2_1 and use pre-compiled binaries, remove unused libcelt (#3184) --- .gitignore | 2 + Freeswitch.2017.sln | 28 -- libs/.gitignore | 2 - libs/win32/celt/config.h | 34 -- libs/win32/celt/float_cast.h | 114 ----- libs/win32/celt/libcelt.2017.vcxproj | 157 ------ libs/win32/ldns/ldns-lib/config.h | 452 ------------------ .../win32/ldns/ldns-lib/ldns-lib.2017.vcxproj | 267 ----------- libs/win32/ldns/ldns-lib/net.h | 195 -------- libs/win32/ldns/ldns-lib/util.h | 326 ------------- .../mod_enum/mod_enum.2017.vcxproj | 8 +- src/mod/applications/mod_enum/mod_enum.c | 3 - w32/download_LDNS.props | 40 -- w32/download_celt.props | 40 -- w32/ldns-version.props | 21 + w32/ldns.props | 59 +++ 16 files changed, 83 insertions(+), 1665 deletions(-) delete mode 100644 libs/win32/celt/config.h delete mode 100644 libs/win32/celt/float_cast.h delete mode 100644 libs/win32/celt/libcelt.2017.vcxproj delete mode 100644 libs/win32/ldns/ldns-lib/config.h delete mode 100644 libs/win32/ldns/ldns-lib/ldns-lib.2017.vcxproj delete mode 100644 libs/win32/ldns/ldns-lib/net.h delete mode 100644 libs/win32/ldns/ldns-lib/util.h delete mode 100644 w32/download_LDNS.props delete mode 100644 w32/download_celt.props create mode 100644 w32/ldns-version.props create mode 100644 w32/ldns.props diff --git a/.gitignore b/.gitignore index a086940a54..1941e58ade 100644 --- a/.gitignore +++ b/.gitignore @@ -293,6 +293,8 @@ libs/pthreads-*/ libs/pthreads-*.zip libs/mpg123-*/ libs/mpg123-*.zip +libs/ldns-*/ +libs/ldns-*.zip libs/SharpZipLib.*/ libs/SharpZipLib.*.nupkg libs/nasm-*/ diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index 833a468451..433c5978ba 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -331,8 +331,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_valet_parking", "src\mo EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_bv", "src\mod\codecs\mod_bv\mod_bv.2017.vcxproj", "{D5C87B19-150D-4EF3-A671-96589BD2D14A}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcelt", "libs\win32\celt\libcelt.2017.vcxproj", "{ABB71A76-42B0-47A4-973A-42E3D920C6FD}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FSComm", "fscomm\FSComm.2017.vcxproj", "{7D3122C7-C9D0-3748-81F8-F0DDCB40BF5E}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_curl", "src\mod\applications\mod_curl\mod_curl.2017.vcxproj", "{EF300386-A8DF-4372-B6D8-FB9BFFCA9AED}" @@ -357,8 +355,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_say_pt", "src\mod\say\m EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_say_sv", "src\mod\say\mod_say_sv\mod_say_sv.2017.vcxproj", "{8CDA2B34-FA44-49CC-9EC2-B8F35856CD15}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ldns", "libs\win32\ldns\ldns-lib\ldns-lib.2017.vcxproj", "{23B4D303-79FC-49E0-89E2-2280E7E28940}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_callcenter", "src\mod\applications\mod_callcenter\mod_callcenter.2017.vcxproj", "{47886A6C-CCA6-4F9F-A7D4-F97D06FB2B1A}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_blacklist", "src\mod\applications\mod_blacklist\mod_blacklist.2017.vcxproj", "{50AAC2CE-BFC9-4912-87CC-C6381850D735}" @@ -1367,17 +1363,6 @@ Global {D5C87B19-150D-4EF3-A671-96589BD2D14A}.Release|Win32.Build.0 = Release|Win32 {D5C87B19-150D-4EF3-A671-96589BD2D14A}.Release|x64.ActiveCfg = Release|x64 {D5C87B19-150D-4EF3-A671-96589BD2D14A}.Release|x64.Build.0 = Release|x64 - {ABB71A76-42B0-47A4-973A-42E3D920C6FD}.All|Win32.ActiveCfg = Release|x64 - {ABB71A76-42B0-47A4-973A-42E3D920C6FD}.All|x64.ActiveCfg = Release|x64 - {ABB71A76-42B0-47A4-973A-42E3D920C6FD}.All|x64.Build.0 = Release|x64 - {ABB71A76-42B0-47A4-973A-42E3D920C6FD}.Debug|Win32.ActiveCfg = Debug|Win32 - {ABB71A76-42B0-47A4-973A-42E3D920C6FD}.Debug|Win32.Build.0 = Debug|Win32 - {ABB71A76-42B0-47A4-973A-42E3D920C6FD}.Debug|x64.ActiveCfg = Debug|x64 - {ABB71A76-42B0-47A4-973A-42E3D920C6FD}.Debug|x64.Build.0 = Debug|x64 - {ABB71A76-42B0-47A4-973A-42E3D920C6FD}.Release|Win32.ActiveCfg = Release|Win32 - {ABB71A76-42B0-47A4-973A-42E3D920C6FD}.Release|Win32.Build.0 = Release|Win32 - {ABB71A76-42B0-47A4-973A-42E3D920C6FD}.Release|x64.ActiveCfg = Release|x64 - {ABB71A76-42B0-47A4-973A-42E3D920C6FD}.Release|x64.Build.0 = Release|x64 {7D3122C7-C9D0-3748-81F8-F0DDCB40BF5E}.All|Win32.ActiveCfg = Release|Win32 {7D3122C7-C9D0-3748-81F8-F0DDCB40BF5E}.All|Win32.Build.0 = Release|Win32 {7D3122C7-C9D0-3748-81F8-F0DDCB40BF5E}.All|x64.ActiveCfg = Release|Win32 @@ -1503,17 +1488,6 @@ Global {8CDA2B34-FA44-49CC-9EC2-B8F35856CD15}.Release|Win32.Build.0 = Release|Win32 {8CDA2B34-FA44-49CC-9EC2-B8F35856CD15}.Release|x64.ActiveCfg = Release|x64 {8CDA2B34-FA44-49CC-9EC2-B8F35856CD15}.Release|x64.Build.0 = Release|x64 - {23B4D303-79FC-49E0-89E2-2280E7E28940}.All|Win32.ActiveCfg = Release|x64 - {23B4D303-79FC-49E0-89E2-2280E7E28940}.All|x64.ActiveCfg = Release|x64 - {23B4D303-79FC-49E0-89E2-2280E7E28940}.All|x64.Build.0 = Release|x64 - {23B4D303-79FC-49E0-89E2-2280E7E28940}.Debug|Win32.ActiveCfg = Debug|Win32 - {23B4D303-79FC-49E0-89E2-2280E7E28940}.Debug|Win32.Build.0 = Debug|Win32 - {23B4D303-79FC-49E0-89E2-2280E7E28940}.Debug|x64.ActiveCfg = Debug|x64 - {23B4D303-79FC-49E0-89E2-2280E7E28940}.Debug|x64.Build.0 = Debug|x64 - {23B4D303-79FC-49E0-89E2-2280E7E28940}.Release|Win32.ActiveCfg = Release|Win32 - {23B4D303-79FC-49E0-89E2-2280E7E28940}.Release|Win32.Build.0 = Release|Win32 - {23B4D303-79FC-49E0-89E2-2280E7E28940}.Release|x64.ActiveCfg = Release|x64 - {23B4D303-79FC-49E0-89E2-2280E7E28940}.Release|x64.Build.0 = Release|x64 {47886A6C-CCA6-4F9F-A7D4-F97D06FB2B1A}.All|Win32.ActiveCfg = Release|x64 {47886A6C-CCA6-4F9F-A7D4-F97D06FB2B1A}.All|x64.ActiveCfg = Release|x64 {47886A6C-CCA6-4F9F-A7D4-F97D06FB2B1A}.All|x64.Build.0 = Release|x64 @@ -2261,7 +2235,6 @@ Global {0382E8FD-CFDC-41C0-8B03-792C7C84FC31} = {6CD61A1D-797C-470A-BE08-8C31B68BB336} {432DB165-1EB2-4781-A9C0-71E62610B20A} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {D5C87B19-150D-4EF3-A671-96589BD2D14A} = {F881ADA2-2F1A-4046-9FEB-191D9422D781} - {ABB71A76-42B0-47A4-973A-42E3D920C6FD} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {EF300386-A8DF-4372-B6D8-FB9BFFCA9AED} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {AFA983D6-4569-4F88-BA94-555ED00FD9A8} = {F881ADA2-2F1A-4046-9FEB-191D9422D781} {990BAA76-89D3-4E38-8479-C7B28784EFC8} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} @@ -2273,7 +2246,6 @@ Global {5C2B4D88-3BEA-4FE0-90DF-FA9836099D5F} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {7C22BDFF-CC09-400C-8A09-660733980028} = {6CD61A1D-797C-470A-BE08-8C31B68BB336} {8CDA2B34-FA44-49CC-9EC2-B8F35856CD15} = {6CD61A1D-797C-470A-BE08-8C31B68BB336} - {23B4D303-79FC-49E0-89E2-2280E7E28940} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {47886A6C-CCA6-4F9F-A7D4-F97D06FB2B1A} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {50AAC2CE-BFC9-4912-87CC-C6381850D735} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {A61D7CB4-75A5-4A55-8CA1-BE5AF615D921} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} diff --git a/libs/.gitignore b/libs/.gitignore index 06b712abd4..c34ce55599 100644 --- a/libs/.gitignore +++ b/libs/.gitignore @@ -52,7 +52,6 @@ opal /broadvoice/src/Makefile.in /broadvoice/src/stamp-h1 /broadvoice/tests/regression_tests.sh -/celt-*/ /Communicator_semi_40.cd_semi_6000/ /esl/Debug/ /esl/Release/ @@ -479,7 +478,6 @@ opal /tiff-*/tools/tiffmedian /tiff-*/tools/tiffset /tiff-*/tools/tiffsplit -/win32/celt/*/*/libcelt.log /win32/libg722_1/*/*/libg722_1.log /win32/libshout/*/*/libshout.log /win32/tmp*.bat diff --git a/libs/win32/celt/config.h b/libs/win32/celt/config.h deleted file mode 100644 index 2eeb58d4a5..0000000000 --- a/libs/win32/celt/config.h +++ /dev/null @@ -1,34 +0,0 @@ -/* This is a build of CELT */ -#define CELT_BUILD - -/* Version extra */ -#define CELT_EXTRA_VERSION "-1" - -/* Version major */ -#define CELT_MAJOR_VERSION 0 - -/* Version micro */ -#define CELT_MICRO_VERSION 0 - -/* Version minor */ -#define CELT_MINOR_VERSION 7 - -/* Complete version string */ -#define CELT_VERSION "0.7.0-1" - -/* Compile as fixed-point */ -/* #undef FIXED_POINT */ - -/* Compile as floating-point */ -#define FLOATING_POINT - -/* Make use of alloca */ -/* #undef USE_ALLOCA */ -#define USE_ALLOCA 1 /* disable this when using SSE */ - -/* Define to equivalent of C99 restrict keyword, or to nothing if this is not - supported. Do not define if restrict is supported directly. */ -#define restrict /* __restrict */ - -// Microsoft version of 'inline' -#define inline __inline diff --git a/libs/win32/celt/float_cast.h b/libs/win32/celt/float_cast.h deleted file mode 100644 index 9caa39b4b3..0000000000 --- a/libs/win32/celt/float_cast.h +++ /dev/null @@ -1,114 +0,0 @@ -/* -** Copyright (C) 2001 Erik de Castro Lopo -** -** Permission to use, copy, modify, distribute, and sell this file for any -** purpose is hereby granted without fee, provided that the above copyright -** and this permission notice appear in all copies. No representations are -** made about the suitability of this software for any purpose. It is -** provided "as is" without express or implied warranty. -*/ - -/* Version 1.1 */ - -#ifndef FLOAT_CAST_H -#define FLOAT_CAST_H - -/*============================================================================ -** On Intel Pentium processors (especially PIII and probably P4), converting -** from float to int is very slow. To meet the C specs, the code produced by -** most C compilers targeting Pentium needs to change the FPU rounding mode -** before the float to int conversion is performed. -** -** Changing the FPU rounding mode causes the FPU pipeline to be flushed. It -** is this flushing of the pipeline which is so slow. -** -** Fortunately the ISO C99 specifications define the functions lrint, lrintf, -** llrint and llrintf which fix this problem as a side effect. -** -** On Unix-like systems, the configure process should have detected the -** presence of these functions. If they weren't found we have to replace them -** here with a standard C cast. -*/ - -/* -** The C99 prototypes for lrint and lrintf are as follows: -** -** long int lrintf (float x) ; -** long int lrint (double x) ; -*/ - -/* The presence of the required functions are detected during the configure -** process and the values HAVE_LRINT and HAVE_LRINTF are set accordingly in -** the config.h file. -*/ - -#if (HAVE_LRINTF) -/*#if 0*/ - - /* These defines enable functionality introduced with the 1999 ISO C - ** standard. They must be defined before the inclusion of math.h to - ** engage them. If optimisation is enabled, these functions will be - ** inlined. With optimisation switched off, you have to link in the - ** maths library using -lm. - */ - - #define _ISOC9X_SOURCE 1 - #define _ISOC99_SOURCE 1 - - #define __USE_ISOC9X 1 - #define __USE_ISOC99 1 - - #include - #define float2int(x) lrintf(x) - -#elif (defined(HAVE_LRINT)) - -#define _ISOC9X_SOURCE 1 -#define _ISOC99_SOURCE 1 - -#define __USE_ISOC9X 1 -#define __USE_ISOC99 1 - -#include -#define float2int(x) lrint(x) - -#elif (defined (WIN32) || defined (_WIN32)) - - #include - - /* Win32 doesn't seem to have these functions. - ** Therefore implement inline versions of these functions here. - */ - -#ifndef _WIN64 - __inline long int - float2int (float flt) - { int intgr; - - _asm - { fld flt - fistp intgr - } ; - - return intgr ; - } -#else -#define float2int -#endif - - -#else - -#ifdef __GNUC__ /* supported by gcc, but not by all other compilers*/ - #warning "Don't have the functions lrint() and lrintf ()." - #warning "Replacing these functions with a standard C cast." -#endif /* __GNUC__ */ - - #include - - #define float2int(flt) ((int)(floor(.5+flt))) - -#endif - - -#endif /* FLOAT_CAST_H */ diff --git a/libs/win32/celt/libcelt.2017.vcxproj b/libs/win32/celt/libcelt.2017.vcxproj deleted file mode 100644 index 03c1461d4e..0000000000 --- a/libs/win32/celt/libcelt.2017.vcxproj +++ /dev/null @@ -1,157 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {ABB71A76-42B0-47A4-973A-42E3D920C6FD} - celt - Win32Proj - libcelt - - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - true - $(DefaultPlatformToolset) - - - StaticLibrary - Unicode - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - - - - .\;%(AdditionalIncludeDirectories) - - - - - Disabled - ..\..\celt-0.10.0\libcelt;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - Level3 - 4305;4267;4101;4554;4018;4244;%(DisableSpecificWarnings) - - - - - X64 - - - Disabled - ..\..\celt-0.10.0\libcelt;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;_AMD64_;_WIN64;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - Level3 - 4305;4267;4101;4554;4018;4244;%(DisableSpecificWarnings) - - - - - MaxSpeed - true - ..\..\celt-0.10.0\libcelt;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - MultiThreadedDLL - true - Level3 - 4305;4267;4101;4554;4018;4244;%(DisableSpecificWarnings) - - - - - X64 - - - MaxSpeed - true - ..\..\celt-0.10.0\libcelt;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;_AMD64_;_WIN64;%(PreprocessorDefinitions) - MultiThreadedDLL - true - Level3 - 4305;4267;4101;4554;4018;4244;%(DisableSpecificWarnings) - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/libs/win32/ldns/ldns-lib/config.h b/libs/win32/ldns/ldns-lib/config.h deleted file mode 100644 index fb29bc2c7c..0000000000 --- a/libs/win32/ldns/ldns-lib/config.h +++ /dev/null @@ -1,452 +0,0 @@ -/* ldns/config.h.in. Generated from configure.ac by autoheader. */ - -/* Define if building universal (internal helper macro) */ -#undef AC_APPLE_UNIVERSAL_BUILD - -/* Define to 1 if you have the header file. */ -#undef HAVE_ARPA_INET_H - -/* Whether the C compiler accepts the "format" attribute */ -#undef HAVE_ATTR_FORMAT - -/* Whether the C compiler accepts the "unused" attribute */ -#undef HAVE_ATTR_UNUSED - -/* Define to 1 if you have the `b32_ntop' function. */ -#undef HAVE_B32_NTOP - -/* Define to 1 if you have the `b32_pton' function. */ -#undef HAVE_B32_PTON - -/* Define to 1 if you have the `b64_ntop' function. */ -#undef HAVE_B64_NTOP - -/* Define to 1 if you have the `b64_pton' function. */ -#undef HAVE_B64_PTON - -/* Define to 1 if you have the `ctime_r' function. */ -#undef HAVE_CTIME_R - -/* Define to 1 if you have the header file. */ -#undef HAVE_DLFCN_H - -/* Define to 1 if you have the `endprotoent' function. */ -#undef HAVE_ENDPROTOENT - -/* Define to 1 if you have the `endservent' function. */ -#undef HAVE_ENDSERVENT - -/* Define to 1 if you have the `EVP_sha256' function. */ -#undef HAVE_EVP_SHA256 - -/* Whether getaddrinfo is available */ -#undef HAVE_GETADDRINFO - -/* Define to 1 if you have the header file. */ -#undef HAVE_GETOPT_H - -/* Define to 1 if you have the `gmtime_r' function. */ -#undef HAVE_GMTIME_R - -/* If you have HMAC_CTX_init */ -#undef HAVE_HMAC_CTX_INIT - -/* Define to 1 if you have the `inet_aton' function. */ -#undef HAVE_INET_ATON - -/* Define to 1 if you have the `inet_ntop' function. */ -#undef HAVE_INET_NTOP - -/* Define to 1 if you have the `inet_pton' function. */ -#undef HAVE_INET_PTON - -/* define if you have inttypes.h */ -#undef HAVE_INTTYPES_H - -/* Define to 1 if you have the `isblank' function. */ -#undef HAVE_ISBLANK - -/* Define to 1 if you have the `crypto' library (-lcrypto). */ -#undef HAVE_LIBCRYPTO - -/* Define to 1 if you have the `nsl' library (-lnsl). */ -#undef HAVE_LIBNSL - -/* Define to 1 if you have the `socket' library (-lsocket). */ -#undef HAVE_LIBSOCKET - -/* Define to 1 if your system has a GNU libc compatible `malloc' function, and - to 0 otherwise. */ -#define HAVE_MALLOC 1 - -/* Define to 1 if you have the `memmove' function. */ -#define HAVE_MEMMOVE 1 - -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_NETDB_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_NETINET_IN_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_OPENSSL_ERR_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_OPENSSL_RAND_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_OPENSSL_SSL_H - -/* Define to 1 if you have the `random' function. */ -#define HAVE_RANDOM 1 - -/* Define to 1 if your system has a GNU libc compatible `realloc' function, - and to 0 otherwise. */ -#define HAVE_REALLOC 1 - -/* Define to 1 if you have the `sleep' function. */ -#undef HAVE_SLEEP - -/* Define to 1 if you have the `snprintf' function. */ -#define HAVE_SNPRINTF 1 - -/* Define if you have the SSL libraries installed. */ -#undef HAVE_SSL - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDARG_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDBOOL_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRING_H - -/* Define to 1 if you have the `strlcpy' function. */ -#undef HAVE_STRLCPY - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_MOUNT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_PARAM_H - -/* define if you have sys/socket.h */ -#undef HAVE_SYS_SOCKET_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have the `timegm' function. */ -#undef HAVE_TIMEGM - -/* Define to 1 if you have the header file. */ -#undef HAVE_TIME_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Define to 1 if you have the header file. */ -#define HAVE_WINSOCK2_H 1 - -/* Define to 1 if you have the header file. */ -#undef HAVE_WS2TCPIP_H - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#undef LT_OBJDIR - -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT - -/* Define to the full name of this package. */ -#undef PACKAGE_NAME - -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING - -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME - -/* Define to the version of this package. */ -#undef PACKAGE_VERSION - -/* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* System configuration dir */ -#undef SYSCONFDIR - -/* Define this to enable GOST support. */ -#undef USE_GOST - -/* Define this to enable SHA256 and SHA512 support. */ -#undef USE_SHA2 - -/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# undef _ALL_SOURCE -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# undef _GNU_SOURCE -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# undef _POSIX_PTHREAD_SEMANTICS -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# undef _TANDEM_SOURCE -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# undef __EXTENSIONS__ -#endif - - -/* Whether the windows socket API is used */ -#define USE_WINSOCK - -/* the version of the windows API enabled */ -//#undef WINVER - -/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most - significant byte first (like Motorola and SPARC, unlike Intel). */ -#if defined AC_APPLE_UNIVERSAL_BUILD -# if defined __BIG_ENDIAN__ -# define WORDS_BIGENDIAN 1 -# endif -#else -# ifndef WORDS_BIGENDIAN -# undef WORDS_BIGENDIAN -# endif -#endif - -/* Define to 1 if on MINIX. */ -#undef _MINIX - -/* Define to 2 if the system does not provide POSIX.1 features except with - this defined. */ -#undef _POSIX_1_SOURCE - -/* Define to 1 if you need to in order for `stat' and other things to work. */ -#undef _POSIX_SOURCE - -/* Define to empty if `const' does not conform to ANSI C. */ -#undef const - -/* in_addr_t */ -#undef in_addr_t - -/* in_port_t */ -#undef in_port_t - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -#ifndef _WIN32 -#define inline /* Do not define inline for Windows to avoid warnings/errors with winsock2.h usage of inline within the latest Windows SDKs */ -#endif -#endif - -#if _MSC_VER >= 1900 -#include -#else -/* Define to `short' if does not define. */ -#undef int16_t - -/* Define to `int' if does not define. */ -#undef int32_t - -/* Define to `long long' if does not define. */ -#undef int64_t - -/* Define to `char' if does not define. */ -#undef int8_t - -/* Define to rpl_malloc if the replacement function should be used. */ -#undef malloc - -/* Define to rpl_realloc if the replacement function should be used. */ -#undef realloc - -/* Define to 'int' if not defined */ -#undef socklen_t - -/* Define to `unsigned short' if does not define. */ -#define uint16_t unsigned short - -#define int16_t short - -/* Define to `unsigned int' if does not define. */ -#define uint32_t unsigned int - -/* Define to `unsigned long long' if does not define. */ -#define uint64_t unsigned long long - -/* Define to `unsigned char' if does not define. */ -#define uint8_t unsigned char - -#define int8_t char - -#endif -/* Define to `int' if does not define. */ -#define ssize_t int - - -#include -#include -//#include -#include - -#ifndef LITTLE_ENDIAN -#define LITTLE_ENDIAN 1234 -#endif - -#ifndef BIG_ENDIAN -#define BIG_ENDIAN 4321 -#endif - -#ifndef BYTE_ORDER -#ifdef WORDS_BIGENDIAN -#define BYTE_ORDER BIG_ENDIAN -#else -#define BYTE_ORDER LITTLE_ENDIAN -#endif /* WORDS_BIGENDIAN */ -#endif /* BYTE_ORDER */ - -#if STDC_HEADERS -#include -#include -#endif - -#ifdef HAVE_STDINT_H -#include -#endif - -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - -#ifdef HAVE_NETINET_IN_H -#include -#endif - -#ifdef HAVE_ARPA_INET_H -#include -#endif - -#ifdef HAVE_WINSOCK2_H -#include -#endif - -#ifdef HAVE_WS2TCPIP_H -#include -#endif - -#ifdef _MSC_VER -#if _MSC_VER < 1900 -#define snprintf _snprintf -#else -#ifndef HAVE_ISBLANK -#define HAVE_ISBLANK -#endif -#endif -#define vsnprintf _vsnprintf -#define strcasecmp _stricmp -#define strncasecmp _strnicmp -#define strdup _strdup -/* -#define gmtime gmtime_s -#define ctime ctime_s -#define strcpy strcpu_s -*/ -#define putenv _putenv -#define srandom srand -#define random rand -#endif - -#ifndef B64_PTON -int ldns_b64_ntop(uint8_t const *src, size_t srclength, - char *target, size_t targsize); -/** - * calculates the size needed to store the result of b64_ntop - */ -/*@unused@*/ -inline static size_t ldns_b64_ntop_calculate_size(size_t srcsize) -{ - return ((((srcsize + 2) / 3) * 4) + 1); -} -#endif /* !B64_PTON */ -#ifndef B64_NTOP -int ldns_b64_pton(char const *src, uint8_t *target, size_t targsize); -/** - * calculates the size needed to store the result of ldns_b64_pton - */ -/*@unused@*/ -inline static size_t ldns_b64_pton_calculate_size(size_t srcsize) -{ - return ((((srcsize / 4) * 3) - 2) + 2); -} -#endif /* !B64_NTOP */ - -#ifndef HAVE_SLEEP -/* use windows sleep, in millisecs, instead */ -#define sleep(x) Sleep((x)*1000) -#endif - -#ifndef HAVE_RANDOM -#define srandom(x) srand(x) -#define random(x) rand(x) -#endif - -#ifndef HAVE_TIMEGM -#include -time_t timegm (struct tm *tm); -#endif /* !TIMEGM */ -#ifndef HAVE_GMTIME_R -struct tm *gmtime_r(const time_t *timep, struct tm *result); -#endif -#ifndef HAVE_ISBLANK -int isblank(int c); -#endif /* !HAVE_ISBLANK */ -#ifndef HAVE_SNPRINTF -#include -int snprintf (char *str, size_t count, const char *fmt, ...); -int vsnprintf (char *str, size_t count, const char *fmt, va_list arg); -#endif /* HAVE_SNPRINTF */ -#ifndef HAVE_INET_PTON -int inet_pton(int af, const char* src, void* dst); -#endif /* HAVE_INET_PTON */ -#ifndef HAVE_INET_NTOP -const char *inet_ntop(int af, const void *src, char *dst, size_t size); -#endif -#ifndef HAVE_INET_ATON -int inet_aton(const char *cp, struct in_addr *addr); -#endif -#ifndef HAVE_MEMMOVE -void *memmove(void *dest, const void *src, size_t n); -#endif -#ifndef HAVE_STRLCPY -size_t strlcpy(char *dst, const char *src, size_t siz); -#endif -#ifndef HAVE_GETADDRINFO -#include "compat/fake-rfc2553.h" -#endif - diff --git a/libs/win32/ldns/ldns-lib/ldns-lib.2017.vcxproj b/libs/win32/ldns/ldns-lib/ldns-lib.2017.vcxproj deleted file mode 100644 index f9d7b0e98e..0000000000 --- a/libs/win32/ldns/ldns-lib/ldns-lib.2017.vcxproj +++ /dev/null @@ -1,267 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - ldns - {23B4D303-79FC-49E0-89E2-2280E7E28940} - ldns - - - - StaticLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.40219.1 - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - - - - Disabled - ..\..\..\ldns\;.;%(AdditionalIncludeDirectories) - HAVE_ISBLANK;HAVE_STRUCT_ADDRINFO;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - Level3 - ProgramDatabase - 4013;4101;4996;4267;4244;%(DisableSpecificWarnings) - - - if not exist "$(ProjectDir)..\..\..\ldns\ldns\config.h" type "$(ProjectDir)\config.h" > "$(ProjectDir)..\..\..\ldns\ldns\config.h" -if not exist "$(ProjectDir)..\..\..\ldns\ldns\util.h" type "$(ProjectDir)\util.h" > "$(ProjectDir)..\..\..\ldns\ldns\util.h" -if not exist "$(ProjectDir)..\..\..\ldns\ldns\net.h" type "$(ProjectDir)\net.h" > "$(ProjectDir)..\..\..\ldns\ldns\net.h" - - - /ignore:4221 %(AdditionalOptions) - - - - - Disabled - ..\..\..\ldns\;.;%(AdditionalIncludeDirectories) - HAVE_ISBLANK;HAVE_STRUCT_ADDRINFO;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebugDLL - Level3 - ProgramDatabase - 4013;4101;4996;4267;4244;%(DisableSpecificWarnings) - - - if not exist "$(ProjectDir)..\..\..\ldns\ldns\config.h" type "$(ProjectDir)\config.h" > "$(ProjectDir)..\..\..\ldns\ldns\config.h" -if not exist "$(ProjectDir)..\..\..\ldns\ldns\util.h" type "$(ProjectDir)\util.h" > "$(ProjectDir)..\..\..\ldns\ldns\util.h" -if not exist "$(ProjectDir)..\..\..\ldns\ldns\net.h" type "$(ProjectDir)\net.h" > "$(ProjectDir)..\..\..\ldns\ldns\net.h" - - - /ignore:4221 %(AdditionalOptions) - - - - - MaxSpeed - true - MultiThreadedDLL - true - Level3 - ProgramDatabase - HAVE_ISBLANK;HAVE_STRUCT_ADDRINFO;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;_MBCS;%(PreprocessorDefinitions) - ..\..\..\ldns\;.;%(AdditionalIncludeDirectories) - 4013;4101;4996;4267;4244;%(DisableSpecificWarnings) - - - true - true - true - MachineX86 - - - if not exist "$(ProjectDir)..\..\..\ldns\ldns\config.h" type "$(ProjectDir)\config.h" > "$(ProjectDir)..\..\..\ldns\ldns\config.h" -if not exist "$(ProjectDir)..\..\..\ldns\ldns\util.h" type "$(ProjectDir)\util.h" > "$(ProjectDir)..\..\..\ldns\ldns\util.h" -if not exist "$(ProjectDir)..\..\..\ldns\ldns\net.h" type "$(ProjectDir)\net.h" > "$(ProjectDir)..\..\..\ldns\ldns\net.h" - - - /ignore:4221 %(AdditionalOptions) - - - - - MaxSpeed - true - MultiThreadedDLL - true - Level3 - ProgramDatabase - HAVE_ISBLANK;HAVE_STRUCT_ADDRINFO;HAVE_CONFIG_H;_CRT_SECURE_NO_DEPRECATE;_MBCS;%(PreprocessorDefinitions) - ..\..\..\ldns\;.;%(AdditionalIncludeDirectories) - 4013;4101;4996;4267;4244;%(DisableSpecificWarnings) - - - true - true - true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - if not exist "$(ProjectDir)..\..\..\ldns\ldns\config.h" type "$(ProjectDir)\config.h" > "$(ProjectDir)..\..\..\ldns\ldns\config.h" -if not exist "$(ProjectDir)..\..\..\ldns\ldns\util.h" type "$(ProjectDir)\util.h" > "$(ProjectDir)..\..\..\ldns\ldns\util.h" -if not exist "$(ProjectDir)..\..\..\ldns\ldns\net.h" type "$(ProjectDir)\net.h" > "$(ProjectDir)..\..\..\ldns\ldns\net.h" - - - /ignore:4221 %(AdditionalOptions) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/libs/win32/ldns/ldns-lib/net.h b/libs/win32/ldns/ldns-lib/net.h deleted file mode 100644 index 19b6d784e6..0000000000 --- a/libs/win32/ldns/ldns-lib/net.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - * net.h - * - * DNS Resolver definitions - * - * a Net::DNS like library for C - * - * (c) NLnet Labs, 2005-2006 - * - * See the file LICENSE for the license - */ - -#ifndef LDNS_NET_H -#define LDNS_NET_H - -#include -#ifdef _MSC_VER -#include -#define socklen_t int -#define in_port_t USHORT -#define in_addr_t UINT -#else -#include -#include -#endif - -#define LDNS_DEFAULT_TIMEOUT_SEC 2 -#define LDNS_DEFAULT_TIMEOUT_USEC 0 - -/** - * \file - * - * Contains functions to send and receive packets over a network. - */ - -/** - * Sends a buffer to an ip using udp and return the respons as a ldns_pkt - * \param[in] qbin the ldns_buffer to be send - * \param[in] to the ip addr to send to - * \param[in] tolen length of the ip addr - * \param[in] timeout the timeout value for the network - * \param[out] answersize size of the packet - * \param[out] result packet with the answer - * \return status - */ -ldns_status ldns_udp_send(uint8_t **result, ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout, size_t *answersize); - -/** - * Send an udp query and don't wait for an answer but return - * the socket - * \param[in] qbin the ldns_buffer to be send - * \param[in] to the ip addr to send to - * \param[in] tolen length of the ip addr - * \param[in] timeout the timeout value for the network - * \return the socket used - */ - -int ldns_udp_bgsend(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout); - -/** - * Send an tcp query and don't wait for an answer but return - * the socket - * \param[in] qbin the ldns_buffer to be send - * \param[in] to the ip addr to send to - * \param[in] tolen length of the ip addr - * \param[in] timeout the timeout value for the network - * \return the socket used - */ -int ldns_tcp_bgsend(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout); - -/** - * Sends a buffer to an ip using tcp and return the respons as a ldns_pkt - * \param[in] qbin the ldns_buffer to be send - * \param[in] qbin the ldns_buffer to be send - * \param[in] to the ip addr to send to - * \param[in] tolen length of the ip addr - * \param[in] timeout the timeout value for the network - * \param[out] answersize size of the packet - * \param[out] result packet with the answer - * \return status - */ -ldns_status ldns_tcp_send(uint8_t **result, ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout, size_t *answersize); - -/** - * Sends ptk to the nameserver at the resolver object. Returns the data - * as a ldns_pkt - * - * \param[out] pkt packet received from the nameserver - * \param[in] r the resolver to use - * \param[in] query_pkt the query to send - * \return status - */ -ldns_status ldns_send(ldns_pkt **pkt, ldns_resolver *r, const ldns_pkt *query_pkt); - -/** - * Sends and ldns_buffer (presumably containing a packet to the nameserver at the resolver object. Returns the data - * as a ldns_pkt - * - * \param[out] pkt packet received from the nameserver - * \param[in] r the resolver to use - * \param[in] qb the buffer to send - * \param[in] tsig_mac the tsig MAC to authenticate the response with (NULL to do no TSIG authentication) - * \return status - */ -ldns_status ldns_send_buffer(ldns_pkt **pkt, ldns_resolver *r, ldns_buffer *qb, ldns_rdf *tsig_mac); - -/** - * Create a tcp socket to the specified address - * \param[in] to ip and family - * \param[in] tolen length of to - * \param[in] timeout timeout for the socket - * \return a socket descriptor - */ -int ldns_tcp_connect(const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout); - -/** - * Create a udp socket to the specified address - * \param[in] to ip and family - * \param[in] timeout timeout for the socket - * \return a socket descriptor - */ -int ldns_udp_connect(const struct sockaddr_storage *to, struct timeval timeout); - -/** - * send a query via tcp to a server. Don't want for the answer - * - * \param[in] qbin the buffer to send - * \param[in] sockfd the socket to use - * \param[in] to which ip to send it - * \param[in] tolen socketlen - * \return number of bytes sent - */ -ssize_t ldns_tcp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen); - -/** - * send a query via udp to a server. Don;t want for the answer - * - * \param[in] qbin the buffer to send - * \param[in] sockfd the socket to use - * \param[in] to which ip to send it - * \param[in] tolen socketlen - * \return number of bytes sent - */ -ssize_t ldns_udp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen); -/** - * Gives back a raw packet from the wire and reads the header data from the given - * socket. Allocates the data (of size size) itself, so don't forget to free - * - * \param[in] sockfd the socket to read from - * \param[out] size the number of bytes that are read - * \return the data read - */ -uint8_t *ldns_tcp_read_wire(int sockfd, size_t *size); - -/** - * Gives back a raw packet from the wire and reads the header data from the given - * socket. Allocates the data (of size size) itself, so don't forget to free - * - * \param[in] sockfd the socket to read from - * \param[in] fr the address of the client (if applicable) - * \param[in] *frlen the lenght of the client's addr (if applicable) - * \param[out] size the number of bytes that are read - * \return the data read - */ -uint8_t *ldns_udp_read_wire(int sockfd, size_t *size, struct sockaddr_storage *fr, socklen_t *frlen); - -/** - * returns the native sockaddr representation from the rdf. - * \param[in] rd the ldns_rdf to operate on - * \param[in] port what port to use. 0 means; use default (53) - * \param[out] size what is the size of the sockaddr_storage - * \return struct sockaddr* the address in the format so other - * functions can use it (sendto) - */ -struct sockaddr_storage * ldns_rdf2native_sockaddr_storage(const ldns_rdf *rd, uint16_t port, size_t *size); - -/** - * returns an rdf with the sockaddr info. works for ip4 and ip6 - * \param[in] sock the struct sockaddr_storage to convert - * \param[in] port what port was used. When NULL this is not set - * \return ldns_rdf* wth the address - */ -ldns_rdf * ldns_sockaddr_storage2rdf(struct sockaddr_storage *sock, uint16_t *port); - -/** - * Prepares the resolver for an axfr query - * The query is sent and the answers can be read with ldns_axfr_next - * \param[in] resolver the resolver to use - * \param[in] domain the domain to exfr - * \param[in] c the class to use - * \return ldns_status the status of the transfer - */ -ldns_status ldns_axfr_start(ldns_resolver *resolver, ldns_rdf *domain, ldns_rr_class c); - -#endif /* LDNS_NET_H */ diff --git a/libs/win32/ldns/ldns-lib/util.h b/libs/win32/ldns/ldns-lib/util.h deleted file mode 100644 index add9a79c33..0000000000 --- a/libs/win32/ldns/ldns-lib/util.h +++ /dev/null @@ -1,326 +0,0 @@ -/* - * util.h - * - * helper function header file - * - * a Net::DNS like library for C - * - * (c) NLnet Labs, 2004 - * - * See the file LICENSE for the license - */ - -#ifndef _UTIL_H -#define _UTIL_H - -//@include_inttypes_h@ -#include -#include -#include - -#define dprintf(X,Y) fprintf(stderr, (X), (Y)) -/* #define dprintf(X, Y) */ - -#define LDNS_VERSION "@PACKAGE_VERSION@" - -/** - * splint static inline workaround - */ -#ifdef S_SPLINT_S -#define INLINE -#else -#define INLINE static inline -#endif - -/** - * Memory management macros - */ -#define LDNS_MALLOC(type) LDNS_XMALLOC(type, 1) - -#define LDNS_XMALLOC(type, count) ((type *) malloc((count) * sizeof(type))) - -#define LDNS_REALLOC(ptr, type) LDNS_XREALLOC((ptr), type, 1) - -#define LDNS_XREALLOC(ptr, type, count) \ - ((type *) realloc((ptr), (count) * sizeof(type))) - -#define LDNS_FREE(ptr) \ - do { free((ptr)); (ptr) = NULL; } while (0) - -#define LDNS_DEP printf("DEPRECATED FUNCTION!\n"); - -/* - * Copy data allowing for unaligned accesses in network byte order - * (big endian). - */ -INLINE uint16_t -ldns_read_uint16(const void *src) -{ -#ifdef ALLOW_UNALIGNED_ACCESSES - return ntohs(*(uint16_t *) src); -#else - uint8_t *p = (uint8_t *) src; - return ((uint16_t) p[0] << 8) | (uint16_t) p[1]; -#endif -} - -INLINE uint32_t -ldns_read_uint32(const void *src) -{ -#ifdef ALLOW_UNALIGNED_ACCESSES - return ntohl(*(uint32_t *) src); -#else - uint8_t *p = (uint8_t *) src; - return ( ((uint32_t) p[0] << 24) - | ((uint32_t) p[1] << 16) - | ((uint32_t) p[2] << 8) - | (uint32_t) p[3]); -#endif -} - -/* - * Copy data allowing for unaligned accesses in network byte order - * (big endian). - */ -INLINE void -ldns_write_uint16(void *dst, uint16_t data) -{ -#ifdef ALLOW_UNALIGNED_ACCESSES - * (uint16_t *) dst = htons(data); -#else - uint8_t *p = (uint8_t *) dst; - p[0] = (uint8_t) ((data >> 8) & 0xff); - p[1] = (uint8_t) (data & 0xff); -#endif -} - -INLINE void -ldns_write_uint32(void *dst, uint32_t data) -{ -#ifdef ALLOW_UNALIGNED_ACCESSES - * (uint32_t *) dst = htonl(data); -#else - uint8_t *p = (uint8_t *) dst; - p[0] = (uint8_t) ((data >> 24) & 0xff); - p[1] = (uint8_t) ((data >> 16) & 0xff); - p[2] = (uint8_t) ((data >> 8) & 0xff); - p[3] = (uint8_t) (data & 0xff); -#endif -} - -/* warning. */ -INLINE void -ldns_write_uint64_as_uint48(void *dst, uint64_t data) -{ - uint8_t *p = (uint8_t *) dst; - p[0] = (uint8_t) ((data >> 40) & 0xff); - p[1] = (uint8_t) ((data >> 32) & 0xff); - p[2] = (uint8_t) ((data >> 24) & 0xff); - p[3] = (uint8_t) ((data >> 16) & 0xff); - p[4] = (uint8_t) ((data >> 8) & 0xff); - p[5] = (uint8_t) (data & 0xff); -} - - -/** - * Structure to do a Schwartzian-like transformation, for instance when - * sorting. If you need a transformation on the objects that are sorted, - * you can sue this to store the transformed values, so you do not - * need to do the transformation again for each comparison - */ -struct ldns_schwartzian_compare_struct { - void *original_object; - void *transformed_object; -}; - -/** A general purpose lookup table - * - * Lookup tables are arrays of (id, name) pairs, - * So you can for instance lookup the RCODE 3, which is "NXDOMAIN", - * and vice versa. The lookup tables themselves are defined wherever needed, - * for instance in \ref host2str.c - */ -struct ldns_struct_lookup_table { - int id; - const char *name; -}; -typedef struct ldns_struct_lookup_table ldns_lookup_table; - -/** - * Looks up the table entry by name, returns NULL if not found. - * \param[in] table the lookup table to search in - * \param[in] name what to search for - * \return the item found - */ -ldns_lookup_table *ldns_lookup_by_name(ldns_lookup_table table[], - const char *name); - -/** - * Looks up the table entry by id, returns NULL if not found. - * \param[in] table the lookup table to search in - * \param[in] id what to search for - * \return the item found - */ -ldns_lookup_table *ldns_lookup_by_id(ldns_lookup_table table[], int id); - -/** - * Returns the value of the specified bit - * The bits are counted from left to right, so bit #0 is the - * left most bit. - * \param[in] bits array holding the bits - * \param[in] index to the wanted bit - * \return - */ -int ldns_get_bit(uint8_t bits[], size_t index); - - -/** - * Returns the value of the specified bit - * The bits are counted from right to left, so bit #0 is the - * right most bit. - * \param[in] bits array holding the bits - * \param[in] index to the wanted bit - * \return 1 or 0 depending no the bit state - */ -int ldns_get_bit_r(uint8_t bits[], size_t index); - -/** - * sets the specified bit in the specified byte to - * 1 if value is true, 0 if false - * The bits are counted from right to left, so bit #0 is the - * right most bit. - * \param[in] byte the bit to set the bit in - * \param[in] bit_nr the bit to set (0 <= n <= 7) - * \param[in] value whether to set the bit to 1 or 0 - * \return 1 or 0 depending no the bit state - */ -void ldns_set_bit(uint8_t *byte, int bit_nr, bool value); - -/** - * Returns the value of a to the power of b - * (or 1 of b < 1) - */ -/*@unused@*/ -INLINE long -ldns_power(long a, long b) { - long result = 1; - while (b > 0) { - if (b & 1) { - result *= a; - if (b == 1) { - return result; - } - } - a *= a; - b /= 2; - } - return result; -} - -/** - * Returns the int value of the given (hex) digit - * \param[in] ch the hex char to convert - * \return the converted decimal value - */ -int ldns_hexdigit_to_int(char ch); - -/** - * Returns the char (hex) representation of the given int - * \param[in] ch the int to convert - * \return the converted hex char - */ -char ldns_int_to_hexdigit(int ch); - -/** - * Converts a hex string to binary data - * - * \param[out] data The binary result is placed here. - * At least strlen(str)/2 bytes should be allocated - * \param[in] str The hex string to convert. - * This string should not contain spaces - * \return The number of bytes of converted data, or -1 if one of the arguments * is NULL, or -2 if the string length is not an even number - */ -int -ldns_hexstring_to_data(uint8_t *data, const char *str); - -/** - * Show the internal library version - * \return a string with the version in it - */ -const char * ldns_version(void); - -/** - * Convert TM to seconds since epoch (midnight, January 1st, 1970). - * Like timegm(3), which is not always available. - * \param[in] tm a struct tm* with the date - * \return the seconds since epoch - */ -time_t mktime_from_utc(const struct tm *tm); - -/** - * Seed the random function. - * If the file descriptor is specified, the random generator is seeded with - * data from that file. If not, /dev/urandom is used. - * - * applications should call this if they need entropy data within ldns - * If openSSL is available, it is automatically seeded from /dev/urandom - * or /dev/random. - * - * If you need more entropy, or have no openssl available, this function - * MUST be called at the start of the program - * - * If openssl *is* available, this function just adds more entropy - * - * \param[in] fd a file providing entropy data for the seed - * \param[in] size the number of bytes to use as entropy data. If this is 0, - * only the minimal amount is taken (usually 4 bytes) - * \return 0 if seeding succeeds, 1 if it fails - */ -int ldns_init_random(FILE *fd, unsigned int size); - - -/** - * Encode data as BubbleBabble - * - * \param[in] data a pointer to data to be encoded - * \param[in] len size the number of bytes of data - * \return a string of BubbleBabble - */ -char *ldns_bubblebabble(uint8_t *data, size_t len); - -#ifndef B32_NTOP -int ldns_b32_ntop(uint8_t const *src, size_t srclength, - char *target, size_t targsize); -int b32_ntop(uint8_t const *src, size_t srclength, - char *target, size_t targsize); -int ldns_b32_ntop_extended_hex(uint8_t const *src, size_t srclength, - char *target, size_t targsize); -int b32_ntop_extended_hex(uint8_t const *src, size_t srclength, - char *target, size_t targsize); -/** - * calculates the size needed to store the result of b32_ntop - */ -/*@unused@*/ -static inline size_t ldns_b32_ntop_calculate_size(size_t srcsize) -{ - size_t result = ((((srcsize / 5) * 8) - 2) + 2); - return result; -} -#endif /* !B32_NTOP */ -#ifndef B32_PTON -int ldns_b32_pton(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize); -int b32_pton(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize); -int ldns_b32_pton_extended_hex(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize); -int b32_pton_extended_hex(char const *src, size_t hashed_owner_str_len, uint8_t *target, size_t targsize); -/** - * calculates the size needed to store the result of b32_pton - */ -/*@unused@*/ -static inline size_t ldns_b32_pton_calculate_size(size_t srcsize) -{ - size_t result = ((((srcsize) / 8) * 5)); - return result; -} -#endif /* !B32_PTON */ - -#endif /* !_UTIL_H */ diff --git a/src/mod/applications/mod_enum/mod_enum.2017.vcxproj b/src/mod/applications/mod_enum/mod_enum.2017.vcxproj index a9d5e925f7..29ab2a2801 100644 --- a/src/mod/applications/mod_enum/mod_enum.2017.vcxproj +++ b/src/mod/applications/mod_enum/mod_enum.2017.vcxproj @@ -46,6 +46,7 @@ $(DefaultPlatformToolset) + @@ -86,7 +87,6 @@ - %(RootDir)%(Directory)..\..\..\..\libs\ldns;%(AdditionalIncludeDirectories) false @@ -103,7 +103,6 @@ X64 - %(RootDir)%(Directory)..\..\..\..\libs\ldns;%(AdditionalIncludeDirectories) false @@ -118,7 +117,6 @@ - %(RootDir)%(Directory)..\..\..\..\libs\ldns;%(AdditionalIncludeDirectories) false @@ -135,7 +133,6 @@ X64 - %(RootDir)%(Directory)..\..\..\..\libs\ldns;%(AdditionalIncludeDirectories) false @@ -152,9 +149,6 @@ - - {23b4d303-79fc-49e0-89e2-2280e7e28940} - {202d7a4e-760d-4d0e-afa1-d7459ced30ff} false diff --git a/src/mod/applications/mod_enum/mod_enum.c b/src/mod/applications/mod_enum/mod_enum.c index 3a6efbaa8d..08c0d709f7 100644 --- a/src/mod/applications/mod_enum/mod_enum.c +++ b/src/mod/applications/mod_enum/mod_enum.c @@ -31,9 +31,6 @@ */ #include -#ifdef _MSC_VER -#define ssize_t int -#endif #include #define ENUM_MAXNAMESERVERS 10 /* max nameservers that will be used */ diff --git a/w32/download_LDNS.props b/w32/download_LDNS.props deleted file mode 100644 index 0036e1f278..0000000000 --- a/w32/download_LDNS.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/download_celt.props b/w32/download_celt.props deleted file mode 100644 index b6ae91ca22..0000000000 --- a/w32/download_celt.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/ldns-version.props b/w32/ldns-version.props new file mode 100644 index 0000000000..a52adf8006 --- /dev/null +++ b/w32/ldns-version.props @@ -0,0 +1,21 @@ + + + + + 1.9.2 + 1 + + + true + + + + + + $(ldnsVersion) + + + $(ldnsBuildNumber) + + + diff --git a/w32/ldns.props b/w32/ldns.props new file mode 100644 index 0000000000..c4375740ec --- /dev/null +++ b/w32/ldns.props @@ -0,0 +1,59 @@ + + + + + + + + $(BaseDir)libs\ldns-$(ldnsVersion)_$(ldnsBuildNumber) + + + + + + + + + + + + + + $(ldnsLibDir)\include;%(AdditionalIncludeDirectories) + + + $(ldnsLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + ldns.lib;ws2_32.lib;%(AdditionalDependencies) + + + From b78995c6609d76b050eb093173a504f199ace03d Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Fri, 25 Sep 2026 01:04:49 +0500 Subject: [PATCH 21/88] [mod_sofia] Keep the dialog handle after answering a refer NOTIFY (#3189) `sofia_handle_sip_i_notify()` answered an in-dialog `refer` NOTIFY and then fell through to the generic handling, which sent a second response and, on a terminated subscription, destroyed the dialog's handle. A channel kept up after the REFER outcome (`sip_refer_continue_after_reply=true`) could no longer send a REFER, re-INVITE or BYE. Return right after the `200 OK`; `refer` NOTIFYs are no longer forwarded under `proxy-notify-events`. Co-authored-by: Chris Rienzo --- src/mod/endpoints/mod_sofia/sofia.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 98c0becf6f..93583895c7 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -693,6 +693,7 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status, } } nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_IF(!zstr(session_id_header), SIPTAG_HEADER_STR(session_id_header)), TAG_END()); + return; } /* if no session, assume it could be an incoming notify from a gateway subscription */ From 8356b2ec5cc307d61cdcfcece971d9394971b67f Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 26 Sep 2026 23:27:09 +0300 Subject: [PATCH 22/88] [Build-System] Windows: Upgrade speex to v1.2.1_1 and use pre-compiled binaries, upgrade speexdsp to v1.2.1 and build it from the upstream sources (#3190) --- .gitignore | 1 + Freeswitch.2017.sln | 15 - libs/.gitignore | 1 + libs/win32/speex/config.h | 20 - libs/win32/speex/libspeex.2017.vcxproj | 644 ------------------ libs/win32/speex/libspeexdsp.2017.vcxproj | 72 +- w32/Library/FreeSwitchCore.2017.vcxproj | 13 +- ...ad_speex.props => download_speexdsp.props} | 12 +- w32/speex-version.props | 21 + w32/speex.props | 59 ++ w32/speexdsp-version.props | 19 + w32/speexdsp.props | 17 + 12 files changed, 172 insertions(+), 722 deletions(-) delete mode 100644 libs/win32/speex/config.h delete mode 100644 libs/win32/speex/libspeex.2017.vcxproj rename w32/{download_speex.props => download_speexdsp.props} (61%) create mode 100644 w32/speex-version.props create mode 100644 w32/speex.props create mode 100644 w32/speexdsp-version.props create mode 100644 w32/speexdsp.props diff --git a/.gitignore b/.gitignore index 1941e58ade..673a7a3bbc 100644 --- a/.gitignore +++ b/.gitignore @@ -295,6 +295,7 @@ libs/mpg123-*/ libs/mpg123-*.zip libs/ldns-*/ libs/ldns-*.zip +libs/speex-*.zip libs/SharpZipLib.*/ libs/SharpZipLib.*.nupkg libs/nasm-*/ diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index 433c5978ba..d92ffe969a 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -301,8 +301,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_lcr", "src\mod\applicat EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspandsp", "libs\win32\spandsp\libspandsp.2017.vcxproj", "{1CBB0077-18C5-455F-801C-0A0CE7B0BBF5}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspeex", "libs\win32\speex\libspeex.2017.vcxproj", "{E972C52F-9E85-4D65-B19C-031E511E9DB4}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspeexdsp", "libs\win32\speex\libspeexdsp.2017.vcxproj", "{03207781-0D1C-4DB3-A71D-45C608F28DBD}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_opal", "src\mod\endpoints\mod_opal\mod_opal.2017.vcxproj", "{05C9FB27-480E-4D53-B3B7-6338E2526666}" @@ -1212,18 +1210,6 @@ Global {1CBB0077-18C5-455F-801C-0A0CE7B0BBF5}.Release|Win32.Build.0 = Release|Win32 {1CBB0077-18C5-455F-801C-0A0CE7B0BBF5}.Release|x64.ActiveCfg = Release|x64 {1CBB0077-18C5-455F-801C-0A0CE7B0BBF5}.Release|x64.Build.0 = Release|x64 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.All|Win32.ActiveCfg = Release_Dynamic|Win32 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.All|Win32.Build.0 = Release_Dynamic|Win32 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.All|x64.ActiveCfg = Release_Dynamic|x64 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.All|x64.Build.0 = Release_Dynamic|x64 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.Debug|Win32.ActiveCfg = Debug|Win32 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.Debug|Win32.Build.0 = Debug|Win32 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.Debug|x64.ActiveCfg = Debug|x64 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.Debug|x64.Build.0 = Debug|x64 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.Release|Win32.ActiveCfg = Release|Win32 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.Release|Win32.Build.0 = Release|Win32 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.Release|x64.ActiveCfg = Release|x64 - {E972C52F-9E85-4D65-B19C-031E511E9DB4}.Release|x64.Build.0 = Release|x64 {03207781-0D1C-4DB3-A71D-45C608F28DBD}.All|Win32.ActiveCfg = Release_Static_SSE|x64 {03207781-0D1C-4DB3-A71D-45C608F28DBD}.All|x64.ActiveCfg = Release_Static_SSE|x64 {03207781-0D1C-4DB3-A71D-45C608F28DBD}.All|x64.Build.0 = Release_Static_SSE|x64 @@ -2220,7 +2206,6 @@ Global {329FD5B0-EF28-4606-86D0-F6EA21CF8E36} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {1A3793D1-05D1-4B57-9B0F-5AF3E79DC439} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {1CBB0077-18C5-455F-801C-0A0CE7B0BBF5} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} - {E972C52F-9E85-4D65-B19C-031E511E9DB4} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {03207781-0D1C-4DB3-A71D-45C608F28DBD} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {05C9FB27-480E-4D53-B3B7-6338E2526666} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C} {CC1DD008-9406-448D-A0AD-33C3186CFADB} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C} diff --git a/libs/.gitignore b/libs/.gitignore index c34ce55599..ef60896454 100644 --- a/libs/.gitignore +++ b/libs/.gitignore @@ -537,6 +537,7 @@ libg722_1/config/compile srtp/build/compile /pcre-*/ /speex-*/ +/speexdsp-*/ /curl-*/ /sqlite-*.zip /sqlite-*/ diff --git a/libs/win32/speex/config.h b/libs/win32/speex/config.h deleted file mode 100644 index abd35f0914..0000000000 --- a/libs/win32/speex/config.h +++ /dev/null @@ -1,20 +0,0 @@ -// Microsoft version of 'inline' -#define inline __inline - -// Visual Studio support alloca(), but it always align variables to 16-bit -// boundary, while SSE need 128-bit alignment. So we disable alloca() when -// SSE is enabled. -#ifndef _USE_SSE -# define USE_ALLOCA -#endif - -/* Default to floating point */ -#ifndef FIXED_POINT -# define FLOATING_POINT -# define USE_SMALLFT -#else -# define USE_KISS_FFT -#endif - -/* We don't support visibility on Win32 */ -#define EXPORT diff --git a/libs/win32/speex/libspeex.2017.vcxproj b/libs/win32/speex/libspeex.2017.vcxproj deleted file mode 100644 index 1addcd5c9e..0000000000 --- a/libs/win32/speex/libspeex.2017.vcxproj +++ /dev/null @@ -1,644 +0,0 @@ - - - - - Debug_RTL_dll - Win32 - - - Debug_RTL_dll - x64 - - - Debug - Win32 - - - Debug - x64 - - - Release_Dynamic - Win32 - - - Release_Dynamic - x64 - - - Release_RTL_dll - Win32 - - - Release_RTL_dll - x64 - - - Release_SSE2 - Win32 - - - Release_SSE2 - x64 - - - Release_SSE - Win32 - - - Release_SSE - x64 - - - Release - Win32 - - - Release - x64 - - - - {E972C52F-9E85-4D65-B19C-031E511E9DB4} - libspeex - Win32Proj - libspeex - - - - - StaticLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - DynamicLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - DynamicLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - true - $(DefaultPlatformToolset) - - - StaticLibrary - MultiByte - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - $(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - - Disabled - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - TurnOffAllWarnings - CompileAsC - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - Full - AnySuitable - true - Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - MultiThreadedDLL - false - - - TurnOffAllWarnings - CompileAsC - 4244;4305;4311;4100;4127;%(DisableSpecificWarnings) - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - Full - AnySuitable - true - Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - StreamingSIMDExtensions - - - Level4 - ProgramDatabase - CompileAsC - 4244;4305;4311;4100;4127;%(DisableSpecificWarnings) - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - Full - AnySuitable - true - Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - StreamingSIMDExtensions2 - - - Level4 - ProgramDatabase - CompileAsC - 4244;4305;4311;4100;4127;%(DisableSpecificWarnings) - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - Full - AnySuitable - true - Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - - - Level4 - ProgramDatabase - CompileAsC - 4244;4305;4311;4100;4127;%(DisableSpecificWarnings) - /FS %(AdditionalOptions) - - - libspeex.def - true - true - false - - - - - - - Disabled - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - - - Level4 - EditAndContinue - CompileAsC - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - Full - AnySuitable - true - Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - - - Level4 - ProgramDatabase - CompileAsC - 4244;4305;4311;4100;4127;%(DisableSpecificWarnings) - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - X64 - - - Disabled - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - TurnOffAllWarnings - CompileAsC - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - X64 - - - Full - AnySuitable - true - Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - MultiThreadedDLL - false - TurnOffAllWarnings - CompileAsC - 4244;4305;4311;4100;4127;%(DisableSpecificWarnings) - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - X64 - - - Full - AnySuitable - true - Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - StreamingSIMDExtensions - - - Level4 - ProgramDatabase - CompileAsC - 4244;4305;4311;4100;4127;%(DisableSpecificWarnings) - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - X64 - - - Full - AnySuitable - true - Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - StreamingSIMDExtensions2 - - - Level4 - ProgramDatabase - CompileAsC - 4244;4305;4311;4100;4127;%(DisableSpecificWarnings) - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - X64 - - - Full - AnySuitable - true - Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - - - Level4 - ProgramDatabase - CompileAsC - 4244;4305;4311;4100;4127;%(DisableSpecificWarnings) - /FS %(AdditionalOptions) - - - libspeex.def - true - true - false - - - MachineX64 - - - - - X64 - - - Disabled - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - - - Level4 - ProgramDatabase - CompileAsC - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - X64 - - - Full - AnySuitable - true - Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - - - Level4 - ProgramDatabase - CompileAsC - 4244;4305;4311;4100;4127;%(DisableSpecificWarnings) - /FS %(AdditionalOptions) - - - $(OutDir)libspeex.lib - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/libs/win32/speex/libspeexdsp.2017.vcxproj b/libs/win32/speex/libspeexdsp.2017.vcxproj index 4e2ba30453..9ba52e7359 100644 --- a/libs/win32/speex/libspeexdsp.2017.vcxproj +++ b/libs/win32/speex/libspeexdsp.2017.vcxproj @@ -41,7 +41,8 @@ 10.0 - + + StaticLibrary MultiByte @@ -154,7 +155,7 @@ Disabled - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) + $(speexdsp_libDir)\win32;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) true EnableFastChecks @@ -171,7 +172,7 @@ Disabled - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) + $(speexdsp_libDir)\win32;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) true EnableFastChecks @@ -188,7 +189,7 @@ AnySuitable true Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) + $(speexdsp_libDir)\win32;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -209,7 +210,7 @@ AnySuitable true Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) + $(speexdsp_libDir)\win32;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_LIB;HAVE_CONFIG_H;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -227,7 +228,7 @@ AnySuitable true Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) + $(speexdsp_libDir)\win32;%(AdditionalIncludeDirectories) _USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H;%(PreprocessorDefinitions) true @@ -265,7 +266,7 @@ AnySuitable true Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) + $(speexdsp_libDir)\win32;%(AdditionalIncludeDirectories) _USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H;%(PreprocessorDefinitions) true @@ -300,7 +301,7 @@ AnySuitable true Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) + $(speexdsp_libDir)\win32;%(AdditionalIncludeDirectories) _USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H;%(PreprocessorDefinitions) true @@ -329,7 +330,7 @@ AnySuitable true Speed - $(ProjectDir);..\..\speex-1.2rc1\include;%(AdditionalIncludeDirectories) + $(speexdsp_libDir)\win32;%(AdditionalIncludeDirectories) _USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H;%(PreprocessorDefinitions) true @@ -350,30 +351,39 @@ - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/w32/Library/FreeSwitchCore.2017.vcxproj b/w32/Library/FreeSwitchCore.2017.vcxproj index 43e28e04e1..b75d87e8cb 100644 --- a/w32/Library/FreeSwitchCore.2017.vcxproj +++ b/w32/Library/FreeSwitchCore.2017.vcxproj @@ -53,6 +53,8 @@ + + @@ -130,7 +132,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" Disabled - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) true EnableFastChecks @@ -180,7 +182,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" Disabled - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) true EnableFastChecks @@ -221,7 +223,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" MaxSpeed - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) MultiThreadedDLL Create @@ -259,7 +261,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" MaxSpeed - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\speex-1.2rc1\include;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) MultiThreadedDLL Create @@ -792,9 +794,6 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" {03207781-0d1c-4db3-a71d-45c608f28dbd} false - - {e972c52f-9e85-4d65-b19c-031e511e9db4} - {eef031cb-fed8-451e-a471-91ec8d4f6750} false diff --git a/w32/download_speex.props b/w32/download_speexdsp.props similarity index 61% rename from w32/download_speex.props rename to w32/download_speexdsp.props index 503db016a1..513478df78 100644 --- a/w32/download_speex.props +++ b/w32/download_speexdsp.props @@ -1,10 +1,11 @@ + - true + true - + diff --git a/w32/speex-version.props b/w32/speex-version.props new file mode 100644 index 0000000000..2f071de699 --- /dev/null +++ b/w32/speex-version.props @@ -0,0 +1,21 @@ + + + + + 1.2.1 + 1 + + + true + + + + + + $(speexVersion) + + + $(speexBuildNumber) + + + diff --git a/w32/speex.props b/w32/speex.props new file mode 100644 index 0000000000..99b82ce38d --- /dev/null +++ b/w32/speex.props @@ -0,0 +1,59 @@ + + + + + + + + $(BaseDir)libs\speex-$(speexVersion)_$(speexBuildNumber) + + + + + + + + + + + + + + $(speexLibDir)\include;%(AdditionalIncludeDirectories) + + + $(speexLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + libspeex.lib;%(AdditionalDependencies) + + + diff --git a/w32/speexdsp-version.props b/w32/speexdsp-version.props new file mode 100644 index 0000000000..fc03258b42 --- /dev/null +++ b/w32/speexdsp-version.props @@ -0,0 +1,19 @@ + + + + + + + 1.2.1 + + + true + + + + + + $(speexdspVersion) + + + diff --git a/w32/speexdsp.props b/w32/speexdsp.props new file mode 100644 index 0000000000..00362fa611 --- /dev/null +++ b/w32/speexdsp.props @@ -0,0 +1,17 @@ + + + + + + + + $(BaseDir)libs\speexdsp-$(speexdspVersion) + + + + + $(speexdsp_libDir)\include;%(AdditionalIncludeDirectories) + + + + From 542ea9fe61781cbcacd63f7f1ca876b69ecfeedc Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sun, 27 Sep 2026 20:20:28 +0300 Subject: [PATCH 23/88] [Build-System] Windows: Upgrade libjpeg to v10_1 and use pre-compiled binaries (#3191) --- .gitignore | 2 + Freeswitch.2017.sln | 14 - libs/.gitignore | 1 - libs/win32/libjpeg/libjpeg.2017.vcxproj | 246 ------------------ libs/win32/spandsp/libspandsp.2017.vcxproj | 17 +- .../mod_spandsp/mod_spandsp.2017.vcxproj | 9 +- w32/download_libjpeg.props | 40 --- w32/libjpeg-version.props | 21 ++ w32/libjpeg.props | 59 +++++ 9 files changed, 92 insertions(+), 317 deletions(-) delete mode 100644 libs/win32/libjpeg/libjpeg.2017.vcxproj delete mode 100644 w32/download_libjpeg.props create mode 100644 w32/libjpeg-version.props create mode 100644 w32/libjpeg.props diff --git a/.gitignore b/.gitignore index 673a7a3bbc..e4f56f5183 100644 --- a/.gitignore +++ b/.gitignore @@ -296,6 +296,8 @@ libs/mpg123-*.zip libs/ldns-*/ libs/ldns-*.zip libs/speex-*.zip +libs/libjpeg-*/ +libs/libjpeg-*.zip libs/SharpZipLib.*/ libs/SharpZipLib.*.nupkg libs/nasm-*/ diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index d92ffe969a..ebe6d39f0b 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -367,8 +367,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "xmlrpc-c", "xmlrpc-c", "{9D EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_redis", "src\mod\applications\mod_redis\mod_redis.2017.vcxproj", "{886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libjpeg", "libs\win32\libjpeg\libjpeg.2017.vcxproj", "{019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "abyss", "libs\win32\xmlrpc-c\abyss.2017.vcxproj", "{D2396DD7-7D38-473A-ABB7-6F96D65AE1B9}" ProjectSection(ProjectDependencies) = postProject {0D108721-EAE8-4BAF-8102-D8960EC93647} = {0D108721-EAE8-4BAF-8102-D8960EC93647} @@ -1540,17 +1538,6 @@ Global {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.Release|Win32.Build.0 = Release|Win32 {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.Release|x64.ActiveCfg = Release|x64 {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.Release|x64.Build.0 = Release|x64 - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.All|Win32.ActiveCfg = Release|Win32 - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.All|Win32.Build.0 = Release|Win32 - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.All|x64.ActiveCfg = Release|Win32 - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.Debug|Win32.ActiveCfg = Debug|Win32 - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.Debug|Win32.Build.0 = Debug|Win32 - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.Debug|x64.ActiveCfg = Debug|x64 - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.Debug|x64.Build.0 = Debug|x64 - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.Release|Win32.ActiveCfg = Release|Win32 - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.Release|Win32.Build.0 = Release|Win32 - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.Release|x64.ActiveCfg = Release|x64 - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.Release|x64.Build.0 = Release|x64 {D2396DD7-7D38-473A-ABB7-6F96D65AE1B9}.All|Win32.ActiveCfg = Release|x64 {D2396DD7-7D38-473A-ABB7-6F96D65AE1B9}.All|x64.ActiveCfg = Release|x64 {D2396DD7-7D38-473A-ABB7-6F96D65AE1B9}.All|x64.Build.0 = Release|x64 @@ -2238,7 +2225,6 @@ Global {2469B306-B027-4FF2-8815-C9C1EA2CAE79} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {9DE35039-A8F6-4FBF-B1B6-EB527F802411} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {D2396DD7-7D38-473A-ABB7-6F96D65AE1B9} = {9DE35039-A8F6-4FBF-B1B6-EB527F802411} {BED7539C-0099-4A14-AD5D-30828F15A171} = {9DE35039-A8F6-4FBF-B1B6-EB527F802411} {0D108721-EAE8-4BAF-8102-D8960EC93647} = {9DE35039-A8F6-4FBF-B1B6-EB527F802411} diff --git a/libs/.gitignore b/libs/.gitignore index ef60896454..aab0d1cae0 100644 --- a/libs/.gitignore +++ b/libs/.gitignore @@ -520,7 +520,6 @@ opal /broadvoice/broadvoice.spec /zeromq-*/ -/jpeg-8d/ /libnode-*/ /libnode-*.zip diff --git a/libs/win32/libjpeg/libjpeg.2017.vcxproj b/libs/win32/libjpeg/libjpeg.2017.vcxproj deleted file mode 100644 index 540ada1d74..0000000000 --- a/libs/win32/libjpeg/libjpeg.2017.vcxproj +++ /dev/null @@ -1,246 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Disabled - Disabled - Disabled - Disabled - false - false - false - false - - - - libjpeg - {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1} - Win32Proj - libjpeg - - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - StaticLibrary - false - true - Unicode - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - - - Level3 - NotUsing - Full - true - false - WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS - true - true - ..\..\jpeg-8d;%(AdditionalIncludeDirectories) - 4267;%(DisableSpecificWarnings) - - - Windows - true - true - true - - - if not exist "$(ProjectDir)..\..\jpeg-8d\jconfig.h" type "$(ProjectDir)..\..\jpeg-8d\jconfig.vc" > "$(ProjectDir)..\..\jpeg-8d\jconfig.h" - - - - - Level3 - NotUsing - Full - true - false - WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS - true - true - ..\..\jpeg-8d;%(AdditionalIncludeDirectories) - 4267;%(DisableSpecificWarnings) - - - Windows - true - true - true - - - if not exist "$(ProjectDir)..\..\jpeg-8d\jconfig.h" type "$(ProjectDir)..\..\jpeg-8d\jconfig.vc" > "$(ProjectDir)..\..\jpeg-8d\jconfig.h" - - - - - Level3 - NotUsing - true - false - WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS - true - true - ..\..\jpeg-8d;%(AdditionalIncludeDirectories) - false - Disabled - 4267;%(DisableSpecificWarnings) - MultiThreadedDebugDLL - - - Windows - true - true - true - - - if not exist "$(ProjectDir)..\..\jpeg-8d\jconfig.h" type "$(ProjectDir)..\..\jpeg-8d\jconfig.vc" > "$(ProjectDir)..\..\jpeg-8d\jconfig.h" - - - - - Level3 - NotUsing - Disabled - true - false - WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS - - - false - ..\..\jpeg-8d;%(AdditionalIncludeDirectories) - false - MultiThreadedDebugDLL - 4267;%(DisableSpecificWarnings) - - - Windows - true - true - true - - - if not exist "$(ProjectDir)..\..\jpeg-8d\jconfig.h" type "$(ProjectDir)..\..\jpeg-8d\jconfig.vc" > "$(ProjectDir)..\..\jpeg-8d\jconfig.h" - - - - - - \ No newline at end of file diff --git a/libs/win32/spandsp/libspandsp.2017.vcxproj b/libs/win32/spandsp/libspandsp.2017.vcxproj index 2010c70166..16813100a8 100644 --- a/libs/win32/spandsp/libspandsp.2017.vcxproj +++ b/libs/win32/spandsp/libspandsp.2017.vcxproj @@ -68,6 +68,7 @@ + @@ -84,7 +85,7 @@ Disabled - .;..\..\src\spandsp;..\..\src;..\..\src\msvc;.\spandsp;.\msvc;..\..\jpeg-8d;%(AdditionalIncludeDirectories) + .;..\..\src\spandsp;..\..\src;..\..\src\msvc;.\spandsp;.\msvc;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBSPANDSP_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;HAVE_CONFIG_H;%(PreprocessorDefinitions) true EnableFastChecks @@ -105,7 +106,7 @@ $(IntDir)BuildLog $(ProjectName).htm - .;.\spandsp;.\msvc;..\..\jpeg-8d;%(AdditionalIncludeDirectories) + .;.\spandsp;.\msvc;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBSPANDSP_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;HAVE_CONFIG_H;%(PreprocessorDefinitions) MultiThreadedDLL Level4 @@ -126,7 +127,7 @@ Disabled - .;.\spandsp;.\msvc;..\..\jpeg-8d;%(AdditionalIncludeDirectories) + .;.\spandsp;.\msvc;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBSPANDSP_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;HAVE_CONFIG_H;%(PreprocessorDefinitions) true EnableFastChecks @@ -147,7 +148,7 @@ $(IntDir)BuildLog $(ProjectName).htm - .;.\spandsp;.\msvc;..\..\jpeg-8d;%(AdditionalIncludeDirectories) + .;.\spandsp;.\msvc;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBSPANDSP_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;HAVE_CONFIG_H;%(PreprocessorDefinitions) MultiThreadedDLL Level4 @@ -451,14 +452,6 @@ - - {019dbd2a-273d-4ba4-bf86-b5efe2ed76b1} - true - false - false - true - false - {dee932ab-5911-4700-9eeb-8c7090a0a330} false diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.2017.vcxproj b/src/mod/applications/mod_spandsp/mod_spandsp.2017.vcxproj index 0802291b90..41852288bf 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.2017.vcxproj +++ b/src/mod/applications/mod_spandsp/mod_spandsp.2017.vcxproj @@ -66,6 +66,7 @@ + @@ -90,7 +91,7 @@ - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(AdditionalIncludeDirectories) 4189;6031;4456;4024;4047;4324;6340;6246;6011;6387;%(DisableSpecificWarnings) @@ -108,7 +109,7 @@ X64 - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(AdditionalIncludeDirectories) 4189;6031;4456;4024;4047;4324;6340;6246;6011;6387;%(DisableSpecificWarnings) @@ -124,7 +125,7 @@ - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(AdditionalIncludeDirectories) 4189;6031;4456;4024;4047;4324;6340;6246;6011;6387;%(DisableSpecificWarnings) @@ -142,7 +143,7 @@ X64 - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(AdditionalIncludeDirectories) 4189;6031;4456;4024;4047;4324;6340;6246;6011;6387;%(DisableSpecificWarnings) diff --git a/w32/download_libjpeg.props b/w32/download_libjpeg.props deleted file mode 100644 index 23e7c7b147..0000000000 --- a/w32/download_libjpeg.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/libjpeg-version.props b/w32/libjpeg-version.props new file mode 100644 index 0000000000..33e05ee036 --- /dev/null +++ b/w32/libjpeg-version.props @@ -0,0 +1,21 @@ + + + + + 10 + 1 + + + true + + + + + + $(libjpegVersion) + + + $(libjpegBuildNumber) + + + diff --git a/w32/libjpeg.props b/w32/libjpeg.props new file mode 100644 index 0000000000..5b836ce531 --- /dev/null +++ b/w32/libjpeg.props @@ -0,0 +1,59 @@ + + + + + + + + $(BaseDir)libs\libjpeg-$(libjpegVersion)_$(libjpegBuildNumber) + + + + + + + + + + + + + + $(libjpegLibDir)\include;%(AdditionalIncludeDirectories) + + + $(libjpegLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + libjpeg.lib;%(AdditionalDependencies) + + + From e6ed73bc1674ee483a2cf4174cd37dbcd002b941 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 28 Sep 2026 12:27:26 +0300 Subject: [PATCH 24/88] [Build-System] Windows: Upgrade freetype to v2.14.3_1 and use pre-compiled binaries (#3193) --- .gitignore | 3 +- Freeswitch.2017.sln | 15 - libs/win32/freetype/freetype.2017.vcxproj | 638 ---------------------- w32/Library/FreeSwitchCore.2017.vcxproj | 12 +- w32/download_freetype.props | 40 -- w32/freetype-version.props | 21 + w32/freetype.props | 58 +- 7 files changed, 82 insertions(+), 705 deletions(-) delete mode 100644 libs/win32/freetype/freetype.2017.vcxproj delete mode 100644 w32/download_freetype.props create mode 100644 w32/freetype-version.props diff --git a/.gitignore b/.gitignore index e4f56f5183..b220bcec97 100644 --- a/.gitignore +++ b/.gitignore @@ -228,7 +228,6 @@ yum/temp Freeswitch.2015.VC.db Freeswitch.2015.VC.VC.opendb -libs/freetype/ libs/libpng/ libs/zlib/ @@ -298,6 +297,8 @@ libs/ldns-*.zip libs/speex-*.zip libs/libjpeg-*/ libs/libjpeg-*.zip +libs/freetype-*/ +libs/freetype-*.zip libs/SharpZipLib.*/ libs/SharpZipLib.*.nupkg libs/nasm-*/ diff --git a/Freeswitch.2017.sln b/Freeswitch.2017.sln index ebe6d39f0b..c444625e19 100644 --- a/Freeswitch.2017.sln +++ b/Freeswitch.2017.sln @@ -414,8 +414,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libyuv", "libs\win32\libyuv EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libvpx", "libs\win32\libvpx\libvpx.2017.vcxproj", "{DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "freetype.2017", "libs\win32\freetype\freetype.2017.vcxproj", "{78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_png", "src\mod\formats\mod_png\mod_png.2017.vcxproj", "{FBC7E2A4-B989-4289-BA7F-68F440E9EF8B}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_av", "src\mod\applications\mod_av\mod_av.2017.vcxproj", "{7AEE504B-23B6-4B05-829E-7CD34855F146}" @@ -1702,18 +1700,6 @@ Global {DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74}.Release|Win32.Build.0 = Release|Win32 {DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74}.Release|x64.ActiveCfg = Release|x64 {DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74}.Release|x64.Build.0 = Release|x64 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.All|Win32.ActiveCfg = Release|Win32 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.All|Win32.Build.0 = Release|Win32 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.All|x64.ActiveCfg = Release|x64 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.All|x64.Build.0 = Release|x64 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.Debug|Win32.ActiveCfg = Debug|Win32 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.Debug|Win32.Build.0 = Debug|Win32 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.Debug|x64.ActiveCfg = Debug|x64 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.Debug|x64.Build.0 = Debug|x64 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.Release|Win32.ActiveCfg = Release|Win32 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.Release|Win32.Build.0 = Release|Win32 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.Release|x64.ActiveCfg = Release|x64 - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}.Release|x64.Build.0 = Release|x64 {FBC7E2A4-B989-4289-BA7F-68F440E9EF8B}.All|Win32.ActiveCfg = Release|Win32 {FBC7E2A4-B989-4289-BA7F-68F440E9EF8B}.All|Win32.Build.0 = Release|Win32 {FBC7E2A4-B989-4289-BA7F-68F440E9EF8B}.All|x64.ActiveCfg = Release|x64 @@ -2239,7 +2225,6 @@ Global {5B2BACE4-0F5A-4A21-930D-C0F4B1F58FA6} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C} {B6E22500-3DB6-4E6E-8CD5-591B781D7D99} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B} {FBC7E2A4-B989-4289-BA7F-68F440E9EF8B} = {A5A27244-AD24-46E5-B01B-840CD296C91D} {7AEE504B-23B6-4B05-829E-7CD34855F146} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {87933C2D-0159-46F7-B326-E1B6E982C21E} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} diff --git a/libs/win32/freetype/freetype.2017.vcxproj b/libs/win32/freetype/freetype.2017.vcxproj deleted file mode 100644 index 4043fbc429..0000000000 --- a/libs/win32/freetype/freetype.2017.vcxproj +++ /dev/null @@ -1,638 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B} - - - - StaticLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - StaticLibrary - false - MultiByte - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - freetype27 - - - - - Disabled - $(UserOptionDirectory);..\..\freetype\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) - _DEBUG;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebugDLL - true - Level4 - ProgramDatabase - Default - 4001 - true - false - $(OutDir)$(TargetName).pdb - Disabled - - - _DEBUG;$(UserDefines);%(PreprocessorDefinitions) - 0x0409 - - - true - MachineX86 - $(UserLibraryDirectories);%(AdditionalLibraryDirectories) - $(UserDependencies);%(AdditionalDependencies) - - - - - Disabled - $(UserOptionDirectory);..\..\freetype\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) - _DEBUG;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebugDLL - true - Level4 - ProgramDatabase - Default - 4001 - true - false - $(OutDir)$(TargetName).pdb - Disabled - - - _DEBUG;$(UserDefines);%(PreprocessorDefinitions) - 0x0409 - - - true - MachineX64 - $(UserLibraryDirectories);%(AdditionalLibraryDirectories) - $(UserDependencies);%(AdditionalDependencies) - - - - - Full - AnySuitable - $(UserOptionDirectory);..\..\freetype\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) - NDEBUG;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - true - Level4 - Default - 4001 - true - false - StreamingSIMDExtensions2 - false - false - false - - - true - - - true - Neither - true - - - NDEBUG;$(UserDefines);%(PreprocessorDefinitions) - 0x0409 - - - true - true - MachineX86 - $(UserLibraryDirectories);%(AdditionalLibraryDirectories) - $(UserDependencies);%(AdditionalDependencies) - - - - - Full - AnySuitable - $(UserOptionDirectory);..\..\freetype\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories) - NDEBUG;WIN32;_LIB;_CRT_SECURE_NO_WARNINGS;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions) - true - MultiThreadedDLL - true - true - Level4 - Default - 4001 - true - false - StreamingSIMDExtensions2 - false - false - false - - - true - - - true - Neither - true - - - NDEBUG;$(UserDefines);%(PreprocessorDefinitions) - 0x0409 - - - true - true - MachineX64 - $(UserLibraryDirectories);%(AdditionalLibraryDirectories) - $(UserDependencies);%(AdditionalDependencies) - - - - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - false - false - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - false - false - - - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - - - - - - - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - - - - - - - - - - - - \ No newline at end of file diff --git a/w32/Library/FreeSwitchCore.2017.vcxproj b/w32/Library/FreeSwitchCore.2017.vcxproj index b75d87e8cb..0ca2b7eccd 100644 --- a/w32/Library/FreeSwitchCore.2017.vcxproj +++ b/w32/Library/FreeSwitchCore.2017.vcxproj @@ -55,6 +55,7 @@ + @@ -132,7 +133,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" Disabled - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) true EnableFastChecks @@ -182,7 +183,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" Disabled - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) true EnableFastChecks @@ -223,7 +224,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" MaxSpeed - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) MultiThreadedDLL Create @@ -261,7 +262,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" MaxSpeed - ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\freetype\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) + ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) MultiThreadedDLL Create @@ -778,9 +779,6 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" {1cbb0077-18c5-455f-801c-0a0ce7b0bbf5} - - {78b079bd-9fc7-4b9e-b4a6-96da0f00248b} - {dce19daf-69ac-46db-b14a-39f0faa5db74} diff --git a/w32/download_freetype.props b/w32/download_freetype.props deleted file mode 100644 index 4a6b55d996..0000000000 --- a/w32/download_freetype.props +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - true - - - - - - - - - diff --git a/w32/freetype-version.props b/w32/freetype-version.props new file mode 100644 index 0000000000..caa2281540 --- /dev/null +++ b/w32/freetype-version.props @@ -0,0 +1,21 @@ + + + + + 2.14.3 + 1 + + + true + + + + + + $(freetypeVersion) + + + $(freetypeBuildNumber) + + + diff --git a/w32/freetype.props b/w32/freetype.props index 07668a0f7a..e0e44d0ff3 100644 --- a/w32/freetype.props +++ b/w32/freetype.props @@ -1,9 +1,59 @@ - + + + + + + + $(BaseDir)libs\freetype-$(freetypeVersion)_$(freetypeBuildNumber) + + + + + + + + + + + - $(SolutionDir)libs\freetype\include\;%(AdditionalIncludeDirectories) - HAVE_FREETYPE;FREETYPE_STATICLIB;%(PreprocessorDefinitions) + $(freetypeLibDir)\include;%(AdditionalIncludeDirectories) + + $(freetypeLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + freetype.lib;%(AdditionalDependencies) + - \ No newline at end of file + From ecb91ceb99e97385e849abefb3a6043c7861932f Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 28 Sep 2026 16:24:09 +0300 Subject: [PATCH 25/88] [Build-System] Windows: Retry failed package downloads and fail the build when a package never arrives (#3194) --- w32/downloadpackage.task | 183 +++++++++++++++++++++++++++++++-------- 1 file changed, 146 insertions(+), 37 deletions(-) diff --git a/w32/downloadpackage.task b/w32/downloadpackage.task index 0223e98cb0..6132131ac2 100644 --- a/w32/downloadpackage.task +++ b/w32/downloadpackage.task @@ -38,6 +38,9 @@ using System.Diagnostics; { public string filename; public int progress; + public long lastActivityTicks; + public Exception error; + public bool cancelled; } protected ManualResetEvent TaskCanceled { get; private set; } @@ -70,6 +73,8 @@ using System.Diagnostics; basedir = Path.GetFullPath(@"$(BaseDir)"); TaskCanceled = new ManualResetEvent(false); + ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; + bool result = true; //Log.LogMessage(MessageImportance.High, // "Checking for package \"" + package + "\"."); @@ -96,6 +101,8 @@ using System.Diagnostics; Log.LogMessage(MessageImportance.High, "Start downloading package \"" + package + "\"."); + bool downloaded = true; + using (var client = new System.Net.WebClient()) { Uri uri = new Uri(package); @@ -111,41 +118,12 @@ using System.Diagnostics; } else //if (!File.Exists(output)) // Uncomment to skip download if exists { - var syncObject = new State - { - filename = urifilename, - progress = -1 - }; - lock (syncObject) - { - client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted); - client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback); - client.DownloadFileAsync(uri, output, syncObject); - - while (!Monitor.Wait(syncObject, 1000)) - { - if (TaskCanceled.WaitOne(0)) - { - client.CancelAsync(); - Monitor.Wait(syncObject); - - if (File.Exists(output)) - { - Log.LogMessage(MessageImportance.High, - "Deleting incomplete file " + output + " for package \"" + package + "\"."); - File.Delete(output); - } - - Log.LogMessage(MessageImportance.High, - "Downloading canceled for package \"" + package + "\"."); - - break; - } - } - } + client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted); + client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback); + downloaded = Download(client, uri, output, urifilename); } - if (File.Exists(output)) + if (downloaded && File.Exists(output)) { // Successful download. @@ -181,7 +159,11 @@ using System.Diagnostics; } } - if (!TaskCanceled.WaitOne(0)) + if (!downloaded && !TaskCanceled.WaitOne(0)) + { + result = false; + } + else if (!TaskCanceled.WaitOne(0)) { Log.LogMessage(MessageImportance.High, "Downloading finished for package \"" + package + "\"."); @@ -190,7 +172,129 @@ using System.Diagnostics; m.ReleaseMutex(); - return true; + return result; + } + + // Every failure is retried -- an HTTP status of any kind, 404 and 403 + // included, a dropped or stalled connection, an empty file. The URL a sheet + // names is taken to be right, so a failure is something passing, and a + // missing file on a mirror or a release CDN is often exactly that. Only + // cancelling the build stops the retries early. + private static readonly int[] retryDelaysSeconds = { 2, 5, 10, 20, 30 }; + private const int stallTimeoutSeconds = 60; + + private bool Download(WebClient client, Uri uri, string output, string urifilename) + { + int attempts = retryDelaysSeconds.Length + 1; + string reason = null; + + for (int attempt = 1; attempt <= attempts; attempt++) + { + if (attempt > 1) + { + int delay = retryDelaysSeconds[attempt - 2]; + Log.LogWarning("Downloading package \"" + package + "\" failed (" + reason + "), attempt " + + (attempt - 1) + " of " + attempts + "; retrying in " + delay + " s."); + if (TaskCanceled.WaitOne(delay * 1000)) + { + Log.LogMessage(MessageImportance.High, + "Downloading canceled for package \"" + package + "\"."); + return false; + } + } + + reason = DownloadOnce(client, uri, output, urifilename); + if (reason == null) + { + return true; + } + + if (File.Exists(output)) + { + Log.LogMessage(MessageImportance.High, + "Deleting incomplete file " + output + " for package \"" + package + "\"."); + File.Delete(output); + } + + if (TaskCanceled.WaitOne(0)) + { + Log.LogMessage(MessageImportance.High, + "Downloading canceled for package \"" + package + "\"."); + return false; + } + } + + Log.LogError("Downloading package \"" + package + "\" failed after " + attempts + " attempts: " + reason + "."); + return false; + } + + // One attempt: null when the file arrived, otherwise why it did not. + private string DownloadOnce(WebClient client, Uri uri, string output, string urifilename) + { + var syncObject = new State + { + filename = urifilename, + progress = -1, + lastActivityTicks = DateTime.UtcNow.Ticks + }; + + lock (syncObject) + { + client.DownloadFileAsync(uri, output, syncObject); + + while (!Monitor.Wait(syncObject, 1000)) + { + if (TaskCanceled.WaitOne(0)) + { + client.CancelAsync(); + Monitor.Wait(syncObject); + return "canceled"; + } + + // DownloadFileAsync ignores WebRequest timeouts, so a connection + // that stops delivering would otherwise wait forever. + long idle = DateTime.UtcNow.Ticks - Interlocked.Read(ref syncObject.lastActivityTicks); + if (idle > TimeSpan.FromSeconds(stallTimeoutSeconds).Ticks) + { + client.CancelAsync(); + Monitor.Wait(syncObject); + return "no data for " + stallTimeoutSeconds + " s"; + } + } + } + + if (syncObject.error != null) + { + return Describe(syncObject.error); + } + if (syncObject.cancelled) + { + return "canceled"; + } + if (!File.Exists(output)) + { + return "no file written"; + } + if (new FileInfo(output).Length == 0) + { + return "0 bytes"; + } + return null; + } + + private static string Describe(Exception error) + { + var web = error as WebException; + if (web != null) + { + var http = web.Response as HttpWebResponse; + if (http != null) + { + return "HTTP " + (int)http.StatusCode + " " + http.StatusDescription; + } + return web.Status + ": " + web.Message; + } + return error.GetType().Name + ": " + error.Message; } private void Extract(string filename, string extracttofolder) @@ -244,10 +348,13 @@ using System.Diagnostics; private void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { - lock (e.UserState) + var state = (State)e.UserState; + lock (state) { + state.error = e.Error; + state.cancelled = e.Cancelled; //releases blocked thread - Monitor.Pulse(e.UserState); + Monitor.Pulse(state); } } @@ -267,6 +374,8 @@ using System.Diagnostics; private void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e) { + Interlocked.Exchange(ref ((State)e.UserState).lastActivityTicks, DateTime.UtcNow.Ticks); + if (((State)e.UserState).progress < e.ProgressPercentage) { ((State)e.UserState).progress = e.ProgressPercentage; From 541879c4ac7000c608eb547ada3e02d5d80f035b Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 28 Sep 2026 21:09:45 +0300 Subject: [PATCH 26/88] [Build-System] Windows: Fix a download hang on a missed completion signal and keep retrying when an incomplete file cannot be deleted (#3196) --- w32/downloadpackage.task | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/w32/downloadpackage.task b/w32/downloadpackage.task index 6132131ac2..013e3b70bd 100644 --- a/w32/downloadpackage.task +++ b/w32/downloadpackage.task @@ -41,6 +41,7 @@ using System.Diagnostics; public long lastActivityTicks; public Exception error; public bool cancelled; + public bool completed; } protected ManualResetEvent TaskCanceled { get; private set; } @@ -213,7 +214,16 @@ using System.Diagnostics; { Log.LogMessage(MessageImportance.High, "Deleting incomplete file " + output + " for package \"" + package + "\"."); - File.Delete(output); + try + { + File.Delete(output); + } + catch (Exception e) + { + // A scanner may still hold the file; the next attempt + // overwrites it anyway, so do not let this end the retries. + Log.LogWarning("Could not delete " + output + ": " + e.Message); + } } if (TaskCanceled.WaitOne(0)) @@ -242,12 +252,19 @@ using System.Diagnostics; { client.DownloadFileAsync(uri, output, syncObject); - while (!Monitor.Wait(syncObject, 1000)) + // Wait on the completed flag, not on Monitor.Wait's result: a pulse + // that lands while a timed-out Wait is reacquiring the lock is lost. + while (!syncObject.completed) { + if (Monitor.Wait(syncObject, 1000) || syncObject.completed) + { + continue; + } + if (TaskCanceled.WaitOne(0)) { client.CancelAsync(); - Monitor.Wait(syncObject); + WaitCompleted(syncObject); return "canceled"; } @@ -257,7 +274,7 @@ using System.Diagnostics; if (idle > TimeSpan.FromSeconds(stallTimeoutSeconds).Ticks) { client.CancelAsync(); - Monitor.Wait(syncObject); + WaitCompleted(syncObject); return "no data for " + stallTimeoutSeconds + " s"; } } @@ -282,6 +299,15 @@ using System.Diagnostics; return null; } + // Caller holds the lock on state. + private static void WaitCompleted(State state) + { + while (!state.completed) + { + Monitor.Wait(state); + } + } + private static string Describe(Exception error) { var web = error as WebException; @@ -353,6 +379,7 @@ using System.Diagnostics; { state.error = e.Error; state.cancelled = e.Cancelled; + state.completed = true; //releases blocked thread Monitor.Pulse(state); } From 67cc916efeb1eb29d5bbe2f6c46beb7c74ff1f78 Mon Sep 17 00:00:00 2001 From: Serhii Ivanov <11349489+s3rj1k@users.noreply.github.com> Date: Tue, 29 Sep 2026 00:55:17 +0200 Subject: [PATCH 27/88] [GHA] Bump macOS version to 27 (#3197) --- .github/workflows/macos.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index cf79c73247..229566af50 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -16,11 +16,11 @@ on: jobs: build: name: Build MacOS - runs-on: macos-latest + runs-on: xcode-27 steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v7 with: fetch-depth: 0 @@ -30,7 +30,6 @@ jobs: brew upgrade --formula || true # Remove pinned cmake version (https://github.com/actions/runner-images/blob/macos-15-arm64/20250825.2246/images/macos/scripts/build/install-common-utils.sh#L19) brew uninstall --ignore-dependencies cmake || true - # brew install libtiff openssl@3 brew install \ autoconf \ automake \ @@ -39,6 +38,7 @@ jobs: gnu-sed \ jpeg \ ldns \ + libks \ libpq@18 \ libsndfile \ libtool \ @@ -47,21 +47,20 @@ jobs: ossp-uuid \ pcre2 \ pkgconf \ + signalwire-client-c \ sofia-sip \ speex \ speexdsp \ sqlite \ - yasm \ && \ brew list --pinned | awk '{system("brew unpin " $1)}' && \ brew install --adopt \ - signalwire/homebrew-signalwire/libks2 \ - signalwire/homebrew-signalwire/signalwire-c2 \ signalwire/homebrew-signalwire/spandsp \ && \ brew link --force --overwrite \ ffmpeg@7 \ - libpq@18 + libpq@18 \ + ruby@3.4 - name: Bootstrap FreeSWITCH run: ./bootstrap.sh -j @@ -94,7 +93,7 @@ jobs: # find . -type f | sort - name: Upload build artifacts - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 if: always() with: name: freeswitch-macos-build From c8d17a46ce47e5566b91d384dd3c34d3236eea6d Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 29 Sep 2026 18:14:56 +0300 Subject: [PATCH 28/88] [mod_com_g729] Remove from tree. Use Debian packages. (#3200) --- .gitignore | 4 -- build/getg729.sh.in | 34 ---------------- build/modules.conf.in | 1 - build/modules.conf.most | 1 - .../testing/autoload_configs/modules.conf.xml | 1 - configure.ac | 4 -- debian/bootstrap.sh | 1 - debian/control-modules | 4 -- src/mod/Makefile.am | 5 +-- src/mod/codecs/mod_com_g729/Makefile.am | 39 ------------------- 10 files changed, 1 insertion(+), 93 deletions(-) delete mode 100755 build/getg729.sh.in delete mode 100644 src/mod/codecs/mod_com_g729/Makefile.am diff --git a/.gitignore b/.gitignore index b220bcec97..f4adb571b9 100644 --- a/.gitignore +++ b/.gitignore @@ -104,7 +104,6 @@ Release/ /build/freeswitch.pc /build/standalone_module/freeswitch.pc /build/getlib.sh -/build/getg729.sh /build/getsounds.sh /build/Makefile /build/Makefile.in @@ -116,7 +115,6 @@ Release/ /libs/esl/fs_ivrd /libs/esl/testclient /libs/esl/testserver -/libs/fsg729-*-installer /libs/g729/ /libs/libcodec2/compile /libs/libcodec2/config.guess @@ -148,8 +146,6 @@ Release/ /src/mod/applications/mod_snipe_hunt/Makefile /src/mod/applications/mod_test/test/Makefile /src/mod/applications/mod_test/test/Makefile.in -/src/mod/codecs/mod_com_g729/Makefile -/src/mod/codecs/mod_com_g729/Makefile.in /src/mod/dialplans/mod_dialplan_directory/Makefile /src/mod/formats/mod_shell_stream/Makefile /src/mod/languages/mod_lua/mod_lua_wrap.cpp.orig diff --git a/build/getg729.sh.in b/build/getg729.sh.in deleted file mode 100755 index d37ac1f47e..0000000000 --- a/build/getg729.sh.in +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh - -TAR=@TAR@ -ZCAT=@ZCAT@ -WGET=@WGET@ -CURL=@CURL@ - -if [ -f "$WGET" ] ; then - DOWNLOAD_CMD=$WGET -else - if [ -f "$CURL" ] ; then - DOWNLOAD_CMD="$CURL -L -O" - fi -fi - -base=http://files.freeswitch.org/g729/ -tarfile=$1 -url=`echo $tarfile | grep "://"` - -if [ ! -z $url ] ; then - base=$tarfile/ - tarfile=$2 -fi - -if [ ! -f $tarfile ] ; then - $DOWNLOAD_CMD $base$tarfile - if [ ! -f $tarfile ] ; then - echo cannot find $tarfile - exit 1 - fi -fi - -exit 0 - diff --git a/build/modules.conf.in b/build/modules.conf.in index 9b2e360811..da42dcf11d 100755 --- a/build/modules.conf.in +++ b/build/modules.conf.in @@ -52,7 +52,6 @@ codecs/mod_amr codecs/mod_b64 #codecs/mod_bv #codecs/mod_codec2 -#codecs/mod_com_g729 codecs/mod_g723_1 codecs/mod_g729 #codecs/mod_ilbc diff --git a/build/modules.conf.most b/build/modules.conf.most index 6b4427b0ee..222298f4b6 100755 --- a/build/modules.conf.most +++ b/build/modules.conf.most @@ -52,7 +52,6 @@ codecs/mod_amrwb codecs/mod_b64 codecs/mod_bv codecs/mod_codec2 -#codecs/mod_com_g729 codecs/mod_g723_1 codecs/mod_g729 codecs/mod_ilbc diff --git a/conf/testing/autoload_configs/modules.conf.xml b/conf/testing/autoload_configs/modules.conf.xml index 7c65886a9e..c36844bbc1 100644 --- a/conf/testing/autoload_configs/modules.conf.xml +++ b/conf/testing/autoload_configs/modules.conf.xml @@ -33,6 +33,5 @@ - diff --git a/configure.ac b/configure.ac index 16af18ce2d..4a27adfaca 100644 --- a/configure.ac +++ b/configure.ac @@ -1249,8 +1249,6 @@ AC_PATH_PROGS(WGET, wget) AC_PATH_PROGS(CURL, curl) GETLIB="cd $switch_srcdir/libs && ${SHELL} $switch_builddir/build/getlib.sh" AC_SUBST(GETLIB) -GETG729="cd $switch_srcdir/libs && ${SHELL} $switch_builddir/build/getg729.sh" -AC_SUBST(GETG729) GETSOUNDS="${SHELL} $switch_builddir/build/getsounds.sh" AC_SUBST(GETSOUNDS) @@ -2093,7 +2091,6 @@ AC_CONFIG_FILES([Makefile src/mod/codecs/mod_b64/Makefile src/mod/codecs/mod_bv/Makefile src/mod/codecs/mod_codec2/Makefile - src/mod/codecs/mod_com_g729/Makefile src/mod/codecs/mod_g723_1/Makefile src/mod/codecs/mod_g729/Makefile src/mod/codecs/mod_ilbc/Makefile @@ -2183,7 +2180,6 @@ AC_CONFIG_FILES([Makefile src/include/switch_am_config.h build/getsounds.sh build/getlib.sh - build/getg729.sh build/freeswitch.pc build/standalone_module/freeswitch.pc build/modmake.rules diff --git a/debian/bootstrap.sh b/debian/bootstrap.sh index 85a71b2a83..7a376097cd 100755 --- a/debian/bootstrap.sh +++ b/debian/bootstrap.sh @@ -38,7 +38,6 @@ avoid_mods=( applications/mod_osp applications/mod_skel applications/mod_cluechoo - codecs/mod_com_g729 codecs/mod_openh264 codecs/mod_siren codecs/mod_skel_codec diff --git a/debian/control-modules b/debian/control-modules index c33b873a88..6d10b6d116 100755 --- a/debian/control-modules +++ b/debian/control-modules @@ -263,10 +263,6 @@ Description: mod_codec2 Adds mod_codec2. Build-Depends: libcodec2-dev -Module: codecs/mod_com_g729 -Description: mod_com_g729 - Adds mod_com_g729. - Module: codecs/mod_g723_1 Description: mod_g723_1 Adds mod_g723_1. diff --git a/src/mod/Makefile.am b/src/mod/Makefile.am index e1cc13fb6d..97911d1ba3 100644 --- a/src/mod/Makefile.am +++ b/src/mod/Makefile.am @@ -58,7 +58,7 @@ $(OUR_MODULES) $(OUR_CLEAN_MODULES) $(OUR_INSTALL_MODULES) $(OUR_UNINSTALL_MODUL fi ; \ fi ; \ if test -z "$$target" ; then target="all" ; fi ; \ - if ! test -z "$$fail" || ! test -f $$moddir/$$modname.c && ! test -f $$moddir/$$modname.cpp && test $$modname != "mod_com_g729" ; \ + if ! test -z "$$fail" || ! test -f $$moddir/$$modname.c && ! test -f $$moddir/$$modname.cpp ; \ then echo ; echo "WARNING $$modname is not a valid FreeSWITCH module dir, skipping it..." ; else \ if test "$$target" != "print_tests" ; then echo; echo making $$target $$modname ; fi;\ test -d "$$buildmoddir" || mkdir -p $$buildmoddir ; \ @@ -72,9 +72,6 @@ $(OUR_MODULES) $(OUR_CLEAN_MODULES) $(OUR_INSTALL_MODULES) $(OUR_UNINSTALL_MODUL test -z "$$fail" ; \ fi; -mod_com_g729-activate: - cd $(switch_builddir)/src/mod/codecs/mod_com_g729 && $(MAKE) $(AM_MAKEFLAGS) activate - .DEFAULT: @if test -z "`echo $@ | grep '\-all$$'`"; then $(MAKE) $(AM_MAKEFLAGS) $@-all ; else echo Unknown target `echo $@ | sed -e 's|-all||'`; exit 1; fi diff --git a/src/mod/codecs/mod_com_g729/Makefile.am b/src/mod/codecs/mod_com_g729/Makefile.am deleted file mode 100644 index 128a9f9628..0000000000 --- a/src/mod/codecs/mod_com_g729/Makefile.am +++ /dev/null @@ -1,39 +0,0 @@ -include $(top_srcdir)/build/modmake.rulesam - -MODNAME=mod_com_g729 -VERSION=latest - -if ISLINUX - -G729INSTALLER = $(top_srcdir)/libs/fs-$(VERSION)-installer -LICSERVER=/usr/sbin/freeswitch-license-server -VALIDATOR=$(bindir)/freeswitch-license-validator -MOD=$(moddir)/mod_com_g729.so -BUILT_SOURCES = $(G729INSTALLER) - -install: $(LICSERVER) $(VALIDATOR) $(MOD) - -$(LICSERVER) $(VALIDATOR) $(MOD): $(G729INSTALLER) - $(SHELL) $(G729INSTALLER) $(bindir) $(moddir) nobanner - @echo - @echo - @echo Now you can activate your license by running $(MAKE) mod_com_g729-activate - @echo - @echo - -$(G729INSTALLER): - rm -f $(top_srcdir)/libs/fs-*-installer* - $(GETG729) fs-$(VERSION)-installer - chmod 755 $(G729INSTALLER) - -clean: - rm -f $(top_srcdir)/libs/fs-*-installer* - rm -rf /tmp/fsg729 - -activate: $(LICSERVER) $(VALIDATOR) $(MOD) - $(VALIDATOR) - -uninstall: clean - rm -f $(LICSERVER) $(VALIDATOR) $(MOD) - -endif From 6c08a4177e8c7c63460944dd454ef96d20a1be9c Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 29 Sep 2026 18:41:20 +0300 Subject: [PATCH 29/88] [mod_pocketsphinx] Download sphinxbase, pocketsphinx and the model from freeswitch/windows-deps releases instead of files.freeswitch.org (#3202) --- src/mod/asr_tts/mod_pocketsphinx/Makefile.am | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mod/asr_tts/mod_pocketsphinx/Makefile.am b/src/mod/asr_tts/mod_pocketsphinx/Makefile.am index 525b3927ca..9417760d8c 100644 --- a/src/mod/asr_tts/mod_pocketsphinx/Makefile.am +++ b/src/mod/asr_tts/mod_pocketsphinx/Makefile.am @@ -13,6 +13,7 @@ SPHINXBASE_LA2=$(SPHINXBASE_BUILDDIR)/src/libsphinxad/libsphinxad.la POCKETSPHINX_LA=$(POCKETSPHINX_BUILDDIR)/src/libpocketsphinx/libpocketsphinx.la SPHINXMODEL=communicator_semi_6000_20080321 +SPHINX_MIRROR=https://github.com/freeswitch/windows-deps/releases/download mod_LTLIBRARIES = mod_pocketsphinx.la mod_pocketsphinx_la_SOURCES = mod_pocketsphinx.c @@ -28,7 +29,7 @@ BUILT_SOURCES=$(POCKETSPHINX_LA) $(SPHINXBASE_LA) $(SPHINXBASE_LA2) endif $(SPHINXBASE_DIR): - $(GETLIB) $(SPHINXBASE).tar.gz + $(GETLIB) $(SPHINX_MIRROR)/$(SPHINXBASE) $(SPHINXBASE).tar.gz $(SPHINXBASE_BUILDDIR)/Makefile: $(SPHINXBASE_DIR) mkdir -p $(SPHINXBASE_BUILDDIR) @@ -46,7 +47,7 @@ $(SPHINXBASE_LA2): $(SPHINXBASE_BUILDDIR)/buildstamp $(TOUCH_TARGET) $(POCKETSPHINX_DIR): - $(GETLIB) $(POCKETSPHINX).tar.gz + $(GETLIB) $(SPHINX_MIRROR)/$(POCKETSPHINX) $(POCKETSPHINX).tar.gz $(POCKETSPHINX_BUILDDIR)/Makefile: $(POCKETSPHINX_DIR) $(SPHINXBASE_LA) $(SPHINXBASE_LA2) mkdir -p $(POCKETSPHINX_BUILDDIR) @@ -64,7 +65,7 @@ $(DESTDIR)$(grammardir)/model: mkdir -p $(DESTDIR)$(grammardir)/model $(DESTDIR)$(grammardir)/model/communicator: - $(GETLIB) $(SPHINXMODEL).tar.gz + $(GETLIB) $(SPHINX_MIRROR)/$(SPHINXMODEL) $(SPHINXMODEL).tar.gz mkdir -p $(DESTDIR)$(grammardir)/model/communicator cp -rp $(switch_srcdir)/libs/Communicator_semi_40.cd_semi_6000/* $(DESTDIR)$(grammardir)/model/communicator From 3dee68e8109207e4b01202ab868636cbe9ac841d Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 3 Oct 2026 00:44:51 +0300 Subject: [PATCH 30/88] [Build-System] Windows: Upgrade openssl to v3.4.8_1 and use libks, curl, rabbitmq-c, libpq and signalwire-client-c packages built against it (#3212) --- w32/curl-version.props | 2 +- w32/libks-version.props | 2 +- w32/libpq-version.props | 2 +- w32/openssl-version.props | 2 +- w32/rabbitmq-c-version.props | 2 +- w32/signalwire-client-c-version.props | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/w32/curl-version.props b/w32/curl-version.props index e2995b4b6c..8e8319afe9 100644 --- a/w32/curl-version.props +++ b/w32/curl-version.props @@ -3,7 +3,7 @@ 7.88.1 - 1 + 2 true diff --git a/w32/libks-version.props b/w32/libks-version.props index f40f433372..88f74addc7 100644 --- a/w32/libks-version.props +++ b/w32/libks-version.props @@ -5,7 +5,7 @@ 2.0.11 - 1 + 2 true diff --git a/w32/libpq-version.props b/w32/libpq-version.props index 78e20e96dd..670c58fdc8 100644 --- a/w32/libpq-version.props +++ b/w32/libpq-version.props @@ -5,7 +5,7 @@ 17.11 - 1 + 2 true diff --git a/w32/openssl-version.props b/w32/openssl-version.props index 813028e5bb..13c5865f9e 100644 --- a/w32/openssl-version.props +++ b/w32/openssl-version.props @@ -4,7 +4,7 @@ - 3.4.7 + 3.4.8 1 $(BaseDir)libs\openssl-$(OpenSSLVersion)_$(OpenSSLBuildNumber) diff --git a/w32/rabbitmq-c-version.props b/w32/rabbitmq-c-version.props index cf37180f9e..8d9cac6cb6 100644 --- a/w32/rabbitmq-c-version.props +++ b/w32/rabbitmq-c-version.props @@ -8,7 +8,7 @@ 17 0 $(rabbitmq_cMajorVersion).$(rabbitmq_cMinorVersion).$(rabbitmq_cRevisionVersion) - 1 + 2 true diff --git a/w32/signalwire-client-c-version.props b/w32/signalwire-client-c-version.props index 3447e8a8fe..d92816be10 100644 --- a/w32/signalwire-client-c-version.props +++ b/w32/signalwire-client-c-version.props @@ -5,7 +5,7 @@ 2.0.5 - 2 + 3 true From f4778e7f2c98417b2b23c088f7007d6b2c1653fb Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 9 Oct 2026 16:18:38 +0300 Subject: [PATCH 31/88] [UTILS] FSGET: Add source/build-dep/showsrc actions, make token optional (if already configured), add swapi_ token support (#3217) - New optional actions: `source`, `build-dep`, `showsrc`. `source` and `build-dep` resolve the source version for the current dpkg architecture, so apt does not pick a package built for another arch. - TOKEN can be omitted when the apt repository is already configured. - `swapi_*` tokens are accepted as FreeSWITCH Enterprise tokens, same as `PT*` - Arguments can be given in any order. Examples: ``` curl -sSL https://freeswitch.org/fsget | bash -s pat_xxxxx release install curl -sSL https://freeswitch.org/fsget | bash -s swapi_xxxxx prerelease build-dep curl -sSL https://freeswitch.org/fsget | bash -s build-dep release pat_xxxxx curl -sSL https://freeswitch.org/fsget | bash -s source curl -sSL https://freeswitch.org/fsget | bash -s showsrc ``` --- scripts/packaging/README.md | 52 +++++++++- scripts/packaging/fsget.sh | 198 ++++++++++++++++++++++++++++++------ 2 files changed, 215 insertions(+), 35 deletions(-) diff --git a/scripts/packaging/README.md b/scripts/packaging/README.md index 88059328c7..46de902917 100644 --- a/scripts/packaging/README.md +++ b/scripts/packaging/README.md @@ -19,17 +19,63 @@ A `SignalWire Personal Access Token` (PAT) or an `API Token` (for enterprise cus ## Configuring FreeSWITCH Debian repository ``` -curl -sSL https://freeswitch.org/fsget | bash -s [release|prerelease] [install] +curl -sSL https://freeswitch.org/fsget | bash -s [release|prerelease] [install|source|build-dep|showsrc] ``` Notice that `fsget` accepts arguments: -- `` (Required) +- `` (Optional) - omit if the FreeSWITCH apt repository is already configured (the credentials are already in `/etc/apt/auth.conf`) - `[release|prerelease]` (Optional) - `release` by default, `prerelease` is what you see in the `master` branch -- `[install]` (Optional) - If missing it will not install FreeSWITCH automatically after configuring the repository +- `[install|source|build-dep|showsrc]` (Optional) - action to perform after the repository is configured. If missing it will not perform any action after configuring the repository. `FreeSWITCH Community` or `FreeSWITCH Enterprise` version is installed based on the token provided. Enterprise customers may install `FreeSWITCH Community` versions by using a `SignalWire Personal Access Token` instead of an `API Token`. + +Arguments can be supplied in any order — `fsget` recognises them by pattern. These commands are equivalent: +``` +curl -sSL https://freeswitch.org/fsget | bash -s release build-dep +curl -sSL https://freeswitch.org/fsget | bash -s build-dep release +curl -sSL https://freeswitch.org/fsget | bash -s build-dep release +``` + +### Available actions + +| Action | Description | +| --- | --- | +| `install` | Install `freeswitch-meta-all` after the repository is configured. | +| `source` | Download the FreeSWITCH source package for the current build architecture. | +| `build-dep` | Install the FreeSWITCH build dependencies for the current build architecture. | +| `showsrc` | Print the FreeSWITCH source version for the current build architecture and exit. | + +Because FreeSWITCH source packages encode the build architecture in the version string, `source` and `build-dep` look up the exact version for the current architecture before invoking `apt-get` — this prevents `apt` from picking a candidate built for a different architecture. + +### Examples + +Configure the repository and install FreeSWITCH: +``` +curl -sSL https://freeswitch.org/fsget | bash -s release install +``` + +Configure the prerelease repository and install build dependencies: +``` +curl -sSL https://freeswitch.org/fsget | bash -s prerelease build-dep +``` + +Token already configured — just install build dependencies for the current architecture: +``` +curl -sSL https://freeswitch.org/fsget | bash -s build-dep +``` + +Token already configured — fetch the source package for the current architecture: +``` +curl -sSL https://freeswitch.org/fsget | bash -s source +``` + +Print the FreeSWITCH source version for the current architecture: +``` +curl -sSL https://freeswitch.org/fsget | bash -s showsrc +``` + ## Installing FreeSWITCH If not installed already type diff --git a/scripts/packaging/fsget.sh b/scripts/packaging/fsget.sh index 0ef9cc3bb6..8d872233a9 100755 --- a/scripts/packaging/fsget.sh +++ b/scripts/packaging/fsget.sh @@ -6,6 +6,33 @@ set -e # Exit immediately if a command exits with a non-zero status set -u # Treat unset variables as an error set -o pipefail # Return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status +print_usage() +{ + cat << EOF +Usage: $0 [TOKEN] [release|prerelease] [install|source|build-dep|showsrc] + + TOKEN PAT (pat_*, ghapat_*) or FSA token (PT*, swapi_*). Optional if the + FreeSWITCH apt repository is already configured. + release Use the stable repository (default when TOKEN is provided). + prerelease Use the unstable repository. + +Actions (optional): + install Install freeswitch-meta-all after configuring the repository. + source Download FreeSWITCH source package for the build architecture. + build-dep Install build dependencies for FreeSWITCH on the build architecture. + showsrc Print the FreeSWITCH source version for the build architecture and exit. + +If TOKEN is omitted the repository is assumed to be configured already and the +action is executed against the existing configuration. + +Examples: + $0 pat_xxxxx release install + $0 PT_xxxxx prerelease build-dep + $0 build-dep + $0 showsrc +EOF +} + source_os_release() { if [ ! -f /etc/os-release ]; then @@ -13,7 +40,10 @@ source_os_release() exit 1 fi . /etc/os-release +} +print_os_identification() +{ echo -n "Operating system identification:" [ -n "$ID" ] && echo -n " ID=$ID" [ -n "$VERSION_CODENAME" ] && echo -n " CODENAME=$VERSION_CODENAME" @@ -42,25 +72,96 @@ configure_auth() fi } -install_freeswitch() +# `apt-get source` extracts the source tree with `dpkg-source`, which lives in +# `dpkg-dev` — only pull that package in when we actually need extraction. +# Callers must run `apt-get update` before invoking this (the `source` action +# already does so as part of the version lookup). +ensure_dpkg_source() +{ + if ! command -v dpkg-source > /dev/null 2>&1; then + apt-get install -y dpkg-dev + fi +} + +# FreeSWITCH source versions encode build arch in the version string (e.g. +# 1.10.X-release.YYYYMMDDHHMMSS+1.debNN-amd64). Plain `apt-get source freeswitch` +# or `apt-get build-dep freeswitch` may pick a candidate that does not match the +# current architecture, so we filter showsrc output by the dpkg architecture. +get_freeswitch_source_version() +{ + apt-cache showsrc freeswitch \ + | grep "^Version" \ + | grep "$(dpkg --print-architecture)" \ + | awk '{print $2}' \ + | head -n 1 +} + +run_action() { local edition="$1" local action="$2" + local label="FreeSWITCH" + [ -n "${edition}" ] && label="FreeSWITCH ${edition}" - apt-get update - - if [ "${action}" = "install" ]; then - echo "Installing FreeSWITCH ${edition}" - apt-get install -y freeswitch-meta-all - echo "------------------------------------------------------------------" - echo " Done installing FreeSWITCH ${edition}" - echo "------------------------------------------------------------------" - else - echo "------------------------------------------------------------------" - echo " Done configuring FreeSWITCH Debian repository" - echo "------------------------------------------------------------------" - echo "To install FreeSWITCH ${edition} type: apt-get install -y freeswitch-meta-all" - fi + case "${action}" in + "") + echo "------------------------------------------------------------------" + echo " Done configuring ${label} Debian repository" + echo "------------------------------------------------------------------" + echo "To install ${label} type: apt-get install -y freeswitch-meta-all" + ;; + install) + apt-get update + echo "Installing ${label}" + apt-get install -y freeswitch-meta-all + echo "------------------------------------------------------------------" + echo " Done installing ${label}" + echo "------------------------------------------------------------------" + ;; + source) + apt-get update + local version + version=$(get_freeswitch_source_version) + if [ -z "${version}" ]; then + echo "Error: Unable to determine FreeSWITCH source version for $(dpkg --print-architecture)" + exit 1 + fi + ensure_dpkg_source + echo "Downloading ${label} source (version: ${version})" + apt-get source "freeswitch=${version}" + echo "------------------------------------------------------------------" + echo " Done downloading ${label} source (version: ${version})" + echo "------------------------------------------------------------------" + ;; + build-dep) + apt-get update + local version + version=$(get_freeswitch_source_version) + if [ -z "${version}" ]; then + echo "Error: Unable to determine FreeSWITCH source version for $(dpkg --print-architecture)" + exit 1 + fi + echo "Installing ${label} build dependencies (version: ${version})" + apt-get build-dep -y "freeswitch=${version}" + echo "------------------------------------------------------------------" + echo " Done installing ${label} build dependencies (version: ${version})" + echo "------------------------------------------------------------------" + ;; + showsrc) + local version + version=$(get_freeswitch_source_version) + if [ -z "${version}" ]; then + echo "Error: Unable to determine FreeSWITCH source version for $(dpkg --print-architecture)" + exit 1 + fi + echo "${version}" + ;; + *) + echo "Error: Unknown action '${action}'" + print_usage + exit 1 + ;; + esac } if [ "$(id -u)" != "0" ]; then @@ -68,23 +169,61 @@ if [ "$(id -u)" != "0" ]; then fi if [ "$#" -lt 1 ] || [ "$#" -gt 3 ]; then - echo "Usage: $0 [[release|prerelease] [install]]" + print_usage exit 1 fi -TOKEN=$1 -RELEASE="${2:-release}" -ACTION="${3:-}" +TOKEN="" +RELEASE="release" +ACTION="" + +for arg in "$@"; do + case "${arg}" in + release | prerelease) + RELEASE="${arg}" + ;; + install | source | build-dep | showsrc) + ACTION="${arg}" + ;; + pat_* | ghapat_* | PT* | swapi_* | not_a_real_token_but_a_dummy_token_*) + TOKEN="${arg}" + ;; + *) + echo "Error: Unrecognized argument '${arg}'" + print_usage + exit 1 + ;; + esac +done + +if [ -z "${TOKEN}" ] && [ -z "${ACTION}" ]; then + echo "Error: Either a TOKEN or an action must be specified." + print_usage + exit 1 +fi source_os_release -if [ "${ID,,}" = "debian" ]; then - ARCH=$(dpkg --print-architecture) +if [ "${ID,,}" != "debian" ]; then + echo "Unrecognized OS. We support Debian only." + exit 1 +fi +# `showsrc` is meant to be machine-readable (a single version line); keep its +# stdout clean. All other paths print the OS identification for context. +if [ "${ACTION}" != "showsrc" ]; then + print_os_identification +fi + +ARCH=$(dpkg --print-architecture) +EDITION="" + +if [ -n "${TOKEN}" ]; then if [[ ${TOKEN} == pat_* || ${TOKEN} == ghapat_* || ${TOKEN} == not_a_real_token_but_a_dummy_token_* ]]; then DOMAIN="freeswitch.signalwire.com" GPG_KEY="/usr/share/keyrings/signalwire-freeswitch-repo.gpg" RPI="" + EDITION="Community" if [ "${RELEASE,,}" = "prerelease" ]; then RELEASE="unstable" @@ -96,7 +235,7 @@ if [ "${ID,,}" = "debian" ]; then RPI="rpi/" fi - echo "FreeSWITCH Community ($RELEASE)" + echo "FreeSWITCH ${EDITION} (${RELEASE})" setup_common configure_auth "${DOMAIN}" "" "${TOKEN}" @@ -112,12 +251,11 @@ if [ "${ID,,}" = "debian" ]; then echo "Suites: ${VERSION_CODENAME}" >> /etc/apt/sources.list.d/freeswitch.sources echo "Components: main" >> /etc/apt/sources.list.d/freeswitch.sources echo "Signed-By: ${GPG_KEY}" >> /etc/apt/sources.list.d/freeswitch.sources - - install_freeswitch "Community" "${ACTION}" - elif [[ ${TOKEN} == PT* ]]; then + elif [[ ${TOKEN} == PT* || ${TOKEN} == swapi_* ]]; then DOMAIN="fsa.freeswitch.com" GPG_KEY="/usr/share/keyrings/signalwire-freeswitch-advantage-repo.gpg" RPI="" + EDITION="Enterprise" if [ "${RELEASE,,}" = "prerelease" ]; then RELEASE="unstable" @@ -129,7 +267,7 @@ if [ "${ID,,}" = "debian" ]; then RPI="-rpi" fi - echo "FreeSWITCH Enterprise ($RELEASE)" + echo "FreeSWITCH ${EDITION} (${RELEASE})" setup_common configure_auth "${DOMAIN}" "" "${TOKEN}" @@ -145,11 +283,7 @@ if [ "${ID,,}" = "debian" ]; then echo "Suites: ${VERSION_CODENAME}" >> /etc/apt/sources.list.d/freeswitch.sources echo "Components: ${RELEASE}" >> /etc/apt/sources.list.d/freeswitch.sources echo "Signed-By: ${GPG_KEY}" >> /etc/apt/sources.list.d/freeswitch.sources - - install_freeswitch "Enterprise" "${ACTION}" - else - echo "Unrecognized token type" fi -else - echo "Unrecognized OS. We support Debian only." fi + +run_action "${EDITION}" "${ACTION}" From 12ac48ab9e692d645b91b83bab89a85abdc3af53 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 9 Oct 2026 23:37:26 +0300 Subject: [PATCH 32/88] [UTILS] FSGET: Add swpat_ token prefix support. (#3219) --- scripts/packaging/fsget.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/packaging/fsget.sh b/scripts/packaging/fsget.sh index 8d872233a9..33f272cbdb 100755 --- a/scripts/packaging/fsget.sh +++ b/scripts/packaging/fsget.sh @@ -11,7 +11,7 @@ print_usage() cat << EOF Usage: $0 [TOKEN] [release|prerelease] [install|source|build-dep|showsrc] - TOKEN PAT (pat_*, ghapat_*) or FSA token (PT*, swapi_*). Optional if the + TOKEN PAT (swpat_*, pat_*, ghapat_*) or FSA token (PT*, swapi_*). Optional if the FreeSWITCH apt repository is already configured. release Use the stable repository (default when TOKEN is provided). prerelease Use the unstable repository. @@ -26,7 +26,7 @@ If TOKEN is omitted the repository is assumed to be configured already and the action is executed against the existing configuration. Examples: - $0 pat_xxxxx release install + $0 swpat_xxxxx release install $0 PT_xxxxx prerelease build-dep $0 build-dep $0 showsrc @@ -185,7 +185,7 @@ for arg in "$@"; do install | source | build-dep | showsrc) ACTION="${arg}" ;; - pat_* | ghapat_* | PT* | swapi_* | not_a_real_token_but_a_dummy_token_*) + swpat_* | pat_* | ghapat_* | PT* | swapi_* | not_a_real_token_but_a_dummy_token_*) TOKEN="${arg}" ;; *) @@ -219,7 +219,7 @@ ARCH=$(dpkg --print-architecture) EDITION="" if [ -n "${TOKEN}" ]; then - if [[ ${TOKEN} == pat_* || ${TOKEN} == ghapat_* || ${TOKEN} == not_a_real_token_but_a_dummy_token_* ]]; then + if [[ ${TOKEN} == swpat_* || ${TOKEN} == pat_* || ${TOKEN} == ghapat_* || ${TOKEN} == not_a_real_token_but_a_dummy_token_* ]]; then DOMAIN="freeswitch.signalwire.com" GPG_KEY="/usr/share/keyrings/signalwire-freeswitch-repo.gpg" RPI="" From 9ad11881cb0255d3f0f5623d90eadf373540442a Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 26 Oct 2026 21:26:46 +0300 Subject: [PATCH 33/88] [mod_lua] Fix crash on concurrent first Lua run by initializing SWIG type tables once at module load (#3245) --- src/mod/languages/mod_lua/mod_lua.cpp | 11 +++ src/mod/languages/mod_lua/test/test_mod_lua.c | 68 +++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/src/mod/languages/mod_lua/mod_lua.cpp b/src/mod/languages/mod_lua/mod_lua.cpp index b1d19428dc..d0b39ba1d8 100644 --- a/src/mod/languages/mod_lua/mod_lua.cpp +++ b/src/mod/languages/mod_lua/mod_lua.cpp @@ -680,6 +680,17 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load) switch_application_interface_t *app_interface; switch_dialplan_interface_t *dp_interface; switch_chat_application_interface_t *chat_app_interface; + lua_State *L; + + /* The first luaopen_freeswitch() call fills SWIG's process-wide type tables and is not thread-safe, + so do it once here, before anything (calls, event hooks, startup scripts) can run Lua concurrently. */ + if (!(L = lua_init())) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to initialize Lua\n"); + + return SWITCH_STATUS_FALSE; + } + + lua_uninit(L); /* connect my internal structure to the blank pointer passed to me */ *module_interface = switch_loadable_module_create_module_interface(pool, modname); diff --git a/src/mod/languages/mod_lua/test/test_mod_lua.c b/src/mod/languages/mod_lua/test/test_mod_lua.c index bbd4cba584..3652c5c2b2 100644 --- a/src/mod/languages/mod_lua/test/test_mod_lua.c +++ b/src/mod/languages/mod_lua/test/test_mod_lua.c @@ -30,6 +30,36 @@ #include +#define CONCURRENT_RUN_THREADS 32 + +static switch_mutex_t *concurrent_run_mutex = NULL; +static switch_thread_cond_t *concurrent_run_cond = NULL; +static int concurrent_run_ready = 0; +static int concurrent_run_go = 0; + +static void *SWITCH_THREAD_FUNC concurrent_run_thread(switch_thread_t *thread, void *obj) +{ + int *ok = (int *)obj; + switch_stream_handle_t stream = { 0 }; + + SWITCH_STANDARD_STREAM(stream); + + /* Block until every thread is up, so that one broadcast sends them all into lua_init() together */ + switch_mutex_lock(concurrent_run_mutex); + concurrent_run_ready++; + switch_thread_cond_broadcast(concurrent_run_cond); + while (!concurrent_run_go) { + switch_thread_cond_wait(concurrent_run_cond, concurrent_run_mutex); + } + switch_mutex_unlock(concurrent_run_mutex); + + switch_api_execute("lua", "~stream:write('+OK')", NULL, &stream); + *ok = stream.data && !strcmp((char *)stream.data, "+OK"); + switch_safe_free(stream.data); + + return NULL; +} + FST_CORE_BEGIN("conf") { FST_MODULE_BEGIN(mod_lua, mod_lua_test) @@ -40,6 +70,44 @@ FST_CORE_BEGIN("conf") } FST_SETUP_END() + /* Keep this test first: only the very first luaopen_freeswitch() in the process can race on SWIG's type tables */ + FST_TEST_BEGIN(concurrent_first_run_test) + { + switch_thread_t *thread[CONCURRENT_RUN_THREADS] = { 0 }; + int ok[CONCURRENT_RUN_THREADS] = { 0 }; + switch_threadattr_t *thd_attr = NULL; + switch_status_t status; + int i, started = 0; + + switch_mutex_init(&concurrent_run_mutex, SWITCH_MUTEX_DEFAULT, fst_pool); + switch_thread_cond_create(&concurrent_run_cond, fst_pool); + switch_threadattr_create(&thd_attr, fst_pool); + switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); + + for (i = 0; i < CONCURRENT_RUN_THREADS; i++) { + if (switch_thread_create(&thread[started], thd_attr, concurrent_run_thread, &ok[started], fst_pool) == SWITCH_STATUS_SUCCESS) { + started++; + } + } + + fst_check_int_equals(started, CONCURRENT_RUN_THREADS); + + /* Only wait for the threads that did start, so a failed switch_thread_create() fails the test instead of hanging it */ + switch_mutex_lock(concurrent_run_mutex); + while (concurrent_run_ready < started) { + switch_thread_cond_wait(concurrent_run_cond, concurrent_run_mutex); + } + concurrent_run_go = 1; + switch_thread_cond_broadcast(concurrent_run_cond); + switch_mutex_unlock(concurrent_run_mutex); + + for (i = 0; i < started; i++) { + switch_thread_join(&status, thread[i]); + fst_check(ok[i]); + } + } + FST_TEST_END() + FST_TEST_BEGIN(json_test) { switch_stream_handle_t stream = { 0 }; From 36573f134844c515caff1f99d650cf3f1b1fe37a Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 27 Oct 2026 22:50:22 +0300 Subject: [PATCH 34/88] Bump sofia-sip library requirement to version 1.13.19 (#3246) --- configure.ac | 2 +- debian/bootstrap.sh | 4 ++-- freeswitch.spec | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 4a27adfaca..9507ab6fe1 100644 --- a/configure.ac +++ b/configure.ac @@ -710,7 +710,7 @@ PKG_CHECK_MODULES([SPANDSP], [spandsp >= 3.1.1],[ AC_MSG_ERROR([no usable spandsp; please install spandsp4 devel package or equivalent]) ]) -PKG_CHECK_MODULES([SOFIA_SIP], [sofia-sip-ua >= 1.13.18],[ +PKG_CHECK_MODULES([SOFIA_SIP], [sofia-sip-ua >= 1.13.19],[ AM_CONDITIONAL([HAVE_SOFIA_SIP],[true])],[ AC_MSG_ERROR([no usable sofia-sip; please install sofia-sip-ua devel package or equivalent]) ]) diff --git a/debian/bootstrap.sh b/debian/bootstrap.sh index 7a376097cd..58fdd15cc7 100755 --- a/debian/bootstrap.sh +++ b/debian/bootstrap.sh @@ -317,7 +317,7 @@ Build-Depends: uuid-dev, libexpat1-dev, libgdbm-dev, libdb-dev, # used by many modules libcurl4-openssl-dev | libcurl4-gnutls-dev | libcurl-dev, - bison, zlib1g-dev, libsofia-sip-ua-dev (>= 1.13.18), + bison, zlib1g-dev, libsofia-sip-ua-dev (>= 1.13.19), libspandsp4-dev, # used to format the private freeswitch apt-repo key properly gnupg, @@ -356,7 +356,7 @@ Description: Cross-Platform Scalable Multi-Protocol Soft Switch Package: libfreeswitch1 Architecture: amd64 armhf arm64 -Depends: \${shlibs:Depends}, \${misc:Depends}, libsofia-sip-ua0 (>= 1.13.18) +Depends: \${shlibs:Depends}, \${misc:Depends}, libsofia-sip-ua0 (>= 1.13.19) Recommends: Suggests: libfreeswitch1-dbg Conflicts: freeswitch-all (<= 1.6.7) diff --git a/freeswitch.spec b/freeswitch.spec index 8c0597701d..d75619bbee 100755 --- a/freeswitch.spec +++ b/freeswitch.spec @@ -131,7 +131,7 @@ BuildRequires: curl-devel >= 7.19 BuildRequires: gcc-c++ BuildRequires: libtool >= 1.5.17 BuildRequires: openssl-devel >= 1.0.1e -BuildRequires: sofia-sip-devel >= 1.13.18 +BuildRequires: sofia-sip-devel >= 1.13.19 BuildRequires: spandsp4-devel >= 3.1.1 BuildRequires: pcre2-devel BuildRequires: speex-devel From d38da74dc74031099bbaac6e97f42e46f66b32e1 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 27 Oct 2026 23:58:56 +0300 Subject: [PATCH 35/88] [Build-System] Windows: Upgrade libks to v2.1.0_1 and signalwire-client-c to v2.0.5_4 (#3247) --- w32/libks-version.props | 4 ++-- w32/signalwire-client-c-version.props | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/w32/libks-version.props b/w32/libks-version.props index 88f74addc7..005fd47461 100644 --- a/w32/libks-version.props +++ b/w32/libks-version.props @@ -4,8 +4,8 @@ - 2.0.11 - 2 + 2.1.0 + 1 true diff --git a/w32/signalwire-client-c-version.props b/w32/signalwire-client-c-version.props index d92816be10..8f48e2d3fb 100644 --- a/w32/signalwire-client-c-version.props +++ b/w32/signalwire-client-c-version.props @@ -5,7 +5,7 @@ 2.0.5 - 3 + 4 true From ad4b9dcb9bac1270fa60f55149c79c0152a994ba Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 28 Oct 2026 14:48:33 +0300 Subject: [PATCH 36/88] [mod_v8, Build-System] Port to the V8 13.6 API of Node.js 24 libnode. Windows: Upgrade libnode to v24.22.1_1 and take it from windows-deps (#3249) --- src/mod/languages/mod_v8/Makefile.am | 2 +- .../languages/mod_v8/include/javascript.hpp | 39 +++++++++++-------- src/mod/languages/mod_v8/src/fsevent.cpp | 4 +- .../languages/mod_v8/src/fseventhandler.cpp | 2 +- src/mod/languages/mod_v8/src/fssession.cpp | 2 +- src/mod/languages/mod_v8/src/fsxml.cpp | 4 +- src/mod/languages/mod_v8/src/jsbase.cpp | 4 +- src/mod/languages/mod_v8/src/jsmain.cpp | 5 ++- w32/libnode-version.props | 3 +- w32/libnode.props | 25 ++++++------ 10 files changed, 50 insertions(+), 40 deletions(-) diff --git a/src/mod/languages/mod_v8/Makefile.am b/src/mod/languages/mod_v8/Makefile.am index bb14928ae9..743d073448 100644 --- a/src/mod/languages/mod_v8/Makefile.am +++ b/src/mod/languages/mod_v8/Makefile.am @@ -5,7 +5,7 @@ AUTOMAKE_OPTIONS += foreign MODNAME=mod_v8 AM_CFLAGS += -I. -I./include -I$(switch_srcdir)/src/mod/languages/mod_v8/include $(V8_CFLAGS) -AM_CPPFLAGS += -I. -I./include -I$(switch_srcdir)/src/mod/languages/mod_v8/include $(V8_CFLAGS) -std=c++17 +AM_CPPFLAGS += -I. -I./include -I$(switch_srcdir)/src/mod/languages/mod_v8/include $(V8_CFLAGS) -std=c++20 AM_LDFLAGS += -avoid-version -module -no-undefined -shared AM_LIBADD = $(switch_builddir)/libfreeswitch.la diff --git a/src/mod/languages/mod_v8/include/javascript.hpp b/src/mod/languages/mod_v8/include/javascript.hpp index 35d30ea570..769e2f7e68 100644 --- a/src/mod/languages/mod_v8/include/javascript.hpp +++ b/src/mod/languages/mod_v8/include/javascript.hpp @@ -205,7 +205,7 @@ static inline v8::Local js_stack_frame(v8::Local /* Macro for easy V8 "get property" callback definition */ #define JS_GET_PROPERTY_DEF(method_name, class_name) \ - static void method_name(v8::Local property, const v8::PropertyCallbackInfo& info)\ + static void method_name(v8::Local property, const v8::PropertyCallbackInfo& info)\ {\ JS_CHECK_SCRIPT_STATE();\ class_name *obj = JSBase::GetInstance(info.Holder());\ @@ -220,11 +220,11 @@ static inline v8::Local js_stack_frame(v8::Local info.GetReturnValue().Set(false);\ }\ }\ - void method_name##Impl(v8::Local property, const v8::PropertyCallbackInfo& info) + void method_name##Impl(v8::Local property, const v8::PropertyCallbackInfo& info) /* Macro for easy V8 "set property" callback definition */ #define JS_SET_PROPERTY_DEF(method_name, class_name) \ - static void method_name(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info)\ + static void method_name(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info)\ {\ JS_CHECK_SCRIPT_STATE();\ class_name *obj = JSBase::GetInstance(info.Holder());\ @@ -239,20 +239,20 @@ static inline v8::Local js_stack_frame(v8::Local /* A property setter's ReturnValue is void; V8 7+ rejects Set() on it. */\ }\ }\ - void method_name##Impl(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) + void method_name##Impl(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) /* Macro for easy V8 "function" callback definition */ #define JS_FUNCTION_DEF(method_name, class_name) \ static void method_name(const v8::FunctionCallbackInfo& info)\ {\ JS_CHECK_SCRIPT_STATE();\ - class_name *obj = JSBase::GetInstance(info.Holder());\ + class_name *obj = JSBase::GetInstance(info.This());\ if (obj) {\ obj->method_name##Impl(info);\ } else {\ int line;\ char *file = JSMain::GetStackInfo(info.GetIsolate(), &line);\ - JsUtf8Value str(info.Holder());\ + JsUtf8Value str(info.This());\ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "mod_v8", line, NULL, SWITCH_LOG_DEBUG, "No valid internal data available for %s when calling %s\n", *str ? *str : "[unknown]", #class_name "::" #method_name "()");\ free(file);\ info.GetReturnValue().Set(false);\ @@ -261,18 +261,18 @@ static inline v8::Local js_stack_frame(v8::Local void method_name##Impl(const v8::FunctionCallbackInfo& info) /* Macros for V8 callback implementations */ -#define JS_GET_PROPERTY_IMPL(method_name, class_name) void class_name::method_name##Impl(v8::Local property, const v8::PropertyCallbackInfo& info) -#define JS_SET_PROPERTY_IMPL(method_name, class_name) void class_name::method_name##Impl(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +#define JS_GET_PROPERTY_IMPL(method_name, class_name) void class_name::method_name##Impl(v8::Local property, const v8::PropertyCallbackInfo& info) +#define JS_SET_PROPERTY_IMPL(method_name, class_name) void class_name::method_name##Impl(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) #define JS_FUNCTION_IMPL(method_name, class_name) void class_name::method_name##Impl(const v8::FunctionCallbackInfo& info) /* Macros for V8 callback definitions (class static version) */ -#define JS_GET_PROPERTY_DEF_STATIC(method_name) static void method_name(v8::Local property, const v8::PropertyCallbackInfo& info) -#define JS_SET_PROPERTY_DEF_STATIC(method_name) static void method_name(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +#define JS_GET_PROPERTY_DEF_STATIC(method_name) static void method_name(v8::Local property, const v8::PropertyCallbackInfo& info) +#define JS_SET_PROPERTY_DEF_STATIC(method_name) static void method_name(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) #define JS_FUNCTION_DEF_STATIC(method_name) static void method_name(const v8::FunctionCallbackInfo& info) /* Macros for V8 callback implementations (class static version) */ -#define JS_GET_PROPERTY_IMPL_STATIC(method_name, class_name) void class_name::method_name(v8::Local property, const v8::PropertyCallbackInfo& info) -#define JS_SET_PROPERTY_IMPL_STATIC(method_name, class_name) void class_name::method_name(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +#define JS_GET_PROPERTY_IMPL_STATIC(method_name, class_name) void class_name::method_name(v8::Local property, const v8::PropertyCallbackInfo& info) +#define JS_SET_PROPERTY_IMPL_STATIC(method_name, class_name) void class_name::method_name(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) #define JS_FUNCTION_IMPL_STATIC(method_name, class_name) void class_name::method_name(const v8::FunctionCallbackInfo& info) /* Macro for basic script state check (to know if the script is being terminated), should be called before calling any callback actual code */ @@ -321,8 +321,8 @@ typedef struct { /* JS Property definition */ typedef struct { const char *name; /* Name of the property */ - v8::AccessorGetterCallback get; /* The property getter */ - v8::AccessorSetterCallback set; /* The property setter */ + v8::AccessorNameGetterCallback get; /* The property getter */ + v8::AccessorNameSetterCallback set; /* The property setter */ } js_property_t; /* JS Class definition */ @@ -395,13 +395,18 @@ public: template static T *GetInstance(const v8::FunctionCallbackInfo& info) { v8::HandleScope scope(info.GetIsolate()); - return GetInstance(info.Holder()); + return GetInstance(info.This()); } /* Get a JSBase instance from a JavaScript object */ template static T *GetInstance(const v8::Local& self) { - v8::Local val = self->GetInternalField(0); + /* Scripts can hand any object in here (as a receiver or an argument); only ours carry field 0 */ + if (self.IsEmpty() || self->InternalFieldCount() < 1) { + return NULL; + } + + v8::Local val = self->GetInternalField(0).As(); if (!val.IsEmpty() && val->IsExternal()) { v8::Local wrap = v8::Local::Cast(val); @@ -416,7 +421,7 @@ public: static v8::Local GetFunctionFromArg(v8::Isolate *isolate, const v8::Local& arg); /* Default JS setter callback, to be used for read only values */ - static void DefaultSetProperty(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + static void DefaultSetProperty(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); /* Get the name of the JavaScript class - must be overridden by the actual implementation */ virtual std::string GetJSClassName() = 0; diff --git a/src/mod/languages/mod_v8/src/fsevent.cpp b/src/mod/languages/mod_v8/src/fsevent.cpp index 745e238913..09640992e3 100644 --- a/src/mod/languages/mod_v8/src/fsevent.cpp +++ b/src/mod/languages/mod_v8/src/fsevent.cpp @@ -348,7 +348,7 @@ JS_EVENT_FUNCTION_IMPL_STATIC(Fire) { JS_CHECK_SCRIPT_STATE(); HandleScope handle_scope(info.GetIsolate()); - FSEvent *obj = JSBase::GetInstance(info.Holder()); + FSEvent *obj = JSBase::GetInstance(info.This()); if (obj && obj->_event) { switch_event_fire(&obj->_event); @@ -393,7 +393,7 @@ JS_EVENT_FUNCTION_IMPL_STATIC(Destroy) { JS_CHECK_SCRIPT_STATE(); HandleScope handle_scope(info.GetIsolate()); - FSEvent *obj = JSBase::GetInstance(info.Holder()); + FSEvent *obj = JSBase::GetInstance(info.This()); if (obj) { delete obj; diff --git a/src/mod/languages/mod_v8/src/fseventhandler.cpp b/src/mod/languages/mod_v8/src/fseventhandler.cpp index 2fa40bba8f..b7a0777ffd 100644 --- a/src/mod/languages/mod_v8/src/fseventhandler.cpp +++ b/src/mod/languages/mod_v8/src/fseventhandler.cpp @@ -572,7 +572,7 @@ JS_EVENTHANDLER_FUNCTION_IMPL_STATIC(Destroy) { JS_CHECK_SCRIPT_STATE(); - FSEventHandler *obj = JSBase::GetInstance(info.Holder()); + FSEventHandler *obj = JSBase::GetInstance(info.This()); if (obj) { delete obj; diff --git a/src/mod/languages/mod_v8/src/fssession.cpp b/src/mod/languages/mod_v8/src/fssession.cpp index c055cc3854..f478975507 100644 --- a/src/mod/languages/mod_v8/src/fssession.cpp +++ b/src/mod/languages/mod_v8/src/fssession.cpp @@ -1836,7 +1836,7 @@ JS_SESSION_FUNCTION_IMPL(Bridge) cb_state.jss_a = this; cb_state.jss_b = jss_b; - cb_state.session_obj_a.Reset(info.GetIsolate(), info.Holder()); + cb_state.session_obj_a.Reset(info.GetIsolate(), info.This()); cb_state.session_obj_b.Reset(info.GetIsolate(), obj_b); cb_state.session_state = this; cb_state.context.Reset(info.GetIsolate(), info.GetIsolate()->GetCurrentContext()); diff --git a/src/mod/languages/mod_v8/src/fsxml.cpp b/src/mod/languages/mod_v8/src/fsxml.cpp index 93de0547da..76a379bf15 100644 --- a/src/mod/languages/mod_v8/src/fsxml.cpp +++ b/src/mod/languages/mod_v8/src/fsxml.cpp @@ -129,7 +129,7 @@ Local FSXML::GetJSObjFromXMLObj(const switch_xml_t xml, const v8::Functio /* Create a new object if it wasn't found in the hash */ if ((newObj = new FSXML(info))) { if (_rootJSObject.IsEmpty()) { - newObj->_rootJSObject.Reset(info.GetIsolate(), info.Holder()); /* The caller is the owner */ + newObj->_rootJSObject.Reset(info.GetIsolate(), info.This()); /* The caller is the owner */ } else { newObj->_rootJSObject.Reset(info.GetIsolate(), _rootJSObject); /* The owner is stored in the persistent object */ } @@ -354,7 +354,7 @@ JS_XML_IMPL_STATIC(Remove) } delete obj; } else { - JsUtf8Value str(info.Holder()); + JsUtf8Value str(info.This()); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No valid internal data available for %s when calling FSXML::Remove()\n", *str ? *str : "[unknown]"); } } diff --git a/src/mod/languages/mod_v8/src/jsbase.cpp b/src/mod/languages/mod_v8/src/jsbase.cpp index 85df1715b7..f4ae4e3451 100644 --- a/src/mod/languages/mod_v8/src/jsbase.cpp +++ b/src/mod/languages/mod_v8/src/jsbase.cpp @@ -217,7 +217,7 @@ void JSBase::Register(Isolate *isolate, const js_class_definition_t *desc) // Add properties to the object for (int i = 0;; i++) { if (!desc->properties[i].get) break; - function->InstanceTemplate()->SetAccessor(js_new_string(isolate, desc->properties[i].name), desc->properties[i].get, desc->properties[i].set); + function->InstanceTemplate()->SetNativeDataProperty(js_new_string(isolate, desc->properties[i].name), desc->properties[i].get, desc->properties[i].set); } #if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5 @@ -287,7 +287,7 @@ Local JSBase::GetFunctionFromArg(Isolate *isolate, const Local& } } -void JSBase::DefaultSetProperty(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +void JSBase::DefaultSetProperty(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { info.GetIsolate()->ThrowException(js_new_string(info.GetIsolate(), "this property cannot be changed!")); } diff --git a/src/mod/languages/mod_v8/src/jsmain.cpp b/src/mod/languages/mod_v8/src/jsmain.cpp index 93662f68eb..fc4a8bf5cf 100644 --- a/src/mod/languages/mod_v8/src/jsmain.cpp +++ b/src/mod/languages/mod_v8/src/jsmain.cpp @@ -173,7 +173,9 @@ JSMain::~JSMain(void) if (forcedTerminationMessage) free(forcedTerminationMessage); if (forcedTerminationScriptFile) free(forcedTerminationScriptFile); - isolate->Dispose(); + if (isolate) { + isolate->Dispose(); + } } const string JSMain::GetExceptionInfo(Isolate* isolate, TryCatch* try_catch) @@ -471,7 +473,6 @@ void JSMain::Dispose() // Make sure to cleanup properly! #if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5 v8::Isolate::GetCurrent()->LowMemoryNotification(); - while (!v8::Isolate::GetCurrent()->IdleNotificationDeadline(0.500)) {} V8::Dispose(); #if V8_MAJOR_VERSION >= 10 /* ShutdownPlatform() became a deprecated alias for DisposePlatform() in diff --git a/w32/libnode-version.props b/w32/libnode-version.props index 1204ab2b59..2a7565207a 100644 --- a/w32/libnode-version.props +++ b/w32/libnode-version.props @@ -4,7 +4,8 @@ - 20.19.2 + 24.22.1 + 1 true diff --git a/w32/libnode.props b/w32/libnode.props index 35971bace2..afe68a0fbe 100644 --- a/w32/libnode.props +++ b/w32/libnode.props @@ -6,21 +6,21 @@ - $(BaseDir)libs\libnode-$(LibNodeVersion) + $(BaseDir)libs\libnode-$(LibNodeVersion)_$(LibNodeBuildNumber) - - @@ -68,11 +71,11 @@ `#if __cplusplus <= 201703L` fires even with /std:c++20. Set both here. --> stdcpp20 /Zc:__cplusplus %(AdditionalOptions) - $(SolutionDir)libs\libnode-$(LibNodeVersion)\include;$(SolutionDir)src\mod\languages\mod_v8;$(SolutionDir)src\mod\languages\mod_v8\include;%(AdditionalIncludeDirectories) + $(LibNodeDir)\include;$(SolutionDir)src\mod\languages\mod_v8;$(SolutionDir)src\mod\languages\mod_v8\include;%(AdditionalIncludeDirectories) USING_V8_SHARED;USING_V8_PLATFORM_SHARED;%(PreprocessorDefinitions) - $(SolutionDir)libs\libnode-$(LibNodeVersion)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LibNodeDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) libnode.lib;%(AdditionalDependencies) From 9fdd2cdfaf3662740fbac6a406cc7c451c7ec0b4 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 28 Oct 2026 18:27:37 +0300 Subject: [PATCH 37/88] [mod_av] Add support for FFmpeg 8 (#3250) --- src/mod/applications/mod_av/avcodec.c | 17 ++++++++++---- src/mod/applications/mod_av/avformat.c | 32 ++++++++++++++++++-------- src/mod/applications/mod_av/mod_av.h | 1 + 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/mod/applications/mod_av/avcodec.c b/src/mod/applications/mod_av/avcodec.c index a9d449b562..20f9abe719 100644 --- a/src/mod/applications/mod_av/avcodec.c +++ b/src/mod/applications/mod_av/avcodec.c @@ -42,6 +42,13 @@ #include #include +/* AV_PROFILE_* replaced FF_PROFILE_* in FFmpeg 6.1, FFmpeg 8 removed the latter */ +#ifndef AV_PROFILE_H264_BASELINE +#define AV_PROFILE_H264_BASELINE FF_PROFILE_H264_BASELINE +#define AV_PROFILE_H264_MAIN FF_PROFILE_H264_MAIN +#define AV_PROFILE_H264_HIGH FF_PROFILE_H264_HIGH +#endif + int SLICE_SIZE = (SWITCH_DEFAULT_VIDEO_SIZE + 100); #define H264_NALU_BUFFER_SIZE 65536 @@ -530,7 +537,7 @@ static void init_profile(avcodec_profile_t *aprofile, const char *name) aprofile->decoder_thread_count = avcodec_globals.dec_threads; if (!strcasecmp(name, "H264")) { - aprofile->ctx.profile = FF_PROFILE_H264_BASELINE; + aprofile->ctx.profile = AV_PROFILE_H264_BASELINE; aprofile->ctx.level = 31; #ifdef AV_CODEC_FLAG_PSNR aprofile->ctx.flags |= AV_CODEC_FLAG_PSNR; @@ -2071,7 +2078,7 @@ static void parse_profile(avcodec_profile_t *aprofile, switch_xml_t profile) ctx = &aprofile->ctx; - ctx->profile = FF_PROFILE_H264_BASELINE; + ctx->profile = AV_PROFILE_H264_BASELINE; ctx->level = 31; for (param = switch_xml_child(profile, "param"); param; param = param->next) { @@ -2094,11 +2101,11 @@ static void parse_profile(avcodec_profile_t *aprofile, switch_xml_t profile) if (ctx->profile == 0 && !strcasecmp(aprofile->name, "H264")) { if (!strcasecmp(value, "baseline")) { - ctx->profile = FF_PROFILE_H264_BASELINE; + ctx->profile = AV_PROFILE_H264_BASELINE; } else if (!strcasecmp(value, "main")) { - ctx->profile = FF_PROFILE_H264_MAIN; + ctx->profile = AV_PROFILE_H264_MAIN; } else if (!strcasecmp(value, "high")) { - ctx->profile = FF_PROFILE_H264_HIGH; + ctx->profile = AV_PROFILE_H264_HIGH; } } } else if (!strcmp(name, "level")) { diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index d617a52dfe..92ec9ed9cf 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -281,6 +281,24 @@ GCC_DIAG_ON(deprecated-declarations) #endif } +static inline int av_get_ticks_per_frame(AVCodecContext *c) +{ +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_8_V) + int ticks; + +GCC_DIAG_OFF(deprecated-declarations) + ticks = c->ticks_per_frame; +GCC_DIAG_ON(deprecated-declarations) + + return ticks; +#else + /* FFmpeg 8 removed ticks_per_frame, which decoders of field based codecs set to 2 */ + const AVCodecDescriptor *desc = avcodec_descriptor_get(c->codec_id); + + return (desc && (desc->props & AV_CODEC_PROP_FIELDS)) ? 2 : 1; +#endif +} + static char *const get_error_text(const int error, char *error_buffer, switch_size_t error_buflen) { av_strerror(error, error_buffer, error_buflen); @@ -637,12 +655,14 @@ static switch_status_t add_stream(av_file_context_t *context, MediaStream *mst, c->rc_initial_buffer_occupancy = buffer_bytes * 8; if (codec_id == AV_CODEC_ID_H264) { +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVCODEC_8_V) /* FFmpeg 8 removed ticks_per_frame */ #if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) GCC_DIAG_OFF(deprecated-declarations) #endif c->ticks_per_frame = 2; #if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) GCC_DIAG_ON(deprecated-declarations) +#endif #endif c->flags|=AV_CODEC_FLAG_LOOP_FILTER; // flags=+loop @@ -1431,7 +1451,7 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h switch_goto_status(SWITCH_STATUS_FALSE, err); } -#if (LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) +#if (LIBAVFORMAT_VERSION_MAJOR >= LIBAVFORMAT_7_V) handle->seekable = !(context->fc->iformat->flags & AVFMT_NOTIMESTAMPS); #else handle->seekable = context->fc->iformat->read_seek2 ? 1 : (context->fc->iformat->read_seek ? 1 : 0); @@ -3240,21 +3260,15 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f if ((c = av_get_codec_context(mst)) && c->time_base.num) { cp = av_stream_get_parser(st); -#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) -GCC_DIAG_OFF(deprecated-declarations) -#endif - ticks = cp ? cp->repeat_pict + 1 : c->ticks_per_frame; + ticks = cp ? cp->repeat_pict + 1 : av_get_ticks_per_frame(c); // mst->next_pts += ((int64_t)AV_TIME_BASE * st->codec->time_base.num * ticks) / st->codec->time_base.den; } if (!context->video_start_time) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "start: %" SWITCH_INT64_T_FMT " ticks: %d ticks_per_frame: %d st num:%d st den:%d codec num:%d codec den:%d start: %" SWITCH_TIME_T_FMT ", duration:%" SWITCH_INT64_T_FMT " nb_frames:%" SWITCH_INT64_T_FMT " q2d:%f\n", - context->video_start_time, ticks, c ? c->ticks_per_frame : -1, st->time_base.num, st->time_base.den, c ? c->time_base.num : -1, c ? c->time_base.den : -1, + context->video_start_time, ticks, c ? av_get_ticks_per_frame(c) : -1, st->time_base.num, st->time_base.den, c ? c->time_base.num : -1, c ? c->time_base.den : -1, st->start_time, st->duration == AV_NOPTS_VALUE ? context->fc->duration / AV_TIME_BASE * 1000 : st->duration, st->nb_frames, av_q2d(st->time_base)); } -#if ((LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_6_V && LIBAVFORMAT_VERSION_MINOR >= LIBAVFORMAT_61_V) || LIBAVFORMAT_VERSION_MAJOR == LIBAVFORMAT_7_V) -GCC_DIAG_ON(deprecated-declarations) -#endif again: diff --git a/src/mod/applications/mod_av/mod_av.h b/src/mod/applications/mod_av/mod_av.h index 8152a77a81..92a6caaaa3 100644 --- a/src/mod/applications/mod_av/mod_av.h +++ b/src/mod/applications/mod_av/mod_av.h @@ -43,6 +43,7 @@ #define LIBAVCODEC_V 59 /* FFmpeg version >= 5.1 */ #define LIBAVCODEC_6_V 60 /* FFmpeg version >= 6.0 */ #define LIBAVCODEC_7_V 61 /* FFmpeg version >= 7.0 */ +#define LIBAVCODEC_8_V 62 /* FFmpeg version >= 8.0 */ #define LIBAVCODEC_61_V 31 /* FFmpeg version >= 6.1 */ #define LIBAVFORMAT_V 59 /* FFmpeg version >= 5.1 */ #define LIBAVFORMAT_6_V 60 /* FFmpeg version >= 6.0 */ From f37a27f2f47ff965b90e4d4080ecbcf292c916b1 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 28 Oct 2026 22:03:59 +0300 Subject: [PATCH 38/88] [Build-System] Windows: Upgrade FFmpeg to v8.1.3_1 and openh264 to 2.7.0, take FFmpeg from windows-deps (#3251) --- .../Setup.CA.DownloadOpenH264/CustomAction.cs | 2 +- w32/download_openh264.props | 2 +- w32/ffmpeg-version.props | 3 ++- w32/ffmpeg.props | 9 +++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/w32/Setup/CustomActions/Setup.CA.DownloadOpenH264/CustomAction.cs b/w32/Setup/CustomActions/Setup.CA.DownloadOpenH264/CustomAction.cs index fcab4445c4..89ab930c1a 100644 --- a/w32/Setup/CustomActions/Setup.CA.DownloadOpenH264/CustomAction.cs +++ b/w32/Setup/CustomActions/Setup.CA.DownloadOpenH264/CustomAction.cs @@ -19,7 +19,7 @@ namespace Setup.CA.DownloadOpenH264 try { - WebRequest request = HttpWebRequest.Create("http://ciscobinary.openh264.org/openh264-1.8.0-win64.dll.bz2"); + WebRequest request = HttpWebRequest.Create("http://ciscobinary.openh264.org/openh264-2.7.0-win64.dll.bz2"); using (WebResponse response = request.GetResponse()) { diff --git a/w32/download_openh264.props b/w32/download_openh264.props index 1e5d7d7e19..c2d504ecf1 100644 --- a/w32/download_openh264.props +++ b/w32/download_openh264.props @@ -33,7 +33,7 @@ - 7.1.5 + 8.1.3 + 1 true diff --git a/w32/ffmpeg.props b/w32/ffmpeg.props index 39dec685b4..72a2365dde 100644 --- a/w32/ffmpeg.props +++ b/w32/ffmpeg.props @@ -17,15 +17,16 @@ $([System.Text.RegularExpressions.Regex]::Replace('$(Configuration)', '-.*$', '')) $([System.Text.RegularExpressions.Regex]::Replace('$(Configuration)', '^.*-', '')) - $(BaseDir)libs\ffmpeg-$(ffmpegVersion) + ffmpeg-$(ffmpegVersion)_$(ffmpegBuildNumber) + $(BaseDir)libs\$(ffmpegPkg) $(ffmpegDir)\binaries\$(ffmpegVariant)\$(Platform)\$(ffmpegConfigName) - https://github.com/freeswitch/ffmpeg-packaging/releases/download/ffmpeg-v$(ffmpegVersion) + https://github.com/freeswitch/windows-deps/releases/download/ffmpeg-v$(ffmpegVersion)_$(ffmpegBuildNumber) Date: Mon, 9 Nov 2026 15:34:10 +0100 Subject: [PATCH 39/88] [GHA] Pin `ubuntu-24.04` as unit-test runner (#3272) --- .github/workflows/unit-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 5e414ab835..6cf6f24c97 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -39,7 +39,7 @@ on: jobs: unit-test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 container: image: ${{ inputs.container-image }} options: --privileged From 209e98e9af512e798aae548947623257c00a330c Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 9 Nov 2026 19:11:13 +0300 Subject: [PATCH 40/88] [Build-System] Windows: Upgrade signalwire-client-c to v2.0.6_1 (#3271) --- w32/signalwire-client-c-version.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/w32/signalwire-client-c-version.props b/w32/signalwire-client-c-version.props index 8f48e2d3fb..f2b8b5ada1 100644 --- a/w32/signalwire-client-c-version.props +++ b/w32/signalwire-client-c-version.props @@ -4,8 +4,8 @@ - 2.0.5 - 4 + 2.0.6 + 1 true From 6383a78dd2763edaf1b7941862c7a569921694b6 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 9 Nov 2026 20:17:18 +0300 Subject: [PATCH 41/88] [Core] scan-build: switch_cache_db_type_name(). Value stored to 'type_str' during its initialization is never read (#3273) --- src/include/switch_core.h | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 40f126a818..887c4d4241 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -2625,27 +2625,16 @@ typedef struct switch_cache_db_handle switch_cache_db_handle_t; static inline const char *switch_cache_db_type_name(switch_cache_db_handle_type_t type) { - const char *type_str = "INVALID"; - switch (type) { case SCDB_TYPE_DATABASE_INTERFACE: - { - type_str = "DATABASE_INTERFACE"; - } - break; + return "DATABASE_INTERFACE"; case SCDB_TYPE_ODBC: - { - type_str = "ODBC"; - } - break; + return "ODBC"; case SCDB_TYPE_CORE_DB: - { - type_str = "CORE_DB"; - } - break; + return "CORE_DB"; + default: + return "INVALID"; } - - return type_str; } SWITCH_DECLARE(switch_cache_db_handle_type_t) switch_cache_db_get_type(switch_cache_db_handle_t *dbh); From 4b4d3612670c5f4cb849bfdae17793f7dcff4d46 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 9 Nov 2026 20:42:59 +0300 Subject: [PATCH 42/88] [libscgi] Scan-build: Fix function call (recv) with invalid argument (#3274) --- libs/libscgi/src/scgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/libscgi/src/scgi.c b/libs/libscgi/src/scgi.c index 9da34ff6d7..7b2864b86f 100644 --- a/libs/libscgi/src/scgi.c +++ b/libs/libscgi/src/scgi.c @@ -657,7 +657,7 @@ SCGI_DECLARE(scgi_status_t) scgi_parse(scgi_socket_t sock, scgi_handle_t *handle handle->sock = sock; handle->connected = 1; - sock_setup(handle); + if (sock_setup(handle) != SCGI_SUCCESS) goto end; for(;;) { From 75366730ac5c65c462e094466fc2f3dc6d49e437 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 9 Nov 2026 21:08:00 +0300 Subject: [PATCH 43/88] [SWIG] Generated files contain Dead initialization. Overload affected methods to avoid that. (#3275) --- src/include/switch_cpp.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/include/switch_cpp.h b/src/include/switch_cpp.h index 5fd21fc55b..40473f0cb7 100644 --- a/src/include/switch_cpp.h +++ b/src/include/switch_cpp.h @@ -193,9 +193,13 @@ SWITCH_DECLARE(bool) email(char *to, char *from, char *headers = NULL, char *bod switch_event_node_t *enodes[SWITCH_EVENT_ALL + 1]; uint32_t node_index; - SWITCH_DECLARE_CONSTRUCTOR EventConsumer(const char *event_name = NULL, const char *subclass_name = "", int len = 5000); + SWITCH_DECLARE_CONSTRUCTOR EventConsumer(const char *event_name, const char *subclass_name, int len); + inline EventConsumer(const char *event_name, const char *subclass_name) : EventConsumer(event_name, subclass_name, 5000) {} + inline EventConsumer(const char *event_name) : EventConsumer(event_name, "", 5000) {} + inline EventConsumer() : EventConsumer(NULL, "", 5000) {} SWITCH_DECLARE_CONSTRUCTOR ~ EventConsumer(); - SWITCH_DECLARE(int) bind(const char *event_name, const char *subclass_name = ""); + SWITCH_DECLARE(int) bind(const char *event_name, const char *subclass_name); + inline int bind(const char *event_name) { return bind(event_name, ""); } SWITCH_DECLARE(Event *) pop(int block = 0, int timeout = 0); SWITCH_DECLARE(void) cleanup(); }; @@ -238,7 +242,8 @@ SWITCH_DECLARE(bool) email(char *to, char *from, char *headers = NULL, char *bod SWITCH_DECLARE(int) answer(); SWITCH_DECLARE(int) print(char *txt); SWITCH_DECLARE(int) preAnswer(); - SWITCH_DECLARE(void) hangup(const char *cause = "normal_clearing"); + SWITCH_DECLARE(void) hangup(const char *cause); + inline void hangup() { hangup("normal_clearing"); } SWITCH_DECLARE(void) hangupState(void); SWITCH_DECLARE(void) setVariable(char *var, char *val); SWITCH_DECLARE(void) setPrivate(char *var, void *val); @@ -247,7 +252,9 @@ SWITCH_DECLARE(bool) email(char *to, char *from, char *headers = NULL, char *bod SWITCH_DECLARE(switch_status_t) process_callback_result(char *result); SWITCH_DECLARE(void) say(const char *tosay, const char *module_name, const char *say_type, const char *say_method, const char *say_gender = NULL); - SWITCH_DECLARE(void) sayPhrase(const char *phrase_name, const char *phrase_data = "", const char *phrase_lang = NULL); + SWITCH_DECLARE(void) sayPhrase(const char *phrase_name, const char *phrase_data, const char *phrase_lang); + inline void sayPhrase(const char *phrase_name, const char *phrase_data) { sayPhrase(phrase_name, phrase_data, NULL); } + inline void sayPhrase(const char *phrase_name) { sayPhrase(phrase_name, "", NULL); } SWITCH_DECLARE(const char *) hangupCause(); SWITCH_DECLARE(const char *) getState(); From 9c48aa3f059b5209db6bbc7dba6218117d7f2330 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 9 Nov 2026 21:36:23 +0300 Subject: [PATCH 44/88] swigall (#3276) --- .../src/org/freeswitch/swig/CoreSession.java | 16 +- .../org/freeswitch/swig/EventConsumer.java | 20 +- .../org/freeswitch/swig/freeswitchJNI.java | 15 +- .../languages/mod_java/switch_swig_wrap.cpp | 155 +++- src/mod/languages/mod_lua/mod_lua_wrap.cpp | 497 +++++++++++- .../languages/mod_managed/freeswitch_wrap.cxx | 102 ++- src/mod/languages/mod_managed/managed/swig.cs | 71 +- src/mod/languages/mod_perl/mod_perl_wrap.cpp | 749 ++++++++++++++++-- .../languages/mod_python3/mod_python_wrap.cpp | 522 ++++++++++-- 9 files changed, 1942 insertions(+), 205 deletions(-) diff --git a/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java b/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java index 28036acb5f..4b56da9bf7 100644 --- a/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java +++ b/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java @@ -148,7 +148,11 @@ public class CoreSession { } public void hangup(String cause) { - freeswitchJNI.CoreSession_hangup(swigCPtr, this, cause); + freeswitchJNI.CoreSession_hangup__SWIG_0(swigCPtr, this, cause); + } + + public void hangup() { + freeswitchJNI.CoreSession_hangup__SWIG_1(swigCPtr, this); } public void hangupState() { @@ -181,7 +185,15 @@ public class CoreSession { } public void sayPhrase(String phrase_name, String phrase_data, String phrase_lang) { - freeswitchJNI.CoreSession_sayPhrase(swigCPtr, this, phrase_name, phrase_data, phrase_lang); + freeswitchJNI.CoreSession_sayPhrase__SWIG_0(swigCPtr, this, phrase_name, phrase_data, phrase_lang); + } + + public void sayPhrase(String phrase_name, String phrase_data) { + freeswitchJNI.CoreSession_sayPhrase__SWIG_1(swigCPtr, this, phrase_name, phrase_data); + } + + public void sayPhrase(String phrase_name) { + freeswitchJNI.CoreSession_sayPhrase__SWIG_2(swigCPtr, this, phrase_name); } public String hangupCause() { diff --git a/src/mod/languages/mod_java/src/org/freeswitch/swig/EventConsumer.java b/src/mod/languages/mod_java/src/org/freeswitch/swig/EventConsumer.java index 86d8cdad06..f06f4e1d6e 100644 --- a/src/mod/languages/mod_java/src/org/freeswitch/swig/EventConsumer.java +++ b/src/mod/languages/mod_java/src/org/freeswitch/swig/EventConsumer.java @@ -107,11 +107,27 @@ public class EventConsumer { } public EventConsumer(String event_name, String subclass_name, int len) { - this(freeswitchJNI.new_EventConsumer(event_name, subclass_name, len), true); + this(freeswitchJNI.new_EventConsumer__SWIG_0(event_name, subclass_name, len), true); + } + + public EventConsumer(String event_name, String subclass_name) { + this(freeswitchJNI.new_EventConsumer__SWIG_1(event_name, subclass_name), true); + } + + public EventConsumer(String event_name) { + this(freeswitchJNI.new_EventConsumer__SWIG_2(event_name), true); + } + + public EventConsumer() { + this(freeswitchJNI.new_EventConsumer__SWIG_3(), true); } public int bind(String event_name, String subclass_name) { - return freeswitchJNI.EventConsumer_bind(swigCPtr, this, event_name, subclass_name); + return freeswitchJNI.EventConsumer_bind__SWIG_0(swigCPtr, this, event_name, subclass_name); + } + + public int bind(String event_name) { + return freeswitchJNI.EventConsumer_bind__SWIG_1(swigCPtr, this, event_name); } public Event pop(int block, int timeout) { diff --git a/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java b/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java index 301d949845..814f49dc6c 100644 --- a/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java +++ b/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java @@ -86,9 +86,13 @@ public class freeswitchJNI { public final static native long EventConsumer_enodes_get(long jarg1, EventConsumer jarg1_); public final static native void EventConsumer_node_index_set(long jarg1, EventConsumer jarg1_, long jarg2); public final static native long EventConsumer_node_index_get(long jarg1, EventConsumer jarg1_); - public final static native long new_EventConsumer(String jarg1, String jarg2, int jarg3); + public final static native long new_EventConsumer__SWIG_0(String jarg1, String jarg2, int jarg3); + public final static native long new_EventConsumer__SWIG_1(String jarg1, String jarg2); + public final static native long new_EventConsumer__SWIG_2(String jarg1); + public final static native long new_EventConsumer__SWIG_3(); public final static native void delete_EventConsumer(long jarg1); - public final static native int EventConsumer_bind(long jarg1, EventConsumer jarg1_, String jarg2, String jarg3); + public final static native int EventConsumer_bind__SWIG_0(long jarg1, EventConsumer jarg1_, String jarg2, String jarg3); + public final static native int EventConsumer_bind__SWIG_1(long jarg1, EventConsumer jarg1_, String jarg2); public final static native long EventConsumer_pop(long jarg1, EventConsumer jarg1_, int jarg2, int jarg3); public final static native void EventConsumer_cleanup(long jarg1, EventConsumer jarg1_); public final static native void delete_CoreSession(long jarg1); @@ -116,7 +120,8 @@ public class freeswitchJNI { public final static native int CoreSession_answer(long jarg1, CoreSession jarg1_); public final static native int CoreSession_print(long jarg1, CoreSession jarg1_, String jarg2); public final static native int CoreSession_preAnswer(long jarg1, CoreSession jarg1_); - public final static native void CoreSession_hangup(long jarg1, CoreSession jarg1_, String jarg2); + public final static native void CoreSession_hangup__SWIG_0(long jarg1, CoreSession jarg1_, String jarg2); + public final static native void CoreSession_hangup__SWIG_1(long jarg1, CoreSession jarg1_); public final static native void CoreSession_hangupState(long jarg1, CoreSession jarg1_); public final static native void CoreSession_setVariable(long jarg1, CoreSession jarg1_, String jarg2, String jarg3); public final static native void CoreSession_setPrivate(long jarg1, CoreSession jarg1_, String jarg2, long jarg3); @@ -124,7 +129,9 @@ public class freeswitchJNI { public final static native String CoreSession_getVariable(long jarg1, CoreSession jarg1_, String jarg2); public final static native long CoreSession_process_callback_result(long jarg1, CoreSession jarg1_, String jarg2); public final static native void CoreSession_say(long jarg1, CoreSession jarg1_, String jarg2, String jarg3, String jarg4, String jarg5, String jarg6); - public final static native void CoreSession_sayPhrase(long jarg1, CoreSession jarg1_, String jarg2, String jarg3, String jarg4); + public final static native void CoreSession_sayPhrase__SWIG_0(long jarg1, CoreSession jarg1_, String jarg2, String jarg3, String jarg4); + public final static native void CoreSession_sayPhrase__SWIG_1(long jarg1, CoreSession jarg1_, String jarg2, String jarg3); + public final static native void CoreSession_sayPhrase__SWIG_2(long jarg1, CoreSession jarg1_, String jarg2); public final static native String CoreSession_hangupCause(long jarg1, CoreSession jarg1_); public final static native String CoreSession_getState(long jarg1, CoreSession jarg1_); public final static native int CoreSession_recordFile(long jarg1, CoreSession jarg1_, String jarg2, int jarg3, int jarg4, int jarg5); diff --git a/src/mod/languages/mod_java/switch_swig_wrap.cpp b/src/mod/languages/mod_java/switch_swig_wrap.cpp index 8a4bc664bd..09f4ffdfb3 100644 --- a/src/mod/languages/mod_java/switch_swig_wrap.cpp +++ b/src/mod/languages/mod_java/switch_swig_wrap.cpp @@ -1733,11 +1733,11 @@ SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1n } -SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1EventConsumer(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2, jint jarg3) { +SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1EventConsumer_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2, jint jarg3) { jlong jresult = 0 ; - char *arg1 = (char *) NULL ; - char *arg2 = (char *) "" ; - int arg3 = (int) 5000 ; + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; EventConsumer *result = 0 ; (void)jenv; @@ -1761,6 +1761,63 @@ SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1EventConsum } +SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1EventConsumer_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2) { + jlong jresult = 0 ; + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + EventConsumer *result = 0 ; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)jenv->GetStringUTFChars(jarg1, 0); + if (!arg1) return 0; + } + arg2 = 0; + if (jarg2) { + arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0); + if (!arg2) return 0; + } + result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2); + *(EventConsumer **)&jresult = result; + if (arg1) jenv->ReleaseStringUTFChars(jarg1, (const char *)arg1); + if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2); + return jresult; +} + + +SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1EventConsumer_1_1SWIG_12(JNIEnv *jenv, jclass jcls, jstring jarg1) { + jlong jresult = 0 ; + char *arg1 = (char *) 0 ; + EventConsumer *result = 0 ; + + (void)jenv; + (void)jcls; + arg1 = 0; + if (jarg1) { + arg1 = (char *)jenv->GetStringUTFChars(jarg1, 0); + if (!arg1) return 0; + } + result = (EventConsumer *)new EventConsumer((char const *)arg1); + *(EventConsumer **)&jresult = result; + if (arg1) jenv->ReleaseStringUTFChars(jarg1, (const char *)arg1); + return jresult; +} + + +SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1EventConsumer_1_1SWIG_13(JNIEnv *jenv, jclass jcls) { + jlong jresult = 0 ; + EventConsumer *result = 0 ; + + (void)jenv; + (void)jcls; + result = (EventConsumer *)new EventConsumer(); + *(EventConsumer **)&jresult = result; + return jresult; +} + + SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_delete_1EventConsumer(JNIEnv *jenv, jclass jcls, jlong jarg1) { EventConsumer *arg1 = (EventConsumer *) 0 ; @@ -1771,11 +1828,11 @@ SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_delete_1EventCons } -SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1bind(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jstring jarg3) { +SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1bind_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jstring jarg3) { jint jresult = 0 ; EventConsumer *arg1 = (EventConsumer *) 0 ; char *arg2 = (char *) 0 ; - char *arg3 = (char *) "" ; + char *arg3 = (char *) 0 ; int result; (void)jenv; @@ -1800,6 +1857,28 @@ SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1bi } +SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1bind_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) { + jint jresult = 0 ; + EventConsumer *arg1 = (EventConsumer *) 0 ; + char *arg2 = (char *) 0 ; + int result; + + (void)jenv; + (void)jcls; + (void)jarg1_; + arg1 = *(EventConsumer **)&jarg1; + arg2 = 0; + if (jarg2) { + arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0); + if (!arg2) return 0; + } + result = (int)(arg1)->bind((char const *)arg2); + jresult = (jint)result; + if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2); + return jresult; +} + + SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1pop(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2, jint jarg3) { jlong jresult = 0 ; EventConsumer *arg1 = (EventConsumer *) 0 ; @@ -2255,9 +2334,9 @@ SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1preA } -SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1hangup(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) { +SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1hangup_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) { CoreSession *arg1 = (CoreSession *) 0 ; - char *arg2 = (char *) "normal_clearing" ; + char *arg2 = (char *) 0 ; (void)jenv; (void)jcls; @@ -2273,6 +2352,17 @@ SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1hang } +SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1hangup_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { + CoreSession *arg1 = (CoreSession *) 0 ; + + (void)jenv; + (void)jcls; + (void)jarg1_; + arg1 = *(CoreSession **)&jarg1; + (arg1)->hangup(); +} + + SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1hangupState(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { CoreSession *arg1 = (CoreSession *) 0 ; @@ -2441,11 +2531,11 @@ SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1say( } -SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1sayPhrase(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jstring jarg3, jstring jarg4) { +SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1sayPhrase_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jstring jarg3, jstring jarg4) { CoreSession *arg1 = (CoreSession *) 0 ; char *arg2 = (char *) 0 ; - char *arg3 = (char *) "" ; - char *arg4 = (char *) NULL ; + char *arg3 = (char *) 0 ; + char *arg4 = (char *) 0 ; (void)jenv; (void)jcls; @@ -2473,6 +2563,49 @@ SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1sayP } +SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1sayPhrase_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jstring jarg3) { + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + + (void)jenv; + (void)jcls; + (void)jarg1_; + arg1 = *(CoreSession **)&jarg1; + arg2 = 0; + if (jarg2) { + arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0); + if (!arg2) return ; + } + arg3 = 0; + if (jarg3) { + arg3 = (char *)jenv->GetStringUTFChars(jarg3, 0); + if (!arg3) return ; + } + (arg1)->sayPhrase((char const *)arg2,(char const *)arg3); + if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2); + if (arg3) jenv->ReleaseStringUTFChars(jarg3, (const char *)arg3); +} + + +SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1sayPhrase_1_1SWIG_12(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) { + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + + (void)jenv; + (void)jcls; + (void)jarg1_; + arg1 = *(CoreSession **)&jarg1; + arg2 = 0; + if (jarg2) { + arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0); + if (!arg2) return ; + } + (arg1)->sayPhrase((char const *)arg2); + if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2); +} + + SWIGEXPORT jstring JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1hangupCause(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { jstring jresult = 0 ; CoreSession *arg1 = (CoreSession *) 0 ; diff --git a/src/mod/languages/mod_lua/mod_lua_wrap.cpp b/src/mod/languages/mod_lua/mod_lua_wrap.cpp index c82d4fc373..1be04729c7 100644 --- a/src/mod/languages/mod_lua/mod_lua_wrap.cpp +++ b/src/mod/languages/mod_lua/mod_lua_wrap.cpp @@ -5525,27 +5525,21 @@ static int _wrap_EventConsumer_node_index_get(lua_State* L) { } -static int _wrap_new_EventConsumer(lua_State* L) { +static int _wrap_new_EventConsumer__SWIG_0(lua_State* L) { { int SWIG_arg = 0; - char *arg1 = (char *) NULL ; - char *arg2 = (char *) "" ; - int arg3 = (int) 5000 ; + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; EventConsumer *result = 0 ; - SWIG_check_num_args("EventConsumer::EventConsumer",0,3) - if(lua_gettop(L)>=1 && !SWIG_lua_isnilstring(L,1)) SWIG_fail_arg("EventConsumer::EventConsumer",1,"char const *"); - if(lua_gettop(L)>=2 && !SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("EventConsumer::EventConsumer",2,"char const *"); - if(lua_gettop(L)>=3 && !lua_isnumber(L,3)) SWIG_fail_arg("EventConsumer::EventConsumer",3,"int"); - if(lua_gettop(L)>=1){ - arg1 = (char *)lua_tostring(L, 1); - } - if(lua_gettop(L)>=2){ - arg2 = (char *)lua_tostring(L, 2); - } - if(lua_gettop(L)>=3){ - arg3 = (int)lua_tonumber(L, 3); - } + SWIG_check_num_args("EventConsumer::EventConsumer",3,3) + if(!SWIG_lua_isnilstring(L,1)) SWIG_fail_arg("EventConsumer::EventConsumer",1,"char const *"); + if(!SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("EventConsumer::EventConsumer",2,"char const *"); + if(!lua_isnumber(L,3)) SWIG_fail_arg("EventConsumer::EventConsumer",3,"int"); + arg1 = (char *)lua_tostring(L, 1); + arg2 = (char *)lua_tostring(L, 2); + arg3 = (int)lua_tonumber(L, 3); result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2,arg3); SWIG_NewPointerObj(L,result,SWIGTYPE_p_EventConsumer,1); SWIG_arg++; return SWIG_arg; @@ -5557,27 +5551,148 @@ static int _wrap_new_EventConsumer(lua_State* L) { } -static int _wrap_EventConsumer_bind(lua_State* L) { +static int _wrap_new_EventConsumer__SWIG_1(lua_State* L) { + { + int SWIG_arg = 0; + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + EventConsumer *result = 0 ; + + SWIG_check_num_args("EventConsumer::EventConsumer",2,2) + if(!SWIG_lua_isnilstring(L,1)) SWIG_fail_arg("EventConsumer::EventConsumer",1,"char const *"); + if(!SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("EventConsumer::EventConsumer",2,"char const *"); + arg1 = (char *)lua_tostring(L, 1); + arg2 = (char *)lua_tostring(L, 2); + result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2); + SWIG_NewPointerObj(L,result,SWIGTYPE_p_EventConsumer,1); SWIG_arg++; + return SWIG_arg; + + fail: SWIGUNUSED; + } + lua_error(L); + return 0; +} + + +static int _wrap_new_EventConsumer__SWIG_2(lua_State* L) { + { + int SWIG_arg = 0; + char *arg1 = (char *) 0 ; + EventConsumer *result = 0 ; + + SWIG_check_num_args("EventConsumer::EventConsumer",1,1) + if(!SWIG_lua_isnilstring(L,1)) SWIG_fail_arg("EventConsumer::EventConsumer",1,"char const *"); + arg1 = (char *)lua_tostring(L, 1); + result = (EventConsumer *)new EventConsumer((char const *)arg1); + SWIG_NewPointerObj(L,result,SWIGTYPE_p_EventConsumer,1); SWIG_arg++; + return SWIG_arg; + + fail: SWIGUNUSED; + } + lua_error(L); + return 0; +} + + +static int _wrap_new_EventConsumer__SWIG_3(lua_State* L) { + { + int SWIG_arg = 0; + EventConsumer *result = 0 ; + + SWIG_check_num_args("EventConsumer::EventConsumer",0,0) + result = (EventConsumer *)new EventConsumer(); + SWIG_NewPointerObj(L,result,SWIGTYPE_p_EventConsumer,1); SWIG_arg++; + return SWIG_arg; + + fail: SWIGUNUSED; + } + lua_error(L); + return 0; +} + + +static int _wrap_new_EventConsumer(lua_State* L) { + int argc; + int argv[4]={ + 1,2,3,4 + }; + + argc = lua_gettop(L); + if (argc == 0) { + return _wrap_new_EventConsumer__SWIG_3(L); + } + if (argc == 1) { + int _v = 0; + { + _v = SWIG_lua_isnilstring(L,argv[0]); + } + if (_v) { + return _wrap_new_EventConsumer__SWIG_2(L); + } + } + if (argc == 2) { + int _v = 0; + { + _v = SWIG_lua_isnilstring(L,argv[0]); + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[1]); + } + if (_v) { + return _wrap_new_EventConsumer__SWIG_1(L); + } + } + } + if (argc == 3) { + int _v = 0; + { + _v = SWIG_lua_isnilstring(L,argv[0]); + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[1]); + } + if (_v) { + { + _v = lua_isnumber(L,argv[2]); + } + if (_v) { + return _wrap_new_EventConsumer__SWIG_0(L); + } + } + } + } + + SWIG_Lua_pusherrstring(L,"Wrong arguments for overloaded function 'new_EventConsumer'\n" + " Possible C/C++ prototypes are:\n" + " EventConsumer::EventConsumer(char const *,char const *,int)\n" + " EventConsumer::EventConsumer(char const *,char const *)\n" + " EventConsumer::EventConsumer(char const *)\n" + " EventConsumer::EventConsumer()\n"); + lua_error(L);return 0; +} + + +static int _wrap_EventConsumer_bind__SWIG_0(lua_State* L) { { int SWIG_arg = 0; EventConsumer *arg1 = (EventConsumer *) 0 ; char *arg2 = (char *) 0 ; - char *arg3 = (char *) "" ; + char *arg3 = (char *) 0 ; int result; - SWIG_check_num_args("EventConsumer::bind",2,3) + SWIG_check_num_args("EventConsumer::bind",3,3) if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("EventConsumer::bind",1,"EventConsumer *"); if(!SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("EventConsumer::bind",2,"char const *"); - if(lua_gettop(L)>=3 && !SWIG_lua_isnilstring(L,3)) SWIG_fail_arg("EventConsumer::bind",3,"char const *"); + if(!SWIG_lua_isnilstring(L,3)) SWIG_fail_arg("EventConsumer::bind",3,"char const *"); if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_EventConsumer,0))){ SWIG_fail_ptr("EventConsumer_bind",1,SWIGTYPE_p_EventConsumer); } arg2 = (char *)lua_tostring(L, 2); - if(lua_gettop(L)>=3){ - arg3 = (char *)lua_tostring(L, 3); - } + arg3 = (char *)lua_tostring(L, 3); result = (int)(arg1)->bind((char const *)arg2,(char const *)arg3); lua_pushnumber(L, (lua_Number) result); SWIG_arg++; return SWIG_arg; @@ -5589,6 +5704,92 @@ static int _wrap_EventConsumer_bind(lua_State* L) { } +static int _wrap_EventConsumer_bind__SWIG_1(lua_State* L) { + { + int SWIG_arg = 0; + EventConsumer *arg1 = (EventConsumer *) 0 ; + char *arg2 = (char *) 0 ; + int result; + + SWIG_check_num_args("EventConsumer::bind",2,2) + if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("EventConsumer::bind",1,"EventConsumer *"); + if(!SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("EventConsumer::bind",2,"char const *"); + + if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_EventConsumer,0))){ + SWIG_fail_ptr("EventConsumer_bind",1,SWIGTYPE_p_EventConsumer); + } + + arg2 = (char *)lua_tostring(L, 2); + result = (int)(arg1)->bind((char const *)arg2); + lua_pushnumber(L, (lua_Number) result); SWIG_arg++; + return SWIG_arg; + + fail: SWIGUNUSED; + } + lua_error(L); + return 0; +} + + +static int _wrap_EventConsumer_bind(lua_State* L) { + int argc; + int argv[4]={ + 1,2,3,4 + }; + + argc = lua_gettop(L); + if (argc == 2) { + int _v = 0; + { + void *ptr; + if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_EventConsumer, 0)) { + _v = 0; + } else { + _v = 1; + } + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[1]); + } + if (_v) { + return _wrap_EventConsumer_bind__SWIG_1(L); + } + } + } + if (argc == 3) { + int _v = 0; + { + void *ptr; + if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_EventConsumer, 0)) { + _v = 0; + } else { + _v = 1; + } + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[1]); + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[2]); + } + if (_v) { + return _wrap_EventConsumer_bind__SWIG_0(L); + } + } + } + } + + SWIG_Lua_pusherrstring(L,"Wrong arguments for overloaded function 'EventConsumer_bind'\n" + " Possible C/C++ prototypes are:\n" + " EventConsumer::bind(char const *,char const *)\n" + " EventConsumer::bind(char const *)\n"); + lua_error(L);return 0; +} + + static int _wrap_EventConsumer_pop(lua_State* L) { { int SWIG_arg = 0; @@ -6366,23 +6567,21 @@ static int _wrap_CoreSession_preAnswer(lua_State* L) { } -static int _wrap_CoreSession_hangup(lua_State* L) { +static int _wrap_CoreSession_hangup__SWIG_0(lua_State* L) { { int SWIG_arg = 0; CoreSession *arg1 = (CoreSession *) 0 ; - char *arg2 = (char *) "normal_clearing" ; + char *arg2 = (char *) 0 ; - SWIG_check_num_args("CoreSession::hangup",1,2) + SWIG_check_num_args("CoreSession::hangup",2,2) if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("CoreSession::hangup",1,"CoreSession *"); - if(lua_gettop(L)>=2 && !SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("CoreSession::hangup",2,"char const *"); + if(!SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("CoreSession::hangup",2,"char const *"); if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_CoreSession,0))){ SWIG_fail_ptr("CoreSession_hangup",1,SWIGTYPE_p_CoreSession); } - if(lua_gettop(L)>=2){ - arg2 = (char *)lua_tostring(L, 2); - } + arg2 = (char *)lua_tostring(L, 2); (arg1)->hangup((char const *)arg2); return SWIG_arg; @@ -6394,6 +6593,78 @@ static int _wrap_CoreSession_hangup(lua_State* L) { } +static int _wrap_CoreSession_hangup__SWIG_1(lua_State* L) { + { + int SWIG_arg = 0; + CoreSession *arg1 = (CoreSession *) 0 ; + + SWIG_check_num_args("CoreSession::hangup",1,1) + if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("CoreSession::hangup",1,"CoreSession *"); + + if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_CoreSession,0))){ + SWIG_fail_ptr("CoreSession_hangup",1,SWIGTYPE_p_CoreSession); + } + + (arg1)->hangup(); + + return SWIG_arg; + + fail: SWIGUNUSED; + } + lua_error(L); + return 0; +} + + +static int _wrap_CoreSession_hangup(lua_State* L) { + int argc; + int argv[3]={ + 1,2,3 + }; + + argc = lua_gettop(L); + if (argc == 1) { + int _v = 0; + { + void *ptr; + if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_CoreSession, 0)) { + _v = 0; + } else { + _v = 1; + } + } + if (_v) { + return _wrap_CoreSession_hangup__SWIG_1(L); + } + } + if (argc == 2) { + int _v = 0; + { + void *ptr; + if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_CoreSession, 0)) { + _v = 0; + } else { + _v = 1; + } + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[1]); + } + if (_v) { + return _wrap_CoreSession_hangup__SWIG_0(L); + } + } + } + + SWIG_Lua_pusherrstring(L,"Wrong arguments for overloaded function 'CoreSession_hangup'\n" + " Possible C/C++ prototypes are:\n" + " CoreSession::hangup(char const *)\n" + " CoreSession::hangup()\n"); + lua_error(L);return 0; +} + + static int _wrap_CoreSession_hangupState(lua_State* L) { { int SWIG_arg = 0; @@ -6599,31 +6870,27 @@ static int _wrap_CoreSession_say(lua_State* L) { } -static int _wrap_CoreSession_sayPhrase(lua_State* L) { +static int _wrap_CoreSession_sayPhrase__SWIG_0(lua_State* L) { { int SWIG_arg = 0; CoreSession *arg1 = (CoreSession *) 0 ; char *arg2 = (char *) 0 ; - char *arg3 = (char *) "" ; - char *arg4 = (char *) NULL ; + char *arg3 = (char *) 0 ; + char *arg4 = (char *) 0 ; - SWIG_check_num_args("CoreSession::sayPhrase",2,4) + SWIG_check_num_args("CoreSession::sayPhrase",4,4) if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("CoreSession::sayPhrase",1,"CoreSession *"); if(!SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("CoreSession::sayPhrase",2,"char const *"); - if(lua_gettop(L)>=3 && !SWIG_lua_isnilstring(L,3)) SWIG_fail_arg("CoreSession::sayPhrase",3,"char const *"); - if(lua_gettop(L)>=4 && !SWIG_lua_isnilstring(L,4)) SWIG_fail_arg("CoreSession::sayPhrase",4,"char const *"); + if(!SWIG_lua_isnilstring(L,3)) SWIG_fail_arg("CoreSession::sayPhrase",3,"char const *"); + if(!SWIG_lua_isnilstring(L,4)) SWIG_fail_arg("CoreSession::sayPhrase",4,"char const *"); if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_CoreSession,0))){ SWIG_fail_ptr("CoreSession_sayPhrase",1,SWIGTYPE_p_CoreSession); } arg2 = (char *)lua_tostring(L, 2); - if(lua_gettop(L)>=3){ - arg3 = (char *)lua_tostring(L, 3); - } - if(lua_gettop(L)>=4){ - arg4 = (char *)lua_tostring(L, 4); - } + arg3 = (char *)lua_tostring(L, 3); + arg4 = (char *)lua_tostring(L, 4); (arg1)->sayPhrase((char const *)arg2,(char const *)arg3,(char const *)arg4); return SWIG_arg; @@ -6635,6 +6902,150 @@ static int _wrap_CoreSession_sayPhrase(lua_State* L) { } +static int _wrap_CoreSession_sayPhrase__SWIG_1(lua_State* L) { + { + int SWIG_arg = 0; + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + + SWIG_check_num_args("CoreSession::sayPhrase",3,3) + if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("CoreSession::sayPhrase",1,"CoreSession *"); + if(!SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("CoreSession::sayPhrase",2,"char const *"); + if(!SWIG_lua_isnilstring(L,3)) SWIG_fail_arg("CoreSession::sayPhrase",3,"char const *"); + + if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_CoreSession,0))){ + SWIG_fail_ptr("CoreSession_sayPhrase",1,SWIGTYPE_p_CoreSession); + } + + arg2 = (char *)lua_tostring(L, 2); + arg3 = (char *)lua_tostring(L, 3); + (arg1)->sayPhrase((char const *)arg2,(char const *)arg3); + + return SWIG_arg; + + fail: SWIGUNUSED; + } + lua_error(L); + return 0; +} + + +static int _wrap_CoreSession_sayPhrase__SWIG_2(lua_State* L) { + { + int SWIG_arg = 0; + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + + SWIG_check_num_args("CoreSession::sayPhrase",2,2) + if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("CoreSession::sayPhrase",1,"CoreSession *"); + if(!SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("CoreSession::sayPhrase",2,"char const *"); + + if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_CoreSession,0))){ + SWIG_fail_ptr("CoreSession_sayPhrase",1,SWIGTYPE_p_CoreSession); + } + + arg2 = (char *)lua_tostring(L, 2); + (arg1)->sayPhrase((char const *)arg2); + + return SWIG_arg; + + fail: SWIGUNUSED; + } + lua_error(L); + return 0; +} + + +static int _wrap_CoreSession_sayPhrase(lua_State* L) { + int argc; + int argv[5]={ + 1,2,3,4,5 + }; + + argc = lua_gettop(L); + if (argc == 2) { + int _v = 0; + { + void *ptr; + if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_CoreSession, 0)) { + _v = 0; + } else { + _v = 1; + } + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[1]); + } + if (_v) { + return _wrap_CoreSession_sayPhrase__SWIG_2(L); + } + } + } + if (argc == 3) { + int _v = 0; + { + void *ptr; + if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_CoreSession, 0)) { + _v = 0; + } else { + _v = 1; + } + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[1]); + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[2]); + } + if (_v) { + return _wrap_CoreSession_sayPhrase__SWIG_1(L); + } + } + } + } + if (argc == 4) { + int _v = 0; + { + void *ptr; + if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_CoreSession, 0)) { + _v = 0; + } else { + _v = 1; + } + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[1]); + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[2]); + } + if (_v) { + { + _v = SWIG_lua_isnilstring(L,argv[3]); + } + if (_v) { + return _wrap_CoreSession_sayPhrase__SWIG_0(L); + } + } + } + } + } + + SWIG_Lua_pusherrstring(L,"Wrong arguments for overloaded function 'CoreSession_sayPhrase'\n" + " Possible C/C++ prototypes are:\n" + " CoreSession::sayPhrase(char const *,char const *,char const *)\n" + " CoreSession::sayPhrase(char const *,char const *)\n" + " CoreSession::sayPhrase(char const *)\n"); + lua_error(L);return 0; +} + + static int _wrap_CoreSession_hangupCause(lua_State* L) { { int SWIG_arg = 0; diff --git a/src/mod/languages/mod_managed/freeswitch_wrap.cxx b/src/mod/languages/mod_managed/freeswitch_wrap.cxx index 012f65edef..a512affd8b 100644 --- a/src/mod/languages/mod_managed/freeswitch_wrap.cxx +++ b/src/mod/languages/mod_managed/freeswitch_wrap.cxx @@ -52089,11 +52089,11 @@ SWIGEXPORT unsigned long SWIGSTDCALL CSharp_FreeSWITCHfNative_EventConsumer_node } -SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_new_EventConsumer___(char * jarg1, char * jarg2, int jarg3) { +SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_new_EventConsumer__SWIG_0___(char * jarg1, char * jarg2, int jarg3) { void * jresult ; - char *arg1 = (char *) NULL ; - char *arg2 = (char *) "" ; - int arg3 = (int) 5000 ; + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; EventConsumer *result = 0 ; arg1 = (char *)jarg1; @@ -52105,6 +52105,42 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_new_EventConsumer___(char } +SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_new_EventConsumer__SWIG_1___(char * jarg1, char * jarg2) { + void * jresult ; + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + EventConsumer *result = 0 ; + + arg1 = (char *)jarg1; + arg2 = (char *)jarg2; + result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2); + jresult = (void *)result; + return jresult; +} + + +SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_new_EventConsumer__SWIG_2___(char * jarg1) { + void * jresult ; + char *arg1 = (char *) 0 ; + EventConsumer *result = 0 ; + + arg1 = (char *)jarg1; + result = (EventConsumer *)new EventConsumer((char const *)arg1); + jresult = (void *)result; + return jresult; +} + + +SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_new_EventConsumer__SWIG_3___() { + void * jresult ; + EventConsumer *result = 0 ; + + result = (EventConsumer *)new EventConsumer(); + jresult = (void *)result; + return jresult; +} + + SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_delete_EventConsumer___(void * jarg1) { EventConsumer *arg1 = (EventConsumer *) 0 ; @@ -52113,11 +52149,11 @@ SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_delete_EventConsumer___(voi } -SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_EventConsumer_bind___(void * jarg1, char * jarg2, char * jarg3) { +SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_EventConsumer_bind__SWIG_0___(void * jarg1, char * jarg2, char * jarg3) { int jresult ; EventConsumer *arg1 = (EventConsumer *) 0 ; char *arg2 = (char *) 0 ; - char *arg3 = (char *) "" ; + char *arg3 = (char *) 0 ; int result; arg1 = (EventConsumer *)jarg1; @@ -52129,6 +52165,20 @@ SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_EventConsumer_bind___(void * } +SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_EventConsumer_bind__SWIG_1___(void * jarg1, char * jarg2) { + int jresult ; + EventConsumer *arg1 = (EventConsumer *) 0 ; + char *arg2 = (char *) 0 ; + int result; + + arg1 = (EventConsumer *)jarg1; + arg2 = (char *)jarg2; + result = (int)(arg1)->bind((char const *)arg2); + jresult = result; + return jresult; +} + + SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_EventConsumer_pop___(void * jarg1, int jarg2, int jarg3) { void * jresult ; EventConsumer *arg1 = (EventConsumer *) 0 ; @@ -52461,9 +52511,9 @@ SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_preAnswer___(voi } -SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_Hangup___(void * jarg1, char * jarg2) { +SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_Hangup__SWIG_0___(void * jarg1, char * jarg2) { CoreSession *arg1 = (CoreSession *) 0 ; - char *arg2 = (char *) "normal_clearing" ; + char *arg2 = (char *) 0 ; arg1 = (CoreSession *)jarg1; arg2 = (char *)jarg2; @@ -52471,6 +52521,14 @@ SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_Hangup___(void } +SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_Hangup__SWIG_1___(void * jarg1) { + CoreSession *arg1 = (CoreSession *) 0 ; + + arg1 = (CoreSession *)jarg1; + (arg1)->hangup(); +} + + SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_hangupState___(void * jarg1) { CoreSession *arg1 = (CoreSession *) 0 ; @@ -52549,11 +52607,11 @@ SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_Say___(void * j } -SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_SayPhrase___(void * jarg1, char * jarg2, char * jarg3, char * jarg4) { +SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_SayPhrase__SWIG_0___(void * jarg1, char * jarg2, char * jarg3, char * jarg4) { CoreSession *arg1 = (CoreSession *) 0 ; char *arg2 = (char *) 0 ; - char *arg3 = (char *) "" ; - char *arg4 = (char *) NULL ; + char *arg3 = (char *) 0 ; + char *arg4 = (char *) 0 ; arg1 = (CoreSession *)jarg1; arg2 = (char *)jarg2; @@ -52563,6 +52621,28 @@ SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_SayPhrase___(vo } +SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_SayPhrase__SWIG_1___(void * jarg1, char * jarg2, char * jarg3) { + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + + arg1 = (CoreSession *)jarg1; + arg2 = (char *)jarg2; + arg3 = (char *)jarg3; + (arg1)->sayPhrase((char const *)arg2,(char const *)arg3); +} + + +SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_SayPhrase__SWIG_2___(void * jarg1, char * jarg2) { + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + + arg1 = (CoreSession *)jarg1; + arg2 = (char *)jarg2; + (arg1)->sayPhrase((char const *)arg2); +} + + SWIGEXPORT char * SWIGSTDCALL CSharp_FreeSWITCHfNative_CoreSession_hangupCause___(void * jarg1) { char * jresult ; CoreSession *arg1 = (CoreSession *) 0 ; diff --git a/src/mod/languages/mod_managed/managed/swig.cs b/src/mod/languages/mod_managed/managed/swig.cs index 1196a380a8..6d7faecd59 100644 --- a/src/mod/languages/mod_managed/managed/swig.cs +++ b/src/mod/languages/mod_managed/managed/swig.cs @@ -261,7 +261,11 @@ public class CoreSession : global::System.IDisposable { } public void Hangup(string cause) { - freeswitchPINVOKE.CoreSession_Hangup(swigCPtr, cause); + freeswitchPINVOKE.CoreSession_Hangup__SWIG_0(swigCPtr, cause); + } + + public void Hangup() { + freeswitchPINVOKE.CoreSession_Hangup__SWIG_1(swigCPtr); } public void hangupState() { @@ -292,7 +296,15 @@ public class CoreSession : global::System.IDisposable { } public void SayPhrase(string phrase_name, string phrase_data, string phrase_lang) { - freeswitchPINVOKE.CoreSession_SayPhrase(swigCPtr, phrase_name, phrase_data, phrase_lang); + freeswitchPINVOKE.CoreSession_SayPhrase__SWIG_0(swigCPtr, phrase_name, phrase_data, phrase_lang); + } + + public void SayPhrase(string phrase_name, string phrase_data) { + freeswitchPINVOKE.CoreSession_SayPhrase__SWIG_1(swigCPtr, phrase_name, phrase_data); + } + + public void SayPhrase(string phrase_name) { + freeswitchPINVOKE.CoreSession_SayPhrase__SWIG_2(swigCPtr, phrase_name); } public string hangupCause() { @@ -857,11 +869,25 @@ public class EventConsumer : global::System.IDisposable { } } - public EventConsumer(string event_name, string subclass_name, int len) : this(freeswitchPINVOKE.new_EventConsumer(event_name, subclass_name, len), true) { + public EventConsumer(string event_name, string subclass_name, int len) : this(freeswitchPINVOKE.new_EventConsumer__SWIG_0(event_name, subclass_name, len), true) { + } + + public EventConsumer(string event_name, string subclass_name) : this(freeswitchPINVOKE.new_EventConsumer__SWIG_1(event_name, subclass_name), true) { + } + + public EventConsumer(string event_name) : this(freeswitchPINVOKE.new_EventConsumer__SWIG_2(event_name), true) { + } + + public EventConsumer() : this(freeswitchPINVOKE.new_EventConsumer__SWIG_3(), true) { } public int bind(string event_name, string subclass_name) { - int ret = freeswitchPINVOKE.EventConsumer_bind(swigCPtr, event_name, subclass_name); + int ret = freeswitchPINVOKE.EventConsumer_bind__SWIG_0(swigCPtr, event_name, subclass_name); + return ret; + } + + public int bind(string event_name) { + int ret = freeswitchPINVOKE.EventConsumer_bind__SWIG_1(swigCPtr, event_name); return ret; } @@ -29211,14 +29237,26 @@ class freeswitchPINVOKE { [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_EventConsumer_node_index_get___")] public static extern uint EventConsumer_node_index_get(global::System.Runtime.InteropServices.HandleRef jarg1); - [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_new_EventConsumer___")] - public static extern global::System.IntPtr new_EventConsumer(string jarg1, string jarg2, int jarg3); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_new_EventConsumer__SWIG_0___")] + public static extern global::System.IntPtr new_EventConsumer__SWIG_0(string jarg1, string jarg2, int jarg3); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_new_EventConsumer__SWIG_1___")] + public static extern global::System.IntPtr new_EventConsumer__SWIG_1(string jarg1, string jarg2); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_new_EventConsumer__SWIG_2___")] + public static extern global::System.IntPtr new_EventConsumer__SWIG_2(string jarg1); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_new_EventConsumer__SWIG_3___")] + public static extern global::System.IntPtr new_EventConsumer__SWIG_3(); [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_delete_EventConsumer___")] public static extern void delete_EventConsumer(global::System.Runtime.InteropServices.HandleRef jarg1); - [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_EventConsumer_bind___")] - public static extern int EventConsumer_bind(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2, string jarg3); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_EventConsumer_bind__SWIG_0___")] + public static extern int EventConsumer_bind__SWIG_0(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2, string jarg3); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_EventConsumer_bind__SWIG_1___")] + public static extern int EventConsumer_bind__SWIG_1(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2); [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_EventConsumer_pop___")] public static extern global::System.IntPtr EventConsumer_pop(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2, int jarg3); @@ -29301,8 +29339,11 @@ class freeswitchPINVOKE { [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_CoreSession_preAnswer___")] public static extern int CoreSession_preAnswer(global::System.Runtime.InteropServices.HandleRef jarg1); - [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_CoreSession_Hangup___")] - public static extern void CoreSession_Hangup(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_CoreSession_Hangup__SWIG_0___")] + public static extern void CoreSession_Hangup__SWIG_0(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_CoreSession_Hangup__SWIG_1___")] + public static extern void CoreSession_Hangup__SWIG_1(global::System.Runtime.InteropServices.HandleRef jarg1); [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_CoreSession_hangupState___")] public static extern void CoreSession_hangupState(global::System.Runtime.InteropServices.HandleRef jarg1); @@ -29322,8 +29363,14 @@ class freeswitchPINVOKE { [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_CoreSession_Say___")] public static extern void CoreSession_Say(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2, string jarg3, string jarg4, string jarg5, string jarg6); - [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_CoreSession_SayPhrase___")] - public static extern void CoreSession_SayPhrase(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2, string jarg3, string jarg4); + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_CoreSession_SayPhrase__SWIG_0___")] + public static extern void CoreSession_SayPhrase__SWIG_0(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2, string jarg3, string jarg4); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_CoreSession_SayPhrase__SWIG_1___")] + public static extern void CoreSession_SayPhrase__SWIG_1(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2, string jarg3); + + [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_CoreSession_SayPhrase__SWIG_2___")] + public static extern void CoreSession_SayPhrase__SWIG_2(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2); [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_CoreSession_hangupCause___")] public static extern string CoreSession_hangupCause(global::System.Runtime.InteropServices.HandleRef jarg1); diff --git a/src/mod/languages/mod_perl/mod_perl_wrap.cpp b/src/mod/languages/mod_perl/mod_perl_wrap.cpp index c345b3b267..11ba2b3375 100644 --- a/src/mod/languages/mod_perl/mod_perl_wrap.cpp +++ b/src/mod/languages/mod_perl/mod_perl_wrap.cpp @@ -4991,11 +4991,11 @@ XS(_wrap_EventConsumer_node_index_get) { } -XS(_wrap_new_EventConsumer) { +XS(_wrap_new_EventConsumer__SWIG_0) { { - char *arg1 = (char *) NULL ; - char *arg2 = (char *) "" ; - int arg3 = (int) 5000 ; + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; int res1 ; char *buf1 = 0 ; int alloc1 = 0 ; @@ -5008,30 +5008,24 @@ XS(_wrap_new_EventConsumer) { EventConsumer *result = 0 ; dXSARGS; - if ((items < 0) || (items > 3)) { + if ((items < 3) || (items > 3)) { SWIG_croak("Usage: new_EventConsumer(event_name,subclass_name,len);"); } - if (items > 0) { - res1 = SWIG_AsCharPtrAndSize(ST(0), &buf1, NULL, &alloc1); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_EventConsumer" "', argument " "1"" of type '" "char const *""'"); - } - arg1 = reinterpret_cast< char * >(buf1); + res1 = SWIG_AsCharPtrAndSize(ST(0), &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_EventConsumer" "', argument " "1"" of type '" "char const *""'"); } - if (items > 1) { - res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_EventConsumer" "', argument " "2"" of type '" "char const *""'"); - } - arg2 = reinterpret_cast< char * >(buf2); - } - if (items > 2) { - ecode3 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), &val3); - if (!SWIG_IsOK(ecode3)) { - SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_EventConsumer" "', argument " "3"" of type '" "int""'"); - } - arg3 = static_cast< int >(val3); + arg1 = reinterpret_cast< char * >(buf1); + res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_EventConsumer" "', argument " "2"" of type '" "char const *""'"); } + arg2 = reinterpret_cast< char * >(buf2); + ecode3 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_EventConsumer" "', argument " "3"" of type '" "int""'"); + } + arg3 = static_cast< int >(val3); result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2,arg3); ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_EventConsumer, SWIG_OWNER | SWIG_SHADOW); argvi++ ; if (alloc1 == SWIG_NEWOBJ) delete[] buf1; @@ -5047,6 +5041,211 @@ XS(_wrap_new_EventConsumer) { } +XS(_wrap_new_EventConsumer__SWIG_1) { + { + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + int res1 ; + char *buf1 = 0 ; + int alloc1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int argvi = 0; + EventConsumer *result = 0 ; + dXSARGS; + + if ((items < 2) || (items > 2)) { + SWIG_croak("Usage: new_EventConsumer(event_name,subclass_name);"); + } + res1 = SWIG_AsCharPtrAndSize(ST(0), &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_EventConsumer" "', argument " "1"" of type '" "char const *""'"); + } + arg1 = reinterpret_cast< char * >(buf1); + res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_EventConsumer" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = reinterpret_cast< char * >(buf2); + result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2); + ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_EventConsumer, SWIG_OWNER | SWIG_SHADOW); argvi++ ; + if (alloc1 == SWIG_NEWOBJ) delete[] buf1; + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + XSRETURN(argvi); + fail: + if (alloc1 == SWIG_NEWOBJ) delete[] buf1; + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + SWIG_croak_null(); + } +} + + +XS(_wrap_new_EventConsumer__SWIG_2) { + { + char *arg1 = (char *) 0 ; + int res1 ; + char *buf1 = 0 ; + int alloc1 = 0 ; + int argvi = 0; + EventConsumer *result = 0 ; + dXSARGS; + + if ((items < 1) || (items > 1)) { + SWIG_croak("Usage: new_EventConsumer(event_name);"); + } + res1 = SWIG_AsCharPtrAndSize(ST(0), &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_EventConsumer" "', argument " "1"" of type '" "char const *""'"); + } + arg1 = reinterpret_cast< char * >(buf1); + result = (EventConsumer *)new EventConsumer((char const *)arg1); + ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_EventConsumer, SWIG_OWNER | SWIG_SHADOW); argvi++ ; + if (alloc1 == SWIG_NEWOBJ) delete[] buf1; + XSRETURN(argvi); + fail: + if (alloc1 == SWIG_NEWOBJ) delete[] buf1; + SWIG_croak_null(); + } +} + + +XS(_wrap_new_EventConsumer__SWIG_3) { + { + int argvi = 0; + EventConsumer *result = 0 ; + dXSARGS; + + if ((items < 0) || (items > 0)) { + SWIG_croak("Usage: new_EventConsumer();"); + } + result = (EventConsumer *)new EventConsumer(); + ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_EventConsumer, SWIG_OWNER | SWIG_SHADOW); argvi++ ; + XSRETURN(argvi); + fail: + SWIG_croak_null(); + } +} + + +XS(_wrap_new_EventConsumer) { + dXSARGS; + + { + unsigned long _index = 0; + SWIG_TypeRank _rank = 0; + if (items == 0) { + SWIG_TypeRank _ranki = 0; + SWIG_TypeRank _rankm = 0; + if (!_index || (_ranki < _rank)) { + _rank = _ranki; _index = 1; + if (_rank == _rankm) goto dispatch; + } + } + if (items == 1) { + SWIG_TypeRank _ranki = 0; + SWIG_TypeRank _rankm = 0; + SWIG_TypeRank _pi = 1; + int _v = 0; + { + int res = SWIG_AsCharPtrAndSize(ST(0), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_2; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + if (!_index || (_ranki < _rank)) { + _rank = _ranki; _index = 2; + if (_rank == _rankm) goto dispatch; + } + } + check_2: + + if (items == 2) { + SWIG_TypeRank _ranki = 0; + SWIG_TypeRank _rankm = 0; + SWIG_TypeRank _pi = 1; + int _v = 0; + { + int res = SWIG_AsCharPtrAndSize(ST(0), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_3; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_3; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + if (!_index || (_ranki < _rank)) { + _rank = _ranki; _index = 3; + if (_rank == _rankm) goto dispatch; + } + } + check_3: + + if (items == 3) { + SWIG_TypeRank _ranki = 0; + SWIG_TypeRank _rankm = 0; + SWIG_TypeRank _pi = 1; + int _v = 0; + { + int res = SWIG_AsCharPtrAndSize(ST(0), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_4; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_4; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + { + int res = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), NULL); + _v = SWIG_CheckState(res); + } + } + if (!_v) goto check_4; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + if (!_index || (_ranki < _rank)) { + _rank = _ranki; _index = 4; + if (_rank == _rankm) goto dispatch; + } + } + check_4: + + dispatch: + switch(_index) { + case 1: + PUSHMARK(MARK); SWIG_CALLXS(_wrap_new_EventConsumer__SWIG_3); return; + case 2: + PUSHMARK(MARK); SWIG_CALLXS(_wrap_new_EventConsumer__SWIG_2); return; + case 3: + PUSHMARK(MARK); SWIG_CALLXS(_wrap_new_EventConsumer__SWIG_1); return; + case 4: + PUSHMARK(MARK); SWIG_CALLXS(_wrap_new_EventConsumer__SWIG_0); return; + } + } + + croak("No matching function for overloaded 'new_EventConsumer'"); + XSRETURN(0); +} + + XS(_wrap_delete_EventConsumer) { { EventConsumer *arg1 = (EventConsumer *) 0 ; @@ -5074,11 +5273,11 @@ XS(_wrap_delete_EventConsumer) { } -XS(_wrap_EventConsumer_bind) { +XS(_wrap_EventConsumer_bind__SWIG_0) { { EventConsumer *arg1 = (EventConsumer *) 0 ; char *arg2 = (char *) 0 ; - char *arg3 = (char *) "" ; + char *arg3 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; @@ -5091,7 +5290,7 @@ XS(_wrap_EventConsumer_bind) { int result; dXSARGS; - if ((items < 2) || (items > 3)) { + if ((items < 3) || (items > 3)) { SWIG_croak("Usage: EventConsumer_bind(self,event_name,subclass_name);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_EventConsumer, 0 | 0 ); @@ -5104,13 +5303,11 @@ XS(_wrap_EventConsumer_bind) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "EventConsumer_bind" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); - if (items > 2) { - res3 = SWIG_AsCharPtrAndSize(ST(2), &buf3, NULL, &alloc3); - if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "EventConsumer_bind" "', argument " "3"" of type '" "char const *""'"); - } - arg3 = reinterpret_cast< char * >(buf3); + res3 = SWIG_AsCharPtrAndSize(ST(2), &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "EventConsumer_bind" "', argument " "3"" of type '" "char const *""'"); } + arg3 = reinterpret_cast< char * >(buf3); result = (int)(arg1)->bind((char const *)arg2,(char const *)arg3); ST(argvi) = SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(result)); argvi++ ; @@ -5126,6 +5323,131 @@ XS(_wrap_EventConsumer_bind) { } +XS(_wrap_EventConsumer_bind__SWIG_1) { + { + EventConsumer *arg1 = (EventConsumer *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int argvi = 0; + int result; + dXSARGS; + + if ((items < 2) || (items > 2)) { + SWIG_croak("Usage: EventConsumer_bind(self,event_name);"); + } + res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_EventConsumer, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "EventConsumer_bind" "', argument " "1"" of type '" "EventConsumer *""'"); + } + arg1 = reinterpret_cast< EventConsumer * >(argp1); + res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "EventConsumer_bind" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = reinterpret_cast< char * >(buf2); + result = (int)(arg1)->bind((char const *)arg2); + ST(argvi) = SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(result)); argvi++ ; + + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + XSRETURN(argvi); + fail: + + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + SWIG_croak_null(); + } +} + + +XS(_wrap_EventConsumer_bind) { + dXSARGS; + + { + unsigned long _index = 0; + SWIG_TypeRank _rank = 0; + if (items == 2) { + SWIG_TypeRank _ranki = 0; + SWIG_TypeRank _rankm = 0; + SWIG_TypeRank _pi = 1; + int _v = 0; + { + void *vptr = 0; + int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_EventConsumer, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_1; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_1; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + if (!_index || (_ranki < _rank)) { + _rank = _ranki; _index = 1; + if (_rank == _rankm) goto dispatch; + } + } + check_1: + + if (items == 3) { + SWIG_TypeRank _ranki = 0; + SWIG_TypeRank _rankm = 0; + SWIG_TypeRank _pi = 1; + int _v = 0; + { + void *vptr = 0; + int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_EventConsumer, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_2; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_2; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(2), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_2; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + if (!_index || (_ranki < _rank)) { + _rank = _ranki; _index = 2; + if (_rank == _rankm) goto dispatch; + } + } + check_2: + + dispatch: + switch(_index) { + case 1: + PUSHMARK(MARK); SWIG_CALLXS(_wrap_EventConsumer_bind__SWIG_1); return; + case 2: + PUSHMARK(MARK); SWIG_CALLXS(_wrap_EventConsumer_bind__SWIG_0); return; + } + } + + croak("No matching function for overloaded 'EventConsumer_bind'"); + XSRETURN(0); +} + + XS(_wrap_EventConsumer_pop) { { EventConsumer *arg1 = (EventConsumer *) 0 ; @@ -6066,10 +6388,10 @@ XS(_wrap_CoreSession_preAnswer) { } -XS(_wrap_CoreSession_hangup) { +XS(_wrap_CoreSession_hangup__SWIG_0) { { CoreSession *arg1 = (CoreSession *) 0 ; - char *arg2 = (char *) "normal_clearing" ; + char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; @@ -6078,7 +6400,7 @@ XS(_wrap_CoreSession_hangup) { int argvi = 0; dXSARGS; - if ((items < 1) || (items > 2)) { + if ((items < 2) || (items > 2)) { SWIG_croak("Usage: CoreSession_hangup(self,cause);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); @@ -6086,13 +6408,11 @@ XS(_wrap_CoreSession_hangup) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_hangup" "', argument " "1"" of type '" "CoreSession *""'"); } arg1 = reinterpret_cast< CoreSession * >(argp1); - if (items > 1) { - res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_hangup" "', argument " "2"" of type '" "char const *""'"); - } - arg2 = reinterpret_cast< char * >(buf2); + res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_hangup" "', argument " "2"" of type '" "char const *""'"); } + arg2 = reinterpret_cast< char * >(buf2); (arg1)->hangup((char const *)arg2); ST(argvi) = &PL_sv_undef; @@ -6106,6 +6426,103 @@ XS(_wrap_CoreSession_hangup) { } +XS(_wrap_CoreSession_hangup__SWIG_1) { + { + CoreSession *arg1 = (CoreSession *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int argvi = 0; + dXSARGS; + + if ((items < 1) || (items > 1)) { + SWIG_croak("Usage: CoreSession_hangup(self);"); + } + res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_hangup" "', argument " "1"" of type '" "CoreSession *""'"); + } + arg1 = reinterpret_cast< CoreSession * >(argp1); + (arg1)->hangup(); + ST(argvi) = &PL_sv_undef; + + XSRETURN(argvi); + fail: + + SWIG_croak_null(); + } +} + + +XS(_wrap_CoreSession_hangup) { + dXSARGS; + + { + unsigned long _index = 0; + SWIG_TypeRank _rank = 0; + if (items == 1) { + SWIG_TypeRank _ranki = 0; + SWIG_TypeRank _rankm = 0; + SWIG_TypeRank _pi = 1; + int _v = 0; + { + void *vptr = 0; + int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_CoreSession, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_1; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + if (!_index || (_ranki < _rank)) { + _rank = _ranki; _index = 1; + if (_rank == _rankm) goto dispatch; + } + } + check_1: + + if (items == 2) { + SWIG_TypeRank _ranki = 0; + SWIG_TypeRank _rankm = 0; + SWIG_TypeRank _pi = 1; + int _v = 0; + { + void *vptr = 0; + int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_CoreSession, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_2; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_2; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + if (!_index || (_ranki < _rank)) { + _rank = _ranki; _index = 2; + if (_rank == _rankm) goto dispatch; + } + } + check_2: + + dispatch: + switch(_index) { + case 1: + PUSHMARK(MARK); SWIG_CALLXS(_wrap_CoreSession_hangup__SWIG_1); return; + case 2: + PUSHMARK(MARK); SWIG_CALLXS(_wrap_CoreSession_hangup__SWIG_0); return; + } + } + + croak("No matching function for overloaded 'CoreSession_hangup'"); + XSRETURN(0); +} + + XS(_wrap_CoreSession_hangupState) { { CoreSession *arg1 = (CoreSession *) 0 ; @@ -6429,12 +6846,12 @@ XS(_wrap_CoreSession_say) { } -XS(_wrap_CoreSession_sayPhrase) { +XS(_wrap_CoreSession_sayPhrase__SWIG_0) { { CoreSession *arg1 = (CoreSession *) 0 ; char *arg2 = (char *) 0 ; - char *arg3 = (char *) "" ; - char *arg4 = (char *) NULL ; + char *arg3 = (char *) 0 ; + char *arg4 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; @@ -6449,7 +6866,7 @@ XS(_wrap_CoreSession_sayPhrase) { int argvi = 0; dXSARGS; - if ((items < 2) || (items > 4)) { + if ((items < 4) || (items > 4)) { SWIG_croak("Usage: CoreSession_sayPhrase(self,phrase_name,phrase_data,phrase_lang);"); } res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); @@ -6462,20 +6879,16 @@ XS(_wrap_CoreSession_sayPhrase) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_sayPhrase" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); - if (items > 2) { - res3 = SWIG_AsCharPtrAndSize(ST(2), &buf3, NULL, &alloc3); - if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CoreSession_sayPhrase" "', argument " "3"" of type '" "char const *""'"); - } - arg3 = reinterpret_cast< char * >(buf3); + res3 = SWIG_AsCharPtrAndSize(ST(2), &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CoreSession_sayPhrase" "', argument " "3"" of type '" "char const *""'"); } - if (items > 3) { - res4 = SWIG_AsCharPtrAndSize(ST(3), &buf4, NULL, &alloc4); - if (!SWIG_IsOK(res4)) { - SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "CoreSession_sayPhrase" "', argument " "4"" of type '" "char const *""'"); - } - arg4 = reinterpret_cast< char * >(buf4); + arg3 = reinterpret_cast< char * >(buf3); + res4 = SWIG_AsCharPtrAndSize(ST(3), &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "CoreSession_sayPhrase" "', argument " "4"" of type '" "char const *""'"); } + arg4 = reinterpret_cast< char * >(buf4); (arg1)->sayPhrase((char const *)arg2,(char const *)arg3,(char const *)arg4); ST(argvi) = &PL_sv_undef; @@ -6493,6 +6906,226 @@ XS(_wrap_CoreSession_sayPhrase) { } +XS(_wrap_CoreSession_sayPhrase__SWIG_1) { + { + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + int argvi = 0; + dXSARGS; + + if ((items < 3) || (items > 3)) { + SWIG_croak("Usage: CoreSession_sayPhrase(self,phrase_name,phrase_data);"); + } + res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_sayPhrase" "', argument " "1"" of type '" "CoreSession *""'"); + } + arg1 = reinterpret_cast< CoreSession * >(argp1); + res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_sayPhrase" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = reinterpret_cast< char * >(buf2); + res3 = SWIG_AsCharPtrAndSize(ST(2), &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CoreSession_sayPhrase" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = reinterpret_cast< char * >(buf3); + (arg1)->sayPhrase((char const *)arg2,(char const *)arg3); + ST(argvi) = &PL_sv_undef; + + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + if (alloc3 == SWIG_NEWOBJ) delete[] buf3; + XSRETURN(argvi); + fail: + + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + if (alloc3 == SWIG_NEWOBJ) delete[] buf3; + SWIG_croak_null(); + } +} + + +XS(_wrap_CoreSession_sayPhrase__SWIG_2) { + { + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int argvi = 0; + dXSARGS; + + if ((items < 2) || (items > 2)) { + SWIG_croak("Usage: CoreSession_sayPhrase(self,phrase_name);"); + } + res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_sayPhrase" "', argument " "1"" of type '" "CoreSession *""'"); + } + arg1 = reinterpret_cast< CoreSession * >(argp1); + res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_sayPhrase" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = reinterpret_cast< char * >(buf2); + (arg1)->sayPhrase((char const *)arg2); + ST(argvi) = &PL_sv_undef; + + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + XSRETURN(argvi); + fail: + + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + SWIG_croak_null(); + } +} + + +XS(_wrap_CoreSession_sayPhrase) { + dXSARGS; + + { + unsigned long _index = 0; + SWIG_TypeRank _rank = 0; + if (items == 2) { + SWIG_TypeRank _ranki = 0; + SWIG_TypeRank _rankm = 0; + SWIG_TypeRank _pi = 1; + int _v = 0; + { + void *vptr = 0; + int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_CoreSession, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_1; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_1; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + if (!_index || (_ranki < _rank)) { + _rank = _ranki; _index = 1; + if (_rank == _rankm) goto dispatch; + } + } + check_1: + + if (items == 3) { + SWIG_TypeRank _ranki = 0; + SWIG_TypeRank _rankm = 0; + SWIG_TypeRank _pi = 1; + int _v = 0; + { + void *vptr = 0; + int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_CoreSession, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_2; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_2; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(2), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_2; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + if (!_index || (_ranki < _rank)) { + _rank = _ranki; _index = 2; + if (_rank == _rankm) goto dispatch; + } + } + check_2: + + if (items == 4) { + SWIG_TypeRank _ranki = 0; + SWIG_TypeRank _rankm = 0; + SWIG_TypeRank _pi = 1; + int _v = 0; + { + void *vptr = 0; + int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_CoreSession, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_3; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_3; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(2), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_3; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + { + int res = SWIG_AsCharPtrAndSize(ST(3), 0, NULL, 0); + _v = SWIG_CheckState(res); + } + if (!_v) goto check_3; + _ranki += _v*_pi; + _rankm += _pi; + _pi *= SWIG_MAXCASTRANK; + if (!_index || (_ranki < _rank)) { + _rank = _ranki; _index = 3; + if (_rank == _rankm) goto dispatch; + } + } + check_3: + + dispatch: + switch(_index) { + case 1: + PUSHMARK(MARK); SWIG_CALLXS(_wrap_CoreSession_sayPhrase__SWIG_2); return; + case 2: + PUSHMARK(MARK); SWIG_CALLXS(_wrap_CoreSession_sayPhrase__SWIG_1); return; + case 3: + PUSHMARK(MARK); SWIG_CALLXS(_wrap_CoreSession_sayPhrase__SWIG_0); return; + } + } + + croak("No matching function for overloaded 'CoreSession_sayPhrase'"); + XSRETURN(0); +} + + XS(_wrap_CoreSession_hangupCause) { { CoreSession *arg1 = (CoreSession *) 0 ; diff --git a/src/mod/languages/mod_python3/mod_python_wrap.cpp b/src/mod/languages/mod_python3/mod_python_wrap.cpp index bc132dea36..b9a38298d0 100644 --- a/src/mod/languages/mod_python3/mod_python_wrap.cpp +++ b/src/mod/languages/mod_python3/mod_python_wrap.cpp @@ -6183,11 +6183,11 @@ fail: } -SWIGINTERN PyObject *_wrap_new_EventConsumer(PyObject *self, PyObject *args) { +SWIGINTERN PyObject *_wrap_new_EventConsumer__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; - char *arg1 = (char *) NULL ; - char *arg2 = (char *) "" ; - int arg3 = (int) 5000 ; + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; int res1 ; char *buf1 = 0 ; int alloc1 = 0 ; @@ -6196,31 +6196,24 @@ SWIGINTERN PyObject *_wrap_new_EventConsumer(PyObject *self, PyObject *args) { int alloc2 = 0 ; int val3 ; int ecode3 = 0 ; - PyObject *swig_obj[3] ; EventConsumer *result = 0 ; - if (!SWIG_Python_UnpackTuple(args, "new_EventConsumer", 0, 3, swig_obj)) SWIG_fail; - if (swig_obj[0]) { - res1 = SWIG_AsCharPtrAndSize(swig_obj[0], &buf1, NULL, &alloc1); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_EventConsumer" "', argument " "1"" of type '" "char const *""'"); - } - arg1 = reinterpret_cast< char * >(buf1); + if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; + res1 = SWIG_AsCharPtrAndSize(swig_obj[0], &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_EventConsumer" "', argument " "1"" of type '" "char const *""'"); } - if (swig_obj[1]) { - res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_EventConsumer" "', argument " "2"" of type '" "char const *""'"); - } - arg2 = reinterpret_cast< char * >(buf2); - } - if (swig_obj[2]) { - ecode3 = SWIG_AsVal_int(swig_obj[2], &val3); - if (!SWIG_IsOK(ecode3)) { - SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_EventConsumer" "', argument " "3"" of type '" "int""'"); - } - arg3 = static_cast< int >(val3); + arg1 = reinterpret_cast< char * >(buf1); + res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_EventConsumer" "', argument " "2"" of type '" "char const *""'"); } + arg2 = reinterpret_cast< char * >(buf2); + ecode3 = SWIG_AsVal_int(swig_obj[2], &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_EventConsumer" "', argument " "3"" of type '" "int""'"); + } + arg3 = static_cast< int >(val3); result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2,arg3); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_EventConsumer, SWIG_POINTER_NEW | 0 ); if (alloc1 == SWIG_NEWOBJ) delete[] buf1; @@ -6233,6 +6226,139 @@ fail: } +SWIGINTERN PyObject *_wrap_new_EventConsumer__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { + PyObject *resultobj = 0; + char *arg1 = (char *) 0 ; + char *arg2 = (char *) 0 ; + int res1 ; + char *buf1 = 0 ; + int alloc1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + EventConsumer *result = 0 ; + + if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; + res1 = SWIG_AsCharPtrAndSize(swig_obj[0], &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_EventConsumer" "', argument " "1"" of type '" "char const *""'"); + } + arg1 = reinterpret_cast< char * >(buf1); + res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_EventConsumer" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = reinterpret_cast< char * >(buf2); + result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_EventConsumer, SWIG_POINTER_NEW | 0 ); + if (alloc1 == SWIG_NEWOBJ) delete[] buf1; + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + return resultobj; +fail: + if (alloc1 == SWIG_NEWOBJ) delete[] buf1; + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + return NULL; +} + + +SWIGINTERN PyObject *_wrap_new_EventConsumer__SWIG_2(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { + PyObject *resultobj = 0; + char *arg1 = (char *) 0 ; + int res1 ; + char *buf1 = 0 ; + int alloc1 = 0 ; + EventConsumer *result = 0 ; + + if ((nobjs < 1) || (nobjs > 1)) SWIG_fail; + res1 = SWIG_AsCharPtrAndSize(swig_obj[0], &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_EventConsumer" "', argument " "1"" of type '" "char const *""'"); + } + arg1 = reinterpret_cast< char * >(buf1); + result = (EventConsumer *)new EventConsumer((char const *)arg1); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_EventConsumer, SWIG_POINTER_NEW | 0 ); + if (alloc1 == SWIG_NEWOBJ) delete[] buf1; + return resultobj; +fail: + if (alloc1 == SWIG_NEWOBJ) delete[] buf1; + return NULL; +} + + +SWIGINTERN PyObject *_wrap_new_EventConsumer__SWIG_3(PyObject *self, Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) { + PyObject *resultobj = 0; + EventConsumer *result = 0 ; + + if ((nobjs < 0) || (nobjs > 0)) SWIG_fail; + result = (EventConsumer *)new EventConsumer(); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_EventConsumer, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_new_EventConsumer(PyObject *self, PyObject *args) { + Py_ssize_t argc; + PyObject *argv[4] = { + 0 + }; + + if (!(argc = SWIG_Python_UnpackTuple(args, "new_EventConsumer", 0, 3, argv))) SWIG_fail; + --argc; + if (argc == 0) { + return _wrap_new_EventConsumer__SWIG_3(self, argc, argv); + } + if (argc == 1) { + int _v = 0; + int res = SWIG_AsCharPtrAndSize(argv[0], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_new_EventConsumer__SWIG_2(self, argc, argv); + } + } + if (argc == 2) { + int _v = 0; + int res = SWIG_AsCharPtrAndSize(argv[0], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_new_EventConsumer__SWIG_1(self, argc, argv); + } + } + } + if (argc == 3) { + int _v = 0; + int res = SWIG_AsCharPtrAndSize(argv[0], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + { + int res = SWIG_AsVal_int(argv[2], NULL); + _v = SWIG_CheckState(res); + } + if (_v) { + return _wrap_new_EventConsumer__SWIG_0(self, argc, argv); + } + } + } + } + +fail: + SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'new_EventConsumer'.\n" + " Possible C/C++ prototypes are:\n" + " EventConsumer::EventConsumer(char const *,char const *,int)\n" + " EventConsumer::EventConsumer(char const *,char const *)\n" + " EventConsumer::EventConsumer(char const *)\n" + " EventConsumer::EventConsumer()\n"); + return 0; +} + + SWIGINTERN PyObject *_wrap_delete_EventConsumer(PyObject *self, PyObject *args) { PyObject *resultobj = 0; EventConsumer *arg1 = (EventConsumer *) 0 ; @@ -6255,11 +6381,11 @@ fail: } -SWIGINTERN PyObject *_wrap_EventConsumer_bind(PyObject *self, PyObject *args) { +SWIGINTERN PyObject *_wrap_EventConsumer_bind__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; EventConsumer *arg1 = (EventConsumer *) 0 ; char *arg2 = (char *) 0 ; - char *arg3 = (char *) "" ; + char *arg3 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; @@ -6268,10 +6394,9 @@ SWIGINTERN PyObject *_wrap_EventConsumer_bind(PyObject *self, PyObject *args) { int res3 ; char *buf3 = 0 ; int alloc3 = 0 ; - PyObject *swig_obj[3] ; int result; - if (!SWIG_Python_UnpackTuple(args, "EventConsumer_bind", 2, 3, swig_obj)) SWIG_fail; + if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_EventConsumer, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "EventConsumer_bind" "', argument " "1"" of type '" "EventConsumer *""'"); @@ -6282,13 +6407,11 @@ SWIGINTERN PyObject *_wrap_EventConsumer_bind(PyObject *self, PyObject *args) { SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "EventConsumer_bind" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); - if (swig_obj[2]) { - res3 = SWIG_AsCharPtrAndSize(swig_obj[2], &buf3, NULL, &alloc3); - if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "EventConsumer_bind" "', argument " "3"" of type '" "char const *""'"); - } - arg3 = reinterpret_cast< char * >(buf3); + res3 = SWIG_AsCharPtrAndSize(swig_obj[2], &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "EventConsumer_bind" "', argument " "3"" of type '" "char const *""'"); } + arg3 = reinterpret_cast< char * >(buf3); result = (int)(arg1)->bind((char const *)arg2,(char const *)arg3); resultobj = SWIG_From_int(static_cast< int >(result)); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; @@ -6301,6 +6424,86 @@ fail: } +SWIGINTERN PyObject *_wrap_EventConsumer_bind__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { + PyObject *resultobj = 0; + EventConsumer *arg1 = (EventConsumer *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int result; + + if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_EventConsumer, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "EventConsumer_bind" "', argument " "1"" of type '" "EventConsumer *""'"); + } + arg1 = reinterpret_cast< EventConsumer * >(argp1); + res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "EventConsumer_bind" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = reinterpret_cast< char * >(buf2); + result = (int)(arg1)->bind((char const *)arg2); + resultobj = SWIG_From_int(static_cast< int >(result)); + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + return NULL; +} + + +SWIGINTERN PyObject *_wrap_EventConsumer_bind(PyObject *self, PyObject *args) { + Py_ssize_t argc; + PyObject *argv[4] = { + 0 + }; + + if (!(argc = SWIG_Python_UnpackTuple(args, "EventConsumer_bind", 0, 3, argv))) SWIG_fail; + --argc; + if (argc == 2) { + int _v = 0; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_EventConsumer, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_EventConsumer_bind__SWIG_1(self, argc, argv); + } + } + } + if (argc == 3) { + int _v = 0; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_EventConsumer, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[2], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_EventConsumer_bind__SWIG_0(self, argc, argv); + } + } + } + } + +fail: + SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'EventConsumer_bind'.\n" + " Possible C/C++ prototypes are:\n" + " EventConsumer::bind(char const *,char const *)\n" + " EventConsumer::bind(char const *)\n"); + return 0; +} + + SWIGINTERN PyObject *_wrap_EventConsumer_pop(PyObject *self, PyObject *args) { PyObject *resultobj = 0; EventConsumer *arg1 = (EventConsumer *) 0 ; @@ -7094,30 +7297,27 @@ fail: } -SWIGINTERN PyObject *_wrap_CoreSession_hangup(PyObject *self, PyObject *args) { +SWIGINTERN PyObject *_wrap_CoreSession_hangup__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; CoreSession *arg1 = (CoreSession *) 0 ; - char *arg2 = (char *) "normal_clearing" ; + char *arg2 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; - PyObject *swig_obj[2] ; - if (!SWIG_Python_UnpackTuple(args, "CoreSession_hangup", 1, 2, swig_obj)) SWIG_fail; + if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_hangup" "', argument " "1"" of type '" "CoreSession *""'"); } arg1 = reinterpret_cast< CoreSession * >(argp1); - if (swig_obj[1]) { - res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_hangup" "', argument " "2"" of type '" "char const *""'"); - } - arg2 = reinterpret_cast< char * >(buf2); + res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_hangup" "', argument " "2"" of type '" "char const *""'"); } + arg2 = reinterpret_cast< char * >(buf2); (arg1)->hangup((char const *)arg2); resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; @@ -7128,6 +7328,66 @@ fail: } +SWIGINTERN PyObject *_wrap_CoreSession_hangup__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { + PyObject *resultobj = 0; + CoreSession *arg1 = (CoreSession *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + + if ((nobjs < 1) || (nobjs > 1)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_hangup" "', argument " "1"" of type '" "CoreSession *""'"); + } + arg1 = reinterpret_cast< CoreSession * >(argp1); + (arg1)->hangup(); + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_CoreSession_hangup(PyObject *self, PyObject *args) { + Py_ssize_t argc; + PyObject *argv[3] = { + 0 + }; + + if (!(argc = SWIG_Python_UnpackTuple(args, "CoreSession_hangup", 0, 2, argv))) SWIG_fail; + --argc; + if (argc == 1) { + int _v = 0; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CoreSession, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_CoreSession_hangup__SWIG_1(self, argc, argv); + } + } + if (argc == 2) { + int _v = 0; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CoreSession, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_CoreSession_hangup__SWIG_0(self, argc, argv); + } + } + } + +fail: + SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'CoreSession_hangup'.\n" + " Possible C/C++ prototypes are:\n" + " CoreSession::hangup(char const *)\n" + " CoreSession::hangup()\n"); + return 0; +} + + SWIGINTERN PyObject *_wrap_CoreSession_hangupState(PyObject *self, PyObject *args) { PyObject *resultobj = 0; CoreSession *arg1 = (CoreSession *) 0 ; @@ -7408,12 +7668,12 @@ fail: } -SWIGINTERN PyObject *_wrap_CoreSession_sayPhrase(PyObject *self, PyObject *args) { +SWIGINTERN PyObject *_wrap_CoreSession_sayPhrase__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { PyObject *resultobj = 0; CoreSession *arg1 = (CoreSession *) 0 ; char *arg2 = (char *) 0 ; - char *arg3 = (char *) "" ; - char *arg4 = (char *) NULL ; + char *arg3 = (char *) 0 ; + char *arg4 = (char *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; @@ -7425,9 +7685,8 @@ SWIGINTERN PyObject *_wrap_CoreSession_sayPhrase(PyObject *self, PyObject *args) int res4 ; char *buf4 = 0 ; int alloc4 = 0 ; - PyObject *swig_obj[4] ; - if (!SWIG_Python_UnpackTuple(args, "CoreSession_sayPhrase", 2, 4, swig_obj)) SWIG_fail; + if ((nobjs < 4) || (nobjs > 4)) SWIG_fail; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_sayPhrase" "', argument " "1"" of type '" "CoreSession *""'"); @@ -7438,20 +7697,16 @@ SWIGINTERN PyObject *_wrap_CoreSession_sayPhrase(PyObject *self, PyObject *args) SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_sayPhrase" "', argument " "2"" of type '" "char const *""'"); } arg2 = reinterpret_cast< char * >(buf2); - if (swig_obj[2]) { - res3 = SWIG_AsCharPtrAndSize(swig_obj[2], &buf3, NULL, &alloc3); - if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CoreSession_sayPhrase" "', argument " "3"" of type '" "char const *""'"); - } - arg3 = reinterpret_cast< char * >(buf3); + res3 = SWIG_AsCharPtrAndSize(swig_obj[2], &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CoreSession_sayPhrase" "', argument " "3"" of type '" "char const *""'"); } - if (swig_obj[3]) { - res4 = SWIG_AsCharPtrAndSize(swig_obj[3], &buf4, NULL, &alloc4); - if (!SWIG_IsOK(res4)) { - SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "CoreSession_sayPhrase" "', argument " "4"" of type '" "char const *""'"); - } - arg4 = reinterpret_cast< char * >(buf4); + arg3 = reinterpret_cast< char * >(buf3); + res4 = SWIG_AsCharPtrAndSize(swig_obj[3], &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "CoreSession_sayPhrase" "', argument " "4"" of type '" "char const *""'"); } + arg4 = reinterpret_cast< char * >(buf4); (arg1)->sayPhrase((char const *)arg2,(char const *)arg3,(char const *)arg4); resultobj = SWIG_Py_Void(); if (alloc2 == SWIG_NEWOBJ) delete[] buf2; @@ -7466,6 +7721,149 @@ fail: } +SWIGINTERN PyObject *_wrap_CoreSession_sayPhrase__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { + PyObject *resultobj = 0; + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + char *arg3 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int res3 ; + char *buf3 = 0 ; + int alloc3 = 0 ; + + if ((nobjs < 3) || (nobjs > 3)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_sayPhrase" "', argument " "1"" of type '" "CoreSession *""'"); + } + arg1 = reinterpret_cast< CoreSession * >(argp1); + res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_sayPhrase" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = reinterpret_cast< char * >(buf2); + res3 = SWIG_AsCharPtrAndSize(swig_obj[2], &buf3, NULL, &alloc3); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CoreSession_sayPhrase" "', argument " "3"" of type '" "char const *""'"); + } + arg3 = reinterpret_cast< char * >(buf3); + (arg1)->sayPhrase((char const *)arg2,(char const *)arg3); + resultobj = SWIG_Py_Void(); + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + if (alloc3 == SWIG_NEWOBJ) delete[] buf3; + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + if (alloc3 == SWIG_NEWOBJ) delete[] buf3; + return NULL; +} + + +SWIGINTERN PyObject *_wrap_CoreSession_sayPhrase__SWIG_2(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) { + PyObject *resultobj = 0; + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + + if ((nobjs < 2) || (nobjs > 2)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_sayPhrase" "', argument " "1"" of type '" "CoreSession *""'"); + } + arg1 = reinterpret_cast< CoreSession * >(argp1); + res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_sayPhrase" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = reinterpret_cast< char * >(buf2); + (arg1)->sayPhrase((char const *)arg2); + resultobj = SWIG_Py_Void(); + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + return NULL; +} + + +SWIGINTERN PyObject *_wrap_CoreSession_sayPhrase(PyObject *self, PyObject *args) { + Py_ssize_t argc; + PyObject *argv[5] = { + 0 + }; + + if (!(argc = SWIG_Python_UnpackTuple(args, "CoreSession_sayPhrase", 0, 4, argv))) SWIG_fail; + --argc; + if (argc == 2) { + int _v = 0; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CoreSession, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_CoreSession_sayPhrase__SWIG_2(self, argc, argv); + } + } + } + if (argc == 3) { + int _v = 0; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CoreSession, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[2], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_CoreSession_sayPhrase__SWIG_1(self, argc, argv); + } + } + } + } + if (argc == 4) { + int _v = 0; + void *vptr = 0; + int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CoreSession, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[2], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + int res = SWIG_AsCharPtrAndSize(argv[3], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_CoreSession_sayPhrase__SWIG_0(self, argc, argv); + } + } + } + } + } + +fail: + SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'CoreSession_sayPhrase'.\n" + " Possible C/C++ prototypes are:\n" + " CoreSession::sayPhrase(char const *,char const *,char const *)\n" + " CoreSession::sayPhrase(char const *,char const *)\n" + " CoreSession::sayPhrase(char const *)\n"); + return 0; +} + + SWIGINTERN PyObject *_wrap_CoreSession_hangupCause(PyObject *self, PyObject *args) { PyObject *resultobj = 0; CoreSession *arg1 = (CoreSession *) 0 ; From fa67e000bf9340063ff2ae16909a47dd8531d2d8 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 9 Nov 2026 21:53:18 +0300 Subject: [PATCH 45/88] [mod_sofia] scan-build: sofia_receive_message(). Value stored to 'to_tag' during its initialization is never read (#3277) --- src/mod/endpoints/mod_sofia/mod_sofia.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 8cdc3f92ba..209c7ca4bc 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -2506,8 +2506,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi /* Set sip_to_tag to local tag for inbound channels. */ if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) { - const char* to_tag = ""; - to_tag = switch_str_nil(nta_leg_get_tag(nua_get_dialog_state_leg(tech_pvt->nh))); + const char *to_tag = switch_str_nil(nta_leg_get_tag(nua_get_dialog_state_leg(tech_pvt->nh))); if(to_tag) { switch_channel_set_variable(channel, "sip_to_tag", to_tag); } From b791f28d010f165c8e057602c2b7e60111706454 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 9 Nov 2026 23:03:18 +0300 Subject: [PATCH 46/88] [GHA] Move CI to Debian 13 (Trixie). (#3278) Use the freeswitch-public-ci-base:trixie-amd64 image for unit-tests, D-in-D unit-tests and scan-build. ci.sh: use scan-build-14 on bookworm and the default scan-build (clang 19) otherwise. --- .../{bookworm => trixie}/amd64/CI/Dockerfile | 2 +- .github/workflows/ci.yml | 2 +- .github/workflows/scan-build.yml | 2 +- .github/workflows/unit-test-dind.yml | 4 ++-- .github/workflows/unit-test.yml | 2 +- ci.sh | 16 +++++++++++++--- tests/unit/run-tests-docker.sh | 2 +- 7 files changed, 20 insertions(+), 10 deletions(-) rename .github/docker/debian/{bookworm => trixie}/amd64/CI/Dockerfile (92%) diff --git a/.github/docker/debian/bookworm/amd64/CI/Dockerfile b/.github/docker/debian/trixie/amd64/CI/Dockerfile similarity index 92% rename from .github/docker/debian/bookworm/amd64/CI/Dockerfile rename to .github/docker/debian/trixie/amd64/CI/Dockerfile index 0fd3cec5f4..26bf74d296 100644 --- a/.github/docker/debian/bookworm/amd64/CI/Dockerfile +++ b/.github/docker/debian/trixie/amd64/CI/Dockerfile @@ -1,4 +1,4 @@ -ARG BUILDER_IMAGE=signalwire/freeswitch-public-ci-base:bookworm-amd64 +ARG BUILDER_IMAGE=signalwire/freeswitch-public-ci-base:trixie-amd64 FROM ${BUILDER_IMAGE} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d65a6171a..d9eb5c28fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ on: default: false env: - CI_BASE_STATIC_IMAGE: signalwire/freeswitch-public-ci-base:bookworm-amd64 + CI_BASE_STATIC_IMAGE: signalwire/freeswitch-public-ci-base:trixie-amd64 DOCKER_BUILD_SUMMARY: false DOCKER_BUILD_CHECKS_ANNOTATIONS: false DOCKER_BUILD_RECORD_UPLOAD: false diff --git a/.github/workflows/scan-build.yml b/.github/workflows/scan-build.yml index 4237a28c4f..76e51941a9 100644 --- a/.github/workflows/scan-build.yml +++ b/.github/workflows/scan-build.yml @@ -16,7 +16,7 @@ jobs: scan-build: runs-on: ubuntu-latest container: - image: signalwire/freeswitch-public-ci-base:bookworm-amd64 + image: signalwire/freeswitch-public-ci-base:trixie-amd64 options: --privileged env: DEBIAN_FRONTEND: noninteractive diff --git a/.github/workflows/unit-test-dind.yml b/.github/workflows/unit-test-dind.yml index 082763c07e..4688d5523b 100644 --- a/.github/workflows/unit-test-dind.yml +++ b/.github/workflows/unit-test-dind.yml @@ -23,7 +23,7 @@ jobs: unit-tests: runs-on: ubuntu-latest container: - image: signalwire/freeswitch-public-ci-base:bookworm-amd64 + image: signalwire/freeswitch-public-ci-base:trixie-amd64 options: --privileged env: DEBIAN_FRONTEND: noninteractive @@ -65,7 +65,7 @@ jobs: echo "logs_path=${GITHUB_WORKSPACE}/freeswitch/tests/unit/logs" >> $GITHUB_OUTPUT "${GITHUB_WORKSPACE}/freeswitch/tests/unit/run-tests-docker.sh" \ - --base-image signalwire/freeswitch-public-ci-base:bookworm-amd64 \ + --base-image signalwire/freeswitch-public-ci-base:trixie-amd64 \ --cpus ${{ env.NUM_CPU_PER_CONTAINER }} \ --image-tag ci.local \ --max-containers ${{ env.MAX_CONTAINERS }} \ diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 6cf6f24c97..86c05ae03f 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -25,7 +25,7 @@ on: description: 'Container image to use for running tests' required: false type: string - default: 'signalwire/freeswitch-public-ci-base:bookworm-amd64' + default: 'signalwire/freeswitch-public-ci-base:trixie-amd64' working-directory: description: 'Working directory for running tests' required: false diff --git a/ci.sh b/ci.sh index 9207bcd1a1..edff73e934 100755 --- a/ci.sh +++ b/ci.sh @@ -131,14 +131,24 @@ build_freeswitch() ;; "scan-build") - if ! command -v scan-build-14 > /dev/null 2>&1; then - echo "Error: scan-build-14 command not found. Please ensure clang static analyzer is installed." >&2 + # Use scan-build-14 for bookworm, default scan-build otherwise + DEBIAN_CODENAME=$(. /etc/os-release && echo "$VERSION_CODENAME") + if [[ "$DEBIAN_CODENAME" == "bookworm" ]]; then + SCAN_BUILD_CMD="scan-build-14" + else + SCAN_BUILD_CMD="scan-build" + fi + + if ! command -v $SCAN_BUILD_CMD > /dev/null 2>&1; then + echo "Error: $SCAN_BUILD_CMD command not found. Please ensure clang static analyzer is installed." >&2 exit 1 fi + echo "Using: $SCAN_BUILD_CMD (Debian: $DEBIAN_CODENAME)" + mkdir -p scan-build - scan-build-14 \ + $SCAN_BUILD_CMD \ --force-analyze-debug-code \ --status-bugs \ -o ./scan-build/ \ diff --git a/tests/unit/run-tests-docker.sh b/tests/unit/run-tests-docker.sh index 91e52d3b3d..2b7b0105a0 100755 --- a/tests/unit/run-tests-docker.sh +++ b/tests/unit/run-tests-docker.sh @@ -92,7 +92,7 @@ if ! docker build \ --build-arg BUILDER_IMAGE="$BASE_IMAGE" \ --build-context sofia-sip="$SOFIA_SIP_PATH" \ --build-context freeswitch="$FREESWITCH_PATH" \ - --file "$FREESWITCH_PATH/.github/docker/debian/bookworm/amd64/CI/Dockerfile" \ + --file "$FREESWITCH_PATH/.github/docker/debian/trixie/amd64/CI/Dockerfile" \ --tag "$IMAGE_TAG" \ "$FREESWITCH_PATH/.github/docker/debian" > "$BUILD_LOG" 2>&1; then echo "Docker build failed! Build log:" From 0dd016319f673f4c34cd57c9466a37b96fa76a40 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 13 Nov 2026 17:27:39 +0300 Subject: [PATCH 47/88] [Build-System] Windows: Upgrade libnode to v24.22.3_1 (#3280) --- w32/libnode-version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/w32/libnode-version.props b/w32/libnode-version.props index 2a7565207a..1f53cafa2d 100644 --- a/w32/libnode-version.props +++ b/w32/libnode-version.props @@ -4,7 +4,7 @@ - 24.22.1 + 24.22.3 1 From 9b38dcf201a5c61d84a96ce9c7f3d77aee094ff9 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 16 Nov 2026 19:41:20 +0300 Subject: [PATCH 48/88] [Build-System] Windows: Update libpq to v17.11_3 (#3286) --- w32/libpq-version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/w32/libpq-version.props b/w32/libpq-version.props index 670c58fdc8..cb9f3174ca 100644 --- a/w32/libpq-version.props +++ b/w32/libpq-version.props @@ -5,7 +5,7 @@ 17.11 - 2 + 3 true From 07dedba4a4ce5d392a763f2c7a054806b88bb37a Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 16 Nov 2026 21:54:28 +0300 Subject: [PATCH 49/88] [core] Replace GetARGBBlend with ARGBBlend in switch_img_patch_rgb and add a unit test, GetARGBBlend is removed from newer libyuv (#3287) --- src/switch_core_video.c | 20 +------ tests/unit/switch_core.c | 121 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 18 deletions(-) diff --git a/src/switch_core_video.c b/src/switch_core_video.c index 0e1d6cba6b..351b5fbc35 100644 --- a/src/switch_core_video.c +++ b/src/switch_core_video.c @@ -370,8 +370,6 @@ SWITCH_DECLARE(void) switch_img_attenuate(switch_image_t *img) SWITCH_DECLARE(void) switch_img_patch_rgb(switch_image_t *IMG, switch_image_t *img, int x, int y, switch_bool_t noalpha) { #ifdef SWITCH_HAVE_YUV - int i; - if (noalpha) { switch_img_patch_rgb_noalpha(IMG, img, x, y); return; @@ -386,19 +384,9 @@ SWITCH_DECLARE(void) switch_img_patch_rgb(switch_image_t *IMG, switch_image_t *i int dst_stride_argb = IMG->stride[SWITCH_PLANE_PACKED]; int width = MIN(img->d_w, IMG->d_w - abs(x)); int height = MIN(img->d_h, IMG->d_h - abs(y)); - void (*ARGBBlendRow)(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) = GetARGBBlend(); // switch_img_attenuate(img); - // Coalesce rows. we have same size images, treat as a single row - if (src_stride_argb0 == width * 4 && - src_stride_argb1 == width * 4 && - x == 0 && y == 0) { - width *= height; - height = 1; - src_stride_argb0 = src_stride_argb1 = dst_stride_argb = 0; - } - if (y) { src_argb1 += (y * IMG->d_w * 4); dst_argb += (y * IMG->d_w * 4); @@ -408,12 +396,8 @@ SWITCH_DECLARE(void) switch_img_patch_rgb(switch_image_t *IMG, switch_image_t *i dst_argb += (x * 4); } - for (i = 0; i < height; ++i) { - ARGBBlendRow(src_argb0, src_argb1, dst_argb, width); - src_argb0 += src_stride_argb0; - src_argb1 += src_stride_argb1; - dst_argb += dst_stride_argb; - } + /* ARGBBlend coalesces rows internally. */ + ARGBBlend(src_argb0, src_stride_argb0, src_argb1, src_stride_argb1, dst_argb, dst_stride_argb, width, height); } #endif } diff --git a/tests/unit/switch_core.c b/tests/unit/switch_core.c index 096c8d014a..a5fc60d939 100644 --- a/tests/unit/switch_core.c +++ b/tests/unit/switch_core.c @@ -706,6 +706,127 @@ FST_CORE_BEGIN("./conf") } } FST_TEST_END() + + FST_TEST_BEGIN(test_switch_img_patch_rgb) + { + /* Odd sizes on purpose: exercise the SIMD remainder paths inside libyuv. */ + int W = 127, H = 63; + /* {x, y, w, h}: the full-frame same-size case is the only one where all strides + equal width*4, so it takes libyuv's coalesced single-row path; the others take + the per-row path, the last one patches flush against the bottom-right corner. */ + int cases[][4] = { {0, 0, 127, 63}, {0, 0, 61, 29}, {1, 0, 61, 29}, {0, 1, 61, 29}, {33, 17, 61, 29}, {66, 34, 61, 29} }; + switch_bool_t noalpha[] = { SWITCH_FALSE, SWITCH_TRUE }; + uint32_t seed = 12345; + int p, n, i, j; + + for (n = 0; n < 2; n++) { + for (p = 0; p < (int)(sizeof(cases) / sizeof(cases[0])); p++) { + int px = cases[p][0], py = cases[p][1], w = cases[p][2], h = cases[p][3]; + switch_image_t *IMG = switch_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, W, H, 1); + switch_image_t *img = switch_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, w, h, 1); + uint8_t *pristine = malloc((size_t)W * H * 4); + int outside_ok = 1, region_ok = 1; + + fst_check(IMG && img && pristine); + + if (!IMG || !img || !pristine) { + switch_img_free(&IMG); + switch_img_free(&img); + switch_safe_free(pristine); + continue; + } + + /* Deterministic pseudo-random pixels; alpha covers the full range */ + for (i = 0; i < H; i++) { + uint8_t *row = IMG->planes[SWITCH_PLANE_PACKED] + i * IMG->stride[SWITCH_PLANE_PACKED]; + + for (j = 0; j < W * 4; j++) { + seed = seed * 1103515245 + 12345; + row[j] = (uint8_t)(seed >> 16); + } + + memcpy(pristine + (size_t)i * W * 4, row, W * 4); + } + + for (i = 0; i < h; i++) { + uint8_t *row = img->planes[SWITCH_PLANE_PACKED] + i * img->stride[SWITCH_PLANE_PACKED]; + + for (j = 0; j < w * 4; j++) { + seed = seed * 1103515245 + 12345; + row[j] = (uint8_t)(seed >> 16); + } + + if (noalpha[n]) { + /* Opaque patch: the noalpha path must then copy src pixels verbatim */ + for (j = 3; j < w * 4; j += 4) { + row[j] = 255; + } + } + } + + switch_img_patch_rgb(IMG, img, px, py, noalpha[n]); + + for (i = 0; i < H && outside_ok && region_ok; i++) { + uint8_t *row = IMG->planes[SWITCH_PLANE_PACKED] + i * IMG->stride[SWITCH_PLANE_PACKED]; + uint8_t *old = pristine + (size_t)i * W * 4; + uint8_t *src = NULL; + + if (i >= py && i < py + h) { + src = img->planes[SWITCH_PLANE_PACKED] + (i - py) * img->stride[SWITCH_PLANE_PACKED]; + } + + for (j = 0; j < W; j++) { + if (!src || j < px || j >= px + w) { + /* Pixels outside the patched region must be untouched */ + if (memcmp(row + j * 4, old + j * 4, 4)) { + outside_ok = 0; + break; + } + } else if (noalpha[n]) { + /* Opaque src: expect a verbatim copy */ + if (memcmp(row + j * 4, src + (j - px) * 4, 4)) { + region_ok = 0; + break; + } + } else { + /* libyuv ARGBBlend reference: dst = clamp255((((256 - a) * b) >> 8) + f), dst alpha = 255 */ + const uint8_t *f = src + (j - px) * 4; + const uint8_t *b = old + j * 4; + uint32_t a = f[3]; + int k; + + for (k = 0; k < 3; k++) { + uint32_t e = (((256 - a) * b[k]) >> 8) + f[k]; + + if (e > 255) e = 255; + + if (row[j * 4 + k] != (uint8_t)e) { + region_ok = 0; + break; + } + } + + if (row[j * 4 + 3] != 255) { + region_ok = 0; + } + + if (!region_ok) break; + } + } + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "patch_rgb x=%d y=%d w=%d h=%d noalpha=%d outside_ok=%d region_ok=%d\n", + px, py, w, h, noalpha[n], outside_ok, region_ok); + fst_check(outside_ok); + fst_check(region_ok); + + switch_img_free(&IMG); + switch_img_free(&img); + free(pristine); + } + } + } + FST_TEST_END() } FST_SUITE_END() } From 379b73c3c31999659f63a48f00e66db72d6eb8b8 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 16 Nov 2026 20:17:39 +0300 Subject: [PATCH 50/88] [libyuv] Update to hash 79ca9187e540faaaca47b34622e110d07f335d05 from https://chromium.googlesource.com/libyuv/libyuv/ --- Makefile.am | 31 +- libs/libyuv/.clang-format | 6 + libs/libyuv/.gitignore | 37 + libs/libyuv/.gn | 41 + libs/libyuv/AUTHORS | 4 + libs/libyuv/Android.bp | 96 +- libs/libyuv/Android.mk | 55 +- libs/libyuv/BUILD.bazel | 287 + libs/libyuv/BUILD.gn | 361 +- libs/libyuv/CM_linux_packages.cmake | 7 +- libs/libyuv/CMakeLists.txt | 310 +- libs/libyuv/DEPS | 1685 +- libs/libyuv/DIR_METADATA | 3 + libs/libyuv/GEMINI.md | 177 + libs/libyuv/OWNERS | 8 +- libs/libyuv/PRESUBMIT.py | 103 +- libs/libyuv/README.chromium | 11 +- libs/libyuv/README.md | 3 +- libs/libyuv/WORKSPACE.bazel | 14 + libs/libyuv/build_overrides/build.gni | 29 +- .../build_overrides/partition_alloc.gni | 17 + libs/libyuv/cleanup_links.py | 107 - libs/libyuv/codereview.settings | 3 +- libs/libyuv/docs/deprecated_builds.md | 39 +- libs/libyuv/docs/environment_variables.md | 34 +- libs/libyuv/docs/feature_detection.md | 108 + libs/libyuv/docs/formats.md | 100 +- libs/libyuv/docs/getting_started.md | 177 +- libs/libyuv/download_vs_toolchain.py | 8 +- libs/libyuv/include/libyuv.h | 3 +- libs/libyuv/include/libyuv/basic_types.h | 36 - libs/libyuv/include/libyuv/compare.h | 3 + libs/libyuv/include/libyuv/compare_row.h | 367 +- libs/libyuv/include/libyuv/convert.h | 838 +- libs/libyuv/include/libyuv/convert_argb.h | 1969 +- libs/libyuv/include/libyuv/convert_from.h | 288 +- .../libyuv/include/libyuv/convert_from_argb.h | 394 +- libs/libyuv/include/libyuv/cpu_id.h | 87 +- libs/libyuv/include/libyuv/cpu_support.h | 147 + .../include/libyuv/loongson_intrinsics.h | 14 + libs/libyuv/include/libyuv/macros_msa.h | 233 - libs/libyuv/include/libyuv/mjpeg_decoder.h | 35 +- libs/libyuv/include/libyuv/planar_functions.h | 506 +- libs/libyuv/include/libyuv/rotate.h | 184 +- libs/libyuv/include/libyuv/rotate_argb.h | 2 + libs/libyuv/include/libyuv/rotate_row.h | 559 +- libs/libyuv/include/libyuv/row.h | 7570 ++++-- libs/libyuv/include/libyuv/row_sve.h | 2524 ++ libs/libyuv/include/libyuv/scale.h | 267 +- libs/libyuv/include/libyuv/scale_argb.h | 2 + libs/libyuv/include/libyuv/scale_rgb.h | 44 + libs/libyuv/include/libyuv/scale_row.h | 1571 +- libs/libyuv/include/libyuv/scale_uv.h | 52 + libs/libyuv/include/libyuv/version.h | 2 +- libs/libyuv/include/libyuv/video_common.h | 80 +- libs/libyuv/infra/config/OWNERS | 3 + libs/libyuv/infra/config/PRESUBMIT.py | 17 + libs/libyuv/infra/config/README.md | 2 + libs/libyuv/infra/config/codereview.settings | 6 + libs/libyuv/infra/config/commit-queue.cfg | 144 + libs/libyuv/infra/config/cr-buildbucket.cfg | 1130 + libs/libyuv/infra/config/luci-logdog.cfg | 9 + libs/libyuv/infra/config/luci-milo.cfg | 246 + libs/libyuv/infra/config/luci-scheduler.cfg | 385 + libs/libyuv/infra/config/main.star | 399 + libs/libyuv/infra/config/project.cfg | 15 + libs/libyuv/infra/config/realms.cfg | 111 + libs/libyuv/libyuv.bzl | 50 + libs/libyuv/libyuv.gni | 19 +- libs/libyuv/libyuv.gyp | 137 + libs/libyuv/libyuv.gypi | 96 + libs/libyuv/linux.mk | 54 +- libs/libyuv/pylintrc | 36 +- .../riscv_script/prepare_toolchain_qemu.sh | 74 + libs/libyuv/riscv_script/riscv-clang.cmake | 56 + libs/libyuv/riscv_script/run_qemu.sh | 15 + libs/libyuv/source/compare.cc | 630 +- libs/libyuv/source/compare_common.cc | 167 +- libs/libyuv/source/compare_gcc.cc | 1654 +- libs/libyuv/source/compare_hvx.cc | 381 + libs/libyuv/source/compare_mmi.cc | 123 - libs/libyuv/source/compare_msa.cc | 97 - libs/libyuv/source/compare_neon.cc | 316 +- libs/libyuv/source/compare_neon64.cc | 445 +- libs/libyuv/source/compare_wasm.cc | 345 + libs/libyuv/source/compare_win.cc | 1171 +- libs/libyuv/source/convert.cc | 5637 ++-- libs/libyuv/source/convert_argb.cc | 8905 ++++++- libs/libyuv/source/convert_from.cc | 1448 +- libs/libyuv/source/convert_from_argb.cc | 5167 +++- libs/libyuv/source/convert_jpeg.cc | 142 +- libs/libyuv/source/convert_to_argb.cc | 600 +- libs/libyuv/source/convert_to_i420.cc | 483 +- libs/libyuv/source/cpu_id.cc | 416 +- libs/libyuv/source/mjpeg_decoder.cc | 185 +- libs/libyuv/source/mjpeg_validate.cc | 14 +- libs/libyuv/source/planar_functions.cc | 4968 +++- libs/libyuv/source/rotate.cc | 1272 +- libs/libyuv/source/rotate_any.cc | 170 +- libs/libyuv/source/rotate_argb.cc | 327 +- libs/libyuv/source/rotate_common.cc | 124 +- libs/libyuv/source/rotate_gcc.cc | 2012 +- libs/libyuv/source/rotate_hvx.cc | 388 + libs/libyuv/source/rotate_lasx.cc | 506 + libs/libyuv/source/rotate_lsx.cc | 383 + libs/libyuv/source/rotate_mmi.cc | 291 - libs/libyuv/source/rotate_msa.cc | 250 - libs/libyuv/source/rotate_neon.cc | 767 +- libs/libyuv/source/rotate_neon64.cc | 859 +- libs/libyuv/source/rotate_rvv.cc | 275 + libs/libyuv/source/rotate_sme.cc | 313 + libs/libyuv/source/rotate_sve.cc | 279 + libs/libyuv/source/rotate_wasm.cc | 328 + libs/libyuv/source/rotate_win.cc | 1399 +- libs/libyuv/source/row_any.cc | 2888 +- libs/libyuv/source/row_common.cc | 3687 ++- libs/libyuv/source/row_gcc.cc | 21662 ++++++++++++---- libs/libyuv/source/row_hvx.cc | 1863 ++ libs/libyuv/source/row_lasx.cc | 3558 +++ libs/libyuv/source/row_lsx.cc | 3112 +++ libs/libyuv/source/row_mmi.cc | 6042 ----- libs/libyuv/source/row_msa.cc | 3512 --- libs/libyuv/source/row_neon.cc | 4797 ++-- libs/libyuv/source/row_neon64.cc | 6768 +++-- libs/libyuv/source/row_rvv.cc | 3199 +++ libs/libyuv/source/row_sme.cc | 1169 + libs/libyuv/source/row_sve.cc | 1785 ++ libs/libyuv/source/row_wasm.cc | 2047 ++ libs/libyuv/source/row_win.cc | 16423 +++++++----- libs/libyuv/source/scale.cc | 2369 +- libs/libyuv/source/scale_any.cc | 1009 +- libs/libyuv/source/scale_argb.cc | 993 +- libs/libyuv/source/scale_common.cc | 1178 +- libs/libyuv/source/scale_gcc.cc | 4999 +++- libs/libyuv/source/scale_hvx.cc | 625 + libs/libyuv/source/scale_lsx.cc | 975 + libs/libyuv/source/scale_mmi.cc | 1113 - libs/libyuv/source/scale_msa.cc | 949 - libs/libyuv/source/scale_neon.cc | 1309 +- libs/libyuv/source/scale_neon64.cc | 1931 +- libs/libyuv/source/scale_rgb.cc | 84 + libs/libyuv/source/scale_rvv.cc | 1348 + libs/libyuv/source/scale_sme.cc | 628 + libs/libyuv/source/scale_uv.cc | 1986 ++ libs/libyuv/source/scale_wasm.cc | 713 + libs/libyuv/source/scale_win.cc | 3526 ++- libs/libyuv/source/test.sh | 35 + libs/libyuv/tools_libyuv/OWNERS | 5 +- .../tools_libyuv/autoroller/roll_deps.py | 1146 +- .../autoroller/unittests/roll_deps_test.py | 196 +- .../autoroller/unittests/testdata/DEPS | 1 + libs/libyuv/tools_libyuv/get_landmines.py | 34 +- libs/libyuv/tools_libyuv/msan/OWNERS | 4 +- libs/libyuv/tools_libyuv/ubsan/OWNERS | 5 +- .../tools_libyuv/valgrind/chrome_tests.bat | 53 - .../tools_libyuv/valgrind/chrome_tests.py | 869 - .../tools_libyuv/valgrind/chrome_tests.sh | 94 - libs/libyuv/tools_libyuv/valgrind/common.py | 256 - .../tools_libyuv/valgrind/gdb_helper.py | 91 - .../tools_libyuv/valgrind/libyuv_tests.bat | 79 - .../tools_libyuv/valgrind/libyuv_tests.py | 139 - .../tools_libyuv/valgrind/libyuv_tests.sh | 101 - .../tools_libyuv/valgrind/locate_valgrind.sh | 73 - .../tools_libyuv/valgrind/memcheck/OWNERS | 1 - .../valgrind/memcheck/PRESUBMIT.py | 99 - .../valgrind/memcheck/suppressions.txt | 21 - .../valgrind/memcheck/suppressions_mac.txt | 5 - .../valgrind/memcheck/suppressions_win32.txt | 5 - .../tools_libyuv/valgrind/memcheck_analyze.py | 644 - libs/libyuv/tools_libyuv/valgrind/valgrind.sh | 110 - .../tools_libyuv/valgrind/valgrind_test.py | 517 - libs/libyuv/unit_test/basictypes_test.cc | 35 +- libs/libyuv/unit_test/color_test.cc | 473 +- libs/libyuv/unit_test/compare_test.cc | 444 +- libs/libyuv/unit_test/convert_argb_test.cc | 3165 +++ libs/libyuv/unit_test/convert_test.cc | 4089 +-- libs/libyuv/unit_test/cpu_test.cc | 464 +- libs/libyuv/unit_test/cpu_thread_test.cc | 12 +- libs/libyuv/unit_test/math_test.cc | 73 +- libs/libyuv/unit_test/planar_test.cc | 5049 +++- libs/libyuv/unit_test/rotate_argb_test.cc | 291 +- libs/libyuv/unit_test/rotate_test.cc | 715 +- libs/libyuv/unit_test/scale_argb_test.cc | 358 +- libs/libyuv/unit_test/scale_plane_test.cc | 919 + libs/libyuv/unit_test/scale_rgb_test.cc | 280 + libs/libyuv/unit_test/scale_test.cc | 1259 +- libs/libyuv/unit_test/scale_uv_test.cc | 657 + libs/libyuv/unit_test/testdata/juno.txt | 15 - libs/libyuv/unit_test/testdata/mips.txt | 7 + .../unit_test/testdata/mips_loongson2k.txt | 5 + .../unit_test/testdata/mips_loongson3.txt | 10 + .../unit_test/testdata/mips_loongson_mmi.txt | 7 + libs/libyuv/unit_test/testdata/riscv64.txt | 4 + .../libyuv/unit_test/testdata/riscv64_rvv.txt | 4 + .../unit_test/testdata/riscv64_rvv_zvfh.txt | 4 + libs/libyuv/unit_test/unit_test.cc | 305 +- libs/libyuv/unit_test/unit_test.h | 63 +- libs/libyuv/unit_test/video_common_test.cc | 134 +- libs/libyuv/util/color.cc | 120 + libs/libyuv/util/compare.cc | 104 +- libs/libyuv/util/cpuid.c | 260 +- libs/libyuv/util/i444tonv12_eg.cc | 28 + libs/libyuv/util/psnr_main.cc | 52 +- libs/libyuv/util/ssim.cc | 34 +- libs/libyuv/util/yuvconstants.c | 114 + libs/libyuv/util/yuvconvert.cc | 64 +- libs/libyuv/vpython.toml | 76 + libs/libyuv/vpython.toml.uv.lock | 1722 ++ libs/libyuv/winarm.mk | 1 + libs/win32/libyuv/libyuv.2017.vcxproj | 38 +- 210 files changed, 149515 insertions(+), 52648 deletions(-) create mode 100644 libs/libyuv/.clang-format create mode 100644 libs/libyuv/.gitignore create mode 100644 libs/libyuv/.gn create mode 100644 libs/libyuv/BUILD.bazel create mode 100644 libs/libyuv/DIR_METADATA create mode 100644 libs/libyuv/GEMINI.md create mode 100644 libs/libyuv/WORKSPACE.bazel create mode 100644 libs/libyuv/build_overrides/partition_alloc.gni delete mode 100755 libs/libyuv/cleanup_links.py create mode 100644 libs/libyuv/docs/feature_detection.md create mode 100644 libs/libyuv/include/libyuv/cpu_support.h create mode 100644 libs/libyuv/include/libyuv/loongson_intrinsics.h delete mode 100644 libs/libyuv/include/libyuv/macros_msa.h create mode 100644 libs/libyuv/include/libyuv/row_sve.h create mode 100644 libs/libyuv/include/libyuv/scale_rgb.h create mode 100644 libs/libyuv/include/libyuv/scale_uv.h create mode 100644 libs/libyuv/infra/config/OWNERS create mode 100644 libs/libyuv/infra/config/PRESUBMIT.py create mode 100644 libs/libyuv/infra/config/README.md create mode 100644 libs/libyuv/infra/config/codereview.settings create mode 100644 libs/libyuv/infra/config/commit-queue.cfg create mode 100644 libs/libyuv/infra/config/cr-buildbucket.cfg create mode 100644 libs/libyuv/infra/config/luci-logdog.cfg create mode 100644 libs/libyuv/infra/config/luci-milo.cfg create mode 100644 libs/libyuv/infra/config/luci-scheduler.cfg create mode 100755 libs/libyuv/infra/config/main.star create mode 100644 libs/libyuv/infra/config/project.cfg create mode 100644 libs/libyuv/infra/config/realms.cfg create mode 100644 libs/libyuv/libyuv.bzl create mode 100644 libs/libyuv/libyuv.gyp create mode 100644 libs/libyuv/libyuv.gypi create mode 100755 libs/libyuv/riscv_script/prepare_toolchain_qemu.sh create mode 100644 libs/libyuv/riscv_script/riscv-clang.cmake create mode 100755 libs/libyuv/riscv_script/run_qemu.sh create mode 100644 libs/libyuv/source/compare_hvx.cc delete mode 100644 libs/libyuv/source/compare_mmi.cc delete mode 100644 libs/libyuv/source/compare_msa.cc create mode 100644 libs/libyuv/source/compare_wasm.cc create mode 100644 libs/libyuv/source/rotate_hvx.cc create mode 100644 libs/libyuv/source/rotate_lasx.cc create mode 100644 libs/libyuv/source/rotate_lsx.cc delete mode 100644 libs/libyuv/source/rotate_mmi.cc delete mode 100644 libs/libyuv/source/rotate_msa.cc create mode 100644 libs/libyuv/source/rotate_rvv.cc create mode 100644 libs/libyuv/source/rotate_sme.cc create mode 100644 libs/libyuv/source/rotate_sve.cc create mode 100644 libs/libyuv/source/rotate_wasm.cc create mode 100644 libs/libyuv/source/row_hvx.cc create mode 100644 libs/libyuv/source/row_lasx.cc create mode 100644 libs/libyuv/source/row_lsx.cc delete mode 100644 libs/libyuv/source/row_mmi.cc delete mode 100644 libs/libyuv/source/row_msa.cc create mode 100644 libs/libyuv/source/row_rvv.cc create mode 100644 libs/libyuv/source/row_sme.cc create mode 100644 libs/libyuv/source/row_sve.cc create mode 100644 libs/libyuv/source/row_wasm.cc create mode 100644 libs/libyuv/source/scale_hvx.cc create mode 100644 libs/libyuv/source/scale_lsx.cc delete mode 100644 libs/libyuv/source/scale_mmi.cc delete mode 100644 libs/libyuv/source/scale_msa.cc create mode 100644 libs/libyuv/source/scale_rgb.cc create mode 100644 libs/libyuv/source/scale_rvv.cc create mode 100644 libs/libyuv/source/scale_sme.cc create mode 100644 libs/libyuv/source/scale_uv.cc create mode 100644 libs/libyuv/source/scale_wasm.cc create mode 100755 libs/libyuv/source/test.sh delete mode 100755 libs/libyuv/tools_libyuv/valgrind/chrome_tests.bat delete mode 100755 libs/libyuv/tools_libyuv/valgrind/chrome_tests.py delete mode 100755 libs/libyuv/tools_libyuv/valgrind/chrome_tests.sh delete mode 100644 libs/libyuv/tools_libyuv/valgrind/common.py delete mode 100644 libs/libyuv/tools_libyuv/valgrind/gdb_helper.py delete mode 100644 libs/libyuv/tools_libyuv/valgrind/libyuv_tests.bat delete mode 100755 libs/libyuv/tools_libyuv/valgrind/libyuv_tests.py delete mode 100755 libs/libyuv/tools_libyuv/valgrind/libyuv_tests.sh delete mode 100755 libs/libyuv/tools_libyuv/valgrind/locate_valgrind.sh delete mode 100644 libs/libyuv/tools_libyuv/valgrind/memcheck/OWNERS delete mode 100644 libs/libyuv/tools_libyuv/valgrind/memcheck/PRESUBMIT.py delete mode 100644 libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions.txt delete mode 100644 libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions_mac.txt delete mode 100644 libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions_win32.txt delete mode 100755 libs/libyuv/tools_libyuv/valgrind/memcheck_analyze.py delete mode 100755 libs/libyuv/tools_libyuv/valgrind/valgrind.sh delete mode 100755 libs/libyuv/tools_libyuv/valgrind/valgrind_test.py create mode 100644 libs/libyuv/unit_test/convert_argb_test.cc create mode 100644 libs/libyuv/unit_test/scale_plane_test.cc create mode 100644 libs/libyuv/unit_test/scale_rgb_test.cc create mode 100644 libs/libyuv/unit_test/scale_uv_test.cc delete mode 100644 libs/libyuv/unit_test/testdata/juno.txt create mode 100644 libs/libyuv/unit_test/testdata/mips.txt create mode 100644 libs/libyuv/unit_test/testdata/mips_loongson2k.txt create mode 100644 libs/libyuv/unit_test/testdata/mips_loongson3.txt create mode 100644 libs/libyuv/unit_test/testdata/mips_loongson_mmi.txt create mode 100644 libs/libyuv/unit_test/testdata/riscv64.txt create mode 100644 libs/libyuv/unit_test/testdata/riscv64_rvv.txt create mode 100644 libs/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt create mode 100644 libs/libyuv/util/color.cc create mode 100644 libs/libyuv/util/i444tonv12_eg.cc create mode 100644 libs/libyuv/util/yuvconstants.c create mode 100644 libs/libyuv/vpython.toml create mode 100644 libs/libyuv/vpython.toml.uv.lock diff --git a/Makefile.am b/Makefile.am index 71e57cd006..6d1982842d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -179,10 +179,10 @@ libfreeswitch_libyuv_la_SOURCES = \ libs/libyuv/source/compare.cc \ libs/libyuv/source/compare_common.cc \ libs/libyuv/source/compare_gcc.cc \ -libs/libyuv/source/compare_mmi.cc \ -libs/libyuv/source/compare_msa.cc \ +libs/libyuv/source/compare_hvx.cc \ libs/libyuv/source/compare_neon64.cc \ libs/libyuv/source/compare_neon.cc \ +libs/libyuv/source/compare_wasm.cc \ libs/libyuv/source/compare_win.cc \ libs/libyuv/source/convert_argb.cc \ libs/libyuv/source/convert.cc \ @@ -200,28 +200,43 @@ libs/libyuv/source/rotate_argb.cc \ libs/libyuv/source/rotate.cc \ libs/libyuv/source/rotate_common.cc \ libs/libyuv/source/rotate_gcc.cc \ -libs/libyuv/source/rotate_mmi.cc \ -libs/libyuv/source/rotate_msa.cc \ +libs/libyuv/source/rotate_hvx.cc \ +libs/libyuv/source/rotate_lasx.cc \ +libs/libyuv/source/rotate_lsx.cc \ libs/libyuv/source/rotate_neon64.cc \ libs/libyuv/source/rotate_neon.cc \ +libs/libyuv/source/rotate_rvv.cc \ +libs/libyuv/source/rotate_sme.cc \ +libs/libyuv/source/rotate_sve.cc \ +libs/libyuv/source/rotate_wasm.cc \ libs/libyuv/source/rotate_win.cc \ libs/libyuv/source/row_any.cc \ libs/libyuv/source/row_common.cc \ libs/libyuv/source/row_gcc.cc \ -libs/libyuv/source/row_mmi.cc \ -libs/libyuv/source/row_msa.cc \ +libs/libyuv/source/row_hvx.cc \ +libs/libyuv/source/row_lasx.cc \ +libs/libyuv/source/row_lsx.cc \ libs/libyuv/source/row_neon64.cc \ libs/libyuv/source/row_neon.cc \ +libs/libyuv/source/row_rvv.cc \ +libs/libyuv/source/row_sme.cc \ +libs/libyuv/source/row_sve.cc \ +libs/libyuv/source/row_wasm.cc \ libs/libyuv/source/row_win.cc \ libs/libyuv/source/scale_any.cc \ libs/libyuv/source/scale_argb.cc \ libs/libyuv/source/scale.cc \ libs/libyuv/source/scale_common.cc \ libs/libyuv/source/scale_gcc.cc \ -libs/libyuv/source/scale_mmi.cc \ -libs/libyuv/source/scale_msa.cc \ +libs/libyuv/source/scale_hvx.cc \ +libs/libyuv/source/scale_lsx.cc \ libs/libyuv/source/scale_neon64.cc \ libs/libyuv/source/scale_neon.cc \ +libs/libyuv/source/scale_rgb.cc \ +libs/libyuv/source/scale_rvv.cc \ +libs/libyuv/source/scale_sme.cc \ +libs/libyuv/source/scale_uv.cc \ +libs/libyuv/source/scale_wasm.cc \ libs/libyuv/source/scale_win.cc \ libs/libyuv/source/video_common.cc diff --git a/libs/libyuv/.clang-format b/libs/libyuv/.clang-format new file mode 100644 index 0000000000..59d487051f --- /dev/null +++ b/libs/libyuv/.clang-format @@ -0,0 +1,6 @@ +# Defines the Chromium style for automatic reformatting. +# http://clang.llvm.org/docs/ClangFormatStyleOptions.html +BasedOnStyle: Chromium +--- +Language: Java +BasedOnStyle: Google diff --git a/libs/libyuv/.gitignore b/libs/libyuv/.gitignore new file mode 100644 index 0000000000..20d679b7f2 --- /dev/null +++ b/libs/libyuv/.gitignore @@ -0,0 +1,37 @@ +*.pyc +.landmines +pin-log.txt +/base +/build +/buildtools +/google_apis +/links +/links.db +/ios +/mojo +/native_client +/net +/out +/unit_test/out +/source/out +/sde-avx-sse-transition-out.txt +/testing +/third_party +/tools + +# Files generated by CMake build +cmake_install.cmake +CMakeCache.txt +CMakeFiles/ +yuvconvert +libgtest.a +libyuv.a +libyuv_unittest + +# Files generated by winarm.mk build +libyuv_arm.lib +source/*.o + +# Files generated by perf +perf.data +perf.data.old diff --git a/libs/libyuv/.gn b/libs/libyuv/.gn new file mode 100644 index 0000000000..43a31e13e9 --- /dev/null +++ b/libs/libyuv/.gn @@ -0,0 +1,41 @@ +# Copyright 2015 The LibYuv Project Authors. All rights reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +import("//build/dotfile_settings.gni") + +# The location of the build configuration file. +buildconfig = "//build/config/BUILDCONFIG.gn" + +# The hermetic Python interpreter to use by default. +script_executable = "//third_party/cpython3/host/bin/python3" + +# The secondary source root is a parallel directory tree where +# GN build files are placed when they can not be placed directly +# in the source tree, e.g. for third party source trees. +secondary_source = "//build/secondary/" + +# These are the targets to check headers for by default. The files in targets +# matching these patterns (see "gn help label_pattern" for format) will have +# their includes checked for proper dependencies when you run either +# "gn check" or "gn gen --check". +check_targets = [ "//libyuv/*" ] + +# These are the list of GN files that run exec_script. This allowlist exists +# to force additional review for new uses of exec_script, which is strongly +# discouraged except for gypi_to_gn calls. +exec_script_allowlist = build_dotfile_settings.exec_script_allowlist + + [ "//build_overrides/build.gni" ] + +default_args = { + android_static_analysis = "off" + mac_sdk_min = "10.12" + ios_deployment_target = "12.0" + + # Use Siso instead of Ninja. + use_siso = true +} diff --git a/libs/libyuv/AUTHORS b/libs/libyuv/AUTHORS index 9686ac13eb..42959c1d87 100644 --- a/libs/libyuv/AUTHORS +++ b/libs/libyuv/AUTHORS @@ -2,3 +2,7 @@ # Name or Organization Google Inc. + +Ho Cheung +Ivan Pavlotskiy +Sida Zhu diff --git a/libs/libyuv/Android.bp b/libs/libyuv/Android.bp index ea76f9435b..aa953dadea 100644 --- a/libs/libyuv/Android.bp +++ b/libs/libyuv/Android.bp @@ -1,6 +1,31 @@ +package { + default_applicable_licenses: ["external_libyuv_license"], +} + +// Added automatically by a large-scale-change +// +// large-scale-change included anything that looked like it might be a license +// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc. +// +// Please consider removing redundant or irrelevant files from 'license_text:'. +// See: http://go/android-license-faq +license { + name: "external_libyuv_license", + visibility: [":__subpackages__"], + license_kinds: [ + "SPDX-license-identifier-BSD", + ], + license_text: [ + "LICENSE", + "PATENTS", + ], +} + cc_library { name: "libyuv", vendor_available: true, + product_available: true, + host_supported: true, vndk: { enabled: true, }, @@ -9,47 +34,48 @@ cc_library { "source/compare.cc", "source/compare_common.cc", "source/compare_gcc.cc", + "source/compare_hvx.cc", "source/compare_neon.cc", "source/compare_neon64.cc", - "source/compare_mmi.cc", - "source/compare_msa.cc", "source/convert.cc", "source/convert_argb.cc", "source/convert_from.cc", "source/convert_from_argb.cc", + "source/convert_jpeg.cc", "source/convert_to_argb.cc", "source/convert_to_i420.cc", "source/cpu_id.cc", + "source/mjpeg_decoder.cc", + "source/mjpeg_validate.cc", "source/planar_functions.cc", "source/rotate.cc", "source/rotate_any.cc", "source/rotate_argb.cc", "source/rotate_common.cc", "source/rotate_gcc.cc", - "source/rotate_mmi.cc", - "source/rotate_msa.cc", + "source/rotate_hvx.cc", "source/rotate_neon.cc", "source/rotate_neon64.cc", + "source/rotate_rvv.cc", "source/row_any.cc", "source/row_common.cc", "source/row_gcc.cc", - "source/row_mmi.cc", - "source/row_msa.cc", + "source/row_hvx.cc", "source/row_neon.cc", "source/row_neon64.cc", + "source/row_rvv.cc", "source/scale.cc", "source/scale_any.cc", "source/scale_argb.cc", "source/scale_common.cc", "source/scale_gcc.cc", - "source/scale_mmi.cc", - "source/scale_msa.cc", + "source/scale_hvx.cc", "source/scale_neon.cc", "source/scale_neon64.cc", + "source/scale_rgb.cc", + "source/scale_rvv.cc", + "source/scale_uv.cc", "source/video_common.cc", - "source/convert_jpeg.cc", - "source/mjpeg_decoder.cc", - "source/mjpeg_validate.cc", ], cflags: [ @@ -58,11 +84,30 @@ cc_library { "-Wno-unused-parameter", "-fexceptions", "-DHAVE_JPEG", + "-DLIBYUV_UNLIMITED_DATA", ], + arch: { + arm: { + cflags: ["-mfpu=neon"], + }, + }, + shared_libs: ["libjpeg"], export_include_dirs: ["include"], + + apex_available: [ + "//apex_available:platform", + "com.android.media.swcodec", + ], + min_sdk_version: "29", + sanitize: { + cfi: true, + config: { + cfi_assembly_support: true, + }, + }, } // compatibilty static library until all uses of libyuv_static are replaced @@ -71,6 +116,11 @@ cc_library_static { name: "libyuv_static", vendor_available: true, whole_static_libs: ["libyuv"], + apex_available: [ + "//apex_available:platform", + "com.android.media.swcodec", + ], + min_sdk_version: "29", } cc_test { @@ -79,10 +129,10 @@ cc_test { shared_libs: ["libjpeg"], cflags: ["-Wall", "-Werror"], srcs: [ - "unit_test/unit_test.cc", "unit_test/basictypes_test.cc", "unit_test/color_test.cc", "unit_test/compare_test.cc", + "unit_test/convert_argb_test.cc", "unit_test/convert_test.cc", "unit_test/cpu_test.cc", "unit_test/cpu_thread_test.cc", @@ -91,7 +141,11 @@ cc_test { "unit_test/rotate_argb_test.cc", "unit_test/rotate_test.cc", "unit_test/scale_argb_test.cc", + "unit_test/scale_plane_test.cc", + "unit_test/scale_rgb_test.cc", "unit_test/scale_test.cc", + "unit_test/scale_uv_test.cc", + "unit_test/unit_test.cc", "unit_test/video_common_test.cc", ], } @@ -114,6 +168,15 @@ cc_test { static_libs: ["libyuv"], } +cc_test { + name: "i444tonv12_eg", + gtest: false, + srcs: [ + "util/i444tonv12_eg.cc", + ], + static_libs: ["libyuv"], +} + cc_test { name: "psnr", gtest: false, @@ -125,6 +188,15 @@ cc_test { static_libs: ["libyuv"], } +cc_test { + name: "yuvconstants", + gtest: false, + srcs: [ + "util/yuvconstants.c", + ], + static_libs: ["libyuv"], +} + cc_test { name: "yuvconvert", gtest: false, diff --git a/libs/libyuv/Android.mk b/libs/libyuv/Android.mk index 0975d64a38..8f8d1e442c 100644 --- a/libs/libyuv/Android.mk +++ b/libs/libyuv/Android.mk @@ -1,4 +1,7 @@ # This is the Android makefile for libyuv for NDK. + +# Ignore this file during non-NDK builds. +ifdef NDK_ROOT LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) @@ -9,10 +12,10 @@ LOCAL_SRC_FILES := \ source/compare.cc \ source/compare_common.cc \ source/compare_gcc.cc \ - source/compare_mmi.cc \ - source/compare_msa.cc \ + source/compare_hvx.cc \ source/compare_neon.cc \ source/compare_neon64.cc \ + source/compare_win.cc \ source/convert.cc \ source/convert_argb.cc \ source/convert_from.cc \ @@ -26,26 +29,31 @@ LOCAL_SRC_FILES := \ source/rotate_argb.cc \ source/rotate_common.cc \ source/rotate_gcc.cc \ - source/rotate_mmi.cc \ - source/rotate_msa.cc \ + source/rotate_hvx.cc \ source/rotate_neon.cc \ source/rotate_neon64.cc \ + source/rotate_rvv.cc \ + source/rotate_win.cc \ source/row_any.cc \ source/row_common.cc \ source/row_gcc.cc \ - source/row_mmi.cc \ - source/row_msa.cc \ + source/row_hvx.cc \ source/row_neon.cc \ source/row_neon64.cc \ + source/row_rvv.cc \ + source/row_win.cc \ source/scale.cc \ source/scale_any.cc \ source/scale_argb.cc \ source/scale_common.cc \ source/scale_gcc.cc \ - source/scale_mmi.cc \ - source/scale_msa.cc \ + source/scale_hvx.cc \ source/scale_neon.cc \ source/scale_neon64.cc \ + source/scale_rgb.cc \ + source/scale_rvv.cc \ + source/scale_uv.cc \ + source/scale_win.cc \ source/video_common.cc common_CFLAGS := -Wall -fexceptions @@ -85,20 +93,25 @@ LOCAL_MODULE_TAGS := tests LOCAL_CPP_EXTENSION := .cc LOCAL_C_INCLUDES += $(LOCAL_PATH)/include LOCAL_SRC_FILES := \ - unit_test/unit_test.cc \ - unit_test/basictypes_test.cc \ - unit_test/color_test.cc \ - unit_test/compare_test.cc \ - unit_test/convert_test.cc \ - unit_test/cpu_test.cc \ - unit_test/cpu_thread_test.cc \ - unit_test/math_test.cc \ - unit_test/planar_test.cc \ - unit_test/rotate_argb_test.cc \ - unit_test/rotate_test.cc \ - unit_test/scale_argb_test.cc \ - unit_test/scale_test.cc \ + unit_test/basictypes_test.cc \ + unit_test/color_test.cc \ + unit_test/compare_test.cc \ + unit_test/convert_argb_test.cc \ + unit_test/convert_test.cc \ + unit_test/cpu_test.cc \ + unit_test/cpu_thread_test.cc \ + unit_test/math_test.cc \ + unit_test/planar_test.cc \ + unit_test/rotate_argb_test.cc \ + unit_test/rotate_test.cc \ + unit_test/scale_argb_test.cc \ + unit_test/scale_plane_test.cc \ + unit_test/scale_rgb_test.cc \ + unit_test/scale_test.cc \ + unit_test/scale_uv_test.cc \ + unit_test/unit_test.cc \ unit_test/video_common_test.cc LOCAL_MODULE := libyuv_unittest include $(BUILD_NATIVE_TEST) +endif # NDK_ROOT diff --git a/libs/libyuv/BUILD.bazel b/libs/libyuv/BUILD.bazel new file mode 100644 index 0000000000..62bc4cd0e3 --- /dev/null +++ b/libs/libyuv/BUILD.bazel @@ -0,0 +1,287 @@ +# Copyright 2026 The LibYuv Project Authors. All rights reserved. +# +# Description: +# The libyuv package provides implementation yuv image conversion, rotation +# and scaling. + +load("@bazel_skylib//lib:selects.bzl", "selects") +load(":libyuv.bzl", "libyuv_hdrs", "libyuv_neon_srcs", "libyuv_rvv_srcs", "libyuv_srcs", "libyuv_sve_srcs", "libyuv_test_srcs") + +# Detect if we are in Google's internal repository (where source files are +# under files/) or open source (where source files are at the root). +PREFIX = "files/" if len(native.glob(["files/source/*.cc"])) > 0 else "" + +# We support NEON for all arm processors, as we only support ARMv7a+. +SUPPORTS_NEON_COPTS = [ + "-DLIBYUV_NEON", +] + +# ARMv7a requires that we explicitly enable NEON. arm64 enables it implicitly. +ENABLE_NEON_COPTS = [ + "-mfpu=neon", +] + +ENABLE_NEON64_COPTS = [ + "-march=armv8-a+dotprod+i8mm", +] + +NEON_COPTS = select({ + "@platforms//cpu:armv7": ENABLE_NEON_COPTS + SUPPORTS_NEON_COPTS, + "@platforms//cpu:aarch64": ENABLE_NEON64_COPTS + SUPPORTS_NEON_COPTS, + "//conditions:default": [], +}) + +SUPPORTS_SVE_COPTS = [ + "-DLIBYUV_SVE", +] + +ENABLE_SVE_COPTS = [ + "-march=armv8.5-a+i8mm+sve2", +] + +SVE_COPTS = select({ + "@platforms//cpu:aarch64": ENABLE_SVE_COPTS + SUPPORTS_SVE_COPTS, + "//conditions:default": [], +}) + +SUPPORTS_RVV_COPTS = [ + "-DLIBYUV_RVV", + "-fno-tree-vectorize", + "-fno-tree-slp-vectorize", +] + +ENABLE_RVV_COPTS = [ + "-march=rv32gcv", +] + +ENABLE_RVV64_COPTS = [ + "-march=rv64gcv", +] + +RVV_COPTS = select({ + "@platforms//cpu:riscv32": ENABLE_RVV_COPTS + SUPPORTS_RVV_COPTS, + "@platforms//cpu:riscv64": ENABLE_RVV64_COPTS + SUPPORTS_RVV_COPTS, + "//conditions:default": [], +}) + +ARCH_SUPPORT_COPTS = select({ + "@platforms//cpu:armv7": SUPPORTS_NEON_COPTS, + "@platforms//cpu:aarch64": SUPPORTS_NEON_COPTS + SUPPORTS_SVE_COPTS, + "@platforms//cpu:riscv32": SUPPORTS_RVV_COPTS, + "@platforms//cpu:riscv64": SUPPORTS_RVV_COPTS, + "@platforms//cpu:wasm32": ["-msimd128"], + "@platforms//cpu:wasm64": ["-msimd128"], + "//conditions:default": [], +}) + +PLATFORM_COPTS = select({ + "@platforms//os:android": ["-DHAVE_JPEG"], + "@platforms//os:linux": ["-DHAVE_JPEG"], + "@platforms//os:windows": ["-DHAVE_JPEG"], + "@platforms//os:macos": ["-DHAVE_JPEG"], + "//conditions:default": [], +}) + [ + "-DLIBYUV_DISABLE_SME", + "-DLIBYUV_USE_ABSL_FLAGS", + "-DGOOGLE_COMMANDLINEFLAGS_FULL_API", +] + +ALL_COPTS = PLATFORM_COPTS + ARCH_SUPPORT_COPTS + +ALL_NEON_COPTS = NEON_COPTS + PLATFORM_COPTS + +ALL_SVE_COPTS = SVE_COPTS + PLATFORM_COPTS + +ALL_RVV_COPTS = RVV_COPTS + PLATFORM_COPTS + +NEON_DEPS = select({ + "@platforms//cpu:armv7": [":libyuv_neon_impl"], + "@platforms//cpu:aarch64": [":libyuv_neon_impl"], + "//conditions:default": [], +}) + +SVE_DEPS = select({ + "@platforms//cpu:aarch64": [":libyuv_sve_impl"], + "//conditions:default": [], +}) + +RVV_DEPS = select({ + "@platforms//cpu:riscv32": [":libyuv_rvv_impl"], + "@platforms//cpu:riscv64": [":libyuv_rvv_impl"], + "//conditions:default": [], +}) + +PLATFORM_DEPS = select({ + "@platforms//os:android": ["@libjpeg_turbo//:jpeg"], + "@platforms//os:linux": ["@libjpeg_turbo//:jpeg"], + "@platforms//os:windows": ["@libjpeg_turbo//:jpeg"], + "@platforms//os:macos": ["@libjpeg_turbo//:jpeg"], + "//conditions:default": [], +}) + +ALL_DEPS = NEON_DEPS + SVE_DEPS + RVV_DEPS + PLATFORM_DEPS + +cc_library( + name = "libyuv", + hdrs = [ + PREFIX + "include/libyuv.h", + # Headers included by libyuv.h. + PREFIX + "include/libyuv/basic_types.h", + PREFIX + "include/libyuv/compare.h", + PREFIX + "include/libyuv/convert.h", + PREFIX + "include/libyuv/convert_argb.h", + PREFIX + "include/libyuv/convert_from.h", + PREFIX + "include/libyuv/convert_from_argb.h", + PREFIX + "include/libyuv/cpu_id.h", + PREFIX + "include/libyuv/mjpeg_decoder.h", + PREFIX + "include/libyuv/planar_functions.h", + PREFIX + "include/libyuv/rotate.h", + PREFIX + "include/libyuv/rotate_argb.h", + PREFIX + "include/libyuv/row.h", # Bug 553148013: Should be private. + PREFIX + "include/libyuv/scale.h", + PREFIX + "include/libyuv/scale_argb.h", + PREFIX + "include/libyuv/scale_rgb.h", + PREFIX + "include/libyuv/scale_uv.h", + PREFIX + "include/libyuv/version.h", + PREFIX + "include/libyuv/video_common.h", + # Headers included by libyuv/row.h. + PREFIX + "include/libyuv/cpu_support.h", # Bug 553148013: Should be private. + ], + strip_include_prefix = PREFIX + "include", + visibility = ["//visibility:public"], + deps = [":libyuv_impl"], +) + +cc_library( + name = "libyuv_impl", + srcs = libyuv_srcs(PREFIX), + hdrs = libyuv_hdrs(PREFIX), + copts = ALL_COPTS + selects.with_or({ + ( + "@platforms//os:android", + "@platforms//os:ios", + "@platforms//os:tvos", + "@platforms//os:windows", + "@platforms//os:macos", + ): [], + "//conditions:default": [ + "-fomit-frame-pointer", + ], + }) + selects.with_or({ + ( + "@platforms//os:android", + "@platforms//os:ios", + "@platforms//os:tvos", + ): ["-O2"], + "//conditions:default": [], + }), + includes = [PREFIX + "include"], + deps = ALL_DEPS, + alwayslink = 1, +) + +cc_library( + name = "libyuv_neon_impl", + srcs = libyuv_neon_srcs(PREFIX), + copts = ALL_NEON_COPTS, + includes = [PREFIX + "include"], + visibility = ["//visibility:private"], + alwayslink = 1, +) + +cc_library( + name = "libyuv_sve_impl", + srcs = libyuv_sve_srcs(PREFIX), + copts = ALL_SVE_COPTS, + includes = [PREFIX + "include"], + visibility = ["//visibility:private"], + alwayslink = 1, +) + +cc_library( + name = "libyuv_rvv_impl", + srcs = libyuv_rvv_srcs(PREFIX), + copts = ALL_RVV_COPTS, + includes = [PREFIX + "include"], + visibility = ["//visibility:private"], + alwayslink = 1, +) + +cc_test( + name = "libyuv_test", + srcs = libyuv_test_srcs(PREFIX), + copts = ALL_COPTS + [ + "-Wno-unused-variable", + ], + visibility = ["//visibility:public"], + deps = [ + ":libyuv", + "@com_google_googletest//:gtest_main", + "@com_google_absl//absl/flags:flag", + "@com_google_absl//absl/flags:parse", + ], +) + +cc_library( + name = "psnr_lib", + srcs = [PREFIX + "util/psnr.cc"], + hdrs = [PREFIX + "util/psnr.h"], + copts = PLATFORM_COPTS, + visibility = ["//visibility:private"], +) + +cc_library( + name = "ssim_lib", + srcs = [PREFIX + "util/ssim.cc"], + hdrs = [PREFIX + "util/ssim.h"], + visibility = ["//visibility:private"], +) + +cc_binary( + name = "psnr", + srcs = [PREFIX + "util/psnr_main.cc"], + copts = PLATFORM_COPTS + [ + "-Wframe-larger-than=64000", + ], + deps = [ + ":libyuv", + ":psnr_lib", + ":ssim_lib", + ], +) + +cc_binary( + name = "i444tonv12_eg", + srcs = [PREFIX + "util/i444tonv12_eg.cc"], + visibility = ["//visibility:public"], + deps = [ + ":libyuv", + ], +) + +cc_binary( + name = "cpuid", + srcs = [PREFIX + "util/cpuid.c"], + visibility = ["//visibility:public"], + deps = [ + ":libyuv", + ], +) + +cc_binary( + name = "yuvconstants", + srcs = [PREFIX + "util/yuvconstants.c"], + visibility = ["//visibility:public"], + deps = [ + ":libyuv", + ], +) + +cc_binary( + name = "yuvconvert", + srcs = [PREFIX + "util/yuvconvert.cc"], + visibility = ["//visibility:public"], + deps = [ + ":libyuv", + ], +) diff --git a/libs/libyuv/BUILD.gn b/libs/libyuv/BUILD.gn index 8904fd6c69..3c37e05910 100644 --- a/libs/libyuv/BUILD.gn +++ b/libs/libyuv/BUILD.gn @@ -6,12 +6,14 @@ # in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. -import("libyuv.gni") +import("//build/config/features.gni") +import("//build/config/sanitizers/sanitizers.gni") import("//testing/test.gni") +import("libyuv.gni") declare_args() { - # Set to false to disable building with gflags. - libyuv_use_gflags = true + # Set to false to disable building with absl flags. + libyuv_use_absl_flags = true # When building a shared library using a target in WebRTC or # Chromium projects that depends on libyuv, setting this flag @@ -21,26 +23,49 @@ declare_args() { config("libyuv_config") { include_dirs = [ "include" ] - if (is_android && current_cpu == "arm64") { - ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker64" ] + + # Define CHROMIUM to tell cpu_id to avoid sandbox unsafe system calls. + defines = [ "CHROMIUM" ] + if (libyuv_enable_rowwin) { + defines += [ "LIBYUV_ENABLE_ROWWIN=1" ] } - if (is_android && current_cpu != "arm64") { - ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker" ] + if (!libyuv_use_neon) { + defines += [ "LIBYUV_DISABLE_NEON" ] + } + if (!libyuv_use_sve) { + defines += [ "LIBYUV_DISABLE_SVE" ] + } + if (!libyuv_use_sme) { + defines += [ "LIBYUV_DISABLE_SME" ] + } + if (libyuv_disable_rvv) { + defines += [ "LIBYUV_DISABLE_RVV" ] + } else if (libyuv_use_rvv) { + defines += [ "LIBYUV_RVV" ] + } + if (!libyuv_use_lsx) { + defines += [ "LIBYUV_DISABLE_LSX" ] + } + if (!libyuv_use_lasx) { + defines += [ "LIBYUV_DISABLE_LASX" ] + } + if (current_cpu == "wasm") { + cflags_cc = [ "-msimd128" ] } } # This target is built when no specific target is specified on the command line. group("default") { testonly = true - deps = [ - ":libyuv", - ] + deps = [ ":libyuv" ] if (libyuv_include_tests) { deps += [ ":compare", ":cpuid", + ":i444tonv12_eg", ":libyuv_unittest", ":psnr", + ":yuvconstants", ":yuvconvert", ] } @@ -50,30 +75,38 @@ group("libyuv") { all_dependent_configs = [ ":libyuv_config" ] deps = [] - if (is_win && target_cpu == "x64") { + if (is_win && target_cpu == "x64" && current_toolchain == default_toolchain) { # Compile with clang in order to get inline assembly - public_deps = [ - ":libyuv_internal(//build/toolchain/win:win_clang_x64)", - ] + public_deps = [ ":libyuv_internal(//build/toolchain/win:win_clang_x64)" ] } else { - public_deps = [ - ":libyuv_internal", - ] + public_deps = [ ":libyuv_internal" ] } if (libyuv_use_neon) { deps += [ ":libyuv_neon" ] } - if (libyuv_use_msa) { - deps += [ ":libyuv_msa" ] + if (libyuv_use_sve) { + deps += [ ":libyuv_sve" ] } - if (libyuv_use_mmi) { - deps += [ ":libyuv_mmi" ] + if (libyuv_use_sme) { + deps += [ ":libyuv_sme" ] } - if (!is_ios) { + if (libyuv_use_rvv && !libyuv_disable_rvv) { + deps += [ ":libyuv_rvv" ] + } + + if (libyuv_use_lsx) { + deps += [ ":libyuv_lsx" ] + } + + if (libyuv_use_lasx) { + deps += [ ":libyuv_lasx" ] + } + + if (!is_ios && !libyuv_disable_jpeg) { # Make sure that clients of libyuv link with libjpeg. This can't go in # libyuv_internal because in Windows x64 builds that will generate a clang # build of libjpeg, and we don't want two copies. @@ -89,20 +122,26 @@ static_library("libyuv_internal") { "include/libyuv.h", "include/libyuv/basic_types.h", "include/libyuv/compare.h", + "include/libyuv/compare_row.h", "include/libyuv/convert.h", "include/libyuv/convert_argb.h", "include/libyuv/convert_from.h", "include/libyuv/convert_from_argb.h", "include/libyuv/cpu_id.h", + "include/libyuv/cpu_support.h", + "include/libyuv/loongson_intrinsics.h", "include/libyuv/mjpeg_decoder.h", "include/libyuv/planar_functions.h", "include/libyuv/rotate.h", "include/libyuv/rotate_argb.h", "include/libyuv/rotate_row.h", "include/libyuv/row.h", + "include/libyuv/row_sve.h", "include/libyuv/scale.h", "include/libyuv/scale_argb.h", + "include/libyuv/scale_rgb.h", "include/libyuv/scale_row.h", + "include/libyuv/scale_uv.h", "include/libyuv/version.h", "include/libyuv/video_common.h", @@ -110,6 +149,8 @@ static_library("libyuv_internal") { "source/compare.cc", "source/compare_common.cc", "source/compare_gcc.cc", + "source/compare_hvx.cc", + "source/compare_wasm.cc", "source/compare_win.cc", "source/convert.cc", "source/convert_argb.cc", @@ -127,16 +168,24 @@ static_library("libyuv_internal") { "source/rotate_argb.cc", "source/rotate_common.cc", "source/rotate_gcc.cc", + "source/rotate_hvx.cc", + "source/rotate_wasm.cc", "source/rotate_win.cc", "source/row_any.cc", "source/row_common.cc", "source/row_gcc.cc", + "source/row_hvx.cc", + "source/row_wasm.cc", "source/row_win.cc", "source/scale.cc", "source/scale_any.cc", "source/scale_argb.cc", "source/scale_common.cc", "source/scale_gcc.cc", + "source/scale_hvx.cc", + "source/scale_rgb.cc", + "source/scale_uv.cc", + "source/scale_wasm.cc", "source/scale_win.cc", "source/video_common.cc", ] @@ -150,7 +199,7 @@ static_library("libyuv_internal") { configs += [ "//build/config/gcc:symbol_visibility_default" ] } - if (!is_ios) { + if ((!is_ios || use_blink) && !libyuv_disable_jpeg) { defines += [ "HAVE_JPEG" ] # Needed to pull in libjpeg headers. Can't add //third_party:jpeg to deps @@ -158,9 +207,7 @@ static_library("libyuv_internal") { deps += [ "//third_party:jpeg_includes" ] } - # Always enable optimization for Release and NaCl builds (to workaround - # crbug.com/538243). - if (!is_debug || is_nacl) { + if (!is_debug) { configs -= [ "//build/config/compiler:default_optimization" ] # Enable optimize for speed (-O2) over size (-Os). @@ -192,61 +239,126 @@ if (libyuv_use_neon) { "source/scale_neon64.cc", ] - deps = [ - ":libyuv_internal", - ] + deps = [ ":libyuv_internal" ] public_configs = [ ":libyuv_config" ] - # Always enable optimization for Release and NaCl builds (to workaround - # crbug.com/538243). - if (!is_debug) { - configs -= [ "//build/config/compiler:default_optimization" ] + if (current_cpu == "arm64") { + # The -march arguments below are incompatible with libc++ modules. + use_libcxx_modules = false - # Enable optimize for speed (-O2) over size (-Os). - # TODO(fbarchard): Consider optimize_speed which is O3. - configs += [ "//build/config/compiler:optimize_max" ] - } - - if (current_cpu != "arm64") { - configs -= [ "//build/config/compiler:compiler_arm_fpu" ] - cflags = [ "-mfpu=neon" ] + # TODO(thakis): Do we get this from global flags already? Is this needed? + cflags = [ "-march=armv8-a+dotprod+i8mm" ] } } } -if (libyuv_use_msa) { - static_library("libyuv_msa") { +if (libyuv_use_sve) { + static_library("libyuv_sve") { sources = [ - # MSA Source Files - "source/compare_msa.cc", - "source/rotate_msa.cc", - "source/row_msa.cc", - "source/scale_msa.cc", + "source/rotate_sve.cc", + "source/row_sve.cc", ] - deps = [ - ":libyuv_internal", + deps = [ ":libyuv_internal" ] + + public_configs = [ ":libyuv_config" ] + + # The -march arguments below are incompatible with libc++ modules. + use_libcxx_modules = false + + # SVE2 is an Armv9-A feature, but use Armv8.5-A for compatibility. + cflags = [ "-march=armv8.5-a+i8mm+sve2" ] + } +} + +if (libyuv_use_sme) { + static_library("libyuv_sme") { + sources = [ + "source/rotate_sme.cc", + "source/row_sme.cc", + "source/scale_sme.cc", ] + deps = [ ":libyuv_internal" ] + + public_configs = [ ":libyuv_config" ] + + # The -march arguments below are incompatible with libc++ modules. + use_libcxx_modules = false + + # SME is an Armv9-A feature, but use Armv8.5-A for compatibility with + # processors like Apple M4/M5 that support SME without SVE. + cflags = [ "-march=armv8.5-a+i8mm+sme" ] + } +} + +if (libyuv_use_rvv && !libyuv_disable_rvv) { + static_library("libyuv_rvv") { + sources = [ + "source/rotate_rvv.cc", + "source/row_rvv.cc", + "source/scale_rvv.cc", + ] + + deps = [ ":libyuv_internal" ] + + public_configs = [ ":libyuv_config" ] + + # The -march arguments below are incompatible with libc++ modules. + use_libcxx_modules = false + + if (current_cpu == "riscv64") { + cflags = [ + "-march=rv64gcv", + "-fno-tree-vectorize", + "-fno-tree-slp-vectorize", + ] + } else { + cflags = [ + "-march=rv32gcv", + "-fno-tree-vectorize", + "-fno-tree-slp-vectorize", + ] + } + } +} + +if (libyuv_use_lsx) { + static_library("libyuv_lsx") { + sources = [ + # LSX Source Files + "source/rotate_lsx.cc", + "source/row_lsx.cc", + "source/scale_lsx.cc", + ] + + cflags_cc = [ + "-mlsx", + "-Wno-c++11-narrowing", + ] + + deps = [ ":libyuv_internal" ] + public_configs = [ ":libyuv_config" ] } } -if (libyuv_use_mmi) { - static_library("libyuv_mmi") { +if (libyuv_use_lasx) { + static_library("libyuv_lasx") { sources = [ - # MMI Source Files - "source/compare_mmi.cc", - "source/rotate_mmi.cc", - "source/row_mmi.cc", - "source/scale_mmi.cc", + # LASX Source Files + "source/rotate_lasx.cc", + "source/row_lasx.cc", ] - deps = [ - ":libyuv_internal", + cflags_cc = [ + "-mlasx", + "-Wno-c++11-narrowing", ] + deps = [ ":libyuv_internal" ] + public_configs = [ ":libyuv_config" ] } } @@ -267,19 +379,36 @@ if (libyuv_include_tests) { ] } } + config("libyuv_unittest_config") { defines = [ "GTEST_RELATIVE_PATH" ] } + if (!build_with_chromium && prebuilt_instrumented_libraries_available && + is_msan) { + # Override the relative PT_INTERP from //third_party/instrumented_libs so + # standalone test binaries can be launched from any working directory + # (such as the builder root on LUCI Linux MSan). + config("libyuv_msan_ldflags") { + if (msan_track_origins == 0) { + _msan_archive = "msan-no-origins-noble-lib" + } else { + _msan_archive = "msan-chained-origins-noble-lib" + } + _ld_linux = rebase_path( + "//third_party/instrumented_libs/binaries/$_msan_archive/lib/ld-linux-x86-64.so.2") + ldflags = [ "-Wl,--dynamic-linker=$_ld_linux" ] + } + } + test("libyuv_unittest") { testonly = true sources = [ - # sources - # headers "unit_test/basictypes_test.cc", "unit_test/color_test.cc", "unit_test/compare_test.cc", + "unit_test/convert_argb_test.cc", "unit_test/convert_test.cc", "unit_test/cpu_test.cc", "unit_test/cpu_thread_test.cc", @@ -288,7 +417,10 @@ if (libyuv_include_tests) { "unit_test/rotate_argb_test.cc", "unit_test/rotate_test.cc", "unit_test/scale_argb_test.cc", + "unit_test/scale_plane_test.cc", + "unit_test/scale_rgb_test.cc", "unit_test/scale_test.cc", + "unit_test/scale_uv_test.cc", "unit_test/unit_test.cc", "unit_test/unit_test.h", "unit_test/video_common_test.cc", @@ -300,20 +432,28 @@ if (libyuv_include_tests) { ] defines = [] - if (libyuv_use_gflags) { - defines += [ "LIBYUV_USE_GFLAGS" ] - deps += [ "//third_party/gflags" ] + if (libyuv_use_absl_flags) { + defines += [ "LIBYUV_USE_ABSL_FLAGS" ] + deps += [ + "//third_party/abseil-cpp/absl/flags:flag", + "//third_party/abseil-cpp/absl/flags:parse", + ] } configs += [ ":libyuv_unittest_warnings_config" ] + if (!build_with_chromium && prebuilt_instrumented_libraries_available && + is_msan) { + configs += [ ":libyuv_msan_ldflags" ] + } - public_deps = [ - "//testing/gtest", - ] + public_deps = [ "//testing/gtest" ] public_configs = [ ":libyuv_unittest_config" ] - if (is_linux) { + if (is_linux || is_chromeos) { cflags = [ "-fexceptions" ] + + # For enabling ASLR. + ldflags = [ "-pie" ] } if (is_ios) { configs -= [ "//build/config/compiler:default_symbols" ] @@ -323,15 +463,10 @@ if (libyuv_include_tests) { if (!is_ios && !libyuv_disable_jpeg) { defines += [ "HAVE_JPEG" ] } - if (is_android) { - deps += [ "//testing/android/native_test:native_test_native_code" ] - } # TODO(YangZhang): These lines can be removed when high accuracy # YUV to RGB to Neon is ported. - if ((target_cpu == "armv7" || target_cpu == "armv7s" || - (target_cpu == "arm" && arm_version >= 7) || target_cpu == "arm64") && - (arm_use_neon || arm_optionally_use_neon)) { + if (target_cpu == "arm" || target_cpu == "arm64") { defines += [ "LIBYUV_NEON" ] } @@ -349,12 +484,14 @@ if (libyuv_include_tests) { # sources "util/compare.cc", ] - deps = [ - ":libyuv", - ] - if (is_linux) { + deps = [ ":libyuv" ] + if (is_linux || is_chromeos) { cflags = [ "-fexceptions" ] } + if (!build_with_chromium && prebuilt_instrumented_libraries_available && + is_msan) { + configs += [ ":libyuv_msan_ldflags" ] + } } executable("yuvconvert") { @@ -362,12 +499,29 @@ if (libyuv_include_tests) { # sources "util/yuvconvert.cc", ] - deps = [ - ":libyuv", - ] - if (is_linux) { + deps = [ ":libyuv" ] + if (is_linux || is_chromeos) { cflags = [ "-fexceptions" ] } + if (!build_with_chromium && prebuilt_instrumented_libraries_available && + is_msan) { + configs += [ ":libyuv_msan_ldflags" ] + } + } + + executable("yuvconstants") { + sources = [ + # sources + "util/yuvconstants.c", + ] + deps = [ ":libyuv" ] + if (is_linux || is_chromeos) { + cflags = [ "-fexceptions" ] + } + if (!build_with_chromium && prebuilt_instrumented_libraries_available && + is_msan) { + configs += [ ":libyuv_msan_ldflags" ] + } } executable("psnr") { @@ -377,13 +531,27 @@ if (libyuv_include_tests) { "util/psnr_main.cc", "util/ssim.cc", ] - deps = [ - ":libyuv", - ] + deps = [ ":libyuv" ] if (!is_ios && !libyuv_disable_jpeg) { defines = [ "HAVE_JPEG" ] } + if (!build_with_chromium && prebuilt_instrumented_libraries_available && + is_msan) { + configs += [ ":libyuv_msan_ldflags" ] + } + } + + executable("i444tonv12_eg") { + sources = [ + # sources + "util/i444tonv12_eg.cc", + ] + deps = [ ":libyuv" ] + if (!build_with_chromium && prebuilt_instrumented_libraries_available && + is_msan) { + configs += [ ":libyuv_msan_ldflags" ] + } } executable("cpuid") { @@ -391,8 +559,25 @@ if (libyuv_include_tests) { # sources "util/cpuid.c", ] - deps = [ - ":libyuv", - ] + deps = [ ":libyuv" ] + if (!build_with_chromium && prebuilt_instrumented_libraries_available && + is_msan) { + configs += [ ":libyuv_msan_ldflags" ] + } + } +} + +if (!build_with_chromium) { + # GN evaluates each .gn file once per toolchain, so restricting to default + # toolchain will ensure write_file() is called only once. + if (current_toolchain == default_toolchain) { + # Write debug logs to gn_logs.txt. + # This is also required for Siso builds. + import("//build/gn_logs.gni") + lines = [ + "Generated during 'gn gen' by //BUILD.gn.", + "", + ] + build_gn_logs + write_file("$root_build_dir/gn_logs.txt", lines) } } diff --git a/libs/libyuv/CM_linux_packages.cmake b/libs/libyuv/CM_linux_packages.cmake index 5f676f8998..4caf15662e 100644 --- a/libs/libyuv/CM_linux_packages.cmake +++ b/libs/libyuv/CM_linux_packages.cmake @@ -1,6 +1,7 @@ # determine the version number from the #define in libyuv/version.h EXECUTE_PROCESS ( - COMMAND grep --perl-regex --only-matching "(?<=LIBYUV_VERSION )[0-9]+" include/libyuv/version.h + COMMAND grep -Eo "LIBYUV_VERSION\ [0-9]+" include/libyuv/version.h + COMMAND grep -Eo "[0-9]+" WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE YUV_VERSION_NUMBER OUTPUT_STRIP_TRAILING_WHITESPACE ) @@ -8,7 +9,7 @@ SET ( YUV_VER_MAJOR 0 ) SET ( YUV_VER_MINOR 0 ) SET ( YUV_VER_PATCH ${YUV_VERSION_NUMBER} ) SET ( YUV_VERSION ${YUV_VER_MAJOR}.${YUV_VER_MINOR}.${YUV_VER_PATCH} ) -MESSAGE ( "Building ver.: ${YUV_VERSION}" ) +MESSAGE ( VERBOSE "Building ver.: ${YUV_VERSION}" ) # is this a 32-bit or 64-bit build? IF ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) @@ -45,7 +46,7 @@ ELSE () SET ( YUV_SYSTEM_NAME "amd-${YUV_BIT_SIZE}" ) ENDIF () ENDIF () -MESSAGE ( "Packaging for: ${YUV_SYSTEM_NAME}" ) +MESSAGE ( VERBOSE "Packaging for: ${YUV_SYSTEM_NAME}" ) # define all the variables needed by CPack to create .deb and .rpm packages SET ( CPACK_PACKAGE_VENDOR "Frank Barchard" ) diff --git a/libs/libyuv/CMakeLists.txt b/libs/libyuv/CMakeLists.txt index ed4948f066..83211a2f29 100644 --- a/libs/libyuv/CMakeLists.txt +++ b/libs/libyuv/CMakeLists.txt @@ -1,51 +1,276 @@ # CMakeLists for libyuv # Originally created for "roxlu build system" to compile libyuv on windows -# Run with -DTEST=ON to build unit tests +# Run with -DUNIT_TEST=ON to build unit tests -PROJECT ( YUV C CXX ) # "C" is required even for C++ projects -CMAKE_MINIMUM_REQUIRED( VERSION 2.8 ) -OPTION( TEST "Built unit tests" OFF ) +cmake_minimum_required( VERSION 3.16 ) +project ( YUV C CXX ) # "C" is required even for C++ projects +option( UNIT_TEST "Built unit tests" OFF ) +option( LIBYUV_DISABLE_JPEG "Disable JPEG support" OFF ) -SET ( ly_base_dir ${PROJECT_SOURCE_DIR} ) -SET ( ly_src_dir ${ly_base_dir}/source ) -SET ( ly_inc_dir ${ly_base_dir}/include ) -SET ( ly_tst_dir ${ly_base_dir}/unit_test ) -SET ( ly_lib_name yuv ) -SET ( ly_lib_static ${ly_lib_name} ) -SET ( ly_lib_shared ${ly_lib_name}_shared ) +include(CheckCSourceCompiles) -FILE ( GLOB_RECURSE ly_source_files ${ly_src_dir}/*.cc ) -LIST ( SORT ly_source_files ) +set ( ly_base_dir ${PROJECT_SOURCE_DIR} ) +set ( ly_src_dir ${ly_base_dir}/source ) +set ( ly_inc_dir ${ly_base_dir}/include ) +set ( ly_tst_dir ${ly_base_dir}/unit_test ) +set ( ly_lib_name yuv ) +set ( ly_lib_static ${ly_lib_name} ) +set ( ly_lib_shared ${ly_lib_name}_shared ) -FILE ( GLOB_RECURSE ly_unittest_sources ${ly_tst_dir}/*.cc ) -LIST ( SORT ly_unittest_sources ) +# We cannot use GLOB here since we want to be able to separate out files that +# need particular flags to enable architecture extensions like AArch64's SVE. +# TODO: More of these files could be separated out for different architectures. +set ( ly_common_source_files + ${ly_src_dir}/compare.cc + ${ly_src_dir}/compare_common.cc + ${ly_src_dir}/compare_gcc.cc + ${ly_src_dir}/compare_hvx.cc + ${ly_src_dir}/compare_wasm.cc + ${ly_src_dir}/compare_win.cc + ${ly_src_dir}/convert.cc + ${ly_src_dir}/convert_argb.cc + ${ly_src_dir}/convert_from.cc + ${ly_src_dir}/convert_from_argb.cc + ${ly_src_dir}/convert_jpeg.cc + ${ly_src_dir}/convert_to_argb.cc + ${ly_src_dir}/convert_to_i420.cc + ${ly_src_dir}/cpu_id.cc + ${ly_src_dir}/mjpeg_decoder.cc + ${ly_src_dir}/mjpeg_validate.cc + ${ly_src_dir}/planar_functions.cc + ${ly_src_dir}/rotate.cc + ${ly_src_dir}/rotate_any.cc + ${ly_src_dir}/rotate_argb.cc + ${ly_src_dir}/rotate_common.cc + ${ly_src_dir}/rotate_gcc.cc + ${ly_src_dir}/rotate_hvx.cc + ${ly_src_dir}/rotate_rvv.cc + ${ly_src_dir}/rotate_wasm.cc + ${ly_src_dir}/rotate_win.cc + ${ly_src_dir}/row_any.cc + ${ly_src_dir}/row_common.cc + ${ly_src_dir}/row_gcc.cc + ${ly_src_dir}/row_hvx.cc + ${ly_src_dir}/row_rvv.cc + ${ly_src_dir}/row_wasm.cc + ${ly_src_dir}/row_win.cc + ${ly_src_dir}/scale.cc + ${ly_src_dir}/scale_any.cc + ${ly_src_dir}/scale_argb.cc + ${ly_src_dir}/scale_common.cc + ${ly_src_dir}/scale_gcc.cc + ${ly_src_dir}/scale_hvx.cc + ${ly_src_dir}/scale_rgb.cc + ${ly_src_dir}/scale_rvv.cc + ${ly_src_dir}/scale_uv.cc + ${ly_src_dir}/scale_wasm.cc + ${ly_src_dir}/scale_win.cc + ${ly_src_dir}/video_common.cc) -INCLUDE_DIRECTORIES( BEFORE ${ly_inc_dir} ) +file ( GLOB_RECURSE ly_unittest_sources ${ly_tst_dir}/*.cc ) +list ( SORT ly_unittest_sources ) -# this creates the static library (.a) -ADD_LIBRARY ( ${ly_lib_static} STATIC ${ly_source_files} ) +include_directories( BEFORE ${ly_inc_dir} ) -# this creates the shared library (.so) -ADD_LIBRARY ( ${ly_lib_shared} SHARED ${ly_source_files} ) -SET_TARGET_PROPERTIES ( ${ly_lib_shared} PROPERTIES OUTPUT_NAME "${ly_lib_name}" ) -SET_TARGET_PROPERTIES ( ${ly_lib_shared} PROPERTIES PREFIX "lib" ) - -# this creates the conversion tool -ADD_EXECUTABLE ( yuvconvert ${ly_base_dir}/util/yuvconvert.cc ) -TARGET_LINK_LIBRARIES ( yuvconvert ${ly_lib_static} ) - - -INCLUDE ( FindJPEG ) -if (JPEG_FOUND) - include_directories( ${JPEG_INCLUDE_DIR} ) - target_link_libraries( yuvconvert ${JPEG_LIBRARY} ) - add_definitions( -DHAVE_JPEG ) +if(MSVC) + add_definitions ( -D_CRT_SECURE_NO_WARNINGS ) endif() -if(TEST) +# Need to set PIC to allow creating shared libraries from object file libraries. +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +# Build the set of objects that do not need to be compiled with flags to enable +# particular architecture features. +add_library( ${ly_lib_name}_common_objects OBJECT ${ly_common_source_files} ) +set(ly_lib_parts $) + +string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" SYSPROC) +set(LOONGARCH64_ALIASES loongarch64) +list(FIND LOONGARCH64_ALIASES "${SYSPROC}" LOONGARCH64MATCH) + +if(LOONGARCH64MATCH GREATER "-1") + set(LOONGARCH64 1) +endif() + +if(NOT MSVC) + string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" arch_lowercase) + + if(arch_lowercase MATCHES "^arm" AND NOT arch_lowercase STREQUAL "arm64") + # Enable Arm Neon kernels. + add_definitions(-DLIBYUV_NEON=1) + add_library(${ly_lib_name}_neon OBJECT + ${ly_src_dir}/compare_neon.cc + ${ly_src_dir}/rotate_neon.cc + ${ly_src_dir}/row_neon.cc + ${ly_src_dir}/scale_neon.cc) + target_compile_options(${ly_lib_name}_neon PRIVATE -mfpu=neon) + list(APPEND ly_lib_parts $) + endif() + + if(arch_lowercase STREQUAL "aarch64" OR arch_lowercase STREQUAL "arm64") + # Enable AArch64 Neon dot-product and i8mm kernels. + add_library(${ly_lib_name}_neon64 OBJECT + ${ly_src_dir}/compare_neon64.cc + ${ly_src_dir}/rotate_neon64.cc + ${ly_src_dir}/row_neon64.cc + ${ly_src_dir}/scale_neon64.cc) + target_compile_options(${ly_lib_name}_neon64 PRIVATE -march=armv8.2-a+dotprod+i8mm) + list(APPEND ly_lib_parts $) + + # Enable AArch64 SVE kernels. + add_library(${ly_lib_name}_sve OBJECT + ${ly_src_dir}/rotate_sve.cc + ${ly_src_dir}/row_sve.cc) + target_compile_options(${ly_lib_name}_sve PRIVATE -march=armv8.5-a+i8mm+sve2) + list(APPEND ly_lib_parts $) + + # Check whether the compiler can compile SME functions; this fails + # with Clang for Windows. + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(OLD_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -march=armv8.5-a+i8mm+sme") + set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + check_c_source_compiles(" +__arm_locally_streaming void func(void) { } +int main(void) { return 0; } + " CAN_COMPILE_SME) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) + set(CMAKE_TRY_COMPILE_TARGET_TYPE ${OLD_CMAKE_TRY_COMPILE_TARGET_TYPE}) + + if (CAN_COMPILE_SME) + # Enable AArch64 SME kernels. + add_library(${ly_lib_name}_sme OBJECT + ${ly_src_dir}/rotate_sme.cc + ${ly_src_dir}/row_sme.cc + ${ly_src_dir}/scale_sme.cc) + target_compile_options(${ly_lib_name}_sme PRIVATE -march=armv8.5-a+i8mm+sme) + list(APPEND ly_lib_parts $) + else() + add_definitions(-DLIBYUV_DISABLE_SME) + endif() + endif() + + if(arch_lowercase MATCHES "^riscv") + option(USE_RVV "Enable RISC-V Vector" ON) + if(USE_RVV) + if(NOT RISCV_COMPILER_FLAGS) + if(CMAKE_SIZEOF_VOID_P EQUAL 8 OR arch_lowercase STREQUAL "riscv64") + set(RISCV_COMPILER_FLAGS "-march=rv64gcv") + else() + set(RISCV_COMPILER_FLAGS "-march=rv32gcv") + endif() + endif() + + include(CheckCSourceCompiles) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(OLD_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${RISCV_COMPILER_FLAGS} -fno-tree-vectorize -fno-tree-slp-vectorize") + set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + check_c_source_compiles(" +int main(void) { return 0; } + " CAN_COMPILE_RVV) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) + set(CMAKE_TRY_COMPILE_TARGET_TYPE ${OLD_CMAKE_TRY_COMPILE_TARGET_TYPE}) + + if(CAN_COMPILE_RVV) + if(NOT CMAKE_C_FLAGS MATCHES "-march=" AND NOT CMAKE_C_FLAGS MATCHES "-mcpu=") + set(CMAKE_C_FLAGS "${RISCV_COMPILER_FLAGS} -fno-tree-vectorize -fno-tree-slp-vectorize ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "${RISCV_COMPILER_FLAGS} -fno-tree-vectorize -fno-tree-slp-vectorize ${CMAKE_CXX_FLAGS}") + endif() + else() + add_definitions(-DLIBYUV_DISABLE_RVV) + endif() + else() + add_definitions(-DLIBYUV_DISABLE_RVV) + endif() + endif() + + if(arch_lowercase MATCHES "^wasm" OR EMSCRIPTEN) + set(CMAKE_C_FLAGS "-msimd128 ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-msimd128 ${CMAKE_CXX_FLAGS}") + endif() +endif() + +if(LOONGARCH64) + include(CheckCXXSourceCompiles) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-narrowing") + check_cxx_source_compiles(" + int main(int argc, char **argv) { + __asm__ volatile ( + \"vadd.w $vr0, $vr1, $vr1\" + ); + return 0; }" SUPPORTS_LSX) + + check_cxx_source_compiles(" + int main(int argc, char **argv) { + __asm__ volatile ( + \"xvadd.w $xr0, $xr1, $xr1\" + ); + return 0; }" SUPPORTS_LASX) + + if(SUPPORTS_LSX) + # These kernels use only LSX (128-bit) instructions and must not be + # compiled with -mlasx, which would let the compiler emit 256-bit LASX + # code (e.g. for stack-array copies) and crash on LSX-only CPUs. + add_library(${ly_lib_name}_lsx OBJECT + ${ly_src_dir}/rotate_lsx.cc + ${ly_src_dir}/row_lsx.cc + ${ly_src_dir}/scale_lsx.cc) + target_compile_options(${ly_lib_name}_lsx PRIVATE -mlsx) + list(APPEND ly_lib_parts $) + endif() + if(SUPPORTS_LASX) + add_library(${ly_lib_name}_lasx OBJECT + ${ly_src_dir}/rotate_lasx.cc + ${ly_src_dir}/row_lasx.cc) + target_compile_options(${ly_lib_name}_lasx PRIVATE -mlasx) + list(APPEND ly_lib_parts $) + endif() +endif() + +# this creates the static library (.a) +add_library( ${ly_lib_static} STATIC ${ly_lib_parts}) + +# this creates the shared library (.so) +add_library( ${ly_lib_shared} SHARED ${ly_lib_parts}) +set_target_properties( ${ly_lib_shared} PROPERTIES OUTPUT_NAME "${ly_lib_name}" ) +set_target_properties( ${ly_lib_shared} PROPERTIES PREFIX "lib" ) +if(WIN32) + set_target_properties( ${ly_lib_shared} PROPERTIES IMPORT_PREFIX "lib" ) +endif() + +# this creates the cpuid tool +add_executable ( cpuid ${ly_base_dir}/util/cpuid.c ) +target_link_libraries ( cpuid ${ly_lib_static} ) + +# this creates the conversion tool +add_executable ( yuvconvert ${ly_base_dir}/util/yuvconvert.cc ) +target_link_libraries ( yuvconvert ${ly_lib_static} ) + +# this creates the yuvconstants tool +add_executable ( yuvconstants ${ly_base_dir}/util/yuvconstants.c ) +target_link_libraries ( yuvconstants ${ly_lib_static} ) +if(NOT MSVC) + target_link_libraries ( yuvconstants m ) +endif() + +if (NOT LIBYUV_DISABLE_JPEG) + find_package ( JPEG ) + if (JPEG_FOUND) + include_directories( ${JPEG_INCLUDE_DIR} ) + target_link_libraries( ${ly_lib_shared} ${JPEG_LIBRARY} ) + add_definitions( -DHAVE_JPEG ) + endif() +endif() + +if(UNIT_TEST) find_library(GTEST_LIBRARY gtest) if(GTEST_LIBRARY STREQUAL "GTEST_LIBRARY-NOTFOUND") - set(GTEST_SRC_DIR /usr/src/gtest CACHE STRING "Location of gtest sources") + set(GTEST_SRC_DIR_DEFAULT /usr/src/gtest) + if (CMAKE_CROSSCOMPILING) + set(GTEST_SRC_DIR_DEFAULT ${CMAKE_SOURCE_DIR}/third_party/googletest/src/googletest) + endif() + set(GTEST_SRC_DIR ${GTEST_SRC_DIR_DEFAULT} CACHE STRING "Location of gtest sources") if(EXISTS ${GTEST_SRC_DIR}/src/gtest-all.cc) message(STATUS "building gtest from sources in ${GTEST_SRC_DIR}") set(gtest_sources ${GTEST_SRC_DIR}/src/gtest-all.cc) @@ -54,12 +279,15 @@ if(TEST) include_directories(${GTEST_SRC_DIR}/include) set(GTEST_LIBRARY gtest) else() - message(FATAL_ERROR "TEST is set but unable to find gtest library") + message(FATAL_ERROR "UNIT_TEST is set but unable to find gtest library") endif() endif() add_executable(libyuv_unittest ${ly_unittest_sources}) target_link_libraries(libyuv_unittest ${ly_lib_name} ${GTEST_LIBRARY}) + if(NOT MSVC) + target_link_libraries(libyuv_unittest m) + endif() find_library(PTHREAD_LIBRARY pthread) if(NOT PTHREAD_LIBRARY STREQUAL "PTHREAD_LIBRARY-NOTFOUND") target_link_libraries(libyuv_unittest pthread) @@ -81,11 +309,11 @@ endif() # install the conversion tool, .so, .a, and all the header files -INSTALL ( PROGRAMS ${CMAKE_BINARY_DIR}/yuvconvert DESTINATION bin ) -INSTALL ( TARGETS ${ly_lib_static} DESTINATION lib ) -INSTALL ( TARGETS ${ly_lib_shared} LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) -INSTALL ( DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include ) +install ( TARGETS yuvconvert DESTINATION bin ) +install ( TARGETS ${ly_lib_static} DESTINATION lib ) +install ( TARGETS ${ly_lib_shared} LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib ) +install ( DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include ) # create the .deb and .rpm packages using cpack -INCLUDE ( CM_linux_packages.cmake ) +include ( CM_linux_packages.cmake ) diff --git a/libs/libyuv/DEPS b/libs/libyuv/DEPS index 758848138d..fb25ec79c9 100644 --- a/libs/libyuv/DEPS +++ b/libs/libyuv/DEPS @@ -1,135 +1,205 @@ +gclient_gn_args_file = 'src/build/config/gclient_args.gni' +gclient_gn_args = [ + 'generate_location_tags', +] + vars = { 'chromium_git': 'https://chromium.googlesource.com', - 'chromium_revision': '08ed8f830153eebaf021fabcf92aed05a4cdc2a8', + 'chromium_revision': '2fec1883d8c89392206801daa91f95eb2f8ab3e1', + 'gn_version': 'git_revision:4f6a76b64b8279e98004f541f8e136307efe5e01', + # ninja CIPD package version. + # https://chrome-infra-packages.appspot.com/p/infra/3pp/tools/ninja + 'ninja_version': 'version:3@1.12.1.chromium.4', + # reclient CIPD package version + 'reclient_version': 're_client_version:0.185.0.db415f21-gomaip', + # siso CIPD package version. + 'siso_version': 'git_revision:9863d88c26094a24fb848f8994da81e005810c76', + # CPython 3 CIPD package version for Siso hermetic toolchain. + 'cpython3_version': 'version:3@3.11.9.chromium.38', + # Fetch configuration files required for the 'use_remoteexec' gn arg + 'download_remoteexec_cfg': False, + # RBE instance to use for running remote builds + 'rbe_instance': Str('projects/rbe-webrtc-developer/instances/default_instance'), + # RBE project to download rewrapper config files for. Only needed if + # different from the project used in 'rbe_instance' + 'rewrapper_cfg_project': Str(''), + + # Keep the Chromium default of generating location tags. + 'generate_location_tags': True, + + # By default, download the fuchsia sdk from the public sdk directory. + 'fuchsia_sdk_cipd_prefix': 'fuchsia/sdk/core/', + 'fuchsia_version': 'version:31.20260204.7.1', + # By default, download the fuchsia images from the fuchsia GCS bucket. + 'fuchsia_images_bucket': 'fuchsia', + 'checkout_fuchsia': False, + # Since the images are hundreds of MB, default to only downloading the image + # most commonly useful for developers. Bots and developers that need to use + # other images can override this with additional images. + 'checkout_fuchsia_boot_images': "terminal.x64", + 'checkout_fuchsia_product_bundles': '"{checkout_fuchsia_boot_images}" != ""', + + # condition to allowlist deps for non-git-source processing. + 'non_git_source': 'True', + + 'android_sdk_build-tools_version': '-jLl4Ibk_WmgTsZaP-ueQwZDhBwkWf5BsQ4UNrkzXF0C', + 'android_sdk_emulator_version': '9lGp8nTUCRRWGMnI_96HcKfzjnxEJKUcfvfwmA3wXNkC', + 'android_sdk_platform-tools_version': 'qTD9QdBlBf3dyHsN1lJ0RH6AhHxR42Hmg2Ih-Vj4zIEC', + 'android_sdk_platforms_version': 'gxwLT70eR_ObwZJzKK8UIS-N549yAocNTmc0JHgO7gUC', } deps = { 'src/build': - Var('chromium_git') + '/chromium/src/build' + '@' + '2ee8adf846a4b485fae5ea87290f82447c638c1a', + Var('chromium_git') + '/chromium/src/build' + '@' + 'bc3e93b3c459cfa0bb6bef8944b6398bbd9a7be8', 'src/buildtools': - Var('chromium_git') + '/chromium/src/buildtools' + '@' + '74cfb57006f83cfe050817526db359d5c8a11628', + Var('chromium_git') + '/chromium/src/buildtools' + '@' + '136da69a1267b8db487354b96d44d0cc8add5aeb', 'src/testing': - Var('chromium_git') + '/chromium/src/testing' + '@' + 'ae52062d9c6d7e38df1c17b53caad1289a4742a1', + Var('chromium_git') + '/chromium/src/testing' + '@' + 'd274a4df83dc1781e42bade23902491faf30a0d2', 'src/third_party': - Var('chromium_git') + '/chromium/src/third_party' + '@' + '3a7aa3a24ca6db31d7afbee24f1c61dffc6d21f4', + Var('chromium_git') + '/chromium/src/third_party' + '@' + '51ac942dd6e95df61e747ad812f410a3c23947a0', 'src/buildtools/linux64': { 'packages': [ { - 'package': 'gn/gn/linux-amd64', - 'version': 'git_revision:972ed755f8e6d31cae9ba15fcd08136ae1a7886f', + 'package': 'gn/gn/linux-${{arch}}', + 'version': Var('gn_version'), } ], 'dep_type': 'cipd', 'condition': 'checkout_linux', }, + 'src/buildtools/mac': { 'packages': [ { - 'package': 'gn/gn/mac-amd64', - 'version': 'git_revision:972ed755f8e6d31cae9ba15fcd08136ae1a7886f', + 'package': 'gn/gn/mac-${{arch}}', + 'version': Var('gn_version'), } ], 'dep_type': 'cipd', 'condition': 'checkout_mac', }, + 'src/buildtools/win': { 'packages': [ { 'package': 'gn/gn/windows-amd64', - 'version': 'git_revision:972ed755f8e6d31cae9ba15fcd08136ae1a7886f', + 'version': Var('gn_version'), } ], 'dep_type': 'cipd', 'condition': 'checkout_win', }, - 'src/buildtools/clang_format/script': - Var('chromium_git') + '/chromium/llvm-project/cfe/tools/clang-format.git' + '@' + '96636aa0e9f047f17447f2d45a094d0b59ed7917', - 'src/buildtools/third_party/libc++/trunk': - Var('chromium_git') + '/chromium/llvm-project/libcxx.git' + '@' + '5938e0582bac570a41edb3d6a2217c299adc1bc6', - 'src/buildtools/third_party/libc++abi/trunk': - Var('chromium_git') + '/chromium/llvm-project/libcxxabi.git' + '@' + '0d529660e32d77d9111912d73f2c74fc5fa2a858', - 'src/buildtools/third_party/libunwind/trunk': - Var('chromium_git') + '/external/llvm.org/libunwind.git' + '@' + '69d9b84cca8354117b9fe9705a4430d789ee599b', + 'src/buildtools/reclient': { + 'packages': [ + { + 'package': 'infra/rbe/client/${{platform}}', + 'version': Var('reclient_version'), + } + ], + 'dep_type': 'cipd', + }, 'src/third_party/catapult': - Var('chromium_git') + '/catapult.git' + '@' + '2e1d9ff85e0a54a39f55d656086ff00a830cb7a9', + Var('chromium_git') + '/catapult.git' + '@' + '520359912034c843ec1903864f88182b1afb88d1', + 'src/third_party/clang-format/script': + Var('chromium_git') + '/external/github.com/llvm/llvm-project/clang/tools/clang-format.git' + '@' + 'c2725e0622e1a86d55f14514f2177a39efea4a0e', + 'src/third_party/compiler-rt/src': + 'https://chromium.googlesource.com/external/github.com/llvm/llvm-project/compiler-rt.git@996704b467befd58a41cda583dfb5d6f75d446e6', 'src/third_party/colorama/src': - Var('chromium_git') + '/external/colorama.git' + '@' + '799604a1041e9b3bc5d2789ecbd7e8db2e18e6b8', - 'src/third_party/freetype/src': - Var('chromium_git') + '/chromium/src/third_party/freetype2.git' + '@' + '3fa35aa420ee88856c60d3c0b7fedd43801953cc', + Var('chromium_git') + '/external/colorama.git' + '@' + '3de9f013df4b470069d03d250224062e8cf15c49', + 'src/third_party/cpu_features/src': { + 'url': Var('chromium_git') + '/external/github.com/google/cpu_features.git' + '@' + '936b9ab5515dead115606559502e3864958f7f6e', + 'condition': 'checkout_android', + }, + 'src/third_party/depot_tools': + Var('chromium_git') + '/chromium/tools/depot_tools.git' + '@' + 'ccffb57777dca15a09c9a1029acdd776d4ae9a06', + 'third_party/fuchsia-gn-sdk': { + 'url': Var('chromium_git') + '/chromium/src/third_party/fuchsia-gn-sdk.git' + '@' + '0d6902558d92fe3d49ba9a8f638ddea829be595b', + 'condition': 'checkout_fuchsia', + }, 'src/third_party/googletest/src': - Var('chromium_git') + '/external/github.com/google/googletest.git' + '@' + '565f1b848215b77c3732bca345fe76a0431d8b34', + Var('chromium_git') + '/external/github.com/google/googletest.git' + '@' + '4fe3307fb2d9f86d19777c7eb0e4809e9694dde7', 'src/third_party/harfbuzz-ng/src': - Var('chromium_git') + '/external/github.com/harfbuzz/harfbuzz.git' + '@' + 'bbad1b8298125d78c159ed7fdd7bde6a3f3fff56', + Var('chromium_git') + '/external/github.com/harfbuzz/harfbuzz.git' + '@' + 'fa2908bf16d2ccd6623f4d575455fea72a1a722b', + 'src/third_party/instrumented_libs': { + 'url': Var('chromium_git') + '/chromium/third_party/instrumented_libraries.git' + '@' + '69015643b3f68dbd438c010439c59adc52cac808', + 'condition': 'checkout_instrumented_libraries', + }, + 'src/third_party/libc++/src': + Var('chromium_git') + '/external/github.com/llvm/llvm-project/libcxx.git' + '@' + '7ab65651aed6802d2599dcb7a73b1f82d5179d05', + 'src/third_party/libc++abi/src': + Var('chromium_git') + '/external/github.com/llvm/llvm-project/libcxxabi.git' + '@' + '8f11bb1d4438d0239d0dfc1bd9456a9f31629dda', + 'src/third_party/llvm-libc/src': + Var('chromium_git') + '/external/github.com/llvm/llvm-project/libc.git' + '@' + 'd38523b674e26b7c8d61ed2e48d6cfe248b12da0', + + 'src/third_party/libunwind/src': + Var('chromium_git') + '/external/github.com/llvm/llvm-project/libunwind.git' + '@' + '17ccf7d110c5526cb77e93cfd8330f491fb2bf18', 'src/third_party/libjpeg_turbo': - Var('chromium_git') + '/chromium/deps/libjpeg_turbo.git' + '@' + 'd460d6b1cb965c3363f36f7ed716f13d60cdb65d', - 'src/third_party/yasm/source/patched-yasm': - Var('chromium_git') + '/chromium/deps/yasm/patched-yasm.git' + '@' + '720b70524a4424b15fc57e82263568c8ba0496ad', + Var('chromium_git') + '/chromium/deps/libjpeg_turbo.git' + '@' + '6bb85251a8382b5e07f635a981ac685cc5ab5053', + 'src/third_party/nasm': + Var('chromium_git') + '/chromium/deps/nasm.git' + '@' + 'af5eeeb054bebadfbb79c7bcd100a95e2ad4525f', 'src/tools': - Var('chromium_git') + '/chromium/src/tools' + '@' + '716cf8f74e9df7f53f474bae612b0b69bff8ed4e', - 'src/tools/swarming_client': - Var('chromium_git') + '/infra/luci/client-py.git' + '@' + '96f125709acfd0b48fc1e5dae7d6ea42291726ac', + Var('chromium_git') + '/chromium/src/tools' + '@' + '73a128cf7335a71785ed9324d6a15b5559ca8050', # libyuv-only dependencies (not present in Chromium). - 'src/third_party/gflags': - Var('chromium_git') + '/external/webrtc/deps/third_party/gflags' + '@' + '892576179b45861b53e04a112996a738309cf364', - 'src/third_party/gflags/src': - Var('chromium_git') + '/external/github.com/gflags/gflags' + '@' + '03bebcb065c83beff83d50ae025a55a4bf94dfca', 'src/third_party/gtest-parallel': Var('chromium_git') + '/external/webrtc/deps/third_party/gtest-parallel' + '@' + '1dad0e9f6d82ff994130b529d7d814b40eb32b0e', 'src/third_party/lss': { - 'url': Var('chromium_git') + '/linux-syscall-support.git' + '@' + '8048ece6c16c91acfe0d36d1d3cc0890ab6e945c', + 'url': Var('chromium_git') + '/linux-syscall-support.git' + '@' + '29164a80da4d41134950d76d55199ea33fbb9613', 'condition': 'checkout_android or checkout_linux', }, + 'src/third_party/re2/src': + Var('chromium_git') + '/external/github.com/google/re2.git' + '@' + '972a15cedd008d846f1a39b2e88ce48d7f166cbd', + # Android deps: - 'src/third_party/accessibility_test_framework': { + 'src/third_party/kotlin_stdlib/cipd': { 'packages': [ { - 'package': 'chromium/third_party/accessibility-test-framework', - 'version': 'b5ec1e56e58e56bc1a0c77d43111c37f9b512c8a', + 'package': 'chromium/third_party/kotlin_stdlib', + 'version': 'FfVJUc4q9S6JB4uqVGPJQ3anrc1Y_W0O-oGK_2MJA5gC', }, ], 'condition': 'checkout_android', 'dep_type': 'cipd', }, - 'src/third_party/auto/src': { - 'url': Var('chromium_git') + '/external/github.com/google/auto.git' + '@' + '8a81a858ae7b78a1aef71ac3905fade0bbd64e82', - 'condition': 'checkout_android', - }, - 'src/third_party/boringssl/src': - 'https://boringssl.googlesource.com/boringssl.git' + '@' + '05cd93068b0a553afc48f69acbceae10c6a17593', - 'src/base': { - 'url': Var('chromium_git') + '/chromium/src/base' + '@' + '3bd361995da8b0cc4e32789e3490f17e4c2997b4', - 'condition': 'checkout_android', - }, - 'src/third_party/bazel': { + + 'src/third_party/kotlinc/current': { 'packages': [ { - 'package': 'chromium/third_party/bazel', - 'version': '1794576f65a721eb0af320a0701e48d31f1b2415', + 'package': 'chromium/third_party/kotlinc', + 'version': 'KZWh3uhuenRgsoGqNYgSo82FO3sMwZjvmuR9TBvanTcC', }, ], 'condition': 'checkout_android', 'dep_type': 'cipd', }, - 'src/third_party/bouncycastle': { - 'packages': [ - { - 'package': 'chromium/third_party/bouncycastle', - 'version': 'c078e87552ba26e776566fdaf0f22cd8712743d0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - 'src/third_party/android_ndk': { - 'url': Var('chromium_git') + '/android_ndk.git' + '@' + '62582753e869484bf0cc7f7e8d184ce0077033c2', + + 'src/third_party/android_toolchain/ndk': { + 'packages': [ + { + 'package': 'chromium/third_party/android_toolchain/android_toolchain', + 'version': 'KXOia11cm9lVdUdPlbGLu8sCz6Y4ey_HV2s8_8qeqhgC', + }, + ], 'condition': 'checkout_android', + 'dep_type': 'cipd', }, + + 'src/third_party/androidx/cipd': { + 'packages': [ + { + 'package': 'chromium/third_party/androidx', + 'version': 'CL9NOUuKPO8ESaAQIKtBbN6MV0jndo4M-vT-Fjf3ZGoC', + }, + ], + 'condition': 'checkout_android and non_git_source', + 'dep_type': 'cipd', + }, + 'src/third_party/android_support_test_runner': { 'packages': [ { @@ -140,78 +210,46 @@ deps = { 'condition': 'checkout_android', 'dep_type': 'cipd', }, + 'src/third_party/android_sdk/public': { 'packages': [ { - 'package': 'chromium/third_party/android_sdk/public/build-tools', - 'version': '5DL7LQQjVMLClXLzLgmGysccPGsGcjJdvH9z5-uetiIC', + 'package': 'chromium/third_party/android_sdk/public/build-tools/36.1.0', + 'version': Var('android_sdk_build-tools_version'), }, { 'package': 'chromium/third_party/android_sdk/public/emulator', - 'version': 'xhyuoquVvBTcJelgRjMKZeoBVSQRjB7pLVJPt5C9saIC', - }, - { - 'package': 'chromium/third_party/android_sdk/public/extras', - 'version': 'ppQ4TnqDvBHQ3lXx5KPq97egzF5X2FFyOrVHkGmiTMQC', - }, - { - 'package': 'chromium/third_party/android_sdk/public/patcher', - 'version': 'I6FNMhrXlpB-E1lOhMlvld7xt9lBVNOO83KIluXDyA0C', + 'version': Var('android_sdk_emulator_version'), }, { 'package': 'chromium/third_party/android_sdk/public/platform-tools', - 'version': 'MSnxgXN7IurL-MQs1RrTkSFSb8Xd1UtZjLArI8Ty1FgC', + 'version': Var('android_sdk_platform-tools_version'), }, { - 'package': 'chromium/third_party/android_sdk/public/platforms', - 'version': 'Kg2t9p0YnQk8bldUv4VA3o156uPXLUfIFAmVZ-Gm5ewC', + 'package': 'chromium/third_party/android_sdk/public/platforms/android-36.1', + 'version': Var('android_sdk_platforms_version'), }, { - 'package': 'chromium/third_party/android_sdk/public/sources', - 'version': 'K9uEn3JvNELEVjjVK_GQD3ZQD3rqAnJSxCWxjmUmRkgC', - }, - { - 'package': 'chromium/third_party/android_sdk/public/tools', - 'version': 'wYcRQC2WHsw2dKWs4EA7fw9Qsyzu1ds1_fRjKmGxe5QC', - }, - { - 'package': 'chromium/third_party/android_sdk/public/tools-lint', - 'version': '89hXqZYzCum3delB5RV7J_QyWkaRodqdtQS0s3LMh3wC', + 'package': 'chromium/third_party/android_sdk/public/cmdline-tools/linux', + 'version': 'LZa8CWNVWS6UUQgQ7IJdFCqRV1Bmx2-alTNqEDJpJkcC', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, - 'src/tools/clang/dsymutil': { - 'packages': [ - { - 'package': 'chromium/llvm-build-tools/dsymutil', - 'version': 'OWlhXkmj18li3yhJk59Kmjbc5KdgLh56TwCd1qBdzlIC', - } - ], - 'condition': 'checkout_mac', - 'dep_type': 'cipd', - }, - 'src/third_party/android_build_tools/aapt2': { + + + 'src/third_party/android_build_tools/aapt2/cipd': { 'packages': [ { 'package': 'chromium/third_party/android_build_tools/aapt2', - 'version': 'version:3.6.0-alpha03-5516695-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - 'src/third_party/byte_buddy': { - 'packages': [ - { - 'package': 'chromium/third_party/byte_buddy', - 'version': 'c9b53316603fc2d997c899c7ca1707f809b918cd', + 'version': 'vUP1cs7krVsNHbUJpwSDR7rvWuYLGzINVa9xopPpt74C', }, ], 'condition': 'checkout_android', 'dep_type': 'cipd', }, + 'src/third_party/ced/src': { 'url': Var('chromium_git') + '/external/github.com/google/compact_enc_det.git' + '@' + 'ba412eaaacd3186085babcd901679a48863c7dd5', 'condition': 'checkout_android', @@ -234,40 +272,34 @@ deps = { 'condition': 'checkout_android', 'dep_type': 'cipd', }, - 'src/third_party/guava': { - 'packages': [ - { - 'package': 'chromium/third_party/guava', - 'version': 'a6fba501f3a0de88b9be1daa2052632de5b96a46', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - 'src/third_party/hamcrest': { + + 'src/third_party/hamcrest/cipd': { 'packages': [ { 'package': 'chromium/third_party/hamcrest', - 'version': '37eccfc658fe79695d6abb6dd497463c4372032f', + 'version': 'dBioOAmFJjqAr_DY7dipbXdVfAxUQwjOBNibMPtX8lQC', }, ], 'condition': 'checkout_android', 'dep_type': 'cipd', }, + 'src/third_party/icu': { - 'url': Var('chromium_git') + '/chromium/deps/icu.git' + '@' + '53f6b233a41ec982d8445996247093f7aaf41639', + 'url': Var('chromium_git') + '/chromium/deps/icu.git' + '@' + 'a86a32e67b8d1384b33f8fa48c83a6079b86f8cd', }, - 'src/third_party/icu4j': { + + 'src/third_party/icu4j/cipd': { 'packages': [ { 'package': 'chromium/third_party/icu4j', - 'version': 'e87e5bed2b4935913ee26a3ebd0b723ee2344354', + 'version': '8dV7WRVX0tTaNNqkLEnCA_dMofr2MJXFK400E7gOFygC', }, ], 'condition': 'checkout_android', 'dep_type': 'cipd', }, + 'src/third_party/intellij': { 'packages': [ { @@ -278,28 +310,74 @@ deps = { 'condition': 'checkout_android', 'dep_type': 'cipd', }, + 'src/third_party/jdk/current': { + 'packages': [ + { + 'package': 'chromium/third_party/jdk/linux-amd64', + 'version': '2iiuF-nKDH3moTImx2op4WTRetbfhzKoZhH7Xo44zGsC', + }, + ], + # Needed on Linux for use on chromium_presubmit (for checkstyle). + 'condition': '(checkout_android or checkout_linux) and non_git_source', + 'dep_type': 'cipd', + }, 'src/third_party/jsr-305/src': { 'url': Var('chromium_git') + '/external/jsr-305.git' + '@' + '642c508235471f7220af6d5df2d3210e3bfc0919', 'condition': 'checkout_android', }, 'src/third_party/junit/src': { - 'url': Var('chromium_git') + '/external/junit.git' + '@' + '64155f8a9babcfcf4263cf4d08253a1556e75481', + 'url': Var('chromium_git') + '/external/junit.git' + '@' + '0eb5ce72848d730da5bd6d42902fdd6a8a42055d', 'condition': 'checkout_android', }, + 'src/third_party/libunwindstack': { + 'url': Var('chromium_git') + '/chromium/src/third_party/libunwindstack.git' + '@' + '0928ad0d25e4af07c8be5ab06d0ca584f9f4ceb5', + 'condition': 'checkout_android', + }, + 'src/third_party/ninja': { + 'packages': [ + { + 'package': 'infra/3pp/tools/ninja/${{platform}}', + 'version': Var('ninja_version'), + } + ], + 'dep_type': 'cipd', + }, + 'src/third_party/siso/cipd': { + 'packages': [ + { + 'package': 'build/siso/${{platform}}', + 'version': Var('siso_version'), + } + ], + 'dep_type': 'cipd', + }, + # Always download Linux x64 package regardless of host OS for RBE workers. + 'src/third_party/cpython3/linux-amd64': { + 'packages': [ + { + 'package': 'infra/3pp/tools/cpython3/linux-amd64', + 'version': Var('cpython3_version'), + }, + ], + 'condition': 'non_git_source', + 'dep_type': 'cipd', + }, + + # Host platform package. + 'src/third_party/cpython3/host': { + 'packages': [ + { + 'package': 'infra/3pp/tools/cpython3/${{platform}}', + 'version': Var('cpython3_version'), + }, + ], + 'condition': 'non_git_source', + 'dep_type': 'cipd', + }, 'src/third_party/mockito/src': { - 'url': Var('chromium_git') + '/external/mockito/mockito.git' + '@' + '04a2a289a4222f80ad20717c25144981210d2eac', + 'url': Var('chromium_git') + '/external/mockito/mockito.git' + '@' + '7c3641bcef717ffa7d765f2c86b847d0aab1aac9', 'condition': 'checkout_android', }, - 'src/third_party/objenesis': { - 'packages': [ - { - 'package': 'chromium/third_party/objenesis', - 'version': '9e367f55e5a65781ee77bfcbaa88fb82b30e75c0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, 'src/third_party/ow2_asm': { 'packages': [ { @@ -310,11 +388,25 @@ deps = { 'condition': 'checkout_android', 'dep_type': 'cipd', }, - 'src/third_party/r8': { + + 'src/third_party/r8/cipd': { 'packages': [ { 'package': 'chromium/third_party/r8', - 'version': '6xVKWv-ssICwyU5FC1osaRpeZio2kM4Tko33I_SIK-EC', + 'version': 'MW7AMY0Q5SzgubYVtiVVg4LMjsFBcLKwKyc2dqcArAMC', + }, + ], + 'condition': 'checkout_android', + 'dep_type': 'cipd', + }, + # This duplication is intentional, so we avoid updating the r8.jar used by + # dexing unless necessary, since each update invalidates all incremental + # dexing and unnecessarily slows down all bots. + 'src/third_party/r8/d8/cipd': { + 'packages': [ + { + 'package': 'chromium/third_party/r8', + 'version': 'MW7AMY0Q5SzgubYVtiVVg4LMjsFBcLKwKyc2dqcArAMC', }, ], 'condition': 'checkout_android', @@ -324,35 +416,43 @@ deps = { 'packages': [ { 'package': 'chromium/third_party/proguard', - 'version': '3bd778c422ea5496de2ef25c007a517dbb5ce5ca', + 'version': 'Fd91BJFVlmiO6c46YMTsdy7n2f5Sk2hVVGlzPLvqZPsC', }, ], 'condition': 'checkout_android', 'dep_type': 'cipd', }, 'src/third_party/requests/src': { - 'url': Var('chromium_git') + '/external/github.com/kennethreitz/requests.git' + '@' + 'f172b30356d821d180fa4ecfa3e71c7274a32de4', + 'url': Var('chromium_git') + '/external/github.com/kennethreitz/requests.git' + '@' + 'c7e0fc087ceeadb8b4c84a0953a422c474093d6d', 'condition': 'checkout_android', }, - 'src/third_party/robolectric': { + + 'src/third_party/robolectric/cipd': { 'packages': [ { 'package': 'chromium/third_party/robolectric', - 'version': '1KXoOiNP1a_uZNdM2ybWKwAQNow1dHTXTig-ZK4Xgq8C', + 'version': 'dr-aJxRAPYDTBJXnjfht-bdxyywD6BP1lrcjZZPnRG0C', }, ], 'condition': 'checkout_android', 'dep_type': 'cipd', }, - 'src/third_party/robolectric/robolectric': { - 'url': Var('chromium_git') + '/external/robolectric.git' + '@' + '3d6dcabf5521e028c8efc2778ab6bd8c7b6d923c', - 'condition': 'checkout_android', - }, - 'src/third_party/sqlite4java': { + + 'src/third_party/sqlite4java/cipd': { 'packages': [ { 'package': 'chromium/third_party/sqlite4java', - 'version': '889660698187baa7c8b0d79f7bf58563125fbd66', + 'version': 'LofjKH9dgXIAJhRYCPQlMFywSwxYimrfDeBmaHc-Z5EC', + }, + ], + 'condition': 'checkout_android', + 'dep_type': 'cipd', + }, + 'src/third_party/turbine/cipd': { + 'packages': [ + { + 'package': 'chromium/third_party/turbine', + 'version': 'BMHNhxMhr7uGz1rh_Od_JE4kAdP9K5MXr6GN2R9tQkAC', }, ], 'condition': 'checkout_android', @@ -362,1039 +462,284 @@ deps = { 'url': Var('chromium_git') + '/chromium/third_party/ub-uiautomator.git' + '@' + '00270549ce3161ae72ceb24712618ea28b4f9434', 'condition': 'checkout_android', }, - 'src/third_party/xstream': { - 'packages': [ - { - 'package': 'chromium/third_party/xstream', - 'version': '4278b1b78b86ab7a1a29e64d5aec9a47a9aab0fe', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, # iOS deps: 'src/ios': { - 'url': Var('chromium_git') + '/chromium/src/ios' + '@' + '2f3f83ac15360abe4307e5092647d6dd3601e861', + 'url': Var('chromium_git') + '/chromium/src/ios' + '@' + '5d7abd83379e442938c885daa681ad8c48c21f63', 'condition': 'checkout_ios' }, - # Win deps: - # Dependencies used by libjpeg-turbo - 'src/third_party/yasm/binaries': { - 'url': Var('chromium_git') + '/chromium/deps/yasm/binaries.git' + '@' + '52f9b3f4b0aa06da24ef8b123058bb61ee468881', - 'condition': 'checkout_win', + 'src/third_party/llvm-build/Release+Asserts': { + 'dep_type': 'gcs', + 'bucket': 'chromium-browser-clang', + 'objects': [ + { + # The Android libclang_rt.builtins libraries are currently only included in the Linux clang package. + 'object_name': 'Linux_x64/clang-llvmorg-23-init-3706-gfc648683-1.tar.xz', + 'sha256sum': '9a5dfd23f6d37b21709327aa39562225c01a058cc209d1c629448d6d6d874ab2', + 'size_bytes': 57775784, + 'generation': 1770870606052091, + 'condition': 'host_os == "linux" or checkout_android', + }, + { + 'object_name': 'Linux_x64/llvmobjdump-llvmorg-23-init-3706-gfc648683-1.tar.xz', + 'sha256sum': '103ba738fb6ebcd290e38458fdec8fa7b95bc3216af1e60ad260bc065b49d447', + 'size_bytes': 5798432, + 'generation': 1770870606263889, + 'condition': '((checkout_linux or checkout_mac or checkout_android) and host_os == "linux")', + }, + { + 'object_name': 'Mac/clang-llvmorg-23-init-3706-gfc648683-1.tar.xz', + 'sha256sum': '0230c7c9a625ceb2d2c650d995fb9cb5cdb6ab7c0c05042f560cc0cda441a2d0', + 'size_bytes': 54682532, + 'generation': 1770870608103936, + 'condition': 'host_os == "mac" and host_cpu == "x64"', + }, + { + 'object_name': 'Mac/clang-mac-runtime-library-llvmorg-23-init-3706-gfc648683-1.tar.xz', + 'sha256sum': 'a7af5d119637f67bff7f390923a78a712b1067157c019aebf2dcddbc4ed7b640', + 'size_bytes': 1015272, + 'generation': 1770870616072374, + 'condition': 'checkout_mac and not host_os == "mac"', + }, + { + 'object_name': 'Mac/llvmobjdump-llvmorg-23-init-3706-gfc648683-1.tar.xz', + 'sha256sum': '556b8abf3ec08c42769986ea8940ac7f09fa2cfe49328a2ccccee4641efce6c4', + 'size_bytes': 5703228, + 'generation': 1770870608115133, + 'condition': 'host_os == "mac" and host_cpu == "x64"', + }, + { + 'object_name': 'Mac_arm64/clang-llvmorg-23-init-3706-gfc648683-1.tar.xz', + 'sha256sum': '34102ff942cb0d7e2163fada5aeb53f5c2438d07d8caf5ed79970b133adc04be', + 'size_bytes': 45849908, + 'generation': 1770870617609650, + 'condition': 'host_os == "mac" and host_cpu == "arm64"', + }, + { + 'object_name': 'Mac_arm64/llvmobjdump-llvmorg-23-init-3706-gfc648683-1.tar.xz', + 'sha256sum': 'aea68efe7aeab8eb4d2371e79e7dcb021e1448d8edd0d4851fa34907b93205a6', + 'size_bytes': 5446112, + 'generation': 1770870617921094, + 'condition': 'host_os == "mac" and host_cpu == "arm64"', + }, + { + 'object_name': 'Win/clang-llvmorg-23-init-3706-gfc648683-1.tar.xz', + 'sha256sum': 'cca114f624db433c2ba6458a6de34e6e474bea379f483817dd5dc0a02c59df3c', + 'size_bytes': 49244312, + 'generation': 1770870628650736, + 'condition': 'host_os == "win"', + }, + { + 'object_name': 'Win/clang-win-runtime-library-llvmorg-23-init-3706-gfc648683-1.tar.xz', + 'sha256sum': '3f2ad3f2adb92384ecdcb33385aa8beacd7f38d27bed6179e39b2e971469d028', + 'size_bytes': 2595252, + 'generation': 1770870636929948, + 'condition': 'checkout_win and not host_os == "win"', + }, + { + 'object_name': 'Win/llvmobjdump-llvmorg-23-init-3706-gfc648683-1.tar.xz', + 'sha256sum': '7baba8d463b92d16c510d67be60eed89897ba76898121ea709264cbb41066af1', + 'size_bytes': 5859968, + 'generation': 1770870628750202, + 'condition': '(checkout_linux or checkout_mac or checkout_android) and host_os == "win"', + }, + ] }, + # Everything coming after this is automatically updated by the auto-roller. # === ANDROID_DEPS Generated Code Start === - # Generated by //tools/android/roll/android_deps/fetch_all.py - 'src/third_party/android_deps/libs/android_arch_core_common': { + # Generated by //third_party/android_deps/fetch_all.py + 'src/third_party/android_deps/cipd/libs/com_android_tools_common': { 'packages': [ { - 'package': 'chromium/third_party/android_deps/libs/android_arch_core_common', - 'version': 'version:1.1.1-cr0', + 'package': 'chromium/third_party/android_deps/libs/com_android_tools_common', + 'version': 'version:2@30.2.0-beta01.cr2', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, - 'src/third_party/android_deps/libs/android_arch_lifecycle_livedata': { + 'src/third_party/android_deps/cipd/libs/com_android_tools_layoutlib_layoutlib_api': { 'packages': [ { - 'package': 'chromium/third_party/android_deps/libs/android_arch_lifecycle_livedata', - 'version': 'version:1.1.1-cr0', + 'package': 'chromium/third_party/android_deps/libs/com_android_tools_layoutlib_layoutlib_api', + 'version': 'version:2@30.2.0-beta01.cr2', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, - 'src/third_party/android_deps/libs/android_arch_lifecycle_livedata_core': { + 'src/third_party/android_deps/cipd/libs/com_android_tools_sdk_common': { 'packages': [ { - 'package': 'chromium/third_party/android_deps/libs/android_arch_lifecycle_livedata_core', - 'version': 'version:1.1.1-cr0', + 'package': 'chromium/third_party/android_deps/libs/com_android_tools_sdk_common', + 'version': 'version:2@30.2.0-beta01.cr2', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, - 'src/third_party/android_deps/libs/android_arch_core_runtime': { + 'src/third_party/android_deps/cipd/libs/com_google_android_apps_common_testing_accessibility_framework_accessibility_test_framework': { 'packages': [ { - 'package': 'chromium/third_party/android_deps/libs/android_arch_core_runtime', - 'version': 'version:1.1.1-cr0', + 'package': 'chromium/third_party/android_deps/libs/com_google_android_apps_common_testing_accessibility_framework_accessibility_test_framework', + 'version': 'version:2@4.0.0.cr2', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, - 'src/third_party/android_deps/libs/android_arch_lifecycle_viewmodel': { + 'src/third_party/android_deps/cipd/libs/com_googlecode_java_diff_utils_diffutils': { 'packages': [ { - 'package': 'chromium/third_party/android_deps/libs/android_arch_lifecycle_viewmodel', - 'version': 'version:1.1.1-cr0', + 'package': 'chromium/third_party/android_deps/libs/com_googlecode_java_diff_utils_diffutils', + 'version': 'version:2@1.3.0.cr2', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, - 'src/third_party/android_deps/libs/com_android_support_localbroadcastmanager': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_localbroadcastmanager', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_print': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_print', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/android_arch_lifecycle_common': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/android_arch_lifecycle_common', - 'version': 'version:1.1.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/android_arch_lifecycle_common_java8': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/android_arch_lifecycle_common_java8', - 'version': 'version:1.1.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/android_arch_lifecycle_runtime': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/android_arch_lifecycle_runtime', - 'version': 'version:1.1.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/androidx_annotation_annotation': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/androidx_annotation_annotation', - 'version': 'version:1.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/androidx_lifecycle_lifecycle_common': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/androidx_lifecycle_lifecycle_common', - 'version': 'version:2.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/androidx_test_core': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/androidx_test_core', - 'version': 'version:1.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/androidx_test_ext_junit': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/androidx_test_ext_junit', - 'version': 'version:1.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/androidx_test_monitor': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/androidx_test_monitor', - 'version': 'version:1.1.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/androidx_test_rules': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/androidx_test_rules', - 'version': 'version:1.1.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/androidx_test_runner': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/androidx_test_runner', - 'version': 'version:1.1.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_animated_vector_drawable': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_animated_vector_drawable', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_appcompat_v7': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_appcompat_v7', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_asynclayoutinflater': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_asynclayoutinflater', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_coordinatorlayout': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_coordinatorlayout', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_customview': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_customview', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_drawerlayout': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_drawerlayout', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_slidingpanelayout': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_slidingpanelayout', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_loader': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_loader', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_cardview_v7': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_cardview_v7', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_design': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_design', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_gridlayout_v7': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_gridlayout_v7', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_leanback_v17': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_leanback_v17', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_mediarouter_v7': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_mediarouter_v7', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_multidex': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_multidex', - 'version': 'version:1.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_palette_v7': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_palette_v7', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_preference_leanback_v17': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_preference_leanback_v17', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_preference_v14': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_preference_v14', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_preference_v7': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_preference_v7', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_recyclerview_v7': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_recyclerview_v7', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_support_annotations': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_support_annotations', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_support_compat': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_support_compat', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_support_core_ui': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_support_core_ui', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_support_core_utils': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_support_core_utils', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_support_fragment': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_support_fragment', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_support_media_compat': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_support_media_compat', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_support_v13': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_support_v13', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_support_v4': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_support_v4', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_support_vector_drawable': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_support_vector_drawable', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_transition': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_transition', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_swiperefreshlayout': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_swiperefreshlayout', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_viewpager': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_viewpager', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_collections': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_collections', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_versionedparcelable': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_versionedparcelable', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_cursoradapter': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_cursoradapter', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_interpolator': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_interpolator', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_android_support_documentfile': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_android_support_documentfile', - 'version': 'version:28.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_auth': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_auth', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_auth_api_phone': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_auth_api_phone', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_auth_base': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_auth_base', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_base': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_base', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_basement': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_basement', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_cast': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_cast', - 'version': 'version:16.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_cast_framework': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_cast_framework', - 'version': 'version:16.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_clearcut': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_clearcut', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_fido': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_fido', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_flags': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_flags', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_gcm': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_gcm', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_iid': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_iid', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_instantapps': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_instantapps', - 'version': 'version:16.0.0-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_location': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_location', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_phenotype': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_phenotype', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_places_placereport': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_places_placereport', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_stats': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_stats', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_tasks': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_tasks', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_vision': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_vision', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_android_gms_play_services_vision_common': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_android_gms_play_services_vision_common', - 'version': 'version:15.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_code_findbugs_jsr305': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_code_findbugs_jsr305', - 'version': 'version:1.3.9-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_dagger_dagger': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_dagger_dagger', - 'version': 'version:2.17-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_dagger_dagger_compiler': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_dagger_dagger_compiler', - 'version': 'version:2.17-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_dagger_dagger_producers': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_dagger_dagger_producers', - 'version': 'version:2.17-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_dagger_dagger_spi': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_dagger_dagger_spi', - 'version': 'version:2.17-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_errorprone_error_prone_annotations': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_errorprone_error_prone_annotations', - 'version': 'version:2.1.3-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_errorprone_javac_shaded': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_errorprone_javac_shaded', - 'version': 'version:9-dev-r4023-3-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_googlejavaformat_google_java_format': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_googlejavaformat_google_java_format', - 'version': 'version:1.5-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_guava_guava': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_guava_guava', - 'version': 'version:25.0-jre-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_j2objc_j2objc_annotations': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_j2objc_j2objc_annotations', - 'version': 'version:1.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_google_protobuf_protobuf_lite': { - 'packages': [ - { - 'package': 'chromium/third_party/android_deps/libs/com_google_protobuf_protobuf_lite', - 'version': 'version:3.0.1-cr0', - }, - ], - 'condition': 'checkout_android', - 'dep_type': 'cipd', - }, - - 'src/third_party/android_deps/libs/com_squareup_javapoet': { + 'src/third_party/android_deps/cipd/libs/com_squareup_javapoet': { 'packages': [ { 'package': 'chromium/third_party/android_deps/libs/com_squareup_javapoet', - 'version': 'version:1.11.0-cr0', + 'version': 'version:2@1.13.0.cr2', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, - 'src/third_party/android_deps/libs/javax_annotation_jsr250_api': { + 'src/third_party/android_deps/cipd/libs/net_bytebuddy_byte_buddy': { 'packages': [ { - 'package': 'chromium/third_party/android_deps/libs/javax_annotation_jsr250_api', - 'version': 'version:1.0-cr0', + 'package': 'chromium/third_party/android_deps/libs/net_bytebuddy_byte_buddy', + 'version': 'version:2@1.17.6.cr2', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, - 'src/third_party/android_deps/libs/javax_inject_javax_inject': { + 'src/third_party/android_deps/cipd/libs/net_bytebuddy_byte_buddy_agent': { 'packages': [ { - 'package': 'chromium/third_party/android_deps/libs/javax_inject_javax_inject', - 'version': 'version:1-cr0', + 'package': 'chromium/third_party/android_deps/libs/net_bytebuddy_byte_buddy_agent', + 'version': 'version:2@1.17.6.cr2', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, - 'src/third_party/android_deps/libs/net_sf_kxml_kxml2': { + 'src/third_party/android_deps/cipd/libs/org_ccil_cowan_tagsoup_tagsoup': { 'packages': [ { - 'package': 'chromium/third_party/android_deps/libs/net_sf_kxml_kxml2', - 'version': 'version:2.3.0-cr0', + 'package': 'chromium/third_party/android_deps/libs/org_ccil_cowan_tagsoup_tagsoup', + 'version': 'version:2@1.2.1.cr2', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, - 'src/third_party/android_deps/libs/org_checkerframework_checker_compat_qual': { + 'src/third_party/android_deps/cipd/libs/org_checkerframework_checker_compat_qual': { 'packages': [ { 'package': 'chromium/third_party/android_deps/libs/org_checkerframework_checker_compat_qual', - 'version': 'version:2.3.0-cr0', + 'version': 'version:2@2.5.5.cr2', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, - 'src/third_party/android_deps/libs/org_codehaus_mojo_animal_sniffer_annotations': { + 'src/third_party/android_deps/cipd/libs/org_jetbrains_kotlin_kotlin_android_extensions_runtime': { 'packages': [ { - 'package': 'chromium/third_party/android_deps/libs/org_codehaus_mojo_animal_sniffer_annotations', - 'version': 'version:1.14-cr0', + 'package': 'chromium/third_party/android_deps/libs/org_jetbrains_kotlin_kotlin_android_extensions_runtime', + 'version': 'version:2@1.9.22.cr2', }, ], - 'condition': 'checkout_android', + 'condition': 'checkout_android and non_git_source', + 'dep_type': 'cipd', + }, + + 'src/third_party/android_deps/cipd/libs/org_jetbrains_kotlin_kotlin_parcelize_runtime': { + 'packages': [ + { + 'package': 'chromium/third_party/android_deps/libs/org_jetbrains_kotlin_kotlin_parcelize_runtime', + 'version': 'version:2@1.9.22.cr2', + }, + ], + 'condition': 'checkout_android and non_git_source', + 'dep_type': 'cipd', + }, + + 'src/third_party/android_deps/cipd/libs/org_jsoup_jsoup': { + 'packages': [ + { + 'package': 'chromium/third_party/android_deps/libs/org_jsoup_jsoup', + 'version': 'version:2@1.15.1.cr2', + }, + ], + 'condition': 'checkout_android and non_git_source', + 'dep_type': 'cipd', + }, + + 'src/third_party/android_deps/cipd/libs/org_mockito_mockito_android': { + 'packages': [ + { + 'package': 'chromium/third_party/android_deps/libs/org_mockito_mockito_android', + 'version': 'version:2@5.19.0.cr2', + }, + ], + 'condition': 'checkout_android and non_git_source', + 'dep_type': 'cipd', + }, + + 'src/third_party/android_deps/cipd/libs/org_mockito_mockito_core': { + 'packages': [ + { + 'package': 'chromium/third_party/android_deps/libs/org_mockito_mockito_core', + 'version': 'version:2@5.19.0.cr2', + }, + ], + 'condition': 'checkout_android and non_git_source', + 'dep_type': 'cipd', + }, + + 'src/third_party/android_deps/cipd/libs/org_mockito_mockito_subclass': { + 'packages': [ + { + 'package': 'chromium/third_party/android_deps/libs/org_mockito_mockito_subclass', + 'version': 'version:2@5.19.0.cr2', + }, + ], + 'condition': 'checkout_android and non_git_source', + 'dep_type': 'cipd', + }, + + 'src/third_party/android_deps/cipd/libs/org_objenesis_objenesis': { + 'packages': [ + { + 'package': 'chromium/third_party/android_deps/libs/org_objenesis_objenesis', + 'version': 'version:2@3.3.cr2', + }, + ], + 'condition': 'checkout_android and non_git_source', 'dep_type': 'cipd', }, # === ANDROID_DEPS Generated Code End === } -# Define rules for which include paths are allowed in our source. -include_rules = [ '+gflags' ] - -pre_deps_hooks = [ - { - # Remove any symlinks from before 177567c518b121731e507e9b9c4049c4dc96e4c8. - # TODO(kjellander): Remove this in March 2017. - 'name': 'cleanup_links', - 'pattern': '.', - 'action': ['python', 'src/cleanup_links.py'], - }, -] - hooks = [ { # This clobbers when necessary (based on get_landmines.py). It should be @@ -1403,7 +748,7 @@ hooks = [ 'name': 'landmines', 'pattern': '.', 'action': [ - 'python', + 'python3', 'src/build/landmines.py', '--landmine-scripts', 'src/tools_libyuv/get_landmines.py', @@ -1416,109 +761,71 @@ hooks = [ 'name': 'sysroot_arm', 'pattern': '.', 'condition': 'checkout_linux and checkout_arm', - 'action': ['python', 'src/build/linux/sysroot_scripts/install-sysroot.py', + 'action': ['python3', 'src/build/linux/sysroot_scripts/install-sysroot.py', '--arch=arm'], }, { 'name': 'sysroot_arm64', 'pattern': '.', 'condition': 'checkout_linux and checkout_arm64', - 'action': ['python', 'src/build/linux/sysroot_scripts/install-sysroot.py', + 'action': ['python3', 'src/build/linux/sysroot_scripts/install-sysroot.py', '--arch=arm64'], }, { 'name': 'sysroot_x86', 'pattern': '.', 'condition': 'checkout_linux and (checkout_x86 or checkout_x64)', - 'action': ['python', 'src/build/linux/sysroot_scripts/install-sysroot.py', + 'action': ['python3', 'src/build/linux/sysroot_scripts/install-sysroot.py', '--arch=x86'], }, - { - 'name': 'sysroot_mips', - 'pattern': '.', - 'condition': 'checkout_linux and checkout_mips', - 'action': ['python', 'src/build/linux/sysroot_scripts/install-sysroot.py', - '--arch=mips'], - }, { 'name': 'sysroot_x64', 'pattern': '.', 'condition': 'checkout_linux and checkout_x64', - 'action': ['python', 'src/build/linux/sysroot_scripts/install-sysroot.py', + 'action': ['python3', 'src/build/linux/sysroot_scripts/install-sysroot.py', '--arch=x64'], }, { # Update the Windows toolchain if necessary. 'name': 'win_toolchain', 'pattern': '.', - 'action': ['python', 'src/build/vs_toolchain.py', 'update'], + 'action': ['python3', 'src/build/vs_toolchain.py', 'update'], }, { # Update the Mac toolchain if necessary. 'name': 'mac_toolchain', 'pattern': '.', - 'action': ['python', 'src/build/mac_toolchain.py'], + 'action': ['python3', 'src/build/mac_toolchain.py'], + 'condition': 'checkout_mac', }, - # Pull binutils for linux, enabled debug fission for faster linking / - # debugging when used with clang on Ubuntu Precise. - # https://code.google.com/p/chromium/issues/detail?id=352046 { - 'name': 'binutils', - 'pattern': 'src/third_party/binutils', + 'name': 'Download Fuchsia SDK from GCS', + 'pattern': '.', + 'condition': 'checkout_fuchsia', 'action': [ - 'python', - 'src/third_party/binutils/download.py', + 'python3', + 'src/build/fuchsia/update_sdk.py', + '--cipd-prefix={fuchsia_sdk_cipd_prefix}', + '--version={fuchsia_version}', ], }, { - # Pull clang if needed or requested via GYP_DEFINES. - # Note: On Win, this should run after win_toolchain, as it may use it. - 'name': 'clang', + 'name': 'Download Fuchsia system images', 'pattern': '.', - 'action': ['python', 'src/tools/clang/scripts/update.py'], + 'condition': 'checkout_fuchsia and checkout_fuchsia_product_bundles', + 'action': [ + 'python3', + 'src/build/fuchsia/update_product_bundles.py', + '{checkout_fuchsia_boot_images}', + ], }, { # Update LASTCHANGE. 'name': 'lastchange', 'pattern': '.', - 'action': ['python', 'src/build/util/lastchange.py', + 'action': ['python3', 'src/build/util/lastchange.py', '-o', 'src/build/util/LASTCHANGE'], }, - # Pull clang-format binaries using checked-in hashes. - { - 'name': 'clang_format_win', - 'pattern': '.', - 'action': [ 'download_from_google_storage', - '--no_resume', - '--platform=win32', - '--no_auth', - '--bucket', 'chromium-clang-format', - '-s', 'src/buildtools/win/clang-format.exe.sha1', - ], - }, - { - 'name': 'clang_format_mac', - 'pattern': '.', - 'action': [ 'download_from_google_storage', - '--no_resume', - '--platform=darwin', - '--no_auth', - '--bucket', 'chromium-clang-format', - '-s', 'src/buildtools/mac/clang-format.sha1', - ], - }, - { - 'name': 'clang_format_linux', - 'pattern': '.', - 'condition': 'host_os == "linux"', - 'action': [ 'download_from_google_storage', - '--no_resume', - '--platform=linux*', - '--no_auth', - '--bucket', 'chromium-clang-format', - '-s', 'src/buildtools/linux64/clang-format.sha1', - ], - }, # Pull luci-go binaries (isolate, swarming) using checked-in hashes. { 'name': 'luci-go_win', @@ -1526,7 +833,6 @@ hooks = [ 'action': [ 'download_from_google_storage', '--no_resume', '--platform=win32', - '--no_auth', '--bucket', 'chromium-luci', '-d', 'src/tools/luci-go/win64', ], @@ -1537,7 +843,6 @@ hooks = [ 'action': [ 'download_from_google_storage', '--no_resume', '--platform=darwin', - '--no_auth', '--bucket', 'chromium-luci', '-d', 'src/tools/luci-go/mac64', ], @@ -1548,23 +853,75 @@ hooks = [ 'action': [ 'download_from_google_storage', '--no_resume', '--platform=linux*', - '--no_auth', '--bucket', 'chromium-luci', '-d', 'src/tools/luci-go/linux64', ], }, { - # We used to use src as a CIPD root. We moved it to a different directory - # in crrev.com/c/930178 but left the clobber here to ensure that that CL - # could be reverted safely. This can be safely removed once crbug.com/794764 - # is resolved. - 'name': 'Android Clobber Deprecated CIPD Root', + 'name': 'Generate component metadata for tests', 'pattern': '.', - 'condition': 'checkout_android', - 'action': ['src/build/cipd/clobber_cipd_root.py', - '--root', 'src', + 'action': [ + 'vpython3', + 'src/testing/generate_location_tags.py', + '--out', + 'src/testing/location_tags.json', + ], + }, + # Download remote exec cfg files + { + 'name': 'configure_reclient_cfgs', + 'pattern': '.', + 'condition': 'download_remoteexec_cfg', + 'action': ['python3', + 'src/buildtools/reclient_cfgs/configure_reclient_cfgs.py', + '--rbe_instance', + Var('rbe_instance'), + '--reproxy_cfg_template', + 'reproxy.cfg.template', + '--rewrapper_cfg_project', + Var('rewrapper_cfg_project'), + '--quiet', + ], + }, + # Configure Siso for developer builds. + { + 'name': 'configure_siso', + 'pattern': '.', + 'action': ['python3', + 'src/build/config/siso/configure_siso.py', + '--rbe_instance', + Var('rbe_instance'), + ], + }, + { + 'name': 'dsymutil_mac_arm64', + 'pattern': '.', + 'condition': 'host_os == "mac" and host_cpu == "arm64"', + 'action': [ 'python3', + 'src/third_party/depot_tools/download_from_google_storage.py', + '--no_resume', + '--no_auth', + '--bucket', 'chromium-browser-clang', + '-s', 'src/tools/clang/dsymutil/bin/dsymutil.arm64.sha1', + '-o', 'src/tools/clang/dsymutil/bin/dsymutil', + ], + }, + { + 'name': 'dsymutil_mac_x64', + 'pattern': '.', + 'condition': 'host_os == "mac" and host_cpu == "x64"', + 'action': [ 'python3', + 'src/third_party/depot_tools/download_from_google_storage.py', + '--no_resume', + '--no_auth', + '--bucket', 'chromium-browser-clang', + '-s', 'src/tools/clang/dsymutil/bin/dsymutil.x64.sha1', + '-o', 'src/tools/clang/dsymutil/bin/dsymutil', ], }, ] -recursedeps = [] +recursedeps = [ + 'src/buildtools', + 'src/third_party/instrumented_libs', +] diff --git a/libs/libyuv/DIR_METADATA b/libs/libyuv/DIR_METADATA new file mode 100644 index 0000000000..8bc04f159c --- /dev/null +++ b/libs/libyuv/DIR_METADATA @@ -0,0 +1,3 @@ +monorail { + component: "Internals>Images>Codecs" +} diff --git a/libs/libyuv/GEMINI.md b/libs/libyuv/GEMINI.md new file mode 100644 index 0000000000..d9cfd977a1 --- /dev/null +++ b/libs/libyuv/GEMINI.md @@ -0,0 +1,177 @@ +# Gemini Project Context: libyuv Row Functions + +This file provides context for the core row-processing architecture of +libyuv. Use these guidelines when refactoring, reviewing, or generating +code within the `row_*.cc` files. + +## Architectural Overview + +Libyuv uses a dispatch system where high-level conversion functions call +optimized "Row" functions. These functions are categorized by SIMD architecture +and compiler compatibility. + +## Source File Map + +### x86 Architectures (32-bit and 64-bit) + +* **row_gcc.cc**: **Master copy.** Contains inline assembly in GCC syntax for + GCC and Clang. Supports AVX, and AVX512. AVX512 implementations are strictly + for 64-bit targets. +* **row_win.cc**: Derivative of `row_gcc.cc`. Contains C++ intrinsics + specifically for Visual C++ (MSVC). Can be tested with Clang using + `-DLIBYUV_ENABLE_ROWWIN`. +* **Note**: Use either `row_gcc` or `row_win`, never both. + +### Arm Architecture (32-bit) + +* **row_neon.cc**: 32-bit Arm. Written entirely in inline assembly for + GCC/Clang. + +### Arm Architecture (AArch64) (64-bit) + +* **row_neon64.cc**: 64-bit Arm (AArch64) Neon. Written entirely in inline + assembly for GCC/Clang. +* **row_sve.cc**: Armv9 Scalable Vector Extension (SVE2). +* **row_sme.cc**: Armv9 Scalable Matrix Extension (SME) and Streaming SVE + (SSVE). +* **row_sve.h**: Streaming-compatible implementations shared across + **row_sve.cc** and **row_sme.cc**. + +### Other Architectures + +* **row_rvv.cc**: RISC-V Vector (RVV). Implemented using intrinsics. Optimized + for SiFive X280. +* **row_hvx.cc**: Qualcomm Hexagon Vector Extensions (HVX). Implemented using + intrinsics. +* **row_lsx.cc / row_lasx.cc**: Loongarch MIPS-like extensions. + +### Utility and Fallbacks + +* **row_common.cc**: Portable C/C++ versions and multi-step `ARGB` wrapper + row functions. This is the reference implementation. +* **row_any.cc**: Handles "remainder" pixels for widths not multiples of SIMD + register size. Used for SSE/AVX2, Neon, and LoongArch (LSX/LASX). Not + required for AVX-512, SVE2, SME, RVV, or HVX, which handle tail masking + directly inside the Row function. + +## Deprecated and Lower-Priority Formats + +The following datatypes and functions are deprecated or lower priority and are +not always fully hand-optimized across every SIMD extension: + +* **16-bit RGB formats** (deprecated): `RGB565` (`FOURCC_RGBP`, + `FOURCC_L565`), `ARGB1555` (`FOURCC_RGBO`, `FOURCC_L555`, `FOURCC_5551`), + and `ARGB4444` (`FOURCC_R444`). +* **Legacy fixed-matrix RGB-to-YUV row functions** (deprecated in favor of + `*MatrixRow` variants): `RGB565ToYRow`, `RGB565ToUVRow`, `ARGB1555ToYRow`, + `ARGB1555ToUVRow`, `ARGB4444ToYRow`, `ARGB4444ToUVRow`. +* **Row-biplanar YUV** (deprecated): `M420` (`FOURCC_M420`). + +When adding SIMD coverage for deprecated or less relevant formats, prefer +two-step wrapper implementations in `source/row_common.cc` that convert to or +from an intermediate stack-allocated `ARGB` row buffer (or delegate to existing +`*MatrixRow` functions) rather than writing large bespoke assembly kernels. + +## Coding Guidelines + +1. **Feature Macros**: Use the `HAS_` macros in `include/libyuv/row.h` to + enable or disable specific instruction set extensions. +2. **Inline asm clobbers (all architectures)**: Every register written by an + inline asm block must be listed in its clobber list: vector registers, + general purpose registers, mask/predicate registers, `"cc"` when flags + are set (`subs`, `cmp`, `whilelt`, ...) and `"memory"` when the block + stores. Declare them even if the ABI treats them as caller-saved: with + LTO/LTCG the compiler may keep values live in any register across the + asm, and other OS ABIs (e.g. Windows) differ in which registers are + callee-saved. Never remove a clobber because it "is not needed by the + ABI". Use real register names, not numbers (`"v22"`, not `"22"`). Order + the list `"memory"` first (when stores occur), then `"cc"` (on + architectures with flags), then registers. + +### x86 Architectures (32-bit and 64-bit) + +1. **AVX512 Logic**: AVX512 row functions are strictly enabled for **64-bit x86 + only**. Do not create `_Any_` wrappers for AVX512 row functions; handle + arbitrary tail widths directly inside the Row function using `k1`-`k7` + opmask registers. +2. **MSVC Intrinsics (`row_win.cc`)**: When converting `row_gcc.cc` to + `row_win.cc`, use `_mm512_permutex2var_epi8`, not `_mm512_permi2var_epi8` + intrinsic. +3. **Clobber names**: Always declare vector clobbers as `"xmmN"`, never + `"ymmN"` or `"zmmN"`, including for AVX2 and AVX512 code. Clang for + Windows must preserve xmm6-xmm15 and does not save them when they are + declared as ymm or zmm. +4. **MSan Intrinsics (`*_win.cc`)**: Clang builds with MemorySanitizer + (`-fsanitize=memory`) define `LIBYUV_ENABLE_ROWWIN` and compile `*_win.cc` + (`row_win.cc`, `scale_win.cc`, `compare_win.cc`, `rotate_win.cc`) instead of + inline assembly (`*_gcc.cc`). When porting `*_gcc.cc` to `*_win.cc`, never + use AVX-512 intrinsics that LLVM's MSan pass does not model: + * **Down-converting masked stores**: Never use + `_mm512_mask_cvtepi32_storeu_epi8`, `_mm512_mask_cvtepi64_storeu_epi8`, + `_mm512_mask_cvtepi16_storeu_epi8`, or + `_mm512_mask_cvtepi32_storeu_epi16`. They lower to target-specific + `@llvm.x86.avx512.mask.pmov.*.mem.*` intrinsics that LLVM MSan does not + model, leaving the destination shadow memory poisoned (uninitialized). + Instead, convert to a narrower vector first and use a standard masked + store (e.g. `_mm_mask_storeu_epi8(dst, mask, _mm512_cvtepi32_epi8(v))`), + which lowers to `@llvm.masked.store` for MSan and still compiles to a + single `vpmovdb` instruction at `-O2`. + * **Ternary logic (`_mm*_ternarylogic_epi32` / `epi64`)**: Never use + `_mm512_ternarylogic_epi32`/`epi64` (or `_mm256_`/`_mm_` variants) + anywhere in `*_win.cc` when porting `vpternlogd`/`vpternlogq` from + `*_gcc.cc`. They lower to `@llvm.x86.avx512.pternlog.*`, which LLVM MSan + does not model bitwise—`handleUnknownIntrinsic` traps immediately with + `use-of-uninitialized-value` if *any* bit of any of the three inputs is + uninitialized (such as the unused alpha byte of an `RGBX` buffer or tail + padding), even if masked off by `imm8` or merely copied to memory. + * For boolean blends and inversions (e.g. `ARGBGrayRow_AVX512VNNI`, + `I422ToAR30Row_AVX512BW`, `ARGBToUV444MatrixRow_AVX512VNNIVBMI`), + use standard bitwise intrinsics (`_mm512_and_si512`, + `_mm512_andnot_si512`, `_mm512_or_si512`, `_mm512_xor_si512`), which + LLVM MSan models bit-by-bit and Clang `-O2` folds back into + `vpternlog` in non-MSan builds. + * For write-only partial channel updates into `dst` (e.g. writing + alpha in `ARGBCopyYToAlphaRow_AVX512BW`), use byte-masked stores + (`_mm512_mask_storeu_epi8`) instead of reading `dst` and blending. + * **Single-source variable permutes (`_mm512_permutexvar_epi*` / + `_mm512_mask_permutexvar_epi*`)**: Never use + `_mm512_permutexvar_epi{8,16,32,64}` or + `_mm512_mask_permutexvar_epi{8,16,32,64}` directly. They lower to + `@llvm.x86.avx512.permvar.*`, which LLVM MSan does not model + lane-by-lane—instead it ORs the input shadows without permuting them, + poisoning initialized output lanes whenever *any* lane of the input + vector is uninitialized (e.g. `_mm512_castsi128_si512`, + `_mm512_castsi256_si512`, unused `RGBX` alpha bytes, or uninitialized + tail lanes). Use the `PermutexvarEpi*` and `MaskPermutexvarEpi*` + helpers in `row_win.cc` / `scale_win.cc`, which use portable + lane-by-lane C loops under `LIBYUV_MSAN` and the native intrinsics + otherwise. + * **512-bit float-to-int truncation (`_mm512_cvttps_epi32`)**: Never use + `_mm512_cvttps_epi32` directly; it lowers to + `@llvm.x86.avx512.mask.cvttps2dq.512`, which LLVM MSan does not model + lane-by-lane. Use the `CvttpsEpi32` helper in `row_win.cc`, which uses + a portable lane-by-lane C loop under `LIBYUV_MSAN` and + `_mm512_cvttps_epi32` otherwise. + +### AArch64 + +1. For SVE2/SME, aim to use full predicates (`ptrue`) and full vectors for the + main loop body and use predication only to mask the tail loop as needed. + Pointer updates should be done with `inc[bhwd]` or `add`, not by `incp`. + +## Changelist (CL) Format Guidelines + +When adding new code, remove trailing spaces. +When generating descriptions, follow the Chromium standard format. Wrap +commit message text at 72 characters + +### Changelist (CL) Description Example + +\[libyuv] Optimized ARGBToRGB24 for AVX2 + +Detailed technical explanation of the change. Describe the SIMD +optimization logic and any platform-specific constraints. Mention +if this impacts specific row files like row_gcc.cc. + +Test: libyuv_unittest --gunit_filter=*ARGBToRGB24* +Bug: libyuv:12345, b/67890 diff --git a/libs/libyuv/OWNERS b/libs/libyuv/OWNERS index 7b21adfe6c..7345e8767b 100644 --- a/libs/libyuv/OWNERS +++ b/libs/libyuv/OWNERS @@ -1,8 +1,10 @@ fbarchard@chromium.org -magjed@chromium.org +wtc@google.com +mbonadei@chromium.org +jansson@google.com -per-file *.gn=phoglund@chromium.org +per-file *.gn=mbonadei@chromium.org,jansson@google.com per-file .gitignore=* per-file AUTHORS=* per-file DEPS=* -per-file PRESUBMIT.py=phoglund@chromium.org +per-file PRESUBMIT.py=mbonadei@chromium.org,jansson@google.com diff --git a/libs/libyuv/PRESUBMIT.py b/libs/libyuv/PRESUBMIT.py index 2cf1542ff1..37df28a106 100644 --- a/libs/libyuv/PRESUBMIT.py +++ b/libs/libyuv/PRESUBMIT.py @@ -6,67 +6,60 @@ # in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. -import os - - -def _RunPythonTests(input_api, output_api): - def join(*args): - return input_api.os_path.join(input_api.PresubmitLocalPath(), *args) - - test_directories = [ - root for root, _, files in os.walk(join('tools_libyuv')) - if any(f.endswith('_test.py') for f in files) - ] - - tests = [] - for directory in test_directories: - tests.extend( - input_api.canned_checks.GetUnitTestsInDirectory( - input_api, - output_api, - directory, - whitelist=[r'.+_test\.py$'])) - return input_api.RunTests(tests, parallel=True) +# Runs PRESUBMIT.py in py3 mode by git cl presubmit. +USE_PYTHON3 = True def _CommonChecks(input_api, output_api): - """Checks common to both upload and commit.""" - results = [] - results.extend(input_api.canned_checks.RunPylint(input_api, output_api, - black_list=(r'^base[\\\/].*\.py$', - r'^build[\\\/].*\.py$', - r'^buildtools[\\\/].*\.py$', - r'^ios[\\\/].*\.py$', - r'^out.*[\\\/].*\.py$', - r'^testing[\\\/].*\.py$', - r'^third_party[\\\/].*\.py$', - r'^tools[\\\/].*\.py$', - # TODO(kjellander): should arguably be checked. - r'^tools_libyuv[\\\/]valgrind[\\\/].*\.py$', - r'^xcodebuild.*[\\\/].*\.py$',), - disabled_warnings=['F0401', # Failed to import x - 'E0611', # No package y in x - 'W0232', # Class has no __init__ method - ], - pylintrc='pylintrc')) - results.extend(_RunPythonTests(input_api, output_api)) - return results + """Checks common to both upload and commit.""" + results = [] + results.extend( + input_api.canned_checks.RunPylint( + input_api, + output_api, + files_to_skip=( + r'^base[\\\/].*\.py$', + r'^build[\\\/].*\.py$', + r'^buildtools[\\\/].*\.py$', + r'^ios[\\\/].*\.py$', + r'^out.*[\\\/].*\.py$', + r'^testing[\\\/].*\.py$', + r'^third_party[\\\/].*\.py$', + r'^tools[\\\/].*\.py$', + # TODO(kjellander): should arguably be checked. + r'^tools_libyuv[\\\/]valgrind[\\\/].*\.py$', + r'^xcodebuild.*[\\\/].*\.py$', + ), + disabled_warnings=[ + 'F0401', # Failed to import x + 'E0611', # No package y in x + 'W0232', # Class has no __init__ method + ], + pylintrc='pylintrc', + version='2.7', + ) + ) + return results def CheckChangeOnUpload(input_api, output_api): - results = [] - results.extend(_CommonChecks(input_api, output_api)) - results.extend( - input_api.canned_checks.CheckGNFormatted(input_api, output_api)) - return results + results = [] + results.extend(_CommonChecks(input_api, output_api)) + results.extend( + input_api.canned_checks.CheckGNFormatted(input_api, output_api) + ) + return results def CheckChangeOnCommit(input_api, output_api): - results = [] - results.extend(_CommonChecks(input_api, output_api)) - results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) - results.extend(input_api.canned_checks.CheckChangeWasUploaded( - input_api, output_api)) - results.extend(input_api.canned_checks.CheckChangeHasDescription( - input_api, output_api)) - return results + results = [] + results.extend(_CommonChecks(input_api, output_api)) + results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) + results.extend( + input_api.canned_checks.CheckChangeWasUploaded(input_api, output_api) + ) + results.extend( + input_api.canned_checks.CheckChangeHasDescription(input_api, + output_api) + ) + return results diff --git a/libs/libyuv/README.chromium b/libs/libyuv/README.chromium index dadffc9c3b..0bac66a43c 100644 --- a/libs/libyuv/README.chromium +++ b/libs/libyuv/README.chromium @@ -1,8 +1,13 @@ Name: libyuv -URL: http://code.google.com/p/libyuv/ -Version: 1735 -License: BSD +URL: https://chromium.googlesource.com/libyuv/libyuv/ +Version: 1977 +Revision: DEPS +License: BSD-3-Clause License File: LICENSE +Shipped: yes +Security Critical: yes +Update Mechanism: Manual Description: libyuv is an open source project that includes YUV conversion and scaling functionality. + diff --git a/libs/libyuv/README.md b/libs/libyuv/README.md index db70b7f08d..4baa69cd5e 100644 --- a/libs/libyuv/README.md +++ b/libs/libyuv/README.md @@ -5,8 +5,9 @@ * Convert to RGB formats for rendering/effects. * Rotate by 90/180/270 degrees to adjust for mobile devices in portrait mode. * Optimized for SSSE3/AVX2 on x86/x64. -* Optimized for Neon on Arm. +* Optimized for Neon/SVE2/SME on Arm. * Optimized for MSA on Mips. +* Optimized for RVV on RISC-V. ### Development diff --git a/libs/libyuv/WORKSPACE.bazel b/libs/libyuv/WORKSPACE.bazel new file mode 100644 index 0000000000..0b288ac64c --- /dev/null +++ b/libs/libyuv/WORKSPACE.bazel @@ -0,0 +1,14 @@ +workspace(name = "libyuv") + +android_sdk_repository( + name = "androidsdk", + # Bazel will automatically use the ANDROID_HOME environment variable. +) + +android_ndk_repository( + name = "androidndk", + # Bazel will automatically use the ANDROID_NDK_HOME environment variable. +) + +# Optional: If you need to fetch specific dependencies (e.g., GoogleTest, libjpeg-turbo) +# you can define them here using http_archive. diff --git a/libs/libyuv/build_overrides/build.gni b/libs/libyuv/build_overrides/build.gni index 6d8319b965..2a7051d075 100644 --- a/libs/libyuv/build_overrides/build.gni +++ b/libs/libyuv/build_overrides/build.gni @@ -6,9 +6,6 @@ # in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. -# Some non-Chromium builds don't use Chromium's third_party/binutils. -linux_use_bundled_binutils_override = true - # Variable that can be used to support multiple build scenarios, like having # Chromium specific targets in a client project's GN file etc. build_with_chromium = false @@ -16,6 +13,9 @@ build_with_chromium = false # Some non-Chromium builds don't support building java targets. enable_java_templates = true +# Enables assertions on safety checks in libc++. +enable_safe_libcxx = true + # Allow using custom suppressions files (currently not used by libyuv). asan_suppressions_file = "//build/sanitizers/asan_suppressions.cc" lsan_suppressions_file = "//build/sanitizers/lsan_suppressions.cc" @@ -35,12 +35,31 @@ ignore_elf32_limitations = true # Use bundled hermetic Xcode installation maintained by Chromium, # except for local iOS builds where it is unsupported. -if (host_os == "mac") { +# Allow for mac cross compile on linux machines. +if (host_os == "mac" || host_os == "linux") { _result = exec_script("//build/mac/should_use_hermetic_xcode.py", [ target_os ], "value") assert(_result != 2, - "Do not allow building targets with the default" + + "Do not allow building targets with the default " + "hermetic toolchain if the minimum OS version is not met.") use_system_xcode = _result == 0 } + +declare_args() { + # Limits the defined //third_party/android_deps targets to only "buildCompile" + # and "buildCompileNoDeps" targets. This is useful for third-party + # repositories which do not use JUnit tests. For instance, + # limit_android_deps == true removes "gn gen" requirement for + # //third_party/robolectric . + limit_android_deps = false + + # Allows googletest to pretty-print various absl types. + # Defined here rather than in gtest.gni to match chromium. + gtest_enable_absl_printers = true +} + +vpython_spec_files = [ + "//vpython.toml", + "//vpython.toml.uv.lock", +] diff --git a/libs/libyuv/build_overrides/partition_alloc.gni b/libs/libyuv/build_overrides/partition_alloc.gni new file mode 100644 index 0000000000..dcf8ac2d25 --- /dev/null +++ b/libs/libyuv/build_overrides/partition_alloc.gni @@ -0,0 +1,17 @@ +# Copyright 2022 The LibYuv Project Authors. All rights reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +# Use default values for PartitionAlloc as standalone library from +# base/allocator/partition_allocator/build_overrides/partition_alloc.gni +use_partition_alloc_as_malloc_default = false +use_allocator_shim_default = false +enable_backup_ref_ptr_support_default = false +enable_mte_checked_ptr_support_default = false +put_ref_count_in_previous_slot_default = false +enable_backup_ref_ptr_slow_checks_default = false +enable_dangling_raw_ptr_checks_default = false diff --git a/libs/libyuv/cleanup_links.py b/libs/libyuv/cleanup_links.py deleted file mode 100755 index ba2907892f..0000000000 --- a/libs/libyuv/cleanup_links.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env python -# Copyright 2017 The LibYuv Project Authors. All rights reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -# This is a copy of the file from WebRTC in: -# https://chromium.googlesource.com/external/webrtc/+/master/cleanup_links.py - -"""Script to cleanup symlinks created from setup_links.py. - -Before 177567c518b121731e507e9b9c4049c4dc96e4c8 (#15754) we had a Chromium -checkout which we created symlinks into. In order to do clean syncs after -landing that change, this script cleans up any old symlinks, avoiding annoying -manual cleanup needed in order to complete gclient sync. -""" - -import logging -import optparse -import os -import shelve -import subprocess -import sys - - -ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) -LINKS_DB = 'links' - -# Version management to make future upgrades/downgrades easier to support. -SCHEMA_VERSION = 1 - -class WebRTCLinkSetup(object): - def __init__(self, links_db, dry_run=False): - self._dry_run = dry_run - self._links_db = links_db - - def CleanupLinks(self): - logging.debug('CleanupLinks') - for source, link_path in self._links_db.iteritems(): - if source == 'SCHEMA_VERSION': - continue - if os.path.islink(link_path) or sys.platform.startswith('win'): - # os.path.islink() always returns false on Windows - # See http://bugs.python.org/issue13143. - logging.debug('Removing link to %s at %s', source, link_path) - if not self._dry_run: - if os.path.exists(link_path): - if sys.platform.startswith('win') and os.path.isdir(link_path): - subprocess.check_call(['rmdir', '/q', '/s', link_path], - shell=True) - else: - os.remove(link_path) - del self._links_db[source] - - -def _initialize_database(filename): - links_database = shelve.open(filename) - # Wipe the database if this version of the script ends up looking at a - # newer (future) version of the links db, just to be sure. - version = links_database.get('SCHEMA_VERSION') - if version and version != SCHEMA_VERSION: - logging.info('Found database with schema version %s while this script only ' - 'supports %s. Wiping previous database contents.', version, - SCHEMA_VERSION) - links_database.clear() - links_database['SCHEMA_VERSION'] = SCHEMA_VERSION - return links_database - - -def main(): - parser = optparse.OptionParser() - parser.add_option('-d', '--dry-run', action='store_true', default=False, - help='Print what would be done, but don\'t perform any ' - 'operations. This will automatically set logging to ' - 'verbose.') - parser.add_option('-v', '--verbose', action='store_const', - const=logging.DEBUG, default=logging.INFO, - help='Print verbose output for debugging.') - options, _ = parser.parse_args() - - if options.dry_run: - options.verbose = logging.DEBUG - logging.basicConfig(format='%(message)s', level=options.verbose) - - # Work from the root directory of the checkout. - script_dir = os.path.dirname(os.path.abspath(__file__)) - os.chdir(script_dir) - - # The database file gets .db appended on some platforms. - db_filenames = [LINKS_DB, LINKS_DB + '.db'] - if any(os.path.isfile(f) for f in db_filenames): - links_database = _initialize_database(LINKS_DB) - try: - symlink_creator = WebRTCLinkSetup(links_database, options.dry_run) - symlink_creator.CleanupLinks() - finally: - for f in db_filenames: - if os.path.isfile(f): - os.remove(f) - return 0 - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/libs/libyuv/codereview.settings b/libs/libyuv/codereview.settings index 00ba1d37d0..b226fae57a 100644 --- a/libs/libyuv/codereview.settings +++ b/libs/libyuv/codereview.settings @@ -1,6 +1,5 @@ -# This file is used by git cl to get repository specific information. +# This file is used by `git cl` to get repository specific information. CODE_REVIEW_SERVER: codereview.chromium.org GERRIT_HOST: True PROJECT: libyuv -TRY_ON_UPLOAD: False VIEW_VC: https://chromium.googlesource.com/libyuv/libyuv/+/ diff --git a/libs/libyuv/docs/deprecated_builds.md b/libs/libyuv/docs/deprecated_builds.md index 29e0bf9bc3..747260ee8e 100644 --- a/libs/libyuv/docs/deprecated_builds.md +++ b/libs/libyuv/docs/deprecated_builds.md @@ -11,23 +11,7 @@ Refer to chromium instructions for each platform for other prerequisites. Create a working directory, enter it, and run: - gclient config https://chromium.googlesource.com/libyuv/libyuv - gclient sync - - -Then you'll get a .gclient file like: - - solutions = [ - { "name" : "libyuv", - "url" : "https://chromium.googlesource.com/libyuv/libyuv", - "deps_file" : "DEPS", - "managed" : True, - "custom_deps" : { - }, - "safesync_url": "", - }, - ]; - + fetch libyuv For iOS add `;target_os=['ios'];` to your OSX .gclient and run `GYP_DEFINES="OS=ios" gclient sync.` @@ -157,19 +141,13 @@ ia32 GYP_DEFINES="OS=android target_arch=ia32 android_full_debug=1" GYP_CROSSCOMPILE=1 ./gyp_libyuv ninja -j7 -C out/Debug yuv_unittest_apk -mipsel - - GYP_DEFINES="OS=android target_arch=mipsel" GYP_CROSSCOMPILE=1 ./gyp_libyuv - ninja -j7 -C out/Debug yuv_unittest_apk - ninja -j7 -C out/Release yuv_unittest_apk - arm32 disassembly: - third_party/android_ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-objdump -d out/Release/obj/source/libyuv.row_neon.o + llvm-objdump -d out/Release/obj/source/libyuv.row_neon.o arm64 disassembly: - third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-objdump -d out/Release/obj/source/libyuv.row_neon64.o + llvm-objdump -d out/Release/obj/source/libyuv.row_neon64.o Running tests: @@ -195,16 +173,6 @@ Running test with C code: gn gen out/Official "--args=is_debug=false is_official_build=true is_chrome_branded=true" ninja -C out/Official -#### Building mips with GN - -mipsel - gn gen out/Default "--args=is_debug=false target_cpu=\"mipsel\" target_os = \"android\" mips_arch_variant = \"r6\" mips_use_msa = true is_component_build = true is_clang = false" - ninja -C out/Default - -mips64el - gn gen out/Default "--args=is_debug=false target_cpu=\"mips64el\" target_os = \"android\" mips_arch_variant = \"r6\" mips_use_msa = true is_component_build = true is_clang = false" - ninja -C out/Default - ### Linux GYP_DEFINES="target_arch=x64" ./gyp_libyuv @@ -239,6 +207,7 @@ If you get a compile error for atlthunk.lib on Windows, read http://www.chromium ninja -C out/Debug libyuv_unittest ninja -C out/Debug compare ninja -C out/Debug yuvconvert + ninja -C out/Debug yuvconstants ninja -C out/Debug psnr ninja -C out/Debug cpuid diff --git a/libs/libyuv/docs/environment_variables.md b/libs/libyuv/docs/environment_variables.md index cd8159ad5a..a46744e45b 100644 --- a/libs/libyuv/docs/environment_variables.md +++ b/libs/libyuv/docs/environment_variables.md @@ -7,9 +7,11 @@ For test purposes, environment variables can be set to control libyuv behavior. By default the cpu is detected and the most advanced form of SIMD is used. But you can disable instruction sets selectively, or completely, falling back on C code. Set the variable to 1 to disable the specified instruction set. ## All CPUs + LIBYUV_DISABLE_ASM ## Intel CPUs + LIBYUV_DISABLE_X86 LIBYUV_DISABLE_SSE2 LIBYUV_DISABLE_SSSE3 @@ -22,19 +24,39 @@ By default the cpu is detected and the most advanced form of SIMD is used. But LIBYUV_DISABLE_F16C LIBYUV_DISABLE_AVX512BW LIBYUV_DISABLE_AVX512VL + LIBYUV_DISABLE_AVX512VNNI LIBYUV_DISABLE_AVX512VBMI LIBYUV_DISABLE_AVX512VBMI2 LIBYUV_DISABLE_AVX512VBITALG - LIBYUV_DISABLE_AVX512VPOPCNTDQ - LIBYUV_DISABLE_GFNI + LIBYUV_DISABLE_AVX10 + LIBYUV_DISABLE_AVX10_2 + LIBYUV_DISABLE_AVXVNNI + LIBYUV_DISABLE_AVXVNNIINT8 + LIBYUV_DISABLE_AMXINT8 + LIBYUV_DISABLE_AVX512BMM + LIBYUV_DISABLE_AMXTF32 -## ARM CPUs +## Arm CPUs LIBYUV_DISABLE_NEON + LIBYUV_DISABLE_NEON_DOTPROD + LIBYUV_DISABLE_NEON_I8MM + LIBYUV_DISABLE_SVE + LIBYUV_DISABLE_SVE2 + LIBYUV_DISABLE_SME -## MIPS CPUs - LIBYUV_DISABLE_MSA - LIBYUV_DISABLE_MMI +## LOONGARCH CPUs + + LIBYUV_DISABLE_LSX + LIBYUV_DISABLE_LASX + +## RISCV CPUs + + LIBYUV_DISABLE_RVV + +## Hexagon CPUs + + LIBYUV_DISABLE_HVX # Test Width/Height/Repeat diff --git a/libs/libyuv/docs/feature_detection.md b/libs/libyuv/docs/feature_detection.md new file mode 100644 index 0000000000..d32e84bfed --- /dev/null +++ b/libs/libyuv/docs/feature_detection.md @@ -0,0 +1,108 @@ +# Introduction + +Several routines in libyuv have multiple implementations specialized for a +variety of CPU architecture extensions. Libyuv will automatically detect and +use the latest architecture extension present on a machine for which a kernel +implementation is available. + +# Feature detection on AArch64 + +## Architecture extensions of interest + +The Arm 64-bit A-class architecture has a number of vector extensions which can +be used to accelerate libyuv kernels. + +### Neon extensions + +Neon is available and mandatory in AArch64 from the base Armv8.0-A +architecture. Neon can be used even if later extensions like the Scalable +Vector Extension (SVE) are also present. The exception to this is if the CPU is +currently operating in streaming mode as introduced by the Scalable Matrix +Extension, described later. + +There are also a couple of architecture extensions present for Neon that we can +take advantage of in libyuv: + +* The Neon DotProd extension is architecturally available from Armv8.1-A and + becomes mandatory from Armv8.4-A. This extension provides instructions to + perform a pairwise widening multiply of groups of four bytes from two source + vectors, taking the sum of the four widened multiply results within each + group to give a 32-bit result, accumulating into a destination vector. + +* The Neon I8MM extension extends the DotProd extension with support for + mixed-sign DotProds. The I8MM extension is architecturally available from + Armv8.1-A and becomes mandatory from Armv8.6-A. It does not strictly depend + on the DotProd extension being implemented, however at time of writing there + is no known micro-architecture implementation where I8MM is implemented + without the DotProd extension also being implemented. + +### The Scalable Vector Extension (SVE) + +The two Scalable Vector extensions (SVE and SVE2) provides equivalent +functionality to most existing Neon instructions but with the ability to +efficiently operate on vector registers with a run-time-determined vector +length. + +The original version of SVE is architecturally available from Armv8.2-A and is +primarily targeted at HPC applications. This focus means it does not include +most of the DSP-style operations that are necessary for most libyuv +color-conversion kernels, though it can still be used for many scaling or +rotation kernels. + +SVE does not strictly depend on either of the Neon DotProd or I8MM extensions +being implemented. The only micro-architecture at time of writing where SVE is +implemented without these two extensions both also being implemented is the +Fujitsu A64FX, which is not a CPU of interest for libyuv. + +SVE2 extends the base SVE extension with the remaining instructions from Neon, +porting these instructions to operate on scalable vectors. SVE2 is +architecturally available from Armv9.0-A. If SVE2 is implemented then SVE must +also be implemented. Since Armv9.0-A is based on Armv8.5-A this implies that +the Neon DotProd extension is also implemented. Interestingly this means that +the I8MM extension is not mandatory since it only becomes mandatory from +Armv8.6-A or Armv9.1-A, however there is no micro-architecture at time of +writing where SVE2 is implemented without all previously-mentioned features +also being implemented. + +### The Scalable Matrix Extension (SME) + +The Scalable Matrix Extension (SME) is an optional feature introduced from +Armv9.2-A. SME exists alongside SVE and introduces new execution modes for +applications performing extended periods of data processing. In particular SME +introduces a few new components of interest: + +* Access to a scalable two-dimensional ZA tile register and new instructions to + interact with rows and columns of the ZA tiles. This can be useful for data + transformations like transposes. + +* A streaming SVE (SSVE) mode, during which the SVE vector length matches the + ZA tile register width. In typical systems where the ZA tile register width + is longer than the core SVE vector length, SSVE processing allows for faster + data processing, even if the ZA tile register is unused. While the CPU is + executing in streaming mode, Neon instructions are unavailable. + +* When both SSVE and the ZA tile registers are enabled there are additional + outer-product instructions accumulating into a whole ZA tile, suitable for + accelerating matrix arithmetic. This is likely less useful in libyuv. + +## Linux and Android + +On AArch64 running under Linux and Android, features are detected by inspecting +the CPU auxiliary vector via `getauxval(AT_HWCAP)` and `getauxval(AT_HWCAP2)`, +inspecting the returned bitmask. + +## Windows + +On Windows we detect features using the `IsProcessorFeaturePresent` interface +and passing an enum parameter for the feature we want to check. More +information on this can be found here: + + https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent#parameters + +## Apple Silicon + +On Apple Silicon we detect features using the `sysctlbyname` interface and +passing a string representing the feature we want to detect. More information +on this can be found here: + + https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics diff --git a/libs/libyuv/docs/formats.md b/libs/libyuv/docs/formats.md index 97e8ce05f4..b0a81a94bd 100644 --- a/libs/libyuv/docs/formats.md +++ b/libs/libyuv/docs/formats.md @@ -4,7 +4,9 @@ Formats (FOURCC) supported by libyuv are detailed here. # Core Formats -There are 2 core formats supported by libyuv - I420 and ARGB. All YUV formats can be converted to/from I420. All RGB formats can be converted to/from ARGB. +There are 2 core formats supported by libyuv - I420 and ARGB. + All YUV formats can be converted to/from I420. + All RGB formats can be converted to/from ARGB. Filtering functions such as scaling and planar functions work on I420 and/or ARGB. @@ -36,26 +38,34 @@ This is how OSX formats map to libyuv The following is extracted from video_common.h as a complete list of formats supported by libyuv. enum FourCC { - // 9 Primary YUV formats: 5 planar, 2 biplanar, 2 packed. + // 15 Primary YUV formats: 6 planar, 7 biplanar, 2 packed. FOURCC_I420 = FOURCC('I', '4', '2', '0'), FOURCC_I422 = FOURCC('I', '4', '2', '2'), FOURCC_I444 = FOURCC('I', '4', '4', '4'), FOURCC_I400 = FOURCC('I', '4', '0', '0'), FOURCC_NV21 = FOURCC('N', 'V', '2', '1'), FOURCC_NV12 = FOURCC('N', 'V', '1', '2'), + FOURCC_NV16 = FOURCC('N', 'V', '1', '6'), + FOURCC_NV24 = FOURCC('N', 'V', '2', '4'), + FOURCC_P010 = FOURCC('P', '0', '1', '0'), + FOURCC_P210 = FOURCC('P', '2', '1', '0'), + FOURCC_P410 = FOURCC('P', '4', '1', '0'), FOURCC_YUY2 = FOURCC('Y', 'U', 'Y', '2'), FOURCC_UYVY = FOURCC('U', 'Y', 'V', 'Y'), - FOURCC_H010 = FOURCC('H', '0', '1', '0'), // unofficial fourcc. 10 bit lsb + FOURCC_I010 = FOURCC('I', '0', '1', '0'), // bt.601 10 bit 420 + FOURCC_I210 = FOURCC('I', '2', '1', '0'), // bt.601 10 bit 422 // 1 Secondary YUV format: row biplanar. - FOURCC_M420 = FOURCC('M', '4', '2', '0'), + FOURCC_M420 = FOURCC('M', '4', '2', '0'), // deprecated. - // 11 Primary RGB formats: 4 32 bpp, 2 24 bpp, 3 16 bpp, 1 10 bpc + // 13 Primary RGB formats: 4 32 bpp, 2 24 bpp, 3 16 bpp, 1 10 bpc, 2 64 bpp FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B'), FOURCC_BGRA = FOURCC('B', 'G', 'R', 'A'), FOURCC_ABGR = FOURCC('A', 'B', 'G', 'R'), FOURCC_AR30 = FOURCC('A', 'R', '3', '0'), // 10 bit per channel. 2101010. FOURCC_AB30 = FOURCC('A', 'B', '3', '0'), // ABGR version of 10 bit + FOURCC_AR64 = FOURCC('A', 'R', '6', '4'), // 16 bit per channel. + FOURCC_AB64 = FOURCC('A', 'B', '6', '4'), // ABGR version of 16 bit FOURCC_24BG = FOURCC('2', '4', 'B', 'G'), FOURCC_RAW = FOURCC('r', 'a', 'w', ' '), FOURCC_RGBA = FOURCC('R', 'G', 'B', 'A'), @@ -66,15 +76,34 @@ The following is extracted from video_common.h as a complete list of formats sup // 1 Primary Compressed YUV format. FOURCC_MJPG = FOURCC('M', 'J', 'P', 'G'), - // 8 Auxiliary YUV variations: 3 with U and V planes are swapped, 1 Alias. + // 23 Auxiliary YUV variations: 3 with U and V planes are swapped, 1 Alias. FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'), FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'), FOURCC_YV24 = FOURCC('Y', 'V', '2', '4'), FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'), // Linux version of I420. - FOURCC_J420 = FOURCC('J', '4', '2', '0'), - FOURCC_J400 = FOURCC('J', '4', '0', '0'), // unofficial fourcc - FOURCC_H420 = FOURCC('H', '4', '2', '0'), // unofficial fourcc - FOURCC_H422 = FOURCC('H', '4', '2', '2'), // unofficial fourcc + FOURCC_J420 = + FOURCC('J', '4', '2', '0'), // jpeg (bt.601 full), unofficial fourcc + FOURCC_J422 = + FOURCC('J', '4', '2', '2'), // jpeg (bt.601 full), unofficial fourcc + FOURCC_J444 = + FOURCC('J', '4', '4', '4'), // jpeg (bt.601 full), unofficial fourcc + FOURCC_J400 = + FOURCC('J', '4', '0', '0'), // jpeg (bt.601 full), unofficial fourcc + FOURCC_F420 = FOURCC('F', '4', '2', '0'), // bt.709 full, unofficial fourcc + FOURCC_F422 = FOURCC('F', '4', '2', '2'), // bt.709 full, unofficial fourcc + FOURCC_F444 = FOURCC('F', '4', '4', '4'), // bt.709 full, unofficial fourcc + FOURCC_H420 = FOURCC('H', '4', '2', '0'), // bt.709, unofficial fourcc + FOURCC_H422 = FOURCC('H', '4', '2', '2'), // bt.709, unofficial fourcc + FOURCC_H444 = FOURCC('H', '4', '4', '4'), // bt.709, unofficial fourcc + FOURCC_U420 = FOURCC('U', '4', '2', '0'), // bt.2020, unofficial fourcc + FOURCC_U422 = FOURCC('U', '4', '2', '2'), // bt.2020, unofficial fourcc + FOURCC_U444 = FOURCC('U', '4', '4', '4'), // bt.2020, unofficial fourcc + FOURCC_F010 = FOURCC('F', '0', '1', '0'), // bt.709 full range 10 bit 420 + FOURCC_H010 = FOURCC('H', '0', '1', '0'), // bt.709 10 bit 420 + FOURCC_U010 = FOURCC('U', '0', '1', '0'), // bt.2020 10 bit 420 + FOURCC_F210 = FOURCC('F', '2', '1', '0'), // bt.709 full range 10 bit 422 + FOURCC_H210 = FOURCC('H', '2', '1', '0'), // bt.709 10 bit 422 + FOURCC_U210 = FOURCC('U', '2', '1', '0'), // bt.2020 10 bit 422 // 14 Auxiliary aliases. CanonicalFourCC() maps these to canonical fourcc. FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'), // Alias for I420. @@ -97,13 +126,35 @@ The following is extracted from video_common.h as a complete list of formats sup # Planar YUV The following formats contains a full size Y plane followed by 1 or 2 - planes for UV: I420, I422, I444, I400, NV21, NV12, I400 + planes for UV: I420, I422, I444, I400, NV21, NV12, NV16, NV24, + P010, P210, P410 The size (subsampling) of the UV varies. - I420, NV12 and NV21 are half width, half height - I422, NV16 and NV61 are half width, full height - I444, NV24 and NV42 are full width, full height + I420, NV12, NV21 and P010 are half width, half height + I422, NV16, NV61 and P210 are half width, full height + I444, NV24, NV42 and P410 are full width, full height I400 and J400 have no chroma channel. +# Color space + The YUV formats start with a letter to specify the color space. e.g. I420 + I = BT.601 limited range + J = BT.601 full range (J = JPEG that uses this) + H = BT.709 limited range (H for HD) + F = BT.709 full range (F for Full range) + U = BT.2020 limited range (U for UHD) + V = BT.2020 full range + For YUV to RGB conversions, a matrix can be passed. See also convert_argh.h + +# HDR formats + Planar formats with 10 or 12 bits use the following fourcc: + I010, I012, P010, P012 are half width, half height + I210, I212, P210, P212 are half width, full height + I410, I412, P410, P412 are full width, full height + where + I is the color space (see above) and 3 planes: Y, U and V. + P is a biplanar format, similar to NV12 but 16 bits, with the valid bits in the high bits. There is a Y plane and a UV plane. + 0, 2 or 4 is the last digit of subsampling: 4:2:0, 4:2:2, or 4:4:4 + 10 or 12 is the bits per channel. The bits are in the low bits of a 16 bit channel. + # The ARGB FOURCC There are 4 ARGB layouts - ARGB, BGRA, ABGR and RGBA. ARGB is most common by far, used for screen formats, and windows webcam drivers. @@ -114,13 +165,13 @@ A fourcc provided by capturer, can be thought of string, e.g. "ARGB". On little endian machines, as an int, this would have 'A' in the lowest byte. The FOURCC macro reverses the order: - #define FOURCC(a, b, c, d) (((uint32)(a)) | ((uint32)(b) << 8) | ((uint32)(c) << 16) | ((uint32)(d) << 24)) + #define FOURCC(a, b, c, d) (((uint32_t)(a)) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) -So the "ARGB" string, read as an uint32, is +So the "ARGB" string, read as an uint32_t, is FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B') -If you were to read ARGB pixels as uint32's, the alpha would be in the high byte, and the blue in the lowest byte. In memory, these are stored little endian, so 'B' is first, then 'G', 'R' and 'A' last. +If you were to read ARGB pixels as uint32_t's, the alpha would be in the high byte, and the blue in the lowest byte. In memory, these are stored little endian, so 'B' is first, then 'G', 'R' and 'A' last. When calling conversion functions, the names match the FOURCC, so in this case it would be I420ToARGB(). @@ -152,6 +203,13 @@ The 2 bit alpha has 4 values. Here are the comparable 8 bit alpha values. The 10 bit RGB values range from 0 to 1023. XR30 is the same as AR30 but with no alpha channel. +# AB64 and AR64 + +AB64 is similar to ABGR, with 16 bit (2 bytes) per channel. Each channel stores an unsigned short. +In memory R is the lowest and A is the highest. +Each channel has value ranges from 0 to 65535. +AR64 is similar to ARGB. + # NV12 and NV21 NV12 is a biplanar format with a full sized Y plane followed by a single @@ -161,3 +219,11 @@ The 12 in NV12 refers to 12 bits per pixel. NV12 has a half width and half height chroma channel, and therefore is a 420 subsampling. NV16 is 16 bits per pixel, with half width and full height. aka 422. NV24 is 24 bits per pixel with full sized chroma channel. aka 444. +Most NV12 functions allow the destination Y pointer to be NULL. + +# YUY2 and UYVY + +YUY2 is a packed YUV format with half width, full height. + +YUY2 is YUYV in memory +UYVY is UYVY in memory diff --git a/libs/libyuv/docs/getting_started.md b/libs/libyuv/docs/getting_started.md index 4426b606e0..d9807ae40e 100644 --- a/libs/libyuv/docs/getting_started.md +++ b/libs/libyuv/docs/getting_started.md @@ -11,21 +11,7 @@ Refer to chromium instructions for each platform for other prerequisites. Create a working directory, enter it, and run: - gclient config --name src https://chromium.googlesource.com/libyuv/libyuv - gclient sync - -Then you'll get a .gclient file like: - - solutions = [ - { "name" : "src", - "url" : "https://chromium.googlesource.com/libyuv/libyuv", - "deps_file" : "DEPS", - "managed" : True, - "custom_deps" : { - }, - "safesync_url": "", - }, - ]; + fetch libyuv For iOS add `;target_os=['ios'];` to your OSX .gclient and run `gclient sync.` @@ -57,15 +43,47 @@ To get just the source (not buildable): ## Building the Library and Unittests +### Bazel + +Libyuv can be built using [Bazel](https://bazel.build/). + +#### Android Prerequisites +To build for Android using Bazel, you must have the Android SDK and NDK installed. Bazel will look for the following environment variables to locate them: +* `ANDROID_HOME`: Set this to the path of your Android SDK. +* `ANDROID_NDK_HOME`: Set this to the path of your Android NDK. + +Ensure these variables are set before running the Bazel Android build commands. + +**Android arm64:** + + bazel build -c opt --config=android_arm64 //:libyuv_test + + # Or, specifying standard open-source flags (if NDK is set up in workspace): + bazel build -c opt --cpu=arm64-v8a --crosstool_top=//external:android/crosstool //:libyuv_test + +**Linux x86_64:** + + bazel build -c opt //:libyuv_test + + # Or, specifying a specific CPU architecture: + bazel build -c opt --cpu=haswell //:libyuv_test + +Additional commonly used compiler options can be passed to Bazel via `--copt`: + + bazel build -c opt --config=android_arm64 \ + --copt=-DLIBYUV_UNLIMITED_DATA \ + --copt=-DENABLE_ROW_TESTS \ + //:libyuv_test + ### Windows - call gn gen out\Release "--args=is_debug=false target_cpu=\"x64\"" - call gn gen out\Debug "--args=is_debug=true target_cpu=\"x64\"" + gn gen out\Release "--args=is_debug=false target_cpu=\"x64\"" + gn gen out\Debug "--args=is_debug=true target_cpu=\"x64\"" ninja -v -C out\Release ninja -v -C out\Debug - call gn gen out\Release "--args=is_debug=false target_cpu=\"x86\"" - call gn gen out\Debug "--args=is_debug=true target_cpu=\"x86\"" + gn gen out\Release "--args=is_debug=false target_cpu=\"x86\"" + gn gen out\Debug "--args=is_debug=true target_cpu=\"x86\"" ninja -v -C out\Release ninja -v -C out\Debug @@ -130,20 +148,13 @@ ia32 ninja -v -C out/Debug libyuv_unittest ninja -v -C out/Release libyuv_unittest -mips - - gn gen out/Release "--args=is_debug=false target_os=\"android\" target_cpu=\"mips64el\" mips_arch_variant=\"r6\" mips_use_msa=true is_component_build=true" - gn gen out/Debug "--args=is_debug=true target_os=\"android\" target_cpu=\"mips64el\" mips_arch_variant=\"r6\" mips_use_msa=true is_component_build=true" - ninja -v -C out/Debug libyuv_unittest - ninja -v -C out/Release libyuv_unittest - arm disassembly: - third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-objdump -d ./out/Release/obj/libyuv/row_common.o >row_common.txt + llvm-objdump -d ./out/Release/obj/libyuv/row_common.o >row_common.txt - third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-objdump -d ./out/Release/obj/libyuv_neon/row_neon.o >row_neon.txt + llvm-objdump -d ./out/Release/obj/libyuv_neon/row_neon.o >row_neon.txt - third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-objdump -d ./out/Release/obj/libyuv_neon/row_neon64.o >row_neon64.txt + llvm-objdump -d ./out/Release/obj/libyuv_neon/row_neon64.o >row_neon64.txt Caveat: Disassembly may require optimize_max be disabled in BUILD.gn @@ -165,6 +176,7 @@ Running test with C code: ninja -C out/Debug libyuv_unittest ninja -C out/Debug compare ninja -C out/Debug yuvconvert + ninja -C out/Debug yuvconstants ninja -C out/Debug psnr ninja -C out/Debug cpuid @@ -175,22 +187,13 @@ Running test with C code: ninja -v -C out/Debug libyuv_unittest ninja -v -C out/Release libyuv_unittest -### MIPS Linux - -mips - - gn gen out/Release "--args=is_debug=false target_os=\"linux\" target_cpu=\"mips64el\" mips_arch_variant=\"loongson3\" mips_use_mmi=true is_component_build=false use_sysroot=false use_gold=false" - gn gen out/Debug "--args=is_debug=true target_os=\"linux\" target_cpu=\"mips64el\" mips_arch_variant=\"loongson3\" mips_use_mmi=true is_component_build=false use_sysroot=false use_gold=false" - ninja -v -C out/Debug libyuv_unittest - ninja -v -C out/Release libyuv_unittest - ## Building the Library with make ### Linux make V=1 -f linux.mk make V=1 -f linux.mk clean - make V=1 -f linux.mk CXX=clang++ + make V=1 -f linux.mk CXX=clang++ CC=clang ## Building the library with cmake @@ -219,6 +222,88 @@ Install cmake: http://www.cmake.org/ make -j4 make package +## Building RISC-V target with cmake + +### Native build on RISC-V SBC (e.g. SpacemiT K1/K3) + +On a 64-bit RISC-V system, CMake automatically detects `riscv64` and enables +RVV with `-march=rv64gcv`: + + cmake -B out/Release -DCMAKE_BUILD_TYPE=Release -DUNIT_TEST=ON + cmake --build out/Release + +To build for 32-bit RISC-V targets: + + cmake -B out/Release -DCMAKE_BUILD_TYPE=Release -DRISCV_COMPILER_FLAGS="-march=rv32gcv" + cmake --build out/Release + +#### Customized Compiler Flags + +Customized compiler flags can be passed with `-DRISCV_COMPILER_FLAGS="xxx"`. +When assigned, the specified flags are used instead of the default `-march=rv64gcv`: + +Targeting SiFive X280: + + cmake -B out/Release -DUNIT_TEST=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DRISCV_COMPILER_FLAGS="-mcpu=sifive-x280" + +Targeting Coral (32-bit without floating point, Zve32x): + + cmake -B out/Release -DUNIT_TEST=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DRISCV_COMPILER_FLAGS="-march=rv32imac_zve32x" + +To disable RVV: + + cmake -B out/Release -DCMAKE_BUILD_TYPE=Release -DUSE_RVV=OFF + +### Building RISC-V with Bazel and Blaze + +To build with Bazel for 64-bit or 32-bit RISC-V targets: + + bazel test --platforms=@platforms//cpu:riscv64 //... + bazel test --platforms=@platforms//cpu:riscv32 //... + +For custom targets such as SiFive X280 or Coral: + + bazel test --platforms=@platforms//cpu:riscv64 --copt=-mcpu=sifive-x280 //... + bazel test --platforms=@platforms//cpu:riscv32 --copt=-march=rv32imac_zve32x //... + +In google3 using Blaze: + + blaze test --config=mpu64 //third_party/libyuv:libyuv_test + blaze run --config=mpu64 //third_party/libyuv:cpuid + blaze run --config=mpu64 //third_party/libyuv:yuvconvert + +### Cross-compile for RISC-V target using QEMU + +#### Prerequisite: build risc-v clang toolchain and qemu + +If you don't have prebuilt clang and riscv64 qemu, run the script to download source and build them. + + ./riscv_script/prepare_toolchain_qemu.sh + +After running script, clang & qemu are built in `build-toolchain-qemu/riscv-clang/` & `build-toolchain-qemu/riscv-qemu/`. + +#### Cross-compile for RISC-V target + cmake -B out/Release/ -DUNIT_TEST=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE="./riscv_script/riscv-clang.cmake" \ + -DTOOLCHAIN_PATH={TOOLCHAIN_PATH} \ + -DUSE_RVV=ON . + cmake --build out/Release/ + +### Run on QEMU + +#### Run libyuv_unittest on QEMU + cd out/Release/ + USE_RVV=ON \ + TOOLCHAIN_PATH={TOOLCHAIN_PATH} \ + QEMU_PREFIX_PATH={QEMU_PREFIX_PATH} \ + ../../riscv_script/run_qemu.sh libyuv_unittest + + ## Setup for Arm Cross compile See also https://www.ccoderun.ca/programming/2015-12-20_CrossCompiling/index.html @@ -239,6 +324,20 @@ See also https://www.ccoderun.ca/programming/2015-12-20_CrossCompiling/index.htm ## Running Unittests +### Bazel + +You can run the tests using Bazel's `test` command. This will build and run the test in an isolated environment: + + bazel test -c opt //:libyuv_test + +To pass specific arguments to the test binary (like a gtest filter), use `--test_arg`: + + bazel test -c opt //:libyuv_test --test_arg=--gtest_filter="*" --test_output=all + +Alternatively, you can run the compiled binary directly from the `bazel-bin` directory: + + ./bazel-bin/libyuv_test --gtest_filter="*" + ### Windows out\Release\libyuv_unittest.exe --gtest_catch_exceptions=0 --gtest_filter="*" diff --git a/libs/libyuv/download_vs_toolchain.py b/libs/libyuv/download_vs_toolchain.py index 4b3457899f..9fc89affe5 100644 --- a/libs/libyuv/download_vs_toolchain.py +++ b/libs/libyuv/download_vs_toolchain.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python -# +#!/usr/bin/env vpython3 + # Copyright 2014 The LibYuv Project Authors. All rights reserved. # # Use of this source code is governed by a BSD-style license @@ -22,8 +22,8 @@ sys.path.insert(0, os.path.join(checkout_root, 'build')) sys.path.insert(0, os.path.join(checkout_root, 'tools', 'find_depot_tools')) -import vs_toolchain +import vs_toolchain # pylint: disable=wrong-import-position if __name__ == '__main__': - sys.exit(vs_toolchain.main()) + sys.exit(vs_toolchain.main()) diff --git a/libs/libyuv/include/libyuv.h b/libs/libyuv/include/libyuv.h index aeffd5ef7a..692742d261 100644 --- a/libs/libyuv/include/libyuv.h +++ b/libs/libyuv/include/libyuv.h @@ -25,7 +25,8 @@ #include "libyuv/row.h" #include "libyuv/scale.h" #include "libyuv/scale_argb.h" -#include "libyuv/scale_row.h" +#include "libyuv/scale_rgb.h" +#include "libyuv/scale_uv.h" #include "libyuv/version.h" #include "libyuv/video_common.h" diff --git a/libs/libyuv/include/libyuv/basic_types.h b/libs/libyuv/include/libyuv/basic_types.h index 1bea67f2f2..c015b493bc 100644 --- a/libs/libyuv/include/libyuv/basic_types.h +++ b/libs/libyuv/include/libyuv/basic_types.h @@ -11,37 +11,6 @@ #ifndef INCLUDE_LIBYUV_BASIC_TYPES_H_ #define INCLUDE_LIBYUV_BASIC_TYPES_H_ -#include // For size_t and NULL - -#if !defined(INT_TYPES_DEFINED) && !defined(GG_LONGLONG) -#define INT_TYPES_DEFINED - -#if defined(_MSC_VER) && (_MSC_VER < 1600) -#include // for uintptr_t on x86 -typedef unsigned __int64 uint64_t; -typedef __int64 int64_t; -typedef unsigned int uint32_t; -typedef int int32_t; -typedef unsigned short uint16_t; -typedef short int16_t; -typedef unsigned char uint8_t; -typedef signed char int8_t; -#else -#include // for uintptr_t and C99 types -#endif // defined(_MSC_VER) && (_MSC_VER < 1600) -// Types are deprecated. Enable this macro for legacy types. -#ifdef LIBYUV_LEGACY_TYPES -typedef uint64_t uint64; -typedef int64_t int64; -typedef uint32_t uint32; -typedef int32_t int32; -typedef uint16_t uint16; -typedef int16_t int16; -typedef uint8_t uint8; -typedef int8_t int8; -#endif // LIBYUV_LEGACY_TYPES -#endif // INT_TYPES_DEFINED - #if !defined(LIBYUV_API) #if defined(_WIN32) || defined(__CYGWIN__) #if defined(LIBYUV_BUILDING_SHARED_LIBRARY) @@ -60,9 +29,4 @@ typedef int8_t int8; #endif // __GNUC__ #endif // LIBYUV_API -// TODO(fbarchard): Remove bool macros. -#define LIBYUV_BOOL int -#define LIBYUV_FALSE 0 -#define LIBYUV_TRUE 1 - #endif // INCLUDE_LIBYUV_BASIC_TYPES_H_ diff --git a/libs/libyuv/include/libyuv/compare.h b/libs/libyuv/include/libyuv/compare.h index 3353ad71c6..a8196d792c 100644 --- a/libs/libyuv/include/libyuv/compare.h +++ b/libs/libyuv/include/libyuv/compare.h @@ -11,6 +11,9 @@ #ifndef INCLUDE_LIBYUV_COMPARE_H_ #define INCLUDE_LIBYUV_COMPARE_H_ +#include +#include + #include "libyuv/basic_types.h" #ifdef __cplusplus diff --git a/libs/libyuv/include/libyuv/compare_row.h b/libs/libyuv/include/libyuv/compare_row.h index e95b9d93eb..cb5cbc827b 100644 --- a/libs/libyuv/include/libyuv/compare_row.h +++ b/libs/libyuv/include/libyuv/compare_row.h @@ -11,82 +11,164 @@ #ifndef INCLUDE_LIBYUV_COMPARE_ROW_H_ #define INCLUDE_LIBYUV_COMPARE_ROW_H_ -#include "libyuv/basic_types.h" +#include +#include + +#include "libyuv/cpu_support.h" #ifdef __cplusplus namespace libyuv { extern "C" { #endif -#if defined(__pnacl__) || defined(__CLR_VER) || \ - (defined(__native_client__) && defined(__x86_64__)) || \ - (defined(__i386__) && !defined(__SSE__) && !defined(__clang__)) -#define LIBYUV_DISABLE_X86 -#endif -#if defined(__native_client__) -#define LIBYUV_DISABLE_NEON -#endif -// MemorySanitizer does not support assembly code yet. http://crbug.com/344505 -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) -#define LIBYUV_DISABLE_X86 -#endif -#endif -// Visual C 2012 required for AVX2. -#if defined(_M_IX86) && !defined(__clang__) && defined(_MSC_VER) && \ - _MSC_VER >= 1700 -#define VISUALC_HAS_AVX2 1 -#endif // VisualStudio >= 2012 - -// clang >= 3.4.0 required for AVX2. -#if defined(__clang__) && (defined(__x86_64__) || defined(__i386__)) -#if (__clang_major__ > 3) || (__clang_major__ == 3 && (__clang_minor__ >= 4)) -#define CLANG_HAS_AVX2 1 -#endif // clang >= 3.4 -#endif // __clang__ - -// The following are available for Visual C and GCC: -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(__x86_64__) || defined(__i386__) || defined(_M_IX86)) -#define HAS_HASHDJB2_SSE41 +// The following are available for Visual C 32/64 bit, and for clang with +// LIBYUV_ENABLE_ROWWIN, which is also enabled for MemorySanitizer. These are +// intrinsics in compare_win.cc. +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || \ + defined(_M_IX86)) && \ + ((defined(_MSC_VER) && !defined(__clang__)) || \ + defined(LIBYUV_ENABLE_ROWWIN)) +#define HAS_HAMMINGDISTANCE_SSE42 #define HAS_SUMSQUAREERROR_SSE2 +#define HAS_HASHDJB2_SSE41 +#define HAS_SSIM4X4ROW_SSE2 +#define HAS_SSIMWINDOWROW_SSE2 +#if defined(VISUALC_HAS_AVX2) +#define HAS_HAMMINGDISTANCE_AVX2 +#define HAS_SUMSQUAREERROR_AVX2 +#define HAS_HASHDJB2_AVX2 +#define HAS_SSIM4X4ROW_AVX2 +#define HAS_SSIMWINDOWROW_AVX2 +#define HAS_ARGBDETECTROW_AVX2 +#endif +#if defined(VISUALC_HAS_AVX512) +#define HAS_HAMMINGDISTANCE_AVX512BW +#define HAS_HAMMINGDISTANCE_AVX512VNNI +#define HAS_SUMSQUAREERROR_AVX512BW +#define HAS_SUMSQUAREERROR_AVX512VNNI +#define HAS_HASHDJB2_AVX512BW +#define HAS_SSIM4X4ROW_AVX512BW +#define HAS_SSIMWINDOWROW_AVX512BW +#endif +#endif + +// The following are available for 32/64 bit GCC and clang, as inline assembly +// in compare_gcc.cc: +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__)) && \ + !defined(LIBYUV_ENABLE_ROWWIN) && \ + (!defined(_MSC_VER) || defined(__clang__)) +#if defined(__x86_64__) #define HAS_HAMMINGDISTANCE_SSE42 #endif - -// The following are available for Visual C and clangcl 32 bit: -#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) && \ - (defined(VISUALC_HAS_AVX2) || defined(CLANG_HAS_AVX2)) -#define HAS_HASHDJB2_AVX2 -#define HAS_SUMSQUAREERROR_AVX2 -#endif - -// The following are available for GCC and clangcl 64 bit: -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) #define HAS_HAMMINGDISTANCE_SSSE3 -#endif - -// The following are available for GCC and clangcl 64 bit: -#if !defined(LIBYUV_DISABLE_X86) && defined(CLANG_HAS_AVX2) && \ - (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) +#define HAS_SUMSQUAREERROR_SSE2 +#define HAS_HASHDJB2_SSE41 +#define HAS_SSIM4X4ROW_SSE2 +#define HAS_SSIMWINDOWROW_SSE2 +#if defined(CLANG_HAS_AVX2) || defined(GCC_HAS_AVX2) #define HAS_HAMMINGDISTANCE_AVX2 +#define HAS_SUMSQUAREERROR_AVX2 +#define HAS_HASHDJB2_AVX2 +#define HAS_SSIM4X4ROW_AVX2 +#define HAS_SSIMWINDOWROW_AVX2 +#define HAS_ARGBDETECTROW_AVX2 +#endif +#if defined(__x86_64__) && \ + (defined(CLANG_HAS_AVX512) || defined(GCC_HAS_AVX512)) +#define HAS_HAMMINGDISTANCE_AVX512BW +#define HAS_HAMMINGDISTANCE_AVX512VNNI +#define HAS_SUMSQUAREERROR_AVX512BW +#define HAS_SUMSQUAREERROR_AVX512VNNI +#define HAS_HASHDJB2_AVX512BW +#define HAS_SSIM4X4ROW_AVX512BW +#define HAS_SSIMWINDOWROW_AVX512BW +#endif #endif // The following are available for Neon: #if !defined(LIBYUV_DISABLE_NEON) && \ (defined(__ARM_NEON__) || defined(LIBYUV_NEON) || defined(__aarch64__)) -#define HAS_SUMSQUAREERROR_NEON #define HAS_HAMMINGDISTANCE_NEON +#define HAS_SUMSQUAREERROR_NEON +#define HAS_HASHDJB2_NEON +#define HAS_SSIM4X4ROW_NEON +#define HAS_SSIMWINDOWROW_NEON +#define HAS_ARGBDETECTROW_NEON #endif -#if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) -#define HAS_HAMMINGDISTANCE_MSA -#define HAS_SUMSQUAREERROR_MSA +// The following are available for AArch64 Neon: +#if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) +#define HAS_HAMMINGDISTANCE_NEON_DOTPROD +#define HAS_SUMSQUAREERROR_NEON_DOTPROD +#define HAS_SSIM4X4ROW_NEON_DOTPROD #endif -#if !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) -#define HAS_HAMMINGDISTANCE_MMI -#define HAS_SUMSQUAREERROR_MMI +// The following are available for AArch64 SVE: +#if !defined(LIBYUV_DISABLE_SVE) && defined(__aarch64__) +#define HAS_SSIM4X4ROW_SVE2 +#define HAS_SSIMWINDOWROW_SVE2 +#endif + +// The following are available for AArch64 SME: +#if !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && \ + defined(__aarch64__) +#define HAS_SSIM4X4ROW_SME +#define HAS_SSIMWINDOWROW_SME +#endif + +// The following are available for RISC-V Vector (RVV): +#if !defined(LIBYUV_DISABLE_RVV) && \ + (defined(__riscv_vector) || defined(LIBYUV_RVV)) +#define HAS_HAMMINGDISTANCE_RVV +#define HAS_SUMSQUAREERROR_RVV +#define HAS_HASHDJB2_RVV +#define HAS_SSIM4X4ROW_RVV +#if defined(__riscv_f) || defined(__riscv_zve32f) +#define HAS_SSIMWINDOWROW_RVV +#endif +#define HAS_ARGBDETECTROW_RVV +#endif + +// The following are available for LoongArch LSX: +#if !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx) +#define HAS_HAMMINGDISTANCE_LSX +#define HAS_SUMSQUAREERROR_LSX +#define HAS_HASHDJB2_LSX +#define HAS_SSIM4X4ROW_LSX +#define HAS_SSIMWINDOWROW_LSX +#define HAS_ARGBDETECTROW_LSX +#endif + +// The following are available for LoongArch LASX: +#if !defined(LIBYUV_DISABLE_LASX) && defined(__loongarch_asx) +#define HAS_HAMMINGDISTANCE_LASX +#define HAS_SUMSQUAREERROR_LASX +#define HAS_HASHDJB2_LASX +#define HAS_SSIM4X4ROW_LASX +#define HAS_SSIMWINDOWROW_LASX +#define HAS_ARGBDETECTROW_LASX +#endif + +// The following are available for WebAssembly SIMD128: +#if !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) +#define HAS_HAMMINGDISTANCE_WASMSIMD +#define HAS_SUMSQUAREERROR_WASMSIMD +#define HAS_HASHDJB2_WASMSIMD +#define HAS_SSIM4X4ROW_WASMSIMD +#define HAS_SSIMWINDOWROW_WASMSIMD +#define HAS_ARGBDETECTROW_WASMSIMD +#endif + +// The following are available for Hexagon HVX: +#if !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) +#define HAS_HAMMINGDISTANCE_HVX +#define HAS_SUMSQUAREERROR_HVX +#define HAS_HASHDJB2_HVX +#define HAS_SSIM4X4ROW_HVX +#define HAS_SSIMWINDOWROW_HVX +#define HAS_ARGBDETECTROW_HVX #endif uint32_t HammingDistance_C(const uint8_t* src_a, @@ -101,13 +183,31 @@ uint32_t HammingDistance_SSSE3(const uint8_t* src_a, uint32_t HammingDistance_AVX2(const uint8_t* src_a, const uint8_t* src_b, int count); +uint32_t HammingDistance_AVX512BW(const uint8_t* src_a, + const uint8_t* src_b, + int count); +uint32_t HammingDistance_AVX512VNNI(const uint8_t* src_a, + const uint8_t* src_b, + int count); uint32_t HammingDistance_NEON(const uint8_t* src_a, const uint8_t* src_b, int count); -uint32_t HammingDistance_MSA(const uint8_t* src_a, +uint32_t HammingDistance_NEON_DotProd(const uint8_t* src_a, + const uint8_t* src_b, + int count); +uint32_t HammingDistance_RVV(const uint8_t* src_a, const uint8_t* src_b, int count); -uint32_t HammingDistance_MMI(const uint8_t* src_a, +uint32_t HammingDistance_LSX(const uint8_t* src_a, + const uint8_t* src_b, + int count); +uint32_t HammingDistance_LASX(const uint8_t* src_a, + const uint8_t* src_b, + int count); +uint32_t HammingDistance_WASMSIMD(const uint8_t* src_a, + const uint8_t* src_b, + int count); +uint32_t HammingDistance_HVX(const uint8_t* src_a, const uint8_t* src_b, int count); uint32_t SumSquareError_C(const uint8_t* src_a, @@ -119,19 +219,168 @@ uint32_t SumSquareError_SSE2(const uint8_t* src_a, uint32_t SumSquareError_AVX2(const uint8_t* src_a, const uint8_t* src_b, int count); +uint32_t SumSquareError_AVX512BW(const uint8_t* src_a, + const uint8_t* src_b, + int count); +uint32_t SumSquareError_AVX512VNNI(const uint8_t* src_a, + const uint8_t* src_b, + int count); uint32_t SumSquareError_NEON(const uint8_t* src_a, const uint8_t* src_b, int count); -uint32_t SumSquareError_MSA(const uint8_t* src_a, +uint32_t SumSquareError_NEON_DotProd(const uint8_t* src_a, + const uint8_t* src_b, + int count); +uint32_t SumSquareError_RVV(const uint8_t* src_a, const uint8_t* src_b, int count); -uint32_t SumSquareError_MMI(const uint8_t* src_a, +uint32_t SumSquareError_LSX(const uint8_t* src_a, + const uint8_t* src_b, + int count); +uint32_t SumSquareError_LASX(const uint8_t* src_a, + const uint8_t* src_b, + int count); +uint32_t SumSquareError_WASMSIMD(const uint8_t* src_a, + const uint8_t* src_b, + int count); +uint32_t SumSquareError_HVX(const uint8_t* src_a, const uint8_t* src_b, int count); uint32_t HashDjb2_C(const uint8_t* src, int count, uint32_t seed); uint32_t HashDjb2_SSE41(const uint8_t* src, int count, uint32_t seed); uint32_t HashDjb2_AVX2(const uint8_t* src, int count, uint32_t seed); +uint32_t HashDjb2_AVX512BW(const uint8_t* src, int count, uint32_t seed); +uint32_t HashDjb2_NEON(const uint8_t* src, int count, uint32_t seed); +uint32_t HashDjb2_RVV(const uint8_t* src, int count, uint32_t seed); +uint32_t HashDjb2_LSX(const uint8_t* src, int count, uint32_t seed); +uint32_t HashDjb2_LASX(const uint8_t* src, int count, uint32_t seed); +uint32_t HashDjb2_WASMSIMD(const uint8_t* src, int count, uint32_t seed); +uint32_t HashDjb2_HVX(const uint8_t* src, int count, uint32_t seed); + +void Ssim4x4Row_C(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_SSE2(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_AVX2(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_AVX512BW(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_NEON(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_NEON_DotProd(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_SVE2(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_SME(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_RVV(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_LSX(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_LASX(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_WASMSIMD(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +void Ssim4x4Row_HVX(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width); +float SsimWindowRow_C(const uint32_t* row0, + const uint32_t* row1, + int num_windows); +float SsimWindowRow_SSE2(const uint32_t* row0, + const uint32_t* row1, + int num_windows); +float SsimWindowRow_AVX2(const uint32_t* row0, + const uint32_t* row1, + int num_windows); +float SsimWindowRow_AVX512BW(const uint32_t* row0, + const uint32_t* row1, + int num_windows); +float SsimWindowRow_NEON(const uint32_t* row0, + const uint32_t* row1, + int num_windows); +float SsimWindowRow_SVE2(const uint32_t* row0, + const uint32_t* row1, + int num_windows); +float SsimWindowRow_SME(const uint32_t* row0, + const uint32_t* row1, + int num_windows); +float SsimWindowRow_RVV(const uint32_t* row0, + const uint32_t* row1, + int num_windows); +float SsimWindowRow_LSX(const uint32_t* row0, + const uint32_t* row1, + int num_windows); +float SsimWindowRow_LASX(const uint32_t* row0, + const uint32_t* row1, + int num_windows); +float SsimWindowRow_WASMSIMD(const uint32_t* row0, + const uint32_t* row1, + int num_windows); +float SsimWindowRow_HVX(const uint32_t* row0, + const uint32_t* row1, + int num_windows); + +uint32_t ARGBDetectRow_C(const uint8_t* argb, int width); +uint32_t ARGBDetectRow_AVX2(const uint8_t* argb, int width); +uint32_t ARGBDetectRow_NEON(const uint8_t* argb, int width); +uint32_t ARGBDetectRow_RVV(const uint8_t* argb, int width); +uint32_t ARGBDetectRow_LSX(const uint8_t* argb, int width); +uint32_t ARGBDetectRow_LASX(const uint8_t* argb, int width); +uint32_t ARGBDetectRow_WASMSIMD(const uint8_t* argb, int width); +uint32_t ARGBDetectRow_HVX(const uint8_t* argb, int width); #ifdef __cplusplus } // extern "C" diff --git a/libs/libyuv/include/libyuv/convert.h b/libs/libyuv/include/libyuv/convert.h index f571142fab..fdaec5eaf5 100644 --- a/libs/libyuv/include/libyuv/convert.h +++ b/libs/libyuv/include/libyuv/convert.h @@ -11,6 +11,9 @@ #ifndef INCLUDE_LIBYUV_CONVERT_H_ #define INCLUDE_LIBYUV_CONVERT_H_ +#include +#include + #include "libyuv/basic_types.h" #include "libyuv/rotate.h" // For enum RotationMode. @@ -25,6 +28,8 @@ namespace libyuv { extern "C" { #endif +struct ArgbConstants; + // Convert I444 to I420. LIBYUV_API int I444ToI420(const uint8_t* src_y, @@ -42,6 +47,21 @@ int I444ToI420(const uint8_t* src_y, int width, int height); +// Convert I444 to NV12. +LIBYUV_API +int I444ToNV12(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + // Convert I444 to NV21. LIBYUV_API int I444ToNV21(const uint8_t* src_y, @@ -74,6 +94,95 @@ int I422ToI420(const uint8_t* src_y, int width, int height); +// Convert I422 to I444. +LIBYUV_API +int I422ToI444(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert I422 to I210. +LIBYUV_API +int I422ToI210(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert MM21 to NV12. +LIBYUV_API +int MM21ToNV12(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert MM21 to I420. +LIBYUV_API +int MM21ToI420(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert MM21 to YUY2 +LIBYUV_API +int MM21ToYUY2(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_yuy2, + int dst_stride_yuy2, + int width, + int height); + +// Convert MT2T to P010 +// Note that src_y and src_uv point to packed 10-bit values, so the Y plane will +// be 10 / 8 times the dimensions of the image. Also for this reason, +// src_stride_y and src_stride_uv are given in bytes. +LIBYUV_API +int MT2TToP010(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + // Convert I422 to NV21. LIBYUV_API int I422ToNV21(const uint8_t* src_y, @@ -107,6 +216,23 @@ int I420Copy(const uint8_t* src_y, int width, int height); +// Convert I420 to I444. +LIBYUV_API +int I420ToI444(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + // Copy I010 to I010 #define I010ToI010 I010Copy #define H010ToH010 I010Copy @@ -144,6 +270,356 @@ int I010ToI420(const uint16_t* src_y, int width, int height); +#define H210ToH420 I210ToI420 +LIBYUV_API +int I210ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +#define H210ToH422 I210ToI422 +LIBYUV_API +int I210ToI422(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +#define H410ToH420 I410ToI420 +LIBYUV_API +int I410ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +#define H410ToH444 I410ToI444 +LIBYUV_API +int I410ToI444(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +#define H012ToH420 I012ToI420 +LIBYUV_API +int I012ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +#define H212ToH422 I212ToI422 +LIBYUV_API +int I212ToI422(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +#define H212ToH420 I212ToI420 +LIBYUV_API +int I212ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +#define H412ToH444 I412ToI444 +LIBYUV_API +int I412ToI444(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +#define H412ToH420 I412ToI420 +LIBYUV_API +int I412ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert 10 bit P010 to 8 bit NV12. +// dst_y can be NULL +LIBYUV_API +int P010ToNV12(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +#define I412ToI012 I410ToI010 +#define H410ToH010 I410ToI010 +#define H412ToH012 I410ToI010 +LIBYUV_API +int I410ToI010(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + +#define I212ToI012 I210ToI010 +#define H210ToH010 I210ToI010 +#define H212ToH012 I210ToI010 +LIBYUV_API +int I210ToI010(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert I010 to I410 +LIBYUV_API +int I010ToI410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert I012 to I412 +#define I012ToI412 I010ToI410 + +// Convert I210 to I410 +LIBYUV_API +int I210ToI410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert I212 to I412 +#define I212ToI412 I210ToI410 + +// Convert I010 to P010 +LIBYUV_API +int I010ToP010(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert 10 bit YUV I010 to NV12 +LIBYUV_API +int I010ToNV12(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert I210 to P210 +LIBYUV_API +int I210ToP210(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert I410 to P410 +LIBYUV_API +int I410ToP410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert I012 to P012 +LIBYUV_API +int I012ToP012(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert I212 to P212 +LIBYUV_API +int I212ToP212(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert I412 to P412 +LIBYUV_API +int I412ToP412(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + // Convert I400 (grey) to I420. LIBYUV_API int I400ToI420(const uint8_t* src_y, @@ -157,6 +633,23 @@ int I400ToI420(const uint8_t* src_y, int width, int height); +// Convert J420 to I420. +LIBYUV_API +int J420ToI420(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + // Convert I400 (grey) to NV21. LIBYUV_API int I400ToNV21(const uint8_t* src_y, @@ -200,6 +693,175 @@ int NV21ToI420(const uint8_t* src_y, int width, int height); +// Convert NV12 to NV24. +LIBYUV_API +int NV12ToNV24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert NV16 to NV24. +LIBYUV_API +int NV16ToNV24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert P010 to I010. +LIBYUV_API +int P010ToI010(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert P210 to I210. +LIBYUV_API +int P210ToI210(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert P410 to I410. +LIBYUV_API +int P410ToI410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert P010 to I420. +LIBYUV_API +int P010ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert P210 to I420. +LIBYUV_API +int P210ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert P410 to I420. +LIBYUV_API +int P410ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert P012 to I012. +LIBYUV_API +int P012ToI012(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert P010 to P410. +LIBYUV_API +int P010ToP410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert P012 to P412. +#define P012ToP412 P010ToP410 + +// Convert P016 to P416. +#define P016ToP416 P010ToP410 + +// Convert P210 to P410. +LIBYUV_API +int P210ToP410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert P212 to P412. +#define P212ToP412 P210ToP410 + +// Convert P216 to P416. +#define P216ToP416 P210ToP410 + // Convert YUY2 to I420. LIBYUV_API int YUY2ToI420(const uint8_t* src_yuy2, @@ -248,19 +910,6 @@ int AYUVToNV21(const uint8_t* src_ayuv, int width, int height); -// Convert M420 to I420. -LIBYUV_API -int M420ToI420(const uint8_t* src_m420, - int src_stride_m420, - uint8_t* dst_y, - int dst_stride_y, - uint8_t* dst_u, - int dst_stride_u, - uint8_t* dst_v, - int dst_stride_v, - int width, - int height); - // Convert Android420 to I420. LIBYUV_API int Android420ToI420(const uint8_t* src_y, @@ -292,6 +941,35 @@ int ARGBToI420(const uint8_t* src_argb, int width, int height); +// RGB to I420 with matrix. See ArgbConstants in convert_from_argb.h for usage. +LIBYUV_API +int ARGBToI420Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + const struct ArgbConstants* argbconstants, + int width, + int height); + +// Convert ARGB to I420 with Alpha +LIBYUV_API +int ARGBToI420Alpha(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + uint8_t* dst_a, + int dst_stride_a, + int width, + int height); + // BGRA little endian (argb in memory) to I420. LIBYUV_API int BGRAToI420(const uint8_t* src_bgra, @@ -318,6 +996,71 @@ int ABGRToI420(const uint8_t* src_abgr, int width, int height); +// Convert AR30 to I420. +LIBYUV_API +int AR30ToI420(const uint8_t* src_ar30, + int src_stride_ar30, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Convert AB30 to I420. +LIBYUV_API +int AB30ToI420(const uint8_t* src_ab30, + int src_stride_ab30, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// BGRA little endian (argb in memory) to I422. +LIBYUV_API +int BGRAToI422(const uint8_t* src_bgra, + int src_stride_bgra, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// ABGR little endian (rgba in memory) to I422. +LIBYUV_API +int ABGRToI422(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// RGBA little endian (abgr in memory) to I422. +LIBYUV_API +int RGBAToI422(const uint8_t* src_rgba, + int src_stride_rgba, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + // RGBA little endian (abgr in memory) to I420. LIBYUV_API int RGBAToI420(const uint8_t* src_rgba, @@ -370,7 +1113,46 @@ int RAWToI420(const uint8_t* src_raw, int width, int height); -// RGB16 (RGBP fourcc) little endian to I420. +// RGB big endian (rgb in memory) to I444. +LIBYUV_API +int RAWToI444(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// RGB big endian (rgb in memory) to J420. +LIBYUV_API +int RAWToJ420(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// RGB big endian (rgb in memory) to J444. +LIBYUV_API +int RAWToJ444(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// RGB16 (RGBP fourcc) little endian to I420. Deprecated. LIBYUV_API int RGB565ToI420(const uint8_t* src_rgb565, int src_stride_rgb565, @@ -383,7 +1165,7 @@ int RGB565ToI420(const uint8_t* src_rgb565, int width, int height); -// RGB15 (RGBO fourcc) little endian to I420. +// RGB15 (RGBO fourcc) little endian to I420. Deprecated. LIBYUV_API int ARGB1555ToI420(const uint8_t* src_argb1555, int src_stride_argb1555, @@ -396,7 +1178,7 @@ int ARGB1555ToI420(const uint8_t* src_argb1555, int width, int height); -// RGB12 (R444 fourcc) little endian to I420. +// RGB12 (R444 fourcc) little endian to I420. Deprecated. LIBYUV_API int ARGB4444ToI420(const uint8_t* src_argb4444, int src_stride_argb4444, @@ -418,7 +1200,15 @@ int RGB24ToJ400(const uint8_t* src_rgb24, int width, int height); -#ifdef HAVE_JPEG +// RGB big endian (rgb in memory) to J400. +LIBYUV_API +int RAWToJ400(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_yj, + int dst_stride_yj, + int width, + int height); + // src_width/height provided by capture. // dst_width/height for clipping determine final size. LIBYUV_API @@ -448,13 +1238,25 @@ int MJPGToNV21(const uint8_t* sample, int dst_width, int dst_height); +// JPEG to NV12 +LIBYUV_API +int MJPGToNV12(const uint8_t* sample, + size_t sample_size, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int src_width, + int src_height, + int dst_width, + int dst_height); + // Query size of MJPG in pixels. LIBYUV_API int MJPGSize(const uint8_t* sample, size_t sample_size, int* width, int* height); -#endif // Convert camera sample to I420 with cropping, rotation and vertical flip. // "src_size" is needed to parse MJPG. diff --git a/libs/libyuv/include/libyuv/convert_argb.h b/libs/libyuv/include/libyuv/convert_argb.h index e8ed1f59f3..59b690f3a8 100644 --- a/libs/libyuv/include/libyuv/convert_argb.h +++ b/libs/libyuv/include/libyuv/convert_argb.h @@ -11,20 +11,80 @@ #ifndef INCLUDE_LIBYUV_CONVERT_ARGB_H_ #define INCLUDE_LIBYUV_CONVERT_ARGB_H_ +#include +#include + #include "libyuv/basic_types.h" #include "libyuv/rotate.h" // For enum RotationMode. - -// TODO(fbarchard): This set of functions should exactly match convert.h -// TODO(fbarchard): Add tests. Create random content of right size and convert -// with C vs Opt and or to I420 and compare. -// TODO(fbarchard): Some of these functions lack parameter setting. +#include "libyuv/scale.h" // For enum FilterMode. #ifdef __cplusplus namespace libyuv { extern "C" { #endif +// Conversion matrix for YUV to RGB +LIBYUV_API extern const struct YuvConstants kYuvI601Constants; // BT.601 +LIBYUV_API extern const struct YuvConstants kYuvJPEGConstants; // BT.601 full +LIBYUV_API extern const struct YuvConstants kYuvH709Constants; // BT.709 +LIBYUV_API extern const struct YuvConstants kYuvF709Constants; // BT.709 full +LIBYUV_API extern const struct YuvConstants kYuv2020Constants; // BT.2020 +LIBYUV_API extern const struct YuvConstants kYuvV2020Constants; // BT.2020 full + +// Conversion matrix for YVU to BGR +LIBYUV_API extern const struct YuvConstants kYvuI601Constants; // BT.601 +LIBYUV_API extern const struct YuvConstants kYvuJPEGConstants; // BT.601 full +LIBYUV_API extern const struct YuvConstants kYvuH709Constants; // BT.709 +LIBYUV_API extern const struct YuvConstants kYvuF709Constants; // BT.709 full +LIBYUV_API extern const struct YuvConstants kYvu2020Constants; // BT.2020 +LIBYUV_API extern const struct YuvConstants kYvuV2020Constants; // BT.2020 full + +// Macros for end swapped destination Matrix conversions. +// Swap UV and pass mirrored kYvuJPEGConstants matrix. +// TODO(fbarchard): Add macro for each Matrix function. +#define kYuvI601ConstantsVU kYvuI601Constants +#define kYuvJPEGConstantsVU kYvuJPEGConstants +#define kYuvH709ConstantsVU kYvuH709Constants +#define kYuvF709ConstantsVU kYvuF709Constants +#define kYuv2020ConstantsVU kYvu2020Constants +#define kYuvV2020ConstantsVU kYvuV2020Constants + +#define NV12ToABGRMatrix(a, b, c, d, e, f, g, h, i) \ + NV21ToARGBMatrix(a, b, c, d, e, f, g##VU, h, i) +#define NV21ToABGRMatrix(a, b, c, d, e, f, g, h, i) \ + NV12ToARGBMatrix(a, b, c, d, e, f, g##VU, h, i) +#define NV12ToRAWMatrix(a, b, c, d, e, f, g, h, i) \ + NV21ToRGB24Matrix(a, b, c, d, e, f, g##VU, h, i) +#define NV21ToRAWMatrix(a, b, c, d, e, f, g, h, i) \ + NV12ToRGB24Matrix(a, b, c, d, e, f, g##VU, h, i) +#define I010ToABGRMatrix(a, b, c, d, e, f, g, h, i, j, k) \ + I010ToARGBMatrix(a, b, e, f, c, d, g, h, i##VU, j, k) +#define I210ToABGRMatrix(a, b, c, d, e, f, g, h, i, j, k) \ + I210ToARGBMatrix(a, b, e, f, c, d, g, h, i##VU, j, k) +#define I410ToABGRMatrix(a, b, c, d, e, f, g, h, i, j, k) \ + I410ToARGBMatrix(a, b, e, f, c, d, g, h, i##VU, j, k) +#define I010ToAB30Matrix(a, b, c, d, e, f, g, h, i, j, k) \ + I010ToAR30Matrix(a, b, e, f, c, d, g, h, i##VU, j, k) +#define I210ToAB30Matrix(a, b, c, d, e, f, g, h, i, j, k) \ + I210ToAR30Matrix(a, b, e, f, c, d, g, h, i##VU, j, k) +#define I410ToAB30Matrix(a, b, c, d, e, f, g, h, i, j, k) \ + I410ToAR30Matrix(a, b, e, f, c, d, g, h, i##VU, j, k) +#define I012ToAB30Matrix(a, b, c, d, e, f, g, h, i, j, k) \ + I012ToAR30Matrix(a, b, e, f, c, d, g, h, i##VU, j, k) +#define I420AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \ + I420AlphaToARGBMatrix(a, b, e, f, c, d, g, h, i, j, k##VU, l, m, n) +#define I422AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \ + I422AlphaToARGBMatrix(a, b, e, f, c, d, g, h, i, j, k##VU, l, m, n) +#define I444AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \ + I444AlphaToARGBMatrix(a, b, e, f, c, d, g, h, i, j, k##VU, l, m, n) +#define I010AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \ + I010AlphaToARGBMatrix(a, b, e, f, c, d, g, h, i, j, k##VU, l, m, n) +#define I210AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \ + I210AlphaToARGBMatrix(a, b, e, f, c, d, g, h, i, j, k##VU, l, m, n) +#define I410AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, k, l, m, n) \ + I410AlphaToARGBMatrix(a, b, e, f, c, d, g, h, i, j, k##VU, l, m, n) + // Alias. #define ARGBToARGB ARGBCopy @@ -50,7 +110,7 @@ int I420ToARGB(const uint8_t* src_y, int width, int height); -// Duplicate prototype for function in convert_from.h for remoting. +// Convert I420 to ABGR. LIBYUV_API int I420ToABGR(const uint8_t* src_y, int src_stride_y, @@ -63,19 +123,318 @@ int I420ToABGR(const uint8_t* src_y, int width, int height); -// Convert I010 to ARGB. +// Convert J420 to ARGB. LIBYUV_API -int I010ToARGB(const uint16_t* src_y, +int J420ToARGB(const uint8_t* src_y, int src_stride_y, - const uint16_t* src_u, + const uint8_t* src_u, int src_stride_u, - const uint16_t* src_v, + const uint8_t* src_v, int src_stride_v, uint8_t* dst_argb, int dst_stride_argb, int width, int height); +// Convert J420 to ABGR. +LIBYUV_API +int J420ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert H420 to ARGB. +LIBYUV_API +int H420ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert H420 to ABGR. +LIBYUV_API +int H420ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert U420 to ARGB. +LIBYUV_API +int U420ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert U420 to ABGR. +LIBYUV_API +int U420ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert I422 to ARGB. +LIBYUV_API +int I422ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert I422 to ABGR. +LIBYUV_API +int I422ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert J422 to ARGB. +LIBYUV_API +int J422ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert J422 to ABGR. +LIBYUV_API +int J422ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert H422 to ARGB. +LIBYUV_API +int H422ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert H422 to ABGR. +LIBYUV_API +int H422ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert U422 to ARGB. +LIBYUV_API +int U422ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert U422 to ABGR. +LIBYUV_API +int U422ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert I444 to ARGB. +LIBYUV_API +int I444ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert I444 to ABGR. +LIBYUV_API +int I444ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert J444 to ARGB. +LIBYUV_API +int J444ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert J444 to ABGR. +LIBYUV_API +int J444ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert H444 to ARGB. +LIBYUV_API +int H444ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert H444 to ABGR. +LIBYUV_API +int H444ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert U444 to ARGB. +LIBYUV_API +int U444ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert U444 to ABGR. +LIBYUV_API +int U444ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert I444 to RGB24. +LIBYUV_API +int I444ToRGB24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height); + +// Convert I444 to RAW. +LIBYUV_API +int I444ToRAW(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_raw, + int dst_stride_raw, + int width, + int height); + // Convert I010 to ARGB. LIBYUV_API int I010ToARGB(const uint16_t* src_y, @@ -128,52 +487,104 @@ int H010ToABGR(const uint16_t* src_y, int width, int height); -// Convert I422 to ARGB. +// Convert U010 to ARGB. LIBYUV_API -int I422ToARGB(const uint8_t* src_y, +int U010ToARGB(const uint16_t* src_y, int src_stride_y, - const uint8_t* src_u, + const uint16_t* src_u, int src_stride_u, - const uint8_t* src_v, + const uint16_t* src_v, int src_stride_v, uint8_t* dst_argb, int dst_stride_argb, int width, int height); -// Convert I444 to ARGB. +// Convert U010 to ABGR. LIBYUV_API -int I444ToARGB(const uint8_t* src_y, +int U010ToABGR(const uint16_t* src_y, int src_stride_y, - const uint8_t* src_u, + const uint16_t* src_u, int src_stride_u, - const uint8_t* src_v, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert I210 to ARGB. +LIBYUV_API +int I210ToARGB(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, int src_stride_v, uint8_t* dst_argb, int dst_stride_argb, int width, int height); -// Convert J444 to ARGB. +// Convert I210 to ABGR. LIBYUV_API -int J444ToARGB(const uint8_t* src_y, +int I210ToABGR(const uint16_t* src_y, int src_stride_y, - const uint8_t* src_u, + const uint16_t* src_u, int src_stride_u, - const uint8_t* src_v, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert H210 to ARGB. +LIBYUV_API +int H210ToARGB(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, int src_stride_v, uint8_t* dst_argb, int dst_stride_argb, int width, int height); -// Convert I444 to ABGR. +// Convert H210 to ABGR. LIBYUV_API -int I444ToABGR(const uint8_t* src_y, +int H210ToABGR(const uint16_t* src_y, int src_stride_y, - const uint8_t* src_u, + const uint16_t* src_u, int src_stride_u, - const uint8_t* src_v, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert U210 to ARGB. +LIBYUV_API +int U210ToARGB(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert U210 to ABGR. +LIBYUV_API +int U210ToABGR(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, int src_stride_v, uint8_t* dst_abgr, int dst_stride_abgr, @@ -212,6 +623,70 @@ int I420AlphaToABGR(const uint8_t* src_y, int height, int attenuate); +// Convert I422 with Alpha to preattenuated ARGB. +LIBYUV_API +int I422AlphaToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height, + int attenuate); + +// Convert I422 with Alpha to preattenuated ABGR. +LIBYUV_API +int I422AlphaToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height, + int attenuate); + +// Convert I444 with Alpha to preattenuated ARGB. +LIBYUV_API +int I444AlphaToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height, + int attenuate); + +// Convert I444 with Alpha to preattenuated ABGR. +LIBYUV_API +int I444AlphaToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height, + int attenuate); + // Convert I400 (grey) to ARGB. Reverse of ARGBToI400. LIBYUV_API int I400ToARGB(const uint8_t* src_y, @@ -332,15 +807,6 @@ int NV21ToRAW(const uint8_t* src_y, int width, int height); -// Convert M420 to ARGB. -LIBYUV_API -int M420ToARGB(const uint8_t* src_m420, - int src_stride_m420, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height); - // Convert YUY2 to ARGB. LIBYUV_API int YUY2ToARGB(const uint8_t* src_yuy2, @@ -359,123 +825,6 @@ int UYVYToARGB(const uint8_t* src_uyvy, int width, int height); -// Convert J420 to ARGB. -LIBYUV_API -int J420ToARGB(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height); - -// Convert J422 to ARGB. -LIBYUV_API -int J422ToARGB(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height); - -// Convert J420 to ABGR. -LIBYUV_API -int J420ToABGR(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_abgr, - int dst_stride_abgr, - int width, - int height); - -// Convert J422 to ABGR. -LIBYUV_API -int J422ToABGR(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_abgr, - int dst_stride_abgr, - int width, - int height); - -// Convert H420 to ARGB. -LIBYUV_API -int H420ToARGB(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height); - -// Convert H422 to ARGB. -LIBYUV_API -int H422ToARGB(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height); - -// Convert H420 to ABGR. -LIBYUV_API -int H420ToABGR(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_abgr, - int dst_stride_abgr, - int width, - int height); - -// Convert H422 to ABGR. -LIBYUV_API -int H422ToABGR(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_abgr, - int dst_stride_abgr, - int width, - int height); - -// Convert H010 to ARGB. -LIBYUV_API -int H010ToARGB(const uint16_t* src_y, - int src_stride_y, - const uint16_t* src_u, - int src_stride_u, - const uint16_t* src_v, - int src_stride_v, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height); - // Convert I010 to AR30. LIBYUV_API int I010ToAR30(const uint16_t* src_y, @@ -528,6 +877,110 @@ int H010ToAB30(const uint16_t* src_y, int width, int height); +// Convert U010 to AR30. +LIBYUV_API +int U010ToAR30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height); + +// Convert U010 to AB30. +LIBYUV_API +int U010ToAB30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height); + +// Convert I210 to AR30. +LIBYUV_API +int I210ToAR30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height); + +// Convert I210 to AB30. +LIBYUV_API +int I210ToAB30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height); + +// Convert H210 to AR30. +LIBYUV_API +int H210ToAR30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height); + +// Convert H210 to AB30. +LIBYUV_API +int H210ToAB30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height); + +// Convert U210 to AR30. +LIBYUV_API +int U210ToAR30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height); + +// Convert U210 to AB30. +LIBYUV_API +int U210ToAB30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height); + // BGRA little endian (argb in memory) to ARGB. LIBYUV_API int BGRAToARGB(const uint8_t* src_bgra, @@ -576,7 +1029,16 @@ int RAWToARGB(const uint8_t* src_raw, int width, int height); -// RGB16 (RGBP fourcc) little endian to ARGB. +// RGB big endian (rgb in memory) to RGBA. +LIBYUV_API +int RAWToRGBA(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_rgba, + int dst_stride_rgba, + int width, + int height); + +// RGB16 (RGBP fourcc) little endian to ARGB. Deprecated. LIBYUV_API int RGB565ToARGB(const uint8_t* src_rgb565, int src_stride_rgb565, @@ -585,7 +1047,7 @@ int RGB565ToARGB(const uint8_t* src_rgb565, int width, int height); -// RGB15 (RGBO fourcc) little endian to ARGB. +// RGB15 (RGBO fourcc) little endian to ARGB. Deprecated. LIBYUV_API int ARGB1555ToARGB(const uint8_t* src_argb1555, int src_stride_argb1555, @@ -594,7 +1056,7 @@ int ARGB1555ToARGB(const uint8_t* src_argb1555, int width, int height); -// RGB12 (R444 fourcc) little endian to ARGB. +// RGB12 (R444 fourcc) little endian to ARGB. Deprecated. LIBYUV_API int ARGB4444ToARGB(const uint8_t* src_argb4444, int src_stride_argb4444, @@ -635,7 +1097,42 @@ int AR30ToAB30(const uint8_t* src_ar30, int width, int height); -#ifdef HAVE_JPEG +// Convert AR64 to ARGB. +LIBYUV_API +int AR64ToARGB(const uint16_t* src_ar64, + int src_stride_ar64, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert AB64 to ABGR. +#define AB64ToABGR AR64ToARGB + +// Convert AB64 to ARGB. +LIBYUV_API +int AB64ToARGB(const uint16_t* src_ab64, + int src_stride_ab64, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Convert AR64 to ABGR. +#define AR64ToABGR AB64ToARGB + +// Convert AR64 To AB64. +LIBYUV_API +int AR64ToAB64(const uint16_t* src_ar64, + int src_stride_ar64, + uint16_t* dst_ab64, + int dst_stride_ab64, + int width, + int height); + +// Convert AB64 To AR64. +#define AB64ToAR64 AR64ToAB64 + // src_width/height provided by capture // dst_width/height for clipping determine final size. LIBYUV_API @@ -647,7 +1144,6 @@ int MJPGToARGB(const uint8_t* sample, int src_height, int dst_width, int dst_height); -#endif // Convert Android420 to ARGB. LIBYUV_API @@ -677,6 +1173,1165 @@ int Android420ToABGR(const uint8_t* src_y, int width, int height); +// Convert NV12 to RGB565. Deprecated. +LIBYUV_API +int NV12ToRGB565(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + int width, + int height); + +// Convert I422 to BGRA. +LIBYUV_API +int I422ToBGRA(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_bgra, + int dst_stride_bgra, + int width, + int height); + +// Convert I422 to ABGR. +LIBYUV_API +int I422ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +// Convert I422 to RGBA. +LIBYUV_API +int I422ToRGBA(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgba, + int dst_stride_rgba, + int width, + int height); + +LIBYUV_API +int I420ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +LIBYUV_API +int I420ToBGRA(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_bgra, + int dst_stride_bgra, + int width, + int height); + +LIBYUV_API +int I420ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height); + +LIBYUV_API +int I420ToRGBA(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgba, + int dst_stride_rgba, + int width, + int height); + +LIBYUV_API +int I420ToRGB24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height); + +LIBYUV_API +int I420ToRAW(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_raw, + int dst_stride_raw, + int width, + int height); + +LIBYUV_API +int H420ToRGB24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height); + +LIBYUV_API +int H420ToRAW(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_raw, + int dst_stride_raw, + int width, + int height); + +LIBYUV_API +int J420ToRGB24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height); + +LIBYUV_API +int J420ToRAW(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_raw, + int dst_stride_raw, + int width, + int height); + +// Convert I422 to RGB24. +LIBYUV_API +int I422ToRGB24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height); + +// Convert I422 to RAW. +LIBYUV_API +int I422ToRAW(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_raw, + int dst_stride_raw, + int width, + int height); + +// Convert I420 to RGB565. Deprecated. +LIBYUV_API +int I420ToRGB565(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + int width, + int height); + +// Convert J420 to RGB565. Deprecated. +LIBYUV_API +int J420ToRGB565(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + int width, + int height); + +// Convert H420 to RGB565. Deprecated. +LIBYUV_API +int H420ToRGB565(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + int width, + int height); + +// Convert I422 to RGB565. Deprecated. +LIBYUV_API +int I422ToRGB565(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + int width, + int height); + +// Convert I420 To RGB565 with 4x4 dither matrix (16 bytes). Deprecated. +// Values in dither matrix from 0 to 7 recommended. +// The order of the dither matrix is first byte is upper left. + +LIBYUV_API +int I420ToRGB565Dither(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + const uint8_t* dither4x4, + int width, + int height); + +// Convert I420 to ARGB1555. Deprecated. +LIBYUV_API +int I420ToARGB1555(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb1555, + int dst_stride_argb1555, + int width, + int height); + +// Convert I420 to ARGB4444. Deprecated. +LIBYUV_API +int I420ToARGB4444(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb4444, + int dst_stride_argb4444, + int width, + int height); + +// Convert I420 to AR30. +LIBYUV_API +int I420ToAR30(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height); + +// Convert I420 to AB30. +LIBYUV_API +int I420ToAB30(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height); + +// Convert H420 to AR30. +LIBYUV_API +int H420ToAR30(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height); + +// Convert H420 to AB30. +LIBYUV_API +int H420ToAB30(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height); + +// Convert I420 to ARGB with matrix. +LIBYUV_API +int I420ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I422 to ARGB with matrix. +LIBYUV_API +int I422ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I444 to ARGB with matrix. +LIBYUV_API +int I444ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I444 to RGB24 with matrix. +LIBYUV_API +int I444ToRGB24Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert 10 bit 420 YUV to ARGB with matrix. +LIBYUV_API +int I010ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert 10 bit 420 YUV to ARGB with matrix. +LIBYUV_API +int I210ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert 10 bit 444 YUV to ARGB with matrix. +LIBYUV_API +int I410ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert 10 bit YUV to ARGB with matrix. +LIBYUV_API +int I010ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// multiply 12 bit yuv into high bits to allow any number of bits. +LIBYUV_API +int I012ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert 12 bit YUV to ARGB with matrix. +LIBYUV_API +int I012ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert 10 bit 422 YUV to ARGB with matrix. +LIBYUV_API +int I210ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert 10 bit 444 YUV to ARGB with matrix. +LIBYUV_API +int I410ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert P010 to ARGB with matrix. +LIBYUV_API +int P010ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert P210 to ARGB with matrix. +LIBYUV_API +int P210ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert P410 to ARGB with matrix. +LIBYUV_API +int P410ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert P010 to AR30 with matrix. +LIBYUV_API +int P010ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert P210 to AR30 with matrix. +LIBYUV_API +int P210ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert P410 to AR30 with matrix. +LIBYUV_API +int P410ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// P012 and P010 use most significant bits so the conversion is the same. +// Convert P012 to ARGB with matrix. +#define P012ToARGBMatrix P010ToARGBMatrix +// Convert P012 to AR30 with matrix. +#define P012ToAR30Matrix P010ToAR30Matrix +// Convert P212 to ARGB with matrix. +#define P212ToARGBMatrix P210ToARGBMatrix +// Convert P212 to AR30 with matrix. +#define P212ToAR30Matrix P210ToAR30Matrix +// Convert P412 to ARGB with matrix. +#define P412ToARGBMatrix P410ToARGBMatrix +// Convert P412 to AR30 with matrix. +#define P412ToAR30Matrix P410ToAR30Matrix + +// Convert P016 to ARGB with matrix. +#define P016ToARGBMatrix P010ToARGBMatrix +// Convert P016 to AR30 with matrix. +#define P016ToAR30Matrix P010ToAR30Matrix +// Convert P216 to ARGB with matrix. +#define P216ToARGBMatrix P210ToARGBMatrix +// Convert P216 to AR30 with matrix. +#define P216ToAR30Matrix P210ToAR30Matrix +// Convert P416 to ARGB with matrix. +#define P416ToARGBMatrix P410ToARGBMatrix +// Convert P416 to AR30 with matrix. +#define P416ToAR30Matrix P410ToAR30Matrix + +// Convert I420 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I420AlphaToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate); + +// Convert I422 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I422AlphaToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate); + +// Convert I444 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I444AlphaToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate); + +// Convert I010 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I010AlphaToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate); + +// Convert I210 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I210AlphaToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate); + +// Convert I410 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I410AlphaToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate); + +// Convert NV12 to ARGB with matrix. +LIBYUV_API +int NV12ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert NV21 to ARGB with matrix. +LIBYUV_API +int NV21ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_vu, + int src_stride_vu, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert NV12 to RGB565 with matrix. Deprecated. +LIBYUV_API +int NV12ToRGB565Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert NV12 to RGB24 with matrix. +LIBYUV_API +int NV12ToRGB24Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert NV21 to RGB24 with matrix. +LIBYUV_API +int NV21ToRGB24Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_vu, + int src_stride_vu, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert YUY2 to ARGB with matrix. +LIBYUV_API +int YUY2ToARGBMatrix(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert UYVY to ARGB with matrix. +LIBYUV_API +int UYVYToARGBMatrix(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert Android420 to ARGB with matrix. +LIBYUV_API +int Android420ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + int src_pixel_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I422 to RGBA with matrix. +LIBYUV_API +int I422ToRGBAMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgba, + int dst_stride_rgba, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I420 to RGBA with matrix. +LIBYUV_API +int I420ToRGBAMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgba, + int dst_stride_rgba, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I420 to RGB24 with matrix. +LIBYUV_API +int I420ToRGB24Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I422 to RGB24 with matrix. +LIBYUV_API +int I422ToRGB24Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I420 to RGB565 with specified color matrix. Deprecated. +LIBYUV_API +int I420ToRGB565Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I422 to RGB565 with specified color matrix. Deprecated. +LIBYUV_API +int I422ToRGB565Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I420 to AR30 with matrix. +LIBYUV_API +int I420ToAR30Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I400 (grey) to ARGB. Reverse of ARGBToI400. +LIBYUV_API +int I400ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height); + +// Convert I420 to ARGB with matrix and UV filter mode. +LIBYUV_API +int I420ToARGBMatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + +// Convert I422 to ARGB with matrix and UV filter mode. +LIBYUV_API +int I422ToARGBMatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + +// Convert I422 to RGB24 with matrix and UV filter mode. +LIBYUV_API +int I422ToRGB24MatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + +// Convert I420 to RGB24 with matrix and UV filter mode. +LIBYUV_API +int I420ToRGB24MatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + +// Convert I010 to AR30 with matrix and UV filter mode. +LIBYUV_API +int I010ToAR30MatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + +// Convert I210 to AR30 with matrix and UV filter mode. +LIBYUV_API +int I210ToAR30MatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + +// Convert I010 to ARGB with matrix and UV filter mode. +LIBYUV_API +int I010ToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + +// Convert I210 to ARGB with matrix and UV filter mode. +LIBYUV_API +int I210ToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + +// Convert I420 with Alpha to attenuated ARGB with matrix and UV filter mode. +LIBYUV_API +int I420AlphaToARGBMatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate, + enum FilterMode filter); + +// Convert I422 with Alpha to attenuated ARGB with matrix and UV filter mode. +LIBYUV_API +int I422AlphaToARGBMatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate, + enum FilterMode filter); + +// Convert I010 with Alpha to attenuated ARGB with matrix and UV filter mode. +LIBYUV_API +int I010AlphaToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate, + enum FilterMode filter); + +// Convert I210 with Alpha to attenuated ARGB with matrix and UV filter mode. +LIBYUV_API +int I210AlphaToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate, + enum FilterMode filter); + +// Convert P010 to ARGB with matrix and UV filter mode. +LIBYUV_API +int P010ToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + +// Convert P210 to ARGB with matrix and UV filter mode. +LIBYUV_API +int P210ToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + +// Convert P010 to AR30 with matrix and UV filter mode. +LIBYUV_API +int P010ToAR30MatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + +// Convert P210 to AR30 with matrix and UV filter mode. +LIBYUV_API +int P210ToAR30MatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter); + // Convert camera sample to ARGB with cropping, rotation and vertical flip. // "sample_size" is needed to parse MJPG. // "dst_stride_argb" number of bytes in a row of the dst_argb plane. diff --git a/libs/libyuv/include/libyuv/convert_from.h b/libs/libyuv/include/libyuv/convert_from.h index 861418d07b..a746629afd 100644 --- a/libs/libyuv/include/libyuv/convert_from.h +++ b/libs/libyuv/include/libyuv/convert_from.h @@ -11,6 +11,8 @@ #ifndef INCLUDE_LIBYUV_CONVERT_FROM_H_ #define INCLUDE_LIBYUV_CONVERT_FROM_H_ +#include + #include "libyuv/basic_types.h" #include "libyuv/rotate.h" @@ -23,6 +25,7 @@ extern "C" { // Convert 8 bit YUV to 10 bit. #define H420ToH010 I420ToI010 +LIBYUV_API int I420ToI010(const uint8_t* src_y, int src_stride_y, const uint8_t* src_u, @@ -38,6 +41,24 @@ int I420ToI010(const uint8_t* src_y, int width, int height); +// Convert 8 bit YUV to 12 bit. +#define H420ToH012 I420ToI012 +LIBYUV_API +int I420ToI012(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + LIBYUV_API int I420ToI422(const uint8_t* src_y, int src_stride_y, @@ -107,6 +128,81 @@ int I420ToNV21(const uint8_t* src_y, int width, int height); +// Convert I420 to P010. +LIBYUV_API +int I420ToP010(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert I422 to P210. +LIBYUV_API +int I422ToP210(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert I444 to P410. +LIBYUV_API +int I444ToP410(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert I420 to P210. +LIBYUV_API +int I420ToP210(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Convert I420 to P410. +LIBYUV_API +int I420ToP410(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + LIBYUV_API int I420ToYUY2(const uint8_t* src_y, int src_stride_y, @@ -131,6 +227,10 @@ int I420ToUYVY(const uint8_t* src_y, int width, int height); +// The following are from convert_argb.h +// DEPRECATED: The prototypes will be removed in future. Use convert_argb.h + +// Convert I420 to ARGB. LIBYUV_API int I420ToARGB(const uint8_t* src_y, int src_stride_y, @@ -143,18 +243,7 @@ int I420ToARGB(const uint8_t* src_y, int width, int height); -LIBYUV_API -int I420ToBGRA(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_bgra, - int dst_stride_bgra, - int width, - int height); - +// Convert I420 to ABGR. LIBYUV_API int I420ToABGR(const uint8_t* src_y, int src_stride_y, @@ -167,181 +256,6 @@ int I420ToABGR(const uint8_t* src_y, int width, int height); -LIBYUV_API -int I420ToRGBA(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgba, - int dst_stride_rgba, - int width, - int height); - -LIBYUV_API -int I420ToRGB24(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb24, - int dst_stride_rgb24, - int width, - int height); - -LIBYUV_API -int I420ToRAW(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_raw, - int dst_stride_raw, - int width, - int height); - -LIBYUV_API -int H420ToRGB24(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb24, - int dst_stride_rgb24, - int width, - int height); - -LIBYUV_API -int H420ToRAW(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_raw, - int dst_stride_raw, - int width, - int height); - -LIBYUV_API -int I420ToRGB565(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - int width, - int height); - -LIBYUV_API -int J420ToRGB565(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - int width, - int height); - -LIBYUV_API -int H420ToRGB565(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - int width, - int height); - -LIBYUV_API -int I422ToRGB565(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - int width, - int height); - -// Convert I420 To RGB565 with 4x4 dither matrix (16 bytes). -// Values in dither matrix from 0 to 7 recommended. -// The order of the dither matrix is first byte is upper left. - -LIBYUV_API -int I420ToRGB565Dither(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - const uint8_t* dither4x4, - int width, - int height); - -LIBYUV_API -int I420ToARGB1555(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_argb1555, - int dst_stride_argb1555, - int width, - int height); - -LIBYUV_API -int I420ToARGB4444(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_argb4444, - int dst_stride_argb4444, - int width, - int height); - -// Convert I420 to AR30. -LIBYUV_API -int I420ToAR30(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_ar30, - int dst_stride_ar30, - int width, - int height); - -// Convert H420 to AR30. -LIBYUV_API -int H420ToAR30(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_ar30, - int dst_stride_ar30, - int width, - int height); - // Convert I420 to specified format. // "dst_sample_stride" is bytes in a row for the destination. Pass 0 if the // buffer has contiguous rows. Can be negative. A multiple of 16 is optimal. diff --git a/libs/libyuv/include/libyuv/convert_from_argb.h b/libs/libyuv/include/libyuv/convert_from_argb.h index 08c6aa5649..817df6f9ea 100644 --- a/libs/libyuv/include/libyuv/convert_from_argb.h +++ b/libs/libyuv/include/libyuv/convert_from_argb.h @@ -11,6 +11,8 @@ #ifndef INCLUDE_LIBYUV_CONVERT_FROM_ARGB_H_ #define INCLUDE_LIBYUV_CONVERT_FROM_ARGB_H_ +#include + #include "libyuv/basic_types.h" #ifdef __cplusplus @@ -18,6 +20,47 @@ namespace libyuv { extern "C" { #endif +// The ArgbConstants below can be used with the ARGBTo*Matrix() functions to +// process different RGB formats. E.g., if your input is ARGB little endian +// (bgra in memory) you'll want to use the kArgb* constants. Alternatively, if +// your input is ABGR little endian (rgba in memory) you'd use the kAbgr* ones. +// +// Conversion matrix for xRGB to YUV. +LIBYUV_API extern const struct ArgbConstants kArgbI601Constants; // BT.601 +LIBYUV_API extern const struct ArgbConstants kArgbJPEGConstants; // BT.601 full +LIBYUV_API extern const struct ArgbConstants kArgbH709Constants; // BT.709 +LIBYUV_API extern const struct ArgbConstants kArgbF709Constants; // BT.709 full +LIBYUV_API extern const struct ArgbConstants kArgbU2020Constants; // BT.2020 +LIBYUV_API extern const struct ArgbConstants + kArgbV2020Constants; // BT.2020 full + +// Conversion matrix for xBGR to YUV. +LIBYUV_API extern const struct ArgbConstants kAbgrI601Constants; // BT.601 +LIBYUV_API extern const struct ArgbConstants kAbgrJPEGConstants; // BT.601 full +LIBYUV_API extern const struct ArgbConstants kAbgrH709Constants; // BT.709 +LIBYUV_API extern const struct ArgbConstants kAbgrF709Constants; // BT.709 full +LIBYUV_API extern const struct ArgbConstants kAbgrU2020Constants; // BT.2020 +LIBYUV_API extern const struct ArgbConstants + kAbgrV2020Constants; // BT.2020 full + +// Conversion matrix for RGBx to YUV. +LIBYUV_API extern const struct ArgbConstants kRgbaI601Constants; // BT.601 +LIBYUV_API extern const struct ArgbConstants kRgbaJPEGConstants; // BT.601 full +LIBYUV_API extern const struct ArgbConstants kRgbaH709Constants; // BT.709 +LIBYUV_API extern const struct ArgbConstants kRgbaF709Constants; // BT.709 full +LIBYUV_API extern const struct ArgbConstants kRgbaU2020Constants; // BT.2020 +LIBYUV_API extern const struct ArgbConstants + kRgbaV2020Constants; // BT.2020 full + +// Conversion matrix from BGRx to YUV. +LIBYUV_API extern const struct ArgbConstants kBgraI601Constants; // BT.601 +LIBYUV_API extern const struct ArgbConstants kBgraJPEGConstants; // BT.601 full +LIBYUV_API extern const struct ArgbConstants kBgraH709Constants; // BT.709 +LIBYUV_API extern const struct ArgbConstants kBgraF709Constants; // BT.709 full +LIBYUV_API extern const struct ArgbConstants kBgraU2020Constants; // BT.2020 +LIBYUV_API extern const struct ArgbConstants + kBgraV2020Constants; // BT.2020 full + // Copy ARGB to ARGB. #define ARGBToARGB ARGBCopy LIBYUV_API @@ -77,6 +120,10 @@ int ARGBToAR30(const uint8_t* src_argb, int width, int height); +// Aliases +#define ABGRToRGB24 ARGBToRAW +#define ABGRToRAW ARGBToRGB24 + // Convert ARGB To RGB24. LIBYUV_API int ARGBToRGB24(const uint8_t* src_argb, @@ -95,7 +142,7 @@ int ARGBToRAW(const uint8_t* src_argb, int width, int height); -// Convert ARGB To RGB565. +// Convert ARGB To RGB565. Deprecated. LIBYUV_API int ARGBToRGB565(const uint8_t* src_argb, int src_stride_argb, @@ -104,7 +151,7 @@ int ARGBToRGB565(const uint8_t* src_argb, int width, int height); -// Convert ARGB To RGB565 with 4x4 dither matrix (16 bytes). +// Convert ARGB To RGB565 with 4x4 dither matrix (16 bytes). Deprecated. // Values in dither matrix from 0 to 7 recommended. // The order of the dither matrix is first byte is upper left. // TODO(fbarchard): Consider pointer to 2d array for dither4x4. @@ -118,7 +165,7 @@ int ARGBToRGB565Dither(const uint8_t* src_argb, int width, int height); -// Convert ARGB To ARGB1555. +// Convert ARGB To ARGB1555. Deprecated. LIBYUV_API int ARGBToARGB1555(const uint8_t* src_argb, int src_stride_argb, @@ -127,7 +174,7 @@ int ARGBToARGB1555(const uint8_t* src_argb, int width, int height); -// Convert ARGB To ARGB4444. +// Convert ARGB To ARGB4444. Deprecated. LIBYUV_API int ARGBToARGB4444(const uint8_t* src_argb, int src_stride_argb, @@ -149,6 +196,45 @@ int ARGBToI444(const uint8_t* src_argb, int width, int height); +// ARGB to I444 with matrix. See ArgbConstants at the top of this file for +// usage. +LIBYUV_API +int ARGBToI444Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + const struct ArgbConstants* argbconstants, + int width, + int height); + +// Convert ARGB to AR64. +LIBYUV_API +int ARGBToAR64(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_ar64, + int dst_stride_ar64, + int width, + int height); + +// Convert ABGR to AB64. +#define ABGRToAB64 ARGBToAR64 + +// Convert ARGB to AB64. +LIBYUV_API +int ARGBToAB64(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_ab64, + int dst_stride_ab64, + int width, + int height); + +// Convert ABGR to AR64. +#define ABGRToAR64 ARGBToAB64 + // Convert ARGB To I422. LIBYUV_API int ARGBToI422(const uint8_t* src_argb, @@ -162,6 +248,34 @@ int ARGBToI422(const uint8_t* src_argb, int width, int height); +// Convert ABGR To I422. +LIBYUV_API +int ABGRToI422(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height); + +// ARGB to I422 with matrix. See ArgbConstants at the top of this file for +// usage. +LIBYUV_API +int ARGBToI422Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + const struct ArgbConstants* argbconstants, + int width, + int height); + // Convert ARGB To I420. (also in convert.h) LIBYUV_API int ARGBToI420(const uint8_t* src_argb, @@ -181,10 +295,10 @@ int ARGBToJ420(const uint8_t* src_argb, int src_stride_argb, uint8_t* dst_yj, int dst_stride_yj, - uint8_t* dst_u, - int dst_stride_u, - uint8_t* dst_v, - int dst_stride_v, + uint8_t* dst_uj, + int dst_stride_uj, + uint8_t* dst_vj, + int dst_stride_vj, int width, int height); @@ -194,10 +308,23 @@ int ARGBToJ422(const uint8_t* src_argb, int src_stride_argb, uint8_t* dst_yj, int dst_stride_yj, - uint8_t* dst_u, - int dst_stride_u, - uint8_t* dst_v, - int dst_stride_v, + uint8_t* dst_uj, + int dst_stride_uj, + uint8_t* dst_vj, + int dst_stride_vj, + int width, + int height); + +// Convert ARGB to J444. +LIBYUV_API +int ARGBToJ444(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_yj, + int dst_stride_yj, + uint8_t* dst_uj, + int dst_stride_uj, + uint8_t* dst_vj, + int dst_stride_vj, int width, int height); @@ -210,6 +337,50 @@ int ARGBToJ400(const uint8_t* src_argb, int width, int height); +// Convert ABGR to J420. (JPeg full range I420). +LIBYUV_API +int ABGRToJ420(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_yj, + int dst_stride_yj, + uint8_t* dst_uj, + int dst_stride_uj, + uint8_t* dst_vj, + int dst_stride_vj, + int width, + int height); + +// Convert ABGR to J422. +LIBYUV_API +int ABGRToJ422(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_yj, + int dst_stride_yj, + uint8_t* dst_uj, + int dst_stride_uj, + uint8_t* dst_vj, + int dst_stride_vj, + int width, + int height); + +// Convert ABGR to J400. (JPeg full range). +LIBYUV_API +int ABGRToJ400(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_yj, + int dst_stride_yj, + int width, + int height); + +// Convert RGBA to J400. (JPeg full range). +LIBYUV_API +int RGBAToJ400(const uint8_t* src_rgba, + int src_stride_rgba, + uint8_t* dst_yj, + int dst_stride_yj, + int width, + int height); + // Convert ARGB to I400. LIBYUV_API int ARGBToI400(const uint8_t* src_argb, @@ -219,15 +390,6 @@ int ARGBToI400(const uint8_t* src_argb, int width, int height); -// Convert ARGB to G. (Reverse of J400toARGB, which replicates G back to ARGB) -LIBYUV_API -int ARGBToG(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_g, - int dst_stride_g, - int width, - int height); - // Convert ARGB To NV12. LIBYUV_API int ARGBToNV12(const uint8_t* src_argb, @@ -239,6 +401,80 @@ int ARGBToNV12(const uint8_t* src_argb, int width, int height); +// ARGB to NV12 with matrix. See ArgbConstants at the top of this file for +// usage. +LIBYUV_API +int ARGBToNV12Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height); + +// Convert ARGB To NV16. +LIBYUV_API +int ARGBToNV16(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// ARGB to NV16 with matrix. See ArgbConstants at the top of this file for +// usage. +LIBYUV_API +int ARGBToNV16Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height); + +// Convert ARGB To NV24. +LIBYUV_API +int ARGBToNV24(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// ARGB to NV24 with matrix. See ArgbConstants at the top of this file for +// usage. +LIBYUV_API +int ARGBToNV24Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height); + +// ARGB to NV21 with matrix. See ArgbConstants at the top of this file for +// usage. +LIBYUV_API +int ARGBToNV21Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + const struct ArgbConstants* argbconstants, + int width, + int height); + // Convert ARGB To NV21. LIBYUV_API int ARGBToNV21(const uint8_t* src_argb, @@ -250,6 +486,78 @@ int ARGBToNV21(const uint8_t* src_argb, int width, int height); +// Convert ARGB To P010. +LIBYUV_API +int ARGBToP010(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// ARGB to P010 with matrix. See ArgbConstants at the top of this file for +// usage. +LIBYUV_API +int ARGBToP010Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height); + +// Convert ARGB To P210. +LIBYUV_API +int ARGBToP210(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// ARGB to P210 with matrix. See ArgbConstants at the top of this file for +// usage. +LIBYUV_API +int ARGBToP210Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height); + +// Convert ARGB To P410. +LIBYUV_API +int ARGBToP410(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// ARGB to P410 with matrix. See ArgbConstants at the top of this file for +// usage. +LIBYUV_API +int ARGBToP410Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height); + // Convert ABGR To NV12. LIBYUV_API int ABGRToNV12(const uint8_t* src_abgr, @@ -272,17 +580,6 @@ int ABGRToNV21(const uint8_t* src_abgr, int width, int height); -// Convert ARGB To NV21. -LIBYUV_API -int ARGBToNV21(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_y, - int dst_stride_y, - uint8_t* dst_vu, - int dst_stride_vu, - int width, - int height); - // Convert ARGB To YUY2. LIBYUV_API int ARGBToYUY2(const uint8_t* src_argb, @@ -301,6 +598,39 @@ int ARGBToUYVY(const uint8_t* src_argb, int width, int height); +// RAW to NV21 +LIBYUV_API +int RAWToNV21(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + int width, + int height); + +// RGB24 to NV12 +LIBYUV_API +int RGB24ToNV12(const uint8_t* src_rgb24, + int src_stride_rgb24, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// RAW to JNV21 full range NV21 +LIBYUV_API +int RAWToJNV21(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + int width, + int height); + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/include/libyuv/cpu_id.h b/libs/libyuv/include/libyuv/cpu_id.h index b01cd25c57..54512b766d 100644 --- a/libs/libyuv/include/libyuv/cpu_id.h +++ b/libs/libyuv/include/libyuv/cpu_id.h @@ -11,6 +11,8 @@ #ifndef INCLUDE_LIBYUV_CPU_ID_H_ #define INCLUDE_LIBYUV_CPU_ID_H_ +#include + #include "libyuv/basic_types.h" #ifdef __cplusplus @@ -21,34 +23,60 @@ extern "C" { // Internal flag to indicate cpuid requires initialization. static const int kCpuInitialized = 0x1; -// These flags are only valid on ARM processors. +// These flags are only valid on Arm processors. static const int kCpuHasARM = 0x2; -static const int kCpuHasNEON = 0x4; -// 0x8 reserved for future ARM flag. +static const int kCpuHasNEON = 0x100; +static const int kCpuHasNeonDotProd = 0x200; +static const int kCpuHasNeonI8MM = 0x400; +static const int kCpuHasSVE = 0x800; +static const int kCpuHasSVE2 = 0x1000; +static const int kCpuHasSME = 0x2000; +static const int kCpuHasSME2 = 0x4000; +static const int kCpuHasSVEF32MM = 0x8000; + +// These flags are only valid on RISCV processors. +static const int kCpuHasRISCV = 0x4; +static const int kCpuHasRVV = 0x100; +static const int kCpuHasRVVZVFH = 0x200; // These flags are only valid on x86 processors. -static const int kCpuHasX86 = 0x10; -static const int kCpuHasSSE2 = 0x20; -static const int kCpuHasSSSE3 = 0x40; -static const int kCpuHasSSE41 = 0x80; -static const int kCpuHasSSE42 = 0x100; // unused at this time. -static const int kCpuHasAVX = 0x200; -static const int kCpuHasAVX2 = 0x400; -static const int kCpuHasERMS = 0x800; -static const int kCpuHasFMA3 = 0x1000; -static const int kCpuHasF16C = 0x2000; -static const int kCpuHasGFNI = 0x4000; -static const int kCpuHasAVX512BW = 0x8000; -static const int kCpuHasAVX512VL = 0x10000; -static const int kCpuHasAVX512VBMI = 0x20000; -static const int kCpuHasAVX512VBMI2 = 0x40000; -static const int kCpuHasAVX512VBITALG = 0x80000; -static const int kCpuHasAVX512VPOPCNTDQ = 0x100000; +static const int kCpuHasX86 = 0x8; +static const int kCpuHasSSE2 = 0x100; +static const int kCpuHasSSSE3 = 0x200; +static const int kCpuHasSSE41 = 0x400; +static const int kCpuHasSSE42 = 0x800; +static const int kCpuHasAVX = 0x1000; +static const int kCpuHasAVX2 = 0x2000; +static const int kCpuHasERMS = 0x4000; +static const int kCpuHasFSMR = 0x8000; +static const int kCpuHasFMA3 = 0x10000; +static const int kCpuHasF16C = 0x20000; +static const int kCpuHasAVX512BW = 0x40000; +static const int kCpuHasAVX512VL = 0x80000; +static const int kCpuHasAVX512VNNI = 0x100000; +static const int kCpuHasAVX512VBMI = 0x200000; +static const int kCpuHasAVX512VBMI2 = 0x400000; +static const int kCpuHasAVX512VBITALG = 0x800000; +static const int kCpuHasAVX10 = 0x1000000; +static const int kCpuHasAVX10_2 = 0x2000000; +static const int kCpuHasAVXVNNI = 0x4000000; +static const int kCpuHasAVXVNNIINT8 = 0x8000000; +static const int kCpuHasAMXINT8 = 0x10000000; +static const int kCpuHasAVX512BMM = 0x20000000; +static const int kCpuHasAMXTF32 = 0x40000000; -// These flags are only valid on MIPS processors. -static const int kCpuHasMIPS = 0x200000; -static const int kCpuHasMSA = 0x400000; -static const int kCpuHasMMI = 0x800000; +// These flags are only valid on LOONGARCH processors. +static const int kCpuHasLOONGARCH = 0x20; +static const int kCpuHasLSX = 0x100; +static const int kCpuHasLASX = 0x200; + +// These flags are only valid on WASM processors. +static const int kCpuHasWASM = 0x40; +static const int kCpuHasWASMSIMD = 0x100; + +// These flags are only valid on Hexagon processors. +static const int kCpuHasHexagon = 0x80; +static const int kCpuHasHVX = 0x100; // Optional init function. TestCpuFlag does an auto-init. // Returns cpu_info flags. @@ -71,6 +99,17 @@ static __inline int TestCpuFlag(int test_flag) { // Internal function for parsing /proc/cpuinfo. LIBYUV_API int ArmCpuCaps(const char* cpuinfo_name); +LIBYUV_API +int RiscvCpuCaps(const char* cpuinfo_name); + +#ifdef __linux__ +// On Linux, parse AArch64 features from getauxval(AT_HWCAP{,2}). +LIBYUV_API +int AArch64CpuCaps(unsigned long hwcap, unsigned long hwcap2); +#else +LIBYUV_API +int AArch64CpuCaps(); +#endif // For testing, allow CPU flags to be disabled. // ie MaskCpuFlags(~kCpuHasSSSE3) to disable SSSE3. diff --git a/libs/libyuv/include/libyuv/cpu_support.h b/libs/libyuv/include/libyuv/cpu_support.h new file mode 100644 index 0000000000..d007f3d011 --- /dev/null +++ b/libs/libyuv/include/libyuv/cpu_support.h @@ -0,0 +1,147 @@ +/* + * Copyright 2024 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef INCLUDE_LIBYUV_CPU_SUPPORT_H_ +#define INCLUDE_LIBYUV_CPU_SUPPORT_H_ + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +#if defined(__pnacl__) || defined(__CLR_VER) || \ + (defined(__native_client__) && defined(__x86_64__)) || \ + (defined(__i386__) && !defined(__SSE__) && !defined(__clang__)) +#define LIBYUV_DISABLE_X86 +#endif + +#if defined(__native_client__) +#define LIBYUV_DISABLE_NEON +#endif + +// MemorySanitizer does not support assembly code yet. http://crbug.com/344505 +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) +#if !defined(LIBYUV_MSAN) +#define LIBYUV_MSAN 1 +#endif +#if !defined(LIBYUV_DISABLE_NEON) +#define LIBYUV_DISABLE_NEON +#endif +#if !defined(LIBYUV_DISABLE_SME) +#define LIBYUV_DISABLE_SME +#endif +#if !defined(LIBYUV_DISABLE_SVE) +#define LIBYUV_DISABLE_SVE +#endif +#if !defined(LIBYUV_ENABLE_ROWWIN) +#define LIBYUV_ENABLE_ROWWIN +#endif +#endif // __has_feature(memory_sanitizer) +#endif // defined(__has_feature) + +// clang >= 3.5.0 required for Arm64. +#if defined(__clang__) && defined(__aarch64__) && !defined(LIBYUV_DISABLE_NEON) +#if (__clang_major__ < 3) || (__clang_major__ == 3 && (__clang_minor__ < 5)) +#define LIBYUV_DISABLE_NEON +#endif // clang >= 3.5 +#endif // __clang__ + +// GCC >= 4.7.0 required for AVX2. +#if defined(__GNUC__) && !defined(__clang__) && \ + !defined(LIBYUV_ENABLE_ROWWIN) && \ + (defined(__x86_64__) || defined(__i386__)) +#if (__GNUC__ > 4) || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 7)) +#define GCC_HAS_AVX2 1 +#endif // GNUC >= 4.7 +#endif // __GNUC__ + +// GCC >= 9.0.0 required for AVX512 (including VNNI and VBMI). +#if defined(__GNUC__) && !defined(__clang__) && \ + !defined(LIBYUV_ENABLE_ROWWIN) && defined(__x86_64__) +#if (__GNUC__ >= 9) +#define GCC_HAS_AVX512 1 +#endif // GNUC >= 9 +#endif // __GNUC__ + +// Function target attributes so GCC enables zmm16..zmm31 and k1..k7 clobbers +// inside AVX512 functions without emitting AVX512 in non-AVX512 functions. +#if defined(GCC_HAS_AVX512) +#define LIBYUV_TARGET_AVX512BW \ + __attribute__((target("avx512bw,avx512vl,avx512f,bmi2"))) +#define LIBYUV_TARGET_AVX512VBMI \ + __attribute__((target("avx512vbmi,avx512bw,avx512vl,avx512f,bmi2"))) +#define LIBYUV_TARGET_AVX512VNNI \ + __attribute__((target("avx512vnni,avx512bw,avx512vl,avx512f,bmi2"))) +#define LIBYUV_TARGET_AVX512VNNIVBMI \ + __attribute__(( \ + target("avx512vnni,avx512vbmi,avx512bw,avx512vl,avx512f,bmi2"))) +#elif !defined(LIBYUV_ENABLE_ROWWIN) && \ + !(defined(_MSC_VER) && !defined(__clang__)) +#define LIBYUV_TARGET_AVX512BW +#define LIBYUV_TARGET_AVX512VBMI +#define LIBYUV_TARGET_AVX512VNNI +#define LIBYUV_TARGET_AVX512VNNIVBMI +#endif + +// clang >= 3.4.0 required for AVX2. +#if defined(__clang__) && !defined(LIBYUV_ENABLE_ROWWIN) && \ + (defined(__x86_64__) || defined(__i386__)) +#if (__clang_major__ > 3) || (__clang_major__ == 3 && (__clang_minor__ >= 4)) +#define CLANG_HAS_AVX2 1 +#endif // clang >= 3.4 +#endif // __clang__ + +// clang >= 7.0.0 required for AVX512. +#if defined(__clang__) && !defined(LIBYUV_ENABLE_ROWWIN) && \ + (defined(__x86_64__) || defined(__i386__)) +// clang in xcode follows a different versioning scheme. +// TODO(fbarchard): fix xcode 9 ios b/789. +#if (__clang_major__ >= 7) && !defined(__APPLE__) +#define CLANG_HAS_AVX512 1 +#endif // clang >= 7 +#endif // __clang__ + +// Visual C 2012 (or clang >= 3.4 with LIBYUV_ENABLE_ROWWIN) required for AVX2. +#if ((defined(_M_IX86) || defined(_M_X64)) && !defined(__clang__) && \ + defined(_MSC_VER) && _MSC_VER >= 1700) || \ + (defined(LIBYUV_ENABLE_ROWWIN) && defined(__clang__) && \ + (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || \ + defined(_M_IX86)) && \ + ((__clang_major__ > 3) || \ + (__clang_major__ == 3 && (__clang_minor__ >= 4)))) +#define VISUALC_HAS_AVX2 1 +#endif // VisualStudio >= 2012 + +// Visual C 2019 (or clang >= 7 with LIBYUV_ENABLE_ROWWIN) required for AVX512. +#if (defined(_M_X64) || defined(__x86_64__)) && \ + ((!defined(__clang__) && defined(_MSC_VER) && _MSC_VER >= 1920) || \ + (defined(LIBYUV_ENABLE_ROWWIN) && defined(__clang__) && \ + (__clang_major__ >= 7) && !defined(__APPLE__))) +#define VISUALC_HAS_AVX512 1 +#endif // VisualStudio >= 2019 + +#if defined(LIBYUV_ENABLE_SME) +#undef LIBYUV_DISABLE_SME +#endif + +// Clang 18+ required for SME due to needing __arm_tpidr2_save from compiler-rt, +// only enabled on Linux and Android (both define __linux__) for now. +#if !defined(LIBYUV_DISABLE_SME) && defined(__aarch64__) && \ + defined(__linux__) && defined(__clang__) && (__clang_major__ >= 18) +#define CLANG_HAS_SME 1 +#endif + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // INCLUDE_LIBYUV_CPU_SUPPORT_H_ diff --git a/libs/libyuv/include/libyuv/loongson_intrinsics.h b/libs/libyuv/include/libyuv/loongson_intrinsics.h new file mode 100644 index 0000000000..7dd44c5759 --- /dev/null +++ b/libs/libyuv/include/libyuv/loongson_intrinsics.h @@ -0,0 +1,14 @@ +/* + * Copyright 2022 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef INCLUDE_LIBYUV_LOONGSON_INTRINSICS_H_ +#define INCLUDE_LIBYUV_LOONGSON_INTRINSICS_H_ + +#endif // INCLUDE_LIBYUV_LOONGSON_INTRINSICS_H_ diff --git a/libs/libyuv/include/libyuv/macros_msa.h b/libs/libyuv/include/libyuv/macros_msa.h deleted file mode 100644 index 29997ce11f..0000000000 --- a/libs/libyuv/include/libyuv/macros_msa.h +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright 2016 The LibYuv Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef INCLUDE_LIBYUV_MACROS_MSA_H_ -#define INCLUDE_LIBYUV_MACROS_MSA_H_ - -#if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) -#include -#include - -#if (__mips_isa_rev >= 6) -#define LW(psrc) \ - ({ \ - const uint8_t* psrc_lw_m = (const uint8_t*)(psrc); \ - uint32_t val_m; \ - asm volatile("lw %[val_m], %[psrc_lw_m] \n" \ - : [val_m] "=r"(val_m) \ - : [psrc_lw_m] "m"(*psrc_lw_m)); \ - val_m; \ - }) - -#if (__mips == 64) -#define LD(psrc) \ - ({ \ - const uint8_t* psrc_ld_m = (const uint8_t*)(psrc); \ - uint64_t val_m = 0; \ - asm volatile("ld %[val_m], %[psrc_ld_m] \n" \ - : [val_m] "=r"(val_m) \ - : [psrc_ld_m] "m"(*psrc_ld_m)); \ - val_m; \ - }) -#else // !(__mips == 64) -#define LD(psrc) \ - ({ \ - const uint8_t* psrc_ld_m = (const uint8_t*)(psrc); \ - uint32_t val0_m, val1_m; \ - uint64_t val_m = 0; \ - val0_m = LW(psrc_ld_m); \ - val1_m = LW(psrc_ld_m + 4); \ - val_m = (uint64_t)(val1_m); /* NOLINT */ \ - val_m = (uint64_t)((val_m << 32) & 0xFFFFFFFF00000000); /* NOLINT */ \ - val_m = (uint64_t)(val_m | (uint64_t)val0_m); /* NOLINT */ \ - val_m; \ - }) -#endif // (__mips == 64) - -#define SW(val, pdst) \ - ({ \ - uint8_t* pdst_sw_m = (uint8_t*)(pdst); /* NOLINT */ \ - uint32_t val_m = (val); \ - asm volatile("sw %[val_m], %[pdst_sw_m] \n" \ - : [pdst_sw_m] "=m"(*pdst_sw_m) \ - : [val_m] "r"(val_m)); \ - }) - -#if (__mips == 64) -#define SD(val, pdst) \ - ({ \ - uint8_t* pdst_sd_m = (uint8_t*)(pdst); /* NOLINT */ \ - uint64_t val_m = (val); \ - asm volatile("sd %[val_m], %[pdst_sd_m] \n" \ - : [pdst_sd_m] "=m"(*pdst_sd_m) \ - : [val_m] "r"(val_m)); \ - }) -#else // !(__mips == 64) -#define SD(val, pdst) \ - ({ \ - uint8_t* pdst_sd_m = (uint8_t*)(pdst); /* NOLINT */ \ - uint32_t val0_m, val1_m; \ - val0_m = (uint32_t)((val)&0x00000000FFFFFFFF); \ - val1_m = (uint32_t)(((val) >> 32) & 0x00000000FFFFFFFF); \ - SW(val0_m, pdst_sd_m); \ - SW(val1_m, pdst_sd_m + 4); \ - }) -#endif // !(__mips == 64) -#else // !(__mips_isa_rev >= 6) -#define LW(psrc) \ - ({ \ - const uint8_t* psrc_lw_m = (const uint8_t*)(psrc); \ - uint32_t val_m; \ - asm volatile("ulw %[val_m], %[psrc_lw_m] \n" \ - : [val_m] "=r"(val_m) \ - : [psrc_lw_m] "m"(*psrc_lw_m)); \ - val_m; \ - }) - -#if (__mips == 64) -#define LD(psrc) \ - ({ \ - const uint8_t* psrc_ld_m = (const uint8_t*)(psrc); \ - uint64_t val_m = 0; \ - asm volatile("uld %[val_m], %[psrc_ld_m] \n" \ - : [val_m] "=r"(val_m) \ - : [psrc_ld_m] "m"(*psrc_ld_m)); \ - val_m; \ - }) -#else // !(__mips == 64) -#define LD(psrc) \ - ({ \ - const uint8_t* psrc_ld_m = (const uint8_t*)(psrc); \ - uint32_t val0_m, val1_m; \ - uint64_t val_m = 0; \ - val0_m = LW(psrc_ld_m); \ - val1_m = LW(psrc_ld_m + 4); \ - val_m = (uint64_t)(val1_m); /* NOLINT */ \ - val_m = (uint64_t)((val_m << 32) & 0xFFFFFFFF00000000); /* NOLINT */ \ - val_m = (uint64_t)(val_m | (uint64_t)val0_m); /* NOLINT */ \ - val_m; \ - }) -#endif // (__mips == 64) - -#define SW(val, pdst) \ - ({ \ - uint8_t* pdst_sw_m = (uint8_t*)(pdst); /* NOLINT */ \ - uint32_t val_m = (val); \ - asm volatile("usw %[val_m], %[pdst_sw_m] \n" \ - : [pdst_sw_m] "=m"(*pdst_sw_m) \ - : [val_m] "r"(val_m)); \ - }) - -#define SD(val, pdst) \ - ({ \ - uint8_t* pdst_sd_m = (uint8_t*)(pdst); /* NOLINT */ \ - uint32_t val0_m, val1_m; \ - val0_m = (uint32_t)((val)&0x00000000FFFFFFFF); \ - val1_m = (uint32_t)(((val) >> 32) & 0x00000000FFFFFFFF); \ - SW(val0_m, pdst_sd_m); \ - SW(val1_m, pdst_sd_m + 4); \ - }) -#endif // (__mips_isa_rev >= 6) - -// TODO(fbarchard): Consider removing __VAR_ARGS versions. -#define LD_B(RTYPE, psrc) *((RTYPE*)(psrc)) /* NOLINT */ -#define LD_UB(...) LD_B(const v16u8, __VA_ARGS__) - -#define ST_B(RTYPE, in, pdst) *((RTYPE*)(pdst)) = (in) /* NOLINT */ -#define ST_UB(...) ST_B(v16u8, __VA_ARGS__) - -#define ST_H(RTYPE, in, pdst) *((RTYPE*)(pdst)) = (in) /* NOLINT */ -#define ST_UH(...) ST_H(v8u16, __VA_ARGS__) - -/* Description : Load two vectors with 16 'byte' sized elements - Arguments : Inputs - psrc, stride - Outputs - out0, out1 - Return Type - as per RTYPE - Details : Load 16 byte elements in 'out0' from (psrc) - Load 16 byte elements in 'out1' from (psrc + stride) -*/ -#define LD_B2(RTYPE, psrc, stride, out0, out1) \ - { \ - out0 = LD_B(RTYPE, (psrc)); \ - out1 = LD_B(RTYPE, (psrc) + stride); \ - } -#define LD_UB2(...) LD_B2(const v16u8, __VA_ARGS__) - -#define LD_B4(RTYPE, psrc, stride, out0, out1, out2, out3) \ - { \ - LD_B2(RTYPE, (psrc), stride, out0, out1); \ - LD_B2(RTYPE, (psrc) + 2 * stride, stride, out2, out3); \ - } -#define LD_UB4(...) LD_B4(const v16u8, __VA_ARGS__) - -/* Description : Store two vectors with stride each having 16 'byte' sized - elements - Arguments : Inputs - in0, in1, pdst, stride - Details : Store 16 byte elements from 'in0' to (pdst) - Store 16 byte elements from 'in1' to (pdst + stride) -*/ -#define ST_B2(RTYPE, in0, in1, pdst, stride) \ - { \ - ST_B(RTYPE, in0, (pdst)); \ - ST_B(RTYPE, in1, (pdst) + stride); \ - } -#define ST_UB2(...) ST_B2(v16u8, __VA_ARGS__) - -#define ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride) \ - { \ - ST_B2(RTYPE, in0, in1, (pdst), stride); \ - ST_B2(RTYPE, in2, in3, (pdst) + 2 * stride, stride); \ - } -#define ST_UB4(...) ST_B4(v16u8, __VA_ARGS__) - -/* Description : Store vectors of 8 halfword elements with stride - Arguments : Inputs - in0, in1, pdst, stride - Details : Store 8 halfword elements from 'in0' to (pdst) - Store 8 halfword elements from 'in1' to (pdst + stride) -*/ -#define ST_H2(RTYPE, in0, in1, pdst, stride) \ - { \ - ST_H(RTYPE, in0, (pdst)); \ - ST_H(RTYPE, in1, (pdst) + stride); \ - } -#define ST_UH2(...) ST_H2(v8u16, __VA_ARGS__) - -// TODO(fbarchard): Consider using __msa_vshf_b and __msa_ilvr_b directly. -/* Description : Shuffle byte vector elements as per mask vector - Arguments : Inputs - in0, in1, in2, in3, mask0, mask1 - Outputs - out0, out1 - Return Type - as per RTYPE - Details : Byte elements from 'in0' & 'in1' are copied selectively to - 'out0' as per control vector 'mask0' -*/ -#define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) \ - { \ - out0 = (RTYPE)__msa_vshf_b((v16i8)mask0, (v16i8)in1, (v16i8)in0); \ - out1 = (RTYPE)__msa_vshf_b((v16i8)mask1, (v16i8)in3, (v16i8)in2); \ - } -#define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__) - -/* Description : Interleave both left and right half of input vectors - Arguments : Inputs - in0, in1 - Outputs - out0, out1 - Return Type - as per RTYPE - Details : Right half of byte elements from 'in0' and 'in1' are - interleaved and written to 'out0' -*/ -#define ILVRL_B2(RTYPE, in0, in1, out0, out1) \ - { \ - out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1); \ - out1 = (RTYPE)__msa_ilvl_b((v16i8)in0, (v16i8)in1); \ - } -#define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__) - -#endif /* !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) */ - -#endif // INCLUDE_LIBYUV_MACROS_MSA_H_ diff --git a/libs/libyuv/include/libyuv/mjpeg_decoder.h b/libs/libyuv/include/libyuv/mjpeg_decoder.h index 275f8d4c18..2dc60a2751 100644 --- a/libs/libyuv/include/libyuv/mjpeg_decoder.h +++ b/libs/libyuv/include/libyuv/mjpeg_decoder.h @@ -11,6 +11,9 @@ #ifndef INCLUDE_LIBYUV_MJPEG_DECODER_H_ #define INCLUDE_LIBYUV_MJPEG_DECODER_H_ +#include +#include + #include "libyuv/basic_types.h" #ifdef __cplusplus @@ -26,7 +29,7 @@ namespace libyuv { extern "C" { #endif -LIBYUV_BOOL ValidateJpeg(const uint8_t* sample, size_t sample_size); +int ValidateJpeg(const uint8_t* sample, size_t sample_size); #ifdef __cplusplus } // extern "C" @@ -81,11 +84,11 @@ class LIBYUV_API MJpegDecoder { // Loads a new frame, reads its headers, and determines the uncompressed // image format. - // Returns LIBYUV_TRUE if image looks valid and format is supported. - // If return value is LIBYUV_TRUE, then the values for all the following + // Returns true if image looks valid and format is supported. + // If return value is true, then the values for all the following // getters are populated. // src_len is the size of the compressed mjpeg frame in bytes. - LIBYUV_BOOL LoadFrame(const uint8_t* src, size_t src_len); + bool LoadFrame(const uint8_t* src, size_t src_len); // Returns width of the last loaded frame in pixels. int GetWidth(); @@ -129,7 +132,7 @@ class LIBYUV_API MJpegDecoder { // Call this after LoadFrame() if you decide you don't want to decode it // after all. - LIBYUV_BOOL UnloadFrame(); + bool UnloadFrame(); // Decodes the entire image into a one-buffer-per-color-component format. // dst_width must match exactly. dst_height must be <= to image height; if @@ -138,16 +141,16 @@ class LIBYUV_API MJpegDecoder { // at least GetComponentSize(i). The pointers in planes are incremented // to point to after the end of the written data. // TODO(fbarchard): Add dst_x, dst_y to allow specific rect to be decoded. - LIBYUV_BOOL DecodeToBuffers(uint8_t** planes, int dst_width, int dst_height); + bool DecodeToBuffers(uint8_t** planes, int dst_width, int dst_height); // Decodes the entire image and passes the data via repeated calls to a // callback function. Each call will get the data for a whole number of // image scanlines. // TODO(fbarchard): Add dst_x, dst_y to allow specific rect to be decoded. - LIBYUV_BOOL DecodeToCallback(CallbackFunction fn, - void* opaque, - int dst_width, - int dst_height); + bool DecodeToCallback(CallbackFunction fn, + void* opaque, + int dst_width, + int dst_height); // The helper function which recognizes the jpeg sub-sampling type. static JpegSubsamplingType JpegSubsamplingTypeHelper( @@ -159,13 +162,11 @@ class LIBYUV_API MJpegDecoder { void AllocOutputBuffers(int num_outbufs); void DestroyOutputBuffers(); - LIBYUV_BOOL StartDecode(); - LIBYUV_BOOL FinishDecode(); + bool StartDecode(); + bool FinishDecode(); void SetScanlinePointers(uint8_t** data); - LIBYUV_BOOL DecodeImcuRow(); - - int GetComponentScanlinePadding(int component); + bool DecodeImcuRow(); // A buffer holding the input data for a frame. Buffer buf_; @@ -175,9 +176,9 @@ class LIBYUV_API MJpegDecoder { jpeg_source_mgr* source_mgr_; SetJmpErrorMgr* error_mgr_; - // LIBYUV_TRUE iff at least one component has scanline padding. (i.e., + // true iff at least one component has scanline padding. (i.e., // GetComponentScanlinePadding() != 0.) - LIBYUV_BOOL has_scanline_padding_; + bool has_scanline_padding_; // Temporaries used to point to scanline outputs. int num_outbufs_; // Outermost size of all arrays below. diff --git a/libs/libyuv/include/libyuv/planar_functions.h b/libs/libyuv/include/libyuv/planar_functions.h index 50fe5f681d..6306cd75e3 100644 --- a/libs/libyuv/include/libyuv/planar_functions.h +++ b/libs/libyuv/include/libyuv/planar_functions.h @@ -11,6 +11,9 @@ #ifndef INCLUDE_LIBYUV_PLANAR_FUNCTIONS_H_ #define INCLUDE_LIBYUV_PLANAR_FUNCTIONS_H_ +#include +#include + #include "libyuv/basic_types.h" // TODO(fbarchard): Remove the following headers includes. @@ -22,24 +25,6 @@ namespace libyuv { extern "C" { #endif -// TODO(fbarchard): Move cpu macros to row.h -#if defined(__pnacl__) || defined(__CLR_VER) || \ - (defined(__native_client__) && defined(__x86_64__)) || \ - (defined(__i386__) && !defined(__SSE__) && !defined(__clang__)) -#define LIBYUV_DISABLE_X86 -#endif -// MemorySanitizer does not support assembly code yet. http://crbug.com/344505 -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) -#define LIBYUV_DISABLE_X86 -#endif -#endif -// The following are available on all x86 platforms: -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(_M_IX86) || defined(__x86_64__) || defined(__i386__)) -#define HAS_ARGBAFFINEROW_SSE2 -#endif - // Copy a plane of data. LIBYUV_API void CopyPlane(const uint8_t* src_y, @@ -66,14 +51,28 @@ void Convert16To8Plane(const uint16_t* src_y, int width, int height); +// Convert 8 bit Y to 10/12/16 bit. +// "bits" accepts bit depths (10, 12, 16) or legacy scale values (1024, 4096, +// 65536). LIBYUV_API -void Convert8To16Plane(const uint8_t* src_y, - int src_stride_y, - uint16_t* dst_y, - int dst_stride_y, - int scale, // 1024 for 10 bits - int width, - int height); +void Convert8To16Plane( + const uint8_t* src_y, + int src_stride_y, + uint16_t* dst_y, + int dst_stride_y, + int bits, // 10, 12, 16 bits (or 1024, 4096, 65536 scale) + int width, + int height); + +LIBYUV_API +void Convert8To8Plane(const uint8_t* src_y, + int src_stride_y, + uint8_t* dst_y, + int dst_stride_y, + int scale, // 220 for Y, 225 for U,V + int bias, // 16 + int width, + int height); // Set a plane of data to a 32 bit value. LIBYUV_API @@ -83,6 +82,50 @@ void SetPlane(uint8_t* dst_y, int height, uint32_t value); +// Convert a plane of tiles of 16 x H to linear. +LIBYUV_API +int DetilePlane(const uint8_t* src_y, + int src_stride_y, + uint8_t* dst_y, + int dst_stride_y, + int width, + int height, + int tile_height); + +// Convert a plane of 16 bit tiles of 16 x H to linear. +LIBYUV_API +int DetilePlane_16(const uint16_t* src_y, + int src_stride_y, + uint16_t* dst_y, + int dst_stride_y, + int width, + int height, + int tile_height); + +// Convert a UV plane of tiles of 16 x H into linear U and V planes. +LIBYUV_API +void DetileSplitUVPlane(const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + int tile_height); + +// Convert a Y and UV plane of tiles into interlaced YUY2. +LIBYUV_API +void DetileToYUY2(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_yuy2, + int dst_stride_yuy2, + int width, + int height, + int tile_height); + // Split interleaved UV plane into separate U and V planes. LIBYUV_API void SplitUVPlane(const uint8_t* src_uv, @@ -105,6 +148,63 @@ void MergeUVPlane(const uint8_t* src_u, int width, int height); +// Split interleaved msb UV plane into separate lsb U and V planes. +LIBYUV_API +void SplitUVPlane_16(const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height, + int depth); + +// Merge separate lsb U and V planes into one interleaved msb UV plane. +LIBYUV_API +void MergeUVPlane_16(const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height, + int depth); + +// Convert lsb plane to msb plane +LIBYUV_API +void ConvertToMSBPlane_16(const uint16_t* src_y, + int src_stride_y, + uint16_t* dst_y, + int dst_stride_y, + int width, + int height, + int depth); + +// Convert msb plane to lsb plane +LIBYUV_API +void ConvertToLSBPlane_16(const uint16_t* src_y, + int src_stride_y, + uint16_t* dst_y, + int dst_stride_y, + int width, + int height, + int depth); + +// Scale U and V to half width and height and merge into interleaved UV plane. +// width and height are source size, allowing odd sizes. +// Use for converting I444 or I422 to NV12. +LIBYUV_API +void HalfMergeUVPlane(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + // Swap U and V channels in interleaved UV plane. LIBYUV_API void SwapUVPlane(const uint8_t* src_uv, @@ -140,6 +240,92 @@ void MergeRGBPlane(const uint8_t* src_r, int width, int height); +// Split interleaved ARGB plane into separate R, G, B and A planes. +// dst_a can be NULL to discard alpha plane. +LIBYUV_API +void SplitARGBPlane(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_r, + int dst_stride_r, + uint8_t* dst_g, + int dst_stride_g, + uint8_t* dst_b, + int dst_stride_b, + uint8_t* dst_a, + int dst_stride_a, + int width, + int height); + +// Merge separate R, G, B and A planes into one interleaved ARGB plane. +// src_a can be NULL to fill opaque value to alpha. +LIBYUV_API +void MergeARGBPlane(const uint8_t* src_r, + int src_stride_r, + const uint8_t* src_g, + int src_stride_g, + const uint8_t* src_b, + int src_stride_b, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + +// Merge separate 'depth' bit R, G and B planes stored in lsb +// into one interleaved XR30 plane. +// depth should in range [10, 16] +LIBYUV_API +void MergeXR30Plane(const uint16_t* src_r, + int src_stride_r, + const uint16_t* src_g, + int src_stride_g, + const uint16_t* src_b, + int src_stride_b, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height, + int depth); + +// Merge separate 'depth' bit R, G, B and A planes stored in lsb +// into one interleaved AR64 plane. +// src_a can be NULL to fill opaque value to alpha. +// depth should in range [1, 16] +LIBYUV_API +void MergeAR64Plane(const uint16_t* src_r, + int src_stride_r, + const uint16_t* src_g, + int src_stride_g, + const uint16_t* src_b, + int src_stride_b, + const uint16_t* src_a, + int src_stride_a, + uint16_t* dst_ar64, + int dst_stride_ar64, + int width, + int height, + int depth); + +// Merge separate 'depth' bit R, G, B and A planes stored in lsb +// into one interleaved ARGB plane. +// src_a can be NULL to fill opaque value to alpha. +// depth should in range [8, 16] +LIBYUV_API +void MergeARGB16To8Plane(const uint16_t* src_r, + int src_stride_r, + const uint16_t* src_g, + int src_stride_g, + const uint16_t* src_b, + int src_stride_b, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height, + int depth); + // Copy I400. Supports inverting. LIBYUV_API int I400ToI400(const uint8_t* src_y, @@ -187,6 +373,68 @@ int I444Copy(const uint8_t* src_y, int width, int height); +// Copy I210 to I210. +#define I210ToI210 I210Copy +LIBYUV_API +int I210Copy(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Copy I410 to I410. +#define I410ToI410 I410Copy +LIBYUV_API +int I410Copy(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height); + +// Copy NV12. Supports inverting. +LIBYUV_API +int NV12Copy(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + +// Copy NV21. Supports inverting. +LIBYUV_API +int NV21Copy(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_vu, + int src_stride_vu, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + int width, + int height); + // Convert YUY2 to I422. LIBYUV_API int YUY2ToI422(const uint8_t* src_yuy2, @@ -233,19 +481,22 @@ int UYVYToNV12(const uint8_t* src_uyvy, int width, int height); -// Convert NV21 to NV12. +// Convert NV12 to NV21. LIBYUV_API -int NV21ToNV12(const uint8_t* src_y, +int NV12ToNV21(const uint8_t* src_y, int src_stride_y, - const uint8_t* src_vu, - int src_stride_vu, + const uint8_t* src_uv, + int src_stride_uv, uint8_t* dst_y, int dst_stride_y, - uint8_t* dst_uv, - int dst_stride_uv, + uint8_t* dst_vu, + int dst_stride_vu, int width, int height); +// Alias +#define NV21ToNV12 NV12ToNV21 + LIBYUV_API int YUY2ToY(const uint8_t* src_yuy2, int src_stride_yuy2, @@ -254,6 +505,14 @@ int YUY2ToY(const uint8_t* src_yuy2, int width, int height); +LIBYUV_API +int UYVYToY(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_y, + int dst_stride_y, + int width, + int height); + // Convert I420 to I400. (calls CopyPlane ignoring u/v). LIBYUV_API int I420ToI400(const uint8_t* src_y, @@ -301,6 +560,22 @@ int I400Mirror(const uint8_t* src_y, int width, int height); +// Alias +#define NV12ToNV12Mirror NV12Mirror + +// NV12 mirror. +LIBYUV_API +int NV12Mirror(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); + // Alias #define ARGBToARGBMirror ARGBMirror @@ -313,56 +588,44 @@ int ARGBMirror(const uint8_t* src_argb, int width, int height); -// Convert NV12 to RGB565. +// Alias +#define RGB24ToRGB24Mirror RGB24Mirror + +// RGB24 mirror. LIBYUV_API -int NV12ToRGB565(const uint8_t* src_y, +int RGB24Mirror(const uint8_t* src_rgb24, + int src_stride_rgb24, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height); + +// Mirror a plane of data. +LIBYUV_API +void MirrorPlane(const uint8_t* src_y, int src_stride_y, - const uint8_t* src_uv, - int src_stride_uv, - uint8_t* dst_rgb565, - int dst_stride_rgb565, + uint8_t* dst_y, + int dst_stride_y, int width, int height); -// I422ToARGB is in convert_argb.h -// Convert I422 to BGRA. +// Mirror a plane of 16-bit data. LIBYUV_API -int I422ToBGRA(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_bgra, - int dst_stride_bgra, - int width, - int height); +void MirrorPlane_16(const uint16_t* src_y, + int src_stride_y, + uint16_t* dst_y, + int dst_stride_y, + int width, + int height); -// Convert I422 to ABGR. +// Mirror a plane of UV data. LIBYUV_API -int I422ToABGR(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_abgr, - int dst_stride_abgr, - int width, - int height); - -// Convert I422 to RGBA. -LIBYUV_API -int I422ToRGBA(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgba, - int dst_stride_rgba, - int width, - int height); +void MirrorUVPlane(const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height); // Alias #define RGB24ToRAW RAWToRGB24 @@ -511,6 +774,10 @@ int ARGBPolynomial(const uint8_t* src_argb, // Convert plane of 16 bit shorts to half floats. // Source values are multiplied by scale before storing as half float. +// +// Note: Unlike other libyuv functions that operate on uint16_t buffers, the +// src_stride_y and dst_stride_y parameters of HalfFloatPlane() are in bytes, +// not in units of uint16_t. LIBYUV_API int HalfFloatPlane(const uint16_t* src_y, int src_stride_y, @@ -575,15 +842,6 @@ int ARGBCopyYToAlpha(const uint8_t* src_y, int width, int height); -typedef void (*ARGBBlendRow)(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width); - -// Get function to Alpha Blend ARGB pixels and store to destination. -LIBYUV_API -ARGBBlendRow GetARGBBlend(void); - // Alpha Blend ARGB images and store to destination. // Source is pre-multiplied by alpha using ARGBAttenuate. // Alpha of destination is set to 255. @@ -597,6 +855,18 @@ int ARGBBlend(const uint8_t* src_argb0, int width, int height); +// Alpha Blend unattenuated ARGB images and store to destination. +// Source and destination are not pre-multiplied by alpha. +LIBYUV_API +int ARGBAlphaBlend(const uint8_t* src_argb0, + int src_stride_argb0, + const uint8_t* src_argb1, + int src_stride_argb1, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height); + // Alpha Blend plane and store to destination. // Source is not pre-multiplied by alpha. LIBYUV_API @@ -671,6 +941,17 @@ int ARGBSubtract(const uint8_t* src_argb0, int width, int height); +// Bitwise OR ARGB image with a specified ARGB value (e.g. 0xff000000 to force +// opaque alpha). +LIBYUV_API +int ARGBOr(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height, + uint32_t value); + // Convert I422 to YUY2. LIBYUV_API int I422ToYUY2(const uint8_t* src_y, @@ -743,6 +1024,19 @@ int ARGBBlur(const uint8_t* src_argb, int height, int radius); +// Gaussian 5x5 blur a float plane. +// Coefficients of 1, 4, 6, 4, 1. +// Each destination pixel is a blur of the 5x5 +// pixels from the source. +// Source edges are clamped. +LIBYUV_API +int GaussPlane_F32(const float* src, + int src_stride, + float* dst, + int dst_stride, + int width, + int height); + // Multiply ARGB image by ARGB value. LIBYUV_API int ARGBShade(const uint8_t* src_argb, @@ -768,6 +1062,21 @@ int InterpolatePlane(const uint8_t* src0, int height, int interpolation); +// Interpolate between two images using specified amount of interpolation +// (0 to 255) and store to destination. +// 'interpolation' is specified as 8 bit fraction where 0 means 100% src0 +// and 255 means 1% src0 and 99% src1. +LIBYUV_API +int InterpolatePlane_16(const uint16_t* src0, + int src_stride0, // measured in 16 bit pixels + const uint16_t* src1, + int src_stride1, + uint16_t* dst, + int dst_stride, + int width, + int height, + int interpolation); + // Interpolate between two ARGB images using specified amount of interpolation // Internally calls InterpolatePlane with width * 4 (bpp). LIBYUV_API @@ -807,33 +1116,28 @@ int I420Interpolate(const uint8_t* src0_y, int height, int interpolation); -// Row function for copying pixels from a source with a slope to a row -// of destination. Useful for scaling, rotation, mirror, texture mapping. -LIBYUV_API -void ARGBAffineRow_C(const uint8_t* src_argb, - int src_argb_stride, - uint8_t* dst_argb, - const float* uv_dudv, - int width); -// TODO(fbarchard): Move ARGBAffineRow_SSE2 to row.h -LIBYUV_API -void ARGBAffineRow_SSE2(const uint8_t* src_argb, - int src_argb_stride, - uint8_t* dst_argb, - const float* uv_dudv, - int width); - // Shuffle ARGB channel order. e.g. BGRA to ARGB. -// shuffler is 16 bytes and must be aligned. +// shuffler is 16 bytes. LIBYUV_API -int ARGBShuffle(const uint8_t* src_bgra, - int src_stride_bgra, +int ARGBShuffle(const uint8_t* src_argb, + int src_stride_argb, uint8_t* dst_argb, int dst_stride_argb, const uint8_t* shuffler, int width, int height); +// Shuffle AR64 channel order. e.g. AR64 to AB64. +// shuffler is 16 bytes. +LIBYUV_API +int AR64Shuffle(const uint16_t* src_ar64, + int src_stride_ar64, + uint16_t* dst_ar64, + int dst_stride_ar64, + const uint8_t* shuffler, + int width, + int height); + // Sobel ARGB effect with planar output. LIBYUV_API int ARGBSobelToPlane(const uint8_t* src_argb, diff --git a/libs/libyuv/include/libyuv/rotate.h b/libs/libyuv/include/libyuv/rotate.h index c64e0216d5..4b1278d4b1 100644 --- a/libs/libyuv/include/libyuv/rotate.h +++ b/libs/libyuv/include/libyuv/rotate.h @@ -11,6 +11,8 @@ #ifndef INCLUDE_LIBYUV_ROTATE_H_ #define INCLUDE_LIBYUV_ROTATE_H_ +#include + #include "libyuv/basic_types.h" #ifdef __cplusplus @@ -49,6 +51,24 @@ int I420Rotate(const uint8_t* src_y, int height, enum RotationMode mode); +// Rotate I422 frame. +LIBYUV_API +int I422Rotate(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode mode); + // Rotate I444 frame. LIBYUV_API int I444Rotate(const uint8_t* src_y, @@ -67,6 +87,60 @@ int I444Rotate(const uint8_t* src_y, int height, enum RotationMode mode); +// Rotate I010 frame. +LIBYUV_API +int I010Rotate(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode mode); + +// Rotate I210 frame. +LIBYUV_API +int I210Rotate(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode mode); + +// Rotate I410 frame. +LIBYUV_API +int I410Rotate(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode mode); + // Rotate NV12 input and store in I420. LIBYUV_API int NV12ToI420Rotate(const uint8_t* src_y, @@ -83,6 +157,26 @@ int NV12ToI420Rotate(const uint8_t* src_y, int height, enum RotationMode mode); +// Convert Android420 to I420 with rotation. +// "rotation" can be 0, 90, 180 or 270. +LIBYUV_API +int Android420ToI420Rotate(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + int src_pixel_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode rotation); + // Rotate a plane by 0, 90, 180, or 270. LIBYUV_API int RotatePlane(const uint8_t* src, @@ -118,39 +212,61 @@ void RotatePlane270(const uint8_t* src, int width, int height); +// Rotate a plane by 0, 90, 180, or 270. LIBYUV_API -void RotateUV90(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width, - int height); +int RotatePlane_16(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height, + enum RotationMode mode); // Rotations for when U and V are interleaved. -// These functions take one input pointer and +// These functions take one UV input pointer and // split the data into two buffers while -// rotating them. Deprecated. +// rotating them. +// width and height expected to be half size for NV12. LIBYUV_API -void RotateUV180(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width, - int height); +int SplitRotateUV(const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode mode); LIBYUV_API -void RotateUV270(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width, - int height); +void SplitRotateUV90(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height); + +LIBYUV_API +void SplitRotateUV180(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height); + +LIBYUV_API +void SplitRotateUV270(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height); // The 90 and 270 functions are based on transposes. // Doing a transpose with reversing the read/write @@ -165,14 +281,14 @@ void TransposePlane(const uint8_t* src, int height); LIBYUV_API -void TransposeUV(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width, - int height); +void SplitTransposeUV(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height); #ifdef __cplusplus } // extern "C" diff --git a/libs/libyuv/include/libyuv/rotate_argb.h b/libs/libyuv/include/libyuv/rotate_argb.h index 20432949ab..00f6c833ce 100644 --- a/libs/libyuv/include/libyuv/rotate_argb.h +++ b/libs/libyuv/include/libyuv/rotate_argb.h @@ -11,6 +11,8 @@ #ifndef INCLUDE_LIBYUV_ROTATE_ARGB_H_ #define INCLUDE_LIBYUV_ROTATE_ARGB_H_ +#include + #include "libyuv/basic_types.h" #include "libyuv/rotate.h" // For RotationMode. diff --git a/libs/libyuv/include/libyuv/rotate_row.h b/libs/libyuv/include/libyuv/rotate_row.h index 022293eef2..5caa3bdc9b 100644 --- a/libs/libyuv/include/libyuv/rotate_row.h +++ b/libs/libyuv/include/libyuv/rotate_row.h @@ -11,66 +11,133 @@ #ifndef INCLUDE_LIBYUV_ROTATE_ROW_H_ #define INCLUDE_LIBYUV_ROTATE_ROW_H_ -#include "libyuv/basic_types.h" +#include +#include + +#include "libyuv/cpu_support.h" #ifdef __cplusplus namespace libyuv { extern "C" { #endif -#if defined(__pnacl__) || defined(__CLR_VER) || \ - (defined(__native_client__) && defined(__x86_64__)) || \ - (defined(__i386__) && !defined(__SSE__) && !defined(__clang__)) -#define LIBYUV_DISABLE_X86 +// The following are available for Visual C 32/64 bit, and for clang with +// LIBYUV_ENABLE_ROWWIN, which is also enabled for MemorySanitizer. These are +// intrinsics in rotate_win.cc. +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || \ + defined(_M_IX86)) && \ + ((defined(_MSC_VER) && !defined(__clang__)) || \ + defined(LIBYUV_ENABLE_ROWWIN)) +#if defined(VISUALC_HAS_AVX2) +#define HAS_TRANSPOSEWX8_AVX2 +#define HAS_TRANSPOSEUVWX8_AVX2 +#define HAS_TRANSPOSEWX8_16_AVX2 +#define HAS_TRANSPOSEWX16_16_AVX2 +#define HAS_TRANSPOSEWX4_32_AVX2 +#define HAS_TRANSPOSEWX8_32_AVX2 +#define HAS_TRANSPOSEWXH_32_AVX2 +#define HAS_TRANSPOSEWX16_AVX2 +#define HAS_TRANSPOSEUVWX16_AVX2 #endif -#if defined(__native_client__) -#define LIBYUV_DISABLE_NEON +#if defined(VISUALC_HAS_AVX512) +#define HAS_TRANSPOSEWX16_AVX512BW +#define HAS_TRANSPOSEUVWX16_AVX512BW +#define HAS_TRANSPOSEWX32_16_AVX512BW +#define HAS_TRANSPOSEWX16_32_AVX512BW #endif -// MemorySanitizer does not support assembly code yet. http://crbug.com/344505 -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) -#define LIBYUV_DISABLE_X86 -#endif -#endif -// The following are available for Visual C and clangcl 32 bit: -#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) -#define HAS_TRANSPOSEWX8_SSSE3 -#define HAS_TRANSPOSEUVWX8_SSE2 #endif -// The following are available for GCC 32 or 64 bit: -#if !defined(LIBYUV_DISABLE_X86) && (defined(__i386__) || defined(__x86_64__)) -#define HAS_TRANSPOSEWX8_SSSE3 +// The following are available for 32/64 bit GCC and clang, as inline assembly +// in rotate_gcc.cc: +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__)) && \ + (defined(CLANG_HAS_AVX2) || defined(GCC_HAS_AVX2)) && \ + !defined(LIBYUV_ENABLE_ROWWIN) && \ + (!defined(_MSC_VER) || defined(__clang__)) +#define HAS_TRANSPOSEWX8_AVX2 +#define HAS_TRANSPOSEUVWX8_AVX2 +#define HAS_TRANSPOSEWX8_16_AVX2 +#define HAS_TRANSPOSEWX16_16_AVX2 +#define HAS_TRANSPOSEWX4_32_AVX2 +#define HAS_TRANSPOSEWX8_32_AVX2 +#define HAS_TRANSPOSEWXH_32_AVX2 +#define HAS_TRANSPOSEWX16_AVX2 +#define HAS_TRANSPOSEUVWX16_AVX2 #endif -// The following are available for 64 bit GCC: -#if !defined(LIBYUV_DISABLE_X86) && defined(__x86_64__) -#define HAS_TRANSPOSEWX8_FAST_SSSE3 -#define HAS_TRANSPOSEUVWX8_SSE2 +// The following are available for AVX512 GCC/clang x64 platforms: +#if !defined(LIBYUV_DISABLE_X86) && defined(__x86_64__) && \ + (defined(CLANG_HAS_AVX512) || defined(GCC_HAS_AVX512)) && \ + !defined(LIBYUV_ENABLE_ROWWIN) && \ + (!defined(_MSC_VER) || defined(__clang__)) +#define HAS_TRANSPOSEWX16_AVX512BW +#define HAS_TRANSPOSEUVWX16_AVX512BW +#define HAS_TRANSPOSEWX32_16_AVX512BW +#define HAS_TRANSPOSEWX16_32_AVX512BW #endif #if !defined(LIBYUV_DISABLE_NEON) && \ (defined(__ARM_NEON__) || defined(LIBYUV_NEON) || defined(__aarch64__)) +#if defined(__aarch64__) +#define HAS_TRANSPOSEWX16_NEON +#else #define HAS_TRANSPOSEWX8_NEON +#endif #define HAS_TRANSPOSEUVWX8_NEON +#define HAS_TRANSPOSEWX8_16_NEON +#define HAS_TRANSPOSEWX4_32_NEON +#define HAS_TRANSPOSEWXH_32_NEON #endif -#if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) -#define HAS_TRANSPOSEWX16_MSA -#define HAS_TRANSPOSEUVWX16_MSA +#if !defined(LIBYUV_DISABLE_SVE) && defined(__aarch64__) +#define HAS_TRANSPOSEWX8_16_SVE2 +#define HAS_TRANSPOSEWX4_32_SVE2 #endif -#if !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) -#define HAS_TRANSPOSEWX8_MMI -#define HAS_TRANSPOSEUVWX8_MMI +#if !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && \ + defined(__aarch64__) +#define HAS_TRANSPOSEWXH_SME +#define HAS_TRANSPOSEUVWXH_SME +#define HAS_TRANSPOSEWXH_16_SME +#define HAS_TRANSPOSEWXH_32_SME #endif -void TransposeWxH_C(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width, - int height); +#if !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx) +#define HAS_TRANSPOSEWX8_LSX +#define HAS_TRANSPOSEUVWX8_LSX +#define HAS_TRANSPOSEWX8_16_LSX +#define HAS_TRANSPOSEWX4_32_LSX +#endif + +#if !defined(LIBYUV_DISABLE_LASX) && defined(__loongarch_asx) +#define HAS_TRANSPOSEWX16_LASX +#define HAS_TRANSPOSEUVWX16_LASX +#define HAS_TRANSPOSEWX16_16_LASX +#define HAS_TRANSPOSEWX4_32_LASX +#endif + +#if !defined(LIBYUV_DISABLE_RVV) && defined(__riscv_vector) +#define HAS_TRANSPOSEWXH_16_RVV +#define HAS_TRANSPOSEWX4_32_RVV +#define HAS_TRANSPOSEWXH_32_RVV +#endif + +#if !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) +#define HAS_TRANSPOSEWX8_WASMSIMD +#define HAS_TRANSPOSEUVWX8_WASMSIMD +#define HAS_TRANSPOSEWX16_WASMSIMD +#define HAS_TRANSPOSEUVWX16_WASMSIMD +#define HAS_TRANSPOSEWX8_16_WASMSIMD +#define HAS_TRANSPOSEWX4_32_WASMSIMD +#endif + +#if !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) +#define HAS_TRANSPOSEWXH_HVX +#define HAS_TRANSPOSEUVWXH_HVX +#define HAS_TRANSPOSEWXH_16_HVX +#define HAS_TRANSPOSEWXH_32_HVX +#endif void TransposeWx8_C(const uint8_t* src, int src_stride, @@ -87,61 +154,99 @@ void TransposeWx8_NEON(const uint8_t* src, uint8_t* dst, int dst_stride, int width); -void TransposeWx8_SSSE3(const uint8_t* src, +void TransposeWx16_NEON(const uint8_t* src, int src_stride, uint8_t* dst, int dst_stride, int width); -void TransposeWx8_MMI(const uint8_t* src, +void TransposeWxH_SME(const uint8_t* src, int src_stride, uint8_t* dst, int dst_stride, - int width); -void TransposeWx8_Fast_SSSE3(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width); -void TransposeWx16_MSA(const uint8_t* src, + int width, + int height); +void TransposeWxH_HVX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height); +void TransposeWx8_AVX2(const uint8_t* src, int src_stride, uint8_t* dst, int dst_stride, int width); +void TransposeWx16_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); +void TransposeWx16_AVX512BW(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); +void TransposeWx8_LSX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); +void TransposeWx16_LASX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); +void TransposeWx8_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); +void TransposeWx16_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); void TransposeWx8_Any_NEON(const uint8_t* src, int src_stride, uint8_t* dst, int dst_stride, int width); -void TransposeWx8_Any_SSSE3(const uint8_t* src, +void TransposeWx16_Any_NEON(const uint8_t* src, int src_stride, uint8_t* dst, int dst_stride, int width); -void TransposeWx8_Any_MMI(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width); -void TransposeWx8_Fast_Any_SSSE3(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width); -void TransposeWx16_Any_MSA(const uint8_t* src, +void TransposeWx8_Any_AVX2(const uint8_t* src, int src_stride, uint8_t* dst, int dst_stride, int width); - -void TransposeUVWxH_C(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width, - int height); +void TransposeWx16_Any_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); +void TransposeWx8_Any_LSX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); +void TransposeWx16_Any_LASX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); +void TransposeWx8_Any_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); +void TransposeWx16_Any_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); void TransposeUVWx8_C(const uint8_t* src, int src_stride, @@ -157,13 +262,27 @@ void TransposeUVWx16_C(const uint8_t* src, uint8_t* dst_b, int dst_stride_b, int width); -void TransposeUVWx8_SSE2(const uint8_t* src, +void TransposeUVWx8_AVX2(const uint8_t* src, int src_stride, uint8_t* dst_a, int dst_stride_a, uint8_t* dst_b, int dst_stride_b, int width); +void TransposeUVWx16_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width); +void TransposeUVWx16_AVX512BW(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width); void TransposeUVWx8_NEON(const uint8_t* src, int src_stride, uint8_t* dst_a, @@ -171,22 +290,52 @@ void TransposeUVWx8_NEON(const uint8_t* src, uint8_t* dst_b, int dst_stride_b, int width); -void TransposeUVWx8_MMI(const uint8_t* src, +void TransposeUVWxH_SME(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height); +void TransposeUVWxH_HVX(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height); +void TransposeUVWx8_LSX(const uint8_t* src, int src_stride, uint8_t* dst_a, int dst_stride_a, uint8_t* dst_b, int dst_stride_b, int width); -void TransposeUVWx16_MSA(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width); +void TransposeUVWx16_LASX(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width); +void TransposeUVWx8_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width); +void TransposeUVWx16_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width); -void TransposeUVWx8_Any_SSE2(const uint8_t* src, +void TransposeUVWx8_Any_AVX2(const uint8_t* src, int src_stride, uint8_t* dst_a, int dst_stride_a, @@ -200,20 +349,266 @@ void TransposeUVWx8_Any_NEON(const uint8_t* src, uint8_t* dst_b, int dst_stride_b, int width); -void TransposeUVWx8_Any_MMI(const uint8_t* src, +void TransposeUVWx16_Any_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width); +void TransposeUVWx8_Any_LSX(const uint8_t* src, int src_stride, uint8_t* dst_a, int dst_stride_a, uint8_t* dst_b, int dst_stride_b, int width); -void TransposeUVWx16_Any_MSA(const uint8_t* src, +void TransposeUVWx16_Any_LASX(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width); +void TransposeUVWx8_Any_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width); +void TransposeUVWx16_Any_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width); + +void TransposeWx8_16_C(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx8_16_AVX2(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx16_16_AVX2(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx32_16_AVX512BW(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx8_16_NEON(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx8_16_SVE2(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWxH_16_SME(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height); +void TransposeWxH_16_RVV(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height); +void TransposeWxH_16_HVX(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height); +void TransposeWx8_16_LSX(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx16_16_LASX(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx8_16_WASMSIMD(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx8_16_Any_AVX2(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx16_16_Any_AVX2(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx8_16_Any_NEON(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx8_16_Any_LSX(const uint16_t* src, int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, + uint16_t* dst, + int dst_stride, int width); +void TransposeWx16_16_Any_LASX(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); +void TransposeWx8_16_Any_WASMSIMD(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width); + +void TransposeWxH_32_C(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height); + +void TransposeWxH_32_SME(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height); + +void TransposeWx4_32_NEON(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWxH_32_NEON(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height); + +void TransposeWx4_32_SVE2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWx4_32_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWx8_32_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWxH_32_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height); + +void TransposeWx16_32_AVX512BW(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWx4_32_RVV(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWxH_32_RVV(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height); +void TransposeWxH_32_HVX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height); + +void TransposeWx4_32_LSX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWx4_32_LASX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWx4_32_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWx4_32_C(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWx4_32_Any_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWx8_32_Any_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWx4_32_Any_LSX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWx4_32_Any_LASX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); + +void TransposeWx4_32_Any_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width); #ifdef __cplusplus } // extern "C" diff --git a/libs/libyuv/include/libyuv/row.h b/libs/libyuv/include/libyuv/row.h index 890766ff3f..8f920f202a 100644 --- a/libs/libyuv/include/libyuv/row.h +++ b/libs/libyuv/include/libyuv/row.h @@ -11,108 +11,51 @@ #ifndef INCLUDE_LIBYUV_ROW_H_ #define INCLUDE_LIBYUV_ROW_H_ -#include // For malloc. +#include // For NULL +#include +#include // For malloc #include "libyuv/basic_types.h" +#include "libyuv/cpu_support.h" #ifdef __cplusplus namespace libyuv { extern "C" { #endif -#if defined(__pnacl__) || defined(__CLR_VER) || \ - (defined(__native_client__) && defined(__x86_64__)) || \ - (defined(__i386__) && !defined(__SSE__) && !defined(__clang__)) -#define LIBYUV_DISABLE_X86 -#endif -#if defined(__native_client__) -#define LIBYUV_DISABLE_NEON -#endif -// MemorySanitizer does not support assembly code yet. http://crbug.com/344505 -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) -#define LIBYUV_DISABLE_X86 +// This module is for Visual C 32/64 bit +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || \ + defined(_M_IX86)) +#if ((defined(_MSC_VER) && !defined(__clang__)) || \ + defined(LIBYUV_ENABLE_ROWWIN)) +#define USE_ROW_WIN +#else +#define USE_ROW_GCC #endif #endif -// clang >= 3.5.0 required for Arm64. -#if defined(__clang__) && defined(__aarch64__) && !defined(LIBYUV_DISABLE_NEON) -#if (__clang_major__ < 3) || (__clang_major__ == 3 && (__clang_minor__ < 5)) -#define LIBYUV_DISABLE_NEON -#endif // clang >= 3.5 -#endif // __clang__ -// GCC >= 4.7.0 required for AVX2. -#if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) -#if (__GNUC__ > 4) || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 7)) -#define GCC_HAS_AVX2 1 -#endif // GNUC >= 4.7 -#endif // __GNUC__ - -// clang >= 3.4.0 required for AVX2. -#if defined(__clang__) && (defined(__x86_64__) || defined(__i386__)) -#if (__clang_major__ > 3) || (__clang_major__ == 3 && (__clang_minor__ >= 4)) -#define CLANG_HAS_AVX2 1 -#endif // clang >= 3.4 -#endif // __clang__ - -// clang >= 6.0.0 required for AVX512. -#if defined(__clang__) && (defined(__x86_64__) || defined(__i386__)) -// clang in xcode follows a different versioning scheme. -// TODO(fbarchard): fix xcode 9 ios b/789. -#if (__clang_major__ >= 7) && !defined(__APPLE__) -#define CLANG_HAS_AVX512 1 -#endif // clang >= 7 -#endif // __clang__ - -// Visual C 2012 required for AVX2. -#if defined(_M_IX86) && !defined(__clang__) && defined(_MSC_VER) && \ - _MSC_VER >= 1700 -#define VISUALC_HAS_AVX2 1 -#endif // VisualStudio >= 2012 - -// The following are available on all x86 platforms: -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(_M_IX86) || defined(__x86_64__) || defined(__i386__)) +// The following are available on clang x86 platforms: +#if defined(USE_ROW_GCC) // Conversions: -#define HAS_ABGRTOUVROW_SSSE3 -#define HAS_ABGRTOYROW_SSSE3 -#define HAS_ARGB1555TOARGBROW_SSE2 -#define HAS_ARGB4444TOARGBROW_SSE2 #define HAS_ARGBEXTRACTALPHAROW_SSE2 -#define HAS_ARGBSETROW_X86 #define HAS_ARGBSHUFFLEROW_SSSE3 -#define HAS_ARGBTOARGB1555ROW_SSE2 -#define HAS_ARGBTOARGB4444ROW_SSE2 #define HAS_ARGBTORAWROW_SSSE3 #define HAS_ARGBTORGB24ROW_SSSE3 -#define HAS_ARGBTORGB565DITHERROW_SSE2 -#define HAS_ARGBTORGB565ROW_SSE2 -#define HAS_ARGBTOUV444ROW_SSSE3 -#define HAS_ARGBTOUVJROW_SSSE3 -#define HAS_ARGBTOUVROW_SSSE3 -#define HAS_ARGBTOYJROW_SSSE3 -#define HAS_ARGBTOYROW_SSSE3 -#define HAS_BGRATOUVROW_SSSE3 -#define HAS_BGRATOYROW_SSSE3 #define HAS_COPYROW_ERMS #define HAS_COPYROW_SSE2 -#define HAS_H422TOARGBROW_SSSE3 -#define HAS_HALFFLOATROW_SSE2 -#define HAS_I400TOARGBROW_SSE2 -#define HAS_I422TOARGB1555ROW_SSSE3 -#define HAS_I422TOARGB4444ROW_SSSE3 #define HAS_I422TOARGBROW_SSSE3 #define HAS_I422TORGB24ROW_SSSE3 -#define HAS_I422TORGB565ROW_SSSE3 #define HAS_I422TORGBAROW_SSSE3 +#define HAS_I422TORGB565ROW_SSSE3 +#define HAS_I422TOARGB1555ROW_SSSE3 +#define HAS_I422TOARGB4444ROW_SSSE3 #define HAS_I422TOUYVYROW_SSE2 #define HAS_I422TOYUY2ROW_SSE2 #define HAS_I444TOARGBROW_SSSE3 -#define HAS_J400TOARGBROW_SSE2 -#define HAS_J422TOARGBROW_SSSE3 +#define HAS_I444TORGB24ROW_SSSE3 #define HAS_MERGEUVROW_SSE2 #define HAS_MIRRORROW_SSSE3 -#define HAS_MIRRORUVROW_SSSE3 #define HAS_NV12TOARGBROW_SSSE3 #define HAS_NV12TORGB24ROW_SSSE3 #define HAS_NV12TORGB565ROW_SSSE3 @@ -120,18 +63,10 @@ extern "C" { #define HAS_NV21TORGB24ROW_SSSE3 #define HAS_RAWTOARGBROW_SSSE3 #define HAS_RAWTORGB24ROW_SSSE3 -#define HAS_RAWTOYROW_SSSE3 #define HAS_RGB24TOARGBROW_SSSE3 -#define HAS_RGB24TOYROW_SSSE3 -#define HAS_RGB565TOARGBROW_SSE2 -#define HAS_RGBATOUVROW_SSSE3 -#define HAS_RGBATOYROW_SSSE3 #define HAS_SETROW_ERMS -#define HAS_SETROW_X86 #define HAS_SPLITUVROW_SSE2 #define HAS_UYVYTOARGBROW_SSSE3 -#define HAS_UYVYTOUV422ROW_SSE2 -#define HAS_UYVYTOUVROW_SSE2 #define HAS_UYVYTOYROW_SSE2 #define HAS_YUY2TOARGBROW_SSSE3 #define HAS_YUY2TOUV422ROW_SSE2 @@ -140,42 +75,17 @@ extern "C" { // Effects: #define HAS_ARGBADDROW_SSE2 -#define HAS_ARGBAFFINEROW_SSE2 -#define HAS_ARGBATTENUATEROW_SSSE3 -#define HAS_ARGBBLENDROW_SSSE3 -#define HAS_ARGBCOLORMATRIXROW_SSSE3 -#define HAS_ARGBCOLORTABLEROW_X86 +#define HAS_ARGBALPHABLENDROW_SSSE3 #define HAS_ARGBCOPYALPHAROW_SSE2 #define HAS_ARGBCOPYYTOALPHAROW_SSE2 -#define HAS_ARGBGRAYROW_SSSE3 -#define HAS_ARGBLUMACOLORTABLEROW_SSSE3 #define HAS_ARGBMIRRORROW_SSE2 #define HAS_ARGBMULTIPLYROW_SSE2 +#define HAS_ARGBORROW_SSE2 #define HAS_ARGBPOLYNOMIALROW_SSE2 -#define HAS_ARGBQUANTIZEROW_SSE2 -#define HAS_ARGBSEPIAROW_SSSE3 -#define HAS_ARGBSHADEROW_SSE2 #define HAS_ARGBSUBTRACTROW_SSE2 -#define HAS_ARGBUNATTENUATEROW_SSE2 #define HAS_BLENDPLANEROW_SSSE3 -#define HAS_COMPUTECUMULATIVESUMROW_SSE2 -#define HAS_CUMULATIVESUMTOAVERAGEROW_SSE2 -#define HAS_INTERPOLATEROW_SSSE3 -#define HAS_RGBCOLORTABLEROW_X86 -#define HAS_SOBELROW_SSE2 -#define HAS_SOBELTOPLANEROW_SSE2 -#define HAS_SOBELXROW_SSE2 -#define HAS_SOBELXYROW_SSE2 -#define HAS_SOBELYROW_SSE2 - -// The following functions fail on gcc/clang 32 bit with fpic and framepointer. -// caveat: clangcl uses row_win.cc which works. -#if defined(__x86_64__) || !defined(__pic__) || defined(__clang__) || \ - defined(_MSC_VER) -// TODO(fbarchard): fix build error on android_full_debug=1 -// https://code.google.com/p/libyuv/issues/detail?id=517 #define HAS_I422ALPHATOARGBROW_SSSE3 -#endif +#define HAS_I444ALPHATOARGBROW_SSSE3 #endif // The following are available on all x86 platforms, but @@ -183,167 +93,658 @@ extern "C" { #if !defined(LIBYUV_DISABLE_X86) && \ (defined(VISUALC_HAS_AVX2) || defined(CLANG_HAS_AVX2) || \ defined(GCC_HAS_AVX2)) +#define HAS_ARGBMIRRORROW_AVX2 +#define HAS_RGB24MIRRORROW_AVX2 +#define HAS_ARGBTOUVMATRIXROW_AVX2 +#define HAS_RGBTOUVMATRIXROW_AVX2 +#define HAS_RGB565TOUVMATRIXROW_AVX2 +#define HAS_ARGB1555TOUVMATRIXROW_AVX2 +#define HAS_ARGB4444TOUVMATRIXROW_AVX2 +#define HAS_MERGEUVROW_AVX2 +#define HAS_MIRRORROW_AVX2 +#define HAS_MIRRORSPLITUVROW_AVX2 +#define HAS_MIRRORUVROW_AVX2 +#define HAS_INTERPOLATEROW_16_AVX2 +#define HAS_INTERPOLATEROW_AVX2 +#define HAS_I422TOARGBROW_AVX2 +#define HAS_NV12TOARGBROW_AVX2 +#define HAS_NV21TOARGBROW_AVX2 +#endif + +#if !defined(LIBYUV_DISABLE_X86) && defined(USE_ROW_GCC) && \ + (defined(VISUALC_HAS_AVX2) || defined(CLANG_HAS_AVX2) || \ + defined(GCC_HAS_AVX2)) #define HAS_ARGBCOPYALPHAROW_AVX2 #define HAS_ARGBCOPYYTOALPHAROW_AVX2 #define HAS_ARGBEXTRACTALPHAROW_AVX2 -#define HAS_ARGBMIRRORROW_AVX2 #define HAS_ARGBPOLYNOMIALROW_AVX2 #define HAS_ARGBSHUFFLEROW_AVX2 #define HAS_ARGBTORGB565DITHERROW_AVX2 -#define HAS_ARGBTOUVJROW_AVX2 -#define HAS_ARGBTOUVROW_AVX2 -#define HAS_ARGBTOYJROW_AVX2 -#define HAS_ARGBTOYROW_AVX2 #define HAS_COPYROW_AVX -#define HAS_H422TOARGBROW_AVX2 #define HAS_HALFFLOATROW_AVX2 -// #define HAS_HALFFLOATROW_F16C // Enable to test halffloat cast -#define HAS_I400TOARGBROW_AVX2 +#define HAS_I422ALPHATOARGBROW_AVX2 +#define HAS_I422TORGB24ROW_AVX2 +#define HAS_I422TORGBAROW_AVX2 +#define HAS_I422TORGB565ROW_AVX2 #define HAS_I422TOARGB1555ROW_AVX2 #define HAS_I422TOARGB4444ROW_AVX2 -#define HAS_I422TOARGBROW_AVX2 -#define HAS_I422TORGB24ROW_AVX2 -#define HAS_I422TORGB565ROW_AVX2 -#define HAS_I422TORGBAROW_AVX2 +#define HAS_I444ALPHATOARGBROW_AVX2 #define HAS_I444TOARGBROW_AVX2 -#define HAS_INTERPOLATEROW_AVX2 -#define HAS_J422TOARGBROW_AVX2 -#define HAS_MERGEUVROW_AVX2 -#define HAS_MIRRORROW_AVX2 -#define HAS_NV12TOARGBROW_AVX2 +#define HAS_I444TORGB24ROW_AVX2 +#define HAS_J400TOARGBROW_AVX2 #define HAS_NV12TORGB24ROW_AVX2 #define HAS_NV12TORGB565ROW_AVX2 -#define HAS_NV21TOARGBROW_AVX2 #define HAS_NV21TORGB24ROW_AVX2 #define HAS_SPLITUVROW_AVX2 #define HAS_UYVYTOARGBROW_AVX2 -#define HAS_UYVYTOUV422ROW_AVX2 -#define HAS_UYVYTOUVROW_AVX2 #define HAS_UYVYTOYROW_AVX2 #define HAS_YUY2TOARGBROW_AVX2 #define HAS_YUY2TOUV422ROW_AVX2 #define HAS_YUY2TOUVROW_AVX2 #define HAS_YUY2TOYROW_AVX2 +// #define HAS_HALFFLOATROW_F16C // Enable to test half float cast // Effects: #define HAS_ARGBADDROW_AVX2 -#define HAS_ARGBATTENUATEROW_AVX2 +#define HAS_ARGBALPHABLENDROW_AVX2 #define HAS_ARGBMULTIPLYROW_AVX2 +#define HAS_ARGBORROW_AVX2 #define HAS_ARGBSUBTRACTROW_AVX2 -#define HAS_ARGBUNATTENUATEROW_AVX2 #define HAS_BLENDPLANEROW_AVX2 - -#if defined(__x86_64__) || !defined(__pic__) || defined(__clang__) || \ - defined(_MSC_VER) -// TODO(fbarchard): fix build error on android_full_debug=1 -// https://code.google.com/p/libyuv/issues/detail?id=517 -#define HAS_I422ALPHATOARGBROW_AVX2 -#endif -#endif - -// The following are available for AVX2 Visual C and clangcl 32 bit: -// TODO(fbarchard): Port to gcc. -#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) && \ - (defined(VISUALC_HAS_AVX2) || defined(CLANG_HAS_AVX2)) -#define HAS_ARGB1555TOARGBROW_AVX2 -#define HAS_ARGB4444TOARGBROW_AVX2 -#define HAS_ARGBTOARGB1555ROW_AVX2 -#define HAS_ARGBTOARGB4444ROW_AVX2 -#define HAS_ARGBTORGB565ROW_AVX2 -#define HAS_J400TOARGBROW_AVX2 -#define HAS_RGB565TOARGBROW_AVX2 -#endif - -// The following are also available on x64 Visual C. -#if !defined(LIBYUV_DISABLE_X86) && defined(_MSC_VER) && defined(_M_X64) && \ - (!defined(__clang__) || defined(__SSSE3__)) -#define HAS_I422ALPHATOARGBROW_SSSE3 -#define HAS_I422TOARGBROW_SSSE3 #endif // The following are available for gcc/clang x86 platforms: // TODO(fbarchard): Port to Visual C -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) +#if !defined(LIBYUV_DISABLE_X86) && defined(USE_ROW_GCC) && \ + (defined(__x86_64__) || defined(__i386__)) && \ + !defined(LIBYUV_ENABLE_ROWWIN) +#define HAS_AB64TOARGBROW_SSSE3 #define HAS_ABGRTOAR30ROW_SSSE3 +#define HAS_AR64TOARGBROW_SSSE3 +#define HAS_ARGBATTENUATEROW_SSSE3 +#define HAS_ARGBTOAB64ROW_SSSE3 #define HAS_ARGBTOAR30ROW_SSSE3 +#define HAS_ARGBTOAR64ROW_SSSE3 +#define HAS_ARGBUNATTENUATEROW_SSE2 #define HAS_CONVERT16TO8ROW_SSSE3 #define HAS_CONVERT8TO16ROW_SSE2 -// I210 is for H010. 2 = 422. I for 601 vs H for 709. +#define HAS_HALFMERGEUVROW_SSSE3 +#define HAS_HALFROW_16TO8_SSSE3 +#define HAS_HALFWIDTHROW_16TO8_SSSE3 #define HAS_I210TOAR30ROW_SSSE3 #define HAS_I210TOARGBROW_SSSE3 +#define HAS_I212TOAR30ROW_SSSE3 +#define HAS_I212TOARGBROW_SSSE3 +#define HAS_I400TOARGBROW_SSE2 +#define HAS_I410TOAR30ROW_SSSE3 +#define HAS_I410TOARGBROW_SSSE3 #define HAS_I422TOAR30ROW_SSSE3 -#define HAS_MERGERGBROW_SSSE3 +#define HAS_MERGEARGBROW_SSE2 +#define HAS_MERGEXRGBROW_SSE2 +#define HAS_MIRRORSPLITUVROW_SSSE3 +#define HAS_MIRRORUVROW_SSSE3 +#define HAS_NV21TOYUV24ROW_SSSE3 +#define HAS_P210TOAR30ROW_SSSE3 +#define HAS_RGB24MIRRORROW_SSSE3 +#define HAS_P210TOARGBROW_SSSE3 +#define HAS_P410TOAR30ROW_SSSE3 +#define HAS_P410TOARGBROW_SSSE3 +#define HAS_SPLITARGBROW_SSE2 +#define HAS_SPLITARGBROW_SSSE3 +#define HAS_SPLITRGBROW_SSE41 #define HAS_SPLITRGBROW_SSSE3 +#define HAS_SPLITXRGBROW_SSE2 +#define HAS_SPLITXRGBROW_SSSE3 #define HAS_SWAPUVROW_SSSE3 +#define HAS_YUY2TONVUVROW_SSE2 +// TODO: port row_win to use 8 bit coefficients. +#define HAS_ARGBTOYMATRIXROW_SSSE3 +#define HAS_RGBTOYMATRIXROW_SSSE3 +#define HAS_ARGBTOUVMATRIXROW_SSSE3 +#define HAS_RGBTOUVMATRIXROW_SSSE3 +#define HAS_ARGBTOUV444MATRIXROW_SSSE3 +#define HAS_RGBTOUV444MATRIXROW_SSSE3 +#define HAS_I210ALPHATOARGBROW_SSSE3 +#define HAS_I410ALPHATOARGBROW_SSSE3 #endif // The following are available for AVX2 gcc/clang x86 platforms: // TODO(fbarchard): Port to Visual C -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) && \ - (defined(CLANG_HAS_AVX2) || defined(GCC_HAS_AVX2)) +#if !defined(LIBYUV_DISABLE_X86) && defined(USE_ROW_GCC) && \ + (defined(__x86_64__) || defined(__i386__)) && \ + (defined(CLANG_HAS_AVX2) || defined(GCC_HAS_AVX2)) && \ + !defined(LIBYUV_ENABLE_ROWWIN) +#define HAS_AB64TOARGBROW_AVX2 #define HAS_ABGRTOAR30ROW_AVX2 -#define HAS_ABGRTOUVROW_AVX2 -#define HAS_ABGRTOYROW_AVX2 +#define HAS_AR30TOAB30ROW_AVX2 +#define HAS_AR30TOABGRROW_AVX2 +#define HAS_AR30TOARGBROW_AVX2 +#define HAS_AR64TOARGBROW_AVX2 +#define HAS_ARGBATTENUATEROW_AVX2 +#define HAS_ARGBTOAB64ROW_AVX2 #define HAS_ARGBTOAR30ROW_AVX2 +#define HAS_ARGBTOAR64ROW_AVX2 #define HAS_ARGBTORAWROW_AVX2 #define HAS_ARGBTORGB24ROW_AVX2 +#define HAS_ARGBTORGB565ROW_AVX2 +#define HAS_ARGBTOARGB1555ROW_AVX2 +#define HAS_ARGBTOARGB4444ROW_AVX2 +#define HAS_RAWTOARGBROW_AVX2 +#define HAS_RGB24TOARGBROW_AVX2 +#define HAS_RGB565TOARGBROW_AVX2 +#define HAS_ARGB1555TOARGBROW_AVX2 +#define HAS_ARGB4444TOARGBROW_AVX2 +#define HAS_ARGBTOUV444MATRIXROW_AVX2 +#define HAS_RGBTOUV444MATRIXROW_AVX2 +#define HAS_ARGBTOYMATRIXROW_AVX2 +#define HAS_RGBTOYMATRIXROW_AVX2 +#define HAS_RGB565TOYMATRIXROW_AVX2 +#define HAS_ARGB1555TOYMATRIXROW_AVX2 +#define HAS_ARGB4444TOYMATRIXROW_AVX2 +#define HAS_ARGB1555TOUVROW_AVX2 +#define HAS_ARGB1555TOYROW_AVX2 +#define HAS_ARGB4444TOUVROW_AVX2 +#define HAS_ARGB4444TOYROW_AVX2 +#define HAS_ARGBAFFINEROW_AVX2 +#define HAS_ARGBCOLORMATRIXROW_AVX2 +#define HAS_ARGBCOLORTABLEROW_AVX2 +#define HAS_ARGBLUMACOLORTABLEROW_AVX2 +#define HAS_ARGBQUANTIZEROW_AVX2 +#define HAS_ARGBSEPIAROW_AVX2 +#define HAS_ARGBSETROW_AVX2 +#define HAS_ARGBSHADEROW_AVX2 +#define HAS_ARGBUNATTENUATEROW_AVX2 +#define HAS_ARGBBLENDROW_AVX2 +#define HAS_ARGBGRAYROW_AVX2 +#define HAS_AYUVTOUVROW_AVX2 +#define HAS_AYUVTOVUROW_AVX2 +#define HAS_AYUVTOYROW_AVX2 +#define HAS_BYTETOFLOATROW_AVX2 +#define HAS_COMPUTECUMULATIVESUMROW_AVX2 #define HAS_CONVERT16TO8ROW_AVX2 #define HAS_CONVERT8TO16ROW_AVX2 +#define HAS_CONVERT8TO8ROW_AVX2 +#define HAS_COPYROW_16_AVX2 +#define HAS_CUMULATIVESUMTOAVERAGEROW_AVX2 +#define HAS_DETILEROW_16_AVX2 +#define HAS_DETILEROW_AVX2 +#define HAS_DETILESPLITUVROW_AVX2 +#define HAS_DETILETOYUY2_AVX2 +#define HAS_DIVIDEROW_16_AVX2 +#define HAS_GAUSSCOL_AVX2 +#define HAS_GAUSSCOL_F32_AVX2 +#define HAS_GAUSSROW_AVX2 +#define HAS_GAUSSROW_F32_AVX2 +#define HAS_RGB565TOUVROW_AVX2 +#define HAS_RGB565TOYROW_AVX2 +#define HAS_RGBCOLORTABLEROW_AVX2 +#define HAS_SCALEMAXSAMPLES_AVX2 +#define HAS_SCALESAMPLES_AVX2 +#define HAS_SCALESUMSAMPLES_AVX2 +#define HAS_SETROW_AVX2 +#define HAS_SOBELROW_AVX2 +#define HAS_SOBELTOPLANEROW_AVX2 +#define HAS_SOBELXROW_AVX2 +#define HAS_SOBELXYROW_AVX2 +#define HAS_SOBELYROW_AVX2 +#define HAS_HALFMERGEUVROW_AVX2 +#define HAS_HALFROW_16_AVX2 +#define HAS_HALFROW_16TO8_AVX2 +#define HAS_HALFROW_AVX2 +#define HAS_HALFWIDTHROW_16TO8_AVX2 +#define HAS_HALFWIDTHROW_16TO8_ODD_AVX2 #define HAS_I210TOAR30ROW_AVX2 #define HAS_I210TOARGBROW_AVX2 +#define HAS_I212TOAR30ROW_AVX2 +#define HAS_I212TOARGBROW_AVX2 +#define HAS_I400TOARGBROW_AVX2 +#define HAS_I410TOAR30ROW_AVX2 +#define HAS_I410TOARGBROW_AVX2 #define HAS_I422TOAR30ROW_AVX2 +#define HAS_RAWTORGB24ROW_AVX2 +#define HAS_RAWTORGBAROW_AVX2 #define HAS_I422TOUYVYROW_AVX2 #define HAS_I422TOYUY2ROW_AVX2 +#define HAS_MERGEAR64ROW_AVX2 +#define HAS_MERGEARGB16TO8ROW_AVX2 +#define HAS_MERGEARGBROW_AVX2 +#define HAS_MERGERGBROW_AVX2 #define HAS_MERGEUVROW_16_AVX2 +#define HAS_MERGEXR30ROW_AVX2 +#define HAS_MERGEXR64ROW_AVX2 +#define HAS_MERGEXRGB16TO8ROW_AVX2 +#define HAS_MERGEXRGBROW_AVX2 #define HAS_MULTIPLYROW_16_AVX2 +#define HAS_NV21TOYUV24ROW_AVX2 +#define HAS_P210TOAR30ROW_AVX2 +#define HAS_P210TOARGBROW_AVX2 +#define HAS_P410TOAR30ROW_AVX2 +#define HAS_P410TOARGBROW_AVX2 +#define HAS_SPLITARGBROW_AVX2 +#define HAS_SPLITRGBROW_AVX2 +#define HAS_SPLITUVROW_16_AVX2 +#define HAS_SPLITXRGBROW_AVX2 #define HAS_SWAPUVROW_AVX2 -// TODO(fbarchard): Fix AVX2 version of YUV24 -// #define HAS_NV21TOYUV24ROW_AVX2 +#define HAS_UNPACKMT2T_AVX2 +#define HAS_YUY2TONVUVROW_AVX2 +#define HAS_I210ALPHATOARGBROW_AVX2 +#define HAS_I410ALPHATOARGBROW_AVX2 #endif -// The following are available for AVX512 clang x86 platforms: -// TODO(fbarchard): Port to GCC and Visual C -// TODO(fbarchard): re-enable HAS_ARGBTORGB24ROW_AVX512VBMI. Issue libyuv:789 -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) && \ - (defined(CLANG_HAS_AVX512)) -#define HAS_ARGBTORGB24ROW_AVX512VBMI +// This module is for Visual C 32/64 bit +#if !defined(LIBYUV_DISABLE_X86) && defined(USE_ROW_WIN) && \ + (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || \ + defined(_M_IX86)) && \ + ((defined(_MSC_VER) && !defined(__clang__)) || \ + defined(LIBYUV_ENABLE_ROWWIN)) +#define HAS_RAWTORGB24ROW_SSSE3 +#define HAS_ARGBALPHABLENDROW_SSSE3 +#define HAS_ARGBORROW_SSE2 +#define HAS_MIRRORSPLITUVROW_SSSE3 +#if defined(VISUALC_HAS_AVX2) +#define HAS_RAWTORGB24ROW_AVX2 +#define HAS_RAWTOARGBROW_AVX2 +#define HAS_I422TORGB24ROW_AVX2 +#define HAS_RGB24TOARGBROW_AVX2 +#define HAS_RGB565TOARGBROW_AVX2 +#define HAS_ARGB1555TOARGBROW_AVX2 +#define HAS_ARGB4444TOARGBROW_AVX2 +#define HAS_ARGBSHUFFLEROW_AVX2 +#define HAS_ARGBTORGB565ROW_AVX2 +#define HAS_ARGBTORGB565DITHERROW_AVX2 +#define HAS_ARGBTOARGB1555ROW_AVX2 +#define HAS_ARGBTOARGB4444ROW_AVX2 +#define HAS_I422TORGB565ROW_AVX2 +#define HAS_I422TOARGB1555ROW_AVX2 +#define HAS_I422TOARGB4444ROW_AVX2 +#define HAS_NV12TORGB565ROW_AVX2 +#define HAS_CONVERT8TO16ROW_AVX2 +#define HAS_CONVERT8TO8ROW_AVX2 +#define HAS_I422TOAR30ROW_AVX2 +#define HAS_AR30TOAB30ROW_AVX2 +#define HAS_AR30TOABGRROW_AVX2 +#define HAS_AR30TOARGBROW_AVX2 +#define HAS_AYUVTOUVROW_AVX2 +#define HAS_AYUVTOVUROW_AVX2 +#define HAS_AYUVTOYROW_AVX2 +#define HAS_ARGB1555TOUVROW_AVX2 +#define HAS_ARGB1555TOYROW_AVX2 +#define HAS_ARGB4444TOUVROW_AVX2 +#define HAS_ARGB4444TOYROW_AVX2 +#define HAS_ARGBAFFINEROW_AVX2 +#define HAS_ARGBCOLORMATRIXROW_AVX2 +#define HAS_ARGBCOLORTABLEROW_AVX2 +#define HAS_ARGBLUMACOLORTABLEROW_AVX2 +#define HAS_ARGBQUANTIZEROW_AVX2 +#define HAS_ARGBSEPIAROW_AVX2 +#define HAS_ARGBSETROW_AVX2 +#define HAS_ARGBSHADEROW_AVX2 +#define HAS_BYTETOFLOATROW_AVX2 +#define HAS_COPYROW_16_AVX2 +#define HAS_DETILEROW_16_AVX2 +#define HAS_DETILEROW_AVX2 +#define HAS_DETILESPLITUVROW_AVX2 +#define HAS_GAUSSROW_AVX2 +#define HAS_GAUSSROW_F32_AVX2 +#define HAS_RGB565TOUVROW_AVX2 +#define HAS_RGB565TOYROW_AVX2 +#define HAS_RGBCOLORTABLEROW_AVX2 +#define HAS_SETROW_AVX2 +#define HAS_SOBELROW_AVX2 +#define HAS_SOBELTOPLANEROW_AVX2 +#define HAS_SOBELXROW_AVX2 +#define HAS_SOBELXYROW_AVX2 +#define HAS_SOBELYROW_AVX2 +#define HAS_ARGBALPHABLENDROW_AVX2 +#define HAS_ARGBORROW_AVX2 +#define HAS_ARGBTOYMATRIXROW_AVX2 +#define HAS_RGBTOYMATRIXROW_AVX2 +#define HAS_RGB565TOYMATRIXROW_AVX2 +#define HAS_ARGB1555TOYMATRIXROW_AVX2 +#define HAS_ARGB4444TOYMATRIXROW_AVX2 +#define HAS_ARGBTOUV444MATRIXROW_AVX2 +#define HAS_RGBTOUV444MATRIXROW_AVX2 +#define HAS_J400TOARGBROW_AVX2 +#define HAS_MULTIPLYROW_16_AVX2 +#define HAS_SWAPUVROW_AVX2 +#define HAS_AB64TOARGBROW_AVX2 +#define HAS_AR64TOARGBROW_AVX2 +#define HAS_ARGBADDROW_AVX2 +#define HAS_ARGBBLENDROW_AVX2 +#define HAS_ARGBCOPYALPHAROW_AVX2 +#define HAS_ARGBGRAYROW_AVX2 +#define HAS_ARGBPOLYNOMIALROW_AVX2 +#define HAS_ARGBSUBTRACTROW_AVX2 +#define HAS_ARGBTOAB64ROW_AVX2 +#define HAS_ARGBTOAR64ROW_AVX2 +#define HAS_ARGBTORAWROW_AVX2 +#define HAS_ARGBTORGB24ROW_AVX2 +#define HAS_ARGBUNATTENUATEROW_AVX2 +#define HAS_COMPUTECUMULATIVESUMROW_AVX2 +#define HAS_CONVERT16TO8ROW_AVX2 +#define HAS_COPYROW_AVX +#define HAS_CUMULATIVESUMTOAVERAGEROW_AVX2 +#define HAS_DETILETOYUY2_AVX2 +#define HAS_DIVIDEROW_16_AVX2 +#define HAS_GAUSSCOL_AVX2 +#define HAS_GAUSSCOL_F32_AVX2 +#define HAS_HALFMERGEUVROW_AVX2 +#define HAS_HALFROW_16_AVX2 +#define HAS_HALFROW_16TO8_AVX2 +#define HAS_HALFROW_AVX2 +#define HAS_HALFWIDTHROW_16TO8_AVX2 +#define HAS_HALFWIDTHROW_16TO8_ODD_AVX2 +#define HAS_I422TOUYVYROW_AVX2 +#define HAS_I422TOYUY2ROW_AVX2 +#define HAS_I444TOARGBROW_AVX2 +#define HAS_I444TORGB24ROW_AVX2 +#define HAS_MERGEAR64ROW_AVX2 +#define HAS_MERGEARGB16TO8ROW_AVX2 +#define HAS_MERGEARGBROW_AVX2 +#define HAS_MERGERGBROW_AVX2 +#define HAS_MERGEUVROW_16_AVX2 +#define HAS_MERGEXR30ROW_AVX2 +#define HAS_MERGEXR64ROW_AVX2 +#define HAS_MERGEXRGB16TO8ROW_AVX2 +#define HAS_MERGEXRGBROW_AVX2 +#define HAS_NV12TORGB24ROW_AVX2 +#define HAS_NV21TORGB24ROW_AVX2 +#define HAS_NV21TOYUV24ROW_AVX2 +#define HAS_RAWTORGBAROW_AVX2 +#define HAS_SCALEMAXSAMPLES_AVX2 +#define HAS_SCALESAMPLES_AVX2 +#define HAS_SCALESUMSAMPLES_AVX2 +#define HAS_SPLITARGBROW_AVX2 +#define HAS_SPLITRGBROW_AVX2 +#define HAS_SPLITUVROW_16_AVX2 +#define HAS_SPLITUVROW_AVX2 +#define HAS_SPLITXRGBROW_AVX2 +#define HAS_UNPACKMT2T_AVX2 +#define HAS_UYVYTOUV422ROW_AVX2 +#define HAS_UYVYTOUVROW_AVX2 +#define HAS_UYVYTOYROW_AVX2 +#define HAS_YUY2TONVUVROW_AVX2 +#define HAS_YUY2TOUV422ROW_AVX2 +#define HAS_YUY2TOUVROW_AVX2 +#define HAS_YUY2TOYROW_AVX2 +#endif +#if defined(VISUALC_HAS_AVX512) +#define HAS_RAWTOARGBROW_AVX512BW +#define HAS_RGB24TOARGBROW_AVX512BW +#define HAS_RAWTORGB24ROW_AVX512BW +#define HAS_ARGBSHUFFLEROW_AVX512BW +#define HAS_I422TORGB24ROW_AVX512VBMI +#define HAS_RAWTORGB24ROW_AVX512VBMI +#define HAS_I422TORGB24ROW_AVX512BW +#define HAS_I422TOAR30ROW_AVX512BW +#define HAS_RGBTOYMATRIXROW_AVX512BW +#define HAS_BLENDPLANEROW_AVX512BW +#define HAS_INTERPOLATEROW_AVX512BW +#define HAS_ARGBEXTRACTALPHAROW_AVX512BW +#define HAS_ARGBCOPYYTOALPHAROW_AVX512BW +#define HAS_ARGBMIRRORROW_AVX512BW +#define HAS_RGB24MIRRORROW_AVX512VBMI +#define HAS_AYUVTOYROW_AVX512VBMI +#define HAS_AYUVTOUVROW_AVX512VBMI +#define HAS_AYUVTOVUROW_AVX512VBMI +#define HAS_AR30TOARGBROW_AVX512BW +#define HAS_AR30TOABGRROW_AVX512BW +#define HAS_AR30TOAB30ROW_AVX512BW +#define HAS_MERGEXR30ROW_10_AVX512BW +#define HAS_MIRRORROW_16_AVX512BW +#define HAS_MERGERGBROW_AVX512VBMI +#define HAS_RAWTORGBAROW_AVX512VBMI +#define HAS_NV12TOARGBROW_AVX512BW +#define HAS_NV21TOARGBROW_AVX512BW +#define HAS_NV12TORGB24ROW_AVX512VBMI +#define HAS_NV21TORGB24ROW_AVX512VBMI +#define HAS_NV21TOYUV24ROW_AVX512VBMI +#define HAS_I422ALPHATOARGBROW_AVX512BW +#define HAS_SWAPUVROW_AVX512BW +#define HAS_HALFMERGEUVROW_AVX512BW +#define HAS_INTERPOLATEROW_16_AVX512BW +#define HAS_ARGBATTENUATEROW_AVX512BW +#define HAS_ARGBMULTIPLYROW_AVX512BW +#define HAS_ARGBTOAR30ROW_AVX512BW +#define HAS_ABGRTOAR30ROW_AVX512BW +#define HAS_I400TOARGBROW_AVX512BW +#define HAS_ARGBGRAYROW_AVX512BW +#define HAS_ARGBBLENDROW_AVX512BW +#define HAS_ARGBALPHABLENDROW_AVX512BW +#define HAS_ARGBORROW_AVX512BW +#define HAS_ARGBTOYMATRIXROW_AVX512VNNI +#define HAS_ARGBTOUV444MATRIXROW_AVX512VNNI +#define HAS_ARGBTOUVMATRIXROW_AVX512VNNI +#define HAS_ARGBGRAYROW_AVX512VNNI +// AVX512VNNIVBMI requires both AVX512VNNI and AVX512VBMI. +#define HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI +#define HAS_ARGBTOUV444MATRIXROW_AVX512VNNIVBMI +#define HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI +#define HAS_I422TOARGBROW_AVX512BW +#define HAS_ARGB1555TOARGBROW_AVX512BW +#define HAS_ARGBCOLORMATRIXROW_AVX512VNNI +#define HAS_ARGBSEPIAROW_AVX512VNNI +#define HAS_ARGBTORGB565DITHERROW_AVX512BW +#define HAS_ARGBTORGB565ROW_AVX512BW +#define HAS_CONVERT8TO8ROW_AVX512BW +#define HAS_DIVIDEROW_16_AVX512BW +#define HAS_HALFFLOATROW_AVX512BW +#define HAS_I210ALPHATOARGBROW_AVX512BW +#define HAS_I210TOAR30ROW_AVX512BW +#define HAS_I210TOARGBROW_AVX512BW +#define HAS_I212TOAR30ROW_AVX512BW +#define HAS_I212TOARGBROW_AVX512BW +#define HAS_I410ALPHATOARGBROW_AVX512BW +#define HAS_I410TOAR30ROW_AVX512BW +#define HAS_I410TOARGBROW_AVX512BW +#define HAS_I422TOARGB1555ROW_AVX512BW +#define HAS_I422TOARGB4444ROW_AVX512BW +#define HAS_I422TORGB565ROW_AVX512BW +#define HAS_I422TORGBAROW_AVX512BW +#define HAS_I444ALPHATOARGBROW_AVX512BW +#define HAS_I444TOARGBROW_AVX512BW +#define HAS_I444TORGB24ROW_AVX512VBMI +#define HAS_MERGEUVROW_16_AVX512BW +#define HAS_P210TOAR30ROW_AVX512BW +#define HAS_P210TOARGBROW_AVX512BW +#define HAS_P410TOAR30ROW_AVX512BW +#define HAS_P410TOARGBROW_AVX512BW +#define HAS_UYVYTOARGBROW_AVX512BW +#define HAS_UYVYTOUVROW_AVX512BW +#define HAS_UYVYTOYROW_AVX512BW +#define HAS_YUY2TOARGBROW_AVX512BW +#define HAS_YUY2TOUVROW_AVX512BW +#define HAS_YUY2TOYROW_AVX512BW +#define HAS_ARGBTORAWROW_AVX512BW +#define HAS_ARGBTORGB24ROW_AVX512BW +#define HAS_ARGBTOUV444MATRIXROW_AVX512BW +#define HAS_ARGBTOUVMATRIXROW_AVX512BW +#define HAS_ARGBTOYMATRIXROW_AVX512BW +#define HAS_CONVERT16TO8ROW_AVX512BW +#define HAS_CONVERT8TO16ROW_AVX512BW +#define HAS_COPYROW_AVX512BW +#define HAS_HALFROW_16TO8_AVX512BW +#define HAS_HALFWIDTHROW_16TO8_AVX512BW +#define HAS_J400TOARGBROW_AVX512BW +#define HAS_MERGEUVROW_AVX512BW +#define HAS_MIRRORROW_AVX512BW +#define HAS_MIRRORUVROW_AVX512BW +#define HAS_MIRRORSPLITUVROW_AVX512BW +#define HAS_MULTIPLYROW_16_AVX512BW +#define HAS_RGBTOUV444MATRIXROW_AVX512BW +#define HAS_RGBTOUVMATRIXROW_AVX512BW +#define HAS_SPLITUVROW_AVX512BW +#endif +#endif + +// The following are available for AVX512 GCC/clang x64 platforms: +#if !defined(LIBYUV_DISABLE_X86) && defined(USE_ROW_GCC) && \ + defined(__x86_64__) && \ + (defined(CLANG_HAS_AVX512) || defined(GCC_HAS_AVX512)) +#define HAS_COPYROW_AVX512BW +#define HAS_RAWTOARGBROW_AVX512BW +#define HAS_RGB24TOARGBROW_AVX512BW +#define HAS_RAWTORGB24ROW_AVX512BW +#define HAS_RAWTORGB24ROW_AVX512VBMI +#define HAS_ARGBTORGB24ROW_AVX512BW +#define HAS_ARGBTORAWROW_AVX512BW +#define HAS_CONVERT16TO8ROW_AVX512BW +#define HAS_CONVERT8TO16ROW_AVX512BW +#define HAS_HALFROW_16TO8_AVX512BW +#define HAS_HALFWIDTHROW_16TO8_AVX512BW +#define HAS_MULTIPLYROW_16_AVX512BW +#define HAS_I422TOARGBROW_AVX512BW +#define HAS_I422TOAR30ROW_AVX512BW +#define HAS_ARGBSHUFFLEROW_AVX512BW +#define HAS_ARGBTOUV444MATRIXROW_AVX512BW +#define HAS_BLENDPLANEROW_AVX512BW +#define HAS_INTERPOLATEROW_AVX512BW +#define HAS_RGBTOUV444MATRIXROW_AVX512BW +#define HAS_ARGBTOYMATRIXROW_AVX512BW +#define HAS_I422TORGB24ROW_AVX512VBMI +#define HAS_I422TORGB24ROW_AVX512BW +#define HAS_ARGBTOUVMATRIXROW_AVX512BW +#define HAS_J400TOARGBROW_AVX512BW +#define HAS_MERGEUVROW_AVX512BW +#define HAS_MIRRORROW_AVX512BW +#define HAS_MIRRORUVROW_AVX512BW +#define HAS_MIRRORSPLITUVROW_AVX512BW +#define HAS_SPLITUVROW_AVX512BW +#define HAS_RGBTOUVMATRIXROW_AVX512BW +#define HAS_RGBTOYMATRIXROW_AVX512BW +#define HAS_ARGBEXTRACTALPHAROW_AVX512BW +#define HAS_ARGBCOPYYTOALPHAROW_AVX512BW +#define HAS_ARGBMIRRORROW_AVX512BW +#define HAS_RGB24MIRRORROW_AVX512VBMI +#define HAS_AYUVTOYROW_AVX512VBMI +#define HAS_AYUVTOUVROW_AVX512VBMI +#define HAS_AYUVTOVUROW_AVX512VBMI +#define HAS_AR30TOARGBROW_AVX512BW +#define HAS_AR30TOABGRROW_AVX512BW +#define HAS_AR30TOAB30ROW_AVX512BW +#define HAS_MERGEXR30ROW_10_AVX512BW +#define HAS_MIRRORROW_16_AVX512BW +#define HAS_MERGERGBROW_AVX512VBMI +#define HAS_RAWTORGBAROW_AVX512VBMI +#define HAS_NV12TOARGBROW_AVX512BW +#define HAS_NV21TOARGBROW_AVX512BW +#define HAS_NV12TORGB24ROW_AVX512VBMI +#define HAS_NV21TORGB24ROW_AVX512VBMI +#define HAS_NV21TOYUV24ROW_AVX512VBMI +#define HAS_I422ALPHATOARGBROW_AVX512BW +#define HAS_SWAPUVROW_AVX512BW +#define HAS_HALFMERGEUVROW_AVX512BW +#define HAS_INTERPOLATEROW_16_AVX512BW +#define HAS_ARGBATTENUATEROW_AVX512BW +#define HAS_ARGBMULTIPLYROW_AVX512BW +#define HAS_ARGBTOAR30ROW_AVX512BW +#define HAS_ABGRTOAR30ROW_AVX512BW +#define HAS_I400TOARGBROW_AVX512BW +#define HAS_ARGBGRAYROW_AVX512BW +#define HAS_ARGBBLENDROW_AVX512BW +#define HAS_ARGBALPHABLENDROW_AVX512BW +#define HAS_ARGBORROW_AVX512BW +#define HAS_ARGBTOYMATRIXROW_AVX512VNNI +#define HAS_ARGBTOUV444MATRIXROW_AVX512VNNI +#define HAS_ARGBTOUVMATRIXROW_AVX512VNNI +#define HAS_ARGBGRAYROW_AVX512VNNI +// AVX512VNNIVBMI requires both AVX512VNNI and AVX512VBMI. +#define HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI +#define HAS_ARGBTOUV444MATRIXROW_AVX512VNNIVBMI +#define HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI +#define HAS_ARGB1555TOARGBROW_AVX512BW +#define HAS_ARGBCOLORMATRIXROW_AVX512VNNI +#define HAS_ARGBSEPIAROW_AVX512VNNI +#define HAS_ARGBTORGB565DITHERROW_AVX512BW +#define HAS_ARGBTORGB565ROW_AVX512BW +#define HAS_CONVERT8TO8ROW_AVX512BW +#define HAS_DIVIDEROW_16_AVX512BW +#define HAS_HALFFLOATROW_AVX512BW +#define HAS_I210ALPHATOARGBROW_AVX512BW +#define HAS_I210TOAR30ROW_AVX512BW +#define HAS_I210TOARGBROW_AVX512BW +#define HAS_I212TOAR30ROW_AVX512BW +#define HAS_I212TOARGBROW_AVX512BW +#define HAS_I410ALPHATOARGBROW_AVX512BW +#define HAS_I410TOAR30ROW_AVX512BW +#define HAS_I410TOARGBROW_AVX512BW +#define HAS_I422TOARGB1555ROW_AVX512BW +#define HAS_I422TOARGB4444ROW_AVX512BW +#define HAS_I422TORGB565ROW_AVX512BW +#define HAS_I422TORGBAROW_AVX512BW +#define HAS_I444ALPHATOARGBROW_AVX512BW +#define HAS_I444TOARGBROW_AVX512BW +#define HAS_I444TORGB24ROW_AVX512VBMI +#define HAS_MERGEUVROW_16_AVX512BW +#define HAS_P210TOAR30ROW_AVX512BW +#define HAS_P210TOARGBROW_AVX512BW +#define HAS_P410TOAR30ROW_AVX512BW +#define HAS_P410TOARGBROW_AVX512BW +#define HAS_UYVYTOARGBROW_AVX512BW +#define HAS_UYVYTOUVROW_AVX512BW +#define HAS_UYVYTOYROW_AVX512BW +#define HAS_YUY2TOARGBROW_AVX512BW +#define HAS_YUY2TOUVROW_AVX512BW +#define HAS_YUY2TOYROW_AVX512BW #endif // The following are available on Neon platforms: #if !defined(LIBYUV_DISABLE_NEON) && \ (defined(__aarch64__) || defined(__ARM_NEON__) || defined(LIBYUV_NEON)) -#define HAS_ABGRTOUVROW_NEON -#define HAS_ABGRTOYROW_NEON +#define HAS_AB64TOARGBROW_NEON +#define HAS_AR30TOAB30ROW_NEON +#define HAS_AR30TOABGRROW_NEON +#define HAS_AR30TOARGBROW_NEON +#define HAS_AR64TOARGBROW_NEON #define HAS_ARGB1555TOARGBROW_NEON #define HAS_ARGB1555TOUVROW_NEON #define HAS_ARGB1555TOYROW_NEON #define HAS_ARGB4444TOARGBROW_NEON #define HAS_ARGB4444TOUVROW_NEON #define HAS_ARGB4444TOYROW_NEON +#define HAS_ARGBCOPYALPHAROW_NEON +#define HAS_ARGBCOPYYTOALPHAROW_NEON #define HAS_ARGBEXTRACTALPHAROW_NEON #define HAS_ARGBSETROW_NEON +#define HAS_ARGBTOAB64ROW_NEON +#define HAS_ARGBTOAR64ROW_NEON #define HAS_ARGBTOARGB1555ROW_NEON #define HAS_ARGBTOARGB4444ROW_NEON #define HAS_ARGBTORAWROW_NEON #define HAS_ARGBTORGB24ROW_NEON #define HAS_ARGBTORGB565DITHERROW_NEON #define HAS_ARGBTORGB565ROW_NEON -#define HAS_ARGBTOUV444ROW_NEON -#define HAS_ARGBTOUVJROW_NEON -#define HAS_ARGBTOUVROW_NEON -#define HAS_ARGBTOYJROW_NEON -#define HAS_ARGBTOYROW_NEON -#define HAS_AYUVTOUVROW_NEON +#define HAS_ARGBTOUV444MATRIXROW_NEON +#define HAS_RGBTOUV444MATRIXROW_NEON +#if !defined(__GNUC__) || defined(__clang__) +#define HAS_ARGBTOUVMATRIXROW_NEON +#define HAS_RGBTOUVMATRIXROW_NEON +#define HAS_RGB565TOUVMATRIXROW_NEON +#define HAS_ARGB1555TOUVMATRIXROW_NEON +#define HAS_ARGB4444TOUVMATRIXROW_NEON +#endif +#define HAS_ARGBTOYMATRIXROW_NEON +#define HAS_RGB565TOYMATRIXROW_NEON +#define HAS_ARGB1555TOYMATRIXROW_NEON +#define HAS_ARGB4444TOYMATRIXROW_NEON +#define HAS_RGBTOYMATRIXROW_NEON #define HAS_AYUVTOVUROW_NEON #define HAS_AYUVTOYROW_NEON -#define HAS_BGRATOUVROW_NEON -#define HAS_BGRATOYROW_NEON #define HAS_BYTETOFLOATROW_NEON +#define HAS_CONVERT16TO8ROW_NEON +#define HAS_CONVERT8TO16ROW_NEON +#define HAS_CONVERT8TO8ROW_NEON +#define HAS_COPYROW_16_NEON #define HAS_COPYROW_NEON +#define HAS_DETILEROW_16_NEON +#define HAS_DETILEROW_NEON +#define HAS_DETILESPLITUVROW_NEON +#define HAS_DETILETOYUY2_NEON +#define HAS_DIVIDEROW_16_NEON #define HAS_HALFFLOATROW_NEON +#define HAS_HALFMERGEUVROW_NEON +#define HAS_HALFROW_16TO8_NEON +#define HAS_HALFWIDTHROW_16TO8_NEON #define HAS_I400TOARGBROW_NEON #define HAS_I422ALPHATOARGBROW_NEON #define HAS_I422TOARGB1555ROW_NEON @@ -354,11 +755,27 @@ extern "C" { #define HAS_I422TORGBAROW_NEON #define HAS_I422TOUYVYROW_NEON #define HAS_I422TOYUY2ROW_NEON +#define HAS_I444ALPHATOARGBROW_NEON #define HAS_I444TOARGBROW_NEON +#define HAS_I444TORGB24ROW_NEON +#define HAS_INTERPOLATEROW_16_NEON +#define HAS_INTERPOLATEROW_NEON #define HAS_J400TOARGBROW_NEON +#define HAS_MERGEAR64ROW_NEON +#define HAS_MERGEARGB16TO8ROW_NEON +#define HAS_MERGEARGBROW_NEON +#define HAS_MERGERGBROW_NEON +#define HAS_MERGEUVROW_16_NEON #define HAS_MERGEUVROW_NEON +#define HAS_MERGEXR30ROW_NEON +#define HAS_MERGEXR64ROW_NEON +#define HAS_MERGEXRGB16TO8ROW_NEON +#define HAS_MERGEXRGBROW_NEON +#define HAS_MIRRORROW_16_NEON #define HAS_MIRRORROW_NEON +#define HAS_MIRRORSPLITUVROW_NEON #define HAS_MIRRORUVROW_NEON +#define HAS_MULTIPLYROW_16_NEON #define HAS_NV12TOARGBROW_NEON #define HAS_NV12TORGB24ROW_NEON #define HAS_NV12TORGB565ROW_NEON @@ -367,43 +784,53 @@ extern "C" { #define HAS_NV21TOYUV24ROW_NEON #define HAS_RAWTOARGBROW_NEON #define HAS_RAWTORGB24ROW_NEON +#define HAS_RAWTORGBAROW_NEON #define HAS_RAWTOUVROW_NEON -#define HAS_RAWTOYROW_NEON #define HAS_RGB24TOARGBROW_NEON #define HAS_RGB24TOUVROW_NEON -#define HAS_RGB24TOYROW_NEON #define HAS_RGB565TOARGBROW_NEON #define HAS_RGB565TOUVROW_NEON #define HAS_RGB565TOYROW_NEON -#define HAS_RGBATOUVROW_NEON -#define HAS_RGBATOYROW_NEON #define HAS_SETROW_NEON +#define HAS_SPLITARGBROW_NEON #define HAS_SPLITRGBROW_NEON +#define HAS_SPLITUVROW_16_NEON #define HAS_SPLITUVROW_NEON +#define HAS_SPLITXRGBROW_NEON #define HAS_SWAPUVROW_NEON +#define HAS_UNPACKMT2T_NEON #define HAS_UYVYTOARGBROW_NEON -#define HAS_UYVYTOUV422ROW_NEON #define HAS_UYVYTOUVROW_NEON #define HAS_UYVYTOYROW_NEON #define HAS_YUY2TOARGBROW_NEON +#define HAS_YUY2TONVUVROW_NEON #define HAS_YUY2TOUV422ROW_NEON #define HAS_YUY2TOUVROW_NEON #define HAS_YUY2TOYROW_NEON // Effects: #define HAS_ARGBADDROW_NEON +#define HAS_ARGBAFFINEROW_NEON +#define HAS_ARGBALPHABLENDROW_NEON #define HAS_ARGBATTENUATEROW_NEON #define HAS_ARGBBLENDROW_NEON +#define HAS_BLENDPLANEROW_NEON #define HAS_ARGBCOLORMATRIXROW_NEON +#define HAS_ARGBCOLORTABLEROW_NEON #define HAS_ARGBGRAYROW_NEON +#define HAS_ARGBLUMACOLORTABLEROW_NEON #define HAS_ARGBMIRRORROW_NEON #define HAS_ARGBMULTIPLYROW_NEON +#define HAS_ARGBORROW_NEON +#define HAS_ARGBPOLYNOMIALROW_NEON #define HAS_ARGBQUANTIZEROW_NEON #define HAS_ARGBSEPIAROW_NEON #define HAS_ARGBSHADEROW_NEON #define HAS_ARGBSHUFFLEROW_NEON #define HAS_ARGBSUBTRACTROW_NEON -#define HAS_INTERPOLATEROW_NEON +#define HAS_ARGBUNATTENUATEROW_NEON +#define HAS_RGB24MIRRORROW_NEON +#define HAS_RGBCOLORTABLEROW_NEON #define HAS_SOBELROW_NEON #define HAS_SOBELTOPLANEROW_NEON #define HAS_SOBELXROW_NEON @@ -413,170 +840,508 @@ extern "C" { // The following are available on AArch64 platforms: #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) +#define HAS_ABGRTOAR30ROW_NEON +#define HAS_ARGBTOAR30ROW_NEON +#define HAS_COMPUTECUMULATIVESUMROW_NEON +#define HAS_CUMULATIVESUMTOAVERAGEROW_NEON +#define HAS_I210ALPHATOARGBROW_NEON +#define HAS_I210TOAR30ROW_NEON +#define HAS_I210TOARGBROW_NEON +#define HAS_I212TOAR30ROW_NEON +#define HAS_I212TOARGBROW_NEON +#define HAS_I410ALPHATOARGBROW_NEON +#define HAS_I410TOAR30ROW_NEON +#define HAS_I410TOARGBROW_NEON +#define HAS_I422TOAR30ROW_NEON +#define HAS_P210TOAR30ROW_NEON +#define HAS_P210TOARGBROW_NEON +#define HAS_P410TOAR30ROW_NEON +#define HAS_P410TOARGBROW_NEON + +#define HAS_ARGBGRAYROW_NEON_DOTPROD +#define HAS_ARGBSEPIAROW_NEON_DOTPROD +#define HAS_ARGBTOYMATRIXROW_NEON_DOTPROD +#define HAS_RGBTOYMATRIXROW_NEON_DOTPROD + +#define HAS_ARGBCOLORMATRIXROW_NEON_I8MM +#define HAS_ARGBTOUVMATRIXROW_NEON_I8MM +#define HAS_ARGBTOUV444MATRIXROW_NEON_I8MM +#endif + +// The following are available on AArch64 SVE platforms: +#if !defined(LIBYUV_DISABLE_SVE) && defined(__aarch64__) +#define HAS_ARGB1555TOARGBROW_SVE2 +#define HAS_ARGBALPHABLENDROW_SVE2 +#define HAS_ARGBORROW_SVE2 +#define HAS_ARGBTORAWROW_SVE2 +#define HAS_ARGBTORGB24ROW_SVE2 +#define HAS_ARGBTORGB565DITHERROW_SVE2 +#define HAS_ARGBTORGB565ROW_SVE2 +#define HAS_ARGBTOUVMATRIXROW_SVE2 +#define HAS_ARGBTOYMATRIXROW_SVE2 +#define HAS_AYUVTOUVROW_SVE2 +#define HAS_AYUVTOVUROW_SVE2 +// Disabled: NEON version is faster for 128 bit vectors. +// #define HAS_CONVERT16TO8ROW_SVE2 +#define HAS_CONVERT8TO8ROW_SVE2 +#define HAS_COPYROW_SVE2 +#define HAS_DIVIDEROW_16_SVE2 +#define HAS_HALFFLOATROW_SVE2 +#define HAS_HALFMERGEUVROW_SVE2 +// Disabled: NEON version is faster for 128 bit vectors. +// #define HAS_HALFROW_16TO8_SVE2 +// Disabled: NEON version is faster for 128 bit vectors. +// #define HAS_HALFWIDTHROW_16TO8_SVE2 +#define HAS_I210ALPHATOARGBROW_SVE2 +#define HAS_I210TOAR30ROW_SVE2 +#define HAS_I210TOARGBROW_SVE2 +#define HAS_I212TOAR30ROW_SVE2 +#define HAS_I212TOARGBROW_SVE2 +#define HAS_I400TOARGBROW_SVE2 +#define HAS_I410ALPHATOARGBROW_SVE2 +#define HAS_I410TOAR30ROW_SVE2 +#define HAS_I410TOARGBROW_SVE2 +#define HAS_I422ALPHATOARGBROW_SVE2 +#define HAS_I422TOAR30ROW_SVE2 +#define HAS_I422TOARGB1555ROW_SVE2 +#define HAS_I422TOARGB4444ROW_SVE2 +#define HAS_I422TOARGBROW_SVE2 +#define HAS_I422TORGB24ROW_SVE2 +#define HAS_I422TORGB565ROW_SVE2 +#define HAS_I422TORGBAROW_SVE2 +#define HAS_I444ALPHATOARGBROW_SVE2 +#define HAS_I444TOARGBROW_SVE2 +#define HAS_I444TORGB24ROW_SVE2 +#define HAS_INTERPOLATEROW_SVE2 +#define HAS_MERGEUVROW_SVE2 +#define HAS_NV12TOARGBROW_SVE2 +#define HAS_NV12TORGB24ROW_SVE2 +#define HAS_NV21TOARGBROW_SVE2 +#define HAS_NV21TORGB24ROW_SVE2 +#define HAS_P210TOAR30ROW_SVE2 +#define HAS_P210TOARGBROW_SVE2 +#define HAS_P410TOAR30ROW_SVE2 +#define HAS_P410TOARGBROW_SVE2 +#define HAS_RAWTOARGBROW_SVE2 +#define HAS_RAWTORGB24ROW_SVE2 +#define HAS_RAWTORGBAROW_SVE2 +#define HAS_RGB24TOARGBROW_SVE2 +#define HAS_SPLITUVROW_SVE2 +#define HAS_UYVYTOARGBROW_SVE2 +#define HAS_UYVYTOUVROW_SVE2 +#define HAS_UYVYTOYROW_SVE2 +#define HAS_YUY2TOARGBROW_SVE2 +#define HAS_YUY2TOUVROW_SVE2 +#define HAS_YUY2TOYROW_SVE2 +#endif + +// The following are available on AArch64 SME platforms: +#if !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && \ + defined(__aarch64__) +#define HAS_ARGBALPHABLENDROW_SME +#define HAS_ARGBMULTIPLYROW_SME +#define HAS_ARGBORROW_SME +#define HAS_ARGBTOUVMATRIXROW_SME +#define HAS_ARGBTOYMATRIXROW_SME +#define HAS_CONVERT16TO8ROW_SME +#define HAS_CONVERT8TO16ROW_SME +#define HAS_CONVERT8TO8ROW_SME +#define HAS_COPYROW_SME +#define HAS_HALFROW_16TO8_SME +#define HAS_HALFWIDTHROW_16TO8_SME +#define HAS_I210ALPHATOARGBROW_SME +#define HAS_I210TOAR30ROW_SME +#define HAS_I210TOARGBROW_SME +#define HAS_I212TOAR30ROW_SME +#define HAS_I212TOARGBROW_SME +#define HAS_I400TOARGBROW_SME +#define HAS_I410ALPHATOARGBROW_SME +#define HAS_I410TOAR30ROW_SME +#define HAS_I410TOARGBROW_SME +#define HAS_I422ALPHATOARGBROW_SME +#define HAS_I422TOAR30ROW_SME +#define HAS_I422TOARGB1555ROW_SME +#define HAS_I422TOARGB4444ROW_SME +#define HAS_I422TOARGBROW_SME +#define HAS_I422TORGB24ROW_SME +#define HAS_I422TORGB565ROW_SME +#define HAS_I422TORGBAROW_SME +#define HAS_I444ALPHATOARGBROW_SME +#define HAS_I444TOARGBROW_SME +#define HAS_I444TORGB24ROW_SME +#define HAS_INTERPOLATEROW_16_SME +#define HAS_INTERPOLATEROW_SME +#define HAS_MERGEUVROW_16_SME +#define HAS_MERGEUVROW_SME +#define HAS_MULTIPLYROW_16_SME +#define HAS_NV12TOARGBROW_SME +#define HAS_NV12TORGB24ROW_SME +#define HAS_NV21TOARGBROW_SME +#define HAS_NV21TORGB24ROW_SME +#define HAS_P210TOAR30ROW_SME +#define HAS_P210TOARGBROW_SME +#define HAS_P410TOAR30ROW_SME +#define HAS_P410TOARGBROW_SME +#define HAS_UYVYTOARGBROW_SME +#define HAS_YUY2TOARGBROW_SME +#endif + +// The following are available on AArch64 platforms: +#if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) +#define HAS_GAUSSCOL_F32_NEON +#define HAS_GAUSSROW_F32_NEON #define HAS_SCALESUMSAMPLES_NEON #endif -#if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) -#define HAS_ABGRTOUVROW_MSA -#define HAS_ABGRTOYROW_MSA -#define HAS_ARGB1555TOARGBROW_MSA -#define HAS_ARGB1555TOUVROW_MSA -#define HAS_ARGB1555TOYROW_MSA -#define HAS_ARGB4444TOARGBROW_MSA -#define HAS_ARGBADDROW_MSA -#define HAS_ARGBATTENUATEROW_MSA -#define HAS_ARGBBLENDROW_MSA -#define HAS_ARGBCOLORMATRIXROW_MSA -#define HAS_ARGBEXTRACTALPHAROW_MSA -#define HAS_ARGBGRAYROW_MSA -#define HAS_ARGBMIRRORROW_MSA -#define HAS_ARGBMULTIPLYROW_MSA -#define HAS_ARGBQUANTIZEROW_MSA -#define HAS_ARGBSEPIAROW_MSA -#define HAS_ARGBSETROW_MSA -#define HAS_ARGBSHADEROW_MSA -#define HAS_ARGBSHUFFLEROW_MSA -#define HAS_ARGBSUBTRACTROW_MSA -#define HAS_ARGBTOARGB1555ROW_MSA -#define HAS_ARGBTOARGB4444ROW_MSA -#define HAS_ARGBTORAWROW_MSA -#define HAS_ARGBTORGB24ROW_MSA -#define HAS_ARGBTORGB565DITHERROW_MSA -#define HAS_ARGBTORGB565ROW_MSA -#define HAS_ARGBTOUV444ROW_MSA -#define HAS_ARGBTOUVJROW_MSA -#define HAS_ARGBTOUVROW_MSA -#define HAS_ARGBTOYJROW_MSA -#define HAS_ARGBTOYROW_MSA -#define HAS_BGRATOUVROW_MSA -#define HAS_BGRATOYROW_MSA -#define HAS_HALFFLOATROW_MSA -#define HAS_I400TOARGBROW_MSA -#define HAS_I422ALPHATOARGBROW_MSA -#define HAS_I422TOARGBROW_MSA -#define HAS_I422TORGB24ROW_MSA -#define HAS_I422TORGBAROW_MSA -#define HAS_I422TOUYVYROW_MSA -#define HAS_I422TOYUY2ROW_MSA -#define HAS_I444TOARGBROW_MSA -#define HAS_INTERPOLATEROW_MSA -#define HAS_J400TOARGBROW_MSA -#define HAS_MERGEUVROW_MSA -#define HAS_MIRRORROW_MSA -#define HAS_MIRRORUVROW_MSA -#define HAS_NV12TOARGBROW_MSA -#define HAS_NV12TORGB565ROW_MSA -#define HAS_NV21TOARGBROW_MSA -#define HAS_RAWTOARGBROW_MSA -#define HAS_RAWTORGB24ROW_MSA -#define HAS_RAWTOUVROW_MSA -#define HAS_RAWTOYROW_MSA -#define HAS_RGB24TOARGBROW_MSA -#define HAS_RGB24TOUVROW_MSA -#define HAS_RGB24TOYROW_MSA -#define HAS_RGB565TOARGBROW_MSA -#define HAS_RGB565TOUVROW_MSA -#define HAS_RGB565TOYROW_MSA -#define HAS_RGBATOUVROW_MSA -#define HAS_RGBATOYROW_MSA -#define HAS_SETROW_MSA -#define HAS_SOBELROW_MSA -#define HAS_SOBELTOPLANEROW_MSA -#define HAS_SOBELXROW_MSA -#define HAS_SOBELXYROW_MSA -#define HAS_SOBELYROW_MSA -#define HAS_SPLITUVROW_MSA -#define HAS_UYVYTOARGBROW_MSA -#define HAS_UYVYTOUVROW_MSA -#define HAS_UYVYTOYROW_MSA -#define HAS_YUY2TOARGBROW_MSA -#define HAS_YUY2TOUV422ROW_MSA -#define HAS_YUY2TOUVROW_MSA -#define HAS_YUY2TOYROW_MSA + +#if !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx) +#define HAS_ARGB1555TOARGBROW_LSX +#define HAS_ARGB1555TOUVROW_LSX +#define HAS_ARGB1555TOYROW_LSX +#define HAS_ARGB4444TOARGBROW_LSX +#define HAS_ARGBADDROW_LSX +#define HAS_ARGBALPHABLENDROW_LSX +#define HAS_ARGBATTENUATEROW_LSX +#define HAS_ARGBBLENDROW_LSX +#define HAS_ARGBCOLORMATRIXROW_LSX +#define HAS_ARGBEXTRACTALPHAROW_LSX +#define HAS_ARGBGRAYROW_LSX +#define HAS_ARGBORROW_LSX +#define HAS_ARGBSEPIAROW_LSX +#define HAS_ARGBSHADEROW_LSX +#define HAS_ARGBSHUFFLEROW_LSX +#define HAS_ARGBSUBTRACTROW_LSX +#define HAS_ARGBQUANTIZEROW_LSX +#define HAS_ARGBSETROW_LSX +#define HAS_ARGBTOARGB1555ROW_LSX +#define HAS_ARGBTOARGB4444ROW_LSX +#define HAS_ARGBTORAWROW_LSX +#define HAS_ARGBTORGB24ROW_LSX +#define HAS_ARGBTORGB565ROW_LSX +#define HAS_ARGBTORGB565DITHERROW_LSX +#define HAS_ARGBMIRRORROW_LSX +#define HAS_ARGBMULTIPLYROW_LSX +#define HAS_HALFFLOATROW_LSX +#define HAS_I400TOARGBROW_LSX +#define HAS_I444TOARGBROW_LSX +#define HAS_INTERPOLATEROW_LSX +#define HAS_I422ALPHATOARGBROW_LSX +#define HAS_I422TOARGB1555ROW_LSX +#define HAS_I422TOARGB4444ROW_LSX +#define HAS_I422TORGB24ROW_LSX +#define HAS_I422TORGB565ROW_LSX +#define HAS_I422TORGBAROW_LSX +#define HAS_I422TOUYVYROW_LSX +#define HAS_I422TOYUY2ROW_LSX +#define HAS_J400TOARGBROW_LSX +#define HAS_MERGEUVROW_LSX +#define HAS_MIRRORROW_LSX +#define HAS_MIRRORUVROW_LSX +#define HAS_MIRRORSPLITUVROW_LSX +#define HAS_NV12TOARGBROW_LSX +#define HAS_NV12TORGB565ROW_LSX +#define HAS_NV21TOARGBROW_LSX +#define HAS_RAWTOARGBROW_LSX +#define HAS_RAWTORGB24ROW_LSX +#define HAS_RAWTOUVROW_LSX +#define HAS_RGB24TOARGBROW_LSX +#define HAS_RGB24TOUVROW_LSX +#define HAS_RGB565TOARGBROW_LSX +#define HAS_RGB565TOUVROW_LSX +#define HAS_RGB565TOYROW_LSX +#define HAS_SETROW_LSX +#define HAS_SOBELROW_LSX +#define HAS_SOBELTOPLANEROW_LSX +#define HAS_SOBELXYROW_LSX +#define HAS_SPLITUVROW_LSX +#define HAS_UYVYTOARGBROW_LSX +#define HAS_UYVYTOUV422ROW_LSX +#define HAS_UYVYTOUVROW_LSX +#define HAS_UYVYTOYROW_LSX +#define HAS_YUY2TOARGBROW_LSX +#define HAS_YUY2TOUVROW_LSX +#define HAS_YUY2TOUV422ROW_LSX +#define HAS_YUY2TOYROW_LSX +#define HAS_ARGBTOYMATRIXROW_LSX +#define HAS_COPYROW_LSX +#define HAS_RGBTOYMATRIXROW_LSX #endif -#if !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) -#define HAS_ABGRTOUVROW_MMI -#define HAS_ABGRTOYROW_MMI -#define HAS_ARGB1555TOARGBROW_MMI -#define HAS_ARGB1555TOUVROW_MMI -#define HAS_ARGB1555TOYROW_MMI -#define HAS_ARGB4444TOARGBROW_MMI -#define HAS_ARGB4444TOUVROW_MMI -#define HAS_ARGB4444TOYROW_MMI -#define HAS_ARGBADDROW_MMI -#define HAS_ARGBATTENUATEROW_MMI -#define HAS_ARGBBLENDROW_MMI -#define HAS_ARGBCOLORMATRIXROW_MMI -#define HAS_ARGBCOPYALPHAROW_MMI -#define HAS_ARGBCOPYYTOALPHAROW_MMI -#define HAS_ARGBEXTRACTALPHAROW_MMI -#define HAS_ARGBGRAYROW_MMI -#define HAS_ARGBMIRRORROW_MMI -#define HAS_ARGBMULTIPLYROW_MMI -#define HAS_ARGBSEPIAROW_MMI -#define HAS_ARGBSHADEROW_MMI -#define HAS_ARGBSHUFFLEROW_MMI -#define HAS_ARGBSUBTRACTROW_MMI -#define HAS_ARGBTOARGB1555ROW_MMI -#define HAS_ARGBTOARGB4444ROW_MMI -#define HAS_ARGBTORAWROW_MMI -#define HAS_ARGBTORGB24ROW_MMI -#define HAS_ARGBTORGB565DITHERROW_MMI -#define HAS_ARGBTORGB565ROW_MMI -#define HAS_ARGBTOUV444ROW_MMI -#define HAS_ARGBTOUVJROW_MMI -#define HAS_ARGBTOUVROW_MMI -#define HAS_ARGBTOYJROW_MMI -#define HAS_ARGBTOYROW_MMI -#define HAS_BGRATOUVROW_MMI -#define HAS_BGRATOYROW_MMI -#define HAS_BLENDPLANEROW_MMI -#define HAS_COMPUTECUMULATIVESUMROW_MMI -#define HAS_CUMULATIVESUMTOAVERAGEROW_MMI -#define HAS_HALFFLOATROW_MMI -#define HAS_I400TOARGBROW_MMI -#define HAS_I422TOUYVYROW_MMI -#define HAS_I422TOYUY2ROW_MMI -#define HAS_INTERPOLATEROW_MMI -#define HAS_J400TOARGBROW_MMI -#define HAS_MERGERGBROW_MMI -#define HAS_MERGEUVROW_MMI -#define HAS_MIRRORROW_MMI -#define HAS_MIRRORUVROW_MMI -#define HAS_RAWTOARGBROW_MMI -#define HAS_RAWTORGB24ROW_MMI -#define HAS_RAWTOUVROW_MMI -#define HAS_RAWTOYROW_MMI -#define HAS_RGB24TOARGBROW_MMI -#define HAS_RGB24TOUVROW_MMI -#define HAS_RGB24TOYROW_MMI -#define HAS_RGB565TOARGBROW_MMI -#define HAS_RGB565TOUVROW_MMI -#define HAS_RGB565TOYROW_MMI -#define HAS_RGBATOUVROW_MMI -#define HAS_RGBATOYROW_MMI -#define HAS_SOBELROW_MMI -#define HAS_SOBELTOPLANEROW_MMI -#define HAS_SOBELXROW_MMI -#define HAS_SOBELXYROW_MMI -#define HAS_SOBELYROW_MMI -#define HAS_SPLITRGBROW_MMI -#define HAS_SPLITUVROW_MMI -#define HAS_UYVYTOUVROW_MMI -#define HAS_UYVYTOYROW_MMI -#define HAS_YUY2TOUV422ROW_MMI -#define HAS_YUY2TOUVROW_MMI -#define HAS_YUY2TOYROW_MMI +#if !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx) +#define HAS_I422TOARGBROW_LSX #endif +#if !defined(LIBYUV_DISABLE_LASX) && defined(__loongarch_asx) +#define HAS_ARGB1555TOARGBROW_LASX +#define HAS_ARGB1555TOUVROW_LASX +#define HAS_ARGB1555TOYROW_LASX +#define HAS_ARGB4444TOARGBROW_LASX +#define HAS_ARGBADDROW_LASX +#define HAS_ARGBALPHABLENDROW_LASX +#define HAS_ARGBATTENUATEROW_LASX +#define HAS_ARGBBLENDROW_LASX +#define HAS_ARGBCOLORMATRIXROW_LASX +#define HAS_ARGBEXTRACTALPHAROW_LASX +#define HAS_ARGBGRAYROW_LASX +#define HAS_ARGBMIRRORROW_LASX +#define HAS_ARGBMULTIPLYROW_LASX +#define HAS_ARGBORROW_LASX +#define HAS_ARGBQUANTIZEROW_LASX +#define HAS_ARGBSEPIAROW_LASX +#define HAS_ARGBSETROW_LASX +#define HAS_ARGBSHADEROW_LASX +#define HAS_ARGBSHUFFLEROW_LASX +#define HAS_ARGBSUBTRACTROW_LASX +#define HAS_ARGBTOARGB1555ROW_LASX +#define HAS_ARGBTOARGB4444ROW_LASX +#define HAS_ARGBTORAWROW_LASX +#define HAS_ARGBTORGB24ROW_LASX +#define HAS_ARGBTORGB565DITHERROW_LASX +#define HAS_ARGBTORGB565ROW_LASX +#define HAS_ARGBTOYMATRIXROW_LASX +#define HAS_COPYROW_LASX +#define HAS_HALFFLOATROW_LASX +#define HAS_I400TOARGBROW_LASX +#define HAS_I422ALPHATOARGBROW_LASX +#define HAS_I422TOARGB1555ROW_LASX +#define HAS_I422TOARGB4444ROW_LASX +#define HAS_I422TOARGBROW_LASX +#define HAS_I422TORGB24ROW_LASX +#define HAS_I422TORGB565ROW_LASX +#define HAS_I422TORGBAROW_LASX +#define HAS_I422TOUYVYROW_LASX +#define HAS_I422TOYUY2ROW_LASX +#define HAS_I444TOARGBROW_LASX +#define HAS_INTERPOLATEROW_LASX +#define HAS_J400TOARGBROW_LASX +#define HAS_MERGEUVROW_LASX +#define HAS_MIRRORROW_LASX +#define HAS_MIRRORSPLITUVROW_LASX +#define HAS_MIRRORUVROW_LASX +#define HAS_NV12TOARGBROW_LASX +#define HAS_NV12TORGB565ROW_LASX +#define HAS_NV21TOARGBROW_LASX +#define HAS_RAWTOARGBROW_LASX +#define HAS_RAWTORGB24ROW_LASX +#define HAS_RAWTOUVROW_LASX +#define HAS_RGB24TOARGBROW_LASX +#define HAS_RGB24TOUVROW_LASX +#define HAS_RGB565TOARGBROW_LASX +#define HAS_RGB565TOUVROW_LASX +#define HAS_RGB565TOYROW_LASX +#define HAS_RGBTOYMATRIXROW_LASX +#define HAS_SETROW_LASX +#define HAS_SOBELROW_LASX +#define HAS_SOBELTOPLANEROW_LASX +#define HAS_SOBELXYROW_LASX +#define HAS_SPLITUVROW_LASX +#define HAS_UYVYTOARGBROW_LASX +#define HAS_UYVYTOUV422ROW_LASX +#define HAS_UYVYTOUVROW_LASX +#define HAS_UYVYTOYROW_LASX +#define HAS_YUY2TOARGBROW_LASX +#define HAS_YUY2TOUV422ROW_LASX +#define HAS_YUY2TOUVROW_LASX +#define HAS_YUY2TOYROW_LASX +#endif + +#if !defined(LIBYUV_DISABLE_RVV) && \ + (defined(__riscv_vector) || defined(LIBYUV_RVV)) +#define HAS_AR64TOARGBROW_RVV +#define HAS_ARGBCOPYYTOALPHAROW_RVV +#define HAS_ARGBEXTRACTALPHAROW_RVV +#define HAS_ARGBMULTIPLYROW_RVV +#define HAS_ARGBTOAR64ROW_RVV +#define HAS_ARGBMIRRORROW_RVV +#define HAS_ARGBSETROW_RVV +#define HAS_ARGBSHUFFLEROW_RVV +#define HAS_ARGBTOUV444MATRIXROW_RVV +#define HAS_ARGBTOUVMATRIXROW_RVV +#define HAS_ARGBTOYMATRIXROW_RVV +#define HAS_CONVERT16TO8ROW_RVV +#define HAS_CONVERT8TO16ROW_RVV +#define HAS_COPYROW_RVV +#define HAS_HALFROW_16TO8_RVV +#define HAS_HALFWIDTHROW_16TO8_RVV +#define HAS_I422TOAR30ROW_RVV +#define HAS_INTERPOLATEROW_RVV +#define HAS_MULTIPLYROW_16_RVV +#define HAS_RGBTOUV444MATRIXROW_RVV +#define HAS_RGBTOUVMATRIXROW_RVV +#define HAS_RGBTOYMATRIXROW_RVV +#define HAS_SPLITARGBROW_RVV +#define HAS_SPLITRGBROW_RVV +#define HAS_SPLITUVROW_RVV +#define HAS_SPLITXRGBROW_RVV +#define HAS_SWAPUVROW_RVV +#define HAS_AB64TOARGBROW_RVV +#define HAS_AR64TOAB64ROW_RVV +#define HAS_ARGBALPHABLENDROW_RVV +#define HAS_ARGBATTENUATEROW_RVV +#define HAS_ARGBBLENDROW_RVV +#define HAS_ARGBORROW_RVV +#define HAS_ARGBTOAB64ROW_RVV +#define HAS_ARGBTOABGRROW_RVV +#define HAS_ARGBTOBGRAROW_RVV +#define HAS_ARGBTORAWROW_RVV +#define HAS_ARGBTORGB24ROW_RVV +#define HAS_ARGBTORGBAROW_RVV +#define HAS_BLENDPLANEROW_RVV +#define HAS_I400TOARGBROW_RVV +#define HAS_I422ALPHATOARGBROW_RVV +#define HAS_I422TOARGBROW_RVV +#define HAS_I422TORGB24ROW_RVV +#define HAS_I422TORGBAROW_RVV +#define HAS_I444ALPHATOARGBROW_RVV +#define HAS_I444TOARGBROW_RVV +#define HAS_I444TORGB24ROW_RVV +#define HAS_J400TOARGBROW_RVV +#define HAS_MERGEARGBROW_RVV +#define HAS_MERGERGBROW_RVV +#define HAS_MERGEUVROW_RVV +#define HAS_MERGEXRGBROW_RVV +#define HAS_MIRRORUVROW_RVV +#define HAS_NV12TOARGBROW_RVV +#define HAS_NV12TORGB24ROW_RVV +#define HAS_NV21TOARGBROW_RVV +#define HAS_NV21TORGB24ROW_RVV +#define HAS_RAWTOARGBROW_RVV +#define HAS_RAWTORGB24ROW_RVV +#define HAS_RAWTORGBAROW_RVV +#define HAS_RGB24TOARGBROW_RVV +#define HAS_RGBATOARGBROW_RVV +#endif + +#if !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) +#define HAS_ARGB1555TOARGBROW_WASMSIMD +#define HAS_ARGB1555TOUVMATRIXROW_WASMSIMD +#define HAS_ARGB1555TOYMATRIXROW_WASMSIMD +#define HAS_ARGB4444TOARGBROW_WASMSIMD +#define HAS_ARGB4444TOUVMATRIXROW_WASMSIMD +#define HAS_ARGB4444TOYMATRIXROW_WASMSIMD +#define HAS_ARGBALPHABLENDROW_WASMSIMD +#define HAS_ARGBBLENDROW_WASMSIMD +#define HAS_ARGBCOPYYTOALPHAROW_WASMSIMD +#define HAS_ARGBEXTRACTALPHAROW_WASMSIMD +#define HAS_ARGBMIRRORROW_WASMSIMD +#define HAS_ARGBORROW_WASMSIMD +#define HAS_ARGBSHUFFLEROW_WASMSIMD +#define HAS_ARGBTOARGB1555ROW_WASMSIMD +#define HAS_ARGBTOARGB4444ROW_WASMSIMD +#define HAS_ARGBTORGB565DITHERROW_WASMSIMD +#define HAS_ARGBTORGB565ROW_WASMSIMD +#define HAS_ARGBTOUV444MATRIXROW_WASMSIMD +#define HAS_ARGBTOUVMATRIXROW_WASMSIMD +#define HAS_ARGBTOYMATRIXROW_WASMSIMD +#define HAS_BLENDPLANEROW_WASMSIMD +#define HAS_CONVERT8TO16ROW_WASMSIMD +#define HAS_I422TOAR30ROW_WASMSIMD +#define HAS_I422TOARGB1555ROW_WASMSIMD +#define HAS_I422TOARGB4444ROW_WASMSIMD +#define HAS_I422TOARGBROW_WASMSIMD +#define HAS_I422TORGB24ROW_WASMSIMD +#define HAS_I422TORGB565ROW_WASMSIMD +#define HAS_INTERPOLATEROW_16_WASMSIMD +#define HAS_INTERPOLATEROW_WASMSIMD +#define HAS_J400TOARGBROW_WASMSIMD +#define HAS_MERGEUVROW_WASMSIMD +#define HAS_MIRRORROW_WASMSIMD +#define HAS_MIRRORSPLITUVROW_WASMSIMD +#define HAS_MIRRORUVROW_WASMSIMD +#define HAS_MULTIPLYROW_16_WASMSIMD +#define HAS_NV12TOARGBROW_WASMSIMD +#define HAS_NV12TORGB565ROW_WASMSIMD +#define HAS_NV21TOARGBROW_WASMSIMD +#define HAS_RAWTOARGBROW_WASMSIMD +#define HAS_RAWTORGB24ROW_WASMSIMD +#define HAS_RGB24MIRRORROW_WASMSIMD +#define HAS_RGB24TOARGBROW_WASMSIMD +#define HAS_RGB565TOARGBROW_WASMSIMD +#define HAS_RGB565TOUVMATRIXROW_WASMSIMD +#define HAS_RGB565TOYMATRIXROW_WASMSIMD +#define HAS_RGBTOUV444MATRIXROW_WASMSIMD +#define HAS_RGBTOUVMATRIXROW_WASMSIMD +#define HAS_RGBTOYMATRIXROW_WASMSIMD +#define HAS_SWAPUVROW_WASMSIMD +#endif + +#if !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) +#define HAS_AB64TOARGBROW_HVX +#define HAS_AR64TOAB64ROW_HVX +#define HAS_AR64TOARGBROW_HVX +#define HAS_ARGBADDROW_HVX +#define HAS_ARGBALPHABLENDROW_HVX +#define HAS_ARGBATTENUATEROW_HVX +#define HAS_ARGBBLENDROW_HVX +#define HAS_ARGBCOPYALPHAROW_HVX +#define HAS_ARGBCOPYYTOALPHAROW_HVX +#define HAS_ARGBEXTRACTALPHAROW_HVX +#define HAS_ARGBMIRRORROW_HVX +#define HAS_ARGBMULTIPLYROW_HVX +#define HAS_ARGBORROW_HVX +#define HAS_ARGBSETROW_HVX +#define HAS_ARGBSUBTRACTROW_HVX +#define HAS_ARGBTOAB64ROW_HVX +#define HAS_ARGBTOABGRROW_HVX +#define HAS_ARGBTOAR64ROW_HVX +#define HAS_ARGBTOBGRAROW_HVX +#define HAS_ARGBTORGBAROW_HVX +#define HAS_ARGBTOUV444MATRIXROW_HVX +#define HAS_ARGBTOUVMATRIXROW_HVX +#define HAS_ARGBTOYMATRIXROW_HVX +#define HAS_BLENDPLANEROW_HVX +#define HAS_CONVERT16TO8ROW_HVX +#define HAS_CONVERT8TO16ROW_HVX +#define HAS_CONVERT8TO8ROW_HVX +#define HAS_COPYROW_16_HVX +#define HAS_COPYROW_HVX +#define HAS_DIVIDEROW_16_HVX +#define HAS_HALFROW_16TO8_HVX +#define HAS_I400TOARGBROW_HVX +#define HAS_I422ALPHATOARGBROW_HVX +#define HAS_I422TOARGBROW_HVX +#define HAS_I422TORGBAROW_HVX +#define HAS_I444ALPHATOARGBROW_HVX +#define HAS_I444TOARGBROW_HVX +#define HAS_INTERPOLATEROW_16_HVX +#define HAS_INTERPOLATEROW_HVX +#define HAS_J400TOARGBROW_HVX +#define HAS_MERGEARGBROW_HVX +#define HAS_MERGEUVROW_16_HVX +#define HAS_MERGEUVROW_HVX +#define HAS_MERGEXRGBROW_HVX +#define HAS_MIRRORROW_16_HVX +#define HAS_MIRRORROW_HVX +#define HAS_MIRRORSPLITUVROW_HVX +#define HAS_MIRRORUVROW_HVX +#define HAS_MULTIPLYROW_16_HVX +#define HAS_NV12TOARGBROW_HVX +#define HAS_NV21TOARGBROW_HVX +#define HAS_RGBATOARGBROW_HVX +#define HAS_SETROW_HVX +#define HAS_SPLITARGBROW_HVX +#define HAS_SPLITUVROW_16_HVX +#define HAS_SPLITUVROW_HVX +#define HAS_SPLITXRGBROW_HVX +#define HAS_SWAPUVROW_HVX +#define HAS_UYVYTOUV422ROW_HVX +#define HAS_UYVYTOUVROW_HVX +#define HAS_UYVYTOYROW_HVX +#define HAS_YUY2TOUV422ROW_HVX +#define HAS_YUY2TOUVROW_HVX +#define HAS_YUY2TOYROW_HVX +#endif + +#undef SIMD_ALIGNED #if defined(_MSC_VER) && !defined(__CLR_VER) && !defined(__clang__) #if defined(VISUALC_HAS_AVX2) #define SIMD_ALIGNED(var) __declspec(align(32)) var #else #define SIMD_ALIGNED(var) __declspec(align(16)) var #endif +#define LIBYUV_NOINLINE __declspec(noinline) typedef __declspec(align(16)) int16_t vec16[8]; typedef __declspec(align(16)) int32_t vec32[4]; +typedef __declspec(align(16)) float vecf32[4]; typedef __declspec(align(16)) int8_t vec8[16]; typedef __declspec(align(16)) uint16_t uvec16[8]; typedef __declspec(align(16)) uint32_t uvec32[4]; @@ -594,8 +1359,10 @@ typedef __declspec(align(32)) uint8_t ulvec8[32]; #else #define SIMD_ALIGNED(var) var __attribute__((aligned(16))) #endif +#define LIBYUV_NOINLINE __attribute__((noinline)) typedef int16_t __attribute__((vector_size(16))) vec16; typedef int32_t __attribute__((vector_size(16))) vec32; +typedef float __attribute__((vector_size(16))) vecf32; typedef int8_t __attribute__((vector_size(16))) vec8; typedef uint16_t __attribute__((vector_size(16))) uvec16; typedef uint32_t __attribute__((vector_size(16))) uvec32; @@ -608,8 +1375,10 @@ typedef uint32_t __attribute__((vector_size(32))) ulvec32; typedef uint8_t __attribute__((vector_size(32))) ulvec8; #else #define SIMD_ALIGNED(var) var +#define LIBYUV_NOINLINE typedef int16_t vec16[8]; typedef int32_t vec32[4]; +typedef float vecf32[4]; typedef int8_t vec8[16]; typedef uint16_t uvec16[8]; typedef uint32_t uvec32[4]; @@ -622,65 +1391,66 @@ typedef uint32_t ulvec32[8]; typedef uint8_t ulvec8[32]; #endif -#if defined(__aarch64__) -// This struct is for Arm64 color conversion. +#if defined(__aarch64__) || defined(__arm__) || defined(__riscv) +// This struct is for ARM and RISC-V color conversion. struct YuvConstants { - uvec16 kUVToRB; - uvec16 kUVToRB2; - uvec16 kUVToG; - uvec16 kUVToG2; - vec16 kUVBiasBGR; - vec32 kYToRgb; + uvec8 kUVCoeff; + vec16 kRGBCoeffBias; }; -#elif defined(__arm__) -// This struct is for ArmV7 color conversion. -struct YuvConstants { - uvec8 kUVToRB; - uvec8 kUVToG; - vec16 kUVBiasBGR; - vec32 kYToRgb; +struct ArgbConstants { + uvec8 kRGBToY; + vec8 kRGBToU; + vec8 kRGBToV; + uvec16 kAddY; + uvec16 kAddUV; }; #else // This struct is for Intel color conversion. struct YuvConstants { - int8_t kUVToB[32]; - int8_t kUVToG[32]; - int8_t kUVToR[32]; - int16_t kUVBiasB[16]; - int16_t kUVBiasG[16]; - int16_t kUVBiasR[16]; + uint8_t kUVToB[32]; + uint8_t kUVToG[32]; + uint8_t kUVToR[32]; int16_t kYToRgb[16]; + int16_t kYBiasToRgb[16]; +}; +struct ArgbConstants { + uint8_t kRGBToY[32]; + int8_t kRGBToU[32]; + int8_t kRGBToV[32]; + uint16_t kAddY[16]; + uint16_t kAddUV[16]; }; // Offsets into YuvConstants structure #define KUVTOB 0 #define KUVTOG 32 #define KUVTOR 64 -#define KUVBIASB 96 -#define KUVBIASG 128 -#define KUVBIASR 160 -#define KYTORGB 192 +#define KYTORGB 96 +#define KYBIASTORGB 128 + #endif -// Conversion matrix for YUV to RGB -extern const struct YuvConstants SIMD_ALIGNED(kYuvI601Constants); // BT.601 -extern const struct YuvConstants SIMD_ALIGNED(kYuvJPEGConstants); // JPeg -extern const struct YuvConstants SIMD_ALIGNED(kYuvH709Constants); // BT.709 +#define IS_ALIGNED(p, a) (!((uintptr_t)(p) & ((a) - 1))) -// Conversion matrix for YVU to BGR -extern const struct YuvConstants SIMD_ALIGNED(kYvuI601Constants); // BT.601 -extern const struct YuvConstants SIMD_ALIGNED(kYvuJPEGConstants); // JPeg -extern const struct YuvConstants SIMD_ALIGNED(kYvuH709Constants); // BT.709 - -#define IS_ALIGNED(p, a) (!((uintptr_t)(p) & ((a)-1))) - -#define align_buffer_64(var, size) \ - uint8_t* var##_mem = (uint8_t*)(malloc((size) + 63)); /* NOLINT */ \ - uint8_t* var = (uint8_t*)(((intptr_t)(var##_mem) + 63) & ~63) /* NOLINT */ +#ifdef LIBYUV_MSAN +#define align_buffer_64(var, size) \ + size_t var##_mem_size = (size); /* NOLINT */ \ + void* var##_mem = (var##_mem_size > SIZE_MAX - 63) \ + ? NULL \ + : calloc(1, var##_mem_size + 63); /* NOLINT */ \ + uint8_t* var = (uint8_t*)(((intptr_t)var##_mem + 63) & ~63) /* NOLINT */ +#else +#define align_buffer_64(var, size) \ + size_t var##_mem_size = (size); /* NOLINT */ \ + void* var##_mem = (var##_mem_size > SIZE_MAX - 63) \ + ? NULL \ + : malloc(var##_mem_size + 63); /* NOLINT */ \ + uint8_t* var = (uint8_t*)(((intptr_t)var##_mem + 63) & ~63) /* NOLINT */ +#endif #define free_aligned_buffer_64(var) \ free(var##_mem); \ - var = 0 + var = NULL #if defined(__APPLE__) || defined(__x86_64__) || defined(__llvm__) #define OMITFP @@ -725,39 +1495,261 @@ extern const struct YuvConstants SIMD_ALIGNED(kYvuH709Constants); // BT.709 #define IACA_UD_BYTES __asm__ __volatile__("\n\t .byte 0x0F, 0x0B"); #else /* Visual C */ -#define IACA_UD_BYTES \ - { __asm _emit 0x0F __asm _emit 0x0B } +#define IACA_UD_BYTES {__asm _emit 0x0F __asm _emit 0x0B} #define IACA_SSC_MARK(x) \ - { __asm mov ebx, x __asm _emit 0x64 __asm _emit 0x67 __asm _emit 0x90 } + {__asm mov ebx, x __asm _emit 0x64 __asm _emit 0x67 __asm _emit 0x90} #define IACA_VC64_START __writegsbyte(111, 111); #define IACA_VC64_END __writegsbyte(222, 222); #endif -#define IACA_START \ - { \ - IACA_UD_BYTES \ - IACA_SSC_MARK(111) \ - } -#define IACA_END \ - { \ - IACA_SSC_MARK(222) \ - IACA_UD_BYTES \ - } +#define IACA_START {IACA_UD_BYTES IACA_SSC_MARK(111)} +#define IACA_END {IACA_SSC_MARK(222) IACA_UD_BYTES} +void I210AlphaToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I210AlphaToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I210AlphaToARGBRow_SME(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410AlphaToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410AlphaToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410AlphaToARGBRow_SME(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); void I444ToARGBRow_NEON(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void I444ToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444ToARGBRow_SME(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444ToRGB24Row_NEON(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void I444ToRGB24Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void I444ToRGB24Row_SME(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void I210ToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I210ToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I210ToARGBRow_SME(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410ToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410ToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410ToARGBRow_SME(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I210ToAR30Row_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I210ToAR30Row_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I210ToAR30Row_SME(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410ToAR30Row_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410ToAR30Row_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410ToAR30Row_SME(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I212ToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I212ToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I212ToARGBRow_SME(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I212ToAR30Row_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I212ToAR30Row_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I212ToAR30Row_SME(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); void I422ToARGBRow_NEON(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void I422ToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGBRow_SME(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToAR30Row_NEON(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToAR30Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToAR30Row_SME(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444AlphaToARGBRow_NEON(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444AlphaToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444AlphaToARGBRow_SME(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void I422AlphaToARGBRow_NEON(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, @@ -765,47 +1757,125 @@ void I422AlphaToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); -void I422ToARGBRow_NEON(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width); +void I422AlphaToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422AlphaToARGBRow_SME(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void I422ToRGBARow_NEON(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_rgba, const struct YuvConstants* yuvconstants, int width); +void I422ToRGBARow_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGBARow_SME(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width); void I422ToRGB24Row_NEON(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width); +void I422ToRGB24Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB24Row_SME(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); void I422ToRGB565Row_NEON(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_rgb565, const struct YuvConstants* yuvconstants, int width); +void I422ToRGB565Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB565Row_SME(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width); void I422ToARGB1555Row_NEON(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_argb1555, const struct YuvConstants* yuvconstants, int width); +void I422ToARGB1555Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB1555Row_SME(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width); void I422ToARGB4444Row_NEON(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_argb4444, const struct YuvConstants* yuvconstants, int width); +void I422ToARGB4444Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB4444Row_SME(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width); void NV12ToARGBRow_NEON(const uint8_t* src_y, const uint8_t* src_uv, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void NV12ToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToARGBRow_SME(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void NV12ToRGB565Row_NEON(const uint8_t* src_y, const uint8_t* src_uv, uint8_t* dst_rgb565, @@ -816,16 +1886,46 @@ void NV21ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void NV21ToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void NV21ToARGBRow_SME(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void NV12ToRGB24Row_NEON(const uint8_t* src_y, const uint8_t* src_uv, uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width); +void NV12ToRGB24Row_SVE2(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToRGB24Row_SME(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); void NV21ToRGB24Row_NEON(const uint8_t* src_y, const uint8_t* src_vu, uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width); +void NV21ToRGB24Row_SVE2(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void NV21ToRGB24Row_SME(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); void NV21ToYUV24Row_NEON(const uint8_t* src_y, const uint8_t* src_vu, uint8_t* dst_yuv24, @@ -834,150 +1934,317 @@ void YUY2ToARGBRow_NEON(const uint8_t* src_yuy2, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void YUY2ToARGBRow_SVE2(const uint8_t* src_yuy2, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void YUY2ToARGBRow_SME(const uint8_t* src_yuy2, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void UYVYToARGBRow_NEON(const uint8_t* src_uyvy, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); -void I444ToARGBRow_MSA(const uint8_t* src_y, +void UYVYToARGBRow_SVE2(const uint8_t* src_uyvy, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void UYVYToARGBRow_SME(const uint8_t* src_uyvy, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444ToARGBRow_RVV(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); - -void I422ToARGBRow_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width); -void I422ToRGBARow_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width); -void I422AlphaToARGBRow_MSA(const uint8_t* src_y, +void I444AlphaToARGBRow_RVV(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, const uint8_t* src_a, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); -void I422ToRGB24Row_MSA(const uint8_t* src_y, +void I444ToRGB24Row_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGBRow_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422AlphaToARGBRow_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGBARow_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB24Row_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void I422ToAR30Row_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void I444ToARGBRow_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444ToARGBRow_LASX(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); -void I422ToRGB565Row_MSA(const uint8_t* src_y, + +void I422ToARGBRow_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGBRow_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGBARow_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGBARow_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width); +void I422AlphaToARGBRow_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422AlphaToARGBRow_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB24Row_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB24Row_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB565Row_LSX(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_rgb565, const struct YuvConstants* yuvconstants, int width); -void I422ToARGB4444Row_MSA(const uint8_t* src_y, +void I422ToRGB565Row_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB4444Row_LSX(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_argb4444, const struct YuvConstants* yuvconstants, int width); -void I422ToARGB1555Row_MSA(const uint8_t* src_y, +void I422ToARGB4444Row_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB1555Row_LSX(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_argb1555, const struct YuvConstants* yuvconstants, int width); -void NV12ToARGBRow_MSA(const uint8_t* src_y, +void I422ToARGB1555Row_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width); + +void NV12ToARGBRow_LSX(const uint8_t* src_y, const uint8_t* src_uv, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); -void NV12ToRGB565Row_MSA(const uint8_t* src_y, +void NV12ToARGBRow_LASX(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToRGB565Row_LSX(const uint8_t* src_y, const uint8_t* src_uv, uint8_t* dst_rgb565, const struct YuvConstants* yuvconstants, int width); -void NV21ToARGBRow_MSA(const uint8_t* src_y, +void NV12ToRGB565Row_LASX(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width); +void NV21ToARGBRow_LSX(const uint8_t* src_y, const uint8_t* src_vu, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); -void YUY2ToARGBRow_MSA(const uint8_t* src_yuy2, +void NV21ToARGBRow_LASX(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void YUY2ToARGBRow_LSX(const uint8_t* src_yuy2, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); -void UYVYToARGBRow_MSA(const uint8_t* src_uyvy, +void YUY2ToARGBRow_LASX(const uint8_t* src_yuy2, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void UYVYToARGBRow_LSX(const uint8_t* src_uyvy, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void UYVYToARGBRow_LASX(const uint8_t* src_uyvy, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToARGBRow_RVV(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void NV21ToARGBRow_RVV(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToRGB24Row_RVV(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void NV21ToRGB24Row_RVV(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); + +void ARGBToUV444MatrixRow_NEON(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_NEON(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_Any_NEON(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_Any_NEON(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); + +void ARGBToUVMatrixRow_NEON(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_Any_NEON(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_NEON_I8MM(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_Any_NEON_I8MM(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_NEON_I8MM(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_Any_NEON_I8MM(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_SVE2(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_SME(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_SVE2(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_SME(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); -void ARGBToYRow_AVX2(const uint8_t* src_argb, uint8_t* dst_y, int width); -void ARGBToYRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ABGRToYRow_AVX2(const uint8_t* src_abgr, uint8_t* dst_y, int width); -void ABGRToYRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToYRow_SSSE3(const uint8_t* src_argb, uint8_t* dst_y, int width); -void ARGBToYJRow_AVX2(const uint8_t* src_argb, uint8_t* dst_y, int width); -void ARGBToYJRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToYJRow_SSSE3(const uint8_t* src_argb, uint8_t* dst_y, int width); -void BGRAToYRow_SSSE3(const uint8_t* src_bgra, uint8_t* dst_y, int width); -void ABGRToYRow_SSSE3(const uint8_t* src_abgr, uint8_t* dst_y, int width); -void RGBAToYRow_SSSE3(const uint8_t* src_rgba, uint8_t* dst_y, int width); -void RGB24ToYRow_SSSE3(const uint8_t* src_rgb24, uint8_t* dst_y, int width); -void RAWToYRow_SSSE3(const uint8_t* src_raw, uint8_t* dst_y, int width); -void ARGBToYRow_NEON(const uint8_t* src_argb, uint8_t* dst_y, int width); -void ARGBToYJRow_NEON(const uint8_t* src_argb, uint8_t* dst_y, int width); -void ARGBToYRow_MSA(const uint8_t* src_argb0, uint8_t* dst_y, int width); -void ARGBToYJRow_MSA(const uint8_t* src_argb0, uint8_t* dst_y, int width); -void ARGBToYRow_MMI(const uint8_t* src_argb0, uint8_t* dst_y, int width); -void ARGBToYJRow_MMI(const uint8_t* src_argb0, uint8_t* dst_y, int width); -void ARGBToUV444Row_NEON(const uint8_t* src_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVRow_NEON(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUV444Row_MSA(const uint8_t* src_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVRow_MSA(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUV444Row_MMI(const uint8_t* src_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVRow_MMI(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVJRow_NEON(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void BGRAToUVRow_NEON(const uint8_t* src_bgra, - int src_stride_bgra, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ABGRToUVRow_NEON(const uint8_t* src_abgr, - int src_stride_abgr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGBAToUVRow_NEON(const uint8_t* src_rgba, - int src_stride_rgba, - uint8_t* dst_u, - uint8_t* dst_v, - int width); void RGB24ToUVRow_NEON(const uint8_t* src_rgb24, int src_stride_rgb24, uint8_t* dst_u, @@ -988,6 +2255,7 @@ void RAWToUVRow_NEON(const uint8_t* src_raw, uint8_t* dst_u, uint8_t* dst_v, int width); + void RGB565ToUVRow_NEON(const uint8_t* src_rgb565, int src_stride_rgb565, uint8_t* dst_u, @@ -1003,96 +2271,48 @@ void ARGB4444ToUVRow_NEON(const uint8_t* src_argb4444, uint8_t* dst_u, uint8_t* dst_v, int width); -void ARGBToUVJRow_MSA(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void BGRAToUVRow_MSA(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ABGRToUVRow_MSA(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGBAToUVRow_MSA(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGB24ToUVRow_MSA(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RAWToUVRow_MSA(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGB565ToUVRow_MSA(const uint8_t* src_rgb565, - int src_stride_rgb565, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGB1555ToUVRow_MSA(const uint8_t* src_argb1555, + +void ARGB1555ToUVRow_LSX(const uint8_t* src_argb1555, int src_stride_argb1555, uint8_t* dst_u, uint8_t* dst_v, int width); -void ARGBToUVJRow_MMI(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void BGRAToUVRow_MMI(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ABGRToUVRow_MMI(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGBAToUVRow_MMI(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGB24ToUVRow_MMI(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RAWToUVRow_MMI(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGB565ToUVRow_MMI(const uint8_t* src_rgb565, +void ARGB1555ToUVRow_LASX(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void RGB565ToUVRow_LSX(const uint8_t* src_rgb565, int src_stride_rgb565, uint8_t* dst_u, uint8_t* dst_v, int width); -void ARGB1555ToUVRow_MMI(const uint8_t* src_argb1555, - int src_stride_argb1555, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGB4444ToUVRow_MMI(const uint8_t* src_argb4444, - int src_stride_argb4444, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void BGRAToYRow_NEON(const uint8_t* src_bgra, uint8_t* dst_y, int width); -void ABGRToYRow_NEON(const uint8_t* src_abgr, uint8_t* dst_y, int width); -void RGBAToYRow_NEON(const uint8_t* src_rgba, uint8_t* dst_y, int width); -void RGB24ToYRow_NEON(const uint8_t* src_rgb24, uint8_t* dst_y, int width); -void RAWToYRow_NEON(const uint8_t* src_raw, uint8_t* dst_y, int width); +void RGB565ToUVRow_LASX(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void RGB24ToUVRow_LSX(const uint8_t* src_rgb24, + int src_stride_rgb24, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void RGB24ToUVRow_LASX(const uint8_t* src_rgb24, + int src_stride_rgb24, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void RAWToUVRow_LSX(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void RAWToUVRow_LASX(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_u, + uint8_t* dst_v, + int width); + void RGB565ToYRow_NEON(const uint8_t* src_rgb565, uint8_t* dst_y, int width); void ARGB1555ToYRow_NEON(const uint8_t* src_argb1555, uint8_t* dst_y, @@ -1100,46 +2320,509 @@ void ARGB1555ToYRow_NEON(const uint8_t* src_argb1555, void ARGB4444ToYRow_NEON(const uint8_t* src_argb4444, uint8_t* dst_y, int width); -void BGRAToYRow_MSA(const uint8_t* src_argb, uint8_t* dst_y, int width); -void ABGRToYRow_MSA(const uint8_t* src_argb, uint8_t* dst_y, int width); -void RGBAToYRow_MSA(const uint8_t* src_argb, uint8_t* dst_y, int width); -void RGB24ToYRow_MSA(const uint8_t* src_argb, uint8_t* dst_y, int width); -void RAWToYRow_MSA(const uint8_t* src_argb, uint8_t* dst_y, int width); -void RGB565ToYRow_MSA(const uint8_t* src_rgb565, uint8_t* dst_y, int width); -void ARGB1555ToYRow_MSA(const uint8_t* src_argb1555, uint8_t* dst_y, int width); -void BGRAToYRow_MMI(const uint8_t* src_argb, uint8_t* dst_y, int width); -void ABGRToYRow_MMI(const uint8_t* src_argb, uint8_t* dst_y, int width); -void RGBAToYRow_MMI(const uint8_t* src_argb, uint8_t* dst_y, int width); -void RGB24ToYRow_MMI(const uint8_t* src_argb, uint8_t* dst_y, int width); -void RAWToYRow_MMI(const uint8_t* src_argb, uint8_t* dst_y, int width); -void RGB565ToYRow_MMI(const uint8_t* src_rgb565, uint8_t* dst_y, int width); -void ARGB1555ToYRow_MMI(const uint8_t* src_argb1555, uint8_t* dst_y, int width); -void ARGB4444ToYRow_MMI(const uint8_t* src_argb4444, uint8_t* dst_y, int width); -void ARGBToYRow_C(const uint8_t* src_argb, uint8_t* dst_y, int width); -void ARGBToYJRow_C(const uint8_t* src_argb, uint8_t* dst_y, int width); -void BGRAToYRow_C(const uint8_t* src_argb, uint8_t* dst_y, int width); -void ABGRToYRow_C(const uint8_t* src_argb, uint8_t* dst_y, int width); -void RGBAToYRow_C(const uint8_t* src_argb, uint8_t* dst_y, int width); -void RGB24ToYRow_C(const uint8_t* src_argb, uint8_t* dst_y, int width); -void RAWToYRow_C(const uint8_t* src_argb, uint8_t* dst_y, int width); +void ARGB1555ToYRow_LSX(const uint8_t* src_argb1555, uint8_t* dst_y, int width); + +void ARGB1555ToYRow_LASX(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width); +void RGB565ToYRow_LSX(const uint8_t* src_rgb565, uint8_t* dst_y, int width); +void RGB565ToYRow_LASX(const uint8_t* src_rgb565, uint8_t* dst_y, int width); + +void ARGBToYMatrixRow_C(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_C(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_C(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToUVMatrixRow_C(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUV444MatrixRow_C(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGB565ToYMatrixRow_C(const uint8_t* src_rgb565, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB1555ToYMatrixRow_C(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB1555ToUVMatrixRow_C(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGB4444ToYMatrixRow_C(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB4444ToUVMatrixRow_C(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGB565ToUVMatrixRow_C(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_SSSE3(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUVMatrixRow_AVX2(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUVMatrixRow_Any_AVX2(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUVMatrixRow_AVX512BW(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_AVX2(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_AVX512BW(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_AVX512VNNI(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_AVX512VNNIVBMI(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_C(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_SSSE3(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_AVX2(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_Any_AVX2(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGB565ToYMatrixRow_AVX2(const uint8_t* src_rgb565, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGB565ToYMatrixRow_Any_AVX2(const uint8_t* src_rgb565, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB1555ToYMatrixRow_AVX2(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB1555ToYMatrixRow_Any_AVX2(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB1555ToUVMatrixRow_AVX2(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGB1555ToUVMatrixRow_Any_AVX2(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGB4444ToYMatrixRow_AVX2(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB4444ToYMatrixRow_Any_AVX2(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB4444ToUVMatrixRow_AVX2(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGB4444ToUVMatrixRow_Any_AVX2(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGB565ToUVMatrixRow_AVX2(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGB565ToUVMatrixRow_Any_AVX2(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGB565ToYMatrixRow_NEON(const uint8_t* src_rgb565, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB1555ToYMatrixRow_NEON(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB1555ToUVMatrixRow_NEON(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGB4444ToYMatrixRow_NEON(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB4444ToUVMatrixRow_NEON(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGB565ToUVMatrixRow_NEON(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGB565ToYMatrixRow_Any_NEON(const uint8_t* src_rgb565, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB1555ToYMatrixRow_Any_NEON(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB1555ToUVMatrixRow_Any_NEON(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGB4444ToYMatrixRow_Any_NEON(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB4444ToUVMatrixRow_Any_NEON(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGB565ToUVMatrixRow_Any_NEON(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); + +void ARGBToYMatrixRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_AVX512VNNIVBMI(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_Any_SSSE3(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_Any_AVX2(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); + +void RGBToYMatrixRow_NEON(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); + +void RGBToUVMatrixRow_NEON(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_Any_NEON(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToUVMatrixRow_Any_NEON(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUV444MatrixRow_NEON(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUV444MatrixRow_Any_NEON(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_NEON_DotProd(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_Any_NEON_DotProd(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); + +void ARGBToYMatrixRow_NEON_DotProd(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_LSX(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_LASX(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_RVV(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_LSX(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_LASX(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_RVV(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_RVV(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_RVV(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUV444MatrixRow_RVV(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUVMatrixRow_RVV(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_SSSE3(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_Any_SSSE3(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_AVX512BW(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); + +void ARGBToYMatrixRow_Any_NEON_DotProd(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_Any_LSX(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToYMatrixRow_Any_LASX(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_Any_LSX(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_Any_LASX(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); + +void ARGBToUV444MatrixRow_SSSE3(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_AVX512VNNIVBMI(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUV444MatrixRow_SSSE3(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUV444MatrixRow_AVX2(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUV444MatrixRow_AVX512BW(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUVMatrixRow_SSSE3(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUVMatrixRow_Any_SSSE3(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_Any_SSSE3(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_Any_AVX2(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_Any_SSSE3(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_Any_AVX2(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUV444MatrixRow_Any_SSSE3(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUV444MatrixRow_Any_AVX2(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); + +// Deprecated. void RGB565ToYRow_C(const uint8_t* src_rgb565, uint8_t* dst_y, int width); void ARGB1555ToYRow_C(const uint8_t* src_argb1555, uint8_t* dst_y, int width); void ARGB4444ToYRow_C(const uint8_t* src_argb4444, uint8_t* dst_y, int width); -void ARGBToYRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToYJRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void BGRAToYRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ABGRToYRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGBAToYRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGB24ToYRow_Any_SSSE3(const uint8_t* src_rgb24, uint8_t* dst_y, int width); -void RAWToYRow_Any_SSSE3(const uint8_t* src_raw, uint8_t* dst_y, int width); -void ARGBToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToYJRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void BGRAToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ABGRToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGBAToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGB24ToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RAWToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void RGB565ToYRow_AVX2(const uint8_t* src_rgb565, uint8_t* dst_y, int width); +void ARGB1555ToYRow_AVX2(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width); +void ARGB4444ToYRow_AVX2(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width); +void RGB565ToYRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGB1555ToYRow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGB4444ToYRow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); + void RGB565ToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void ARGB1555ToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, @@ -1147,314 +2830,84 @@ void ARGB1555ToYRow_Any_NEON(const uint8_t* src_ptr, void ARGB4444ToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void BGRAToYRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ABGRToYRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGBAToYRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToYJRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToYRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGB24ToYRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RAWToYRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGB565ToYRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGB1555ToYRow_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void BGRAToYRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ABGRToYRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGBAToYRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToYJRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToYRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGB24ToYRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RAWToYRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGB565ToYRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGB1555ToYRow_Any_MMI(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGB4444ToYRow_Any_MMI(const uint8_t* src_ptr, + +void RGB565ToYRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGB1555ToYRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToUVRow_AVX2(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ABGRToUVRow_AVX2(const uint8_t* src_abgr, - int src_stride_abgr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVJRow_AVX2(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVRow_SSSE3(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVJRow_SSSE3(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void BGRAToUVRow_SSSE3(const uint8_t* src_bgra, - int src_stride_bgra, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ABGRToUVRow_SSSE3(const uint8_t* src_abgr, - int src_stride_abgr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGBAToUVRow_SSSE3(const uint8_t* src_rgba, - int src_stride_rgba, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVRow_Any_AVX2(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ABGRToUVRow_Any_AVX2(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVJRow_Any_AVX2(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVRow_Any_SSSE3(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVJRow_Any_SSSE3(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void BGRAToUVRow_Any_SSSE3(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ABGRToUVRow_Any_SSSE3(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGBAToUVRow_Any_SSSE3(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUV444Row_Any_NEON(const uint8_t* src_ptr, - uint8_t* dst_u, - uint8_t* dst_v, +void RGB565ToYRow_Any_LASX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGB1555ToYRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, int width); -void ARGBToUVRow_Any_NEON(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUV444Row_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVRow_Any_MSA(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUV444Row_Any_MMI(const uint8_t* src_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVRow_Any_MMI(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVJRow_Any_NEON(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void BGRAToUVRow_Any_NEON(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ABGRToUVRow_Any_NEON(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGBAToUVRow_Any_NEON(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); + void RGB24ToUVRow_Any_NEON(const uint8_t* src_ptr, - int src_stride_ptr, + int src_stride, uint8_t* dst_u, uint8_t* dst_v, int width); void RAWToUVRow_Any_NEON(const uint8_t* src_ptr, - int src_stride_ptr, + int src_stride, uint8_t* dst_u, uint8_t* dst_v, int width); + void RGB565ToUVRow_Any_NEON(const uint8_t* src_ptr, - int src_stride_ptr, + int src_stride, uint8_t* dst_u, uint8_t* dst_v, int width); void ARGB1555ToUVRow_Any_NEON(const uint8_t* src_ptr, - int src_stride_ptr, + int src_stride, uint8_t* dst_u, uint8_t* dst_v, int width); void ARGB4444ToUVRow_Any_NEON(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void ARGB1555ToUVRow_Any_LSX(const uint8_t* src_ptr, + int src_stride_ptr, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void ARGB1555ToUVRow_Any_LASX(const uint8_t* src_ptr, int src_stride_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); -void ARGBToUVJRow_Any_MSA(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void BGRAToUVRow_Any_MSA(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ABGRToUVRow_Any_MSA(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGBAToUVRow_Any_MSA(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGB24ToUVRow_Any_MSA(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RAWToUVRow_Any_MSA(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGB565ToUVRow_Any_MSA(const uint8_t* src_ptr, +void RGB565ToUVRow_Any_LSX(const uint8_t* src_ptr, int src_stride_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); -void ARGB1555ToUVRow_Any_MSA(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVJRow_Any_MMI(const uint8_t* src_ptr, +void RGB565ToUVRow_Any_LASX(const uint8_t* src_ptr, + int src_stride_ptr, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void RGB24ToUVRow_Any_LSX(const uint8_t* src_ptr, int src_stride_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); -void BGRAToUVRow_Any_MMI(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ABGRToUVRow_Any_MMI(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGBAToUVRow_Any_MMI(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGB24ToUVRow_Any_MMI(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RAWToUVRow_Any_MMI(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGB565ToUVRow_Any_MMI(const uint8_t* src_ptr, +void RGB24ToUVRow_Any_LASX(const uint8_t* src_ptr, int src_stride_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); -void ARGB1555ToUVRow_Any_MMI(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGB4444ToUVRow_Any_MMI(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVRow_C(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVJRow_C(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVRow_C(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ARGBToUVJRow_C(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void BGRAToUVRow_C(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void ABGRToUVRow_C(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGBAToUVRow_C(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RGB24ToUVRow_C(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void RAWToUVRow_C(const uint8_t* src_rgb, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); +void RAWToUVRow_Any_LSX(const uint8_t* src_ptr, + int src_stride_ptr, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void RAWToUVRow_Any_LASX(const uint8_t* src_ptr, + int src_stride_ptr, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +// Deprecated. void RGB565ToUVRow_C(const uint8_t* src_rgb565, int src_stride_rgb565, uint8_t* dst_u, @@ -1470,60 +2923,115 @@ void ARGB4444ToUVRow_C(const uint8_t* src_argb4444, uint8_t* dst_u, uint8_t* dst_v, int width); - -void ARGBToUV444Row_SSSE3(const uint8_t* src_argb, +void RGB565ToUVRow_AVX2(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void ARGB1555ToUVRow_AVX2(const uint8_t* src_argb1555, + int src_stride_argb1555, uint8_t* dst_u, uint8_t* dst_v, int width); -void ARGBToUV444Row_Any_SSSE3(const uint8_t* src_ptr, +void ARGB4444ToUVRow_AVX2(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void RGB565ToUVRow_Any_AVX2(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void ARGB1555ToUVRow_Any_AVX2(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void ARGB4444ToUVRow_Any_AVX2(const uint8_t* src_ptr, + int src_stride, uint8_t* dst_u, uint8_t* dst_v, int width); -void ARGBToUV444Row_C(const uint8_t* src_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width); - +void MirrorRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width); void MirrorRow_AVX2(const uint8_t* src, uint8_t* dst, int width); void MirrorRow_SSSE3(const uint8_t* src, uint8_t* dst, int width); void MirrorRow_NEON(const uint8_t* src, uint8_t* dst, int width); -void MirrorRow_MSA(const uint8_t* src, uint8_t* dst, int width); -void MirrorRow_MMI(const uint8_t* src, uint8_t* dst, int width); +void MirrorRow_LSX(const uint8_t* src, uint8_t* dst, int width); +void MirrorRow_LASX(const uint8_t* src, uint8_t* dst, int width); void MirrorRow_C(const uint8_t* src, uint8_t* dst, int width); void MirrorRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void MirrorRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void MirrorRow_Any_SSE2(const uint8_t* src, uint8_t* dst, int width); void MirrorRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void MirrorRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void MirrorRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void MirrorRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void MirrorRow_Any_LASX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void MirrorUVRow_AVX512BW(const uint8_t* src_uv, uint8_t* dst_uv, int width); +void MirrorUVRow_AVX2(const uint8_t* src_uv, uint8_t* dst_uv, int width); +void MirrorUVRow_SSSE3(const uint8_t* src_uv, uint8_t* dst_uv, int width); +void MirrorUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_uv, int width); +void MirrorUVRow_LSX(const uint8_t* src_uv, uint8_t* dst_uv, int width); +void MirrorUVRow_LASX(const uint8_t* src_uv, uint8_t* dst_uv, int width); +void MirrorUVRow_RVV(const uint8_t* src_uv, uint8_t* dst_uv, int width); +void MirrorUVRow_C(const uint8_t* src_uv, uint8_t* dst_uv, int width); +void MirrorUVRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void MirrorUVRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void MirrorUVRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void MirrorUVRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void MirrorUVRow_Any_LASX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void MirrorUVRow_SSSE3(const uint8_t* src, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void MirrorUVRow_NEON(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void MirrorUVRow_MSA(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void MirrorUVRow_MMI(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void MirrorUVRow_C(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width); +void MirrorSplitUVRow_AVX512BW(const uint8_t* src, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void MirrorSplitUVRow_AVX2(const uint8_t* src, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void MirrorSplitUVRow_SSSE3(const uint8_t* src, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void MirrorSplitUVRow_Any_AVX2(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void MirrorSplitUVRow_Any_SSSE3(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void MirrorSplitUVRow_NEON(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void MirrorSplitUVRow_LSX(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void MirrorSplitUVRow_LASX(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void MirrorSplitUVRow_C(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); + +void MirrorRow_16_C(const uint16_t* src, uint16_t* dst, int width); +void MirrorRow_16_AVX512BW(const uint16_t* src, uint16_t* dst, int width); +void MirrorRow_16_NEON(const uint16_t* src, uint16_t* dst, int width); +void MirrorRow_16_Any_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int width); void ARGBMirrorRow_AVX2(const uint8_t* src, uint8_t* dst, int width); +void ARGBMirrorRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width); void ARGBMirrorRow_SSE2(const uint8_t* src, uint8_t* dst, int width); -void ARGBMirrorRow_NEON(const uint8_t* src, uint8_t* dst, int width); -void ARGBMirrorRow_MSA(const uint8_t* src, uint8_t* dst, int width); -void ARGBMirrorRow_MMI(const uint8_t* src, uint8_t* dst, int width); +void ARGBMirrorRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width); +void ARGBMirrorRow_LSX(const uint8_t* src, uint8_t* dst, int width); +void ARGBMirrorRow_LASX(const uint8_t* src, uint8_t* dst, int width); +void ARGBMirrorRow_RVV(const uint8_t* src, uint8_t* dst, int width); +void ARGBMirrorRow_WASMSIMD(const uint8_t* src, uint8_t* dst, int width); void ARGBMirrorRow_C(const uint8_t* src, uint8_t* dst, int width); void ARGBMirrorRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, @@ -1534,8 +3042,33 @@ void ARGBMirrorRow_Any_SSE2(const uint8_t* src_ptr, void ARGBMirrorRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBMirrorRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBMirrorRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGBMirrorRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGBMirrorRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); + +void RGB24MirrorRow_SSSE3(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width); +void RGB24MirrorRow_AVX2(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width); +void RGB24MirrorRow_AVX512VBMI(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width); +void RGB24MirrorRow_NEON(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width); +void RGB24MirrorRow_C(const uint8_t* src_rgb24, uint8_t* dst_rgb24, int width); +void RGB24MirrorRow_Any_SSSE3(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void RGB24MirrorRow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void RGB24MirrorRow_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void SplitUVRow_C(const uint8_t* src_uv, uint8_t* dst_u, @@ -1545,6 +3078,10 @@ void SplitUVRow_SSE2(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, int width); +void SplitUVRow_AVX512BW(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); void SplitUVRow_AVX2(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, @@ -1553,11 +3090,19 @@ void SplitUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, int width); -void SplitUVRow_MSA(const uint8_t* src_uv, +void SplitUVRow_SVE2(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void SplitUVRow_LSX(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, int width); -void SplitUVRow_MMI(const uint8_t* src_uv, +void SplitUVRow_LASX(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void SplitUVRow_RVV(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, int width); @@ -1573,15 +3118,112 @@ void SplitUVRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); -void SplitUVRow_Any_MSA(const uint8_t* src_ptr, +void SplitUVRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); -void SplitUVRow_Any_MMI(const uint8_t* src_ptr, +void SplitUVRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void DetileRow_C(const uint8_t* src, + ptrdiff_t src_tile_stride, + uint8_t* dst, + int width); +void DetileRow_NEON(const uint8_t* src, + ptrdiff_t src_tile_stride, + uint8_t* dst, + int width); +void DetileRow_Any_NEON(const uint8_t* src, + ptrdiff_t src_tile_stride, + uint8_t* dst, + int width); +void DetileRow_AVX2(const uint8_t* src, + ptrdiff_t src_tile_stride, + uint8_t* dst, + int width); +void DetileRow_Any_AVX2(const uint8_t* src, + ptrdiff_t src_tile_stride, + uint8_t* dst, + int width); +void DetileRow_16_C(const uint16_t* src, + ptrdiff_t src_tile_stride, + uint16_t* dst, + int width); +void DetileRow_16_NEON(const uint16_t* src, + ptrdiff_t src_tile_stride, + uint16_t* dst, + int width); +void DetileRow_16_Any_NEON(const uint16_t* src, + ptrdiff_t src_tile_stride, + uint16_t* dst, + int width); +void DetileRow_16_AVX2(const uint16_t* src, + ptrdiff_t src_tile_stride, + uint16_t* dst, + int width); +void DetileRow_16_Any_AVX2(const uint16_t* src, + ptrdiff_t src_tile_stride, + uint16_t* dst, + int width); +void DetileSplitUVRow_C(const uint8_t* src_uv, + ptrdiff_t src_tile_stride, uint8_t* dst_u, uint8_t* dst_v, int width); - +void DetileSplitUVRow_AVX2(const uint8_t* src_uv, + ptrdiff_t src_tile_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void DetileSplitUVRow_Any_AVX2(const uint8_t* src_uv, + ptrdiff_t src_tile_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void DetileSplitUVRow_NEON(const uint8_t* src_uv, + ptrdiff_t src_tile_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void DetileSplitUVRow_Any_NEON(const uint8_t* src_uv, + ptrdiff_t src_tile_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void DetileToYUY2_C(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width); +void DetileToYUY2_AVX2(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width); +void DetileToYUY2_Any_AVX2(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width); +void DetileToYUY2_NEON(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width); +void DetileToYUY2_Any_NEON(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width); +void UnpackMT2T_C(const uint8_t* src, uint16_t* dst, size_t size); +void UnpackMT2T_AVX2(const uint8_t* src, uint16_t* dst, size_t size); +void UnpackMT2T_NEON(const uint8_t* src, uint16_t* dst, size_t size); void MergeUVRow_C(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, @@ -1594,15 +3236,31 @@ void MergeUVRow_AVX2(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width); +void MergeUVRow_AVX512BW(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width); void MergeUVRow_NEON(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width); -void MergeUVRow_MSA(const uint8_t* src_u, +void MergeUVRow_SVE2(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width); +void MergeUVRow_SME(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width); -void MergeUVRow_MMI(const uint8_t* src_u, +void MergeUVRow_LSX(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width); +void MergeUVRow_LASX(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width); +void MergeUVRow_RVV(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width); @@ -1618,14 +3276,67 @@ void MergeUVRow_Any_NEON(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void MergeUVRow_Any_MSA(const uint8_t* y_buf, - const uint8_t* uv_buf, - uint8_t* dst_ptr, - int width); -void MergeUVRow_Any_MMI(const uint8_t* y_buf, +void MergeUVRow_Any_LSX(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); +void MergeUVRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); + +void HalfMergeUVRow_C(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width); + +void HalfMergeUVRow_NEON(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width); + +void HalfMergeUVRow_SVE2(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width); + +void HalfMergeUVRow_SSSE3(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width); + +void HalfMergeUVRow_AVX2(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width); +void HalfMergeUVRow_AVX512BW(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width); +void HalfMergeUVRow_Any_SSSE3(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width); +void HalfMergeUVRow_Any_AVX2(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width); void SplitRGBRow_C(const uint8_t* src_rgb, uint8_t* dst_r, @@ -1637,12 +3348,22 @@ void SplitRGBRow_SSSE3(const uint8_t* src_rgb, uint8_t* dst_g, uint8_t* dst_b, int width); +void SplitRGBRow_SSE41(const uint8_t* src_rgb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void SplitRGBRow_AVX2(const uint8_t* src_rgb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); void SplitRGBRow_NEON(const uint8_t* src_rgb, uint8_t* dst_r, uint8_t* dst_g, uint8_t* dst_b, int width); -void SplitRGBRow_MMI(const uint8_t* src_rgb, +void SplitRGBRow_RVV(const uint8_t* src_rgb, uint8_t* dst_r, uint8_t* dst_g, uint8_t* dst_b, @@ -1652,93 +3373,599 @@ void SplitRGBRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_g, uint8_t* dst_b, int width); +void SplitRGBRow_Any_SSE41(const uint8_t* src_ptr, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void SplitRGBRow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); void SplitRGBRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_r, uint8_t* dst_g, uint8_t* dst_b, int width); -void SplitRGBRow_Any_MMI(const uint8_t* src_ptr, - uint8_t* dst_r, - uint8_t* dst_g, - uint8_t* dst_b, - int width); void MergeRGBRow_C(const uint8_t* src_r, const uint8_t* src_g, const uint8_t* src_b, uint8_t* dst_rgb, int width); -void MergeRGBRow_SSSE3(const uint8_t* src_r, - const uint8_t* src_g, - const uint8_t* src_b, - uint8_t* dst_rgb, - int width); +void MergeRGBRow_AVX2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_rgb, + int width); void MergeRGBRow_NEON(const uint8_t* src_r, const uint8_t* src_g, const uint8_t* src_b, uint8_t* dst_rgb, int width); -void MergeRGBRow_MMI(const uint8_t* src_r, +void MergeRGBRow_RVV(const uint8_t* src_r, const uint8_t* src_g, const uint8_t* src_b, uint8_t* dst_rgb, int width); -void MergeRGBRow_Any_SSSE3(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_ptr, - int width); +void MergeRGBRow_AVX512VBMI(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_rgb, + int width); +void MergeRGBRow_Any_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + int width); void MergeRGBRow_Any_NEON(const uint8_t* src_r, const uint8_t* src_g, const uint8_t* src_b, uint8_t* dst_rgb, int width); -void MergeRGBRow_Any_MMI(const uint8_t* src_r, - const uint8_t* src_g, - const uint8_t* src_b, - uint8_t* dst_rgb, +void MergeARGBRow_C(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width); +void MergeARGBRow_SSE2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width); +void MergeARGBRow_AVX2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width); +void MergeARGBRow_NEON(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width); +void MergeARGBRow_RVV(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width); +void MergeARGBRow_Any_SSE2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_ptr, + int width); +void MergeARGBRow_Any_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_ptr, + int width); +void MergeARGBRow_Any_NEON(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_ptr, + int width); +void SplitARGBRow_C(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width); +void SplitARGBRow_SSE2(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width); +void SplitARGBRow_SSSE3(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width); +void SplitARGBRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width); +void SplitARGBRow_NEON(const uint8_t* src_rgba, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width); +void SplitARGBRow_RVV(const uint8_t* src_rgba, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width); +void SplitARGBRow_Any_SSE2(const uint8_t* src_ptr, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width); +void SplitARGBRow_Any_SSSE3(const uint8_t* src_ptr, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width); +void SplitARGBRow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width); +void SplitARGBRow_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width); +void MergeXRGBRow_C(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width); +void MergeXRGBRow_SSE2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width); +void MergeXRGBRow_AVX2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width); +void MergeXRGBRow_NEON(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width); +void MergeXRGBRow_RVV(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width); +void MergeXRGBRow_Any_SSE2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + int width); +void MergeXRGBRow_Any_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + int width); +void MergeXRGBRow_Any_NEON(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + int width); +void SplitXRGBRow_C(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void SplitXRGBRow_SSE2(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void SplitXRGBRow_SSSE3(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void SplitXRGBRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void SplitXRGBRow_NEON(const uint8_t* src_rgba, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void SplitXRGBRow_RVV(const uint8_t* src_rgba, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void SplitXRGBRow_Any_SSE2(const uint8_t* src_ptr, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void SplitXRGBRow_Any_SSSE3(const uint8_t* src_ptr, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void SplitXRGBRow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void SplitXRGBRow_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); + +void MergeXR30Row_C(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int depth, + int width); +void MergeAR64Row_C(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint16_t* dst_ar64, + int depth, + int width); +void MergeARGB16To8Row_C(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint8_t* dst_argb, + int depth, int width); +void MergeXR64Row_C(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint16_t* dst_ar64, + int depth, + int width); +void MergeXRGB16To8Row_C(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_argb, + int depth, + int width); +void MergeXR30Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int depth, + int width); +void MergeXR30Row_10_AVX512BW(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int depth, + int width); +void MergeAR64Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint16_t* dst_ar64, + int depth, + int width); +void MergeARGB16To8Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint8_t* dst_argb, + int depth, + int width); +void MergeXR64Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint16_t* dst_ar64, + int depth, + int width); +void MergeXRGB16To8Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_argb, + int depth, + int width); +void MergeXR30Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int depth, + int width); +void MergeXR30Row_10_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int /* depth */, + int width); +void MergeAR64Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint16_t* dst_ar64, + int depth, + int width); +void MergeARGB16To8Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint8_t* dst_argb, + int depth, + int width); +void MergeXR64Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint16_t* dst_ar64, + int depth, + int width); +void MergeXRGB16To8Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_argb, + int depth, + int width); +void MergeXR30Row_Any_AVX2(const uint16_t* r_buf, + const uint16_t* g_buf, + const uint16_t* b_buf, + uint8_t* dst_ptr, + int depth, + int width); +void MergeAR64Row_Any_AVX2(const uint16_t* r_buf, + const uint16_t* g_buf, + const uint16_t* b_buf, + const uint16_t* a_buf, + uint16_t* dst_ptr, + int depth, + int width); +void MergeXR64Row_Any_AVX2(const uint16_t* r_buf, + const uint16_t* g_buf, + const uint16_t* b_buf, + uint16_t* dst_ptr, + int depth, + int width); +void MergeARGB16To8Row_Any_AVX2(const uint16_t* r_buf, + const uint16_t* g_buf, + const uint16_t* b_buf, + const uint16_t* a_buf, + uint8_t* dst_ptr, + int depth, + int width); +void MergeXRGB16To8Row_Any_AVX2(const uint16_t* r_buf, + const uint16_t* g_buf, + const uint16_t* b_buf, + uint8_t* dst_ptr, + int depth, + int width); +void MergeXR30Row_Any_NEON(const uint16_t* r_buf, + const uint16_t* g_buf, + const uint16_t* b_buf, + uint8_t* dst_ptr, + int depth, + int width); +void MergeXR30Row_10_Any_NEON(const uint16_t* r_buf, + const uint16_t* g_buf, + const uint16_t* b_buf, + uint8_t* dst_ptr, + int depth, + int width); +void MergeAR64Row_Any_NEON(const uint16_t* r_buf, + const uint16_t* g_buf, + const uint16_t* b_buf, + const uint16_t* a_buf, + uint16_t* dst_ptr, + int depth, + int width); +void MergeARGB16To8Row_Any_NEON(const uint16_t* r_buf, + const uint16_t* g_buf, + const uint16_t* b_buf, + const uint16_t* a_buf, + uint8_t* dst_ptr, + int depth, + int width); +void MergeXR64Row_Any_NEON(const uint16_t* r_buf, + const uint16_t* g_buf, + const uint16_t* b_buf, + uint16_t* dst_ptr, + int depth, + int width); +void MergeXRGB16To8Row_Any_NEON(const uint16_t* r_buf, + const uint16_t* g_buf, + const uint16_t* b_buf, + uint8_t* dst_ptr, + int depth, + int width); void MergeUVRow_16_C(const uint16_t* src_u, const uint16_t* src_v, uint16_t* dst_uv, - int scale, /* 64 for 10 bit */ + int depth, int width); void MergeUVRow_16_AVX2(const uint16_t* src_u, const uint16_t* src_v, uint16_t* dst_uv, - int scale, + int depth, int width); +void MergeUVRow_16_AVX512BW(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width); +void MergeUVRow_16_Any_AVX2(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width); +void MergeUVRow_16_NEON(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width); +void MergeUVRow_16_Any_NEON(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width); +void MergeUVRow_16_SME(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width); + +void SplitUVRow_16_C(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width); +void SplitUVRow_16_AVX2(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width); +void SplitUVRow_16_Any_AVX2(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width); +void SplitUVRow_16_NEON(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width); +void SplitUVRow_16_Any_NEON(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width); -void MultiplyRow_16_AVX2(const uint16_t* src_y, - uint16_t* dst_y, - int scale, - int width); void MultiplyRow_16_C(const uint16_t* src_y, uint16_t* dst_y, int scale, int width); +void MultiplyRow_16_AVX2(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); +void MultiplyRow_16_Any_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int scale, + int width); +void MultiplyRow_16_AVX512BW(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); +void MultiplyRow_16_NEON(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); +void MultiplyRow_16_Any_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int scale, + int width); +void MultiplyRow_16_SME(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); +void MultiplyRow_16_RVV(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); -void Convert8To16Row_C(const uint8_t* src_y, +void DivideRow_16_C(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); +void DivideRow_16_AVX2(const uint16_t* src_y, uint16_t* dst_y, int scale, int width); +void DivideRow_16_AVX512BW(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); +void DivideRow_16_Any_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int scale, + int width); +void DivideRow_16_NEON(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); +void DivideRow_16_SVE2(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); +void DivideRow_16_Any_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int scale, + int width); + +void Convert8To16Row_C(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width); void Convert8To16Row_SSE2(const uint8_t* src_y, uint16_t* dst_y, - int scale, + int bits, int width); void Convert8To16Row_AVX2(const uint8_t* src_y, uint16_t* dst_y, - int scale, + int bits, int width); +void Convert8To16Row_AVX512BW(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width); void Convert8To16Row_Any_SSE2(const uint8_t* src_ptr, uint16_t* dst_ptr, - int scale, + int bits, int width); void Convert8To16Row_Any_AVX2(const uint8_t* src_ptr, uint16_t* dst_ptr, - int scale, + int bits, int width); +void Convert8To16Row_NEON(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width); +void Convert8To16Row_Any_NEON(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width); +void Convert8To16Row_SME(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width); +void Convert8To16Row_RVV(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width); void Convert16To8Row_C(const uint16_t* src_y, uint8_t* dst_y, @@ -1752,6 +3979,10 @@ void Convert16To8Row_AVX2(const uint16_t* src_y, uint8_t* dst_y, int scale, int width); +void Convert16To8Row_AVX512BW(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width); void Convert16To8Row_Any_SSSE3(const uint16_t* src_ptr, uint8_t* dst_ptr, int scale, @@ -1760,32 +3991,252 @@ void Convert16To8Row_Any_AVX2(const uint16_t* src_ptr, uint8_t* dst_ptr, int scale, int width); +void Convert16To8Row_NEON(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width); +void Convert16To8Row_Any_NEON(const uint16_t* src_ptr, + uint8_t* dst_ptr, + int scale, + int width); +void Convert16To8Row_SME(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width); +void Convert16To8Row_SVE2(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width); +void Convert16To8Row_RVV(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width); + +void HalfRow_C(const uint8_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int width); +void HalfRow_AVX2(const uint8_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int width); +void HalfRow_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int width); + +void HalfRow_16_C(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint16_t* dst_uv, + int width); +void HalfRow_16_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint16_t* dst_uv, + int width); +void HalfRow_16_Any_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int width); + +void HalfRow_16To8_C(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfRow_16To8_SSSE3(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfRow_16To8_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfRow_16To8_AVX512BW(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfRow_16To8_Any_SSSE3(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int scale, + int width); +void HalfRow_16To8_Any_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int scale, + int width); +void HalfRow_16To8_NEON(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfRow_16To8_Any_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int scale, + int width); +void HalfRow_16To8_SVE2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfRow_16To8_SME(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfRow_16To8_RVV(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); + +void HalfWidthRow_16To8_C(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfWidthRow_16To8_Odd_C(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfWidthRow_16To8_Odd_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfWidthRow_16To8_SSSE3(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfWidthRow_16To8_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfWidthRow_16To8_AVX512BW(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfWidthRow_16To8_Any_SSSE3(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int scale, + int width); +void HalfWidthRow_16To8_Any_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int scale, + int width); +void HalfWidthRow_16To8_NEON(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfWidthRow_16To8_Any_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int scale, + int width); +void HalfWidthRow_16To8_SVE2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfWidthRow_16To8_SME(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void HalfWidthRow_16To8_RVV(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); + +void Convert8To8Row_C(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width); +void Convert8To8Row_NEON(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width); +void Convert8To8Row_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int scale, + int bias, + int width); +void Convert8To8Row_SVE2(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width); +void Convert8To8Row_SME(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width); +void Convert8To8Row_AVX2(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width); +void Convert8To8Row_AVX512BW(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width); +void Convert8To8Row_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int scale, + int bias, + int width); void CopyRow_SSE2(const uint8_t* src, uint8_t* dst, int width); void CopyRow_AVX(const uint8_t* src, uint8_t* dst, int width); +void CopyRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width); void CopyRow_ERMS(const uint8_t* src, uint8_t* dst, int width); void CopyRow_NEON(const uint8_t* src, uint8_t* dst, int width); -void CopyRow_MIPS(const uint8_t* src, uint8_t* dst, int count); +void CopyRow_SVE2(const uint8_t* src, uint8_t* dst, int width); +void CopyRow_SME(const uint8_t* src, uint8_t* dst, int width); +void CopyRow_RVV(const uint8_t* src, uint8_t* dst, int count); +void CopyRow_LSX(const uint8_t* src, uint8_t* dst, int width); +void CopyRow_LASX(const uint8_t* src, uint8_t* dst, int width); void CopyRow_C(const uint8_t* src, uint8_t* dst, int count); void CopyRow_Any_SSE2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void CopyRow_Any_AVX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void CopyRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void CopyRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void CopyRow_Any_LASX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void CopyRow_16_C(const uint16_t* src, uint16_t* dst, int count); +void CopyRow_16_AVX2(const uint16_t* src, uint16_t* dst, int count); +void CopyRow_16_Any_AVX2(const uint16_t* src_ptr, uint16_t* dst_ptr, int width); +void CopyRow_16_NEON(const uint16_t* src, uint16_t* dst, int count); +void CopyRow_16_Any_NEON(const uint16_t* src_ptr, uint16_t* dst_ptr, int width); void ARGBCopyAlphaRow_C(const uint8_t* src, uint8_t* dst, int width); void ARGBCopyAlphaRow_SSE2(const uint8_t* src, uint8_t* dst, int width); void ARGBCopyAlphaRow_AVX2(const uint8_t* src, uint8_t* dst, int width); -void ARGBCopyAlphaRow_MMI(const uint8_t* src, uint8_t* dst, int width); +void ARGBCopyAlphaRow_NEON(const uint8_t* src, uint8_t* dst, int width); void ARGBCopyAlphaRow_Any_SSE2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void ARGBCopyAlphaRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBCopyAlphaRow_Any_MMI(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); +void ARGBCopyAlphaRow_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void ARGBExtractAlphaRow_C(const uint8_t* src_argb, uint8_t* dst_a, int width); void ARGBExtractAlphaRow_SSE2(const uint8_t* src_argb, @@ -1794,13 +4245,22 @@ void ARGBExtractAlphaRow_SSE2(const uint8_t* src_argb, void ARGBExtractAlphaRow_AVX2(const uint8_t* src_argb, uint8_t* dst_a, int width); +void ARGBExtractAlphaRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_a, + int width); void ARGBExtractAlphaRow_NEON(const uint8_t* src_argb, uint8_t* dst_a, int width); -void ARGBExtractAlphaRow_MSA(const uint8_t* src_argb, +void ARGBExtractAlphaRow_LSX(const uint8_t* src_argb, uint8_t* dst_a, int width); -void ARGBExtractAlphaRow_MMI(const uint8_t* src_argb, +void ARGBExtractAlphaRow_LASX(const uint8_t* src_argb, + uint8_t* dst_a, + int width); +void ARGBExtractAlphaRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_a, + int width); +void ARGBExtractAlphaRow_RVV(const uint8_t* src_argb, uint8_t* dst_a, int width); void ARGBExtractAlphaRow_Any_SSE2(const uint8_t* src_ptr, @@ -1812,41 +4272,57 @@ void ARGBExtractAlphaRow_Any_AVX2(const uint8_t* src_ptr, void ARGBExtractAlphaRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBExtractAlphaRow_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGBExtractAlphaRow_Any_MMI(const uint8_t* src_ptr, +void ARGBExtractAlphaRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGBExtractAlphaRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBExtractAlphaRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void ARGBCopyYToAlphaRow_C(const uint8_t* src, uint8_t* dst, int width); void ARGBCopyYToAlphaRow_SSE2(const uint8_t* src, uint8_t* dst, int width); void ARGBCopyYToAlphaRow_AVX2(const uint8_t* src, uint8_t* dst, int width); -void ARGBCopyYToAlphaRow_MMI(const uint8_t* src, uint8_t* dst, int width); +void ARGBCopyYToAlphaRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width); +void ARGBCopyYToAlphaRow_NEON(const uint8_t* src, uint8_t* dst, int width); +void ARGBCopyYToAlphaRow_WASMSIMD(const uint8_t* src, uint8_t* dst, int width); +void ARGBCopyYToAlphaRow_RVV(const uint8_t* src, uint8_t* dst, int width); void ARGBCopyYToAlphaRow_Any_SSE2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void ARGBCopyYToAlphaRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBCopyYToAlphaRow_Any_MMI(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); +void ARGBCopyYToAlphaRow_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBCopyYToAlphaRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void SetRow_C(uint8_t* dst, uint8_t v8, int width); -void SetRow_MSA(uint8_t* dst, uint8_t v8, int width); -void SetRow_X86(uint8_t* dst, uint8_t v8, int width); void SetRow_ERMS(uint8_t* dst, uint8_t v8, int width); +void SetRow_AVX2(uint8_t* dst, uint8_t v8, int width); void SetRow_NEON(uint8_t* dst, uint8_t v8, int width); -void SetRow_Any_X86(uint8_t* dst_ptr, uint8_t v32, int width); +void SetRow_LSX(uint8_t* dst, uint8_t v8, int width); +void SetRow_LASX(uint8_t* dst, uint8_t v8, int width); +void SetRow_Any_AVX2(uint8_t* dst_ptr, uint8_t v32, int width); void SetRow_Any_NEON(uint8_t* dst_ptr, uint8_t v32, int width); +void SetRow_Any_LSX(uint8_t* dst_ptr, uint8_t v32, int width); +void SetRow_Any_LASX(uint8_t* dst_ptr, uint8_t v32, int width); void ARGBSetRow_C(uint8_t* dst_argb, uint32_t v32, int width); -void ARGBSetRow_X86(uint8_t* dst_argb, uint32_t v32, int width); +void ARGBSetRow_AVX2(uint8_t* dst_argb, uint32_t v32, int width); void ARGBSetRow_NEON(uint8_t* dst, uint32_t v32, int width); +void ARGBSetRow_RVV(uint8_t* dst_argb, uint32_t v32, int width); +void ARGBSetRow_Any_AVX2(uint8_t* dst_ptr, uint32_t v32, int width); void ARGBSetRow_Any_NEON(uint8_t* dst_ptr, uint32_t v32, int width); -void ARGBSetRow_MSA(uint8_t* dst_argb, uint32_t v32, int width); -void ARGBSetRow_Any_MSA(uint8_t* dst_ptr, uint32_t v32, int width); +void ARGBSetRow_LSX(uint8_t* dst_argb, uint32_t v32, int width); +void ARGBSetRow_LASX(uint8_t* dst_argb, uint32_t v32, int width); +void ARGBSetRow_Any_LSX(uint8_t* dst_ptr, uint32_t v32, int width); +void ARGBSetRow_Any_LASX(uint8_t* dst_ptr, uint32_t v32, int width); // ARGBShufflers for BGRAToARGB etc. void ARGBShuffleRow_C(const uint8_t* src_argb, @@ -1861,18 +4337,26 @@ void ARGBShuffleRow_AVX2(const uint8_t* src_argb, uint8_t* dst_argb, const uint8_t* shuffler, int width); +void ARGBShuffleRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + const uint8_t* shuffler, + int width); void ARGBShuffleRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, const uint8_t* shuffler, int width); -void ARGBShuffleRow_MSA(const uint8_t* src_argb, +void ARGBShuffleRow_RVV(const uint8_t* src_argb, uint8_t* dst_argb, const uint8_t* shuffler, int width); -void ARGBShuffleRow_MMI(const uint8_t* src_argb, +void ARGBShuffleRow_LSX(const uint8_t* src_argb, uint8_t* dst_argb, const uint8_t* shuffler, int width); +void ARGBShuffleRow_LASX(const uint8_t* src_argb, + uint8_t* dst_argb, + const uint8_t* shuffler, + int width); void ARGBShuffleRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, const uint8_t* param, @@ -1885,29 +4369,46 @@ void ARGBShuffleRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, const uint8_t* param, int width); -void ARGBShuffleRow_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - const uint8_t* param, - int width); -void ARGBShuffleRow_Any_MMI(const uint8_t* src_ptr, +void ARGBShuffleRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, const uint8_t* param, int width); +void ARGBShuffleRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + const uint8_t* param, + int width); void RGB24ToARGBRow_SSSE3(const uint8_t* src_rgb24, uint8_t* dst_argb, int width); void RAWToARGBRow_SSSE3(const uint8_t* src_raw, uint8_t* dst_argb, int width); +void RAWToARGBRow_AVX2(const uint8_t* src_raw, uint8_t* dst_argb, int width); +void RGB24ToARGBRow_AVX2(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width); +void RAWToARGBRow_AVX512BW(const uint8_t* src_raw, + uint8_t* dst_argb, + int width); +void RAWToRGBARow_AVX2(const uint8_t* src_raw, uint8_t* dst_rgba, int width); void RAWToRGB24Row_SSSE3(const uint8_t* src_raw, uint8_t* dst_rgb24, int width); -void RGB565ToARGBRow_SSE2(const uint8_t* src, uint8_t* dst, int width); -void ARGB1555ToARGBRow_SSE2(const uint8_t* src, uint8_t* dst, int width); -void ARGB4444ToARGBRow_SSE2(const uint8_t* src, uint8_t* dst, int width); +void RAWToRGB24Row_AVX2(const uint8_t* src_raw, uint8_t* dst_rgb24, int width); +void RAWToRGB24Row_AVX512BW(const uint8_t* src_raw, + uint8_t* dst_rgb24, + int width); +void RAWToRGB24Row_AVX512VBMI(const uint8_t* src_raw, + uint8_t* dst_rgb24, + int width); + +// Deprecated. void RGB565ToARGBRow_AVX2(const uint8_t* src_rgb565, uint8_t* dst_argb, int width); void ARGB1555ToARGBRow_AVX2(const uint8_t* src_argb1555, uint8_t* dst_argb, int width); +void ARGB1555ToARGBRow_AVX512BW(const uint8_t* src_argb1555, + uint8_t* dst_argb, + int width); void ARGB4444ToARGBRow_AVX2(const uint8_t* src_argb4444, uint8_t* dst_argb, int width); @@ -1915,43 +4416,66 @@ void ARGB4444ToARGBRow_AVX2(const uint8_t* src_argb4444, void RGB24ToARGBRow_NEON(const uint8_t* src_rgb24, uint8_t* dst_argb, int width); -void RGB24ToARGBRow_MSA(const uint8_t* src_rgb24, uint8_t* dst_argb, int width); -void RGB24ToARGBRow_MMI(const uint8_t* src_rgb24, uint8_t* dst_argb, int width); +void RGB24ToARGBRow_SVE2(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width); +void RGB24ToARGBRow_LSX(const uint8_t* src_rgb24, uint8_t* dst_argb, int width); +void RGB24ToARGBRow_LASX(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width); +void RGB24ToARGBRow_RVV(const uint8_t* src_rgb24, uint8_t* dst_argb, int width); void RAWToARGBRow_NEON(const uint8_t* src_raw, uint8_t* dst_argb, int width); -void RAWToARGBRow_MSA(const uint8_t* src_raw, uint8_t* dst_argb, int width); -void RAWToARGBRow_MMI(const uint8_t* src_raw, uint8_t* dst_argb, int width); +void RAWToARGBRow_SVE2(const uint8_t* src_raw, uint8_t* dst_argb, int width); +void RAWToRGBARow_NEON(const uint8_t* src_raw, uint8_t* dst_rgba, int width); +void RAWToRGBARow_SVE2(const uint8_t* src_raw, uint8_t* dst_rgba, int width); +void RAWToARGBRow_LSX(const uint8_t* src_raw, uint8_t* dst_argb, int width); +void RAWToARGBRow_LASX(const uint8_t* src_raw, uint8_t* dst_argb, int width); +void RAWToARGBRow_RVV(const uint8_t* src_raw, uint8_t* dst_argb, int width); +void RAWToRGBARow_RVV(const uint8_t* src_raw, uint8_t* dst_rgba, int width); void RAWToRGB24Row_NEON(const uint8_t* src_raw, uint8_t* dst_rgb24, int width); -void RAWToRGB24Row_MSA(const uint8_t* src_raw, uint8_t* dst_rgb24, int width); -void RAWToRGB24Row_MMI(const uint8_t* src_raw, uint8_t* dst_rgb24, int width); +void RAWToRGB24Row_SVE2(const uint8_t* src_raw, uint8_t* dst_rgb24, int width); +void RAWToRGB24Row_LSX(const uint8_t* src_raw, uint8_t* dst_rgb24, int width); +void RAWToRGB24Row_LASX(const uint8_t* src_raw, uint8_t* dst_rgb24, int width); +void RAWToRGB24Row_RVV(const uint8_t* src_raw, uint8_t* dst_rgb24, int width); +void RAWToRGB24Row_WASMSIMD(const uint8_t* src_raw, + uint8_t* dst_rgb24, + int width); void RGB565ToARGBRow_NEON(const uint8_t* src_rgb565, uint8_t* dst_argb, int width); -void RGB565ToARGBRow_MSA(const uint8_t* src_rgb565, - uint8_t* dst_argb, - int width); -void RGB565ToARGBRow_MMI(const uint8_t* src_rgb565, +void RGB565ToARGBRow_LSX(const uint8_t* src_rgb565, uint8_t* dst_argb, int width); +void RGB565ToARGBRow_LASX(const uint8_t* src_rgb565, + uint8_t* dst_argb, + int width); void ARGB1555ToARGBRow_NEON(const uint8_t* src_argb1555, uint8_t* dst_argb, int width); -void ARGB1555ToARGBRow_MSA(const uint8_t* src_argb1555, - uint8_t* dst_argb, - int width); -void ARGB1555ToARGBRow_MMI(const uint8_t* src_argb1555, +void ARGB1555ToARGBRow_SVE2(const uint8_t* src_argb1555, + uint8_t* dst_argb, + int width); +void ARGB1555ToARGBRow_LSX(const uint8_t* src_argb1555, uint8_t* dst_argb, int width); +void ARGB1555ToARGBRow_LASX(const uint8_t* src_argb1555, + uint8_t* dst_argb, + int width); void ARGB4444ToARGBRow_NEON(const uint8_t* src_argb4444, uint8_t* dst_argb, int width); -void ARGB4444ToARGBRow_MSA(const uint8_t* src_argb4444, - uint8_t* dst_argb, - int width); -void ARGB4444ToARGBRow_MMI(const uint8_t* src_argb4444, +void ARGB4444ToARGBRow_LSX(const uint8_t* src_argb4444, uint8_t* dst_argb, int width); +void ARGB4444ToARGBRow_LASX(const uint8_t* src_argb4444, + uint8_t* dst_argb, + int width); void RGB24ToARGBRow_C(const uint8_t* src_rgb24, uint8_t* dst_argb, int width); void RAWToARGBRow_C(const uint8_t* src_raw, uint8_t* dst_argb, int width); +void RAWToRGBARow_C(const uint8_t* src_raw, uint8_t* dst_rgba, int width); +void RAWToRGBARow_AVX512VBMI(const uint8_t* src_raw, + uint8_t* dst_rgba, + int width); void RAWToRGB24Row_C(const uint8_t* src_raw, uint8_t* dst_rgb24, int width); void RGB565ToARGBRow_C(const uint8_t* src_rgb565, uint8_t* dst_argb, int width); void ARGB1555ToARGBRow_C(const uint8_t* src_argb1555, @@ -1961,9 +4485,42 @@ void ARGB4444ToARGBRow_C(const uint8_t* src_argb4444, uint8_t* dst_argb, int width); void AR30ToARGBRow_C(const uint8_t* src_ar30, uint8_t* dst_argb, int width); +void AR30ToARGBRow_AVX2(const uint8_t* src_ar30, uint8_t* dst_argb, int width); +void AR30ToARGBRow_AVX512BW(const uint8_t* src_ar30, + uint8_t* dst_argb, + int width); void AR30ToABGRRow_C(const uint8_t* src_ar30, uint8_t* dst_abgr, int width); +void AR30ToABGRRow_AVX2(const uint8_t* src_ar30, uint8_t* dst_abgr, int width); +void AR30ToABGRRow_AVX512BW(const uint8_t* src_ar30, + uint8_t* dst_abgr, + int width); void ARGBToAR30Row_C(const uint8_t* src_argb, uint8_t* dst_ar30, int width); void AR30ToAB30Row_C(const uint8_t* src_ar30, uint8_t* dst_ab30, int width); +void AR30ToAB30Row_AVX2(const uint8_t* src_ar30, uint8_t* dst_ab30, int width); +void AR30ToAB30Row_AVX512BW(const uint8_t* src_ar30, + uint8_t* dst_ab30, + int width); +void AR30ToARGBRow_NEON(const uint8_t* src_ar30, uint8_t* dst_argb, int width); +void AR30ToABGRRow_NEON(const uint8_t* src_ar30, uint8_t* dst_abgr, int width); +void AR30ToAB30Row_NEON(const uint8_t* src_ar30, uint8_t* dst_ab30, int width); +void AR30ToARGBRow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void AR30ToABGRRow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void AR30ToAB30Row_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void AR30ToARGBRow_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void AR30ToABGRRow_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void AR30ToAB30Row_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void RGB24ToARGBRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, @@ -1971,19 +4528,23 @@ void RGB24ToARGBRow_Any_SSSE3(const uint8_t* src_ptr, void RAWToARGBRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void RAWToARGBRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void RGB24ToARGBRow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void RGB24ToARGBRow_AVX512BW(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width); +void RAWToRGBARow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void RAWToRGB24Row_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void RAWToRGB24Row_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); -void RGB565ToARGBRow_Any_SSE2(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGB1555ToARGBRow_Any_SSE2(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGB4444ToARGBRow_Any_SSE2(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); void RGB565ToARGBRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); @@ -1997,76 +4558,86 @@ void ARGB4444ToARGBRow_Any_AVX2(const uint8_t* src_ptr, void RGB24ToARGBRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGB24ToARGBRow_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void RGB24ToARGBRow_Any_MMI(const uint8_t* src_ptr, +void RGB24ToARGBRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void RGB24ToARGBRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void RAWToARGBRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RAWToARGBRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RAWToARGBRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void RAWToRGBARow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void RAWToARGBRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void RAWToARGBRow_Any_LASX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void RAWToRGB24Row_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RAWToRGB24Row_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RAWToRGB24Row_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void RAWToRGB24Row_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void RAWToRGB24Row_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void RAWToRGB24Row_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void RGB565ToARGBRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void RGB565ToARGBRow_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void RGB565ToARGBRow_Any_MMI(const uint8_t* src_ptr, +void RGB565ToARGBRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void RGB565ToARGBRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void ARGB1555ToARGBRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGB1555ToARGBRow_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGB1555ToARGBRow_Any_MMI(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); void ARGB4444ToARGBRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGB1555ToARGBRow_Any_LSX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGB1555ToARGBRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); -void ARGB4444ToARGBRow_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGB4444ToARGBRow_Any_MMI(const uint8_t* src_ptr, +void ARGB4444ToARGBRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGB4444ToARGBRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void ARGBToRGB24Row_SSSE3(const uint8_t* src, uint8_t* dst, int width); void ARGBToRAWRow_SSSE3(const uint8_t* src, uint8_t* dst, int width); -void ARGBToRGB565Row_SSE2(const uint8_t* src, uint8_t* dst, int width); -void ARGBToARGB1555Row_SSE2(const uint8_t* src, uint8_t* dst, int width); -void ARGBToARGB4444Row_SSE2(const uint8_t* src, uint8_t* dst, int width); + void ABGRToAR30Row_SSSE3(const uint8_t* src, uint8_t* dst, int width); void ARGBToAR30Row_SSSE3(const uint8_t* src, uint8_t* dst, int width); void ARGBToRAWRow_AVX2(const uint8_t* src, uint8_t* dst, int width); void ARGBToRGB24Row_AVX2(const uint8_t* src, uint8_t* dst, int width); -void ARGBToRGB24Row_AVX512VBMI(const uint8_t* src, uint8_t* dst, int width); +void ARGBToRAWRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width); +void ARGBToRGB24Row_AVX512BW(const uint8_t* src, uint8_t* dst, int width); +// Deprecated. void ARGBToRGB565DitherRow_C(const uint8_t* src_argb, uint8_t* dst_rgb, - const uint32_t dither4, + uint32_t dither4, int width); -void ARGBToRGB565DitherRow_SSE2(const uint8_t* src, - uint8_t* dst, - const uint32_t dither4, - int width); + void ARGBToRGB565DitherRow_AVX2(const uint8_t* src, uint8_t* dst, - const uint32_t dither4, + uint32_t dither4, int width); +void ARGBToRGB565DitherRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_rgb, + uint32_t dither4, + int width); void ARGBToRGB565Row_AVX2(const uint8_t* src_argb, uint8_t* dst_rgb, int width); +void ARGBToRGB565Row_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width); void ARGBToARGB1555Row_AVX2(const uint8_t* src_argb, uint8_t* dst_rgb, int width); @@ -2074,15 +4645,24 @@ void ARGBToARGB4444Row_AVX2(const uint8_t* src_argb, uint8_t* dst_rgb, int width); void ABGRToAR30Row_AVX2(const uint8_t* src, uint8_t* dst, int width); +void ABGRToAR30Row_AVX512BW(const uint8_t* src, uint8_t* dst, int width); void ARGBToAR30Row_AVX2(const uint8_t* src, uint8_t* dst, int width); +void ARGBToAR30Row_AVX512BW(const uint8_t* src, uint8_t* dst, int width); void ARGBToRGB24Row_NEON(const uint8_t* src_argb, uint8_t* dst_rgb24, int width); +void ARGBToRGB24Row_SVE2(const uint8_t* src_argb, + uint8_t* dst_rgb24, + int width); void ARGBToRAWRow_NEON(const uint8_t* src_argb, uint8_t* dst_raw, int width); +void ARGBToRAWRow_SVE2(const uint8_t* src_argb, uint8_t* dst_raw, int width); void ARGBToRGB565Row_NEON(const uint8_t* src_argb, uint8_t* dst_rgb565, int width); +void ARGBToRGB565Row_SVE2(const uint8_t* src_argb, + uint8_t* dst_rgb565, + int width); void ARGBToARGB1555Row_NEON(const uint8_t* src_argb, uint8_t* dst_argb1555, int width); @@ -2091,36 +4671,48 @@ void ARGBToARGB4444Row_NEON(const uint8_t* src_argb, int width); void ARGBToRGB565DitherRow_NEON(const uint8_t* src_argb, uint8_t* dst_rgb, - const uint32_t dither4, + uint32_t dither4, int width); -void ARGBToRGB24Row_MSA(const uint8_t* src_argb, uint8_t* dst_rgb, int width); -void ARGBToRAWRow_MSA(const uint8_t* src_argb, uint8_t* dst_rgb, int width); -void ARGBToRGB565Row_MSA(const uint8_t* src_argb, uint8_t* dst_rgb, int width); -void ARGBToARGB1555Row_MSA(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width); -void ARGBToARGB4444Row_MSA(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width); -void ARGBToRGB565DitherRow_MSA(const uint8_t* src_argb, +void ARGBToRGB565DitherRow_SVE2(const uint8_t* src_argb, + uint8_t* dst_rgb, + uint32_t dither4, + int width); +void ARGBToRGB565DitherRow_LSX(const uint8_t* src_argb, uint8_t* dst_rgb, - const uint32_t dither4, + uint32_t dither4, int width); +void ARGBToRGB565DitherRow_LASX(const uint8_t* src_argb, + uint8_t* dst_rgb, + uint32_t dither4, + int width); -void ARGBToRGB24Row_MMI(const uint8_t* src_argb, uint8_t* dst_rgb, int width); -void ARGBToRAWRow_MMI(const uint8_t* src_argb, uint8_t* dst_rgb, int width); -void ARGBToRGB565Row_MMI(const uint8_t* src_argb, uint8_t* dst_rgb, int width); -void ARGBToARGB1555Row_MMI(const uint8_t* src_argb, +void ARGBToRGB24Row_LSX(const uint8_t* src_argb, uint8_t* dst_rgb, int width); +void ARGBToRGB24Row_LASX(const uint8_t* src_argb, uint8_t* dst_rgb, int width); +void ARGBToRAWRow_LSX(const uint8_t* src_argb, uint8_t* dst_rgb, int width); +void ARGBToRAWRow_LASX(const uint8_t* src_argb, uint8_t* dst_rgb, int width); +void ARGBToRGB565Row_LSX(const uint8_t* src_argb, uint8_t* dst_rgb, int width); +void ARGBToRGB565Row_LASX(const uint8_t* src_argb, uint8_t* dst_rgb, int width); +void ARGBToARGB1555Row_LSX(const uint8_t* src_argb, uint8_t* dst_rgb, int width); -void ARGBToARGB4444Row_MMI(const uint8_t* src_argb, +void ARGBToARGB1555Row_LASX(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width); +void ARGBToARGB4444Row_LSX(const uint8_t* src_argb, uint8_t* dst_rgb, int width); -void ARGBToRGB565DitherRow_MMI(const uint8_t* src_argb, - uint8_t* dst_rgb, - const uint32_t dither4, - int width); +void ARGBToARGB4444Row_LASX(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width); +void ARGBToRAWRow_RVV(const uint8_t* src_argb, uint8_t* dst_raw, int width); +void ARGBToABGRRow_RVV(const uint8_t* src_argb, uint8_t* dst_abgr, int width); +void ARGBToBGRARow_RVV(const uint8_t* src_argb, uint8_t* dst_bgra, int width); +void ARGBToRGBARow_RVV(const uint8_t* src_argb, uint8_t* dst_rgb, int width); +void ARGBToRGB24Row_RVV(const uint8_t* src_argb, uint8_t* dst_rgb24, int width); + +void ARGBToABGRRow_C(const uint8_t* src_argb, uint8_t* dst_abgr, int width); +void ARGBToBGRARow_C(const uint8_t* src_argb, uint8_t* dst_bgra, int width); void ARGBToRGBARow_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width); void ARGBToRGB24Row_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width); void ARGBToRAWRow_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width); @@ -2130,23 +4722,96 @@ void ARGBToARGB4444Row_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width); void ABGRToAR30Row_C(const uint8_t* src_abgr, uint8_t* dst_ar30, int width); void ARGBToAR30Row_C(const uint8_t* src_argb, uint8_t* dst_ar30, int width); -void J400ToARGBRow_SSE2(const uint8_t* src_y, uint8_t* dst_argb, int width); -void J400ToARGBRow_AVX2(const uint8_t* src_y, uint8_t* dst_argb, int width); -void J400ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, int width); -void J400ToARGBRow_MSA(const uint8_t* src_y, uint8_t* dst_argb, int width); -void J400ToARGBRow_MMI(const uint8_t* src_y, uint8_t* dst_argb, int width); -void J400ToARGBRow_C(const uint8_t* src_y, uint8_t* dst_argb, int width); -void J400ToARGBRow_Any_SSE2(const uint8_t* src_ptr, +void ARGBToAR64Row_C(const uint8_t* src_argb, uint16_t* dst_ar64, int width); +void ARGBToAB64Row_C(const uint8_t* src_argb, uint16_t* dst_ab64, int width); +void AR64ToARGBRow_C(const uint16_t* src_ar64, uint8_t* dst_argb, int width); +void AB64ToARGBRow_C(const uint16_t* src_ab64, uint8_t* dst_argb, int width); +void AR64ToAB64Row_C(const uint16_t* src_ar64, uint16_t* dst_ab64, int width); +void RGBAToARGBRow_C(const uint8_t* src_rgba, uint8_t* dst_argb, int width); +void AR64ShuffleRow_C(const uint8_t* src_ar64, + uint8_t* dst_ar64, + const uint8_t* shuffler, + int width); +void ARGBToAR64Row_SSSE3(const uint8_t* src_argb, + uint16_t* dst_ar64, + int width); +void ARGBToAB64Row_SSSE3(const uint8_t* src_argb, + uint16_t* dst_ab64, + int width); +void AR64ToARGBRow_SSSE3(const uint16_t* src_ar64, + uint8_t* dst_argb, + int width); +void AB64ToARGBRow_SSSE3(const uint16_t* src_ab64, + uint8_t* dst_argb, + int width); +void ARGBToAR64Row_AVX2(const uint8_t* src_argb, uint16_t* dst_ar64, int width); +void ARGBToAB64Row_AVX2(const uint8_t* src_argb, uint16_t* dst_ab64, int width); +void AR64ToARGBRow_AVX2(const uint16_t* src_ar64, uint8_t* dst_argb, int width); +void AB64ToARGBRow_AVX2(const uint16_t* src_ab64, uint8_t* dst_argb, int width); +void ARGBToAR64Row_NEON(const uint8_t* src_argb, uint16_t* dst_ar64, int width); +void ARGBToAB64Row_NEON(const uint8_t* src_argb, uint16_t* dst_ab64, int width); +void AR64ToARGBRow_NEON(const uint16_t* src_ar64, uint8_t* dst_argb, int width); +void AB64ToARGBRow_NEON(const uint16_t* src_ab64, uint8_t* dst_argb, int width); +void ARGBToAR64Row_RVV(const uint8_t* src_argb, uint16_t* dst_ar64, int width); +void ARGBToAB64Row_RVV(const uint8_t* src_argb, uint16_t* dst_ab64, int width); +void AR64ToARGBRow_RVV(const uint16_t* src_ar64, uint8_t* dst_argb, int width); +void AB64ToARGBRow_RVV(const uint16_t* src_ab64, uint8_t* dst_argb, int width); +void AR64ToAB64Row_RVV(const uint16_t* src_ar64, uint16_t* dst_ab64, int width); +void RGBAToARGBRow_RVV(const uint8_t* src_rgba, uint8_t* dst_argb, int width); +void ARGBToAR64Row_Any_SSSE3(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int width); +void ARGBToAB64Row_Any_SSSE3(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int width); +void AR64ToARGBRow_Any_SSSE3(const uint16_t* src_ptr, + uint8_t* dst_ptr, + int width); +void AB64ToARGBRow_Any_SSSE3(const uint16_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBToAR64Row_Any_AVX2(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int width); +void ARGBToAB64Row_Any_AVX2(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int width); +void AR64ToARGBRow_Any_AVX2(const uint16_t* src_ptr, uint8_t* dst_ptr, int width); +void AB64ToARGBRow_Any_AVX2(const uint16_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBToAR64Row_Any_NEON(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int width); +void ARGBToAB64Row_Any_NEON(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int width); +void AR64ToARGBRow_Any_NEON(const uint16_t* src_ptr, + uint8_t* dst_ptr, + int width); +void AB64ToARGBRow_Any_NEON(const uint16_t* src_ptr, + uint8_t* dst_ptr, + int width); + +void J400ToARGBRow_AVX512BW(const uint8_t* src_y, uint8_t* dst_argb, int width); +void J400ToARGBRow_AVX2(const uint8_t* src_y, uint8_t* dst_argb, int width); +void J400ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, int width); +void J400ToARGBRow_LSX(const uint8_t* src_y, uint8_t* dst_argb, int width); +void J400ToARGBRow_LASX(const uint8_t* src_y, uint8_t* dst_argb, int width); +void J400ToARGBRow_RVV(const uint8_t* src_y, uint8_t* dst_argb, int width); +void J400ToARGBRow_C(const uint8_t* src_y, uint8_t* dst_argb, int width); void J400ToARGBRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void J400ToARGBRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void J400ToARGBRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void J400ToARGBRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void J400ToARGBRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void J400ToARGBRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void I444ToARGBRow_C(const uint8_t* src_y, const uint8_t* src_u, @@ -2154,6 +4819,12 @@ void I444ToARGBRow_C(const uint8_t* src_y, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width); +void I444ToRGB24Row_C(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); void I422ToARGBRow_C(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, @@ -2178,6 +4849,51 @@ void I210ToARGBRow_C(const uint16_t* src_y, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width); +void I212ToAR30Row_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I212ToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410ToAR30Row_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410ToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I210AlphaToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I410AlphaToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I444AlphaToARGBRow_C(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); void I422AlphaToARGBRow_C(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, @@ -2222,6 +4938,27 @@ void UYVYToARGBRow_C(const uint8_t* src_uyvy, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width); +void P210ToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P410ToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P210ToAR30Row_C(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P410ToAR30Row_C(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); + void I422ToRGBARow_C(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, @@ -2258,12 +4995,85 @@ void I422ToARGBRow_AVX2(const uint8_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void I422ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToAR30Row_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); void I422ToRGBARow_AVX2(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, - uint8_t* dst_argb, + uint8_t* dst_rgba, const struct YuvConstants* yuvconstants, int width); +void I422ToRGBARow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width); +// Deprecated. +void I422ToRGB565Row_AVX2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB565Row_AVX512BW(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB1555Row_AVX2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB1555Row_AVX512BW(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB4444Row_AVX2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB4444Row_AVX512BW(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB565Row_SSSE3(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB1555Row_SSSE3(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB4444Row_SSSE3(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width); void I444ToARGBRow_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -2276,18 +5086,30 @@ void I444ToARGBRow_AVX2(const uint8_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); -void I444ToARGBRow_SSSE3(const uint8_t* y_buf, +void I444ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444ToRGB24Row_SSSE3(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void I444ToRGB24Row_AVX2(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, - uint8_t* dst_argb, + uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width); -void I444ToARGBRow_AVX2(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width); +void I444ToRGB24Row_AVX512VBMI(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); void I422ToARGBRow_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -2313,6 +5135,44 @@ void I210ToARGBRow_SSSE3(const uint16_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void I212ToAR30Row_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void I212ToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I410ToAR30Row_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void I410ToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I210AlphaToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I410AlphaToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void I422ToAR30Row_AVX2(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -2325,12 +5185,121 @@ void I210ToARGBRow_AVX2(const uint16_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void I210ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void I210ToAR30Row_AVX2(const uint16_t* y_buf, const uint16_t* u_buf, const uint16_t* v_buf, uint8_t* dst_ar30, const struct YuvConstants* yuvconstants, int width); +void I210ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void I212ToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I212ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I212ToAR30Row_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void I212ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void I410ToAR30Row_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void I410ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void I410ToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I410ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I210AlphaToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I210AlphaToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I410AlphaToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I410AlphaToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444AlphaToARGBRow_SSSE3(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444AlphaToARGBRow_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444AlphaToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void I422AlphaToARGBRow_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -2345,6 +5314,13 @@ void I422AlphaToARGBRow_AVX2(const uint8_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void I422AlphaToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void NV12ToARGBRow_SSSE3(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_argb, @@ -2355,6 +5331,11 @@ void NV12ToARGBRow_AVX2(const uint8_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void NV12ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void NV12ToRGB24Row_SSSE3(const uint8_t* src_y, const uint8_t* src_uv, uint8_t* dst_rgb24, @@ -2365,30 +5346,50 @@ void NV21ToRGB24Row_SSSE3(const uint8_t* src_y, uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width); -void NV12ToRGB565Row_SSSE3(const uint8_t* src_y, - const uint8_t* src_uv, - uint8_t* dst_rgb565, - const struct YuvConstants* yuvconstants, - int width); + void NV12ToRGB24Row_AVX2(const uint8_t* src_y, const uint8_t* src_uv, uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width); +void NV12ToRGB24Row_AVX512VBMI(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); void NV21ToRGB24Row_AVX2(const uint8_t* src_y, const uint8_t* src_vu, uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width); -void NV21ToYUV24Row_AVX2(const uint8_t* src_y, - const uint8_t* src_vu, - uint8_t* dst_yuv24, - int width); +void NV21ToRGB24Row_AVX512VBMI(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToRGB565Row_SSSE3(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width); void NV12ToRGB565Row_AVX2(const uint8_t* src_y, const uint8_t* src_uv, uint8_t* dst_rgb565, const struct YuvConstants* yuvconstants, int width); +void NV21ToYUV24Row_SSSE3(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_yuv24, + int width); +void NV21ToYUV24Row_AVX2(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_yuv24, + int width); +void NV21ToYUV24Row_AVX512VBMI(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_yuv24, + int width); + void NV21ToARGBRow_SSSE3(const uint8_t* y_buf, const uint8_t* vu_buf, uint8_t* dst_argb, @@ -2399,6 +5400,11 @@ void NV21ToARGBRow_AVX2(const uint8_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void NV21ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* vu_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void YUY2ToARGBRow_SSSE3(const uint8_t* yuy2_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, @@ -2411,52 +5417,87 @@ void YUY2ToARGBRow_AVX2(const uint8_t* yuy2_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void YUY2ToARGBRow_AVX512BW(const uint8_t* yuy2_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void UYVYToARGBRow_AVX2(const uint8_t* uyvy_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width); +void UYVYToARGBRow_AVX512BW(const uint8_t* uyvy_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); + +void P210ToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P410ToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P210ToAR30Row_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P410ToAR30Row_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P210ToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P210ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P410ToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P410ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P210ToAR30Row_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P210ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P410ToAR30Row_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P410ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); + void I422ToRGBARow_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_rgba, const struct YuvConstants* yuvconstants, int width); -void I422ToARGB4444Row_SSSE3(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb4444, - const struct YuvConstants* yuvconstants, - int width); -void I422ToARGB4444Row_AVX2(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb4444, - const struct YuvConstants* yuvconstants, - int width); -void I422ToARGB1555Row_SSSE3(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb1555, - const struct YuvConstants* yuvconstants, - int width); -void I422ToARGB1555Row_AVX2(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb1555, - const struct YuvConstants* yuvconstants, - int width); -void I422ToRGB565Row_SSSE3(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_rgb565, - const struct YuvConstants* yuvconstants, - int width); -void I422ToRGB565Row_AVX2(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_rgb565, - const struct YuvConstants* yuvconstants, - int width); + void I422ToRGB24Row_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -2469,6 +5510,18 @@ void I422ToRGB24Row_AVX2(const uint8_t* src_y, uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width); +void I422ToRGB24Row_AVX512VBMI(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB24Row_AVX512BW(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); void I422ToARGBRow_Any_AVX2(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -2487,12 +5540,24 @@ void I444ToARGBRow_Any_SSSE3(const uint8_t* y_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); +void I444ToRGB24Row_Any_SSSE3(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); void I444ToARGBRow_Any_AVX2(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); +void I444ToRGB24Row_Any_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); void I422ToARGBRow_Any_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -2517,6 +5582,44 @@ void I210ToARGBRow_Any_SSSE3(const uint16_t* y_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); +void I212ToAR30Row_Any_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I212ToARGBRow_Any_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I410ToAR30Row_Any_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I410ToARGBRow_Any_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I210AlphaToARGBRow_Any_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I410AlphaToARGBRow_Any_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); void I422ToAR30Row_Any_AVX2(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -2535,6 +5638,58 @@ void I210ToAR30Row_Any_AVX2(const uint16_t* y_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); +void I212ToARGBRow_Any_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I212ToAR30Row_Any_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I410ToAR30Row_Any_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I410ToARGBRow_Any_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I210AlphaToARGBRow_Any_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I410AlphaToARGBRow_Any_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I444AlphaToARGBRow_Any_SSSE3(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I444AlphaToARGBRow_Any_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); void I422AlphaToARGBRow_Any_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -2589,20 +5744,15 @@ void NV21ToRGB24Row_Any_AVX2(const uint8_t* y_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void NV21ToYUV24Row_Any_AVX2(const uint8_t* src_y, - const uint8_t* src_vu, - uint8_t* dst_yuv24, - int width); -void NV12ToRGB565Row_Any_SSSE3(const uint8_t* y_buf, - const uint8_t* uv_buf, - uint8_t* dst_ptr, - const struct YuvConstants* yuvconstants, - int width); -void NV12ToRGB565Row_Any_AVX2(const uint8_t* y_buf, +void NV21ToYUV24Row_Any_SSSE3(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, - const struct YuvConstants* yuvconstants, int width); +void NV21ToYUV24Row_Any_AVX2(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); + void YUY2ToARGBRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, @@ -2619,48 +5769,53 @@ void UYVYToARGBRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); +void P210ToARGBRow_Any_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void P410ToARGBRow_Any_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void P210ToAR30Row_Any_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void P410ToAR30Row_Any_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void P210ToARGBRow_Any_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void P410ToARGBRow_Any_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void P210ToAR30Row_Any_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void P410ToAR30Row_Any_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); void I422ToRGBARow_Any_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void I422ToARGB4444Row_Any_SSSE3(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_ptr, - const struct YuvConstants* yuvconstants, - int width); -void I422ToARGB4444Row_Any_AVX2(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_ptr, - const struct YuvConstants* yuvconstants, - int width); -void I422ToARGB1555Row_Any_SSSE3(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_ptr, - const struct YuvConstants* yuvconstants, - int width); -void I422ToARGB1555Row_Any_AVX2(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_ptr, - const struct YuvConstants* yuvconstants, - int width); -void I422ToRGB565Row_Any_SSSE3(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_ptr, - const struct YuvConstants* yuvconstants, - int width); -void I422ToRGB565Row_Any_AVX2(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_ptr, - const struct YuvConstants* yuvconstants, - int width); + void I422ToRGB24Row_Any_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -2673,43 +5828,148 @@ void I422ToRGB24Row_Any_AVX2(const uint8_t* y_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); +void I422ToRGB565Row_Any_SSSE3(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB1555Row_Any_SSSE3(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB4444Row_Any_SSSE3(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToRGB565Row_Any_SSSE3(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB565Row_Any_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB1555Row_Any_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB4444Row_Any_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToRGB565Row_Any_AVX2(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); -void I400ToARGBRow_C(const uint8_t* src_y, uint8_t* rgb_buf, int width); -void I400ToARGBRow_SSE2(const uint8_t* y_buf, uint8_t* dst_argb, int width); -void I400ToARGBRow_AVX2(const uint8_t* y_buf, uint8_t* dst_argb, int width); -void I400ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, int width); -void I400ToARGBRow_MSA(const uint8_t* src_y, uint8_t* dst_argb, int width); -void I400ToARGBRow_MMI(const uint8_t* src_y, uint8_t* dst_argb, int width); +void I400ToARGBRow_C(const uint8_t* src_y, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width); +void I400ToARGBRow_SSE2(const uint8_t* y_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I400ToARGBRow_AVX2(const uint8_t* y_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I400ToARGBRow_AVX512BW(const uint8_t* y_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I400ToARGBRow_NEON(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I400ToARGBRow_SVE2(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I400ToARGBRow_SME(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I400ToARGBRow_LSX(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I400ToARGBRow_LASX(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I400ToARGBRow_RVV(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); void I400ToARGBRow_Any_SSE2(const uint8_t* src_ptr, uint8_t* dst_ptr, + const struct YuvConstants* param, int width); void I400ToARGBRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, + const struct YuvConstants* param, int width); void I400ToARGBRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, + const struct YuvConstants* param, + int width); +void I400ToARGBRow_Any_LSX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I400ToARGBRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, int width); -void I400ToARGBRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void I400ToARGBRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); // ARGB preattenuated alpha blend. -void ARGBBlendRow_SSSE3(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width); -void ARGBBlendRow_NEON(const uint8_t* src_argb0, +void ARGBBlendRow_AVX2(const uint8_t* src_argb0, const uint8_t* src_argb1, uint8_t* dst_argb, int width); -void ARGBBlendRow_MSA(const uint8_t* src_argb0, +void ARGBBlendRow_AVX512BW(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBBlendRow_NEON(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBBlendRow_LSX(const uint8_t* src_argb0, const uint8_t* src_argb1, uint8_t* dst_argb, int width); -void ARGBBlendRow_MMI(const uint8_t* src_argb0, +void ARGBBlendRow_LASX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBBlendRow_Any_LSX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBBlendRow_Any_LASX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBBlendRow_RVV(const uint8_t* src_argb0, const uint8_t* src_argb1, uint8_t* dst_argb, int width); -void ARGBBlendRow_C(const uint8_t* src_argb0, +void ARGBBlendRow_C(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); @@ -2735,16 +5995,26 @@ void BlendPlaneRow_Any_AVX2(const uint8_t* y_buf, const uint8_t* v_buf, uint8_t* dst_ptr, int width); -void BlendPlaneRow_MMI(const uint8_t* src0, +void BlendPlaneRow_AVX512BW(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width); +void BlendPlaneRow_NEON(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width); +void BlendPlaneRow_Any_NEON(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + int width); +void BlendPlaneRow_RVV(const uint8_t* src0, const uint8_t* src1, const uint8_t* alpha, uint8_t* dst, int width); -void BlendPlaneRow_Any_MMI(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_ptr, - int width); void BlendPlaneRow_C(const uint8_t* src0, const uint8_t* src1, const uint8_t* alpha, @@ -2753,11 +6023,11 @@ void BlendPlaneRow_C(const uint8_t* src0, // ARGB multiply images. Same API as Blend, but these require // pointer and width alignment for SSE2. -void ARGBMultiplyRow_C(const uint8_t* src_argb0, +void ARGBMultiplyRow_C(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); -void ARGBMultiplyRow_SSE2(const uint8_t* src_argb0, +void ARGBMultiplyRow_SSE2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); @@ -2765,7 +6035,7 @@ void ARGBMultiplyRow_Any_SSE2(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void ARGBMultiplyRow_AVX2(const uint8_t* src_argb0, +void ARGBMultiplyRow_AVX2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); @@ -2773,7 +6043,11 @@ void ARGBMultiplyRow_Any_AVX2(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void ARGBMultiplyRow_NEON(const uint8_t* src_argb0, +void ARGBMultiplyRow_AVX512BW(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBMultiplyRow_NEON(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); @@ -2781,29 +6055,37 @@ void ARGBMultiplyRow_Any_NEON(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void ARGBMultiplyRow_MSA(const uint8_t* src_argb0, +void ARGBMultiplyRow_SME(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); -void ARGBMultiplyRow_Any_MSA(const uint8_t* y_buf, - const uint8_t* uv_buf, - uint8_t* dst_ptr, - int width); -void ARGBMultiplyRow_MMI(const uint8_t* src_argb0, +void ARGBMultiplyRow_LSX(const uint8_t* src_argb0, const uint8_t* src_argb1, uint8_t* dst_argb, int width); -void ARGBMultiplyRow_Any_MMI(const uint8_t* y_buf, +void ARGBMultiplyRow_LASX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBMultiplyRow_Any_LSX(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); +void ARGBMultiplyRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); +void ARGBMultiplyRow_RVV(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); // ARGB add images. -void ARGBAddRow_C(const uint8_t* src_argb0, +void ARGBAddRow_C(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); -void ARGBAddRow_SSE2(const uint8_t* src_argb0, +void ARGBAddRow_SSE2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); @@ -2811,7 +6093,7 @@ void ARGBAddRow_Any_SSE2(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void ARGBAddRow_AVX2(const uint8_t* src_argb0, +void ARGBAddRow_AVX2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); @@ -2819,7 +6101,7 @@ void ARGBAddRow_Any_AVX2(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void ARGBAddRow_NEON(const uint8_t* src_argb0, +void ARGBAddRow_NEON(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); @@ -2827,30 +6109,30 @@ void ARGBAddRow_Any_NEON(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void ARGBAddRow_MSA(const uint8_t* src_argb0, +void ARGBAddRow_LSX(const uint8_t* src_argb0, const uint8_t* src_argb1, uint8_t* dst_argb, int width); -void ARGBAddRow_Any_MSA(const uint8_t* y_buf, - const uint8_t* uv_buf, - uint8_t* dst_ptr, - int width); -void ARGBAddRow_MMI(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width); -void ARGBAddRow_Any_MMI(const uint8_t* y_buf, +void ARGBAddRow_LASX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAddRow_Any_LSX(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); +void ARGBAddRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); // ARGB subtract images. Same API as Blend, but these require // pointer and width alignment for SSE2. -void ARGBSubtractRow_C(const uint8_t* src_argb0, +void ARGBSubtractRow_C(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); -void ARGBSubtractRow_SSE2(const uint8_t* src_argb0, +void ARGBSubtractRow_SSE2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); @@ -2858,7 +6140,7 @@ void ARGBSubtractRow_Any_SSE2(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void ARGBSubtractRow_AVX2(const uint8_t* src_argb0, +void ARGBSubtractRow_AVX2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); @@ -2866,7 +6148,7 @@ void ARGBSubtractRow_Any_AVX2(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void ARGBSubtractRow_NEON(const uint8_t* src_argb0, +void ARGBSubtractRow_NEON(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width); @@ -2874,22 +6156,170 @@ void ARGBSubtractRow_Any_NEON(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void ARGBSubtractRow_MSA(const uint8_t* src_argb0, +void ARGBSubtractRow_LSX(const uint8_t* src_argb0, const uint8_t* src_argb1, uint8_t* dst_argb, int width); -void ARGBSubtractRow_Any_MSA(const uint8_t* y_buf, +void ARGBSubtractRow_LASX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBSubtractRow_Any_LSX(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void ARGBSubtractRow_MMI(const uint8_t* src_argb0, +void ARGBSubtractRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); + +// ARGB bitwise OR with 32-bit value. +void ARGBOrRow_C(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); +void ARGBOrRow_SSE2(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); +void ARGBOrRow_Any_SSE2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + uint32_t value, + int width); +void ARGBOrRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); +void ARGBOrRow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + uint32_t value, + int width); +void ARGBOrRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); +void ARGBOrRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); +void ARGBOrRow_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + uint32_t value, + int width); +void ARGBOrRow_SVE2(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); +void ARGBOrRow_SME(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); +void ARGBOrRow_LSX(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); +void ARGBOrRow_Any_LSX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + uint32_t value, + int width); +void ARGBOrRow_LASX(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); +void ARGBOrRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + uint32_t value, + int width); +void ARGBOrRow_RVV(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); +void ARGBOrRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); +void ARGBOrRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + uint32_t value, + int width); +void ARGBOrRow_HVX(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width); + +// Unattenuated ARGB alpha blend. +void ARGBAlphaBlendRow_C(const uint8_t* src_argb0, const uint8_t* src_argb1, uint8_t* dst_argb, int width); -void ARGBSubtractRow_Any_MMI(const uint8_t* y_buf, - const uint8_t* uv_buf, - uint8_t* dst_ptr, +void ARGBAlphaBlendRow_SSSE3(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, int width); +void ARGBAlphaBlendRow_Any_SSSE3(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); +void ARGBAlphaBlendRow_AVX2(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAlphaBlendRow_Any_AVX2(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); +void ARGBAlphaBlendRow_AVX512BW(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAlphaBlendRow_NEON(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAlphaBlendRow_Any_NEON(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); +void ARGBAlphaBlendRow_SVE2(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAlphaBlendRow_SME(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAlphaBlendRow_LSX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAlphaBlendRow_Any_LSX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); +void ARGBAlphaBlendRow_LASX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAlphaBlendRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); +void ARGBAlphaBlendRow_RVV(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAlphaBlendRow_WASMSIMD(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAlphaBlendRow_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); +void ARGBAlphaBlendRow_HVX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); void ARGBToRGB24Row_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, @@ -2897,15 +6327,7 @@ void ARGBToRGB24Row_Any_SSSE3(const uint8_t* src_ptr, void ARGBToRAWRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToRGB565Row_Any_SSE2(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGBToARGB1555Row_Any_SSE2(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGBToARGB4444Row_Any_SSE2(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); + void ABGRToAR30Row_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); @@ -2916,13 +6338,7 @@ void ARGBToRAWRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void ARGBToRGB24Row_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToRGB24Row_Any_AVX512VBMI(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGBToRGB565DitherRow_Any_SSE2(const uint8_t* src_ptr, - uint8_t* dst_ptr, - const uint32_t param, - int width); + void ARGBToRGB565DitherRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, const uint32_t param, @@ -2961,41 +6377,40 @@ void ARGBToRGB565DitherRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, const uint32_t param, int width); -void ARGBToRGB24Row_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGBToRAWRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToRGB565Row_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGBToARGB1555Row_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGBToARGB4444Row_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGBToRGB565DitherRow_Any_MSA(const uint8_t* src_ptr, +void ARGBToRGB565DitherRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, const uint32_t param, int width); - -void ARGBToRGB24Row_Any_MMI(const uint8_t* src_ptr, +void ARGBToRGB565DitherRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + const uint32_t param, + int width); +void ARGBToRGB24Row_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToRAWRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToRGB565Row_Any_MMI(const uint8_t* src_ptr, +void ARGBToRGB24Row_Any_LASX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToARGB1555Row_Any_MMI(const uint8_t* src_ptr, +void ARGBToRAWRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGBToRAWRow_Any_LASX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGBToRGB565Row_Any_LSX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBToRGB565Row_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBToARGB1555Row_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToARGB4444Row_Any_MMI(const uint8_t* src_ptr, +void ARGBToARGB1555Row_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBToARGB4444Row_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBToRGB565DitherRow_Any_MMI(const uint8_t* src_ptr, - uint8_t* dst_ptr, - const uint32_t param, - int width); +void ARGBToARGB4444Row_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void I444ToARGBRow_Any_NEON(const uint8_t* y_buf, const uint8_t* u_buf, @@ -3003,12 +6418,61 @@ void I444ToARGBRow_Any_NEON(const uint8_t* y_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); +void I444ToRGB24Row_Any_NEON(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); void I422ToARGBRow_Any_NEON(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); +void I210ToARGBRow_Any_NEON(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I410ToARGBRow_Any_NEON(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I210ToAR30Row_Any_NEON(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I410ToAR30Row_Any_NEON(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I212ToARGBRow_Any_NEON(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I212ToAR30Row_Any_NEON(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I444AlphaToARGBRow_Any_NEON(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); void I422AlphaToARGBRow_Any_NEON(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -3016,6 +6480,20 @@ void I422AlphaToARGBRow_Any_NEON(const uint8_t* y_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); +void I410AlphaToARGBRow_Any_NEON(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I210AlphaToARGBRow_Any_NEON(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); void I422ToRGBARow_Any_NEON(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -3046,6 +6524,12 @@ void I422ToRGB565Row_Any_NEON(const uint8_t* y_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); +void I422ToAR30Row_Any_NEON(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); void NV12ToARGBRow_Any_NEON(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, @@ -3066,9 +6550,9 @@ void NV21ToRGB24Row_Any_NEON(const uint8_t* y_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void NV21ToYUV24Row_Any_NEON(const uint8_t* src_y, - const uint8_t* src_vu, - uint8_t* dst_yuv24, +void NV21ToYUV24Row_Any_NEON(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, int width); void NV12ToRGB565Row_Any_NEON(const uint8_t* y_buf, const uint8_t* uv_buf, @@ -3083,78 +6567,239 @@ void UYVYToARGBRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void I444ToARGBRow_Any_MSA(const uint8_t* y_buf, +void ARGBToAR30Row_NEON(const uint8_t* src, uint8_t* dst, int width); +void ABGRToAR30Row_NEON(const uint8_t* src, uint8_t* dst, int width); +void ABGRToAR30Row_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBToAR30Row_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void P210ToARGBRow_NEON(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P210ToARGBRow_SVE2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P210ToARGBRow_SME(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P410ToARGBRow_NEON(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P410ToARGBRow_SVE2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P410ToARGBRow_SME(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P210ToAR30Row_NEON(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P210ToAR30Row_SVE2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P210ToAR30Row_SME(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P410ToAR30Row_NEON(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P410ToAR30Row_SVE2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P410ToAR30Row_SME(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P210ToARGBRow_Any_NEON(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P410ToARGBRow_Any_NEON(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void P210ToAR30Row_Any_NEON(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void P410ToAR30Row_Any_NEON(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void I444ToARGBRow_Any_LSX(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void I422ToARGBRow_Any_MSA(const uint8_t* y_buf, +void I444ToARGBRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGBRow_Any_LSX(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void I422ToRGBARow_Any_MSA(const uint8_t* y_buf, +void I422ToARGBRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGBARow_Any_LSX(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void I422AlphaToARGBRow_Any_MSA(const uint8_t* y_buf, +void I422ToRGBARow_Any_LASX(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422AlphaToARGBRow_Any_LSX(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, const uint8_t* a_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void I422ToRGB24Row_Any_MSA(const uint8_t* y_buf, +void I422AlphaToARGBRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB24Row_Any_LSX(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void I422ToRGB565Row_Any_MSA(const uint8_t* y_buf, +void I422ToRGB24Row_Any_LASX(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void I422ToARGB4444Row_Any_MSA(const uint8_t* y_buf, +void I422ToRGB565Row_Any_LSX(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB565Row_Any_LASX(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB4444Row_Any_LSX(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void I422ToARGB1555Row_Any_MSA(const uint8_t* y_buf, +void I422ToARGB4444Row_Any_LASX(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB1555Row_Any_LSX(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void NV12ToARGBRow_Any_MSA(const uint8_t* y_buf, +void I422ToARGB1555Row_Any_LASX(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); + +void NV12ToARGBRow_Any_LSX(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void NV12ToRGB565Row_Any_MSA(const uint8_t* y_buf, +void NV12ToARGBRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToRGB565Row_Any_LSX(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void NV21ToARGBRow_Any_MSA(const uint8_t* y_buf, +void NV12ToRGB565Row_Any_LASX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void NV21ToARGBRow_Any_LSX(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void YUY2ToARGBRow_Any_MSA(const uint8_t* src_ptr, +void NV21ToARGBRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void YUY2ToARGBRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); -void UYVYToARGBRow_Any_MSA(const uint8_t* src_ptr, +void YUY2ToARGBRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void UYVYToARGBRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, int width); +void UYVYToARGBRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); void YUY2ToYRow_AVX2(const uint8_t* src_yuy2, uint8_t* dst_y, int width); void YUY2ToUVRow_AVX2(const uint8_t* src_yuy2, @@ -3162,6 +6807,10 @@ void YUY2ToUVRow_AVX2(const uint8_t* src_yuy2, uint8_t* dst_u, uint8_t* dst_v, int width); +void YUY2ToNVUVRow_AVX2(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_uv, + int width); void YUY2ToUV422Row_AVX2(const uint8_t* src_yuy2, uint8_t* dst_u, uint8_t* dst_v, @@ -3172,100 +6821,148 @@ void YUY2ToUVRow_SSE2(const uint8_t* src_yuy2, uint8_t* dst_u, uint8_t* dst_v, int width); +void YUY2ToNVUVRow_SSE2(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_uv, + int width); void YUY2ToUV422Row_SSE2(const uint8_t* src_yuy2, uint8_t* dst_u, uint8_t* dst_v, int width); void YUY2ToYRow_NEON(const uint8_t* src_yuy2, uint8_t* dst_y, int width); +void YUY2ToYRow_SVE2(const uint8_t* src_yuy2, uint8_t* dst_y, int width); +void YUY2ToYRow_AVX512BW(const uint8_t* src_yuy2, uint8_t* dst_y, int width); void YUY2ToUVRow_NEON(const uint8_t* src_yuy2, int stride_yuy2, uint8_t* dst_u, uint8_t* dst_v, int width); +void YUY2ToUVRow_SVE2(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void YUY2ToUVRow_AVX512BW(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void UYVYToYRow_SVE2(const uint8_t* src_uyvy, uint8_t* dst_y, int width); +void UYVYToYRow_AVX512BW(const uint8_t* src_uyvy, uint8_t* dst_y, int width); +void UYVYToUVRow_SVE2(const uint8_t* src_uyvy, + int stride_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void UYVYToUVRow_AVX512BW(const uint8_t* src_uyvy, + int stride_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void YUY2ToNVUVRow_NEON(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_uv, + int width); void YUY2ToUV422Row_NEON(const uint8_t* src_yuy2, uint8_t* dst_u, uint8_t* dst_v, int width); -void YUY2ToYRow_MSA(const uint8_t* src_yuy2, uint8_t* dst_y, int width); -void YUY2ToYRow_MMI(const uint8_t* src_yuy2, uint8_t* dst_y, int width); -void YUY2ToUVRow_MSA(const uint8_t* src_yuy2, +void YUY2ToYRow_LSX(const uint8_t* src_yuy2, uint8_t* dst_y, int width); +void YUY2ToYRow_LASX(const uint8_t* src_yuy2, uint8_t* dst_y, int width); +void YUY2ToUVRow_LSX(const uint8_t* src_yuy2, int src_stride_yuy2, uint8_t* dst_u, uint8_t* dst_v, int width); -void YUY2ToUVRow_MMI(const uint8_t* src_yuy2, - int src_stride_yuy2, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void YUY2ToUV422Row_MSA(const uint8_t* src_yuy2, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void YUY2ToUV422Row_MMI(const uint8_t* src_yuy2, +void YUY2ToUVRow_LASX(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void YUY2ToUV422Row_LSX(const uint8_t* src_yuy2, uint8_t* dst_u, uint8_t* dst_v, int width); +void YUY2ToUV422Row_LASX(const uint8_t* src_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width); void YUY2ToYRow_C(const uint8_t* src_yuy2, uint8_t* dst_y, int width); void YUY2ToUVRow_C(const uint8_t* src_yuy2, int src_stride_yuy2, uint8_t* dst_u, uint8_t* dst_v, int width); +void YUY2ToNVUVRow_C(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_uv, + int width); void YUY2ToUV422Row_C(const uint8_t* src_yuy2, uint8_t* dst_u, uint8_t* dst_v, int width); void YUY2ToYRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void YUY2ToUVRow_Any_AVX2(const uint8_t* src_ptr, - int src_stride_ptr, + int src_stride, uint8_t* dst_u, uint8_t* dst_v, int width); +void YUY2ToNVUVRow_Any_AVX2(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_uv, + int width); void YUY2ToUV422Row_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); void YUY2ToYRow_Any_SSE2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void YUY2ToUVRow_Any_SSE2(const uint8_t* src_ptr, - int src_stride_ptr, + int src_stride, uint8_t* dst_u, uint8_t* dst_v, int width); +void YUY2ToNVUVRow_Any_SSE2(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_uv, + int width); void YUY2ToUV422Row_Any_SSE2(const uint8_t* src_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); void YUY2ToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void YUY2ToUVRow_Any_NEON(const uint8_t* src_ptr, - int src_stride_ptr, + int src_stride, uint8_t* dst_u, uint8_t* dst_v, int width); +void YUY2ToNVUVRow_Any_NEON(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_uv, + int width); void YUY2ToUV422Row_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); -void YUY2ToYRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void YUY2ToYRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void YUY2ToUVRow_Any_MSA(const uint8_t* src_ptr, +void YUY2ToYRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void YUY2ToYRow_Any_LASX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void YUY2ToUVRow_Any_LSX(const uint8_t* src_ptr, int src_stride_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); -void YUY2ToUVRow_Any_MMI(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void YUY2ToUV422Row_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void YUY2ToUV422Row_Any_MMI(const uint8_t* src_ptr, +void YUY2ToUVRow_Any_LASX(const uint8_t* src_ptr, + int src_stride_ptr, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void YUY2ToUV422Row_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); +void YUY2ToUV422Row_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_u, + uint8_t* dst_v, + int width); void UYVYToYRow_AVX2(const uint8_t* src_uyvy, uint8_t* dst_y, int width); void UYVYToUVRow_AVX2(const uint8_t* src_uyvy, int stride_uyvy, @@ -3306,26 +7003,26 @@ void UYVYToUV422Row_NEON(const uint8_t* src_uyvy, uint8_t* dst_u, uint8_t* dst_v, int width); -void UYVYToYRow_MSA(const uint8_t* src_uyvy, uint8_t* dst_y, int width); -void UYVYToYRow_MMI(const uint8_t* src_uyvy, uint8_t* dst_y, int width); -void UYVYToUVRow_MSA(const uint8_t* src_uyvy, +void UYVYToYRow_LSX(const uint8_t* src_uyvy, uint8_t* dst_y, int width); +void UYVYToYRow_LASX(const uint8_t* src_uyvy, uint8_t* dst_y, int width); +void UYVYToUVRow_LSX(const uint8_t* src_uyvy, int src_stride_uyvy, uint8_t* dst_u, uint8_t* dst_v, int width); -void UYVYToUVRow_MMI(const uint8_t* src_uyvy, - int src_stride_uyvy, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void UYVYToUV422Row_MSA(const uint8_t* src_uyvy, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void UYVYToUV422Row_MMI(const uint8_t* src_uyvy, +void UYVYToUVRow_LASX(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void UYVYToUV422Row_LSX(const uint8_t* src_uyvy, uint8_t* dst_u, uint8_t* dst_v, int width); +void UYVYToUV422Row_LASX(const uint8_t* src_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width); void UYVYToYRow_C(const uint8_t* src_uyvy, uint8_t* dst_y, int width); void UYVYToUVRow_C(const uint8_t* src_uyvy, @@ -3339,7 +7036,7 @@ void UYVYToUV422Row_C(const uint8_t* src_uyvy, int width); void UYVYToYRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void UYVYToUVRow_Any_AVX2(const uint8_t* src_ptr, - int src_stride_ptr, + int src_stride, uint8_t* dst_u, uint8_t* dst_v, int width); @@ -3349,7 +7046,7 @@ void UYVYToUV422Row_Any_AVX2(const uint8_t* src_ptr, int width); void UYVYToYRow_Any_SSE2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void UYVYToUVRow_Any_SSE2(const uint8_t* src_ptr, - int src_stride_ptr, + int src_stride, uint8_t* dst_u, uint8_t* dst_v, int width); @@ -3359,7 +7056,7 @@ void UYVYToUV422Row_Any_SSE2(const uint8_t* src_ptr, int width); void UYVYToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void UYVYToUVRow_Any_NEON(const uint8_t* src_ptr, - int src_stride_ptr, + int src_stride, uint8_t* dst_u, uint8_t* dst_v, int width); @@ -3367,26 +7064,26 @@ void UYVYToUV422Row_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); -void UYVYToYRow_Any_MSA(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void UYVYToYRow_Any_MMI(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void UYVYToUVRow_Any_MSA(const uint8_t* src_ptr, +void UYVYToYRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void UYVYToYRow_Any_LASX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void UYVYToUVRow_Any_LSX(const uint8_t* src_ptr, int src_stride_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); -void UYVYToUVRow_Any_MMI(const uint8_t* src_ptr, - int src_stride_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void UYVYToUV422Row_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_u, - uint8_t* dst_v, - int width); -void UYVYToUV422Row_Any_MMI(const uint8_t* src_ptr, +void UYVYToUVRow_Any_LASX(const uint8_t* src_ptr, + int src_stride_ptr, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void UYVYToUV422Row_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_u, uint8_t* dst_v, int width); +void UYVYToUV422Row_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_u, + uint8_t* dst_v, + int width); void SwapUVRow_C(const uint8_t* src_uv, uint8_t* dst_vu, int width); void SwapUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_vu, int width); void SwapUVRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); @@ -3394,31 +7091,76 @@ void SwapUVRow_SSSE3(const uint8_t* src_uv, uint8_t* dst_vu, int width); void SwapUVRow_Any_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void SwapUVRow_AVX2(const uint8_t* src_uv, uint8_t* dst_vu, int width); void SwapUVRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void SwapUVRow_AVX512BW(const uint8_t* src_uv, uint8_t* dst_vu, int width); +void SwapUVRow_RVV(const uint8_t* src_uv, uint8_t* dst_vu, int width); void AYUVToYRow_C(const uint8_t* src_ayuv, uint8_t* dst_y, int width); +void AYUVToYRow_AVX2(const uint8_t* src_ayuv, uint8_t* dst_y, int width); +void AYUVToYRow_AVX512VBMI(const uint8_t* src_ayuv, uint8_t* dst_y, int width); void AYUVToUVRow_C(const uint8_t* src_ayuv, - int stride_ayuv, + int src_stride_ayuv, uint8_t* dst_uv, int width); +void AYUVToUVRow_AVX2(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + int width); +void AYUVToUVRow_AVX512VBMI(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + int width); void AYUVToVURow_C(const uint8_t* src_ayuv, - int stride_ayuv, + int src_stride_ayuv, uint8_t* dst_vu, int width); +void AYUVToVURow_AVX2(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_vu, + int width); +void AYUVToVURow_AVX512VBMI(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_vu, + int width); void AYUVToYRow_NEON(const uint8_t* src_ayuv, uint8_t* dst_y, int width); void AYUVToUVRow_NEON(const uint8_t* src_ayuv, - int stride_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + int width); +void AYUVToUVRow_SVE2(const uint8_t* src_ayuv, + int src_stride_ayuv, uint8_t* dst_uv, int width); void AYUVToVURow_NEON(const uint8_t* src_ayuv, - int stride_ayuv, + int src_stride_ayuv, uint8_t* dst_vu, int width); -void AYUVToYRow_Any_NEON(const uint8_t* src_ayuv, uint8_t* dst_y, int width); -void AYUVToUVRow_Any_NEON(const uint8_t* src_ayuv, - int stride_ayuv, - uint8_t* dst_uv, +void AYUVToVURow_SVE2(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_vu, + int width); +void AYUVToYRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void AYUVToUVRow_Any_AVX2(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_vu, int width); -void AYUVToVURow_Any_NEON(const uint8_t* src_ayuv, - int stride_ayuv, +void AYUVToVURow_Any_AVX2(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_vu, + int width); +void AYUVToYRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void AYUVToUVRow_Any_NEON(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_vu, + int width); +void AYUVToUVRow_Any_SVE2(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_vu, + int width); +void AYUVToVURow_Any_NEON(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_vu, + int width); +void AYUVToVURow_Any_SVE2(const uint8_t* src_ptr, + int src_stride, uint8_t* dst_vu, int width); @@ -3492,46 +7234,46 @@ void I422ToUYVYRow_Any_NEON(const uint8_t* y_buf, const uint8_t* v_buf, uint8_t* dst_ptr, int width); -void I422ToYUY2Row_MSA(const uint8_t* src_y, +void I422ToYUY2Row_LSX(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_yuy2, int width); -void I422ToYUY2Row_MMI(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_yuy2, - int width); -void I422ToUYVYRow_MSA(const uint8_t* src_y, +void I422ToYUY2Row_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_yuy2, + int width); +void I422ToUYVYRow_LSX(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uyvy, int width); -void I422ToUYVYRow_MMI(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_uyvy, - int width); -void I422ToYUY2Row_Any_MSA(const uint8_t* y_buf, +void I422ToUYVYRow_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uyvy, + int width); +void I422ToYUY2Row_Any_LSX(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, int width); -void I422ToYUY2Row_Any_MMI(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_ptr, - int width); -void I422ToUYVYRow_Any_MSA(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_ptr, - int width); -void I422ToUYVYRow_Any_MMI(const uint8_t* y_buf, +void I422ToYUY2Row_Any_LASX(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + int width); +void I422ToUYVYRow_Any_LSX(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_ptr, int width); +void I422ToUYVYRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + int width); // Effects related row functions. void ARGBAttenuateRow_C(const uint8_t* src_argb, uint8_t* dst_argb, int width); @@ -3541,13 +7283,19 @@ void ARGBAttenuateRow_SSSE3(const uint8_t* src_argb, void ARGBAttenuateRow_AVX2(const uint8_t* src_argb, uint8_t* dst_argb, int width); +void ARGBAttenuateRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + int width); void ARGBAttenuateRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width); -void ARGBAttenuateRow_MSA(const uint8_t* src_argb, +void ARGBAttenuateRow_LSX(const uint8_t* src_argb, uint8_t* dst_argb, int width); -void ARGBAttenuateRow_MMI(const uint8_t* src_argb, +void ARGBAttenuateRow_LASX(const uint8_t* src_argb, + uint8_t* dst_argb, + int width); +void ARGBAttenuateRow_RVV(const uint8_t* src_argb, uint8_t* dst_argb, int width); void ARGBAttenuateRow_Any_SSSE3(const uint8_t* src_ptr, @@ -3559,12 +7307,12 @@ void ARGBAttenuateRow_Any_AVX2(const uint8_t* src_ptr, void ARGBAttenuateRow_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); -void ARGBAttenuateRow_Any_MSA(const uint8_t* src_ptr, - uint8_t* dst_ptr, - int width); -void ARGBAttenuateRow_Any_MMI(const uint8_t* src_ptr, +void ARGBAttenuateRow_Any_LSX(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGBAttenuateRow_Any_LASX(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); // Inverse table for unattenuate, shared by C and SSE2. extern const uint32_t fixed_invtbl8[256]; @@ -3577,66 +7325,97 @@ void ARGBUnattenuateRow_SSE2(const uint8_t* src_argb, void ARGBUnattenuateRow_AVX2(const uint8_t* src_argb, uint8_t* dst_argb, int width); +void ARGBUnattenuateRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + int width); void ARGBUnattenuateRow_Any_SSE2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); void ARGBUnattenuateRow_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int width); +void ARGBUnattenuateRow_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); void ARGBGrayRow_C(const uint8_t* src_argb, uint8_t* dst_argb, int width); -void ARGBGrayRow_SSSE3(const uint8_t* src_argb, uint8_t* dst_argb, int width); +void ARGBGrayRow_AVX2(const uint8_t* src_argb, uint8_t* dst_argb, int width); +void ARGBGrayRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + int width); +void ARGBGrayRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_argb, + int width); void ARGBGrayRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width); -void ARGBGrayRow_MSA(const uint8_t* src_argb, uint8_t* dst_argb, int width); -void ARGBGrayRow_MMI(const uint8_t* src_argb, uint8_t* dst_argb, int width); +void ARGBGrayRow_NEON_DotProd(const uint8_t* src_argb, + uint8_t* dst_argb, + int width); +void ARGBGrayRow_LSX(const uint8_t* src_argb, uint8_t* dst_argb, int width); +void ARGBGrayRow_LASX(const uint8_t* src_argb, uint8_t* dst_argb, int width); void ARGBSepiaRow_C(uint8_t* dst_argb, int width); -void ARGBSepiaRow_SSSE3(uint8_t* dst_argb, int width); +void ARGBSepiaRow_AVX2(uint8_t* dst_argb, int width); +void ARGBSepiaRow_AVX512VNNI(uint8_t* dst_argb, int width); void ARGBSepiaRow_NEON(uint8_t* dst_argb, int width); -void ARGBSepiaRow_MSA(uint8_t* dst_argb, int width); -void ARGBSepiaRow_MMI(uint8_t* dst_argb, int width); +void ARGBSepiaRow_NEON_DotProd(uint8_t* dst_argb, int width); +void ARGBSepiaRow_LSX(uint8_t* dst_argb, int width); +void ARGBSepiaRow_LASX(uint8_t* dst_argb, int width); void ARGBColorMatrixRow_C(const uint8_t* src_argb, uint8_t* dst_argb, const int8_t* matrix_argb, int width); -void ARGBColorMatrixRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_argb, - const int8_t* matrix_argb, - int width); +void ARGBColorMatrixRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + const int8_t* matrix_argb, + int width); +void ARGBColorMatrixRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_argb, + const int8_t* matrix_argb, + int width); void ARGBColorMatrixRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, const int8_t* matrix_argb, int width); -void ARGBColorMatrixRow_MSA(const uint8_t* src_argb, - uint8_t* dst_argb, - const int8_t* matrix_argb, - int width); -void ARGBColorMatrixRow_MMI(const uint8_t* src_argb, +void ARGBColorMatrixRow_NEON_I8MM(const uint8_t* src_argb, + uint8_t* dst_argb, + const int8_t* matrix_argb, + int width); +void ARGBColorMatrixRow_LSX(const uint8_t* src_argb, uint8_t* dst_argb, const int8_t* matrix_argb, int width); +void ARGBColorMatrixRow_LASX(const uint8_t* src_argb, + uint8_t* dst_argb, + const int8_t* matrix_argb, + int width); void ARGBColorTableRow_C(uint8_t* dst_argb, const uint8_t* table_argb, int width); -void ARGBColorTableRow_X86(uint8_t* dst_argb, - const uint8_t* table_argb, - int width); +void ARGBColorTableRow_AVX2(uint8_t* dst_argb, + const uint8_t* table_argb, + int width); +void ARGBColorTableRow_NEON(uint8_t* dst_argb, + const uint8_t* table_argb, + int width); void RGBColorTableRow_C(uint8_t* dst_argb, const uint8_t* table_argb, int width); -void RGBColorTableRow_X86(uint8_t* dst_argb, - const uint8_t* table_argb, - int width); +void RGBColorTableRow_AVX2(uint8_t* dst_argb, + const uint8_t* table_argb, + int width); +void RGBColorTableRow_NEON(uint8_t* dst_argb, + const uint8_t* table_argb, + int width); void ARGBQuantizeRow_C(uint8_t* dst_argb, int scale, int interval_size, int interval_offset, int width); -void ARGBQuantizeRow_SSE2(uint8_t* dst_argb, +void ARGBQuantizeRow_AVX2(uint8_t* dst_argb, int scale, int interval_size, int interval_offset, @@ -3646,17 +7425,22 @@ void ARGBQuantizeRow_NEON(uint8_t* dst_argb, int interval_size, int interval_offset, int width); -void ARGBQuantizeRow_MSA(uint8_t* dst_argb, +void ARGBQuantizeRow_LSX(uint8_t* dst_argb, int scale, int interval_size, int interval_offset, int width); +void ARGBQuantizeRow_LASX(uint8_t* dst_argb, + int scale, + int interval_size, + int interval_offset, + int width); void ARGBShadeRow_C(const uint8_t* src_argb, uint8_t* dst_argb, int width, uint32_t value); -void ARGBShadeRow_SSE2(const uint8_t* src_argb, +void ARGBShadeRow_AVX2(const uint8_t* src_argb, uint8_t* dst_argb, int width, uint32_t value); @@ -3664,31 +7448,36 @@ void ARGBShadeRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width, uint32_t value); -void ARGBShadeRow_MSA(const uint8_t* src_argb, - uint8_t* dst_argb, - int width, - uint32_t value); -void ARGBShadeRow_MMI(const uint8_t* src_argb, +void ARGBShadeRow_LSX(const uint8_t* src_argb, uint8_t* dst_argb, int width, uint32_t value); +void ARGBShadeRow_LASX(const uint8_t* src_argb, + uint8_t* dst_argb, + int width, + uint32_t value); // Used for blur. -void CumulativeSumToAverageRow_SSE2(const int32_t* topleft, +void CumulativeSumToAverageRow_AVX2(const int32_t* topleft, const int32_t* botleft, int width, int area, uint8_t* dst, int count); -void ComputeCumulativeSumRow_SSE2(const uint8_t* row, +void ComputeCumulativeSumRow_AVX2(const uint8_t* row, + int32_t* cumsum, + const int32_t* previous_cumsum, + int width); +void CumulativeSumToAverageRow_NEON(const int32_t* topleft, + const int32_t* botleft, + int width, + int area, + uint8_t* dst, + int count); +void ComputeCumulativeSumRow_NEON(const uint8_t* row, int32_t* cumsum, const int32_t* previous_cumsum, int width); - -void ComputeCumulativeSumRow_MMI(const uint8_t* row, - int32_t* cumsum, - const int32_t* previous_cumsum, - int width); void CumulativeSumToAverageRow_C(const int32_t* tl, const int32_t* bl, @@ -3708,7 +7497,13 @@ void ARGBAffineRow_C(const uint8_t* src_argb, const float* uv_dudv, int width); LIBYUV_API -void ARGBAffineRow_SSE2(const uint8_t* src_argb, +void ARGBAffineRow_AVX2(const uint8_t* src_argb, + int src_argb_stride, + uint8_t* dst_argb, + const float* src_dudv, + int width); +LIBYUV_API +void ARGBAffineRow_NEON(const uint8_t* src_argb, int src_argb_stride, uint8_t* dst_argb, const float* src_dudv, @@ -3720,27 +7515,42 @@ void InterpolateRow_C(uint8_t* dst_ptr, ptrdiff_t src_stride, int width, int source_y_fraction); -void InterpolateRow_SSSE3(uint8_t* dst_ptr, - const uint8_t* src_ptr, - ptrdiff_t src_stride, - int dst_width, - int source_y_fraction); void InterpolateRow_AVX2(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction); +void InterpolateRow_AVX512BW(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int dst_width, + int source_y_fraction); void InterpolateRow_NEON(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction); -void InterpolateRow_MSA(uint8_t* dst_ptr, +void InterpolateRow_SVE2(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int dst_width, + int source_y_fraction); +void InterpolateRow_SME(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int dst_width, + int source_y_fraction); +void InterpolateRow_LSX(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride, int width, int source_y_fraction); -void InterpolateRow_MMI(uint8_t* dst_ptr, +void InterpolateRow_LASX(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void InterpolateRow_RVV(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride, int width, @@ -3750,32 +7560,57 @@ void InterpolateRow_Any_NEON(uint8_t* dst_ptr, ptrdiff_t src_stride_ptr, int width, int source_y_fraction); -void InterpolateRow_Any_SSSE3(uint8_t* dst_ptr, - const uint8_t* src_ptr, - ptrdiff_t src_stride_ptr, - int width, - int source_y_fraction); void InterpolateRow_Any_AVX2(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride_ptr, int width, int source_y_fraction); -void InterpolateRow_Any_MSA(uint8_t* dst_ptr, - const uint8_t* src_ptr, - ptrdiff_t src_stride_ptr, - int width, - int source_y_fraction); -void InterpolateRow_Any_MMI(uint8_t* dst_ptr, +void InterpolateRow_Any_LSX(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride_ptr, int width, int source_y_fraction); +void InterpolateRow_Any_LASX(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride_ptr, + int width, + int source_y_fraction); void InterpolateRow_16_C(uint16_t* dst_ptr, const uint16_t* src_ptr, ptrdiff_t src_stride, int width, int source_y_fraction); +void InterpolateRow_16_AVX2(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void InterpolateRow_16_Any_AVX2(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void InterpolateRow_16_AVX512BW(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void InterpolateRow_16_NEON(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void InterpolateRow_16_Any_NEON(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void InterpolateRow_16_SME(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); // Sobel images. void SobelXRow_C(const uint8_t* src_y0, @@ -3783,7 +7618,7 @@ void SobelXRow_C(const uint8_t* src_y0, const uint8_t* src_y2, uint8_t* dst_sobelx, int width); -void SobelXRow_SSE2(const uint8_t* src_y0, +void SobelXRow_AVX2(const uint8_t* src_y0, const uint8_t* src_y1, const uint8_t* src_y2, uint8_t* dst_sobelx, @@ -3793,21 +7628,11 @@ void SobelXRow_NEON(const uint8_t* src_y0, const uint8_t* src_y2, uint8_t* dst_sobelx, int width); -void SobelXRow_MSA(const uint8_t* src_y0, - const uint8_t* src_y1, - const uint8_t* src_y2, - uint8_t* dst_sobelx, - int width); -void SobelXRow_MMI(const uint8_t* src_y0, - const uint8_t* src_y1, - const uint8_t* src_y2, - uint8_t* dst_sobelx, - int width); void SobelYRow_C(const uint8_t* src_y0, const uint8_t* src_y1, uint8_t* dst_sobely, int width); -void SobelYRow_SSE2(const uint8_t* src_y0, +void SobelYRow_AVX2(const uint8_t* src_y0, const uint8_t* src_y1, uint8_t* dst_sobely, int width); @@ -3815,19 +7640,11 @@ void SobelYRow_NEON(const uint8_t* src_y0, const uint8_t* src_y1, uint8_t* dst_sobely, int width); -void SobelYRow_MSA(const uint8_t* src_y0, - const uint8_t* src_y1, - uint8_t* dst_sobely, - int width); -void SobelYRow_MMI(const uint8_t* src_y0, - const uint8_t* src_y1, - uint8_t* dst_sobely, - int width); void SobelRow_C(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width); -void SobelRow_SSE2(const uint8_t* src_sobelx, +void SobelRow_AVX2(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width); @@ -3835,19 +7652,19 @@ void SobelRow_NEON(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width); -void SobelRow_MSA(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_argb, - int width); -void SobelRow_MMI(const uint8_t* src_sobelx, +void SobelRow_LSX(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width); +void SobelRow_LASX(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_argb, + int width); void SobelToPlaneRow_C(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_y, int width); -void SobelToPlaneRow_SSE2(const uint8_t* src_sobelx, +void SobelToPlaneRow_AVX2(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_y, int width); @@ -3855,19 +7672,19 @@ void SobelToPlaneRow_NEON(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_y, int width); -void SobelToPlaneRow_MSA(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_y, - int width); -void SobelToPlaneRow_MMI(const uint8_t* src_sobelx, +void SobelToPlaneRow_LSX(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_y, int width); +void SobelToPlaneRow_LASX(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_y, + int width); void SobelXYRow_C(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width); -void SobelXYRow_SSE2(const uint8_t* src_sobelx, +void SobelXYRow_AVX2(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width); @@ -3875,15 +7692,15 @@ void SobelXYRow_NEON(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width); -void SobelXYRow_MSA(const uint8_t* src_sobelx, +void SobelXYRow_LSX(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width); -void SobelXYRow_MMI(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_argb, - int width); -void SobelRow_Any_SSE2(const uint8_t* y_buf, +void SobelXYRow_LASX(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_argb, + int width); +void SobelRow_Any_AVX2(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); @@ -3891,15 +7708,15 @@ void SobelRow_Any_NEON(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void SobelRow_Any_MSA(const uint8_t* y_buf, +void SobelRow_Any_LSX(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void SobelRow_Any_MMI(const uint8_t* y_buf, - const uint8_t* uv_buf, - uint8_t* dst_ptr, - int width); -void SobelToPlaneRow_Any_SSE2(const uint8_t* y_buf, +void SobelRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); +void SobelToPlaneRow_Any_AVX2(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); @@ -3907,15 +7724,15 @@ void SobelToPlaneRow_Any_NEON(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void SobelToPlaneRow_Any_MSA(const uint8_t* y_buf, +void SobelToPlaneRow_Any_LSX(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void SobelToPlaneRow_Any_MMI(const uint8_t* y_buf, - const uint8_t* uv_buf, - uint8_t* dst_ptr, - int width); -void SobelXYRow_Any_SSE2(const uint8_t* y_buf, +void SobelToPlaneRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); +void SobelXYRow_Any_AVX2(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); @@ -3923,14 +7740,14 @@ void SobelXYRow_Any_NEON(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); -void SobelXYRow_Any_MSA(const uint8_t* y_buf, - const uint8_t* uv_buf, - uint8_t* dst_ptr, - int width); -void SobelXYRow_Any_MMI(const uint8_t* y_buf, +void SobelXYRow_Any_LSX(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, int width); +void SobelXYRow_Any_LASX(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); void ARGBPolynomialRow_C(const uint8_t* src_argb, uint8_t* dst_argb, @@ -3944,21 +7761,33 @@ void ARGBPolynomialRow_AVX2(const uint8_t* src_argb, uint8_t* dst_argb, const float* poly, int width); +void ARGBPolynomialRow_Any_SSE2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + const float* param, + int width); +void ARGBPolynomialRow_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + const float* param, + int width); +void ARGBPolynomialRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + const float* poly, + int width); +void ARGBPolynomialRow_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + const float* param, + int width); // Scale and convert to half float. void HalfFloatRow_C(const uint16_t* src, uint16_t* dst, float scale, int width); -void HalfFloatRow_SSE2(const uint16_t* src, - uint16_t* dst, - float scale, - int width); -void HalfFloatRow_Any_SSE2(const uint16_t* src_ptr, - uint16_t* dst_ptr, - float param, - int width); void HalfFloatRow_AVX2(const uint16_t* src, uint16_t* dst, float scale, int width); +void HalfFloatRow_AVX512BW(const uint16_t* src, + uint16_t* dst, + float scale, + int width); void HalfFloatRow_Any_AVX2(const uint16_t* src_ptr, uint16_t* dst_ptr, float param, @@ -3987,23 +7816,39 @@ void HalfFloatRow_Any_NEON(const uint16_t* src_ptr, uint16_t* dst_ptr, float param, int width); -void HalfFloat1Row_NEON(const uint16_t* src, +void HalfFloatRow_SVE2(const uint16_t* src, + uint16_t* dst, + float scale, + int width); +void HalfFloat1Row_SVE2(const uint16_t* src, uint16_t* dst, float scale, int width); -void HalfFloat1Row_Any_NEON(const uint16_t* src_ptr, - uint16_t* dst_ptr, - float param, - int width); -void HalfFloatRow_MSA(const uint16_t* src, +void HalfFloatRow_LSX(const uint16_t* src, uint16_t* dst, float scale, int width); -void HalfFloatRow_Any_MSA(const uint16_t* src_ptr, +void HalfFloatRow_LASX(const uint16_t* src, + uint16_t* dst, + float scale, + int width); +void HalfFloatRow_Any_LSX(const uint16_t* src_ptr, uint16_t* dst_ptr, float param, int width); +void HalfFloatRow_Any_LASX(const uint16_t* src_ptr, + uint16_t* dst_ptr, + float param, + int width); void ByteToFloatRow_C(const uint8_t* src, float* dst, float scale, int width); +void ByteToFloatRow_AVX2(const uint8_t* src, + float* dst, + float scale, + int width); +void ByteToFloatRow_Any_AVX2(const uint8_t* src_ptr, + float* dst_ptr, + float param, + int width); void ByteToFloatRow_NEON(const uint8_t* src, float* dst, float scale, @@ -4012,31 +7857,698 @@ void ByteToFloatRow_Any_NEON(const uint8_t* src_ptr, float* dst_ptr, float param, int width); - +// Convert FP16 Half Floats to FP32 Floats +void ConvertFP16ToFP32Row_NEON(const uint16_t* src, // fp16 + float* dst, + int width); +// Convert a column of FP16 Half Floats to a row of FP32 Floats +void ConvertFP16ToFP32Column_NEON(const uint16_t* src, // fp16 + int src_stride, // stride in elements + float* dst, + int width); +// Convert FP32 Floats to FP16 Half Floats +void ConvertFP32ToFP16Row_NEON(const float* src, + uint16_t* dst, // fp16 + int width); void ARGBLumaColorTableRow_C(const uint8_t* src_argb, uint8_t* dst_argb, int width, const uint8_t* luma, uint32_t lumacoeff); -void ARGBLumaColorTableRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_argb, - int width, - const uint8_t* luma, - uint32_t lumacoeff); +void ARGBLumaColorTableRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + int width, + const uint8_t* luma, + uint32_t lumacoeff); +void ARGBLumaColorTableRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + int width, + const uint8_t* luma, + uint32_t lumacoeff); float ScaleMaxSamples_C(const float* src, float* dst, float scale, int width); +float ScaleMaxSamples_AVX2(const float* src, + float* dst, + float scale, + int width); float ScaleMaxSamples_NEON(const float* src, float* dst, float scale, int width); float ScaleSumSamples_C(const float* src, float* dst, float scale, int width); +float ScaleSumSamples_AVX2(const float* src, + float* dst, + float scale, + int width); float ScaleSumSamples_NEON(const float* src, float* dst, float scale, int width); void ScaleSamples_C(const float* src, float* dst, float scale, int width); +void ScaleSamples_AVX2(const float* src, float* dst, float scale, int width); void ScaleSamples_NEON(const float* src, float* dst, float scale, int width); +void GaussRow_F32_AVX2(const float* src, float* dst, int width); +void GaussRow_F32_NEON(const float* src, float* dst, int width); +void GaussRow_F32_C(const float* src, float* dst, int width); + +void GaussCol_F32_AVX2(const float* src0, + const float* src1, + const float* src2, + const float* src3, + const float* src4, + float* dst, + int width); + +void GaussCol_F32_NEON(const float* src0, + const float* src1, + const float* src2, + const float* src3, + const float* src4, + float* dst, + int width); + +void GaussCol_F32_C(const float* src0, + const float* src1, + const float* src2, + const float* src3, + const float* src4, + float* dst, + int width); + +void GaussRow_C(const uint32_t* src, uint16_t* dst, int width); +void GaussRow_AVX2(const uint32_t* src, uint16_t* dst, int width); +void GaussRow_NEON(const uint32_t* src, uint16_t* dst, int width); +void GaussCol_C(const uint16_t* src0, + const uint16_t* src1, + const uint16_t* src2, + const uint16_t* src3, + const uint16_t* src4, + uint32_t* dst, + int width); +void GaussCol_AVX2(const uint16_t* src0, + const uint16_t* src1, + const uint16_t* src2, + const uint16_t* src3, + const uint16_t* src4, + uint32_t* dst, + int width); +void GaussCol_NEON(const uint16_t* src0, + const uint16_t* src1, + const uint16_t* src2, + const uint16_t* src3, + const uint16_t* src4, + uint32_t* dst, + int width); + +void ClampFloatToZero_SSE2(const float* src_x, float* dst_y, int width); + +void RAWToARGBRow_WASMSIMD(const uint8_t* src_raw, + uint8_t* dst_argb, + int width); +void RGB24ToARGBRow_WASMSIMD(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width); +void ARGBToYMatrixRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_WASMSIMD(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void RGB565ToYMatrixRow_WASMSIMD(const uint8_t* src_rgb565, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB1555ToYMatrixRow_WASMSIMD(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGB4444ToYMatrixRow_WASMSIMD(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUV444MatrixRow_WASMSIMD(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_WASMSIMD(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUVMatrixRow_WASMSIMD(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGB565ToUVMatrixRow_WASMSIMD(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGB1555ToUVMatrixRow_WASMSIMD(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGB4444ToUVMatrixRow_WASMSIMD(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void Convert8To16Row_WASMSIMD(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width); +void MultiplyRow_16_WASMSIMD(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); +void MergeUVRow_WASMSIMD(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width); +void MirrorRow_WASMSIMD(const uint8_t* src, uint8_t* dst, int width); +void MirrorUVRow_WASMSIMD(const uint8_t* src_uv, uint8_t* dst_uv, int width); +void SwapUVRow_WASMSIMD(const uint8_t* src_uv, uint8_t* dst_vu, int width); +void MirrorSplitUVRow_WASMSIMD(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void RGB24MirrorRow_WASMSIMD(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width); +void ARGBMirrorRow_WASMSIMD(const uint8_t* src, uint8_t* dst, int width); +void InterpolateRow_WASMSIMD(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void InterpolateRow_16_WASMSIMD(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void J400ToARGBRow_WASMSIMD(const uint8_t* src_y, uint8_t* dst_argb, int width); +void RGB565ToARGBRow_WASMSIMD(const uint8_t* src_rgb565, + uint8_t* dst_argb, + int width); +void ARGB1555ToARGBRow_WASMSIMD(const uint8_t* src_argb1555, + uint8_t* dst_argb, + int width); +void ARGB4444ToARGBRow_WASMSIMD(const uint8_t* src_argb4444, + uint8_t* dst_argb, + int width); +void ARGBToRGB565DitherRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_rgb, + uint32_t dither4, + int width); +void ARGBToRGB565Row_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width); +void ARGBToARGB1555Row_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_argb1555, + int width); +void ARGBToARGB4444Row_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_argb4444, + int width); +void ARGBShuffleRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_argb, + const uint8_t* shuffler, + int width); +void I422ToARGBRow_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToAR30Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToARGBRow_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void NV21ToARGBRow_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB24Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB565Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB1555Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB4444Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToRGB565Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width); +void ARGBBlendRow_WASMSIMD(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void BlendPlaneRow_WASMSIMD(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width); + +void RAWToARGBRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void RGB24ToARGBRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBToYMatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width, + const struct ArgbConstants* c); +void RGBToYMatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width, + const struct ArgbConstants* c); +void RGB565ToYMatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width, + const struct ArgbConstants* c); +void ARGB1555ToYMatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width, + const struct ArgbConstants* c); +void ARGB4444ToYMatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUV444MatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGBToUVMatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void RGB565ToUVMatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGB1555ToUVMatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGB4444ToUVMatrixRow_Any_WASMSIMD(const uint8_t* src_ptr, + int src_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void Convert8To16Row_Any_WASMSIMD(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int scale, + int width); +void MultiplyRow_16_Any_WASMSIMD(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int scale, + int width); +void MergeUVRow_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + int width); +void MirrorRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void MirrorUVRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void SwapUVRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void RGB24MirrorRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBMirrorRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void InterpolateRow_Any_WASMSIMD(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void InterpolateRow_16_Any_WASMSIMD(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void J400ToARGBRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void RGB565ToARGBRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGB1555ToARGBRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGB4444ToARGBRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBToRGB565DitherRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + const uint32_t dither4, + int width); +void ARGBToRGB565Row_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBToARGB1555Row_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBToARGB4444Row_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int width); +void ARGBShuffleRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint8_t* dst_ptr, + const uint8_t* shuffler, + int width); +void I422ToARGBRow_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToAR30Row_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToARGBRow_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void NV21ToARGBRow_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB24Row_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGB565Row_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB1555Row_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void I422ToARGB4444Row_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToRGB565Row_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_ptr, + const struct YuvConstants* yuvconstants, + int width); +void BlendPlaneRow_Any_WASMSIMD(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ptr, + int width); + +void CopyRow_HVX(const uint8_t* src, uint8_t* dst, int count); +void CopyRow_16_HVX(const uint16_t* src, uint16_t* dst, int count); +void SetRow_HVX(uint8_t* dst, uint8_t v8, int width); +void ARGBSetRow_HVX(uint8_t* dst_argb, uint32_t v32, int width); +void MirrorRow_HVX(const uint8_t* src, uint8_t* dst, int width); +void MirrorRow_16_HVX(const uint16_t* src, uint16_t* dst, int width); +void MirrorUVRow_HVX(const uint8_t* src_uv, uint8_t* dst_uv, int width); +void MirrorSplitUVRow_HVX(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void ARGBMirrorRow_HVX(const uint8_t* src, uint8_t* dst, int width); +void SplitUVRow_HVX(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void MergeUVRow_HVX(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width); +void SplitUVRow_16_HVX(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width); +void MergeUVRow_16_HVX(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width); +void SplitARGBRow_HVX(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width); +void MergeARGBRow_HVX(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width); +void SplitXRGBRow_HVX(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width); +void MergeXRGBRow_HVX(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width); +void SwapUVRow_HVX(const uint8_t* src_uv, uint8_t* dst_vu, int width); +void InterpolateRow_HVX(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void InterpolateRow_16_HVX(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction); +void BlendPlaneRow_HVX(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width); +void ARGBBlendRow_HVX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAttenuateRow_HVX(const uint8_t* src_argb, + uint8_t* dst_argb, + int width); +void ARGBMultiplyRow_HVX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBAddRow_HVX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBSubtractRow_HVX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width); +void ARGBExtractAlphaRow_HVX(const uint8_t* src_argb, + uint8_t* dst_a, + int width); +void ARGBCopyAlphaRow_HVX(const uint8_t* src, uint8_t* dst, int width); +void ARGBCopyYToAlphaRow_HVX(const uint8_t* src, uint8_t* dst, int width); +void Convert16To8Row_HVX(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width); +void Convert8To16Row_HVX(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width); +void Convert8To8Row_HVX(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width); +void MultiplyRow_16_HVX(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); +void DivideRow_16_HVX(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width); +void HalfRow_16To8_HVX(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width); +void YUY2ToYRow_HVX(const uint8_t* src_yuy2, uint8_t* dst_y, int width); +void YUY2ToUVRow_HVX(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void YUY2ToUV422Row_HVX(const uint8_t* src_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void UYVYToYRow_HVX(const uint8_t* src_uyvy, uint8_t* dst_y, int width); +void UYVYToUVRow_HVX(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void UYVYToUV422Row_HVX(const uint8_t* src_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width); +void I400ToARGBRow_HVX(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void J400ToARGBRow_HVX(const uint8_t* src_y, uint8_t* dst_argb, int width); +void ARGBToABGRRow_HVX(const uint8_t* src_argb, uint8_t* dst_abgr, int width); +void ARGBToBGRARow_HVX(const uint8_t* src_argb, uint8_t* dst_bgra, int width); +void ARGBToRGBARow_HVX(const uint8_t* src_argb, uint8_t* dst_rgba, int width); +void RGBAToARGBRow_HVX(const uint8_t* src_rgba, uint8_t* dst_argb, int width); +void ARGBToAR64Row_HVX(const uint8_t* src_argb, uint16_t* dst_ar64, int width); +void ARGBToAB64Row_HVX(const uint8_t* src_argb, uint16_t* dst_ab64, int width); +void AR64ToARGBRow_HVX(const uint16_t* src_ar64, uint8_t* dst_argb, int width); +void AB64ToARGBRow_HVX(const uint16_t* src_ab64, uint8_t* dst_argb, int width); +void AR64ToAB64Row_HVX(const uint16_t* src_ar64, uint16_t* dst_ab64, int width); +void I422ToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444ToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422AlphaToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I444AlphaToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void I422ToRGBARow_HVX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width); +void NV12ToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void NV21ToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width); +void ARGBToYMatrixRow_HVX(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c); +void ARGBToUVMatrixRow_HVX(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); +void ARGBToUV444MatrixRow_HVX(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c); + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/include/libyuv/row_sve.h b/libs/libyuv/include/libyuv/row_sve.h new file mode 100644 index 0000000000..7faf57db84 --- /dev/null +++ b/libs/libyuv/include/libyuv/row_sve.h @@ -0,0 +1,2524 @@ +/* + * Copyright 2024 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef INCLUDE_LIBYUV_ROW_SVE_H_ +#define INCLUDE_LIBYUV_ROW_SVE_H_ + +#include "libyuv/row.h" + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +#if !defined(LIBYUV_DISABLE_SVE) && defined(__aarch64__) + +#if !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && \ + defined(__aarch64__) +#define STREAMING_COMPATIBLE __arm_streaming_compatible +#else // defined(LIBYUV_DISABLE_SME) || !defined(CLANG_HAS_SME) || + // !defined(__aarch64__) +#define STREAMING_COMPATIBLE +#endif // !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && + // defined(__aarch64__) + +#define YUVTORGB_SVE_SETUP \ + "ld1rb {z28.b}, p0/z, [%[kUVCoeff], #0] \n" \ + "ld1rb {z29.b}, p0/z, [%[kUVCoeff], #1] \n" \ + "ld1rb {z30.b}, p0/z, [%[kUVCoeff], #2] \n" \ + "ld1rb {z31.b}, p0/z, [%[kUVCoeff], #3] \n" \ + "ld1rh {z24.h}, p0/z, [%[kRGBCoeffBias], #0] \n" \ + "ld1rh {z25.h}, p0/z, [%[kRGBCoeffBias], #2] \n" \ + "ld1rh {z26.h}, p0/z, [%[kRGBCoeffBias], #4] \n" \ + "ld1rh {z27.h}, p0/z, [%[kRGBCoeffBias], #6] \n" + +#define YUVTORGB_SVE_SETUP_AR30 \ + YUVTORGB_SVE_SETUP \ + "add z25.h, z25.h, #24 \n" \ + "sub z26.h, z26.h, #24 \n" \ + "add z27.h, z27.h, #24 \n" + +#define READYUV444_SVE \ + "ld1b {z0.h}, p1/z, [%[src_y]] \n" \ + "ld1b {z1.h}, p1/z, [%[src_u]] \n" \ + "ld1b {z2.h}, p1/z, [%[src_v]] \n" \ + "add %[src_y], %[src_y], %[vl] \n" \ + "add %[src_u], %[src_u], %[vl] \n" \ + "add %[src_v], %[src_v], %[vl] \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_u], 448] \n" \ + "trn1 z0.b, z0.b, z0.b \n" \ + "prfm pldl1keep, [%[src_v], 448] \n" + +// Read twice as much data from YUV, putting the even elements from the Y data +// in z0.h and odd elements in z1.h. +#define READYUV444_SVE_2X \ + "ld1b {z0.b}, p1/z, [%[src_y]] \n" \ + "ld1b {z2.b}, p1/z, [%[src_u]] \n" \ + "ld1b {z3.b}, p1/z, [%[src_v]] \n" \ + "incb %[src_y] \n" \ + "incb %[src_u] \n" \ + "incb %[src_v] \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" \ + "trn2 z1.b, z0.b, z0.b \n" \ + "trn1 z0.b, z0.b, z0.b \n" + +#define READYUV400_SVE \ + "ld1b {z0.h}, p1/z, [%[src_y]] \n" \ + "inch %[src_y] \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "trn1 z0.b, z0.b, z0.b \n" + +#define READYUV422_SVE \ + "ld1b {z0.h}, p1/z, [%[src_y]] \n" \ + "ld1b {z1.s}, p1/z, [%[src_u]] \n" \ + "ld1b {z2.s}, p1/z, [%[src_v]] \n" \ + "inch %[src_y] \n" \ + "incw %[src_u] \n" \ + "incw %[src_v] \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" \ + "trn1 z0.b, z0.b, z0.b \n" \ + "trn1 z1.h, z1.h, z1.h \n" \ + "trn1 z2.h, z2.h, z2.h \n" + +// Read twice as much data from YUV, putting the even elements from the Y data +// in z0.h and odd elements in z1.h. U/V data is not duplicated, stored in +// z2.h/z3.h. +#define READYUV422_SVE_2X \ + "ld1b {z0.b}, p1/z, [%[src_y]] \n" \ + "ld1b {z2.h}, p1/z, [%[src_u]] \n" \ + "ld1b {z3.h}, p1/z, [%[src_v]] \n" \ + "incb %[src_y] \n" \ + "inch %[src_u] \n" \ + "inch %[src_v] \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" \ + "trn2 z1.b, z0.b, z0.b \n" \ + "trn1 z0.b, z0.b, z0.b \n" + +#define READI210_SVE \ + "ld1h {z3.h}, p1/z, [%[src_y]] \n" \ + "ld1h {z1.s}, p1/z, [%[src_u]] \n" \ + "ld1h {z2.s}, p1/z, [%[src_v]] \n" \ + "incb %[src_y] \n" \ + "inch %[src_u] \n" \ + "inch %[src_v] \n" \ + "lsl z0.h, z3.h, #6 \n" \ + "trn1 z1.h, z1.h, z1.h \n" \ + "trn1 z2.h, z2.h, z2.h \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" \ + "usra z0.h, z3.h, #4 \n" \ + "uqshrnb z1.b, z1.h, #2 \n" \ + "uqshrnb z2.b, z2.h, #2 \n" + +#define READI210_SVE_2X \ + "ld1h {z4.h}, p2/z, [%[src_y]] \n" \ + "ld1h {z5.h}, p3/z, [%[src_y], #1, mul vl] \n" \ + "ld1h {z2.h}, p1/z, [%[src_u]] \n" \ + "ld1h {z3.h}, p1/z, [%[src_v]] \n" \ + "incb %[src_y], all, mul #2 \n" \ + "uzp1 z6.h, z4.h, z5.h \n" \ + "uzp2 z5.h, z4.h, z5.h \n" \ + "incb %[src_u] \n" \ + "incb %[src_v] \n" \ + "lsl z0.h, z6.h, #6 \n" \ + "lsl z1.h, z5.h, #6 \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" \ + "usra z0.h, z6.h, #4 \n" \ + "usra z1.h, z5.h, #4 \n" \ + "uqshrnb z2.b, z2.h, #2 \n" \ + "uqshrnb z3.b, z3.h, #2 \n" + +#define READP210_SVE \ + "ld1h {z0.h}, p1/z, [%[src_y]] \n" \ + "ld1h {z1.h}, p2/z, [%[src_uv]] \n" \ + "incb %[src_y] \n" \ + "incb %[src_uv] \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_uv], 256] \n" \ + "tbl z1.b, {z1.b}, z22.b \n" + +#define READI410_SVE \ + "ld1h {z3.h}, p1/z, [%[src_y]] \n" \ + "lsl z0.h, z3.h, #6 \n" \ + "usra z0.h, z3.h, #4 \n" \ + "ld1h {z1.h}, p1/z, [%[src_u]] \n" \ + "ld1h {z2.h}, p1/z, [%[src_v]] \n" \ + "incb %[src_y] \n" \ + "incb %[src_u] \n" \ + "incb %[src_v] \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" \ + "uqshrnb z1.b, z1.h, #2 \n" \ + "uqshrnb z2.b, z2.h, #2 \n" + +// We need different predicates for the UV components since we are reading +// 32-bit (pairs of UV) elements rather than 16-bit Y elements. +#define READP410_SVE \ + "ld1h {z0.h}, p1/z, [%[src_y]] \n" \ + "ld1w {z1.s}, p2/z, [%[src_uv]] \n" \ + "ld1w {z2.s}, p3/z, [%[src_uv], #1, mul vl] \n" \ + "incb %[src_y] \n" \ + "incb %[src_uv], all, mul #2 \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_uv], 256] \n" \ + "uzp2 z1.b, z1.b, z2.b \n" + +#define READI212_SVE \ + "ld1h {z3.h}, p1/z, [%[src_y]] \n" \ + "ld1h {z1.s}, p1/z, [%[src_u]] \n" \ + "ld1h {z2.s}, p1/z, [%[src_v]] \n" \ + "incb %[src_y] \n" \ + "inch %[src_u] \n" \ + "inch %[src_v] \n" \ + "lsl z0.h, z3.h, #4 \n" \ + "trn1 z1.h, z1.h, z1.h \n" \ + "trn1 z2.h, z2.h, z2.h \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" \ + "usra z0.h, z3.h, #8 \n" \ + "uqshrnb z1.b, z1.h, #4 \n" \ + "uqshrnb z2.b, z2.h, #4 \n" + +#define I400TORGB_SVE \ + "umulh z18.h, z24.h, z0.h \n" /* Y */ \ + "movprfx z16, z18 \n" \ + "usqadd z16.h, p0/m, z16.h, z4.h \n" /* B */ \ + "movprfx z17, z18 \n" \ + "usqadd z17.h, p0/m, z17.h, z6.h \n" /* G */ \ + "usqadd z18.h, p0/m, z18.h, z5.h \n" /* R */ + +// We need a different predicate for the UV component to handle the tail. +// If there is a single element remaining then we want to load one Y element +// but two UV elements. +#define READNV_SVE_2X \ + "ld1b {z0.b}, p1/z, [%[src_y]] \n" /* Y0Y0 */ \ + "ld1b {z2.b}, p2/z, [%[src_uv]] \n" /* U0V0 or V0U0 */ \ + "incb %[src_y] \n" \ + "incb %[src_uv] \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_uv], 256] \n" \ + "trn2 z1.b, z0.b, z0.b \n" /* YYYY */ \ + "trn1 z0.b, z0.b, z0.b \n" /* YYYY */ + +// Like NVTORGB_SVE but U/V components are stored in widened .h elements of +// z1/z2 rather than even/odd .b lanes of z1. +#define I4XXTORGB_SVE \ + "umulh z0.h, z24.h, z0.h \n" /* Y */ \ + "umullb z6.h, z30.b, z1.b \n" \ + "umullb z4.h, z28.b, z1.b \n" /* DB */ \ + "umullb z5.h, z29.b, z2.b \n" /* DR */ \ + "umlalb z6.h, z31.b, z2.b \n" /* DG */ \ + "add z17.h, z0.h, z26.h \n" /* G */ \ + "add z16.h, z0.h, z4.h \n" /* B */ \ + "add z18.h, z0.h, z5.h \n" /* R */ \ + "uqsub z17.h, z17.h, z6.h \n" /* G */ \ + "uqsub z16.h, z16.h, z25.h \n" /* B */ \ + "uqsub z18.h, z18.h, z27.h \n" /* R */ + +#define I444TORGB_SVE_2X \ + "umulh z0.h, z24.h, z0.h \n" /* Y0 */ \ + "umulh z1.h, z24.h, z1.h \n" /* Y1 */ \ + "umullb z6.h, z30.b, z2.b \n" \ + "umullt z7.h, z30.b, z2.b \n" \ + "umullb z4.h, z28.b, z2.b \n" /* DB */ \ + "umullt z2.h, z28.b, z2.b \n" /* DB */ \ + "umlalb z6.h, z31.b, z3.b \n" /* DG */ \ + "umlalt z7.h, z31.b, z3.b \n" /* DG */ \ + "umullb z5.h, z29.b, z3.b \n" /* DR */ \ + "umullt z3.h, z29.b, z3.b \n" /* DR */ \ + "add z17.h, z0.h, z26.h \n" /* G */ \ + "add z21.h, z1.h, z26.h \n" /* G */ \ + "add z16.h, z0.h, z4.h \n" /* B */ \ + "add z20.h, z1.h, z2.h \n" /* B */ \ + "add z18.h, z0.h, z5.h \n" /* R */ \ + "add z22.h, z1.h, z3.h \n" /* R */ \ + "uqsub z17.h, z17.h, z6.h \n" /* G */ \ + "uqsub z21.h, z21.h, z7.h \n" /* G */ \ + "uqsub z16.h, z16.h, z25.h \n" /* B */ \ + "uqsub z20.h, z20.h, z25.h \n" /* B */ \ + "uqsub z18.h, z18.h, z27.h \n" /* R */ \ + "uqsub z22.h, z22.h, z27.h \n" /* R */ + +// Like I4XXTORGB_SVE but U/V components are stored in even/odd .b lanes of z1 +// rather than widened .h elements of z1/z2. +#define NVTORGB_SVE \ + "umulh z0.h, z24.h, z0.h \n" /* Y */ \ + "umullb z6.h, z30.b, z1.b \n" \ + "umullb z4.h, z28.b, z1.b \n" /* DB */ \ + "umullt z5.h, z29.b, z1.b \n" /* DR */ \ + "umlalt z6.h, z31.b, z1.b \n" /* DG */ \ + "add z17.h, z0.h, z26.h \n" /* G */ \ + "add z16.h, z0.h, z4.h \n" /* B */ \ + "add z18.h, z0.h, z5.h \n" /* R */ \ + "uqsub z17.h, z17.h, z6.h \n" /* G */ \ + "uqsub z16.h, z16.h, z25.h \n" /* B */ \ + "uqsub z18.h, z18.h, z27.h \n" /* R */ + +// The U/V component multiplies do not need to be duplicated in I422, we just +// need to combine them with Y0/Y1 correctly. +#define I422TORGB_SVE_2X \ + "umulh z0.h, z24.h, z0.h \n" /* Y0 */ \ + "umulh z1.h, z24.h, z1.h \n" /* Y1 */ \ + "umullb z6.h, z30.b, z2.b \n" \ + "umullb z4.h, z28.b, z2.b \n" /* DB */ \ + "umullb z5.h, z29.b, z3.b \n" /* DR */ \ + "umlalb z6.h, z31.b, z3.b \n" /* DG */ \ + \ + "add z17.h, z0.h, z26.h \n" /* G0 */ \ + "add z21.h, z1.h, z26.h \n" /* G1 */ \ + "add z16.h, z0.h, z4.h \n" /* B0 */ \ + "add z20.h, z1.h, z4.h \n" /* B1 */ \ + "add z18.h, z0.h, z5.h \n" /* R0 */ \ + "add z22.h, z1.h, z5.h \n" /* R1 */ \ + "uqsub z17.h, z17.h, z6.h \n" /* G0 */ \ + "uqsub z21.h, z21.h, z6.h \n" /* G1 */ \ + "uqsub z16.h, z16.h, z25.h \n" /* B0 */ \ + "uqsub z20.h, z20.h, z25.h \n" /* B1 */ \ + "uqsub z18.h, z18.h, z27.h \n" /* R0 */ \ + "uqsub z22.h, z22.h, z27.h \n" /* R1 */ + +// clang-format off +#define NVTORGB_SVE_2X(bt_u, bt_v) \ + "umulh z0.h, z24.h, z0.h \n" /* Y0 */ \ + "umulh z1.h, z24.h, z1.h \n" /* Y1 */ \ + "umull" #bt_u " z6.h, z30.b, z2.b \n" \ + "umull" #bt_u " z4.h, z28.b, z2.b \n" /* DB */ \ + "umull" #bt_v " z5.h, z29.b, z2.b \n" /* DR */ \ + "umlal" #bt_v " z6.h, z31.b, z2.b \n" /* DG */ \ + \ + "add z17.h, z0.h, z26.h \n" /* G0 */ \ + "add z21.h, z1.h, z26.h \n" /* G1 */ \ + "add z16.h, z0.h, z4.h \n" /* B0 */ \ + "add z20.h, z1.h, z4.h \n" /* B1 */ \ + "add z18.h, z0.h, z5.h \n" /* R0 */ \ + "add z22.h, z1.h, z5.h \n" /* R1 */ \ + "uqsub z17.h, z17.h, z6.h \n" /* G0 */ \ + "uqsub z21.h, z21.h, z6.h \n" /* G1 */ \ + "uqsub z16.h, z16.h, z25.h \n" /* B0 */ \ + "uqsub z20.h, z20.h, z25.h \n" /* B1 */ \ + "uqsub z18.h, z18.h, z27.h \n" /* R0 */ \ + "uqsub z22.h, z22.h, z27.h \n" /* R1 */ +// clang-format on + +#define RGBTOARGB8_SVE_TOP_2X \ + /* Inputs: B: z16.h, G: z17.h, R: z18.h */ \ + "uqshl z16.h, p0/m, z16.h, #2 \n" /* B0 */ \ + "uqshl z17.h, p0/m, z17.h, #2 \n" /* G0 */ \ + "uqshl z18.h, p0/m, z18.h, #2 \n" /* R0 */ \ + "uqshl z20.h, p0/m, z20.h, #2 \n" /* B1 */ \ + "uqshl z21.h, p0/m, z21.h, #2 \n" /* G1 */ \ + "uqshl z22.h, p0/m, z22.h, #2 \n" /* R1 */ + +// Convert from 2.14 fixed point RGB to 8 bit ARGB, interleaving as BG and RA +// pairs to allow us to use ST2 for storing rather than ST4. +#define RGBTOARGB8_SVE \ + /* Inputs: B: z16.h, G: z17.h, R: z18.h, A: z19.b */ \ + "uqshrnb z16.b, z16.h, #6 \n" /* B0 */ \ + "uqshrnb z18.b, z18.h, #6 \n" /* R0 */ \ + "uqshrnt z16.b, z17.h, #6 \n" /* BG */ \ + "trn1 z17.b, z18.b, z19.b \n" /* RA */ + +// Convert from 2.14 fixed point RGBA to 8 bit ARGB, interleaving as BG and RA +// pairs to allow us to use ST2 for storing rather than ST4. +#define RGBATOARGB8_SVE \ + /* Inputs: B: z16.h, G: z17.h, R: z18.h, A: z19.h */ \ + "uqshrnb z16.b, z16.h, #6 \n" /* B0 */ \ + "uqshrnt z16.b, z17.h, #6 \n" /* BG */ \ + "uqshrnb z17.b, z18.h, #6 \n" /* R0 */ \ + "uqshrnt z17.b, z19.h, #2 \n" /* RA */ + +// Convert from 2.14 fixed point RGB to 8 bit RGBA, interleaving as AB and GR +// pairs to allow us to use ST2 for storing rather than ST4. +#define RGBTORGBA8_SVE \ + /* Inputs: B: z16.h, G: z17.h, R: z18.h, A: z19.b */ \ + "uqshrnt z19.b, z16.h, #6 \n" /* AB */ \ + "uqshrnb z20.b, z17.h, #6 \n" /* G0 */ \ + "uqshrnt z20.b, z18.h, #6 \n" /* GR */ + +#define RGBTOARGB8_SVE_2X \ + /* Inputs: B: z16.h, G: z17.h, R: z18.h, A: z19.b */ \ + "uqshrnb z16.b, z16.h, #6 \n" /* B0 */ \ + "uqshrnb z17.b, z17.h, #6 \n" /* G0 */ \ + "uqshrnb z18.b, z18.h, #6 \n" /* R0 */ \ + "uqshrnt z16.b, z20.h, #6 \n" /* B1 */ \ + "uqshrnt z17.b, z21.h, #6 \n" /* G1 */ \ + "uqshrnt z18.b, z22.h, #6 \n" /* R1 */ + +// Store AR30 elements. Inputs are 2.14 fixed point RGB. We expect z23 to be +// populated with 0x3ff0 (0x3fff would also work) to saturate the R input +// rather than needing a pair of shifts to saturate and then insert into the +// correct position in the lane. +#define STOREAR30_SVE \ + /* Inputs: B: z16.h, G: z17.h, R: z18.h */ \ + "uqshl z16.h, p0/m, z16.h, #2 \n" /* bbbbbbbbbbxxxxxx */ \ + "uqshl z17.h, p0/m, z17.h, #2 \n" /* ggggggggggxxxxxx */ \ + "umin z18.h, p0/m, z18.h, z23.h \n" /* 00rrrrrrrrrrxxxx */ \ + "orr z18.h, z18.h, #0xc000 \n" /* 11rrrrrrrrrrxxxx */ \ + "sri z18.h, z17.h, #12 \n" /* 11rrrrrrrrrrgggg */ \ + "lsl z17.h, z17.h, #4 \n" /* ggggggxxxxxx0000 */ \ + "sri z17.h, z16.h, #6 \n" /* ggggggbbbbbbbbbb */ \ + "st2h {z17.h, z18.h}, p1, [%[dst_ar30]] \n" \ + "incb %[dst_ar30], all, mul #2 \n" + +#define STOREAR30_SVE_2X \ + /* Inputs: B: z16.h, G: z17.h, R: z18.h */ \ + /* B: z20.h, G: z21.h, R: z22.h */ \ + "uqshl z16.h, p0/m, z16.h, #2 \n" /* bbbbbbbbbbxxxxxx */ \ + "uqshl z20.h, p0/m, z20.h, #2 \n" /* bbbbbbbbbbxxxxxx */ \ + "uqshl z17.h, p0/m, z17.h, #2 \n" /* ggggggggggxxxxxx */ \ + "uqshl z21.h, p0/m, z21.h, #2 \n" /* ggggggggggxxxxxx */ \ + "umin z18.h, p0/m, z18.h, z23.h \n" /* 00rrrrrrrrrrxxxx */ \ + "umin z22.h, p0/m, z22.h, z23.h \n" /* 00rrrrrrrrrrxxxx */ \ + "orr z18.h, z18.h, #0xc000 \n" /* 11rrrrrrrrrrxxxx */ \ + "orr z22.h, z22.h, #0xc000 \n" /* 11rrrrrrrrrrxxxx */ \ + "sri z18.h, z17.h, #12 \n" /* 11rrrrrrrrrrgggg */ \ + "sri z22.h, z21.h, #12 \n" /* 11rrrrrrrrrrgggg */ \ + "lsl z17.h, z17.h, #4 \n" /* ggggggxxxxxx0000 */ \ + "lsl z19.h, z21.h, #4 \n" /* ggggggxxxxxx0000 */ \ + "sri z17.h, z16.h, #6 \n" /* ggggggbbbbbbbbbb */ \ + "sri z19.h, z20.h, #6 \n" /* ggggggbbbbbbbbbb */ \ + "zip2 z16.h, z17.h, z19.h \n" \ + "zip1 z21.h, z17.h, z19.h \n" \ + "zip2 z17.h, z18.h, z22.h \n" \ + "zip1 z22.h, z18.h, z22.h \n" \ + "st2h {z21.h, z22.h}, p2, [%[dst_ar30]] \n" \ + "st2h {z16.h, z17.h}, p3, [%[dst_ar30], #2, mul vl] \n" \ + "incb %[dst_ar30], all, mul #4 \n" + +#define YUVTORGB_SVE_REGS \ + "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z16", "z17", "z18", "z19", \ + "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", \ + "z30", "z31", "p0", "p1", "p2", "p3" + +static inline void I444ToRGB24Row_SVE_SC( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm volatile( + "cntb %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "1: \n" // + READYUV444_SVE_2X I444TORGB_SVE_2X RGBTOARGB8_SVE_2X + "subs %w[width], %w[width], %w[vl] \n" + "st3b {z16.b, z17.b, z18.b}, p1, [%[dst_rgb24]] \n" + "incb %[dst_rgb24], all, mul #3 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "cnth %[vl] \n" + "whilelt p1.b, wzr, %w[width] \n" // + READYUV444_SVE_2X I444TORGB_SVE_2X RGBTOARGB8_SVE_2X + "st3b {z16.b, z17.b, z18.b}, p1, [%[dst_rgb24]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_argb] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I400ToARGBRow_SVE_SC(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm volatile( + "cnth %[vl] \n" + "ptrue p0.b \n" + "dup z19.b, #255 \n" // Alpha + YUVTORGB_SVE_SETUP + "subs %w[width], %w[width], %w[vl] \n" + "mov z1.h, #128 \n" // U/V + "umullb z6.h, z30.b, z1.b \n" + "umullb z4.h, z28.b, z1.b \n" // DB + "umullb z5.h, z29.b, z1.b \n" // DR + "mla z6.h, p0/m, z31.h, z1.h \n" // DG + "sub z4.h, z4.h, z25.h \n" + "sub z5.h, z5.h, z27.h \n" + "sub z6.h, z26.h, z6.h \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READYUV400_SVE I400TORGB_SVE RGBTOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" // + READYUV400_SVE I400TORGB_SVE RGBTOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I422ToARGBRow_SVE_SC(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm volatile( + "cntb %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "1: \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X RGBTOARGB8_SVE_2X + "subs %w[width], %w[width], %w[vl] \n" + "st4b {z16.b, z17.b, z18.b, z19.b}, p1, [%[dst_argb]] \n" + "incb %[dst_argb], all, mul #4 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "cnth %[vl] \n" + "whilelt p1.b, wzr, %w[width] \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X RGBTOARGB8_SVE_2X + "st4b {z16.b, z17.b, z18.b, z19.b}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I422ToRGB24Row_SVE_SC( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm volatile( + "cntb %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "1: \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X RGBTOARGB8_SVE_2X + "subs %w[width], %w[width], %w[vl] \n" + "st3b {z16.b, z17.b, z18.b}, p1, [%[dst_argb]] \n" + "incb %[dst_argb], all, mul #3 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "cnth %[vl] \n" + "whilelt p1.b, wzr, %w[width] \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X RGBTOARGB8_SVE_2X + "st3b {z16.b, z17.b, z18.b}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +#define RGB8TORGB565_SVE_FROM_TOP_2X \ + "sri z18.h, z17.h, #5 \n" /* rrrrrgggggg00000 */ \ + "sri z22.h, z21.h, #5 \n" /* rrrrrgggggg00000 */ \ + "sri z18.h, z16.h, #11 \n" /* rrrrrggggggbbbbb */ \ + "sri z22.h, z20.h, #11 \n" /* rrrrrggggggbbbbb */ \ + "mov z19.d, z22.d \n" + +static inline void I422ToRGB565Row_SVE_SC( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm volatile( + "cntb %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "1: \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X RGBTOARGB8_SVE_TOP_2X + "subs %w[width], %w[width], %w[vl] \n" // + RGB8TORGB565_SVE_FROM_TOP_2X + "st2h {z18.h, z19.h}, p1, [%[dst]] \n" + "incb %[dst], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "cnth %[vl] \n" + "whilelt p1.b, wzr, %w[width] \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X + RGBTOARGB8_SVE_TOP_2X RGB8TORGB565_SVE_FROM_TOP_2X + // Need to permute the data on the final iteration such that the + // predicates (.b) line up with the 16-bit element data. + "trn1 z20.b, z18.b, z19.b \n" + "trn2 z21.b, z18.b, z19.b \n" + "st2b {z20.b, z21.b}, p1, [%[dst]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst] "+r"(dst_rgb565), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +#define RGB8TOARGB1555_SVE_FROM_TOP_2X \ + "dup z0.h, #0x8000 \n" /* 1000000000000000 */ \ + "dup z1.h, #0x8000 \n" /* 1000000000000000 */ \ + "sri z0.h, z18.h, #1 \n" /* 1rrrrrxxxxxxxxxx */ \ + "sri z1.h, z22.h, #1 \n" /* 1rrrrrxxxxxxxxxx */ \ + "sri z0.h, z17.h, #6 \n" /* 1rrrrrgggggxxxxx */ \ + "sri z1.h, z21.h, #6 \n" /* 1rrrrrgggggxxxxx */ \ + "sri z0.h, z16.h, #11 \n" /* 1rrrrrgggggbbbbb */ \ + "sri z1.h, z20.h, #11 \n" /* 1rrrrrgggggbbbbb */ + +static inline void I422ToARGB1555Row_SVE_SC( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm volatile( + "cntb %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "1: \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X RGBTOARGB8_SVE_TOP_2X + "subs %w[width], %w[width], %w[vl] \n" // + RGB8TOARGB1555_SVE_FROM_TOP_2X + "st2h {z0.h, z1.h}, p1, [%[dst]] \n" + "incb %[dst], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "cnth %[vl] \n" + "whilelt p1.b, wzr, %w[width] \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X + RGBTOARGB8_SVE_TOP_2X RGB8TOARGB1555_SVE_FROM_TOP_2X + // Need to permute the data on the final iteration such that the + // predicates (.b) line up with the 16-bit element data. + "trn1 z2.b, z0.b, z1.b \n" + "trn2 z3.b, z0.b, z1.b \n" + "st2b {z2.b, z3.b}, p1, [%[dst]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst] "+r"(dst_argb1555), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +#define RGB8TOARGB4444_SVE_FROM_TOP_2X \ + "dup z0.h, #0xf000 \n" /* 1111000000000000 */ \ + "dup z1.h, #0xf000 \n" /* 1111000000000000 */ \ + "sri z0.h, z18.h, #4 \n" /* 1111rrrrxxxxxxxx */ \ + "sri z1.h, z22.h, #4 \n" /* 1111rrrrxxxxxxxx */ \ + "sri z0.h, z17.h, #8 \n" /* 1111rrrrggggxxxx */ \ + "sri z1.h, z21.h, #8 \n" /* 1111rrrrggggxxxx */ \ + "sri z0.h, z16.h, #12 \n" /* 1111rrrrggggbbbb */ \ + "sri z1.h, z20.h, #12 \n" /* 1111rrrrggggbbbb */ + +static inline void I422ToARGB4444Row_SVE_SC( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm volatile( + "cntb %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "1: \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X RGBTOARGB8_SVE_TOP_2X + "subs %w[width], %w[width], %w[vl] \n" // + RGB8TOARGB4444_SVE_FROM_TOP_2X + "st2h {z0.h, z1.h}, p1, [%[dst]] \n" + "incb %[dst], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "cnth %[vl] \n" + "whilelt p1.b, wzr, %w[width] \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X + RGBTOARGB8_SVE_TOP_2X RGB8TOARGB4444_SVE_FROM_TOP_2X + // Need to permute the data on the final iteration such that the + // predicates (.b) line up with the 16-bit element data. + "trn1 z2.b, z0.b, z1.b \n" + "trn2 z3.b, z0.b, z1.b \n" + "st2b {z2.b, z3.b}, p1, [%[dst]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst] "+r"(dst_argb4444), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I422ToRGBARow_SVE_SC(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm volatile( + "cnth %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READYUV422_SVE I4XXTORGB_SVE RGBTORGBA8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z19.h, z20.h}, p1, [%[dst_rgba]] \n" + "add %[dst_rgba], %[dst_rgba], %[vl], lsl #2 \n" + "b.ge 1b \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p1.h, wzr, %w[width] \n" // + READYUV422_SVE I4XXTORGB_SVE RGBTORGBA8_SVE + "st2h {z19.h, z20.h}, p1, [%[dst_rgba]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgba] "+r"(dst_rgba), // %[dst_rgba] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I422ToAR30Row_SVE_SC(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + // The limit is used for saturating the 2.14 red channel in STOREAR30_SVE_2X. + const uint16_t limit = 0x3ff0; + asm volatile( + "cnth %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP_AR30 + "dup z23.h, %w[limit] \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "ptrue p2.b \n" + "ptrue p3.b \n" + "1: \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X STOREAR30_SVE_2X + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.ge 1b \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #1 \n" + "b.eq 99f \n" + + "whilelt p1.b, wzr, %w[width] \n" + "whilelt p2.h, wzr, %w[width] \n" + "whilelt p3.h, %w[vl], %w[width] \n" // + READYUV422_SVE_2X I422TORGB_SVE_2X STOREAR30_SVE_2X + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [limit] "r"(limit) // %[limit] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I422AlphaToARGBRow_SVE_SC( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm volatile( + "cntb %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "1: \n" // + READYUV422_SVE_2X + "ld1b {z19.b}, p1/z, [%[src_a]] \n" + "add %[src_a], %[src_a], %[vl] \n" // Alpha + I422TORGB_SVE_2X RGBTOARGB8_SVE_2X + "subs %w[width], %w[width], %w[vl] \n" + "st4b {z16.b, z17.b, z18.b, z19.b}, p1, [%[dst_argb]] \n" + "incb %[dst_argb], all, mul #4 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "cnth %[vl] \n" + "whilelt p1.b, wzr, %w[width] \n" // + READYUV422_SVE_2X + "ld1b {z19.b}, p1/z, [%[src_a]] \n" // Alpha + I422TORGB_SVE_2X RGBTOARGB8_SVE_2X + "st4b {z16.b, z17.b, z18.b, z19.b}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I444AlphaToARGBRow_SVE_SC( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm volatile( + "cnth %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READYUV444_SVE + "ld1b {z19.h}, p1/z, [%[src_a]] \n" + "add %[src_a], %[src_a], %[vl] \n" // Alpha + I4XXTORGB_SVE RGBTOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" // + READYUV444_SVE + "ld1b {z19.h}, p1/z, [%[src_a]] \n" // Alpha + I4XXTORGB_SVE RGBTOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void NV12ToARGBRow_SVE_SC(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cntb %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "ptrue p2.b \n" + "1: \n" // + READNV_SVE_2X NVTORGB_SVE_2X(b, t) RGBTOARGB8_SVE_2X + "subs %w[width], %w[width], %w[vl] \n" + "st4b {z16.b, z17.b, z18.b, z19.b}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.b, wzr, %w[width] \n" + "add %w[width], %w[width], #1 \n" // Round up to even + "and %w[width], %w[width], #0xfffffffe \n" + "whilelt p2.b, wzr, %w[width] \n" // + READNV_SVE_2X NVTORGB_SVE_2X(b, t) RGBTOARGB8_SVE_2X + "st4b {z16.b, z17.b, z18.b, z19.b}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS, "p2"); +} + +static inline void NV21ToARGBRow_SVE_SC(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cntb %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "ptrue p2.b \n" + "1: \n" // + READNV_SVE_2X NVTORGB_SVE_2X(t, b) RGBTOARGB8_SVE_2X + "subs %w[width], %w[width], %w[vl] \n" + "st4b {z16.b, z17.b, z18.b, z19.b}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.b, wzr, %w[width] \n" + "add %w[width], %w[width], #1 \n" // Round up to even + "and %w[width], %w[width], #0xfffffffe \n" + "whilelt p2.b, wzr, %w[width] \n" // + READNV_SVE_2X NVTORGB_SVE_2X(t, b) RGBTOARGB8_SVE_2X + "st4b {z16.b, z17.b, z18.b, z19.b}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_vu), // %[src_vu] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS, "p2"); +} + +static inline void NV12ToRGB24Row_SVE_SC( + const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cntb %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "ptrue p2.b \n" + "1: \n" // + READNV_SVE_2X NVTORGB_SVE_2X(b, t) RGBTOARGB8_SVE_2X + "subs %w[width], %w[width], %w[vl] \n" + "st3b {z16.b, z17.b, z18.b}, p1, [%[dst_rgb24]] \n" + "incb %[dst_rgb24], all, mul #3 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.b, wzr, %w[width] \n" + "add %w[width], %w[width], #1 \n" // Round up to even + "and %w[width], %w[width], #0xfffffffe \n" + "whilelt p2.b, wzr, %w[width] \n" // + READNV_SVE_2X NVTORGB_SVE_2X(b, t) RGBTOARGB8_SVE_2X + "st3b {z16.b, z17.b, z18.b}, p1, [%[dst_rgb24]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS, "p2"); +} + +static inline void NV21ToRGB24Row_SVE_SC( + const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cntb %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "ptrue p2.b \n" + "1: \n" // + READNV_SVE_2X NVTORGB_SVE_2X(t, b) RGBTOARGB8_SVE_2X + "subs %w[width], %w[width], %w[vl] \n" + "st3b {z16.b, z17.b, z18.b}, p1, [%[dst_rgb24]] \n" + "incb %[dst_rgb24], all, mul #3 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.b, wzr, %w[width] \n" + "add %w[width], %w[width], #1 \n" // Round up to even + "and %w[width], %w[width], #0xfffffffe \n" + "whilelt p2.b, wzr, %w[width] \n" // + READNV_SVE_2X NVTORGB_SVE_2X(t, b) RGBTOARGB8_SVE_2X + "st3b {z16.b, z17.b, z18.b}, p1, [%[dst_rgb24]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_vu), // %[src_vu] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS, "p2"); +} + +#define READYUY2_SVE \ + "ld1w {z0.s}, p2/z, [%[src_yuy2]] \n" /* YUYV */ \ + "incb %[src_yuy2] \n" \ + "prfm pldl1keep, [%[src_yuy2], 448] \n" \ + "tbl z1.b, {z0.b}, z22.b \n" /* UVUV */ \ + "trn1 z0.b, z0.b, z0.b \n" /* YYYY */ + +static inline void YUY2ToARGBRow_SVE_SC(const uint8_t* src_yuy2, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint32_t nv_uv_start = 0x03010301U; + uint32_t nv_uv_step = 0x04040404U; + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" + "index z22.s, %w[nv_uv_start], %w[nv_uv_step] \n" + "dup z19.b, #255 \n" // Alpha + YUVTORGB_SVE_SETUP + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "ptrue p2.h \n" + "1: \n" // + READYUY2_SVE NVTORGB_SVE RGBTOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" + "add %w[width], %w[width], #1 \n" // Round up to even + "and %w[width], %w[width], #0xfffffffe \n" + "whilelt p2.h, wzr, %w[width] \n" // + READYUY2_SVE NVTORGB_SVE RGBTOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_yuy2] "+r"(src_yuy2), // %[src_yuy2] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [nv_uv_start] "r"(nv_uv_start), // %[nv_uv_start] + [nv_uv_step] "r"(nv_uv_step) // %[nv_uv_step] + : "cc", "memory", YUVTORGB_SVE_REGS, "p2"); +} + +#define READUYVY_SVE \ + "ld1w {z0.s}, p2/z, [%[src_uyvy]] \n" /* UYVY */ \ + "incb %[src_uyvy] \n" \ + "prfm pldl1keep, [%[src_uyvy], 448] \n" \ + "tbl z1.b, {z0.b}, z22.b \n" /* UVUV */ \ + "trn2 z0.b, z0.b, z0.b \n" /* YYYY */ + +static inline void UYVYToARGBRow_SVE_SC(const uint8_t* src_uyvy, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint32_t nv_uv_start = 0x02000200U; + uint32_t nv_uv_step = 0x04040404U; + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" + "index z22.s, %w[nv_uv_start], %w[nv_uv_step] \n" + "dup z19.b, #255 \n" // Alpha + YUVTORGB_SVE_SETUP + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "ptrue p2.h \n" + "1: \n" // + READUYVY_SVE NVTORGB_SVE RGBTOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" + "add %w[width], %w[width], #1 \n" // Round up to even + "and %w[width], %w[width], #0xfffffffe \n" + "whilelt p2.h, wzr, %w[width] \n" // + READUYVY_SVE NVTORGB_SVE RGBTOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_uyvy] "+r"(src_uyvy), // %[src_yuy2] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [nv_uv_start] "r"(nv_uv_start), // %[nv_uv_start] + [nv_uv_step] "r"(nv_uv_step) // %[nv_uv_step] + : "cc", "memory", YUVTORGB_SVE_REGS, "p2"); +} + +static inline void I210ToARGBRow_SVE_SC(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READI210_SVE I4XXTORGB_SVE RGBTOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" // + READI210_SVE I4XXTORGB_SVE RGBTOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I210AlphaToARGBRow_SVE_SC( + const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READI210_SVE + "ld1h {z19.h}, p1/z, [%[src_a]] \n" // + I4XXTORGB_SVE + "incb %[src_a] \n" // + RGBATOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" // + READI210_SVE + "ld1h {z19.h}, p1/z, [%[src_a]] \n" // + I4XXTORGB_SVE RGBATOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I210ToAR30Row_SVE_SC(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + // The limit is used for saturating the 2.14 red channel in STOREAR30_SVE_2X. + uint16_t limit = 0x3ff0; + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z23.h, %w[limit] \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "ptrue p2.h \n" + "ptrue p3.h \n" + "1: \n" // + READI210_SVE_2X I422TORGB_SVE_2X STOREAR30_SVE_2X + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #1 \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p2.h, wzr, %w[width] \n" + "whilelt p3.h, %w[vl], %w[width] \n" + "add %w[width], %w[width], #1 \n" // (width + 1) / 2 + "lsr %w[width], %w[width], #1 \n" + "whilelt p1.h, wzr, %w[width] \n" // + READI210_SVE_2X I422TORGB_SVE_2X STOREAR30_SVE_2X + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [limit] "r"(limit) // %[limit] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +// P210 has 10 bits in msb of 16 bit NV12 style layout. +static inline void P210ToARGBRow_SVE_SC(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + uint32_t nv_uv_start = 0x03010301U; + uint32_t nv_uv_step = 0x04040404U; + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "index z22.s, %w[nv_uv_start], %w[nv_uv_step] \n" + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "ptrue p2.h \n" + "1: \n" // + READP210_SVE NVTORGB_SVE RGBTOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" + "add %w[width], %w[width], #1 \n" // Round up to even + "and %w[width], %w[width], #0xfffffffe \n" + "whilelt p2.h, wzr, %w[width] \n" // + READP210_SVE NVTORGB_SVE RGBTOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [nv_uv_start] "r"(nv_uv_start), // %[nv_uv_start] + [nv_uv_step] "r"(nv_uv_step) // %[nv_uv_step] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void P210ToAR30Row_SVE_SC(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + uint32_t nv_uv_start = 0x03010301U; + uint32_t nv_uv_step = 0x04040404U; + // The limit is used for saturating the 2.14 red channel in STOREAR30_SVE. + uint16_t limit = 0x3ff0; + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "index z22.s, %w[nv_uv_start], %w[nv_uv_step] \n" + "dup z23.h, %w[limit] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "ptrue p2.h \n" + "1: \n" // + READP210_SVE NVTORGB_SVE + "subs %w[width], %w[width], %w[vl] \n" // + STOREAR30_SVE + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" + "add %w[width], %w[width], #1 \n" // Round up to even + "and %w[width], %w[width], #0xfffffffe \n" + "whilelt p2.h, wzr, %w[width] \n" // + READP210_SVE NVTORGB_SVE STOREAR30_SVE + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [nv_uv_start] "r"(nv_uv_start), // %[nv_uv_start] + [nv_uv_step] "r"(nv_uv_step), // %[nv_uv_step] + [limit] "r"(limit) // %[limit] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I410ToARGBRow_SVE_SC(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READI410_SVE I4XXTORGB_SVE RGBTOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" // + READI410_SVE I4XXTORGB_SVE RGBTOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I410AlphaToARGBRow_SVE_SC( + const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "cmp %w[width], %w[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READI410_SVE + "ld1h {z19.h}, p1/z, [%[src_a]] \n" // + I4XXTORGB_SVE + "incb %[src_a] \n" // + RGBATOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" // + READI410_SVE + "ld1h {z19.h}, p1/z, [%[src_a]] \n" // + I4XXTORGB_SVE RGBATOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I410ToAR30Row_SVE_SC(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + // The limit is used for saturating the 2.14 red channel in STOREAR30_SVE. + uint16_t limit = 0x3ff0; + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z23.h, %w[limit] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READI410_SVE I4XXTORGB_SVE STOREAR30_SVE + "subs %w[width], %w[width], %w[vl] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" // + READI410_SVE I4XXTORGB_SVE STOREAR30_SVE + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_ar30] "+r"(dst_ar30), // %[dst_argb] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [limit] "r"(limit) // %[limit] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void P410ToARGBRow_SVE_SC(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "ptrue p2.s \n" + "ptrue p3.s \n" + "1: \n" // + READP410_SVE NVTORGB_SVE RGBTOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" + "whilelt p2.s, wzr, %w[width] \n" + "cntw %x[vl] \n" + "whilelt p3.s, %w[vl], %w[width] \n" // + READP410_SVE NVTORGB_SVE RGBTOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width), // %[width] + [vl] "+r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void P410ToAR30Row_SVE_SC(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + // The limit is used for saturating the 2.14 red channel in STOREAR30_SVE. + uint16_t limit = 0x3ff0; + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z23.h, %w[limit] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "ptrue p2.s \n" + "ptrue p3.s \n" + "1: \n" // + READP410_SVE NVTORGB_SVE + "subs %w[width], %w[width], %w[vl] \n" // + STOREAR30_SVE + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" + "whilelt p2.s, wzr, %w[width] \n" + "cntw %x[vl] \n" + "whilelt p3.s, %w[vl], %w[width] \n" // + READP410_SVE NVTORGB_SVE STOREAR30_SVE + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width), // %[width] + [vl] "+r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [limit] "r"(limit) // %[limit] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I212ToAR30Row_SVE_SC(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + // The limit is used for saturating the 2.14 red channel in STOREAR30_SVE. + uint16_t limit = 0x3ff0; + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z23.h, %w[limit] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READI212_SVE I4XXTORGB_SVE STOREAR30_SVE + "subs %w[width], %w[width], %w[vl] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" // + READI212_SVE I4XXTORGB_SVE STOREAR30_SVE + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [limit] "r"(limit) // %[limit] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +static inline void I212ToARGBRow_SVE_SC(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm("cnth %0" : "=r"(vl)); + asm volatile( + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READI212_SVE I4XXTORGB_SVE RGBTOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" // + READI212_SVE I4XXTORGB_SVE RGBTOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +#define CONVERT8TO8_SVE \ + "ld1b {z0.b}, p0/z, [%[src]] \n" \ + "ld1b {z1.b}, p1/z, [%[src], #1, mul vl] \n" \ + "incb %[src], all, mul #2 \n" \ + "subs %w[width], %w[width], %w[vl], lsl #1 \n" \ + "umulh z0.b, z0.b, z2.b \n" \ + "umulh z1.b, z1.b, z2.b \n" \ + "prfm pldl1keep, [%[src], 448] \n" \ + "add z0.b, z0.b, z3.b \n" \ + "add z1.b, z1.b, z3.b \n" \ + "st1b {z0.b}, p0, [%[dst]] \n" \ + "st1b {z1.b}, p1, [%[dst], #1, mul vl] \n" \ + "incb %[dst], all, mul #2 \n" + +static inline void Convert8To8Row_SVE_SC(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + asm volatile( + "dup z2.b, %w[scale] \n" + "dup z3.b, %w[bias] \n" + "cntb %[vl] \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.lt 2f \n" + + // Run bulk of computation with all-true predicates to avoid predicate + // generation overhead. + "ptrue p0.b \n" + "ptrue p1.b \n" + "1: \n" // + CONVERT8TO8_SVE + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #1 \n" + "b.eq 99f \n" + + // Calculate predicates for the final iteration to deal with the tail. + "whilelt p0.b, wzr, %w[width] \n" + "whilelt p1.b, %w[vl], %w[width] \n" // + CONVERT8TO8_SVE + + "99: \n" + : [src] "+r"(src_y), // %[src] + [dst] "+r"(dst_y), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [scale] "r"(scale), // %[scale] + [bias] "r"(bias) // %[bias] + : "cc", "memory", "z0", "z1", "z2", "z3", "p0", "p1"); +} + +// SVE constants are stored negated such that we can store 128 in int8_t. + +// RGB to BT601 coefficients +// UB 0.875 coefficient = 112 +// UG -0.5781 coefficient = -74 +// UR -0.2969 coefficient = -38 +// VB -0.1406 coefficient = -18 +// VG -0.7344 coefficient = -94 +// VR 0.875 coefficient = 112 + +static const int8_t kARGBToUVCoefficients[] = { + // -UB, -UG, -UR, 0, -VB, -VG, -VR, 0 + -112, 74, 38, 0, 18, 94, -112, 0, +}; + +static const int8_t kABGRToUVCoefficients[] = { + // -UR, -UG, -UB, 0, -VR, -VG, -VB, 0 + 38, 74, -112, 0, -112, 94, 18, 0, +}; + +static const int8_t kBGRAToUVCoefficients[] = { + // 0, -UR, -UG, -UB, 0, -VR, -VG, -VB + 0, 38, 74, -112, 0, -112, 94, 18, +}; + +static const int8_t kRGBAToUVCoefficients[] = { + // 0, -UB, -UG, -UR, 0, -VB, -VG, -VR + 0, -112, 74, 38, 0, 18, 94, -112, +}; + +// RGB to JPEG coefficients +// UB 0.500 coefficient = 128 +// UG -0.33126 coefficient = -85 +// UR -0.16874 coefficient = -43 +// VB -0.08131 coefficient = -21 +// VG -0.41869 coefficient = -107 +// VR 0.500 coefficient = 128 + +static const int8_t kARGBToUVJCoefficients[] = { + // -UB, -UG, -UR, 0, -VB, -VG, -VR, 0 + -128, 85, 43, 0, 21, 107, -128, 0, +}; + +static const int8_t kABGRToUVJCoefficients[] = { + // -UR, -UG, -UB, 0, -VR, -VG, -VB, 0 + 43, 85, -128, 0, -128, 107, 21, 0, +}; + +#define ARGBTOUVMATRIX_SVE \ + "ld1d {z0.d}, p1/z, [%[src0]] \n" /* ABCD(bgra) */ \ + "ld1d {z1.d}, p2/z, [%[src0], #1, mul vl] \n" /* EFGH(bgra) */ \ + "ld1d {z2.d}, p3/z, [%[src0], #2, mul vl] \n" /* IJKL(bgra) */ \ + "ld1d {z3.d}, p4/z, [%[src0], #3, mul vl] \n" /* MNOP(bgra) */ \ + "ld1d {z4.d}, p1/z, [%[src1]] \n" /* ABCD(bgra) */ \ + "ld1d {z5.d}, p2/z, [%[src1], #1, mul vl] \n" /* EFGH(bgra) */ \ + "ld1d {z6.d}, p3/z, [%[src1], #2, mul vl] \n" /* IJKL(bgra) */ \ + "ld1d {z7.d}, p4/z, [%[src1], #3, mul vl] \n" /* MNOP(bgra) */ \ + "incb %[src0], all, mul #4 \n" \ + "incb %[src1], all, mul #4 \n" \ + \ + "uaddlb z16.h, z0.b, z4.b \n" /* ABCD(br) */ \ + "uaddlb z18.h, z1.b, z5.b \n" /* EFGH(br) */ \ + "uaddlb z20.h, z2.b, z6.b \n" /* IJKL(br) */ \ + "uaddlb z22.h, z3.b, z7.b \n" /* MNOP(br) */ \ + "uaddlt z17.h, z0.b, z4.b \n" /* ABCD(ga) */ \ + "uaddlt z19.h, z1.b, z5.b \n" /* EFGH(ga) */ \ + "uaddlt z21.h, z2.b, z6.b \n" /* IJKL(ga) */ \ + "uaddlt z23.h, z3.b, z7.b \n" /* MNOP(ga) */ \ + \ + /* Use ADDP on 32-bit elements to add adjacent pairs of 9-bit unsigned */ \ + "addp z16.s, p0/m, z16.s, z18.s \n" /* ABEFCDGH(br) */ \ + "addp z17.s, p0/m, z17.s, z19.s \n" /* ABEFCDGH(ga) */ \ + "addp z20.s, p0/m, z20.s, z22.s \n" /* IJMNKLOP(br) */ \ + "addp z21.s, p0/m, z21.s, z23.s \n" /* IJMNKLOP(ga) */ \ + \ + "rshrnb z0.b, z16.h, #2 \n" /* ABEFCDGH(b0r0) */ \ + "rshrnb z1.b, z20.h, #2 \n" /* IJMNKLOP(b0r0) */ \ + "rshrnt z0.b, z17.h, #2 \n" /* ABEFCDGH(bgra) */ \ + "rshrnt z1.b, z21.h, #2 \n" /* IJMNKLOP(bgra) */ \ + \ + "tbl z0.s, {z0.s}, z27.s \n" /* ABCDEFGH */ \ + "tbl z1.s, {z1.s}, z27.s \n" /* IJKLMNOP */ \ + \ + "subs %w[width], %w[width], %w[vl], lsl #2 \n" /* VL per loop */ \ + \ + "mov z16.b, #0 \n" \ + "mov z17.b, #0 \n" \ + "mov z20.b, #0 \n" \ + "mov z21.b, #0 \n" \ + \ + "usdot z16.s, z0.b, z24.b \n" \ + "usdot z17.s, z1.b, z24.b \n" \ + "usdot z20.s, z0.b, z25.b \n" \ + "usdot z21.s, z1.b, z25.b \n" \ + \ + "subhnb z16.b, z26.h, z16.h \n" /* U */ \ + "subhnb z20.b, z26.h, z20.h \n" /* V */ \ + "subhnb z17.b, z26.h, z17.h \n" /* U */ \ + "subhnb z21.b, z26.h, z21.h \n" /* V */ \ + \ + "uzp1 z16.h, z16.h, z17.h \n" \ + "uzp1 z20.h, z20.h, z21.h \n" \ + \ + "st1b {z16.h}, p5, [%[dst_u]] \n" /* U */ \ + "st1b {z20.h}, p5, [%[dst_v]] \n" /* V */ \ + "inch %[dst_u] \n" \ + "inch %[dst_v] \n" + +static inline void ARGBToUVMatrixRow_SVE_SC(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const int8_t* uvconstants) + STREAMING_COMPATIBLE { + const uint8_t* src_argb_1 = src_argb + src_stride_argb; + uint64_t vl; + asm("cntd %x0" : "=r"(vl)); + + // Width is a multiple of two here, so halve it. + width >>= 1; + + asm volatile( + "ptrue p0.b \n" + "ld1rw {z24.s}, p0/z, [%[uvconstants]] \n" + "ld1rw {z25.s}, p0/z, [%[uvconstants], #4] \n" + "mov z26.h, #0x8000 \n" // 128.0 (0x8000) + + // Generate some TBL indices to undo the interleaving from ADDP. + "index z0.s, #0, #1 \n" + "index z1.s, #1, #1 \n" + "uzp1 z27.s, z0.s, z1.s \n" + + "subs %w[width], %w[width], %w[vl], lsl #2 \n" + "b.lt 2f \n" + + "ptrue p1.d \n" + "ptrue p2.d \n" + "ptrue p3.d \n" + "ptrue p4.d \n" + "ptrue p5.h \n" + "1: \n" // + ARGBTOUVMATRIX_SVE + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #2 \n" + "b.eq 99f \n" + + "3: \n" + "whilelt p1.d, wzr, %w[width] \n" + "whilelt p2.d, %w[vl], %w[width] \n" + "whilelt p3.d, %w[vl2], %w[width] \n" + "whilelt p4.d, %w[vl3], %w[width] \n" + "whilelt p5.h, wzr, %w[width] \n" // + ARGBTOUVMATRIX_SVE + "b.gt 3b \n" + + "99: \n" + : [src0] "+r"(src_argb), // %[src0] + [src1] "+r"(src_argb_1), // %[src1] + [dst_u] "+r"(dst_u), // %[dst_u] + [dst_v] "+r"(dst_v), // %[dst_v] + [width] "+r"(width) // %[width] + : [uvconstants] "r"(uvconstants), // %[uvconstants] + [vl] "r"(vl), // %[vl] + [vl2] "r"(vl * 2), // %[vl2] + [vl3] "r"(vl * 3) // %[vl3] + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z16", + "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", + "z27", "p0", "p1", "p2", "p3", "p4", "p5"); +} + +#define ARGBTOYMATRIX_SVE(p1, p2, p3, p4, p5) \ + "ld1w {z0.s}, " p1 \ + "/z, [%[src]] \n" /* load 4*vl pixels */ \ + "ld1w {z1.s}, " p2 \ + "/z, [%[src], #1, mul vl] \n" \ + "ld1w {z2.s}, " p3 \ + "/z, [%[src], #2, mul vl] \n" \ + "ld1w {z3.s}, " p4 \ + "/z, [%[src], #3, mul vl] \n" \ + "incb %[src], all, mul #4 \n" \ + "mov z16.b, #0 \n" \ + "mov z17.b, #0 \n" \ + "mov z18.b, #0 \n" \ + "mov z19.b, #0 \n" \ + "udot z16.s, z0.b, z24.b \n" \ + "udot z17.s, z1.b, z24.b \n" \ + "udot z18.s, z2.b, z24.b \n" \ + "udot z19.s, z3.b, z24.b \n" \ + "uzp1 z16.h, z16.h, z17.h \n" \ + "uzp1 z18.h, z18.h, z19.h \n" \ + "addhnb z16.b, z16.h, z25.h \n" \ + "addhnb z18.b, z18.h, z25.h \n" \ + "uzp1 z20.b, z16.b, z18.b \n" \ + "st1b {z20.b}, " p5 \ + ", [%[dst_y]] \n" \ + "incb %[dst_y] \n" \ + "subs %w[width], %w[width], %w[vl], lsl #2 \n" + +static inline void ARGBToYMatrixRow_SVE_SC(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) + STREAMING_COMPATIBLE { + uint64_t vl; + asm("cntw %x0" : "=r"(vl)); + + asm volatile( + "ptrue p0.b \n" + "ld1rw {z24.s}, p0/z, [%[c]] \n" + "ld1rh {z25.h}, p0/z, [%[c], #48] \n" + + "subs %w[width], %w[width], %w[vl], lsl #2 \n" + "b.lt 2f \n" + + "ptrue p1.s \n" + "1: \n" // + ARGBTOYMATRIX_SVE("p1", "p1", "p1", "p1", "p0") + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #2 \n" + "b.eq 99f \n" + + "3: \n" + "whilelt p1.s, wzr, %w[width] \n" + "whilelt p2.s, %w[vl], %w[width] \n" + "whilelt p3.s, %w[vl2], %w[width] \n" + "whilelt p4.s, %w[vl3], %w[width] \n" + "whilelt p5.b, wzr, %w[width] \n" // + ARGBTOYMATRIX_SVE("p1", "p2", "p3", "p4", "p5") + "b.gt 3b \n" + + "99: \n" + : [src] "+r"(src_argb), // %[src] + [dst_y] "+r"(dst_y), // %[dst_y] + [width] "+r"(width) // %[width] + : [c] "r"(c), // %[c] + [vl] "r"(vl), // %[vl] + [vl2] "r"(vl * 2), // %[vl2] + [vl3] "r"(vl * 3) // %[vl3] + : "cc", "memory", "z0", "z1", "z2", "z3", "z16", "z17", "z18", "z19", + "z20", "z24", "z25", "p0", "p1", "p2", "p3", "p4", "p5"); +} + +#define SSIM4X4_SVE \ + "add %[tmp_a], %[src_a], %[stride_a] \n" \ + "add %[tmp_b], %[src_b], %[stride_b] \n" \ + "ld1w {z0.s}, p0/z, [%[src_a]] \n" \ + "ld1w {z1.s}, p0/z, [%[tmp_a]] \n" \ + "add %[tmp_a], %[tmp_a], %[stride_a] \n" \ + "ld1w {z4.s}, p0/z, [%[src_b]] \n" \ + "ld1w {z5.s}, p0/z, [%[tmp_b]] \n" \ + "add %[tmp_b], %[tmp_b], %[stride_b] \n" \ + "ld1w {z2.s}, p0/z, [%[tmp_a]] \n" \ + "add %[tmp_a], %[tmp_a], %[stride_a] \n" \ + "ld1w {z3.s}, p0/z, [%[tmp_a]] \n" \ + "ld1w {z6.s}, p0/z, [%[tmp_b]] \n" \ + "add %[tmp_b], %[tmp_b], %[stride_b] \n" \ + "ld1w {z7.s}, p0/z, [%[tmp_b]] \n" \ + "incb %[src_a] \n" \ + "incb %[src_b] \n" \ + "mov z16.s, #0 \n" \ + "mov z17.s, #0 \n" \ + "mov z18.s, #0 \n" \ + "mov z19.s, #0 \n" \ + "udot z16.s, z0.b, z20.b \n" \ + "udot z17.s, z4.b, z20.b \n" \ + "udot z18.s, z0.b, z0.b \n" \ + "udot z19.s, z0.b, z4.b \n" \ + "udot z16.s, z1.b, z20.b \n" \ + "udot z17.s, z5.b, z20.b \n" \ + "udot z18.s, z1.b, z1.b \n" \ + "udot z19.s, z1.b, z5.b \n" \ + "udot z16.s, z2.b, z20.b \n" \ + "udot z17.s, z6.b, z20.b \n" \ + "udot z18.s, z2.b, z2.b \n" \ + "udot z19.s, z2.b, z6.b \n" \ + "udot z16.s, z3.b, z20.b \n" \ + "udot z17.s, z7.b, z20.b \n" \ + "udot z18.s, z3.b, z3.b \n" \ + "udot z19.s, z3.b, z7.b \n" \ + "udot z18.s, z4.b, z4.b \n" \ + "udot z18.s, z5.b, z5.b \n" \ + "udot z18.s, z6.b, z6.b \n" \ + "udot z18.s, z7.b, z7.b \n" \ + "subs %w[width], %w[width], %w[vl] \n" \ + "st4w {z16.s, z17.s, z18.s, z19.s}, p0, [%[dst]]\n" \ + "incb %[dst], all, mul #4 \n" + +static inline void Ssim4x4Row_SVE_SC(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) STREAMING_COMPATIBLE { + uint64_t vl; + const uint8_t* tmp_a; + const uint8_t* tmp_b; + width >>= 2; + asm volatile( + "cntw %x[vl] \n" + "mov z20.b, #1 \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.s \n" + "1: \n" // + SSIM4X4_SVE + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.s, wzr, %w[width] \n" // + SSIM4X4_SVE + + "99: \n" + : [src_a] "+r"(src_a), // %[src_a] + [src_b] "+r"(src_b), // %[src_b] + [dst] "+r"(dst), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl), // %[vl] + [tmp_a] "=&r"(tmp_a), // %[tmp_a] + [tmp_b] "=&r"(tmp_b) // %[tmp_b] + : [stride_a] "r"((ptrdiff_t)stride_a), // %[stride_a] + [stride_b] "r"((ptrdiff_t)stride_b) // %[stride_b] + : "memory", "cc", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z16", + "z17", "z18", "z19", "z20", "p0"); +} + +static inline float SsimWindowRow_SVE_SC(const uint32_t* row0, + const uint32_t* row1, + int num_windows) STREAMING_COMPATIBLE { + uint64_t vl; + const uint32_t* row0_next = row0 + 4; + const uint32_t* row1_next = row1 + 4; + float total; + asm volatile( + "cntw %x[vl] \n" + "ptrue p1.s \n" + "mov z24.s, #0 \n" + "dup z25.s, %w[c1] \n" + "dup z26.s, %w[c2] \n" + + "1: \n" + "whilelt p0.s, wzr, %w[num_windows] \n" + "ld4w {z0.s, z1.s, z2.s, z3.s}, p0/z, [%[row0]] \n" + "ld4w {z4.s, z5.s, z6.s, z7.s}, p0/z, [%[row0_next]] \n" + "ld4w {z16.s, z17.s, z18.s, z19.s}, p0/z, [%[row1]] \n" + "ld4w {z20.s, z21.s, z22.s, z23.s}, p0/z, [%[row1_next]] \n" + "incb %[row0], all, mul #4 \n" + "incb %[row0_next], all, mul #4 \n" + "incb %[row1], all, mul #4 \n" + "incb %[row1_next], all, mul #4 \n" + "add z0.s, z0.s, z4.s \n" + "add z1.s, z1.s, z5.s \n" + "add z2.s, z2.s, z6.s \n" + "add z3.s, z3.s, z7.s \n" + "add z16.s, z16.s, z20.s \n" + "add z17.s, z17.s, z21.s \n" + "add z18.s, z18.s, z22.s \n" + "add z19.s, z19.s, z23.s \n" + "add z0.s, z0.s, z16.s \n" + "add z1.s, z1.s, z17.s \n" + "add z2.s, z2.s, z18.s \n" + "add z3.s, z3.s, z19.s \n" + "mul z4.s, z0.s, z1.s \n" + "lsl z4.s, z4.s, #1 \n" + "mul z5.s, z0.s, z0.s \n" + "mla z5.s, p1/m, z1.s, z1.s \n" + "lsl z3.s, z3.s, #7 \n" + "sub z3.s, z3.s, z4.s \n" + "add z4.s, z4.s, z25.s \n" + "add z3.s, z3.s, z26.s \n" + "lsl z2.s, z2.s, #6 \n" + "sub z2.s, z2.s, z5.s \n" + "add z5.s, z5.s, z25.s \n" + "add z2.s, z2.s, z26.s \n" + "scvtf z4.s, p1/m, z4.s \n" + "scvtf z3.s, p1/m, z3.s \n" + "scvtf z5.s, p1/m, z5.s \n" + "scvtf z2.s, p1/m, z2.s \n" + "fmul z4.s, z4.s, z3.s \n" + "fmul z5.s, z5.s, z2.s \n" + "fdiv z4.s, p1/m, z4.s, z5.s \n" + "fadd z24.s, p0/m, z24.s, z4.s \n" + "subs %w[num_windows], %w[num_windows], %w[vl] \n" + "b.gt 1b \n" + + "faddv %s[total], p1, z24.s \n" + : [row0] "+r"(row0), // %[row0] + [row0_next] "+r"(row0_next), // %[row0_next] + [row1] "+r"(row1), // %[row1] + [row1_next] "+r"(row1_next), // %[row1_next] + [num_windows] "+r"(num_windows), // %[num_windows] + [vl] "=&r"(vl), // %[vl] + [total] "=w"(total) // %[total] + : [c1] "r"(26634), // %[c1] + [c2] "r"(239708) // %[c2] + : "memory", "cc", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z16", + "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", + "p0", "p1"); + return total; +} + +static inline void ARGBOrRow_SVE_SC(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) STREAMING_COMPATIBLE { + uint32_t vl; + asm volatile( + "cntw %x[vl] \n" + "dup z2.s, %w[value] \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.lt 2f \n" + + "ptrue p0.s \n" + "1: \n" + "ld1w {z0.s}, p0/z, [%[src]] \n" + "ld1w {z1.s}, p0/z, [%[src], #1, mul vl] \n" + "incb %[src], all, mul #2 \n" + "orr z0.d, z0.d, z2.d \n" + "orr z1.d, z1.d, z2.d \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "st1w {z0.s}, p0, [%[dst]] \n" + "st1w {z1.s}, p0, [%[dst], #1, mul vl] \n" + "incb %[dst], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #1 \n" + "b.eq 99f \n" + + "whilelt p0.s, wzr, %w[width] \n" + "whilelt p1.s, %w[vl], %w[width] \n" + "ld1w {z0.s}, p0/z, [%[src]] \n" + "ld1w {z1.s}, p1/z, [%[src], #1, mul vl] \n" + "orr z0.d, z0.d, z2.d \n" + "orr z1.d, z1.d, z2.d \n" + "st1w {z0.s}, p0, [%[dst]] \n" + "st1w {z1.s}, p1, [%[dst], #1, mul vl] \n" + + "99: \n" + : [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_argb), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [value] "r"(value) // %[value] + : "memory", "cc", "z0", "z1", "z2", "p0", "p1"); +} + +#define ARGBALPHABLEND_SVE_2X(pred0, pred1) \ + "ld1w {z0.s}, " #pred0 "/z, [%[src0]] \n" \ + "ld1w {z1.s}, " #pred1 "/z, [%[src0], #1, mul vl] \n" \ + "ld1w {z2.s}, " #pred0 "/z, [%[src1]] \n" \ + "ld1w {z3.s}, " #pred1 "/z, [%[src1], #1, mul vl] \n" \ + "incb %[src0], all, mul #2 \n" \ + "incb %[src1], all, mul #2 \n" \ + "lsr z4.s, z0.s, #24 \n" \ + "lsr z5.s, z1.s, #24 \n" \ + "lsr z6.s, z2.s, #24 \n" \ + "lsr z7.s, z3.s, #24 \n" \ + "mov z16.d, z24.d \n" \ + "mov z17.d, z24.d \n" \ + "umlalb z16.h, z6.b, z4.b \n" \ + "umlalb z17.h, z7.b, z5.b \n" \ + "usra z16.h, z16.h, #8 \n" \ + "usra z17.h, z17.h, #8 \n" \ + "lsr z16.h, z16.h, #8 \n" \ + "lsr z17.h, z17.h, #8 \n" \ + "sub z16.s, z4.s, z16.s \n" \ + "sub z17.s, z5.s, z17.s \n" \ + "add z16.s, z6.s, z16.s \n" \ + "add z17.s, z7.s, z17.s \n" \ + "lsl z18.s, z4.s, #8 \n" \ + "lsl z19.s, z5.s, #8 \n" \ + "sub z18.s, z18.s, z4.s \n" \ + "sub z19.s, z19.s, z5.s \n" \ + "sub z6.s, z6.s, #1 \n" \ + "sub z7.s, z7.s, #1 \n" \ + "asr z6.s, z6.s, #31 \n" \ + "asr z7.s, z7.s, #31 \n" \ + "udiv z18.s, p0/m, z18.s, z16.s \n" \ + "udiv z19.s, p0/m, z19.s, z17.s \n" \ + "mul z18.s, z18.s, z25.s \n" \ + "mul z19.s, z19.s, z25.s \n" \ + "orr z18.d, z18.d, z6.d \n" \ + "orr z19.d, z19.d, z7.d \n" \ + "not z20.b, p0/m, z18.b \n" \ + "not z21.b, p0/m, z19.b \n" \ + "mov z4.d, z24.d \n" \ + "mov z5.d, z24.d \n" \ + "mov z6.d, z24.d \n" \ + "mov z7.d, z24.d \n" \ + "umlalb z4.h, z2.b, z20.b \n" \ + "umlalt z5.h, z2.b, z20.b \n" \ + "umlalb z6.h, z3.b, z21.b \n" \ + "umlalt z7.h, z3.b, z21.b \n" \ + "umlalb z4.h, z0.b, z18.b \n" \ + "umlalt z5.h, z0.b, z18.b \n" \ + "umlalb z6.h, z1.b, z19.b \n" \ + "umlalt z7.h, z1.b, z19.b \n" \ + "usra z4.h, z4.h, #8 \n" \ + "usra z5.h, z5.h, #8 \n" \ + "usra z6.h, z6.h, #8 \n" \ + "usra z7.h, z7.h, #8 \n" \ + "shrnb z0.b, z4.h, #8 \n" \ + "shrnt z0.b, z5.h, #8 \n" \ + "shrnb z1.b, z6.h, #8 \n" \ + "shrnt z1.b, z7.h, #8 \n" \ + "and z0.d, z0.d, z26.d \n" \ + "and z1.d, z1.d, z26.d \n" \ + "lsl z16.s, z16.s, #24 \n" \ + "lsl z17.s, z17.s, #24 \n" \ + "orr z0.d, z0.d, z16.d \n" \ + "orr z1.d, z1.d, z17.d \n" \ + "st1w {z0.s}, " #pred0 ", [%[dst]] \n" \ + "st1w {z1.s}, " #pred1 ", [%[dst], #1, mul vl] \n" \ + "incb %[dst], all, mul #2 \n" + +static inline void ARGBAlphaBlendRow_SVE_SC(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) STREAMING_COMPATIBLE { + uint32_t vl; + asm volatile( + "cntw %x[vl] \n" + "ptrue p0.b \n" + "mov z24.h, #1 \n" + "mov z25.s, #0x01010101 \n" + "mov z26.s, #0x00ffffff \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.lt 2f \n" + + "1: \n" + ARGBALPHABLEND_SVE_2X(p0, p0) + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #1 \n" + "b.eq 99f \n" + + "whilelt p1.s, wzr, %w[width] \n" + "whilelt p2.s, %w[vl], %w[width] \n" + ARGBALPHABLEND_SVE_2X(p1, p2) + + "99: \n" + : [src0] "+r"(src_argb0), // %[src0] + [src1] "+r"(src_argb1), // %[src1] + [dst] "+r"(dst_argb), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z16", + "z17", "z18", "z19", "z20", "z21", "z24", "z25", "z26", "p0", "p1", + "p2"); +} + +#endif // !defined(LIBYUV_DISABLE_SVE) && defined(__aarch64__) + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // INCLUDE_LIBYUV_ROW_SVE_H_ diff --git a/libs/libyuv/include/libyuv/scale.h b/libs/libyuv/include/libyuv/scale.h index 23ba1634f7..ada3f6061a 100644 --- a/libs/libyuv/include/libyuv/scale.h +++ b/libs/libyuv/include/libyuv/scale.h @@ -11,6 +11,8 @@ #ifndef INCLUDE_LIBYUV_SCALE_H_ #define INCLUDE_LIBYUV_SCALE_H_ +#include + #include "libyuv/basic_types.h" #ifdef __cplusplus @@ -27,27 +29,40 @@ typedef enum FilterMode { } FilterModeEnum; // Scale a YUV plane. +// Returns 0 if successful. LIBYUV_API -void ScalePlane(const uint8_t* src, - int src_stride, - int src_width, - int src_height, - uint8_t* dst, - int dst_stride, - int dst_width, - int dst_height, - enum FilterMode filtering); +int ScalePlane(const uint8_t* src, + int src_stride, + int src_width, + int src_height, + uint8_t* dst, + int dst_stride, + int dst_width, + int dst_height, + enum FilterMode filtering); LIBYUV_API -void ScalePlane_16(const uint16_t* src, - int src_stride, - int src_width, - int src_height, - uint16_t* dst, - int dst_stride, - int dst_width, - int dst_height, - enum FilterMode filtering); +int ScalePlane_16(const uint16_t* src, + int src_stride, + int src_width, + int src_height, + uint16_t* dst, + int dst_stride, + int dst_width, + int dst_height, + enum FilterMode filtering); + +// Sample is expected to be in the low 12 bits. +LIBYUV_API +int ScalePlane_12(const uint16_t* src, + int src_stride, + int src_width, + int src_height, + uint16_t* dst, + int dst_stride, + int dst_width, + int dst_height, + enum FilterMode filtering); // Scales a YUV 4:2:0 image from the src width and height to the // dst width and height. @@ -97,6 +112,25 @@ int I420Scale_16(const uint16_t* src_y, int dst_height, enum FilterMode filtering); +LIBYUV_API +int I420Scale_12(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int dst_width, + int dst_height, + enum FilterMode filtering); + // Scales a YUV 4:4:4 image from the src width and height to the // dst width and height. // If filtering is kFilterNone, a simple nearest-neighbor algorithm is @@ -145,6 +179,197 @@ int I444Scale_16(const uint16_t* src_y, int dst_height, enum FilterMode filtering); +LIBYUV_API +int I444Scale_12(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int dst_width, + int dst_height, + enum FilterMode filtering); + +// Scales a YUV 4:2:2 image from the src width and height to the +// dst width and height. +// If filtering is kFilterNone, a simple nearest-neighbor algorithm is +// used. This produces basic (blocky) quality at the fastest speed. +// If filtering is kFilterBilinear, interpolation is used to produce a better +// quality image, at the expense of speed. +// If filtering is kFilterBox, averaging is used to produce ever better +// quality image, at further expense of speed. +// Returns 0 if successful. +LIBYUV_API +int I422Scale(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + int src_width, + int src_height, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int dst_width, + int dst_height, + enum FilterMode filtering); + +LIBYUV_API +int I422Scale_16(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int dst_width, + int dst_height, + enum FilterMode filtering); + +LIBYUV_API +int I422Scale_12(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int dst_width, + int dst_height, + enum FilterMode filtering); + +// Scales an NV12, NV16 or NV24 image from the src width and height to the +// dst width and height. +// If filtering is kFilterNone, a simple nearest-neighbor algorithm is +// used. This produces basic (blocky) quality at the fastest speed. +// If filtering is kFilterBilinear, interpolation is used to produce a better +// quality image, at the expense of speed. +// kFilterBox is not supported for the UV channel and will be treated as +// bilinear. +// Returns 0 if successful. + +LIBYUV_API +int NV12Scale(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering); + +LIBYUV_API +int NV16Scale(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering); + +LIBYUV_API +int NV24Scale(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering); + +// Scales a P010, P210 or P410 image (10-bit, samples in the MSBs of uint16). +// Strides are in uint16 elements. Y and UV are converted to 10-bit LSB, +// scaled with ScalePlane_16 (kFilterBox included), then converted back to +// 10-bit MSB. +// Returns 0 if successful. + +LIBYUV_API +int P010Scale(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering); + +LIBYUV_API +int P210Scale(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering); + +LIBYUV_API +int P410Scale(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering); + #ifdef __cplusplus // Legacy API. Deprecated. LIBYUV_API @@ -164,11 +389,7 @@ int Scale(const uint8_t* src_y, int dst_stride_v, int dst_width, int dst_height, - LIBYUV_BOOL interpolate); - -// For testing, allow disabling of specialized scalers. -LIBYUV_API -void SetUseReferenceImpl(LIBYUV_BOOL use); + int interpolate); #endif // __cplusplus #ifdef __cplusplus diff --git a/libs/libyuv/include/libyuv/scale_argb.h b/libs/libyuv/include/libyuv/scale_argb.h index 7641f18e34..c0a55340fd 100644 --- a/libs/libyuv/include/libyuv/scale_argb.h +++ b/libs/libyuv/include/libyuv/scale_argb.h @@ -11,6 +11,8 @@ #ifndef INCLUDE_LIBYUV_SCALE_ARGB_H_ #define INCLUDE_LIBYUV_SCALE_ARGB_H_ +#include + #include "libyuv/basic_types.h" #include "libyuv/scale.h" // For FilterMode diff --git a/libs/libyuv/include/libyuv/scale_rgb.h b/libs/libyuv/include/libyuv/scale_rgb.h new file mode 100644 index 0000000000..94218fe3df --- /dev/null +++ b/libs/libyuv/include/libyuv/scale_rgb.h @@ -0,0 +1,44 @@ +/* + * Copyright 2022 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef INCLUDE_LIBYUV_SCALE_RGB_H_ +#define INCLUDE_LIBYUV_SCALE_RGB_H_ + +#include + +#include "libyuv/basic_types.h" +#include "libyuv/scale.h" // For FilterMode + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// RGB can be RAW, RGB24 or YUV24 +// RGB scales 24 bit images by converting a row at a time to ARGB +// and using ARGB row functions to scale, then convert to RGB. +// TODO(fbarchard): Allow input/output formats to be specified. +LIBYUV_API +int RGBScale(const uint8_t* src_rgb, + int src_stride_rgb, + int src_width, + int src_height, + uint8_t* dst_rgb, + int dst_stride_rgb, + int dst_width, + int dst_height, + enum FilterMode filtering); + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // INCLUDE_LIBYUV_SCALE_UV_H_ diff --git a/libs/libyuv/include/libyuv/scale_row.h b/libs/libyuv/include/libyuv/scale_row.h index 6e207a9c64..e81d227d91 100644 --- a/libs/libyuv/include/libyuv/scale_row.h +++ b/libs/libyuv/include/libyuv/scale_row.h @@ -11,7 +11,10 @@ #ifndef INCLUDE_LIBYUV_SCALE_ROW_H_ #define INCLUDE_LIBYUV_SCALE_ROW_H_ -#include "libyuv/basic_types.h" +#include +#include + +#include "libyuv/cpu_support.h" #include "libyuv/scale.h" #ifdef __cplusplus @@ -19,68 +22,86 @@ namespace libyuv { extern "C" { #endif -#if defined(__pnacl__) || defined(__CLR_VER) || \ - (defined(__native_client__) && defined(__x86_64__)) || \ - (defined(__i386__) && !defined(__SSE__) && !defined(__clang__)) -#define LIBYUV_DISABLE_X86 -#endif -#if defined(__native_client__) -#define LIBYUV_DISABLE_NEON -#endif -// MemorySanitizer does not support assembly code yet. http://crbug.com/344505 -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) -#define LIBYUV_DISABLE_X86 -#endif -#endif -// GCC >= 4.7.0 required for AVX2. -#if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) -#if (__GNUC__ > 4) || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 7)) -#define GCC_HAS_AVX2 1 -#endif // GNUC >= 4.7 -#endif // __GNUC__ - -// clang >= 3.4.0 required for AVX2. -#if defined(__clang__) && (defined(__x86_64__) || defined(__i386__)) -#if (__clang_major__ > 3) || (__clang_major__ == 3 && (__clang_minor__ >= 4)) -#define CLANG_HAS_AVX2 1 -#endif // clang >= 3.4 -#endif // __clang__ - -// Visual C 2012 required for AVX2. -#if defined(_M_IX86) && !defined(__clang__) && defined(_MSC_VER) && \ - _MSC_VER >= 1700 -#define VISUALC_HAS_AVX2 1 -#endif // VisualStudio >= 2012 - // The following are available on all x86 platforms: -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(_M_IX86) || defined(__x86_64__) || defined(__i386__)) +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(_M_IX86) || defined(_M_X64) || defined(__x86_64__) || \ + defined(__i386__)) #define HAS_FIXEDDIV1_X86 #define HAS_FIXEDDIV_X86 #define HAS_SCALEADDROW_SSE2 -#define HAS_SCALEARGBCOLS_SSE2 -#define HAS_SCALEARGBCOLSUP2_SSE2 -#define HAS_SCALEARGBFILTERCOLS_SSSE3 -#define HAS_SCALEARGBROWDOWN2_SSE2 -#define HAS_SCALEARGBROWDOWNEVEN_SSE2 -#define HAS_SCALECOLSUP2_SSE2 -#define HAS_SCALEFILTERCOLS_SSSE3 +#endif + +// The following are available on 32-bit Visual C and gcc/clang x86 platforms: +#if !defined(LIBYUV_DISABLE_X86) && !defined(LIBYUV_ENABLE_ROWWIN) && \ + ((defined(_MSC_VER) && defined(_M_IX86) && !defined(__clang__)) || \ + defined(__x86_64__) || defined(__i386__)) #define HAS_SCALEROWDOWN2_SSSE3 -#define HAS_SCALEROWDOWN34_SSSE3 -#define HAS_SCALEROWDOWN38_SSSE3 #define HAS_SCALEROWDOWN4_SSSE3 #endif +// The following are available for gcc/clang x86 platforms: +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__)) && \ + !defined(LIBYUV_ENABLE_ROWWIN) +#define HAS_SCALEROWUP2_LINEAR_SSE2 +#define HAS_SCALEROWUP2_LINEAR_SSSE3 +#define HAS_SCALEROWUP2_BILINEAR_SSE2 +#define HAS_SCALEROWUP2_BILINEAR_SSSE3 +#define HAS_SCALEROWUP2_LINEAR_12_SSSE3 +#define HAS_SCALEROWUP2_BILINEAR_12_SSSE3 +#define HAS_SCALEROWUP2_LINEAR_16_SSE2 +#define HAS_SCALEROWUP2_BILINEAR_16_SSE2 +#define HAS_SCALEUVROWUP2_LINEAR_SSSE3 +#define HAS_SCALEUVROWUP2_BILINEAR_SSSE3 +#define HAS_SCALEUVROWUP2_LINEAR_16_SSE41 +#define HAS_SCALEUVROWUP2_BILINEAR_16_SSE41 +#endif + // The following are available on all x86 platforms, but // require VS2012, clang 3.4 or gcc 4.7. -// The code supports NaCL but requires a new compiler and validator. #if !defined(LIBYUV_DISABLE_X86) && \ (defined(VISUALC_HAS_AVX2) || defined(CLANG_HAS_AVX2) || \ defined(GCC_HAS_AVX2)) #define HAS_SCALEADDROW_AVX2 +#define HAS_SCALEARGBCOLS_AVX2 +#define HAS_SCALEARGBCOLSUP2_AVX2 +#define HAS_SCALEARGBFILTERCOLS_AVX2 +#define HAS_SCALEARGBROWDOWN2_AVX2 +#define HAS_SCALEARGBROWDOWNEVEN_AVX2 +#define HAS_SCALECOLSUP2_AVX2 +#define HAS_SCALEFILTERCOLS_AVX2 +#define HAS_SCALEROWDOWN2_16_AVX2 #define HAS_SCALEROWDOWN2_AVX2 +#define HAS_SCALEROWDOWN34_AVX2 +#define HAS_SCALEROWDOWN38_AVX2 #define HAS_SCALEROWDOWN4_AVX2 +#define HAS_SCALEROWUP2_BILINEAR_12_AVX2 +#define HAS_SCALEROWUP2_BILINEAR_16_AVX2 +#define HAS_SCALEROWUP2_BILINEAR_AVX2 +#define HAS_SCALEROWUP2_LINEAR_12_AVX2 +#define HAS_SCALEROWUP2_LINEAR_16_AVX2 +#define HAS_SCALEROWUP2_LINEAR_AVX2 +#define HAS_SCALEUVADDCOLS3_AVX2 +#define HAS_SCALEUVROWDOWN2_AVX2 +#define HAS_SCALEUVROWDOWN2BOX_AVX2 +#define HAS_SCALEUVROWDOWN2LINEAR_AVX2 +#define HAS_SCALEUVROWDOWNEVEN_AVX2 +#define HAS_SCALEUVROWUP2_BILINEAR_16_AVX2 +#define HAS_SCALEUVROWUP2_BILINEAR_AVX2 +#define HAS_SCALEUVROWUP2_LINEAR_16_AVX2 +#define HAS_SCALEUVROWUP2_LINEAR_AVX2 +#endif + +// The following are available for AVX512 x64 platforms: +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(_M_X64)) && \ + (defined(CLANG_HAS_AVX512) || defined(GCC_HAS_AVX512) || \ + defined(VISUALC_HAS_AVX512)) +#define HAS_SCALEADDROW_AVX512BW +#define HAS_SCALEADDCOLS1_AVX512BW +#define HAS_SCALEADDCOLS2_AVX512BW +#define HAS_SCALEUVADDCOLS3_AVX512VBMI +#define HAS_SCALEROWDOWN2_AVX512BW #endif // The following are available on Neon platforms: @@ -96,36 +117,121 @@ extern "C" { #define HAS_SCALEROWDOWN34_NEON #define HAS_SCALEROWDOWN38_NEON #define HAS_SCALEROWDOWN4_NEON +#define HAS_SCALEUVADDCOLS3_NEON +#define HAS_SCALEUVROWDOWN2_NEON +#define HAS_SCALEUVROWDOWN2LINEAR_NEON +#define HAS_SCALEUVROWDOWN2BOX_NEON +#define HAS_SCALEUVROWDOWNEVEN_NEON +#define HAS_SCALEROWUP2_LINEAR_NEON +#define HAS_SCALEROWUP2_BILINEAR_NEON +#define HAS_SCALEROWUP2_LINEAR_12_NEON +#define HAS_SCALEROWUP2_BILINEAR_12_NEON +#define HAS_SCALEROWUP2_LINEAR_16_NEON +#define HAS_SCALEROWUP2_BILINEAR_16_NEON +#define HAS_SCALEUVROWUP2_LINEAR_NEON +#define HAS_SCALEUVROWUP2_BILINEAR_NEON +#define HAS_SCALEUVROWUP2_LINEAR_16_NEON +#define HAS_SCALEUVROWUP2_BILINEAR_16_NEON #endif -#if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) -#define HAS_SCALEADDROW_MSA -#define HAS_SCALEARGBCOLS_MSA -#define HAS_SCALEARGBFILTERCOLS_MSA -#define HAS_SCALEARGBROWDOWN2_MSA -#define HAS_SCALEARGBROWDOWNEVEN_MSA -#define HAS_SCALEFILTERCOLS_MSA -#define HAS_SCALEROWDOWN2_MSA -#define HAS_SCALEROWDOWN34_MSA -#define HAS_SCALEROWDOWN38_MSA -#define HAS_SCALEROWDOWN4_MSA +// The following are available on AArch64 Neon platforms: +#if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) +#define HAS_SCALEROWDOWN2_16_NEON #endif -#if !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) -#define HAS_FIXEDDIV1_MIPS -#define HAS_FIXEDDIV_MIPS -#define HAS_SCALEADDROW_16_MMI -#define HAS_SCALEADDROW_MMI -#define HAS_SCALEARGBCOLS_MMI -#define HAS_SCALEARGBCOLSUP2_MMI -#define HAS_SCALEARGBROWDOWN2_MMI -#define HAS_SCALEARGBROWDOWNEVEN_MMI -#define HAS_SCALECOLS_16_MMI -#define HAS_SCALECOLS_MMI -#define HAS_SCALEROWDOWN2_16_MMI -#define HAS_SCALEROWDOWN2_MMI -#define HAS_SCALEROWDOWN4_16_MMI -#define HAS_SCALEROWDOWN4_MMI +// The following are available on AArch64 SME platforms: +#if !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && \ + defined(__aarch64__) +#define HAS_SCALEARGBROWDOWN2_SME +#define HAS_SCALEROWDOWN2_16_SME +#define HAS_SCALEROWDOWN2_SME +#define HAS_SCALEUVADDCOLS3_SME +#define HAS_SCALEUVROWDOWN2BOX_SME +#define HAS_SCALEUVROWDOWN2LINEAR_SME +#define HAS_SCALEUVROWDOWN2_SME +#endif + +#if !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx) +#define HAS_SCALEARGBROWDOWN2_LSX +#define HAS_SCALEARGBROWDOWNEVEN_LSX +#define HAS_SCALEROWDOWN2_LSX +#define HAS_SCALEROWDOWN4_LSX +#define HAS_SCALEROWDOWN38_LSX +#define HAS_SCALEFILTERCOLS_LSX +#define HAS_SCALEADDROW_LSX +#define HAS_SCALEARGBCOLS_LSX +#define HAS_SCALEARGBFILTERCOLS_LSX +#define HAS_SCALEROWDOWN34_LSX +#define HAS_SCALEUVADDCOLS3_LSX +#endif + +#if !defined(LIBYUV_DISABLE_RVV) && \ + ((defined(__riscv_vector) && defined(__riscv_zve64x)) || \ + (defined(LIBYUV_RVV) && \ + (!defined(__riscv_vector) || defined(__riscv_zve64x)))) +#define HAS_SCALEUVROWDOWN4_RVV +#endif + +#if !defined(LIBYUV_DISABLE_RVV) && \ + (defined(__riscv_vector) || defined(LIBYUV_RVV)) +#define HAS_SCALEARGBROWDOWN2_RVV +#define HAS_SCALEROWDOWN34_0_BOX_RVV +#define HAS_SCALEROWDOWN34_1_BOX_RVV +#define HAS_SCALEROWDOWN38_2_BOX_RVV +#define HAS_SCALEROWDOWN38_3_BOX_RVV +#define HAS_SCALEUVROWUP2_BILINEAR_RVV +#define HAS_SCALEUVROWUP2_LINEAR_RVV +#define HAS_SCALEROWDOWN34_RVV +#define HAS_SCALEROWDOWN38_RVV +#define HAS_SCALEROWUP2_BILINEAR_RVV +#define HAS_SCALEROWUP2_LINEAR_RVV + +#define HAS_SCALEARGBROWDOWN2BOX_RVV +#define HAS_SCALEARGBROWDOWN2LINEAR_RVV +#define HAS_SCALEARGBROWDOWNEVENBOX_RVV +#define HAS_SCALEROWDOWN2BOX_RVV +#define HAS_SCALEADDROW_RVV +// TODO: Test ScaleARGBRowDownEven_RVV and enable it +// #define HAS_SCALEARGBROWDOWNEVEN_RVV +#define HAS_SCALEUVROWDOWNEVEN_RVV +#define HAS_SCALEROWDOWN2_RVV +#define HAS_SCALEROWDOWN2LINEAR_RVV +#define HAS_SCALEROWDOWN4_RVV +#define HAS_SCALEROWDOWN4BOX_RVV +#define HAS_SCALEUVADDCOLS3_RVV +#define HAS_SCALEUVROWDOWN2_RVV +#define HAS_SCALEUVROWDOWN2BOX_RVV +#define HAS_SCALEUVROWDOWN2LINEAR_RVV +#define HAS_SCALEARGBFILTERCOLS_RVV +#endif + +// The following are available for WebAssembly SIMD128: +#if !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) +#define HAS_SCALEADDROW_WASMSIMD +#define HAS_SCALEARGBCOLS_WASMSIMD +#define HAS_SCALEARGBCOLSUP2_WASMSIMD +#define HAS_SCALEARGBFILTERCOLS_WASMSIMD +#define HAS_SCALEARGBROWDOWN2_WASMSIMD +#define HAS_SCALEARGBROWDOWNEVEN_WASMSIMD +#define HAS_SCALEFILTERCOLS_WASMSIMD +#define HAS_SCALEROWDOWN2_WASMSIMD +#define HAS_SCALEROWDOWN34_WASMSIMD +#define HAS_SCALEROWDOWN38_WASMSIMD +#define HAS_SCALEROWDOWN4_WASMSIMD +#define HAS_SCALEUVADDCOLS3_WASMSIMD +#endif + +// The following are available for Hexagon HVX: +#if !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) +#define HAS_SCALEADDROW_HVX +#define HAS_SCALEARGBROWDOWN2_HVX +#define HAS_SCALEROWDOWN2_16_HVX +#define HAS_SCALEROWDOWN2_HVX +#define HAS_SCALEROWDOWN4_HVX +#define HAS_SCALEUVADDCOLS3_HVX +#define HAS_SCALEUVROWDOWN2_HVX +#define HAS_SCALEUVROWDOWN2BOX_HVX +#define HAS_SCALEUVROWDOWN2LINEAR_HVX #endif // Scale ARGB vertically with bilinear interpolation. @@ -165,17 +271,12 @@ enum FilterMode ScaleFilterReduce(int src_width, // Divide num by div and return as 16.16 fixed point result. int FixedDiv_C(int num, int div); int FixedDiv_X86(int num, int div); -int FixedDiv_MIPS(int num, int div); // Divide num - 1 by div - 1 and return as 16.16 fixed point result. int FixedDiv1_C(int num, int div); int FixedDiv1_X86(int num, int div); -int FixedDiv1_MIPS(int num, int div); #ifdef HAS_FIXEDDIV_X86 #define FixedDiv FixedDiv_X86 #define FixedDiv1 FixedDiv1_X86 -#elif defined HAS_FIXEDDIV_MIPS -#define FixedDiv FixedDiv_MIPS -#define FixedDiv1 FixedDiv1_MIPS #else #define FixedDiv FixedDiv_C #define FixedDiv1 FixedDiv1_C @@ -260,6 +361,40 @@ void ScaleRowDown34_1_Box_16_C(const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* d, int dst_width); + +void ScaleRowUp2_Linear_C(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_C(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_16_C(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_16_C(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_Any_C(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_Any_C(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_16_Any_C(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_16_Any_C(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); + void ScaleCols_C(uint8_t* dst_ptr, const uint8_t* src_ptr, int dst_width, @@ -375,6 +510,142 @@ void ScaleARGBFilterCols64_C(uint8_t* dst_argb, int dst_width, int x32, int dx); +void ScaleUVRowDown2_C(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2_16_C(const uint16_t* src_uv, + ptrdiff_t src_stride, + uint16_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Linear_C(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Linear_16_C(const uint16_t* src_uv, + ptrdiff_t src_stride, + uint16_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Box_C(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Box_16_C(const uint16_t* src_uv, + ptrdiff_t src_stride, + uint16_t* dst_uv, + int dst_width); +void ScaleUVRowDownEven_C(const uint8_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDownEven_16_C(const uint16_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint16_t* dst_uv, + int dst_width); +void ScaleUVRowDownEvenBox_C(const uint8_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDownEvenBox_16_C(const uint16_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint16_t* dst_uv, + int dst_width); + +void ScaleUVRowUp2_Linear_C(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_C(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_Any_C(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_Any_C(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_16_C(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_16_C(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_16_Any_C(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_16_Any_C(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); + +void ScaleUVCols_C(uint8_t* dst_uv, + const uint8_t* src_uv, + int dst_width, + int x, + int dx); +void ScaleUVCols_16_C(uint16_t* dst_uv, + const uint16_t* src_uv, + int dst_width, + int x, + int dx); +void ScaleUVCols64_C(uint8_t* dst_uv, + const uint8_t* src_uv, + int dst_width, + int x32, + int dx); +void ScaleUVCols64_16_C(uint16_t* dst_uv, + const uint16_t* src_uv, + int dst_width, + int x32, + int dx); +void ScaleUVColsUp2_C(uint8_t* dst_uv, + const uint8_t* src_uv, + int dst_width, + int, + int); +void ScaleUVColsUp2_16_C(uint16_t* dst_uv, + const uint16_t* src_uv, + int dst_width, + int, + int); +void ScaleUVFilterCols_C(uint8_t* dst_uv, + const uint8_t* src_uv, + int dst_width, + int x, + int dx); +void ScaleUVFilterCols_16_C(uint16_t* dst_uv, + const uint16_t* src_uv, + int dst_width, + int x, + int dx); +void ScaleUVFilterCols64_C(uint8_t* dst_uv, + const uint8_t* src_uv, + int dst_width, + int x32, + int dx); +void ScaleUVFilterCols64_16_C(uint16_t* dst_uv, + const uint16_t* src_uv, + int dst_width, + int x32, + int dx); +void ScaleUVAddCols3_C(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_16_C(int dst_width, + int scaleval, + const uint32_t* src_uv, + uint16_t* dst_uv); // Specialized scalers for x86. void ScaleRowDown2_SSSE3(const uint8_t* src_ptr, @@ -401,6 +672,34 @@ void ScaleRowDown2Box_AVX2(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); +void ScaleRowDown2_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowDown2Linear_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowDown2Box_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowDown2_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown2Linear_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown2Box_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown2Box_Odd_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); void ScaleRowDown4_SSSE3(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, @@ -418,30 +717,144 @@ void ScaleRowDown4Box_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown34_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleRowDown34_1_Box_SSSE3(const uint8_t* src_ptr, +void ScaleRowDown34_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_1_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_0_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_3_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_2_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); + +void ScaleRowUp2_Linear_SSE2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_SSE2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_12_SSSE3(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_12_SSSE3(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_16_SSE2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_16_SSE2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_SSSE3(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_SSSE3(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, + ptrdiff_t dst_stride, int dst_width); -void ScaleRowDown34_0_Box_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, +void ScaleRowUp2_Linear_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_12_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, int dst_width); -void ScaleRowDown38_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleRowDown38_3_Box_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleRowDown38_2_Box_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, +void ScaleRowUp2_Bilinear_12_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_16_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, int dst_width); +void ScaleRowUp2_Bilinear_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_Any_SSE2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_Any_SSE2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_12_Any_SSSE3(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_12_Any_SSSE3(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_16_Any_SSE2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_16_Any_SSE2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_Any_SSSE3(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_Any_SSSE3(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_12_Any_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_12_Any_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_16_Any_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_16_Any_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); + void ScaleRowDown2_Any_SSSE3(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, @@ -474,6 +887,18 @@ void ScaleRowDown2Box_Odd_AVX2(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); +void ScaleRowDown2_16_Any_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowDown2Linear_16_Any_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowDown2Box_16_Any_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width); void ScaleRowDown4_Any_SSSE3(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, @@ -491,63 +916,78 @@ void ScaleRowDown4Box_Any_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown34_Any_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleRowDown34_1_Box_Any_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleRowDown34_0_Box_Any_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleRowDown38_Any_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleRowDown38_3_Box_Any_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleRowDown38_2_Box_Any_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); +void ScaleRowDown34_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_1_Box_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_0_Box_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_3_Box_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_2_Box_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); void ScaleAddRow_SSE2(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width); void ScaleAddRow_AVX2(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width); +void ScaleAddRow_AVX512BW(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int src_width); void ScaleAddRow_Any_SSE2(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width); void ScaleAddRow_Any_AVX2(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width); +void ScaleAddCols1_AVX512BW(int dst_width, + int boxheight, + int x, + int dx, + const uint16_t* src_ptr, + uint8_t* dst_ptr); +void ScaleAddCols2_AVX512BW(int dst_width, + int boxheight, + int x, + int dx, + const uint16_t* src_ptr, + uint8_t* dst_ptr); -void ScaleFilterCols_SSSE3(uint8_t* dst_ptr, - const uint8_t* src_ptr, - int dst_width, - int x, - int dx); -void ScaleColsUp2_SSE2(uint8_t* dst_ptr, +void ScaleFilterCols_AVX2(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx); +void ScaleColsUp2_AVX2(uint8_t* dst_ptr, const uint8_t* src_ptr, int dst_width, int x, int dx); // ARGB Column functions -void ScaleARGBCols_SSE2(uint8_t* dst_argb, +void ScaleARGBCols_AVX2(uint8_t* dst_argb, const uint8_t* src_argb, int dst_width, int x, int dx); -void ScaleARGBFilterCols_SSSE3(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx); -void ScaleARGBColsUp2_SSE2(uint8_t* dst_argb, +void ScaleARGBFilterCols_AVX2(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx); +void ScaleARGBColsUp2_AVX2(uint8_t* dst_argb, const uint8_t* src_argb, int dst_width, int x, @@ -572,47 +1012,22 @@ void ScaleARGBCols_Any_NEON(uint8_t* dst_ptr, int dst_width, int x, int dx); -void ScaleARGBFilterCols_MSA(uint8_t* dst_argb, +void ScaleARGBFilterCols_RVV(uint8_t* dst_argb, const uint8_t* src_argb, int dst_width, int x, int dx); -void ScaleARGBCols_MSA(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx); -void ScaleARGBFilterCols_Any_MSA(uint8_t* dst_ptr, - const uint8_t* src_ptr, - int dst_width, - int x, - int dx); -void ScaleARGBCols_Any_MSA(uint8_t* dst_ptr, - const uint8_t* src_ptr, - int dst_width, - int x, - int dx); -void ScaleARGBCols_MMI(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx); -void ScaleARGBCols_Any_MMI(uint8_t* dst_ptr, - const uint8_t* src_ptr, - int dst_width, - int x, - int dx); // ARGB Row functions -void ScaleARGBRowDown2_SSE2(const uint8_t* src_argb, +void ScaleARGBRowDown2_AVX2(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDown2Linear_SSE2(const uint8_t* src_argb, +void ScaleARGBRowDown2Linear_AVX2(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDown2Box_SSE2(const uint8_t* src_argb, +void ScaleARGBRowDown2Box_AVX2(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width); @@ -620,47 +1035,59 @@ void ScaleARGBRowDown2_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); +void ScaleARGBRowDown2_SME(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); void ScaleARGBRowDown2Linear_NEON(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width); +void ScaleARGBRowDown2Linear_SME(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width); void ScaleARGBRowDown2Box_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); -void ScaleARGBRowDown2_MSA(const uint8_t* src_argb, +void ScaleARGBRowDown2Box_SME(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleARGBRowDown2_RVV(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDown2Linear_MSA(const uint8_t* src_argb, +void ScaleARGBRowDown2Linear_RVV(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDown2Box_MSA(const uint8_t* src_argb, +void ScaleARGBRowDown2Box_RVV(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDown2_MMI(const uint8_t* src_argb, +void ScaleARGBRowDown2_LSX(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDown2Linear_MMI(const uint8_t* src_argb, +void ScaleARGBRowDown2Linear_LSX(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDown2Box_MMI(const uint8_t* src_argb, +void ScaleARGBRowDown2Box_LSX(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDown2_Any_SSE2(const uint8_t* src_ptr, +void ScaleARGBRowDown2_Any_AVX2(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleARGBRowDown2Linear_Any_SSE2(const uint8_t* src_ptr, +void ScaleARGBRowDown2Linear_Any_AVX2(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleARGBRowDown2Box_Any_SSE2(const uint8_t* src_ptr, +void ScaleARGBRowDown2Box_Any_AVX2(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); @@ -676,36 +1103,24 @@ void ScaleARGBRowDown2Box_Any_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleARGBRowDown2_Any_MSA(const uint8_t* src_ptr, +void ScaleARGBRowDown2_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleARGBRowDown2Linear_Any_MSA(const uint8_t* src_ptr, +void ScaleARGBRowDown2Linear_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleARGBRowDown2Box_Any_MSA(const uint8_t* src_ptr, +void ScaleARGBRowDown2Box_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleARGBRowDown2_Any_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleARGBRowDown2Linear_Any_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleARGBRowDown2Box_Any_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleARGBRowDownEven_SSE2(const uint8_t* src_argb, +void ScaleARGBRowDownEven_AVX2(const uint8_t* src_argb, ptrdiff_t src_stride, int src_stepx, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDownEvenBox_SSE2(const uint8_t* src_argb, +void ScaleARGBRowDownEvenBox_AVX2(const uint8_t* src_argb, ptrdiff_t src_stride, int src_stepx, uint8_t* dst_argb, @@ -720,32 +1135,32 @@ void ScaleARGBRowDownEvenBox_NEON(const uint8_t* src_argb, int src_stepx, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDownEven_MSA(const uint8_t* src_argb, +void ScaleARGBRowDownEven_LSX(const uint8_t* src_argb, ptrdiff_t src_stride, int32_t src_stepx, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDownEvenBox_MSA(const uint8_t* src_argb, +void ScaleARGBRowDownEvenBox_LSX(const uint8_t* src_argb, ptrdiff_t src_stride, int src_stepx, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDownEven_MMI(const uint8_t* src_argb, +void ScaleARGBRowDownEven_RVV(const uint8_t* src_argb, ptrdiff_t src_stride, int32_t src_stepx, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDownEvenBox_MMI(const uint8_t* src_argb, +void ScaleARGBRowDownEvenBox_RVV(const uint8_t* src_argb, ptrdiff_t src_stride, int src_stepx, uint8_t* dst_argb, int dst_width); -void ScaleARGBRowDownEven_Any_SSE2(const uint8_t* src_ptr, +void ScaleARGBRowDownEven_Any_AVX2(const uint8_t* src_ptr, ptrdiff_t src_stride, int src_stepx, uint8_t* dst_ptr, int dst_width); -void ScaleARGBRowDownEvenBox_Any_SSE2(const uint8_t* src_ptr, +void ScaleARGBRowDownEvenBox_Any_AVX2(const uint8_t* src_ptr, ptrdiff_t src_stride, int src_stepx, uint8_t* dst_ptr, @@ -760,43 +1175,324 @@ void ScaleARGBRowDownEvenBox_Any_NEON(const uint8_t* src_ptr, int src_stepx, uint8_t* dst_ptr, int dst_width); -void ScaleARGBRowDownEven_Any_MSA(const uint8_t* src_ptr, +void ScaleARGBRowDownEven_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, int32_t src_stepx, uint8_t* dst_ptr, int dst_width); -void ScaleARGBRowDownEvenBox_Any_MSA(const uint8_t* src_ptr, +void ScaleARGBRowDownEvenBox_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, int src_stepx, uint8_t* dst_ptr, int dst_width); -void ScaleARGBRowDownEven_Any_MMI(const uint8_t* src_ptr, + +// UV Row functions +void ScaleUVRowDown2_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Linear_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleUVRowDown2_SME(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleUVRowDown2Linear_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Linear_SME(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Box_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleUVRowDown2Box_SME(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleUVRowDown2_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Linear_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleUVRowDown2_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowDown2Linear_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowDown2Box_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowDown2_Any_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowDown2Linear_Any_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowDown2Box_Any_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowDownEven_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDownEven_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown4_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + int32_t src_stepx, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDownEven_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + int32_t src_stepx, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDownEven_Any_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowDownEven_Any_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_ptr, + int dst_width); + +void ScaleUVRowUp2_Linear_SSSE3(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_SSSE3(const uint8_t* src_ptr, ptrdiff_t src_stride, - int32_t src_stepx, uint8_t* dst_ptr, + ptrdiff_t dst_stride, int dst_width); -void ScaleARGBRowDownEvenBox_Any_MMI(const uint8_t* src_ptr, +void ScaleUVRowUp2_Linear_Any_SSSE3(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_Any_SSSE3(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_Any_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_Any_AVX2(const uint8_t* src_ptr, ptrdiff_t src_stride, - int src_stepx, uint8_t* dst_ptr, + ptrdiff_t dst_stride, int dst_width); +void ScaleUVRowUp2_Linear_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_Any_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_RVV(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_16_SSE41(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_16_SSE41(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_16_Any_SSE41(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_16_Any_SSE41(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_16_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_16_Any_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_16_Any_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_16_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_16_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVRowUp2_Linear_16_Any_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleUVRowUp2_Bilinear_16_Any_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleUVAddCols3_AVX2(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_Any_AVX2(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_AVX512VBMI(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_NEON(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_Any_NEON(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_SME(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_RVV(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_LSX(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_Any_LSX(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_WASMSIMD(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_Any_WASMSIMD(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); +void ScaleUVAddCols3_HVX(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv); // ScaleRowDown2Box also used by planar functions -// NEON downscalers with interpolation. - -// Note - not static due to reuse in convert for 444 to 420. +// NEON/SME downscalers with interpolation. void ScaleRowDown2_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); +void ScaleRowDown2_SME(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleRowDown2_16_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width); +void ScaleRowDown2_16_SME(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width); void ScaleRowDown2Linear_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); +void ScaleRowDown2Linear_SME(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleRowDown2Linear_16_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width); +void ScaleRowDown2Linear_16_SME(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width); void ScaleRowDown2Box_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); +void ScaleRowDown2Box_SME(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleRowDown2Box_16_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width); +void ScaleRowDown2Box_16_SME(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width); void ScaleRowDown4_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, @@ -891,6 +1587,55 @@ void ScaleRowDown38_2_Box_Any_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width); +void ScaleRowUp2_Linear_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_12_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_12_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_16_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_16_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_Any_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_Any_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_12_Any_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_12_Any_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); +void ScaleRowUp2_Linear_16_Any_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_16_Any_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); + void ScaleAddRow_NEON(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width); void ScaleAddRow_Any_NEON(const uint8_t* src_ptr, uint16_t* dst_ptr, @@ -908,197 +1653,425 @@ void ScaleFilterCols_Any_NEON(uint8_t* dst_ptr, int x, int dx); -void ScaleRowDown2_MSA(const uint8_t* src_ptr, +void ScaleRowDown2_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); -void ScaleRowDown2Linear_MSA(const uint8_t* src_ptr, +void ScaleRowDown2Linear_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); -void ScaleRowDown2Box_MSA(const uint8_t* src_ptr, +void ScaleRowDown2Box_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); -void ScaleRowDown4_MSA(const uint8_t* src_ptr, +void ScaleRowDown4_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); -void ScaleRowDown4Box_MSA(const uint8_t* src_ptr, +void ScaleRowDown4Box_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); -void ScaleRowDown38_MSA(const uint8_t* src_ptr, +void ScaleRowDown38_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); -void ScaleRowDown38_2_Box_MSA(const uint8_t* src_ptr, +void ScaleRowDown38_2_Box_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown38_3_Box_MSA(const uint8_t* src_ptr, +void ScaleRowDown38_3_Box_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleAddRow_MSA(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width); -void ScaleFilterCols_MSA(uint8_t* dst_ptr, +void ScaleAddRow_LSX(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width); +void ScaleFilterCols_LSX(uint8_t* dst_ptr, const uint8_t* src_ptr, int dst_width, int x, int dx); -void ScaleRowDown34_MSA(const uint8_t* src_ptr, +void ScaleARGBFilterCols_LSX(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx); +void ScaleARGBCols_LSX(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx); +void ScaleRowDown34_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); -void ScaleRowDown34_0_Box_MSA(const uint8_t* src_ptr, +void ScaleRowDown34_0_Box_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* d, int dst_width); -void ScaleRowDown34_1_Box_MSA(const uint8_t* src_ptr, +void ScaleRowDown34_1_Box_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* d, int dst_width); - -void ScaleRowDown2_Any_MSA(const uint8_t* src_ptr, +void ScaleRowDown2_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown2Linear_Any_MSA(const uint8_t* src_ptr, +void ScaleRowDown2Linear_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown2Box_Any_MSA(const uint8_t* src_ptr, +void ScaleRowDown2Box_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown4_Any_MSA(const uint8_t* src_ptr, +void ScaleRowDown4_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown4Box_Any_MSA(const uint8_t* src_ptr, +void ScaleRowDown4Box_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown38_Any_MSA(const uint8_t* src_ptr, +void ScaleRowDown38_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown38_2_Box_Any_MSA(const uint8_t* src_ptr, +void ScaleRowDown38_2_Box_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown38_3_Box_Any_MSA(const uint8_t* src_ptr, +void ScaleRowDown38_3_Box_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleAddRow_Any_MSA(const uint8_t* src_ptr, +void ScaleAddRow_Any_LSX(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width); -void ScaleFilterCols_Any_MSA(uint8_t* dst_ptr, +void ScaleFilterCols_Any_LSX(uint8_t* dst_ptr, const uint8_t* src_ptr, int dst_width, int x, int dx); -void ScaleRowDown34_Any_MSA(const uint8_t* src_ptr, +void ScaleARGBCols_Any_LSX(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx); +void ScaleARGBFilterCols_Any_LSX(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx); +void ScaleRowDown34_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown34_0_Box_Any_MSA(const uint8_t* src_ptr, +void ScaleRowDown34_0_Box_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown34_1_Box_Any_MSA(const uint8_t* src_ptr, +void ScaleRowDown34_1_Box_Any_LSX(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown2_MMI(const uint8_t* src_ptr, +void ScaleAddRow_RVV(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width); +void ScaleRowDown2_RVV(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); -void ScaleRowDown2_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width); -void ScaleRowDown2Linear_MMI(const uint8_t* src_ptr, +void ScaleRowDown2Linear_RVV(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); -void ScaleRowDown2Linear_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width); -void ScaleRowDown2Box_MMI(const uint8_t* src_ptr, +void ScaleRowDown2Box_RVV(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width); -void ScaleRowDown2Box_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width); -void ScaleRowDown2Box_Odd_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width); -void ScaleRowDown4_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width); -void ScaleRowDown4_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width); -void ScaleRowDown4Box_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width); -void ScaleRowDown4Box_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width); -void ScaleAddRow_MMI(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width); -void ScaleAddRow_16_MMI(const uint16_t* src_ptr, - uint32_t* dst_ptr, - int src_width); -void ScaleColsUp2_MMI(uint8_t* dst_ptr, - const uint8_t* src_ptr, - int dst_width, - int x, - int dx); -void ScaleColsUp2_16_MMI(uint16_t* dst_ptr, - const uint16_t* src_ptr, - int dst_width, - int x, - int dx); -void ScaleARGBColsUp2_MMI(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx); -void ScaleRowDown2_Any_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width); -void ScaleRowDown2Linear_Any_MMI(const uint8_t* src_ptr, +void ScaleRowDown4_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown4Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_0_Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_1_Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleRowDown38_3_Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_2_Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); + +void ScaleRowUp2_Linear_RVV(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowUp2_Bilinear_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width); + +void ScaleRowDown2_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown2Linear_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown2Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown4_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown4Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_0_Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_1_Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_3_Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_2_Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown2_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown2Linear_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown2Box_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown2Box_Odd_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown4_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown4Box_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_Any_WASMSIMD(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); -void ScaleRowDown2Box_Any_MMI(const uint8_t* src_ptr, +void ScaleRowDown34_0_Box_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown34_1_Box_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_3_Box_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown38_2_Box_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleAddRow_WASMSIMD(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int src_width); +void ScaleAddRow_Any_WASMSIMD(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int src_width); +void ScaleFilterCols_WASMSIMD(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx); +void ScaleFilterCols_Any_WASMSIMD(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx); +void ScaleARGBRowDown2_WASMSIMD(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width); +void ScaleARGBRowDown2Linear_WASMSIMD(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width); +void ScaleARGBRowDown2Box_WASMSIMD(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width); +void ScaleARGBRowDown2_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleARGBRowDown2Linear_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleARGBRowDown2Box_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleARGBRowDownEven_WASMSIMD(const uint8_t* src_argb, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_argb, + int dst_width); +void ScaleARGBRowDownEvenBox_WASMSIMD(const uint8_t* src_argb, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_argb, + int dst_width); +void ScaleARGBRowDownEven_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_ptr, + int dst_width); +void ScaleARGBRowDownEvenBox_Any_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_ptr, + int dst_width); +void ScaleARGBCols_WASMSIMD(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx); +void ScaleARGBCols_Any_WASMSIMD(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx); +void ScaleARGBFilterCols_WASMSIMD(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx); +void ScaleARGBFilterCols_Any_WASMSIMD(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx); +void ScaleARGBColsUp2_WASMSIMD(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx); + +void ScaleAddRow_HVX(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width); +void ScaleRowDown2_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleRowDown2Linear_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleRowDown2Box_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width); +void ScaleRowDown2Box_Odd_HVX(const uint8_t* src_ptr, ptrdiff_t src_stride, - uint8_t* dst_ptr, + uint8_t* dst, int dst_width); -void ScaleRowDown4_Any_MMI(const uint8_t* src_ptr, +void ScaleRowDown2_16_HVX(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width); +void ScaleRowDown2Linear_16_HVX(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width); +void ScaleRowDown2Box_16_HVX(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width); +void ScaleRowDown4_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleRowDown4Box_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width); +void ScaleARGBRowDown2_HVX(const uint8_t* src_argb, ptrdiff_t src_stride, - uint8_t* dst_ptr, + uint8_t* dst_argb, int dst_width); -void ScaleRowDown4Box_Any_MMI(const uint8_t* src_ptr, +void ScaleARGBRowDown2Linear_HVX(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width); +void ScaleARGBRowDown2Box_HVX(const uint8_t* src_argb, ptrdiff_t src_stride, - uint8_t* dst_ptr, + uint8_t* dst_argb, int dst_width); -void ScaleAddRow_Any_MMI(const uint8_t* src_ptr, - uint16_t* dst_ptr, - int src_width); +void ScaleUVRowDown2_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Linear_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); +void ScaleUVRowDown2Box_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width); + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/include/libyuv/scale_uv.h b/libs/libyuv/include/libyuv/scale_uv.h new file mode 100644 index 0000000000..168c5d9495 --- /dev/null +++ b/libs/libyuv/include/libyuv/scale_uv.h @@ -0,0 +1,52 @@ +/* + * Copyright 2020 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef INCLUDE_LIBYUV_SCALE_UV_H_ +#define INCLUDE_LIBYUV_SCALE_UV_H_ + +#include + +#include "libyuv/basic_types.h" +#include "libyuv/scale.h" // For FilterMode + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +LIBYUV_API +int UVScale(const uint8_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint8_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering); + +// Scale a 16 bit UV image. +LIBYUV_API +int UVScale_16(const uint16_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint16_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering); + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // INCLUDE_LIBYUV_SCALE_UV_H_ diff --git a/libs/libyuv/include/libyuv/version.h b/libs/libyuv/include/libyuv/version.h index b1883ef8e1..5ba507c6d8 100644 --- a/libs/libyuv/include/libyuv/version.h +++ b/libs/libyuv/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 1735 +#define LIBYUV_VERSION 1977 #endif // INCLUDE_LIBYUV_VERSION_H_ diff --git a/libs/libyuv/include/libyuv/video_common.h b/libs/libyuv/include/libyuv/video_common.h index ffcbdbf1b0..ee989f7869 100644 --- a/libs/libyuv/include/libyuv/video_common.h +++ b/libs/libyuv/include/libyuv/video_common.h @@ -13,6 +13,9 @@ #ifndef INCLUDE_LIBYUV_VIDEO_COMMON_H_ #define INCLUDE_LIBYUV_VIDEO_COMMON_H_ +#include +#include + #include "libyuv/basic_types.h" #ifdef __cplusplus @@ -50,45 +53,72 @@ extern "C" { // Secondary formats are converted in 2 steps. // Auxilliary formats call primary converters. enum FourCC { - // 9 Primary YUV formats: 5 planar, 2 biplanar, 2 packed. + // 15 Primary YUV formats: 6 planar, 7 biplanar, 2 packed. FOURCC_I420 = FOURCC('I', '4', '2', '0'), FOURCC_I422 = FOURCC('I', '4', '2', '2'), FOURCC_I444 = FOURCC('I', '4', '4', '4'), FOURCC_I400 = FOURCC('I', '4', '0', '0'), FOURCC_NV21 = FOURCC('N', 'V', '2', '1'), FOURCC_NV12 = FOURCC('N', 'V', '1', '2'), + FOURCC_NV16 = FOURCC('N', 'V', '1', '6'), + FOURCC_NV24 = FOURCC('N', 'V', '2', '4'), + FOURCC_P010 = FOURCC('P', '0', '1', '0'), + FOURCC_P210 = FOURCC('P', '2', '1', '0'), + FOURCC_P410 = FOURCC('P', '4', '1', '0'), FOURCC_YUY2 = FOURCC('Y', 'U', 'Y', '2'), FOURCC_UYVY = FOURCC('U', 'Y', 'V', 'Y'), - FOURCC_H010 = FOURCC('H', '0', '1', '0'), // unofficial fourcc. 10 bit lsb + FOURCC_I010 = FOURCC('I', '0', '1', '0'), // bt.601 10 bit 420 + FOURCC_I210 = FOURCC('I', '2', '1', '0'), // bt.601 10 bit 422 - // 1 Secondary YUV format: row biplanar. + // 1 Secondary YUV format: row biplanar. deprecated. FOURCC_M420 = FOURCC('M', '4', '2', '0'), - // 11 Primary RGB formats: 4 32 bpp, 2 24 bpp, 3 16 bpp, 1 10 bpc + // 13 Primary RGB formats: 4 32 bpp, 2 24 bpp, 3 16 bpp, 1 10 bpc 2 64 bpp FOURCC_ARGB = FOURCC('A', 'R', 'G', 'B'), FOURCC_BGRA = FOURCC('B', 'G', 'R', 'A'), FOURCC_ABGR = FOURCC('A', 'B', 'G', 'R'), FOURCC_AR30 = FOURCC('A', 'R', '3', '0'), // 10 bit per channel. 2101010. FOURCC_AB30 = FOURCC('A', 'B', '3', '0'), // ABGR version of 10 bit + FOURCC_AR64 = FOURCC('A', 'R', '6', '4'), // 16 bit per channel. + FOURCC_AB64 = FOURCC('A', 'B', '6', '4'), // ABGR version of 16 bit FOURCC_24BG = FOURCC('2', '4', 'B', 'G'), FOURCC_RAW = FOURCC('r', 'a', 'w', ' '), FOURCC_RGBA = FOURCC('R', 'G', 'B', 'A'), - FOURCC_RGBP = FOURCC('R', 'G', 'B', 'P'), // rgb565 LE. - FOURCC_RGBO = FOURCC('R', 'G', 'B', 'O'), // argb1555 LE. - FOURCC_R444 = FOURCC('R', '4', '4', '4'), // argb4444 LE. + FOURCC_RGBP = FOURCC('R', 'G', 'B', 'P'), // rgb565 LE. deprecated. + FOURCC_RGBO = FOURCC('R', 'G', 'B', 'O'), // argb1555 LE. deprecated. + FOURCC_R444 = FOURCC('R', '4', '4', '4'), // argb4444 LE. deprecated. // 1 Primary Compressed YUV format. FOURCC_MJPG = FOURCC('M', 'J', 'P', 'G'), - // 8 Auxiliary YUV variations: 3 with U and V planes are swapped, 1 Alias. + // 23 Auxiliary YUV variations: 3 with U and V planes are swapped, 1 Alias. FOURCC_YV12 = FOURCC('Y', 'V', '1', '2'), FOURCC_YV16 = FOURCC('Y', 'V', '1', '6'), FOURCC_YV24 = FOURCC('Y', 'V', '2', '4'), FOURCC_YU12 = FOURCC('Y', 'U', '1', '2'), // Linux version of I420. - FOURCC_J420 = FOURCC('J', '4', '2', '0'), - FOURCC_J400 = FOURCC('J', '4', '0', '0'), // unofficial fourcc - FOURCC_H420 = FOURCC('H', '4', '2', '0'), // unofficial fourcc - FOURCC_H422 = FOURCC('H', '4', '2', '2'), // unofficial fourcc + FOURCC_J420 = + FOURCC('J', '4', '2', '0'), // jpeg (bt.601 full), unofficial fourcc + FOURCC_J422 = + FOURCC('J', '4', '2', '2'), // jpeg (bt.601 full), unofficial fourcc + FOURCC_J444 = + FOURCC('J', '4', '4', '4'), // jpeg (bt.601 full), unofficial fourcc + FOURCC_J400 = + FOURCC('J', '4', '0', '0'), // jpeg (bt.601 full), unofficial fourcc + FOURCC_F420 = FOURCC('F', '4', '2', '0'), // bt.709 full, unofficial fourcc + FOURCC_F422 = FOURCC('F', '4', '2', '2'), // bt.709 full, unofficial fourcc + FOURCC_F444 = FOURCC('F', '4', '4', '4'), // bt.709 full, unofficial fourcc + FOURCC_H420 = FOURCC('H', '4', '2', '0'), // bt.709, unofficial fourcc + FOURCC_H422 = FOURCC('H', '4', '2', '2'), // bt.709, unofficial fourcc + FOURCC_H444 = FOURCC('H', '4', '4', '4'), // bt.709, unofficial fourcc + FOURCC_U420 = FOURCC('U', '4', '2', '0'), // bt.2020, unofficial fourcc + FOURCC_U422 = FOURCC('U', '4', '2', '2'), // bt.2020, unofficial fourcc + FOURCC_U444 = FOURCC('U', '4', '4', '4'), // bt.2020, unofficial fourcc + FOURCC_F010 = FOURCC('F', '0', '1', '0'), // bt.709 full range 10 bit 420 + FOURCC_H010 = FOURCC('H', '0', '1', '0'), // bt.709 10 bit 420 + FOURCC_U010 = FOURCC('U', '0', '1', '0'), // bt.2020 10 bit 420 + FOURCC_F210 = FOURCC('F', '2', '1', '0'), // bt.709 full range 10 bit 422 + FOURCC_H210 = FOURCC('H', '2', '1', '0'), // bt.709 10 bit 422 + FOURCC_U210 = FOURCC('U', '2', '1', '0'), // bt.2020 10 bit 422 // 14 Auxiliary aliases. CanonicalFourCC() maps these to canonical fourcc. FOURCC_IYUV = FOURCC('I', 'Y', 'U', 'V'), // Alias for I420. @@ -105,9 +135,9 @@ enum FourCC { FOURCC_BGR3 = FOURCC('B', 'G', 'R', '3'), // Alias for 24BG. FOURCC_CM32 = FOURCC(0, 0, 0, 32), // Alias for BGRA kCMPixelFormat_32ARGB FOURCC_CM24 = FOURCC(0, 0, 0, 24), // Alias for RAW kCMPixelFormat_24RGB - FOURCC_L555 = FOURCC('L', '5', '5', '5'), // Alias for RGBO. - FOURCC_L565 = FOURCC('L', '5', '6', '5'), // Alias for RGBP. - FOURCC_5551 = FOURCC('5', '5', '5', '1'), // Alias for RGBO. + FOURCC_L555 = FOURCC('L', '5', '5', '5'), // Alias for RGBO. deprecated. + FOURCC_L565 = FOURCC('L', '5', '6', '5'), // Alias for RGBP. deprecated. + FOURCC_5551 = FOURCC('5', '5', '5', '1'), // Alias for RGBO. deprecated. // deprecated formats. Not supported, but defined for backward compatibility. FOURCC_I411 = FOURCC('I', '4', '1', '1'), @@ -131,9 +161,11 @@ enum FourCCBpp { FOURCC_BPP_I400 = 8, FOURCC_BPP_NV21 = 12, FOURCC_BPP_NV12 = 12, + FOURCC_BPP_NV16 = 16, + FOURCC_BPP_NV24 = 24, FOURCC_BPP_YUY2 = 16, FOURCC_BPP_UYVY = 16, - FOURCC_BPP_M420 = 12, + FOURCC_BPP_M420 = 12, // deprecated FOURCC_BPP_Q420 = 12, FOURCC_BPP_ARGB = 32, FOURCC_BPP_BGRA = 32, @@ -141,11 +173,13 @@ enum FourCCBpp { FOURCC_BPP_RGBA = 32, FOURCC_BPP_AR30 = 32, FOURCC_BPP_AB30 = 32, + FOURCC_BPP_AR64 = 64, + FOURCC_BPP_AB64 = 64, FOURCC_BPP_24BG = 24, FOURCC_BPP_RAW = 24, - FOURCC_BPP_RGBP = 16, - FOURCC_BPP_RGBO = 16, - FOURCC_BPP_R444 = 16, + FOURCC_BPP_RGBP = 16, // deprecated + FOURCC_BPP_RGBO = 16, // deprecated + FOURCC_BPP_R444 = 16, // deprecated FOURCC_BPP_RGGB = 8, FOURCC_BPP_BGGR = 8, FOURCC_BPP_GRBG = 8, @@ -158,7 +192,13 @@ enum FourCCBpp { FOURCC_BPP_J400 = 8, FOURCC_BPP_H420 = 12, FOURCC_BPP_H422 = 16, - FOURCC_BPP_H010 = 24, + FOURCC_BPP_I010 = 15, + FOURCC_BPP_I210 = 20, + FOURCC_BPP_H010 = 15, + FOURCC_BPP_H210 = 20, + FOURCC_BPP_P010 = 15, + FOURCC_BPP_P210 = 20, + FOURCC_BPP_P410 = 30, FOURCC_BPP_MJPG = 0, // 0 means unknown. FOURCC_BPP_H264 = 0, FOURCC_BPP_IYUV = 12, diff --git a/libs/libyuv/infra/config/OWNERS b/libs/libyuv/infra/config/OWNERS new file mode 100644 index 0000000000..2c4f90a03c --- /dev/null +++ b/libs/libyuv/infra/config/OWNERS @@ -0,0 +1,3 @@ +fbarchard@chromium.org +mbonadei@chromium.org +jansson@google.com diff --git a/libs/libyuv/infra/config/PRESUBMIT.py b/libs/libyuv/infra/config/PRESUBMIT.py new file mode 100644 index 0000000000..0aa465e242 --- /dev/null +++ b/libs/libyuv/infra/config/PRESUBMIT.py @@ -0,0 +1,17 @@ +# Copyright 2018 The PDFium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +USE_PYTHON3 = True + + +def CheckChangeOnUpload(input_api, output_api): + return input_api.canned_checks.CheckChangedLUCIConfigs( + input_api, output_api + ) + + +def CheckChangeOnCommit(input_api, output_api): + return input_api.canned_checks.CheckChangedLUCIConfigs( + input_api, output_api + ) diff --git a/libs/libyuv/infra/config/README.md b/libs/libyuv/infra/config/README.md new file mode 100644 index 0000000000..e5e3b5f818 --- /dev/null +++ b/libs/libyuv/infra/config/README.md @@ -0,0 +1,2 @@ +This folder contains libyuv project-wide configurations +for chrome-infra services. diff --git a/libs/libyuv/infra/config/codereview.settings b/libs/libyuv/infra/config/codereview.settings new file mode 100644 index 0000000000..6d74227357 --- /dev/null +++ b/libs/libyuv/infra/config/codereview.settings @@ -0,0 +1,6 @@ +# This file is used by gcl and git-cl to get repository specific information. +CODE_REVIEW_SERVER: codereview.chromium.org +PROJECT: libyuv +GERRIT_HOST: True +VIEW_VC: https://chromium.googlesource.com/libyuv/libyuv/+/ + diff --git a/libs/libyuv/infra/config/commit-queue.cfg b/libs/libyuv/infra/config/commit-queue.cfg new file mode 100644 index 0000000000..640b530e48 --- /dev/null +++ b/libs/libyuv/infra/config/commit-queue.cfg @@ -0,0 +1,144 @@ +# Auto-generated by lucicfg. +# Do not modify manually. +# +# For the schema of this file, see Config message: +# https://config.luci.app/schemas/projects:commit-queue.cfg + +cq_status_host: "chromium-cq-status.appspot.com" +submit_options { + max_burst: 4 + burst_delay { + seconds: 480 + } +} +config_groups { + name: "config" + gerrit { + url: "https://chromium-review.googlesource.com" + projects { + name: "libyuv/libyuv" + ref_regexp: "refs/heads/infra/config" + } + } + verifiers { + gerrit_cq_ability { + committer_list: "project-libyuv-committers" + dry_run_access_list: "project-libyuv-tryjob-access" + } + tryjob { + builders { + name: "libyuv/try/presubmit" + } + retry_config { + single_quota: 1 + global_quota: 2 + failure_weight: 1 + transient_failure_weight: 1 + timeout_weight: 2 + } + } + } +} +config_groups { + name: "master" + gerrit { + url: "https://chromium-review.googlesource.com" + projects { + name: "libyuv/libyuv" + ref_regexp: "refs/heads/main" + ref_regexp: "refs/heads/master" + } + } + verifiers { + gerrit_cq_ability { + committer_list: "project-libyuv-committers" + dry_run_access_list: "project-libyuv-tryjob-access" + } + tryjob { + builders { + name: "libyuv/try/android" + experiment_percentage: 100 + } + builders { + name: "libyuv/try/android_arm64" + experiment_percentage: 100 + } + builders { + name: "libyuv/try/android_rel" + experiment_percentage: 100 + } + builders { + name: "libyuv/try/android_x64" + } + builders { + name: "libyuv/try/android_x86" + } + builders { + name: "libyuv/try/ios_arm64" + } + builders { + name: "libyuv/try/ios_arm64_rel" + } + builders { + name: "libyuv/try/linux" + } + builders { + name: "libyuv/try/linux_asan" + } + builders { + name: "libyuv/try/linux_gcc" + experiment_percentage: 100 + } + builders { + name: "libyuv/try/linux_msan" + experiment_percentage: 100 + } + builders { + name: "libyuv/try/linux_rel" + } + builders { + name: "libyuv/try/linux_tsan2" + } + builders { + name: "libyuv/try/linux_ubsan" + } + builders { + name: "libyuv/try/linux_ubsan_vptr" + } + builders { + name: "libyuv/try/mac" + } + builders { + name: "libyuv/try/mac_asan" + } + builders { + name: "libyuv/try/mac_rel" + } + builders { + name: "libyuv/try/win" + } + builders { + name: "libyuv/try/win_clang" + } + builders { + name: "libyuv/try/win_clang_rel" + } + builders { + name: "libyuv/try/win_rel" + } + builders { + name: "libyuv/try/win_x64_clang_rel" + } + builders { + name: "libyuv/try/win_x64_rel" + } + retry_config { + single_quota: 1 + global_quota: 2 + failure_weight: 1 + transient_failure_weight: 1 + timeout_weight: 2 + } + } + } +} diff --git a/libs/libyuv/infra/config/cr-buildbucket.cfg b/libs/libyuv/infra/config/cr-buildbucket.cfg new file mode 100644 index 0000000000..a3348afc4f --- /dev/null +++ b/libs/libyuv/infra/config/cr-buildbucket.cfg @@ -0,0 +1,1130 @@ +# Auto-generated by lucicfg. +# Do not modify manually. +# +# For the schema of this file, see BuildbucketCfg message: +# https://config.luci.app/schemas/projects:buildbucket.cfg + +buckets { + name: "ci" + acls { + role: WRITER + group: "project-libyuv-admins" + } + acls { + group: "all" + } + swarming { + builders { + name: "Android ARM64 Debug" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Android Debug" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Android Release" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Android Tester ARM32 Debug (Nexus 5X)" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "device_type:walleye" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Android Tester ARM32 Release (Nexus 5X)" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "device_type:walleye" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Android Tester ARM64 Debug (Nexus 5X)" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "device_type:walleye" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Android32 x86 Debug" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Android64 x64 Debug" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Linux Asan" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Linux MSan" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Linux Tsan v2" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Linux UBSan" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Linux UBSan vptr" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Linux32 Debug" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Linux32 Release" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Linux64 Debug" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Linux64 Release" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Mac Asan" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cpu:arm64" + dimensions: "os:Mac-15" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Mac64 Debug" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cpu:arm64" + dimensions: "os:Mac-15" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Mac64 Release" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cpu:arm64" + dimensions: "os:Mac-15" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Win32 Debug" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Win32 Debug (Clang)" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Win32 Release" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Win32 Release (Clang)" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Win64 Debug" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Win64 Debug (Clang)" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Win64 Release" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "Win64 Release (Clang)" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "iOS ARM64 Debug" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cpu:arm64" + dimensions: "os:Mac-15" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "iOS ARM64 Release" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cpu:arm64" + dimensions: "os:Mac-15" + dimensions: "pool:luci.flex.ci" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-trusted\"}" + properties_j: "builder_group:\"client.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + } + shadow: "ci.shadow" + constraints { + pools: "luci.flex.ci" + } +} +buckets { + name: "ci.shadow" + acls { + role: WRITER + group: "project-libyuv-admins" + } + acls { + group: "all" + } + constraints { + pools: "luci.flex.ci" + service_accounts: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + dynamic_builder_template {} +} +buckets { + name: "cron" + acls { + role: WRITER + group: "project-libyuv-admins" + } + acls { + group: "all" + } + swarming { + builders { + name: "DEPS Autoroller" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cpu:x86-64" + dimensions: "os:Linux" + dimensions: "pool:luci.webrtc.cron" + recipe { + name: "libyuv/roll_deps" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + } + execution_timeout_secs: 7200 + build_numbers: YES + service_account: "libyuv-ci-autoroll-builder@chops-service-accounts.iam.gserviceaccount.com" + } + } +} +buckets { + name: "try" + acls { + role: WRITER + group: "project-libyuv-admins" + } + acls { + group: "all" + } + acls { + role: SCHEDULER + group: "project-libyuv-tryjob-access" + } + acls { + role: SCHEDULER + group: "service-account-cq" + } + swarming { + builders { + name: "android" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "device_type:walleye" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "android_arm64" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "device_type:walleye" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "android_rel" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "device_type:walleye" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "android_x64" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "android_x86" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "ios_arm64" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cpu:arm64" + dimensions: "os:Mac-15" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "ios_arm64_rel" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cpu:arm64" + dimensions: "os:Mac-15" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "linux" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "linux_asan" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "linux_gcc" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "linux_msan" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "linux_rel" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "linux_tsan2" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "linux_ubsan" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "linux_ubsan_vptr" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "mac" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cpu:arm64" + dimensions: "os:Mac-15" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "mac_asan" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cpu:arm64" + dimensions: "os:Mac-15" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "mac_rel" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cpu:arm64" + dimensions: "os:Mac-15" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "presubmit" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Ubuntu-24.04" + dimensions: "pool:luci.flex.try" + recipe { + name: "run_presubmit" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + properties_j: "repo_name:\"libyuv\"" + properties_j: "runhooks:true" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "win" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "win_clang" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "win_clang_rel" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "win_rel" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "win_x64_clang_rel" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + builders { + name: "win_x64_rel" + swarming_host: "chromium-swarm.appspot.com" + swarming_tags: "vpython:native-python-wrapper" + dimensions: "cores:8" + dimensions: "cpu:x86-64" + dimensions: "os:Windows-10" + dimensions: "pool:luci.flex.try" + recipe { + name: "libyuv/libyuv" + cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" + cipd_version: "refs/heads/main" + properties_j: "$build/siso:{\"configs\":[\"builder\"],\"enable_cloud_profiler\":true,\"enable_cloud_trace\":true,\"enable_monitoring\":true,\"project\":\"rbe-webrtc-untrusted\"}" + properties_j: "builder_group:\"tryserver.libyuv\"" + } + execution_timeout_secs: 10800 + build_numbers: YES + service_account: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + } + shadow: "try.shadow" + constraints { + pools: "luci.flex.try" + service_accounts: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } +} +buckets { + name: "try.shadow" + acls { + role: WRITER + group: "project-libyuv-admins" + } + acls { + group: "all" + } + constraints { + pools: "luci.flex.try" + service_accounts: "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + dynamic_builder_template {} +} diff --git a/libs/libyuv/infra/config/luci-logdog.cfg b/libs/libyuv/infra/config/luci-logdog.cfg new file mode 100644 index 0000000000..01a391261d --- /dev/null +++ b/libs/libyuv/infra/config/luci-logdog.cfg @@ -0,0 +1,9 @@ +# Auto-generated by lucicfg. +# Do not modify manually. +# +# For the schema of this file, see ProjectConfig message: +# https://config.luci.app/schemas/projects:luci-logdog.cfg + +reader_auth_groups: "all" +writer_auth_groups: "luci-logdog-chromium-writers" +archive_gs_bucket: "chromium-luci-logdog" diff --git a/libs/libyuv/infra/config/luci-milo.cfg b/libs/libyuv/infra/config/luci-milo.cfg new file mode 100644 index 0000000000..cde1848b59 --- /dev/null +++ b/libs/libyuv/infra/config/luci-milo.cfg @@ -0,0 +1,246 @@ +# Auto-generated by lucicfg. +# Do not modify manually. +# +# For the schema of this file, see Project message: +# https://config.luci.app/schemas/projects:luci-milo.cfg + +consoles { + id: "main" + name: "libyuv Main Console" + repo_url: "https://chromium.googlesource.com/libyuv/libyuv" + refs: "regexp:refs/heads/main" + manifest_name: "REVISION" + builders { + name: "buildbucket/luci.libyuv.ci/Android ARM64 Debug" + category: "Android|Builder" + short_name: "dbg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Android Debug" + category: "Android|Builder" + short_name: "dbg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Android Release" + category: "Android|Builder" + short_name: "rel" + } + builders { + name: "buildbucket/luci.libyuv.ci/Android32 x86 Debug" + category: "Android|Builder|x86" + short_name: "dbg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Android64 x64 Debug" + category: "Android|Builder|x64" + short_name: "dbg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Android Tester ARM32 Debug (Nexus 5X)" + category: "Android|Tester|ARM 32" + short_name: "dbg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Android Tester ARM32 Release (Nexus 5X)" + category: "Android|Tester|ARM 32" + short_name: "rel" + } + builders { + name: "buildbucket/luci.libyuv.ci/Android Tester ARM64 Debug (Nexus 5X)" + category: "Android|Tester|ARM 64" + short_name: "dbg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Linux Asan" + category: "Linux" + short_name: "asan" + } + builders { + name: "buildbucket/luci.libyuv.ci/Linux MSan" + category: "Linux" + short_name: "msan" + } + builders { + name: "buildbucket/luci.libyuv.ci/Linux Tsan v2" + category: "Linux" + short_name: "tsan" + } + builders { + name: "buildbucket/luci.libyuv.ci/Linux UBSan" + category: "Linux|UBSan" + } + builders { + name: "buildbucket/luci.libyuv.ci/Linux UBSan vptr" + category: "Linux|UBSan" + short_name: "vptr" + } + builders { + name: "buildbucket/luci.libyuv.ci/Linux32 Debug" + category: "Linux|32" + short_name: "dbg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Linux32 Release" + category: "Linux|32" + short_name: "rel" + } + builders { + name: "buildbucket/luci.libyuv.ci/Linux64 Debug" + category: "Linux|64" + short_name: "dbg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Linux64 Release" + category: "Linux|64" + short_name: "rel" + } + builders { + name: "buildbucket/luci.libyuv.ci/Mac Asan" + category: "Mac" + short_name: "asan" + } + builders { + name: "buildbucket/luci.libyuv.ci/Mac64 Debug" + category: "Mac" + short_name: "dbg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Mac64 Release" + category: "Mac" + short_name: "rel" + } + builders { + name: "buildbucket/luci.libyuv.ci/Win32 Debug" + category: "Win|32|Debug" + } + builders { + name: "buildbucket/luci.libyuv.ci/Win32 Debug (Clang)" + category: "Win|32|Debug" + short_name: "clg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Win32 Release" + category: "Win|32|Release" + } + builders { + name: "buildbucket/luci.libyuv.ci/Win32 Release (Clang)" + category: "Win|32|Release" + short_name: "clg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Win64 Debug" + category: "Win|64|Debug" + short_name: "clg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Win64 Debug (Clang)" + category: "Win|64|Debug" + short_name: "clg" + } + builders { + name: "buildbucket/luci.libyuv.ci/Win64 Release" + category: "Win|64|Release" + } + builders { + name: "buildbucket/luci.libyuv.ci/Win64 Release (Clang)" + category: "Win|64|Release" + short_name: "clg" + } + builders { + name: "buildbucket/luci.libyuv.ci/iOS ARM64 Debug" + category: "iOS|ARM64" + short_name: "dbg" + } + builders { + name: "buildbucket/luci.libyuv.ci/iOS ARM64 Release" + category: "iOS|ARM64" + short_name: "rel" + } + include_experimental_builds: true +} +consoles { + id: "cron" + name: "Cron" + builders { + name: "buildbucket/luci.libyuv.cron/DEPS Autoroller" + } + builder_view_only: true +} +consoles { + id: "try" + name: "libyuv Try Builders" + builders { + name: "buildbucket/luci.libyuv.try/android" + } + builders { + name: "buildbucket/luci.libyuv.try/android_arm64" + } + builders { + name: "buildbucket/luci.libyuv.try/android_rel" + } + builders { + name: "buildbucket/luci.libyuv.try/android_x64" + } + builders { + name: "buildbucket/luci.libyuv.try/android_x86" + } + builders { + name: "buildbucket/luci.libyuv.try/ios_arm64" + } + builders { + name: "buildbucket/luci.libyuv.try/ios_arm64_rel" + } + builders { + name: "buildbucket/luci.libyuv.try/linux" + } + builders { + name: "buildbucket/luci.libyuv.try/linux_asan" + } + builders { + name: "buildbucket/luci.libyuv.try/linux_gcc" + } + builders { + name: "buildbucket/luci.libyuv.try/linux_msan" + } + builders { + name: "buildbucket/luci.libyuv.try/linux_rel" + } + builders { + name: "buildbucket/luci.libyuv.try/linux_tsan2" + } + builders { + name: "buildbucket/luci.libyuv.try/linux_ubsan" + } + builders { + name: "buildbucket/luci.libyuv.try/linux_ubsan_vptr" + } + builders { + name: "buildbucket/luci.libyuv.try/mac" + } + builders { + name: "buildbucket/luci.libyuv.try/mac_asan" + } + builders { + name: "buildbucket/luci.libyuv.try/mac_rel" + } + builders { + name: "buildbucket/luci.libyuv.try/win" + } + builders { + name: "buildbucket/luci.libyuv.try/win_clang" + } + builders { + name: "buildbucket/luci.libyuv.try/win_clang_rel" + } + builders { + name: "buildbucket/luci.libyuv.try/win_rel" + } + builders { + name: "buildbucket/luci.libyuv.try/win_x64_clang_rel" + } + builders { + name: "buildbucket/luci.libyuv.try/win_x64_rel" + } + builder_view_only: true +} +logo_url: "https://storage.googleapis.com/chrome-infra-public/logo/libyuv-logo.png" diff --git a/libs/libyuv/infra/config/luci-scheduler.cfg b/libs/libyuv/infra/config/luci-scheduler.cfg new file mode 100644 index 0000000000..33bd6a7d24 --- /dev/null +++ b/libs/libyuv/infra/config/luci-scheduler.cfg @@ -0,0 +1,385 @@ +# Auto-generated by lucicfg. +# Do not modify manually. +# +# For the schema of this file, see ProjectConfig message: +# https://config.luci.app/schemas/projects:luci-scheduler.cfg + +job { + id: "Android ARM64 Debug" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Android ARM64 Debug" + } +} +job { + id: "Android Debug" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Android Debug" + } +} +job { + id: "Android Release" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Android Release" + } +} +job { + id: "Android Tester ARM32 Debug (Nexus 5X)" + realm: "ci" + acls { + role: TRIGGERER + granted_to: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Android Tester ARM32 Debug (Nexus 5X)" + } +} +job { + id: "Android Tester ARM32 Release (Nexus 5X)" + realm: "ci" + acls { + role: TRIGGERER + granted_to: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Android Tester ARM32 Release (Nexus 5X)" + } +} +job { + id: "Android Tester ARM64 Debug (Nexus 5X)" + realm: "ci" + acls { + role: TRIGGERER + granted_to: "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Android Tester ARM64 Debug (Nexus 5X)" + } +} +job { + id: "Android32 x86 Debug" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Android32 x86 Debug" + } +} +job { + id: "Android64 x64 Debug" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Android64 x64 Debug" + } +} +job { + id: "DEPS Autoroller" + realm: "cron" + schedule: "0 14 * * *" + acl_sets: "cron" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "cron" + builder: "DEPS Autoroller" + } +} +job { + id: "Linux Asan" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Linux Asan" + } +} +job { + id: "Linux MSan" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Linux MSan" + } +} +job { + id: "Linux Tsan v2" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Linux Tsan v2" + } +} +job { + id: "Linux UBSan" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Linux UBSan" + } +} +job { + id: "Linux UBSan vptr" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Linux UBSan vptr" + } +} +job { + id: "Linux32 Debug" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Linux32 Debug" + } +} +job { + id: "Linux32 Release" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Linux32 Release" + } +} +job { + id: "Linux64 Debug" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Linux64 Debug" + } +} +job { + id: "Linux64 Release" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Linux64 Release" + } +} +job { + id: "Mac Asan" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Mac Asan" + } +} +job { + id: "Mac64 Debug" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Mac64 Debug" + } +} +job { + id: "Mac64 Release" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Mac64 Release" + } +} +job { + id: "Win32 Debug" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Win32 Debug" + } +} +job { + id: "Win32 Debug (Clang)" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Win32 Debug (Clang)" + } +} +job { + id: "Win32 Release" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Win32 Release" + } +} +job { + id: "Win32 Release (Clang)" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Win32 Release (Clang)" + } +} +job { + id: "Win64 Debug" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Win64 Debug" + } +} +job { + id: "Win64 Debug (Clang)" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Win64 Debug (Clang)" + } +} +job { + id: "Win64 Release" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Win64 Release" + } +} +job { + id: "Win64 Release (Clang)" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "Win64 Release (Clang)" + } +} +job { + id: "iOS ARM64 Debug" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "iOS ARM64 Debug" + } +} +job { + id: "iOS ARM64 Release" + realm: "ci" + acl_sets: "ci" + buildbucket { + server: "cr-buildbucket.appspot.com" + bucket: "ci" + builder: "iOS ARM64 Release" + } +} +trigger { + id: "master-gitiles-trigger" + realm: "ci" + acl_sets: "ci" + triggers: "Android ARM64 Debug" + triggers: "Android Debug" + triggers: "Android Release" + triggers: "Android32 x86 Debug" + triggers: "Android64 x64 Debug" + triggers: "Linux Asan" + triggers: "Linux MSan" + triggers: "Linux Tsan v2" + triggers: "Linux UBSan" + triggers: "Linux UBSan vptr" + triggers: "Linux32 Debug" + triggers: "Linux32 Release" + triggers: "Linux64 Debug" + triggers: "Linux64 Release" + triggers: "Mac Asan" + triggers: "Mac64 Debug" + triggers: "Mac64 Release" + triggers: "Win32 Debug" + triggers: "Win32 Debug (Clang)" + triggers: "Win32 Release" + triggers: "Win32 Release (Clang)" + triggers: "Win64 Debug" + triggers: "Win64 Debug (Clang)" + triggers: "Win64 Release" + triggers: "Win64 Release (Clang)" + triggers: "iOS ARM64 Debug" + triggers: "iOS ARM64 Release" + gitiles { + repo: "https://chromium.googlesource.com/libyuv/libyuv" + refs: "regexp:refs/heads/main" + } +} +acl_sets { + name: "ci" + acls { + role: OWNER + granted_to: "group:project-libyuv-admins" + } + acls { + granted_to: "group:all" + } +} +acl_sets { + name: "cron" + acls { + role: OWNER + granted_to: "group:project-libyuv-admins" + } + acls { + granted_to: "group:all" + } +} diff --git a/libs/libyuv/infra/config/main.star b/libs/libyuv/infra/config/main.star new file mode 100755 index 0000000000..e1634bb938 --- /dev/null +++ b/libs/libyuv/infra/config/main.star @@ -0,0 +1,399 @@ +#!/usr/bin/env lucicfg +# https://chromium.googlesource.com/infra/luci/luci-go/+/master/lucicfg/doc/ + +"""LUCI project configuration for libyuv CQ and CI.""" + +lucicfg.check_version("1.30.9") + +LIBYUV_GIT = "https://chromium.googlesource.com/libyuv/libyuv" +LIBYUV_GERRIT = "https://chromium-review.googlesource.com/libyuv/libyuv" + +RBE_PROJECT = { + "ci": "rbe-webrtc-trusted", + "try": "rbe-webrtc-untrusted", +} + +# Use LUCI Scheduler BBv2 names and add Scheduler realms configs. +lucicfg.enable_experiment("crbug.com/1182002") + +lucicfg.config( + lint_checks = ["default"], + config_dir = ".", + tracked_files = [ + "commit-queue.cfg", + "cr-buildbucket.cfg", + "luci-logdog.cfg", + "luci-milo.cfg", + "luci-scheduler.cfg", + "project.cfg", + "realms.cfg", + ], +) + +# Generates project.cfg + +luci.project( + name = "libyuv", + buildbucket = "cr-buildbucket.appspot.com", + logdog = "luci-logdog.appspot.com", + milo = "luci-milo.appspot.com", + notify = "luci-notify.appspot.com", + scheduler = "luci-scheduler.appspot.com", + swarming = "chromium-swarm.appspot.com", + acls = [ + acl.entry(acl.PROJECT_CONFIGS_READER, groups = ["all"]), + acl.entry(acl.LOGDOG_READER, groups = ["all"]), + acl.entry(acl.LOGDOG_WRITER, groups = ["luci-logdog-chromium-writers"]), + acl.entry(acl.SCHEDULER_READER, groups = ["all"]), + acl.entry(acl.SCHEDULER_OWNER, groups = ["project-libyuv-admins"]), + acl.entry(acl.BUILDBUCKET_READER, groups = ["all"]), + acl.entry(acl.BUILDBUCKET_OWNER, groups = ["project-libyuv-admins"]), + ], + bindings = [ + luci.binding( + roles = "role/swarming.taskTriggerer", # for LED tasks. + groups = "project-libyuv-admins", + ), + luci.binding( + roles = "role/configs.validator", + users = "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com", + ), + ], +) + +# Generates luci-logdog.cfg + +luci.logdog( + gs_bucket = "chromium-luci-logdog", +) + +# Generates luci-scheduler.cfg + +luci.gitiles_poller( + name = "master-gitiles-trigger", + bucket = "ci", + repo = LIBYUV_GIT, +) + +# Generates luci-milo.cfg + +luci.milo( + logo = "https://storage.googleapis.com/chrome-infra-public/logo/libyuv-logo.png", +) + +def libyuv_ci_view(name, category, short_name): + return luci.console_view_entry( + console_view = "main", + builder = name, + category = category, + short_name = short_name, + ) + +def libyuv_try_view(name): + return luci.list_view_entry( + list_view = "try", + builder = name, + ) + +luci.console_view( + name = "main", + title = "libyuv Main Console", + include_experimental_builds = True, + repo = LIBYUV_GIT, +) + +luci.list_view( + name = "cron", + title = "Cron", + entries = ["DEPS Autoroller"], +) + +luci.list_view( + name = "try", + title = "libyuv Try Builders", +) + +# Generates commit-queue.cfg + +def libyuv_try_job_verifier(name, cq_group, experiment_percentage): + return luci.cq_tryjob_verifier( + builder = name, + cq_group = cq_group, + experiment_percentage = experiment_percentage, + ) + +luci.cq( + status_host = "chromium-cq-status.appspot.com", + submit_max_burst = 4, + submit_burst_delay = 8 * time.minute, +) + +luci.cq_group( + name = "master", + watch = [ + cq.refset( + repo = LIBYUV_GERRIT, + refs = ["refs/heads/main", "refs/heads/master"], + ), + ], + acls = [ + acl.entry(acl.CQ_COMMITTER, groups = ["project-libyuv-committers"]), + acl.entry(acl.CQ_DRY_RUNNER, groups = ["project-libyuv-tryjob-access"]), + ], + retry_config = cq.RETRY_ALL_FAILURES, + cancel_stale_tryjobs = True, +) + +luci.cq_group( + name = "config", + watch = [ + cq.refset( + repo = LIBYUV_GERRIT, + refs = ["refs/heads/infra/config"], + ), + ], + acls = [ + acl.entry(acl.CQ_COMMITTER, groups = ["project-libyuv-committers"]), + acl.entry(acl.CQ_DRY_RUNNER, groups = ["project-libyuv-tryjob-access"]), + ], + retry_config = cq.RETRY_ALL_FAILURES, + cancel_stale_tryjobs = True, +) + +# Generates cr-buildbucket.cfg + +luci.bucket( + name = "ci", + constraints = luci.bucket_constraints( + pools = ["luci.flex.ci"], + ), +) +luci.bucket( + name = "ci.shadow", + shadows = "ci", + constraints = luci.bucket_constraints( + pools = ["luci.flex.ci"], + service_accounts = [ + "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com", + ], + ), + bindings = [ + # For led permissions. + luci.binding( + roles = "role/buildbucket.creator", + groups = [ + "chromium-led-users", + "mdb/chrome-build-access-sphinx", + "mdb/chrome-troopers", + "mdb/foundry-x-team", + ], + ), + ], + dynamic = True, +) +luci.bucket( + name = "try", + acls = [ + acl.entry(acl.BUILDBUCKET_TRIGGERER, groups = [ + "project-libyuv-tryjob-access", + "service-account-cq", + ]), + ], + constraints = luci.bucket_constraints( + pools = ["luci.flex.try"], + service_accounts = [ + "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com", + ], + ), +) +luci.bucket( + name = "try.shadow", + shadows = "try", + constraints = luci.bucket_constraints( + pools = ["luci.flex.try"], + service_accounts = [ + "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com", + ], + ), + bindings = [ + # For led permissions. + luci.binding( + roles = "role/buildbucket.creator", + groups = [ + "chromium-led-users", + "mdb/chrome-build-access-sphinx", + "mdb/chrome-troopers", + "mdb/foundry-x-team", + ], + ), + ], + dynamic = True, +) +luci.bucket( + name = "cron", +) + +def get_os_dimensions(os): + if os == "android": + return {"device_type": "walleye"} + if os == "ios" or os == "mac": + return {"os": "Mac-15", "cpu": "arm64"} + elif os == "win": + return {"os": "Windows-10", "cores": "8", "cpu": "x86-64"} + elif os == "linux": + return {"os": "Ubuntu-24.04", "cores": "8", "cpu": "x86-64"} + return {} + +def libyuv_ci_builder(name, dimensions, properties, triggered_by): + return luci.builder( + name = name, + dimensions = dimensions, + properties = properties, + bucket = "ci", + service_account = "libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com", + triggered_by = triggered_by, + swarming_tags = ["vpython:native-python-wrapper"], + execution_timeout = 180 * time.minute, + build_numbers = True, + executable = luci.recipe( + name = "libyuv/libyuv", + cipd_package = "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build", + ), + ) + +def libyuv_try_builder(name, dimensions, properties, recipe_name = "libyuv/libyuv"): + return luci.builder( + name = name, + dimensions = dimensions, + properties = properties, + bucket = "try", + service_account = "libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com", + swarming_tags = ["vpython:native-python-wrapper"], + execution_timeout = 180 * time.minute, + build_numbers = True, + executable = luci.recipe( + name = recipe_name, + cipd_package = "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build", + ), + ) + +def get_build_properties(bucket): + rbe_project = RBE_PROJECT.get(bucket) + return { + "$build/siso": { + "project": rbe_project, + "configs": ["builder"], + "enable_cloud_profiler": True, + "enable_cloud_trace": True, + "enable_monitoring": True, + }, + } + +def ci_builder(name, os, category, short_name = None): + dimensions = get_os_dimensions(os) + properties = get_build_properties("ci") + + dimensions["pool"] = "luci.flex.ci" + properties["builder_group"] = "client.libyuv" + + triggered_by = ["master-gitiles-trigger" if os != "android" else "Android Debug"] + libyuv_ci_view(name, category, short_name) + return libyuv_ci_builder(name, dimensions, properties, triggered_by) + +def try_builder(name, os, experiment_percentage = None): + dimensions = get_os_dimensions(os) + properties = get_build_properties("try") + + dimensions["pool"] = "luci.flex.try" + properties["builder_group"] = "tryserver.libyuv" + + if name == "presubmit": + recipe_name = "run_presubmit" + properties["repo_name"] = "libyuv" + properties["runhooks"] = True + libyuv_try_job_verifier(name, "config", experiment_percentage) + return libyuv_try_builder(name, dimensions, properties, recipe_name) + + libyuv_try_job_verifier(name, "master", experiment_percentage) + libyuv_try_view(name) + return libyuv_try_builder(name, dimensions, properties) + +luci.builder( + name = "DEPS Autoroller", + bucket = "cron", + service_account = "libyuv-ci-autoroll-builder@chops-service-accounts.iam.gserviceaccount.com", + dimensions = { + "pool": "luci.webrtc.cron", + "os": "Linux", + "cpu": "x86-64", + }, + swarming_tags = ["vpython:native-python-wrapper"], + execution_timeout = 120 * time.minute, + build_numbers = True, + schedule = "0 14 * * *", # Every 2 hours. + executable = luci.recipe( + name = "libyuv/roll_deps", + cipd_package = "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build", + ), +) + +ci_builder("Android ARM64 Debug", "linux", "Android|Builder", "dbg") +ci_builder("Android Debug", "linux", "Android|Builder", "dbg") +ci_builder("Android Release", "linux", "Android|Builder", "rel") +ci_builder("Android32 x86 Debug", "linux", "Android|Builder|x86", "dbg") +ci_builder("Android64 x64 Debug", "linux", "Android|Builder|x64", "dbg") +ci_builder("Android Tester ARM32 Debug (Nexus 5X)", "android", "Android|Tester|ARM 32", "dbg") +ci_builder("Android Tester ARM32 Release (Nexus 5X)", "android", "Android|Tester|ARM 32", "rel") +ci_builder("Android Tester ARM64 Debug (Nexus 5X)", "android", "Android|Tester|ARM 64", "dbg") +ci_builder("Linux Asan", "linux", "Linux", "asan") +ci_builder("Linux MSan", "linux", "Linux", "msan") +ci_builder("Linux Tsan v2", "linux", "Linux", "tsan") +ci_builder("Linux UBSan", "linux", "Linux|UBSan") +ci_builder("Linux UBSan vptr", "linux", "Linux|UBSan", "vptr") +ci_builder("Linux32 Debug", "linux", "Linux|32", "dbg") +ci_builder("Linux32 Release", "linux", "Linux|32", "rel") +ci_builder("Linux64 Debug", "linux", "Linux|64", "dbg") +ci_builder("Linux64 Release", "linux", "Linux|64", "rel") +ci_builder("Mac Asan", "mac", "Mac", "asan") +ci_builder("Mac64 Debug", "mac", "Mac", "dbg") +ci_builder("Mac64 Release", "mac", "Mac", "rel") +ci_builder("Win32 Debug", "win", "Win|32|Debug") +ci_builder("Win32 Debug (Clang)", "win", "Win|32|Debug", "clg") +ci_builder("Win32 Release", "win", "Win|32|Release") +ci_builder("Win32 Release (Clang)", "win", "Win|32|Release", "clg") +ci_builder("Win64 Debug", "win", "Win|64|Debug", "clg") +ci_builder("Win64 Debug (Clang)", "win", "Win|64|Debug", "clg") +ci_builder("Win64 Release", "win", "Win|64|Release") +ci_builder("Win64 Release (Clang)", "win", "Win|64|Release", "clg") +ci_builder("iOS ARM64 Debug", "ios", "iOS|ARM64", "dbg") +ci_builder("iOS ARM64 Release", "ios", "iOS|ARM64", "rel") + +# TODO(crbug.com/1242847): make this not experimental. +try_builder("android", "android", experiment_percentage = 100) +try_builder("android_arm64", "android", experiment_percentage = 100) +try_builder("android_rel", "android", experiment_percentage = 100) + +try_builder("android_x64", "linux") +try_builder("android_x86", "linux") +try_builder("ios_arm64", "ios") +try_builder("ios_arm64_rel", "ios") +try_builder("linux", "linux") +try_builder("linux_asan", "linux") +try_builder("linux_gcc", "linux", experiment_percentage = 100) + +# TODO(libyuv:388428508): Make linux_msan not experimental. +try_builder("linux_msan", "linux", experiment_percentage = 100) +try_builder("linux_rel", "linux") +try_builder("linux_tsan2", "linux") +try_builder("linux_ubsan", "linux") +try_builder("linux_ubsan_vptr", "linux") +try_builder("mac", "mac") +try_builder("mac_asan", "mac") +try_builder("mac_rel", "mac") +try_builder("win", "win") +try_builder("win_clang", "win") +try_builder("win_clang_rel", "win") +try_builder("win_rel", "win") +try_builder("win_x64_clang_rel", "win") +try_builder("win_x64_rel", "win") +try_builder("presubmit", "linux") diff --git a/libs/libyuv/infra/config/project.cfg b/libs/libyuv/infra/config/project.cfg new file mode 100644 index 0000000000..312b39ef85 --- /dev/null +++ b/libs/libyuv/infra/config/project.cfg @@ -0,0 +1,15 @@ +# Auto-generated by lucicfg. +# Do not modify manually. +# +# For the schema of this file, see ProjectCfg message: +# https://config.luci.app/schemas/projects:project.cfg + +name: "libyuv" +access: "group:all" +lucicfg { + version: "1.46.1" + package_dir: "." + config_dir: "." + entry_point: "main.star" + experiments: "crbug.com/1182002" +} diff --git a/libs/libyuv/infra/config/realms.cfg b/libs/libyuv/infra/config/realms.cfg new file mode 100644 index 0000000000..b4bae90ea0 --- /dev/null +++ b/libs/libyuv/infra/config/realms.cfg @@ -0,0 +1,111 @@ +# Auto-generated by lucicfg. +# Do not modify manually. +# +# For the schema of this file, see RealmsCfg message: +# https://config.luci.app/schemas/projects:realms.cfg + +realms { + name: "@root" + bindings { + role: "role/buildbucket.owner" + principals: "group:project-libyuv-admins" + } + bindings { + role: "role/buildbucket.reader" + principals: "group:all" + } + bindings { + role: "role/configs.reader" + principals: "group:all" + } + bindings { + role: "role/configs.validator" + principals: "user:libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + bindings { + role: "role/logdog.reader" + principals: "group:all" + } + bindings { + role: "role/logdog.writer" + principals: "group:luci-logdog-chromium-writers" + } + bindings { + role: "role/scheduler.owner" + principals: "group:project-libyuv-admins" + } + bindings { + role: "role/scheduler.reader" + principals: "group:all" + } + bindings { + role: "role/swarming.taskTriggerer" + principals: "group:project-libyuv-admins" + } +} +realms { + name: "ci" + bindings { + role: "role/buildbucket.builderServiceAccount" + principals: "user:libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + bindings { + role: "role/scheduler.triggerer" + principals: "user:libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + conditions { + restrict { + attribute: "scheduler.job.name" + values: "Android Tester ARM32 Debug (Nexus 5X)" + values: "Android Tester ARM32 Release (Nexus 5X)" + values: "Android Tester ARM64 Debug (Nexus 5X)" + } + } + } +} +realms { + name: "ci.shadow" + bindings { + role: "role/buildbucket.builderServiceAccount" + principals: "user:libyuv-ci-builder@chops-service-accounts.iam.gserviceaccount.com" + } + bindings { + role: "role/buildbucket.creator" + principals: "group:chromium-led-users" + principals: "group:mdb/chrome-build-access-sphinx" + principals: "group:mdb/chrome-troopers" + principals: "group:mdb/foundry-x-team" + } +} +realms { + name: "cron" + bindings { + role: "role/buildbucket.builderServiceAccount" + principals: "user:libyuv-ci-autoroll-builder@chops-service-accounts.iam.gserviceaccount.com" + } +} +realms { + name: "try" + bindings { + role: "role/buildbucket.builderServiceAccount" + principals: "user:libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + bindings { + role: "role/buildbucket.triggerer" + principals: "group:project-libyuv-tryjob-access" + principals: "group:service-account-cq" + } +} +realms { + name: "try.shadow" + bindings { + role: "role/buildbucket.builderServiceAccount" + principals: "user:libyuv-try-builder@chops-service-accounts.iam.gserviceaccount.com" + } + bindings { + role: "role/buildbucket.creator" + principals: "group:chromium-led-users" + principals: "group:mdb/chrome-build-access-sphinx" + principals: "group:mdb/chrome-troopers" + principals: "group:mdb/foundry-x-team" + } +} diff --git a/libs/libyuv/libyuv.bzl b/libs/libyuv/libyuv.bzl new file mode 100644 index 0000000000..1e910687f8 --- /dev/null +++ b/libs/libyuv/libyuv.bzl @@ -0,0 +1,50 @@ +# Copyright 2026 The LibYuv Project Authors. All rights reserved. +# +# Shared target definitions for Bazel and Blaze builds. + +def libyuv_srcs(prefix = ""): + return native.glob( + [ + prefix + "source/*.cc", + prefix + "include/libyuv/*.h", + ], + exclude = [ + prefix + "source/*neon*.cc", + prefix + "source/*rvv*.cc", + prefix + "source/*sve*.cc", + prefix + "source/*sme*.cc", + ], + ) + +def libyuv_hdrs(prefix = ""): + return [ + prefix + "include/libyuv/compare.h", + prefix + "include/libyuv/convert.h", + prefix + "include/libyuv/convert_from_argb.h", + prefix + "include/libyuv/cpu_id.h", + prefix + "include/libyuv/row.h", # Bug 553148013: Should be private. + ] + +def libyuv_neon_srcs(prefix = ""): + return native.glob([ + prefix + "source/*neon*.cc", + prefix + "include/libyuv/*.h", + ]) + +def libyuv_rvv_srcs(prefix = ""): + return native.glob([ + prefix + "source/*rvv*.cc", + prefix + "include/libyuv/*.h", + ]) + +def libyuv_sve_srcs(prefix = ""): + return native.glob([ + prefix + "source/*sve*.cc", + prefix + "include/libyuv/*.h", + ]) + +def libyuv_test_srcs(prefix = ""): + return native.glob([ + prefix + "unit_test/*.cc", + prefix + "unit_test/*.h", + ]) diff --git a/libs/libyuv/libyuv.gni b/libs/libyuv/libyuv.gni index 8df40ba2d7..23e38c1b40 100644 --- a/libs/libyuv/libyuv.gni +++ b/libs/libyuv/libyuv.gni @@ -6,18 +6,29 @@ # in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. -import("//build_overrides/build.gni") import("//build/config/arm.gni") +import("//build/config/loongarch64.gni") import("//build/config/mips.gni") +import("//build_overrides/build.gni") declare_args() { libyuv_include_tests = !build_with_chromium libyuv_disable_jpeg = false - libyuv_use_neon = - current_cpu == "arm64" || - (current_cpu == "arm" && (arm_use_neon || arm_optionally_use_neon)) + libyuv_disable_rvv = false + libyuv_enable_rowwin = false + libyuv_use_neon = current_cpu == "arm64" || current_cpu == "arm" + libyuv_use_sve = current_cpu == "arm64" + + # Restrict to (is_linux || is_android) to work around undefined symbol linker + # errors on Fuchsia, macOS, and compilation errors on Windows. + # TODO: bug 359006069 - Remove the restriction after the linker and + # compilation errors are fixed. + libyuv_use_sme = current_cpu == "arm64" && (is_linux || is_android) libyuv_use_msa = (current_cpu == "mips64el" || current_cpu == "mipsel") && mips_use_msa libyuv_use_mmi = (current_cpu == "mips64el" || current_cpu == "mipsel") && mips_use_mmi + libyuv_use_lsx = current_cpu == "loong64" && loongarch64_use_lsx + libyuv_use_lasx = current_cpu == "loong64" && loongarch64_use_lasx + libyuv_use_rvv = current_cpu == "riscv64" || current_cpu == "riscv32" } diff --git a/libs/libyuv/libyuv.gyp b/libs/libyuv/libyuv.gyp new file mode 100644 index 0000000000..fa4b146a43 --- /dev/null +++ b/libs/libyuv/libyuv.gyp @@ -0,0 +1,137 @@ +# Copyright 2011 The LibYuv Project Authors. All rights reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +{ + 'includes': [ + 'libyuv.gypi', + ], + # Make sure that if we are being compiled to an xcodeproj, nothing tries to + # include a .pch. + 'xcode_settings': { + 'GCC_PREFIX_HEADER': '', + 'GCC_PRECOMPILE_PREFIX_HEADER': 'NO', + }, + 'variables': { + 'use_system_libjpeg%': 0, + # Can be enabled if your jpeg has GYP support. + 'libyuv_disable_jpeg%': 1, + # 'chromium_code' treats libyuv as internal and increases warning level. + 'chromium_code': 1, + # clang compiler default variable usable by other apps that include libyuv. + 'clang%': 0, + # Link-Time Optimizations. + 'use_lto%': 0, + 'build_neon': 0, + 'conditions': [ + ['(target_arch == "armv7" or target_arch == "armv7s" or \ + (target_arch == "arm" and arm_version >= 7) or target_arch == "arm64")\ + and (arm_neon == 1 or arm_neon_optional == 1)', { + 'build_neon': 1, + }], + ], + }, + + 'targets': [ + { + 'target_name': 'libyuv', + # Change type to 'shared_library' to build .so or .dll files. + 'type': 'static_library', + 'variables': { + 'optimize': 'max', # enable O2 and ltcg. + }, + # Allows libyuv.a redistributable library without external dependencies. + 'standalone_static_library': 1, + 'conditions': [ + # Disable -Wunused-parameter + ['clang == 1', { + 'cflags': [ + '-Wno-unused-parameter', + ], + }], + ['build_neon != 0', { + 'defines': [ + 'LIBYUV_NEON', + ], + 'cflags!': [ + '-mfpu=vfp', + '-mfpu=vfpv3', + '-mfpu=vfpv3-d16', + # '-mthumb', # arm32 not thumb + ], + 'conditions': [ + # Disable LTO in libyuv_neon target due to gcc 4.9 compiler bug. + ['clang == 0 and use_lto == 1', { + 'cflags!': [ + '-flto', + '-ffat-lto-objects', + ], + }], + # arm64 does not need -mfpu=neon option as neon is not optional + ['target_arch != "arm64"', { + 'cflags': [ + '-mfpu=neon', + # '-marm', # arm32 not thumb + ], + }], + ], + }], + ['OS != "ios" and libyuv_disable_jpeg != 1', { + 'defines': [ + 'HAVE_JPEG' + ], + 'conditions': [ + # Caveat system jpeg support may not support motion jpeg + [ 'use_system_libjpeg == 1', { + 'dependencies': [ + '<(DEPTH)/third_party/libjpeg/libjpeg.gyp:libjpeg', + ], + }, { + 'dependencies': [ + '<(DEPTH)/third_party/libjpeg_turbo/libjpeg.gyp:libjpeg', + ], + }], + [ 'use_system_libjpeg == 1', { + 'link_settings': { + 'libraries': [ + '-ljpeg', + ], + } + }], + ], + }], + ], #conditions + 'defines': [ + # Enable the following 3 macros to turn off assembly for specified CPU. + # 'LIBYUV_DISABLE_X86', + # 'LIBYUV_DISABLE_NEON', + # Enable the following macro to build libyuv as a shared library (dll). + # 'LIBYUV_USING_SHARED_LIBRARY', + # TODO(fbarchard): Make these into gyp defines. + ], + 'include_dirs': [ + 'include', + '.', + ], + 'direct_dependent_settings': { + 'include_dirs': [ + 'include', + '.', + ], + }, + 'sources': [ + '<@(libyuv_sources)', + ], + }, + ], # targets. +} + +# Local Variables: +# tab-width:2 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=2 shiftwidth=2: diff --git a/libs/libyuv/libyuv.gypi b/libs/libyuv/libyuv.gypi new file mode 100644 index 0000000000..91d9ff67fb --- /dev/null +++ b/libs/libyuv/libyuv.gypi @@ -0,0 +1,96 @@ +# Copyright 2014 The LibYuv Project Authors. All rights reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +{ + 'variables': { + 'libyuv_sources': [ + # includes. + 'include/libyuv.h', + 'include/libyuv/basic_types.h', + 'include/libyuv/compare.h', + 'include/libyuv/compare_row.h', + 'include/libyuv/convert.h', + 'include/libyuv/convert_argb.h', + 'include/libyuv/convert_from.h', + 'include/libyuv/convert_from_argb.h', + 'include/libyuv/cpu_id.h', + 'include/libyuv/cpu_support.h', + 'include/libyuv/loongson_intrinsics.h', + 'include/libyuv/mjpeg_decoder.h', + 'include/libyuv/planar_functions.h', + 'include/libyuv/rotate.h', + 'include/libyuv/rotate_argb.h', + 'include/libyuv/rotate_row.h', + 'include/libyuv/row.h', + 'include/libyuv/row_sve.h', + 'include/libyuv/scale.h', + 'include/libyuv/scale_argb.h', + 'include/libyuv/scale_rgb.h', + 'include/libyuv/scale_row.h', + 'include/libyuv/scale_uv.h', + 'include/libyuv/version.h', + 'include/libyuv/video_common.h', + + # sources. + 'source/compare.cc', + 'source/compare_common.cc', + 'source/compare_gcc.cc', + 'source/compare_hvx.cc', + 'source/compare_neon.cc', + 'source/compare_neon64.cc', + 'source/compare_win.cc', + 'source/convert.cc', + 'source/convert_argb.cc', + 'source/convert_from.cc', + 'source/convert_from_argb.cc', + 'source/convert_jpeg.cc', + 'source/convert_to_argb.cc', + 'source/convert_to_i420.cc', + 'source/cpu_id.cc', + 'source/mjpeg_decoder.cc', + 'source/mjpeg_validate.cc', + 'source/planar_functions.cc', + 'source/rotate.cc', + 'source/rotate_any.cc', + 'source/rotate_argb.cc', + 'source/rotate_common.cc', + 'source/rotate_gcc.cc', + 'source/rotate_hvx.cc', + 'source/rotate_lasx.cc', + 'source/rotate_lsx.cc', + 'source/rotate_neon.cc', + 'source/rotate_neon64.cc', + 'source/rotate_rvv.cc', + 'source/rotate_win.cc', + 'source/row_any.cc', + 'source/row_common.cc', + 'source/row_gcc.cc', + 'source/row_hvx.cc', + 'source/row_lasx.cc', + 'source/row_lsx.cc', + 'source/row_neon.cc', + 'source/row_neon64.cc', + 'source/row_rvv.cc', + 'source/row_win.cc', + 'source/scale.cc', + 'source/scale_any.cc', + 'source/scale_argb.cc', + 'source/scale_common.cc', + 'source/scale_gcc.cc', + 'source/scale_hvx.cc', + 'source/scale_lsx.cc', + 'source/scale_neon.cc', + 'source/scale_neon64.cc', + 'source/scale_rgb.cc', + 'source/scale_rvv.cc', + 'source/scale_uv.cc', + 'source/scale_win.cc', + 'source/video_common.cc', + ], + } +} diff --git a/libs/libyuv/linux.mk b/libs/libyuv/linux.mk index e9a26a79b2..f4d9c73b1b 100644 --- a/libs/libyuv/linux.mk +++ b/libs/libyuv/linux.mk @@ -13,15 +13,14 @@ LOCAL_OBJ_FILES := \ source/compare.o \ source/compare_common.o \ source/compare_gcc.o \ - source/compare_mmi.o \ - source/compare_msa.o \ - source/compare_neon64.o \ + source/compare_hvx.o \ source/compare_neon.o \ + source/compare_neon64.o \ source/compare_win.o \ - source/convert_argb.o \ source/convert.o \ - source/convert_from_argb.o \ + source/convert_argb.o \ source/convert_from.o \ + source/convert_from_argb.o \ source/convert_jpeg.o \ source/convert_to_argb.o \ source/convert_to_i420.o \ @@ -29,33 +28,40 @@ LOCAL_OBJ_FILES := \ source/mjpeg_decoder.o \ source/mjpeg_validate.o \ source/planar_functions.o \ + source/rotate.o \ source/rotate_any.o \ source/rotate_argb.o \ - source/rotate.o \ source/rotate_common.o \ source/rotate_gcc.o \ - source/rotate_mmi.o \ - source/rotate_msa.o \ - source/rotate_neon64.o \ + source/rotate_hvx.o \ + source/rotate_lasx.o \ + source/rotate_lsx.o \ source/rotate_neon.o \ + source/rotate_neon64.o \ + source/rotate_rvv.o \ source/rotate_win.o \ source/row_any.o \ source/row_common.o \ source/row_gcc.o \ - source/row_mmi.o \ - source/row_msa.o \ - source/row_neon64.o \ + source/row_hvx.o \ + source/row_lasx.o \ + source/row_lsx.o \ source/row_neon.o \ + source/row_neon64.o \ + source/row_rvv.o \ source/row_win.o \ + source/scale.o \ source/scale_any.o \ source/scale_argb.o \ - source/scale.o \ source/scale_common.o \ source/scale_gcc.o \ - source/scale_mmi.o \ - source/scale_msa.o \ - source/scale_neon64.o \ + source/scale_hvx.o \ + source/scale_lsx.o \ source/scale_neon.o \ + source/scale_neon64.o \ + source/scale_rgb.o \ + source/scale_rvv.o \ + source/scale_uv.o \ source/scale_win.o \ source/video_common.o @@ -65,19 +71,31 @@ LOCAL_OBJ_FILES := \ .c.o: $(CC) -c $(CFLAGS) $*.c -o $*.o -all: libyuv.a yuvconvert cpuid psnr +all: libyuv.a i444tonv12_eg yuvconvert yuvconstants cpuid psnr compare libyuv.a: $(LOCAL_OBJ_FILES) $(AR) $(ARFLAGS) $@ $(LOCAL_OBJ_FILES) +# A C++ test utility that compares two YUV files. +compare: util/compare.cc libyuv.a + $(CXX) $(CXXFLAGS) -Iutil/ -o $@ util/compare.cc libyuv.a + # A C++ test utility that uses libyuv conversion. yuvconvert: util/yuvconvert.cc libyuv.a $(CXX) $(CXXFLAGS) -Iutil/ -o $@ util/yuvconvert.cc libyuv.a +# A C test utility that generates yuvconstants for yuv to rgb. +yuvconstants: util/yuvconstants.c libyuv.a + $(CXX) $(CXXFLAGS) -Iutil/ -lm -o $@ util/yuvconstants.c libyuv.a + # A standalone test utility psnr: util/psnr.cc $(CXX) $(CXXFLAGS) -Iutil/ -o $@ util/psnr.cc util/psnr_main.cc util/ssim.cc +# A simple conversion example. +i444tonv12_eg: util/i444tonv12_eg.cc libyuv.a + $(CXX) $(CXXFLAGS) -o $@ util/i444tonv12_eg.cc libyuv.a + # A C test utility that uses libyuv conversion from C. # gcc 4.4 and older require -fno-exceptions to avoid link error on __gxx_personality_v0 # CC=gcc-4.4 CXXFLAGS=-fno-exceptions CXX=g++-4.4 make -f linux.mk @@ -85,4 +103,4 @@ cpuid: util/cpuid.c libyuv.a $(CC) $(CFLAGS) -o $@ util/cpuid.c libyuv.a clean: - /bin/rm -f source/*.o *.ii *.s libyuv.a yuvconvert cpuid psnr + /bin/rm -f source/*.o *.ii *.s libyuv.a i444tonv12_eg yuvconvert yuvconstants cpuid psnr compare diff --git a/libs/libyuv/pylintrc b/libs/libyuv/pylintrc index b8bea33489..57be7df051 100644 --- a/libs/libyuv/pylintrc +++ b/libs/libyuv/pylintrc @@ -13,5 +13,37 @@ reports=no [FORMAT] -# We use two spaces for indents, instead of the usual four spaces or tab. -indent-string=' ' +# Maximum number of characters on a single line. +max-line-length=79 + +# We use four spaces for indents. +indent-string=' ' + +[BASIC] + +# List of builtins function names that should not be used, separated by a comma +bad-functions=map,filter,apply,input + +# Naming style matching correct module names. +module-naming-style=snake_case + +# Naming style matching correct constant names. +const-naming-style=UPPER_CASE + +# Naming style matching correct class names. +class-naming-style=PascalCase + +# Naming style matching correct function names. +function-naming-style=snake_case + +# Regular expression matching correct method names. +method-rgx=([a-z_][a-z0-9_]{2,}|setUp|tearDown)$ + +# Naming style matching correct attribute names. +attr-naming-style=snake_case + +# Naming style matching correct argument names. +argument-naming-style=snake_case + +# Naming style matching correct variable names. +variable-naming-style=snake_case diff --git a/libs/libyuv/riscv_script/prepare_toolchain_qemu.sh b/libs/libyuv/riscv_script/prepare_toolchain_qemu.sh new file mode 100755 index 0000000000..2a90173931 --- /dev/null +++ b/libs/libyuv/riscv_script/prepare_toolchain_qemu.sh @@ -0,0 +1,74 @@ +#!/bin/bash +set -ev + +# Download & build RISC-V Clang toolchain & QEMU emulator. +# RISC-V Clang is for cross compile with the RISC-V Vector ISA. +# RISC-V QEMU is used to run the test suite. +# +# Requirements: Linux host w/ working C++ compiler, git, cmake, ninja, wget, tar + +# NOTE: this script must be run from the top-level directory of the LIBYUV_SRC_DIR. + +RISCV_TRIPLE="riscv64-unknown-linux-gnu" +RISCV_QEMU="qemu-riscv64" + +LIBYUV_SRC_DIR=$(pwd) +BUILD_DIR="$LIBYUV_SRC_DIR"/build-toolchain-qemu +INSTALL_QEMU="$BUILD_DIR"/riscv-qemu +INSTALL_CLANG="$BUILD_DIR"/riscv-clang + +LLVM_VERSION="16.0.0" +LLVM_NAME=llvm-project-"$LLVM_VERSION".src + +RISCV_GNU_TOOLCHAIN="$BUILD_DIR"/riscv-gnu-toolchain +RISCV_CLANG_TOOLCHAIN="$BUILD_DIR"/"$LLVM_NAME" + +QEMU_NAME="qemu-7.0.0" + +mkdir -p "$BUILD_DIR" +cd "$BUILD_DIR" + +# Download and install RISC-V GNU Toolchain (needed to build Clang) +if [ ! -d "$RISCV_GNU_TOOLCHAIN" ] +then + git clone git@github.com:riscv/riscv-gnu-toolchain.git + pushd "$RISCV_GNU_TOOLCHAIN" + git submodule update --init --recursive + ./configure --with-cmodel=medany --prefix="$INSTALL_CLANG" + ionice nice make linux -j `nproc` install + popd +fi + +# Download Clang toolchain & build cross compiler +if [ ! -d "$RISCV_CLANG_TOOLCHAIN" ] +then + wget https://github.com/llvm/llvm-project/releases/download/llvmorg-"$LLVM_VERSION"/"$LLVM_NAME".tar.xz + tar xvJf "$LLVM_NAME".tar.xz + pushd "$RISCV_CLANG_TOOLCHAIN" + cmake -DCMAKE_INSTALL_PREFIX="$INSTALL_CLANG" \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_TARGETS_TO_BUILD="RISCV" \ + -DLLVM_ENABLE_PROJECTS="clang" \ + -DLLVM_DEFAULT_TARGET_TRIPLE="$RISCV_TRIPLE" \ + -DLLVM_INSTALL_TOOLCHAIN_ONLY=On \ + -DDEFAULT_SYSROOT=../sysroot \ + -G "Ninja" "$RISCV_CLANG_TOOLCHAIN"/llvm + ionice nice ninja -j `nproc` + ionice nice ninja -j `nproc` install + popd + pushd "$INSTALL_CLANG"/bin + ln -sf clang "$RISCV_TRIPLE"-clang + ln -sf clang++ "$RISCV_TRIPLE"-clang++ + popd +fi + +# Download QEMU and build the riscv64 Linux usermode emulator +if [ ! -d "$QEMU_NAME" ] +then + wget https://download.qemu.org/"$QEMU_NAME".tar.xz + tar xvJf "$QEMU_NAME".tar.xz + pushd "$QEMU_NAME" + ./configure --target-list=riscv64-linux-user --prefix="$INSTALL_QEMU" + ionice nice make -j `nproc` install + popd +fi diff --git a/libs/libyuv/riscv_script/riscv-clang.cmake b/libs/libyuv/riscv_script/riscv-clang.cmake new file mode 100644 index 0000000000..41d23a5c37 --- /dev/null +++ b/libs/libyuv/riscv_script/riscv-clang.cmake @@ -0,0 +1,56 @@ +set(CMAKE_CROSSCOMPILING TRUE) +set(CMAKE_SYSTEM_NAME "Linux") +set(CMAKE_SYSTEM_PROCESSOR "riscv64") + +option(USE_RVV "Enable riscv vector or not." ON) +option(USE_AUTO_VECTORIZER "Enable riscv auto vectorizer or not." OFF) + +# Avoid to use system path for cross-compile +set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE) + +set(TOOLCHAIN_PATH "" CACHE STRING "The toolcahin path.") +if(NOT TOOLCHAIN_PATH) + set(TOOLCHAIN_PATH ${CMAKE_SOURCE_DIR}/build-toolchain-qemu/riscv-clang) +endif() + +set(TOOLCHAIN_PREFIX "riscv64-unknown-linux-gnu-" CACHE STRING "The toolcahin prefix.") + +# toolchain setting +set(CMAKE_C_COMPILER "${TOOLCHAIN_PATH}/bin/${TOOLCHAIN_PREFIX}clang") +set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PATH}/bin/${TOOLCHAIN_PREFIX}clang++") + +# CMake will just use the host-side tools for the following tools, so we setup them here. +set(CMAKE_C_COMPILER_AR "${TOOLCHAIN_PATH}/bin/llvm-ar") +set(CMAKE_CXX_COMPILER_AR "${TOOLCHAIN_PATH}/bin/llvm-ar") +set(CMAKE_C_COMPILER_RANLIB "${TOOLCHAIN_PATH}/bin/llvm-ranlib") +set(CMAKE_CXX_COMPILER_RANLIB "${TOOLCHAIN_PATH}/bin/llvm-ranlib") +set(CMAKE_OBJDUMP "${TOOLCHAIN_PATH}/bin/llvm-objdump") +set(CMAKE_OBJCOPY "${TOOLCHAIN_PATH}/bin/llvm-objcopy") + +# compile options +set(RISCV_COMPILER_FLAGS "" CACHE STRING "Compile flags") +# if user provides RISCV_COMPILER_FLAGS, appeding compile flags is avoided. +if(RISCV_COMPILER_FLAGS STREQUAL "") + message(STATUS "USE_RVV: ${USE_RVV}") + message(STATUS "USE_AUTO_VECTORIZER: ${USE_AUTO_VECTORIZER}") + if(USE_RVV) + list(APPEND RISCV_COMPILER_FLAGS "-march=rv64gcv") + if(NOT USE_AUTO_VECTORIZER) + # Disable auto-vectorizer + add_compile_options(-fno-tree-vectorize -fno-tree-slp-vectorize) + endif() + else() + list(APPEND RISCV_COMPILER_FLAGS "-march=rv64gc") + endif() +endif() +add_compile_options("-Wuninitialized") +message(STATUS "RISCV_COMPILER_FLAGS: ${RISCV_COMPILER_FLAGS}") + +set(CMAKE_C_FLAGS "${RISCV_COMPILER_FLAGS} ${CMAKE_C_FLAGS}") +set(CMAKE_CXX_FLAGS "${RISCV_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}") + +set(RISCV_LINKER_FLAGS "-lstdc++ -lpthread -lm -ldl") +set(RISCV_LINKER_FLAGS_EXE) +set(CMAKE_SHARED_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}") +set(CMAKE_MODULE_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}") +set(CMAKE_EXE_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${RISCV_LINKER_FLAGS_EXE} ${CMAKE_EXE_LINKER_FLAGS}") diff --git a/libs/libyuv/riscv_script/run_qemu.sh b/libs/libyuv/riscv_script/run_qemu.sh new file mode 100755 index 0000000000..080af3b19d --- /dev/null +++ b/libs/libyuv/riscv_script/run_qemu.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -x +set -e + +USE_RVV="${USE_RVV:-OFF}" +TOOLCHAIN_PATH="${TOOLCHAIN_PATH:-../../build-toolchain-qemu/riscv-clang}" +QEMU_PREFIX_PATH="${QEMU_PREFIX_PATH:-../../build-toolchain-qemu/riscv-qemu/}" + +if [ "${USE_RVV}" = "ON" ];then + QEMU_OPTION="-cpu rv64,zba=true,zbb=true,zbc=true,zbs=true,v=true,vlen=512,elen=64,vext_spec=v1.0 -L ${TOOLCHAIN_PATH}/sysroot" +else + QEMU_OPTION="-cpu rv64,zba=true,zbb=true,zbc=true,zbs=true -L ${TOOLCHAIN_PATH}/sysroot" +fi + +$QEMU_PREFIX_PATH/bin/qemu-riscv64 $QEMU_OPTION $@ diff --git a/libs/libyuv/source/compare.cc b/libs/libyuv/source/compare.cc index 7f4828104f..12c5738966 100644 --- a/libs/libyuv/source/compare.cc +++ b/libs/libyuv/source/compare.cc @@ -11,12 +11,13 @@ #include "libyuv/compare.h" #include +#include #include +#include #ifdef _OPENMP #include #endif -#include "libyuv/basic_types.h" #include "libyuv/compare_row.h" #include "libyuv/cpu_id.h" #include "libyuv/row.h" @@ -31,6 +32,7 @@ extern "C" { LIBYUV_API uint32_t HashDjb2(const uint8_t* src, uint64_t count, uint32_t seed) { const int kBlockSize = 1 << 15; // 32768; + int simd_size = 16; // SIMD for multiple of 16, and C for remainder. int remainder; uint32_t (*HashDjb2_SSE)(const uint8_t* src, int count, uint32_t seed) = HashDjb2_C; @@ -42,55 +44,78 @@ uint32_t HashDjb2(const uint8_t* src, uint64_t count, uint32_t seed) { #if defined(HAS_HASHDJB2_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { HashDjb2_SSE = HashDjb2_AVX2; + simd_size = 32; + } +#endif +#if defined(HAS_HASHDJB2_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + HashDjb2_SSE = HashDjb2_NEON; + } +#endif +#if defined(HAS_HASHDJB2_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + HashDjb2_SSE = HashDjb2_AVX512BW; + simd_size = 1; // Any count. + } +#endif +#if defined(HAS_HASHDJB2_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + HashDjb2_SSE = HashDjb2_RVV; + simd_size = 1; // Any count. + } +#endif +#if defined(HAS_HASHDJB2_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + HashDjb2_SSE = HashDjb2_LSX; + } +#endif +#if defined(HAS_HASHDJB2_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + HashDjb2_SSE = HashDjb2_LASX; + } +#endif +#if defined(HAS_HASHDJB2_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + HashDjb2_SSE = HashDjb2_WASMSIMD; + } +#endif +#if defined(HAS_HASHDJB2_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + HashDjb2_SSE = HashDjb2_HVX; + simd_size = 1; // Any count. } #endif - while (count >= (uint64_t)(kBlockSize)) { + while (count >= (uint64_t)kBlockSize) { seed = HashDjb2_SSE(src, kBlockSize, seed); src += kBlockSize; count -= kBlockSize; } - remainder = (int)count & ~15; + remainder = (int)count & ~(simd_size - 1); if (remainder) { seed = HashDjb2_SSE(src, remainder, seed); src += remainder; count -= remainder; } - remainder = (int)count & 15; + remainder = (int)count & (simd_size - 1); if (remainder) { - seed = HashDjb2_C(src, remainder, seed); + if (HashDjb2_SSE == HashDjb2_C) { + seed = HashDjb2_C(src, remainder, seed); + } else { + SIMD_ALIGNED(uint8_t buf[32]); + uint32_t pow33 = 1; + int i; + memset(buf, 0, sizeof(buf)); + for (i = 0; i < remainder; ++i) { + pow33 *= 33; + } + memcpy(buf + simd_size - remainder, src, remainder); + seed = seed * pow33 + HashDjb2_SSE(buf, simd_size, 0); + } } return seed; } -static uint32_t ARGBDetectRow_C(const uint8_t* argb, int width) { - int x; - for (x = 0; x < width - 1; x += 2) { - if (argb[0] != 255) { // First byte is not Alpha of 255, so not ARGB. - return FOURCC_BGRA; - } - if (argb[3] != 255) { // Fourth byte is not Alpha of 255, so not BGRA. - return FOURCC_ARGB; - } - if (argb[4] != 255) { // Second pixel first byte is not Alpha of 255. - return FOURCC_BGRA; - } - if (argb[7] != 255) { // Second pixel fourth byte is not Alpha of 255. - return FOURCC_ARGB; - } - argb += 8; - } - if (width & 1) { - if (argb[0] != 255) { // First byte is not Alpha of 255, so not ARGB. - return FOURCC_BGRA; - } - if (argb[3] != 255) { // 4th byte is not Alpha of 255, so not BGRA. - return FOURCC_ARGB; - } - } - return 0; -} - // Scan an opaque argb image and return fourcc based on alpha offset. // Returns FOURCC_ARGB, FOURCC_BGRA, or 0 if unknown. LIBYUV_API @@ -98,17 +123,56 @@ uint32_t ARGBDetect(const uint8_t* argb, int stride_argb, int width, int height) { + uint32_t (*ARGBDetectRow)(const uint8_t* argb, int width) = ARGBDetectRow_C; uint32_t fourcc = 0; int h; + if (!argb || width <= 0 || height <= 0) { + return fourcc; + } // Coalesce rows. - if (stride_argb == width * 4) { + if (stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; stride_argb = 0; } +#if defined(HAS_ARGBDETECTROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBDetectRow = ARGBDetectRow_AVX2; + } +#endif +#if defined(HAS_ARGBDETECTROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBDetectRow = ARGBDetectRow_NEON; + } +#endif +#if defined(HAS_ARGBDETECTROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBDetectRow = ARGBDetectRow_RVV; + } +#endif +#if defined(HAS_ARGBDETECTROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBDetectRow = ARGBDetectRow_LSX; + } +#endif +#if defined(HAS_ARGBDETECTROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBDetectRow = ARGBDetectRow_LASX; + } +#endif +#if defined(HAS_ARGBDETECTROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBDetectRow = ARGBDetectRow_WASMSIMD; + } +#endif +#if defined(HAS_ARGBDETECTROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBDetectRow = ARGBDetectRow_HVX; + } +#endif for (h = 0; h < height && fourcc == 0; ++h) { - fourcc = ARGBDetectRow_C(argb, width); + fourcc = ARGBDetectRow(argb, width); argb += stride_argb; } return fourcc; @@ -122,9 +186,8 @@ uint64_t ComputeHammingDistance(const uint8_t* src_a, const uint8_t* src_b, int count) { const int kBlockSize = 1 << 15; // 32768; - const int kSimdSize = 64; - // SIMD for multiple of 64, and C for remainder - int remainder = count & (kBlockSize - 1) & ~(kSimdSize - 1); + int simd_size = 64; // SIMD for multiple of 64, and C for remainder. + int remainder; uint64_t diff = 0; int i; uint32_t (*HammingDistance)(const uint8_t* src_a, const uint8_t* src_b, @@ -134,6 +197,11 @@ uint64_t ComputeHammingDistance(const uint8_t* src_a, HammingDistance = HammingDistance_NEON; } #endif +#if defined(HAS_HAMMINGDISTANCE_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + HammingDistance = HammingDistance_NEON_DotProd; + } +#endif #if defined(HAS_HAMMINGDISTANCE_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { HammingDistance = HammingDistance_SSSE3; @@ -149,16 +217,46 @@ uint64_t ComputeHammingDistance(const uint8_t* src_a, HammingDistance = HammingDistance_AVX2; } #endif -#if defined(HAS_HAMMINGDISTANCE_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - HammingDistance = HammingDistance_MSA; +#if defined(HAS_HAMMINGDISTANCE_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + HammingDistance = HammingDistance_AVX512BW; + simd_size = 1; // Any count. } #endif -#if defined(HAS_HAMMINGDISTANCE_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - HammingDistance = HammingDistance_MMI; +#if defined(HAS_HAMMINGDISTANCE_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + HammingDistance = HammingDistance_AVX512VNNI; + simd_size = 1; // Any count. } #endif +#if defined(HAS_HAMMINGDISTANCE_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + HammingDistance = HammingDistance_RVV; + simd_size = 1; // Any count. + } +#endif +#if defined(HAS_HAMMINGDISTANCE_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + HammingDistance = HammingDistance_LSX; + } +#endif +#if defined(HAS_HAMMINGDISTANCE_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + HammingDistance = HammingDistance_LASX; + } +#endif +#if defined(HAS_HAMMINGDISTANCE_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + HammingDistance = HammingDistance_WASMSIMD; + } +#endif +#if defined(HAS_HAMMINGDISTANCE_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + HammingDistance = HammingDistance_HVX; + simd_size = 1; // Any count. + } +#endif + remainder = count & (kBlockSize - 1) & ~(simd_size - 1); #ifdef _OPENMP #pragma omp parallel for reduction(+ : diff) @@ -173,9 +271,19 @@ uint64_t ComputeHammingDistance(const uint8_t* src_a, src_a += remainder; src_b += remainder; } - remainder = count & (kSimdSize - 1); + remainder = count & (simd_size - 1); if (remainder) { - diff += HammingDistance_C(src_a, src_b, remainder); + if (HammingDistance == HammingDistance_C) { + diff += HammingDistance_C(src_a, src_b, remainder); + } else { + SIMD_ALIGNED(uint8_t buf_a[64]); + SIMD_ALIGNED(uint8_t buf_b[64]); + memset(buf_a, 0, sizeof(buf_a)); + memset(buf_b, 0, sizeof(buf_b)); + memcpy(buf_a, src_a, remainder); + memcpy(buf_b, src_b, remainder); + diff += HammingDistance(buf_a, buf_b, simd_size); + } } return diff; } @@ -189,7 +297,8 @@ uint64_t ComputeSumSquareError(const uint8_t* src_a, // Up to 65536 of those can be summed and remain within a uint32_t. // After each block of 65536 pixels, accumulate into a uint64_t. const int kBlockSize = 65536; - int remainder = count & (kBlockSize - 1) & ~31; + int simd_size = 32; // SIMD for multiple of 32, and C for remainder. + int remainder; uint64_t sse = 0; int i; uint32_t (*SumSquareError)(const uint8_t* src_a, const uint8_t* src_b, @@ -199,6 +308,11 @@ uint64_t ComputeSumSquareError(const uint8_t* src_a, SumSquareError = SumSquareError_NEON; } #endif +#if defined(HAS_SUMSQUAREERROR_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + SumSquareError = SumSquareError_NEON_DotProd; + } +#endif #if defined(HAS_SUMSQUAREERROR_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { // Note only used for multiples of 16 so count is not checked. @@ -211,16 +325,46 @@ uint64_t ComputeSumSquareError(const uint8_t* src_a, SumSquareError = SumSquareError_AVX2; } #endif -#if defined(HAS_SUMSQUAREERROR_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - SumSquareError = SumSquareError_MSA; +#if defined(HAS_SUMSQUAREERROR_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + SumSquareError = SumSquareError_AVX512BW; + simd_size = 1; // Any count. } #endif -#if defined(HAS_SUMSQUAREERROR_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - SumSquareError = SumSquareError_MMI; +#if defined(HAS_SUMSQUAREERROR_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + SumSquareError = SumSquareError_AVX512VNNI; + simd_size = 1; // Any count. } #endif +#if defined(HAS_SUMSQUAREERROR_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SumSquareError = SumSquareError_RVV; + simd_size = 1; // Any count. + } +#endif +#if defined(HAS_SUMSQUAREERROR_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + SumSquareError = SumSquareError_LSX; + } +#endif +#if defined(HAS_SUMSQUAREERROR_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + SumSquareError = SumSquareError_LASX; + } +#endif +#if defined(HAS_SUMSQUAREERROR_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + SumSquareError = SumSquareError_WASMSIMD; + } +#endif +#if defined(HAS_SUMSQUAREERROR_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SumSquareError = SumSquareError_HVX; + simd_size = 1; // Any count. + } +#endif + remainder = count & (kBlockSize - 1) & ~(simd_size - 1); #ifdef _OPENMP #pragma omp parallel for reduction(+ : sse) #endif @@ -234,9 +378,19 @@ uint64_t ComputeSumSquareError(const uint8_t* src_a, src_a += remainder; src_b += remainder; } - remainder = count & 31; + remainder = count & (simd_size - 1); if (remainder) { - sse += SumSquareError_C(src_a, src_b, remainder); + if (SumSquareError == SumSquareError_C) { + sse += SumSquareError_C(src_a, src_b, remainder); + } else { + SIMD_ALIGNED(uint8_t buf_a[32]); + SIMD_ALIGNED(uint8_t buf_b[32]); + memset(buf_a, 0, sizeof(buf_a)); + memset(buf_b, 0, sizeof(buf_b)); + memcpy(buf_a, src_a, remainder); + memcpy(buf_b, src_b, remainder); + sse += SumSquareError(buf_a, buf_b, simd_size); + } } return sse; } @@ -250,8 +404,12 @@ uint64_t ComputeSumSquareErrorPlane(const uint8_t* src_a, int height) { uint64_t sse = 0; int h; + if (!src_a || !src_b || width <= 0 || height <= 0) { + return sse; + } // Coalesce rows. - if (stride_a == width && stride_b == width) { + if (stride_a == width && stride_b == width && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; stride_a = stride_b = 0; @@ -323,18 +481,14 @@ double I420Psnr(const uint8_t* src_y_a, return SumSquareErrorToPsnr(sse, samples); } -static const int64_t cc1 = 26634; // (64^2*(.01*255)^2 -static const int64_t cc2 = 239708; // (64^2*(.03*255)^2 - -static double Ssim8x8_C(const uint8_t* src_a, - int stride_a, - const uint8_t* src_b, - int stride_b) { - int64_t sum_a = 0; - int64_t sum_b = 0; - int64_t sum_sq_a = 0; - int64_t sum_sq_b = 0; - int64_t sum_axb = 0; +static float Ssim8x8(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b) { + int32_t sum_a = 0; + int32_t sum_b = 0; + int32_t sum_sq_ab = 0; + int32_t sum_axb = 0; int i; for (i = 0; i < 8; ++i) { @@ -342,8 +496,7 @@ static double Ssim8x8_C(const uint8_t* src_a, for (j = 0; j < 8; ++j) { sum_a += src_a[j]; sum_b += src_b[j]; - sum_sq_a += src_a[j] * src_a[j]; - sum_sq_b += src_b[j] * src_b[j]; + sum_sq_ab += src_a[j] * src_a[j] + src_b[j] * src_b[j]; sum_axb += src_a[j] * src_b[j]; } @@ -352,30 +505,90 @@ static double Ssim8x8_C(const uint8_t* src_a, } { - const int64_t count = 64; - // scale the constants by number of pixels - const int64_t c1 = (cc1 * count * count) >> 12; - const int64_t c2 = (cc2 * count * count) >> 12; - - const int64_t sum_a_x_sum_b = sum_a * sum_b; - - const int64_t ssim_n = (2 * sum_a_x_sum_b + c1) * - (2 * count * sum_axb - 2 * sum_a_x_sum_b + c2); - - const int64_t sum_a_sq = sum_a * sum_a; - const int64_t sum_b_sq = sum_b * sum_b; - - const int64_t ssim_d = - (sum_a_sq + sum_b_sq + c1) * - (count * sum_sq_a - sum_a_sq + count * sum_sq_b - sum_b_sq + c2); - - if (ssim_d == 0.0) { - return DBL_MAX; - } - return ssim_n * 1.0 / ssim_d; + const int32_t c1 = 26634; // (64^2*(.01*255)^2) + const int32_t c2 = 239708; // (64^2*(.03*255)^2) + const int32_t sum_a_x_sum_b_2 = 2 * sum_a * sum_b; + const int32_t sum_a_sq_b_sq = sum_a * sum_a + sum_b * sum_b; + const int32_t n1 = sum_a_x_sum_b_2 + c1; + const int32_t n2 = (sum_axb << 7) - sum_a_x_sum_b_2 + c2; + const int32_t d1 = sum_a_sq_b_sq + c1; + const int32_t d2 = (sum_sq_ab << 6) - sum_a_sq_b_sq + c2; + return ((float)n1 * (float)n2) / ((float)d1 * (float)d2); } } +static void Ssim4x4Row_Rem(void (*Ssim4x4Row)(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width), + int simd_size, + const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int rem_width) { + if (Ssim4x4Row == Ssim4x4Row_C) { + Ssim4x4Row_C(src_a, stride_a, src_b, stride_b, dst, rem_width); + return; + } + SIMD_ALIGNED(uint8_t buf_a[32 * 4]); + SIMD_ALIGNED(uint8_t buf_b[32 * 4]); + SIMD_ALIGNED(uint32_t buf_dst[32]); + memset(buf_a, 0, sizeof(buf_a)); + memset(buf_b, 0, sizeof(buf_b)); + int r; + for (r = 0; r < 4; ++r) { + memcpy(buf_a + r * 32, src_a + (ptrdiff_t)r * stride_a, rem_width); + memcpy(buf_b + r * 32, src_b + (ptrdiff_t)r * stride_b, rem_width); + } + Ssim4x4Row(buf_a, 32, buf_b, 32, buf_dst, simd_size); + memcpy(dst, buf_dst, (size_t)rem_width * sizeof(uint32_t)); +} + +static float SsimWindowRow_Rem(float (*SsimWindowRow)(const uint32_t* row0, + const uint32_t* row1, + int num_windows), + int win_simd_size, + const uint32_t* row0, + const uint32_t* row1, + int rem_windows) { + if (SsimWindowRow == SsimWindowRow_C) { + return SsimWindowRow_C(row0, row1, rem_windows); + } + SIMD_ALIGNED(uint32_t win0[9 * 4]); + SIMD_ALIGNED(uint32_t win1[9 * 4]); + memset(win0, 0, sizeof(win0)); + memset(win1, 0, sizeof(win1)); + // Set odd tiles (1, 3, 5, 7) in win1 so each unused window k >= 1 has + // sum_a = 4439, sum_b = -3, sum_sq = 307887, giving n1 = 2*4439*(-3) + c1 = 0 + // and SSIM = 0.0f (avoiding float precision loss from adding 1.0f per lane). + int k; + for (k = 1; k <= win_simd_size; k += 2) { + win1[k * 4 + 0] = 4439u; + win1[k * 4 + 1] = (uint32_t)-3; + win1[k * 4 + 2] = 307887u; + } + float total = 0.0f; + int w; + for (w = 0; w < rem_windows; ++w) { + const uint32_t* r0 = row0 + w * 4; + const uint32_t* r1 = row1 + w * 4; + win0[0] = r0[0] + r0[4]; + win0[1] = r0[1] + r0[5]; + win0[2] = r0[2] + r0[6]; + win0[3] = r0[3] + r0[7]; + win1[0] = r1[0] + r1[4] - 4439u; + win1[1] = r1[1] + r1[5] - (uint32_t)-3; + win1[2] = r1[2] + r1[6] - 307887u; + win1[3] = r1[3] + r1[7]; + total += SsimWindowRow(win0, win1, win_simd_size); + } + return total; +} + // We are using a 8x8 moving window with starting location of each 8x8 window // on the 4x4 pixel grid. Such arrangement allows the windows to overlap // block boundaries to penalize blocking artifacts. @@ -388,20 +601,231 @@ double CalcFrameSsim(const uint8_t* src_a, int height) { int samples = 0; double ssim_total = 0; - double (*Ssim8x8)(const uint8_t* src_a, int stride_a, const uint8_t* src_b, - int stride_b) = Ssim8x8_C; + // Return 0 rather than 0.0 / 0 (NaN) when the plane is too small for any + // sample windows, so I420Ssim on small images stays finite. + if (width <= 8 || height <= 8) { + return 0.0; + } - // sample point start with each 4x4 location - int i; - for (i = 0; i < height - 8; i += 4) { - int j; - for (j = 0; j < width - 8; j += 4) { - ssim_total += Ssim8x8(src_a + j, stride_a, src_b + j, stride_b); - samples++; + int simd_size = 4; + void (*Ssim4x4Row)(const uint8_t* src_a, int stride_a, const uint8_t* src_b, + int stride_b, uint32_t* dst, int width) = Ssim4x4Row_C; + int win_simd_size = 1; + float (*SsimWindowRow)(const uint32_t* row0, const uint32_t* row1, + int num_windows) = SsimWindowRow_C; +#if defined(HAS_SSIM4X4ROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + Ssim4x4Row = Ssim4x4Row_SSE2; + simd_size = 16; + } +#endif +#if defined(HAS_SSIM4X4ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Ssim4x4Row = Ssim4x4Row_AVX2; + simd_size = 32; + } +#endif +#if defined(HAS_SSIM4X4ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Ssim4x4Row = Ssim4x4Row_AVX512BW; + simd_size = 4; + } +#endif +#if defined(HAS_SSIMWINDOWROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + SsimWindowRow = SsimWindowRow_SSE2; + win_simd_size = 4; + } +#endif +#if defined(HAS_SSIMWINDOWROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SsimWindowRow = SsimWindowRow_AVX2; + win_simd_size = 8; + } +#endif +#if defined(HAS_SSIMWINDOWROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + SsimWindowRow = SsimWindowRow_AVX512BW; + win_simd_size = 1; + } +#endif +#if defined(HAS_SSIM4X4ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Ssim4x4Row = Ssim4x4Row_NEON; + simd_size = 16; + } +#endif +#if defined(HAS_SSIM4X4ROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + Ssim4x4Row = Ssim4x4Row_NEON_DotProd; + simd_size = 16; + } +#endif +#if defined(HAS_SSIMWINDOWROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + SsimWindowRow = SsimWindowRow_NEON; + win_simd_size = 4; + } +#endif +#if defined(HAS_SSIM4X4ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + Ssim4x4Row = Ssim4x4Row_SVE2; + simd_size = 4; + } +#endif +#if defined(HAS_SSIMWINDOWROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + SsimWindowRow = SsimWindowRow_SVE2; + win_simd_size = 1; + } +#endif +#if defined(HAS_SSIM4X4ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Ssim4x4Row = Ssim4x4Row_SME; + simd_size = 4; + } +#endif +#if defined(HAS_SSIMWINDOWROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + SsimWindowRow = SsimWindowRow_SME; + win_simd_size = 1; + } +#endif +#if defined(HAS_SSIM4X4ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Ssim4x4Row = Ssim4x4Row_RVV; + simd_size = 4; + } +#endif +#if defined(HAS_SSIMWINDOWROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SsimWindowRow = SsimWindowRow_RVV; + win_simd_size = 1; + } +#endif +#if defined(HAS_SSIM4X4ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + Ssim4x4Row = Ssim4x4Row_LSX; + simd_size = 16; + } +#endif +#if defined(HAS_SSIMWINDOWROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + SsimWindowRow = SsimWindowRow_LSX; + win_simd_size = 1; + } +#endif +#if defined(HAS_SSIM4X4ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + Ssim4x4Row = Ssim4x4Row_LASX; + simd_size = 32; + } +#endif +#if defined(HAS_SSIMWINDOWROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + SsimWindowRow = SsimWindowRow_LASX; + win_simd_size = 1; + } +#endif +#if defined(HAS_SSIM4X4ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + Ssim4x4Row = Ssim4x4Row_WASMSIMD; + simd_size = 16; + } +#endif +#if defined(HAS_SSIMWINDOWROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + SsimWindowRow = SsimWindowRow_WASMSIMD; + win_simd_size = 4; + } +#endif +#if defined(HAS_SSIM4X4ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Ssim4x4Row = Ssim4x4Row_HVX; + simd_size = 4; + } +#endif +#if defined(HAS_SSIMWINDOWROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SsimWindowRow = SsimWindowRow_HVX; + win_simd_size = 1; + } +#endif + + const int num_windows = (width - 8 + 3) >> 2; + const int num_tiles = num_windows + 1; + const int tile_width = num_tiles * 4; + const int main_width = tile_width & ~(simd_size - 1); + const int rem_width = tile_width & (simd_size - 1); + const int main_windows = num_windows & ~(win_simd_size - 1); + const int rem_windows = num_windows & (win_simd_size - 1); + +#ifdef _OPENMP +#pragma omp parallel reduction(+ : ssim_total, samples) +#endif + { + align_buffer_64(row_buf, (size_t)tile_width * 2 * sizeof(uint32_t)); + if (row_buf) { + uint32_t* row0 = (uint32_t*)row_buf; + uint32_t* row1 = row0 + tile_width; + int prev_i = -8; + int i; +#ifdef _OPENMP +#pragma omp for schedule(static) +#endif + for (i = 0; i < height - 8; i += 4) { + const uint8_t* a = src_a + (ptrdiff_t)i * stride_a; + const uint8_t* b = src_b + (ptrdiff_t)i * stride_b; + if (prev_i + 4 != i) { + if (main_width > 0) { + Ssim4x4Row(a, stride_a, b, stride_b, row0, main_width); + } + if (rem_width > 0) { + Ssim4x4Row_Rem(Ssim4x4Row, simd_size, a + main_width, stride_a, + b + main_width, stride_b, row0 + main_width, + rem_width); + } + } + a += (ptrdiff_t)stride_a * 4; + b += (ptrdiff_t)stride_b * 4; + if (main_width > 0) { + Ssim4x4Row(a, stride_a, b, stride_b, row1, main_width); + } + if (rem_width > 0) { + Ssim4x4Row_Rem(Ssim4x4Row, simd_size, a + main_width, stride_a, + b + main_width, stride_b, row1 + main_width, + rem_width); + } + if (main_windows > 0) { + ssim_total += SsimWindowRow(row0, row1, main_windows); + } + if (rem_windows > 0) { + ssim_total += SsimWindowRow_Rem(SsimWindowRow, win_simd_size, + row0 + main_windows * 4, + row1 + main_windows * 4, rem_windows); + } + samples += num_windows; + uint32_t* tmp = row0; + row0 = row1; + row1 = tmp; + prev_i = i; + } + free_aligned_buffer_64(row_buf); + } else { + int i; +#ifdef _OPENMP +#pragma omp for schedule(static) +#endif + for (i = 0; i < height - 8; i += 4) { + const uint8_t* a = src_a + (ptrdiff_t)i * stride_a; + const uint8_t* b = src_b + (ptrdiff_t)i * stride_b; + int j; + for (j = 0; j < width - 8; j += 4) { + ssim_total += Ssim8x8(a + j, stride_a, b + j, stride_b); + samples++; + } + } } - - src_a += stride_a * 4; - src_b += stride_b * 4; } ssim_total /= samples; diff --git a/libs/libyuv/source/compare_common.cc b/libs/libyuv/source/compare_common.cc index d4b170ad98..f50bc47082 100644 --- a/libs/libyuv/source/compare_common.cc +++ b/libs/libyuv/source/compare_common.cc @@ -8,45 +8,17 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "libyuv/basic_types.h" - #include "libyuv/compare_row.h" +#include + +#include "libyuv/video_common.h" + #ifdef __cplusplus namespace libyuv { extern "C" { #endif -#if ORIGINAL_OPT -uint32_t HammingDistance_C1(const uint8_t* src_a, - const uint8_t* src_b, - int count) { - uint32_t diff = 0u; - - int i; - for (i = 0; i < count; ++i) { - int x = src_a[i] ^ src_b[i]; - if (x & 1) - ++diff; - if (x & 2) - ++diff; - if (x & 4) - ++diff; - if (x & 8) - ++diff; - if (x & 16) - ++diff; - if (x & 32) - ++diff; - if (x & 64) - ++diff; - if (x & 128) - ++diff; - } - return diff; -} -#endif - // Hakmem method for hamming distance. uint32_t HammingDistance_C(const uint8_t* src_a, const uint8_t* src_b, @@ -55,7 +27,11 @@ uint32_t HammingDistance_C(const uint8_t* src_a, int i; for (i = 0; i < count - 3; i += 4) { - uint32_t x = *((const uint32_t*)src_a) ^ *((const uint32_t*)src_b); + uint32_t a = (uint32_t)src_a[0] | ((uint32_t)src_a[1] << 8) | + ((uint32_t)src_a[2] << 16) | ((uint32_t)src_a[3] << 24); + uint32_t b = (uint32_t)src_b[0] | ((uint32_t)src_b[1] << 8) | + ((uint32_t)src_b[2] << 16) | ((uint32_t)src_b[3] << 24); + uint32_t x = a ^ b; uint32_t u = x - ((x >> 1) & 0x55555555); u = ((u >> 2) & 0x33333333) + (u & 0x33333333); diff += ((((u + (u >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24); @@ -98,6 +74,131 @@ uint32_t HashDjb2_C(const uint8_t* src, int count, uint32_t seed) { return hash; } +// Compute 4x4 tile statistics (sum_a, sum_b, sum_sq_a + sum_sq_b, sum_axb) +// across 4 rows for width pixels (width is a multiple of 4). +void Ssim4x4Row_C(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + const ptrdiff_t sa = stride_a; + const ptrdiff_t sb = stride_b; + const uint8_t* a0 = src_a; + const uint8_t* a1 = a0 + sa; + const uint8_t* a2 = a1 + sa; + const uint8_t* a3 = a2 + sa; + const uint8_t* b0 = src_b; + const uint8_t* b1 = b0 + sb; + const uint8_t* b2 = b1 + sb; + const uint8_t* b3 = b2 + sb; + int x; + for (x = 0; x < width; x += 4) { + uint32_t sum_a = a0[0] + a0[1] + a0[2] + a0[3] + a1[0] + a1[1] + a1[2] + + a1[3] + a2[0] + a2[1] + a2[2] + a2[3] + a3[0] + a3[1] + + a3[2] + a3[3]; + uint32_t sum_b = b0[0] + b0[1] + b0[2] + b0[3] + b1[0] + b1[1] + b1[2] + + b1[3] + b2[0] + b2[1] + b2[2] + b2[3] + b3[0] + b3[1] + + b3[2] + b3[3]; + uint32_t sum_sq_ab = + a0[0] * a0[0] + a0[1] * a0[1] + a0[2] * a0[2] + a0[3] * a0[3] + + a1[0] * a1[0] + a1[1] * a1[1] + a1[2] * a1[2] + a1[3] * a1[3] + + a2[0] * a2[0] + a2[1] * a2[1] + a2[2] * a2[2] + a2[3] * a2[3] + + a3[0] * a3[0] + a3[1] * a3[1] + a3[2] * a3[2] + a3[3] * a3[3] + + b0[0] * b0[0] + b0[1] * b0[1] + b0[2] * b0[2] + b0[3] * b0[3] + + b1[0] * b1[0] + b1[1] * b1[1] + b1[2] * b1[2] + b1[3] * b1[3] + + b2[0] * b2[0] + b2[1] * b2[1] + b2[2] * b2[2] + b2[3] * b2[3] + + b3[0] * b3[0] + b3[1] * b3[1] + b3[2] * b3[2] + b3[3] * b3[3]; + uint32_t sum_axb = + a0[0] * b0[0] + a0[1] * b0[1] + a0[2] * b0[2] + a0[3] * b0[3] + + a1[0] * b1[0] + a1[1] * b1[1] + a1[2] * b1[2] + a1[3] * b1[3] + + a2[0] * b2[0] + a2[1] * b2[1] + a2[2] * b2[2] + a2[3] * b2[3] + + a3[0] * b3[0] + a3[1] * b3[1] + a3[2] * b3[2] + a3[3] * b3[3]; + dst[0] = sum_a; + dst[1] = sum_b; + dst[2] = sum_sq_ab; + dst[3] = sum_axb; + a0 += 4; + a1 += 4; + a2 += 4; + a3 += 4; + b0 += 4; + b1 += 4; + b2 += 4; + b3 += 4; + dst += 4; + } +} + +// Combine two consecutive 4x4 tile rows (row0 and row1) into 8x8 windows +// stepped on a 4-pixel horizontal grid and return the sum of SSIM values. +float SsimWindowRow_C(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + const int32_t c1 = 26634; // (64^2*(.01*255)^2) + const int32_t c2 = 239708; // (64^2*(.03*255)^2) + + float ssim_total = 0.0f; + int32_t prev_a = (int32_t)(row0[0] + row1[0]); + int32_t prev_b = (int32_t)(row0[1] + row1[1]); + int32_t prev_sq = (int32_t)(row0[2] + row1[2]); + int32_t prev_axb = (int32_t)(row0[3] + row1[3]); + int w; + for (w = 0; w < num_windows; ++w) { + row0 += 4; + row1 += 4; + const int32_t next_a = (int32_t)(row0[0] + row1[0]); + const int32_t next_b = (int32_t)(row0[1] + row1[1]); + const int32_t next_sq = (int32_t)(row0[2] + row1[2]); + const int32_t next_axb = (int32_t)(row0[3] + row1[3]); + const int32_t sum_a = prev_a + next_a; + const int32_t sum_b = prev_b + next_b; + const int32_t sum_sq_ab = prev_sq + next_sq; + const int32_t sum_axb = prev_axb + next_axb; + prev_a = next_a; + prev_b = next_b; + prev_sq = next_sq; + prev_axb = next_axb; + + const int32_t sum_a_x_sum_b_2 = 2 * sum_a * sum_b; + const int32_t sum_a_sq_b_sq = sum_a * sum_a + sum_b * sum_b; + const int32_t n1 = sum_a_x_sum_b_2 + c1; + const int32_t n2 = (sum_axb << 7) - sum_a_x_sum_b_2 + c2; + const int32_t d1 = sum_a_sq_b_sq + c1; + const int32_t d2 = (sum_sq_ab << 6) - sum_a_sq_b_sq + c2; + ssim_total += ((float)n1 * (float)n2) / ((float)d1 * (float)d2); + } + return ssim_total; +} + +uint32_t ARGBDetectRow_C(const uint8_t* argb, int width) { + int x; + for (x = 0; x < width - 1; x += 2) { + if (argb[0] != 255) { // First byte is not Alpha of 255, so not ARGB. + return FOURCC_BGRA; + } + if (argb[3] != 255) { // Fourth byte is not Alpha of 255, so not BGRA. + return FOURCC_ARGB; + } + if (argb[4] != 255) { // Second pixel first byte is not Alpha of 255. + return FOURCC_BGRA; + } + if (argb[7] != 255) { // Second pixel fourth byte is not Alpha of 255. + return FOURCC_ARGB; + } + argb += 8; + } + if (width & 1) { + if (argb[0] != 255) { // First byte is not Alpha of 255, so not ARGB. + return FOURCC_BGRA; + } + if (argb[3] != 255) { // 4th byte is not Alpha of 255, so not BGRA. + return FOURCC_ARGB; + } + } + return 0; +} + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/source/compare_gcc.cc b/libs/libyuv/source/compare_gcc.cc index 676527c1b1..5828ceaa7b 100644 --- a/libs/libyuv/source/compare_gcc.cc +++ b/libs/libyuv/source/compare_gcc.cc @@ -8,222 +8,200 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "libyuv/basic_types.h" - #include "libyuv/compare_row.h" #include "libyuv/row.h" +#include "libyuv/video_common.h" #ifdef __cplusplus namespace libyuv { extern "C" { #endif -// This module is for GCC x86 and x64. -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. -#if defined(__x86_64__) +// This module is for GCC and clang x86 and x64. +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__)) && \ + !defined(LIBYUV_ENABLE_ROWWIN) && \ + (!defined(_MSC_VER) || defined(__clang__)) + +// "memory" clobber prevents the reads from being removed + +#ifdef HAS_HAMMINGDISTANCE_SSE42 uint32_t HammingDistance_SSE42(const uint8_t* src_a, const uint8_t* src_b, int count) { - uint64_t diff = 0u; + uint64_t diff; asm volatile( - "xor %3,%3 \n" - "xor %%r8,%%r8 \n" - "xor %%r9,%%r9 \n" - "xor %%r10,%%r10 \n" + "xor %3,%3 \n" + "xor %%r8,%%r8 \n" + "xor %%r9,%%r9 \n" + "xor %%r10,%%r10 \n" // Process 32 bytes per loop. LABELALIGN - "1: \n" - "mov (%0),%%rcx \n" - "mov 0x8(%0),%%rdx \n" - "xor (%1),%%rcx \n" - "xor 0x8(%1),%%rdx \n" - "popcnt %%rcx,%%rcx \n" - "popcnt %%rdx,%%rdx \n" - "mov 0x10(%0),%%rsi \n" - "mov 0x18(%0),%%rdi \n" - "xor 0x10(%1),%%rsi \n" - "xor 0x18(%1),%%rdi \n" - "popcnt %%rsi,%%rsi \n" - "popcnt %%rdi,%%rdi \n" - "add $0x20,%0 \n" - "add $0x20,%1 \n" - "add %%rcx,%3 \n" - "add %%rdx,%%r8 \n" - "add %%rsi,%%r9 \n" - "add %%rdi,%%r10 \n" - "sub $0x20,%2 \n" - "jg 1b \n" + "1: \n" + "mov (%0),%%rcx \n" + "mov 0x8(%0),%%rdx \n" + "xor (%1),%%rcx \n" + "xor 0x8(%1),%%rdx \n" + "popcnt %%rcx,%%rcx \n" + "popcnt %%rdx,%%rdx \n" + "mov 0x10(%0),%%rsi \n" + "mov 0x18(%0),%%rdi \n" + "xor 0x10(%1),%%rsi \n" + "xor 0x18(%1),%%rdi \n" + "popcnt %%rsi,%%rsi \n" + "popcnt %%rdi,%%rdi \n" + "add $0x20,%0 \n" + "add $0x20,%1 \n" + "add %%rcx,%3 \n" + "add %%rdx,%%r8 \n" + "add %%rsi,%%r9 \n" + "add %%rdi,%%r10 \n" + "sub $0x20,%2 \n" + "jg 1b \n" - "add %%r8, %3 \n" - "add %%r9, %3 \n" - "add %%r10, %3 \n" + "add %%r8, %3 \n" + "add %%r9, %3 \n" + "add %%r10, %3 \n" : "+r"(src_a), // %0 "+r"(src_b), // %1 "+r"(count), // %2 - "=r"(diff) // %3 + "=&r"(diff) // %3 : - : "memory", "cc", "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10"); + : "cc", "memory", "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10"); - return static_cast(diff); + return (uint32_t)(diff); } -#else -uint32_t HammingDistance_SSE42(const uint8_t* src_a, - const uint8_t* src_b, - int count) { - uint32_t diff = 0u; - - asm volatile( - // Process 16 bytes per loop. - LABELALIGN - "1: \n" - "mov (%0),%%ecx \n" - "mov 0x4(%0),%%edx \n" - "xor (%1),%%ecx \n" - "xor 0x4(%1),%%edx \n" - "popcnt %%ecx,%%ecx \n" - "add %%ecx,%3 \n" - "popcnt %%edx,%%edx \n" - "add %%edx,%3 \n" - "mov 0x8(%0),%%ecx \n" - "mov 0xc(%0),%%edx \n" - "xor 0x8(%1),%%ecx \n" - "xor 0xc(%1),%%edx \n" - "popcnt %%ecx,%%ecx \n" - "add %%ecx,%3 \n" - "popcnt %%edx,%%edx \n" - "add %%edx,%3 \n" - "add $0x10,%0 \n" - "add $0x10,%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_a), // %0 - "+r"(src_b), // %1 - "+r"(count), // %2 - "+r"(diff) // %3 - : - : "memory", "cc", "ecx", "edx"); - - return diff; -} -#endif +#endif // HAS_HAMMINGDISTANCE_SSE42 +#if defined(HAS_HAMMINGDISTANCE_SSSE3) || defined(HAS_HAMMINGDISTANCE_AVX2) || \ + defined(HAS_HAMMINGDISTANCE_AVX512BW) static const vec8 kNibbleMask = {15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15}; static const vec8 kBitCount = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4}; +#endif +#ifdef HAS_HAMMINGDISTANCE_SSSE3 uint32_t HammingDistance_SSSE3(const uint8_t* src_a, const uint8_t* src_b, int count) { - uint32_t diff = 0u; + uint32_t diff; asm volatile( - "movdqa %4,%%xmm2 \n" - "movdqa %5,%%xmm3 \n" - "pxor %%xmm0,%%xmm0 \n" - "pxor %%xmm1,%%xmm1 \n" - "sub %0,%1 \n" + "movdqa %4,%%xmm2 \n" + "movdqa %5,%%xmm3 \n" + "pxor %%xmm0,%%xmm0 \n" + "pxor %%xmm1,%%xmm1 \n" + "sub %0,%1 \n" LABELALIGN - "1: \n" - "movdqa (%0),%%xmm4 \n" - "movdqa 0x10(%0), %%xmm5 \n" - "pxor (%0,%1), %%xmm4 \n" - "movdqa %%xmm4,%%xmm6 \n" - "pand %%xmm2,%%xmm6 \n" - "psrlw $0x4,%%xmm4 \n" - "movdqa %%xmm3,%%xmm7 \n" - "pshufb %%xmm6,%%xmm7 \n" - "pand %%xmm2,%%xmm4 \n" - "movdqa %%xmm3,%%xmm6 \n" - "pshufb %%xmm4,%%xmm6 \n" - "paddb %%xmm7,%%xmm6 \n" - "pxor 0x10(%0,%1),%%xmm5 \n" - "add $0x20,%0 \n" - "movdqa %%xmm5,%%xmm4 \n" - "pand %%xmm2,%%xmm5 \n" - "psrlw $0x4,%%xmm4 \n" - "movdqa %%xmm3,%%xmm7 \n" - "pshufb %%xmm5,%%xmm7 \n" - "pand %%xmm2,%%xmm4 \n" - "movdqa %%xmm3,%%xmm5 \n" - "pshufb %%xmm4,%%xmm5 \n" - "paddb %%xmm7,%%xmm5 \n" - "paddb %%xmm5,%%xmm6 \n" - "psadbw %%xmm1,%%xmm6 \n" - "paddd %%xmm6,%%xmm0 \n" - "sub $0x20,%2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm4 \n" + "movdqu 0x10(%0), %%xmm5 \n" + "movdqu (%0,%1), %%xmm6 \n" + "pxor %%xmm6, %%xmm4 \n" + "movdqa %%xmm4,%%xmm6 \n" + "pand %%xmm2,%%xmm6 \n" + "psrlw $0x4,%%xmm4 \n" + "movdqa %%xmm3,%%xmm7 \n" + "pshufb %%xmm6,%%xmm7 \n" + "pand %%xmm2,%%xmm4 \n" + "movdqa %%xmm3,%%xmm6 \n" + "pshufb %%xmm4,%%xmm6 \n" + "paddb %%xmm7,%%xmm6 \n" + "movdqu 0x10(%0,%1),%%xmm7 \n" + "pxor %%xmm7,%%xmm5 \n" + "add $0x20,%0 \n" + "movdqa %%xmm5,%%xmm4 \n" + "pand %%xmm2,%%xmm5 \n" + "psrlw $0x4,%%xmm4 \n" + "movdqa %%xmm3,%%xmm7 \n" + "pshufb %%xmm5,%%xmm7 \n" + "pand %%xmm2,%%xmm4 \n" + "movdqa %%xmm3,%%xmm5 \n" + "pshufb %%xmm4,%%xmm5 \n" + "paddb %%xmm7,%%xmm5 \n" + "paddb %%xmm5,%%xmm6 \n" + "psadbw %%xmm1,%%xmm6 \n" + "paddd %%xmm6,%%xmm0 \n" + "sub $0x20,%2 \n" + "jg 1b \n" - "pshufd $0xaa,%%xmm0,%%xmm1 \n" - "paddd %%xmm1,%%xmm0 \n" - "movd %%xmm0, %3 \n" + "pshufd $0xaa,%%xmm0,%%xmm1 \n" + "paddd %%xmm1,%%xmm0 \n" + "movd %%xmm0, %3 \n" : "+r"(src_a), // %0 "+r"(src_b), // %1 "+r"(count), // %2 "=r"(diff) // %3 : "m"(kNibbleMask), // %4 "m"(kBitCount) // %5 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + : "cc", "memory", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); return diff; } +#endif // HAS_HAMMINGDISTANCE_SSSE3 #ifdef HAS_HAMMINGDISTANCE_AVX2 uint32_t HammingDistance_AVX2(const uint8_t* src_a, const uint8_t* src_b, int count) { - uint32_t diff = 0u; + uint32_t diff; asm volatile( "vbroadcastf128 %4,%%ymm2 \n" "vbroadcastf128 %5,%%ymm3 \n" - "vpxor %%ymm0,%%ymm0,%%ymm0 \n" - "vpxor %%ymm1,%%ymm1,%%ymm1 \n" - "sub %0,%1 \n" + "vpxor %%ymm0,%%ymm0,%%ymm0 \n" + "vpxor %%ymm1,%%ymm1,%%ymm1 \n" + "sub %0,%1 \n" LABELALIGN - "1: \n" - "vmovdqa (%0),%%ymm4 \n" - "vmovdqa 0x20(%0), %%ymm5 \n" - "vpxor (%0,%1), %%ymm4, %%ymm4 \n" - "vpand %%ymm2,%%ymm4,%%ymm6 \n" - "vpsrlw $0x4,%%ymm4,%%ymm4 \n" - "vpshufb %%ymm6,%%ymm3,%%ymm6 \n" - "vpand %%ymm2,%%ymm4,%%ymm4 \n" - "vpshufb %%ymm4,%%ymm3,%%ymm4 \n" - "vpaddb %%ymm4,%%ymm6,%%ymm6 \n" - "vpxor 0x20(%0,%1),%%ymm5,%%ymm4 \n" - "add $0x40,%0 \n" - "vpand %%ymm2,%%ymm4,%%ymm5 \n" - "vpsrlw $0x4,%%ymm4,%%ymm4 \n" - "vpshufb %%ymm5,%%ymm3,%%ymm5 \n" - "vpand %%ymm2,%%ymm4,%%ymm4 \n" - "vpshufb %%ymm4,%%ymm3,%%ymm4 \n" - "vpaddb %%ymm5,%%ymm4,%%ymm4 \n" - "vpaddb %%ymm6,%%ymm4,%%ymm4 \n" - "vpsadbw %%ymm1,%%ymm4,%%ymm4 \n" - "vpaddd %%ymm0,%%ymm4,%%ymm0 \n" - "sub $0x40,%2 \n" - "jg 1b \n" + "1: \n" + "vmovdqu (%0),%%ymm4 \n" + "vmovdqu 0x20(%0), %%ymm5 \n" + "vpxor (%0,%1), %%ymm4, %%ymm4 \n" + "vpand %%ymm2,%%ymm4,%%ymm6 \n" + "vpsrlw $0x4,%%ymm4,%%ymm4 \n" + "vpshufb %%ymm6,%%ymm3,%%ymm6 \n" + "vpand %%ymm2,%%ymm4,%%ymm4 \n" + "vpshufb %%ymm4,%%ymm3,%%ymm4 \n" + "vpaddb %%ymm4,%%ymm6,%%ymm6 \n" + "vpxor 0x20(%0,%1),%%ymm5,%%ymm4 \n" + "add $0x40,%0 \n" + "vpand %%ymm2,%%ymm4,%%ymm5 \n" + "vpsrlw $0x4,%%ymm4,%%ymm4 \n" + "vpshufb %%ymm5,%%ymm3,%%ymm5 \n" + "vpand %%ymm2,%%ymm4,%%ymm4 \n" + "vpshufb %%ymm4,%%ymm3,%%ymm4 \n" + "vpaddb %%ymm5,%%ymm4,%%ymm4 \n" + "vpaddb %%ymm6,%%ymm4,%%ymm4 \n" + "vpsadbw %%ymm1,%%ymm4,%%ymm4 \n" + "vpaddd %%ymm0,%%ymm4,%%ymm0 \n" + "sub $0x40,%2 \n" + "jg 1b \n" - "vpermq $0xb1,%%ymm0,%%ymm1 \n" - "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xaa,%%ymm0,%%ymm1 \n" - "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" - "vmovd %%xmm0, %3 \n" - "vzeroupper \n" + "vpermq $0xb1,%%ymm0,%%ymm1 \n" + "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xaa,%%ymm0,%%ymm1 \n" + "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" + "vmovd %%xmm0,%3 \n" + "vzeroupper \n" : "+r"(src_a), // %0 "+r"(src_b), // %1 "+r"(count), // %2 "=r"(diff) // %3 : "m"(kNibbleMask), // %4 "m"(kBitCount) // %5 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); + : "cc", "memory", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); return diff; } @@ -234,44 +212,89 @@ uint32_t SumSquareError_SSE2(const uint8_t* src_a, int count) { uint32_t sse; asm volatile( - "pxor %%xmm0,%%xmm0 \n" - "pxor %%xmm5,%%xmm5 \n" + "pxor %%xmm0,%%xmm0 \n" + "pxor %%xmm5,%%xmm5 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm1 \n" - "lea 0x10(%0),%0 \n" - "movdqu (%1),%%xmm2 \n" - "lea 0x10(%1),%1 \n" - "movdqa %%xmm1,%%xmm3 \n" - "psubusb %%xmm2,%%xmm1 \n" - "psubusb %%xmm3,%%xmm2 \n" - "por %%xmm2,%%xmm1 \n" - "movdqa %%xmm1,%%xmm2 \n" - "punpcklbw %%xmm5,%%xmm1 \n" - "punpckhbw %%xmm5,%%xmm2 \n" - "pmaddwd %%xmm1,%%xmm1 \n" - "pmaddwd %%xmm2,%%xmm2 \n" - "paddd %%xmm1,%%xmm0 \n" - "paddd %%xmm2,%%xmm0 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - - "pshufd $0xee,%%xmm0,%%xmm1 \n" - "paddd %%xmm1,%%xmm0 \n" - "pshufd $0x1,%%xmm0,%%xmm1 \n" - "paddd %%xmm1,%%xmm0 \n" - "movd %%xmm0,%3 \n" + "1: \n" + "movdqu (%0),%%xmm1 \n" + "lea 0x10(%0),%0 \n" + "movdqu (%1),%%xmm2 \n" + "lea 0x10(%1),%1 \n" + "movdqa %%xmm1,%%xmm3 \n" + "psubusb %%xmm2,%%xmm1 \n" + "psubusb %%xmm3,%%xmm2 \n" + "por %%xmm2,%%xmm1 \n" + "movdqa %%xmm1,%%xmm2 \n" + "punpcklbw %%xmm5,%%xmm1 \n" + "punpckhbw %%xmm5,%%xmm2 \n" + "pmaddwd %%xmm1,%%xmm1 \n" + "pmaddwd %%xmm2,%%xmm2 \n" + "paddd %%xmm1,%%xmm0 \n" + "paddd %%xmm2,%%xmm0 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "pshufd $0xee,%%xmm0,%%xmm1 \n" + "paddd %%xmm1,%%xmm0 \n" + "pshufd $0x1,%%xmm0,%%xmm1 \n" + "paddd %%xmm1,%%xmm0 \n" + "movd %%xmm0,%3 \n" : "+r"(src_a), // %0 "+r"(src_b), // %1 "+r"(count), // %2 - "=g"(sse) // %3 - ::"memory", - "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); + "=r"(sse) // %3 + : + : "cc", "memory", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); return sse; } +#ifdef HAS_SUMSQUAREERROR_AVX2 +uint32_t SumSquareError_AVX2(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t sse; + asm volatile( + "vpxor %%ymm0,%%ymm0,%%ymm0 \n" + "vpxor %%ymm5,%%ymm5,%%ymm5 \n" + "sub %0,%1 \n" + + // Process 32 bytes per loop. + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm1 \n" + "vmovdqu (%0,%1),%%ymm2 \n" + "add $0x20,%0 \n" + "vpsubusb %%ymm2,%%ymm1,%%ymm3 \n" + "vpsubusb %%ymm1,%%ymm2,%%ymm2 \n" + "vpor %%ymm2,%%ymm3,%%ymm1 \n" + "vpunpcklbw %%ymm5,%%ymm1,%%ymm2 \n" + "vpunpckhbw %%ymm5,%%ymm1,%%ymm1 \n" + "vpmaddwd %%ymm2,%%ymm2,%%ymm2 \n" + "vpmaddwd %%ymm1,%%ymm1,%%ymm1 \n" + "vpaddd %%ymm2,%%ymm0,%%ymm0 \n" + "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + + "vextracti128 $1,%%ymm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpshufd $0xee,%%xmm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpshufd $0x1,%%xmm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,%3 \n" + "vzeroupper \n" + : "+r"(src_a), // %0 + "+r"(src_b), // %1 + "+r"(count), // %2 + "=r"(sse) // %3 + : + : "cc", "memory", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); + return sse; +} +#endif // HAS_SUMSQUAREERROR_AVX2 + static const uvec32 kHash16x33 = {0x92d9e201, 0, 0, 0}; // 33 ^ 16 static const uvec32 kHashMul0 = { 0x0c3525e1, // 33 ^ 15 @@ -301,58 +324,1251 @@ static const uvec32 kHashMul3 = { uint32_t HashDjb2_SSE41(const uint8_t* src, int count, uint32_t seed) { uint32_t hash; asm volatile( - "movd %2,%%xmm0 \n" - "pxor %%xmm7,%%xmm7 \n" - "movdqa %4,%%xmm6 \n" + "movd %2,%%xmm0 \n" + "pxor %%xmm7,%%xmm7 \n" + "movdqa %4,%%xmm6 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm1 \n" - "lea 0x10(%0),%0 \n" - "pmulld %%xmm6,%%xmm0 \n" - "movdqa %5,%%xmm5 \n" - "movdqa %%xmm1,%%xmm2 \n" - "punpcklbw %%xmm7,%%xmm2 \n" - "movdqa %%xmm2,%%xmm3 \n" - "punpcklwd %%xmm7,%%xmm3 \n" - "pmulld %%xmm5,%%xmm3 \n" - "movdqa %6,%%xmm5 \n" - "movdqa %%xmm2,%%xmm4 \n" - "punpckhwd %%xmm7,%%xmm4 \n" - "pmulld %%xmm5,%%xmm4 \n" - "movdqa %7,%%xmm5 \n" - "punpckhbw %%xmm7,%%xmm1 \n" - "movdqa %%xmm1,%%xmm2 \n" - "punpcklwd %%xmm7,%%xmm2 \n" - "pmulld %%xmm5,%%xmm2 \n" - "movdqa %8,%%xmm5 \n" - "punpckhwd %%xmm7,%%xmm1 \n" - "pmulld %%xmm5,%%xmm1 \n" - "paddd %%xmm4,%%xmm3 \n" - "paddd %%xmm2,%%xmm1 \n" - "paddd %%xmm3,%%xmm1 \n" - "pshufd $0xe,%%xmm1,%%xmm2 \n" - "paddd %%xmm2,%%xmm1 \n" - "pshufd $0x1,%%xmm1,%%xmm2 \n" - "paddd %%xmm2,%%xmm1 \n" - "paddd %%xmm1,%%xmm0 \n" - "sub $0x10,%1 \n" - "jg 1b \n" - "movd %%xmm0,%3 \n" + "1: \n" + "movdqu (%0),%%xmm1 \n" + "lea 0x10(%0),%0 \n" + "pmulld %%xmm6,%%xmm0 \n" + "movdqa %5,%%xmm5 \n" + "movdqa %%xmm1,%%xmm2 \n" + "punpcklbw %%xmm7,%%xmm2 \n" + "movdqa %%xmm2,%%xmm3 \n" + "punpcklwd %%xmm7,%%xmm3 \n" + "pmulld %%xmm5,%%xmm3 \n" + "movdqa %6,%%xmm5 \n" + "movdqa %%xmm2,%%xmm4 \n" + "punpckhwd %%xmm7,%%xmm4 \n" + "pmulld %%xmm5,%%xmm4 \n" + "movdqa %7,%%xmm5 \n" + "punpckhbw %%xmm7,%%xmm1 \n" + "movdqa %%xmm1,%%xmm2 \n" + "punpcklwd %%xmm7,%%xmm2 \n" + "pmulld %%xmm5,%%xmm2 \n" + "movdqa %8,%%xmm5 \n" + "punpckhwd %%xmm7,%%xmm1 \n" + "pmulld %%xmm5,%%xmm1 \n" + "paddd %%xmm4,%%xmm3 \n" + "paddd %%xmm2,%%xmm1 \n" + "paddd %%xmm3,%%xmm1 \n" + "pshufd $0xe,%%xmm1,%%xmm2 \n" + "paddd %%xmm2,%%xmm1 \n" + "pshufd $0x1,%%xmm1,%%xmm2 \n" + "paddd %%xmm2,%%xmm1 \n" + "paddd %%xmm1,%%xmm0 \n" + "sub $0x10,%1 \n" + "jg 1b \n" + "movd %%xmm0,%3 \n" : "+r"(src), // %0 "+r"(count), // %1 "+rm"(seed), // %2 - "=g"(hash) // %3 + "=r"(hash) // %3 : "m"(kHash16x33), // %4 "m"(kHashMul0), // %5 "m"(kHashMul1), // %6 "m"(kHashMul2), // %7 "m"(kHashMul3) // %8 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + : "cc", "memory", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); return hash; } -#endif // defined(__x86_64__) || (defined(__i386__) && !defined(__pic__))) +#if defined(HAS_HAMMINGDISTANCE_AVX512BW) || \ + defined(HAS_HAMMINGDISTANCE_AVX512VNNI) || \ + defined(HAS_SUMSQUAREERROR_AVX512BW) || \ + defined(HAS_SUMSQUAREERROR_AVX512VNNI) || \ + defined(HAS_HASHDJB2_AVX512BW) || defined(HAS_SSIM4X4ROW_AVX512BW) +// Mask of the low n bytes, for n = 0 to 63. +static uint64_t LowBytesMask64(int n) { + return n ? ~0ULL >> (64 - n) : 0ULL; +} +#endif + +#ifdef HAS_HAMMINGDISTANCE_AVX512BW +// Process 64 bytes per loop and the remainder of 1 to 63 bytes with masked +// loads that read zeros, so any count is supported. +LIBYUV_TARGET_AVX512BW +uint32_t HammingDistance_AVX512BW(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t diff; + const uint64_t mask = LowBytesMask64(count & 63); + asm volatile( + "vbroadcasti32x4 %[nibble],%%zmm2 \n" + "vbroadcasti32x4 %[bitcount],%%zmm3 \n" + "vpxord %%zmm0,%%zmm0,%%zmm0 \n" + "vpxord %%zmm1,%%zmm1,%%zmm1 \n" + "kmovq %[mask],%%k1 \n" + "sub %[src_a],%[src_b] \n" + "sub $0x40,%[count] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src_a]),%%zmm4 \n" + "vpxorq (%[src_a],%[src_b]),%%zmm4,%%zmm4 \n" + "add $0x40,%[src_a] \n" + "vpandq %%zmm2,%%zmm4,%%zmm5 \n" + "vpsrlw $0x4,%%zmm4,%%zmm4 \n" + "vpandq %%zmm2,%%zmm4,%%zmm4 \n" + "vpshufb %%zmm5,%%zmm3,%%zmm5 \n" + "vpshufb %%zmm4,%%zmm3,%%zmm4 \n" + "vpaddb %%zmm5,%%zmm4,%%zmm4 \n" + "vpsadbw %%zmm1,%%zmm4,%%zmm4 \n" + "vpaddq %%zmm4,%%zmm0,%%zmm0 \n" + "sub $0x40,%[count] \n" + "jge 1b \n" + + // Remainder: 1 to 63 bytes, masked loads. + "2: \n" + "add $0x40,%[count] \n" + "je 3f \n" + "vmovdqu8 (%[src_a]),%%zmm4%{%%k1%}%{z%} \n" + "vmovdqu8 (%[src_a],%[src_b]),%%zmm5%{%%k1%}%{z%} \n" + "vpxorq %%zmm5,%%zmm4,%%zmm4 \n" + "vpandq %%zmm2,%%zmm4,%%zmm5 \n" + "vpsrlw $0x4,%%zmm4,%%zmm4 \n" + "vpandq %%zmm2,%%zmm4,%%zmm4 \n" + "vpshufb %%zmm5,%%zmm3,%%zmm5 \n" + "vpshufb %%zmm4,%%zmm3,%%zmm4 \n" + "vpaddb %%zmm5,%%zmm4,%%zmm4 \n" + "vpsadbw %%zmm1,%%zmm4,%%zmm4 \n" + "vpaddq %%zmm4,%%zmm0,%%zmm0 \n" + + // Add 8 qwords. + "3: \n" + "vextracti64x4 $1,%%zmm0,%%ymm1 \n" + "vpaddq %%ymm1,%%ymm0,%%ymm0 \n" + "vextracti128 $1,%%ymm0,%%xmm1 \n" + "vpaddq %%xmm1,%%xmm0,%%xmm0 \n" + "vpshufd $0xee,%%xmm0,%%xmm1 \n" + "vpaddq %%xmm1,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,%[diff] \n" + "vzeroupper \n" + : [src_a] "+r"(src_a), [src_b] "+r"(src_b), [count] "+r"(count), + [diff] "=r"(diff) + : [nibble] "m"(kNibbleMask), [bitcount] "m"(kBitCount), [mask] "m"(mask) + : "memory", "cc", "k1", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + return diff; +} +#endif // HAS_HAMMINGDISTANCE_AVX512BW + +#ifdef HAS_HAMMINGDISTANCE_AVX512VNNI +// Process 64 bytes per loop and the remainder of 1 to 63 bytes with masked +// loads that read zeros, accumulating byte popcounts with vpdpbusd. +uint32_t HammingDistance_AVX512VNNI(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t diff; + const uint64_t mask = LowBytesMask64(count & 63); + asm volatile( + "vbroadcasti32x4 %[nibble],%%zmm2 \n" + "vbroadcasti32x4 %[bitcount],%%zmm3 \n" + "vpxord %%zmm0,%%zmm0,%%zmm0 \n" + "vpternlogd $0xff,%%zmm1,%%zmm1,%%zmm1 \n" + "vpsrlw $0xf,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm0,%%zmm1,%%zmm1 \n" + "kmovq %[mask],%%k1 \n" + "sub %[src_a],%[src_b] \n" + "sub $0x40,%[count] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src_a]),%%zmm4 \n" + "vpxorq (%[src_a],%[src_b]),%%zmm4,%%zmm4 \n" + "add $0x40,%[src_a] \n" + "vpandq %%zmm2,%%zmm4,%%zmm5 \n" + "vpsrlw $0x4,%%zmm4,%%zmm4 \n" + "vpandq %%zmm2,%%zmm4,%%zmm4 \n" + "vpshufb %%zmm5,%%zmm3,%%zmm5 \n" + "vpshufb %%zmm4,%%zmm3,%%zmm4 \n" + "vpaddb %%zmm5,%%zmm4,%%zmm4 \n" + "vpdpbusd %%zmm4,%%zmm1,%%zmm0 \n" + "sub $0x40,%[count] \n" + "jge 1b \n" + + // Remainder: 1 to 63 bytes, masked loads. + "2: \n" + "add $0x40,%[count] \n" + "je 3f \n" + "vmovdqu8 (%[src_a]),%%zmm4%{%%k1%}%{z%} \n" + "vmovdqu8 (%[src_a],%[src_b]),%%zmm5%{%%k1%}%{z%} \n" + "vpxorq %%zmm5,%%zmm4,%%zmm4 \n" + "vpandq %%zmm2,%%zmm4,%%zmm5 \n" + "vpsrlw $0x4,%%zmm4,%%zmm4 \n" + "vpandq %%zmm2,%%zmm4,%%zmm4 \n" + "vpshufb %%zmm5,%%zmm3,%%zmm5 \n" + "vpshufb %%zmm4,%%zmm3,%%zmm4 \n" + "vpaddb %%zmm5,%%zmm4,%%zmm4 \n" + "vpdpbusd %%zmm4,%%zmm1,%%zmm0 \n" + + // Add 16 dwords. + "3: \n" + "vextracti64x4 $1,%%zmm0,%%ymm1 \n" + "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" + "vextracti128 $1,%%ymm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpshufd $0xee,%%xmm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpshufd $0x1,%%xmm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,%[diff] \n" + "vzeroupper \n" + : [src_a] "+r"(src_a), [src_b] "+r"(src_b), [count] "+r"(count), + [diff] "=r"(diff) + : [nibble] "m"(kNibbleMask), [bitcount] "m"(kBitCount), [mask] "m"(mask) + : "memory", "cc", "k1", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + return diff; +} +#endif // HAS_HAMMINGDISTANCE_AVX512VNNI + +#ifdef HAS_SUMSQUAREERROR_AVX512BW +// Process 64 bytes per loop and the remainder of 1 to 63 bytes with masked +// loads that read zeros, so any count is supported. +LIBYUV_TARGET_AVX512BW +uint32_t SumSquareError_AVX512BW(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t sse; + const uint64_t mask = LowBytesMask64(count & 63); + asm volatile( + "vpxord %%zmm0,%%zmm0,%%zmm0 \n" + "vpxord %%zmm5,%%zmm5,%%zmm5 \n" + "kmovq %[mask],%%k1 \n" + "sub %[src_a],%[src_b] \n" + "sub $0x40,%[count] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src_a]),%%zmm1 \n" + "vmovdqu8 (%[src_a],%[src_b]),%%zmm2 \n" + "add $0x40,%[src_a] \n" + "vpsubusb %%zmm2,%%zmm1,%%zmm3 \n" // abs difference trick + "vpsubusb %%zmm1,%%zmm2,%%zmm2 \n" + "vporq %%zmm3,%%zmm2,%%zmm1 \n" + "vpunpcklbw %%zmm5,%%zmm1,%%zmm2 \n" // u16 + "vpunpckhbw %%zmm5,%%zmm1,%%zmm1 \n" + "vpmaddwd %%zmm2,%%zmm2,%%zmm2 \n" // square + hadd to u32 + "vpmaddwd %%zmm1,%%zmm1,%%zmm1 \n" + "vpaddd %%zmm2,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm1,%%zmm0,%%zmm0 \n" + "sub $0x40,%[count] \n" + "jge 1b \n" + + // Remainder: 1 to 63 bytes, masked loads. + "2: \n" + "add $0x40,%[count] \n" + "je 3f \n" + "vmovdqu8 (%[src_a]),%%zmm1%{%%k1%}%{z%} \n" + "vmovdqu8 (%[src_a],%[src_b]),%%zmm2%{%%k1%}%{z%} \n" + "vpsubusb %%zmm2,%%zmm1,%%zmm3 \n" + "vpsubusb %%zmm1,%%zmm2,%%zmm2 \n" + "vporq %%zmm3,%%zmm2,%%zmm1 \n" + "vpunpcklbw %%zmm5,%%zmm1,%%zmm2 \n" + "vpunpckhbw %%zmm5,%%zmm1,%%zmm1 \n" + "vpmaddwd %%zmm2,%%zmm2,%%zmm2 \n" + "vpmaddwd %%zmm1,%%zmm1,%%zmm1 \n" + "vpaddd %%zmm2,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm1,%%zmm0,%%zmm0 \n" + + // Add 16 dwords. + "3: \n" + "vextracti64x4 $1,%%zmm0,%%ymm1 \n" + "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" + "vextracti128 $1,%%ymm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpshufd $0xee,%%xmm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpshufd $0x1,%%xmm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,%[sse] \n" + "vzeroupper \n" + : [src_a] "+r"(src_a), [src_b] "+r"(src_b), [count] "+r"(count), + [sse] "=r"(sse) + : [mask] "m"(mask) + : "memory", "cc", "k1", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); + return sse; +} +#endif // HAS_SUMSQUAREERROR_AVX512BW + +#ifdef HAS_SUMSQUAREERROR_AVX512VNNI +// Process 64 bytes per loop and the remainder of 1 to 63 bytes with masked +// loads that read zeros, so any count is supported. +LIBYUV_TARGET_AVX512VNNI +uint32_t SumSquareError_AVX512VNNI(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t sse; + const uint64_t mask = LowBytesMask64(count & 63); + asm volatile( + "vpxord %%zmm0,%%zmm0,%%zmm0 \n" + "vpxord %%zmm4,%%zmm4,%%zmm4 \n" + "vpxord %%zmm5,%%zmm5,%%zmm5 \n" + "kmovq %[mask],%%k1 \n" + "sub %[src_a],%[src_b] \n" + "sub $0x40,%[count] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src_a]),%%zmm1 \n" + "vmovdqu8 (%[src_a],%[src_b]),%%zmm2 \n" + "add $0x40,%[src_a] \n" + "vpsubusb %%zmm2,%%zmm1,%%zmm3 \n" // abs difference trick + "vpsubusb %%zmm1,%%zmm2,%%zmm2 \n" + "vporq %%zmm3,%%zmm2,%%zmm1 \n" + "vpunpcklbw %%zmm5,%%zmm1,%%zmm2 \n" // u16 + "vpunpckhbw %%zmm5,%%zmm1,%%zmm1 \n" + "vpdpwssd %%zmm2,%%zmm2,%%zmm0 \n" // square + hadd + acc + "vpdpwssd %%zmm1,%%zmm1,%%zmm4 \n" + "sub $0x40,%[count] \n" + "jge 1b \n" + + // Remainder: 1 to 63 bytes, masked loads. + "2: \n" + "add $0x40,%[count] \n" + "je 3f \n" + "vmovdqu8 (%[src_a]),%%zmm1%{%%k1%}%{z%} \n" + "vmovdqu8 (%[src_a],%[src_b]),%%zmm2%{%%k1%}%{z%} \n" + "vpsubusb %%zmm2,%%zmm1,%%zmm3 \n" + "vpsubusb %%zmm1,%%zmm2,%%zmm2 \n" + "vporq %%zmm3,%%zmm2,%%zmm1 \n" + "vpunpcklbw %%zmm5,%%zmm1,%%zmm2 \n" + "vpunpckhbw %%zmm5,%%zmm1,%%zmm1 \n" + "vpdpwssd %%zmm2,%%zmm2,%%zmm0 \n" + "vpdpwssd %%zmm1,%%zmm1,%%zmm4 \n" + + // Add 16 dwords. + "3: \n" + "vpaddd %%zmm4,%%zmm0,%%zmm0 \n" + "vextracti64x4 $1,%%zmm0,%%ymm1 \n" + "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" + "vextracti128 $1,%%ymm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpshufd $0xee,%%xmm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpshufd $0x1,%%xmm0,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,%[sse] \n" + "vzeroupper \n" + : [src_a] "+r"(src_a), [src_b] "+r"(src_b), [count] "+r"(count), + [sse] "=r"(sse) + : [mask] "m"(mask) + : "memory", "cc", "k1", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + return sse; +} +#endif // HAS_SUMSQUAREERROR_AVX512VNNI + +#if defined(HAS_HASHDJB2_AVX2) || defined(HAS_HASHDJB2_AVX512BW) +// HashDjb2 is hash = hash * 33 ^ n + sum(src[i] * 33 ^ (n - 1 - i)). +// The 32 bit multipliers 33 ^ (63 - i) are split into 16 bit halves so that +// vpmaddwd can be used instead of vpmulld, which is 2 uops and 10 cycles. +// m = hi * 65536 + lo, with lo treated as signed and hi adjusted by the carry, +// so src * m = src * lo + ((src * hi) << 16) modulo 2 ^ 32. +// The first 64 are lo and the next 64 are hi. +static const uint16_t kHashMulLoHi[128] = { + // lo for 33 ^ 63 .. 33 ^ 0 + 0x0be1, 0x93c1, 0x9fa1, 0xaf81, 0x4361, 0xdb41, 0xf721, 0x1701, // + 0xbae1, 0x62c1, 0x8ea1, 0xbe81, 0x7261, 0x2a41, 0x6621, 0xa601, // + 0x69e1, 0x31c1, 0x7da1, 0xcd81, 0xa161, 0x7941, 0xd521, 0x3501, // + 0x18e1, 0x00c1, 0x6ca1, 0xdc81, 0xd061, 0xc841, 0x4421, 0xc401, // + 0xc7e1, 0xcfc1, 0x5ba1, 0xeb81, 0xff61, 0x1741, 0xb321, 0x5301, // + 0x76e1, 0x9ec1, 0x4aa1, 0xfa81, 0x2e61, 0x6641, 0x2221, 0xe201, // + 0x25e1, 0x6dc1, 0x39a1, 0x0981, 0x5d61, 0xb541, 0x9121, 0x7101, // + 0xd4e1, 0x3cc1, 0x28a1, 0x1881, 0x8c61, 0x0441, 0x0021, 0x0001, // + // hi for 33 ^ 63 .. 33 ^ 0 + 0xd8be, 0xef4c, 0x6458, 0x6022, 0x40f9, 0x193e, 0x6d5f, 0x31dc, // + 0x0945, 0xc238, 0x1567, 0xa38f, 0x3380, 0x301b, 0x664e, 0x031a, // + 0xd18c, 0xb8c6, 0x79f6, 0xae5d, 0x0549, 0xc219, 0x7a3f, 0x1338, // + 0x0095, 0xc1f5, 0xa107, 0xaf8c, 0x0552, 0x3e39, 0x3830, 0x1138, // + 0x655f, 0xccc5, 0x9999, 0xd61c, 0x829c, 0x1379, 0x2f23, 0xac18, // + 0xcee9, 0xc836, 0x72ac, 0x510d, 0xcc27, 0xb0da, 0xee16, 0x92da, // + 0x0c35, 0xa347, 0x3b40, 0x4f5f, 0x30f3, 0x855d, 0x040b, 0x747c, // + 0xec42, 0x4cfa, 0x0255, 0x0012, 0x0001, 0x0000, 0x0000, 0x0000, // +}; +#endif + +#ifdef HAS_HASHDJB2_AVX2 +// Sum of 32 words in ymm0 to ymm1 times 32 multipliers at offset 'o' words, +// added to xmm4 (lo) and xmm5 (hi). +#define HASH32_AVX2(o) \ + "vpmaddwd " #o \ + "*2(%[tbl]),%%ymm0,%%ymm2 \n" \ + "vpmaddwd " #o \ + "*2+0x20(%[tbl]),%%ymm1,%%ymm3 \n" \ + "vpaddd %%ymm2,%%ymm4,%%ymm4 \n" \ + "vpaddd %%ymm3,%%ymm4,%%ymm4 \n" \ + "vpmaddwd " #o \ + "*2+0x80(%[tbl]),%%ymm0,%%ymm2 \n" \ + "vpmaddwd " #o \ + "*2+0xa0(%[tbl]),%%ymm1,%%ymm3 \n" \ + "vpaddd %%ymm2,%%ymm5,%%ymm5 \n" \ + "vpaddd %%ymm3,%%ymm5,%%ymm5 \n" + +// lo + (hi << 16), add 8 dwords, and hash = hash * mul + sum. +#define HASHSUM_AVX2(mul) \ + "vpslld $0x10,%%ymm5,%%ymm5 \n" \ + "vpaddd %%ymm5,%%ymm4,%%ymm4 \n" \ + "vextracti128 $1,%%ymm4,%%xmm5 \n" \ + "vpaddd %%xmm5,%%xmm4,%%xmm4 \n" \ + "vpshufd $0xee,%%xmm4,%%xmm5 \n" \ + "vpaddd %%xmm5,%%xmm4,%%xmm4 \n" \ + "vpshufd $0x1,%%xmm4,%%xmm5 \n" \ + "vpaddd %%xmm5,%%xmm4,%%xmm4 \n" \ + "vmovd %%xmm4,%[sum] \n" \ + "imul $" #mul \ + ",%[seed],%[seed] \n" \ + "add %[sum],%[seed] \n" + +// Count is a multiple of 32. Process 64 bytes per loop with one horizontal +// add, then 32 bytes if needed. +uint32_t HashDjb2_AVX2(const uint8_t* src, int count, uint32_t seed) { + uint32_t sum; + asm volatile( + "sub $0x40,%[count] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vpmovzxbw (%[src]),%%ymm0 \n" + "vpmovzxbw 0x10(%[src]),%%ymm1 \n" + "vpmaddwd (%[tbl]),%%ymm0,%%ymm4 \n" + "vpmaddwd 0x20(%[tbl]),%%ymm1,%%ymm2 \n" + "vpaddd %%ymm2,%%ymm4,%%ymm4 \n" + "vpmaddwd 0x80(%[tbl]),%%ymm0,%%ymm5 \n" + "vpmaddwd 0xa0(%[tbl]),%%ymm1,%%ymm3 \n" + "vpaddd %%ymm3,%%ymm5,%%ymm5 \n" + "vpmovzxbw 0x20(%[src]),%%ymm0 \n" + "vpmovzxbw 0x30(%[src]),%%ymm1 \n" + "add $0x40,%[src] \n" // + HASH32_AVX2(32) // + HASHSUM_AVX2(0xf07f8801) // 33 ^ 64 + "sub $0x40,%[count] \n" + "jge 1b \n" + + // Remainder of 32 bytes. + "2: \n" + "add $0x40,%[count] \n" + "je 3f \n" + "vpmovzxbw (%[src]),%%ymm0 \n" + "vpmovzxbw 0x10(%[src]),%%ymm1 \n" + "vpxor %%ymm4,%%ymm4,%%ymm4 \n" + "vpxor %%ymm5,%%ymm5,%%ymm5 \n" // + HASH32_AVX2(32) // + HASHSUM_AVX2(0x1137c401) // 33 ^ 32 + + "3: \n" + "vzeroupper \n" + : + [src] "+r"(src), [count] "+r"(count), [seed] "+r"(seed), [sum] "=&r"(sum) + : [tbl] "r"(kHashMulLoHi) + : "cc", "memory", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + return seed; +} +#undef HASH32_AVX2 +#undef HASHSUM_AVX2 +#endif // HAS_HASHDJB2_AVX2 + +#ifdef HAS_HASHDJB2_AVX512BW +static uint32_t Pow33(int n) { + uint32_t r = 1u; + uint32_t b = 33u; + while (n) { + if (n & 1) { + r *= b; + } + b *= b; + n >>= 1; + } + return r; +} + +// Sum of 64 words in zmm0 and zmm1 times 33 ^ (63 - i), using lo multipliers +// in zmm4/zmm5 and hi multipliers in zmm6/zmm7, then hash = hash * mul + sum. +#define HASH64_AVX512BW(mul) \ + "vpmaddwd %%zmm6,%%zmm0,%%zmm2 \n" \ + "vpmaddwd %%zmm7,%%zmm1,%%zmm3 \n" \ + "vpmaddwd %%zmm4,%%zmm0,%%zmm0 \n" \ + "vpmaddwd %%zmm5,%%zmm1,%%zmm1 \n" \ + "vpaddd %%zmm3,%%zmm2,%%zmm2 \n" \ + "vpaddd %%zmm1,%%zmm0,%%zmm0 \n" \ + "vpslld $0x10,%%zmm2,%%zmm2 \n" \ + "vpaddd %%zmm2,%%zmm0,%%zmm0 \n" \ + "vextracti64x4 $1,%%zmm0,%%ymm1 \n" \ + "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" \ + "vextracti128 $1,%%ymm0,%%xmm1 \n" \ + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" \ + "vpshufd $0xee,%%xmm0,%%xmm1 \n" \ + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" \ + "vpshufd $0x1,%%xmm0,%%xmm1 \n" \ + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" \ + "vmovd %%xmm0,%[sum] \n" \ + "imul " mul \ + " \n" \ + "add %[sum],%[seed] \n" + +// Process 64 bytes per loop. The remainder of n = 1 to 63 bytes is loaded +// into the high n bytes with a masked load ending at src + count, so the +// same multipliers apply, and hash is multiplied by 33 ^ n. +LIBYUV_TARGET_AVX512BW +uint32_t HashDjb2_AVX512BW(const uint8_t* src, int count, uint32_t seed) { + const int n = count & 63; + const uint64_t mask = n ? ~0ULL << (64 - n) : 0ULL; + const uint32_t pow_n = Pow33(n); + intptr_t width = count; + uint32_t sum; + asm volatile( + "vmovdqu64 (%[tbl]),%%zmm4 \n" + "vmovdqu64 0x40(%[tbl]),%%zmm5 \n" + "vmovdqu64 0x80(%[tbl]),%%zmm6 \n" + "vmovdqu64 0xc0(%[tbl]),%%zmm7 \n" + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vpmovzxbw (%[src]),%%zmm0 \n" + "vpmovzxbw 0x20(%[src]),%%zmm1 \n" + "add $0x40,%[src] \n" // + HASH64_AVX512BW("$0xf07f8801,%[seed],%[seed]") // 33 ^ 64 + "sub $0x40,%[width] \n" + "jge 1b \n" + + // Remainder: 1 to 63 bytes, masked load into the high bytes. + "2: \n" + "add $0x40,%[width] \n" + "je 3f \n" + "kmovq %[mask],%%k1 \n" + "vmovdqu8 -0x40(%[src],%[width]),%%zmm0%{%%k1%}%{z%} \n" + "vextracti64x4 $1,%%zmm0,%%ymm1 \n" + "vpmovzxbw %%ymm0,%%zmm0 \n" + "vpmovzxbw %%ymm1,%%zmm1 \n" // + HASH64_AVX512BW("%[pow_n],%[seed]") + + "3: \n" + "vzeroupper \n" + : + [src] "+r"(src), [width] "+r"(width), [seed] "+r"(seed), [sum] "=&r"(sum) + : [tbl] "r"(kHashMulLoHi), [pow_n] "m"(pow_n), [mask] "m"(mask) + : "cc", "memory", "k1", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); + return seed; +} +#undef HASH64_AVX512BW +#endif // HAS_HASHDJB2_AVX512BW + +#ifdef HAS_SSIM4X4ROW_SSE2 +#define SSIM_ROW0_SSE2(LOAD_A, LOAD_B) \ + LOAD_A \ + LOAD_B \ + "movdqa %%xmm0,%%xmm2 \n" \ + "psrlw $0x8,%%xmm0 \n" \ + "psllw $0x8,%%xmm2 \n" \ + "psrlw $0x8,%%xmm2 \n" \ + "movdqa %%xmm0,%%xmm4 \n" \ + "paddw %%xmm2,%%xmm4 \n" \ + "movdqa %%xmm0,%%xmm6 \n" \ + "pmaddwd %%xmm6,%%xmm6 \n" \ + "movdqa %%xmm2,%%xmm3 \n" \ + "pmaddwd %%xmm3,%%xmm3 \n" \ + "paddd %%xmm3,%%xmm6 \n" \ + "movdqa %%xmm1,%%xmm3 \n" \ + "psrlw $0x8,%%xmm1 \n" \ + "psllw $0x8,%%xmm3 \n" \ + "psrlw $0x8,%%xmm3 \n" \ + "movdqa %%xmm1,%%xmm5 \n" \ + "paddw %%xmm3,%%xmm5 \n" \ + "pmaddwd %%xmm1,%%xmm0 \n" \ + "pmaddwd %%xmm3,%%xmm2 \n" \ + "movdqa %%xmm0,%%xmm7 \n" \ + "paddd %%xmm2,%%xmm7 \n" \ + "pmaddwd %%xmm1,%%xmm1 \n" \ + "pmaddwd %%xmm3,%%xmm3 \n" \ + "paddd %%xmm1,%%xmm6 \n" \ + "paddd %%xmm3,%%xmm6 \n" + +#define SSIM_ROW_SSE2(LOAD_A, LOAD_B) \ + LOAD_A \ + LOAD_B \ + "movdqa %%xmm0,%%xmm2 \n" \ + "psrlw $0x8,%%xmm0 \n" \ + "psllw $0x8,%%xmm2 \n" \ + "psrlw $0x8,%%xmm2 \n" \ + "paddw %%xmm0,%%xmm4 \n" \ + "paddw %%xmm2,%%xmm4 \n" \ + "movdqa %%xmm0,%%xmm3 \n" \ + "pmaddwd %%xmm3,%%xmm3 \n" \ + "paddd %%xmm3,%%xmm6 \n" \ + "movdqa %%xmm2,%%xmm3 \n" \ + "pmaddwd %%xmm3,%%xmm3 \n" \ + "paddd %%xmm3,%%xmm6 \n" \ + "movdqa %%xmm1,%%xmm3 \n" \ + "psrlw $0x8,%%xmm1 \n" \ + "psllw $0x8,%%xmm3 \n" \ + "psrlw $0x8,%%xmm3 \n" \ + "paddw %%xmm1,%%xmm5 \n" \ + "paddw %%xmm3,%%xmm5 \n" \ + "pmaddwd %%xmm1,%%xmm0 \n" \ + "pmaddwd %%xmm3,%%xmm2 \n" \ + "paddd %%xmm0,%%xmm7 \n" \ + "paddd %%xmm2,%%xmm7 \n" \ + "pmaddwd %%xmm1,%%xmm1 \n" \ + "pmaddwd %%xmm3,%%xmm3 \n" \ + "paddd %%xmm1,%%xmm6 \n" \ + "paddd %%xmm3,%%xmm6 \n" + +void Ssim4x4Row_SSE2(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + asm volatile( + LABELALIGN "1: \n" // + SSIM_ROW0_SSE2("movdqu (%[src_a]),%%xmm0\n", + "movdqu (%[src_b]),%%xmm1\n") // + "add %[stride_a],%[src_a] \n" + "add %[stride_b],%[src_b] \n" // + SSIM_ROW_SSE2("movdqu (%[src_a]),%%xmm0\n", + "movdqu (%[src_b]),%%xmm1\n") // + SSIM_ROW_SSE2("movdqu (%[src_a],%[stride_a]),%%xmm0\n", + "movdqu (%[src_b],%[stride_b]),%%xmm1\n") // + SSIM_ROW_SSE2("movdqu (%[src_a],%[stride_a],2),%%xmm0\n", + "movdqu (%[src_b],%[stride_b],2),%%xmm1\n") // + "sub %[stride_a],%[src_a] \n" + "sub %[stride_b],%[src_b] \n" + "add $0x10,%[src_a] \n" + "add $0x10,%[src_b] \n" + "pcmpeqd %%xmm0,%%xmm0 \n" + "psrlw $0xf,%%xmm0 \n" + "pmaddwd %%xmm0,%%xmm4 \n" + "pmaddwd %%xmm0,%%xmm5 \n" + "movdqa %%xmm4,%%xmm0 \n" + "punpckldq %%xmm5,%%xmm0 \n" + "punpckhdq %%xmm5,%%xmm4 \n" + "movdqa %%xmm6,%%xmm1 \n" + "punpckldq %%xmm7,%%xmm1 \n" + "punpckhdq %%xmm7,%%xmm6 \n" + "movdqa %%xmm0,%%xmm2 \n" + "punpcklqdq %%xmm1,%%xmm2 \n" + "punpckhqdq %%xmm1,%%xmm0 \n" + "movdqa %%xmm4,%%xmm3 \n" + "punpcklqdq %%xmm6,%%xmm3 \n" + "punpckhqdq %%xmm6,%%xmm4 \n" + "movdqu %%xmm2,0x00(%[dst]) \n" + "movdqu %%xmm0,0x10(%[dst]) \n" + "movdqu %%xmm3,0x20(%[dst]) \n" + "movdqu %%xmm4,0x30(%[dst]) \n" + "add $0x40,%[dst] \n" + "subl $0x10,%[width] \n" + "jg 1b \n" + : [src_a] "+r"(src_a), [src_b] "+r"(src_b), [dst] "+r"(dst), + [width] "+rm"(width) + : [stride_a] "r"((ptrdiff_t)stride_a), [stride_b] "r"((ptrdiff_t)stride_b) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#undef SSIM_ROW0_SSE2 +#undef SSIM_ROW_SSE2 +#endif // HAS_SSIM4X4ROW_SSE2 + +#ifdef HAS_SSIM4X4ROW_AVX2 +#define SSIM_ROW0_AVX2(LOAD_A, LOAD_B) \ + LOAD_A \ + LOAD_B \ + "vpsrlw $0x8,%%ymm0,%%ymm2 \n" \ + "vpsllw $0x8,%%ymm0,%%ymm0 \n" \ + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" \ + "vpaddw %%ymm0,%%ymm2,%%ymm4 \n" \ + "vpmaddwd %%ymm2,%%ymm2,%%ymm6 \n" \ + "vpmaddwd %%ymm0,%%ymm0,%%ymm3 \n" \ + "vpaddd %%ymm3,%%ymm6,%%ymm6 \n" \ + "vpsrlw $0x8,%%ymm1,%%ymm3 \n" \ + "vpsllw $0x8,%%ymm1,%%ymm1 \n" \ + "vpsrlw $0x8,%%ymm1,%%ymm1 \n" \ + "vpaddw %%ymm1,%%ymm3,%%ymm5 \n" \ + "vpmaddwd %%ymm3,%%ymm2,%%ymm7 \n" \ + "vpmaddwd %%ymm1,%%ymm0,%%ymm0 \n" \ + "vpaddd %%ymm0,%%ymm7,%%ymm7 \n" \ + "vpmaddwd %%ymm3,%%ymm3,%%ymm3 \n" \ + "vpmaddwd %%ymm1,%%ymm1,%%ymm1 \n" \ + "vpaddd %%ymm3,%%ymm6,%%ymm6 \n" \ + "vpaddd %%ymm1,%%ymm6,%%ymm6 \n" + +#define SSIM_ROW_AVX2(LOAD_A, LOAD_B) \ + LOAD_A \ + LOAD_B \ + "vpsrlw $0x8,%%ymm0,%%ymm2 \n" \ + "vpsllw $0x8,%%ymm0,%%ymm0 \n" \ + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" \ + "vpaddw %%ymm2,%%ymm4,%%ymm4 \n" \ + "vpaddw %%ymm0,%%ymm4,%%ymm4 \n" \ + "vpmaddwd %%ymm2,%%ymm2,%%ymm3 \n" \ + "vpaddd %%ymm3,%%ymm6,%%ymm6 \n" \ + "vpmaddwd %%ymm0,%%ymm0,%%ymm3 \n" \ + "vpaddd %%ymm3,%%ymm6,%%ymm6 \n" \ + "vpsrlw $0x8,%%ymm1,%%ymm3 \n" \ + "vpsllw $0x8,%%ymm1,%%ymm1 \n" \ + "vpsrlw $0x8,%%ymm1,%%ymm1 \n" \ + "vpaddw %%ymm3,%%ymm5,%%ymm5 \n" \ + "vpaddw %%ymm1,%%ymm5,%%ymm5 \n" \ + "vpmaddwd %%ymm3,%%ymm2,%%ymm2 \n" \ + "vpmaddwd %%ymm1,%%ymm0,%%ymm0 \n" \ + "vpaddd %%ymm2,%%ymm7,%%ymm7 \n" \ + "vpaddd %%ymm0,%%ymm7,%%ymm7 \n" \ + "vpmaddwd %%ymm3,%%ymm3,%%ymm3 \n" \ + "vpmaddwd %%ymm1,%%ymm1,%%ymm1 \n" \ + "vpaddd %%ymm3,%%ymm6,%%ymm6 \n" \ + "vpaddd %%ymm1,%%ymm6,%%ymm6 \n" + +void Ssim4x4Row_AVX2(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + asm volatile( + LABELALIGN "1: \n" // + SSIM_ROW0_AVX2("vmovdqu (%[src_a]),%%ymm0\n", + "vmovdqu (%[src_b]),%%ymm1\n") // + "add %[stride_a],%[src_a] \n" + "add %[stride_b],%[src_b] \n" // + SSIM_ROW_AVX2("vmovdqu (%[src_a]),%%ymm0\n", + "vmovdqu (%[src_b]),%%ymm1\n") // + SSIM_ROW_AVX2("vmovdqu (%[src_a],%[stride_a]),%%ymm0\n", + "vmovdqu (%[src_b],%[stride_b]),%%ymm1\n") // + SSIM_ROW_AVX2("vmovdqu (%[src_a],%[stride_a],2),%%ymm0\n", + "vmovdqu (%[src_b],%[stride_b],2),%%ymm1\n") // + "sub %[stride_a],%[src_a] \n" + "sub %[stride_b],%[src_b] \n" + "add $0x20,%[src_a] \n" + "add $0x20,%[src_b] \n" + "vpcmpeqd %%ymm0,%%ymm0,%%ymm0 \n" + "vpsrlw $0xf,%%ymm0,%%ymm0 \n" + "vpmaddwd %%ymm0,%%ymm4,%%ymm4 \n" + "vpmaddwd %%ymm0,%%ymm5,%%ymm5 \n" + "vpunpckldq %%ymm5,%%ymm4,%%ymm0 \n" + "vpunpckhdq %%ymm5,%%ymm4,%%ymm1 \n" + "vpunpckldq %%ymm7,%%ymm6,%%ymm2 \n" + "vpunpckhdq %%ymm7,%%ymm6,%%ymm3 \n" + "vpunpcklqdq %%ymm2,%%ymm0,%%ymm4 \n" + "vpunpckhqdq %%ymm2,%%ymm0,%%ymm5 \n" + "vpunpcklqdq %%ymm3,%%ymm1,%%ymm6 \n" + "vpunpckhqdq %%ymm3,%%ymm1,%%ymm7 \n" + "vperm2i128 $0x20,%%ymm5,%%ymm4,%%ymm0 \n" + "vperm2i128 $0x20,%%ymm7,%%ymm6,%%ymm1 \n" + "vperm2i128 $0x31,%%ymm5,%%ymm4,%%ymm2 \n" + "vperm2i128 $0x31,%%ymm7,%%ymm6,%%ymm3 \n" + "vmovdqu %%ymm0,0x00(%[dst]) \n" + "vmovdqu %%ymm1,0x20(%[dst]) \n" + "vmovdqu %%ymm2,0x40(%[dst]) \n" + "vmovdqu %%ymm3,0x60(%[dst]) \n" + "add $0x80,%[dst] \n" + "subl $0x20,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src_a] "+r"(src_a), [src_b] "+r"(src_b), [dst] "+r"(dst), + [width] "+rm"(width) + : [stride_a] "r"((ptrdiff_t)stride_a), [stride_b] "r"((ptrdiff_t)stride_b) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#undef SSIM_ROW0_AVX2 +#undef SSIM_ROW_AVX2 +#endif // HAS_SSIM4X4ROW_AVX2 + +#ifdef HAS_SSIM4X4ROW_AVX512BW +#define SSIM_ROW0_AVX512BW(LOAD_A, LOAD_B) \ + LOAD_A \ + LOAD_B \ + "vpsrlw $0x8,%%zmm0,%%zmm2 \n" \ + "vpsllw $0x8,%%zmm0,%%zmm0 \n" \ + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" \ + "vpaddw %%zmm0,%%zmm2,%%zmm4 \n" \ + "vpmaddwd %%zmm2,%%zmm2,%%zmm6 \n" \ + "vpmaddwd %%zmm0,%%zmm0,%%zmm3 \n" \ + "vpaddd %%zmm3,%%zmm6,%%zmm6 \n" \ + "vpsrlw $0x8,%%zmm1,%%zmm3 \n" \ + "vpsllw $0x8,%%zmm1,%%zmm1 \n" \ + "vpsrlw $0x8,%%zmm1,%%zmm1 \n" \ + "vpaddw %%zmm1,%%zmm3,%%zmm5 \n" \ + "vpmaddwd %%zmm3,%%zmm2,%%zmm7 \n" \ + "vpmaddwd %%zmm1,%%zmm0,%%zmm0 \n" \ + "vpaddd %%zmm0,%%zmm7,%%zmm7 \n" \ + "vpmaddwd %%zmm3,%%zmm3,%%zmm3 \n" \ + "vpmaddwd %%zmm1,%%zmm1,%%zmm1 \n" \ + "vpaddd %%zmm3,%%zmm6,%%zmm6 \n" \ + "vpaddd %%zmm1,%%zmm6,%%zmm6 \n" + +#define SSIM_ROW_AVX512BW(LOAD_A, LOAD_B) \ + LOAD_A \ + LOAD_B \ + "vpsrlw $0x8,%%zmm0,%%zmm2 \n" \ + "vpsllw $0x8,%%zmm0,%%zmm0 \n" \ + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" \ + "vpaddw %%zmm2,%%zmm4,%%zmm4 \n" \ + "vpaddw %%zmm0,%%zmm4,%%zmm4 \n" \ + "vpmaddwd %%zmm2,%%zmm2,%%zmm3 \n" \ + "vpaddd %%zmm3,%%zmm6,%%zmm6 \n" \ + "vpmaddwd %%zmm0,%%zmm0,%%zmm3 \n" \ + "vpaddd %%zmm3,%%zmm6,%%zmm6 \n" \ + "vpsrlw $0x8,%%zmm1,%%zmm3 \n" \ + "vpsllw $0x8,%%zmm1,%%zmm1 \n" \ + "vpsrlw $0x8,%%zmm1,%%zmm1 \n" \ + "vpaddw %%zmm3,%%zmm5,%%zmm5 \n" \ + "vpaddw %%zmm1,%%zmm5,%%zmm5 \n" \ + "vpmaddwd %%zmm3,%%zmm2,%%zmm2 \n" \ + "vpmaddwd %%zmm1,%%zmm0,%%zmm0 \n" \ + "vpaddd %%zmm2,%%zmm7,%%zmm7 \n" \ + "vpaddd %%zmm0,%%zmm7,%%zmm7 \n" \ + "vpmaddwd %%zmm3,%%zmm3,%%zmm3 \n" \ + "vpmaddwd %%zmm1,%%zmm1,%%zmm1 \n" \ + "vpaddd %%zmm3,%%zmm6,%%zmm6 \n" \ + "vpaddd %%zmm1,%%zmm6,%%zmm6 \n" + +#define SSIM_TRANSPOSE_AVX512BW \ + "vpternlogd $0xff,%%zmm0,%%zmm0,%%zmm0 \n" \ + "vpsrlw $0xf,%%zmm0,%%zmm0 \n" \ + "vpmaddwd %%zmm0,%%zmm4,%%zmm4 \n" \ + "vpmaddwd %%zmm0,%%zmm5,%%zmm5 \n" \ + "vpunpckldq %%zmm5,%%zmm4,%%zmm0 \n" \ + "vpunpckhdq %%zmm5,%%zmm4,%%zmm1 \n" \ + "vpunpckldq %%zmm7,%%zmm6,%%zmm2 \n" \ + "vpunpckhdq %%zmm7,%%zmm6,%%zmm3 \n" \ + "vpunpcklqdq %%zmm2,%%zmm0,%%zmm4 \n" \ + "vpunpckhqdq %%zmm2,%%zmm0,%%zmm5 \n" \ + "vpunpcklqdq %%zmm3,%%zmm1,%%zmm6 \n" \ + "vpunpckhqdq %%zmm3,%%zmm1,%%zmm7 \n" \ + "vshufi32x4 $0x44,%%zmm5,%%zmm4,%%zmm0 \n" \ + "vshufi32x4 $0x44,%%zmm7,%%zmm6,%%zmm1 \n" \ + "vshufi32x4 $0xee,%%zmm5,%%zmm4,%%zmm2 \n" \ + "vshufi32x4 $0xee,%%zmm7,%%zmm6,%%zmm3 \n" \ + "vshufi32x4 $0x88,%%zmm1,%%zmm0,%%zmm4 \n" \ + "vshufi32x4 $0xdd,%%zmm1,%%zmm0,%%zmm5 \n" \ + "vshufi32x4 $0x88,%%zmm3,%%zmm2,%%zmm6 \n" \ + "vshufi32x4 $0xdd,%%zmm3,%%zmm2,%%zmm7 \n" + +// Process 64 pixels (16 4x4 tiles) per loop and the remainder of 4 to 60 +// pixels (1 to 15 tiles) with masked loads and stores. +LIBYUV_TARGET_AVX512BW +void Ssim4x4Row_AVX512BW(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + const int rem = width & 60; + const uint16_t load_mask = rem ? (uint16_t)((1U << (rem >> 2)) - 1U) : 0U; + const uint64_t store_mask = LowBytesMask64(rem); + asm volatile( + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN "1: \n" // + SSIM_ROW0_AVX512BW("vmovdqu8 (%[src_a]),%%zmm0\n", + "vmovdqu8 (%[src_b]),%%zmm1\n") // + "add %[stride_a],%[src_a] \n" + "add %[stride_b],%[src_b] \n" // + SSIM_ROW_AVX512BW("vmovdqu8 (%[src_a]),%%zmm0\n", + "vmovdqu8 (%[src_b]),%%zmm1\n") // + SSIM_ROW_AVX512BW("vmovdqu8 (%[src_a],%[stride_a]),%%zmm0\n", + "vmovdqu8 (%[src_b],%[stride_b]),%%zmm1\n") // + SSIM_ROW_AVX512BW("vmovdqu8 (%[src_a],%[stride_a],2),%%zmm0\n", + "vmovdqu8 (%[src_b],%[stride_b],2),%%zmm1\n") // + "sub %[stride_a],%[src_a] \n" + "sub %[stride_b],%[src_b] \n" + "add $0x40,%[src_a] \n" + "add $0x40,%[src_b] \n" // + SSIM_TRANSPOSE_AVX512BW + "vmovdqu32 %%zmm4,0x00(%[dst]) \n" + "vmovdqu32 %%zmm5,0x40(%[dst]) \n" + "vmovdqu32 %%zmm6,0x80(%[dst]) \n" + "vmovdqu32 %%zmm7,0xc0(%[dst]) \n" + "add $0x100,%[dst] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "je 3f \n" + "kmovw %[load_mask],%%k1 \n" // + SSIM_ROW0_AVX512BW("vmovdqu32 (%[src_a]),%%zmm0%{%%k1%}%{z%}\n", + "vmovdqu32 (%[src_b]),%%zmm1%{%%k1%}%{z%}\n") // + "add %[stride_a],%[src_a] \n" + "add %[stride_b],%[src_b] \n" // + SSIM_ROW_AVX512BW("vmovdqu32 (%[src_a]),%%zmm0%{%%k1%}%{z%}\n", + "vmovdqu32 (%[src_b]),%%zmm1%{%%k1%}%{z%}\n") // + SSIM_ROW_AVX512BW( + "vmovdqu32 (%[src_a],%[stride_a]),%%zmm0%{%%k1%}%{z%}\n", + "vmovdqu32 (%[src_b],%[stride_b]),%%zmm1%{%%k1%}%{z%}\n") // + SSIM_ROW_AVX512BW( + "vmovdqu32 (%[src_a],%[stride_a],2),%%zmm0%{%%k1%}%{z%}\n", + "vmovdqu32 (%[src_b],%[stride_b],2),%%zmm1%{%%k1%}%{z%}\n") // + SSIM_TRANSPOSE_AVX512BW + "kmovq %[store_mask],%%k1 \n" + "vmovdqu32 %%zmm4,0x00(%[dst])%{%%k1%} \n" + "kshiftrq $0x10,%%k1,%%k1 \n" + "vmovdqu32 %%zmm5,0x40(%[dst])%{%%k1%} \n" + "kshiftrq $0x10,%%k1,%%k1 \n" + "vmovdqu32 %%zmm6,0x80(%[dst])%{%%k1%} \n" + "kshiftrq $0x10,%%k1,%%k1 \n" + "vmovdqu32 %%zmm7,0xc0(%[dst])%{%%k1%} \n" + + "3: \n" + "vzeroupper \n" + : [src_a] "+r"(src_a), [src_b] "+r"(src_b), [dst] "+r"(dst), + [width] "+r"(width) + : [stride_a] "r"((ptrdiff_t)stride_a), + [stride_b] "r"((ptrdiff_t)stride_b), [load_mask] "m"(load_mask), + [store_mask] "m"(store_mask) + : "memory", "cc", "k1", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); +} +#undef SSIM_ROW0_AVX512BW +#undef SSIM_ROW_AVX512BW +#undef SSIM_TRANSPOSE_AVX512BW +#endif // HAS_SSIM4X4ROW_AVX512BW + +#if defined(HAS_SSIMWINDOWROW_SSE2) || defined(HAS_SSIMWINDOWROW_AVX2) || \ + defined(HAS_SSIMWINDOWROW_AVX512BW) +static const uvec32 kSsimC1 = {26634, 26634, 26634, 26634}; +static const uvec32 kSsimC2 = {239708, 239708, 239708, 239708}; +#endif + +#ifdef HAS_SSIMWINDOWROW_SSE2 +// num_windows is a multiple of 4. +float SsimWindowRow_SSE2(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + float total; + asm volatile( + "sub %[row0],%[row1] \n" + "xorps %%xmm0,%%xmm0 \n" + + LABELALIGN + "1: \n" + "movdqu 0x00(%[row0]),%%xmm1 \n" + "movdqu 0x00(%[row0],%[row1]),%%xmm5 \n" + "paddd %%xmm5,%%xmm1 \n" + "movdqu 0x10(%[row0]),%%xmm2 \n" + "movdqu 0x10(%[row0],%[row1]),%%xmm5 \n" + "paddd %%xmm5,%%xmm2 \n" + "movdqu 0x20(%[row0]),%%xmm3 \n" + "movdqu 0x20(%[row0],%[row1]),%%xmm5 \n" + "paddd %%xmm5,%%xmm3 \n" + "movdqu 0x30(%[row0]),%%xmm4 \n" + "movdqu 0x30(%[row0],%[row1]),%%xmm5 \n" + "paddd %%xmm5,%%xmm4 \n" + "movdqu 0x40(%[row0]),%%xmm5 \n" + "add $0x40,%[row0] \n" + "paddd %%xmm2,%%xmm1 \n" + "paddd %%xmm3,%%xmm2 \n" + "paddd %%xmm4,%%xmm3 \n" + "paddd %%xmm5,%%xmm4 \n" + "movdqu 0x00(%[row0],%[row1]),%%xmm5 \n" + "paddd %%xmm5,%%xmm4 \n" + "movdqa %%xmm1,%%xmm5 \n" + "punpckldq %%xmm2,%%xmm1 \n" + "punpckhdq %%xmm2,%%xmm5 \n" + "movdqa %%xmm3,%%xmm2 \n" + "punpckldq %%xmm4,%%xmm3 \n" + "punpckhdq %%xmm4,%%xmm2 \n" + "movdqa %%xmm1,%%xmm4 \n" + "punpcklqdq %%xmm3,%%xmm1 \n" + "punpckhqdq %%xmm3,%%xmm4 \n" + "movdqa %%xmm5,%%xmm3 \n" + "punpcklqdq %%xmm2,%%xmm3 \n" + "punpckhqdq %%xmm2,%%xmm5 \n" + "movdqa %%xmm1,%%xmm2 \n" + "pmaddwd %%xmm4,%%xmm2 \n" + "pmaddwd %%xmm1,%%xmm1 \n" + "pmaddwd %%xmm4,%%xmm4 \n" + "paddd %%xmm4,%%xmm1 \n" + "pslld $0x1,%%xmm2 \n" + "pslld $0x7,%%xmm5 \n" + "psubd %%xmm2,%%xmm5 \n" + "paddd %[c1],%%xmm2 \n" + "paddd %[c2],%%xmm5 \n" + "pslld $0x6,%%xmm3 \n" + "psubd %%xmm1,%%xmm3 \n" + "paddd %[c1],%%xmm1 \n" + "paddd %[c2],%%xmm3 \n" + "cvtdq2ps %%xmm2,%%xmm2 \n" + "cvtdq2ps %%xmm5,%%xmm5 \n" + "cvtdq2ps %%xmm1,%%xmm1 \n" + "cvtdq2ps %%xmm3,%%xmm3 \n" + "mulps %%xmm5,%%xmm2 \n" + "mulps %%xmm3,%%xmm1 \n" + "divps %%xmm1,%%xmm2 \n" + "addps %%xmm2,%%xmm0 \n" + "sub $0x4,%[num_windows] \n" + "jg 1b \n" + + "movhlps %%xmm0,%%xmm1 \n" + "addps %%xmm1,%%xmm0 \n" + "movaps %%xmm0,%%xmm1 \n" + "shufps $0x1,%%xmm0,%%xmm1 \n" + "addss %%xmm1,%%xmm0 \n" + "movss %%xmm0,%[total] \n" + : [row0] "+r"(row0), [row1] "+r"(row1), [num_windows] "+r"(num_windows), + [total] "=m"(total) + : [c1] "m"(kSsimC1), [c2] "m"(kSsimC2) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + return total; +} +#endif // HAS_SSIMWINDOWROW_SSE2 + +#ifdef HAS_SSIMWINDOWROW_AVX2 +// num_windows is a multiple of 8. +float SsimWindowRow_AVX2(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + float total; + asm volatile( + "sub %[row0],%[row1] \n" + "vxorps %%ymm0,%%ymm0,%%ymm0 \n" + + LABELALIGN + "1: \n" + "vmovdqu 0x00(%[row0]),%%ymm1 \n" + "vpaddd 0x00(%[row0],%[row1]),%%ymm1,%%ymm1 \n" + "vmovdqu 0x10(%[row0]),%%ymm5 \n" + "vpaddd 0x10(%[row0],%[row1]),%%ymm5,%%ymm5 \n" + "vpaddd %%ymm5,%%ymm1,%%ymm1 \n" + "vmovdqu 0x20(%[row0]),%%ymm2 \n" + "vpaddd 0x20(%[row0],%[row1]),%%ymm2,%%ymm2 \n" + "vmovdqu 0x30(%[row0]),%%ymm5 \n" + "vpaddd 0x30(%[row0],%[row1]),%%ymm5,%%ymm5 \n" + "vpaddd %%ymm5,%%ymm2,%%ymm2 \n" + "vmovdqu 0x40(%[row0]),%%ymm3 \n" + "vpaddd 0x40(%[row0],%[row1]),%%ymm3,%%ymm3 \n" + "vmovdqu 0x50(%[row0]),%%ymm5 \n" + "vpaddd 0x50(%[row0],%[row1]),%%ymm5,%%ymm5 \n" + "vpaddd %%ymm5,%%ymm3,%%ymm3 \n" + "vmovdqu 0x60(%[row0]),%%ymm4 \n" + "vpaddd 0x60(%[row0],%[row1]),%%ymm4,%%ymm4 \n" + "vmovdqu 0x70(%[row0]),%%ymm5 \n" + "vpaddd 0x70(%[row0],%[row1]),%%ymm5,%%ymm5 \n" + "vpaddd %%ymm5,%%ymm4,%%ymm4 \n" + "add $0x80,%[row0] \n" + "vpunpckldq %%ymm2,%%ymm1,%%ymm5 \n" + "vpunpckhdq %%ymm2,%%ymm1,%%ymm1 \n" + "vpunpckldq %%ymm4,%%ymm3,%%ymm2 \n" + "vpunpckhdq %%ymm4,%%ymm3,%%ymm3 \n" + "vpunpcklqdq %%ymm2,%%ymm5,%%ymm4 \n" + "vpunpckhqdq %%ymm2,%%ymm5,%%ymm2 \n" + "vpunpcklqdq %%ymm3,%%ymm1,%%ymm5 \n" + "vpunpckhqdq %%ymm3,%%ymm1,%%ymm3 \n" + "vpmaddwd %%ymm2,%%ymm4,%%ymm1 \n" + "vpmaddwd %%ymm4,%%ymm4,%%ymm4 \n" + "vpmaddwd %%ymm2,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm2,%%ymm4,%%ymm4 \n" + "vpslld $0x1,%%ymm1,%%ymm1 \n" + "vpslld $0x7,%%ymm3,%%ymm3 \n" + "vpsubd %%ymm1,%%ymm3,%%ymm3 \n" + "vpslld $0x6,%%ymm5,%%ymm5 \n" + "vpsubd %%ymm4,%%ymm5,%%ymm5 \n" + "vpbroadcastd %[c1],%%ymm2 \n" + "vpaddd %%ymm2,%%ymm1,%%ymm1 \n" + "vpaddd %%ymm2,%%ymm4,%%ymm4 \n" + "vpbroadcastd %[c2],%%ymm2 \n" + "vpaddd %%ymm2,%%ymm3,%%ymm3 \n" + "vpaddd %%ymm2,%%ymm5,%%ymm5 \n" + "vcvtdq2ps %%ymm1,%%ymm1 \n" + "vcvtdq2ps %%ymm3,%%ymm3 \n" + "vcvtdq2ps %%ymm4,%%ymm4 \n" + "vcvtdq2ps %%ymm5,%%ymm5 \n" + "vmulps %%ymm3,%%ymm1,%%ymm1 \n" + "vmulps %%ymm5,%%ymm4,%%ymm4 \n" + "vdivps %%ymm4,%%ymm1,%%ymm1 \n" + "vaddps %%ymm1,%%ymm0,%%ymm0 \n" + "sub $0x8,%[num_windows] \n" + "jg 1b \n" + + "vextractf128 $0x1,%%ymm0,%%xmm1 \n" + "vaddps %%xmm1,%%xmm0,%%xmm0 \n" + "vmovhlps %%xmm0,%%xmm1,%%xmm1 \n" + "vaddps %%xmm1,%%xmm0,%%xmm0 \n" + "vshufps $0x1,%%xmm0,%%xmm0,%%xmm1 \n" + "vaddss %%xmm1,%%xmm0,%%xmm0 \n" + "vmovss %%xmm0,%[total] \n" + "vzeroupper \n" + : [row0] "+r"(row0), [row1] "+r"(row1), [num_windows] "+r"(num_windows), + [total] "=m"(total) + : [c1] "m"(kSsimC1), [c2] "m"(kSsimC2) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + return total; +} +#endif // HAS_SSIMWINDOWROW_AVX2 + +#ifdef HAS_SSIMWINDOWROW_AVX512BW +#define SSIM_WINDOW_AVX512BW \ + "vpunpckldq %%zmm2,%%zmm1,%%zmm5 \n" \ + "vpunpckhdq %%zmm2,%%zmm1,%%zmm1 \n" \ + "vpunpckldq %%zmm4,%%zmm3,%%zmm2 \n" \ + "vpunpckhdq %%zmm4,%%zmm3,%%zmm3 \n" \ + "vpunpcklqdq %%zmm2,%%zmm5,%%zmm4 \n" \ + "vpunpckhqdq %%zmm2,%%zmm5,%%zmm2 \n" \ + "vpunpcklqdq %%zmm3,%%zmm1,%%zmm5 \n" \ + "vpunpckhqdq %%zmm3,%%zmm1,%%zmm3 \n" \ + "vpmaddwd %%zmm2,%%zmm4,%%zmm1 \n" \ + "vpmaddwd %%zmm4,%%zmm4,%%zmm4 \n" \ + "vpmaddwd %%zmm2,%%zmm2,%%zmm2 \n" \ + "vpaddd %%zmm2,%%zmm4,%%zmm4 \n" \ + "vpslld $0x1,%%zmm1,%%zmm1 \n" \ + "vpslld $0x7,%%zmm3,%%zmm3 \n" \ + "vpsubd %%zmm1,%%zmm3,%%zmm3 \n" \ + "vpslld $0x6,%%zmm5,%%zmm5 \n" \ + "vpsubd %%zmm4,%%zmm5,%%zmm5 \n" \ + "vpaddd %[c1]%{1to16%},%%zmm1,%%zmm1 \n" \ + "vpaddd %[c2]%{1to16%},%%zmm3,%%zmm3 \n" \ + "vpaddd %[c1]%{1to16%},%%zmm4,%%zmm4 \n" \ + "vpaddd %[c2]%{1to16%},%%zmm5,%%zmm5 \n" \ + "vcvtdq2ps %%zmm1,%%zmm1 \n" \ + "vcvtdq2ps %%zmm3,%%zmm3 \n" \ + "vcvtdq2ps %%zmm4,%%zmm4 \n" \ + "vcvtdq2ps %%zmm5,%%zmm5 \n" \ + "vmulps %%zmm3,%%zmm1,%%zmm1 \n" \ + "vmulps %%zmm5,%%zmm4,%%zmm4 \n" \ + "vdivps %%zmm4,%%zmm1,%%zmm1 \n" + +// Process 16 8x8 windows per loop and the remainder of 1 to 15 windows with +// masked loads and masked accumulation. +LIBYUV_TARGET_AVX512BW +float SsimWindowRow_AVX512BW(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + const int rem = num_windows & 15; + const uint64_t load_mask = rem ? (~0ULL >> (60 - rem * 4)) : 0ULL; + const uint16_t win_mask = + (uint16_t)(((0x01110U >> (16 - (rem & 3) * 4)) << (rem >> 2)) + + (0x1111U << (rem >> 2)) - 0x1111U); + float total; + asm volatile( + "sub %[row0],%[row1] \n" + "vxorps %%xmm0,%%xmm0,%%xmm0 \n" + "sub $0x10,%[num_windows] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 0x00(%[row0]),%%zmm1 \n" + "vpaddd 0x00(%[row0],%[row1]),%%zmm1,%%zmm1 \n" + "vmovdqu32 0x40(%[row0]),%%zmm2 \n" + "vpaddd 0x40(%[row0],%[row1]),%%zmm2,%%zmm2 \n" + "vmovdqu32 0x80(%[row0]),%%zmm3 \n" + "vpaddd 0x80(%[row0],%[row1]),%%zmm3,%%zmm3 \n" + "vmovdqu32 0xc0(%[row0]),%%zmm4 \n" + "vpaddd 0xc0(%[row0],%[row1]),%%zmm4,%%zmm4 \n" + "valignd $0x4,%%zmm1,%%zmm2,%%zmm5 \n" + "vpaddd %%zmm5,%%zmm1,%%zmm1 \n" + "valignd $0x4,%%zmm2,%%zmm3,%%zmm5 \n" + "vpaddd %%zmm5,%%zmm2,%%zmm2 \n" + "valignd $0x4,%%zmm3,%%zmm4,%%zmm5 \n" + "vpaddd %%zmm5,%%zmm3,%%zmm3 \n" + "vmovdqu32 0xd0(%[row0]),%%zmm5 \n" + "vpaddd 0xd0(%[row0],%[row1]),%%zmm5,%%zmm5 \n" + "add $0x100,%[row0] \n" + "vpaddd %%zmm5,%%zmm4,%%zmm4 \n" // + SSIM_WINDOW_AVX512BW + "vaddps %%zmm1,%%zmm0,%%zmm0 \n" + "sub $0x10,%[num_windows] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[num_windows] \n" + "je 3f \n" + "kmovq %[load_mask],%%k1 \n" + "vmovdqu32 0x00(%[row0]),%%zmm1%{%%k1%}%{z%} \n" + "vpaddd 0x00(%[row0],%[row1]),%%zmm1,%%zmm1%{%%k1%}%{z%} \n" + "kshiftrq $0x10,%%k1,%%k1 \n" + "vmovdqu32 0x40(%[row0]),%%zmm2%{%%k1%}%{z%} \n" + "vpaddd 0x40(%[row0],%[row1]),%%zmm2,%%zmm2%{%%k1%}%{z%} \n" + "kshiftrq $0x10,%%k1,%%k1 \n" + "vmovdqu32 0x80(%[row0]),%%zmm3%{%%k1%}%{z%} \n" + "vpaddd 0x80(%[row0],%[row1]),%%zmm3,%%zmm3%{%%k1%}%{z%} \n" + "kshiftrq $0x10,%%k1,%%k1 \n" + "vmovdqu32 0xc0(%[row0]),%%zmm4%{%%k1%}%{z%} \n" + "vpaddd 0xc0(%[row0],%[row1]),%%zmm4,%%zmm4%{%%k1%}%{z%} \n" + "valignd $0x4,%%zmm1,%%zmm2,%%zmm5 \n" + "vpaddd %%zmm5,%%zmm1,%%zmm1 \n" + "valignd $0x4,%%zmm2,%%zmm3,%%zmm5 \n" + "vpaddd %%zmm5,%%zmm2,%%zmm2 \n" + "valignd $0x4,%%zmm3,%%zmm4,%%zmm5 \n" + "vpaddd %%zmm5,%%zmm3,%%zmm3 \n" + "valignd $0x4,%%zmm4,%%zmm4,%%zmm5 \n" + "vpaddd %%zmm5,%%zmm4,%%zmm4 \n" // + SSIM_WINDOW_AVX512BW + "kmovw %[win_mask],%%k1 \n" + "vaddps %%zmm1,%%zmm0,%%zmm0%{%%k1%} \n" + + "3: \n" + "vextractf32x8 $0x1,%%zmm0,%%ymm1 \n" + "vaddps %%ymm1,%%ymm0,%%ymm0 \n" + "vextractf128 $0x1,%%ymm0,%%xmm1 \n" + "vaddps %%xmm1,%%xmm0,%%xmm0 \n" + "vmovhlps %%xmm0,%%xmm1,%%xmm1 \n" + "vaddps %%xmm1,%%xmm0,%%xmm0 \n" + "vshufps $0x1,%%xmm0,%%xmm0,%%xmm1 \n" + "vaddss %%xmm1,%%xmm0,%[total] \n" + "vzeroupper \n" + : [row0] "+r"(row0), [row1] "+r"(row1), [num_windows] "+r"(num_windows), + [total] "=x"(total) + : [c1] "m"(kSsimC1), [c2] "m"(kSsimC2), [load_mask] "m"(load_mask), + [win_mask] "m"(win_mask) + : "memory", "cc", "k1", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + return total; +} +#undef SSIM_WINDOW_AVX512BW +#endif // HAS_SSIMWINDOWROW_AVX512BW + +#ifdef HAS_ARGBDETECTROW_AVX2 +uint32_t ARGBDetectRow_AVX2(const uint8_t* argb, int width) { + uint32_t diff = 0; + asm volatile( + "vpcmpeqd %%ymm1,%%ymm1,%%ymm1 \n" + "sub $0x8,%[width] \n" + "jl 2f \n" LABELALIGN + "1: \n" + "vpcmpeqb (%[argb]),%%ymm1,%%ymm0 \n" + "vpmovmskb %%ymm0,%[diff] \n" + "not %[diff] \n" + "and $0x99999999,%[diff] \n" + "jnz 99f \n" + "add $0x20,%[argb] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" LABELALIGN + "3: \n" + "vmovd (%[argb]),%%xmm0 \n" + "add $0x4,%[argb] \n" + "vpcmpeqb %%xmm1,%%xmm0,%%xmm0 \n" + "vpmovmskb %%xmm0,%[diff] \n" + "not %[diff] \n" + "and $0x9,%[diff] \n" + "jnz 99f \n" + "sub $0x1,%[width] \n" + "jg 3b \n" + "99: \n" + "vzeroupper \n" + : [argb] "+r"(argb), [width] "+r"(width), [diff] "+r"(diff) + : + : "memory", "cc", "xmm0", "xmm1"); + if (diff) { + return (__builtin_ctz(diff) & 3) == 0 ? FOURCC_BGRA : FOURCC_ARGB; + } + return 0; +} +#endif // HAS_ARGBDETECTROW_AVX2 + +#endif // !defined(LIBYUV_DISABLE_X86) && (defined(__x86_64__) || + // defined(__i386__)) && !defined(LIBYUV_ENABLE_ROWWIN) #ifdef __cplusplus } // extern "C" diff --git a/libs/libyuv/source/compare_hvx.cc b/libs/libyuv/source/compare_hvx.cc new file mode 100644 index 0000000000..fac674adb5 --- /dev/null +++ b/libs/libyuv/source/compare_hvx.cc @@ -0,0 +1,381 @@ +/* + * Copyright 2026 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/compare_row.h" +#include "libyuv/video_common.h" + +#if !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) + +#include +#include +#include +#include + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +static inline HVX_Vector vloada(const void* ptr) { + HVX_Vector v; + memcpy(&v, (const HVX_Vector*)ptr, sizeof(v)); + return v; +} + +static inline HVX_UVector vloadu(const void* ptr) { + HVX_UVector v; + memcpy(&v, ptr, sizeof(v)); + return v; +} + +static inline void vstoreu(void* ptr, HVX_UVector v) { + memcpy(ptr, &v, sizeof(v)); +} + +// Partial load of n bytes (1 <= n <= 128), zeroing lanes past n. +static inline HVX_Vector vloadu_partial_zero(const void* ptr, int n) { + if (n >= 128) { + return vloadu(ptr); + } + const uintptr_t addr = (uintptr_t)ptr; + const uintptr_t offset = addr & 127; + HVX_Vector v0 = vloada(ptr); + HVX_Vector v1 = + (offset + (uintptr_t)n > 128) ? vloada((const uint8_t*)ptr + 128) : v0; + HVX_Vector aligned = Q6_V_valign_VVR(v1, v0, addr); + HVX_VectorPred mask = Q6_Q_vsetq_R(n); + return Q6_V_vmux_QVV(mask, aligned, Q6_V_vzero()); +} + +// Partial store of n bytes (1 <= n <= 128) without overwriting past n. +static inline void vstoreu_partial(void* ptr, HVX_Vector v, int n) { + if (n >= 128) { + vstoreu(ptr, v); + return; + } + const uintptr_t addr = (uintptr_t)ptr; + const uintptr_t offset = addr & 127; + HVX_Vector value = Q6_V_vlalign_VVR(v, v, addr); + HVX_VectorPred ql_not = Q6_Q_vsetq_R(addr); + HVX_VectorPred qr = Q6_Q_vsetq2_R(offset + (uintptr_t)n); + if (offset + (uintptr_t)n > 128) { + Q6_vmem_QRIV(qr, (uint8_t*)ptr + 128, value); + qr = Q6_Q_vcmp_eq_VbVb(value, value); + } + ql_not = Q6_Q_or_QQn(ql_not, qr); + Q6_vmem_QnRIV(ql_not, ptr, value); +} + +static inline uint32_t horizontal_sum_u32(HVX_Vector x) { + x = Q6_Vw_vadd_VwVw(x, Q6_V_vror_VR(x, 64)); + x = Q6_Vw_vadd_VwVw(x, Q6_V_vror_VR(x, 32)); + x = Q6_Vw_vadd_VwVw(x, Q6_V_vror_VR(x, 16)); + x = Q6_Vw_vadd_VwVw(x, Q6_V_vror_VR(x, 8)); + x = Q6_Vw_vadd_VwVw(x, Q6_V_vror_VR(x, 4)); + uint32_t result; + memcpy(&result, &x, sizeof(result)); + return result; +} + +#if defined(HAS_HAMMINGDISTANCE_HVX) +uint32_t HammingDistance_HVX(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + HVX_Vector sum = Q6_V_vzero(); + while (count >= 128) { + HVX_Vector x = Q6_V_vxor_VV(vloadu(src_a), vloadu(src_b)); + HVX_Vector c = Q6_Vh_vpopcount_Vh(x); + sum = Q6_Vuw_vrmpyacc_VuwVubRub(sum, c, 0x01010101); + src_a += 128; + src_b += 128; + count -= 128; + } + if (count > 0) { + HVX_Vector x = Q6_V_vxor_VV(vloadu_partial_zero(src_a, count), + vloadu_partial_zero(src_b, count)); + HVX_Vector c = Q6_Vh_vpopcount_Vh(x); + sum = Q6_Vuw_vrmpyacc_VuwVubRub(sum, c, 0x01010101); + } + return horizontal_sum_u32(sum); +} +#endif // defined(HAS_HAMMINGDISTANCE_HVX) + +#if defined(HAS_SUMSQUAREERROR_HVX) +uint32_t SumSquareError_HVX(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + HVX_Vector sum = Q6_V_vzero(); + while (count >= 128) { + HVX_Vector d = Q6_Vub_vabsdiff_VubVub(vloadu(src_a), vloadu(src_b)); + sum = Q6_Vuw_vrmpyacc_VuwVubVub(sum, d, d); + src_a += 128; + src_b += 128; + count -= 128; + } + if (count > 0) { + HVX_Vector d = Q6_Vub_vabsdiff_VubVub(vloadu_partial_zero(src_a, count), + vloadu_partial_zero(src_b, count)); + sum = Q6_Vuw_vrmpyacc_VuwVubVub(sum, d, d); + } + return horizontal_sum_u32(sum); +} +#endif // defined(HAS_SUMSQUAREERROR_HVX) + +#if defined(HAS_HASHDJB2_HVX) +static const uint32_t kHashMul32[32] __attribute__((aligned(128))) = { + 0x655ec7e1, 0xccc4cfc1, 0x99995ba1, 0xd61beb81, // 33 ^ 31 .. 28 + 0x829bff61, 0x13791741, 0x2f22b321, 0xac185301, // 33 ^ 27 .. 24 + 0xcee976e1, 0xc8359ec1, 0x72ac4aa1, 0x510cfa81, // 33 ^ 23 .. 20 + 0xcc272e61, 0xb0da6641, 0xee162221, 0x92d9e201, // 33 ^ 19 .. 16 + 0x0c3525e1, 0xa3476dc1, 0x3b4039a1, 0x4f5f0981, // 33 ^ 15 .. 12 + 0x30f35d61, 0x855cb541, 0x040a9121, 0x747c7101, // 33 ^ 11 .. 8 + 0xec41d4e1, 0x4cfa3cc1, 0x025528a1, 0x00121881, // 33 ^ 7 .. 4 + 0x00008c61, 0x00000441, 0x00000021, 0x00000001, // 33 ^ 3 .. 0 +}; + +static inline HVX_Vector vmpy_u32(HVX_Vector a, HVX_Vector b) { + HVX_Vector hi = Q6_Vw_vmpyieo_VhVh(a, b); + return Q6_Vw_vmpyieacc_VwVwVuh(hi, a, b); +} + +static uint32_t Pow33(int n) { + uint32_t r = 1u; + uint32_t b = 33u; + while (n) { + if (n & 1) { + r *= b; + } + b *= b; + n >>= 1; + } + return r; +} + +static inline uint32_t HashSum128_HVX(HVX_Vector s, + HVX_Vector mul0, + HVX_Vector mul1, + HVX_Vector mul2, + HVX_Vector mul3) { + HVX_VectorPair h01 = Q6_Wuh_vunpack_Vub(s); + HVX_VectorPair w01 = Q6_Wuw_vunpack_Vuh(Q6_V_lo_W(h01)); + HVX_VectorPair w23 = Q6_Wuw_vunpack_Vuh(Q6_V_hi_W(h01)); + HVX_Vector sum = Q6_Vw_vmpyie_VwVuh(mul0, Q6_V_lo_W(w01)); + sum = Q6_Vw_vmpyieacc_VwVwVuh(sum, mul1, Q6_V_hi_W(w01)); + sum = Q6_Vw_vmpyieacc_VwVwVuh(sum, mul2, Q6_V_lo_W(w23)); + sum = Q6_Vw_vmpyieacc_VwVwVuh(sum, mul3, Q6_V_hi_W(w23)); + return horizontal_sum_u32(sum); +} + +uint32_t HashDjb2_HVX(const uint8_t* src, int count, uint32_t seed) { + const HVX_Vector c32 = Q6_V_vsplat_R(0x1137c401u); // 33 ^ 32 + const HVX_Vector mul3 = vloada(kHashMul32); + const HVX_Vector mul2 = vmpy_u32(mul3, c32); + const HVX_Vector mul1 = vmpy_u32(mul2, c32); + const HVX_Vector mul0 = vmpy_u32(mul1, c32); + while (count >= 128) { + seed = seed * 0x193f1001u + // 33 ^ 128 + HashSum128_HVX(vloadu(src), mul0, mul1, mul2, mul3); + src += 128; + count -= 128; + } + if (count > 0) { + HVX_Vector v = vloadu_partial_zero(src, count); + HVX_Vector s = Q6_V_valign_VVR(v, Q6_V_vzero(), count); + seed = seed * Pow33(count) + HashSum128_HVX(s, mul0, mul1, mul2, mul3); + } + return seed; +} +#endif // defined(HAS_HASHDJB2_HVX) + +#if defined(HAS_SSIM4X4ROW_HVX) +#define SSIM_4X4_HVX(va0, vb0, va1, vb1, va2, vb2, va3, vb3) \ + HVX_Vector sum_a = Q6_Vuw_vrmpy_VubRub(va0, 0x01010101); \ + sum_a = Q6_Vuw_vrmpyacc_VuwVubRub(sum_a, va1, 0x01010101); \ + sum_a = Q6_Vuw_vrmpyacc_VuwVubRub(sum_a, va2, 0x01010101); \ + sum_a = Q6_Vuw_vrmpyacc_VuwVubRub(sum_a, va3, 0x01010101); \ + HVX_Vector sum_b = Q6_Vuw_vrmpy_VubRub(vb0, 0x01010101); \ + sum_b = Q6_Vuw_vrmpyacc_VuwVubRub(sum_b, vb1, 0x01010101); \ + sum_b = Q6_Vuw_vrmpyacc_VuwVubRub(sum_b, vb2, 0x01010101); \ + sum_b = Q6_Vuw_vrmpyacc_VuwVubRub(sum_b, vb3, 0x01010101); \ + HVX_Vector sum_sq = Q6_Vuw_vrmpy_VubVub(va0, va0); \ + sum_sq = Q6_Vuw_vrmpyacc_VuwVubVub(sum_sq, vb0, vb0); \ + sum_sq = Q6_Vuw_vrmpyacc_VuwVubVub(sum_sq, va1, va1); \ + sum_sq = Q6_Vuw_vrmpyacc_VuwVubVub(sum_sq, vb1, vb1); \ + sum_sq = Q6_Vuw_vrmpyacc_VuwVubVub(sum_sq, va2, va2); \ + sum_sq = Q6_Vuw_vrmpyacc_VuwVubVub(sum_sq, vb2, vb2); \ + sum_sq = Q6_Vuw_vrmpyacc_VuwVubVub(sum_sq, va3, va3); \ + sum_sq = Q6_Vuw_vrmpyacc_VuwVubVub(sum_sq, vb3, vb3); \ + HVX_Vector sum_axb = Q6_Vuw_vrmpy_VubVub(va0, vb0); \ + sum_axb = Q6_Vuw_vrmpyacc_VuwVubVub(sum_axb, va1, vb1); \ + sum_axb = Q6_Vuw_vrmpyacc_VuwVubVub(sum_axb, va2, vb2); \ + sum_axb = Q6_Vuw_vrmpyacc_VuwVubVub(sum_axb, va3, vb3); \ + HVX_VectorPair ab = Q6_W_vshuff_VVR(sum_b, sum_a, -4); \ + HVX_VectorPair sqx = Q6_W_vshuff_VVR(sum_axb, sum_sq, -4); \ + HVX_VectorPair out01 = Q6_W_vshuff_VVR(Q6_V_lo_W(sqx), Q6_V_lo_W(ab), -8); \ + HVX_VectorPair out23 = Q6_W_vshuff_VVR(Q6_V_hi_W(sqx), Q6_V_hi_W(ab), -8) + +// Width is a multiple of 4. +void Ssim4x4Row_HVX(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + const ptrdiff_t sa = stride_a; + const ptrdiff_t sb = stride_b; + const uint8_t* a0 = src_a; + const uint8_t* a1 = a0 + sa; + const uint8_t* a2 = a1 + sa; + const uint8_t* a3 = a2 + sa; + const uint8_t* b0 = src_b; + const uint8_t* b1 = b0 + sb; + const uint8_t* b2 = b1 + sb; + const uint8_t* b3 = b2 + sb; + + while (width >= 128) { + SSIM_4X4_HVX(vloadu(a0), vloadu(b0), vloadu(a1), vloadu(b1), vloadu(a2), + vloadu(b2), vloadu(a3), vloadu(b3)); + vstoreu(dst + 0, Q6_V_lo_W(out01)); + vstoreu(dst + 32, Q6_V_hi_W(out01)); + vstoreu(dst + 64, Q6_V_lo_W(out23)); + vstoreu(dst + 96, Q6_V_hi_W(out23)); + a0 += 128; + a1 += 128; + a2 += 128; + a3 += 128; + b0 += 128; + b1 += 128; + b2 += 128; + b3 += 128; + dst += 128; + width -= 128; + } + if (width > 0) { + SSIM_4X4_HVX(vloadu_partial_zero(a0, width), vloadu_partial_zero(b0, width), + vloadu_partial_zero(a1, width), vloadu_partial_zero(b1, width), + vloadu_partial_zero(a2, width), vloadu_partial_zero(b2, width), + vloadu_partial_zero(a3, width), + vloadu_partial_zero(b3, width)); + int bytes = width * 4; + if (bytes > 0) { + vstoreu_partial(dst + 0, Q6_V_lo_W(out01), bytes < 128 ? bytes : 128); + } + if (bytes > 128) { + vstoreu_partial(dst + 32, Q6_V_hi_W(out01), + bytes - 128 < 128 ? bytes - 128 : 128); + } + if (bytes > 256) { + vstoreu_partial(dst + 64, Q6_V_lo_W(out23), + bytes - 256 < 128 ? bytes - 256 : 128); + } + if (bytes > 384) { + vstoreu_partial(dst + 96, Q6_V_hi_W(out23), bytes - 384); + } + } +} +#undef SSIM_4X4_HVX +#endif // defined(HAS_SSIM4X4ROW_HVX) + +#if defined(HAS_SSIMWINDOWROW_HVX) +float SsimWindowRow_HVX(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + const HVX_Vector vc1 = Q6_V_vsplat_R(26634); + const HVX_Vector vc2 = Q6_V_vsplat_R(239708); + float total = 0.0f; + while (num_windows > 0) { + int count = num_windows < 8 ? num_windows : 8; + HVX_Vector t0, t1; + if (num_windows >= 8) { + t0 = Q6_Vw_vadd_VwVw(vloadu(row0), vloadu(row1)); + t1 = Q6_Vw_vadd_VwVw(vloadu(row0 + 4), vloadu(row1 + 4)); + } else { + int bytes0 = count * 16; + int bytes1 = (count + 1) * 16; + t0 = Q6_Vw_vadd_VwVw(vloadu_partial_zero(row0, bytes0), + vloadu_partial_zero(row1, bytes0)); + t1 = Q6_Vw_vadd_VwVw(vloadu_partial_zero(row0 + 4, bytes1 - 16), + vloadu_partial_zero(row1 + 4, bytes1 - 16)); + } + HVX_Vector w = Q6_Vw_vadd_VwVw(t0, t1); + HVX_Vector w_b = Q6_V_vror_VR(w, 4); + HVX_Vector w_sq = Q6_V_vror_VR(w, 8); + HVX_Vector w_axb = Q6_V_vror_VR(w, 12); + HVX_Vector ab2 = Q6_Vw_vasl_VwR(Q6_Vw_vmpyie_VwVuh(w, w_b), 1); + HVX_Vector a2b2 = + Q6_Vw_vmpyieacc_VwVwVuh(Q6_Vw_vmpyie_VwVuh(w, w), w_b, w_b); + HVX_Vector vn1 = Q6_Vw_vadd_VwVw(ab2, vc1); + HVX_Vector vn2 = + Q6_Vw_vadd_VwVw(Q6_Vw_vsub_VwVw(Q6_Vw_vasl_VwR(w_axb, 7), ab2), vc2); + HVX_Vector vd1 = Q6_Vw_vadd_VwVw(a2b2, vc1); + HVX_Vector vd2 = + Q6_Vw_vadd_VwVw(Q6_Vw_vsub_VwVw(Q6_Vw_vasl_VwR(w_sq, 6), a2b2), vc2); + int32_t n1[32] __attribute__((aligned(128))); + int32_t n2[32] __attribute__((aligned(128))); + int32_t d1[32] __attribute__((aligned(128))); + int32_t d2[32] __attribute__((aligned(128))); + vstoreu(n1, vn1); + vstoreu(n2, vn2); + vstoreu(d1, vd1); + vstoreu(d2, vd2); + int i; + for (i = 0; i < count; ++i) { + float num = (float)n1[i * 4] * (float)n2[i * 4]; + float den = (float)d1[i * 4] * (float)d2[i * 4]; + total += num / den; + } + row0 += 32; + row1 += 32; + num_windows -= 8; + } + return total; +} +#endif // defined(HAS_SSIMWINDOWROW_HVX) + +#if defined(HAS_ARGBDETECTROW_HVX) +uint32_t ARGBDetectRow_HVX(const uint8_t* argb, int width) { + const HVX_Vector mask_rgb = Q6_V_vsplat_R(0x00ffff00); + const HVX_Vector ones = Q6_Vb_vsplat_R(-1); + const HVX_Vector zero = Q6_V_vzero(); + while (width > 0) { + HVX_Vector v; + if (width >= 32) { + v = vloadu(argb); + } else { + int bytes = width * 4; + v = Q6_V_vmux_QVV(Q6_Q_vsetq_R(bytes), vloadu_partial_zero(argb, bytes), + ones); + } + v = Q6_V_vor_VV(v, mask_rgb); + HVX_VectorPred eq = Q6_Q_vcmp_eq_VbVb(v, ones); + HVX_Vector diff_v = Q6_V_vmux_QVV(eq, zero, ones); + if (horizontal_sum_u32(Q6_Vuw_vrmpy_VubRub(diff_v, 0x01010101)) != 0) { + uint32_t diff[32] __attribute__((aligned(128))); + vstoreu(diff, diff_v); + int i; + for (i = 0; i < 32; ++i) { + if (diff[i] != 0) { + return (diff[i] & 0xffu) ? FOURCC_BGRA : FOURCC_ARGB; + } + } + } + argb += 128; + width -= 32; + } + return 0; +} +#endif // defined(HAS_ARGBDETECTROW_HVX) + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) diff --git a/libs/libyuv/source/compare_mmi.cc b/libs/libyuv/source/compare_mmi.cc deleted file mode 100644 index 7640d9468c..0000000000 --- a/libs/libyuv/source/compare_mmi.cc +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2012 The LibYuv Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "libyuv/basic_types.h" - -#include "libyuv/compare_row.h" - -#ifdef __cplusplus -namespace libyuv { -extern "C" { -#endif - -// This module is for Mips MMI. -#if !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) - -// Hakmem method for hamming distance. -uint32_t HammingDistance_MMI(const uint8_t* src_a, - const uint8_t* src_b, - int count) { - uint32_t diff = 0u; - - uint64_t temp = 0, temp1 = 0, ta = 0, tb = 0; - uint64_t c1 = 0x5555555555555555; - uint64_t c2 = 0x3333333333333333; - uint64_t c3 = 0x0f0f0f0f0f0f0f0f; - uint32_t c4 = 0x01010101; - uint64_t s1 = 1, s2 = 2, s3 = 4; - __asm__ volatile( - "1: \n\t" - "ldc1 %[ta], 0(%[src_a]) \n\t" - "ldc1 %[tb], 0(%[src_b]) \n\t" - "xor %[temp], %[ta], %[tb] \n\t" - "psrlw %[temp1], %[temp], %[s1] \n\t" // temp1=x>>1 - "and %[temp1], %[temp1], %[c1] \n\t" // temp1&=c1 - "psubw %[temp1], %[temp], %[temp1] \n\t" // x-temp1 - "and %[temp], %[temp1], %[c2] \n\t" // t = (u&c2) - "psrlw %[temp1], %[temp1], %[s2] \n\t" // u>>2 - "and %[temp1], %[temp1], %[c2] \n\t" // u>>2 & c2 - "paddw %[temp1], %[temp1], %[temp] \n\t" // t1 = t1+t - "psrlw %[temp], %[temp1], %[s3] \n\t" // u>>4 - "paddw %[temp1], %[temp1], %[temp] \n\t" // u+(u>>4) - "and %[temp1], %[temp1], %[c3] \n\t" //&c3 - "dmfc1 $t0, %[temp1] \n\t" - "dsrl32 $t0, $t0, 0 \n\t " - "mul $t0, $t0, %[c4] \n\t" - "dsrl $t0, $t0, 24 \n\t" - "dadd %[diff], %[diff], $t0 \n\t" - "dmfc1 $t0, %[temp1] \n\t" - "mul $t0, $t0, %[c4] \n\t" - "dsrl $t0, $t0, 24 \n\t" - "dadd %[diff], %[diff], $t0 \n\t" - "daddiu %[src_a], %[src_a], 8 \n\t" - "daddiu %[src_b], %[src_b], 8 \n\t" - "addiu %[count], %[count], -8 \n\t" - "bgtz %[count], 1b \n\t" - "nop \n\t" - : [diff] "+r"(diff), [src_a] "+r"(src_a), [src_b] "+r"(src_b), - [count] "+r"(count), [ta] "+f"(ta), [tb] "+f"(tb), [temp] "+f"(temp), - [temp1] "+f"(temp1) - : [c1] "f"(c1), [c2] "f"(c2), [c3] "f"(c3), [c4] "r"(c4), [s1] "f"(s1), - [s2] "f"(s2), [s3] "f"(s3) - : "memory"); - return diff; -} - -uint32_t SumSquareError_MMI(const uint8_t* src_a, - const uint8_t* src_b, - int count) { - uint32_t sse = 0u; - uint32_t sse_hi = 0u, sse_lo = 0u; - - uint64_t src1, src2; - uint64_t diff, diff_hi, diff_lo; - uint64_t sse_sum, sse_tmp; - - const uint64_t mask = 0x0ULL; - - __asm__ volatile( - "xor %[sse_sum], %[sse_sum], %[sse_sum] \n\t" - - "1: \n\t" - "ldc1 %[src1], 0x00(%[src_a]) \n\t" - "ldc1 %[src2], 0x00(%[src_b]) \n\t" - "pasubub %[diff], %[src1], %[src2] \n\t" - "punpcklbh %[diff_lo], %[diff], %[mask] \n\t" - "punpckhbh %[diff_hi], %[diff], %[mask] \n\t" - "pmaddhw %[sse_tmp], %[diff_lo], %[diff_lo] \n\t" - "paddw %[sse_sum], %[sse_sum], %[sse_tmp] \n\t" - "pmaddhw %[sse_tmp], %[diff_hi], %[diff_hi] \n\t" - "paddw %[sse_sum], %[sse_sum], %[sse_tmp] \n\t" - - "daddiu %[src_a], %[src_a], 0x08 \n\t" - "daddiu %[src_b], %[src_b], 0x08 \n\t" - "daddiu %[count], %[count], -0x08 \n\t" - "bnez %[count], 1b \n\t" - - "mfc1 %[sse_lo], %[sse_sum] \n\t" - "mfhc1 %[sse_hi], %[sse_sum] \n\t" - "daddu %[sse], %[sse_hi], %[sse_lo] \n\t" - : [sse] "+&r"(sse), [diff] "=&f"(diff), [src1] "=&f"(src1), - [src2] "=&f"(src2), [diff_lo] "=&f"(diff_lo), [diff_hi] "=&f"(diff_hi), - [sse_sum] "=&f"(sse_sum), [sse_tmp] "=&f"(sse_tmp), - [sse_hi] "+&r"(sse_hi), [sse_lo] "+&r"(sse_lo) - : [src_a] "r"(src_a), [src_b] "r"(src_b), [count] "r"(count), - [mask] "f"(mask) - : "memory"); - - return sse; -} - -#endif // !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) - -#ifdef __cplusplus -} // extern "C" -} // namespace libyuv -#endif diff --git a/libs/libyuv/source/compare_msa.cc b/libs/libyuv/source/compare_msa.cc deleted file mode 100644 index 0b807d37be..0000000000 --- a/libs/libyuv/source/compare_msa.cc +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2017 The LibYuv Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "libyuv/basic_types.h" - -#include "libyuv/compare_row.h" -#include "libyuv/row.h" - -// This module is for GCC MSA -#if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) -#include "libyuv/macros_msa.h" - -#ifdef __cplusplus -namespace libyuv { -extern "C" { -#endif - -uint32_t HammingDistance_MSA(const uint8_t* src_a, - const uint8_t* src_b, - int count) { - uint32_t diff = 0u; - int i; - v16u8 src0, src1, src2, src3; - v2i64 vec0 = {0}, vec1 = {0}; - - for (i = 0; i < count; i += 32) { - src0 = (v16u8)__msa_ld_b((v16i8*)src_a, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)src_a, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)src_b, 0); - src3 = (v16u8)__msa_ld_b((v16i8*)src_b, 16); - src0 ^= src2; - src1 ^= src3; - vec0 += __msa_pcnt_d((v2i64)src0); - vec1 += __msa_pcnt_d((v2i64)src1); - src_a += 32; - src_b += 32; - } - - vec0 += vec1; - diff = (uint32_t)__msa_copy_u_w((v4i32)vec0, 0); - diff += (uint32_t)__msa_copy_u_w((v4i32)vec0, 2); - return diff; -} - -uint32_t SumSquareError_MSA(const uint8_t* src_a, - const uint8_t* src_b, - int count) { - uint32_t sse = 0u; - int i; - v16u8 src0, src1, src2, src3; - v8i16 vec0, vec1, vec2, vec3; - v4i32 reg0 = {0}, reg1 = {0}, reg2 = {0}, reg3 = {0}; - v2i64 tmp0; - - for (i = 0; i < count; i += 32) { - src0 = (v16u8)__msa_ld_b((v16i8*)src_a, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)src_a, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)src_b, 0); - src3 = (v16u8)__msa_ld_b((v16i8*)src_b, 16); - vec0 = (v8i16)__msa_ilvr_b((v16i8)src2, (v16i8)src0); - vec1 = (v8i16)__msa_ilvl_b((v16i8)src2, (v16i8)src0); - vec2 = (v8i16)__msa_ilvr_b((v16i8)src3, (v16i8)src1); - vec3 = (v8i16)__msa_ilvl_b((v16i8)src3, (v16i8)src1); - vec0 = __msa_hsub_u_h((v16u8)vec0, (v16u8)vec0); - vec1 = __msa_hsub_u_h((v16u8)vec1, (v16u8)vec1); - vec2 = __msa_hsub_u_h((v16u8)vec2, (v16u8)vec2); - vec3 = __msa_hsub_u_h((v16u8)vec3, (v16u8)vec3); - reg0 = __msa_dpadd_s_w(reg0, vec0, vec0); - reg1 = __msa_dpadd_s_w(reg1, vec1, vec1); - reg2 = __msa_dpadd_s_w(reg2, vec2, vec2); - reg3 = __msa_dpadd_s_w(reg3, vec3, vec3); - src_a += 32; - src_b += 32; - } - - reg0 += reg1; - reg2 += reg3; - reg0 += reg2; - tmp0 = __msa_hadd_s_d(reg0, reg0); - sse = (uint32_t)__msa_copy_u_w((v4i32)tmp0, 0); - sse += (uint32_t)__msa_copy_u_w((v4i32)tmp0, 2); - return sse; -} - -#ifdef __cplusplus -} // extern "C" -} // namespace libyuv -#endif - -#endif // !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) diff --git a/libs/libyuv/source/compare_neon.cc b/libs/libyuv/source/compare_neon.cc index 2a2181e0cb..529571822e 100644 --- a/libs/libyuv/source/compare_neon.cc +++ b/libs/libyuv/source/compare_neon.cc @@ -8,16 +8,22 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "libyuv/basic_types.h" - #include "libyuv/compare_row.h" #include "libyuv/row.h" +#include "libyuv/video_common.h" #ifdef __cplusplus namespace libyuv { extern "C" { #endif +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + #if !defined(LIBYUV_DISABLE_NEON) && defined(__ARM_NEON__) && \ !defined(__aarch64__) @@ -29,24 +35,24 @@ uint32_t HammingDistance_NEON(const uint8_t* src_a, uint32_t diff; asm volatile( - "vmov.u16 q4, #0 \n" // accumulator + "vmov.u16 q4, #0 \n" // accumulator - "1: \n" - "vld1.8 {q0, q1}, [%0]! \n" - "vld1.8 {q2, q3}, [%1]! \n" - "veor.32 q0, q0, q2 \n" - "veor.32 q1, q1, q3 \n" - "vcnt.i8 q0, q0 \n" - "vcnt.i8 q1, q1 \n" - "subs %2, %2, #32 \n" - "vadd.u8 q0, q0, q1 \n" // 16 byte counts - "vpadal.u8 q4, q0 \n" // 8 shorts - "bgt 1b \n" + "1: \n" + "vld1.8 {q0, q1}, [%0]! \n" + "vld1.8 {q2, q3}, [%1]! \n" + "veor.32 q0, q0, q2 \n" + "veor.32 q1, q1, q3 \n" + "vcnt.i8 q0, q0 \n" + "vcnt.i8 q1, q1 \n" + "subs %2, %2, #32 \n" + "vadd.u8 q0, q0, q1 \n" // 16 byte counts + "vpadal.u8 q4, q0 \n" // 8 shorts + "bgt 1b \n" - "vpaddl.u16 q0, q4 \n" // 4 ints - "vpadd.u32 d0, d0, d1 \n" - "vpadd.u32 d0, d0, d0 \n" - "vmov.32 %3, d0[0] \n" + "vpaddl.u16 q0, q4 \n" // 4 ints + "vpadd.u32 d0, d0, d1 \n" + "vpadd.u32 d0, d0, d0 \n" + "vmov.32 %3, d0[0] \n" : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(diff) : @@ -59,35 +65,267 @@ uint32_t SumSquareError_NEON(const uint8_t* src_a, int count) { uint32_t sse; asm volatile( - "vmov.u8 q8, #0 \n" - "vmov.u8 q10, #0 \n" - "vmov.u8 q9, #0 \n" - "vmov.u8 q11, #0 \n" + "vmov.u8 q8, #0 \n" + "vmov.u8 q10, #0 \n" + "vmov.u8 q9, #0 \n" + "vmov.u8 q11, #0 \n" - "1: \n" - "vld1.8 {q0}, [%0]! \n" - "vld1.8 {q1}, [%1]! \n" - "subs %2, %2, #16 \n" - "vsubl.u8 q2, d0, d2 \n" - "vsubl.u8 q3, d1, d3 \n" - "vmlal.s16 q8, d4, d4 \n" - "vmlal.s16 q9, d6, d6 \n" - "vmlal.s16 q10, d5, d5 \n" - "vmlal.s16 q11, d7, d7 \n" - "bgt 1b \n" + "1: \n" + "vld1.8 {q0}, [%0]! \n" + "vld1.8 {q1}, [%1]! \n" + "subs %2, %2, #16 \n" + "vsubl.u8 q2, d0, d2 \n" + "vsubl.u8 q3, d1, d3 \n" + "vmlal.s16 q8, d4, d4 \n" + "vmlal.s16 q9, d6, d6 \n" + "vmlal.s16 q10, d5, d5 \n" + "vmlal.s16 q11, d7, d7 \n" + "bgt 1b \n" - "vadd.u32 q8, q8, q9 \n" - "vadd.u32 q10, q10, q11 \n" - "vadd.u32 q11, q8, q10 \n" - "vpaddl.u32 q1, q11 \n" - "vadd.u64 d0, d2, d3 \n" - "vmov.32 %3, d0[0] \n" + "vadd.u32 q8, q8, q9 \n" + "vadd.u32 q10, q10, q11 \n" + "vadd.u32 q11, q8, q10 \n" + "vpaddl.u32 q1, q11 \n" + "vadd.u64 d0, d2, d3 \n" + "vmov.32 %3, d0[0] \n" : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(sse) : : "memory", "cc", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11"); return sse; } +#define SSIM_ROW_NEON32(LOAD_A, LOAD_B, PADD_U8, PADD_U16) \ + LOAD_A \ + LOAD_B \ + PADD_U8 " q8, q0 \n" PADD_U8 \ + " q9, q1 \n" \ + "vmull.u8 q2, d0, d0 \n" \ + "vmull.u8 q3, d1, d1 \n" PADD_U16 \ + " q10, q2 \n" PADD_U16 \ + " q11, q3 \n" \ + "vmull.u8 q2, d2, d2 \n" \ + "vmull.u8 q3, d3, d3 \n" \ + "vpadal.u16 q10, q2 \n" \ + "vpadal.u16 q11, q3 \n" \ + "vmull.u8 q2, d0, d2 \n" \ + "vmull.u8 q3, d1, d3 \n" PADD_U16 \ + " q12, q2 \n" PADD_U16 \ + " q13, q3 \n" + +void Ssim4x4Row_NEON(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + asm volatile( + "1: \n" // + SSIM_ROW_NEON32("vld1.8 {d0, d1}, [%[src_a]], %[stride_a]\n", + "vld1.8 {d2, d3}, [%[src_b]], %[stride_b]\n", "vpaddl.u8", + "vpaddl.u16") // + SSIM_ROW_NEON32("vld1.8 {d0, d1}, [%[src_a]], %[stride_a]\n", + "vld1.8 {d2, d3}, [%[src_b]], %[stride_b]\n", "vpadal.u8", + "vpadal.u16") // + SSIM_ROW_NEON32("vld1.8 {d0, d1}, [%[src_a]], %[stride_a]\n", + "vld1.8 {d2, d3}, [%[src_b]], %[stride_b]\n", "vpadal.u8", + "vpadal.u16") // + SSIM_ROW_NEON32("vld1.8 {d0, d1}, [%[src_a]]\n", + "vld1.8 {d2, d3}, [%[src_b]]\n", "vpadal.u8", + "vpadal.u16") // + "sub %[src_a], %[src_a], %[stride_a], lsl #1 \n" + "sub %[src_a], %[src_a], %[stride_a] \n" + "add %[src_a], %[src_a], #16 \n" + "sub %[src_b], %[src_b], %[stride_b], lsl #1 \n" + "sub %[src_b], %[src_b], %[stride_b] \n" + "add %[src_b], %[src_b], #16 \n" + "vpaddl.u16 q8, q8 \n" + "vpaddl.u16 q9, q9 \n" + "vpadd.u32 d20, d20, d21 \n" + "vpadd.u32 d21, d22, d23 \n" + "vpadd.u32 d22, d24, d25 \n" + "vpadd.u32 d23, d26, d27 \n" + "subs %[width], %[width], #16 \n" + "vst4.32 {d16, d18, d20, d22}, [%[dst]]! \n" + "vst4.32 {d17, d19, d21, d23}, [%[dst]]! \n" + "bgt 1b \n" + : [src_a] "+r"(src_a), [src_b] "+r"(src_b), [dst] "+r"(dst), + [width] "+r"(width) + : [stride_a] "r"(stride_a), [stride_b] "r"(stride_b) + : "memory", "cc", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", + "q13"); +} +#undef SSIM_ROW_NEON32 + +static const uvec32 kDjb2Multiplicands[] = { + {0x0c3525e1, // 33^15 + 0xa3476dc1, // 33^14 + 0x3b4039a1, // 33^13 + 0x4f5f0981}, // 33^12 + {0x30f35d61, // 33^11 + 0x855cb541, // 33^10 + 0x040a9121, // 33^9 + 0x747c7101}, // 33^8 + {0xec41d4e1, // 33^7 + 0x4cfa3cc1, // 33^6 + 0x025528a1, // 33^5 + 0x00121881}, // 33^4 + {0x00008c61, // 33^3 + 0x00000441, // 33^2 + 0x00000021, // 33^1 + 0x00000001}, // 33^0 +}; + +uint32_t HashDjb2_NEON(const uint8_t* src, int count, uint32_t seed) { + uint32_t hash = seed; + const uint32_t c16 = 0x92d9e201; // 33^16 + const void* muls0 = &kDjb2Multiplicands[0]; + const void* muls1 = &kDjb2Multiplicands[2]; + uint32_t tmp; + asm volatile( + "vld1.32 {d16, d17, d18, d19}, [%[muls0]] \n" + "vld1.32 {d20, d21, d22, d23}, [%[muls1]] \n" + "1: \n" + "vld1.8 {d0, d1}, [%[src]]! \n" + "subs %[count], %[count], #16 \n" + "vmovl.u8 q1, d0 \n" + "vmovl.u8 q2, d1 \n" + "vmovl.u16 q0, d2 \n" + "vmovl.u16 q1, d3 \n" + "vmovl.u16 q3, d5 \n" + "vmovl.u16 q2, d4 \n" + "vmul.i32 q0, q0, q8 \n" + "vmla.i32 q0, q1, q9 \n" + "vmla.i32 q0, q2, q10 \n" + "vmla.i32 q0, q3, q11 \n" + "vpadd.i32 d0, d0, d1 \n" + "vpadd.i32 d0, d0, d0 \n" + "vmov.32 %[tmp], d0[0] \n" + "mla %[hash], %[hash], %[c16], %[tmp] \n" + "bgt 1b \n" + : + [src] "+r"(src), [hash] "+r"(hash), [count] "+r"(count), [tmp] "=&r"(tmp) + : [muls0] "r"(muls0), [muls1] "r"(muls1), [c16] "r"(c16) + : "memory", "cc", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11"); + return hash; +} + +float SsimWindowRow_NEON(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + const uint32_t* row0_next = row0 + 4; + const uint32_t* row1_next = row1 + 4; + float total; + asm volatile( + "vmov.i32 q12, #0 \n" + "vdup.32 q13, %[c1] \n" + "vdup.32 q14, %[c2] \n" + "1: \n" + "vld4.32 {d0, d2, d4, d6}, [%[row0]]! \n" + "vld4.32 {d1, d3, d5, d7}, [%[row0]]! \n" + "vld4.32 {d16, d18, d20, d22}, [%[row0_next]]! \n" + "vld4.32 {d17, d19, d21, d23}, [%[row0_next]]! \n" + "vadd.i32 q0, q0, q8 \n" + "vadd.i32 q1, q1, q9 \n" + "vadd.i32 q2, q2, q10 \n" + "vadd.i32 q3, q3, q11 \n" + "vld4.32 {d16, d18, d20, d22}, [%[row1]]! \n" + "vld4.32 {d17, d19, d21, d23}, [%[row1]]! \n" + "vadd.i32 q0, q0, q8 \n" + "vadd.i32 q1, q1, q9 \n" + "vadd.i32 q2, q2, q10 \n" + "vadd.i32 q3, q3, q11 \n" + "vld4.32 {d16, d18, d20, d22}, [%[row1_next]]! \n" + "vld4.32 {d17, d19, d21, d23}, [%[row1_next]]! \n" + "vadd.i32 q0, q0, q8 \n" + "vadd.i32 q1, q1, q9 \n" + "vadd.i32 q2, q2, q10 \n" + "vadd.i32 q3, q3, q11 \n" + "vmul.i32 q8, q0, q1 \n" + "vshl.i32 q8, q8, #1 \n" + "vmul.i32 q9, q0, q0 \n" + "vmla.i32 q9, q1, q1 \n" + "vshl.i32 q3, q3, #7 \n" + "vsub.i32 q3, q3, q8 \n" + "vadd.i32 q8, q8, q13 \n" + "vadd.i32 q3, q3, q14 \n" + "vshl.i32 q2, q2, #6 \n" + "vsub.i32 q2, q2, q9 \n" + "vadd.i32 q9, q9, q13 \n" + "vadd.i32 q2, q2, q14 \n" + "vcvt.f32.s32 q8, q8 \n" + "vcvt.f32.s32 q3, q3 \n" + "vcvt.f32.s32 q9, q9 \n" + "vcvt.f32.s32 q2, q2 \n" + "vmul.f32 q3, q8, q3 \n" + "vmul.f32 q2, q9, q2 \n" + "vdiv.f32 s12, s12, s8 \n" + "vdiv.f32 s13, s13, s9 \n" + "vdiv.f32 s14, s14, s10 \n" + "vdiv.f32 s15, s15, s11 \n" + "subs %[num_windows], %[num_windows], #4 \n" + "vadd.f32 q12, q12, q3 \n" + "bgt 1b \n" + "vpadd.f32 d0, d24, d25 \n" + "vpadd.f32 d0, d0, d0 \n" + "vmov.f32 %[total], s0 \n" + : [row0] "+r"(row0), [row0_next] "+r"(row0_next), [row1] "+r"(row1), + [row1_next] "+r"(row1_next), [num_windows] "+r"(num_windows), + [total] "=r"(total) + : [c1] "r"(26634), [c2] "r"(239708) + : "memory", "cc", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", + "q13", "q14"); + return total; +} + +uint32_t ARGBDetectRow_NEON(const uint8_t* argb, int width) { + uint32_t diff_lo = 0; + uint32_t diff_hi = 0; + uint32_t tmp; + asm volatile( + "vmov.i32 q2, #0x00ff0000 \n" + "vorr.i32 q2, #0x0000ff00 \n" + "vmov.i8 q3, #0xff \n" + "subs %[width], %[width], #4 \n" + "blt 2f \n" + "1: \n" + "vld1.8 {q0}, [%[argb]]! \n" + "vorr q0, q0, q2 \n" + "vceq.i8 q0, q0, q3 \n" + "vmvn q0, q0 \n" + "vshrn.i16 d0, q0, #4 \n" + "vmov %[diff_lo], %[diff_hi], d0 \n" + "orrs %[tmp], %[diff_lo], %[diff_hi] \n" + "bne 99f \n" + "subs %[width], %[width], #4 \n" + "bge 1b \n" + "2: \n" + "adds %[width], %[width], #4 \n" + "ble 99f \n" + "3: \n" + "vld1.32 {d0[0]}, [%[argb]]! \n" + "vorr d0, d0, d4 \n" + "vceq.i8 d0, d0, d6 \n" + "vmvn d0, d0 \n" + "vshrn.i16 d0, q0, #4 \n" + "vmov.u16 %[diff_lo], d0[0] \n" + "cmp %[diff_lo], #0 \n" + "bne 99f \n" + "subs %[width], %[width], #1 \n" + "bgt 3b \n" + "99: \n" + : [argb] "+r"(argb), [width] "+r"(width), [diff_lo] "+r"(diff_lo), + [diff_hi] "+r"(diff_hi), [tmp] "=&r"(tmp) + : + : "memory", "cc", "q0", "q2", "q3"); + if (diff_lo) { + return (__builtin_ctz(diff_lo) & 12) == 0 ? FOURCC_BGRA : FOURCC_ARGB; + } + if (diff_hi) { + return (__builtin_ctz(diff_hi) & 12) == 0 ? FOURCC_BGRA : FOURCC_ARGB; + } + return 0; +} + #endif // defined(__ARM_NEON__) && !defined(__aarch64__) #ifdef __cplusplus diff --git a/libs/libyuv/source/compare_neon64.cc b/libs/libyuv/source/compare_neon64.cc index 6e8f672ab7..c1b4741589 100644 --- a/libs/libyuv/source/compare_neon64.cc +++ b/libs/libyuv/source/compare_neon64.cc @@ -8,16 +8,22 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "libyuv/basic_types.h" - #include "libyuv/compare_row.h" #include "libyuv/row.h" +#include "libyuv/video_common.h" #ifdef __cplusplus namespace libyuv { extern "C" { #endif +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) // 256 bits at a time @@ -27,25 +33,27 @@ uint32_t HammingDistance_NEON(const uint8_t* src_a, int count) { uint32_t diff; asm volatile( - "movi v4.8h, #0 \n" + "movi v4.8h, #0 \n" - "1: \n" - "ld1 {v0.16b, v1.16b}, [%0], #32 \n" - "ld1 {v2.16b, v3.16b}, [%1], #32 \n" - "eor v0.16b, v0.16b, v2.16b \n" - "eor v1.16b, v1.16b, v3.16b \n" - "cnt v0.16b, v0.16b \n" - "cnt v1.16b, v1.16b \n" - "subs %w2, %w2, #32 \n" - "add v0.16b, v0.16b, v1.16b \n" - "uadalp v4.8h, v0.16b \n" - "b.gt 1b \n" + "1: \n" + "ld1 {v0.16b, v1.16b}, [%0], #32 \n" + "ld1 {v2.16b, v3.16b}, [%1], #32 \n" + "eor v0.16b, v0.16b, v2.16b \n" + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "eor v1.16b, v1.16b, v3.16b \n" + "cnt v0.16b, v0.16b \n" + "prfm pldl1keep, [%1, 448] \n" + "cnt v1.16b, v1.16b \n" + "subs %w2, %w2, #32 \n" + "add v0.16b, v0.16b, v1.16b \n" + "uadalp v4.8h, v0.16b \n" + "b.gt 1b \n" - "uaddlv s4, v4.8h \n" - "fmov %w3, s4 \n" + "uaddlv s4, v4.8h \n" + "fmov %w3, s4 \n" : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(diff) : - : "cc", "v0", "v1", "v2", "v3", "v4"); + : "memory", "cc", "v0", "v1", "v2", "v3", "v4"); return diff; } @@ -54,34 +62,395 @@ uint32_t SumSquareError_NEON(const uint8_t* src_a, int count) { uint32_t sse; asm volatile( - "eor v16.16b, v16.16b, v16.16b \n" - "eor v18.16b, v18.16b, v18.16b \n" - "eor v17.16b, v17.16b, v17.16b \n" - "eor v19.16b, v19.16b, v19.16b \n" + "movi v16.16b, #0 \n" + "movi v17.16b, #0 \n" + "movi v18.16b, #0 \n" + "movi v19.16b, #0 \n" - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" - "ld1 {v1.16b}, [%1], #16 \n" - "subs %w2, %w2, #16 \n" - "usubl v2.8h, v0.8b, v1.8b \n" - "usubl2 v3.8h, v0.16b, v1.16b \n" - "smlal v16.4s, v2.4h, v2.4h \n" - "smlal v17.4s, v3.4h, v3.4h \n" - "smlal2 v18.4s, v2.8h, v2.8h \n" - "smlal2 v19.4s, v3.8h, v3.8h \n" - "b.gt 1b \n" + "1: \n" + "ld1 {v0.16b}, [%0], #16 \n" + "ld1 {v1.16b}, [%1], #16 \n" + "subs %w2, %w2, #16 \n" + "usubl v2.8h, v0.8b, v1.8b \n" + "usubl2 v3.8h, v0.16b, v1.16b \n" + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "smlal v16.4s, v2.4h, v2.4h \n" + "smlal v17.4s, v3.4h, v3.4h \n" + "prfm pldl1keep, [%1, 448] \n" + "smlal2 v18.4s, v2.8h, v2.8h \n" + "smlal2 v19.4s, v3.8h, v3.8h \n" + "b.gt 1b \n" - "add v16.4s, v16.4s, v17.4s \n" - "add v18.4s, v18.4s, v19.4s \n" - "add v19.4s, v16.4s, v18.4s \n" - "addv s0, v19.4s \n" - "fmov %w3, s0 \n" + "add v16.4s, v16.4s, v17.4s \n" + "add v18.4s, v18.4s, v19.4s \n" + "add v19.4s, v16.4s, v18.4s \n" + "addv s0, v19.4s \n" + "fmov %w3, s0 \n" : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(sse) : - : "cc", "v0", "v1", "v2", "v3", "v16", "v17", "v18", "v19"); + : "memory", "cc", "v0", "v1", "v2", "v3", "v16", "v17", "v18", "v19"); return sse; } +static const uvec32 kDjb2Multiplicands[] = { + {0x0c3525e1, // 33^15 + 0xa3476dc1, // 33^14 + 0x3b4039a1, // 33^13 + 0x4f5f0981}, // 33^12 + {0x30f35d61, // 33^11 + 0x855cb541, // 33^10 + 0x040a9121, // 33^9 + 0x747c7101}, // 33^8 + {0xec41d4e1, // 33^7 + 0x4cfa3cc1, // 33^6 + 0x025528a1, // 33^5 + 0x00121881}, // 33^4 + {0x00008c61, // 33^3 + 0x00000441, // 33^2 + 0x00000021, // 33^1 + 0x00000001}, // 33^0 +}; + +static const uvec32 kDjb2WidenIndices[] = { + {0xffffff00U, 0xffffff01U, 0xffffff02U, 0xffffff03U}, + {0xffffff04U, 0xffffff05U, 0xffffff06U, 0xffffff07U}, + {0xffffff08U, 0xffffff09U, 0xffffff0aU, 0xffffff0bU}, + {0xffffff0cU, 0xffffff0dU, 0xffffff0eU, 0xffffff0fU}, +}; + +uint32_t HashDjb2_NEON(const uint8_t* src, int count, uint32_t seed) { + uint32_t hash = seed; + const uint32_t c16 = 0x92d9e201; // 33^16 + uint32_t tmp, tmp2; + asm("ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%[kIdx]] \n" + "ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%[kMuls]] \n" + + // count is always a multiple of 16. + // maintain two accumulators, reduce and then final sum in scalar since + // this has better performance on little cores. + "1: \n" + "ldr q0, [%[src]], #16 \n" + "subs %w[count], %w[count], #16 \n" + "tbl v3.16b, {v0.16b}, v19.16b \n" + "tbl v2.16b, {v0.16b}, v18.16b \n" + "tbl v1.16b, {v0.16b}, v17.16b \n" + "tbl v0.16b, {v0.16b}, v16.16b \n" + "mul v3.4s, v3.4s, v7.4s \n" + "mul v2.4s, v2.4s, v6.4s \n" + "mla v3.4s, v1.4s, v5.4s \n" + "mla v2.4s, v0.4s, v4.4s \n" + "addv s1, v3.4s \n" + "addv s0, v2.4s \n" + "fmov %w[tmp2], s1 \n" + "fmov %w[tmp], s0 \n" + "add %w[tmp], %w[tmp], %w[tmp2] \n" + "madd %w[hash], %w[hash], %w[c16], %w[tmp] \n" + "b.gt 1b \n" + : [src] "+r"(src), // %[src] + [hash] "+r"(hash), // %[hash] + [count] "+r"(count), // %[count] + [tmp] "=&r"(tmp), // %[tmp] + [tmp2] "=&r"(tmp2) // %[tmp2] + : [kMuls] "r"(kDjb2Multiplicands), // %[kMuls] + [kIdx] "r"(kDjb2WidenIndices), // %[kIdx] + [c16] "r"(c16) // %[c16] + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19"); + return hash; +} + +uint32_t HammingDistance_NEON_DotProd(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t diff; + asm volatile( + "movi v4.4s, #0 \n" + "movi v5.4s, #0 \n" + "movi v6.16b, #1 \n" + + "1: \n" + "ldp q0, q1, [%0], #32 \n" + "ldp q2, q3, [%1], #32 \n" + "eor v0.16b, v0.16b, v2.16b \n" + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "eor v1.16b, v1.16b, v3.16b \n" + "cnt v0.16b, v0.16b \n" + "prfm pldl1keep, [%1, 448] \n" + "cnt v1.16b, v1.16b \n" + "subs %w2, %w2, #32 \n" + "udot v4.4s, v0.16b, v6.16b \n" + "udot v5.4s, v1.16b, v6.16b \n" + "b.gt 1b \n" + + "add v0.4s, v4.4s, v5.4s \n" + "addv s0, v0.4s \n" + "fmov %w3, s0 \n" + : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(diff) + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6"); + return diff; +} + +uint32_t SumSquareError_NEON_DotProd(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + // count is guaranteed to be a multiple of 32. + uint32_t sse; + asm volatile( + "movi v4.4s, #0 \n" + "movi v5.4s, #0 \n" + + "1: \n" + "ldp q0, q2, [%0], #32 \n" + "ldp q1, q3, [%1], #32 \n" + "subs %w2, %w2, #32 \n" + "uabd v0.16b, v0.16b, v1.16b \n" + "uabd v1.16b, v2.16b, v3.16b \n" + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "udot v4.4s, v0.16b, v0.16b \n" + "udot v5.4s, v1.16b, v1.16b \n" + "prfm pldl1keep, [%1, 448] \n" + "b.gt 1b \n" + + "add v0.4s, v4.4s, v5.4s \n" + "addv s0, v0.4s \n" + "fmov %w3, s0 \n" + : "+r"(src_a), "+r"(src_b), "+r"(count), "=r"(sse) + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5"); + return sse; +} + +#define SSIM_ROW_NEON64(VA, VB, PADD_U8, PADD_U16) \ + PADD_U8 " v4.8h, " #VA ".16b \n" PADD_U8 \ + " v5.8h, " #VB \ + ".16b \n" \ + "umull v6.8h, " #VA ".8b, " #VA \ + ".8b \n" \ + "umull2 v7.8h, " #VA ".16b, " #VA ".16b \n" PADD_U16 \ + " v20.4s, v6.8h \n" PADD_U16 \ + " v21.4s, v7.8h \n" \ + "umull v6.8h, " #VB ".8b, " #VB \ + ".8b \n" \ + "umull2 v7.8h, " #VB ".16b, " #VB \ + ".16b \n" \ + "uadalp v20.4s, v6.8h \n" \ + "uadalp v21.4s, v7.8h \n" \ + "umull v6.8h, " #VA ".8b, " #VB \ + ".8b \n" \ + "umull2 v7.8h, " #VA ".16b, " #VB ".16b \n" PADD_U16 \ + " v22.4s, v6.8h \n" PADD_U16 \ + " v23.4s, v7.8h \n" + +void Ssim4x4Row_NEON(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + const ptrdiff_t sa = stride_a; + const ptrdiff_t sb = stride_b; + const uint8_t* a0 = src_a; + const uint8_t* a1 = a0 + sa; + const uint8_t* a2 = a1 + sa; + const uint8_t* a3 = a2 + sa; + const uint8_t* b0 = src_b; + const uint8_t* b1 = b0 + sb; + const uint8_t* b2 = b1 + sb; + const uint8_t* b3 = b2 + sb; + asm volatile( + "1: \n" + "ldr q0, [%[a0]], #16 \n" + "ldr q1, [%[b0]], #16 \n" + "ldr q2, [%[a1]], #16 \n" + "ldr q3, [%[b1]], #16 \n" // + SSIM_ROW_NEON64(v0, v1, "uaddlp", "uaddlp") // + SSIM_ROW_NEON64(v2, v3, "uadalp", "uadalp") // + "ldr q0, [%[a2]], #16 \n" + "ldr q1, [%[b2]], #16 \n" + "ldr q2, [%[a3]], #16 \n" + "ldr q3, [%[b3]], #16 \n" // + SSIM_ROW_NEON64(v0, v1, "uadalp", "uadalp") // + SSIM_ROW_NEON64(v2, v3, "uadalp", "uadalp") // + "uaddlp v16.4s, v4.8h \n" + "uaddlp v17.4s, v5.8h \n" + "addp v18.4s, v20.4s, v21.4s \n" + "addp v19.4s, v22.4s, v23.4s \n" + "subs %w[width], %w[width], #16 \n" + "st4 {v16.4s, v17.4s, v18.4s, v19.4s}, [%[dst]], #64 \n" + "b.gt 1b \n" + : [a0] "+r"(a0), [a1] "+r"(a1), [a2] "+r"(a2), [a3] "+r"(a3), + [b0] "+r"(b0), [b1] "+r"(b1), [b2] "+r"(b2), [b3] "+r"(b3), + [dst] "+r"(dst), [width] "+r"(width) + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23"); +} +#undef SSIM_ROW_NEON64 + +void Ssim4x4Row_NEON_DotProd(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + const ptrdiff_t sa = stride_a; + const ptrdiff_t sb = stride_b; + const uint8_t* a0 = src_a; + const uint8_t* a1 = a0 + sa; + const uint8_t* a2 = a1 + sa; + const uint8_t* a3 = a2 + sa; + const uint8_t* b0 = src_b; + const uint8_t* b1 = b0 + sb; + const uint8_t* b2 = b1 + sb; + const uint8_t* b3 = b2 + sb; + asm volatile( + "movi v6.16b, #1 \n" + "1: \n" + "movi v16.4s, #0 \n" + "movi v17.4s, #0 \n" + "movi v18.4s, #0 \n" + "movi v19.4s, #0 \n" + "ldr q0, [%[a0]], #16 \n" + "ldr q1, [%[b0]], #16 \n" + "ldr q2, [%[a1]], #16 \n" + "ldr q3, [%[b1]], #16 \n" + "udot v16.4s, v0.16b, v6.16b \n" + "udot v17.4s, v1.16b, v6.16b \n" + "udot v18.4s, v0.16b, v0.16b \n" + "udot v18.4s, v1.16b, v1.16b \n" + "udot v19.4s, v0.16b, v1.16b \n" + "udot v16.4s, v2.16b, v6.16b \n" + "udot v17.4s, v3.16b, v6.16b \n" + "udot v18.4s, v2.16b, v2.16b \n" + "udot v18.4s, v3.16b, v3.16b \n" + "udot v19.4s, v2.16b, v3.16b \n" + "ldr q0, [%[a2]], #16 \n" + "ldr q1, [%[b2]], #16 \n" + "ldr q2, [%[a3]], #16 \n" + "ldr q3, [%[b3]], #16 \n" + "udot v16.4s, v0.16b, v6.16b \n" + "udot v17.4s, v1.16b, v6.16b \n" + "udot v18.4s, v0.16b, v0.16b \n" + "udot v18.4s, v1.16b, v1.16b \n" + "udot v19.4s, v0.16b, v1.16b \n" + "udot v16.4s, v2.16b, v6.16b \n" + "udot v17.4s, v3.16b, v6.16b \n" + "udot v18.4s, v2.16b, v2.16b \n" + "udot v18.4s, v3.16b, v3.16b \n" + "udot v19.4s, v2.16b, v3.16b \n" + "subs %w[width], %w[width], #16 \n" + "st4 {v16.4s, v17.4s, v18.4s, v19.4s}, [%[dst]], #64 \n" + "b.gt 1b \n" + : [a0] "+r"(a0), [a1] "+r"(a1), [a2] "+r"(a2), [a3] "+r"(a3), + [b0] "+r"(b0), [b1] "+r"(b1), [b2] "+r"(b2), [b3] "+r"(b3), + [dst] "+r"(dst), [width] "+r"(width) + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v6", "v16", "v17", "v18", + "v19"); +} + +float SsimWindowRow_NEON(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + const uint32_t* row0_next = row0 + 4; + const uint32_t* row1_next = row1 + 4; + float total; + asm volatile( + "movi v24.4s, #0 \n" + "dup v25.4s, %w[c1] \n" + "dup v26.4s, %w[c2] \n" + "1: \n" + "ld4 {v0.4s, v1.4s, v2.4s, v3.4s}, [%[row0]], #64 \n" + "ld4 {v4.4s, v5.4s, v6.4s, v7.4s}, [%[row0_next]], #64 \n" + "ld4 {v16.4s, v17.4s, v18.4s, v19.4s}, [%[row1]], #64 \n" + "ld4 {v20.4s, v21.4s, v22.4s, v23.4s}, [%[row1_next]], #64 \n" + "add v0.4s, v0.4s, v4.4s \n" + "add v1.4s, v1.4s, v5.4s \n" + "add v2.4s, v2.4s, v6.4s \n" + "add v3.4s, v3.4s, v7.4s \n" + "add v16.4s, v16.4s, v20.4s \n" + "add v17.4s, v17.4s, v21.4s \n" + "add v18.4s, v18.4s, v22.4s \n" + "add v19.4s, v19.4s, v23.4s \n" + "add v0.4s, v0.4s, v16.4s \n" + "add v1.4s, v1.4s, v17.4s \n" + "add v2.4s, v2.4s, v18.4s \n" + "add v3.4s, v3.4s, v19.4s \n" + "mul v4.4s, v0.4s, v1.4s \n" + "shl v4.4s, v4.4s, #1 \n" + "mul v5.4s, v0.4s, v0.4s \n" + "mla v5.4s, v1.4s, v1.4s \n" + "shl v3.4s, v3.4s, #7 \n" + "sub v3.4s, v3.4s, v4.4s \n" + "add v4.4s, v4.4s, v25.4s \n" + "add v3.4s, v3.4s, v26.4s \n" + "shl v2.4s, v2.4s, #6 \n" + "sub v2.4s, v2.4s, v5.4s \n" + "add v5.4s, v5.4s, v25.4s \n" + "add v2.4s, v2.4s, v26.4s \n" + "scvtf v4.4s, v4.4s \n" + "scvtf v3.4s, v3.4s \n" + "scvtf v5.4s, v5.4s \n" + "scvtf v2.4s, v2.4s \n" + "fmul v4.4s, v4.4s, v3.4s \n" + "fmul v5.4s, v5.4s, v2.4s \n" + "fdiv v4.4s, v4.4s, v5.4s \n" + "subs %w[num_windows], %w[num_windows], #4 \n" + "fadd v24.4s, v24.4s, v4.4s \n" + "b.gt 1b \n" + "faddp v24.4s, v24.4s, v24.4s \n" + "faddp %s[total], v24.2s \n" + : [row0] "+r"(row0), [row0_next] "+r"(row0_next), [row1] "+r"(row1), + [row1_next] "+r"(row1_next), [num_windows] "+r"(num_windows), + [total] "=w"(total) + : [c1] "r"(26634), [c2] "r"(239708) + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26"); + return total; +} + +uint32_t ARGBDetectRow_NEON(const uint8_t* argb, int width) { + uint64_t diff = 0; + asm volatile( + "movi v2.2d, #0x00ffff0000ffff00 \n" + "movi v3.16b, #0xff \n" + "subs %w[width], %w[width], #4 \n" + "b.lt 2f \n" + "1: \n" + "ldr q0, [%[argb]], #16 \n" + "orr v0.16b, v0.16b, v2.16b \n" + "cmeq v0.16b, v0.16b, v3.16b \n" + "mvn v0.16b, v0.16b \n" + "shrn v0.8b, v0.8h, #4 \n" + "fmov %x[diff], d0 \n" + "cbnz %x[diff], 99f \n" + "subs %w[width], %w[width], #4 \n" + "b.ge 1b \n" + "2: \n" + "adds %w[width], %w[width], #4 \n" + "b.le 99f \n" + "3: \n" + "ldr s0, [%[argb]], #4 \n" + "orr v0.8b, v0.8b, v2.8b \n" + "cmeq v0.8b, v0.8b, v3.8b \n" + "mvn v0.8b, v0.8b \n" + "shrn v0.8b, v0.8h, #4 \n" + "fmov %x[diff], d0 \n" + "and %x[diff], %x[diff], #0xffff \n" + "cbnz %x[diff], 99f \n" + "subs %w[width], %w[width], #1 \n" + "b.gt 3b \n" + "99: \n" + : [argb] "+r"(argb), [width] "+r"(width), [diff] "+r"(diff) + : + : "memory", "cc", "v0", "v2", "v3"); + if (diff) { + return (__builtin_ctzll(diff) & 12) == 0 ? FOURCC_BGRA : FOURCC_ARGB; + } + return 0; +} + #endif // !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) #ifdef __cplusplus diff --git a/libs/libyuv/source/compare_wasm.cc b/libs/libyuv/source/compare_wasm.cc new file mode 100644 index 0000000000..5447cf84be --- /dev/null +++ b/libs/libyuv/source/compare_wasm.cc @@ -0,0 +1,345 @@ +/* + * Copyright 2026 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/compare_row.h" +#include "libyuv/row.h" +#include "libyuv/video_common.h" + +#if !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) +#include + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// Add the 4 32 bit lanes. +static inline uint32_t SumLanes_WASMSIMD(v128_t sum) { + sum = wasm_i32x4_add(sum, wasm_i64x2_shuffle(sum, sum, 1, 0)); + sum = wasm_i32x4_add(sum, wasm_i32x4_shuffle(sum, sum, 1, 0, 3, 2)); + return wasm_u32x4_extract_lane(sum, 0); +} + +#if defined(HAS_HAMMINGDISTANCE_WASMSIMD) +// Bit counts of 64 bytes are added as bytes, then accumulated into 32 bit +// lanes using relaxed i8x16 dot product when available or pairwise widening +// adds. Count is a multiple of 64. +uint32_t HammingDistance_WASMSIMD(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + v128_t sum = wasm_i32x4_splat(0); +#ifdef __wasm_relaxed_simd__ + const v128_t ones = wasm_i8x16_splat(1); +#endif + while (count > 0) { + v128_t c0 = wasm_i8x16_popcnt( + wasm_v128_xor(wasm_v128_load(src_a), wasm_v128_load(src_b))); + v128_t c1 = wasm_i8x16_popcnt( + wasm_v128_xor(wasm_v128_load(src_a + 16), wasm_v128_load(src_b + 16))); + v128_t c2 = wasm_i8x16_popcnt( + wasm_v128_xor(wasm_v128_load(src_a + 32), wasm_v128_load(src_b + 32))); + v128_t c3 = wasm_i8x16_popcnt( + wasm_v128_xor(wasm_v128_load(src_a + 48), wasm_v128_load(src_b + 48))); + v128_t c = wasm_i8x16_add(wasm_i8x16_add(c0, c1), wasm_i8x16_add(c2, c3)); +#ifdef __wasm_relaxed_simd__ + sum = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(c, ones, sum); +#else + sum = wasm_i32x4_add(sum, wasm_u32x4_extadd_pairwise_u16x8( + wasm_u16x8_extadd_pairwise_u8x16(c))); +#endif + src_a += 64; + src_b += 64; + count -= 64; + } + return SumLanes_WASMSIMD(sum); +} +#endif // HAS_HAMMINGDISTANCE_WASMSIMD + +#if defined(HAS_SUMSQUAREERROR_WASMSIMD) +// Differences are widened to signed 16 bits and squared with i32x4.dot. +// Count is a multiple of 16. +uint32_t SumSquareError_WASMSIMD(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + v128_t sum = wasm_i32x4_splat(0); + while (count > 0) { + v128_t a = wasm_v128_load(src_a); + v128_t b = wasm_v128_load(src_b); + v128_t lo = wasm_i16x8_sub(wasm_u16x8_extend_low_u8x16(a), + wasm_u16x8_extend_low_u8x16(b)); + v128_t hi = wasm_i16x8_sub(wasm_u16x8_extend_high_u8x16(a), + wasm_u16x8_extend_high_u8x16(b)); + sum = wasm_i32x4_add(sum, wasm_i32x4_add(wasm_i32x4_dot_i16x8(lo, lo), + wasm_i32x4_dot_i16x8(hi, hi))); + src_a += 16; + src_b += 16; + count -= 16; + } + return SumLanes_WASMSIMD(sum); +} +#endif // HAS_SUMSQUAREERROR_WASMSIMD + +#if defined(HAS_HASHDJB2_WASMSIMD) +static const uint32_t kHashMul_WASMSIMD[24] = { + // 33 ^ (30 - 2 * i) for byte pair i of 32 bytes. + 0xccc4cfc1, 0xd61beb81, 0x13791741, 0xac185301, // 33 ^ 30 .. 24 + 0xc8359ec1, 0x510cfa81, 0xb0da6641, 0x92d9e201, // 33 ^ 22 .. 16 + 0xa3476dc1, 0x4f5f0981, 0x855cb541, 0x747c7101, // 33 ^ 14 .. 8 + 0x4cfa3cc1, 0x00121881, 0x00000441, 0x00000001, // 33 ^ 6 .. 0 + 0x1137c401, 0x1137c401, 0x1137c401, 0x1137c401, // 33 ^ 32 + 0x00010021, 0x00010021, 0x00010021, 0x00010021, // 16 bit 33, 1 +}; + +// Sum of 16 bytes times 33 ^ n, as 4 lanes. Byte pairs are combined as +// src[2 * i] * 33 + src[2 * i + 1] with i32x4.dot, then multiplied by +// 33 ^ n for the pair. +static inline v128_t HashMul16_WASMSIMD(const uint8_t* src, + const v128_t* m, + v128_t k33) { + v128_t s = wasm_v128_load(src); + v128_t lo = wasm_i32x4_dot_i16x8(wasm_u16x8_extend_low_u8x16(s), k33); + v128_t hi = wasm_i32x4_dot_i16x8(wasm_u16x8_extend_high_u8x16(s), k33); + return wasm_i32x4_add(wasm_i32x4_mul(lo, m[0]), wasm_i32x4_mul(hi, m[1])); +} + +// HashDjb2 of n bytes is hash * 33 ^ n + sum(src[i] * 33 ^ (n - 1 - i)). +// Products are summed per lane, multiplying the sums by 33 ^ 32 for each 32 +// bytes, so one horizontal add is done at the end. +// Count is a multiple of 16. +uint32_t HashDjb2_WASMSIMD(const uint8_t* src, int count, uint32_t seed) { + const v128_t* m = (const v128_t*)kHashMul_WASMSIMD; + v128_t sum = wasm_i32x4_make(0, 0, 0, (int32_t)seed); + // Load constants into Wasm locals outside the loop, instead of v128.const + // in the loop. + asm("" : "+r"(m)); + const v128_t k33_32 = m[4]; + const v128_t k33 = m[5]; + if (count & 16) { + // Lane 3 of m[1] is 33 ^ 16, and lanes 0..2 of sum are 0. + sum = wasm_i32x4_add(wasm_i32x4_mul(sum, m[1]), + HashMul16_WASMSIMD(src, m + 2, k33)); + src += 16; + count -= 16; + } + while (count > 0) { + sum = wasm_i32x4_add( + wasm_i32x4_mul(sum, k33_32), + wasm_i32x4_add(HashMul16_WASMSIMD(src, m, k33), + HashMul16_WASMSIMD(src + 16, m + 2, k33))); + src += 32; + count -= 32; + } + return SumLanes_WASMSIMD(sum); +} +#endif // HAS_HASHDJB2_WASMSIMD + +#if defined(HAS_SSIM4X4ROW_WASMSIMD) +void Ssim4x4Row_WASMSIMD(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + const uint8_t* src_a1 = src_a + stride_a; + const uint8_t* src_a2 = src_a1 + stride_a; + const uint8_t* src_a3 = src_a2 + stride_a; + const uint8_t* src_b1 = src_b + stride_b; + const uint8_t* src_b2 = src_b1 + stride_b; + const uint8_t* src_b3 = src_b2 + stride_b; + const v128_t mask = wasm_i16x8_splat(0x00ff); + for (; width > 0; width -= 16) { + v128_t a0 = wasm_v128_load(src_a); + v128_t a1 = wasm_v128_load(src_a1); + v128_t a2 = wasm_v128_load(src_a2); + v128_t a3 = wasm_v128_load(src_a3); + v128_t b0 = wasm_v128_load(src_b); + v128_t b1 = wasm_v128_load(src_b1); + v128_t b2 = wasm_v128_load(src_b2); + v128_t b3 = wasm_v128_load(src_b3); + + v128_t a0_ev = wasm_v128_and(a0, mask); + v128_t a0_od = wasm_u16x8_shr(a0, 8); + v128_t a1_ev = wasm_v128_and(a1, mask); + v128_t a1_od = wasm_u16x8_shr(a1, 8); + v128_t a2_ev = wasm_v128_and(a2, mask); + v128_t a2_od = wasm_u16x8_shr(a2, 8); + v128_t a3_ev = wasm_v128_and(a3, mask); + v128_t a3_od = wasm_u16x8_shr(a3, 8); + + v128_t b0_ev = wasm_v128_and(b0, mask); + v128_t b0_od = wasm_u16x8_shr(b0, 8); + v128_t b1_ev = wasm_v128_and(b1, mask); + v128_t b1_od = wasm_u16x8_shr(b1, 8); + v128_t b2_ev = wasm_v128_and(b2, mask); + v128_t b2_od = wasm_u16x8_shr(b2, 8); + v128_t b3_ev = wasm_v128_and(b3, mask); + v128_t b3_od = wasm_u16x8_shr(b3, 8); + + v128_t sum_a_16 = + wasm_i16x8_add(wasm_i16x8_add(wasm_i16x8_add(a0_ev, a0_od), + wasm_i16x8_add(a1_ev, a1_od)), + wasm_i16x8_add(wasm_i16x8_add(a2_ev, a2_od), + wasm_i16x8_add(a3_ev, a3_od))); + v128_t sum_b_16 = + wasm_i16x8_add(wasm_i16x8_add(wasm_i16x8_add(b0_ev, b0_od), + wasm_i16x8_add(b1_ev, b1_od)), + wasm_i16x8_add(wasm_i16x8_add(b2_ev, b2_od), + wasm_i16x8_add(b3_ev, b3_od))); + + v128_t sum_a = wasm_u32x4_extadd_pairwise_u16x8(sum_a_16); + v128_t sum_b = wasm_u32x4_extadd_pairwise_u16x8(sum_b_16); + + v128_t sum_axb = wasm_i32x4_add( + wasm_i32x4_add(wasm_i32x4_add(wasm_i32x4_dot_i16x8(a0_ev, b0_ev), + wasm_i32x4_dot_i16x8(a0_od, b0_od)), + wasm_i32x4_add(wasm_i32x4_dot_i16x8(a1_ev, b1_ev), + wasm_i32x4_dot_i16x8(a1_od, b1_od))), + wasm_i32x4_add(wasm_i32x4_add(wasm_i32x4_dot_i16x8(a2_ev, b2_ev), + wasm_i32x4_dot_i16x8(a2_od, b2_od)), + wasm_i32x4_add(wasm_i32x4_dot_i16x8(a3_ev, b3_ev), + wasm_i32x4_dot_i16x8(a3_od, b3_od)))); + + v128_t sq0 = + wasm_i32x4_add(wasm_i32x4_add(wasm_i32x4_dot_i16x8(a0_ev, a0_ev), + wasm_i32x4_dot_i16x8(a0_od, a0_od)), + wasm_i32x4_add(wasm_i32x4_dot_i16x8(b0_ev, b0_ev), + wasm_i32x4_dot_i16x8(b0_od, b0_od))); + v128_t sq1 = + wasm_i32x4_add(wasm_i32x4_add(wasm_i32x4_dot_i16x8(a1_ev, a1_ev), + wasm_i32x4_dot_i16x8(a1_od, a1_od)), + wasm_i32x4_add(wasm_i32x4_dot_i16x8(b1_ev, b1_ev), + wasm_i32x4_dot_i16x8(b1_od, b1_od))); + v128_t sq2 = + wasm_i32x4_add(wasm_i32x4_add(wasm_i32x4_dot_i16x8(a2_ev, a2_ev), + wasm_i32x4_dot_i16x8(a2_od, a2_od)), + wasm_i32x4_add(wasm_i32x4_dot_i16x8(b2_ev, b2_ev), + wasm_i32x4_dot_i16x8(b2_od, b2_od))); + v128_t sq3 = + wasm_i32x4_add(wasm_i32x4_add(wasm_i32x4_dot_i16x8(a3_ev, a3_ev), + wasm_i32x4_dot_i16x8(a3_od, a3_od)), + wasm_i32x4_add(wasm_i32x4_dot_i16x8(b3_ev, b3_ev), + wasm_i32x4_dot_i16x8(b3_od, b3_od))); + v128_t sum_sq_ab = + wasm_i32x4_add(wasm_i32x4_add(sq0, sq1), wasm_i32x4_add(sq2, sq3)); + + v128_t t0 = wasm_i32x4_shuffle(sum_a, sum_b, 0, 4, 1, 5); + v128_t t1 = wasm_i32x4_shuffle(sum_a, sum_b, 2, 6, 3, 7); + v128_t t2 = wasm_i32x4_shuffle(sum_sq_ab, sum_axb, 0, 4, 1, 5); + v128_t t3 = wasm_i32x4_shuffle(sum_sq_ab, sum_axb, 2, 6, 3, 7); + + wasm_v128_store(dst, wasm_i64x2_shuffle(t0, t2, 0, 2)); + wasm_v128_store(dst + 4, wasm_i64x2_shuffle(t0, t2, 1, 3)); + wasm_v128_store(dst + 8, wasm_i64x2_shuffle(t1, t3, 0, 2)); + wasm_v128_store(dst + 12, wasm_i64x2_shuffle(t1, t3, 1, 3)); + + src_a += 16; + src_a1 += 16; + src_a2 += 16; + src_a3 += 16; + src_b += 16; + src_b1 += 16; + src_b2 += 16; + src_b3 += 16; + dst += 16; + } +} +#endif // HAS_SSIM4X4ROW_WASMSIMD + +#if defined(HAS_SSIMWINDOWROW_WASMSIMD) +float SsimWindowRow_WASMSIMD(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + const v128_t vc1 = wasm_i32x4_splat(26634); + const v128_t vc2 = wasm_i32x4_splat(239708); + v128_t total = wasm_f32x4_splat(0.0f); + v128_t t0 = wasm_i32x4_add(wasm_v128_load(row0), wasm_v128_load(row1)); + int w; + for (w = 0; w < num_windows; w += 4) { + v128_t t1 = + wasm_i32x4_add(wasm_v128_load(row0 + 4), wasm_v128_load(row1 + 4)); + v128_t t2 = + wasm_i32x4_add(wasm_v128_load(row0 + 8), wasm_v128_load(row1 + 8)); + v128_t t3 = + wasm_i32x4_add(wasm_v128_load(row0 + 12), wasm_v128_load(row1 + 12)); + v128_t t4 = + wasm_i32x4_add(wasm_v128_load(row0 + 16), wasm_v128_load(row1 + 16)); + row0 += 16; + row1 += 16; + v128_t w0 = wasm_i32x4_add(t0, t1); + v128_t w1 = wasm_i32x4_add(t1, t2); + v128_t w2 = wasm_i32x4_add(t2, t3); + v128_t w3 = wasm_i32x4_add(t3, t4); + t0 = t4; + + v128_t u0 = wasm_i32x4_shuffle(w0, w1, 0, 4, 1, 5); + v128_t u1 = wasm_i32x4_shuffle(w0, w1, 2, 6, 3, 7); + v128_t u2 = wasm_i32x4_shuffle(w2, w3, 0, 4, 1, 5); + v128_t u3 = wasm_i32x4_shuffle(w2, w3, 2, 6, 3, 7); + v128_t sum_a = wasm_i64x2_shuffle(u0, u2, 0, 2); + v128_t sum_b = wasm_i64x2_shuffle(u0, u2, 1, 3); + v128_t sum_sq = wasm_i64x2_shuffle(u1, u3, 0, 2); + v128_t sum_axb = wasm_i64x2_shuffle(u1, u3, 1, 3); + + v128_t ab2 = wasm_i32x4_shl(wasm_i32x4_dot_i16x8(sum_a, sum_b), 1); + v128_t a2b2 = wasm_i32x4_add(wasm_i32x4_dot_i16x8(sum_a, sum_a), + wasm_i32x4_dot_i16x8(sum_b, sum_b)); + v128_t n1 = wasm_i32x4_add(ab2, vc1); + v128_t n2 = + wasm_i32x4_add(wasm_i32x4_sub(wasm_i32x4_shl(sum_axb, 7), ab2), vc2); + v128_t d1 = wasm_i32x4_add(a2b2, vc1); + v128_t d2 = + wasm_i32x4_add(wasm_i32x4_sub(wasm_i32x4_shl(sum_sq, 6), a2b2), vc2); + + v128_t num = wasm_f32x4_mul(wasm_f32x4_convert_i32x4(n1), + wasm_f32x4_convert_i32x4(n2)); + v128_t den = wasm_f32x4_mul(wasm_f32x4_convert_i32x4(d1), + wasm_f32x4_convert_i32x4(d2)); + total = wasm_f32x4_add(total, wasm_f32x4_div(num, den)); + } + total = wasm_f32x4_add(total, wasm_i64x2_shuffle(total, total, 1, 0)); + total = wasm_f32x4_add(total, wasm_i32x4_shuffle(total, total, 1, 0, 3, 2)); + return wasm_f32x4_extract_lane(total, 0); +} +#endif // HAS_SSIMWINDOWROW_WASMSIMD + +#if defined(HAS_ARGBDETECTROW_WASMSIMD) +uint32_t ARGBDetectRow_WASMSIMD(const uint8_t* argb, int width) { + const v128_t mask_rgb = wasm_i32x4_splat(0x00ffff00); + const v128_t ones = wasm_i8x16_splat(-1); + while (width >= 4) { + v128_t v = wasm_v128_or(wasm_v128_load(argb), mask_rgb); + uint32_t diff = + (~(uint32_t)wasm_i8x16_bitmask(wasm_i8x16_eq(v, ones))) & 0xffffu; + if (diff) { + return (__builtin_ctz(diff) & 3) == 0 ? FOURCC_BGRA : FOURCC_ARGB; + } + argb += 16; + width -= 4; + } + while (width > 0) { + v128_t v = wasm_v128_or(wasm_v128_load32_zero(argb), mask_rgb); + uint32_t diff = + (~(uint32_t)wasm_i8x16_bitmask(wasm_i8x16_eq(v, ones))) & 0x9u; + if (diff) { + return (diff & 1u) ? FOURCC_BGRA : FOURCC_ARGB; + } + argb += 4; + width -= 1; + } + return 0; +} +#endif // HAS_ARGBDETECTROW_WASMSIMD + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) diff --git a/libs/libyuv/source/compare_win.cc b/libs/libyuv/source/compare_win.cc index d57d3d9d1c..a25cf6efae 100644 --- a/libs/libyuv/source/compare_win.cc +++ b/libs/libyuv/source/compare_win.cc @@ -8,13 +8,22 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "libyuv/basic_types.h" - #include "libyuv/compare_row.h" #include "libyuv/row.h" +#include "libyuv/video_common.h" -#if defined(_MSC_VER) -#include // For __popcnt +// This module is for Visual C 32/64 bit, and for clang with +// LIBYUV_ENABLE_ROWWIN, which is also enabled for MemorySanitizer. +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || \ + defined(_M_IX86)) && \ + ((defined(_MSC_VER) && !defined(__clang__)) || \ + defined(LIBYUV_ENABLE_ROWWIN)) + +#include // For SSE2 to AVX512 intrinsics +#include // For memcpy +#if defined(_MSC_VER) && !defined(__clang__) +#include #endif #ifdef __cplusplus @@ -22,220 +31,998 @@ namespace libyuv { extern "C" { #endif -// This module is for 32 bit Visual C x86 and clangcl -#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) +// Target attributes allow gcc and clang to build each function for its +// instruction set regardless of the baseline. +#if defined(__clang__) || defined(__GNUC__) +#define LIBYUV_TARGET_SSE2 __attribute__((target("sse2"))) +#define LIBYUV_TARGET_SSE41 __attribute__((target("sse4.1"))) +#define LIBYUV_TARGET_SSE42 __attribute__((target("sse4.2,popcnt"))) +#define LIBYUV_TARGET_AVX2 __attribute__((target("avx2"))) +#define LIBYUV_TARGET_AVX512BW \ + __attribute__((target("avx512bw,avx512vl,avx512f"))) +#define LIBYUV_TARGET_AVX512VNNI \ + __attribute__((target("avx512vnni,avx512bw,avx512vl,avx512f"))) +#else +#define LIBYUV_TARGET_SSE2 +#define LIBYUV_TARGET_SSE41 +#define LIBYUV_TARGET_SSE42 +#define LIBYUV_TARGET_AVX2 +#define LIBYUV_TARGET_AVX512BW +#define LIBYUV_TARGET_AVX512VNNI +#endif // defined(__clang__) || defined(__GNUC__) +#if defined(HAS_HAMMINGDISTANCE_SSE42) +// Count is a multiple of 8. +LIBYUV_TARGET_SSE42 uint32_t HammingDistance_SSE42(const uint8_t* src_a, const uint8_t* src_b, int count) { uint32_t diff = 0u; - int i; - for (i = 0; i < count - 3; i += 4) { - uint32_t x = *((uint32_t*)src_a) ^ *((uint32_t*)src_b); // NOLINT - src_a += 4; - src_b += 4; - diff += __popcnt(x); + for (i = 0; i < count; i += 8) { + uint64_t a; + uint64_t b; + memcpy(&a, src_a + i, 8); + memcpy(&b, src_b + i, 8); +#if defined(__x86_64__) || defined(_M_X64) + diff += (uint32_t)_mm_popcnt_u64(a ^ b); +#else + diff += _mm_popcnt_u32((uint32_t)(a ^ b)) + + _mm_popcnt_u32((uint32_t)((a ^ b) >> 32)); +#endif } return diff; } +#endif // HAS_HAMMINGDISTANCE_SSE42 -__declspec(naked) uint32_t - SumSquareError_SSE2(const uint8_t* src_a, const uint8_t* src_b, int count) { - __asm { - mov eax, [esp + 4] // src_a - mov edx, [esp + 8] // src_b - mov ecx, [esp + 12] // count - pxor xmm0, xmm0 - pxor xmm5, xmm5 +#if defined(HAS_HAMMINGDISTANCE_AVX512BW) || \ + defined(HAS_HAMMINGDISTANCE_AVX512VNNI) || \ + defined(HAS_SUMSQUAREERROR_AVX512BW) || \ + defined(HAS_SUMSQUAREERROR_AVX512VNNI) || \ + defined(HAS_HASHDJB2_AVX512BW) || defined(HAS_SSIM4X4ROW_AVX512BW) +// Mask of the low n bytes, for n = 0 to 64. +static __mmask64 LowBytesMask64(int n) { + return (__mmask64)(n >= 64 ? ~0ULL : (1ULL << n) - 1); +} +#endif - wloop: - movdqu xmm1, [eax] - lea eax, [eax + 16] - movdqu xmm2, [edx] - lea edx, [edx + 16] - movdqa xmm3, xmm1 // abs trick - psubusb xmm1, xmm2 - psubusb xmm2, xmm3 - por xmm1, xmm2 - movdqa xmm2, xmm1 - punpcklbw xmm1, xmm5 - punpckhbw xmm2, xmm5 - pmaddwd xmm1, xmm1 - pmaddwd xmm2, xmm2 - paddd xmm0, xmm1 - paddd xmm0, xmm2 - sub ecx, 16 - jg wloop - - pshufd xmm1, xmm0, 0xee - paddd xmm0, xmm1 - pshufd xmm1, xmm0, 0x01 - paddd xmm0, xmm1 - movd eax, xmm0 - ret +#if defined(HAS_HAMMINGDISTANCE_AVX2) +// Count is a multiple of 64. +LIBYUV_TARGET_AVX2 +uint32_t HammingDistance_AVX2(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + const __m256i kNibbleMask = _mm256_set1_epi8(15); + const __m256i kBitCount = _mm256_broadcastsi128_si256( + _mm_setr_epi8(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4)); + const __m256i zero = _mm256_setzero_si256(); + __m256i sum = _mm256_setzero_si256(); + __m128i sum128; + int i; + for (i = 0; i < count; i += 64) { + __m256i x0 = + _mm256_xor_si256(_mm256_loadu_si256((const __m256i*)(src_a + i)), + _mm256_loadu_si256((const __m256i*)(src_b + i))); + __m256i x1 = + _mm256_xor_si256(_mm256_loadu_si256((const __m256i*)(src_a + i + 32)), + _mm256_loadu_si256((const __m256i*)(src_b + i + 32))); + __m256i c0 = _mm256_add_epi8( + _mm256_shuffle_epi8(kBitCount, _mm256_and_si256(x0, kNibbleMask)), + _mm256_shuffle_epi8( + kBitCount, + _mm256_and_si256(_mm256_srli_epi16(x0, 4), kNibbleMask))); + __m256i c1 = _mm256_add_epi8( + _mm256_shuffle_epi8(kBitCount, _mm256_and_si256(x1, kNibbleMask)), + _mm256_shuffle_epi8( + kBitCount, + _mm256_and_si256(_mm256_srli_epi16(x1, 4), kNibbleMask))); + sum = _mm256_add_epi64(sum, _mm256_sad_epu8(_mm256_add_epi8(c0, c1), zero)); } + sum128 = _mm_add_epi64(_mm256_castsi256_si128(sum), + _mm256_extracti128_si256(sum, 1)); + sum128 = _mm_add_epi64(sum128, _mm_unpackhi_epi64(sum128, sum128)); + _mm256_zeroupper(); + return (uint32_t)_mm_cvtsi128_si32(sum128); +} +#endif // HAS_HAMMINGDISTANCE_AVX2 + +#if defined(HAS_HAMMINGDISTANCE_AVX512BW) +// Bit count of 64 bytes, summed to 8 qwords. +LIBYUV_TARGET_AVX512BW +static __m512i BitCount64_AVX512BW(__m512i x) { + const __m512i kNibbleMask = _mm512_set1_epi8(15); + const __m512i kBitCount = _mm512_broadcast_i32x4( + _mm_setr_epi8(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4)); + __m512i lo = _mm512_shuffle_epi8(kBitCount, _mm512_and_si512(x, kNibbleMask)); + __m512i hi = _mm512_shuffle_epi8( + kBitCount, _mm512_and_si512(_mm512_srli_epi16(x, 4), kNibbleMask)); + return _mm512_sad_epu8(_mm512_add_epi8(lo, hi), _mm512_setzero_si512()); } -// Visual C 2012 required for AVX2. -#if _MSC_VER >= 1700 -// C4752: found Intel(R) Advanced Vector Extensions; consider using /arch:AVX. -#pragma warning(disable : 4752) -__declspec(naked) uint32_t - SumSquareError_AVX2(const uint8_t* src_a, const uint8_t* src_b, int count) { - __asm { - mov eax, [esp + 4] // src_a - mov edx, [esp + 8] // src_b - mov ecx, [esp + 12] // count - vpxor ymm0, ymm0, ymm0 // sum - vpxor ymm5, ymm5, ymm5 // constant 0 for unpck - sub edx, eax - - wloop: - vmovdqu ymm1, [eax] - vmovdqu ymm2, [eax + edx] - lea eax, [eax + 32] - vpsubusb ymm3, ymm1, ymm2 // abs difference trick - vpsubusb ymm2, ymm2, ymm1 - vpor ymm1, ymm2, ymm3 - vpunpcklbw ymm2, ymm1, ymm5 // u16. mutates order. - vpunpckhbw ymm1, ymm1, ymm5 - vpmaddwd ymm2, ymm2, ymm2 // square + hadd to u32. - vpmaddwd ymm1, ymm1, ymm1 - vpaddd ymm0, ymm0, ymm1 - vpaddd ymm0, ymm0, ymm2 - sub ecx, 32 - jg wloop - - vpshufd ymm1, ymm0, 0xee // 3, 2 + 1, 0 both lanes. - vpaddd ymm0, ymm0, ymm1 - vpshufd ymm1, ymm0, 0x01 // 1 + 0 both lanes. - vpaddd ymm0, ymm0, ymm1 - vpermq ymm1, ymm0, 0x02 // high + low lane. - vpaddd ymm0, ymm0, ymm1 - vmovd eax, xmm0 - vzeroupper - ret +// Process 64 bytes per loop and the remainder of 1 to 63 bytes with masked +// loads that read zeros, so any count is supported. +LIBYUV_TARGET_AVX512BW +uint32_t HammingDistance_AVX512BW(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + __m512i sum = _mm512_setzero_si512(); + while (count >= 64) { + sum = _mm512_add_epi64( + sum, BitCount64_AVX512BW(_mm512_xor_si512(_mm512_loadu_si512(src_a), + _mm512_loadu_si512(src_b)))); + src_a += 64; + src_b += 64; + count -= 64; } + if (count > 0) { + const __mmask64 k = LowBytesMask64(count); + sum = _mm512_add_epi64(sum, BitCount64_AVX512BW(_mm512_xor_si512( + _mm512_maskz_loadu_epi8(k, src_a), + _mm512_maskz_loadu_epi8(k, src_b)))); + } + return (uint32_t)_mm512_reduce_add_epi64(sum); } -#endif // _MSC_VER >= 1700 +#endif // HAS_HAMMINGDISTANCE_AVX512BW -uvec32 kHash16x33 = {0x92d9e201, 0, 0, 0}; // 33 ^ 16 -uvec32 kHashMul0 = { - 0x0c3525e1, // 33 ^ 15 - 0xa3476dc1, // 33 ^ 14 - 0x3b4039a1, // 33 ^ 13 - 0x4f5f0981, // 33 ^ 12 -}; -uvec32 kHashMul1 = { - 0x30f35d61, // 33 ^ 11 - 0x855cb541, // 33 ^ 10 - 0x040a9121, // 33 ^ 9 - 0x747c7101, // 33 ^ 8 -}; -uvec32 kHashMul2 = { - 0xec41d4e1, // 33 ^ 7 - 0x4cfa3cc1, // 33 ^ 6 - 0x025528a1, // 33 ^ 5 - 0x00121881, // 33 ^ 4 -}; -uvec32 kHashMul3 = { - 0x00008c61, // 33 ^ 3 - 0x00000441, // 33 ^ 2 - 0x00000021, // 33 ^ 1 - 0x00000001, // 33 ^ 0 -}; - -__declspec(naked) uint32_t - HashDjb2_SSE41(const uint8_t* src, int count, uint32_t seed) { - __asm { - mov eax, [esp + 4] // src - mov ecx, [esp + 8] // count - movd xmm0, [esp + 12] // seed - - pxor xmm7, xmm7 // constant 0 for unpck - movdqa xmm6, xmmword ptr kHash16x33 - - wloop: - movdqu xmm1, [eax] // src[0-15] - lea eax, [eax + 16] - pmulld xmm0, xmm6 // hash *= 33 ^ 16 - movdqa xmm5, xmmword ptr kHashMul0 - movdqa xmm2, xmm1 - punpcklbw xmm2, xmm7 // src[0-7] - movdqa xmm3, xmm2 - punpcklwd xmm3, xmm7 // src[0-3] - pmulld xmm3, xmm5 - movdqa xmm5, xmmword ptr kHashMul1 - movdqa xmm4, xmm2 - punpckhwd xmm4, xmm7 // src[4-7] - pmulld xmm4, xmm5 - movdqa xmm5, xmmword ptr kHashMul2 - punpckhbw xmm1, xmm7 // src[8-15] - movdqa xmm2, xmm1 - punpcklwd xmm2, xmm7 // src[8-11] - pmulld xmm2, xmm5 - movdqa xmm5, xmmword ptr kHashMul3 - punpckhwd xmm1, xmm7 // src[12-15] - pmulld xmm1, xmm5 - paddd xmm3, xmm4 // add 16 results - paddd xmm1, xmm2 - paddd xmm1, xmm3 - - pshufd xmm2, xmm1, 0x0e // upper 2 dwords - paddd xmm1, xmm2 - pshufd xmm2, xmm1, 0x01 - paddd xmm1, xmm2 - paddd xmm0, xmm1 - sub ecx, 16 - jg wloop - - movd eax, xmm0 // return hash - ret - } +#if defined(HAS_HAMMINGDISTANCE_AVX512VNNI) +// Bit count of 64 bytes accumulated into 16 dwords with vpdpbusd. +LIBYUV_TARGET_AVX512VNNI +static __m512i BitCount64_AVX512VNNI(__m512i x, __m512i sum) { + const __m512i kNibbleMask = _mm512_set1_epi8(15); + const __m512i kOnes = _mm512_set1_epi8(1); + const __m512i kBitCount = _mm512_broadcast_i32x4( + _mm_setr_epi8(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4)); + __m512i lo = _mm512_shuffle_epi8(kBitCount, _mm512_and_si512(x, kNibbleMask)); + __m512i hi = _mm512_shuffle_epi8( + kBitCount, _mm512_and_si512(_mm512_srli_epi16(x, 4), kNibbleMask)); + return _mm512_dpbusd_epi32(sum, kOnes, _mm512_add_epi8(lo, hi)); } -// Visual C 2012 required for AVX2. -#if _MSC_VER >= 1700 -__declspec(naked) uint32_t - HashDjb2_AVX2(const uint8_t* src, int count, uint32_t seed) { - __asm { - mov eax, [esp + 4] // src - mov ecx, [esp + 8] // count - vmovd xmm0, [esp + 12] // seed +// Process 64 bytes per loop and the remainder of 1 to 63 bytes with masked +// loads that read zeros, so any count is supported. +LIBYUV_TARGET_AVX512VNNI +uint32_t HammingDistance_AVX512VNNI(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + __m512i sum = _mm512_setzero_si512(); + while (count >= 64) { + sum = BitCount64_AVX512VNNI( + _mm512_xor_si512(_mm512_loadu_si512(src_a), _mm512_loadu_si512(src_b)), + sum); + src_a += 64; + src_b += 64; + count -= 64; + } + if (count > 0) { + const __mmask64 k = LowBytesMask64(count); + sum = BitCount64_AVX512VNNI( + _mm512_xor_si512(_mm512_maskz_loadu_epi8(k, src_a), + _mm512_maskz_loadu_epi8(k, src_b)), + sum); + } + return (uint32_t)_mm512_reduce_add_epi32(sum); +} +#endif // HAS_HAMMINGDISTANCE_AVX512VNNI - wloop: - vpmovzxbd xmm3, [eax] // src[0-3] - vpmulld xmm0, xmm0, xmmword ptr kHash16x33 // hash *= 33 ^ 16 - vpmovzxbd xmm4, [eax + 4] // src[4-7] - vpmulld xmm3, xmm3, xmmword ptr kHashMul0 - vpmovzxbd xmm2, [eax + 8] // src[8-11] - vpmulld xmm4, xmm4, xmmword ptr kHashMul1 - vpmovzxbd xmm1, [eax + 12] // src[12-15] - vpmulld xmm2, xmm2, xmmword ptr kHashMul2 - lea eax, [eax + 16] - vpmulld xmm1, xmm1, xmmword ptr kHashMul3 - vpaddd xmm3, xmm3, xmm4 // add 16 results - vpaddd xmm1, xmm1, xmm2 - vpaddd xmm1, xmm1, xmm3 - vpshufd xmm2, xmm1, 0x0e // upper 2 dwords - vpaddd xmm1, xmm1,xmm2 - vpshufd xmm2, xmm1, 0x01 - vpaddd xmm1, xmm1, xmm2 - vpaddd xmm0, xmm0, xmm1 - sub ecx, 16 - jg wloop +#if defined(HAS_SUMSQUAREERROR_SSE2) +// Count is a multiple of 16. +LIBYUV_TARGET_SSE2 +uint32_t SumSquareError_SSE2(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + const __m128i zero = _mm_setzero_si128(); + __m128i sum = _mm_setzero_si128(); + int i; + for (i = 0; i < count; i += 16) { + __m128i a = _mm_loadu_si128((const __m128i*)(src_a + i)); + __m128i b = _mm_loadu_si128((const __m128i*)(src_b + i)); + __m128i d = _mm_or_si128(_mm_subs_epu8(a, b), _mm_subs_epu8(b, a)); + __m128i lo = _mm_unpacklo_epi8(d, zero); + __m128i hi = _mm_unpackhi_epi8(d, zero); + sum = _mm_add_epi32(sum, _mm_madd_epi16(lo, lo)); + sum = _mm_add_epi32(sum, _mm_madd_epi16(hi, hi)); + } + sum = _mm_add_epi32(sum, _mm_shuffle_epi32(sum, 0xee)); + sum = _mm_add_epi32(sum, _mm_shuffle_epi32(sum, 0x01)); + return (uint32_t)_mm_cvtsi128_si32(sum); +} +#endif // HAS_SUMSQUAREERROR_SSE2 - vmovd eax, xmm0 // return hash - vzeroupper - ret +#if defined(HAS_SUMSQUAREERROR_AVX2) +// Count is a multiple of 32. +LIBYUV_TARGET_AVX2 +uint32_t SumSquareError_AVX2(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + const __m256i zero = _mm256_setzero_si256(); + __m256i sum = _mm256_setzero_si256(); + __m128i sum128; + int i; + for (i = 0; i < count; i += 32) { + __m256i a = _mm256_loadu_si256((const __m256i*)(src_a + i)); + __m256i b = _mm256_loadu_si256((const __m256i*)(src_b + i)); + __m256i d = _mm256_or_si256(_mm256_subs_epu8(a, b), _mm256_subs_epu8(b, a)); + __m256i lo = _mm256_unpacklo_epi8(d, zero); + __m256i hi = _mm256_unpackhi_epi8(d, zero); + sum = _mm256_add_epi32(sum, _mm256_madd_epi16(lo, lo)); + sum = _mm256_add_epi32(sum, _mm256_madd_epi16(hi, hi)); + } + sum128 = _mm_add_epi32(_mm256_castsi256_si128(sum), + _mm256_extracti128_si256(sum, 1)); + sum128 = _mm_add_epi32(sum128, _mm_shuffle_epi32(sum128, 0xee)); + sum128 = _mm_add_epi32(sum128, _mm_shuffle_epi32(sum128, 0x01)); + _mm256_zeroupper(); + return (uint32_t)_mm_cvtsi128_si32(sum128); +} +#endif // HAS_SUMSQUAREERROR_AVX2 + +#if defined(HAS_SUMSQUAREERROR_AVX512BW) +// Sum of squared differences of 64 bytes, as 16 dwords. +LIBYUV_TARGET_AVX512BW +static __m512i SumSquare64_AVX512BW(__m512i a, __m512i b) { + const __m512i zero = _mm512_setzero_si512(); + __m512i d = _mm512_or_si512(_mm512_subs_epu8(a, b), _mm512_subs_epu8(b, a)); + __m512i lo = _mm512_unpacklo_epi8(d, zero); + __m512i hi = _mm512_unpackhi_epi8(d, zero); + return _mm512_add_epi32(_mm512_madd_epi16(lo, lo), _mm512_madd_epi16(hi, hi)); +} + +// Process 64 bytes per loop and the remainder of 1 to 63 bytes with masked +// loads that read zeros, so any count is supported. +LIBYUV_TARGET_AVX512BW +uint32_t SumSquareError_AVX512BW(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + __m512i sum = _mm512_setzero_si512(); + while (count >= 64) { + sum = + _mm512_add_epi32(sum, SumSquare64_AVX512BW(_mm512_loadu_si512(src_a), + _mm512_loadu_si512(src_b))); + src_a += 64; + src_b += 64; + count -= 64; + } + if (count > 0) { + const __mmask64 k = LowBytesMask64(count); + sum = _mm512_add_epi32( + sum, SumSquare64_AVX512BW(_mm512_maskz_loadu_epi8(k, src_a), + _mm512_maskz_loadu_epi8(k, src_b))); + } + return (uint32_t)_mm512_reduce_add_epi32(sum); +} +#endif // HAS_SUMSQUAREERROR_AVX512BW + +#if defined(HAS_SUMSQUAREERROR_AVX512VNNI) +// Process 64 bytes per loop and the remainder of 1 to 63 bytes with masked +// loads that read zeros, so any count is supported. +LIBYUV_TARGET_AVX512VNNI +uint32_t SumSquareError_AVX512VNNI(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + const __m512i zero = _mm512_setzero_si512(); + __m512i sum0 = _mm512_setzero_si512(); + __m512i sum1 = _mm512_setzero_si512(); + while (count >= 64) { + __m512i a = _mm512_loadu_si512(src_a); + __m512i b = _mm512_loadu_si512(src_b); + __m512i d = _mm512_or_si512(_mm512_subs_epu8(a, b), _mm512_subs_epu8(b, a)); + __m512i lo = _mm512_unpacklo_epi8(d, zero); + __m512i hi = _mm512_unpackhi_epi8(d, zero); + sum0 = _mm512_dpwssd_epi32(sum0, lo, lo); + sum1 = _mm512_dpwssd_epi32(sum1, hi, hi); + src_a += 64; + src_b += 64; + count -= 64; + } + if (count > 0) { + const __mmask64 k = LowBytesMask64(count); + __m512i a = _mm512_maskz_loadu_epi8(k, src_a); + __m512i b = _mm512_maskz_loadu_epi8(k, src_b); + __m512i d = _mm512_or_si512(_mm512_subs_epu8(a, b), _mm512_subs_epu8(b, a)); + __m512i lo = _mm512_unpacklo_epi8(d, zero); + __m512i hi = _mm512_unpackhi_epi8(d, zero); + sum0 = _mm512_dpwssd_epi32(sum0, lo, lo); + sum1 = _mm512_dpwssd_epi32(sum1, hi, hi); + } + return (uint32_t)_mm512_reduce_add_epi32(_mm512_add_epi32(sum0, sum1)); +} +#endif // HAS_SUMSQUAREERROR_AVX512VNNI + +#if defined(HAS_HASHDJB2_SSE41) +// 33 ^ (15 - i) for byte i of 16. +static const uint32_t kHashMul16[16] = { + 0x0c3525e1, 0xa3476dc1, 0x3b4039a1, 0x4f5f0981, // 33 ^ 15 .. 12 + 0x30f35d61, 0x855cb541, 0x040a9121, 0x747c7101, // 33 ^ 11 .. 8 + 0xec41d4e1, 0x4cfa3cc1, 0x025528a1, 0x00121881, // 33 ^ 7 .. 4 + 0x00008c61, 0x00000441, 0x00000021, 0x00000001, // 33 ^ 3 .. 0 +}; +static const uint32_t kHash16x33 = 0x92d9e201; // 33 ^ 16 + +// Count is a multiple of 16. +LIBYUV_TARGET_SSE41 +uint32_t HashDjb2_SSE41(const uint8_t* src, int count, uint32_t seed) { + const __m128i zero = _mm_setzero_si128(); + const __m128i mul0 = _mm_loadu_si128((const __m128i*)(kHashMul16)); + const __m128i mul1 = _mm_loadu_si128((const __m128i*)(kHashMul16 + 4)); + const __m128i mul2 = _mm_loadu_si128((const __m128i*)(kHashMul16 + 8)); + const __m128i mul3 = _mm_loadu_si128((const __m128i*)(kHashMul16 + 12)); + int i; + for (i = 0; i < count; i += 16) { + __m128i s = _mm_loadu_si128((const __m128i*)(src + i)); + __m128i lo = _mm_unpacklo_epi8(s, zero); + __m128i hi = _mm_unpackhi_epi8(s, zero); + __m128i sum = _mm_add_epi32( + _mm_add_epi32(_mm_mullo_epi32(_mm_unpacklo_epi16(lo, zero), mul0), + _mm_mullo_epi32(_mm_unpackhi_epi16(lo, zero), mul1)), + _mm_add_epi32(_mm_mullo_epi32(_mm_unpacklo_epi16(hi, zero), mul2), + _mm_mullo_epi32(_mm_unpackhi_epi16(hi, zero), mul3))); + sum = _mm_add_epi32(sum, _mm_shuffle_epi32(sum, 0x0e)); + sum = _mm_add_epi32(sum, _mm_shuffle_epi32(sum, 0x01)); + seed = seed * kHash16x33 + (uint32_t)_mm_cvtsi128_si32(sum); + } + return seed; +} +#endif // HAS_HASHDJB2_SSE41 + +#if defined(HAS_HASHDJB2_AVX2) || defined(HAS_HASHDJB2_AVX512BW) +// HashDjb2 is hash = hash * 33 ^ n + sum(src[i] * 33 ^ (n - 1 - i)). +// The 32 bit multipliers 33 ^ (63 - i) are split into 16 bit halves so that +// vpmaddwd can be used instead of vpmulld, which is 2 uops and 10 cycles. +// m = hi * 65536 + lo, with lo treated as signed and hi adjusted by the carry, +// so src * m = src * lo + ((src * hi) << 16) modulo 2 ^ 32. +// The first 64 are lo and the next 64 are hi. +static const uint16_t kHashMulLoHi[128] = { + // lo for 33 ^ 63 .. 33 ^ 0 + 0x0be1, 0x93c1, 0x9fa1, 0xaf81, 0x4361, 0xdb41, 0xf721, 0x1701, // + 0xbae1, 0x62c1, 0x8ea1, 0xbe81, 0x7261, 0x2a41, 0x6621, 0xa601, // + 0x69e1, 0x31c1, 0x7da1, 0xcd81, 0xa161, 0x7941, 0xd521, 0x3501, // + 0x18e1, 0x00c1, 0x6ca1, 0xdc81, 0xd061, 0xc841, 0x4421, 0xc401, // + 0xc7e1, 0xcfc1, 0x5ba1, 0xeb81, 0xff61, 0x1741, 0xb321, 0x5301, // + 0x76e1, 0x9ec1, 0x4aa1, 0xfa81, 0x2e61, 0x6641, 0x2221, 0xe201, // + 0x25e1, 0x6dc1, 0x39a1, 0x0981, 0x5d61, 0xb541, 0x9121, 0x7101, // + 0xd4e1, 0x3cc1, 0x28a1, 0x1881, 0x8c61, 0x0441, 0x0021, 0x0001, // + // hi for 33 ^ 63 .. 33 ^ 0 + 0xd8be, 0xef4c, 0x6458, 0x6022, 0x40f9, 0x193e, 0x6d5f, 0x31dc, // + 0x0945, 0xc238, 0x1567, 0xa38f, 0x3380, 0x301b, 0x664e, 0x031a, // + 0xd18c, 0xb8c6, 0x79f6, 0xae5d, 0x0549, 0xc219, 0x7a3f, 0x1338, // + 0x0095, 0xc1f5, 0xa107, 0xaf8c, 0x0552, 0x3e39, 0x3830, 0x1138, // + 0x655f, 0xccc5, 0x9999, 0xd61c, 0x829c, 0x1379, 0x2f23, 0xac18, // + 0xcee9, 0xc836, 0x72ac, 0x510d, 0xcc27, 0xb0da, 0xee16, 0x92da, // + 0x0c35, 0xa347, 0x3b40, 0x4f5f, 0x30f3, 0x855d, 0x040b, 0x747c, // + 0xec42, 0x4cfa, 0x0255, 0x0012, 0x0001, 0x0000, 0x0000, 0x0000, // +}; +#endif + +#if defined(HAS_HASHDJB2_AVX2) +// lo + (hi << 16), then add 8 dwords. +LIBYUV_TARGET_AVX2 +static uint32_t HashSum_AVX2(__m256i lo, __m256i hi) { + __m256i s = _mm256_add_epi32(lo, _mm256_slli_epi32(hi, 16)); + __m128i s128 = + _mm_add_epi32(_mm256_castsi256_si128(s), _mm256_extracti128_si256(s, 1)); + s128 = _mm_add_epi32(s128, _mm_shuffle_epi32(s128, 0x0e)); + s128 = _mm_add_epi32(s128, _mm_shuffle_epi32(s128, 0x01)); + return (uint32_t)_mm_cvtsi128_si32(s128); +} + +// Count is a multiple of 32. Process 64 bytes per loop with one horizontal +// add, then 32 bytes if needed. +LIBYUV_TARGET_AVX2 +uint32_t HashDjb2_AVX2(const uint8_t* src, int count, uint32_t seed) { + const __m256i* m = (const __m256i*)kHashMulLoHi; + while (count >= 64) { + __m256i w0 = _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)src)); + __m256i w1 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src + 16))); + __m256i w2 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src + 32))); + __m256i w3 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src + 48))); + __m256i lo = _mm256_add_epi32( + _mm256_add_epi32(_mm256_madd_epi16(w0, _mm256_loadu_si256(m + 0)), + _mm256_madd_epi16(w1, _mm256_loadu_si256(m + 1))), + _mm256_add_epi32(_mm256_madd_epi16(w2, _mm256_loadu_si256(m + 2)), + _mm256_madd_epi16(w3, _mm256_loadu_si256(m + 3)))); + __m256i hi = _mm256_add_epi32( + _mm256_add_epi32(_mm256_madd_epi16(w0, _mm256_loadu_si256(m + 4)), + _mm256_madd_epi16(w1, _mm256_loadu_si256(m + 5))), + _mm256_add_epi32(_mm256_madd_epi16(w2, _mm256_loadu_si256(m + 6)), + _mm256_madd_epi16(w3, _mm256_loadu_si256(m + 7)))); + seed = seed * 0xf07f8801u + HashSum_AVX2(lo, hi); // 33 ^ 64 + src += 64; + count -= 64; + } + if (count > 0) { + __m256i w0 = _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)src)); + __m256i w1 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src + 16))); + __m256i lo = + _mm256_add_epi32(_mm256_madd_epi16(w0, _mm256_loadu_si256(m + 2)), + _mm256_madd_epi16(w1, _mm256_loadu_si256(m + 3))); + __m256i hi = + _mm256_add_epi32(_mm256_madd_epi16(w0, _mm256_loadu_si256(m + 6)), + _mm256_madd_epi16(w1, _mm256_loadu_si256(m + 7))); + seed = seed * 0x1137c401u + HashSum_AVX2(lo, hi); // 33 ^ 32 + } + _mm256_zeroupper(); + return seed; +} +#endif // HAS_HASHDJB2_AVX2 + +#if defined(HAS_HASHDJB2_AVX512BW) +static uint32_t Pow33(int n) { + uint32_t r = 1u; + uint32_t b = 33u; + while (n) { + if (n & 1) { + r *= b; + } + b *= b; + n >>= 1; + } + return r; +} + +// Sum of 64 bytes, zero extended to words in w0 and w1, times 33 ^ (63 - i). +LIBYUV_TARGET_AVX512BW +static uint32_t HashSum64_AVX512BW(__m512i w0, __m512i w1) { + const __m512i* m = (const __m512i*)kHashMulLoHi; + __m512i lo = + _mm512_add_epi32(_mm512_madd_epi16(w0, _mm512_loadu_si512(m)), + _mm512_madd_epi16(w1, _mm512_loadu_si512(m + 1))); + __m512i hi = + _mm512_add_epi32(_mm512_madd_epi16(w0, _mm512_loadu_si512(m + 2)), + _mm512_madd_epi16(w1, _mm512_loadu_si512(m + 3))); + return (uint32_t)_mm512_reduce_add_epi32( + _mm512_add_epi32(lo, _mm512_slli_epi32(hi, 16))); +} + +// hash = hash * 33 ^ 64 + sum(src[i] * 33 ^ (63 - i)) for each 64 bytes. +// The remainder of n = 1 to 63 bytes is loaded into the high n bytes with a +// masked load ending at src + count, so the same multipliers apply, and +// hash is multiplied by 33 ^ n. +LIBYUV_TARGET_AVX512BW +uint32_t HashDjb2_AVX512BW(const uint8_t* src, int count, uint32_t seed) { + int n; + while (count >= 64) { + seed = seed * 0xf07f8801u + // 33 ^ 64 + HashSum64_AVX512BW( + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)src)), + _mm512_cvtepu8_epi16( + _mm256_loadu_si256((const __m256i*)(src + 32)))); + src += 64; + count -= 64; + } + n = count; + if (n) { + const __mmask64 k = (__mmask64)~LowBytesMask64(64 - n); + __m512i s = _mm512_maskz_loadu_epi8(k, src + n - 64); + seed = seed * Pow33(n) + + HashSum64_AVX512BW( + _mm512_cvtepu8_epi16(_mm512_castsi512_si256(s)), + _mm512_cvtepu8_epi16(_mm512_extracti64x4_epi64(s, 1))); + } + return seed; +} +#endif // HAS_HASHDJB2_AVX512BW + +#if defined(HAS_SSIM4X4ROW_SSE2) +// Width is a multiple of 16. +LIBYUV_TARGET_SSE2 +void Ssim4x4Row_SSE2(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + const ptrdiff_t sa = stride_a; + const ptrdiff_t sb = stride_b; + const uint8_t* a0 = src_a; + const uint8_t* a1 = a0 + sa; + const uint8_t* a2 = a1 + sa; + const uint8_t* a3 = a2 + sa; + const uint8_t* b0 = src_b; + const uint8_t* b1 = b0 + sb; + const uint8_t* b2 = b1 + sb; + const uint8_t* b3 = b2 + sb; + const __m128i kMaskFF = _mm_set1_epi16(0x00ff); + const __m128i kOnes16 = _mm_set1_epi16(1); + int x; + for (x = 0; x < width; x += 16) { + __m128i acc_a = _mm_setzero_si128(); + __m128i acc_b = _mm_setzero_si128(); + __m128i acc_sq = _mm_setzero_si128(); + __m128i acc_axb = _mm_setzero_si128(); +#define SSIM_ROW_SSE2_WIN(ar, br) \ + do { \ + __m128i va = _mm_loadu_si128((const __m128i*)((ar) + x)); \ + __m128i vb = _mm_loadu_si128((const __m128i*)((br) + x)); \ + __m128i a_ev = _mm_and_si128(va, kMaskFF); \ + __m128i a_od = _mm_srli_epi16(va, 8); \ + __m128i b_ev = _mm_and_si128(vb, kMaskFF); \ + __m128i b_od = _mm_srli_epi16(vb, 8); \ + acc_a = _mm_add_epi16(acc_a, _mm_add_epi16(a_ev, a_od)); \ + acc_b = _mm_add_epi16(acc_b, _mm_add_epi16(b_ev, b_od)); \ + acc_sq = _mm_add_epi32(acc_sq, _mm_add_epi32(_mm_madd_epi16(a_ev, a_ev), \ + _mm_madd_epi16(a_od, a_od))); \ + acc_sq = _mm_add_epi32(acc_sq, _mm_add_epi32(_mm_madd_epi16(b_ev, b_ev), \ + _mm_madd_epi16(b_od, b_od))); \ + acc_axb = \ + _mm_add_epi32(acc_axb, _mm_add_epi32(_mm_madd_epi16(a_ev, b_ev), \ + _mm_madd_epi16(a_od, b_od))); \ + } while (0) + SSIM_ROW_SSE2_WIN(a0, b0); + SSIM_ROW_SSE2_WIN(a1, b1); + SSIM_ROW_SSE2_WIN(a2, b2); + SSIM_ROW_SSE2_WIN(a3, b3); +#undef SSIM_ROW_SSE2_WIN + acc_a = _mm_madd_epi16(acc_a, kOnes16); + acc_b = _mm_madd_epi16(acc_b, kOnes16); + { + __m128i t0 = _mm_unpacklo_epi32(acc_a, acc_b); + __m128i t1 = _mm_unpackhi_epi32(acc_a, acc_b); + __m128i t2 = _mm_unpacklo_epi32(acc_sq, acc_axb); + __m128i t3 = _mm_unpackhi_epi32(acc_sq, acc_axb); + _mm_storeu_si128((__m128i*)(dst + 0), _mm_unpacklo_epi64(t0, t2)); + _mm_storeu_si128((__m128i*)(dst + 4), _mm_unpackhi_epi64(t0, t2)); + _mm_storeu_si128((__m128i*)(dst + 8), _mm_unpacklo_epi64(t1, t3)); + _mm_storeu_si128((__m128i*)(dst + 12), _mm_unpackhi_epi64(t1, t3)); + } + dst += 16; } } -#endif // _MSC_VER >= 1700 +#endif // HAS_SSIM4X4ROW_SSE2 -#endif // !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) +#if defined(HAS_SSIM4X4ROW_AVX2) +// Width is a multiple of 32. +LIBYUV_TARGET_AVX2 +void Ssim4x4Row_AVX2(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + const ptrdiff_t sa = stride_a; + const ptrdiff_t sb = stride_b; + const uint8_t* a0 = src_a; + const uint8_t* a1 = a0 + sa; + const uint8_t* a2 = a1 + sa; + const uint8_t* a3 = a2 + sa; + const uint8_t* b0 = src_b; + const uint8_t* b1 = b0 + sb; + const uint8_t* b2 = b1 + sb; + const uint8_t* b3 = b2 + sb; + const __m256i kMaskFF = _mm256_set1_epi16(0x00ff); + const __m256i kOnes16 = _mm256_set1_epi16(1); + int x; + for (x = 0; x < width; x += 32) { + __m256i acc_a = _mm256_setzero_si256(); + __m256i acc_b = _mm256_setzero_si256(); + __m256i acc_sq = _mm256_setzero_si256(); + __m256i acc_axb = _mm256_setzero_si256(); +#define SSIM_ROW_AVX2_WIN(ar, br) \ + do { \ + __m256i va = _mm256_loadu_si256((const __m256i*)((ar) + x)); \ + __m256i vb = _mm256_loadu_si256((const __m256i*)((br) + x)); \ + __m256i a_ev = _mm256_and_si256(va, kMaskFF); \ + __m256i a_od = _mm256_srli_epi16(va, 8); \ + __m256i b_ev = _mm256_and_si256(vb, kMaskFF); \ + __m256i b_od = _mm256_srli_epi16(vb, 8); \ + acc_a = _mm256_add_epi16(acc_a, _mm256_add_epi16(a_ev, a_od)); \ + acc_b = _mm256_add_epi16(acc_b, _mm256_add_epi16(b_ev, b_od)); \ + acc_sq = _mm256_add_epi32( \ + acc_sq, _mm256_add_epi32(_mm256_madd_epi16(a_ev, a_ev), \ + _mm256_madd_epi16(a_od, a_od))); \ + acc_sq = _mm256_add_epi32( \ + acc_sq, _mm256_add_epi32(_mm256_madd_epi16(b_ev, b_ev), \ + _mm256_madd_epi16(b_od, b_od))); \ + acc_axb = _mm256_add_epi32( \ + acc_axb, _mm256_add_epi32(_mm256_madd_epi16(a_ev, b_ev), \ + _mm256_madd_epi16(a_od, b_od))); \ + } while (0) + SSIM_ROW_AVX2_WIN(a0, b0); + SSIM_ROW_AVX2_WIN(a1, b1); + SSIM_ROW_AVX2_WIN(a2, b2); + SSIM_ROW_AVX2_WIN(a3, b3); +#undef SSIM_ROW_AVX2_WIN + acc_a = _mm256_madd_epi16(acc_a, kOnes16); + acc_b = _mm256_madd_epi16(acc_b, kOnes16); + { + __m256i t0 = _mm256_unpacklo_epi32(acc_a, acc_b); + __m256i t1 = _mm256_unpackhi_epi32(acc_a, acc_b); + __m256i t2 = _mm256_unpacklo_epi32(acc_sq, acc_axb); + __m256i t3 = _mm256_unpackhi_epi32(acc_sq, acc_axb); + __m256i u0 = _mm256_unpacklo_epi64(t0, t2); + __m256i u1 = _mm256_unpackhi_epi64(t0, t2); + __m256i u2 = _mm256_unpacklo_epi64(t1, t3); + __m256i u3 = _mm256_unpackhi_epi64(t1, t3); + _mm256_storeu_si256((__m256i*)(dst + 0), + _mm256_permute2x128_si256(u0, u1, 0x20)); + _mm256_storeu_si256((__m256i*)(dst + 8), + _mm256_permute2x128_si256(u2, u3, 0x20)); + _mm256_storeu_si256((__m256i*)(dst + 16), + _mm256_permute2x128_si256(u0, u1, 0x31)); + _mm256_storeu_si256((__m256i*)(dst + 24), + _mm256_permute2x128_si256(u2, u3, 0x31)); + } + dst += 32; + } + _mm256_zeroupper(); +} +#endif // HAS_SSIM4X4ROW_AVX2 + +#if defined(HAS_SSIM4X4ROW_AVX512BW) +// Width is a multiple of 4. +LIBYUV_TARGET_AVX512BW +void Ssim4x4Row_AVX512BW(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + const ptrdiff_t sa = stride_a; + const ptrdiff_t sb = stride_b; + const uint8_t* a0 = src_a; + const uint8_t* a1 = a0 + sa; + const uint8_t* a2 = a1 + sa; + const uint8_t* a3 = a2 + sa; + const uint8_t* b0 = src_b; + const uint8_t* b1 = b0 + sb; + const uint8_t* b2 = b1 + sb; + const uint8_t* b3 = b2 + sb; + const __m512i kMaskFF = _mm512_set1_epi16(0x00ff); + const __m512i kOnes16 = _mm512_set1_epi16(1); +#define SSIM_ROW_AVX512_WIN(va, vb) \ + do { \ + __m512i a_ev = _mm512_and_si512(va, kMaskFF); \ + __m512i a_od = _mm512_srli_epi16(va, 8); \ + __m512i b_ev = _mm512_and_si512(vb, kMaskFF); \ + __m512i b_od = _mm512_srli_epi16(vb, 8); \ + acc_a = _mm512_add_epi16(acc_a, _mm512_add_epi16(a_ev, a_od)); \ + acc_b = _mm512_add_epi16(acc_b, _mm512_add_epi16(b_ev, b_od)); \ + acc_sq = _mm512_add_epi32( \ + acc_sq, _mm512_add_epi32(_mm512_madd_epi16(a_ev, a_ev), \ + _mm512_madd_epi16(a_od, a_od))); \ + acc_sq = _mm512_add_epi32( \ + acc_sq, _mm512_add_epi32(_mm512_madd_epi16(b_ev, b_ev), \ + _mm512_madd_epi16(b_od, b_od))); \ + acc_axb = _mm512_add_epi32( \ + acc_axb, _mm512_add_epi32(_mm512_madd_epi16(a_ev, b_ev), \ + _mm512_madd_epi16(a_od, b_od))); \ + } while (0) +#define SSIM_TRANSPOSE_AVX512_WIN() \ + acc_a = _mm512_madd_epi16(acc_a, kOnes16); \ + acc_b = _mm512_madd_epi16(acc_b, kOnes16); \ + __m512i t0 = _mm512_unpacklo_epi32(acc_a, acc_b); \ + __m512i t1 = _mm512_unpackhi_epi32(acc_a, acc_b); \ + __m512i t2 = _mm512_unpacklo_epi32(acc_sq, acc_axb); \ + __m512i t3 = _mm512_unpackhi_epi32(acc_sq, acc_axb); \ + __m512i u0 = _mm512_unpacklo_epi64(t0, t2); \ + __m512i u1 = _mm512_unpackhi_epi64(t0, t2); \ + __m512i u2 = _mm512_unpacklo_epi64(t1, t3); \ + __m512i u3 = _mm512_unpackhi_epi64(t1, t3); \ + __m512i v0 = _mm512_shuffle_i32x4(u0, u1, 0x44); \ + __m512i v1 = _mm512_shuffle_i32x4(u2, u3, 0x44); \ + __m512i v2 = _mm512_shuffle_i32x4(u0, u1, 0xee); \ + __m512i v3 = _mm512_shuffle_i32x4(u2, u3, 0xee); \ + __m512i out0 = _mm512_shuffle_i32x4(v0, v1, 0x88); \ + __m512i out1 = _mm512_shuffle_i32x4(v0, v1, 0xdd); \ + __m512i out2 = _mm512_shuffle_i32x4(v2, v3, 0x88); \ + __m512i out3 = _mm512_shuffle_i32x4(v2, v3, 0xdd) + + while (width >= 64) { + __m512i acc_a = _mm512_setzero_si512(); + __m512i acc_b = _mm512_setzero_si512(); + __m512i acc_sq = _mm512_setzero_si512(); + __m512i acc_axb = _mm512_setzero_si512(); + SSIM_ROW_AVX512_WIN(_mm512_loadu_si512(a0), _mm512_loadu_si512(b0)); + SSIM_ROW_AVX512_WIN(_mm512_loadu_si512(a1), _mm512_loadu_si512(b1)); + SSIM_ROW_AVX512_WIN(_mm512_loadu_si512(a2), _mm512_loadu_si512(b2)); + SSIM_ROW_AVX512_WIN(_mm512_loadu_si512(a3), _mm512_loadu_si512(b3)); + SSIM_TRANSPOSE_AVX512_WIN(); + _mm512_storeu_si512(dst + 0, out0); + _mm512_storeu_si512(dst + 16, out1); + _mm512_storeu_si512(dst + 32, out2); + _mm512_storeu_si512(dst + 48, out3); + a0 += 64; + a1 += 64; + a2 += 64; + a3 += 64; + b0 += 64; + b1 += 64; + b2 += 64; + b3 += 64; + dst += 64; + width -= 64; + } + if (width > 0) { + const __mmask16 load_mask = (__mmask16)((1U << (width >> 2)) - 1U); + const uint64_t store_mask = LowBytesMask64(width); + __m512i acc_a = _mm512_setzero_si512(); + __m512i acc_b = _mm512_setzero_si512(); + __m512i acc_sq = _mm512_setzero_si512(); + __m512i acc_axb = _mm512_setzero_si512(); + SSIM_ROW_AVX512_WIN(_mm512_maskz_loadu_epi32(load_mask, a0), + _mm512_maskz_loadu_epi32(load_mask, b0)); + SSIM_ROW_AVX512_WIN(_mm512_maskz_loadu_epi32(load_mask, a1), + _mm512_maskz_loadu_epi32(load_mask, b1)); + SSIM_ROW_AVX512_WIN(_mm512_maskz_loadu_epi32(load_mask, a2), + _mm512_maskz_loadu_epi32(load_mask, b2)); + SSIM_ROW_AVX512_WIN(_mm512_maskz_loadu_epi32(load_mask, a3), + _mm512_maskz_loadu_epi32(load_mask, b3)); + SSIM_TRANSPOSE_AVX512_WIN(); + _mm512_mask_storeu_epi32(dst + 0, (__mmask16)store_mask, out0); + _mm512_mask_storeu_epi32(dst + 16, (__mmask16)(store_mask >> 16), out1); + _mm512_mask_storeu_epi32(dst + 32, (__mmask16)(store_mask >> 32), out2); + _mm512_mask_storeu_epi32(dst + 48, (__mmask16)(store_mask >> 48), out3); + } +#undef SSIM_ROW_AVX512_WIN +#undef SSIM_TRANSPOSE_AVX512_WIN +} +#endif // HAS_SSIM4X4ROW_AVX512BW + +#if defined(HAS_SSIMWINDOWROW_SSE2) +// num_windows is a multiple of 4. +LIBYUV_TARGET_SSE2 +float SsimWindowRow_SSE2(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + const __m128i vc1 = _mm_set1_epi32(26634); + const __m128i vc2 = _mm_set1_epi32(239708); + __m128 total = _mm_setzero_ps(); + __m128i t0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)row0), + _mm_loadu_si128((const __m128i*)row1)); + int w; + for (w = 0; w < num_windows; w += 4) { + __m128i t1 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(row0 + 4)), + _mm_loadu_si128((const __m128i*)(row1 + 4))); + __m128i t2 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(row0 + 8)), + _mm_loadu_si128((const __m128i*)(row1 + 8))); + __m128i t3 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(row0 + 12)), + _mm_loadu_si128((const __m128i*)(row1 + 12))); + __m128i t4 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(row0 + 16)), + _mm_loadu_si128((const __m128i*)(row1 + 16))); + row0 += 16; + row1 += 16; + __m128i w0 = _mm_add_epi32(t0, t1); + __m128i w1 = _mm_add_epi32(t1, t2); + __m128i w2 = _mm_add_epi32(t2, t3); + __m128i w3 = _mm_add_epi32(t3, t4); + t0 = t4; + + __m128i u0 = _mm_unpacklo_epi32(w0, w1); + __m128i u1 = _mm_unpackhi_epi32(w0, w1); + __m128i u2 = _mm_unpacklo_epi32(w2, w3); + __m128i u3 = _mm_unpackhi_epi32(w2, w3); + __m128i sum_a = _mm_unpacklo_epi64(u0, u2); + __m128i sum_b = _mm_unpackhi_epi64(u0, u2); + __m128i sum_sq = _mm_unpacklo_epi64(u1, u3); + __m128i sum_axb = _mm_unpackhi_epi64(u1, u3); + + __m128i ab2 = _mm_slli_epi32(_mm_madd_epi16(sum_a, sum_b), 1); + __m128i a2b2 = _mm_add_epi32(_mm_madd_epi16(sum_a, sum_a), + _mm_madd_epi16(sum_b, sum_b)); + __m128i n1 = _mm_add_epi32(ab2, vc1); + __m128i n2 = + _mm_add_epi32(_mm_sub_epi32(_mm_slli_epi32(sum_axb, 7), ab2), vc2); + __m128i d1 = _mm_add_epi32(a2b2, vc1); + __m128i d2 = + _mm_add_epi32(_mm_sub_epi32(_mm_slli_epi32(sum_sq, 6), a2b2), vc2); + + __m128 num = _mm_mul_ps(_mm_cvtepi32_ps(n1), _mm_cvtepi32_ps(n2)); + __m128 den = _mm_mul_ps(_mm_cvtepi32_ps(d1), _mm_cvtepi32_ps(d2)); + total = _mm_add_ps(total, _mm_div_ps(num, den)); + } + total = _mm_add_ps(total, _mm_movehl_ps(total, total)); + total = _mm_add_ss(total, _mm_shuffle_ps(total, total, 1)); + return _mm_cvtss_f32(total); +} +#endif // HAS_SSIMWINDOWROW_SSE2 + +#if defined(HAS_SSIMWINDOWROW_AVX2) +// num_windows is a multiple of 8. +LIBYUV_TARGET_AVX2 +float SsimWindowRow_AVX2(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + const __m256i vc1 = _mm256_set1_epi32(26634); + const __m256i vc2 = _mm256_set1_epi32(239708); + __m256 total = _mm256_setzero_ps(); + __m128 total128; + int w; + for (w = 0; w < num_windows; w += 8) { + __m256i e01 = + _mm256_add_epi32(_mm256_loadu_si256((const __m256i*)(row0 + 0)), + _mm256_loadu_si256((const __m256i*)(row1 + 0))); + __m256i o12 = + _mm256_add_epi32(_mm256_loadu_si256((const __m256i*)(row0 + 4)), + _mm256_loadu_si256((const __m256i*)(row1 + 4))); + __m256i e23 = + _mm256_add_epi32(_mm256_loadu_si256((const __m256i*)(row0 + 8)), + _mm256_loadu_si256((const __m256i*)(row1 + 8))); + __m256i o34 = + _mm256_add_epi32(_mm256_loadu_si256((const __m256i*)(row0 + 12)), + _mm256_loadu_si256((const __m256i*)(row1 + 12))); + __m256i e45 = + _mm256_add_epi32(_mm256_loadu_si256((const __m256i*)(row0 + 16)), + _mm256_loadu_si256((const __m256i*)(row1 + 16))); + __m256i o56 = + _mm256_add_epi32(_mm256_loadu_si256((const __m256i*)(row0 + 20)), + _mm256_loadu_si256((const __m256i*)(row1 + 20))); + __m256i e67 = + _mm256_add_epi32(_mm256_loadu_si256((const __m256i*)(row0 + 24)), + _mm256_loadu_si256((const __m256i*)(row1 + 24))); + __m256i o78 = + _mm256_add_epi32(_mm256_loadu_si256((const __m256i*)(row0 + 28)), + _mm256_loadu_si256((const __m256i*)(row1 + 28))); + row0 += 32; + row1 += 32; + __m256i w0 = _mm256_add_epi32(e01, o12); + __m256i w1 = _mm256_add_epi32(e23, o34); + __m256i w2 = _mm256_add_epi32(e45, o56); + __m256i w3 = _mm256_add_epi32(e67, o78); + + __m256i u0 = _mm256_unpacklo_epi32(w0, w1); + __m256i u1 = _mm256_unpackhi_epi32(w0, w1); + __m256i u2 = _mm256_unpacklo_epi32(w2, w3); + __m256i u3 = _mm256_unpackhi_epi32(w2, w3); + __m256i sum_a = _mm256_unpacklo_epi64(u0, u2); + __m256i sum_b = _mm256_unpackhi_epi64(u0, u2); + __m256i sum_sq = _mm256_unpacklo_epi64(u1, u3); + __m256i sum_axb = _mm256_unpackhi_epi64(u1, u3); + + __m256i ab2 = _mm256_slli_epi32(_mm256_madd_epi16(sum_a, sum_b), 1); + __m256i a2b2 = _mm256_add_epi32(_mm256_madd_epi16(sum_a, sum_a), + _mm256_madd_epi16(sum_b, sum_b)); + __m256i n1 = _mm256_add_epi32(ab2, vc1); + __m256i n2 = _mm256_add_epi32( + _mm256_sub_epi32(_mm256_slli_epi32(sum_axb, 7), ab2), vc2); + __m256i d1 = _mm256_add_epi32(a2b2, vc1); + __m256i d2 = _mm256_add_epi32( + _mm256_sub_epi32(_mm256_slli_epi32(sum_sq, 6), a2b2), vc2); + + __m256 num = _mm256_mul_ps(_mm256_cvtepi32_ps(n1), _mm256_cvtepi32_ps(n2)); + __m256 den = _mm256_mul_ps(_mm256_cvtepi32_ps(d1), _mm256_cvtepi32_ps(d2)); + total = _mm256_add_ps(total, _mm256_div_ps(num, den)); + } + total128 = _mm_add_ps(_mm256_castps256_ps128(total), + _mm256_extractf128_ps(total, 1)); + total128 = _mm_add_ps(total128, _mm_movehl_ps(total128, total128)); + total128 = _mm_add_ss(total128, _mm_shuffle_ps(total128, total128, 1)); + _mm256_zeroupper(); + return _mm_cvtss_f32(total128); +} +#endif // HAS_SSIMWINDOWROW_AVX2 + +#if defined(HAS_SSIMWINDOWROW_AVX512BW) +LIBYUV_TARGET_AVX512BW +float SsimWindowRow_AVX512BW(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + const __m512i vc1 = _mm512_set1_epi32(26634); + const __m512i vc2 = _mm512_set1_epi32(239708); + __m512 total = _mm512_setzero_ps(); +#define SSIM_WINDOW_AVX512_WIN(w0, w1, w2, w3) \ + __m512i u0 = _mm512_unpacklo_epi32(w0, w1); \ + __m512i u1 = _mm512_unpackhi_epi32(w0, w1); \ + __m512i u2 = _mm512_unpacklo_epi32(w2, w3); \ + __m512i u3 = _mm512_unpackhi_epi32(w2, w3); \ + __m512i sum_a = _mm512_unpacklo_epi64(u0, u2); \ + __m512i sum_b = _mm512_unpackhi_epi64(u0, u2); \ + __m512i sum_sq = _mm512_unpacklo_epi64(u1, u3); \ + __m512i sum_axb = _mm512_unpackhi_epi64(u1, u3); \ + __m512i ab2 = _mm512_slli_epi32(_mm512_madd_epi16(sum_a, sum_b), 1); \ + __m512i a2b2 = _mm512_add_epi32(_mm512_madd_epi16(sum_a, sum_a), \ + _mm512_madd_epi16(sum_b, sum_b)); \ + __m512i n1 = _mm512_add_epi32(ab2, vc1); \ + __m512i n2 = _mm512_add_epi32( \ + _mm512_sub_epi32(_mm512_slli_epi32(sum_axb, 7), ab2), vc2); \ + __m512i d1 = _mm512_add_epi32(a2b2, vc1); \ + __m512i d2 = _mm512_add_epi32( \ + _mm512_sub_epi32(_mm512_slli_epi32(sum_sq, 6), a2b2), vc2); \ + __m512 num = _mm512_mul_ps(_mm512_cvtepi32_ps(n1), _mm512_cvtepi32_ps(n2)); \ + __m512 den = _mm512_mul_ps(_mm512_cvtepi32_ps(d1), _mm512_cvtepi32_ps(d2)); \ + __m512 ssim = _mm512_div_ps(num, den) + + while (num_windows >= 16) { + __m512i t0 = _mm512_add_epi32(_mm512_loadu_si512(row0 + 0), + _mm512_loadu_si512(row1 + 0)); + __m512i t1 = _mm512_add_epi32(_mm512_loadu_si512(row0 + 16), + _mm512_loadu_si512(row1 + 16)); + __m512i t2 = _mm512_add_epi32(_mm512_loadu_si512(row0 + 32), + _mm512_loadu_si512(row1 + 32)); + __m512i t3 = _mm512_add_epi32(_mm512_loadu_si512(row0 + 48), + _mm512_loadu_si512(row1 + 48)); + __m512i t4 = _mm512_add_epi32(_mm512_loadu_si512(row0 + 52), + _mm512_loadu_si512(row1 + 52)); + row0 += 64; + row1 += 64; + num_windows -= 16; + __m512i w0 = _mm512_add_epi32(t0, _mm512_alignr_epi32(t1, t0, 4)); + __m512i w1 = _mm512_add_epi32(t1, _mm512_alignr_epi32(t2, t1, 4)); + __m512i w2 = _mm512_add_epi32(t2, _mm512_alignr_epi32(t3, t2, 4)); + __m512i w3 = _mm512_add_epi32(t3, t4); + SSIM_WINDOW_AVX512_WIN(w0, w1, w2, w3); + total = _mm512_add_ps(total, ssim); + } + if (num_windows > 0) { + const uint64_t load_mask = ~0ULL >> (60 - num_windows * 4); + const __mmask16 win_mask = + (__mmask16)(((0x01110U >> (16 - (num_windows & 3) * 4)) + << (num_windows >> 2)) + + (0x1111U << (num_windows >> 2)) - 0x1111U); + const __mmask16 m0 = (__mmask16)load_mask; + const __mmask16 m1 = (__mmask16)(load_mask >> 16); + const __mmask16 m2 = (__mmask16)(load_mask >> 32); + const __mmask16 m3 = (__mmask16)(load_mask >> 48); + __m512i t0 = _mm512_add_epi32(_mm512_maskz_loadu_epi32(m0, row0 + 0), + _mm512_maskz_loadu_epi32(m0, row1 + 0)); + __m512i t1 = _mm512_add_epi32(_mm512_maskz_loadu_epi32(m1, row0 + 16), + _mm512_maskz_loadu_epi32(m1, row1 + 16)); + __m512i t2 = _mm512_add_epi32(_mm512_maskz_loadu_epi32(m2, row0 + 32), + _mm512_maskz_loadu_epi32(m2, row1 + 32)); + __m512i t3 = _mm512_add_epi32(_mm512_maskz_loadu_epi32(m3, row0 + 48), + _mm512_maskz_loadu_epi32(m3, row1 + 48)); + __m512i w0 = _mm512_add_epi32(t0, _mm512_alignr_epi32(t1, t0, 4)); + __m512i w1 = _mm512_add_epi32(t1, _mm512_alignr_epi32(t2, t1, 4)); + __m512i w2 = _mm512_add_epi32(t2, _mm512_alignr_epi32(t3, t2, 4)); + __m512i w3 = _mm512_add_epi32(t3, _mm512_alignr_epi32(t3, t3, 4)); + SSIM_WINDOW_AVX512_WIN(w0, w1, w2, w3); + total = _mm512_mask_add_ps(total, win_mask, total, ssim); + } +#undef SSIM_WINDOW_AVX512_WIN + return _mm512_reduce_add_ps(total); +} +#endif // HAS_SSIMWINDOWROW_AVX512BW + +#if defined(HAS_ARGBDETECTROW_AVX2) +LIBYUV_TARGET_AVX2 +uint32_t ARGBDetectRow_AVX2(const uint8_t* argb, int width) { + if (width >= 8) { + const __m256i mask_rgb = _mm256_set1_epi32(0x00ffff00); + const __m256i ones = _mm256_set1_epi8(-1); + do { + __m256i v = + _mm256_or_si256(_mm256_loadu_si256((const __m256i*)argb), mask_rgb); + uint32_t diff = + ~(uint32_t)_mm256_movemask_epi8(_mm256_cmpeq_epi8(v, ones)); + if (diff) { +#if defined(_MSC_VER) && !defined(__clang__) + unsigned long bit; // NOLINT(runtime/int) + _BitScanForward(&bit, diff); +#else + int bit = __builtin_ctz(diff); +#endif + _mm256_zeroupper(); + return (bit & 3) == 0 ? FOURCC_BGRA : FOURCC_ARGB; + } + argb += 32; + width -= 8; + } while (width >= 8); + _mm256_zeroupper(); + } + if (width > 0) { + const __m128i mask_rgb = _mm_set1_epi32(0x00ffff00); + const __m128i ones = _mm_set1_epi8(-1); + do { + __m128i v = _mm_or_si128(_mm_loadu_si32(argb), mask_rgb); + uint32_t diff = + (~(uint32_t)_mm_movemask_epi8(_mm_cmpeq_epi8(v, ones))) & 0x9u; + if (diff) { + return (diff & 1u) ? FOURCC_BGRA : FOURCC_ARGB; + } + argb += 4; + width -= 1; + } while (width > 0); + } + return 0; +} +#endif // HAS_ARGBDETECTROW_AVX2 #ifdef __cplusplus } // extern "C" } // namespace libyuv #endif + +#endif // !defined(LIBYUV_DISABLE_X86) && (x86 or x64) && + // (Visual C or LIBYUV_ENABLE_ROWWIN) diff --git a/libs/libyuv/source/convert.cc b/libs/libyuv/source/convert.cc index 614fa48241..e76ba7c341 100644 --- a/libs/libyuv/source/convert.cc +++ b/libs/libyuv/source/convert.cc @@ -10,24 +10,35 @@ #include "libyuv/convert.h" -#include "libyuv/basic_types.h" +#include + +#include "libyuv/convert_from_argb.h" #include "libyuv/cpu_id.h" #include "libyuv/planar_functions.h" #include "libyuv/rotate.h" #include "libyuv/row.h" -#include "libyuv/scale.h" // For ScalePlane() +#include "libyuv/scale.h" // For ScalePlane() +#include "libyuv/scale_row.h" // For FixedDiv +#include "libyuv/scale_uv.h" // For UVScale() #ifdef __cplusplus namespace libyuv { + +extern const struct ArgbConstants kArgbI601Constants; +extern const struct ArgbConstants kArgbJPEGConstants; extern "C" { #endif +// Subsample amount uses a shift. +// v is value +// a is amount to add to round up +// s is shift to subsample down #define SUBSAMPLE(v, a, s) (v < 0) ? (-((-v + a) >> s)) : ((v + a) >> s) static __inline int Abs(int v) { return v >= 0 ? v : -v; } -// Any I4xx To I420 format with mirroring. +// Any I4xx To I420 format static int I4xxToI420(const uint8_t* src_y, int src_stride_y, const uint8_t* src_u, @@ -44,27 +55,31 @@ static int I4xxToI420(const uint8_t* src_y, int src_y_height, int src_uv_width, int src_uv_height) { - const int dst_y_width = Abs(src_y_width); + int r; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || + src_y_width <= 0 || src_y_height == 0 || src_y_height == INT_MIN || + src_uv_width <= 0 || src_uv_height == 0) { + return -1; + } + const int dst_y_width = src_y_width; const int dst_y_height = Abs(src_y_height); const int dst_uv_width = SUBSAMPLE(dst_y_width, 1, 1); const int dst_uv_height = SUBSAMPLE(dst_y_height, 1, 1); - if (src_uv_width == 0 || src_uv_height == 0) { - return -1; - } if (dst_y) { - ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, dst_y, - dst_stride_y, dst_y_width, dst_y_height, kFilterBilinear); + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, src_y_width, + src_y_height); } - ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u, - dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear); - ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v, - dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear); - return 0; + r = ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u, + dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear); + if (r != 0) { + return r; + } + r = ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v, + dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear); + return r; } -// Copy I420 with optional flipping. -// TODO(fbarchard): Use Scale plane which supports mirroring, but ensure -// is does row coalescing. +// Copy I420 with optional vertical flipping using negative height. LIBYUV_API int I420Copy(const uint8_t* src_y, int src_stride_y, @@ -82,16 +97,17 @@ int I420Copy(const uint8_t* src_y, int height) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_u || !src_v || !dst_u || !dst_v || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -124,16 +140,17 @@ int I010Copy(const uint16_t* src_y, int height) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_u || !src_v || !dst_u || !dst_v || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -148,6 +165,389 @@ int I010Copy(const uint16_t* src_y, return 0; } +static int Planar16bitTo8bit(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + int subsample_x, + int subsample_y, + int depth) { + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); + int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); + int scale = 1 << (24 - depth); + // Negative height means invert the image. + if (height < 0) { + height = -height; + uv_height = -uv_height; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(uv_height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(uv_height - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + + // Convert Y plane. + if (dst_y) { + Convert16To8Plane(src_y, src_stride_y, dst_y, dst_stride_y, scale, width, + height); + } + // Convert UV planes. + Convert16To8Plane(src_u, src_stride_u, dst_u, dst_stride_u, scale, uv_width, + uv_height); + Convert16To8Plane(src_v, src_stride_v, dst_v, dst_stride_v, scale, uv_width, + uv_height); + return 0; +} + +static int I41xToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + int depth) { + int y; + const int scale = 1 << (24 - depth); + const int uv_width = SUBSAMPLE(width, 1, 1); + void (*Convert16To8Row)(const uint16_t* src_y, uint8_t* dst_y, int scale, + int width) = Convert16To8Row_C; + void (*HalfWidthRow_16To8)(const uint16_t* src_uv, ptrdiff_t src_uv_stride, + uint8_t* dst_uv, int scale, int width) = + (width & 1) ? HalfWidthRow_16To8_Odd_C : HalfWidthRow_16To8_C; + + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + if (src_y) { + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_stride_y = -src_stride_y; + } + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + +#if defined(HAS_CONVERT16TO8ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Convert16To8Row = Convert16To8Row_Any_NEON; + if (IS_ALIGNED(width, 16)) { + Convert16To8Row = Convert16To8Row_NEON; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + Convert16To8Row = Convert16To8Row_SVE2; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Convert16To8Row = Convert16To8Row_SME; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Convert16To8Row = Convert16To8Row_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + Convert16To8Row = Convert16To8Row_SSSE3; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Convert16To8Row = Convert16To8Row_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + Convert16To8Row = Convert16To8Row_AVX2; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Convert16To8Row = Convert16To8Row_AVX512BW; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Convert16To8Row = Convert16To8Row_RVV; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Convert16To8Row = Convert16To8Row_HVX; + } +#endif + + if (IS_ALIGNED(width, 2)) { +#if defined(HAS_HALFWIDTHROW_16TO8_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + HalfWidthRow_16To8 = HalfWidthRow_16To8_Any_NEON; + if (IS_ALIGNED(uv_width, 8)) { + HalfWidthRow_16To8 = HalfWidthRow_16To8_NEON; + } + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + HalfWidthRow_16To8 = HalfWidthRow_16To8_SVE2; + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_SME) + if (TestCpuFlag(kCpuHasSME)) { + HalfWidthRow_16To8 = HalfWidthRow_16To8_SME; + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + HalfWidthRow_16To8 = HalfWidthRow_16To8_Any_SSSE3; + if (IS_ALIGNED(uv_width, 8)) { + HalfWidthRow_16To8 = HalfWidthRow_16To8_SSSE3; + } + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + HalfWidthRow_16To8 = HalfWidthRow_16To8_Any_AVX2; + if (IS_ALIGNED(uv_width, 16)) { + HalfWidthRow_16To8 = HalfWidthRow_16To8_AVX2; + } + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + HalfWidthRow_16To8 = HalfWidthRow_16To8_AVX512BW; + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + HalfWidthRow_16To8 = HalfWidthRow_16To8_RVV; + } +#endif + } else { +#if defined(HAS_HALFWIDTHROW_16TO8_ODD_AVX2) || \ + defined(HAS_HALFWIDTHROW_16TO8_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + HalfWidthRow_16To8 = HalfWidthRow_16To8_Odd_AVX2; + } +#endif + } + + for (y = 0; y < height - 1; y += 2) { + HalfWidthRow_16To8(src_u, src_stride_u, dst_u, scale, uv_width); + HalfWidthRow_16To8(src_v, src_stride_v, dst_v, scale, uv_width); + if (dst_y) { + Convert16To8Row(src_y, dst_y, scale, width); + Convert16To8Row(src_y + src_stride_y, dst_y + dst_stride_y, scale, width); + src_y += src_stride_y * 2; + dst_y += dst_stride_y * 2; + } + src_u += src_stride_u * 2; + src_v += src_stride_v * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; + } + if (height & 1) { + HalfWidthRow_16To8(src_u, 0, dst_u, scale, uv_width); + HalfWidthRow_16To8(src_v, 0, dst_v, scale, uv_width); + if (dst_y) { + Convert16To8Row(src_y, dst_y, scale, width); + } + } + return 0; +} + +static int I21xToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + int depth) { + int y; + const int scale = 1 << (24 - depth); + const int uv_width = SUBSAMPLE(width, 1, 1); + void (*Convert16To8Row)(const uint16_t* src_y, uint8_t* dst_y, int scale, + int width) = Convert16To8Row_C; + void (*HalfRow_16To8)(const uint16_t* src_uv, ptrdiff_t src_uv_stride, + uint8_t* dst_uv, int scale, int width) = + HalfRow_16To8_C; + + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + if (src_y) { + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_stride_y = -src_stride_y; + } + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + +#if defined(HAS_CONVERT16TO8ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Convert16To8Row = Convert16To8Row_Any_NEON; + if (IS_ALIGNED(width, 16)) { + Convert16To8Row = Convert16To8Row_NEON; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + Convert16To8Row = Convert16To8Row_SVE2; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Convert16To8Row = Convert16To8Row_SME; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Convert16To8Row = Convert16To8Row_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + Convert16To8Row = Convert16To8Row_SSSE3; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Convert16To8Row = Convert16To8Row_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + Convert16To8Row = Convert16To8Row_AVX2; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Convert16To8Row = Convert16To8Row_AVX512BW; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Convert16To8Row = Convert16To8Row_RVV; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Convert16To8Row = Convert16To8Row_HVX; + } +#endif + +#if defined(HAS_HALFROW_16TO8_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + HalfRow_16To8 = HalfRow_16To8_Any_NEON; + if (IS_ALIGNED(uv_width, 16)) { + HalfRow_16To8 = HalfRow_16To8_NEON; + } + } +#endif +#if defined(HAS_HALFROW_16TO8_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + HalfRow_16To8 = HalfRow_16To8_SVE2; + } +#endif +#if defined(HAS_HALFROW_16TO8_SME) + if (TestCpuFlag(kCpuHasSME)) { + HalfRow_16To8 = HalfRow_16To8_SME; + } +#endif +#if defined(HAS_HALFROW_16TO8_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + HalfRow_16To8 = HalfRow_16To8_Any_SSSE3; + if (IS_ALIGNED(uv_width, 16)) { + HalfRow_16To8 = HalfRow_16To8_SSSE3; + } + } +#endif +#if defined(HAS_HALFROW_16TO8_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + HalfRow_16To8 = HalfRow_16To8_Any_AVX2; + if (IS_ALIGNED(uv_width, 32)) { + HalfRow_16To8 = HalfRow_16To8_AVX2; + } + } +#endif +#if defined(HAS_HALFROW_16TO8_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + HalfRow_16To8 = HalfRow_16To8_AVX512BW; + } +#endif +#if defined(HAS_HALFROW_16TO8_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + HalfRow_16To8 = HalfRow_16To8_RVV; + } +#endif +#if defined(HAS_HALFROW_16TO8_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + HalfRow_16To8 = HalfRow_16To8_HVX; + } +#endif + + for (y = 0; y < height - 1; y += 2) { + HalfRow_16To8(src_u, src_stride_u, dst_u, scale, uv_width); + HalfRow_16To8(src_v, src_stride_v, dst_v, scale, uv_width); + if (dst_y) { + Convert16To8Row(src_y, dst_y, scale, width); + Convert16To8Row(src_y + src_stride_y, dst_y + dst_stride_y, scale, width); + src_y += src_stride_y * 2; + dst_y += dst_stride_y * 2; + } + src_u += src_stride_u * 2; + src_v += src_stride_v * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; + } + if (height & 1) { + HalfRow_16To8(src_u, 0, dst_u, scale, uv_width); + HalfRow_16To8(src_v, 0, dst_v, scale, uv_width); + if (dst_y) { + Convert16To8Row(src_y, dst_y, scale, width); + } + } + return 0; +} + // Convert 10 bit YUV to 8 bit. LIBYUV_API int I010ToI420(const uint16_t* src_y, @@ -164,34 +564,591 @@ int I010ToI420(const uint16_t* src_y, int dst_stride_v, int width, int height) { + return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, width, height, 1, + 1, 10); +} + +LIBYUV_API +int I210ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return I21xToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, + dst_v, dst_stride_v, width, height, 10); +} + +LIBYUV_API +int I210ToI422(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, width, height, 1, + 0, 10); +} + +LIBYUV_API +int I410ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return I41xToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, + dst_v, dst_stride_v, width, height, 10); +} + +LIBYUV_API +int I410ToI444(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, width, height, 0, + 0, 10); +} + +LIBYUV_API +int I012ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, width, height, 1, + 1, 12); +} + +LIBYUV_API +int I212ToI422(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, width, height, 1, + 0, 12); +} + +LIBYUV_API +int I212ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return I21xToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, + dst_v, dst_stride_v, width, height, 12); +} + +LIBYUV_API +int I412ToI444(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return Planar16bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, width, height, 0, + 0, 12); +} + +LIBYUV_API +int I412ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return I41xToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, + dst_v, dst_stride_v, width, height, 12); +} + +// Any Ix10 To I010 format +static int Ix10ToI010(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height, + int subsample_x, + int subsample_y) { + int r; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + const int dst_y_width = width; + const int dst_y_height = Abs(height); + const int src_uv_width = SUBSAMPLE(width, subsample_x, subsample_x); + const int src_uv_height = SUBSAMPLE(height, subsample_y, subsample_y); + const int dst_uv_width = SUBSAMPLE(dst_y_width, 1, 1); + const int dst_uv_height = SUBSAMPLE(dst_y_height, 1, 1); + if (dst_y) { + CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + r = ScalePlane_12(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u, + dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear); + if (r != 0) { + return r; + } + r = ScalePlane_12(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v, + dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear); + return r; +} + +LIBYUV_API +int I410ToI010(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + return Ix10ToI010(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, + dst_v, dst_stride_v, width, height, 0, 0); +} + +LIBYUV_API +int I210ToI010(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + return Ix10ToI010(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, + dst_v, dst_stride_v, width, height, 1, 0); +} + +// Any I[420]1[02] to P[420]1[02] format +static int IxxxToPxxx(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height, + int subsample_x, + int subsample_y, + int depth) { + if (width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } + const int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); + const int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); + + ConvertToMSBPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height, + depth); + MergeUVPlane_16(src_u, src_stride_u, src_v, src_stride_v, dst_uv, + dst_stride_uv, uv_width, uv_height, depth); + return 0; +} + +LIBYUV_API +int I010ToP010(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return IxxxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height, 1, 1, 10); +} + +LIBYUV_API +int I010ToNV12(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + int y; int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_u || !src_v || !dst_u || !dst_v || width <= 0 || height == 0) { + const int scale = 16385; // 16384 for 10 bits + void (*Convert16To8Row)(const uint16_t* src_y, uint8_t* dst_y, int scale, + int width) = Convert16To8Row_C; + void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, + uint8_t* dst_uv, int width) = MergeUVRow_C; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_uv || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; } +#if defined(HAS_CONVERT16TO8ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Convert16To8Row = Convert16To8Row_Any_NEON; + if (IS_ALIGNED(halfwidth, 16)) { + Convert16To8Row = Convert16To8Row_NEON; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Convert16To8Row = Convert16To8Row_SME; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Convert16To8Row = Convert16To8Row_Any_SSSE3; + if (IS_ALIGNED(halfwidth, 16)) { + Convert16To8Row = Convert16To8Row_SSSE3; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Convert16To8Row = Convert16To8Row_Any_AVX2; + if (IS_ALIGNED(halfwidth, 32)) { + Convert16To8Row = Convert16To8Row_AVX2; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Convert16To8Row = Convert16To8Row_AVX512BW; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Convert16To8Row = Convert16To8Row_HVX; + } +#endif + +#if defined(HAS_MERGEUVROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + MergeUVRow = MergeUVRow_Any_SSE2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_SSE2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeUVRow = MergeUVRow_Any_AVX2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_AVX2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow = MergeUVRow_AVX512BW; + } +#endif +#if defined(HAS_MERGEUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeUVRow = MergeUVRow_Any_NEON; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_NEON; + } + } +#endif +#if defined(HAS_MERGEUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + MergeUVRow = MergeUVRow_SVE2; + } +#endif +#if defined(HAS_MERGEUVROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow = MergeUVRow_SME; + } +#endif +#if defined(HAS_MERGEUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MergeUVRow = MergeUVRow_Any_LSX; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_LSX; + } + } +#endif +#if defined(HAS_MERGEUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MergeUVRow = MergeUVRow_Any_LASX; + if (IS_ALIGNED(halfwidth, 32)) { + MergeUVRow = MergeUVRow_LASX; + } + } +#endif +#if defined(HAS_MERGEUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeUVRow = MergeUVRow_RVV; + } +#endif +#if defined(HAS_MERGEUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MergeUVRow = MergeUVRow_Any_WASMSIMD; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_WASMSIMD; + } + } +#endif +#if defined(HAS_MERGEUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow = MergeUVRow_HVX; + } +#endif // Convert Y plane. - Convert16To8Plane(src_y, src_stride_y, dst_y, dst_stride_y, 16384, width, - height); - // Convert UV planes. - Convert16To8Plane(src_u, src_stride_u, dst_u, dst_stride_u, 16384, halfwidth, - halfheight); - Convert16To8Plane(src_v, src_stride_v, dst_v, dst_stride_v, 16384, halfwidth, - halfheight); + if (dst_y) { + Convert16To8Plane(src_y, src_stride_y, dst_y, dst_stride_y, scale, width, + height); + } + + { + // Allocate a row of uv. + align_buffer_64(row_u, ((halfwidth + 31) & ~31) * 2); + uint8_t* row_v = row_u + ((halfwidth + 31) & ~31); + if (!row_u) + return 1; + + for (y = 0; y < halfheight; ++y) { + Convert16To8Row(src_u, row_u, scale, halfwidth); + Convert16To8Row(src_v, row_v, scale, halfwidth); + MergeUVRow(row_u, row_v, dst_uv, halfwidth); + src_u += src_stride_u; + src_v += src_stride_v; + dst_uv += dst_stride_uv; + } + free_aligned_buffer_64(row_u); + } return 0; } +LIBYUV_API +int I210ToP210(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return IxxxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height, 1, 0, 10); +} + +LIBYUV_API +int I410ToP410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return IxxxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height, 0, 0, 10); +} + +LIBYUV_API +int I012ToP012(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return IxxxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height, 1, 1, 12); +} + +LIBYUV_API +int I212ToP212(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return IxxxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height, 1, 0, 12); +} + +LIBYUV_API +int I412ToP412(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return IxxxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height, 0, 0, 12); +} + // 422 chroma is 1/2 width, 1x height // 420 chroma is 1/2 width, 1/2 height LIBYUV_API @@ -215,6 +1172,48 @@ int I422ToI420(const uint8_t* src_y, dst_v, dst_stride_v, width, height, src_uv_width, height); } +LIBYUV_API +int I422ToI210(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + int halfwidth = (width + 1) >> 1; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + + // Convert Y plane. + Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 1024, width, + height); + // Convert UV planes. + Convert8To16Plane(src_u, src_stride_u, dst_u, dst_stride_u, 1024, halfwidth, + height); + Convert8To16Plane(src_v, src_stride_v, dst_v, dst_stride_v, 1024, halfwidth, + height); + return 0; +} + // TODO(fbarchard): Implement row conversion. LIBYUV_API int I422ToNV21(const uint8_t* src_y, @@ -229,33 +1228,211 @@ int I422ToNV21(const uint8_t* src_y, int dst_stride_vu, int width, int height) { + int r; + if (width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; } // Allocate u and v buffers - align_buffer_64(plane_u, halfwidth * halfheight * 2); - uint8_t* plane_v = plane_u + halfwidth * halfheight; + const uint64_t plane_size = (uint64_t)halfwidth * halfheight; + if (plane_size > SIZE_MAX / 2) + return 1; + align_buffer_64(plane_u, (size_t)plane_size * 2); + if (!plane_u) + return 1; + uint8_t* plane_v = plane_u + (size_t)plane_size; - I422ToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, - dst_y, dst_stride_y, plane_u, halfwidth, plane_v, halfwidth, width, - height); + r = I422ToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, + dst_y, dst_stride_y, plane_u, halfwidth, plane_v, halfwidth, + width, height); + if (r != 0) { + free_aligned_buffer_64(plane_u); + return r; + } MergeUVPlane(plane_v, halfwidth, plane_u, halfwidth, dst_vu, dst_stride_vu, halfwidth, halfheight); free_aligned_buffer_64(plane_u); return 0; } +LIBYUV_API +int MM21ToNV12(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + if (!src_uv || !dst_uv || width <= 0) { + return -1; + } + + int sign = height < 0 ? -1 : 1; + + if (dst_y) { + DetilePlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height, 32); + } + DetilePlane(src_uv, src_stride_uv, dst_uv, dst_stride_uv, (width + 1) & ~1, + (height + sign) / 2, 16); + + return 0; +} + +LIBYUV_API +int MM21ToI420(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + int sign = height < 0 ? -1 : 1; + + if (!src_uv || !dst_u || !dst_v || width <= 0) { + return -1; + } + + if (dst_y) { + DetilePlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height, 32); + } + DetileSplitUVPlane(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, + dst_stride_v, (width + 1) & ~1, (height + sign) / 2, 16); + + return 0; +} + +LIBYUV_API +int MM21ToYUY2(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_yuy2, + int dst_stride_yuy2, + int width, + int height) { + if (!src_y || !src_uv || !dst_yuy2 || width <= 0) { + return -1; + } + + DetileToYUY2(src_y, src_stride_y, src_uv, src_stride_uv, dst_yuy2, + dst_stride_yuy2, width, height, 32); + + return 0; +} + +// Convert MT2T into P010. See tinyurl.com/mtk-10bit-video-format for format +// documentation. +// TODO(greenjustin): Add an MT2T to I420 conversion. +LIBYUV_API +int MT2TToP010(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + if (width <= 0 || height == 0 || height == INT_MIN || !src_uv || !dst_uv) { + return -1; + } + + { + int uv_width = (width + 1) & ~1; + int uv_height = (height + 1) / 2; + int y = 0; + const int tile_width = 16; + const int y_tile_height = 32; + const int uv_tile_height = 16; + int padded_width = (width + tile_width - 1) & ~(tile_width - 1); + int y_tile_row_size = padded_width * y_tile_height * 10 / 8; + int uv_tile_row_size = padded_width * uv_tile_height * 10 / 8; + size_t row_buf_size = padded_width * y_tile_height * sizeof(uint16_t); + void (*UnpackMT2T)(const uint8_t* src, uint16_t* dst, size_t size) = + UnpackMT2T_C; + align_buffer_64(row_buf, row_buf_size); + if (!row_buf) + return 1; + +#if defined(HAS_UNPACKMT2T_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + UnpackMT2T = UnpackMT2T_AVX2; + } +#endif +#if defined(HAS_UNPACKMT2T_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + UnpackMT2T = UnpackMT2T_NEON; + } +#endif + // Negative height means invert the image. + if (height < 0) { + height = -height; + uv_height = (height + 1) / 2; + if (dst_y) { + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; + dst_stride_y = -dst_stride_y; + } + dst_uv = dst_uv + (ptrdiff_t)(uv_height - 1) * dst_stride_uv; + dst_stride_uv = -dst_stride_uv; + } + + // Unpack and detile Y in rows of tiles + if (src_y && dst_y) { + for (y = 0; y < (height & ~(y_tile_height - 1)); y += y_tile_height) { + UnpackMT2T(src_y, (uint16_t*)row_buf, y_tile_row_size); + DetilePlane_16((uint16_t*)row_buf, padded_width, dst_y, dst_stride_y, + width, y_tile_height, y_tile_height); + src_y += src_stride_y * y_tile_height; + dst_y += dst_stride_y * y_tile_height; + } + if (height & (y_tile_height - 1)) { + UnpackMT2T(src_y, (uint16_t*)row_buf, y_tile_row_size); + DetilePlane_16((uint16_t*)row_buf, padded_width, dst_y, dst_stride_y, + width, height & (y_tile_height - 1), y_tile_height); + } + } + + // Unpack and detile UV plane + for (y = 0; y < (uv_height & ~(uv_tile_height - 1)); y += uv_tile_height) { + UnpackMT2T(src_uv, (uint16_t*)row_buf, uv_tile_row_size); + DetilePlane_16((uint16_t*)row_buf, padded_width, dst_uv, dst_stride_uv, + uv_width, uv_tile_height, uv_tile_height); + src_uv += src_stride_uv * uv_tile_height; + dst_uv += dst_stride_uv * uv_tile_height; + } + if (uv_height & (uv_tile_height - 1)) { + UnpackMT2T(src_uv, (uint16_t*)row_buf, uv_tile_row_size); + DetilePlane_16((uint16_t*)row_buf, padded_width, dst_uv, dst_stride_uv, + uv_width, uv_height & (uv_tile_height - 1), + uv_tile_height); + } + free_aligned_buffer_64(row_buf); + } + return 0; +} + #ifdef I422TONV21_ROW_VERSION // Unittest fails for this version. // 422 chroma is 1/2 width, 1x height @@ -277,21 +1454,22 @@ int I422ToNV21(const uint8_t* src_y, int y; void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width) = MergeUVRow_C; - void (*InterpolateRow)(uint8_t * dst_ptr, const uint8_t* src_ptr, + void (*InterpolateRow)(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_C; int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_u || !src_v || !dst_vu || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !src_u || !src_v || !dst_vu || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -307,11 +1485,16 @@ int I422ToNV21(const uint8_t* src_y, #if defined(HAS_MERGEUVROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { MergeUVRow = MergeUVRow_Any_AVX2; - if (IS_ALIGNED(halfwidth, 32)) { + if (IS_ALIGNED(halfwidth, 16)) { MergeUVRow = MergeUVRow_AVX2; } } #endif +#if defined(HAS_MERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow = MergeUVRow_AVX512BW; + } +#endif #if defined(HAS_MERGEUVROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { MergeUVRow = MergeUVRow_Any_NEON; @@ -320,27 +1503,42 @@ int I422ToNV21(const uint8_t* src_y, } } #endif -#if defined(HAS_MERGEUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - MergeUVRow = MergeUVRow_Any_MSA; +#if defined(HAS_MERGEUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + MergeUVRow = MergeUVRow_SVE2; + } +#endif +#if defined(HAS_MERGEUVROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow = MergeUVRow_SME; + } +#endif +#if defined(HAS_MERGEUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MergeUVRow = MergeUVRow_Any_LSX; if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow = MergeUVRow_MSA; + MergeUVRow = MergeUVRow_LSX; } } #endif -#if defined(HAS_MERGEUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - MergeUVRow = MergeUVRow_Any_MMI; - if (IS_ALIGNED(halfwidth, 8)) { - MergeUVRow = MergeUVRow_MMI; +#if defined(HAS_MERGEUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MergeUVRow = MergeUVRow_Any_LASX; + if (IS_ALIGNED(halfwidth, 32)) { + MergeUVRow = MergeUVRow_LASX; } } #endif -#if defined(HAS_INTERPOLATEROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - InterpolateRow = InterpolateRow_SSSE3; +#if defined(HAS_MERGEUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeUVRow = MergeUVRow_RVV; + } +#endif +#if defined(HAS_MERGEUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MergeUVRow = MergeUVRow_Any_WASMSIMD; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_WASMSIMD; } } #endif @@ -352,6 +1550,11 @@ int I422ToNV21(const uint8_t* src_y, } } #endif +#if defined(HAS_INTERPOLATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_AVX512BW; + } +#endif #if defined(HAS_INTERPOLATEROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { InterpolateRow = InterpolateRow_Any_NEON; @@ -360,19 +1563,42 @@ int I422ToNV21(const uint8_t* src_y, } } #endif -#if defined(HAS_INTERPOLATEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - InterpolateRow = InterpolateRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - InterpolateRow = InterpolateRow_MSA; +#if defined(HAS_INTERPOLATEROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + InterpolateRow = InterpolateRow_SVE2; + } +#endif +#if defined(HAS_INTERPOLATEROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + InterpolateRow = InterpolateRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + InterpolateRow = InterpolateRow_LSX; } } #endif -#if defined(HAS_INTERPOLATEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - InterpolateRow = InterpolateRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - InterpolateRow = InterpolateRow_MMI; +#if defined(HAS_INTERPOLATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + InterpolateRow = InterpolateRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + InterpolateRow = InterpolateRow_LASX; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + InterpolateRow = InterpolateRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + InterpolateRow = InterpolateRow_WASMSIMD; } } #endif @@ -385,6 +1611,8 @@ int I422ToNV21(const uint8_t* src_y, int awidth = halfwidth * 2; align_buffer_64(row_vu_0, awidth * 2); uint8_t* row_vu_1 = row_vu_0 + awidth; + if (!row_vu_0) + return 1; for (y = 0; y < height - 1; y += 2) { MergeUVRow(src_v, src_u, row_vu_0, halfwidth); @@ -426,7 +1654,41 @@ int I444ToI420(const uint8_t* src_y, dst_v, dst_stride_v, width, height, width, height); } -// TODO(fbarchard): Implement row conversion. +LIBYUV_API +int I444ToNV12(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + if ((!src_y && dst_y) || !src_u || !src_v || !dst_uv || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + if (dst_y) { + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + HalfMergeUVPlane(src_u, src_stride_u, src_v, src_stride_v, dst_uv, + dst_stride_uv, width, height); + return 0; +} + LIBYUV_API int I444ToNV21(const uint8_t* src_y, int src_stride_y, @@ -440,30 +1702,9 @@ int I444ToNV21(const uint8_t* src_y, int dst_stride_vu, int width, int height) { - int halfwidth = (width + 1) >> 1; - int halfheight = (height + 1) >> 1; - // Negative height means invert the image. - if (height < 0) { - height = -height; - halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; - src_stride_y = -src_stride_y; - src_stride_u = -src_stride_u; - src_stride_v = -src_stride_v; - } - // Allocate u and v buffers - align_buffer_64(plane_u, halfwidth * halfheight * 2); - uint8_t* plane_v = plane_u + halfwidth * halfheight; - - I444ToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, - dst_y, dst_stride_y, plane_u, halfwidth, plane_v, halfwidth, width, - height); - MergeUVPlane(plane_v, halfwidth, plane_u, halfwidth, dst_vu, dst_stride_vu, - halfwidth, halfheight); - free_aligned_buffer_64(plane_u); - return 0; + return I444ToNV12(src_y, src_stride_y, src_v, src_stride_v, src_u, + src_stride_u, dst_y, dst_stride_y, dst_vu, dst_stride_vu, + width, height); } // I400 is greyscale typically used in MJPG @@ -480,14 +1721,15 @@ int I400ToI420(const uint8_t* src_y, int height) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!dst_u || !dst_v || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } if (dst_y) { @@ -510,14 +1752,15 @@ int I400ToNV21(const uint8_t* src_y, int height) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!dst_vu || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !dst_vu || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } if (dst_y) { @@ -527,120 +1770,8 @@ int I400ToNV21(const uint8_t* src_y, return 0; } -static void CopyPlane2(const uint8_t* src, - int src_stride_0, - int src_stride_1, - uint8_t* dst, - int dst_stride, - int width, - int height) { - int y; - void (*CopyRow)(const uint8_t* src, uint8_t* dst, int width) = CopyRow_C; -#if defined(HAS_COPYROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - CopyRow = IS_ALIGNED(width, 32) ? CopyRow_SSE2 : CopyRow_Any_SSE2; - } -#endif -#if defined(HAS_COPYROW_AVX) - if (TestCpuFlag(kCpuHasAVX)) { - CopyRow = IS_ALIGNED(width, 64) ? CopyRow_AVX : CopyRow_Any_AVX; - } -#endif -#if defined(HAS_COPYROW_ERMS) - if (TestCpuFlag(kCpuHasERMS)) { - CopyRow = CopyRow_ERMS; - } -#endif -#if defined(HAS_COPYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - CopyRow = IS_ALIGNED(width, 32) ? CopyRow_NEON : CopyRow_Any_NEON; - } -#endif - - // Copy plane - for (y = 0; y < height - 1; y += 2) { - CopyRow(src, dst, width); - CopyRow(src + src_stride_0, dst + dst_stride, width); - src += src_stride_0 + src_stride_1; - dst += dst_stride * 2; - } - if (height & 1) { - CopyRow(src, dst, width); - } -} - -// Support converting from FOURCC_M420 -// Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for -// easy conversion to I420. -// M420 format description: -// M420 is row biplanar 420: 2 rows of Y and 1 row of UV. -// Chroma is half width / half height. (420) -// src_stride_m420 is row planar. Normally this will be the width in pixels. -// The UV plane is half width, but 2 values, so src_stride_m420 applies to -// this as well as the two Y planes. -static int X420ToI420(const uint8_t* src_y, - int src_stride_y0, - int src_stride_y1, - const uint8_t* src_uv, - int src_stride_uv, - uint8_t* dst_y, - int dst_stride_y, - uint8_t* dst_u, - int dst_stride_u, - uint8_t* dst_v, - int dst_stride_v, - int width, - int height) { - int halfwidth = (width + 1) >> 1; - int halfheight = (height + 1) >> 1; - if (!src_uv || !dst_u || !dst_v || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - halfheight = (height + 1) >> 1; - if (dst_y) { - dst_y = dst_y + (height - 1) * dst_stride_y; - } - dst_u = dst_u + (halfheight - 1) * dst_stride_u; - dst_v = dst_v + (halfheight - 1) * dst_stride_v; - dst_stride_y = -dst_stride_y; - dst_stride_u = -dst_stride_u; - dst_stride_v = -dst_stride_v; - } - // Coalesce rows. - if (src_stride_y0 == width && src_stride_y1 == width && - dst_stride_y == width) { - width *= height; - height = 1; - src_stride_y0 = src_stride_y1 = dst_stride_y = 0; - } - // Coalesce rows. - if (src_stride_uv == halfwidth * 2 && dst_stride_u == halfwidth && - dst_stride_v == halfwidth) { - halfwidth *= halfheight; - halfheight = 1; - src_stride_uv = dst_stride_u = dst_stride_v = 0; - } - - if (dst_y) { - if (src_stride_y0 == src_stride_y1) { - CopyPlane(src_y, src_stride_y0, dst_y, dst_stride_y, width, height); - } else { - CopyPlane2(src_y, src_stride_y0, src_stride_y1, dst_y, dst_stride_y, - width, height); - } - } - - // Split UV plane - NV12 / NV21 - SplitUVPlane(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, dst_stride_v, - halfwidth, halfheight); - - return 0; -} - // Convert NV12 to I420. +// TODO(fbarchard): Consider inverting destination. Faster on ARM with prfm. LIBYUV_API int NV12ToI420(const uint8_t* src_y, int src_stride_y, @@ -654,9 +1785,46 @@ int NV12ToI420(const uint8_t* src_y, int dst_stride_v, int width, int height) { - return X420ToI420(src_y, src_stride_y, src_stride_y, src_uv, src_stride_uv, - dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, - dst_stride_v, width, height); + int halfwidth = (width + 1) >> 1; + int halfheight = (height + 1) >> 1; + if ((!src_y && dst_y) || !src_uv || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_uv = src_uv + (ptrdiff_t)(halfheight - 1) * src_stride_uv; + src_stride_y = -src_stride_y; + src_stride_uv = -src_stride_uv; + } + // Coalesce rows. + if (src_stride_y == width && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = dst_stride_y = 0; + } + // Coalesce rows. + if (src_stride_uv == halfwidth * 2 && dst_stride_u == halfwidth && + dst_stride_v == halfwidth && + (ptrdiff_t)halfwidth * halfheight <= INT_MAX) { + halfwidth *= halfheight; + halfheight = 1; + src_stride_uv = dst_stride_u = dst_stride_v = 0; + } + + if (dst_y) { + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + + // Split UV plane - NV12 / NV21 + SplitUVPlane(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, dst_stride_v, + halfwidth, halfheight); + + return 0; } // Convert NV21 to I420. Same as NV12 but u and v pointers swapped. @@ -673,15 +1841,502 @@ int NV21ToI420(const uint8_t* src_y, int dst_stride_v, int width, int height) { - return X420ToI420(src_y, src_stride_y, src_stride_y, src_vu, src_stride_vu, - dst_y, dst_stride_y, dst_v, dst_stride_v, dst_u, - dst_stride_u, width, height); + return NV12ToI420(src_y, src_stride_y, src_vu, src_stride_vu, dst_y, + dst_stride_y, dst_v, dst_stride_v, dst_u, dst_stride_u, + width, height); } -// Convert M420 to I420. LIBYUV_API -int M420ToI420(const uint8_t* src_m420, - int src_stride_m420, +int NV12ToNV24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + int r; + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + + if (dst_y) { + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + r = UVScale(src_uv, src_stride_uv, SUBSAMPLE(width, 1, 1), + SUBSAMPLE(height, 1, 1), dst_uv, dst_stride_uv, Abs(width), + Abs(height), kFilterBilinear); + return r; +} + +LIBYUV_API +int NV16ToNV24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + int r; + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + + if (dst_y) { + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + r = UVScale(src_uv, src_stride_uv, SUBSAMPLE(width, 1, 1), height, dst_uv, + dst_stride_uv, Abs(width), Abs(height), kFilterBilinear); + return r; +} + +// Any P[420]1[02] to I[420]1[02] format +static int PxxxToIxxx(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height, + int subsample_x, + int subsample_y, + int depth) { + const int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); + const int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); + if (!src_y || !dst_y || !src_uv || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + ConvertToLSBPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height, + depth); + SplitUVPlane_16(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, + dst_stride_v, uv_width, uv_height, depth); + return 0; +} + +LIBYUV_API +int P010ToI010(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + return PxxxToIxxx(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, + width, height, 1, 1, 10); +} + +LIBYUV_API +int P210ToI210(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + return PxxxToIxxx(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, + width, height, 1, 0, 10); +} + +LIBYUV_API +int P410ToI410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + return PxxxToIxxx(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, + width, height, 0, 0, 10); +} + +static void InvertPx10(const uint16_t** src_y, + int* src_stride_y, + const uint16_t** src_uv, + int* src_stride_uv, + int* height, + int subsample_y) { + const int abs_height = Abs(*height); + const int src_uv_height = SUBSAMPLE(abs_height, subsample_y, subsample_y); + if (*src_y) { + *src_y = *src_y + (ptrdiff_t)(abs_height - 1) * *src_stride_y; + *src_stride_y = -*src_stride_y; + } + *src_uv = *src_uv + (ptrdiff_t)(src_uv_height - 1) * *src_stride_uv; + *src_stride_uv = -*src_stride_uv; + *height = abs_height; +} + +static int Px10ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + int subsample_x, + int subsample_y) { + const int scale16 = 256; // P*10 stores 10-bit in the MSBs. + int src_uv_width; + int dst_uv_width; + if ((!src_y && dst_y) || !src_uv || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + if (height < 0) { + InvertPx10(&src_y, &src_stride_y, &src_uv, &src_stride_uv, &height, + subsample_y); + } + src_uv_width = SUBSAMPLE(width, subsample_x, subsample_x); + dst_uv_width = SUBSAMPLE(width, 1, 1); + + if (dst_y) { + Convert16To8Plane(src_y, src_stride_y, dst_y, dst_stride_y, scale16, width, + height); + } + + if (subsample_x && subsample_y) { + int y; + const int uv_packed = src_uv_width * 2; + const int uv_height = SUBSAMPLE(height, 1, 1); + void (*Convert16To8Row)(const uint16_t* src_y, uint8_t* dst_y, int scale, + int width) = Convert16To8Row_C; + void (*SplitUVRow)(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, + int width) = SplitUVRow_C; + +#if defined(HAS_CONVERT16TO8ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Convert16To8Row = Convert16To8Row_Any_NEON; + if (IS_ALIGNED(uv_packed, 16)) { + Convert16To8Row = Convert16To8Row_NEON; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + Convert16To8Row = Convert16To8Row_SVE2; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Convert16To8Row = Convert16To8Row_SME; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Convert16To8Row = Convert16To8Row_Any_SSSE3; + if (IS_ALIGNED(uv_packed, 16)) { + Convert16To8Row = Convert16To8Row_SSSE3; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Convert16To8Row = Convert16To8Row_Any_AVX2; + if (IS_ALIGNED(uv_packed, 32)) { + Convert16To8Row = Convert16To8Row_AVX2; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Convert16To8Row = Convert16To8Row_AVX512BW; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Convert16To8Row = Convert16To8Row_RVV; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Convert16To8Row = Convert16To8Row_HVX; + } +#endif +#if defined(HAS_SPLITUVROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + SplitUVRow = SplitUVRow_Any_SSE2; + if (IS_ALIGNED(src_uv_width, 16)) { + SplitUVRow = SplitUVRow_SSE2; + } + } +#endif +#if defined(HAS_SPLITUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SplitUVRow = SplitUVRow_Any_AVX2; + if (IS_ALIGNED(src_uv_width, 32)) { + SplitUVRow = SplitUVRow_AVX2; + } + } +#endif +#if defined(HAS_SPLITUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + SplitUVRow = SplitUVRow_AVX512BW; + } +#endif +#if defined(HAS_SPLITUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + SplitUVRow = SplitUVRow_Any_NEON; + if (IS_ALIGNED(src_uv_width, 16)) { + SplitUVRow = SplitUVRow_NEON; + } + } +#endif +#if defined(HAS_SPLITUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + SplitUVRow = SplitUVRow_SVE2; + } +#endif +#if defined(HAS_SPLITUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + SplitUVRow = SplitUVRow_Any_LSX; + if (IS_ALIGNED(src_uv_width, 16)) { + SplitUVRow = SplitUVRow_LSX; + } + } +#endif +#if defined(HAS_SPLITUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + SplitUVRow = SplitUVRow_Any_LASX; + if (IS_ALIGNED(src_uv_width, 32)) { + SplitUVRow = SplitUVRow_LASX; + } + } +#endif +#if defined(HAS_SPLITUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SplitUVRow = SplitUVRow_RVV; + } +#endif +#if defined(HAS_SPLITUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SplitUVRow = SplitUVRow_HVX; + } +#endif + + align_buffer_64(row_uv, ((uv_packed + 63) & ~63)); + if (!row_uv) { + return 1; + } + for (y = 0; y < uv_height; ++y) { + Convert16To8Row(src_uv, row_uv, scale16, uv_packed); + SplitUVRow(row_uv, dst_u, dst_v, src_uv_width); + src_uv += src_stride_uv; + dst_u += dst_stride_u; + dst_v += dst_stride_v; + } + free_aligned_buffer_64(row_uv); + return 0; + } + + { + int y; + const int scale = 16384; // 10-bit LSB after SplitUVRow_16. + int row_stride; + void (*SplitUVRow_16)(const uint16_t* src_uv, uint16_t* dst_u, + uint16_t* dst_v, int depth, int width) = + SplitUVRow_16_C; + void (*Half16To8)(const uint16_t* src_uv, ptrdiff_t src_uv_stride, + uint8_t* dst_uv, int scale, int width) = + subsample_x + ? HalfRow_16To8_C + : ((width & 1) ? HalfWidthRow_16To8_Odd_C : HalfWidthRow_16To8_C); + +#if defined(HAS_SPLITUVROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SplitUVRow_16 = SplitUVRow_16_Any_AVX2; + if (IS_ALIGNED(src_uv_width, 16)) { + SplitUVRow_16 = SplitUVRow_16_AVX2; + } + } +#endif +#if defined(HAS_SPLITUVROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + SplitUVRow_16 = SplitUVRow_16_Any_NEON; + if (IS_ALIGNED(src_uv_width, 8)) { + SplitUVRow_16 = SplitUVRow_16_NEON; + } + } +#endif +#if defined(HAS_SPLITUVROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SplitUVRow_16 = SplitUVRow_16_HVX; + } +#endif + if (subsample_x) { +#if defined(HAS_HALFROW_16TO8_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Half16To8 = HalfRow_16To8_Any_NEON; + if (IS_ALIGNED(dst_uv_width, 16)) { + Half16To8 = HalfRow_16To8_NEON; + } + } +#endif +#if defined(HAS_HALFROW_16TO8_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + Half16To8 = HalfRow_16To8_SVE2; + } +#endif +#if defined(HAS_HALFROW_16TO8_SME) + if (TestCpuFlag(kCpuHasSME)) { + Half16To8 = HalfRow_16To8_SME; + } +#endif +#if defined(HAS_HALFROW_16TO8_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Half16To8 = HalfRow_16To8_Any_SSSE3; + if (IS_ALIGNED(dst_uv_width, 16)) { + Half16To8 = HalfRow_16To8_SSSE3; + } + } +#endif +#if defined(HAS_HALFROW_16TO8_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Half16To8 = HalfRow_16To8_Any_AVX2; + if (IS_ALIGNED(dst_uv_width, 32)) { + Half16To8 = HalfRow_16To8_AVX2; + } + } +#endif +#if defined(HAS_HALFROW_16TO8_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Half16To8 = HalfRow_16To8_AVX512BW; + } +#endif +#if defined(HAS_HALFROW_16TO8_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Half16To8 = HalfRow_16To8_RVV; + } +#endif +#if defined(HAS_HALFROW_16TO8_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Half16To8 = HalfRow_16To8_HVX; + } +#endif + } else if (IS_ALIGNED(width, 2)) { +#if defined(HAS_HALFWIDTHROW_16TO8_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Half16To8 = HalfWidthRow_16To8_Any_NEON; + if (IS_ALIGNED(dst_uv_width, 8)) { + Half16To8 = HalfWidthRow_16To8_NEON; + } + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + Half16To8 = HalfWidthRow_16To8_SVE2; + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_SME) + if (TestCpuFlag(kCpuHasSME)) { + Half16To8 = HalfWidthRow_16To8_SME; + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Half16To8 = HalfWidthRow_16To8_Any_SSSE3; + if (IS_ALIGNED(dst_uv_width, 8)) { + Half16To8 = HalfWidthRow_16To8_SSSE3; + } + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Half16To8 = HalfWidthRow_16To8_Any_AVX2; + if (IS_ALIGNED(dst_uv_width, 16)) { + Half16To8 = HalfWidthRow_16To8_AVX2; + } + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Half16To8 = HalfWidthRow_16To8_AVX512BW; + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Half16To8 = HalfWidthRow_16To8_RVV; + } +#endif + } else { +#if defined(HAS_HALFWIDTHROW_16TO8_ODD_AVX2) || \ + defined(HAS_HALFWIDTHROW_16TO8_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Half16To8 = HalfWidthRow_16To8_Odd_AVX2; + } +#endif + } + + row_stride = (src_uv_width + 31) & ~31; + align_buffer_64(row_u, (size_t)row_stride * sizeof(uint16_t) * 4u); + if (!row_u) { + return 1; + } + { + uint16_t* row_u0 = (uint16_t*)row_u; + uint16_t* row_u1 = row_u0 + row_stride; + uint16_t* row_v0 = row_u1 + row_stride; + uint16_t* row_v1 = row_v0 + row_stride; + for (y = 0; y < height - 1; y += 2) { + SplitUVRow_16(src_uv, row_u0, row_v0, 10, src_uv_width); + SplitUVRow_16(src_uv + src_stride_uv, row_u1, row_v1, 10, src_uv_width); + Half16To8(row_u0, row_stride, dst_u, scale, dst_uv_width); + Half16To8(row_v0, row_stride, dst_v, scale, dst_uv_width); + src_uv += src_stride_uv * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; + } + if (height & 1) { + SplitUVRow_16(src_uv, row_u0, row_v0, 10, src_uv_width); + Half16To8(row_u0, 0, dst_u, scale, dst_uv_width); + Half16To8(row_v0, 0, dst_v, scale, dst_uv_width); + } + } + free_aligned_buffer_64(row_u); + return 0; + } +} + +LIBYUV_API +int P010ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, uint8_t* dst_y, int dst_stride_y, uint8_t* dst_u, @@ -690,10 +2345,114 @@ int M420ToI420(const uint8_t* src_m420, int dst_stride_v, int width, int height) { - return X420ToI420(src_m420, src_stride_m420, src_stride_m420 * 2, - src_m420 + src_stride_m420 * 2, src_stride_m420 * 3, dst_y, + return Px10ToI420(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, - width, height); + width, height, 1, 1); +} + +LIBYUV_API +int P210ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return Px10ToI420(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, + width, height, 1, 0); +} + +LIBYUV_API +int P410ToI420(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return Px10ToI420(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, + width, height, 0, 0); +} + +LIBYUV_API +int P012ToI012(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + return PxxxToIxxx(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, + width, height, 1, 1, 12); +} + +LIBYUV_API +int P010ToP410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + int r; + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + + if (dst_y) { + CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + r = UVScale_16(src_uv, src_stride_uv, SUBSAMPLE(width, 1, 1), + SUBSAMPLE(height, 1, 1), dst_uv, dst_stride_uv, Abs(width), + Abs(height), kFilterBilinear); + return r; +} + +LIBYUV_API +int P210ToP410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + int r; + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + + if (dst_y) { + CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + r = UVScale_16(src_uv, src_stride_uv, SUBSAMPLE(width, 1, 1), height, dst_uv, + dst_stride_uv, Abs(width), Abs(height), kFilterBilinear); + return r; } // Convert YUY2 to I420. @@ -714,10 +2473,13 @@ int YUY2ToI420(const uint8_t* src_yuy2, YUY2ToUVRow_C; void (*YUY2ToYRow)(const uint8_t* src_yuy2, uint8_t* dst_y, int width) = YUY2ToYRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; + src_yuy2 = src_yuy2 + (ptrdiff_t)(height - 1) * src_stride_yuy2; src_stride_yuy2 = -src_stride_yuy2; } #if defined(HAS_YUY2TOYROW_SSE2) @@ -740,6 +2502,12 @@ int YUY2ToI420(const uint8_t* src_yuy2, } } #endif +#if defined(HAS_YUY2TOYROW_AVX512BW) && defined(HAS_YUY2TOUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + YUY2ToUVRow = YUY2ToUVRow_AVX512BW; + YUY2ToYRow = YUY2ToYRow_AVX512BW; + } +#endif #if defined(HAS_YUY2TOYROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { YUY2ToYRow = YUY2ToYRow_Any_NEON; @@ -750,28 +2518,38 @@ int YUY2ToI420(const uint8_t* src_yuy2, } } #endif -#if defined(HAS_YUY2TOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - YUY2ToYRow = YUY2ToYRow_Any_MSA; - YUY2ToUVRow = YUY2ToUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - YUY2ToYRow = YUY2ToYRow_MSA; - YUY2ToUVRow = YUY2ToUVRow_MSA; +#if defined(HAS_YUY2TOYROW_SVE2) && defined(HAS_YUY2TOUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + YUY2ToYRow = YUY2ToYRow_SVE2; + YUY2ToUVRow = YUY2ToUVRow_SVE2; + } +#endif +#if defined(HAS_YUY2TOYROW_LSX) && defined(HAS_YUY2TOUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + YUY2ToYRow = YUY2ToYRow_Any_LSX; + YUY2ToUVRow = YUY2ToUVRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + YUY2ToYRow = YUY2ToYRow_LSX; + YUY2ToUVRow = YUY2ToUVRow_LSX; } } #endif -#if defined(HAS_YUY2TOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - YUY2ToYRow = YUY2ToYRow_Any_MMI; - YUY2ToUVRow = YUY2ToUVRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - YUY2ToYRow = YUY2ToYRow_MMI; - if (IS_ALIGNED(width, 16)) { - YUY2ToUVRow = YUY2ToUVRow_MMI; - } +#if defined(HAS_YUY2TOYROW_LASX) && defined(HAS_YUY2TOUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + YUY2ToYRow = YUY2ToYRow_Any_LASX; + YUY2ToUVRow = YUY2ToUVRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + YUY2ToYRow = YUY2ToYRow_LASX; + YUY2ToUVRow = YUY2ToUVRow_LASX; } } #endif +#if defined(HAS_YUY2TOYROW_HVX) && defined(HAS_YUY2TOUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + YUY2ToYRow = YUY2ToYRow_HVX; + YUY2ToUVRow = YUY2ToUVRow_HVX; + } +#endif for (y = 0; y < height - 1; y += 2) { YUY2ToUVRow(src_yuy2, src_stride_yuy2, dst_u, dst_v, width); @@ -807,10 +2585,13 @@ int UYVYToI420(const uint8_t* src_uyvy, UYVYToUVRow_C; void (*UYVYToYRow)(const uint8_t* src_uyvy, uint8_t* dst_y, int width) = UYVYToYRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; + src_uyvy = src_uyvy + (ptrdiff_t)(height - 1) * src_stride_uyvy; src_stride_uyvy = -src_stride_uyvy; } #if defined(HAS_UYVYTOYROW_SSE2) @@ -833,6 +2614,12 @@ int UYVYToI420(const uint8_t* src_uyvy, } } #endif +#if defined(HAS_UYVYTOYROW_AVX512BW) && defined(HAS_UYVYTOUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + UYVYToUVRow = UYVYToUVRow_AVX512BW; + UYVYToYRow = UYVYToYRow_AVX512BW; + } +#endif #if defined(HAS_UYVYTOYROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { UYVYToYRow = UYVYToYRow_Any_NEON; @@ -843,26 +2630,38 @@ int UYVYToI420(const uint8_t* src_uyvy, } } #endif -#if defined(HAS_UYVYTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - UYVYToYRow = UYVYToYRow_Any_MSA; - UYVYToUVRow = UYVYToUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - UYVYToYRow = UYVYToYRow_MSA; - UYVYToUVRow = UYVYToUVRow_MSA; +#if defined(HAS_UYVYTOYROW_SVE2) && defined(HAS_UYVYTOUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + UYVYToYRow = UYVYToYRow_SVE2; + UYVYToUVRow = UYVYToUVRow_SVE2; + } +#endif +#if defined(HAS_UYVYTOYROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + UYVYToYRow = UYVYToYRow_Any_LSX; + UYVYToUVRow = UYVYToUVRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + UYVYToYRow = UYVYToYRow_LSX; + UYVYToUVRow = UYVYToUVRow_LSX; } } #endif -#if defined(HAS_UYVYTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - UYVYToYRow = UYVYToYRow_Any_MMI; - UYVYToUVRow = UYVYToUVRow_Any_MMI; - if (IS_ALIGNED(width, 16)) { - UYVYToYRow = UYVYToYRow_MMI; - UYVYToUVRow = UYVYToUVRow_MMI; +#if defined(HAS_UYVYTOYROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + UYVYToYRow = UYVYToYRow_Any_LASX; + UYVYToUVRow = UYVYToUVRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + UYVYToYRow = UYVYToYRow_LASX; + UYVYToUVRow = UYVYToUVRow_LASX; } } #endif +#if defined(HAS_UYVYTOYROW_HVX) && defined(HAS_UYVYTOUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + UYVYToYRow = UYVYToYRow_HVX; + UYVYToUVRow = UYVYToUVRow_HVX; + } +#endif for (y = 0; y < height - 1; y += 2) { UYVYToUVRow(src_uyvy, src_stride_uyvy, dst_u, dst_v, width); @@ -895,31 +2694,30 @@ int AYUVToNV12(const uint8_t* src_ayuv, uint8_t* dst_uv, int width) = AYUVToUVRow_C; void (*AYUVToYRow)(const uint8_t* src_ayuv, uint8_t* dst_y, int width) = AYUVToYRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_ayuv = src_ayuv + (height - 1) * src_stride_ayuv; + src_ayuv = src_ayuv + (ptrdiff_t)(height - 1) * src_stride_ayuv; src_stride_ayuv = -src_stride_ayuv; } -// place holders for future intel code -#if defined(HAS_AYUVTOYROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - AYUVToUVRow = AYUVToUVRow_Any_SSE2; - AYUVToYRow = AYUVToYRow_Any_SSE2; +#if defined(HAS_AYUVTOYROW_AVX2) && defined(HAS_AYUVTOUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + AYUVToYRow = AYUVToYRow_Any_AVX2; + AYUVToUVRow = AYUVToUVRow_Any_AVX2; if (IS_ALIGNED(width, 16)) { - AYUVToUVRow = AYUVToUVRow_SSE2; - AYUVToYRow = AYUVToYRow_SSE2; + AYUVToYRow = AYUVToYRow_AVX2; + AYUVToUVRow = AYUVToUVRow_AVX2; } } #endif -#if defined(HAS_AYUVTOYROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - AYUVToUVRow = AYUVToUVRow_Any_AVX2; - AYUVToYRow = AYUVToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - AYUVToUVRow = AYUVToUVRow_AVX2; - AYUVToYRow = AYUVToYRow_AVX2; - } +#if defined(HAS_AYUVTOYROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI | kCpuHasAVX512VL) == + (kCpuHasAVX512VBMI | kCpuHasAVX512VL)) { + AYUVToUVRow = AYUVToUVRow_AVX512VBMI; + AYUVToYRow = AYUVToYRow_AVX512VBMI; } #endif @@ -933,6 +2731,14 @@ int AYUVToNV12(const uint8_t* src_ayuv, } } #endif +#if defined(HAS_AYUVTOUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + AYUVToUVRow = AYUVToUVRow_Any_SVE2; + if (IS_ALIGNED(width, 2)) { + AYUVToUVRow = AYUVToUVRow_SVE2; + } + } +#endif for (y = 0; y < height - 1; y += 2) { AYUVToUVRow(src_ayuv, src_stride_ayuv, dst_uv, width); @@ -964,31 +2770,30 @@ int AYUVToNV21(const uint8_t* src_ayuv, uint8_t* dst_vu, int width) = AYUVToVURow_C; void (*AYUVToYRow)(const uint8_t* src_ayuv, uint8_t* dst_y, int width) = AYUVToYRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_ayuv = src_ayuv + (height - 1) * src_stride_ayuv; + src_ayuv = src_ayuv + (ptrdiff_t)(height - 1) * src_stride_ayuv; src_stride_ayuv = -src_stride_ayuv; } -// place holders for future intel code -#if defined(HAS_AYUVTOYROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - AYUVToVURow = AYUVToVURow_Any_SSE2; - AYUVToYRow = AYUVToYRow_Any_SSE2; +#if defined(HAS_AYUVTOYROW_AVX2) && defined(HAS_AYUVTOVUROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + AYUVToYRow = AYUVToYRow_Any_AVX2; + AYUVToVURow = AYUVToVURow_Any_AVX2; if (IS_ALIGNED(width, 16)) { - AYUVToVURow = AYUVToVURow_SSE2; - AYUVToYRow = AYUVToYRow_SSE2; + AYUVToYRow = AYUVToYRow_AVX2; + AYUVToVURow = AYUVToVURow_AVX2; } } #endif -#if defined(HAS_AYUVTOYROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - AYUVToVURow = AYUVToVURow_Any_AVX2; - AYUVToYRow = AYUVToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - AYUVToVURow = AYUVToVURow_AVX2; - AYUVToYRow = AYUVToYRow_AVX2; - } +#if defined(HAS_AYUVTOYROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI | kCpuHasAVX512VL) == + (kCpuHasAVX512VBMI | kCpuHasAVX512VL)) { + AYUVToVURow = AYUVToVURow_AVX512VBMI; + AYUVToYRow = AYUVToYRow_AVX512VBMI; } #endif @@ -1002,6 +2807,14 @@ int AYUVToNV21(const uint8_t* src_ayuv, } } #endif +#if defined(HAS_AYUVTOVUROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + AYUVToVURow = AYUVToVURow_Any_SVE2; + if (IS_ALIGNED(width, 2)) { + AYUVToVURow = AYUVToVURow_SVE2; + } + } +#endif for (y = 0; y < height - 1; y += 2) { AYUVToVURow(src_ayuv, src_stride_ayuv, dst_vu, width); @@ -1030,106 +2843,539 @@ int ARGBToI420(const uint8_t* src_argb, int dst_stride_v, int width, int height) { + return ARGBToI420Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kArgbI601Constants, width, height); +} + +LIBYUV_API +int ARGBToI420Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + const struct ArgbConstants* argbconstants, + int width, + int height) { int y; - void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVRow_C; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; - if (!src_argb || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUVMatrixRow)(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + ARGBToUVMatrixRow_C; + +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON_I8MM; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON_I8MM; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SVE2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SME; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_HVX; + } +#endif + if (!src_argb || !dst_y || !dst_u || !dst_v || !argbconstants || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } -#if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVRow = ARGBToUVRow_Any_SSSE3; - ARGBToYRow = ARGBToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_SSSE3; - ARGBToYRow = ARGBToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVRow = ARGBToUVRow_Any_AVX2; - ARGBToYRow = ARGBToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_AVX2; - ARGBToYRow = ARGBToYRow_AVX2; - } - } -#endif -#if defined(HAS_ARGBTOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYRow = ARGBToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToUVRow = ARGBToUVRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYRow = ARGBToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBToYRow = ARGBToYRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToUVRow = ARGBToUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYRow = ARGBToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_MMI; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToUVRow = ARGBToUVRow_Any_MMI; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_MMI; - } - } -#endif for (y = 0; y < height - 1; y += 2) { - ARGBToUVRow(src_argb, src_stride_argb, dst_u, dst_v, width); - ARGBToYRow(src_argb, dst_y, width); - ARGBToYRow(src_argb + src_stride_argb, dst_y + dst_stride_y, width); + ARGBToUVMatrixRow(src_argb, src_stride_argb, dst_u, dst_v, width, + argbconstants); + ARGBToYMatrixRow(src_argb, dst_y, width, argbconstants); + ARGBToYMatrixRow(src_argb + src_stride_argb, dst_y + dst_stride_y, width, + argbconstants); src_argb += src_stride_argb * 2; dst_y += dst_stride_y * 2; dst_u += dst_stride_u; dst_v += dst_stride_v; } if (height & 1) { - ARGBToUVRow(src_argb, 0, dst_u, dst_v, width); - ARGBToYRow(src_argb, dst_y, width); + ARGBToUVMatrixRow(src_argb, 0, dst_u, dst_v, width, argbconstants); + ARGBToYMatrixRow(src_argb, dst_y, width, argbconstants); } return 0; } +#ifdef USE_EXTRACTALPHA +// Convert ARGB to I420 with Alpha +// The following version calls ARGBExtractAlpha on the full image. +LIBYUV_API +int ARGBToI420Alpha(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + uint8_t* dst_a, + int dst_stride_a, + int width, + int height) { + int r = ARGBToI420(src_argb, src_stride_argb, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, width, height); + if (r == 0) { + r = ARGBExtractAlpha(src_argb, src_stride_argb, dst_a, dst_stride_a, width, + height); + } + return r; +} +#else // USE_EXTRACTALPHA +// Convert ARGB to I420 with Alpha +LIBYUV_API +int ARGBToI420Alpha(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + uint8_t* dst_a, + int dst_stride_a, + int width, + int height) { + int y; + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUVMatrixRow)(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + ARGBToUVMatrixRow_C; + void (*ARGBExtractAlphaRow)(const uint8_t* src_argb, uint8_t* dst_a, + int width) = ARGBExtractAlphaRow_C; + if (!src_argb || !dst_y || !dst_u || !dst_v || !dst_a || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } + +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON_I8MM; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON_I8MM; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SVE2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SME; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_HVX; + } +#endif + +#if defined(HAS_ARGBEXTRACTALPHAROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + ARGBExtractAlphaRow = IS_ALIGNED(width, 8) ? ARGBExtractAlphaRow_SSE2 + : ARGBExtractAlphaRow_Any_SSE2; + } +#endif +#if defined(HAS_ARGBEXTRACTALPHAROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBExtractAlphaRow = IS_ALIGNED(width, 32) ? ARGBExtractAlphaRow_AVX2 + : ARGBExtractAlphaRow_Any_AVX2; + } +#endif +#if defined(HAS_ARGBEXTRACTALPHAROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBExtractAlphaRow = ARGBExtractAlphaRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBEXTRACTALPHAROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBExtractAlphaRow = IS_ALIGNED(width, 16) ? ARGBExtractAlphaRow_NEON + : ARGBExtractAlphaRow_Any_NEON; + } +#endif +#if defined(HAS_ARGBEXTRACTALPHAROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBExtractAlphaRow = IS_ALIGNED(width, 8) ? ARGBExtractAlphaRow_LSX + : ARGBExtractAlphaRow_Any_LSX; + } +#endif +#if defined(HAS_ARGBEXTRACTALPHAROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBExtractAlphaRow = IS_ALIGNED(width, 16) ? ARGBExtractAlphaRow_LASX + : ARGBExtractAlphaRow_Any_LASX; + } +#endif +#if defined(HAS_ARGBEXTRACTALPHAROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBExtractAlphaRow = IS_ALIGNED(width, 16) + ? ARGBExtractAlphaRow_WASMSIMD + : ARGBExtractAlphaRow_Any_WASMSIMD; + } +#endif +#if defined(HAS_ARGBEXTRACTALPHAROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBExtractAlphaRow = ARGBExtractAlphaRow_RVV; + } +#endif +#if defined(HAS_ARGBEXTRACTALPHAROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBExtractAlphaRow = ARGBExtractAlphaRow_HVX; + } +#endif + + for (y = 0; y < height - 1; y += 2) { + ARGBToUVMatrixRow(src_argb, src_stride_argb, dst_u, dst_v, width, + &kArgbI601Constants); + ARGBToYMatrixRow(src_argb, dst_y, width, &kArgbI601Constants); + ARGBToYMatrixRow(src_argb + src_stride_argb, dst_y + dst_stride_y, width, + &kArgbI601Constants); + ARGBExtractAlphaRow(src_argb, dst_a, width); + ARGBExtractAlphaRow(src_argb + src_stride_argb, dst_a + dst_stride_a, + width); + src_argb += src_stride_argb * 2; + dst_y += dst_stride_y * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; + dst_a += dst_stride_a * 2; + } + if (height & 1) { + ARGBToUVMatrixRow(src_argb, 0, dst_u, dst_v, width, &kArgbI601Constants); + ARGBToYMatrixRow(src_argb, dst_y, width, &kArgbI601Constants); + ARGBExtractAlphaRow(src_argb, dst_a, width); + } + return 0; +} +#endif // USE_EXTRACTALPHA + // Convert BGRA to I420. LIBYUV_API int BGRAToI420(const uint8_t* src_bgra, @@ -1142,94 +3388,60 @@ int BGRAToI420(const uint8_t* src_bgra, int dst_stride_v, int width, int height) { - int y; - void (*BGRAToUVRow)(const uint8_t* src_bgra0, int src_stride_bgra, - uint8_t* dst_u, uint8_t* dst_v, int width) = - BGRAToUVRow_C; - void (*BGRAToYRow)(const uint8_t* src_bgra, uint8_t* dst_y, int width) = - BGRAToYRow_C; - if (!src_bgra || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - src_bgra = src_bgra + (height - 1) * src_stride_bgra; - src_stride_bgra = -src_stride_bgra; - } -#if defined(HAS_BGRATOYROW_SSSE3) && defined(HAS_BGRATOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - BGRAToUVRow = BGRAToUVRow_Any_SSSE3; - BGRAToYRow = BGRAToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - BGRAToUVRow = BGRAToUVRow_SSSE3; - BGRAToYRow = BGRAToYRow_SSSE3; - } - } -#endif -#if defined(HAS_BGRATOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - BGRAToYRow = BGRAToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - BGRAToYRow = BGRAToYRow_NEON; - } - } -#endif -#if defined(HAS_BGRATOUVROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - BGRAToUVRow = BGRAToUVRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { - BGRAToUVRow = BGRAToUVRow_NEON; - } - } -#endif -#if defined(HAS_BGRATOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - BGRAToYRow = BGRAToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - BGRAToYRow = BGRAToYRow_MSA; - } - } -#endif -#if defined(HAS_BGRATOUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - BGRAToUVRow = BGRAToUVRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - BGRAToUVRow = BGRAToUVRow_MSA; - } - } -#endif -#if defined(HAS_BGRATOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - BGRAToYRow = BGRAToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - BGRAToYRow = BGRAToYRow_MMI; - } - } -#endif -#if defined(HAS_BGRATOUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - BGRAToUVRow = BGRAToUVRow_Any_MMI; - if (IS_ALIGNED(width, 16)) { - BGRAToUVRow = BGRAToUVRow_MMI; - } - } -#endif + return ARGBToI420Matrix(src_bgra, src_stride_bgra, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kBgraI601Constants, width, height); +} - for (y = 0; y < height - 1; y += 2) { - BGRAToUVRow(src_bgra, src_stride_bgra, dst_u, dst_v, width); - BGRAToYRow(src_bgra, dst_y, width); - BGRAToYRow(src_bgra + src_stride_bgra, dst_y + dst_stride_y, width); - src_bgra += src_stride_bgra * 2; - dst_y += dst_stride_y * 2; - dst_u += dst_stride_u; - dst_v += dst_stride_v; - } - if (height & 1) { - BGRAToUVRow(src_bgra, 0, dst_u, dst_v, width); - BGRAToYRow(src_bgra, dst_y, width); - } - return 0; +// Convert BGRA to I422. +LIBYUV_API +int BGRAToI422(const uint8_t* src_bgra, + int src_stride_bgra, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return ARGBToI422Matrix(src_bgra, src_stride_bgra, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kBgraI601Constants, width, height); +} + +// Convert ABGR to I422. +LIBYUV_API +int ABGRToI422(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return ARGBToI422Matrix(src_abgr, src_stride_abgr, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kAbgrI601Constants, width, height); +} + +// Convert RGBA to I422. +LIBYUV_API +int RGBAToI422(const uint8_t* src_rgba, + int src_stride_rgba, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return ARGBToI422Matrix(src_rgba, src_stride_rgba, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kRgbaI601Constants, width, height); } // Convert ABGR to I420. @@ -1244,94 +3456,9 @@ int ABGRToI420(const uint8_t* src_abgr, int dst_stride_v, int width, int height) { - int y; - void (*ABGRToUVRow)(const uint8_t* src_abgr0, int src_stride_abgr, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ABGRToUVRow_C; - void (*ABGRToYRow)(const uint8_t* src_abgr, uint8_t* dst_y, int width) = - ABGRToYRow_C; - if (!src_abgr || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - src_abgr = src_abgr + (height - 1) * src_stride_abgr; - src_stride_abgr = -src_stride_abgr; - } -#if defined(HAS_ABGRTOYROW_SSSE3) && defined(HAS_ABGRTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ABGRToUVRow = ABGRToUVRow_Any_SSSE3; - ABGRToYRow = ABGRToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ABGRToUVRow = ABGRToUVRow_SSSE3; - ABGRToYRow = ABGRToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ABGRTOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ABGRToYRow = ABGRToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ABGRToYRow = ABGRToYRow_NEON; - } - } -#endif -#if defined(HAS_ABGRTOUVROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ABGRToUVRow = ABGRToUVRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { - ABGRToUVRow = ABGRToUVRow_NEON; - } - } -#endif -#if defined(HAS_ABGRTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ABGRToYRow = ABGRToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ABGRToYRow = ABGRToYRow_MSA; - } - } -#endif -#if defined(HAS_ABGRTOUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ABGRToUVRow = ABGRToUVRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ABGRToUVRow = ABGRToUVRow_MSA; - } - } -#endif -#if defined(HAS_ABGRTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ABGRToYRow = ABGRToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ABGRToYRow = ABGRToYRow_MMI; - } - } -#endif -#if defined(HAS_ABGRTOUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ABGRToUVRow = ABGRToUVRow_Any_MMI; - if (IS_ALIGNED(width, 16)) { - ABGRToUVRow = ABGRToUVRow_MMI; - } - } -#endif - - for (y = 0; y < height - 1; y += 2) { - ABGRToUVRow(src_abgr, src_stride_abgr, dst_u, dst_v, width); - ABGRToYRow(src_abgr, dst_y, width); - ABGRToYRow(src_abgr + src_stride_abgr, dst_y + dst_stride_y, width); - src_abgr += src_stride_abgr * 2; - dst_y += dst_stride_y * 2; - dst_u += dst_stride_u; - dst_v += dst_stride_v; - } - if (height & 1) { - ABGRToUVRow(src_abgr, 0, dst_u, dst_v, width); - ABGRToYRow(src_abgr, dst_y, width); - } - return 0; + return ARGBToI420Matrix(src_abgr, src_stride_abgr, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kAbgrI601Constants, width, height); } // Convert RGBA to I420. @@ -1346,96 +3473,293 @@ int RGBAToI420(const uint8_t* src_rgba, int dst_stride_v, int width, int height) { + return ARGBToI420Matrix(src_rgba, src_stride_rgba, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kRgbaI601Constants, width, height); +} + +static int AR30ToI420Matrix(const uint8_t* src_ar30, + int src_stride_ar30, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + const struct ArgbConstants* argbconstants, + int width, + int height) { int y; - void (*RGBAToUVRow)(const uint8_t* src_rgba0, int src_stride_rgba, - uint8_t* dst_u, uint8_t* dst_v, int width) = - RGBAToUVRow_C; - void (*RGBAToYRow)(const uint8_t* src_rgba, uint8_t* dst_y, int width) = - RGBAToYRow_C; - if (!src_rgba || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + void (*AR30ToARGBRow)(const uint8_t* src_ar30, uint8_t* dst_argb, int width) = + AR30ToARGBRow_C; + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUVMatrixRow)(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + ARGBToUVMatrixRow_C; + if (!src_ar30 || !dst_y || !dst_u || !dst_v || !argbconstants || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgba = src_rgba + (height - 1) * src_stride_rgba; - src_stride_rgba = -src_stride_rgba; + src_ar30 = src_ar30 + (ptrdiff_t)(height - 1) * src_stride_ar30; + src_stride_ar30 = -src_stride_ar30; } -#if defined(HAS_RGBATOYROW_SSSE3) && defined(HAS_RGBATOUVROW_SSSE3) +#if defined(HAS_AR30TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + AR30ToARGBRow = AR30ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + AR30ToARGBRow = AR30ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_AR30TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + AR30ToARGBRow = AR30ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + AR30ToARGBRow = AR30ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_AR30TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + AR30ToARGBRow = AR30ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { - RGBAToUVRow = RGBAToUVRow_Any_SSSE3; - RGBAToYRow = RGBAToYRow_Any_SSSE3; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; if (IS_ALIGNED(width, 16)) { - RGBAToUVRow = RGBAToUVRow_SSSE3; - RGBAToYRow = RGBAToYRow_SSSE3; + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; } } #endif -#if defined(HAS_RGBATOYROW_NEON) +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - RGBAToYRow = RGBAToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - RGBAToYRow = RGBAToYRow_NEON; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; } } #endif -#if defined(HAS_RGBATOUVROW_NEON) +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - RGBAToUVRow = RGBAToUVRow_Any_NEON; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON; if (IS_ALIGNED(width, 16)) { - RGBAToUVRow = RGBAToUVRow_NEON; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON; } } #endif -#if defined(HAS_RGBATOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - RGBAToYRow = RGBAToYRow_Any_MSA; +#if defined(HAS_ARGBTOUVMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON_I8MM; if (IS_ALIGNED(width, 16)) { - RGBAToYRow = RGBAToYRow_MSA; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON_I8MM; } } #endif -#if defined(HAS_RGBATOUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - RGBAToUVRow = RGBAToUVRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - RGBAToUVRow = RGBAToUVRow_MSA; +#if defined(HAS_ARGBTOUVMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SVE2; } } #endif -#if defined(HAS_RGBATOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - RGBAToYRow = RGBAToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - RGBAToYRow = RGBAToYRow_MMI; +#if defined(HAS_ARGBTOUVMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SME; } } #endif -#if defined(HAS_RGBATOUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - RGBAToUVRow = RGBAToUVRow_Any_MMI; +#if defined(HAS_ARGBTOUVMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_WASMSIMD; if (IS_ALIGNED(width, 16)) { - RGBAToUVRow = RGBAToUVRow_MMI; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_WASMSIMD; } } #endif +#if defined(HAS_ARGBTOUVMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_HVX; + } +#endif + int row_stride = width * 4; + align_buffer_64(row, row_stride * 2); + if (!row) { + return -1; + } for (y = 0; y < height - 1; y += 2) { - RGBAToUVRow(src_rgba, src_stride_rgba, dst_u, dst_v, width); - RGBAToYRow(src_rgba, dst_y, width); - RGBAToYRow(src_rgba + src_stride_rgba, dst_y + dst_stride_y, width); - src_rgba += src_stride_rgba * 2; + AR30ToARGBRow(src_ar30, row, width); + AR30ToARGBRow(src_ar30 + src_stride_ar30, row + row_stride, width); + ARGBToUVMatrixRow(row, row_stride, dst_u, dst_v, width, argbconstants); + ARGBToYMatrixRow(row, dst_y, width, argbconstants); + ARGBToYMatrixRow(row + row_stride, dst_y + dst_stride_y, width, + argbconstants); + src_ar30 += src_stride_ar30 * 2; dst_y += dst_stride_y * 2; dst_u += dst_stride_u; dst_v += dst_stride_v; } if (height & 1) { - RGBAToUVRow(src_rgba, 0, dst_u, dst_v, width); - RGBAToYRow(src_rgba, dst_y, width); + AR30ToARGBRow(src_ar30, row, width); + ARGBToUVMatrixRow(row, 0, dst_u, dst_v, width, argbconstants); + ARGBToYMatrixRow(row, dst_y, width, argbconstants); } + free_aligned_buffer_64(row); return 0; } +// Convert AR30 to I420. +LIBYUV_API +int AR30ToI420(const uint8_t* src_ar30, + int src_stride_ar30, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return AR30ToI420Matrix(src_ar30, src_stride_ar30, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kArgbI601Constants, width, height); +} + +// Convert AB30 to I420. +LIBYUV_API +int AB30ToI420(const uint8_t* src_ab30, + int src_stride_ab30, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return AR30ToI420Matrix(src_ab30, src_stride_ab30, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kAbgrI601Constants, width, height); +} + // Convert RGB24 to I420. LIBYUV_API int RGB24ToI420(const uint8_t* src_rgb24, @@ -1449,143 +3773,152 @@ int RGB24ToI420(const uint8_t* src_rgb24, int width, int height) { int y; -#if (defined(HAS_RGB24TOYROW_NEON) || defined(HAS_RGB24TOYROW_MSA) || \ - defined(HAS_RGB24TOYROW_MMI)) - void (*RGB24ToUVRow)(const uint8_t* src_rgb24, int src_stride_rgb24, - uint8_t* dst_u, uint8_t* dst_v, int width) = - RGB24ToUVRow_C; - void (*RGB24ToYRow)(const uint8_t* src_rgb24, uint8_t* dst_y, int width) = - RGB24ToYRow_C; -#else - void (*RGB24ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = - RGB24ToARGBRow_C; - void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVRow_C; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; + void (*RGBToUVMatrixRow)(const uint8_t* src_rgb, int src_stride_rgb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = RGBToUVMatrixRow_C; + void (*RGBToYMatrixRow)(const uint8_t* src_rgb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = RGBToYMatrixRow_C; + +#if defined(HAS_RGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_SSSE3; + } + } #endif - if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { +#if defined(HAS_RGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_RVV; + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RGBToYMatrixRow = RGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_WASMSIMD; + } + } +#endif + + if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; + src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; src_stride_rgb24 = -src_stride_rgb24; } -// Neon version does direct RGB24 to YUV. -#if defined(HAS_RGB24TOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - RGB24ToUVRow = RGB24ToUVRow_Any_NEON; - RGB24ToYRow = RGB24ToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - RGB24ToYRow = RGB24ToYRow_NEON; - if (IS_ALIGNED(width, 16)) { - RGB24ToUVRow = RGB24ToUVRow_NEON; - } - } + for (y = 0; y < height - 1; y += 2) { + RGBToUVMatrixRow(src_rgb24, src_stride_rgb24, dst_u, dst_v, width, + &kArgbI601Constants); + RGBToYMatrixRow(src_rgb24, dst_y, width, &kArgbI601Constants); + RGBToYMatrixRow(src_rgb24 + src_stride_rgb24, dst_y + dst_stride_y, width, + &kArgbI601Constants); + src_rgb24 += src_stride_rgb24 * 2; + dst_y += dst_stride_y * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; } -#elif defined(HAS_RGB24TOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - RGB24ToUVRow = RGB24ToUVRow_Any_MSA; - RGB24ToYRow = RGB24ToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - RGB24ToYRow = RGB24ToYRow_MSA; - RGB24ToUVRow = RGB24ToUVRow_MSA; - } - } -#elif defined(HAS_RGB24TOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - RGB24ToUVRow = RGB24ToUVRow_Any_MMI; - RGB24ToYRow = RGB24ToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - RGB24ToYRow = RGB24ToYRow_MMI; - if (IS_ALIGNED(width, 16)) { - RGB24ToUVRow = RGB24ToUVRow_MMI; - } - } - } -// Other platforms do intermediate conversion from RGB24 to ARGB. -#else -#if defined(HAS_RGB24TOARGBROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - RGB24ToARGBRow = RGB24ToARGBRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - RGB24ToARGBRow = RGB24ToARGBRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVRow = ARGBToUVRow_Any_SSSE3; - ARGBToYRow = ARGBToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_SSSE3; - ARGBToYRow = ARGBToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVRow = ARGBToUVRow_Any_AVX2; - ARGBToYRow = ARGBToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_AVX2; - ARGBToYRow = ARGBToYRow_AVX2; - } - } -#endif -#endif - - { -#if !(defined(HAS_RGB24TOYROW_NEON) || defined(HAS_RGB24TOYROW_MSA) || \ - defined(HAS_RGB24TOYROW_MMI)) - // Allocate 2 rows of ARGB. - const int kRowSize = (width * 4 + 31) & ~31; - align_buffer_64(row, kRowSize * 2); -#endif - - for (y = 0; y < height - 1; y += 2) { -#if (defined(HAS_RGB24TOYROW_NEON) || defined(HAS_RGB24TOYROW_MSA) || \ - defined(HAS_RGB24TOYROW_MMI)) - RGB24ToUVRow(src_rgb24, src_stride_rgb24, dst_u, dst_v, width); - RGB24ToYRow(src_rgb24, dst_y, width); - RGB24ToYRow(src_rgb24 + src_stride_rgb24, dst_y + dst_stride_y, width); -#else - RGB24ToARGBRow(src_rgb24, row, width); - RGB24ToARGBRow(src_rgb24 + src_stride_rgb24, row + kRowSize, width); - ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); - ARGBToYRow(row, dst_y, width); - ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); -#endif - src_rgb24 += src_stride_rgb24 * 2; - dst_y += dst_stride_y * 2; - dst_u += dst_stride_u; - dst_v += dst_stride_v; - } - if (height & 1) { -#if (defined(HAS_RGB24TOYROW_NEON) || defined(HAS_RGB24TOYROW_MSA) || \ - defined(HAS_RGB24TOYROW_MMI)) - RGB24ToUVRow(src_rgb24, 0, dst_u, dst_v, width); - RGB24ToYRow(src_rgb24, dst_y, width); -#else - RGB24ToARGBRow(src_rgb24, row, width); - ARGBToUVRow(row, 0, dst_u, dst_v, width); - ARGBToYRow(row, dst_y, width); -#endif - } -#if !(defined(HAS_RGB24TOYROW_NEON) || defined(HAS_RGB24TOYROW_MSA) || \ - defined(HAS_RGB24TOYROW_MMI)) - free_aligned_buffer_64(row); -#endif + if (height & 1) { + RGBToYMatrixRow(src_rgb24, dst_y, width, &kArgbI601Constants); + RGBToUVMatrixRow(src_rgb24, 0, dst_u, dst_v, width, &kArgbI601Constants); } return 0; } +#undef HAS_RGB24TOYROW -// TODO(fbarchard): Use Matrix version to implement I420 and J420. -// Convert RGB24 to J420. +/// Convert RGB24 to J420. LIBYUV_API int RGB24ToJ420(const uint8_t* src_rgb24, int src_stride_rgb24, @@ -1598,137 +3931,146 @@ int RGB24ToJ420(const uint8_t* src_rgb24, int width, int height) { int y; -#if (defined(HAS_RGB24TOYJROW_NEON) || defined(HAS_RGB24TOYJROW_MSA) || \ - defined(HAS_RGB24TOYJROW_MMI)) - void (*RGB24ToUVJRow)(const uint8_t* src_rgb24, int src_stride_rgb24, - uint8_t* dst_u, uint8_t* dst_v, int width) = - RGB24ToUVJRow_C; - void (*RGB24ToYJRow)(const uint8_t* src_rgb24, uint8_t* dst_y, int width) = - RGB24ToYJRow_C; -#else - void (*RGB24ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = - RGB24ToARGBRow_C; - void (*ARGBToUVJRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVJRow_C; - void (*ARGBToYJRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYJRow_C; + void (*RGBToUVMatrixRow)(const uint8_t* src_rgb, int src_stride_rgb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = RGBToUVMatrixRow_C; + void (*RGBToYMatrixRow)(const uint8_t* src_rgb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = RGBToYMatrixRow_C; + +#if defined(HAS_RGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_SSSE3; + } + } #endif - if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { +#if defined(HAS_RGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_RVV; + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RGBToYMatrixRow = RGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_WASMSIMD; + } + } +#endif + + if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; + src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; src_stride_rgb24 = -src_stride_rgb24; } -// Neon version does direct RGB24 to YUV. -#if defined(HAS_RGB24TOYJROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - RGB24ToUVJRow = RGB24ToUVJRow_Any_NEON; - RGB24ToYJRow = RGB24ToYJRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - RGB24ToYJRow = RGB24ToYJRow_NEON; - if (IS_ALIGNED(width, 16)) { - RGB24ToUVJRow = RGB24ToUVJRow_NEON; - } - } + for (y = 0; y < height - 1; y += 2) { + RGBToUVMatrixRow(src_rgb24, src_stride_rgb24, dst_u, dst_v, width, + &kArgbJPEGConstants); + RGBToYMatrixRow(src_rgb24, dst_y, width, &kArgbJPEGConstants); + RGBToYMatrixRow(src_rgb24 + src_stride_rgb24, dst_y + dst_stride_y, width, + &kArgbJPEGConstants); + src_rgb24 += src_stride_rgb24 * 2; + dst_y += dst_stride_y * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; } -#elif defined(HAS_RGB24TOYJROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - RGB24ToUVJRow = RGB24ToUVJRow_Any_MSA; - RGB24ToYJRow = RGB24ToYJRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - RGB24ToYJRow = RGB24ToYJRow_MSA; - RGB24ToUVJRow = RGB24ToUVJRow_MSA; - } - } -#elif defined(HAS_RGB24TOYJROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - RGB24ToUVJRow = RGB24ToUVJRow_Any_MMI; - RGB24ToYJRow = RGB24ToYJRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - RGB24ToYJRow = RGB24ToYJRow_MMI; - if (IS_ALIGNED(width, 16)) { - RGB24ToUVJRow = RGB24ToUVJRow_MMI; - } - } - } -// Other platforms do intermediate conversion from RGB24 to ARGB. -#else -#if defined(HAS_RGB24TOARGBROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - RGB24ToARGBRow = RGB24ToARGBRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - RGB24ToARGBRow = RGB24ToARGBRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_SSSE3) && defined(HAS_ARGBTOUVJROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVJRow = ARGBToUVJRow_Any_SSSE3; - ARGBToYJRow = ARGBToYJRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVJRow = ARGBToUVJRow_SSSE3; - ARGBToYJRow = ARGBToYJRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_AVX2) && defined(HAS_ARGBTOUVJROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVJRow = ARGBToUVJRow_Any_AVX2; - ARGBToYJRow = ARGBToYJRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToUVJRow = ARGBToUVJRow_AVX2; - ARGBToYJRow = ARGBToYJRow_AVX2; - } - } -#endif -#endif - - { -#if !(defined(HAS_RGB24TOYJROW_NEON) || defined(HAS_RGB24TOYJROW_MSA) || \ - defined(HAS_RGB24TOYJROW_MMI)) - // Allocate 2 rows of ARGB. - const int kRowSize = (width * 4 + 31) & ~31; - align_buffer_64(row, kRowSize * 2); -#endif - - for (y = 0; y < height - 1; y += 2) { -#if (defined(HAS_RGB24TOYJROW_NEON) || defined(HAS_RGB24TOYJROW_MSA) || \ - defined(HAS_RGB24TOYJROW_MMI)) - RGB24ToUVJRow(src_rgb24, src_stride_rgb24, dst_u, dst_v, width); - RGB24ToYJRow(src_rgb24, dst_y, width); - RGB24ToYJRow(src_rgb24 + src_stride_rgb24, dst_y + dst_stride_y, width); -#else - RGB24ToARGBRow(src_rgb24, row, width); - RGB24ToARGBRow(src_rgb24 + src_stride_rgb24, row + kRowSize, width); - ARGBToUVJRow(row, kRowSize, dst_u, dst_v, width); - ARGBToYJRow(row, dst_y, width); - ARGBToYJRow(row + kRowSize, dst_y + dst_stride_y, width); -#endif - src_rgb24 += src_stride_rgb24 * 2; - dst_y += dst_stride_y * 2; - dst_u += dst_stride_u; - dst_v += dst_stride_v; - } - if (height & 1) { -#if (defined(HAS_RGB24TOYJROW_NEON) || defined(HAS_RGB24TOYJROW_MSA) || \ - defined(HAS_RGB24TOYJROW_MMI)) - RGB24ToUVJRow(src_rgb24, 0, dst_u, dst_v, width); - RGB24ToYJRow(src_rgb24, dst_y, width); -#else - RGB24ToARGBRow(src_rgb24, row, width); - ARGBToUVJRow(row, 0, dst_u, dst_v, width); - ARGBToYJRow(row, dst_y, width); -#endif - } -#if !(defined(HAS_RGB24TOYJROW_NEON) || defined(HAS_RGB24TOYJROW_MSA) || \ - defined(HAS_RGB24TOYJROW_MMI)) - free_aligned_buffer_64(row); -#endif + if (height & 1) { + RGBToYMatrixRow(src_rgb24, dst_y, width, &kArgbJPEGConstants); + RGBToUVMatrixRow(src_rgb24, 0, dst_u, dst_v, width, &kArgbJPEGConstants); } return 0; } @@ -1746,139 +4088,471 @@ int RAWToI420(const uint8_t* src_raw, int width, int height) { int y; -#if (defined(HAS_RAWTOYROW_NEON) || defined(HAS_RAWTOYROW_MSA) || \ - defined(HAS_RAWTOYROW_MMI)) - void (*RAWToUVRow)(const uint8_t* src_raw, int src_stride_raw, uint8_t* dst_u, - uint8_t* dst_v, int width) = RAWToUVRow_C; - void (*RAWToYRow)(const uint8_t* src_raw, uint8_t* dst_y, int width) = - RAWToYRow_C; -#else - void (*RAWToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = - RAWToARGBRow_C; - void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVRow_C; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; + void (*RGBToUVMatrixRow)(const uint8_t* src_rgb, int src_stride_rgb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = RGBToUVMatrixRow_C; + void (*RGBToYMatrixRow)(const uint8_t* src_rgb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = RGBToYMatrixRow_C; + +#if defined(HAS_RGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_SSSE3; + } + } #endif - if (!src_raw || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { +#if defined(HAS_RGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_WASMSIMD; + } + } +#endif + + if (!src_raw || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_raw = src_raw + (height - 1) * src_stride_raw; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; src_stride_raw = -src_stride_raw; } -// Neon version does direct RAW to YUV. -#if defined(HAS_RAWTOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - RAWToUVRow = RAWToUVRow_Any_NEON; - RAWToYRow = RAWToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - RAWToYRow = RAWToYRow_NEON; - if (IS_ALIGNED(width, 16)) { - RAWToUVRow = RAWToUVRow_NEON; - } - } + for (y = 0; y < height - 1; y += 2) { + RGBToUVMatrixRow(src_raw, src_stride_raw, dst_u, dst_v, width, + &kAbgrI601Constants); + RGBToYMatrixRow(src_raw, dst_y, width, &kAbgrI601Constants); + RGBToYMatrixRow(src_raw + src_stride_raw, dst_y + dst_stride_y, width, + &kAbgrI601Constants); + src_raw += src_stride_raw * 2; + dst_y += dst_stride_y * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; } -#elif defined(HAS_RAWTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - RAWToUVRow = RAWToUVRow_Any_MSA; - RAWToYRow = RAWToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - RAWToYRow = RAWToYRow_MSA; - RAWToUVRow = RAWToUVRow_MSA; - } - } -#elif defined(HAS_RAWTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - RAWToUVRow = RAWToUVRow_Any_MMI; - RAWToYRow = RAWToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - RAWToYRow = RAWToYRow_MMI; - if (IS_ALIGNED(width, 16)) { - RAWToUVRow = RAWToUVRow_MMI; - } - } - } -// Other platforms do intermediate conversion from RAW to ARGB. -#else -#if defined(HAS_RAWTOARGBROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - RAWToARGBRow = RAWToARGBRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - RAWToARGBRow = RAWToARGBRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVRow = ARGBToUVRow_Any_SSSE3; - ARGBToYRow = ARGBToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_SSSE3; - ARGBToYRow = ARGBToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVRow = ARGBToUVRow_Any_AVX2; - ARGBToYRow = ARGBToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_AVX2; - ARGBToYRow = ARGBToYRow_AVX2; - } - } -#endif -#endif - - { -#if !(defined(HAS_RAWTOYROW_NEON) || defined(HAS_RAWTOYROW_MSA) || \ - defined(HAS_RAWTOYROW_MMI)) - // Allocate 2 rows of ARGB. - const int kRowSize = (width * 4 + 31) & ~31; - align_buffer_64(row, kRowSize * 2); -#endif - - for (y = 0; y < height - 1; y += 2) { -#if (defined(HAS_RAWTOYROW_NEON) || defined(HAS_RAWTOYROW_MSA) || \ - defined(HAS_RAWTOYROW_MMI)) - RAWToUVRow(src_raw, src_stride_raw, dst_u, dst_v, width); - RAWToYRow(src_raw, dst_y, width); - RAWToYRow(src_raw + src_stride_raw, dst_y + dst_stride_y, width); -#else - RAWToARGBRow(src_raw, row, width); - RAWToARGBRow(src_raw + src_stride_raw, row + kRowSize, width); - ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); - ARGBToYRow(row, dst_y, width); - ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); -#endif - src_raw += src_stride_raw * 2; - dst_y += dst_stride_y * 2; - dst_u += dst_stride_u; - dst_v += dst_stride_v; - } - if (height & 1) { -#if (defined(HAS_RAWTOYROW_NEON) || defined(HAS_RAWTOYROW_MSA) || \ - defined(HAS_RAWTOYROW_MMI)) - RAWToUVRow(src_raw, 0, dst_u, dst_v, width); - RAWToYRow(src_raw, dst_y, width); -#else - RAWToARGBRow(src_raw, row, width); - ARGBToUVRow(row, 0, dst_u, dst_v, width); - ARGBToYRow(row, dst_y, width); -#endif - } -#if !(defined(HAS_RAWTOYROW_NEON) || defined(HAS_RAWTOYROW_MSA) || \ - defined(HAS_RAWTOYROW_MMI)) - free_aligned_buffer_64(row); -#endif + if (height & 1) { + RGBToYMatrixRow(src_raw, dst_y, width, &kAbgrI601Constants); + RGBToUVMatrixRow(src_raw, 0, dst_u, dst_v, width, &kAbgrI601Constants); } return 0; } +#undef HAS_RAWTOYROW + +// Convert RAW to J420. +LIBYUV_API +int RAWToJ420(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + int y; + void (*RGBToUVMatrixRow)(const uint8_t* src_rgb, int src_stride_rgb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = RGBToUVMatrixRow_C; + void (*RGBToYMatrixRow)(const uint8_t* src_rgb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = RGBToYMatrixRow_C; + +#if defined(HAS_RGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_WASMSIMD; + } + } +#endif + + if (!src_raw || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; + src_stride_raw = -src_stride_raw; + } + + for (y = 0; y < height - 1; y += 2) { + RGBToUVMatrixRow(src_raw, src_stride_raw, dst_u, dst_v, width, + &kAbgrJPEGConstants); + RGBToYMatrixRow(src_raw, dst_y, width, &kAbgrJPEGConstants); + RGBToYMatrixRow(src_raw + src_stride_raw, dst_y + dst_stride_y, width, + &kAbgrJPEGConstants); + src_raw += src_stride_raw * 2; + dst_y += dst_stride_y * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; + } + if (height & 1) { + RGBToYMatrixRow(src_raw, dst_y, width, &kAbgrJPEGConstants); + RGBToUVMatrixRow(src_raw, 0, dst_u, dst_v, width, &kAbgrJPEGConstants); + } + return 0; +} + +// Convert RAW to I444 with matrix. +static int RAWToI444Matrix(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + const struct ArgbConstants* argbconstants, + int width, + int height) { + int y; + void (*RGBToUV444MatrixRow)( + const uint8_t* src_rgb, uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = RGBToUV444MatrixRow_C; + void (*RGBToYMatrixRow)(const uint8_t* src_rgb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = RGBToYMatrixRow_C; + +#if defined(HAS_RGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RGBToYMatrixRow = RGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_WASMSIMD; + } + } +#endif + +#if defined(HAS_RGBTOUV444MATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToUV444MatrixRow = RGBToUV444MatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToUV444MatrixRow = RGBToUV444MatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_RGBTOUV444MATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToUV444MatrixRow = RGBToUV444MatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToUV444MatrixRow = RGBToUV444MatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOUV444MATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToUV444MatrixRow = RGBToUV444MatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOUV444MATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToUV444MatrixRow = RGBToUV444MatrixRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + RGBToUV444MatrixRow = RGBToUV444MatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOUV444MATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RGBToUV444MatrixRow = RGBToUV444MatrixRow_RVV; + } +#endif +#if defined(HAS_RGBTOUV444MATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToUV444MatrixRow = RGBToUV444MatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToUV444MatrixRow = RGBToUV444MatrixRow_WASMSIMD; + } + } +#endif + + if (!src_raw || !dst_y || !dst_u || !dst_v || !argbconstants || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + if (height < 0) { + height = -height; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; + src_stride_raw = -src_stride_raw; + } + + for (y = 0; y < height; ++y) { + RGBToYMatrixRow(src_raw, dst_y, width, argbconstants); + RGBToUV444MatrixRow(src_raw, dst_u, dst_v, width, argbconstants); + src_raw += src_stride_raw; + dst_y += dst_stride_y; + dst_u += dst_stride_u; + dst_v += dst_stride_v; + } + return 0; +} + +// Convert RAW to I444. +LIBYUV_API +int RAWToI444(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return RAWToI444Matrix(src_raw, src_stride_raw, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, &kAbgrI601Constants, + width, height); +} + +// Convert RAW to J444. +LIBYUV_API +int RAWToJ444(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return RAWToI444Matrix(src_raw, src_stride_raw, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, &kAbgrJPEGConstants, + width, height); +} // Convert RGB565 to I420. LIBYUV_API @@ -1893,147 +4567,92 @@ int RGB565ToI420(const uint8_t* src_rgb565, int width, int height) { int y; -#if (defined(HAS_RGB565TOYROW_NEON) || defined(HAS_RGB565TOYROW_MSA) || \ - defined(HAS_RGB565TOYROW_MMI)) - void (*RGB565ToUVRow)(const uint8_t* src_rgb565, int src_stride_rgb565, - uint8_t* dst_u, uint8_t* dst_v, int width) = - RGB565ToUVRow_C; - void (*RGB565ToYRow)(const uint8_t* src_rgb565, uint8_t* dst_y, int width) = - RGB565ToYRow_C; -#else - void (*RGB565ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, - int width) = RGB565ToARGBRow_C; - void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVRow_C; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; + void (*RGB565ToUVMatrixRow)(const uint8_t* src_rgb565, int src_stride_rgb565, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + RGB565ToUVMatrixRow_C; + void (*RGB565ToYMatrixRow)(const uint8_t* src_rgb565, uint8_t* dst_y, + int width, const struct ArgbConstants* c) = + RGB565ToYMatrixRow_C; + +#if defined(HAS_RGB565TOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGB565ToYMatrixRow = RGB565ToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGB565ToYMatrixRow = RGB565ToYMatrixRow_AVX2; + } + } #endif - if (!src_rgb565 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { +#if defined(HAS_RGB565TOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGB565ToUVMatrixRow = RGB565ToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + RGB565ToUVMatrixRow = RGB565ToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGB565TOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGB565ToUVMatrixRow = RGB565ToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGB565ToUVMatrixRow = RGB565ToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGB565TOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGB565ToYMatrixRow = RGB565ToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGB565ToYMatrixRow = RGB565ToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGB565TOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGB565ToUVMatrixRow = RGB565ToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGB565ToUVMatrixRow = RGB565ToUVMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_RGB565TOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGB565ToYMatrixRow = RGB565ToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGB565ToYMatrixRow = RGB565ToYMatrixRow_WASMSIMD; + } + } +#endif + + if (!src_rgb565 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb565 = src_rgb565 + (height - 1) * src_stride_rgb565; + src_rgb565 = src_rgb565 + (ptrdiff_t)(height - 1) * src_stride_rgb565; src_stride_rgb565 = -src_stride_rgb565; } -// Neon version does direct RGB565 to YUV. -#if defined(HAS_RGB565TOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - RGB565ToUVRow = RGB565ToUVRow_Any_NEON; - RGB565ToYRow = RGB565ToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - RGB565ToYRow = RGB565ToYRow_NEON; - if (IS_ALIGNED(width, 16)) { - RGB565ToUVRow = RGB565ToUVRow_NEON; - } - } + for (y = 0; y < height - 1; y += 2) { + RGB565ToUVMatrixRow(src_rgb565, src_stride_rgb565, dst_u, dst_v, width, + &kArgbI601Constants); + RGB565ToYMatrixRow(src_rgb565, dst_y, width, &kArgbI601Constants); + RGB565ToYMatrixRow(src_rgb565 + src_stride_rgb565, dst_y + dst_stride_y, + width, &kArgbI601Constants); + src_rgb565 += src_stride_rgb565 * 2; + dst_y += dst_stride_y * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; } -#elif defined(HAS_RGB565TOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - RGB565ToUVRow = RGB565ToUVRow_Any_MSA; - RGB565ToYRow = RGB565ToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - RGB565ToYRow = RGB565ToYRow_MSA; - RGB565ToUVRow = RGB565ToUVRow_MSA; - } - } -#elif defined(HAS_RGB565TOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - RGB565ToUVRow = RGB565ToUVRow_Any_MMI; - RGB565ToYRow = RGB565ToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - RGB565ToYRow = RGB565ToYRow_MMI; - if (IS_ALIGNED(width, 16)) { - RGB565ToUVRow = RGB565ToUVRow_MMI; - } - } - } -// Other platforms do intermediate conversion from RGB565 to ARGB. -#else -#if defined(HAS_RGB565TOARGBROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - RGB565ToARGBRow = RGB565ToARGBRow_Any_SSE2; - if (IS_ALIGNED(width, 8)) { - RGB565ToARGBRow = RGB565ToARGBRow_SSE2; - } - } -#endif -#if defined(HAS_RGB565TOARGBROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - RGB565ToARGBRow = RGB565ToARGBRow_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - RGB565ToARGBRow = RGB565ToARGBRow_AVX2; - } - } -#endif -#if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVRow = ARGBToUVRow_Any_SSSE3; - ARGBToYRow = ARGBToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_SSSE3; - ARGBToYRow = ARGBToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVRow = ARGBToUVRow_Any_AVX2; - ARGBToYRow = ARGBToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_AVX2; - ARGBToYRow = ARGBToYRow_AVX2; - } - } -#endif -#endif - { -#if !(defined(HAS_RGB565TOYROW_NEON) || defined(HAS_RGB565TOYROW_MSA) || \ - defined(HAS_RGB565TOYROW_MMI)) - // Allocate 2 rows of ARGB. - const int kRowSize = (width * 4 + 31) & ~31; - align_buffer_64(row, kRowSize * 2); -#endif - for (y = 0; y < height - 1; y += 2) { -#if (defined(HAS_RGB565TOYROW_NEON) || defined(HAS_RGB565TOYROW_MSA) || \ - defined(HAS_RGB565TOYROW_MMI)) - RGB565ToUVRow(src_rgb565, src_stride_rgb565, dst_u, dst_v, width); - RGB565ToYRow(src_rgb565, dst_y, width); - RGB565ToYRow(src_rgb565 + src_stride_rgb565, dst_y + dst_stride_y, width); -#else - RGB565ToARGBRow(src_rgb565, row, width); - RGB565ToARGBRow(src_rgb565 + src_stride_rgb565, row + kRowSize, width); - ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); - ARGBToYRow(row, dst_y, width); - ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); -#endif - src_rgb565 += src_stride_rgb565 * 2; - dst_y += dst_stride_y * 2; - dst_u += dst_stride_u; - dst_v += dst_stride_v; - } - if (height & 1) { -#if (defined(HAS_RGB565TOYROW_NEON) || defined(HAS_RGB565TOYROW_MSA) || \ - defined(HAS_RGB565TOYROW_MMI)) - RGB565ToUVRow(src_rgb565, 0, dst_u, dst_v, width); - RGB565ToYRow(src_rgb565, dst_y, width); -#else - RGB565ToARGBRow(src_rgb565, row, width); - ARGBToUVRow(row, 0, dst_u, dst_v, width); - ARGBToYRow(row, dst_y, width); -#endif - } -#if !(defined(HAS_RGB565TOYROW_NEON) || defined(HAS_RGB565TOYROW_MSA) || \ - defined(HAS_RGB565TOYROW_MMI)) - free_aligned_buffer_64(row); -#endif + if (height & 1) { + RGB565ToYMatrixRow(src_rgb565, dst_y, width, &kArgbI601Constants); + RGB565ToUVMatrixRow(src_rgb565, 0, dst_u, dst_v, width, + &kArgbI601Constants); } return 0; } - // Convert ARGB1555 to I420. LIBYUV_API int ARGB1555ToI420(const uint8_t* src_argb1555, @@ -2047,151 +4666,92 @@ int ARGB1555ToI420(const uint8_t* src_argb1555, int width, int height) { int y; -#if (defined(HAS_ARGB1555TOYROW_NEON) || defined(HAS_ARGB1555TOYROW_MSA) || \ - defined(HAS_ARGB1555TOYROW_MMI)) - void (*ARGB1555ToUVRow)(const uint8_t* src_argb1555, int src_stride_argb1555, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGB1555ToUVRow_C; - void (*ARGB1555ToYRow)(const uint8_t* src_argb1555, uint8_t* dst_y, - int width) = ARGB1555ToYRow_C; -#else - void (*ARGB1555ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, - int width) = ARGB1555ToARGBRow_C; - void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVRow_C; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; + void (*ARGB1555ToUVMatrixRow)( + const uint8_t* src_argb1555, int src_stride_argb1555, uint8_t* dst_u, + uint8_t* dst_v, int width, const struct ArgbConstants* c) = + ARGB1555ToUVMatrixRow_C; + void (*ARGB1555ToYMatrixRow)(const uint8_t* src_argb1555, uint8_t* dst_y, + int width, const struct ArgbConstants* c) = + ARGB1555ToYMatrixRow_C; + +#if defined(HAS_ARGB1555TOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGB1555ToYMatrixRow = ARGB1555ToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGB1555ToYMatrixRow = ARGB1555ToYMatrixRow_AVX2; + } + } #endif +#if defined(HAS_ARGB1555TOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGB1555ToUVMatrixRow = ARGB1555ToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGB1555ToUVMatrixRow = ARGB1555ToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGB1555TOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGB1555ToUVMatrixRow = ARGB1555ToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGB1555ToUVMatrixRow = ARGB1555ToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGB1555TOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGB1555ToYMatrixRow = ARGB1555ToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGB1555ToYMatrixRow = ARGB1555ToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGB1555TOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGB1555ToUVMatrixRow = ARGB1555ToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGB1555ToUVMatrixRow = ARGB1555ToUVMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGB1555TOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGB1555ToYMatrixRow = ARGB1555ToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGB1555ToYMatrixRow = ARGB1555ToYMatrixRow_WASMSIMD; + } + } +#endif + if (!src_argb1555 || !dst_y || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb1555 = src_argb1555 + (height - 1) * src_stride_argb1555; + src_argb1555 = src_argb1555 + (ptrdiff_t)(height - 1) * src_stride_argb1555; src_stride_argb1555 = -src_stride_argb1555; } -// Neon version does direct ARGB1555 to YUV. -#if defined(HAS_ARGB1555TOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGB1555ToUVRow = ARGB1555ToUVRow_Any_NEON; - ARGB1555ToYRow = ARGB1555ToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGB1555ToYRow = ARGB1555ToYRow_NEON; - if (IS_ALIGNED(width, 16)) { - ARGB1555ToUVRow = ARGB1555ToUVRow_NEON; - } - } + for (y = 0; y < height - 1; y += 2) { + ARGB1555ToUVMatrixRow(src_argb1555, src_stride_argb1555, dst_u, dst_v, + width, &kArgbI601Constants); + ARGB1555ToYMatrixRow(src_argb1555, dst_y, width, &kArgbI601Constants); + ARGB1555ToYMatrixRow(src_argb1555 + src_stride_argb1555, + dst_y + dst_stride_y, width, &kArgbI601Constants); + src_argb1555 += src_stride_argb1555 * 2; + dst_y += dst_stride_y * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; } -#elif defined(HAS_ARGB1555TOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGB1555ToUVRow = ARGB1555ToUVRow_Any_MSA; - ARGB1555ToYRow = ARGB1555ToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGB1555ToYRow = ARGB1555ToYRow_MSA; - ARGB1555ToUVRow = ARGB1555ToUVRow_MSA; - } - } -#elif defined(HAS_ARGB1555TOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGB1555ToUVRow = ARGB1555ToUVRow_Any_MMI; - ARGB1555ToYRow = ARGB1555ToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGB1555ToYRow = ARGB1555ToYRow_MMI; - if (IS_ALIGNED(width, 16)) { - ARGB1555ToUVRow = ARGB1555ToUVRow_MMI; - } - } - } -// Other platforms do intermediate conversion from ARGB1555 to ARGB. -#else -#if defined(HAS_ARGB1555TOARGBROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_SSE2; - if (IS_ALIGNED(width, 8)) { - ARGB1555ToARGBRow = ARGB1555ToARGBRow_SSE2; - } - } -#endif -#if defined(HAS_ARGB1555TOARGBROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - ARGB1555ToARGBRow = ARGB1555ToARGBRow_AVX2; - } - } -#endif -#if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVRow = ARGBToUVRow_Any_SSSE3; - ARGBToYRow = ARGBToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_SSSE3; - ARGBToYRow = ARGBToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVRow = ARGBToUVRow_Any_AVX2; - ARGBToYRow = ARGBToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_AVX2; - ARGBToYRow = ARGBToYRow_AVX2; - } - } -#endif -#endif - { -#if !(defined(HAS_ARGB1555TOYROW_NEON) || defined(HAS_ARGB1555TOYROW_MSA) || \ - defined(HAS_ARGB1555TOYROW_MMI)) - // Allocate 2 rows of ARGB. - const int kRowSize = (width * 4 + 31) & ~31; - align_buffer_64(row, kRowSize * 2); -#endif - - for (y = 0; y < height - 1; y += 2) { -#if (defined(HAS_ARGB1555TOYROW_NEON) || defined(HAS_ARGB1555TOYROW_MSA) || \ - defined(HAS_ARGB1555TOYROW_MMI)) - ARGB1555ToUVRow(src_argb1555, src_stride_argb1555, dst_u, dst_v, width); - ARGB1555ToYRow(src_argb1555, dst_y, width); - ARGB1555ToYRow(src_argb1555 + src_stride_argb1555, dst_y + dst_stride_y, - width); -#else - ARGB1555ToARGBRow(src_argb1555, row, width); - ARGB1555ToARGBRow(src_argb1555 + src_stride_argb1555, row + kRowSize, - width); - ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); - ARGBToYRow(row, dst_y, width); - ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); -#endif - src_argb1555 += src_stride_argb1555 * 2; - dst_y += dst_stride_y * 2; - dst_u += dst_stride_u; - dst_v += dst_stride_v; - } - if (height & 1) { -#if (defined(HAS_ARGB1555TOYROW_NEON) || defined(HAS_ARGB1555TOYROW_MSA) || \ - defined(HAS_ARGB1555TOYROW_MMI)) - ARGB1555ToUVRow(src_argb1555, 0, dst_u, dst_v, width); - ARGB1555ToYRow(src_argb1555, dst_y, width); -#else - ARGB1555ToARGBRow(src_argb1555, row, width); - ARGBToUVRow(row, 0, dst_u, dst_v, width); - ARGBToYRow(row, dst_y, width); -#endif - } -#if !(defined(HAS_ARGB1555TOYROW_NEON) || defined(HAS_ARGB1555TOYROW_MSA) || \ - defined(HAS_ARGB1555TOYROW_MMI)) - free_aligned_buffer_64(row); -#endif + if (height & 1) { + ARGB1555ToYMatrixRow(src_argb1555, dst_y, width, &kArgbI601Constants); + ARGB1555ToUVMatrixRow(src_argb1555, 0, dst_u, dst_v, width, + &kArgbI601Constants); } return 0; } - // Convert ARGB4444 to I420. LIBYUV_API int ARGB4444ToI420(const uint8_t* src_argb4444, @@ -2205,170 +4765,92 @@ int ARGB4444ToI420(const uint8_t* src_argb4444, int width, int height) { int y; -#if (defined(HAS_ARGB4444TOYROW_NEON) || defined(HAS_ARGB4444TOYROW_MMI)) - void (*ARGB4444ToUVRow)(const uint8_t* src_argb4444, int src_stride_argb4444, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGB4444ToUVRow_C; - void (*ARGB4444ToYRow)(const uint8_t* src_argb4444, uint8_t* dst_y, - int width) = ARGB4444ToYRow_C; -#else - void (*ARGB4444ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, - int width) = ARGB4444ToARGBRow_C; - void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVRow_C; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; + void (*ARGB4444ToUVMatrixRow)( + const uint8_t* src_argb4444, int src_stride_argb4444, uint8_t* dst_u, + uint8_t* dst_v, int width, const struct ArgbConstants* c) = + ARGB4444ToUVMatrixRow_C; + void (*ARGB4444ToYMatrixRow)(const uint8_t* src_argb4444, uint8_t* dst_y, + int width, const struct ArgbConstants* c) = + ARGB4444ToYMatrixRow_C; + +#if defined(HAS_ARGB4444TOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGB4444ToYMatrixRow = ARGB4444ToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGB4444ToYMatrixRow = ARGB4444ToYMatrixRow_AVX2; + } + } #endif +#if defined(HAS_ARGB4444TOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGB4444ToUVMatrixRow = ARGB4444ToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGB4444ToUVMatrixRow = ARGB4444ToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGB4444TOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGB4444ToUVMatrixRow = ARGB4444ToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGB4444ToUVMatrixRow = ARGB4444ToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGB4444TOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGB4444ToYMatrixRow = ARGB4444ToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGB4444ToYMatrixRow = ARGB4444ToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGB4444TOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGB4444ToUVMatrixRow = ARGB4444ToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGB4444ToUVMatrixRow = ARGB4444ToUVMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGB4444TOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGB4444ToYMatrixRow = ARGB4444ToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGB4444ToYMatrixRow = ARGB4444ToYMatrixRow_WASMSIMD; + } + } +#endif + if (!src_argb4444 || !dst_y || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb4444 = src_argb4444 + (height - 1) * src_stride_argb4444; + src_argb4444 = src_argb4444 + (ptrdiff_t)(height - 1) * src_stride_argb4444; src_stride_argb4444 = -src_stride_argb4444; } -// Neon version does direct ARGB4444 to YUV. -#if defined(HAS_ARGB4444TOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGB4444ToUVRow = ARGB4444ToUVRow_Any_NEON; - ARGB4444ToYRow = ARGB4444ToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGB4444ToYRow = ARGB4444ToYRow_NEON; - if (IS_ALIGNED(width, 16)) { - ARGB4444ToUVRow = ARGB4444ToUVRow_NEON; - } - } + for (y = 0; y < height - 1; y += 2) { + ARGB4444ToUVMatrixRow(src_argb4444, src_stride_argb4444, dst_u, dst_v, + width, &kArgbI601Constants); + ARGB4444ToYMatrixRow(src_argb4444, dst_y, width, &kArgbI601Constants); + ARGB4444ToYMatrixRow(src_argb4444 + src_stride_argb4444, + dst_y + dst_stride_y, width, &kArgbI601Constants); + src_argb4444 += src_stride_argb4444 * 2; + dst_y += dst_stride_y * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; } -#elif defined(HAS_ARGB4444TOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGB4444ToUVRow = ARGB4444ToUVRow_Any_MMI; - ARGB4444ToYRow = ARGB4444ToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGB4444ToYRow = ARGB4444ToYRow_MMI; - if (IS_ALIGNED(width, 16)) { - ARGB4444ToUVRow = ARGB4444ToUVRow_MMI; - } - } - } -// Other platforms do intermediate conversion from ARGB4444 to ARGB. -#else -#if defined(HAS_ARGB4444TOARGBROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_SSE2; - if (IS_ALIGNED(width, 8)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_SSE2; - } - } -#endif -#if defined(HAS_ARGB4444TOARGBROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_AVX2; - } - } -#endif -#if defined(HAS_ARGB4444TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVRow = ARGBToUVRow_Any_SSSE3; - ARGBToYRow = ARGBToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_SSSE3; - ARGBToYRow = ARGBToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVRow = ARGBToUVRow_Any_AVX2; - ARGBToYRow = ARGBToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_AVX2; - ARGBToYRow = ARGBToYRow_AVX2; - } - } -#endif -#if defined(HAS_ARGBTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToUVRow = ARGBToUVRow_Any_MSA; - ARGBToYRow = ARGBToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBToYRow = ARGBToYRow_MSA; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_MSA; - } - } - } -#endif -#if defined(HAS_ARGBTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToUVRow = ARGBToUVRow_Any_MMI; - ARGBToYRow = ARGBToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_MMI; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_MMI; - } - } - } -#endif -#endif - - { -#if !(defined(HAS_ARGB4444TOYROW_NEON) || defined(HAS_ARGB4444TOYROW_MMI)) - // Allocate 2 rows of ARGB. - const int kRowSize = (width * 4 + 31) & ~31; - align_buffer_64(row, kRowSize * 2); -#endif - - for (y = 0; y < height - 1; y += 2) { -#if (defined(HAS_ARGB4444TOYROW_NEON) || defined(HAS_ARGB4444TOYROW_MMI)) - ARGB4444ToUVRow(src_argb4444, src_stride_argb4444, dst_u, dst_v, width); - ARGB4444ToYRow(src_argb4444, dst_y, width); - ARGB4444ToYRow(src_argb4444 + src_stride_argb4444, dst_y + dst_stride_y, - width); -#else - ARGB4444ToARGBRow(src_argb4444, row, width); - ARGB4444ToARGBRow(src_argb4444 + src_stride_argb4444, row + kRowSize, - width); - ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); - ARGBToYRow(row, dst_y, width); - ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); -#endif - src_argb4444 += src_stride_argb4444 * 2; - dst_y += dst_stride_y * 2; - dst_u += dst_stride_u; - dst_v += dst_stride_v; - } - if (height & 1) { -#if (defined(HAS_ARGB4444TOYROW_NEON) || defined(HAS_ARGB4444TOYROW_MMI)) - ARGB4444ToUVRow(src_argb4444, 0, dst_u, dst_v, width); - ARGB4444ToYRow(src_argb4444, dst_y, width); -#else - ARGB4444ToARGBRow(src_argb4444, row, width); - ARGBToUVRow(row, 0, dst_u, dst_v, width); - ARGBToYRow(row, dst_y, width); -#endif - } -#if !(defined(HAS_ARGB4444TOYROW_NEON) || defined(HAS_ARGB4444TOYROW_MMI)) - free_aligned_buffer_64(row); -#endif + if (height & 1) { + ARGB4444ToYMatrixRow(src_argb4444, dst_y, width, &kArgbI601Constants); + ARGB4444ToUVMatrixRow(src_argb4444, 0, dst_u, dst_v, width, + &kArgbI601Constants); } return 0; } - // Convert RGB24 to J400. LIBYUV_API int RGB24ToJ400(const uint8_t* src_rgb24, @@ -2378,125 +4860,199 @@ int RGB24ToJ400(const uint8_t* src_rgb24, int width, int height) { int y; -#if (defined(HAS_RGB24TOYJROW_NEON) || defined(HAS_RGB24TOYJROW_MSA) || \ - defined(HAS_RGB24TOYJROW_MMI)) - void (*RGB24ToYJRow)(const uint8_t* src_rgb24, uint8_t* dst_yj, int width) = - RGB24ToYJRow_C; -#else - void (*RGB24ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = - RGB24ToARGBRow_C; - void (*ARGBToYJRow)(const uint8_t* src_argb, uint8_t* dst_yj, int width) = - ARGBToYJRow_C; -#endif - if (!src_rgb24 || !dst_yj || width <= 0 || height == 0) { + void (*RGBToYMatrixRow)(const uint8_t* src_rgb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = RGBToYMatrixRow_C; + if (!src_rgb24 || !dst_yj || width <= 0 || height == 0 || height == INT_MIN) { return -1; } - // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; + src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; src_stride_rgb24 = -src_stride_rgb24; } + // Coalesce rows. + if (src_stride_rgb24 == width * 3 && dst_stride_yj == width && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_rgb24 = dst_stride_yj = 0; + } -// Neon version does direct RGB24 to YUV. -#if defined(HAS_RGB24TOYJROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - RGB24ToYJRow = RGB24ToYJRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - RGB24ToYJRow = RGB24ToYJRow_NEON; - } - } -#elif defined(HAS_RGB24TOYJROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - RGB24ToYJRow = RGB24ToYJRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - RGB24ToYJRow = RGB24ToYJRow_MSA; - } - } -#elif defined(HAS_RGB24TOYJROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - RGB24ToYJRow = RGB24ToYJRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - RGB24ToYJRow = RGB24ToYJRow_MMI; - } - } -// Other platforms do intermediate conversion from RGB24 to ARGB. -#else -#if defined(HAS_RGB24TOARGBROW_SSSE3) +#if defined(HAS_RGBTOYMATRIXROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { - RGB24ToARGBRow = RGB24ToARGBRow_Any_SSSE3; + RGBToYMatrixRow = RGBToYMatrixRow_Any_SSSE3; if (IS_ALIGNED(width, 16)) { - RGB24ToARGBRow = RGB24ToARGBRow_SSSE3; + RGBToYMatrixRow = RGBToYMatrixRow_SSSE3; } } #endif -#if defined(HAS_ARGBTOYJROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToYJRow = ARGBToYJRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToYJRow = ARGBToYJRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_AVX2) +#if defined(HAS_RGBTOYMATRIXROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToYJRow = ARGBToYJRow_Any_AVX2; + RGBToYMatrixRow = RGBToYMatrixRow_Any_AVX2; if (IS_ALIGNED(width, 32)) { - ARGBToYJRow = ARGBToYJRow_AVX2; + RGBToYMatrixRow = RGBToYMatrixRow_AVX2; } } #endif +#if defined(HAS_RGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RGBToYMatrixRow = RGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_WASMSIMD; + } + } #endif - { -#if !(defined(HAS_RGB24TOYJROW_NEON) || defined(HAS_RGB24TOYJROW_MSA) || \ - defined(HAS_RGB24TOYJROW_MMI)) - // Allocate 2 rows of ARGB. - const int kRowSize = (width * 4 + 31) & ~31; - align_buffer_64(row, kRowSize * 2); -#endif - - for (y = 0; y < height - 1; y += 2) { -#if (defined(HAS_RGB24TOYJROW_NEON) || defined(HAS_RGB24TOYJROW_MSA) || \ - defined(HAS_RGB24TOYJROW_MMI)) - RGB24ToYJRow(src_rgb24, dst_yj, width); - RGB24ToYJRow(src_rgb24 + src_stride_rgb24, dst_yj + dst_stride_yj, width); -#else - RGB24ToARGBRow(src_rgb24, row, width); - RGB24ToARGBRow(src_rgb24 + src_stride_rgb24, row + kRowSize, width); - ARGBToYJRow(row, dst_yj, width); - ARGBToYJRow(row + kRowSize, dst_yj + dst_stride_yj, width); -#endif - src_rgb24 += src_stride_rgb24 * 2; - dst_yj += dst_stride_yj * 2; - } - if (height & 1) { -#if (defined(HAS_RGB24TOYJROW_NEON) || defined(HAS_RGB24TOYJROW_MSA) || \ - defined(HAS_RGB24TOYJROW_MMI)) - RGB24ToYJRow(src_rgb24, dst_yj, width); -#else - RGB24ToARGBRow(src_rgb24, row, width); - ARGBToYJRow(row, dst_yj, width); -#endif - } -#if !(defined(HAS_RGB24TOYJROW_NEON) || defined(HAS_RGB24TOYJROW_MSA) || \ - defined(HAS_RGB24TOYJROW_MMI)) - free_aligned_buffer_64(row); -#endif + for (y = 0; y < height; ++y) { + RGBToYMatrixRow(src_rgb24, dst_yj, width, &kArgbJPEGConstants); + src_rgb24 += src_stride_rgb24; + dst_yj += dst_stride_yj; } return 0; } -static void SplitPixels(const uint8_t* src_u, - int src_pixel_stride_uv, - uint8_t* dst_u, - int width) { - int i; - for (i = 0; i < width; ++i) { - *dst_u = *src_u; - ++dst_u; - src_u += src_pixel_stride_uv; +// Convert RAW to J400. +LIBYUV_API +int RAWToJ400(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_yj, + int dst_stride_yj, + int width, + int height) { + int y; + void (*RGBToYMatrixRow)(const uint8_t* src_rgb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = RGBToYMatrixRow_C; + if (!src_raw || !dst_yj || width <= 0 || height == 0 || height == INT_MIN) { + return -1; } + if (height < 0) { + height = -height; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; + src_stride_raw = -src_stride_raw; + } + // Coalesce rows. + if (src_stride_raw == width * 3 && dst_stride_yj == width && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_raw = dst_stride_yj = 0; + } + +#if defined(HAS_RGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RGBToYMatrixRow = RGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_WASMSIMD; + } + } +#endif + + for (y = 0; y < height; ++y) { + RGBToYMatrixRow(src_raw, dst_yj, width, &kAbgrJPEGConstants); + src_raw += src_stride_raw; + dst_yj += dst_stride_yj; + } + return 0; } // Convert Android420 to I420. @@ -2516,60 +5072,145 @@ int Android420ToI420(const uint8_t* src_y, int dst_stride_v, int width, int height) { - int y; - const ptrdiff_t vu_off = src_v - src_u; - int halfwidth = (width + 1) >> 1; - int halfheight = (height + 1) >> 1; - if (!src_u || !src_v || !dst_u || !dst_v || width <= 0 || height == 0) { + return Android420ToI420Rotate(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, src_pixel_stride_uv, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, + dst_stride_v, width, height, kRotate0); +} + +// depth is source bits measured from lsb; For msb use 16 +static int Biplanar16bitTo8bit(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height, + int subsample_x, + int subsample_y, + int depth) { + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } + int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); + int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); + int scale = 1 << (24 - depth); // Negative height means invert the image. if (height < 0) { height = -height; - halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + uv_height = -uv_height; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_uv = src_uv + (ptrdiff_t)(uv_height - 1) * src_stride_uv; + src_stride_y = -src_stride_y; + src_stride_uv = -src_stride_uv; + } + + // Convert Y plane. + if (dst_y) { + Convert16To8Plane(src_y, src_stride_y, dst_y, dst_stride_y, scale, width, + height); + } + // Convert UV planes. + Convert16To8Plane(src_uv, src_stride_uv, dst_uv, dst_stride_uv, scale, + uv_width * 2, uv_height); + return 0; +} + +// Convert 10 bit P010 to 8 bit NV12. +// Depth set to 16 because P010 uses 10 msb and this function keeps the upper 8 +// bits of the specified number of bits. +LIBYUV_API +int P010ToNV12(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return Biplanar16bitTo8bit(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, + dst_stride_y, dst_uv, dst_stride_uv, width, height, + 1, 1, 16); +} + +static int Planar8bitTo8bit(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + int subsample_x, + int subsample_y, + int scale_y, + int bias_y, + int scale_uv, + int bias_uv) { + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); + int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); + // Negative height means invert the image. + if (height < 0) { + height = -height; + uv_height = -uv_height; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(uv_height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(uv_height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; } + // Convert Y plane. if (dst_y) { - CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); - } - - // Copy UV planes as is - I420 - if (src_pixel_stride_uv == 1) { - CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight); - CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight); - return 0; - // Split UV planes - NV21 - } - if (src_pixel_stride_uv == 2 && vu_off == -1 && - src_stride_u == src_stride_v) { - SplitUVPlane(src_v, src_stride_v, dst_v, dst_stride_v, dst_u, dst_stride_u, - halfwidth, halfheight); - return 0; - // Split UV planes - NV12 - } - if (src_pixel_stride_uv == 2 && vu_off == 1 && src_stride_u == src_stride_v) { - SplitUVPlane(src_u, src_stride_u, dst_u, dst_stride_u, dst_v, dst_stride_v, - halfwidth, halfheight); - return 0; - } - - for (y = 0; y < halfheight; ++y) { - SplitPixels(src_u, src_pixel_stride_uv, dst_u, halfwidth); - SplitPixels(src_v, src_pixel_stride_uv, dst_v, halfwidth); - src_u += src_stride_u; - src_v += src_stride_v; - dst_u += dst_stride_u; - dst_v += dst_stride_v; + Convert8To8Plane(src_y, src_stride_y, dst_y, dst_stride_y, scale_y, bias_y, + width, height); } + // Convert UV planes. + Convert8To8Plane(src_u, src_stride_u, dst_u, dst_stride_u, scale_uv, bias_uv, + uv_width, uv_height); + Convert8To8Plane(src_v, src_stride_v, dst_v, dst_stride_v, scale_uv, bias_uv, + uv_width, uv_height); return 0; } +LIBYUV_API +int J420ToI420(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return Planar8bitTo8bit(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, width, height, 1, + 1, 220, 16, 225, 16); +} + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/source/convert_argb.cc b/libs/libyuv/source/convert_argb.cc index 540503330d..9799e0a791 100644 --- a/libs/libyuv/source/convert_argb.cc +++ b/libs/libyuv/source/convert_argb.cc @@ -10,13 +10,16 @@ #include "libyuv/convert_argb.h" +#include +#include +#include // For memcpy. + +#include "libyuv/convert_from_argb.h" #include "libyuv/cpu_id.h" -#ifdef HAVE_JPEG -#include "libyuv/mjpeg_decoder.h" -#endif #include "libyuv/planar_functions.h" // For CopyPlane and ARGBShuffle. #include "libyuv/rotate_argb.h" #include "libyuv/row.h" +#include "libyuv/scale_row.h" // For ScaleRowUp2_Linear and ScaleRowUp2_Bilinear #include "libyuv/video_common.h" #ifdef __cplusplus @@ -32,13 +35,14 @@ int ARGBCopy(const uint8_t* src_argb, int dst_stride_argb, int width, int height) { - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } @@ -47,30 +51,33 @@ int ARGBCopy(const uint8_t* src_argb, return 0; } -// Convert I420 to ARGB with matrix -static int I420ToARGBMatrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_argb, - int dst_stride_argb, - const struct YuvConstants* yuvconstants, - int width, - int height) { +// Convert I420 to ARGB with matrix. +LIBYUV_API +int I420ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = I422ToARGBRow_C; - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I422TOARGBROW_SSSE3) @@ -89,6 +96,12 @@ static int I420ToARGBMatrix(const uint8_t* src_y, } } #endif +#if defined(HAS_I422TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == + (kCpuHasAVX512BW | kCpuHasAVX512VL)) { + I422ToARGBRow = I422ToARGBRow_AVX512BW; + } +#endif #if defined(HAS_I422TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { I422ToARGBRow = I422ToARGBRow_Any_NEON; @@ -97,14 +110,50 @@ static int I420ToARGBMatrix(const uint8_t* src_y, } } #endif -#if defined(HAS_I422TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToARGBRow = I422ToARGBRow_Any_MSA; +#if defined(HAS_I422TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToARGBRow = I422ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I422TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToARGBRow = I422ToARGBRow_SME; + } +#endif +#if defined(HAS_I422TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToARGBRow = I422ToARGBRow_Any_LSX; if (IS_ALIGNED(width, 8)) { - I422ToARGBRow = I422ToARGBRow_MSA; + I422ToARGBRow = I422ToARGBRow_LSX; } } #endif +#if defined(HAS_I422TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToARGBRow = I422ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422ToARGBRow = I422ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_I422TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I422ToARGBRow = I422ToARGBRow_RVV; + } +#endif +#if defined(HAS_I422TOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + I422ToARGBRow = I422ToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + I422ToARGBRow = I422ToARGBRow_WASMSIMD; + } + } +#endif +#if defined(HAS_I422TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I422ToARGBRow = I422ToARGBRow_HVX; + } +#endif for (y = 0; y < height; ++y) { I422ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); @@ -226,35 +275,75 @@ int H420ToABGR(const uint8_t* src_y, width, height); } -// Convert I422 to ARGB with matrix -static int I422ToARGBMatrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_argb, - int dst_stride_argb, - const struct YuvConstants* yuvconstants, - int width, - int height) { +// Convert U420 to ARGB. +LIBYUV_API +int U420ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + &kYuv2020Constants, width, height); +} + +// Convert U420 to ABGR. +LIBYUV_API +int U420ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return I420ToARGBMatrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_abgr, dst_stride_abgr, + &kYvu2020Constants, // Use Yvu matrix + width, height); +} + +// Convert I422 to ARGB with matrix. +LIBYUV_API +int I422ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = I422ToARGBRow_C; - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. if (src_stride_y == width && src_stride_u * 2 == width && - src_stride_v * 2 == width && dst_stride_argb == width * 4) { + src_stride_v * 2 == width && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = src_stride_u = src_stride_v = dst_stride_argb = 0; @@ -275,6 +364,12 @@ static int I422ToARGBMatrix(const uint8_t* src_y, } } #endif +#if defined(HAS_I422TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == + (kCpuHasAVX512BW | kCpuHasAVX512VL)) { + I422ToARGBRow = I422ToARGBRow_AVX512BW; + } +#endif #if defined(HAS_I422TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { I422ToARGBRow = I422ToARGBRow_Any_NEON; @@ -283,14 +378,50 @@ static int I422ToARGBMatrix(const uint8_t* src_y, } } #endif -#if defined(HAS_I422TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToARGBRow = I422ToARGBRow_Any_MSA; +#if defined(HAS_I422TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToARGBRow = I422ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I422TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToARGBRow = I422ToARGBRow_SME; + } +#endif +#if defined(HAS_I422TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToARGBRow = I422ToARGBRow_Any_LSX; if (IS_ALIGNED(width, 8)) { - I422ToARGBRow = I422ToARGBRow_MSA; + I422ToARGBRow = I422ToARGBRow_LSX; } } #endif +#if defined(HAS_I422TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToARGBRow = I422ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422ToARGBRow = I422ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_I422TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I422ToARGBRow = I422ToARGBRow_RVV; + } +#endif +#if defined(HAS_I422TOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + I422ToARGBRow = I422ToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + I422ToARGBRow = I422ToARGBRow_WASMSIMD; + } + } +#endif +#if defined(HAS_I422TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I422ToARGBRow = I422ToARGBRow_HVX; + } +#endif for (y = 0; y < height; ++y) { I422ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); @@ -410,34 +541,474 @@ int H422ToABGR(const uint8_t* src_y, width, height); } -// Convert 10 bit YUV to ARGB with matrix -// TODO(fbarchard): Consider passing scale multiplier to I210ToARGB to -// multiply 10 bit yuv into high bits to allow any number of bits. -static int I010ToAR30Matrix(const uint16_t* src_y, - int src_stride_y, - const uint16_t* src_u, - int src_stride_u, - const uint16_t* src_v, - int src_stride_v, - uint8_t* dst_ar30, - int dst_stride_ar30, - const struct YuvConstants* yuvconstants, - int width, - int height) { +// Convert U422 to ARGB. +LIBYUV_API +int U422ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + &kYuv2020Constants, width, height); +} + +// Convert U422 to ABGR. +LIBYUV_API +int U422ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return I422ToARGBMatrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_abgr, dst_stride_abgr, + &kYvu2020Constants, // Use Yvu matrix + width, height); +} + +// Convert I444 to ARGB with matrix. +LIBYUV_API +int I444ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; - void (*I210ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, - const uint16_t* v_buf, uint8_t* rgb_buf, + void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = - I210ToAR30Row_C; - if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) { + I444ToARGBRow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } + // Coalesce rows. + if (src_stride_y == width && src_stride_u == width && src_stride_v == width && + dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = src_stride_u = src_stride_v = dst_stride_argb = 0; + } +#if defined(HAS_I444TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I444ToARGBRow = I444ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I444TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I444ToARGBRow = I444ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I444ToARGBRow = I444ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I444TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I444ToARGBRow = I444ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_I444TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I444ToARGBRow = I444ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I444TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I444ToARGBRow = I444ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I444TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I444ToARGBRow = I444ToARGBRow_SME; + } +#endif +#if defined(HAS_I444TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I444ToARGBRow = I444ToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_LSX; + } + } +#endif +#if defined(HAS_I444TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I444ToARGBRow = I444ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I444ToARGBRow = I444ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_I444TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I444ToARGBRow = I444ToARGBRow_RVV; + } +#endif +#if defined(HAS_I444TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I444ToARGBRow = I444ToARGBRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + I444ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + +// Convert I444 to ARGB. +LIBYUV_API +int I444ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + &kYuvI601Constants, width, height); +} + +// Convert I444 to ABGR. +LIBYUV_API +int I444ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return I444ToARGBMatrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_abgr, dst_stride_abgr, + &kYvuI601Constants, // Use Yvu matrix + width, height); +} + +// Convert J444 to ARGB. +LIBYUV_API +int J444ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + &kYuvJPEGConstants, width, height); +} + +// Convert J444 to ABGR. +LIBYUV_API +int J444ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return I444ToARGBMatrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_abgr, dst_stride_abgr, + &kYvuJPEGConstants, // Use Yvu matrix + width, height); +} + +// Convert H444 to ARGB. +LIBYUV_API +int H444ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + &kYuvH709Constants, width, height); +} + +// Convert H444 to ABGR. +LIBYUV_API +int H444ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return I444ToARGBMatrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_abgr, dst_stride_abgr, + &kYvuH709Constants, // Use Yvu matrix + width, height); +} + +// Convert U444 to ARGB. +LIBYUV_API +int U444ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + &kYuv2020Constants, width, height); +} + +// Convert U444 to ABGR. +LIBYUV_API +int U444ToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return I444ToARGBMatrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_abgr, dst_stride_abgr, + &kYvu2020Constants, // Use Yvu matrix + width, height); +} + +// Convert I444 to RGB24 with matrix. +LIBYUV_API +int I444ToRGB24Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I444ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I444ToRGB24Row_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; + dst_stride_rgb24 = -dst_stride_rgb24; + } + // Coalesce rows. + if (src_stride_y == width && src_stride_u == width && src_stride_v == width && + dst_stride_rgb24 == width * 3 && (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = src_stride_u = src_stride_v = dst_stride_rgb24 = 0; + } +#if defined(HAS_I444TORGB24ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I444ToRGB24Row = I444ToRGB24Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I444ToRGB24Row = I444ToRGB24Row_SSSE3; + } + } +#endif +#if defined(HAS_I444TORGB24ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I444ToRGB24Row = I444ToRGB24Row_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + I444ToRGB24Row = I444ToRGB24Row_AVX2; + } + } +#endif +#if defined(HAS_I444TORGB24ROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI)) { + I444ToRGB24Row = I444ToRGB24Row_AVX512VBMI; + } +#endif +#if defined(HAS_I444TORGB24ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I444ToRGB24Row = I444ToRGB24Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I444ToRGB24Row = I444ToRGB24Row_NEON; + } + } +#endif +#if defined(HAS_I444TORGB24ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I444ToRGB24Row = I444ToRGB24Row_SVE2; + } +#endif +#if defined(HAS_I444TORGB24ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I444ToRGB24Row = I444ToRGB24Row_SME; + } +#endif +#if defined(HAS_I444TORGB24ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I444ToRGB24Row = I444ToRGB24Row_RVV; + } +#endif + + for (y = 0; y < height; ++y) { + I444ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width); + dst_rgb24 += dst_stride_rgb24; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + +// Convert I444 to RGB24. +LIBYUV_API +int I444ToRGB24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height) { + return I444ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgb24, dst_stride_rgb24, + &kYuvI601Constants, width, height); +} + +// Convert I444 to RAW. +LIBYUV_API +int I444ToRAW(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_raw, + int dst_stride_raw, + int width, + int height) { + return I444ToRGB24Matrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_raw, dst_stride_raw, + &kYvuI601Constants, // Use Yvu matrix + width, height); +} + +// Convert 10 bit YUV to ARGB with matrix. +// TODO(fbarchard): Consider passing scale multiplier to I210ToARGB to +// multiply 10 bit yuv into high bits to allow any number of bits. +LIBYUV_API +int I010ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I210ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I210ToAR30Row_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } +#if defined(HAS_I210TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I210ToAR30Row = I210ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I210ToAR30Row = I210ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_I210TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I210ToAR30Row = I210ToAR30Row_SVE2; + } +#endif +#if defined(HAS_I210TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I210ToAR30Row = I210ToAR30Row_SME; + } +#endif #if defined(HAS_I210TOAR30ROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { I210ToAR30Row = I210ToAR30Row_Any_SSSE3; @@ -453,6 +1024,11 @@ static int I010ToAR30Matrix(const uint16_t* src_y, I210ToAR30Row = I210ToAR30Row_AVX2; } } +#endif +#if defined(HAS_I210TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I210ToAR30Row = I210ToAR30Row_AVX512BW; + } #endif for (y = 0; y < height; ++y) { I210ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); @@ -500,6 +1076,23 @@ int H010ToAR30(const uint16_t* src_y, &kYuvH709Constants, width, height); } +// Convert U010 to AR30. +LIBYUV_API +int U010ToAR30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height) { + return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_ar30, dst_stride_ar30, + &kYuv2020Constants, width, height); +} + // Convert I010 to AB30. LIBYUV_API int I010ToAB30(const uint16_t* src_y, @@ -534,30 +1127,391 @@ int H010ToAB30(const uint16_t* src_y, &kYvuH709Constants, width, height); } -// Convert 10 bit YUV to ARGB with matrix -static int I010ToARGBMatrix(const uint16_t* src_y, - int src_stride_y, - const uint16_t* src_u, - int src_stride_u, - const uint16_t* src_v, - int src_stride_v, - uint8_t* dst_argb, - int dst_stride_argb, - const struct YuvConstants* yuvconstants, - int width, - int height) { +// Convert U010 to AB30. +LIBYUV_API +int U010ToAB30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height) { + return I010ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, + src_stride_u, dst_ab30, dst_stride_ab30, + &kYuv2020Constants, width, height); +} + +// Convert 12 bit YUV to ARGB with matrix. +// TODO(fbarchard): Consider passing scale multiplier to I212ToARGB to +// multiply 12 bit yuv into high bits to allow any number of bits. +LIBYUV_API +int I012ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; - void (*I210ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + void (*I212ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, const uint16_t* v_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = - I210ToARGBRow_C; - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + I212ToAR30Row_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } +#if defined(HAS_I212TOAR30ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I212ToAR30Row = I212ToAR30Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I212ToAR30Row = I212ToAR30Row_SSSE3; + } + } +#endif +#if defined(HAS_I212TOAR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I212ToAR30Row = I212ToAR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I212ToAR30Row = I212ToAR30Row_AVX2; + } + } +#endif +#if defined(HAS_I212TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I212ToAR30Row = I212ToAR30Row_AVX512BW; + } +#endif +#if defined(HAS_I212TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I212ToAR30Row = I212ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I212ToAR30Row = I212ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_I212TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I212ToAR30Row = I212ToAR30Row_SVE2; + } +#endif +#if defined(HAS_I212TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I212ToAR30Row = I212ToAR30Row_SME; + } +#endif + for (y = 0; y < height; ++y) { + I212ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + if (y & 1) { + src_u += src_stride_u; + src_v += src_stride_v; + } + } + return 0; +} + +// Convert 10 bit YUV to ARGB with matrix. +// TODO(fbarchard): Consider passing scale multiplier to I210ToARGB to +// multiply 10 bit yuv into high bits to allow any number of bits. +LIBYUV_API +int I210ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I210ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I210ToAR30Row_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } +#if defined(HAS_I210TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I210ToAR30Row = I210ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I210ToAR30Row = I210ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_I210TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I210ToAR30Row = I210ToAR30Row_SVE2; + } +#endif +#if defined(HAS_I210TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I210ToAR30Row = I210ToAR30Row_SME; + } +#endif +#if defined(HAS_I210TOAR30ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I210ToAR30Row = I210ToAR30Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I210ToAR30Row = I210ToAR30Row_SSSE3; + } + } +#endif +#if defined(HAS_I210TOAR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I210ToAR30Row = I210ToAR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I210ToAR30Row = I210ToAR30Row_AVX2; + } + } +#endif +#if defined(HAS_I210TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I210ToAR30Row = I210ToAR30Row_AVX512BW; + } +#endif + for (y = 0; y < height; ++y) { + I210ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + +// Convert I210 to AR30. +LIBYUV_API +int I210ToAR30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height) { + return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_ar30, dst_stride_ar30, + &kYuvI601Constants, width, height); +} + +// Convert H210 to AR30. +LIBYUV_API +int H210ToAR30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height) { + return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_ar30, dst_stride_ar30, + &kYuvH709Constants, width, height); +} + +// Convert U210 to AR30. +LIBYUV_API +int U210ToAR30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height) { + return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_ar30, dst_stride_ar30, + &kYuv2020Constants, width, height); +} + +// Convert I210 to AB30. +LIBYUV_API +int I210ToAB30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height) { + return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, + src_stride_u, dst_ab30, dst_stride_ab30, + &kYvuI601Constants, width, height); +} + +// Convert H210 to AB30. +LIBYUV_API +int H210ToAB30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height) { + return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, + src_stride_u, dst_ab30, dst_stride_ab30, + &kYvuH709Constants, width, height); +} + +// Convert U210 to AB30. +LIBYUV_API +int U210ToAB30(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height) { + return I210ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, + src_stride_u, dst_ab30, dst_stride_ab30, + &kYuv2020Constants, width, height); +} + +LIBYUV_API +int I410ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I410ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I410ToAR30Row_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } +#if defined(HAS_I410TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I410ToAR30Row = I410ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I410ToAR30Row = I410ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_I410TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410ToAR30Row = I410ToAR30Row_SVE2; + } +#endif +#if defined(HAS_I410TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I410ToAR30Row = I410ToAR30Row_SME; + } +#endif +#if defined(HAS_I410TOAR30ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I410ToAR30Row = I410ToAR30Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I410ToAR30Row = I410ToAR30Row_SSSE3; + } + } +#endif +#if defined(HAS_I410TOAR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I410ToAR30Row = I410ToAR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I410ToAR30Row = I410ToAR30Row_AVX2; + } + } +#endif +#if defined(HAS_I410TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I410ToAR30Row = I410ToAR30Row_AVX512BW; + } +#endif + for (y = 0; y < height; ++y) { + I410ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + +// Convert 10 bit YUV to ARGB with matrix. +LIBYUV_API +int I010ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I210ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I210ToARGBRow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I210TOARGBROW_SSSE3) @@ -568,6 +1522,24 @@ static int I010ToARGBMatrix(const uint16_t* src_y, } } #endif +#if defined(HAS_I210TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I210ToARGBRow = I210ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I210ToARGBRow = I210ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I210TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I210ToARGBRow = I210ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I210TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I210ToARGBRow = I210ToARGBRow_SME; + } +#endif #if defined(HAS_I210TOARGBROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { I210ToARGBRow = I210ToARGBRow_Any_AVX2; @@ -575,6 +1547,11 @@ static int I010ToARGBMatrix(const uint16_t* src_y, I210ToARGBRow = I210ToARGBRow_AVX2; } } +#endif +#if defined(HAS_I210TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I210ToARGBRow = I210ToARGBRow_AVX512BW; + } #endif for (y = 0; y < height; ++y) { I210ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); @@ -660,74 +1637,200 @@ int H010ToABGR(const uint16_t* src_y, width, height); } -// Convert I444 to ARGB with matrix -static int I444ToARGBMatrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_argb, - int dst_stride_argb, - const struct YuvConstants* yuvconstants, - int width, - int height) { +// Convert U010 to ARGB. +LIBYUV_API +int U010ToARGB(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + &kYuv2020Constants, width, height); +} + +// Convert U010 to ABGR. +LIBYUV_API +int U010ToABGR(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return I010ToARGBMatrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_abgr, dst_stride_abgr, + &kYvu2020Constants, // Use Yvu matrix + width, height); +} + +// Convert 12 bit YUV to ARGB with matrix. +LIBYUV_API +int I012ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; - void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, - const uint8_t* v_buf, uint8_t* rgb_buf, + void (*I212ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = - I444ToARGBRow_C; - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + I212ToARGBRow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I212TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I212ToARGBRow = I212ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I212ToARGBRow = I212ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I212TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I212ToARGBRow = I212ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I212ToARGBRow = I212ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I212TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I212ToARGBRow = I212ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_I212TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I212ToARGBRow = I212ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I212ToARGBRow = I212ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I212TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I212ToARGBRow = I212ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I212TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I212ToARGBRow = I212ToARGBRow_SME; + } +#endif + for (y = 0; y < height; ++y) { + I212ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + if (y & 1) { + src_u += src_stride_u; + src_v += src_stride_v; + } + } + return 0; +} + +// Convert 10 bit 422 YUV to ARGB with matrix. +LIBYUV_API +int I210ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I210ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I210ToARGBRow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. - if (src_stride_y == width && src_stride_u == width && src_stride_v == width && - dst_stride_argb == width * 4) { + if (src_stride_y == width && src_stride_u * 2 == width && + src_stride_v * 2 == width && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = src_stride_u = src_stride_v = dst_stride_argb = 0; } -#if defined(HAS_I444TOARGBROW_SSSE3) +#if defined(HAS_I210TOARGBROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { - I444ToARGBRow = I444ToARGBRow_Any_SSSE3; + I210ToARGBRow = I210ToARGBRow_Any_SSSE3; if (IS_ALIGNED(width, 8)) { - I444ToARGBRow = I444ToARGBRow_SSSE3; + I210ToARGBRow = I210ToARGBRow_SSSE3; } } #endif -#if defined(HAS_I444TOARGBROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - I444ToARGBRow = I444ToARGBRow_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - I444ToARGBRow = I444ToARGBRow_AVX2; - } - } -#endif -#if defined(HAS_I444TOARGBROW_NEON) +#if defined(HAS_I210TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - I444ToARGBRow = I444ToARGBRow_Any_NEON; + I210ToARGBRow = I210ToARGBRow_Any_NEON; if (IS_ALIGNED(width, 8)) { - I444ToARGBRow = I444ToARGBRow_NEON; + I210ToARGBRow = I210ToARGBRow_NEON; } } #endif -#if defined(HAS_I444TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I444ToARGBRow = I444ToARGBRow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - I444ToARGBRow = I444ToARGBRow_MSA; +#if defined(HAS_I210TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I210ToARGBRow = I210ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I210TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I210ToARGBRow = I210ToARGBRow_SME; + } +#endif +#if defined(HAS_I210TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I210ToARGBRow = I210ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I210ToARGBRow = I210ToARGBRow_AVX2; } } #endif - +#if defined(HAS_I210TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I210ToARGBRow = I210ToARGBRow_AVX512BW; + } +#endif for (y = 0; y < height; ++y) { - I444ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); + I210ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); dst_argb += dst_stride_argb; src_y += src_stride_y; src_u += src_stride_u; @@ -736,74 +1839,656 @@ static int I444ToARGBMatrix(const uint8_t* src_y, return 0; } -// Convert I444 to ARGB. +// Convert I210 to ARGB. LIBYUV_API -int I444ToARGB(const uint8_t* src_y, +int I210ToARGB(const uint16_t* src_y, int src_stride_y, - const uint8_t* src_u, + const uint16_t* src_u, int src_stride_u, - const uint8_t* src_v, + const uint16_t* src_v, int src_stride_v, uint8_t* dst_argb, int dst_stride_argb, int width, int height) { - return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, dst_argb, dst_stride_argb, &kYuvI601Constants, width, height); } -// Convert I444 to ABGR. +// Convert I210 to ABGR. LIBYUV_API -int I444ToABGR(const uint8_t* src_y, +int I210ToABGR(const uint16_t* src_y, int src_stride_y, - const uint8_t* src_u, + const uint16_t* src_u, int src_stride_u, - const uint8_t* src_v, + const uint16_t* src_v, int src_stride_v, uint8_t* dst_abgr, int dst_stride_abgr, int width, int height) { - return I444ToARGBMatrix(src_y, src_stride_y, src_v, + return I210ToARGBMatrix(src_y, src_stride_y, src_v, src_stride_v, // Swap U and V src_u, src_stride_u, dst_abgr, dst_stride_abgr, &kYvuI601Constants, // Use Yvu matrix width, height); } -// Convert J444 to ARGB. +// Convert H210 to ARGB. LIBYUV_API -int J444ToARGB(const uint8_t* src_y, +int H210ToARGB(const uint16_t* src_y, int src_stride_y, - const uint8_t* src_u, + const uint16_t* src_u, int src_stride_u, - const uint8_t* src_v, + const uint16_t* src_v, int src_stride_v, uint8_t* dst_argb, int dst_stride_argb, int width, int height) { - return I444ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, dst_argb, dst_stride_argb, - &kYuvJPEGConstants, width, height); + &kYuvH709Constants, width, height); } -// Convert I420 with Alpha to preattenuated ARGB. -static int I420AlphaToARGBMatrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - const uint8_t* src_a, - int src_stride_a, - uint8_t* dst_argb, - int dst_stride_argb, - const struct YuvConstants* yuvconstants, - int width, - int height, - int attenuate) { +// Convert H210 to ABGR. +LIBYUV_API +int H210ToABGR(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return I210ToARGBMatrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_abgr, dst_stride_abgr, + &kYvuH709Constants, // Use Yvu matrix + width, height); +} + +// Convert U210 to ARGB. +LIBYUV_API +int U210ToARGB(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + &kYuv2020Constants, width, height); +} + +// Convert U210 to ABGR. +LIBYUV_API +int U210ToABGR(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + return I210ToARGBMatrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_abgr, dst_stride_abgr, + &kYvu2020Constants, // Use Yvu matrix + width, height); +} + +LIBYUV_API +int I410ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I410ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I410ToARGBRow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } + // Coalesce rows. + if (src_stride_y == width && src_stride_u == width && src_stride_v == width && + dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = src_stride_u = src_stride_v = dst_stride_argb = 0; + } +#if defined(HAS_I410TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I410ToARGBRow = I410ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I410ToARGBRow = I410ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I410TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I410ToARGBRow = I410ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I410ToARGBRow = I410ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I410TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410ToARGBRow = I410ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I410TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I410ToARGBRow = I410ToARGBRow_SME; + } +#endif +#if defined(HAS_I410TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I410ToARGBRow = I410ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I410ToARGBRow = I410ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I410TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I410ToARGBRow = I410ToARGBRow_AVX512BW; + } +#endif + for (y = 0; y < height; ++y) { + I410ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + +LIBYUV_API +int P010ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*P210ToARGBRow)( + const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = P210ToARGBRow_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_P210TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + P210ToARGBRow = P210ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + P210ToARGBRow = P210ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_P210TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + P210ToARGBRow = P210ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + P210ToARGBRow = P210ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_P210TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + P210ToARGBRow = P210ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_P210TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + P210ToARGBRow = P210ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + P210ToARGBRow = P210ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_P210TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + P210ToARGBRow = P210ToARGBRow_SVE2; + } +#endif +#if defined(HAS_P210TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + P210ToARGBRow = P210ToARGBRow_SME; + } +#endif + for (y = 0; y < height; ++y) { + P210ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + if (y & 1) { + src_uv += src_stride_uv; + } + } + return 0; +} + +LIBYUV_API +int P210ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*P210ToARGBRow)( + const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = P210ToARGBRow_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_P210TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + P210ToARGBRow = P210ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + P210ToARGBRow = P210ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_P210TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + P210ToARGBRow = P210ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + P210ToARGBRow = P210ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_P210TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + P210ToARGBRow = P210ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_P210TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + P210ToARGBRow = P210ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + P210ToARGBRow = P210ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_P210TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + P210ToARGBRow = P210ToARGBRow_SVE2; + } +#endif +#if defined(HAS_P210TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + P210ToARGBRow = P210ToARGBRow_SME; + } +#endif + for (y = 0; y < height; ++y) { + P210ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_uv += src_stride_uv; + } + return 0; +} + +LIBYUV_API +int P410ToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*P410ToARGBRow)( + const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = P410ToARGBRow_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_P410TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + P410ToARGBRow = P410ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + P410ToARGBRow = P410ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_P410TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + P410ToARGBRow = P410ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + P410ToARGBRow = P410ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_P410TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + P410ToARGBRow = P410ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_P410TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + P410ToARGBRow = P410ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + P410ToARGBRow = P410ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_P410TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + P410ToARGBRow = P410ToARGBRow_SVE2; + } +#endif +#if defined(HAS_P410TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + P410ToARGBRow = P410ToARGBRow_SME; + } +#endif + for (y = 0; y < height; ++y) { + P410ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_uv += src_stride_uv; + } + return 0; +} + +LIBYUV_API +int P010ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*P210ToAR30Row)( + const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = P210ToAR30Row_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } +#if defined(HAS_P210TOAR30ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + P210ToAR30Row = P210ToAR30Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + P210ToAR30Row = P210ToAR30Row_SSSE3; + } + } +#endif +#if defined(HAS_P210TOAR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + P210ToAR30Row = P210ToAR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + P210ToAR30Row = P210ToAR30Row_AVX2; + } + } +#endif +#if defined(HAS_P210TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + P210ToAR30Row = P210ToAR30Row_AVX512BW; + } +#endif +#if defined(HAS_P210TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + P210ToAR30Row = P210ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + P210ToAR30Row = P210ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_P210TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + P210ToAR30Row = P210ToAR30Row_SVE2; + } +#endif +#if defined(HAS_P210TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + P210ToAR30Row = P210ToAR30Row_SME; + } +#endif + for (y = 0; y < height; ++y) { + P210ToAR30Row(src_y, src_uv, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + if (y & 1) { + src_uv += src_stride_uv; + } + } + return 0; +} + +LIBYUV_API +int P210ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*P210ToAR30Row)( + const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = P210ToAR30Row_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } +#if defined(HAS_P210TOAR30ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + P210ToAR30Row = P210ToAR30Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + P210ToAR30Row = P210ToAR30Row_SSSE3; + } + } +#endif +#if defined(HAS_P210TOAR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + P210ToAR30Row = P210ToAR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + P210ToAR30Row = P210ToAR30Row_AVX2; + } + } +#endif +#if defined(HAS_P210TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + P210ToAR30Row = P210ToAR30Row_AVX512BW; + } +#endif +#if defined(HAS_P210TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + P210ToAR30Row = P210ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + P210ToAR30Row = P210ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_P210TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + P210ToAR30Row = P210ToAR30Row_SVE2; + } +#endif +#if defined(HAS_P210TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + P210ToAR30Row = P210ToAR30Row_SME; + } +#endif + for (y = 0; y < height; ++y) { + P210ToAR30Row(src_y, src_uv, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + src_uv += src_stride_uv; + } + return 0; +} + +LIBYUV_API +int P410ToAR30Matrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*P410ToAR30Row)( + const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = P410ToAR30Row_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } +#if defined(HAS_P410TOAR30ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + P410ToAR30Row = P410ToAR30Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + P410ToAR30Row = P410ToAR30Row_SSSE3; + } + } +#endif +#if defined(HAS_P410TOAR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + P410ToAR30Row = P410ToAR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + P410ToAR30Row = P410ToAR30Row_AVX2; + } + } +#endif +#if defined(HAS_P410TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + P410ToAR30Row = P410ToAR30Row_AVX512BW; + } +#endif +#if defined(HAS_P410TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + P410ToAR30Row = P410ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + P410ToAR30Row = P410ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_P410TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + P410ToAR30Row = P410ToAR30Row_SVE2; + } +#endif +#if defined(HAS_P410TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + P410ToAR30Row = P410ToAR30Row_SME; + } +#endif + for (y = 0; y < height; ++y) { + P410ToAR30Row(src_y, src_uv, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + src_uv += src_stride_uv; + } + return 0; +} + +// Convert I420 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I420AlphaToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate) { int y; void (*I422AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, const uint8_t* a_buf, @@ -812,13 +2497,15 @@ static int I420AlphaToARGBMatrix(const uint8_t* src_y, int width) = I422AlphaToARGBRow_C; void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width) = ARGBAttenuateRow_C; - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I422ALPHATOARGBROW_SSSE3) @@ -837,6 +2524,11 @@ static int I420AlphaToARGBMatrix(const uint8_t* src_y, } } #endif +#if defined(HAS_I422ALPHATOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_AVX512BW; + } +#endif #if defined(HAS_I422ALPHATOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { I422AlphaToARGBRow = I422AlphaToARGBRow_Any_NEON; @@ -845,14 +2537,42 @@ static int I420AlphaToARGBMatrix(const uint8_t* src_y, } } #endif -#if defined(HAS_I422ALPHATOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422AlphaToARGBRow = I422AlphaToARGBRow_Any_MSA; +#if defined(HAS_I422ALPHATOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_SVE2; + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_SME; + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LSX; if (IS_ALIGNED(width, 8)) { - I422AlphaToARGBRow = I422AlphaToARGBRow_MSA; + I422AlphaToARGBRow = I422AlphaToARGBRow_LSX; } } #endif +#if defined(HAS_I422ALPHATOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_LASX; + } + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_RVV; + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_HVX; + } +#endif #if defined(HAS_ARGBATTENUATEROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; @@ -869,6 +2589,11 @@ static int I420AlphaToARGBMatrix(const uint8_t* src_y, } } #endif +#if defined(HAS_ARGBATTENUATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX512BW; + } +#endif #if defined(HAS_ARGBATTENUATEROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; @@ -877,22 +2602,32 @@ static int I420AlphaToARGBMatrix(const uint8_t* src_y, } } #endif -#if defined(HAS_ARGBATTENUATEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - ARGBAttenuateRow = ARGBAttenuateRow_MSA; +#if defined(HAS_ARGBATTENUATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAttenuateRow = ARGBAttenuateRow_RVV; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_LSX; } } #endif -#if defined(HAS_ARGBATTENUATEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBAttenuateRow = ARGBAttenuateRow_Any_MMI; - if (IS_ALIGNED(width, 2)) { - ARGBAttenuateRow = ARGBAttenuateRow_MMI; +#if defined(HAS_ARGBATTENUATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_LASX; } } #endif +#if defined(HAS_ARGBATTENUATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAttenuateRow = ARGBAttenuateRow_HVX; + } +#endif for (y = 0; y < height; ++y) { I422AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, @@ -911,6 +2646,350 @@ static int I420AlphaToARGBMatrix(const uint8_t* src_y, return 0; } +// Convert I422 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I422AlphaToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate) { + int y; + void (*I422AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) = I422AlphaToARGBRow_C; + void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, + int width) = ARGBAttenuateRow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } + // Coalesce rows. + if (src_stride_y == width && src_stride_u * 2 == width && + src_stride_v * 2 == width && src_stride_a == width && + dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = src_stride_u = src_stride_v = src_stride_a = + dst_stride_argb = 0; + } +#if defined(HAS_I422ALPHATOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_SVE2; + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_SME; + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_LSX; + } + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_LASX; + } + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_RVV; + } +#endif +#if defined(HAS_I422ALPHATOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I422AlphaToARGBRow = I422AlphaToARGBRow_HVX; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_NEON; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAttenuateRow = ARGBAttenuateRow_RVV; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_LSX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_LASX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAttenuateRow = ARGBAttenuateRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + I422AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_a += src_stride_a; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + +// Convert I444 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I444AlphaToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate) { + int y; + void (*I444AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) = I444AlphaToARGBRow_C; + void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, + int width) = ARGBAttenuateRow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } + // Coalesce rows. + if (src_stride_y == width && src_stride_u == width && src_stride_v == width && + src_stride_a == width && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = src_stride_u = src_stride_v = src_stride_a = + dst_stride_argb = 0; + } +#if defined(HAS_I444ALPHATOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_SVE2; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_SME; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_RVV; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_HVX; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_NEON; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAttenuateRow = ARGBAttenuateRow_RVV; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_LSX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_LASX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAttenuateRow = ARGBAttenuateRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + I444AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_a += src_stride_a; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + // Convert I420 with Alpha to ARGB. LIBYUV_API int I420AlphaToARGB(const uint8_t* src_y, @@ -954,28 +3033,555 @@ int I420AlphaToABGR(const uint8_t* src_y, width, height, attenuate); } -// Convert I400 to ARGB. +// Convert I422 with Alpha to ARGB. LIBYUV_API -int I400ToARGB(const uint8_t* src_y, - int src_stride_y, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height) { +int I422AlphaToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height, + int attenuate) { + return I422AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, src_a, src_stride_a, dst_argb, + dst_stride_argb, &kYuvI601Constants, width, + height, attenuate); +} + +// Convert I422 with Alpha to ABGR. +LIBYUV_API +int I422AlphaToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height, + int attenuate) { + return I422AlphaToARGBMatrix( + src_y, src_stride_y, src_v, src_stride_v, // Swap U and V + src_u, src_stride_u, src_a, src_stride_a, dst_abgr, dst_stride_abgr, + &kYvuI601Constants, // Use Yvu matrix + width, height, attenuate); +} + +// Convert I444 with Alpha to ARGB. +LIBYUV_API +int I444AlphaToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height, + int attenuate) { + return I444AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, src_a, src_stride_a, dst_argb, + dst_stride_argb, &kYuvI601Constants, width, + height, attenuate); +} + +// Convert I444 with Alpha to ABGR. +LIBYUV_API +int I444AlphaToABGR(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height, + int attenuate) { + return I444AlphaToARGBMatrix( + src_y, src_stride_y, src_v, src_stride_v, // Swap U and V + src_u, src_stride_u, src_a, src_stride_a, dst_abgr, dst_stride_abgr, + &kYvuI601Constants, // Use Yvu matrix + width, height, attenuate); +} + +// Convert I010 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I010AlphaToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate) { int y; - void (*I400ToARGBRow)(const uint8_t* y_buf, uint8_t* rgb_buf, int width) = - I400ToARGBRow_C; - if (!src_y || !dst_argb || width <= 0 || height == 0) { + void (*I210AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) = I210AlphaToARGBRow_C; + void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, + int width) = ARGBAttenuateRow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I210ALPHATOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I210ALPHATOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_SVE2; + } +#endif +#if defined(HAS_I210ALPHATOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_SME; + } +#endif +#if defined(HAS_I210ALPHATOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I210ALPHATOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I210ALPHATOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_NEON; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAttenuateRow = ARGBAttenuateRow_RVV; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_LSX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_LASX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAttenuateRow = ARGBAttenuateRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + I210AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_a += src_stride_a; + src_y += src_stride_y; + if (y & 1) { + src_u += src_stride_u; + src_v += src_stride_v; + } + } + return 0; +} + +// Convert I210 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I210AlphaToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate) { + int y; + void (*I210AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) = I210AlphaToARGBRow_C; + void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, + int width) = ARGBAttenuateRow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I210ALPHATOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I210ALPHATOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_SVE2; + } +#endif +#if defined(HAS_I210ALPHATOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_SME; + } +#endif +#if defined(HAS_I210ALPHATOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I210ALPHATOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I210ALPHATOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I210AlphaToARGBRow = I210AlphaToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_NEON; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAttenuateRow = ARGBAttenuateRow_RVV; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_LSX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_LASX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAttenuateRow = ARGBAttenuateRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + I210AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_a += src_stride_a; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + +// Convert I410 with Alpha to preattenuated ARGB with matrix. +LIBYUV_API +int I410AlphaToARGBMatrix(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate) { + int y; + void (*I410AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) = I410AlphaToARGBRow_C; + void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, + int width) = ARGBAttenuateRow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I410ALPHATOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_SVE2; + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_SME; + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_NEON; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAttenuateRow = ARGBAttenuateRow_RVV; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_LSX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_LASX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAttenuateRow = ARGBAttenuateRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + I410AlphaToARGBRow(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_a += src_stride_a; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + +// Convert I400 to ARGB with matrix. +LIBYUV_API +int I400ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I400ToARGBRow)(const uint8_t* y_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I400ToARGBRow_C; + assert(yuvconstants); + if (!src_y || !dst_argb || width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. - if (src_stride_y == width && dst_stride_argb == width * 4) { + if (src_stride_y == width && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = dst_stride_argb = 0; @@ -996,6 +3602,11 @@ int I400ToARGB(const uint8_t* src_y, } } #endif +#if defined(HAS_I400TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I400ToARGBRow = I400ToARGBRow_AVX512BW; + } +#endif #if defined(HAS_I400TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { I400ToARGBRow = I400ToARGBRow_Any_NEON; @@ -1004,31 +3615,63 @@ int I400ToARGB(const uint8_t* src_y, } } #endif -#if defined(HAS_I400TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I400ToARGBRow = I400ToARGBRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - I400ToARGBRow = I400ToARGBRow_MSA; +#if defined(HAS_I400TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I400ToARGBRow = I400ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I400TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I400ToARGBRow = I400ToARGBRow_SME; + } +#endif +#if defined(HAS_I400TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I400ToARGBRow = I400ToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I400ToARGBRow = I400ToARGBRow_LSX; } } #endif -#if defined(HAS_I400TOARGBROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - I400ToARGBRow = I400ToARGBRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - I400ToARGBRow = I400ToARGBRow_MMI; +#if defined(HAS_I400TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I400ToARGBRow = I400ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I400ToARGBRow = I400ToARGBRow_LASX; } } #endif +#if defined(HAS_I400TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I400ToARGBRow = I400ToARGBRow_RVV; + } +#endif +#if defined(HAS_I400TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I400ToARGBRow = I400ToARGBRow_HVX; + } +#endif for (y = 0; y < height; ++y) { - I400ToARGBRow(src_y, dst_argb, width); + I400ToARGBRow(src_y, dst_argb, yuvconstants, width); dst_argb += dst_stride_argb; src_y += src_stride_y; } return 0; } +// Convert I400 to ARGB. +LIBYUV_API +int I400ToARGB(const uint8_t* src_y, + int src_stride_y, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return I400ToARGBMatrix(src_y, src_stride_y, dst_argb, dst_stride_argb, + &kYuvI601Constants, width, height); +} + // Convert J400 to ARGB. LIBYUV_API int J400ToARGB(const uint8_t* src_y, @@ -1040,29 +3683,23 @@ int J400ToARGB(const uint8_t* src_y, int y; void (*J400ToARGBRow)(const uint8_t* src_y, uint8_t* dst_argb, int width) = J400ToARGBRow_C; - if (!src_y || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !dst_argb || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } // Coalesce rows. - if (src_stride_y == width && dst_stride_argb == width * 4) { + if (src_stride_y == width && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = dst_stride_argb = 0; } -#if defined(HAS_J400TOARGBROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - J400ToARGBRow = J400ToARGBRow_Any_SSE2; - if (IS_ALIGNED(width, 8)) { - J400ToARGBRow = J400ToARGBRow_SSE2; - } - } -#endif + #if defined(HAS_J400TOARGBROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { J400ToARGBRow = J400ToARGBRow_Any_AVX2; @@ -1071,6 +3708,11 @@ int J400ToARGB(const uint8_t* src_y, } } #endif +#if defined(HAS_J400TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + J400ToARGBRow = J400ToARGBRow_AVX512BW; + } +#endif #if defined(HAS_J400TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { J400ToARGBRow = J400ToARGBRow_Any_NEON; @@ -1079,22 +3721,41 @@ int J400ToARGB(const uint8_t* src_y, } } #endif -#if defined(HAS_J400TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - J400ToARGBRow = J400ToARGBRow_Any_MSA; +#if defined(HAS_J400TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + J400ToARGBRow = J400ToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + J400ToARGBRow = J400ToARGBRow_LSX; + } + } +#endif +#if defined(HAS_J400TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + J400ToARGBRow = J400ToARGBRow_Any_LASX; if (IS_ALIGNED(width, 16)) { - J400ToARGBRow = J400ToARGBRow_MSA; + J400ToARGBRow = J400ToARGBRow_LASX; } } #endif -#if defined(HAS_J400TOARGBROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - J400ToARGBRow = J400ToARGBRow_Any_MMI; - if (IS_ALIGNED(width, 4)) { - J400ToARGBRow = J400ToARGBRow_MMI; +#if defined(HAS_J400TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + J400ToARGBRow = J400ToARGBRow_RVV; + } +#endif +#if defined(HAS_J400TOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + J400ToARGBRow = J400ToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + J400ToARGBRow = J400ToARGBRow_WASMSIMD; } } #endif +#if defined(HAS_J400TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + J400ToARGBRow = J400ToARGBRow_HVX; + } +#endif + for (y = 0; y < height; ++y) { J400ToARGBRow(src_y, dst_argb, width); src_y += src_stride_y; @@ -1103,6 +3764,7 @@ int J400ToARGB(const uint8_t* src_y, return 0; } +#if !defined(__riscv) && !defined(__hexagon__) // Shuffle table for converting BGRA to ARGB. static const uvec8 kShuffleMaskBGRAToARGB = { 3u, 2u, 1u, 0u, 7u, 6u, 5u, 4u, 11u, 10u, 9u, 8u, 15u, 14u, 13u, 12u}; @@ -1115,6 +3777,10 @@ static const uvec8 kShuffleMaskABGRToARGB = { static const uvec8 kShuffleMaskRGBAToARGB = { 1u, 2u, 3u, 0u, 5u, 6u, 7u, 4u, 9u, 10u, 11u, 8u, 13u, 14u, 15u, 12u}; +// Shuffle table for converting AR64 to AB64. +static const uvec8 kShuffleMaskAR64ToAB64 = { + 4u, 5u, 2u, 3u, 0u, 1u, 6u, 7u, 12u, 13u, 10u, 11u, 8u, 9u, 14u, 15u}; + // Convert BGRA to ARGB. LIBYUV_API int BGRAToARGB(const uint8_t* src_bgra, @@ -1124,19 +3790,19 @@ int BGRAToARGB(const uint8_t* src_bgra, int width, int height) { return ARGBShuffle(src_bgra, src_stride_bgra, dst_argb, dst_stride_argb, - (const uint8_t*)(&kShuffleMaskBGRAToARGB), width, height); + (const uint8_t*)&kShuffleMaskBGRAToARGB, width, height); } // Convert ARGB to BGRA (same as BGRAToARGB). LIBYUV_API -int ARGBToBGRA(const uint8_t* src_bgra, - int src_stride_bgra, - uint8_t* dst_argb, - int dst_stride_argb, +int ARGBToBGRA(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_bgra, + int dst_stride_bgra, int width, int height) { - return ARGBShuffle(src_bgra, src_stride_bgra, dst_argb, dst_stride_argb, - (const uint8_t*)(&kShuffleMaskBGRAToARGB), width, height); + return ARGBShuffle(src_argb, src_stride_argb, dst_bgra, dst_stride_bgra, + (const uint8_t*)&kShuffleMaskBGRAToARGB, width, height); } // Convert ABGR to ARGB. @@ -1148,19 +3814,19 @@ int ABGRToARGB(const uint8_t* src_abgr, int width, int height) { return ARGBShuffle(src_abgr, src_stride_abgr, dst_argb, dst_stride_argb, - (const uint8_t*)(&kShuffleMaskABGRToARGB), width, height); + (const uint8_t*)&kShuffleMaskABGRToARGB, width, height); } // Convert ARGB to ABGR to (same as ABGRToARGB). LIBYUV_API -int ARGBToABGR(const uint8_t* src_abgr, - int src_stride_abgr, - uint8_t* dst_argb, - int dst_stride_argb, +int ARGBToABGR(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_abgr, + int dst_stride_abgr, int width, int height) { - return ARGBShuffle(src_abgr, src_stride_abgr, dst_argb, dst_stride_argb, - (const uint8_t*)(&kShuffleMaskABGRToARGB), width, height); + return ARGBShuffle(src_argb, src_stride_argb, dst_abgr, dst_stride_abgr, + (const uint8_t*)&kShuffleMaskABGRToARGB, width, height); } // Convert RGBA to ARGB. @@ -1172,9 +3838,238 @@ int RGBAToARGB(const uint8_t* src_rgba, int width, int height) { return ARGBShuffle(src_rgba, src_stride_rgba, dst_argb, dst_stride_argb, - (const uint8_t*)(&kShuffleMaskRGBAToARGB), width, height); + (const uint8_t*)&kShuffleMaskRGBAToARGB, width, height); } +// Convert AR64 To AB64. +LIBYUV_API +int AR64ToAB64(const uint16_t* src_ar64, + int src_stride_ar64, + uint16_t* dst_ab64, + int dst_stride_ab64, + int width, + int height) { + return AR64Shuffle(src_ar64, src_stride_ar64, dst_ab64, dst_stride_ab64, + (const uint8_t*)&kShuffleMaskAR64ToAB64, width, height); +} +#else +// Convert BGRA to ARGB (same as ARGBToBGRA). +LIBYUV_API +int BGRAToARGB(const uint8_t* src_bgra, + int src_stride_bgra, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return ARGBToBGRA(src_bgra, src_stride_bgra, dst_argb, dst_stride_argb, width, + height); +} + +// Convert ARGB to BGRA. +LIBYUV_API +int ARGBToBGRA(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_bgra, + int dst_stride_bgra, + int width, + int height) { + int y; + void (*ARGBToBGRARow)(const uint8_t* src_argb, uint8_t* dst_bgra, int width) = + ARGBToBGRARow_C; + if (!src_argb || !dst_bgra || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } + // Coalesce rows. + if (src_stride_argb == width * 4 && dst_stride_bgra == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_argb = dst_stride_bgra = 0; + } + +#if defined(HAS_ARGBTOBGRAROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToBGRARow = ARGBToBGRARow_RVV; + } +#endif +#if defined(HAS_ARGBTOBGRAROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToBGRARow = ARGBToBGRARow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + ARGBToBGRARow(src_argb, dst_bgra, width); + src_argb += src_stride_argb; + dst_bgra += dst_stride_bgra; + } + return 0; +} + +// Convert ARGB to ABGR. +LIBYUV_API +int ARGBToABGR(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_abgr, + int dst_stride_abgr, + int width, + int height) { + int y; + void (*ARGBToABGRRow)(const uint8_t* src_argb, uint8_t* dst_abgr, int width) = + ARGBToABGRRow_C; + if (!src_argb || !dst_abgr || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } + // Coalesce rows. + if (src_stride_argb == width * 4 && dst_stride_abgr == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_argb = dst_stride_abgr = 0; + } + +#if defined(HAS_ARGBTOABGRROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToABGRRow = ARGBToABGRRow_RVV; + } +#endif +#if defined(HAS_ARGBTOABGRROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToABGRRow = ARGBToABGRRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + ARGBToABGRRow(src_argb, dst_abgr, width); + src_argb += src_stride_argb; + dst_abgr += dst_stride_abgr; + } + return 0; +} + +// Convert ABGR to ARGB (same as ARGBToABGR). +LIBYUV_API +int ABGRToARGB(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return ARGBToABGR(src_abgr, src_stride_abgr, dst_argb, dst_stride_argb, width, + height); +} + +// Convert RGBA to ARGB. +LIBYUV_API +int RGBAToARGB(const uint8_t* src_rgba, + int src_stride_rgba, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + int y; + void (*RGBAToARGBRow)(const uint8_t* src_rgba, uint8_t* dst_argb, int width) = + RGBAToARGBRow_C; + if (!src_rgba || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_rgba = src_rgba + (ptrdiff_t)(height - 1) * src_stride_rgba; + src_stride_rgba = -src_stride_rgba; + } + // Coalesce rows. + if (src_stride_rgba == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_rgba = dst_stride_argb = 0; + } + +#if defined(HAS_RGBATOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RGBAToARGBRow = RGBAToARGBRow_RVV; + } +#endif +#if defined(HAS_RGBATOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + RGBAToARGBRow = RGBAToARGBRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + RGBAToARGBRow(src_rgba, dst_argb, width); + src_rgba += src_stride_rgba; + dst_argb += dst_stride_argb; + } + return 0; +} + +// Convert AR64 To AB64. +LIBYUV_API +int AR64ToAB64(const uint16_t* src_ar64, + int src_stride_ar64, + uint16_t* dst_ab64, + int dst_stride_ab64, + int width, + int height) { + int y; + void (*AR64ToAB64Row)(const uint16_t* src_ar64, uint16_t* dst_ab64, + int width) = AR64ToAB64Row_C; + if (!src_ar64 || !dst_ab64 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_ar64 = src_ar64 + (ptrdiff_t)(height - 1) * src_stride_ar64; + src_stride_ar64 = -src_stride_ar64; + } + // Coalesce rows. + if (src_stride_ar64 == width * 4 && dst_stride_ab64 == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_ar64 = dst_stride_ab64 = 0; + } + +#if defined(HAS_AR64TOAB64ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + AR64ToAB64Row = AR64ToAB64Row_RVV; + } +#endif +#if defined(HAS_AR64TOAB64ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + AR64ToAB64Row = AR64ToAB64Row_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + AR64ToAB64Row(src_ar64, dst_ab64, width); + src_ar64 += src_stride_ar64; + dst_ab64 += dst_stride_ab64; + } + return 0; +} +#endif + // Convert RGB24 to ARGB. LIBYUV_API int RGB24ToARGB(const uint8_t* src_rgb24, @@ -1186,17 +4081,19 @@ int RGB24ToARGB(const uint8_t* src_rgb24, int y; void (*RGB24ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = RGB24ToARGBRow_C; - if (!src_rgb24 || !dst_argb || width <= 0 || height == 0) { + if (!src_rgb24 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; + src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; src_stride_rgb24 = -src_stride_rgb24; } // Coalesce rows. - if (src_stride_rgb24 == width * 3 && dst_stride_argb == width * 4) { + if (src_stride_rgb24 == width * 3 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_rgb24 = dst_stride_argb = 0; @@ -1209,6 +4106,19 @@ int RGB24ToARGB(const uint8_t* src_rgb24, } } #endif +#if defined(HAS_RGB24TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGB24ToARGBRow = RGB24ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGB24ToARGBRow = RGB24ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_RGB24TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGB24ToARGBRow = RGB24ToARGBRow_AVX512BW; + } +#endif #if defined(HAS_RGB24TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { RGB24ToARGBRow = RGB24ToARGBRow_Any_NEON; @@ -1217,23 +4127,40 @@ int RGB24ToARGB(const uint8_t* src_rgb24, } } #endif -#if defined(HAS_RGB24TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - RGB24ToARGBRow = RGB24ToARGBRow_Any_MSA; +#if defined(HAS_RGB24TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + RGB24ToARGBRow = RGB24ToARGBRow_SVE2; + } +#endif +#if defined(HAS_RGB24TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RGB24ToARGBRow = RGB24ToARGBRow_Any_LSX; if (IS_ALIGNED(width, 16)) { - RGB24ToARGBRow = RGB24ToARGBRow_MSA; + RGB24ToARGBRow = RGB24ToARGBRow_LSX; } } #endif -#if defined(HAS_RGB24TOARGBROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - RGB24ToARGBRow = RGB24ToARGBRow_Any_MMI; - if (IS_ALIGNED(width, 4)) { - RGB24ToARGBRow = RGB24ToARGBRow_MMI; +#if defined(HAS_RGB24TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RGB24ToARGBRow = RGB24ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + RGB24ToARGBRow = RGB24ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_RGB24TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RGB24ToARGBRow = RGB24ToARGBRow_RVV; + } +#endif +#if defined(HAS_RGB24TOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGB24ToARGBRow = RGB24ToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGB24ToARGBRow = RGB24ToARGBRow_WASMSIMD; } } #endif - for (y = 0; y < height; ++y) { RGB24ToARGBRow(src_rgb24, dst_argb, width); src_rgb24 += src_stride_rgb24; @@ -1253,17 +4180,18 @@ int RAWToARGB(const uint8_t* src_raw, int y; void (*RAWToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = RAWToARGBRow_C; - if (!src_raw || !dst_argb || width <= 0 || height == 0) { + if (!src_raw || !dst_argb || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_raw = src_raw + (height - 1) * src_stride_raw; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; src_stride_raw = -src_stride_raw; } // Coalesce rows. - if (src_stride_raw == width * 3 && dst_stride_argb == width * 4) { + if (src_stride_raw == width * 3 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_raw = dst_stride_argb = 0; @@ -1276,6 +4204,19 @@ int RAWToARGB(const uint8_t* src_raw, } } #endif +#if defined(HAS_RAWTOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RAWToARGBRow = RAWToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RAWToARGBRow = RAWToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_RAWTOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RAWToARGBRow = RAWToARGBRow_AVX512BW; + } +#endif #if defined(HAS_RAWTOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { RAWToARGBRow = RAWToARGBRow_Any_NEON; @@ -1284,19 +4225,37 @@ int RAWToARGB(const uint8_t* src_raw, } } #endif -#if defined(HAS_RAWTOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - RAWToARGBRow = RAWToARGBRow_Any_MSA; +#if defined(HAS_RAWTOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + RAWToARGBRow = RAWToARGBRow_SVE2; + } +#endif +#if defined(HAS_RAWTOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RAWToARGBRow = RAWToARGBRow_Any_LSX; if (IS_ALIGNED(width, 16)) { - RAWToARGBRow = RAWToARGBRow_MSA; + RAWToARGBRow = RAWToARGBRow_LSX; } } #endif -#if defined(HAS_RAWTOARGBROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - RAWToARGBRow = RAWToARGBRow_Any_MMI; - if (IS_ALIGNED(width, 4)) { - RAWToARGBRow = RAWToARGBRow_MMI; +#if defined(HAS_RAWTOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RAWToARGBRow = RAWToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + RAWToARGBRow = RAWToARGBRow_LASX; + } + } +#endif +#if defined(HAS_RAWTOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RAWToARGBRow = RAWToARGBRow_RVV; + } +#endif +#if defined(HAS_RAWTOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RAWToARGBRow = RAWToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RAWToARGBRow = RAWToARGBRow_WASMSIMD; } } #endif @@ -1309,6 +4268,74 @@ int RAWToARGB(const uint8_t* src_raw, return 0; } +// Convert RAW to RGBA. +LIBYUV_API +int RAWToRGBA(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_rgba, + int dst_stride_rgba, + int width, + int height) { + int y; + void (*RAWToRGBARow)(const uint8_t* src_rgb, uint8_t* dst_rgba, int width) = + RAWToRGBARow_C; + if (!src_raw || !dst_rgba || width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; + src_stride_raw = -src_stride_raw; + } + // Coalesce rows. + if (src_stride_raw == width * 3 && dst_stride_rgba == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_raw = dst_stride_rgba = 0; + } +#if defined(HAS_RAWTORGBAROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RAWToRGBARow = RAWToRGBARow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + RAWToRGBARow = RAWToRGBARow_AVX2; + } + } +#endif +#if defined(HAS_RAWTORGBAROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI | kCpuHasAVX512VL) == + (kCpuHasAVX512VBMI | kCpuHasAVX512VL)) { + RAWToRGBARow = RAWToRGBARow_AVX512VBMI; + } +#endif +#if defined(HAS_RAWTORGBAROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RAWToRGBARow = RAWToRGBARow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + RAWToRGBARow = RAWToRGBARow_NEON; + } + } +#endif +#if defined(HAS_RAWTORGBAROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + RAWToRGBARow = RAWToRGBARow_SVE2; + } +#endif +#if defined(HAS_RAWTORGBAROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RAWToRGBARow = RAWToRGBARow_RVV; + } +#endif + + for (y = 0; y < height; ++y) { + RAWToRGBARow(src_raw, dst_rgba, width); + src_raw += src_stride_raw; + dst_rgba += dst_stride_rgba; + } + return 0; +} + // Convert RGB565 to ARGB. LIBYUV_API int RGB565ToARGB(const uint8_t* src_rgb565, @@ -1320,29 +4347,24 @@ int RGB565ToARGB(const uint8_t* src_rgb565, int y; void (*RGB565ToARGBRow)(const uint8_t* src_rgb565, uint8_t* dst_argb, int width) = RGB565ToARGBRow_C; - if (!src_rgb565 || !dst_argb || width <= 0 || height == 0) { + if (!src_rgb565 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb565 = src_rgb565 + (height - 1) * src_stride_rgb565; + src_rgb565 = src_rgb565 + (ptrdiff_t)(height - 1) * src_stride_rgb565; src_stride_rgb565 = -src_stride_rgb565; } // Coalesce rows. - if (src_stride_rgb565 == width * 2 && dst_stride_argb == width * 4) { + if (src_stride_rgb565 == width * 2 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_rgb565 = dst_stride_argb = 0; } -#if defined(HAS_RGB565TOARGBROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - RGB565ToARGBRow = RGB565ToARGBRow_Any_SSE2; - if (IS_ALIGNED(width, 8)) { - RGB565ToARGBRow = RGB565ToARGBRow_SSE2; - } - } -#endif + #if defined(HAS_RGB565TOARGBROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { RGB565ToARGBRow = RGB565ToARGBRow_Any_AVX2; @@ -1354,24 +4376,32 @@ int RGB565ToARGB(const uint8_t* src_rgb565, #if defined(HAS_RGB565TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { RGB565ToARGBRow = RGB565ToARGBRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { + if (IS_ALIGNED(width, 16)) { RGB565ToARGBRow = RGB565ToARGBRow_NEON; } } #endif -#if defined(HAS_RGB565TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - RGB565ToARGBRow = RGB565ToARGBRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - RGB565ToARGBRow = RGB565ToARGBRow_MSA; +#if defined(HAS_RGB565TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RGB565ToARGBRow = RGB565ToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + RGB565ToARGBRow = RGB565ToARGBRow_LSX; } } #endif -#if defined(HAS_RGB565TOARGBROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - RGB565ToARGBRow = RGB565ToARGBRow_Any_MMI; - if (IS_ALIGNED(width, 4)) { - RGB565ToARGBRow = RGB565ToARGBRow_MMI; +#if defined(HAS_RGB565TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RGB565ToARGBRow = RGB565ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + RGB565ToARGBRow = RGB565ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_RGB565TOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGB565ToARGBRow = RGB565ToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + RGB565ToARGBRow = RGB565ToARGBRow_WASMSIMD; } } #endif @@ -1395,29 +4425,24 @@ int ARGB1555ToARGB(const uint8_t* src_argb1555, int y; void (*ARGB1555ToARGBRow)(const uint8_t* src_argb1555, uint8_t* dst_argb, int width) = ARGB1555ToARGBRow_C; - if (!src_argb1555 || !dst_argb || width <= 0 || height == 0) { + if (!src_argb1555 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb1555 = src_argb1555 + (height - 1) * src_stride_argb1555; + src_argb1555 = src_argb1555 + (ptrdiff_t)(height - 1) * src_stride_argb1555; src_stride_argb1555 = -src_stride_argb1555; } // Coalesce rows. - if (src_stride_argb1555 == width * 2 && dst_stride_argb == width * 4) { + if (src_stride_argb1555 == width * 2 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb1555 = dst_stride_argb = 0; } -#if defined(HAS_ARGB1555TOARGBROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_SSE2; - if (IS_ALIGNED(width, 8)) { - ARGB1555ToARGBRow = ARGB1555ToARGBRow_SSE2; - } - } -#endif + #if defined(HAS_ARGB1555TOARGBROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_AVX2; @@ -1426,27 +4451,45 @@ int ARGB1555ToARGB(const uint8_t* src_argb1555, } } #endif +#if defined(HAS_ARGB1555TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGB1555ToARGBRow = ARGB1555ToARGBRow_AVX512BW; + } +#endif #if defined(HAS_ARGB1555TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { + if (IS_ALIGNED(width, 16)) { ARGB1555ToARGBRow = ARGB1555ToARGBRow_NEON; } } #endif -#if defined(HAS_ARGB1555TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGB1555ToARGBRow = ARGB1555ToARGBRow_MSA; +#if defined(HAS_ARGB1555TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGB1555ToARGBRow = ARGB1555ToARGBRow_SVE2; + } +#endif +#if defined(HAS_ARGB1555TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGB1555ToARGBRow = ARGB1555ToARGBRow_LSX; } } #endif -#if defined(HAS_ARGB1555TOARGBROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_MMI; - if (IS_ALIGNED(width, 4)) { - ARGB1555ToARGBRow = ARGB1555ToARGBRow_MMI; +#if defined(HAS_ARGB1555TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGB1555ToARGBRow = ARGB1555ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_ARGB1555TOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + ARGB1555ToARGBRow = ARGB1555ToARGBRow_WASMSIMD; } } #endif @@ -1470,29 +4513,24 @@ int ARGB4444ToARGB(const uint8_t* src_argb4444, int y; void (*ARGB4444ToARGBRow)(const uint8_t* src_argb4444, uint8_t* dst_argb, int width) = ARGB4444ToARGBRow_C; - if (!src_argb4444 || !dst_argb || width <= 0 || height == 0) { + if (!src_argb4444 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb4444 = src_argb4444 + (height - 1) * src_stride_argb4444; + src_argb4444 = src_argb4444 + (ptrdiff_t)(height - 1) * src_stride_argb4444; src_stride_argb4444 = -src_stride_argb4444; } // Coalesce rows. - if (src_stride_argb4444 == width * 2 && dst_stride_argb == width * 4) { + if (src_stride_argb4444 == width * 2 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb4444 = dst_stride_argb = 0; } -#if defined(HAS_ARGB4444TOARGBROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_SSE2; - if (IS_ALIGNED(width, 8)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_SSE2; - } - } -#endif + #if defined(HAS_ARGB4444TOARGBROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_AVX2; @@ -1509,19 +4547,27 @@ int ARGB4444ToARGB(const uint8_t* src_argb4444, } } #endif -#if defined(HAS_ARGB4444TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_MSA; +#if defined(HAS_ARGB4444TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGB4444ToARGBRow = ARGB4444ToARGBRow_LSX; } } #endif -#if defined(HAS_ARGB4444TOARGBROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_MMI; - if (IS_ALIGNED(width, 4)) { - ARGB4444ToARGBRow = ARGB4444ToARGBRow_MMI; +#if defined(HAS_ARGB4444TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGB4444ToARGBRow = ARGB4444ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_ARGB4444TOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + ARGB4444ToARGBRow = ARGB4444ToARGBRow_WASMSIMD; } } #endif @@ -1543,23 +4589,48 @@ int AR30ToARGB(const uint8_t* src_ar30, int width, int height) { int y; - if (!src_ar30 || !dst_argb || width <= 0 || height == 0) { + if (!src_ar30 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_ar30 = src_ar30 + (height - 1) * src_stride_ar30; + src_ar30 = src_ar30 + (ptrdiff_t)(height - 1) * src_stride_ar30; src_stride_ar30 = -src_stride_ar30; } // Coalesce rows. - if (src_stride_ar30 == width * 4 && dst_stride_argb == width * 4) { + if (src_stride_ar30 == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_ar30 = dst_stride_argb = 0; } + void (*AR30ToARGBRow)(const uint8_t* src_ar30, uint8_t* dst_argb, int width) = + AR30ToARGBRow_C; +#if defined(HAS_AR30TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + AR30ToARGBRow = AR30ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + AR30ToARGBRow = AR30ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_AR30TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + AR30ToARGBRow = AR30ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + AR30ToARGBRow = AR30ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_AR30TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + AR30ToARGBRow = AR30ToARGBRow_AVX512BW; + } +#endif for (y = 0; y < height; ++y) { - AR30ToARGBRow_C(src_ar30, dst_argb, width); + AR30ToARGBRow(src_ar30, dst_argb, width); src_ar30 += src_stride_ar30; dst_argb += dst_stride_argb; } @@ -1575,23 +4646,48 @@ int AR30ToABGR(const uint8_t* src_ar30, int width, int height) { int y; - if (!src_ar30 || !dst_abgr || width <= 0 || height == 0) { + void (*AR30ToABGRRow)(const uint8_t* src_ar30, uint8_t* dst_abgr, int width) = + AR30ToABGRRow_C; + if (!src_ar30 || !dst_abgr || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_ar30 = src_ar30 + (height - 1) * src_stride_ar30; + src_ar30 = src_ar30 + (ptrdiff_t)(height - 1) * src_stride_ar30; src_stride_ar30 = -src_stride_ar30; } // Coalesce rows. - if (src_stride_ar30 == width * 4 && dst_stride_abgr == width * 4) { + if (src_stride_ar30 == width * 4 && dst_stride_abgr == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_ar30 = dst_stride_abgr = 0; } +#if defined(HAS_AR30TOABGRROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + AR30ToABGRRow = AR30ToABGRRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + AR30ToABGRRow = AR30ToABGRRow_NEON; + } + } +#endif +#if defined(HAS_AR30TOABGRROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + AR30ToABGRRow = AR30ToABGRRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + AR30ToABGRRow = AR30ToABGRRow_AVX2; + } + } +#endif +#if defined(HAS_AR30TOABGRROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + AR30ToABGRRow = AR30ToABGRRow_AVX512BW; + } +#endif for (y = 0; y < height; ++y) { - AR30ToABGRRow_C(src_ar30, dst_abgr, width); + AR30ToABGRRow(src_ar30, dst_abgr, width); src_ar30 += src_stride_ar30; dst_abgr += dst_stride_abgr; } @@ -1607,50 +4703,220 @@ int AR30ToAB30(const uint8_t* src_ar30, int width, int height) { int y; - if (!src_ar30 || !dst_ab30 || width <= 0 || height == 0) { + void (*AR30ToAB30Row)(const uint8_t* src_ar30, uint8_t* dst_ab30, int width) = + AR30ToAB30Row_C; + if (!src_ar30 || !dst_ab30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_ar30 = src_ar30 + (height - 1) * src_stride_ar30; + src_ar30 = src_ar30 + (ptrdiff_t)(height - 1) * src_stride_ar30; src_stride_ar30 = -src_stride_ar30; } // Coalesce rows. - if (src_stride_ar30 == width * 4 && dst_stride_ab30 == width * 4) { + if (src_stride_ar30 == width * 4 && dst_stride_ab30 == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_ar30 = dst_stride_ab30 = 0; } +#if defined(HAS_AR30TOAB30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + AR30ToAB30Row = AR30ToAB30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + AR30ToAB30Row = AR30ToAB30Row_NEON; + } + } +#endif +#if defined(HAS_AR30TOAB30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + AR30ToAB30Row = AR30ToAB30Row_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + AR30ToAB30Row = AR30ToAB30Row_AVX2; + } + } +#endif +#if defined(HAS_AR30TOAB30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + AR30ToAB30Row = AR30ToAB30Row_AVX512BW; + } +#endif for (y = 0; y < height; ++y) { - AR30ToAB30Row_C(src_ar30, dst_ab30, width); + AR30ToAB30Row(src_ar30, dst_ab30, width); src_ar30 += src_stride_ar30; dst_ab30 += dst_stride_ab30; } return 0; } -// Convert NV12 to ARGB with matrix -static int NV12ToARGBMatrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_uv, - int src_stride_uv, - uint8_t* dst_argb, - int dst_stride_argb, - const struct YuvConstants* yuvconstants, - int width, - int height) { +// Convert AR64 to ARGB. +LIBYUV_API +int AR64ToARGB(const uint16_t* src_ar64, + int src_stride_ar64, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { int y; - void (*NV12ToARGBRow)( - const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, int width) = NV12ToARGBRow_C; - if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) { + void (*AR64ToARGBRow)(const uint16_t* src_ar64, uint8_t* dst_argb, + int width) = AR64ToARGBRow_C; + if (!src_ar64 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + src_ar64 = src_ar64 + (ptrdiff_t)(height - 1) * src_stride_ar64; + src_stride_ar64 = -src_stride_ar64; + } + // Coalesce rows. + if (src_stride_ar64 == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_ar64 = dst_stride_argb = 0; + } +#if defined(HAS_AR64TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + AR64ToARGBRow = AR64ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + AR64ToARGBRow = AR64ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_AR64TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + AR64ToARGBRow = AR64ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + AR64ToARGBRow = AR64ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_AR64TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + AR64ToARGBRow = AR64ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + AR64ToARGBRow = AR64ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_AR64TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + AR64ToARGBRow = AR64ToARGBRow_RVV; + } +#endif +#if defined(HAS_AR64TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + AR64ToARGBRow = AR64ToARGBRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + AR64ToARGBRow(src_ar64, dst_argb, width); + src_ar64 += src_stride_ar64; + dst_argb += dst_stride_argb; + } + return 0; +} + +// Convert AB64 to ARGB. +LIBYUV_API +int AB64ToARGB(const uint16_t* src_ab64, + int src_stride_ab64, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + int y; + void (*AB64ToARGBRow)(const uint16_t* src_ar64, uint8_t* dst_argb, + int width) = AB64ToARGBRow_C; + if (!src_ab64 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_ab64 = src_ab64 + (ptrdiff_t)(height - 1) * src_stride_ab64; + src_stride_ab64 = -src_stride_ab64; + } + // Coalesce rows. + if (src_stride_ab64 == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_ab64 = dst_stride_argb = 0; + } +#if defined(HAS_AB64TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + AB64ToARGBRow = AB64ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + AB64ToARGBRow = AB64ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_AB64TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + AB64ToARGBRow = AB64ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + AB64ToARGBRow = AB64ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_AB64TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + AB64ToARGBRow = AB64ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + AB64ToARGBRow = AB64ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_AB64TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + AB64ToARGBRow = AB64ToARGBRow_RVV; + } +#endif +#if defined(HAS_AB64TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + AB64ToARGBRow = AB64ToARGBRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + AB64ToARGBRow(src_ab64, dst_argb, width); + src_ab64 += src_stride_ab64; + dst_argb += dst_stride_argb; + } + return 0; +} + +// Convert NV12 to ARGB with matrix. +LIBYUV_API +int NV12ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*NV12ToARGBRow)( + const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = NV12ToARGBRow_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_NV12TOARGBROW_SSSE3) @@ -1669,6 +4935,11 @@ static int NV12ToARGBMatrix(const uint8_t* src_y, } } #endif +#if defined(HAS_NV12TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + NV12ToARGBRow = NV12ToARGBRow_AVX512BW; + } +#endif #if defined(HAS_NV12TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { NV12ToARGBRow = NV12ToARGBRow_Any_NEON; @@ -1677,14 +4948,50 @@ static int NV12ToARGBMatrix(const uint8_t* src_y, } } #endif -#if defined(HAS_NV12TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - NV12ToARGBRow = NV12ToARGBRow_Any_MSA; +#if defined(HAS_NV12TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + NV12ToARGBRow = NV12ToARGBRow_SVE2; + } +#endif +#if defined(HAS_NV12TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + NV12ToARGBRow = NV12ToARGBRow_SME; + } +#endif +#if defined(HAS_NV12TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + NV12ToARGBRow = NV12ToARGBRow_Any_LSX; if (IS_ALIGNED(width, 8)) { - NV12ToARGBRow = NV12ToARGBRow_MSA; + NV12ToARGBRow = NV12ToARGBRow_LSX; } } #endif +#if defined(HAS_NV12TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + NV12ToARGBRow = NV12ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + NV12ToARGBRow = NV12ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_NV12TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + NV12ToARGBRow = NV12ToARGBRow_RVV; + } +#endif +#if defined(HAS_NV12TOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + NV12ToARGBRow = NV12ToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + NV12ToARGBRow = NV12ToARGBRow_WASMSIMD; + } + } +#endif +#if defined(HAS_NV12TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + NV12ToARGBRow = NV12ToARGBRow_HVX; + } +#endif for (y = 0; y < height; ++y) { NV12ToARGBRow(src_y, src_uv, dst_argb, yuvconstants, width); @@ -1697,27 +5004,30 @@ static int NV12ToARGBMatrix(const uint8_t* src_y, return 0; } -// Convert NV21 to ARGB with matrix -static int NV21ToARGBMatrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_vu, - int src_stride_vu, - uint8_t* dst_argb, - int dst_stride_argb, - const struct YuvConstants* yuvconstants, - int width, - int height) { +// Convert NV21 to ARGB with matrix. +LIBYUV_API +int NV21ToARGBMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_vu, + int src_stride_vu, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; void (*NV21ToARGBRow)( const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = NV21ToARGBRow_C; - if (!src_y || !src_vu || !dst_argb || width <= 0 || height == 0) { + assert(yuvconstants); + if (!src_y || !src_vu || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_NV21TOARGBROW_SSSE3) @@ -1736,6 +5046,11 @@ static int NV21ToARGBMatrix(const uint8_t* src_y, } } #endif +#if defined(HAS_NV21TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + NV21ToARGBRow = NV21ToARGBRow_AVX512BW; + } +#endif #if defined(HAS_NV21TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { NV21ToARGBRow = NV21ToARGBRow_Any_NEON; @@ -1744,14 +5059,50 @@ static int NV21ToARGBMatrix(const uint8_t* src_y, } } #endif -#if defined(HAS_NV21TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - NV21ToARGBRow = NV21ToARGBRow_Any_MSA; +#if defined(HAS_NV21TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + NV21ToARGBRow = NV21ToARGBRow_SVE2; + } +#endif +#if defined(HAS_NV21TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + NV21ToARGBRow = NV21ToARGBRow_SME; + } +#endif +#if defined(HAS_NV21TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + NV21ToARGBRow = NV21ToARGBRow_Any_LSX; if (IS_ALIGNED(width, 8)) { - NV21ToARGBRow = NV21ToARGBRow_MSA; + NV21ToARGBRow = NV21ToARGBRow_LSX; } } #endif +#if defined(HAS_NV21TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + NV21ToARGBRow = NV21ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + NV21ToARGBRow = NV21ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_NV21TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + NV21ToARGBRow = NV21ToARGBRow_RVV; + } +#endif +#if defined(HAS_NV21TOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + NV21ToARGBRow = NV21ToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + NV21ToARGBRow = NV21ToARGBRow_WASMSIMD; + } + } +#endif +#if defined(HAS_NV21TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + NV21ToARGBRow = NV21ToARGBRow_HVX; + } +#endif for (y = 0; y < height; ++y) { NV21ToARGBRow(src_y, src_vu, dst_argb, yuvconstants, width); @@ -1823,27 +5174,30 @@ int NV21ToABGR(const uint8_t* src_y, } // TODO(fbarchard): Consider SSSE3 2 step conversion. -// Convert NV12 to RGB24 with matrix -static int NV12ToRGB24Matrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_uv, - int src_stride_uv, - uint8_t* dst_rgb24, - int dst_stride_rgb24, - const struct YuvConstants* yuvconstants, - int width, - int height) { +// Convert NV12 to RGB24 with matrix. +LIBYUV_API +int NV12ToRGB24Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; void (*NV12ToRGB24Row)( const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = NV12ToRGB24Row_C; - if (!src_y || !src_uv || !dst_rgb24 || width <= 0 || height == 0) { + assert(yuvconstants); + if (!src_y || !src_uv || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; dst_stride_rgb24 = -dst_stride_rgb24; } #if defined(HAS_NV12TORGB24ROW_NEON) @@ -1854,6 +5208,16 @@ static int NV12ToRGB24Matrix(const uint8_t* src_y, } } #endif +#if defined(HAS_NV12TORGB24ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + NV12ToRGB24Row = NV12ToRGB24Row_SVE2; + } +#endif +#if defined(HAS_NV12TORGB24ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + NV12ToRGB24Row = NV12ToRGB24Row_SME; + } +#endif #if defined(HAS_NV12TORGB24ROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { NV12ToRGB24Row = NV12ToRGB24Row_Any_SSSE3; @@ -1870,6 +5234,17 @@ static int NV12ToRGB24Matrix(const uint8_t* src_y, } } #endif +#if defined(HAS_NV12TORGB24ROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI | kCpuHasAVX512VL) == + (kCpuHasAVX512VBMI | kCpuHasAVX512VL)) { + NV12ToRGB24Row = NV12ToRGB24Row_AVX512VBMI; + } +#endif +#if defined(HAS_NV12TORGB24ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + NV12ToRGB24Row = NV12ToRGB24Row_RVV; + } +#endif for (y = 0; y < height; ++y) { NV12ToRGB24Row(src_y, src_uv, dst_rgb24, yuvconstants, width); @@ -1882,27 +5257,30 @@ static int NV12ToRGB24Matrix(const uint8_t* src_y, return 0; } -// Convert NV21 to RGB24 with matrix -static int NV21ToRGB24Matrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_vu, - int src_stride_vu, - uint8_t* dst_rgb24, - int dst_stride_rgb24, - const struct YuvConstants* yuvconstants, - int width, - int height) { +// Convert NV21 to RGB24 with matrix. +LIBYUV_API +int NV21ToRGB24Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_vu, + int src_stride_vu, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; void (*NV21ToRGB24Row)( const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = NV21ToRGB24Row_C; - if (!src_y || !src_vu || !dst_rgb24 || width <= 0 || height == 0) { + assert(yuvconstants); + if (!src_y || !src_vu || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; dst_stride_rgb24 = -dst_stride_rgb24; } #if defined(HAS_NV21TORGB24ROW_NEON) @@ -1913,6 +5291,16 @@ static int NV21ToRGB24Matrix(const uint8_t* src_y, } } #endif +#if defined(HAS_NV21TORGB24ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + NV21ToRGB24Row = NV21ToRGB24Row_SVE2; + } +#endif +#if defined(HAS_NV21TORGB24ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + NV21ToRGB24Row = NV21ToRGB24Row_SME; + } +#endif #if defined(HAS_NV21TORGB24ROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { NV21ToRGB24Row = NV21ToRGB24Row_Any_SSSE3; @@ -1929,6 +5317,17 @@ static int NV21ToRGB24Matrix(const uint8_t* src_y, } } #endif +#if defined(HAS_NV21TORGB24ROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI | kCpuHasAVX512VL) == + (kCpuHasAVX512VBMI | kCpuHasAVX512VL)) { + NV21ToRGB24Row = NV21ToRGB24Row_AVX512VBMI; + } +#endif +#if defined(HAS_NV21TORGB24ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + NV21ToRGB24Row = NV21ToRGB24Row_RVV; + } +#endif for (y = 0; y < height; ++y) { NV21ToRGB24Row(src_y, src_vu, dst_rgb24, yuvconstants, width); @@ -2011,13 +5410,14 @@ int NV21ToYUV24(const uint8_t* src_y, int y; void (*NV21ToYUV24Row)(const uint8_t* src_y, const uint8_t* src_vu, uint8_t* dst_yuv24, int width) = NV21ToYUV24Row_C; - if (!src_y || !src_vu || !dst_yuv24 || width <= 0 || height == 0) { + if (!src_y || !src_vu || !dst_yuv24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_yuv24 = dst_yuv24 + (height - 1) * dst_stride_yuv24; + dst_yuv24 = dst_yuv24 + (ptrdiff_t)(height - 1) * dst_stride_yuv24; dst_stride_yuv24 = -dst_stride_yuv24; } #if defined(HAS_NV21TOYUV24ROW_NEON) @@ -2028,6 +5428,14 @@ int NV21ToYUV24(const uint8_t* src_y, } } #endif +#if defined(HAS_NV21TOYUV24ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + NV21ToYUV24Row = NV21ToYUV24Row_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + NV21ToYUV24Row = NV21ToYUV24Row_SSSE3; + } + } +#endif #if defined(HAS_NV21TOYUV24ROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { NV21ToYUV24Row = NV21ToYUV24Row_Any_AVX2; @@ -2035,6 +5443,11 @@ int NV21ToYUV24(const uint8_t* src_y, NV21ToYUV24Row = NV21ToYUV24Row_AVX2; } } +#endif +#if defined(HAS_NV21TOYUV24ROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI)) { + NV21ToYUV24Row = NV21ToYUV24Row_AVX512VBMI; + } #endif for (y = 0; y < height; ++y) { NV21ToYUV24Row(src_y, src_vu, dst_yuv24, width); @@ -2047,98 +5460,32 @@ int NV21ToYUV24(const uint8_t* src_y, return 0; } -// Convert M420 to ARGB. +// Convert YUY2 to ARGB with matrix. LIBYUV_API -int M420ToARGB(const uint8_t* src_m420, - int src_stride_m420, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height) { - int y; - void (*NV12ToARGBRow)( - const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, int width) = NV12ToARGBRow_C; - if (!src_m420 || !dst_argb || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; - dst_stride_argb = -dst_stride_argb; - } -#if defined(HAS_NV12TOARGBROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - NV12ToARGBRow = NV12ToARGBRow_Any_SSSE3; - if (IS_ALIGNED(width, 8)) { - NV12ToARGBRow = NV12ToARGBRow_SSSE3; - } - } -#endif -#if defined(HAS_NV12TOARGBROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - NV12ToARGBRow = NV12ToARGBRow_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - NV12ToARGBRow = NV12ToARGBRow_AVX2; - } - } -#endif -#if defined(HAS_NV12TOARGBROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - NV12ToARGBRow = NV12ToARGBRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - NV12ToARGBRow = NV12ToARGBRow_NEON; - } - } -#endif -#if defined(HAS_NV12TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - NV12ToARGBRow = NV12ToARGBRow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - NV12ToARGBRow = NV12ToARGBRow_MSA; - } - } -#endif - - for (y = 0; y < height - 1; y += 2) { - NV12ToARGBRow(src_m420, src_m420 + src_stride_m420 * 2, dst_argb, - &kYuvI601Constants, width); - NV12ToARGBRow(src_m420 + src_stride_m420, src_m420 + src_stride_m420 * 2, - dst_argb + dst_stride_argb, &kYuvI601Constants, width); - dst_argb += dst_stride_argb * 2; - src_m420 += src_stride_m420 * 3; - } - if (height & 1) { - NV12ToARGBRow(src_m420, src_m420 + src_stride_m420 * 2, dst_argb, - &kYuvI601Constants, width); - } - return 0; -} - -// Convert YUY2 to ARGB. -LIBYUV_API -int YUY2ToARGB(const uint8_t* src_yuy2, - int src_stride_yuy2, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height) { +int YUY2ToARGBMatrix(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { int y; void (*YUY2ToARGBRow)(const uint8_t* src_yuy2, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) = YUY2ToARGBRow_C; - if (!src_yuy2 || !dst_argb || width <= 0 || height == 0) { + if (!src_yuy2 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; + src_yuy2 = src_yuy2 + (ptrdiff_t)(height - 1) * src_stride_yuy2; src_stride_yuy2 = -src_stride_yuy2; } // Coalesce rows. - if (src_stride_yuy2 == width * 2 && dst_stride_argb == width * 4) { + if (src_stride_yuy2 == width * 2 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_yuy2 = dst_stride_argb = 0; @@ -2146,7 +5493,7 @@ int YUY2ToARGB(const uint8_t* src_yuy2, #if defined(HAS_YUY2TOARGBROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { YUY2ToARGBRow = YUY2ToARGBRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { + if (IS_ALIGNED(width, 8)) { YUY2ToARGBRow = YUY2ToARGBRow_SSSE3; } } @@ -2159,6 +5506,11 @@ int YUY2ToARGB(const uint8_t* src_yuy2, } } #endif +#if defined(HAS_YUY2TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + YUY2ToARGBRow = YUY2ToARGBRow_AVX512BW; + } +#endif #if defined(HAS_YUY2TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { YUY2ToARGBRow = YUY2ToARGBRow_Any_NEON; @@ -2167,22 +5519,145 @@ int YUY2ToARGB(const uint8_t* src_yuy2, } } #endif -#if defined(HAS_YUY2TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - YUY2ToARGBRow = YUY2ToARGBRow_Any_MSA; +#if defined(HAS_YUY2TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + YUY2ToARGBRow = YUY2ToARGBRow_SVE2; + } +#endif +#if defined(HAS_YUY2TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + YUY2ToARGBRow = YUY2ToARGBRow_SME; + } +#endif +#if defined(HAS_YUY2TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + YUY2ToARGBRow = YUY2ToARGBRow_Any_LSX; if (IS_ALIGNED(width, 8)) { - YUY2ToARGBRow = YUY2ToARGBRow_MSA; + YUY2ToARGBRow = YUY2ToARGBRow_LSX; + } + } +#endif +#if defined(HAS_YUY2TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + YUY2ToARGBRow = YUY2ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + YUY2ToARGBRow = YUY2ToARGBRow_LASX; } } #endif for (y = 0; y < height; ++y) { - YUY2ToARGBRow(src_yuy2, dst_argb, &kYuvI601Constants, width); + YUY2ToARGBRow(src_yuy2, dst_argb, yuvconstants, width); src_yuy2 += src_stride_yuy2; dst_argb += dst_stride_argb; } return 0; } +// Convert YUY2 to ARGB. +LIBYUV_API +int YUY2ToARGB(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + return YUY2ToARGBMatrix(src_yuy2, src_stride_yuy2, dst_argb, dst_stride_argb, + &kYuvI601Constants, width, height); +} + +// Convert UYVY to ARGB with matrix. +LIBYUV_API +int UYVYToARGBMatrix(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*UYVYToARGBRow)(const uint8_t* src_uyvy, uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, int width) = + UYVYToARGBRow_C; + if (!src_uyvy || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_uyvy = src_uyvy + (ptrdiff_t)(height - 1) * src_stride_uyvy; + src_stride_uyvy = -src_stride_uyvy; + } + // Coalesce rows. + if (src_stride_uyvy == width * 2 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_uyvy = dst_stride_argb = 0; + } +#if defined(HAS_UYVYTOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + UYVYToARGBRow = UYVYToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + UYVYToARGBRow = UYVYToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_UYVYTOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + UYVYToARGBRow = UYVYToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + UYVYToARGBRow = UYVYToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_UYVYTOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + UYVYToARGBRow = UYVYToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_UYVYTOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + UYVYToARGBRow = UYVYToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + UYVYToARGBRow = UYVYToARGBRow_NEON; + } + } +#endif +#if defined(HAS_UYVYTOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + UYVYToARGBRow = UYVYToARGBRow_SVE2; + } +#endif +#if defined(HAS_UYVYTOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + UYVYToARGBRow = UYVYToARGBRow_SME; + } +#endif +#if defined(HAS_UYVYTOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + UYVYToARGBRow = UYVYToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + UYVYToARGBRow = UYVYToARGBRow_LSX; + } + } +#endif +#if defined(HAS_UYVYTOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + UYVYToARGBRow = UYVYToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + UYVYToARGBRow = UYVYToARGBRow_LASX; + } + } +#endif + for (y = 0; y < height; ++y) { + UYVYToARGBRow(src_uyvy, dst_argb, yuvconstants, width); + src_uyvy += src_stride_uyvy; + dst_argb += dst_stride_argb; + } + return 0; +} + // Convert UYVY to ARGB. LIBYUV_API int UYVYToARGB(const uint8_t* src_uyvy, @@ -2191,64 +5666,10 @@ int UYVYToARGB(const uint8_t* src_uyvy, int dst_stride_argb, int width, int height) { - int y; - void (*UYVYToARGBRow)(const uint8_t* src_uyvy, uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, int width) = - UYVYToARGBRow_C; - if (!src_uyvy || !dst_argb || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; - src_stride_uyvy = -src_stride_uyvy; - } - // Coalesce rows. - if (src_stride_uyvy == width * 2 && dst_stride_argb == width * 4) { - width *= height; - height = 1; - src_stride_uyvy = dst_stride_argb = 0; - } -#if defined(HAS_UYVYTOARGBROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - UYVYToARGBRow = UYVYToARGBRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - UYVYToARGBRow = UYVYToARGBRow_SSSE3; - } - } -#endif -#if defined(HAS_UYVYTOARGBROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - UYVYToARGBRow = UYVYToARGBRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - UYVYToARGBRow = UYVYToARGBRow_AVX2; - } - } -#endif -#if defined(HAS_UYVYTOARGBROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - UYVYToARGBRow = UYVYToARGBRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - UYVYToARGBRow = UYVYToARGBRow_NEON; - } - } -#endif -#if defined(HAS_UYVYTOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - UYVYToARGBRow = UYVYToARGBRow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - UYVYToARGBRow = UYVYToARGBRow_MSA; - } - } -#endif - for (y = 0; y < height; ++y) { - UYVYToARGBRow(src_uyvy, dst_argb, &kYuvI601Constants, width); - src_uyvy += src_stride_uyvy; - dst_argb += dst_stride_argb; - } - return 0; + return UYVYToARGBMatrix(src_uyvy, src_stride_uyvy, dst_argb, dst_stride_argb, + &kYuvI601Constants, width, height); } + static void WeavePixels(const uint8_t* src_u, const uint8_t* src_v, int src_pixel_stride_uv, @@ -2264,7 +5685,7 @@ static void WeavePixels(const uint8_t* src_u, } } -// Convert Android420 to ARGB. +// Convert Android420 to ARGB with matrix. LIBYUV_API int Android420ToARGBMatrix(const uint8_t* src_y, int src_stride_y, @@ -2283,14 +5704,16 @@ int Android420ToARGBMatrix(const uint8_t* src_y, const ptrdiff_t vu_off = src_v - src_u; int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } @@ -2313,7 +5736,12 @@ int Android420ToARGBMatrix(const uint8_t* src_y, } // General case fallback creates NV12 - align_buffer_64(plane_uv, halfwidth * 2 * halfheight); + const uint64_t uv_size = (uint64_t)halfwidth * 2 * halfheight; + if (uv_size > SIZE_MAX) + return 1; + align_buffer_64(plane_uv, (size_t)uv_size); + if (!plane_uv) + return 1; dst_uv = plane_uv; for (y = 0; y < halfheight; ++y) { WeavePixels(src_u, src_v, src_pixel_stride_uv, dst_uv, halfwidth); @@ -2365,6 +5793,4421 @@ int Android420ToABGR(const uint8_t* src_y, height); } +// Convert I422 to RGBA with matrix. +LIBYUV_API +int I422ToRGBAMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgba, + int dst_stride_rgba, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I422ToRGBARow)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I422ToRGBARow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgba = dst_rgba + (ptrdiff_t)(height - 1) * dst_stride_rgba; + dst_stride_rgba = -dst_stride_rgba; + } + // Coalesce rows. + if (src_stride_y == width && src_stride_u * 2 == width && + src_stride_v * 2 == width && dst_stride_rgba == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = src_stride_u = src_stride_v = dst_stride_rgba = 0; + } +#if defined(HAS_I422TORGBAROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422ToRGBARow = I422ToRGBARow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422ToRGBARow = I422ToRGBARow_SSSE3; + } + } +#endif +#if defined(HAS_I422TORGBAROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422ToRGBARow = I422ToRGBARow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422ToRGBARow = I422ToRGBARow_AVX2; + } + } +#endif +#if defined(HAS_I422TORGBAROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I422ToRGBARow = I422ToRGBARow_AVX512BW; + } +#endif +#if defined(HAS_I422TORGBAROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422ToRGBARow = I422ToRGBARow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422ToRGBARow = I422ToRGBARow_NEON; + } + } +#endif +#if defined(HAS_I422TORGBAROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToRGBARow = I422ToRGBARow_SVE2; + } +#endif +#if defined(HAS_I422TORGBAROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToRGBARow = I422ToRGBARow_SME; + } +#endif +#if defined(HAS_I422TORGBAROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToRGBARow = I422ToRGBARow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I422ToRGBARow = I422ToRGBARow_LSX; + } + } +#endif +#if defined(HAS_I422TORGBAROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToRGBARow = I422ToRGBARow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422ToRGBARow = I422ToRGBARow_LASX; + } + } +#endif +#if defined(HAS_I422TORGBAROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I422ToRGBARow = I422ToRGBARow_RVV; + } +#endif +#if defined(HAS_I422TORGBAROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I422ToRGBARow = I422ToRGBARow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width); + dst_rgba += dst_stride_rgba; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + +// Convert I422 to RGBA. +LIBYUV_API +int I422ToRGBA(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgba, + int dst_stride_rgba, + int width, + int height) { + return I422ToRGBAMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgba, dst_stride_rgba, + &kYuvI601Constants, width, height); +} + +// Convert I422 to BGRA. +LIBYUV_API +int I422ToBGRA(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_bgra, + int dst_stride_bgra, + int width, + int height) { + return I422ToRGBAMatrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_bgra, dst_stride_bgra, + &kYvuI601Constants, // Use Yvu matrix + width, height); +} + +// Convert NV12 to RGB565 with matrix. +LIBYUV_API +int NV12ToRGB565Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*NV12ToRGB565Row)( + const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = NV12ToRGB565Row_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; + dst_stride_rgb565 = -dst_stride_rgb565; + } +#if defined(HAS_NV12TORGB565ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + NV12ToRGB565Row = NV12ToRGB565Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + NV12ToRGB565Row = NV12ToRGB565Row_SSSE3; + } + } +#endif +#if defined(HAS_NV12TORGB565ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + NV12ToRGB565Row = NV12ToRGB565Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + NV12ToRGB565Row = NV12ToRGB565Row_AVX2; + } + } +#endif +#if defined(HAS_NV12TORGB565ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + NV12ToRGB565Row = NV12ToRGB565Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + NV12ToRGB565Row = NV12ToRGB565Row_NEON; + } + } +#endif +#if defined(HAS_NV12TORGB565ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + NV12ToRGB565Row = NV12ToRGB565Row_Any_LSX; + if (IS_ALIGNED(width, 8)) { + NV12ToRGB565Row = NV12ToRGB565Row_LSX; + } + } +#endif +#if defined(HAS_NV12TORGB565ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + NV12ToRGB565Row = NV12ToRGB565Row_Any_LASX; + if (IS_ALIGNED(width, 16)) { + NV12ToRGB565Row = NV12ToRGB565Row_LASX; + } + } +#endif +#if defined(HAS_NV12TORGB565ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + NV12ToRGB565Row = NV12ToRGB565Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + NV12ToRGB565Row = NV12ToRGB565Row_WASMSIMD; + } + } +#endif + + for (y = 0; y < height; ++y) { + NV12ToRGB565Row(src_y, src_uv, dst_rgb565, yuvconstants, width); + dst_rgb565 += dst_stride_rgb565; + src_y += src_stride_y; + if (y & 1) { + src_uv += src_stride_uv; + } + } + return 0; +} + +// Convert NV12 to RGB565. +LIBYUV_API +int NV12ToRGB565(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + int width, + int height) { + return NV12ToRGB565Matrix(src_y, src_stride_y, src_uv, src_stride_uv, + dst_rgb565, dst_stride_rgb565, &kYuvI601Constants, + width, height); +} + +// Convert I422 to RGBA with matrix. +LIBYUV_API +int I420ToRGBAMatrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgba, + int dst_stride_rgba, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I422ToRGBARow)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I422ToRGBARow_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgba = dst_rgba + (ptrdiff_t)(height - 1) * dst_stride_rgba; + dst_stride_rgba = -dst_stride_rgba; + } +#if defined(HAS_I422TORGBAROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422ToRGBARow = I422ToRGBARow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422ToRGBARow = I422ToRGBARow_SSSE3; + } + } +#endif +#if defined(HAS_I422TORGBAROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422ToRGBARow = I422ToRGBARow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422ToRGBARow = I422ToRGBARow_AVX2; + } + } +#endif +#if defined(HAS_I422TORGBAROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I422ToRGBARow = I422ToRGBARow_AVX512BW; + } +#endif +#if defined(HAS_I422TORGBAROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422ToRGBARow = I422ToRGBARow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422ToRGBARow = I422ToRGBARow_NEON; + } + } +#endif +#if defined(HAS_I422TORGBAROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToRGBARow = I422ToRGBARow_SVE2; + } +#endif +#if defined(HAS_I422TORGBAROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToRGBARow = I422ToRGBARow_SME; + } +#endif +#if defined(HAS_I422TORGBAROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToRGBARow = I422ToRGBARow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I422ToRGBARow = I422ToRGBARow_LSX; + } + } +#endif +#if defined(HAS_I422TORGBAROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToRGBARow = I422ToRGBARow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422ToRGBARow = I422ToRGBARow_LASX; + } + } +#endif +#if defined(HAS_I422TORGBAROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I422ToRGBARow = I422ToRGBARow_RVV; + } +#endif +#if defined(HAS_I422TORGBAROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I422ToRGBARow = I422ToRGBARow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width); + dst_rgba += dst_stride_rgba; + src_y += src_stride_y; + if (y & 1) { + src_u += src_stride_u; + src_v += src_stride_v; + } + } + return 0; +} + +// Convert I420 to RGBA. +LIBYUV_API +int I420ToRGBA(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgba, + int dst_stride_rgba, + int width, + int height) { + return I420ToRGBAMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgba, dst_stride_rgba, + &kYuvI601Constants, width, height); +} + +// Convert I420 to BGRA. +LIBYUV_API +int I420ToBGRA(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_bgra, + int dst_stride_bgra, + int width, + int height) { + return I420ToRGBAMatrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_bgra, dst_stride_bgra, + &kYvuI601Constants, // Use Yvu matrix + width, height); +} + +// Convert I420 to RGB24 with matrix. +LIBYUV_API +int I420ToRGB24Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I422ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I422ToRGB24Row_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; + dst_stride_rgb24 = -dst_stride_rgb24; + } +#if defined(HAS_I422TORGB24ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422ToRGB24Row = I422ToRGB24Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422ToRGB24Row = I422ToRGB24Row_SSSE3; + } + } +#endif +#if defined(HAS_I422TORGB24ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422ToRGB24Row = I422ToRGB24Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422ToRGB24Row = I422ToRGB24Row_AVX2; + } + } +#endif +#if defined(HAS_I422TORGB24ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I422ToRGB24Row = I422ToRGB24Row_AVX512BW; + } +#endif +#if defined(HAS_I422TORGB24ROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI)) { + I422ToRGB24Row = I422ToRGB24Row_AVX512VBMI; + } +#endif +#if defined(HAS_I422TORGB24ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422ToRGB24Row = I422ToRGB24Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422ToRGB24Row = I422ToRGB24Row_NEON; + } + } +#endif +#if defined(HAS_I422TORGB24ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToRGB24Row = I422ToRGB24Row_SVE2; + } +#endif +#if defined(HAS_I422TORGB24ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToRGB24Row = I422ToRGB24Row_SME; + } +#endif +#if defined(HAS_I422TORGB24ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToRGB24Row = I422ToRGB24Row_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I422ToRGB24Row = I422ToRGB24Row_LSX; + } + } +#endif +#if defined(HAS_I422TORGB24ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToRGB24Row = I422ToRGB24Row_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422ToRGB24Row = I422ToRGB24Row_LASX; + } + } +#endif +#if defined(HAS_I422TORGB24ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I422ToRGB24Row = I422ToRGB24Row_RVV; + } +#endif +#if defined(HAS_I422TORGB24ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + I422ToRGB24Row = I422ToRGB24Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + I422ToRGB24Row = I422ToRGB24Row_WASMSIMD; + } + } +#endif + + for (y = 0; y < height; ++y) { + I422ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width); + dst_rgb24 += dst_stride_rgb24; + src_y += src_stride_y; + if (y & 1) { + src_u += src_stride_u; + src_v += src_stride_v; + } + } + return 0; +} + +// Convert I420 to RGB24. +LIBYUV_API +int I420ToRGB24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height) { + return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgb24, dst_stride_rgb24, + &kYuvI601Constants, width, height); +} + +// Convert I420 to RAW. +LIBYUV_API +int I420ToRAW(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_raw, + int dst_stride_raw, + int width, + int height) { + return I420ToRGB24Matrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_raw, dst_stride_raw, + &kYvuI601Constants, // Use Yvu matrix + width, height); +} + +// Convert J420 to RGB24. +LIBYUV_API +int J420ToRGB24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height) { + return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgb24, dst_stride_rgb24, + &kYuvJPEGConstants, width, height); +} + +// Convert J420 to RAW. +LIBYUV_API +int J420ToRAW(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_raw, + int dst_stride_raw, + int width, + int height) { + return I420ToRGB24Matrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_raw, dst_stride_raw, + &kYvuJPEGConstants, // Use Yvu matrix + width, height); +} + +// Convert H420 to RGB24. +LIBYUV_API +int H420ToRGB24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height) { + return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgb24, dst_stride_rgb24, + &kYuvH709Constants, width, height); +} + +// Convert H420 to RAW. +LIBYUV_API +int H420ToRAW(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_raw, + int dst_stride_raw, + int width, + int height) { + return I420ToRGB24Matrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_raw, dst_stride_raw, + &kYvuH709Constants, // Use Yvu matrix + width, height); +} + +// Convert I422 to RGB24 with matrix. +LIBYUV_API +int I422ToRGB24Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I422ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I422ToRGB24Row_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; + dst_stride_rgb24 = -dst_stride_rgb24; + } + // Coalesce rows. + if (src_stride_y == width && src_stride_u * 2 == width && + src_stride_v * 2 == width && dst_stride_rgb24 == width * 3 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = src_stride_u = src_stride_v = dst_stride_rgb24 = 0; + } +#if defined(HAS_I422TORGB24ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422ToRGB24Row = I422ToRGB24Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422ToRGB24Row = I422ToRGB24Row_SSSE3; + } + } +#endif +#if defined(HAS_I422TORGB24ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422ToRGB24Row = I422ToRGB24Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422ToRGB24Row = I422ToRGB24Row_AVX2; + } + } +#endif +#if defined(HAS_I422TORGB24ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I422ToRGB24Row = I422ToRGB24Row_AVX512BW; + } +#endif +#if defined(HAS_I422TORGB24ROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI)) { + I422ToRGB24Row = I422ToRGB24Row_AVX512VBMI; + } +#endif +#if defined(HAS_I422TORGB24ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422ToRGB24Row = I422ToRGB24Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422ToRGB24Row = I422ToRGB24Row_NEON; + } + } +#endif +#if defined(HAS_I422TORGB24ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToRGB24Row = I422ToRGB24Row_SVE2; + } +#endif +#if defined(HAS_I422TORGB24ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToRGB24Row = I422ToRGB24Row_SME; + } +#endif +#if defined(HAS_I422TORGB24ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToRGB24Row = I422ToRGB24Row_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I422ToRGB24Row = I422ToRGB24Row_LSX; + } + } +#endif +#if defined(HAS_I422TORGB24ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToRGB24Row = I422ToRGB24Row_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422ToRGB24Row = I422ToRGB24Row_LASX; + } + } +#endif +#if defined(HAS_I422TORGB24ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I422ToRGB24Row = I422ToRGB24Row_RVV; + } +#endif +#if defined(HAS_I422TORGB24ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + I422ToRGB24Row = I422ToRGB24Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + I422ToRGB24Row = I422ToRGB24Row_WASMSIMD; + } + } +#endif + + for (y = 0; y < height; ++y) { + I422ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width); + dst_rgb24 += dst_stride_rgb24; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + +// Convert I422 to RGB24. +LIBYUV_API +int I422ToRGB24(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height) { + return I422ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgb24, dst_stride_rgb24, + &kYuvI601Constants, width, height); +} + +// Convert I422 to RAW. +LIBYUV_API +int I422ToRAW(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_raw, + int dst_stride_raw, + int width, + int height) { + return I422ToRGB24Matrix(src_y, src_stride_y, src_v, + src_stride_v, // Swap U and V + src_u, src_stride_u, dst_raw, dst_stride_raw, + &kYvuI601Constants, // Use Yvu matrix + width, height); +} + +// Convert I420 to ARGB1555. +LIBYUV_API +int I420ToARGB1555(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb1555, + int dst_stride_argb1555, + int width, + int height) { + int y; + void (*I422ToARGB1555Row)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width) = I422ToARGB1555Row_C; + if (!src_y || !src_u || !src_v || !dst_argb1555 || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb1555 = dst_argb1555 + (ptrdiff_t)(height - 1) * dst_stride_argb1555; + dst_stride_argb1555 = -dst_stride_argb1555; + } +#if defined(HAS_I422TOARGB1555ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422ToARGB1555Row = I422ToARGB1555Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422ToARGB1555Row = I422ToARGB1555Row_SSSE3; + } + } +#endif +#if defined(HAS_I422TOARGB1555ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422ToARGB1555Row = I422ToARGB1555Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422ToARGB1555Row = I422ToARGB1555Row_AVX2; + } + } +#endif +#if defined(HAS_I422TOARGB1555ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == + (kCpuHasAVX512BW | kCpuHasAVX512VL)) { + I422ToARGB1555Row = I422ToARGB1555Row_AVX512BW; + } +#endif +#if defined(HAS_I422TOARGB1555ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422ToARGB1555Row = I422ToARGB1555Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422ToARGB1555Row = I422ToARGB1555Row_NEON; + } + } +#endif +#if defined(HAS_I422TOARGB1555ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToARGB1555Row = I422ToARGB1555Row_SVE2; + } +#endif +#if defined(HAS_I422TOARGB1555ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToARGB1555Row = I422ToARGB1555Row_SME; + } +#endif +#if defined(HAS_I422TOARGB1555ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToARGB1555Row = I422ToARGB1555Row_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I422ToARGB1555Row = I422ToARGB1555Row_LSX; + } + } +#endif +#if defined(HAS_I422TOARGB1555ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToARGB1555Row = I422ToARGB1555Row_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422ToARGB1555Row = I422ToARGB1555Row_LASX; + } + } +#endif +#if defined(HAS_I422TOARGB1555ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + I422ToARGB1555Row = I422ToARGB1555Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + I422ToARGB1555Row = I422ToARGB1555Row_WASMSIMD; + } + } +#endif + + for (y = 0; y < height; ++y) { + I422ToARGB1555Row(src_y, src_u, src_v, dst_argb1555, &kYuvI601Constants, + width); + dst_argb1555 += dst_stride_argb1555; + src_y += src_stride_y; + if (y & 1) { + src_u += src_stride_u; + src_v += src_stride_v; + } + } + return 0; +} + +// Convert I420 to ARGB4444. +LIBYUV_API +int I420ToARGB4444(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb4444, + int dst_stride_argb4444, + int width, + int height) { + int y; + void (*I422ToARGB4444Row)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width) = I422ToARGB4444Row_C; + if (!src_y || !src_u || !src_v || !dst_argb4444 || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb4444 = dst_argb4444 + (ptrdiff_t)(height - 1) * dst_stride_argb4444; + dst_stride_argb4444 = -dst_stride_argb4444; + } +#if defined(HAS_I422TOARGB4444ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422ToARGB4444Row = I422ToARGB4444Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422ToARGB4444Row = I422ToARGB4444Row_SSSE3; + } + } +#endif +#if defined(HAS_I422TOARGB4444ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422ToARGB4444Row = I422ToARGB4444Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422ToARGB4444Row = I422ToARGB4444Row_AVX2; + } + } +#endif +#if defined(HAS_I422TOARGB4444ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == + (kCpuHasAVX512BW | kCpuHasAVX512VL)) { + I422ToARGB4444Row = I422ToARGB4444Row_AVX512BW; + } +#endif +#if defined(HAS_I422TOARGB4444ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422ToARGB4444Row = I422ToARGB4444Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422ToARGB4444Row = I422ToARGB4444Row_NEON; + } + } +#endif +#if defined(HAS_I422TOARGB4444ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToARGB4444Row = I422ToARGB4444Row_SVE2; + } +#endif +#if defined(HAS_I422TOARGB4444ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToARGB4444Row = I422ToARGB4444Row_SME; + } +#endif +#if defined(HAS_I422TOARGB4444ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToARGB4444Row = I422ToARGB4444Row_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I422ToARGB4444Row = I422ToARGB4444Row_LSX; + } + } +#endif +#if defined(HAS_I422TOARGB4444ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToARGB4444Row = I422ToARGB4444Row_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422ToARGB4444Row = I422ToARGB4444Row_LASX; + } + } +#endif +#if defined(HAS_I422TOARGB4444ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + I422ToARGB4444Row = I422ToARGB4444Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + I422ToARGB4444Row = I422ToARGB4444Row_WASMSIMD; + } + } +#endif + + for (y = 0; y < height; ++y) { + I422ToARGB4444Row(src_y, src_u, src_v, dst_argb4444, &kYuvI601Constants, + width); + dst_argb4444 += dst_stride_argb4444; + src_y += src_stride_y; + if (y & 1) { + src_u += src_stride_u; + src_v += src_stride_v; + } + } + return 0; +} + +// Convert I420 to RGB565 with specified color matrix. +LIBYUV_API +int I420ToRGB565Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I422ToRGB565Row)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I422ToRGB565Row_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; + dst_stride_rgb565 = -dst_stride_rgb565; + } +#if defined(HAS_I422TORGB565ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422ToRGB565Row = I422ToRGB565Row_SSSE3; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422ToRGB565Row = I422ToRGB565Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422ToRGB565Row = I422ToRGB565Row_AVX2; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == + (kCpuHasAVX512BW | kCpuHasAVX512VL)) { + I422ToRGB565Row = I422ToRGB565Row_AVX512BW; + } +#endif +#if defined(HAS_I422TORGB565ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422ToRGB565Row = I422ToRGB565Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422ToRGB565Row = I422ToRGB565Row_NEON; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToRGB565Row = I422ToRGB565Row_SVE2; + } +#endif +#if defined(HAS_I422TORGB565ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToRGB565Row = I422ToRGB565Row_SME; + } +#endif +#if defined(HAS_I422TORGB565ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToRGB565Row = I422ToRGB565Row_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I422ToRGB565Row = I422ToRGB565Row_LSX; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToRGB565Row = I422ToRGB565Row_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422ToRGB565Row = I422ToRGB565Row_LASX; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + I422ToRGB565Row = I422ToRGB565Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + I422ToRGB565Row = I422ToRGB565Row_WASMSIMD; + } + } +#endif + + for (y = 0; y < height; ++y) { + I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, yuvconstants, width); + dst_rgb565 += dst_stride_rgb565; + src_y += src_stride_y; + if (y & 1) { + src_u += src_stride_u; + src_v += src_stride_v; + } + } + return 0; +} + +// Convert I420 to RGB565. +LIBYUV_API +int I420ToRGB565(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + int width, + int height) { + return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgb565, dst_stride_rgb565, + &kYuvI601Constants, width, height); +} + +// Convert J420 to RGB565. +LIBYUV_API +int J420ToRGB565(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + int width, + int height) { + return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgb565, dst_stride_rgb565, + &kYuvJPEGConstants, width, height); +} + +// Convert H420 to RGB565. +LIBYUV_API +int H420ToRGB565(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + int width, + int height) { + return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgb565, dst_stride_rgb565, + &kYuvH709Constants, width, height); +} + +// Convert I422 to RGB565 with specified color matrix. +LIBYUV_API +int I422ToRGB565Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I422ToRGB565Row)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I422ToRGB565Row_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; + dst_stride_rgb565 = -dst_stride_rgb565; + } + // Coalesce rows. + if (src_stride_y == width && src_stride_u * 2 == width && + src_stride_v * 2 == width && dst_stride_rgb565 == width * 2 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = src_stride_u = src_stride_v = dst_stride_rgb565 = 0; + } +#if defined(HAS_I422TORGB565ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422ToRGB565Row = I422ToRGB565Row_SSSE3; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422ToRGB565Row = I422ToRGB565Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422ToRGB565Row = I422ToRGB565Row_AVX2; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == + (kCpuHasAVX512BW | kCpuHasAVX512VL)) { + I422ToRGB565Row = I422ToRGB565Row_AVX512BW; + } +#endif +#if defined(HAS_I422TORGB565ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422ToRGB565Row = I422ToRGB565Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422ToRGB565Row = I422ToRGB565Row_NEON; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToRGB565Row = I422ToRGB565Row_SVE2; + } +#endif +#if defined(HAS_I422TORGB565ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToRGB565Row = I422ToRGB565Row_SME; + } +#endif +#if defined(HAS_I422TORGB565ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToRGB565Row = I422ToRGB565Row_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I422ToRGB565Row = I422ToRGB565Row_LSX; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToRGB565Row = I422ToRGB565Row_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422ToRGB565Row = I422ToRGB565Row_LASX; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + I422ToRGB565Row = I422ToRGB565Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + I422ToRGB565Row = I422ToRGB565Row_WASMSIMD; + } + } +#endif + + for (y = 0; y < height; ++y) { + I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, yuvconstants, width); + dst_rgb565 += dst_stride_rgb565; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + +// Convert I422 to RGB565. +LIBYUV_API +int I422ToRGB565(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + int width, + int height) { + return I422ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgb565, dst_stride_rgb565, + &kYuvI601Constants, width, height); +} + +// Ordered 8x8 dither for 888 to 565. Values from 0 to 7. +static const uint8_t kDither565_4x4[16] = { + 0, 4, 1, 5, 6, 2, 7, 3, 1, 5, 0, 4, 7, 3, 6, 2, +}; + +// Convert I420 to RGB565 with dithering. +LIBYUV_API +int I420ToRGB565Dither(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb565, + int dst_stride_rgb565, + const uint8_t* dither4x4, + int width, + int height) { + int y; + uint32_t dither4[4]; + void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I422ToARGBRow_C; + void (*ARGBToRGB565DitherRow)(const uint8_t* src_argb, uint8_t* dst_rgb, + uint32_t dither4, int width) = + ARGBToRGB565DitherRow_C; + if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; + dst_stride_rgb565 = -dst_stride_rgb565; + } + if (!dither4x4) { + dither4x4 = kDither565_4x4; + } + memcpy(dither4, dither4x4, 16); +#if defined(HAS_I422TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422ToARGBRow = I422ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422ToARGBRow = I422ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I422TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422ToARGBRow = I422ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422ToARGBRow = I422ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I422TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == + (kCpuHasAVX512BW | kCpuHasAVX512VL)) { + I422ToARGBRow = I422ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_I422TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422ToARGBRow = I422ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422ToARGBRow = I422ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I422TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToARGBRow = I422ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I422TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToARGBRow = I422ToARGBRow_SME; + } +#endif +#if defined(HAS_I422TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToARGBRow = I422ToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I422ToARGBRow = I422ToARGBRow_LSX; + } + } +#endif +#if defined(HAS_I422TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToARGBRow = I422ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I422ToARGBRow = I422ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_I422TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I422ToARGBRow = I422ToARGBRow_RVV; + } +#endif +#if defined(HAS_I422TOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + I422ToARGBRow = I422ToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + I422ToARGBRow = I422ToARGBRow_WASMSIMD; + } + } +#endif +#if defined(HAS_I422TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I422ToARGBRow = I422ToARGBRow_HVX; + } +#endif +#if defined(HAS_ARGBTORGB565DITHERROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTORGB565DITHERROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTORGB565DITHERROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTORGB565DITHERROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_SVE2; + } +#endif +#if defined(HAS_ARGBTORGB565DITHERROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTORGB565DITHERROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTORGB565DITHERROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_WASMSIMD; + } + } +#endif + { + // Allocate a row of argb. + align_buffer_64(row_argb, width * 4); + if (!row_argb) + return 1; + for (y = 0; y < height; ++y) { + I422ToARGBRow(src_y, src_u, src_v, row_argb, &kYuvI601Constants, width); + ARGBToRGB565DitherRow(row_argb, dst_rgb565, dither4[y & 3], width); + dst_rgb565 += dst_stride_rgb565; + src_y += src_stride_y; + if (y & 1) { + src_u += src_stride_u; + src_v += src_stride_v; + } + } + free_aligned_buffer_64(row_argb); + } + return 0; +} + +// Convert I420 to AR30 with matrix. +LIBYUV_API +int I420ToAR30Matrix(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I422ToAR30Row)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I422ToAR30Row_C; + + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } + +#if defined(HAS_I422TOAR30ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422ToAR30Row = I422ToAR30Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422ToAR30Row = I422ToAR30Row_SSSE3; + } + } +#endif +#if defined(HAS_I422TOAR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422ToAR30Row = I422ToAR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422ToAR30Row = I422ToAR30Row_AVX2; + } + } +#endif +#if defined(HAS_I422TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == + (kCpuHasAVX512BW | kCpuHasAVX512VL)) { + I422ToAR30Row = I422ToAR30Row_AVX512BW; + } +#endif +#if defined(HAS_I422TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422ToAR30Row = I422ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422ToAR30Row = I422ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_I422TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I422ToAR30Row = I422ToAR30Row_SVE2; + } +#endif +#if defined(HAS_I422TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I422ToAR30Row = I422ToAR30Row_SME; + } +#endif +#if defined(HAS_I422TOAR30ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I422ToAR30Row = I422ToAR30Row_RVV; + } +#endif +#if defined(HAS_I422TOAR30ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + I422ToAR30Row = I422ToAR30Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + I422ToAR30Row = I422ToAR30Row_WASMSIMD; + } + } +#endif + + for (y = 0; y < height; ++y) { + I422ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + if (y & 1) { + src_u += src_stride_u; + src_v += src_stride_v; + } + } + return 0; +} + +// Convert I420 to AR30. +LIBYUV_API +int I420ToAR30(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height) { + return I420ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_ar30, dst_stride_ar30, + &kYuvI601Constants, width, height); +} + +// Convert H420 to AR30. +LIBYUV_API +int H420ToAR30(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height) { + return I420ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_ar30, dst_stride_ar30, + &kYvuH709Constants, width, height); +} + +// Convert I420 to AB30. +LIBYUV_API +int I420ToAB30(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height) { + return I420ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, + src_stride_u, dst_ab30, dst_stride_ab30, + &kYvuI601Constants, width, height); +} + +// Convert H420 to AB30. +LIBYUV_API +int H420ToAB30(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_ab30, + int dst_stride_ab30, + int width, + int height) { + return I420ToAR30Matrix(src_y, src_stride_y, src_v, src_stride_v, src_u, + src_stride_u, dst_ab30, dst_stride_ab30, + &kYvuH709Constants, width, height); +} + +static int I420ToARGBMatrixBilinear(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I444ToARGBRow_C; + void (*Scale2RowUp_Bilinear)(const uint8_t* src_ptr, ptrdiff_t src_stride, + uint8_t* dst_ptr, ptrdiff_t dst_stride, + int dst_width) = ScaleRowUp2_Bilinear_Any_C; + void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I444TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I444ToARGBRow = I444ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I444TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I444ToARGBRow = I444ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I444ToARGBRow = I444ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I444TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I444ToARGBRow = I444ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_I444TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I444ToARGBRow = I444ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I444TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I444ToARGBRow = I444ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I444TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I444ToARGBRow = I444ToARGBRow_SME; + } +#endif +#if defined(HAS_I444TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I444ToARGBRow = I444ToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_LSX; + } + } +#endif +#if defined(HAS_I444TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I444ToARGBRow = I444ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I444ToARGBRow = I444ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_I444TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I444ToARGBRow = I444ToARGBRow_RVV; + } +#endif +#if defined(HAS_I444TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I444ToARGBRow = I444ToARGBRow_HVX; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSE2; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSSE3; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_AVX2; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_NEON; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; + } +#endif +#if defined(HAS_SCALEROWUP2_BILINEAR_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_RVV; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; + } +#endif + + // alloc 4 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 4); + uint8_t* temp_u_1 = row; + uint8_t* temp_u_2 = row + row_size; + uint8_t* temp_v_1 = row + row_size * 2; + uint8_t* temp_v_2 = row + row_size * 3; + if (!row) + return 1; + + ScaleRowUp2_Linear(src_u, temp_u_1, width); + ScaleRowUp2_Linear(src_v, temp_v_1, width); + I444ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + + for (y = 0; y < height - 2; y += 2) { + Scale2RowUp_Bilinear(src_u, src_stride_u, temp_u_1, row_size, width); + Scale2RowUp_Bilinear(src_v, src_stride_v, temp_v_1, row_size, width); + I444ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + I444ToARGBRow(src_y, temp_u_2, temp_v_2, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + + if (!(height & 1)) { + ScaleRowUp2_Linear(src_u, temp_u_1, width); + ScaleRowUp2_Linear(src_v, temp_v_1, width); + I444ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); + } + + free_aligned_buffer_64(row); + return 0; +} + +static int I422ToARGBMatrixLinear(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I444ToARGBRow_C; + void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I444TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I444ToARGBRow = I444ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I444TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I444ToARGBRow = I444ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I444ToARGBRow = I444ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I444TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I444ToARGBRow = I444ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_I444TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I444ToARGBRow = I444ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I444TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I444ToARGBRow = I444ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I444TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I444ToARGBRow = I444ToARGBRow_SME; + } +#endif +#if defined(HAS_I444TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I444ToARGBRow = I444ToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_LSX; + } + } +#endif +#if defined(HAS_I444TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I444ToARGBRow = I444ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I444ToARGBRow = I444ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_I444TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I444ToARGBRow = I444ToARGBRow_RVV; + } +#endif +#if defined(HAS_I444TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I444ToARGBRow = I444ToARGBRow_HVX; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; + } +#endif + + // alloc 2 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 2); + uint8_t* temp_u = row; + uint8_t* temp_v = row + row_size; + if (!row) + return 1; + + for (y = 0; y < height; ++y) { + ScaleRowUp2_Linear(src_u, temp_u, width); + ScaleRowUp2_Linear(src_v, temp_v, width); + I444ToARGBRow(src_y, temp_u, temp_v, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + + free_aligned_buffer_64(row); + return 0; +} + +static int I420ToRGB24MatrixBilinear(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I444ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I444ToRGB24Row_C; + void (*Scale2RowUp_Bilinear)(const uint8_t* src_ptr, ptrdiff_t src_stride, + uint8_t* dst_ptr, ptrdiff_t dst_stride, + int dst_width) = ScaleRowUp2_Bilinear_Any_C; + void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; + dst_stride_rgb24 = -dst_stride_rgb24; + } +#if defined(HAS_I444TORGB24ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I444ToRGB24Row = I444ToRGB24Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I444ToRGB24Row = I444ToRGB24Row_SSSE3; + } + } +#endif +#if defined(HAS_I444TORGB24ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I444ToRGB24Row = I444ToRGB24Row_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + I444ToRGB24Row = I444ToRGB24Row_AVX2; + } + } +#endif +#if defined(HAS_I444TORGB24ROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI)) { + I444ToRGB24Row = I444ToRGB24Row_AVX512VBMI; + } +#endif +#if defined(HAS_I444TORGB24ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I444ToRGB24Row = I444ToRGB24Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I444ToRGB24Row = I444ToRGB24Row_NEON; + } + } +#endif +#if defined(HAS_I444TORGB24ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I444ToRGB24Row = I444ToRGB24Row_SVE2; + } +#endif +#if defined(HAS_I444TORGB24ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I444ToRGB24Row = I444ToRGB24Row_SME; + } +#endif +#if defined(HAS_I444TORGB24ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I444ToRGB24Row = I444ToRGB24Row_RVV; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSE2; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSSE3; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_AVX2; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_NEON; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; + } +#endif +#if defined(HAS_SCALEROWUP2_BILINEAR_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_RVV; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; + } +#endif + + // alloc 4 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 4); + uint8_t* temp_u_1 = row; + uint8_t* temp_u_2 = row + row_size; + uint8_t* temp_v_1 = row + row_size * 2; + uint8_t* temp_v_2 = row + row_size * 3; + if (!row) + return 1; + + ScaleRowUp2_Linear(src_u, temp_u_1, width); + ScaleRowUp2_Linear(src_v, temp_v_1, width); + I444ToRGB24Row(src_y, temp_u_1, temp_v_1, dst_rgb24, yuvconstants, width); + dst_rgb24 += dst_stride_rgb24; + src_y += src_stride_y; + + for (y = 0; y < height - 2; y += 2) { + Scale2RowUp_Bilinear(src_u, src_stride_u, temp_u_1, row_size, width); + Scale2RowUp_Bilinear(src_v, src_stride_v, temp_v_1, row_size, width); + I444ToRGB24Row(src_y, temp_u_1, temp_v_1, dst_rgb24, yuvconstants, width); + dst_rgb24 += dst_stride_rgb24; + src_y += src_stride_y; + I444ToRGB24Row(src_y, temp_u_2, temp_v_2, dst_rgb24, yuvconstants, width); + dst_rgb24 += dst_stride_rgb24; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + + if (!(height & 1)) { + ScaleRowUp2_Linear(src_u, temp_u_1, width); + ScaleRowUp2_Linear(src_v, temp_v_1, width); + I444ToRGB24Row(src_y, temp_u_1, temp_v_1, dst_rgb24, yuvconstants, width); + } + + free_aligned_buffer_64(row); + return 0; +} + +static int I010ToAR30MatrixBilinear(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I410ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I410ToAR30Row_C; + void (*Scale2RowUp_Bilinear_12)( + const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, + ptrdiff_t dst_stride, int dst_width) = ScaleRowUp2_Bilinear_16_Any_C; + void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_16_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } +#if defined(HAS_I410TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I410ToAR30Row = I410ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I410ToAR30Row = I410ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_I410TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410ToAR30Row = I410ToAR30Row_SVE2; + } +#endif +#if defined(HAS_I410TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I410ToAR30Row = I410ToAR30Row_SME; + } +#endif +#if defined(HAS_I410TOAR30ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I410ToAR30Row = I410ToAR30Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I410ToAR30Row = I410ToAR30Row_SSSE3; + } + } +#endif +#if defined(HAS_I410TOAR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I410ToAR30Row = I410ToAR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I410ToAR30Row = I410ToAR30Row_AVX2; + } + } +#endif +#if defined(HAS_I410TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I410ToAR30Row = I410ToAR30Row_AVX512BW; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_12_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_SSSE3; + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_12_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_AVX2; + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_12_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_NEON; + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON; + } +#endif + + // alloc 4 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 4 * sizeof(uint16_t)); + uint16_t* temp_u_1 = (uint16_t*)(row); + uint16_t* temp_u_2 = (uint16_t*)(row) + row_size; + uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2; + uint16_t* temp_v_2 = (uint16_t*)(row) + row_size * 3; + if (!row) + return 1; + + ScaleRowUp2_Linear_12(src_u, temp_u_1, width); + ScaleRowUp2_Linear_12(src_v, temp_v_1, width); + I410ToAR30Row(src_y, temp_u_1, temp_v_1, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + + for (y = 0; y < height - 2; y += 2) { + Scale2RowUp_Bilinear_12(src_u, src_stride_u, temp_u_1, row_size, width); + Scale2RowUp_Bilinear_12(src_v, src_stride_v, temp_v_1, row_size, width); + I410ToAR30Row(src_y, temp_u_1, temp_v_1, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + I410ToAR30Row(src_y, temp_u_2, temp_v_2, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + + if (!(height & 1)) { + ScaleRowUp2_Linear_12(src_u, temp_u_1, width); + ScaleRowUp2_Linear_12(src_v, temp_v_1, width); + I410ToAR30Row(src_y, temp_u_1, temp_v_1, dst_ar30, yuvconstants, width); + } + + free_aligned_buffer_64(row); + + return 0; +} + +static int I210ToAR30MatrixLinear(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I410ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I410ToAR30Row_C; + void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_16_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } +#if defined(HAS_I410TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I410ToAR30Row = I410ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I410ToAR30Row = I410ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_I410TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410ToAR30Row = I410ToAR30Row_SVE2; + } +#endif +#if defined(HAS_I410TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I410ToAR30Row = I410ToAR30Row_SME; + } +#endif +#if defined(HAS_I410TOAR30ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I410ToAR30Row = I410ToAR30Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I410ToAR30Row = I410ToAR30Row_SSSE3; + } + } +#endif +#if defined(HAS_I410TOAR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I410ToAR30Row = I410ToAR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I410ToAR30Row = I410ToAR30Row_AVX2; + } + } +#endif +#if defined(HAS_I410TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I410ToAR30Row = I410ToAR30Row_AVX512BW; + } +#endif + +#if defined(HAS_SCALEROWUP2_LINEAR_12_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_12_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_12_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON; + } +#endif + + // alloc 2 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); + uint16_t* temp_u = (uint16_t*)(row); + uint16_t* temp_v = (uint16_t*)(row) + row_size; + if (!row) + return 1; + + for (y = 0; y < height; ++y) { + ScaleRowUp2_Linear_12(src_u, temp_u, width); + ScaleRowUp2_Linear_12(src_v, temp_v, width); + I410ToAR30Row(src_y, temp_u, temp_v, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + free_aligned_buffer_64(row); + return 0; +} + +static int I010ToARGBMatrixBilinear(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I410ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I410ToARGBRow_C; + void (*Scale2RowUp_Bilinear_12)( + const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, + ptrdiff_t dst_stride, int dst_width) = ScaleRowUp2_Bilinear_16_Any_C; + void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_16_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I410TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I410ToARGBRow = I410ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I410ToARGBRow = I410ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I410TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I410ToARGBRow = I410ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I410ToARGBRow = I410ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I410TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410ToARGBRow = I410ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I410TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I410ToARGBRow = I410ToARGBRow_SME; + } +#endif +#if defined(HAS_I410TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I410ToARGBRow = I410ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I410ToARGBRow = I410ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I410TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I410ToARGBRow = I410ToARGBRow_AVX512BW; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_12_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_SSSE3; + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_12_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_AVX2; + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_12_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_NEON; + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON; + } +#endif + + // alloc 4 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 4 * sizeof(uint16_t)); + uint16_t* temp_u_1 = (uint16_t*)(row); + uint16_t* temp_u_2 = (uint16_t*)(row) + row_size; + uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2; + uint16_t* temp_v_2 = (uint16_t*)(row) + row_size * 3; + if (!row) + return 1; + + ScaleRowUp2_Linear_12(src_u, temp_u_1, width); + ScaleRowUp2_Linear_12(src_v, temp_v_1, width); + I410ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + + for (y = 0; y < height - 2; y += 2) { + Scale2RowUp_Bilinear_12(src_u, src_stride_u, temp_u_1, row_size, width); + Scale2RowUp_Bilinear_12(src_v, src_stride_v, temp_v_1, row_size, width); + I410ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + I410ToARGBRow(src_y, temp_u_2, temp_v_2, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + + if (!(height & 1)) { + ScaleRowUp2_Linear_12(src_u, temp_u_1, width); + ScaleRowUp2_Linear_12(src_v, temp_v_1, width); + I410ToARGBRow(src_y, temp_u_1, temp_v_1, dst_argb, yuvconstants, width); + } + + free_aligned_buffer_64(row); + return 0; +} + +static int I210ToARGBMatrixLinear(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I410ToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I410ToARGBRow_C; + void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_16_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I410TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I410ToARGBRow = I410ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I410ToARGBRow = I410ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I410TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I410ToARGBRow = I410ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I410ToARGBRow = I410ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I410TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410ToARGBRow = I410ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I410TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I410ToARGBRow = I410ToARGBRow_SME; + } +#endif +#if defined(HAS_I410TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I410ToARGBRow = I410ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I410ToARGBRow = I410ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I410TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I410ToARGBRow = I410ToARGBRow_AVX512BW; + } +#endif + +#if defined(HAS_SCALEROWUP2_LINEAR_12_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_12_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_12_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON; + } +#endif + + // alloc 2 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); + uint16_t* temp_u = (uint16_t*)(row); + uint16_t* temp_v = (uint16_t*)(row) + row_size; + if (!row) + return 1; + + for (y = 0; y < height; ++y) { + ScaleRowUp2_Linear_12(src_u, temp_u, width); + ScaleRowUp2_Linear_12(src_v, temp_v, width); + I410ToARGBRow(src_y, temp_u, temp_v, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + + free_aligned_buffer_64(row); + return 0; +} + +static int I420AlphaToARGBMatrixBilinear( + const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate) { + int y; + void (*I444AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) = I444AlphaToARGBRow_C; + void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, + int width) = ARGBAttenuateRow_C; + void (*Scale2RowUp_Bilinear)(const uint8_t* src_ptr, ptrdiff_t src_stride, + uint8_t* dst_ptr, ptrdiff_t dst_stride, + int dst_width) = ScaleRowUp2_Bilinear_Any_C; + void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I444ALPHATOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_SVE2; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_SME; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_RVV; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_HVX; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_NEON; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAttenuateRow = ARGBAttenuateRow_RVV; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_LSX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_LASX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAttenuateRow = ARGBAttenuateRow_HVX; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSE2; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_SSSE3; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_AVX2; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_Any_NEON; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; + } +#endif +#if defined(HAS_SCALEROWUP2_BILINEAR_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Scale2RowUp_Bilinear = ScaleRowUp2_Bilinear_RVV; + ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; + } +#endif + + // alloc 4 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 4); + uint8_t* temp_u_1 = row; + uint8_t* temp_u_2 = row + row_size; + uint8_t* temp_v_1 = row + row_size * 2; + uint8_t* temp_v_2 = row + row_size * 3; + if (!row) + return 1; + + ScaleRowUp2_Linear(src_u, temp_u_1, width); + ScaleRowUp2_Linear(src_v, temp_v_1, width); + I444AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_a += src_stride_a; + + for (y = 0; y < height - 2; y += 2) { + Scale2RowUp_Bilinear(src_u, src_stride_u, temp_u_1, row_size, width); + Scale2RowUp_Bilinear(src_v, src_stride_v, temp_v_1, row_size, width); + I444AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_a += src_stride_a; + I444AlphaToARGBRow(src_y, temp_u_2, temp_v_2, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + src_a += src_stride_a; + } + + if (!(height & 1)) { + ScaleRowUp2_Linear(src_u, temp_u_1, width); + ScaleRowUp2_Linear(src_v, temp_v_1, width); + I444AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + } + + free_aligned_buffer_64(row); + return 0; +} + +static int I422AlphaToARGBMatrixLinear(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate) { + int y; + void (*I444AlphaToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) = I444AlphaToARGBRow_C; + void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, + int width) = ARGBAttenuateRow_C; + void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I444ALPHATOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_SVE2; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_SME; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_RVV; + } +#endif +#if defined(HAS_I444ALPHATOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I444AlphaToARGBRow = I444AlphaToARGBRow_HVX; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_NEON; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAttenuateRow = ARGBAttenuateRow_RVV; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_LSX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_LASX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAttenuateRow = ARGBAttenuateRow_HVX; + } +#endif + +#if defined(HAS_SCALEROWUP2_LINEAR_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; + } +#endif + + // alloc 2 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 2); + uint8_t* temp_u = row; + uint8_t* temp_v = row + row_size; + if (!row) + return 1; + + for (y = 0; y < height; ++y) { + ScaleRowUp2_Linear(src_u, temp_u, width); + ScaleRowUp2_Linear(src_v, temp_v, width); + I444AlphaToARGBRow(src_y, temp_u, temp_v, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_a += src_stride_a; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + + free_aligned_buffer_64(row); + return 0; +} + +static int I010AlphaToARGBMatrixBilinear( + const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate) { + int y; + void (*I410AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) = I410AlphaToARGBRow_C; + void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, + int width) = ARGBAttenuateRow_C; + void (*Scale2RowUp_Bilinear_12)( + const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, + ptrdiff_t dst_stride, int dst_width) = ScaleRowUp2_Bilinear_16_Any_C; + void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_16_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I410ALPHATOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_SVE2; + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_SME; + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_NEON; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAttenuateRow = ARGBAttenuateRow_RVV; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_LSX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_LASX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAttenuateRow = ARGBAttenuateRow_HVX; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_12_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_SSSE3; + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_SSSE3; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_12_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_AVX2; + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_AVX2; + } +#endif + +#if defined(HAS_SCALEROWUP2_BILINEAR_12_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp_Bilinear_12 = ScaleRowUp2_Bilinear_12_Any_NEON; + ScaleRowUp2_Linear_12 = ScaleRowUp2_Linear_12_Any_NEON; + } +#endif + + // alloc 4 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 4 * sizeof(uint16_t)); + uint16_t* temp_u_1 = (uint16_t*)(row); + uint16_t* temp_u_2 = (uint16_t*)(row) + row_size; + uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2; + uint16_t* temp_v_2 = (uint16_t*)(row) + row_size * 3; + if (!row) + return 1; + + ScaleRowUp2_Linear_12(src_u, temp_u_1, width); + ScaleRowUp2_Linear_12(src_v, temp_v_1, width); + I410AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_a += src_stride_a; + + for (y = 0; y < height - 2; y += 2) { + Scale2RowUp_Bilinear_12(src_u, src_stride_u, temp_u_1, row_size, width); + Scale2RowUp_Bilinear_12(src_v, src_stride_v, temp_v_1, row_size, width); + I410AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_a += src_stride_a; + I410AlphaToARGBRow(src_y, temp_u_2, temp_v_2, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_a += src_stride_a; + src_u += src_stride_u; + src_v += src_stride_v; + } + + if (!(height & 1)) { + ScaleRowUp2_Linear_12(src_u, temp_u_1, width); + ScaleRowUp2_Linear_12(src_v, temp_v_1, width); + I410AlphaToARGBRow(src_y, temp_u_1, temp_v_1, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + } + + free_aligned_buffer_64(row); + return 0; +} + +static int I210AlphaToARGBMatrixLinear(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate) { + int y; + void (*I410AlphaToARGBRow)(const uint16_t* y_buf, const uint16_t* u_buf, + const uint16_t* v_buf, const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) = I410AlphaToARGBRow_C; + void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, + int width) = ARGBAttenuateRow_C; + void (*ScaleRowUp2_Linear)(const uint16_t* src_ptr, uint16_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_16_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I410ALPHATOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_SVE2; + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_SME; + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I410ALPHATOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I410AlphaToARGBRow = I410AlphaToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_NEON; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAttenuateRow = ARGBAttenuateRow_RVV; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_LSX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_LASX; + } + } +#endif +#if defined(HAS_ARGBATTENUATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAttenuateRow = ARGBAttenuateRow_HVX; + } +#endif + +#if defined(HAS_SCALEROWUP2_LINEAR_12_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_12_Any_SSSE3; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_12_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_12_Any_AVX2; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_12_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_12_Any_NEON; + } +#endif + + // alloc 2 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); + uint16_t* temp_u = (uint16_t*)(row); + uint16_t* temp_v = (uint16_t*)(row) + row_size; + if (!row) + return 1; + + for (y = 0; y < height; ++y) { + ScaleRowUp2_Linear(src_u, temp_u, width); + ScaleRowUp2_Linear(src_v, temp_v, width); + I410AlphaToARGBRow(src_y, temp_u, temp_v, src_a, dst_argb, yuvconstants, + width); + if (attenuate) { + ARGBAttenuateRow(dst_argb, dst_argb, width); + } + dst_argb += dst_stride_argb; + src_a += src_stride_a; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + free_aligned_buffer_64(row); + return 0; +} + +static int P010ToARGBMatrixBilinear(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*P410ToARGBRow)( + const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = P410ToARGBRow_C; + void (*Scale2RowUp_Bilinear_16)( + const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, + ptrdiff_t dst_stride, int dst_width) = ScaleUVRowUp2_Bilinear_16_Any_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_P410TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + P410ToARGBRow = P410ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + P410ToARGBRow = P410ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_P410TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + P410ToARGBRow = P410ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + P410ToARGBRow = P410ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_P410TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + P410ToARGBRow = P410ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_P410TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + P410ToARGBRow = P410ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + P410ToARGBRow = P410ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_P410TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + P410ToARGBRow = P410ToARGBRow_SVE2; + } +#endif +#if defined(HAS_P410TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + P410ToARGBRow = P410ToARGBRow_SME; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_SSE41 + if (TestCpuFlag(kCpuHasSSE41)) { + Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_SSE41; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_NEON + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_NEON; + } +#endif + + // alloc 2 lines temp + const int row_size = (2 * width + 31) & ~31; + align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); + uint16_t* temp_uv_1 = (uint16_t*)(row); + uint16_t* temp_uv_2 = (uint16_t*)(row) + row_size; + if (!row) + return 1; + + Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width); + P410ToARGBRow(src_y, temp_uv_1, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + + for (y = 0; y < height - 2; y += 2) { + Scale2RowUp_Bilinear_16(src_uv, src_stride_uv, temp_uv_1, row_size, width); + P410ToARGBRow(src_y, temp_uv_1, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + P410ToARGBRow(src_y, temp_uv_2, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_uv += src_stride_uv; + } + + if (!(height & 1)) { + Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width); + P410ToARGBRow(src_y, temp_uv_1, dst_argb, yuvconstants, width); + } + + free_aligned_buffer_64(row); + return 0; +} + +static int P210ToARGBMatrixLinear(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*P410ToARGBRow)( + const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = P410ToARGBRow_C; + void (*ScaleRowUp2_Linear)(const uint16_t* src_uv, uint16_t* dst_uv, + int dst_width) = ScaleUVRowUp2_Linear_16_Any_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_P410TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + P410ToARGBRow = P410ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + P410ToARGBRow = P410ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_P410TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + P410ToARGBRow = P410ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + P410ToARGBRow = P410ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_P410TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + P410ToARGBRow = P410ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_P410TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + P410ToARGBRow = P410ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + P410ToARGBRow = P410ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_P410TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + P410ToARGBRow = P410ToARGBRow_SVE2; + } +#endif +#if defined(HAS_P410TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + P410ToARGBRow = P410ToARGBRow_SME; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_SSE41 + if (TestCpuFlag(kCpuHasSSE41)) { + ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_SSE41; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_NEON + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_NEON; + } +#endif + + const int row_size = (2 * width + 31) & ~31; + align_buffer_64(row, row_size * sizeof(uint16_t)); + uint16_t* temp_uv = (uint16_t*)(row); + if (!row) + return 1; + + for (y = 0; y < height; ++y) { + ScaleRowUp2_Linear(src_uv, temp_uv, width); + P410ToARGBRow(src_y, temp_uv, dst_argb, yuvconstants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_uv += src_stride_uv; + } + + free_aligned_buffer_64(row); + return 0; +} + +static int P010ToAR30MatrixBilinear(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*P410ToAR30Row)( + const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = P410ToAR30Row_C; + void (*Scale2RowUp_Bilinear_16)( + const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, + ptrdiff_t dst_stride, int dst_width) = ScaleUVRowUp2_Bilinear_16_Any_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } +#if defined(HAS_P410TOAR30ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + P410ToAR30Row = P410ToAR30Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + P410ToAR30Row = P410ToAR30Row_SSSE3; + } + } +#endif +#if defined(HAS_P410TOAR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + P410ToAR30Row = P410ToAR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + P410ToAR30Row = P410ToAR30Row_AVX2; + } + } +#endif +#if defined(HAS_P410TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + P410ToAR30Row = P410ToAR30Row_AVX512BW; + } +#endif +#if defined(HAS_P410TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + P410ToAR30Row = P410ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + P410ToAR30Row = P410ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_P410TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + P410ToAR30Row = P410ToAR30Row_SVE2; + } +#endif +#if defined(HAS_P410TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + P410ToAR30Row = P410ToAR30Row_SME; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_SSE41 + if (TestCpuFlag(kCpuHasSSE41)) { + Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_SSE41; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_NEON + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp_Bilinear_16 = ScaleUVRowUp2_Bilinear_16_Any_NEON; + } +#endif + + // alloc 2 lines temp + const int row_size = (2 * width + 31) & ~31; + align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); + uint16_t* temp_uv_1 = (uint16_t*)(row); + uint16_t* temp_uv_2 = (uint16_t*)(row) + row_size; + if (!row) + return 1; + + Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width); + P410ToAR30Row(src_y, temp_uv_1, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + + for (y = 0; y < height - 2; y += 2) { + Scale2RowUp_Bilinear_16(src_uv, src_stride_uv, temp_uv_1, row_size, width); + P410ToAR30Row(src_y, temp_uv_1, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + P410ToAR30Row(src_y, temp_uv_2, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + src_uv += src_stride_uv; + } + + if (!(height & 1)) { + Scale2RowUp_Bilinear_16(src_uv, 0, temp_uv_1, row_size, width); + P410ToAR30Row(src_y, temp_uv_1, dst_ar30, yuvconstants, width); + } + + free_aligned_buffer_64(row); + return 0; +} + +static int P210ToAR30MatrixLinear(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*P410ToAR30Row)( + const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = P410ToAR30Row_C; + void (*ScaleRowUp2_Linear)(const uint16_t* src_uv, uint16_t* dst_uv, + int dst_width) = ScaleUVRowUp2_Linear_16_Any_C; + assert(yuvconstants); + if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } +#if defined(HAS_P410TOAR30ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + P410ToAR30Row = P410ToAR30Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + P410ToAR30Row = P410ToAR30Row_SSSE3; + } + } +#endif +#if defined(HAS_P410TOAR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + P410ToAR30Row = P410ToAR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + P410ToAR30Row = P410ToAR30Row_AVX2; + } + } +#endif +#if defined(HAS_P410TOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + P410ToAR30Row = P410ToAR30Row_AVX512BW; + } +#endif +#if defined(HAS_P410TOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + P410ToAR30Row = P410ToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + P410ToAR30Row = P410ToAR30Row_NEON; + } + } +#endif +#if defined(HAS_P410TOAR30ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + P410ToAR30Row = P410ToAR30Row_SVE2; + } +#endif +#if defined(HAS_P410TOAR30ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + P410ToAR30Row = P410ToAR30Row_SME; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_SSE41 + if (TestCpuFlag(kCpuHasSSE41)) { + ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_SSE41; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_NEON + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp2_Linear = ScaleUVRowUp2_Linear_16_Any_NEON; + } +#endif + + const int row_size = (2 * width + 31) & ~31; + align_buffer_64(row, row_size * sizeof(uint16_t)); + uint16_t* temp_uv = (uint16_t*)(row); + if (!row) + return 1; + + for (y = 0; y < height; ++y) { + ScaleRowUp2_Linear(src_uv, temp_uv, width); + P410ToAR30Row(src_y, temp_uv, dst_ar30, yuvconstants, width); + dst_ar30 += dst_stride_ar30; + src_y += src_stride_y; + src_uv += src_stride_uv; + } + + free_aligned_buffer_64(row); + return 0; +} + +static int I422ToRGB24MatrixLinear(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height) { + int y; + void (*I444ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I444ToRGB24Row_C; + void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_Any_C; + assert(yuvconstants); + if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; + dst_stride_rgb24 = -dst_stride_rgb24; + } +#if defined(HAS_I444TORGB24ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I444ToRGB24Row = I444ToRGB24Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I444ToRGB24Row = I444ToRGB24Row_SSSE3; + } + } +#endif +#if defined(HAS_I444TORGB24ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I444ToRGB24Row = I444ToRGB24Row_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + I444ToRGB24Row = I444ToRGB24Row_AVX2; + } + } +#endif +#if defined(HAS_I444TORGB24ROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI)) { + I444ToRGB24Row = I444ToRGB24Row_AVX512VBMI; + } +#endif +#if defined(HAS_I444TORGB24ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I444ToRGB24Row = I444ToRGB24Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I444ToRGB24Row = I444ToRGB24Row_NEON; + } + } +#endif +#if defined(HAS_I444TORGB24ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I444ToRGB24Row = I444ToRGB24Row_SVE2; + } +#endif +#if defined(HAS_I444TORGB24ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I444ToRGB24Row = I444ToRGB24Row_SME; + } +#endif +#if defined(HAS_I444TORGB24ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I444ToRGB24Row = I444ToRGB24Row_RVV; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSE2; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_SSSE3; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_AVX2; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_Any_NEON; + } +#endif +#if defined(HAS_SCALEROWUP2_LINEAR_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleRowUp2_Linear = ScaleRowUp2_Linear_RVV; + } +#endif + + // alloc 2 lines temp + const int row_size = (width + 31) & ~31; + align_buffer_64(row, row_size * 2); + uint8_t* temp_u = row; + uint8_t* temp_v = row + row_size; + if (!row) + return 1; + + for (y = 0; y < height; ++y) { + ScaleRowUp2_Linear(src_u, temp_u, width); + ScaleRowUp2_Linear(src_v, temp_v, width); + I444ToRGB24Row(src_y, temp_u, temp_v, dst_rgb24, yuvconstants, width); + dst_rgb24 += dst_stride_rgb24; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + + free_aligned_buffer_64(row); + return 0; +} + +LIBYUV_API +int I422ToRGB24MatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I422ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgb24, dst_stride_rgb24, + yuvconstants, width, height); + case kFilterBilinear: + case kFilterBox: + case kFilterLinear: + return I422ToRGB24MatrixLinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, + dst_rgb24, dst_stride_rgb24, yuvconstants, width, height); + } + + return -1; +} + +LIBYUV_API +int I420ToARGBMatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + yuvconstants, width, height); + case kFilterBilinear: + case kFilterBox: + return I420ToARGBMatrixBilinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, + dst_argb, dst_stride_argb, yuvconstants, width, height); + case kFilterLinear: + // Actually we can do this, but probably there's no usage. + return -1; + } + + return -1; +} + +LIBYUV_API +int I422ToARGBMatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + yuvconstants, width, height); + case kFilterBilinear: + case kFilterBox: + case kFilterLinear: + return I422ToARGBMatrixLinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, + dst_argb, dst_stride_argb, yuvconstants, width, height); + } + + return -1; +} + +LIBYUV_API +int I420ToRGB24MatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_rgb24, dst_stride_rgb24, + yuvconstants, width, height); + case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 + case kFilterBilinear: + case kFilterBox: + return I420ToRGB24MatrixBilinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, + dst_rgb24, dst_stride_rgb24, yuvconstants, width, height); + } + + return -1; +} + +LIBYUV_API +int I010ToAR30MatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_ar30, dst_stride_ar30, + yuvconstants, width, height); + case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 + case kFilterBilinear: + case kFilterBox: + return I010ToAR30MatrixBilinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, + dst_ar30, dst_stride_ar30, yuvconstants, width, height); + } + + return -1; +} + +LIBYUV_API +int I210ToAR30MatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I210ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_ar30, dst_stride_ar30, + yuvconstants, width, height); + case kFilterBilinear: + case kFilterBox: + case kFilterLinear: + return I210ToAR30MatrixLinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, + dst_ar30, dst_stride_ar30, yuvconstants, width, height); + } + + return -1; +} + +LIBYUV_API +int I010ToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I010ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + yuvconstants, width, height); + case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 + case kFilterBilinear: + case kFilterBox: + return I010ToARGBMatrixBilinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, + dst_argb, dst_stride_argb, yuvconstants, width, height); + } + + return -1; +} + +LIBYUV_API +int I210ToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I210ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_argb, dst_stride_argb, + yuvconstants, width, height); + case kFilterBilinear: + case kFilterBox: + case kFilterLinear: + return I210ToARGBMatrixLinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, + dst_argb, dst_stride_argb, yuvconstants, width, height); + } + + return -1; +} + +LIBYUV_API +int I420AlphaToARGBMatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I420AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, + src_v, src_stride_v, src_a, src_stride_a, + dst_argb, dst_stride_argb, yuvconstants, + width, height, attenuate); + case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 + case kFilterBilinear: + case kFilterBox: + return I420AlphaToARGBMatrixBilinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a, + src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height, + attenuate); + } + + return -1; +} + +LIBYUV_API +int I422AlphaToARGBMatrixFilter(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I422AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, + src_v, src_stride_v, src_a, src_stride_a, + dst_argb, dst_stride_argb, yuvconstants, + width, height, attenuate); + case kFilterBilinear: + case kFilterBox: + case kFilterLinear: + return I422AlphaToARGBMatrixLinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a, + src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height, + attenuate); + } + + return -1; +} + +LIBYUV_API +int I010AlphaToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I010AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, + src_v, src_stride_v, src_a, src_stride_a, + dst_argb, dst_stride_argb, yuvconstants, + width, height, attenuate); + case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 + case kFilterBilinear: + case kFilterBox: + return I010AlphaToARGBMatrixBilinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a, + src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height, + attenuate); + } + + return -1; +} + +LIBYUV_API +int I210AlphaToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + int attenuate, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return I210AlphaToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, + src_v, src_stride_v, src_a, src_stride_a, + dst_argb, dst_stride_argb, yuvconstants, + width, height, attenuate); + case kFilterBilinear: + case kFilterBox: + case kFilterLinear: + return I210AlphaToARGBMatrixLinear( + src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_a, + src_stride_a, dst_argb, dst_stride_argb, yuvconstants, width, height, + attenuate); + } + + return -1; +} + +// TODO(fb): Verify this function works correctly. P010 is like NV12 but 10 bit +// UV is biplanar. +LIBYUV_API +int P010ToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return P010ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, + dst_argb, dst_stride_argb, yuvconstants, width, + height); + case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 + case kFilterBilinear: + case kFilterBox: + return P010ToARGBMatrixBilinear(src_y, src_stride_y, src_uv, + src_stride_uv, dst_argb, dst_stride_argb, + yuvconstants, width, height); + } + + return -1; +} + +LIBYUV_API +int P210ToARGBMatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return P210ToARGBMatrix(src_y, src_stride_y, src_uv, src_stride_uv, + dst_argb, dst_stride_argb, yuvconstants, width, + height); + case kFilterBilinear: + case kFilterBox: + case kFilterLinear: + return P210ToARGBMatrixLinear(src_y, src_stride_y, src_uv, src_stride_uv, + dst_argb, dst_stride_argb, yuvconstants, + width, height); + } + + return -1; +} + +LIBYUV_API +int P010ToAR30MatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return P010ToAR30Matrix(src_y, src_stride_y, src_uv, src_stride_uv, + dst_ar30, dst_stride_ar30, yuvconstants, width, + height); + case kFilterLinear: // TODO(fb): Implement Linear using Bilinear stride 0 + case kFilterBilinear: + case kFilterBox: + return P010ToAR30MatrixBilinear(src_y, src_stride_y, src_uv, + src_stride_uv, dst_ar30, dst_stride_ar30, + yuvconstants, width, height); + } + + return -1; +} + +LIBYUV_API +int P210ToAR30MatrixFilter(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + uint8_t* dst_ar30, + int dst_stride_ar30, + const struct YuvConstants* yuvconstants, + int width, + int height, + enum FilterMode filter) { + switch (filter) { + case kFilterNone: + return P210ToAR30Matrix(src_y, src_stride_y, src_uv, src_stride_uv, + dst_ar30, dst_stride_ar30, yuvconstants, width, + height); + case kFilterBilinear: + case kFilterBox: + case kFilterLinear: + return P210ToAR30MatrixLinear(src_y, src_stride_y, src_uv, src_stride_uv, + dst_ar30, dst_stride_ar30, yuvconstants, + width, height); + } + + return -1; +} + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/source/convert_from.cc b/libs/libyuv/source/convert_from.cc index 60140cb4e2..6f5853bc2d 100644 --- a/libs/libyuv/source/convert_from.cc +++ b/libs/libyuv/source/convert_from.cc @@ -10,7 +10,9 @@ #include "libyuv/convert_from.h" -#include "libyuv/basic_types.h" +#include +#include + #include "libyuv/convert.h" // For I420Copy #include "libyuv/cpu_id.h" #include "libyuv/planar_functions.h" @@ -46,23 +48,26 @@ static int I420ToI4xx(const uint8_t* src_y, int src_y_height, int dst_uv_width, int dst_uv_height) { - const int dst_y_width = Abs(src_y_width); - const int dst_y_height = Abs(src_y_height); const int src_uv_width = SUBSAMPLE(src_y_width, 1, 1); const int src_uv_height = SUBSAMPLE(src_y_height, 1, 1); - if (src_y_width == 0 || src_y_height == 0 || dst_uv_width <= 0 || + int r; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || + src_y_width <= 0 || src_y_height == 0 || dst_uv_width <= 0 || dst_uv_height <= 0) { return -1; } if (dst_y) { - ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, dst_y, - dst_stride_y, dst_y_width, dst_y_height, kFilterBilinear); + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, src_y_width, + src_y_height); } - ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u, - dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear); - ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v, - dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear); - return 0; + r = ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u, + dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear); + if (r != 0) { + return r; + } + r = ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v, + dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear); + return r; } // Convert 8 bit YUV to 10 bit. @@ -83,24 +88,29 @@ int I420ToI010(const uint8_t* src_y, int height) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_u || !src_v || !dst_u || !dst_v || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; - src_stride_y = -src_stride_y; + if (src_y) { + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_stride_y = -src_stride_y; + } + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; } // Convert Y plane. - Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 1024, width, - height); + if (dst_y) { + Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 1024, width, + height); + } // Convert UV planes. Convert8To16Plane(src_u, src_stride_u, dst_u, dst_stride_u, 1024, halfwidth, halfheight); @@ -109,6 +119,55 @@ int I420ToI010(const uint8_t* src_y, return 0; } +// Convert 8 bit YUV to 12 bit. +LIBYUV_API +int I420ToI012(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + int halfwidth = (width + 1) >> 1; + int halfheight = (height + 1) >> 1; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + if (src_y) { + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_stride_y = -src_stride_y; + } + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + + // Convert Y plane. + if (dst_y) { + Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 4096, width, + height); + } + // Convert UV planes. + Convert8To16Plane(src_u, src_stride_u, dst_u, dst_stride_u, 4096, halfwidth, + halfheight); + Convert8To16Plane(src_v, src_stride_v, dst_v, dst_stride_v, 4096, halfwidth, + halfheight); + return 0; +} + // 420 chroma is 1/2 width, 1/2 height // 422 chroma is 1/2 width, 1x height LIBYUV_API @@ -159,6 +218,114 @@ int I420ToI444(const uint8_t* src_y, dst_uv_height); } +// 420 chroma to 444 chroma, 10/12 bit version +LIBYUV_API +int I010ToI410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + int r; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + + if (dst_y) { + CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + r = ScalePlane_12(src_u, src_stride_u, SUBSAMPLE(width, 1, 1), + SUBSAMPLE(height, 1, 1), dst_u, dst_stride_u, width, + Abs(height), kFilterBilinear); + if (r != 0) { + return r; + } + r = ScalePlane_12(src_v, src_stride_v, SUBSAMPLE(width, 1, 1), + SUBSAMPLE(height, 1, 1), dst_v, dst_stride_v, width, + Abs(height), kFilterBilinear); + return r; +} + +// 422 chroma to 444 chroma, 10/12 bit version +LIBYUV_API +int I210ToI410(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + int r; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + + if (dst_y) { + CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + r = ScalePlane_12(src_u, src_stride_u, SUBSAMPLE(width, 1, 1), height, dst_u, + dst_stride_u, width, Abs(height), kFilterBilinear); + if (r != 0) { + return r; + } + r = ScalePlane_12(src_v, src_stride_v, SUBSAMPLE(width, 1, 1), height, dst_v, + dst_stride_v, width, Abs(height), kFilterBilinear); + return r; +} + +// 422 chroma is 1/2 width, 1x height +// 444 chroma is 1x width, 1x height +LIBYUV_API +int I422ToI444(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + int r; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + + if (dst_y) { + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + r = ScalePlane(src_u, src_stride_u, SUBSAMPLE(width, 1, 1), height, dst_u, + dst_stride_u, width, Abs(height), kFilterBilinear); + if (r != 0) { + return r; + } + r = ScalePlane(src_v, src_stride_v, SUBSAMPLE(width, 1, 1), height, dst_v, + dst_stride_v, width, Abs(height), kFilterBilinear); + return r; +} + // Copy to I400. Source can be I420,422,444,400,NV12,NV21 LIBYUV_API int I400Copy(const uint8_t* src_y, @@ -167,15 +334,9 @@ int I400Copy(const uint8_t* src_y, int dst_stride_y, int width, int height) { - if (!src_y || !dst_y || width <= 0 || height == 0) { + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } - // Negative height means invert the image. - if (height < 0) { - height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_stride_y = -src_stride_y; - } CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); return 0; } @@ -195,18 +356,20 @@ int I422ToYUY2(const uint8_t* src_y, void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_yuy2, int width) = I422ToYUY2Row_C; - if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2; + dst_yuy2 = dst_yuy2 + (ptrdiff_t)(height - 1) * dst_stride_yuy2; dst_stride_yuy2 = -dst_stride_yuy2; } // Coalesce rows. if (src_stride_y == width && src_stride_u * 2 == width && - src_stride_v * 2 == width && dst_stride_yuy2 == width * 2) { + src_stride_v * 2 == width && dst_stride_yuy2 == width * 2 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = src_stride_u = src_stride_v = dst_stride_yuy2 = 0; @@ -261,13 +424,14 @@ int I420ToYUY2(const uint8_t* src_y, void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_yuy2, int width) = I422ToYUY2Row_C; - if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2; + dst_yuy2 = dst_yuy2 + (ptrdiff_t)(height - 1) * dst_stride_yuy2; dst_stride_yuy2 = -dst_stride_yuy2; } #if defined(HAS_I422TOYUY2ROW_SSE2) @@ -294,19 +458,19 @@ int I420ToYUY2(const uint8_t* src_y, } } #endif -#if defined(HAS_I422TOYUY2ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToYUY2Row = I422ToYUY2Row_Any_MSA; - if (IS_ALIGNED(width, 32)) { - I422ToYUY2Row = I422ToYUY2Row_MSA; +#if defined(HAS_I422TOYUY2ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToYUY2Row = I422ToYUY2Row_Any_LSX; + if (IS_ALIGNED(width, 16)) { + I422ToYUY2Row = I422ToYUY2Row_LSX; } } #endif -#if defined(HAS_I422TOYUY2ROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - I422ToYUY2Row = I422ToYUY2Row_Any_MMI; - if (IS_ALIGNED(width, 8)) { - I422ToYUY2Row = I422ToYUY2Row_MMI; +#if defined(HAS_I422TOYUY2ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToYUY2Row = I422ToYUY2Row_Any_LASX; + if (IS_ALIGNED(width, 32)) { + I422ToYUY2Row = I422ToYUY2Row_LASX; } } #endif @@ -341,18 +505,20 @@ int I422ToUYVY(const uint8_t* src_y, void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uyvy, int width) = I422ToUYVYRow_C; - if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy; + dst_uyvy = dst_uyvy + (ptrdiff_t)(height - 1) * dst_stride_uyvy; dst_stride_uyvy = -dst_stride_uyvy; } // Coalesce rows. if (src_stride_y == width && src_stride_u * 2 == width && - src_stride_v * 2 == width && dst_stride_uyvy == width * 2) { + src_stride_v * 2 == width && dst_stride_uyvy == width * 2 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = src_stride_u = src_stride_v = dst_stride_uyvy = 0; @@ -381,19 +547,19 @@ int I422ToUYVY(const uint8_t* src_y, } } #endif -#if defined(HAS_I422TOUYVYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToUYVYRow = I422ToUYVYRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - I422ToUYVYRow = I422ToUYVYRow_MSA; +#if defined(HAS_I422TOUYVYROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToUYVYRow = I422ToUYVYRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + I422ToUYVYRow = I422ToUYVYRow_LSX; } } #endif -#if defined(HAS_I422TOUYVYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - I422ToUYVYRow = I422ToUYVYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - I422ToUYVYRow = I422ToUYVYRow_MMI; +#if defined(HAS_I422TOUYVYROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToUYVYRow = I422ToUYVYRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + I422ToUYVYRow = I422ToUYVYRow_LASX; } } #endif @@ -423,13 +589,14 @@ int I420ToUYVY(const uint8_t* src_y, void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uyvy, int width) = I422ToUYVYRow_C; - if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy; + dst_uyvy = dst_uyvy + (ptrdiff_t)(height - 1) * dst_stride_uyvy; dst_stride_uyvy = -dst_stride_uyvy; } #if defined(HAS_I422TOUYVYROW_SSE2) @@ -456,19 +623,19 @@ int I420ToUYVY(const uint8_t* src_y, } } #endif -#if defined(HAS_I422TOUYVYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToUYVYRow = I422ToUYVYRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - I422ToUYVYRow = I422ToUYVYRow_MSA; +#if defined(HAS_I422TOUYVYROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I422ToUYVYRow = I422ToUYVYRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + I422ToUYVYRow = I422ToUYVYRow_LSX; } } #endif -#if defined(HAS_I422TOUYVYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - I422ToUYVYRow = I422ToUYVYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - I422ToUYVYRow = I422ToUYVYRow_MMI; +#if defined(HAS_I422TOUYVYROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I422ToUYVYRow = I422ToUYVYRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + I422ToUYVYRow = I422ToUYVYRow_LASX; } } #endif @@ -488,7 +655,6 @@ int I420ToUYVY(const uint8_t* src_y, return 0; } -// TODO(fbarchard): test negative height for invert. LIBYUV_API int I420ToNV12(const uint8_t* src_y, int src_stride_y, @@ -502,12 +668,23 @@ int I420ToNV12(const uint8_t* src_y, int dst_stride_uv, int width, int height) { - if (!src_y || !src_u || !src_v || !dst_y || !dst_uv || width <= 0 || - height == 0) { + int halfwidth = (width + 1) / 2; + int halfheight = (height + 1) / 2; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_uv || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } - int halfwidth = (width + 1) / 2; - int halfheight = height > 0 ? (height + 1) / 2 : (height - 1) / 2; + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } if (dst_y) { CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); } @@ -534,805 +711,314 @@ int I420ToNV21(const uint8_t* src_y, width, height); } -// Convert I422 to RGBA with matrix -static int I420ToRGBAMatrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgba, - int dst_stride_rgba, - const struct YuvConstants* yuvconstants, - int width, - int height) { +static int I4xxToPxxx(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height, + int subsample_x, + int subsample_y) { int y; - void (*I422ToRGBARow)(const uint8_t* y_buf, const uint8_t* u_buf, - const uint8_t* v_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, int width) = - I422ToRGBARow_C; - if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0) { + int uv_width; + int uv_height; + int row_stride; + void (*Convert8To16Row)(const uint8_t* src_y, uint16_t* dst_y, int bits, + int width) = Convert8To16Row_C; + void (*MergeUVRow_16)(const uint16_t* src_u, const uint16_t* src_v, + uint16_t* dst_uv, int depth, int width) = + MergeUVRow_16_C; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_y || !dst_uv || + width <= 0 || height == 0 || height == INT_MIN) { return -1; } - // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgba = dst_rgba + (height - 1) * dst_stride_rgba; - dst_stride_rgba = -dst_stride_rgba; + uv_height = SUBSAMPLE(height, subsample_y, subsample_y); + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(uv_height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(uv_height - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } else { + uv_height = SUBSAMPLE(height, subsample_y, subsample_y); } -#if defined(HAS_I422TORGBAROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - I422ToRGBARow = I422ToRGBARow_Any_SSSE3; - if (IS_ALIGNED(width, 8)) { - I422ToRGBARow = I422ToRGBARow_SSSE3; - } - } -#endif -#if defined(HAS_I422TORGBAROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - I422ToRGBARow = I422ToRGBARow_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - I422ToRGBARow = I422ToRGBARow_AVX2; - } - } -#endif -#if defined(HAS_I422TORGBAROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - I422ToRGBARow = I422ToRGBARow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - I422ToRGBARow = I422ToRGBARow_NEON; - } - } -#endif -#if defined(HAS_I422TORGBAROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToRGBARow = I422ToRGBARow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - I422ToRGBARow = I422ToRGBARow_MSA; - } - } -#endif + uv_width = SUBSAMPLE(width, subsample_x, subsample_x); - for (y = 0; y < height; ++y) { - I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width); - dst_rgba += dst_stride_rgba; - src_y += src_stride_y; - if (y & 1) { - src_u += src_stride_u; - src_v += src_stride_v; - } - } - return 0; -} + Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 10, width, + height); + ConvertToMSBPlane_16(dst_y, dst_stride_y, dst_y, dst_stride_y, width, height, + 10); -// Convert I420 to RGBA. -LIBYUV_API -int I420ToRGBA(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgba, - int dst_stride_rgba, - int width, - int height) { - return I420ToRGBAMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, - src_stride_v, dst_rgba, dst_stride_rgba, - &kYuvI601Constants, width, height); -} - -// Convert I420 to BGRA. -LIBYUV_API -int I420ToBGRA(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_bgra, - int dst_stride_bgra, - int width, - int height) { - return I420ToRGBAMatrix(src_y, src_stride_y, src_v, - src_stride_v, // Swap U and V - src_u, src_stride_u, dst_bgra, dst_stride_bgra, - &kYvuI601Constants, // Use Yvu matrix - width, height); -} - -// Convert I420 to RGB24 with matrix -static int I420ToRGB24Matrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb24, - int dst_stride_rgb24, - const struct YuvConstants* yuvconstants, - int width, - int height) { - int y; - void (*I422ToRGB24Row)(const uint8_t* y_buf, const uint8_t* u_buf, - const uint8_t* v_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, int width) = - I422ToRGB24Row_C; - if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24; - dst_stride_rgb24 = -dst_stride_rgb24; - } -#if defined(HAS_I422TORGB24ROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - I422ToRGB24Row = I422ToRGB24Row_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - I422ToRGB24Row = I422ToRGB24Row_SSSE3; - } - } -#endif -#if defined(HAS_I422TORGB24ROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - I422ToRGB24Row = I422ToRGB24Row_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - I422ToRGB24Row = I422ToRGB24Row_AVX2; - } - } -#endif -#if defined(HAS_I422TORGB24ROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - I422ToRGB24Row = I422ToRGB24Row_Any_NEON; - if (IS_ALIGNED(width, 8)) { - I422ToRGB24Row = I422ToRGB24Row_NEON; - } - } -#endif -#if defined(HAS_I422TORGB24ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToRGB24Row = I422ToRGB24Row_Any_MSA; - if (IS_ALIGNED(width, 16)) { - I422ToRGB24Row = I422ToRGB24Row_MSA; - } - } -#endif - - for (y = 0; y < height; ++y) { - I422ToRGB24Row(src_y, src_u, src_v, dst_rgb24, yuvconstants, width); - dst_rgb24 += dst_stride_rgb24; - src_y += src_stride_y; - if (y & 1) { - src_u += src_stride_u; - src_v += src_stride_v; - } - } - return 0; -} - -// Convert I420 to RGB24. -LIBYUV_API -int I420ToRGB24(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb24, - int dst_stride_rgb24, - int width, - int height) { - return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, - src_stride_v, dst_rgb24, dst_stride_rgb24, - &kYuvI601Constants, width, height); -} - -// Convert I420 to RAW. -LIBYUV_API -int I420ToRAW(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_raw, - int dst_stride_raw, - int width, - int height) { - return I420ToRGB24Matrix(src_y, src_stride_y, src_v, - src_stride_v, // Swap U and V - src_u, src_stride_u, dst_raw, dst_stride_raw, - &kYvuI601Constants, // Use Yvu matrix - width, height); -} - -// Convert H420 to RGB24. -LIBYUV_API -int H420ToRGB24(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb24, - int dst_stride_rgb24, - int width, - int height) { - return I420ToRGB24Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, - src_stride_v, dst_rgb24, dst_stride_rgb24, - &kYuvH709Constants, width, height); -} - -// Convert H420 to RAW. -LIBYUV_API -int H420ToRAW(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_raw, - int dst_stride_raw, - int width, - int height) { - return I420ToRGB24Matrix(src_y, src_stride_y, src_v, - src_stride_v, // Swap U and V - src_u, src_stride_u, dst_raw, dst_stride_raw, - &kYvuH709Constants, // Use Yvu matrix - width, height); -} - -// Convert I420 to ARGB1555. -LIBYUV_API -int I420ToARGB1555(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_argb1555, - int dst_stride_argb1555, - int width, - int height) { - int y; - void (*I422ToARGB1555Row)(const uint8_t* y_buf, const uint8_t* u_buf, - const uint8_t* v_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, - int width) = I422ToARGB1555Row_C; - if (!src_y || !src_u || !src_v || !dst_argb1555 || width <= 0 || - height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - dst_argb1555 = dst_argb1555 + (height - 1) * dst_stride_argb1555; - dst_stride_argb1555 = -dst_stride_argb1555; - } -#if defined(HAS_I422TOARGB1555ROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - I422ToARGB1555Row = I422ToARGB1555Row_Any_SSSE3; - if (IS_ALIGNED(width, 8)) { - I422ToARGB1555Row = I422ToARGB1555Row_SSSE3; - } - } -#endif -#if defined(HAS_I422TOARGB1555ROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - I422ToARGB1555Row = I422ToARGB1555Row_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - I422ToARGB1555Row = I422ToARGB1555Row_AVX2; - } - } -#endif -#if defined(HAS_I422TOARGB1555ROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - I422ToARGB1555Row = I422ToARGB1555Row_Any_NEON; - if (IS_ALIGNED(width, 8)) { - I422ToARGB1555Row = I422ToARGB1555Row_NEON; - } - } -#endif -#if defined(HAS_I422TOARGB1555ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToARGB1555Row = I422ToARGB1555Row_Any_MSA; - if (IS_ALIGNED(width, 8)) { - I422ToARGB1555Row = I422ToARGB1555Row_MSA; - } - } -#endif - - for (y = 0; y < height; ++y) { - I422ToARGB1555Row(src_y, src_u, src_v, dst_argb1555, &kYuvI601Constants, - width); - dst_argb1555 += dst_stride_argb1555; - src_y += src_stride_y; - if (y & 1) { - src_u += src_stride_u; - src_v += src_stride_v; - } - } - return 0; -} - -// Convert I420 to ARGB4444. -LIBYUV_API -int I420ToARGB4444(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_argb4444, - int dst_stride_argb4444, - int width, - int height) { - int y; - void (*I422ToARGB4444Row)(const uint8_t* y_buf, const uint8_t* u_buf, - const uint8_t* v_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, - int width) = I422ToARGB4444Row_C; - if (!src_y || !src_u || !src_v || !dst_argb4444 || width <= 0 || - height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - dst_argb4444 = dst_argb4444 + (height - 1) * dst_stride_argb4444; - dst_stride_argb4444 = -dst_stride_argb4444; - } -#if defined(HAS_I422TOARGB4444ROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - I422ToARGB4444Row = I422ToARGB4444Row_Any_SSSE3; - if (IS_ALIGNED(width, 8)) { - I422ToARGB4444Row = I422ToARGB4444Row_SSSE3; - } - } -#endif -#if defined(HAS_I422TOARGB4444ROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - I422ToARGB4444Row = I422ToARGB4444Row_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - I422ToARGB4444Row = I422ToARGB4444Row_AVX2; - } - } -#endif -#if defined(HAS_I422TOARGB4444ROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - I422ToARGB4444Row = I422ToARGB4444Row_Any_NEON; - if (IS_ALIGNED(width, 8)) { - I422ToARGB4444Row = I422ToARGB4444Row_NEON; - } - } -#endif -#if defined(HAS_I422TOARGB4444ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToARGB4444Row = I422ToARGB4444Row_Any_MSA; - if (IS_ALIGNED(width, 8)) { - I422ToARGB4444Row = I422ToARGB4444Row_MSA; - } - } -#endif - - for (y = 0; y < height; ++y) { - I422ToARGB4444Row(src_y, src_u, src_v, dst_argb4444, &kYuvI601Constants, - width); - dst_argb4444 += dst_stride_argb4444; - src_y += src_stride_y; - if (y & 1) { - src_u += src_stride_u; - src_v += src_stride_v; - } - } - return 0; -} - -// Convert I420 to RGB565 with specified color matrix. -LIBYUV_API -int I420ToRGB565Matrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - const struct YuvConstants* yuvconstants, - int width, - int height) { - int y; - void (*I422ToRGB565Row)(const uint8_t* y_buf, const uint8_t* u_buf, - const uint8_t* v_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, int width) = - I422ToRGB565Row_C; - if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; - dst_stride_rgb565 = -dst_stride_rgb565; - } -#if defined(HAS_I422TORGB565ROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3; - if (IS_ALIGNED(width, 8)) { - I422ToRGB565Row = I422ToRGB565Row_SSSE3; - } - } -#endif -#if defined(HAS_I422TORGB565ROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - I422ToRGB565Row = I422ToRGB565Row_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - I422ToRGB565Row = I422ToRGB565Row_AVX2; - } - } -#endif -#if defined(HAS_I422TORGB565ROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - I422ToRGB565Row = I422ToRGB565Row_Any_NEON; - if (IS_ALIGNED(width, 8)) { - I422ToRGB565Row = I422ToRGB565Row_NEON; - } - } -#endif -#if defined(HAS_I422TORGB565ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToRGB565Row = I422ToRGB565Row_Any_MSA; - if (IS_ALIGNED(width, 8)) { - I422ToRGB565Row = I422ToRGB565Row_MSA; - } - } -#endif - - for (y = 0; y < height; ++y) { - I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, yuvconstants, width); - dst_rgb565 += dst_stride_rgb565; - src_y += src_stride_y; - if (y & 1) { - src_u += src_stride_u; - src_v += src_stride_v; - } - } - return 0; -} - -// Convert I420 to RGB565. -LIBYUV_API -int I420ToRGB565(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - int width, - int height) { - return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, - src_stride_v, dst_rgb565, dst_stride_rgb565, - &kYuvI601Constants, width, height); -} - -// Convert J420 to RGB565. -LIBYUV_API -int J420ToRGB565(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - int width, - int height) { - return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, - src_stride_v, dst_rgb565, dst_stride_rgb565, - &kYuvJPEGConstants, width, height); -} - -// Convert H420 to RGB565. -LIBYUV_API -int H420ToRGB565(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - int width, - int height) { - return I420ToRGB565Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, - src_stride_v, dst_rgb565, dst_stride_rgb565, - &kYuvH709Constants, width, height); -} - -// Convert I422 to RGB565. -LIBYUV_API -int I422ToRGB565(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - int width, - int height) { - int y; - void (*I422ToRGB565Row)(const uint8_t* y_buf, const uint8_t* u_buf, - const uint8_t* v_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, int width) = - I422ToRGB565Row_C; - if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; - dst_stride_rgb565 = -dst_stride_rgb565; - } -#if defined(HAS_I422TORGB565ROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3; - if (IS_ALIGNED(width, 8)) { - I422ToRGB565Row = I422ToRGB565Row_SSSE3; - } - } -#endif -#if defined(HAS_I422TORGB565ROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - I422ToRGB565Row = I422ToRGB565Row_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - I422ToRGB565Row = I422ToRGB565Row_AVX2; - } - } -#endif -#if defined(HAS_I422TORGB565ROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - I422ToRGB565Row = I422ToRGB565Row_Any_NEON; - if (IS_ALIGNED(width, 8)) { - I422ToRGB565Row = I422ToRGB565Row_NEON; - } - } -#endif -#if defined(HAS_I422TORGB565ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToRGB565Row = I422ToRGB565Row_Any_MSA; - if (IS_ALIGNED(width, 8)) { - I422ToRGB565Row = I422ToRGB565Row_MSA; - } - } -#endif - - for (y = 0; y < height; ++y) { - I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, &kYuvI601Constants, width); - dst_rgb565 += dst_stride_rgb565; - src_y += src_stride_y; - src_u += src_stride_u; - src_v += src_stride_v; - } - return 0; -} - -// Ordered 8x8 dither for 888 to 565. Values from 0 to 7. -static const uint8_t kDither565_4x4[16] = { - 0, 4, 1, 5, 6, 2, 7, 3, 1, 5, 0, 4, 7, 3, 6, 2, -}; - -// Convert I420 to RGB565 with dithering. -LIBYUV_API -int I420ToRGB565Dither(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - const uint8_t* dither4x4, - int width, - int height) { - int y; - void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, - const uint8_t* v_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, int width) = - I422ToARGBRow_C; - void (*ARGBToRGB565DitherRow)(const uint8_t* src_argb, uint8_t* dst_rgb, - const uint32_t dither4, int width) = - ARGBToRGB565DitherRow_C; - if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; - dst_stride_rgb565 = -dst_stride_rgb565; - } - if (!dither4x4) { - dither4x4 = kDither565_4x4; - } -#if defined(HAS_I422TOARGBROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - I422ToARGBRow = I422ToARGBRow_Any_SSSE3; - if (IS_ALIGNED(width, 8)) { - I422ToARGBRow = I422ToARGBRow_SSSE3; - } - } -#endif -#if defined(HAS_I422TOARGBROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - I422ToARGBRow = I422ToARGBRow_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - I422ToARGBRow = I422ToARGBRow_AVX2; - } - } -#endif -#if defined(HAS_I422TOARGBROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - I422ToARGBRow = I422ToARGBRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - I422ToARGBRow = I422ToARGBRow_NEON; - } - } -#endif -#if defined(HAS_I422TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToARGBRow = I422ToARGBRow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - I422ToARGBRow = I422ToARGBRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTORGB565DITHERROW_SSE2) +#if defined(HAS_CONVERT8TO16ROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_SSE2; - if (IS_ALIGNED(width, 4)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_SSE2; + Convert8To16Row = Convert8To16Row_Any_SSE2; + if (IS_ALIGNED(uv_width, 16)) { + Convert8To16Row = Convert8To16Row_SSE2; } } #endif -#if defined(HAS_ARGBTORGB565DITHERROW_AVX2) +#if defined(HAS_CONVERT8TO16ROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_AVX2; - if (IS_ALIGNED(width, 8)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_AVX2; + Convert8To16Row = Convert8To16Row_Any_AVX2; + if (IS_ALIGNED(uv_width, 32)) { + Convert8To16Row = Convert8To16Row_AVX2; } } #endif -#if defined(HAS_ARGBTORGB565DITHERROW_NEON) +#if defined(HAS_CONVERT8TO16ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Convert8To16Row = Convert8To16Row_AVX512BW; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_NEON; + Convert8To16Row = Convert8To16Row_Any_NEON; + if (IS_ALIGNED(uv_width, 16)) { + Convert8To16Row = Convert8To16Row_NEON; } } #endif -#if defined(HAS_ARGBTORGB565DITHERROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_MSA; +#if defined(HAS_CONVERT8TO16ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Convert8To16Row = Convert8To16Row_SME; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Convert8To16Row = Convert8To16Row_RVV; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Convert8To16Row = Convert8To16Row_HVX; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + Convert8To16Row = Convert8To16Row_Any_WASMSIMD; + if (IS_ALIGNED(uv_width, 16)) { + Convert8To16Row = Convert8To16Row_WASMSIMD; } } #endif - { - // Allocate a row of argb. - align_buffer_64(row_argb, width * 4); - for (y = 0; y < height; ++y) { - I422ToARGBRow(src_y, src_u, src_v, row_argb, &kYuvI601Constants, width); - ARGBToRGB565DitherRow(row_argb, dst_rgb565, - *(const uint32_t*)(dither4x4 + ((y & 3) << 2)), - width); - dst_rgb565 += dst_stride_rgb565; - src_y += src_stride_y; - if (y & 1) { - src_u += src_stride_u; - src_v += src_stride_v; - } - } - free_aligned_buffer_64(row_argb); - } - return 0; -} - -// Convert I420 to AR30 with matrix -static int I420ToAR30Matrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_ar30, - int dst_stride_ar30, - const struct YuvConstants* yuvconstants, - int width, - int height) { - int y; - void (*I422ToAR30Row)(const uint8_t* y_buf, const uint8_t* u_buf, - const uint8_t* v_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, int width) = - I422ToAR30Row_C; - - if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; - dst_stride_ar30 = -dst_stride_ar30; - } - -#if defined(HAS_I422TOAR30ROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - I422ToAR30Row = I422ToAR30Row_Any_SSSE3; - if (IS_ALIGNED(width, 8)) { - I422ToAR30Row = I422ToAR30Row_SSSE3; - } - } -#endif -#if defined(HAS_I422TOAR30ROW_AVX2) +#if defined(HAS_MERGEUVROW_16_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - I422ToAR30Row = I422ToAR30Row_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - I422ToAR30Row = I422ToAR30Row_AVX2; + MergeUVRow_16 = MergeUVRow_16_Any_AVX2; + if (IS_ALIGNED(uv_width, 8)) { + MergeUVRow_16 = MergeUVRow_16_AVX2; } } #endif +#if defined(HAS_MERGEUVROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow_16 = MergeUVRow_16_AVX512BW; + } +#endif +#if defined(HAS_MERGEUVROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeUVRow_16 = MergeUVRow_16_Any_NEON; + if (IS_ALIGNED(uv_width, 8)) { + MergeUVRow_16 = MergeUVRow_16_NEON; + } + } +#endif +#if defined(HAS_MERGEUVROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow_16 = MergeUVRow_16_SME; + } +#endif +#if defined(HAS_MERGEUVROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow_16 = MergeUVRow_16_HVX; + } +#endif - for (y = 0; y < height; ++y) { - I422ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width); - dst_ar30 += dst_stride_ar30; - src_y += src_stride_y; - if (y & 1) { + row_stride = (uv_width + 31) & ~31; + align_buffer_64(row_u, (size_t)row_stride * sizeof(uint16_t) * 2u); + if (!row_u) { + return 1; + } + { + uint16_t* row_u16 = (uint16_t*)row_u; + uint16_t* row_v16 = row_u16 + row_stride; + for (y = 0; y < uv_height; ++y) { + Convert8To16Row(src_u, row_u16, 10, uv_width); + Convert8To16Row(src_v, row_v16, 10, uv_width); + MergeUVRow_16(row_u16, row_v16, dst_uv, 10, uv_width); src_u += src_stride_u; src_v += src_stride_v; + dst_uv += dst_stride_uv; } } + free_aligned_buffer_64(row_u); return 0; } -// Convert I420 to AR30. LIBYUV_API -int I420ToAR30(const uint8_t* src_y, +int I420ToP010(const uint8_t* src_y, int src_stride_y, const uint8_t* src_u, int src_stride_u, const uint8_t* src_v, int src_stride_v, - uint8_t* dst_ar30, - int dst_stride_ar30, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, int width, int height) { - return I420ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, - src_stride_v, dst_ar30, dst_stride_ar30, - &kYuvI601Constants, width, height); + return I4xxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height, 1, 1); } -// Convert H420 to AR30. LIBYUV_API -int H420ToAR30(const uint8_t* src_y, +int I422ToP210(const uint8_t* src_y, int src_stride_y, const uint8_t* src_u, int src_stride_u, const uint8_t* src_v, int src_stride_v, - uint8_t* dst_ar30, - int dst_stride_ar30, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, int width, int height) { - return I420ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v, - src_stride_v, dst_ar30, dst_stride_ar30, - &kYvuH709Constants, width, height); + return I4xxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height, 1, 0); +} + +LIBYUV_API +int I444ToP410(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return I4xxToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height, 0, 0); +} + +static int I420ToPxxx(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height, + int dst_uv_width, + int (*i4xx_to_pxxx)(const uint8_t*, + int, + const uint8_t*, + int, + const uint8_t*, + int, + uint16_t*, + int, + uint16_t*, + int, + int, + int)) { + int r; + int abs_height; + uint64_t uv_size; + uint64_t total; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_y || !dst_uv || + width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } + abs_height = Abs(height); + if (height < 0) { + const int src_uv_height = SUBSAMPLE(abs_height, 1, 1); + src_y = src_y + (ptrdiff_t)(abs_height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(src_uv_height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(src_uv_height - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + height = abs_height; + } + uv_size = (uint64_t)dst_uv_width * (uint64_t)abs_height; + total = uv_size * 2u; + if (total > SIZE_MAX) { + return 1; + } + align_buffer_64(plane_u, (size_t)total); + if (!plane_u) { + return 1; + } + { + uint8_t* tmp_u = plane_u; + uint8_t* tmp_v = plane_u + uv_size; + r = I420ToI4xx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, NULL, 0, tmp_u, dst_uv_width, tmp_v, + dst_uv_width, width, height, dst_uv_width, abs_height); + if (!r) { + r = i4xx_to_pxxx(src_y, src_stride_y, tmp_u, dst_uv_width, tmp_v, + dst_uv_width, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height); + } + } + free_aligned_buffer_64(plane_u); + return r; +} + +LIBYUV_API +int I420ToP210(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return I420ToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height, (Abs(width) + 1) >> 1, I422ToP210); +} + +LIBYUV_API +int I420ToP410(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return I420ToPxxx(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + width, height, Abs(width), I444ToP410); } // Convert I420 to specified format @@ -1350,9 +1036,11 @@ int ConvertFromI420(const uint8_t* y, uint32_t fourcc) { uint32_t format = CanonicalFourCC(fourcc); int r = 0; - if (!y || !u || !v || !dst_sample || width <= 0 || height == 0) { + if (!y || !u || !v || !dst_sample || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } + const int abs_height = Abs(height); switch (format) { // Single plane formats case FOURCC_YUY2: @@ -1421,7 +1109,8 @@ int ConvertFromI420(const uint8_t* y, height); break; case FOURCC_NV12: { - uint8_t* dst_uv = dst_sample + width * height; + int dst_y_stride = dst_sample_stride ? dst_sample_stride : width; + uint8_t* dst_uv = dst_sample + (ptrdiff_t)dst_y_stride * abs_height; r = I420ToNV12(y, y_stride, u, u_stride, v, v_stride, dst_sample, dst_sample_stride ? dst_sample_stride : width, dst_uv, dst_sample_stride ? dst_sample_stride : width, width, @@ -1429,28 +1118,121 @@ int ConvertFromI420(const uint8_t* y, break; } case FOURCC_NV21: { - uint8_t* dst_vu = dst_sample + width * height; + int dst_y_stride = dst_sample_stride ? dst_sample_stride : width; + uint8_t* dst_vu = dst_sample + (ptrdiff_t)dst_y_stride * abs_height; r = I420ToNV21(y, y_stride, u, u_stride, v, v_stride, dst_sample, dst_sample_stride ? dst_sample_stride : width, dst_vu, dst_sample_stride ? dst_sample_stride : width, width, height); break; } - // TODO(fbarchard): Add M420. + case FOURCC_NV16: { + int dst_y_stride = dst_sample_stride ? dst_sample_stride : width; + int dst_uv_stride = dst_sample_stride ? dst_sample_stride : width; + uint8_t* dst_uv = dst_sample + (ptrdiff_t)dst_y_stride * abs_height; + int halfwidth = (width + 1) / 2; + int halfheight = SUBSAMPLE(height, 1, 1); + CopyPlane(y, y_stride, dst_sample, dst_y_stride, width, height); + MergeUVPlane(u, u_stride, v, v_stride, dst_uv, dst_uv_stride * 2, + halfwidth, halfheight); + if (abs_height > 1) { + MergeUVPlane(u, u_stride, v, v_stride, dst_uv + dst_uv_stride, + dst_uv_stride * 2, halfwidth, height / 2); + } + r = 0; + break; + } + case FOURCC_NV24: { + int dst_y_stride = dst_sample_stride ? dst_sample_stride : width; + int dst_uv_stride = dst_sample_stride ? dst_sample_stride * 2 : width * 2; + uint8_t* dst_uv = dst_sample + (ptrdiff_t)dst_y_stride * abs_height; + align_buffer_64(temp_u, (size_t)width * abs_height); + align_buffer_64(temp_v, (size_t)width * abs_height); + if (!temp_u || !temp_v) { + free_aligned_buffer_64(temp_u); + free_aligned_buffer_64(temp_v); + return 1; + } + r = I420ToI444(y, y_stride, u, u_stride, v, v_stride, dst_sample, + dst_y_stride, temp_u, width, temp_v, width, width, height); + if (r == 0) { + MergeUVPlane(temp_u, width, temp_v, width, dst_uv, dst_uv_stride, width, + abs_height); + } + free_aligned_buffer_64(temp_u); + free_aligned_buffer_64(temp_v); + break; + } + case FOURCC_P010: + case FOURCC_P210: { + const int uv_min = ((width + 1) / 2) * 2; + int dst_stride_y; + int dst_stride_uv; + uint16_t* dst_y16; + uint16_t* dst_uv16; + if (dst_sample_stride == 0) { + dst_stride_y = width; + dst_stride_uv = uv_min; + } else { + if (dst_sample_stride & 1) { + return -1; + } + dst_stride_y = dst_sample_stride / 2; + dst_stride_uv = dst_sample_stride / 2; + if (Abs(dst_stride_uv) < uv_min) { + return -1; + } + } + dst_y16 = (uint16_t*)dst_sample; + dst_uv16 = dst_y16 + (ptrdiff_t)dst_stride_y * abs_height; + if (format == FOURCC_P010) { + r = I420ToP010(y, y_stride, u, u_stride, v, v_stride, dst_y16, + dst_stride_y, dst_uv16, dst_stride_uv, width, height); + } else { + r = I420ToP210(y, y_stride, u, u_stride, v, v_stride, dst_y16, + dst_stride_y, dst_uv16, dst_stride_uv, width, height); + } + break; + } + case FOURCC_P410: { + const int uv_min = width * 2; + int dst_stride_y; + int dst_stride_uv; + uint16_t* dst_y16; + uint16_t* dst_uv16; + if (dst_sample_stride == 0) { + dst_stride_y = width; + dst_stride_uv = uv_min; + } else { + if (dst_sample_stride & 1) { + return -1; + } + dst_stride_y = dst_sample_stride / 2; + dst_stride_uv = dst_sample_stride; + if (Abs(dst_stride_uv) < uv_min) { + return -1; + } + } + dst_y16 = (uint16_t*)dst_sample; + dst_uv16 = dst_y16 + (ptrdiff_t)dst_stride_y * abs_height; + r = I420ToP410(y, y_stride, u, u_stride, v, v_stride, dst_y16, + dst_stride_y, dst_uv16, dst_stride_uv, width, height); + break; + } // Triplanar formats case FOURCC_I420: case FOURCC_YV12: { dst_sample_stride = dst_sample_stride ? dst_sample_stride : width; int halfstride = (dst_sample_stride + 1) / 2; - int halfheight = (height + 1) / 2; + int halfheight = (abs_height + 1) / 2; uint8_t* dst_u; uint8_t* dst_v; if (format == FOURCC_YV12) { - dst_v = dst_sample + dst_sample_stride * height; - dst_u = dst_v + halfstride * halfheight; + dst_v = dst_sample + (ptrdiff_t)dst_sample_stride * abs_height; + dst_u = dst_v + (ptrdiff_t)halfstride * halfheight; } else { - dst_u = dst_sample + dst_sample_stride * height; - dst_v = dst_u + halfstride * halfheight; + dst_u = dst_sample + (ptrdiff_t)dst_sample_stride * abs_height; + dst_v = dst_u + (ptrdiff_t)halfstride * halfheight; } r = I420Copy(y, y_stride, u, u_stride, v, v_stride, dst_sample, dst_sample_stride, dst_u, halfstride, dst_v, halfstride, @@ -1464,11 +1246,11 @@ int ConvertFromI420(const uint8_t* y, uint8_t* dst_u; uint8_t* dst_v; if (format == FOURCC_YV16) { - dst_v = dst_sample + dst_sample_stride * height; - dst_u = dst_v + halfstride * height; + dst_v = dst_sample + (ptrdiff_t)dst_sample_stride * abs_height; + dst_u = dst_v + (ptrdiff_t)halfstride * abs_height; } else { - dst_u = dst_sample + dst_sample_stride * height; - dst_v = dst_u + halfstride * height; + dst_u = dst_sample + (ptrdiff_t)dst_sample_stride * abs_height; + dst_v = dst_u + (ptrdiff_t)halfstride * abs_height; } r = I420ToI422(y, y_stride, u, u_stride, v, v_stride, dst_sample, dst_sample_stride, dst_u, halfstride, dst_v, halfstride, @@ -1481,11 +1263,11 @@ int ConvertFromI420(const uint8_t* y, uint8_t* dst_u; uint8_t* dst_v; if (format == FOURCC_YV24) { - dst_v = dst_sample + dst_sample_stride * height; - dst_u = dst_v + dst_sample_stride * height; + dst_v = dst_sample + (ptrdiff_t)dst_sample_stride * abs_height; + dst_u = dst_v + (ptrdiff_t)dst_sample_stride * abs_height; } else { - dst_u = dst_sample + dst_sample_stride * height; - dst_v = dst_u + dst_sample_stride * height; + dst_u = dst_sample + (ptrdiff_t)dst_sample_stride * abs_height; + dst_v = dst_u + (ptrdiff_t)dst_sample_stride * abs_height; } r = I420ToI444(y, y_stride, u, u_stride, v, v_stride, dst_sample, dst_sample_stride, dst_u, dst_sample_stride, dst_v, diff --git a/libs/libyuv/source/convert_from_argb.cc b/libs/libyuv/source/convert_from_argb.cc index b7b5643a18..8f71a0ad32 100644 --- a/libs/libyuv/source/convert_from_argb.cc +++ b/libs/libyuv/source/convert_from_argb.cc @@ -10,7 +10,11 @@ #include "libyuv/convert_from_argb.h" -#include "libyuv/basic_types.h" +#include +#include +#include // For memcpy. + +#include "libyuv/convert.h" #include "libyuv/cpu_id.h" #include "libyuv/planar_functions.h" #include "libyuv/row.h" @@ -32,102 +36,201 @@ int ARGBToI444(const uint8_t* src_argb, int dst_stride_v, int width, int height) { + return ARGBToI444Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kArgbI601Constants, width, height); +} + +LIBYUV_API +int ARGBToI444Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + const struct ArgbConstants* argbconstants, + int width, + int height) { int y; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; - void (*ARGBToUV444Row)(const uint8_t* src_argb, uint8_t* dst_u, - uint8_t* dst_v, int width) = ARGBToUV444Row_C; - if (!src_argb || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { - return -1; - } - if (height < 0) { - height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; - src_stride_argb = -src_stride_argb; - } - // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_y == width && - dst_stride_u == width && dst_stride_v == width) { - width *= height; - height = 1; - src_stride_argb = dst_stride_y = dst_stride_u = dst_stride_v = 0; - } -#if defined(HAS_ARGBTOUV444ROW_SSSE3) + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUV444MatrixRow)( + const uint8_t* src_argb, uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = ARGBToUV444MatrixRow_C; + +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUV444Row = ARGBToUV444Row_Any_SSSE3; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; if (IS_ALIGNED(width, 16)) { - ARGBToUV444Row = ARGBToUV444Row_SSSE3; + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; } } #endif -#if defined(HAS_ARGBTOUV444ROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToUV444Row = ARGBToUV444Row_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToUV444Row = ARGBToUV444Row_NEON; - } - } -#endif -#if defined(HAS_ARGBTOUV444ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToUV444Row = ARGBToUV444Row_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBToUV444Row = ARGBToUV444Row_MSA; - } - } -#endif -#if defined(HAS_ARGBTOUV444ROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToUV444Row = ARGBToUV444Row_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToUV444Row = ARGBToUV444Row_MMI; - } - } -#endif -#if defined(HAS_ARGBTOYROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToYRow = ARGBToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToYRow = ARGBToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_AVX2) +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToYRow = ARGBToYRow_Any_AVX2; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; if (IS_ALIGNED(width, 32)) { - ARGBToYRow = ARGBToYRow_AVX2; + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; } } #endif -#if defined(HAS_ARGBTOYROW_NEON) +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYRow = ARGBToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYRow = ARGBToYRow_Any_MSA; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; if (IS_ALIGNED(width, 16)) { - ARGBToYRow = ARGBToYRow_MSA; + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; } } #endif -#if defined(HAS_ARGBTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYRow = ARGBToYRow_Any_MMI; +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_MMI; + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; } } #endif +#if defined(HAS_ARGBTOUV444MATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_NEON_I8MM; + if (IS_ALIGNED(width, 8)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_NEON_I8MM; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_WASMSIMD; + } + } +#endif + if (!src_argb || !dst_y || !dst_u || !dst_v || !argbconstants || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } + for (y = 0; y < height; ++y) { - ARGBToUV444Row(src_argb, dst_u, dst_v, width); - ARGBToYRow(src_argb, dst_y, width); + ARGBToYMatrixRow(src_argb, dst_y, width, argbconstants); + ARGBToUV444MatrixRow(src_argb, dst_u, dst_v, width, argbconstants); src_argb += src_stride_argb; dst_y += dst_stride_y; dst_u += dst_stride_u; @@ -148,102 +251,216 @@ int ARGBToI422(const uint8_t* src_argb, int dst_stride_v, int width, int height) { + return ARGBToI422Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kArgbI601Constants, width, height); +} + +LIBYUV_API +int ARGBToI422Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + const struct ArgbConstants* argbconstants, + int width, + int height) { int y; - void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVRow_C; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; - if (!src_argb || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUVMatrixRow)(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + ARGBToUVMatrixRow_C; + +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON_I8MM; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON_I8MM; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SVE2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SME; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_WASMSIMD; + } + } +#endif + if (!src_argb || !dst_y || !dst_u || !dst_v || !argbconstants || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } - // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_y == width && - dst_stride_u * 2 == width && dst_stride_v * 2 == width) { - width *= height; - height = 1; - src_stride_argb = dst_stride_y = dst_stride_u = dst_stride_v = 0; - } -#if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVRow = ARGBToUVRow_Any_SSSE3; - ARGBToYRow = ARGBToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_SSSE3; - ARGBToYRow = ARGBToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVRow = ARGBToUVRow_Any_AVX2; - ARGBToYRow = ARGBToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_AVX2; - ARGBToYRow = ARGBToYRow_AVX2; - } - } -#endif -#if defined(HAS_ARGBTOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYRow = ARGBToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToUVRow = ARGBToUVRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_NEON; - } - } -#endif - -#if defined(HAS_ARGBTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYRow = ARGBToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBToYRow = ARGBToYRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToUVRow = ARGBToUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_MSA; - } - } -#endif - -#if defined(HAS_ARGBTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYRow = ARGBToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_MMI; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToUVRow = ARGBToUVRow_Any_MMI; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_MMI; - } - } -#endif for (y = 0; y < height; ++y) { - ARGBToUVRow(src_argb, 0, dst_u, dst_v, width); - ARGBToYRow(src_argb, dst_y, width); + ARGBToUVMatrixRow(src_argb, 0, dst_u, dst_v, width, argbconstants); + ARGBToYMatrixRow(src_argb, dst_y, width, argbconstants); src_argb += src_stride_argb; dst_y += dst_stride_y; dst_u += dst_stride_u; @@ -261,738 +478,1492 @@ int ARGBToNV12(const uint8_t* src_argb, int dst_stride_uv, int width, int height) { + return ARGBToNV12Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, + dst_uv, dst_stride_uv, &kArgbI601Constants, width, + height); +} + +LIBYUV_API +int ARGBToNV12Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height) { int y; int halfwidth = (width + 1) >> 1; - void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVRow_C; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; - void (*MergeUVRow_)(const uint8_t* src_u, const uint8_t* src_v, - uint8_t* dst_uv, int width) = MergeUVRow_C; - if (!src_argb || !dst_y || !dst_uv || width <= 0 || height == 0) { + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUVMatrixRow)(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + ARGBToUVMatrixRow_C; + +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON_I8MM; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON_I8MM; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SVE2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SME; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_WASMSIMD; + } + } +#endif + void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, + uint8_t* dst_uv, int width) = MergeUVRow_C; + if (!src_argb || !dst_y || !dst_uv || !argbconstants || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } -#if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVRow = ARGBToUVRow_Any_SSSE3; - ARGBToYRow = ARGBToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_SSSE3; - ARGBToYRow = ARGBToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVRow = ARGBToUVRow_Any_AVX2; - ARGBToYRow = ARGBToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_AVX2; - ARGBToYRow = ARGBToYRow_AVX2; - } - } -#endif -#if defined(HAS_ARGBTOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYRow = ARGBToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToUVRow = ARGBToUVRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYRow = ARGBToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBToYRow = ARGBToYRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToUVRow = ARGBToUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYRow = ARGBToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_MMI; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToUVRow = ARGBToUVRow_Any_MMI; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_MMI; - } - } -#endif #if defined(HAS_MERGEUVROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { - MergeUVRow_ = MergeUVRow_Any_SSE2; + MergeUVRow = MergeUVRow_Any_SSE2; if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_SSE2; + MergeUVRow = MergeUVRow_SSE2; } } #endif #if defined(HAS_MERGEUVROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - MergeUVRow_ = MergeUVRow_Any_AVX2; - if (IS_ALIGNED(halfwidth, 32)) { - MergeUVRow_ = MergeUVRow_AVX2; + MergeUVRow = MergeUVRow_Any_AVX2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_AVX2; } } #endif +#if defined(HAS_MERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow = MergeUVRow_AVX512BW; + } +#endif #if defined(HAS_MERGEUVROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - MergeUVRow_ = MergeUVRow_Any_NEON; + MergeUVRow = MergeUVRow_Any_NEON; if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_NEON; + MergeUVRow = MergeUVRow_NEON; } } #endif -#if defined(HAS_MERGEUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - MergeUVRow_ = MergeUVRow_Any_MSA; +#if defined(HAS_MERGEUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + MergeUVRow = MergeUVRow_SVE2; + } +#endif +#if defined(HAS_MERGEUVROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow = MergeUVRow_SME; + } +#endif +#if defined(HAS_MERGEUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MergeUVRow = MergeUVRow_Any_LSX; if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_MSA; + MergeUVRow = MergeUVRow_LSX; } } #endif -#if defined(HAS_MERGEUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - MergeUVRow_ = MergeUVRow_Any_MMI; - if (IS_ALIGNED(halfwidth, 8)) { - MergeUVRow_ = MergeUVRow_MMI; +#if defined(HAS_MERGEUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MergeUVRow = MergeUVRow_Any_LASX; + if (IS_ALIGNED(halfwidth, 32)) { + MergeUVRow = MergeUVRow_LASX; + } + } +#endif +#if defined(HAS_MERGEUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeUVRow = MergeUVRow_RVV; + } +#endif +#if defined(HAS_MERGEUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow = MergeUVRow_HVX; + } +#endif +#if defined(HAS_MERGEUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MergeUVRow = MergeUVRow_Any_WASMSIMD; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_WASMSIMD; } } #endif - { - // Allocate a rows of uv. - align_buffer_64(row_u, ((halfwidth + 31) & ~31) * 2); - uint8_t* row_v = row_u + ((halfwidth + 31) & ~31); - for (y = 0; y < height - 1; y += 2) { - ARGBToUVRow(src_argb, src_stride_argb, row_u, row_v, width); - MergeUVRow_(row_u, row_v, dst_uv, halfwidth); - ARGBToYRow(src_argb, dst_y, width); - ARGBToYRow(src_argb + src_stride_argb, dst_y + dst_stride_y, width); - src_argb += src_stride_argb * 2; - dst_y += dst_stride_y * 2; - dst_uv += dst_stride_uv; - } - if (height & 1) { - ARGBToUVRow(src_argb, 0, row_u, row_v, width); - MergeUVRow_(row_u, row_v, dst_uv, halfwidth); - ARGBToYRow(src_argb, dst_y, width); - } - free_aligned_buffer_64(row_u); + // Allocate a rows of uv. + align_buffer_64(row_u, ((halfwidth + 31) & ~31) * 2); + uint8_t* row_v = row_u + ((halfwidth + 31) & ~31); + if (!row_u) + return 1; + + for (y = 0; y < height - 1; y += 2) { + ARGBToUVMatrixRow(src_argb, src_stride_argb, row_u, row_v, width, + argbconstants); + MergeUVRow(row_u, row_v, dst_uv, halfwidth); + ARGBToYMatrixRow(src_argb, dst_y, width, argbconstants); + ARGBToYMatrixRow(src_argb + src_stride_argb, dst_y + dst_stride_y, width, + argbconstants); + src_argb += src_stride_argb * 2; + dst_y += dst_stride_y * 2; + dst_uv += dst_stride_uv; } + if (height & 1) { + ARGBToUVMatrixRow(src_argb, 0, row_u, row_v, width, argbconstants); + MergeUVRow(row_u, row_v, dst_uv, halfwidth); + ARGBToYMatrixRow(src_argb, dst_y, width, argbconstants); + } + free_aligned_buffer_64(row_u); return 0; } -// Same as NV12 but U and V swapped. LIBYUV_API -int ARGBToNV21(const uint8_t* src_argb, +int ARGBToNV16(const uint8_t* src_argb, int src_stride_argb, uint8_t* dst_y, int dst_stride_y, - uint8_t* dst_vu, - int dst_stride_vu, - int width, - int height) { - int y; - int halfwidth = (width + 1) >> 1; - void (*ARGBToUVRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVRow_C; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; - void (*MergeUVRow_)(const uint8_t* src_u, const uint8_t* src_v, - uint8_t* dst_vu, int width) = MergeUVRow_C; - if (!src_argb || !dst_y || !dst_vu || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; - src_stride_argb = -src_stride_argb; - } -#if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVRow = ARGBToUVRow_Any_SSSE3; - ARGBToYRow = ARGBToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_SSSE3; - ARGBToYRow = ARGBToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVRow = ARGBToUVRow_Any_AVX2; - ARGBToYRow = ARGBToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_AVX2; - ARGBToYRow = ARGBToYRow_AVX2; - } - } -#endif -#if defined(HAS_ARGBTOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYRow = ARGBToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToUVRow = ARGBToUVRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYRow = ARGBToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBToYRow = ARGBToYRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToUVRow = ARGBToUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYRow = ARGBToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_MMI; - } - } -#endif -#if defined(HAS_ARGBTOUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToUVRow = ARGBToUVRow_Any_MMI; - if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_MMI; - } - } -#endif - -#if defined(HAS_MERGEUVROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - MergeUVRow_ = MergeUVRow_Any_SSE2; - if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_SSE2; - } - } -#endif -#if defined(HAS_MERGEUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - MergeUVRow_ = MergeUVRow_Any_AVX2; - if (IS_ALIGNED(halfwidth, 32)) { - MergeUVRow_ = MergeUVRow_AVX2; - } - } -#endif -#if defined(HAS_MERGEUVROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - MergeUVRow_ = MergeUVRow_Any_NEON; - if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_NEON; - } - } -#endif -#if defined(HAS_MERGEUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - MergeUVRow_ = MergeUVRow_Any_MSA; - if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_MSA; - } - } -#endif -#if defined(HAS_MERGEUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - MergeUVRow_ = MergeUVRow_Any_MMI; - if (IS_ALIGNED(halfwidth, 8)) { - MergeUVRow_ = MergeUVRow_MMI; - } - } -#endif - { - // Allocate a rows of uv. - align_buffer_64(row_u, ((halfwidth + 31) & ~31) * 2); - uint8_t* row_v = row_u + ((halfwidth + 31) & ~31); - - for (y = 0; y < height - 1; y += 2) { - ARGBToUVRow(src_argb, src_stride_argb, row_u, row_v, width); - MergeUVRow_(row_v, row_u, dst_vu, halfwidth); - ARGBToYRow(src_argb, dst_y, width); - ARGBToYRow(src_argb + src_stride_argb, dst_y + dst_stride_y, width); - src_argb += src_stride_argb * 2; - dst_y += dst_stride_y * 2; - dst_vu += dst_stride_vu; - } - if (height & 1) { - ARGBToUVRow(src_argb, 0, row_u, row_v, width); - MergeUVRow_(row_v, row_u, dst_vu, halfwidth); - ARGBToYRow(src_argb, dst_y, width); - } - free_aligned_buffer_64(row_u); - } - return 0; -} - -LIBYUV_API -int ABGRToNV12(const uint8_t* src_abgr, - int src_stride_abgr, - uint8_t* dst_y, - int dst_stride_y, uint8_t* dst_uv, int dst_stride_uv, int width, int height) { + return ARGBToNV16Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, + dst_uv, dst_stride_uv, &kArgbI601Constants, width, + height); +} + +LIBYUV_API +int ARGBToNV16Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height) { int y; - int halfwidth = (width + 1) >> 1; - void (*ABGRToUVRow)(const uint8_t* src_abgr0, int src_stride_abgr, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ABGRToUVRow_C; - void (*ABGRToYRow)(const uint8_t* src_abgr, uint8_t* dst_y, int width) = - ABGRToYRow_C; - void (*MergeUVRow_)(const uint8_t* src_u, const uint8_t* src_v, - uint8_t* dst_uv, int width) = MergeUVRow_C; - if (!src_abgr || !dst_y || !dst_uv || width <= 0 || height == 0) { + int halfwidth = (width >> 1) + (width & 1); + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUVMatrixRow)(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + ARGBToUVMatrixRow_C; + +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON_I8MM; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON_I8MM; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SVE2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SME; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_WASMSIMD; + } + } +#endif + void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, + uint8_t* dst_uv, int width) = MergeUVRow_C; + if (!src_argb || !dst_y || !dst_uv || !argbconstants || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_abgr = src_abgr + (height - 1) * src_stride_abgr; - src_stride_abgr = -src_stride_abgr; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; } -#if defined(HAS_ABGRTOYROW_SSSE3) && defined(HAS_ABGRTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ABGRToUVRow = ABGRToUVRow_Any_SSSE3; - ABGRToYRow = ABGRToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ABGRToUVRow = ABGRToUVRow_SSSE3; - ABGRToYRow = ABGRToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ABGRTOYROW_AVX2) && defined(HAS_ABGRTOUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ABGRToUVRow = ABGRToUVRow_Any_AVX2; - ABGRToYRow = ABGRToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ABGRToUVRow = ABGRToUVRow_AVX2; - ABGRToYRow = ABGRToYRow_AVX2; - } - } -#endif -#if defined(HAS_ABGRTOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ABGRToYRow = ABGRToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ABGRToYRow = ABGRToYRow_NEON; - } - } -#endif -#if defined(HAS_ABGRTOUVROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ABGRToUVRow = ABGRToUVRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { - ABGRToUVRow = ABGRToUVRow_NEON; - } - } -#endif -#if defined(HAS_ABGRTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ABGRToYRow = ABGRToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ABGRToYRow = ABGRToYRow_MSA; - } - } -#endif -#if defined(HAS_ABGRTOUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ABGRToUVRow = ABGRToUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - ABGRToUVRow = ABGRToUVRow_MSA; - } - } -#endif -#if defined(HAS_ABGRTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ABGRToYRow = ABGRToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ABGRToYRow = ABGRToYRow_MMI; - } - } -#endif -#if defined(HAS_ABGRTOUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ABGRToUVRow = ABGRToUVRow_Any_MMI; - if (IS_ALIGNED(width, 16)) { - ABGRToUVRow = ABGRToUVRow_MMI; - } - } -#endif #if defined(HAS_MERGEUVROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { - MergeUVRow_ = MergeUVRow_Any_SSE2; + MergeUVRow = MergeUVRow_Any_SSE2; if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_SSE2; + MergeUVRow = MergeUVRow_SSE2; } } #endif #if defined(HAS_MERGEUVROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - MergeUVRow_ = MergeUVRow_Any_AVX2; - if (IS_ALIGNED(halfwidth, 32)) { - MergeUVRow_ = MergeUVRow_AVX2; + MergeUVRow = MergeUVRow_Any_AVX2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_AVX2; } } #endif +#if defined(HAS_MERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow = MergeUVRow_AVX512BW; + } +#endif #if defined(HAS_MERGEUVROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - MergeUVRow_ = MergeUVRow_Any_NEON; + MergeUVRow = MergeUVRow_Any_NEON; if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_NEON; + MergeUVRow = MergeUVRow_NEON; } } #endif -#if defined(HAS_MERGEUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - MergeUVRow_ = MergeUVRow_Any_MSA; +#if defined(HAS_MERGEUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + MergeUVRow = MergeUVRow_SVE2; + } +#endif +#if defined(HAS_MERGEUVROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow = MergeUVRow_SME; + } +#endif +#if defined(HAS_MERGEUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MergeUVRow = MergeUVRow_Any_LSX; if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_MSA; + MergeUVRow = MergeUVRow_LSX; } } #endif -#if defined(HAS_MERGEUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - MergeUVRow_ = MergeUVRow_Any_MMI; - if (IS_ALIGNED(halfwidth, 8)) { - MergeUVRow_ = MergeUVRow_MMI; +#if defined(HAS_MERGEUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MergeUVRow = MergeUVRow_Any_LASX; + if (IS_ALIGNED(halfwidth, 32)) { + MergeUVRow = MergeUVRow_LASX; + } + } +#endif +#if defined(HAS_MERGEUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeUVRow = MergeUVRow_RVV; + } +#endif +#if defined(HAS_MERGEUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow = MergeUVRow_HVX; + } +#endif +#if defined(HAS_MERGEUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MergeUVRow = MergeUVRow_Any_WASMSIMD; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_WASMSIMD; } } #endif - { - // Allocate a rows of uv. - align_buffer_64(row_u, ((halfwidth + 31) & ~31) * 2); - uint8_t* row_v = row_u + ((halfwidth + 31) & ~31); - for (y = 0; y < height - 1; y += 2) { - ABGRToUVRow(src_abgr, src_stride_abgr, row_u, row_v, width); - MergeUVRow_(row_u, row_v, dst_uv, halfwidth); - ABGRToYRow(src_abgr, dst_y, width); - ABGRToYRow(src_abgr + src_stride_abgr, dst_y + dst_stride_y, width); - src_abgr += src_stride_abgr * 2; - dst_y += dst_stride_y * 2; - dst_uv += dst_stride_uv; - } - if (height & 1) { - ABGRToUVRow(src_abgr, 0, row_u, row_v, width); - MergeUVRow_(row_u, row_v, dst_uv, halfwidth); - ABGRToYRow(src_abgr, dst_y, width); - } - free_aligned_buffer_64(row_u); + size_t row_size = + (static_cast(halfwidth) + 31) & ~static_cast(31); + if (row_size > SIZE_MAX / 2) { + return -1; } + align_buffer_64(row_u, row_size * 2); + if (!row_u) + return 1; + uint8_t* row_v = row_u + row_size; + + for (y = 0; y < height; ++y) { + ARGBToUVMatrixRow(src_argb, 0, row_u, row_v, width, argbconstants); + ARGBToYMatrixRow(src_argb, dst_y, width, argbconstants); + MergeUVRow(row_u, row_v, dst_uv, halfwidth); + src_argb += src_stride_argb; + dst_y += dst_stride_y; + dst_uv += dst_stride_uv; + } + free_aligned_buffer_64(row_u); return 0; } -// Same as NV12 but U and V swapped. LIBYUV_API -int ABGRToNV21(const uint8_t* src_abgr, - int src_stride_abgr, +int ARGBToNV24(const uint8_t* src_argb, + int src_stride_argb, uint8_t* dst_y, int dst_stride_y, - uint8_t* dst_vu, - int dst_stride_vu, + uint8_t* dst_uv, + int dst_stride_uv, int width, int height) { + return ARGBToNV24Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, + dst_uv, dst_stride_uv, &kArgbI601Constants, width, + height); +} + +LIBYUV_API +int ARGBToNV24Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height) { int y; - int halfwidth = (width + 1) >> 1; - void (*ABGRToUVRow)(const uint8_t* src_abgr0, int src_stride_abgr, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ABGRToUVRow_C; - void (*ABGRToYRow)(const uint8_t* src_abgr, uint8_t* dst_y, int width) = - ABGRToYRow_C; - void (*MergeUVRow_)(const uint8_t* src_u, const uint8_t* src_v, - uint8_t* dst_vu, int width) = MergeUVRow_C; - if (!src_abgr || !dst_y || !dst_vu || width <= 0 || height == 0) { + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUV444MatrixRow)( + const uint8_t* src_argb, uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = ARGBToUV444MatrixRow_C; + +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif + +#if defined(HAS_ARGBTOUV444MATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_NEON_I8MM; + if (IS_ALIGNED(width, 8)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_NEON_I8MM; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_WASMSIMD; + } + } +#endif + void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, + uint8_t* dst_uv, int width) = MergeUVRow_C; + if (!src_argb || !dst_y || !dst_uv || !argbconstants || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_abgr = src_abgr + (height - 1) * src_stride_abgr; - src_stride_abgr = -src_stride_abgr; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; } -#if defined(HAS_ABGRTOYROW_SSSE3) && defined(HAS_ABGRTOUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ABGRToUVRow = ABGRToUVRow_Any_SSSE3; - ABGRToYRow = ABGRToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ABGRToUVRow = ABGRToUVRow_SSSE3; - ABGRToYRow = ABGRToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ABGRTOYROW_AVX2) && defined(HAS_ABGRTOUVROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ABGRToUVRow = ABGRToUVRow_Any_AVX2; - ABGRToYRow = ABGRToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ABGRToUVRow = ABGRToUVRow_AVX2; - ABGRToYRow = ABGRToYRow_AVX2; - } - } -#endif -#if defined(HAS_ABGRTOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ABGRToYRow = ABGRToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ABGRToYRow = ABGRToYRow_NEON; - } - } -#endif -#if defined(HAS_ABGRTOUVROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ABGRToUVRow = ABGRToUVRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { - ABGRToUVRow = ABGRToUVRow_NEON; - } - } -#endif -#if defined(HAS_ABGRTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ABGRToYRow = ABGRToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ABGRToYRow = ABGRToYRow_MSA; - } - } -#endif -#if defined(HAS_ABGRTOUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ABGRToUVRow = ABGRToUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - ABGRToUVRow = ABGRToUVRow_MSA; - } - } -#endif -#if defined(HAS_ABGRTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ABGRToYRow = ABGRToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ABGRToYRow = ABGRToYRow_MMI; - } - } -#endif -#if defined(HAS_ABGRTOUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ABGRToUVRow = ABGRToUVRow_Any_MMI; - if (IS_ALIGNED(width, 16)) { - ABGRToUVRow = ABGRToUVRow_MMI; - } - } -#endif - #if defined(HAS_MERGEUVROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { - MergeUVRow_ = MergeUVRow_Any_SSE2; - if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_SSE2; + MergeUVRow = MergeUVRow_Any_SSE2; + if (IS_ALIGNED(width, 16)) { + MergeUVRow = MergeUVRow_SSE2; } } #endif #if defined(HAS_MERGEUVROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - MergeUVRow_ = MergeUVRow_Any_AVX2; - if (IS_ALIGNED(halfwidth, 32)) { - MergeUVRow_ = MergeUVRow_AVX2; + MergeUVRow = MergeUVRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + MergeUVRow = MergeUVRow_AVX2; } } #endif +#if defined(HAS_MERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow = MergeUVRow_AVX512BW; + } +#endif #if defined(HAS_MERGEUVROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - MergeUVRow_ = MergeUVRow_Any_NEON; - if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_NEON; + MergeUVRow = MergeUVRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + MergeUVRow = MergeUVRow_NEON; } } #endif -#if defined(HAS_MERGEUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - MergeUVRow_ = MergeUVRow_Any_MSA; - if (IS_ALIGNED(halfwidth, 16)) { - MergeUVRow_ = MergeUVRow_MSA; +#if defined(HAS_MERGEUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + MergeUVRow = MergeUVRow_SVE2; + } +#endif +#if defined(HAS_MERGEUVROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow = MergeUVRow_SME; + } +#endif +#if defined(HAS_MERGEUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MergeUVRow = MergeUVRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + MergeUVRow = MergeUVRow_LSX; } } #endif -#if defined(HAS_MERGEUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - MergeUVRow_ = MergeUVRow_Any_MMI; - if (IS_ALIGNED(halfwidth, 8)) { - MergeUVRow_ = MergeUVRow_MMI; +#if defined(HAS_MERGEUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MergeUVRow = MergeUVRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + MergeUVRow = MergeUVRow_LASX; + } + } +#endif +#if defined(HAS_MERGEUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeUVRow = MergeUVRow_RVV; + } +#endif +#if defined(HAS_MERGEUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow = MergeUVRow_HVX; + } +#endif +#if defined(HAS_MERGEUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MergeUVRow = MergeUVRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + MergeUVRow = MergeUVRow_WASMSIMD; } } #endif - { - // Allocate a rows of uv. - align_buffer_64(row_u, ((halfwidth + 31) & ~31) * 2); - uint8_t* row_v = row_u + ((halfwidth + 31) & ~31); - for (y = 0; y < height - 1; y += 2) { - ABGRToUVRow(src_abgr, src_stride_abgr, row_u, row_v, width); - MergeUVRow_(row_v, row_u, dst_vu, halfwidth); - ABGRToYRow(src_abgr, dst_y, width); - ABGRToYRow(src_abgr + src_stride_abgr, dst_y + dst_stride_y, width); - src_abgr += src_stride_abgr * 2; - dst_y += dst_stride_y * 2; - dst_vu += dst_stride_vu; - } - if (height & 1) { - ABGRToUVRow(src_abgr, 0, row_u, row_v, width); - MergeUVRow_(row_v, row_u, dst_vu, halfwidth); - ABGRToYRow(src_abgr, dst_y, width); - } - free_aligned_buffer_64(row_u); + size_t row_size = + (static_cast(width) + 31) & ~static_cast(31); + if (row_size > SIZE_MAX / 2) { + return -1; } + align_buffer_64(row_u, row_size * 2); + if (!row_u) + return 1; + uint8_t* row_v = row_u + row_size; + + for (y = 0; y < height; ++y) { + ARGBToUV444MatrixRow(src_argb, row_u, row_v, width, argbconstants); + ARGBToYMatrixRow(src_argb, dst_y, width, argbconstants); + MergeUVRow(row_u, row_v, dst_uv, width); + src_argb += src_stride_argb; + dst_y += dst_stride_y; + dst_uv += dst_stride_uv; + } + free_aligned_buffer_64(row_u); return 0; } -// Convert ARGB to YUY2. LIBYUV_API -int ARGBToYUY2(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_yuy2, - int dst_stride_yuy2, - int width, - int height) { +int ARGBToNV21Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + const struct ArgbConstants* argbconstants, + int width, + int height) { int y; - void (*ARGBToUVRow)(const uint8_t* src_argb, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVRow_C; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; + int halfwidth = (width + 1) >> 1; + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUVMatrixRow)(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + ARGBToUVMatrixRow_C; + +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON_I8MM; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON_I8MM; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SVE2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SME; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_WASMSIMD; + } + } +#endif + void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, + uint8_t* dst_vu, int width) = MergeUVRow_C; + if (!src_argb || !dst_y || !dst_vu || !argbconstants || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } +#if defined(HAS_MERGEUVROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + MergeUVRow = MergeUVRow_Any_SSE2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_SSE2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeUVRow = MergeUVRow_Any_AVX2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_AVX2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow = MergeUVRow_AVX512BW; + } +#endif +#if defined(HAS_MERGEUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeUVRow = MergeUVRow_Any_NEON; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_NEON; + } + } +#endif +#if defined(HAS_MERGEUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + MergeUVRow = MergeUVRow_SVE2; + } +#endif +#if defined(HAS_MERGEUVROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow = MergeUVRow_SME; + } +#endif +#if defined(HAS_MERGEUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MergeUVRow = MergeUVRow_Any_LSX; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_LSX; + } + } +#endif +#if defined(HAS_MERGEUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MergeUVRow = MergeUVRow_Any_LASX; + if (IS_ALIGNED(halfwidth, 32)) { + MergeUVRow = MergeUVRow_LASX; + } + } +#endif +#if defined(HAS_MERGEUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeUVRow = MergeUVRow_RVV; + } +#endif +#if defined(HAS_MERGEUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow = MergeUVRow_HVX; + } +#endif +#if defined(HAS_MERGEUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MergeUVRow = MergeUVRow_Any_WASMSIMD; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_WASMSIMD; + } + } +#endif + + // Allocate a rows of uv. + align_buffer_64(row_u, ((halfwidth + 31) & ~31) * 2); + uint8_t* row_v = row_u + ((halfwidth + 31) & ~31); + if (!row_u) + return 1; + + for (y = 0; y < height - 1; y += 2) { + ARGBToUVMatrixRow(src_argb, src_stride_argb, row_u, row_v, width, + argbconstants); + MergeUVRow(row_v, row_u, dst_vu, halfwidth); + ARGBToYMatrixRow(src_argb, dst_y, width, argbconstants); + ARGBToYMatrixRow(src_argb + src_stride_argb, dst_y + dst_stride_y, width, + argbconstants); + src_argb += src_stride_argb * 2; + dst_y += dst_stride_y * 2; + dst_vu += dst_stride_vu; + } + if (height & 1) { + ARGBToUVMatrixRow(src_argb, 0, row_u, row_v, width, argbconstants); + MergeUVRow(row_v, row_u, dst_vu, halfwidth); + ARGBToYMatrixRow(src_argb, dst_y, width, argbconstants); + } + free_aligned_buffer_64(row_u); + return 0; +} +LIBYUV_API +int ARGBToI400Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + const struct ArgbConstants* constants, + int width, + int height) { + int y; + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + if (!src_argb || !dst_y || !constants || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + if (height < 0) { + height = -height; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + ARGBToYMatrixRow(src_argb, dst_y, width, constants); + src_argb += src_stride_argb; + dst_y += dst_stride_y; + } + return 0; +} +LIBYUV_API +int ARGBToYUY2Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_yuy2, + int dst_stride_yuy2, + const struct ArgbConstants* constants, + int width, + int height) { + int y; + void (*ARGBToUVMatrixRow)(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + ARGBToUVMatrixRow_C; + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_yuy2, int width) = I422ToYUY2Row_C; - if (!src_argb || !dst_yuy2 || width <= 0 || height == 0) { + if (!src_argb || !dst_yuy2 || !constants || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } - // Negative height means invert the image. if (height < 0) { height = -height; - dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2; + dst_yuy2 = dst_yuy2 + (ptrdiff_t)(height - 1) * dst_stride_yuy2; dst_stride_yuy2 = -dst_stride_yuy2; } - // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_yuy2 == width * 2) { - width *= height; - height = 1; - src_stride_argb = dst_stride_yuy2 = 0; - } -#if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVRow = ARGBToUVRow_Any_SSSE3; - ARGBToYRow = ARGBToYRow_Any_SSSE3; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_SSSE3; - ARGBToYRow = ARGBToYRow_SSSE3; + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; } } #endif -#if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVRow = ARGBToUVRow_Any_AVX2; - ARGBToYRow = ARGBToYRow_Any_AVX2; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_AVX2; - ARGBToYRow = ARGBToYRow_AVX2; + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; } } #endif -#if defined(HAS_ARGBTOYROW_NEON) +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYRow = ARGBToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_NEON; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; } } #endif -#if defined(HAS_ARGBTOUVROW_NEON) +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - ARGBToUVRow = ARGBToUVRow_Any_NEON; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON; if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_NEON; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON; } } #endif -#if defined(HAS_ARGBTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYRow = ARGBToYRow_Any_MSA; +#if defined(HAS_ARGBTOUVMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON_I8MM; if (IS_ALIGNED(width, 16)) { - ARGBToYRow = ARGBToYRow_MSA; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON_I8MM; } } #endif -#if defined(HAS_ARGBTOUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToUVRow = ARGBToUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_MSA; +#if defined(HAS_ARGBTOUVMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SVE2; } } #endif -#if defined(HAS_ARGBTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYRow = ARGBToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_MMI; +#if defined(HAS_ARGBTOUVMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SME; } } #endif -#if defined(HAS_ARGBTOUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToUVRow = ARGBToUVRow_Any_MMI; +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_WASMSIMD; if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_MMI; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_WASMSIMD; } } #endif +#if defined(HAS_ARGBTOUVMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_HVX; + } +#endif #if defined(HAS_I422TOYUY2ROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { I422ToYUY2Row = I422ToYUY2Row_Any_SSE2; @@ -1017,32 +1988,17 @@ int ARGBToYUY2(const uint8_t* src_argb, } } #endif -#if defined(HAS_I422TOYUY2ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToYUY2Row = I422ToYUY2Row_Any_MSA; - if (IS_ALIGNED(width, 32)) { - I422ToYUY2Row = I422ToYUY2Row_MSA; - } - } -#endif -#if defined(HAS_I422TOYUY2ROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - I422ToYUY2Row = I422ToYUY2Row_Any_MMI; - if (IS_ALIGNED(width, 8)) { - I422ToYUY2Row = I422ToYUY2Row_MMI; - } - } -#endif { - // Allocate a rows of yuv. align_buffer_64(row_y, ((width + 63) & ~63) * 2); uint8_t* row_u = row_y + ((width + 63) & ~63); uint8_t* row_v = row_u + ((width + 63) & ~63) / 2; + if (!row_y) + return 1; for (y = 0; y < height; ++y) { - ARGBToUVRow(src_argb, 0, row_u, row_v, width); - ARGBToYRow(src_argb, row_y, width); + ARGBToUVMatrixRow(src_argb, 0, row_u, row_v, width, constants); + ARGBToYMatrixRow(src_argb, row_y, width, constants); I422ToYUY2Row(row_y, row_u, row_v, dst_yuy2, width); src_argb += src_stride_argb; dst_yuy2 += dst_stride_yuy2; @@ -1053,107 +2009,178 @@ int ARGBToYUY2(const uint8_t* src_argb, return 0; } -// Convert ARGB to UYVY. LIBYUV_API -int ARGBToUYVY(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_uyvy, - int dst_stride_uyvy, - int width, - int height) { +int ARGBToUYVYMatrix(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_uyvy, + int dst_stride_uyvy, + const struct ArgbConstants* constants, + int width, + int height) { int y; - void (*ARGBToUVRow)(const uint8_t* src_argb, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVRow_C; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; + void (*ARGBToUVMatrixRow)(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + ARGBToUVMatrixRow_C; + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uyvy, int width) = I422ToUYVYRow_C; - if (!src_argb || !dst_uyvy || width <= 0 || height == 0) { + if (!src_argb || !dst_uyvy || !constants || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } - // Negative height means invert the image. if (height < 0) { height = -height; - dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy; + dst_uyvy = dst_uyvy + (ptrdiff_t)(height - 1) * dst_stride_uyvy; dst_stride_uyvy = -dst_stride_uyvy; } - // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_uyvy == width * 2) { - width *= height; - height = 1; - src_stride_argb = dst_stride_uyvy = 0; - } -#if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVRow = ARGBToUVRow_Any_SSSE3; - ARGBToYRow = ARGBToYRow_Any_SSSE3; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_SSSE3; - ARGBToYRow = ARGBToYRow_SSSE3; + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; } } #endif -#if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToUVRow = ARGBToUVRow_Any_AVX2; - ARGBToYRow = ARGBToYRow_Any_AVX2; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_AVX2; - ARGBToYRow = ARGBToYRow_AVX2; + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; } } #endif -#if defined(HAS_ARGBTOYROW_NEON) +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYRow = ARGBToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_NEON; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; } } #endif -#if defined(HAS_ARGBTOUVROW_NEON) +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - ARGBToUVRow = ARGBToUVRow_Any_NEON; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON; if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_NEON; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON; } } #endif -#if defined(HAS_ARGBTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYRow = ARGBToYRow_Any_MSA; +#if defined(HAS_ARGBTOUVMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON_I8MM; if (IS_ALIGNED(width, 16)) { - ARGBToYRow = ARGBToYRow_MSA; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON_I8MM; } } #endif -#if defined(HAS_ARGBTOUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToUVRow = ARGBToUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - ARGBToUVRow = ARGBToUVRow_MSA; +#if defined(HAS_ARGBTOUVMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SVE2; } } #endif -#if defined(HAS_ARGBTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYRow = ARGBToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_MMI; +#if defined(HAS_ARGBTOUVMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SME; } } #endif -#if defined(HAS_ARGBTOUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToUVRow = ARGBToUVRow_Any_MMI; +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_WASMSIMD; if (IS_ALIGNED(width, 16)) { - ARGBToUVRow = ARGBToUVRow_MMI; + ARGBToUVMatrixRow = ARGBToUVMatrixRow_WASMSIMD; } } #endif +#if defined(HAS_ARGBTOUVMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_HVX; + } +#endif #if defined(HAS_I422TOUYVYROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { I422ToUYVYRow = I422ToUYVYRow_Any_SSE2; @@ -1178,32 +2205,17 @@ int ARGBToUYVY(const uint8_t* src_argb, } } #endif -#if defined(HAS_I422TOUYVYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToUYVYRow = I422ToUYVYRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - I422ToUYVYRow = I422ToUYVYRow_MSA; - } - } -#endif -#if defined(HAS_I422TOUYVYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - I422ToUYVYRow = I422ToUYVYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - I422ToUYVYRow = I422ToUYVYRow_MMI; - } - } -#endif { - // Allocate a rows of yuv. align_buffer_64(row_y, ((width + 63) & ~63) * 2); uint8_t* row_u = row_y + ((width + 63) & ~63); uint8_t* row_v = row_u + ((width + 63) & ~63) / 2; + if (!row_y) + return 1; for (y = 0; y < height; ++y) { - ARGBToUVRow(src_argb, 0, row_u, row_v, width); - ARGBToYRow(src_argb, row_y, width); + ARGBToUVMatrixRow(src_argb, 0, row_u, row_v, width, constants); + ARGBToYMatrixRow(src_argb, row_y, width, constants); I422ToUYVYRow(row_y, row_u, row_v, dst_uyvy, width); src_argb += src_stride_argb; dst_uyvy += dst_stride_uyvy; @@ -1214,6 +2226,1347 @@ int ARGBToUYVY(const uint8_t* src_argb, return 0; } +// Same as NV12 but U and V swapped. +LIBYUV_API +int ARGBToNV21(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + int width, + int height) { + return ARGBToNV21Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, + dst_vu, dst_stride_vu, &kArgbI601Constants, width, + height); +} + +LIBYUV_API +int ARGBToP010(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return ARGBToP010Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, + dst_uv, dst_stride_uv, &kArgbI601Constants, width, + height); +} + +LIBYUV_API +int ARGBToP010Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height) { + if (!src_argb || !dst_y || !dst_uv || !argbconstants || width <= 0 || + width > (INT_MAX / 2) || height == 0 || height == INT_MIN) { + return -1; + } + int y; + int halfwidth = (width >> 1) + (width & 1); + void (*Convert8To16Row)(const uint8_t* src_y, uint16_t* dst_y, int bits, + int width) = Convert8To16Row_C; + void (*MultiplyRow_16)(const uint16_t* src_y, uint16_t* dst_y, int scale, + int width) = MultiplyRow_16_C; + void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, + uint8_t* dst_uv, int width) = MergeUVRow_C; + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUVMatrixRow)(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + ARGBToUVMatrixRow_C; +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON_I8MM; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON_I8MM; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SVE2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SME; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_WASMSIMD; + } + } +#endif + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } +#if defined(HAS_CONVERT8TO16ROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + Convert8To16Row = Convert8To16Row_Any_SSE2; + if (IS_ALIGNED(width, 16)) { + Convert8To16Row = Convert8To16Row_SSE2; + } + } +#endif +#if defined(HAS_CONVERT8TO16ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Convert8To16Row = Convert8To16Row_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + Convert8To16Row = Convert8To16Row_AVX2; + } + } +#endif +#if defined(HAS_CONVERT8TO16ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Convert8To16Row = Convert8To16Row_AVX512BW; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Convert8To16Row = Convert8To16Row_Any_NEON; + if (IS_ALIGNED(width, 16)) { + Convert8To16Row = Convert8To16Row_NEON; + } + } +#endif +#if defined(HAS_CONVERT8TO16ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Convert8To16Row = Convert8To16Row_SME; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Convert8To16Row = Convert8To16Row_RVV; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Convert8To16Row = Convert8To16Row_HVX; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + Convert8To16Row = Convert8To16Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + Convert8To16Row = Convert8To16Row_WASMSIMD; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MultiplyRow_16 = MultiplyRow_16_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + MultiplyRow_16 = MultiplyRow_16_AVX2; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MultiplyRow_16 = MultiplyRow_16_AVX512BW; + } +#endif +#if defined(HAS_MULTIPLYROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MultiplyRow_16 = MultiplyRow_16_Any_NEON; + if (IS_ALIGNED(width, 16)) { + MultiplyRow_16 = MultiplyRow_16_NEON; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + MultiplyRow_16 = MultiplyRow_16_SME; + } +#endif +#if defined(HAS_MULTIPLYROW_16_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MultiplyRow_16 = MultiplyRow_16_RVV; + } +#endif +#if defined(HAS_MULTIPLYROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MultiplyRow_16 = MultiplyRow_16_HVX; + } +#endif +#if defined(HAS_MULTIPLYROW_16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MultiplyRow_16 = MultiplyRow_16_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + MultiplyRow_16 = MultiplyRow_16_WASMSIMD; + } + } +#endif +#if defined(HAS_MERGEUVROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + MergeUVRow = MergeUVRow_Any_SSE2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_SSE2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeUVRow = MergeUVRow_Any_AVX2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_AVX2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow = MergeUVRow_AVX512BW; + } +#endif +#if defined(HAS_MERGEUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeUVRow = MergeUVRow_Any_NEON; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_NEON; + } + } +#endif +#if defined(HAS_MERGEUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + MergeUVRow = MergeUVRow_SVE2; + } +#endif +#if defined(HAS_MERGEUVROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow = MergeUVRow_SME; + } +#endif +#if defined(HAS_MERGEUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MergeUVRow = MergeUVRow_Any_LSX; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_LSX; + } + } +#endif +#if defined(HAS_MERGEUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MergeUVRow = MergeUVRow_Any_LASX; + if (IS_ALIGNED(halfwidth, 32)) { + MergeUVRow = MergeUVRow_LASX; + } + } +#endif +#if defined(HAS_MERGEUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeUVRow = MergeUVRow_RVV; + } +#endif +#if defined(HAS_MERGEUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow = MergeUVRow_HVX; + } +#endif +#if defined(HAS_MERGEUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MergeUVRow = MergeUVRow_Any_WASMSIMD; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_WASMSIMD; + } + } +#endif + + size_t row_y_size = + (static_cast(width) + 31) & ~static_cast(31); + size_t row_uv_size = + (static_cast(halfwidth) + 31) & ~static_cast(31); + size_t row_uv_merged_size = + (static_cast(halfwidth) * 2 + 31) & ~static_cast(31); + if (row_uv_size > (SIZE_MAX - row_y_size) / 2) { + return -1; + } + size_t row_size = row_y_size + row_uv_size * 2; + if (row_uv_merged_size > SIZE_MAX - row_size) { + return -1; + } + align_buffer_64(row, row_size + row_uv_merged_size); + if (!row) + return 1; + uint8_t* row_y = row; + uint8_t* row_u = row_y + row_y_size; + uint8_t* row_v = row_u + row_uv_size; + uint8_t* row_uv = row_v + row_uv_size; + + for (y = 0; y < height - 1; y += 2) { + ARGBToUVMatrixRow(src_argb, src_stride_argb, row_u, row_v, width, + argbconstants); + MergeUVRow(row_u, row_v, row_uv, halfwidth); + Convert8To16Row(row_uv, dst_uv, 10, halfwidth * 2); + MultiplyRow_16(dst_uv, dst_uv, 64, halfwidth * 2); + ARGBToYMatrixRow(src_argb, row_y, width, argbconstants); + Convert8To16Row(row_y, dst_y, 10, width); + MultiplyRow_16(dst_y, dst_y, 64, width); + ARGBToYMatrixRow(src_argb + src_stride_argb, row_y, width, argbconstants); + Convert8To16Row(row_y, dst_y + dst_stride_y, 10, width); + MultiplyRow_16(dst_y + dst_stride_y, dst_y + dst_stride_y, 64, width); + src_argb += src_stride_argb * 2; + dst_y += dst_stride_y * 2; + dst_uv += dst_stride_uv; + } + if (height & 1) { + ARGBToUVMatrixRow(src_argb, 0, row_u, row_v, width, argbconstants); + MergeUVRow(row_u, row_v, row_uv, halfwidth); + Convert8To16Row(row_uv, dst_uv, 10, halfwidth * 2); + MultiplyRow_16(dst_uv, dst_uv, 64, halfwidth * 2); + ARGBToYMatrixRow(src_argb, row_y, width, argbconstants); + Convert8To16Row(row_y, dst_y, 10, width); + MultiplyRow_16(dst_y, dst_y, 64, width); + } + free_aligned_buffer_64(row); + return 0; +} + +LIBYUV_API +int ARGBToP210(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return ARGBToP210Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, + dst_uv, dst_stride_uv, &kArgbI601Constants, width, + height); +} + +LIBYUV_API +int ARGBToP210Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height) { + if (!src_argb || !dst_y || !dst_uv || !argbconstants || width <= 0 || + width > (INT_MAX / 2) || height == 0 || height == INT_MIN) { + return -1; + } + int y; + int halfwidth = (width >> 1) + (width & 1); + void (*Convert8To16Row)(const uint8_t* src_y, uint16_t* dst_y, int bits, + int width) = Convert8To16Row_C; + void (*MultiplyRow_16)(const uint16_t* src_y, uint16_t* dst_y, int scale, + int width) = MultiplyRow_16_C; + void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, + uint8_t* dst_uv, int width) = MergeUVRow_C; + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUVMatrixRow)(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = + ARGBToUVMatrixRow_C; +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_NEON_I8MM; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_NEON_I8MM; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SVE2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + if (IS_ALIGNED(width, 2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SME; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToUVMatrixRow = ARGBToUVMatrixRow_WASMSIMD; + } + } +#endif + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } +#if defined(HAS_CONVERT8TO16ROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + Convert8To16Row = Convert8To16Row_Any_SSE2; + if (IS_ALIGNED(width, 16)) { + Convert8To16Row = Convert8To16Row_SSE2; + } + } +#endif +#if defined(HAS_CONVERT8TO16ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Convert8To16Row = Convert8To16Row_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + Convert8To16Row = Convert8To16Row_AVX2; + } + } +#endif +#if defined(HAS_CONVERT8TO16ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Convert8To16Row = Convert8To16Row_AVX512BW; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Convert8To16Row = Convert8To16Row_Any_NEON; + if (IS_ALIGNED(width, 16)) { + Convert8To16Row = Convert8To16Row_NEON; + } + } +#endif +#if defined(HAS_CONVERT8TO16ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Convert8To16Row = Convert8To16Row_SME; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Convert8To16Row = Convert8To16Row_RVV; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Convert8To16Row = Convert8To16Row_HVX; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + Convert8To16Row = Convert8To16Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + Convert8To16Row = Convert8To16Row_WASMSIMD; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MultiplyRow_16 = MultiplyRow_16_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + MultiplyRow_16 = MultiplyRow_16_AVX2; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MultiplyRow_16 = MultiplyRow_16_AVX512BW; + } +#endif +#if defined(HAS_MULTIPLYROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MultiplyRow_16 = MultiplyRow_16_Any_NEON; + if (IS_ALIGNED(width, 16)) { + MultiplyRow_16 = MultiplyRow_16_NEON; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + MultiplyRow_16 = MultiplyRow_16_SME; + } +#endif +#if defined(HAS_MULTIPLYROW_16_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MultiplyRow_16 = MultiplyRow_16_RVV; + } +#endif +#if defined(HAS_MULTIPLYROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MultiplyRow_16 = MultiplyRow_16_HVX; + } +#endif +#if defined(HAS_MULTIPLYROW_16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MultiplyRow_16 = MultiplyRow_16_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + MultiplyRow_16 = MultiplyRow_16_WASMSIMD; + } + } +#endif +#if defined(HAS_MERGEUVROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + MergeUVRow = MergeUVRow_Any_SSE2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_SSE2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeUVRow = MergeUVRow_Any_AVX2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_AVX2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow = MergeUVRow_AVX512BW; + } +#endif +#if defined(HAS_MERGEUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeUVRow = MergeUVRow_Any_NEON; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_NEON; + } + } +#endif +#if defined(HAS_MERGEUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + MergeUVRow = MergeUVRow_SVE2; + } +#endif +#if defined(HAS_MERGEUVROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow = MergeUVRow_SME; + } +#endif +#if defined(HAS_MERGEUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MergeUVRow = MergeUVRow_Any_LSX; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_LSX; + } + } +#endif +#if defined(HAS_MERGEUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MergeUVRow = MergeUVRow_Any_LASX; + if (IS_ALIGNED(halfwidth, 32)) { + MergeUVRow = MergeUVRow_LASX; + } + } +#endif +#if defined(HAS_MERGEUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeUVRow = MergeUVRow_RVV; + } +#endif +#if defined(HAS_MERGEUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow = MergeUVRow_HVX; + } +#endif +#if defined(HAS_MERGEUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MergeUVRow = MergeUVRow_Any_WASMSIMD; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_WASMSIMD; + } + } +#endif + + size_t row_y_size = + (static_cast(width) + 31) & ~static_cast(31); + size_t row_uv_size = + (static_cast(halfwidth) + 31) & ~static_cast(31); + size_t row_uv_merged_size = + (static_cast(halfwidth) * 2 + 31) & ~static_cast(31); + if (row_uv_size > (SIZE_MAX - row_y_size) / 2) { + return -1; + } + size_t row_size = row_y_size + row_uv_size * 2; + if (row_uv_merged_size > SIZE_MAX - row_size) { + return -1; + } + align_buffer_64(row, row_size + row_uv_merged_size); + if (!row) + return 1; + uint8_t* row_y = row; + uint8_t* row_u = row_y + row_y_size; + uint8_t* row_v = row_u + row_uv_size; + uint8_t* row_uv = row_v + row_uv_size; + + for (y = 0; y < height; ++y) { + ARGBToUVMatrixRow(src_argb, 0, row_u, row_v, width, argbconstants); + MergeUVRow(row_u, row_v, row_uv, halfwidth); + Convert8To16Row(row_uv, dst_uv, 10, halfwidth * 2); + MultiplyRow_16(dst_uv, dst_uv, 64, halfwidth * 2); + ARGBToYMatrixRow(src_argb, row_y, width, argbconstants); + Convert8To16Row(row_y, dst_y, 10, width); + MultiplyRow_16(dst_y, dst_y, 64, width); + src_argb += src_stride_argb; + dst_y += dst_stride_y; + dst_uv += dst_stride_uv; + } + free_aligned_buffer_64(row); + return 0; +} + +LIBYUV_API +int ARGBToP410(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return ARGBToP410Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, + dst_uv, dst_stride_uv, &kArgbI601Constants, width, + height); +} + +LIBYUV_API +int ARGBToP410Matrix(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height) { + if (!src_argb || !dst_y || !dst_uv || !argbconstants || width <= 0 || + width > (INT_MAX / 2) || height == 0 || height == INT_MIN) { + return -1; + } + int y; + void (*Convert8To16Row)(const uint8_t* src_y, uint16_t* dst_y, int bits, + int width) = Convert8To16Row_C; + void (*MultiplyRow_16)(const uint16_t* src_y, uint16_t* dst_y, int scale, + int width) = MultiplyRow_16_C; + void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, + uint8_t* dst_uv, int width) = MergeUVRow_C; + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; + void (*ARGBToUV444MatrixRow)( + const uint8_t* src_argb, uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = ARGBToUV444MatrixRow_C; +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SME; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif + +#if defined(HAS_ARGBTOUV444MATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_NEON; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_NEON_I8MM; + if (IS_ALIGNED(width, 8)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_NEON_I8MM; + } + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_HVX; + } +#endif +#if defined(HAS_ARGBTOUV444MATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToUV444MatrixRow = ARGBToUV444MatrixRow_WASMSIMD; + } + } +#endif + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } +#if defined(HAS_CONVERT8TO16ROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + Convert8To16Row = Convert8To16Row_Any_SSE2; + if (IS_ALIGNED(width, 16)) { + Convert8To16Row = Convert8To16Row_SSE2; + } + } +#endif +#if defined(HAS_CONVERT8TO16ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Convert8To16Row = Convert8To16Row_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + Convert8To16Row = Convert8To16Row_AVX2; + } + } +#endif +#if defined(HAS_CONVERT8TO16ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Convert8To16Row = Convert8To16Row_AVX512BW; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Convert8To16Row = Convert8To16Row_Any_NEON; + if (IS_ALIGNED(width, 16)) { + Convert8To16Row = Convert8To16Row_NEON; + } + } +#endif +#if defined(HAS_CONVERT8TO16ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Convert8To16Row = Convert8To16Row_SME; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Convert8To16Row = Convert8To16Row_RVV; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Convert8To16Row = Convert8To16Row_HVX; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + Convert8To16Row = Convert8To16Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + Convert8To16Row = Convert8To16Row_WASMSIMD; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MultiplyRow_16 = MultiplyRow_16_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + MultiplyRow_16 = MultiplyRow_16_AVX2; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MultiplyRow_16 = MultiplyRow_16_AVX512BW; + } +#endif +#if defined(HAS_MULTIPLYROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MultiplyRow_16 = MultiplyRow_16_Any_NEON; + if (IS_ALIGNED(width, 16)) { + MultiplyRow_16 = MultiplyRow_16_NEON; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + MultiplyRow_16 = MultiplyRow_16_SME; + } +#endif +#if defined(HAS_MULTIPLYROW_16_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MultiplyRow_16 = MultiplyRow_16_RVV; + } +#endif +#if defined(HAS_MULTIPLYROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MultiplyRow_16 = MultiplyRow_16_HVX; + } +#endif +#if defined(HAS_MULTIPLYROW_16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MultiplyRow_16 = MultiplyRow_16_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + MultiplyRow_16 = MultiplyRow_16_WASMSIMD; + } + } +#endif +#if defined(HAS_MERGEUVROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + MergeUVRow = MergeUVRow_Any_SSE2; + if (IS_ALIGNED(width, 16)) { + MergeUVRow = MergeUVRow_SSE2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeUVRow = MergeUVRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + MergeUVRow = MergeUVRow_AVX2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow = MergeUVRow_AVX512BW; + } +#endif +#if defined(HAS_MERGEUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeUVRow = MergeUVRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + MergeUVRow = MergeUVRow_NEON; + } + } +#endif +#if defined(HAS_MERGEUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + MergeUVRow = MergeUVRow_SVE2; + } +#endif +#if defined(HAS_MERGEUVROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow = MergeUVRow_SME; + } +#endif +#if defined(HAS_MERGEUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MergeUVRow = MergeUVRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + MergeUVRow = MergeUVRow_LSX; + } + } +#endif +#if defined(HAS_MERGEUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MergeUVRow = MergeUVRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + MergeUVRow = MergeUVRow_LASX; + } + } +#endif +#if defined(HAS_MERGEUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeUVRow = MergeUVRow_RVV; + } +#endif +#if defined(HAS_MERGEUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow = MergeUVRow_HVX; + } +#endif +#if defined(HAS_MERGEUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MergeUVRow = MergeUVRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + MergeUVRow = MergeUVRow_WASMSIMD; + } + } +#endif + + size_t row_size = + (static_cast(width) + 31) & ~static_cast(31); + size_t row_uv_merged_size = + (static_cast(width) * 2 + 31) & ~static_cast(31); + if (row_size > SIZE_MAX / 3) { + return -1; + } + size_t rows = row_size * 3; + if (row_uv_merged_size > SIZE_MAX - rows) { + return -1; + } + align_buffer_64(row, rows + row_uv_merged_size); + if (!row) + return 1; + uint8_t* row_y = row; + uint8_t* row_u = row_y + row_size; + uint8_t* row_v = row_u + row_size; + uint8_t* row_uv = row_v + row_size; + + for (y = 0; y < height; ++y) { + ARGBToUV444MatrixRow(src_argb, row_u, row_v, width, argbconstants); + MergeUVRow(row_u, row_v, row_uv, width); + Convert8To16Row(row_uv, dst_uv, 10, width * 2); + MultiplyRow_16(dst_uv, dst_uv, 64, width * 2); + ARGBToYMatrixRow(src_argb, row_y, width, argbconstants); + Convert8To16Row(row_y, dst_y, 10, width); + MultiplyRow_16(dst_y, dst_y, 64, width); + src_argb += src_stride_argb; + dst_y += dst_stride_y; + dst_uv += dst_stride_uv; + } + free_aligned_buffer_64(row); + return 0; +} + +LIBYUV_API +int ABGRToNV12(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return ARGBToNV12Matrix(src_abgr, src_stride_abgr, dst_y, dst_stride_y, + dst_uv, dst_stride_uv, &kAbgrI601Constants, width, + height); +} + +// Same as NV12 but U and V swapped. +LIBYUV_API +int ABGRToNV21(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + int width, + int height) { + return ARGBToNV21Matrix(src_abgr, src_stride_abgr, dst_y, dst_stride_y, + dst_vu, dst_stride_vu, &kAbgrI601Constants, width, + height); +} + +// Convert ARGB to YUY2. +LIBYUV_API +int ARGBToYUY2(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_yuy2, + int dst_stride_yuy2, + int width, + int height) { + return ARGBToYUY2Matrix(src_argb, src_stride_argb, dst_yuy2, dst_stride_yuy2, + &kArgbI601Constants, width, height); +} + +// Convert ARGB to UYVY. +LIBYUV_API +int ARGBToUYVY(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_uyvy, + int dst_stride_uyvy, + int width, + int height) { + return ARGBToUYVYMatrix(src_argb, src_stride_argb, dst_uyvy, dst_stride_uyvy, + &kArgbI601Constants, width, height); +} + // Convert ARGB to I400. LIBYUV_API int ARGBToI400(const uint8_t* src_argb, @@ -1222,72 +3575,11 @@ int ARGBToI400(const uint8_t* src_argb, int dst_stride_y, int width, int height) { - int y; - void (*ARGBToYRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = - ARGBToYRow_C; - if (!src_argb || !dst_y || width <= 0 || height == 0) { - return -1; - } - if (height < 0) { - height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; - src_stride_argb = -src_stride_argb; - } - // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_y == width) { - width *= height; - height = 1; - src_stride_argb = dst_stride_y = 0; - } -#if defined(HAS_ARGBTOYROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToYRow = ARGBToYRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToYRow = ARGBToYRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToYRow = ARGBToYRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToYRow = ARGBToYRow_AVX2; - } - } -#endif -#if defined(HAS_ARGBTOYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYRow = ARGBToYRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYRow = ARGBToYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBToYRow = ARGBToYRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYRow = ARGBToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYRow = ARGBToYRow_MMI; - } - } -#endif - - for (y = 0; y < height; ++y) { - ARGBToYRow(src_argb, dst_y, width); - src_argb += src_stride_argb; - dst_y += dst_stride_y; - } - return 0; + return ARGBToI400Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, + &kArgbI601Constants, width, height); } +#if !defined(__riscv) && !defined(__hexagon__) // Shuffle table for converting ARGB to RGBA. static const uvec8 kShuffleMaskARGBToRGBA = { 3u, 0u, 1u, 2u, 7u, 4u, 5u, 6u, 11u, 8u, 9u, 10u, 15u, 12u, 13u, 14u}; @@ -1303,6 +3595,54 @@ int ARGBToRGBA(const uint8_t* src_argb, return ARGBShuffle(src_argb, src_stride_argb, dst_rgba, dst_stride_rgba, (const uint8_t*)(&kShuffleMaskARGBToRGBA), width, height); } +#else +// Convert ARGB to RGBA. +LIBYUV_API +int ARGBToRGBA(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_rgba, + int dst_stride_rgba, + int width, + int height) { + int y; + void (*ARGBToRGBARow)(const uint8_t* src_argb, uint8_t* dst_rgba, int width) = + ARGBToRGBARow_C; + if (!src_argb || !dst_rgba || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + if (height < 0) { + height = -height; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } + // Coalesce rows. + if (src_stride_argb == width * 4 && dst_stride_rgba == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_argb = dst_stride_rgba = 0; + } + +#if defined(HAS_ARGBTORGBAROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToRGBARow = ARGBToRGBARow_RVV; + } +#endif +#if defined(HAS_ARGBTORGBAROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToRGBARow = ARGBToRGBARow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + ARGBToRGBARow(src_argb, dst_rgba, width); + src_argb += src_stride_argb; + dst_rgba += dst_stride_rgba; + } + return 0; +} +#endif // Convert ARGB To RGB24. LIBYUV_API @@ -1315,16 +3655,18 @@ int ARGBToRGB24(const uint8_t* src_argb, int y; void (*ARGBToRGB24Row)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToRGB24Row_C; - if (!src_argb || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_argb || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_rgb24 == width * 3) { + if (src_stride_argb == width * 4 && dst_stride_rgb24 == width * 3 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_rgb24 = 0; @@ -1345,38 +3687,45 @@ int ARGBToRGB24(const uint8_t* src_argb, } } #endif -#if defined(HAS_ARGBTORGB24ROW_AVX512VBMI) - if (TestCpuFlag(kCpuHasAVX512VBMI)) { - ARGBToRGB24Row = ARGBToRGB24Row_Any_AVX512VBMI; - if (IS_ALIGNED(width, 32)) { - ARGBToRGB24Row = ARGBToRGB24Row_AVX512VBMI; - } +#if defined(HAS_ARGBTORGB24ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToRGB24Row = ARGBToRGB24Row_AVX512BW; } #endif #if defined(HAS_ARGBTORGB24ROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ARGBToRGB24Row = ARGBToRGB24Row_Any_NEON; - if (IS_ALIGNED(width, 8)) { + if (IS_ALIGNED(width, 16)) { ARGBToRGB24Row = ARGBToRGB24Row_NEON; } } #endif -#if defined(HAS_ARGBTORGB24ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToRGB24Row = ARGBToRGB24Row_Any_MSA; +#if defined(HAS_ARGBTORGB24ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToRGB24Row = ARGBToRGB24Row_SVE2; + } +#endif +#if defined(HAS_ARGBTORGB24ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToRGB24Row = ARGBToRGB24Row_Any_LSX; if (IS_ALIGNED(width, 16)) { - ARGBToRGB24Row = ARGBToRGB24Row_MSA; + ARGBToRGB24Row = ARGBToRGB24Row_LSX; } } #endif -#if defined(HAS_ARGBTORGB24ROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToRGB24Row = ARGBToRGB24Row_Any_MMI; - if (IS_ALIGNED(width, 4)) { - ARGBToRGB24Row = ARGBToRGB24Row_MMI; +#if defined(HAS_ARGBTORGB24ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToRGB24Row = ARGBToRGB24Row_Any_LASX; + if (IS_ALIGNED(width, 32)) { + ARGBToRGB24Row = ARGBToRGB24Row_LASX; } } #endif +#if defined(HAS_ARGBTORGB24ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToRGB24Row = ARGBToRGB24Row_RVV; + } +#endif for (y = 0; y < height; ++y) { ARGBToRGB24Row(src_argb, dst_rgb24, width); @@ -1397,16 +3746,17 @@ int ARGBToRAW(const uint8_t* src_argb, int y; void (*ARGBToRAWRow)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToRAWRow_C; - if (!src_argb || !dst_raw || width <= 0 || height == 0) { + if (!src_argb || !dst_raw || width <= 0 || height == 0 || height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_raw == width * 3) { + if (src_stride_argb == width * 4 && dst_stride_raw == width * 3 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_raw = 0; @@ -1427,6 +3777,11 @@ int ARGBToRAW(const uint8_t* src_argb, } } #endif +#if defined(HAS_ARGBTORAWROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToRAWRow = ARGBToRAWRow_AVX512BW; + } +#endif #if defined(HAS_ARGBTORAWROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ARGBToRAWRow = ARGBToRAWRow_Any_NEON; @@ -1435,22 +3790,32 @@ int ARGBToRAW(const uint8_t* src_argb, } } #endif -#if defined(HAS_ARGBTORAWROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToRAWRow = ARGBToRAWRow_Any_MSA; +#if defined(HAS_ARGBTORAWROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToRAWRow = ARGBToRAWRow_SVE2; + } +#endif +#if defined(HAS_ARGBTORAWROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToRAWRow = ARGBToRAWRow_Any_LSX; if (IS_ALIGNED(width, 16)) { - ARGBToRAWRow = ARGBToRAWRow_MSA; + ARGBToRAWRow = ARGBToRAWRow_LSX; } } #endif -#if defined(HAS_ARGBTORAWROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToRAWRow = ARGBToRAWRow_Any_MMI; - if (IS_ALIGNED(width, 4)) { - ARGBToRAWRow = ARGBToRAWRow_MMI; +#if defined(HAS_ARGBTORAWROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToRAWRow = ARGBToRAWRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + ARGBToRAWRow = ARGBToRAWRow_LASX; } } #endif +#if defined(HAS_ARGBTORAWROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToRAWRow = ARGBToRAWRow_RVV; + } +#endif for (y = 0; y < height; ++y) { ARGBToRAWRow(src_argb, dst_raw, width); @@ -1475,28 +3840,24 @@ int ARGBToRGB565Dither(const uint8_t* src_argb, int width, int height) { int y; + uint32_t dither4[4]; void (*ARGBToRGB565DitherRow)(const uint8_t* src_argb, uint8_t* dst_rgb, - const uint32_t dither4, int width) = + uint32_t dither4, int width) = ARGBToRGB565DitherRow_C; - if (!src_argb || !dst_rgb565 || width <= 0 || height == 0) { + if (!src_argb || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } if (!dither4x4) { dither4x4 = kDither565_4x4; } -#if defined(HAS_ARGBTORGB565DITHERROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_SSE2; - if (IS_ALIGNED(width, 4)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_SSE2; - } - } -#endif + memcpy(dither4, dither4x4, 16); + #if defined(HAS_ARGBTORGB565DITHERROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_AVX2; @@ -1505,6 +3866,11 @@ int ARGBToRGB565Dither(const uint8_t* src_argb, } } #endif +#if defined(HAS_ARGBTORGB565DITHERROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_AVX512BW; + } +#endif #if defined(HAS_ARGBTORGB565DITHERROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_NEON; @@ -1513,27 +3879,38 @@ int ARGBToRGB565Dither(const uint8_t* src_argb, } } #endif -#if defined(HAS_ARGBTORGB565DITHERROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_MSA; +#if defined(HAS_ARGBTORGB565DITHERROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_SVE2; + } +#endif +#if defined(HAS_ARGBTORGB565DITHERROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_LSX; } } #endif -#if defined(HAS_ARGBTORGB565DITHERROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_MMI; - if (IS_ALIGNED(width, 4)) { - ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_MMI; +#if defined(HAS_ARGBTORGB565DITHERROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTORGB565DITHERROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + ARGBToRGB565DitherRow = ARGBToRGB565DitherRow_WASMSIMD; } } #endif for (y = 0; y < height; ++y) { - ARGBToRGB565DitherRow(src_argb, dst_rgb565, - *(const uint32_t*)(dither4x4 + ((y & 3) << 2)), - width); + ARGBToRGB565DitherRow(src_argb, dst_rgb565, dither4[y & 3], width); src_argb += src_stride_argb; dst_rgb565 += dst_stride_rgb565; } @@ -1552,28 +3929,23 @@ int ARGBToRGB565(const uint8_t* src_argb, int y; void (*ARGBToRGB565Row)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToRGB565Row_C; - if (!src_argb || !dst_rgb565 || width <= 0 || height == 0) { + if (!src_argb || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_rgb565 == width * 2) { + if (src_stride_argb == width * 4 && dst_stride_rgb565 == width * 2 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_rgb565 = 0; } -#if defined(HAS_ARGBTORGB565ROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ARGBToRGB565Row = ARGBToRGB565Row_Any_SSE2; - if (IS_ALIGNED(width, 4)) { - ARGBToRGB565Row = ARGBToRGB565Row_SSE2; - } - } -#endif + #if defined(HAS_ARGBTORGB565ROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { ARGBToRGB565Row = ARGBToRGB565Row_Any_AVX2; @@ -1582,6 +3954,11 @@ int ARGBToRGB565(const uint8_t* src_argb, } } #endif +#if defined(HAS_ARGBTORGB565ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToRGB565Row = ARGBToRGB565Row_AVX512BW; + } +#endif #if defined(HAS_ARGBTORGB565ROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ARGBToRGB565Row = ARGBToRGB565Row_Any_NEON; @@ -1590,19 +3967,32 @@ int ARGBToRGB565(const uint8_t* src_argb, } } #endif -#if defined(HAS_ARGBTORGB565ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToRGB565Row = ARGBToRGB565Row_Any_MSA; +#if defined(HAS_ARGBTORGB565ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToRGB565Row = ARGBToRGB565Row_SVE2; + } +#endif +#if defined(HAS_ARGBTORGB565ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToRGB565Row = ARGBToRGB565Row_Any_LSX; if (IS_ALIGNED(width, 8)) { - ARGBToRGB565Row = ARGBToRGB565Row_MSA; + ARGBToRGB565Row = ARGBToRGB565Row_LSX; } } #endif -#if defined(HAS_ARGBTORGB565ROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToRGB565Row = ARGBToRGB565Row_Any_MMI; - if (IS_ALIGNED(width, 4)) { - ARGBToRGB565Row = ARGBToRGB565Row_MMI; +#if defined(HAS_ARGBTORGB565ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToRGB565Row = ARGBToRGB565Row_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToRGB565Row = ARGBToRGB565Row_LASX; + } + } +#endif +#if defined(HAS_ARGBTORGB565ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToRGB565Row = ARGBToRGB565Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + ARGBToRGB565Row = ARGBToRGB565Row_WASMSIMD; } } #endif @@ -1626,28 +4016,23 @@ int ARGBToARGB1555(const uint8_t* src_argb, int y; void (*ARGBToARGB1555Row)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToARGB1555Row_C; - if (!src_argb || !dst_argb1555 || width <= 0 || height == 0) { + if (!src_argb || !dst_argb1555 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_argb1555 == width * 2) { + if (src_stride_argb == width * 4 && dst_stride_argb1555 == width * 2 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_argb1555 = 0; } -#if defined(HAS_ARGBTOARGB1555ROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ARGBToARGB1555Row = ARGBToARGB1555Row_Any_SSE2; - if (IS_ALIGNED(width, 4)) { - ARGBToARGB1555Row = ARGBToARGB1555Row_SSE2; - } - } -#endif + #if defined(HAS_ARGBTOARGB1555ROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { ARGBToARGB1555Row = ARGBToARGB1555Row_Any_AVX2; @@ -1664,19 +4049,27 @@ int ARGBToARGB1555(const uint8_t* src_argb, } } #endif -#if defined(HAS_ARGBTOARGB1555ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToARGB1555Row = ARGBToARGB1555Row_Any_MSA; +#if defined(HAS_ARGBTOARGB1555ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToARGB1555Row = ARGBToARGB1555Row_Any_LSX; if (IS_ALIGNED(width, 8)) { - ARGBToARGB1555Row = ARGBToARGB1555Row_MSA; + ARGBToARGB1555Row = ARGBToARGB1555Row_LSX; } } #endif -#if defined(HAS_ARGBTOARGB1555ROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToARGB1555Row = ARGBToARGB1555Row_Any_MMI; - if (IS_ALIGNED(width, 4)) { - ARGBToARGB1555Row = ARGBToARGB1555Row_MMI; +#if defined(HAS_ARGBTOARGB1555ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToARGB1555Row = ARGBToARGB1555Row_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToARGB1555Row = ARGBToARGB1555Row_LASX; + } + } +#endif +#if defined(HAS_ARGBTOARGB1555ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToARGB1555Row = ARGBToARGB1555Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + ARGBToARGB1555Row = ARGBToARGB1555Row_WASMSIMD; } } #endif @@ -1700,28 +4093,23 @@ int ARGBToARGB4444(const uint8_t* src_argb, int y; void (*ARGBToARGB4444Row)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToARGB4444Row_C; - if (!src_argb || !dst_argb4444 || width <= 0 || height == 0) { + if (!src_argb || !dst_argb4444 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_argb4444 == width * 2) { + if (src_stride_argb == width * 4 && dst_stride_argb4444 == width * 2 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_argb4444 = 0; } -#if defined(HAS_ARGBTOARGB4444ROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ARGBToARGB4444Row = ARGBToARGB4444Row_Any_SSE2; - if (IS_ALIGNED(width, 4)) { - ARGBToARGB4444Row = ARGBToARGB4444Row_SSE2; - } - } -#endif + #if defined(HAS_ARGBTOARGB4444ROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { ARGBToARGB4444Row = ARGBToARGB4444Row_Any_AVX2; @@ -1738,19 +4126,27 @@ int ARGBToARGB4444(const uint8_t* src_argb, } } #endif -#if defined(HAS_ARGBTOARGB4444ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToARGB4444Row = ARGBToARGB4444Row_Any_MSA; +#if defined(HAS_ARGBTOARGB4444ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToARGB4444Row = ARGBToARGB4444Row_Any_LSX; if (IS_ALIGNED(width, 8)) { - ARGBToARGB4444Row = ARGBToARGB4444Row_MSA; + ARGBToARGB4444Row = ARGBToARGB4444Row_LSX; } } #endif -#if defined(HAS_ARGBTOARGB4444ROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToARGB4444Row = ARGBToARGB4444Row_Any_MMI; - if (IS_ALIGNED(width, 4)) { - ARGBToARGB4444Row = ARGBToARGB4444Row_MMI; +#if defined(HAS_ARGBTOARGB4444ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToARGB4444Row = ARGBToARGB4444Row_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToARGB4444Row = ARGBToARGB4444Row_LASX; + } + } +#endif +#if defined(HAS_ARGBTOARGB4444ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToARGB4444Row = ARGBToARGB4444Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + ARGBToARGB4444Row = ARGBToARGB4444Row_WASMSIMD; } } #endif @@ -1774,20 +4170,30 @@ int ABGRToAR30(const uint8_t* src_abgr, int y; void (*ABGRToAR30Row)(const uint8_t* src_abgr, uint8_t* dst_rgb, int width) = ABGRToAR30Row_C; - if (!src_abgr || !dst_ar30 || width <= 0 || height == 0) { + if (!src_abgr || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_abgr = src_abgr + (height - 1) * src_stride_abgr; + src_abgr = src_abgr + (ptrdiff_t)(height - 1) * src_stride_abgr; src_stride_abgr = -src_stride_abgr; } // Coalesce rows. - if (src_stride_abgr == width * 4 && dst_stride_ar30 == width * 4) { + if (src_stride_abgr == width * 4 && dst_stride_ar30 == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_abgr = dst_stride_ar30 = 0; } +#if defined(HAS_ABGRTOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ABGRToAR30Row = ABGRToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ABGRToAR30Row = ABGRToAR30Row_NEON; + } + } +#endif #if defined(HAS_ABGRTOAR30ROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { ABGRToAR30Row = ABGRToAR30Row_Any_SSSE3; @@ -1803,6 +4209,11 @@ int ABGRToAR30(const uint8_t* src_abgr, ABGRToAR30Row = ABGRToAR30Row_AVX2; } } +#endif +#if defined(HAS_ABGRTOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ABGRToAR30Row = ABGRToAR30Row_AVX512BW; + } #endif for (y = 0; y < height; ++y) { ABGRToAR30Row(src_abgr, dst_ar30, width); @@ -1823,20 +4234,30 @@ int ARGBToAR30(const uint8_t* src_argb, int y; void (*ARGBToAR30Row)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToAR30Row_C; - if (!src_argb || !dst_ar30 || width <= 0 || height == 0) { + if (!src_argb || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_ar30 == width * 4) { + if (src_stride_argb == width * 4 && dst_stride_ar30 == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_ar30 = 0; } +#if defined(HAS_ARGBTOAR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToAR30Row = ARGBToAR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBToAR30Row = ARGBToAR30Row_NEON; + } + } +#endif #if defined(HAS_ARGBTOAR30ROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { ARGBToAR30Row = ARGBToAR30Row_Any_SSSE3; @@ -1852,6 +4273,11 @@ int ARGBToAR30(const uint8_t* src_argb, ARGBToAR30Row = ARGBToAR30Row_AVX2; } } +#endif +#if defined(HAS_ARGBTOAR30ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToAR30Row = ARGBToAR30Row_AVX512BW; + } #endif for (y = 0; y < height; ++y) { ARGBToAR30Row(src_argb, dst_ar30, width); @@ -1861,302 +4287,569 @@ int ARGBToAR30(const uint8_t* src_argb, return 0; } -// Convert ARGB to J420. (JPeg full range I420). +// ARGB little endian (bgra in memory) to J444 LIBYUV_API -int ARGBToJ420(const uint8_t* src_argb, +int ARGBToJ444(const uint8_t* src_argb, int src_stride_argb, - uint8_t* dst_yj, - int dst_stride_yj, + uint8_t* dst_y, + int dst_stride_y, uint8_t* dst_u, int dst_stride_u, uint8_t* dst_v, int dst_stride_v, int width, int height) { - int y; - void (*ARGBToUVJRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVJRow_C; - void (*ARGBToYJRow)(const uint8_t* src_argb, uint8_t* dst_yj, int width) = - ARGBToYJRow_C; - if (!src_argb || !dst_yj || !dst_u || !dst_v || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; - src_stride_argb = -src_stride_argb; - } -#if defined(HAS_ARGBTOYJROW_SSSE3) && defined(HAS_ARGBTOUVJROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVJRow = ARGBToUVJRow_Any_SSSE3; - ARGBToYJRow = ARGBToYJRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVJRow = ARGBToUVJRow_SSSE3; - ARGBToYJRow = ARGBToYJRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToYJRow = ARGBToYJRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToYJRow = ARGBToYJRow_AVX2; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYJRow = ARGBToYJRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToYJRow = ARGBToYJRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOUVJROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToUVJRow = ARGBToUVJRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { - ARGBToUVJRow = ARGBToUVJRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYJRow = ARGBToYJRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBToYJRow = ARGBToYJRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYJRow = ARGBToYJRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYJRow = ARGBToYJRow_MMI; - } - } -#endif -#if defined(HAS_ARGBTOUVJROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToUVJRow = ARGBToUVJRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - ARGBToUVJRow = ARGBToUVJRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOUVJROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToUVJRow = ARGBToUVJRow_Any_MMI; - if (IS_ALIGNED(width, 16)) { - ARGBToUVJRow = ARGBToUVJRow_MMI; - } - } -#endif + return ARGBToI444Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kArgbJPEGConstants, width, height); +} - for (y = 0; y < height - 1; y += 2) { - ARGBToUVJRow(src_argb, src_stride_argb, dst_u, dst_v, width); - ARGBToYJRow(src_argb, dst_yj, width); - ARGBToYJRow(src_argb + src_stride_argb, dst_yj + dst_stride_yj, width); - src_argb += src_stride_argb * 2; - dst_yj += dst_stride_yj * 2; - dst_u += dst_stride_u; - dst_v += dst_stride_v; - } - if (height & 1) { - ARGBToUVJRow(src_argb, 0, dst_u, dst_v, width); - ARGBToYJRow(src_argb, dst_yj, width); - } - return 0; +// Convert ARGB to J420. (JPeg full range I420). +LIBYUV_API +int ARGBToJ420(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return ARGBToI420Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kArgbJPEGConstants, width, height); } // Convert ARGB to J422. (JPeg full range I422). LIBYUV_API int ARGBToJ422(const uint8_t* src_argb, int src_stride_argb, - uint8_t* dst_yj, - int dst_stride_yj, + uint8_t* dst_y, + int dst_stride_y, uint8_t* dst_u, int dst_stride_u, uint8_t* dst_v, int dst_stride_v, int width, int height) { - int y; - void (*ARGBToUVJRow)(const uint8_t* src_argb0, int src_stride_argb, - uint8_t* dst_u, uint8_t* dst_v, int width) = - ARGBToUVJRow_C; - void (*ARGBToYJRow)(const uint8_t* src_argb, uint8_t* dst_yj, int width) = - ARGBToYJRow_C; - if (!src_argb || !dst_yj || !dst_u || !dst_v || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; - src_stride_argb = -src_stride_argb; - } - // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_yj == width && - dst_stride_u * 2 == width && dst_stride_v * 2 == width) { - width *= height; - height = 1; - src_stride_argb = dst_stride_yj = dst_stride_u = dst_stride_v = 0; - } -#if defined(HAS_ARGBTOYJROW_SSSE3) && defined(HAS_ARGBTOUVJROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToUVJRow = ARGBToUVJRow_Any_SSSE3; - ARGBToYJRow = ARGBToYJRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToUVJRow = ARGBToUVJRow_SSSE3; - ARGBToYJRow = ARGBToYJRow_SSSE3; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToYJRow = ARGBToYJRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToYJRow = ARGBToYJRow_AVX2; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYJRow = ARGBToYJRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToYJRow = ARGBToYJRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOUVJROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBToUVJRow = ARGBToUVJRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { - ARGBToUVJRow = ARGBToUVJRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYJRow = ARGBToYJRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBToYJRow = ARGBToYJRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYJRow = ARGBToYJRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYJRow = ARGBToYJRow_MMI; - } - } -#endif -#if defined(HAS_ARGBTOUVJROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToUVJRow = ARGBToUVJRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - ARGBToUVJRow = ARGBToUVJRow_MSA; - } - } -#endif -#if defined(HAS_ARGBTOUVJROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToUVJRow = ARGBToUVJRow_Any_MMI; - if (IS_ALIGNED(width, 16)) { - ARGBToUVJRow = ARGBToUVJRow_MMI; - } - } -#endif - - for (y = 0; y < height; ++y) { - ARGBToUVJRow(src_argb, 0, dst_u, dst_v, width); - ARGBToYJRow(src_argb, dst_yj, width); - src_argb += src_stride_argb; - dst_yj += dst_stride_yj; - dst_u += dst_stride_u; - dst_v += dst_stride_v; - } - return 0; + return ARGBToI422Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kArgbJPEGConstants, width, height); } // Convert ARGB to J400. LIBYUV_API int ARGBToJ400(const uint8_t* src_argb, int src_stride_argb, + uint8_t* dst_y, + int dst_stride_y, + int width, + int height) { + return ARGBToI400Matrix(src_argb, src_stride_argb, dst_y, dst_stride_y, + &kArgbJPEGConstants, width, height); +} + +// Convert RGBA to J400. +LIBYUV_API +int RGBAToJ400(const uint8_t* src_rgba, + int src_stride_rgba, uint8_t* dst_yj, int dst_stride_yj, int width, int height) { + return ARGBToI400Matrix(src_rgba, src_stride_rgba, dst_yj, dst_stride_yj, + &kRgbaJPEGConstants, width, height); +} + +// Convert ABGR to J420. (JPeg full range I420). +LIBYUV_API +int ABGRToJ420(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return ARGBToI420Matrix(src_abgr, src_stride_abgr, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kAbgrJPEGConstants, width, height); +} + +// Convert ABGR to J422. (JPeg full range I422). +LIBYUV_API +int ABGRToJ422(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + return ARGBToI422Matrix(src_abgr, src_stride_abgr, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, + &kAbgrJPEGConstants, width, height); +} + +// Convert ABGR to J400. +LIBYUV_API +int ABGRToJ400(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_yj, + int dst_stride_yj, + int width, + int height) { + return ARGBToI400Matrix(src_abgr, src_stride_abgr, dst_yj, dst_stride_yj, + &kAbgrJPEGConstants, width, height); +} + +// Convert ARGB to AR64. +LIBYUV_API +int ARGBToAR64(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_ar64, + int dst_stride_ar64, + int width, + int height) { int y; - void (*ARGBToYJRow)(const uint8_t* src_argb, uint8_t* dst_yj, int width) = - ARGBToYJRow_C; - if (!src_argb || !dst_yj || width <= 0 || height == 0) { + void (*ARGBToAR64Row)(const uint8_t* src_argb, uint16_t* dst_ar64, + int width) = ARGBToAR64Row_C; + if (!src_argb || !dst_ar64 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } + // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_yj == width) { + if (src_stride_argb == width * 4 && dst_stride_ar64 == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; - src_stride_argb = dst_stride_yj = 0; + src_stride_argb = dst_stride_ar64 = 0; } -#if defined(HAS_ARGBTOYJROW_SSSE3) +#if defined(HAS_ARGBTOAR64ROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToYJRow = ARGBToYJRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - ARGBToYJRow = ARGBToYJRow_SSSE3; + ARGBToAR64Row = ARGBToAR64Row_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBToAR64Row = ARGBToAR64Row_SSSE3; } } #endif -#if defined(HAS_ARGBTOYJROW_AVX2) +#if defined(HAS_ARGBTOAR64ROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToYJRow = ARGBToYJRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - ARGBToYJRow = ARGBToYJRow_AVX2; + ARGBToAR64Row = ARGBToAR64Row_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBToAR64Row = ARGBToAR64Row_AVX2; } } #endif -#if defined(HAS_ARGBTOYJROW_NEON) +#if defined(HAS_ARGBTOAR64ROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYJRow = ARGBToYJRow_Any_NEON; + ARGBToAR64Row = ARGBToAR64Row_Any_NEON; if (IS_ALIGNED(width, 8)) { - ARGBToYJRow = ARGBToYJRow_NEON; + ARGBToAR64Row = ARGBToAR64Row_NEON; } } #endif -#if defined(HAS_ARGBTOYJROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYJRow = ARGBToYJRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBToYJRow = ARGBToYJRow_MSA; - } +#if defined(HAS_ARGBTOAR64ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToAR64Row = ARGBToAR64Row_RVV; } #endif -#if defined(HAS_ARGBTOYJROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYJRow = ARGBToYJRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYJRow = ARGBToYJRow_MMI; - } +#if defined(HAS_ARGBTOAR64ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToAR64Row = ARGBToAR64Row_HVX; } #endif for (y = 0; y < height; ++y) { - ARGBToYJRow(src_argb, dst_yj, width); + ARGBToAR64Row(src_argb, dst_ar64, width); src_argb += src_stride_argb; - dst_yj += dst_stride_yj; + dst_ar64 += dst_stride_ar64; } return 0; } +// Convert ARGB to AB64. +LIBYUV_API +int ARGBToAB64(const uint8_t* src_argb, + int src_stride_argb, + uint16_t* dst_ab64, + int dst_stride_ab64, + int width, + int height) { + int y; + void (*ARGBToAB64Row)(const uint8_t* src_argb, uint16_t* dst_ar64, + int width) = ARGBToAB64Row_C; + if (!src_argb || !dst_ab64 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; + } + // Coalesce rows. + if (src_stride_argb == width * 4 && dst_stride_ab64 == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_argb = dst_stride_ab64 = 0; + } +#if defined(HAS_ARGBTOAB64ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBToAB64Row = ARGBToAB64Row_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBToAB64Row = ARGBToAB64Row_SSSE3; + } + } +#endif +#if defined(HAS_ARGBTOAB64ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBToAB64Row = ARGBToAB64Row_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBToAB64Row = ARGBToAB64Row_AVX2; + } + } +#endif +#if defined(HAS_ARGBTOAB64ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBToAB64Row = ARGBToAB64Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBToAB64Row = ARGBToAB64Row_NEON; + } + } +#endif +#if defined(HAS_ARGBTOAB64ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToAB64Row = ARGBToAB64Row_RVV; + } +#endif +#if defined(HAS_ARGBTOAB64ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToAB64Row = ARGBToAB64Row_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + ARGBToAB64Row(src_argb, dst_ab64, width); + src_argb += src_stride_argb; + dst_ab64 += dst_stride_ab64; + } + return 0; +} + +// Convert RAW to NV21 with Matrix. +static int RAWToNVMatrix(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + const struct ArgbConstants* argbconstants, + int width, + int height, + int is_nv21) { + int y; + int halfwidth = (width + 1) >> 1; + void (*RGBToUVMatrixRow)(const uint8_t* src_rgb, int src_stride_rgb, + uint8_t* dst_u, uint8_t* dst_v, int width, + const struct ArgbConstants* c) = RGBToUVMatrixRow_C; + void (*RGBToYMatrixRow)(const uint8_t* src_rgb, uint8_t* dst_y, int width, + const struct ArgbConstants* c) = RGBToYMatrixRow_C; + void (*MergeUVRow)(const uint8_t* src_uj, const uint8_t* src_vj, + uint8_t* dst_vu, int width) = MergeUVRow_C; + + if (!src_raw || !dst_y || !dst_uv || !argbconstants || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; + src_stride_raw = -src_stride_raw; + } + +#if defined(HAS_RGBTOYMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToYMatrixRow = RGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_NEON_DotProd; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + RGBToYMatrixRow = RGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RGBToYMatrixRow = RGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_RGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToYMatrixRow = RGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToYMatrixRow = RGBToYMatrixRow_WASMSIMD; + } + } +#endif + +#if defined(HAS_RGBTOUVMATRIXROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_SSSE3; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_AVX2; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_NEON; + } + } +#endif +#if defined(HAS_RGBTOUVMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGBToUVMatrixRow = RGBToUVMatrixRow_WASMSIMD; + } + } +#endif + +#if defined(HAS_MERGEUVROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + MergeUVRow = MergeUVRow_Any_SSE2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_SSE2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeUVRow = MergeUVRow_Any_AVX2; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_AVX2; + } + } +#endif +#if defined(HAS_MERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow = MergeUVRow_AVX512BW; + } +#endif +#if defined(HAS_MERGEUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeUVRow = MergeUVRow_Any_NEON; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_NEON; + } + } +#endif +#if defined(HAS_MERGEUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + MergeUVRow = MergeUVRow_SVE2; + } +#endif +#if defined(HAS_MERGEUVROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow = MergeUVRow_SME; + } +#endif +#if defined(HAS_MERGEUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MergeUVRow = MergeUVRow_Any_LSX; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_LSX; + } + } +#endif +#if defined(HAS_MERGEUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MergeUVRow = MergeUVRow_Any_LASX; + if (IS_ALIGNED(halfwidth, 32)) { + MergeUVRow = MergeUVRow_LASX; + } + } +#endif +#if defined(HAS_MERGEUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeUVRow = MergeUVRow_RVV; + } +#endif +#if defined(HAS_MERGEUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow = MergeUVRow_HVX; + } +#endif +#if defined(HAS_MERGEUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MergeUVRow = MergeUVRow_Any_WASMSIMD; + if (IS_ALIGNED(halfwidth, 16)) { + MergeUVRow = MergeUVRow_WASMSIMD; + } + } +#endif + + { + // Allocate 1 row of U and 1 row of V. + align_buffer_64(row_u, halfwidth); + align_buffer_64(row_v, halfwidth); + + if (!row_u || !row_v) { + free_aligned_buffer_64(row_u); + free_aligned_buffer_64(row_v); + return 1; + } + + const uint8_t* first_chroma = is_nv21 ? row_v : row_u; + const uint8_t* second_chroma = is_nv21 ? row_u : row_v; + + for (y = 0; y < height - 1; y += 2) { + RGBToUVMatrixRow(src_raw, src_stride_raw, row_u, row_v, width, + argbconstants); + MergeUVRow(first_chroma, second_chroma, dst_uv, halfwidth); + RGBToYMatrixRow(src_raw, dst_y, width, argbconstants); + RGBToYMatrixRow(src_raw + src_stride_raw, dst_y + dst_stride_y, width, + argbconstants); + src_raw += src_stride_raw * 2; + dst_y += dst_stride_y * 2; + dst_uv += dst_stride_uv; + } + if (height & 1) { + RGBToUVMatrixRow(src_raw, 0, row_u, row_v, width, argbconstants); + MergeUVRow(first_chroma, second_chroma, dst_uv, halfwidth); + RGBToYMatrixRow(src_raw, dst_y, width, argbconstants); + } + free_aligned_buffer_64(row_v); + free_aligned_buffer_64(row_u); + } + return 0; +} + +LIBYUV_API +int RAWToNV21Matrix(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + const struct ArgbConstants* argbconstants, + int width, + int height) { + return RAWToNVMatrix(src_raw, src_stride_raw, dst_y, dst_stride_y, dst_vu, + dst_stride_vu, argbconstants, width, height, 1); +} + +LIBYUV_API +int RAWToJNV21(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + int width, + int height) { + return RAWToNV21Matrix(src_raw, src_stride_raw, dst_y, dst_stride_y, dst_vu, + dst_stride_vu, &kAbgrJPEGConstants, width, height); +} + +LIBYUV_API +int RAWToNV21(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + int width, + int height) { + return RAWToNV21Matrix(src_raw, src_stride_raw, dst_y, dst_stride_y, dst_vu, + dst_stride_vu, &kAbgrI601Constants, width, height); +} + +LIBYUV_API +int RGB24ToNV12(const uint8_t* src_rgb24, + int src_stride_rgb24, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + return RAWToNVMatrix(src_rgb24, src_stride_rgb24, dst_y, dst_stride_y, dst_uv, + dst_stride_uv, &kArgbI601Constants, width, height, 0); +} + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/source/convert_jpeg.cc b/libs/libyuv/source/convert_jpeg.cc index f440c7c2e9..d9ce28a923 100644 --- a/libs/libyuv/source/convert_jpeg.cc +++ b/libs/libyuv/source/convert_jpeg.cc @@ -94,7 +94,7 @@ int MJPGSize(const uint8_t* src_mjpg, int* width, int* height) { MJpegDecoder mjpeg_decoder; - LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg); + bool ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg); if (ret) { *width = mjpeg_decoder.GetWidth(); *height = mjpeg_decoder.GetHeight(); @@ -126,7 +126,7 @@ int MJPGToI420(const uint8_t* src_mjpg, // TODO(fbarchard): Port MJpeg to C. MJpegDecoder mjpeg_decoder; - LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg); + bool ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg); if (ret && (mjpeg_decoder.GetWidth() != src_width || mjpeg_decoder.GetHeight() != src_height)) { // ERROR: MJPEG frame has unexpected dimensions @@ -266,7 +266,7 @@ int MJPGToNV21(const uint8_t* src_mjpg, // TODO(fbarchard): Port MJpeg to C. MJpegDecoder mjpeg_decoder; - LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg); + bool ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg); if (ret && (mjpeg_decoder.GetWidth() != src_width || mjpeg_decoder.GetHeight() != src_height)) { // ERROR: MJPEG frame has unexpected dimensions @@ -328,6 +328,140 @@ int MJPGToNV21(const uint8_t* src_mjpg, return ret ? 0 : 1; } +static void JpegI420ToNV12(void* opaque, + const uint8_t* const* data, + const int* strides, + int rows) { + NV21Buffers* dest = (NV21Buffers*)(opaque); + // Use NV21 with VU swapped. + I420ToNV21(data[0], strides[0], data[2], strides[2], data[1], strides[1], + dest->y, dest->y_stride, dest->vu, dest->vu_stride, dest->w, rows); + dest->y += rows * dest->y_stride; + dest->vu += ((rows + 1) >> 1) * dest->vu_stride; + dest->h -= rows; +} + +static void JpegI422ToNV12(void* opaque, + const uint8_t* const* data, + const int* strides, + int rows) { + NV21Buffers* dest = (NV21Buffers*)(opaque); + // Use NV21 with VU swapped. + I422ToNV21(data[0], strides[0], data[2], strides[2], data[1], strides[1], + dest->y, dest->y_stride, dest->vu, dest->vu_stride, dest->w, rows); + dest->y += rows * dest->y_stride; + dest->vu += ((rows + 1) >> 1) * dest->vu_stride; + dest->h -= rows; +} + +static void JpegI444ToNV12(void* opaque, + const uint8_t* const* data, + const int* strides, + int rows) { + NV21Buffers* dest = (NV21Buffers*)(opaque); + // Use NV21 with VU swapped. + I444ToNV21(data[0], strides[0], data[2], strides[2], data[1], strides[1], + dest->y, dest->y_stride, dest->vu, dest->vu_stride, dest->w, rows); + dest->y += rows * dest->y_stride; + dest->vu += ((rows + 1) >> 1) * dest->vu_stride; + dest->h -= rows; +} + +static void JpegI400ToNV12(void* opaque, + const uint8_t* const* data, + const int* strides, + int rows) { + NV21Buffers* dest = (NV21Buffers*)(opaque); + // Use NV21 since there is no UV plane. + I400ToNV21(data[0], strides[0], dest->y, dest->y_stride, dest->vu, + dest->vu_stride, dest->w, rows); + dest->y += rows * dest->y_stride; + dest->vu += ((rows + 1) >> 1) * dest->vu_stride; + dest->h -= rows; +} + +// MJPG (Motion JPEG) to NV12. +LIBYUV_API +int MJPGToNV12(const uint8_t* sample, + size_t sample_size, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int src_width, + int src_height, + int dst_width, + int dst_height) { + if (sample_size == kUnknownDataSize) { + // ERROR: MJPEG frame size unknown + return -1; + } + + // TODO(fbarchard): Port MJpeg to C. + MJpegDecoder mjpeg_decoder; + bool ret = mjpeg_decoder.LoadFrame(sample, sample_size); + if (ret && (mjpeg_decoder.GetWidth() != src_width || + mjpeg_decoder.GetHeight() != src_height)) { + // ERROR: MJPEG frame has unexpected dimensions + mjpeg_decoder.UnloadFrame(); + return 1; // runtime failure + } + if (ret) { + // Use NV21Buffers but with UV instead of VU. + NV21Buffers bufs = {dst_y, dst_stride_y, dst_uv, + dst_stride_uv, dst_width, dst_height}; + // YUV420 + if (mjpeg_decoder.GetColorSpace() == MJpegDecoder::kColorSpaceYCbCr && + mjpeg_decoder.GetNumComponents() == 3 && + mjpeg_decoder.GetVertSampFactor(0) == 2 && + mjpeg_decoder.GetHorizSampFactor(0) == 2 && + mjpeg_decoder.GetVertSampFactor(1) == 1 && + mjpeg_decoder.GetHorizSampFactor(1) == 1 && + mjpeg_decoder.GetVertSampFactor(2) == 1 && + mjpeg_decoder.GetHorizSampFactor(2) == 1) { + ret = mjpeg_decoder.DecodeToCallback(&JpegI420ToNV12, &bufs, dst_width, + dst_height); + // YUV422 + } else if (mjpeg_decoder.GetColorSpace() == + MJpegDecoder::kColorSpaceYCbCr && + mjpeg_decoder.GetNumComponents() == 3 && + mjpeg_decoder.GetVertSampFactor(0) == 1 && + mjpeg_decoder.GetHorizSampFactor(0) == 2 && + mjpeg_decoder.GetVertSampFactor(1) == 1 && + mjpeg_decoder.GetHorizSampFactor(1) == 1 && + mjpeg_decoder.GetVertSampFactor(2) == 1 && + mjpeg_decoder.GetHorizSampFactor(2) == 1) { + ret = mjpeg_decoder.DecodeToCallback(&JpegI422ToNV12, &bufs, dst_width, + dst_height); + // YUV444 + } else if (mjpeg_decoder.GetColorSpace() == + MJpegDecoder::kColorSpaceYCbCr && + mjpeg_decoder.GetNumComponents() == 3 && + mjpeg_decoder.GetVertSampFactor(0) == 1 && + mjpeg_decoder.GetHorizSampFactor(0) == 1 && + mjpeg_decoder.GetVertSampFactor(1) == 1 && + mjpeg_decoder.GetHorizSampFactor(1) == 1 && + mjpeg_decoder.GetVertSampFactor(2) == 1 && + mjpeg_decoder.GetHorizSampFactor(2) == 1) { + ret = mjpeg_decoder.DecodeToCallback(&JpegI444ToNV12, &bufs, dst_width, + dst_height); + // YUV400 + } else if (mjpeg_decoder.GetColorSpace() == + MJpegDecoder::kColorSpaceGrayscale && + mjpeg_decoder.GetNumComponents() == 1 && + mjpeg_decoder.GetVertSampFactor(0) == 1 && + mjpeg_decoder.GetHorizSampFactor(0) == 1) { + ret = mjpeg_decoder.DecodeToCallback(&JpegI400ToNV12, &bufs, dst_width, + dst_height); + } else { + // Unknown colorspace. + mjpeg_decoder.UnloadFrame(); + return 1; + } + } + return ret ? 0 : 1; +} + struct ARGBBuffers { uint8_t* argb; int argb_stride; @@ -397,7 +531,7 @@ int MJPGToARGB(const uint8_t* src_mjpg, // TODO(fbarchard): Port MJpeg to C. MJpegDecoder mjpeg_decoder; - LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg); + bool ret = mjpeg_decoder.LoadFrame(src_mjpg, src_size_mjpg); if (ret && (mjpeg_decoder.GetWidth() != src_width || mjpeg_decoder.GetHeight() != src_height)) { // ERROR: MJPEG frame has unexpected dimensions diff --git a/libs/libyuv/source/convert_to_argb.cc b/libs/libyuv/source/convert_to_argb.cc index bde1aa8891..17842d285a 100644 --- a/libs/libyuv/source/convert_to_argb.cc +++ b/libs/libyuv/source/convert_to_argb.cc @@ -10,6 +10,11 @@ #include "libyuv/convert_argb.h" +#include +#include +#include +#include + #include "libyuv/cpu_id.h" #ifdef HAVE_JPEG #include "libyuv/mjpeg_decoder.h" @@ -23,6 +28,280 @@ namespace libyuv { extern "C" { #endif +static int NV16ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + int y; + void (*NV12ToARGBRow)( + const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = NV12ToARGBRow_C; + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_NV12TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + NV12ToARGBRow = NV12ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + NV12ToARGBRow = NV12ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_NV12TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + NV12ToARGBRow = NV12ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + NV12ToARGBRow = NV12ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_NV12TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + NV12ToARGBRow = NV12ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_NV12TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + NV12ToARGBRow = NV12ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + NV12ToARGBRow = NV12ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_NV12TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + NV12ToARGBRow = NV12ToARGBRow_SVE2; + } +#endif +#if defined(HAS_NV12TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + NV12ToARGBRow = NV12ToARGBRow_SME; + } +#endif +#if defined(HAS_NV12TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + NV12ToARGBRow = NV12ToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + NV12ToARGBRow = NV12ToARGBRow_LSX; + } + } +#endif +#if defined(HAS_NV12TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + NV12ToARGBRow = NV12ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + NV12ToARGBRow = NV12ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_NV12TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + NV12ToARGBRow = NV12ToARGBRow_RVV; + } +#endif +#if defined(HAS_NV12TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + NV12ToARGBRow = NV12ToARGBRow_HVX; + } +#endif +#if defined(HAS_NV12TOARGBROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + NV12ToARGBRow = NV12ToARGBRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + NV12ToARGBRow = NV12ToARGBRow_WASMSIMD; + } + } +#endif + + for (y = 0; y < height; ++y) { + NV12ToARGBRow(src_y, src_uv, dst_argb, &kYuvI601Constants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_uv += src_stride_uv; + } + return 0; +} + +static int NV24ToARGB(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + int y; + void (*I444ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, + const uint8_t* v_buf, uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I444ToARGBRow_C; + void (*SplitUVRow)(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, + int width) = SplitUVRow_C; + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } +#if defined(HAS_I444TOARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I444ToARGBRow = I444ToARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_I444TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I444ToARGBRow = I444ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I444ToARGBRow = I444ToARGBRow_AVX2; + } + } +#endif +#if defined(HAS_I444TOARGBROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + I444ToARGBRow = I444ToARGBRow_AVX512BW; + } +#endif +#if defined(HAS_I444TOARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I444ToARGBRow = I444ToARGBRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_NEON; + } + } +#endif +#if defined(HAS_I444TOARGBROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + I444ToARGBRow = I444ToARGBRow_SVE2; + } +#endif +#if defined(HAS_I444TOARGBROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + I444ToARGBRow = I444ToARGBRow_SME; + } +#endif +#if defined(HAS_I444TOARGBROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + I444ToARGBRow = I444ToARGBRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + I444ToARGBRow = I444ToARGBRow_LSX; + } + } +#endif +#if defined(HAS_I444TOARGBROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + I444ToARGBRow = I444ToARGBRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + I444ToARGBRow = I444ToARGBRow_LASX; + } + } +#endif +#if defined(HAS_I444TOARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + I444ToARGBRow = I444ToARGBRow_RVV; + } +#endif +#if defined(HAS_I444TOARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + I444ToARGBRow = I444ToARGBRow_HVX; + } +#endif + +#if defined(HAS_SPLITUVROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + SplitUVRow = SplitUVRow_Any_SSE2; + if (IS_ALIGNED(width, 16)) { + SplitUVRow = SplitUVRow_SSE2; + } + } +#endif +#if defined(HAS_SPLITUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SplitUVRow = SplitUVRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + SplitUVRow = SplitUVRow_AVX2; + } + } +#endif +#if defined(HAS_SPLITUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + SplitUVRow = SplitUVRow_AVX512BW; + } +#endif +#if defined(HAS_SPLITUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + SplitUVRow = SplitUVRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + SplitUVRow = SplitUVRow_NEON; + } + } +#endif +#if defined(HAS_SPLITUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + SplitUVRow = SplitUVRow_SVE2; + } +#endif +#if defined(HAS_SPLITUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + SplitUVRow = SplitUVRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + SplitUVRow = SplitUVRow_LSX; + } + } +#endif +#if defined(HAS_SPLITUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + SplitUVRow = SplitUVRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + SplitUVRow = SplitUVRow_LASX; + } + } +#endif +#if defined(HAS_SPLITUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SplitUVRow = SplitUVRow_RVV; + } +#endif +#if defined(HAS_SPLITUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SplitUVRow = SplitUVRow_HVX; + } +#endif + + align_buffer_64(row_u, width); + align_buffer_64(row_v, width); + if (!row_u || !row_v) { + free_aligned_buffer_64(row_u); + free_aligned_buffer_64(row_v); + return 1; + } + for (y = 0; y < height; ++y) { + SplitUVRow(src_uv, row_u, row_v, width); + I444ToARGBRow(src_y, row_u, row_v, dst_argb, &kYuvI601Constants, width); + dst_argb += dst_stride_argb; + src_y += src_stride_y; + src_uv += src_stride_uv; + } + free_aligned_buffer_64(row_u); + free_aligned_buffer_64(row_v); + return 0; +} + // Convert camera sample to ARGB with cropping, rotation and vertical flip. // src_width is used for source stride computation // src_height is used to compute location of planes, and indicate inversion @@ -32,9 +311,6 @@ extern "C" { // TODO(fbarchard): Add the following: // H010ToARGB // I010ToARGB -// J400ToARGB -// J422ToARGB -// J444ToARGB LIBYUV_API int ConvertToARGB(const uint8_t* sample, @@ -49,12 +325,26 @@ int ConvertToARGB(const uint8_t* sample, int crop_height, enum RotationMode rotation, uint32_t fourcc) { + if (src_height == INT_MIN || crop_height == INT_MIN) { + return -1; + } + + int abs_src_height = (src_height < 0) ? -src_height : src_height; + int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height; + + if (dst_argb == NULL || sample == NULL || src_width <= 0 || + src_width > INT_MAX / 4 || crop_width <= 0 || crop_width > INT_MAX / 4 || + src_height == 0 || crop_height == 0 || crop_x < 0 || crop_y < 0 || + crop_width > src_width || crop_x > src_width - crop_width || + abs_crop_height > abs_src_height || + crop_y > abs_src_height - abs_crop_height) { + return -1; + } + uint32_t format = CanonicalFourCC(fourcc); int aligned_src_width = (src_width + 1) & ~1; const uint8_t* src; const uint8_t* src_uv; - int abs_src_height = (src_height < 0) ? -src_height : src_height; - int inv_crop_height = (crop_height < 0) ? -crop_height : crop_height; int r = 0; // One pass rotation is available for some formats. For the rest, convert @@ -62,24 +352,25 @@ int ConvertToARGB(const uint8_t* sample, // and then rotate the ARGB to the final destination buffer. // For in-place conversion, if destination dst_argb is same as source sample, // also enable temporary buffer. - LIBYUV_BOOL need_buf = - (rotation && format != FOURCC_ARGB) || dst_argb == sample; + int need_buf = (rotation && format != FOURCC_ARGB) || dst_argb == sample; uint8_t* dest_argb = dst_argb; int dest_dst_stride_argb = dst_stride_argb; uint8_t* rotate_buffer = NULL; - int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height; + int inv_crop_height = (crop_height < 0) ? -crop_height : crop_height; - if (dst_argb == NULL || sample == NULL || src_width <= 0 || crop_width <= 0 || - src_height == 0 || crop_height == 0) { - return -1; - } if (src_height < 0) { inv_crop_height = -inv_crop_height; } if (need_buf) { - int argb_size = crop_width * 4 * abs_crop_height; - rotate_buffer = (uint8_t*)malloc(argb_size); /* NOLINT */ + const uint64_t rotate_buffer_size = + (uint64_t)crop_width * 4 * abs_crop_height; +#if UINT64_MAX > SIZE_MAX + if (rotate_buffer_size > SIZE_MAX) { + return -1; // Invalid size. + } +#endif + rotate_buffer = (uint8_t*)malloc((size_t)rotate_buffer_size); if (!rotate_buffer) { return 1; // Out of memory runtime error. } @@ -90,200 +381,337 @@ int ConvertToARGB(const uint8_t* sample, switch (format) { // Single plane formats case FOURCC_YUY2: - src = sample + (aligned_src_width * crop_y + crop_x) * 2; + src = sample + ((ptrdiff_t)aligned_src_width * crop_y + crop_x) * 2; r = YUY2ToARGB(src, aligned_src_width * 2, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_UYVY: - src = sample + (aligned_src_width * crop_y + crop_x) * 2; + src = sample + ((ptrdiff_t)aligned_src_width * crop_y + crop_x) * 2; r = UYVYToARGB(src, aligned_src_width * 2, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_24BG: - src = sample + (src_width * crop_y + crop_x) * 3; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 3; r = RGB24ToARGB(src, src_width * 3, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_RAW: - src = sample + (src_width * crop_y + crop_x) * 3; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 3; r = RAWToARGB(src, src_width * 3, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_ARGB: if (!need_buf && !rotation) { - src = sample + (src_width * crop_y + crop_x) * 4; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; r = ARGBToARGB(src, src_width * 4, dst_argb, dst_stride_argb, crop_width, inv_crop_height); } break; case FOURCC_BGRA: - src = sample + (src_width * crop_y + crop_x) * 4; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; r = BGRAToARGB(src, src_width * 4, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_ABGR: - src = sample + (src_width * crop_y + crop_x) * 4; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; r = ABGRToARGB(src, src_width * 4, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_RGBA: - src = sample + (src_width * crop_y + crop_x) * 4; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; r = RGBAToARGB(src, src_width * 4, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_AR30: - src = sample + (src_width * crop_y + crop_x) * 4; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; r = AR30ToARGB(src, src_width * 4, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_AB30: - src = sample + (src_width * crop_y + crop_x) * 4; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; r = AB30ToARGB(src, src_width * 4, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_RGBP: - src = sample + (src_width * crop_y + crop_x) * 2; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 2; r = RGB565ToARGB(src, src_width * 2, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_RGBO: - src = sample + (src_width * crop_y + crop_x) * 2; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 2; r = ARGB1555ToARGB(src, src_width * 2, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_R444: - src = sample + (src_width * crop_y + crop_x) * 2; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 2; r = ARGB4444ToARGB(src, src_width * 2, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_I400: - src = sample + src_width * crop_y + crop_x; + src = sample + (ptrdiff_t)src_width * crop_y + crop_x; r = I400ToARGB(src, src_width, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; + case FOURCC_J400: + src = sample + (ptrdiff_t)src_width * crop_y + crop_x; + r = J400ToARGB(src, src_width, dst_argb, dst_stride_argb, crop_width, + inv_crop_height); + break; // Biplanar formats case FOURCC_NV12: - src = sample + (src_width * crop_y + crop_x); - src_uv = - sample + aligned_src_width * (abs_src_height + crop_y / 2) + crop_x; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x); + src_uv = sample + + aligned_src_width * ((ptrdiff_t)abs_src_height + crop_y / 2) + + (crop_x & ~1); r = NV12ToARGB(src, src_width, src_uv, aligned_src_width, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; case FOURCC_NV21: - src = sample + (src_width * crop_y + crop_x); - src_uv = - sample + aligned_src_width * (abs_src_height + crop_y / 2) + crop_x; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x); + src_uv = sample + + aligned_src_width * ((ptrdiff_t)abs_src_height + crop_y / 2) + + (crop_x & ~1); // Call NV12 but with u and v parameters swapped. r = NV21ToARGB(src, src_width, src_uv, aligned_src_width, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; - case FOURCC_M420: - src = sample + (src_width * crop_y) * 12 / 8 + crop_x; - r = M420ToARGB(src, src_width, dst_argb, dst_stride_argb, crop_width, - inv_crop_height); + case FOURCC_NV16: + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x); + src_uv = sample + + aligned_src_width * ((ptrdiff_t)abs_src_height + crop_y) + + (crop_x & ~1); + r = NV16ToARGB(src, src_width, src_uv, aligned_src_width, dst_argb, + dst_stride_argb, crop_width, inv_crop_height); break; - + case FOURCC_NV24: + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x); + src_uv = sample + (ptrdiff_t)aligned_src_width * abs_src_height + + (ptrdiff_t)aligned_src_width * 2 * crop_y + + (ptrdiff_t)crop_x * 2; + r = NV24ToARGB(src, src_width, src_uv, aligned_src_width * 2, dst_argb, + dst_stride_argb, crop_width, inv_crop_height); + break; + case FOURCC_P010: { + const uint16_t* src16 = (const uint16_t*)sample; + const uint16_t* src_y16 = + src16 + ((ptrdiff_t)src_width * crop_y + crop_x); + const uint16_t* src_uv16 = + src16 + ((ptrdiff_t)src_width * abs_src_height) + + ((ptrdiff_t)(crop_y / 2) * aligned_src_width) + ((crop_x / 2) * 2); + r = P010ToARGBMatrix(src_y16, src_width, src_uv16, aligned_src_width, + dst_argb, dst_stride_argb, &kYuvI601Constants, + crop_width, inv_crop_height); + break; + } + case FOURCC_P210: { + const uint16_t* src16 = (const uint16_t*)sample; + const uint16_t* src_y16 = + src16 + ((ptrdiff_t)src_width * crop_y + crop_x); + const uint16_t* src_uv16 = + src16 + ((ptrdiff_t)src_width * abs_src_height) + + ((ptrdiff_t)crop_y * aligned_src_width) + ((crop_x / 2) * 2); + r = P210ToARGBMatrix(src_y16, src_width, src_uv16, aligned_src_width, + dst_argb, dst_stride_argb, &kYuvI601Constants, + crop_width, inv_crop_height); + break; + } + case FOURCC_P410: { + const uint16_t* src16 = (const uint16_t*)sample; + const uint16_t* src_y16 = + src16 + ((ptrdiff_t)src_width * crop_y + crop_x); + const uint16_t* src_uv16 = + src16 + ((ptrdiff_t)src_width * abs_src_height) + + ((ptrdiff_t)crop_y * src_width * 2) + crop_x * 2; + r = P410ToARGBMatrix(src_y16, src_width, src_uv16, src_width * 2, + dst_argb, dst_stride_argb, &kYuvI601Constants, + crop_width, inv_crop_height); + break; + } // Triplanar formats case FOURCC_I420: case FOURCC_YV12: { - const uint8_t* src_y = sample + (src_width * crop_y + crop_x); + const uint8_t* src_y = sample + ((ptrdiff_t)src_width * crop_y + crop_x); const uint8_t* src_u; const uint8_t* src_v; int halfwidth = (src_width + 1) / 2; int halfheight = (abs_src_height + 1) / 2; if (format == FOURCC_YV12) { - src_v = sample + src_width * abs_src_height + - (halfwidth * crop_y + crop_x) / 2; - src_u = sample + src_width * abs_src_height + - halfwidth * (halfheight + crop_y / 2) + crop_x / 2; + src_v = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * (crop_y / 2) + crop_x / 2; + src_u = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)halfheight + crop_y / 2) + crop_x / 2; } else { - src_u = sample + src_width * abs_src_height + - (halfwidth * crop_y + crop_x) / 2; - src_v = sample + src_width * abs_src_height + - halfwidth * (halfheight + crop_y / 2) + crop_x / 2; + src_u = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * (crop_y / 2) + crop_x / 2; + src_v = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)halfheight + crop_y / 2) + crop_x / 2; } r = I420ToARGB(src_y, src_width, src_u, halfwidth, src_v, halfwidth, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; } - case FOURCC_H420: { - int halfwidth = (src_width + 1) / 2; - int halfheight = (abs_src_height + 1) / 2; - const uint8_t* src_y = sample + (src_width * crop_y + crop_x); - const uint8_t* src_u = sample + src_width * abs_src_height + - (halfwidth * crop_y + crop_x) / 2; - const uint8_t* src_v = sample + src_width * abs_src_height + - halfwidth * (halfheight + crop_y / 2) + crop_x / 2; - r = H420ToARGB(src_y, src_width, src_u, halfwidth, src_v, halfwidth, - dst_argb, dst_stride_argb, crop_width, inv_crop_height); - break; - } - case FOURCC_J420: { int halfwidth = (src_width + 1) / 2; int halfheight = (abs_src_height + 1) / 2; - const uint8_t* src_y = sample + (src_width * crop_y + crop_x); - const uint8_t* src_u = sample + src_width * abs_src_height + - (halfwidth * crop_y + crop_x) / 2; - const uint8_t* src_v = sample + src_width * abs_src_height + - halfwidth * (halfheight + crop_y / 2) + crop_x / 2; + const uint8_t* src_y = sample + ((ptrdiff_t)src_width * crop_y + crop_x); + const uint8_t* src_u = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * (crop_y / 2) + crop_x / 2; + const uint8_t* src_v = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)halfheight + crop_y / 2) + + crop_x / 2; r = J420ToARGB(src_y, src_width, src_u, halfwidth, src_v, halfwidth, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; } + case FOURCC_H420: { + int halfwidth = (src_width + 1) / 2; + int halfheight = (abs_src_height + 1) / 2; + const uint8_t* src_y = sample + ((ptrdiff_t)src_width * crop_y + crop_x); + const uint8_t* src_u = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * (crop_y / 2) + crop_x / 2; + const uint8_t* src_v = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)halfheight + crop_y / 2) + + crop_x / 2; + r = H420ToARGB(src_y, src_width, src_u, halfwidth, src_v, halfwidth, + dst_argb, dst_stride_argb, crop_width, inv_crop_height); + break; + } + + case FOURCC_U420: { + int halfwidth = (src_width + 1) / 2; + int halfheight = (abs_src_height + 1) / 2; + const uint8_t* src_y = sample + ((ptrdiff_t)src_width * crop_y + crop_x); + const uint8_t* src_u = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * (crop_y / 2) + crop_x / 2; + const uint8_t* src_v = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)halfheight + crop_y / 2) + + crop_x / 2; + r = U420ToARGB(src_y, src_width, src_u, halfwidth, src_v, halfwidth, + dst_argb, dst_stride_argb, crop_width, inv_crop_height); + break; + } + case FOURCC_I422: case FOURCC_YV16: { int halfwidth = (src_width + 1) / 2; - const uint8_t* src_y = sample + src_width * crop_y + crop_x; + const uint8_t* src_y = sample + (ptrdiff_t)src_width * crop_y + crop_x; const uint8_t* src_u; const uint8_t* src_v; if (format == FOURCC_YV16) { - src_v = sample + src_width * abs_src_height + halfwidth * crop_y + - crop_x / 2; - src_u = sample + src_width * abs_src_height + - halfwidth * (abs_src_height + crop_y) + crop_x / 2; + src_v = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * crop_y + crop_x / 2; + src_u = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)abs_src_height + crop_y) + crop_x / 2; } else { - src_u = sample + src_width * abs_src_height + halfwidth * crop_y + - crop_x / 2; - src_v = sample + src_width * abs_src_height + - halfwidth * (abs_src_height + crop_y) + crop_x / 2; + src_u = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * crop_y + crop_x / 2; + src_v = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)abs_src_height + crop_y) + crop_x / 2; } r = I422ToARGB(src_y, src_width, src_u, halfwidth, src_v, halfwidth, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; } + case FOURCC_J422: { + int halfwidth = (src_width + 1) / 2; + const uint8_t* src_y = sample + (ptrdiff_t)src_width * crop_y + crop_x; + const uint8_t* src_u = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * crop_y + crop_x / 2; + const uint8_t* src_v = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)abs_src_height + crop_y) + + crop_x / 2; + r = J422ToARGB(src_y, src_width, src_u, halfwidth, src_v, halfwidth, + dst_argb, dst_stride_argb, crop_width, inv_crop_height); + break; + } + case FOURCC_H422: { int halfwidth = (src_width + 1) / 2; - const uint8_t* src_y = sample + src_width * crop_y + crop_x; - const uint8_t* src_u = - sample + src_width * abs_src_height + halfwidth * crop_y + crop_x / 2; - const uint8_t* src_v = sample + src_width * abs_src_height + - halfwidth * (abs_src_height + crop_y) + crop_x / 2; + const uint8_t* src_y = sample + (ptrdiff_t)src_width * crop_y + crop_x; + const uint8_t* src_u = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * crop_y + crop_x / 2; + const uint8_t* src_v = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)abs_src_height + crop_y) + + crop_x / 2; r = H422ToARGB(src_y, src_width, src_u, halfwidth, src_v, halfwidth, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; } + case FOURCC_U422: { + int halfwidth = (src_width + 1) / 2; + const uint8_t* src_y = sample + (ptrdiff_t)src_width * crop_y + crop_x; + const uint8_t* src_u = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * crop_y + crop_x / 2; + const uint8_t* src_v = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)abs_src_height + crop_y) + + crop_x / 2; + r = U422ToARGB(src_y, src_width, src_u, halfwidth, src_v, halfwidth, + dst_argb, dst_stride_argb, crop_width, inv_crop_height); + break; + } + case FOURCC_I444: case FOURCC_YV24: { - const uint8_t* src_y = sample + src_width * crop_y + crop_x; + const uint8_t* src_y = sample + (ptrdiff_t)src_width * crop_y + crop_x; const uint8_t* src_u; const uint8_t* src_v; if (format == FOURCC_YV24) { - src_v = sample + src_width * (abs_src_height + crop_y) + crop_x; - src_u = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x; + src_v = + sample + src_width * ((ptrdiff_t)abs_src_height + crop_y) + crop_x; + src_u = sample + src_width * ((ptrdiff_t)abs_src_height * 2 + crop_y) + + crop_x; } else { - src_u = sample + src_width * (abs_src_height + crop_y) + crop_x; - src_v = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x; + src_u = + sample + src_width * ((ptrdiff_t)abs_src_height + crop_y) + crop_x; + src_v = sample + src_width * ((ptrdiff_t)abs_src_height * 2 + crop_y) + + crop_x; } r = I444ToARGB(src_y, src_width, src_u, src_width, src_v, src_width, dst_argb, dst_stride_argb, crop_width, inv_crop_height); break; } + + case FOURCC_J444: { + const uint8_t* src_y = sample + (ptrdiff_t)src_width * crop_y + crop_x; + const uint8_t* src_u = + sample + src_width * ((ptrdiff_t)abs_src_height + crop_y) + crop_x; + const uint8_t* src_v = + sample + src_width * ((ptrdiff_t)abs_src_height * 2 + crop_y) + + crop_x; + r = J444ToARGB(src_y, src_width, src_u, src_width, src_v, src_width, + dst_argb, dst_stride_argb, crop_width, inv_crop_height); + break; + } + + case FOURCC_H444: { + const uint8_t* src_y = sample + (ptrdiff_t)src_width * crop_y + crop_x; + const uint8_t* src_u = + sample + src_width * ((ptrdiff_t)abs_src_height + crop_y) + crop_x; + const uint8_t* src_v = + sample + src_width * ((ptrdiff_t)abs_src_height * 2 + crop_y) + + crop_x; + r = H444ToARGB(src_y, src_width, src_u, src_width, src_v, src_width, + dst_argb, dst_stride_argb, crop_width, inv_crop_height); + break; + } + + case FOURCC_U444: { + const uint8_t* src_y = sample + (ptrdiff_t)src_width * crop_y + crop_x; + const uint8_t* src_u = + sample + src_width * ((ptrdiff_t)abs_src_height + crop_y) + crop_x; + const uint8_t* src_v = + sample + src_width * ((ptrdiff_t)abs_src_height * 2 + crop_y) + + crop_x; + r = U444ToARGB(src_y, src_width, src_u, src_width, src_v, src_width, + dst_argb, dst_stride_argb, crop_width, inv_crop_height); + break; + } + #ifdef HAVE_JPEG case FOURCC_MJPG: r = MJPGToARGB(sample, sample_size, dst_argb, dst_stride_argb, src_width, @@ -301,7 +729,7 @@ int ConvertToARGB(const uint8_t* sample, } free(rotate_buffer); } else if (rotation) { - src = sample + (src_width * crop_y + crop_x) * 4; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; r = ARGBRotate(src, src_width * 4, dst_argb, dst_stride_argb, crop_width, inv_crop_height, rotation); } diff --git a/libs/libyuv/source/convert_to_i420.cc b/libs/libyuv/source/convert_to_i420.cc index 584be0ac33..e5a094df9b 100644 --- a/libs/libyuv/source/convert_to_i420.cc +++ b/libs/libyuv/source/convert_to_i420.cc @@ -8,10 +8,17 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include - #include "libyuv/convert.h" +#include +#include +#include +#include +#include + +#include "libyuv/cpu_id.h" +#include "libyuv/planar_functions.h" +#include "libyuv/row.h" #include "libyuv/video_common.h" #ifdef __cplusplus @@ -19,6 +26,257 @@ namespace libyuv { extern "C" { #endif +static int NV16ToI420(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + int y; + int halfwidth = (width + 1) >> 1; + int halfheight = (height + 1) >> 1; + // UV rows are halfwidth * 2 (even) bytes. + int awidth = halfwidth * 2; + void (*SplitUVRow)(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, + int width) = SplitUVRow_C; + void (*InterpolateRow)(uint8_t* dst_ptr, const uint8_t* src_ptr, + ptrdiff_t src_stride, int dst_width, + int source_y_fraction) = InterpolateRow_C; + if ((!src_y && dst_y) || !src_uv || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + if (src_y) { + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_stride_y = -src_stride_y; + } + src_uv = src_uv + (ptrdiff_t)(height - 1) * src_stride_uv; + src_stride_uv = -src_stride_uv; + } + if (dst_y) { + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } +#if defined(HAS_SPLITUVROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + SplitUVRow = SplitUVRow_Any_SSE2; + if (IS_ALIGNED(halfwidth, 16)) { + SplitUVRow = SplitUVRow_SSE2; + } + } +#endif +#if defined(HAS_SPLITUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SplitUVRow = SplitUVRow_Any_AVX2; + if (IS_ALIGNED(halfwidth, 32)) { + SplitUVRow = SplitUVRow_AVX2; + } + } +#endif +#if defined(HAS_SPLITUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + SplitUVRow = SplitUVRow_AVX512BW; + } +#endif +#if defined(HAS_SPLITUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + SplitUVRow = SplitUVRow_Any_NEON; + if (IS_ALIGNED(halfwidth, 16)) { + SplitUVRow = SplitUVRow_NEON; + } + } +#endif +#if defined(HAS_SPLITUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + SplitUVRow = SplitUVRow_SVE2; + } +#endif +#if defined(HAS_SPLITUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + SplitUVRow = SplitUVRow_Any_LSX; + if (IS_ALIGNED(halfwidth, 16)) { + SplitUVRow = SplitUVRow_LSX; + } + } +#endif +#if defined(HAS_SPLITUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + SplitUVRow = SplitUVRow_Any_LASX; + if (IS_ALIGNED(halfwidth, 32)) { + SplitUVRow = SplitUVRow_LASX; + } + } +#endif +#if defined(HAS_SPLITUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SplitUVRow = SplitUVRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + InterpolateRow = InterpolateRow_Any_AVX2; + if (IS_ALIGNED(awidth, 32)) { + InterpolateRow = InterpolateRow_AVX2; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_AVX512BW; + } +#endif +#if defined(HAS_INTERPOLATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + InterpolateRow = InterpolateRow_Any_NEON; + if (IS_ALIGNED(awidth, 16)) { + InterpolateRow = InterpolateRow_NEON; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + InterpolateRow = InterpolateRow_SVE2; + } +#endif +#if defined(HAS_INTERPOLATEROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + InterpolateRow = InterpolateRow_Any_LSX; + if (IS_ALIGNED(awidth, 16)) { + InterpolateRow = InterpolateRow_LSX; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + InterpolateRow = InterpolateRow_Any_LASX; + if (IS_ALIGNED(awidth, 32)) { + InterpolateRow = InterpolateRow_LASX; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + InterpolateRow = InterpolateRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_Any_WASMSIMD; + if (IS_ALIGNED(awidth, 16)) { + InterpolateRow = InterpolateRow_WASMSIMD; + } + } +#endif + + align_buffer_64(row_uv, awidth); + if (!row_uv) { + return 1; + } + for (y = 0; y < halfheight; ++y) { + if (y * 2 + 1 < height) { + // Average 2 rows of UV with rounding (source_y_fraction 128). + InterpolateRow(row_uv, src_uv, src_stride_uv, awidth, 128); + SplitUVRow(row_uv, dst_u, dst_v, halfwidth); + } else { + SplitUVRow(src_uv, dst_u, dst_v, halfwidth); + } + src_uv += (ptrdiff_t)src_stride_uv * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; + } + free_aligned_buffer_64(row_uv); + return 0; +} + +static int NV24ToI420(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height) { + int x, y; + int halfwidth = (width + 1) >> 1; + int halfheight = (height + 1) >> 1; + void (*HalfRow)(const uint8_t* src_uv, ptrdiff_t src_uv_stride, + uint8_t* dst_uv, int width) = HalfRow_C; + if ((!src_y && dst_y) || !src_uv || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + if (src_y) { + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_stride_y = -src_stride_y; + } + src_uv = src_uv + (ptrdiff_t)(height - 1) * src_stride_uv; + src_stride_uv = -src_stride_uv; + } + if (dst_y) { + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } +#if defined(HAS_HALFROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + HalfRow = HalfRow_Any_AVX2; + if (IS_ALIGNED(width * 2, 32)) { + HalfRow = HalfRow_AVX2; + } + } +#endif + + align_buffer_64(row_uv, width * 2); + if (!row_uv) { + return 1; + } + for (y = 0; y < halfheight; ++y) { + if (y * 2 + 1 < height) { + HalfRow(src_uv, src_stride_uv, row_uv, width * 2); + } else { + memcpy(row_uv, src_uv, (size_t)width * 2); + } + for (x = 0; x < halfwidth - 1; ++x) { + dst_u[x] = (row_uv[x * 4 + 0] + row_uv[x * 4 + 2] + 1) >> 1; + dst_v[x] = (row_uv[x * 4 + 1] + row_uv[x * 4 + 3] + 1) >> 1; + } + if (width & 1) { + dst_u[halfwidth - 1] = row_uv[(halfwidth - 1) * 4 + 0]; + dst_v[halfwidth - 1] = row_uv[(halfwidth - 1) * 4 + 1]; + } else { + dst_u[halfwidth - 1] = (row_uv[(halfwidth - 1) * 4 + 0] + + row_uv[(halfwidth - 1) * 4 + 2] + 1) >> + 1; + dst_v[halfwidth - 1] = (row_uv[(halfwidth - 1) * 4 + 1] + + row_uv[(halfwidth - 1) * 4 + 3] + 1) >> + 1; + } + src_uv += (ptrdiff_t)src_stride_uv * 2; + dst_u += dst_stride_u; + dst_v += dst_stride_v; + } + free_aligned_buffer_64(row_uv); + return 0; +} + // Convert camera sample to I420 with cropping, rotation and vertical flip. // src_width is used for source stride computation // src_height is used to compute location of planes, and indicate inversion @@ -41,18 +299,28 @@ int ConvertToI420(const uint8_t* sample, int crop_height, enum RotationMode rotation, uint32_t fourcc) { + if (src_height == INT_MIN || crop_height == INT_MIN) { + return -1; + } + + const int abs_src_height = (src_height < 0) ? -src_height : src_height; + const int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height; + + if (!dst_y || !dst_u || !dst_v || !sample || src_width <= 0 || + src_width > INT_MAX / 4 || crop_width <= 0 || src_height == 0 || + crop_height == 0 || crop_x < 0 || crop_y < 0 || crop_width > src_width || + crop_x > src_width - crop_width || abs_crop_height > abs_src_height || + crop_y > abs_src_height - abs_crop_height) { + return -1; + } + uint32_t format = CanonicalFourCC(fourcc); - int aligned_src_width = (src_width + 1) & ~1; const uint8_t* src; const uint8_t* src_uv; - const int abs_src_height = (src_height < 0) ? -src_height : src_height; - // TODO(nisse): Why allow crop_height < 0? - const int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height; int r = 0; - LIBYUV_BOOL need_buf = - (rotation && format != FOURCC_I420 && format != FOURCC_NV12 && - format != FOURCC_NV21 && format != FOURCC_YV12) || - dst_y == sample; + int need_buf = (rotation && format != FOURCC_I420 && format != FOURCC_NV12 && + format != FOURCC_NV21 && format != FOURCC_YV12) || + dst_y == sample; uint8_t* tmp_y = dst_y; uint8_t* tmp_u = dst_u; uint8_t* tmp_v = dst_v; @@ -62,11 +330,7 @@ int ConvertToI420(const uint8_t* sample, uint8_t* rotate_buffer = NULL; const int inv_crop_height = (src_height < 0) ? -abs_crop_height : abs_crop_height; - - if (!dst_y || !dst_u || !dst_v || !sample || src_width <= 0 || - crop_width <= 0 || src_height == 0 || crop_height == 0) { - return -1; - } + int aligned_src_width = (src_width + 1) & ~1; // One pass rotation is available for some formats. For the rest, convert // to I420 (with optional vertical flipping) into a temporary I420 buffer, @@ -74,9 +338,14 @@ int ConvertToI420(const uint8_t* sample, // For in-place conversion, if destination dst_y is same as source sample, // also enable temporary buffer. if (need_buf) { - int y_size = crop_width * abs_crop_height; - int uv_size = ((crop_width + 1) / 2) * ((abs_crop_height + 1) / 2); - rotate_buffer = (uint8_t*)malloc(y_size + uv_size * 2); /* NOLINT */ + size_t y_size = (size_t)crop_width * abs_crop_height; + size_t uv_size = + (size_t)((crop_width + 1) / 2) * ((abs_crop_height + 1) / 2); + if (uv_size > SIZE_MAX / 2 || y_size > SIZE_MAX - uv_size * 2) { + return -1; // Invalid size. + } + const size_t rotate_buffer_size = y_size + uv_size * 2; + rotate_buffer = (uint8_t*)malloc(rotate_buffer_size); if (!rotate_buffer) { return 1; // Out of memory runtime error. } @@ -89,119 +358,189 @@ int ConvertToI420(const uint8_t* sample, switch (format) { // Single plane formats - case FOURCC_YUY2: - src = sample + (aligned_src_width * crop_y + crop_x) * 2; - r = YUY2ToI420(src, aligned_src_width * 2, dst_y, dst_stride_y, dst_u, - dst_stride_u, dst_v, dst_stride_v, crop_width, - inv_crop_height); + case FOURCC_YUY2: { // TODO(fbarchard): Find better odd crop fix. + uint8_t* u = (crop_x & 1) ? dst_v : dst_u; + uint8_t* v = (crop_x & 1) ? dst_u : dst_v; + int stride_u = (crop_x & 1) ? dst_stride_v : dst_stride_u; + int stride_v = (crop_x & 1) ? dst_stride_u : dst_stride_v; + src = sample + ((ptrdiff_t)aligned_src_width * crop_y + crop_x) * 2; + r = YUY2ToI420(src, aligned_src_width * 2, dst_y, dst_stride_y, u, + stride_u, v, stride_v, crop_width, inv_crop_height); break; - case FOURCC_UYVY: - src = sample + (aligned_src_width * crop_y + crop_x) * 2; - r = UYVYToI420(src, aligned_src_width * 2, dst_y, dst_stride_y, dst_u, - dst_stride_u, dst_v, dst_stride_v, crop_width, - inv_crop_height); + } + case FOURCC_UYVY: { + uint8_t* u = (crop_x & 1) ? dst_v : dst_u; + uint8_t* v = (crop_x & 1) ? dst_u : dst_v; + int stride_u = (crop_x & 1) ? dst_stride_v : dst_stride_u; + int stride_v = (crop_x & 1) ? dst_stride_u : dst_stride_v; + src = sample + ((ptrdiff_t)aligned_src_width * crop_y + crop_x) * 2; + r = UYVYToI420(src, aligned_src_width * 2, dst_y, dst_stride_y, u, + stride_u, v, stride_v, crop_width, inv_crop_height); break; + } case FOURCC_RGBP: - src = sample + (src_width * crop_y + crop_x) * 2; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 2; r = RGB565ToI420(src, src_width * 2, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, crop_width, inv_crop_height); break; case FOURCC_RGBO: - src = sample + (src_width * crop_y + crop_x) * 2; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 2; r = ARGB1555ToI420(src, src_width * 2, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, crop_width, inv_crop_height); break; case FOURCC_R444: - src = sample + (src_width * crop_y + crop_x) * 2; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 2; r = ARGB4444ToI420(src, src_width * 2, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, crop_width, inv_crop_height); break; case FOURCC_24BG: - src = sample + (src_width * crop_y + crop_x) * 3; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 3; r = RGB24ToI420(src, src_width * 3, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, crop_width, inv_crop_height); break; case FOURCC_RAW: - src = sample + (src_width * crop_y + crop_x) * 3; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 3; r = RAWToI420(src, src_width * 3, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, crop_width, inv_crop_height); break; case FOURCC_ARGB: - src = sample + (src_width * crop_y + crop_x) * 4; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; r = ARGBToI420(src, src_width * 4, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, crop_width, inv_crop_height); break; case FOURCC_BGRA: - src = sample + (src_width * crop_y + crop_x) * 4; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; r = BGRAToI420(src, src_width * 4, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, crop_width, inv_crop_height); break; case FOURCC_ABGR: - src = sample + (src_width * crop_y + crop_x) * 4; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; r = ABGRToI420(src, src_width * 4, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, crop_width, inv_crop_height); break; case FOURCC_RGBA: - src = sample + (src_width * crop_y + crop_x) * 4; + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; r = RGBAToI420(src, src_width * 4, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, crop_width, inv_crop_height); break; - // TODO(fbarchard): Add AR30 and AB30 + case FOURCC_AR30: + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; + r = AR30ToI420(src, src_width * 4, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, crop_width, + inv_crop_height); + break; + case FOURCC_AB30: + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x) * 4; + r = AB30ToI420(src, src_width * 4, dst_y, dst_stride_y, dst_u, + dst_stride_u, dst_v, dst_stride_v, crop_width, + inv_crop_height); + break; case FOURCC_I400: - src = sample + src_width * crop_y + crop_x; + src = sample + (ptrdiff_t)src_width * crop_y + crop_x; r = I400ToI420(src, src_width, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, crop_width, inv_crop_height); break; // Biplanar formats case FOURCC_NV12: - src = sample + (src_width * crop_y + crop_x); - src_uv = sample + (src_width * abs_src_height) + - ((crop_y / 2) * aligned_src_width) + ((crop_x / 2) * 2); + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x); + src_uv = sample + ((ptrdiff_t)src_width * abs_src_height) + + ((ptrdiff_t)(crop_y / 2) * aligned_src_width) + + ((crop_x / 2) * 2); r = NV12ToI420Rotate(src, src_width, src_uv, aligned_src_width, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, crop_width, inv_crop_height, rotation); break; case FOURCC_NV21: - src = sample + (src_width * crop_y + crop_x); - src_uv = sample + (src_width * abs_src_height) + - ((crop_y / 2) * aligned_src_width) + ((crop_x / 2) * 2); + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x); + src_uv = sample + ((ptrdiff_t)src_width * abs_src_height) + + ((ptrdiff_t)(crop_y / 2) * aligned_src_width) + + ((crop_x / 2) * 2); // Call NV12 but with dst_u and dst_v parameters swapped. r = NV12ToI420Rotate(src, src_width, src_uv, aligned_src_width, dst_y, dst_stride_y, dst_v, dst_stride_v, dst_u, dst_stride_u, crop_width, inv_crop_height, rotation); break; - case FOURCC_M420: - src = sample + (src_width * crop_y) * 12 / 8 + crop_x; - r = M420ToI420(src, src_width, dst_y, dst_stride_y, dst_u, dst_stride_u, - dst_v, dst_stride_v, crop_width, inv_crop_height); + case FOURCC_NV16: + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x); + src_uv = sample + ((ptrdiff_t)aligned_src_width * abs_src_height) + + ((ptrdiff_t)crop_y * aligned_src_width) + ((crop_x / 2) * 2); + r = NV16ToI420(src, src_width, src_uv, aligned_src_width, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, + crop_width, inv_crop_height); break; + case FOURCC_NV24: + src = sample + ((ptrdiff_t)src_width * crop_y + crop_x); + src_uv = sample + ((ptrdiff_t)aligned_src_width * abs_src_height) + + ((ptrdiff_t)crop_y * aligned_src_width * 2) + (crop_x * 2); + r = NV24ToI420(src, src_width, src_uv, aligned_src_width * 2, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, + crop_width, inv_crop_height); + break; + case FOURCC_P010: { + const uint16_t* src16 = (const uint16_t*)sample; + const uint16_t* src_y16 = + src16 + ((ptrdiff_t)src_width * crop_y + crop_x); + const uint16_t* src_uv16 = + src16 + ((ptrdiff_t)src_width * abs_src_height) + + ((ptrdiff_t)(crop_y / 2) * aligned_src_width) + ((crop_x / 2) * 2); + r = P010ToI420(src_y16, src_width, src_uv16, aligned_src_width, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, + crop_width, inv_crop_height); + break; + } + case FOURCC_P210: { + const uint16_t* src16 = (const uint16_t*)sample; + const uint16_t* src_y16 = + src16 + ((ptrdiff_t)src_width * crop_y + crop_x); + const uint16_t* src_uv16 = + src16 + ((ptrdiff_t)src_width * abs_src_height) + + ((ptrdiff_t)crop_y * aligned_src_width) + ((crop_x / 2) * 2); + r = P210ToI420(src_y16, src_width, src_uv16, aligned_src_width, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, + crop_width, inv_crop_height); + break; + } + case FOURCC_P410: { + const uint16_t* src16 = (const uint16_t*)sample; + const uint16_t* src_y16 = + src16 + ((ptrdiff_t)src_width * crop_y + crop_x); + const uint16_t* src_uv16 = + src16 + ((ptrdiff_t)src_width * abs_src_height) + + ((ptrdiff_t)crop_y * src_width * 2) + crop_x * 2; + r = P410ToI420(src_y16, src_width, src_uv16, src_width * 2, dst_y, + dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, + crop_width, inv_crop_height); + break; + } // Triplanar formats case FOURCC_I420: case FOURCC_YV12: { - const uint8_t* src_y = sample + (src_width * crop_y + crop_x); + const uint8_t* src_y = sample + ((ptrdiff_t)src_width * crop_y + crop_x); const uint8_t* src_u; const uint8_t* src_v; int halfwidth = (src_width + 1) / 2; int halfheight = (abs_src_height + 1) / 2; if (format == FOURCC_YV12) { - src_v = sample + src_width * abs_src_height + halfwidth * (crop_y / 2) + + src_v = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * (crop_y / 2) + (crop_x / 2); + src_u = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)halfheight + (crop_y / 2)) + (crop_x / 2); - src_u = sample + src_width * abs_src_height + - halfwidth * (halfheight + (crop_y / 2)) + (crop_x / 2); } else { - src_u = sample + src_width * abs_src_height + halfwidth * (crop_y / 2) + + src_u = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * (crop_y / 2) + (crop_x / 2); + src_v = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)halfheight + (crop_y / 2)) + (crop_x / 2); - src_v = sample + src_width * abs_src_height + - halfwidth * (halfheight + (crop_y / 2)) + (crop_x / 2); } r = I420Rotate(src_y, src_width, src_u, halfwidth, src_v, halfwidth, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, @@ -210,20 +549,20 @@ int ConvertToI420(const uint8_t* sample, } case FOURCC_I422: case FOURCC_YV16: { - const uint8_t* src_y = sample + src_width * crop_y + crop_x; + const uint8_t* src_y = sample + (ptrdiff_t)src_width * crop_y + crop_x; const uint8_t* src_u; const uint8_t* src_v; int halfwidth = (src_width + 1) / 2; if (format == FOURCC_YV16) { - src_v = sample + src_width * abs_src_height + halfwidth * crop_y + - (crop_x / 2); - src_u = sample + src_width * abs_src_height + - halfwidth * (abs_src_height + crop_y) + (crop_x / 2); + src_v = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * crop_y + (crop_x / 2); + src_u = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)abs_src_height + crop_y) + (crop_x / 2); } else { - src_u = sample + src_width * abs_src_height + halfwidth * crop_y + - (crop_x / 2); - src_v = sample + src_width * abs_src_height + - halfwidth * (abs_src_height + crop_y) + (crop_x / 2); + src_u = sample + (ptrdiff_t)src_width * abs_src_height + + (ptrdiff_t)halfwidth * crop_y + (crop_x / 2); + src_v = sample + (ptrdiff_t)src_width * abs_src_height + + halfwidth * ((ptrdiff_t)abs_src_height + crop_y) + (crop_x / 2); } r = I422ToI420(src_y, src_width, src_u, halfwidth, src_v, halfwidth, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, @@ -232,15 +571,19 @@ int ConvertToI420(const uint8_t* sample, } case FOURCC_I444: case FOURCC_YV24: { - const uint8_t* src_y = sample + src_width * crop_y + crop_x; + const uint8_t* src_y = sample + (ptrdiff_t)src_width * crop_y + crop_x; const uint8_t* src_u; const uint8_t* src_v; if (format == FOURCC_YV24) { - src_v = sample + src_width * (abs_src_height + crop_y) + crop_x; - src_u = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x; + src_v = + sample + src_width * ((ptrdiff_t)abs_src_height + crop_y) + crop_x; + src_u = sample + src_width * ((ptrdiff_t)abs_src_height * 2 + crop_y) + + crop_x; } else { - src_u = sample + src_width * (abs_src_height + crop_y) + crop_x; - src_v = sample + src_width * (abs_src_height * 2 + crop_y) + crop_x; + src_u = + sample + src_width * ((ptrdiff_t)abs_src_height + crop_y) + crop_x; + src_v = sample + src_width * ((ptrdiff_t)abs_src_height * 2 + crop_y) + + crop_x; } r = I444ToI420(src_y, src_width, src_u, src_width, src_v, src_width, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, diff --git a/libs/libyuv/source/cpu_id.cc b/libs/libyuv/source/cpu_id.cc index 48e2b61526..f78283a972 100644 --- a/libs/libyuv/source/cpu_id.cc +++ b/libs/libyuv/source/cpu_id.cc @@ -20,9 +20,25 @@ #endif // For ArmCpuCaps() but unittested on all platforms -#include +#include // For fopen() #include +#if defined(__linux__) && (defined(__aarch64__) || defined(__loongarch__)) +#include // For getauxval() +#endif + +#if defined(_WIN32) && defined(__aarch64__) +#undef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#undef WIN32_EXTRA_LEAN +#define WIN32_EXTRA_LEAN +#include // For IsProcessorFeaturePresent() +#endif + +#if defined(__APPLE__) && defined(__aarch64__) +#include // For sysctlbyname() +#endif + #ifdef __cplusplus namespace libyuv { extern "C" { @@ -40,7 +56,6 @@ extern "C" { // cpu_info_ variable for SIMD instruction sets detected. LIBYUV_API int cpu_info_ = 0; -// TODO(fbarchard): Consider using int for cpuid so casting is not needed. // Low level cpuid for X86. #if (defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \ defined(__x86_64__)) && \ @@ -75,9 +90,9 @@ void CpuId(int info_eax, int info_ecx, int* cpu_info) { asm volatile( #if defined(__i386__) && defined(__PIC__) // Preserve ebx for fpic 32 bit. - "mov %%ebx, %%edi \n" + "mov %%ebx, %%edi \n" "cpuid \n" - "xchg %%edi, %%ebx \n" + "xchg %%edi, %%ebx \n" : "=D"(info_ebx), #else "cpuid \n" @@ -108,14 +123,14 @@ void CpuId(int eax, int ecx, int* cpu_info) { // } // For VS2013 and earlier 32 bit, the _xgetbv(0) optimizer produces bad code. // https://code.google.com/p/libyuv/issues/detail?id=529 -#if defined(_M_IX86) && (_MSC_VER < 1900) +#if defined(_M_IX86) && defined(_MSC_VER) && (_MSC_VER < 1900) #pragma optimize("g", off) #endif #if (defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \ defined(__x86_64__)) && \ !defined(__pnacl__) && !defined(__CLR_VER) && !defined(__native_client__) // X86 CPUs have xgetbv to detect OS saves high parts of ymm registers. -int GetXCR0() { +static int GetXCR0() { int xcr0 = 0; #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) xcr0 = (int)_xgetbv(0); // VS2010 SP1 required. NOLINT @@ -129,80 +144,258 @@ int GetXCR0() { #define GetXCR0() 0 #endif // defined(_M_IX86) || defined(_M_X64) .. // Return optimization to previous setting. -#if defined(_M_IX86) && (_MSC_VER < 1900) +#if defined(_M_IX86) && defined(_MSC_VER) && (_MSC_VER < 1900) #pragma optimize("g", on) #endif -// based on libvpx arm_cpudetect.c +static int cpuinfo_search(const char* cpuinfo_line, + const char* needle, + int needle_len) { + const char* p = strstr(cpuinfo_line, needle); + return p && (p[needle_len] == ' ' || p[needle_len] == '\n'); +} + +// Based on libvpx arm_cpudetect.c // For Arm, but public to allow testing on any CPU LIBYUV_API SAFEBUFFERS int ArmCpuCaps(const char* cpuinfo_name) { char cpuinfo_line[512]; - FILE* f = fopen(cpuinfo_name, "r"); + FILE* f = fopen(cpuinfo_name, "re"); if (!f) { // Assume Neon if /proc/cpuinfo is unavailable. // This will occur for Chrome sandbox for Pepper or Render process. return kCpuHasNEON; } - while (fgets(cpuinfo_line, sizeof(cpuinfo_line) - 1, f)) { + memset(cpuinfo_line, 0, sizeof(cpuinfo_line)); + int features = 0; + while (fgets(cpuinfo_line, sizeof(cpuinfo_line), f)) { if (memcmp(cpuinfo_line, "Features", 8) == 0) { - char* p = strstr(cpuinfo_line, " neon"); - if (p && (p[5] == ' ' || p[5] == '\n')) { - fclose(f); - return kCpuHasNEON; - } - // aarch64 uses asimd for Neon. - p = strstr(cpuinfo_line, " asimd"); - if (p) { - fclose(f); - return kCpuHasNEON; + if (cpuinfo_search(cpuinfo_line, " neon", 5)) { + features |= kCpuHasNEON; } } } fclose(f); - return 0; + return features; } -// TODO(fbarchard): Consider read_msa_ir(). -// TODO(fbarchard): Add unittest. -LIBYUV_API SAFEBUFFERS int MipsCpuCaps(const char* cpuinfo_name, - const char ase[]) { - char cpuinfo_line[512]; - FILE* f = fopen(cpuinfo_name, "r"); - if (!f) { - // ase enabled if /proc/cpuinfo is unavailable. - if (strcmp(ase, " msa") == 0) { - return kCpuHasMSA; +#ifdef __aarch64__ +#ifdef __linux__ +// Define hwcap values ourselves: building with an old auxv header where these +// hwcap values are not defined should not prevent features from being enabled. +#define YUV_AARCH64_HWCAP_ASIMDDP (1UL << 20) +#define YUV_AARCH64_HWCAP_SVE (1UL << 22) +#define YUV_AARCH64_HWCAP2_SVE2 (1UL << 1) +#define YUV_AARCH64_HWCAP2_SVEF32MM (1UL << 10) +#define YUV_AARCH64_HWCAP2_I8MM (1UL << 13) +#define YUV_AARCH64_HWCAP2_SME (1UL << 23) +#define YUV_AARCH64_HWCAP2_SME2 (1UL << 37) + +// For AArch64, but public to allow testing on any CPU. +LIBYUV_API SAFEBUFFERS int AArch64CpuCaps(unsigned long hwcap, + unsigned long hwcap2) { + // Neon is mandatory on AArch64, so enable regardless of hwcaps. + int features = kCpuHasNEON; + + // Don't try to enable later extensions unless earlier extensions are also + // reported available. Some of these constraints aren't strictly required by + // the architecture, but are satisfied by all micro-architectures of + // interest. This also avoids an issue on some emulators where true + // architectural constraints are not satisfied, e.g. SVE2 may be reported as + // available while SVE is not. + if (hwcap & YUV_AARCH64_HWCAP_ASIMDDP) { + features |= kCpuHasNeonDotProd; + if (hwcap2 & YUV_AARCH64_HWCAP2_I8MM) { + features |= kCpuHasNeonI8MM; + if (hwcap & YUV_AARCH64_HWCAP_SVE) { + features |= kCpuHasSVE; + if (hwcap2 & YUV_AARCH64_HWCAP2_SVEF32MM) { + features |= kCpuHasSVEF32MM; + } + if (hwcap2 & YUV_AARCH64_HWCAP2_SVE2) { + features |= kCpuHasSVE2; + } + } + // SME may be present without SVE + if (hwcap2 & YUV_AARCH64_HWCAP2_SME) { + features |= kCpuHasSME; + if (hwcap2 & YUV_AARCH64_HWCAP2_SME2) { + features |= kCpuHasSME2; + } + } } - if (strcmp(ase, " mmi") == 0) { - return kCpuHasMMI; - } - return 0; } - while (fgets(cpuinfo_line, sizeof(cpuinfo_line) - 1, f)) { - if (memcmp(cpuinfo_line, "ASEs implemented", 16) == 0) { - char* p = strstr(cpuinfo_line, ase); - if (p) { - fclose(f); - if (strcmp(ase, " msa") == 0) { - return kCpuHasMSA; + return features; +} + +#elif defined(_WIN32) +// For AArch64, but public to allow testing on any CPU. +LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() { + // Neon is mandatory on AArch64, so enable unconditionally. + int features = kCpuHasNEON; + + // For more information on IsProcessorFeaturePresent(), see: + // https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent#parameters +#ifdef PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE + if (IsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE)) { + features |= kCpuHasNeonDotProd; + } +#endif + // No Neon I8MM or SVE feature detection available here at time of writing. + return features; +} + +#elif defined(__APPLE__) +static bool have_feature(const char* feature) { + // For more information on sysctlbyname(), see: + // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics + // If feature is "hw.optional.arm.sme_max_svl_b", this function returns + // whether the value of sme_max_svl_b is nonzero. + int64_t feature_present = 0; + size_t size = sizeof(feature_present); + if (sysctlbyname(feature, &feature_present, &size, NULL, 0) != 0) { + return false; + } + return feature_present != 0; +} + +// For AArch64, but public to allow testing on any CPU. +LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() { + // Neon is mandatory on AArch64, so enable unconditionally. + int features = kCpuHasNEON; + + if (have_feature("hw.optional.arm.FEAT_DotProd")) { + features |= kCpuHasNeonDotProd; + if (have_feature("hw.optional.arm.FEAT_I8MM")) { + features |= kCpuHasNeonI8MM; + // An Apple processor may have SME hardware (e.g. A18/A19), but the XNU + // kernel only enables EL0 execution if sme_max_svl_b is nonzero. + // macOS and iPadOS (e.g. on M4) support and enable user-mode SME, but iOS + // disables user-mode SME, which causes SMSTART to trigger an + // EXC_BAD_INSTRUCTION fault. See + // https://github.com/pytorch/cpuinfo/issues/432. + if (have_feature("hw.optional.arm.sme_max_svl_b") && + have_feature("hw.optional.arm.FEAT_SME")) { + features |= kCpuHasSME; + if (have_feature("hw.optional.arm.FEAT_SME2")) { + features |= kCpuHasSME2; } - return 0; - } - } else if (memcmp(cpuinfo_line, "cpu model", 9) == 0) { - char* p = strstr(cpuinfo_line, "Loongson-3"); - if (p) { - fclose(f); - if (strcmp(ase, " mmi") == 0) { - return kCpuHasMMI; - } - return 0; } } } + // No SVE feature detection available here at time of writing. + return features; +} + +#else // !defined(__linux__) && !defined(_WIN32) && !defined(__APPLE__) +// For AArch64, but public to allow testing on any CPU. +LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() { + // Neon is mandatory on AArch64, so enable unconditionally. + int features = kCpuHasNEON; + + // TODO(libyuv:980) support feature detection on other platforms. + + return features; +} +#endif +#endif // defined(__aarch64__) + +LIBYUV_API SAFEBUFFERS int RiscvCpuCaps(const char* cpuinfo_name) { + char cpuinfo_line[512]; + int flag = 0; + FILE* f = fopen(cpuinfo_name, "re"); + if (!f) { +#if !defined(LIBYUV_DISABLE_RVV) && defined(__riscv) && __riscv_xlen == 64 + // Assume RVV if /proc/cpuinfo is unavailable. + // This will occur for Chrome sandbox for Pepper or Render process. + return kCpuHasRVV; +#else + return 0; +#endif + } + memset(cpuinfo_line, 0, sizeof(cpuinfo_line)); + while (fgets(cpuinfo_line, sizeof(cpuinfo_line), f)) { + if (memcmp(cpuinfo_line, "isa", 3) == 0) { + // ISA string must begin with rv64{i,e,g} for a 64-bit processor. + char* isa = strstr(cpuinfo_line, "rv64"); + if (isa) { + size_t isa_len = strlen(isa); + char* extensions; + size_t extensions_len = 0; + size_t std_isa_len; + // Remove the new-line character at the end of string + if (isa[isa_len - 1] == '\n') { + isa[--isa_len] = '\0'; + } + // 5 ISA characters + if (isa_len < 5) { + fclose(f); + return 0; + } + // Skip {i,e,g} canonical checking. + // Skip rvxxx + isa += 5; + // Find the very first occurrence of 's', 'x' or 'z'. + // To detect multi-letter standard, non-standard, and + // supervisor-level extensions. + extensions = strpbrk(isa, "zxs"); + if (extensions) { + extensions_len = strlen(extensions); + // Multi-letter extensions are seperated by a single underscore + // as described in RISC-V User-Level ISA V2.2. + char* ext = extensions; + while (ext) { + char* next = strchr(ext, '_'); + if (next) { + *next = '\0'; + next++; + } + // Search for the ZVFH (Vector FP16) extension. + if (!strcmp(ext, "zvfh")) { + flag |= kCpuHasRVVZVFH; + } + ext = next; + } + } + std_isa_len = isa_len - extensions_len - 5; + // Detect the v in the standard single-letter extensions. + if (memchr(isa, 'v', std_isa_len)) { + // The RVV implied the F extension. + flag |= kCpuHasRVV; + } + } + } +#if !defined(LIBYUV_DISABLE_RVV) && defined(__riscv) && __riscv_xlen == 64 + // Assume RVV if /proc/cpuinfo is from x86 host running QEMU. + else if ((memcmp(cpuinfo_line, "vendor_id\t: GenuineIntel", 24) == 0) || + (memcmp(cpuinfo_line, "vendor_id\t: AuthenticAMD", 24) == 0)) { + fclose(f); + return kCpuHasRVV; + } +#endif + } fclose(f); - return 0; + return flag; } +#if defined(__loongarch__) && defined(__linux__) +// Define hwcap values ourselves: building with an old auxv header where these +// hwcap values are not defined should not prevent features from being enabled. +#define YUV_LOONGARCH_HWCAP_LSX (1 << 4) +#define YUV_LOONGARCH_HWCAP_LASX (1 << 5) + +LIBYUV_API SAFEBUFFERS int LoongArchCpuCaps(void) { + int flag = 0; + unsigned long hwcap = getauxval(AT_HWCAP); + + if (hwcap & YUV_LOONGARCH_HWCAP_LSX) + flag |= kCpuHasLSX; + + if (hwcap & YUV_LOONGARCH_HWCAP_LASX) + flag |= kCpuHasLASX; + return flag; +} +#endif + static SAFEBUFFERS int GetCpuFlags(void) { int cpu_info = 0; #if !defined(__pnacl__) && !defined(__CLR_VER) && \ @@ -211,62 +404,121 @@ static SAFEBUFFERS int GetCpuFlags(void) { int cpu_info0[4] = {0, 0, 0, 0}; int cpu_info1[4] = {0, 0, 0, 0}; int cpu_info7[4] = {0, 0, 0, 0}; + int cpu_einfo7[4] = {0, 0, 0, 0}; + int cpu_einfo1e[4] = {0, 0, 0, 0}; + int cpu_info24[4] = {0, 0, 0, 0}; + int cpu_info21[4] = {0, 0, 0, 0}; + int cpu_amdinfo21[4] = {0, 0, 0, 0}; + int cpu_extinfo0[4] = {0, 0, 0, 0}; CpuId(0, 0, cpu_info0); CpuId(1, 0, cpu_info1); if (cpu_info0[0] >= 7) { CpuId(7, 0, cpu_info7); + // Leaf 7 EAX reports the maximum supported sub-leaf. + if (cpu_info7[0] >= 1) { + CpuId(7, 1, cpu_einfo7); + } + } + // Extended leaf 0x80000021 is only valid if the CPU reports it. Querying an + // unsupported extended leaf returns data from the highest basic leaf on + // Intel CPUs, which could spuriously set bits below. + CpuId(0x80000000, 0, cpu_extinfo0); + if ((unsigned)cpu_extinfo0[0] >= 0x80000021u) { + CpuId(0x80000021, 0, cpu_amdinfo21); + } + if (cpu_info0[0] >= 0x1e) { + CpuId(0x1e, 1, cpu_einfo1e); + } + if (cpu_info0[0] >= 0x21) { + CpuId(0x21, 0, cpu_info21); + } + if (cpu_info0[0] >= 0x24) { + CpuId(0x24, 0, cpu_info24); } cpu_info = kCpuHasX86 | ((cpu_info1[3] & 0x04000000) ? kCpuHasSSE2 : 0) | ((cpu_info1[2] & 0x00000200) ? kCpuHasSSSE3 : 0) | ((cpu_info1[2] & 0x00080000) ? kCpuHasSSE41 : 0) | ((cpu_info1[2] & 0x00100000) ? kCpuHasSSE42 : 0) | - ((cpu_info7[1] & 0x00000200) ? kCpuHasERMS : 0); + ((cpu_info7[1] & 0x00000200) ? kCpuHasERMS : 0) | + ((cpu_info7[3] & 0x00000010) ? kCpuHasFSMR : 0); // AVX requires OS saves YMM registers. if (((cpu_info1[2] & 0x1c000000) == 0x1c000000) && // AVX and OSXSave ((GetXCR0() & 6) == 6)) { // Test OS saves YMM registers cpu_info |= kCpuHasAVX | ((cpu_info7[1] & 0x00000020) ? kCpuHasAVX2 : 0) | ((cpu_info1[2] & 0x00001000) ? kCpuHasFMA3 : 0) | - ((cpu_info1[2] & 0x20000000) ? kCpuHasF16C : 0); + ((cpu_info1[2] & 0x20000000) ? kCpuHasF16C : 0) | + ((cpu_einfo7[0] & 0x00000010) ? kCpuHasAVXVNNI : 0) | + ((cpu_einfo7[3] & 0x00000010) ? kCpuHasAVXVNNIINT8 : 0); + + cpu_info |= ((cpu_amdinfo21[0] & 0x00008000) ? kCpuHasERMS : 0); // Detect AVX512bw - if ((GetXCR0() & 0xe0) == 0xe0) { - cpu_info |= (cpu_info7[1] & 0x40000000) ? kCpuHasAVX512BW : 0; - cpu_info |= (cpu_info7[1] & 0x80000000) ? kCpuHasAVX512VL : 0; - cpu_info |= (cpu_info7[2] & 0x00000002) ? kCpuHasAVX512VBMI : 0; - cpu_info |= (cpu_info7[2] & 0x00000040) ? kCpuHasAVX512VBMI2 : 0; - cpu_info |= (cpu_info7[2] & 0x00001000) ? kCpuHasAVX512VBITALG : 0; - cpu_info |= (cpu_info7[2] & 0x00004000) ? kCpuHasAVX512VPOPCNTDQ : 0; - cpu_info |= (cpu_info7[2] & 0x00000100) ? kCpuHasGFNI : 0; + if ((GetXCR0() & 0xe0) == 0xe0 && (cpu_info7[1] & 0x00010000)) { + cpu_info |= ((cpu_info7[1] & 0x40000000) ? kCpuHasAVX512BW : 0) | + ((cpu_info7[1] & 0x80000000) ? kCpuHasAVX512VL : 0) | + ((cpu_info7[2] & 0x00000002) ? kCpuHasAVX512VBMI : 0) | + ((cpu_info7[2] & 0x00000040) ? kCpuHasAVX512VBMI2 : 0) | + ((cpu_info7[2] & 0x00000800) ? kCpuHasAVX512VNNI : 0) | + ((cpu_info7[2] & 0x00001000) ? kCpuHasAVX512VBITALG : 0) | + ((cpu_einfo7[3] & 0x00080000) ? kCpuHasAVX10 : 0) | + ((cpu_info7[3] & 0x02000000) ? kCpuHasAMXINT8 : 0) | + ((cpu_info21[0] & 0x00800000) ? kCpuHasAVX512BMM : 0) | + ((cpu_einfo1e[0] & 0x00000040) ? kCpuHasAMXTF32 : 0); + if (cpu_info0[0] >= 0x24 && (cpu_einfo7[3] & 0x00080000)) { + cpu_info |= ((cpu_info24[1] & 0xFF) >= 2) ? kCpuHasAVX10_2 : 0; + } } } #endif -#if defined(__mips__) && defined(__linux__) -#if defined(__mips_msa) - cpu_info = MipsCpuCaps("/proc/cpuinfo", " msa"); -#elif defined(_MIPS_ARCH_LOONGSON3A) - cpu_info = MipsCpuCaps("/proc/cpuinfo", " mmi"); -#endif - cpu_info |= kCpuHasMIPS; -#endif -#if defined(__arm__) || defined(__aarch64__) -// gcc -mfpu=neon defines __ARM_NEON__ -// __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon. -// For Linux, /proc/cpuinfo can be tested but without that assume Neon. -#if defined(__ARM_NEON__) || defined(__native_client__) || !defined(__linux__) - cpu_info = kCpuHasNEON; -// For aarch64(arm64), /proc/cpuinfo's feature is not complete, e.g. no neon -// flag in it. -// So for aarch64, neon enabling is hard coded here. +#if defined(__loongarch__) && defined(__linux__) + cpu_info = LoongArchCpuCaps(); + cpu_info |= kCpuHasLOONGARCH; #endif #if defined(__aarch64__) +#if defined(__linux__) + // getauxval is supported since Android SDK version 18, minimum at time of + // writing is 21, so should be safe to always use this. If getauxval is + // somehow disabled then getauxval returns 0, which will leave Neon enabled + // since Neon is mandatory on AArch64. + unsigned long hwcap = getauxval(AT_HWCAP); + unsigned long hwcap2 = getauxval(AT_HWCAP2); + cpu_info = AArch64CpuCaps(hwcap, hwcap2); +#else + cpu_info = AArch64CpuCaps(); +#endif + cpu_info |= kCpuHasARM; +#endif // __aarch64__ +#if defined(__arm__) + // gcc -mfpu=neon defines __ARM_NEON__ + // __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon. + // For Linux, /proc/cpuinfo can be tested but without that assume Neon. + // Linux arm parse text file for neon detect. +#if defined(__linux__) + cpu_info = ArmCpuCaps("/proc/cpuinfo"); +#elif defined(__ARM_NEON__) cpu_info = kCpuHasNEON; #else - // Linux arm parse text file for neon detect. - cpu_info = ArmCpuCaps("/proc/cpuinfo"); + cpu_info = 0; #endif cpu_info |= kCpuHasARM; #endif // __arm__ +#if defined(__riscv) && defined(__linux__) + cpu_info = RiscvCpuCaps("/proc/cpuinfo"); + cpu_info |= kCpuHasRISCV; +#endif // __riscv +#if defined(__wasm__) + cpu_info = kCpuHasWASM; +#if !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) + cpu_info |= kCpuHasWASMSIMD; +#endif +#endif // __wasm__ +#if defined(__hexagon__) + cpu_info = kCpuHasHexagon; +#if !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) + cpu_info |= kCpuHasHVX; +#endif +#endif // __hexagon__ cpu_info |= kCpuInitialized; return cpu_info; } diff --git a/libs/libyuv/source/mjpeg_decoder.cc b/libs/libyuv/source/mjpeg_decoder.cc index 80e381dd6b..4c6a22f935 100644 --- a/libs/libyuv/source/mjpeg_decoder.cc +++ b/libs/libyuv/source/mjpeg_decoder.cc @@ -13,8 +13,7 @@ #ifdef HAVE_JPEG #include -#if !defined(__pnacl__) && !defined(__CLR_VER) && \ - !defined(COVERAGE_ENABLED) && !defined(TARGET_IPHONE_SIMULATOR) +#if !defined(__pnacl__) && !defined(__CLR_VER) && !defined(COVERAGE_ENABLED) // Must be included before jpeglib. #include #define HAVE_SETJMP @@ -26,7 +25,8 @@ #endif -#include // For jpeglib.h. +#include // For jpeglib.h. +#include // For calloc(), malloc(), and free(). // C++ build requires extern C for jpeg internals. #ifdef __cplusplus @@ -66,16 +66,17 @@ void ErrorHandler(jpeg_common_struct* cinfo); void OutputHandler(jpeg_common_struct* cinfo); MJpegDecoder::MJpegDecoder() - : has_scanline_padding_(LIBYUV_FALSE), + : has_scanline_padding_(false), num_outbufs_(0), scanlines_(NULL), scanlines_sizes_(NULL), databuf_(NULL), databuf_strides_(NULL) { - decompress_struct_ = new jpeg_decompress_struct; - source_mgr_ = new jpeg_source_mgr; + decompress_struct_ = static_cast( + malloc(sizeof(jpeg_decompress_struct))); + source_mgr_ = static_cast(malloc(sizeof(jpeg_source_mgr))); #ifdef HAVE_SETJMP - error_mgr_ = new SetJmpErrorMgr; + error_mgr_ = static_cast(malloc(sizeof(SetJmpErrorMgr))); decompress_struct_->err = jpeg_std_error(&error_mgr_->base); // Override standard exit()-based error handler. error_mgr_->base.error_exit = &ErrorHandler; @@ -95,42 +96,45 @@ MJpegDecoder::MJpegDecoder() MJpegDecoder::~MJpegDecoder() { jpeg_destroy_decompress(decompress_struct_); - delete decompress_struct_; - delete source_mgr_; + free(decompress_struct_); + free(source_mgr_); #ifdef HAVE_SETJMP - delete error_mgr_; + free(error_mgr_); #endif DestroyOutputBuffers(); } -LIBYUV_BOOL MJpegDecoder::LoadFrame(const uint8_t* src, size_t src_len) { +bool MJpegDecoder::LoadFrame(const uint8_t* src, size_t src_len) { if (!ValidateJpeg(src, src_len)) { - return LIBYUV_FALSE; + return false; } buf_.data = src; - buf_.len = static_cast(src_len); + buf_.len = (int)src_len; buf_vec_.pos = 0; decompress_struct_->client_data = &buf_vec_; #ifdef HAVE_SETJMP if (setjmp(error_mgr_->setjmp_buffer)) { // We called jpeg_read_header, it experienced an error, and we called // longjmp() and rewound the stack to here. Return error. - return LIBYUV_FALSE; + return false; } #endif if (jpeg_read_header(decompress_struct_, TRUE) != JPEG_HEADER_OK) { // ERROR: Bad MJPEG header - return LIBYUV_FALSE; + return false; } AllocOutputBuffers(GetNumComponents()); for (int i = 0; i < num_outbufs_; ++i) { int scanlines_size = GetComponentScanlinesPerImcuRow(i); - if (scanlines_sizes_[i] != scanlines_size) { - if (scanlines_[i]) { - delete scanlines_[i]; - } - scanlines_[i] = new uint8_t*[scanlines_size]; + // databuf_[i] is sized by scanlines_size * stride, so a change in either + // must trigger reallocation below. Remember the change before + // scanlines_sizes_[i] is overwritten. + bool scanlines_changed = scanlines_sizes_[i] != scanlines_size; + if (scanlines_changed) { + free(scanlines_[i]); + scanlines_[i] = + static_cast(malloc(scanlines_size * sizeof(uint8_t*))); scanlines_sizes_[i] = scanlines_size; } @@ -141,20 +145,23 @@ LIBYUV_BOOL MJpegDecoder::LoadFrame(const uint8_t* src, size_t src_len) { // the next scanline) and will be overwritten when jpeglib writes out that // next scanline. int databuf_stride = GetComponentStride(i); + // Cannot overflow: + // - JPEG width is stored as an u16, so `databuf_stride` (width rounded up + // to + // DCTSIZE) is at most slightly larger than UINT16_MAX. + // - Sampling factor is stored in 4 bits, so scanlines_size is < 16. int databuf_size = scanlines_size * databuf_stride; - if (databuf_strides_[i] != databuf_stride) { - if (databuf_[i]) { - delete databuf_[i]; - } - databuf_[i] = new uint8_t[databuf_size]; + if (scanlines_changed || databuf_strides_[i] != databuf_stride) { + free(databuf_[i]); + databuf_[i] = static_cast(malloc(databuf_size)); databuf_strides_[i] = databuf_stride; } if (GetComponentStride(i) != GetComponentWidth(i)) { - has_scanline_padding_ = LIBYUV_TRUE; + has_scanline_padding_ = true; } } - return LIBYUV_TRUE; + return true; } static int DivideAndRoundUp(int numerator, int denominator) { @@ -231,50 +238,52 @@ int MJpegDecoder::GetComponentSize(int component) { return GetComponentWidth(component) * GetComponentHeight(component); } -LIBYUV_BOOL MJpegDecoder::UnloadFrame() { +bool MJpegDecoder::UnloadFrame() { #ifdef HAVE_SETJMP if (setjmp(error_mgr_->setjmp_buffer)) { // We called jpeg_abort_decompress, it experienced an error, and we called // longjmp() and rewound the stack to here. Return error. - return LIBYUV_FALSE; + return false; } #endif jpeg_abort_decompress(decompress_struct_); - return LIBYUV_TRUE; + return true; } // TODO(fbarchard): Allow rectangle to be specified: x, y, width, height. -LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes, - int dst_width, - int dst_height) { +bool MJpegDecoder::DecodeToBuffers(uint8_t** planes, + int dst_width, + int dst_height) { if (dst_width != GetWidth() || dst_height > GetHeight()) { // ERROR: Bad dimensions - return LIBYUV_FALSE; + return false; } #ifdef HAVE_SETJMP if (setjmp(error_mgr_->setjmp_buffer)) { // We called into jpeglib, it experienced an error sometime during this // function call, and we called longjmp() and rewound the stack to here. // Return error. - return LIBYUV_FALSE; + return false; } #endif if (!StartDecode()) { - return LIBYUV_FALSE; + return false; } SetScanlinePointers(databuf_); int lines_left = dst_height; // Compute amount of lines to skip to implement vertical crop. - // TODO(fbarchard): Ensure skip is a multiple of maximum component - // subsample. ie 2 + // Round skip down to a multiple of the maximum vertical sampling factor so + // that every component skips a whole number of rows. The rows remaining + // below the crop are still >= dst_height. int skip = (GetHeight() - dst_height) / 2; + skip -= skip % decompress_struct_->max_v_samp_factor; if (skip > 0) { // There is no API to skip lines in the output data, so we read them // into the temp buffer. while (skip >= GetImageScanlinesPerImcuRow()) { if (!DecodeImcuRow()) { FinishDecode(); - return LIBYUV_FALSE; + return false; } skip -= GetImageScanlinesPerImcuRow(); } @@ -283,21 +292,25 @@ LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes, // copy the parts we want into the destination. if (!DecodeImcuRow()) { FinishDecode(); - return LIBYUV_FALSE; + return false; + } + // Image lines wanted from this iMCU row, clamped to the destination. + int image_lines_to_copy = GetImageScanlinesPerImcuRow() - skip; + if (image_lines_to_copy > lines_left) { + image_lines_to_copy = lines_left; } for (int i = 0; i < num_outbufs_; ++i) { - // TODO(fbarchard): Compute skip to avoid this assert(skip % GetVertSubSampFactor(i) == 0); int rows_to_skip = DivideAndRoundDown(skip, GetVertSubSampFactor(i)); int scanlines_to_copy = - GetComponentScanlinesPerImcuRow(i) - rows_to_skip; + DivideAndRoundUp(image_lines_to_copy, GetVertSubSampFactor(i)); int data_to_skip = rows_to_skip * GetComponentStride(i); CopyPlane(databuf_[i] + data_to_skip, GetComponentStride(i), planes[i], GetComponentWidth(i), GetComponentWidth(i), scanlines_to_copy); planes[i] += scanlines_to_copy * GetComponentWidth(i); } - lines_left -= (GetImageScanlinesPerImcuRow() - skip); + lines_left -= image_lines_to_copy; } } @@ -306,7 +319,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes, lines_left -= GetImageScanlinesPerImcuRow()) { if (!DecodeImcuRow()) { FinishDecode(); - return LIBYUV_FALSE; + return false; } for (int i = 0; i < num_outbufs_; ++i) { int scanlines_to_copy = GetComponentScanlinesPerImcuRow(i); @@ -320,7 +333,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes, // Have a partial iMCU row left over to decode. if (!DecodeImcuRow()) { FinishDecode(); - return LIBYUV_FALSE; + return false; } for (int i = 0; i < num_outbufs_; ++i) { int scanlines_to_copy = @@ -333,34 +346,38 @@ LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes, return FinishDecode(); } -LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn, - void* opaque, - int dst_width, - int dst_height) { +bool MJpegDecoder::DecodeToCallback(CallbackFunction fn, + void* opaque, + int dst_width, + int dst_height) { if (dst_width != GetWidth() || dst_height > GetHeight()) { // ERROR: Bad dimensions - return LIBYUV_FALSE; + return false; } #ifdef HAVE_SETJMP if (setjmp(error_mgr_->setjmp_buffer)) { // We called into jpeglib, it experienced an error sometime during this // function call, and we called longjmp() and rewound the stack to here. // Return error. - return LIBYUV_FALSE; + return false; } #endif if (!StartDecode()) { - return LIBYUV_FALSE; + return false; } SetScanlinePointers(databuf_); int lines_left = dst_height; - // TODO(fbarchard): Compute amount of lines to skip to implement vertical crop + // Compute amount of lines to skip to implement vertical crop. + // Round skip down to a multiple of the maximum vertical sampling factor so + // that every component skips a whole number of rows. The rows remaining + // below the crop are still >= dst_height. int skip = (GetHeight() - dst_height) / 2; + skip -= skip % decompress_struct_->max_v_samp_factor; if (skip > 0) { while (skip >= GetImageScanlinesPerImcuRow()) { if (!DecodeImcuRow()) { FinishDecode(); - return LIBYUV_FALSE; + return false; } skip -= GetImageScanlinesPerImcuRow(); } @@ -368,10 +385,9 @@ LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn, // Have a partial iMCU row left over to skip. if (!DecodeImcuRow()) { FinishDecode(); - return LIBYUV_FALSE; + return false; } for (int i = 0; i < num_outbufs_; ++i) { - // TODO(fbarchard): Compute skip to avoid this assert(skip % GetVertSubSampFactor(i) == 0); int rows_to_skip = DivideAndRoundDown(skip, GetVertSubSampFactor(i)); int data_to_skip = rows_to_skip * GetComponentStride(i); @@ -379,7 +395,11 @@ LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn, // callback. databuf_[i] += data_to_skip; } + // Image lines wanted from this iMCU row, clamped to the destination. int scanlines_to_copy = GetImageScanlinesPerImcuRow() - skip; + if (scanlines_to_copy > lines_left) { + scanlines_to_copy = lines_left; + } (*fn)(opaque, databuf_, databuf_strides_, scanlines_to_copy); // Now change them back. for (int i = 0; i < num_outbufs_; ++i) { @@ -395,7 +415,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn, lines_left -= GetImageScanlinesPerImcuRow()) { if (!DecodeImcuRow()) { FinishDecode(); - return LIBYUV_FALSE; + return false; } (*fn)(opaque, databuf_, databuf_strides_, GetImageScanlinesPerImcuRow()); } @@ -403,7 +423,7 @@ LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn, // Have a partial iMCU row left over to decode. if (!DecodeImcuRow()) { FinishDecode(); - return LIBYUV_FALSE; + return false; } (*fn)(opaque, databuf_, databuf_strides_, lines_left); } @@ -417,7 +437,6 @@ void init_source(j_decompress_ptr cinfo) { boolean fill_input_buffer(j_decompress_ptr cinfo) { BufferVector* buf_vec = reinterpret_cast(cinfo->client_data); if (buf_vec->pos >= buf_vec->len) { - assert(0 && "No more data"); // ERROR: No more data return FALSE; } @@ -429,7 +448,7 @@ boolean fill_input_buffer(j_decompress_ptr cinfo) { void skip_input_data(j_decompress_ptr cinfo, long num_bytes) { // NOLINT jpeg_source_mgr* src = cinfo->src; - size_t bytes = static_cast(num_bytes); + size_t bytes = (size_t)num_bytes; if (bytes > src->bytes_in_buffer) { src->next_input_byte = nullptr; src->bytes_in_buffer = 0; @@ -478,17 +497,11 @@ void MJpegDecoder::AllocOutputBuffers(int num_outbufs) { // it. DestroyOutputBuffers(); - scanlines_ = new uint8_t**[num_outbufs]; - scanlines_sizes_ = new int[num_outbufs]; - databuf_ = new uint8_t*[num_outbufs]; - databuf_strides_ = new int[num_outbufs]; - - for (int i = 0; i < num_outbufs; ++i) { - scanlines_[i] = NULL; - scanlines_sizes_[i] = 0; - databuf_[i] = NULL; - databuf_strides_[i] = 0; - } + scanlines_ = + static_cast(calloc(num_outbufs, sizeof(uint8_t**))); + scanlines_sizes_ = static_cast(calloc(num_outbufs, sizeof(int))); + databuf_ = static_cast(calloc(num_outbufs, sizeof(uint8_t*))); + databuf_strides_ = static_cast(calloc(num_outbufs, sizeof(int))); num_outbufs_ = num_outbufs; } @@ -496,13 +509,13 @@ void MJpegDecoder::AllocOutputBuffers(int num_outbufs) { void MJpegDecoder::DestroyOutputBuffers() { for (int i = 0; i < num_outbufs_; ++i) { - delete[] scanlines_[i]; - delete[] databuf_[i]; + free(scanlines_[i]); + free(databuf_[i]); } - delete[] scanlines_; - delete[] databuf_; - delete[] scanlines_sizes_; - delete[] databuf_strides_; + free(scanlines_); + free(databuf_); + free(scanlines_sizes_); + free(databuf_strides_); scanlines_ = NULL; databuf_ = NULL; scanlines_sizes_ = NULL; @@ -511,29 +524,29 @@ void MJpegDecoder::DestroyOutputBuffers() { } // JDCT_IFAST and do_block_smoothing improve performance substantially. -LIBYUV_BOOL MJpegDecoder::StartDecode() { +bool MJpegDecoder::StartDecode() { decompress_struct_->raw_data_out = TRUE; decompress_struct_->dct_method = JDCT_IFAST; // JDCT_ISLOW is default decompress_struct_->dither_mode = JDITHER_NONE; // Not applicable to 'raw': - decompress_struct_->do_fancy_upsampling = (boolean)(LIBYUV_FALSE); + decompress_struct_->do_fancy_upsampling = (boolean)(0); // Only for buffered mode: - decompress_struct_->enable_2pass_quant = (boolean)(LIBYUV_FALSE); + decompress_struct_->enable_2pass_quant = (boolean)(0); // Blocky but fast: - decompress_struct_->do_block_smoothing = (boolean)(LIBYUV_FALSE); + decompress_struct_->do_block_smoothing = (boolean)(0); if (!jpeg_start_decompress(decompress_struct_)) { // ERROR: Couldn't start JPEG decompressor"; - return LIBYUV_FALSE; + return false; } - return LIBYUV_TRUE; + return true; } -LIBYUV_BOOL MJpegDecoder::FinishDecode() { +bool MJpegDecoder::FinishDecode() { // jpeglib considers it an error if we finish without decoding the whole // image, so we call "abort" rather than "finish". jpeg_abort_decompress(decompress_struct_); - return LIBYUV_TRUE; + return true; } void MJpegDecoder::SetScanlinePointers(uint8_t** data) { @@ -546,7 +559,7 @@ void MJpegDecoder::SetScanlinePointers(uint8_t** data) { } } -inline LIBYUV_BOOL MJpegDecoder::DecodeImcuRow() { +inline bool MJpegDecoder::DecodeImcuRow() { return (unsigned int)(GetImageScanlinesPerImcuRow()) == jpeg_read_raw_data(decompress_struct_, scanlines_, GetImageScanlinesPerImcuRow()); diff --git a/libs/libyuv/source/mjpeg_validate.cc b/libs/libyuv/source/mjpeg_validate.cc index ba0a03ab9e..91d62ecd54 100644 --- a/libs/libyuv/source/mjpeg_validate.cc +++ b/libs/libyuv/source/mjpeg_validate.cc @@ -18,7 +18,7 @@ extern "C" { #endif // Helper function to scan for EOI marker (0xff 0xd9). -static LIBYUV_BOOL ScanEOI(const uint8_t* src_mjpg, size_t src_size_mjpg) { +static int ScanEOI(const uint8_t* src_mjpg, size_t src_size_mjpg) { if (src_size_mjpg >= 2) { const uint8_t* end = src_mjpg + src_size_mjpg - 1; const uint8_t* it = src_mjpg; @@ -29,34 +29,34 @@ static LIBYUV_BOOL ScanEOI(const uint8_t* src_mjpg, size_t src_size_mjpg) { break; } if (it[1] == 0xd9) { - return LIBYUV_TRUE; // Success: Valid jpeg. + return 1; // Success: Valid jpeg. } ++it; // Skip over current 0xff. } } // ERROR: Invalid jpeg end code not found. Size src_size_mjpg - return LIBYUV_FALSE; + return 0; } // Helper function to validate the jpeg appears intact. -LIBYUV_BOOL ValidateJpeg(const uint8_t* src_mjpg, size_t src_size_mjpg) { +int ValidateJpeg(const uint8_t* src_mjpg, size_t src_size_mjpg) { // Maximum size that ValidateJpeg will consider valid. const size_t kMaxJpegSize = 0x7fffffffull; const size_t kBackSearchSize = 1024; if (src_size_mjpg < 64 || src_size_mjpg > kMaxJpegSize || !src_mjpg) { // ERROR: Invalid jpeg size: src_size_mjpg - return LIBYUV_FALSE; + return 0; } // SOI marker if (src_mjpg[0] != 0xff || src_mjpg[1] != 0xd8 || src_mjpg[2] != 0xff) { // ERROR: Invalid jpeg initial start code - return LIBYUV_FALSE; + return 0; } // Look for the End Of Image (EOI) marker near the end of the buffer. if (src_size_mjpg > kBackSearchSize) { if (ScanEOI(src_mjpg + src_size_mjpg - kBackSearchSize, kBackSearchSize)) { - return LIBYUV_TRUE; // Success: Valid jpeg. + return 1; // Success: Valid jpeg. } // Reduce search size for forward search. src_size_mjpg = src_size_mjpg - kBackSearchSize + 1; diff --git a/libs/libyuv/source/planar_functions.cc b/libs/libyuv/source/planar_functions.cc index c07f0943d3..c307644908 100644 --- a/libs/libyuv/source/planar_functions.cc +++ b/libs/libyuv/source/planar_functions.cc @@ -10,12 +10,12 @@ #include "libyuv/planar_functions.h" +#include +#include #include // for memset() +#include "libyuv/convert_from_argb.h" // For ArgbConstants #include "libyuv/cpu_id.h" -#ifdef HAVE_JPEG -#include "libyuv/mjpeg_decoder.h" -#endif #include "libyuv/row.h" #include "libyuv/scale_row.h" // for ScaleRowDown2 @@ -34,14 +34,18 @@ void CopyPlane(const uint8_t* src_y, int height) { int y; void (*CopyRow)(const uint8_t* src, uint8_t* dst, int width) = CopyRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows. - if (src_stride_y == width && dst_stride_y == width) { + if (src_stride_y == width && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = dst_stride_y = 0; @@ -61,6 +65,11 @@ void CopyPlane(const uint8_t* src_y, CopyRow = IS_ALIGNED(width, 64) ? CopyRow_AVX : CopyRow_Any_AVX; } #endif +#if defined(HAS_COPYROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + CopyRow = CopyRow_AVX512BW; + } +#endif #if defined(HAS_COPYROW_ERMS) if (TestCpuFlag(kCpuHasERMS)) { CopyRow = CopyRow_ERMS; @@ -71,6 +80,36 @@ void CopyPlane(const uint8_t* src_y, CopyRow = IS_ALIGNED(width, 32) ? CopyRow_NEON : CopyRow_Any_NEON; } #endif +#if defined(HAS_COPYROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + CopyRow = CopyRow_SVE2; + } +#endif +#if defined(HAS_COPYROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + CopyRow = CopyRow_SME; + } +#endif +#if defined(HAS_COPYROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + CopyRow = CopyRow_RVV; + } +#endif +#if defined(HAS_COPYROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + CopyRow = IS_ALIGNED(width, 16) ? CopyRow_LSX : CopyRow_Any_LSX; + } +#endif +#if defined(HAS_COPYROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + CopyRow = IS_ALIGNED(width, 32) ? CopyRow_LASX : CopyRow_Any_LASX; + } +#endif +#if defined(HAS_COPYROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + CopyRow = CopyRow_HVX; + } +#endif // Copy plane for (y = 0; y < height; ++y) { @@ -80,8 +119,6 @@ void CopyPlane(const uint8_t* src_y, } } -// TODO(fbarchard): Consider support for negative height. -// TODO(fbarchard): Consider stride measured in bytes. LIBYUV_API void CopyPlane_16(const uint16_t* src_y, int src_stride_y, @@ -91,25 +128,39 @@ void CopyPlane_16(const uint16_t* src_y, int height) { int y; void (*CopyRow)(const uint16_t* src, uint16_t* dst, int width) = CopyRow_16_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; + dst_stride_y = -dst_stride_y; + } // Coalesce rows. - if (src_stride_y == width && dst_stride_y == width) { + if (src_stride_y == width && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = dst_stride_y = 0; } -#if defined(HAS_COPYROW_16_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(width, 32)) { - CopyRow = CopyRow_16_SSE2; + // Nothing to do. + if (src_y == dst_y && src_stride_y == dst_stride_y) { + return; } -#endif -#if defined(HAS_COPYROW_16_ERMS) - if (TestCpuFlag(kCpuHasERMS)) { - CopyRow = CopyRow_16_ERMS; +#if defined(HAS_COPYROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + CopyRow = IS_ALIGNED(width, 32) ? CopyRow_16_AVX2 : CopyRow_16_Any_AVX2; } #endif #if defined(HAS_COPYROW_16_NEON) - if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 32)) { - CopyRow = CopyRow_16_NEON; + if (TestCpuFlag(kCpuHasNEON)) { + CopyRow = IS_ALIGNED(width, 16) ? CopyRow_16_NEON : CopyRow_16_Any_NEON; + } +#endif +#if defined(HAS_COPYROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + CopyRow = CopyRow_16_HVX; } #endif @@ -134,18 +185,35 @@ void Convert16To8Plane(const uint16_t* src_y, void (*Convert16To8Row)(const uint16_t* src_y, uint8_t* dst_y, int scale, int width) = Convert16To8Row_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows. - if (src_stride_y == width && dst_stride_y == width) { + if (src_stride_y == width && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = dst_stride_y = 0; } +#if defined(HAS_CONVERT16TO8ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Convert16To8Row = Convert16To8Row_Any_NEON; + if (IS_ALIGNED(width, 16)) { + Convert16To8Row = Convert16To8Row_NEON; + } + } +#endif +#if defined(HAS_CONVERT16TO8ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Convert16To8Row = Convert16To8Row_SME; + } +#endif #if defined(HAS_CONVERT16TO8ROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { Convert16To8Row = Convert16To8Row_Any_SSSE3; @@ -162,6 +230,16 @@ void Convert16To8Plane(const uint16_t* src_y, } } #endif +#if defined(HAS_CONVERT16TO8ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Convert16To8Row = Convert16To8Row_AVX512BW; + } +#endif +#if defined(HAS_CONVERT16TO8ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Convert16To8Row = Convert16To8Row_HVX; + } +#endif // Convert plane for (y = 0; y < height; ++y) { @@ -173,25 +251,39 @@ void Convert16To8Plane(const uint16_t* src_y, // Convert a plane of 8 bit data to 16 bit LIBYUV_API -void Convert8To16Plane(const uint8_t* src_y, - int src_stride_y, - uint16_t* dst_y, - int dst_stride_y, - int scale, // 16384 for 10 bits - int width, - int height) { +void Convert8To16Plane( + const uint8_t* src_y, + int src_stride_y, + uint16_t* dst_y, + int dst_stride_y, + int bits, // 10, 12, 16 bits (or 1024, 4096, 65536 scale) + int width, + int height) { int y; - void (*Convert8To16Row)(const uint8_t* src_y, uint16_t* dst_y, int scale, + void (*Convert8To16Row)(const uint8_t* src_y, uint16_t* dst_y, int bits, int width) = Convert8To16Row_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Convert legacy scale to bits if needed. + if (bits > 16) { + int b = 0; + while (bits > 1) { + bits >>= 1; + ++b; + } + bits = b; + } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows. - if (src_stride_y == width && dst_stride_y == width) { + if (src_stride_y == width && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = dst_stride_y = 0; @@ -212,10 +304,121 @@ void Convert8To16Plane(const uint8_t* src_y, } } #endif +#if defined(HAS_CONVERT8TO16ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Convert8To16Row = Convert8To16Row_AVX512BW; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Convert8To16Row = Convert8To16Row_Any_NEON; + if (IS_ALIGNED(width, 16)) { + Convert8To16Row = Convert8To16Row_NEON; + } + } +#endif +#if defined(HAS_CONVERT8TO16ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Convert8To16Row = Convert8To16Row_SME; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + Convert8To16Row = Convert8To16Row_RVV; + } +#endif +#if defined(HAS_CONVERT8TO16ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + Convert8To16Row = Convert8To16Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + Convert8To16Row = Convert8To16Row_WASMSIMD; + } + } +#endif +#if defined(HAS_CONVERT8TO16ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Convert8To16Row = Convert8To16Row_HVX; + } +#endif // Convert plane for (y = 0; y < height; ++y) { - Convert8To16Row(src_y, dst_y, scale, width); + Convert8To16Row(src_y, dst_y, bits, width); + src_y += src_stride_y; + dst_y += dst_stride_y; + } +} + +// Convert a plane of 8 bit data to 8 bit +LIBYUV_API +void Convert8To8Plane(const uint8_t* src_y, + int src_stride_y, + uint8_t* dst_y, + int dst_stride_y, + int scale, // 220 for Y, 225 to UV + int bias, // 16 + int width, + int height) { + int y; + void (*Convert8To8Row)(const uint8_t* src_y, uint8_t* dst_y, int scale, + int bias, int width) = Convert8To8Row_C; + + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; + dst_stride_y = -dst_stride_y; + } + // Coalesce rows. + if (src_stride_y == width && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = dst_stride_y = 0; + } +#if defined(HAS_CONVERT8TO8ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + Convert8To8Row = Convert8To8Row_Any_NEON; + if (IS_ALIGNED(width, 32)) { + Convert8To8Row = Convert8To8Row_NEON; + } + } +#endif +#if defined(HAS_CONVERT8TO8ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + Convert8To8Row = Convert8To8Row_SVE2; + } +#endif +#if defined(HAS_CONVERT8TO8ROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + Convert8To8Row = Convert8To8Row_SME; + } +#endif +#if defined(HAS_CONVERT8TO8ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + Convert8To8Row = Convert8To8Row_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + Convert8To8Row = Convert8To8Row_AVX2; + } + } +#endif +#if defined(HAS_CONVERT8TO8ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + Convert8To8Row = Convert8To8Row_AVX512BW; + } +#endif +#if defined(HAS_CONVERT8TO8ROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + Convert8To8Row = Convert8To8Row_HVX; + } +#endif + + // Convert plane + for (y = 0; y < height; ++y) { + Convert8To8Row(src_y, dst_y, scale, bias, width); src_y += src_stride_y; dst_y += dst_stride_y; } @@ -238,15 +441,18 @@ int I422Copy(const uint8_t* src_y, int width, int height) { int halfwidth = (width + 1) >> 1; - if (!src_u || !src_v || !dst_u || !dst_v || width <= 0 || height == 0) { + + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } + // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -276,15 +482,16 @@ int I444Copy(const uint8_t* src_y, int dst_stride_v, int width, int height) { - if (!src_u || !src_v || !dst_u || !dst_v || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -298,6 +505,88 @@ int I444Copy(const uint8_t* src_y, return 0; } +// Copy I210. +LIBYUV_API +int I210Copy(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + int halfwidth = (width + 1) >> 1; + + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + + if (dst_y) { + CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + // Copy UV planes. + CopyPlane_16(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, height); + CopyPlane_16(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, height); + return 0; +} + +// Copy I410. +LIBYUV_API +int I410Copy(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height) { + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + + if (dst_y) { + CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + CopyPlane_16(src_u, src_stride_u, dst_u, dst_stride_u, width, height); + CopyPlane_16(src_v, src_stride_v, dst_v, dst_stride_v, width, height); + return 0; +} + // Copy I400. LIBYUV_API int I400ToI400(const uint8_t* src_y, @@ -306,13 +595,13 @@ int I400ToI400(const uint8_t* src_y, int dst_stride_y, int width, int height) { - if (!src_y || !dst_y || width <= 0 || height == 0) { + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); @@ -335,13 +624,13 @@ int I420ToI400(const uint8_t* src_y, (void)src_stride_u; (void)src_v; (void)src_stride_v; - if (!src_y || !dst_y || width <= 0 || height == 0) { + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } @@ -349,6 +638,57 @@ int I420ToI400(const uint8_t* src_y, return 0; } +// Copy NV12. Supports inverting. +LIBYUV_API +int NV12Copy(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + int halfwidth = (width + 1) >> 1; + int halfheight = (height + 1) >> 1; + + if (!src_y || !dst_y || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_uv = src_uv + (ptrdiff_t)(halfheight - 1) * src_stride_uv; + src_stride_y = -src_stride_y; + src_stride_uv = -src_stride_uv; + } + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + CopyPlane(src_uv, src_stride_uv, dst_uv, dst_stride_uv, halfwidth * 2, + halfheight); + return 0; +} + +// Copy NV21. Supports inverting. +LIBYUV_API +int NV21Copy(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_vu, + int src_stride_vu, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + int width, + int height) { + return NV12Copy(src_y, src_stride_y, src_vu, src_stride_vu, dst_y, + dst_stride_y, dst_vu, dst_stride_vu, width, height); +} + // Support function for NV12 etc UV channels. // Width and height are plane sizes (typically half pixel width). LIBYUV_API @@ -363,17 +703,20 @@ void SplitUVPlane(const uint8_t* src_uv, int y; void (*SplitUVRow)(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, int width) = SplitUVRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - dst_u = dst_u + (height - 1) * dst_stride_u; - dst_v = dst_v + (height - 1) * dst_stride_v; + dst_u = dst_u + (ptrdiff_t)(height - 1) * dst_stride_u; + dst_v = dst_v + (ptrdiff_t)(height - 1) * dst_stride_v; dst_stride_u = -dst_stride_u; dst_stride_v = -dst_stride_v; } // Coalesce rows. if (src_stride_uv == width * 2 && dst_stride_u == width && - dst_stride_v == width) { + dst_stride_v == width && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_uv = dst_stride_u = dst_stride_v = 0; @@ -394,6 +737,11 @@ void SplitUVPlane(const uint8_t* src_uv, } } #endif +#if defined(HAS_SPLITUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + SplitUVRow = SplitUVRow_AVX512BW; + } +#endif #if defined(HAS_SPLITUVROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { SplitUVRow = SplitUVRow_Any_NEON; @@ -402,22 +750,37 @@ void SplitUVPlane(const uint8_t* src_uv, } } #endif -#if defined(HAS_SPLITUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - SplitUVRow = SplitUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - SplitUVRow = SplitUVRow_MSA; +#if defined(HAS_SPLITUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + SplitUVRow = SplitUVRow_SVE2; + } +#endif +#if defined(HAS_SPLITUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + SplitUVRow = SplitUVRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + SplitUVRow = SplitUVRow_LSX; } } #endif -#if defined(HAS_SPLITUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - SplitUVRow = SplitUVRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - SplitUVRow = SplitUVRow_MMI; +#if defined(HAS_SPLITUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + SplitUVRow = SplitUVRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + SplitUVRow = SplitUVRow_LASX; } } #endif +#if defined(HAS_SPLITUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SplitUVRow = SplitUVRow_RVV; + } +#endif +#if defined(HAS_SPLITUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SplitUVRow = SplitUVRow_HVX; + } +#endif for (y = 0; y < height; ++y) { // Copy a row of UV. @@ -440,15 +803,18 @@ void MergeUVPlane(const uint8_t* src_u, int y; void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width) = MergeUVRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - dst_uv = dst_uv + (height - 1) * dst_stride_uv; + dst_uv = dst_uv + (ptrdiff_t)(height - 1) * dst_stride_uv; dst_stride_uv = -dst_stride_uv; } // Coalesce rows. if (src_stride_u == width && src_stride_v == width && - dst_stride_uv == width * 2) { + dst_stride_uv == width * 2 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_u = src_stride_v = dst_stride_uv = 0; @@ -464,11 +830,16 @@ void MergeUVPlane(const uint8_t* src_u, #if defined(HAS_MERGEUVROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { MergeUVRow = MergeUVRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { + if (IS_ALIGNED(width, 16)) { MergeUVRow = MergeUVRow_AVX2; } } #endif +#if defined(HAS_MERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow = MergeUVRow_AVX512BW; + } +#endif #if defined(HAS_MERGEUVROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { MergeUVRow = MergeUVRow_Any_NEON; @@ -477,22 +848,50 @@ void MergeUVPlane(const uint8_t* src_u, } } #endif -#if defined(HAS_MERGEUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - MergeUVRow = MergeUVRow_Any_MSA; +#if defined(HAS_MERGEUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + MergeUVRow = MergeUVRow_SVE2; + } +#endif +#if defined(HAS_MERGEUVROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow = MergeUVRow_SME; + } +#endif +#if defined(HAS_MERGEUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MergeUVRow = MergeUVRow_Any_LSX; if (IS_ALIGNED(width, 16)) { - MergeUVRow = MergeUVRow_MSA; + MergeUVRow = MergeUVRow_LSX; } } #endif -#if defined(HAS_MERGEUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - MergeUVRow = MergeUVRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - MergeUVRow = MergeUVRow_MMI; +#if defined(HAS_MERGEUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MergeUVRow = MergeUVRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + MergeUVRow = MergeUVRow_LASX; } } #endif +#if defined(HAS_MERGEUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeUVRow = MergeUVRow_RVV; + } +#endif +#if defined(HAS_MERGEUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MergeUVRow = MergeUVRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + MergeUVRow = MergeUVRow_WASMSIMD; + } + } +#endif +#if defined(HAS_MERGEUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow = MergeUVRow_HVX; + } +#endif for (y = 0; y < height; ++y) { // Merge a row of U and V into a row of UV. @@ -503,6 +902,295 @@ void MergeUVPlane(const uint8_t* src_u, } } +// Support function for P010 etc UV channels. +// Width and height are plane sizes (typically half pixel width). +LIBYUV_API +void SplitUVPlane_16(const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height, + int depth) { + int y; + void (*SplitUVRow_16)(const uint16_t* src_uv, uint16_t* dst_u, + uint16_t* dst_v, int depth, int width) = + SplitUVRow_16_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_u = dst_u + (ptrdiff_t)(height - 1) * dst_stride_u; + dst_v = dst_v + (ptrdiff_t)(height - 1) * dst_stride_v; + dst_stride_u = -dst_stride_u; + dst_stride_v = -dst_stride_v; + } + // Coalesce rows. + if (src_stride_uv == width * 2 && dst_stride_u == width && + dst_stride_v == width && (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_uv = dst_stride_u = dst_stride_v = 0; + } +#if defined(HAS_SPLITUVROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SplitUVRow_16 = SplitUVRow_16_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + SplitUVRow_16 = SplitUVRow_16_AVX2; + } + } +#endif +#if defined(HAS_SPLITUVROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + SplitUVRow_16 = SplitUVRow_16_Any_NEON; + if (IS_ALIGNED(width, 8)) { + SplitUVRow_16 = SplitUVRow_16_NEON; + } + } +#endif +#if defined(HAS_SPLITUVROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SplitUVRow_16 = SplitUVRow_16_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + // Copy a row of UV. + SplitUVRow_16(src_uv, dst_u, dst_v, depth, width); + dst_u += dst_stride_u; + dst_v += dst_stride_v; + src_uv += src_stride_uv; + } +} + +LIBYUV_API +void MergeUVPlane_16(const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height, + int depth) { + int y; + void (*MergeUVRow_16)(const uint16_t* src_u, const uint16_t* src_v, + uint16_t* dst_uv, int depth, int width) = + MergeUVRow_16_C; + assert(depth >= 8); + assert(depth <= 16); + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_uv = dst_uv + (ptrdiff_t)(height - 1) * dst_stride_uv; + dst_stride_uv = -dst_stride_uv; + } + // Coalesce rows. + if (src_stride_u == width && src_stride_v == width && + dst_stride_uv == width * 2 && (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_u = src_stride_v = dst_stride_uv = 0; + } +#if defined(HAS_MERGEUVROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeUVRow_16 = MergeUVRow_16_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + MergeUVRow_16 = MergeUVRow_16_AVX2; + } + } +#endif +#if defined(HAS_MERGEUVROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MergeUVRow_16 = MergeUVRow_16_AVX512BW; + } +#endif +#if defined(HAS_MERGEUVROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeUVRow_16 = MergeUVRow_16_Any_NEON; + if (IS_ALIGNED(width, 8)) { + MergeUVRow_16 = MergeUVRow_16_NEON; + } + } +#endif +#if defined(HAS_MERGEUVROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + MergeUVRow_16 = MergeUVRow_16_SME; + } +#endif +#if defined(HAS_MERGEUVROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeUVRow_16 = MergeUVRow_16_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + // Merge a row of U and V into a row of UV. + MergeUVRow_16(src_u, src_v, dst_uv, depth, width); + src_u += src_stride_u; + src_v += src_stride_v; + dst_uv += dst_stride_uv; + } +} + +// Convert plane from lsb to msb +LIBYUV_API +void ConvertToMSBPlane_16(const uint16_t* src_y, + int src_stride_y, + uint16_t* dst_y, + int dst_stride_y, + int width, + int height, + int depth) { + int y; + int scale = 1 << (16 - depth); + void (*MultiplyRow_16)(const uint16_t* src_y, uint16_t* dst_y, int scale, + int width) = MultiplyRow_16_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; + dst_stride_y = -dst_stride_y; + } + // Coalesce rows. + if (src_stride_y == width && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = dst_stride_y = 0; + } + +#if defined(HAS_MULTIPLYROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MultiplyRow_16 = MultiplyRow_16_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + MultiplyRow_16 = MultiplyRow_16_AVX2; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MultiplyRow_16 = MultiplyRow_16_AVX512BW; + } +#endif +#if defined(HAS_MULTIPLYROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MultiplyRow_16 = MultiplyRow_16_Any_NEON; + if (IS_ALIGNED(width, 16)) { + MultiplyRow_16 = MultiplyRow_16_NEON; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + MultiplyRow_16 = MultiplyRow_16_SME; + } +#endif +#if defined(HAS_MULTIPLYROW_16_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MultiplyRow_16 = MultiplyRow_16_RVV; + } +#endif +#if defined(HAS_MULTIPLYROW_16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MultiplyRow_16 = MultiplyRow_16_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + MultiplyRow_16 = MultiplyRow_16_WASMSIMD; + } + } +#endif +#if defined(HAS_MULTIPLYROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MultiplyRow_16 = MultiplyRow_16_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + MultiplyRow_16(src_y, dst_y, scale, width); + src_y += src_stride_y; + dst_y += dst_stride_y; + } +} + +// Convert plane from msb to lsb +LIBYUV_API +void ConvertToLSBPlane_16(const uint16_t* src_y, + int src_stride_y, + uint16_t* dst_y, + int dst_stride_y, + int width, + int height, + int depth) { + int y; + int scale = 1 << depth; + void (*DivideRow)(const uint16_t* src_y, uint16_t* dst_y, int scale, + int width) = DivideRow_16_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; + dst_stride_y = -dst_stride_y; + } + // Coalesce rows. + if (src_stride_y == width && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_y = dst_stride_y = 0; + } + +#if defined(HAS_DIVIDEROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + DivideRow = DivideRow_16_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + DivideRow = DivideRow_16_AVX2; + } + } +#endif +#if defined(HAS_DIVIDEROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + DivideRow = DivideRow_16_AVX512BW; + } +#endif +#if defined(HAS_DIVIDEROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + DivideRow = DivideRow_16_Any_NEON; + if (IS_ALIGNED(width, 16)) { + DivideRow = DivideRow_16_NEON; + } + } +#endif +#if defined(HAS_DIVIDEROW_16_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + DivideRow = DivideRow_16_SVE2; + } +#endif +#if defined(HAS_DIVIDEROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + DivideRow = DivideRow_16_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + DivideRow(src_y, dst_y, scale, width); + src_y += src_stride_y; + dst_y += dst_stride_y; + } +} + // Swap U and V channels in interleaved UV plane. LIBYUV_API void SwapUVPlane(const uint8_t* src_uv, @@ -514,14 +1202,18 @@ void SwapUVPlane(const uint8_t* src_uv, int y; void (*SwapUVRow)(const uint8_t* src_uv, uint8_t* dst_vu, int width) = SwapUVRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_uv = src_uv + (height - 1) * src_stride_uv; + src_uv = src_uv + (ptrdiff_t)(height - 1) * src_stride_uv; src_stride_uv = -src_stride_uv; } // Coalesce rows. - if (src_stride_uv == width * 2 && dst_stride_vu == width * 2) { + if (src_stride_uv == width * 2 && dst_stride_vu == width * 2 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_uv = dst_stride_vu = 0; @@ -543,6 +1235,11 @@ void SwapUVPlane(const uint8_t* src_uv, } } #endif +#if defined(HAS_SWAPUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + SwapUVRow = SwapUVRow_AVX512BW; + } +#endif #if defined(HAS_SWAPUVROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { SwapUVRow = SwapUVRow_Any_NEON; @@ -551,6 +1248,24 @@ void SwapUVPlane(const uint8_t* src_uv, } } #endif +#if defined(HAS_SWAPUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SwapUVRow = SwapUVRow_RVV; + } +#endif +#if defined(HAS_SWAPUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + SwapUVRow = SwapUVRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + SwapUVRow = SwapUVRow_WASMSIMD; + } + } +#endif +#if defined(HAS_SWAPUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SwapUVRow = SwapUVRow_HVX; + } +#endif for (y = 0; y < height; ++y) { SwapUVRow(src_uv, dst_vu, width); @@ -559,31 +1274,296 @@ void SwapUVPlane(const uint8_t* src_uv, } } -// Convert NV21 to NV12. +// Convert NV12 to NV21. LIBYUV_API -int NV21ToNV12(const uint8_t* src_y, +int NV12ToNV21(const uint8_t* src_y, int src_stride_y, - const uint8_t* src_vu, - int src_stride_vu, + const uint8_t* src_uv, + int src_stride_uv, uint8_t* dst_y, int dst_stride_y, - uint8_t* dst_uv, - int dst_stride_uv, + uint8_t* dst_vu, + int dst_stride_vu, int width, int height) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_vu || !dst_uv || width <= 0 || height == 0) { + + if (!src_uv || !dst_vu || width <= 0 || height == 0 || height == INT_MIN) { return -1; } + if (dst_y) { CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); } - SwapUVPlane(src_vu, src_stride_vu, dst_uv, dst_stride_uv, halfwidth, + + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + src_uv = src_uv + (ptrdiff_t)(halfheight - 1) * src_stride_uv; + src_stride_uv = -src_stride_uv; + } + + SwapUVPlane(src_uv, src_stride_uv, dst_vu, dst_stride_vu, halfwidth, halfheight); return 0; } +// Test if tile_height is a power of 2 (16 or 32) +#define IS_POWEROFTWO(x) (!((x) & ((x) - 1))) + +// Detile a plane of data +// tile width is 16 and assumed. +// tile_height is 16 or 32 for MM21. +// src_stride_y is bytes per row of source ignoring tiling. e.g. 640 +// TODO: More detile row functions. +LIBYUV_API +int DetilePlane(const uint8_t* src_y, + int src_stride_y, + uint8_t* dst_y, + int dst_stride_y, + int width, + int height, + int tile_height) { + const ptrdiff_t src_tile_stride = 16 * tile_height; + int y; + void (*DetileRow)(const uint8_t* src, ptrdiff_t src_tile_stride, uint8_t* dst, + int width) = DetileRow_C; + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN || + !IS_POWEROFTWO(tile_height)) { + return -1; + } + + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; + dst_stride_y = -dst_stride_y; + } + +#if defined(HAS_DETILEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + DetileRow = DetileRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + DetileRow = DetileRow_AVX2; + } + } +#endif +#if defined(HAS_DETILEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + DetileRow = DetileRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + DetileRow = DetileRow_NEON; + } + } +#endif + + // Detile plane + for (y = 0; y < height; ++y) { + DetileRow(src_y, src_tile_stride, dst_y, width); + dst_y += dst_stride_y; + src_y += 16; + // Advance to next row of tiles. + if ((y & (tile_height - 1)) == (tile_height - 1)) { + src_y = src_y - src_tile_stride + src_stride_y * tile_height; + } + } + return 0; +} + +// Convert a plane of 16 bit tiles of 16 x H to linear. +// tile width is 16 and assumed. +// tile_height is 16 or 32 for MT2T. +LIBYUV_API +int DetilePlane_16(const uint16_t* src_y, + int src_stride_y, + uint16_t* dst_y, + int dst_stride_y, + int width, + int height, + int tile_height) { + const ptrdiff_t src_tile_stride = 16 * tile_height; + int y; + void (*DetileRow_16)(const uint16_t* src, ptrdiff_t src_tile_stride, + uint16_t* dst, int width) = DetileRow_16_C; + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN || + !IS_POWEROFTWO(tile_height)) { + return -1; + } + + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; + dst_stride_y = -dst_stride_y; + } + +#if defined(HAS_DETILEROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + DetileRow_16 = DetileRow_16_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + DetileRow_16 = DetileRow_16_AVX2; + } + } +#endif +#if defined(HAS_DETILEROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + DetileRow_16 = DetileRow_16_Any_NEON; + if (IS_ALIGNED(width, 16)) { + DetileRow_16 = DetileRow_16_NEON; + } + } +#endif + + // Detile plane + for (y = 0; y < height; ++y) { + DetileRow_16(src_y, src_tile_stride, dst_y, width); + dst_y += dst_stride_y; + src_y += 16; + // Advance to next row of tiles. + if ((y & (tile_height - 1)) == (tile_height - 1)) { + src_y = src_y - src_tile_stride + src_stride_y * tile_height; + } + } + return 0; +} + +LIBYUV_API +void DetileSplitUVPlane(const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + int tile_height) { + const ptrdiff_t src_tile_stride = 16 * tile_height; + int y; + void (*DetileSplitUVRow)(const uint8_t* src, ptrdiff_t src_tile_stride, + uint8_t* dst_u, uint8_t* dst_v, int width) = + DetileSplitUVRow_C; + assert(src_stride_uv >= 0); + assert(tile_height > 0); + assert(src_stride_uv > 0); + + // tile_height must be a power of 2 (16 or 32); the row loop below uses it as + // a bit mask. + if (width <= 0 || height == 0 || height == INT_MIN || tile_height <= 0 || + !IS_POWEROFTWO(tile_height)) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_u = dst_u + (ptrdiff_t)(height - 1) * dst_stride_u; + dst_stride_u = -dst_stride_u; + dst_v = dst_v + (ptrdiff_t)(height - 1) * dst_stride_v; + dst_stride_v = -dst_stride_v; + } + +#if defined(HAS_DETILESPLITUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + DetileSplitUVRow = DetileSplitUVRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + DetileSplitUVRow = DetileSplitUVRow_AVX2; + } + } +#endif +#if defined(HAS_DETILESPLITUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + DetileSplitUVRow = DetileSplitUVRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + DetileSplitUVRow = DetileSplitUVRow_NEON; + } + } +#endif + + // Detile plane + for (y = 0; y < height; ++y) { + DetileSplitUVRow(src_uv, src_tile_stride, dst_u, dst_v, width); + dst_u += dst_stride_u; + dst_v += dst_stride_v; + src_uv += 16; + // Advance to next row of tiles. + if ((y & (tile_height - 1)) == (tile_height - 1)) { + src_uv = src_uv - src_tile_stride + src_stride_uv * tile_height; + } + } +} + +LIBYUV_API +void DetileToYUY2(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_yuy2, + int dst_stride_yuy2, + int width, + int height, + int tile_height) { + const ptrdiff_t src_y_tile_stride = 16 * tile_height; + const ptrdiff_t src_uv_tile_stride = src_y_tile_stride / 2; + int y; + void (*DetileToYUY2)(const uint8_t* src_y, ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, int width) = DetileToYUY2_C; + assert(src_stride_y >= 0); + assert(src_stride_y > 0); + assert(src_stride_uv >= 0); + assert(src_stride_uv > 0); + assert(tile_height > 0); + + // tile_height must be a power of 2 and at least 2 (16 or 32); the row loop + // uses it as a bit mask and the UV tile is tile_height / 2 rows. + if (width <= 0 || height == 0 || height == INT_MIN || tile_height < 2 || + !IS_POWEROFTWO(tile_height)) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_yuy2 = dst_yuy2 + (ptrdiff_t)(height - 1) * dst_stride_yuy2; + dst_stride_yuy2 = -dst_stride_yuy2; + } + +#if defined(HAS_DETILETOYUY2_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + DetileToYUY2 = DetileToYUY2_Any_NEON; + if (IS_ALIGNED(width, 16)) { + DetileToYUY2 = DetileToYUY2_NEON; + } + } +#endif + +#if defined(HAS_DETILETOYUY2_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + DetileToYUY2 = DetileToYUY2_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + DetileToYUY2 = DetileToYUY2_AVX2; + } + } +#endif + + // Detile plane + for (y = 0; y < height; ++y) { + DetileToYUY2(src_y, src_y_tile_stride, src_uv, src_uv_tile_stride, dst_yuy2, + width); + dst_yuy2 += dst_stride_yuy2; + src_y += 16; + + if (y & 0x1) + src_uv += 16; + + // Advance to next row of tiles. + if ((y & (tile_height - 1)) == (tile_height - 1)) { + src_y = src_y - src_y_tile_stride + src_stride_y * tile_height; + src_uv = src_uv - src_uv_tile_stride + src_stride_uv * (tile_height / 2); + } + } +} + // Support function for NV12 etc RGB channels. // Width and height are plane sizes (typically half pixel width). LIBYUV_API @@ -600,19 +1580,23 @@ void SplitRGBPlane(const uint8_t* src_rgb, int y; void (*SplitRGBRow)(const uint8_t* src_rgb, uint8_t* dst_r, uint8_t* dst_g, uint8_t* dst_b, int width) = SplitRGBRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - dst_r = dst_r + (height - 1) * dst_stride_r; - dst_g = dst_g + (height - 1) * dst_stride_g; - dst_b = dst_b + (height - 1) * dst_stride_b; + dst_r = dst_r + (ptrdiff_t)(height - 1) * dst_stride_r; + dst_g = dst_g + (ptrdiff_t)(height - 1) * dst_stride_g; + dst_b = dst_b + (ptrdiff_t)(height - 1) * dst_stride_b; dst_stride_r = -dst_stride_r; dst_stride_g = -dst_stride_g; dst_stride_b = -dst_stride_b; } // Coalesce rows. if (src_stride_rgb == width * 3 && dst_stride_r == width && - dst_stride_g == width && dst_stride_b == width) { + dst_stride_g == width && dst_stride_b == width && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_rgb = dst_stride_r = dst_stride_g = dst_stride_b = 0; @@ -625,6 +1609,22 @@ void SplitRGBPlane(const uint8_t* src_rgb, } } #endif +#if defined(HAS_SPLITRGBROW_SSE41) + if (TestCpuFlag(kCpuHasSSE41)) { + SplitRGBRow = SplitRGBRow_Any_SSE41; + if (IS_ALIGNED(width, 16)) { + SplitRGBRow = SplitRGBRow_SSE41; + } + } +#endif +#if defined(HAS_SPLITRGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SplitRGBRow = SplitRGBRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + SplitRGBRow = SplitRGBRow_AVX2; + } + } +#endif #if defined(HAS_SPLITRGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { SplitRGBRow = SplitRGBRow_Any_NEON; @@ -633,12 +1633,9 @@ void SplitRGBPlane(const uint8_t* src_rgb, } } #endif -#if defined(HAS_SPLITRGBROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - SplitRGBRow = SplitRGBRow_Any_MMI; - if (IS_ALIGNED(width, 4)) { - SplitRGBRow = SplitRGBRow_MMI; - } +#if defined(HAS_SPLITRGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SplitRGBRow = SplitRGBRow_RVV; } #endif @@ -667,28 +1664,37 @@ void MergeRGBPlane(const uint8_t* src_r, void (*MergeRGBRow)(const uint8_t* src_r, const uint8_t* src_g, const uint8_t* src_b, uint8_t* dst_rgb, int width) = MergeRGBRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Coalesce rows. // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb = dst_rgb + (height - 1) * dst_stride_rgb; + dst_rgb = dst_rgb + (ptrdiff_t)(height - 1) * dst_stride_rgb; dst_stride_rgb = -dst_stride_rgb; } // Coalesce rows. if (src_stride_r == width && src_stride_g == width && src_stride_b == width && - dst_stride_rgb == width * 3) { + dst_stride_rgb == width * 3 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_r = src_stride_g = src_stride_b = dst_stride_rgb = 0; } -#if defined(HAS_MERGERGBROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - MergeRGBRow = MergeRGBRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - MergeRGBRow = MergeRGBRow_SSSE3; +#if defined(HAS_MERGERGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeRGBRow = MergeRGBRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + MergeRGBRow = MergeRGBRow_AVX2; } } #endif +#if defined(HAS_MERGERGBROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI | kCpuHasAVX512VL) == + (kCpuHasAVX512VBMI | kCpuHasAVX512VL)) { + MergeRGBRow = MergeRGBRow_AVX512VBMI; + } +#endif #if defined(HAS_MERGERGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { MergeRGBRow = MergeRGBRow_Any_NEON; @@ -697,12 +1703,9 @@ void MergeRGBPlane(const uint8_t* src_r, } } #endif -#if defined(HAS_MERGERGBROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - MergeRGBRow = MergeRGBRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - MergeRGBRow = MergeRGBRow_MMI; - } +#if defined(HAS_MERGERGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeRGBRow = MergeRGBRow_RVV; } #endif @@ -716,67 +1719,762 @@ void MergeRGBPlane(const uint8_t* src_r, } } -// Mirror a plane of data. -void MirrorPlane(const uint8_t* src_y, - int src_stride_y, - uint8_t* dst_y, - int dst_stride_y, - int width, - int height) { +LIBYUV_NOINLINE +static void SplitARGBPlaneAlpha(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_r, + int dst_stride_r, + uint8_t* dst_g, + int dst_stride_g, + uint8_t* dst_b, + int dst_stride_b, + uint8_t* dst_a, + int dst_stride_a, + int width, + int height) { int y; - void (*MirrorRow)(const uint8_t* src, uint8_t* dst, int width) = MirrorRow_C; + void (*SplitARGBRow)(const uint8_t* src_rgb, uint8_t* dst_r, uint8_t* dst_g, + uint8_t* dst_b, uint8_t* dst_a, int width) = + SplitARGBRow_C; + + assert(height >= 0); + + if (width <= 0 || height == 0) { + return; + } + if (src_stride_argb == width * 4 && dst_stride_r == width && + dst_stride_g == width && dst_stride_b == width && dst_stride_a == width && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_argb = dst_stride_r = dst_stride_g = dst_stride_b = + dst_stride_a = 0; + } + +#if defined(HAS_SPLITARGBROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + SplitARGBRow = SplitARGBRow_Any_SSE2; + if (IS_ALIGNED(width, 8)) { + SplitARGBRow = SplitARGBRow_SSE2; + } + } +#endif +#if defined(HAS_SPLITARGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + SplitARGBRow = SplitARGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + SplitARGBRow = SplitARGBRow_SSSE3; + } + } +#endif +#if defined(HAS_SPLITARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SplitARGBRow = SplitARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + SplitARGBRow = SplitARGBRow_AVX2; + } + } +#endif +#if defined(HAS_SPLITARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + SplitARGBRow = SplitARGBRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + SplitARGBRow = SplitARGBRow_NEON; + } + } +#endif +#if defined(HAS_SPLITARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SplitARGBRow = SplitARGBRow_RVV; + } +#endif +#if defined(HAS_SPLITARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SplitARGBRow = SplitARGBRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + SplitARGBRow(src_argb, dst_r, dst_g, dst_b, dst_a, width); + dst_r += dst_stride_r; + dst_g += dst_stride_g; + dst_b += dst_stride_b; + dst_a += dst_stride_a; + src_argb += src_stride_argb; + } +} + +LIBYUV_NOINLINE +static void SplitARGBPlaneOpaque(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_r, + int dst_stride_r, + uint8_t* dst_g, + int dst_stride_g, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height) { + int y; + void (*SplitXRGBRow)(const uint8_t* src_rgb, uint8_t* dst_r, uint8_t* dst_g, + uint8_t* dst_b, int width) = SplitXRGBRow_C; + assert(height >= 0); + + if (width <= 0 || height == 0) { + return; + } + if (src_stride_argb == width * 4 && dst_stride_r == width && + dst_stride_g == width && dst_stride_b == width && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_argb = dst_stride_r = dst_stride_g = dst_stride_b = 0; + } + +#if defined(HAS_SPLITXRGBROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + SplitXRGBRow = SplitXRGBRow_Any_SSE2; + if (IS_ALIGNED(width, 8)) { + SplitXRGBRow = SplitXRGBRow_SSE2; + } + } +#endif +#if defined(HAS_SPLITXRGBROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + SplitXRGBRow = SplitXRGBRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + SplitXRGBRow = SplitXRGBRow_SSSE3; + } + } +#endif +#if defined(HAS_SPLITXRGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SplitXRGBRow = SplitXRGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + SplitXRGBRow = SplitXRGBRow_AVX2; + } + } +#endif +#if defined(HAS_SPLITXRGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + SplitXRGBRow = SplitXRGBRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + SplitXRGBRow = SplitXRGBRow_NEON; + } + } +#endif +#if defined(HAS_SPLITXRGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SplitXRGBRow = SplitXRGBRow_RVV; + } +#endif +#if defined(HAS_SPLITXRGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SplitXRGBRow = SplitXRGBRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + SplitXRGBRow(src_argb, dst_r, dst_g, dst_b, width); + dst_r += dst_stride_r; + dst_g += dst_stride_g; + dst_b += dst_stride_b; + src_argb += src_stride_argb; + } +} + +LIBYUV_API +void SplitARGBPlane(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_r, + int dst_stride_r, + uint8_t* dst_g, + int dst_stride_g, + uint8_t* dst_b, + int dst_stride_b, + uint8_t* dst_a, + int dst_stride_a, + int width, + int height) { + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_stride_y = -src_stride_y; - } -#if defined(HAS_MIRRORROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - MirrorRow = MirrorRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { - MirrorRow = MirrorRow_NEON; + dst_r = dst_r + (ptrdiff_t)(height - 1) * dst_stride_r; + dst_g = dst_g + (ptrdiff_t)(height - 1) * dst_stride_g; + dst_b = dst_b + (ptrdiff_t)(height - 1) * dst_stride_b; + dst_stride_r = -dst_stride_r; + dst_stride_g = -dst_stride_g; + dst_stride_b = -dst_stride_b; + if (dst_a) { + dst_a = dst_a + (ptrdiff_t)(height - 1) * dst_stride_a; + dst_stride_a = -dst_stride_a; } } -#endif -#if defined(HAS_MIRRORROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - MirrorRow = MirrorRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - MirrorRow = MirrorRow_SSSE3; - } + + if (dst_a == NULL) { + SplitARGBPlaneOpaque(src_argb, src_stride_argb, dst_r, dst_stride_r, dst_g, + dst_stride_g, dst_b, dst_stride_b, width, height); + } else { + SplitARGBPlaneAlpha(src_argb, src_stride_argb, dst_r, dst_stride_r, dst_g, + dst_stride_g, dst_b, dst_stride_b, dst_a, dst_stride_a, + width, height); } -#endif -#if defined(HAS_MIRRORROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - MirrorRow = MirrorRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { - MirrorRow = MirrorRow_AVX2; - } +} + +LIBYUV_NOINLINE +static void MergeARGBPlaneAlpha(const uint8_t* src_r, + int src_stride_r, + const uint8_t* src_g, + int src_stride_g, + const uint8_t* src_b, + int src_stride_b, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + int y; + void (*MergeARGBRow)(const uint8_t* src_r, const uint8_t* src_g, + const uint8_t* src_b, const uint8_t* src_a, + uint8_t* dst_argb, int width) = MergeARGBRow_C; + + assert(height >= 0); + + if (width <= 0 || height == 0) { + return; } -#endif -#if defined(HAS_MIRRORROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - MirrorRow = MirrorRow_Any_MSA; - if (IS_ALIGNED(width, 64)) { - MirrorRow = MirrorRow_MSA; - } + if (src_stride_r == width && src_stride_g == width && src_stride_b == width && + src_stride_a == width && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_r = src_stride_g = src_stride_b = src_stride_a = + dst_stride_argb = 0; } -#endif -#if defined(HAS_MIRRORROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - MirrorRow = MirrorRow_Any_MMI; +#if defined(HAS_MERGEARGBROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + MergeARGBRow = MergeARGBRow_Any_SSE2; if (IS_ALIGNED(width, 8)) { - MirrorRow = MirrorRow_MMI; + MergeARGBRow = MergeARGBRow_SSE2; + } + } +#endif +#if defined(HAS_MERGEARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeARGBRow = MergeARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + MergeARGBRow = MergeARGBRow_AVX2; + } + } +#endif +#if defined(HAS_MERGEARGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeARGBRow = MergeARGBRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + MergeARGBRow = MergeARGBRow_NEON; + } + } +#endif +#if defined(HAS_MERGEARGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeARGBRow = MergeARGBRow_RVV; + } +#endif +#if defined(HAS_MERGEARGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeARGBRow = MergeARGBRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + MergeARGBRow(src_r, src_g, src_b, src_a, dst_argb, width); + src_r += src_stride_r; + src_g += src_stride_g; + src_b += src_stride_b; + src_a += src_stride_a; + dst_argb += dst_stride_argb; + } +} + +LIBYUV_NOINLINE +static void MergeARGBPlaneOpaque(const uint8_t* src_r, + int src_stride_r, + const uint8_t* src_g, + int src_stride_g, + const uint8_t* src_b, + int src_stride_b, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + int y; + void (*MergeXRGBRow)(const uint8_t* src_r, const uint8_t* src_g, + const uint8_t* src_b, uint8_t* dst_argb, int width) = + MergeXRGBRow_C; + + assert(height >= 0); + + if (width <= 0 || height == 0) { + return; + } + if (src_stride_r == width && src_stride_g == width && src_stride_b == width && + dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_r = src_stride_g = src_stride_b = dst_stride_argb = 0; + } +#if defined(HAS_MERGEXRGBROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + MergeXRGBRow = MergeXRGBRow_Any_SSE2; + if (IS_ALIGNED(width, 8)) { + MergeXRGBRow = MergeXRGBRow_SSE2; + } + } +#endif +#if defined(HAS_MERGEXRGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeXRGBRow = MergeXRGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + MergeXRGBRow = MergeXRGBRow_AVX2; + } + } +#endif +#if defined(HAS_MERGEXRGBROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeXRGBRow = MergeXRGBRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + MergeXRGBRow = MergeXRGBRow_NEON; + } + } +#endif +#if defined(HAS_MERGEXRGBROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MergeXRGBRow = MergeXRGBRow_RVV; + } +#endif +#if defined(HAS_MERGEXRGBROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MergeXRGBRow = MergeXRGBRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + MergeXRGBRow(src_r, src_g, src_b, dst_argb, width); + src_r += src_stride_r; + src_g += src_stride_g; + src_b += src_stride_b; + dst_argb += dst_stride_argb; + } +} + +LIBYUV_API +void MergeARGBPlane(const uint8_t* src_r, + int src_stride_r, + const uint8_t* src_g, + int src_stride_g, + const uint8_t* src_b, + int src_stride_b, + const uint8_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } + + if (src_a == NULL) { + MergeARGBPlaneOpaque(src_r, src_stride_r, src_g, src_stride_g, src_b, + src_stride_b, dst_argb, dst_stride_argb, width, + height); + } else { + MergeARGBPlaneAlpha(src_r, src_stride_r, src_g, src_stride_g, src_b, + src_stride_b, src_a, src_stride_a, dst_argb, + dst_stride_argb, width, height); + } +} + +// TODO(yuan): Support 2 bit alpha channel. +LIBYUV_API +void MergeXR30Plane(const uint16_t* src_r, + int src_stride_r, + const uint16_t* src_g, + int src_stride_g, + const uint16_t* src_b, + int src_stride_b, + uint8_t* dst_ar30, + int dst_stride_ar30, + int width, + int height, + int depth) { + int y; + void (*MergeXR30Row)(const uint16_t* src_r, const uint16_t* src_g, + const uint16_t* src_b, uint8_t* dst_ar30, int depth, + int width) = MergeXR30Row_C; + + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; + dst_stride_ar30 = -dst_stride_ar30; + } + // Coalesce rows. + if (src_stride_r == width && src_stride_g == width && src_stride_b == width && + dst_stride_ar30 == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_r = src_stride_g = src_stride_b = dst_stride_ar30 = 0; + } +#if defined(HAS_MERGEXR30ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeXR30Row = MergeXR30Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + MergeXR30Row = MergeXR30Row_AVX2; + } + } +#endif +#if defined(HAS_MERGEXR30ROW_10_AVX512BW) + if (depth == 10 && TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) == + (kCpuHasAVX512BW | kCpuHasAVX512VL)) { + MergeXR30Row = MergeXR30Row_10_AVX512BW; + } +#endif +#if defined(HAS_MERGEXR30ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + if (depth == 10) { + MergeXR30Row = MergeXR30Row_10_Any_NEON; + if (IS_ALIGNED(width, 8)) { + MergeXR30Row = MergeXR30Row_10_NEON; + } + } else { + MergeXR30Row = MergeXR30Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + MergeXR30Row = MergeXR30Row_NEON; + } } } #endif - // Mirror plane for (y = 0; y < height; ++y) { - MirrorRow(src_y, dst_y, width); - src_y += src_stride_y; - dst_y += dst_stride_y; + MergeXR30Row(src_r, src_g, src_b, dst_ar30, depth, width); + src_r += src_stride_r; + src_g += src_stride_g; + src_b += src_stride_b; + dst_ar30 += dst_stride_ar30; + } +} + +LIBYUV_NOINLINE +static void MergeAR64PlaneAlpha(const uint16_t* src_r, + int src_stride_r, + const uint16_t* src_g, + int src_stride_g, + const uint16_t* src_b, + int src_stride_b, + const uint16_t* src_a, + int src_stride_a, + uint16_t* dst_ar64, + int dst_stride_ar64, + int width, + int height, + int depth) { + int y; + void (*MergeAR64Row)(const uint16_t* src_r, const uint16_t* src_g, + const uint16_t* src_b, const uint16_t* src_a, + uint16_t* dst_argb, int depth, int width) = + MergeAR64Row_C; + + assert(height >= 0); + + if (width <= 0 || height == 0) { + return; + } + if (src_stride_r == width && src_stride_g == width && src_stride_b == width && + src_stride_a == width && dst_stride_ar64 == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_r = src_stride_g = src_stride_b = src_stride_a = + dst_stride_ar64 = 0; + } +#if defined(HAS_MERGEAR64ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeAR64Row = MergeAR64Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + MergeAR64Row = MergeAR64Row_AVX2; + } + } +#endif +#if defined(HAS_MERGEAR64ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeAR64Row = MergeAR64Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + MergeAR64Row = MergeAR64Row_NEON; + } + } +#endif + + for (y = 0; y < height; ++y) { + MergeAR64Row(src_r, src_g, src_b, src_a, dst_ar64, depth, width); + src_r += src_stride_r; + src_g += src_stride_g; + src_b += src_stride_b; + src_a += src_stride_a; + dst_ar64 += dst_stride_ar64; + } +} + +LIBYUV_NOINLINE +static void MergeAR64PlaneOpaque(const uint16_t* src_r, + int src_stride_r, + const uint16_t* src_g, + int src_stride_g, + const uint16_t* src_b, + int src_stride_b, + uint16_t* dst_ar64, + int dst_stride_ar64, + int width, + int height, + int depth) { + int y; + void (*MergeXR64Row)(const uint16_t* src_r, const uint16_t* src_g, + const uint16_t* src_b, uint16_t* dst_argb, int depth, + int width) = MergeXR64Row_C; + + assert(height >= 0); + + if (width <= 0 || height == 0) { + return; + } + // Coalesce rows. + if (src_stride_r == width && src_stride_g == width && src_stride_b == width && + dst_stride_ar64 == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_r = src_stride_g = src_stride_b = dst_stride_ar64 = 0; + } +#if defined(HAS_MERGEXR64ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeXR64Row = MergeXR64Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + MergeXR64Row = MergeXR64Row_AVX2; + } + } +#endif +#if defined(HAS_MERGEXR64ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeXR64Row = MergeXR64Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + MergeXR64Row = MergeXR64Row_NEON; + } + } +#endif + + for (y = 0; y < height; ++y) { + MergeXR64Row(src_r, src_g, src_b, dst_ar64, depth, width); + src_r += src_stride_r; + src_g += src_stride_g; + src_b += src_stride_b; + dst_ar64 += dst_stride_ar64; + } +} + +LIBYUV_API +void MergeAR64Plane(const uint16_t* src_r, + int src_stride_r, + const uint16_t* src_g, + int src_stride_g, + const uint16_t* src_b, + int src_stride_b, + const uint16_t* src_a, + int src_stride_a, + uint16_t* dst_ar64, + int dst_stride_ar64, + int width, + int height, + int depth) { + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_ar64 = dst_ar64 + (ptrdiff_t)(height - 1) * dst_stride_ar64; + dst_stride_ar64 = -dst_stride_ar64; + } + + if (src_a == NULL) { + MergeAR64PlaneOpaque(src_r, src_stride_r, src_g, src_stride_g, src_b, + src_stride_b, dst_ar64, dst_stride_ar64, width, height, + depth); + } else { + MergeAR64PlaneAlpha(src_r, src_stride_r, src_g, src_stride_g, src_b, + src_stride_b, src_a, src_stride_a, dst_ar64, + dst_stride_ar64, width, height, depth); + } +} + +LIBYUV_NOINLINE +static void MergeARGB16To8PlaneAlpha(const uint16_t* src_r, + int src_stride_r, + const uint16_t* src_g, + int src_stride_g, + const uint16_t* src_b, + int src_stride_b, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height, + int depth) { + int y; + void (*MergeARGB16To8Row)(const uint16_t* src_r, const uint16_t* src_g, + const uint16_t* src_b, const uint16_t* src_a, + uint8_t* dst_argb, int depth, int width) = + MergeARGB16To8Row_C; + + assert(height >= 0); + + if (width <= 0 || height == 0) { + return; + } + if (src_stride_r == width && src_stride_g == width && src_stride_b == width && + src_stride_a == width && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_r = src_stride_g = src_stride_b = src_stride_a = + dst_stride_argb = 0; + } +#if defined(HAS_MERGEARGB16TO8ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeARGB16To8Row = MergeARGB16To8Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + MergeARGB16To8Row = MergeARGB16To8Row_AVX2; + } + } +#endif +#if defined(HAS_MERGEARGB16TO8ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeARGB16To8Row = MergeARGB16To8Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + MergeARGB16To8Row = MergeARGB16To8Row_NEON; + } + } +#endif + + for (y = 0; y < height; ++y) { + MergeARGB16To8Row(src_r, src_g, src_b, src_a, dst_argb, depth, width); + src_r += src_stride_r; + src_g += src_stride_g; + src_b += src_stride_b; + src_a += src_stride_a; + dst_argb += dst_stride_argb; + } +} + +LIBYUV_NOINLINE +static void MergeARGB16To8PlaneOpaque(const uint16_t* src_r, + int src_stride_r, + const uint16_t* src_g, + int src_stride_g, + const uint16_t* src_b, + int src_stride_b, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height, + int depth) { + int y; + void (*MergeXRGB16To8Row)(const uint16_t* src_r, const uint16_t* src_g, + const uint16_t* src_b, uint8_t* dst_argb, int depth, + int width) = MergeXRGB16To8Row_C; + + assert(height >= 0); + + if (width <= 0 || height == 0) { + return; + } + // Coalesce rows. + if (src_stride_r == width && src_stride_g == width && src_stride_b == width && + dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_r = src_stride_g = src_stride_b = dst_stride_argb = 0; + } +#if defined(HAS_MERGEXRGB16TO8ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MergeXRGB16To8Row = MergeXRGB16To8Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + MergeXRGB16To8Row = MergeXRGB16To8Row_AVX2; + } + } +#endif +#if defined(HAS_MERGEXRGB16TO8ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MergeXRGB16To8Row = MergeXRGB16To8Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + MergeXRGB16To8Row = MergeXRGB16To8Row_NEON; + } + } +#endif + + for (y = 0; y < height; ++y) { + MergeXRGB16To8Row(src_r, src_g, src_b, dst_argb, depth, width); + src_r += src_stride_r; + src_g += src_stride_g; + src_b += src_stride_b; + dst_argb += dst_stride_argb; + } +} + +LIBYUV_API +void MergeARGB16To8Plane(const uint16_t* src_r, + int src_stride_r, + const uint16_t* src_g, + int src_stride_g, + const uint16_t* src_b, + int src_stride_b, + const uint16_t* src_a, + int src_stride_a, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height, + int depth) { + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } + + if (src_a == NULL) { + MergeARGB16To8PlaneOpaque(src_r, src_stride_r, src_g, src_stride_g, src_b, + src_stride_b, dst_argb, dst_stride_argb, width, + height, depth); + } else { + MergeARGB16To8PlaneAlpha(src_r, src_stride_r, src_g, src_stride_g, src_b, + src_stride_b, src_a, src_stride_a, dst_argb, + dst_stride_argb, width, height, depth); } } @@ -797,19 +2495,20 @@ int YUY2ToI422(const uint8_t* src_yuy2, uint8_t* dst_v, int width) = YUY2ToUV422Row_C; void (*YUY2ToYRow)(const uint8_t* src_yuy2, uint8_t* dst_y, int width) = YUY2ToYRow_C; - if (!src_yuy2 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_yuy2 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; + src_yuy2 = src_yuy2 + (ptrdiff_t)(height - 1) * src_stride_yuy2; src_stride_yuy2 = -src_stride_yuy2; } // Coalesce rows. if (src_stride_yuy2 == width * 2 && dst_stride_y == width && dst_stride_u * 2 == width && dst_stride_v * 2 == width && - width * height <= 32768) { + (ptrdiff_t)width * height <= 32768) { width *= height; height = 1; src_stride_yuy2 = dst_stride_y = dst_stride_u = dst_stride_v = 0; @@ -834,6 +2533,11 @@ int YUY2ToI422(const uint8_t* src_yuy2, } } #endif +#if defined(HAS_YUY2TOYROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + YUY2ToYRow = YUY2ToYRow_AVX512BW; + } +#endif #if defined(HAS_YUY2TOYROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { YUY2ToYRow = YUY2ToYRow_Any_NEON; @@ -844,26 +2548,37 @@ int YUY2ToI422(const uint8_t* src_yuy2, } } #endif -#if defined(HAS_YUY2TOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - YUY2ToYRow = YUY2ToYRow_Any_MSA; - YUY2ToUV422Row = YUY2ToUV422Row_Any_MSA; - if (IS_ALIGNED(width, 32)) { - YUY2ToYRow = YUY2ToYRow_MSA; - YUY2ToUV422Row = YUY2ToUV422Row_MSA; +#if defined(HAS_YUY2TOYROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + YUY2ToYRow = YUY2ToYRow_SVE2; + } +#endif +#if defined(HAS_YUY2TOYROW_LSX) && defined(HAS_YUY2TOUV422ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + YUY2ToYRow = YUY2ToYRow_Any_LSX; + YUY2ToUV422Row = YUY2ToUV422Row_Any_LSX; + if (IS_ALIGNED(width, 16)) { + YUY2ToYRow = YUY2ToYRow_LSX; + YUY2ToUV422Row = YUY2ToUV422Row_LSX; } } #endif -#if defined(HAS_YUY2TOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - YUY2ToYRow = YUY2ToYRow_Any_MMI; - YUY2ToUV422Row = YUY2ToUV422Row_Any_MMI; - if (IS_ALIGNED(width, 8)) { - YUY2ToYRow = YUY2ToYRow_MMI; - YUY2ToUV422Row = YUY2ToUV422Row_MMI; +#if defined(HAS_YUY2TOYROW_LASX) && defined(HAS_YUY2TOUV422ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + YUY2ToYRow = YUY2ToYRow_Any_LASX; + YUY2ToUV422Row = YUY2ToUV422Row_Any_LASX; + if (IS_ALIGNED(width, 32)) { + YUY2ToYRow = YUY2ToYRow_LASX; + YUY2ToUV422Row = YUY2ToUV422Row_LASX; } } #endif +#if defined(HAS_YUY2TOYROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + YUY2ToYRow = YUY2ToYRow_HVX; + YUY2ToUV422Row = YUY2ToUV422Row_HVX; + } +#endif for (y = 0; y < height; ++y) { YUY2ToUV422Row(src_yuy2, dst_u, dst_v, width); @@ -893,19 +2608,20 @@ int UYVYToI422(const uint8_t* src_uyvy, uint8_t* dst_v, int width) = UYVYToUV422Row_C; void (*UYVYToYRow)(const uint8_t* src_uyvy, uint8_t* dst_y, int width) = UYVYToYRow_C; - if (!src_uyvy || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_uyvy || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; + src_uyvy = src_uyvy + (ptrdiff_t)(height - 1) * src_stride_uyvy; src_stride_uyvy = -src_stride_uyvy; } // Coalesce rows. if (src_stride_uyvy == width * 2 && dst_stride_y == width && dst_stride_u * 2 == width && dst_stride_v * 2 == width && - width * height <= 32768) { + (ptrdiff_t)width * height <= 32768) { width *= height; height = 1; src_stride_uyvy = dst_stride_y = dst_stride_u = dst_stride_v = 0; @@ -930,6 +2646,11 @@ int UYVYToI422(const uint8_t* src_uyvy, } } #endif +#if defined(HAS_UYVYTOYROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + UYVYToYRow = UYVYToYRow_AVX512BW; + } +#endif #if defined(HAS_UYVYTOYROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { UYVYToYRow = UYVYToYRow_Any_NEON; @@ -940,26 +2661,37 @@ int UYVYToI422(const uint8_t* src_uyvy, } } #endif -#if defined(HAS_UYVYTOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - UYVYToYRow = UYVYToYRow_Any_MSA; - UYVYToUV422Row = UYVYToUV422Row_Any_MSA; - if (IS_ALIGNED(width, 32)) { - UYVYToYRow = UYVYToYRow_MSA; - UYVYToUV422Row = UYVYToUV422Row_MSA; +#if defined(HAS_UYVYTOYROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + UYVYToYRow = UYVYToYRow_SVE2; + } +#endif +#if defined(HAS_UYVYTOYROW_LSX) && defined(HAS_UYVYTOUV422ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + UYVYToYRow = UYVYToYRow_Any_LSX; + UYVYToUV422Row = UYVYToUV422Row_Any_LSX; + if (IS_ALIGNED(width, 16)) { + UYVYToYRow = UYVYToYRow_LSX; + UYVYToUV422Row = UYVYToUV422Row_LSX; } } #endif -#if defined(HAS_UYVYTOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - UYVYToYRow = UYVYToYRow_Any_MMI; - UYVYToUV422Row = UYVYToUV422Row_Any_MMI; - if (IS_ALIGNED(width, 16)) { - UYVYToYRow = UYVYToYRow_MMI; - UYVYToUV422Row = UYVYToUV422Row_MMI; +#if defined(HAS_UYVYTOYROW_LASX) && defined(HAS_UYVYTOUV422ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + UYVYToYRow = UYVYToYRow_Any_LASX; + UYVYToUV422Row = UYVYToUV422Row_Any_LASX; + if (IS_ALIGNED(width, 32)) { + UYVYToYRow = UYVYToYRow_LASX; + UYVYToUV422Row = UYVYToUV422Row_LASX; } } #endif +#if defined(HAS_UYVYTOYROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + UYVYToYRow = UYVYToYRow_HVX; + UYVYToUV422Row = UYVYToUV422Row_HVX; + } +#endif for (y = 0; y < height; ++y) { UYVYToUV422Row(src_uyvy, dst_u, dst_v, width); @@ -983,17 +2715,18 @@ int YUY2ToY(const uint8_t* src_yuy2, int y; void (*YUY2ToYRow)(const uint8_t* src_yuy2, uint8_t* dst_y, int width) = YUY2ToYRow_C; - if (!src_yuy2 || !dst_y || width <= 0 || height == 0) { + if (!src_yuy2 || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; + src_yuy2 = src_yuy2 + (ptrdiff_t)(height - 1) * src_stride_yuy2; src_stride_yuy2 = -src_stride_yuy2; } // Coalesce rows. - if (src_stride_yuy2 == width * 2 && dst_stride_y == width) { + if (src_stride_yuy2 == width * 2 && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_yuy2 = dst_stride_y = 0; @@ -1014,6 +2747,11 @@ int YUY2ToY(const uint8_t* src_yuy2, } } #endif +#if defined(HAS_YUY2TOYROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + YUY2ToYRow = YUY2ToYRow_AVX512BW; + } +#endif #if defined(HAS_YUY2TOYROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { YUY2ToYRow = YUY2ToYRow_Any_NEON; @@ -1022,20 +2760,14 @@ int YUY2ToY(const uint8_t* src_yuy2, } } #endif -#if defined(HAS_YUY2TOYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - YUY2ToYRow = YUY2ToYRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - YUY2ToYRow = YUY2ToYRow_MSA; - } +#if defined(HAS_YUY2TOYROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + YUY2ToYRow = YUY2ToYRow_SVE2; } #endif -#if defined(HAS_YUY2TOYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - YUY2ToYRow = YUY2ToYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - YUY2ToYRow = YUY2ToYRow_MMI; - } +#if defined(HAS_YUY2TOYROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + YUY2ToYRow = YUY2ToYRow_HVX; } #endif @@ -1047,6 +2779,384 @@ int YUY2ToY(const uint8_t* src_yuy2, return 0; } +// Convert UYVY to Y. +LIBYUV_API +int UYVYToY(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_y, + int dst_stride_y, + int width, + int height) { + int y; + void (*UYVYToYRow)(const uint8_t* src_uyvy, uint8_t* dst_y, int width) = + UYVYToYRow_C; + if (!src_uyvy || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_uyvy = src_uyvy + (ptrdiff_t)(height - 1) * src_stride_uyvy; + src_stride_uyvy = -src_stride_uyvy; + } + // Coalesce rows. + if (src_stride_uyvy == width * 2 && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_uyvy = dst_stride_y = 0; + } +#if defined(HAS_UYVYTOYROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + UYVYToYRow = UYVYToYRow_Any_SSE2; + if (IS_ALIGNED(width, 16)) { + UYVYToYRow = UYVYToYRow_SSE2; + } + } +#endif +#if defined(HAS_UYVYTOYROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + UYVYToYRow = UYVYToYRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + UYVYToYRow = UYVYToYRow_AVX2; + } + } +#endif +#if defined(HAS_UYVYTOYROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + UYVYToYRow = UYVYToYRow_AVX512BW; + } +#endif +#if defined(HAS_UYVYTOYROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + UYVYToYRow = UYVYToYRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + UYVYToYRow = UYVYToYRow_NEON; + } + } +#endif +#if defined(HAS_UYVYTOYROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + UYVYToYRow = UYVYToYRow_SVE2; + } +#endif +#if defined(HAS_UYVYTOYROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + UYVYToYRow = UYVYToYRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + UYVYToYRow = UYVYToYRow_LSX; + } + } +#endif +#if defined(HAS_UYVYTOYROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + UYVYToYRow = UYVYToYRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + UYVYToYRow = UYVYToYRow_LASX; + } + } +#endif +#if defined(HAS_UYVYTOYROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + UYVYToYRow = UYVYToYRow_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + UYVYToYRow(src_uyvy, dst_y, width); + src_uyvy += src_stride_uyvy; + dst_y += dst_stride_y; + } + return 0; +} + +// Mirror a plane of data. +// See Also I400Mirror +LIBYUV_API +void MirrorPlane(const uint8_t* src_y, + int src_stride_y, + uint8_t* dst_y, + int dst_stride_y, + int width, + int height) { + int y; + void (*MirrorRow)(const uint8_t* src, uint8_t* dst, int width) = MirrorRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_stride_y = -src_stride_y; + } +#if defined(HAS_MIRRORROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MirrorRow = MirrorRow_Any_NEON; + if (IS_ALIGNED(width, 32)) { + MirrorRow = MirrorRow_NEON; + } + } +#endif +#if defined(HAS_MIRRORROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + MirrorRow = MirrorRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + MirrorRow = MirrorRow_SSSE3; + } + } +#endif +#if defined(HAS_MIRRORROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MirrorRow = MirrorRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + MirrorRow = MirrorRow_AVX2; + } + } +#endif +#if defined(HAS_MIRRORROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MirrorRow = MirrorRow_AVX512BW; + } +#endif +#if defined(HAS_MIRRORROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MirrorRow = MirrorRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + MirrorRow = MirrorRow_LSX; + } + } +#endif +#if defined(HAS_MIRRORROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MirrorRow = MirrorRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + MirrorRow = MirrorRow_LASX; + } + } +#endif +#if defined(HAS_MIRRORROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MirrorRow = MirrorRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + MirrorRow = MirrorRow_WASMSIMD; + } + } +#endif +#if defined(HAS_MIRRORROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MirrorRow = MirrorRow_HVX; + } +#endif + + // Mirror plane + for (y = 0; y < height; ++y) { + MirrorRow(src_y, dst_y, width); + src_y += src_stride_y; + dst_y += dst_stride_y; + } +} + +// Mirror a plane of 16-bit data. +LIBYUV_API +void MirrorPlane_16(const uint16_t* src_y, + int src_stride_y, + uint16_t* dst_y, + int dst_stride_y, + int width, + int height) { + int y; + void (*MirrorRow_16)(const uint16_t* src, uint16_t* dst, int width) = + MirrorRow_16_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_stride_y = -src_stride_y; + } +#if defined(HAS_MIRRORROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MirrorRow_16 = MirrorRow_16_Any_NEON; + if (IS_ALIGNED(width, 16)) { + MirrorRow_16 = MirrorRow_16_NEON; + } + } +#endif +#if defined(HAS_MIRRORUVROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + MirrorRow_16 = reinterpret_cast( + MirrorUVRow_Any_SSSE3); + if (IS_ALIGNED(width, 8)) { + MirrorRow_16 = + reinterpret_cast( + MirrorUVRow_SSSE3); + } + } +#endif +#if defined(HAS_MIRRORUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MirrorRow_16 = reinterpret_cast( + MirrorUVRow_Any_AVX2); + if (IS_ALIGNED(width, 16)) { + MirrorRow_16 = + reinterpret_cast( + MirrorUVRow_AVX2); + } + } +#endif +#if defined(HAS_MIRRORROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MirrorRow_16 = MirrorRow_16_AVX512BW; + } +#endif +#if defined(HAS_MIRRORUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MirrorRow_16 = reinterpret_cast( + MirrorUVRow_Any_LSX); + if (IS_ALIGNED(width, 8)) { + MirrorRow_16 = + reinterpret_cast( + MirrorUVRow_LSX); + } + } +#endif +#if defined(HAS_MIRRORUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MirrorRow_16 = reinterpret_cast( + MirrorUVRow_Any_LASX); + if (IS_ALIGNED(width, 16)) { + MirrorRow_16 = + reinterpret_cast( + MirrorUVRow_LASX); + } + } +#endif +#if defined(HAS_MIRRORUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MirrorRow_16 = reinterpret_cast( + MirrorUVRow_RVV); + } +#endif +#if defined(HAS_MIRRORUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MirrorRow_16 = reinterpret_cast( + MirrorUVRow_Any_WASMSIMD); + if (IS_ALIGNED(width, 8)) { + MirrorRow_16 = + reinterpret_cast( + MirrorUVRow_WASMSIMD); + } + } +#endif +#if defined(HAS_MIRRORROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MirrorRow_16 = MirrorRow_16_HVX; + } +#endif + + // Mirror plane + for (y = 0; y < height; ++y) { + MirrorRow_16(src_y, dst_y, width); + src_y += src_stride_y; + dst_y += dst_stride_y; + } +} + +// Mirror a plane of UV data. +LIBYUV_API +void MirrorUVPlane(const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + int y; + void (*MirrorUVRow)(const uint8_t* src, uint8_t* dst, int width) = + MirrorUVRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_uv = src_uv + (ptrdiff_t)(height - 1) * src_stride_uv; + src_stride_uv = -src_stride_uv; + } +#if defined(HAS_MIRRORUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + MirrorUVRow = MirrorUVRow_Any_NEON; + if (IS_ALIGNED(width, 32)) { + MirrorUVRow = MirrorUVRow_NEON; + } + } +#endif +#if defined(HAS_MIRRORUVROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + MirrorUVRow = MirrorUVRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + MirrorUVRow = MirrorUVRow_SSSE3; + } + } +#endif +#if defined(HAS_MIRRORUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MirrorUVRow = MirrorUVRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + MirrorUVRow = MirrorUVRow_AVX2; + } + } +#endif +#if defined(HAS_MIRRORUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MirrorUVRow = MirrorUVRow_AVX512BW; + } +#endif +#if defined(HAS_MIRRORUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MirrorUVRow = MirrorUVRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + MirrorUVRow = MirrorUVRow_LSX; + } + } +#endif +#if defined(HAS_MIRRORUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MirrorUVRow = MirrorUVRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + MirrorUVRow = MirrorUVRow_LASX; + } + } +#endif +#if defined(HAS_MIRRORUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + MirrorUVRow = MirrorUVRow_RVV; + } +#endif +#if defined(HAS_MIRRORUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MirrorUVRow = MirrorUVRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + MirrorUVRow = MirrorUVRow_WASMSIMD; + } + } +#endif +#if defined(HAS_MIRRORUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MirrorUVRow = MirrorUVRow_HVX; + } +#endif + + // MirrorUV plane + for (y = 0; y < height; ++y) { + MirrorUVRow(src_uv, dst_uv, width); + src_uv += src_stride_uv; + dst_uv += dst_stride_uv; + } +} + // Mirror I400 with optional flipping LIBYUV_API int I400Mirror(const uint8_t* src_y, @@ -1055,13 +3165,13 @@ int I400Mirror(const uint8_t* src_y, int dst_stride_y, int width, int height) { - if (!src_y || !dst_y || width <= 0 || height == 0) { + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } @@ -1087,17 +3197,19 @@ int I420Mirror(const uint8_t* src_y, int height) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_y || !src_u || !src_v || !dst_y || !dst_u || !dst_v || width <= 0 || - height == 0) { + + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } + // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -1111,6 +3223,44 @@ int I420Mirror(const uint8_t* src_y, return 0; } +// NV12 mirror. +LIBYUV_API +int NV12Mirror(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + int halfwidth = (width + 1) >> 1; + int halfheight = (height + 1) >> 1; + + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_uv = src_uv + (ptrdiff_t)(halfheight - 1) * src_stride_uv; + src_stride_y = -src_stride_y; + src_stride_uv = -src_stride_uv; + } + + if (dst_y) { + MirrorPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + } + MirrorUVPlane(src_uv, src_stride_uv, dst_uv, dst_stride_uv, halfwidth, + halfheight); + return 0; +} + // ARGB mirror. LIBYUV_API int ARGBMirror(const uint8_t* src_argb, @@ -1122,19 +3272,20 @@ int ARGBMirror(const uint8_t* src_argb, int y; void (*ARGBMirrorRow)(const uint8_t* src, uint8_t* dst, int width) = ARGBMirrorRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } #if defined(HAS_ARGBMIRRORROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ARGBMirrorRow = ARGBMirrorRow_Any_NEON; - if (IS_ALIGNED(width, 4)) { + if (IS_ALIGNED(width, 8)) { ARGBMirrorRow = ARGBMirrorRow_NEON; } } @@ -1155,22 +3306,45 @@ int ARGBMirror(const uint8_t* src_argb, } } #endif -#if defined(HAS_ARGBMIRRORROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBMirrorRow = ARGBMirrorRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBMirrorRow = ARGBMirrorRow_MSA; +#if defined(HAS_ARGBMIRRORROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBMirrorRow = ARGBMirrorRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBMIRRORROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBMirrorRow = ARGBMirrorRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBMirrorRow = ARGBMirrorRow_LSX; } } #endif -#if defined(HAS_ARGBMIRRORROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBMirrorRow = ARGBMirrorRow_Any_MMI; - if (IS_ALIGNED(width, 2)) { - ARGBMirrorRow = ARGBMirrorRow_MMI; +#if defined(HAS_ARGBMIRRORROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBMirrorRow = ARGBMirrorRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBMirrorRow = ARGBMirrorRow_LASX; } } #endif +#if defined(HAS_ARGBMIRRORROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBMirrorRow = ARGBMirrorRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 4)) { + ARGBMirrorRow = ARGBMirrorRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBMIRRORROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBMirrorRow = ARGBMirrorRow_RVV; + } +#endif +#if defined(HAS_ARGBMIRRORROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBMirrorRow = ARGBMirrorRow_HVX; + } +#endif // Mirror plane for (y = 0; y < height; ++y) { @@ -1181,35 +3355,72 @@ int ARGBMirror(const uint8_t* src_argb, return 0; } -// Get a blender that optimized for the CPU and pixel count. -// As there are 6 blenders to choose from, the caller should try to use -// the same blend function for all pixels if possible. +// RGB24 mirror. LIBYUV_API -ARGBBlendRow GetARGBBlend(void) { - void (*ARGBBlendRow)(const uint8_t* src_argb, const uint8_t* src_argb1, - uint8_t* dst_argb, int width) = ARGBBlendRow_C; -#if defined(HAS_ARGBBLENDROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBBlendRow = ARGBBlendRow_SSSE3; - return ARGBBlendRow; +int RGB24Mirror(const uint8_t* src_rgb24, + int src_stride_rgb24, + uint8_t* dst_rgb24, + int dst_stride_rgb24, + int width, + int height) { + int y; + void (*RGB24MirrorRow)(const uint8_t* src, uint8_t* dst, int width) = + RGB24MirrorRow_C; + if (!src_rgb24 || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; } -#endif -#if defined(HAS_ARGBBLENDROW_NEON) + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; + src_stride_rgb24 = -src_stride_rgb24; + } +#if defined(HAS_RGB24MIRRORROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - ARGBBlendRow = ARGBBlendRow_NEON; + RGB24MirrorRow = RGB24MirrorRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + RGB24MirrorRow = RGB24MirrorRow_NEON; + } } #endif -#if defined(HAS_ARGBBLENDROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBBlendRow = ARGBBlendRow_MSA; +#if defined(HAS_RGB24MIRRORROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + RGB24MirrorRow = RGB24MirrorRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + RGB24MirrorRow = RGB24MirrorRow_SSSE3; + } } #endif -#if defined(HAS_ARGBBLENDROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBBlendRow = ARGBBlendRow_MMI; +#if defined(HAS_RGB24MIRRORROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGB24MirrorRow = RGB24MirrorRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RGB24MirrorRow = RGB24MirrorRow_AVX2; + } } #endif - return ARGBBlendRow; +#if defined(HAS_RGB24MIRRORROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI)) { + RGB24MirrorRow = RGB24MirrorRow_AVX512VBMI; + } +#endif +#if defined(HAS_RGB24MIRRORROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RGB24MirrorRow = RGB24MirrorRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RGB24MirrorRow = RGB24MirrorRow_WASMSIMD; + } + } +#endif + + // Mirror plane + for (y = 0; y < height; ++y) { + RGB24MirrorRow(src_rgb24, dst_rgb24, width); + src_rgb24 += src_stride_rgb24; + dst_rgb24 += dst_stride_rgb24; + } + return 0; } // Alpha Blend 2 ARGB images and store to destination. @@ -1224,24 +3435,70 @@ int ARGBBlend(const uint8_t* src_argb0, int height) { int y; void (*ARGBBlendRow)(const uint8_t* src_argb, const uint8_t* src_argb1, - uint8_t* dst_argb, int width) = GetARGBBlend(); - if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0) { + uint8_t* dst_argb, int width) = ARGBBlendRow_C; + if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. if (src_stride_argb0 == width * 4 && src_stride_argb1 == width * 4 && - dst_stride_argb == width * 4) { + dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb0 = src_stride_argb1 = dst_stride_argb = 0; } - +#if defined(HAS_ARGBBLENDROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBBlendRow = ARGBBlendRow_AVX2; + } +#endif +#if defined(HAS_ARGBBLENDROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBBlendRow = ARGBBlendRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBBLENDROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBBlendRow = ARGBBlendRow_NEON; + } +#endif +#if defined(HAS_ARGBBLENDROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBBlendRow = ARGBBlendRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBBlendRow = ARGBBlendRow_LSX; + } + } +#endif +#if defined(HAS_ARGBBLENDROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBBlendRow = ARGBBlendRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBBlendRow = ARGBBlendRow_LASX; + } + } +#endif +#if defined(HAS_ARGBBLENDROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBBlendRow = ARGBBlendRow_RVV; + } +#endif +#if defined(HAS_ARGBBLENDROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBBlendRow = ARGBBlendRow_WASMSIMD; + } +#endif +#if defined(HAS_ARGBBLENDROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBBlendRow = ARGBBlendRow_HVX; + } +#endif for (y = 0; y < height; ++y) { ARGBBlendRow(src_argb0, src_argb1, dst_argb, width); src_argb0 += src_stride_argb0; @@ -1251,6 +3508,118 @@ int ARGBBlend(const uint8_t* src_argb0, return 0; } +// Alpha Blend 2 unattenuated ARGB images and store to destination. +LIBYUV_API +int ARGBAlphaBlend(const uint8_t* src_argb0, + int src_stride_argb0, + const uint8_t* src_argb1, + int src_stride_argb1, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + int y; + void (*ARGBAlphaBlendRow)(const uint8_t* src_argb, const uint8_t* src_argb1, + uint8_t* dst_argb, int width) = ARGBAlphaBlendRow_C; + if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; + dst_stride_argb = -dst_stride_argb; + } + // Coalesce rows. + if (src_stride_argb0 == width * 4 && src_stride_argb1 == width * 4 && + dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_argb0 = src_stride_argb1 = dst_stride_argb = 0; + } +#if defined(HAS_ARGBALPHABLENDROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_Any_SSSE3; + if (IS_ALIGNED(width, 4)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBALPHABLENDROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBALPHABLENDROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBALPHABLENDROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_NEON; + } + } +#endif +#if defined(HAS_ARGBALPHABLENDROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_SVE2; + } +#endif +#if defined(HAS_ARGBALPHABLENDROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_SME; + } +#endif +#if defined(HAS_ARGBALPHABLENDROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_LSX; + } + } +#endif +#if defined(HAS_ARGBALPHABLENDROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_LASX; + } + } +#endif +#if defined(HAS_ARGBALPHABLENDROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_RVV; + } +#endif +#if defined(HAS_ARGBALPHABLENDROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 4)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBALPHABLENDROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAlphaBlendRow = ARGBAlphaBlendRow_HVX; + } +#endif + for (y = 0; y < height; ++y) { + ARGBAlphaBlendRow(src_argb0, src_argb1, dst_argb, width); + src_argb0 += src_stride_argb0; + src_argb1 += src_stride_argb1; + dst_argb += dst_stride_argb; + } + return 0; +} + // Alpha Blend plane and store to destination. LIBYUV_API int BlendPlane(const uint8_t* src_y0, @@ -1267,19 +3636,21 @@ int BlendPlane(const uint8_t* src_y0, void (*BlendPlaneRow)(const uint8_t* src0, const uint8_t* src1, const uint8_t* alpha, uint8_t* dst, int width) = BlendPlaneRow_C; - if (!src_y0 || !src_y1 || !alpha || !dst_y || width <= 0 || height == 0) { + if (!src_y0 || !src_y1 || !alpha || !dst_y || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows for Y plane. if (src_stride_y0 == width && src_stride_y1 == width && - alpha_stride == width && dst_stride_y == width) { + alpha_stride == width && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y0 = src_stride_y1 = alpha_stride = dst_stride_y = 0; @@ -1301,14 +3672,37 @@ int BlendPlane(const uint8_t* src_y0, } } #endif -#if defined(HAS_BLENDPLANEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - BlendPlaneRow = BlendPlaneRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - BlendPlaneRow = BlendPlaneRow_MMI; +#if defined(HAS_BLENDPLANEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + BlendPlaneRow = BlendPlaneRow_AVX512BW; + } +#endif +#if defined(HAS_BLENDPLANEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + BlendPlaneRow = BlendPlaneRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + BlendPlaneRow = BlendPlaneRow_NEON; } } #endif +#if defined(HAS_BLENDPLANEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + BlendPlaneRow = BlendPlaneRow_RVV; + } +#endif +#if defined(HAS_BLENDPLANEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + BlendPlaneRow = BlendPlaneRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + BlendPlaneRow = BlendPlaneRow_WASMSIMD; + } + } +#endif +#if defined(HAS_BLENDPLANEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + BlendPlaneRow = BlendPlaneRow_HVX; + } +#endif for (y = 0; y < height; ++y) { BlendPlaneRow(src_y0, src_y1, alpha, dst_y, width); @@ -1353,15 +3747,17 @@ int I420Blend(const uint8_t* src_y0, BlendPlaneRow_C; void (*ScaleRowDown2)(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width) = ScaleRowDown2Box_C; + if (!src_y0 || !src_u0 || !src_v0 || !src_y1 || !src_u1 || !src_v1 || - !alpha || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + !alpha || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } @@ -1385,13 +3781,36 @@ int I420Blend(const uint8_t* src_y0, } } #endif -#if defined(HAS_BLENDPLANEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - BlendPlaneRow = BlendPlaneRow_Any_MMI; - if (IS_ALIGNED(halfwidth, 8)) { - BlendPlaneRow = BlendPlaneRow_MMI; +#if defined(HAS_BLENDPLANEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + BlendPlaneRow = BlendPlaneRow_AVX512BW; + } +#endif +#if defined(HAS_BLENDPLANEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + BlendPlaneRow = BlendPlaneRow_Any_NEON; + if (IS_ALIGNED(halfwidth, 16)) { + BlendPlaneRow = BlendPlaneRow_NEON; } } +#endif +#if defined(HAS_BLENDPLANEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + BlendPlaneRow = BlendPlaneRow_RVV; + } +#endif +#if defined(HAS_BLENDPLANEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + BlendPlaneRow = BlendPlaneRow_Any_WASMSIMD; + if (IS_ALIGNED(halfwidth, 8)) { + BlendPlaneRow = BlendPlaneRow_WASMSIMD; + } + } +#endif +#if defined(HAS_BLENDPLANEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + BlendPlaneRow = BlendPlaneRow_HVX; + } #endif if (!IS_ALIGNED(width, 2)) { ScaleRowDown2 = ScaleRowDown2Box_Odd_C; @@ -1429,20 +3848,41 @@ int I420Blend(const uint8_t* src_y0, } } #endif -#if defined(HAS_SCALEROWDOWN2_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ScaleRowDown2 = ScaleRowDown2Box_Odd_MMI; +#if defined(HAS_SCALEROWDOWN2_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ScaleRowDown2 = ScaleRowDown2Box_Odd_AVX512BW; if (IS_ALIGNED(width, 2)) { - ScaleRowDown2 = ScaleRowDown2Box_Any_MMI; - if (IS_ALIGNED(halfwidth, 8)) { - ScaleRowDown2 = ScaleRowDown2Box_MMI; + ScaleRowDown2 = ScaleRowDown2Box_AVX512BW; + } + } +#endif +#if defined(HAS_SCALEROWDOWN2_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleRowDown2 = ScaleRowDown2Box_RVV; + } +#endif +#if defined(HAS_SCALEROWDOWN2_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ScaleRowDown2 = ScaleRowDown2Box_Odd_WASMSIMD; + if (IS_ALIGNED(width, 2)) { + ScaleRowDown2 = ScaleRowDown2Box_Any_WASMSIMD; + if (IS_ALIGNED(halfwidth, 16)) { + ScaleRowDown2 = ScaleRowDown2Box_WASMSIMD; } } } #endif +#if defined(HAS_SCALEROWDOWN2_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ScaleRowDown2 = + IS_ALIGNED(width, 2) ? ScaleRowDown2Box_HVX : ScaleRowDown2Box_Odd_HVX; + } +#endif // Row buffer for intermediate alpha pixels. align_buffer_64(halfalpha, halfwidth); + if (!halfalpha) + return 1; for (y = 0; y < height; y += 2) { // last row of odd height image use 1 row of alpha instead of 2. if (y == (height - 1)) { @@ -1450,7 +3890,7 @@ int I420Blend(const uint8_t* src_y0, } // Subsample 2 rows of UV to half width and half height. ScaleRowDown2(alpha, alpha_stride, halfalpha, halfwidth); - alpha += alpha_stride * 2; + alpha += (ptrdiff_t)alpha_stride * 2; BlendPlaneRow(src_u0, src_u1, halfalpha, dst_u, halfwidth); BlendPlaneRow(src_v0, src_v1, halfalpha, dst_v, halfwidth); src_u0 += src_stride_u0; @@ -1477,18 +3917,19 @@ int ARGBMultiply(const uint8_t* src_argb0, int y; void (*ARGBMultiplyRow)(const uint8_t* src0, const uint8_t* src1, uint8_t* dst, int width) = ARGBMultiplyRow_C; - if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0) { + if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. if (src_stride_argb0 == width * 4 && src_stride_argb1 == width * 4 && - dst_stride_argb == width * 4) { + dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb0 = src_stride_argb1 = dst_stride_argb = 0; @@ -1509,6 +3950,11 @@ int ARGBMultiply(const uint8_t* src_argb0, } } #endif +#if defined(HAS_ARGBMULTIPLYROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBMultiplyRow = ARGBMultiplyRow_AVX512BW; + } +#endif #if defined(HAS_ARGBMULTIPLYROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ARGBMultiplyRow = ARGBMultiplyRow_Any_NEON; @@ -1517,22 +3963,37 @@ int ARGBMultiply(const uint8_t* src_argb0, } } #endif -#if defined(HAS_ARGBMULTIPLYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBMultiplyRow = ARGBMultiplyRow_Any_MSA; +#if defined(HAS_ARGBMULTIPLYROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBMultiplyRow = ARGBMultiplyRow_SME; + } +#endif +#if defined(HAS_ARGBMULTIPLYROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBMultiplyRow = ARGBMultiplyRow_Any_LSX; if (IS_ALIGNED(width, 4)) { - ARGBMultiplyRow = ARGBMultiplyRow_MSA; + ARGBMultiplyRow = ARGBMultiplyRow_LSX; } } #endif -#if defined(HAS_ARGBMULTIPLYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBMultiplyRow = ARGBMultiplyRow_Any_MMI; - if (IS_ALIGNED(width, 2)) { - ARGBMultiplyRow = ARGBMultiplyRow_MMI; +#if defined(HAS_ARGBMULTIPLYROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBMultiplyRow = ARGBMultiplyRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBMultiplyRow = ARGBMultiplyRow_LASX; } } #endif +#if defined(HAS_ARGBMULTIPLYROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBMultiplyRow = ARGBMultiplyRow_RVV; + } +#endif +#if defined(HAS_ARGBMULTIPLYROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBMultiplyRow = ARGBMultiplyRow_HVX; + } +#endif // Multiply plane for (y = 0; y < height; ++y) { @@ -1557,28 +4018,29 @@ int ARGBAdd(const uint8_t* src_argb0, int y; void (*ARGBAddRow)(const uint8_t* src0, const uint8_t* src1, uint8_t* dst, int width) = ARGBAddRow_C; - if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0) { + if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. if (src_stride_argb0 == width * 4 && src_stride_argb1 == width * 4 && - dst_stride_argb == width * 4) { + dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb0 = src_stride_argb1 = dst_stride_argb = 0; } -#if defined(HAS_ARGBADDROW_SSE2) && (defined(_MSC_VER) && !defined(__clang__)) +#if defined(HAS_ARGBADDROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { ARGBAddRow = ARGBAddRow_SSE2; } #endif -#if defined(HAS_ARGBADDROW_SSE2) && !(defined(_MSC_VER) && !defined(__clang__)) +#if defined(HAS_ARGBADDROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { ARGBAddRow = ARGBAddRow_Any_SSE2; if (IS_ALIGNED(width, 4)) { @@ -1602,22 +4064,27 @@ int ARGBAdd(const uint8_t* src_argb0, } } #endif -#if defined(HAS_ARGBADDROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBAddRow = ARGBAddRow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - ARGBAddRow = ARGBAddRow_MSA; +#if defined(HAS_ARGBADDROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAddRow = ARGBAddRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAddRow = ARGBAddRow_LSX; } } #endif -#if defined(HAS_ARGBADDROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBAddRow = ARGBAddRow_Any_MMI; - if (IS_ALIGNED(width, 2)) { - ARGBAddRow = ARGBAddRow_MMI; +#if defined(HAS_ARGBADDROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAddRow = ARGBAddRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAddRow = ARGBAddRow_LASX; } } #endif +#if defined(HAS_ARGBADDROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAddRow = ARGBAddRow_HVX; + } +#endif // Add plane for (y = 0; y < height; ++y) { @@ -1642,18 +4109,19 @@ int ARGBSubtract(const uint8_t* src_argb0, int y; void (*ARGBSubtractRow)(const uint8_t* src0, const uint8_t* src1, uint8_t* dst, int width) = ARGBSubtractRow_C; - if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0) { + if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. if (src_stride_argb0 == width * 4 && src_stride_argb1 == width * 4 && - dst_stride_argb == width * 4) { + dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb0 = src_stride_argb1 = dst_stride_argb = 0; @@ -1682,22 +4150,27 @@ int ARGBSubtract(const uint8_t* src_argb0, } } #endif -#if defined(HAS_ARGBSUBTRACTROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBSubtractRow = ARGBSubtractRow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - ARGBSubtractRow = ARGBSubtractRow_MSA; +#if defined(HAS_ARGBSUBTRACTROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBSubtractRow = ARGBSubtractRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBSubtractRow = ARGBSubtractRow_LSX; } } #endif -#if defined(HAS_ARGBSUBTRACTROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBSubtractRow = ARGBSubtractRow_Any_MMI; - if (IS_ALIGNED(width, 2)) { - ARGBSubtractRow = ARGBSubtractRow_MMI; +#if defined(HAS_ARGBSUBTRACTROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBSubtractRow = ARGBSubtractRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBSubtractRow = ARGBSubtractRow_LASX; } } #endif +#if defined(HAS_ARGBSUBTRACTROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBSubtractRow = ARGBSubtractRow_HVX; + } +#endif // Subtract plane for (y = 0; y < height; ++y) { @@ -1708,174 +4181,113 @@ int ARGBSubtract(const uint8_t* src_argb0, } return 0; } -// Convert I422 to RGBA with matrix -static int I422ToRGBAMatrix(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgba, - int dst_stride_rgba, - const struct YuvConstants* yuvconstants, - int width, - int height) { + +// Bitwise OR ARGB image with a specified ARGB value. +LIBYUV_API +int ARGBOr(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height, + uint32_t value) { int y; - void (*I422ToRGBARow)(const uint8_t* y_buf, const uint8_t* u_buf, - const uint8_t* v_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, int width) = - I422ToRGBARow_C; - if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0) { + void (*ARGBOrRow)(const uint8_t* src_argb, uint8_t* dst_argb, uint32_t value, + int width) = ARGBOrRow_C; + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgba = dst_rgba + (height - 1) * dst_stride_rgba; - dst_stride_rgba = -dst_stride_rgba; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; } -#if defined(HAS_I422TORGBAROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - I422ToRGBARow = I422ToRGBARow_Any_SSSE3; - if (IS_ALIGNED(width, 8)) { - I422ToRGBARow = I422ToRGBARow_SSSE3; + // Coalesce rows. + if (src_stride_argb == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_argb = dst_stride_argb = 0; + } +#if defined(HAS_ARGBORROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + ARGBOrRow = ARGBOrRow_Any_SSE2; + if (IS_ALIGNED(width, 4)) { + ARGBOrRow = ARGBOrRow_SSE2; } } #endif -#if defined(HAS_I422TORGBAROW_AVX2) +#if defined(HAS_ARGBORROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - I422ToRGBARow = I422ToRGBARow_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - I422ToRGBARow = I422ToRGBARow_AVX2; + ARGBOrRow = ARGBOrRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBOrRow = ARGBOrRow_AVX2; } } #endif -#if defined(HAS_I422TORGBAROW_NEON) +#if defined(HAS_ARGBORROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBOrRow = ARGBOrRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBORROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - I422ToRGBARow = I422ToRGBARow_Any_NEON; + ARGBOrRow = ARGBOrRow_Any_NEON; if (IS_ALIGNED(width, 8)) { - I422ToRGBARow = I422ToRGBARow_NEON; + ARGBOrRow = ARGBOrRow_NEON; } } #endif -#if defined(HAS_I422TORGBAROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToRGBARow = I422ToRGBARow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - I422ToRGBARow = I422ToRGBARow_MSA; +#if defined(HAS_ARGBORROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBOrRow = ARGBOrRow_SVE2; + } +#endif +#if defined(HAS_ARGBORROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + ARGBOrRow = ARGBOrRow_SME; + } +#endif +#if defined(HAS_ARGBORROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBOrRow = ARGBOrRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBOrRow = ARGBOrRow_LSX; } } #endif - +#if defined(HAS_ARGBORROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBOrRow = ARGBOrRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBOrRow = ARGBOrRow_LASX; + } + } +#endif +#if defined(HAS_ARGBORROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBOrRow = ARGBOrRow_RVV; + } +#endif +#if defined(HAS_ARGBORROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBOrRow = ARGBOrRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 4)) { + ARGBOrRow = ARGBOrRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBORROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBOrRow = ARGBOrRow_HVX; + } +#endif for (y = 0; y < height; ++y) { - I422ToRGBARow(src_y, src_u, src_v, dst_rgba, yuvconstants, width); - dst_rgba += dst_stride_rgba; - src_y += src_stride_y; - src_u += src_stride_u; - src_v += src_stride_v; - } - return 0; -} - -// Convert I422 to RGBA. -LIBYUV_API -int I422ToRGBA(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_rgba, - int dst_stride_rgba, - int width, - int height) { - return I422ToRGBAMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v, - src_stride_v, dst_rgba, dst_stride_rgba, - &kYuvI601Constants, width, height); -} - -// Convert I422 to BGRA. -LIBYUV_API -int I422ToBGRA(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint8_t* dst_bgra, - int dst_stride_bgra, - int width, - int height) { - return I422ToRGBAMatrix(src_y, src_stride_y, src_v, - src_stride_v, // Swap U and V - src_u, src_stride_u, dst_bgra, dst_stride_bgra, - &kYvuI601Constants, // Use Yvu matrix - width, height); -} - -// Convert NV12 to RGB565. -LIBYUV_API -int NV12ToRGB565(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_uv, - int src_stride_uv, - uint8_t* dst_rgb565, - int dst_stride_rgb565, - int width, - int height) { - int y; - void (*NV12ToRGB565Row)( - const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, int width) = NV12ToRGB565Row_C; - if (!src_y || !src_uv || !dst_rgb565 || width <= 0 || height == 0) { - return -1; - } - // Negative height means invert the image. - if (height < 0) { - height = -height; - dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; - dst_stride_rgb565 = -dst_stride_rgb565; - } -#if defined(HAS_NV12TORGB565ROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - NV12ToRGB565Row = NV12ToRGB565Row_Any_SSSE3; - if (IS_ALIGNED(width, 8)) { - NV12ToRGB565Row = NV12ToRGB565Row_SSSE3; - } - } -#endif -#if defined(HAS_NV12TORGB565ROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - NV12ToRGB565Row = NV12ToRGB565Row_Any_AVX2; - if (IS_ALIGNED(width, 16)) { - NV12ToRGB565Row = NV12ToRGB565Row_AVX2; - } - } -#endif -#if defined(HAS_NV12TORGB565ROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - NV12ToRGB565Row = NV12ToRGB565Row_Any_NEON; - if (IS_ALIGNED(width, 8)) { - NV12ToRGB565Row = NV12ToRGB565Row_NEON; - } - } -#endif -#if defined(HAS_NV12TORGB565ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - NV12ToRGB565Row = NV12ToRGB565Row_Any_MSA; - if (IS_ALIGNED(width, 8)) { - NV12ToRGB565Row = NV12ToRGB565Row_MSA; - } - } -#endif - - for (y = 0; y < height; ++y) { - NV12ToRGB565Row(src_y, src_uv, dst_rgb565, &kYuvI601Constants, width); - dst_rgb565 += dst_stride_rgb565; - src_y += src_stride_y; - if (y & 1) { - src_uv += src_stride_uv; - } + ARGBOrRow(src_argb, dst_argb, value, width); + src_argb += src_stride_argb; + dst_argb += dst_stride_argb; } return 0; } @@ -1891,17 +4303,19 @@ int RAWToRGB24(const uint8_t* src_raw, int y; void (*RAWToRGB24Row)(const uint8_t* src_rgb, uint8_t* dst_rgb24, int width) = RAWToRGB24Row_C; - if (!src_raw || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_raw || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_raw = src_raw + (height - 1) * src_stride_raw; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; src_stride_raw = -src_stride_raw; } // Coalesce rows. - if (src_stride_raw == width * 3 && dst_stride_rgb24 == width * 3) { + if (src_stride_raw == width * 3 && dst_stride_rgb24 == width * 3 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_raw = dst_stride_rgb24 = 0; @@ -1914,27 +4328,63 @@ int RAWToRGB24(const uint8_t* src_raw, } } #endif +#if defined(HAS_RAWTORGB24ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RAWToRGB24Row = RAWToRGB24Row_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + RAWToRGB24Row = RAWToRGB24Row_AVX2; + } + } +#endif +#if defined(HAS_RAWTORGB24ROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + RAWToRGB24Row = RAWToRGB24Row_AVX512BW; + } +#endif +#if defined(HAS_RAWTORGB24ROW_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI)) { + RAWToRGB24Row = RAWToRGB24Row_AVX512VBMI; + } +#endif #if defined(HAS_RAWTORGB24ROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { RAWToRGB24Row = RAWToRGB24Row_Any_NEON; - if (IS_ALIGNED(width, 8)) { + if (IS_ALIGNED(width, 16)) { RAWToRGB24Row = RAWToRGB24Row_NEON; } } #endif -#if defined(HAS_RAWTORGB24ROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - RAWToRGB24Row = RAWToRGB24Row_Any_MSA; +#if defined(HAS_RAWTORGB24ROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + RAWToRGB24Row = RAWToRGB24Row_SVE2; + } +#endif +#if defined(HAS_RAWTORGB24ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + RAWToRGB24Row = RAWToRGB24Row_Any_LSX; if (IS_ALIGNED(width, 16)) { - RAWToRGB24Row = RAWToRGB24Row_MSA; + RAWToRGB24Row = RAWToRGB24Row_LSX; } } #endif -#if defined(HAS_RAWTORGB24ROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - RAWToRGB24Row = RAWToRGB24Row_Any_MMI; - if (IS_ALIGNED(width, 4)) { - RAWToRGB24Row = RAWToRGB24Row_MMI; +#if defined(HAS_RAWTORGB24ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + RAWToRGB24Row = RAWToRGB24Row_Any_LASX; + if (IS_ALIGNED(width, 32)) { + RAWToRGB24Row = RAWToRGB24Row_LASX; + } + } +#endif +#if defined(HAS_RAWTORGB24ROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + RAWToRGB24Row = RAWToRGB24Row_RVV; + } +#endif +#if defined(HAS_RAWTORGB24ROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + RAWToRGB24Row = RAWToRGB24Row_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + RAWToRGB24Row = RAWToRGB24Row_WASMSIMD; } } #endif @@ -1947,6 +4397,7 @@ int RAWToRGB24(const uint8_t* src_raw, return 0; } +// TODO(fbarchard): Consider uint8_t value LIBYUV_API void SetPlane(uint8_t* dst_y, int dst_stride_y, @@ -1954,14 +4405,18 @@ void SetPlane(uint8_t* dst_y, int height, uint32_t value) { int y; - void (*SetRow)(uint8_t * dst, uint8_t value, int width) = SetRow_C; + void (*SetRow)(uint8_t* dst, uint8_t value, int width) = SetRow_C; + + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows. - if (dst_stride_y == width) { + if (dst_stride_y == width && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; dst_stride_y = 0; @@ -1974,11 +4429,11 @@ void SetPlane(uint8_t* dst_y, } } #endif -#if defined(HAS_SETROW_X86) - if (TestCpuFlag(kCpuHasX86)) { - SetRow = SetRow_Any_X86; - if (IS_ALIGNED(width, 4)) { - SetRow = SetRow_X86; +#if defined(HAS_SETROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SetRow = SetRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + SetRow = SetRow_AVX2; } } #endif @@ -1987,15 +4442,31 @@ void SetPlane(uint8_t* dst_y, SetRow = SetRow_ERMS; } #endif -#if defined(HAS_SETROW_MSA) - if (TestCpuFlag(kCpuHasMSA) && IS_ALIGNED(width, 16)) { - SetRow = SetRow_MSA; +#if defined(HAS_SETROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + SetRow = SetRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + SetRow = SetRow_LSX; + } + } +#endif +#if defined(HAS_SETROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + SetRow = SetRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + SetRow = SetRow_LASX; + } + } +#endif +#if defined(HAS_SETROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SetRow = SetRow_HVX; } #endif // Set plane for (y = 0; y < height; ++y) { - SetRow(dst_y, value, width); + SetRow(dst_y, (uint8_t)value, width); dst_y += dst_stride_y; } } @@ -2020,9 +4491,10 @@ int I420Rect(uint8_t* dst_y, uint8_t* start_y = dst_y + y * dst_stride_y + x; uint8_t* start_u = dst_u + (y / 2) * dst_stride_u + (x / 2); uint8_t* start_v = dst_v + (y / 2) * dst_stride_v + (x / 2); - if (!dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || x < 0 || - y < 0 || value_y < 0 || value_y > 255 || value_u < 0 || value_u > 255 || - value_v < 0 || value_v > 255) { + + if (!dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN || x < 0 || y < 0 || value_y < 0 || value_y > 255 || + value_u < 0 || value_u > 255 || value_v < 0 || value_v > 255) { return -1; } @@ -2042,19 +4514,20 @@ int ARGBRect(uint8_t* dst_argb, int height, uint32_t value) { int y; - void (*ARGBSetRow)(uint8_t * dst_argb, uint32_t value, int width) = + void (*ARGBSetRow)(uint8_t* dst_argb, uint32_t value, int width) = ARGBSetRow_C; - if (!dst_argb || width <= 0 || height == 0 || dst_x < 0 || dst_y < 0) { + if (!dst_argb || width <= 0 || height == 0 || height == INT_MIN || + dst_x < 0 || dst_y < 0) { return -1; } if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } dst_argb += dst_y * dst_stride_argb + dst_x * 4; // Coalesce rows. - if (dst_stride_argb == width * 4) { + if (dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; dst_stride_argb = 0; @@ -2068,19 +4541,40 @@ int ARGBRect(uint8_t* dst_argb, } } #endif -#if defined(HAS_ARGBSETROW_X86) - if (TestCpuFlag(kCpuHasX86)) { - ARGBSetRow = ARGBSetRow_X86; +#if defined(HAS_ARGBSETROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBSetRow = ARGBSetRow_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + ARGBSetRow = ARGBSetRow_AVX2; + } } #endif -#if defined(HAS_ARGBSETROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBSetRow = ARGBSetRow_Any_MSA; +#if defined(HAS_ARGBSETROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBSetRow = ARGBSetRow_Any_LSX; if (IS_ALIGNED(width, 4)) { - ARGBSetRow = ARGBSetRow_MSA; + ARGBSetRow = ARGBSetRow_LSX; } } #endif +#if defined(HAS_ARGBSETROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBSetRow = ARGBSetRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBSetRow = ARGBSetRow_LASX; + } + } +#endif +#if defined(HAS_ARGBSETROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBSetRow = ARGBSetRow_HVX; + } +#endif +#if defined(HAS_ARGBSETROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBSetRow = ARGBSetRow_RVV; + } +#endif // Set plane for (y = 0; y < height; ++y) { @@ -2113,16 +4607,18 @@ int ARGBAttenuate(const uint8_t* src_argb, int y; void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width) = ARGBAttenuateRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_argb == width * 4) { + if (src_stride_argb == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_argb = 0; @@ -2143,6 +4639,11 @@ int ARGBAttenuate(const uint8_t* src_argb, } } #endif +#if defined(HAS_ARGBATTENUATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBAttenuateRow = ARGBAttenuateRow_AVX512BW; + } +#endif #if defined(HAS_ARGBATTENUATEROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ARGBAttenuateRow = ARGBAttenuateRow_Any_NEON; @@ -2151,22 +4652,32 @@ int ARGBAttenuate(const uint8_t* src_argb, } } #endif -#if defined(HAS_ARGBATTENUATEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBAttenuateRow = ARGBAttenuateRow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - ARGBAttenuateRow = ARGBAttenuateRow_MSA; +#if defined(HAS_ARGBATTENUATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBAttenuateRow = ARGBAttenuateRow_LSX; } } #endif -#if defined(HAS_ARGBATTENUATEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBAttenuateRow = ARGBAttenuateRow_Any_MMI; - if (IS_ALIGNED(width, 2)) { - ARGBAttenuateRow = ARGBAttenuateRow_MMI; +#if defined(HAS_ARGBATTENUATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBAttenuateRow = ARGBAttenuateRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBAttenuateRow = ARGBAttenuateRow_LASX; } } #endif +#if defined(HAS_ARGBATTENUATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBAttenuateRow = ARGBAttenuateRow_RVV; + } +#endif +#if defined(HAS_ARGBATTENUATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBAttenuateRow = ARGBAttenuateRow_HVX; + } +#endif for (y = 0; y < height; ++y) { ARGBAttenuateRow(src_argb, dst_argb, width); @@ -2187,16 +4698,18 @@ int ARGBUnattenuate(const uint8_t* src_argb, int y; void (*ARGBUnattenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width) = ARGBUnattenuateRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_argb == width * 4) { + if (src_stride_argb == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_argb = 0; @@ -2217,7 +4730,14 @@ int ARGBUnattenuate(const uint8_t* src_argb, } } #endif - // TODO(fbarchard): Neon version. +#if defined(HAS_ARGBUNATTENUATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBUnattenuateRow = ARGBUnattenuateRow_Any_NEON; + if (IS_ALIGNED(width, 4)) { + ARGBUnattenuateRow = ARGBUnattenuateRow_NEON; + } + } +#endif for (y = 0; y < height; ++y) { ARGBUnattenuateRow(src_argb, dst_argb, width); @@ -2238,23 +4758,35 @@ int ARGBGrayTo(const uint8_t* src_argb, int y; void (*ARGBGrayRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width) = ARGBGrayRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_argb == width * 4) { + if (src_stride_argb == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_argb = 0; } -#if defined(HAS_ARGBGRAYROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3) && IS_ALIGNED(width, 8)) { - ARGBGrayRow = ARGBGrayRow_SSSE3; +#if defined(HAS_ARGBGRAYROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBGrayRow = ARGBGrayRow_AVX2; + } +#endif +#if defined(HAS_ARGBGRAYROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBGrayRow = ARGBGrayRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBGRAYROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBGrayRow = ARGBGrayRow_AVX512VNNI; } #endif #if defined(HAS_ARGBGRAYROW_NEON) @@ -2262,14 +4794,19 @@ int ARGBGrayTo(const uint8_t* src_argb, ARGBGrayRow = ARGBGrayRow_NEON; } #endif -#if defined(HAS_ARGBGRAYROW_MSA) - if (TestCpuFlag(kCpuHasMSA) && IS_ALIGNED(width, 8)) { - ARGBGrayRow = ARGBGrayRow_MSA; +#if defined(HAS_ARGBGRAYROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd) && IS_ALIGNED(width, 8)) { + ARGBGrayRow = ARGBGrayRow_NEON_DotProd; } #endif -#if defined(HAS_ARGBGRAYROW_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(width, 2)) { - ARGBGrayRow = ARGBGrayRow_MMI; +#if defined(HAS_ARGBGRAYROW_LSX) + if (TestCpuFlag(kCpuHasLSX) && IS_ALIGNED(width, 8)) { + ARGBGrayRow = ARGBGrayRow_LSX; + } +#endif +#if defined(HAS_ARGBGRAYROW_LASX) + if (TestCpuFlag(kCpuHasLASX) && IS_ALIGNED(width, 16)) { + ARGBGrayRow = ARGBGrayRow_LASX; } #endif @@ -2297,14 +4834,24 @@ int ARGBGray(uint8_t* dst_argb, return -1; } // Coalesce rows. - if (dst_stride_argb == width * 4) { + if (dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; dst_stride_argb = 0; } -#if defined(HAS_ARGBGRAYROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3) && IS_ALIGNED(width, 8)) { - ARGBGrayRow = ARGBGrayRow_SSSE3; +#if defined(HAS_ARGBGRAYROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBGrayRow = ARGBGrayRow_AVX2; + } +#endif +#if defined(HAS_ARGBGRAYROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBGrayRow = ARGBGrayRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBGRAYROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBGrayRow = ARGBGrayRow_AVX512VNNI; } #endif #if defined(HAS_ARGBGRAYROW_NEON) @@ -2312,14 +4859,19 @@ int ARGBGray(uint8_t* dst_argb, ARGBGrayRow = ARGBGrayRow_NEON; } #endif -#if defined(HAS_ARGBGRAYROW_MSA) - if (TestCpuFlag(kCpuHasMSA) && IS_ALIGNED(width, 8)) { - ARGBGrayRow = ARGBGrayRow_MSA; +#if defined(HAS_ARGBGRAYROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd) && IS_ALIGNED(width, 8)) { + ARGBGrayRow = ARGBGrayRow_NEON_DotProd; } #endif -#if defined(HAS_ARGBGRAYROW_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(width, 2)) { - ARGBGrayRow = ARGBGrayRow_MMI; +#if defined(HAS_ARGBGRAYROW_LSX) + if (TestCpuFlag(kCpuHasLSX) && IS_ALIGNED(width, 8)) { + ARGBGrayRow = ARGBGrayRow_LSX; + } +#endif +#if defined(HAS_ARGBGRAYROW_LASX) + if (TestCpuFlag(kCpuHasLASX) && IS_ALIGNED(width, 16)) { + ARGBGrayRow = ARGBGrayRow_LASX; } #endif @@ -2339,20 +4891,25 @@ int ARGBSepia(uint8_t* dst_argb, int width, int height) { int y; - void (*ARGBSepiaRow)(uint8_t * dst_argb, int width) = ARGBSepiaRow_C; + void (*ARGBSepiaRow)(uint8_t* dst_argb, int width) = ARGBSepiaRow_C; uint8_t* dst = dst_argb + dst_y * dst_stride_argb + dst_x * 4; if (!dst_argb || width <= 0 || height <= 0 || dst_x < 0 || dst_y < 0) { return -1; } // Coalesce rows. - if (dst_stride_argb == width * 4) { + if (dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; dst_stride_argb = 0; } -#if defined(HAS_ARGBSEPIAROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3) && IS_ALIGNED(width, 8)) { - ARGBSepiaRow = ARGBSepiaRow_SSSE3; +#if defined(HAS_ARGBSEPIAROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBSepiaRow = ARGBSepiaRow_AVX2; + } +#endif +#if defined(HAS_ARGBSEPIAROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBSepiaRow = ARGBSepiaRow_AVX512VNNI; } #endif #if defined(HAS_ARGBSEPIAROW_NEON) @@ -2360,14 +4917,19 @@ int ARGBSepia(uint8_t* dst_argb, ARGBSepiaRow = ARGBSepiaRow_NEON; } #endif -#if defined(HAS_ARGBSEPIAROW_MSA) - if (TestCpuFlag(kCpuHasMSA) && IS_ALIGNED(width, 8)) { - ARGBSepiaRow = ARGBSepiaRow_MSA; +#if defined(HAS_ARGBSEPIAROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd) && IS_ALIGNED(width, 8)) { + ARGBSepiaRow = ARGBSepiaRow_NEON_DotProd; } #endif -#if defined(HAS_ARGBSEPIAROW_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(width, 2)) { - ARGBSepiaRow = ARGBSepiaRow_MMI; +#if defined(HAS_ARGBSEPIAROW_LSX) + if (TestCpuFlag(kCpuHasLSX) && IS_ALIGNED(width, 8)) { + ARGBSepiaRow = ARGBSepiaRow_LSX; + } +#endif +#if defined(HAS_ARGBSEPIAROW_LASX) + if (TestCpuFlag(kCpuHasLASX) && IS_ALIGNED(width, 16)) { + ARGBSepiaRow = ARGBSepiaRow_LASX; } #endif @@ -2392,23 +4954,30 @@ int ARGBColorMatrix(const uint8_t* src_argb, void (*ARGBColorMatrixRow)(const uint8_t* src_argb, uint8_t* dst_argb, const int8_t* matrix_argb, int width) = ARGBColorMatrixRow_C; - if (!src_argb || !dst_argb || !matrix_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || !matrix_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_argb == width * 4) { + if (src_stride_argb == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_argb = 0; } -#if defined(HAS_ARGBCOLORMATRIXROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3) && IS_ALIGNED(width, 8)) { - ARGBColorMatrixRow = ARGBColorMatrixRow_SSSE3; +#if defined(HAS_ARGBCOLORMATRIXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBColorMatrixRow = ARGBColorMatrixRow_AVX2; + } +#endif +#if defined(HAS_ARGBCOLORMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBColorMatrixRow = ARGBColorMatrixRow_AVX512VNNI; } #endif #if defined(HAS_ARGBCOLORMATRIXROW_NEON) @@ -2416,14 +4985,19 @@ int ARGBColorMatrix(const uint8_t* src_argb, ARGBColorMatrixRow = ARGBColorMatrixRow_NEON; } #endif -#if defined(HAS_ARGBCOLORMATRIXROW_MSA) - if (TestCpuFlag(kCpuHasMSA) && IS_ALIGNED(width, 8)) { - ARGBColorMatrixRow = ARGBColorMatrixRow_MSA; +#if defined(HAS_ARGBCOLORMATRIXROW_NEON_I8MM) + if (TestCpuFlag(kCpuHasNeonI8MM) && IS_ALIGNED(width, 8)) { + ARGBColorMatrixRow = ARGBColorMatrixRow_NEON_I8MM; } #endif -#if defined(HAS_ARGBCOLORMATRIXROW_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(width, 2)) { - ARGBColorMatrixRow = ARGBColorMatrixRow_MMI; +#if defined(HAS_ARGBCOLORMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX) && IS_ALIGNED(width, 4)) { + ARGBColorMatrixRow = ARGBColorMatrixRow_LSX; + } +#endif +#if defined(HAS_ARGBCOLORMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX) && IS_ALIGNED(width, 8)) { + ARGBColorMatrixRow = ARGBColorMatrixRow_LASX; } #endif for (y = 0; y < height; ++y) { @@ -2482,7 +5056,7 @@ int ARGBColorTable(uint8_t* dst_argb, int width, int height) { int y; - void (*ARGBColorTableRow)(uint8_t * dst_argb, const uint8_t* table_argb, + void (*ARGBColorTableRow)(uint8_t* dst_argb, const uint8_t* table_argb, int width) = ARGBColorTableRow_C; uint8_t* dst = dst_argb + dst_y * dst_stride_argb + dst_x * 4; if (!dst_argb || !table_argb || width <= 0 || height <= 0 || dst_x < 0 || @@ -2490,14 +5064,19 @@ int ARGBColorTable(uint8_t* dst_argb, return -1; } // Coalesce rows. - if (dst_stride_argb == width * 4) { + if (dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; dst_stride_argb = 0; } -#if defined(HAS_ARGBCOLORTABLEROW_X86) - if (TestCpuFlag(kCpuHasX86)) { - ARGBColorTableRow = ARGBColorTableRow_X86; +#if defined(HAS_ARGBCOLORTABLEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBColorTableRow = ARGBColorTableRow_AVX2; + } +#endif +#if defined(HAS_ARGBCOLORTABLEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBColorTableRow = ARGBColorTableRow_NEON; } #endif for (y = 0; y < height; ++y) { @@ -2518,7 +5097,7 @@ int RGBColorTable(uint8_t* dst_argb, int width, int height) { int y; - void (*RGBColorTableRow)(uint8_t * dst_argb, const uint8_t* table_argb, + void (*RGBColorTableRow)(uint8_t* dst_argb, const uint8_t* table_argb, int width) = RGBColorTableRow_C; uint8_t* dst = dst_argb + dst_y * dst_stride_argb + dst_x * 4; if (!dst_argb || !table_argb || width <= 0 || height <= 0 || dst_x < 0 || @@ -2526,14 +5105,19 @@ int RGBColorTable(uint8_t* dst_argb, return -1; } // Coalesce rows. - if (dst_stride_argb == width * 4) { + if (dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; dst_stride_argb = 0; } -#if defined(HAS_RGBCOLORTABLEROW_X86) - if (TestCpuFlag(kCpuHasX86)) { - RGBColorTableRow = RGBColorTableRow_X86; +#if defined(HAS_RGBCOLORTABLEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + RGBColorTableRow = RGBColorTableRow_AVX2; + } +#endif +#if defined(HAS_RGBCOLORTABLEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + RGBColorTableRow = RGBColorTableRow_NEON; } #endif for (y = 0; y < height; ++y) { @@ -2563,7 +5147,7 @@ int ARGBQuantize(uint8_t* dst_argb, int width, int height) { int y; - void (*ARGBQuantizeRow)(uint8_t * dst_argb, int scale, int interval_size, + void (*ARGBQuantizeRow)(uint8_t* dst_argb, int scale, int interval_size, int interval_offset, int width) = ARGBQuantizeRow_C; uint8_t* dst = dst_argb + dst_y * dst_stride_argb + dst_x * 4; if (!dst_argb || width <= 0 || height <= 0 || dst_x < 0 || dst_y < 0 || @@ -2571,14 +5155,14 @@ int ARGBQuantize(uint8_t* dst_argb, return -1; } // Coalesce rows. - if (dst_stride_argb == width * 4) { + if (dst_stride_argb == width * 4 && (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; dst_stride_argb = 0; } -#if defined(HAS_ARGBQUANTIZEROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(width, 4)) { - ARGBQuantizeRow = ARGBQuantizeRow_SSE2; +#if defined(HAS_ARGBQUANTIZEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBQuantizeRow = ARGBQuantizeRow_AVX2; } #endif #if defined(HAS_ARGBQUANTIZEROW_NEON) @@ -2586,9 +5170,14 @@ int ARGBQuantize(uint8_t* dst_argb, ARGBQuantizeRow = ARGBQuantizeRow_NEON; } #endif -#if defined(HAS_ARGBQUANTIZEROW_MSA) - if (TestCpuFlag(kCpuHasMSA) && IS_ALIGNED(width, 8)) { - ARGBQuantizeRow = ARGBQuantizeRow_MSA; +#if defined(HAS_ARGBQUANTIZEROW_LSX) + if (TestCpuFlag(kCpuHasLSX) && IS_ALIGNED(width, 4)) { + ARGBQuantizeRow = ARGBQuantizeRow_LSX; + } +#endif +#if defined(HAS_ARGBQUANTIZEROW_LASX) + if (TestCpuFlag(kCpuHasLASX) && IS_ALIGNED(width, 8)) { + ARGBQuantizeRow = ARGBQuantizeRow_LASX; } #endif for (y = 0; y < height; ++y) { @@ -2615,14 +5204,14 @@ int ARGBComputeCumulativeSum(const uint8_t* src_argb, if (!dst_cumsum || !src_argb || width <= 0 || height <= 0) { return -1; } -#if defined(HAS_CUMULATIVESUMTOAVERAGEROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ComputeCumulativeSumRow = ComputeCumulativeSumRow_SSE2; +#if defined(HAS_COMPUTECUMULATIVESUMROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ComputeCumulativeSumRow = ComputeCumulativeSumRow_AVX2; } #endif -#if defined(HAS_CUMULATIVESUMTOAVERAGEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ComputeCumulativeSumRow = ComputeCumulativeSumRow_MMI; +#if defined(HAS_COMPUTECUMULATIVESUMROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ComputeCumulativeSumRow = ComputeCumulativeSumRow_NEON; } #endif @@ -2661,12 +5250,13 @@ int ARGBBlur(const uint8_t* src_argb, int32_t* max_cumsum_bot_row; int32_t* cumsum_top_row; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } if (radius > height) { @@ -2675,18 +5265,19 @@ int ARGBBlur(const uint8_t* src_argb, if (radius > (width / 2 - 1)) { radius = width / 2 - 1; } - if (radius <= 0) { + if (radius <= 0 || height <= 1) { return -1; } -#if defined(HAS_CUMULATIVESUMTOAVERAGEROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ComputeCumulativeSumRow = ComputeCumulativeSumRow_SSE2; - CumulativeSumToAverageRow = CumulativeSumToAverageRow_SSE2; +#if defined(HAS_CUMULATIVESUMTOAVERAGEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ComputeCumulativeSumRow = ComputeCumulativeSumRow_AVX2; + CumulativeSumToAverageRow = CumulativeSumToAverageRow_AVX2; } #endif -#if defined(HAS_CUMULATIVESUMTOAVERAGEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ComputeCumulativeSumRow = ComputeCumulativeSumRow_MMI; +#if defined(HAS_CUMULATIVESUMTOAVERAGEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ComputeCumulativeSumRow = ComputeCumulativeSumRow_NEON; + CumulativeSumToAverageRow = CumulativeSumToAverageRow_NEON; } #endif // Compute enough CumulativeSum for first row to be blurred. After this @@ -2766,23 +5357,25 @@ int ARGBShade(const uint8_t* src_argb, int y; void (*ARGBShadeRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width, uint32_t value) = ARGBShadeRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0 || value == 0u) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN || value == 0u) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_argb == width * 4) { + if (src_stride_argb == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_argb = 0; } -#if defined(HAS_ARGBSHADEROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(width, 4)) { - ARGBShadeRow = ARGBShadeRow_SSE2; +#if defined(HAS_ARGBSHADEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBShadeRow = ARGBShadeRow_AVX2; } #endif #if defined(HAS_ARGBSHADEROW_NEON) @@ -2790,14 +5383,14 @@ int ARGBShade(const uint8_t* src_argb, ARGBShadeRow = ARGBShadeRow_NEON; } #endif -#if defined(HAS_ARGBSHADEROW_MSA) - if (TestCpuFlag(kCpuHasMSA) && IS_ALIGNED(width, 4)) { - ARGBShadeRow = ARGBShadeRow_MSA; +#if defined(HAS_ARGBSHADEROW_LSX) + if (TestCpuFlag(kCpuHasLSX) && IS_ALIGNED(width, 4)) { + ARGBShadeRow = ARGBShadeRow_LSX; } #endif -#if defined(HAS_ARGBSHADEROW_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(width, 2)) { - ARGBShadeRow = ARGBShadeRow_MMI; +#if defined(HAS_ARGBSHADEROW_LASX) + if (TestCpuFlag(kCpuHasLASX) && IS_ALIGNED(width, 8)) { + ARGBShadeRow = ARGBShadeRow_LASX; } #endif @@ -2821,32 +5414,26 @@ int InterpolatePlane(const uint8_t* src0, int height, int interpolation) { int y; - void (*InterpolateRow)(uint8_t * dst_ptr, const uint8_t* src_ptr, + void (*InterpolateRow)(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_C; - if (!src0 || !src1 || !dst || width <= 0 || height == 0) { + if (!src0 || !src1 || !dst || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst = dst + (height - 1) * dst_stride; + dst = dst + (ptrdiff_t)(height - 1) * dst_stride; dst_stride = -dst_stride; } // Coalesce rows. - if (src_stride0 == width && src_stride1 == width && dst_stride == width) { + if (src_stride0 == width && src_stride1 == width && dst_stride == width && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride0 = src_stride1 = dst_stride = 0; } -#if defined(HAS_INTERPOLATEROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - InterpolateRow = InterpolateRow_SSSE3; - } - } -#endif #if defined(HAS_INTERPOLATEROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { InterpolateRow = InterpolateRow_Any_AVX2; @@ -2855,6 +5442,11 @@ int InterpolatePlane(const uint8_t* src0, } } #endif +#if defined(HAS_INTERPOLATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_AVX512BW; + } +#endif #if defined(HAS_INTERPOLATEROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { InterpolateRow = InterpolateRow_Any_NEON; @@ -2863,22 +5455,50 @@ int InterpolatePlane(const uint8_t* src0, } } #endif -#if defined(HAS_INTERPOLATEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - InterpolateRow = InterpolateRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - InterpolateRow = InterpolateRow_MSA; +#if defined(HAS_INTERPOLATEROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + InterpolateRow = InterpolateRow_SVE2; + } +#endif +#if defined(HAS_INTERPOLATEROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + InterpolateRow = InterpolateRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + InterpolateRow = InterpolateRow_LSX; } } #endif -#if defined(HAS_INTERPOLATEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - InterpolateRow = InterpolateRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - InterpolateRow = InterpolateRow_MMI; +#if defined(HAS_INTERPOLATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + InterpolateRow = InterpolateRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + InterpolateRow = InterpolateRow_LASX; } } #endif +#if defined(HAS_INTERPOLATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + InterpolateRow = InterpolateRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + InterpolateRow = InterpolateRow_WASMSIMD; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_HVX; + } +#endif for (y = 0; y < height; ++y) { InterpolateRow(dst, src0, src1 - src0, width, interpolation); @@ -2889,6 +5509,87 @@ int InterpolatePlane(const uint8_t* src0, return 0; } +// Interpolate 2 planes by specified amount (0 to 255). +LIBYUV_API +int InterpolatePlane_16(const uint16_t* src0, + int src_stride0, + const uint16_t* src1, + int src_stride1, + uint16_t* dst, + int dst_stride, + int width, + int height, + int interpolation) { + int y; + void (*InterpolateRow_16)(uint16_t* dst_ptr, const uint16_t* src_ptr, + ptrdiff_t src_stride, int dst_width, + int source_y_fraction) = InterpolateRow_16_C; + if (!src0 || !src1 || !dst || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst = dst + (ptrdiff_t)(height - 1) * dst_stride; + dst_stride = -dst_stride; + } + // Coalesce rows. + if (src_stride0 == width && src_stride1 == width && dst_stride == width && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride0 = src_stride1 = dst_stride = 0; + } +#if defined(HAS_INTERPOLATEROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + InterpolateRow_16 = InterpolateRow_16_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + InterpolateRow_16 = InterpolateRow_16_AVX2; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow_16 = InterpolateRow_16_AVX512BW; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + InterpolateRow_16 = InterpolateRow_16_Any_NEON; + if (IS_ALIGNED(width, 8)) { + InterpolateRow_16 = InterpolateRow_16_NEON; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow_16 = InterpolateRow_16_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow_16 = InterpolateRow_16_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + InterpolateRow_16 = InterpolateRow_16_WASMSIMD; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow_16 = InterpolateRow_16_HVX; + } +#endif + + for (y = 0; y < height; ++y) { + InterpolateRow_16(dst, src0, src1 - src0, width, interpolation); + src0 += src_stride0; + src1 += src_stride1; + dst += dst_stride; + } + return 0; +} + // Interpolate 2 ARGB images by specified amount (0 to 255). LIBYUV_API int ARGBInterpolate(const uint8_t* src_argb0, @@ -2930,10 +5631,13 @@ int I420Interpolate(const uint8_t* src0_y, int interpolation) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; + if (!src0_y || !src0_u || !src0_v || !src1_y || !src1_u || !src1_v || - !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } + InterpolatePlane(src0_y, src0_stride_y, src1_y, src1_stride_y, dst_y, dst_stride_y, width, height, interpolation); InterpolatePlane(src0_u, src0_stride_u, src1_u, src1_stride_u, dst_u, @@ -2945,30 +5649,32 @@ int I420Interpolate(const uint8_t* src0_y, // Shuffle ARGB channel order. e.g. BGRA to ARGB. LIBYUV_API -int ARGBShuffle(const uint8_t* src_bgra, - int src_stride_bgra, +int ARGBShuffle(const uint8_t* src_argb, + int src_stride_argb, uint8_t* dst_argb, int dst_stride_argb, const uint8_t* shuffler, int width, int height) { int y; - void (*ARGBShuffleRow)(const uint8_t* src_bgra, uint8_t* dst_argb, + void (*ARGBShuffleRow)(const uint8_t* src_argb, uint8_t* dst_argb, const uint8_t* shuffler, int width) = ARGBShuffleRow_C; - if (!src_bgra || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_bgra = src_bgra + (height - 1) * src_stride_bgra; - src_stride_bgra = -src_stride_bgra; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; + src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_bgra == width * 4 && dst_stride_argb == width * 4) { + if (src_stride_argb == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; - src_stride_bgra = dst_stride_argb = 0; + src_stride_argb = dst_stride_argb = 0; } #if defined(HAS_ARGBSHUFFLEROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { @@ -2986,6 +5692,11 @@ int ARGBShuffle(const uint8_t* src_bgra, } } #endif +#if defined(HAS_ARGBSHUFFLEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBShuffleRow = ARGBShuffleRow_AVX512BW; + } +#endif #if defined(HAS_ARGBSHUFFLEROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ARGBShuffleRow = ARGBShuffleRow_Any_NEON; @@ -2994,31 +5705,212 @@ int ARGBShuffle(const uint8_t* src_bgra, } } #endif -#if defined(HAS_ARGBSHUFFLEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBShuffleRow = ARGBShuffleRow_Any_MSA; - if (IS_ALIGNED(width, 8)) { - ARGBShuffleRow = ARGBShuffleRow_MSA; +#if defined(HAS_ARGBSHUFFLEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBShuffleRow = ARGBShuffleRow_Any_LSX; + if (IS_ALIGNED(width, 4)) { + ARGBShuffleRow = ARGBShuffleRow_LSX; } } #endif -#if defined(HAS_ARGBSHUFFLEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBShuffleRow = ARGBShuffleRow_Any_MMI; - if (IS_ALIGNED(width, 2)) { - ARGBShuffleRow = ARGBShuffleRow_MMI; +#if defined(HAS_ARGBSHUFFLEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBShuffleRow = ARGBShuffleRow_Any_LASX; + if (IS_ALIGNED(width, 8)) { + ARGBShuffleRow = ARGBShuffleRow_LASX; } } #endif +#if defined(HAS_ARGBSHUFFLEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBShuffleRow = ARGBShuffleRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 4)) { + ARGBShuffleRow = ARGBShuffleRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBSHUFFLEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBShuffleRow = ARGBShuffleRow_RVV; + } +#endif for (y = 0; y < height; ++y) { - ARGBShuffleRow(src_bgra, dst_argb, shuffler, width); - src_bgra += src_stride_bgra; + ARGBShuffleRow(src_argb, dst_argb, shuffler, width); + src_argb += src_stride_argb; dst_argb += dst_stride_argb; } return 0; } +// Shuffle AR64 channel order. e.g. AR64 to AB64. +LIBYUV_API +int AR64Shuffle(const uint16_t* src_ar64, + int src_stride_ar64, + uint16_t* dst_ar64, + int dst_stride_ar64, + const uint8_t* shuffler, + int width, + int height) { + int y; + void (*AR64ShuffleRow)(const uint8_t* src_ar64, uint8_t* dst_ar64, + const uint8_t* shuffler, int width) = AR64ShuffleRow_C; + if (!src_ar64 || !dst_ar64 || width <= 0 || height == 0 || + height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_ar64 = src_ar64 + (ptrdiff_t)(height - 1) * src_stride_ar64; + src_stride_ar64 = -src_stride_ar64; + } + // Coalesce rows. + if (src_stride_ar64 == width * 4 && dst_stride_ar64 == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { + width *= height; + height = 1; + src_stride_ar64 = dst_stride_ar64 = 0; + } + // Assembly versions can be reused if it's implemented with shuffle. +#if defined(HAS_ARGBSHUFFLEROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + AR64ShuffleRow = ARGBShuffleRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + AR64ShuffleRow = ARGBShuffleRow_SSSE3; + } + } +#endif +#if defined(HAS_ARGBSHUFFLEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + AR64ShuffleRow = ARGBShuffleRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + AR64ShuffleRow = ARGBShuffleRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBSHUFFLEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + AR64ShuffleRow = ARGBShuffleRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBSHUFFLEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + AR64ShuffleRow = ARGBShuffleRow_Any_NEON; + if (IS_ALIGNED(width, 4)) { + AR64ShuffleRow = ARGBShuffleRow_NEON; + } + } +#endif +#if defined(HAS_ARGBSHUFFLEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + AR64ShuffleRow = ARGBShuffleRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 4)) { + AR64ShuffleRow = ARGBShuffleRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBSHUFFLEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + AR64ShuffleRow = ARGBShuffleRow_RVV; + } +#endif + + for (y = 0; y < height; ++y) { + AR64ShuffleRow((uint8_t*)(src_ar64), (uint8_t*)(dst_ar64), shuffler, + width * 2); + src_ar64 += src_stride_ar64; + dst_ar64 += dst_stride_ar64; + } + return 0; +} + +// Gauss blur a float plane using Gaussian 5x5 filter with +// coefficients of 1, 4, 6, 4, 1. +// Each destination pixel is a blur of the 5x5 +// pixels from the source. +// Source edges are clamped. +// Edge is 2 pixels on each side, and interior is multiple of 4. +LIBYUV_API +int GaussPlane_F32(const float* src, + int src_stride, + float* dst, + int dst_stride, + int width, + int height) { + int y; + void (*GaussCol_F32)(const float* src0, const float* src1, const float* src2, + const float* src3, const float* src4, float* dst, + int width) = GaussCol_F32_C; + void (*GaussRow_F32)(const float* src, float* dst, int width) = + GaussRow_F32_C; + if (!src || !dst || width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src = src + (ptrdiff_t)(height - 1) * src_stride; + src_stride = -src_stride; + } + +#if defined(HAS_GAUSSCOL_F32_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + GaussCol_F32 = GaussCol_F32_AVX2; + } +#endif +#if defined(HAS_GAUSSCOL_F32_NEON) + if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 8)) { + GaussCol_F32 = GaussCol_F32_NEON; + } +#endif +#if defined(HAS_GAUSSROW_F32_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + GaussRow_F32 = GaussRow_F32_AVX2; + } +#endif +#if defined(HAS_GAUSSROW_F32_NEON) + if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 8)) { + GaussRow_F32 = GaussRow_F32_NEON; + } +#endif + { + // 2 pixels on each side, but aligned out to 16 bytes. + align_buffer_64(rowbuf, (4 + width + 4) * 4); + if (!rowbuf) + return 1; + memset(rowbuf, 0, 16); + memset(rowbuf + (4 + width) * 4, 0, 16); + float* row = (float*)(rowbuf + 16); + const float* src0 = src; + const float* src1 = src; + const float* src2 = src; + const float* src3 = src2 + ((height > 1) ? src_stride : 0); + const float* src4 = src3 + ((height > 2) ? src_stride : 0); + + for (y = 0; y < height; ++y) { + GaussCol_F32(src0, src1, src2, src3, src4, row, width); + + // Extrude edge by 2 floats + row[-2] = row[-1] = row[0]; + row[width + 1] = row[width] = row[width - 1]; + + GaussRow_F32(row - 2, dst, width); + + src0 = src1; + src1 = src2; + src2 = src3; + src3 = src4; + if ((y + 2) < (height - 1)) { + src4 += src_stride; + } + dst += dst_stride; + } + free_aligned_buffer_64(rowbuf); + } + return 0; +} + // Sobel ARGB effect. static int ARGBSobelize(const uint8_t* src_argb, int src_stride_argb, @@ -3031,68 +5923,115 @@ static int ARGBSobelize(const uint8_t* src_argb, uint8_t* dst, int width)) { int y; - void (*ARGBToYJRow)(const uint8_t* src_argb, uint8_t* dst_g, int width) = - ARGBToYJRow_C; + void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_g, int width, + const struct ArgbConstants* c) = ARGBToYMatrixRow_C; void (*SobelYRow)(const uint8_t* src_y0, const uint8_t* src_y1, uint8_t* dst_sobely, int width) = SobelYRow_C; void (*SobelXRow)(const uint8_t* src_y0, const uint8_t* src_y1, const uint8_t* src_y2, uint8_t* dst_sobely, int width) = SobelXRow_C; const int kEdge = 16; // Extra pixels at start of row for extrude/align. - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } -#if defined(HAS_ARGBTOYJROW_SSSE3) +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { - ARGBToYJRow = ARGBToYJRow_Any_SSSE3; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_SSSE3; if (IS_ALIGNED(width, 16)) { - ARGBToYJRow = ARGBToYJRow_SSSE3; + ARGBToYMatrixRow = ARGBToYMatrixRow_SSSE3; } } #endif -#if defined(HAS_ARGBTOYJROW_AVX2) +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - ARGBToYJRow = ARGBToYJRow_Any_AVX2; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_AVX2; if (IS_ALIGNED(width, 32)) { - ARGBToYJRow = ARGBToYJRow_AVX2; + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX2; } } #endif -#if defined(HAS_ARGBTOYJROW_NEON) +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) + if (TestCpuFlag(kCpuHasAVX512VNNI) && TestCpuFlag(kCpuHasAVX512VBMI)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_AVX512VNNIVBMI; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - ARGBToYJRow = ARGBToYJRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - ARGBToYJRow = ARGBToYJRow_NEON; - } - } -#endif -#if defined(HAS_ARGBTOYJROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBToYJRow = ARGBToYJRow_Any_MSA; + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON; if (IS_ALIGNED(width, 16)) { - ARGBToYJRow = ARGBToYJRow_MSA; + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON; } } #endif -#if defined(HAS_ARGBTOYJROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBToYJRow = ARGBToYJRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBToYJRow = ARGBToYJRow_MMI; +#if defined(HAS_ARGBTOYMATRIXROW_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_NEON_DotProd; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_NEON_DotProd; } } #endif +#if defined(HAS_ARGBTOYMATRIXROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_SVE2; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LSX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_LASX; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_RVV; + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_WASMSIMD; + } + } +#endif +#if defined(HAS_ARGBTOYMATRIXROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBToYMatrixRow = ARGBToYMatrixRow_HVX; + } +#endif -#if defined(HAS_SOBELYROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - SobelYRow = SobelYRow_SSE2; +#if defined(HAS_SOBELYROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SobelYRow = SobelYRow_AVX2; } #endif #if defined(HAS_SOBELYROW_NEON) @@ -3100,52 +6039,34 @@ static int ARGBSobelize(const uint8_t* src_argb, SobelYRow = SobelYRow_NEON; } #endif -#if defined(HAS_SOBELYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - SobelYRow = SobelYRow_MSA; - } -#endif -#if defined(HAS_SOBELYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - SobelYRow = SobelYRow_MMI; - } -#endif -#if defined(HAS_SOBELXROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - SobelXRow = SobelXRow_SSE2; +#if defined(HAS_SOBELXROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SobelXRow = SobelXRow_AVX2; } #endif #if defined(HAS_SOBELXROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { SobelXRow = SobelXRow_NEON; } -#endif -#if defined(HAS_SOBELXROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - SobelXRow = SobelXRow_MSA; - } -#endif -#if defined(HAS_SOBELXROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - SobelXRow = SobelXRow_MMI; - } #endif { // 3 rows with edges before/after. - const int kRowSize = (width + kEdge + 31) & ~31; - align_buffer_64(rows, kRowSize * 2 + (kEdge + kRowSize * 3 + kEdge)); + const int row_size = (width + kEdge + 31) & ~31; + align_buffer_64(rows, row_size * 2 + (kEdge + row_size * 3 + kEdge)); uint8_t* row_sobelx = rows; - uint8_t* row_sobely = rows + kRowSize; - uint8_t* row_y = rows + kRowSize * 2; + uint8_t* row_sobely = rows + row_size; + uint8_t* row_y = rows + row_size * 2; // Convert first row. uint8_t* row_y0 = row_y + kEdge; - uint8_t* row_y1 = row_y0 + kRowSize; - uint8_t* row_y2 = row_y1 + kRowSize; - ARGBToYJRow(src_argb, row_y0, width); + uint8_t* row_y1 = row_y0 + row_size; + uint8_t* row_y2 = row_y1 + row_size; + if (!rows) + return 1; + ARGBToYMatrixRow(src_argb, row_y0, width, &kArgbJPEGConstants); row_y0[-1] = row_y0[0]; memset(row_y0 + width, row_y0[width - 1], 16); // Extrude 16 for valgrind. - ARGBToYJRow(src_argb, row_y1, width); + ARGBToYMatrixRow(src_argb, row_y1, width, &kArgbJPEGConstants); row_y1[-1] = row_y1[0]; memset(row_y1 + width, row_y1[width - 1], 16); memset(row_y2 + width, 0, 16); @@ -3155,7 +6076,7 @@ static int ARGBSobelize(const uint8_t* src_argb, if (y < (height - 1)) { src_argb += src_stride_argb; } - ARGBToYJRow(src_argb, row_y2, width); + ARGBToYMatrixRow(src_argb, row_y2, width, &kArgbJPEGConstants); row_y2[-1] = row_y2[0]; row_y2[width] = row_y2[width - 1]; @@ -3188,11 +6109,11 @@ int ARGBSobel(const uint8_t* src_argb, int height) { void (*SobelRow)(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width) = SobelRow_C; -#if defined(HAS_SOBELROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - SobelRow = SobelRow_Any_SSE2; +#if defined(HAS_SOBELROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SobelRow = SobelRow_Any_AVX2; if (IS_ALIGNED(width, 16)) { - SobelRow = SobelRow_SSE2; + SobelRow = SobelRow_AVX2; } } #endif @@ -3204,19 +6125,19 @@ int ARGBSobel(const uint8_t* src_argb, } } #endif -#if defined(HAS_SOBELROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - SobelRow = SobelRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - SobelRow = SobelRow_MSA; +#if defined(HAS_SOBELROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + SobelRow = SobelRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + SobelRow = SobelRow_LSX; } } #endif -#if defined(HAS_SOBELROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - SobelRow = SobelRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - SobelRow = SobelRow_MMI; +#if defined(HAS_SOBELROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + SobelRow = SobelRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + SobelRow = SobelRow_LASX; } } #endif @@ -3234,11 +6155,11 @@ int ARGBSobelToPlane(const uint8_t* src_argb, int height) { void (*SobelToPlaneRow)(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_, int width) = SobelToPlaneRow_C; -#if defined(HAS_SOBELTOPLANEROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - SobelToPlaneRow = SobelToPlaneRow_Any_SSE2; - if (IS_ALIGNED(width, 16)) { - SobelToPlaneRow = SobelToPlaneRow_SSE2; +#if defined(HAS_SOBELTOPLANEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SobelToPlaneRow = SobelToPlaneRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + SobelToPlaneRow = SobelToPlaneRow_AVX2; } } #endif @@ -3250,19 +6171,19 @@ int ARGBSobelToPlane(const uint8_t* src_argb, } } #endif -#if defined(HAS_SOBELTOPLANEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - SobelToPlaneRow = SobelToPlaneRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - SobelToPlaneRow = SobelToPlaneRow_MSA; +#if defined(HAS_SOBELTOPLANEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + SobelToPlaneRow = SobelToPlaneRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + SobelToPlaneRow = SobelToPlaneRow_LSX; } } #endif -#if defined(HAS_SOBELTOPLANEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - SobelToPlaneRow = SobelToPlaneRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - SobelToPlaneRow = SobelToPlaneRow_MMI; +#if defined(HAS_SOBELTOPLANEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + SobelToPlaneRow = SobelToPlaneRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + SobelToPlaneRow = SobelToPlaneRow_LASX; } } #endif @@ -3281,11 +6202,11 @@ int ARGBSobelXY(const uint8_t* src_argb, int height) { void (*SobelXYRow)(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width) = SobelXYRow_C; -#if defined(HAS_SOBELXYROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - SobelXYRow = SobelXYRow_Any_SSE2; +#if defined(HAS_SOBELXYROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SobelXYRow = SobelXYRow_Any_AVX2; if (IS_ALIGNED(width, 16)) { - SobelXYRow = SobelXYRow_SSE2; + SobelXYRow = SobelXYRow_AVX2; } } #endif @@ -3297,19 +6218,19 @@ int ARGBSobelXY(const uint8_t* src_argb, } } #endif -#if defined(HAS_SOBELXYROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - SobelXYRow = SobelXYRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - SobelXYRow = SobelXYRow_MSA; +#if defined(HAS_SOBELXYROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + SobelXYRow = SobelXYRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + SobelXYRow = SobelXYRow_LSX; } } #endif -#if defined(HAS_SOBELXYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - SobelXYRow = SobelXYRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - SobelXYRow = SobelXYRow_MMI; +#if defined(HAS_SOBELXYROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + SobelXYRow = SobelXYRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + SobelXYRow = SobelXYRow_LASX; } } #endif @@ -3329,30 +6250,45 @@ int ARGBPolynomial(const uint8_t* src_argb, int y; void (*ARGBPolynomialRow)(const uint8_t* src_argb, uint8_t* dst_argb, const float* poly, int width) = ARGBPolynomialRow_C; - if (!src_argb || !dst_argb || !poly || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || !poly || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_argb == width * 4) { + if (src_stride_argb == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_argb = 0; } #if defined(HAS_ARGBPOLYNOMIALROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(width, 2)) { - ARGBPolynomialRow = ARGBPolynomialRow_SSE2; + if (TestCpuFlag(kCpuHasSSE2)) { + ARGBPolynomialRow = ARGBPolynomialRow_Any_SSE2; + if (IS_ALIGNED(width, 2)) { + ARGBPolynomialRow = ARGBPolynomialRow_SSE2; + } } #endif #if defined(HAS_ARGBPOLYNOMIALROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2) && TestCpuFlag(kCpuHasFMA3) && - IS_ALIGNED(width, 2)) { - ARGBPolynomialRow = ARGBPolynomialRow_AVX2; + if (TestCpuFlag(kCpuHasAVX2) && TestCpuFlag(kCpuHasFMA3)) { + ARGBPolynomialRow = ARGBPolynomialRow_Any_AVX2; + if (IS_ALIGNED(width, 2)) { + ARGBPolynomialRow = ARGBPolynomialRow_AVX2; + } + } +#endif +#if defined(HAS_ARGBPOLYNOMIALROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBPolynomialRow = ARGBPolynomialRow_Any_NEON; + if (IS_ALIGNED(width, 2)) { + ARGBPolynomialRow = ARGBPolynomialRow_NEON; + } } #endif @@ -3377,7 +6313,7 @@ int HalfFloatPlane(const uint16_t* src_y, int y; void (*HalfFloatRow)(const uint16_t* src, uint16_t* dst, float scale, int width) = HalfFloatRow_C; - if (!src_y || !dst_y || width <= 0 || height == 0) { + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } src_stride_y >>= 1; @@ -3385,23 +6321,16 @@ int HalfFloatPlane(const uint16_t* src_y, // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } // Coalesce rows. - if (src_stride_y == width && dst_stride_y == width) { + if (src_stride_y == width && dst_stride_y == width && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = dst_stride_y = 0; } -#if defined(HAS_HALFFLOATROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - HalfFloatRow = HalfFloatRow_Any_SSE2; - if (IS_ALIGNED(width, 8)) { - HalfFloatRow = HalfFloatRow_SSE2; - } - } -#endif #if defined(HAS_HALFFLOATROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { HalfFloatRow = HalfFloatRow_Any_AVX2; @@ -3419,20 +6348,45 @@ int HalfFloatPlane(const uint16_t* src_y, } } #endif +#if defined(HAS_HALFFLOATROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + HalfFloatRow = HalfFloatRow_AVX512BW; + } +#endif #if defined(HAS_HALFFLOATROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - HalfFloatRow = - (scale == 1.0f) ? HalfFloat1Row_Any_NEON : HalfFloatRow_Any_NEON; - if (IS_ALIGNED(width, 8)) { - HalfFloatRow = (scale == 1.0f) ? HalfFloat1Row_NEON : HalfFloatRow_NEON; + if (TestCpuFlag(kCpuHasNEON) +#if defined(__arm__) + // When scale is 1/65535 the scale * 2^-112 used to convert is a denormal. + // But when Neon vmul is asked to multiply a normal float by that + // denormal scale, even though the result would have been normal, it + // flushes to zero. The scalar version of vmul supports denormals. + && scale >= 1.0f / 4096.0f +#endif + ) { + HalfFloatRow = HalfFloatRow_Any_NEON; + if (IS_ALIGNED(width, 16)) { + HalfFloatRow = HalfFloatRow_NEON; } } #endif -#if defined(HAS_HALFFLOATROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - HalfFloatRow = HalfFloatRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - HalfFloatRow = HalfFloatRow_MSA; +#if defined(HAS_HALFFLOATROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + HalfFloatRow = scale == 1.0f ? HalfFloat1Row_SVE2 : HalfFloatRow_SVE2; + } +#endif +#if defined(HAS_HALFFLOATROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + HalfFloatRow = HalfFloatRow_Any_LSX; + if (IS_ALIGNED(width, 8)) { + HalfFloatRow = HalfFloatRow_LSX; + } + } +#endif +#if defined(HAS_HALFFLOATROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + HalfFloatRow = HalfFloatRow_Any_LASX; + if (IS_ALIGNED(width, 16)) { + HalfFloatRow = HalfFloatRow_LASX; } } #endif @@ -3453,6 +6407,14 @@ int ByteToFloat(const uint8_t* src_y, float* dst_y, float scale, int width) { if (!src_y || !dst_y || width <= 0) { return -1; } +#if defined(HAS_BYTETOFLOATROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ByteToFloatRow = ByteToFloatRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + ByteToFloatRow = ByteToFloatRow_AVX2; + } + } +#endif #if defined(HAS_BYTETOFLOATROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ByteToFloatRow = ByteToFloatRow_Any_NEON; @@ -3479,24 +6441,31 @@ int ARGBLumaColorTable(const uint8_t* src_argb, void (*ARGBLumaColorTableRow)( const uint8_t* src_argb, uint8_t* dst_argb, int width, const uint8_t* luma, const uint32_t lumacoeff) = ARGBLumaColorTableRow_C; - if (!src_argb || !dst_argb || !luma || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || !luma || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_argb == width * 4) { + if (src_stride_argb == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_argb = 0; } -#if defined(HAS_ARGBLUMACOLORTABLEROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3) && IS_ALIGNED(width, 4)) { - ARGBLumaColorTableRow = ARGBLumaColorTableRow_SSSE3; +#if defined(HAS_ARGBLUMACOLORTABLEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ARGBLumaColorTableRow = ARGBLumaColorTableRow_AVX2; + } +#endif +#if defined(HAS_ARGBLUMACOLORTABLEROW_NEON) + if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 4)) { + ARGBLumaColorTableRow = ARGBLumaColorTableRow_NEON; } #endif @@ -3519,21 +6488,31 @@ int ARGBCopyAlpha(const uint8_t* src_argb, int y; void (*ARGBCopyAlphaRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width) = ARGBCopyAlphaRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_argb == width * 4) { + if (src_stride_argb == width * 4 && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_argb = 0; } +#if defined(HAS_ARGBCOPYALPHAROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBCopyAlphaRow = ARGBCopyAlphaRow_Any_NEON; + if (IS_ALIGNED(width, 8)) { + ARGBCopyAlphaRow = ARGBCopyAlphaRow_NEON; + } + } +#endif #if defined(HAS_ARGBCOPYALPHAROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { ARGBCopyAlphaRow = ARGBCopyAlphaRow_Any_SSE2; @@ -3550,12 +6529,9 @@ int ARGBCopyAlpha(const uint8_t* src_argb, } } #endif -#if defined(HAS_ARGBCOPYALPHAROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBCopyAlphaRow = ARGBCopyAlphaRow_Any_MMI; - if (IS_ALIGNED(width, 2)) { - ARGBCopyAlphaRow = ARGBCopyAlphaRow_MMI; - } +#if defined(HAS_ARGBCOPYALPHAROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBCopyAlphaRow = ARGBCopyAlphaRow_HVX; } #endif @@ -3575,17 +6551,18 @@ int ARGBExtractAlpha(const uint8_t* src_argb, int dst_stride_a, int width, int height) { - if (!src_argb || !dst_a || width <= 0 || height == 0) { + if (!src_argb || !dst_a || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb += (height - 1) * src_stride_argb; + src_argb += (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. - if (src_stride_argb == width * 4 && dst_stride_a == width) { + if (src_stride_argb == width * 4 && dst_stride_a == width && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_argb = dst_stride_a = 0; @@ -3604,22 +6581,44 @@ int ARGBExtractAlpha(const uint8_t* src_argb, : ARGBExtractAlphaRow_Any_AVX2; } #endif +#if defined(HAS_ARGBEXTRACTALPHAROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBExtractAlphaRow = ARGBExtractAlphaRow_AVX512BW; + } +#endif #if defined(HAS_ARGBEXTRACTALPHAROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ARGBExtractAlphaRow = IS_ALIGNED(width, 16) ? ARGBExtractAlphaRow_NEON : ARGBExtractAlphaRow_Any_NEON; } #endif -#if defined(HAS_ARGBEXTRACTALPHAROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBExtractAlphaRow = IS_ALIGNED(width, 16) ? ARGBExtractAlphaRow_MSA - : ARGBExtractAlphaRow_Any_MSA; +#if defined(HAS_ARGBEXTRACTALPHAROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ARGBExtractAlphaRow = IS_ALIGNED(width, 8) ? ARGBExtractAlphaRow_LSX + : ARGBExtractAlphaRow_Any_LSX; } #endif -#if defined(HAS_ARGBEXTRACTALPHAROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBExtractAlphaRow = IS_ALIGNED(width, 8) ? ARGBExtractAlphaRow_MMI - : ARGBExtractAlphaRow_Any_MMI; +#if defined(HAS_ARGBEXTRACTALPHAROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + ARGBExtractAlphaRow = IS_ALIGNED(width, 16) ? ARGBExtractAlphaRow_LASX + : ARGBExtractAlphaRow_Any_LASX; + } +#endif +#if defined(HAS_ARGBEXTRACTALPHAROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBExtractAlphaRow = IS_ALIGNED(width, 16) + ? ARGBExtractAlphaRow_WASMSIMD + : ARGBExtractAlphaRow_Any_WASMSIMD; + } +#endif +#if defined(HAS_ARGBEXTRACTALPHAROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBExtractAlphaRow = ARGBExtractAlphaRow_RVV; + } +#endif +#if defined(HAS_ARGBEXTRACTALPHAROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBExtractAlphaRow = ARGBExtractAlphaRow_HVX; } #endif @@ -3642,17 +6641,18 @@ int ARGBCopyYToAlpha(const uint8_t* src_y, int y; void (*ARGBCopyYToAlphaRow)(const uint8_t* src_y, uint8_t* dst_argb, int width) = ARGBCopyYToAlphaRow_C; - if (!src_y || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !dst_argb || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } // Coalesce rows. - if (src_stride_y == width && dst_stride_argb == width * 4) { + if (src_stride_y == width && dst_stride_argb == width * 4 && + (ptrdiff_t)width * height <= INT_MAX) { width *= height; height = 1; src_stride_y = dst_stride_argb = 0; @@ -3673,12 +6673,32 @@ int ARGBCopyYToAlpha(const uint8_t* src_y, } } #endif -#if defined(HAS_ARGBCOPYYTOALPHAROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBCopyYToAlphaRow = ARGBCopyYToAlphaRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - ARGBCopyYToAlphaRow = ARGBCopyYToAlphaRow_MMI; - } +#if defined(HAS_ARGBCOPYYTOALPHAROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ARGBCopyYToAlphaRow = ARGBCopyYToAlphaRow_AVX512BW; + } +#endif +#if defined(HAS_ARGBCOPYYTOALPHAROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ARGBCopyYToAlphaRow = IS_ALIGNED(width, 16) ? ARGBCopyYToAlphaRow_NEON + : ARGBCopyYToAlphaRow_Any_NEON; + } +#endif +#if defined(HAS_ARGBCOPYYTOALPHAROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ARGBCopyYToAlphaRow = IS_ALIGNED(width, 16) + ? ARGBCopyYToAlphaRow_WASMSIMD + : ARGBCopyYToAlphaRow_Any_WASMSIMD; + } +#endif +#if defined(HAS_ARGBCOPYYTOALPHAROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ARGBCopyYToAlphaRow = ARGBCopyYToAlphaRow_RVV; + } +#endif +#if defined(HAS_ARGBCOPYYTOALPHAROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ARGBCopyYToAlphaRow = ARGBCopyYToAlphaRow_HVX; } #endif @@ -3690,9 +6710,6 @@ int ARGBCopyYToAlpha(const uint8_t* src_y, return 0; } -// TODO(fbarchard): Consider if width is even Y channel can be split -// directly. A SplitUVRow_Odd function could copy the remaining chroma. - LIBYUV_API int YUY2ToNV12(const uint8_t* src_yuy2, int src_stride_yuy2, @@ -3703,124 +6720,113 @@ int YUY2ToNV12(const uint8_t* src_yuy2, int width, int height) { int y; - int halfwidth = (width + 1) >> 1; - void (*SplitUVRow)(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, - int width) = SplitUVRow_C; - void (*InterpolateRow)(uint8_t * dst_ptr, const uint8_t* src_ptr, - ptrdiff_t src_stride, int dst_width, - int source_y_fraction) = InterpolateRow_C; - if (!src_yuy2 || !dst_y || !dst_uv || width <= 0 || height == 0) { + void (*YUY2ToYRow)(const uint8_t* src_yuy2, uint8_t* dst_y, int width) = + YUY2ToYRow_C; + void (*YUY2ToNVUVRow)(const uint8_t* src_yuy2, int stride_yuy2, + uint8_t* dst_uv, int width) = YUY2ToNVUVRow_C; + if (!src_yuy2 || !dst_y || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } + // Negative height means invert the image. if (height < 0) { height = -height; - src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; + src_yuy2 = src_yuy2 + (ptrdiff_t)(height - 1) * src_stride_yuy2; src_stride_yuy2 = -src_stride_yuy2; } -#if defined(HAS_SPLITUVROW_SSE2) +#if defined(HAS_YUY2TOYROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { - SplitUVRow = SplitUVRow_Any_SSE2; + YUY2ToYRow = YUY2ToYRow_Any_SSE2; if (IS_ALIGNED(width, 16)) { - SplitUVRow = SplitUVRow_SSE2; + YUY2ToYRow = YUY2ToYRow_SSE2; } } #endif -#if defined(HAS_SPLITUVROW_AVX2) +#if defined(HAS_YUY2TOYROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - SplitUVRow = SplitUVRow_Any_AVX2; + YUY2ToYRow = YUY2ToYRow_Any_AVX2; if (IS_ALIGNED(width, 32)) { - SplitUVRow = SplitUVRow_AVX2; + YUY2ToYRow = YUY2ToYRow_AVX2; } } #endif -#if defined(HAS_SPLITUVROW_NEON) +#if defined(HAS_YUY2TOYROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + YUY2ToYRow = YUY2ToYRow_AVX512BW; + } +#endif +#if defined(HAS_YUY2TOYROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - SplitUVRow = SplitUVRow_Any_NEON; + YUY2ToYRow = YUY2ToYRow_Any_NEON; if (IS_ALIGNED(width, 16)) { - SplitUVRow = SplitUVRow_NEON; + YUY2ToYRow = YUY2ToYRow_NEON; } } #endif -#if defined(HAS_SPLITUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - SplitUVRow = SplitUVRow_Any_MSA; +#if defined(HAS_YUY2TOYROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + YUY2ToYRow = YUY2ToYRow_SVE2; + } +#endif +#if defined(HAS_YUY2TOYROW_LSX) && defined(HAS_YUY2TOUV422ROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + YUY2ToYRow = YUY2ToYRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + YUY2ToYRow = YUY2ToYRow_LSX; + } + } +#endif +#if defined(HAS_YUY2TOYROW_LASX) && defined(HAS_YUY2TOUV422ROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + YUY2ToYRow = YUY2ToYRow_Any_LASX; if (IS_ALIGNED(width, 32)) { - SplitUVRow = SplitUVRow_MSA; + YUY2ToYRow = YUY2ToYRow_LASX; } } #endif -#if defined(HAS_SPLITUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - SplitUVRow = SplitUVRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - SplitUVRow = SplitUVRow_MMI; - } +#if defined(HAS_YUY2TOYROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + YUY2ToYRow = YUY2ToYRow_HVX; } #endif -#if defined(HAS_INTERPOLATEROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_SSSE3; + +#if defined(HAS_YUY2TONVUVROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + YUY2ToNVUVRow = YUY2ToNVUVRow_Any_SSE2; if (IS_ALIGNED(width, 16)) { - InterpolateRow = InterpolateRow_SSSE3; + YUY2ToNVUVRow = YUY2ToNVUVRow_SSE2; } } #endif -#if defined(HAS_INTERPOLATEROW_AVX2) +#if defined(HAS_YUY2TONVUVROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - InterpolateRow = InterpolateRow_Any_AVX2; + YUY2ToNVUVRow = YUY2ToNVUVRow_Any_AVX2; if (IS_ALIGNED(width, 32)) { - InterpolateRow = InterpolateRow_AVX2; + YUY2ToNVUVRow = YUY2ToNVUVRow_AVX2; } } #endif -#if defined(HAS_INTERPOLATEROW_NEON) +#if defined(HAS_YUY2TONVUVROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { - InterpolateRow = InterpolateRow_Any_NEON; + YUY2ToNVUVRow = YUY2ToNVUVRow_Any_NEON; if (IS_ALIGNED(width, 16)) { - InterpolateRow = InterpolateRow_NEON; - } - } -#endif -#if defined(HAS_INTERPOLATEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - InterpolateRow = InterpolateRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - InterpolateRow = InterpolateRow_MSA; - } - } -#endif -#if defined(HAS_INTERPOLATEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - InterpolateRow = InterpolateRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - InterpolateRow = InterpolateRow_MMI; + YUY2ToNVUVRow = YUY2ToNVUVRow_NEON; } } #endif - { - int awidth = halfwidth * 2; - // row of y and 2 rows of uv - align_buffer_64(rows, awidth * 3); - - for (y = 0; y < height - 1; y += 2) { - // Split Y from UV. - SplitUVRow(src_yuy2, rows, rows + awidth, awidth); - memcpy(dst_y, rows, width); - SplitUVRow(src_yuy2 + src_stride_yuy2, rows, rows + awidth * 2, awidth); - memcpy(dst_y + dst_stride_y, rows, width); - InterpolateRow(dst_uv, rows + awidth, awidth, awidth, 128); - src_yuy2 += src_stride_yuy2 * 2; - dst_y += dst_stride_y * 2; - dst_uv += dst_stride_uv; - } - if (height & 1) { - // Split Y from UV. - SplitUVRow(src_yuy2, rows, dst_uv, awidth); - memcpy(dst_y, rows, width); - } - free_aligned_buffer_64(rows); + for (y = 0; y < height - 1; y += 2) { + YUY2ToYRow(src_yuy2, dst_y, width); + YUY2ToYRow(src_yuy2 + src_stride_yuy2, dst_y + dst_stride_y, width); + YUY2ToNVUVRow(src_yuy2, src_stride_yuy2, dst_uv, width); + src_yuy2 += src_stride_yuy2 * 2; + dst_y += dst_stride_y * 2; + dst_uv += dst_stride_uv; + } + if (height & 1) { + YUY2ToYRow(src_yuy2, dst_y, width); + YUY2ToNVUVRow(src_yuy2, 0, dst_uv, width); } return 0; } @@ -3836,24 +6842,30 @@ int UYVYToNV12(const uint8_t* src_uyvy, int height) { int y; int halfwidth = (width + 1) >> 1; + // UYVY rows are processed as awidth (even) samples. Select kernels on the + // width actually passed to them. + int awidth = halfwidth * 2; void (*SplitUVRow)(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, int width) = SplitUVRow_C; - void (*InterpolateRow)(uint8_t * dst_ptr, const uint8_t* src_ptr, + void (*InterpolateRow)(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_C; - if (!src_uyvy || !dst_y || !dst_uv || width <= 0 || height == 0) { + + if (!src_uyvy || !dst_y || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } + // Negative height means invert the image. if (height < 0) { height = -height; - src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; + src_uyvy = src_uyvy + (ptrdiff_t)(height - 1) * src_stride_uyvy; src_stride_uyvy = -src_stride_uyvy; } #if defined(HAS_SPLITUVROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { SplitUVRow = SplitUVRow_Any_SSE2; - if (IS_ALIGNED(width, 16)) { + if (IS_ALIGNED(awidth, 16)) { SplitUVRow = SplitUVRow_SSE2; } } @@ -3861,80 +6873,127 @@ int UYVYToNV12(const uint8_t* src_uyvy, #if defined(HAS_SPLITUVROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { SplitUVRow = SplitUVRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { + if (IS_ALIGNED(awidth, 32)) { SplitUVRow = SplitUVRow_AVX2; } } #endif +#if defined(HAS_SPLITUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + SplitUVRow = SplitUVRow_AVX512BW; + } +#endif #if defined(HAS_SPLITUVROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { SplitUVRow = SplitUVRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { + if (IS_ALIGNED(awidth, 16)) { SplitUVRow = SplitUVRow_NEON; } } #endif -#if defined(HAS_SPLITUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - SplitUVRow = SplitUVRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - SplitUVRow = SplitUVRow_MSA; +#if defined(HAS_SPLITUVROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + SplitUVRow = SplitUVRow_SVE2; + } +#endif +#if defined(HAS_SPLITUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + SplitUVRow = SplitUVRow_Any_LSX; + if (IS_ALIGNED(awidth, 16)) { + SplitUVRow = SplitUVRow_LSX; } } #endif -#if defined(HAS_SPLITUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - SplitUVRow = SplitUVRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - SplitUVRow = SplitUVRow_MMI; +#if defined(HAS_SPLITUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + SplitUVRow = SplitUVRow_Any_LASX; + if (IS_ALIGNED(awidth, 32)) { + SplitUVRow = SplitUVRow_LASX; } } #endif -#if defined(HAS_INTERPOLATEROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_SSSE3; - if (IS_ALIGNED(width, 16)) { - InterpolateRow = InterpolateRow_SSSE3; - } +#if defined(HAS_SPLITUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SplitUVRow = SplitUVRow_RVV; } #endif +#if defined(HAS_SPLITUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SplitUVRow = SplitUVRow_HVX; + } +#endif + #if defined(HAS_INTERPOLATEROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { InterpolateRow = InterpolateRow_Any_AVX2; - if (IS_ALIGNED(width, 32)) { + if (IS_ALIGNED(awidth, 32)) { InterpolateRow = InterpolateRow_AVX2; } } #endif +#if defined(HAS_INTERPOLATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_AVX512BW; + } +#endif #if defined(HAS_INTERPOLATEROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { InterpolateRow = InterpolateRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { + if (IS_ALIGNED(awidth, 16)) { InterpolateRow = InterpolateRow_NEON; } } #endif -#if defined(HAS_INTERPOLATEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - InterpolateRow = InterpolateRow_Any_MSA; - if (IS_ALIGNED(width, 32)) { - InterpolateRow = InterpolateRow_MSA; +#if defined(HAS_INTERPOLATEROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + InterpolateRow = InterpolateRow_SVE2; + } +#endif +#if defined(HAS_INTERPOLATEROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + InterpolateRow = InterpolateRow_Any_LSX; + if (IS_ALIGNED(awidth, 16)) { + InterpolateRow = InterpolateRow_LSX; } } #endif -#if defined(HAS_INTERPOLATEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - InterpolateRow = InterpolateRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - InterpolateRow = InterpolateRow_MMI; +#if defined(HAS_INTERPOLATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + InterpolateRow = InterpolateRow_Any_LASX; + if (IS_ALIGNED(awidth, 32)) { + InterpolateRow = InterpolateRow_LASX; } } #endif +#if defined(HAS_INTERPOLATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + InterpolateRow = InterpolateRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_Any_WASMSIMD; + if (IS_ALIGNED(awidth, 16)) { + InterpolateRow = InterpolateRow_WASMSIMD; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_HVX; + } +#endif { - int awidth = halfwidth * 2; // row of y and 2 rows of uv align_buffer_64(rows, awidth * 3); + if (!rows) + return 1; for (y = 0; y < height - 1; y += 2) { // Split Y from UV. @@ -3957,6 +7016,79 @@ int UYVYToNV12(const uint8_t* src_uyvy, return 0; } +// width and height are src size allowing odd size handling. +LIBYUV_API +void HalfMergeUVPlane(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + int y; + void (*HalfMergeUVRow)(const uint8_t* src_u, int src_stride_u, + const uint8_t* src_v, int src_stride_v, + uint8_t* dst_uv, int width) = HalfMergeUVRow_C; + + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } +#if defined(HAS_HALFMERGEUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 16)) { + HalfMergeUVRow = HalfMergeUVRow_NEON; + } +#endif +#if defined(HAS_HALFMERGEUVROW_SVE2) + // The average of two values must be retained for the final odd element if + // present. Existing code just handles this by falling back to the C + // implementation, so mirror that for SVE2 as well. + if (TestCpuFlag(kCpuHasSVE2) && IS_ALIGNED(width, 2)) { + HalfMergeUVRow = HalfMergeUVRow_SVE2; + } +#endif +#if defined(HAS_HALFMERGEUVROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + HalfMergeUVRow = HalfMergeUVRow_Any_SSSE3; + if (IS_ALIGNED(width, 16)) { + HalfMergeUVRow = HalfMergeUVRow_SSSE3; + } + } +#endif +#if defined(HAS_HALFMERGEUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + HalfMergeUVRow = HalfMergeUVRow_Any_AVX2; + if (IS_ALIGNED(width, 32)) { + HalfMergeUVRow = HalfMergeUVRow_AVX2; + } + } +#endif +#if defined(HAS_HALFMERGEUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + HalfMergeUVRow = HalfMergeUVRow_AVX512BW; + } +#endif + + for (y = 0; y < height - 1; y += 2) { + // Merge a row of U and V into a row of UV. + HalfMergeUVRow(src_u, src_stride_u, src_v, src_stride_v, dst_uv, width); + src_u += src_stride_u * 2; + src_v += src_stride_v * 2; + dst_uv += dst_stride_uv; + } + if (height & 1) { + HalfMergeUVRow(src_u, 0, src_v, 0, dst_uv, width); + } +} + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/source/rotate.cc b/libs/libyuv/source/rotate.cc index d414186a5a..db72843a25 100644 --- a/libs/libyuv/source/rotate.cc +++ b/libs/libyuv/source/rotate.cc @@ -10,6 +10,9 @@ #include "libyuv/rotate.h" +#include +#include + #include "libyuv/convert.h" #include "libyuv/cpu_id.h" #include "libyuv/planar_functions.h" @@ -21,6 +24,21 @@ namespace libyuv { extern "C" { #endif +static void TransposeWxH(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height) { + int i; + for (i = 0; i < width; ++i) { + int j; + for (j = 0; j < height; ++j) { + dst[i * dst_stride + j] = src[j * src_stride + i]; + } + } +} + LIBYUV_API void TransposePlane(const uint8_t* src, int src_stride, @@ -29,57 +47,123 @@ void TransposePlane(const uint8_t* src, int width, int height) { int i = height; -#if defined(HAS_TRANSPOSEWX16_MSA) +#if defined(HAS_TRANSPOSEWXH_SME) || defined(HAS_TRANSPOSEWXH_HVX) + void (*TransposeWxH_fn)(const uint8_t* src, int src_stride, uint8_t* dst, + int dst_stride, int width, int height) = NULL; +#endif +#if defined(HAS_TRANSPOSEWX16_AVX2) || defined(HAS_TRANSPOSEWX16_AVX512BW) || \ + defined(HAS_TRANSPOSEWX16_LASX) || defined(HAS_TRANSPOSEWX16_WASMSIMD) + void (*TransposeWx16)(const uint8_t* src, int src_stride, uint8_t* dst, + int dst_stride, int width) = NULL; +#elif defined(HAS_TRANSPOSEWX16_NEON) void (*TransposeWx16)(const uint8_t* src, int src_stride, uint8_t* dst, int dst_stride, int width) = TransposeWx16_C; -#else +#endif +#if !defined(HAS_TRANSPOSEWX16_NEON) void (*TransposeWx8)(const uint8_t* src, int src_stride, uint8_t* dst, int dst_stride, int width) = TransposeWx8_C; #endif + #if defined(HAS_TRANSPOSEWX8_NEON) if (TestCpuFlag(kCpuHasNEON)) { - TransposeWx8 = TransposeWx8_NEON; - } -#endif -#if defined(HAS_TRANSPOSEWX8_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - TransposeWx8 = TransposeWx8_Any_SSSE3; + TransposeWx8 = TransposeWx8_Any_NEON; if (IS_ALIGNED(width, 8)) { - TransposeWx8 = TransposeWx8_SSSE3; + TransposeWx8 = TransposeWx8_NEON; } } #endif -#if defined(HAS_TRANSPOSEWX8_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - TransposeWx8 = TransposeWx8_MMI; - } -#endif -#if defined(HAS_TRANSPOSEWX8_FAST_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - TransposeWx8 = TransposeWx8_Fast_Any_SSSE3; +#if defined(HAS_TRANSPOSEWX16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + TransposeWx16 = TransposeWx16_Any_NEON; if (IS_ALIGNED(width, 16)) { - TransposeWx8 = TransposeWx8_Fast_SSSE3; + TransposeWx16 = TransposeWx16_NEON; } } #endif -#if defined(HAS_TRANSPOSEWX16_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - TransposeWx16 = TransposeWx16_Any_MSA; +#if defined(HAS_TRANSPOSEWXH_SME) + if (TestCpuFlag(kCpuHasSME)) { + TransposeWxH_fn = TransposeWxH_SME; + } +#endif +#if defined(HAS_TRANSPOSEWXH_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + TransposeWxH_fn = TransposeWxH_HVX; + } +#endif +#if defined(HAS_TRANSPOSEWX8_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + TransposeWx8 = TransposeWx8_Any_AVX2; if (IS_ALIGNED(width, 16)) { - TransposeWx16 = TransposeWx16_MSA; + TransposeWx8 = TransposeWx8_AVX2; + } + } +#endif +#if defined(HAS_TRANSPOSEWX16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + TransposeWx16 = TransposeWx16_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + TransposeWx16 = TransposeWx16_AVX2; + } + } +#endif +#if defined(HAS_TRANSPOSEWX16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + TransposeWx16 = TransposeWx16_AVX512BW; + } +#endif +#if defined(HAS_TRANSPOSEWX8_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + TransposeWx8 = TransposeWx8_Any_LSX; + if (IS_ALIGNED(width, 16)) { + TransposeWx8 = TransposeWx8_LSX; + } + } +#endif +#if defined(HAS_TRANSPOSEWX16_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + TransposeWx16 = TransposeWx16_Any_LASX; + if (IS_ALIGNED(width, 16)) { + TransposeWx16 = TransposeWx16_LASX; + } + } +#endif +#if defined(HAS_TRANSPOSEWX8_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + TransposeWx8 = TransposeWx8_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + TransposeWx8 = TransposeWx8_WASMSIMD; + } + } +#endif +#if defined(HAS_TRANSPOSEWX16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + TransposeWx16 = TransposeWx16_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + TransposeWx16 = TransposeWx16_WASMSIMD; } } #endif -#if defined(HAS_TRANSPOSEWX16_MSA) - // Work across the source in 16x16 tiles - while (i >= 16) { - TransposeWx16(src, src_stride, dst, dst_stride, width); - src += 16 * src_stride; // Go down 16 rows. - dst += 16; // Move over 16 columns. - i -= 16; +#if defined(HAS_TRANSPOSEWXH_SME) || defined(HAS_TRANSPOSEWXH_HVX) + if (TransposeWxH_fn) { + TransposeWxH_fn(src, src_stride, dst, dst_stride, width, height); + return; } -#else +#endif +#if defined(HAS_TRANSPOSEWX16_AVX2) || defined(HAS_TRANSPOSEWX16_AVX512BW) || \ + defined(HAS_TRANSPOSEWX16_LASX) || defined(HAS_TRANSPOSEWX16_NEON) || \ + defined(HAS_TRANSPOSEWX16_WASMSIMD) + // Work across the source in 16x16 tiles + if (TransposeWx16) { + while (i >= 16) { + TransposeWx16(src, src_stride, dst, dst_stride, width); + src += 16 * src_stride; // Go down 16 rows. + dst += 16; // Move over 16 columns. + i -= 16; + } + } +#endif +#if !defined(HAS_TRANSPOSEWX16_NEON) // Work across the source in 8x8 tiles while (i >= 8) { TransposeWx8(src, src_stride, dst, dst_stride, width); @@ -90,7 +174,7 @@ void TransposePlane(const uint8_t* src, #endif if (i > 0) { - TransposeWxH_C(src, src_stride, dst, dst_stride, width, i); + TransposeWxH(src, src_stride, dst, dst_stride, width, i); } } @@ -104,7 +188,7 @@ void RotatePlane90(const uint8_t* src, // Rotate by 90 is a transpose with the source read // from bottom to top. So set the source pointer to the end // of the buffer and flip the sign of the source stride. - src += src_stride * (height - 1); + src += (ptrdiff_t)src_stride * (height - 1); src_stride = -src_stride; TransposePlane(src, src_stride, dst, dst_stride, width, height); } @@ -119,7 +203,7 @@ void RotatePlane270(const uint8_t* src, // Rotate by 270 is a transpose with the destination written // from bottom to top. So set the destination pointer to the end // of the buffer and flip the sign of the destination stride. - dst += dst_stride * (width - 1); + dst += (ptrdiff_t)dst_stride * (width - 1); dst_stride = -dst_stride; TransposePlane(src, src_stride, dst, dst_stride, width, height); } @@ -131,10 +215,13 @@ void RotatePlane180(const uint8_t* src, int dst_stride, int width, int height) { - // Swap first and last row and mirror the content. Uses a temporary row. + // Swap top and bottom row and mirror the content. Uses a temporary row. align_buffer_64(row, width); - const uint8_t* src_bot = src + src_stride * (height - 1); - uint8_t* dst_bot = dst + dst_stride * (height - 1); + assert(row); + if (!row) + return; + const uint8_t* src_bot = src + (ptrdiff_t)src_stride * (height - 1); + uint8_t* dst_bot = dst + (ptrdiff_t)dst_stride * (height - 1); int half_height = (height + 1) >> 1; int y; void (*MirrorRow)(const uint8_t* src, uint8_t* dst, int width) = MirrorRow_C; @@ -142,7 +229,7 @@ void RotatePlane180(const uint8_t* src, #if defined(HAS_MIRRORROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { MirrorRow = MirrorRow_Any_NEON; - if (IS_ALIGNED(width, 16)) { + if (IS_ALIGNED(width, 32)) { MirrorRow = MirrorRow_NEON; } } @@ -163,22 +250,40 @@ void RotatePlane180(const uint8_t* src, } } #endif -#if defined(HAS_MIRRORROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - MirrorRow = MirrorRow_Any_MSA; - if (IS_ALIGNED(width, 64)) { - MirrorRow = MirrorRow_MSA; +#if defined(HAS_MIRRORROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MirrorRow = MirrorRow_AVX512BW; + } +#endif +#if defined(HAS_MIRRORROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + MirrorRow = MirrorRow_Any_LSX; + if (IS_ALIGNED(width, 16)) { + MirrorRow = MirrorRow_LSX; } } #endif -#if defined(HAS_MIRRORROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - MirrorRow = MirrorRow_Any_MMI; - if (IS_ALIGNED(width, 8)) { - MirrorRow = MirrorRow_MMI; +#if defined(HAS_MIRRORROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + MirrorRow = MirrorRow_Any_LASX; + if (IS_ALIGNED(width, 32)) { + MirrorRow = MirrorRow_LASX; } } #endif +#if defined(HAS_MIRRORROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + MirrorRow = MirrorRow_Any_WASMSIMD; + if (IS_ALIGNED(width, 16)) { + MirrorRow = MirrorRow_WASMSIMD; + } + } +#endif +#if defined(HAS_MIRRORROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MirrorRow = MirrorRow_HVX; + } +#endif #if defined(HAS_COPYROW_SSE2) if (TestCpuFlag(kCpuHasSSE2)) { CopyRow = IS_ALIGNED(width, 32) ? CopyRow_SSE2 : CopyRow_Any_SSE2; @@ -189,6 +294,11 @@ void RotatePlane180(const uint8_t* src, CopyRow = IS_ALIGNED(width, 64) ? CopyRow_AVX : CopyRow_Any_AVX; } #endif +#if defined(HAS_COPYROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + CopyRow = CopyRow_AVX512BW; + } +#endif #if defined(HAS_COPYROW_ERMS) if (TestCpuFlag(kCpuHasERMS)) { CopyRow = CopyRow_ERMS; @@ -199,85 +309,188 @@ void RotatePlane180(const uint8_t* src, CopyRow = IS_ALIGNED(width, 32) ? CopyRow_NEON : CopyRow_Any_NEON; } #endif -#if defined(HAS_COPYROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - CopyRow = IS_ALIGNED(width, 8) ? CopyRow_MMI : CopyRow_Any_MMI; +#if defined(HAS_COPYROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + CopyRow = CopyRow_SVE2; + } +#endif +#if defined(HAS_COPYROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + CopyRow = CopyRow_SME; + } +#endif +#if defined(HAS_COPYROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + CopyRow = CopyRow_RVV; + } +#endif +#if defined(HAS_COPYROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + CopyRow = CopyRow_HVX; + } +#endif +#if defined(HAS_COPYROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + CopyRow = IS_ALIGNED(width, 16) ? CopyRow_LSX : CopyRow_Any_LSX; + } +#endif +#if defined(HAS_COPYROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + CopyRow = IS_ALIGNED(width, 32) ? CopyRow_LASX : CopyRow_Any_LASX; } #endif // Odd height will harmlessly mirror the middle row twice. for (y = 0; y < half_height; ++y) { - MirrorRow(src, row, width); // Mirror first row into a buffer + CopyRow(src, row, width); // Copy top row into buffer + MirrorRow(src_bot, dst, width); // Mirror bottom row into top row + MirrorRow(row, dst_bot, width); // Mirror buffer into bottom row src += src_stride; - MirrorRow(src_bot, dst, width); // Mirror last row into first row dst += dst_stride; - CopyRow(row, dst_bot, width); // Copy first mirrored row into last src_bot -= src_stride; dst_bot -= dst_stride; } free_aligned_buffer_64(row); } +static void TransposeUVWxH(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height) { + int i; + for (i = 0; i < width * 2; i += 2) { + int j; + for (j = 0; j < height; ++j) { + dst_a[((i >> 1) * dst_stride_a) + j] = src[i + (j * src_stride)]; + dst_b[((i >> 1) * dst_stride_b) + j] = src[i + (j * src_stride) + 1]; + } + } +} + LIBYUV_API -void TransposeUV(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width, - int height) { +void SplitTransposeUV(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height) { int i = height; -#if defined(HAS_TRANSPOSEUVWX16_MSA) +#if defined(HAS_TRANSPOSEUVWXH_SME) || defined(HAS_TRANSPOSEUVWXH_HVX) + void (*TransposeUVWxH_fn)(const uint8_t* src, int src_stride, uint8_t* dst_a, + int dst_stride_a, uint8_t* dst_b, int dst_stride_b, + int width, int height) = NULL; +#endif +#if defined(HAS_TRANSPOSEUVWX16_AVX2) || \ + defined(HAS_TRANSPOSEUVWX16_AVX512BW) || \ + defined(HAS_TRANSPOSEUVWX16_LASX) || defined(HAS_TRANSPOSEUVWX16_WASMSIMD) void (*TransposeUVWx16)(const uint8_t* src, int src_stride, uint8_t* dst_a, int dst_stride_a, uint8_t* dst_b, int dst_stride_b, - int width) = TransposeUVWx16_C; -#else + int width) = NULL; +#endif void (*TransposeUVWx8)(const uint8_t* src, int src_stride, uint8_t* dst_a, int dst_stride_a, uint8_t* dst_b, int dst_stride_b, int width) = TransposeUVWx8_C; + +#if defined(HAS_TRANSPOSEUVWX8_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + TransposeUVWx8 = TransposeUVWx8_Any_LSX; + if (IS_ALIGNED(width, 8)) { + TransposeUVWx8 = TransposeUVWx8_LSX; + } + } +#endif +#if defined(HAS_TRANSPOSEUVWX16_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + TransposeUVWx16 = TransposeUVWx16_Any_LASX; + if (IS_ALIGNED(width, 8)) { + TransposeUVWx16 = TransposeUVWx16_LASX; + } + } #endif #if defined(HAS_TRANSPOSEUVWX8_NEON) if (TestCpuFlag(kCpuHasNEON)) { - TransposeUVWx8 = TransposeUVWx8_NEON; - } -#endif -#if defined(HAS_TRANSPOSEUVWX8_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - TransposeUVWx8 = TransposeUVWx8_Any_SSE2; + TransposeUVWx8 = TransposeUVWx8_Any_NEON; if (IS_ALIGNED(width, 8)) { - TransposeUVWx8 = TransposeUVWx8_SSE2; + TransposeUVWx8 = TransposeUVWx8_NEON; } } #endif -#if defined(HAS_TRANSPOSEUVWX8_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - TransposeUVWx8 = TransposeUVWx8_Any_MMI; - if (IS_ALIGNED(width, 4)) { - TransposeUVWx8 = TransposeUVWx8_MMI; +#if defined(HAS_TRANSPOSEUVWXH_SME) + if (TestCpuFlag(kCpuHasSME)) { + TransposeUVWxH_fn = TransposeUVWxH_SME; + } +#endif +#if defined(HAS_TRANSPOSEUVWXH_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + TransposeUVWxH_fn = TransposeUVWxH_HVX; + } +#endif +#if defined(HAS_TRANSPOSEUVWX8_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + TransposeUVWx8 = TransposeUVWx8_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + TransposeUVWx8 = TransposeUVWx8_AVX2; } } #endif -#if defined(HAS_TRANSPOSEUVWX16_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - TransposeUVWx16 = TransposeUVWx16_Any_MSA; +#if defined(HAS_TRANSPOSEUVWX16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + TransposeUVWx16 = TransposeUVWx16_Any_AVX2; if (IS_ALIGNED(width, 8)) { - TransposeUVWx16 = TransposeUVWx16_MSA; + TransposeUVWx16 = TransposeUVWx16_AVX2; + } + } +#endif +#if defined(HAS_TRANSPOSEUVWX16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + TransposeUVWx16 = TransposeUVWx16_AVX512BW; + } +#endif +#if defined(HAS_TRANSPOSEUVWX8_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + TransposeUVWx8 = TransposeUVWx8_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + TransposeUVWx8 = TransposeUVWx8_WASMSIMD; + } + } +#endif +#if defined(HAS_TRANSPOSEUVWX16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + TransposeUVWx16 = TransposeUVWx16_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + TransposeUVWx16 = TransposeUVWx16_WASMSIMD; } } #endif -#if defined(HAS_TRANSPOSEUVWX16_MSA) - // Work through the source in 8x8 tiles. - while (i >= 16) { - TransposeUVWx16(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, - width); - src += 16 * src_stride; // Go down 16 rows. - dst_a += 16; // Move over 8 columns. - dst_b += 16; // Move over 8 columns. - i -= 16; +#if defined(HAS_TRANSPOSEUVWXH_SME) || defined(HAS_TRANSPOSEUVWXH_HVX) + if (TransposeUVWxH_fn) { + TransposeUVWxH_fn(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, + width, i); + return; } -#else +#endif +#if defined(HAS_TRANSPOSEUVWX16_AVX2) || \ + defined(HAS_TRANSPOSEUVWX16_AVX512BW) || \ + defined(HAS_TRANSPOSEUVWX16_LASX) || defined(HAS_TRANSPOSEUVWX16_WASMSIMD) + // Work through the source in 16x16 tiles. + if (TransposeUVWx16) { + while (i >= 16) { + TransposeUVWx16(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, + width); + src += 16 * src_stride; // Go down 16 rows. + dst_a += 16; // Move over 16 columns. + dst_b += 16; // Move over 16 columns. + i -= 16; + } + } +#endif // Work through the source in 8x8 tiles. while (i >= 8) { TransposeUVWx8(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, @@ -287,79 +500,104 @@ void TransposeUV(const uint8_t* src, dst_b += 8; // Move over 8 columns. i -= 8; } -#endif if (i > 0) { - TransposeUVWxH_C(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, - width, i); + TransposeUVWxH(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, + width, i); } } LIBYUV_API -void RotateUV90(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width, - int height) { - src += src_stride * (height - 1); +void SplitRotateUV90(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height) { + src += (ptrdiff_t)src_stride * (height - 1); src_stride = -src_stride; - TransposeUV(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, width, - height); + SplitTransposeUV(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, + width, height); } LIBYUV_API -void RotateUV270(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width, - int height) { +void SplitRotateUV270(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height) { dst_a += dst_stride_a * (width - 1); dst_b += dst_stride_b * (width - 1); dst_stride_a = -dst_stride_a; dst_stride_b = -dst_stride_b; - TransposeUV(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, width, - height); + SplitTransposeUV(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, + width, height); } // Rotate 180 is a horizontal and vertical flip. LIBYUV_API -void RotateUV180(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width, - int height) { +void SplitRotateUV180(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height) { int i; - void (*MirrorUVRow)(const uint8_t* src, uint8_t* dst_u, uint8_t* dst_v, - int width) = MirrorUVRow_C; -#if defined(HAS_MIRRORUVROW_NEON) - if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 8)) { - MirrorUVRow = MirrorUVRow_NEON; + void (*MirrorSplitUVRow)(const uint8_t* src, uint8_t* dst_u, uint8_t* dst_v, + int width) = MirrorSplitUVRow_C; +#if defined(HAS_MIRRORSPLITUVROW_NEON) + if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 16)) { + MirrorSplitUVRow = MirrorSplitUVRow_NEON; } #endif -#if defined(HAS_MIRRORUVROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3) && IS_ALIGNED(width, 16)) { - MirrorUVRow = MirrorUVRow_SSSE3; +#if defined(HAS_MIRRORSPLITUVROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + MirrorSplitUVRow = MirrorSplitUVRow_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + MirrorSplitUVRow = MirrorSplitUVRow_SSSE3; + } } #endif -#if defined(HAS_MIRRORUVROW_MSA) - if (TestCpuFlag(kCpuHasMSA) && IS_ALIGNED(width, 32)) { - MirrorUVRow = MirrorUVRow_MSA; +#if defined(HAS_MIRRORSPLITUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + MirrorSplitUVRow = MirrorSplitUVRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + MirrorSplitUVRow = MirrorSplitUVRow_AVX2; + } } #endif -#if defined(HAS_MIRRORUVROW_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(width, 8)) { - MirrorUVRow = MirrorUVRow_MMI; +#if defined(HAS_MIRRORSPLITUVROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + MirrorSplitUVRow = MirrorSplitUVRow_AVX512BW; + } +#endif +#if defined(HAS_MIRRORSPLITUVROW_LSX) + if (TestCpuFlag(kCpuHasLSX) && IS_ALIGNED(width, 16)) { + MirrorSplitUVRow = MirrorSplitUVRow_LSX; + } +#endif +#if defined(HAS_MIRRORSPLITUVROW_LASX) + if (TestCpuFlag(kCpuHasLASX) && IS_ALIGNED(width, 32)) { + MirrorSplitUVRow = MirrorSplitUVRow_LASX; + } +#endif +#if defined(HAS_MIRRORSPLITUVROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD) && IS_ALIGNED(width, 16)) { + MirrorSplitUVRow = MirrorSplitUVRow_WASMSIMD; + } +#endif +#if defined(HAS_MIRRORSPLITUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + MirrorSplitUVRow = MirrorSplitUVRow_HVX; } #endif @@ -367,13 +605,60 @@ void RotateUV180(const uint8_t* src, dst_b += dst_stride_b * (height - 1); for (i = 0; i < height; ++i) { - MirrorUVRow(src, dst_a, dst_b, width); + MirrorSplitUVRow(src, dst_a, dst_b, width); src += src_stride; dst_a -= dst_stride_a; dst_b -= dst_stride_b; } } +// Rotate UV and split into planar. +// width and height expected to be half size for NV12 +LIBYUV_API +int SplitRotateUV(const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode mode) { + if (!src_uv || width <= 0 || height == 0 || height == INT_MIN || !dst_u || + !dst_v) { + return -1; + } + + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_uv = src_uv + (ptrdiff_t)(height - 1) * src_stride_uv; + src_stride_uv = -src_stride_uv; + } + + switch (mode) { + case kRotate0: + SplitUVPlane(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, + dst_stride_v, width, height); + return 0; + case kRotate90: + SplitRotateUV90(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, + dst_stride_v, width, height); + return 0; + case kRotate270: + SplitRotateUV270(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, + dst_stride_v, width, height); + return 0; + case kRotate180: + SplitRotateUV180(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, + dst_stride_v, width, height); + return 0; + default: + break; + } + return -1; +} + LIBYUV_API int RotatePlane(const uint8_t* src, int src_stride, @@ -382,14 +667,14 @@ int RotatePlane(const uint8_t* src, int width, int height, enum RotationMode mode) { - if (!src || width <= 0 || height == 0 || !dst) { + if (!src || width <= 0 || height == 0 || height == INT_MIN || !dst) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src = src + (height - 1) * src_stride; + src = src + (ptrdiff_t)(height - 1) * src_stride; src_stride = -src_stride; } @@ -413,6 +698,235 @@ int RotatePlane(const uint8_t* src, return -1; } +static void TransposeWxH_16(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height) { + int i; + for (i = 0; i < width; ++i) { + int j; + for (j = 0; j < height; ++j) { + dst[i * dst_stride + j] = src[j * src_stride + i]; + } + } +} + +static void TransposePlane_16(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height) { + int i = height; +#if defined(HAS_TRANSPOSEWXH_16_SME) || defined(HAS_TRANSPOSEWXH_16_RVV) || \ + defined(HAS_TRANSPOSEWXH_16_HVX) + void (*TransposeWxH_16_fn)(const uint16_t* src, int src_stride, uint16_t* dst, + int dst_stride, int width, int height) = NULL; +#endif +#if defined(HAS_TRANSPOSEWX32_16_AVX512BW) + void (*TransposeWx32_16)(const uint16_t* src, int src_stride, uint16_t* dst, + int dst_stride, int width) = NULL; +#endif +#if defined(HAS_TRANSPOSEWX16_16_AVX2) || defined(HAS_TRANSPOSEWX16_16_LASX) + void (*TransposeWx16_16)(const uint16_t* src, int src_stride, uint16_t* dst, + int dst_stride, int width) = NULL; +#endif + void (*TransposeWx8_16)(const uint16_t* src, int src_stride, uint16_t* dst, + int dst_stride, int width) = TransposeWx8_16_C; + +#if defined(HAS_TRANSPOSEWX8_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + TransposeWx8_16 = TransposeWx8_16_Any_NEON; + if (IS_ALIGNED(width, 8)) { + TransposeWx8_16 = TransposeWx8_16_NEON; + } + } +#endif +#if defined(HAS_TRANSPOSEWX8_16_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + TransposeWx8_16 = TransposeWx8_16_SVE2; + } +#endif +#if defined(HAS_TRANSPOSEWXH_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + TransposeWxH_16_fn = TransposeWxH_16_SME; + } +#endif +#if defined(HAS_TRANSPOSEWXH_16_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + TransposeWxH_16_fn = TransposeWxH_16_RVV; + } +#endif +#if defined(HAS_TRANSPOSEWXH_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + TransposeWxH_16_fn = TransposeWxH_16_HVX; + } +#endif +#if defined(HAS_TRANSPOSEWX8_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + TransposeWx8_16 = TransposeWx8_16_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + TransposeWx8_16 = TransposeWx8_16_AVX2; + } + } +#endif +#if defined(HAS_TRANSPOSEWX16_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + TransposeWx16_16 = TransposeWx16_16_Any_AVX2; + if (IS_ALIGNED(width, 8)) { + TransposeWx16_16 = TransposeWx16_16_AVX2; + } + } +#endif +#if defined(HAS_TRANSPOSEWX32_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + TransposeWx32_16 = TransposeWx32_16_AVX512BW; + } +#endif +#if defined(HAS_TRANSPOSEWX8_16_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + TransposeWx8_16 = TransposeWx8_16_Any_LSX; + if (IS_ALIGNED(width, 8)) { + TransposeWx8_16 = TransposeWx8_16_LSX; + } + } +#endif +#if defined(HAS_TRANSPOSEWX16_16_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + TransposeWx16_16 = TransposeWx16_16_Any_LASX; + if (IS_ALIGNED(width, 8)) { + TransposeWx16_16 = TransposeWx16_16_LASX; + } + } +#endif +#if defined(HAS_TRANSPOSEWX8_16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + TransposeWx8_16 = TransposeWx8_16_Any_WASMSIMD; + if (IS_ALIGNED(width, 8)) { + TransposeWx8_16 = TransposeWx8_16_WASMSIMD; + } + } +#endif + +#if defined(HAS_TRANSPOSEWXH_16_SME) || defined(HAS_TRANSPOSEWXH_16_RVV) || \ + defined(HAS_TRANSPOSEWXH_16_HVX) + if (TransposeWxH_16_fn) { + TransposeWxH_16_fn(src, src_stride, dst, dst_stride, width, height); + return; + } +#endif +#if defined(HAS_TRANSPOSEWX32_16_AVX512BW) + if (TransposeWx32_16) { + while (i >= 32) { + TransposeWx32_16(src, src_stride, dst, dst_stride, width); + src += 32 * (ptrdiff_t)src_stride; + dst += 32; + i -= 32; + } + } +#endif +#if defined(HAS_TRANSPOSEWX16_16_AVX2) || defined(HAS_TRANSPOSEWX16_16_LASX) + if (TransposeWx16_16) { + while (i >= 16) { + TransposeWx16_16(src, src_stride, dst, dst_stride, width); + src += 16 * (ptrdiff_t)src_stride; + dst += 16; + i -= 16; + } + } +#endif + // Work across the source in 8x8 tiles + while (i >= 8) { + TransposeWx8_16(src, src_stride, dst, dst_stride, width); + src += 8 * (ptrdiff_t)src_stride; // Go down 8 rows. + dst += 8; // Move over 8 columns. + i -= 8; + } + + if (i > 0) { + TransposeWxH_16(src, src_stride, dst, dst_stride, width, i); + } +} + +static void RotatePlane90_16(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height) { + // Rotate by 90 is a transpose with the source read + // from bottom to top. So set the source pointer to the end + // of the buffer and flip the sign of the source stride. + src += (ptrdiff_t)src_stride * (height - 1); + src_stride = -src_stride; + TransposePlane_16(src, src_stride, dst, dst_stride, width, height); +} + +static void RotatePlane270_16(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height) { + // Rotate by 270 is a transpose with the destination written + // from bottom to top. So set the destination pointer to the end + // of the buffer and flip the sign of the destination stride. + dst += (ptrdiff_t)dst_stride * (width - 1); + dst_stride = -dst_stride; + TransposePlane_16(src, src_stride, dst, dst_stride, width, height); +} + +static void RotatePlane180_16(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height) { + // Rotate by 180 is a vertical flip (negative height) and horizontal mirror. + MirrorPlane_16(src, src_stride, dst, dst_stride, width, -height); +} + +LIBYUV_API +int RotatePlane_16(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height, + enum RotationMode mode) { + if (!src || width <= 0 || height == 0 || height == INT_MIN || !dst) { + return -1; + } + + // Negative height means invert the image. + if (height < 0) { + height = -height; + src = src + (ptrdiff_t)(height - 1) * src_stride; + src_stride = -src_stride; + } + + switch (mode) { + case kRotate0: + // copy frame + CopyPlane_16(src, src_stride, dst, dst_stride, width, height); + return 0; + case kRotate90: + RotatePlane90_16(src, src_stride, dst, dst_stride, width, height); + return 0; + case kRotate270: + RotatePlane270_16(src, src_stride, dst, dst_stride, width, height); + return 0; + case kRotate180: + RotatePlane180_16(src, src_stride, dst, dst_stride, width, height); + return 0; + default: + break; + } + return -1; +} + LIBYUV_API int I420Rotate(const uint8_t* src_y, int src_stride_y, @@ -431,8 +945,8 @@ int I420Rotate(const uint8_t* src_y, enum RotationMode mode) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || !dst_y || - !dst_u || !dst_v) { + if ((!src_y && dst_y) || !src_u || !src_v || width <= 0 || height == 0 || + height == INT_MIN || !dst_y || !dst_u || !dst_v) { return -1; } @@ -440,9 +954,9 @@ int I420Rotate(const uint8_t* src_y, if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -481,6 +995,107 @@ int I420Rotate(const uint8_t* src_y, return -1; } +// I422 has half width x full height UV planes, so rotate by 90 and 270 +// require scaling to maintain 422 subsampling. +LIBYUV_API +int I422Rotate(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode mode) { + int halfwidth = (width + 1) >> 1; + int halfheight = (height + 1) >> 1; + int r; + if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || + height == INT_MIN || !dst_y || !dst_u || !dst_v) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + + switch (mode) { + case kRotate0: + // Copy frame + CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, height); + CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, height); + return 0; + + // Note on temporary Y plane for UV. + // Rotation of UV first fits within the Y destination plane rows. + // Y plane is width x height + // Y plane rotated is height x width + // UV plane is (width / 2) x height + // UV plane rotated is height x (width / 2) + // UV plane rotated+scaled is (height / 2) x width. + // UV plane rotated is a temporary that fits within the Y plane rotated. + + case kRotate90: + RotatePlane90(src_u, src_stride_u, dst_y, dst_stride_y, halfwidth, + height); + r = ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_u, + dst_stride_u, halfheight, width, kFilterBilinear); + if (r != 0) { + return r; + } + RotatePlane90(src_v, src_stride_v, dst_y, dst_stride_y, halfwidth, + height); + r = ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_v, + dst_stride_v, halfheight, width, kFilterLinear); + if (r != 0) { + return r; + } + RotatePlane90(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + return 0; + case kRotate270: + RotatePlane270(src_u, src_stride_u, dst_y, dst_stride_y, halfwidth, + height); + r = ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_u, + dst_stride_u, halfheight, width, kFilterBilinear); + if (r != 0) { + return r; + } + RotatePlane270(src_v, src_stride_v, dst_y, dst_stride_y, halfwidth, + height); + r = ScalePlane(dst_y, dst_stride_y, height, halfwidth, dst_v, + dst_stride_v, halfheight, width, kFilterLinear); + if (r != 0) { + return r; + } + RotatePlane270(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + return 0; + case kRotate180: + RotatePlane180(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + RotatePlane180(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, + height); + RotatePlane180(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, + height); + return 0; + default: + break; + } + return -1; +} + LIBYUV_API int I444Rotate(const uint8_t* src_y, int src_stride_y, @@ -496,41 +1111,41 @@ int I444Rotate(const uint8_t* src_y, int dst_stride_v, int width, int height, - enum libyuv::RotationMode mode) { - if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || !dst_y || - !dst_u || !dst_v) { + enum RotationMode mode) { + if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || + height == INT_MIN || !dst_y || !dst_u || !dst_v) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; } switch (mode) { - case libyuv::kRotate0: + case kRotate0: // copy frame CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, width, height); CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, width, height); return 0; - case libyuv::kRotate90: + case kRotate90: RotatePlane90(src_y, src_stride_y, dst_y, dst_stride_y, width, height); RotatePlane90(src_u, src_stride_u, dst_u, dst_stride_u, width, height); RotatePlane90(src_v, src_stride_v, dst_v, dst_stride_v, width, height); return 0; - case libyuv::kRotate270: + case kRotate270: RotatePlane270(src_y, src_stride_y, dst_y, dst_stride_y, width, height); RotatePlane270(src_u, src_stride_u, dst_u, dst_stride_u, width, height); RotatePlane270(src_v, src_stride_v, dst_v, dst_stride_v, width, height); return 0; - case libyuv::kRotate180: + case kRotate180: RotatePlane180(src_y, src_stride_y, dst_y, dst_stride_y, width, height); RotatePlane180(src_u, src_stride_u, dst_u, dst_stride_u, width, height); RotatePlane180(src_v, src_stride_v, dst_v, dst_stride_v, width, height); @@ -557,8 +1172,8 @@ int NV12ToI420Rotate(const uint8_t* src_y, enum RotationMode mode) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_y || !src_uv || width <= 0 || height == 0 || !dst_y || !dst_u || - !dst_v) { + if (!src_y || !src_uv || width <= 0 || height == 0 || height == INT_MIN || + !dst_y || !dst_u || !dst_v) { return -1; } @@ -566,8 +1181,8 @@ int NV12ToI420Rotate(const uint8_t* src_y, if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_uv = src_uv + (halfheight - 1) * src_stride_uv; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_uv = src_uv + (ptrdiff_t)(halfheight - 1) * src_stride_uv; src_stride_y = -src_stride_y; src_stride_uv = -src_stride_uv; } @@ -580,18 +1195,347 @@ int NV12ToI420Rotate(const uint8_t* src_y, width, height); case kRotate90: RotatePlane90(src_y, src_stride_y, dst_y, dst_stride_y, width, height); - RotateUV90(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, - dst_stride_v, halfwidth, halfheight); + SplitRotateUV90(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, + dst_stride_v, halfwidth, halfheight); return 0; case kRotate270: RotatePlane270(src_y, src_stride_y, dst_y, dst_stride_y, width, height); - RotateUV270(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, - dst_stride_v, halfwidth, halfheight); + SplitRotateUV270(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, + dst_stride_v, halfwidth, halfheight); return 0; case kRotate180: RotatePlane180(src_y, src_stride_y, dst_y, dst_stride_y, width, height); - RotateUV180(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, - dst_stride_v, halfwidth, halfheight); + SplitRotateUV180(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, + dst_stride_v, halfwidth, halfheight); + return 0; + default: + break; + } + return -1; +} + +static void SplitPixels(const uint8_t* src_u, + int src_pixel_stride_uv, + uint8_t* dst_u, + int width) { + int i; + for (i = 0; i < width; ++i) { + *dst_u = *src_u; + ++dst_u; + src_u += src_pixel_stride_uv; + } +} + +// Convert Android420 to I420 with Rotate +LIBYUV_API +int Android420ToI420Rotate(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + int src_pixel_stride_uv, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode rotation) { + int y; + const ptrdiff_t vu_off = src_v - src_u; + int halfwidth = (width + 1) >> 1; + int halfheight = (height + 1) >> 1; + if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + + if (dst_y) { + RotatePlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height, + rotation); + } + + // Copy UV planes - I420 + if (src_pixel_stride_uv == 1) { + RotatePlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight, + rotation); + RotatePlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight, + rotation); + return 0; + } + // Split UV planes - NV21 + if (src_pixel_stride_uv == 2 && vu_off == -1 && + src_stride_u == src_stride_v) { + SplitRotateUV(src_v, src_stride_v, dst_v, dst_stride_v, dst_u, dst_stride_u, + halfwidth, halfheight, rotation); + return 0; + } + // Split UV planes - NV12 + if (src_pixel_stride_uv == 2 && vu_off == 1 && src_stride_u == src_stride_v) { + SplitRotateUV(src_u, src_stride_u, dst_u, dst_stride_u, dst_v, dst_stride_v, + halfwidth, halfheight, rotation); + return 0; + } + + if (rotation == 0) { + for (y = 0; y < halfheight; ++y) { + SplitPixels(src_u, src_pixel_stride_uv, dst_u, halfwidth); + SplitPixels(src_v, src_pixel_stride_uv, dst_v, halfwidth); + src_u += src_stride_u; + src_v += src_stride_v; + dst_u += dst_stride_u; + dst_v += dst_stride_v; + } + return 0; + } + // unsupported type and/or rotation. + return -1; +} + +LIBYUV_API +int I010Rotate(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode mode) { + int halfwidth = (width + 1) >> 1; + int halfheight = (height + 1) >> 1; + if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || + height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_stride_y < 0) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + + switch (mode) { + case kRotate0: + // copy frame + return I010Copy(src_y, src_stride_y, src_u, src_stride_u, src_v, + src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u, + dst_v, dst_stride_v, width, height); + case kRotate90: + RotatePlane90_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + RotatePlane90_16(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, + halfheight); + RotatePlane90_16(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, + halfheight); + return 0; + case kRotate270: + RotatePlane270_16(src_y, src_stride_y, dst_y, dst_stride_y, width, + height); + RotatePlane270_16(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, + halfheight); + RotatePlane270_16(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, + halfheight); + return 0; + case kRotate180: + RotatePlane180_16(src_y, src_stride_y, dst_y, dst_stride_y, width, + height); + RotatePlane180_16(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, + halfheight); + RotatePlane180_16(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, + halfheight); + return 0; + default: + break; + } + return -1; +} + +// I210 has half width x full height UV planes, so rotate by 90 and 270 +// require scaling to maintain 422 subsampling. +LIBYUV_API +int I210Rotate(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode mode) { + int halfwidth = (width + 1) >> 1; + int halfheight = (height + 1) >> 1; + int r; + if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || + height == INT_MIN || !dst_y || !dst_u || !dst_v) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + halfheight = (height + 1) >> 1; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + + switch (mode) { + case kRotate0: + // Copy frame + CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + CopyPlane_16(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, height); + CopyPlane_16(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, height); + return 0; + + // Note on temporary Y plane for UV. + // Rotation of UV first fits within the Y destination plane rows. + // Y plane is width x height + // Y plane rotated is height x width + // UV plane is (width / 2) x height + // UV plane rotated is height x (width / 2) + // UV plane rotated+scaled is (height / 2) x width. + // UV plane rotated is a temporary that fits within the Y plane rotated. + + case kRotate90: + RotatePlane90_16(src_u, src_stride_u, dst_y, dst_stride_y, halfwidth, + height); + r = ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_u, + dst_stride_u, halfheight, width, kFilterBilinear); + if (r != 0) { + return r; + } + RotatePlane90_16(src_v, src_stride_v, dst_y, dst_stride_y, halfwidth, + height); + r = ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_v, + dst_stride_v, halfheight, width, kFilterLinear); + if (r != 0) { + return r; + } + RotatePlane90_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + return 0; + case kRotate270: + RotatePlane270_16(src_u, src_stride_u, dst_y, dst_stride_y, halfwidth, + height); + r = ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_u, + dst_stride_u, halfheight, width, kFilterBilinear); + if (r != 0) { + return r; + } + RotatePlane270_16(src_v, src_stride_v, dst_y, dst_stride_y, halfwidth, + height); + r = ScalePlane_16(dst_y, dst_stride_y, height, halfwidth, dst_v, + dst_stride_v, halfheight, width, kFilterLinear); + if (r != 0) { + return r; + } + RotatePlane270_16(src_y, src_stride_y, dst_y, dst_stride_y, width, + height); + return 0; + case kRotate180: + RotatePlane180_16(src_y, src_stride_y, dst_y, dst_stride_y, width, + height); + RotatePlane180_16(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, + height); + RotatePlane180_16(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, + height); + return 0; + default: + break; + } + return -1; +} + +LIBYUV_API +int I410Rotate(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int width, + int height, + enum RotationMode mode) { + if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || + height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_stride_y < 0) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; + src_stride_y = -src_stride_y; + src_stride_u = -src_stride_u; + src_stride_v = -src_stride_v; + } + + switch (mode) { + case kRotate0: + // copy frame + CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + CopyPlane_16(src_u, src_stride_u, dst_u, dst_stride_u, width, height); + CopyPlane_16(src_v, src_stride_v, dst_v, dst_stride_v, width, height); + return 0; + case kRotate90: + RotatePlane90_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height); + RotatePlane90_16(src_u, src_stride_u, dst_u, dst_stride_u, width, height); + RotatePlane90_16(src_v, src_stride_v, dst_v, dst_stride_v, width, height); + return 0; + case kRotate270: + RotatePlane270_16(src_y, src_stride_y, dst_y, dst_stride_y, width, + height); + RotatePlane270_16(src_u, src_stride_u, dst_u, dst_stride_u, width, + height); + RotatePlane270_16(src_v, src_stride_v, dst_v, dst_stride_v, width, + height); + return 0; + case kRotate180: + RotatePlane180_16(src_y, src_stride_y, dst_y, dst_stride_y, width, + height); + RotatePlane180_16(src_u, src_stride_u, dst_u, dst_stride_u, width, + height); + RotatePlane180_16(src_v, src_stride_v, dst_v, dst_stride_v, width, + height); return 0; default: break; diff --git a/libs/libyuv/source/rotate_any.cc b/libs/libyuv/source/rotate_any.cc index b3baf084d0..bc203655a9 100644 --- a/libs/libyuv/source/rotate_any.cc +++ b/libs/libyuv/source/rotate_any.cc @@ -11,42 +11,50 @@ #include "libyuv/rotate.h" #include "libyuv/rotate_row.h" -#include "libyuv/basic_types.h" - #ifdef __cplusplus namespace libyuv { extern "C" { #endif -#define TANY(NAMEANY, TPOS_SIMD, MASK) \ - void NAMEANY(const uint8_t* src, int src_stride, uint8_t* dst, \ - int dst_stride, int width) { \ - int r = width & MASK; \ - int n = width - r; \ - if (n > 0) { \ - TPOS_SIMD(src, src_stride, dst, dst_stride, n); \ - } \ - TransposeWx8_C(src + n, src_stride, dst + n * dst_stride, dst_stride, r); \ +#define TANY(NAMEANY, TPOS_SIMD, TPOS_C, MASK) \ + void NAMEANY(const uint8_t* src, int src_stride, uint8_t* dst, \ + int dst_stride, int width) { \ + int r = width & MASK; \ + int n = width - r; \ + if (n > 0) { \ + TPOS_SIMD(src, src_stride, dst, dst_stride, n); \ + } \ + ptrdiff_t np = n; \ + TPOS_C(src + np, src_stride, dst + np * dst_stride, dst_stride, r); \ } #ifdef HAS_TRANSPOSEWX8_NEON -TANY(TransposeWx8_Any_NEON, TransposeWx8_NEON, 7) +TANY(TransposeWx8_Any_NEON, TransposeWx8_NEON, TransposeWx8_C, 7) #endif -#ifdef HAS_TRANSPOSEWX8_SSSE3 -TANY(TransposeWx8_Any_SSSE3, TransposeWx8_SSSE3, 7) +#ifdef HAS_TRANSPOSEWX16_NEON +TANY(TransposeWx16_Any_NEON, TransposeWx16_NEON, TransposeWx16_C, 15) #endif -#ifdef HAS_TRANSPOSEWX8_MMI -TANY(TransposeWx8_Any_MMI, TransposeWx8_MMI, 7) +#ifdef HAS_TRANSPOSEWX8_AVX2 +TANY(TransposeWx8_Any_AVX2, TransposeWx8_AVX2, TransposeWx8_C, 15) #endif -#ifdef HAS_TRANSPOSEWX8_FAST_SSSE3 -TANY(TransposeWx8_Fast_Any_SSSE3, TransposeWx8_Fast_SSSE3, 15) +#ifdef HAS_TRANSPOSEWX16_AVX2 +TANY(TransposeWx16_Any_AVX2, TransposeWx16_AVX2, TransposeWx16_C, 15) #endif -#ifdef HAS_TRANSPOSEWX16_MSA -TANY(TransposeWx16_Any_MSA, TransposeWx16_MSA, 15) +#ifdef HAS_TRANSPOSEWX8_LSX +TANY(TransposeWx8_Any_LSX, TransposeWx8_LSX, TransposeWx8_C, 15) +#endif +#ifdef HAS_TRANSPOSEWX16_LASX +TANY(TransposeWx16_Any_LASX, TransposeWx16_LASX, TransposeWx16_C, 15) +#endif +#ifdef HAS_TRANSPOSEWX8_WASMSIMD +TANY(TransposeWx8_Any_WASMSIMD, TransposeWx8_WASMSIMD, TransposeWx8_C, 15) +#endif +#ifdef HAS_TRANSPOSEWX16_WASMSIMD +TANY(TransposeWx16_Any_WASMSIMD, TransposeWx16_WASMSIMD, TransposeWx16_C, 15) #endif #undef TANY -#define TUVANY(NAMEANY, TPOS_SIMD, MASK) \ +#define TUVANY(NAMEANY, TPOS_SIMD, TPOS_C, MASK) \ void NAMEANY(const uint8_t* src, int src_stride, uint8_t* dst_a, \ int dst_stride_a, uint8_t* dst_b, int dst_stride_b, \ int width) { \ @@ -55,24 +63,126 @@ TANY(TransposeWx16_Any_MSA, TransposeWx16_MSA, 15) if (n > 0) { \ TPOS_SIMD(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, n); \ } \ - TransposeUVWx8_C(src + n * 2, src_stride, dst_a + n * dst_stride_a, \ - dst_stride_a, dst_b + n * dst_stride_b, dst_stride_b, r); \ + ptrdiff_t np = n; \ + TPOS_C(src + np * 2, src_stride, dst_a + np * dst_stride_a, dst_stride_a, \ + dst_b + np * dst_stride_b, dst_stride_b, r); \ } #ifdef HAS_TRANSPOSEUVWX8_NEON -TUVANY(TransposeUVWx8_Any_NEON, TransposeUVWx8_NEON, 7) +TUVANY(TransposeUVWx8_Any_NEON, TransposeUVWx8_NEON, TransposeUVWx8_C, 7) #endif -#ifdef HAS_TRANSPOSEUVWX8_SSE2 -TUVANY(TransposeUVWx8_Any_SSE2, TransposeUVWx8_SSE2, 7) +#ifdef HAS_TRANSPOSEUVWX8_AVX2 +TUVANY(TransposeUVWx8_Any_AVX2, TransposeUVWx8_AVX2, TransposeUVWx8_C, 7) #endif -#ifdef HAS_TRANSPOSEUVWX8_MMI -TUVANY(TransposeUVWx8_Any_MMI, TransposeUVWx8_MMI, 7) +#ifdef HAS_TRANSPOSEUVWX16_AVX2 +TUVANY(TransposeUVWx16_Any_AVX2, TransposeUVWx16_AVX2, TransposeUVWx16_C, 7) #endif -#ifdef HAS_TRANSPOSEUVWX16_MSA -TUVANY(TransposeUVWx16_Any_MSA, TransposeUVWx16_MSA, 7) +#ifdef HAS_TRANSPOSEUVWX8_LSX +TUVANY(TransposeUVWx8_Any_LSX, TransposeUVWx8_LSX, TransposeUVWx8_C, 7) +#endif +#ifdef HAS_TRANSPOSEUVWX16_LASX +TUVANY(TransposeUVWx16_Any_LASX, TransposeUVWx16_LASX, TransposeUVWx16_C, 7) +#endif +#ifdef HAS_TRANSPOSEUVWX8_WASMSIMD +TUVANY(TransposeUVWx8_Any_WASMSIMD, + TransposeUVWx8_WASMSIMD, + TransposeUVWx8_C, + 7) +#endif +#ifdef HAS_TRANSPOSEUVWX16_WASMSIMD +TUVANY(TransposeUVWx16_Any_WASMSIMD, + TransposeUVWx16_WASMSIMD, + TransposeUVWx16_C, + 7) #endif #undef TUVANY +#define TANY32(NAMEANY, TPOS_SIMD, TPOS_C, MASK) \ + void NAMEANY(const uint8_t* src, int src_stride, uint8_t* dst, \ + int dst_stride, int width) { \ + int r = width & MASK; \ + int n = width - r; \ + if (n > 0) { \ + TPOS_SIMD(src, src_stride, dst, dst_stride, n); \ + } \ + if (r > 0) { \ + TPOS_C(src + (ptrdiff_t)n * src_stride, src_stride, \ + dst + (ptrdiff_t)n * 4, dst_stride, 4, r); \ + } \ + } + +#ifdef HAS_TRANSPOSEWX4_32_AVX2 +TANY32(TransposeWx4_32_Any_AVX2, TransposeWx4_32_AVX2, TransposeWxH_32_C, 3) +#endif +#ifdef HAS_TRANSPOSEWX4_32_LSX +TANY32(TransposeWx4_32_Any_LSX, TransposeWx4_32_LSX, TransposeWxH_32_C, 3) +#endif +#ifdef HAS_TRANSPOSEWX4_32_LASX +TANY32(TransposeWx4_32_Any_LASX, TransposeWx4_32_LASX, TransposeWxH_32_C, 7) +#endif +#ifdef HAS_TRANSPOSEWX4_32_WASMSIMD +TANY32(TransposeWx4_32_Any_WASMSIMD, + TransposeWx4_32_WASMSIMD, + TransposeWxH_32_C, + 3) +#endif +#undef TANY32 + +#define TANY32_SRC(NAMEANY, TPOS_SIMD, MASK, HEIGHT) \ + void NAMEANY(const uint8_t* src, int src_stride, uint8_t* dst, \ + int dst_stride, int width) { \ + int r = width & MASK; \ + int n = width - r; \ + if (n > 0) { \ + TPOS_SIMD(src, src_stride, dst, dst_stride, n); \ + } \ + ptrdiff_t np = n; \ + TransposeWxH_32_C(src + np * 4, src_stride, dst + np * dst_stride, \ + dst_stride, r, HEIGHT); \ + } + +#ifdef HAS_TRANSPOSEWX8_32_AVX2 +TANY32_SRC(TransposeWx8_32_Any_AVX2, TransposeWx8_32_AVX2, 3, 8) +#endif +#undef TANY32_SRC + +#define TANY16(NAMEANY, TPOS_SIMD, MASK, HEIGHT) \ + void NAMEANY(const uint16_t* src, int src_stride, uint16_t* dst, \ + int dst_stride, int width) { \ + int r = width & MASK; \ + int n = width - r; \ + if (n > 0) { \ + TPOS_SIMD(src, src_stride, dst, dst_stride, n); \ + } \ + ptrdiff_t np = n; \ + TransposeWx8_16_C(src + np, src_stride, dst + np * dst_stride, dst_stride, \ + r); \ + if ((HEIGHT) == 16) { \ + TransposeWx8_16_C(src + np + 8 * src_stride, src_stride, \ + dst + np * dst_stride + 8, dst_stride, r); \ + } \ + } + +#ifdef HAS_TRANSPOSEWX8_16_NEON +TANY16(TransposeWx8_16_Any_NEON, TransposeWx8_16_NEON, 7, 8) +#endif +#ifdef HAS_TRANSPOSEWX8_16_AVX2 +TANY16(TransposeWx8_16_Any_AVX2, TransposeWx8_16_AVX2, 7, 8) +#endif +#ifdef HAS_TRANSPOSEWX16_16_AVX2 +TANY16(TransposeWx16_16_Any_AVX2, TransposeWx16_16_AVX2, 7, 16) +#endif +#ifdef HAS_TRANSPOSEWX8_16_LSX +TANY16(TransposeWx8_16_Any_LSX, TransposeWx8_16_LSX, 7, 8) +#endif +#ifdef HAS_TRANSPOSEWX16_16_LASX +TANY16(TransposeWx16_16_Any_LASX, TransposeWx16_16_LASX, 7, 16) +#endif +#ifdef HAS_TRANSPOSEWX8_16_WASMSIMD +TANY16(TransposeWx8_16_Any_WASMSIMD, TransposeWx8_16_WASMSIMD, 7, 8) +#endif +#undef TANY16 + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/source/rotate_argb.cc b/libs/libyuv/source/rotate_argb.cc index a93fd55f92..1b0bf7417d 100644 --- a/libs/libyuv/source/rotate_argb.cc +++ b/libs/libyuv/source/rotate_argb.cc @@ -8,188 +8,217 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "libyuv/rotate.h" +#include "libyuv/rotate_argb.h" + +#include #include "libyuv/convert.h" #include "libyuv/cpu_id.h" #include "libyuv/planar_functions.h" +#include "libyuv/rotate.h" +#include "libyuv/rotate_row.h" #include "libyuv/row.h" -#include "libyuv/scale_row.h" /* for ScaleARGBRowDownEven_ */ #ifdef __cplusplus namespace libyuv { extern "C" { #endif -static void ARGBTranspose(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height) { - int i; - int src_pixel_step = src_stride_argb >> 2; - void (*ScaleARGBRowDownEven)( - const uint8_t* src_argb, ptrdiff_t src_stride_argb, int src_step, - uint8_t* dst_argb, int dst_width) = ScaleARGBRowDownEven_C; -#if defined(HAS_SCALEARGBROWDOWNEVEN_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ScaleARGBRowDownEven = ScaleARGBRowDownEven_Any_SSE2; +static int ARGBTranspose(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { +#if defined(HAS_TRANSPOSEWXH_32_NEON) || defined(HAS_TRANSPOSEWXH_32_SME) || \ + defined(HAS_TRANSPOSEWXH_32_RVV) || defined(HAS_TRANSPOSEWXH_32_HVX) || \ + defined(HAS_TRANSPOSEWXH_32_AVX2) + void (*TransposeWxH_32)(const uint8_t* src, int src_stride, uint8_t* dst, + int dst_stride, int width, int height) = NULL; +#endif +#if defined(HAS_TRANSPOSEWX16_32_AVX512BW) + void (*TransposeWx16_32)(const uint8_t* src, int src_stride, uint8_t* dst, + int dst_stride, int width) = NULL; +#endif +#if defined(HAS_TRANSPOSEWX8_32_AVX2) + void (*TransposeWx8_32)(const uint8_t* src, int src_stride, uint8_t* dst, + int dst_stride, int width) = NULL; +#endif + void (*TransposeWx4_32)(const uint8_t* src, int src_stride, uint8_t* dst, + int dst_stride, int width) = NULL; + // Check stride is a multiple of 4. + if (src_stride_argb & 3) { + return -1; + } +#if defined(HAS_TRANSPOSEWX4_32_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + TransposeWx4_32 = TransposeWx4_32_Any_AVX2; if (IS_ALIGNED(height, 4)) { // Width of dest. - ScaleARGBRowDownEven = ScaleARGBRowDownEven_SSE2; + TransposeWx4_32 = TransposeWx4_32_AVX2; } } #endif -#if defined(HAS_SCALEARGBROWDOWNEVEN_NEON) +#if defined(HAS_TRANSPOSEWX8_32_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + TransposeWx8_32 = TransposeWx8_32_Any_AVX2; + if (IS_ALIGNED(width, 4)) { + TransposeWx8_32 = TransposeWx8_32_AVX2; + } + } +#endif +#if defined(HAS_TRANSPOSEWXH_32_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + TransposeWxH_32 = TransposeWxH_32_AVX2; + } +#endif +#if defined(HAS_TRANSPOSEWX16_32_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + TransposeWx16_32 = TransposeWx16_32_AVX512BW; + } +#endif +#if defined(HAS_TRANSPOSEWXH_32_NEON) if (TestCpuFlag(kCpuHasNEON)) { - ScaleARGBRowDownEven = ScaleARGBRowDownEven_Any_NEON; + TransposeWxH_32 = TransposeWxH_32_NEON; + } +#endif +#if defined(HAS_TRANSPOSEWX4_32_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + TransposeWx4_32 = TransposeWx4_32_SVE2; +#if defined(HAS_TRANSPOSEWXH_32_NEON) + TransposeWxH_32 = NULL; +#endif + } +#endif +#if defined(HAS_TRANSPOSEWXH_32_SME) + if (TestCpuFlag(kCpuHasSME)) { + TransposeWxH_32 = TransposeWxH_32_SME; + } +#endif +#if defined(HAS_TRANSPOSEWXH_32_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + TransposeWxH_32 = TransposeWxH_32_RVV; + } +#endif +#if defined(HAS_TRANSPOSEWXH_32_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + TransposeWxH_32 = TransposeWxH_32_HVX; + } +#endif +#if defined(HAS_TRANSPOSEWX4_32_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + TransposeWx4_32 = TransposeWx4_32_Any_LSX; if (IS_ALIGNED(height, 4)) { // Width of dest. - ScaleARGBRowDownEven = ScaleARGBRowDownEven_NEON; + TransposeWx4_32 = TransposeWx4_32_LSX; } } #endif -#if defined(HAS_SCALEARGBROWDOWNEVEN_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ScaleARGBRowDownEven = ScaleARGBRowDownEven_Any_MSA; - if (IS_ALIGNED(height, 4)) { // Width of dest. - ScaleARGBRowDownEven = ScaleARGBRowDownEven_MSA; +#if defined(HAS_TRANSPOSEWX4_32_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + TransposeWx4_32 = TransposeWx4_32_Any_LASX; + if (IS_ALIGNED(height, 8)) { // Width of dest. + TransposeWx4_32 = TransposeWx4_32_LASX; } } #endif -#if defined(HAS_SCALEARGBROWDOWNEVEN_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ScaleARGBRowDownEven = ScaleARGBRowDownEven_Any_MMI; +#if defined(HAS_TRANSPOSEWX4_32_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + TransposeWx4_32 = TransposeWx4_32_Any_WASMSIMD; if (IS_ALIGNED(height, 4)) { // Width of dest. - ScaleARGBRowDownEven = ScaleARGBRowDownEven_MMI; + TransposeWx4_32 = TransposeWx4_32_WASMSIMD; } } #endif - for (i = 0; i < width; ++i) { // column of source to row of dest. - ScaleARGBRowDownEven(src_argb, 0, src_pixel_step, dst_argb, height); - dst_argb += dst_stride_argb; - src_argb += 4; +#if defined(HAS_TRANSPOSEWX16_32_AVX512BW) + if (TransposeWx16_32) { + while (height >= 16) { + TransposeWx16_32(src_argb, src_stride_argb, dst_argb, dst_stride_argb, + width); + src_argb += 16 * (ptrdiff_t)src_stride_argb; + dst_argb += 16 * 4; + height -= 16; + } } +#endif +#if defined(HAS_TRANSPOSEWXH_32_NEON) || defined(HAS_TRANSPOSEWXH_32_SME) || \ + defined(HAS_TRANSPOSEWXH_32_RVV) || defined(HAS_TRANSPOSEWXH_32_HVX) || \ + defined(HAS_TRANSPOSEWXH_32_AVX2) + if (TransposeWxH_32) { + if (height > 0) { + TransposeWxH_32(src_argb, src_stride_argb, dst_argb, dst_stride_argb, + width, height); + } + return 0; + } +#endif +#if defined(HAS_TRANSPOSEWX8_32_AVX2) + if (TransposeWx8_32) { + while (height >= 8) { + TransposeWx8_32(src_argb, src_stride_argb, dst_argb, dst_stride_argb, + width); + src_argb += 8 * (ptrdiff_t)src_stride_argb; + dst_argb += 8 * 4; + height -= 8; + } + } +#endif + if (height > 0) { + if (TransposeWx4_32) { + while (width >= 4) { + TransposeWx4_32(src_argb, src_stride_argb, dst_argb, dst_stride_argb, + height); + src_argb += 4 * 4; + dst_argb += 4 * (ptrdiff_t)dst_stride_argb; + width -= 4; + } + } + if (width > 0) { + TransposeWxH_32_C(src_argb, src_stride_argb, dst_argb, dst_stride_argb, + width, height); + } + } + return 0; } -void ARGBRotate90(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height) { +static int ARGBRotate90(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { // Rotate by 90 is a ARGBTranspose with the source read // from bottom to top. So set the source pointer to the end // of the buffer and flip the sign of the source stride. - src_argb += src_stride_argb * (height - 1); + src_argb += (ptrdiff_t)src_stride_argb * (height - 1); src_stride_argb = -src_stride_argb; - ARGBTranspose(src_argb, src_stride_argb, dst_argb, dst_stride_argb, width, - height); + return ARGBTranspose(src_argb, src_stride_argb, dst_argb, dst_stride_argb, + width, height); } -void ARGBRotate270(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height) { +static int ARGBRotate270(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { // Rotate by 270 is a ARGBTranspose with the destination written // from bottom to top. So set the destination pointer to the end // of the buffer and flip the sign of the destination stride. - dst_argb += dst_stride_argb * (width - 1); + dst_argb += (ptrdiff_t)dst_stride_argb * (width - 1); dst_stride_argb = -dst_stride_argb; - ARGBTranspose(src_argb, src_stride_argb, dst_argb, dst_stride_argb, width, - height); + return ARGBTranspose(src_argb, src_stride_argb, dst_argb, dst_stride_argb, + width, height); } -void ARGBRotate180(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_argb, - int dst_stride_argb, - int width, - int height) { - // Swap first and last row and mirror the content. Uses a temporary row. - align_buffer_64(row, width * 4); - const uint8_t* src_bot = src_argb + src_stride_argb * (height - 1); - uint8_t* dst_bot = dst_argb + dst_stride_argb * (height - 1); - int half_height = (height + 1) >> 1; - int y; - void (*ARGBMirrorRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width) = - ARGBMirrorRow_C; - void (*CopyRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width) = - CopyRow_C; -#if defined(HAS_ARGBMIRRORROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - ARGBMirrorRow = ARGBMirrorRow_Any_NEON; - if (IS_ALIGNED(width, 4)) { - ARGBMirrorRow = ARGBMirrorRow_NEON; - } - } -#endif -#if defined(HAS_ARGBMIRRORROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ARGBMirrorRow = ARGBMirrorRow_Any_SSE2; - if (IS_ALIGNED(width, 4)) { - ARGBMirrorRow = ARGBMirrorRow_SSE2; - } - } -#endif -#if defined(HAS_ARGBMIRRORROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - ARGBMirrorRow = ARGBMirrorRow_Any_AVX2; - if (IS_ALIGNED(width, 8)) { - ARGBMirrorRow = ARGBMirrorRow_AVX2; - } - } -#endif -#if defined(HAS_ARGBMIRRORROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ARGBMirrorRow = ARGBMirrorRow_Any_MSA; - if (IS_ALIGNED(width, 16)) { - ARGBMirrorRow = ARGBMirrorRow_MSA; - } - } -#endif -#if defined(HAS_ARGBMIRRORROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ARGBMirrorRow = ARGBMirrorRow_Any_MMI; - if (IS_ALIGNED(width, 2)) { - ARGBMirrorRow = ARGBMirrorRow_MMI; - } - } -#endif -#if defined(HAS_COPYROW_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - CopyRow = IS_ALIGNED(width * 4, 32) ? CopyRow_SSE2 : CopyRow_Any_SSE2; - } -#endif -#if defined(HAS_COPYROW_AVX) - if (TestCpuFlag(kCpuHasAVX)) { - CopyRow = IS_ALIGNED(width * 4, 64) ? CopyRow_AVX : CopyRow_Any_AVX; - } -#endif -#if defined(HAS_COPYROW_ERMS) - if (TestCpuFlag(kCpuHasERMS)) { - CopyRow = CopyRow_ERMS; - } -#endif -#if defined(HAS_COPYROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - CopyRow = IS_ALIGNED(width * 4, 32) ? CopyRow_NEON : CopyRow_Any_NEON; - } -#endif - - // Odd height will harmlessly mirror the middle row twice. - for (y = 0; y < half_height; ++y) { - ARGBMirrorRow(src_argb, row, width); // Mirror first row into a buffer - ARGBMirrorRow(src_bot, dst_argb, width); // Mirror last row into first row - CopyRow(row, dst_bot, width * 4); // Copy first mirrored row into last - src_argb += src_stride_argb; - dst_argb += dst_stride_argb; - src_bot -= src_stride_argb; - dst_bot -= dst_stride_argb; - } - free_aligned_buffer_64(row); +static int ARGBRotate180(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_argb, + int dst_stride_argb, + int width, + int height) { + // Rotate by 180 is a vertical flip (negative height) and horizontal mirror. + return ARGBMirror(src_argb, src_stride_argb, dst_argb, dst_stride_argb, width, + -height); } LIBYUV_API @@ -200,14 +229,15 @@ int ARGBRotate(const uint8_t* src_argb, int width, int height, enum RotationMode mode) { - if (!src_argb || width <= 0 || height == 0 || !dst_argb) { + if (!src_argb || width <= 0 || height == 0 || height == INT_MIN || + !dst_argb) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } @@ -217,17 +247,14 @@ int ARGBRotate(const uint8_t* src_argb, return ARGBCopy(src_argb, src_stride_argb, dst_argb, dst_stride_argb, width, height); case kRotate90: - ARGBRotate90(src_argb, src_stride_argb, dst_argb, dst_stride_argb, width, - height); - return 0; + return ARGBRotate90(src_argb, src_stride_argb, dst_argb, dst_stride_argb, + width, height); case kRotate270: - ARGBRotate270(src_argb, src_stride_argb, dst_argb, dst_stride_argb, width, - height); - return 0; + return ARGBRotate270(src_argb, src_stride_argb, dst_argb, dst_stride_argb, + width, height); case kRotate180: - ARGBRotate180(src_argb, src_stride_argb, dst_argb, dst_stride_argb, width, - height); - return 0; + return ARGBRotate180(src_argb, src_stride_argb, dst_argb, dst_stride_argb, + width, height); default: break; } diff --git a/libs/libyuv/source/rotate_common.cc b/libs/libyuv/source/rotate_common.cc index ff212adebc..e4aab102f5 100644 --- a/libs/libyuv/source/rotate_common.cc +++ b/libs/libyuv/source/rotate_common.cc @@ -36,6 +36,16 @@ void TransposeWx8_C(const uint8_t* src, } } +void TransposeWx16_C(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + TransposeWx8_C(src, src_stride, dst, dst_stride, width); + TransposeWx8_C((src + 8 * src_stride), src_stride, (dst + 8), dst_stride, + width); +} + void TransposeUVWx8_C(const uint8_t* src, int src_stride, uint8_t* dst_a, @@ -67,35 +77,99 @@ void TransposeUVWx8_C(const uint8_t* src, } } -void TransposeWxH_C(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width, - int height) { +void TransposeUVWx16_C(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width) { + TransposeUVWx8_C(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, + width); + TransposeUVWx8_C((src + 8 * src_stride), src_stride, (dst_a + 8), + dst_stride_a, (dst_b + 8), dst_stride_b, width); +} + +void TransposeWx8_16_C(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + int i; + for (i = 0; i < width; ++i) { + dst[0] = src[0 * src_stride]; + dst[1] = src[1 * src_stride]; + dst[2] = src[2 * src_stride]; + dst[3] = src[3 * src_stride]; + dst[4] = src[4 * src_stride]; + dst[5] = src[5 * src_stride]; + dst[6] = src[6 * src_stride]; + dst[7] = src[7 * src_stride]; + ++src; + dst += dst_stride; + } +} + +static inline void Copy4(uint8_t* dst, const uint8_t* src) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = src[3]; +} + +// Transpose 32 bit values (ARGB) +void TransposeWx4_32_C(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const uint8_t* src1 = src + src_stride; + const uint8_t* src2 = src1 + src_stride; + const uint8_t* src3 = src2 + src_stride; + uint8_t* dst1 = dst + dst_stride; + uint8_t* dst2 = dst1 + dst_stride; + uint8_t* dst3 = dst2 + dst_stride; + int i; + for (i = 0; i < width; i += 4) { + Copy4(dst + 0, src + 0); + Copy4(dst + 4, src1 + 0); + Copy4(dst + 8, src2 + 0); + Copy4(dst + 12, src3 + 0); + Copy4(dst1 + 0, src + 4); + Copy4(dst1 + 4, src1 + 4); + Copy4(dst1 + 8, src2 + 4); + Copy4(dst1 + 12, src3 + 4); + Copy4(dst2 + 0, src + 8); + Copy4(dst2 + 4, src1 + 8); + Copy4(dst2 + 8, src2 + 8); + Copy4(dst2 + 12, src3 + 8); + Copy4(dst3 + 0, src + 12); + Copy4(dst3 + 4, src1 + 12); + Copy4(dst3 + 8, src2 + 12); + Copy4(dst3 + 12, src3 + 12); + src += (ptrdiff_t)src_stride * 4; // advance 4 rows + src1 += (ptrdiff_t)src_stride * 4; + src2 += (ptrdiff_t)src_stride * 4; + src3 += (ptrdiff_t)src_stride * 4; + dst += 4 * 4; // advance 4 columns + dst1 += 4 * 4; + dst2 += 4 * 4; + dst3 += 4 * 4; + } +} + +void TransposeWxH_32_C(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height) { int i; for (i = 0; i < width; ++i) { int j; for (j = 0; j < height; ++j) { - dst[i * dst_stride + j] = src[j * src_stride + i]; - } - } -} - -void TransposeUVWxH_C(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width, - int height) { - int i; - for (i = 0; i < width * 2; i += 2) { - int j; - for (j = 0; j < height; ++j) { - dst_a[j + ((i >> 1) * dst_stride_a)] = src[i + (j * src_stride)]; - dst_b[j + ((i >> 1) * dst_stride_b)] = src[i + (j * src_stride) + 1]; + Copy4(dst + (ptrdiff_t)i * dst_stride + j * 4, + src + (ptrdiff_t)j * src_stride + i * 4); } } } diff --git a/libs/libyuv/source/rotate_gcc.cc b/libs/libyuv/source/rotate_gcc.cc index 04e19e29ee..734638023f 100644 --- a/libs/libyuv/source/rotate_gcc.cc +++ b/libs/libyuv/source/rotate_gcc.cc @@ -11,362 +11,1702 @@ #include "libyuv/rotate_row.h" #include "libyuv/row.h" +#include + #ifdef __cplusplus namespace libyuv { extern "C" { #endif -// This module is for GCC x86 and x64. -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. -// Transpose 8x8. 32 or 64 bit, but not NaCL for 64 bit. -#if defined(HAS_TRANSPOSEWX8_SSSE3) -void TransposeWx8_SSSE3(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width) { +// This module is for GCC and clang x86 and x64. +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__)) && \ + !defined(LIBYUV_ENABLE_ROWWIN) && \ + (!defined(_MSC_VER) || defined(__clang__)) + +#if defined(HAS_TRANSPOSEWX8_AVX2) || defined(HAS_TRANSPOSEUVWX8_AVX2) +// Transpose 16x8 bytes using 2 lanes of AVX2. Source row r is in lane r / 4 +// of ymm(r % 4). Byte and word unpacks produce 4-row column chunks in each +// lane; vperm2i128 + dword unpack join rows 0..3 and 4..7. Each 128-bit lane +// holds 8 bytes for dst_a (low 64 bits) and 8 bytes for dst_b (high 64 bits). +// Width is a multiple of 16 bytes. +static void TransposeWx8_Byte_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int byte_width) { + const ptrdiff_t d_a = dst_stride_a; + const ptrdiff_t d_b = dst_stride_b; + uintptr_t temp; asm volatile( - // Read in the data from the source pointer. - // First round of bit swap. - LABELALIGN - "1: \n" - "movq (%0),%%xmm0 \n" - "movq (%0,%3),%%xmm1 \n" - "lea (%0,%3,2),%0 \n" - "punpcklbw %%xmm1,%%xmm0 \n" - "movq (%0),%%xmm2 \n" - "movdqa %%xmm0,%%xmm1 \n" - "palignr $0x8,%%xmm1,%%xmm1 \n" - "movq (%0,%3),%%xmm3 \n" - "lea (%0,%3,2),%0 \n" - "punpcklbw %%xmm3,%%xmm2 \n" - "movdqa %%xmm2,%%xmm3 \n" - "movq (%0),%%xmm4 \n" - "palignr $0x8,%%xmm3,%%xmm3 \n" - "movq (%0,%3),%%xmm5 \n" - "lea (%0,%3,2),%0 \n" - "punpcklbw %%xmm5,%%xmm4 \n" - "movdqa %%xmm4,%%xmm5 \n" - "movq (%0),%%xmm6 \n" - "palignr $0x8,%%xmm5,%%xmm5 \n" - "movq (%0,%3),%%xmm7 \n" - "lea (%0,%3,2),%0 \n" - "punpcklbw %%xmm7,%%xmm6 \n" - "neg %3 \n" - "movdqa %%xmm6,%%xmm7 \n" - "lea 0x8(%0,%3,8),%0 \n" - "palignr $0x8,%%xmm7,%%xmm7 \n" - "neg %3 \n" - // Second round of bit swap. - "punpcklwd %%xmm2,%%xmm0 \n" - "punpcklwd %%xmm3,%%xmm1 \n" - "movdqa %%xmm0,%%xmm2 \n" - "movdqa %%xmm1,%%xmm3 \n" - "palignr $0x8,%%xmm2,%%xmm2 \n" - "palignr $0x8,%%xmm3,%%xmm3 \n" - "punpcklwd %%xmm6,%%xmm4 \n" - "punpcklwd %%xmm7,%%xmm5 \n" - "movdqa %%xmm4,%%xmm6 \n" - "movdqa %%xmm5,%%xmm7 \n" - "palignr $0x8,%%xmm6,%%xmm6 \n" - "palignr $0x8,%%xmm7,%%xmm7 \n" - // Third round of bit swap. - // Write to the destination pointer. - "punpckldq %%xmm4,%%xmm0 \n" - "movq %%xmm0,(%1) \n" - "movdqa %%xmm0,%%xmm4 \n" - "palignr $0x8,%%xmm4,%%xmm4 \n" - "movq %%xmm4,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "punpckldq %%xmm6,%%xmm2 \n" - "movdqa %%xmm2,%%xmm6 \n" - "movq %%xmm2,(%1) \n" - "palignr $0x8,%%xmm6,%%xmm6 \n" - "punpckldq %%xmm5,%%xmm1 \n" - "movq %%xmm6,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "movdqa %%xmm1,%%xmm5 \n" - "movq %%xmm1,(%1) \n" - "palignr $0x8,%%xmm5,%%xmm5 \n" - "movq %%xmm5,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "punpckldq %%xmm7,%%xmm3 \n" - "movq %%xmm3,(%1) \n" - "movdqa %%xmm3,%%xmm7 \n" - "palignr $0x8,%%xmm7,%%xmm7 \n" - "sub $0x8,%2 \n" - "movq %%xmm7,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "jg 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "r"((intptr_t)(src_stride)), // %3 - "r"((intptr_t)(dst_stride)) // %4 + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[src_stride]),%%xmm1 \n" + "lea (%[src],%[src_stride],2),%[temp] \n" + "lea 0x10(%[src]),%[src] \n" + "vmovdqu (%[temp]),%%xmm2 \n" + "vmovdqu (%[temp],%[src_stride]),%%xmm3 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm0,%%ymm0 \n" + "vinserti128 $1,(%[temp],%[src_stride]),%%ymm1,%%ymm1 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm2,%%ymm2 \n" + "vinserti128 $1,(%[temp],%[src_stride]),%%ymm3,%%ymm3 \n" + + "vpunpcklbw %%ymm1,%%ymm0,%%ymm4 \n" + "vpunpckhbw %%ymm1,%%ymm0,%%ymm5 \n" + "vpunpcklbw %%ymm3,%%ymm2,%%ymm6 \n" + "vpunpckhbw %%ymm3,%%ymm2,%%ymm7 \n" + + "vpunpcklwd %%ymm6,%%ymm4,%%ymm0 \n" + "vpunpckhwd %%ymm6,%%ymm4,%%ymm1 \n" + "vpunpcklwd %%ymm7,%%ymm5,%%ymm2 \n" + "vpunpckhwd %%ymm7,%%ymm5,%%ymm3 \n" + + "vperm2i128 $0x20,%%ymm1,%%ymm0,%%ymm4 \n" + "vperm2i128 $0x31,%%ymm1,%%ymm0,%%ymm5 \n" + "vperm2i128 $0x20,%%ymm3,%%ymm2,%%ymm6 \n" + "vperm2i128 $0x31,%%ymm3,%%ymm2,%%ymm7 \n" + + "vpunpckldq %%ymm5,%%ymm4,%%ymm0 \n" + "vpunpckhdq %%ymm5,%%ymm4,%%ymm1 \n" + "vpunpckldq %%ymm7,%%ymm6,%%ymm2 \n" + "vpunpckhdq %%ymm7,%%ymm6,%%ymm3 \n" + + "vmovq %%xmm0,(%[dst_a]) \n" + "vmovhpd %%xmm0,(%[dst_b]) \n" + "add %[dst_stride_a],%[dst_a] \n" + "add %[dst_stride_b],%[dst_b] \n" + "vmovq %%xmm1,(%[dst_a]) \n" + "vmovhpd %%xmm1,(%[dst_b]) \n" + "add %[dst_stride_a],%[dst_a] \n" + "add %[dst_stride_b],%[dst_b] \n" + "vextracti128 $1,%%ymm0,%%xmm4 \n" + "vextracti128 $1,%%ymm1,%%xmm5 \n" + "vmovq %%xmm4,(%[dst_a]) \n" + "vmovhpd %%xmm4,(%[dst_b]) \n" + "add %[dst_stride_a],%[dst_a] \n" + "add %[dst_stride_b],%[dst_b] \n" + "vmovq %%xmm5,(%[dst_a]) \n" + "vmovhpd %%xmm5,(%[dst_b]) \n" + "add %[dst_stride_a],%[dst_a] \n" + "add %[dst_stride_b],%[dst_b] \n" + "vmovq %%xmm2,(%[dst_a]) \n" + "vmovhpd %%xmm2,(%[dst_b]) \n" + "add %[dst_stride_a],%[dst_a] \n" + "add %[dst_stride_b],%[dst_b] \n" + "vmovq %%xmm3,(%[dst_a]) \n" + "vmovhpd %%xmm3,(%[dst_b]) \n" + "add %[dst_stride_a],%[dst_a] \n" + "add %[dst_stride_b],%[dst_b] \n" + "vextracti128 $1,%%ymm2,%%xmm6 \n" + "vextracti128 $1,%%ymm3,%%xmm7 \n" + "vmovq %%xmm6,(%[dst_a]) \n" + "vmovhpd %%xmm6,(%[dst_b]) \n" + "add %[dst_stride_a],%[dst_a] \n" + "add %[dst_stride_b],%[dst_b] \n" + "vmovq %%xmm7,(%[dst_a]) \n" + "vmovhpd %%xmm7,(%[dst_b]) \n" + "add %[dst_stride_a],%[dst_a] \n" + "add %[dst_stride_b],%[dst_b] \n" + "subl $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src), [dst_a] "+r"(dst_a), [dst_b] "+r"(dst_b), + [width] "+rm"(byte_width), [temp] "=&r"(temp) + : [src_stride] "r"((ptrdiff_t)src_stride), + [dst_stride_a] "rm"(d_a), + [dst_stride_b] "rm"(d_b) : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); } -#endif // defined(HAS_TRANSPOSEWX8_SSSE3) +#endif // defined(HAS_TRANSPOSEWX8_AVX2) || defined(HAS_TRANSPOSEUVWX8_AVX2) -// Transpose 16x8. 64 bit -#if defined(HAS_TRANSPOSEWX8_FAST_SSSE3) -void TransposeWx8_Fast_SSSE3(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width) { - asm volatile( - // Read in the data from the source pointer. - // First round of bit swap. - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu (%0,%3),%%xmm1 \n" - "lea (%0,%3,2),%0 \n" - "movdqa %%xmm0,%%xmm8 \n" - "punpcklbw %%xmm1,%%xmm0 \n" - "punpckhbw %%xmm1,%%xmm8 \n" - "movdqu (%0),%%xmm2 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm8,%%xmm9 \n" - "palignr $0x8,%%xmm1,%%xmm1 \n" - "palignr $0x8,%%xmm9,%%xmm9 \n" - "movdqu (%0,%3),%%xmm3 \n" - "lea (%0,%3,2),%0 \n" - "movdqa %%xmm2,%%xmm10 \n" - "punpcklbw %%xmm3,%%xmm2 \n" - "punpckhbw %%xmm3,%%xmm10 \n" - "movdqa %%xmm2,%%xmm3 \n" - "movdqa %%xmm10,%%xmm11 \n" - "movdqu (%0),%%xmm4 \n" - "palignr $0x8,%%xmm3,%%xmm3 \n" - "palignr $0x8,%%xmm11,%%xmm11 \n" - "movdqu (%0,%3),%%xmm5 \n" - "lea (%0,%3,2),%0 \n" - "movdqa %%xmm4,%%xmm12 \n" - "punpcklbw %%xmm5,%%xmm4 \n" - "punpckhbw %%xmm5,%%xmm12 \n" - "movdqa %%xmm4,%%xmm5 \n" - "movdqa %%xmm12,%%xmm13 \n" - "movdqu (%0),%%xmm6 \n" - "palignr $0x8,%%xmm5,%%xmm5 \n" - "palignr $0x8,%%xmm13,%%xmm13 \n" - "movdqu (%0,%3),%%xmm7 \n" - "lea (%0,%3,2),%0 \n" - "movdqa %%xmm6,%%xmm14 \n" - "punpcklbw %%xmm7,%%xmm6 \n" - "punpckhbw %%xmm7,%%xmm14 \n" - "neg %3 \n" - "movdqa %%xmm6,%%xmm7 \n" - "movdqa %%xmm14,%%xmm15 \n" - "lea 0x10(%0,%3,8),%0 \n" - "palignr $0x8,%%xmm7,%%xmm7 \n" - "palignr $0x8,%%xmm15,%%xmm15 \n" - "neg %3 \n" - // Second round of bit swap. - "punpcklwd %%xmm2,%%xmm0 \n" - "punpcklwd %%xmm3,%%xmm1 \n" - "movdqa %%xmm0,%%xmm2 \n" - "movdqa %%xmm1,%%xmm3 \n" - "palignr $0x8,%%xmm2,%%xmm2 \n" - "palignr $0x8,%%xmm3,%%xmm3 \n" - "punpcklwd %%xmm6,%%xmm4 \n" - "punpcklwd %%xmm7,%%xmm5 \n" - "movdqa %%xmm4,%%xmm6 \n" - "movdqa %%xmm5,%%xmm7 \n" - "palignr $0x8,%%xmm6,%%xmm6 \n" - "palignr $0x8,%%xmm7,%%xmm7 \n" - "punpcklwd %%xmm10,%%xmm8 \n" - "punpcklwd %%xmm11,%%xmm9 \n" - "movdqa %%xmm8,%%xmm10 \n" - "movdqa %%xmm9,%%xmm11 \n" - "palignr $0x8,%%xmm10,%%xmm10 \n" - "palignr $0x8,%%xmm11,%%xmm11 \n" - "punpcklwd %%xmm14,%%xmm12 \n" - "punpcklwd %%xmm15,%%xmm13 \n" - "movdqa %%xmm12,%%xmm14 \n" - "movdqa %%xmm13,%%xmm15 \n" - "palignr $0x8,%%xmm14,%%xmm14 \n" - "palignr $0x8,%%xmm15,%%xmm15 \n" - // Third round of bit swap. - // Write to the destination pointer. - "punpckldq %%xmm4,%%xmm0 \n" - "movq %%xmm0,(%1) \n" - "movdqa %%xmm0,%%xmm4 \n" - "palignr $0x8,%%xmm4,%%xmm4 \n" - "movq %%xmm4,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "punpckldq %%xmm6,%%xmm2 \n" - "movdqa %%xmm2,%%xmm6 \n" - "movq %%xmm2,(%1) \n" - "palignr $0x8,%%xmm6,%%xmm6 \n" - "punpckldq %%xmm5,%%xmm1 \n" - "movq %%xmm6,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "movdqa %%xmm1,%%xmm5 \n" - "movq %%xmm1,(%1) \n" - "palignr $0x8,%%xmm5,%%xmm5 \n" - "movq %%xmm5,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "punpckldq %%xmm7,%%xmm3 \n" - "movq %%xmm3,(%1) \n" - "movdqa %%xmm3,%%xmm7 \n" - "palignr $0x8,%%xmm7,%%xmm7 \n" - "movq %%xmm7,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "punpckldq %%xmm12,%%xmm8 \n" - "movq %%xmm8,(%1) \n" - "movdqa %%xmm8,%%xmm12 \n" - "palignr $0x8,%%xmm12,%%xmm12 \n" - "movq %%xmm12,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "punpckldq %%xmm14,%%xmm10 \n" - "movdqa %%xmm10,%%xmm14 \n" - "movq %%xmm10,(%1) \n" - "palignr $0x8,%%xmm14,%%xmm14 \n" - "punpckldq %%xmm13,%%xmm9 \n" - "movq %%xmm14,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "movdqa %%xmm9,%%xmm13 \n" - "movq %%xmm9,(%1) \n" - "palignr $0x8,%%xmm13,%%xmm13 \n" - "movq %%xmm13,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "punpckldq %%xmm15,%%xmm11 \n" - "movq %%xmm11,(%1) \n" - "movdqa %%xmm11,%%xmm15 \n" - "palignr $0x8,%%xmm15,%%xmm15 \n" - "sub $0x10,%2 \n" - "movq %%xmm15,(%1,%4) \n" - "lea (%1,%4,2),%1 \n" - "jg 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "r"((intptr_t)(src_stride)), // %3 - "r"((intptr_t)(dst_stride)) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", - "xmm15"); +#if defined(HAS_TRANSPOSEWX8_AVX2) +void TransposeWx8_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + TransposeWx8_Byte_AVX2(src, src_stride, dst, dst_stride * 2, dst + dst_stride, + dst_stride * 2, width); } -#endif // defined(HAS_TRANSPOSEWX8_FAST_SSSE3) +#endif // defined(HAS_TRANSPOSEWX8_AVX2) -// Transpose UV 8x8. 64 bit. -#if defined(HAS_TRANSPOSEUVWX8_SSE2) -void TransposeUVWx8_SSE2(const uint8_t* src, +#if defined(HAS_TRANSPOSEUVWX8_AVX2) +void TransposeUVWx8_AVX2(const uint8_t* src, int src_stride, uint8_t* dst_a, int dst_stride_a, uint8_t* dst_b, int dst_stride_b, int width) { - asm volatile( - // Read in the data from the source pointer. - // First round of bit swap. - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu (%0,%4),%%xmm1 \n" - "lea (%0,%4,2),%0 \n" - "movdqa %%xmm0,%%xmm8 \n" - "punpcklbw %%xmm1,%%xmm0 \n" - "punpckhbw %%xmm1,%%xmm8 \n" - "movdqa %%xmm8,%%xmm1 \n" - "movdqu (%0),%%xmm2 \n" - "movdqu (%0,%4),%%xmm3 \n" - "lea (%0,%4,2),%0 \n" - "movdqa %%xmm2,%%xmm8 \n" - "punpcklbw %%xmm3,%%xmm2 \n" - "punpckhbw %%xmm3,%%xmm8 \n" - "movdqa %%xmm8,%%xmm3 \n" - "movdqu (%0),%%xmm4 \n" - "movdqu (%0,%4),%%xmm5 \n" - "lea (%0,%4,2),%0 \n" - "movdqa %%xmm4,%%xmm8 \n" - "punpcklbw %%xmm5,%%xmm4 \n" - "punpckhbw %%xmm5,%%xmm8 \n" - "movdqa %%xmm8,%%xmm5 \n" - "movdqu (%0),%%xmm6 \n" - "movdqu (%0,%4),%%xmm7 \n" - "lea (%0,%4,2),%0 \n" - "movdqa %%xmm6,%%xmm8 \n" - "punpcklbw %%xmm7,%%xmm6 \n" - "neg %4 \n" - "lea 0x10(%0,%4,8),%0 \n" - "punpckhbw %%xmm7,%%xmm8 \n" - "movdqa %%xmm8,%%xmm7 \n" - "neg %4 \n" - // Second round of bit swap. - "movdqa %%xmm0,%%xmm8 \n" - "movdqa %%xmm1,%%xmm9 \n" - "punpckhwd %%xmm2,%%xmm8 \n" - "punpckhwd %%xmm3,%%xmm9 \n" - "punpcklwd %%xmm2,%%xmm0 \n" - "punpcklwd %%xmm3,%%xmm1 \n" - "movdqa %%xmm8,%%xmm2 \n" - "movdqa %%xmm9,%%xmm3 \n" - "movdqa %%xmm4,%%xmm8 \n" - "movdqa %%xmm5,%%xmm9 \n" - "punpckhwd %%xmm6,%%xmm8 \n" - "punpckhwd %%xmm7,%%xmm9 \n" - "punpcklwd %%xmm6,%%xmm4 \n" - "punpcklwd %%xmm7,%%xmm5 \n" - "movdqa %%xmm8,%%xmm6 \n" - "movdqa %%xmm9,%%xmm7 \n" - // Third round of bit swap. - // Write to the destination pointer. - "movdqa %%xmm0,%%xmm8 \n" - "punpckldq %%xmm4,%%xmm0 \n" - "movlpd %%xmm0,(%1) \n" // Write back U channel - "movhpd %%xmm0,(%2) \n" // Write back V channel - "punpckhdq %%xmm4,%%xmm8 \n" - "movlpd %%xmm8,(%1,%5) \n" - "lea (%1,%5,2),%1 \n" - "movhpd %%xmm8,(%2,%6) \n" - "lea (%2,%6,2),%2 \n" - "movdqa %%xmm2,%%xmm8 \n" - "punpckldq %%xmm6,%%xmm2 \n" - "movlpd %%xmm2,(%1) \n" - "movhpd %%xmm2,(%2) \n" - "punpckhdq %%xmm6,%%xmm8 \n" - "movlpd %%xmm8,(%1,%5) \n" - "lea (%1,%5,2),%1 \n" - "movhpd %%xmm8,(%2,%6) \n" - "lea (%2,%6,2),%2 \n" - "movdqa %%xmm1,%%xmm8 \n" - "punpckldq %%xmm5,%%xmm1 \n" - "movlpd %%xmm1,(%1) \n" - "movhpd %%xmm1,(%2) \n" - "punpckhdq %%xmm5,%%xmm8 \n" - "movlpd %%xmm8,(%1,%5) \n" - "lea (%1,%5,2),%1 \n" - "movhpd %%xmm8,(%2,%6) \n" - "lea (%2,%6,2),%2 \n" - "movdqa %%xmm3,%%xmm8 \n" - "punpckldq %%xmm7,%%xmm3 \n" - "movlpd %%xmm3,(%1) \n" - "movhpd %%xmm3,(%2) \n" - "punpckhdq %%xmm7,%%xmm8 \n" - "sub $0x8,%3 \n" - "movlpd %%xmm8,(%1,%5) \n" - "lea (%1,%5,2),%1 \n" - "movhpd %%xmm8,(%2,%6) \n" - "lea (%2,%6,2),%2 \n" - "jg 1b \n" - : "+r"(src), // %0 - "+r"(dst_a), // %1 - "+r"(dst_b), // %2 - "+r"(width) // %3 - : "r"((intptr_t)(src_stride)), // %4 - "r"((intptr_t)(dst_stride_a)), // %5 - "r"((intptr_t)(dst_stride_b)) // %6 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7", "xmm8", "xmm9"); + TransposeWx8_Byte_AVX2(src, src_stride, dst_a, dst_stride_a, dst_b, + dst_stride_b, width * 2); } -#endif // defined(HAS_TRANSPOSEUVWX8_SSE2) -#endif // defined(__x86_64__) || defined(__i386__) +#endif // defined(HAS_TRANSPOSEUVWX8_AVX2) + +#if defined(HAS_TRANSPOSEWX16_AVX512BW) || defined(HAS_TRANSPOSEUVWX16_AVX512BW) +// Dword permutes to gather 16 rows of a column from 4 lanes. +static const uint32_t kPermdTranspose_AVX512BW[32] = { + 0, 4, 8, 12, 2, 6, 10, 14, 16, 20, 24, 28, 18, 22, 26, 30, + 1, 5, 9, 13, 3, 7, 11, 15, 17, 21, 25, 29, 19, 23, 27, 31}; + +// Transpose 16x16 bytes held in 4 lanes of 4 zmm registers. +// Source row r is in lane r / 4 of zmm(r % 4). Outputs zmm0..zmm3 are 16 +// destination rows, lane n of zmm0/zmm2 for dst_a and lane n of zmm1/zmm3 +// for dst_b. +#define TRANSPOSE16X16_AVX512BW \ + "vpunpcklbw %%zmm1,%%zmm0,%%zmm4 \n" \ + "vpunpckhbw %%zmm1,%%zmm0,%%zmm5 \n" \ + "vpunpcklbw %%zmm3,%%zmm2,%%zmm0 \n" \ + "vpunpckhbw %%zmm3,%%zmm2,%%zmm1 \n" \ + "vpunpcklwd %%zmm0,%%zmm4,%%zmm2 \n" \ + "vpunpckhwd %%zmm0,%%zmm4,%%zmm3 \n" \ + "vpunpcklwd %%zmm1,%%zmm5,%%zmm4 \n" \ + "vpunpckhwd %%zmm1,%%zmm5,%%zmm5 \n" \ + "vmovdqa64 %%zmm2,%%zmm0 \n" \ + "vpermt2d %%zmm4,%%zmm6,%%zmm0 \n" \ + "vmovdqa64 %%zmm2,%%zmm1 \n" \ + "vpermt2d %%zmm4,%%zmm7,%%zmm1 \n" \ + "vmovdqa64 %%zmm3,%%zmm2 \n" \ + "vpermt2d %%zmm5,%%zmm6,%%zmm2 \n" \ + "vpermt2d %%zmm5,%%zmm7,%%zmm3 \n" + +// Transpose 16x16 bytes using 4 lanes of AVX512BW with tail masking. +// Can be used for 8-bit planar transpose (dst_a = even rows, dst_b = odd rows) +// or 16-bit UV split transpose (dst_a = U plane, dst_b = V plane). +// TODO(fbarchard): Port to rotate_win.cc using intrinsics. +// TODO(fbarchard): Use for ARGB (32 bit) and 16 bit channel transposes. +// TODO(fbarchard): Consider removing in favor of TransposeWx16_Byte_AVX2, +// which is within 10% of AVX512BW on most CPUs. +LIBYUV_TARGET_AVX512BW +static void TransposeWx16_Byte_AVX512BW(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int byte_width) { + uintptr_t temp; + asm volatile( + "vmovdqu32 (%[shuf]),%%zmm6 \n" + "vmovdqu32 0x40(%[shuf]),%%zmm7 \n" + "sub $0x10,%[width] \n" + "jl 2f \n" + + // Main loop: 16 source rows x 16 bytes. + LABELALIGN + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[src_stride]),%%xmm1 \n" + "lea (%[src],%[src_stride],2),%[temp] \n" + "lea 0x10(%[src]),%[src] \n" + "vmovdqu (%[temp]),%%xmm2 \n" + "vmovdqu (%[temp],%[src_stride]),%%xmm3 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti32x4 $1,(%[temp]),%%zmm0,%%zmm0 \n" + "vinserti32x4 $1,(%[temp],%[src_stride]),%%zmm1,%%zmm1 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti32x4 $1,(%[temp]),%%zmm2,%%zmm2 \n" + "vinserti32x4 $1,(%[temp],%[src_stride]),%%zmm3,%%zmm3 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti32x4 $2,(%[temp]),%%zmm0,%%zmm0 \n" + "vinserti32x4 $2,(%[temp],%[src_stride]),%%zmm1,%%zmm1 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti32x4 $2,(%[temp]),%%zmm2,%%zmm2 \n" + "vinserti32x4 $2,(%[temp],%[src_stride]),%%zmm3,%%zmm3 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti32x4 $3,(%[temp]),%%zmm0,%%zmm0 \n" + "vinserti32x4 $3,(%[temp],%[src_stride]),%%zmm1,%%zmm1 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti32x4 $3,(%[temp]),%%zmm2,%%zmm2 \n" + "vinserti32x4 $3,(%[temp],%[src_stride]),%%zmm3,%%zmm3 \n" + + TRANSPOSE16X16_AVX512BW + + "vmovdqu %%xmm0,(%[dst_a]) \n" + "vmovdqu %%xmm1,(%[dst_b]) \n" + "vextracti32x4 $1,%%zmm0,(%[dst_a],%[dst_stride_a]) \n" + "vextracti32x4 $1,%%zmm1,(%[dst_b],%[dst_stride_b]) \n" + "lea (%[dst_a],%[dst_stride_a],2),%[dst_a] \n" + "lea (%[dst_b],%[dst_stride_b],2),%[dst_b] \n" + "vmovdqu %%xmm2,(%[dst_a]) \n" + "vmovdqu %%xmm3,(%[dst_b]) \n" + "vextracti32x4 $1,%%zmm2,(%[dst_a],%[dst_stride_a]) \n" + "vextracti32x4 $1,%%zmm3,(%[dst_b],%[dst_stride_b]) \n" + "lea (%[dst_a],%[dst_stride_a],2),%[dst_a] \n" + "lea (%[dst_b],%[dst_stride_b],2),%[dst_b] \n" + "vextracti32x4 $2,%%zmm0,(%[dst_a]) \n" + "vextracti32x4 $2,%%zmm1,(%[dst_b]) \n" + "vextracti32x4 $3,%%zmm0,(%[dst_a],%[dst_stride_a]) \n" + "vextracti32x4 $3,%%zmm1,(%[dst_b],%[dst_stride_b]) \n" + "lea (%[dst_a],%[dst_stride_a],2),%[dst_a] \n" + "lea (%[dst_b],%[dst_stride_b],2),%[dst_b] \n" + "vextracti32x4 $2,%%zmm2,(%[dst_a]) \n" + "vextracti32x4 $2,%%zmm3,(%[dst_b]) \n" + "vextracti32x4 $3,%%zmm2,(%[dst_a],%[dst_stride_a]) \n" + "vextracti32x4 $3,%%zmm3,(%[dst_b],%[dst_stride_b]) \n" + "lea (%[dst_a],%[dst_stride_a],2),%[dst_a] \n" + "lea (%[dst_b],%[dst_stride_b],2),%[dst_b] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + // Remainder: 1 to 15 bytes, masked loads. + "2: \n" + "add $0x10,%[width] \n" + "je 99f \n" + "mov $-1,%k[temp] \n" + "bzhi %k[width],%k[temp],%k[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu8 (%[src]),%%xmm0%{%%k1%}%{z%} \n" + "vmovdqu8 (%[src],%[src_stride]),%%xmm1%{%%k1%}%{z%} \n" + "lea (%[src],%[src_stride],2),%[src] \n" + "vmovdqu8 (%[src]),%%xmm2%{%%k1%}%{z%} \n" + "vmovdqu8 (%[src],%[src_stride]),%%xmm3%{%%k1%}%{z%} \n" + "lea (%[src],%[src_stride],2),%[src] \n" + "vmovdqu8 (%[src]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm4,%%zmm0,%%zmm0 \n" + "vmovdqu8 (%[src],%[src_stride]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm4,%%zmm1,%%zmm1 \n" + "lea (%[src],%[src_stride],2),%[src] \n" + "vmovdqu8 (%[src]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm4,%%zmm2,%%zmm2 \n" + "vmovdqu8 (%[src],%[src_stride]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm4,%%zmm3,%%zmm3 \n" + "lea (%[src],%[src_stride],2),%[src] \n" + "vmovdqu8 (%[src]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm4,%%zmm0,%%zmm0 \n" + "vmovdqu8 (%[src],%[src_stride]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm4,%%zmm1,%%zmm1 \n" + "lea (%[src],%[src_stride],2),%[src] \n" + "vmovdqu8 (%[src]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm4,%%zmm2,%%zmm2 \n" + "vmovdqu8 (%[src],%[src_stride]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm4,%%zmm3,%%zmm3 \n" + "lea (%[src],%[src_stride],2),%[src] \n" + "vmovdqu8 (%[src]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm4,%%zmm0,%%zmm0 \n" + "vmovdqu8 (%[src],%[src_stride]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm4,%%zmm1,%%zmm1 \n" + "lea (%[src],%[src_stride],2),%[src] \n" + "vmovdqu8 (%[src]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm4,%%zmm2,%%zmm2 \n" + "vmovdqu8 (%[src],%[src_stride]),%%xmm4%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm4,%%zmm3,%%zmm3 \n" + + TRANSPOSE16X16_AVX512BW + + // Store 1 destination row per remaining byte. + "vmovdqu %%xmm0,(%[dst_a]) \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vmovdqu %%xmm1,(%[dst_b]) \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vextracti32x4 $1,%%zmm0,(%[dst_a],%[dst_stride_a]) \n" + "lea (%[dst_a],%[dst_stride_a],2),%[dst_a] \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vextracti32x4 $1,%%zmm1,(%[dst_b],%[dst_stride_b]) \n" + "lea (%[dst_b],%[dst_stride_b],2),%[dst_b] \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vmovdqu %%xmm2,(%[dst_a]) \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vmovdqu %%xmm3,(%[dst_b]) \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vextracti32x4 $1,%%zmm2,(%[dst_a],%[dst_stride_a]) \n" + "lea (%[dst_a],%[dst_stride_a],2),%[dst_a] \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vextracti32x4 $1,%%zmm3,(%[dst_b],%[dst_stride_b]) \n" + "lea (%[dst_b],%[dst_stride_b],2),%[dst_b] \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vextracti32x4 $2,%%zmm0,(%[dst_a]) \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vextracti32x4 $2,%%zmm1,(%[dst_b]) \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vextracti32x4 $3,%%zmm0,(%[dst_a],%[dst_stride_a]) \n" + "lea (%[dst_a],%[dst_stride_a],2),%[dst_a] \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vextracti32x4 $3,%%zmm1,(%[dst_b],%[dst_stride_b]) \n" + "lea (%[dst_b],%[dst_stride_b],2),%[dst_b] \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vextracti32x4 $2,%%zmm2,(%[dst_a]) \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vextracti32x4 $2,%%zmm3,(%[dst_b]) \n" + "sub $0x1,%[width] \n" + "je 99f \n" + "vextracti32x4 $3,%%zmm2,(%[dst_a],%[dst_stride_a]) \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src), [dst_a] "+r"(dst_a), [dst_b] "+r"(dst_b), + [width] "+r"(byte_width), [temp] "=&r"(temp) + : [src_stride] "r"((ptrdiff_t)src_stride), + [dst_stride_a] "r"((ptrdiff_t)dst_stride_a), + [dst_stride_b] "r"((ptrdiff_t)dst_stride_b), + [shuf] "r"(kPermdTranspose_AVX512BW) + : "memory", "cc", "k1", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); +} +#undef TRANSPOSE16X16_AVX512BW +#endif // defined(HAS_TRANSPOSEWX16_AVX512BW) || + // defined(HAS_TRANSPOSEUVWX16_AVX512BW) + +#if defined(HAS_TRANSPOSEWX16_AVX512BW) +void TransposeWx16_AVX512BW(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + TransposeWx16_Byte_AVX512BW(src, src_stride, dst, dst_stride * 2, + dst + (width > 1 ? dst_stride : 0), + dst_stride * 2, width); +} +#endif // defined(HAS_TRANSPOSEWX16_AVX512BW) + +#if defined(HAS_TRANSPOSEUVWX16_AVX512BW) +void TransposeUVWx16_AVX512BW(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width) { + TransposeWx16_Byte_AVX512BW(src, src_stride, dst_a, dst_stride_a, dst_b, + dst_stride_b, width * 2); +} +#endif // defined(HAS_TRANSPOSEUVWX16_AVX512BW) + +#if defined(__x86_64__) +#if defined(HAS_TRANSPOSEWX16_AVX2) || defined(HAS_TRANSPOSEUVWX16_AVX2) +// Transpose 16x16 bytes using 2 lanes of AVX2. Source row r is in lane r / 8 +// of ymm(r % 8). 3 unpack stages leave each lane with 2 columns x 8 rows, and +// vpermq joins the rows 0..7 and 8..15 halves. Lane 0 of each output is an +// even column for dst_a and lane 1 an odd column for dst_b. +// Width is a multiple of 16 bytes. +static void TransposeWx16_Byte_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int byte_width) { + uintptr_t temp; + asm volatile( + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[src_stride]),%%xmm1 \n" + "lea (%[src],%[src_stride],2),%[temp] \n" + "lea 0x10(%[src]),%[src] \n" + "vmovdqu (%[temp]),%%xmm2 \n" + "vmovdqu (%[temp],%[src_stride]),%%xmm3 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm4 \n" + "vmovdqu (%[temp],%[src_stride]),%%xmm5 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm6 \n" + "vmovdqu (%[temp],%[src_stride]),%%xmm7 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm0,%%ymm0 \n" + "vinserti128 $1,(%[temp],%[src_stride]),%%ymm1,%%ymm1 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm2,%%ymm2 \n" + "vinserti128 $1,(%[temp],%[src_stride]),%%ymm3,%%ymm3 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm4,%%ymm4 \n" + "vinserti128 $1,(%[temp],%[src_stride]),%%ymm5,%%ymm5 \n" + "lea (%[temp],%[src_stride],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm6,%%ymm6 \n" + "vinserti128 $1,(%[temp],%[src_stride]),%%ymm7,%%ymm7 \n" + + "vpunpcklbw %%ymm1,%%ymm0,%%ymm8 \n" + "vpunpckhbw %%ymm1,%%ymm0,%%ymm9 \n" + "vpunpcklbw %%ymm3,%%ymm2,%%ymm10 \n" + "vpunpckhbw %%ymm3,%%ymm2,%%ymm11 \n" + "vpunpcklbw %%ymm5,%%ymm4,%%ymm12 \n" + "vpunpckhbw %%ymm5,%%ymm4,%%ymm13 \n" + "vpunpcklbw %%ymm7,%%ymm6,%%ymm14 \n" + "vpunpckhbw %%ymm7,%%ymm6,%%ymm15 \n" + + "vpunpcklwd %%ymm10,%%ymm8,%%ymm0 \n" + "vpunpckhwd %%ymm10,%%ymm8,%%ymm1 \n" + "vpunpcklwd %%ymm11,%%ymm9,%%ymm2 \n" + "vpunpckhwd %%ymm11,%%ymm9,%%ymm3 \n" + "vpunpcklwd %%ymm14,%%ymm12,%%ymm4 \n" + "vpunpckhwd %%ymm14,%%ymm12,%%ymm5 \n" + "vpunpcklwd %%ymm15,%%ymm13,%%ymm6 \n" + "vpunpckhwd %%ymm15,%%ymm13,%%ymm7 \n" + + "vpunpckldq %%ymm4,%%ymm0,%%ymm8 \n" + "vpunpckhdq %%ymm4,%%ymm0,%%ymm9 \n" + "vpunpckldq %%ymm5,%%ymm1,%%ymm10 \n" + "vpunpckhdq %%ymm5,%%ymm1,%%ymm11 \n" + "vpunpckldq %%ymm6,%%ymm2,%%ymm12 \n" + "vpunpckhdq %%ymm6,%%ymm2,%%ymm13 \n" + "vpunpckldq %%ymm7,%%ymm3,%%ymm14 \n" + "vpunpckhdq %%ymm7,%%ymm3,%%ymm15 \n" + + "vpermq $0xd8,%%ymm8,%%ymm8 \n" + "vpermq $0xd8,%%ymm9,%%ymm9 \n" + "vpermq $0xd8,%%ymm10,%%ymm10 \n" + "vpermq $0xd8,%%ymm11,%%ymm11 \n" + "vpermq $0xd8,%%ymm12,%%ymm12 \n" + "vpermq $0xd8,%%ymm13,%%ymm13 \n" + "vpermq $0xd8,%%ymm14,%%ymm14 \n" + "vpermq $0xd8,%%ymm15,%%ymm15 \n" + + "vmovdqu %%xmm8,(%[dst_a]) \n" + "vextracti128 $1,%%ymm8,(%[dst_b]) \n" + "vmovdqu %%xmm9,(%[dst_a],%[dst_stride_a]) \n" + "vextracti128 $1,%%ymm9,(%[dst_b],%[dst_stride_b]) \n" + "lea (%[dst_a],%[dst_stride_a],2),%[dst_a] \n" + "lea (%[dst_b],%[dst_stride_b],2),%[dst_b] \n" + "vmovdqu %%xmm10,(%[dst_a]) \n" + "vextracti128 $1,%%ymm10,(%[dst_b]) \n" + "vmovdqu %%xmm11,(%[dst_a],%[dst_stride_a]) \n" + "vextracti128 $1,%%ymm11,(%[dst_b],%[dst_stride_b]) \n" + "lea (%[dst_a],%[dst_stride_a],2),%[dst_a] \n" + "lea (%[dst_b],%[dst_stride_b],2),%[dst_b] \n" + "vmovdqu %%xmm12,(%[dst_a]) \n" + "vextracti128 $1,%%ymm12,(%[dst_b]) \n" + "vmovdqu %%xmm13,(%[dst_a],%[dst_stride_a]) \n" + "vextracti128 $1,%%ymm13,(%[dst_b],%[dst_stride_b]) \n" + "lea (%[dst_a],%[dst_stride_a],2),%[dst_a] \n" + "lea (%[dst_b],%[dst_stride_b],2),%[dst_b] \n" + "vmovdqu %%xmm14,(%[dst_a]) \n" + "vextracti128 $1,%%ymm14,(%[dst_b]) \n" + "vmovdqu %%xmm15,(%[dst_a],%[dst_stride_a]) \n" + "vextracti128 $1,%%ymm15,(%[dst_b],%[dst_stride_b]) \n" + "lea (%[dst_a],%[dst_stride_a],2),%[dst_a] \n" + "lea (%[dst_b],%[dst_stride_b],2),%[dst_b] \n" + "sub $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src), [dst_a] "+r"(dst_a), [dst_b] "+r"(dst_b), + [width] "+r"(byte_width), [temp] "=&r"(temp) + : [src_stride] "r"((ptrdiff_t)src_stride), + [dst_stride_a] "r"((ptrdiff_t)dst_stride_a), + [dst_stride_b] "r"((ptrdiff_t)dst_stride_b) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", + "xmm15"); +} +#endif // defined(HAS_TRANSPOSEWX16_AVX2) || defined(HAS_TRANSPOSEUVWX16_AVX2) + +#if defined(HAS_TRANSPOSEWX16_AVX2) +void TransposeWx16_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + TransposeWx16_Byte_AVX2(src, src_stride, dst, dst_stride * 2, + dst + dst_stride, dst_stride * 2, width); +} +#endif // defined(HAS_TRANSPOSEWX16_AVX2) + +#if defined(HAS_TRANSPOSEUVWX16_AVX2) +void TransposeUVWx16_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width) { + TransposeWx16_Byte_AVX2(src, src_stride, dst_a, dst_stride_a, dst_b, + dst_stride_b, width * 2); +} +#endif // defined(HAS_TRANSPOSEUVWX16_AVX2) +#else // !defined(__x86_64__) +#if defined(HAS_TRANSPOSEWX16_AVX2) +void TransposeWx16_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + TransposeWx8_AVX2(src, src_stride, dst, dst_stride, width); + TransposeWx8_AVX2(src + 8 * (ptrdiff_t)src_stride, src_stride, dst + 8, + dst_stride, width); +} +#endif // defined(HAS_TRANSPOSEWX16_AVX2) + +#if defined(HAS_TRANSPOSEUVWX16_AVX2) +void TransposeUVWx16_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width) { + TransposeUVWx8_AVX2(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, + width); + TransposeUVWx8_AVX2(src + 8 * (ptrdiff_t)src_stride, src_stride, dst_a + 8, + dst_stride_a, dst_b + 8, dst_stride_b, width); +} +#endif // defined(HAS_TRANSPOSEUVWX16_AVX2) +#endif // defined(__x86_64__) + +#if defined(HAS_TRANSPOSEWX16_16_AVX2) +#if defined(__x86_64__) +void TransposeWx16_16_AVX2(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = (ptrdiff_t)src_stride * 2; + const ptrdiff_t d = (ptrdiff_t)dst_stride * 2; + const uint8_t* src_b = (const uint8_t*)src; + uint8_t* dst_b = (uint8_t*)dst; + const uint8_t* temp; + asm volatile( + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm2 \n" + "vmovdqu (%[temp],%[s]),%%xmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm4 \n" + "vmovdqu (%[temp],%[s]),%%xmm5 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm6 \n" + "vmovdqu (%[temp],%[s]),%%xmm7 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vinserti128 $1,(%[temp]),%%ymm0,%%ymm0 \n" + "vinserti128 $1,(%[temp],%[s]),%%ymm1,%%ymm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm2,%%ymm2 \n" + "vinserti128 $1,(%[temp],%[s]),%%ymm3,%%ymm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm4,%%ymm4 \n" + "vinserti128 $1,(%[temp],%[s]),%%ymm5,%%ymm5 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm6,%%ymm6 \n" + "vinserti128 $1,(%[temp],%[s]),%%ymm7,%%ymm7 \n" + "add $0x10,%[src] \n" + + // Stage 1: 16-bit unpack -> ymm8..ymm15 + "vpunpcklwd %%ymm1,%%ymm0,%%ymm8 \n" + "vpunpckhwd %%ymm1,%%ymm0,%%ymm9 \n" + "vpunpcklwd %%ymm3,%%ymm2,%%ymm10 \n" + "vpunpckhwd %%ymm3,%%ymm2,%%ymm11 \n" + "vpunpcklwd %%ymm5,%%ymm4,%%ymm12 \n" + "vpunpckhwd %%ymm5,%%ymm4,%%ymm13 \n" + "vpunpcklwd %%ymm7,%%ymm6,%%ymm14 \n" + "vpunpckhwd %%ymm7,%%ymm6,%%ymm15 \n" + + // Stage 2: 32-bit unpack -> ymm0..ymm7 + "vpunpckldq %%ymm10,%%ymm8,%%ymm0 \n" + "vpunpckhdq %%ymm10,%%ymm8,%%ymm1 \n" + "vpunpckldq %%ymm11,%%ymm9,%%ymm2 \n" + "vpunpckhdq %%ymm11,%%ymm9,%%ymm3 \n" + "vpunpckldq %%ymm14,%%ymm12,%%ymm4 \n" + "vpunpckhdq %%ymm14,%%ymm12,%%ymm5 \n" + "vpunpckldq %%ymm15,%%ymm13,%%ymm6 \n" + "vpunpckhdq %%ymm15,%%ymm13,%%ymm7 \n" + + // Stage 3: 64-bit unpack -> ymm8..ymm15 + "vpunpcklqdq %%ymm4,%%ymm0,%%ymm8 \n" + "vpunpckhqdq %%ymm4,%%ymm0,%%ymm9 \n" + "vpunpcklqdq %%ymm5,%%ymm1,%%ymm10 \n" + "vpunpckhqdq %%ymm5,%%ymm1,%%ymm11 \n" + "vpunpcklqdq %%ymm6,%%ymm2,%%ymm12 \n" + "vpunpckhqdq %%ymm6,%%ymm2,%%ymm13 \n" + "vpunpcklqdq %%ymm7,%%ymm3,%%ymm14 \n" + "vpunpckhqdq %%ymm7,%%ymm3,%%ymm15 \n" + + "vmovdqu %%ymm8,(%[dst]) \n" + "vmovdqu %%ymm9,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu %%ymm10,(%[dst]) \n" + "vmovdqu %%ymm11,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu %%ymm12,(%[dst]) \n" + "vmovdqu %%ymm13,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu %%ymm14,(%[dst]) \n" + "vmovdqu %%ymm15,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "sub $0x8,%[w] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src_b), // %[src] + [dst] "+r"(dst_b), // %[dst] + [w] "+r"(width), // %[w] + [temp] "=&r"(temp) // %[temp] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", + "xmm15"); +} +#endif // defined(__x86_64__) +#endif // defined(HAS_TRANSPOSEWX16_16_AVX2) + +#if defined(HAS_TRANSPOSEWX8_16_AVX2) +void TransposeWx8_16_AVX2(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = (ptrdiff_t)src_stride * 2; + const ptrdiff_t d = (ptrdiff_t)dst_stride * 2; + const uint8_t* src_b = (const uint8_t*)src; + uint8_t* dst_b = (uint8_t*)dst; + const uint8_t* temp; + asm volatile( + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm2 \n" + "vmovdqu (%[temp],%[s]),%%xmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm0,%%ymm0 \n" + "vinserti128 $1,(%[temp],%[s]),%%ymm1,%%ymm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm2,%%ymm2 \n" + "vinserti128 $1,(%[temp],%[s]),%%ymm3,%%ymm3 \n" + "add $0x10,%[src] \n" + + "vpunpcklwd %%ymm1,%%ymm0,%%ymm4 \n" + "vpunpckhwd %%ymm1,%%ymm0,%%ymm5 \n" + "vpunpcklwd %%ymm3,%%ymm2,%%ymm6 \n" + "vpunpckhwd %%ymm3,%%ymm2,%%ymm7 \n" + + "vpunpckldq %%ymm6,%%ymm4,%%ymm0 \n" + "vpunpckhdq %%ymm6,%%ymm4,%%ymm1 \n" + "vpunpckldq %%ymm7,%%ymm5,%%ymm2 \n" + "vpunpckhdq %%ymm7,%%ymm5,%%ymm3 \n" + + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpermq $0xd8,%%ymm2,%%ymm2 \n" + "vpermq $0xd8,%%ymm3,%%ymm3 \n" + + "vmovdqu %%xmm0,(%[dst]) \n" + "vextracti128 $1,%%ymm0,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu %%xmm1,(%[dst]) \n" + "vextracti128 $1,%%ymm1,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu %%xmm2,(%[dst]) \n" + "vextracti128 $1,%%ymm2,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu %%xmm3,(%[dst]) \n" + "vextracti128 $1,%%ymm3,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "subl $0x8,%[w] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src_b), + [dst] "+r"(dst_b), +#if defined(__i386__) + [w] "+m"(width), +#else + [w] "+rm"(width), +#endif + [temp] "=&r"(temp) + : [s] "r"(s), + [d] "r"(d) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // defined(HAS_TRANSPOSEWX8_16_AVX2) + +#if defined(HAS_TRANSPOSEWX16_16_AVX2) && !defined(__x86_64__) +void TransposeWx16_16_AVX2(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + TransposeWx8_16_AVX2(src, src_stride, dst, dst_stride, width); + TransposeWx8_16_AVX2(src + 8 * (ptrdiff_t)src_stride, src_stride, dst + 8, + dst_stride, width); +} +#endif // defined(HAS_TRANSPOSEWX16_16_AVX2) && !defined(__x86_64__) + +#if defined(HAS_TRANSPOSEWX32_16_AVX512BW) +// Transpose 32 rows of 16 bit plane (arbitrary width) using 8x32 tiles in +// zmm0..zmm15 with k1-masked right tail. +LIBYUV_TARGET_AVX512BW +void TransposeWx32_16_AVX512BW(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = (ptrdiff_t)src_stride * 2; + const ptrdiff_t d = (ptrdiff_t)dst_stride * 2; + const uint8_t* src_b = (const uint8_t*)src; + uint8_t* dst_b = (uint8_t*)dst; + const int n = width & ~7; + if (n > 0) { + int cnt = n; + const uint8_t* temp; + asm volatile( + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm2 \n" + "vmovdqu (%[temp],%[s]),%%xmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm4 \n" + "vmovdqu (%[temp],%[s]),%%xmm5 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm6 \n" + "vmovdqu (%[temp],%[s]),%%xmm7 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vinserti32x4 $1,(%[temp]),%%zmm0,%%zmm0 \n" + "vinserti32x4 $1,(%[temp],%[s]),%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $1,(%[temp]),%%zmm2,%%zmm2 \n" + "vinserti32x4 $1,(%[temp],%[s]),%%zmm3,%%zmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $1,(%[temp]),%%zmm4,%%zmm4 \n" + "vinserti32x4 $1,(%[temp],%[s]),%%zmm5,%%zmm5 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $1,(%[temp]),%%zmm6,%%zmm6 \n" + "vinserti32x4 $1,(%[temp],%[s]),%%zmm7,%%zmm7 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vinserti32x4 $2,(%[temp]),%%zmm0,%%zmm0 \n" + "vinserti32x4 $2,(%[temp],%[s]),%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $2,(%[temp]),%%zmm2,%%zmm2 \n" + "vinserti32x4 $2,(%[temp],%[s]),%%zmm3,%%zmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $2,(%[temp]),%%zmm4,%%zmm4 \n" + "vinserti32x4 $2,(%[temp],%[s]),%%zmm5,%%zmm5 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $2,(%[temp]),%%zmm6,%%zmm6 \n" + "vinserti32x4 $2,(%[temp],%[s]),%%zmm7,%%zmm7 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vinserti32x4 $3,(%[temp]),%%zmm0,%%zmm0 \n" + "vinserti32x4 $3,(%[temp],%[s]),%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $3,(%[temp]),%%zmm2,%%zmm2 \n" + "vinserti32x4 $3,(%[temp],%[s]),%%zmm3,%%zmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $3,(%[temp]),%%zmm4,%%zmm4 \n" + "vinserti32x4 $3,(%[temp],%[s]),%%zmm5,%%zmm5 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $3,(%[temp]),%%zmm6,%%zmm6 \n" + "vinserti32x4 $3,(%[temp],%[s]),%%zmm7,%%zmm7 \n" + "add $0x10,%[src] \n" + + // Stage 1: 16-bit unpack -> zmm8..zmm15 + "vpunpcklwd %%zmm1,%%zmm0,%%zmm8 \n" + "vpunpckhwd %%zmm1,%%zmm0,%%zmm9 \n" + "vpunpcklwd %%zmm3,%%zmm2,%%zmm10 \n" + "vpunpckhwd %%zmm3,%%zmm2,%%zmm11 \n" + "vpunpcklwd %%zmm5,%%zmm4,%%zmm12 \n" + "vpunpckhwd %%zmm5,%%zmm4,%%zmm13 \n" + "vpunpcklwd %%zmm7,%%zmm6,%%zmm14 \n" + "vpunpckhwd %%zmm7,%%zmm6,%%zmm15 \n" + + // Stage 2: 32-bit unpack -> zmm0..zmm7 + "vpunpckldq %%zmm10,%%zmm8,%%zmm0 \n" + "vpunpckhdq %%zmm10,%%zmm8,%%zmm1 \n" + "vpunpckldq %%zmm11,%%zmm9,%%zmm2 \n" + "vpunpckhdq %%zmm11,%%zmm9,%%zmm3 \n" + "vpunpckldq %%zmm14,%%zmm12,%%zmm4 \n" + "vpunpckhdq %%zmm14,%%zmm12,%%zmm5 \n" + "vpunpckldq %%zmm15,%%zmm13,%%zmm6 \n" + "vpunpckhdq %%zmm15,%%zmm13,%%zmm7 \n" + + // Stage 3: 64-bit unpack -> zmm8..zmm15 + "vpunpcklqdq %%zmm4,%%zmm0,%%zmm8 \n" + "vpunpckhqdq %%zmm4,%%zmm0,%%zmm9 \n" + "vpunpcklqdq %%zmm5,%%zmm1,%%zmm10 \n" + "vpunpckhqdq %%zmm5,%%zmm1,%%zmm11 \n" + "vpunpcklqdq %%zmm6,%%zmm2,%%zmm12 \n" + "vpunpckhqdq %%zmm6,%%zmm2,%%zmm13 \n" + "vpunpcklqdq %%zmm7,%%zmm3,%%zmm14 \n" + "vpunpckhqdq %%zmm7,%%zmm3,%%zmm15 \n" + + "vmovdqu16 %%zmm8,(%[dst]) \n" + "vmovdqu16 %%zmm9,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu16 %%zmm10,(%[dst]) \n" + "vmovdqu16 %%zmm11,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu16 %%zmm12,(%[dst]) \n" + "vmovdqu16 %%zmm13,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu16 %%zmm14,(%[dst]) \n" + "vmovdqu16 %%zmm15,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "sub $0x8,%[cnt] \n" + "jg 1b \n" + : [src] "+r"(src_b), // %[src] + [dst] "+r"(dst_b), // %[dst] + [cnt] "+r"(cnt), // %[cnt] + [temp] "=&r"(temp) // %[temp] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", + "xmm14", "xmm15"); + width -= n; + } + if (width > 0) { + const uint32_t col_mask = (1u << width) - 1; + const uint8_t* temp; + asm volatile( + "kmovw %[col_mask],%%k1 \n" + "vmovdqu16 (%[src]),%%xmm0%{%%k1%}%{z%} \n" + "vmovdqu16 (%[src],%[s]),%%xmm1%{%%k1%}%{z%} \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm2%{%%k1%}%{z%} \n" + "vmovdqu16 (%[temp],%[s]),%%xmm3%{%%k1%}%{z%} \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm4%{%%k1%}%{z%} \n" + "vmovdqu16 (%[temp],%[s]),%%xmm5%{%%k1%}%{z%} \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm6%{%%k1%}%{z%} \n" + "vmovdqu16 (%[temp],%[s]),%%xmm7%{%%k1%}%{z%} \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm16,%%zmm0,%%zmm0 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm16,%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm16,%%zmm2,%%zmm2 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm16,%%zmm3,%%zmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm16,%%zmm4,%%zmm4 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm16,%%zmm5,%%zmm5 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm16,%%zmm6,%%zmm6 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm16,%%zmm7,%%zmm7 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm16,%%zmm0,%%zmm0 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm16,%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm16,%%zmm2,%%zmm2 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm16,%%zmm3,%%zmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm16,%%zmm4,%%zmm4 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm16,%%zmm5,%%zmm5 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm16,%%zmm6,%%zmm6 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm16,%%zmm7,%%zmm7 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm16,%%zmm0,%%zmm0 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm16,%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm16,%%zmm2,%%zmm2 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm16,%%zmm3,%%zmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm16,%%zmm4,%%zmm4 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm16,%%zmm5,%%zmm5 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu16 (%[temp]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm16,%%zmm6,%%zmm6 \n" + "vmovdqu16 (%[temp],%[s]),%%xmm16%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm16,%%zmm7,%%zmm7 \n" + + // Stage 1: 16-bit unpack -> zmm8..zmm15 + "vpunpcklwd %%zmm1,%%zmm0,%%zmm8 \n" + "vpunpckhwd %%zmm1,%%zmm0,%%zmm9 \n" + "vpunpcklwd %%zmm3,%%zmm2,%%zmm10 \n" + "vpunpckhwd %%zmm3,%%zmm2,%%zmm11 \n" + "vpunpcklwd %%zmm5,%%zmm4,%%zmm12 \n" + "vpunpckhwd %%zmm5,%%zmm4,%%zmm13 \n" + "vpunpcklwd %%zmm7,%%zmm6,%%zmm14 \n" + "vpunpckhwd %%zmm7,%%zmm6,%%zmm15 \n" + + // Stage 2: 32-bit unpack -> zmm0..zmm7 + "vpunpckldq %%zmm10,%%zmm8,%%zmm0 \n" + "vpunpckhdq %%zmm10,%%zmm8,%%zmm1 \n" + "vpunpckldq %%zmm11,%%zmm9,%%zmm2 \n" + "vpunpckhdq %%zmm11,%%zmm9,%%zmm3 \n" + "vpunpckldq %%zmm14,%%zmm12,%%zmm4 \n" + "vpunpckhdq %%zmm14,%%zmm12,%%zmm5 \n" + "vpunpckldq %%zmm15,%%zmm13,%%zmm6 \n" + "vpunpckhdq %%zmm15,%%zmm13,%%zmm7 \n" + + // Stage 3: 64-bit unpack -> zmm8..zmm15 + "vpunpcklqdq %%zmm4,%%zmm0,%%zmm8 \n" + "vpunpckhqdq %%zmm4,%%zmm0,%%zmm9 \n" + "vpunpcklqdq %%zmm5,%%zmm1,%%zmm10 \n" + "vpunpckhqdq %%zmm5,%%zmm1,%%zmm11 \n" + "vpunpcklqdq %%zmm6,%%zmm2,%%zmm12 \n" + "vpunpckhqdq %%zmm6,%%zmm2,%%zmm13 \n" + "vpunpcklqdq %%zmm7,%%zmm3,%%zmm14 \n" + "vpunpckhqdq %%zmm7,%%zmm3,%%zmm15 \n" + + "vmovdqu16 %%zmm8,(%[dst]) \n" + "cmp $1,%[width] \n" + "jle 2f \n" + "vmovdqu16 %%zmm9,(%[dst],%[d]) \n" + "cmp $2,%[width] \n" + "jle 2f \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu16 %%zmm10,(%[dst]) \n" + "cmp $3,%[width] \n" + "jle 2f \n" + "vmovdqu16 %%zmm11,(%[dst],%[d]) \n" + "cmp $4,%[width] \n" + "jle 2f \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu16 %%zmm12,(%[dst]) \n" + "cmp $5,%[width] \n" + "jle 2f \n" + "vmovdqu16 %%zmm13,(%[dst],%[d]) \n" + "cmp $6,%[width] \n" + "jle 2f \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu16 %%zmm14,(%[dst]) \n" + "2: \n" + : [dst] "+r"(dst_b), // %[dst] + [temp] "=&r"(temp) // %[temp] + : [src] "r"(src_b), // %[src] + [s] "r"(s), // %[s] + [d] "r"(d), // %[d] + [col_mask] "r"(col_mask), // %[col_mask] + [width] "r"(width) // %[width] + : "memory", "cc", "k1", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", + "xmm14", "xmm15", "xmm16"); + } + asm volatile("vzeroupper \n"); +} +#endif // defined(HAS_TRANSPOSEWX32_16_AVX512BW) + +#if defined(HAS_TRANSPOSEWX4_32_AVX2) +// Transpose 32 bit values (ARGB). Read a column of 4 pixels across 8 rows per +// AVX2 iteration (with a 4-row VEX 128-bit tail) and write 4 destination rows. +void TransposeWx4_32_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + uintptr_t temp; + asm volatile( + "subl $0x8,%[width] \n" + "jl 2f \n" + + // Main loop: 8 source rows of 4 pixels -> 4 dst rows of 8 pixels (32 B). + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm2 \n" + "vmovdqu (%[temp],%[s]),%%xmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm0,%%ymm0 \n" + "vinserti128 $1,(%[temp],%[s]),%%ymm1,%%ymm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm2,%%ymm2 \n" + "vinserti128 $1,(%[temp],%[s]),%%ymm3,%%ymm3 \n" + "lea (%[temp],%[s],2),%[src] \n" + + "vpunpckldq %%ymm1,%%ymm0,%%ymm4 \n" + "vpunpckldq %%ymm3,%%ymm2,%%ymm5 \n" + "vpunpckhdq %%ymm1,%%ymm0,%%ymm6 \n" + "vpunpckhdq %%ymm3,%%ymm2,%%ymm7 \n" + + "vpunpcklqdq %%ymm5,%%ymm4,%%ymm0 \n" + "vpunpckhqdq %%ymm5,%%ymm4,%%ymm1 \n" + "vpunpcklqdq %%ymm7,%%ymm6,%%ymm2 \n" + "vpunpckhqdq %%ymm7,%%ymm6,%%ymm3 \n" + + "vmovdqu %%ymm0,(%[dst]) \n" + "vmovdqu %%ymm1,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[temp] \n" + "vmovdqu %%ymm2,(%[temp]) \n" + "vmovdqu %%ymm3,(%[temp],%[d]) \n" + "add $0x20,%[dst] \n" + "subl $0x8,%[width] \n" + "jge 1b \n" + + // Tail: 4 source rows of 4 pixels -> 4 dst rows of 4 pixels (16 B). + "2: \n" + "addl $0x8,%[width] \n" + "je 99f \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm2 \n" + "vmovdqu (%[temp],%[s]),%%xmm3 \n" + + "vpunpckldq %%xmm1,%%xmm0,%%xmm4 \n" + "vpunpckldq %%xmm3,%%xmm2,%%xmm5 \n" + "vpunpckhdq %%xmm1,%%xmm0,%%xmm6 \n" + "vpunpckhdq %%xmm3,%%xmm2,%%xmm7 \n" + + "vpunpcklqdq %%xmm5,%%xmm4,%%xmm0 \n" + "vpunpckhqdq %%xmm5,%%xmm4,%%xmm1 \n" + "vpunpcklqdq %%xmm7,%%xmm6,%%xmm2 \n" + "vpunpckhqdq %%xmm7,%%xmm6,%%xmm3 \n" + + "vmovdqu %%xmm0,(%[dst]) \n" + "vmovdqu %%xmm1,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[temp] \n" + "vmovdqu %%xmm2,(%[temp]) \n" + "vmovdqu %%xmm3,(%[temp],%[d]) \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [width] "+rm"(width), // %[width] + [temp] "=&r"(temp) // %[temp] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // defined(HAS_TRANSPOSEWX4_32_AVX2) + +#if defined(HAS_TRANSPOSEWX8_32_AVX2) +// Transpose 8 rows of 32 bit plane (width multiple of 4) using 4x8 YMM vertical +// tiles in ymm0..ymm7. +void TransposeWx8_32_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + const uint8_t* temp; + asm volatile( + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm2 \n" + "vmovdqu (%[temp],%[s]),%%xmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vinserti128 $1,(%[temp]),%%ymm0,%%ymm0 \n" + "vinserti128 $1,(%[temp],%[s]),%%ymm1,%%ymm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti128 $1,(%[temp]),%%ymm2,%%ymm2 \n" + "vinserti128 $1,(%[temp],%[s]),%%ymm3,%%ymm3 \n" + "add $0x10,%[src] \n" + + // Stage 1: 32-bit unpack across both 128-bit lanes + "vpunpckldq %%ymm1,%%ymm0,%%ymm4 \n" + "vpunpckldq %%ymm3,%%ymm2,%%ymm5 \n" + "vpunpckhdq %%ymm1,%%ymm0,%%ymm6 \n" + "vpunpckhdq %%ymm3,%%ymm2,%%ymm7 \n" + + // Stage 2: 64-bit unpack across both 128-bit lanes + "vpunpcklqdq %%ymm5,%%ymm4,%%ymm0 \n" + "vpunpckhqdq %%ymm5,%%ymm4,%%ymm1 \n" + "vpunpcklqdq %%ymm7,%%ymm6,%%ymm2 \n" + "vpunpckhqdq %%ymm7,%%ymm6,%%ymm3 \n" + + // Store 4 full 256-bit (32 B) rows = 8 32-bit pixels each + "vmovdqu %%ymm0,(%[dst]) \n" + "vmovdqu %%ymm1,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu %%ymm2,(%[dst]) \n" + "vmovdqu %%ymm3,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "subl $0x4,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [width] "+rm"(width), // %[width] + [temp] "=&r"(temp) // %[temp] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // defined(HAS_TRANSPOSEWX8_32_AVX2) + +#if defined(HAS_TRANSPOSEWXH_32_AVX2) +// Transpose rem_w (1..3) columns x 8 rows of 32-bit pixels using AVX2. +static void TransposeRemWx8_32_AVX2(const uint8_t* src, + ptrdiff_t s, + uint8_t* dst, + ptrdiff_t d, + int rem_w) { + const uint8_t* temp; + asm volatile( + "cmpl $2,%[rem_w] \n" + "jl 1f \n" + "je 2f \n" + + // rem_w == 3: load 12 bytes per row from 8 rows. + "vmovq (%[src]),%%xmm0 \n" + "vpinsrd $2,8(%[src]),%%xmm0,%%xmm0 \n" + "vmovq (%[src],%[s]),%%xmm1 \n" + "vpinsrd $2,8(%[src],%[s]),%%xmm1,%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovq (%[temp]),%%xmm2 \n" + "vpinsrd $2,8(%[temp]),%%xmm2,%%xmm2 \n" + "vmovq (%[temp],%[s]),%%xmm3 \n" + "vpinsrd $2,8(%[temp],%[s]),%%xmm3,%%xmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovq (%[temp]),%%xmm4 \n" + "vpinsrd $2,8(%[temp]),%%xmm4,%%xmm4 \n" + "vinserti128 $1,%%xmm4,%%ymm0,%%ymm0 \n" + "vmovq (%[temp],%[s]),%%xmm5 \n" + "vpinsrd $2,8(%[temp],%[s]),%%xmm5,%%xmm5 \n" + "vinserti128 $1,%%xmm5,%%ymm1,%%ymm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovq (%[temp]),%%xmm4 \n" + "vpinsrd $2,8(%[temp]),%%xmm4,%%xmm4 \n" + "vinserti128 $1,%%xmm4,%%ymm2,%%ymm2 \n" + "vmovq (%[temp],%[s]),%%xmm5 \n" + "vpinsrd $2,8(%[temp],%[s]),%%xmm5,%%xmm5 \n" + "vinserti128 $1,%%xmm5,%%ymm3,%%ymm3 \n" + "jmp 3f \n" + + // rem_w == 2: load 8 bytes per row from 8 rows. + "2: \n" + "vmovq (%[src]),%%xmm0 \n" + "vmovq (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovq (%[temp]),%%xmm2 \n" + "vmovq (%[temp],%[s]),%%xmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovq (%[temp]),%%xmm4 \n" + "vinserti128 $1,%%xmm4,%%ymm0,%%ymm0 \n" + "vmovq (%[temp],%[s]),%%xmm5 \n" + "vinserti128 $1,%%xmm5,%%ymm1,%%ymm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovq (%[temp]),%%xmm4 \n" + "vinserti128 $1,%%xmm4,%%ymm2,%%ymm2 \n" + "vmovq (%[temp],%[s]),%%xmm5 \n" + "vinserti128 $1,%%xmm5,%%ymm3,%%ymm3 \n" + "jmp 3f \n" + + // rem_w == 1: load 4 bytes per row from 8 rows. + "1: \n" + "vmovd (%[src]),%%xmm0 \n" + "vmovd (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovd (%[temp]),%%xmm2 \n" + "vmovd (%[temp],%[s]),%%xmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovd (%[temp]),%%xmm4 \n" + "vinserti128 $1,%%xmm4,%%ymm0,%%ymm0 \n" + "vmovd (%[temp],%[s]),%%xmm5 \n" + "vinserti128 $1,%%xmm5,%%ymm1,%%ymm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovd (%[temp]),%%xmm4 \n" + "vinserti128 $1,%%xmm4,%%ymm2,%%ymm2 \n" + "vmovd (%[temp],%[s]),%%xmm5 \n" + "vinserti128 $1,%%xmm5,%%ymm3,%%ymm3 \n" + + "3: \n" + "vpunpckldq %%ymm1,%%ymm0,%%ymm4 \n" + "vpunpckldq %%ymm3,%%ymm2,%%ymm5 \n" + "vpunpcklqdq %%ymm5,%%ymm4,%%ymm6 \n" + "vmovdqu %%ymm6,(%[dst]) \n" + "cmpl $1,%[rem_w] \n" + "jle 4f \n" + "vpunpckhqdq %%ymm5,%%ymm4,%%ymm7 \n" + "vmovdqu %%ymm7,(%[dst],%[d]) \n" + "cmpl $2,%[rem_w] \n" + "jle 4f \n" + "vpunpckhdq %%ymm1,%%ymm0,%%ymm4 \n" + "vpunpckhdq %%ymm3,%%ymm2,%%ymm5 \n" + "vpunpcklqdq %%ymm5,%%ymm4,%%ymm6 \n" + "vmovdqu %%ymm6,(%[dst],%[d],2) \n" + "4: \n" + "vzeroupper \n" + : [temp] "=&r"(temp) + : [src] "r"(src), + [s] "r"(s), + [dst] "r"(dst), + [d] "r"(d), + [rem_w] "rm"(rem_w) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} + +// Transpose rem_w (1..3) columns x 4 rows of 32-bit pixels using VEX 128-bit. +static void TransposeRemWx4_32_AVX2(const uint8_t* src, + ptrdiff_t s, + uint8_t* dst, + ptrdiff_t d, + int rem_w) { + const uint8_t* temp; + asm volatile( + "cmpl $2,%[rem_w] \n" + "jl 1f \n" + "je 2f \n" + + // rem_w == 3: load 12 bytes per row from 4 rows. + "vmovq (%[src]),%%xmm0 \n" + "vpinsrd $2,8(%[src]),%%xmm0,%%xmm0 \n" + "vmovq (%[src],%[s]),%%xmm1 \n" + "vpinsrd $2,8(%[src],%[s]),%%xmm1,%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovq (%[temp]),%%xmm2 \n" + "vpinsrd $2,8(%[temp]),%%xmm2,%%xmm2 \n" + "vmovq (%[temp],%[s]),%%xmm3 \n" + "vpinsrd $2,8(%[temp],%[s]),%%xmm3,%%xmm3 \n" + "jmp 3f \n" + + // rem_w == 2: load 8 bytes per row from 4 rows. + "2: \n" + "vmovq (%[src]),%%xmm0 \n" + "vmovq (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovq (%[temp]),%%xmm2 \n" + "vmovq (%[temp],%[s]),%%xmm3 \n" + "jmp 3f \n" + + // rem_w == 1: load 4 bytes per row from 4 rows. + "1: \n" + "vmovd (%[src]),%%xmm0 \n" + "vmovd (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovd (%[temp]),%%xmm2 \n" + "vmovd (%[temp],%[s]),%%xmm3 \n" + + "3: \n" + "vpunpckldq %%xmm1,%%xmm0,%%xmm4 \n" + "vpunpckldq %%xmm3,%%xmm2,%%xmm5 \n" + "vpunpcklqdq %%xmm5,%%xmm4,%%xmm6 \n" + "vmovdqu %%xmm6,(%[dst]) \n" + "cmpl $1,%[rem_w] \n" + "jle 4f \n" + "vpunpckhqdq %%xmm5,%%xmm4,%%xmm7 \n" + "vmovdqu %%xmm7,(%[dst],%[d]) \n" + "cmpl $2,%[rem_w] \n" + "jle 4f \n" + "vpunpckhdq %%xmm1,%%xmm0,%%xmm4 \n" + "vpunpckhdq %%xmm3,%%xmm2,%%xmm5 \n" + "vpunpcklqdq %%xmm5,%%xmm4,%%xmm6 \n" + "vmovdqu %%xmm6,(%[dst],%[d],2) \n" + "4: \n" + : [temp] "=&r"(temp) + : [src] "r"(src), + [s] "r"(s), + [dst] "r"(dst), + [d] "r"(d), + [rem_w] "rm"(rem_w) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} + +// Transpose arbitrary WxH 32-bit plane using AVX2 (4x8, 8x4, 4x4, and 4x{1..3} +// tiles plus exact remainder handling). +void TransposeWxH_32_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + const int w4 = width & ~3; + const int rem_w = width & 3; + + // Tier 1: 8-row strips using 4x8 YMM tiles + rem_w x 8 YMM tail. + while (height >= 8) { + if (w4 > 0) { + TransposeWx8_32_AVX2(src, src_stride, dst, dst_stride, w4); + } + if (rem_w > 0) { + TransposeRemWx8_32_AVX2(src + (ptrdiff_t)w4 * 4, s, + dst + (ptrdiff_t)w4 * d, d, rem_w); + } + src += 8 * s; + dst += 32; + height -= 8; + } + + // Tier 2: 4-row strip using 8x4 YMM tiles + 4x4 XMM block + rem_w x 4 tail. + if (height >= 4) { + const int w8 = width & ~7; + if (w8 > 0) { + const uint8_t* src_p = src; + uint8_t* dst_p = dst; + int cnt = w8; + const uint8_t* temp; + asm volatile( + "1: \n" + "vmovdqu (%[src]),%%ymm0 \n" + "vmovdqu (%[src],%[s]),%%ymm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%ymm2 \n" + "vmovdqu (%[temp],%[s]),%%ymm3 \n" + "add $0x20,%[src] \n" + + "vpunpckldq %%ymm1,%%ymm0,%%ymm4 \n" + "vpunpckldq %%ymm3,%%ymm2,%%ymm5 \n" + "vpunpckhdq %%ymm1,%%ymm0,%%ymm6 \n" + "vpunpckhdq %%ymm3,%%ymm2,%%ymm7 \n" + + "vpunpcklqdq %%ymm5,%%ymm4,%%ymm0 \n" + "vpunpckhqdq %%ymm5,%%ymm4,%%ymm1 \n" + "vpunpcklqdq %%ymm7,%%ymm6,%%ymm2 \n" + "vpunpckhqdq %%ymm7,%%ymm6,%%ymm3 \n" + + "vmovdqu %%xmm0,(%[dst]) \n" + "vmovdqu %%xmm1,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu %%xmm2,(%[dst]) \n" + "vmovdqu %%xmm3,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vextracti128 $1,%%ymm0,(%[dst]) \n" + "vextracti128 $1,%%ymm1,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vextracti128 $1,%%ymm2,(%[dst]) \n" + "vextracti128 $1,%%ymm3,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "subl $0x8,%[cnt] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src_p), + [dst] "+r"(dst_p), + [cnt] "+rm"(cnt), + [temp] "=&r"(temp) + : [s] "r"(s), + [d] "r"(d) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); + } + if (width & 4) { + const uint8_t* src_p = src + (ptrdiff_t)w8 * 4; + uint8_t* dst_p = dst + (ptrdiff_t)w8 * d; + uintptr_t temp; + asm volatile( + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm2 \n" + "vmovdqu (%[temp],%[s]),%%xmm3 \n" + + "vpunpckldq %%xmm1,%%xmm0,%%xmm4 \n" + "vpunpckldq %%xmm3,%%xmm2,%%xmm5 \n" + "vpunpckhdq %%xmm1,%%xmm0,%%xmm6 \n" + "vpunpckhdq %%xmm3,%%xmm2,%%xmm7 \n" + + "vpunpcklqdq %%xmm5,%%xmm4,%%xmm0 \n" + "vpunpckhqdq %%xmm5,%%xmm4,%%xmm1 \n" + "vpunpcklqdq %%xmm7,%%xmm6,%%xmm2 \n" + "vpunpckhqdq %%xmm7,%%xmm6,%%xmm3 \n" + + "vmovdqu %%xmm0,(%[dst]) \n" + "vmovdqu %%xmm1,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[temp] \n" + "vmovdqu %%xmm2,(%[temp]) \n" + "vmovdqu %%xmm3,(%[temp],%[d]) \n" + : [temp] "=&r"(temp) + : [src] "r"(src_p), + [dst] "r"(dst_p), + [s] "r"(s), + [d] "r"(d) + : "memory", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); + } + if (rem_w > 0) { + TransposeRemWx4_32_AVX2(src + (ptrdiff_t)w4 * 4, s, + dst + (ptrdiff_t)w4 * d, d, rem_w); + } + src += 4 * s; + dst += 16; + height -= 4; + } + + // Tier 3: 1..3 remaining source rows using 4 x height XMM tiles + corner. + if (height > 0) { + if (w4 > 0) { + const uint8_t* src_p = src; + uint8_t* dst_p = dst; + int cnt = w4; + if (height == 1) { + asm volatile( + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "add $0x10,%[src] \n" + "vmovd %%xmm0,(%[dst]) \n" + "vpextrd $1,%%xmm0,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vpextrd $2,%%xmm0,(%[dst]) \n" + "vpextrd $3,%%xmm0,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "sub $0x4,%[cnt] \n" + "jg 1b \n" + : [src] "+r"(src_p), + [dst] "+r"(dst_p), + [cnt] "+r"(cnt) + : [d] "r"(d) + : "memory", "cc", "xmm0"); + } else if (height == 2) { + asm volatile( + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[s]),%%xmm1 \n" + "add $0x10,%[src] \n" + "vpunpckldq %%xmm1,%%xmm0,%%xmm2 \n" + "vpunpckhdq %%xmm1,%%xmm0,%%xmm3 \n" + "vmovq %%xmm2,(%[dst]) \n" + "vmovhpd %%xmm2,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovq %%xmm3,(%[dst]) \n" + "vmovhpd %%xmm3,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "sub $0x4,%[cnt] \n" + "jg 1b \n" + : [src] "+r"(src_p), + [dst] "+r"(dst_p), + [cnt] "+r"(cnt) + : [s] "r"(s), + [d] "r"(d) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); + } else { + asm volatile( + "vpxor %%xmm3,%%xmm3,%%xmm3 \n" + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[s]),%%xmm1 \n" + "vmovdqu (%[src],%[s],2),%%xmm2 \n" + "add $0x10,%[src] \n" + "vpunpckldq %%xmm1,%%xmm0,%%xmm4 \n" + "vpunpckldq %%xmm3,%%xmm2,%%xmm5 \n" + "vpunpckhdq %%xmm1,%%xmm0,%%xmm6 \n" + "vpunpckhdq %%xmm3,%%xmm2,%%xmm7 \n" + "vpunpcklqdq %%xmm5,%%xmm4,%%xmm0 \n" + "vpunpckhqdq %%xmm5,%%xmm4,%%xmm1 \n" + "vpunpcklqdq %%xmm7,%%xmm6,%%xmm2 \n" + "vmovq %%xmm0,(%[dst]) \n" + "vpextrd $2,%%xmm0,8(%[dst]) \n" + "vmovq %%xmm1,(%[dst],%[d]) \n" + "vpextrd $2,%%xmm1,8(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovq %%xmm2,(%[dst]) \n" + "vpextrd $2,%%xmm2,8(%[dst]) \n" + "vpunpckhqdq %%xmm7,%%xmm6,%%xmm4 \n" + "vmovq %%xmm4,(%[dst],%[d]) \n" + "vpextrd $2,%%xmm4,8(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "sub $0x4,%[cnt] \n" + "jg 1b \n" + : [src] "+r"(src_p), + [dst] "+r"(dst_p), + [cnt] "+r"(cnt) + : [s] "r"(s), + [d] "r"(d) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); + } + } + for (int x = w4; x < width; ++x) { + uint8_t* dst_row = dst + (ptrdiff_t)x * d; + for (int y = 0; y < height; ++y) { + memcpy(dst_row + y * 4, src + (ptrdiff_t)y * s + x * 4, 4); + } + } + } +} +#endif // defined(HAS_TRANSPOSEWXH_32_AVX2) + +#if defined(HAS_TRANSPOSEWX16_32_AVX512BW) +// Transpose 16 rows of 32 bit plane (arbitrary width) using 4x16 ZMM vertical +// tiles in zmm0..zmm7 with k1-masked right tail. +LIBYUV_TARGET_AVX512BW +void TransposeWx16_32_AVX512BW(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + const int n = width & ~3; + if (n > 0) { + int cnt = n; + const uint8_t* temp; + asm volatile( + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vmovdqu (%[src],%[s]),%%xmm1 \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovdqu (%[temp]),%%xmm2 \n" + "vmovdqu (%[temp],%[s]),%%xmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vinserti32x4 $1,(%[temp]),%%zmm0,%%zmm0 \n" + "vinserti32x4 $1,(%[temp],%[s]),%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $1,(%[temp]),%%zmm2,%%zmm2 \n" + "vinserti32x4 $1,(%[temp],%[s]),%%zmm3,%%zmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vinserti32x4 $2,(%[temp]),%%zmm0,%%zmm0 \n" + "vinserti32x4 $2,(%[temp],%[s]),%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $2,(%[temp]),%%zmm2,%%zmm2 \n" + "vinserti32x4 $2,(%[temp],%[s]),%%zmm3,%%zmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vinserti32x4 $3,(%[temp]),%%zmm0,%%zmm0 \n" + "vinserti32x4 $3,(%[temp],%[s]),%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vinserti32x4 $3,(%[temp]),%%zmm2,%%zmm2 \n" + "vinserti32x4 $3,(%[temp],%[s]),%%zmm3,%%zmm3 \n" + "add $0x10,%[src] \n" + + // Stage 1: 32-bit unpack across all 4 128-bit lanes + "vpunpckldq %%zmm1,%%zmm0,%%zmm4 \n" + "vpunpckldq %%zmm3,%%zmm2,%%zmm5 \n" + "vpunpckhdq %%zmm1,%%zmm0,%%zmm6 \n" + "vpunpckhdq %%zmm3,%%zmm2,%%zmm7 \n" + + // Stage 2: 64-bit unpack across all 4 128-bit lanes + "vpunpcklqdq %%zmm5,%%zmm4,%%zmm0 \n" + "vpunpckhqdq %%zmm5,%%zmm4,%%zmm1 \n" + "vpunpcklqdq %%zmm7,%%zmm6,%%zmm2 \n" + "vpunpckhqdq %%zmm7,%%zmm6,%%zmm3 \n" + + // Store 4 full 512-bit (64 B) rows = 16 32-bit pixels each + "vmovdqu32 %%zmm0,(%[dst]) \n" + "vmovdqu32 %%zmm1,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu32 %%zmm2,(%[dst]) \n" + "vmovdqu32 %%zmm3,(%[dst],%[d]) \n" + "lea (%[dst],%[d],2),%[dst] \n" + "sub $0x4,%[cnt] \n" + "jg 1b \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [cnt] "+r"(cnt), // %[cnt] + [temp] "=&r"(temp) // %[temp] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); + width -= n; + } + if (width > 0) { + const uint32_t col_mask = (1u << width) - 1; + const uint8_t* temp; + asm volatile( + "kmovw %[col_mask],%%k1 \n" + "vmovdqu32 (%[src]),%%xmm0%{%%k1%}%{z%} \n" + "vmovdqu32 (%[src],%[s]),%%xmm1%{%%k1%}%{z%} \n" + "lea (%[src],%[s],2),%[temp] \n" + "vmovdqu32 (%[temp]),%%xmm2%{%%k1%}%{z%} \n" + "vmovdqu32 (%[temp],%[s]),%%xmm3%{%%k1%}%{z%} \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vmovdqu32 (%[temp]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm8,%%zmm0,%%zmm0 \n" + "vmovdqu32 (%[temp],%[s]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm8,%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu32 (%[temp]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm8,%%zmm2,%%zmm2 \n" + "vmovdqu32 (%[temp],%[s]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $1,%%xmm8,%%zmm3,%%zmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vmovdqu32 (%[temp]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm8,%%zmm0,%%zmm0 \n" + "vmovdqu32 (%[temp],%[s]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm8,%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu32 (%[temp]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm8,%%zmm2,%%zmm2 \n" + "vmovdqu32 (%[temp],%[s]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $2,%%xmm8,%%zmm3,%%zmm3 \n" + "lea (%[temp],%[s],2),%[temp] \n" + + "vmovdqu32 (%[temp]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm8,%%zmm0,%%zmm0 \n" + "vmovdqu32 (%[temp],%[s]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm8,%%zmm1,%%zmm1 \n" + "lea (%[temp],%[s],2),%[temp] \n" + "vmovdqu32 (%[temp]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm8,%%zmm2,%%zmm2 \n" + "vmovdqu32 (%[temp],%[s]),%%xmm8%{%%k1%}%{z%} \n" + "vinserti32x4 $3,%%xmm8,%%zmm3,%%zmm3 \n" + + "vpunpckldq %%zmm1,%%zmm0,%%zmm4 \n" + "vpunpckldq %%zmm3,%%zmm2,%%zmm5 \n" + "vpunpckhdq %%zmm1,%%zmm0,%%zmm6 \n" + "vpunpckhdq %%zmm3,%%zmm2,%%zmm7 \n" + + "vpunpcklqdq %%zmm5,%%zmm4,%%zmm0 \n" + "vpunpckhqdq %%zmm5,%%zmm4,%%zmm1 \n" + "vpunpcklqdq %%zmm7,%%zmm6,%%zmm2 \n" + "vpunpckhqdq %%zmm7,%%zmm6,%%zmm3 \n" + + "vmovdqu32 %%zmm0,(%[dst]) \n" + "cmp $1,%[width] \n" + "jle 2f \n" + "vmovdqu32 %%zmm1,(%[dst],%[d]) \n" + "cmp $2,%[width] \n" + "jle 2f \n" + "lea (%[dst],%[d],2),%[dst] \n" + "vmovdqu32 %%zmm2,(%[dst]) \n" + "2: \n" + : [dst] "+r"(dst), // %[dst] + [temp] "=&r"(temp) // %[temp] + : [src] "r"(src), // %[src] + [s] "r"(s), // %[s] + [d] "r"(d), // %[d] + [col_mask] "r"(col_mask), // %[col_mask] + [width] "r"(width) // %[width] + : "memory", "cc", "k1", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7", "xmm8"); + } + asm volatile("vzeroupper \n"); +} +#endif // defined(HAS_TRANSPOSEWX16_32_AVX512BW) + +#endif // !defined(LIBYUV_DISABLE_X86) && (defined(__x86_64__) || + // defined(__i386__)) && !defined(LIBYUV_ENABLE_ROWWIN) #ifdef __cplusplus } // extern "C" diff --git a/libs/libyuv/source/rotate_hvx.cc b/libs/libyuv/source/rotate_hvx.cc new file mode 100644 index 0000000000..b3a0606f91 --- /dev/null +++ b/libs/libyuv/source/rotate_hvx.cc @@ -0,0 +1,388 @@ +/* + * Copyright 2026 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/rotate_row.h" +#include "libyuv/row.h" + +#if !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) +#include +#include +#include +#include + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +static inline HVX_Vector LoadAligned_HVX(const void* ptr) { + HVX_Vector v; + memcpy(&v, (const HVX_Vector*)ptr, sizeof(v)); + return v; +} + +static inline HVX_Vector LoadU_HVX(const void* ptr) { + HVX_UVector v; + memcpy(&v, ptr, sizeof(v)); + return v; +} + +static inline void StoreU_HVX(void* ptr, HVX_Vector v) { + memcpy(ptr, &v, sizeof(HVX_UVector)); +} + +static inline HVX_Vector LoadPartial_HVX(const void* ptr, int n_bytes) { + if (n_bytes >= 128) { + return LoadU_HVX(ptr); + } + const uint8_t* p = (const uint8_t*)ptr; + const uintptr_t addr = (uintptr_t)p; + const uintptr_t offset = addr & 127u; + HVX_Vector v0 = LoadAligned_HVX(p); + HVX_Vector v1 = + (offset + (uintptr_t)n_bytes > 128u) ? LoadAligned_HVX(p + 128) : v0; + return Q6_V_valign_VVR(v1, v0, addr); +} + +static inline void StorePartial_HVX(void* ptr, HVX_Vector v, int n_bytes) { + if (n_bytes >= 128) { + StoreU_HVX(ptr, v); + return; + } + uint8_t* p = (uint8_t*)ptr; + const uintptr_t addr = (uintptr_t)p; + const uintptr_t offset = addr & 127u; + HVX_Vector value = Q6_V_vlalign_VVR(v, v, addr); + HVX_VectorPred ql_not = Q6_Q_vsetq_R(addr); + HVX_VectorPred qr = Q6_Q_vsetq2_R(offset + (uintptr_t)n_bytes); + if (offset + (uintptr_t)n_bytes > 128u) { + Q6_vmem_QRIV(qr, p + 128, value); + qr = Q6_Q_vcmp_eq_VbVb(value, value); + } + ql_not = Q6_Q_or_QQn(ql_not, qr); + Q6_vmem_QnRIV(ql_not, p, value); +} + +static inline void Interleave4_HVX(HVX_Vector* x0, + HVX_Vector* x1, + HVX_Vector* x2, + HVX_Vector* x3, + int stride) { + HVX_VectorPair p01 = Q6_W_vshuff_VVR(*x1, *x0, -stride); + HVX_VectorPair p23 = Q6_W_vshuff_VVR(*x3, *x2, -stride); + HVX_VectorPair q01 = + Q6_W_vshuff_VVR(Q6_V_lo_W(p23), Q6_V_lo_W(p01), -2 * stride); + HVX_VectorPair q23 = + Q6_W_vshuff_VVR(Q6_V_hi_W(p23), Q6_V_hi_W(p01), -2 * stride); + *x0 = Q6_V_lo_W(q01); + *x1 = Q6_V_hi_W(q01); + *x2 = Q6_V_lo_W(q23); + *x3 = Q6_V_hi_W(q23); +} + +static inline void Interleave32_HVX(HVX_Vector* x, + HVX_Vector* out, + int stride) { + int g, q, j; + for (g = 0; g < 32; g += 4) { + Interleave4_HVX(&x[g], &x[g + 1], &x[g + 2], &x[g + 3], stride); + } + for (q = 0; q < 4; ++q) { + Interleave4_HVX(&x[q], &x[4 + q], &x[8 + q], &x[12 + q], 4 * stride); + Interleave4_HVX(&x[16 + q], &x[20 + q], &x[24 + q], &x[28 + q], 4 * stride); + for (j = 0; j < 4; ++j) { + HVX_VectorPair p = + Q6_W_vshuff_VVR(x[16 + 4 * j + q], x[4 * j + q], -16 * stride); + out[8 * q + 2 * j] = Q6_V_lo_W(p); + out[8 * q + 2 * j + 1] = Q6_V_hi_W(p); + } + } +} + +#if defined(HAS_TRANSPOSEWXH_HVX) || defined(HAS_TRANSPOSEUVWXH_HVX) +static void TransposeWxH_Byte_HVX(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int byte_width, + int height) { + const ptrdiff_t s_stride = src_stride; + const ptrdiff_t da_stride = dst_stride_a; + const ptrdiff_t db_stride = dst_stride_b; + HVX_Vector buf[4][32]; + HVX_Vector v[32]; + const HVX_Vector vzero = Q6_V_vzero(); + + do { + const int block_h = height > 128 ? 128 : height; + const uint8_t* src2 = src; + uint8_t* dst2_a = dst_a; + uint8_t* dst2_b = dst_b; + int bw = byte_width; + + do { + const int block_w = bw > 128 ? 128 : bw; + int s, r, k; + for (s = 0; s < 4; ++s) { + if (s * 32 < block_h) { + int strip_h = block_h - s * 32; + const uint8_t* src_row = src2 + (ptrdiff_t)(s * 32) * s_stride; + if (strip_h > 32) { + strip_h = 32; + } + if (block_w == 128) { + for (r = 0; r < strip_h; ++r) { + v[r] = LoadU_HVX(src_row); + src_row += s_stride; + } + } else { + for (r = 0; r < strip_h; ++r) { + v[r] = LoadPartial_HVX(src_row, block_w); + src_row += s_stride; + } + } + for (; r < 32; ++r) { + v[r] = vzero; + } + Interleave32_HVX(v, buf[s], 1); + } + } + + if (block_h == 128) { + for (k = 0; k < 32 && k * 4 < block_w; ++k) { + HVX_Vector b0 = buf[0][k]; + HVX_Vector b1 = buf[1][k]; + HVX_Vector b2 = buf[2][k]; + HVX_Vector b3 = buf[3][k]; + Interleave4_HVX(&b0, &b1, &b2, &b3, 32); + StoreU_HVX(dst2_a, b0); + if (k * 4 + 1 < block_w) { + StoreU_HVX(dst2_b, b1); + } + if (k * 4 + 2 < block_w) { + StoreU_HVX(dst2_a + da_stride, b2); + } + if (k * 4 + 3 < block_w) { + StoreU_HVX(dst2_b + db_stride, b3); + } + dst2_a += 2 * da_stride; + dst2_b += 2 * db_stride; + } + } else { + for (k = 0; k < 32 && k * 4 < block_w; ++k) { + HVX_Vector b0 = buf[0][k]; + HVX_Vector b1 = (block_h > 32) ? buf[1][k] : vzero; + HVX_Vector b2 = (block_h > 64) ? buf[2][k] : vzero; + HVX_Vector b3 = (block_h > 96) ? buf[3][k] : vzero; + Interleave4_HVX(&b0, &b1, &b2, &b3, 32); + StorePartial_HVX(dst2_a, b0, block_h); + if (k * 4 + 1 < block_w) { + StorePartial_HVX(dst2_b, b1, block_h); + } + if (k * 4 + 2 < block_w) { + StorePartial_HVX(dst2_a + da_stride, b2, block_h); + } + if (k * 4 + 3 < block_w) { + StorePartial_HVX(dst2_b + db_stride, b3, block_h); + } + dst2_a += 2 * da_stride; + dst2_b += 2 * db_stride; + } + } + + src2 += 128; + bw -= 128; + } while (bw > 0); + + src += 128 * s_stride; + dst_a += 128; + dst_b += 128; + height -= 128; + } while (height > 0); +} +#endif // defined(HAS_TRANSPOSEWXH_HVX) || defined(HAS_TRANSPOSEUVWXH_HVX) + +#ifdef HAS_TRANSPOSEWXH_HVX +void TransposeWxH_HVX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height) { + TransposeWxH_Byte_HVX(src, src_stride, dst, dst_stride * 2, + dst + (width > 1 ? dst_stride : 0), dst_stride * 2, + width, height); +} +#endif // HAS_TRANSPOSEWXH_HVX + +#ifdef HAS_TRANSPOSEUVWXH_HVX +void TransposeUVWxH_HVX(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height) { + TransposeWxH_Byte_HVX(src, src_stride, dst_a, dst_stride_a, dst_b, + dst_stride_b, width * 2, height); +} +#endif // HAS_TRANSPOSEUVWXH_HVX + +#ifdef HAS_TRANSPOSEWXH_16_HVX +void TransposeWxH_16_HVX(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height) { + const ptrdiff_t s_stride = src_stride; + const ptrdiff_t d_stride = dst_stride; + HVX_Vector buf[2][32]; + HVX_Vector v[32]; + const HVX_Vector vzero = Q6_V_vzero(); + + do { + const int block_h = height > 64 ? 64 : height; + const uint16_t* src2 = src; + uint16_t* dst2 = dst; + int w = width; + + do { + const int block_w = w > 64 ? 64 : w; + int s, r, k; + for (s = 0; s < 2; ++s) { + if (s * 32 < block_h) { + int strip_h = block_h - s * 32; + const uint16_t* src_row = src2 + (ptrdiff_t)(s * 32) * s_stride; + if (strip_h > 32) { + strip_h = 32; + } + if (block_w == 64) { + for (r = 0; r < strip_h; ++r) { + v[r] = LoadU_HVX(src_row); + src_row += s_stride; + } + } else { + for (r = 0; r < strip_h; ++r) { + v[r] = LoadPartial_HVX(src_row, block_w * 2); + src_row += s_stride; + } + } + for (; r < 32; ++r) { + v[r] = vzero; + } + Interleave32_HVX(v, buf[s], 2); + } + } + + if (block_h == 64) { + for (k = 0; k < 32 && k * 2 < block_w; ++k) { + HVX_VectorPair c01 = Q6_W_vshuff_VVR(buf[1][k], buf[0][k], -64); + StoreU_HVX(dst2, Q6_V_lo_W(c01)); + if (k * 2 + 1 < block_w) { + StoreU_HVX(dst2 + d_stride, Q6_V_hi_W(c01)); + } + dst2 += 2 * d_stride; + } + } else { + for (k = 0; k < 32 && k * 2 < block_w; ++k) { + HVX_Vector b0 = buf[0][k]; + HVX_Vector b1 = (block_h > 32) ? buf[1][k] : vzero; + HVX_VectorPair c01 = Q6_W_vshuff_VVR(b1, b0, -64); + StorePartial_HVX(dst2, Q6_V_lo_W(c01), block_h * 2); + if (k * 2 + 1 < block_w) { + StorePartial_HVX(dst2 + d_stride, Q6_V_hi_W(c01), block_h * 2); + } + dst2 += 2 * d_stride; + } + } + + src2 += 64; + w -= 64; + } while (w > 0); + + src += 64 * s_stride; + dst += 64; + height -= 64; + } while (height > 0); +} +#endif // HAS_TRANSPOSEWXH_16_HVX + +#ifdef HAS_TRANSPOSEWXH_32_HVX +void TransposeWxH_32_HVX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height) { + const ptrdiff_t s_stride = src_stride; + const ptrdiff_t d_stride = dst_stride; + HVX_Vector v[32]; + HVX_Vector out[32]; + const HVX_Vector vzero = Q6_V_vzero(); + + do { + const int block_h = height > 32 ? 32 : height; + const uint8_t* src2 = src; + uint8_t* dst2 = dst; + int w = width; + + do { + const int block_w = w > 32 ? 32 : w; + const uint8_t* src_row = src2; + int r, c; + if (block_w == 32) { + for (r = 0; r < block_h; ++r) { + v[r] = LoadU_HVX(src_row); + src_row += s_stride; + } + } else { + for (r = 0; r < block_h; ++r) { + v[r] = LoadPartial_HVX(src_row, block_w * 4); + src_row += s_stride; + } + } + for (; r < 32; ++r) { + v[r] = vzero; + } + Interleave32_HVX(v, out, 4); + + if (block_h == 32) { + for (c = 0; c < block_w; ++c) { + StoreU_HVX(dst2, out[c]); + dst2 += d_stride; + } + } else { + for (c = 0; c < block_w; ++c) { + StorePartial_HVX(dst2, out[c], block_h * 4); + dst2 += d_stride; + } + } + + src2 += 128; + w -= 32; + } while (w > 0); + + src += 32 * s_stride; + dst += 128; + height -= 32; + } while (height > 0); +} +#endif // HAS_TRANSPOSEWXH_32_HVX + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) diff --git a/libs/libyuv/source/rotate_lasx.cc b/libs/libyuv/source/rotate_lasx.cc new file mode 100644 index 0000000000..8a50cbe2a0 --- /dev/null +++ b/libs/libyuv/source/rotate_lasx.cc @@ -0,0 +1,506 @@ +/* + * Copyright 2026 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/rotate_row.h" + +#if !defined(LIBYUV_DISABLE_LASX) && defined(__loongarch_asx) + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +void TransposeWx16_LASX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + const uint8_t* t; + asm volatile( + "srli.w %[w], %[w], 4 \n" + "beqz %[w], 2f \n" + "1: \n" + "move %[t], %[src] \n" + "vld $vr0, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr1, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr2, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr3, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr4, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr5, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr6, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr7, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr8, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr9, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr10, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr11, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr12, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr13, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr14, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr15, %[t], 0 \n" + "addi.d %[src], %[src], 16 \n" + + "xvpermi.q $xr0, $xr8, 0x02 \n" + "xvpermi.q $xr1, $xr9, 0x02 \n" + "xvpermi.q $xr2, $xr10, 0x02 \n" + "xvpermi.q $xr3, $xr11, 0x02 \n" + "xvpermi.q $xr4, $xr12, 0x02 \n" + "xvpermi.q $xr5, $xr13, 0x02 \n" + "xvpermi.q $xr6, $xr14, 0x02 \n" + "xvpermi.q $xr7, $xr15, 0x02 \n" + + "xvilvl.b $xr8, $xr1, $xr0 \n" + "xvilvh.b $xr9, $xr1, $xr0 \n" + "xvilvl.b $xr10, $xr3, $xr2 \n" + "xvilvh.b $xr11, $xr3, $xr2 \n" + "xvilvl.b $xr12, $xr5, $xr4 \n" + "xvilvh.b $xr13, $xr5, $xr4 \n" + "xvilvl.b $xr14, $xr7, $xr6 \n" + "xvilvh.b $xr15, $xr7, $xr6 \n" + + "xvilvl.h $xr0, $xr10, $xr8 \n" + "xvilvh.h $xr1, $xr10, $xr8 \n" + "xvilvl.h $xr2, $xr11, $xr9 \n" + "xvilvh.h $xr3, $xr11, $xr9 \n" + "xvilvl.h $xr4, $xr14, $xr12 \n" + "xvilvh.h $xr5, $xr14, $xr12 \n" + "xvilvl.h $xr6, $xr15, $xr13 \n" + "xvilvh.h $xr7, $xr15, $xr13 \n" + + "xvilvl.w $xr8, $xr4, $xr0 \n" + "xvilvh.w $xr9, $xr4, $xr0 \n" + "xvilvl.w $xr10, $xr5, $xr1 \n" + "xvilvh.w $xr11, $xr5, $xr1 \n" + "xvilvl.w $xr12, $xr6, $xr2 \n" + "xvilvh.w $xr13, $xr6, $xr2 \n" + "xvilvl.w $xr14, $xr7, $xr3 \n" + "xvilvh.w $xr15, $xr7, $xr3 \n" + + "xvpermi.d $xr0, $xr8, 0x08 \n" + "xvpermi.d $xr1, $xr8, 0x0d \n" + "xvpermi.d $xr2, $xr9, 0x08 \n" + "xvpermi.d $xr3, $xr9, 0x0d \n" + "xvpermi.d $xr4, $xr10, 0x08 \n" + "xvpermi.d $xr5, $xr10, 0x0d \n" + "xvpermi.d $xr6, $xr11, 0x08 \n" + "xvpermi.d $xr7, $xr11, 0x0d \n" + "xvpermi.d $xr8, $xr12, 0x08 \n" + "xvpermi.d $xr9, $xr12, 0x0d \n" + "xvpermi.d $xr10, $xr13, 0x08 \n" + "xvpermi.d $xr11, $xr13, 0x0d \n" + "xvpermi.d $xr12, $xr14, 0x08 \n" + "xvpermi.d $xr13, $xr14, 0x0d \n" + "xvpermi.d $xr14, $xr15, 0x08 \n" + "xvpermi.d $xr15, $xr15, 0x0d \n" + + "vst $vr0, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr1, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr2, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr3, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr4, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr5, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr6, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr7, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr8, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr9, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr10, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr11, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr12, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr13, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr14, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr15, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [w] "+r"(width), // %[w] + [t] "=&r"(t) // %[t] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr12", "$xr13", "$xr14", + "$xr15"); +} + +void TransposeUVWx16_LASX(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t da = dst_stride_a; + const ptrdiff_t db = dst_stride_b; + const uint8_t* t; + asm volatile( + "srli.w %[w], %[w], 3 \n" + "beqz %[w], 2f \n" + "1: \n" + "move %[t], %[src] \n" + "vld $vr0, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr1, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr2, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr3, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr4, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr5, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr6, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr7, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr8, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr9, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr10, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr11, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr12, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr13, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr14, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr15, %[t], 0 \n" + "addi.d %[src], %[src], 16 \n" + + "xvpermi.q $xr0, $xr8, 0x02 \n" + "xvpermi.q $xr1, $xr9, 0x02 \n" + "xvpermi.q $xr2, $xr10, 0x02 \n" + "xvpermi.q $xr3, $xr11, 0x02 \n" + "xvpermi.q $xr4, $xr12, 0x02 \n" + "xvpermi.q $xr5, $xr13, 0x02 \n" + "xvpermi.q $xr6, $xr14, 0x02 \n" + "xvpermi.q $xr7, $xr15, 0x02 \n" + + "xvilvl.b $xr8, $xr1, $xr0 \n" + "xvilvh.b $xr9, $xr1, $xr0 \n" + "xvilvl.b $xr10, $xr3, $xr2 \n" + "xvilvh.b $xr11, $xr3, $xr2 \n" + "xvilvl.b $xr12, $xr5, $xr4 \n" + "xvilvh.b $xr13, $xr5, $xr4 \n" + "xvilvl.b $xr14, $xr7, $xr6 \n" + "xvilvh.b $xr15, $xr7, $xr6 \n" + + "xvilvl.h $xr0, $xr10, $xr8 \n" + "xvilvh.h $xr1, $xr10, $xr8 \n" + "xvilvl.h $xr2, $xr11, $xr9 \n" + "xvilvh.h $xr3, $xr11, $xr9 \n" + "xvilvl.h $xr4, $xr14, $xr12 \n" + "xvilvh.h $xr5, $xr14, $xr12 \n" + "xvilvl.h $xr6, $xr15, $xr13 \n" + "xvilvh.h $xr7, $xr15, $xr13 \n" + + "xvilvl.w $xr8, $xr4, $xr0 \n" + "xvilvh.w $xr9, $xr4, $xr0 \n" + "xvilvl.w $xr10, $xr5, $xr1 \n" + "xvilvh.w $xr11, $xr5, $xr1 \n" + "xvilvl.w $xr12, $xr6, $xr2 \n" + "xvilvh.w $xr13, $xr6, $xr2 \n" + "xvilvl.w $xr14, $xr7, $xr3 \n" + "xvilvh.w $xr15, $xr7, $xr3 \n" + + "xvpermi.d $xr0, $xr8, 0x08 \n" + "xvpermi.d $xr1, $xr8, 0x0d \n" + "xvpermi.d $xr2, $xr9, 0x08 \n" + "xvpermi.d $xr3, $xr9, 0x0d \n" + "xvpermi.d $xr4, $xr10, 0x08 \n" + "xvpermi.d $xr5, $xr10, 0x0d \n" + "xvpermi.d $xr6, $xr11, 0x08 \n" + "xvpermi.d $xr7, $xr11, 0x0d \n" + "xvpermi.d $xr8, $xr12, 0x08 \n" + "xvpermi.d $xr9, $xr12, 0x0d \n" + "xvpermi.d $xr10, $xr13, 0x08 \n" + "xvpermi.d $xr11, $xr13, 0x0d \n" + "xvpermi.d $xr12, $xr14, 0x08 \n" + "xvpermi.d $xr13, $xr14, 0x0d \n" + "xvpermi.d $xr14, $xr15, 0x08 \n" + "xvpermi.d $xr15, $xr15, 0x0d \n" + + "vst $vr0, %[dst_a], 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vst $vr1, %[dst_b], 0 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vst $vr2, %[dst_a], 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vst $vr3, %[dst_b], 0 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vst $vr4, %[dst_a], 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vst $vr5, %[dst_b], 0 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vst $vr6, %[dst_a], 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vst $vr7, %[dst_b], 0 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vst $vr8, %[dst_a], 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vst $vr9, %[dst_b], 0 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vst $vr10, %[dst_a], 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vst $vr11, %[dst_b], 0 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vst $vr12, %[dst_a], 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vst $vr13, %[dst_b], 0 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vst $vr14, %[dst_a], 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vst $vr15, %[dst_b], 0 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src), // %[src] + [dst_a] "+r"(dst_a), // %[dst_a] + [dst_b] "+r"(dst_b), // %[dst_b] + [w] "+r"(width), // %[w] + [t] "=&r"(t) // %[t] + : [s] "r"(s), // %[s] + [da] "r"(da), // %[da] + [db] "r"(db) // %[db] + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr12", "$xr13", "$xr14", + "$xr15"); +} + +void TransposeWx4_32_LASX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + ptrdiff_t s = src_stride; + ptrdiff_t s2 = s * 2; + ptrdiff_t s3 = s + s2; + ptrdiff_t s4 = s * 4; + uint8_t* dst0 = dst; + uint8_t* dst1 = dst0 + dst_stride; + uint8_t* dst2 = dst1 + dst_stride; + uint8_t* dst3 = dst2 + dst_stride; + const uint8_t* src4; + + asm volatile( + "srli.w %[w], %[w], 3 \n" + "beqz %[w], 2f \n" + "1: \n" + "vld $vr0, %[src], 0 \n" + "vldx $vr1, %[src], %[s] \n" + "vldx $vr2, %[src], %[s2] \n" + "vldx $vr3, %[src], %[s3] \n" + "add.d %[src4], %[src], %[s4] \n" + "vld $vr4, %[src4], 0 \n" + "vldx $vr5, %[src4], %[s] \n" + "vldx $vr6, %[src4], %[s2] \n" + "vldx $vr7, %[src4], %[s3] \n" + "add.d %[src], %[src4], %[s4] \n" + + "xvpermi.q $xr0, $xr4, 0x02 \n" + "xvpermi.q $xr1, $xr5, 0x02 \n" + "xvpermi.q $xr2, $xr6, 0x02 \n" + "xvpermi.q $xr3, $xr7, 0x02 \n" + + "xvilvl.w $xr4, $xr1, $xr0 \n" + "xvilvh.w $xr5, $xr1, $xr0 \n" + "xvilvl.w $xr6, $xr3, $xr2 \n" + "xvilvh.w $xr7, $xr3, $xr2 \n" + + "xvilvl.d $xr0, $xr6, $xr4 \n" + "xvilvh.d $xr1, $xr6, $xr4 \n" + "xvilvl.d $xr2, $xr7, $xr5 \n" + "xvilvh.d $xr3, $xr7, $xr5 \n" + + "xvst $xr0, %[dst0], 0 \n" + "xvst $xr1, %[dst1], 0 \n" + "xvst $xr2, %[dst2], 0 \n" + "xvst $xr3, %[dst3], 0 \n" + "addi.d %[dst0], %[dst0], 32 \n" + "addi.d %[dst1], %[dst1], 32 \n" + "addi.d %[dst2], %[dst2], 32 \n" + "addi.d %[dst3], %[dst3], 32 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src), // %[src] + [src4] "=&r"(src4), // %[src4] + [dst0] "+r"(dst0), // %[dst0] + [dst1] "+r"(dst1), // %[dst1] + [dst2] "+r"(dst2), // %[dst2] + [dst3] "+r"(dst3), // %[dst3] + [w] "+r"(width) // %[w] + : [s] "r"(s), // %[s] + [s2] "r"(s2), // %[s2] + [s3] "r"(s3), // %[s3] + [s4] "r"(s4) // %[s4] + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7"); +} + +void TransposeWx16_16_LASX(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = (ptrdiff_t)src_stride * 2; + const ptrdiff_t d = (ptrdiff_t)dst_stride * 2; + const uint8_t* src_b = (const uint8_t*)src; + uint8_t* dst_b = (uint8_t*)dst; + const uint8_t* t; + asm volatile( + "srli.w %[w], %[w], 3 \n" + "beqz %[w], 2f \n" + "1: \n" + "move %[t], %[src] \n" + "vld $vr0, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr1, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr2, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr3, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr4, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr5, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr6, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr7, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + + "vld $vr8, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr9, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr10, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr11, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr12, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr13, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr14, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr15, %[t], 0 \n" + "addi.d %[src], %[src], 16 \n" + + "xvpermi.q $xr0, $xr8, 0x02 \n" + "xvpermi.q $xr1, $xr9, 0x02 \n" + "xvpermi.q $xr2, $xr10, 0x02 \n" + "xvpermi.q $xr3, $xr11, 0x02 \n" + "xvpermi.q $xr4, $xr12, 0x02 \n" + "xvpermi.q $xr5, $xr13, 0x02 \n" + "xvpermi.q $xr6, $xr14, 0x02 \n" + "xvpermi.q $xr7, $xr15, 0x02 \n" + + "xvilvl.h $xr8, $xr1, $xr0 \n" + "xvilvh.h $xr9, $xr1, $xr0 \n" + "xvilvl.h $xr10, $xr3, $xr2 \n" + "xvilvh.h $xr11, $xr3, $xr2 \n" + "xvilvl.h $xr12, $xr5, $xr4 \n" + "xvilvh.h $xr13, $xr5, $xr4 \n" + "xvilvl.h $xr14, $xr7, $xr6 \n" + "xvilvh.h $xr15, $xr7, $xr6 \n" + + "xvilvl.w $xr0, $xr10, $xr8 \n" + "xvilvh.w $xr1, $xr10, $xr8 \n" + "xvilvl.w $xr2, $xr11, $xr9 \n" + "xvilvh.w $xr3, $xr11, $xr9 \n" + "xvilvl.w $xr4, $xr14, $xr12 \n" + "xvilvh.w $xr5, $xr14, $xr12 \n" + "xvilvl.w $xr6, $xr15, $xr13 \n" + "xvilvh.w $xr7, $xr15, $xr13 \n" + + "xvilvl.d $xr8, $xr4, $xr0 \n" + "xvilvh.d $xr9, $xr4, $xr0 \n" + "xvilvl.d $xr10, $xr5, $xr1 \n" + "xvilvh.d $xr11, $xr5, $xr1 \n" + "xvilvl.d $xr12, $xr6, $xr2 \n" + "xvilvh.d $xr13, $xr6, $xr2 \n" + "xvilvl.d $xr14, $xr7, $xr3 \n" + "xvilvh.d $xr15, $xr7, $xr3 \n" + + "xvst $xr8, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "xvst $xr9, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "xvst $xr10, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "xvst $xr11, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "xvst $xr12, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "xvst $xr13, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "xvst $xr14, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "xvst $xr15, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src_b), // %[src] + [dst] "+r"(dst_b), // %[dst] + [w] "+r"(width), // %[w] + [t] "=&r"(t) // %[t] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr12", "$xr13", "$xr14", + "$xr15"); +} + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_LASX) && defined(__loongarch_asx) diff --git a/libs/libyuv/source/rotate_lsx.cc b/libs/libyuv/source/rotate_lsx.cc new file mode 100644 index 0000000000..531145bf18 --- /dev/null +++ b/libs/libyuv/source/rotate_lsx.cc @@ -0,0 +1,383 @@ +/* + * Copyright 2022 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/rotate_row.h" + +#if !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx) + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +void TransposeWx8_LSX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + const uint8_t* t; + asm volatile( + "srli.w %[w], %[w], 4 \n" + "beqz %[w], 2f \n" + "1: \n" + "move %[t], %[src] \n" + "vld $vr0, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr1, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr2, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr3, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr4, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr5, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr6, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr7, %[t], 0 \n" + "addi.d %[src], %[src], 16 \n" + + "vilvl.b $vr8, $vr1, $vr0 \n" + "vilvh.b $vr9, $vr1, $vr0 \n" + "vilvl.b $vr10, $vr3, $vr2 \n" + "vilvh.b $vr11, $vr3, $vr2 \n" + "vilvl.b $vr12, $vr5, $vr4 \n" + "vilvh.b $vr13, $vr5, $vr4 \n" + "vilvl.b $vr14, $vr7, $vr6 \n" + "vilvh.b $vr15, $vr7, $vr6 \n" + + "vilvl.h $vr0, $vr10, $vr8 \n" + "vilvh.h $vr1, $vr10, $vr8 \n" + "vilvl.h $vr2, $vr11, $vr9 \n" + "vilvh.h $vr3, $vr11, $vr9 \n" + "vilvl.h $vr4, $vr14, $vr12 \n" + "vilvh.h $vr5, $vr14, $vr12 \n" + "vilvl.h $vr6, $vr15, $vr13 \n" + "vilvh.h $vr7, $vr15, $vr13 \n" + + "vilvl.w $vr8, $vr4, $vr0 \n" + "vilvh.w $vr9, $vr4, $vr0 \n" + "vilvl.w $vr10, $vr5, $vr1 \n" + "vilvh.w $vr11, $vr5, $vr1 \n" + "vilvl.w $vr12, $vr6, $vr2 \n" + "vilvh.w $vr13, $vr6, $vr2 \n" + "vilvl.w $vr14, $vr7, $vr3 \n" + "vilvh.w $vr15, $vr7, $vr3 \n" + + "vstelm.d $vr8, %[dst], 0, 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr8, %[dst], 0, 1 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr9, %[dst], 0, 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr9, %[dst], 0, 1 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr10, %[dst], 0, 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr10, %[dst], 0, 1 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr11, %[dst], 0, 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr11, %[dst], 0, 1 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr12, %[dst], 0, 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr12, %[dst], 0, 1 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr13, %[dst], 0, 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr13, %[dst], 0, 1 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr14, %[dst], 0, 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr14, %[dst], 0, 1 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr15, %[dst], 0, 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vstelm.d $vr15, %[dst], 0, 1 \n" + "add.d %[dst], %[dst], %[d] \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [w] "+r"(width), // %[w] + [t] "=&r"(t) // %[t] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr12", "$vr13", "$vr14", + "$vr15"); +} + +void TransposeUVWx8_LSX(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t da = dst_stride_a; + const ptrdiff_t db = dst_stride_b; + const uint8_t* t; + asm volatile( + "srli.w %[w], %[w], 3 \n" + "beqz %[w], 2f \n" + "1: \n" + "move %[t], %[src] \n" + "vld $vr0, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr1, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr2, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr3, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr4, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr5, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr6, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr7, %[t], 0 \n" + "addi.d %[src], %[src], 16 \n" + + "vilvl.b $vr8, $vr1, $vr0 \n" + "vilvh.b $vr9, $vr1, $vr0 \n" + "vilvl.b $vr10, $vr3, $vr2 \n" + "vilvh.b $vr11, $vr3, $vr2 \n" + "vilvl.b $vr12, $vr5, $vr4 \n" + "vilvh.b $vr13, $vr5, $vr4 \n" + "vilvl.b $vr14, $vr7, $vr6 \n" + "vilvh.b $vr15, $vr7, $vr6 \n" + + "vilvl.h $vr0, $vr10, $vr8 \n" + "vilvh.h $vr1, $vr10, $vr8 \n" + "vilvl.h $vr2, $vr11, $vr9 \n" + "vilvh.h $vr3, $vr11, $vr9 \n" + "vilvl.h $vr4, $vr14, $vr12 \n" + "vilvh.h $vr5, $vr14, $vr12 \n" + "vilvl.h $vr6, $vr15, $vr13 \n" + "vilvh.h $vr7, $vr15, $vr13 \n" + + "vilvl.w $vr8, $vr4, $vr0 \n" + "vilvh.w $vr9, $vr4, $vr0 \n" + "vilvl.w $vr10, $vr5, $vr1 \n" + "vilvh.w $vr11, $vr5, $vr1 \n" + "vilvl.w $vr12, $vr6, $vr2 \n" + "vilvh.w $vr13, $vr6, $vr2 \n" + "vilvl.w $vr14, $vr7, $vr3 \n" + "vilvh.w $vr15, $vr7, $vr3 \n" + + "vstelm.d $vr8, %[dst_a], 0, 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vstelm.d $vr8, %[dst_b], 0, 1 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vstelm.d $vr9, %[dst_a], 0, 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vstelm.d $vr9, %[dst_b], 0, 1 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vstelm.d $vr10, %[dst_a], 0, 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vstelm.d $vr10, %[dst_b], 0, 1 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vstelm.d $vr11, %[dst_a], 0, 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vstelm.d $vr11, %[dst_b], 0, 1 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vstelm.d $vr12, %[dst_a], 0, 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vstelm.d $vr12, %[dst_b], 0, 1 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vstelm.d $vr13, %[dst_a], 0, 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vstelm.d $vr13, %[dst_b], 0, 1 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vstelm.d $vr14, %[dst_a], 0, 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vstelm.d $vr14, %[dst_b], 0, 1 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "vstelm.d $vr15, %[dst_a], 0, 0 \n" + "add.d %[dst_a], %[dst_a], %[da] \n" + "vstelm.d $vr15, %[dst_b], 0, 1 \n" + "add.d %[dst_b], %[dst_b], %[db] \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src), // %[src] + [dst_a] "+r"(dst_a), // %[dst_a] + [dst_b] "+r"(dst_b), // %[dst_b] + [w] "+r"(width), // %[w] + [t] "=&r"(t) // %[t] + : [s] "r"(s), // %[s] + [da] "r"(da), // %[da] + [db] "r"(db) // %[db] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr12", "$vr13", "$vr14", + "$vr15"); +} + +void TransposeWx4_32_LSX(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t s2 = s * 2; + const ptrdiff_t s3 = s + s2; + const ptrdiff_t s4 = s * 4; + uint8_t* dst0 = dst; + uint8_t* dst1 = dst0 + dst_stride; + uint8_t* dst2 = dst1 + dst_stride; + uint8_t* dst3 = dst2 + dst_stride; + asm volatile( + "srli.w %[w], %[w], 2 \n" + "beqz %[w], 2f \n" + "1: \n" + "vld $vr0, %[src], 0 \n" + "vldx $vr1, %[src], %[s] \n" + "vldx $vr2, %[src], %[s2] \n" + "vldx $vr3, %[src], %[s3] \n" + "add.d %[src], %[src], %[s4] \n" + + "vilvl.w $vr4, $vr1, $vr0 \n" + "vilvh.w $vr5, $vr1, $vr0 \n" + "vilvl.w $vr6, $vr3, $vr2 \n" + "vilvh.w $vr7, $vr3, $vr2 \n" + + "vilvl.d $vr0, $vr6, $vr4 \n" + "vilvh.d $vr1, $vr6, $vr4 \n" + "vilvl.d $vr2, $vr7, $vr5 \n" + "vilvh.d $vr3, $vr7, $vr5 \n" + + "vst $vr0, %[dst0], 0 \n" + "vst $vr1, %[dst1], 0 \n" + "vst $vr2, %[dst2], 0 \n" + "vst $vr3, %[dst3], 0 \n" + "addi.d %[dst0], %[dst0], 16 \n" + "addi.d %[dst1], %[dst1], 16 \n" + "addi.d %[dst2], %[dst2], 16 \n" + "addi.d %[dst3], %[dst3], 16 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src), // %[src] + [dst0] "+r"(dst0), // %[dst0] + [dst1] "+r"(dst1), // %[dst1] + [dst2] "+r"(dst2), // %[dst2] + [dst3] "+r"(dst3), // %[dst3] + [w] "+r"(width) // %[w] + : [s] "r"(s), // %[s] + [s2] "r"(s2), // %[s2] + [s3] "r"(s3), // %[s3] + [s4] "r"(s4) // %[s4] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7"); +} + +void TransposeWx8_16_LSX(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = (ptrdiff_t)src_stride * 2; + const ptrdiff_t d = (ptrdiff_t)dst_stride * 2; + const uint8_t* src_b = (const uint8_t*)src; + uint8_t* dst_b = (uint8_t*)dst; + const uint8_t* t; + asm volatile( + "srli.w %[w], %[w], 3 \n" + "beqz %[w], 2f \n" + "1: \n" + "move %[t], %[src] \n" + "vld $vr0, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr1, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr2, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr3, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr4, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr5, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr6, %[t], 0 \n" + "add.d %[t], %[t], %[s] \n" + "vld $vr7, %[t], 0 \n" + "addi.d %[src], %[src], 16 \n" + + "vilvl.h $vr8, $vr1, $vr0 \n" + "vilvh.h $vr9, $vr1, $vr0 \n" + "vilvl.h $vr10, $vr3, $vr2 \n" + "vilvh.h $vr11, $vr3, $vr2 \n" + "vilvl.h $vr12, $vr5, $vr4 \n" + "vilvh.h $vr13, $vr5, $vr4 \n" + "vilvl.h $vr14, $vr7, $vr6 \n" + "vilvh.h $vr15, $vr7, $vr6 \n" + + "vilvl.w $vr0, $vr10, $vr8 \n" + "vilvh.w $vr1, $vr10, $vr8 \n" + "vilvl.w $vr2, $vr11, $vr9 \n" + "vilvh.w $vr3, $vr11, $vr9 \n" + "vilvl.w $vr4, $vr14, $vr12 \n" + "vilvh.w $vr5, $vr14, $vr12 \n" + "vilvl.w $vr6, $vr15, $vr13 \n" + "vilvh.w $vr7, $vr15, $vr13 \n" + + "vilvl.d $vr8, $vr4, $vr0 \n" + "vilvh.d $vr9, $vr4, $vr0 \n" + "vilvl.d $vr10, $vr5, $vr1 \n" + "vilvh.d $vr11, $vr5, $vr1 \n" + "vilvl.d $vr12, $vr6, $vr2 \n" + "vilvh.d $vr13, $vr6, $vr2 \n" + "vilvl.d $vr14, $vr7, $vr3 \n" + "vilvh.d $vr15, $vr7, $vr3 \n" + + "vst $vr8, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr9, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr10, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr11, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr12, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr13, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr14, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "vst $vr15, %[dst], 0 \n" + "add.d %[dst], %[dst], %[d] \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src_b), // %[src] + [dst] "+r"(dst_b), // %[dst] + [w] "+r"(width), // %[w] + [t] "=&r"(t) // %[t] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr12", "$vr13", "$vr14", + "$vr15"); +} + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx) diff --git a/libs/libyuv/source/rotate_mmi.cc b/libs/libyuv/source/rotate_mmi.cc deleted file mode 100644 index f8de60834d..0000000000 --- a/libs/libyuv/source/rotate_mmi.cc +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright 2011 The LibYuv Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "libyuv/rotate_row.h" -#include "libyuv/row.h" - -#ifdef __cplusplus -namespace libyuv { -extern "C" { -#endif - -// This module is for Mips MMI. -#if !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) - -void TransposeWx8_MMI(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width) { - uint64_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6; - uint64_t tmp7, tmp8, tmp9, tmp10, tmp11, tmp12, tmp13; - uint8_t* src_tmp = nullptr; - - __asm__ volatile( - "1: \n\t" - "ldc1 %[tmp12], 0x00(%[src]) \n\t" - "dadd %[src_tmp], %[src], %[src_stride] \n\t" - "ldc1 %[tmp13], 0x00(%[src_tmp]) \n\t" - - /* tmp0 = (00 10 01 11 02 12 03 13) */ - "punpcklbh %[tmp0], %[tmp12], %[tmp13] \n\t" - /* tmp1 = (04 14 05 15 06 16 07 17) */ - "punpckhbh %[tmp1], %[tmp12], %[tmp13] \n\t" - - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - "ldc1 %[tmp12], 0x00(%[src_tmp]) \n\t" - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - "ldc1 %[tmp13], 0x00(%[src_tmp]) \n\t" - - /* tmp2 = (20 30 21 31 22 32 23 33) */ - "punpcklbh %[tmp2], %[tmp12], %[tmp13] \n\t" - /* tmp3 = (24 34 25 35 26 36 27 37) */ - "punpckhbh %[tmp3], %[tmp12], %[tmp13] \n\t" - - /* tmp4 = (00 10 20 30 01 11 21 31) */ - "punpcklhw %[tmp4], %[tmp0], %[tmp2] \n\t" - /* tmp5 = (02 12 22 32 03 13 23 33) */ - "punpckhhw %[tmp5], %[tmp0], %[tmp2] \n\t" - /* tmp6 = (04 14 24 34 05 15 25 35) */ - "punpcklhw %[tmp6], %[tmp1], %[tmp3] \n\t" - /* tmp7 = (06 16 26 36 07 17 27 37) */ - "punpckhhw %[tmp7], %[tmp1], %[tmp3] \n\t" - - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - "ldc1 %[tmp12], 0x00(%[src_tmp]) \n\t" - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - "ldc1 %[tmp13], 0x00(%[src_tmp]) \n\t" - - /* tmp0 = (40 50 41 51 42 52 43 53) */ - "punpcklbh %[tmp0], %[tmp12], %[tmp13] \n\t" - /* tmp1 = (44 54 45 55 46 56 47 57) */ - "punpckhbh %[tmp1], %[tmp12], %[tmp13] \n\t" - - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - "ldc1 %[tmp12], 0x00(%[src_tmp]) \n\t" - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - "ldc1 %[tmp13], 0x00(%[src_tmp]) \n\t" - - /* tmp2 = (60 70 61 71 62 72 63 73) */ - "punpcklbh %[tmp2], %[tmp12], %[tmp13] \n\t" - /* tmp3 = (64 74 65 75 66 76 67 77) */ - "punpckhbh %[tmp3], %[tmp12], %[tmp13] \n\t" - - /* tmp8 = (40 50 60 70 41 51 61 71) */ - "punpcklhw %[tmp8], %[tmp0], %[tmp2] \n\t" - /* tmp9 = (42 52 62 72 43 53 63 73) */ - "punpckhhw %[tmp9], %[tmp0], %[tmp2] \n\t" - /* tmp10 = (44 54 64 74 45 55 65 75) */ - "punpcklhw %[tmp10], %[tmp1], %[tmp3] \n\t" - /* tmp11 = (46 56 66 76 47 57 67 77) */ - "punpckhhw %[tmp11], %[tmp1], %[tmp3] \n\t" - - /* tmp0 = (00 10 20 30 40 50 60 70) */ - "punpcklwd %[tmp0], %[tmp4], %[tmp8] \n\t" - /* tmp1 = (01 11 21 31 41 51 61 71) */ - "punpckhwd %[tmp1], %[tmp4], %[tmp8] \n\t" - "gssdlc1 %[tmp0], 0x07(%[dst]) \n\t" - "gssdrc1 %[tmp0], 0x00(%[dst]) \n\t" - "dadd %[dst], %[dst], %[dst_stride] \n\t" - "gssdlc1 %[tmp1], 0x07(%[dst]) \n\t" - "gssdrc1 %[tmp1], 0x00(%[dst]) \n\t" - - /* tmp0 = (02 12 22 32 42 52 62 72) */ - "punpcklwd %[tmp0], %[tmp5], %[tmp9] \n\t" - /* tmp1 = (03 13 23 33 43 53 63 73) */ - "punpckhwd %[tmp1], %[tmp5], %[tmp9] \n\t" - "dadd %[dst], %[dst], %[dst_stride] \n\t" - "gssdlc1 %[tmp0], 0x07(%[dst]) \n\t" - "gssdrc1 %[tmp0], 0x00(%[dst]) \n\t" - "dadd %[dst], %[dst], %[dst_stride] \n\t" - "gssdlc1 %[tmp1], 0x07(%[dst]) \n\t" - "gssdrc1 %[tmp1], 0x00(%[dst]) \n\t" - - /* tmp0 = (04 14 24 34 44 54 64 74) */ - "punpcklwd %[tmp0], %[tmp6], %[tmp10] \n\t" - /* tmp1 = (05 15 25 35 45 55 65 75) */ - "punpckhwd %[tmp1], %[tmp6], %[tmp10] \n\t" - "dadd %[dst], %[dst], %[dst_stride] \n\t" - "gssdlc1 %[tmp0], 0x07(%[dst]) \n\t" - "gssdrc1 %[tmp0], 0x00(%[dst]) \n\t" - "dadd %[dst], %[dst], %[dst_stride] \n\t" - "gssdlc1 %[tmp1], 0x07(%[dst]) \n\t" - "gssdrc1 %[tmp1], 0x00(%[dst]) \n\t" - - /* tmp0 = (06 16 26 36 46 56 66 76) */ - "punpcklwd %[tmp0], %[tmp7], %[tmp11] \n\t" - /* tmp1 = (07 17 27 37 47 57 67 77) */ - "punpckhwd %[tmp1], %[tmp7], %[tmp11] \n\t" - "dadd %[dst], %[dst], %[dst_stride] \n\t" - "gssdlc1 %[tmp0], 0x07(%[dst]) \n\t" - "gssdrc1 %[tmp0], 0x00(%[dst]) \n\t" - "dadd %[dst], %[dst], %[dst_stride] \n\t" - "gssdlc1 %[tmp1], 0x07(%[dst]) \n\t" - "gssdrc1 %[tmp1], 0x00(%[dst]) \n\t" - - "dadd %[dst], %[dst], %[dst_stride] \n\t" - "daddi %[src], %[src], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - - : [tmp0] "=&f"(tmp0), [tmp1] "=&f"(tmp1), [tmp2] "=&f"(tmp2), - [tmp3] "=&f"(tmp3), [tmp4] "=&f"(tmp4), [tmp5] "=&f"(tmp5), - [tmp6] "=&f"(tmp6), [tmp7] "=&f"(tmp7), [tmp8] "=&f"(tmp8), - [tmp9] "=&f"(tmp9), [tmp10] "=&f"(tmp10), [tmp11] "=&f"(tmp11), - [tmp12] "=&f"(tmp12), [tmp13] "=&f"(tmp13), [dst] "+&r"(dst), - [src_tmp] "+&r"(src_tmp) - : [src] "r"(src), [width] "r"(width), [src_stride] "r"(src_stride), - [dst_stride] "r"(dst_stride) - : "memory"); -} - -void TransposeUVWx8_MMI(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width) { - uint64_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6; - uint64_t tmp7, tmp8, tmp9, tmp10, tmp11, tmp12, tmp13; - uint8_t* src_tmp = nullptr; - - __asm__ volatile( - "1: \n\t" - /* tmp12 = (u00 v00 u01 v01 u02 v02 u03 v03) */ - "ldc1 %[tmp12], 0x00(%[src]) \n\t" - "dadd %[src_tmp], %[src], %[src_stride] \n\t" - /* tmp13 = (u10 v10 u11 v11 u12 v12 u13 v13) */ - "ldc1 %[tmp13], 0x00(%[src_tmp]) \n\t" - - /* tmp0 = (u00 u10 v00 v10 u01 u11 v01 v11) */ - "punpcklbh %[tmp0], %[tmp12], %[tmp13] \n\t" - /* tmp1 = (u02 u12 v02 v12 u03 u13 v03 v13) */ - "punpckhbh %[tmp1], %[tmp12], %[tmp13] \n\t" - - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - /* tmp12 = (u20 v20 u21 v21 u22 v22 u23 v23) */ - "ldc1 %[tmp12], 0x00(%[src_tmp]) \n\t" - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - /* tmp13 = (u30 v30 u31 v31 u32 v32 u33 v33) */ - "ldc1 %[tmp13], 0x00(%[src_tmp]) \n\t" - - /* tmp2 = (u20 u30 v20 v30 u21 u31 v21 v31) */ - "punpcklbh %[tmp2], %[tmp12], %[tmp13] \n\t" - /* tmp3 = (u22 u32 v22 v32 u23 u33 v23 v33) */ - "punpckhbh %[tmp3], %[tmp12], %[tmp13] \n\t" - - /* tmp4 = (u00 u10 u20 u30 v00 v10 v20 v30) */ - "punpcklhw %[tmp4], %[tmp0], %[tmp2] \n\t" - /* tmp5 = (u01 u11 u21 u31 v01 v11 v21 v31) */ - "punpckhhw %[tmp5], %[tmp0], %[tmp2] \n\t" - /* tmp6 = (u02 u12 u22 u32 v02 v12 v22 v32) */ - "punpcklhw %[tmp6], %[tmp1], %[tmp3] \n\t" - /* tmp7 = (u03 u13 u23 u33 v03 v13 v23 v33) */ - "punpckhhw %[tmp7], %[tmp1], %[tmp3] \n\t" - - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - /* tmp12 = (u40 v40 u41 v41 u42 v42 u43 v43) */ - "ldc1 %[tmp12], 0x00(%[src_tmp]) \n\t" - /* tmp13 = (u50 v50 u51 v51 u52 v52 u53 v53) */ - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - "ldc1 %[tmp13], 0x00(%[src_tmp]) \n\t" - - /* tmp0 = (u40 u50 v40 v50 u41 u51 v41 v51) */ - "punpcklbh %[tmp0], %[tmp12], %[tmp13] \n\t" - /* tmp1 = (u42 u52 v42 v52 u43 u53 v43 v53) */ - "punpckhbh %[tmp1], %[tmp12], %[tmp13] \n\t" - - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - /* tmp12 = (u60 v60 u61 v61 u62 v62 u63 v63) */ - "ldc1 %[tmp12], 0x00(%[src_tmp]) \n\t" - /* tmp13 = (u70 v70 u71 v71 u72 v72 u73 v73) */ - "dadd %[src_tmp], %[src_tmp], %[src_stride] \n\t" - "ldc1 %[tmp13], 0x00(%[src_tmp]) \n\t" - - /* tmp2 = (u60 u70 v60 v70 u61 u71 v61 v71) */ - "punpcklbh %[tmp2], %[tmp12], %[tmp13] \n\t" - /* tmp3 = (u62 u72 v62 v72 u63 u73 v63 v73) */ - "punpckhbh %[tmp3], %[tmp12], %[tmp13] \n\t" - - /* tmp8 = (u40 u50 u60 u70 v40 v50 v60 v70) */ - "punpcklhw %[tmp8], %[tmp0], %[tmp2] \n\t" - /* tmp9 = (u41 u51 u61 u71 v41 v51 v61 v71) */ - "punpckhhw %[tmp9], %[tmp0], %[tmp2] \n\t" - /* tmp10 = (u42 u52 u62 u72 v42 v52 v62 v72) */ - "punpcklhw %[tmp10], %[tmp1], %[tmp3] \n\t" - /* tmp11 = (u43 u53 u63 u73 v43 v53 v63 v73) */ - "punpckhhw %[tmp11], %[tmp1], %[tmp3] \n\t" - - /* tmp0 = (u00 u10 u20 u30 u40 u50 u60 u70) */ - "punpcklwd %[tmp0], %[tmp4], %[tmp8] \n\t" - /* tmp1 = (v00 v10 v20 v30 v40 v50 v60 v70) */ - "punpckhwd %[tmp1], %[tmp4], %[tmp8] \n\t" - "gssdlc1 %[tmp0], 0x07(%[dst_a]) \n\t" - "gssdrc1 %[tmp0], 0x00(%[dst_a]) \n\t" - "gssdlc1 %[tmp1], 0x07(%[dst_b]) \n\t" - "gssdrc1 %[tmp1], 0x00(%[dst_b]) \n\t" - - /* tmp0 = (u01 u11 u21 u31 u41 u51 u61 u71) */ - "punpcklwd %[tmp0], %[tmp5], %[tmp9] \n\t" - /* tmp1 = (v01 v11 v21 v31 v41 v51 v61 v71) */ - "punpckhwd %[tmp1], %[tmp5], %[tmp9] \n\t" - "dadd %[dst_a], %[dst_a], %[dst_stride_a] \n\t" - "gssdlc1 %[tmp0], 0x07(%[dst_a]) \n\t" - "gssdrc1 %[tmp0], 0x00(%[dst_a]) \n\t" - "dadd %[dst_b], %[dst_b], %[dst_stride_b] \n\t" - "gssdlc1 %[tmp1], 0x07(%[dst_b]) \n\t" - "gssdrc1 %[tmp1], 0x00(%[dst_b]) \n\t" - - /* tmp0 = (u02 u12 u22 u32 u42 u52 u62 u72) */ - "punpcklwd %[tmp0], %[tmp6], %[tmp10] \n\t" - /* tmp1 = (v02 v12 v22 v32 v42 v52 v62 v72) */ - "punpckhwd %[tmp1], %[tmp6], %[tmp10] \n\t" - "dadd %[dst_a], %[dst_a], %[dst_stride_a] \n\t" - "gssdlc1 %[tmp0], 0x07(%[dst_a]) \n\t" - "gssdrc1 %[tmp0], 0x00(%[dst_a]) \n\t" - "dadd %[dst_b], %[dst_b], %[dst_stride_b] \n\t" - "gssdlc1 %[tmp1], 0x07(%[dst_b]) \n\t" - "gssdrc1 %[tmp1], 0x00(%[dst_b]) \n\t" - - /* tmp0 = (u03 u13 u23 u33 u43 u53 u63 u73) */ - "punpcklwd %[tmp0], %[tmp7], %[tmp11] \n\t" - /* tmp1 = (v03 v13 v23 v33 v43 v53 v63 v73) */ - "punpckhwd %[tmp1], %[tmp7], %[tmp11] \n\t" - "dadd %[dst_a], %[dst_a], %[dst_stride_a] \n\t" - "gssdlc1 %[tmp0], 0x07(%[dst_a]) \n\t" - "gssdrc1 %[tmp0], 0x00(%[dst_a]) \n\t" - "dadd %[dst_b], %[dst_b], %[dst_stride_b] \n\t" - "gssdlc1 %[tmp1], 0x07(%[dst_b]) \n\t" - "gssdrc1 %[tmp1], 0x00(%[dst_b]) \n\t" - - "dadd %[dst_a], %[dst_a], %[dst_stride_a] \n\t" - "dadd %[dst_b], %[dst_b], %[dst_stride_b] \n\t" - "daddiu %[src], %[src], 0x08 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - - : [tmp0] "=&f"(tmp0), [tmp1] "=&f"(tmp1), [tmp2] "=&f"(tmp2), - [tmp3] "=&f"(tmp3), [tmp4] "=&f"(tmp4), [tmp5] "=&f"(tmp5), - [tmp6] "=&f"(tmp6), [tmp7] "=&f"(tmp7), [tmp8] "=&f"(tmp8), - [tmp9] "=&f"(tmp9), [tmp10] "=&f"(tmp10), [tmp11] "=&f"(tmp11), - [tmp12] "=&f"(tmp12), [tmp13] "=&f"(tmp13), [dst_a] "+&r"(dst_a), - [dst_b] "+&r"(dst_b), [src_tmp] "+&r"(src_tmp) - : [src] "r"(src), [width] "r"(width), [dst_stride_a] "r"(dst_stride_a), - [dst_stride_b] "r"(dst_stride_b), [src_stride] "r"(src_stride) - : "memory"); -} - -#endif // !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) - -#ifdef __cplusplus -} // extern "C" -} // namespace libyuv -#endif diff --git a/libs/libyuv/source/rotate_msa.cc b/libs/libyuv/source/rotate_msa.cc deleted file mode 100644 index 99bdca65b3..0000000000 --- a/libs/libyuv/source/rotate_msa.cc +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright 2016 The LibYuv Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "libyuv/rotate_row.h" - -// This module is for GCC MSA -#if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) -#include "libyuv/macros_msa.h" - -#ifdef __cplusplus -namespace libyuv { -extern "C" { -#endif - -#define ILVRL_B(in0, in1, in2, in3, out0, out1, out2, out3) \ - { \ - out0 = (v16u8)__msa_ilvr_b((v16i8)in1, (v16i8)in0); \ - out1 = (v16u8)__msa_ilvl_b((v16i8)in1, (v16i8)in0); \ - out2 = (v16u8)__msa_ilvr_b((v16i8)in3, (v16i8)in2); \ - out3 = (v16u8)__msa_ilvl_b((v16i8)in3, (v16i8)in2); \ - } - -#define ILVRL_H(in0, in1, in2, in3, out0, out1, out2, out3) \ - { \ - out0 = (v16u8)__msa_ilvr_h((v8i16)in1, (v8i16)in0); \ - out1 = (v16u8)__msa_ilvl_h((v8i16)in1, (v8i16)in0); \ - out2 = (v16u8)__msa_ilvr_h((v8i16)in3, (v8i16)in2); \ - out3 = (v16u8)__msa_ilvl_h((v8i16)in3, (v8i16)in2); \ - } - -#define ILVRL_W(in0, in1, in2, in3, out0, out1, out2, out3) \ - { \ - out0 = (v16u8)__msa_ilvr_w((v4i32)in1, (v4i32)in0); \ - out1 = (v16u8)__msa_ilvl_w((v4i32)in1, (v4i32)in0); \ - out2 = (v16u8)__msa_ilvr_w((v4i32)in3, (v4i32)in2); \ - out3 = (v16u8)__msa_ilvl_w((v4i32)in3, (v4i32)in2); \ - } - -#define ILVRL_D(in0, in1, in2, in3, out0, out1, out2, out3) \ - { \ - out0 = (v16u8)__msa_ilvr_d((v2i64)in1, (v2i64)in0); \ - out1 = (v16u8)__msa_ilvl_d((v2i64)in1, (v2i64)in0); \ - out2 = (v16u8)__msa_ilvr_d((v2i64)in3, (v2i64)in2); \ - out3 = (v16u8)__msa_ilvl_d((v2i64)in3, (v2i64)in2); \ - } - -void TransposeWx16_C(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width) { - TransposeWx8_C(src, src_stride, dst, dst_stride, width); - TransposeWx8_C((src + 8 * src_stride), src_stride, (dst + 8), dst_stride, - width); -} - -void TransposeUVWx16_C(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width) { - TransposeUVWx8_C(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b, - width); - TransposeUVWx8_C((src + 8 * src_stride), src_stride, (dst_a + 8), - dst_stride_a, (dst_b + 8), dst_stride_b, width); -} - -void TransposeWx16_MSA(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width) { - int x; - const uint8_t* s; - v16u8 src0, src1, src2, src3, dst0, dst1, dst2, dst3, vec0, vec1, vec2, vec3; - v16u8 reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7; - v16u8 res0, res1, res2, res3, res4, res5, res6, res7, res8, res9; - - for (x = 0; x < width; x += 16) { - s = src; - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src1 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src2 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src3 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3); - ILVRL_H(vec0, vec2, vec1, vec3, reg0, reg1, reg2, reg3); - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src1 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src2 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src3 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3); - ILVRL_H(vec0, vec2, vec1, vec3, reg4, reg5, reg6, reg7); - ILVRL_W(reg0, reg4, reg1, reg5, res0, res1, res2, res3); - ILVRL_W(reg2, reg6, reg3, reg7, res4, res5, res6, res7); - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src1 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src2 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src3 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3); - ILVRL_H(vec0, vec2, vec1, vec3, reg0, reg1, reg2, reg3); - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src1 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src2 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src3 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3); - ILVRL_H(vec0, vec2, vec1, vec3, reg4, reg5, reg6, reg7); - res8 = (v16u8)__msa_ilvr_w((v4i32)reg4, (v4i32)reg0); - res9 = (v16u8)__msa_ilvl_w((v4i32)reg4, (v4i32)reg0); - ILVRL_D(res0, res8, res1, res9, dst0, dst1, dst2, dst3); - ST_UB4(dst0, dst1, dst2, dst3, dst, dst_stride); - dst += dst_stride * 4; - res8 = (v16u8)__msa_ilvr_w((v4i32)reg5, (v4i32)reg1); - res9 = (v16u8)__msa_ilvl_w((v4i32)reg5, (v4i32)reg1); - ILVRL_D(res2, res8, res3, res9, dst0, dst1, dst2, dst3); - ST_UB4(dst0, dst1, dst2, dst3, dst, dst_stride); - dst += dst_stride * 4; - res8 = (v16u8)__msa_ilvr_w((v4i32)reg6, (v4i32)reg2); - res9 = (v16u8)__msa_ilvl_w((v4i32)reg6, (v4i32)reg2); - ILVRL_D(res4, res8, res5, res9, dst0, dst1, dst2, dst3); - ST_UB4(dst0, dst1, dst2, dst3, dst, dst_stride); - dst += dst_stride * 4; - res8 = (v16u8)__msa_ilvr_w((v4i32)reg7, (v4i32)reg3); - res9 = (v16u8)__msa_ilvl_w((v4i32)reg7, (v4i32)reg3); - ILVRL_D(res6, res8, res7, res9, dst0, dst1, dst2, dst3); - ST_UB4(dst0, dst1, dst2, dst3, dst, dst_stride); - src += 16; - dst += dst_stride * 4; - } -} - -void TransposeUVWx16_MSA(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int width) { - int x; - const uint8_t* s; - v16u8 src0, src1, src2, src3, dst0, dst1, dst2, dst3, vec0, vec1, vec2, vec3; - v16u8 reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7; - v16u8 res0, res1, res2, res3, res4, res5, res6, res7, res8, res9; - - for (x = 0; x < width; x += 8) { - s = src; - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src1 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src2 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src3 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3); - ILVRL_H(vec0, vec2, vec1, vec3, reg0, reg1, reg2, reg3); - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src1 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src2 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src3 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3); - ILVRL_H(vec0, vec2, vec1, vec3, reg4, reg5, reg6, reg7); - ILVRL_W(reg0, reg4, reg1, reg5, res0, res1, res2, res3); - ILVRL_W(reg2, reg6, reg3, reg7, res4, res5, res6, res7); - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src1 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src2 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src3 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3); - ILVRL_H(vec0, vec2, vec1, vec3, reg0, reg1, reg2, reg3); - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src1 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src2 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - src3 = (v16u8)__msa_ld_b((v16i8*)s, 0); - s += src_stride; - ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3); - ILVRL_H(vec0, vec2, vec1, vec3, reg4, reg5, reg6, reg7); - res8 = (v16u8)__msa_ilvr_w((v4i32)reg4, (v4i32)reg0); - res9 = (v16u8)__msa_ilvl_w((v4i32)reg4, (v4i32)reg0); - ILVRL_D(res0, res8, res1, res9, dst0, dst1, dst2, dst3); - ST_UB2(dst0, dst2, dst_a, dst_stride_a); - ST_UB2(dst1, dst3, dst_b, dst_stride_b); - dst_a += dst_stride_a * 2; - dst_b += dst_stride_b * 2; - res8 = (v16u8)__msa_ilvr_w((v4i32)reg5, (v4i32)reg1); - res9 = (v16u8)__msa_ilvl_w((v4i32)reg5, (v4i32)reg1); - ILVRL_D(res2, res8, res3, res9, dst0, dst1, dst2, dst3); - ST_UB2(dst0, dst2, dst_a, dst_stride_a); - ST_UB2(dst1, dst3, dst_b, dst_stride_b); - dst_a += dst_stride_a * 2; - dst_b += dst_stride_b * 2; - res8 = (v16u8)__msa_ilvr_w((v4i32)reg6, (v4i32)reg2); - res9 = (v16u8)__msa_ilvl_w((v4i32)reg6, (v4i32)reg2); - ILVRL_D(res4, res8, res5, res9, dst0, dst1, dst2, dst3); - ST_UB2(dst0, dst2, dst_a, dst_stride_a); - ST_UB2(dst1, dst3, dst_b, dst_stride_b); - dst_a += dst_stride_a * 2; - dst_b += dst_stride_b * 2; - res8 = (v16u8)__msa_ilvr_w((v4i32)reg7, (v4i32)reg3); - res9 = (v16u8)__msa_ilvl_w((v4i32)reg7, (v4i32)reg3); - ILVRL_D(res6, res8, res7, res9, dst0, dst1, dst2, dst3); - ST_UB2(dst0, dst2, dst_a, dst_stride_a); - ST_UB2(dst1, dst3, dst_b, dst_stride_b); - src += 16; - dst_a += dst_stride_a * 2; - dst_b += dst_stride_b * 2; - } -} - -#ifdef __cplusplus -} // extern "C" -} // namespace libyuv -#endif - -#endif // !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) diff --git a/libs/libyuv/source/rotate_neon.cc b/libs/libyuv/source/rotate_neon.cc index fdc0dd476c..292930ef8f 100644 --- a/libs/libyuv/source/rotate_neon.cc +++ b/libs/libyuv/source/rotate_neon.cc @@ -11,187 +11,87 @@ #include "libyuv/rotate_row.h" #include "libyuv/row.h" -#include "libyuv/basic_types.h" - #ifdef __cplusplus namespace libyuv { extern "C" { #endif +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + #if !defined(LIBYUV_DISABLE_NEON) && defined(__ARM_NEON__) && \ !defined(__aarch64__) -static const uvec8 kVTbl4x4Transpose = {0, 4, 8, 12, 1, 5, 9, 13, - 2, 6, 10, 14, 3, 7, 11, 15}; - void TransposeWx8_NEON(const uint8_t* src, int src_stride, uint8_t* dst, int dst_stride, int width) { - const uint8_t* src_temp; + const uint8_t* temp; asm volatile( // loops are on blocks of 8. loop will stop when // counter gets to or below 0. starting the counter // at w-8 allow for this - "sub %5, #8 \n" + "sub %[width], #8 \n" - // handle 8x8 blocks. this should be the majority of the plane - "1: \n" - "mov %0, %1 \n" + "1: \n" + "mov %[temp], %[src] \n" + "vld1.8 {d0}, [%[temp]], %[src_stride] \n" + "vld1.8 {d1}, [%[temp]], %[src_stride] \n" + "vld1.8 {d2}, [%[temp]], %[src_stride] \n" + "vld1.8 {d3}, [%[temp]], %[src_stride] \n" + "vld1.8 {d4}, [%[temp]], %[src_stride] \n" + "vld1.8 {d5}, [%[temp]], %[src_stride] \n" + "vld1.8 {d6}, [%[temp]], %[src_stride] \n" + "vld1.8 {d7}, [%[temp]] \n" + "add %[src], #8 \n" - "vld1.8 {d0}, [%0], %2 \n" - "vld1.8 {d1}, [%0], %2 \n" - "vld1.8 {d2}, [%0], %2 \n" - "vld1.8 {d3}, [%0], %2 \n" - "vld1.8 {d4}, [%0], %2 \n" - "vld1.8 {d5}, [%0], %2 \n" - "vld1.8 {d6}, [%0], %2 \n" - "vld1.8 {d7}, [%0] \n" + "vtrn.8 d1, d0 \n" + "vtrn.8 d3, d2 \n" + "vtrn.8 d5, d4 \n" + "vtrn.8 d7, d6 \n" + "subs %[width], #8 \n" - "vtrn.8 d1, d0 \n" - "vtrn.8 d3, d2 \n" - "vtrn.8 d5, d4 \n" - "vtrn.8 d7, d6 \n" + "vtrn.16 d1, d3 \n" + "vtrn.16 d0, d2 \n" + "vtrn.16 d5, d7 \n" + "vtrn.16 d4, d6 \n" - "vtrn.16 d1, d3 \n" - "vtrn.16 d0, d2 \n" - "vtrn.16 d5, d7 \n" - "vtrn.16 d4, d6 \n" + "vtrn.32 d1, d5 \n" + "vtrn.32 d0, d4 \n" + "vtrn.32 d3, d7 \n" + "vtrn.32 d2, d6 \n" - "vtrn.32 d1, d5 \n" - "vtrn.32 d0, d4 \n" - "vtrn.32 d3, d7 \n" - "vtrn.32 d2, d6 \n" + "vrev16.8 q0, q0 \n" + "vrev16.8 q1, q1 \n" + "vrev16.8 q2, q2 \n" + "vrev16.8 q3, q3 \n" - "vrev16.8 q0, q0 \n" - "vrev16.8 q1, q1 \n" - "vrev16.8 q2, q2 \n" - "vrev16.8 q3, q3 \n" + "mov %[temp], %[dst] \n" + "vst1.8 {d1}, [%[temp]], %[dst_stride] \n" + "vst1.8 {d0}, [%[temp]], %[dst_stride] \n" + "vst1.8 {d3}, [%[temp]], %[dst_stride] \n" + "vst1.8 {d2}, [%[temp]], %[dst_stride] \n" + "vst1.8 {d5}, [%[temp]], %[dst_stride] \n" + "vst1.8 {d4}, [%[temp]], %[dst_stride] \n" + "vst1.8 {d7}, [%[temp]], %[dst_stride] \n" + "vst1.8 {d6}, [%[temp]] \n" + "add %[dst], %[dst], %[dst_stride], lsl #3 \n" - "mov %0, %3 \n" - - "vst1.8 {d1}, [%0], %4 \n" - "vst1.8 {d0}, [%0], %4 \n" - "vst1.8 {d3}, [%0], %4 \n" - "vst1.8 {d2}, [%0], %4 \n" - "vst1.8 {d5}, [%0], %4 \n" - "vst1.8 {d4}, [%0], %4 \n" - "vst1.8 {d7}, [%0], %4 \n" - "vst1.8 {d6}, [%0] \n" - - "add %1, #8 \n" // src += 8 - "add %3, %3, %4, lsl #3 \n" // dst += 8 * dst_stride - "subs %5, #8 \n" // w -= 8 - "bge 1b \n" - - // add 8 back to counter. if the result is 0 there are - // no residuals. - "adds %5, #8 \n" - "beq 4f \n" - - // some residual, so between 1 and 7 lines left to transpose - "cmp %5, #2 \n" - "blt 3f \n" - - "cmp %5, #4 \n" - "blt 2f \n" - - // 4x8 block - "mov %0, %1 \n" - "vld1.32 {d0[0]}, [%0], %2 \n" - "vld1.32 {d0[1]}, [%0], %2 \n" - "vld1.32 {d1[0]}, [%0], %2 \n" - "vld1.32 {d1[1]}, [%0], %2 \n" - "vld1.32 {d2[0]}, [%0], %2 \n" - "vld1.32 {d2[1]}, [%0], %2 \n" - "vld1.32 {d3[0]}, [%0], %2 \n" - "vld1.32 {d3[1]}, [%0] \n" - - "mov %0, %3 \n" - - "vld1.8 {q3}, [%6] \n" - - "vtbl.8 d4, {d0, d1}, d6 \n" - "vtbl.8 d5, {d0, d1}, d7 \n" - "vtbl.8 d0, {d2, d3}, d6 \n" - "vtbl.8 d1, {d2, d3}, d7 \n" - - // TODO(frkoenig): Rework shuffle above to - // write out with 4 instead of 8 writes. - "vst1.32 {d4[0]}, [%0], %4 \n" - "vst1.32 {d4[1]}, [%0], %4 \n" - "vst1.32 {d5[0]}, [%0], %4 \n" - "vst1.32 {d5[1]}, [%0] \n" - - "add %0, %3, #4 \n" - "vst1.32 {d0[0]}, [%0], %4 \n" - "vst1.32 {d0[1]}, [%0], %4 \n" - "vst1.32 {d1[0]}, [%0], %4 \n" - "vst1.32 {d1[1]}, [%0] \n" - - "add %1, #4 \n" // src += 4 - "add %3, %3, %4, lsl #2 \n" // dst += 4 * dst_stride - "subs %5, #4 \n" // w -= 4 - "beq 4f \n" - - // some residual, check to see if it includes a 2x8 block, - // or less - "cmp %5, #2 \n" - "blt 3f \n" - - // 2x8 block - "2: \n" - "mov %0, %1 \n" - "vld1.16 {d0[0]}, [%0], %2 \n" - "vld1.16 {d1[0]}, [%0], %2 \n" - "vld1.16 {d0[1]}, [%0], %2 \n" - "vld1.16 {d1[1]}, [%0], %2 \n" - "vld1.16 {d0[2]}, [%0], %2 \n" - "vld1.16 {d1[2]}, [%0], %2 \n" - "vld1.16 {d0[3]}, [%0], %2 \n" - "vld1.16 {d1[3]}, [%0] \n" - - "vtrn.8 d0, d1 \n" - - "mov %0, %3 \n" - - "vst1.64 {d0}, [%0], %4 \n" - "vst1.64 {d1}, [%0] \n" - - "add %1, #2 \n" // src += 2 - "add %3, %3, %4, lsl #1 \n" // dst += 2 * dst_stride - "subs %5, #2 \n" // w -= 2 - "beq 4f \n" - - // 1x8 block - "3: \n" - "vld1.8 {d0[0]}, [%1], %2 \n" - "vld1.8 {d0[1]}, [%1], %2 \n" - "vld1.8 {d0[2]}, [%1], %2 \n" - "vld1.8 {d0[3]}, [%1], %2 \n" - "vld1.8 {d0[4]}, [%1], %2 \n" - "vld1.8 {d0[5]}, [%1], %2 \n" - "vld1.8 {d0[6]}, [%1], %2 \n" - "vld1.8 {d0[7]}, [%1] \n" - - "vst1.64 {d0}, [%3] \n" - - "4: \n" - - : "=&r"(src_temp), // %0 - "+r"(src), // %1 - "+r"(src_stride), // %2 - "+r"(dst), // %3 - "+r"(dst_stride), // %4 - "+r"(width) // %5 - : "r"(&kVTbl4x4Transpose) // %6 + "bge 1b \n" + : [temp] "=&r"(temp), // %[temp] + [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [width] "+r"(width) // %[width] + : [src_stride] "r"(src_stride), // %[src_stride] + [dst_stride] "r"(dst_stride) // %[dst_stride] : "memory", "cc", "q0", "q1", "q2", "q3"); } -static const uvec8 kVTbl4x4TransposeDi = {0, 8, 1, 9, 2, 10, 3, 11, - 4, 12, 5, 13, 6, 14, 7, 15}; - void TransposeUVWx8_NEON(const uint8_t* src, int src_stride, uint8_t* dst_a, @@ -199,215 +99,384 @@ void TransposeUVWx8_NEON(const uint8_t* src, uint8_t* dst_b, int dst_stride_b, int width) { - const uint8_t* src_temp; + const uint8_t* temp; asm volatile( // loops are on blocks of 8. loop will stop when // counter gets to or below 0. starting the counter // at w-8 allow for this - "sub %7, #8 \n" + "sub %[width], #8 \n" - // handle 8x8 blocks. this should be the majority of the plane - "1: \n" - "mov %0, %1 \n" + "1: \n" + "mov %[temp], %[src] \n" + "vld2.8 {d0, d1}, [%[temp]], %[src_stride] \n" + "vld2.8 {d2, d3}, [%[temp]], %[src_stride] \n" + "vld2.8 {d4, d5}, [%[temp]], %[src_stride] \n" + "vld2.8 {d6, d7}, [%[temp]], %[src_stride] \n" + "vld2.8 {d16, d17}, [%[temp]], %[src_stride] \n" + "vld2.8 {d18, d19}, [%[temp]], %[src_stride] \n" + "vld2.8 {d20, d21}, [%[temp]], %[src_stride] \n" + "vld2.8 {d22, d23}, [%[temp]] \n" + "add %[src], #8*2 \n" - "vld2.8 {d0, d1}, [%0], %2 \n" - "vld2.8 {d2, d3}, [%0], %2 \n" - "vld2.8 {d4, d5}, [%0], %2 \n" - "vld2.8 {d6, d7}, [%0], %2 \n" - "vld2.8 {d16, d17}, [%0], %2 \n" - "vld2.8 {d18, d19}, [%0], %2 \n" - "vld2.8 {d20, d21}, [%0], %2 \n" - "vld2.8 {d22, d23}, [%0] \n" + "vtrn.8 q1, q0 \n" + "vtrn.8 q3, q2 \n" + "vtrn.8 q9, q8 \n" + "vtrn.8 q11, q10 \n" + "subs %[width], #8 \n" - "vtrn.8 q1, q0 \n" - "vtrn.8 q3, q2 \n" - "vtrn.8 q9, q8 \n" - "vtrn.8 q11, q10 \n" + "vtrn.16 q1, q3 \n" + "vtrn.16 q0, q2 \n" + "vtrn.16 q9, q11 \n" + "vtrn.16 q8, q10 \n" - "vtrn.16 q1, q3 \n" - "vtrn.16 q0, q2 \n" - "vtrn.16 q9, q11 \n" - "vtrn.16 q8, q10 \n" + "vtrn.32 q1, q9 \n" + "vtrn.32 q0, q8 \n" + "vtrn.32 q3, q11 \n" + "vtrn.32 q2, q10 \n" - "vtrn.32 q1, q9 \n" - "vtrn.32 q0, q8 \n" - "vtrn.32 q3, q11 \n" - "vtrn.32 q2, q10 \n" + "vrev16.8 q0, q0 \n" + "vrev16.8 q1, q1 \n" + "vrev16.8 q2, q2 \n" + "vrev16.8 q3, q3 \n" + "vrev16.8 q8, q8 \n" + "vrev16.8 q9, q9 \n" + "vrev16.8 q10, q10 \n" + "vrev16.8 q11, q11 \n" - "vrev16.8 q0, q0 \n" - "vrev16.8 q1, q1 \n" - "vrev16.8 q2, q2 \n" - "vrev16.8 q3, q3 \n" - "vrev16.8 q8, q8 \n" - "vrev16.8 q9, q9 \n" - "vrev16.8 q10, q10 \n" - "vrev16.8 q11, q11 \n" + "mov %[temp], %[dst_a] \n" + "vst1.8 {d2}, [%[temp]], %[dst_stride_a] \n" + "vst1.8 {d0}, [%[temp]], %[dst_stride_a] \n" + "vst1.8 {d6}, [%[temp]], %[dst_stride_a] \n" + "vst1.8 {d4}, [%[temp]], %[dst_stride_a] \n" + "vst1.8 {d18}, [%[temp]], %[dst_stride_a] \n" + "vst1.8 {d16}, [%[temp]], %[dst_stride_a] \n" + "vst1.8 {d22}, [%[temp]], %[dst_stride_a] \n" + "vst1.8 {d20}, [%[temp]] \n" + "add %[dst_a], %[dst_a], %[dst_stride_a], lsl #3 \n" - "mov %0, %3 \n" + "mov %[temp], %[dst_b] \n" + "vst1.8 {d3}, [%[temp]], %[dst_stride_b] \n" + "vst1.8 {d1}, [%[temp]], %[dst_stride_b] \n" + "vst1.8 {d7}, [%[temp]], %[dst_stride_b] \n" + "vst1.8 {d5}, [%[temp]], %[dst_stride_b] \n" + "vst1.8 {d19}, [%[temp]], %[dst_stride_b] \n" + "vst1.8 {d17}, [%[temp]], %[dst_stride_b] \n" + "vst1.8 {d23}, [%[temp]], %[dst_stride_b] \n" + "vst1.8 {d21}, [%[temp]] \n" + "add %[dst_b], %[dst_b], %[dst_stride_b], lsl #3 \n" - "vst1.8 {d2}, [%0], %4 \n" - "vst1.8 {d0}, [%0], %4 \n" - "vst1.8 {d6}, [%0], %4 \n" - "vst1.8 {d4}, [%0], %4 \n" - "vst1.8 {d18}, [%0], %4 \n" - "vst1.8 {d16}, [%0], %4 \n" - "vst1.8 {d22}, [%0], %4 \n" - "vst1.8 {d20}, [%0] \n" - - "mov %0, %5 \n" - - "vst1.8 {d3}, [%0], %6 \n" - "vst1.8 {d1}, [%0], %6 \n" - "vst1.8 {d7}, [%0], %6 \n" - "vst1.8 {d5}, [%0], %6 \n" - "vst1.8 {d19}, [%0], %6 \n" - "vst1.8 {d17}, [%0], %6 \n" - "vst1.8 {d23}, [%0], %6 \n" - "vst1.8 {d21}, [%0] \n" - - "add %1, #8*2 \n" // src += 8*2 - "add %3, %3, %4, lsl #3 \n" // dst_a += 8 * dst_stride_a - "add %5, %5, %6, lsl #3 \n" // dst_b += 8 * dst_stride_b - "subs %7, #8 \n" // w -= 8 - "bge 1b \n" - - // add 8 back to counter. if the result is 0 there are - // no residuals. - "adds %7, #8 \n" - "beq 4f \n" - - // some residual, so between 1 and 7 lines left to transpose - "cmp %7, #2 \n" - "blt 3f \n" - - "cmp %7, #4 \n" - "blt 2f \n" - - // TODO(frkoenig): Clean this up - // 4x8 block - "mov %0, %1 \n" - "vld1.64 {d0}, [%0], %2 \n" - "vld1.64 {d1}, [%0], %2 \n" - "vld1.64 {d2}, [%0], %2 \n" - "vld1.64 {d3}, [%0], %2 \n" - "vld1.64 {d4}, [%0], %2 \n" - "vld1.64 {d5}, [%0], %2 \n" - "vld1.64 {d6}, [%0], %2 \n" - "vld1.64 {d7}, [%0] \n" - - "vld1.8 {q15}, [%8] \n" - - "vtrn.8 q0, q1 \n" - "vtrn.8 q2, q3 \n" - - "vtbl.8 d16, {d0, d1}, d30 \n" - "vtbl.8 d17, {d0, d1}, d31 \n" - "vtbl.8 d18, {d2, d3}, d30 \n" - "vtbl.8 d19, {d2, d3}, d31 \n" - "vtbl.8 d20, {d4, d5}, d30 \n" - "vtbl.8 d21, {d4, d5}, d31 \n" - "vtbl.8 d22, {d6, d7}, d30 \n" - "vtbl.8 d23, {d6, d7}, d31 \n" - - "mov %0, %3 \n" - - "vst1.32 {d16[0]}, [%0], %4 \n" - "vst1.32 {d16[1]}, [%0], %4 \n" - "vst1.32 {d17[0]}, [%0], %4 \n" - "vst1.32 {d17[1]}, [%0], %4 \n" - - "add %0, %3, #4 \n" - "vst1.32 {d20[0]}, [%0], %4 \n" - "vst1.32 {d20[1]}, [%0], %4 \n" - "vst1.32 {d21[0]}, [%0], %4 \n" - "vst1.32 {d21[1]}, [%0] \n" - - "mov %0, %5 \n" - - "vst1.32 {d18[0]}, [%0], %6 \n" - "vst1.32 {d18[1]}, [%0], %6 \n" - "vst1.32 {d19[0]}, [%0], %6 \n" - "vst1.32 {d19[1]}, [%0], %6 \n" - - "add %0, %5, #4 \n" - "vst1.32 {d22[0]}, [%0], %6 \n" - "vst1.32 {d22[1]}, [%0], %6 \n" - "vst1.32 {d23[0]}, [%0], %6 \n" - "vst1.32 {d23[1]}, [%0] \n" - - "add %1, #4*2 \n" // src += 4 * 2 - "add %3, %3, %4, lsl #2 \n" // dst_a += 4 * - // dst_stride_a - "add %5, %5, %6, lsl #2 \n" // dst_b += 4 * - // dst_stride_b - "subs %7, #4 \n" // w -= 4 - "beq 4f \n" - - // some residual, check to see if it includes a 2x8 block, - // or less - "cmp %7, #2 \n" - "blt 3f \n" - - // 2x8 block - "2: \n" - "mov %0, %1 \n" - "vld2.16 {d0[0], d2[0]}, [%0], %2 \n" - "vld2.16 {d1[0], d3[0]}, [%0], %2 \n" - "vld2.16 {d0[1], d2[1]}, [%0], %2 \n" - "vld2.16 {d1[1], d3[1]}, [%0], %2 \n" - "vld2.16 {d0[2], d2[2]}, [%0], %2 \n" - "vld2.16 {d1[2], d3[2]}, [%0], %2 \n" - "vld2.16 {d0[3], d2[3]}, [%0], %2 \n" - "vld2.16 {d1[3], d3[3]}, [%0] \n" - - "vtrn.8 d0, d1 \n" - "vtrn.8 d2, d3 \n" - - "mov %0, %3 \n" - - "vst1.64 {d0}, [%0], %4 \n" - "vst1.64 {d2}, [%0] \n" - - "mov %0, %5 \n" - - "vst1.64 {d1}, [%0], %6 \n" - "vst1.64 {d3}, [%0] \n" - - "add %1, #2*2 \n" // src += 2 * 2 - "add %3, %3, %4, lsl #1 \n" // dst_a += 2 * - // dst_stride_a - "add %5, %5, %6, lsl #1 \n" // dst_b += 2 * - // dst_stride_b - "subs %7, #2 \n" // w -= 2 - "beq 4f \n" - - // 1x8 block - "3: \n" - "vld2.8 {d0[0], d1[0]}, [%1], %2 \n" - "vld2.8 {d0[1], d1[1]}, [%1], %2 \n" - "vld2.8 {d0[2], d1[2]}, [%1], %2 \n" - "vld2.8 {d0[3], d1[3]}, [%1], %2 \n" - "vld2.8 {d0[4], d1[4]}, [%1], %2 \n" - "vld2.8 {d0[5], d1[5]}, [%1], %2 \n" - "vld2.8 {d0[6], d1[6]}, [%1], %2 \n" - "vld2.8 {d0[7], d1[7]}, [%1] \n" - - "vst1.64 {d0}, [%3] \n" - "vst1.64 {d1}, [%5] \n" - - "4: \n" - - : "=&r"(src_temp), // %0 - "+r"(src), // %1 - "+r"(src_stride), // %2 - "+r"(dst_a), // %3 - "+r"(dst_stride_a), // %4 - "+r"(dst_b), // %5 - "+r"(dst_stride_b), // %6 - "+r"(width) // %7 - : "r"(&kVTbl4x4TransposeDi) // %8 + "bge 1b \n" + : [temp] "=&r"(temp), // %[temp] + [src] "+r"(src), // %[src] + [dst_a] "+r"(dst_a), // %[dst_a] + [dst_b] "+r"(dst_b), // %[dst_b] + [width] "+r"(width) // %[width] + : [src_stride] "r"(src_stride), // %[src_stride] + [dst_stride_a] "r"(dst_stride_a), // %[dst_stride_a] + [dst_stride_b] "r"(dst_stride_b) // %[dst_stride_b] : "memory", "cc", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11"); } + +// Transpose 32 bit values (ARGB) in Wx4 tiles using vld4.32 with lane insertion +// and lane stores for 1..3 remainder rows. +void TransposeWx4_32_NEON(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const uint8_t* src1 = src + s; + const uint8_t* src2 = src1 + s; + const uint8_t* src3 = src2 + s; + const ptrdiff_t d = dst_stride; + uint8_t* dst1 = dst + d; + uint8_t* dst2 = dst1 + d; + uint8_t* dst3 = dst2 + d; + asm volatile( + "subs %8, %8, #4 \n" + "blt 2f \n" + + // Main loop transpose 4x4. Read a column, write a row. + "1: \n" + "vld4.32 {d0[0], d2[0], d4[0], d6[0]}, [%0], %9 \n" + "vld4.32 {d0[1], d2[1], d4[1], d6[1]}, [%1], %9 \n" + "vld4.32 {d1[0], d3[0], d5[0], d7[0]}, [%2], %9 \n" + "vld4.32 {d1[1], d3[1], d5[1], d7[1]}, [%3], %9 \n" + "subs %8, %8, #4 \n" + "vst1.8 {q0}, [%4]! \n" + "vst1.8 {q1}, [%5]! \n" + "vst1.8 {q2}, [%6]! \n" + "vst1.8 {q3}, [%7]! \n" + "bge 1b \n" + + "2: \n" + "adds %8, %8, #4 \n" + "beq 5f \n" + + // Remainder of 1, 2, or 3 source rows. + "vld4.32 {d0[0], d2[0], d4[0], d6[0]}, [%0] \n" + "cmp %8, #2 \n" + "blt 4f \n" + "vld4.32 {d0[1], d2[1], d4[1], d6[1]}, [%1] \n" + "bgt 3f \n" + "vst1.32 {d0}, [%4] \n" + "vst1.32 {d2}, [%5] \n" + "vst1.32 {d4}, [%6] \n" + "vst1.32 {d6}, [%7] \n" + "b 5f \n" + + "3: \n" + "vld4.32 {d1[0], d3[0], d5[0], d7[0]}, [%2] \n" + "vst1.32 {d0}, [%4]! \n" + "vst1.32 {d2}, [%5]! \n" + "vst1.32 {d4}, [%6]! \n" + "vst1.32 {d6}, [%7]! \n" + "vst1.32 {d1[0]}, [%4] \n" + "vst1.32 {d3[0]}, [%5] \n" + "vst1.32 {d5[0]}, [%6] \n" + "vst1.32 {d7[0]}, [%7] \n" + "b 5f \n" + + "4: \n" + "vst1.32 {d0[0]}, [%4] \n" + "vst1.32 {d2[0]}, [%5] \n" + "vst1.32 {d4[0]}, [%6] \n" + "vst1.32 {d6[0]}, [%7] \n" + "5: \n" + : "+r"(src), // %0 + "+r"(src1), // %1 + "+r"(src2), // %2 + "+r"(src3), // %3 + "+r"(dst), // %4 + "+r"(dst1), // %5 + "+r"(dst2), // %6 + "+r"(dst3), // %7 + "+r"(width) // %8 + : "r"(s * 4) // %9 + : "memory", "cc", "q0", "q1", "q2", "q3"); +} + +void TransposeWxH_32_NEON(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height) { + const ptrdiff_t d = dst_stride; + while (width >= 4) { + TransposeWx4_32_NEON(src, src_stride, dst, dst_stride, height); + src += 16; + dst += 4 * d; + width -= 4; + } + if (width == 3) { + const ptrdiff_t s = src_stride; + const uint8_t* src1 = src + s; + const uint8_t* src2 = src1 + s; + const uint8_t* src3 = src2 + s; + uint8_t* dst1 = dst + d; + uint8_t* dst2 = dst1 + d; + asm volatile( + "subs %7, %7, #4 \n" + "blt 2f \n" + "1: \n" + "vld3.32 {d0[0], d2[0], d4[0]}, [%0], %8 \n" + "vld3.32 {d0[1], d2[1], d4[1]}, [%1], %8 \n" + "vld3.32 {d1[0], d3[0], d5[0]}, [%2], %8 \n" + "vld3.32 {d1[1], d3[1], d5[1]}, [%3], %8 \n" + "subs %7, %7, #4 \n" + "vst1.8 {q0}, [%4]! \n" + "vst1.8 {q1}, [%5]! \n" + "vst1.8 {q2}, [%6]! \n" + "bge 1b \n" + "2: \n" + "adds %7, %7, #4 \n" + "beq 5f \n" + "vld3.32 {d0[0], d2[0], d4[0]}, [%0] \n" + "cmp %7, #2 \n" + "blt 4f \n" + "vld3.32 {d0[1], d2[1], d4[1]}, [%1] \n" + "bgt 3f \n" + "vst1.32 {d0}, [%4] \n" + "vst1.32 {d2}, [%5] \n" + "vst1.32 {d4}, [%6] \n" + "b 5f \n" + "3: \n" + "vld3.32 {d1[0], d3[0], d5[0]}, [%2] \n" + "vst1.32 {d0}, [%4]! \n" + "vst1.32 {d2}, [%5]! \n" + "vst1.32 {d4}, [%6]! \n" + "vst1.32 {d1[0]}, [%4] \n" + "vst1.32 {d3[0]}, [%5] \n" + "vst1.32 {d5[0]}, [%6] \n" + "b 5f \n" + "4: \n" + "vst1.32 {d0[0]}, [%4] \n" + "vst1.32 {d2[0]}, [%5] \n" + "vst1.32 {d4[0]}, [%6] \n" + "5: \n" + : "+r"(src), // %0 + "+r"(src1), // %1 + "+r"(src2), // %2 + "+r"(src3), // %3 + "+r"(dst), // %4 + "+r"(dst1), // %5 + "+r"(dst2), // %6 + "+r"(height) // %7 + : "r"(s * 4) // %8 + : "memory", "cc", "q0", "q1", "q2"); + } else if (width == 2) { + const ptrdiff_t s = src_stride; + const uint8_t* src1 = src + s; + const uint8_t* src2 = src1 + s; + const uint8_t* src3 = src2 + s; + uint8_t* dst1 = dst + d; + asm volatile( + "subs %6, %6, #4 \n" + "blt 2f \n" + "1: \n" + "vld2.32 {d0[0], d2[0]}, [%0], %7 \n" + "vld2.32 {d0[1], d2[1]}, [%1], %7 \n" + "vld2.32 {d1[0], d3[0]}, [%2], %7 \n" + "vld2.32 {d1[1], d3[1]}, [%3], %7 \n" + "subs %6, %6, #4 \n" + "vst1.8 {q0}, [%4]! \n" + "vst1.8 {q1}, [%5]! \n" + "bge 1b \n" + "2: \n" + "adds %6, %6, #4 \n" + "beq 5f \n" + "vld2.32 {d0[0], d2[0]}, [%0] \n" + "cmp %6, #2 \n" + "blt 4f \n" + "vld2.32 {d0[1], d2[1]}, [%1] \n" + "bgt 3f \n" + "vst1.32 {d0}, [%4] \n" + "vst1.32 {d2}, [%5] \n" + "b 5f \n" + "3: \n" + "vld2.32 {d1[0], d3[0]}, [%2] \n" + "vst1.32 {d0}, [%4]! \n" + "vst1.32 {d2}, [%5]! \n" + "vst1.32 {d1[0]}, [%4] \n" + "vst1.32 {d3[0]}, [%5] \n" + "b 5f \n" + "4: \n" + "vst1.32 {d0[0]}, [%4] \n" + "vst1.32 {d2[0]}, [%5] \n" + "5: \n" + : "+r"(src), // %0 + "+r"(src1), // %1 + "+r"(src2), // %2 + "+r"(src3), // %3 + "+r"(dst), // %4 + "+r"(dst1), // %5 + "+r"(height) // %6 + : "r"(s * 4) // %7 + : "memory", "cc", "q0", "q1"); + } else if (width == 1) { + const ptrdiff_t s = src_stride; + const uint8_t* src1 = src + s; + const uint8_t* src2 = src1 + s; + const uint8_t* src3 = src2 + s; + asm volatile( + "subs %5, %5, #4 \n" + "blt 2f \n" + "1: \n" + "vld1.32 {d0[0]}, [%0], %6 \n" + "vld1.32 {d0[1]}, [%1], %6 \n" + "vld1.32 {d1[0]}, [%2], %6 \n" + "vld1.32 {d1[1]}, [%3], %6 \n" + "subs %5, %5, #4 \n" + "vst1.8 {q0}, [%4]! \n" + "bge 1b \n" + "2: \n" + "adds %5, %5, #4 \n" + "beq 5f \n" + "vld1.32 {d0[0]}, [%0] \n" + "cmp %5, #2 \n" + "blt 4f \n" + "vld1.32 {d0[1]}, [%1] \n" + "bgt 3f \n" + "vst1.32 {d0}, [%4] \n" + "b 5f \n" + "3: \n" + "vld1.32 {d1[0]}, [%2] \n" + "vst1.32 {d0}, [%4]! \n" + "vst1.32 {d1[0]}, [%4] \n" + "b 5f \n" + "4: \n" + "vst1.32 {d0[0]}, [%4] \n" + "5: \n" + : "+r"(src), // %0 + "+r"(src1), // %1 + "+r"(src2), // %2 + "+r"(src3), // %3 + "+r"(dst), // %4 + "+r"(height) // %5 + : "r"(s * 4) // %6 + : "memory", "cc", "q0"); + } +} + +void TransposeWx8_16_NEON(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = (ptrdiff_t)src_stride * 2; + const ptrdiff_t d = (ptrdiff_t)dst_stride * 2; + const uint8_t* temp; + asm volatile( + "1: \n" + "mov %[temp], %[src] \n" + "vld1.8 {q0}, [%[temp]], %[s] \n" + "vld1.8 {q1}, [%[temp]], %[s] \n" + "vld1.8 {q2}, [%[temp]], %[s] \n" + "vld1.8 {q3}, [%[temp]], %[s] \n" + "vld1.8 {q8}, [%[temp]], %[s] \n" + "vld1.8 {q9}, [%[temp]], %[s] \n" + "vld1.8 {q10}, [%[temp]], %[s] \n" + "vld1.8 {q11}, [%[temp]] \n" + "add %[src], %[src], #16 \n" + + // Stage 1: 16-bit transpose + "vtrn.16 q0, q1 \n" + "vtrn.16 q2, q3 \n" + "vtrn.16 q8, q9 \n" + "vtrn.16 q10, q11 \n" + + // Stage 2: 32-bit transpose + "vtrn.32 q0, q2 \n" + "vtrn.32 q1, q3 \n" + "vtrn.32 q8, q10 \n" + "vtrn.32 q9, q11 \n" + + // Stage 3: 64-bit swap + "vswp d1, d16 \n" + "vswp d3, d18 \n" + "vswp d5, d20 \n" + "vswp d7, d22 \n" + + "subs %[w], %[w], #8 \n" + "vst1.8 {q0}, [%[dst]], %[d] \n" + "vst1.8 {q1}, [%[dst]], %[d] \n" + "vst1.8 {q2}, [%[dst]], %[d] \n" + "vst1.8 {q3}, [%[dst]], %[d] \n" + "vst1.8 {q8}, [%[dst]], %[d] \n" + "vst1.8 {q9}, [%[dst]], %[d] \n" + "vst1.8 {q10}, [%[dst]], %[d] \n" + "vst1.8 {q11}, [%[dst]], %[d] \n" + "bgt 1b \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [w] "+r"(width), // %[w] + [temp] "=&r"(temp) // %[temp] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "cc", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11"); +} + #endif // defined(__ARM_NEON__) && !defined(__aarch64__) #ifdef __cplusplus diff --git a/libs/libyuv/source/rotate_neon64.cc b/libs/libyuv/source/rotate_neon64.cc index f469baacf6..5844c0d28e 100644 --- a/libs/libyuv/source/rotate_neon64.cc +++ b/libs/libyuv/source/rotate_neon64.cc @@ -11,195 +11,137 @@ #include "libyuv/rotate_row.h" #include "libyuv/row.h" -#include "libyuv/basic_types.h" - #ifdef __cplusplus namespace libyuv { extern "C" { #endif +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + // This module is for GCC Neon armv8 64 bit. #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) -static const uvec8 kVTbl4x4Transpose = {0, 4, 8, 12, 1, 5, 9, 13, - 2, 6, 10, 14, 3, 7, 11, 15}; - -void TransposeWx8_NEON(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width) { +void TransposeWx16_NEON(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { const uint8_t* src_temp; asm volatile( - // loops are on blocks of 8. loop will stop when - // counter gets to or below 0. starting the counter - // at w-8 allow for this - "sub %w3, %w3, #8 \n" + "1: \n" + "mov %[src_temp], %[src] \n" - // handle 8x8 blocks. this should be the majority of the plane - "1: \n" - "mov %0, %1 \n" + "ld1 {v16.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v17.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v18.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v19.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v20.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v21.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v22.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v23.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v24.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v25.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v26.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v27.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v28.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v29.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v30.16b}, [%[src_temp]], %[src_stride] \n" + "ld1 {v31.16b}, [%[src_temp]], %[src_stride] \n" - "ld1 {v0.8b}, [%0], %5 \n" - "ld1 {v1.8b}, [%0], %5 \n" - "ld1 {v2.8b}, [%0], %5 \n" - "ld1 {v3.8b}, [%0], %5 \n" - "ld1 {v4.8b}, [%0], %5 \n" - "ld1 {v5.8b}, [%0], %5 \n" - "ld1 {v6.8b}, [%0], %5 \n" - "ld1 {v7.8b}, [%0] \n" + "add %[src], %[src], #16 \n" - "trn2 v16.8b, v0.8b, v1.8b \n" - "trn1 v17.8b, v0.8b, v1.8b \n" - "trn2 v18.8b, v2.8b, v3.8b \n" - "trn1 v19.8b, v2.8b, v3.8b \n" - "trn2 v20.8b, v4.8b, v5.8b \n" - "trn1 v21.8b, v4.8b, v5.8b \n" - "trn2 v22.8b, v6.8b, v7.8b \n" - "trn1 v23.8b, v6.8b, v7.8b \n" + // Transpose bytes within each 2x2 block. + "trn1 v0.16b, v16.16b, v17.16b \n" + "trn2 v1.16b, v16.16b, v17.16b \n" + "trn1 v2.16b, v18.16b, v19.16b \n" + "trn2 v3.16b, v18.16b, v19.16b \n" + "trn1 v4.16b, v20.16b, v21.16b \n" + "trn2 v5.16b, v20.16b, v21.16b \n" + "trn1 v6.16b, v22.16b, v23.16b \n" + "trn2 v7.16b, v22.16b, v23.16b \n" + "trn1 v8.16b, v24.16b, v25.16b \n" + "trn2 v9.16b, v24.16b, v25.16b \n" + "trn1 v10.16b, v26.16b, v27.16b \n" + "trn2 v11.16b, v26.16b, v27.16b \n" + "trn1 v12.16b, v28.16b, v29.16b \n" + "trn2 v13.16b, v28.16b, v29.16b \n" + "trn1 v14.16b, v30.16b, v31.16b \n" + "trn2 v15.16b, v30.16b, v31.16b \n" - "trn2 v3.4h, v17.4h, v19.4h \n" - "trn1 v1.4h, v17.4h, v19.4h \n" - "trn2 v2.4h, v16.4h, v18.4h \n" - "trn1 v0.4h, v16.4h, v18.4h \n" - "trn2 v7.4h, v21.4h, v23.4h \n" - "trn1 v5.4h, v21.4h, v23.4h \n" - "trn2 v6.4h, v20.4h, v22.4h \n" - "trn1 v4.4h, v20.4h, v22.4h \n" + // Transpose 2x2-byte blocks within each 4x4 block. + "trn1 v16.8h, v0.8h, v2.8h \n" + "trn1 v17.8h, v1.8h, v3.8h \n" + "trn2 v18.8h, v0.8h, v2.8h \n" + "trn2 v19.8h, v1.8h, v3.8h \n" + "trn1 v20.8h, v4.8h, v6.8h \n" + "trn1 v21.8h, v5.8h, v7.8h \n" + "trn2 v22.8h, v4.8h, v6.8h \n" + "trn2 v23.8h, v5.8h, v7.8h \n" + "trn1 v24.8h, v8.8h, v10.8h \n" + "trn1 v25.8h, v9.8h, v11.8h \n" + "trn2 v26.8h, v8.8h, v10.8h \n" + "trn2 v27.8h, v9.8h, v11.8h \n" + "trn1 v28.8h, v12.8h, v14.8h \n" + "trn1 v29.8h, v13.8h, v15.8h \n" + "trn2 v30.8h, v12.8h, v14.8h \n" + "trn2 v31.8h, v13.8h, v15.8h \n" - "trn2 v21.2s, v1.2s, v5.2s \n" - "trn1 v17.2s, v1.2s, v5.2s \n" - "trn2 v20.2s, v0.2s, v4.2s \n" - "trn1 v16.2s, v0.2s, v4.2s \n" - "trn2 v23.2s, v3.2s, v7.2s \n" - "trn1 v19.2s, v3.2s, v7.2s \n" - "trn2 v22.2s, v2.2s, v6.2s \n" - "trn1 v18.2s, v2.2s, v6.2s \n" + "subs %w[width], %w[width], #16 \n" - "mov %0, %2 \n" + // Transpose 4x4-byte blocks within each 8x8 block. + "trn1 v0.4s, v16.4s, v20.4s \n" + "trn1 v2.4s, v17.4s, v21.4s \n" + "trn1 v4.4s, v18.4s, v22.4s \n" + "trn1 v6.4s, v19.4s, v23.4s \n" + "trn2 v8.4s, v16.4s, v20.4s \n" + "trn2 v10.4s, v17.4s, v21.4s \n" + "trn2 v12.4s, v18.4s, v22.4s \n" + "trn2 v14.4s, v19.4s, v23.4s \n" + "trn1 v1.4s, v24.4s, v28.4s \n" + "trn1 v3.4s, v25.4s, v29.4s \n" + "trn1 v5.4s, v26.4s, v30.4s \n" + "trn1 v7.4s, v27.4s, v31.4s \n" + "trn2 v9.4s, v24.4s, v28.4s \n" + "trn2 v11.4s, v25.4s, v29.4s \n" + "trn2 v13.4s, v26.4s, v30.4s \n" + "trn2 v15.4s, v27.4s, v31.4s \n" - "st1 {v17.8b}, [%0], %6 \n" - "st1 {v16.8b}, [%0], %6 \n" - "st1 {v19.8b}, [%0], %6 \n" - "st1 {v18.8b}, [%0], %6 \n" - "st1 {v21.8b}, [%0], %6 \n" - "st1 {v20.8b}, [%0], %6 \n" - "st1 {v23.8b}, [%0], %6 \n" - "st1 {v22.8b}, [%0] \n" + // Transpose 8x8-byte blocks and store. + "st2 {v0.d, v1.d}[0], [%[dst]], %[dst_stride] \n" + "st2 {v2.d, v3.d}[0], [%[dst]], %[dst_stride] \n" + "st2 {v4.d, v5.d}[0], [%[dst]], %[dst_stride] \n" + "st2 {v6.d, v7.d}[0], [%[dst]], %[dst_stride] \n" + "st2 {v8.d, v9.d}[0], [%[dst]], %[dst_stride] \n" + "st2 {v10.d, v11.d}[0], [%[dst]], %[dst_stride] \n" + "st2 {v12.d, v13.d}[0], [%[dst]], %[dst_stride] \n" + "st2 {v14.d, v15.d}[0], [%[dst]], %[dst_stride] \n" + "st2 {v0.d, v1.d}[1], [%[dst]], %[dst_stride] \n" + "st2 {v2.d, v3.d}[1], [%[dst]], %[dst_stride] \n" + "st2 {v4.d, v5.d}[1], [%[dst]], %[dst_stride] \n" + "st2 {v6.d, v7.d}[1], [%[dst]], %[dst_stride] \n" + "st2 {v8.d, v9.d}[1], [%[dst]], %[dst_stride] \n" + "st2 {v10.d, v11.d}[1], [%[dst]], %[dst_stride] \n" + "st2 {v12.d, v13.d}[1], [%[dst]], %[dst_stride] \n" + "st2 {v14.d, v15.d}[1], [%[dst]], %[dst_stride] \n" - "add %1, %1, #8 \n" // src += 8 - "add %2, %2, %6, lsl #3 \n" // dst += 8 * dst_stride - "subs %w3, %w3, #8 \n" // w -= 8 - "b.ge 1b \n" - - // add 8 back to counter. if the result is 0 there are - // no residuals. - "adds %w3, %w3, #8 \n" - "b.eq 4f \n" - - // some residual, so between 1 and 7 lines left to transpose - "cmp %w3, #2 \n" - "b.lt 3f \n" - - "cmp %w3, #4 \n" - "b.lt 2f \n" - - // 4x8 block - "mov %0, %1 \n" - "ld1 {v0.s}[0], [%0], %5 \n" - "ld1 {v0.s}[1], [%0], %5 \n" - "ld1 {v0.s}[2], [%0], %5 \n" - "ld1 {v0.s}[3], [%0], %5 \n" - "ld1 {v1.s}[0], [%0], %5 \n" - "ld1 {v1.s}[1], [%0], %5 \n" - "ld1 {v1.s}[2], [%0], %5 \n" - "ld1 {v1.s}[3], [%0] \n" - - "mov %0, %2 \n" - - "ld1 {v2.16b}, [%4] \n" - - "tbl v3.16b, {v0.16b}, v2.16b \n" - "tbl v0.16b, {v1.16b}, v2.16b \n" - - // TODO(frkoenig): Rework shuffle above to - // write out with 4 instead of 8 writes. - "st1 {v3.s}[0], [%0], %6 \n" - "st1 {v3.s}[1], [%0], %6 \n" - "st1 {v3.s}[2], [%0], %6 \n" - "st1 {v3.s}[3], [%0] \n" - - "add %0, %2, #4 \n" - "st1 {v0.s}[0], [%0], %6 \n" - "st1 {v0.s}[1], [%0], %6 \n" - "st1 {v0.s}[2], [%0], %6 \n" - "st1 {v0.s}[3], [%0] \n" - - "add %1, %1, #4 \n" // src += 4 - "add %2, %2, %6, lsl #2 \n" // dst += 4 * dst_stride - "subs %w3, %w3, #4 \n" // w -= 4 - "b.eq 4f \n" - - // some residual, check to see if it includes a 2x8 block, - // or less - "cmp %w3, #2 \n" - "b.lt 3f \n" - - // 2x8 block - "2: \n" - "mov %0, %1 \n" - "ld1 {v0.h}[0], [%0], %5 \n" - "ld1 {v1.h}[0], [%0], %5 \n" - "ld1 {v0.h}[1], [%0], %5 \n" - "ld1 {v1.h}[1], [%0], %5 \n" - "ld1 {v0.h}[2], [%0], %5 \n" - "ld1 {v1.h}[2], [%0], %5 \n" - "ld1 {v0.h}[3], [%0], %5 \n" - "ld1 {v1.h}[3], [%0] \n" - - "trn2 v2.8b, v0.8b, v1.8b \n" - "trn1 v3.8b, v0.8b, v1.8b \n" - - "mov %0, %2 \n" - - "st1 {v3.8b}, [%0], %6 \n" - "st1 {v2.8b}, [%0] \n" - - "add %1, %1, #2 \n" // src += 2 - "add %2, %2, %6, lsl #1 \n" // dst += 2 * dst_stride - "subs %w3, %w3, #2 \n" // w -= 2 - "b.eq 4f \n" - - // 1x8 block - "3: \n" - "ld1 {v0.b}[0], [%1], %5 \n" - "ld1 {v0.b}[1], [%1], %5 \n" - "ld1 {v0.b}[2], [%1], %5 \n" - "ld1 {v0.b}[3], [%1], %5 \n" - "ld1 {v0.b}[4], [%1], %5 \n" - "ld1 {v0.b}[5], [%1], %5 \n" - "ld1 {v0.b}[6], [%1], %5 \n" - "ld1 {v0.b}[7], [%1] \n" - - "st1 {v0.8b}, [%2] \n" - - "4: \n" - - : "=&r"(src_temp), // %0 - "+r"(src), // %1 - "+r"(dst), // %2 - "+r"(width) // %3 - : "r"(&kVTbl4x4Transpose), // %4 - "r"(static_cast(src_stride)), // %5 - "r"(static_cast(dst_stride)) // %6 - : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", - "v17", "v18", "v19", "v20", "v21", "v22", "v23"); + "b.gt 1b \n" + : [src] "+r"(src), // %[src] + [src_temp] "=&r"(src_temp), // %[src_temp] + [dst] "+r"(dst), // %[dst] + [width] "+r"(width) // %[width] + : [src_stride] "r"((ptrdiff_t)src_stride), // %[src_stride] + [dst_stride] "r"((ptrdiff_t)dst_stride) // %[dst_stride] + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", + "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", + "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", + "v29", "v30", "v31"); } -static const uint8_t kVTbl4x4TransposeDi[32] = { - 0, 16, 32, 48, 2, 18, 34, 50, 4, 20, 36, 52, 6, 22, 38, 54, - 1, 17, 33, 49, 3, 19, 35, 51, 5, 21, 37, 53, 7, 23, 39, 55}; - void TransposeUVWx8_NEON(const uint8_t* src, int src_stride, uint8_t* dst_a, @@ -207,217 +149,404 @@ void TransposeUVWx8_NEON(const uint8_t* src, uint8_t* dst_b, int dst_stride_b, int width) { - const uint8_t* src_temp; + const uint8_t* temp; asm volatile( // loops are on blocks of 8. loop will stop when // counter gets to or below 0. starting the counter // at w-8 allow for this - "sub %w4, %w4, #8 \n" + "sub %w[width], %w[width], #8 \n" - // handle 8x8 blocks. this should be the majority of the plane - "1: \n" - "mov %0, %1 \n" + "1: \n" + "mov %[temp], %[src] \n" + "ld1 {v0.16b}, [%[temp]], %[src_stride] \n" + "ld1 {v1.16b}, [%[temp]], %[src_stride] \n" + "ld1 {v2.16b}, [%[temp]], %[src_stride] \n" + "ld1 {v3.16b}, [%[temp]], %[src_stride] \n" + "ld1 {v4.16b}, [%[temp]], %[src_stride] \n" + "ld1 {v5.16b}, [%[temp]], %[src_stride] \n" + "ld1 {v6.16b}, [%[temp]], %[src_stride] \n" + "ld1 {v7.16b}, [%[temp]] \n" + "add %[src], %[src], #16 \n" - "ld1 {v0.16b}, [%0], %5 \n" - "ld1 {v1.16b}, [%0], %5 \n" - "ld1 {v2.16b}, [%0], %5 \n" - "ld1 {v3.16b}, [%0], %5 \n" - "ld1 {v4.16b}, [%0], %5 \n" - "ld1 {v5.16b}, [%0], %5 \n" - "ld1 {v6.16b}, [%0], %5 \n" - "ld1 {v7.16b}, [%0] \n" + "trn1 v16.16b, v0.16b, v1.16b \n" + "trn2 v17.16b, v0.16b, v1.16b \n" + "trn1 v18.16b, v2.16b, v3.16b \n" + "trn2 v19.16b, v2.16b, v3.16b \n" + "trn1 v20.16b, v4.16b, v5.16b \n" + "trn2 v21.16b, v4.16b, v5.16b \n" + "trn1 v22.16b, v6.16b, v7.16b \n" + "trn2 v23.16b, v6.16b, v7.16b \n" - "trn1 v16.16b, v0.16b, v1.16b \n" - "trn2 v17.16b, v0.16b, v1.16b \n" - "trn1 v18.16b, v2.16b, v3.16b \n" - "trn2 v19.16b, v2.16b, v3.16b \n" - "trn1 v20.16b, v4.16b, v5.16b \n" - "trn2 v21.16b, v4.16b, v5.16b \n" - "trn1 v22.16b, v6.16b, v7.16b \n" - "trn2 v23.16b, v6.16b, v7.16b \n" + "subs %w[width], %w[width], #8 \n" - "trn1 v0.8h, v16.8h, v18.8h \n" - "trn2 v1.8h, v16.8h, v18.8h \n" - "trn1 v2.8h, v20.8h, v22.8h \n" - "trn2 v3.8h, v20.8h, v22.8h \n" - "trn1 v4.8h, v17.8h, v19.8h \n" - "trn2 v5.8h, v17.8h, v19.8h \n" - "trn1 v6.8h, v21.8h, v23.8h \n" - "trn2 v7.8h, v21.8h, v23.8h \n" + "trn1 v0.8h, v16.8h, v18.8h \n" + "trn2 v1.8h, v16.8h, v18.8h \n" + "trn1 v2.8h, v20.8h, v22.8h \n" + "trn2 v3.8h, v20.8h, v22.8h \n" + "trn1 v4.8h, v17.8h, v19.8h \n" + "trn2 v5.8h, v17.8h, v19.8h \n" + "trn1 v6.8h, v21.8h, v23.8h \n" + "trn2 v7.8h, v21.8h, v23.8h \n" - "trn1 v16.4s, v0.4s, v2.4s \n" - "trn2 v17.4s, v0.4s, v2.4s \n" - "trn1 v18.4s, v1.4s, v3.4s \n" - "trn2 v19.4s, v1.4s, v3.4s \n" - "trn1 v20.4s, v4.4s, v6.4s \n" - "trn2 v21.4s, v4.4s, v6.4s \n" - "trn1 v22.4s, v5.4s, v7.4s \n" - "trn2 v23.4s, v5.4s, v7.4s \n" + "trn1 v16.4s, v0.4s, v2.4s \n" + "trn2 v17.4s, v0.4s, v2.4s \n" + "trn1 v18.4s, v1.4s, v3.4s \n" + "trn2 v19.4s, v1.4s, v3.4s \n" + "trn1 v20.4s, v4.4s, v6.4s \n" + "trn2 v21.4s, v4.4s, v6.4s \n" + "trn1 v22.4s, v5.4s, v7.4s \n" + "trn2 v23.4s, v5.4s, v7.4s \n" - "mov %0, %2 \n" + "mov %[temp], %[dst_a] \n" + "st1 {v16.d}[0], [%[temp]], %[dst_stride_a] \n" + "st1 {v18.d}[0], [%[temp]], %[dst_stride_a] \n" + "st1 {v17.d}[0], [%[temp]], %[dst_stride_a] \n" + "st1 {v19.d}[0], [%[temp]], %[dst_stride_a] \n" + "st1 {v16.d}[1], [%[temp]], %[dst_stride_a] \n" + "st1 {v18.d}[1], [%[temp]], %[dst_stride_a] \n" + "st1 {v17.d}[1], [%[temp]], %[dst_stride_a] \n" + "st1 {v19.d}[1], [%[temp]] \n" + "add %[dst_a], %[dst_a], %[dst_stride_a], lsl #3 \n" - "st1 {v16.d}[0], [%0], %6 \n" - "st1 {v18.d}[0], [%0], %6 \n" - "st1 {v17.d}[0], [%0], %6 \n" - "st1 {v19.d}[0], [%0], %6 \n" - "st1 {v16.d}[1], [%0], %6 \n" - "st1 {v18.d}[1], [%0], %6 \n" - "st1 {v17.d}[1], [%0], %6 \n" - "st1 {v19.d}[1], [%0] \n" + "mov %[temp], %[dst_b] \n" + "st1 {v20.d}[0], [%[temp]], %[dst_stride_b] \n" + "st1 {v22.d}[0], [%[temp]], %[dst_stride_b] \n" + "st1 {v21.d}[0], [%[temp]], %[dst_stride_b] \n" + "st1 {v23.d}[0], [%[temp]], %[dst_stride_b] \n" + "st1 {v20.d}[1], [%[temp]], %[dst_stride_b] \n" + "st1 {v22.d}[1], [%[temp]], %[dst_stride_b] \n" + "st1 {v21.d}[1], [%[temp]], %[dst_stride_b] \n" + "st1 {v23.d}[1], [%[temp]] \n" + "add %[dst_b], %[dst_b], %[dst_stride_b], lsl #3 \n" - "mov %0, %3 \n" - - "st1 {v20.d}[0], [%0], %7 \n" - "st1 {v22.d}[0], [%0], %7 \n" - "st1 {v21.d}[0], [%0], %7 \n" - "st1 {v23.d}[0], [%0], %7 \n" - "st1 {v20.d}[1], [%0], %7 \n" - "st1 {v22.d}[1], [%0], %7 \n" - "st1 {v21.d}[1], [%0], %7 \n" - "st1 {v23.d}[1], [%0] \n" - - "add %1, %1, #16 \n" // src += 8*2 - "add %2, %2, %6, lsl #3 \n" // dst_a += 8 * - // dst_stride_a - "add %3, %3, %7, lsl #3 \n" // dst_b += 8 * - // dst_stride_b - "subs %w4, %w4, #8 \n" // w -= 8 - "b.ge 1b \n" - - // add 8 back to counter. if the result is 0 there are - // no residuals. - "adds %w4, %w4, #8 \n" - "b.eq 4f \n" - - // some residual, so between 1 and 7 lines left to transpose - "cmp %w4, #2 \n" - "b.lt 3f \n" - - "cmp %w4, #4 \n" - "b.lt 2f \n" - - // TODO(frkoenig): Clean this up - // 4x8 block - "mov %0, %1 \n" - "ld1 {v0.8b}, [%0], %5 \n" - "ld1 {v1.8b}, [%0], %5 \n" - "ld1 {v2.8b}, [%0], %5 \n" - "ld1 {v3.8b}, [%0], %5 \n" - "ld1 {v4.8b}, [%0], %5 \n" - "ld1 {v5.8b}, [%0], %5 \n" - "ld1 {v6.8b}, [%0], %5 \n" - "ld1 {v7.8b}, [%0] \n" - - "ld1 {v30.16b}, [%8], #16 \n" - "ld1 {v31.16b}, [%8] \n" - - "tbl v16.16b, {v0.16b, v1.16b, v2.16b, v3.16b}, v30.16b \n" - "tbl v17.16b, {v0.16b, v1.16b, v2.16b, v3.16b}, v31.16b \n" - "tbl v18.16b, {v4.16b, v5.16b, v6.16b, v7.16b}, v30.16b \n" - "tbl v19.16b, {v4.16b, v5.16b, v6.16b, v7.16b}, v31.16b \n" - - "mov %0, %2 \n" - - "st1 {v16.s}[0], [%0], %6 \n" - "st1 {v16.s}[1], [%0], %6 \n" - "st1 {v16.s}[2], [%0], %6 \n" - "st1 {v16.s}[3], [%0], %6 \n" - - "add %0, %2, #4 \n" - "st1 {v18.s}[0], [%0], %6 \n" - "st1 {v18.s}[1], [%0], %6 \n" - "st1 {v18.s}[2], [%0], %6 \n" - "st1 {v18.s}[3], [%0] \n" - - "mov %0, %3 \n" - - "st1 {v17.s}[0], [%0], %7 \n" - "st1 {v17.s}[1], [%0], %7 \n" - "st1 {v17.s}[2], [%0], %7 \n" - "st1 {v17.s}[3], [%0], %7 \n" - - "add %0, %3, #4 \n" - "st1 {v19.s}[0], [%0], %7 \n" - "st1 {v19.s}[1], [%0], %7 \n" - "st1 {v19.s}[2], [%0], %7 \n" - "st1 {v19.s}[3], [%0] \n" - - "add %1, %1, #8 \n" // src += 4 * 2 - "add %2, %2, %6, lsl #2 \n" // dst_a += 4 * - // dst_stride_a - "add %3, %3, %7, lsl #2 \n" // dst_b += 4 * - // dst_stride_b - "subs %w4, %w4, #4 \n" // w -= 4 - "b.eq 4f \n" - - // some residual, check to see if it includes a 2x8 block, - // or less - "cmp %w4, #2 \n" - "b.lt 3f \n" - - // 2x8 block - "2: \n" - "mov %0, %1 \n" - "ld2 {v0.h, v1.h}[0], [%0], %5 \n" - "ld2 {v2.h, v3.h}[0], [%0], %5 \n" - "ld2 {v0.h, v1.h}[1], [%0], %5 \n" - "ld2 {v2.h, v3.h}[1], [%0], %5 \n" - "ld2 {v0.h, v1.h}[2], [%0], %5 \n" - "ld2 {v2.h, v3.h}[2], [%0], %5 \n" - "ld2 {v0.h, v1.h}[3], [%0], %5 \n" - "ld2 {v2.h, v3.h}[3], [%0] \n" - - "trn1 v4.8b, v0.8b, v2.8b \n" - "trn2 v5.8b, v0.8b, v2.8b \n" - "trn1 v6.8b, v1.8b, v3.8b \n" - "trn2 v7.8b, v1.8b, v3.8b \n" - - "mov %0, %2 \n" - - "st1 {v4.d}[0], [%0], %6 \n" - "st1 {v6.d}[0], [%0] \n" - - "mov %0, %3 \n" - - "st1 {v5.d}[0], [%0], %7 \n" - "st1 {v7.d}[0], [%0] \n" - - "add %1, %1, #4 \n" // src += 2 * 2 - "add %2, %2, %6, lsl #1 \n" // dst_a += 2 * - // dst_stride_a - "add %3, %3, %7, lsl #1 \n" // dst_b += 2 * - // dst_stride_b - "subs %w4, %w4, #2 \n" // w -= 2 - "b.eq 4f \n" - - // 1x8 block - "3: \n" - "ld2 {v0.b, v1.b}[0], [%1], %5 \n" - "ld2 {v0.b, v1.b}[1], [%1], %5 \n" - "ld2 {v0.b, v1.b}[2], [%1], %5 \n" - "ld2 {v0.b, v1.b}[3], [%1], %5 \n" - "ld2 {v0.b, v1.b}[4], [%1], %5 \n" - "ld2 {v0.b, v1.b}[5], [%1], %5 \n" - "ld2 {v0.b, v1.b}[6], [%1], %5 \n" - "ld2 {v0.b, v1.b}[7], [%1] \n" - - "st1 {v0.d}[0], [%2] \n" - "st1 {v1.d}[0], [%3] \n" - - "4: \n" - - : "=&r"(src_temp), // %0 - "+r"(src), // %1 - "+r"(dst_a), // %2 - "+r"(dst_b), // %3 - "+r"(width) // %4 - : "r"(static_cast(src_stride)), // %5 - "r"(static_cast(dst_stride_a)), // %6 - "r"(static_cast(dst_stride_b)), // %7 - "r"(&kVTbl4x4TransposeDi) // %8 + "b.ge 1b \n" + : [temp] "=&r"(temp), // %[temp] + [src] "+r"(src), // %[src] + [dst_a] "+r"(dst_a), // %[dst_a] + [dst_b] "+r"(dst_b), // %[dst_b] + [width] "+r"(width) // %[width] + : [src_stride] "r"((ptrdiff_t)src_stride), // %[src_stride] + [dst_stride_a] "r"((ptrdiff_t)dst_stride_a), // %[dst_stride_a] + [dst_stride_b] "r"((ptrdiff_t)dst_stride_b) // %[dst_stride_b] : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v30", "v31"); } + +// Transpose 32 bit values (ARGB) in Wx4 tiles using ld4 with lane insertion +// and lane stores for 1..3 remainder rows. +void TransposeWx4_32_NEON(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const uint8_t* src1 = src + s; + const uint8_t* src2 = src1 + s; + const uint8_t* src3 = src2 + s; + const ptrdiff_t d = dst_stride; + uint8_t* dst1 = dst + d; + uint8_t* dst2 = dst1 + d; + uint8_t* dst3 = dst2 + d; + asm volatile( + "subs %w8, %w8, #4 \n" + "b.lt 2f \n" + + // Main loop transpose 4x4. Read a column, write a row. + "1: \n" + "ldp s0, s1, [%0] \n" + "ldp s2, s3, [%0, #8] \n" + "add %0, %0, %9 \n" + "ld4 {v0.s, v1.s, v2.s, v3.s}[1], [%1], %9 \n" + "ld4 {v0.s, v1.s, v2.s, v3.s}[2], [%2], %9 \n" + "ld4 {v0.s, v1.s, v2.s, v3.s}[3], [%3], %9 \n" + "subs %w8, %w8, #4 \n" + "st1 {v0.4s}, [%4], 16 \n" + "st1 {v1.4s}, [%5], 16 \n" + "st1 {v2.4s}, [%6], 16 \n" + "st1 {v3.4s}, [%7], 16 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w8, %w8, #4 \n" + "b.eq 5f \n" + + // Remainder of 1, 2, or 3 source rows. + "ld4 {v0.s, v1.s, v2.s, v3.s}[0], [%0] \n" + "cmp %w8, #2 \n" + "b.lt 4f \n" + "ld4 {v0.s, v1.s, v2.s, v3.s}[1], [%1] \n" + "b.gt 3f \n" + "st1 {v0.d}[0], [%4] \n" + "st1 {v1.d}[0], [%5] \n" + "st1 {v2.d}[0], [%6] \n" + "st1 {v3.d}[0], [%7] \n" + "b 5f \n" + + "3: \n" + "ld4 {v0.s, v1.s, v2.s, v3.s}[2], [%2] \n" + "st1 {v0.d}[0], [%4], 8 \n" + "st1 {v1.d}[0], [%5], 8 \n" + "st1 {v2.d}[0], [%6], 8 \n" + "st1 {v3.d}[0], [%7], 8 \n" + "st1 {v0.s}[2], [%4] \n" + "st1 {v1.s}[2], [%5] \n" + "st1 {v2.s}[2], [%6] \n" + "st1 {v3.s}[2], [%7] \n" + "b 5f \n" + + "4: \n" + "st1 {v0.s}[0], [%4] \n" + "st1 {v1.s}[0], [%5] \n" + "st1 {v2.s}[0], [%6] \n" + "st1 {v3.s}[0], [%7] \n" + "5: \n" + : "+r"(src), // %0 + "+r"(src1), // %1 + "+r"(src2), // %2 + "+r"(src3), // %3 + "+r"(dst), // %4 + "+r"(dst1), // %5 + "+r"(dst2), // %6 + "+r"(dst3), // %7 + "+r"(width) // %8 + : "r"(s * 4) // %9 + : "memory", "cc", "v0", "v1", "v2", "v3"); +} + +void TransposeWxH_32_NEON(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height) { + const ptrdiff_t d = dst_stride; + while (width >= 4) { + TransposeWx4_32_NEON(src, src_stride, dst, dst_stride, height); + src += 16; + dst += 4 * d; + width -= 4; + } + if (width == 3) { + const ptrdiff_t s = src_stride; + const uint8_t* src1 = src + s; + const uint8_t* src2 = src1 + s; + const uint8_t* src3 = src2 + s; + uint8_t* dst1 = dst + d; + uint8_t* dst2 = dst1 + d; + asm volatile( + "subs %w7, %w7, #4 \n" + "b.lt 2f \n" + "1: \n" + "ld3 {v0.s, v1.s, v2.s}[0], [%0], %8 \n" + "ld3 {v0.s, v1.s, v2.s}[1], [%1], %8 \n" + "ld3 {v0.s, v1.s, v2.s}[2], [%2], %8 \n" + "ld3 {v0.s, v1.s, v2.s}[3], [%3], %8 \n" + "subs %w7, %w7, #4 \n" + "st1 {v0.4s}, [%4], 16 \n" + "st1 {v1.4s}, [%5], 16 \n" + "st1 {v2.4s}, [%6], 16 \n" + "b.ge 1b \n" + "2: \n" + "adds %w7, %w7, #4 \n" + "b.eq 5f \n" + "ld3 {v0.s, v1.s, v2.s}[0], [%0] \n" + "cmp %w7, #2 \n" + "b.lt 4f \n" + "ld3 {v0.s, v1.s, v2.s}[1], [%1] \n" + "b.gt 3f \n" + "st1 {v0.d}[0], [%4] \n" + "st1 {v1.d}[0], [%5] \n" + "st1 {v2.d}[0], [%6] \n" + "b 5f \n" + "3: \n" + "ld3 {v0.s, v1.s, v2.s}[2], [%2] \n" + "st1 {v0.d}[0], [%4], 8 \n" + "st1 {v1.d}[0], [%5], 8 \n" + "st1 {v2.d}[0], [%6], 8 \n" + "st1 {v0.s}[2], [%4] \n" + "st1 {v1.s}[2], [%5] \n" + "st1 {v2.s}[2], [%6] \n" + "b 5f \n" + "4: \n" + "st1 {v0.s}[0], [%4] \n" + "st1 {v1.s}[0], [%5] \n" + "st1 {v2.s}[0], [%6] \n" + "5: \n" + : "+r"(src), // %0 + "+r"(src1), // %1 + "+r"(src2), // %2 + "+r"(src3), // %3 + "+r"(dst), // %4 + "+r"(dst1), // %5 + "+r"(dst2), // %6 + "+r"(height) // %7 + : "r"(s * 4) // %8 + : "memory", "cc", "v0", "v1", "v2"); + } else if (width == 2) { + const ptrdiff_t s = src_stride; + const uint8_t* src1 = src + s; + const uint8_t* src2 = src1 + s; + const uint8_t* src3 = src2 + s; + uint8_t* dst1 = dst + d; + asm volatile( + "subs %w6, %w6, #4 \n" + "b.lt 2f \n" + "1: \n" + "ld2 {v0.s, v1.s}[0], [%0], %7 \n" + "ld2 {v0.s, v1.s}[1], [%1], %7 \n" + "ld2 {v0.s, v1.s}[2], [%2], %7 \n" + "ld2 {v0.s, v1.s}[3], [%3], %7 \n" + "subs %w6, %w6, #4 \n" + "st1 {v0.4s}, [%4], 16 \n" + "st1 {v1.4s}, [%5], 16 \n" + "b.ge 1b \n" + "2: \n" + "adds %w6, %w6, #4 \n" + "b.eq 5f \n" + "ld2 {v0.s, v1.s}[0], [%0] \n" + "cmp %w6, #2 \n" + "b.lt 4f \n" + "ld2 {v0.s, v1.s}[1], [%1] \n" + "b.gt 3f \n" + "st1 {v0.d}[0], [%4] \n" + "st1 {v1.d}[0], [%5] \n" + "b 5f \n" + "3: \n" + "ld2 {v0.s, v1.s}[2], [%2] \n" + "st1 {v0.d}[0], [%4], 8 \n" + "st1 {v1.d}[0], [%5], 8 \n" + "st1 {v0.s}[2], [%4] \n" + "st1 {v1.s}[2], [%5] \n" + "b 5f \n" + "4: \n" + "st1 {v0.s}[0], [%4] \n" + "st1 {v1.s}[0], [%5] \n" + "5: \n" + : "+r"(src), // %0 + "+r"(src1), // %1 + "+r"(src2), // %2 + "+r"(src3), // %3 + "+r"(dst), // %4 + "+r"(dst1), // %5 + "+r"(height) // %6 + : "r"(s * 4) // %7 + : "memory", "cc", "v0", "v1"); + } else if (width == 1) { + const ptrdiff_t s = src_stride; + const uint8_t* src1 = src + s; + const uint8_t* src2 = src1 + s; + const uint8_t* src3 = src2 + s; + asm volatile( + "subs %w5, %w5, #4 \n" + "b.lt 2f \n" + "1: \n" + "ld1 {v0.s}[0], [%0], %6 \n" + "ld1 {v0.s}[1], [%1], %6 \n" + "ld1 {v0.s}[2], [%2], %6 \n" + "ld1 {v0.s}[3], [%3], %6 \n" + "subs %w5, %w5, #4 \n" + "st1 {v0.4s}, [%4], 16 \n" + "b.ge 1b \n" + "2: \n" + "adds %w5, %w5, #4 \n" + "b.eq 5f \n" + "ld1 {v0.s}[0], [%0] \n" + "cmp %w5, #2 \n" + "b.lt 4f \n" + "ld1 {v0.s}[1], [%1] \n" + "b.gt 3f \n" + "st1 {v0.d}[0], [%4] \n" + "b 5f \n" + "3: \n" + "ld1 {v0.s}[2], [%2] \n" + "st1 {v0.d}[0], [%4], 8 \n" + "st1 {v0.s}[2], [%4] \n" + "b 5f \n" + "4: \n" + "st1 {v0.s}[0], [%4] \n" + "5: \n" + : "+r"(src), // %0 + "+r"(src1), // %1 + "+r"(src2), // %2 + "+r"(src3), // %3 + "+r"(dst), // %4 + "+r"(height) // %5 + : "r"(s * 4) // %6 + : "memory", "cc", "v0"); + } +} + +void TransposeWx8_16_NEON(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = (ptrdiff_t)src_stride * 2; + const ptrdiff_t d = (ptrdiff_t)dst_stride * 2; + const uint16_t* temp; + asm volatile( + "1: \n" + "mov %[temp], %[src] \n" + "ld1 {v0.8h}, [%[temp]], %[s] \n" + "ld1 {v1.8h}, [%[temp]], %[s] \n" + "ld1 {v2.8h}, [%[temp]], %[s] \n" + "ld1 {v3.8h}, [%[temp]], %[s] \n" + "ld1 {v4.8h}, [%[temp]], %[s] \n" + "ld1 {v5.8h}, [%[temp]], %[s] \n" + "ld1 {v6.8h}, [%[temp]], %[s] \n" + "ld1 {v7.8h}, [%[temp]] \n" + "add %[src], %[src], #16 \n" + + // Stage 1: 16-bit transpose + "trn1 v16.8h, v0.8h, v1.8h \n" + "trn2 v17.8h, v0.8h, v1.8h \n" + "trn1 v18.8h, v2.8h, v3.8h \n" + "trn2 v19.8h, v2.8h, v3.8h \n" + "trn1 v20.8h, v4.8h, v5.8h \n" + "trn2 v21.8h, v4.8h, v5.8h \n" + "trn1 v22.8h, v6.8h, v7.8h \n" + "trn2 v23.8h, v6.8h, v7.8h \n" + + // Stage 2: 32-bit transpose + "trn1 v0.4s, v16.4s, v18.4s \n" + "trn1 v1.4s, v17.4s, v19.4s \n" + "trn2 v2.4s, v16.4s, v18.4s \n" + "trn2 v3.4s, v17.4s, v19.4s \n" + "trn1 v4.4s, v20.4s, v22.4s \n" + "trn1 v5.4s, v21.4s, v23.4s \n" + "trn2 v6.4s, v20.4s, v22.4s \n" + "trn2 v7.4s, v21.4s, v23.4s \n" + + // Stage 3: 64-bit transpose + "trn1 v16.2d, v0.2d, v4.2d \n" + "trn1 v17.2d, v1.2d, v5.2d \n" + "trn1 v18.2d, v2.2d, v6.2d \n" + "trn1 v19.2d, v3.2d, v7.2d \n" + "trn2 v20.2d, v0.2d, v4.2d \n" + "trn2 v21.2d, v1.2d, v5.2d \n" + "trn2 v22.2d, v2.2d, v6.2d \n" + "trn2 v23.2d, v3.2d, v7.2d \n" + + "subs %w[w], %w[w], #8 \n" + "st1 {v16.8h}, [%[dst]], %[d] \n" + "st1 {v17.8h}, [%[dst]], %[d] \n" + "st1 {v18.8h}, [%[dst]], %[d] \n" + "st1 {v19.8h}, [%[dst]], %[d] \n" + "st1 {v20.8h}, [%[dst]], %[d] \n" + "st1 {v21.8h}, [%[dst]], %[d] \n" + "st1 {v22.8h}, [%[dst]], %[d] \n" + "st1 {v23.8h}, [%[dst]], %[d] \n" + "b.gt 1b \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [w] "+r"(width), // %[w] + [temp] "=&r"(temp) // %[temp] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23"); +} + #endif // !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) #ifdef __cplusplus diff --git a/libs/libyuv/source/rotate_rvv.cc b/libs/libyuv/source/rotate_rvv.cc new file mode 100644 index 0000000000..327f861ec5 --- /dev/null +++ b/libs/libyuv/source/rotate_rvv.cc @@ -0,0 +1,275 @@ +/* + * Copyright 2026 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/rotate_row.h" +#include "libyuv/row.h" + +// This module is for RVV (RISC-V Vector extension) +#if !defined(LIBYUV_DISABLE_RVV) && defined(__riscv_vector) +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +#ifndef RVV_VL_CLOBBER +#ifdef __clang__ +#define RVV_VL_CLOBBER +#else +#define RVV_VL_CLOBBER "vl", +#endif +#endif + +#ifdef HAS_TRANSPOSEWX4_32_RVV +// Transpose 32 bit values (ARGB) in Wx4 tiles, moving down W rows of source +// (VL at a time) and across W columns of destination (4 rows). +// Tuned for 512-bit VL (SiFive X280). +void TransposeWx4_32_RVV(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + int vl; + ptrdiff_t src_step; + ptrdiff_t dst_step; + uint8_t* dst1 = dst + (ptrdiff_t)dst_stride; + uint8_t* dst2 = dst1 + (ptrdiff_t)dst_stride; + uint8_t* dst3 = dst2 + (ptrdiff_t)dst_stride; + asm volatile( + "vsetvli %[vl], %[w], e32, m2, ta, ma \n" + "slli %[dst_step], %[vl], 2 \n" + "mul %[src_step], %[vl], %[src_stride] \n" + "sub %[w], %[w], %[vl] \n" + "bltz %[w], 2f \n" + "1: \n" + "vlsseg4e32.v v8, (%[src]), %[src_stride] \n" + "add %[src], %[src], %[src_step] \n" + "vse32.v v8, (%[dst0]) \n" + "vse32.v v10, (%[dst1]) \n" + "vse32.v v12, (%[dst2]) \n" + "vse32.v v14, (%[dst3]) \n" + "add %[dst0], %[dst0], %[dst_step] \n" + "add %[dst1], %[dst1], %[dst_step] \n" + "add %[dst2], %[dst2], %[dst_step] \n" + "add %[dst3], %[dst3], %[dst_step] \n" + "sub %[w], %[w], %[vl] \n" + "bgez %[w], 1b \n" + "2: \n" + "add %[w], %[w], %[vl] \n" + "beqz %[w], 3f \n" + "vsetvli %[vl], %[w], e32, m2, ta, ma \n" + "vlsseg4e32.v v8, (%[src]), %[src_stride] \n" + "vse32.v v8, (%[dst0]) \n" + "vse32.v v10, (%[dst1]) \n" + "vse32.v v12, (%[dst2]) \n" + "vse32.v v14, (%[dst3]) \n" + "3: \n" + : [w] "+r"(width), // %[w] + [src] "+r"(src), // %[src] + [dst0] "+r"(dst), // %[dst0] + [dst1] "+r"(dst1), // %[dst1] + [dst2] "+r"(dst2), // %[dst2] + [dst3] "+r"(dst3), // %[dst3] + [vl] "=&r"(vl), // %[vl] + [src_step] "=&r"(src_step), // %[src_step] + [dst_step] "=&r"(dst_step) // %[dst_step] + : [src_stride] "r"((ptrdiff_t)src_stride) // %[src_stride] + : RVV_VL_CLOBBER "vtype", "memory", "v8", "v9", "v10", "v11", "v12", + "v13", "v14", "v15"); +} +#endif // HAS_TRANSPOSEWX4_32_RVV + +#ifdef HAS_TRANSPOSEWXH_32_RVV +// Transpose 32 bit plane of any width x height using RVV without scalar +// fallback. +void TransposeWxH_32_RVV(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height) { + while (width >= 4) { + TransposeWx4_32_RVV(src, src_stride, dst, dst_stride, height); + src += 16; + dst += 4 * (ptrdiff_t)dst_stride; + width -= 4; + } + while (width > 0) { + const uint8_t* s_col = src; + uint8_t* d_row = dst; + int h = height; + int vl; + ptrdiff_t src_step; + ptrdiff_t dst_step; + asm volatile( + "vsetvli %[vl], %[h], e32, m8, ta, ma \n" + "slli %[d_step], %[vl], 2 \n" + "mul %[s_step], %[vl], %[src_stride] \n" + "sub %[h], %[h], %[vl] \n" + "bltz %[h], 2f \n" + "1: \n" + "vlse32.v v8, (%[s]), %[src_stride] \n" + "add %[s], %[s], %[s_step] \n" + "vse32.v v8, (%[d]) \n" + "add %[d], %[d], %[d_step] \n" + "sub %[h], %[h], %[vl] \n" + "bgez %[h], 1b \n" + "2: \n" + "add %[h], %[h], %[vl] \n" + "beqz %[h], 3f \n" + "vsetvli %[vl], %[h], e32, m8, ta, ma \n" + "vlse32.v v8, (%[s]), %[src_stride] \n" + "vse32.v v8, (%[d]) \n" + "3: \n" + : [h] "+r"(h), // %[h] + [s] "+r"(s_col), // %[s] + [d] "+r"(d_row), // %[d] + [vl] "=&r"(vl), // %[vl] + [s_step] "=&r"(src_step), // %[s_step] + [d_step] "=&r"(dst_step) // %[d_step] + : [src_stride] "r"((ptrdiff_t)src_stride) // %[src_stride] + : RVV_VL_CLOBBER "vtype", "memory", "v8", "v9", "v10", "v11", "v12", + "v13", "v14", "v15"); + src += 4; + dst += (ptrdiff_t)dst_stride; + width -= 1; + } +} +#endif // HAS_TRANSPOSEWXH_32_RVV + +#ifdef HAS_TRANSPOSEWXH_16_RVV +void TransposeWxH_16_RVV(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height) { + const ptrdiff_t s_stride = (ptrdiff_t)src_stride * 2; + const ptrdiff_t d_stride = (ptrdiff_t)dst_stride * 2; + while (width >= 4) { + const uint16_t* s0 = src; + const uint16_t* s1 = src + 1; + const uint16_t* s2 = src + 2; + const uint16_t* s3 = src + 3; + uint8_t* d0 = (uint8_t*)dst; + uint8_t* d1 = d0 + d_stride; + uint8_t* d2 = d1 + d_stride; + uint8_t* d3 = d2 + d_stride; + int h = height; + int vl; + ptrdiff_t src_step; + ptrdiff_t dst_step; + asm volatile( + "vsetvli %[vl], %[h], e16, m8, ta, ma \n" + "slli %[d_step], %[vl], 1 \n" + "mul %[s_step], %[vl], %[s_stride] \n" + "sub %[h], %[h], %[vl] \n" + "bltz %[h], 2f \n" + "1: \n" + "vlse16.v v0, (%[s0]), %[s_stride] \n" + "vlse16.v v8, (%[s1]), %[s_stride] \n" + "vlse16.v v16, (%[s2]), %[s_stride] \n" + "vlse16.v v24, (%[s3]), %[s_stride] \n" + "add %[s0], %[s0], %[s_step] \n" + "add %[s1], %[s1], %[s_step] \n" + "add %[s2], %[s2], %[s_step] \n" + "add %[s3], %[s3], %[s_step] \n" + "vse16.v v0, (%[d0]) \n" + "vse16.v v8, (%[d1]) \n" + "vse16.v v16, (%[d2]) \n" + "vse16.v v24, (%[d3]) \n" + "add %[d0], %[d0], %[d_step] \n" + "add %[d1], %[d1], %[d_step] \n" + "add %[d2], %[d2], %[d_step] \n" + "add %[d3], %[d3], %[d_step] \n" + "sub %[h], %[h], %[vl] \n" + "bgez %[h], 1b \n" + "2: \n" + "add %[h], %[h], %[vl] \n" + "beqz %[h], 3f \n" + "vsetvli %[vl], %[h], e16, m8, ta, ma \n" + "vlse16.v v0, (%[s0]), %[s_stride] \n" + "vlse16.v v8, (%[s1]), %[s_stride] \n" + "vlse16.v v16, (%[s2]), %[s_stride] \n" + "vlse16.v v24, (%[s3]), %[s_stride] \n" + "vse16.v v0, (%[d0]) \n" + "vse16.v v8, (%[d1]) \n" + "vse16.v v16, (%[d2]) \n" + "vse16.v v24, (%[d3]) \n" + "3: \n" + : [h] "+r"(h), // %[h] + [s0] "+r"(s0), // %[s0] + [s1] "+r"(s1), // %[s1] + [s2] "+r"(s2), // %[s2] + [s3] "+r"(s3), // %[s3] + [d0] "+r"(d0), // %[d0] + [d1] "+r"(d1), // %[d1] + [d2] "+r"(d2), // %[d2] + [d3] "+r"(d3), // %[d3] + [vl] "=&r"(vl), // %[vl] + [s_step] "=&r"(src_step), // %[s_step] + [d_step] "=&r"(dst_step) // %[d_step] + : [s_stride] "r"(s_stride) // %[s_stride] + : RVV_VL_CLOBBER "vtype", "memory", "v0", "v1", "v2", "v3", "v4", "v5", + "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", + "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", + "v26", "v27", "v28", "v29", "v30", "v31"); + src += 4; + dst += 4 * (ptrdiff_t)dst_stride; + width -= 4; + } + while (width > 0) { + const uint16_t* s_col = src; + uint16_t* d_row = dst; + int h = height; + int vl; + ptrdiff_t src_step; + ptrdiff_t dst_step; + asm volatile( + "vsetvli %[vl], %[h], e16, m8, ta, ma \n" + "slli %[d_step], %[vl], 1 \n" + "mul %[s_step], %[vl], %[s_stride] \n" + "sub %[h], %[h], %[vl] \n" + "bltz %[h], 2f \n" + "1: \n" + "vlse16.v v8, (%[s]), %[s_stride] \n" + "add %[s], %[s], %[s_step] \n" + "vse16.v v8, (%[d]) \n" + "add %[d], %[d], %[d_step] \n" + "sub %[h], %[h], %[vl] \n" + "bgez %[h], 1b \n" + "2: \n" + "add %[h], %[h], %[vl] \n" + "beqz %[h], 3f \n" + "vsetvli %[vl], %[h], e16, m8, ta, ma \n" + "vlse16.v v8, (%[s]), %[s_stride] \n" + "vse16.v v8, (%[d]) \n" + "3: \n" + : [h] "+r"(h), // %[h] + [s] "+r"(s_col), // %[s] + [d] "+r"(d_row), // %[d] + [vl] "=&r"(vl), // %[vl] + [s_step] "=&r"(src_step), // %[s_step] + [d_step] "=&r"(dst_step) // %[d_step] + : [s_stride] "r"(s_stride) // %[s_stride] + : RVV_VL_CLOBBER "vtype", "memory", "v8", "v9", "v10", "v11", "v12", + "v13", "v14", "v15"); + src += 1; + dst += (ptrdiff_t)dst_stride; + width -= 1; + } +} +#endif // HAS_TRANSPOSEWXH_16_RVV + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_RVV) && defined(__riscv_vector) diff --git a/libs/libyuv/source/rotate_sme.cc b/libs/libyuv/source/rotate_sme.cc new file mode 100644 index 0000000000..85d5bf6049 --- /dev/null +++ b/libs/libyuv/source/rotate_sme.cc @@ -0,0 +1,313 @@ +/* + * Copyright 2024 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/rotate_row.h" +#include "libyuv/row.h" + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + +#if !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && \ + defined(__aarch64__) + +__arm_locally_streaming __arm_new("za") void TransposeWxH_SME( + const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height) { + int vl; + asm("cntb %x0" : "=r"(vl)); + + do { + const uint8_t* src2 = src; + uint8_t* dst2 = dst; + + // Process up to VL elements per iteration of the inner loop. + int block_height = height > vl ? vl : height; + + int width2 = width; + do { + const uint8_t* src3 = src2; + + // Process up to VL elements per iteration of the inner loop. + int block_width = width2 > vl ? vl : width2; + + asm volatile( + "mov w12, #0 \n" + + // Create a predicate to handle loading partial rows. + "whilelt p0.b, wzr, %w[block_width] \n" + + // Load H <= VL rows into ZA0. + "1: \n" + "ld1b {za0h.b[w12, 0]}, p0/z, [%[src3]] \n" + "add %[src3], %[src3], %[src_stride] \n" + "add w12, w12, #1 \n" + "cmp w12, %w[block_height] \n" + "b.ne 1b \n" + + // Create a predicate to handle storing partial columns. + "whilelt p0.b, wzr, %w[block_height] \n" + "mov w12, #0 \n" + + // Store W <= VL columns from ZA0. + "2: \n" + "st1b {za0v.b[w12, 0]}, p0, [%[dst2]] \n" + "add %[dst2], %[dst2], %[dst_stride] \n" + "add w12, w12, #1 \n" + "cmp w12, %w[block_width] \n" + "b.ne 2b \n" + : [src3] "+r"(src3), // %[src3] + [dst2] "+r"(dst2) // %[dst2] + : [src_stride] "r"((ptrdiff_t)src_stride), // %[src_stride] + [dst_stride] "r"((ptrdiff_t)dst_stride), // %[dst_stride] + [block_width] "r"(block_width), // %[block_width] + [block_height] "r"(block_height) // %[block_height] + : "cc", "memory", "p0", "w12", "za"); + + src2 += vl; + width2 -= vl; + } while (width2 > 0); + + src += vl * src_stride; + dst += vl; + height -= vl; + } while (height > 0); +} + +__arm_locally_streaming __arm_new("za") void TransposeUVWxH_SME( + const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width, + int height) { + int vl; + asm("cnth %x0" : "=r"(vl)); + + do { + const uint8_t* src2 = src; + uint8_t* dst2_a = dst_a; + uint8_t* dst2_b = dst_b; + + // Process up to VL bytes per iteration of the inner loop. + int block_height = height > vl * 2 ? vl * 2 : height; + + int width2 = width; + do { + const uint8_t* src3 = src2; + + // Process up to VL 16-bit elements per iteration of the inner loop. + int block_width = width2 > vl ? vl : width2; + + asm volatile( + "mov w12, #0 \n" + + // Create a predicate to handle loading partial rows, + // %[block_width] is always a multiple of two here. + "whilelt p0.b, wzr, %w[block_width] \n" + + // Load H <= VL rows into ZA0, such that U/V components exist in + // alternating columns. + "1: \n" + "ld1b {za0h.b[w12, 0]}, p0/z, [%[src]] \n" + "add %[src], %[src], %[src_stride] \n" + "add w12, w12, #1 \n" + "cmp w12, %w[block_height] \n" + "b.ne 1b \n" + + // Create a predicate to handle storing partial columns. + "whilelt p0.b, wzr, %w[block_height] \n" + "mov w12, #0 \n" + + // Store alternating UV data from pairs of ZA0 columns. + "2: \n" + "st1b {za0v.b[w12, 0]}, p0, [%[dst_a]] \n" + "st1b {za0v.b[w12, 1]}, p0, [%[dst_b]] \n" + "add %[dst_a], %[dst_a], %[dst_stride_a] \n" + "add %[dst_b], %[dst_b], %[dst_stride_b] \n" + "add w12, w12, #2 \n" + "cmp w12, %w[block_width] \n" + "b.ne 2b \n" + : [src] "+r"(src3), // %[src] + [dst_a] "+r"(dst2_a), // %[dst_a] + [dst_b] "+r"(dst2_b) // %[dst_b] + : [src_stride] "r"((ptrdiff_t)src_stride), // %[src_stride] + [dst_stride_a] "r"((ptrdiff_t)dst_stride_a), // %[dst_stride_a] + [dst_stride_b] "r"((ptrdiff_t)dst_stride_b), // %[dst_stride_b] + [block_width] "r"(block_width * 2), // %[block_width] + [block_height] "r"(block_height) // %[block_height] + : "cc", "memory", "p0", "w12", "za"); + + src2 += 2 * vl; + width2 -= vl; + } while (width2 > 0); + + src += 2 * vl * src_stride; + dst_a += 2 * vl; + dst_b += 2 * vl; + height -= 2 * vl; + } while (height > 0); +} + +__arm_locally_streaming __arm_new("za") void TransposeWxH_32_SME( + const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height) { + int vl; + asm("cntw %x0" : "=r"(vl)); + + do { + const uint8_t* src2 = src; + uint8_t* dst2 = dst; + + // Process up to VL 32-bit rows per iteration of the outer loop. + int block_height = height > vl ? vl : height; + + int width2 = width; + do { + const uint8_t* src3 = src2; + + // Process up to VL 32-bit columns per iteration of the inner loop. + int block_width = width2 > vl ? vl : width2; + + asm volatile( + "mov w12, #0 \n" + + // Create a predicate to handle loading partial rows. + "whilelt p0.s, wzr, %w[block_width] \n" + + // Load H <= VL rows into ZA0.S. + "1: \n" + "ld1w {za0h.s[w12, 0]}, p0/z, [%[src3]] \n" + "add %[src3], %[src3], %[src_stride] \n" + "add w12, w12, #1 \n" + "cmp w12, %w[block_height] \n" + "b.ne 1b \n" + + // Create a predicate to handle storing partial columns. + "whilelt p0.s, wzr, %w[block_height] \n" + "mov w12, #0 \n" + + // Store W <= VL columns from ZA0.S. + "2: \n" + "st1w {za0v.s[w12, 0]}, p0, [%[dst2]] \n" + "add %[dst2], %[dst2], %[dst_stride] \n" + "add w12, w12, #1 \n" + "cmp w12, %w[block_width] \n" + "b.ne 2b \n" + : [src3] "+r"(src3), // %[src3] + [dst2] "+r"(dst2) // %[dst2] + : [src_stride] "r"((ptrdiff_t)src_stride), // %[src_stride] + [dst_stride] "r"((ptrdiff_t)dst_stride), // %[dst_stride] + [block_width] "r"(block_width), // %[block_width] + [block_height] "r"(block_height) // %[block_height] + : "cc", "memory", "p0", "w12", "za"); + + src2 += vl * 4; + width2 -= vl; + } while (width2 > 0); + + src += (ptrdiff_t)vl * src_stride; + dst += vl * 4; + height -= vl; + } while (height > 0); +} + +__arm_locally_streaming __arm_new("za") void TransposeWxH_16_SME( + const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width, + int height) { + int vl; + asm("cnth %x0" : "=r"(vl)); + + do { + const uint16_t* src2 = src; + uint16_t* dst2 = dst; + + // Process up to VL 16-bit rows per iteration of the outer loop. + int block_height = height > vl ? vl : height; + + int width2 = width; + do { + const uint16_t* src3 = src2; + + // Process up to VL 16-bit columns per iteration of the inner loop. + int block_width = width2 > vl ? vl : width2; + + asm volatile( + "mov w12, #0 \n" + + // Create a predicate to handle loading partial rows. + "whilelt p0.h, wzr, %w[block_width] \n" + + // Load H <= VL rows into ZA0.H. + "1: \n" + "ld1h {za0h.h[w12, 0]}, p0/z, [%[src3]] \n" + "add %[src3], %[src3], %[src_stride] \n" + "add w12, w12, #1 \n" + "cmp w12, %w[block_height] \n" + "b.ne 1b \n" + + // Create a predicate to handle storing partial columns. + "whilelt p0.h, wzr, %w[block_height] \n" + "mov w12, #0 \n" + + // Store W <= VL columns from ZA0.H. + "2: \n" + "st1h {za0v.h[w12, 0]}, p0, [%[dst2]] \n" + "add %[dst2], %[dst2], %[dst_stride] \n" + "add w12, w12, #1 \n" + "cmp w12, %w[block_width] \n" + "b.ne 2b \n" + : [src3] "+r"(src3), // %[src3] + [dst2] "+r"(dst2) // %[dst2] + : [src_stride] "r"((ptrdiff_t)src_stride * 2), // %[src_stride] + [dst_stride] "r"((ptrdiff_t)dst_stride * 2), // %[dst_stride] + [block_width] "r"(block_width), // %[block_width] + [block_height] "r"(block_height) // %[block_height] + : "memory", "cc", "w12", "p0", "za"); + + src2 += vl; + width2 -= vl; + } while (width2 > 0); + + src += (ptrdiff_t)vl * src_stride; + dst += vl; + height -= vl; + } while (height > 0); +} + +#endif // !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && + // defined(__aarch64__) + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif diff --git a/libs/libyuv/source/rotate_sve.cc b/libs/libyuv/source/rotate_sve.cc new file mode 100644 index 0000000000..f7dc3c14dd --- /dev/null +++ b/libs/libyuv/source/rotate_sve.cc @@ -0,0 +1,279 @@ +/* + * Copyright 2026 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/rotate_row.h" +#include "libyuv/row.h" + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +#if !defined(LIBYUV_DISABLE_SVE) && defined(__aarch64__) + +// Transpose 32 bit values (ARGB) in Wx4 tiles using SVE2 with predication +// for tail widths. +void TransposeWx4_32_SVE2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t s4 = s * 4; + const ptrdiff_t d = dst_stride; + const uint8_t* src1 = src + s; + const uint8_t* src2 = src1 + s; + const uint8_t* src3 = src2 + s; + uint8_t* dst1 = dst + d; + uint8_t* dst2 = dst1 + d; + uint8_t* dst3 = dst2 + d; + asm volatile( + "ptrue p0.s, vl4 \n" + "subs %w[width], %w[width], #4 \n" + "b.lt 2f \n" + + // Main loop: full 4x4 blocks. + "1: \n" + "ld1w {z0.s}, p0/z, [%[src0]] \n" + "ld1w {z1.s}, p0/z, [%[src1]] \n" + "ld1w {z2.s}, p0/z, [%[src2]] \n" + "ld1w {z3.s}, p0/z, [%[src3]] \n" + "add %[src0], %[src0], %[s4] \n" + "add %[src1], %[src1], %[s4] \n" + "add %[src2], %[src2], %[s4] \n" + "add %[src3], %[src3], %[s4] \n" + "trn1 z4.s, z0.s, z1.s \n" + "trn2 z5.s, z0.s, z1.s \n" + "trn1 z6.s, z2.s, z3.s \n" + "trn2 z7.s, z2.s, z3.s \n" + "trn1 z0.d, z4.d, z6.d \n" // column 0 + "trn1 z1.d, z5.d, z7.d \n" // column 1 + "trn2 z2.d, z4.d, z6.d \n" // column 2 + "trn2 z3.d, z5.d, z7.d \n" // column 3 + "subs %w[width], %w[width], #4 \n" + "st1w {z0.s}, p0, [%[dst0]] \n" + "st1w {z1.s}, p0, [%[dst1]] \n" + "st1w {z2.s}, p0, [%[dst2]] \n" + "st1w {z3.s}, p0, [%[dst3]] \n" + "add %[dst0], %[dst0], #16 \n" + "add %[dst1], %[dst1], #16 \n" + "add %[dst2], %[dst2], #16 \n" + "add %[dst3], %[dst3], #16 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], #4 \n" + "b.eq 3f \n" + + // Tail loop: 1..3 remaining source rows / destination columns. + "cmp %w[width], #1 \n" + "csel %[src1], %[src0], %[src1], eq \n" + "cmp %w[width], #2 \n" + "csel %[src2], %[src1], %[src2], le \n" + "mov %[src3], %[src2] \n" + "ld1w {z0.s}, p0/z, [%[src0]] \n" + "ld1w {z1.s}, p0/z, [%[src1]] \n" + "ld1w {z2.s}, p0/z, [%[src2]] \n" + "ld1w {z3.s}, p0/z, [%[src3]] \n" + "trn1 z4.s, z0.s, z1.s \n" + "trn2 z5.s, z0.s, z1.s \n" + "trn1 z6.s, z2.s, z3.s \n" + "trn2 z7.s, z2.s, z3.s \n" + "trn1 z0.d, z4.d, z6.d \n" // column 0 + "trn1 z1.d, z5.d, z7.d \n" // column 1 + "trn2 z2.d, z4.d, z6.d \n" // column 2 + "trn2 z3.d, z5.d, z7.d \n" // column 3 + "whilelt p0.s, wzr, %w[width] \n" + "st1w {z0.s}, p0, [%[dst0]] \n" + "st1w {z1.s}, p0, [%[dst1]] \n" + "st1w {z2.s}, p0, [%[dst2]] \n" + "st1w {z3.s}, p0, [%[dst3]] \n" + "3: \n" + : [src0] "+r"(src), // %[src0] + [src1] "+r"(src1), // %[src1] + [src2] "+r"(src2), // %[src2] + [src3] "+r"(src3), // %[src3] + [dst0] "+r"(dst), // %[dst0] + [dst1] "+r"(dst1), // %[dst1] + [dst2] "+r"(dst2), // %[dst2] + [dst3] "+r"(dst3), // %[dst3] + [width] "+r"(width) // %[width] + : [s4] "r"(s4) // %[s4] + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "p0"); +} + +void TransposeWx8_16_SVE2(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = (ptrdiff_t)src_stride * 2; + const ptrdiff_t d = (ptrdiff_t)dst_stride * 2; + const uint16_t* temp; + asm volatile( + "ptrue p0.h, vl8 \n" + "subs %w[w], %w[w], #8 \n" + "b.lt 2f \n" + + "1: \n" + "mov %[temp], %[src] \n" + "ld1h {z0.h}, p0/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z1.h}, p0/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z2.h}, p0/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z3.h}, p0/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z4.h}, p0/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z5.h}, p0/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z6.h}, p0/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z7.h}, p0/z, [%[temp]] \n" + "add %[src], %[src], #16 \n" + + "trn1 z16.h, z0.h, z1.h \n" + "trn2 z17.h, z0.h, z1.h \n" + "trn1 z18.h, z2.h, z3.h \n" + "trn2 z19.h, z2.h, z3.h \n" + "trn1 z20.h, z4.h, z5.h \n" + "trn2 z21.h, z4.h, z5.h \n" + "trn1 z22.h, z6.h, z7.h \n" + "trn2 z23.h, z6.h, z7.h \n" + + "trn1 z0.s, z16.s, z18.s \n" + "trn1 z1.s, z17.s, z19.s \n" + "trn2 z2.s, z16.s, z18.s \n" + "trn2 z3.s, z17.s, z19.s \n" + "trn1 z4.s, z20.s, z22.s \n" + "trn1 z5.s, z21.s, z23.s \n" + "trn2 z6.s, z20.s, z22.s \n" + "trn2 z7.s, z21.s, z23.s \n" + + "trn1 z16.d, z0.d, z4.d \n" + "trn1 z17.d, z1.d, z5.d \n" + "trn1 z18.d, z2.d, z6.d \n" + "trn1 z19.d, z3.d, z7.d \n" + "trn2 z20.d, z0.d, z4.d \n" + "trn2 z21.d, z1.d, z5.d \n" + "trn2 z22.d, z2.d, z6.d \n" + "trn2 z23.d, z3.d, z7.d \n" + + "st1h {z16.h}, p0, [%[dst]] \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z17.h}, p0, [%[dst]] \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z18.h}, p0, [%[dst]] \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z19.h}, p0, [%[dst]] \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z20.h}, p0, [%[dst]] \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z21.h}, p0, [%[dst]] \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z22.h}, p0, [%[dst]] \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z23.h}, p0, [%[dst]] \n" + "add %[dst], %[dst], %[d] \n" + "subs %w[w], %w[w], #8 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[w], %w[w], #8 \n" + "b.eq 3f \n" + "whilelt p1.h, wzr, %w[w] \n" + "mov %[temp], %[src] \n" + "ld1h {z0.h}, p1/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z1.h}, p1/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z2.h}, p1/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z3.h}, p1/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z4.h}, p1/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z5.h}, p1/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z6.h}, p1/z, [%[temp]] \n" + "add %[temp], %[temp], %[s] \n" + "ld1h {z7.h}, p1/z, [%[temp]] \n" + + "trn1 z16.h, z0.h, z1.h \n" + "trn2 z17.h, z0.h, z1.h \n" + "trn1 z18.h, z2.h, z3.h \n" + "trn2 z19.h, z2.h, z3.h \n" + "trn1 z20.h, z4.h, z5.h \n" + "trn2 z21.h, z4.h, z5.h \n" + "trn1 z22.h, z6.h, z7.h \n" + "trn2 z23.h, z6.h, z7.h \n" + + "trn1 z0.s, z16.s, z18.s \n" + "trn1 z1.s, z17.s, z19.s \n" + "trn2 z2.s, z16.s, z18.s \n" + "trn2 z3.s, z17.s, z19.s \n" + "trn1 z4.s, z20.s, z22.s \n" + "trn1 z5.s, z21.s, z23.s \n" + "trn2 z6.s, z20.s, z22.s \n" + "trn2 z7.s, z21.s, z23.s \n" + + "trn1 z16.d, z0.d, z4.d \n" + "trn1 z17.d, z1.d, z5.d \n" + "trn1 z18.d, z2.d, z6.d \n" + "trn1 z19.d, z3.d, z7.d \n" + "trn2 z20.d, z0.d, z4.d \n" + "trn2 z21.d, z1.d, z5.d \n" + "trn2 z22.d, z2.d, z6.d \n" + "trn2 z23.d, z3.d, z7.d \n" + + "st1h {z16.h}, p0, [%[dst]] \n" + "subs %w[w], %w[w], #1 \n" + "b.eq 3f \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z17.h}, p0, [%[dst]] \n" + "subs %w[w], %w[w], #1 \n" + "b.eq 3f \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z18.h}, p0, [%[dst]] \n" + "subs %w[w], %w[w], #1 \n" + "b.eq 3f \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z19.h}, p0, [%[dst]] \n" + "subs %w[w], %w[w], #1 \n" + "b.eq 3f \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z20.h}, p0, [%[dst]] \n" + "subs %w[w], %w[w], #1 \n" + "b.eq 3f \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z21.h}, p0, [%[dst]] \n" + "subs %w[w], %w[w], #1 \n" + "b.eq 3f \n" + "add %[dst], %[dst], %[d] \n" + "st1h {z22.h}, p0, [%[dst]] \n" + "3: \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [w] "+r"(width), // %[w] + [temp] "=&r"(temp) // %[temp] + : [s] "r"(s), // %[s] + [d] "r"(d) // %[d] + : "memory", "cc", "p0", "p1", "z0", "z1", "z2", "z3", "z4", "z5", "z6", + "z7", "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23"); +} + +#endif // !defined(LIBYUV_DISABLE_SVE) && defined(__aarch64__) + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif diff --git a/libs/libyuv/source/rotate_wasm.cc b/libs/libyuv/source/rotate_wasm.cc new file mode 100644 index 0000000000..5a8adc95d2 --- /dev/null +++ b/libs/libyuv/source/rotate_wasm.cc @@ -0,0 +1,328 @@ +/* + * Copyright 2026 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/rotate_row.h" +#include "libyuv/row.h" + +#if !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) +#include + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// Interleave the low or high halves of 2 vectors as 8, 16, 32 or 64 bit +// elements. These map to punpck on x86 and zip on Arm. +#define ZIPLO8(a, b) \ + wasm_i8x16_shuffle(a, b, 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, \ + 23) +#define ZIPHI8(a, b) \ + wasm_i8x16_shuffle(a, b, 8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, \ + 30, 15, 31) +#define ZIPLO16(a, b) wasm_i16x8_shuffle(a, b, 0, 8, 1, 9, 2, 10, 3, 11) +#define ZIPHI16(a, b) wasm_i16x8_shuffle(a, b, 4, 12, 5, 13, 6, 14, 7, 15) +#define ZIPLO32(a, b) wasm_i32x4_shuffle(a, b, 0, 4, 1, 5) +#define ZIPHI32(a, b) wasm_i32x4_shuffle(a, b, 2, 6, 3, 7) +#define ZIPLO64(a, b) wasm_i64x2_shuffle(a, b, 0, 2) +#define ZIPHI64(a, b) wasm_i64x2_shuffle(a, b, 1, 3) + +// Transpose 8 rows x 16 bytes. c[m] holds columns 2m and 2m + 1 of the 8 rows +// in its low and high 8 bytes. +static inline void Transpose8x16_WASMSIMD(const uint8_t* src, + ptrdiff_t s, + v128_t* c) { + v128_t r0 = wasm_v128_load(src); + v128_t r1 = wasm_v128_load(src + s); + v128_t r2 = wasm_v128_load(src + s * 2); + v128_t r3 = wasm_v128_load(src + s * 3); + v128_t r4 = wasm_v128_load(src + s * 4); + v128_t r5 = wasm_v128_load(src + s * 5); + v128_t r6 = wasm_v128_load(src + s * 6); + v128_t r7 = wasm_v128_load(src + s * 7); + + // Bytes of row pairs. a0 is columns 0..7 of rows 0, 1. + v128_t a0 = ZIPLO8(r0, r1); + v128_t a1 = ZIPHI8(r0, r1); + v128_t a2 = ZIPLO8(r2, r3); + v128_t a3 = ZIPHI8(r2, r3); + v128_t a4 = ZIPLO8(r4, r5); + v128_t a5 = ZIPHI8(r4, r5); + v128_t a6 = ZIPLO8(r6, r7); + v128_t a7 = ZIPHI8(r6, r7); + + // Words. b0 is columns 0..3 of rows 0..3. + v128_t b0 = ZIPLO16(a0, a2); + v128_t b1 = ZIPHI16(a0, a2); + v128_t b2 = ZIPLO16(a1, a3); + v128_t b3 = ZIPHI16(a1, a3); + v128_t b4 = ZIPLO16(a4, a6); + v128_t b5 = ZIPHI16(a4, a6); + v128_t b6 = ZIPLO16(a5, a7); + v128_t b7 = ZIPHI16(a5, a7); + + // Dwords. c0 is columns 0, 1 of rows 0..7. + c[0] = ZIPLO32(b0, b4); + c[1] = ZIPHI32(b0, b4); + c[2] = ZIPLO32(b1, b5); + c[3] = ZIPHI32(b1, b5); + c[4] = ZIPLO32(b2, b6); + c[5] = ZIPHI32(b2, b6); + c[6] = ZIPLO32(b3, b7); + c[7] = ZIPHI32(b3, b7); +} + +#if defined(HAS_TRANSPOSEWX8_WASMSIMD) || defined(HAS_TRANSPOSEUVWX8_WASMSIMD) +// Transpose 8 rows x 16 bytes. Even columns go to dst_a and odd columns go to +// dst_b. Width is a multiple of 16 bytes. +static void TransposeWx8_Byte_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int byte_width) { + const ptrdiff_t sa = dst_stride_a; + const ptrdiff_t sb = dst_stride_b; + while (byte_width > 0) { + v128_t c[8]; + int m; + Transpose8x16_WASMSIMD(src, src_stride, c); + for (m = 0; m < 8; ++m) { + wasm_v128_store64_lane(dst_a + sa * m, c[m], 0); + wasm_v128_store64_lane(dst_b + sb * m, c[m], 1); + } + src += 16; + dst_a += sa * 8; + dst_b += sb * 8; + byte_width -= 16; + } +} +#endif // HAS_TRANSPOSEWX8_WASMSIMD || HAS_TRANSPOSEUVWX8_WASMSIMD + +#if defined(HAS_TRANSPOSEWX8_WASMSIMD) +// Transpose 16x8. Width is a multiple of 16. +void TransposeWx8_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + TransposeWx8_Byte_WASMSIMD(src, src_stride, dst, dst_stride * 2, + dst + dst_stride, dst_stride * 2, width); +} +#endif // HAS_TRANSPOSEWX8_WASMSIMD + +#if defined(HAS_TRANSPOSEUVWX8_WASMSIMD) +// Transpose UV 8x8. Width is a multiple of 8. +void TransposeUVWx8_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width) { + TransposeWx8_Byte_WASMSIMD(src, src_stride, dst_a, dst_stride_a, dst_b, + dst_stride_b, width * 2); +} +#endif // HAS_TRANSPOSEUVWX8_WASMSIMD + +#if defined(HAS_TRANSPOSEWX16_WASMSIMD) || defined(HAS_TRANSPOSEUVWX16_WASMSIMD) +// Transpose 16 rows x 16 bytes as 2 halves of 8 rows, which are joined with +// 64 bit interleaves to store full 16 byte rows. Even columns go to dst_a and +// odd columns go to dst_b. Width is a multiple of 16 bytes. +static void TransposeWx16_Byte_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int byte_width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t sa = dst_stride_a; + const ptrdiff_t sb = dst_stride_b; + while (byte_width > 0) { + v128_t lo[8]; + v128_t hi[8]; + int m; + Transpose8x16_WASMSIMD(src, s, lo); + Transpose8x16_WASMSIMD(src + s * 8, s, hi); + for (m = 0; m < 8; ++m) { + wasm_v128_store(dst_a + sa * m, ZIPLO64(lo[m], hi[m])); + wasm_v128_store(dst_b + sb * m, ZIPHI64(lo[m], hi[m])); + } + src += 16; + dst_a += sa * 8; + dst_b += sb * 8; + byte_width -= 16; + } +} +#endif // HAS_TRANSPOSEWX16_WASMSIMD || HAS_TRANSPOSEUVWX16_WASMSIMD + +#if defined(HAS_TRANSPOSEWX16_WASMSIMD) +// Transpose 16x16. Width is a multiple of 16. +void TransposeWx16_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + TransposeWx16_Byte_WASMSIMD(src, src_stride, dst, dst_stride * 2, + dst + dst_stride, dst_stride * 2, width); +} +#endif // HAS_TRANSPOSEWX16_WASMSIMD + +#if defined(HAS_TRANSPOSEUVWX16_WASMSIMD) +// Transpose UV 8x16. Width is a multiple of 8. +void TransposeUVWx16_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width) { + TransposeWx16_Byte_WASMSIMD(src, src_stride, dst_a, dst_stride_a, dst_b, + dst_stride_b, width * 2); +} +#endif // HAS_TRANSPOSEUVWX16_WASMSIMD + +#if defined(HAS_TRANSPOSEWX4_32_WASMSIMD) +// Transpose 32 bit values (ARGB) in Wx4 tiles, moving down 4 rows of source +// and across 4 columns of destination. Width is a multiple of 4. +void TransposeWx4_32_WASMSIMD(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + uint8_t* dst1 = dst + d; + uint8_t* dst2 = dst1 + d; + uint8_t* dst3 = dst2 + d; + while (width >= 8) { + v128_t r0 = wasm_v128_load(src); + v128_t r1 = wasm_v128_load(src + s); + v128_t r2 = wasm_v128_load(src + s * 2); + v128_t r3 = wasm_v128_load(src + s * 3); + src += s * 4; + v128_t r4 = wasm_v128_load(src); + v128_t r5 = wasm_v128_load(src + s); + v128_t r6 = wasm_v128_load(src + s * 2); + v128_t r7 = wasm_v128_load(src + s * 3); + src += s * 4; + v128_t a0 = ZIPLO32(r0, r1); + v128_t a1 = ZIPHI32(r0, r1); + v128_t a2 = ZIPLO32(r2, r3); + v128_t a3 = ZIPHI32(r2, r3); + v128_t b0 = ZIPLO32(r4, r5); + v128_t b1 = ZIPHI32(r4, r5); + v128_t b2 = ZIPLO32(r6, r7); + v128_t b3 = ZIPHI32(r6, r7); + wasm_v128_store(dst, ZIPLO64(a0, a2)); + wasm_v128_store(dst1, ZIPHI64(a0, a2)); + wasm_v128_store(dst2, ZIPLO64(a1, a3)); + wasm_v128_store(dst3, ZIPHI64(a1, a3)); + wasm_v128_store(dst + 16, ZIPLO64(b0, b2)); + wasm_v128_store(dst1 + 16, ZIPHI64(b0, b2)); + wasm_v128_store(dst2 + 16, ZIPLO64(b1, b3)); + wasm_v128_store(dst3 + 16, ZIPHI64(b1, b3)); + dst += 32; + dst1 += 32; + dst2 += 32; + dst3 += 32; + width -= 8; + } + while (width > 0) { + v128_t r0 = wasm_v128_load(src); + v128_t r1 = wasm_v128_load(src + s); + v128_t r2 = wasm_v128_load(src + s * 2); + v128_t r3 = wasm_v128_load(src + s * 3); + v128_t a0 = ZIPLO32(r0, r1); + v128_t a1 = ZIPHI32(r0, r1); + v128_t a2 = ZIPLO32(r2, r3); + v128_t a3 = ZIPHI32(r2, r3); + wasm_v128_store(dst, ZIPLO64(a0, a2)); + wasm_v128_store(dst1, ZIPHI64(a0, a2)); + wasm_v128_store(dst2, ZIPLO64(a1, a3)); + wasm_v128_store(dst3, ZIPHI64(a1, a3)); + src += s * 4; + dst += 16; + dst1 += 16; + dst2 += 16; + dst3 += 16; + width -= 4; + } +} +#endif // HAS_TRANSPOSEWX4_32_WASMSIMD + +#if defined(HAS_TRANSPOSEWX8_16_WASMSIMD) +void TransposeWx8_16_WASMSIMD(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + while (width > 0) { + v128_t r0 = wasm_v128_load(src); + v128_t r1 = wasm_v128_load(src + s); + v128_t r2 = wasm_v128_load(src + s * 2); + v128_t r3 = wasm_v128_load(src + s * 3); + v128_t r4 = wasm_v128_load(src + s * 4); + v128_t r5 = wasm_v128_load(src + s * 5); + v128_t r6 = wasm_v128_load(src + s * 6); + v128_t r7 = wasm_v128_load(src + s * 7); + + v128_t t0 = ZIPLO16(r0, r1); + v128_t t1 = ZIPHI16(r0, r1); + v128_t t2 = ZIPLO16(r2, r3); + v128_t t3 = ZIPHI16(r2, r3); + v128_t t4 = ZIPLO16(r4, r5); + v128_t t5 = ZIPHI16(r4, r5); + v128_t t6 = ZIPLO16(r6, r7); + v128_t t7 = ZIPHI16(r6, r7); + + v128_t u0 = ZIPLO32(t0, t2); + v128_t u1 = ZIPHI32(t0, t2); + v128_t u2 = ZIPLO32(t1, t3); + v128_t u3 = ZIPHI32(t1, t3); + v128_t u4 = ZIPLO32(t4, t6); + v128_t u5 = ZIPHI32(t4, t6); + v128_t u6 = ZIPLO32(t5, t7); + v128_t u7 = ZIPHI32(t5, t7); + + wasm_v128_store(dst, ZIPLO64(u0, u4)); + wasm_v128_store(dst + d, ZIPHI64(u0, u4)); + wasm_v128_store(dst + d * 2, ZIPLO64(u1, u5)); + wasm_v128_store(dst + d * 3, ZIPHI64(u1, u5)); + wasm_v128_store(dst + d * 4, ZIPLO64(u2, u6)); + wasm_v128_store(dst + d * 5, ZIPHI64(u2, u6)); + wasm_v128_store(dst + d * 6, ZIPLO64(u3, u7)); + wasm_v128_store(dst + d * 7, ZIPHI64(u3, u7)); + src += 8; + dst += d * 8; + width -= 8; + } +} +#endif // HAS_TRANSPOSEWX8_16_WASMSIMD + +#undef ZIPLO8 +#undef ZIPHI8 +#undef ZIPLO16 +#undef ZIPHI16 +#undef ZIPLO32 +#undef ZIPHI32 +#undef ZIPLO64 +#undef ZIPHI64 + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) diff --git a/libs/libyuv/source/rotate_win.cc b/libs/libyuv/source/rotate_win.cc index e887dd525c..d1d48dfea4 100644 --- a/libs/libyuv/source/rotate_win.cc +++ b/libs/libyuv/source/rotate_win.cc @@ -11,242 +11,1205 @@ #include "libyuv/rotate_row.h" #include "libyuv/row.h" +// This module is for Visual C 32/64 bit, and for clang with +// LIBYUV_ENABLE_ROWWIN, which is also enabled for MemorySanitizer. +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || \ + defined(_M_IX86)) && \ + ((defined(_MSC_VER) && !defined(__clang__)) || \ + defined(LIBYUV_ENABLE_ROWWIN)) + +#include +#include // For AVX2 and AVX512 intrinsics +#include +#if defined(_MSC_VER) && !defined(__clang__) +#include +#endif + #ifdef __cplusplus namespace libyuv { extern "C" { #endif -// This module is for 32 bit Visual C x86 and clangcl -#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) +// Target attributes allow gcc and clang to build each function for its +// instruction set regardless of the baseline, which may lack SSE2 for 32 bit. +#if defined(__clang__) || defined(__GNUC__) +#define LIBYUV_TARGET_AVX2 __attribute__((target("avx2"))) +#define LIBYUV_TARGET_AVX512BW \ + __attribute__((target("avx512bw,avx512vl,avx512f"))) +#else +#define LIBYUV_TARGET_AVX2 +#define LIBYUV_TARGET_AVX512BW +#endif // defined(__clang__) || defined(__GNUC__) -__declspec(naked) void TransposeWx8_SSSE3(const uint8_t* src, - int src_stride, - uint8_t* dst, - int dst_stride, - int width) { - __asm { - push edi - push esi - push ebp - mov eax, [esp + 12 + 4] // src - mov edi, [esp + 12 + 8] // src_stride - mov edx, [esp + 12 + 12] // dst - mov esi, [esp + 12 + 16] // dst_stride - mov ecx, [esp + 12 + 20] // width +#if defined(HAS_TRANSPOSEWX8_AVX2) || defined(HAS_TRANSPOSEUVWX8_AVX2) +// Transpose 8 rows x 16 bytes using 2 lanes of AVX2. Source row r is in +// lane r / 4 of register r % 4. Each 128-bit output lane holds 2 columns x 8 +// rows: low 8 bytes (even column) for dst_a and high 8 bytes (odd column) for +// dst_b. Width is a multiple of 16 bytes. +LIBYUV_TARGET_AVX2 +static void TransposeWx8_Byte_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int byte_width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t sa = dst_stride_a; + const ptrdiff_t sb = dst_stride_b; + while (byte_width > 0) { + __m256i r0 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src))), + _mm_loadu_si128((const __m128i*)(src + s * 4)), 1); + __m256i r1 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s))), + _mm_loadu_si128((const __m128i*)(src + s * 5)), 1); + __m256i r2 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 2))), + _mm_loadu_si128((const __m128i*)(src + s * 6)), 1); + __m256i r3 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 3))), + _mm_loadu_si128((const __m128i*)(src + s * 7)), 1); - // Read in the data from the source pointer. - // First round of bit swap. - align 4 - convertloop: - movq xmm0, qword ptr [eax] - lea ebp, [eax + 8] - movq xmm1, qword ptr [eax + edi] - lea eax, [eax + 2 * edi] - punpcklbw xmm0, xmm1 - movq xmm2, qword ptr [eax] - movdqa xmm1, xmm0 - palignr xmm1, xmm1, 8 - movq xmm3, qword ptr [eax + edi] - lea eax, [eax + 2 * edi] - punpcklbw xmm2, xmm3 - movdqa xmm3, xmm2 - movq xmm4, qword ptr [eax] - palignr xmm3, xmm3, 8 - movq xmm5, qword ptr [eax + edi] - punpcklbw xmm4, xmm5 - lea eax, [eax + 2 * edi] - movdqa xmm5, xmm4 - movq xmm6, qword ptr [eax] - palignr xmm5, xmm5, 8 - movq xmm7, qword ptr [eax + edi] - punpcklbw xmm6, xmm7 - mov eax, ebp - movdqa xmm7, xmm6 - palignr xmm7, xmm7, 8 - // Second round of bit swap. - punpcklwd xmm0, xmm2 - punpcklwd xmm1, xmm3 - movdqa xmm2, xmm0 - movdqa xmm3, xmm1 - palignr xmm2, xmm2, 8 - palignr xmm3, xmm3, 8 - punpcklwd xmm4, xmm6 - punpcklwd xmm5, xmm7 - movdqa xmm6, xmm4 - movdqa xmm7, xmm5 - palignr xmm6, xmm6, 8 - palignr xmm7, xmm7, 8 - // Third round of bit swap. - // Write to the destination pointer. - punpckldq xmm0, xmm4 - movq qword ptr [edx], xmm0 - movdqa xmm4, xmm0 - palignr xmm4, xmm4, 8 - movq qword ptr [edx + esi], xmm4 - lea edx, [edx + 2 * esi] - punpckldq xmm2, xmm6 - movdqa xmm6, xmm2 - palignr xmm6, xmm6, 8 - movq qword ptr [edx], xmm2 - punpckldq xmm1, xmm5 - movq qword ptr [edx + esi], xmm6 - lea edx, [edx + 2 * esi] - movdqa xmm5, xmm1 - movq qword ptr [edx], xmm1 - palignr xmm5, xmm5, 8 - punpckldq xmm3, xmm7 - movq qword ptr [edx + esi], xmm5 - lea edx, [edx + 2 * esi] - movq qword ptr [edx], xmm3 - movdqa xmm7, xmm3 - palignr xmm7, xmm7, 8 - sub ecx, 8 - movq qword ptr [edx + esi], xmm7 - lea edx, [edx + 2 * esi] - jg convertloop + __m256i a0 = _mm256_unpacklo_epi8(r0, r1); + __m256i a1 = _mm256_unpackhi_epi8(r0, r1); + __m256i a2 = _mm256_unpacklo_epi8(r2, r3); + __m256i a3 = _mm256_unpackhi_epi8(r2, r3); - pop ebp - pop esi - pop edi - ret + __m256i b0 = _mm256_unpacklo_epi16(a0, a2); + __m256i b1 = _mm256_unpackhi_epi16(a0, a2); + __m256i b2 = _mm256_unpacklo_epi16(a1, a3); + __m256i b3 = _mm256_unpackhi_epi16(a1, a3); + + __m256i t0 = _mm256_permute2x128_si256(b0, b1, 0x20); + __m256i t1 = _mm256_permute2x128_si256(b0, b1, 0x31); + __m256i t2 = _mm256_permute2x128_si256(b2, b3, 0x20); + __m256i t3 = _mm256_permute2x128_si256(b2, b3, 0x31); + + __m256i c0 = _mm256_unpacklo_epi32(t0, t1); + __m256i c1 = _mm256_unpackhi_epi32(t0, t1); + __m256i c2 = _mm256_unpacklo_epi32(t2, t3); + __m256i c3 = _mm256_unpackhi_epi32(t2, t3); + + __m128i lo0 = _mm256_castsi256_si128(c0); + __m128i lo1 = _mm256_castsi256_si128(c1); + __m128i hi0 = _mm256_extracti128_si256(c0, 1); + __m128i hi1 = _mm256_extracti128_si256(c1, 1); + __m128i lo2 = _mm256_castsi256_si128(c2); + __m128i lo3 = _mm256_castsi256_si128(c3); + __m128i hi2 = _mm256_extracti128_si256(c2, 1); + __m128i hi3 = _mm256_extracti128_si256(c3, 1); + + _mm_storel_epi64((__m128i*)(dst_a), lo0); + _mm_storeh_pd((double*)(dst_b), _mm_castsi128_pd(lo0)); + _mm_storel_epi64((__m128i*)(dst_a + sa), lo1); + _mm_storeh_pd((double*)(dst_b + sb), _mm_castsi128_pd(lo1)); + _mm_storel_epi64((__m128i*)(dst_a + sa * 2), hi0); + _mm_storeh_pd((double*)(dst_b + sb * 2), _mm_castsi128_pd(hi0)); + _mm_storel_epi64((__m128i*)(dst_a + sa * 3), hi1); + _mm_storeh_pd((double*)(dst_b + sb * 3), _mm_castsi128_pd(hi1)); + _mm_storel_epi64((__m128i*)(dst_a + sa * 4), lo2); + _mm_storeh_pd((double*)(dst_b + sb * 4), _mm_castsi128_pd(lo2)); + _mm_storel_epi64((__m128i*)(dst_a + sa * 5), lo3); + _mm_storeh_pd((double*)(dst_b + sb * 5), _mm_castsi128_pd(lo3)); + _mm_storel_epi64((__m128i*)(dst_a + sa * 6), hi2); + _mm_storeh_pd((double*)(dst_b + sb * 6), _mm_castsi128_pd(hi2)); + _mm_storel_epi64((__m128i*)(dst_a + sa * 7), hi3); + _mm_storeh_pd((double*)(dst_b + sb * 7), _mm_castsi128_pd(hi3)); + + src += 16; + dst_a += sa * 8; + dst_b += sb * 8; + byte_width -= 16; } + _mm256_zeroupper(); +} +#endif // defined(HAS_TRANSPOSEWX8_AVX2) || defined(HAS_TRANSPOSEUVWX8_AVX2) + +#if defined(HAS_TRANSPOSEWX8_AVX2) +// Transpose 16x8. Width is a multiple of 16. +LIBYUV_TARGET_AVX2 +void TransposeWx8_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + TransposeWx8_Byte_AVX2(src, src_stride, dst, dst_stride * 2, dst + dst_stride, + dst_stride * 2, width); +} +#endif // defined(HAS_TRANSPOSEWX8_AVX2) + +#if defined(HAS_TRANSPOSEUVWX8_AVX2) +// Transpose UV 8x8. Width is a multiple of 8. +LIBYUV_TARGET_AVX2 +void TransposeUVWx8_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width) { + TransposeWx8_Byte_AVX2(src, src_stride, dst_a, dst_stride_a, dst_b, + dst_stride_b, width * 2); +} +#endif // defined(HAS_TRANSPOSEUVWX8_AVX2) + +#if defined(HAS_TRANSPOSEWX16_AVX2) || defined(HAS_TRANSPOSEUVWX16_AVX2) +// Load row r into lane 0 and row r + 8 into lane 1. +#define LOAD2ROWS_AVX2(p, s8) \ + _mm256_inserti128_si256( \ + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(p))), \ + _mm_loadu_si128((const __m128i*)((p) + (s8))), 1) + +// Transpose 16x16 bytes using 2 lanes of AVX2. Source row r is in lane r / 8 +// of register r % 8. 3 unpack stages leave each lane with 2 columns x 8 rows, +// and vpermq joins the rows 0..7 and 8..15 halves. Lane 0 of each output is an +// even column for dst_a and lane 1 an odd column for dst_b. +// Width is a multiple of 16 bytes. +LIBYUV_TARGET_AVX2 +static void TransposeWx16_Byte_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int byte_width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t sa = dst_stride_a; + const ptrdiff_t sb = dst_stride_b; + while (byte_width > 0) { + __m256i r0 = LOAD2ROWS_AVX2(src, s * 8); + __m256i r1 = LOAD2ROWS_AVX2(src + s, s * 8); + __m256i r2 = LOAD2ROWS_AVX2(src + s * 2, s * 8); + __m256i r3 = LOAD2ROWS_AVX2(src + s * 3, s * 8); + __m256i r4 = LOAD2ROWS_AVX2(src + s * 4, s * 8); + __m256i r5 = LOAD2ROWS_AVX2(src + s * 5, s * 8); + __m256i r6 = LOAD2ROWS_AVX2(src + s * 6, s * 8); + __m256i r7 = LOAD2ROWS_AVX2(src + s * 7, s * 8); + + __m256i a0 = _mm256_unpacklo_epi8(r0, r1); + __m256i a1 = _mm256_unpackhi_epi8(r0, r1); + __m256i a2 = _mm256_unpacklo_epi8(r2, r3); + __m256i a3 = _mm256_unpackhi_epi8(r2, r3); + __m256i a4 = _mm256_unpacklo_epi8(r4, r5); + __m256i a5 = _mm256_unpackhi_epi8(r4, r5); + __m256i a6 = _mm256_unpacklo_epi8(r6, r7); + __m256i a7 = _mm256_unpackhi_epi8(r6, r7); + + __m256i b0 = _mm256_unpacklo_epi16(a0, a2); + __m256i b1 = _mm256_unpackhi_epi16(a0, a2); + __m256i b2 = _mm256_unpacklo_epi16(a1, a3); + __m256i b3 = _mm256_unpackhi_epi16(a1, a3); + __m256i b4 = _mm256_unpacklo_epi16(a4, a6); + __m256i b5 = _mm256_unpackhi_epi16(a4, a6); + __m256i b6 = _mm256_unpacklo_epi16(a5, a7); + __m256i b7 = _mm256_unpackhi_epi16(a5, a7); + + __m256i c0 = _mm256_permute4x64_epi64(_mm256_unpacklo_epi32(b0, b4), 0xd8); + __m256i c1 = _mm256_permute4x64_epi64(_mm256_unpackhi_epi32(b0, b4), 0xd8); + __m256i c2 = _mm256_permute4x64_epi64(_mm256_unpacklo_epi32(b1, b5), 0xd8); + __m256i c3 = _mm256_permute4x64_epi64(_mm256_unpackhi_epi32(b1, b5), 0xd8); + __m256i c4 = _mm256_permute4x64_epi64(_mm256_unpacklo_epi32(b2, b6), 0xd8); + __m256i c5 = _mm256_permute4x64_epi64(_mm256_unpackhi_epi32(b2, b6), 0xd8); + __m256i c6 = _mm256_permute4x64_epi64(_mm256_unpacklo_epi32(b3, b7), 0xd8); + __m256i c7 = _mm256_permute4x64_epi64(_mm256_unpackhi_epi32(b3, b7), 0xd8); + + _mm_storeu_si128((__m128i*)(dst_a), _mm256_castsi256_si128(c0)); + _mm_storeu_si128((__m128i*)(dst_b), _mm256_extracti128_si256(c0, 1)); + _mm_storeu_si128((__m128i*)(dst_a + sa), _mm256_castsi256_si128(c1)); + _mm_storeu_si128((__m128i*)(dst_b + sb), _mm256_extracti128_si256(c1, 1)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 2), _mm256_castsi256_si128(c2)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 2), + _mm256_extracti128_si256(c2, 1)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 3), _mm256_castsi256_si128(c3)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 3), + _mm256_extracti128_si256(c3, 1)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 4), _mm256_castsi256_si128(c4)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 4), + _mm256_extracti128_si256(c4, 1)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 5), _mm256_castsi256_si128(c5)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 5), + _mm256_extracti128_si256(c5, 1)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 6), _mm256_castsi256_si128(c6)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 6), + _mm256_extracti128_si256(c6, 1)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 7), _mm256_castsi256_si128(c7)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 7), + _mm256_extracti128_si256(c7, 1)); + + src += 16; + dst_a += sa * 8; + dst_b += sb * 8; + byte_width -= 16; + } + _mm256_zeroupper(); +} +#undef LOAD2ROWS_AVX2 +#endif // defined(HAS_TRANSPOSEWX16_AVX2) || defined(HAS_TRANSPOSEUVWX16_AVX2) + +#if defined(HAS_TRANSPOSEWX16_AVX2) +LIBYUV_TARGET_AVX2 +void TransposeWx16_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + TransposeWx16_Byte_AVX2(src, src_stride, dst, dst_stride * 2, + dst + dst_stride, dst_stride * 2, width); +} +#endif // defined(HAS_TRANSPOSEWX16_AVX2) + +#if defined(HAS_TRANSPOSEUVWX16_AVX2) +LIBYUV_TARGET_AVX2 +void TransposeUVWx16_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width) { + TransposeWx16_Byte_AVX2(src, src_stride, dst_a, dst_stride_a, dst_b, + dst_stride_b, width * 2); +} +#endif // defined(HAS_TRANSPOSEUVWX16_AVX2) + +#if defined(HAS_TRANSPOSEWX16_AVX512BW) || defined(HAS_TRANSPOSEUVWX16_AVX512BW) +// Dword permutes to gather 16 rows of a column from 4 lanes. +static const uint32_t kPermdTranspose_AVX512BW[32] = { + 0, 4, 8, 12, 2, 6, 10, 14, 16, 20, 24, 28, 18, 22, 26, 30, + 1, 5, 9, 13, 3, 7, 11, 15, 17, 21, 25, 29, 19, 23, 27, 31}; + +// Load 16 masked bytes from rows p, p + s4, p + s4 * 2, p + s4 * 3 into +// lanes 0..3. +#define LOAD4ROWS_AVX512BW(p, s4, k) \ + _mm512_inserti32x4( \ + _mm512_inserti32x4( \ + _mm512_inserti32x4( \ + _mm512_castsi128_si512(_mm_maskz_loadu_epi8(k, (p))), \ + _mm_maskz_loadu_epi8(k, (p) + (s4)), 1), \ + _mm_maskz_loadu_epi8(k, (p) + (s4) * 2), 2), \ + _mm_maskz_loadu_epi8(k, (p) + (s4) * 3), 3) + +// Store 16 destination rows. Lane n of o0/o2 is for dst_a and lane n of +// o1/o3 is for dst_b. +LIBYUV_TARGET_AVX512BW +static void Store16x16_AVX512BW(__m512i o0, + __m512i o1, + __m512i o2, + __m512i o3, + uint8_t* dst_a, + ptrdiff_t sa, + uint8_t* dst_b, + ptrdiff_t sb) { + _mm_storeu_si128((__m128i*)(dst_a), _mm512_castsi512_si128(o0)); + _mm_storeu_si128((__m128i*)(dst_b), _mm512_castsi512_si128(o1)); + _mm_storeu_si128((__m128i*)(dst_a + sa), _mm512_extracti32x4_epi32(o0, 1)); + _mm_storeu_si128((__m128i*)(dst_b + sb), _mm512_extracti32x4_epi32(o1, 1)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 2), _mm512_castsi512_si128(o2)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 2), _mm512_castsi512_si128(o3)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 3), + _mm512_extracti32x4_epi32(o2, 1)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 3), + _mm512_extracti32x4_epi32(o3, 1)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 4), + _mm512_extracti32x4_epi32(o0, 2)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 4), + _mm512_extracti32x4_epi32(o1, 2)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 5), + _mm512_extracti32x4_epi32(o0, 3)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 5), + _mm512_extracti32x4_epi32(o1, 3)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 6), + _mm512_extracti32x4_epi32(o2, 2)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 6), + _mm512_extracti32x4_epi32(o3, 2)); + _mm_storeu_si128((__m128i*)(dst_a + sa * 7), + _mm512_extracti32x4_epi32(o2, 3)); + _mm_storeu_si128((__m128i*)(dst_b + sb * 7), + _mm512_extracti32x4_epi32(o3, 3)); } -__declspec(naked) void TransposeUVWx8_SSE2(const uint8_t* src, - int src_stride, - uint8_t* dst_a, - int dst_stride_a, - uint8_t* dst_b, - int dst_stride_b, - int w) { - __asm { - push ebx - push esi - push edi - push ebp - mov eax, [esp + 16 + 4] // src - mov edi, [esp + 16 + 8] // src_stride - mov edx, [esp + 16 + 12] // dst_a - mov esi, [esp + 16 + 16] // dst_stride_a - mov ebx, [esp + 16 + 20] // dst_b - mov ebp, [esp + 16 + 24] // dst_stride_b - mov ecx, esp - sub esp, 4 + 16 - and esp, ~15 - mov [esp + 16], ecx - mov ecx, [ecx + 16 + 28] // w +// Transpose 16x16 bytes using 4 lanes of AVX512BW with tail masking. +// Source row r is in lane r / 4 of register r % 4. +// Can be used for 8-bit planar transpose (dst_a = even rows, dst_b = odd rows) +// or 16-bit UV split transpose (dst_a = U plane, dst_b = V plane). +// TODO(fbarchard): Consider removing in favor of TransposeWx16_Byte_AVX2, +// which is within 10% of AVX512BW on most CPUs. +LIBYUV_TARGET_AVX512BW +static void TransposeWx16_Byte_AVX512BW(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int byte_width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t sa = dst_stride_a; + const ptrdiff_t sb = dst_stride_b; + const __m512i perm0 = _mm512_loadu_si512(kPermdTranspose_AVX512BW); + const __m512i perm1 = _mm512_loadu_si512(kPermdTranspose_AVX512BW + 16); + while (byte_width > 0) { + const int n = byte_width < 16 ? byte_width : 16; + const __mmask16 k = (__mmask16)((1u << n) - 1); + __m512i z0 = LOAD4ROWS_AVX512BW(src, s * 4, k); + __m512i z1 = LOAD4ROWS_AVX512BW(src + s, s * 4, k); + __m512i z2 = LOAD4ROWS_AVX512BW(src + s * 2, s * 4, k); + __m512i z3 = LOAD4ROWS_AVX512BW(src + s * 3, s * 4, k); - align 4 - // Read in the data from the source pointer. - // First round of bit swap. - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + edi] - lea eax, [eax + 2 * edi] - movdqa xmm7, xmm0 // use xmm7 as temp register. - punpcklbw xmm0, xmm1 - punpckhbw xmm7, xmm1 - movdqa xmm1, xmm7 - movdqu xmm2, [eax] - movdqu xmm3, [eax + edi] - lea eax, [eax + 2 * edi] - movdqa xmm7, xmm2 - punpcklbw xmm2, xmm3 - punpckhbw xmm7, xmm3 - movdqa xmm3, xmm7 - movdqu xmm4, [eax] - movdqu xmm5, [eax + edi] - lea eax, [eax + 2 * edi] - movdqa xmm7, xmm4 - punpcklbw xmm4, xmm5 - punpckhbw xmm7, xmm5 - movdqa xmm5, xmm7 - movdqu xmm6, [eax] - movdqu xmm7, [eax + edi] - lea eax, [eax + 2 * edi] - movdqu [esp], xmm5 // backup xmm5 - neg edi - movdqa xmm5, xmm6 // use xmm5 as temp register. - punpcklbw xmm6, xmm7 - punpckhbw xmm5, xmm7 - movdqa xmm7, xmm5 - lea eax, [eax + 8 * edi + 16] - neg edi - // Second round of bit swap. - movdqa xmm5, xmm0 - punpcklwd xmm0, xmm2 - punpckhwd xmm5, xmm2 - movdqa xmm2, xmm5 - movdqa xmm5, xmm1 - punpcklwd xmm1, xmm3 - punpckhwd xmm5, xmm3 - movdqa xmm3, xmm5 - movdqa xmm5, xmm4 - punpcklwd xmm4, xmm6 - punpckhwd xmm5, xmm6 - movdqa xmm6, xmm5 - movdqu xmm5, [esp] // restore xmm5 - movdqu [esp], xmm6 // backup xmm6 - movdqa xmm6, xmm5 // use xmm6 as temp register. - punpcklwd xmm5, xmm7 - punpckhwd xmm6, xmm7 - movdqa xmm7, xmm6 + __m512i a0 = _mm512_unpacklo_epi8(z0, z1); + __m512i a1 = _mm512_unpackhi_epi8(z0, z1); + __m512i a2 = _mm512_unpacklo_epi8(z2, z3); + __m512i a3 = _mm512_unpackhi_epi8(z2, z3); + __m512i b0 = _mm512_unpacklo_epi16(a0, a2); + __m512i b1 = _mm512_unpackhi_epi16(a0, a2); + __m512i b2 = _mm512_unpacklo_epi16(a1, a3); + __m512i b3 = _mm512_unpackhi_epi16(a1, a3); + __m512i o0 = _mm512_permutex2var_epi32(b0, perm0, b2); + __m512i o1 = _mm512_permutex2var_epi32(b0, perm1, b2); + __m512i o2 = _mm512_permutex2var_epi32(b1, perm0, b3); + __m512i o3 = _mm512_permutex2var_epi32(b1, perm1, b3); - // Third round of bit swap. - // Write to the destination pointer. - movdqa xmm6, xmm0 - punpckldq xmm0, xmm4 - punpckhdq xmm6, xmm4 - movdqa xmm4, xmm6 - movdqu xmm6, [esp] // restore xmm6 - movlpd qword ptr [edx], xmm0 - movhpd qword ptr [ebx], xmm0 - movlpd qword ptr [edx + esi], xmm4 - lea edx, [edx + 2 * esi] - movhpd qword ptr [ebx + ebp], xmm4 - lea ebx, [ebx + 2 * ebp] - movdqa xmm0, xmm2 // use xmm0 as the temp register. - punpckldq xmm2, xmm6 - movlpd qword ptr [edx], xmm2 - movhpd qword ptr [ebx], xmm2 - punpckhdq xmm0, xmm6 - movlpd qword ptr [edx + esi], xmm0 - lea edx, [edx + 2 * esi] - movhpd qword ptr [ebx + ebp], xmm0 - lea ebx, [ebx + 2 * ebp] - movdqa xmm0, xmm1 // use xmm0 as the temp register. - punpckldq xmm1, xmm5 - movlpd qword ptr [edx], xmm1 - movhpd qword ptr [ebx], xmm1 - punpckhdq xmm0, xmm5 - movlpd qword ptr [edx + esi], xmm0 - lea edx, [edx + 2 * esi] - movhpd qword ptr [ebx + ebp], xmm0 - lea ebx, [ebx + 2 * ebp] - movdqa xmm0, xmm3 // use xmm0 as the temp register. - punpckldq xmm3, xmm7 - movlpd qword ptr [edx], xmm3 - movhpd qword ptr [ebx], xmm3 - punpckhdq xmm0, xmm7 - sub ecx, 8 - movlpd qword ptr [edx + esi], xmm0 - lea edx, [edx + 2 * esi] - movhpd qword ptr [ebx + ebp], xmm0 - lea ebx, [ebx + 2 * ebp] - jg convertloop - - mov esp, [esp + 16] - pop ebp - pop edi - pop esi - pop ebx - ret + if (n == 16) { + Store16x16_AVX512BW(o0, o1, o2, o3, dst_a, sa, dst_b, sb); + dst_a += sa * 8; + dst_b += sb * 8; + } else { + // Remainder: 1 to 15 bytes. Store 1 destination row per byte. + SIMD_ALIGNED(uint8_t temp[16 * 16]); + int i; + Store16x16_AVX512BW(o0, o1, o2, o3, temp, 32, temp + 16, 32); + for (i = 0; i < n; ++i) { + uint8_t* dst = (i & 1) ? dst_b + sb * (i >> 1) : dst_a + sa * (i >> 1); + _mm_storeu_si128((__m128i*)dst, + _mm_load_si128((const __m128i*)(temp + i * 16))); + } + } + src += 16; + byte_width -= 16; } + _mm256_zeroupper(); +} +#undef LOAD4ROWS_AVX512BW +#endif // defined(HAS_TRANSPOSEWX16_AVX512BW) || + // defined(HAS_TRANSPOSEUVWX16_AVX512BW) + +#if defined(HAS_TRANSPOSEWX16_AVX512BW) +LIBYUV_TARGET_AVX512BW +void TransposeWx16_AVX512BW(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + TransposeWx16_Byte_AVX512BW(src, src_stride, dst, dst_stride * 2, + dst + (width > 1 ? dst_stride : 0), + dst_stride * 2, width); +} +#endif // defined(HAS_TRANSPOSEWX16_AVX512BW) + +#if defined(HAS_TRANSPOSEUVWX16_AVX512BW) +LIBYUV_TARGET_AVX512BW +void TransposeUVWx16_AVX512BW(const uint8_t* src, + int src_stride, + uint8_t* dst_a, + int dst_stride_a, + uint8_t* dst_b, + int dst_stride_b, + int width) { + TransposeWx16_Byte_AVX512BW(src, src_stride, dst_a, dst_stride_a, dst_b, + dst_stride_b, width * 2); +} +#endif // defined(HAS_TRANSPOSEUVWX16_AVX512BW) + +#if defined(HAS_TRANSPOSEWX8_16_AVX2) +LIBYUV_TARGET_AVX2 +void TransposeWx8_16_AVX2(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + while (width > 0) { + __m256i r0 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src))), + _mm_loadu_si128((const __m128i*)(src + s * 4)), 1); + __m256i r1 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s))), + _mm_loadu_si128((const __m128i*)(src + s * 5)), 1); + __m256i r2 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 2))), + _mm_loadu_si128((const __m128i*)(src + s * 6)), 1); + __m256i r3 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 3))), + _mm_loadu_si128((const __m128i*)(src + s * 7)), 1); + + __m256i t0 = _mm256_unpacklo_epi16(r0, r1); + __m256i t1 = _mm256_unpackhi_epi16(r0, r1); + __m256i t2 = _mm256_unpacklo_epi16(r2, r3); + __m256i t3 = _mm256_unpackhi_epi16(r2, r3); + + __m256i u0 = _mm256_permute4x64_epi64(_mm256_unpacklo_epi32(t0, t2), 0xd8); + __m256i u1 = _mm256_permute4x64_epi64(_mm256_unpackhi_epi32(t0, t2), 0xd8); + __m256i u2 = _mm256_permute4x64_epi64(_mm256_unpacklo_epi32(t1, t3), 0xd8); + __m256i u3 = _mm256_permute4x64_epi64(_mm256_unpackhi_epi32(t1, t3), 0xd8); + + _mm_storeu_si128((__m128i*)(dst), _mm256_castsi256_si128(u0)); + _mm_storeu_si128((__m128i*)(dst + d), _mm256_extracti128_si256(u0, 1)); + _mm_storeu_si128((__m128i*)(dst + d * 2), _mm256_castsi256_si128(u1)); + _mm_storeu_si128((__m128i*)(dst + d * 3), _mm256_extracti128_si256(u1, 1)); + _mm_storeu_si128((__m128i*)(dst + d * 4), _mm256_castsi256_si128(u2)); + _mm_storeu_si128((__m128i*)(dst + d * 5), _mm256_extracti128_si256(u2, 1)); + _mm_storeu_si128((__m128i*)(dst + d * 6), _mm256_castsi256_si128(u3)); + _mm_storeu_si128((__m128i*)(dst + d * 7), _mm256_extracti128_si256(u3, 1)); + src += 8; + dst += d * 8; + width -= 8; + } + _mm256_zeroupper(); +} +#endif // defined(HAS_TRANSPOSEWX8_16_AVX2) + +#if defined(HAS_TRANSPOSEWX16_16_AVX2) +LIBYUV_TARGET_AVX2 +void TransposeWx16_16_AVX2(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + while (width > 0) { + __m256i r0 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src))), + _mm_loadu_si128((const __m128i*)(src + s * 8)), 1); + __m256i r1 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s))), + _mm_loadu_si128((const __m128i*)(src + s * 9)), 1); + __m256i r2 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 2))), + _mm_loadu_si128((const __m128i*)(src + s * 10)), 1); + __m256i r3 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 3))), + _mm_loadu_si128((const __m128i*)(src + s * 11)), 1); + __m256i r4 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 4))), + _mm_loadu_si128((const __m128i*)(src + s * 12)), 1); + __m256i r5 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 5))), + _mm_loadu_si128((const __m128i*)(src + s * 13)), 1); + __m256i r6 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 6))), + _mm_loadu_si128((const __m128i*)(src + s * 14)), 1); + __m256i r7 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 7))), + _mm_loadu_si128((const __m128i*)(src + s * 15)), 1); + + __m256i t0 = _mm256_unpacklo_epi16(r0, r1); + __m256i t1 = _mm256_unpackhi_epi16(r0, r1); + __m256i t2 = _mm256_unpacklo_epi16(r2, r3); + __m256i t3 = _mm256_unpackhi_epi16(r2, r3); + __m256i t4 = _mm256_unpacklo_epi16(r4, r5); + __m256i t5 = _mm256_unpackhi_epi16(r4, r5); + __m256i t6 = _mm256_unpacklo_epi16(r6, r7); + __m256i t7 = _mm256_unpackhi_epi16(r6, r7); + + __m256i u0 = _mm256_unpacklo_epi32(t0, t2); + __m256i u1 = _mm256_unpackhi_epi32(t0, t2); + __m256i u2 = _mm256_unpacklo_epi32(t1, t3); + __m256i u3 = _mm256_unpackhi_epi32(t1, t3); + __m256i u4 = _mm256_unpacklo_epi32(t4, t6); + __m256i u5 = _mm256_unpackhi_epi32(t4, t6); + __m256i u6 = _mm256_unpacklo_epi32(t5, t7); + __m256i u7 = _mm256_unpackhi_epi32(t5, t7); + + _mm256_storeu_si256((__m256i*)(dst), _mm256_unpacklo_epi64(u0, u4)); + _mm256_storeu_si256((__m256i*)(dst + d), _mm256_unpackhi_epi64(u0, u4)); + _mm256_storeu_si256((__m256i*)(dst + d * 2), _mm256_unpacklo_epi64(u1, u5)); + _mm256_storeu_si256((__m256i*)(dst + d * 3), _mm256_unpackhi_epi64(u1, u5)); + _mm256_storeu_si256((__m256i*)(dst + d * 4), _mm256_unpacklo_epi64(u2, u6)); + _mm256_storeu_si256((__m256i*)(dst + d * 5), _mm256_unpackhi_epi64(u2, u6)); + _mm256_storeu_si256((__m256i*)(dst + d * 6), _mm256_unpacklo_epi64(u3, u7)); + _mm256_storeu_si256((__m256i*)(dst + d * 7), _mm256_unpackhi_epi64(u3, u7)); + src += 8; + dst += d * 8; + width -= 8; + } + _mm256_zeroupper(); +} +#endif // defined(HAS_TRANSPOSEWX16_16_AVX2) + +#if defined(HAS_TRANSPOSEWX32_16_AVX512BW) +LIBYUV_TARGET_AVX512BW +void TransposeWx32_16_AVX512BW(const uint16_t* src, + int src_stride, + uint16_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + while (width >= 8) { + __m512i r0 = _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src))); + __m512i r1 = + _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src + s))); + __m512i r2 = + _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src + s * 2))); + __m512i r3 = + _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src + s * 3))); + __m512i r4 = + _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src + s * 4))); + __m512i r5 = + _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src + s * 5))); + __m512i r6 = + _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src + s * 6))); + __m512i r7 = + _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src + s * 7))); + + r0 = _mm512_inserti32x4(r0, _mm_loadu_si128((const __m128i*)(src + s * 8)), + 1); + r1 = _mm512_inserti32x4(r1, _mm_loadu_si128((const __m128i*)(src + s * 9)), + 1); + r2 = _mm512_inserti32x4(r2, _mm_loadu_si128((const __m128i*)(src + s * 10)), + 1); + r3 = _mm512_inserti32x4(r3, _mm_loadu_si128((const __m128i*)(src + s * 11)), + 1); + r4 = _mm512_inserti32x4(r4, _mm_loadu_si128((const __m128i*)(src + s * 12)), + 1); + r5 = _mm512_inserti32x4(r5, _mm_loadu_si128((const __m128i*)(src + s * 13)), + 1); + r6 = _mm512_inserti32x4(r6, _mm_loadu_si128((const __m128i*)(src + s * 14)), + 1); + r7 = _mm512_inserti32x4(r7, _mm_loadu_si128((const __m128i*)(src + s * 15)), + 1); + + r0 = _mm512_inserti32x4(r0, _mm_loadu_si128((const __m128i*)(src + s * 16)), + 2); + r1 = _mm512_inserti32x4(r1, _mm_loadu_si128((const __m128i*)(src + s * 17)), + 2); + r2 = _mm512_inserti32x4(r2, _mm_loadu_si128((const __m128i*)(src + s * 18)), + 2); + r3 = _mm512_inserti32x4(r3, _mm_loadu_si128((const __m128i*)(src + s * 19)), + 2); + r4 = _mm512_inserti32x4(r4, _mm_loadu_si128((const __m128i*)(src + s * 20)), + 2); + r5 = _mm512_inserti32x4(r5, _mm_loadu_si128((const __m128i*)(src + s * 21)), + 2); + r6 = _mm512_inserti32x4(r6, _mm_loadu_si128((const __m128i*)(src + s * 22)), + 2); + r7 = _mm512_inserti32x4(r7, _mm_loadu_si128((const __m128i*)(src + s * 23)), + 2); + + r0 = _mm512_inserti32x4(r0, _mm_loadu_si128((const __m128i*)(src + s * 24)), + 3); + r1 = _mm512_inserti32x4(r1, _mm_loadu_si128((const __m128i*)(src + s * 25)), + 3); + r2 = _mm512_inserti32x4(r2, _mm_loadu_si128((const __m128i*)(src + s * 26)), + 3); + r3 = _mm512_inserti32x4(r3, _mm_loadu_si128((const __m128i*)(src + s * 27)), + 3); + r4 = _mm512_inserti32x4(r4, _mm_loadu_si128((const __m128i*)(src + s * 28)), + 3); + r5 = _mm512_inserti32x4(r5, _mm_loadu_si128((const __m128i*)(src + s * 29)), + 3); + r6 = _mm512_inserti32x4(r6, _mm_loadu_si128((const __m128i*)(src + s * 30)), + 3); + r7 = _mm512_inserti32x4(r7, _mm_loadu_si128((const __m128i*)(src + s * 31)), + 3); + + __m512i t0 = _mm512_unpacklo_epi16(r0, r1); + __m512i t1 = _mm512_unpackhi_epi16(r0, r1); + __m512i t2 = _mm512_unpacklo_epi16(r2, r3); + __m512i t3 = _mm512_unpackhi_epi16(r2, r3); + __m512i t4 = _mm512_unpacklo_epi16(r4, r5); + __m512i t5 = _mm512_unpackhi_epi16(r4, r5); + __m512i t6 = _mm512_unpacklo_epi16(r6, r7); + __m512i t7 = _mm512_unpackhi_epi16(r6, r7); + + __m512i u0 = _mm512_unpacklo_epi32(t0, t2); + __m512i u1 = _mm512_unpackhi_epi32(t0, t2); + __m512i u2 = _mm512_unpacklo_epi32(t1, t3); + __m512i u3 = _mm512_unpackhi_epi32(t1, t3); + __m512i u4 = _mm512_unpacklo_epi32(t4, t6); + __m512i u5 = _mm512_unpackhi_epi32(t4, t6); + __m512i u6 = _mm512_unpacklo_epi32(t5, t7); + __m512i u7 = _mm512_unpackhi_epi32(t5, t7); + + _mm512_storeu_si512((__m512i*)(dst), _mm512_unpacklo_epi64(u0, u4)); + _mm512_storeu_si512((__m512i*)(dst + d), _mm512_unpackhi_epi64(u0, u4)); + _mm512_storeu_si512((__m512i*)(dst + d * 2), _mm512_unpacklo_epi64(u1, u5)); + _mm512_storeu_si512((__m512i*)(dst + d * 3), _mm512_unpackhi_epi64(u1, u5)); + _mm512_storeu_si512((__m512i*)(dst + d * 4), _mm512_unpacklo_epi64(u2, u6)); + _mm512_storeu_si512((__m512i*)(dst + d * 5), _mm512_unpackhi_epi64(u2, u6)); + _mm512_storeu_si512((__m512i*)(dst + d * 6), _mm512_unpacklo_epi64(u3, u7)); + _mm512_storeu_si512((__m512i*)(dst + d * 7), _mm512_unpackhi_epi64(u3, u7)); + src += 8; + dst += d * 8; + width -= 8; + } + if (width > 0) { + const __mmask8 col_mask = (1u << width) - 1; + __m512i r0 = _mm512_castsi128_si512(_mm_maskz_loadu_epi16(col_mask, src)); + __m512i r1 = + _mm512_castsi128_si512(_mm_maskz_loadu_epi16(col_mask, src + s)); + __m512i r2 = + _mm512_castsi128_si512(_mm_maskz_loadu_epi16(col_mask, src + s * 2)); + __m512i r3 = + _mm512_castsi128_si512(_mm_maskz_loadu_epi16(col_mask, src + s * 3)); + __m512i r4 = + _mm512_castsi128_si512(_mm_maskz_loadu_epi16(col_mask, src + s * 4)); + __m512i r5 = + _mm512_castsi128_si512(_mm_maskz_loadu_epi16(col_mask, src + s * 5)); + __m512i r6 = + _mm512_castsi128_si512(_mm_maskz_loadu_epi16(col_mask, src + s * 6)); + __m512i r7 = + _mm512_castsi128_si512(_mm_maskz_loadu_epi16(col_mask, src + s * 7)); + + r0 = + _mm512_inserti32x4(r0, _mm_maskz_loadu_epi16(col_mask, src + s * 8), 1); + r1 = + _mm512_inserti32x4(r1, _mm_maskz_loadu_epi16(col_mask, src + s * 9), 1); + r2 = _mm512_inserti32x4(r2, _mm_maskz_loadu_epi16(col_mask, src + s * 10), + 1); + r3 = _mm512_inserti32x4(r3, _mm_maskz_loadu_epi16(col_mask, src + s * 11), + 1); + r4 = _mm512_inserti32x4(r4, _mm_maskz_loadu_epi16(col_mask, src + s * 12), + 1); + r5 = _mm512_inserti32x4(r5, _mm_maskz_loadu_epi16(col_mask, src + s * 13), + 1); + r6 = _mm512_inserti32x4(r6, _mm_maskz_loadu_epi16(col_mask, src + s * 14), + 1); + r7 = _mm512_inserti32x4(r7, _mm_maskz_loadu_epi16(col_mask, src + s * 15), + 1); + + r0 = _mm512_inserti32x4(r0, _mm_maskz_loadu_epi16(col_mask, src + s * 16), + 2); + r1 = _mm512_inserti32x4(r1, _mm_maskz_loadu_epi16(col_mask, src + s * 17), + 2); + r2 = _mm512_inserti32x4(r2, _mm_maskz_loadu_epi16(col_mask, src + s * 18), + 2); + r3 = _mm512_inserti32x4(r3, _mm_maskz_loadu_epi16(col_mask, src + s * 19), + 2); + r4 = _mm512_inserti32x4(r4, _mm_maskz_loadu_epi16(col_mask, src + s * 20), + 2); + r5 = _mm512_inserti32x4(r5, _mm_maskz_loadu_epi16(col_mask, src + s * 21), + 2); + r6 = _mm512_inserti32x4(r6, _mm_maskz_loadu_epi16(col_mask, src + s * 22), + 2); + r7 = _mm512_inserti32x4(r7, _mm_maskz_loadu_epi16(col_mask, src + s * 23), + 2); + + r0 = _mm512_inserti32x4(r0, _mm_maskz_loadu_epi16(col_mask, src + s * 24), + 3); + r1 = _mm512_inserti32x4(r1, _mm_maskz_loadu_epi16(col_mask, src + s * 25), + 3); + r2 = _mm512_inserti32x4(r2, _mm_maskz_loadu_epi16(col_mask, src + s * 26), + 3); + r3 = _mm512_inserti32x4(r3, _mm_maskz_loadu_epi16(col_mask, src + s * 27), + 3); + r4 = _mm512_inserti32x4(r4, _mm_maskz_loadu_epi16(col_mask, src + s * 28), + 3); + r5 = _mm512_inserti32x4(r5, _mm_maskz_loadu_epi16(col_mask, src + s * 29), + 3); + r6 = _mm512_inserti32x4(r6, _mm_maskz_loadu_epi16(col_mask, src + s * 30), + 3); + r7 = _mm512_inserti32x4(r7, _mm_maskz_loadu_epi16(col_mask, src + s * 31), + 3); + + __m512i t0 = _mm512_unpacklo_epi16(r0, r1); + __m512i t1 = _mm512_unpackhi_epi16(r0, r1); + __m512i t2 = _mm512_unpacklo_epi16(r2, r3); + __m512i t3 = _mm512_unpackhi_epi16(r2, r3); + __m512i t4 = _mm512_unpacklo_epi16(r4, r5); + __m512i t5 = _mm512_unpackhi_epi16(r4, r5); + __m512i t6 = _mm512_unpacklo_epi16(r6, r7); + __m512i t7 = _mm512_unpackhi_epi16(r6, r7); + + __m512i u0 = _mm512_unpacklo_epi32(t0, t2); + __m512i u1 = _mm512_unpackhi_epi32(t0, t2); + __m512i u2 = _mm512_unpacklo_epi32(t1, t3); + __m512i u3 = _mm512_unpackhi_epi32(t1, t3); + __m512i u4 = _mm512_unpacklo_epi32(t4, t6); + __m512i u5 = _mm512_unpackhi_epi32(t4, t6); + __m512i u6 = _mm512_unpacklo_epi32(t5, t7); + __m512i u7 = _mm512_unpackhi_epi32(t5, t7); + + _mm512_storeu_si512((__m512i*)(dst), _mm512_unpacklo_epi64(u0, u4)); + if (width > 1) { + _mm512_storeu_si512((__m512i*)(dst + d), _mm512_unpackhi_epi64(u0, u4)); + } + if (width > 2) { + _mm512_storeu_si512((__m512i*)(dst + d * 2), + _mm512_unpacklo_epi64(u1, u5)); + } + if (width > 3) { + _mm512_storeu_si512((__m512i*)(dst + d * 3), + _mm512_unpackhi_epi64(u1, u5)); + } + if (width > 4) { + _mm512_storeu_si512((__m512i*)(dst + d * 4), + _mm512_unpacklo_epi64(u2, u6)); + } + if (width > 5) { + _mm512_storeu_si512((__m512i*)(dst + d * 5), + _mm512_unpackhi_epi64(u2, u6)); + } + if (width > 6) { + _mm512_storeu_si512((__m512i*)(dst + d * 6), + _mm512_unpacklo_epi64(u3, u7)); + } + } + _mm256_zeroupper(); +} +#endif // defined(HAS_TRANSPOSEWX32_16_AVX512BW) + +#if defined(HAS_TRANSPOSEWX4_32_AVX2) +// Transpose 32 bit values (ARGB). Read a column of 4 pixels across 8 rows per +// AVX2 iteration (with a 4-row 128-bit tail) and write 4 destination rows. +LIBYUV_TARGET_AVX2 +void TransposeWx4_32_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + while (width >= 8) { + __m256i r0 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src))), + _mm_loadu_si128((const __m128i*)(src + s * 4)), 1); + __m256i r1 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s))), + _mm_loadu_si128((const __m128i*)(src + s * 5)), 1); + __m256i r2 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 2))), + _mm_loadu_si128((const __m128i*)(src + s * 6)), 1); + __m256i r3 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 3))), + _mm_loadu_si128((const __m128i*)(src + s * 7)), 1); + + __m256i t0 = _mm256_unpacklo_epi32(r0, r1); + __m256i t1 = _mm256_unpacklo_epi32(r2, r3); + __m256i t2 = _mm256_unpackhi_epi32(r0, r1); + __m256i t3 = _mm256_unpackhi_epi32(r2, r3); + + _mm256_storeu_si256((__m256i*)(dst), _mm256_unpacklo_epi64(t0, t1)); + _mm256_storeu_si256((__m256i*)(dst + d), _mm256_unpackhi_epi64(t0, t1)); + _mm256_storeu_si256((__m256i*)(dst + d * 2), _mm256_unpacklo_epi64(t2, t3)); + _mm256_storeu_si256((__m256i*)(dst + d * 3), _mm256_unpackhi_epi64(t2, t3)); + src += s * 8; + dst += 32; + width -= 8; + } + if (width > 0) { + __m128i r0 = _mm_loadu_si128((const __m128i*)(src)); + __m128i r1 = _mm_loadu_si128((const __m128i*)(src + s)); + __m128i r2 = _mm_loadu_si128((const __m128i*)(src + s * 2)); + __m128i r3 = _mm_loadu_si128((const __m128i*)(src + s * 3)); + __m128i t0 = _mm_unpacklo_epi32(r0, r1); + __m128i t1 = _mm_unpacklo_epi32(r2, r3); + __m128i t2 = _mm_unpackhi_epi32(r0, r1); + __m128i t3 = _mm_unpackhi_epi32(r2, r3); + _mm_storeu_si128((__m128i*)(dst), _mm_unpacklo_epi64(t0, t1)); + _mm_storeu_si128((__m128i*)(dst + d), _mm_unpackhi_epi64(t0, t1)); + _mm_storeu_si128((__m128i*)(dst + d * 2), _mm_unpacklo_epi64(t2, t3)); + _mm_storeu_si128((__m128i*)(dst + d * 3), _mm_unpackhi_epi64(t2, t3)); + } + _mm256_zeroupper(); +} +#endif // defined(HAS_TRANSPOSEWX4_32_AVX2) + +#if defined(HAS_TRANSPOSEWX8_32_AVX2) +LIBYUV_TARGET_AVX2 +void TransposeWx8_32_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + while (width > 0) { + __m256i r0 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src))), + _mm_loadu_si128((const __m128i*)(src + s * 4)), 1); + __m256i r1 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s))), + _mm_loadu_si128((const __m128i*)(src + s * 5)), 1); + __m256i r2 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 2))), + _mm_loadu_si128((const __m128i*)(src + s * 6)), 1); + __m256i r3 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i*)(src + s * 3))), + _mm_loadu_si128((const __m128i*)(src + s * 7)), 1); + + __m256i t0 = _mm256_unpacklo_epi32(r0, r1); + __m256i t1 = _mm256_unpacklo_epi32(r2, r3); + __m256i t2 = _mm256_unpackhi_epi32(r0, r1); + __m256i t3 = _mm256_unpackhi_epi32(r2, r3); + + _mm256_storeu_si256((__m256i*)(dst), _mm256_unpacklo_epi64(t0, t1)); + _mm256_storeu_si256((__m256i*)(dst + d), _mm256_unpackhi_epi64(t0, t1)); + _mm256_storeu_si256((__m256i*)(dst + d * 2), _mm256_unpacklo_epi64(t2, t3)); + _mm256_storeu_si256((__m256i*)(dst + d * 3), _mm256_unpackhi_epi64(t2, t3)); + src += 16; + dst += d * 4; + width -= 4; + } + _mm256_zeroupper(); +} +#endif // defined(HAS_TRANSPOSEWX8_32_AVX2) + +#if defined(HAS_TRANSPOSEWXH_32_AVX2) +// Load n (1..3) 32-bit pixels into low lanes of __m128i with zeroed upper +// lanes (safe at buffer boundaries and MemorySanitizer-clean). +LIBYUV_TARGET_AVX2 +static __m128i LoadPartialRow_32_AVX2(const uint8_t* p, int n) { + if (n == 1) { + int v; + memcpy(&v, p, 4); + return _mm_cvtsi32_si128(v); + } + if (n == 2) { + return _mm_loadl_epi64((const __m128i*)p); + } + int v; + memcpy(&v, p + 8, 4); + return _mm_insert_epi32(_mm_loadl_epi64((const __m128i*)p), v, 2); } -#endif // !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) +// Transpose arbitrary WxH 32-bit plane using AVX2 (4x8, 8x4, 4x4, and 4x{1..3} +// tiles plus exact remainder handling). +LIBYUV_TARGET_AVX2 +void TransposeWxH_32_AVX2(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width, + int height) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + const int w4 = width & ~3; + const int rem_w = width & 3; + + // Tier 1: 8-row strips using 4x8 YMM tiles + rem_w x 8 YMM tail. + while (height >= 8) { + if (w4 > 0) { + TransposeWx8_32_AVX2(src, src_stride, dst, dst_stride, w4); + } + if (rem_w > 0) { + const uint8_t* src_rem = src + (ptrdiff_t)w4 * 4; + uint8_t* dst_rem = dst + (ptrdiff_t)w4 * d; + __m256i r0 = _mm256_inserti128_si256( + _mm256_castsi128_si256(LoadPartialRow_32_AVX2(src_rem, rem_w)), + LoadPartialRow_32_AVX2(src_rem + s * 4, rem_w), 1); + __m256i r1 = _mm256_inserti128_si256( + _mm256_castsi128_si256(LoadPartialRow_32_AVX2(src_rem + s, rem_w)), + LoadPartialRow_32_AVX2(src_rem + s * 5, rem_w), 1); + __m256i r2 = _mm256_inserti128_si256( + _mm256_castsi128_si256( + LoadPartialRow_32_AVX2(src_rem + s * 2, rem_w)), + LoadPartialRow_32_AVX2(src_rem + s * 6, rem_w), 1); + __m256i r3 = _mm256_inserti128_si256( + _mm256_castsi128_si256( + LoadPartialRow_32_AVX2(src_rem + s * 3, rem_w)), + LoadPartialRow_32_AVX2(src_rem + s * 7, rem_w), 1); + + __m256i t0 = _mm256_unpacklo_epi32(r0, r1); + __m256i t1 = _mm256_unpacklo_epi32(r2, r3); + _mm256_storeu_si256((__m256i*)(dst_rem), _mm256_unpacklo_epi64(t0, t1)); + if (rem_w > 1) { + _mm256_storeu_si256((__m256i*)(dst_rem + d), + _mm256_unpackhi_epi64(t0, t1)); + } + if (rem_w > 2) { + __m256i t2 = _mm256_unpackhi_epi32(r0, r1); + __m256i t3 = _mm256_unpackhi_epi32(r2, r3); + _mm256_storeu_si256((__m256i*)(dst_rem + d * 2), + _mm256_unpacklo_epi64(t2, t3)); + } + _mm256_zeroupper(); + } + src += 8 * s; + dst += 32; + height -= 8; + } + + // Tier 2: 4-row strip using 8x4 YMM tiles + 4x4 XMM block + rem_w x 4 tail. + if (height >= 4) { + const int w8 = width & ~7; + if (w8 > 0) { + const uint8_t* src_p = src; + uint8_t* dst_p = dst; + int cnt = w8; + while (cnt > 0) { + __m256i r0 = _mm256_loadu_si256((const __m256i*)(src_p)); + __m256i r1 = _mm256_loadu_si256((const __m256i*)(src_p + s)); + __m256i r2 = _mm256_loadu_si256((const __m256i*)(src_p + s * 2)); + __m256i r3 = _mm256_loadu_si256((const __m256i*)(src_p + s * 3)); + + __m256i t0 = _mm256_unpacklo_epi32(r0, r1); + __m256i t1 = _mm256_unpacklo_epi32(r2, r3); + __m256i t2 = _mm256_unpackhi_epi32(r0, r1); + __m256i t3 = _mm256_unpackhi_epi32(r2, r3); + + __m256i o0 = _mm256_unpacklo_epi64(t0, t1); + __m256i o1 = _mm256_unpackhi_epi64(t0, t1); + __m256i o2 = _mm256_unpacklo_epi64(t2, t3); + __m256i o3 = _mm256_unpackhi_epi64(t2, t3); + + _mm_storeu_si128((__m128i*)(dst_p), _mm256_castsi256_si128(o0)); + _mm_storeu_si128((__m128i*)(dst_p + d), _mm256_castsi256_si128(o1)); + _mm_storeu_si128((__m128i*)(dst_p + d * 2), _mm256_castsi256_si128(o2)); + _mm_storeu_si128((__m128i*)(dst_p + d * 3), _mm256_castsi256_si128(o3)); + _mm_storeu_si128((__m128i*)(dst_p + d * 4), + _mm256_extracti128_si256(o0, 1)); + _mm_storeu_si128((__m128i*)(dst_p + d * 5), + _mm256_extracti128_si256(o1, 1)); + _mm_storeu_si128((__m128i*)(dst_p + d * 6), + _mm256_extracti128_si256(o2, 1)); + _mm_storeu_si128((__m128i*)(dst_p + d * 7), + _mm256_extracti128_si256(o3, 1)); + + src_p += 32; + dst_p += d * 8; + cnt -= 8; + } + _mm256_zeroupper(); + } + if (width & 4) { + const uint8_t* src_p = src + (ptrdiff_t)w8 * 4; + uint8_t* dst_p = dst + (ptrdiff_t)w8 * d; + __m128i r0 = _mm_loadu_si128((const __m128i*)(src_p)); + __m128i r1 = _mm_loadu_si128((const __m128i*)(src_p + s)); + __m128i r2 = _mm_loadu_si128((const __m128i*)(src_p + s * 2)); + __m128i r3 = _mm_loadu_si128((const __m128i*)(src_p + s * 3)); + __m128i t0 = _mm_unpacklo_epi32(r0, r1); + __m128i t1 = _mm_unpacklo_epi32(r2, r3); + __m128i t2 = _mm_unpackhi_epi32(r0, r1); + __m128i t3 = _mm_unpackhi_epi32(r2, r3); + _mm_storeu_si128((__m128i*)(dst_p), _mm_unpacklo_epi64(t0, t1)); + _mm_storeu_si128((__m128i*)(dst_p + d), _mm_unpackhi_epi64(t0, t1)); + _mm_storeu_si128((__m128i*)(dst_p + d * 2), _mm_unpacklo_epi64(t2, t3)); + _mm_storeu_si128((__m128i*)(dst_p + d * 3), _mm_unpackhi_epi64(t2, t3)); + } + if (rem_w > 0) { + const uint8_t* src_rem = src + (ptrdiff_t)w4 * 4; + uint8_t* dst_rem = dst + (ptrdiff_t)w4 * d; + __m128i r0 = LoadPartialRow_32_AVX2(src_rem, rem_w); + __m128i r1 = LoadPartialRow_32_AVX2(src_rem + s, rem_w); + __m128i r2 = LoadPartialRow_32_AVX2(src_rem + s * 2, rem_w); + __m128i r3 = LoadPartialRow_32_AVX2(src_rem + s * 3, rem_w); + __m128i t0 = _mm_unpacklo_epi32(r0, r1); + __m128i t1 = _mm_unpacklo_epi32(r2, r3); + _mm_storeu_si128((__m128i*)(dst_rem), _mm_unpacklo_epi64(t0, t1)); + if (rem_w > 1) { + _mm_storeu_si128((__m128i*)(dst_rem + d), _mm_unpackhi_epi64(t0, t1)); + } + if (rem_w > 2) { + __m128i t2 = _mm_unpackhi_epi32(r0, r1); + __m128i t3 = _mm_unpackhi_epi32(r2, r3); + _mm_storeu_si128((__m128i*)(dst_rem + d * 2), + _mm_unpacklo_epi64(t2, t3)); + } + } + src += 4 * s; + dst += 16; + height -= 4; + } + + // Tier 3: 1..3 remaining source rows using 4 x height XMM tiles + corner. + if (height > 0) { + if (w4 > 0) { + const uint8_t* src_p = src; + uint8_t* dst_p = dst; + int cnt = w4; + if (height == 1) { + while (cnt > 0) { + __m128i r0 = _mm_loadu_si128((const __m128i*)(src_p)); + int v0 = _mm_cvtsi128_si32(r0); + int v1 = _mm_extract_epi32(r0, 1); + int v2 = _mm_extract_epi32(r0, 2); + int v3 = _mm_extract_epi32(r0, 3); + memcpy(dst_p, &v0, 4); + memcpy(dst_p + d, &v1, 4); + memcpy(dst_p + d * 2, &v2, 4); + memcpy(dst_p + d * 3, &v3, 4); + src_p += 16; + dst_p += d * 4; + cnt -= 4; + } + } else if (height == 2) { + while (cnt > 0) { + __m128i r0 = _mm_loadu_si128((const __m128i*)(src_p)); + __m128i r1 = _mm_loadu_si128((const __m128i*)(src_p + s)); + __m128i t0 = _mm_unpacklo_epi32(r0, r1); + __m128i t1 = _mm_unpackhi_epi32(r0, r1); + _mm_storel_epi64((__m128i*)(dst_p), t0); + _mm_storeh_pd((double*)(dst_p + d), _mm_castsi128_pd(t0)); + _mm_storel_epi64((__m128i*)(dst_p + d * 2), t1); + _mm_storeh_pd((double*)(dst_p + d * 3), _mm_castsi128_pd(t1)); + src_p += 16; + dst_p += d * 4; + cnt -= 4; + } + } else { + const __m128i zero = _mm_setzero_si128(); + while (cnt > 0) { + __m128i r0 = _mm_loadu_si128((const __m128i*)(src_p)); + __m128i r1 = _mm_loadu_si128((const __m128i*)(src_p + s)); + __m128i r2 = _mm_loadu_si128((const __m128i*)(src_p + s * 2)); + __m128i t0 = _mm_unpacklo_epi32(r0, r1); + __m128i t1 = _mm_unpacklo_epi32(r2, zero); + __m128i t2 = _mm_unpackhi_epi32(r0, r1); + __m128i t3 = _mm_unpackhi_epi32(r2, zero); + __m128i o0 = _mm_unpacklo_epi64(t0, t1); + __m128i o1 = _mm_unpackhi_epi64(t0, t1); + __m128i o2 = _mm_unpacklo_epi64(t2, t3); + __m128i o3 = _mm_unpackhi_epi64(t2, t3); + int v0 = _mm_extract_epi32(o0, 2); + int v1 = _mm_extract_epi32(o1, 2); + int v2 = _mm_extract_epi32(o2, 2); + int v3 = _mm_extract_epi32(o3, 2); + _mm_storel_epi64((__m128i*)(dst_p), o0); + memcpy(dst_p + 8, &v0, 4); + _mm_storel_epi64((__m128i*)(dst_p + d), o1); + memcpy(dst_p + d + 8, &v1, 4); + _mm_storel_epi64((__m128i*)(dst_p + d * 2), o2); + memcpy(dst_p + d * 2 + 8, &v2, 4); + _mm_storel_epi64((__m128i*)(dst_p + d * 3), o3); + memcpy(dst_p + d * 3 + 8, &v3, 4); + src_p += 16; + dst_p += d * 4; + cnt -= 4; + } + } + } + for (int x = w4; x < width; ++x) { + uint8_t* dst_row = dst + (ptrdiff_t)x * d; + for (int y = 0; y < height; ++y) { + memcpy(dst_row + y * 4, src + (ptrdiff_t)y * s + x * 4, 4); + } + } + } +} +#endif // defined(HAS_TRANSPOSEWXH_32_AVX2) + +#if defined(HAS_TRANSPOSEWX16_32_AVX512BW) +LIBYUV_TARGET_AVX512BW +void TransposeWx16_32_AVX512BW(const uint8_t* src, + int src_stride, + uint8_t* dst, + int dst_stride, + int width) { + const ptrdiff_t s = src_stride; + const ptrdiff_t d = dst_stride; + while (width >= 4) { + __m512i r0 = _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src))); + __m512i r1 = + _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src + s))); + __m512i r2 = + _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src + s * 2))); + __m512i r3 = + _mm512_castsi128_si512(_mm_loadu_si128((const __m128i*)(src + s * 3))); + + r0 = _mm512_inserti32x4(r0, _mm_loadu_si128((const __m128i*)(src + s * 4)), + 1); + r1 = _mm512_inserti32x4(r1, _mm_loadu_si128((const __m128i*)(src + s * 5)), + 1); + r2 = _mm512_inserti32x4(r2, _mm_loadu_si128((const __m128i*)(src + s * 6)), + 1); + r3 = _mm512_inserti32x4(r3, _mm_loadu_si128((const __m128i*)(src + s * 7)), + 1); + + r0 = _mm512_inserti32x4(r0, _mm_loadu_si128((const __m128i*)(src + s * 8)), + 2); + r1 = _mm512_inserti32x4(r1, _mm_loadu_si128((const __m128i*)(src + s * 9)), + 2); + r2 = _mm512_inserti32x4(r2, _mm_loadu_si128((const __m128i*)(src + s * 10)), + 2); + r3 = _mm512_inserti32x4(r3, _mm_loadu_si128((const __m128i*)(src + s * 11)), + 2); + + r0 = _mm512_inserti32x4(r0, _mm_loadu_si128((const __m128i*)(src + s * 12)), + 3); + r1 = _mm512_inserti32x4(r1, _mm_loadu_si128((const __m128i*)(src + s * 13)), + 3); + r2 = _mm512_inserti32x4(r2, _mm_loadu_si128((const __m128i*)(src + s * 14)), + 3); + r3 = _mm512_inserti32x4(r3, _mm_loadu_si128((const __m128i*)(src + s * 15)), + 3); + + __m512i t0 = _mm512_unpacklo_epi32(r0, r1); + __m512i t1 = _mm512_unpacklo_epi32(r2, r3); + __m512i t2 = _mm512_unpackhi_epi32(r0, r1); + __m512i t3 = _mm512_unpackhi_epi32(r2, r3); + + _mm512_storeu_si512((__m512i*)(dst), _mm512_unpacklo_epi64(t0, t1)); + _mm512_storeu_si512((__m512i*)(dst + d), _mm512_unpackhi_epi64(t0, t1)); + _mm512_storeu_si512((__m512i*)(dst + d * 2), _mm512_unpacklo_epi64(t2, t3)); + _mm512_storeu_si512((__m512i*)(dst + d * 3), _mm512_unpackhi_epi64(t2, t3)); + src += 16; + dst += d * 4; + width -= 4; + } + if (width > 0) { + const __mmask8 col_mask = (1u << width) - 1; + __m512i r0 = _mm512_castsi128_si512(_mm_maskz_loadu_epi32(col_mask, src)); + __m512i r1 = + _mm512_castsi128_si512(_mm_maskz_loadu_epi32(col_mask, src + s)); + __m512i r2 = + _mm512_castsi128_si512(_mm_maskz_loadu_epi32(col_mask, src + s * 2)); + __m512i r3 = + _mm512_castsi128_si512(_mm_maskz_loadu_epi32(col_mask, src + s * 3)); + + r0 = + _mm512_inserti32x4(r0, _mm_maskz_loadu_epi32(col_mask, src + s * 4), 1); + r1 = + _mm512_inserti32x4(r1, _mm_maskz_loadu_epi32(col_mask, src + s * 5), 1); + r2 = + _mm512_inserti32x4(r2, _mm_maskz_loadu_epi32(col_mask, src + s * 6), 1); + r3 = + _mm512_inserti32x4(r3, _mm_maskz_loadu_epi32(col_mask, src + s * 7), 1); + + r0 = + _mm512_inserti32x4(r0, _mm_maskz_loadu_epi32(col_mask, src + s * 8), 2); + r1 = + _mm512_inserti32x4(r1, _mm_maskz_loadu_epi32(col_mask, src + s * 9), 2); + r2 = _mm512_inserti32x4(r2, _mm_maskz_loadu_epi32(col_mask, src + s * 10), + 2); + r3 = _mm512_inserti32x4(r3, _mm_maskz_loadu_epi32(col_mask, src + s * 11), + 2); + + r0 = _mm512_inserti32x4(r0, _mm_maskz_loadu_epi32(col_mask, src + s * 12), + 3); + r1 = _mm512_inserti32x4(r1, _mm_maskz_loadu_epi32(col_mask, src + s * 13), + 3); + r2 = _mm512_inserti32x4(r2, _mm_maskz_loadu_epi32(col_mask, src + s * 14), + 3); + r3 = _mm512_inserti32x4(r3, _mm_maskz_loadu_epi32(col_mask, src + s * 15), + 3); + + __m512i t0 = _mm512_unpacklo_epi32(r0, r1); + __m512i t1 = _mm512_unpacklo_epi32(r2, r3); + __m512i t2 = _mm512_unpackhi_epi32(r0, r1); + __m512i t3 = _mm512_unpackhi_epi32(r2, r3); + + _mm512_storeu_si512((__m512i*)(dst), _mm512_unpacklo_epi64(t0, t1)); + if (width > 1) { + _mm512_storeu_si512((__m512i*)(dst + d), _mm512_unpackhi_epi64(t0, t1)); + } + if (width > 2) { + _mm512_storeu_si512((__m512i*)(dst + d * 2), + _mm512_unpacklo_epi64(t2, t3)); + } + } + _mm256_zeroupper(); +} +#endif // defined(HAS_TRANSPOSEWX16_32_AVX512BW) #ifdef __cplusplus } // extern "C" } // namespace libyuv #endif + +#endif // !defined(LIBYUV_DISABLE_X86) && (x86 or x64) && + // (Visual C or LIBYUV_ENABLE_ROWWIN) diff --git a/libs/libyuv/source/row_any.cc b/libs/libyuv/source/row_any.cc index 9fafff6020..9c6d3ccb3f 100644 --- a/libs/libyuv/source/row_any.cc +++ b/libs/libyuv/source/row_any.cc @@ -10,90 +10,306 @@ #include "libyuv/row.h" +#include #include // For memset. -#include "libyuv/basic_types.h" - #ifdef __cplusplus namespace libyuv { extern "C" { #endif -// memset for temp is meant to clear the source buffer (not dest) so that -// SIMD that reads full multiple of 16 bytes will not trigger msan errors. -// memset is not needed for production, as the garbage values are processed but -// not used, although there may be edge cases for subsampling. -// The size of the buffer is based on the largest read, which can be inferred -// by the source type (e.g. ARGB) and the mask (last parameter), or by examining -// the source code for how much the source pointers are advanced. - -// Subsampled source needs to be increase by 1 of not even. +// Subsampled source needs to be increase by 1 if not even. #define SS(width, shift) (((width) + (1 << (shift)) - 1) >> (shift)) +#ifdef LIBYUV_MSAN +#define MSAN_MEMSET(a, b, c) memset(a, b, c) +#else +#define MSAN_MEMSET(a, b, c) +#endif + +// Any 4 planes to 1 +#define ANY41(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, BPP, MASK) \ + void NAMEANY(const uint8_t* y_buf, const uint8_t* u_buf, \ + const uint8_t* v_buf, const uint8_t* a_buf, uint8_t* dst_ptr, \ + int width) { \ + SIMD_ALIGNED(uint8_t vin[64 * 4]); \ + static_assert(MASK + 1 <= sizeof(vin) / 4, "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[64]); \ + static_assert(SS(MASK + 1, DUVSHIFT) * BPP <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(y_buf, u_buf, v_buf, a_buf, dst_ptr, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, y_buf + np, r); \ + memcpy(vin + 64, u_buf + (np >> UVSHIFT), SS(r, UVSHIFT)); \ + memcpy(vin + 128, v_buf + (np >> UVSHIFT), SS(r, UVSHIFT)); \ + memcpy(vin + 192, a_buf + np, r); \ + ANY_SIMD(vin, vin + 64, vin + 128, vin + 192, vout, MASK + 1); \ + memcpy(dst_ptr + (np >> DUVSHIFT) * BPP, vout, SS(r, DUVSHIFT) * BPP); \ + } + +#ifdef HAS_MERGEARGBROW_SSE2 +ANY41(MergeARGBRow_Any_SSE2, MergeARGBRow_SSE2, 0, 0, 4, 7) +#endif +#ifdef HAS_MERGEARGBROW_AVX2 +ANY41(MergeARGBRow_Any_AVX2, MergeARGBRow_AVX2, 0, 0, 4, 15) +#endif +#ifdef HAS_MERGEARGBROW_NEON +ANY41(MergeARGBRow_Any_NEON, MergeARGBRow_NEON, 0, 0, 4, 15) +#endif + +// Note that odd width replication includes 444 due to implementation +// on arm that subsamples 444 to 422 internally. // Any 4 planes to 1 with yuvconstants #define ANY41C(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, BPP, MASK) \ void NAMEANY(const uint8_t* y_buf, const uint8_t* u_buf, \ const uint8_t* v_buf, const uint8_t* a_buf, uint8_t* dst_ptr, \ const struct YuvConstants* yuvconstants, int width) { \ - SIMD_ALIGNED(uint8_t temp[64 * 5]); \ - memset(temp, 0, 64 * 4); /* for msan */ \ + SIMD_ALIGNED(uint8_t vin[64 * 4]); \ + static_assert(MASK + 1 <= sizeof(vin) / 4, "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[64]); \ + static_assert(SS(MASK + 1, DUVSHIFT) * BPP <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ int r = width & MASK; \ int n = width & ~MASK; \ if (n > 0) { \ ANY_SIMD(y_buf, u_buf, v_buf, a_buf, dst_ptr, yuvconstants, n); \ } \ - memcpy(temp, y_buf + n, r); \ - memcpy(temp + 64, u_buf + (n >> UVSHIFT), SS(r, UVSHIFT)); \ - memcpy(temp + 128, v_buf + (n >> UVSHIFT), SS(r, UVSHIFT)); \ - memcpy(temp + 192, a_buf + n, r); \ - ANY_SIMD(temp, temp + 64, temp + 128, temp + 192, temp + 256, \ - yuvconstants, MASK + 1); \ - memcpy(dst_ptr + (n >> DUVSHIFT) * BPP, temp + 256, \ - SS(r, DUVSHIFT) * BPP); \ + ptrdiff_t np = n; \ + memcpy(vin, y_buf + np, r); \ + memcpy(vin + 64, u_buf + (np >> UVSHIFT), SS(r, UVSHIFT)); \ + memcpy(vin + 128, v_buf + (np >> UVSHIFT), SS(r, UVSHIFT)); \ + memcpy(vin + 192, a_buf + np, r); \ + if (width & 1) { \ + vin[64 + SS(r, UVSHIFT)] = vin[64 + SS(r, UVSHIFT) - 1]; \ + vin[128 + SS(r, UVSHIFT)] = vin[128 + SS(r, UVSHIFT) - 1]; \ + } \ + ANY_SIMD(vin, vin + 64, vin + 128, vin + 192, vout, yuvconstants, \ + MASK + 1); \ + memcpy(dst_ptr + (np >> DUVSHIFT) * BPP, vout, SS(r, DUVSHIFT) * BPP); \ } +#ifdef HAS_I444ALPHATOARGBROW_SSSE3 +ANY41C(I444AlphaToARGBRow_Any_SSSE3, I444AlphaToARGBRow_SSSE3, 0, 0, 4, 7) +#endif +#ifdef HAS_I444ALPHATOARGBROW_AVX2 +ANY41C(I444AlphaToARGBRow_Any_AVX2, I444AlphaToARGBRow_AVX2, 0, 0, 4, 15) +#endif #ifdef HAS_I422ALPHATOARGBROW_SSSE3 ANY41C(I422AlphaToARGBRow_Any_SSSE3, I422AlphaToARGBRow_SSSE3, 1, 0, 4, 7) #endif #ifdef HAS_I422ALPHATOARGBROW_AVX2 ANY41C(I422AlphaToARGBRow_Any_AVX2, I422AlphaToARGBRow_AVX2, 1, 0, 4, 15) #endif +#ifdef HAS_I444ALPHATOARGBROW_NEON +ANY41C(I444AlphaToARGBRow_Any_NEON, I444AlphaToARGBRow_NEON, 0, 0, 4, 7) +#endif #ifdef HAS_I422ALPHATOARGBROW_NEON ANY41C(I422AlphaToARGBRow_Any_NEON, I422AlphaToARGBRow_NEON, 1, 0, 4, 7) #endif -#ifdef HAS_I422ALPHATOARGBROW_MSA -ANY41C(I422AlphaToARGBRow_Any_MSA, I422AlphaToARGBRow_MSA, 1, 0, 4, 7) +#ifdef HAS_I422ALPHATOARGBROW_LSX +ANY41C(I422AlphaToARGBRow_Any_LSX, I422AlphaToARGBRow_LSX, 1, 0, 4, 7) +#endif +#ifdef HAS_I422ALPHATOARGBROW_LASX +ANY41C(I422AlphaToARGBRow_Any_LASX, I422AlphaToARGBRow_LASX, 1, 0, 4, 15) #endif #undef ANY41C +// Any 4 planes to 1 plane of 8 bit with yuvconstants +#define ANY41CT(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, T, SBPP, BPP, MASK) \ + void NAMEANY(const T* y_buf, const T* u_buf, const T* v_buf, const T* a_buf, \ + uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, \ + int width) { \ + SIMD_ALIGNED(T vin[16 * 4]); \ + static_assert((MASK + 1) * SBPP <= sizeof(vin) / 4, \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[64]); \ + static_assert(SS(MASK + 1, DUVSHIFT) * BPP <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for YUY2 and msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(y_buf, u_buf, v_buf, a_buf, dst_ptr, yuvconstants, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, y_buf + np, r * SBPP); \ + memcpy(vin + 16, u_buf + (np >> UVSHIFT), SS(r, UVSHIFT) * SBPP); \ + memcpy(vin + 32, v_buf + (np >> UVSHIFT), SS(r, UVSHIFT) * SBPP); \ + memcpy(vin + 48, a_buf + np, r * SBPP); \ + ANY_SIMD(vin, vin + 16, vin + 32, vin + 48, vout, yuvconstants, MASK + 1); \ + memcpy(dst_ptr + (np >> DUVSHIFT) * BPP, vout, SS(r, DUVSHIFT) * BPP); \ + } + +#ifdef HAS_I210ALPHATOARGBROW_NEON +ANY41CT(I210AlphaToARGBRow_Any_NEON, + I210AlphaToARGBRow_NEON, + 1, + 0, + uint16_t, + 2, + 4, + 7) +#endif +#ifdef HAS_I410ALPHATOARGBROW_NEON +ANY41CT(I410AlphaToARGBRow_Any_NEON, + I410AlphaToARGBRow_NEON, + 0, + 0, + uint16_t, + 2, + 4, + 7) +#endif + +#ifdef HAS_I210ALPHATOARGBROW_SSSE3 +ANY41CT(I210AlphaToARGBRow_Any_SSSE3, + I210AlphaToARGBRow_SSSE3, + 1, + 0, + uint16_t, + 2, + 4, + 7) +#endif + +#ifdef HAS_I210ALPHATOARGBROW_AVX2 +ANY41CT(I210AlphaToARGBRow_Any_AVX2, + I210AlphaToARGBRow_AVX2, + 1, + 0, + uint16_t, + 2, + 4, + 15) +#endif + +#ifdef HAS_I410ALPHATOARGBROW_SSSE3 +ANY41CT(I410AlphaToARGBRow_Any_SSSE3, + I410AlphaToARGBRow_SSSE3, + 0, + 0, + uint16_t, + 2, + 4, + 7) +#endif + +#ifdef HAS_I410ALPHATOARGBROW_AVX2 +ANY41CT(I410AlphaToARGBRow_Any_AVX2, + I410AlphaToARGBRow_AVX2, + 0, + 0, + uint16_t, + 2, + 4, + 15) +#endif + +#undef ANY41CT + +// Any 4 planes to 1 plane with parameter +#define ANY41PT(NAMEANY, ANY_SIMD, STYPE, SBPP, DTYPE, BPP, MASK) \ + void NAMEANY(const STYPE* r_buf, const STYPE* g_buf, const STYPE* b_buf, \ + const STYPE* a_buf, DTYPE* dst_ptr, int depth, int width) { \ + SIMD_ALIGNED(STYPE vin[16 * 4]); \ + static_assert((MASK + 1) * SBPP <= sizeof(vin) / 4, \ + "vin buffer too small"); \ + SIMD_ALIGNED(DTYPE vout[64]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(r_buf, g_buf, b_buf, a_buf, dst_ptr, depth, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, r_buf + np, r * SBPP); \ + memcpy(vin + 16, g_buf + np, r * SBPP); \ + memcpy(vin + 32, b_buf + np, r * SBPP); \ + memcpy(vin + 48, a_buf + np, r * SBPP); \ + ANY_SIMD(vin, vin + 16, vin + 32, vin + 48, vout, depth, MASK + 1); \ + memcpy((uint8_t*)dst_ptr + np * BPP, vout, r * BPP); \ + } + +#ifdef HAS_MERGEAR64ROW_AVX2 +ANY41PT(MergeAR64Row_Any_AVX2, MergeAR64Row_AVX2, uint16_t, 2, uint16_t, 8, 15) +#endif + +#ifdef HAS_MERGEAR64ROW_NEON +ANY41PT(MergeAR64Row_Any_NEON, MergeAR64Row_NEON, uint16_t, 2, uint16_t, 8, 7) +#endif + +#ifdef HAS_MERGEARGB16TO8ROW_AVX2 +ANY41PT(MergeARGB16To8Row_Any_AVX2, + MergeARGB16To8Row_AVX2, + uint16_t, + 2, + uint8_t, + 4, + 15) +#endif + +#ifdef HAS_MERGEARGB16TO8ROW_NEON +ANY41PT(MergeARGB16To8Row_Any_NEON, + MergeARGB16To8Row_NEON, + uint16_t, + 2, + uint8_t, + 4, + 7) +#endif + +#undef ANY41PT + // Any 3 planes to 1. -#define ANY31(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, BPP, MASK) \ - void NAMEANY(const uint8_t* y_buf, const uint8_t* u_buf, \ - const uint8_t* v_buf, uint8_t* dst_ptr, int width) { \ - SIMD_ALIGNED(uint8_t temp[64 * 4]); \ - memset(temp, 0, 64 * 3); /* for YUY2 and msan */ \ - int r = width & MASK; \ - int n = width & ~MASK; \ - if (n > 0) { \ - ANY_SIMD(y_buf, u_buf, v_buf, dst_ptr, n); \ - } \ - memcpy(temp, y_buf + n, r); \ - memcpy(temp + 64, u_buf + (n >> UVSHIFT), SS(r, UVSHIFT)); \ - memcpy(temp + 128, v_buf + (n >> UVSHIFT), SS(r, UVSHIFT)); \ - ANY_SIMD(temp, temp + 64, temp + 128, temp + 192, MASK + 1); \ - memcpy(dst_ptr + (n >> DUVSHIFT) * BPP, temp + 192, \ - SS(r, DUVSHIFT) * BPP); \ +#define ANY31(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, BPP, MASK) \ + void NAMEANY(const uint8_t* y_buf, const uint8_t* u_buf, \ + const uint8_t* v_buf, uint8_t* dst_ptr, int width) { \ + SIMD_ALIGNED(uint8_t vin[64 * 3]); \ + static_assert(MASK + 1 <= sizeof(vin) / 3, "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[64 * 4]); \ + static_assert(SS(MASK + 1, DUVSHIFT) * BPP <= sizeof(vout), \ + "vout buffer too small"); \ + memset(vin, 0, sizeof(vin)); /* for YUY2 and msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(y_buf, u_buf, v_buf, dst_ptr, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, y_buf + np, r); \ + memcpy(vin + 64, u_buf + (np >> UVSHIFT), SS(r, UVSHIFT)); \ + memcpy(vin + 128, v_buf + (np >> UVSHIFT), SS(r, UVSHIFT)); \ + ANY_SIMD(vin, vin + 64, vin + 128, vout, MASK + 1); \ + memcpy(dst_ptr + (np >> DUVSHIFT) * BPP, vout, SS(r, DUVSHIFT) * BPP); \ } // Merge functions. -#ifdef HAS_MERGERGBROW_SSSE3 -ANY31(MergeRGBRow_Any_SSSE3, MergeRGBRow_SSSE3, 0, 0, 3, 15) +#ifdef HAS_MERGERGBROW_AVX2 +ANY31(MergeRGBRow_Any_AVX2, MergeRGBRow_AVX2, 0, 0, 3, 31) #endif #ifdef HAS_MERGERGBROW_NEON ANY31(MergeRGBRow_Any_NEON, MergeRGBRow_NEON, 0, 0, 3, 15) #endif -#ifdef HAS_MERGERGBROW_MMI -ANY31(MergeRGBRow_Any_MMI, MergeRGBRow_MMI, 0, 0, 3, 7) +#ifdef HAS_MERGEXRGBROW_SSE2 +ANY31(MergeXRGBRow_Any_SSE2, MergeXRGBRow_SSE2, 0, 0, 4, 7) +#endif +#ifdef HAS_MERGEXRGBROW_AVX2 +ANY31(MergeXRGBRow_Any_AVX2, MergeXRGBRow_AVX2, 0, 0, 4, 15) +#endif +#ifdef HAS_MERGEXRGBROW_NEON +ANY31(MergeXRGBRow_Any_NEON, MergeXRGBRow_NEON, 0, 0, 4, 15) #endif #ifdef HAS_I422TOYUY2ROW_SSE2 ANY31(I422ToYUY2Row_Any_SSE2, I422ToYUY2Row_SSE2, 1, 1, 4, 15) @@ -106,20 +322,20 @@ ANY31(I422ToUYVYRow_Any_AVX2, I422ToUYVYRow_AVX2, 1, 1, 4, 31) #ifdef HAS_I422TOYUY2ROW_NEON ANY31(I422ToYUY2Row_Any_NEON, I422ToYUY2Row_NEON, 1, 1, 4, 15) #endif -#ifdef HAS_I422TOYUY2ROW_MSA -ANY31(I422ToYUY2Row_Any_MSA, I422ToYUY2Row_MSA, 1, 1, 4, 31) +#ifdef HAS_I422TOYUY2ROW_LSX +ANY31(I422ToYUY2Row_Any_LSX, I422ToYUY2Row_LSX, 1, 1, 4, 15) #endif -#ifdef HAS_I422TOYUY2ROW_MMI -ANY31(I422ToYUY2Row_Any_MMI, I422ToYUY2Row_MMI, 1, 1, 4, 7) +#ifdef HAS_I422TOYUY2ROW_LASX +ANY31(I422ToYUY2Row_Any_LASX, I422ToYUY2Row_LASX, 1, 1, 4, 31) #endif #ifdef HAS_I422TOUYVYROW_NEON ANY31(I422ToUYVYRow_Any_NEON, I422ToUYVYRow_NEON, 1, 1, 4, 15) #endif -#ifdef HAS_I422TOUYVYROW_MSA -ANY31(I422ToUYVYRow_Any_MSA, I422ToUYVYRow_MSA, 1, 1, 4, 31) +#ifdef HAS_I422TOUYVYROW_LSX +ANY31(I422ToUYVYRow_Any_LSX, I422ToUYVYRow_LSX, 1, 1, 4, 15) #endif -#ifdef HAS_I422TOUYVYROW_MMI -ANY31(I422ToUYVYRow_Any_MMI, I422ToUYVYRow_MMI, 1, 1, 4, 7) +#ifdef HAS_I422TOUYVYROW_LASX +ANY31(I422ToUYVYRow_Any_LASX, I422ToUYVYRow_LASX, 1, 1, 4, 31) #endif #ifdef HAS_BLENDPLANEROW_AVX2 ANY31(BlendPlaneRow_Any_AVX2, BlendPlaneRow_AVX2, 0, 0, 1, 31) @@ -127,41 +343,63 @@ ANY31(BlendPlaneRow_Any_AVX2, BlendPlaneRow_AVX2, 0, 0, 1, 31) #ifdef HAS_BLENDPLANEROW_SSSE3 ANY31(BlendPlaneRow_Any_SSSE3, BlendPlaneRow_SSSE3, 0, 0, 1, 7) #endif -#ifdef HAS_BLENDPLANEROW_MMI -ANY31(BlendPlaneRow_Any_MMI, BlendPlaneRow_MMI, 0, 0, 1, 7) +#ifdef HAS_BLENDPLANEROW_NEON +ANY31(BlendPlaneRow_Any_NEON, BlendPlaneRow_NEON, 0, 0, 1, 15) +#endif +#ifdef HAS_BLENDPLANEROW_WASMSIMD +ANY31(BlendPlaneRow_Any_WASMSIMD, BlendPlaneRow_WASMSIMD, 0, 0, 1, 15) #endif #undef ANY31 // Note that odd width replication includes 444 due to implementation // on arm that subsamples 444 to 422 internally. // Any 3 planes to 1 with yuvconstants -#define ANY31C(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, BPP, MASK) \ - void NAMEANY(const uint8_t* y_buf, const uint8_t* u_buf, \ - const uint8_t* v_buf, uint8_t* dst_ptr, \ - const struct YuvConstants* yuvconstants, int width) { \ - SIMD_ALIGNED(uint8_t temp[128 * 4]); \ - memset(temp, 0, 128 * 3); /* for YUY2 and msan */ \ - int r = width & MASK; \ - int n = width & ~MASK; \ - if (n > 0) { \ - ANY_SIMD(y_buf, u_buf, v_buf, dst_ptr, yuvconstants, n); \ - } \ - memcpy(temp, y_buf + n, r); \ - memcpy(temp + 128, u_buf + (n >> UVSHIFT), SS(r, UVSHIFT)); \ - memcpy(temp + 256, v_buf + (n >> UVSHIFT), SS(r, UVSHIFT)); \ - if (width & 1) { \ - temp[128 + SS(r, UVSHIFT)] = temp[128 + SS(r, UVSHIFT) - 1]; \ - temp[256 + SS(r, UVSHIFT)] = temp[256 + SS(r, UVSHIFT) - 1]; \ - } \ - ANY_SIMD(temp, temp + 128, temp + 256, temp + 384, yuvconstants, \ - MASK + 1); \ - memcpy(dst_ptr + (n >> DUVSHIFT) * BPP, temp + 384, \ - SS(r, DUVSHIFT) * BPP); \ +#define ANY31C(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, BPP, MASK) \ + void NAMEANY(const uint8_t* y_buf, const uint8_t* u_buf, \ + const uint8_t* v_buf, uint8_t* dst_ptr, \ + const struct YuvConstants* yuvconstants, int width) { \ + SIMD_ALIGNED(uint8_t vin[128 * 3]); \ + static_assert(MASK + 1 <= sizeof(vin) / 3, "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[128]); \ + static_assert(SS(MASK + 1, DUVSHIFT) * BPP <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for YUY2 and msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(y_buf, u_buf, v_buf, dst_ptr, yuvconstants, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, y_buf + np, r); \ + memcpy(vin + 128, u_buf + (np >> UVSHIFT), SS(r, UVSHIFT)); \ + memcpy(vin + 256, v_buf + (np >> UVSHIFT), SS(r, UVSHIFT)); \ + if (width & 1) { \ + vin[128 + SS(r, UVSHIFT)] = vin[128 + SS(r, UVSHIFT) - 1]; \ + vin[256 + SS(r, UVSHIFT)] = vin[256 + SS(r, UVSHIFT) - 1]; \ + } \ + ANY_SIMD(vin, vin + 128, vin + 256, vout, yuvconstants, MASK + 1); \ + memcpy(dst_ptr + (np >> DUVSHIFT) * BPP, vout, SS(r, DUVSHIFT) * BPP); \ } #ifdef HAS_I422TOARGBROW_SSSE3 ANY31C(I422ToARGBRow_Any_SSSE3, I422ToARGBRow_SSSE3, 1, 0, 4, 7) #endif +#ifdef HAS_I422TORGBAROW_SSSE3 +ANY31C(I422ToRGBARow_Any_SSSE3, I422ToRGBARow_SSSE3, 1, 0, 4, 7) +#endif +#ifdef HAS_I422TOARGB4444ROW_SSSE3 +ANY31C(I422ToARGB4444Row_Any_SSSE3, I422ToARGB4444Row_SSSE3, 1, 0, 2, 7) +#endif +#ifdef HAS_I422TOARGB1555ROW_SSSE3 +ANY31C(I422ToARGB1555Row_Any_SSSE3, I422ToARGB1555Row_SSSE3, 1, 0, 2, 7) +#endif +#ifdef HAS_I422TORGB565ROW_SSSE3 +ANY31C(I422ToRGB565Row_Any_SSSE3, I422ToRGB565Row_SSSE3, 1, 0, 2, 7) +#endif +#ifdef HAS_I422TORGB24ROW_SSSE3 +ANY31C(I422ToRGB24Row_Any_SSSE3, I422ToRGB24Row_SSSE3, 1, 0, 3, 7) +#endif #ifdef HAS_I422TOAR30ROW_SSSE3 ANY31C(I422ToAR30Row_Any_SSSE3, I422ToAR30Row_SSSE3, 1, 0, 4, 7) #endif @@ -170,14 +408,12 @@ ANY31C(I422ToAR30Row_Any_AVX2, I422ToAR30Row_AVX2, 1, 0, 4, 15) #endif #ifdef HAS_I444TOARGBROW_SSSE3 ANY31C(I444ToARGBRow_Any_SSSE3, I444ToARGBRow_SSSE3, 0, 0, 4, 7) -ANY31C(I422ToRGBARow_Any_SSSE3, I422ToRGBARow_SSSE3, 1, 0, 4, 7) -ANY31C(I422ToARGB4444Row_Any_SSSE3, I422ToARGB4444Row_SSSE3, 1, 0, 2, 7) -ANY31C(I422ToARGB1555Row_Any_SSSE3, I422ToARGB1555Row_SSSE3, 1, 0, 2, 7) -ANY31C(I422ToRGB565Row_Any_SSSE3, I422ToRGB565Row_SSSE3, 1, 0, 2, 7) -ANY31C(I422ToRGB24Row_Any_SSSE3, I422ToRGB24Row_SSSE3, 1, 0, 3, 15) -#endif // HAS_I444TOARGBROW_SSSE3 +#endif +#ifdef HAS_I444TORGB24ROW_SSSE3 +ANY31C(I444ToRGB24Row_Any_SSSE3, I444ToRGB24Row_SSSE3, 0, 0, 3, 7) +#endif #ifdef HAS_I422TORGB24ROW_AVX2 -ANY31C(I422ToRGB24Row_Any_AVX2, I422ToRGB24Row_AVX2, 1, 0, 3, 31) +ANY31C(I422ToRGB24Row_Any_AVX2, I422ToRGB24Row_AVX2, 1, 0, 3, 15) #endif #ifdef HAS_I422TOARGBROW_AVX2 ANY31C(I422ToARGBRow_Any_AVX2, I422ToARGBRow_AVX2, 1, 0, 4, 15) @@ -188,6 +424,9 @@ ANY31C(I422ToRGBARow_Any_AVX2, I422ToRGBARow_AVX2, 1, 0, 4, 15) #ifdef HAS_I444TOARGBROW_AVX2 ANY31C(I444ToARGBRow_Any_AVX2, I444ToARGBRow_AVX2, 0, 0, 4, 15) #endif +#ifdef HAS_I444TORGB24ROW_AVX2 +ANY31C(I444ToRGB24Row_Any_AVX2, I444ToRGB24Row_AVX2, 0, 0, 3, 31) +#endif #ifdef HAS_I422TOARGB4444ROW_AVX2 ANY31C(I422ToARGB4444Row_Any_AVX2, I422ToARGB4444Row_AVX2, 1, 0, 2, 15) #endif @@ -197,6 +436,12 @@ ANY31C(I422ToARGB1555Row_Any_AVX2, I422ToARGB1555Row_AVX2, 1, 0, 2, 15) #ifdef HAS_I422TORGB565ROW_AVX2 ANY31C(I422ToRGB565Row_Any_AVX2, I422ToRGB565Row_AVX2, 1, 0, 2, 15) #endif +#ifdef HAS_I444TORGB24ROW_NEON +ANY31C(I444ToRGB24Row_Any_NEON, I444ToRGB24Row_NEON, 0, 0, 3, 7) +#endif +#ifdef HAS_I422TOAR30ROW_NEON +ANY31C(I422ToAR30Row_Any_NEON, I422ToAR30Row_NEON, 1, 0, 4, 7) +#endif #ifdef HAS_I422TOARGBROW_NEON ANY31C(I444ToARGBRow_Any_NEON, I444ToARGBRow_NEON, 0, 0, 4, 7) ANY31C(I422ToARGBRow_Any_NEON, I422ToARGBRow_NEON, 1, 0, 4, 7) @@ -206,36 +451,73 @@ ANY31C(I422ToARGB4444Row_Any_NEON, I422ToARGB4444Row_NEON, 1, 0, 2, 7) ANY31C(I422ToARGB1555Row_Any_NEON, I422ToARGB1555Row_NEON, 1, 0, 2, 7) ANY31C(I422ToRGB565Row_Any_NEON, I422ToRGB565Row_NEON, 1, 0, 2, 7) #endif -#ifdef HAS_I422TOARGBROW_MSA -ANY31C(I444ToARGBRow_Any_MSA, I444ToARGBRow_MSA, 0, 0, 4, 7) -ANY31C(I422ToARGBRow_Any_MSA, I422ToARGBRow_MSA, 1, 0, 4, 7) -ANY31C(I422ToRGBARow_Any_MSA, I422ToRGBARow_MSA, 1, 0, 4, 7) -ANY31C(I422ToRGB24Row_Any_MSA, I422ToRGB24Row_MSA, 1, 0, 3, 15) -ANY31C(I422ToARGB4444Row_Any_MSA, I422ToARGB4444Row_MSA, 1, 0, 2, 7) -ANY31C(I422ToARGB1555Row_Any_MSA, I422ToARGB1555Row_MSA, 1, 0, 2, 7) -ANY31C(I422ToRGB565Row_Any_MSA, I422ToRGB565Row_MSA, 1, 0, 2, 7) +#ifdef HAS_I422TOARGBROW_LSX +ANY31C(I422ToARGBRow_Any_LSX, I422ToARGBRow_LSX, 1, 0, 4, 7) +ANY31C(I422ToRGBARow_Any_LSX, I422ToRGBARow_LSX, 1, 0, 4, 7) +ANY31C(I422ToRGB24Row_Any_LSX, I422ToRGB24Row_LSX, 1, 0, 3, 7) +ANY31C(I422ToRGB565Row_Any_LSX, I422ToRGB565Row_LSX, 1, 0, 2, 7) +ANY31C(I422ToARGB4444Row_Any_LSX, I422ToARGB4444Row_LSX, 1, 0, 2, 7) +ANY31C(I422ToARGB1555Row_Any_LSX, I422ToARGB1555Row_LSX, 1, 0, 2, 7) +#endif +#ifdef HAS_I422TOARGBROW_LASX +ANY31C(I422ToARGBRow_Any_LASX, I422ToARGBRow_LASX, 1, 0, 4, 15) +ANY31C(I422ToRGBARow_Any_LASX, I422ToRGBARow_LASX, 1, 0, 4, 15) +ANY31C(I422ToRGB24Row_Any_LASX, I422ToRGB24Row_LASX, 1, 0, 3, 15) +ANY31C(I422ToRGB565Row_Any_LASX, I422ToRGB565Row_LASX, 1, 0, 2, 15) +ANY31C(I422ToARGB4444Row_Any_LASX, I422ToARGB4444Row_LASX, 1, 0, 2, 15) +ANY31C(I422ToARGB1555Row_Any_LASX, I422ToARGB1555Row_LASX, 1, 0, 2, 15) +#endif +#ifdef HAS_I444TOARGBROW_LSX +ANY31C(I444ToARGBRow_Any_LSX, I444ToARGBRow_LSX, 0, 0, 4, 7) +#endif +#ifdef HAS_I444TOARGBROW_LASX +ANY31C(I444ToARGBRow_Any_LASX, I444ToARGBRow_LASX, 0, 0, 4, 15) +#endif +#ifdef HAS_I422TOARGBROW_WASMSIMD +ANY31C(I422ToARGBRow_Any_WASMSIMD, I422ToARGBRow_WASMSIMD, 1, 0, 4, 7) +#endif +#ifdef HAS_I422TOAR30ROW_WASMSIMD +ANY31C(I422ToAR30Row_Any_WASMSIMD, I422ToAR30Row_WASMSIMD, 1, 0, 4, 7) +#endif +#ifdef HAS_I422TORGB24ROW_WASMSIMD +ANY31C(I422ToRGB24Row_Any_WASMSIMD, I422ToRGB24Row_WASMSIMD, 1, 0, 3, 15) +#endif +#ifdef HAS_I422TORGB565ROW_WASMSIMD +ANY31C(I422ToRGB565Row_Any_WASMSIMD, I422ToRGB565Row_WASMSIMD, 1, 0, 2, 7) +#endif +#ifdef HAS_I422TOARGB1555ROW_WASMSIMD +ANY31C(I422ToARGB1555Row_Any_WASMSIMD, I422ToARGB1555Row_WASMSIMD, 1, 0, 2, 7) +#endif +#ifdef HAS_I422TOARGB4444ROW_WASMSIMD +ANY31C(I422ToARGB4444Row_Any_WASMSIMD, I422ToARGB4444Row_WASMSIMD, 1, 0, 2, 7) #endif #undef ANY31C // Any 3 planes of 16 bit to 1 with yuvconstants // TODO(fbarchard): consider sharing this code with ANY31C -#define ANY31CT(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, T, SBPP, BPP, MASK) \ - void NAMEANY(const T* y_buf, const T* u_buf, const T* v_buf, \ - uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, \ - int width) { \ - SIMD_ALIGNED(T temp[16 * 3]); \ - SIMD_ALIGNED(uint8_t out[64]); \ - memset(temp, 0, 16 * 3 * SBPP); /* for YUY2 and msan */ \ - int r = width & MASK; \ - int n = width & ~MASK; \ - if (n > 0) { \ - ANY_SIMD(y_buf, u_buf, v_buf, dst_ptr, yuvconstants, n); \ - } \ - memcpy(temp, y_buf + n, r * SBPP); \ - memcpy(temp + 16, u_buf + (n >> UVSHIFT), SS(r, UVSHIFT) * SBPP); \ - memcpy(temp + 32, v_buf + (n >> UVSHIFT), SS(r, UVSHIFT) * SBPP); \ - ANY_SIMD(temp, temp + 16, temp + 32, out, yuvconstants, MASK + 1); \ - memcpy(dst_ptr + (n >> DUVSHIFT) * BPP, out, SS(r, DUVSHIFT) * BPP); \ +#define ANY31CT(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, T, SBPP, BPP, MASK) \ + void NAMEANY(const T* y_buf, const T* u_buf, const T* v_buf, \ + uint8_t* dst_ptr, const struct YuvConstants* yuvconstants, \ + int width) { \ + SIMD_ALIGNED(T vin[16 * 3]); \ + static_assert((MASK + 1) * SBPP <= sizeof(vin) / 3, \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[64]); \ + static_assert(SS(MASK + 1, DUVSHIFT) * BPP <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for YUY2 and msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(y_buf, u_buf, v_buf, dst_ptr, yuvconstants, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, y_buf + np, r * SBPP); \ + memcpy(vin + 16, u_buf + (np >> UVSHIFT), SS(r, UVSHIFT) * SBPP); \ + memcpy(vin + 32, v_buf + (np >> UVSHIFT), SS(r, UVSHIFT) * SBPP); \ + ANY_SIMD(vin, vin + 16, vin + 32, vout, yuvconstants, MASK + 1); \ + memcpy(dst_ptr + (np >> DUVSHIFT) * BPP, vout, SS(r, DUVSHIFT) * BPP); \ } #ifdef HAS_I210TOAR30ROW_SSSE3 @@ -250,24 +532,143 @@ ANY31CT(I210ToARGBRow_Any_AVX2, I210ToARGBRow_AVX2, 1, 0, uint16_t, 2, 4, 15) #ifdef HAS_I210TOAR30ROW_AVX2 ANY31CT(I210ToAR30Row_Any_AVX2, I210ToAR30Row_AVX2, 1, 0, uint16_t, 2, 4, 15) #endif +#ifdef HAS_I410TOAR30ROW_SSSE3 +ANY31CT(I410ToAR30Row_Any_SSSE3, I410ToAR30Row_SSSE3, 0, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_I410TOARGBROW_SSSE3 +ANY31CT(I410ToARGBRow_Any_SSSE3, I410ToARGBRow_SSSE3, 0, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_I410TOARGBROW_AVX2 +ANY31CT(I410ToARGBRow_Any_AVX2, I410ToARGBRow_AVX2, 0, 0, uint16_t, 2, 4, 15) +#endif +#ifdef HAS_I410TOAR30ROW_AVX2 +ANY31CT(I410ToAR30Row_Any_AVX2, I410ToAR30Row_AVX2, 0, 0, uint16_t, 2, 4, 15) +#endif +#ifdef HAS_I212TOAR30ROW_SSSE3 +ANY31CT(I212ToAR30Row_Any_SSSE3, I212ToAR30Row_SSSE3, 1, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_I212TOARGBROW_SSSE3 +ANY31CT(I212ToARGBRow_Any_SSSE3, I212ToARGBRow_SSSE3, 1, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_I212TOARGBROW_AVX2 +ANY31CT(I212ToARGBRow_Any_AVX2, I212ToARGBRow_AVX2, 1, 0, uint16_t, 2, 4, 15) +#endif +#ifdef HAS_I212TOAR30ROW_AVX2 +ANY31CT(I212ToAR30Row_Any_AVX2, I212ToAR30Row_AVX2, 1, 0, uint16_t, 2, 4, 15) +#endif +#ifdef HAS_I210TOARGBROW_NEON +ANY31CT(I210ToARGBRow_Any_NEON, I210ToARGBRow_NEON, 1, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_I410TOARGBROW_NEON +ANY31CT(I410ToARGBRow_Any_NEON, I410ToARGBRow_NEON, 0, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_I210TOAR30ROW_NEON +ANY31CT(I210ToAR30Row_Any_NEON, I210ToAR30Row_NEON, 1, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_I410TOAR30ROW_NEON +ANY31CT(I410ToAR30Row_Any_NEON, I410ToAR30Row_NEON, 0, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_I212TOARGBROW_NEON +ANY31CT(I212ToARGBRow_Any_NEON, I212ToARGBRow_NEON, 1, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_I212TOAR30ROW_NEON +ANY31CT(I212ToAR30Row_Any_NEON, I212ToAR30Row_NEON, 1, 0, uint16_t, 2, 4, 7) +#endif #undef ANY31CT +// Any 3 planes to 1 plane with parameter +#define ANY31PT(NAMEANY, ANY_SIMD, STYPE, SBPP, DTYPE, BPP, MASK) \ + void NAMEANY(const STYPE* r_buf, const STYPE* g_buf, const STYPE* b_buf, \ + DTYPE* dst_ptr, int depth, int width) { \ + SIMD_ALIGNED(STYPE vin[16 * 3]); \ + static_assert((MASK + 1) * SBPP <= sizeof(vin) / 3, \ + "vin buffer too small"); \ + SIMD_ALIGNED(DTYPE vout[64]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for YUY2 and msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(r_buf, g_buf, b_buf, dst_ptr, depth, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, r_buf + np, r * SBPP); \ + memcpy(vin + 16, g_buf + np, r * SBPP); \ + memcpy(vin + 32, b_buf + np, r * SBPP); \ + ANY_SIMD(vin, vin + 16, vin + 32, vout, depth, MASK + 1); \ + memcpy((uint8_t*)dst_ptr + np * BPP, vout, r * BPP); \ + } + +#ifdef HAS_MERGEXR30ROW_AVX2 +ANY31PT(MergeXR30Row_Any_AVX2, MergeXR30Row_AVX2, uint16_t, 2, uint8_t, 4, 15) +#endif + +#ifdef HAS_MERGEXR30ROW_NEON +ANY31PT(MergeXR30Row_Any_NEON, MergeXR30Row_NEON, uint16_t, 2, uint8_t, 4, 3) +ANY31PT(MergeXR30Row_10_Any_NEON, + MergeXR30Row_10_NEON, + uint16_t, + 2, + uint8_t, + 4, + 7) +#endif + +#ifdef HAS_MERGEXR64ROW_AVX2 +ANY31PT(MergeXR64Row_Any_AVX2, MergeXR64Row_AVX2, uint16_t, 2, uint16_t, 8, 15) +#endif + +#ifdef HAS_MERGEXR64ROW_NEON +ANY31PT(MergeXR64Row_Any_NEON, MergeXR64Row_NEON, uint16_t, 2, uint16_t, 8, 7) +#endif + +#ifdef HAS_MERGEXRGB16TO8ROW_AVX2 +ANY31PT(MergeXRGB16To8Row_Any_AVX2, + MergeXRGB16To8Row_AVX2, + uint16_t, + 2, + uint8_t, + 4, + 15) +#endif + +#ifdef HAS_MERGEXRGB16TO8ROW_NEON +ANY31PT(MergeXRGB16To8Row_Any_NEON, + MergeXRGB16To8Row_NEON, + uint16_t, + 2, + uint8_t, + 4, + 7) +#endif + +#undef ANY31PT + // Any 2 planes to 1. #define ANY21(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, SBPP2, BPP, MASK) \ void NAMEANY(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, \ int width) { \ - SIMD_ALIGNED(uint8_t temp[64 * 3]); \ - memset(temp, 0, 64 * 2); /* for msan */ \ + SIMD_ALIGNED(uint8_t vin[128 * 2]); \ + static_assert((MASK + 1) * SBPP <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + static_assert(SS(MASK + 1, UVSHIFT) * SBPP2 <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[128]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ int r = width & MASK; \ int n = width & ~MASK; \ if (n > 0) { \ ANY_SIMD(y_buf, uv_buf, dst_ptr, n); \ } \ - memcpy(temp, y_buf + n * SBPP, r * SBPP); \ - memcpy(temp + 64, uv_buf + (n >> UVSHIFT) * SBPP2, \ + ptrdiff_t np = n; \ + memcpy(vin, y_buf + np * SBPP, r * SBPP); \ + memcpy(vin + 128, uv_buf + (np >> UVSHIFT) * SBPP2, \ SS(r, UVSHIFT) * SBPP2); \ - ANY_SIMD(temp, temp + 64, temp + 128, MASK + 1); \ - memcpy(dst_ptr + n * BPP, temp + 128, r * BPP); \ + ANY_SIMD(vin, vin + 128, vout, MASK + 1); \ + memcpy(dst_ptr + np * BPP, vout, r * BPP); \ } // Merge functions. @@ -275,20 +676,23 @@ ANY31CT(I210ToAR30Row_Any_AVX2, I210ToAR30Row_AVX2, 1, 0, uint16_t, 2, 4, 15) ANY21(MergeUVRow_Any_SSE2, MergeUVRow_SSE2, 0, 1, 1, 2, 15) #endif #ifdef HAS_MERGEUVROW_AVX2 -ANY21(MergeUVRow_Any_AVX2, MergeUVRow_AVX2, 0, 1, 1, 2, 31) +ANY21(MergeUVRow_Any_AVX2, MergeUVRow_AVX2, 0, 1, 1, 2, 15) #endif #ifdef HAS_MERGEUVROW_NEON ANY21(MergeUVRow_Any_NEON, MergeUVRow_NEON, 0, 1, 1, 2, 15) #endif -#ifdef HAS_MERGEUVROW_MSA -ANY21(MergeUVRow_Any_MSA, MergeUVRow_MSA, 0, 1, 1, 2, 15) +#ifdef HAS_MERGEUVROW_LSX +ANY21(MergeUVRow_Any_LSX, MergeUVRow_LSX, 0, 1, 1, 2, 15) #endif -#ifdef HAS_MERGEUVROW_MMI -ANY21(MergeUVRow_Any_MMI, MergeUVRow_MMI, 0, 1, 1, 2, 7) +#ifdef HAS_MERGEUVROW_LASX +ANY21(MergeUVRow_Any_LASX, MergeUVRow_LASX, 0, 1, 1, 2, 31) #endif #ifdef HAS_NV21TOYUV24ROW_NEON ANY21(NV21ToYUV24Row_Any_NEON, NV21ToYUV24Row_NEON, 1, 1, 2, 3, 15) #endif +#ifdef HAS_NV21TOYUV24ROW_SSSE3 +ANY21(NV21ToYUV24Row_Any_SSSE3, NV21ToYUV24Row_SSSE3, 1, 1, 2, 3, 15) +#endif #ifdef HAS_NV21TOYUV24ROW_AVX2 ANY21(NV21ToYUV24Row_Any_AVX2, NV21ToYUV24Row_AVX2, 1, 1, 2, 3, 31) #endif @@ -320,78 +724,186 @@ ANY21(ARGBAddRow_Any_NEON, ARGBAddRow_NEON, 0, 4, 4, 4, 7) #ifdef HAS_ARGBSUBTRACTROW_NEON ANY21(ARGBSubtractRow_Any_NEON, ARGBSubtractRow_NEON, 0, 4, 4, 4, 7) #endif -#ifdef HAS_ARGBMULTIPLYROW_MSA -ANY21(ARGBMultiplyRow_Any_MSA, ARGBMultiplyRow_MSA, 0, 4, 4, 4, 3) +#ifdef HAS_ARGBBLENDROW_LSX +ANY21(ARGBBlendRow_Any_LSX, ARGBBlendRow_LSX, 0, 4, 4, 4, 3) #endif -#ifdef HAS_ARGBMULTIPLYROW_MMI -ANY21(ARGBMultiplyRow_Any_MMI, ARGBMultiplyRow_MMI, 0, 4, 4, 4, 1) +#ifdef HAS_ARGBBLENDROW_LASX +ANY21(ARGBBlendRow_Any_LASX, ARGBBlendRow_LASX, 0, 4, 4, 4, 7) #endif -#ifdef HAS_ARGBADDROW_MSA -ANY21(ARGBAddRow_Any_MSA, ARGBAddRow_MSA, 0, 4, 4, 4, 7) +#ifdef HAS_ARGBMULTIPLYROW_LSX +ANY21(ARGBMultiplyRow_Any_LSX, ARGBMultiplyRow_LSX, 0, 4, 4, 4, 3) #endif -#ifdef HAS_ARGBADDROW_MMI -ANY21(ARGBAddRow_Any_MMI, ARGBAddRow_MMI, 0, 4, 4, 4, 1) +#ifdef HAS_ARGBMULTIPLYROW_LASX +ANY21(ARGBMultiplyRow_Any_LASX, ARGBMultiplyRow_LASX, 0, 4, 4, 4, 7) #endif -#ifdef HAS_ARGBSUBTRACTROW_MSA -ANY21(ARGBSubtractRow_Any_MSA, ARGBSubtractRow_MSA, 0, 4, 4, 4, 7) +#ifdef HAS_ARGBADDROW_LSX +ANY21(ARGBAddRow_Any_LSX, ARGBAddRow_LSX, 0, 4, 4, 4, 3) #endif -#ifdef HAS_ARGBSUBTRACTROW_MMI -ANY21(ARGBSubtractRow_Any_MMI, ARGBSubtractRow_MMI, 0, 4, 4, 4, 1) +#ifdef HAS_ARGBADDROW_LASX +ANY21(ARGBAddRow_Any_LASX, ARGBAddRow_LASX, 0, 4, 4, 4, 7) #endif -#ifdef HAS_SOBELROW_SSE2 -ANY21(SobelRow_Any_SSE2, SobelRow_SSE2, 0, 1, 1, 4, 15) +#ifdef HAS_ARGBSUBTRACTROW_LSX +ANY21(ARGBSubtractRow_Any_LSX, ARGBSubtractRow_LSX, 0, 4, 4, 4, 3) +#endif +#ifdef HAS_ARGBSUBTRACTROW_LASX +ANY21(ARGBSubtractRow_Any_LASX, ARGBSubtractRow_LASX, 0, 4, 4, 4, 7) +#endif +#ifdef HAS_ARGBALPHABLENDROW_SSSE3 +ANY21(ARGBAlphaBlendRow_Any_SSSE3, ARGBAlphaBlendRow_SSSE3, 0, 4, 4, 4, 3) +#endif +#ifdef HAS_ARGBALPHABLENDROW_AVX2 +ANY21(ARGBAlphaBlendRow_Any_AVX2, ARGBAlphaBlendRow_AVX2, 0, 4, 4, 4, 7) +#endif +#ifdef HAS_ARGBALPHABLENDROW_NEON +ANY21(ARGBAlphaBlendRow_Any_NEON, ARGBAlphaBlendRow_NEON, 0, 4, 4, 4, 7) +#endif +#ifdef HAS_ARGBALPHABLENDROW_LSX +ANY21(ARGBAlphaBlendRow_Any_LSX, ARGBAlphaBlendRow_LSX, 0, 4, 4, 4, 3) +#endif +#ifdef HAS_ARGBALPHABLENDROW_LASX +ANY21(ARGBAlphaBlendRow_Any_LASX, ARGBAlphaBlendRow_LASX, 0, 4, 4, 4, 7) +#endif +#ifdef HAS_ARGBALPHABLENDROW_WASMSIMD +ANY21(ARGBAlphaBlendRow_Any_WASMSIMD, ARGBAlphaBlendRow_WASMSIMD, 0, 4, 4, 4, 3) +#endif +#ifdef HAS_SOBELROW_AVX2 +ANY21(SobelRow_Any_AVX2, SobelRow_AVX2, 0, 1, 1, 4, 15) #endif #ifdef HAS_SOBELROW_NEON ANY21(SobelRow_Any_NEON, SobelRow_NEON, 0, 1, 1, 4, 7) #endif -#ifdef HAS_SOBELROW_MSA -ANY21(SobelRow_Any_MSA, SobelRow_MSA, 0, 1, 1, 4, 15) +#ifdef HAS_SOBELROW_LSX +ANY21(SobelRow_Any_LSX, SobelRow_LSX, 0, 1, 1, 4, 7) #endif -#ifdef HAS_SOBELROW_MMI -ANY21(SobelRow_Any_MMI, SobelRow_MMI, 0, 1, 1, 4, 7) +#ifdef HAS_SOBELROW_LASX +ANY21(SobelRow_Any_LASX, SobelRow_LASX, 0, 1, 1, 4, 15) #endif -#ifdef HAS_SOBELTOPLANEROW_SSE2 -ANY21(SobelToPlaneRow_Any_SSE2, SobelToPlaneRow_SSE2, 0, 1, 1, 1, 15) +#ifdef HAS_SOBELTOPLANEROW_AVX2 +ANY21(SobelToPlaneRow_Any_AVX2, SobelToPlaneRow_AVX2, 0, 1, 1, 1, 31) #endif #ifdef HAS_SOBELTOPLANEROW_NEON ANY21(SobelToPlaneRow_Any_NEON, SobelToPlaneRow_NEON, 0, 1, 1, 1, 15) #endif -#ifdef HAS_SOBELTOPLANEROW_MSA -ANY21(SobelToPlaneRow_Any_MSA, SobelToPlaneRow_MSA, 0, 1, 1, 1, 31) +#ifdef HAS_SOBELTOPLANEROW_LSX +ANY21(SobelToPlaneRow_Any_LSX, SobelToPlaneRow_LSX, 0, 1, 1, 1, 15) #endif -#ifdef HAS_SOBELTOPLANEROW_MMI -ANY21(SobelToPlaneRow_Any_MMI, SobelToPlaneRow_MMI, 0, 1, 1, 1, 7) +#ifdef HAS_SOBELTOPLANEROW_LASX +ANY21(SobelToPlaneRow_Any_LASX, SobelToPlaneRow_LASX, 0, 1, 1, 1, 31) #endif -#ifdef HAS_SOBELXYROW_SSE2 -ANY21(SobelXYRow_Any_SSE2, SobelXYRow_SSE2, 0, 1, 1, 4, 15) +#ifdef HAS_SOBELXYROW_AVX2 +ANY21(SobelXYRow_Any_AVX2, SobelXYRow_AVX2, 0, 1, 1, 4, 15) #endif #ifdef HAS_SOBELXYROW_NEON ANY21(SobelXYRow_Any_NEON, SobelXYRow_NEON, 0, 1, 1, 4, 7) #endif -#ifdef HAS_SOBELXYROW_MSA -ANY21(SobelXYRow_Any_MSA, SobelXYRow_MSA, 0, 1, 1, 4, 15) +#ifdef HAS_SOBELXYROW_LSX +ANY21(SobelXYRow_Any_LSX, SobelXYRow_LSX, 0, 1, 1, 4, 7) #endif -#ifdef HAS_SOBELXYROW_MMI -ANY21(SobelXYRow_Any_MMI, SobelXYRow_MMI, 0, 1, 1, 4, 7) +#ifdef HAS_SOBELXYROW_LASX +ANY21(SobelXYRow_Any_LASX, SobelXYRow_LASX, 0, 1, 1, 4, 15) +#endif +#ifdef HAS_MERGEUVROW_WASMSIMD +ANY21(MergeUVRow_Any_WASMSIMD, MergeUVRow_WASMSIMD, 0, 1, 1, 2, 15) #endif #undef ANY21 +// Any 2 planes to 1 with stride +// width is measured in source pixels. 4 bytes contains 2 pixels +#define ANY21S(NAMEANY, ANY_SIMD, SBPP, BPP, MASK) \ + void NAMEANY(const uint8_t* src_yuy2, int stride_yuy2, uint8_t* dst_uv, \ + int width) { \ + SIMD_ALIGNED(uint8_t vin[(MASK + 1) * SBPP * 2]); \ + SIMD_ALIGNED(uint8_t vout[(MASK + 1) * BPP]); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int awidth = (width + 1) / 2; \ + int r = awidth & MASK; \ + int n = awidth & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_yuy2, stride_yuy2, dst_uv, n * 2); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_yuy2 + np * SBPP, r * SBPP); \ + memcpy(vin + (MASK + 1) * SBPP, src_yuy2 + stride_yuy2 + np * SBPP, \ + r * SBPP); \ + ANY_SIMD(vin, (MASK + 1) * SBPP, vout, (MASK + 1) * 2); \ + memcpy(dst_uv + np * BPP, vout, r * BPP); \ + } + +#ifdef HAS_YUY2TONVUVROW_NEON +ANY21S(YUY2ToNVUVRow_Any_NEON, YUY2ToNVUVRow_NEON, 4, 2, 7) +#endif +#ifdef HAS_YUY2TONVUVROW_SSE2 +ANY21S(YUY2ToNVUVRow_Any_SSE2, YUY2ToNVUVRow_SSE2, 4, 2, 7) +#endif +#ifdef HAS_YUY2TONVUVROW_AVX2 +ANY21S(YUY2ToNVUVRow_Any_AVX2, YUY2ToNVUVRow_AVX2, 4, 2, 15) +#endif +#undef ANY21S + +// Any 2 planes to 1 half-size merged UV row with stride (2 rows of U and V). +#define ANY21HMS(NAMEANY, ANY_SIMD, MASK) \ + void NAMEANY(const uint8_t* src_u, int src_stride_u, const uint8_t* src_v, \ + int src_stride_v, uint8_t* dst_uv, int width) { \ + SIMD_ALIGNED(uint8_t vin[64 * 4]); \ + static_assert(MASK + 1 <= sizeof(vin) / 4, "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[64]); \ + static_assert(SS(MASK + 1, 1) * 2 <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_u, src_stride_u, src_v, src_stride_v, dst_uv, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_u + np, r); \ + memcpy(vin + 64, src_u + src_stride_u + np, r); \ + memcpy(vin + 128, src_v + np, r); \ + memcpy(vin + 192, src_v + src_stride_v + np, r); \ + if (r & 1) { \ + vin[r] = vin[r - 1]; \ + vin[64 + r] = vin[64 + r - 1]; \ + vin[128 + r] = vin[128 + r - 1]; \ + vin[192 + r] = vin[192 + r - 1]; \ + } \ + ANY_SIMD(vin, 64, vin + 128, 64, vout, MASK + 1); \ + memcpy(dst_uv + (np >> 1) * 2, vout, SS(r, 1) * 2); \ + } + +#ifdef HAS_HALFMERGEUVROW_SSSE3 +ANY21HMS(HalfMergeUVRow_Any_SSSE3, HalfMergeUVRow_SSSE3, 15) +#endif +#ifdef HAS_HALFMERGEUVROW_AVX2 +ANY21HMS(HalfMergeUVRow_Any_AVX2, HalfMergeUVRow_AVX2, 31) +#endif +#undef ANY21HMS + // Any 2 planes to 1 with yuvconstants #define ANY21C(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, SBPP2, BPP, MASK) \ void NAMEANY(const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* dst_ptr, \ const struct YuvConstants* yuvconstants, int width) { \ - SIMD_ALIGNED(uint8_t temp[128 * 3]); \ - memset(temp, 0, 128 * 2); /* for msan */ \ + SIMD_ALIGNED(uint8_t vin[128 * 2]); \ + static_assert((MASK + 1) * SBPP <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + static_assert(SS(MASK + 1, UVSHIFT) * SBPP2 <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[128]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ int r = width & MASK; \ int n = width & ~MASK; \ if (n > 0) { \ ANY_SIMD(y_buf, uv_buf, dst_ptr, yuvconstants, n); \ } \ - memcpy(temp, y_buf + n * SBPP, r * SBPP); \ - memcpy(temp + 128, uv_buf + (n >> UVSHIFT) * SBPP2, \ + ptrdiff_t np = n; \ + memcpy(vin, y_buf + np * SBPP, r * SBPP); \ + memcpy(vin + 128, uv_buf + (np >> UVSHIFT) * SBPP2, \ SS(r, UVSHIFT) * SBPP2); \ - ANY_SIMD(temp, temp + 128, temp + 256, yuvconstants, MASK + 1); \ - memcpy(dst_ptr + n * BPP, temp + 256, r * BPP); \ + ANY_SIMD(vin, vin + 128, vout, yuvconstants, MASK + 1); \ + memcpy(dst_ptr + np * BPP, vout, r * BPP); \ } // Biplanar to RGB. @@ -404,8 +916,11 @@ ANY21C(NV12ToARGBRow_Any_AVX2, NV12ToARGBRow_AVX2, 1, 1, 2, 4, 15) #ifdef HAS_NV12TOARGBROW_NEON ANY21C(NV12ToARGBRow_Any_NEON, NV12ToARGBRow_NEON, 1, 1, 2, 4, 7) #endif -#ifdef HAS_NV12TOARGBROW_MSA -ANY21C(NV12ToARGBRow_Any_MSA, NV12ToARGBRow_MSA, 1, 1, 2, 4, 7) +#ifdef HAS_NV12TOARGBROW_LSX +ANY21C(NV12ToARGBRow_Any_LSX, NV12ToARGBRow_LSX, 1, 1, 2, 4, 7) +#endif +#ifdef HAS_NV12TOARGBROW_LASX +ANY21C(NV12ToARGBRow_Any_LASX, NV12ToARGBRow_LASX, 1, 1, 2, 4, 15) #endif #ifdef HAS_NV21TOARGBROW_SSSE3 ANY21C(NV21ToARGBRow_Any_SSSE3, NV21ToARGBRow_SSSE3, 1, 1, 2, 4, 7) @@ -416,8 +931,11 @@ ANY21C(NV21ToARGBRow_Any_AVX2, NV21ToARGBRow_AVX2, 1, 1, 2, 4, 15) #ifdef HAS_NV21TOARGBROW_NEON ANY21C(NV21ToARGBRow_Any_NEON, NV21ToARGBRow_NEON, 1, 1, 2, 4, 7) #endif -#ifdef HAS_NV21TOARGBROW_MSA -ANY21C(NV21ToARGBRow_Any_MSA, NV21ToARGBRow_MSA, 1, 1, 2, 4, 7) +#ifdef HAS_NV21TOARGBROW_LSX +ANY21C(NV21ToARGBRow_Any_LSX, NV21ToARGBRow_LSX, 1, 1, 2, 4, 7) +#endif +#ifdef HAS_NV21TOARGBROW_LASX +ANY21C(NV21ToARGBRow_Any_LASX, NV21ToARGBRow_LASX, 1, 1, 2, 4, 15) #endif #ifdef HAS_NV12TORGB24ROW_NEON ANY21C(NV12ToRGB24Row_Any_NEON, NV12ToRGB24Row_NEON, 1, 1, 2, 3, 7) @@ -446,24 +964,138 @@ ANY21C(NV12ToRGB565Row_Any_AVX2, NV12ToRGB565Row_AVX2, 1, 1, 2, 2, 15) #ifdef HAS_NV12TORGB565ROW_NEON ANY21C(NV12ToRGB565Row_Any_NEON, NV12ToRGB565Row_NEON, 1, 1, 2, 2, 7) #endif -#ifdef HAS_NV12TORGB565ROW_MSA -ANY21C(NV12ToRGB565Row_Any_MSA, NV12ToRGB565Row_MSA, 1, 1, 2, 2, 7) +#ifdef HAS_NV12TORGB565ROW_LSX +ANY21C(NV12ToRGB565Row_Any_LSX, NV12ToRGB565Row_LSX, 1, 1, 2, 2, 7) +#endif +#ifdef HAS_NV12TORGB565ROW_LASX +ANY21C(NV12ToRGB565Row_Any_LASX, NV12ToRGB565Row_LASX, 1, 1, 2, 2, 15) +#endif +#ifdef HAS_NV12TOARGBROW_WASMSIMD +ANY21C(NV12ToARGBRow_Any_WASMSIMD, NV12ToARGBRow_WASMSIMD, 1, 1, 2, 4, 7) +#endif +#ifdef HAS_NV21TOARGBROW_WASMSIMD +ANY21C(NV21ToARGBRow_Any_WASMSIMD, NV21ToARGBRow_WASMSIMD, 1, 1, 2, 4, 7) +#endif +#ifdef HAS_NV12TORGB565ROW_WASMSIMD +ANY21C(NV12ToRGB565Row_Any_WASMSIMD, NV12ToRGB565Row_WASMSIMD, 1, 1, 2, 2, 7) #endif #undef ANY21C +// Any 2 planes of 16 bit to 1 with yuvconstants +#define ANY21CT(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, T, SBPP, BPP, MASK) \ + void NAMEANY(const T* y_buf, const T* uv_buf, uint8_t* dst_ptr, \ + const struct YuvConstants* yuvconstants, int width) { \ + SIMD_ALIGNED(T vin[32 * 2]); \ + static_assert(SS(MASK + 1, UVSHIFT) * SBPP * 2 <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[64]); \ + static_assert(SS(MASK + 1, DUVSHIFT) * BPP <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(y_buf, uv_buf, dst_ptr, yuvconstants, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, y_buf + np, r * SBPP); \ + memcpy(vin + 32, uv_buf + 2 * (np >> UVSHIFT), SS(r, UVSHIFT) * SBPP * 2); \ + ANY_SIMD(vin, vin + 32, vout, yuvconstants, MASK + 1); \ + memcpy(dst_ptr + (np >> DUVSHIFT) * BPP, vout, SS(r, DUVSHIFT) * BPP); \ + } + +#ifdef HAS_P210TOAR30ROW_SSSE3 +ANY21CT(P210ToAR30Row_Any_SSSE3, P210ToAR30Row_SSSE3, 1, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_P210TOARGBROW_SSSE3 +ANY21CT(P210ToARGBRow_Any_SSSE3, P210ToARGBRow_SSSE3, 1, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_P210TOARGBROW_AVX2 +ANY21CT(P210ToARGBRow_Any_AVX2, P210ToARGBRow_AVX2, 1, 0, uint16_t, 2, 4, 15) +#endif +#ifdef HAS_P210TOAR30ROW_AVX2 +ANY21CT(P210ToAR30Row_Any_AVX2, P210ToAR30Row_AVX2, 1, 0, uint16_t, 2, 4, 15) +#endif +#ifdef HAS_P210TOAR30ROW_NEON +ANY21CT(P210ToAR30Row_Any_NEON, P210ToAR30Row_NEON, 1, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_P210TOARGBROW_NEON +ANY21CT(P210ToARGBRow_Any_NEON, P210ToARGBRow_NEON, 1, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_P410TOAR30ROW_SSSE3 +ANY21CT(P410ToAR30Row_Any_SSSE3, P410ToAR30Row_SSSE3, 0, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_P410TOARGBROW_SSSE3 +ANY21CT(P410ToARGBRow_Any_SSSE3, P410ToARGBRow_SSSE3, 0, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_P410TOARGBROW_AVX2 +ANY21CT(P410ToARGBRow_Any_AVX2, P410ToARGBRow_AVX2, 0, 0, uint16_t, 2, 4, 15) +#endif +#ifdef HAS_P410TOAR30ROW_AVX2 +ANY21CT(P410ToAR30Row_Any_AVX2, P410ToAR30Row_AVX2, 0, 0, uint16_t, 2, 4, 15) +#endif +#ifdef HAS_P410TOAR30ROW_NEON +ANY21CT(P410ToAR30Row_Any_NEON, P410ToAR30Row_NEON, 0, 0, uint16_t, 2, 4, 7) +#endif +#ifdef HAS_P410TOARGBROW_NEON +ANY21CT(P410ToARGBRow_Any_NEON, P410ToARGBRow_NEON, 0, 0, uint16_t, 2, 4, 7) +#endif + +#undef ANY21CT + +// Any 2 16 bit planes with parameter to 1 +#define ANY21PT(NAMEANY, ANY_SIMD, T, BPP, MASK) \ + void NAMEANY(const T* src_u, const T* src_v, T* dst_uv, int depth, \ + int width) { \ + SIMD_ALIGNED(T vin[16 * 2]); \ + static_assert((MASK + 1) * BPP <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + SIMD_ALIGNED(T vout[16]); \ + static_assert((MASK + 1) * BPP * 2 <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_u, src_v, dst_uv, depth, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_u + np, r * BPP); \ + memcpy(vin + 16, src_v + np, r * BPP); \ + ANY_SIMD(vin, vin + 16, vout, depth, MASK + 1); \ + memcpy(dst_uv + np * 2, vout, r * BPP * 2); \ + } + +#ifdef HAS_MERGEUVROW_16_AVX2 +ANY21PT(MergeUVRow_16_Any_AVX2, MergeUVRow_16_AVX2, uint16_t, 2, 7) +#endif +#ifdef HAS_MERGEUVROW_16_NEON +ANY21PT(MergeUVRow_16_Any_NEON, MergeUVRow_16_NEON, uint16_t, 2, 7) +#endif + +#undef ANY21CT + // Any 1 to 1. -#define ANY11(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, BPP, MASK) \ - void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_ptr, int width) { \ - SIMD_ALIGNED(uint8_t temp[128 * 2]); \ - memset(temp, 0, 128); /* for YUY2 and msan */ \ - int r = width & MASK; \ - int n = width & ~MASK; \ - if (n > 0) { \ - ANY_SIMD(src_ptr, dst_ptr, n); \ - } \ - memcpy(temp, src_ptr + (n >> UVSHIFT) * SBPP, SS(r, UVSHIFT) * SBPP); \ - ANY_SIMD(temp, temp + 128, MASK + 1); \ - memcpy(dst_ptr + n * BPP, temp + 128, r * BPP); \ +#define ANY11(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, BPP, MASK) \ + void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_ptr, int width) { \ + SIMD_ALIGNED(uint8_t vin[256]); \ + static_assert(SS(MASK + 1, UVSHIFT) * SBPP <= sizeof(vin), \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[256]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for YUY2 and msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, dst_ptr, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + (np >> UVSHIFT) * SBPP, SS(r, UVSHIFT) * SBPP); \ + ANY_SIMD(vin, vout, MASK + 1); \ + memcpy(dst_ptr + np * BPP, vout, r * BPP); \ } #ifdef HAS_COPYROW_AVX @@ -475,32 +1107,59 @@ ANY11(CopyRow_Any_SSE2, CopyRow_SSE2, 0, 1, 1, 31) #ifdef HAS_COPYROW_NEON ANY11(CopyRow_Any_NEON, CopyRow_NEON, 0, 1, 1, 31) #endif +#ifdef HAS_COPYROW_LSX +ANY11(CopyRow_Any_LSX, CopyRow_LSX, 0, 1, 1, 15) +#endif +#ifdef HAS_COPYROW_LASX +ANY11(CopyRow_Any_LASX, CopyRow_LASX, 0, 1, 1, 31) +#endif #if defined(HAS_ARGBTORGB24ROW_SSSE3) ANY11(ARGBToRGB24Row_Any_SSSE3, ARGBToRGB24Row_SSSE3, 0, 4, 3, 15) ANY11(ARGBToRAWRow_Any_SSSE3, ARGBToRAWRow_SSSE3, 0, 4, 3, 15) -ANY11(ARGBToRGB565Row_Any_SSE2, ARGBToRGB565Row_SSE2, 0, 4, 2, 3) -ANY11(ARGBToARGB1555Row_Any_SSE2, ARGBToARGB1555Row_SSE2, 0, 4, 2, 3) -ANY11(ARGBToARGB4444Row_Any_SSE2, ARGBToARGB4444Row_SSE2, 0, 4, 2, 3) + #endif #if defined(HAS_ARGBTORGB24ROW_AVX2) ANY11(ARGBToRGB24Row_Any_AVX2, ARGBToRGB24Row_AVX2, 0, 4, 3, 31) #endif -#if defined(HAS_ARGBTORGB24ROW_AVX512VBMI) -ANY11(ARGBToRGB24Row_Any_AVX512VBMI, ARGBToRGB24Row_AVX512VBMI, 0, 4, 3, 31) -#endif #if defined(HAS_ARGBTORAWROW_AVX2) ANY11(ARGBToRAWRow_Any_AVX2, ARGBToRAWRow_AVX2, 0, 4, 3, 31) #endif #if defined(HAS_ARGBTORGB565ROW_AVX2) ANY11(ARGBToRGB565Row_Any_AVX2, ARGBToRGB565Row_AVX2, 0, 4, 2, 7) #endif -#if defined(HAS_ARGBTOARGB4444ROW_AVX2) +#if defined(HAS_ARGBTOARGB1555ROW_AVX2) ANY11(ARGBToARGB1555Row_Any_AVX2, ARGBToARGB1555Row_AVX2, 0, 4, 2, 7) +#endif +#if defined(HAS_ARGBTOARGB4444ROW_AVX2) ANY11(ARGBToARGB4444Row_Any_AVX2, ARGBToARGB4444Row_AVX2, 0, 4, 2, 7) #endif #if defined(HAS_ABGRTOAR30ROW_SSSE3) ANY11(ABGRToAR30Row_Any_SSSE3, ABGRToAR30Row_SSSE3, 0, 4, 4, 3) #endif +#if defined(HAS_ABGRTOAR30ROW_NEON) +ANY11(ABGRToAR30Row_Any_NEON, ABGRToAR30Row_NEON, 0, 4, 4, 7) +#endif +#if defined(HAS_ARGBTOAR30ROW_NEON) +ANY11(ARGBToAR30Row_Any_NEON, ARGBToAR30Row_NEON, 0, 4, 4, 7) +#endif +#if defined(HAS_AR30TOARGBROW_NEON) +ANY11(AR30ToARGBRow_Any_NEON, AR30ToARGBRow_NEON, 0, 4, 4, 7) +#endif +#if defined(HAS_AR30TOABGRROW_NEON) +ANY11(AR30ToABGRRow_Any_NEON, AR30ToABGRRow_NEON, 0, 4, 4, 7) +#endif +#if defined(HAS_AR30TOAB30ROW_NEON) +ANY11(AR30ToAB30Row_Any_NEON, AR30ToAB30Row_NEON, 0, 4, 4, 7) +#endif +#if defined(HAS_AR30TOARGBROW_AVX2) +ANY11(AR30ToARGBRow_Any_AVX2, AR30ToARGBRow_AVX2, 0, 4, 4, 7) +#endif +#if defined(HAS_AR30TOABGRROW_AVX2) +ANY11(AR30ToABGRRow_Any_AVX2, AR30ToABGRRow_AVX2, 0, 4, 4, 7) +#endif +#if defined(HAS_AR30TOAB30ROW_AVX2) +ANY11(AR30ToAB30Row_Any_AVX2, AR30ToAB30Row_AVX2, 0, 4, 4, 7) +#endif #if defined(HAS_ARGBTOAR30ROW_SSSE3) ANY11(ARGBToAR30Row_Any_SSSE3, ARGBToAR30Row_SSSE3, 0, 4, 4, 3) #endif @@ -510,28 +1169,30 @@ ANY11(ABGRToAR30Row_Any_AVX2, ABGRToAR30Row_AVX2, 0, 4, 4, 7) #if defined(HAS_ARGBTOAR30ROW_AVX2) ANY11(ARGBToAR30Row_Any_AVX2, ARGBToAR30Row_AVX2, 0, 4, 4, 7) #endif -#if defined(HAS_J400TOARGBROW_SSE2) -ANY11(J400ToARGBRow_Any_SSE2, J400ToARGBRow_SSE2, 0, 1, 4, 7) -#endif + #if defined(HAS_J400TOARGBROW_AVX2) ANY11(J400ToARGBRow_Any_AVX2, J400ToARGBRow_AVX2, 0, 1, 4, 15) #endif -#if defined(HAS_I400TOARGBROW_SSE2) -ANY11(I400ToARGBRow_Any_SSE2, I400ToARGBRow_SSE2, 0, 1, 4, 7) -#endif -#if defined(HAS_I400TOARGBROW_AVX2) -ANY11(I400ToARGBRow_Any_AVX2, I400ToARGBRow_AVX2, 0, 1, 4, 15) -#endif #if defined(HAS_RGB24TOARGBROW_SSSE3) ANY11(RGB24ToARGBRow_Any_SSSE3, RGB24ToARGBRow_SSSE3, 0, 3, 4, 15) ANY11(RAWToARGBRow_Any_SSSE3, RAWToARGBRow_SSSE3, 0, 3, 4, 15) -ANY11(RGB565ToARGBRow_Any_SSE2, RGB565ToARGBRow_SSE2, 0, 2, 4, 7) -ANY11(ARGB1555ToARGBRow_Any_SSE2, ARGB1555ToARGBRow_SSE2, 0, 2, 4, 7) -ANY11(ARGB4444ToARGBRow_Any_SSE2, ARGB4444ToARGBRow_SSE2, 0, 2, 4, 7) + +#endif +#if defined(HAS_RAWTOARGBROW_AVX2) +ANY11(RAWToARGBRow_Any_AVX2, RAWToARGBRow_AVX2, 0, 3, 4, 31) +#endif +#if defined(HAS_RGB24TOARGBROW_AVX2) +ANY11(RGB24ToARGBRow_Any_AVX2, RGB24ToARGBRow_AVX2, 0, 3, 4, 31) +#endif +#if defined(HAS_RAWTORGBAROW_AVX2) +ANY11(RAWToRGBARow_Any_AVX2, RAWToRGBARow_AVX2, 0, 3, 4, 15) #endif #if defined(HAS_RAWTORGB24ROW_SSSE3) ANY11(RAWToRGB24Row_Any_SSSE3, RAWToRGB24Row_SSSE3, 0, 3, 3, 7) #endif +#if defined(HAS_RAWTORGB24ROW_AVX2) +ANY11(RAWToRGB24Row_Any_AVX2, RAWToRGB24Row_AVX2, 0, 3, 3, 31) +#endif #if defined(HAS_RGB565TOARGBROW_AVX2) ANY11(RGB565ToARGBRow_Any_AVX2, RGB565ToARGBRow_AVX2, 0, 2, 4, 15) #endif @@ -542,155 +1203,94 @@ ANY11(ARGB1555ToARGBRow_Any_AVX2, ARGB1555ToARGBRow_AVX2, 0, 2, 4, 15) ANY11(ARGB4444ToARGBRow_Any_AVX2, ARGB4444ToARGBRow_AVX2, 0, 2, 4, 15) #endif #if defined(HAS_ARGBTORGB24ROW_NEON) -ANY11(ARGBToRGB24Row_Any_NEON, ARGBToRGB24Row_NEON, 0, 4, 3, 7) +ANY11(ARGBToRGB24Row_Any_NEON, ARGBToRGB24Row_NEON, 0, 4, 3, 15) ANY11(ARGBToRAWRow_Any_NEON, ARGBToRAWRow_NEON, 0, 4, 3, 7) ANY11(ARGBToRGB565Row_Any_NEON, ARGBToRGB565Row_NEON, 0, 4, 2, 7) ANY11(ARGBToARGB1555Row_Any_NEON, ARGBToARGB1555Row_NEON, 0, 4, 2, 7) ANY11(ARGBToARGB4444Row_Any_NEON, ARGBToARGB4444Row_NEON, 0, 4, 2, 7) ANY11(J400ToARGBRow_Any_NEON, J400ToARGBRow_NEON, 0, 1, 4, 7) -ANY11(I400ToARGBRow_Any_NEON, I400ToARGBRow_NEON, 0, 1, 4, 7) #endif -#if defined(HAS_ARGBTORGB24ROW_MSA) -ANY11(ARGBToRGB24Row_Any_MSA, ARGBToRGB24Row_MSA, 0, 4, 3, 15) -ANY11(ARGBToRAWRow_Any_MSA, ARGBToRAWRow_MSA, 0, 4, 3, 15) -ANY11(ARGBToRGB565Row_Any_MSA, ARGBToRGB565Row_MSA, 0, 4, 2, 7) -ANY11(ARGBToARGB1555Row_Any_MSA, ARGBToARGB1555Row_MSA, 0, 4, 2, 7) -ANY11(ARGBToARGB4444Row_Any_MSA, ARGBToARGB4444Row_MSA, 0, 4, 2, 7) -ANY11(J400ToARGBRow_Any_MSA, J400ToARGBRow_MSA, 0, 1, 4, 15) -ANY11(I400ToARGBRow_Any_MSA, I400ToARGBRow_MSA, 0, 1, 4, 15) +#if defined(HAS_ARGBTORGB24ROW_LSX) +ANY11(ARGBToRGB24Row_Any_LSX, ARGBToRGB24Row_LSX, 0, 4, 3, 15) +ANY11(ARGBToRAWRow_Any_LSX, ARGBToRAWRow_LSX, 0, 4, 3, 15) +ANY11(ARGBToRGB565Row_Any_LSX, ARGBToRGB565Row_LSX, 0, 4, 2, 7) +ANY11(ARGBToARGB1555Row_Any_LSX, ARGBToARGB1555Row_LSX, 0, 4, 2, 7) +ANY11(ARGBToARGB4444Row_Any_LSX, ARGBToARGB4444Row_LSX, 0, 4, 2, 7) #endif -#if defined(HAS_ARGBTORGB24ROW_MMI) -ANY11(ARGBToRGB24Row_Any_MMI, ARGBToRGB24Row_MMI, 0, 4, 3, 3) -ANY11(ARGBToRAWRow_Any_MMI, ARGBToRAWRow_MMI, 0, 4, 3, 3) -ANY11(ARGBToRGB565Row_Any_MMI, ARGBToRGB565Row_MMI, 0, 4, 2, 3) -ANY11(ARGBToARGB1555Row_Any_MMI, ARGBToARGB1555Row_MMI, 0, 4, 2, 3) -ANY11(ARGBToARGB4444Row_Any_MMI, ARGBToARGB4444Row_MMI, 0, 4, 2, 3) -ANY11(J400ToARGBRow_Any_MMI, J400ToARGBRow_MMI, 0, 1, 4, 3) -ANY11(I400ToARGBRow_Any_MMI, I400ToARGBRow_MMI, 0, 1, 4, 7) +#if defined(HAS_ARGBTORGB24ROW_LASX) +ANY11(ARGBToRGB24Row_Any_LASX, ARGBToRGB24Row_LASX, 0, 4, 3, 31) +ANY11(ARGBToRAWRow_Any_LASX, ARGBToRAWRow_LASX, 0, 4, 3, 31) +ANY11(ARGBToRGB565Row_Any_LASX, ARGBToRGB565Row_LASX, 0, 4, 2, 15) +ANY11(ARGBToARGB1555Row_Any_LASX, ARGBToARGB1555Row_LASX, 0, 4, 2, 15) +ANY11(ARGBToARGB4444Row_Any_LASX, ARGBToARGB4444Row_LASX, 0, 4, 2, 15) +#endif +#if defined(HAS_J400TOARGBROW_LSX) +ANY11(J400ToARGBRow_Any_LSX, J400ToARGBRow_LSX, 0, 1, 4, 7) +#endif +#if defined(HAS_J400TOARGBROW_LASX) +ANY11(J400ToARGBRow_Any_LASX, J400ToARGBRow_LASX, 0, 1, 4, 15) #endif #if defined(HAS_RAWTORGB24ROW_NEON) -ANY11(RAWToRGB24Row_Any_NEON, RAWToRGB24Row_NEON, 0, 3, 3, 7) +ANY11(RAWToRGB24Row_Any_NEON, RAWToRGB24Row_NEON, 0, 3, 3, 15) #endif -#if defined(HAS_RAWTORGB24ROW_MSA) -ANY11(RAWToRGB24Row_Any_MSA, RAWToRGB24Row_MSA, 0, 3, 3, 15) +#if defined(HAS_RAWTORGB24ROW_LSX) +ANY11(RAWToRGB24Row_Any_LSX, RAWToRGB24Row_LSX, 0, 3, 3, 15) #endif -#if defined(HAS_RAWTORGB24ROW_MMI) -ANY11(RAWToRGB24Row_Any_MMI, RAWToRGB24Row_MMI, 0, 3, 3, 3) +#if defined(HAS_RAWTORGB24ROW_LASX) +ANY11(RAWToRGB24Row_Any_LASX, RAWToRGB24Row_LASX, 0, 3, 3, 31) #endif -#ifdef HAS_ARGBTOYROW_AVX2 -ANY11(ARGBToYRow_Any_AVX2, ARGBToYRow_AVX2, 0, 4, 1, 31) -#endif -#ifdef HAS_ABGRTOYROW_AVX2 -ANY11(ABGRToYRow_Any_AVX2, ABGRToYRow_AVX2, 0, 4, 1, 31) -#endif -#ifdef HAS_ARGBTOYJROW_AVX2 -ANY11(ARGBToYJRow_Any_AVX2, ARGBToYJRow_AVX2, 0, 4, 1, 31) +#if defined(HAS_RAWTORGB24ROW_WASMSIMD) +ANY11(RAWToRGB24Row_Any_WASMSIMD, RAWToRGB24Row_WASMSIMD, 0, 3, 3, 15) #endif + #ifdef HAS_UYVYTOYROW_AVX2 ANY11(UYVYToYRow_Any_AVX2, UYVYToYRow_AVX2, 0, 2, 1, 31) #endif #ifdef HAS_YUY2TOYROW_AVX2 ANY11(YUY2ToYRow_Any_AVX2, YUY2ToYRow_AVX2, 1, 4, 1, 31) #endif -#ifdef HAS_ARGBTOYROW_SSSE3 -ANY11(ARGBToYRow_Any_SSSE3, ARGBToYRow_SSSE3, 0, 4, 1, 15) -#endif -#ifdef HAS_BGRATOYROW_SSSE3 -ANY11(BGRAToYRow_Any_SSSE3, BGRAToYRow_SSSE3, 0, 4, 1, 15) -ANY11(ABGRToYRow_Any_SSSE3, ABGRToYRow_SSSE3, 0, 4, 1, 15) -ANY11(RGBAToYRow_Any_SSSE3, RGBAToYRow_SSSE3, 0, 4, 1, 15) +#ifdef HAS_YUY2TOYROW_SSE2 ANY11(YUY2ToYRow_Any_SSE2, YUY2ToYRow_SSE2, 1, 4, 1, 15) ANY11(UYVYToYRow_Any_SSE2, UYVYToYRow_SSE2, 1, 4, 1, 15) #endif -#ifdef HAS_ARGBTOYJROW_SSSE3 -ANY11(ARGBToYJRow_Any_SSSE3, ARGBToYJRow_SSSE3, 0, 4, 1, 15) + +#ifdef HAS_RGB565TOYROW_AVX2 +ANY11(RGB565ToYRow_Any_AVX2, RGB565ToYRow_AVX2, 0, 2, 1, 31) #endif -#ifdef HAS_ARGBTOYROW_NEON -ANY11(ARGBToYRow_Any_NEON, ARGBToYRow_NEON, 0, 4, 1, 7) +#ifdef HAS_ARGB1555TOYROW_AVX2 +ANY11(ARGB1555ToYRow_Any_AVX2, ARGB1555ToYRow_AVX2, 0, 2, 1, 31) #endif -#ifdef HAS_ARGBTOYROW_MSA -ANY11(ARGBToYRow_Any_MSA, ARGBToYRow_MSA, 0, 4, 1, 15) -#endif -#ifdef HAS_ARGBTOYROW_MMI -ANY11(ARGBToYRow_Any_MMI, ARGBToYRow_MMI, 0, 4, 1, 7) -#endif -#ifdef HAS_ARGBTOYJROW_NEON -ANY11(ARGBToYJRow_Any_NEON, ARGBToYJRow_NEON, 0, 4, 1, 7) -#endif -#ifdef HAS_ARGBTOYJROW_MSA -ANY11(ARGBToYJRow_Any_MSA, ARGBToYJRow_MSA, 0, 4, 1, 15) -#endif -#ifdef HAS_ARGBTOYJROW_MMI -ANY11(ARGBToYJRow_Any_MMI, ARGBToYJRow_MMI, 0, 4, 1, 7) -#endif -#ifdef HAS_BGRATOYROW_NEON -ANY11(BGRAToYRow_Any_NEON, BGRAToYRow_NEON, 0, 4, 1, 7) -#endif -#ifdef HAS_BGRATOYROW_MSA -ANY11(BGRAToYRow_Any_MSA, BGRAToYRow_MSA, 0, 4, 1, 15) -#endif -#ifdef HAS_BGRATOYROW_MMI -ANY11(BGRAToYRow_Any_MMI, BGRAToYRow_MMI, 0, 4, 1, 7) -#endif -#ifdef HAS_ABGRTOYROW_NEON -ANY11(ABGRToYRow_Any_NEON, ABGRToYRow_NEON, 0, 4, 1, 7) -#endif -#ifdef HAS_ABGRTOYROW_MSA -ANY11(ABGRToYRow_Any_MSA, ABGRToYRow_MSA, 0, 4, 1, 7) -#endif -#ifdef HAS_ABGRTOYROW_MMI -ANY11(ABGRToYRow_Any_MMI, ABGRToYRow_MMI, 0, 4, 1, 7) -#endif -#ifdef HAS_RGBATOYROW_NEON -ANY11(RGBAToYRow_Any_NEON, RGBAToYRow_NEON, 0, 4, 1, 7) -#endif -#ifdef HAS_RGBATOYROW_MSA -ANY11(RGBAToYRow_Any_MSA, RGBAToYRow_MSA, 0, 4, 1, 15) -#endif -#ifdef HAS_RGBATOYROW_MMI -ANY11(RGBAToYRow_Any_MMI, RGBAToYRow_MMI, 0, 4, 1, 7) -#endif -#ifdef HAS_RGB24TOYROW_NEON -ANY11(RGB24ToYRow_Any_NEON, RGB24ToYRow_NEON, 0, 3, 1, 7) -#endif -#ifdef HAS_RGB24TOYROW_MSA -ANY11(RGB24ToYRow_Any_MSA, RGB24ToYRow_MSA, 0, 3, 1, 15) -#endif -#ifdef HAS_RGB24TOYROW_MMI -ANY11(RGB24ToYRow_Any_MMI, RGB24ToYRow_MMI, 0, 3, 1, 7) -#endif -#ifdef HAS_RAWTOYROW_NEON -ANY11(RAWToYRow_Any_NEON, RAWToYRow_NEON, 0, 3, 1, 7) -#endif -#ifdef HAS_RAWTOYROW_MSA -ANY11(RAWToYRow_Any_MSA, RAWToYRow_MSA, 0, 3, 1, 15) -#endif -#ifdef HAS_RAWTOYROW_MMI -ANY11(RAWToYRow_Any_MMI, RAWToYRow_MMI, 0, 3, 1, 7) +#ifdef HAS_ARGB4444TOYROW_AVX2 +ANY11(ARGB4444ToYRow_Any_AVX2, ARGB4444ToYRow_AVX2, 0, 2, 1, 31) #endif #ifdef HAS_RGB565TOYROW_NEON -ANY11(RGB565ToYRow_Any_NEON, RGB565ToYRow_NEON, 0, 2, 1, 7) +ANY11(RGB565ToYRow_Any_NEON, RGB565ToYRow_NEON, 0, 2, 1, 15) #endif -#ifdef HAS_RGB565TOYROW_MSA -ANY11(RGB565ToYRow_Any_MSA, RGB565ToYRow_MSA, 0, 2, 1, 15) +#ifdef HAS_RGB565TOYROW_LSX +ANY11(RGB565ToYRow_Any_LSX, RGB565ToYRow_LSX, 0, 2, 1, 7) #endif -#ifdef HAS_RGB565TOYROW_MMI -ANY11(RGB565ToYRow_Any_MMI, RGB565ToYRow_MMI, 0, 2, 1, 7) +#ifdef HAS_RGB565TOYROW_LASX +ANY11(RGB565ToYRow_Any_LASX, RGB565ToYRow_LASX, 0, 2, 1, 15) #endif #ifdef HAS_ARGB1555TOYROW_NEON +#ifdef __aarch64__ +ANY11(ARGB1555ToYRow_Any_NEON, ARGB1555ToYRow_NEON, 0, 2, 1, 15) +#else ANY11(ARGB1555ToYRow_Any_NEON, ARGB1555ToYRow_NEON, 0, 2, 1, 7) #endif -#ifdef HAS_ARGB1555TOYROW_MSA -ANY11(ARGB1555ToYRow_Any_MSA, ARGB1555ToYRow_MSA, 0, 2, 1, 15) #endif -#ifdef HAS_ARGB1555TOYROW_MMI -ANY11(ARGB1555ToYRow_Any_MMI, ARGB1555ToYRow_MMI, 0, 2, 1, 7) +#ifdef HAS_ARGB1555TOYROW_LSX +ANY11(ARGB1555ToYRow_Any_LSX, ARGB1555ToYRow_LSX, 0, 2, 1, 7) +#endif +#ifdef HAS_ARGB1555TOYROW_LASX +ANY11(ARGB1555ToYRow_Any_LASX, ARGB1555ToYRow_LASX, 0, 2, 1, 15) #endif #ifdef HAS_ARGB4444TOYROW_NEON +#ifdef __aarch64__ +ANY11(ARGB4444ToYRow_Any_NEON, ARGB4444ToYRow_NEON, 0, 2, 1, 15) +#else ANY11(ARGB4444ToYRow_Any_NEON, ARGB4444ToYRow_NEON, 0, 2, 1, 7) #endif -#ifdef HAS_ARGB4444TOYROW_MMI -ANY11(ARGB4444ToYRow_Any_MMI, ARGB4444ToYRow_MMI, 0, 2, 1, 7) #endif #ifdef HAS_YUY2TOYROW_NEON ANY11(YUY2ToYRow_Any_NEON, YUY2ToYRow_NEON, 1, 4, 1, 15) @@ -698,17 +1298,20 @@ ANY11(YUY2ToYRow_Any_NEON, YUY2ToYRow_NEON, 1, 4, 1, 15) #ifdef HAS_UYVYTOYROW_NEON ANY11(UYVYToYRow_Any_NEON, UYVYToYRow_NEON, 1, 4, 1, 15) #endif -#ifdef HAS_YUY2TOYROW_MSA -ANY11(YUY2ToYRow_Any_MSA, YUY2ToYRow_MSA, 1, 4, 1, 31) +#ifdef HAS_YUY2TOYROW_LSX +ANY11(YUY2ToYRow_Any_LSX, YUY2ToYRow_LSX, 1, 4, 1, 15) #endif -#ifdef HAS_YUY2TOYROW_MMI -ANY11(YUY2ToYRow_Any_MMI, YUY2ToYRow_MMI, 1, 4, 1, 7) +#ifdef HAS_YUY2TOYROW_LASX +ANY11(YUY2ToYRow_Any_LASX, YUY2ToYRow_LASX, 1, 4, 1, 31) #endif -#ifdef HAS_UYVYTOYROW_MSA -ANY11(UYVYToYRow_Any_MSA, UYVYToYRow_MSA, 1, 4, 1, 31) +#ifdef HAS_UYVYTOYROW_LSX +ANY11(UYVYToYRow_Any_LSX, UYVYToYRow_LSX, 1, 4, 1, 15) #endif -#ifdef HAS_UYVYTOYROW_MMI -ANY11(UYVYToYRow_Any_MMI, UYVYToYRow_MMI, 1, 4, 1, 15) +#ifdef HAS_UYVYTOYROW_LASX +ANY11(UYVYToYRow_Any_LASX, UYVYToYRow_LASX, 1, 4, 1, 31) +#endif +#ifdef HAS_AYUVTOYROW_AVX2 +ANY11(AYUVToYRow_Any_AVX2, AYUVToYRow_AVX2, 0, 4, 1, 15) #endif #ifdef HAS_AYUVTOYROW_NEON ANY11(AYUVToYRow_Any_NEON, AYUVToYRow_NEON, 0, 4, 1, 15) @@ -725,47 +1328,50 @@ ANY11(SwapUVRow_Any_NEON, SwapUVRow_NEON, 0, 2, 2, 15) #ifdef HAS_RGB24TOARGBROW_NEON ANY11(RGB24ToARGBRow_Any_NEON, RGB24ToARGBRow_NEON, 0, 3, 4, 7) #endif -#ifdef HAS_RGB24TOARGBROW_MSA -ANY11(RGB24ToARGBRow_Any_MSA, RGB24ToARGBRow_MSA, 0, 3, 4, 15) +#ifdef HAS_RGB24TOARGBROW_LSX +ANY11(RGB24ToARGBRow_Any_LSX, RGB24ToARGBRow_LSX, 0, 3, 4, 15) #endif -#ifdef HAS_RGB24TOARGBROW_MMI -ANY11(RGB24ToARGBRow_Any_MMI, RGB24ToARGBRow_MMI, 0, 3, 4, 3) +#ifdef HAS_RGB24TOARGBROW_LASX +ANY11(RGB24ToARGBRow_Any_LASX, RGB24ToARGBRow_LASX, 0, 3, 4, 31) #endif #ifdef HAS_RAWTOARGBROW_NEON ANY11(RAWToARGBRow_Any_NEON, RAWToARGBRow_NEON, 0, 3, 4, 7) #endif -#ifdef HAS_RAWTOARGBROW_MSA -ANY11(RAWToARGBRow_Any_MSA, RAWToARGBRow_MSA, 0, 3, 4, 15) +#ifdef HAS_RAWTORGBAROW_NEON +ANY11(RAWToRGBARow_Any_NEON, RAWToRGBARow_NEON, 0, 3, 4, 7) #endif -#ifdef HAS_RAWTOARGBROW_MMI -ANY11(RAWToARGBRow_Any_MMI, RAWToARGBRow_MMI, 0, 3, 4, 3) +#ifdef HAS_RAWTOARGBROW_LSX +ANY11(RAWToARGBRow_Any_LSX, RAWToARGBRow_LSX, 0, 3, 4, 15) +#endif +#ifdef HAS_RAWTOARGBROW_LASX +ANY11(RAWToARGBRow_Any_LASX, RAWToARGBRow_LASX, 0, 3, 4, 31) #endif #ifdef HAS_RGB565TOARGBROW_NEON -ANY11(RGB565ToARGBRow_Any_NEON, RGB565ToARGBRow_NEON, 0, 2, 4, 7) +ANY11(RGB565ToARGBRow_Any_NEON, RGB565ToARGBRow_NEON, 0, 2, 4, 15) #endif -#ifdef HAS_RGB565TOARGBROW_MSA -ANY11(RGB565ToARGBRow_Any_MSA, RGB565ToARGBRow_MSA, 0, 2, 4, 15) +#ifdef HAS_RGB565TOARGBROW_LSX +ANY11(RGB565ToARGBRow_Any_LSX, RGB565ToARGBRow_LSX, 0, 2, 4, 7) #endif -#ifdef HAS_RGB565TOARGBROW_MMI -ANY11(RGB565ToARGBRow_Any_MMI, RGB565ToARGBRow_MMI, 0, 2, 4, 3) +#ifdef HAS_RGB565TOARGBROW_LASX +ANY11(RGB565ToARGBRow_Any_LASX, RGB565ToARGBRow_LASX, 0, 2, 4, 15) #endif #ifdef HAS_ARGB1555TOARGBROW_NEON -ANY11(ARGB1555ToARGBRow_Any_NEON, ARGB1555ToARGBRow_NEON, 0, 2, 4, 7) +ANY11(ARGB1555ToARGBRow_Any_NEON, ARGB1555ToARGBRow_NEON, 0, 2, 4, 15) #endif -#ifdef HAS_ARGB1555TOARGBROW_MSA -ANY11(ARGB1555ToARGBRow_Any_MSA, ARGB1555ToARGBRow_MSA, 0, 2, 4, 15) +#ifdef HAS_ARGB1555TOARGBROW_LSX +ANY11(ARGB1555ToARGBRow_Any_LSX, ARGB1555ToARGBRow_LSX, 0, 2, 4, 7) #endif -#ifdef HAS_ARGB1555TOARGBROW_MMI -ANY11(ARGB1555ToARGBRow_Any_MMI, ARGB1555ToARGBRow_MMI, 0, 2, 4, 3) +#ifdef HAS_ARGB1555TOARGBROW_LASX +ANY11(ARGB1555ToARGBRow_Any_LASX, ARGB1555ToARGBRow_LASX, 0, 2, 4, 15) #endif #ifdef HAS_ARGB4444TOARGBROW_NEON ANY11(ARGB4444ToARGBRow_Any_NEON, ARGB4444ToARGBRow_NEON, 0, 2, 4, 7) #endif -#ifdef HAS_ARGB4444TOARGBROW_MSA -ANY11(ARGB4444ToARGBRow_Any_MSA, ARGB4444ToARGBRow_MSA, 0, 2, 4, 15) +#ifdef HAS_ARGB4444TOARGBROW_LSX +ANY11(ARGB4444ToARGBRow_Any_LSX, ARGB4444ToARGBRow_LSX, 0, 2, 4, 7) #endif -#ifdef HAS_ARGB4444TOARGBROW_MMI -ANY11(ARGB4444ToARGBRow_Any_MMI, ARGB4444ToARGBRow_MMI, 0, 2, 4, 3) +#ifdef HAS_ARGB4444TOARGBROW_LASX +ANY11(ARGB4444ToARGBRow_Any_LASX, ARGB4444ToARGBRow_LASX, 0, 2, 4, 15) #endif #ifdef HAS_ARGBATTENUATEROW_SSSE3 ANY11(ARGBAttenuateRow_Any_SSSE3, ARGBAttenuateRow_SSSE3, 0, 4, 4, 3) @@ -782,11 +1388,14 @@ ANY11(ARGBUnattenuateRow_Any_AVX2, ARGBUnattenuateRow_AVX2, 0, 4, 4, 7) #ifdef HAS_ARGBATTENUATEROW_NEON ANY11(ARGBAttenuateRow_Any_NEON, ARGBAttenuateRow_NEON, 0, 4, 4, 7) #endif -#ifdef HAS_ARGBATTENUATEROW_MSA -ANY11(ARGBAttenuateRow_Any_MSA, ARGBAttenuateRow_MSA, 0, 4, 4, 7) +#ifdef HAS_ARGBUNATTENUATEROW_NEON +ANY11(ARGBUnattenuateRow_Any_NEON, ARGBUnattenuateRow_NEON, 0, 4, 4, 3) #endif -#ifdef HAS_ARGBATTENUATEROW_MMI -ANY11(ARGBAttenuateRow_Any_MMI, ARGBAttenuateRow_MMI, 0, 4, 4, 1) +#ifdef HAS_ARGBATTENUATEROW_LSX +ANY11(ARGBAttenuateRow_Any_LSX, ARGBAttenuateRow_LSX, 0, 4, 4, 3) +#endif +#ifdef HAS_ARGBATTENUATEROW_LASX +ANY11(ARGBAttenuateRow_Any_LASX, ARGBAttenuateRow_LASX, 0, 4, 4, 7) #endif #ifdef HAS_ARGBEXTRACTALPHAROW_SSE2 ANY11(ARGBExtractAlphaRow_Any_SSE2, ARGBExtractAlphaRow_SSE2, 0, 4, 1, 7) @@ -797,28 +1406,72 @@ ANY11(ARGBExtractAlphaRow_Any_AVX2, ARGBExtractAlphaRow_AVX2, 0, 4, 1, 31) #ifdef HAS_ARGBEXTRACTALPHAROW_NEON ANY11(ARGBExtractAlphaRow_Any_NEON, ARGBExtractAlphaRow_NEON, 0, 4, 1, 15) #endif -#ifdef HAS_ARGBEXTRACTALPHAROW_MSA -ANY11(ARGBExtractAlphaRow_Any_MSA, ARGBExtractAlphaRow_MSA, 0, 4, 1, 15) +#ifdef HAS_ARGBEXTRACTALPHAROW_LSX +ANY11(ARGBExtractAlphaRow_Any_LSX, ARGBExtractAlphaRow_LSX, 0, 4, 1, 7) #endif -#ifdef HAS_ARGBEXTRACTALPHAROW_MMI -ANY11(ARGBExtractAlphaRow_Any_MMI, ARGBExtractAlphaRow_MMI, 0, 4, 1, 7) +#ifdef HAS_ARGBEXTRACTALPHAROW_LASX +ANY11(ARGBExtractAlphaRow_Any_LASX, ARGBExtractAlphaRow_LASX, 0, 4, 1, 15) +#endif +#ifdef HAS_ARGBEXTRACTALPHAROW_WASMSIMD +ANY11(ARGBExtractAlphaRow_Any_WASMSIMD, + ARGBExtractAlphaRow_WASMSIMD, + 0, + 4, + 1, + 15) +#endif +#ifdef HAS_RAWTOARGBROW_WASMSIMD +ANY11(RAWToARGBRow_Any_WASMSIMD, RAWToARGBRow_WASMSIMD, 0, 3, 4, 15) +#endif +#ifdef HAS_RGB24TOARGBROW_WASMSIMD +ANY11(RGB24ToARGBRow_Any_WASMSIMD, RGB24ToARGBRow_WASMSIMD, 0, 3, 4, 15) +#endif +#ifdef HAS_SWAPUVROW_WASMSIMD +ANY11(SwapUVRow_Any_WASMSIMD, SwapUVRow_WASMSIMD, 0, 2, 2, 15) +#endif +#ifdef HAS_J400TOARGBROW_WASMSIMD +ANY11(J400ToARGBRow_Any_WASMSIMD, J400ToARGBRow_WASMSIMD, 0, 1, 4, 15) +#endif +#ifdef HAS_RGB565TOARGBROW_WASMSIMD +ANY11(RGB565ToARGBRow_Any_WASMSIMD, RGB565ToARGBRow_WASMSIMD, 0, 2, 4, 7) +#endif +#ifdef HAS_ARGB1555TOARGBROW_WASMSIMD +ANY11(ARGB1555ToARGBRow_Any_WASMSIMD, ARGB1555ToARGBRow_WASMSIMD, 0, 2, 4, 7) +#endif +#ifdef HAS_ARGB4444TOARGBROW_WASMSIMD +ANY11(ARGB4444ToARGBRow_Any_WASMSIMD, ARGB4444ToARGBRow_WASMSIMD, 0, 2, 4, 7) +#endif +#ifdef HAS_ARGBTORGB565ROW_WASMSIMD +ANY11(ARGBToRGB565Row_Any_WASMSIMD, ARGBToRGB565Row_WASMSIMD, 0, 4, 2, 7) +#endif +#ifdef HAS_ARGBTOARGB1555ROW_WASMSIMD +ANY11(ARGBToARGB1555Row_Any_WASMSIMD, ARGBToARGB1555Row_WASMSIMD, 0, 4, 2, 7) +#endif +#ifdef HAS_ARGBTOARGB4444ROW_WASMSIMD +ANY11(ARGBToARGB4444Row_Any_WASMSIMD, ARGBToARGB4444Row_WASMSIMD, 0, 4, 2, 7) #endif #undef ANY11 // Any 1 to 1 blended. Destination is read, modify, write. -#define ANY11B(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, BPP, MASK) \ - void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_ptr, int width) { \ - SIMD_ALIGNED(uint8_t temp[64 * 2]); \ - memset(temp, 0, 64 * 2); /* for msan */ \ - int r = width & MASK; \ - int n = width & ~MASK; \ - if (n > 0) { \ - ANY_SIMD(src_ptr, dst_ptr, n); \ - } \ - memcpy(temp, src_ptr + (n >> UVSHIFT) * SBPP, SS(r, UVSHIFT) * SBPP); \ - memcpy(temp + 64, dst_ptr + n * BPP, r * BPP); \ - ANY_SIMD(temp, temp + 64, MASK + 1); \ - memcpy(dst_ptr + n * BPP, temp + 64, r * BPP); \ +#define ANY11B(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, BPP, MASK) \ + void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_ptr, int width) { \ + SIMD_ALIGNED(uint8_t vin[64]); \ + static_assert(SS(MASK + 1, UVSHIFT) * SBPP <= sizeof(vin), \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[64]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, dst_ptr, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + (np >> UVSHIFT) * SBPP, SS(r, UVSHIFT) * SBPP); \ + memcpy(vout, dst_ptr + np * BPP, r * BPP); \ + ANY_SIMD(vin, vout, MASK + 1); \ + memcpy(dst_ptr + np * BPP, vout, r * BPP); \ } #ifdef HAS_ARGBCOPYALPHAROW_AVX2 @@ -827,8 +1480,8 @@ ANY11B(ARGBCopyAlphaRow_Any_AVX2, ARGBCopyAlphaRow_AVX2, 0, 4, 4, 15) #ifdef HAS_ARGBCOPYALPHAROW_SSE2 ANY11B(ARGBCopyAlphaRow_Any_SSE2, ARGBCopyAlphaRow_SSE2, 0, 4, 4, 7) #endif -#ifdef HAS_ARGBCOPYALPHAROW_MMI -ANY11B(ARGBCopyAlphaRow_Any_MMI, ARGBCopyAlphaRow_MMI, 0, 4, 4, 1) +#ifdef HAS_ARGBCOPYALPHAROW_NEON +ANY11B(ARGBCopyAlphaRow_Any_NEON, ARGBCopyAlphaRow_NEON, 0, 4, 4, 7) #endif #ifdef HAS_ARGBCOPYYTOALPHAROW_AVX2 ANY11B(ARGBCopyYToAlphaRow_Any_AVX2, ARGBCopyYToAlphaRow_AVX2, 0, 1, 4, 15) @@ -836,34 +1489,78 @@ ANY11B(ARGBCopyYToAlphaRow_Any_AVX2, ARGBCopyYToAlphaRow_AVX2, 0, 1, 4, 15) #ifdef HAS_ARGBCOPYYTOALPHAROW_SSE2 ANY11B(ARGBCopyYToAlphaRow_Any_SSE2, ARGBCopyYToAlphaRow_SSE2, 0, 1, 4, 7) #endif -#ifdef HAS_ARGBCOPYYTOALPHAROW_MMI -ANY11B(ARGBCopyYToAlphaRow_Any_MMI, ARGBCopyYToAlphaRow_MMI, 0, 1, 4, 7) +#ifdef HAS_ARGBCOPYYTOALPHAROW_NEON +ANY11B(ARGBCopyYToAlphaRow_Any_NEON, ARGBCopyYToAlphaRow_NEON, 0, 1, 4, 15) +#endif +#ifdef HAS_ARGBCOPYYTOALPHAROW_WASMSIMD +ANY11B(ARGBCopyYToAlphaRow_Any_WASMSIMD, + ARGBCopyYToAlphaRow_WASMSIMD, + 0, + 1, + 4, + 15) #endif #undef ANY11B // Any 1 to 1 with parameter. #define ANY11P(NAMEANY, ANY_SIMD, T, SBPP, BPP, MASK) \ void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_ptr, T param, int width) { \ - SIMD_ALIGNED(uint8_t temp[64 * 2]); \ - memset(temp, 0, 64); /* for msan */ \ + SIMD_ALIGNED(uint8_t vin[(MASK + 1) * SBPP]); \ + SIMD_ALIGNED(uint8_t vout[(MASK + 1) * BPP]); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ int r = width & MASK; \ int n = width & ~MASK; \ if (n > 0) { \ ANY_SIMD(src_ptr, dst_ptr, param, n); \ } \ - memcpy(temp, src_ptr + n * SBPP, r * SBPP); \ - ANY_SIMD(temp, temp + 64, param, MASK + 1); \ - memcpy(dst_ptr + n * BPP, temp + 64, r * BPP); \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np * SBPP, r * SBPP); \ + ANY_SIMD(vin, vout, param, MASK + 1); \ + memcpy(dst_ptr + np * BPP, vout, r * BPP); \ } -#if defined(HAS_ARGBTORGB565DITHERROW_SSE2) -ANY11P(ARGBToRGB565DitherRow_Any_SSE2, - ARGBToRGB565DitherRow_SSE2, - const uint32_t, +#if defined(HAS_I400TOARGBROW_SSE2) +ANY11P(I400ToARGBRow_Any_SSE2, + I400ToARGBRow_SSE2, + const struct YuvConstants*, + 1, 4, - 2, - 3) + 7) #endif +#if defined(HAS_I400TOARGBROW_AVX2) +ANY11P(I400ToARGBRow_Any_AVX2, + I400ToARGBRow_AVX2, + const struct YuvConstants*, + 1, + 4, + 15) +#endif +#if defined(HAS_I400TOARGBROW_NEON) +ANY11P(I400ToARGBRow_Any_NEON, + I400ToARGBRow_NEON, + const struct YuvConstants*, + 1, + 4, + 7) +#endif +#if defined(HAS_I400TOARGBROW_LSX) +ANY11P(I400ToARGBRow_Any_LSX, + I400ToARGBRow_LSX, + const struct YuvConstants*, + 1, + 4, + 7) +#endif +#if defined(HAS_I400TOARGBROW_LASX) +ANY11P(I400ToARGBRow_Any_LASX, + I400ToARGBRow_LASX, + const struct YuvConstants*, + 1, + 4, + 15) +#endif + #if defined(HAS_ARGBTORGB565DITHERROW_AVX2) ANY11P(ARGBToRGB565DitherRow_Any_AVX2, ARGBToRGB565DitherRow_AVX2, @@ -880,22 +1577,22 @@ ANY11P(ARGBToRGB565DitherRow_Any_NEON, 2, 7) #endif -#if defined(HAS_ARGBTORGB565DITHERROW_MSA) -ANY11P(ARGBToRGB565DitherRow_Any_MSA, - ARGBToRGB565DitherRow_MSA, - const uint32_t, - 4, - 2, - 7) -#endif -#if defined(HAS_ARGBTORGB565DITHERROW_MMI) -ANY11P(ARGBToRGB565DitherRow_Any_MMI, - ARGBToRGB565DitherRow_MMI, +#if defined(HAS_ARGBTORGB565DITHERROW_LSX) +ANY11P(ARGBToRGB565DitherRow_Any_LSX, + ARGBToRGB565DitherRow_LSX, const uint32_t, 4, 2, 3) #endif +#if defined(HAS_ARGBTORGB565DITHERROW_LASX) +ANY11P(ARGBToRGB565DitherRow_Any_LASX, + ARGBToRGB565DitherRow_LASX, + const uint32_t, + 4, + 2, + 7) +#endif #ifdef HAS_ARGBSHUFFLEROW_SSSE3 ANY11P(ARGBShuffleRow_Any_SSSE3, ARGBShuffleRow_SSSE3, const uint8_t*, 4, 4, 7) #endif @@ -905,29 +1602,165 @@ ANY11P(ARGBShuffleRow_Any_AVX2, ARGBShuffleRow_AVX2, const uint8_t*, 4, 4, 15) #ifdef HAS_ARGBSHUFFLEROW_NEON ANY11P(ARGBShuffleRow_Any_NEON, ARGBShuffleRow_NEON, const uint8_t*, 4, 4, 3) #endif -#ifdef HAS_ARGBSHUFFLEROW_MSA -ANY11P(ARGBShuffleRow_Any_MSA, ARGBShuffleRow_MSA, const uint8_t*, 4, 4, 7) +#ifdef HAS_ARGBSHUFFLEROW_LSX +ANY11P(ARGBShuffleRow_Any_LSX, ARGBShuffleRow_LSX, const uint8_t*, 4, 4, 3) #endif -#ifdef HAS_ARGBSHUFFLEROW_MMI -ANY11P(ARGBShuffleRow_Any_MMI, ARGBShuffleRow_MMI, const uint8_t*, 4, 4, 1) +#ifdef HAS_ARGBSHUFFLEROW_LASX +ANY11P(ARGBShuffleRow_Any_LASX, ARGBShuffleRow_LASX, const uint8_t*, 4, 4, 7) +#endif +#if defined(HAS_ARGBTORGB565DITHERROW_WASMSIMD) +ANY11P(ARGBToRGB565DitherRow_Any_WASMSIMD, + ARGBToRGB565DitherRow_WASMSIMD, + const uint32_t, + 4, + 2, + 7) +#endif +#ifdef HAS_ARGBSHUFFLEROW_WASMSIMD +ANY11P(ARGBShuffleRow_Any_WASMSIMD, + ARGBShuffleRow_WASMSIMD, + const uint8_t*, + 4, + 4, + 3) +#endif +#ifdef HAS_ARGBORROW_SSE2 +ANY11P(ARGBOrRow_Any_SSE2, ARGBOrRow_SSE2, const uint32_t, 4, 4, 3) +#endif +#ifdef HAS_ARGBORROW_AVX2 +ANY11P(ARGBOrRow_Any_AVX2, ARGBOrRow_AVX2, const uint32_t, 4, 4, 7) +#endif +#ifdef HAS_ARGBORROW_NEON +ANY11P(ARGBOrRow_Any_NEON, ARGBOrRow_NEON, const uint32_t, 4, 4, 7) +#endif +#ifdef HAS_ARGBORROW_LSX +ANY11P(ARGBOrRow_Any_LSX, ARGBOrRow_LSX, const uint32_t, 4, 4, 3) +#endif +#ifdef HAS_ARGBORROW_LASX +ANY11P(ARGBOrRow_Any_LASX, ARGBOrRow_LASX, const uint32_t, 4, 4, 7) +#endif +#ifdef HAS_ARGBORROW_WASMSIMD +ANY11P(ARGBOrRow_Any_WASMSIMD, ARGBOrRow_WASMSIMD, const uint32_t, 4, 4, 3) +#endif +#ifdef HAS_ARGBPOLYNOMIALROW_SSE2 +ANY11P(ARGBPolynomialRow_Any_SSE2, + ARGBPolynomialRow_SSE2, + const float*, + 4, + 4, + 1) +#endif +#ifdef HAS_ARGBPOLYNOMIALROW_AVX2 +ANY11P(ARGBPolynomialRow_Any_AVX2, + ARGBPolynomialRow_AVX2, + const float*, + 4, + 4, + 1) +#endif +#ifdef HAS_ARGBPOLYNOMIALROW_NEON +ANY11P(ARGBPolynomialRow_Any_NEON, + ARGBPolynomialRow_NEON, + const float*, + 4, + 4, + 1) #endif -#undef ANY11P #undef ANY11P +// Any 1 to 1 with type +#define ANY11T(NAMEANY, ANY_SIMD, SBPP, BPP, STYPE, DTYPE, MASK) \ + void NAMEANY(const STYPE* src_ptr, DTYPE* dst_ptr, int width) { \ + SIMD_ALIGNED(uint8_t vin[(MASK + 1) * SBPP]); \ + SIMD_ALIGNED(uint8_t vout[(MASK + 1) * BPP]); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, dst_ptr, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, (uint8_t*)(src_ptr) + np * SBPP, r * SBPP); \ + ANY_SIMD((STYPE*)vin, (DTYPE*)vout, MASK + 1); \ + memcpy((uint8_t*)(dst_ptr) + np * BPP, vout, r * BPP); \ + } + +#ifdef HAS_ARGBTOAR64ROW_SSSE3 +ANY11T(ARGBToAR64Row_Any_SSSE3, ARGBToAR64Row_SSSE3, 4, 8, uint8_t, uint16_t, 3) +#endif + +#ifdef HAS_ARGBTOAB64ROW_SSSE3 +ANY11T(ARGBToAB64Row_Any_SSSE3, ARGBToAB64Row_SSSE3, 4, 8, uint8_t, uint16_t, 3) +#endif + +#ifdef HAS_AR64TOARGBROW_SSSE3 +ANY11T(AR64ToARGBRow_Any_SSSE3, AR64ToARGBRow_SSSE3, 8, 4, uint16_t, uint8_t, 3) +#endif + +#ifdef HAS_AB64TOARGBROW_SSSE3 +ANY11T(AB64ToARGBRow_Any_SSSE3, AB64ToARGBRow_SSSE3, 8, 4, uint16_t, uint8_t, 3) +#endif + +#ifdef HAS_ARGBTOAR64ROW_AVX2 +ANY11T(ARGBToAR64Row_Any_AVX2, ARGBToAR64Row_AVX2, 4, 8, uint8_t, uint16_t, 7) +#endif + +#ifdef HAS_ARGBTOAB64ROW_AVX2 +ANY11T(ARGBToAB64Row_Any_AVX2, ARGBToAB64Row_AVX2, 4, 8, uint8_t, uint16_t, 7) +#endif + +#ifdef HAS_AR64TOARGBROW_AVX2 +ANY11T(AR64ToARGBRow_Any_AVX2, AR64ToARGBRow_AVX2, 8, 4, uint16_t, uint8_t, 7) +#endif + +#ifdef HAS_AB64TOARGBROW_AVX2 +ANY11T(AB64ToARGBRow_Any_AVX2, AB64ToARGBRow_AVX2, 8, 4, uint16_t, uint8_t, 7) +#endif + +#ifdef HAS_ARGBTOAR64ROW_NEON +ANY11T(ARGBToAR64Row_Any_NEON, ARGBToAR64Row_NEON, 4, 8, uint8_t, uint16_t, 7) +#endif + +#ifdef HAS_ARGBTOAB64ROW_NEON +ANY11T(ARGBToAB64Row_Any_NEON, ARGBToAB64Row_NEON, 4, 8, uint8_t, uint16_t, 7) +#endif + +#ifdef HAS_AR64TOARGBROW_NEON +ANY11T(AR64ToARGBRow_Any_NEON, AR64ToARGBRow_NEON, 8, 4, uint16_t, uint8_t, 7) +#endif + +#ifdef HAS_AB64TOARGBROW_NEON +ANY11T(AB64ToARGBRow_Any_NEON, AB64ToARGBRow_NEON, 8, 4, uint16_t, uint8_t, 7) +#endif + +#ifdef HAS_COPYROW_16_AVX2 +ANY11T(CopyRow_16_Any_AVX2, CopyRow_16_AVX2, 2, 2, uint16_t, uint16_t, 31) +#endif +#ifdef HAS_COPYROW_16_NEON +ANY11T(CopyRow_16_Any_NEON, CopyRow_16_NEON, 2, 2, uint16_t, uint16_t, 15) +#endif + +#undef ANY11T + // Any 1 to 1 with parameter and shorts. BPP measures in shorts. -#define ANY11C(NAMEANY, ANY_SIMD, SBPP, BPP, STYPE, DTYPE, MASK) \ - void NAMEANY(const STYPE* src_ptr, DTYPE* dst_ptr, int scale, int width) { \ - SIMD_ALIGNED(STYPE temp[32]); \ - SIMD_ALIGNED(DTYPE out[32]); \ - memset(temp, 0, 32 * SBPP); /* for msan */ \ - int r = width & MASK; \ - int n = width & ~MASK; \ - if (n > 0) { \ - ANY_SIMD(src_ptr, dst_ptr, scale, n); \ - } \ - memcpy(temp, src_ptr + n, r * SBPP); \ - ANY_SIMD(temp, out, scale, MASK + 1); \ - memcpy(dst_ptr + n, out, r * BPP); \ +#define ANY11C(NAMEANY, ANY_SIMD, SBPP, BPP, STYPE, DTYPE, MASK) \ + void NAMEANY(const STYPE* src_ptr, DTYPE* dst_ptr, int value, int width) { \ + SIMD_ALIGNED(STYPE vin[64]); \ + static_assert((MASK + 1) * SBPP <= sizeof(vin), "vin buffer too small"); \ + SIMD_ALIGNED(DTYPE vout[64]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, dst_ptr, value, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np, r * SBPP); \ + ANY_SIMD(vin, vout, value, MASK + 1); \ + memcpy(dst_ptr + np, vout, r * BPP); \ } #ifdef HAS_CONVERT16TO8ROW_SSSE3 @@ -948,6 +1781,15 @@ ANY11C(Convert16To8Row_Any_AVX2, uint8_t, 31) #endif +#ifdef HAS_CONVERT16TO8ROW_NEON +ANY11C(Convert16To8Row_Any_NEON, + Convert16To8Row_NEON, + 2, + 1, + uint16_t, + uint8_t, + 15) +#endif #ifdef HAS_CONVERT8TO16ROW_SSE2 ANY11C(Convert8To16Row_Any_SSE2, Convert8To16Row_SSE2, @@ -966,27 +1808,120 @@ ANY11C(Convert8To16Row_Any_AVX2, uint16_t, 31) #endif +#ifdef HAS_CONVERT8TO16ROW_NEON +ANY11C(Convert8To16Row_Any_NEON, + Convert8To16Row_NEON, + 1, + 2, + uint8_t, + uint16_t, + 15) +#endif +#ifdef HAS_MULTIPLYROW_16_AVX2 +ANY11C(MultiplyRow_16_Any_AVX2, + MultiplyRow_16_AVX2, + 2, + 2, + uint16_t, + uint16_t, + 31) +#endif +#ifdef HAS_MULTIPLYROW_16_NEON +ANY11C(MultiplyRow_16_Any_NEON, + MultiplyRow_16_NEON, + 2, + 2, + uint16_t, + uint16_t, + 15) +#endif +#ifdef HAS_DIVIDEROW_16_AVX2 +ANY11C(DivideRow_16_Any_AVX2, DivideRow_16_AVX2, 2, 2, uint16_t, uint16_t, 31) +#endif +#ifdef HAS_DIVIDEROW_16_NEON +ANY11C(DivideRow_16_Any_NEON, DivideRow_16_NEON, 2, 2, uint16_t, uint16_t, 15) +#endif +#ifdef HAS_CONVERT8TO16ROW_WASMSIMD +ANY11C(Convert8To16Row_Any_WASMSIMD, + Convert8To16Row_WASMSIMD, + 1, + 2, + uint8_t, + uint16_t, + 15) +#endif +#ifdef HAS_MULTIPLYROW_16_WASMSIMD +ANY11C(MultiplyRow_16_Any_WASMSIMD, + MultiplyRow_16_WASMSIMD, + 2, + 2, + uint16_t, + uint16_t, + 15) +#endif #undef ANY11C -// Any 1 to 1 with parameter and shorts to byte. BPP measures in shorts. -#define ANY11P16(NAMEANY, ANY_SIMD, ST, T, SBPP, BPP, MASK) \ - void NAMEANY(const ST* src_ptr, T* dst_ptr, float param, int width) { \ - SIMD_ALIGNED(ST temp[32]); \ - SIMD_ALIGNED(T out[32]); \ - memset(temp, 0, SBPP * 32); /* for msan */ \ - int r = width & MASK; \ - int n = width & ~MASK; \ - if (n > 0) { \ - ANY_SIMD(src_ptr, dst_ptr, param, n); \ - } \ - memcpy(temp, src_ptr + n, r * SBPP); \ - ANY_SIMD(temp, out, param, MASK + 1); \ - memcpy(dst_ptr + n, out, r * BPP); \ +// Any 1 to 1 with parameter and shorts. BPP measures in shorts. +#define ANY11SB(NAMEANY, ANY_SIMD, SBPP, BPP, STYPE, DTYPE, MASK) \ + void NAMEANY(const STYPE* src_ptr, DTYPE* dst_ptr, int scale, int bias, \ + int width) { \ + SIMD_ALIGNED(STYPE vin[64]); \ + static_assert((MASK + 1) * SBPP <= sizeof(vin), "vin buffer too small"); \ + SIMD_ALIGNED(DTYPE vout[64]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, dst_ptr, scale, bias, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np, r * SBPP); \ + ANY_SIMD(vin, vout, scale, bias, MASK + 1); \ + memcpy(dst_ptr + np, vout, r * BPP); \ } -#ifdef HAS_HALFFLOATROW_SSE2 -ANY11P16(HalfFloatRow_Any_SSE2, HalfFloatRow_SSE2, uint16_t, uint16_t, 2, 2, 7) +#ifdef HAS_CONVERT8TO8ROW_NEON +ANY11SB(Convert8To8Row_Any_NEON, + Convert8To8Row_NEON, + 1, + 1, + uint8_t, + uint8_t, + 31) #endif +#ifdef HAS_CONVERT8TO8ROW_AVX2 +ANY11SB(Convert8To8Row_Any_AVX2, + Convert8To8Row_AVX2, + 1, + 1, + uint8_t, + uint8_t, + 31) +#endif +#undef ANY11B + +// Any 1 to 1 with parameter and shorts to byte. BPP measures in shorts. +#define ANY11P16(NAMEANY, ANY_SIMD, ST, T, SBPP, BPP, MASK) \ + void NAMEANY(const ST* src_ptr, T* dst_ptr, float param, int width) { \ + SIMD_ALIGNED(ST vin[32]); \ + static_assert((MASK + 1) * SBPP <= sizeof(vin), "vin buffer too small"); \ + SIMD_ALIGNED(T vout[32]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, dst_ptr, param, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np, r * SBPP); \ + ANY_SIMD(vin, vout, param, MASK + 1); \ + memcpy(dst_ptr + np, vout, r * BPP); \ + } + #ifdef HAS_HALFFLOATROW_AVX2 ANY11P16(HalfFloatRow_Any_AVX2, HalfFloatRow_AVX2, uint16_t, uint16_t, 2, 2, 15) #endif @@ -1001,41 +1936,47 @@ ANY11P16(HalfFloat1Row_Any_F16C, 15) #endif #ifdef HAS_HALFFLOATROW_NEON -ANY11P16(HalfFloatRow_Any_NEON, HalfFloatRow_NEON, uint16_t, uint16_t, 2, 2, 7) -ANY11P16(HalfFloat1Row_Any_NEON, - HalfFloat1Row_NEON, - uint16_t, - uint16_t, - 2, - 2, - 7) +ANY11P16(HalfFloatRow_Any_NEON, HalfFloatRow_NEON, uint16_t, uint16_t, 2, 2, 15) #endif -#ifdef HAS_HALFFLOATROW_MSA -ANY11P16(HalfFloatRow_Any_MSA, HalfFloatRow_MSA, uint16_t, uint16_t, 2, 2, 31) +#ifdef HAS_BYTETOFLOATROW_AVX2 +ANY11P16(ByteToFloatRow_Any_AVX2, ByteToFloatRow_AVX2, uint8_t, float, 1, 4, 15) #endif #ifdef HAS_BYTETOFLOATROW_NEON -ANY11P16(ByteToFloatRow_Any_NEON, ByteToFloatRow_NEON, uint8_t, float, 1, 3, 7) +ANY11P16(ByteToFloatRow_Any_NEON, ByteToFloatRow_NEON, uint8_t, float, 1, 4, 7) +#endif +#ifdef HAS_HALFFLOATROW_LSX +ANY11P16(HalfFloatRow_Any_LSX, HalfFloatRow_LSX, uint16_t, uint16_t, 2, 2, 7) +#endif +#ifdef HAS_HALFFLOATROW_LASX +ANY11P16(HalfFloatRow_Any_LASX, HalfFloatRow_LASX, uint16_t, uint16_t, 2, 2, 15) #endif #undef ANY11P16 // Any 1 to 1 with yuvconstants -#define ANY11C(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, BPP, MASK) \ - void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_ptr, \ - const struct YuvConstants* yuvconstants, int width) { \ - SIMD_ALIGNED(uint8_t temp[128 * 2]); \ - memset(temp, 0, 128); /* for YUY2 and msan */ \ - int r = width & MASK; \ - int n = width & ~MASK; \ - if (n > 0) { \ - ANY_SIMD(src_ptr, dst_ptr, yuvconstants, n); \ - } \ - memcpy(temp, src_ptr + (n >> UVSHIFT) * SBPP, SS(r, UVSHIFT) * SBPP); \ - ANY_SIMD(temp, temp + 128, yuvconstants, MASK + 1); \ - memcpy(dst_ptr + n * BPP, temp + 128, r * BPP); \ +#define ANY11C(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, BPP, MASK) \ + void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_ptr, \ + const struct YuvConstants* yuvconstants, int width) { \ + SIMD_ALIGNED(uint8_t vin[256]); \ + static_assert(SS(MASK + 1, UVSHIFT) * SBPP <= sizeof(vin), \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[256]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for YUY2 and msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, dst_ptr, yuvconstants, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + (np >> UVSHIFT) * SBPP, SS(r, UVSHIFT) * SBPP); \ + ANY_SIMD(vin, vout, yuvconstants, MASK + 1); \ + memcpy(dst_ptr + np * BPP, vout, r * BPP); \ } + #if defined(HAS_YUY2TOARGBROW_SSSE3) -ANY11C(YUY2ToARGBRow_Any_SSSE3, YUY2ToARGBRow_SSSE3, 1, 4, 4, 15) -ANY11C(UYVYToARGBRow_Any_SSSE3, UYVYToARGBRow_SSSE3, 1, 4, 4, 15) +ANY11C(YUY2ToARGBRow_Any_SSSE3, YUY2ToARGBRow_SSSE3, 1, 4, 4, 7) +ANY11C(UYVYToARGBRow_Any_SSSE3, UYVYToARGBRow_SSSE3, 1, 4, 4, 7) #endif #if defined(HAS_YUY2TOARGBROW_AVX2) ANY11C(YUY2ToARGBRow_Any_AVX2, YUY2ToARGBRow_AVX2, 1, 4, 4, 31) @@ -1045,59 +1986,229 @@ ANY11C(UYVYToARGBRow_Any_AVX2, UYVYToARGBRow_AVX2, 1, 4, 4, 31) ANY11C(YUY2ToARGBRow_Any_NEON, YUY2ToARGBRow_NEON, 1, 4, 4, 7) ANY11C(UYVYToARGBRow_Any_NEON, UYVYToARGBRow_NEON, 1, 4, 4, 7) #endif -#if defined(HAS_YUY2TOARGBROW_MSA) -ANY11C(YUY2ToARGBRow_Any_MSA, YUY2ToARGBRow_MSA, 1, 4, 4, 7) -ANY11C(UYVYToARGBRow_Any_MSA, UYVYToARGBRow_MSA, 1, 4, 4, 7) +#if defined(HAS_YUY2TOARGBROW_LSX) +ANY11C(YUY2ToARGBRow_Any_LSX, YUY2ToARGBRow_LSX, 1, 4, 4, 7) +ANY11C(UYVYToARGBRow_Any_LSX, UYVYToARGBRow_LSX, 1, 4, 4, 7) +#endif +#if defined(HAS_YUY2TOARGBROW_LASX) +ANY11C(YUY2ToARGBRow_Any_LASX, YUY2ToARGBRow_LASX, 1, 4, 4, 15) +ANY11C(UYVYToARGBRow_Any_LASX, UYVYToARGBRow_LASX, 1, 4, 4, 15) #endif #undef ANY11C // Any 1 to 1 interpolate. Takes 2 rows of source via stride. -#define ANY11T(NAMEANY, ANY_SIMD, SBPP, BPP, MASK) \ - void NAMEANY(uint8_t* dst_ptr, const uint8_t* src_ptr, \ - ptrdiff_t src_stride_ptr, int width, int source_y_fraction) { \ - SIMD_ALIGNED(uint8_t temp[64 * 3]); \ - memset(temp, 0, 64 * 2); /* for msan */ \ - int r = width & MASK; \ - int n = width & ~MASK; \ - if (n > 0) { \ - ANY_SIMD(dst_ptr, src_ptr, src_stride_ptr, n, source_y_fraction); \ - } \ - memcpy(temp, src_ptr + n * SBPP, r * SBPP); \ - memcpy(temp + 64, src_ptr + src_stride_ptr + n * SBPP, r * SBPP); \ - ANY_SIMD(temp + 128, temp, 64, MASK + 1, source_y_fraction); \ - memcpy(dst_ptr + n * BPP, temp + 128, r * BPP); \ +#define ANY11I(NAMEANY, ANY_SIMD, TD, TS, SBPP, BPP, MASK) \ + void NAMEANY(TD* dst_ptr, const TS* src_ptr, ptrdiff_t src_stride, \ + int width, int source_y_fraction) { \ + SIMD_ALIGNED(TS vin[64 * 2]); \ + static_assert((MASK + 1) * SBPP * sizeof(TS) <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + SIMD_ALIGNED(TD vout[64]); \ + static_assert((MASK + 1) * BPP * sizeof(TD) <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(dst_ptr, src_ptr, src_stride, n, source_y_fraction); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np * SBPP, r * SBPP * sizeof(TS)); \ + if (source_y_fraction) { \ + memcpy(vin + 64, src_ptr + src_stride + np * SBPP, \ + r * SBPP * sizeof(TS)); \ + } \ + ANY_SIMD(vout, vin, 64, MASK + 1, source_y_fraction); \ + memcpy(dst_ptr + np * BPP, vout, r * BPP * sizeof(TD)); \ } -#ifdef HAS_INTERPOLATEROW_AVX2 -ANY11T(InterpolateRow_Any_AVX2, InterpolateRow_AVX2, 1, 1, 31) -#endif -#ifdef HAS_INTERPOLATEROW_SSSE3 -ANY11T(InterpolateRow_Any_SSSE3, InterpolateRow_SSSE3, 1, 1, 15) +#if defined(HAS_INTERPOLATEROW_AVX2) +ANY11I(InterpolateRow_Any_AVX2, InterpolateRow_AVX2, uint8_t, uint8_t, 1, 1, 31) #endif #ifdef HAS_INTERPOLATEROW_NEON -ANY11T(InterpolateRow_Any_NEON, InterpolateRow_NEON, 1, 1, 15) +ANY11I(InterpolateRow_Any_NEON, InterpolateRow_NEON, uint8_t, uint8_t, 1, 1, 15) #endif -#ifdef HAS_INTERPOLATEROW_MSA -ANY11T(InterpolateRow_Any_MSA, InterpolateRow_MSA, 1, 1, 31) +#ifdef HAS_INTERPOLATEROW_LSX +ANY11I(InterpolateRow_Any_LSX, InterpolateRow_LSX, uint8_t, uint8_t, 1, 1, 15) #endif -#ifdef HAS_INTERPOLATEROW_MMI -ANY11T(InterpolateRow_Any_MMI, InterpolateRow_MMI, 1, 1, 7) +#ifdef HAS_INTERPOLATEROW_LASX +ANY11I(InterpolateRow_Any_LASX, InterpolateRow_LASX, uint8_t, uint8_t, 1, 1, 31) #endif -#undef ANY11T -// Any 1 to 1 mirror. -#define ANY11M(NAMEANY, ANY_SIMD, BPP, MASK) \ - void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_ptr, int width) { \ - SIMD_ALIGNED(uint8_t temp[64 * 2]); \ - memset(temp, 0, 64); /* for msan */ \ +#ifdef HAS_INTERPOLATEROW_16_NEON +ANY11I(InterpolateRow_16_Any_NEON, + InterpolateRow_16_NEON, + uint16_t, + uint16_t, + 1, + 1, + 7) +#endif +#ifdef HAS_INTERPOLATEROW_16_AVX2 +ANY11I(InterpolateRow_16_Any_AVX2, + InterpolateRow_16_AVX2, + uint16_t, + uint16_t, + 1, + 1, + 15) +#endif +#ifdef HAS_INTERPOLATEROW_WASMSIMD +ANY11I(InterpolateRow_Any_WASMSIMD, + InterpolateRow_WASMSIMD, + uint8_t, + uint8_t, + 1, + 1, + 15) +#endif +#ifdef HAS_INTERPOLATEROW_16_WASMSIMD +ANY11I(InterpolateRow_16_Any_WASMSIMD, + InterpolateRow_16_WASMSIMD, + uint16_t, + uint16_t, + 1, + 1, + 7) +#endif +#undef ANY11I + +// Any 1 to 1 half row +#define ANY11H(NAMEANY, ANY_SIMD, T, MASK) \ + void NAMEANY(const T* src_ptr, ptrdiff_t src_stride, T* dst_ptr, \ + int width) { \ + SIMD_ALIGNED(T vin[64 * 2]); \ + static_assert((MASK + 1) * sizeof(T) <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + SIMD_ALIGNED(T vout[64]); \ + static_assert((MASK + 1) * sizeof(T) <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, src_stride, dst_ptr, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np, r * sizeof(T)); \ + memcpy(vin + 64, src_ptr + src_stride + np, r * sizeof(T)); \ + ANY_SIMD(vin, 64, vout, MASK + 1); \ + memcpy(dst_ptr + np, vout, r * sizeof(T)); \ + } + +#ifdef HAS_HALFROW_AVX2 +ANY11H(HalfRow_Any_AVX2, HalfRow_AVX2, uint8_t, 31) +#endif +#ifdef HAS_HALFROW_16_AVX2 +ANY11H(HalfRow_16_Any_AVX2, HalfRow_16_AVX2, uint16_t, 15) +#endif + +#undef ANY11H + +// Any 1 to 1 half row with scale param +#define ANY11HS(NAMEANY, ANY_SIMD, TS, TD, MASK) \ + void NAMEANY(const TS* src_ptr, ptrdiff_t src_stride, TD* dst_ptr, \ + int scale, int width) { \ + SIMD_ALIGNED(TS vin[64 * 2]); \ + static_assert((MASK + 1) * sizeof(TS) <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + SIMD_ALIGNED(TD vout[64]); \ + static_assert((MASK + 1) * sizeof(TD) <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, src_stride, dst_ptr, scale, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np, r * sizeof(TS)); \ + memcpy(vin + 64, src_ptr + src_stride + np, r * sizeof(TS)); \ + ANY_SIMD(vin, 64, vout, scale, MASK + 1); \ + memcpy(dst_ptr + np, vout, r * sizeof(TD)); \ + } + +#ifdef HAS_HALFROW_16TO8_SSSE3 +ANY11HS(HalfRow_16To8_Any_SSSE3, HalfRow_16To8_SSSE3, uint16_t, uint8_t, 15) +#endif +#ifdef HAS_HALFROW_16TO8_AVX2 +ANY11HS(HalfRow_16To8_Any_AVX2, HalfRow_16To8_AVX2, uint16_t, uint8_t, 31) +#endif +#ifdef HAS_HALFROW_16TO8_NEON +ANY11HS(HalfRow_16To8_Any_NEON, HalfRow_16To8_NEON, uint16_t, uint8_t, 15) +#endif + +#undef ANY11HS + +// Any 2 to 1 half-width row with scale param +#define ANY11HWS(NAMEANY, ANY_SIMD, TS, TD, MASK) \ + void NAMEANY(const TS* src_ptr, ptrdiff_t src_stride, TD* dst_ptr, \ + int scale, int width) { \ + SIMD_ALIGNED(TS vin[128 * 2]); \ + static_assert((MASK + 1) * 2 * sizeof(TS) <= sizeof(vin), \ + "vin buffer too small"); \ + SIMD_ALIGNED(TD vout[64]); \ + static_assert((MASK + 1) * sizeof(TD) <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ int r = width & MASK; \ int n = width & ~MASK; \ if (n > 0) { \ - ANY_SIMD(src_ptr + r * BPP, dst_ptr, n); \ + ANY_SIMD(src_ptr, src_stride, dst_ptr, scale, n); \ } \ - memcpy(temp, src_ptr, r* BPP); \ - ANY_SIMD(temp, temp + 64, MASK + 1); \ - memcpy(dst_ptr + n * BPP, temp + 64 + (MASK + 1 - r) * BPP, r * BPP); \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np * 2, r * 2 * sizeof(TS)); \ + memcpy(vin + 128, src_ptr + src_stride + np * 2, r * 2 * sizeof(TS)); \ + ANY_SIMD(vin, 128, vout, scale, MASK + 1); \ + memcpy(dst_ptr + np, vout, r * sizeof(TD)); \ + } + +#ifdef HAS_HALFWIDTHROW_16TO8_SSSE3 +ANY11HWS(HalfWidthRow_16To8_Any_SSSE3, + HalfWidthRow_16To8_SSSE3, + uint16_t, + uint8_t, + 7) +#endif +#ifdef HAS_HALFWIDTHROW_16TO8_AVX2 +ANY11HWS(HalfWidthRow_16To8_Any_AVX2, + HalfWidthRow_16To8_AVX2, + uint16_t, + uint8_t, + 15) +#endif +#ifdef HAS_HALFWIDTHROW_16TO8_NEON +ANY11HWS(HalfWidthRow_16To8_Any_NEON, + HalfWidthRow_16To8_NEON, + uint16_t, + uint8_t, + 7) +#endif + +#undef ANY11HWS + +// Any 1 to 1 mirror. +#define ANY11M(NAMEANY, ANY_SIMD, BPP, MASK) \ + void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_ptr, int width) { \ + SIMD_ALIGNED(uint8_t vin[128]); \ + static_assert((MASK + 1) * BPP <= sizeof(vin), "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[128]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr + r * BPP, dst_ptr, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr, r * BPP); \ + ANY_SIMD(vin, vout, MASK + 1); \ + memcpy(dst_ptr + np * BPP, vout + (MASK + 1 - r) * BPP, r * BPP); \ } #ifdef HAS_MIRRORROW_AVX2 @@ -1107,13 +2218,28 @@ ANY11M(MirrorRow_Any_AVX2, MirrorRow_AVX2, 1, 31) ANY11M(MirrorRow_Any_SSSE3, MirrorRow_SSSE3, 1, 15) #endif #ifdef HAS_MIRRORROW_NEON -ANY11M(MirrorRow_Any_NEON, MirrorRow_NEON, 1, 15) +ANY11M(MirrorRow_Any_NEON, MirrorRow_NEON, 1, 31) #endif -#ifdef HAS_MIRRORROW_MSA -ANY11M(MirrorRow_Any_MSA, MirrorRow_MSA, 1, 63) +#ifdef HAS_MIRRORROW_LSX +ANY11M(MirrorRow_Any_LSX, MirrorRow_LSX, 1, 15) #endif -#ifdef HAS_MIRRORROW_MMI -ANY11M(MirrorRow_Any_MMI, MirrorRow_MMI, 1, 7) +#ifdef HAS_MIRRORROW_LASX +ANY11M(MirrorRow_Any_LASX, MirrorRow_LASX, 1, 31) +#endif +#ifdef HAS_MIRRORUVROW_AVX2 +ANY11M(MirrorUVRow_Any_AVX2, MirrorUVRow_AVX2, 2, 15) +#endif +#ifdef HAS_MIRRORUVROW_SSSE3 +ANY11M(MirrorUVRow_Any_SSSE3, MirrorUVRow_SSSE3, 2, 7) +#endif +#ifdef HAS_MIRRORUVROW_NEON +ANY11M(MirrorUVRow_Any_NEON, MirrorUVRow_NEON, 2, 31) +#endif +#ifdef HAS_MIRRORUVROW_LSX +ANY11M(MirrorUVRow_Any_LSX, MirrorUVRow_LSX, 2, 7) +#endif +#ifdef HAS_MIRRORUVROW_LASX +ANY11M(MirrorUVRow_Any_LASX, MirrorUVRow_LASX, 2, 15) #endif #ifdef HAS_ARGBMIRRORROW_AVX2 ANY11M(ARGBMirrorRow_Any_AVX2, ARGBMirrorRow_AVX2, 4, 7) @@ -1122,40 +2248,131 @@ ANY11M(ARGBMirrorRow_Any_AVX2, ARGBMirrorRow_AVX2, 4, 7) ANY11M(ARGBMirrorRow_Any_SSE2, ARGBMirrorRow_SSE2, 4, 3) #endif #ifdef HAS_ARGBMIRRORROW_NEON -ANY11M(ARGBMirrorRow_Any_NEON, ARGBMirrorRow_NEON, 4, 3) +ANY11M(ARGBMirrorRow_Any_NEON, ARGBMirrorRow_NEON, 4, 7) #endif -#ifdef HAS_ARGBMIRRORROW_MSA -ANY11M(ARGBMirrorRow_Any_MSA, ARGBMirrorRow_MSA, 4, 15) +#ifdef HAS_ARGBMIRRORROW_LSX +ANY11M(ARGBMirrorRow_Any_LSX, ARGBMirrorRow_LSX, 4, 3) #endif -#ifdef HAS_ARGBMIRRORROW_MMI -ANY11M(ARGBMirrorRow_Any_MMI, ARGBMirrorRow_MMI, 4, 1) +#ifdef HAS_ARGBMIRRORROW_LASX +ANY11M(ARGBMirrorRow_Any_LASX, ARGBMirrorRow_LASX, 4, 7) +#endif +#ifdef HAS_RGB24MIRRORROW_AVX2 +ANY11M(RGB24MirrorRow_Any_AVX2, RGB24MirrorRow_AVX2, 3, 31) +#endif +#ifdef HAS_RGB24MIRRORROW_SSSE3 +ANY11M(RGB24MirrorRow_Any_SSSE3, RGB24MirrorRow_SSSE3, 3, 15) +#endif +#ifdef HAS_RGB24MIRRORROW_NEON +ANY11M(RGB24MirrorRow_Any_NEON, RGB24MirrorRow_NEON, 3, 15) +#endif +#ifdef HAS_MIRRORROW_WASMSIMD +ANY11M(MirrorRow_Any_WASMSIMD, MirrorRow_WASMSIMD, 1, 15) +#endif +#ifdef HAS_MIRRORUVROW_WASMSIMD +ANY11M(MirrorUVRow_Any_WASMSIMD, MirrorUVRow_WASMSIMD, 2, 7) +#endif +#ifdef HAS_ARGBMIRRORROW_WASMSIMD +ANY11M(ARGBMirrorRow_Any_WASMSIMD, ARGBMirrorRow_WASMSIMD, 4, 3) +#endif +#ifdef HAS_RGB24MIRRORROW_WASMSIMD +ANY11M(RGB24MirrorRow_Any_WASMSIMD, RGB24MirrorRow_WASMSIMD, 3, 15) #endif #undef ANY11M -// Any 1 plane. (memset) -#define ANY1(NAMEANY, ANY_SIMD, T, BPP, MASK) \ - void NAMEANY(uint8_t* dst_ptr, T v32, int width) { \ - SIMD_ALIGNED(uint8_t temp[64]); \ - int r = width & MASK; \ - int n = width & ~MASK; \ - if (n > 0) { \ - ANY_SIMD(dst_ptr, v32, n); \ - } \ - ANY_SIMD(temp, v32, MASK + 1); \ - memcpy(dst_ptr + n * BPP, temp, r * BPP); \ +// Any 1 to 1 mirror with type. +#define ANY11MT(NAMEANY, ANY_SIMD, T, BPP, MASK) \ + void NAMEANY(const T* src_ptr, T* dst_ptr, int width) { \ + SIMD_ALIGNED(T vin[64]); \ + static_assert((MASK + 1) * BPP <= sizeof(vin), "vin buffer too small"); \ + SIMD_ALIGNED(T vout[64]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr + r, dst_ptr, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr, r * BPP); \ + ANY_SIMD(vin, vout, MASK + 1); \ + memcpy(dst_ptr + np, vout + (MASK + 1 - r), r * BPP); \ } -#ifdef HAS_SETROW_X86 -ANY1(SetRow_Any_X86, SetRow_X86, uint8_t, 1, 3) +#ifdef HAS_MIRRORROW_16_NEON +ANY11MT(MirrorRow_16_Any_NEON, MirrorRow_16_NEON, uint16_t, 2, 15) +#endif +#undef ANY11MT + +// Any 1 to 2 mirror split UV. +#define ANY12MR(NAMEANY, ANY_SIMD, MASK) \ + void NAMEANY(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, \ + int width) { \ + SIMD_ALIGNED(uint8_t vin[128]); \ + static_assert((MASK + 1) * 2 <= sizeof(vin), "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[64 * 2]); \ + static_assert(MASK + 1 <= sizeof(vout) / 2, "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_uv + r * 2, dst_u, dst_v, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_uv, r * 2); \ + ANY_SIMD(vin, vout, vout + 64, MASK + 1); \ + memcpy(dst_u + np, vout + (MASK + 1 - r), r); \ + memcpy(dst_v + np, vout + 64 + (MASK + 1 - r), r); \ + } + +#ifdef HAS_MIRRORSPLITUVROW_SSSE3 +ANY12MR(MirrorSplitUVRow_Any_SSSE3, MirrorSplitUVRow_SSSE3, 7) +#endif +#ifdef HAS_MIRRORSPLITUVROW_AVX2 +ANY12MR(MirrorSplitUVRow_Any_AVX2, MirrorSplitUVRow_AVX2, 15) +#endif +#undef ANY12MR + +// Any 1 plane. (memset) +#define ANY1(NAMEANY, ANY_SIMD, T, BPP, MASK) \ + void NAMEANY(uint8_t* dst_ptr, T v32, int width) { \ + SIMD_ALIGNED(uint8_t vout[64]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(dst_ptr, v32, n); \ + } \ + ptrdiff_t np = n; \ + ANY_SIMD(vout, v32, MASK + 1); \ + memcpy(dst_ptr + np * BPP, vout, r * BPP); \ + } + +#ifdef HAS_SETROW_AVX2 +ANY1(SetRow_Any_AVX2, SetRow_AVX2, uint8_t, 1, 31) #endif #ifdef HAS_SETROW_NEON ANY1(SetRow_Any_NEON, SetRow_NEON, uint8_t, 1, 15) #endif +#ifdef HAS_SETROW_LSX +ANY1(SetRow_Any_LSX, SetRow_LSX, uint8_t, 1, 15) +#endif +#ifdef HAS_SETROW_LASX +ANY1(SetRow_Any_LASX, SetRow_LASX, uint8_t, 1, 31) +#endif +#ifdef HAS_ARGBSETROW_AVX2 +ANY1(ARGBSetRow_Any_AVX2, ARGBSetRow_AVX2, uint32_t, 4, 7) +#endif #ifdef HAS_ARGBSETROW_NEON ANY1(ARGBSetRow_Any_NEON, ARGBSetRow_NEON, uint32_t, 4, 3) #endif -#ifdef HAS_ARGBSETROW_MSA -ANY1(ARGBSetRow_Any_MSA, ARGBSetRow_MSA, uint32_t, 4, 3) +#ifdef HAS_ARGBSETROW_LSX +ANY1(ARGBSetRow_Any_LSX, ARGBSetRow_LSX, uint32_t, 4, 3) +#endif +#ifdef HAS_ARGBSETROW_LASX +ANY1(ARGBSetRow_Any_LASX, ARGBSetRow_LASX, uint32_t, 4, 7) #endif #undef ANY1 @@ -1163,17 +2380,24 @@ ANY1(ARGBSetRow_Any_MSA, ARGBSetRow_MSA, uint32_t, 4, 3) #define ANY12(NAMEANY, ANY_SIMD, UVSHIFT, BPP, DUVSHIFT, MASK) \ void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_u, uint8_t* dst_v, \ int width) { \ - SIMD_ALIGNED(uint8_t temp[128 * 3]); \ - memset(temp, 0, 128); /* for msan */ \ + SIMD_ALIGNED(uint8_t vin[256]); \ + static_assert(SS(MASK + 1, UVSHIFT) * BPP <= sizeof(vin), \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[256 * 2]); \ + static_assert(SS(MASK + 1, DUVSHIFT) <= sizeof(vout) / 2, \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ int r = width & MASK; \ int n = width & ~MASK; \ if (n > 0) { \ ANY_SIMD(src_ptr, dst_u, dst_v, n); \ } \ - memcpy(temp, src_ptr + (n >> UVSHIFT) * BPP, SS(r, UVSHIFT) * BPP); \ - ANY_SIMD(temp, temp + 128, temp + 256, MASK + 1); \ - memcpy(dst_u + (n >> DUVSHIFT), temp + 128, SS(r, DUVSHIFT)); \ - memcpy(dst_v + (n >> DUVSHIFT), temp + 256, SS(r, DUVSHIFT)); \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + (np >> UVSHIFT) * BPP, SS(r, UVSHIFT) * BPP); \ + ANY_SIMD(vin, vout, vout + 256, MASK + 1); \ + memcpy(dst_u + (np >> DUVSHIFT), vout, SS(r, DUVSHIFT)); \ + memcpy(dst_v + (np >> DUVSHIFT), vout + 256, SS(r, DUVSHIFT)); \ } #ifdef HAS_SPLITUVROW_SSE2 @@ -1185,14 +2409,11 @@ ANY12(SplitUVRow_Any_AVX2, SplitUVRow_AVX2, 0, 2, 0, 31) #ifdef HAS_SPLITUVROW_NEON ANY12(SplitUVRow_Any_NEON, SplitUVRow_NEON, 0, 2, 0, 15) #endif -#ifdef HAS_SPLITUVROW_MSA -ANY12(SplitUVRow_Any_MSA, SplitUVRow_MSA, 0, 2, 0, 31) +#ifdef HAS_SPLITUVROW_LSX +ANY12(SplitUVRow_Any_LSX, SplitUVRow_LSX, 0, 2, 0, 15) #endif -#ifdef HAS_SPLITUVROW_MMI -ANY12(SplitUVRow_Any_MMI, SplitUVRow_MMI, 0, 2, 0, 7) -#endif -#ifdef HAS_ARGBTOUV444ROW_SSSE3 -ANY12(ARGBToUV444Row_Any_SSSE3, ARGBToUV444Row_SSSE3, 0, 4, 0, 15) +#ifdef HAS_SPLITUVROW_LASX +ANY12(SplitUVRow_Any_LASX, SplitUVRow_LASX, 0, 2, 0, 31) #endif #ifdef HAS_YUY2TOUV422ROW_AVX2 ANY12(YUY2ToUV422Row_Any_AVX2, YUY2ToUV422Row_AVX2, 1, 4, 1, 31) @@ -1203,92 +2424,396 @@ ANY12(YUY2ToUV422Row_Any_SSE2, YUY2ToUV422Row_SSE2, 1, 4, 1, 15) ANY12(UYVYToUV422Row_Any_SSE2, UYVYToUV422Row_SSE2, 1, 4, 1, 15) #endif #ifdef HAS_YUY2TOUV422ROW_NEON -ANY12(ARGBToUV444Row_Any_NEON, ARGBToUV444Row_NEON, 0, 4, 0, 7) ANY12(YUY2ToUV422Row_Any_NEON, YUY2ToUV422Row_NEON, 1, 4, 1, 15) ANY12(UYVYToUV422Row_Any_NEON, UYVYToUV422Row_NEON, 1, 4, 1, 15) #endif -#ifdef HAS_YUY2TOUV422ROW_MSA -ANY12(ARGBToUV444Row_Any_MSA, ARGBToUV444Row_MSA, 0, 4, 0, 15) -ANY12(YUY2ToUV422Row_Any_MSA, YUY2ToUV422Row_MSA, 1, 4, 1, 31) -ANY12(UYVYToUV422Row_Any_MSA, UYVYToUV422Row_MSA, 1, 4, 1, 31) +#ifdef HAS_YUY2TOUV422ROW_LSX +ANY12(YUY2ToUV422Row_Any_LSX, YUY2ToUV422Row_LSX, 1, 4, 1, 15) +ANY12(UYVYToUV422Row_Any_LSX, UYVYToUV422Row_LSX, 1, 4, 1, 15) #endif -#ifdef HAS_YUY2TOUV422ROW_MMI -ANY12(ARGBToUV444Row_Any_MMI, ARGBToUV444Row_MMI, 0, 4, 0, 7) -ANY12(UYVYToUV422Row_Any_MMI, UYVYToUV422Row_MMI, 1, 4, 1, 15) -ANY12(YUY2ToUV422Row_Any_MMI, YUY2ToUV422Row_MMI, 1, 4, 1, 15) +#ifdef HAS_YUY2TOUV422ROW_LASX +ANY12(YUY2ToUV422Row_Any_LASX, YUY2ToUV422Row_LASX, 1, 4, 1, 31) +ANY12(UYVYToUV422Row_Any_LASX, UYVYToUV422Row_LASX, 1, 4, 1, 31) #endif #undef ANY12 +// Any 2 16 bit planes with parameter to 1 +#define ANY12PT(NAMEANY, ANY_SIMD, T, BPP, MASK) \ + void NAMEANY(const T* src_uv, T* dst_u, T* dst_v, int depth, int width) { \ + SIMD_ALIGNED(T vin[16 * 2]); \ + static_assert((MASK + 1) * BPP * 2 <= sizeof(vin), \ + "vin buffer too small"); \ + SIMD_ALIGNED(T vout[16 * 2]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout) / 2, \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_uv, dst_u, dst_v, depth, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_uv + np * 2, r * BPP * 2); \ + ANY_SIMD(vin, vout, vout + 16, depth, MASK + 1); \ + memcpy(dst_u + np, vout, r * BPP); \ + memcpy(dst_v + np, vout + 16, r * BPP); \ + } + +#ifdef HAS_SPLITUVROW_16_AVX2 +ANY12PT(SplitUVRow_16_Any_AVX2, SplitUVRow_16_AVX2, uint16_t, 2, 15) +#endif + +#ifdef HAS_SPLITUVROW_16_NEON +ANY12PT(SplitUVRow_16_Any_NEON, SplitUVRow_16_NEON, uint16_t, 2, 7) +#endif + +#undef ANY21CT + // Any 1 to 3. Outputs RGB planes. #define ANY13(NAMEANY, ANY_SIMD, BPP, MASK) \ void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_r, uint8_t* dst_g, \ uint8_t* dst_b, int width) { \ - SIMD_ALIGNED(uint8_t temp[16 * 6]); \ - memset(temp, 0, 16 * 3); /* for msan */ \ + SIMD_ALIGNED(uint8_t vin[(MASK + 1) * BPP]); \ + SIMD_ALIGNED(uint8_t vout[(MASK + 1) * 3]); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ int r = width & MASK; \ int n = width & ~MASK; \ if (n > 0) { \ ANY_SIMD(src_ptr, dst_r, dst_g, dst_b, n); \ } \ - memcpy(temp, src_ptr + n * BPP, r * BPP); \ - ANY_SIMD(temp, temp + 16 * 3, temp + 16 * 4, temp + 16 * 5, MASK + 1); \ - memcpy(dst_r + n, temp + 16 * 3, r); \ - memcpy(dst_g + n, temp + 16 * 4, r); \ - memcpy(dst_b + n, temp + 16 * 5, r); \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np * BPP, r * BPP); \ + ANY_SIMD(vin, vout, vout + MASK + 1, vout + (MASK + 1) * 2, MASK + 1); \ + memcpy(dst_r + np, vout, r); \ + memcpy(dst_g + np, vout + MASK + 1, r); \ + memcpy(dst_b + np, vout + (MASK + 1) * 2, r); \ } #ifdef HAS_SPLITRGBROW_SSSE3 ANY13(SplitRGBRow_Any_SSSE3, SplitRGBRow_SSSE3, 3, 15) #endif +#ifdef HAS_SPLITRGBROW_SSE41 +ANY13(SplitRGBRow_Any_SSE41, SplitRGBRow_SSE41, 3, 15) +#endif +#ifdef HAS_SPLITRGBROW_AVX2 +ANY13(SplitRGBRow_Any_AVX2, SplitRGBRow_AVX2, 3, 31) +#endif #ifdef HAS_SPLITRGBROW_NEON ANY13(SplitRGBRow_Any_NEON, SplitRGBRow_NEON, 3, 15) #endif -#ifdef HAS_SPLITRGBROW_MMI -ANY13(SplitRGBRow_Any_MMI, SplitRGBRow_MMI, 3, 3) +#ifdef HAS_SPLITXRGBROW_SSE2 +ANY13(SplitXRGBRow_Any_SSE2, SplitXRGBRow_SSE2, 4, 7) +#endif +#ifdef HAS_SPLITXRGBROW_SSSE3 +ANY13(SplitXRGBRow_Any_SSSE3, SplitXRGBRow_SSSE3, 4, 7) +#endif +#ifdef HAS_SPLITXRGBROW_AVX2 +ANY13(SplitXRGBRow_Any_AVX2, SplitXRGBRow_AVX2, 4, 15) +#endif +#ifdef HAS_SPLITXRGBROW_NEON +ANY13(SplitXRGBRow_Any_NEON, SplitXRGBRow_NEON, 4, 15) +#endif + +// Any 1 to 4. Outputs ARGB planes. +#define ANY14(NAMEANY, ANY_SIMD, BPP, MASK) \ + void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_r, uint8_t* dst_g, \ + uint8_t* dst_b, uint8_t* dst_a, int width) { \ + SIMD_ALIGNED(uint8_t vin[16 * 4]); \ + static_assert((MASK + 1) * BPP <= sizeof(vin), "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[16 * 4]); \ + static_assert(MASK + 1 <= sizeof(vout) / 4, "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, dst_r, dst_g, dst_b, dst_a, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np * BPP, r * BPP); \ + ANY_SIMD(vin, vout, vout + 16, vout + 32, vout + 48, MASK + 1); \ + memcpy(dst_r + np, vout, r); \ + memcpy(dst_g + np, vout + 16, r); \ + memcpy(dst_b + np, vout + 32, r); \ + memcpy(dst_a + np, vout + 48, r); \ + } + +#ifdef HAS_SPLITARGBROW_SSE2 +ANY14(SplitARGBRow_Any_SSE2, SplitARGBRow_SSE2, 4, 7) +#endif +#ifdef HAS_SPLITARGBROW_SSSE3 +ANY14(SplitARGBRow_Any_SSSE3, SplitARGBRow_SSSE3, 4, 7) +#endif +#ifdef HAS_SPLITARGBROW_AVX2 +ANY14(SplitARGBRow_Any_AVX2, SplitARGBRow_AVX2, 4, 15) +#endif +#ifdef HAS_SPLITARGBROW_NEON +ANY14(SplitARGBRow_Any_NEON, SplitARGBRow_NEON, 4, 15) #endif // Any 1 to 2 with source stride (2 rows of source). Outputs UV planes. // 128 byte row allows for 32 avx ARGB pixels. #define ANY12S(NAMEANY, ANY_SIMD, UVSHIFT, BPP, MASK) \ - void NAMEANY(const uint8_t* src_ptr, int src_stride_ptr, uint8_t* dst_u, \ + void NAMEANY(const uint8_t* src_ptr, int src_stride, uint8_t* dst_u, \ uint8_t* dst_v, int width) { \ - SIMD_ALIGNED(uint8_t temp[128 * 4]); \ - memset(temp, 0, 128 * 2); /* for msan */ \ + SIMD_ALIGNED(uint8_t vin[256 * 2]); \ + static_assert(SS(MASK + 1, UVSHIFT) * BPP <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[256 * 2]); \ + static_assert(SS(MASK + 1, 1) <= sizeof(vout) / 2, \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ int r = width & MASK; \ int n = width & ~MASK; \ if (n > 0) { \ - ANY_SIMD(src_ptr, src_stride_ptr, dst_u, dst_v, n); \ + ANY_SIMD(src_ptr, src_stride, dst_u, dst_v, n); \ } \ - memcpy(temp, src_ptr + (n >> UVSHIFT) * BPP, SS(r, UVSHIFT) * BPP); \ - memcpy(temp + 128, src_ptr + src_stride_ptr + (n >> UVSHIFT) * BPP, \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + (np >> UVSHIFT) * BPP, SS(r, UVSHIFT) * BPP); \ + memcpy(vin + 256, src_ptr + src_stride + (np >> UVSHIFT) * BPP, \ SS(r, UVSHIFT) * BPP); \ if ((width & 1) && UVSHIFT == 0) { /* repeat last pixel for subsample */ \ - memcpy(temp + SS(r, UVSHIFT) * BPP, temp + SS(r, UVSHIFT) * BPP - BPP, \ + memcpy(vin + SS(r, UVSHIFT) * BPP, vin + SS(r, UVSHIFT) * BPP - BPP, \ BPP); \ - memcpy(temp + 128 + SS(r, UVSHIFT) * BPP, \ - temp + 128 + SS(r, UVSHIFT) * BPP - BPP, BPP); \ + memcpy(vin + 256 + SS(r, UVSHIFT) * BPP, \ + vin + 256 + SS(r, UVSHIFT) * BPP - BPP, BPP); \ } \ - ANY_SIMD(temp, 128, temp + 256, temp + 384, MASK + 1); \ - memcpy(dst_u + (n >> 1), temp + 256, SS(r, 1)); \ - memcpy(dst_v + (n >> 1), temp + 384, SS(r, 1)); \ + ANY_SIMD(vin, 256, vout, vout + 256, MASK + 1); \ + memcpy(dst_u + (np >> 1), vout, SS(r, 1)); \ + memcpy(dst_v + (np >> 1), vout + 256, SS(r, 1)); \ } -#ifdef HAS_ARGBTOUVROW_AVX2 -ANY12S(ARGBToUVRow_Any_AVX2, ARGBToUVRow_AVX2, 0, 4, 31) +#define ANY12M(NAMEANY, ANY_SIMD, BPP, MASK) \ + void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_u, uint8_t* dst_v, \ + int width, const struct ArgbConstants* c) { \ + SIMD_ALIGNED(uint8_t vin[256]); \ + static_assert((MASK + 1) * BPP <= sizeof(vin), "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[256 * 2]); \ + static_assert(MASK + 1 <= sizeof(vout) / 2, "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, dst_u, dst_v, n, c); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np * BPP, r * BPP); \ + ANY_SIMD(vin, vout, vout + 256, MASK + 1, c); \ + memcpy(dst_u + np, vout, r); \ + memcpy(dst_v + np, vout + 256, r); \ + } + +#define ANY12MS(NAMEANY, ANY_SIMD, UVSHIFT, BPP, MASK) \ + void NAMEANY(const uint8_t* src_ptr, int src_stride, uint8_t* dst_u, \ + uint8_t* dst_v, int width, const struct ArgbConstants* c) { \ + SIMD_ALIGNED(uint8_t vin[256 * 2]); \ + static_assert(SS(MASK + 1, UVSHIFT) * BPP <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[256 * 2]); \ + static_assert(SS(MASK + 1, 1) <= sizeof(vout) / 2, \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, src_stride, dst_u, dst_v, n, c); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + (np >> UVSHIFT) * BPP, SS(r, UVSHIFT) * BPP); \ + memcpy(vin + 256, src_ptr + src_stride + (np >> UVSHIFT) * BPP, \ + SS(r, UVSHIFT) * BPP); \ + if ((width & 1) && UVSHIFT == 0) { /* repeat last pixel for subsample */ \ + memcpy(vin + SS(r, UVSHIFT) * BPP, vin + SS(r, UVSHIFT) * BPP - BPP, \ + BPP); \ + memcpy(vin + 256 + SS(r, UVSHIFT) * BPP, \ + vin + 256 + SS(r, UVSHIFT) * BPP - BPP, BPP); \ + } \ + ANY_SIMD(vin, 256, vout, vout + 256, MASK + 1, c); \ + memcpy(dst_u + (np >> 1), vout, SS(r, 1)); \ + memcpy(dst_v + (np >> 1), vout + 256, SS(r, 1)); \ + } + +#ifdef HAS_ARGBTOUVMATRIXROW_NEON +ANY12MS(ARGBToUVMatrixRow_Any_NEON, ARGBToUVMatrixRow_NEON, 0, 4, 15) #endif -#ifdef HAS_ABGRTOUVROW_AVX2 -ANY12S(ABGRToUVRow_Any_AVX2, ABGRToUVRow_AVX2, 0, 4, 31) +#ifdef HAS_ARGBTOUVMATRIXROW_NEON_I8MM +ANY12MS(ARGBToUVMatrixRow_Any_NEON_I8MM, ARGBToUVMatrixRow_NEON_I8MM, 0, 4, 15) #endif -#ifdef HAS_ARGBTOUVJROW_AVX2 -ANY12S(ARGBToUVJRow_Any_AVX2, ARGBToUVJRow_AVX2, 0, 4, 31) +#ifdef HAS_RGBTOUVMATRIXROW_NEON +ANY12MS(RGBToUVMatrixRow_Any_NEON, RGBToUVMatrixRow_NEON, 0, 3, 15) #endif -#ifdef HAS_ARGBTOUVROW_SSSE3 -ANY12S(ARGBToUVRow_Any_SSSE3, ARGBToUVRow_SSSE3, 0, 4, 15) -ANY12S(ARGBToUVJRow_Any_SSSE3, ARGBToUVJRow_SSSE3, 0, 4, 15) -ANY12S(BGRAToUVRow_Any_SSSE3, BGRAToUVRow_SSSE3, 0, 4, 15) -ANY12S(ABGRToUVRow_Any_SSSE3, ABGRToUVRow_SSSE3, 0, 4, 15) -ANY12S(RGBAToUVRow_Any_SSSE3, RGBAToUVRow_SSSE3, 0, 4, 15) +#ifdef HAS_RGB565TOUVMATRIXROW_NEON +ANY12MS(RGB565ToUVMatrixRow_Any_NEON, RGB565ToUVMatrixRow_NEON, 0, 2, 15) #endif +#ifdef HAS_ARGB1555TOUVMATRIXROW_NEON +ANY12MS(ARGB1555ToUVMatrixRow_Any_NEON, ARGB1555ToUVMatrixRow_NEON, 0, 2, 15) +#endif +#ifdef HAS_ARGB4444TOUVMATRIXROW_NEON +ANY12MS(ARGB4444ToUVMatrixRow_Any_NEON, ARGB4444ToUVMatrixRow_NEON, 0, 2, 15) +#endif +#ifdef HAS_ARGBTOUVMATRIXROW_AVX2 +ANY12MS(ARGBToUVMatrixRow_Any_AVX2, ARGBToUVMatrixRow_AVX2, 0, 4, 15) +ANY12MS(RGBToUVMatrixRow_Any_AVX2, RGBToUVMatrixRow_AVX2, 0, 3, 31) +ANY12MS(RGB565ToUVMatrixRow_Any_AVX2, RGB565ToUVMatrixRow_AVX2, 0, 2, 15) +#ifdef HAS_ARGB1555TOARGBROW_AVX2 +ANY12MS(ARGB1555ToUVMatrixRow_Any_AVX2, ARGB1555ToUVMatrixRow_AVX2, 0, 2, 15) +#endif +#ifdef HAS_ARGB4444TOARGBROW_AVX2 +ANY12MS(ARGB4444ToUVMatrixRow_Any_AVX2, ARGB4444ToUVMatrixRow_AVX2, 0, 2, 15) +#endif +#endif +#ifdef HAS_ARGBTOUVMATRIXROW_SSSE3 +ANY12MS(ARGBToUVMatrixRow_Any_SSSE3, ARGBToUVMatrixRow_SSSE3, 0, 4, 7) +#endif +#ifdef HAS_RGBTOUVMATRIXROW_SSSE3 +ANY12MS(RGBToUVMatrixRow_Any_SSSE3, RGBToUVMatrixRow_SSSE3, 0, 3, 15) +#endif +#ifdef HAS_ARGBTOUV444MATRIXROW_AVX2 +ANY12M(ARGBToUV444MatrixRow_Any_AVX2, ARGBToUV444MatrixRow_AVX2, 4, 31) +#endif +#ifdef HAS_RGBTOUV444MATRIXROW_AVX2 +ANY12M(RGBToUV444MatrixRow_Any_AVX2, RGBToUV444MatrixRow_AVX2, 3, 31) +#endif +#ifdef HAS_ARGBTOUV444MATRIXROW_SSSE3 +ANY12M(ARGBToUV444MatrixRow_Any_SSSE3, ARGBToUV444MatrixRow_SSSE3, 4, 15) +#endif +#ifdef HAS_RGBTOUV444MATRIXROW_SSSE3 +ANY12M(RGBToUV444MatrixRow_Any_SSSE3, RGBToUV444MatrixRow_SSSE3, 3, 15) +#endif +#ifdef HAS_ARGBTOUV444MATRIXROW_NEON +ANY12M(ARGBToUV444MatrixRow_Any_NEON, ARGBToUV444MatrixRow_NEON, 4, 7) +#endif +#ifdef HAS_RGBTOUV444MATRIXROW_NEON +ANY12M(RGBToUV444MatrixRow_Any_NEON, RGBToUV444MatrixRow_NEON, 3, 7) +#endif +#ifdef HAS_ARGBTOUV444MATRIXROW_NEON_I8MM +ANY12M(ARGBToUV444MatrixRow_Any_NEON_I8MM, ARGBToUV444MatrixRow_NEON_I8MM, 4, 7) +#endif +#ifdef HAS_ARGBTOUVMATRIXROW_WASMSIMD +ANY12MS(ARGBToUVMatrixRow_Any_WASMSIMD, ARGBToUVMatrixRow_WASMSIMD, 0, 4, 15) +#endif +#ifdef HAS_RGBTOUVMATRIXROW_WASMSIMD +ANY12MS(RGBToUVMatrixRow_Any_WASMSIMD, RGBToUVMatrixRow_WASMSIMD, 0, 3, 15) +#endif +#ifdef HAS_RGB565TOUVMATRIXROW_WASMSIMD +ANY12MS(RGB565ToUVMatrixRow_Any_WASMSIMD, + RGB565ToUVMatrixRow_WASMSIMD, + 0, + 2, + 15) +#endif +#ifdef HAS_ARGB1555TOUVMATRIXROW_WASMSIMD +ANY12MS(ARGB1555ToUVMatrixRow_Any_WASMSIMD, + ARGB1555ToUVMatrixRow_WASMSIMD, + 0, + 2, + 15) +#endif +#ifdef HAS_ARGB4444TOUVMATRIXROW_WASMSIMD +ANY12MS(ARGB4444ToUVMatrixRow_Any_WASMSIMD, + ARGB4444ToUVMatrixRow_WASMSIMD, + 0, + 2, + 15) +#endif +#ifdef HAS_ARGBTOUV444MATRIXROW_WASMSIMD +ANY12M(ARGBToUV444MatrixRow_Any_WASMSIMD, ARGBToUV444MatrixRow_WASMSIMD, 4, 15) +#endif +#ifdef HAS_RGBTOUV444MATRIXROW_WASMSIMD +ANY12M(RGBToUV444MatrixRow_Any_WASMSIMD, RGBToUV444MatrixRow_WASMSIMD, 3, 15) +#endif + +#define ANY11MC(NAMEANY, ANY_SIMD, BPP, MASK) \ + void NAMEANY(const uint8_t* src_ptr, uint8_t* dst_ptr, int width, \ + const struct ArgbConstants* c) { \ + SIMD_ALIGNED(uint8_t vin[256]); \ + static_assert((MASK + 1) * BPP <= sizeof(vin), "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[256]); \ + static_assert(MASK + 1 <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_ptr, dst_ptr, n, c); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + np * BPP, r * BPP); \ + ANY_SIMD(vin, vout, MASK + 1, c); \ + memcpy(dst_ptr + np, vout, r); \ + } + +#ifdef HAS_ARGBTOYMATRIXROW_SSSE3 +ANY11MC(ARGBToYMatrixRow_Any_SSSE3, ARGBToYMatrixRow_SSSE3, 4, 15) +ANY11MC(RGBToYMatrixRow_Any_SSSE3, RGBToYMatrixRow_SSSE3, 3, 15) +#endif +#ifdef HAS_ARGBTOYMATRIXROW_AVX2 +ANY11MC(ARGBToYMatrixRow_Any_AVX2, ARGBToYMatrixRow_AVX2, 4, 31) +ANY11MC(RGBToYMatrixRow_Any_AVX2, RGBToYMatrixRow_AVX2, 3, 31) +ANY11MC(RGB565ToYMatrixRow_Any_AVX2, RGB565ToYMatrixRow_AVX2, 2, 31) +#ifdef HAS_ARGB1555TOYMATRIXROW_AVX2 +ANY11MC(ARGB1555ToYMatrixRow_Any_AVX2, ARGB1555ToYMatrixRow_AVX2, 2, 31) +#endif +#ifdef HAS_ARGB4444TOYMATRIXROW_AVX2 +ANY11MC(ARGB4444ToYMatrixRow_Any_AVX2, ARGB4444ToYMatrixRow_AVX2, 2, 31) +#endif +#endif +#ifdef HAS_ARGBTOYMATRIXROW_NEON +ANY11MC(ARGBToYMatrixRow_Any_NEON, ARGBToYMatrixRow_NEON, 4, 15) +#endif +#ifdef HAS_ARGBTOYMATRIXROW_NEON_DOTPROD +ANY11MC(ARGBToYMatrixRow_Any_NEON_DotProd, ARGBToYMatrixRow_NEON_DotProd, 4, 15) +ANY11MC(RGBToYMatrixRow_Any_NEON_DotProd, RGBToYMatrixRow_NEON_DotProd, 3, 15) +#endif +#ifdef HAS_RGBTOYMATRIXROW_NEON +ANY11MC(RGBToYMatrixRow_Any_NEON, RGBToYMatrixRow_NEON, 3, 15) +#endif +#ifdef HAS_RGB565TOYMATRIXROW_NEON +ANY11MC(RGB565ToYMatrixRow_Any_NEON, RGB565ToYMatrixRow_NEON, 2, 15) +#endif +#ifdef HAS_ARGB1555TOYMATRIXROW_NEON +ANY11MC(ARGB1555ToYMatrixRow_Any_NEON, ARGB1555ToYMatrixRow_NEON, 2, 15) +#endif +#ifdef HAS_ARGB4444TOYMATRIXROW_NEON +ANY11MC(ARGB4444ToYMatrixRow_Any_NEON, ARGB4444ToYMatrixRow_NEON, 2, 15) +#endif +#ifdef HAS_ARGBTOYMATRIXROW_LSX +ANY11MC(ARGBToYMatrixRow_Any_LSX, ARGBToYMatrixRow_LSX, 4, 7) +#endif +#ifdef HAS_ARGBTOYMATRIXROW_LASX +ANY11MC(ARGBToYMatrixRow_Any_LASX, ARGBToYMatrixRow_LASX, 4, 15) +#endif +#ifdef HAS_RGBTOYMATRIXROW_LSX +ANY11MC(RGBToYMatrixRow_Any_LSX, RGBToYMatrixRow_LSX, 3, 15) +#endif +#ifdef HAS_RGBTOYMATRIXROW_LASX +ANY11MC(RGBToYMatrixRow_Any_LASX, RGBToYMatrixRow_LASX, 3, 31) +#endif +#ifdef HAS_ARGBTOYMATRIXROW_RVV +ANY11MC(ARGBToYMatrixRow_Any_RVV, ARGBToYMatrixRow_RVV, 4, 15) +#endif +#ifdef HAS_ARGBTOYMATRIXROW_WASMSIMD +ANY11MC(ARGBToYMatrixRow_Any_WASMSIMD, ARGBToYMatrixRow_WASMSIMD, 4, 15) +#endif +#ifdef HAS_RGBTOYMATRIXROW_WASMSIMD +ANY11MC(RGBToYMatrixRow_Any_WASMSIMD, RGBToYMatrixRow_WASMSIMD, 3, 15) +#endif +#ifdef HAS_RGB565TOYMATRIXROW_WASMSIMD +ANY11MC(RGB565ToYMatrixRow_Any_WASMSIMD, RGB565ToYMatrixRow_WASMSIMD, 2, 15) +#endif +#ifdef HAS_ARGB1555TOYMATRIXROW_WASMSIMD +ANY11MC(ARGB1555ToYMatrixRow_Any_WASMSIMD, ARGB1555ToYMatrixRow_WASMSIMD, 2, 15) +#endif +#ifdef HAS_ARGB4444TOYMATRIXROW_WASMSIMD +ANY11MC(ARGB4444ToYMatrixRow_Any_WASMSIMD, ARGB4444ToYMatrixRow_WASMSIMD, 2, 15) +#endif +#undef ANY11MC + #ifdef HAS_YUY2TOUVROW_AVX2 ANY12S(YUY2ToUVRow_Any_AVX2, YUY2ToUVRow_AVX2, 1, 4, 31) ANY12S(UYVYToUVRow_Any_AVX2, UYVYToUVRow_AVX2, 1, 4, 31) @@ -1297,144 +2822,227 @@ ANY12S(UYVYToUVRow_Any_AVX2, UYVYToUVRow_AVX2, 1, 4, 31) ANY12S(YUY2ToUVRow_Any_SSE2, YUY2ToUVRow_SSE2, 1, 4, 15) ANY12S(UYVYToUVRow_Any_SSE2, UYVYToUVRow_SSE2, 1, 4, 15) #endif -#ifdef HAS_ARGBTOUVROW_NEON -ANY12S(ARGBToUVRow_Any_NEON, ARGBToUVRow_NEON, 0, 4, 15) -#endif -#ifdef HAS_ARGBTOUVROW_MSA -ANY12S(ARGBToUVRow_Any_MSA, ARGBToUVRow_MSA, 0, 4, 31) -#endif -#ifdef HAS_ARGBTOUVROW_MMI -ANY12S(ARGBToUVRow_Any_MMI, ARGBToUVRow_MMI, 0, 4, 15) -#endif -#ifdef HAS_ARGBTOUVJROW_NEON -ANY12S(ARGBToUVJRow_Any_NEON, ARGBToUVJRow_NEON, 0, 4, 15) -#endif -#ifdef HAS_ARGBTOUVJROW_MSA -ANY12S(ARGBToUVJRow_Any_MSA, ARGBToUVJRow_MSA, 0, 4, 31) -#endif -#ifdef HAS_ARGBTOUVJROW_MMI -ANY12S(ARGBToUVJRow_Any_MMI, ARGBToUVJRow_MMI, 0, 4, 15) -#endif -#ifdef HAS_BGRATOUVROW_NEON -ANY12S(BGRAToUVRow_Any_NEON, BGRAToUVRow_NEON, 0, 4, 15) -#endif -#ifdef HAS_BGRATOUVROW_MSA -ANY12S(BGRAToUVRow_Any_MSA, BGRAToUVRow_MSA, 0, 4, 31) -#endif -#ifdef HAS_BGRATOUVROW_MMI -ANY12S(BGRAToUVRow_Any_MMI, BGRAToUVRow_MMI, 0, 4, 15) -#endif -#ifdef HAS_ABGRTOUVROW_NEON -ANY12S(ABGRToUVRow_Any_NEON, ABGRToUVRow_NEON, 0, 4, 15) -#endif -#ifdef HAS_ABGRTOUVROW_MSA -ANY12S(ABGRToUVRow_Any_MSA, ABGRToUVRow_MSA, 0, 4, 31) -#endif -#ifdef HAS_ABGRTOUVROW_MMI -ANY12S(ABGRToUVRow_Any_MMI, ABGRToUVRow_MMI, 0, 4, 15) -#endif -#ifdef HAS_RGBATOUVROW_NEON -ANY12S(RGBAToUVRow_Any_NEON, RGBAToUVRow_NEON, 0, 4, 15) -#endif -#ifdef HAS_RGBATOUVROW_MSA -ANY12S(RGBAToUVRow_Any_MSA, RGBAToUVRow_MSA, 0, 4, 31) -#endif -#ifdef HAS_RGBATOUVROW_MMI -ANY12S(RGBAToUVRow_Any_MMI, RGBAToUVRow_MMI, 0, 4, 15) -#endif + #ifdef HAS_RGB24TOUVROW_NEON ANY12S(RGB24ToUVRow_Any_NEON, RGB24ToUVRow_NEON, 0, 3, 15) #endif -#ifdef HAS_RGB24TOUVROW_MSA -ANY12S(RGB24ToUVRow_Any_MSA, RGB24ToUVRow_MSA, 0, 3, 15) +#ifdef HAS_RGB24TOUVROW_LSX +ANY12S(RGB24ToUVRow_Any_LSX, RGB24ToUVRow_LSX, 0, 3, 15) #endif -#ifdef HAS_RGB24TOUVROW_MMI -ANY12S(RGB24ToUVRow_Any_MMI, RGB24ToUVRow_MMI, 0, 3, 15) +#ifdef HAS_RGB24TOUVROW_LASX +ANY12S(RGB24ToUVRow_Any_LASX, RGB24ToUVRow_LASX, 0, 3, 31) #endif #ifdef HAS_RAWTOUVROW_NEON ANY12S(RAWToUVRow_Any_NEON, RAWToUVRow_NEON, 0, 3, 15) #endif -#ifdef HAS_RAWTOUVROW_MSA -ANY12S(RAWToUVRow_Any_MSA, RAWToUVRow_MSA, 0, 3, 15) +#ifdef HAS_RAWTOUVROW_LSX +ANY12S(RAWToUVRow_Any_LSX, RAWToUVRow_LSX, 0, 3, 15) #endif -#ifdef HAS_RAWTOUVROW_MMI -ANY12S(RAWToUVRow_Any_MMI, RAWToUVRow_MMI, 0, 3, 15) +#ifdef HAS_RAWTOUVROW_LASX +ANY12S(RAWToUVRow_Any_LASX, RAWToUVRow_LASX, 0, 3, 31) +#endif +#ifdef HAS_RGB565TOUVROW_AVX2 +ANY12S(RGB565ToUVRow_Any_AVX2, RGB565ToUVRow_AVX2, 0, 2, 31) +#endif +#ifdef HAS_ARGB1555TOUVROW_AVX2 +ANY12S(ARGB1555ToUVRow_Any_AVX2, ARGB1555ToUVRow_AVX2, 0, 2, 31) +#endif +#ifdef HAS_ARGB4444TOUVROW_AVX2 +ANY12S(ARGB4444ToUVRow_Any_AVX2, ARGB4444ToUVRow_AVX2, 0, 2, 31) #endif #ifdef HAS_RGB565TOUVROW_NEON ANY12S(RGB565ToUVRow_Any_NEON, RGB565ToUVRow_NEON, 0, 2, 15) #endif -#ifdef HAS_RGB565TOUVROW_MSA -ANY12S(RGB565ToUVRow_Any_MSA, RGB565ToUVRow_MSA, 0, 2, 15) +#ifdef HAS_RGB565TOUVROW_LSX +ANY12S(RGB565ToUVRow_Any_LSX, RGB565ToUVRow_LSX, 0, 2, 15) #endif -#ifdef HAS_RGB565TOUVROW_MMI -ANY12S(RGB565ToUVRow_Any_MMI, RGB565ToUVRow_MMI, 0, 2, 15) +#ifdef HAS_RGB565TOUVROW_LASX +ANY12S(RGB565ToUVRow_Any_LASX, RGB565ToUVRow_LASX, 0, 2, 31) #endif #ifdef HAS_ARGB1555TOUVROW_NEON ANY12S(ARGB1555ToUVRow_Any_NEON, ARGB1555ToUVRow_NEON, 0, 2, 15) #endif -#ifdef HAS_ARGB1555TOUVROW_MSA -ANY12S(ARGB1555ToUVRow_Any_MSA, ARGB1555ToUVRow_MSA, 0, 2, 15) +#ifdef HAS_ARGB1555TOUVROW_LSX +ANY12S(ARGB1555ToUVRow_Any_LSX, ARGB1555ToUVRow_LSX, 0, 2, 15) #endif -#ifdef HAS_ARGB1555TOUVROW_MMI -ANY12S(ARGB1555ToUVRow_Any_MMI, ARGB1555ToUVRow_MMI, 0, 2, 15) +#ifdef HAS_ARGB1555TOUVROW_LASX +ANY12S(ARGB1555ToUVRow_Any_LASX, ARGB1555ToUVRow_LASX, 0, 2, 31) #endif #ifdef HAS_ARGB4444TOUVROW_NEON ANY12S(ARGB4444ToUVRow_Any_NEON, ARGB4444ToUVRow_NEON, 0, 2, 15) #endif -#ifdef HAS_ARGB4444TOUVROW_MMI -ANY12S(ARGB4444ToUVRow_Any_MMI, ARGB4444ToUVRow_MMI, 0, 2, 15) -#endif #ifdef HAS_YUY2TOUVROW_NEON ANY12S(YUY2ToUVRow_Any_NEON, YUY2ToUVRow_NEON, 1, 4, 15) #endif #ifdef HAS_UYVYTOUVROW_NEON ANY12S(UYVYToUVRow_Any_NEON, UYVYToUVRow_NEON, 1, 4, 15) #endif -#ifdef HAS_YUY2TOUVROW_MSA -ANY12S(YUY2ToUVRow_Any_MSA, YUY2ToUVRow_MSA, 1, 4, 31) +#ifdef HAS_YUY2TOUVROW_LSX +ANY12S(YUY2ToUVRow_Any_LSX, YUY2ToUVRow_LSX, 1, 4, 15) #endif -#ifdef HAS_YUY2TOUVROW_MMI -ANY12S(YUY2ToUVRow_Any_MMI, YUY2ToUVRow_MMI, 1, 4, 15) +#ifdef HAS_YUY2TOUVROW_LASX +ANY12S(YUY2ToUVRow_Any_LASX, YUY2ToUVRow_LASX, 1, 4, 31) #endif -#ifdef HAS_UYVYTOUVROW_MSA -ANY12S(UYVYToUVRow_Any_MSA, UYVYToUVRow_MSA, 1, 4, 31) +#ifdef HAS_UYVYTOUVROW_LSX +ANY12S(UYVYToUVRow_Any_LSX, UYVYToUVRow_LSX, 1, 4, 15) #endif -#ifdef HAS_UYVYTOUVROW_MMI -ANY12S(UYVYToUVRow_Any_MMI, UYVYToUVRow_MMI, 1, 4, 15) +#ifdef HAS_UYVYTOUVROW_LASX +ANY12S(UYVYToUVRow_Any_LASX, UYVYToUVRow_LASX, 1, 4, 31) #endif #undef ANY12S // Any 1 to 1 with source stride (2 rows of source). Outputs UV plane. // 128 byte row allows for 32 avx ARGB pixels. #define ANY11S(NAMEANY, ANY_SIMD, UVSHIFT, BPP, MASK) \ - void NAMEANY(const uint8_t* src_ptr, int src_stride_ptr, uint8_t* dst_vu, \ + void NAMEANY(const uint8_t* src_ptr, int src_stride, uint8_t* dst_vu, \ int width) { \ - SIMD_ALIGNED(uint8_t temp[128 * 3]); \ - memset(temp, 0, 128 * 2); /* for msan */ \ + SIMD_ALIGNED(uint8_t vin[128 * 2]); \ + static_assert(SS(MASK + 1, UVSHIFT) * BPP <= sizeof(vin) / 2, \ + "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[128]); \ + static_assert(SS(MASK + 1, 1) * 2 <= sizeof(vout), \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ int r = width & MASK; \ int n = width & ~MASK; \ if (n > 0) { \ - ANY_SIMD(src_ptr, src_stride_ptr, dst_vu, n); \ + ANY_SIMD(src_ptr, src_stride, dst_vu, n); \ } \ - memcpy(temp, src_ptr + (n >> UVSHIFT) * BPP, SS(r, UVSHIFT) * BPP); \ - memcpy(temp + 128, src_ptr + src_stride_ptr + (n >> UVSHIFT) * BPP, \ + ptrdiff_t np = n; \ + memcpy(vin, src_ptr + (np >> UVSHIFT) * BPP, SS(r, UVSHIFT) * BPP); \ + memcpy(vin + 128, src_ptr + src_stride + (np >> UVSHIFT) * BPP, \ SS(r, UVSHIFT) * BPP); \ if ((width & 1) && UVSHIFT == 0) { /* repeat last pixel for subsample */ \ - memcpy(temp + SS(r, UVSHIFT) * BPP, temp + SS(r, UVSHIFT) * BPP - BPP, \ + memcpy(vin + SS(r, UVSHIFT) * BPP, vin + SS(r, UVSHIFT) * BPP - BPP, \ BPP); \ - memcpy(temp + 128 + SS(r, UVSHIFT) * BPP, \ - temp + 128 + SS(r, UVSHIFT) * BPP - BPP, BPP); \ + memcpy(vin + 128 + SS(r, UVSHIFT) * BPP, \ + vin + 128 + SS(r, UVSHIFT) * BPP - BPP, BPP); \ } \ - ANY_SIMD(temp, 128, temp + 256, MASK + 1); \ - memcpy(dst_vu + (n >> 1) * 2, temp + 256, SS(r, 1) * 2); \ + ANY_SIMD(vin, 128, vout, MASK + 1); \ + memcpy(dst_vu + (np >> 1) * 2, vout, SS(r, 1) * 2); \ } +#ifdef HAS_AYUVTOUVROW_AVX2 +ANY11S(AYUVToUVRow_Any_AVX2, AYUVToUVRow_AVX2, 0, 4, 15) +#endif +#ifdef HAS_AYUVTOVUROW_AVX2 +ANY11S(AYUVToVURow_Any_AVX2, AYUVToVURow_AVX2, 0, 4, 15) +#endif #ifdef HAS_AYUVTOVUROW_NEON ANY11S(AYUVToUVRow_Any_NEON, AYUVToUVRow_NEON, 0, 4, 15) ANY11S(AYUVToVURow_Any_NEON, AYUVToVURow_NEON, 0, 4, 15) #endif +#ifdef HAS_AYUVTOUVROW_SVE2 +ANY11S(AYUVToUVRow_Any_SVE2, AYUVToUVRow_SVE2, 0, 4, 1) +#endif +#ifdef HAS_AYUVTOVUROW_SVE2 +ANY11S(AYUVToVURow_Any_SVE2, AYUVToVURow_SVE2, 0, 4, 1) +#endif #undef ANY11S +#define ANYDETILE(NAMEANY, ANY_SIMD, T, BPP, MASK) \ + void NAMEANY(const T* src, ptrdiff_t src_tile_stride, T* dst, int width) { \ + SIMD_ALIGNED(T vin[16]); \ + static_assert((MASK + 1) * BPP <= sizeof(vin), "vin buffer too small"); \ + SIMD_ALIGNED(T vout[16]); \ + static_assert((MASK + 1) * BPP <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src, src_tile_stride, dst, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src + (np / 16) * src_tile_stride, r * BPP); \ + ANY_SIMD(vin, src_tile_stride, vout, MASK + 1); \ + memcpy(dst + np, vout, r * BPP); \ + } + +#ifdef HAS_DETILEROW_NEON +ANYDETILE(DetileRow_Any_NEON, DetileRow_NEON, uint8_t, 1, 15) +#endif +#ifdef HAS_DETILEROW_AVX2 +ANYDETILE(DetileRow_Any_AVX2, DetileRow_AVX2, uint8_t, 1, 15) +#endif +#ifdef HAS_DETILEROW_16_NEON +ANYDETILE(DetileRow_16_Any_NEON, DetileRow_16_NEON, uint16_t, 2, 15) +#endif +#ifdef HAS_DETILEROW_16_AVX2 +ANYDETILE(DetileRow_16_Any_AVX2, DetileRow_16_AVX2, uint16_t, 2, 15) +#endif + +// DetileSplitUVRow width is in bytes +#define ANYDETILESPLITUV(NAMEANY, ANY_SIMD, MASK) \ + void NAMEANY(const uint8_t* src_uv, ptrdiff_t src_tile_stride, \ + uint8_t* dst_u, uint8_t* dst_v, int width) { \ + SIMD_ALIGNED(uint8_t vin[16]); \ + static_assert(MASK + 1 <= sizeof(vin), "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[8 * 2]); \ + static_assert((MASK + 1) / 2 <= sizeof(vout) / 2, \ + "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_uv, src_tile_stride, dst_u, dst_v, n); \ + } \ + ptrdiff_t np = n; \ + memcpy(vin, src_uv + (np / 16) * src_tile_stride, r); \ + ANY_SIMD(vin, src_tile_stride, vout, vout + 8, r); \ + memcpy(dst_u + np / 2, vout, (r + 1) / 2); \ + memcpy(dst_v + np / 2, vout + 8, (r + 1) / 2); \ + } + +#ifdef HAS_DETILESPLITUVROW_NEON +ANYDETILESPLITUV(DetileSplitUVRow_Any_NEON, DetileSplitUVRow_NEON, 15) +#endif +#ifdef HAS_DETILESPLITUVROW_AVX2 +ANYDETILESPLITUV(DetileSplitUVRow_Any_AVX2, DetileSplitUVRow_AVX2, 15) +#endif + +#define ANYDETILEMERGE(NAMEANY, ANY_SIMD, MASK) \ + void NAMEANY(const uint8_t* src_y, ptrdiff_t src_y_tile_stride, \ + const uint8_t* src_uv, ptrdiff_t src_uv_tile_stride, \ + uint8_t* dst_yuy2, int width) { \ + SIMD_ALIGNED(uint8_t vin[32 * 2]); \ + static_assert(MASK + 1 <= sizeof(vin) / 2, "vin buffer too small"); \ + SIMD_ALIGNED(uint8_t vout[32 * 2]); \ + static_assert(2 * (MASK + 1) <= sizeof(vout), "vout buffer too small"); \ + MSAN_MEMSET(vin, 0, sizeof(vin)); /* for msan */ \ + MSAN_MEMSET(vout, 0, sizeof(vout)); /* for msan */ \ + int r = width & MASK; \ + int n = width & ~MASK; \ + if (n > 0) { \ + ANY_SIMD(src_y, src_y_tile_stride, src_uv, src_uv_tile_stride, dst_yuy2, \ + n); \ + } \ + ptrdiff_t np = n; \ + int r0 = (r < 16) ? r : 16; \ + memcpy(vin, src_y + (np / 16) * src_y_tile_stride, r0); \ + memcpy(vin + 32, src_uv + (np / 16) * src_uv_tile_stride, r0); \ + if (r > 16) { \ + memcpy(vin + 16, src_y + (np / 16 + 1) * src_y_tile_stride, r - 16); \ + memcpy(vin + 48, src_uv + (np / 16 + 1) * src_uv_tile_stride, r - 16); \ + } \ + ANY_SIMD(vin, 16, vin + 32, 16, vout, MASK + 1); \ + memcpy(dst_yuy2 + 2 * np, vout, 2 * r); \ + } + +#ifdef HAS_DETILETOYUY2_NEON +ANYDETILEMERGE(DetileToYUY2_Any_NEON, DetileToYUY2_NEON, 15) +#endif + +#ifdef HAS_DETILETOYUY2_AVX2 +ANYDETILEMERGE(DetileToYUY2_Any_AVX2, DetileToYUY2_AVX2, 31) +#endif + +#undef ANYDETILEMERGE + +#undef MSAN_MEMSET + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/source/row_common.cc b/libs/libyuv/source/row_common.cc index 9fa6e34ce5..48eda2282d 100644 --- a/libs/libyuv/source/row_common.cc +++ b/libs/libyuv/source/row_common.cc @@ -10,34 +10,55 @@ #include "libyuv/row.h" -#include +#include #include // For memcpy and memset. -#include "libyuv/basic_types.h" +#include "libyuv/convert_argb.h" // For kYuvI601Constants +#include "libyuv/convert_from_argb.h" // For ArgbConstants #ifdef __cplusplus namespace libyuv { extern "C" { #endif +#ifdef __cplusplus +#define STATIC_CAST(type, expr) static_cast(expr) +#else +#define STATIC_CAST(type, expr) (type)(expr) +#endif + +// This macro controls YUV to RGB using unsigned math to extend range of +// YUV to RGB coefficients to 0 to 4 instead of 0 to 2 for more accuracy on B: +// LIBYUV_UNLIMITED_DATA + +// Macros to enable unlimited data for each colorspace +// LIBYUV_UNLIMITED_BT601 +// LIBYUV_UNLIMITED_BT709 +// LIBYUV_UNLIMITED_BT2020 + // llvm x86 is poor at ternary operator, so use branchless min/max. #define USE_BRANCHLESS 1 -#if USE_BRANCHLESS +#if defined(USE_BRANCHLESS) static __inline int32_t clamp0(int32_t v) { - return ((-(v) >> 31) & (v)); + return -(v >= 0) & v; } - +// TODO(fbarchard): make clamp255 preserve negative values. static __inline int32_t clamp255(int32_t v) { - return (((255 - (v)) >> 31) | (v)) & 255; + return (-(v >= 255) | v) & 255; } static __inline int32_t clamp1023(int32_t v) { - return (((1023 - (v)) >> 31) | (v)) & 1023; + return (-(v >= 1023) | v) & 1023; +} + +// clamp to max +static __inline int32_t ClampMax(int32_t v, int32_t max) { + return (-(v >= max) | v) & max; } static __inline uint32_t Abs(int32_t v) { - int m = v >> 31; + int m = -(v < 0); return (v + m) ^ m; } #else // USE_BRANCHLESS @@ -53,6 +74,10 @@ static __inline int32_t clamp1023(int32_t v) { return (v > 1023) ? 1023 : v; } +static __inline int32_t ClampMax(int32_t v, int32_t max) { + return (v > max) ? max : v; +} + static __inline uint32_t Abs(int32_t v) { return (v < 0) ? -v : v; } @@ -71,7 +96,9 @@ static __inline uint32_t Clamp10(int32_t val) { #if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \ defined(_M_IX86) || defined(__arm__) || defined(_M_ARM) || \ (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) -#define WRITEWORD(p, v) *(uint32_t*)(p) = v +static inline void WRITEWORD(uint8_t* p, uint32_t v) { + memcpy(p, &v, 4); +} #else static inline void WRITEWORD(uint8_t* p, uint32_t v) { p[0] = (uint8_t)(v & 255); @@ -111,6 +138,21 @@ void RAWToARGBRow_C(const uint8_t* src_raw, uint8_t* dst_argb, int width) { } } +void RAWToRGBARow_C(const uint8_t* src_raw, uint8_t* dst_rgba, int width) { + int x; + for (x = 0; x < width; ++x) { + uint8_t r = src_raw[0]; + uint8_t g = src_raw[1]; + uint8_t b = src_raw[2]; + dst_rgba[0] = 255u; + dst_rgba[1] = b; + dst_rgba[2] = g; + dst_rgba[3] = r; + dst_rgba += 4; + src_raw += 3; + } +} + void RAWToRGB24Row_C(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { int x; for (x = 0; x < width; ++x) { @@ -130,12 +172,13 @@ void RGB565ToARGBRow_C(const uint8_t* src_rgb565, int width) { int x; for (x = 0; x < width; ++x) { - uint8_t b = src_rgb565[0] & 0x1f; - uint8_t g = (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3); - uint8_t r = src_rgb565[1] >> 3; - dst_argb[0] = (b << 3) | (b >> 2); - dst_argb[1] = (g << 2) | (g >> 4); - dst_argb[2] = (r << 3) | (r >> 2); + uint8_t b = STATIC_CAST(uint8_t, src_rgb565[0] & 0x1f); + uint8_t g = STATIC_CAST( + uint8_t, (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3)); + uint8_t r = STATIC_CAST(uint8_t, src_rgb565[1] >> 3); + dst_argb[0] = STATIC_CAST(uint8_t, (b << 3) | (b >> 2)); + dst_argb[1] = STATIC_CAST(uint8_t, (g << 2) | (g >> 4)); + dst_argb[2] = STATIC_CAST(uint8_t, (r << 3) | (r >> 2)); dst_argb[3] = 255u; dst_argb += 4; src_rgb565 += 2; @@ -147,13 +190,14 @@ void ARGB1555ToARGBRow_C(const uint8_t* src_argb1555, int width) { int x; for (x = 0; x < width; ++x) { - uint8_t b = src_argb1555[0] & 0x1f; - uint8_t g = (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3); - uint8_t r = (src_argb1555[1] & 0x7c) >> 2; - uint8_t a = src_argb1555[1] >> 7; - dst_argb[0] = (b << 3) | (b >> 2); - dst_argb[1] = (g << 3) | (g >> 2); - dst_argb[2] = (r << 3) | (r >> 2); + uint8_t b = STATIC_CAST(uint8_t, src_argb1555[0] & 0x1f); + uint8_t g = STATIC_CAST( + uint8_t, (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3)); + uint8_t r = STATIC_CAST(uint8_t, (src_argb1555[1] & 0x7c) >> 2); + uint8_t a = STATIC_CAST(uint8_t, src_argb1555[1] >> 7); + dst_argb[0] = STATIC_CAST(uint8_t, (b << 3) | (b >> 2)); + dst_argb[1] = STATIC_CAST(uint8_t, (g << 3) | (g >> 2)); + dst_argb[2] = STATIC_CAST(uint8_t, (r << 3) | (r >> 2)); dst_argb[3] = -a; dst_argb += 4; src_argb1555 += 2; @@ -165,14 +209,14 @@ void ARGB4444ToARGBRow_C(const uint8_t* src_argb4444, int width) { int x; for (x = 0; x < width; ++x) { - uint8_t b = src_argb4444[0] & 0x0f; - uint8_t g = src_argb4444[0] >> 4; - uint8_t r = src_argb4444[1] & 0x0f; - uint8_t a = src_argb4444[1] >> 4; - dst_argb[0] = (b << 4) | b; - dst_argb[1] = (g << 4) | g; - dst_argb[2] = (r << 4) | r; - dst_argb[3] = (a << 4) | a; + uint8_t b = STATIC_CAST(uint8_t, src_argb4444[0] & 0x0f); + uint8_t g = STATIC_CAST(uint8_t, src_argb4444[0] >> 4); + uint8_t r = STATIC_CAST(uint8_t, src_argb4444[1] & 0x0f); + uint8_t a = STATIC_CAST(uint8_t, src_argb4444[1] >> 4); + dst_argb[0] = STATIC_CAST(uint8_t, (b << 4) | b); + dst_argb[1] = STATIC_CAST(uint8_t, (g << 4) | g); + dst_argb[2] = STATIC_CAST(uint8_t, (r << 4) | r); + dst_argb[3] = STATIC_CAST(uint8_t, (a << 4) | a); dst_argb += 4; src_argb4444 += 2; } @@ -181,7 +225,8 @@ void ARGB4444ToARGBRow_C(const uint8_t* src_argb4444, void AR30ToARGBRow_C(const uint8_t* src_ar30, uint8_t* dst_argb, int width) { int x; for (x = 0; x < width; ++x) { - uint32_t ar30 = *(const uint32_t*)src_ar30; + uint32_t ar30; + memcpy(&ar30, src_ar30, sizeof ar30); uint32_t b = (ar30 >> 2) & 0xff; uint32_t g = (ar30 >> 12) & 0xff; uint32_t r = (ar30 >> 22) & 0xff; @@ -195,7 +240,8 @@ void AR30ToARGBRow_C(const uint8_t* src_ar30, uint8_t* dst_argb, int width) { void AR30ToABGRRow_C(const uint8_t* src_ar30, uint8_t* dst_abgr, int width) { int x; for (x = 0; x < width; ++x) { - uint32_t ar30 = *(const uint32_t*)src_ar30; + uint32_t ar30; + memcpy(&ar30, src_ar30, sizeof ar30); uint32_t b = (ar30 >> 2) & 0xff; uint32_t g = (ar30 >> 12) & 0xff; uint32_t r = (ar30 >> 22) & 0xff; @@ -209,7 +255,8 @@ void AR30ToABGRRow_C(const uint8_t* src_ar30, uint8_t* dst_abgr, int width) { void AR30ToAB30Row_C(const uint8_t* src_ar30, uint8_t* dst_ab30, int width) { int x; for (x = 0; x < width; ++x) { - uint32_t ar30 = *(const uint32_t*)src_ar30; + uint32_t ar30; + memcpy(&ar30, src_ar30, sizeof ar30); uint32_t b = ar30 & 0x3ff; uint32_t ga = ar30 & 0xc00ffc00; uint32_t r = (ar30 >> 20) & 0x3ff; @@ -219,6 +266,54 @@ void AR30ToAB30Row_C(const uint8_t* src_ar30, uint8_t* dst_ab30, int width) { } } +void ARGBToABGRRow_C(const uint8_t* src_argb, uint8_t* dst_abgr, int width) { + int x; + for (x = 0; x < width; ++x) { + uint8_t b = src_argb[0]; + uint8_t g = src_argb[1]; + uint8_t r = src_argb[2]; + uint8_t a = src_argb[3]; + dst_abgr[0] = r; + dst_abgr[1] = g; + dst_abgr[2] = b; + dst_abgr[3] = a; + dst_abgr += 4; + src_argb += 4; + } +} + +void ARGBToBGRARow_C(const uint8_t* src_argb, uint8_t* dst_bgra, int width) { + int x; + for (x = 0; x < width; ++x) { + uint8_t b = src_argb[0]; + uint8_t g = src_argb[1]; + uint8_t r = src_argb[2]; + uint8_t a = src_argb[3]; + dst_bgra[0] = a; + dst_bgra[1] = r; + dst_bgra[2] = g; + dst_bgra[3] = b; + dst_bgra += 4; + src_argb += 4; + } +} + +void ARGBToRGBARow_C(const uint8_t* src_argb, uint8_t* dst_rgba, int width) { + int x; + for (x = 0; x < width; ++x) { + uint8_t b = src_argb[0]; + uint8_t g = src_argb[1]; + uint8_t r = src_argb[2]; + uint8_t a = src_argb[3]; + dst_rgba[0] = a; + dst_rgba[1] = b; + dst_rgba[2] = g; + dst_rgba[3] = r; + dst_rgba += 4; + src_argb += 4; + } +} + void ARGBToRGB24Row_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { int x; for (x = 0; x < width; ++x) { @@ -247,6 +342,22 @@ void ARGBToRAWRow_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { } } +void RGBAToARGBRow_C(const uint8_t* src_rgba, uint8_t* dst_argb, int width) { + int x; + for (x = 0; x < width; ++x) { + uint8_t a = src_rgba[0]; + uint8_t b = src_rgba[1]; + uint8_t g = src_rgba[2]; + uint8_t r = src_rgba[3]; + dst_argb[0] = b; + dst_argb[1] = g; + dst_argb[2] = r; + dst_argb[3] = a; + dst_argb += 4; + src_rgba += 4; + } +} + void ARGBToRGB565Row_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { int x; for (x = 0; x < width - 1; x += 2) { @@ -265,7 +376,7 @@ void ARGBToRGB565Row_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { uint8_t b0 = src_argb[0] >> 3; uint8_t g0 = src_argb[1] >> 2; uint8_t r0 = src_argb[2] >> 3; - *(uint16_t*)(dst_rgb) = b0 | (g0 << 5) | (r0 << 11); + *(uint16_t*)(dst_rgb) = STATIC_CAST(uint16_t, b0 | (g0 << 5) | (r0 << 11)); } } @@ -279,29 +390,31 @@ void ARGBToRGB565Row_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { // or the upper byte for big endian. void ARGBToRGB565DitherRow_C(const uint8_t* src_argb, uint8_t* dst_rgb, - const uint32_t dither4, + uint32_t dither4, int width) { int x; for (x = 0; x < width - 1; x += 2) { int dither0 = ((const unsigned char*)(&dither4))[x & 3]; int dither1 = ((const unsigned char*)(&dither4))[(x + 1) & 3]; - uint8_t b0 = clamp255(src_argb[0] + dither0) >> 3; - uint8_t g0 = clamp255(src_argb[1] + dither0) >> 2; - uint8_t r0 = clamp255(src_argb[2] + dither0) >> 3; - uint8_t b1 = clamp255(src_argb[4] + dither1) >> 3; - uint8_t g1 = clamp255(src_argb[5] + dither1) >> 2; - uint8_t r1 = clamp255(src_argb[6] + dither1) >> 3; - WRITEWORD(dst_rgb, b0 | (g0 << 5) | (r0 << 11) | (b1 << 16) | (g1 << 21) | - (r1 << 27)); + uint8_t b0 = STATIC_CAST(uint8_t, clamp255(src_argb[0] + dither0) >> 3); + uint8_t g0 = STATIC_CAST(uint8_t, clamp255(src_argb[1] + dither0) >> 2); + uint8_t r0 = STATIC_CAST(uint8_t, clamp255(src_argb[2] + dither0) >> 3); + uint8_t b1 = STATIC_CAST(uint8_t, clamp255(src_argb[4] + dither1) >> 3); + uint8_t g1 = STATIC_CAST(uint8_t, clamp255(src_argb[5] + dither1) >> 2); + uint8_t r1 = STATIC_CAST(uint8_t, clamp255(src_argb[6] + dither1) >> 3); + *(uint16_t*)(dst_rgb + 0) = + STATIC_CAST(uint16_t, b0 | (g0 << 5) | (r0 << 11)); + *(uint16_t*)(dst_rgb + 2) = + STATIC_CAST(uint16_t, b1 | (g1 << 5) | (r1 << 11)); dst_rgb += 4; src_argb += 8; } if (width & 1) { int dither0 = ((const unsigned char*)(&dither4))[(width - 1) & 3]; - uint8_t b0 = clamp255(src_argb[0] + dither0) >> 3; - uint8_t g0 = clamp255(src_argb[1] + dither0) >> 2; - uint8_t r0 = clamp255(src_argb[2] + dither0) >> 3; - *(uint16_t*)(dst_rgb) = b0 | (g0 << 5) | (r0 << 11); + uint8_t b0 = STATIC_CAST(uint8_t, clamp255(src_argb[0] + dither0) >> 3); + uint8_t g0 = STATIC_CAST(uint8_t, clamp255(src_argb[1] + dither0) >> 2); + uint8_t r0 = STATIC_CAST(uint8_t, clamp255(src_argb[2] + dither0) >> 3); + *(uint16_t*)(dst_rgb) = STATIC_CAST(uint16_t, b0 | (g0 << 5) | (r0 << 11)); } } @@ -316,8 +429,10 @@ void ARGBToARGB1555Row_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { uint8_t g1 = src_argb[5] >> 3; uint8_t r1 = src_argb[6] >> 3; uint8_t a1 = src_argb[7] >> 7; - *(uint32_t*)(dst_rgb) = b0 | (g0 << 5) | (r0 << 10) | (a0 << 15) | - (b1 << 16) | (g1 << 21) | (r1 << 26) | (a1 << 31); + *(uint16_t*)(dst_rgb + 0) = + STATIC_CAST(uint16_t, b0 | (g0 << 5) | (r0 << 10) | (a0 << 15)); + *(uint16_t*)(dst_rgb + 2) = + STATIC_CAST(uint16_t, b1 | (g1 << 5) | (r1 << 10) | (a1 << 15)); dst_rgb += 4; src_argb += 8; } @@ -326,7 +441,8 @@ void ARGBToARGB1555Row_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { uint8_t g0 = src_argb[1] >> 3; uint8_t r0 = src_argb[2] >> 3; uint8_t a0 = src_argb[3] >> 7; - *(uint16_t*)(dst_rgb) = b0 | (g0 << 5) | (r0 << 10) | (a0 << 15); + *(uint16_t*)(dst_rgb) = + STATIC_CAST(uint16_t, b0 | (g0 << 5) | (r0 << 10) | (a0 << 15)); } } @@ -341,8 +457,10 @@ void ARGBToARGB4444Row_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { uint8_t g1 = src_argb[5] >> 4; uint8_t r1 = src_argb[6] >> 4; uint8_t a1 = src_argb[7] >> 4; - *(uint32_t*)(dst_rgb) = b0 | (g0 << 4) | (r0 << 8) | (a0 << 12) | - (b1 << 16) | (g1 << 20) | (r1 << 24) | (a1 << 28); + *(uint16_t*)(dst_rgb + 0) = + STATIC_CAST(uint16_t, b0 | (g0 << 4) | (r0 << 8) | (a0 << 12)); + *(uint16_t*)(dst_rgb + 2) = + STATIC_CAST(uint16_t, b1 | (g1 << 4) | (r1 << 8) | (a1 << 12)); dst_rgb += 4; src_argb += 8; } @@ -351,18 +469,20 @@ void ARGBToARGB4444Row_C(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { uint8_t g0 = src_argb[1] >> 4; uint8_t r0 = src_argb[2] >> 4; uint8_t a0 = src_argb[3] >> 4; - *(uint16_t*)(dst_rgb) = b0 | (g0 << 4) | (r0 << 8) | (a0 << 12); + *(uint16_t*)(dst_rgb) = + STATIC_CAST(uint16_t, b0 | (g0 << 4) | (r0 << 8) | (a0 << 12)); } } void ABGRToAR30Row_C(const uint8_t* src_abgr, uint8_t* dst_ar30, int width) { int x; for (x = 0; x < width; ++x) { - uint32_t b0 = (src_abgr[0] >> 6) | ((uint32_t)(src_abgr[0]) << 2); + uint32_t r0 = (src_abgr[0] >> 6) | ((uint32_t)(src_abgr[0]) << 2); uint32_t g0 = (src_abgr[1] >> 6) | ((uint32_t)(src_abgr[1]) << 2); - uint32_t r0 = (src_abgr[2] >> 6) | ((uint32_t)(src_abgr[2]) << 2); + uint32_t b0 = (src_abgr[2] >> 6) | ((uint32_t)(src_abgr[2]) << 2); uint32_t a0 = (src_abgr[3] >> 6); - *(uint32_t*)(dst_ar30) = r0 | (g0 << 10) | (b0 << 20) | (a0 << 30); + *(uint32_t*)(dst_ar30) = + STATIC_CAST(uint32_t, b0 | (g0 << 10) | (r0 << 20) | (a0 << 30)); dst_ar30 += 4; src_abgr += 4; } @@ -375,158 +495,269 @@ void ARGBToAR30Row_C(const uint8_t* src_argb, uint8_t* dst_ar30, int width) { uint32_t g0 = (src_argb[1] >> 6) | ((uint32_t)(src_argb[1]) << 2); uint32_t r0 = (src_argb[2] >> 6) | ((uint32_t)(src_argb[2]) << 2); uint32_t a0 = (src_argb[3] >> 6); - *(uint32_t*)(dst_ar30) = b0 | (g0 << 10) | (r0 << 20) | (a0 << 30); + *(uint32_t*)(dst_ar30) = + STATIC_CAST(uint32_t, b0 | (g0 << 10) | (r0 << 20) | (a0 << 30)); dst_ar30 += 4; src_argb += 4; } } -static __inline int RGBToY(uint8_t r, uint8_t g, uint8_t b) { - return (66 * r + 129 * g + 25 * b + 0x1080) >> 8; -} - -static __inline int RGBToU(uint8_t r, uint8_t g, uint8_t b) { - return (112 * b - 74 * g - 38 * r + 0x8080) >> 8; -} -static __inline int RGBToV(uint8_t r, uint8_t g, uint8_t b) { - return (112 * r - 94 * g - 18 * b + 0x8080) >> 8; -} - -// ARGBToY_C and ARGBToUV_C -#define MAKEROWY(NAME, R, G, B, BPP) \ - void NAME##ToYRow_C(const uint8_t* src_argb0, uint8_t* dst_y, int width) { \ - int x; \ - for (x = 0; x < width; ++x) { \ - dst_y[0] = RGBToY(src_argb0[R], src_argb0[G], src_argb0[B]); \ - src_argb0 += BPP; \ - dst_y += 1; \ - } \ - } \ - void NAME##ToUVRow_C(const uint8_t* src_rgb0, int src_stride_rgb, \ - uint8_t* dst_u, uint8_t* dst_v, int width) { \ - const uint8_t* src_rgb1 = src_rgb0 + src_stride_rgb; \ - int x; \ - for (x = 0; x < width - 1; x += 2) { \ - uint8_t ab = (src_rgb0[B] + src_rgb0[B + BPP] + src_rgb1[B] + \ - src_rgb1[B + BPP]) >> \ - 2; \ - uint8_t ag = (src_rgb0[G] + src_rgb0[G + BPP] + src_rgb1[G] + \ - src_rgb1[G + BPP]) >> \ - 2; \ - uint8_t ar = (src_rgb0[R] + src_rgb0[R + BPP] + src_rgb1[R] + \ - src_rgb1[R + BPP]) >> \ - 2; \ - dst_u[0] = RGBToU(ar, ag, ab); \ - dst_v[0] = RGBToV(ar, ag, ab); \ - src_rgb0 += BPP * 2; \ - src_rgb1 += BPP * 2; \ - dst_u += 1; \ - dst_v += 1; \ - } \ - if (width & 1) { \ - uint8_t ab = (src_rgb0[B] + src_rgb1[B]) >> 1; \ - uint8_t ag = (src_rgb0[G] + src_rgb1[G]) >> 1; \ - uint8_t ar = (src_rgb0[R] + src_rgb1[R]) >> 1; \ - dst_u[0] = RGBToU(ar, ag, ab); \ - dst_v[0] = RGBToV(ar, ag, ab); \ - } \ +void ARGBToAR64Row_C(const uint8_t* src_argb, uint16_t* dst_ar64, int width) { + int x; + for (x = 0; x < width; ++x) { + uint16_t b = src_argb[0] * 0x0101; + uint16_t g = src_argb[1] * 0x0101; + uint16_t r = src_argb[2] * 0x0101; + uint16_t a = src_argb[3] * 0x0101; + dst_ar64[0] = b; + dst_ar64[1] = g; + dst_ar64[2] = r; + dst_ar64[3] = a; + dst_ar64 += 4; + src_argb += 4; } +} -MAKEROWY(ARGB, 2, 1, 0, 4) -MAKEROWY(BGRA, 1, 2, 3, 4) -MAKEROWY(ABGR, 0, 1, 2, 4) -MAKEROWY(RGBA, 3, 2, 1, 4) -MAKEROWY(RGB24, 2, 1, 0, 3) -MAKEROWY(RAW, 0, 1, 2, 3) -#undef MAKEROWY +void ARGBToAB64Row_C(const uint8_t* src_argb, uint16_t* dst_ab64, int width) { + int x; + for (x = 0; x < width; ++x) { + uint16_t b = src_argb[0] * 0x0101; + uint16_t g = src_argb[1] * 0x0101; + uint16_t r = src_argb[2] * 0x0101; + uint16_t a = src_argb[3] * 0x0101; + dst_ab64[0] = r; + dst_ab64[1] = g; + dst_ab64[2] = b; + dst_ab64[3] = a; + dst_ab64 += 4; + src_argb += 4; + } +} -// JPeg uses a variation on BT.601-1 full range +void AR64ToARGBRow_C(const uint16_t* src_ar64, uint8_t* dst_argb, int width) { + int x; + for (x = 0; x < width; ++x) { + uint8_t b = src_ar64[0] >> 8; + uint8_t g = src_ar64[1] >> 8; + uint8_t r = src_ar64[2] >> 8; + uint8_t a = src_ar64[3] >> 8; + dst_argb[0] = b; + dst_argb[1] = g; + dst_argb[2] = r; + dst_argb[3] = a; + dst_argb += 4; + src_ar64 += 4; + } +} + +void AB64ToARGBRow_C(const uint16_t* src_ab64, uint8_t* dst_argb, int width) { + int x; + for (x = 0; x < width; ++x) { + uint8_t r = src_ab64[0] >> 8; + uint8_t g = src_ab64[1] >> 8; + uint8_t b = src_ab64[2] >> 8; + uint8_t a = src_ab64[3] >> 8; + dst_argb[0] = b; + dst_argb[1] = g; + dst_argb[2] = r; + dst_argb[3] = a; + dst_argb += 4; + src_ab64 += 4; + } +} + +void AR64ToAB64Row_C(const uint16_t* src_ar64, uint16_t* dst_ab64, int width) { + int x; + for (x = 0; x < width; ++x) { + uint16_t b = src_ar64[0]; + uint16_t g = src_ar64[1]; + uint16_t r = src_ar64[2]; + uint16_t a = src_ar64[3]; + dst_ab64[0] = r; + dst_ab64[1] = g; + dst_ab64[2] = b; + dst_ab64[3] = a; + dst_ab64 += 4; + src_ar64 += 4; + } +} + +// TODO(fbarchard): Make shuffle compatible with SIMD versions +// width is in units of 32 bit ARGB pixels (2 per AR64 pixel) so that +// AR64Shuffle can share the ARGBShuffleRow SIMD kernels. +void AR64ShuffleRow_C(const uint8_t* src_ar64, + uint8_t* dst_ar64, + const uint8_t* shuffler, + int width) { + const uint16_t* src_ar64_16 = (const uint16_t*)src_ar64; + uint16_t* dst_ar64_16 = (uint16_t*)dst_ar64; + int index0 = shuffler[0] / 2; + int index1 = shuffler[2] / 2; + int index2 = shuffler[4] / 2; + int index3 = shuffler[6] / 2; + // Shuffle a row of AR64. + int x; + for (x = 0; x < width / 2; ++x) { + // To support in-place conversion. + uint16_t b = src_ar64_16[index0]; + uint16_t g = src_ar64_16[index1]; + uint16_t r = src_ar64_16[index2]; + uint16_t a = src_ar64_16[index3]; + dst_ar64_16[0] = b; + dst_ar64_16[1] = g; + dst_ar64_16[2] = r; + dst_ar64_16[3] = a; + src_ar64_16 += 4; + dst_ar64_16 += 4; + } +} +// BT601 8 bit Y: +// b 0.114 * 219 = 24.966 = 25 +// g 0.587 * 219 = 128.553 = 129 +// r 0.299 * 219 = 65.481 = 66 +// BT601 8 bit U: +// b 0.875 * 128 = 112.0 = 112 +// g -0.5781 * 128 = −73.9968 = -74 +// r -0.2969 * 128 = −38.0032 = -38 +// BT601 8 bit V: +// b -0.1406 * 128 = −17.9968 = -18 +// g -0.7344 * 128 = −94.0032 = -94 +// r 0.875 * 128 = 112.0 = 112 +static __inline uint8_t RGBToY(uint8_t r, uint8_t g, uint8_t b) { + return STATIC_CAST(uint8_t, (66 * r + 129 * g + 25 * b + 0x1080) >> 8); +} +static __inline uint8_t RGBToU(uint8_t r, uint8_t g, uint8_t b) { + return STATIC_CAST(uint8_t, (112 * b - 74 * g - 38 * r + 0x8000) >> 8); +} +static __inline uint8_t RGBToV(uint8_t r, uint8_t g, uint8_t b) { + return STATIC_CAST(uint8_t, (112 * r - 94 * g - 18 * b + 0x8000) >> 8); +} +#define AVGB(a, b) (((a) + (b) + 1) >> 1) + +// JPeg uses BT.601-1 full range // y = 0.29900 * r + 0.58700 * g + 0.11400 * b // u = -0.16874 * r - 0.33126 * g + 0.50000 * b + center // v = 0.50000 * r - 0.41869 * g - 0.08131 * b + center -// BT.601 Mpeg range uses: -// b 0.1016 * 255 = 25.908 = 25 -// g 0.5078 * 255 = 129.489 = 129 -// r 0.2578 * 255 = 65.739 = 66 -// JPeg 8 bit Y (not used): +// JPeg 8 bit Y: // b 0.11400 * 256 = 29.184 = 29 // g 0.58700 * 256 = 150.272 = 150 // r 0.29900 * 256 = 76.544 = 77 -// JPeg 7 bit Y: -// b 0.11400 * 128 = 14.592 = 15 -// g 0.58700 * 128 = 75.136 = 75 -// r 0.29900 * 128 = 38.272 = 38 // JPeg 8 bit U: -// b 0.50000 * 255 = 127.5 = 127 -// g -0.33126 * 255 = -84.4713 = -84 -// r -0.16874 * 255 = -43.0287 = -43 +// b 0.50000 * 256 = 128.0 = 128 +// g -0.33126 * 256 = −84.80256 = -85 +// r -0.16874 * 256 = −43.19744 = -43 // JPeg 8 bit V: -// b -0.08131 * 255 = -20.73405 = -20 -// g -0.41869 * 255 = -106.76595 = -107 -// r 0.50000 * 255 = 127.5 = 127 +// b -0.08131 * 256 = −20.81536 = -21 +// g -0.41869 * 256 = −107.18464 = -107 +// r 0.50000 * 256 = 128.0 = 128 -static __inline int RGBToYJ(uint8_t r, uint8_t g, uint8_t b) { - return (38 * r + 75 * g + 15 * b + 64) >> 7; +// 8 bit +static __inline uint8_t RGBToYJ(uint8_t r, uint8_t g, uint8_t b) { + return (77 * r + 150 * g + 29 * b + 128) >> 8; } -static __inline int RGBToUJ(uint8_t r, uint8_t g, uint8_t b) { - return (127 * b - 84 * g - 43 * r + 0x8080) >> 8; +static __inline uint8_t RGBToYMatrix(uint8_t b0, + uint8_t b1, + uint8_t b2, + uint8_t b3, + const struct ArgbConstants* c) { + return (c->kRGBToY[0] * b0 + c->kRGBToY[1] * b1 + c->kRGBToY[2] * b2 + + c->kRGBToY[3] * b3 + c->kAddY[0]) >> + 8; } -static __inline int RGBToVJ(uint8_t r, uint8_t g, uint8_t b) { - return (127 * r - 107 * g - 20 * b + 0x8080) >> 8; +static __inline uint8_t RGBToUMatrix(uint8_t b0, + uint8_t b1, + uint8_t b2, + uint8_t b3, + const struct ArgbConstants* c) { + return (c->kAddUV[0] - (c->kRGBToU[0] * b0 + c->kRGBToU[1] * b1 + + c->kRGBToU[2] * b2 + c->kRGBToU[3] * b3)) >> + 8; +} +static __inline uint8_t RGBToVMatrix(uint8_t b0, + uint8_t b1, + uint8_t b2, + uint8_t b3, + const struct ArgbConstants* c) { + return (c->kAddUV[0] - (c->kRGBToV[0] * b0 + c->kRGBToV[1] * b1 + + c->kRGBToV[2] * b2 + c->kRGBToV[3] * b3)) >> + 8; } -#define AVGB(a, b) (((a) + (b) + 1) >> 1) - -// ARGBToYJ_C and ARGBToUVJ_C -#define MAKEROWYJ(NAME, R, G, B, BPP) \ - void NAME##ToYJRow_C(const uint8_t* src_argb0, uint8_t* dst_y, int width) { \ - int x; \ - for (x = 0; x < width; ++x) { \ - dst_y[0] = RGBToYJ(src_argb0[R], src_argb0[G], src_argb0[B]); \ - src_argb0 += BPP; \ - dst_y += 1; \ - } \ - } \ - void NAME##ToUVJRow_C(const uint8_t* src_rgb0, int src_stride_rgb, \ - uint8_t* dst_u, uint8_t* dst_v, int width) { \ - const uint8_t* src_rgb1 = src_rgb0 + src_stride_rgb; \ - int x; \ - for (x = 0; x < width - 1; x += 2) { \ - uint8_t ab = AVGB(AVGB(src_rgb0[B], src_rgb1[B]), \ - AVGB(src_rgb0[B + BPP], src_rgb1[B + BPP])); \ - uint8_t ag = AVGB(AVGB(src_rgb0[G], src_rgb1[G]), \ - AVGB(src_rgb0[G + BPP], src_rgb1[G + BPP])); \ - uint8_t ar = AVGB(AVGB(src_rgb0[R], src_rgb1[R]), \ - AVGB(src_rgb0[R + BPP], src_rgb1[R + BPP])); \ - dst_u[0] = RGBToUJ(ar, ag, ab); \ - dst_v[0] = RGBToVJ(ar, ag, ab); \ - src_rgb0 += BPP * 2; \ - src_rgb1 += BPP * 2; \ - dst_u += 1; \ - dst_v += 1; \ - } \ - if (width & 1) { \ - uint8_t ab = AVGB(src_rgb0[B], src_rgb1[B]); \ - uint8_t ag = AVGB(src_rgb0[G], src_rgb1[G]); \ - uint8_t ar = AVGB(src_rgb0[R], src_rgb1[R]); \ - dst_u[0] = RGBToUJ(ar, ag, ab); \ - dst_v[0] = RGBToVJ(ar, ag, ab); \ - } \ +void ARGBToYMatrixRow_C(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + int x; + for (x = 0; x < width; ++x) { + dst_y[0] = + RGBToYMatrix(src_argb[0], src_argb[1], src_argb[2], src_argb[3], c); + src_argb += 4; + dst_y += 1; } +} -MAKEROWYJ(ARGB, 2, 1, 0, 4) -#undef MAKEROWYJ +void ARGBToUVMatrixRow_C(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + const uint8_t* src_argb1 = src_argb + src_stride_argb; + int x; + for (x = 0; x < width - 1; x += 2) { + uint8_t b0 = + (src_argb[0] + src_argb[4] + src_argb1[0] + src_argb1[4] + 2) >> 2; + uint8_t b1 = + (src_argb[1] + src_argb[5] + src_argb1[1] + src_argb1[5] + 2) >> 2; + uint8_t b2 = + (src_argb[2] + src_argb[6] + src_argb1[2] + src_argb1[6] + 2) >> 2; + uint8_t b3 = + (src_argb[3] + src_argb[7] + src_argb1[3] + src_argb1[7] + 2) >> 2; + dst_u[0] = RGBToUMatrix(b0, b1, b2, b3, c); + dst_v[0] = RGBToVMatrix(b0, b1, b2, b3, c); + src_argb += 8; + src_argb1 += 8; + dst_u += 1; + dst_v += 1; + } + if (width & 1) { + uint8_t b0 = (src_argb[0] + src_argb1[0] + 1) >> 1; + uint8_t b1 = (src_argb[1] + src_argb1[1] + 1) >> 1; + uint8_t b2 = (src_argb[2] + src_argb1[2] + 1) >> 1; + uint8_t b3 = (src_argb[3] + src_argb1[3] + 1) >> 1; + dst_u[0] = RGBToUMatrix(b0, b1, b2, b3, c); + dst_v[0] = RGBToVMatrix(b0, b1, b2, b3, c); + } +} + +void ARGBToUV444MatrixRow_C(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + int x; + for (x = 0; x < width; ++x) { + dst_u[0] = + RGBToUMatrix(src_argb[0], src_argb[1], src_argb[2], src_argb[3], c); + dst_v[0] = + RGBToVMatrix(src_argb[0], src_argb[1], src_argb[2], src_argb[3], c); + src_argb += 4; + dst_u += 1; + dst_v += 1; + } +} void RGB565ToYRow_C(const uint8_t* src_rgb565, uint8_t* dst_y, int width) { int x; for (x = 0; x < width; ++x) { uint8_t b = src_rgb565[0] & 0x1f; - uint8_t g = (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3); + uint8_t g = STATIC_CAST( + uint8_t, (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3)); uint8_t r = src_rgb565[1] >> 3; - b = (b << 3) | (b >> 2); - g = (g << 2) | (g >> 4); - r = (r << 3) | (r >> 2); + b = STATIC_CAST(uint8_t, (b << 3) | (b >> 2)); + g = STATIC_CAST(uint8_t, (g << 2) | (g >> 4)); + r = STATIC_CAST(uint8_t, (r << 3) | (r >> 2)); dst_y[0] = RGBToY(r, g, b); src_rgb565 += 2; dst_y += 1; @@ -537,11 +768,12 @@ void ARGB1555ToYRow_C(const uint8_t* src_argb1555, uint8_t* dst_y, int width) { int x; for (x = 0; x < width; ++x) { uint8_t b = src_argb1555[0] & 0x1f; - uint8_t g = (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3); + uint8_t g = STATIC_CAST( + uint8_t, (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3)); uint8_t r = (src_argb1555[1] & 0x7c) >> 2; - b = (b << 3) | (b >> 2); - g = (g << 3) | (g >> 2); - r = (r << 3) | (r >> 2); + b = STATIC_CAST(uint8_t, (b << 3) | (b >> 2)); + g = STATIC_CAST(uint8_t, (g << 3) | (g >> 2)); + r = STATIC_CAST(uint8_t, (r << 3) | (r >> 2)); dst_y[0] = RGBToY(r, g, b); src_argb1555 += 2; dst_y += 1; @@ -554,9 +786,9 @@ void ARGB4444ToYRow_C(const uint8_t* src_argb4444, uint8_t* dst_y, int width) { uint8_t b = src_argb4444[0] & 0x0f; uint8_t g = src_argb4444[0] >> 4; uint8_t r = src_argb4444[1] & 0x0f; - b = (b << 4) | b; - g = (g << 4) | g; - r = (r << 4) | r; + b = STATIC_CAST(uint8_t, (b << 4) | b); + g = STATIC_CAST(uint8_t, (g << 4) | g); + r = STATIC_CAST(uint8_t, (r << 4) | r); dst_y[0] = RGBToY(r, g, b); src_argb4444 += 2; dst_y += 1; @@ -571,45 +803,68 @@ void RGB565ToUVRow_C(const uint8_t* src_rgb565, const uint8_t* next_rgb565 = src_rgb565 + src_stride_rgb565; int x; for (x = 0; x < width - 1; x += 2) { - uint8_t b0 = src_rgb565[0] & 0x1f; - uint8_t g0 = (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3); - uint8_t r0 = src_rgb565[1] >> 3; - uint8_t b1 = src_rgb565[2] & 0x1f; - uint8_t g1 = (src_rgb565[2] >> 5) | ((src_rgb565[3] & 0x07) << 3); - uint8_t r1 = src_rgb565[3] >> 3; - uint8_t b2 = next_rgb565[0] & 0x1f; - uint8_t g2 = (next_rgb565[0] >> 5) | ((next_rgb565[1] & 0x07) << 3); - uint8_t r2 = next_rgb565[1] >> 3; - uint8_t b3 = next_rgb565[2] & 0x1f; - uint8_t g3 = (next_rgb565[2] >> 5) | ((next_rgb565[3] & 0x07) << 3); - uint8_t r3 = next_rgb565[3] >> 3; - uint8_t b = (b0 + b1 + b2 + b3); // 565 * 4 = 787. - uint8_t g = (g0 + g1 + g2 + g3); - uint8_t r = (r0 + r1 + r2 + r3); - b = (b << 1) | (b >> 6); // 787 -> 888. - r = (r << 1) | (r >> 6); + uint8_t b0 = STATIC_CAST(uint8_t, src_rgb565[0] & 0x1f); + uint8_t g0 = STATIC_CAST( + uint8_t, (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3)); + uint8_t r0 = STATIC_CAST(uint8_t, src_rgb565[1] >> 3); + uint8_t b1 = STATIC_CAST(uint8_t, src_rgb565[2] & 0x1f); + uint8_t g1 = STATIC_CAST( + uint8_t, (src_rgb565[2] >> 5) | ((src_rgb565[3] & 0x07) << 3)); + uint8_t r1 = STATIC_CAST(uint8_t, src_rgb565[3] >> 3); + uint8_t b2 = STATIC_CAST(uint8_t, next_rgb565[0] & 0x1f); + uint8_t g2 = STATIC_CAST( + uint8_t, (next_rgb565[0] >> 5) | ((next_rgb565[1] & 0x07) << 3)); + uint8_t r2 = STATIC_CAST(uint8_t, next_rgb565[1] >> 3); + uint8_t b3 = STATIC_CAST(uint8_t, next_rgb565[2] & 0x1f); + uint8_t g3 = STATIC_CAST( + uint8_t, (next_rgb565[2] >> 5) | ((next_rgb565[3] & 0x07) << 3)); + uint8_t r3 = STATIC_CAST(uint8_t, next_rgb565[3] >> 3); + + b0 = STATIC_CAST(uint8_t, (b0 << 3) | (b0 >> 2)); + g0 = STATIC_CAST(uint8_t, (g0 << 2) | (g0 >> 4)); + r0 = STATIC_CAST(uint8_t, (r0 << 3) | (r0 >> 2)); + b1 = STATIC_CAST(uint8_t, (b1 << 3) | (b1 >> 2)); + g1 = STATIC_CAST(uint8_t, (g1 << 2) | (g1 >> 4)); + r1 = STATIC_CAST(uint8_t, (r1 << 3) | (r1 >> 2)); + b2 = STATIC_CAST(uint8_t, (b2 << 3) | (b2 >> 2)); + g2 = STATIC_CAST(uint8_t, (g2 << 2) | (g2 >> 4)); + r2 = STATIC_CAST(uint8_t, (r2 << 3) | (r2 >> 2)); + b3 = STATIC_CAST(uint8_t, (b3 << 3) | (b3 >> 2)); + g3 = STATIC_CAST(uint8_t, (g3 << 2) | (g3 >> 4)); + r3 = STATIC_CAST(uint8_t, (r3 << 3) | (r3 >> 2)); + + uint8_t b = (b0 + b1 + b2 + b3 + 2) >> 2; + uint8_t g = (g0 + g1 + g2 + g3 + 2) >> 2; + uint8_t r = (r0 + r1 + r2 + r3 + 2) >> 2; dst_u[0] = RGBToU(r, g, b); dst_v[0] = RGBToV(r, g, b); + src_rgb565 += 4; next_rgb565 += 4; dst_u += 1; dst_v += 1; } if (width & 1) { - uint8_t b0 = src_rgb565[0] & 0x1f; - uint8_t g0 = (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3); - uint8_t r0 = src_rgb565[1] >> 3; - uint8_t b2 = next_rgb565[0] & 0x1f; - uint8_t g2 = (next_rgb565[0] >> 5) | ((next_rgb565[1] & 0x07) << 3); - uint8_t r2 = next_rgb565[1] >> 3; - uint8_t b = (b0 + b2); // 565 * 2 = 676. - uint8_t g = (g0 + g2); - uint8_t r = (r0 + r2); - b = (b << 2) | (b >> 4); // 676 -> 888 - g = (g << 1) | (g >> 6); - r = (r << 2) | (r >> 4); - dst_u[0] = RGBToU(r, g, b); - dst_v[0] = RGBToV(r, g, b); + uint8_t b0 = STATIC_CAST(uint8_t, src_rgb565[0] & 0x1f); + uint8_t g0 = STATIC_CAST( + uint8_t, (src_rgb565[0] >> 5) | ((src_rgb565[1] & 0x07) << 3)); + uint8_t r0 = STATIC_CAST(uint8_t, src_rgb565[1] >> 3); + uint8_t b2 = STATIC_CAST(uint8_t, next_rgb565[0] & 0x1f); + uint8_t g2 = STATIC_CAST( + uint8_t, (next_rgb565[0] >> 5) | ((next_rgb565[1] & 0x07) << 3)); + uint8_t r2 = STATIC_CAST(uint8_t, next_rgb565[1] >> 3); + b0 = STATIC_CAST(uint8_t, (b0 << 3) | (b0 >> 2)); + g0 = STATIC_CAST(uint8_t, (g0 << 2) | (g0 >> 4)); + r0 = STATIC_CAST(uint8_t, (r0 << 3) | (r0 >> 2)); + b2 = STATIC_CAST(uint8_t, (b2 << 3) | (b2 >> 2)); + g2 = STATIC_CAST(uint8_t, (g2 << 2) | (g2 >> 4)); + r2 = STATIC_CAST(uint8_t, (r2 << 3) | (r2 >> 2)); + + uint8_t ab = AVGB(b0, b2); + uint8_t ag = AVGB(g0, g2); + uint8_t ar = AVGB(r0, r2); + dst_u[0] = RGBToU(ar, ag, ab); + dst_v[0] = RGBToV(ar, ag, ab); } } @@ -621,46 +876,69 @@ void ARGB1555ToUVRow_C(const uint8_t* src_argb1555, const uint8_t* next_argb1555 = src_argb1555 + src_stride_argb1555; int x; for (x = 0; x < width - 1; x += 2) { - uint8_t b0 = src_argb1555[0] & 0x1f; - uint8_t g0 = (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3); - uint8_t r0 = (src_argb1555[1] & 0x7c) >> 2; - uint8_t b1 = src_argb1555[2] & 0x1f; - uint8_t g1 = (src_argb1555[2] >> 5) | ((src_argb1555[3] & 0x03) << 3); - uint8_t r1 = (src_argb1555[3] & 0x7c) >> 2; - uint8_t b2 = next_argb1555[0] & 0x1f; - uint8_t g2 = (next_argb1555[0] >> 5) | ((next_argb1555[1] & 0x03) << 3); - uint8_t r2 = (next_argb1555[1] & 0x7c) >> 2; - uint8_t b3 = next_argb1555[2] & 0x1f; - uint8_t g3 = (next_argb1555[2] >> 5) | ((next_argb1555[3] & 0x03) << 3); - uint8_t r3 = (next_argb1555[3] & 0x7c) >> 2; - uint8_t b = (b0 + b1 + b2 + b3); // 555 * 4 = 777. - uint8_t g = (g0 + g1 + g2 + g3); - uint8_t r = (r0 + r1 + r2 + r3); - b = (b << 1) | (b >> 6); // 777 -> 888. - g = (g << 1) | (g >> 6); - r = (r << 1) | (r >> 6); + uint8_t b0 = STATIC_CAST(uint8_t, src_argb1555[0] & 0x1f); + uint8_t g0 = STATIC_CAST( + uint8_t, (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3)); + uint8_t r0 = STATIC_CAST(uint8_t, (src_argb1555[1] & 0x7c) >> 2); + uint8_t b1 = STATIC_CAST(uint8_t, src_argb1555[2] & 0x1f); + uint8_t g1 = STATIC_CAST( + uint8_t, (src_argb1555[2] >> 5) | ((src_argb1555[3] & 0x03) << 3)); + uint8_t r1 = STATIC_CAST(uint8_t, (src_argb1555[3] & 0x7c) >> 2); + uint8_t b2 = STATIC_CAST(uint8_t, next_argb1555[0] & 0x1f); + uint8_t g2 = STATIC_CAST( + uint8_t, (next_argb1555[0] >> 5) | ((next_argb1555[1] & 0x03) << 3)); + uint8_t r2 = STATIC_CAST(uint8_t, (next_argb1555[1] & 0x7c) >> 2); + uint8_t b3 = STATIC_CAST(uint8_t, next_argb1555[2] & 0x1f); + uint8_t g3 = STATIC_CAST( + uint8_t, (next_argb1555[2] >> 5) | ((next_argb1555[3] & 0x03) << 3)); + uint8_t r3 = STATIC_CAST(uint8_t, (next_argb1555[3] & 0x7c) >> 2); + + b0 = STATIC_CAST(uint8_t, (b0 << 3) | (b0 >> 2)); + g0 = STATIC_CAST(uint8_t, (g0 << 3) | (g0 >> 2)); + r0 = STATIC_CAST(uint8_t, (r0 << 3) | (r0 >> 2)); + b1 = STATIC_CAST(uint8_t, (b1 << 3) | (b1 >> 2)); + g1 = STATIC_CAST(uint8_t, (g1 << 3) | (g1 >> 2)); + r1 = STATIC_CAST(uint8_t, (r1 << 3) | (r1 >> 2)); + b2 = STATIC_CAST(uint8_t, (b2 << 3) | (b2 >> 2)); + g2 = STATIC_CAST(uint8_t, (g2 << 3) | (g2 >> 2)); + r2 = STATIC_CAST(uint8_t, (r2 << 3) | (r2 >> 2)); + b3 = STATIC_CAST(uint8_t, (b3 << 3) | (b3 >> 2)); + g3 = STATIC_CAST(uint8_t, (g3 << 3) | (g3 >> 2)); + r3 = STATIC_CAST(uint8_t, (r3 << 3) | (r3 >> 2)); + + uint8_t b = (b0 + b1 + b2 + b3 + 2) >> 2; + uint8_t g = (g0 + g1 + g2 + g3 + 2) >> 2; + uint8_t r = (r0 + r1 + r2 + r3 + 2) >> 2; dst_u[0] = RGBToU(r, g, b); dst_v[0] = RGBToV(r, g, b); + src_argb1555 += 4; next_argb1555 += 4; dst_u += 1; dst_v += 1; } if (width & 1) { - uint8_t b0 = src_argb1555[0] & 0x1f; - uint8_t g0 = (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3); - uint8_t r0 = (src_argb1555[1] & 0x7c) >> 2; - uint8_t b2 = next_argb1555[0] & 0x1f; - uint8_t g2 = (next_argb1555[0] >> 5) | ((next_argb1555[1] & 0x03) << 3); - uint8_t r2 = next_argb1555[1] >> 3; - uint8_t b = (b0 + b2); // 555 * 2 = 666. - uint8_t g = (g0 + g2); - uint8_t r = (r0 + r2); - b = (b << 2) | (b >> 4); // 666 -> 888. - g = (g << 2) | (g >> 4); - r = (r << 2) | (r >> 4); - dst_u[0] = RGBToU(r, g, b); - dst_v[0] = RGBToV(r, g, b); + uint8_t b0 = STATIC_CAST(uint8_t, src_argb1555[0] & 0x1f); + uint8_t g0 = STATIC_CAST( + uint8_t, (src_argb1555[0] >> 5) | ((src_argb1555[1] & 0x03) << 3)); + uint8_t r0 = STATIC_CAST(uint8_t, (src_argb1555[1] & 0x7c) >> 2); + uint8_t b2 = STATIC_CAST(uint8_t, next_argb1555[0] & 0x1f); + uint8_t g2 = STATIC_CAST( + uint8_t, (next_argb1555[0] >> 5) | ((next_argb1555[1] & 0x03) << 3)); + uint8_t r2 = STATIC_CAST(uint8_t, (next_argb1555[1] & 0x7c) >> 2); + + b0 = STATIC_CAST(uint8_t, (b0 << 3) | (b0 >> 2)); + g0 = STATIC_CAST(uint8_t, (g0 << 3) | (g0 >> 2)); + r0 = STATIC_CAST(uint8_t, (r0 << 3) | (r0 >> 2)); + b2 = STATIC_CAST(uint8_t, (b2 << 3) | (b2 >> 2)); + g2 = STATIC_CAST(uint8_t, (g2 << 3) | (g2 >> 2)); + r2 = STATIC_CAST(uint8_t, (r2 << 3) | (r2 >> 2)); + + uint8_t ab = AVGB(b0, b2); + uint8_t ag = AVGB(g0, g2); + uint8_t ar = AVGB(r0, r2); + dst_u[0] = RGBToU(ar, ag, ab); + dst_v[0] = RGBToV(ar, ag, ab); } } @@ -684,14 +962,26 @@ void ARGB4444ToUVRow_C(const uint8_t* src_argb4444, uint8_t b3 = next_argb4444[2] & 0x0f; uint8_t g3 = next_argb4444[2] >> 4; uint8_t r3 = next_argb4444[3] & 0x0f; - uint8_t b = (b0 + b1 + b2 + b3); // 444 * 4 = 666. - uint8_t g = (g0 + g1 + g2 + g3); - uint8_t r = (r0 + r1 + r2 + r3); - b = (b << 2) | (b >> 4); // 666 -> 888. - g = (g << 2) | (g >> 4); - r = (r << 2) | (r >> 4); + + b0 = STATIC_CAST(uint8_t, (b0 << 4) | b0); + g0 = STATIC_CAST(uint8_t, (g0 << 4) | g0); + r0 = STATIC_CAST(uint8_t, (r0 << 4) | r0); + b1 = STATIC_CAST(uint8_t, (b1 << 4) | b1); + g1 = STATIC_CAST(uint8_t, (g1 << 4) | g1); + r1 = STATIC_CAST(uint8_t, (r1 << 4) | r1); + b2 = STATIC_CAST(uint8_t, (b2 << 4) | b2); + g2 = STATIC_CAST(uint8_t, (g2 << 4) | g2); + r2 = STATIC_CAST(uint8_t, (r2 << 4) | r2); + b3 = STATIC_CAST(uint8_t, (b3 << 4) | b3); + g3 = STATIC_CAST(uint8_t, (g3 << 4) | g3); + r3 = STATIC_CAST(uint8_t, (r3 << 4) | r3); + + uint8_t b = (b0 + b1 + b2 + b3 + 2) >> 2; + uint8_t g = (g0 + g1 + g2 + g3 + 2) >> 2; + uint8_t r = (r0 + r1 + r2 + r3 + 2) >> 2; dst_u[0] = RGBToU(r, g, b); dst_v[0] = RGBToV(r, g, b); + src_argb4444 += 4; next_argb4444 += 4; dst_u += 1; @@ -704,31 +994,19 @@ void ARGB4444ToUVRow_C(const uint8_t* src_argb4444, uint8_t b2 = next_argb4444[0] & 0x0f; uint8_t g2 = next_argb4444[0] >> 4; uint8_t r2 = next_argb4444[1] & 0x0f; - uint8_t b = (b0 + b2); // 444 * 2 = 555. - uint8_t g = (g0 + g2); - uint8_t r = (r0 + r2); - b = (b << 3) | (b >> 2); // 555 -> 888. - g = (g << 3) | (g >> 2); - r = (r << 3) | (r >> 2); - dst_u[0] = RGBToU(r, g, b); - dst_v[0] = RGBToV(r, g, b); - } -} -void ARGBToUV444Row_C(const uint8_t* src_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - for (x = 0; x < width; ++x) { - uint8_t ab = src_argb[0]; - uint8_t ag = src_argb[1]; - uint8_t ar = src_argb[2]; + b0 = STATIC_CAST(uint8_t, (b0 << 4) | b0); + g0 = STATIC_CAST(uint8_t, (g0 << 4) | g0); + r0 = STATIC_CAST(uint8_t, (r0 << 4) | r0); + b2 = STATIC_CAST(uint8_t, (b2 << 4) | b2); + g2 = STATIC_CAST(uint8_t, (g2 << 4) | g2); + r2 = STATIC_CAST(uint8_t, (r2 << 4) | r2); + + uint8_t ab = AVGB(b0, b2); + uint8_t ag = AVGB(g0, g2); + uint8_t ar = AVGB(r0, r2); dst_u[0] = RGBToU(ar, ag, ab); dst_v[0] = RGBToV(ar, ag, ab); - src_argb += 4; - dst_u += 1; - dst_v += 1; } } @@ -754,9 +1032,9 @@ void ARGBSepiaRow_C(uint8_t* dst_argb, int width) { int sg = (b * 22 + g * 88 + r * 45) >> 7; int sr = (b * 24 + g * 98 + r * 50) >> 7; // b does not over flow. a is preserved from original. - dst_argb[0] = sb; - dst_argb[1] = clamp255(sg); - dst_argb[2] = clamp255(sr); + dst_argb[0] = STATIC_CAST(uint8_t, sb); + dst_argb[1] = STATIC_CAST(uint8_t, clamp255(sg)); + dst_argb[2] = STATIC_CAST(uint8_t, clamp255(sr)); dst_argb += 4; } } @@ -785,10 +1063,10 @@ void ARGBColorMatrixRow_C(const uint8_t* src_argb, int sa = (b * matrix_argb[12] + g * matrix_argb[13] + r * matrix_argb[14] + a * matrix_argb[15]) >> 6; - dst_argb[0] = Clamp(sb); - dst_argb[1] = Clamp(sg); - dst_argb[2] = Clamp(sr); - dst_argb[3] = Clamp(sa); + dst_argb[0] = STATIC_CAST(uint8_t, Clamp(sb)); + dst_argb[1] = STATIC_CAST(uint8_t, Clamp(sg)); + dst_argb[2] = STATIC_CAST(uint8_t, Clamp(sr)); + dst_argb[3] = STATIC_CAST(uint8_t, Clamp(sa)); src_argb += 4; dst_argb += 4; } @@ -838,9 +1116,12 @@ void ARGBQuantizeRow_C(uint8_t* dst_argb, int b = dst_argb[0]; int g = dst_argb[1]; int r = dst_argb[2]; - dst_argb[0] = (b * scale >> 16) * interval_size + interval_offset; - dst_argb[1] = (g * scale >> 16) * interval_size + interval_offset; - dst_argb[2] = (r * scale >> 16) * interval_size + interval_offset; + dst_argb[0] = STATIC_CAST( + uint8_t, (b * scale >> 16) * interval_size + interval_offset); + dst_argb[1] = STATIC_CAST( + uint8_t, (g * scale >> 16) * interval_size + interval_offset); + dst_argb[2] = STATIC_CAST( + uint8_t, (r * scale >> 16) * interval_size + interval_offset); dst_argb += 4; } } @@ -874,56 +1155,51 @@ void ARGBShadeRow_C(const uint8_t* src_argb, #undef REPEAT8 #undef SHADE -#define REPEAT8(v) (v) | ((v) << 8) -#define SHADE(f, v) v* f >> 16 - -void ARGBMultiplyRow_C(const uint8_t* src_argb0, +void ARGBMultiplyRow_C(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { int i; for (i = 0; i < width; ++i) { - const uint32_t b = REPEAT8(src_argb0[0]); - const uint32_t g = REPEAT8(src_argb0[1]); - const uint32_t r = REPEAT8(src_argb0[2]); - const uint32_t a = REPEAT8(src_argb0[3]); + const uint32_t b = src_argb[0]; + const uint32_t g = src_argb[1]; + const uint32_t r = src_argb[2]; + const uint32_t a = src_argb[3]; const uint32_t b_scale = src_argb1[0]; const uint32_t g_scale = src_argb1[1]; const uint32_t r_scale = src_argb1[2]; const uint32_t a_scale = src_argb1[3]; - dst_argb[0] = SHADE(b, b_scale); - dst_argb[1] = SHADE(g, g_scale); - dst_argb[2] = SHADE(r, r_scale); - dst_argb[3] = SHADE(a, a_scale); - src_argb0 += 4; + dst_argb[0] = STATIC_CAST(uint8_t, (b * b_scale + 128) >> 8); + dst_argb[1] = STATIC_CAST(uint8_t, (g * g_scale + 128) >> 8); + dst_argb[2] = STATIC_CAST(uint8_t, (r * r_scale + 128) >> 8); + dst_argb[3] = STATIC_CAST(uint8_t, (a * a_scale + 128) >> 8); + src_argb += 4; src_argb1 += 4; dst_argb += 4; } } -#undef REPEAT8 -#undef SHADE #define SHADE(f, v) clamp255(v + f) -void ARGBAddRow_C(const uint8_t* src_argb0, +void ARGBAddRow_C(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { int i; for (i = 0; i < width; ++i) { - const int b = src_argb0[0]; - const int g = src_argb0[1]; - const int r = src_argb0[2]; - const int a = src_argb0[3]; + const int b = src_argb[0]; + const int g = src_argb[1]; + const int r = src_argb[2]; + const int a = src_argb[3]; const int b_add = src_argb1[0]; const int g_add = src_argb1[1]; const int r_add = src_argb1[2]; const int a_add = src_argb1[3]; - dst_argb[0] = SHADE(b, b_add); - dst_argb[1] = SHADE(g, g_add); - dst_argb[2] = SHADE(r, r_add); - dst_argb[3] = SHADE(a, a_add); - src_argb0 += 4; + dst_argb[0] = STATIC_CAST(uint8_t, SHADE(b, b_add)); + dst_argb[1] = STATIC_CAST(uint8_t, SHADE(g, g_add)); + dst_argb[2] = STATIC_CAST(uint8_t, SHADE(r, r_add)); + dst_argb[3] = STATIC_CAST(uint8_t, SHADE(a, a_add)); + src_argb += 4; src_argb1 += 4; dst_argb += 4; } @@ -932,25 +1208,25 @@ void ARGBAddRow_C(const uint8_t* src_argb0, #define SHADE(f, v) clamp0(f - v) -void ARGBSubtractRow_C(const uint8_t* src_argb0, +void ARGBSubtractRow_C(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { int i; for (i = 0; i < width; ++i) { - const int b = src_argb0[0]; - const int g = src_argb0[1]; - const int r = src_argb0[2]; - const int a = src_argb0[3]; + const int b = src_argb[0]; + const int g = src_argb[1]; + const int r = src_argb[2]; + const int a = src_argb[3]; const int b_sub = src_argb1[0]; const int g_sub = src_argb1[1]; const int r_sub = src_argb1[2]; const int a_sub = src_argb1[3]; - dst_argb[0] = SHADE(b, b_sub); - dst_argb[1] = SHADE(g, g_sub); - dst_argb[2] = SHADE(r, r_sub); - dst_argb[3] = SHADE(a, a_sub); - src_argb0 += 4; + dst_argb[0] = STATIC_CAST(uint8_t, SHADE(b, b_sub)); + dst_argb[1] = STATIC_CAST(uint8_t, SHADE(g, g_sub)); + dst_argb[2] = STATIC_CAST(uint8_t, SHADE(r, r_sub)); + dst_argb[3] = STATIC_CAST(uint8_t, SHADE(a, a_sub)); + src_argb += 4; src_argb1 += 4; dst_argb += 4; } @@ -1058,257 +1334,384 @@ void J400ToARGBRow_C(const uint8_t* src_y, uint8_t* dst_argb, int width) { } } -// TODO(fbarchard): Unify these structures to be platform independent. -// TODO(fbarchard): Generate SIMD structures from float matrix. +// Macros to create SIMD specific yuv to rgb conversion constants. -// BT.601 YUV to RGB reference -// R = (Y - 16) * 1.164 - V * -1.596 -// G = (Y - 16) * 1.164 - U * 0.391 - V * 0.813 -// B = (Y - 16) * 1.164 - U * -2.018 +// clang-format off -// Y contribution to R,G,B. Scale and bias. -#define YG 18997 /* round(1.164 * 64 * 256 * 256 / 257) */ -#define YGB -1160 /* 1.164 * 64 * -16 + 64 / 2 */ - -// U and V contributions to R,G,B. -#define UB -128 /* max(-128, round(-2.018 * 64)) */ -#define UG 25 /* round(0.391 * 64) */ -#define VG 52 /* round(0.813 * 64) */ -#define VR -102 /* round(-1.596 * 64) */ - -// Bias values to subtract 16 from Y and 128 from U and V. -#define BB (UB * 128 + YGB) -#define BG (UG * 128 + VG * 128 + YGB) -#define BR (VR * 128 + YGB) - -#if defined(__aarch64__) // 64 bit arm -const struct YuvConstants SIMD_ALIGNED(kYuvI601Constants) = { - {-UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR}, - {-UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR}, - {UG, VG, UG, VG, UG, VG, UG, VG}, - {UG, VG, UG, VG, UG, VG, UG, VG}, - {BB, BG, BR, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; -const struct YuvConstants SIMD_ALIGNED(kYvuI601Constants) = { - {-VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB}, - {-VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB}, - {VG, UG, VG, UG, VG, UG, VG, UG}, - {VG, UG, VG, UG, VG, UG, VG, UG}, - {BR, BG, BB, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; -#elif defined(__arm__) // 32 bit arm -const struct YuvConstants SIMD_ALIGNED(kYuvI601Constants) = { - {-UB, -UB, -UB, -UB, -VR, -VR, -VR, -VR, 0, 0, 0, 0, 0, 0, 0, 0}, - {UG, UG, UG, UG, VG, VG, VG, VG, 0, 0, 0, 0, 0, 0, 0, 0}, - {BB, BG, BR, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; -const struct YuvConstants SIMD_ALIGNED(kYvuI601Constants) = { - {-VR, -VR, -VR, -VR, -UB, -UB, -UB, -UB, 0, 0, 0, 0, 0, 0, 0, 0}, - {VG, VG, VG, VG, UG, UG, UG, UG, 0, 0, 0, 0, 0, 0, 0, 0}, - {BR, BG, BB, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; +#if defined(__aarch64__) || defined(__arm__) || defined(__riscv) +// Bias values include subtract 128 from U and V, bias from Y and rounding. +// For B and R bias is negative. For G bias is positive. +#define YUVCONSTANTSBODY(YG, YB, UB, UG, VG, VR) \ + {{UB, VR, UG, VG, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, \ + {YG, (UB * 128 - YB), (UG * 128 + VG * 128 + YB), (VR * 128 - YB), YB, 0, \ + 0, 0}} #else -const struct YuvConstants SIMD_ALIGNED(kYuvI601Constants) = { - {UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, - UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0}, - {UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, - UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG}, - {0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, - 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR}, - {BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB}, - {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, - {BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR}, - {YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG}}; -const struct YuvConstants SIMD_ALIGNED(kYvuI601Constants) = { - {VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, - VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0}, - {VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, - VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG}, - {0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, - 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB}, - {BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR}, - {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, - {BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB}, - {YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG}}; +#define YUVCONSTANTSBODY(YG, YB, UB, UG, VG, VR) \ + {{UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, \ + UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0}, \ + {UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, \ + UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG}, \ + {0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, \ + 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR}, \ + {YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG}, \ + {YB, YB, YB, YB, YB, YB, YB, YB, YB, YB, YB, YB, YB, YB, YB, YB}} #endif -#undef BB -#undef BG -#undef BR -#undef YGB +#if defined(__aarch64__) || defined(__arm__) || defined(__riscv) +#define ARGBCONSTANTSBODY(Y0, Y1, Y2, Y3, U0, U1, U2, U3, V0, V1, V2, V3, AY, \ + AUV) \ + {{Y0, Y1, Y2, Y3, Y0, Y1, Y2, Y3, Y0, Y1, Y2, Y3, Y0, Y1, Y2, Y3}, \ + {U0, U1, U2, U3, U0, U1, U2, U3, U0, U1, U2, U3, U0, U1, U2, U3}, \ + {V0, V1, V2, V3, V0, V1, V2, V3, V0, V1, V2, V3, V0, V1, V2, V3}, \ + {AY, AY, AY, AY, AY, AY, AY, AY}, \ + {AUV, AUV, AUV, AUV, AUV, AUV, AUV, AUV}} +#else +#define ARGBCONSTANTSBODY(Y0, Y1, Y2, Y3, U0, U1, U2, U3, V0, V1, V2, V3, AY, \ + AUV) \ + {{Y0, Y1, Y2, Y3, Y0, Y1, Y2, Y3, Y0, Y1, Y2, Y3, Y0, Y1, Y2, Y3, \ + Y0, Y1, Y2, Y3, Y0, Y1, Y2, Y3, Y0, Y1, Y2, Y3, Y0, Y1, Y2, Y3}, \ + {U0, U1, U2, U3, U0, U1, U2, U3, U0, U1, U2, U3, U0, U1, U2, U3, \ + U0, U1, U2, U3, U0, U1, U2, U3, U0, U1, U2, U3, U0, U1, U2, U3}, \ + {V0, V1, V2, V3, V0, V1, V2, V3, V0, V1, V2, V3, V0, V1, V2, V3, \ + V0, V1, V2, V3, V0, V1, V2, V3, V0, V1, V2, V3, V0, V1, V2, V3}, \ + {AY, AY, AY, AY, AY, AY, AY, AY, AY, AY, AY, AY, AY, AY, AY, AY}, \ + {AUV, AUV, AUV, AUV, AUV, AUV, AUV, AUV, AUV, AUV, AUV, AUV, AUV, AUV, \ + AUV, AUV}} +#endif + +// clang-format on + +#define MAKEYUVCONSTANTS(name, YG, YB, UB, UG, VG, VR) \ + const struct YuvConstants SIMD_ALIGNED(kYuv##name##Constants) = \ + YUVCONSTANTSBODY(YG, YB, UB, UG, VG, VR); \ + const struct YuvConstants SIMD_ALIGNED(kYvu##name##Constants) = \ + YUVCONSTANTSBODY(YG, YB, VR, VG, UG, UB); + +#define MAKEARGBCONSTANTS(name, RY, GY, BY, RU, GU, BU, RV, GV, BV, AY, AUV) \ + extern const struct ArgbConstants SIMD_ALIGNED(kArgb##name##Constants) = \ + ARGBCONSTANTSBODY(BY, GY, RY, 0, -(BU), -(GU), -(RU), 0, -(BV), -(GV), \ + -(RV), 0, AY, AUV); \ + extern const struct ArgbConstants SIMD_ALIGNED(kAbgr##name##Constants) = \ + ARGBCONSTANTSBODY(RY, GY, BY, 0, -(RU), -(GU), -(BU), 0, -(RV), -(GV), \ + -(BV), 0, AY, AUV); \ + extern const struct ArgbConstants SIMD_ALIGNED(kRgba##name##Constants) = \ + ARGBCONSTANTSBODY(0, BY, GY, RY, 0, -(BU), -(GU), -(RU), 0, -(BV), \ + -(GV), -(RV), AY, AUV); \ + extern const struct ArgbConstants SIMD_ALIGNED(kBgra##name##Constants) = \ + ARGBCONSTANTSBODY(0, RY, GY, BY, 0, -(RU), -(GU), -(BU), 0, -(RV), \ + -(GV), -(BV), AY, AUV); + +// BT.601 limited range RGB to YUV coefficients +// RY = round(0.299 * 219 / 255 * 256) = 66 +// GY = round(0.587 * 219 / 255 * 256) = 129 +// BY = round(0.114 * 219 / 255 * 256) = 25 +// BU = round(0.500 * 224 / 255 * 256) = 112 +// RU = round(-0.299 / (1 - 0.114) * 112.4) = -38 +// GU = round(-0.587 / (1 - 0.114) * 112.4) = -74 +// RV = 112 +// GV = round(-0.587 / (1 - 0.299) * 112.4) = -94 +// BV = round(-0.114 / (1 - 0.299) * 112.4) = -18 +// AY = 16 * 256 + 128 = 4224 +// AUV = 128 * 256 = 32768 +MAKEARGBCONSTANTS(I601, 66, 129, 25, -38, -74, 112, 112, -94, -18, 4224, 32768) + +// BT.601 full range RGB to YUV coefficients (aka JPEG) +// RY = round(0.299 * 256) = 77 +// GY = round(0.587 * 256) = 150 +// BY = round(0.114 * 256) = 29 +// BU = 128 +// RU = round(-0.299 / (1 - 0.114) * 128) = -43 +// GU = round(-0.587 / (1 - 0.114) * 128) = -85 +// RV = 128 +// GV = round(-0.587 / (1 - 0.299) * 128) = -107 +// BV = round(-0.114 / (1 - 0.299) * 128) = -21 +// AY = 128 +// AUV = 32768 +MAKEARGBCONSTANTS(JPEG, 77, 150, 29, -43, -85, 128, 128, -107, -21, 128, 32768) + +// BT.709 limited range RGB to YUV coefficients +// RY = round(0.2126 * 219 / 255 * 256) = 47 +// GY = round(0.7152 * 219 / 255 * 256) = 157 +// BY = round(0.0722 * 219 / 255 * 256) = 16 +// BU = round(0.500 * 224 / 255 * 256) = 112 +// RU = round(-0.2126 / (1 - 0.0722) * 112.4) = -26 +// GU = round(-0.7152 / (1 - 0.0722) * 112.4) = -86 +// RV = 112 +// GV = round(-0.7152 / (1 - 0.2126) * 112.4) = -102 +// BV = round(-0.0722 / (1 - 0.2126) * 112.4) = -10 +// AY = 16 * 256 + 128 = 4224 +// AUV = 128 * 256 = 32768 +MAKEARGBCONSTANTS(H709, 47, 157, 16, -26, -86, 112, 112, -102, -10, 4224, 32768) + +// BT.709 full range RGB to YUV coefficients +// RY = round(0.2126 * 256) = 54 +// GY = round(0.7152 * 256) = 183 +// BY = round(0.0722 * 256) = 19 +// BU = 128 +// RU = round(-0.2126 / (1 - 0.0722) * 128) = -29 +// GU = round(-0.7152 / (1 - 0.0722) * 128) = -99 +// RV = 128 +// GV = round(-0.7152 / (1 - 0.2126) * 128) = -116 +// BV = round(-0.0722 / (1 - 0.2126) * 128) = -12 +// AY = 128 +// AUV = 32768 +MAKEARGBCONSTANTS(F709, 54, 183, 19, -29, -99, 128, 128, -116, -12, 128, 32768) + +// BT.2020 limited range RGB to YUV coefficients +// RY = round(0.2627 * 219 / 255 * 256) = 58 +// GY = round(0.6780 * 219 / 255 * 256) = 149 +// BY = round(0.0593 * 219 / 255 * 256) = 13 +// BU = 112 +// RU = round(-0.2627 / (1 - 0.0593) * 112.4) = -31 +// GU = round(-0.6780 / (1 - 0.0593) * 112.4) = -81 +// RV = 112 +// GV = round(-0.6780 / (1 - 0.2627) * 112.4) = -103 +// BV = round(-0.0593 / (1 - 0.2627) * 112.4) = -9 +// AY = 16 * 256 + 128 = 4224 +// AUV = 128 * 256 = 32768 +MAKEARGBCONSTANTS(U2020, 59, 148, 13, -31, -81, 112, 112, -103, -9, 4224, 32768) + +// BT.2020 full range RGB to YUV coefficients +// RY = round(0.2627 * 256) = 67 +// GY = round(0.6780 * 256) = 174 +// BY = round(0.0593 * 256) = 15 +// BU = 128 +// RU = round(-0.2627 / (1 - 0.0593) * 128) = -36 +// GU = round(-0.6780 / (1 - 0.0593) * 128) = -92 +// RV = 128 +// GV = round(-0.6780 / (1 - 0.2627) * 128) = -118 +// BV = round(-0.0593 / (1 - 0.2627) * 128) = -10 +// AY = 128 +// AUV = 32768 +MAKEARGBCONSTANTS(V2020, 67, 174, 15, -36, -92, 128, 128, -118, -10, 128, 32768) + +// TODO(fbarchard): Generate SIMD structures from float matrix. + +// BT.601 limited range YUV to RGB reference +// R = (Y - 16) * 1.164 + V * 1.596 +// G = (Y - 16) * 1.164 - U * 0.391 - V * 0.813 +// B = (Y - 16) * 1.164 + U * 2.018 +// KR = 0.299; KB = 0.114 + +// U and V contributions to R,G,B. +#if defined(LIBYUV_UNLIMITED_DATA) || defined(LIBYUV_UNLIMITED_BT601) +#define UB 129 /* round(2.018 * 64) */ +#else +#define UB 128 /* max(128, round(2.018 * 64)) */ +#endif +#define UG 25 /* round(0.391 * 64) */ +#define VG 52 /* round(0.813 * 64) */ +#define VR 102 /* round(1.596 * 64) */ + +// Y contribution to R,G,B. Scale and bias. +#define YG 18997 /* round(1.164 * 64 * 256 * 256 / 257) */ +#define YB -1160 /* 1.164 * 64 * -16 + 64 / 2 */ + +MAKEYUVCONSTANTS(I601, YG, YB, UB, UG, VG, VR) + +#undef YG +#undef YB #undef UB #undef UG #undef VG #undef VR -#undef YG -// JPEG YUV to RGB reference -// * R = Y - V * -1.40200 -// * G = Y - U * 0.34414 - V * 0.71414 -// * B = Y - U * -1.77200 +// BT.601 full range YUV to RGB reference (aka JPEG) +// * R = Y + V * 1.40200 +// * G = Y - U * 0.34414 - V * 0.71414 +// * B = Y + U * 1.77200 +// KR = 0.299; KB = 0.114 + +// U and V contributions to R,G,B. +#define UB 113 /* round(1.77200 * 64) */ +#define UG 22 /* round(0.34414 * 64) */ +#define VG 46 /* round(0.71414 * 64) */ +#define VR 90 /* round(1.40200 * 64) */ // Y contribution to R,G,B. Scale and bias. #define YG 16320 /* round(1.000 * 64 * 256 * 256 / 257) */ -#define YGB 32 /* 64 / 2 */ +#define YB 32 /* 64 / 2 */ -// U and V contributions to R,G,B. -#define UB -113 /* round(-1.77200 * 64) */ -#define UG 22 /* round(0.34414 * 64) */ -#define VG 46 /* round(0.71414 * 64) */ -#define VR -90 /* round(-1.40200 * 64) */ +MAKEYUVCONSTANTS(JPEG, YG, YB, UB, UG, VG, VR) -// Bias values to round, and subtract 128 from U and V. -#define BB (UB * 128 + YGB) -#define BG (UG * 128 + VG * 128 + YGB) -#define BR (VR * 128 + YGB) - -#if defined(__aarch64__) -const struct YuvConstants SIMD_ALIGNED(kYuvJPEGConstants) = { - {-UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR}, - {-UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR}, - {UG, VG, UG, VG, UG, VG, UG, VG}, - {UG, VG, UG, VG, UG, VG, UG, VG}, - {BB, BG, BR, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; -const struct YuvConstants SIMD_ALIGNED(kYvuJPEGConstants) = { - {-VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB}, - {-VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB}, - {VG, UG, VG, UG, VG, UG, VG, UG}, - {VG, UG, VG, UG, VG, UG, VG, UG}, - {BR, BG, BB, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; -#elif defined(__arm__) -const struct YuvConstants SIMD_ALIGNED(kYuvJPEGConstants) = { - {-UB, -UB, -UB, -UB, -VR, -VR, -VR, -VR, 0, 0, 0, 0, 0, 0, 0, 0}, - {UG, UG, UG, UG, VG, VG, VG, VG, 0, 0, 0, 0, 0, 0, 0, 0}, - {BB, BG, BR, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; -const struct YuvConstants SIMD_ALIGNED(kYvuJPEGConstants) = { - {-VR, -VR, -VR, -VR, -UB, -UB, -UB, -UB, 0, 0, 0, 0, 0, 0, 0, 0}, - {VG, VG, VG, VG, UG, UG, UG, UG, 0, 0, 0, 0, 0, 0, 0, 0}, - {BR, BG, BB, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; -#else -const struct YuvConstants SIMD_ALIGNED(kYuvJPEGConstants) = { - {UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, - UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0}, - {UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, - UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG}, - {0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, - 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR}, - {BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB}, - {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, - {BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR}, - {YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG}}; -const struct YuvConstants SIMD_ALIGNED(kYvuJPEGConstants) = { - {VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, - VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0}, - {VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, - VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG}, - {0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, - 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB}, - {BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR}, - {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, - {BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB}, - {YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG}}; -#endif - -#undef BB -#undef BG -#undef BR -#undef YGB +#undef YG +#undef YB #undef UB #undef UG #undef VG #undef VR -#undef YG -// BT.709 YUV to RGB reference -// R = (Y - 16) * 1.164 - V * -1.793 -// G = (Y - 16) * 1.164 - U * 0.213 - V * 0.533 -// B = (Y - 16) * 1.164 - U * -2.112 -// See also http://www.equasys.de/colorconversion.html +// BT.709 limited range YUV to RGB reference +// R = (Y - 16) * 1.164 + V * 1.793 +// G = (Y - 16) * 1.164 - U * 0.213 - V * 0.533 +// B = (Y - 16) * 1.164 + U * 2.112 +// KR = 0.2126, KB = 0.0722 + +// U and V contributions to R,G,B. +#if defined(LIBYUV_UNLIMITED_DATA) || defined(LIBYUV_UNLIMITED_BT709) +#define UB 135 /* round(2.112 * 64) */ +#else +#define UB 128 /* max(128, round(2.112 * 64)) */ +#endif +#define UG 14 /* round(0.213 * 64) */ +#define VG 34 /* round(0.533 * 64) */ +#define VR 115 /* round(1.793 * 64) */ // Y contribution to R,G,B. Scale and bias. -#define YG 18997 /* round(1.164 * 64 * 256 * 256 / 257) */ -#define YGB -1160 /* 1.164 * 64 * -16 + 64 / 2 */ +#define YG 18997 /* round(1.164 * 64 * 256 * 256 / 257) */ +#define YB -1160 /* 1.164 * 64 * -16 + 64 / 2 */ -// TODO(fbarchard): Find way to express 2.112 instead of 2.0. -// U and V contributions to R,G,B. -#define UB -128 /* max(-128, round(-2.112 * 64)) */ -#define UG 14 /* round(0.213 * 64) */ -#define VG 34 /* round(0.533 * 64) */ -#define VR -115 /* round(-1.793 * 64) */ +MAKEYUVCONSTANTS(H709, YG, YB, UB, UG, VG, VR) -// Bias values to round, and subtract 128 from U and V. -#define BB (UB * 128 + YGB) -#define BG (UG * 128 + VG * 128 + YGB) -#define BR (VR * 128 + YGB) - -#if defined(__aarch64__) -const struct YuvConstants SIMD_ALIGNED(kYuvH709Constants) = { - {-UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR}, - {-UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR}, - {UG, VG, UG, VG, UG, VG, UG, VG}, - {UG, VG, UG, VG, UG, VG, UG, VG}, - {BB, BG, BR, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; -const struct YuvConstants SIMD_ALIGNED(kYvuH709Constants) = { - {-VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB}, - {-VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB}, - {VG, UG, VG, UG, VG, UG, VG, UG}, - {VG, UG, VG, UG, VG, UG, VG, UG}, - {BR, BG, BB, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; -#elif defined(__arm__) -const struct YuvConstants SIMD_ALIGNED(kYuvH709Constants) = { - {-UB, -UB, -UB, -UB, -VR, -VR, -VR, -VR, 0, 0, 0, 0, 0, 0, 0, 0}, - {UG, UG, UG, UG, VG, VG, VG, VG, 0, 0, 0, 0, 0, 0, 0, 0}, - {BB, BG, BR, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; -const struct YuvConstants SIMD_ALIGNED(kYvuH709Constants) = { - {-VR, -VR, -VR, -VR, -UB, -UB, -UB, -UB, 0, 0, 0, 0, 0, 0, 0, 0}, - {VG, VG, VG, VG, UG, UG, UG, UG, 0, 0, 0, 0, 0, 0, 0, 0}, - {BR, BG, BB, 0, 0, 0, 0, 0}, - {0x0101 * YG, 0, 0, 0}}; -#else -const struct YuvConstants SIMD_ALIGNED(kYuvH709Constants) = { - {UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, - UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0}, - {UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, - UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG}, - {0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, - 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR}, - {BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB}, - {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, - {BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR}, - {YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG}}; -const struct YuvConstants SIMD_ALIGNED(kYvuH709Constants) = { - {VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, - VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0}, - {VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, - VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG}, - {0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, - 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB}, - {BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR}, - {BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG}, - {BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB}, - {YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG}}; -#endif - -#undef BB -#undef BG -#undef BR -#undef YGB +#undef YG +#undef YB #undef UB #undef UG #undef VG #undef VR + +// BT.709 full range YUV to RGB reference +// R = Y + V * 1.5748 +// G = Y - U * 0.18732 - V * 0.46812 +// B = Y + U * 1.8556 +// KR = 0.2126, KB = 0.0722 + +// U and V contributions to R,G,B. +#define UB 119 /* round(1.8556 * 64) */ +#define UG 12 /* round(0.18732 * 64) */ +#define VG 30 /* round(0.46812 * 64) */ +#define VR 101 /* round(1.5748 * 64) */ + +// Y contribution to R,G,B. Scale and bias. (same as jpeg) +#define YG 16320 /* round(1 * 64 * 256 * 256 / 257) */ +#define YB 32 /* 64 / 2 */ + +MAKEYUVCONSTANTS(F709, YG, YB, UB, UG, VG, VR) + #undef YG +#undef YB +#undef UB +#undef UG +#undef VG +#undef VR + +// BT.2020 limited range YUV to RGB reference +// R = (Y - 16) * 1.164384 + V * 1.67867 +// G = (Y - 16) * 1.164384 - U * 0.187326 - V * 0.65042 +// B = (Y - 16) * 1.164384 + U * 2.14177 +// KR = 0.2627; KB = 0.0593 + +// U and V contributions to R,G,B. +#if defined(LIBYUV_UNLIMITED_DATA) || defined(LIBYUV_UNLIMITED_BT2020) +#define UB 137 /* round(2.142 * 64) */ +#else +#define UB 128 /* max(128, round(2.142 * 64)) */ +#endif +#define UG 12 /* round(0.187326 * 64) */ +#define VG 42 /* round(0.65042 * 64) */ +#define VR 107 /* round(1.67867 * 64) */ + +// Y contribution to R,G,B. Scale and bias. +#define YG 19003 /* round(1.164384 * 64 * 256 * 256 / 257) */ +#define YB -1160 /* 1.164384 * 64 * -16 + 64 / 2 */ + +MAKEYUVCONSTANTS(2020, YG, YB, UB, UG, VG, VR) + +#undef YG +#undef YB +#undef UB +#undef UG +#undef VG +#undef VR + +// BT.2020 full range YUV to RGB reference +// R = Y + V * 1.474600 +// G = Y - U * 0.164553 - V * 0.571353 +// B = Y + U * 1.881400 +// KR = 0.2627; KB = 0.0593 + +#define UB 120 /* round(1.881400 * 64) */ +#define UG 11 /* round(0.164553 * 64) */ +#define VG 37 /* round(0.571353 * 64) */ +#define VR 94 /* round(1.474600 * 64) */ + +// Y contribution to R,G,B. Scale and bias. (same as jpeg) +#define YG 16320 /* round(1 * 64 * 256 * 256 / 257) */ +#define YB 32 /* 64 / 2 */ + +MAKEYUVCONSTANTS(V2020, YG, YB, UB, UG, VG, VR) + +#undef YG +#undef YB +#undef UB +#undef UG +#undef VG +#undef VR + +#undef BB +#undef BG +#undef BR + +#undef MAKEYUVCONSTANTS + +#if defined(__aarch64__) || defined(__arm__) || defined(__riscv) +#define LOAD_YUV_CONSTANTS \ + int ub = yuvconstants->kUVCoeff[0]; \ + int vr = yuvconstants->kUVCoeff[1]; \ + int ug = yuvconstants->kUVCoeff[2]; \ + int vg = yuvconstants->kUVCoeff[3]; \ + int yg = yuvconstants->kRGBCoeffBias[0]; \ + int bb = yuvconstants->kRGBCoeffBias[1]; \ + int bg = yuvconstants->kRGBCoeffBias[2]; \ + int br = yuvconstants->kRGBCoeffBias[3] + +#define CALC_RGB16 \ + int32_t y1 = (uint32_t)(y32 * yg) >> 16; \ + int b16 = y1 + (u * ub) - bb; \ + int g16 = y1 + bg - (u * ug + v * vg); \ + int r16 = y1 + (v * vr) - br +#else +#define LOAD_YUV_CONSTANTS \ + int ub = yuvconstants->kUVToB[0]; \ + int ug = yuvconstants->kUVToG[0]; \ + int vg = yuvconstants->kUVToG[1]; \ + int vr = yuvconstants->kUVToR[1]; \ + int yg = yuvconstants->kYToRgb[0]; \ + int yb = yuvconstants->kYBiasToRgb[0] + +#define CALC_RGB16 \ + int32_t y1 = ((uint32_t)(y32 * yg) >> 16) + yb; \ + int8_t ui = (int8_t)u; \ + int8_t vi = (int8_t)v; \ + ui -= 0x80; \ + vi -= 0x80; \ + int b16 = y1 + (ui * ub); \ + int g16 = y1 - (ui * ug + vi * vg); \ + int r16 = y1 + (vi * vr) +#endif + +#if defined(__aarch64__) || defined(__arm__) || defined(__riscv) +#define LOAD_YUV_CONSTANTS_AR30 \ + int ub = yuvconstants->kUVCoeff[0]; \ + int vr = yuvconstants->kUVCoeff[1]; \ + int ug = yuvconstants->kUVCoeff[2]; \ + int vg = yuvconstants->kUVCoeff[3]; \ + int yg = yuvconstants->kRGBCoeffBias[0]; \ + int bb = yuvconstants->kRGBCoeffBias[1] + 24; \ + int bg = yuvconstants->kRGBCoeffBias[2] - 24; \ + int br = yuvconstants->kRGBCoeffBias[3] + 24 +#else +#define LOAD_YUV_CONSTANTS_AR30 \ + int ub = yuvconstants->kUVToB[0]; \ + int ug = yuvconstants->kUVToG[0]; \ + int vg = yuvconstants->kUVToG[1]; \ + int vr = yuvconstants->kUVToR[1]; \ + int yg = yuvconstants->kYToRgb[0]; \ + int yb = yuvconstants->kYBiasToRgb[0] - 24 +#endif // C reference code that mimics the YUV assembly. // Reads 8 bit YUV and leaves result as 16 bit. - static __inline void YuvPixel(uint8_t y, uint8_t u, uint8_t v, @@ -1316,39 +1719,12 @@ static __inline void YuvPixel(uint8_t y, uint8_t* g, uint8_t* r, const struct YuvConstants* yuvconstants) { -#if defined(__aarch64__) - int ub = -yuvconstants->kUVToRB[0]; - int ug = yuvconstants->kUVToG[0]; - int vg = yuvconstants->kUVToG[1]; - int vr = -yuvconstants->kUVToRB[1]; - int bb = yuvconstants->kUVBiasBGR[0]; - int bg = yuvconstants->kUVBiasBGR[1]; - int br = yuvconstants->kUVBiasBGR[2]; - int yg = yuvconstants->kYToRgb[0] / 0x0101; -#elif defined(__arm__) - int ub = -yuvconstants->kUVToRB[0]; - int ug = yuvconstants->kUVToG[0]; - int vg = yuvconstants->kUVToG[4]; - int vr = -yuvconstants->kUVToRB[4]; - int bb = yuvconstants->kUVBiasBGR[0]; - int bg = yuvconstants->kUVBiasBGR[1]; - int br = yuvconstants->kUVBiasBGR[2]; - int yg = yuvconstants->kYToRgb[0] / 0x0101; -#else - int ub = yuvconstants->kUVToB[0]; - int ug = yuvconstants->kUVToG[0]; - int vg = yuvconstants->kUVToG[1]; - int vr = yuvconstants->kUVToR[1]; - int bb = yuvconstants->kUVBiasB[0]; - int bg = yuvconstants->kUVBiasG[0]; - int br = yuvconstants->kUVBiasR[0]; - int yg = yuvconstants->kYToRgb[0]; -#endif - - uint32_t y1 = (uint32_t)(y * 0x0101 * yg) >> 16; - *b = Clamp((int32_t)(-(u * ub) + y1 + bb) >> 6); - *g = Clamp((int32_t)(-(u * ug + v * vg) + y1 + bg) >> 6); - *r = Clamp((int32_t)(-(v * vr) + y1 + br) >> 6); + LOAD_YUV_CONSTANTS; + uint32_t y32 = y * 0x0101; + CALC_RGB16; + *b = STATIC_CAST(uint8_t, Clamp((int32_t)(b16) >> 6)); + *g = STATIC_CAST(uint8_t, Clamp((int32_t)(g16) >> 6)); + *r = STATIC_CAST(uint8_t, Clamp((int32_t)(r16) >> 6)); } // Reads 8 bit YUV and leaves result as 16 bit. @@ -1359,85 +1735,50 @@ static __inline void YuvPixel8_16(uint8_t y, int* g, int* r, const struct YuvConstants* yuvconstants) { -#if defined(__aarch64__) - int ub = -yuvconstants->kUVToRB[0]; - int ug = yuvconstants->kUVToG[0]; - int vg = yuvconstants->kUVToG[1]; - int vr = -yuvconstants->kUVToRB[1]; - int bb = yuvconstants->kUVBiasBGR[0]; - int bg = yuvconstants->kUVBiasBGR[1]; - int br = yuvconstants->kUVBiasBGR[2]; - int yg = yuvconstants->kYToRgb[0] / 0x0101; -#elif defined(__arm__) - int ub = -yuvconstants->kUVToRB[0]; - int ug = yuvconstants->kUVToG[0]; - int vg = yuvconstants->kUVToG[4]; - int vr = -yuvconstants->kUVToRB[4]; - int bb = yuvconstants->kUVBiasBGR[0]; - int bg = yuvconstants->kUVBiasBGR[1]; - int br = yuvconstants->kUVBiasBGR[2]; - int yg = yuvconstants->kYToRgb[0] / 0x0101; -#else - int ub = yuvconstants->kUVToB[0]; - int ug = yuvconstants->kUVToG[0]; - int vg = yuvconstants->kUVToG[1]; - int vr = yuvconstants->kUVToR[1]; - int bb = yuvconstants->kUVBiasB[0]; - int bg = yuvconstants->kUVBiasG[0]; - int br = yuvconstants->kUVBiasR[0]; - int yg = yuvconstants->kYToRgb[0]; -#endif - - uint32_t y1 = (uint32_t)(y * 0x0101 * yg) >> 16; - *b = (int)(-(u * ub) + y1 + bb); - *g = (int)(-(u * ug + v * vg) + y1 + bg); - *r = (int)(-(v * vr) + y1 + br); + LOAD_YUV_CONSTANTS_AR30; + uint32_t y32 = y * 0x0101; + CALC_RGB16; + *b = b16; + *g = g16; + *r = r16; } // C reference code that mimics the YUV 16 bit assembly. // Reads 10 bit YUV and leaves result as 16 bit. -static __inline void YuvPixel16(int16_t y, - int16_t u, - int16_t v, - int* b, - int* g, - int* r, - const struct YuvConstants* yuvconstants) { -#if defined(__aarch64__) - int ub = -yuvconstants->kUVToRB[0]; - int ug = yuvconstants->kUVToG[0]; - int vg = yuvconstants->kUVToG[1]; - int vr = -yuvconstants->kUVToRB[1]; - int bb = yuvconstants->kUVBiasBGR[0]; - int bg = yuvconstants->kUVBiasBGR[1]; - int br = yuvconstants->kUVBiasBGR[2]; - int yg = yuvconstants->kYToRgb[0] / 0x0101; -#elif defined(__arm__) - int ub = -yuvconstants->kUVToRB[0]; - int ug = yuvconstants->kUVToG[0]; - int vg = yuvconstants->kUVToG[4]; - int vr = -yuvconstants->kUVToRB[4]; - int bb = yuvconstants->kUVBiasBGR[0]; - int bg = yuvconstants->kUVBiasBGR[1]; - int br = yuvconstants->kUVBiasBGR[2]; - int yg = yuvconstants->kYToRgb[0] / 0x0101; -#else - int ub = yuvconstants->kUVToB[0]; - int ug = yuvconstants->kUVToG[0]; - int vg = yuvconstants->kUVToG[1]; - int vr = yuvconstants->kUVToR[1]; - int bb = yuvconstants->kUVBiasB[0]; - int bg = yuvconstants->kUVBiasG[0]; - int br = yuvconstants->kUVBiasR[0]; - int yg = yuvconstants->kYToRgb[0]; -#endif +static __inline void YuvPixel10_16(uint16_t y, + uint16_t u, + uint16_t v, + int* b, + int* g, + int* r, + const struct YuvConstants* yuvconstants) { + LOAD_YUV_CONSTANTS; + uint32_t y32 = (y << 6) | (y >> 4); + u = STATIC_CAST(uint8_t, clamp255(u >> 2)); + v = STATIC_CAST(uint8_t, clamp255(v >> 2)); + CALC_RGB16; + *b = b16; + *g = g16; + *r = r16; +} - uint32_t y1 = (uint32_t)((y << 6) * yg) >> 16; - u = clamp255(u >> 2); - v = clamp255(v >> 2); - *b = (int)(-(u * ub) + y1 + bb); - *g = (int)(-(u * ug + v * vg) + y1 + bg); - *r = (int)(-(v * vr) + y1 + br); +// C reference code that mimics the YUV 16 bit assembly. +// Reads 12 bit YUV and leaves result as 16 bit. +static __inline void YuvPixel12_16(int16_t y, + int16_t u, + int16_t v, + int* b, + int* g, + int* r, + const struct YuvConstants* yuvconstants) { + LOAD_YUV_CONSTANTS; + uint32_t y32 = (y << 4) | (y >> 8); + u = STATIC_CAST(uint8_t, clamp255(u >> 4)); + v = STATIC_CAST(uint8_t, clamp255(v >> 4)); + CALC_RGB16; + *b = b16; + *g = g16; + *r = r16; } // C reference code that mimics the YUV 10 bit assembly. @@ -1452,59 +1793,89 @@ static __inline void YuvPixel10(uint16_t y, int b16; int g16; int r16; - YuvPixel16(y, u, v, &b16, &g16, &r16, yuvconstants); - *b = Clamp(b16 >> 6); - *g = Clamp(g16 >> 6); - *r = Clamp(r16 >> 6); + YuvPixel10_16(y, u, v, &b16, &g16, &r16, yuvconstants); + *b = STATIC_CAST(uint8_t, Clamp(b16 >> 6)); + *g = STATIC_CAST(uint8_t, Clamp(g16 >> 6)); + *r = STATIC_CAST(uint8_t, Clamp(r16 >> 6)); } -// Y contribution to R,G,B. Scale and bias. -#define YG 18997 /* round(1.164 * 64 * 256 * 256 / 257) */ -#define YGB -1160 /* 1.164 * 64 * -16 + 64 / 2 */ +// C reference code that mimics the YUV 12 bit assembly. +// Reads 12 bit YUV and clamps down to 8 bit RGB. +static __inline void YuvPixel12(uint16_t y, + uint16_t u, + uint16_t v, + uint8_t* b, + uint8_t* g, + uint8_t* r, + const struct YuvConstants* yuvconstants) { + int b16; + int g16; + int r16; + YuvPixel12_16(y, u, v, &b16, &g16, &r16, yuvconstants); + *b = STATIC_CAST(uint8_t, Clamp(b16 >> 6)); + *g = STATIC_CAST(uint8_t, Clamp(g16 >> 6)); + *r = STATIC_CAST(uint8_t, Clamp(r16 >> 6)); +} + +// C reference code that mimics the YUV 16 bit assembly. +// Reads 16 bit YUV and leaves result as 8 bit. +static __inline void YuvPixel16_8(uint16_t y, + uint16_t u, + uint16_t v, + uint8_t* b, + uint8_t* g, + uint8_t* r, + const struct YuvConstants* yuvconstants) { + LOAD_YUV_CONSTANTS; + uint32_t y32 = y; + u = STATIC_CAST(uint16_t, clamp255(u >> 8)); + v = STATIC_CAST(uint16_t, clamp255(v >> 8)); + CALC_RGB16; + *b = STATIC_CAST(uint8_t, Clamp((int32_t)(b16) >> 6)); + *g = STATIC_CAST(uint8_t, Clamp((int32_t)(g16) >> 6)); + *r = STATIC_CAST(uint8_t, Clamp((int32_t)(r16) >> 6)); +} + +// C reference code that mimics the YUV 16 bit assembly. +// Reads 16 bit YUV and leaves result as 16 bit. +static __inline void YuvPixel16_16(uint16_t y, + uint16_t u, + uint16_t v, + int* b, + int* g, + int* r, + const struct YuvConstants* yuvconstants) { + LOAD_YUV_CONSTANTS; + uint32_t y32 = y; + u = STATIC_CAST(uint16_t, clamp255(u >> 8)); + v = STATIC_CAST(uint16_t, clamp255(v >> 8)); + CALC_RGB16; + *b = b16; + *g = g16; + *r = r16; +} // C reference code that mimics the YUV assembly. -static __inline void YPixel(uint8_t y, uint8_t* b, uint8_t* g, uint8_t* r) { - uint32_t y1 = (uint32_t)(y * 0x0101 * YG) >> 16; - *b = Clamp((int32_t)(y1 + YGB) >> 6); - *g = Clamp((int32_t)(y1 + YGB) >> 6); - *r = Clamp((int32_t)(y1 + YGB) >> 6); -} - -#undef YG -#undef YGB - -#if !defined(LIBYUV_DISABLE_NEON) && \ - (defined(__ARM_NEON__) || defined(__aarch64__) || defined(LIBYUV_NEON)) -// C mimic assembly. -// TODO(fbarchard): Remove subsampling from Neon. -void I444ToARGBRow_C(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* rgb_buf, - const struct YuvConstants* yuvconstants, - int width) { - int x; - for (x = 0; x < width - 1; x += 2) { - uint8_t u = (src_u[0] + src_u[1] + 1) >> 1; - uint8_t v = (src_v[0] + src_v[1] + 1) >> 1; - YuvPixel(src_y[0], u, v, rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, - yuvconstants); - rgb_buf[3] = 255; - YuvPixel(src_y[1], u, v, rgb_buf + 4, rgb_buf + 5, rgb_buf + 6, - yuvconstants); - rgb_buf[7] = 255; - src_y += 2; - src_u += 2; - src_v += 2; - rgb_buf += 8; // Advance 2 pixels. - } - if (width & 1) { - YuvPixel(src_y[0], src_u[0], src_v[0], rgb_buf + 0, rgb_buf + 1, - rgb_buf + 2, yuvconstants); - rgb_buf[3] = 255; - } -} +// Reads 8 bit YUV and leaves result as 8 bit. +static __inline void YPixel(uint8_t y, + uint8_t* b, + uint8_t* g, + uint8_t* r, + const struct YuvConstants* yuvconstants) { +#if defined(__aarch64__) || defined(__arm__) || defined(__riscv) + int yg = yuvconstants->kRGBCoeffBias[0]; + int ygb = yuvconstants->kRGBCoeffBias[4]; #else + int ygb = yuvconstants->kYBiasToRgb[0]; + int yg = yuvconstants->kYToRgb[0]; +#endif + uint32_t y1 = (uint32_t)(y * 0x0101 * yg) >> 16; + uint8_t b8 = STATIC_CAST(uint8_t, Clamp(((int32_t)(y1) + ygb) >> 6)); + *b = b8; + *g = b8; + *r = b8; +} + void I444ToARGBRow_C(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, @@ -1522,7 +1893,23 @@ void I444ToARGBRow_C(const uint8_t* src_y, rgb_buf += 4; // Advance 1 pixel. } } -#endif + +void I444ToRGB24Row_C(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width) { + int x; + for (x = 0; x < width; ++x) { + YuvPixel(src_y[0], src_u[0], src_v[0], rgb_buf + 0, rgb_buf + 1, + rgb_buf + 2, yuvconstants); + src_y += 1; + src_u += 1; + src_v += 1; + rgb_buf += 3; // Advance 1 pixel. + } +} // Also used for 420 void I422ToARGBRow_C(const uint8_t* src_y, @@ -1578,9 +1965,102 @@ void I210ToARGBRow_C(const uint16_t* src_y, } } +void I410ToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width) { + int x; + for (x = 0; x < width; ++x) { + YuvPixel10(src_y[0], src_u[0], src_v[0], rgb_buf + 0, rgb_buf + 1, + rgb_buf + 2, yuvconstants); + rgb_buf[3] = 255; + src_y += 1; + src_u += 1; + src_v += 1; + rgb_buf += 4; // Advance 1 pixels. + } +} + +void I210AlphaToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width) { + int x; + for (x = 0; x < width - 1; x += 2) { + YuvPixel10(src_y[0], src_u[0], src_v[0], rgb_buf + 0, rgb_buf + 1, + rgb_buf + 2, yuvconstants); + rgb_buf[3] = STATIC_CAST(uint8_t, clamp255(src_a[0] >> 2)); + YuvPixel10(src_y[1], src_u[0], src_v[0], rgb_buf + 4, rgb_buf + 5, + rgb_buf + 6, yuvconstants); + rgb_buf[7] = STATIC_CAST(uint8_t, clamp255(src_a[1] >> 2)); + src_y += 2; + src_u += 1; + src_v += 1; + src_a += 2; + rgb_buf += 8; // Advance 2 pixels. + } + if (width & 1) { + YuvPixel10(src_y[0], src_u[0], src_v[0], rgb_buf + 0, rgb_buf + 1, + rgb_buf + 2, yuvconstants); + rgb_buf[3] = STATIC_CAST(uint8_t, clamp255(src_a[0] >> 2)); + } +} + +void I410AlphaToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width) { + int x; + for (x = 0; x < width; ++x) { + YuvPixel10(src_y[0], src_u[0], src_v[0], rgb_buf + 0, rgb_buf + 1, + rgb_buf + 2, yuvconstants); + rgb_buf[3] = STATIC_CAST(uint8_t, clamp255(src_a[0] >> 2)); + src_y += 1; + src_u += 1; + src_v += 1; + src_a += 1; + rgb_buf += 4; // Advance 1 pixels. + } +} + +// 12 bit YUV to ARGB +void I212ToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width) { + int x; + for (x = 0; x < width - 1; x += 2) { + YuvPixel12(src_y[0], src_u[0], src_v[0], rgb_buf + 0, rgb_buf + 1, + rgb_buf + 2, yuvconstants); + rgb_buf[3] = 255; + YuvPixel12(src_y[1], src_u[0], src_v[0], rgb_buf + 4, rgb_buf + 5, + rgb_buf + 6, yuvconstants); + rgb_buf[7] = 255; + src_y += 2; + src_u += 1; + src_v += 1; + rgb_buf += 8; // Advance 2 pixels. + } + if (width & 1) { + YuvPixel12(src_y[0], src_u[0], src_v[0], rgb_buf + 0, rgb_buf + 1, + rgb_buf + 2, yuvconstants); + rgb_buf[3] = 255; + } +} + static void StoreAR30(uint8_t* rgb_buf, int b, int g, int r) { uint32_t ar30; - b = b >> 4; // convert 10.6 to 10 bit. + b = b >> 4; // convert 8 bit 10.6 to 10 bit. g = g >> 4; r = r >> 4; b = Clamp10(b); @@ -1602,9 +2082,9 @@ void I210ToAR30Row_C(const uint16_t* src_y, int g; int r; for (x = 0; x < width - 1; x += 2) { - YuvPixel16(src_y[0], src_u[0], src_v[0], &b, &g, &r, yuvconstants); + YuvPixel10_16(src_y[0], src_u[0], src_v[0], &b, &g, &r, yuvconstants); StoreAR30(rgb_buf, b, g, r); - YuvPixel16(src_y[1], src_u[0], src_v[0], &b, &g, &r, yuvconstants); + YuvPixel10_16(src_y[1], src_u[0], src_v[0], &b, &g, &r, yuvconstants); StoreAR30(rgb_buf + 4, b, g, r); src_y += 2; src_u += 1; @@ -1612,11 +2092,141 @@ void I210ToAR30Row_C(const uint16_t* src_y, rgb_buf += 8; // Advance 2 pixels. } if (width & 1) { - YuvPixel16(src_y[0], src_u[0], src_v[0], &b, &g, &r, yuvconstants); + YuvPixel10_16(src_y[0], src_u[0], src_v[0], &b, &g, &r, yuvconstants); StoreAR30(rgb_buf, b, g, r); } } +// 12 bit YUV to 10 bit AR30 +void I212ToAR30Row_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width) { + int x; + int b; + int g; + int r; + for (x = 0; x < width - 1; x += 2) { + YuvPixel12_16(src_y[0], src_u[0], src_v[0], &b, &g, &r, yuvconstants); + StoreAR30(rgb_buf, b, g, r); + YuvPixel12_16(src_y[1], src_u[0], src_v[0], &b, &g, &r, yuvconstants); + StoreAR30(rgb_buf + 4, b, g, r); + src_y += 2; + src_u += 1; + src_v += 1; + rgb_buf += 8; // Advance 2 pixels. + } + if (width & 1) { + YuvPixel12_16(src_y[0], src_u[0], src_v[0], &b, &g, &r, yuvconstants); + StoreAR30(rgb_buf, b, g, r); + } +} + +void I410ToAR30Row_C(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width) { + int x; + int b; + int g; + int r; + for (x = 0; x < width; ++x) { + YuvPixel10_16(src_y[0], src_u[0], src_v[0], &b, &g, &r, yuvconstants); + StoreAR30(rgb_buf, b, g, r); + src_y += 1; + src_u += 1; + src_v += 1; + rgb_buf += 4; // Advance 1 pixel. + } +} + +// P210 has 10 bits in msb of 16 bit NV12 style layout. +void P210ToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + int x; + for (x = 0; x < width - 1; x += 2) { + YuvPixel16_8(src_y[0], src_uv[0], src_uv[1], dst_argb + 0, dst_argb + 1, + dst_argb + 2, yuvconstants); + dst_argb[3] = 255; + YuvPixel16_8(src_y[1], src_uv[0], src_uv[1], dst_argb + 4, dst_argb + 5, + dst_argb + 6, yuvconstants); + dst_argb[7] = 255; + src_y += 2; + src_uv += 2; + dst_argb += 8; // Advance 2 pixels. + } + if (width & 1) { + YuvPixel16_8(src_y[0], src_uv[0], src_uv[1], dst_argb + 0, dst_argb + 1, + dst_argb + 2, yuvconstants); + dst_argb[3] = 255; + } +} + +void P410ToARGBRow_C(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + int x; + for (x = 0; x < width; ++x) { + YuvPixel16_8(src_y[0], src_uv[0], src_uv[1], dst_argb + 0, dst_argb + 1, + dst_argb + 2, yuvconstants); + dst_argb[3] = 255; + src_y += 1; + src_uv += 2; + dst_argb += 4; // Advance 1 pixels. + } +} + +void P210ToAR30Row_C(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + int x; + int b; + int g; + int r; + for (x = 0; x < width - 1; x += 2) { + YuvPixel16_16(src_y[0], src_uv[0], src_uv[1], &b, &g, &r, yuvconstants); + StoreAR30(dst_ar30, b, g, r); + YuvPixel16_16(src_y[1], src_uv[0], src_uv[1], &b, &g, &r, yuvconstants); + StoreAR30(dst_ar30 + 4, b, g, r); + src_y += 2; + src_uv += 2; + dst_ar30 += 8; // Advance 2 pixels. + } + if (width & 1) { + YuvPixel16_16(src_y[0], src_uv[0], src_uv[1], &b, &g, &r, yuvconstants); + StoreAR30(dst_ar30, b, g, r); + } +} + +void P410ToAR30Row_C(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + int x; + int b; + int g; + int r; + for (x = 0; x < width; ++x) { + YuvPixel16_16(src_y[0], src_uv[0], src_uv[1], &b, &g, &r, yuvconstants); + StoreAR30(dst_ar30, b, g, r); + src_y += 1; + src_uv += 2; + dst_ar30 += 4; // Advance 1 pixel. + } +} + // 8 bit YUV to 10 bit AR30 // Uses same code as 10 bit YUV bit shifts the 8 bit values up to 10 bits. void I422ToAR30Row_C(const uint8_t* src_y, @@ -1645,6 +2255,26 @@ void I422ToAR30Row_C(const uint8_t* src_y, } } +void I444AlphaToARGBRow_C(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width) { + int x; + for (x = 0; x < width; ++x) { + YuvPixel(src_y[0], src_u[0], src_v[0], rgb_buf + 0, rgb_buf + 1, + rgb_buf + 2, yuvconstants); + rgb_buf[3] = src_a[0]; + src_y += 1; + src_u += 1; + src_v += 1; + src_a += 1; + rgb_buf += 4; // Advance 1 pixel. + } +} + void I422AlphaToARGBRow_C(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, @@ -1718,8 +2348,10 @@ void I422ToARGB4444Row_C(const uint8_t* src_y, b1 = b1 >> 4; g1 = g1 >> 4; r1 = r1 >> 4; - *(uint32_t*)(dst_argb4444) = b0 | (g0 << 4) | (r0 << 8) | (b1 << 16) | - (g1 << 20) | (r1 << 24) | 0xf000f000; + *(uint16_t*)(dst_argb4444 + 0) = + STATIC_CAST(uint16_t, b0 | (g0 << 4) | (r0 << 8) | 0xf000); + *(uint16_t*)(dst_argb4444 + 2) = + STATIC_CAST(uint16_t, b1 | (g1 << 4) | (r1 << 8) | 0xf000); src_y += 2; src_u += 1; src_v += 1; @@ -1730,7 +2362,8 @@ void I422ToARGB4444Row_C(const uint8_t* src_y, b0 = b0 >> 4; g0 = g0 >> 4; r0 = r0 >> 4; - *(uint16_t*)(dst_argb4444) = b0 | (g0 << 4) | (r0 << 8) | 0xf000; + *(uint16_t*)(dst_argb4444) = + STATIC_CAST(uint16_t, b0 | (g0 << 4) | (r0 << 8) | 0xf000); } } @@ -1756,8 +2389,10 @@ void I422ToARGB1555Row_C(const uint8_t* src_y, b1 = b1 >> 3; g1 = g1 >> 3; r1 = r1 >> 3; - *(uint32_t*)(dst_argb1555) = b0 | (g0 << 5) | (r0 << 10) | (b1 << 16) | - (g1 << 21) | (r1 << 26) | 0x80008000; + *(uint16_t*)(dst_argb1555 + 0) = + STATIC_CAST(uint16_t, b0 | (g0 << 5) | (r0 << 10) | 0x8000); + *(uint16_t*)(dst_argb1555 + 2) = + STATIC_CAST(uint16_t, b1 | (g1 << 5) | (r1 << 10) | 0x8000); src_y += 2; src_u += 1; src_v += 1; @@ -1768,7 +2403,8 @@ void I422ToARGB1555Row_C(const uint8_t* src_y, b0 = b0 >> 3; g0 = g0 >> 3; r0 = r0 >> 3; - *(uint16_t*)(dst_argb1555) = b0 | (g0 << 5) | (r0 << 10) | 0x8000; + *(uint16_t*)(dst_argb1555) = + STATIC_CAST(uint16_t, b0 | (g0 << 5) | (r0 << 10) | 0x8000); } } @@ -1794,8 +2430,10 @@ void I422ToRGB565Row_C(const uint8_t* src_y, b1 = b1 >> 3; g1 = g1 >> 2; r1 = r1 >> 3; - *(uint32_t*)(dst_rgb565) = - b0 | (g0 << 5) | (r0 << 11) | (b1 << 16) | (g1 << 21) | (r1 << 27); + *(uint16_t*)(dst_rgb565 + 0) = + STATIC_CAST(uint16_t, b0 | (g0 << 5) | (r0 << 11)); + *(uint16_t*)(dst_rgb565 + 2) = + STATIC_CAST(uint16_t, b1 | (g1 << 5) | (r1 << 11)); src_y += 2; src_u += 1; src_v += 1; @@ -1806,7 +2444,8 @@ void I422ToRGB565Row_C(const uint8_t* src_y, b0 = b0 >> 3; g0 = g0 >> 2; r0 = r0 >> 3; - *(uint16_t*)(dst_rgb565) = b0 | (g0 << 5) | (r0 << 11); + *(uint16_t*)(dst_rgb565 + 0) = + STATIC_CAST(uint16_t, b0 | (g0 << 5) | (r0 << 11)); } } @@ -1921,8 +2560,12 @@ void NV12ToRGB565Row_C(const uint8_t* src_y, b1 = b1 >> 3; g1 = g1 >> 2; r1 = r1 >> 3; - *(uint32_t*)(dst_rgb565) = - b0 | (g0 << 5) | (r0 << 11) | (b1 << 16) | (g1 << 21) | (r1 << 27); + *(uint16_t*)(dst_rgb565 + 0) = STATIC_CAST(uint16_t, b0) | + STATIC_CAST(uint16_t, g0 << 5) | + STATIC_CAST(uint16_t, r0 << 11); + *(uint16_t*)(dst_rgb565 + 2) = STATIC_CAST(uint16_t, b1) | + STATIC_CAST(uint16_t, g1 << 5) | + STATIC_CAST(uint16_t, r1 << 11); src_y += 2; src_uv += 2; dst_rgb565 += 4; // Advance 2 pixels. @@ -1932,7 +2575,9 @@ void NV12ToRGB565Row_C(const uint8_t* src_y, b0 = b0 >> 3; g0 = g0 >> 2; r0 = r0 >> 3; - *(uint16_t*)(dst_rgb565) = b0 | (g0 << 5) | (r0 << 11); + *(uint16_t*)(dst_rgb565) = STATIC_CAST(uint16_t, b0) | + STATIC_CAST(uint16_t, g0 << 5) | + STATIC_CAST(uint16_t, r0 << 11); } } @@ -2006,18 +2651,21 @@ void I422ToRGBARow_C(const uint8_t* src_y, } } -void I400ToARGBRow_C(const uint8_t* src_y, uint8_t* rgb_buf, int width) { +void I400ToARGBRow_C(const uint8_t* src_y, + uint8_t* rgb_buf, + const struct YuvConstants* yuvconstants, + int width) { int x; for (x = 0; x < width - 1; x += 2) { - YPixel(src_y[0], rgb_buf + 0, rgb_buf + 1, rgb_buf + 2); + YPixel(src_y[0], rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); rgb_buf[3] = 255; - YPixel(src_y[1], rgb_buf + 4, rgb_buf + 5, rgb_buf + 6); + YPixel(src_y[1], rgb_buf + 4, rgb_buf + 5, rgb_buf + 6, yuvconstants); rgb_buf[7] = 255; src_y += 2; rgb_buf += 8; // Advance 2 pixels. } if (width & 1) { - YPixel(src_y[0], rgb_buf + 0, rgb_buf + 1, rgb_buf + 2); + YPixel(src_y[0], rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); rgb_buf[3] = 255; } } @@ -2035,10 +2683,34 @@ void MirrorRow_C(const uint8_t* src, uint8_t* dst, int width) { } } -void MirrorUVRow_C(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { +void MirrorRow_16_C(const uint16_t* src, uint16_t* dst, int width) { + int x; + src += width - 1; + for (x = 0; x < width - 1; x += 2) { + dst[x] = src[0]; + dst[x + 1] = src[-1]; + src -= 2; + } + if (width & 1) { + dst[width - 1] = src[0]; + } +} + +void MirrorUVRow_C(const uint8_t* src_uv, uint8_t* dst_uv, int width) { + int x; + src_uv += (width - 1) << 1; + for (x = 0; x < width; ++x) { + dst_uv[0] = src_uv[0]; + dst_uv[1] = src_uv[1]; + src_uv -= 2; + dst_uv += 2; + } +} + +void MirrorSplitUVRow_C(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { int x; src_uv += (width - 1) << 1; for (x = 0; x < width - 1; x += 2) { @@ -2056,16 +2728,30 @@ void MirrorUVRow_C(const uint8_t* src_uv, void ARGBMirrorRow_C(const uint8_t* src, uint8_t* dst, int width) { int x; - const uint32_t* src32 = (const uint32_t*)(src); - uint32_t* dst32 = (uint32_t*)(dst); - src32 += width - 1; - for (x = 0; x < width - 1; x += 2) { - dst32[x] = src32[0]; - dst32[x + 1] = src32[-1]; - src32 -= 2; + const uint8_t* s = src + (ptrdiff_t)(width - 1) * 4; + uint8_t* d = dst; + for (x = 0; x < width; ++x) { + d[0] = s[0]; + d[1] = s[1]; + d[2] = s[2]; + d[3] = s[3]; + s -= 4; + d += 4; } - if (width & 1) { - dst32[width - 1] = src32[0]; +} + +void RGB24MirrorRow_C(const uint8_t* src_rgb24, uint8_t* dst_rgb24, int width) { + int x; + src_rgb24 += (ptrdiff_t)width * 3 - 3; + for (x = 0; x < width; ++x) { + uint8_t b = src_rgb24[0]; + uint8_t g = src_rgb24[1]; + uint8_t r = src_rgb24[2]; + dst_rgb24[0] = b; + dst_rgb24[1] = g; + dst_rgb24[2] = r; + src_rgb24 -= 3; + dst_rgb24 += 3; } } @@ -2105,6 +2791,111 @@ void MergeUVRow_C(const uint8_t* src_u, } } +void DetileRow_C(const uint8_t* src, + ptrdiff_t src_tile_stride, + uint8_t* dst, + int width) { + int x; + for (x = 0; x < width - 15; x += 16) { + memcpy(dst, src, 16); + dst += 16; + src += src_tile_stride; + } + if (width & 15) { + memcpy(dst, src, width & 15); + } +} + +void DetileRow_16_C(const uint16_t* src, + ptrdiff_t src_tile_stride, + uint16_t* dst, + int width) { + int x; + for (x = 0; x < width - 15; x += 16) { + memcpy(dst, src, 16 * sizeof(uint16_t)); + dst += 16; + src += src_tile_stride; + } + if (width & 15) { + memcpy(dst, src, (width & 15) * sizeof(uint16_t)); + } +} + +void DetileSplitUVRow_C(const uint8_t* src_uv, + ptrdiff_t src_tile_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + int x; + for (x = 0; x < width - 15; x += 16) { + SplitUVRow_C(src_uv, dst_u, dst_v, 8); + dst_u += 8; + dst_v += 8; + src_uv += src_tile_stride; + } + if (width & 15) { + SplitUVRow_C(src_uv, dst_u, dst_v, ((width & 15) + 1) / 2); + } +} + +void DetileToYUY2_C(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width) { + int x; + for (x = 0; x < width - 15; x += 16) { + int i; + for (i = 0; i < 8; i++) { + dst_yuy2[0] = src_y[0]; + dst_yuy2[1] = src_uv[0]; + dst_yuy2[2] = src_y[1]; + dst_yuy2[3] = src_uv[1]; + dst_yuy2 += 4; + src_y += 2; + src_uv += 2; + } + src_y += src_y_tile_stride - 16; + src_uv += src_uv_tile_stride - 16; + } + // Remaining pixels of a partial 16 pixel tile. + for (x = 0; x < (width & 15); x += 2) { + dst_yuy2[0] = src_y[0]; + dst_yuy2[1] = src_uv[0]; + dst_yuy2[2] = src_y[1]; + dst_yuy2[3] = src_uv[1]; + dst_yuy2 += 4; + src_y += 2; + src_uv += 2; + } +} + +// Unpack MT2T into tiled P010 64 pixels at a time. MT2T's bitstream is encoded +// in 80 byte blocks representing 64 pixels each. The first 16 bytes of the +// block contain all of the lower 2 bits of each pixel packed together, and the +// next 64 bytes represent all the upper 8 bits of the pixel. The lower bits are +// packed into 1x4 blocks, whereas the upper bits are packed in normal raster +// order. +void UnpackMT2T_C(const uint8_t* src, uint16_t* dst, size_t size) { + while (size >= 80) { + const uint8_t* src_lower_bits = src; + const uint8_t* src_upper_bits = src + 16; + + for (int j = 0; j < 4; j++) { + for (int k = 0; k < 16; k++) { + *dst++ = ((src_lower_bits[k] >> (j * 2)) & 0x3) << 6 | + (uint16_t)*src_upper_bits << 8 | + (uint16_t)*src_upper_bits >> 2; + src_upper_bits++; + } + } + + src += 80; + size -= 80; + } +} + void SplitRGBRow_C(const uint8_t* src_rgb, uint8_t* dst_r, uint8_t* dst_g, @@ -2133,27 +2924,197 @@ void MergeRGBRow_C(const uint8_t* src_r, } } -// Use scale to convert lsb formats to msb, depending how many bits there are: -// 128 = 9 bits -// 64 = 10 bits -// 16 = 12 bits -// 1 = 16 bits +void SplitARGBRow_C(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width) { + int x; + for (x = 0; x < width; ++x) { + dst_b[x] = src_argb[0]; + dst_g[x] = src_argb[1]; + dst_r[x] = src_argb[2]; + dst_a[x] = src_argb[3]; + src_argb += 4; + } +} + +void MergeARGBRow_C(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width) { + int x; + for (x = 0; x < width; ++x) { + dst_argb[0] = src_b[x]; + dst_argb[1] = src_g[x]; + dst_argb[2] = src_r[x]; + dst_argb[3] = src_a[x]; + dst_argb += 4; + } +} + +void MergeXR30Row_C(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int depth, + int width) { + assert(depth >= 10); + assert(depth <= 16); + int x; + int shift = depth - 10; + uint32_t* dst_ar30_32 = (uint32_t*)dst_ar30; + for (x = 0; x < width; ++x) { + uint32_t r = clamp1023(src_r[x] >> shift); + uint32_t g = clamp1023(src_g[x] >> shift); + uint32_t b = clamp1023(src_b[x] >> shift); + dst_ar30_32[x] = b | (g << 10) | (r << 20) | 0xc0000000; + } +} + +void MergeAR64Row_C(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint16_t* dst_ar64, + int depth, + int width) { + assert(depth >= 1); + assert(depth <= 16); + int x; + int shift = 16 - depth; + int max = (1 << depth) - 1; + for (x = 0; x < width; ++x) { + dst_ar64[0] = STATIC_CAST(uint16_t, ClampMax(src_b[x], max) << shift); + dst_ar64[1] = STATIC_CAST(uint16_t, ClampMax(src_g[x], max) << shift); + dst_ar64[2] = STATIC_CAST(uint16_t, ClampMax(src_r[x], max) << shift); + dst_ar64[3] = STATIC_CAST(uint16_t, ClampMax(src_a[x], max) << shift); + dst_ar64 += 4; + } +} + +void MergeARGB16To8Row_C(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint8_t* dst_argb, + int depth, + int width) { + assert(depth >= 8); + assert(depth <= 16); + int x; + int shift = depth - 8; + for (x = 0; x < width; ++x) { + dst_argb[0] = STATIC_CAST(uint8_t, clamp255(src_b[x] >> shift)); + dst_argb[1] = STATIC_CAST(uint8_t, clamp255(src_g[x] >> shift)); + dst_argb[2] = STATIC_CAST(uint8_t, clamp255(src_r[x] >> shift)); + dst_argb[3] = STATIC_CAST(uint8_t, clamp255(src_a[x] >> shift)); + dst_argb += 4; + } +} + +void MergeXR64Row_C(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint16_t* dst_ar64, + int depth, + int width) { + assert(depth >= 1); + assert(depth <= 16); + int x; + int shift = 16 - depth; + int max = (1 << depth) - 1; + for (x = 0; x < width; ++x) { + dst_ar64[0] = STATIC_CAST(uint16_t, ClampMax(src_b[x], max) << shift); + dst_ar64[1] = STATIC_CAST(uint16_t, ClampMax(src_g[x], max) << shift); + dst_ar64[2] = STATIC_CAST(uint16_t, ClampMax(src_r[x], max) << shift); + dst_ar64[3] = 0xffff; + dst_ar64 += 4; + } +} + +void MergeXRGB16To8Row_C(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_argb, + int depth, + int width) { + assert(depth >= 8); + assert(depth <= 16); + int x; + int shift = depth - 8; + for (x = 0; x < width; ++x) { + dst_argb[0] = STATIC_CAST(uint8_t, clamp255(src_b[x] >> shift)); + dst_argb[1] = STATIC_CAST(uint8_t, clamp255(src_g[x] >> shift)); + dst_argb[2] = STATIC_CAST(uint8_t, clamp255(src_r[x] >> shift)); + dst_argb[3] = 0xff; + dst_argb += 4; + } +} + +void SplitXRGBRow_C(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + int x; + for (x = 0; x < width; ++x) { + dst_b[x] = src_argb[0]; + dst_g[x] = src_argb[1]; + dst_r[x] = src_argb[2]; + src_argb += 4; + } +} + +void MergeXRGBRow_C(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width) { + int x; + for (x = 0; x < width; ++x) { + dst_argb[0] = src_b[x]; + dst_argb[1] = src_g[x]; + dst_argb[2] = src_r[x]; + dst_argb[3] = 255; + dst_argb += 4; + } +} + +// Convert lsb formats to msb, depending on sample depth. void MergeUVRow_16_C(const uint16_t* src_u, const uint16_t* src_v, uint16_t* dst_uv, - int scale, + int depth, int width) { + int shift = 16 - depth; + assert(depth >= 8); + assert(depth <= 16); int x; - for (x = 0; x < width - 1; x += 2) { - dst_uv[0] = src_u[x] * scale; - dst_uv[1] = src_v[x] * scale; - dst_uv[2] = src_u[x + 1] * scale; - dst_uv[3] = src_v[x + 1] * scale; - dst_uv += 4; + for (x = 0; x < width; ++x) { + dst_uv[0] = STATIC_CAST(uint16_t, src_u[x] << shift); + dst_uv[1] = STATIC_CAST(uint16_t, src_v[x] << shift); + dst_uv += 2; } - if (width & 1) { - dst_uv[0] = src_u[width - 1] * scale; - dst_uv[1] = src_v[width - 1] * scale; +} + +// Convert msb formats to lsb, depending on sample depth. +void SplitUVRow_16_C(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width) { + int shift = 16 - depth; + int x; + assert(depth >= 8); + assert(depth <= 16); + for (x = 0; x < width; ++x) { + dst_u[x] = src_uv[0] >> shift; + dst_v[x] = src_uv[1] >> shift; + src_uv += 2; } } @@ -2163,7 +3124,19 @@ void MultiplyRow_16_C(const uint16_t* src_y, int width) { int x; for (x = 0; x < width; ++x) { - dst_y[x] = src_y[x] * scale; + dst_y[x] = STATIC_CAST(uint16_t, src_y[x] * scale); + } +} + +void DivideRow_16_C(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + int x; + // scale can be 65536 so multiply unsigned to avoid signed overflow. + for (x = 0; x < width; ++x) { + dst_y[x] = + STATIC_CAST(uint16_t, ((uint32_t)src_y[x] * (uint32_t)scale) >> 16); } } @@ -2172,26 +3145,50 @@ void MultiplyRow_16_C(const uint16_t* src_y, // 16384 = 10 bits // 4096 = 12 bits // 256 = 16 bits +// TODO(fbarchard): change scale to bits +#define C16TO8(v, scale) \ + clamp255((int32_t)(((uint32_t)(v) * (uint32_t)(scale)) >> 16)) + void Convert16To8Row_C(const uint16_t* src_y, uint8_t* dst_y, int scale, int width) { int x; + assert(scale >= 256); + assert(scale <= 32768); + for (x = 0; x < width; ++x) { - dst_y[x] = clamp255((src_y[x] * scale) >> 16); + dst_y[x] = STATIC_CAST(uint8_t, C16TO8(src_y[x], scale)); } } -// Use scale to convert lsb formats to msb, depending how many bits there are: -// 1024 = 10 bits +// Convert 8 bit values to 10, 12 or 16 bits. void Convert8To16Row_C(const uint8_t* src_y, uint16_t* dst_y, - int scale, + int bits, int width) { int x; - scale *= 0x0101; // replicates the byte. + int shift = 16 - bits; for (x = 0; x < width; ++x) { - dst_y[x] = (src_y[x] * scale) >> 16; + dst_y[x] = (src_y[x] * 0x0101) >> shift; + } +} + +// Use scale to convert J420 to I420 +// scale parameter is 8.8 fixed point but limited to 0 to 255 +// Function is based on DivideRow, but adds a bias +// Does not clamp +void Convert8To8Row_C(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width) { + int x; + assert(scale >= 0); + assert(scale <= 255); + + for (x = 0; x < width; ++x) { + dst_y[x] = ((src_y[x] * scale) >> 8) + bias; } } @@ -2200,7 +3197,7 @@ void CopyRow_C(const uint8_t* src, uint8_t* dst, int count) { } void CopyRow_16_C(const uint16_t* src, uint16_t* dst, int count) { - memcpy(dst, src, count * 2); + memcpy(dst, src, (size_t)count * 2); } void SetRow_C(uint8_t* dst, uint8_t v8, int width) { @@ -2208,10 +3205,9 @@ void SetRow_C(uint8_t* dst, uint8_t v8, int width) { } void ARGBSetRow_C(uint8_t* dst_argb, uint32_t v32, int width) { - uint32_t* d = (uint32_t*)(dst_argb); int x; for (x = 0; x < width; ++x) { - d[x] = v32; + memcpy(dst_argb + x * sizeof v32, &v32, sizeof v32); } } @@ -2224,14 +3220,31 @@ void YUY2ToUVRow_C(const uint8_t* src_yuy2, // Output a row of UV values, filtering 2 rows of YUY2. int x; for (x = 0; x < width; x += 2) { - dst_u[0] = (src_yuy2[1] + src_yuy2[src_stride_yuy2 + 1] + 1) >> 1; - dst_v[0] = (src_yuy2[3] + src_yuy2[src_stride_yuy2 + 3] + 1) >> 1; + const uint8_t* src_yuy2_next = src_yuy2 + src_stride_yuy2; + dst_u[0] = (src_yuy2[1] + src_yuy2_next[1] + 1) >> 1; + dst_v[0] = (src_yuy2[3] + src_yuy2_next[3] + 1) >> 1; src_yuy2 += 4; dst_u += 1; dst_v += 1; } } +// Filter 2 rows of YUY2 UV's (422) into UV (NV12). +void YUY2ToNVUVRow_C(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_uv, + int width) { + // Output a row of UV values, filtering 2 rows of YUY2. + int x; + for (x = 0; x < width; x += 2) { + const uint8_t* src_yuy2_next = src_yuy2 + src_stride_yuy2; + dst_uv[0] = (src_yuy2[1] + src_yuy2_next[1] + 1) >> 1; + dst_uv[1] = (src_yuy2[3] + src_yuy2_next[3] + 1) >> 1; + src_yuy2 += 4; + dst_uv += 2; + } +} + // Copy row of YUY2 UV's (422) into U and V (422). void YUY2ToUV422Row_C(const uint8_t* src_yuy2, uint8_t* dst_u, @@ -2271,8 +3284,9 @@ void UYVYToUVRow_C(const uint8_t* src_uyvy, // Output a row of UV values. int x; for (x = 0; x < width; x += 2) { - dst_u[0] = (src_uyvy[0] + src_uyvy[src_stride_uyvy + 0] + 1) >> 1; - dst_v[0] = (src_uyvy[2] + src_uyvy[src_stride_uyvy + 2] + 1) >> 1; + const uint8_t* src_uyvy_next = src_uyvy + src_stride_uyvy; + dst_u[0] = (src_uyvy[0] + src_uyvy_next[0] + 1) >> 1; + dst_v[0] = (src_uyvy[2] + src_uyvy_next[2] + 1) >> 1; src_uyvy += 4; dst_u += 1; dst_v += 1; @@ -2309,62 +3323,123 @@ void UYVYToYRow_C(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { } } -#define BLEND(f, b, a) (((256 - a) * b) >> 8) + f +#define BLEND(f, b, a) clamp255((((256 - a) * b) >> 8) + f) -// Blend src_argb0 over src_argb1 and store to dst_argb. -// dst_argb may be src_argb0 or src_argb1. +// Blend src_argb over src_argb1 and store to dst_argb. +// dst_argb may be src_argb or src_argb1. // This code mimics the SSSE3 version for better testability. -void ARGBBlendRow_C(const uint8_t* src_argb0, +void ARGBBlendRow_C(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { int x; for (x = 0; x < width - 1; x += 2) { - uint32_t fb = src_argb0[0]; - uint32_t fg = src_argb0[1]; - uint32_t fr = src_argb0[2]; - uint32_t a = src_argb0[3]; + uint32_t fb = src_argb[0]; + uint32_t fg = src_argb[1]; + uint32_t fr = src_argb[2]; + uint32_t a = src_argb[3]; uint32_t bb = src_argb1[0]; uint32_t bg = src_argb1[1]; uint32_t br = src_argb1[2]; - dst_argb[0] = BLEND(fb, bb, a); - dst_argb[1] = BLEND(fg, bg, a); - dst_argb[2] = BLEND(fr, br, a); + dst_argb[0] = STATIC_CAST(uint8_t, BLEND(fb, bb, a)); + dst_argb[1] = STATIC_CAST(uint8_t, BLEND(fg, bg, a)); + dst_argb[2] = STATIC_CAST(uint8_t, BLEND(fr, br, a)); dst_argb[3] = 255u; - fb = src_argb0[4 + 0]; - fg = src_argb0[4 + 1]; - fr = src_argb0[4 + 2]; - a = src_argb0[4 + 3]; + fb = src_argb[4 + 0]; + fg = src_argb[4 + 1]; + fr = src_argb[4 + 2]; + a = src_argb[4 + 3]; bb = src_argb1[4 + 0]; bg = src_argb1[4 + 1]; br = src_argb1[4 + 2]; - dst_argb[4 + 0] = BLEND(fb, bb, a); - dst_argb[4 + 1] = BLEND(fg, bg, a); - dst_argb[4 + 2] = BLEND(fr, br, a); + dst_argb[4 + 0] = STATIC_CAST(uint8_t, BLEND(fb, bb, a)); + dst_argb[4 + 1] = STATIC_CAST(uint8_t, BLEND(fg, bg, a)); + dst_argb[4 + 2] = STATIC_CAST(uint8_t, BLEND(fr, br, a)); dst_argb[4 + 3] = 255u; - src_argb0 += 8; + src_argb += 8; src_argb1 += 8; dst_argb += 8; } if (width & 1) { - uint32_t fb = src_argb0[0]; - uint32_t fg = src_argb0[1]; - uint32_t fr = src_argb0[2]; - uint32_t a = src_argb0[3]; + uint32_t fb = src_argb[0]; + uint32_t fg = src_argb[1]; + uint32_t fr = src_argb[2]; + uint32_t a = src_argb[3]; uint32_t bb = src_argb1[0]; uint32_t bg = src_argb1[1]; uint32_t br = src_argb1[2]; - dst_argb[0] = BLEND(fb, bb, a); - dst_argb[1] = BLEND(fg, bg, a); - dst_argb[2] = BLEND(fr, br, a); + dst_argb[0] = STATIC_CAST(uint8_t, BLEND(fb, bb, a)); + dst_argb[1] = STATIC_CAST(uint8_t, BLEND(fg, bg, a)); + dst_argb[2] = STATIC_CAST(uint8_t, BLEND(fr, br, a)); dst_argb[3] = 255u; } } #undef BLEND -#define UBLEND(f, b, a) (((a)*f) + ((255 - a) * b) + 255) >> 8 +// Blend unattenuated src_argb0 over src_argb1 and store to dst_argb. +void ARGBAlphaBlendRow_C(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + int x; + for (x = 0; x < width; ++x) { + int sa = src_argb0[3]; + int da = src_argb1[3]; + if (da == 0) { + dst_argb[0] = src_argb0[0]; + dst_argb[1] = src_argb0[1]; + dst_argb[2] = src_argb0[2]; + dst_argb[3] = STATIC_CAST(uint8_t, sa); + } else if (sa == 0) { + dst_argb[0] = src_argb1[0]; + dst_argb[1] = src_argb1[1]; + dst_argb[2] = src_argb1[2]; + dst_argb[3] = STATIC_CAST(uint8_t, da); + } else { + int dst_alpha = da + sa - da * sa / 255; + int alpha_ratio = sa * 255 / dst_alpha; + dst_argb[0] = STATIC_CAST( + uint8_t, + (src_argb1[0] * (255 - alpha_ratio) + src_argb0[0] * alpha_ratio) / + 255); + dst_argb[1] = STATIC_CAST( + uint8_t, + (src_argb1[1] * (255 - alpha_ratio) + src_argb0[1] * alpha_ratio) / + 255); + dst_argb[2] = STATIC_CAST( + uint8_t, + (src_argb1[2] * (255 - alpha_ratio) + src_argb0[2] * alpha_ratio) / + 255); + dst_argb[3] = STATIC_CAST(uint8_t, dst_alpha); + } + src_argb0 += 4; + src_argb1 += 4; + dst_argb += 4; + } +} + +void ARGBOrRow_C(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + const uint8_t v0 = value & 0xff; + const uint8_t v1 = (value >> 8) & 0xff; + const uint8_t v2 = (value >> 16) & 0xff; + const uint8_t v3 = (value >> 24) & 0xff; + int i; + for (i = 0; i < width; ++i) { + dst_argb[0] = src_argb[0] | v0; + dst_argb[1] = src_argb[1] | v1; + dst_argb[2] = src_argb[2] | v2; + dst_argb[3] = src_argb[3] | v3; + src_argb += 4; + dst_argb += 4; + } +} + +#define UBLEND(f, b, a) (((a) * f) + ((255 - a) * b) + 255) >> 8 void BlendPlaneRow_C(const uint8_t* src0, const uint8_t* src1, const uint8_t* alpha, @@ -2385,10 +3460,9 @@ void BlendPlaneRow_C(const uint8_t* src0, } #undef UBLEND -#define ATTENUATE(f, a) (a | (a << 8)) * (f | (f << 8)) >> 24 +#define ATTENUATE(f, a) (f * a + 255) >> 8 // Multiply source RGB by alpha and store to destination. -// This code mimics the SSSE3 version for better testability. void ARGBAttenuateRow_C(const uint8_t* src_argb, uint8_t* dst_argb, int width) { int i; for (i = 0; i < width - 1; i += 2) { @@ -2399,7 +3473,7 @@ void ARGBAttenuateRow_C(const uint8_t* src_argb, uint8_t* dst_argb, int width) { dst_argb[0] = ATTENUATE(b, a); dst_argb[1] = ATTENUATE(g, a); dst_argb[2] = ATTENUATE(r, a); - dst_argb[3] = a; + dst_argb[3] = STATIC_CAST(uint8_t, a); b = src_argb[4]; g = src_argb[5]; r = src_argb[6]; @@ -2407,7 +3481,7 @@ void ARGBAttenuateRow_C(const uint8_t* src_argb, uint8_t* dst_argb, int width) { dst_argb[4] = ATTENUATE(b, a); dst_argb[5] = ATTENUATE(g, a); dst_argb[6] = ATTENUATE(r, a); - dst_argb[7] = a; + dst_argb[7] = STATIC_CAST(uint8_t, a); src_argb += 8; dst_argb += 8; } @@ -2420,7 +3494,7 @@ void ARGBAttenuateRow_C(const uint8_t* src_argb, uint8_t* dst_argb, int width) { dst_argb[0] = ATTENUATE(b, a); dst_argb[1] = ATTENUATE(g, a); dst_argb[2] = ATTENUATE(r, a); - dst_argb[3] = a; + dst_argb[3] = STATIC_CAST(uint8_t, a); } } #undef ATTENUATE @@ -2472,6 +3546,10 @@ const uint32_t fixed_invtbl8[256] = { T(0xfc), T(0xfd), T(0xfe), 0x01000100}; #undef T +// This code mimics the Intel SIMD version for better testability. +#define UNATTENUATE(f, ia) clamp255(((f | (f << 8)) * ia) >> 16) + +// mimics the Intel SIMD code for exactness. void ARGBUnattenuateRow_C(const uint8_t* src_argb, uint8_t* dst_argb, int width) { @@ -2482,14 +3560,12 @@ void ARGBUnattenuateRow_C(const uint8_t* src_argb, uint32_t r = src_argb[2]; const uint32_t a = src_argb[3]; const uint32_t ia = fixed_invtbl8[a] & 0xffff; // 8.8 fixed point - b = (b * ia) >> 8; - g = (g * ia) >> 8; - r = (r * ia) >> 8; + // Clamping should not be necessary but is free in assembly. - dst_argb[0] = clamp255(b); - dst_argb[1] = clamp255(g); - dst_argb[2] = clamp255(r); - dst_argb[3] = a; + dst_argb[0] = STATIC_CAST(uint8_t, UNATTENUATE(b, ia)); + dst_argb[1] = STATIC_CAST(uint8_t, UNATTENUATE(g, ia)); + dst_argb[2] = STATIC_CAST(uint8_t, UNATTENUATE(r, ia)); + dst_argb[3] = STATIC_CAST(uint8_t, a); src_argb += 4; dst_argb += 4; } @@ -2519,13 +3595,24 @@ void CumulativeSumToAverageRow_C(const int32_t* tl, int area, uint8_t* dst, int count) { - float ooa = 1.0f / area; + float ooa; int i; + assert(area != 0); + + ooa = 1.0f / STATIC_CAST(float, area); for (i = 0; i < count; ++i) { - dst[0] = (uint8_t)((bl[w + 0] + tl[0] - bl[0] - tl[w + 0]) * ooa); - dst[1] = (uint8_t)((bl[w + 1] + tl[1] - bl[1] - tl[w + 1]) * ooa); - dst[2] = (uint8_t)((bl[w + 2] + tl[2] - bl[2] - tl[w + 2]) * ooa); - dst[3] = (uint8_t)((bl[w + 3] + tl[3] - bl[3] - tl[w + 3]) * ooa); + dst[0] = + (uint8_t)(STATIC_CAST(float, bl[w + 0] + tl[0] - bl[0] - tl[w + 0]) * + ooa); + dst[1] = + (uint8_t)(STATIC_CAST(float, bl[w + 1] + tl[1] - bl[1] - tl[w + 1]) * + ooa); + dst[2] = + (uint8_t)(STATIC_CAST(float, bl[w + 2] + tl[2] - bl[2] - tl[w + 2]) * + ooa); + dst[3] = + (uint8_t)(STATIC_CAST(float, bl[w + 3] + tl[3] - bl[3] - tl[w + 3]) * + ooa); dst += 4; tl += 4; bl += 4; @@ -2548,7 +3635,8 @@ void ARGBAffineRow_C(const uint8_t* src_argb, int x = (int)(uv[0]); int y = (int)(uv[1]); *(uint32_t*)(dst_argb) = - *(const uint32_t*)(src_argb + y * src_argb_stride + x * 4); + *(const uint32_t*)(src_argb + (ptrdiff_t)y * src_argb_stride + + (ptrdiff_t)x * 4); dst_argb += 4; uv[0] += uv_dudv[2]; uv[1] += uv_dudv[3]; @@ -2556,26 +3644,90 @@ void ARGBAffineRow_C(const uint8_t* src_argb, } // Blend 2 rows into 1. -static void HalfRow_C(const uint8_t* src_uv, - ptrdiff_t src_uv_stride, - uint8_t* dst_uv, - int width) { +void HalfRow_C(const uint8_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int width) { int x; for (x = 0; x < width; ++x) { dst_uv[x] = (src_uv[x] + src_uv[src_uv_stride + x] + 1) >> 1; } } -static void HalfRow_16_C(const uint16_t* src_uv, - ptrdiff_t src_uv_stride, - uint16_t* dst_uv, - int width) { +void HalfRow_16_C(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint16_t* dst_uv, + int width) { int x; for (x = 0; x < width; ++x) { dst_uv[x] = (src_uv[x] + src_uv[src_uv_stride + x] + 1) >> 1; } } +void HalfRow_16To8_C(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + int x; + for (x = 0; x < width; ++x) { + dst_uv[x] = STATIC_CAST( + uint8_t, + C16TO8((src_uv[x] + src_uv[src_uv_stride + x] + 1) >> 1, scale)); + } +} + +void HalfWidthRow_16To8_C(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const uint16_t* s = src_uv; + const uint16_t* t = src_uv + src_uv_stride; + int x; + for (x = 0; x < width - 1; x += 2) { + dst_uv[0] = STATIC_CAST( + uint8_t, C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale)); + dst_uv[1] = STATIC_CAST( + uint8_t, C16TO8((s[2] + s[3] + t[2] + t[3] + 2) >> 2, scale)); + dst_uv += 2; + s += 4; + t += 4; + } + if (width & 1) { + dst_uv[0] = STATIC_CAST( + uint8_t, C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale)); + } +} + +void HalfWidthRow_16To8_Odd_C(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const uint16_t* s = src_uv; + const uint16_t* t = src_uv + src_uv_stride; + int x; + width -= 1; + for (x = 0; x < width - 1; x += 2) { + dst_uv[0] = STATIC_CAST( + uint8_t, C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale)); + dst_uv[1] = STATIC_CAST( + uint8_t, C16TO8((s[2] + s[3] + t[2] + t[3] + 2) >> 2, scale)); + dst_uv += 2; + s += 4; + t += 4; + } + if (width & 1) { + dst_uv[0] = STATIC_CAST( + uint8_t, C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale)); + dst_uv += 1; + s += 2; + t += 2; + } + dst_uv[0] = STATIC_CAST(uint8_t, C16TO8((s[0] + t[0] + 1) >> 1, scale)); +} + // C version 2x2 -> 2x1. void InterpolateRow_C(uint8_t* dst_ptr, const uint8_t* src_ptr, @@ -2586,6 +3738,9 @@ void InterpolateRow_C(uint8_t* dst_ptr, int y0_fraction = 256 - y1_fraction; const uint8_t* src_ptr1 = src_ptr + src_stride; int x; + assert(source_y_fraction >= 0); + assert(source_y_fraction < 256); + if (y1_fraction == 0) { memcpy(dst_ptr, src_ptr, width); return; @@ -2594,21 +3749,17 @@ void InterpolateRow_C(uint8_t* dst_ptr, HalfRow_C(src_ptr, src_stride, dst_ptr, width); return; } - for (x = 0; x < width - 1; x += 2) { - dst_ptr[0] = - (src_ptr[0] * y0_fraction + src_ptr1[0] * y1_fraction + 128) >> 8; - dst_ptr[1] = - (src_ptr[1] * y0_fraction + src_ptr1[1] * y1_fraction + 128) >> 8; - src_ptr += 2; - src_ptr1 += 2; - dst_ptr += 2; - } - if (width & 1) { - dst_ptr[0] = - (src_ptr[0] * y0_fraction + src_ptr1[0] * y1_fraction + 128) >> 8; + for (x = 0; x < width; ++x) { + dst_ptr[0] = STATIC_CAST( + uint8_t, + (src_ptr[0] * y0_fraction + src_ptr1[0] * y1_fraction + 128) >> 8); + ++src_ptr; + ++src_ptr1; + ++dst_ptr; } } +// C version 2x2 -> 2x1. void InterpolateRow_16_C(uint16_t* dst_ptr, const uint16_t* src_ptr, ptrdiff_t src_stride, @@ -2618,23 +3769,24 @@ void InterpolateRow_16_C(uint16_t* dst_ptr, int y0_fraction = 256 - y1_fraction; const uint16_t* src_ptr1 = src_ptr + src_stride; int x; - if (source_y_fraction == 0) { - memcpy(dst_ptr, src_ptr, width * 2); + assert(source_y_fraction >= 0); + assert(source_y_fraction < 256); + + if (y1_fraction == 0) { + memcpy(dst_ptr, src_ptr, (size_t)width * 2); return; } - if (source_y_fraction == 128) { + if (y1_fraction == 128) { HalfRow_16_C(src_ptr, src_stride, dst_ptr, width); return; } - for (x = 0; x < width - 1; x += 2) { - dst_ptr[0] = (src_ptr[0] * y0_fraction + src_ptr1[0] * y1_fraction) >> 8; - dst_ptr[1] = (src_ptr[1] * y0_fraction + src_ptr1[1] * y1_fraction) >> 8; - src_ptr += 2; - src_ptr1 += 2; - dst_ptr += 2; - } - if (width & 1) { - dst_ptr[0] = (src_ptr[0] * y0_fraction + src_ptr1[0] * y1_fraction) >> 8; + for (x = 0; x < width; ++x) { + dst_ptr[0] = STATIC_CAST( + uint16_t, + (src_ptr[0] * y0_fraction + src_ptr1[0] * y1_fraction + 128) >> 8); + ++src_ptr; + ++src_ptr1; + ++dst_ptr; } } @@ -2743,10 +3895,10 @@ void ARGBPolynomialRow_C(const uint8_t* src_argb, dr += poly[14] * r3; da += poly[15] * a3; - dst_argb[0] = Clamp((int32_t)(db)); - dst_argb[1] = Clamp((int32_t)(dg)); - dst_argb[2] = Clamp((int32_t)(dr)); - dst_argb[3] = Clamp((int32_t)(da)); + dst_argb[0] = STATIC_CAST(uint8_t, Clamp((int32_t)(db))); + dst_argb[1] = STATIC_CAST(uint8_t, Clamp((int32_t)(dg))); + dst_argb[2] = STATIC_CAST(uint8_t, Clamp((int32_t)(dr))); + dst_argb[3] = STATIC_CAST(uint8_t, Clamp((int32_t)(da))); src_argb += 4; dst_argb += 4; } @@ -2774,9 +3926,15 @@ void HalfFloatRow_C(const uint16_t* src, float scale, int width) { int i; - float mult = 1.9259299444e-34f * scale; + // Multiply by scale first, then by 2^-112 to move the exponent into half + // float position. Doing the scale and bias as two multiplies keeps every + // intermediate normal; a combined (scale * 2^-112) constant is a denormal + // for scale < 2^-14 (e.g. 1/65535), which costs a microcode assist per + // multiply on Intel CPUs (50x slower). 2^-112 is a power of 2 so the + // result is identical to the single multiply when that was representable. + const float kScaleBias = 1.9259299444e-34f; // 2^-112 for (i = 0; i < width; ++i) { - float value = src[i] * mult; + float value = (src[i] * scale) * kScaleBias; dst[i] = (uint16_t)((*(const uint32_alias_t*)&value) >> 13); } } @@ -2785,7 +3943,7 @@ void ByteToFloatRow_C(const uint8_t* src, float* dst, float scale, int width) { int i; for (i = 0; i < width; ++i) { float value = src[i] * scale; - dst[i] = value; + memcpy(&dst[i], &value, sizeof(value)); } } @@ -2873,8 +4031,8 @@ void ARGBCopyYToAlphaRow_C(const uint8_t* src, uint8_t* dst, int width) { // Maximum temporary width for wrappers to process at a time, in pixels. #define MAXTWIDTH 2048 -#if !(defined(_MSC_VER) && defined(_M_IX86)) && \ - defined(HAS_I422TORGB565ROW_SSSE3) +#if !(defined(_MSC_VER) && !defined(__clang__) && defined(_M_IX86)) && \ + defined(HAS_I422TORGB565ROW_SSSE3) && !defined(LIBYUV_ENABLE_ROWWIN) // row_win.cc has asm version, but GCC uses 2 step wrapper. void I422ToRGB565Row_SSSE3(const uint8_t* src_y, const uint8_t* src_u, @@ -2886,7 +4044,7 @@ void I422ToRGB565Row_SSSE3(const uint8_t* src_y, while (width > 0) { int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; I422ToARGBRow_SSSE3(src_y, src_u, src_v, row, yuvconstants, twidth); - ARGBToRGB565Row_SSE2(row, dst_rgb565, twidth); + ARGBToRGB565Row_C(row, dst_rgb565, twidth); src_y += twidth; src_u += twidth / 2; src_v += twidth / 2; @@ -2908,7 +4066,7 @@ void I422ToARGB1555Row_SSSE3(const uint8_t* src_y, while (width > 0) { int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; I422ToARGBRow_SSSE3(src_y, src_u, src_v, row, yuvconstants, twidth); - ARGBToARGB1555Row_SSE2(row, dst_argb1555, twidth); + ARGBToARGB1555Row_C(row, dst_argb1555, twidth); src_y += twidth; src_u += twidth / 2; src_v += twidth / 2; @@ -2930,7 +4088,7 @@ void I422ToARGB4444Row_SSSE3(const uint8_t* src_y, while (width > 0) { int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; I422ToARGBRow_SSSE3(src_y, src_u, src_v, row, yuvconstants, twidth); - ARGBToARGB4444Row_SSE2(row, dst_argb4444, twidth); + ARGBToARGB4444Row_C(row, dst_argb4444, twidth); src_y += twidth; src_u += twidth / 2; src_v += twidth / 2; @@ -2951,7 +4109,7 @@ void NV12ToRGB565Row_SSSE3(const uint8_t* src_y, while (width > 0) { int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; NV12ToARGBRow_SSSE3(src_y, src_uv, row, yuvconstants, twidth); - ARGBToRGB565Row_SSE2(row, dst_rgb565, twidth); + ARGBToRGB565Row_C(row, dst_rgb565, twidth); src_y += twidth; src_uv += twidth; dst_rgb565 += twidth * 2; @@ -3000,7 +4158,7 @@ void NV21ToRGB24Row_SSSE3(const uint8_t* src_y, } #endif -#if defined(HAS_NV12TORGB24ROW_AVX2) +#if defined(HAS_NV12TOARGBROW_AVX2) && defined(HAS_ARGBTORGB24ROW_AVX2) void NV12ToRGB24Row_AVX2(const uint8_t* src_y, const uint8_t* src_uv, uint8_t* dst_rgb24, @@ -3011,11 +4169,7 @@ void NV12ToRGB24Row_AVX2(const uint8_t* src_y, while (width > 0) { int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; NV12ToARGBRow_AVX2(src_y, src_uv, row, yuvconstants, twidth); -#if defined(HAS_ARGBTORGB24ROW_AVX2) ARGBToRGB24Row_AVX2(row, dst_rgb24, twidth); -#else - ARGBToRGB24Row_SSSE3(row, dst_rgb24, twidth); -#endif src_y += twidth; src_uv += twidth; dst_rgb24 += twidth * 3; @@ -3024,7 +4178,7 @@ void NV12ToRGB24Row_AVX2(const uint8_t* src_y, } #endif -#if defined(HAS_NV21TORGB24ROW_AVX2) +#if defined(HAS_NV21TOARGBROW_AVX2) && defined(HAS_ARGBTORGB24ROW_AVX2) void NV21ToRGB24Row_AVX2(const uint8_t* src_y, const uint8_t* src_vu, uint8_t* dst_rgb24, @@ -3035,11 +4189,7 @@ void NV21ToRGB24Row_AVX2(const uint8_t* src_y, while (width > 0) { int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; NV21ToARGBRow_AVX2(src_y, src_vu, row, yuvconstants, twidth); -#if defined(HAS_ARGBTORGB24ROW_AVX2) ARGBToRGB24Row_AVX2(row, dst_rgb24, twidth); -#else - ARGBToRGB24Row_SSSE3(row, dst_rgb24, twidth); -#endif src_y += twidth; src_vu += twidth; dst_rgb24 += twidth * 3; @@ -3048,7 +4198,78 @@ void NV21ToRGB24Row_AVX2(const uint8_t* src_y, } #endif -#if defined(HAS_I422TORGB565ROW_AVX2) +#if defined(HAS_I422TOARGBROW_AVX512BW) && defined(HAS_ARGBTORGB565ROW_AVX512BW) +void I422ToRGB565Row_AVX512BW(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + I422ToARGBRow_AVX512BW(src_y, src_u, src_v, row, yuvconstants, twidth); + ARGBToRGB565Row_AVX512BW(row, dst_rgb565, twidth); + src_y += twidth; + src_u += twidth / 2; + src_v += twidth / 2; + dst_rgb565 += twidth * 2; + width -= twidth; + } +} +#endif + +#if defined(HAS_I422TOARGBROW_AVX512BW) && defined(HAS_ARGBTOARGB1555ROW_AVX2) +void I422ToARGB1555Row_AVX512BW(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + I422ToARGBRow_AVX512BW(src_y, src_u, src_v, row, yuvconstants, twidth); + if (IS_ALIGNED(twidth, 8)) { + ARGBToARGB1555Row_AVX2(row, dst_argb1555, twidth); + } else { + ARGBToARGB1555Row_Any_AVX2(row, dst_argb1555, twidth); + } + src_y += twidth; + src_u += twidth / 2; + src_v += twidth / 2; + dst_argb1555 += twidth * 2; + width -= twidth; + } +} +#endif + +#if defined(HAS_I422TOARGBROW_AVX512BW) && defined(HAS_ARGBTOARGB4444ROW_AVX2) +void I422ToARGB4444Row_AVX512BW(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + I422ToARGBRow_AVX512BW(src_y, src_u, src_v, row, yuvconstants, twidth); + if (IS_ALIGNED(twidth, 8)) { + ARGBToARGB4444Row_AVX2(row, dst_argb4444, twidth); + } else { + ARGBToARGB4444Row_Any_AVX2(row, dst_argb4444, twidth); + } + src_y += twidth; + src_u += twidth / 2; + src_v += twidth / 2; + dst_argb4444 += twidth * 2; + width -= twidth; + } +} +#endif + +#if defined(HAS_I422TOARGBROW_AVX2) && defined(HAS_ARGBTORGB565ROW_AVX2) void I422ToRGB565Row_AVX2(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, @@ -3059,11 +4280,7 @@ void I422ToRGB565Row_AVX2(const uint8_t* src_y, while (width > 0) { int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; I422ToARGBRow_AVX2(src_y, src_u, src_v, row, yuvconstants, twidth); -#if defined(HAS_ARGBTORGB565ROW_AVX2) ARGBToRGB565Row_AVX2(row, dst_rgb565, twidth); -#else - ARGBToRGB565Row_SSE2(row, dst_rgb565, twidth); -#endif src_y += twidth; src_u += twidth / 2; src_v += twidth / 2; @@ -3073,7 +4290,7 @@ void I422ToRGB565Row_AVX2(const uint8_t* src_y, } #endif -#if defined(HAS_I422TOARGB1555ROW_AVX2) +#if defined(HAS_I422TOARGBROW_AVX2) && defined(HAS_ARGBTOARGB1555ROW_AVX2) void I422ToARGB1555Row_AVX2(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, @@ -3085,11 +4302,7 @@ void I422ToARGB1555Row_AVX2(const uint8_t* src_y, while (width > 0) { int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; I422ToARGBRow_AVX2(src_y, src_u, src_v, row, yuvconstants, twidth); -#if defined(HAS_ARGBTOARGB1555ROW_AVX2) ARGBToARGB1555Row_AVX2(row, dst_argb1555, twidth); -#else - ARGBToARGB1555Row_SSE2(row, dst_argb1555, twidth); -#endif src_y += twidth; src_u += twidth / 2; src_v += twidth / 2; @@ -3099,7 +4312,7 @@ void I422ToARGB1555Row_AVX2(const uint8_t* src_y, } #endif -#if defined(HAS_I422TOARGB4444ROW_AVX2) +#if defined(HAS_I422TOARGBROW_AVX2) && defined(HAS_ARGBTOARGB4444ROW_AVX2) void I422ToARGB4444Row_AVX2(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, @@ -3111,11 +4324,7 @@ void I422ToARGB4444Row_AVX2(const uint8_t* src_y, while (width > 0) { int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; I422ToARGBRow_AVX2(src_y, src_u, src_v, row, yuvconstants, twidth); -#if defined(HAS_ARGBTOARGB4444ROW_AVX2) ARGBToARGB4444Row_AVX2(row, dst_argb4444, twidth); -#else - ARGBToARGB4444Row_SSE2(row, dst_argb4444, twidth); -#endif src_y += twidth; src_u += twidth / 2; src_v += twidth / 2; @@ -3125,8 +4334,8 @@ void I422ToARGB4444Row_AVX2(const uint8_t* src_y, } #endif -#if defined(HAS_I422TORGB24ROW_AVX2) -void I422ToRGB24Row_AVX2(const uint8_t* src_y, +#if defined(HAS_I444TOARGBROW_AVX2) && defined(HAS_ARGBTORGB24ROW_AVX2) +void I444ToRGB24Row_AVX2(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_rgb24, @@ -3136,22 +4345,18 @@ void I422ToRGB24Row_AVX2(const uint8_t* src_y, SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); while (width > 0) { int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; - I422ToARGBRow_AVX2(src_y, src_u, src_v, row, yuvconstants, twidth); -#if defined(HAS_ARGBTORGB24ROW_AVX2) + I444ToARGBRow_AVX2(src_y, src_u, src_v, row, yuvconstants, twidth); ARGBToRGB24Row_AVX2(row, dst_rgb24, twidth); -#else - ARGBToRGB24Row_SSSE3(row, dst_rgb24, twidth); -#endif src_y += twidth; - src_u += twidth / 2; - src_v += twidth / 2; + src_u += twidth; + src_v += twidth; dst_rgb24 += twidth * 3; width -= twidth; } } #endif -#if defined(HAS_NV12TORGB565ROW_AVX2) +#if defined(HAS_NV12TOARGBROW_AVX2) && defined(HAS_ARGBTORGB565ROW_AVX2) void NV12ToRGB565Row_AVX2(const uint8_t* src_y, const uint8_t* src_uv, uint8_t* dst_rgb565, @@ -3162,11 +4367,7 @@ void NV12ToRGB565Row_AVX2(const uint8_t* src_y, while (width > 0) { int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; NV12ToARGBRow_AVX2(src_y, src_uv, row, yuvconstants, twidth); -#if defined(HAS_ARGBTORGB565ROW_AVX2) ARGBToRGB565Row_AVX2(row, dst_rgb565, twidth); -#else - ARGBToRGB565Row_SSE2(row, dst_rgb565, twidth); -#endif src_y += twidth; src_uv += twidth; dst_rgb565 += twidth * 2; @@ -3178,9 +4379,6 @@ void NV12ToRGB565Row_AVX2(const uint8_t* src_y, float ScaleSumSamples_C(const float* src, float* dst, float scale, int width) { float fsum = 0.f; int i; -#if defined(__clang__) -#pragma clang loop vectorize_width(4) -#endif for (i = 0; i < width; ++i) { float v = *src++; fsum += v * v; @@ -3211,8 +4409,9 @@ void ScaleSamples_C(const float* src, float* dst, float scale, int width) { void GaussRow_C(const uint32_t* src, uint16_t* dst, int width) { int i; for (i = 0; i < width; ++i) { - *dst++ = - (src[0] + src[1] * 4 + src[2] * 6 + src[3] * 4 + src[4] + 128) >> 8; + *dst++ = STATIC_CAST( + uint16_t, + (src[0] + src[1] * 4 + src[2] * 6 + src[3] * 4 + src[4] + 128) >> 8); ++src; } } @@ -3231,6 +4430,29 @@ void GaussCol_C(const uint16_t* src0, } } +void GaussRow_F32_C(const float* src, float* dst, int width) { + int i; + for (i = 0; i < width; ++i) { + *dst++ = (src[0] + src[1] * 4 + src[2] * 6 + src[3] * 4 + src[4]) * + (1.0f / 256.0f); + ++src; + } +} + +// filter 5 rows with 1, 4, 6, 4, 1 coefficients to produce 1 row. +void GaussCol_F32_C(const float* src0, + const float* src1, + const float* src2, + const float* src3, + const float* src4, + float* dst, + int width) { + int i; + for (i = 0; i < width; ++i) { + *dst++ = *src0++ + *src1++ * 4 + *src2++ * 6 + *src3++ * 4 + *src4++; + } +} + // Convert biplanar NV21 to packed YUV24 void NV21ToYUV24Row_C(const uint8_t* src_y, const uint8_t* src_vu, @@ -3256,29 +4478,28 @@ void NV21ToYUV24Row_C(const uint8_t* src_y, } // Filter 2 rows of AYUV UV's (444) into UV (420). +// AYUV is VUYA in memory. UV for NV12 is UV order in memory. void AYUVToUVRow_C(const uint8_t* src_ayuv, int src_stride_ayuv, uint8_t* dst_uv, int width) { // Output a row of UV values, filtering 2x2 rows of AYUV. int x; - for (x = 0; x < width; x += 2) { - dst_uv[0] = (src_ayuv[1] + src_ayuv[5] + src_ayuv[src_stride_ayuv + 1] + - src_ayuv[src_stride_ayuv + 5] + 2) >> - 2; - dst_uv[1] = (src_ayuv[0] + src_ayuv[4] + src_ayuv[src_stride_ayuv + 0] + - src_ayuv[src_stride_ayuv + 4] + 2) >> - 2; + for (x = 0; x < width - 1; x += 2) { + const uint8_t* src_ayuv_next = src_ayuv + src_stride_ayuv; + dst_uv[0] = + (src_ayuv[1] + src_ayuv[5] + src_ayuv_next[1] + src_ayuv_next[5] + 2) >> + 2; + dst_uv[1] = + (src_ayuv[0] + src_ayuv[4] + src_ayuv_next[0] + src_ayuv_next[4] + 2) >> + 2; src_ayuv += 8; dst_uv += 2; } if (width & 1) { - dst_uv[0] = (src_ayuv[0] + src_ayuv[0] + src_ayuv[src_stride_ayuv + 0] + - src_ayuv[src_stride_ayuv + 0] + 2) >> - 2; - dst_uv[1] = (src_ayuv[1] + src_ayuv[1] + src_ayuv[src_stride_ayuv + 1] + - src_ayuv[src_stride_ayuv + 1] + 2) >> - 2; + const uint8_t* src_ayuv_next = src_ayuv + src_stride_ayuv; + dst_uv[0] = (src_ayuv[1] + src_ayuv_next[1] + 1) >> 1; + dst_uv[1] = (src_ayuv[0] + src_ayuv_next[0] + 1) >> 1; } } @@ -3289,23 +4510,21 @@ void AYUVToVURow_C(const uint8_t* src_ayuv, int width) { // Output a row of VU values, filtering 2x2 rows of AYUV. int x; - for (x = 0; x < width; x += 2) { - dst_vu[0] = (src_ayuv[0] + src_ayuv[4] + src_ayuv[src_stride_ayuv + 0] + - src_ayuv[src_stride_ayuv + 4] + 2) >> - 2; - dst_vu[1] = (src_ayuv[1] + src_ayuv[5] + src_ayuv[src_stride_ayuv + 1] + - src_ayuv[src_stride_ayuv + 5] + 2) >> - 2; + for (x = 0; x < width - 1; x += 2) { + const uint8_t* src_ayuv_next = src_ayuv + src_stride_ayuv; + dst_vu[0] = + (src_ayuv[0] + src_ayuv[4] + src_ayuv_next[0] + src_ayuv_next[4] + 2) >> + 2; + dst_vu[1] = + (src_ayuv[1] + src_ayuv[5] + src_ayuv_next[1] + src_ayuv_next[5] + 2) >> + 2; src_ayuv += 8; dst_vu += 2; } if (width & 1) { - dst_vu[0] = (src_ayuv[0] + src_ayuv[0] + src_ayuv[src_stride_ayuv + 0] + - src_ayuv[src_stride_ayuv + 0] + 2) >> - 2; - dst_vu[1] = (src_ayuv[1] + src_ayuv[1] + src_ayuv[src_stride_ayuv + 1] + - src_ayuv[src_stride_ayuv + 1] + 2) >> - 2; + const uint8_t* src_ayuv_next = src_ayuv + src_stride_ayuv; + dst_vu[0] = (src_ayuv[0] + src_ayuv_next[0] + 1) >> 1; + dst_vu[1] = (src_ayuv[1] + src_ayuv_next[1] + 1) >> 1; } } @@ -3332,6 +4551,638 @@ void SwapUVRow_C(const uint8_t* src_uv, uint8_t* dst_vu, int width) { } } +void HalfMergeUVRow_C(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width) { + int x; + for (x = 0; x < width - 1; x += 2) { + const uint8_t* src_u_next = src_u + src_stride_u; + dst_uv[0] = (src_u[0] + src_u[1] + src_u_next[0] + src_u_next[1] + 2) >> 2; + const uint8_t* src_v_next = src_v + src_stride_v; + dst_uv[1] = (src_v[0] + src_v[1] + src_v_next[0] + src_v_next[1] + 2) >> 2; + src_u += 2; + src_v += 2; + dst_uv += 2; + } + if (width & 1) { + const uint8_t* src_u_next = src_u + src_stride_u; + dst_uv[0] = (src_u[0] + src_u_next[0] + 1) >> 1; + const uint8_t* src_v_next = src_v + src_stride_v; + dst_uv[1] = (src_v[0] + src_v_next[0] + 1) >> 1; + } +} + +#undef STATIC_CAST + +void RGBToYMatrixRow_C(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB24ToARGBRow_C(src_rgb, row, twidth); + ARGBToYMatrixRow_C(row, dst_y, twidth, c); + src_rgb += twidth * 3; + dst_y += twidth; + width -= twidth; + } +} + +void RGBToUVMatrixRow_C(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB24ToARGBRow_C(src_rgb, row, twidth); + RGB24ToARGBRow_C(src_rgb + src_stride_rgb, row + MAXTWIDTH * 4, twidth); + ARGBToUVMatrixRow_C(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_rgb += twidth * 3; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} + +void RGBToUV444MatrixRow_C(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB24ToARGBRow_C(src_rgb, row, twidth); + ARGBToUV444MatrixRow_C(row, dst_u, dst_v, twidth, c); + src_rgb += twidth * 3; + dst_u += twidth; + dst_v += twidth; + width -= twidth; + } +} + +#if defined(HAS_ARGBTOYMATRIXROW_SSSE3) && defined(HAS_RGB24TOARGBROW_SSSE3) +void RGBToYMatrixRow_SSSE3(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB24ToARGBRow_SSSE3(src_rgb, row, twidth); + ARGBToYMatrixRow_SSSE3(row, dst_y, twidth, c); + src_rgb += twidth * 3; + dst_y += twidth; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) && defined(HAS_RGB24TOARGBROW_AVX2) +void RGBToYMatrixRow_AVX2(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB24ToARGBRow_AVX2(src_rgb, row, twidth); + ARGBToYMatrixRow_AVX2(row, dst_y, twidth, c); + src_rgb += twidth * 3; + dst_y += twidth; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_SSSE3) && defined(HAS_RGB24TOARGBROW_SSSE3) +void RGBToUVMatrixRow_SSSE3(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB24ToARGBRow_SSSE3(src_rgb, row, twidth); + RGB24ToARGBRow_SSSE3(src_rgb + src_stride_rgb, row + MAXTWIDTH * 4, twidth); + ARGBToUVMatrixRow_SSSE3(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_rgb += twidth * 3; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) && defined(HAS_RGB24TOARGBROW_AVX2) +void RGBToUVMatrixRow_AVX2(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB24ToARGBRow_AVX2(src_rgb, row, twidth); + RGB24ToARGBRow_AVX2(src_rgb + src_stride_rgb, row + MAXTWIDTH * 4, twidth); + ARGBToUVMatrixRow_AVX2(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_rgb += twidth * 3; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) && \ + defined(HAS_RGB24TOARGBROW_AVX512BW) +void RGBToUVMatrixRow_AVX512BW(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB24ToARGBRow_AVX512BW(src_rgb, row, twidth); + RGB24ToARGBRow_AVX512BW(src_rgb + src_stride_rgb, row + MAXTWIDTH * 4, + twidth); + ARGBToUVMatrixRow_AVX512BW(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_rgb += twidth * 3; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGBTOUV444MATRIXROW_SSSE3) && defined(HAS_RGB24TOARGBROW_SSSE3) +void RGBToUV444MatrixRow_SSSE3(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB24ToARGBRow_SSSE3(src_rgb, row, twidth); + ARGBToUV444MatrixRow_SSSE3(row, dst_u, dst_v, twidth, c); + src_rgb += twidth * 3; + dst_u += twidth; + dst_v += twidth; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX2) && defined(HAS_RGB24TOARGBROW_AVX2) +void RGBToUV444MatrixRow_AVX2(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB24ToARGBRow_AVX2(src_rgb, row, twidth); + ARGBToUV444MatrixRow_AVX2(row, dst_u, dst_v, twidth, c); + src_rgb += twidth * 3; + dst_u += twidth; + dst_v += twidth; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGBTOUV444MATRIXROW_AVX512BW) && \ + defined(HAS_RGB24TOARGBROW_AVX512BW) +void RGBToUV444MatrixRow_AVX512BW(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB24ToARGBRow_AVX512BW(src_rgb, row, twidth); + ARGBToUV444MatrixRow_AVX512BW(row, dst_u, dst_v, twidth, c); + src_rgb += twidth * 3; + dst_u += twidth; + dst_v += twidth; + width -= twidth; + } +} +#endif + +void RGB565ToYMatrixRow_C(const uint8_t* src_rgb565, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB565ToARGBRow_C(src_rgb565, row, twidth); + ARGBToYMatrixRow_C(row, dst_y, twidth, c); + src_rgb565 += twidth * 2; + dst_y += twidth; + width -= twidth; + } +} + +void RGB565ToUVMatrixRow_C(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB565ToARGBRow_C(src_rgb565, row, twidth); + RGB565ToARGBRow_C(src_rgb565 + src_stride_rgb565, row + MAXTWIDTH * 4, + twidth); + ARGBToUVMatrixRow_C(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_rgb565 += twidth * 2; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} + +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) && defined(HAS_RGB565TOARGBROW_AVX2) +void RGB565ToYMatrixRow_AVX2(const uint8_t* src_rgb565, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB565ToARGBRow_AVX2(src_rgb565, row, twidth); + ARGBToYMatrixRow_AVX2(row, dst_y, twidth, c); + src_rgb565 += twidth * 2; + dst_y += twidth; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) && defined(HAS_RGB565TOARGBROW_AVX2) +void RGB565ToUVMatrixRow_AVX2(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB565ToARGBRow_AVX2(src_rgb565, row, twidth); + RGB565ToARGBRow_AVX2(src_rgb565 + src_stride_rgb565, row + MAXTWIDTH * 4, + twidth); + ARGBToUVMatrixRow_AVX2(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_rgb565 += twidth * 2; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} +#endif + +#if defined(HAS_RGB565TOARGBROW_NEON) && defined(HAS_ARGBTOYMATRIXROW_NEON) +void RGB565ToYMatrixRow_NEON(const uint8_t* src_rgb565, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB565ToARGBRow_NEON(src_rgb565, row, twidth); + ARGBToYMatrixRow_NEON(row, dst_y, twidth, c); + src_rgb565 += twidth * 2; + dst_y += twidth; + width -= twidth; + } +} +#endif + +#if defined(HAS_RGB565TOARGBROW_NEON) && defined(HAS_ARGBTOUVMATRIXROW_NEON) +void RGB565ToUVMatrixRow_NEON(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + RGB565ToARGBRow_NEON(src_rgb565, row, twidth); + RGB565ToARGBRow_NEON(src_rgb565 + src_stride_rgb565, row + MAXTWIDTH * 4, + twidth); + ARGBToUVMatrixRow_NEON(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_rgb565 += twidth * 2; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} +#endif + +void ARGB1555ToYMatrixRow_C(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB1555ToARGBRow_C(src_argb1555, row, twidth); + ARGBToYMatrixRow_C(row, dst_y, twidth, c); + src_argb1555 += twidth * 2; + dst_y += twidth; + width -= twidth; + } +} + +void ARGB1555ToUVMatrixRow_C(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB1555ToARGBRow_C(src_argb1555, row, twidth); + ARGB1555ToARGBRow_C(src_argb1555 + src_stride_argb1555, row + MAXTWIDTH * 4, + twidth); + ARGBToUVMatrixRow_C(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_argb1555 += twidth * 2; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} + +void ARGB4444ToYMatrixRow_C(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB4444ToARGBRow_C(src_argb4444, row, twidth); + ARGBToYMatrixRow_C(row, dst_y, twidth, c); + src_argb4444 += twidth * 2; + dst_y += twidth; + width -= twidth; + } +} + +void ARGB4444ToUVMatrixRow_C(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB4444ToARGBRow_C(src_argb4444, row, twidth); + ARGB4444ToARGBRow_C(src_argb4444 + src_stride_argb4444, row + MAXTWIDTH * 4, + twidth); + ARGBToUVMatrixRow_C(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_argb4444 += twidth * 2; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} + +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) +#if defined(HAS_ARGB1555TOARGBROW_AVX2) +void ARGB1555ToYMatrixRow_AVX2(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB1555ToARGBRow_AVX2(src_argb1555, row, twidth); + ARGBToYMatrixRow_AVX2(row, dst_y, twidth, c); + src_argb1555 += twidth * 2; + dst_y += twidth; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGB4444TOARGBROW_AVX2) +void ARGB4444ToYMatrixRow_AVX2(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB4444ToARGBRow_AVX2(src_argb4444, row, twidth); + ARGBToYMatrixRow_AVX2(row, dst_y, twidth, c); + src_argb4444 += twidth * 2; + dst_y += twidth; + width -= twidth; + } +} +#endif +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_AVX2) +#if defined(HAS_ARGB1555TOARGBROW_AVX2) +void ARGB1555ToUVMatrixRow_AVX2(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB1555ToARGBRow_AVX2(src_argb1555, row, twidth); + ARGB1555ToARGBRow_AVX2(src_argb1555 + src_stride_argb1555, + row + MAXTWIDTH * 4, twidth); + ARGBToUVMatrixRow_AVX2(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_argb1555 += twidth * 2; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGB4444TOARGBROW_AVX2) +void ARGB4444ToUVMatrixRow_AVX2(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB4444ToARGBRow_AVX2(src_argb4444, row, twidth); + ARGB4444ToARGBRow_AVX2(src_argb4444 + src_stride_argb4444, + row + MAXTWIDTH * 4, twidth); + ARGBToUVMatrixRow_AVX2(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_argb4444 += twidth * 2; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} +#endif +#endif + +#if defined(HAS_ARGBTOYMATRIXROW_NEON) && defined(HAS_ARGB1555TOARGBROW_NEON) +void ARGB1555ToYMatrixRow_NEON(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB1555ToARGBRow_NEON(src_argb1555, row, twidth); + ARGBToYMatrixRow_NEON(row, dst_y, twidth, c); + src_argb1555 += twidth * 2; + dst_y += twidth; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGBTOYMATRIXROW_NEON) && defined(HAS_ARGB4444TOARGBROW_NEON) +void ARGB4444ToYMatrixRow_NEON(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB4444ToARGBRow_NEON(src_argb4444, row, twidth); + ARGBToYMatrixRow_NEON(row, dst_y, twidth, c); + src_argb4444 += twidth * 2; + dst_y += twidth; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) && defined(HAS_ARGB1555TOARGBROW_NEON) +void ARGB1555ToUVMatrixRow_NEON(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB1555ToARGBRow_NEON(src_argb1555, row, twidth); + ARGB1555ToARGBRow_NEON(src_argb1555 + src_stride_argb1555, + row + MAXTWIDTH * 4, twidth); + ARGBToUVMatrixRow_NEON(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_argb1555 += twidth * 2; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) && defined(HAS_ARGB4444TOARGBROW_NEON) +void ARGB4444ToUVMatrixRow_NEON(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + SIMD_ALIGNED(uint8_t row[MAXTWIDTH * 4 * 2]); + while (width > 0) { + int twidth = width > MAXTWIDTH ? MAXTWIDTH : width; + ARGB4444ToARGBRow_NEON(src_argb4444, row, twidth); + ARGB4444ToARGBRow_NEON(src_argb4444 + src_stride_argb4444, + row + MAXTWIDTH * 4, twidth); + ARGBToUVMatrixRow_NEON(row, MAXTWIDTH * 4, dst_u, dst_v, twidth, c); + src_argb4444 += twidth * 2; + dst_u += twidth / 2; + dst_v += twidth / 2; + width -= twidth; + } +} +#endif + +#if defined(HAS_RGB565TOYROW_AVX2) && defined(HAS_RGB565TOYMATRIXROW_AVX2) +void RGB565ToYRow_AVX2(const uint8_t* src_rgb565, uint8_t* dst_y, int width) { + RGB565ToYMatrixRow_AVX2(src_rgb565, dst_y, width, &kArgbI601Constants); +} +#endif + +#if defined(HAS_ARGB1555TOYROW_AVX2) && defined(HAS_ARGB1555TOYMATRIXROW_AVX2) +void ARGB1555ToYRow_AVX2(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width) { + ARGB1555ToYMatrixRow_AVX2(src_argb1555, dst_y, width, &kArgbI601Constants); +} +#endif + +#if defined(HAS_ARGB4444TOYROW_AVX2) && defined(HAS_ARGB4444TOYMATRIXROW_AVX2) +void ARGB4444ToYRow_AVX2(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width) { + ARGB4444ToYMatrixRow_AVX2(src_argb4444, dst_y, width, &kArgbI601Constants); +} +#endif + +#if defined(HAS_RGB565TOUVROW_AVX2) && defined(HAS_RGB565TOUVMATRIXROW_AVX2) +void RGB565ToUVRow_AVX2(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + RGB565ToUVMatrixRow_AVX2(src_rgb565, src_stride_rgb565, dst_u, dst_v, width, + &kArgbI601Constants); +} +#endif + +#if defined(HAS_ARGB1555TOUVROW_AVX2) && defined(HAS_ARGB1555TOUVMATRIXROW_AVX2) +void ARGB1555ToUVRow_AVX2(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + ARGB1555ToUVMatrixRow_AVX2(src_argb1555, src_stride_argb1555, dst_u, dst_v, + width, &kArgbI601Constants); +} +#endif + +#if defined(HAS_ARGB4444TOUVROW_AVX2) && defined(HAS_ARGB4444TOUVMATRIXROW_AVX2) +void ARGB4444ToUVRow_AVX2(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + ARGB4444ToUVMatrixRow_AVX2(src_argb4444, src_stride_argb4444, dst_u, dst_v, + width, &kArgbI601Constants); +} +#endif + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/source/row_gcc.cc b/libs/libyuv/source/row_gcc.cc index ae672d625c..3abe073b02 100644 --- a/libs/libyuv/source/row_gcc.cc +++ b/libs/libyuv/source/row_gcc.cc @@ -8,6 +8,9 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include // For memcpy + +#include "libyuv/convert_from_argb.h" // For ArgbConstants #include "libyuv/row.h" #ifdef __cplusplus @@ -15,88 +18,114 @@ namespace libyuv { extern "C" { #endif +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + // This module is for GCC x86 and x64. -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__)) && \ + !defined(LIBYUV_ENABLE_ROWWIN) -#if defined(HAS_ARGBTOYROW_SSSE3) || defined(HAS_ARGBGRAYROW_SSSE3) - -// Constants for ARGB -static const vec8 kARGBToY = {13, 65, 33, 0, 13, 65, 33, 0, - 13, 65, 33, 0, 13, 65, 33, 0}; - -// JPeg full range. -static const vec8 kARGBToYJ = {15, 75, 38, 0, 15, 75, 38, 0, - 15, 75, 38, 0, 15, 75, 38, 0}; -#endif // defined(HAS_ARGBTOYROW_SSSE3) || defined(HAS_ARGBGRAYROW_SSSE3) - -#if defined(HAS_ARGBTOYROW_SSSE3) || defined(HAS_I422TOARGBROW_SSSE3) - -static const vec8 kARGBToU = {112, -74, -38, 0, 112, -74, -38, 0, - 112, -74, -38, 0, 112, -74, -38, 0}; - -static const vec8 kARGBToUJ = {127, -84, -43, 0, 127, -84, -43, 0, - 127, -84, -43, 0, 127, -84, -43, 0}; - -static const vec8 kARGBToV = {-18, -94, 112, 0, -18, -94, 112, 0, - -18, -94, 112, 0, -18, -94, 112, 0}; - -static const vec8 kARGBToVJ = {-20, -107, 127, 0, -20, -107, 127, 0, - -20, -107, 127, 0, -20, -107, 127, 0}; - -// Constants for BGRA -static const vec8 kBGRAToY = {0, 33, 65, 13, 0, 33, 65, 13, - 0, 33, 65, 13, 0, 33, 65, 13}; - -static const vec8 kBGRAToU = {0, -38, -74, 112, 0, -38, -74, 112, - 0, -38, -74, 112, 0, -38, -74, 112}; - -static const vec8 kBGRAToV = {0, 112, -94, -18, 0, 112, -94, -18, - 0, 112, -94, -18, 0, 112, -94, -18}; - -// Constants for ABGR -static const vec8 kABGRToY = {33, 65, 13, 0, 33, 65, 13, 0, - 33, 65, 13, 0, 33, 65, 13, 0}; - -static const vec8 kABGRToU = {-38, -74, 112, 0, -38, -74, 112, 0, - -38, -74, 112, 0, -38, -74, 112, 0}; - -static const vec8 kABGRToV = {112, -94, -18, 0, 112, -94, -18, 0, - 112, -94, -18, 0, 112, -94, -18, 0}; - -// Constants for RGBA. -static const vec8 kRGBAToY = {0, 13, 65, 33, 0, 13, 65, 33, - 0, 13, 65, 33, 0, 13, 65, 33}; - -static const vec8 kRGBAToU = {0, 112, -74, -38, 0, 112, -74, -38, - 0, 112, -74, -38, 0, 112, -74, -38}; - -static const vec8 kRGBAToV = {0, -18, -94, 112, 0, -18, -94, 112, - 0, -18, -94, 112, 0, -18, -94, 112}; - -static const uvec8 kAddY16 = {16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, - 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u}; - -// 7 bit fixed point 0.5. -static const vec16 kAddYJ64 = {64, 64, 64, 64, 64, 64, 64, 64}; - -static const uvec8 kAddUV128 = {128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, - 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u}; - -static const uvec16 kAddUVJ128 = {0x8080u, 0x8080u, 0x8080u, 0x8080u, - 0x8080u, 0x8080u, 0x8080u, 0x8080u}; -#endif // defined(HAS_ARGBTOYROW_SSSE3) || defined(HAS_I422TOARGBROW_SSSE3) - -#ifdef HAS_RGB24TOARGBROW_SSSE3 +// Note: for avx and avx512 declare clobber as xmm registers due to +// clang for windows needing to preserve xmm registers but not saving +// them if declared as ymm or zmm. +#if defined(HAS_RGB24TOARGBROW_SSSE3) || defined(HAS_RGB24TOARGBROW_AVX2) || \ + defined(HAS_RGB24TOARGBROW_AVX512BW) || \ + defined(HAS_RGBTOYMATRIXROW_AVX512BW) // Shuffle table for converting RGB24 to ARGB. -static const uvec8 kShuffleMaskRGB24ToARGB = { - 0u, 1u, 2u, 12u, 3u, 4u, 5u, 13u, 6u, 7u, 8u, 14u, 9u, 10u, 11u, 15u}; +static const uvec8 kShuffleMaskRGB24ToARGB[2] = { + {0u, 1u, 2u, 128u, 3u, 4u, 5u, 128u, 6u, 7u, 8u, 128u, 9u, 10u, 11u, 128u}, + {4u, 5u, 6u, 128u, 7u, 8u, 9u, 128u, 10u, 11u, 12u, 128u, 13u, 14u, 15u, + 128u}}; +#endif // defined(HAS_RGB24TOARGBROW_SSSE3) || + // defined(HAS_RGB24TOARGBROW_AVX2) || + // defined(HAS_RGB24TOARGBROW_AVX512BW) || + // defined(HAS_RGBTOYMATRIXROW_AVX512BW) +#if defined(HAS_RAWTOARGBROW_SSSE3) || defined(HAS_RAWTOARGBROW_AVX2) // Shuffle table for converting RAW to ARGB. -static const uvec8 kShuffleMaskRAWToARGB = {2u, 1u, 0u, 12u, 5u, 4u, 3u, 13u, - 8u, 7u, 6u, 14u, 11u, 10u, 9u, 15u}; +static const uvec8 kShuffleMaskRAWToARGB = { + 2u, 1u, 0u, 128u, 5u, 4u, 3u, 128u, 8u, 7u, 6u, 128u, 11u, 10u, 9u, 128u}; +// Shuffle table for converting RAW to ARGB. Last 12 +static const uvec8 kShuffleMaskRAWToARGB_0 = {6u, 5u, 4u, 128u, 9u, 8u, + 7u, 128u, 12u, 11u, 10u, 128u, + 15u, 14u, 13u, 128u}; +#endif // defined(HAS_RAWTOARGBROW_SSSE3) || defined(HAS_RAWTOARGBROW_AVX2) +#if defined(HAS_RAWTOARGBROW_AVX512BW) +static const uvec8 kShuffleMaskRAWToARGB_AVX512BW[2] = { + {2u, 1u, 0u, 128u, 5u, 4u, 3u, 128u, 8u, 7u, 6u, 128u, 11u, 10u, 9u, 128u}, + {6u, 5u, 4u, 128u, 9u, 8u, 7u, 128u, 12u, 11u, 10u, 128u, 15u, 14u, 13u, + 128u}}; +#endif // defined(HAS_RAWTOARGBROW_AVX512BW) +#if defined(HAS_RAWTORGB24ROW_AVX2) || defined(HAS_RAWTORGB24ROW_AVX512BW) +static const uvec8 kShuffleMaskRAWToRGB24_AVX2[2] = { + {2u, 1u, 0u, 5u, 4u, 3u, 8u, 7u, 6u, 11u, 10u, 9u, 128u, 128u, 128u, 128u}, + {6u, 5u, 4u, 9u, 8u, 7u, 12u, 11u, 10u, 15u, 14u, 13u, 128u, 128u, 128u, + 128u}}; +#endif // defined(HAS_RAWTORGB24ROW_AVX2) || + // defined(HAS_RAWTORGB24ROW_AVX512BW) +#if defined(HAS_RAWTORGB24ROW_AVX2) +static const uint32_t kPermd0_AVX2[8] = {0, 1, 2, 4, 5, 6, 3, 7}; +static const uint32_t kPermd1_AVX2[8] = {2, 4, 5, 6, 3, 7, 0, 1}; +static const uint32_t kPermd2_AVX2[8] = {5, 6, 3, 7, 0, 1, 2, 4}; +#endif // defined(HAS_RAWTORGB24ROW_AVX2) +#if defined(HAS_RAWTORGB24ROW_AVX512BW) || \ + defined(HAS_ARGBTORGB24ROW_AVX512BW) || \ + defined(HAS_ARGBTORAWROW_AVX512BW) +static const uint32_t kPermdRGB24_0_AVX512BW[16] = { + 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 16, 17, 18, 20}; +static const uint32_t kPermdRGB24_1_AVX512BW[16] = { + 5, 6, 8, 9, 10, 12, 13, 14, 16, 17, 18, 20, 21, 22, 24, 25}; +static const uint32_t kPermdRGB24_2_AVX512BW[16] = { + 10, 12, 13, 14, 16, 17, 18, 20, 21, 22, 24, 25, 26, 28, 29, 30}; +#endif // defined(HAS_RAWTORGB24ROW_AVX512BW) || + // defined(HAS_ARGBTORGB24ROW_AVX512BW) || + // defined(HAS_ARGBTORAWROW_AVX512BW) +#if defined(HAS_RAWTORGB24ROW_AVX512VBMI) +static const uint8_t kPermRAWToRGB24_0[64] = { + 0x02, 0x01, 0x00, 0x05, 0x04, 0x03, 0x08, 0x07, 0x06, 0x0b, 0x0a, + 0x09, 0x0e, 0x0d, 0x0c, 0x11, 0x10, 0x0f, 0x14, 0x13, 0x12, 0x17, + 0x16, 0x15, 0x1a, 0x19, 0x18, 0x1d, 0x1c, 0x1b, 0x20, 0x1f, 0x1e, + 0x23, 0x22, 0x21, 0x26, 0x25, 0x24, 0x29, 0x28, 0x27, 0x2c, 0x2b, + 0x2a, 0x2f, 0x2e, 0x2d, 0x32, 0x31, 0x30, 0x35, 0x34, 0x33, 0x38, + 0x37, 0x36, 0x3b, 0x3a, 0x39, 0x3e, 0x3d, 0x3c, 0x41}; +static const uint8_t kPermRAWToRGB24_1[64] = { + 0x00, 0x7f, 0x04, 0x03, 0x02, 0x07, 0x06, 0x05, 0x0a, 0x09, 0x08, + 0x0d, 0x0c, 0x0b, 0x10, 0x0f, 0x0e, 0x13, 0x12, 0x11, 0x16, 0x15, + 0x14, 0x19, 0x18, 0x17, 0x1c, 0x1b, 0x1a, 0x1f, 0x1e, 0x1d, 0x22, + 0x21, 0x20, 0x25, 0x24, 0x23, 0x28, 0x27, 0x26, 0x2b, 0x2a, 0x29, + 0x2e, 0x2d, 0x2c, 0x31, 0x30, 0x2f, 0x34, 0x33, 0x32, 0x37, 0x36, + 0x35, 0x3a, 0x39, 0x38, 0x3d, 0x3c, 0x3b, 0x00, 0x3f}; +static const uint8_t kPermRAWToRGB24_2[64] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, + 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, + 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, + 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, + 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x40, 0x3f}; +static const uint8_t kPermRAWToRGB24_3[64] = { + 0x3e, 0x43, 0x42, 0x41, 0x46, 0x45, 0x44, 0x49, 0x48, 0x47, 0x4c, + 0x4b, 0x4a, 0x4f, 0x4e, 0x4d, 0x52, 0x51, 0x50, 0x55, 0x54, 0x53, + 0x58, 0x57, 0x56, 0x5b, 0x5a, 0x59, 0x5e, 0x5d, 0x5c, 0x61, 0x60, + 0x5f, 0x64, 0x63, 0x62, 0x67, 0x66, 0x65, 0x6a, 0x69, 0x68, 0x6d, + 0x6c, 0x6b, 0x70, 0x6f, 0x6e, 0x73, 0x72, 0x71, 0x76, 0x75, 0x74, + 0x79, 0x78, 0x77, 0x7c, 0x7b, 0x7a, 0x7f, 0x7e, 0x7d}; +#endif // defined(HAS_RAWTORGB24ROW_AVX512VBMI) +#if defined(HAS_RAWTORGBAROW_AVX2) +// Shuffle table for converting RAW to RGBA. +static const uvec8 kShuffleMaskRAWToRGBA_AVX2[2] = { + {128u, 2u, 1u, 0u, 128u, 5u, 4u, 3u, 128u, 8u, 7u, 6u, 128u, 11u, 10u, 9u}, + {128u, 6u, 5u, 4u, 128u, 9u, 8u, 7u, 128u, 12u, 11u, 10u, 128u, 15u, 14u, + 13u}}; +#endif // defined(HAS_RAWTORGBAROW_AVX2) + +#if defined(HAS_RAWTORGB24ROW_SSSE3) // Shuffle table for converting RAW to RGB24. First 8. static const uvec8 kShuffleMaskRAWToRGB24_0 = { 2u, 1u, 0u, 5u, 4u, 3u, 8u, 7u, @@ -111,177 +140,503 @@ static const uvec8 kShuffleMaskRAWToRGB24_1 = { static const uvec8 kShuffleMaskRAWToRGB24_2 = { 8u, 7u, 12u, 11u, 10u, 15u, 14u, 13u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u}; +#endif // defined(HAS_RAWTORGB24ROW_SSSE3) // Shuffle table for converting ARGB to RGB24. -static const uvec8 kShuffleMaskARGBToRGB24 = { - 0u, 1u, 2u, 4u, 5u, 6u, 8u, 9u, 10u, 12u, 13u, 14u, 128u, 128u, 128u, 128u}; +// and for I422ToRGB24. First 8 + next 4 +static const uvec8 kShuffleMaskARGBToRGB24[2] = { + {0u, 1u, 2u, 4u, 5u, 6u, 8u, 9u, 10u, 12u, 13u, 14u, 128u, 128u, 128u, + 128u}, + {0u, 1u, 2u, 4u, 5u, 6u, 8u, 9u, 128u, 128u, 128u, 128u, 10u, 12u, 13u, + 14u}}; // Shuffle table for converting ARGB to RAW. static const uvec8 kShuffleMaskARGBToRAW = { 2u, 1u, 0u, 6u, 5u, 4u, 10u, 9u, 8u, 14u, 13u, 12u, 128u, 128u, 128u, 128u}; -// Shuffle table for converting ARGBToRGB24 for I422ToRGB24. First 8 + next 4 -static const uvec8 kShuffleMaskARGBToRGB24_0 = { - 0u, 1u, 2u, 4u, 5u, 6u, 8u, 9u, 128u, 128u, 128u, 128u, 10u, 12u, 13u, 14u}; - // YUY2 shuf 16 Y to 32 Y. -static const lvec8 kShuffleYUY2Y = {0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, - 10, 12, 12, 14, 14, 0, 0, 2, 2, 4, 4, - 6, 6, 8, 8, 10, 10, 12, 12, 14, 14}; +static const vec8 kShuffleYUY2Y = {0, 0, 2, 2, 4, 4, 6, 6, + 8, 8, 10, 10, 12, 12, 14, 14}; // YUY2 shuf 8 UV to 16 UV. -static const lvec8 kShuffleYUY2UV = {1, 3, 1, 3, 5, 7, 5, 7, 9, 11, 9, - 11, 13, 15, 13, 15, 1, 3, 1, 3, 5, 7, - 5, 7, 9, 11, 9, 11, 13, 15, 13, 15}; +static const vec8 kShuffleYUY2UV = {1, 3, 1, 3, 5, 7, 5, 7, + 9, 11, 9, 11, 13, 15, 13, 15}; // UYVY shuf 16 Y to 32 Y. -static const lvec8 kShuffleUYVYY = {1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11, - 11, 13, 13, 15, 15, 1, 1, 3, 3, 5, 5, - 7, 7, 9, 9, 11, 11, 13, 13, 15, 15}; +static const vec8 kShuffleUYVYY = {1, 1, 3, 3, 5, 5, 7, 7, + 9, 9, 11, 11, 13, 13, 15, 15}; // UYVY shuf 8 UV to 16 UV. -static const lvec8 kShuffleUYVYUV = {0, 2, 0, 2, 4, 6, 4, 6, 8, 10, 8, - 10, 12, 14, 12, 14, 0, 2, 0, 2, 4, 6, - 4, 6, 8, 10, 8, 10, 12, 14, 12, 14}; +static const vec8 kShuffleUYVYUV = {0, 2, 0, 2, 4, 6, 4, 6, + 8, 10, 8, 10, 12, 14, 12, 14}; // NV21 shuf 8 VU to 16 UV. static const lvec8 kShuffleNV21 = { 1, 0, 1, 0, 3, 2, 3, 2, 5, 4, 5, 4, 7, 6, 7, 6, 1, 0, 1, 0, 3, 2, 3, 2, 5, 4, 5, 4, 7, 6, 7, 6, }; -#endif // HAS_RGB24TOARGBROW_SSSE3 -#ifdef HAS_J400TOARGBROW_SSE2 -void J400ToARGBRow_SSE2(const uint8_t* src_y, uint8_t* dst_argb, int width) { +#if defined(HAS_J400TOARGBROW_AVX2) || defined(HAS_J400TOARGBROW_AVX512BW) +static const uint8_t kShuffleMaskJ400ToARGB[64] = { + 0u, 0u, 0u, 128u, 1u, 1u, 1u, 128u, 2u, 2u, 2u, 128u, 3u, 3u, + 3u, 128u, 4u, 4u, 4u, 128u, 5u, 5u, 5u, 128u, 6u, 6u, 6u, 128u, + 7u, 7u, 7u, 128u, 8u, 8u, 8u, 128u, 9u, 9u, 9u, 128u, 10u, 10u, + 10u, 128u, 11u, 11u, 11u, 128u, 12u, 12u, 12u, 128u, 13u, 13u, 13u, 128u, + 14u, 14u, 14u, 128u, 15u, 15u, 15u, 128u}; +#endif // defined(HAS_J400TOARGBROW_AVX2) || + // defined(HAS_J400TOARGBROW_AVX512BW) + +#ifdef HAS_J400TOARGBROW_AVX2 +void J400ToARGBRow_AVX2(const uint8_t* src_y, uint8_t* dst_argb, int width) { asm volatile( - "pcmpeqb %%xmm5,%%xmm5 \n" - "pslld $0x18,%%xmm5 \n" + "vpcmpeqb %%ymm7,%%ymm7,%%ymm7 \n" + "vpslld $0x18,%%ymm7,%%ymm7 \n" + "vmovdqu (%3),%%ymm5 \n" + "vmovdqu 0x20(%3),%%ymm6 \n" LABELALIGN - "1: \n" - "movq (%0),%%xmm0 \n" - "lea 0x8(%0),%0 \n" - "punpcklbw %%xmm0,%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "punpcklwd %%xmm0,%%xmm0 \n" - "punpckhwd %%xmm1,%%xmm1 \n" - "por %%xmm5,%%xmm0 \n" - "por %%xmm5,%%xmm1 \n" - "movdqu %%xmm0,(%1) \n" - "movdqu %%xmm1,0x10(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - : "+r"(src_y), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - ::"memory", - "cc", "xmm0", "xmm1", "xmm5"); + "1: \n" + "vbroadcasti128 (%0),%%ymm0 \n" + "vpshufb %%ymm5,%%ymm0,%%ymm1 \n" + "vpshufb %%ymm6,%%ymm0,%%ymm2 \n" + "vpor %%ymm7,%%ymm1,%%ymm1 \n" + "vpor %%ymm7,%%ymm2,%%ymm2 \n" + "vmovdqu %%ymm1,(%1) \n" + "vmovdqu %%ymm2,0x20(%1) \n" + "lea 0x10(%0),%0 \n" + "lea 0x40(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(kShuffleMaskJ400ToARGB) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm5", "xmm6", "xmm7"); } -#endif // HAS_J400TOARGBROW_SSE2 +#endif // HAS_J400TOARGBROW_AVX2 + +#ifdef HAS_J400TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void J400ToARGBRow_AVX512BW(const uint8_t* src_y, + uint8_t* dst_argb, + int width) { + uintptr_t temp; + asm volatile( + "vpternlogd $0xff,%%zmm16,%%zmm16,%%zmm16 \n" // 0xffffffff + "vpslld $0x18,%%zmm16,%%zmm16 \n" // 0xff000000 + "vmovdqu64 %[shuf],%%zmm5 \n" + "sub $0x20,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vbroadcasti32x4 (%0),%%zmm0 \n" + "vbroadcasti32x4 0x10(%0),%%zmm1 \n" + "vpshufb %%zmm5,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm5,%%zmm1,%%zmm1 \n" + "vpord %%zmm16,%%zmm0,%%zmm0 \n" + "vpord %%zmm16,%%zmm1,%%zmm1 \n" + "vmovdqu64 %%zmm0,(%1) \n" + "vmovdqu64 %%zmm1,0x40(%1) \n" + "lea 0x20(%0),%0 \n" + "lea 0x80(%1),%1 \n" + "sub $0x20,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "mov $-1,%k[temp] \n" + "bzhi %k2,%k[temp],%k[temp] \n" + "kmovd %k[temp],%%k1 \n" + "kshiftrd $16,%%k1,%%k2 \n" + "vmovdqu8 (%0),%%ymm0%{%%k1%}%{z%} \n" + "vshufi32x4 $0x55,%%zmm0,%%zmm0,%%zmm1 \n" + "vshufi32x4 $0x00,%%zmm0,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm5,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm5,%%zmm1,%%zmm1 \n" + "vpord %%zmm16,%%zmm0,%%zmm0 \n" + "vpord %%zmm16,%%zmm1,%%zmm1 \n" + "vmovdqu32 %%zmm0,(%1)%{%%k1%} \n" + "vmovdqu32 %%zmm1,0x40(%1)%{%%k2%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(dst_argb), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : [shuf] "m"(kShuffleMaskJ400ToARGB) // %[shuf] + : "memory", "cc", "xmm0", "xmm1", "xmm5", "xmm16", "k1", "k2"); +} +#endif // HAS_J400TOARGBROW_AVX512BW #ifdef HAS_RGB24TOARGBROW_SSSE3 void RGB24ToARGBRow_SSSE3(const uint8_t* src_rgb24, uint8_t* dst_argb, int width) { asm volatile( - "pcmpeqb %%xmm5,%%xmm5 \n" // 0xff000000 - "pslld $0x18,%%xmm5 \n" - "movdqa %3,%%xmm4 \n" + "pcmpeqb %%xmm5,%%xmm5 \n" // 0xff000000 + "pslld $0x18,%%xmm5 \n" + "movdqa %3,%%xmm4 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm3 \n" - "lea 0x30(%0),%0 \n" - "movdqa %%xmm3,%%xmm2 \n" - "palignr $0x8,%%xmm1,%%xmm2 \n" - "pshufb %%xmm4,%%xmm2 \n" - "por %%xmm5,%%xmm2 \n" - "palignr $0xc,%%xmm0,%%xmm1 \n" - "pshufb %%xmm4,%%xmm0 \n" - "movdqu %%xmm2,0x20(%1) \n" - "por %%xmm5,%%xmm0 \n" - "pshufb %%xmm4,%%xmm1 \n" - "movdqu %%xmm0,(%1) \n" - "por %%xmm5,%%xmm1 \n" - "palignr $0x4,%%xmm3,%%xmm3 \n" - "pshufb %%xmm4,%%xmm3 \n" - "movdqu %%xmm1,0x10(%1) \n" - "por %%xmm5,%%xmm3 \n" - "movdqu %%xmm3,0x30(%1) \n" - "lea 0x40(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_rgb24), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : "m"(kShuffleMaskRGB24ToARGB) // %3 + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x20(%0),%%xmm3 \n" + "lea 0x30(%0),%0 \n" + "movdqa %%xmm3,%%xmm2 \n" + "palignr $0x8,%%xmm1,%%xmm2 \n" + "pshufb %%xmm4,%%xmm2 \n" + "por %%xmm5,%%xmm2 \n" + "palignr $0xc,%%xmm0,%%xmm1 \n" + "pshufb %%xmm4,%%xmm0 \n" + "movdqu %%xmm2,0x20(%1) \n" + "por %%xmm5,%%xmm0 \n" + "pshufb %%xmm4,%%xmm1 \n" + "movdqu %%xmm0,(%1) \n" + "por %%xmm5,%%xmm1 \n" + "palignr $0x4,%%xmm3,%%xmm3 \n" + "pshufb %%xmm4,%%xmm3 \n" + "movdqu %%xmm1,0x10(%1) \n" + "por %%xmm5,%%xmm3 \n" + "movdqu %%xmm3,0x30(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_rgb24), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "m"(kShuffleMaskRGB24ToARGB[0]) // %3 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); } +#endif // HAS_RGB24TOARGBROW_SSSE3 +#ifdef HAS_RGB24TOARGBROW_AVX2 +void RGB24ToARGBRow_AVX2(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width) { + asm volatile( + "vpcmpeqb %%ymm6,%%ymm6,%%ymm6 \n" // 0xff000000 + "vpslld $0x18,%%ymm6,%%ymm6 \n" + "vbroadcasti128 %3,%%ymm4 \n" + "vbroadcasti128 %4,%%ymm5 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" // first 12 + "vinserti128 $1,12(%0),%%ymm0,%%ymm0 \n" // second 12 + "vmovdqu 24(%0),%%xmm1 \n" // third 12 + "vinserti128 $1,36(%0),%%ymm1,%%ymm1 \n" // forth 12 + "vmovdqu 48(%0),%%xmm2 \n" // fifth 12 + "vinserti128 $1,60(%0),%%ymm2,%%ymm2 \n" // sixth 12 + "vmovdqu 68(%0),%%xmm3 \n" // seventh 12 + "vinserti128 $1,80(%0),%%ymm3,%%ymm3 \n" // eighth 12 + "lea 96(%0),%0 \n" + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm4,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm4,%%ymm2,%%ymm2 \n" + "vpshufb %%ymm5,%%ymm3,%%ymm3 \n" + "vpor %%ymm6,%%ymm0,%%ymm0 \n" + "vpor %%ymm6,%%ymm1,%%ymm1 \n" + "vpor %%ymm6,%%ymm2,%%ymm2 \n" + "vpor %%ymm6,%%ymm3,%%ymm3 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "vmovdqu %%ymm2,0x40(%1) \n" + "vmovdqu %%ymm3,0x60(%1) \n" + "lea 0x80(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_rgb24), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "m"(kShuffleMaskRGB24ToARGB[0]), // %3 + "m"(kShuffleMaskRGB24ToARGB[1]) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); +} +#endif // HAS_RGB24TOARGBROW_AVX2 + +#ifdef HAS_RAWTOARGBROW_SSSE3 void RAWToARGBRow_SSSE3(const uint8_t* src_raw, uint8_t* dst_argb, int width) { asm volatile( - "pcmpeqb %%xmm5,%%xmm5 \n" // 0xff000000 - "pslld $0x18,%%xmm5 \n" - "movdqa %3,%%xmm4 \n" + "pcmpeqb %%xmm6,%%xmm6 \n" // 0xff000000 + "pslld $0x18,%%xmm6 \n" + "movdqa %3,%%xmm4 \n" + "movdqa %4,%%xmm5 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm3 \n" - "lea 0x30(%0),%0 \n" - "movdqa %%xmm3,%%xmm2 \n" - "palignr $0x8,%%xmm1,%%xmm2 \n" - "pshufb %%xmm4,%%xmm2 \n" - "por %%xmm5,%%xmm2 \n" - "palignr $0xc,%%xmm0,%%xmm1 \n" - "pshufb %%xmm4,%%xmm0 \n" - "movdqu %%xmm2,0x20(%1) \n" - "por %%xmm5,%%xmm0 \n" - "pshufb %%xmm4,%%xmm1 \n" - "movdqu %%xmm0,(%1) \n" - "por %%xmm5,%%xmm1 \n" - "palignr $0x4,%%xmm3,%%xmm3 \n" - "pshufb %%xmm4,%%xmm3 \n" - "movdqu %%xmm1,0x10(%1) \n" - "por %%xmm5,%%xmm3 \n" - "movdqu %%xmm3,0x30(%1) \n" - "lea 0x40(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_raw), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : "m"(kShuffleMaskRAWToARGB) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 12(%0),%%xmm1 \n" + "movdqu 24(%0),%%xmm2 \n" + "movdqu 32(%0),%%xmm3 \n" + "lea 0x30(%0),%0 \n" + "pshufb %%xmm4,%%xmm0 \n" + "pshufb %%xmm4,%%xmm1 \n" + "pshufb %%xmm4,%%xmm2 \n" + "pshufb %%xmm5,%%xmm3 \n" + "por %%xmm6,%%xmm0 \n" + "por %%xmm6,%%xmm1 \n" + "por %%xmm6,%%xmm2 \n" + "por %%xmm6,%%xmm3 \n" + "movdqu %%xmm0,0x00(%1) \n" + "movdqu %%xmm1,0x10(%1) \n" + "movdqu %%xmm2,0x20(%1) \n" + "movdqu %%xmm3,0x30(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_raw), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "m"(kShuffleMaskRAWToARGB), // %3 + "m"(kShuffleMaskRAWToARGB_0) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); +} +#endif // HAS_RAWTOARGBROW_SSSE3 + +#ifdef HAS_RAWTOARGBROW_AVX2 +void RAWToARGBRow_AVX2(const uint8_t* src_raw, uint8_t* dst_argb, int width) { + asm volatile( + "vpcmpeqb %%ymm6,%%ymm6,%%ymm6 \n" // 0xff000000 + "vpslld $0x18,%%ymm6,%%ymm6 \n" + "vbroadcasti128 %3,%%ymm4 \n" // + "vbroadcasti128 %4,%%ymm5 \n" // + + LABELALIGN // + "1: \n" + "vmovdqu (%0),%%xmm0 \n" // first 12 + "vinserti128 $1,12(%0),%%ymm0,%%ymm0 \n" // second 12 + "vmovdqu 24(%0),%%xmm1 \n" // third 12 + "vinserti128 $1,36(%0),%%ymm1,%%ymm1 \n" // forth 12 + "vmovdqu 48(%0),%%xmm2 \n" // fifth 12 + "vinserti128 $1,60(%0),%%ymm2,%%ymm2 \n" // sixth 12 + "vmovdqu 68(%0),%%xmm3 \n" // seventh 12 + "vinserti128 $1,80(%0),%%ymm3,%%ymm3 \n" // eighth 12 + "lea 96(%0),%0 \n" + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm4,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm4,%%ymm2,%%ymm2 \n" + "vpshufb %%ymm5,%%ymm3,%%ymm3 \n" + "vpor %%ymm6,%%ymm0,%%ymm0 \n" + "vpor %%ymm6,%%ymm1,%%ymm1 \n" + "vpor %%ymm6,%%ymm2,%%ymm2 \n" + "vpor %%ymm6,%%ymm3,%%ymm3 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "vmovdqu %%ymm2,0x40(%1) \n" + "vmovdqu %%ymm3,0x60(%1) \n" + "lea 0x80(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_raw), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "m"(kShuffleMaskRAWToARGB), // %3 + "m"(kShuffleMaskRAWToARGB_0) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); +} +#endif // HAS_RAWTOARGBROW_AVX2 + +#if defined(HAS_RAWTOARGBROW_AVX512BW) || \ + defined(HAS_RGB24TOARGBROW_AVX512BW) || \ + defined(HAS_RAWTORGB24ROW_AVX512BW) || \ + defined(HAS_RGBTOYMATRIXROW_AVX512BW) +static const uint64_t kPermqRGB24ToARGB0_AVX512BW[8] = {0, 1, 1, 2, 3, 4, 4, 5}; +static const uint64_t kPermqRGB24ToARGB1_AVX512BW[8] = {6, 7, 7, 8, + 9, 10, 10, 11}; +static const uint64_t kPermqRGB24ToARGB2_AVX512BW[8] = {4, 5, 5, 6, 7, 8, 8, 9}; +static const uint64_t kPermqRGB24ToARGB3_AVX512BW[8] = {2, 3, 3, 4, 5, 6, 6, 7}; +#endif // defined(HAS_RAWTOARGBROW_AVX512BW) || + // defined(HAS_RGB24TOARGBROW_AVX512BW) || + // defined(HAS_RAWTORGB24ROW_AVX512BW) || + // defined(HAS_RGBTOYMATRIXROW_AVX512BW) + +#ifdef HAS_RAWTOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +static inline void RGBToARGBRow_AVX512BW(const uint8_t* src_raw, + uint8_t* dst_argb, + const uint32_t* shuffler, + int width) { + uintptr_t temp; + uintptr_t mask; + asm volatile( + "vmovdqu64 %[q0],%%zmm20 \n" // kPermqRGB24ToARGB0_AVX512BW + "vmovdqu64 %[q1],%%zmm21 \n" // kPermqRGB24ToARGB1_AVX512BW + "vmovdqu64 %[q2],%%zmm22 \n" // kPermqRGB24ToARGB2_AVX512BW + "vmovdqu64 %[q3],%%zmm23 \n" // kPermqRGB24ToARGB3_AVX512BW + "vbroadcasti64x4 (%[shuffler]),%%zmm4 \n" // shuffler (32 bytes) + "vpternlogd $0xff,%%zmm16,%%zmm16,%%zmm16 \n" // 0xffffffff + "vpslld $0x18,%%zmm16,%%zmm16 \n" // 0xff000000 + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src_raw]),%%zmm0 \n" + "vmovdqu8 64(%[src_raw]),%%zmm1 \n" + "vmovdqu8 128(%[src_raw]),%%zmm2 \n" + "lea 192(%[src_raw]),%[src_raw] \n" + "vpermq %%zmm2,%%zmm23,%%zmm3 \n" + "vmovdqa64 %%zmm0,%%zmm19 \n" + "vpermt2q %%zmm1,%%zmm21,%%zmm19 \n" + "vpermt2q %%zmm2,%%zmm22,%%zmm1 \n" + "vpermq %%zmm0,%%zmm20,%%zmm0 \n" + "vpshufb %%zmm4,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm4,%%zmm19,%%zmm19 \n" + "vpshufb %%zmm4,%%zmm1,%%zmm2 \n" + "vpshufb %%zmm4,%%zmm3,%%zmm3 \n" + "vpord %%zmm16,%%zmm0,%%zmm0 \n" + "vpord %%zmm16,%%zmm19,%%zmm19 \n" + "vpord %%zmm16,%%zmm2,%%zmm2 \n" + "vpord %%zmm16,%%zmm3,%%zmm3 \n" + "vmovdqu32 %%zmm0,(%[dst_argb]) \n" + "vmovdqu32 %%zmm19,0x40(%[dst_argb]) \n" + "vmovdqu32 %%zmm2,0x80(%[dst_argb]) \n" + "vmovdqu32 %%zmm3,0xc0(%[dst_argb]) \n" + "lea 0x100(%[dst_argb]),%[dst_argb]\n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[mask] \n" + "kmovq %[mask],%%k1 \n" + "kshiftrq $16,%%k1,%%k2 \n" + "kshiftrq $32,%%k1,%%k3 \n" + "kshiftrq $48,%%k1,%%k4 \n" + "lea (%q[width],%q[width],2),%k[width] \n" + "bzhi %q[width],%[temp],%[mask] \n" + "kmovq %[mask],%%k5 \n" + "vmovdqu8 (%[src_raw]),%%zmm0%{%%k5%}%{z%} \n" + "xor %k[mask],%k[mask] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[mask] \n" + "bzhi %q[width],%[mask],%[mask] \n" + "kmovq %[mask],%%k5 \n" + "vmovdqu8 64(%[src_raw]),%%zmm1%{%%k5%}%{z%} \n" + "xor %k[mask],%k[mask] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[mask] \n" + "bzhi %q[width],%[mask],%[mask] \n" + "kmovq %[mask],%%k5 \n" + "vmovdqu8 128(%[src_raw]),%%zmm2%{%%k5%}%{z%} \n" + "vpermq %%zmm2,%%zmm23,%%zmm3 \n" + "vpermi2q %%zmm2,%%zmm1,%%zmm22 \n" + "vpermi2q %%zmm1,%%zmm0,%%zmm21 \n" + "vpermq %%zmm0,%%zmm20,%%zmm0 \n" + "vpshufb %%zmm4,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm4,%%zmm21,%%zmm1 \n" + "vpshufb %%zmm4,%%zmm22,%%zmm2 \n" + "vpshufb %%zmm4,%%zmm3,%%zmm3 \n" + "vpord %%zmm16,%%zmm0,%%zmm0 \n" + "vpord %%zmm16,%%zmm1,%%zmm1 \n" + "vpord %%zmm16,%%zmm2,%%zmm2 \n" + "vpord %%zmm16,%%zmm3,%%zmm3 \n" + "vmovdqu32 %%zmm0,(%[dst_argb])%{%%k1%} \n" + "vmovdqu32 %%zmm1,0x40(%[dst_argb])%{%%k2%} \n" + "vmovdqu32 %%zmm2,0x80(%[dst_argb])%{%%k3%} \n" + "vmovdqu32 %%zmm3,0xc0(%[dst_argb])%{%%k4%} \n" + + "99: \n" + "vzeroupper \n" + : [src_raw] "+r"(src_raw), // %[src_raw] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width), // %[width] + [temp] "=&r"(temp), // %[temp] + [mask] "=&r"(mask) // %[mask] + : [shuffler] "r"(shuffler), // %[shuffler] + [q0] "m"(kPermqRGB24ToARGB0_AVX512BW), // %[q0] + [q1] "m"(kPermqRGB24ToARGB1_AVX512BW), // %[q1] + [q2] "m"(kPermqRGB24ToARGB2_AVX512BW), // %[q2] + [q3] "m"(kPermqRGB24ToARGB3_AVX512BW) // %[q3] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm16", + "xmm19", "xmm20", "xmm21", "xmm22", "xmm23", "k1", "k2", "k3", "k4", + "k5"); } +LIBYUV_TARGET_AVX512BW +void RAWToARGBRow_AVX512BW(const uint8_t* src_raw, + uint8_t* dst_argb, + int width) { + RGBToARGBRow_AVX512BW(src_raw, dst_argb, + (const uint32_t*)&kShuffleMaskRAWToARGB_AVX512BW[0], + width); +} + +LIBYUV_TARGET_AVX512BW +void RGB24ToARGBRow_AVX512BW(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width) { + RGBToARGBRow_AVX512BW(src_rgb24, dst_argb, + (const uint32_t*)&kShuffleMaskRGB24ToARGB[0], width); +} +#endif // HAS_RAWTOARGBROW_AVX512BW + +#ifdef HAS_RAWTORGBAROW_AVX2 +void RAWToRGBARow_AVX2(const uint8_t* src_raw, uint8_t* dst_rgba, int width) { + asm volatile( + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsrld $24,%%ymm5,%%ymm5 \n" // 0x000000ff + "vbroadcasti128 %3,%%ymm3 \n" + "vmovdqu %3,%%ymm4 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" // first 12 bytes + "vinserti128 $1,12(%0),%%ymm0,%%ymm0 \n" // second 12 bytes + "vmovdqu 24(%0),%%xmm1 \n" // third 12 bytes + "vinserti128 $1,32(%0),%%ymm1,%%ymm1 \n" // fourth 12 bytes + "lea 0x30(%0),%0 \n" + "vpshufb %%ymm3,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm4,%%ymm1,%%ymm1 \n" + "vpor %%ymm5,%%ymm0,%%ymm0 \n" + "vpor %%ymm5,%%ymm1,%%ymm1 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_raw), // %0 + "+r"(dst_rgba), // %1 + "+r"(width) // %2 + : "m"(kShuffleMaskRAWToRGBA_AVX2) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm3", "xmm4", "xmm5"); +} +#endif // HAS_RAWTORGBAROW_AVX2 + +#ifdef HAS_RAWTORGB24ROW_SSSE3 void RAWToRGB24Row_SSSE3(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { asm volatile( - "movdqa %3,%%xmm3 \n" - "movdqa %4,%%xmm4 \n" - "movdqa %5,%%xmm5 \n" + "movdqa %3,%%xmm3 \n" + "movdqa %4,%%xmm4 \n" + "movdqa %5,%%xmm5 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x4(%0),%%xmm1 \n" - "movdqu 0x8(%0),%%xmm2 \n" - "lea 0x18(%0),%0 \n" - "pshufb %%xmm3,%%xmm0 \n" - "pshufb %%xmm4,%%xmm1 \n" - "pshufb %%xmm5,%%xmm2 \n" - "movq %%xmm0,(%1) \n" - "movq %%xmm1,0x8(%1) \n" - "movq %%xmm2,0x10(%1) \n" - "lea 0x18(%1),%1 \n" - "sub $0x8,%2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x4(%0),%%xmm1 \n" + "movdqu 0x8(%0),%%xmm2 \n" + "lea 0x18(%0),%0 \n" + "pshufb %%xmm3,%%xmm0 \n" + "pshufb %%xmm4,%%xmm1 \n" + "pshufb %%xmm5,%%xmm2 \n" + "movq %%xmm0,(%1) \n" + "movq %%xmm1,0x8(%1) \n" + "movq %%xmm2,0x10(%1) \n" + "lea 0x18(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" : "+r"(src_raw), // %0 "+r"(dst_rgb24), // %1 "+r"(width) // %2 @@ -290,47 +645,286 @@ void RAWToRGB24Row_SSSE3(const uint8_t* src_raw, "m"(kShuffleMaskRAWToRGB24_2) // %5 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); } +#endif // HAS_RAWTORGB24ROW_SSSE3 -void RGB565ToARGBRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { +#ifdef HAS_RAWTORGB24ROW_AVX2 +void RAWToRGB24Row_AVX2(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { asm volatile( - "mov $0x1080108,%%eax \n" - "movd %%eax,%%xmm5 \n" - "pshufd $0x0,%%xmm5,%%xmm5 \n" - "mov $0x20802080,%%eax \n" - "movd %%eax,%%xmm6 \n" - "pshufd $0x0,%%xmm6,%%xmm6 \n" - "pcmpeqb %%xmm3,%%xmm3 \n" - "psllw $0xb,%%xmm3 \n" - "pcmpeqb %%xmm4,%%xmm4 \n" - "psllw $0xa,%%xmm4 \n" - "psrlw $0x5,%%xmm4 \n" - "pcmpeqb %%xmm7,%%xmm7 \n" - "psllw $0x8,%%xmm7 \n" - "sub %0,%1 \n" - "sub %0,%1 \n" + "vmovdqu %3,%%ymm4 \n" // shuffler (32 bytes) + "vmovdqu %4,%%ymm5 \n" // kPermd0_AVX2 + "vmovdqu %5,%%ymm6 \n" // kPermd1_AVX2 + "vmovdqu %6,%%ymm7 \n" // kPermd2_AVX2 LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm0,%%xmm2 \n" - "pand %%xmm3,%%xmm1 \n" - "psllw $0xb,%%xmm2 \n" - "pmulhuw %%xmm5,%%xmm1 \n" - "pmulhuw %%xmm5,%%xmm2 \n" - "psllw $0x8,%%xmm1 \n" - "por %%xmm2,%%xmm1 \n" - "pand %%xmm4,%%xmm0 \n" - "pmulhuw %%xmm6,%%xmm0 \n" - "por %%xmm7,%%xmm0 \n" - "movdqa %%xmm1,%%xmm2 \n" - "punpcklbw %%xmm0,%%xmm1 \n" - "punpckhbw %%xmm0,%%xmm2 \n" - "movdqu %%xmm1,0x00(%1,%0,2) \n" - "movdqu %%xmm2,0x10(%1,%0,2) \n" - "lea 0x10(%0),%0 \n" - "sub $0x8,%2 \n" - "jg 1b \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" // raw0 + "vmovdqu 32(%0),%%ymm1 \n" // raw1 + "vmovdqu 64(%0),%%ymm2 \n" // raw2 + "lea 96(%0),%0 \n" + + "vperm2i128 $0x21,%%ymm1,%%ymm0,%%ymm3 \n" // m01 + "vpermq $0x94,%%ymm0,%%ymm0 \n" // b0 + "vperm2i128 $0x21,%%ymm2,%%ymm1,%%ymm1 \n" // m12 + "vpermq $0xe9,%%ymm2,%%ymm2 \n" // b3 + "vpermq $0xe9,%%ymm3,%%ymm3 \n" // b1 + "vpermq $0x94,%%ymm1,%%ymm1 \n" // b2 + + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm4,%%ymm3,%%ymm3 \n" + "vpshufb %%ymm4,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm4,%%ymm2,%%ymm2 \n" + + "vpermd %%ymm0,%%ymm5,%%ymm0 \n" + "vpermd %%ymm3,%%ymm6,%%ymm3 \n" + "vpermd %%ymm1,%%ymm7,%%ymm1 \n" + "vpermd %%ymm2,%%ymm5,%%ymm2 \n" + + // Dst0 + "vpblendd $0xc0,%%ymm3,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + + // Dst1 + "vpblendd $0xf0,%%ymm1,%%ymm3,%%ymm3 \n" + "vpermq $0x90,%%ymm2,%%ymm2 \n" + "vmovdqu %%ymm3,32(%1) \n" + + // Dst2 + "vpblendd $0xfc,%%ymm2,%%ymm1,%%ymm1 \n" + "vmovdqu %%ymm1,64(%1) \n" + + "lea 96(%1),%1 \n" + "sub $32,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_raw), // %0 + "+r"(dst_rgb24), // %1 + "+r"(width) // %2 + : "m"(kShuffleMaskRAWToRGB24_AVX2), // %3 + "m"(kPermd0_AVX2), // %4 + "m"(kPermd1_AVX2), // %5 + "m"(kPermd2_AVX2) // %6 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_RAWTORGB24ROW_AVX2 + +#ifdef HAS_RAWTORGB24ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void RAWToRGB24Row_AVX512BW(const uint8_t* src_raw, + uint8_t* dst_rgb24, + int width) { + uintptr_t temp; + uintptr_t mask; + asm volatile( + "vmovdqu64 %[q0],%%zmm20 \n" // kPermqRGB24ToARGB0_AVX512BW + "vmovdqu64 %[q1],%%zmm21 \n" // kPermqRGB24ToARGB1_AVX512BW + "vmovdqu64 %[q2],%%zmm22 \n" // kPermqRGB24ToARGB2_AVX512BW + "vmovdqu64 %[q3],%%zmm23 \n" // kPermqRGB24ToARGB3_AVX512BW + "vbroadcasti64x4 %[shuf],%%zmm4 \n" // shuffler (32 bytes) + "vmovdqu32 %[d0],%%zmm24 \n" // kPermdRGB24_0_AVX512BW + "vmovdqu32 %[d1],%%zmm25 \n" // kPermdRGB24_1_AVX512BW + "vmovdqu32 %[d2],%%zmm26 \n" // kPermdRGB24_2_AVX512BW + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src_raw]),%%zmm0 \n" + "vmovdqu8 64(%[src_raw]),%%zmm1 \n" + "vmovdqu8 128(%[src_raw]),%%zmm2 \n" + "lea 192(%[src_raw]),%[src_raw] \n" + "vpermq %%zmm2,%%zmm23,%%zmm3 \n" + "vmovdqa64 %%zmm0,%%zmm19 \n" + "vpermt2q %%zmm1,%%zmm21,%%zmm19 \n" + "vpermt2q %%zmm2,%%zmm22,%%zmm1 \n" + "vpermq %%zmm0,%%zmm20,%%zmm0 \n" + "vpshufb %%zmm4,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm4,%%zmm19,%%zmm19 \n" + "vpshufb %%zmm4,%%zmm1,%%zmm2 \n" + "vpshufb %%zmm4,%%zmm3,%%zmm3 \n" + "vpermt2d %%zmm19,%%zmm24,%%zmm0 \n" + "vpermt2d %%zmm2,%%zmm25,%%zmm19 \n" + "vpermt2d %%zmm3,%%zmm26,%%zmm2 \n" + "vmovdqu8 %%zmm0,(%[dst_rgb24]) \n" + "vmovdqu8 %%zmm19,0x40(%[dst_rgb24]) \n" + "vmovdqu8 %%zmm2,0x80(%[dst_rgb24]) \n" + "lea 0xc0(%[dst_rgb24]),%[dst_rgb24]\n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "lea (%q[width],%q[width],2),%k[width] \n" + "bzhi %q[width],%[temp],%[mask] \n" + "kmovq %[mask],%%k1 \n" + "xor %k[mask],%k[mask] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[mask] \n" + "bzhi %q[width],%[mask],%[mask] \n" + "kmovq %[mask],%%k2 \n" + "xor %k[mask],%k[mask] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[mask] \n" + "bzhi %q[width],%[mask],%[mask] \n" + "kmovq %[mask],%%k3 \n" + "vmovdqu8 (%[src_raw]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu8 64(%[src_raw]),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu8 128(%[src_raw]),%%zmm2%{%%k3%}%{z%} \n" + "vpermq %%zmm2,%%zmm23,%%zmm3 \n" + "vmovdqa64 %%zmm0,%%zmm19 \n" + "vpermt2q %%zmm1,%%zmm21,%%zmm19 \n" + "vpermt2q %%zmm2,%%zmm22,%%zmm1 \n" + "vpermq %%zmm0,%%zmm20,%%zmm0 \n" + "vpshufb %%zmm4,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm4,%%zmm19,%%zmm19 \n" + "vpshufb %%zmm4,%%zmm1,%%zmm2 \n" + "vpshufb %%zmm4,%%zmm3,%%zmm3 \n" + "vpermt2d %%zmm19,%%zmm24,%%zmm0 \n" + "vpermt2d %%zmm2,%%zmm25,%%zmm19 \n" + "vpermt2d %%zmm3,%%zmm26,%%zmm2 \n" + "vmovdqu8 %%zmm0,(%[dst_rgb24])%{%%k1%} \n" + "vmovdqu8 %%zmm19,0x40(%[dst_rgb24])%{%%k2%} \n" + "vmovdqu8 %%zmm2,0x80(%[dst_rgb24])%{%%k3%} \n" + + "99: \n" + "vzeroupper \n" + : [src_raw] "+r"(src_raw), // %[src_raw] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [width] "+r"(width), // %[width] + [temp] "=&r"(temp), // %[temp] + [mask] "=&r"(mask) // %[mask] + : [q0] "m"(kPermqRGB24ToARGB0_AVX512BW), // %[q0] + [q1] "m"(kPermqRGB24ToARGB1_AVX512BW), // %[q1] + [q2] "m"(kPermqRGB24ToARGB2_AVX512BW), // %[q2] + [q3] "m"(kPermqRGB24ToARGB3_AVX512BW), // %[q3] + [shuf] "m"(kShuffleMaskRAWToRGB24_AVX2), // %[shuf] + [d0] "m"(kPermdRGB24_0_AVX512BW), // %[d0] + [d1] "m"(kPermdRGB24_1_AVX512BW), // %[d1] + [d2] "m"(kPermdRGB24_2_AVX512BW) // %[d2] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm19", + "xmm20", "xmm21", "xmm22", "xmm23", "xmm24", "xmm25", "xmm26", "k1", + "k2", "k3"); +} +#endif // HAS_RAWTORGB24ROW_AVX512BW + +#ifdef HAS_RAWTORGB24ROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void RAWToRGB24Row_AVX512VBMI(const uint8_t* src_raw, + uint8_t* dst_rgb24, + int width) { + uintptr_t temp; + uintptr_t mask; + asm volatile( + "vmovdqu32 %[kPermRAWToRGB24_0],%%zmm20 \n" + "vmovdqu32 %[kPermRAWToRGB24_1],%%zmm21 \n" + "vmovdqu32 %[kPermRAWToRGB24_2],%%zmm22 \n" + "vmovdqu32 %[kPermRAWToRGB24_3],%%zmm23 \n" + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src_raw]),%%zmm0 \n" + "vmovdqu8 64(%[src_raw]),%%zmm1 \n" + "vmovdqu8 128(%[src_raw]),%%zmm2 \n" + "lea 192(%[src_raw]),%[src_raw] \n" + "vmovdqa64 %%zmm1,%%zmm3 \n" + "vpermt2b %%zmm0,%%zmm21,%%zmm1 \n" + "vpermt2b %%zmm3,%%zmm20,%%zmm0 \n" + "vpermt2b %%zmm2,%%zmm23,%%zmm3 \n" + "vpermt2b %%zmm2,%%zmm22,%%zmm1 \n" + "vmovdqu8 %%zmm0,(%[dst_rgb24]) \n" + "vmovdqu8 %%zmm1,0x40(%[dst_rgb24]) \n" + "vmovdqu8 %%zmm3,0x80(%[dst_rgb24]) \n" + "lea 0xc0(%[dst_rgb24]),%[dst_rgb24]\n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "lea (%q[width],%q[width],2),%k[width] \n" + "bzhi %q[width],%[temp],%[mask] \n" + "kmovq %[mask],%%k1 \n" + "xor %k[mask],%k[mask] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[mask] \n" + "bzhi %q[width],%[mask],%[mask] \n" + "kmovq %[mask],%%k2 \n" + "xor %k[mask],%k[mask] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[mask] \n" + "bzhi %q[width],%[mask],%[mask] \n" + "kmovq %[mask],%%k3 \n" + "vmovdqu8 (%[src_raw]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu8 64(%[src_raw]),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu8 128(%[src_raw]),%%zmm2%{%%k3%}%{z%} \n" + "vmovdqa64 %%zmm1,%%zmm3 \n" + "vpermt2b %%zmm0,%%zmm21,%%zmm1 \n" + "vpermt2b %%zmm3,%%zmm20,%%zmm0 \n" + "vpermt2b %%zmm2,%%zmm23,%%zmm3 \n" + "vpermt2b %%zmm2,%%zmm22,%%zmm1 \n" + "vmovdqu8 %%zmm0,(%[dst_rgb24])%{%%k1%} \n" + "vmovdqu8 %%zmm1,0x40(%[dst_rgb24])%{%%k2%} \n" + "vmovdqu8 %%zmm3,0x80(%[dst_rgb24])%{%%k3%} \n" + + "99: \n" + "vzeroupper \n" + : [src_raw] "+r"(src_raw), [dst_rgb24] "+r"(dst_rgb24), + [width] "+r"(width), [temp] "=&r"(temp), [mask] "=&r"(mask) + : [kPermRAWToRGB24_0] "m"(kPermRAWToRGB24_0), + [kPermRAWToRGB24_1] "m"(kPermRAWToRGB24_1), + [kPermRAWToRGB24_2] "m"(kPermRAWToRGB24_2), + [kPermRAWToRGB24_3] "m"(kPermRAWToRGB24_3) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm20", "xmm21", + "xmm22", "xmm23", "k1", "k2", "k3"); +} +#endif // HAS_RAWTORGB24ROW_AVX512VBMI + +#ifdef HAS_RGB565TOARGBROW_AVX2 +void RGB565ToARGBRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { + asm volatile( + "mov $0x1080108,%%eax \n" + "vmovd %%eax,%%xmm5 \n" + "vpbroadcastd %%xmm5,%%ymm5 \n" + "mov $0x20802080,%%eax \n" + "vmovd %%eax,%%xmm6 \n" + "vpbroadcastd %%xmm6,%%ymm6 \n" + "vpcmpeqb %%ymm3,%%ymm3,%%ymm3 \n" + "vpsllw $0xb,%%ymm3,%%ymm3 \n" + "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" + "vpsllw $10,%%ymm4,%%ymm4 \n" + "vpsrlw $5,%%ymm4,%%ymm4 \n" + "vpcmpeqb %%ymm7,%%ymm7,%%ymm7 \n" + "vpsllw $0x8,%%ymm7,%%ymm7 \n" + "sub %0,%1 \n" + "sub %0,%1 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpand %%ymm3,%%ymm0,%%ymm1 \n" + "vpsllw $0xb,%%ymm0,%%ymm2 \n" + "vpmulhuw %%ymm5,%%ymm1,%%ymm1 \n" + "vpmulhuw %%ymm5,%%ymm2,%%ymm2 \n" + "vpsllw $0x8,%%ymm1,%%ymm1 \n" + "vpor %%ymm2,%%ymm1,%%ymm1 \n" + "vpand %%ymm4,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm6,%%ymm0,%%ymm0 \n" + "vpor %%ymm7,%%ymm0,%%ymm0 \n" + "vpunpcklbw %%ymm0,%%ymm1,%%ymm2 \n" + "vpunpckhbw %%ymm0,%%ymm1,%%ymm1 \n" + "vperm2i128 $0x20,%%ymm1,%%ymm2,%%ymm0 \n" + "vperm2i128 $0x31,%%ymm1,%%ymm2,%%ymm1 \n" + "vmovdqu %%ymm0,(%1,%0,2) \n" + "vmovdqu %%ymm1,0x20(%1,%0,2) \n" + "lea 0x20(%0),%0 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -338,50 +932,50 @@ void RGB565ToARGBRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { : "memory", "cc", "eax", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); } +#endif // HAS_RGB565TOARGBROW_AVX2 -void ARGB1555ToARGBRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { +#ifdef HAS_ARGB1555TOARGBROW_AVX2 +void ARGB1555ToARGBRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "mov $0x1080108,%%eax \n" - "movd %%eax,%%xmm5 \n" - "pshufd $0x0,%%xmm5,%%xmm5 \n" - "mov $0x42004200,%%eax \n" - "movd %%eax,%%xmm6 \n" - "pshufd $0x0,%%xmm6,%%xmm6 \n" - "pcmpeqb %%xmm3,%%xmm3 \n" - "psllw $0xb,%%xmm3 \n" - "movdqa %%xmm3,%%xmm4 \n" - "psrlw $0x6,%%xmm4 \n" - "pcmpeqb %%xmm7,%%xmm7 \n" - "psllw $0x8,%%xmm7 \n" - "sub %0,%1 \n" - "sub %0,%1 \n" + "mov $0x1080108,%%eax \n" + "vmovd %%eax,%%xmm5 \n" + "vpbroadcastd %%xmm5,%%ymm5 \n" + "mov $0x42004200,%%eax \n" + "vmovd %%eax,%%xmm6 \n" + "vpbroadcastd %%xmm6,%%ymm6 \n" + "vpcmpeqb %%ymm3,%%ymm3,%%ymm3 \n" + "vpsllw $0xb,%%ymm3,%%ymm3 \n" + "vpsrlw $0x6,%%ymm3,%%ymm4 \n" + "vpcmpeqb %%ymm7,%%ymm7,%%ymm7 \n" + "vpsllw $0x8,%%ymm7,%%ymm7 \n" + "sub %0,%1 \n" + "sub %0,%1 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm0,%%xmm2 \n" - "psllw $0x1,%%xmm1 \n" - "psllw $0xb,%%xmm2 \n" - "pand %%xmm3,%%xmm1 \n" - "pmulhuw %%xmm5,%%xmm2 \n" - "pmulhuw %%xmm5,%%xmm1 \n" - "psllw $0x8,%%xmm1 \n" - "por %%xmm2,%%xmm1 \n" - "movdqa %%xmm0,%%xmm2 \n" - "pand %%xmm4,%%xmm0 \n" - "psraw $0x8,%%xmm2 \n" - "pmulhuw %%xmm6,%%xmm0 \n" - "pand %%xmm7,%%xmm2 \n" - "por %%xmm2,%%xmm0 \n" - "movdqa %%xmm1,%%xmm2 \n" - "punpcklbw %%xmm0,%%xmm1 \n" - "punpckhbw %%xmm0,%%xmm2 \n" - "movdqu %%xmm1,0x00(%1,%0,2) \n" - "movdqu %%xmm2,0x10(%1,%0,2) \n" - "lea 0x10(%0),%0 \n" - "sub $0x8,%2 \n" - "jg 1b \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpsllw $0x1,%%ymm0,%%ymm1 \n" + "vpsllw $0xb,%%ymm0,%%ymm2 \n" + "vpand %%ymm3,%%ymm1,%%ymm1 \n" + "vpmulhuw %%ymm5,%%ymm2,%%ymm2 \n" + "vpmulhuw %%ymm5,%%ymm1,%%ymm1 \n" + "vpsllw $0x8,%%ymm1,%%ymm1 \n" + "vpor %%ymm2,%%ymm1,%%ymm1 \n" + "vpsraw $0x8,%%ymm0,%%ymm2 \n" + "vpand %%ymm4,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm6,%%ymm0,%%ymm0 \n" + "vpand %%ymm7,%%ymm2,%%ymm2 \n" + "vpor %%ymm2,%%ymm0,%%ymm0 \n" + "vpunpcklbw %%ymm0,%%ymm1,%%ymm2 \n" + "vpunpckhbw %%ymm0,%%ymm1,%%ymm1 \n" + "vperm2i128 $0x20,%%ymm1,%%ymm2,%%ymm0 \n" + "vperm2i128 $0x31,%%ymm1,%%ymm2,%%ymm1 \n" + "vmovdqu %%ymm0,(%1,%0,2) \n" + "vmovdqu %%ymm1,0x20(%1,%0,2) \n" + "lea 0x20(%0),%0 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -389,121 +983,216 @@ void ARGB1555ToARGBRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { : "memory", "cc", "eax", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); } +#endif // HAS_ARGB1555TOARGBROW_AVX2 -void ARGB4444ToARGBRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { +#ifdef HAS_ARGB1555TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGB1555ToARGBRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + uintptr_t temp; asm volatile( - "mov $0xf0f0f0f,%%eax \n" - "movd %%eax,%%xmm4 \n" - "pshufd $0x0,%%xmm4,%%xmm4 \n" - "movdqa %%xmm4,%%xmm5 \n" - "pslld $0x4,%%xmm5 \n" - "sub %0,%1 \n" - "sub %0,%1 \n" + "mov $0x01080108,%k[temp] \n" + "vpbroadcastd %k[temp],%%zmm5 \n" + "mov $0x42004200,%k[temp] \n" + "vpbroadcastd %k[temp],%%zmm6 \n" + "vpternlogd $0xff,%%zmm3,%%zmm3,%%zmm3 \n" + "vpsllw $0xb,%%zmm3,%%zmm3 \n" + "vpsrlw $0x6,%%zmm3,%%zmm4 \n" + "vpternlogd $0xff,%%zmm7,%%zmm7,%%zmm7 \n" + "vpsllw $0x8,%%zmm7,%%zmm7 \n" + "sub $0x20,%2 \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqa %%xmm0,%%xmm2 \n" - "pand %%xmm4,%%xmm0 \n" - "pand %%xmm5,%%xmm2 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm2,%%xmm3 \n" - "psllw $0x4,%%xmm1 \n" - "psrlw $0x4,%%xmm3 \n" - "por %%xmm1,%%xmm0 \n" - "por %%xmm3,%%xmm2 \n" - "movdqa %%xmm0,%%xmm1 \n" - "punpcklbw %%xmm2,%%xmm0 \n" - "punpckhbw %%xmm2,%%xmm1 \n" - "movdqu %%xmm0,0x00(%1,%0,2) \n" - "movdqu %%xmm1,0x10(%1,%0,2) \n" - "lea 0x10(%0),%0 \n" - "sub $0x8,%2 \n" - "jg 1b \n" + "1: \n" + "vmovdqu16 (%0),%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vpsllw $0x1,%%zmm0,%%zmm1 \n" + "vpsllw $0xb,%%zmm0,%%zmm2 \n" + "vpandd %%zmm3,%%zmm1,%%zmm1 \n" + "vpmulhuw %%zmm5,%%zmm2,%%zmm2 \n" + "vpmulhuw %%zmm5,%%zmm1,%%zmm1 \n" + "vpsllw $0x8,%%zmm1,%%zmm1 \n" + "vpord %%zmm2,%%zmm1,%%zmm1 \n" + "vpsraw $0x8,%%zmm0,%%zmm2 \n" + "vpandd %%zmm4,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm6,%%zmm0,%%zmm0 \n" + "vpandd %%zmm7,%%zmm2,%%zmm2 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "vpunpcklbw %%zmm0,%%zmm1,%%zmm2 \n" + "vpunpckhbw %%zmm0,%%zmm1,%%zmm1 \n" + "vshufi64x2 $0x44,%%zmm1,%%zmm2,%%zmm0 \n" + "vshufi64x2 $0xee,%%zmm1,%%zmm2,%%zmm1 \n" + "vshufi64x2 $0xd8,%%zmm0,%%zmm0,%%zmm0 \n" + "vshufi64x2 $0xd8,%%zmm1,%%zmm1,%%zmm1 \n" + "vmovdqu32 %%zmm0,(%1) \n" + "vmovdqu32 %%zmm1,0x40(%1) \n" + "lea 0x80(%1),%1 \n" + "sub $0x20,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "mov $-1,%k[temp] \n" + "bzhi %k2,%k[temp],%k[temp] \n" + "kmovd %k[temp],%%k1 \n" + "vmovdqu16 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpsllw $0x1,%%zmm0,%%zmm1 \n" + "vpsllw $0xb,%%zmm0,%%zmm2 \n" + "vpandd %%zmm3,%%zmm1,%%zmm1 \n" + "vpmulhuw %%zmm5,%%zmm2,%%zmm2 \n" + "vpmulhuw %%zmm5,%%zmm1,%%zmm1 \n" + "vpsllw $0x8,%%zmm1,%%zmm1 \n" + "vpord %%zmm2,%%zmm1,%%zmm1 \n" + "vpsraw $0x8,%%zmm0,%%zmm2 \n" + "vpandd %%zmm4,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm6,%%zmm0,%%zmm0 \n" + "vpandd %%zmm7,%%zmm2,%%zmm2 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "vpunpcklbw %%zmm0,%%zmm1,%%zmm2 \n" + "vpunpckhbw %%zmm0,%%zmm1,%%zmm1 \n" + "vshufi64x2 $0x44,%%zmm1,%%zmm2,%%zmm0 \n" + "vshufi64x2 $0xee,%%zmm1,%%zmm2,%%zmm1 \n" + "vshufi64x2 $0xd8,%%zmm0,%%zmm0,%%zmm0 \n" + "vshufi64x2 $0xd8,%%zmm1,%%zmm1,%%zmm1 \n" + "cmp $0x10,%2 \n" + "jle 3f \n" + "vmovdqu32 %%zmm0,(%1) \n" + "kshiftrd $0x10,%%k1,%%k1 \n" + "vmovdqu32 %%zmm1,0x40(%1)%{%%k1%} \n" + "jmp 99f \n" + + "3: \n" + "vmovdqu32 %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7", "k1"); +} +#endif // HAS_ARGB1555TOARGBROW_AVX512BW + +#ifdef HAS_ARGB4444TOARGBROW_AVX2 +void ARGB4444ToARGBRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { + asm volatile( + "mov $0x0f0f0f0f,%%eax \n" + "vmovd %%eax,%%xmm4 \n" + "vpbroadcastd %%xmm4,%%ymm4 \n" + "vpslld $0x4,%%ymm4,%%ymm5 \n" + "sub %0,%1 \n" + "sub %0,%1 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpand %%ymm5,%%ymm0,%%ymm2 \n" + "vpand %%ymm4,%%ymm0,%%ymm0 \n" + "vpsllw $0x4,%%ymm0,%%ymm1 \n" + "vpsrlw $0x4,%%ymm2,%%ymm3 \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" + "vpor %%ymm3,%%ymm2,%%ymm2 \n" + "vpunpckhbw %%ymm2,%%ymm0,%%ymm1 \n" + "vpunpcklbw %%ymm2,%%ymm0,%%ymm0 \n" + "vperm2i128 $0x20,%%ymm1,%%ymm0,%%ymm2 \n" + "vperm2i128 $0x31,%%ymm1,%%ymm0,%%ymm1 \n" + "vmovdqu %%ymm2,(%1,%0,2) \n" + "vmovdqu %%ymm1,0x20(%1,%0,2) \n" + "lea 0x20(%0),%0 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 : : "memory", "cc", "eax", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); } +#endif // HAS_ARGB4444TOARGBROW_AVX2 +#ifdef HAS_ARGBTORGB24ROW_SSSE3 void ARGBToRGB24Row_SSSE3(const uint8_t* src, uint8_t* dst, int width) { - asm volatile( + asm volatile("movdqa %3,%%xmm6 \n" - "movdqa %3,%%xmm6 \n" - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x30(%0),%%xmm3 \n" - "lea 0x40(%0),%0 \n" - "pshufb %%xmm6,%%xmm0 \n" - "pshufb %%xmm6,%%xmm1 \n" - "pshufb %%xmm6,%%xmm2 \n" - "pshufb %%xmm6,%%xmm3 \n" - "movdqa %%xmm1,%%xmm4 \n" - "psrldq $0x4,%%xmm1 \n" - "pslldq $0xc,%%xmm4 \n" - "movdqa %%xmm2,%%xmm5 \n" - "por %%xmm4,%%xmm0 \n" - "pslldq $0x8,%%xmm5 \n" - "movdqu %%xmm0,(%1) \n" - "por %%xmm5,%%xmm1 \n" - "psrldq $0x8,%%xmm2 \n" - "pslldq $0x4,%%xmm3 \n" - "por %%xmm3,%%xmm2 \n" - "movdqu %%xmm1,0x10(%1) \n" - "movdqu %%xmm2,0x20(%1) \n" - "lea 0x30(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "m"(kShuffleMaskARGBToRGB24) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x20(%0),%%xmm2 \n" + "movdqu 0x30(%0),%%xmm3 \n" + "lea 0x40(%0),%0 \n" + "pshufb %%xmm6,%%xmm0 \n" + "pshufb %%xmm6,%%xmm1 \n" + "pshufb %%xmm6,%%xmm2 \n" + "pshufb %%xmm6,%%xmm3 \n" + "movdqa %%xmm1,%%xmm4 \n" + "psrldq $0x4,%%xmm1 \n" + "pslldq $0xc,%%xmm4 \n" + "movdqa %%xmm2,%%xmm5 \n" + "por %%xmm4,%%xmm0 \n" + "pslldq $0x8,%%xmm5 \n" + "movdqu %%xmm0,(%1) \n" + "por %%xmm5,%%xmm1 \n" + "psrldq $0x8,%%xmm2 \n" + "pslldq $0x4,%%xmm3 \n" + "por %%xmm3,%%xmm2 \n" + "movdqu %%xmm1,0x10(%1) \n" + "movdqu %%xmm2,0x20(%1) \n" + "lea 0x30(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "m"(kShuffleMaskARGBToRGB24[0]) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6"); } +#endif // HAS_ARGBTORGB24ROW_SSSE3 +#ifdef HAS_ARGBTORAWROW_SSSE3 void ARGBToRAWRow_SSSE3(const uint8_t* src, uint8_t* dst, int width) { - asm volatile( + asm volatile("movdqa %3,%%xmm6 \n" - "movdqa %3,%%xmm6 \n" - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x30(%0),%%xmm3 \n" - "lea 0x40(%0),%0 \n" - "pshufb %%xmm6,%%xmm0 \n" - "pshufb %%xmm6,%%xmm1 \n" - "pshufb %%xmm6,%%xmm2 \n" - "pshufb %%xmm6,%%xmm3 \n" - "movdqa %%xmm1,%%xmm4 \n" - "psrldq $0x4,%%xmm1 \n" - "pslldq $0xc,%%xmm4 \n" - "movdqa %%xmm2,%%xmm5 \n" - "por %%xmm4,%%xmm0 \n" - "pslldq $0x8,%%xmm5 \n" - "movdqu %%xmm0,(%1) \n" - "por %%xmm5,%%xmm1 \n" - "psrldq $0x8,%%xmm2 \n" - "pslldq $0x4,%%xmm3 \n" - "por %%xmm3,%%xmm2 \n" - "movdqu %%xmm1,0x10(%1) \n" - "movdqu %%xmm2,0x20(%1) \n" - "lea 0x30(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "m"(kShuffleMaskARGBToRAW) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x20(%0),%%xmm2 \n" + "movdqu 0x30(%0),%%xmm3 \n" + "lea 0x40(%0),%0 \n" + "pshufb %%xmm6,%%xmm0 \n" + "pshufb %%xmm6,%%xmm1 \n" + "pshufb %%xmm6,%%xmm2 \n" + "pshufb %%xmm6,%%xmm3 \n" + "movdqa %%xmm1,%%xmm4 \n" + "psrldq $0x4,%%xmm1 \n" + "pslldq $0xc,%%xmm4 \n" + "movdqa %%xmm2,%%xmm5 \n" + "por %%xmm4,%%xmm0 \n" + "pslldq $0x8,%%xmm5 \n" + "movdqu %%xmm0,(%1) \n" + "por %%xmm5,%%xmm1 \n" + "psrldq $0x8,%%xmm2 \n" + "pslldq $0x4,%%xmm3 \n" + "por %%xmm3,%%xmm2 \n" + "movdqu %%xmm1,0x10(%1) \n" + "movdqu %%xmm2,0x20(%1) \n" + "lea 0x30(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "m"(kShuffleMaskARGBToRAW) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6"); } +#endif // HAS_ARGBTORAWROW_SSSE3 #ifdef HAS_ARGBTORGB24ROW_AVX2 // vpermd for 12+12 to 24 @@ -511,133 +1200,187 @@ static const lvec32 kPermdRGB24_AVX = {0, 1, 2, 4, 5, 6, 3, 7}; void ARGBToRGB24Row_AVX2(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "vbroadcastf128 %3,%%ymm6 \n" - "vmovdqa %4,%%ymm7 \n" + "vbroadcasti128 %3,%%ymm6 \n" + "vmovdqa %4,%%ymm7 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vmovdqu 0x40(%0),%%ymm2 \n" - "vmovdqu 0x60(%0),%%ymm3 \n" - "lea 0x80(%0),%0 \n" - "vpshufb %%ymm6,%%ymm0,%%ymm0 \n" // xxx0yyy0 - "vpshufb %%ymm6,%%ymm1,%%ymm1 \n" - "vpshufb %%ymm6,%%ymm2,%%ymm2 \n" - "vpshufb %%ymm6,%%ymm3,%%ymm3 \n" - "vpermd %%ymm0,%%ymm7,%%ymm0 \n" // pack to 24 bytes - "vpermd %%ymm1,%%ymm7,%%ymm1 \n" - "vpermd %%ymm2,%%ymm7,%%ymm2 \n" - "vpermd %%ymm3,%%ymm7,%%ymm3 \n" - "vpermq $0x3f,%%ymm1,%%ymm4 \n" // combine 24 + 8 - "vpor %%ymm4,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,(%1) \n" - "vpermq $0xf9,%%ymm1,%%ymm1 \n" // combine 16 + 16 - "vpermq $0x4f,%%ymm2,%%ymm4 \n" - "vpor %%ymm4,%%ymm1,%%ymm1 \n" - "vmovdqu %%ymm1,0x20(%1) \n" - "vpermq $0xfe,%%ymm2,%%ymm2 \n" // combine 8 + 24 - "vpermq $0x93,%%ymm3,%%ymm3 \n" - "vpor %%ymm3,%%ymm2,%%ymm2 \n" - "vmovdqu %%ymm2,0x40(%1) \n" - "lea 0x60(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "m"(kShuffleMaskARGBToRGB24), // %3 - "m"(kPermdRGB24_AVX) // %4 + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu 0x40(%0),%%ymm2 \n" + "vmovdqu 0x60(%0),%%ymm3 \n" + "lea 0x80(%0),%0 \n" + "vpshufb %%ymm6,%%ymm0,%%ymm0 \n" // xxx0yyy0 + "vpshufb %%ymm6,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm6,%%ymm2,%%ymm2 \n" + "vpshufb %%ymm6,%%ymm3,%%ymm3 \n" + "vpermd %%ymm0,%%ymm7,%%ymm0 \n" // pack to 24 bytes + "vpermd %%ymm1,%%ymm7,%%ymm1 \n" + "vpermd %%ymm2,%%ymm7,%%ymm2 \n" + "vpermd %%ymm3,%%ymm7,%%ymm3 \n" + "vpermq $0x3f,%%ymm1,%%ymm4 \n" // combine 24 + 8 + "vpor %%ymm4,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "vpermq $0xf9,%%ymm1,%%ymm1 \n" // combine 16 + 16 + "vpermq $0x4f,%%ymm2,%%ymm4 \n" + "vpor %%ymm4,%%ymm1,%%ymm1 \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "vpermq $0xfe,%%ymm2,%%ymm2 \n" // combine 8 + 24 + "vpermq $0x93,%%ymm3,%%ymm3 \n" + "vpor %%ymm3,%%ymm2,%%ymm2 \n" + "vmovdqu %%ymm2,0x40(%1) \n" + "lea 0x60(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "m"(kShuffleMaskARGBToRGB24[0]), // %3 + "m"(kPermdRGB24_AVX) // %4 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); } -#endif +#endif // HAS_ARGBTORGB24ROW_AVX2 -#ifdef HAS_ARGBTORGB24ROW_AVX512VBMI -// Shuffle table for converting ARGBToRGB24 -static const ulvec8 kPermARGBToRGB24_0 = { - 0u, 1u, 2u, 4u, 5u, 6u, 8u, 9u, 10u, 12u, 13u, - 14u, 16u, 17u, 18u, 20u, 21u, 22u, 24u, 25u, 26u, 28u, - 29u, 30u, 32u, 33u, 34u, 36u, 37u, 38u, 40u, 41u}; -static const ulvec8 kPermARGBToRGB24_1 = { - 10u, 12u, 13u, 14u, 16u, 17u, 18u, 20u, 21u, 22u, 24u, - 25u, 26u, 28u, 29u, 30u, 32u, 33u, 34u, 36u, 37u, 38u, - 40u, 41u, 42u, 44u, 45u, 46u, 48u, 49u, 50u, 52u}; -static const ulvec8 kPermARGBToRGB24_2 = { - 21u, 22u, 24u, 25u, 26u, 28u, 29u, 30u, 32u, 33u, 34u, - 36u, 37u, 38u, 40u, 41u, 42u, 44u, 45u, 46u, 48u, 49u, - 50u, 52u, 53u, 54u, 56u, 57u, 58u, 60u, 61u, 62u}; - -void ARGBToRGB24Row_AVX512VBMI(const uint8_t* src, uint8_t* dst, int width) { +#if defined(HAS_ARGBTORGB24ROW_AVX512BW) || defined(HAS_ARGBTORAWROW_AVX512BW) +LIBYUV_TARGET_AVX512BW +static inline void ARGBToRGBRow_AVX512BW(const uint8_t* src, + uint8_t* dst, + int width, + const uvec8& shuffler) { + uintptr_t temp; asm volatile( - "vmovdqa %3,%%ymm5 \n" - "vmovdqa %4,%%ymm6 \n" - "vmovdqa %5,%%ymm7 \n" + "vbroadcasti32x4 %[shuffler],%%zmm4 \n" + "vmovdqu32 %[kPermdRGB24_0],%%zmm5 \n" + "vmovdqu32 %[kPermdRGB24_1],%%zmm16 \n" + "vmovdqu32 %[kPermdRGB24_2],%%zmm17 \n" + "sub $0x40,%[width] \n" + "jl 2f \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vmovdqu 0x40(%0),%%ymm2 \n" - "vmovdqu 0x60(%0),%%ymm3 \n" - "lea 0x80(%0),%0 \n" - "vpermt2b %%ymm1,%%ymm5,%%ymm0 \n" - "vpermt2b %%ymm2,%%ymm6,%%ymm1 \n" - "vpermt2b %%ymm3,%%ymm7,%%ymm2 \n" - "vmovdqu %%ymm0,(%1) \n" - "vmovdqu %%ymm1,0x20(%1) \n" - "vmovdqu %%ymm2,0x40(%1) \n" - "lea 0x60(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "m"(kPermARGBToRGB24_0), // %3 - "m"(kPermARGBToRGB24_1), // %4 - "m"(kPermARGBToRGB24_2) // %5 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5", "xmm6", "xmm7"); + "1: \n" + "vmovdqu8 (%[src]),%%zmm0 \n" + "vmovdqu8 0x40(%[src]),%%zmm1 \n" + "vmovdqu8 0x80(%[src]),%%zmm2 \n" + "vmovdqu8 0xc0(%[src]),%%zmm3 \n" + "lea 0x100(%[src]),%[src] \n" + "vpshufb %%zmm4,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm4,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm4,%%zmm2,%%zmm2 \n" + "vpshufb %%zmm4,%%zmm3,%%zmm3 \n" + "vpermt2d %%zmm1,%%zmm5,%%zmm0 \n" + "vpermt2d %%zmm2,%%zmm16,%%zmm1 \n" + "vpermt2d %%zmm3,%%zmm17,%%zmm2 \n" + "vmovdqu8 %%zmm0,(%[dst]) \n" + "vmovdqu8 %%zmm1,0x40(%[dst]) \n" + "vmovdqu8 %%zmm2,0x80(%[dst]) \n" + "lea 0xc0(%[dst]),%[dst] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "shr $0x10,%[temp] \n" + "kmovw %k[temp],%%k2 \n" + "shr $0x10,%[temp] \n" + "kmovw %k[temp],%%k3 \n" + "shr $0x10,%[temp] \n" + "kmovw %k[temp],%%k4 \n" + "vmovdqu32 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src]),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu32 0x80(%[src]),%%zmm2%{%%k3%}%{z%} \n" + "vmovdqu32 0xc0(%[src]),%%zmm3%{%%k4%}%{z%} \n" + + "mov $-1,%[temp] \n" + "lea (%q[width],%q[width],2),%k[width] \n" + "bzhi %q[width],%[temp],%[src] \n" + "kmovq %[src],%%k1 \n" + "xor %k[src],%k[src] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[src] \n" + "bzhi %q[width],%[src],%[src] \n" + "kmovq %[src],%%k2 \n" + "xor %k[src],%k[src] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[src] \n" + "bzhi %q[width],%[src],%[src] \n" + "kmovq %[src],%%k3 \n" + + "vpshufb %%zmm4,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm4,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm4,%%zmm2,%%zmm2 \n" + "vpshufb %%zmm4,%%zmm3,%%zmm3 \n" + "vpermt2d %%zmm1,%%zmm5,%%zmm0 \n" + "vpermt2d %%zmm2,%%zmm16,%%zmm1 \n" + "vpermt2d %%zmm3,%%zmm17,%%zmm2 \n" + "vmovdqu8 %%zmm0,(%[dst])%{%%k1%} \n" + "vmovdqu8 %%zmm1,0x40(%[dst])%{%%k2%} \n" + "vmovdqu8 %%zmm2,0x80(%[dst])%{%%k3%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [width] "+r"(width), // %[width] + [temp] "=&r"(temp) // %[temp] + : [shuffler] "m"(shuffler), [kPermdRGB24_0] "m"(kPermdRGB24_0_AVX512BW), + [kPermdRGB24_1] "m"(kPermdRGB24_1_AVX512BW), + [kPermdRGB24_2] "m"(kPermdRGB24_2_AVX512BW) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm16", + "xmm17", "k1", "k2", "k3", "k4"); } -#endif +#endif // defined(HAS_ARGBTORGB24ROW_AVX512BW) || + // defined(HAS_ARGBTORAWROW_AVX512BW) + +#ifdef HAS_ARGBTORGB24ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToRGB24Row_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + ARGBToRGBRow_AVX512BW(src, dst, width, kShuffleMaskARGBToRGB24[0]); +} +#endif // HAS_ARGBTORGB24ROW_AVX512BW #ifdef HAS_ARGBTORAWROW_AVX2 void ARGBToRAWRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "vbroadcastf128 %3,%%ymm6 \n" - "vmovdqa %4,%%ymm7 \n" + "vbroadcasti128 %3,%%ymm6 \n" + "vmovdqa %4,%%ymm7 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vmovdqu 0x40(%0),%%ymm2 \n" - "vmovdqu 0x60(%0),%%ymm3 \n" - "lea 0x80(%0),%0 \n" - "vpshufb %%ymm6,%%ymm0,%%ymm0 \n" // xxx0yyy0 - "vpshufb %%ymm6,%%ymm1,%%ymm1 \n" - "vpshufb %%ymm6,%%ymm2,%%ymm2 \n" - "vpshufb %%ymm6,%%ymm3,%%ymm3 \n" - "vpermd %%ymm0,%%ymm7,%%ymm0 \n" // pack to 24 bytes - "vpermd %%ymm1,%%ymm7,%%ymm1 \n" - "vpermd %%ymm2,%%ymm7,%%ymm2 \n" - "vpermd %%ymm3,%%ymm7,%%ymm3 \n" - "vpermq $0x3f,%%ymm1,%%ymm4 \n" // combine 24 + 8 - "vpor %%ymm4,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,(%1) \n" - "vpermq $0xf9,%%ymm1,%%ymm1 \n" // combine 16 + 16 - "vpermq $0x4f,%%ymm2,%%ymm4 \n" - "vpor %%ymm4,%%ymm1,%%ymm1 \n" - "vmovdqu %%ymm1,0x20(%1) \n" - "vpermq $0xfe,%%ymm2,%%ymm2 \n" // combine 8 + 24 - "vpermq $0x93,%%ymm3,%%ymm3 \n" - "vpor %%ymm3,%%ymm2,%%ymm2 \n" - "vmovdqu %%ymm2,0x40(%1) \n" - "lea 0x60(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu 0x40(%0),%%ymm2 \n" + "vmovdqu 0x60(%0),%%ymm3 \n" + "lea 0x80(%0),%0 \n" + "vpshufb %%ymm6,%%ymm0,%%ymm0 \n" // xxx0yyy0 + "vpshufb %%ymm6,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm6,%%ymm2,%%ymm2 \n" + "vpshufb %%ymm6,%%ymm3,%%ymm3 \n" + "vpermd %%ymm0,%%ymm7,%%ymm0 \n" // pack to 24 bytes + "vpermd %%ymm1,%%ymm7,%%ymm1 \n" + "vpermd %%ymm2,%%ymm7,%%ymm2 \n" + "vpermd %%ymm3,%%ymm7,%%ymm3 \n" + "vpermq $0x3f,%%ymm1,%%ymm4 \n" // combine 24 + 8 + "vpor %%ymm4,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "vpermq $0xf9,%%ymm1,%%ymm1 \n" // combine 16 + 16 + "vpermq $0x4f,%%ymm2,%%ymm4 \n" + "vpor %%ymm4,%%ymm1,%%ymm1 \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "vpermq $0xfe,%%ymm2,%%ymm2 \n" // combine 8 + 24 + "vpermq $0x93,%%ymm3,%%ymm3 \n" + "vpor %%ymm3,%%ymm2,%%ymm2 \n" + "vmovdqu %%ymm2,0x40(%1) \n" + "lea 0x60(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -646,129 +1389,52 @@ void ARGBToRAWRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); } -#endif +#endif // HAS_ARGBTORAWROW_AVX2 -void ARGBToRGB565Row_SSE2(const uint8_t* src, uint8_t* dst, int width) { - asm volatile( - "pcmpeqb %%xmm3,%%xmm3 \n" - "psrld $0x1b,%%xmm3 \n" - "pcmpeqb %%xmm4,%%xmm4 \n" - "psrld $0x1a,%%xmm4 \n" - "pslld $0x5,%%xmm4 \n" - "pcmpeqb %%xmm5,%%xmm5 \n" - "pslld $0xb,%%xmm5 \n" - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm0,%%xmm2 \n" - "pslld $0x8,%%xmm0 \n" - "psrld $0x3,%%xmm1 \n" - "psrld $0x5,%%xmm2 \n" - "psrad $0x10,%%xmm0 \n" - "pand %%xmm3,%%xmm1 \n" - "pand %%xmm4,%%xmm2 \n" - "pand %%xmm5,%%xmm0 \n" - "por %%xmm2,%%xmm1 \n" - "por %%xmm1,%%xmm0 \n" - "packssdw %%xmm0,%%xmm0 \n" - "lea 0x10(%0),%0 \n" - "movq %%xmm0,(%1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x4,%2 \n" - "jg 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - ::"memory", - "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); -} - -void ARGBToRGB565DitherRow_SSE2(const uint8_t* src, - uint8_t* dst, - const uint32_t dither4, - int width) { - asm volatile( - "movd %3,%%xmm6 \n" - "punpcklbw %%xmm6,%%xmm6 \n" - "movdqa %%xmm6,%%xmm7 \n" - "punpcklwd %%xmm6,%%xmm6 \n" - "punpckhwd %%xmm7,%%xmm7 \n" - "pcmpeqb %%xmm3,%%xmm3 \n" - "psrld $0x1b,%%xmm3 \n" - "pcmpeqb %%xmm4,%%xmm4 \n" - "psrld $0x1a,%%xmm4 \n" - "pslld $0x5,%%xmm4 \n" - "pcmpeqb %%xmm5,%%xmm5 \n" - "pslld $0xb,%%xmm5 \n" - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "paddusb %%xmm6,%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm0,%%xmm2 \n" - "pslld $0x8,%%xmm0 \n" - "psrld $0x3,%%xmm1 \n" - "psrld $0x5,%%xmm2 \n" - "psrad $0x10,%%xmm0 \n" - "pand %%xmm3,%%xmm1 \n" - "pand %%xmm4,%%xmm2 \n" - "pand %%xmm5,%%xmm0 \n" - "por %%xmm2,%%xmm1 \n" - "por %%xmm1,%%xmm0 \n" - "packssdw %%xmm0,%%xmm0 \n" - "lea 0x10(%0),%0 \n" - "movq %%xmm0,(%1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x4,%2 \n" - "jg 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "m"(dither4) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7"); +#ifdef HAS_ARGBTORAWROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToRAWRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + ARGBToRGBRow_AVX512BW(src, dst, width, kShuffleMaskARGBToRAW); } +#endif // HAS_ARGBTORAWROW_AVX512BW #ifdef HAS_ARGBTORGB565DITHERROW_AVX2 void ARGBToRGB565DitherRow_AVX2(const uint8_t* src, uint8_t* dst, - const uint32_t dither4, + uint32_t dither4, int width) { asm volatile( "vbroadcastss %3,%%xmm6 \n" - "vpunpcklbw %%xmm6,%%xmm6,%%xmm6 \n" - "vpermq $0xd8,%%ymm6,%%ymm6 \n" - "vpunpcklwd %%ymm6,%%ymm6,%%ymm6 \n" - "vpcmpeqb %%ymm3,%%ymm3,%%ymm3 \n" - "vpsrld $0x1b,%%ymm3,%%ymm3 \n" - "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" - "vpsrld $0x1a,%%ymm4,%%ymm4 \n" - "vpslld $0x5,%%ymm4,%%ymm4 \n" - "vpslld $0xb,%%ymm3,%%ymm5 \n" + "vpunpcklbw %%xmm6,%%xmm6,%%xmm6 \n" + "vpermq $0xd8,%%ymm6,%%ymm6 \n" + "vpunpcklwd %%ymm6,%%ymm6,%%ymm6 \n" + "vpcmpeqb %%ymm3,%%ymm3,%%ymm3 \n" + "vpsrld $0x1b,%%ymm3,%%ymm3 \n" + "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" + "vpsrld $0x1a,%%ymm4,%%ymm4 \n" + "vpslld $0x5,%%ymm4,%%ymm4 \n" + "vpslld $0xb,%%ymm3,%%ymm5 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vpaddusb %%ymm6,%%ymm0,%%ymm0 \n" - "vpsrld $0x5,%%ymm0,%%ymm2 \n" - "vpsrld $0x3,%%ymm0,%%ymm1 \n" - "vpsrld $0x8,%%ymm0,%%ymm0 \n" - "vpand %%ymm4,%%ymm2,%%ymm2 \n" - "vpand %%ymm3,%%ymm1,%%ymm1 \n" - "vpand %%ymm5,%%ymm0,%%ymm0 \n" - "vpor %%ymm2,%%ymm1,%%ymm1 \n" - "vpor %%ymm1,%%ymm0,%%ymm0 \n" - "vpackusdw %%ymm0,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "lea 0x20(%0),%0 \n" - "vmovdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpaddusb %%ymm6,%%ymm0,%%ymm0 \n" + "vpsrld $0x5,%%ymm0,%%ymm2 \n" + "vpsrld $0x3,%%ymm0,%%ymm1 \n" + "vpsrld $0x8,%%ymm0,%%ymm0 \n" + "vpand %%ymm4,%%ymm2,%%ymm2 \n" + "vpand %%ymm3,%%ymm1,%%ymm1 \n" + "vpand %%ymm5,%%ymm0,%%ymm0 \n" + "vpor %%ymm2,%%ymm1,%%ymm1 \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" + "vpackusdw %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "lea 0x20(%0),%0 \n" + "vmovdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -778,76 +1444,247 @@ void ARGBToRGB565DitherRow_AVX2(const uint8_t* src, } #endif // HAS_ARGBTORGB565DITHERROW_AVX2 -void ARGBToARGB1555Row_SSE2(const uint8_t* src, uint8_t* dst, int width) { +#ifdef HAS_ARGBTORGB565DITHERROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToRGB565DitherRow_AVX512BW(const uint8_t* src, + uint8_t* dst, + uint32_t dither4, + int width) { + uintptr_t temp; asm volatile( - "pcmpeqb %%xmm4,%%xmm4 \n" - "psrld $0x1b,%%xmm4 \n" - "movdqa %%xmm4,%%xmm5 \n" - "pslld $0x5,%%xmm5 \n" - "movdqa %%xmm4,%%xmm6 \n" - "pslld $0xa,%%xmm6 \n" - "pcmpeqb %%xmm7,%%xmm7 \n" - "pslld $0xf,%%xmm7 \n" + "vmovd %[dither4],%%xmm6 \n" + "vpunpcklbw %%xmm6,%%xmm6,%%xmm6 \n" + "vpunpcklwd %%xmm6,%%xmm6,%%xmm6 \n" + "vshufi32x4 $0x00,%%zmm6,%%zmm6,%%zmm6 \n" + "vpternlogd $0xff,%%zmm3,%%zmm3,%%zmm3 \n" + "vpsrld $0x1b,%%zmm3,%%zmm3 \n" + "vpternlogd $0xff,%%zmm4,%%zmm4,%%zmm4 \n" + "vpsrld $0x1a,%%zmm4,%%zmm4 \n" + "vpslld $0x5,%%zmm4,%%zmm4 \n" + "vpslld $0xb,%%zmm3,%%zmm5 \n" + "sub $0x10,%2 \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm0,%%xmm2 \n" - "movdqa %%xmm0,%%xmm3 \n" - "psrad $0x10,%%xmm0 \n" - "psrld $0x3,%%xmm1 \n" - "psrld $0x6,%%xmm2 \n" - "psrld $0x9,%%xmm3 \n" - "pand %%xmm7,%%xmm0 \n" - "pand %%xmm4,%%xmm1 \n" - "pand %%xmm5,%%xmm2 \n" - "pand %%xmm6,%%xmm3 \n" - "por %%xmm1,%%xmm0 \n" - "por %%xmm3,%%xmm2 \n" - "por %%xmm2,%%xmm0 \n" - "packssdw %%xmm0,%%xmm0 \n" - "lea 0x10(%0),%0 \n" - "movq %%xmm0,(%1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x4,%2 \n" - "jg 1b \n" + "1: \n" + "vmovdqu32 (%0),%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vpaddusb %%zmm6,%%zmm0,%%zmm0 \n" + "vpsrld $0x3,%%zmm0,%%zmm1 \n" + "vpsrld $0x5,%%zmm0,%%zmm2 \n" + "vpsrld $0x8,%%zmm0,%%zmm0 \n" + "vpandd %%zmm3,%%zmm1,%%zmm1 \n" + "vpandd %%zmm4,%%zmm2,%%zmm2 \n" + "vpandd %%zmm5,%%zmm0,%%zmm0 \n" + "vpternlogd $0xfe,%%zmm2,%%zmm1,%%zmm0 \n" + "vpmovdw %%zmm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%2 \n" + "jle 99f \n" + "mov $-1,%k[temp] \n" + "bzhi %k2,%k[temp],%k[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpaddusb %%zmm6,%%zmm0,%%zmm0 \n" + "vpsrld $0x3,%%zmm0,%%zmm1 \n" + "vpsrld $0x5,%%zmm0,%%zmm2 \n" + "vpsrld $0x8,%%zmm0,%%zmm0 \n" + "vpandd %%zmm3,%%zmm1,%%zmm1 \n" + "vpandd %%zmm4,%%zmm2,%%zmm2 \n" + "vpandd %%zmm5,%%zmm0,%%zmm0 \n" + "vpternlogd $0xfe,%%zmm2,%%zmm1,%%zmm0 \n" + "vpmovdw %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : [dither4] "r"(dither4) // %[dither4] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "k1"); +} +#endif // HAS_ARGBTORGB565DITHERROW_AVX512BW + +#ifdef HAS_ARGBTORGB565ROW_AVX2 +void ARGBToRGB565Row_AVX2(const uint8_t* src, uint8_t* dst, int width) { + asm volatile( + "vpcmpeqb %%ymm3,%%ymm3,%%ymm3 \n" + "vpsrld $0x1b,%%ymm3,%%ymm3 \n" + "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" + "vpsrld $0x1a,%%ymm4,%%ymm4 \n" + "vpslld $0x5,%%ymm4,%%ymm4 \n" + "vpslld $0xb,%%ymm3,%%ymm5 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpsrld $0x5,%%ymm0,%%ymm2 \n" + "vpsrld $0x3,%%ymm0,%%ymm1 \n" + "vpsrld $0x8,%%ymm0,%%ymm0 \n" + "vpand %%ymm4,%%ymm2,%%ymm2 \n" + "vpand %%ymm3,%%ymm1,%%ymm1 \n" + "vpand %%ymm5,%%ymm0,%%ymm0 \n" + "vpor %%ymm2,%%ymm1,%%ymm1 \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" + "vpackusdw %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "lea 0x20(%0),%0 \n" + "vmovdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 - ::"memory", - "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); } +#endif // HAS_ARGBTORGB565ROW_AVX2 -void ARGBToARGB4444Row_SSE2(const uint8_t* src, uint8_t* dst, int width) { +#ifdef HAS_ARGBTORGB565ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToRGB565Row_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + uintptr_t temp; asm volatile( - "pcmpeqb %%xmm4,%%xmm4 \n" - "psllw $0xc,%%xmm4 \n" - "movdqa %%xmm4,%%xmm3 \n" - "psrlw $0x8,%%xmm3 \n" + "vpternlogd $0xff,%%zmm3,%%zmm3,%%zmm3 \n" + "vpsrld $0x1b,%%zmm3,%%zmm3 \n" + "vpternlogd $0xff,%%zmm4,%%zmm4,%%zmm4 \n" + "vpsrld $0x1a,%%zmm4,%%zmm4 \n" + "vpslld $0x5,%%zmm4,%%zmm4 \n" + "vpslld $0xb,%%zmm3,%%zmm5 \n" + "sub $0x10,%2 \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "pand %%xmm3,%%xmm0 \n" - "pand %%xmm4,%%xmm1 \n" - "psrlq $0x4,%%xmm0 \n" - "psrlq $0x8,%%xmm1 \n" - "por %%xmm1,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "lea 0x10(%0),%0 \n" - "movq %%xmm0,(%1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x4,%2 \n" - "jg 1b \n" + "1: \n" + "vmovdqu32 (%0),%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vpsrld $0x3,%%zmm0,%%zmm1 \n" + "vpsrld $0x5,%%zmm0,%%zmm2 \n" + "vpsrld $0x8,%%zmm0,%%zmm0 \n" + "vpandd %%zmm3,%%zmm1,%%zmm1 \n" + "vpandd %%zmm4,%%zmm2,%%zmm2 \n" + "vpandd %%zmm5,%%zmm0,%%zmm0 \n" + "vpternlogd $0xfe,%%zmm2,%%zmm1,%%zmm0 \n" + "vpmovdw %%zmm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%2 \n" + "jle 99f \n" + "mov $-1,%k[temp] \n" + "bzhi %k2,%k[temp],%k[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpsrld $0x3,%%zmm0,%%zmm1 \n" + "vpsrld $0x5,%%zmm0,%%zmm2 \n" + "vpsrld $0x8,%%zmm0,%%zmm0 \n" + "vpandd %%zmm3,%%zmm1,%%zmm1 \n" + "vpandd %%zmm4,%%zmm2,%%zmm2 \n" + "vpandd %%zmm5,%%zmm0,%%zmm0 \n" + "vpternlogd $0xfe,%%zmm2,%%zmm1,%%zmm0 \n" + "vpmovdw %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "k1"); +} +#endif // HAS_ARGBTORGB565ROW_AVX512BW + +#ifdef HAS_ARGBTOARGB1555ROW_AVX2 +void ARGBToARGB1555Row_AVX2(const uint8_t* src, uint8_t* dst, int width) { + asm volatile( + "vpcmpeqb %%ymm3,%%ymm3,%%ymm3 \n" + "vpslld $0x1f,%%ymm3,%%ymm6 \n" + "vpsrld $0x10,%%ymm6,%%ymm6 \n" + "vpsrld $0x1b,%%ymm3,%%ymm3 \n" + "vpslld $0x5,%%ymm3,%%ymm4 \n" + "vpslld $0xa,%%ymm3,%%ymm5 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpsrld $0x6,%%ymm0,%%ymm2 \n" + "vpsrld $0x3,%%ymm0,%%ymm1 \n" + "vpsrld $0x10,%%ymm0,%%ymm7 \n" + "vpsrld $0x9,%%ymm0,%%ymm0 \n" + "vpand %%ymm4,%%ymm2,%%ymm2 \n" + "vpand %%ymm3,%%ymm1,%%ymm1 \n" + "vpand %%ymm6,%%ymm7,%%ymm7 \n" + "vpand %%ymm5,%%ymm0,%%ymm0 \n" + "vpor %%ymm2,%%ymm1,%%ymm1 \n" + "vpor %%ymm7,%%ymm0,%%ymm0 \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" + "vpackusdw %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "lea 0x20(%0),%0 \n" + "vmovdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 - ::"memory", - "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); } -#endif // HAS_RGB24TOARGBROW_SSSE3 +#endif // HAS_ARGBTOARGB1555ROW_AVX2 + +#ifdef HAS_ARGBTOARGB4444ROW_AVX2 +void ARGBToARGB4444Row_AVX2(const uint8_t* src, uint8_t* dst, int width) { + asm volatile( + "vpcmpeqb %%ymm3,%%ymm3,%%ymm3 \n" + "vpsrld $0x1c,%%ymm3,%%ymm3 \n" + "vpslld $0x4,%%ymm3,%%ymm4 \n" + "vpslld $0x8,%%ymm3,%%ymm5 \n" + "vpslld $0xc,%%ymm3,%%ymm6 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpsrld $0x8,%%ymm0,%%ymm2 \n" + "vpsrld $0x4,%%ymm0,%%ymm1 \n" + "vpsrld $0x10,%%ymm0,%%ymm7 \n" + "vpsrld $0xc,%%ymm0,%%ymm0 \n" + "vpand %%ymm4,%%ymm2,%%ymm2 \n" + "vpand %%ymm3,%%ymm1,%%ymm1 \n" + "vpand %%ymm6,%%ymm7,%%ymm7 \n" + "vpand %%ymm5,%%ymm0,%%ymm0 \n" + "vpor %%ymm2,%%ymm1,%%ymm1 \n" + "vpor %%ymm7,%%ymm0,%%ymm0 \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" + "vpackusdw %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "lea 0x20(%0),%0 \n" + "vmovdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_ARGBTOARGB4444ROW_AVX2 /* @@ -882,33 +1719,34 @@ static const uint32_t kMaskRB10 = 0x3ff003ff; static const uint32_t kMaskAG10 = 0xc000ff00; static const uint32_t kMulAG10 = 64 * 65536 + 1028; +#ifdef HAS_ARGBTOAR30ROW_SSSE3 void ARGBToAR30Row_SSSE3(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "movdqa %3,%%xmm2 \n" // shuffler for RB - "movd %4,%%xmm3 \n" // multipler for RB - "movd %5,%%xmm4 \n" // mask for R10 B10 - "movd %6,%%xmm5 \n" // mask for AG - "movd %7,%%xmm6 \n" // multipler for AG - "pshufd $0x0,%%xmm3,%%xmm3 \n" - "pshufd $0x0,%%xmm4,%%xmm4 \n" - "pshufd $0x0,%%xmm5,%%xmm5 \n" - "pshufd $0x0,%%xmm6,%%xmm6 \n" - "sub %0,%1 \n" + "movdqa %3,%%xmm2 \n" // shuffler for RB + "movd %4,%%xmm3 \n" // multipler for RB + "movd %5,%%xmm4 \n" // mask for R10 B10 + "movd %6,%%xmm5 \n" // mask for AG + "movd %7,%%xmm6 \n" // multipler for AG + "pshufd $0x0,%%xmm3,%%xmm3 \n" + "pshufd $0x0,%%xmm4,%%xmm4 \n" + "pshufd $0x0,%%xmm5,%%xmm5 \n" + "pshufd $0x0,%%xmm6,%%xmm6 \n" + "sub %0,%1 \n" - "1: \n" - "movdqu (%0),%%xmm0 \n" // fetch 4 ARGB pixels - "movdqa %%xmm0,%%xmm1 \n" - "pshufb %%xmm2,%%xmm1 \n" // R0B0 - "pand %%xmm5,%%xmm0 \n" // A0G0 - "pmulhuw %%xmm3,%%xmm1 \n" // X2 R16 X4 B10 - "pmulhuw %%xmm6,%%xmm0 \n" // X10 A2 X10 G10 - "pand %%xmm4,%%xmm1 \n" // X2 R10 X10 B10 - "pslld $10,%%xmm0 \n" // A2 x10 G10 x10 - "por %%xmm1,%%xmm0 \n" // A2 R10 G10 B10 - "movdqu %%xmm0,(%1,%0) \n" // store 4 AR30 pixels - "add $0x10,%0 \n" - "sub $0x4,%2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" // fetch 4 ARGB pixels + "movdqa %%xmm0,%%xmm1 \n" + "pshufb %%xmm2,%%xmm1 \n" // R0B0 + "pand %%xmm5,%%xmm0 \n" // A0G0 + "pmulhuw %%xmm3,%%xmm1 \n" // X2 R16 X4 B10 + "pmulhuw %%xmm6,%%xmm0 \n" // X10 A2 X10 G10 + "pand %%xmm4,%%xmm1 \n" // X2 R10 X10 B10 + "pslld $10,%%xmm0 \n" // A2 x10 G10 x10 + "por %%xmm1,%%xmm0 \n" // A2 R10 G10 B10 + "movdqu %%xmm0,(%1,%0) \n" // store 4 AR30 pixels + "add $0x10,%0 \n" + "sub $0x4,%2 \n" + "jg 1b \n" : "+r"(src), // %0 "+r"(dst), // %1 @@ -920,34 +1758,36 @@ void ARGBToAR30Row_SSSE3(const uint8_t* src, uint8_t* dst, int width) { "m"(kMulAG10) // %7 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); } +#endif // HAS_ARGBTOAR30ROW_SSSE3 +#ifdef HAS_ABGRTOAR30ROW_SSSE3 void ABGRToAR30Row_SSSE3(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "movdqa %3,%%xmm2 \n" // shuffler for RB - "movd %4,%%xmm3 \n" // multipler for RB - "movd %5,%%xmm4 \n" // mask for R10 B10 - "movd %6,%%xmm5 \n" // mask for AG - "movd %7,%%xmm6 \n" // multipler for AG - "pshufd $0x0,%%xmm3,%%xmm3 \n" - "pshufd $0x0,%%xmm4,%%xmm4 \n" - "pshufd $0x0,%%xmm5,%%xmm5 \n" - "pshufd $0x0,%%xmm6,%%xmm6 \n" - "sub %0,%1 \n" + "movdqa %3,%%xmm2 \n" // shuffler for RB + "movd %4,%%xmm3 \n" // multipler for RB + "movd %5,%%xmm4 \n" // mask for R10 B10 + "movd %6,%%xmm5 \n" // mask for AG + "movd %7,%%xmm6 \n" // multipler for AG + "pshufd $0x0,%%xmm3,%%xmm3 \n" + "pshufd $0x0,%%xmm4,%%xmm4 \n" + "pshufd $0x0,%%xmm5,%%xmm5 \n" + "pshufd $0x0,%%xmm6,%%xmm6 \n" + "sub %0,%1 \n" - "1: \n" - "movdqu (%0),%%xmm0 \n" // fetch 4 ABGR pixels - "movdqa %%xmm0,%%xmm1 \n" - "pshufb %%xmm2,%%xmm1 \n" // R0B0 - "pand %%xmm5,%%xmm0 \n" // A0G0 - "pmulhuw %%xmm3,%%xmm1 \n" // X2 R16 X4 B10 - "pmulhuw %%xmm6,%%xmm0 \n" // X10 A2 X10 G10 - "pand %%xmm4,%%xmm1 \n" // X2 R10 X10 B10 - "pslld $10,%%xmm0 \n" // A2 x10 G10 x10 - "por %%xmm1,%%xmm0 \n" // A2 R10 G10 B10 - "movdqu %%xmm0,(%1,%0) \n" // store 4 AR30 pixels - "add $0x10,%0 \n" - "sub $0x4,%2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" // fetch 4 ABGR pixels + "movdqa %%xmm0,%%xmm1 \n" + "pshufb %%xmm2,%%xmm1 \n" // R0B0 + "pand %%xmm5,%%xmm0 \n" // A0G0 + "pmulhuw %%xmm3,%%xmm1 \n" // X2 R16 X4 B10 + "pmulhuw %%xmm6,%%xmm0 \n" // X10 A2 X10 G10 + "pand %%xmm4,%%xmm1 \n" // X2 R10 X10 B10 + "pslld $10,%%xmm0 \n" // A2 x10 G10 x10 + "por %%xmm1,%%xmm0 \n" // A2 R10 G10 B10 + "movdqu %%xmm0,(%1,%0) \n" // store 4 AR30 pixels + "add $0x10,%0 \n" + "sub $0x4,%2 \n" + "jg 1b \n" : "+r"(src), // %0 "+r"(dst), // %1 @@ -959,31 +1799,32 @@ void ABGRToAR30Row_SSSE3(const uint8_t* src, uint8_t* dst, int width) { "m"(kMulAG10) // %7 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); } +#endif // HAS_ABGRTOAR30ROW_SSSE3 #ifdef HAS_ARGBTOAR30ROW_AVX2 void ARGBToAR30Row_AVX2(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "vbroadcastf128 %3,%%ymm2 \n" // shuffler for RB - "vbroadcastss %4,%%ymm3 \n" // multipler for RB - "vbroadcastss %5,%%ymm4 \n" // mask for R10 B10 - "vbroadcastss %6,%%ymm5 \n" // mask for AG - "vbroadcastss %7,%%ymm6 \n" // multipler for AG - "sub %0,%1 \n" + "vbroadcasti128 %3,%%ymm2 \n" // shuffler for RB + "vbroadcastss %4,%%ymm3 \n" // multipler for RB + "vbroadcastss %5,%%ymm4 \n" // mask for R10 B10 + "vbroadcastss %6,%%ymm5 \n" // mask for AG + "vbroadcastss %7,%%ymm6 \n" // multipler for AG + "sub %0,%1 \n" - "1: \n" - "vmovdqu (%0),%%ymm0 \n" // fetch 8 ARGB pixels - "vpshufb %%ymm2,%%ymm0,%%ymm1 \n" // R0B0 - "vpand %%ymm5,%%ymm0,%%ymm0 \n" // A0G0 - "vpmulhuw %%ymm3,%%ymm1,%%ymm1 \n" // X2 R16 X4 B10 - "vpmulhuw %%ymm6,%%ymm0,%%ymm0 \n" // X10 A2 X10 G10 - "vpand %%ymm4,%%ymm1,%%ymm1 \n" // X2 R10 X10 B10 - "vpslld $10,%%ymm0,%%ymm0 \n" // A2 x10 G10 x10 - "vpor %%ymm1,%%ymm0,%%ymm0 \n" // A2 R10 G10 B10 - "vmovdqu %%ymm0,(%1,%0) \n" // store 8 AR30 pixels - "add $0x20,%0 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" // fetch 8 ARGB pixels + "vpshufb %%ymm2,%%ymm0,%%ymm1 \n" // R0B0 + "vpand %%ymm5,%%ymm0,%%ymm0 \n" // A0G0 + "vpmulhuw %%ymm3,%%ymm1,%%ymm1 \n" // X2 R16 X4 B10 + "vpmulhuw %%ymm6,%%ymm0,%%ymm0 \n" // X10 A2 X10 G10 + "vpand %%ymm4,%%ymm1,%%ymm1 \n" // X2 R10 X10 B10 + "vpslld $10,%%ymm0,%%ymm0 \n" // A2 x10 G10 x10 + "vpor %%ymm1,%%ymm0,%%ymm0 \n" // A2 R10 G10 B10 + "vmovdqu %%ymm0,(%1,%0) \n" // store 8 AR30 pixels + "add $0x20,%0 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 @@ -995,32 +1836,32 @@ void ARGBToAR30Row_AVX2(const uint8_t* src, uint8_t* dst, int width) { "m"(kMulAG10) // %7 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); } -#endif +#endif // HAS_ARGBTOAR30ROW_AVX2 #ifdef HAS_ABGRTOAR30ROW_AVX2 void ABGRToAR30Row_AVX2(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "vbroadcastf128 %3,%%ymm2 \n" // shuffler for RB - "vbroadcastss %4,%%ymm3 \n" // multipler for RB - "vbroadcastss %5,%%ymm4 \n" // mask for R10 B10 - "vbroadcastss %6,%%ymm5 \n" // mask for AG - "vbroadcastss %7,%%ymm6 \n" // multipler for AG - "sub %0,%1 \n" + "vbroadcasti128 %3,%%ymm2 \n" // shuffler for RB + "vbroadcastss %4,%%ymm3 \n" // multipler for RB + "vbroadcastss %5,%%ymm4 \n" // mask for R10 B10 + "vbroadcastss %6,%%ymm5 \n" // mask for AG + "vbroadcastss %7,%%ymm6 \n" // multipler for AG + "sub %0,%1 \n" - "1: \n" - "vmovdqu (%0),%%ymm0 \n" // fetch 8 ABGR pixels - "vpshufb %%ymm2,%%ymm0,%%ymm1 \n" // R0B0 - "vpand %%ymm5,%%ymm0,%%ymm0 \n" // A0G0 - "vpmulhuw %%ymm3,%%ymm1,%%ymm1 \n" // X2 R16 X4 B10 - "vpmulhuw %%ymm6,%%ymm0,%%ymm0 \n" // X10 A2 X10 G10 - "vpand %%ymm4,%%ymm1,%%ymm1 \n" // X2 R10 X10 B10 - "vpslld $10,%%ymm0,%%ymm0 \n" // A2 x10 G10 x10 - "vpor %%ymm1,%%ymm0,%%ymm0 \n" // A2 R10 G10 B10 - "vmovdqu %%ymm0,(%1,%0) \n" // store 8 AR30 pixels - "add $0x20,%0 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" // fetch 8 ABGR pixels + "vpshufb %%ymm2,%%ymm0,%%ymm1 \n" // R0B0 + "vpand %%ymm5,%%ymm0,%%ymm0 \n" // A0G0 + "vpmulhuw %%ymm3,%%ymm1,%%ymm1 \n" // X2 R16 X4 B10 + "vpmulhuw %%ymm6,%%ymm0,%%ymm0 \n" // X10 A2 X10 G10 + "vpand %%ymm4,%%ymm1,%%ymm1 \n" // X2 R10 X10 B10 + "vpslld $10,%%ymm0,%%ymm0 \n" // A2 x10 G10 x10 + "vpor %%ymm1,%%ymm0,%%ymm0 \n" // A2 R10 G10 B10 + "vmovdqu %%ymm0,(%1,%0) \n" // store 8 AR30 pixels + "add $0x20,%0 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 @@ -1032,932 +1873,2120 @@ void ABGRToAR30Row_AVX2(const uint8_t* src, uint8_t* dst, int width) { "m"(kMulAG10) // %7 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); } +#endif // HAS_ABGRTOAR30ROW_AVX2 + +#if defined(HAS_AB64TOARGBROW_SSSE3) || defined(HAS_AB64TOARGBROW_AVX2) +static const uvec8 kShuffleARGBToABGR = {2, 1, 0, 3, 6, 5, 4, 7, + 10, 9, 8, 11, 14, 13, 12, 15}; #endif -#ifdef HAS_ARGBTOYROW_SSSE3 -// Convert 16 ARGB pixels (64 bytes) to 16 Y values. -void ARGBToYRow_SSSE3(const uint8_t* src_argb, uint8_t* dst_y, int width) { - asm volatile( - "movdqa %3,%%xmm4 \n" - "movdqa %4,%%xmm5 \n" +#if defined(HAS_ARGBTOAB64ROW_SSSE3) || defined(HAS_ARGBTOAB64ROW_AVX2) +static const uvec8 kShuffleARGBToAB64Lo = {2, 2, 1, 1, 0, 0, 3, 3, + 6, 6, 5, 5, 4, 4, 7, 7}; +static const uvec8 kShuffleARGBToAB64Hi = {10, 10, 9, 9, 8, 8, 11, 11, + 14, 14, 13, 13, 12, 12, 15, 15}; +#endif - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x30(%0),%%xmm3 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm4,%%xmm3 \n" - "lea 0x40(%0),%0 \n" - "phaddw %%xmm1,%%xmm0 \n" - "phaddw %%xmm3,%%xmm2 \n" - "psrlw $0x7,%%xmm0 \n" - "psrlw $0x7,%%xmm2 \n" - "packuswb %%xmm2,%%xmm0 \n" - "paddb %%xmm5,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" +#ifdef HAS_ARGBTOAR64ROW_SSSE3 +void ARGBToAR64Row_SSSE3(const uint8_t* src_argb, + uint16_t* dst_ar64, + int width) { + asm volatile( + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqa %%xmm0,%%xmm1 \n" + "punpcklbw %%xmm0,%%xmm0 \n" + "punpckhbw %%xmm1,%%xmm1 \n" + "movdqu %%xmm0,(%1) \n" + "movdqu %%xmm1,0x10(%1) \n" + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" + "sub $0x4,%2 \n" + "jg 1b \n" : "+r"(src_argb), // %0 - "+r"(dst_y), // %1 + "+r"(dst_ar64), // %1 "+r"(width) // %2 - : "m"(kARGBToY), // %3 - "m"(kAddY16) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + ::"memory", + "cc", "xmm0", "xmm1"); } -#endif // HAS_ARGBTOYROW_SSSE3 +#endif // HAS_ARGBTOAR64ROW_SSSE3 -#ifdef HAS_ARGBTOYJROW_SSSE3 -// Convert 16 ARGB pixels (64 bytes) to 16 YJ values. -// Same as ARGBToYRow but different coefficients, no add 16, but do rounding. -void ARGBToYJRow_SSSE3(const uint8_t* src_argb, uint8_t* dst_y, int width) { +#ifdef HAS_ARGBTOAB64ROW_SSSE3 +void ARGBToAB64Row_SSSE3(const uint8_t* src_argb, + uint16_t* dst_ab64, + int width) { asm volatile( - "movdqa %3,%%xmm4 \n" - "movdqa %4,%%xmm5 \n" + "movdqa %3,%%xmm2 \n" + "movdqa %4,%%xmm3 \n" LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqa %%xmm0,%%xmm1 \n" + "pshufb %%xmm2,%%xmm0 \n" + "pshufb %%xmm3,%%xmm1 \n" + "movdqu %%xmm0,(%1) \n" + "movdqu %%xmm1,0x10(%1) \n" + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" + "sub $0x4,%2 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_ab64), // %1 + "+r"(width) // %2 + : "m"(kShuffleARGBToAB64Lo), // %3 + "m"(kShuffleARGBToAB64Hi) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); +} +#endif // HAS_ARGBTOAB64ROW_SSSE3 - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x30(%0),%%xmm3 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm4,%%xmm3 \n" - "lea 0x40(%0),%0 \n" - "phaddw %%xmm1,%%xmm0 \n" - "phaddw %%xmm3,%%xmm2 \n" - "paddw %%xmm5,%%xmm0 \n" - "paddw %%xmm5,%%xmm2 \n" - "psrlw $0x7,%%xmm0 \n" - "psrlw $0x7,%%xmm2 \n" - "packuswb %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_y), // %1 +#ifdef HAS_AR64TOARGBROW_SSSE3 +void AR64ToARGBRow_SSSE3(const uint16_t* src_ar64, + uint8_t* dst_argb, + int width) { + asm volatile( + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "psrlw $8,%%xmm0 \n" + "psrlw $8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x20(%0),%0 \n" + "lea 0x10(%1),%1 \n" + "sub $0x4,%2 \n" + "jg 1b \n" + : "+r"(src_ar64), // %0 + "+r"(dst_argb), // %1 "+r"(width) // %2 - : "m"(kARGBToYJ), // %3 - "m"(kAddYJ64) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + ::"memory", + "cc", "xmm0", "xmm1"); } -#endif // HAS_ARGBTOYJROW_SSSE3 +#endif // HAS_AR64TOARGBROW_SSSE3 -#ifdef HAS_ARGBTOYROW_AVX2 -// vpermd for vphaddw + vpackuswb vpermd. -static const lvec32 kPermdARGBToY_AVX = {0, 4, 1, 5, 2, 6, 3, 7}; +#ifdef HAS_AB64TOARGBROW_SSSE3 +void AB64ToARGBRow_SSSE3(const uint16_t* src_ab64, + uint8_t* dst_argb, + int width) { + asm volatile("movdqa %3,%%xmm2 \n" -// Convert 32 ARGB pixels (128 bytes) to 32 Y values. -void ARGBToYRow_AVX2(const uint8_t* src_argb, uint8_t* dst_y, int width) { - asm volatile( - "vbroadcastf128 %3,%%ymm4 \n" - "vbroadcastf128 %4,%%ymm5 \n" - "vmovdqu %5,%%ymm6 \n" - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vmovdqu 0x40(%0),%%ymm2 \n" - "vmovdqu 0x60(%0),%%ymm3 \n" - "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" - "vpmaddubsw %%ymm4,%%ymm1,%%ymm1 \n" - "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" - "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" - "lea 0x80(%0),%0 \n" - "vphaddw %%ymm1,%%ymm0,%%ymm0 \n" // mutates. - "vphaddw %%ymm3,%%ymm2,%%ymm2 \n" - "vpsrlw $0x7,%%ymm0,%%ymm0 \n" - "vpsrlw $0x7,%%ymm2,%%ymm2 \n" - "vpackuswb %%ymm2,%%ymm0,%%ymm0 \n" // mutates. - "vpermd %%ymm0,%%ymm6,%%ymm0 \n" // unmutate. - "vpaddb %%ymm5,%%ymm0,%%ymm0 \n" // add 16 for Y - "vmovdqu %%ymm0,(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_argb), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : "m"(kARGBToY), // %3 - "m"(kAddY16), // %4 - "m"(kPermdARGBToY_AVX) // %5 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "psrlw $8,%%xmm0 \n" + "psrlw $8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "pshufb %%xmm2,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x20(%0),%0 \n" + "lea 0x10(%1),%1 \n" + "sub $0x4,%2 \n" + "jg 1b \n" + : "+r"(src_ab64), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "m"(kShuffleARGBToABGR) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } -#endif // HAS_ARGBTOYROW_AVX2 +#endif // HAS_AB64TOARGBROW_SSSE3 -#ifdef HAS_ABGRTOYROW_AVX2 -// Convert 32 ABGR pixels (128 bytes) to 32 Y values. -void ABGRToYRow_AVX2(const uint8_t* src_abgr, uint8_t* dst_y, int width) { - asm volatile( - "vbroadcastf128 %3,%%ymm4 \n" - "vbroadcastf128 %4,%%ymm5 \n" - "vmovdqu %5,%%ymm6 \n" - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vmovdqu 0x40(%0),%%ymm2 \n" - "vmovdqu 0x60(%0),%%ymm3 \n" - "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" - "vpmaddubsw %%ymm4,%%ymm1,%%ymm1 \n" - "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" - "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" - "lea 0x80(%0),%0 \n" - "vphaddw %%ymm1,%%ymm0,%%ymm0 \n" // mutates. - "vphaddw %%ymm3,%%ymm2,%%ymm2 \n" - "vpsrlw $0x7,%%ymm0,%%ymm0 \n" - "vpsrlw $0x7,%%ymm2,%%ymm2 \n" - "vpackuswb %%ymm2,%%ymm0,%%ymm0 \n" // mutates. - "vpermd %%ymm0,%%ymm6,%%ymm0 \n" // unmutate. - "vpaddb %%ymm5,%%ymm0,%%ymm0 \n" // add 16 for Y - "vmovdqu %%ymm0,(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_abgr), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : "m"(kABGRToY), // %3 - "m"(kAddY16), // %4 - "m"(kPermdARGBToY_AVX) // %5 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); -} -#endif // HAS_ABGRTOYROW_AVX2 - - -#ifdef HAS_ARGBTOYJROW_AVX2 -// Convert 32 ARGB pixels (128 bytes) to 32 Y values. -void ARGBToYJRow_AVX2(const uint8_t* src_argb, uint8_t* dst_y, int width) { - asm volatile( - "vbroadcastf128 %3,%%ymm4 \n" - "vbroadcastf128 %4,%%ymm5 \n" - "vmovdqu %5,%%ymm6 \n" - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vmovdqu 0x40(%0),%%ymm2 \n" - "vmovdqu 0x60(%0),%%ymm3 \n" - "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" - "vpmaddubsw %%ymm4,%%ymm1,%%ymm1 \n" - "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" - "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" - "lea 0x80(%0),%0 \n" - "vphaddw %%ymm1,%%ymm0,%%ymm0 \n" // mutates. - "vphaddw %%ymm3,%%ymm2,%%ymm2 \n" - "vpaddw %%ymm5,%%ymm0,%%ymm0 \n" // Add .5 for rounding. - "vpaddw %%ymm5,%%ymm2,%%ymm2 \n" - "vpsrlw $0x7,%%ymm0,%%ymm0 \n" - "vpsrlw $0x7,%%ymm2,%%ymm2 \n" - "vpackuswb %%ymm2,%%ymm0,%%ymm0 \n" // mutates. - "vpermd %%ymm0,%%ymm6,%%ymm0 \n" // unmutate. - "vmovdqu %%ymm0,(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_argb), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : "m"(kARGBToYJ), // %3 - "m"(kAddYJ64), // %4 - "m"(kPermdARGBToY_AVX) // %5 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); -} -#endif // HAS_ARGBTOYJROW_AVX2 - -#ifdef HAS_ARGBTOUVROW_SSSE3 -void ARGBToUVRow_SSSE3(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - asm volatile( - "movdqa %5,%%xmm3 \n" - "movdqa %6,%%xmm4 \n" - "movdqa %7,%%xmm5 \n" - "sub %1,%2 \n" - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x00(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x10(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x20(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm2 \n" - "movdqu 0x30(%0),%%xmm6 \n" - "movdqu 0x30(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm6 \n" - - "lea 0x40(%0),%0 \n" - "movdqa %%xmm0,%%xmm7 \n" - "shufps $0x88,%%xmm1,%%xmm0 \n" - "shufps $0xdd,%%xmm1,%%xmm7 \n" - "pavgb %%xmm7,%%xmm0 \n" - "movdqa %%xmm2,%%xmm7 \n" - "shufps $0x88,%%xmm6,%%xmm2 \n" - "shufps $0xdd,%%xmm6,%%xmm7 \n" - "pavgb %%xmm7,%%xmm2 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm2,%%xmm6 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm3,%%xmm1 \n" - "pmaddubsw %%xmm3,%%xmm6 \n" - "phaddw %%xmm2,%%xmm0 \n" - "phaddw %%xmm6,%%xmm1 \n" - "psraw $0x8,%%xmm0 \n" - "psraw $0x8,%%xmm1 \n" - "packsswb %%xmm1,%%xmm0 \n" - "paddb %%xmm5,%%xmm0 \n" - "movlps %%xmm0,(%1) \n" - "movhps %%xmm0,0x00(%1,%2,1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x10,%3 \n" - "jg 1b \n" - : "+r"(src_argb0), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+rm"(width) // %3 - : "r"((intptr_t)(src_stride_argb)), // %4 - "m"(kARGBToV), // %5 - "m"(kARGBToU), // %6 - "m"(kAddUV128) // %7 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"); -} -#endif // HAS_ARGBTOUVROW_SSSE3 - -#ifdef HAS_ARGBTOUVROW_AVX2 -// vpshufb for vphaddw + vpackuswb packed to shorts. -static const lvec8 kShufARGBToUV_AVX = { - 0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15, - 0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15}; -void ARGBToUVRow_AVX2(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - asm volatile( - "vbroadcastf128 %5,%%ymm5 \n" - "vbroadcastf128 %6,%%ymm6 \n" - "vbroadcastf128 %7,%%ymm7 \n" - "sub %1,%2 \n" - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vmovdqu 0x40(%0),%%ymm2 \n" - "vmovdqu 0x60(%0),%%ymm3 \n" - "vpavgb 0x00(%0,%4,1),%%ymm0,%%ymm0 \n" - "vpavgb 0x20(%0,%4,1),%%ymm1,%%ymm1 \n" - "vpavgb 0x40(%0,%4,1),%%ymm2,%%ymm2 \n" - "vpavgb 0x60(%0,%4,1),%%ymm3,%%ymm3 \n" - "lea 0x80(%0),%0 \n" - "vshufps $0x88,%%ymm1,%%ymm0,%%ymm4 \n" - "vshufps $0xdd,%%ymm1,%%ymm0,%%ymm0 \n" - "vpavgb %%ymm4,%%ymm0,%%ymm0 \n" - "vshufps $0x88,%%ymm3,%%ymm2,%%ymm4 \n" - "vshufps $0xdd,%%ymm3,%%ymm2,%%ymm2 \n" - "vpavgb %%ymm4,%%ymm2,%%ymm2 \n" - - "vpmaddubsw %%ymm7,%%ymm0,%%ymm1 \n" - "vpmaddubsw %%ymm7,%%ymm2,%%ymm3 \n" - "vpmaddubsw %%ymm6,%%ymm0,%%ymm0 \n" - "vpmaddubsw %%ymm6,%%ymm2,%%ymm2 \n" - "vphaddw %%ymm3,%%ymm1,%%ymm1 \n" - "vphaddw %%ymm2,%%ymm0,%%ymm0 \n" - "vpsraw $0x8,%%ymm1,%%ymm1 \n" - "vpsraw $0x8,%%ymm0,%%ymm0 \n" - "vpacksswb %%ymm0,%%ymm1,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vpshufb %8,%%ymm0,%%ymm0 \n" - "vpaddb %%ymm5,%%ymm0,%%ymm0 \n" - - "vextractf128 $0x0,%%ymm0,(%1) \n" - "vextractf128 $0x1,%%ymm0,0x0(%1,%2,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x20,%3 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_argb0), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+rm"(width) // %3 - : "r"((intptr_t)(src_stride_argb)), // %4 - "m"(kAddUV128), // %5 - "m"(kARGBToV), // %6 - "m"(kARGBToU), // %7 - "m"(kShufARGBToUV_AVX) // %8 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7"); -} -#endif // HAS_ARGBTOUVROW_AVX2 - -#ifdef HAS_ABGRTOUVROW_AVX2 -void ABGRToUVRow_AVX2(const uint8_t* src_abgr0, - int src_stride_abgr, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - asm volatile( - "vbroadcastf128 %5,%%ymm5 \n" - "vbroadcastf128 %6,%%ymm6 \n" - "vbroadcastf128 %7,%%ymm7 \n" - "sub %1,%2 \n" - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vmovdqu 0x40(%0),%%ymm2 \n" - "vmovdqu 0x60(%0),%%ymm3 \n" - "vpavgb 0x00(%0,%4,1),%%ymm0,%%ymm0 \n" - "vpavgb 0x20(%0,%4,1),%%ymm1,%%ymm1 \n" - "vpavgb 0x40(%0,%4,1),%%ymm2,%%ymm2 \n" - "vpavgb 0x60(%0,%4,1),%%ymm3,%%ymm3 \n" - "lea 0x80(%0),%0 \n" - "vshufps $0x88,%%ymm1,%%ymm0,%%ymm4 \n" - "vshufps $0xdd,%%ymm1,%%ymm0,%%ymm0 \n" - "vpavgb %%ymm4,%%ymm0,%%ymm0 \n" - "vshufps $0x88,%%ymm3,%%ymm2,%%ymm4 \n" - "vshufps $0xdd,%%ymm3,%%ymm2,%%ymm2 \n" - "vpavgb %%ymm4,%%ymm2,%%ymm2 \n" - - "vpmaddubsw %%ymm7,%%ymm0,%%ymm1 \n" - "vpmaddubsw %%ymm7,%%ymm2,%%ymm3 \n" - "vpmaddubsw %%ymm6,%%ymm0,%%ymm0 \n" - "vpmaddubsw %%ymm6,%%ymm2,%%ymm2 \n" - "vphaddw %%ymm3,%%ymm1,%%ymm1 \n" - "vphaddw %%ymm2,%%ymm0,%%ymm0 \n" - "vpsraw $0x8,%%ymm1,%%ymm1 \n" - "vpsraw $0x8,%%ymm0,%%ymm0 \n" - "vpacksswb %%ymm0,%%ymm1,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vpshufb %8,%%ymm0,%%ymm0 \n" - "vpaddb %%ymm5,%%ymm0,%%ymm0 \n" - - "vextractf128 $0x0,%%ymm0,(%1) \n" - "vextractf128 $0x1,%%ymm0,0x0(%1,%2,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x20,%3 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_abgr0), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+rm"(width) // %3 - : "r"((intptr_t)(src_stride_abgr)), // %4 - "m"(kAddUV128), // %5 - "m"(kABGRToV), // %6 - "m"(kABGRToU), // %7 - "m"(kShufARGBToUV_AVX) // %8 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7"); -} -#endif // HAS_ABGRTOUVROW_AVX2 - -#ifdef HAS_ARGBTOUVJROW_AVX2 -void ARGBToUVJRow_AVX2(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - asm volatile( - "vbroadcastf128 %5,%%ymm5 \n" - "vbroadcastf128 %6,%%ymm6 \n" - "vbroadcastf128 %7,%%ymm7 \n" - "sub %1,%2 \n" - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vmovdqu 0x40(%0),%%ymm2 \n" - "vmovdqu 0x60(%0),%%ymm3 \n" - "vpavgb 0x00(%0,%4,1),%%ymm0,%%ymm0 \n" - "vpavgb 0x20(%0,%4,1),%%ymm1,%%ymm1 \n" - "vpavgb 0x40(%0,%4,1),%%ymm2,%%ymm2 \n" - "vpavgb 0x60(%0,%4,1),%%ymm3,%%ymm3 \n" - "lea 0x80(%0),%0 \n" - "vshufps $0x88,%%ymm1,%%ymm0,%%ymm4 \n" - "vshufps $0xdd,%%ymm1,%%ymm0,%%ymm0 \n" - "vpavgb %%ymm4,%%ymm0,%%ymm0 \n" - "vshufps $0x88,%%ymm3,%%ymm2,%%ymm4 \n" - "vshufps $0xdd,%%ymm3,%%ymm2,%%ymm2 \n" - "vpavgb %%ymm4,%%ymm2,%%ymm2 \n" - - "vpmaddubsw %%ymm7,%%ymm0,%%ymm1 \n" - "vpmaddubsw %%ymm7,%%ymm2,%%ymm3 \n" - "vpmaddubsw %%ymm6,%%ymm0,%%ymm0 \n" - "vpmaddubsw %%ymm6,%%ymm2,%%ymm2 \n" - "vphaddw %%ymm3,%%ymm1,%%ymm1 \n" - "vphaddw %%ymm2,%%ymm0,%%ymm0 \n" - "vpaddw %%ymm5,%%ymm0,%%ymm0 \n" - "vpaddw %%ymm5,%%ymm1,%%ymm1 \n" - "vpsraw $0x8,%%ymm1,%%ymm1 \n" - "vpsraw $0x8,%%ymm0,%%ymm0 \n" - "vpacksswb %%ymm0,%%ymm1,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vpshufb %8,%%ymm0,%%ymm0 \n" - - "vextractf128 $0x0,%%ymm0,(%1) \n" - "vextractf128 $0x1,%%ymm0,0x0(%1,%2,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x20,%3 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_argb0), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+rm"(width) // %3 - : "r"((intptr_t)(src_stride_argb)), // %4 - "m"(kAddUVJ128), // %5 - "m"(kARGBToVJ), // %6 - "m"(kARGBToUJ), // %7 - "m"(kShufARGBToUV_AVX) // %8 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7"); -} -#endif // HAS_ARGBTOUVJROW_AVX2 - -#ifdef HAS_ARGBTOUVJROW_SSSE3 -void ARGBToUVJRow_SSSE3(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, +#ifdef HAS_ARGBTOAR64ROW_AVX2 +void ARGBToAR64Row_AVX2(const uint8_t* src_argb, + uint16_t* dst_ar64, int width) { asm volatile( - "movdqa %5,%%xmm3 \n" - "movdqa %6,%%xmm4 \n" - "movdqa %7,%%xmm5 \n" - "sub %1,%2 \n" - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x00(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x10(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x20(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm2 \n" - "movdqu 0x30(%0),%%xmm6 \n" - "movdqu 0x30(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm6 \n" - - "lea 0x40(%0),%0 \n" - "movdqa %%xmm0,%%xmm7 \n" - "shufps $0x88,%%xmm1,%%xmm0 \n" - "shufps $0xdd,%%xmm1,%%xmm7 \n" - "pavgb %%xmm7,%%xmm0 \n" - "movdqa %%xmm2,%%xmm7 \n" - "shufps $0x88,%%xmm6,%%xmm2 \n" - "shufps $0xdd,%%xmm6,%%xmm7 \n" - "pavgb %%xmm7,%%xmm2 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm2,%%xmm6 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm3,%%xmm1 \n" - "pmaddubsw %%xmm3,%%xmm6 \n" - "phaddw %%xmm2,%%xmm0 \n" - "phaddw %%xmm6,%%xmm1 \n" - "paddw %%xmm5,%%xmm0 \n" - "paddw %%xmm5,%%xmm1 \n" - "psraw $0x8,%%xmm0 \n" - "psraw $0x8,%%xmm1 \n" - "packsswb %%xmm1,%%xmm0 \n" - "movlps %%xmm0,(%1) \n" - "movhps %%xmm0,0x00(%1,%2,1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x10,%3 \n" - "jg 1b \n" - : "+r"(src_argb0), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+rm"(width) // %3 - : "r"((intptr_t)(src_stride_argb)), // %4 - "m"(kARGBToVJ), // %5 - "m"(kARGBToUJ), // %6 - "m"(kAddUVJ128) // %7 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"); + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpunpckhbw %%ymm0,%%ymm0,%%ymm1 \n" + "vpunpcklbw %%ymm0,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "lea 0x20(%0),%0 \n" + "lea 0x40(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_ar64), // %1 + "+r"(width) // %2 + ::"memory", + "cc", "xmm0", "xmm1"); } -#endif // HAS_ARGBTOUVJROW_SSSE3 +#endif // HAS_ARGBTOAR64ROW_AVX2 -#ifdef HAS_ARGBTOUV444ROW_SSSE3 -void ARGBToUV444Row_SSSE3(const uint8_t* src_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { +#ifdef HAS_ARGBTOAB64ROW_AVX2 +void ARGBToAB64Row_AVX2(const uint8_t* src_argb, + uint16_t* dst_ab64, + int width) { asm volatile( - "movdqa %4,%%xmm3 \n" - "movdqa %5,%%xmm4 \n" - "movdqa %6,%%xmm5 \n" - "sub %1,%2 \n" + "vbroadcasti128 %3,%%ymm2 \n" + "vbroadcasti128 %4,%%ymm3 \n" LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm3,%%ymm0,%%ymm1 \n" + "vpshufb %%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "lea 0x20(%0),%0 \n" + "lea 0x40(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_ab64), // %1 + "+r"(width) // %2 + : "m"(kShuffleARGBToAB64Lo), // %3 + "m"(kShuffleARGBToAB64Hi) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); +} +#endif // HAS_ARGBTOAB64ROW_AVX2 + +#ifdef HAS_AR64TOARGBROW_AVX2 +void AR64ToARGBRow_AVX2(const uint16_t* src_ar64, + uint8_t* dst_argb, + int width) { + asm volatile( + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vpsrlw $8,%%ymm0,%%ymm0 \n" + "vpsrlw $8,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x40(%0),%0 \n" + "lea 0x20(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ar64), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + ::"memory", + "cc", "xmm0", "xmm1"); +} +#endif // HAS_AR64TOARGBROW_AVX2 + +#ifdef HAS_AB64TOARGBROW_AVX2 +void AB64ToARGBRow_AVX2(const uint16_t* src_ab64, + uint8_t* dst_argb, + int width) { + asm volatile("vbroadcasti128 %3,%%ymm2 \n" LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vpsrlw $8,%%ymm0,%%ymm0 \n" + "vpsrlw $8,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x40(%0),%0 \n" + "lea 0x20(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ab64), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "m"(kShuffleARGBToABGR) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2"); +} +#endif // HAS_AB64TOARGBROW_AVX2 + +// clang-format off + +// TODO(mraptis): Consider passing R, G, B multipliers as parameter. +// round parameter is register containing value to add before shift. +#define RGBTOY(round) \ + "1: \n" \ + "movdqu (%0),%%xmm0 \n" \ + "movdqu 0x10(%0),%%xmm1 \n" \ + "movdqu 0x20(%0),%%xmm2 \n" \ + "movdqu 0x30(%0),%%xmm3 \n" \ + "psubb %%xmm5,%%xmm0 \n" \ + "psubb %%xmm5,%%xmm1 \n" \ + "psubb %%xmm5,%%xmm2 \n" \ + "psubb %%xmm5,%%xmm3 \n" \ + "movdqu %%xmm4,%%xmm6 \n" \ + "pmaddubsw %%xmm0,%%xmm6 \n" \ + "movdqu %%xmm4,%%xmm0 \n" \ + "pmaddubsw %%xmm1,%%xmm0 \n" \ + "movdqu %%xmm4,%%xmm1 \n" \ + "pmaddubsw %%xmm2,%%xmm1 \n" \ + "movdqu %%xmm4,%%xmm2 \n" \ + "pmaddubsw %%xmm3,%%xmm2 \n" \ + "lea 0x40(%0),%0 \n" \ + "phaddw %%xmm0,%%xmm6 \n" \ + "phaddw %%xmm2,%%xmm1 \n" \ + "prefetcht0 1280(%0) \n" \ + "paddw %%" #round ",%%xmm6 \n" \ + "paddw %%" #round ",%%xmm1 \n" \ + "psrlw $0x8,%%xmm6 \n" \ + "psrlw $0x8,%%xmm1 \n" \ + "packuswb %%xmm1,%%xmm6 \n" \ + "movdqu %%xmm6,(%1) \n" \ + "lea 0x10(%1),%1 \n" \ + "sub $0x10,%2 \n" \ + "jg 1b \n" + +#define RGBTOY_AVX2(round) \ + "1: \n" \ + "vmovdqu (%0),%%ymm0 \n" \ + "vmovdqu 0x20(%0),%%ymm1 \n" \ + "vmovdqu 0x40(%0),%%ymm2 \n" \ + "vmovdqu 0x60(%0),%%ymm3 \n" \ + "vpsubb %%ymm5, %%ymm0, %%ymm0 \n" \ + "vpsubb %%ymm5, %%ymm1, %%ymm1 \n" \ + "vpsubb %%ymm5, %%ymm2, %%ymm2 \n" \ + "vpsubb %%ymm5, %%ymm3, %%ymm3 \n" \ + "vpmaddubsw %%ymm0,%%ymm4,%%ymm0 \n" \ + "vpmaddubsw %%ymm1,%%ymm4,%%ymm1 \n" \ + "vpmaddubsw %%ymm2,%%ymm4,%%ymm2 \n" \ + "vpmaddubsw %%ymm3,%%ymm4,%%ymm3 \n" \ + "lea 0x80(%0),%0 \n" \ + "vphaddw %%ymm1,%%ymm0,%%ymm0 \n" /* mutates. */ \ + "vphaddw %%ymm3,%%ymm2,%%ymm2 \n" \ + "prefetcht0 1280(%0) \n" \ + "vpaddw %%" #round ",%%ymm0,%%ymm0 \n" /* Add 16 */ \ + "vpaddw %%" #round ",%%ymm2,%%ymm2 \n" \ + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" \ + "vpsrlw $0x8,%%ymm2,%%ymm2 \n" \ + "vpackuswb %%ymm2,%%ymm0,%%ymm0 \n" /* mutates. */ \ + "vpermd %%ymm0,%%ymm6,%%ymm0 \n" /* unmutate. */ \ + "vmovdqu %%ymm0,(%1) \n" \ + "lea 0x20(%1),%1 \n" \ + "sub $0x20,%2 \n" \ + "jg 1b \n" + +// clang-format on + +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) || \ + defined(HAS_ARGBTOUV444MATRIXROW_AVX2) || \ + defined(HAS_ARGBEXTRACTALPHAROW_AVX2) +// vpermd for vphaddw + vpackuswb vpermd. +static const lvec32 kPermdARGBToY_AVX = {0, 4, 1, 5, 2, 6, 3, 7}; +#endif // defined(HAS_ARGBTOYMATRIXROW_AVX2) || + // defined(HAS_ARGBTOUV444MATRIXROW_AVX2) || + // defined(HAS_ARGBEXTRACTALPHAROW_AVX2) + +#ifdef HAS_ARGBTOYMATRIXROW_SSSE3 +void ARGBToYMatrixRow_SSSE3(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + asm volatile( + "pcmpeqb %%xmm5,%%xmm5 \n" + "psllw $15,%%xmm5 \n" + "packsswb %%xmm5,%%xmm5 \n" + "movdqu 0(%3),%%xmm4 \n" + "movdqu 0x60(%3),%%xmm7 \n" + "movdqa %%xmm4,%%xmm6 \n" + "pmaddubsw %%xmm5,%%xmm6 \n" + "phaddw %%xmm6,%%xmm6 \n" + "psubw %%xmm6,%%xmm7 \n" LABELALIGN "" RGBTOY(xmm7) + : "+r"(src_argb), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(c) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_ARGBTOYMATRIXROW_SSSE3 + +#ifdef HAS_ARGBTOYMATRIXROW_AVX2 +void ARGBToYMatrixRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + asm volatile( + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsllw $15,%%ymm5,%%ymm5 \n" + "vpacksswb %%ymm5,%%ymm5,%%ymm5 \n" + "vbroadcasti128 0(%3),%%ymm4 \n" + "vbroadcasti128 0x60(%3),%%ymm7 \n" + "vpmaddubsw %%ymm5,%%ymm4,%%ymm6 \n" + "vphaddw %%ymm6,%%ymm6,%%ymm6 \n" + "vpsubw %%ymm6,%%ymm7,%%ymm7 \n" + "vmovdqa %4,%%ymm6 \n" LABELALIGN + "" RGBTOY_AVX2(ymm7) "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(c), // %3 + "m"(kPermdARGBToY_AVX) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_ARGBTOYMATRIXROW_AVX2 + +#if defined(HAS_ARGBTOYMATRIXROW_AVX512BW) || \ + defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) || \ + defined(HAS_ARGBTOUV444MATRIXROW_AVX512BW) || \ + defined(HAS_ARGBTOUV444MATRIXROW_AVX512VNNI) || \ + defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) || \ + defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) || \ + defined(HAS_RGBTOYMATRIXROW_AVX512BW) +static const uint32_t kPermdARGBToY_AVX512BW[16] = {0, 4, 8, 12, 1, 5, 9, 13, + 2, 6, 10, 14, 3, 7, 11, 15}; +#endif // defined(HAS_ARGBTOYMATRIXROW_AVX512BW) || + // defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) || + // defined(HAS_ARGBTOUV444MATRIXROW_AVX512BW) || + // defined(HAS_ARGBTOUV444MATRIXROW_AVX512VNNI) || + // defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) || + // defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) || + // defined(HAS_RGBTOYMATRIXROW_AVX512BW) + +#if defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) || \ + defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) || \ + defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) +static const uint32_t kPermdARGBToUV_AVX512BW[16] = { + 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15}; +#endif // defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) || + // defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) || + // defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) + +#ifdef HAS_ARGBTOYMATRIXROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToYMatrixRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + uintptr_t temp; + asm volatile( + "vpternlogd $0xff,%%zmm16,%%zmm16,%%zmm16 \n" + "vpsllw $15,%%zmm16,%%zmm5 \n" + "vpacksswb %%zmm5,%%zmm5,%%zmm5 \n" // zmm5 = 0x80 + "vpabsw %%zmm16,%%zmm16 \n" // zmm16 = 1 + "vbroadcasti32x4 0(%[c]),%%zmm4 \n" + "vbroadcasti32x4 0x60(%[c]),%%zmm17 \n" + "vpmaddubsw %%zmm5,%%zmm4,%%zmm18 \n" + "vpmaddwd %%zmm16,%%zmm18,%%zmm18 \n" + "vpackssdw %%zmm18,%%zmm18,%%zmm18 \n" + "vpsubw %%zmm18,%%zmm17,%%zmm17 \n" + "vmovdqu32 %[perm],%%zmm18 \n" + "sub $0x40,%[width] \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x30(%0),%%xmm6 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm4,%%xmm6 \n" - "phaddw %%xmm1,%%xmm0 \n" - "phaddw %%xmm6,%%xmm2 \n" - "psraw $0x8,%%xmm0 \n" - "psraw $0x8,%%xmm2 \n" - "packsswb %%xmm2,%%xmm0 \n" - "paddb %%xmm5,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x30(%0),%%xmm6 \n" - "pmaddubsw %%xmm3,%%xmm0 \n" - "pmaddubsw %%xmm3,%%xmm1 \n" - "pmaddubsw %%xmm3,%%xmm2 \n" - "pmaddubsw %%xmm3,%%xmm6 \n" - "phaddw %%xmm1,%%xmm0 \n" - "phaddw %%xmm6,%%xmm2 \n" - "psraw $0x8,%%xmm0 \n" - "psraw $0x8,%%xmm2 \n" - "packsswb %%xmm2,%%xmm0 \n" - "paddb %%xmm5,%%xmm0 \n" - "lea 0x40(%0),%0 \n" - "movdqu %%xmm0,0x00(%1,%2,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%3 \n" - "jg 1b \n" + "1: \n" + "vmovdqu8 (%[src_argb]),%%zmm0 \n" + "vmovdqu8 0x40(%[src_argb]),%%zmm1 \n" + "vmovdqu8 0x80(%[src_argb]),%%zmm2 \n" + "vmovdqu8 0xc0(%[src_argb]),%%zmm3 \n" + "vpsubb %%zmm5,%%zmm0,%%zmm0 \n" + "vpsubb %%zmm5,%%zmm1,%%zmm1 \n" + "vpsubb %%zmm5,%%zmm2,%%zmm2 \n" + "vpsubb %%zmm5,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm0,%%zmm4,%%zmm0 \n" + "vpmaddubsw %%zmm1,%%zmm4,%%zmm1 \n" + "vpmaddubsw %%zmm2,%%zmm4,%%zmm2 \n" + "vpmaddubsw %%zmm3,%%zmm4,%%zmm3 \n" + "lea 0x100(%[src_argb]),%[src_argb]\n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm1,%%zmm1 \n" + "vpackssdw %%zmm1,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddwd %%zmm16,%%zmm3,%%zmm3 \n" + "vpackssdw %%zmm3,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm17,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm17,%%zmm2,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm18,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst_y]) \n" + "lea 0x40(%[dst_y]),%[dst_y] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovq %[temp],%%k1 \n" + "kshiftrq $16,%%k1,%%k2 \n" + "kshiftrq $32,%%k1,%%k3 \n" + "kshiftrq $48,%%k1,%%k4 \n" + "vmovdqu32 (%[src_argb]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src_argb]),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu32 0x80(%[src_argb]),%%zmm2%{%%k3%}%{z%} \n" + "vmovdqu32 0xc0(%[src_argb]),%%zmm3%{%%k4%}%{z%} \n" + "vpsubb %%zmm5,%%zmm0,%%zmm0 \n" + "vpsubb %%zmm5,%%zmm1,%%zmm1 \n" + "vpsubb %%zmm5,%%zmm2,%%zmm2 \n" + "vpsubb %%zmm5,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm0,%%zmm4,%%zmm0 \n" + "vpmaddubsw %%zmm1,%%zmm4,%%zmm1 \n" + "vpmaddubsw %%zmm2,%%zmm4,%%zmm2 \n" + "vpmaddubsw %%zmm3,%%zmm4,%%zmm3 \n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm1,%%zmm1 \n" + "vpackssdw %%zmm1,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddwd %%zmm16,%%zmm3,%%zmm3 \n" + "vpackssdw %%zmm3,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm17,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm17,%%zmm2,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm18,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst_y])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src_argb] "+r"(src_argb), [dst_y] "+r"(dst_y), [width] "+r"(width), + [temp] "=&r"(temp) + : [c] "r"(c), [perm] "m"(kPermdARGBToY_AVX512BW) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm16", + "xmm17", "xmm18", "k1", "k2", "k3", "k4"); +} +#endif // HAS_ARGBTOYMATRIXROW_AVX512BW + +#ifdef HAS_ARGBTOYMATRIXROW_AVX512VNNI +LIBYUV_TARGET_AVX512VNNI +void ARGBToYMatrixRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + uintptr_t temp; + asm volatile( + "vpternlogd $0xff,%%zmm16,%%zmm16,%%zmm16 \n" + "vpsllw $15,%%zmm16,%%zmm5 \n" + "vpacksswb %%zmm5,%%zmm5,%%zmm5 \n" // zmm5 = 0x80 + "vbroadcasti32x4 0(%[c]),%%zmm4 \n" // kRGBToY (unsigned) + "vpmovzxwd 0x60(%[c]),%%zmm17 \n" // kAddY (32-bit) + "vpxorq %%zmm0,%%zmm0,%%zmm0 \n" + "vpdpbusd %%zmm5,%%zmm4,%%zmm0 \n" // -128 * sum(c) + "vpsubd %%zmm0,%%zmm17,%%zmm17 \n" // kAddY + 128 * sum(c) + "vmovdqu32 %[perm],%%zmm16 \n" // kPermdARGBToY_AVX512BW + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src_argb]),%%zmm0 \n" + "vmovdqu8 0x40(%[src_argb]),%%zmm1 \n" + "vmovdqu8 0x80(%[src_argb]),%%zmm2 \n" + "vmovdqu8 0xc0(%[src_argb]),%%zmm3 \n" + "lea 0x100(%[src_argb]),%[src_argb]\n" + "vpxorq %%zmm5,%%zmm0,%%zmm0 \n" + "vpxorq %%zmm5,%%zmm1,%%zmm1 \n" + "vpxorq %%zmm5,%%zmm2,%%zmm2 \n" + "vpxorq %%zmm5,%%zmm3,%%zmm3 \n" + "vmovdqa64 %%zmm17,%%zmm18 \n" + "vmovdqa64 %%zmm17,%%zmm19 \n" + "vmovdqa64 %%zmm17,%%zmm20 \n" + "vmovdqa64 %%zmm17,%%zmm21 \n" + "vpdpbusd %%zmm0,%%zmm4,%%zmm18 \n" + "vpdpbusd %%zmm1,%%zmm4,%%zmm19 \n" + "vpdpbusd %%zmm2,%%zmm4,%%zmm20 \n" + "vpdpbusd %%zmm3,%%zmm4,%%zmm21 \n" + "vpackusdw %%zmm19,%%zmm18,%%zmm0 \n" + "vpackusdw %%zmm21,%%zmm20,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm16,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst_y]) \n" + "lea 0x40(%[dst_y]),%[dst_y] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovq %[temp],%%k1 \n" + "kshiftrq $16,%%k1,%%k2 \n" + "kshiftrq $32,%%k1,%%k3 \n" + "kshiftrq $48,%%k1,%%k4 \n" + "vmovdqu32 (%[src_argb]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src_argb]),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu32 0x80(%[src_argb]),%%zmm2%{%%k3%}%{z%} \n" + "vmovdqu32 0xc0(%[src_argb]),%%zmm3%{%%k4%}%{z%} \n" + "vpxorq %%zmm5,%%zmm0,%%zmm0 \n" + "vpxorq %%zmm5,%%zmm1,%%zmm1 \n" + "vpxorq %%zmm5,%%zmm2,%%zmm2 \n" + "vpxorq %%zmm5,%%zmm3,%%zmm3 \n" + "vmovdqa64 %%zmm17,%%zmm18 \n" + "vmovdqa64 %%zmm17,%%zmm19 \n" + "vmovdqa64 %%zmm17,%%zmm20 \n" + "vmovdqa64 %%zmm17,%%zmm21 \n" + "vpdpbusd %%zmm0,%%zmm4,%%zmm18 \n" + "vpdpbusd %%zmm1,%%zmm4,%%zmm19 \n" + "vpdpbusd %%zmm2,%%zmm4,%%zmm20 \n" + "vpdpbusd %%zmm3,%%zmm4,%%zmm21 \n" + "vpackusdw %%zmm19,%%zmm18,%%zmm0 \n" + "vpackusdw %%zmm21,%%zmm20,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm16,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst_y])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src_argb] "+r"(src_argb), [dst_y] "+r"(dst_y), [width] "+r"(width), + [temp] "=&r"(temp) + : [c] "r"(c), [perm] "m"(kPermdARGBToY_AVX512BW) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm16", + "xmm17", "xmm18", "xmm19", "xmm20", "xmm21", "k1", "k2", "k3", "k4"); +} +#endif // HAS_ARGBTOYMATRIXROW_AVX512VNNI + +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) || \ + defined(HAS_ARGBTOUV444MATRIXROW_AVX512VNNIVBMI) || \ + defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) +// AVX512VNNIVBMI kernels use both AVX512VNNI (vpdpbusd) and AVX512VBMI +// (vpermt2b) and require both CPU features. There are no AVX512VBMI +// versions without AVX512VNNI. + +// vpermt2b indices selecting byte 1 of each int32 from 2 vectors. The 32 +// byte pattern is broadcast so each 256 bit half holds the same 32 results. +static const uint8_t kPermbDWordByte1_AVX512VNNIVBMI[32] = { + 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, + 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125}; +#endif + +#ifdef HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI +// Requires AVX512VNNI and AVX512VBMI. +// The 32 bit sums are kAddY + dot(kRGBToY, argb) which is always in +// [0, 65535], so Y is byte 1 of each int32 and no saturation is needed. +LIBYUV_TARGET_AVX512VNNIVBMI +void ARGBToYMatrixRow_AVX512VNNIVBMI(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + uintptr_t temp; + asm volatile( + "vpternlogd $0xff,%%zmm16,%%zmm16,%%zmm16 \n" + "vpsllw $15,%%zmm16,%%zmm5 \n" + "vpacksswb %%zmm5,%%zmm5,%%zmm5 \n" // zmm5 = 0x80 + "vbroadcasti32x4 0(%[c]),%%zmm4 \n" // kRGBToY (unsigned) + "vpmovzxwd 0x60(%[c]),%%zmm17 \n" // kAddY (32-bit) + "vpxorq %%zmm0,%%zmm0,%%zmm0 \n" + "vpdpbusd %%zmm5,%%zmm4,%%zmm0 \n" // -128 * sum(c) + "vpsubd %%zmm0,%%zmm17,%%zmm17 \n" // kAddY + 128 * sum(c) + "vbroadcasti64x4 %[perm],%%zmm16 \n" // byte 1 of int32 + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vpxorq (%[src_argb]),%%zmm5,%%zmm0 \n" + "vmovdqa64 %%zmm17,%%zmm18 \n" + "vpdpbusd %%zmm0,%%zmm4,%%zmm18 \n" + "vpxorq 0x40(%[src_argb]),%%zmm5,%%zmm1 \n" + "vmovdqa64 %%zmm17,%%zmm19 \n" + "vpdpbusd %%zmm1,%%zmm4,%%zmm19 \n" + "vpxorq 0x80(%[src_argb]),%%zmm5,%%zmm2 \n" + "vmovdqa64 %%zmm17,%%zmm20 \n" + "vpdpbusd %%zmm2,%%zmm4,%%zmm20 \n" + "vpxorq 0xc0(%[src_argb]),%%zmm5,%%zmm3 \n" + "vmovdqa64 %%zmm17,%%zmm21 \n" + "vpdpbusd %%zmm3,%%zmm4,%%zmm21 \n" + "lea 0x100(%[src_argb]),%[src_argb]\n" + "vpermt2b %%zmm19,%%zmm16,%%zmm18 \n" // Y 0..31 + "vpermt2b %%zmm21,%%zmm16,%%zmm20 \n" // Y 32..63 + "vmovdqu8 %%ymm18,(%[dst_y]) \n" + "vmovdqu8 %%ymm20,0x20(%[dst_y]) \n" + "lea 0x40(%[dst_y]),%[dst_y] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovq %[temp],%%k1 \n" + "kshiftrq $16,%%k1,%%k2 \n" + "kshiftrq $32,%%k1,%%k3 \n" + "kshiftrq $48,%%k1,%%k4 \n" + "vmovdqu32 (%[src_argb]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src_argb]),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu32 0x80(%[src_argb]),%%zmm2%{%%k3%}%{z%} \n" + "vmovdqu32 0xc0(%[src_argb]),%%zmm3%{%%k4%}%{z%} \n" + "vpxorq %%zmm5,%%zmm0,%%zmm0 \n" + "vpxorq %%zmm5,%%zmm1,%%zmm1 \n" + "vpxorq %%zmm5,%%zmm2,%%zmm2 \n" + "vpxorq %%zmm5,%%zmm3,%%zmm3 \n" + "vmovdqa64 %%zmm17,%%zmm18 \n" + "vmovdqa64 %%zmm17,%%zmm19 \n" + "vmovdqa64 %%zmm17,%%zmm20 \n" + "vmovdqa64 %%zmm17,%%zmm21 \n" + "vpdpbusd %%zmm0,%%zmm4,%%zmm18 \n" + "vpdpbusd %%zmm1,%%zmm4,%%zmm19 \n" + "vpdpbusd %%zmm2,%%zmm4,%%zmm20 \n" + "vpdpbusd %%zmm3,%%zmm4,%%zmm21 \n" + "vpermt2b %%zmm19,%%zmm16,%%zmm18 \n" + "vpermt2b %%zmm21,%%zmm16,%%zmm20 \n" + "vmovdqu8 %%ymm18,(%[dst_y])%{%%k1%} \n" + "vmovdqu8 %%ymm20,0x20(%[dst_y])%{%%k3%} \n" + + "99: \n" + "vzeroupper \n" + : [src_argb] "+r"(src_argb), [dst_y] "+r"(dst_y), [width] "+r"(width), + [temp] "=&r"(temp) + : [c] "r"(c), [perm] "m"(kPermbDWordByte1_AVX512VNNIVBMI) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm16", + "xmm17", "xmm18", "xmm19", "xmm20", "xmm21", "k1", "k2", "k3", "k4"); +} +#endif // HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI + +#ifdef HAS_RGBTOYMATRIXROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void RGBToYMatrixRow_AVX512BW(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + uintptr_t temp; + uintptr_t mask; + asm volatile( + "vmovdqu64 %[q0],%%zmm20 \n" // kPermqRGB24ToARGB0_AVX512BW + "vmovdqu64 %[q1],%%zmm21 \n" // kPermqRGB24ToARGB1_AVX512BW + "vmovdqu64 %[q2],%%zmm22 \n" // kPermqRGB24ToARGB2_AVX512BW + "vmovdqu64 %[q3],%%zmm23 \n" // kPermqRGB24ToARGB3_AVX512BW + "vbroadcasti64x4 %[shuf],%%zmm24 \n" // kShuffleMaskRGB24ToARGB + "vpternlogd $0xff,%%zmm16,%%zmm16,%%zmm16 \n" + "vpsllw $15,%%zmm16,%%zmm5 \n" + "vpacksswb %%zmm5,%%zmm5,%%zmm5 \n" // zmm5 = 0x80 + "vpabsw %%zmm16,%%zmm16 \n" // zmm16 = 1 + "vbroadcasti32x4 0(%[c]),%%zmm4 \n" // zmm4 = kRGBToY + "vbroadcasti32x4 0x60(%[c]),%%zmm17 \n" // zmm17 = kAddY + "vpmaddubsw %%zmm5,%%zmm4,%%zmm19 \n" + "vpmaddwd %%zmm16,%%zmm19,%%zmm19 \n" + "vpackssdw %%zmm19,%%zmm19,%%zmm19 \n" + "vpsubw %%zmm19,%%zmm17,%%zmm17 \n" // zmm17 = adjusted bias + "vmovdqu32 %[perm],%%zmm25 \n" // kPermdARGBToY_AVX512BW + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src_rgb]),%%zmm0 \n" + "vmovdqu8 64(%[src_rgb]),%%zmm1 \n" + "vmovdqu8 128(%[src_rgb]),%%zmm2 \n" + "lea 192(%[src_rgb]),%[src_rgb] \n" + "vpermq %%zmm2,%%zmm23,%%zmm3 \n" + "vmovdqa64 %%zmm0,%%zmm19 \n" + "vpermt2q %%zmm1,%%zmm21,%%zmm19 \n" + "vpermt2q %%zmm2,%%zmm22,%%zmm1 \n" + "vpermq %%zmm0,%%zmm20,%%zmm0 \n" + "vpshufb %%zmm24,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm24,%%zmm19,%%zmm19 \n" + "vpshufb %%zmm24,%%zmm1,%%zmm2 \n" + "vpshufb %%zmm24,%%zmm3,%%zmm3 \n" + "vpsubb %%zmm5,%%zmm0,%%zmm0 \n" + "vpsubb %%zmm5,%%zmm19,%%zmm19 \n" + "vpsubb %%zmm5,%%zmm2,%%zmm2 \n" + "vpsubb %%zmm5,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm0,%%zmm4,%%zmm0 \n" + "vpmaddubsw %%zmm19,%%zmm4,%%zmm19 \n" + "vpmaddubsw %%zmm2,%%zmm4,%%zmm2 \n" + "vpmaddubsw %%zmm3,%%zmm4,%%zmm3 \n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm19,%%zmm19 \n" + "vpackssdw %%zmm19,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddwd %%zmm16,%%zmm3,%%zmm3 \n" + "vpackssdw %%zmm3,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm17,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm17,%%zmm2,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm25,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst_y]) \n" + "lea 0x40(%[dst_y]),%[dst_y] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[mask] \n" + "kmovq %[mask],%%k4 \n" + "lea (%q[width],%q[width],2),%k[width] \n" + "bzhi %q[width],%[temp],%[mask] \n" + "kmovq %[mask],%%k1 \n" + "xor %k[mask],%k[mask] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[mask] \n" + "bzhi %q[width],%[mask],%[mask] \n" + "kmovq %[mask],%%k2 \n" + "xor %k[mask],%k[mask] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[mask] \n" + "bzhi %q[width],%[mask],%[mask] \n" + "kmovq %[mask],%%k3 \n" + "vmovdqu8 (%[src_rgb]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu8 64(%[src_rgb]),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu8 128(%[src_rgb]),%%zmm2%{%%k3%}%{z%} \n" + "vpermq %%zmm2,%%zmm23,%%zmm3 \n" + "vmovdqa64 %%zmm0,%%zmm19 \n" + "vpermt2q %%zmm1,%%zmm21,%%zmm19 \n" + "vpermt2q %%zmm2,%%zmm22,%%zmm1 \n" + "vpermq %%zmm0,%%zmm20,%%zmm0 \n" + "vpshufb %%zmm24,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm24,%%zmm19,%%zmm19 \n" + "vpshufb %%zmm24,%%zmm1,%%zmm2 \n" + "vpshufb %%zmm24,%%zmm3,%%zmm3 \n" + "vpsubb %%zmm5,%%zmm0,%%zmm0 \n" + "vpsubb %%zmm5,%%zmm19,%%zmm19 \n" + "vpsubb %%zmm5,%%zmm2,%%zmm2 \n" + "vpsubb %%zmm5,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm0,%%zmm4,%%zmm0 \n" + "vpmaddubsw %%zmm19,%%zmm4,%%zmm19 \n" + "vpmaddubsw %%zmm2,%%zmm4,%%zmm2 \n" + "vpmaddubsw %%zmm3,%%zmm4,%%zmm3 \n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm19,%%zmm19 \n" + "vpackssdw %%zmm19,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddwd %%zmm16,%%zmm3,%%zmm3 \n" + "vpackssdw %%zmm3,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm17,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm17,%%zmm2,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm25,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst_y])%{%%k4%} \n" + + "99: \n" + "vzeroupper \n" + : [src_rgb] "+r"(src_rgb), [dst_y] "+r"(dst_y), [width] "+r"(width), + [temp] "=&r"(temp), [mask] "=&r"(mask) + : [c] "r"(c), [perm] "m"(kPermdARGBToY_AVX512BW), + [q0] "m"(kPermqRGB24ToARGB0_AVX512BW), + [q1] "m"(kPermqRGB24ToARGB1_AVX512BW), + [q2] "m"(kPermqRGB24ToARGB2_AVX512BW), + [q3] "m"(kPermqRGB24ToARGB3_AVX512BW), + [shuf] "m"(kShuffleMaskRGB24ToARGB) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm16", + "xmm17", "xmm19", "xmm20", "xmm21", "xmm22", "xmm23", "xmm24", "xmm25", + "k1", "k2", "k3", "k4"); +} +#endif // HAS_RGBTOYMATRIXROW_AVX512BW + +#ifdef HAS_ARGBTOUV444MATRIXROW_SSSE3 +void ARGBToUV444MatrixRow_SSSE3(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + asm volatile( + "movdqu 0x80(%4),%%xmm5 \n" // kAddUV + "movdqu 0x20(%4),%%xmm3 \n" // kRGBToU + "movdqu 0x40(%4),%%xmm4 \n" // kRGBToV + "sub %1,%2 \n" + + LABELALIGN + "1: \n" +#if defined(__x86_64__) + "movdqu (%0),%%xmm8 \n" + "movdqu 0x10(%0),%%xmm9 \n" + "movdqu 0x20(%0),%%xmm10 \n" + "movdqu 0x30(%0),%%xmm11 \n" + "movdqa %%xmm8,%%xmm0 \n" + "movdqa %%xmm9,%%xmm1 \n" + "movdqa %%xmm10,%%xmm2 \n" + "movdqa %%xmm11,%%xmm6 \n" +#else + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x20(%0),%%xmm2 \n" + "movdqu 0x30(%0),%%xmm6 \n" +#endif + "pmaddubsw %%xmm3,%%xmm0 \n" + "pmaddubsw %%xmm3,%%xmm1 \n" + "pmaddubsw %%xmm3,%%xmm2 \n" + "pmaddubsw %%xmm3,%%xmm6 \n" + "phaddw %%xmm1,%%xmm0 \n" + "phaddw %%xmm6,%%xmm2 \n" + "movdqa %%xmm5,%%xmm1 \n" + "movdqa %%xmm5,%%xmm6 \n" + "psubw %%xmm0,%%xmm1 \n" + "psubw %%xmm2,%%xmm6 \n" + "psrlw $0x8,%%xmm1 \n" + "psrlw $0x8,%%xmm6 \n" + "packuswb %%xmm6,%%xmm1 \n" + "movdqu %%xmm1,(%1) \n" + +#if defined(__x86_64__) + "pmaddubsw %%xmm4,%%xmm8 \n" + "pmaddubsw %%xmm4,%%xmm9 \n" + "pmaddubsw %%xmm4,%%xmm10 \n" + "pmaddubsw %%xmm4,%%xmm11 \n" + "phaddw %%xmm9,%%xmm8 \n" + "phaddw %%xmm11,%%xmm10 \n" + "movdqa %%xmm5,%%xmm1 \n" + "movdqa %%xmm5,%%xmm6 \n" + "psubw %%xmm8,%%xmm1 \n" + "psubw %%xmm10,%%xmm6 \n" +#else + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x20(%0),%%xmm2 \n" + "movdqu 0x30(%0),%%xmm6 \n" + "pmaddubsw %%xmm4,%%xmm0 \n" + "pmaddubsw %%xmm4,%%xmm1 \n" + "pmaddubsw %%xmm4,%%xmm2 \n" + "pmaddubsw %%xmm4,%%xmm6 \n" + "phaddw %%xmm1,%%xmm0 \n" + "phaddw %%xmm6,%%xmm2 \n" + "movdqa %%xmm5,%%xmm1 \n" + "movdqa %%xmm5,%%xmm6 \n" + "psubw %%xmm0,%%xmm1 \n" + "psubw %%xmm2,%%xmm6 \n" +#endif + "psrlw $0x8,%%xmm1 \n" + "psrlw $0x8,%%xmm6 \n" + "packuswb %%xmm6,%%xmm1 \n" + "movdqu %%xmm1,0x00(%1,%2,1) \n" + + "lea 0x40(%0),%0 \n" + "lea 0x10(%1),%1 \n" + "subl $0x10,%3 \n" + "jg 1b \n" : "+r"(src_argb), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 - "+rm"(width) // %3 - : "m"(kARGBToV), // %4 - "m"(kARGBToU), // %5 - "m"(kAddUV128) // %6 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm6"); +#if defined(__i386__) + "+m"(width) // %3 +#else + "+rm"(width) // %3 +#endif + : "r"(c) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6" +#if defined(__x86_64__) + , + "xmm8", "xmm9", "xmm10", "xmm11" +#endif + ); } -#endif // HAS_ARGBTOUV444ROW_SSSE3 +#endif // HAS_ARGBTOUV444MATRIXROW_SSSE3 -void BGRAToYRow_SSSE3(const uint8_t* src_bgra, uint8_t* dst_y, int width) { +#ifdef HAS_ARGBTOUV444MATRIXROW_AVX2 +void ARGBToUV444MatrixRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { asm volatile( - "movdqa %4,%%xmm5 \n" - "movdqa %3,%%xmm4 \n" + "vmovdqu 0x20(%4),%%ymm3 \n" // kRGBToU + "vmovdqu 0x40(%4),%%ymm4 \n" // kRGBToV + "vmovdqu 0x80(%4),%%ymm5 \n" // kAddUV + "vmovdqu %5,%%ymm7 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x30(%0),%%xmm3 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm4,%%xmm3 \n" - "lea 0x40(%0),%0 \n" - "phaddw %%xmm1,%%xmm0 \n" - "phaddw %%xmm3,%%xmm2 \n" - "psrlw $0x7,%%xmm0 \n" - "psrlw $0x7,%%xmm2 \n" - "packuswb %%xmm2,%%xmm0 \n" - "paddb %%xmm5,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_bgra), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : "m"(kBGRAToY), // %3 - "m"(kAddY16) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); -} + "1: \n" +#if defined(__x86_64__) + "vmovdqu (%0),%%ymm8 \n" + "vmovdqu 0x20(%0),%%ymm9 \n" + "vmovdqu 0x40(%0),%%ymm10 \n" + "vmovdqu 0x60(%0),%%ymm11 \n" + "vpmaddubsw %%ymm3,%%ymm8,%%ymm0 \n" + "vpmaddubsw %%ymm3,%%ymm9,%%ymm1 \n" + "vpmaddubsw %%ymm3,%%ymm10,%%ymm2 \n" + "vpmaddubsw %%ymm3,%%ymm11,%%ymm6 \n" +#else + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu 0x40(%0),%%ymm2 \n" + "vmovdqu 0x60(%0),%%ymm6 \n" + "vpmaddubsw %%ymm3,%%ymm0,%%ymm0 \n" + "vpmaddubsw %%ymm3,%%ymm1,%%ymm1 \n" + "vpmaddubsw %%ymm3,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm3,%%ymm6,%%ymm6 \n" +#endif + "vphaddw %%ymm1,%%ymm0,%%ymm0 \n" // mutates + "vphaddw %%ymm6,%%ymm2,%%ymm2 \n" + "vpsubw %%ymm0,%%ymm5,%%ymm0 \n" + "vpsubw %%ymm2,%%ymm5,%%ymm2 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm2,%%ymm2 \n" + "vpackuswb %%ymm2,%%ymm0,%%ymm0 \n" // mutates + "vpermd %%ymm0,%%ymm7,%%ymm0 \n" // unmutate. + "vmovdqu %%ymm0,(%1) \n" -void BGRAToUVRow_SSSE3(const uint8_t* src_bgra0, - int src_stride_bgra, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { +#if defined(__x86_64__) + "vpmaddubsw %%ymm4,%%ymm8,%%ymm0 \n" + "vpmaddubsw %%ymm4,%%ymm9,%%ymm1 \n" + "vpmaddubsw %%ymm4,%%ymm10,%%ymm2 \n" + "vpmaddubsw %%ymm4,%%ymm11,%%ymm6 \n" +#else + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu 0x40(%0),%%ymm2 \n" + "vmovdqu 0x60(%0),%%ymm6 \n" + "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" + "vpmaddubsw %%ymm4,%%ymm1,%%ymm1 \n" + "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm4,%%ymm6,%%ymm6 \n" +#endif + "vphaddw %%ymm1,%%ymm0,%%ymm0 \n" // mutates + "vphaddw %%ymm6,%%ymm2,%%ymm2 \n" + "vpsubw %%ymm0,%%ymm5,%%ymm0 \n" + "vpsubw %%ymm2,%%ymm5,%%ymm2 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm2,%%ymm2 \n" + "vpackuswb %%ymm2,%%ymm0,%%ymm0 \n" // mutates + "vpermd %%ymm0,%%ymm7,%%ymm0 \n" // unmutate. + "vmovdqu %%ymm0,(%1,%2,1) \n" + "lea 0x80(%0),%0 \n" + "lea 0x20(%1),%1 \n" + "subl $0x20,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 +#if defined(__i386__) + "+m"(width) // %3 +#else + "+rm"(width) // %3 +#endif + : "r"(c), // %4 + "m"(kPermdARGBToY_AVX) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7" +#if defined(__x86_64__) + , + "xmm8", "xmm9", "xmm10", "xmm11" +#endif + ); +} +#endif // HAS_ARGBTOUV444MATRIXROW_AVX2 + +#ifdef HAS_ARGBTOUV444MATRIXROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToUV444MatrixRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + uintptr_t temp; asm volatile( - "movdqa %5,%%xmm3 \n" - "movdqa %6,%%xmm4 \n" - "movdqa %7,%%xmm5 \n" - "sub %1,%2 \n" + "vbroadcasti32x4 0x20(%[c]),%%zmm3 \n" // kRGBToU + "vbroadcasti32x4 0x40(%[c]),%%zmm4 \n" // kRGBToV + "vpternlogd $0xff,%%zmm16,%%zmm16,%%zmm16 \n" // -1 + "vbroadcasti32x4 0x80(%[c]),%%zmm5 \n" // kAddUV + "vmovdqu32 %[perm],%%zmm17 \n" + "sub %[dst_u],%[dst_v] \n" + "sub $0x40,%[width] \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x00(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x10(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x20(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm2 \n" - "movdqu 0x30(%0),%%xmm6 \n" - "movdqu 0x30(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm6 \n" + "1: \n" + "vmovdqu8 (%[src_argb]),%%zmm18 \n" + "vmovdqu8 0x40(%[src_argb]),%%zmm19 \n" + "vmovdqu8 0x80(%[src_argb]),%%zmm20 \n" + "vmovdqu8 0xc0(%[src_argb]),%%zmm21 \n" + "lea 0x100(%[src_argb]),%[src_argb]\n" + "vpmaddubsw %%zmm3,%%zmm18,%%zmm0 \n" + "vpmaddubsw %%zmm3,%%zmm19,%%zmm1 \n" + "vpmaddubsw %%zmm3,%%zmm20,%%zmm2 \n" + "vpmaddubsw %%zmm3,%%zmm21,%%zmm6 \n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm1,%%zmm1 \n" + "vpmaddwd %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddwd %%zmm16,%%zmm6,%%zmm6 \n" + "vpackssdw %%zmm1,%%zmm0,%%zmm0 \n" // mutates + "vpackssdw %%zmm6,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm5,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm5,%%zmm2,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" // mutates + "vpermd %%zmm0,%%zmm17,%%zmm0 \n" // unmutate. + "vmovdqu8 %%zmm0,(%[dst_u]) \n" - "lea 0x40(%0),%0 \n" - "movdqa %%xmm0,%%xmm7 \n" - "shufps $0x88,%%xmm1,%%xmm0 \n" - "shufps $0xdd,%%xmm1,%%xmm7 \n" - "pavgb %%xmm7,%%xmm0 \n" - "movdqa %%xmm2,%%xmm7 \n" - "shufps $0x88,%%xmm6,%%xmm2 \n" - "shufps $0xdd,%%xmm6,%%xmm7 \n" - "pavgb %%xmm7,%%xmm2 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm2,%%xmm6 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm3,%%xmm1 \n" - "pmaddubsw %%xmm3,%%xmm6 \n" - "phaddw %%xmm2,%%xmm0 \n" - "phaddw %%xmm6,%%xmm1 \n" - "psraw $0x8,%%xmm0 \n" - "psraw $0x8,%%xmm1 \n" - "packsswb %%xmm1,%%xmm0 \n" - "paddb %%xmm5,%%xmm0 \n" - "movlps %%xmm0,(%1) \n" - "movhps %%xmm0,0x00(%1,%2,1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x10,%3 \n" - "jg 1b \n" - : "+r"(src_bgra0), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+rm"(width) // %3 - : "r"((intptr_t)(src_stride_bgra)), // %4 - "m"(kBGRAToV), // %5 - "m"(kBGRAToU), // %6 - "m"(kAddUV128) // %7 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"); + "vpmaddubsw %%zmm4,%%zmm18,%%zmm0 \n" + "vpmaddubsw %%zmm4,%%zmm19,%%zmm1 \n" + "vpmaddubsw %%zmm4,%%zmm20,%%zmm2 \n" + "vpmaddubsw %%zmm4,%%zmm21,%%zmm6 \n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm1,%%zmm1 \n" + "vpmaddwd %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddwd %%zmm16,%%zmm6,%%zmm6 \n" + "vpackssdw %%zmm1,%%zmm0,%%zmm0 \n" // mutates + "vpackssdw %%zmm6,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm5,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm5,%%zmm2,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" // mutates + "vpermd %%zmm0,%%zmm17,%%zmm0 \n" // unmutate. + "vmovdqu8 %%zmm0,(%[dst_u],%[dst_v],1) \n" + "lea 0x40(%[dst_u]),%[dst_u] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovq %[temp],%%k1 \n" + "kshiftrq $16,%%k1,%%k2 \n" + "kshiftrq $32,%%k1,%%k3 \n" + "kshiftrq $48,%%k1,%%k4 \n" + "vmovdqu32 (%[src_argb]),%%zmm18%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src_argb]),%%zmm19%{%%k2%}%{z%} \n" + "vmovdqu32 0x80(%[src_argb]),%%zmm20%{%%k3%}%{z%} \n" + "vmovdqu32 0xc0(%[src_argb]),%%zmm21%{%%k4%}%{z%} \n" + "vpmaddubsw %%zmm3,%%zmm18,%%zmm0 \n" + "vpmaddubsw %%zmm3,%%zmm19,%%zmm1 \n" + "vpmaddubsw %%zmm3,%%zmm20,%%zmm2 \n" + "vpmaddubsw %%zmm3,%%zmm21,%%zmm6 \n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm1,%%zmm1 \n" + "vpmaddwd %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddwd %%zmm16,%%zmm6,%%zmm6 \n" + "vpackssdw %%zmm1,%%zmm0,%%zmm0 \n" + "vpackssdw %%zmm6,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm5,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm5,%%zmm2,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm17,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst_u])%{%%k1%} \n" + + "vpmaddubsw %%zmm4,%%zmm18,%%zmm0 \n" + "vpmaddubsw %%zmm4,%%zmm19,%%zmm1 \n" + "vpmaddubsw %%zmm4,%%zmm20,%%zmm2 \n" + "vpmaddubsw %%zmm4,%%zmm21,%%zmm6 \n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm1,%%zmm1 \n" + "vpmaddwd %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddwd %%zmm16,%%zmm6,%%zmm6 \n" + "vpackssdw %%zmm1,%%zmm0,%%zmm0 \n" + "vpackssdw %%zmm6,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm5,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm5,%%zmm2,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm17,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst_u],%[dst_v],1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src_argb] "+r"(src_argb), [dst_u] "+r"(dst_u), [dst_v] "+r"(dst_v), + [width] "+r"(width), [temp] "=&r"(temp) + : [c] "r"(c), [perm] "m"(kPermdARGBToY_AVX512BW) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm16", "xmm17", "xmm18", "xmm19", "xmm20", "xmm21", "k1", "k2", "k3", + "k4"); } +#endif // HAS_ARGBTOUV444MATRIXROW_AVX512BW -void ABGRToYRow_SSSE3(const uint8_t* src_abgr, uint8_t* dst_y, int width) { +#ifdef HAS_ARGBTOUV444MATRIXROW_AVX512VNNI +LIBYUV_TARGET_AVX512VNNI +void ARGBToUV444MatrixRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + uintptr_t temp; asm volatile( - "movdqa %4,%%xmm5 \n" - "movdqa %3,%%xmm4 \n" + "vbroadcasti32x4 0x20(%[c]),%%zmm3 \n" // kRGBToU (signed) + "vbroadcasti32x4 0x40(%[c]),%%zmm4 \n" // kRGBToV (signed) + "vbroadcasti32x4 0x80(%[c]),%%zmm5 \n" // kAddUV + "vmovdqu32 %[perm],%%zmm17 \n" + "sub %[dst_u],%[dst_v] \n" + "sub $0x40,%[width] \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x30(%0),%%xmm3 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm4,%%xmm3 \n" - "lea 0x40(%0),%0 \n" - "phaddw %%xmm1,%%xmm0 \n" - "phaddw %%xmm3,%%xmm2 \n" - "psrlw $0x7,%%xmm0 \n" - "psrlw $0x7,%%xmm2 \n" - "packuswb %%xmm2,%%xmm0 \n" - "paddb %%xmm5,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_abgr), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : "m"(kABGRToY), // %3 - "m"(kAddY16) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); -} + "1: \n" + "vmovdqu8 (%[src_argb]),%%zmm18 \n" + "vmovdqu8 0x40(%[src_argb]),%%zmm19 \n" + "vmovdqu8 0x80(%[src_argb]),%%zmm20 \n" + "vmovdqu8 0xc0(%[src_argb]),%%zmm21 \n" + "lea 0x100(%[src_argb]),%[src_argb]\n" + "vpxorq %%zmm0,%%zmm0,%%zmm0 \n" + "vpxorq %%zmm1,%%zmm1,%%zmm1 \n" + "vpxorq %%zmm2,%%zmm2,%%zmm2 \n" + "vpxorq %%zmm16,%%zmm16,%%zmm16 \n" + "vpdpbusd %%zmm3,%%zmm18,%%zmm0 \n" + "vpdpbusd %%zmm3,%%zmm19,%%zmm1 \n" + "vpdpbusd %%zmm3,%%zmm20,%%zmm2 \n" + "vpdpbusd %%zmm3,%%zmm21,%%zmm16 \n" + "vpackssdw %%zmm1,%%zmm0,%%zmm0 \n" // mutates + "vpackssdw %%zmm16,%%zmm2,%%zmm2 \n" + "vpsubw %%zmm0,%%zmm5,%%zmm0 \n" + "vpsubw %%zmm2,%%zmm5,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" // mutates + "vpermd %%zmm0,%%zmm17,%%zmm0 \n" // unmutate. + "vmovdqu8 %%zmm0,(%[dst_u]) \n" -void RGBAToYRow_SSSE3(const uint8_t* src_rgba, uint8_t* dst_y, int width) { + "vpxorq %%zmm0,%%zmm0,%%zmm0 \n" + "vpxorq %%zmm1,%%zmm1,%%zmm1 \n" + "vpxorq %%zmm2,%%zmm2,%%zmm2 \n" + "vpxorq %%zmm16,%%zmm16,%%zmm16 \n" + "vpdpbusd %%zmm4,%%zmm18,%%zmm0 \n" + "vpdpbusd %%zmm4,%%zmm19,%%zmm1 \n" + "vpdpbusd %%zmm4,%%zmm20,%%zmm2 \n" + "vpdpbusd %%zmm4,%%zmm21,%%zmm16 \n" + "vpackssdw %%zmm1,%%zmm0,%%zmm0 \n" // mutates + "vpackssdw %%zmm16,%%zmm2,%%zmm2 \n" + "vpsubw %%zmm0,%%zmm5,%%zmm0 \n" + "vpsubw %%zmm2,%%zmm5,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" // mutates + "vpermd %%zmm0,%%zmm17,%%zmm0 \n" // unmutate. + "vmovdqu8 %%zmm0,(%[dst_u],%[dst_v],1) \n" + "lea 0x40(%[dst_u]),%[dst_u] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovq %[temp],%%k1 \n" + "kshiftrq $16,%%k1,%%k2 \n" + "kshiftrq $32,%%k1,%%k3 \n" + "kshiftrq $48,%%k1,%%k4 \n" + "vmovdqu32 (%[src_argb]),%%zmm18%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src_argb]),%%zmm19%{%%k2%}%{z%} \n" + "vmovdqu32 0x80(%[src_argb]),%%zmm20%{%%k3%}%{z%} \n" + "vmovdqu32 0xc0(%[src_argb]),%%zmm21%{%%k4%}%{z%} \n" + "vpxorq %%zmm0,%%zmm0,%%zmm0 \n" + "vpxorq %%zmm1,%%zmm1,%%zmm1 \n" + "vpxorq %%zmm2,%%zmm2,%%zmm2 \n" + "vpxorq %%zmm16,%%zmm16,%%zmm16 \n" + "vpdpbusd %%zmm3,%%zmm18,%%zmm0 \n" + "vpdpbusd %%zmm3,%%zmm19,%%zmm1 \n" + "vpdpbusd %%zmm3,%%zmm20,%%zmm2 \n" + "vpdpbusd %%zmm3,%%zmm21,%%zmm16 \n" + "vpackssdw %%zmm1,%%zmm0,%%zmm0 \n" + "vpackssdw %%zmm16,%%zmm2,%%zmm2 \n" + "vpsubw %%zmm0,%%zmm5,%%zmm0 \n" + "vpsubw %%zmm2,%%zmm5,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm17,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst_u])%{%%k1%} \n" + + "vpxorq %%zmm0,%%zmm0,%%zmm0 \n" + "vpxorq %%zmm1,%%zmm1,%%zmm1 \n" + "vpxorq %%zmm2,%%zmm2,%%zmm2 \n" + "vpxorq %%zmm16,%%zmm16,%%zmm16 \n" + "vpdpbusd %%zmm4,%%zmm18,%%zmm0 \n" + "vpdpbusd %%zmm4,%%zmm19,%%zmm1 \n" + "vpdpbusd %%zmm4,%%zmm20,%%zmm2 \n" + "vpdpbusd %%zmm4,%%zmm21,%%zmm16 \n" + "vpackssdw %%zmm1,%%zmm0,%%zmm0 \n" + "vpackssdw %%zmm16,%%zmm2,%%zmm2 \n" + "vpsubw %%zmm0,%%zmm5,%%zmm0 \n" + "vpsubw %%zmm2,%%zmm5,%%zmm2 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm2,%%zmm2 \n" + "vpackuswb %%zmm2,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm17,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst_u],%[dst_v],1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src_argb] "+r"(src_argb), [dst_u] "+r"(dst_u), [dst_v] "+r"(dst_v), + [width] "+r"(width), [temp] "=&r"(temp) + : [c] "r"(c), [perm] "m"(kPermdARGBToY_AVX512BW) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm16", + "xmm17", "xmm18", "xmm19", "xmm20", "xmm21", "k1", "k2", "k3", "k4"); +} +#endif // HAS_ARGBTOUV444MATRIXROW_AVX512VNNI + +#ifdef HAS_ARGBTOUV444MATRIXROW_AVX512VNNIVBMI +// Requires AVX512VNNI and AVX512VBMI. +// U = (kAddUV - dot(kRGBToU, argb)) >> 8. The accumulators start at +// ~kAddUV so they hold ~(kAddUV - dot) and U is the inverse of byte 1 of each +// int32. The inverse is folded into the vpternlogd that merges the halves. +LIBYUV_TARGET_AVX512VNNIVBMI +void ARGBToUV444MatrixRow_AVX512VNNIVBMI(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + uintptr_t temp; asm volatile( - "movdqa %4,%%xmm5 \n" - "movdqa %3,%%xmm4 \n" + "vbroadcasti32x4 0x20(%[c]),%%zmm3 \n" // kRGBToU (signed) + "vbroadcasti32x4 0x40(%[c]),%%zmm4 \n" // kRGBToV (signed) + "vpmovzxwd 0x80(%[c]),%%zmm5 \n" // kAddUV (32-bit) + "vpternlogd $0x55,%%zmm5,%%zmm5,%%zmm5 \n" // ~kAddUV + "vbroadcasti64x4 %[perm],%%zmm16 \n" // byte 1 of int32 + "vpternlogd $0xff,%%zmm6,%%zmm6,%%zmm6 \n" + "vpxord %%zmm7,%%zmm7,%%zmm7 \n" + "vinserti64x4 $1,%%ymm6,%%zmm7,%%zmm6 \n" // high 256 bits select + "sub %[dst_u],%[dst_v] \n" + "sub $0x40,%[width] \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x30(%0),%%xmm3 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm4,%%xmm3 \n" - "lea 0x40(%0),%0 \n" - "phaddw %%xmm1,%%xmm0 \n" - "phaddw %%xmm3,%%xmm2 \n" - "psrlw $0x7,%%xmm0 \n" - "psrlw $0x7,%%xmm2 \n" - "packuswb %%xmm2,%%xmm0 \n" - "paddb %%xmm5,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_rgba), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : "m"(kRGBAToY), // %3 - "m"(kAddY16) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + "1: \n" + "vmovdqu8 (%[src_argb]),%%zmm0 \n" + "vmovdqu8 0x40(%[src_argb]),%%zmm1 \n" + "vmovdqu8 0x80(%[src_argb]),%%zmm2 \n" + "vmovdqu8 0xc0(%[src_argb]),%%zmm7 \n" + "lea 0x100(%[src_argb]),%[src_argb]\n" + "vmovdqa64 %%zmm5,%%zmm17 \n" + "vmovdqa64 %%zmm5,%%zmm18 \n" + "vmovdqa64 %%zmm5,%%zmm19 \n" + "vmovdqa64 %%zmm5,%%zmm20 \n" + "vmovdqa64 %%zmm5,%%zmm21 \n" + "vmovdqa64 %%zmm5,%%zmm22 \n" + "vmovdqa64 %%zmm5,%%zmm23 \n" + "vmovdqa64 %%zmm5,%%zmm24 \n" + "vpdpbusd %%zmm3,%%zmm0,%%zmm17 \n" // U + "vpdpbusd %%zmm4,%%zmm0,%%zmm21 \n" // V + "vpdpbusd %%zmm3,%%zmm1,%%zmm18 \n" + "vpdpbusd %%zmm4,%%zmm1,%%zmm22 \n" + "vpdpbusd %%zmm3,%%zmm2,%%zmm19 \n" + "vpdpbusd %%zmm4,%%zmm2,%%zmm23 \n" + "vpdpbusd %%zmm3,%%zmm7,%%zmm20 \n" + "vpdpbusd %%zmm4,%%zmm7,%%zmm24 \n" + "vpermt2b %%zmm18,%%zmm16,%%zmm17 \n" // U 0..31 + "vpermt2b %%zmm20,%%zmm16,%%zmm19 \n" // U 32..63 + "vpermt2b %%zmm22,%%zmm16,%%zmm21 \n" // V 0..31 + "vpermt2b %%zmm24,%%zmm16,%%zmm23 \n" // V 32..63 + "vpternlogd $0x27,%%zmm6,%%zmm19,%%zmm17 \n" // ~(low 17, high 19) + "vpternlogd $0x27,%%zmm6,%%zmm23,%%zmm21 \n" // ~(low 21, high 23) + "vmovdqu8 %%zmm17,(%[dst_u]) \n" + "vmovdqu8 %%zmm21,(%[dst_u],%[dst_v],1) \n" + "lea 0x40(%[dst_u]),%[dst_u] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovq %[temp],%%k1 \n" + "kshiftrq $16,%%k1,%%k2 \n" + "kshiftrq $32,%%k1,%%k3 \n" + "kshiftrq $48,%%k1,%%k4 \n" + "vmovdqu32 (%[src_argb]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src_argb]),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu32 0x80(%[src_argb]),%%zmm2%{%%k3%}%{z%} \n" + "vmovdqu32 0xc0(%[src_argb]),%%zmm7%{%%k4%}%{z%} \n" + "vmovdqa64 %%zmm5,%%zmm17 \n" + "vmovdqa64 %%zmm5,%%zmm18 \n" + "vmovdqa64 %%zmm5,%%zmm19 \n" + "vmovdqa64 %%zmm5,%%zmm20 \n" + "vmovdqa64 %%zmm5,%%zmm21 \n" + "vmovdqa64 %%zmm5,%%zmm22 \n" + "vmovdqa64 %%zmm5,%%zmm23 \n" + "vmovdqa64 %%zmm5,%%zmm24 \n" + "vpdpbusd %%zmm3,%%zmm0,%%zmm17 \n" + "vpdpbusd %%zmm4,%%zmm0,%%zmm21 \n" + "vpdpbusd %%zmm3,%%zmm1,%%zmm18 \n" + "vpdpbusd %%zmm4,%%zmm1,%%zmm22 \n" + "vpdpbusd %%zmm3,%%zmm2,%%zmm19 \n" + "vpdpbusd %%zmm4,%%zmm2,%%zmm23 \n" + "vpdpbusd %%zmm3,%%zmm7,%%zmm20 \n" + "vpdpbusd %%zmm4,%%zmm7,%%zmm24 \n" + "vpermt2b %%zmm18,%%zmm16,%%zmm17 \n" + "vpermt2b %%zmm20,%%zmm16,%%zmm19 \n" + "vpermt2b %%zmm22,%%zmm16,%%zmm21 \n" + "vpermt2b %%zmm24,%%zmm16,%%zmm23 \n" + "vpternlogd $0x27,%%zmm6,%%zmm19,%%zmm17 \n" + "vpternlogd $0x27,%%zmm6,%%zmm23,%%zmm21 \n" + "vmovdqu8 %%zmm17,(%[dst_u])%{%%k1%} \n" + "vmovdqu8 %%zmm21,(%[dst_u],%[dst_v],1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src_argb] "+r"(src_argb), [dst_u] "+r"(dst_u), [dst_v] "+r"(dst_v), + [width] "+r"(width), [temp] "=&r"(temp) + : [c] "r"(c), [perm] "m"(kPermbDWordByte1_AVX512VNNIVBMI) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7", "xmm16", "xmm17", "xmm18", "xmm19", "xmm20", "xmm21", "xmm22", + "xmm23", "xmm24", "k1", "k2", "k3", "k4"); +} +#endif // HAS_ARGBTOUV444MATRIXROW_AVX512VNNIVBMI + +#ifdef HAS_ARGBTOUVMATRIXROW_SSSE3 + +// ARGBARGB to AARRGGBB shuffle +static const lvec8 kShuffleAARRGGBB = { + 0, 4, 1, 5, 2, 6, 3, 7, 8, 12, 9, 13, 10, 14, 11, 15, + 0, 4, 1, 5, 2, 6, 3, 7, 8, 12, 9, 13, 10, 14, 11, 15, +}; + +// 8x2 -> 4x1 ARGB pixels converted to 4 U and 4 V +// ARGBToUV does rounding average of 4 ARGB pixels +void OMITFP ARGBToUVMatrixRow_SSSE3(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { +#if defined(__i386__) + uvec8 rgb_to_u; + uvec8 rgb_to_v; + uvec16 add_uv; + memcpy(&rgb_to_u, c->kRGBToU, sizeof(rgb_to_u)); + memcpy(&rgb_to_v, c->kRGBToV, sizeof(rgb_to_v)); + memcpy(&add_uv, c->kAddUV, sizeof(add_uv)); +#endif + asm volatile( +#if defined(__i386__) + "movdqa %5,%%xmm4 \n" // RGBToU + "movdqa %6,%%xmm5 \n" // RGBToV + "pcmpeqb %%xmm6,%%xmm6 \n" // 0x0101 + "pabsb %%xmm6,%%xmm6 \n" + "movdqa %8,%%xmm7 \n" // kShuffleAARRGGBB +#else + "movdqu 0x20(%5),%%xmm4 \n" // RGBToU + "movdqu 0x40(%5),%%xmm5 \n" // RGBToV + "pcmpeqb %%xmm6,%%xmm6 \n" // 0x0101 + "pabsb %%xmm6,%%xmm6 \n" + "movdqa %6,%%xmm7 \n" // kShuffleAARRGGBB +#endif + "sub %1,%2 \n" + + "1: \n" + "movdqu (%0),%%xmm0 \n" // Read 8x2 ARGB Pixels + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x00(%0,%4,1),%%xmm2 \n" + "movdqu 0x10(%0,%4,1),%%xmm3 \n" + "pshufb %%xmm7,%%xmm0 \n" // aarrggbb + "pshufb %%xmm7,%%xmm1 \n" + "pshufb %%xmm7,%%xmm2 \n" + "pshufb %%xmm7,%%xmm3 \n" + "pmaddubsw %%xmm6,%%xmm0 \n" // 8x2 -> 4x2 + "pmaddubsw %%xmm6,%%xmm1 \n" + "pmaddubsw %%xmm6,%%xmm2 \n" + "pmaddubsw %%xmm6,%%xmm3 \n" + "paddw %%xmm2,%%xmm0 \n" // 4x2 -> 4x1 + "paddw %%xmm3,%%xmm1 \n" + "pxor %%xmm2,%%xmm2 \n" // 0 for vpavgw + "psrlw $1,%%xmm0 \n" + "psrlw $1,%%xmm1 \n" + "pavgw %%xmm2,%%xmm0 \n" + "pavgw %%xmm2,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" // mutates + +#if defined(__i386__) + "movdqa %7,%%xmm2 \n" // kAddUV +#else + "movdqu 0x80(%5),%%xmm2 \n" // kAddUV +#endif + "movdqa %%xmm0,%%xmm1 \n" + "pmaddubsw %%xmm5,%%xmm1 \n" // 4 V + "pmaddubsw %%xmm4,%%xmm0 \n" // 4 U + "phaddw %%xmm1,%%xmm0 \n" // uuuuvvvv + "psubw %%xmm0,%%xmm2 \n" + "psrlw $0x8,%%xmm2 \n" + "packuswb %%xmm2,%%xmm2 \n" + "movd %%xmm2,(%1) \n" // Write 4 U's + "pshufd $0x55,%%xmm2,%%xmm2 \n" // Copy V to low 4 bytes + "movd %%xmm2,0x00(%1,%2,1) \n" // Write 4 V's + + "lea 0x20(%0),%0 \n" + "lea 0x4(%1),%1 \n" + "subl $0x8,%3 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 +#if defined(__i386__) + "+m"(width) // %3 +#else + "+rm"(width) // %3 +#endif + : "r"((ptrdiff_t)(src_stride_argb)), // %4 +#if defined(__i386__) + "m"(rgb_to_u), // %5 + "m"(rgb_to_v), // %6 + "m"(add_uv), // %7 + "m"(kShuffleAARRGGBB) // %8 +#else + "r"(c), // %5 + "m"(kShuffleAARRGGBB) // %6 +#endif + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); } -void ABGRToUVRow_SSSE3(const uint8_t* src_abgr0, - int src_stride_abgr, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { +#endif // HAS_ARGBTOUVMATRIXROW_SSSE3 + +#ifdef HAS_ARGBTOUVMATRIXROW_AVX2 + +// 16x2 -> 8x1 ARGB pixels converted to 8 U and 8 V +// ARGBToUV does rounding average of 4 ARGB pixels +void OMITFP ARGBToUVMatrixRow_AVX2(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { +#if defined(__i386__) + uvec8 rgb_to_u; + uvec8 rgb_to_v; + uvec16 add_uv; + memcpy(&rgb_to_u, c->kRGBToU, sizeof(rgb_to_u)); + memcpy(&rgb_to_v, c->kRGBToV, sizeof(rgb_to_v)); + memcpy(&add_uv, c->kAddUV, sizeof(add_uv)); +#endif asm volatile( - "movdqa %5,%%xmm3 \n" - "movdqa %6,%%xmm4 \n" - "movdqa %7,%%xmm5 \n" - "sub %1,%2 \n" +#if defined(__i386__) + "vbroadcasti128 %5,%%ymm4 \n" // RGBToU + "vbroadcasti128 %6,%%ymm5 \n" // RGBToV + "vpcmpeqb %%ymm6,%%ymm6,%%ymm6 \n" // 0x0101 + "vpabsb %%ymm6,%%ymm6 \n" + "vmovdqa %8,%%ymm7 \n" // kShuffleAARRGGBB +#else + "vbroadcasti128 0x20(%5),%%ymm4 \n" // RGBToU + "vbroadcasti128 0x40(%5),%%ymm5 \n" // RGBToV + "vpcmpeqb %%ymm6,%%ymm6,%%ymm6 \n" // 0x0101 + "vpabsb %%ymm6,%%ymm6 \n" + "vmovdqa %6,%%ymm7 \n" // kShuffleAARRGGBB +#endif + "sub %1,%2 \n" + + "1: \n" + "vmovdqu (%0),%%ymm0 \n" // Read 16x2 ARGB Pixels + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu 0x00(%0,%4,1),%%ymm2 \n" + "vmovdqu 0x20(%0,%4,1),%%ymm3 \n" + "vpshufb %%ymm7,%%ymm0,%%ymm0 \n" // aarrggbb + "vpshufb %%ymm7,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm7,%%ymm2,%%ymm2 \n" + "vpshufb %%ymm7,%%ymm3,%%ymm3 \n" + "vpmaddubsw %%ymm6,%%ymm0,%%ymm0 \n" // 16x2 -> 8x2 + "vpmaddubsw %%ymm6,%%ymm1,%%ymm1 \n" + "vpmaddubsw %%ymm6,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm6,%%ymm3,%%ymm3 \n" + "vpaddw %%ymm0,%%ymm2,%%ymm0 \n" // 8x2 -> 8x1 + "vpaddw %%ymm1,%%ymm3,%%ymm1 \n" + "vpxor %%ymm2,%%ymm2,%%ymm2 \n" // 0 for vpavgw + "vpsrlw $1,%%ymm0,%%ymm0 \n" + "vpsrlw $1,%%ymm1,%%ymm1 \n" + "vpavgw %%ymm2,%%ymm0,%%ymm0 \n" + "vpavgw %%ymm2,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" // mutates + "vpermq $0xd8,%%ymm0,%%ymm0 \n" // 8 ARGB Pixels + +#if defined(__i386__) + "vbroadcasti128 %7,%%ymm2 \n" // kAddUV +#else + "vmovdqu 0x80(%5),%%ymm2 \n" // kAddUV +#endif + "vpmaddubsw %%ymm5,%%ymm0,%%ymm1 \n" // 8 V + "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" // 8 U + "vphaddw %%ymm1,%%ymm0,%%ymm0 \n" // uuuuvvvv uuuuvvvv + "vpermq $0xd8,%%ymm0,%%ymm0 \n" // uuuuuuuu vvvvvvvv + "vpsubw %%ymm0,%%ymm2,%%ymm0 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" // mutates 8U8u- 8V8v + "vmovq %%xmm0,(%1) \n" // Write 8 U's + "vextractf128 $0x1,%%ymm0,%%xmm0 \n" // Copy V to low 8 bytes + "vmovq %%xmm0,0x00(%1,%2,1) \n" // Write 8 V's + + "lea 0x40(%0),%0 \n" + "lea 0x8(%1),%1 \n" + "subl $0x10,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 +#if defined(__i386__) + "+m"(width) // %3 +#else + "+rm"(width) // %3 +#endif + : "r"((ptrdiff_t)(src_stride_argb)), // %4 +#if defined(__i386__) + "m"(rgb_to_u), // %5 + "m"(rgb_to_v), // %6 + "m"(add_uv), // %7 + "m"(kShuffleAARRGGBB) // %8 +#else + "r"(c), // %5 + "m"(kShuffleAARRGGBB) // %6 +#endif + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_ARGBTOUVMATRIXROW_AVX2 + +// RGB to BT601 coefficients +// UB 0.875 coefficient = 112 +// UG -0.5781 coefficient = -74 +// UR -0.2969 coefficient = -38 +// VB -0.1406 coefficient = -18 +// VG -0.7344 coefficient = -94 +// VR 0.875 coefficient = 112 + +#ifdef HAS_ARGBTOUVMATRIXROW_AVX512BW + +// 32x2 -> 16x1 ARGB pixels converted to 16 U and 16 V +// ARGBToUV does rounding average of 4 ARGB pixels + +LIBYUV_TARGET_AVX512BW +void ARGBToUVMatrixRow_AVX512BW(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + uintptr_t temp; + asm volatile( + "vbroadcasti32x4 0x20(%[c]),%%zmm4 \n" // RGBToU + "vbroadcasti32x4 0x40(%[c]),%%zmm5 \n" // RGBToV + "vpternlogd $0xff,%%zmm16,%%zmm16,%%zmm16 \n" + "vpabsb %%zmm16,%%zmm20 \n" // 0x0101 + "vbroadcasti32x4 0x80(%[c]),%%zmm17 \n" // kAddUV + "vbroadcasti32x4 %[shuf],%%zmm21 \n" // kShuffleAARRGGBB + "vmovups %[permy],%%zmm18 \n" // kPermdARGBToY_AVX512BW + "vmovups %[permuv],%%zmm19 \n" // kPermdARGBToUV_AVX512BW + "sub %1,%2 \n" + "subl $0x20,%3 \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x00(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x10(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x20(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm2 \n" - "movdqu 0x30(%0),%%xmm6 \n" - "movdqu 0x30(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm6 \n" + "1: \n" + "vmovups (%0),%%zmm0 \n" // Read 32x2 ARGB Pixels + "vmovups 0x40(%0),%%zmm1 \n" + "vmovups 0x00(%0,%[stride],1),%%zmm2 \n" + "vmovups 0x40(%0,%[stride],1),%%zmm3 \n" + "vpshufb %%zmm21,%%zmm0,%%zmm0 \n" // aarrggbb + "vpshufb %%zmm21,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm21,%%zmm2,%%zmm2 \n" + "vpshufb %%zmm21,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm20,%%zmm0,%%zmm0 \n" // 32x2 -> 16x2 + "vpmaddubsw %%zmm20,%%zmm1,%%zmm1 \n" + "vpmaddubsw %%zmm20,%%zmm2,%%zmm2 \n" + "vpmaddubsw %%zmm20,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm0,%%zmm2,%%zmm0 \n" // 16x2 -> 16x1 + "vpaddw %%zmm1,%%zmm3,%%zmm1 \n" + "vpxorq %%zmm2,%%zmm2,%%zmm2 \n" // 0 for vpavgw + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm1,%%zmm1 \n" + "vpavgw %%zmm2,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm2,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" // mutates + "vpermd %%zmm0,%%zmm19,%%zmm0 \n" // unscramble pixels - "lea 0x40(%0),%0 \n" - "movdqa %%xmm0,%%xmm7 \n" - "shufps $0x88,%%xmm1,%%xmm0 \n" - "shufps $0xdd,%%xmm1,%%xmm7 \n" - "pavgb %%xmm7,%%xmm0 \n" - "movdqa %%xmm2,%%xmm7 \n" - "shufps $0x88,%%xmm6,%%xmm2 \n" - "shufps $0xdd,%%xmm6,%%xmm7 \n" - "pavgb %%xmm7,%%xmm2 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm2,%%xmm6 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm3,%%xmm1 \n" - "pmaddubsw %%xmm3,%%xmm6 \n" - "phaddw %%xmm2,%%xmm0 \n" - "phaddw %%xmm6,%%xmm1 \n" - "psraw $0x8,%%xmm0 \n" - "psraw $0x8,%%xmm1 \n" - "packsswb %%xmm1,%%xmm0 \n" - "paddb %%xmm5,%%xmm0 \n" - "movlps %%xmm0,(%1) \n" - "movhps %%xmm0,0x00(%1,%2,1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x10,%3 \n" - "jg 1b \n" - : "+r"(src_abgr0), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+rm"(width) // %3 - : "r"((intptr_t)(src_stride_abgr)), // %4 - "m"(kABGRToV), // %5 - "m"(kABGRToU), // %6 - "m"(kAddUV128) // %7 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"); + "vpmaddubsw %%zmm4,%%zmm0,%%zmm1 \n" // 16 U + "vpmaddubsw %%zmm5,%%zmm0,%%zmm0 \n" // 16 V + "vpmaddwd %%zmm16,%%zmm1,%%zmm1 \n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpackssdw %%zmm0,%%zmm1,%%zmm0 \n" // mutates (U in lower, V + // in upper) + "vpaddw %%zmm17,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm0,%%zmm0,%%zmm0 \n" // mutates + "vpermd %%zmm0,%%zmm18,%%zmm0 \n" // unmutate + + "vmovdqu %%xmm0,(%1) \n" // Write 16 U's + "vextracti32x4 $0x1,%%zmm0,%%xmm0 \n" + "vmovdqu %%xmm0,0x00(%1,%2,1) \n" // Write 16 V's + + "lea 0x80(%0),%0 \n" + "lea 0x10(%1),%1 \n" + "subl $0x20,%3 \n" + "jge 1b \n" + + "2: \n" + "addl $0x20,%3 \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q3,%[temp],%[temp] \n" + "kmovd %k[temp],%%k1 \n" + "kshiftrd $16,%%k1,%%k2 \n" + "knotw %%k1,%%k3 \n" + "knotw %%k2,%%k4 \n" + "vmovdqu32 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%0),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu32 0x00(%0,%[stride],1),%%zmm2%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%0,%[stride],1),%%zmm3%{%%k2%}%{z%} \n" + "vpshufd $0xa0,%%zmm0,%%zmm0%{%%k3%} \n" + "vpshufd $0xa0,%%zmm1,%%zmm1%{%%k4%} \n" + "vpshufd $0xa0,%%zmm2,%%zmm2%{%%k3%} \n" + "vpshufd $0xa0,%%zmm3,%%zmm3%{%%k4%} \n" + "vpshufb %%zmm21,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm21,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm21,%%zmm2,%%zmm2 \n" + "vpshufb %%zmm21,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm20,%%zmm0,%%zmm0 \n" + "vpmaddubsw %%zmm20,%%zmm1,%%zmm1 \n" + "vpmaddubsw %%zmm20,%%zmm2,%%zmm2 \n" + "vpmaddubsw %%zmm20,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm0,%%zmm2,%%zmm0 \n" + "vpaddw %%zmm1,%%zmm3,%%zmm1 \n" + "vpxorq %%zmm2,%%zmm2,%%zmm2 \n" + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm1,%%zmm1 \n" + "vpavgw %%zmm2,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm2,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm19,%%zmm0 \n" + + "vpmaddubsw %%zmm4,%%zmm0,%%zmm1 \n" + "vpmaddubsw %%zmm5,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm1,%%zmm1 \n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpackssdw %%zmm0,%%zmm1,%%zmm0 \n" + "vpaddw %%zmm17,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm0,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm18,%%zmm0 \n" + + "addl $1,%3 \n" + "shrl $1,%3 \n" + "mov $-1,%[temp] \n" + "bzhi %q3,%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu8 %%xmm0,(%1)%{%%k1%} \n" + "vextracti32x4 $0x1,%%zmm0,%%xmm0 \n" + "vmovdqu8 %%xmm0,0x00(%1,%2,1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width), // %3 + [temp] "=&r"(temp) // %[temp] + : [stride] "r"((ptrdiff_t)(src_stride_argb)), // %[stride] + [c] "r"(c), // %[c] + [shuf] "m"(kShuffleAARRGGBB), // %[shuf] + [permy] "m"(kPermdARGBToY_AVX512BW), // %[permy] + [permuv] "m"(kPermdARGBToUV_AVX512BW) // %[permuv] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm16", + "xmm17", "xmm18", "xmm19", "xmm20", "xmm21", "k1", "k2", "k3", "k4"); } +#endif // HAS_ARGBTOUVMATRIXROW_AVX512BW -void RGBAToUVRow_SSSE3(const uint8_t* src_rgba0, - int src_stride_rgba, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { +#ifdef HAS_ARGBTOUVMATRIXROW_AVX512VNNI + +// 32x2 -> 16x1 ARGB pixels converted to 16 U and 16 V +// ARGBToUV does rounding average of 4 ARGB pixels + +LIBYUV_TARGET_AVX512VNNI +void ARGBToUVMatrixRow_AVX512VNNI(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + uintptr_t temp; asm volatile( - "movdqa %5,%%xmm3 \n" - "movdqa %6,%%xmm4 \n" - "movdqa %7,%%xmm5 \n" - "sub %1,%2 \n" + "vbroadcasti32x4 0x20(%[c]),%%zmm4 \n" // RGBToU (signed) + "vbroadcasti32x4 0x40(%[c]),%%zmm5 \n" // RGBToV (signed) + "vpternlogd $0xff,%%zmm16,%%zmm16,%%zmm16 \n" + "vpabsb %%zmm16,%%zmm20 \n" // 0x0101 + "vbroadcasti32x4 0x80(%[c]),%%zmm17 \n" // kAddUV + "vbroadcasti32x4 %[shuf],%%zmm21 \n" // kShuffleAARRGGBB + "vmovups %[permy],%%zmm18 \n" // kPermdARGBToY_AVX512BW + "vmovups %[permuv],%%zmm19 \n" // kPermdARGBToUV_AVX512BW + "sub %1,%2 \n" + "subl $0x20,%3 \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x00(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x10(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x20(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm2 \n" - "movdqu 0x30(%0),%%xmm6 \n" - "movdqu 0x30(%0,%4,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm6 \n" + "1: \n" + "vmovups (%0),%%zmm0 \n" // Read 32x2 ARGB Pixels + "vmovups 0x40(%0),%%zmm1 \n" + "vmovups 0x00(%0,%[stride],1),%%zmm2 \n" + "vmovups 0x40(%0,%[stride],1),%%zmm3 \n" + "vpshufb %%zmm21,%%zmm0,%%zmm0 \n" // aarrggbb + "vpshufb %%zmm21,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm21,%%zmm2,%%zmm2 \n" + "vpshufb %%zmm21,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm20,%%zmm0,%%zmm0 \n" // 32x2 -> 16x2 + "vpmaddubsw %%zmm20,%%zmm1,%%zmm1 \n" + "vpmaddubsw %%zmm20,%%zmm2,%%zmm2 \n" + "vpmaddubsw %%zmm20,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm0,%%zmm2,%%zmm0 \n" // 16x2 -> 16x1 + "vpaddw %%zmm1,%%zmm3,%%zmm1 \n" + "vpxorq %%zmm2,%%zmm2,%%zmm2 \n" // 0 for vpavgw and + // vpdpbusd + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm1,%%zmm1 \n" + "vpavgw %%zmm2,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm2,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" // mutates + "vpermd %%zmm0,%%zmm19,%%zmm0 \n" // unscramble pixels - "lea 0x40(%0),%0 \n" - "movdqa %%xmm0,%%xmm7 \n" - "shufps $0x88,%%xmm1,%%xmm0 \n" - "shufps $0xdd,%%xmm1,%%xmm7 \n" - "pavgb %%xmm7,%%xmm0 \n" - "movdqa %%xmm2,%%xmm7 \n" - "shufps $0x88,%%xmm6,%%xmm2 \n" - "shufps $0xdd,%%xmm6,%%xmm7 \n" - "pavgb %%xmm7,%%xmm2 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm2,%%xmm6 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm3,%%xmm1 \n" - "pmaddubsw %%xmm3,%%xmm6 \n" - "phaddw %%xmm2,%%xmm0 \n" - "phaddw %%xmm6,%%xmm1 \n" - "psraw $0x8,%%xmm0 \n" - "psraw $0x8,%%xmm1 \n" - "packsswb %%xmm1,%%xmm0 \n" - "paddb %%xmm5,%%xmm0 \n" - "movlps %%xmm0,(%1) \n" - "movhps %%xmm0,0x00(%1,%2,1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x10,%3 \n" - "jg 1b \n" - : "+r"(src_rgba0), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+rm"(width) // %3 - : "r"((intptr_t)(src_stride_rgba)), // %4 - "m"(kRGBAToV), // %5 - "m"(kRGBAToU), // %6 - "m"(kAddUV128) // %7 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"); + "vpxorq %%zmm1,%%zmm1,%%zmm1 \n" + "vpdpbusd %%zmm4,%%zmm0,%%zmm1 \n" // 16 U (negated) + "vpdpbusd %%zmm5,%%zmm0,%%zmm2 \n" // 16 V (negated) + "vpackssdw %%zmm2,%%zmm1,%%zmm0 \n" // mutates (U in lower, V + // in upper) + "vpsubw %%zmm0,%%zmm17,%%zmm0 \n" // 0x8000 - dot16 + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm0,%%zmm0,%%zmm0 \n" // mutates + "vpermd %%zmm0,%%zmm18,%%zmm0 \n" // unmutate + + "vmovdqu %%xmm0,(%1) \n" // Write 16 U's + "vextracti32x4 $0x1,%%zmm0,%%xmm0 \n" + "vmovdqu %%xmm0,0x00(%1,%2,1) \n" // Write 16 V's + + "lea 0x80(%0),%0 \n" + "lea 0x10(%1),%1 \n" + "subl $0x20,%3 \n" + "jge 1b \n" + + "2: \n" + "addl $0x20,%3 \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q3,%[temp],%[temp] \n" + "kmovd %k[temp],%%k1 \n" + "kshiftrd $16,%%k1,%%k2 \n" + "knotw %%k1,%%k3 \n" + "knotw %%k2,%%k4 \n" + "vmovdqu32 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%0),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu32 0x00(%0,%[stride],1),%%zmm2%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%0,%[stride],1),%%zmm3%{%%k2%}%{z%} \n" + "vpshufd $0xa0,%%zmm0,%%zmm0%{%%k3%} \n" + "vpshufd $0xa0,%%zmm1,%%zmm1%{%%k4%} \n" + "vpshufd $0xa0,%%zmm2,%%zmm2%{%%k3%} \n" + "vpshufd $0xa0,%%zmm3,%%zmm3%{%%k4%} \n" + "vpshufb %%zmm21,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm21,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm21,%%zmm2,%%zmm2 \n" + "vpshufb %%zmm21,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm20,%%zmm0,%%zmm0 \n" + "vpmaddubsw %%zmm20,%%zmm1,%%zmm1 \n" + "vpmaddubsw %%zmm20,%%zmm2,%%zmm2 \n" + "vpmaddubsw %%zmm20,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm0,%%zmm2,%%zmm0 \n" + "vpaddw %%zmm1,%%zmm3,%%zmm1 \n" + "vpxorq %%zmm2,%%zmm2,%%zmm2 \n" + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm1,%%zmm1 \n" + "vpavgw %%zmm2,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm2,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm19,%%zmm0 \n" + + "vpxorq %%zmm1,%%zmm1,%%zmm1 \n" + "vpdpbusd %%zmm4,%%zmm0,%%zmm1 \n" + "vpdpbusd %%zmm5,%%zmm0,%%zmm2 \n" + "vpackssdw %%zmm2,%%zmm1,%%zmm0 \n" + "vpsubw %%zmm0,%%zmm17,%%zmm0 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm0,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm18,%%zmm0 \n" + + "addl $1,%3 \n" + "shrl $1,%3 \n" + "mov $-1,%[temp] \n" + "bzhi %q3,%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu8 %%xmm0,(%1)%{%%k1%} \n" + "vextracti32x4 $0x1,%%zmm0,%%xmm0 \n" + "vmovdqu8 %%xmm0,0x00(%1,%2,1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width), // %3 + [temp] "=&r"(temp) // %[temp] + : [stride] "r"((ptrdiff_t)(src_stride_argb)), // %[stride] + [c] "r"(c), // %[c] + [shuf] "m"(kShuffleAARRGGBB), // %[shuf] + [permy] "m"(kPermdARGBToY_AVX512BW), // %[permy] + [permuv] "m"(kPermdARGBToUV_AVX512BW) // %[permuv] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm16", + "xmm17", "xmm18", "xmm19", "xmm20", "xmm21", "k1", "k2", "k3", "k4"); } +#endif // HAS_ARGBTOUVMATRIXROW_AVX512VNNI + +#ifdef HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI + +// Requires AVX512VNNI and AVX512VBMI. +// 32x2 -> 16x1 ARGB pixels converted to 16 U and 16 V +// ARGBToUV does rounding average of 4 ARGB pixels + +LIBYUV_TARGET_AVX512VNNIVBMI +void ARGBToUVMatrixRow_AVX512VNNIVBMI(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + uintptr_t temp; + asm volatile( + "vbroadcasti32x4 0x20(%[c]),%%zmm4 \n" // RGBToU (signed) + "vbroadcasti32x4 0x40(%[c]),%%zmm5 \n" // RGBToV (signed) + "vpternlogd $0xff,%%zmm16,%%zmm16,%%zmm16 \n" + "vpabsb %%zmm16,%%zmm20 \n" // 0x0101 + "vpmovzxwd 0x80(%[c]),%%zmm17 \n" // kAddUV (32-bit) + "vpternlogd $0x55,%%zmm17,%%zmm17,%%zmm17 \n" // ~kAddUV + "vbroadcasti32x4 %[shuf],%%zmm21 \n" // kShuffleAARRGGBB + "vbroadcasti64x4 %[permb],%%zmm18 \n" // byte 1 of int32 + "vmovups %[permuv],%%zmm19 \n" // kPermdARGBToUV_AVX512BW + "sub %1,%2 \n" + "subl $0x20,%3 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovups (%0),%%zmm0 \n" // Read 32x2 ARGB Pixels + "vmovups 0x40(%0),%%zmm1 \n" + "vmovups 0x00(%0,%[stride],1),%%zmm2 \n" + "vmovups 0x40(%0,%[stride],1),%%zmm3 \n" + "vpshufb %%zmm21,%%zmm0,%%zmm0 \n" // aarrggbb + "vpshufb %%zmm21,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm21,%%zmm2,%%zmm2 \n" + "vpshufb %%zmm21,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm20,%%zmm0,%%zmm0 \n" // 32x2 -> 16x2 + "vpmaddubsw %%zmm20,%%zmm1,%%zmm1 \n" + "vpmaddubsw %%zmm20,%%zmm2,%%zmm2 \n" + "vpmaddubsw %%zmm20,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm0,%%zmm2,%%zmm0 \n" // 16x2 -> 16x1 + "vpaddw %%zmm1,%%zmm3,%%zmm1 \n" + "vpxorq %%zmm2,%%zmm2,%%zmm2 \n" // 0 for vpavgw and + // vpdpbusd + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm1,%%zmm1 \n" + "vpavgw %%zmm2,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm2,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" // mutates + "vpermd %%zmm0,%%zmm19,%%zmm0 \n" // unscramble pixels + + "vmovdqa64 %%zmm17,%%zmm1 \n" // ~kAddUV + "vmovdqa64 %%zmm17,%%zmm3 \n" + "vpdpbusd %%zmm4,%%zmm0,%%zmm1 \n" // ~(16 U) + "vpdpbusd %%zmm5,%%zmm0,%%zmm3 \n" // ~(16 V) + "vpermt2b %%zmm3,%%zmm18,%%zmm1 \n" // byte 1 of U and V + "vpternlogd $0x55,%%ymm1,%%ymm1,%%ymm1 \n" // invert + + "vmovdqu %%xmm1,(%1) \n" // Write 16 U's + "vextracti32x4 $0x1,%%ymm1,0x00(%1,%2,1) \n" // Write 16 V's + + "lea 0x80(%0),%0 \n" + "lea 0x10(%1),%1 \n" + "subl $0x20,%3 \n" + "jge 1b \n" + + "2: \n" + "addl $0x20,%3 \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q3,%[temp],%[temp] \n" + "kmovd %k[temp],%%k1 \n" + "kshiftrd $16,%%k1,%%k2 \n" + "knotw %%k1,%%k3 \n" + "knotw %%k2,%%k4 \n" + "vmovdqu32 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%0),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu32 0x00(%0,%[stride],1),%%zmm2%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%0,%[stride],1),%%zmm3%{%%k2%}%{z%} \n" + "vpshufd $0xa0,%%zmm0,%%zmm0%{%%k3%} \n" + "vpshufd $0xa0,%%zmm1,%%zmm1%{%%k4%} \n" + "vpshufd $0xa0,%%zmm2,%%zmm2%{%%k3%} \n" + "vpshufd $0xa0,%%zmm3,%%zmm3%{%%k4%} \n" + "vpshufb %%zmm21,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm21,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm21,%%zmm2,%%zmm2 \n" + "vpshufb %%zmm21,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm20,%%zmm0,%%zmm0 \n" + "vpmaddubsw %%zmm20,%%zmm1,%%zmm1 \n" + "vpmaddubsw %%zmm20,%%zmm2,%%zmm2 \n" + "vpmaddubsw %%zmm20,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm0,%%zmm2,%%zmm0 \n" + "vpaddw %%zmm1,%%zmm3,%%zmm1 \n" + "vpxorq %%zmm2,%%zmm2,%%zmm2 \n" + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm1,%%zmm1 \n" + "vpavgw %%zmm2,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm2,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vpermd %%zmm0,%%zmm19,%%zmm0 \n" + + "vmovdqa64 %%zmm17,%%zmm1 \n" + "vmovdqa64 %%zmm17,%%zmm3 \n" + "vpdpbusd %%zmm4,%%zmm0,%%zmm1 \n" + "vpdpbusd %%zmm5,%%zmm0,%%zmm3 \n" + "vpermt2b %%zmm3,%%zmm18,%%zmm1 \n" + "vpternlogd $0x55,%%ymm1,%%ymm1,%%ymm1 \n" + + "addl $1,%3 \n" + "shrl $1,%3 \n" + "mov $-1,%[temp] \n" + "bzhi %q3,%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu8 %%xmm1,(%1)%{%%k1%} \n" + "vextracti32x4 $0x1,%%ymm1,%%xmm1 \n" + "vmovdqu8 %%xmm1,0x00(%1,%2,1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width), // %3 + [temp] "=&r"(temp) // %[temp] + : [stride] "r"((ptrdiff_t)(src_stride_argb)), // %[stride] + [c] "r"(c), // %[c] + [shuf] "m"(kShuffleAARRGGBB), // %[shuf] + [permb] "m"(kPermbDWordByte1_AVX512VNNIVBMI), // %[permb] + [permuv] "m"(kPermdARGBToUV_AVX512BW) // %[permuv] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm16", + "xmm17", "xmm18", "xmm19", "xmm20", "xmm21", "k1", "k2", "k3", "k4"); +} +#endif // HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI #if defined(HAS_I422TOARGBROW_SSSE3) || defined(HAS_I422TOARGBROW_AVX2) // Read 8 UV from 444 #define READYUV444 \ - "movq (%[u_buf]),%%xmm0 \n" \ + "movq (%[u_buf]),%%xmm3 \n" \ "movq 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ "lea 0x8(%[u_buf]),%[u_buf] \n" \ - "punpcklbw %%xmm1,%%xmm0 \n" \ + "punpcklbw %%xmm1,%%xmm3 \n" \ "movq (%[y_buf]),%%xmm4 \n" \ "punpcklbw %%xmm4,%%xmm4 \n" \ "lea 0x8(%[y_buf]),%[y_buf] \n" // Read 4 UV from 422, upsample to 8 UV #define READYUV422 \ - "movd (%[u_buf]),%%xmm0 \n" \ + "movd (%[u_buf]),%%xmm3 \n" \ "movd 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ "lea 0x4(%[u_buf]),%[u_buf] \n" \ - "punpcklbw %%xmm1,%%xmm0 \n" \ - "punpcklwd %%xmm0,%%xmm0 \n" \ + "punpcklbw %%xmm1,%%xmm3 \n" \ + "punpcklwd %%xmm3,%%xmm3 \n" \ "movq (%[y_buf]),%%xmm4 \n" \ "punpcklbw %%xmm4,%%xmm4 \n" \ "lea 0x8(%[y_buf]),%[y_buf] \n" // Read 4 UV from 422 10 bit, upsample to 8 UV -// TODO(fbarchard): Consider shufb to replace pack/unpack -// TODO(fbarchard): Consider pmulhuw to replace psraw -// TODO(fbarchard): Consider pmullw to replace psllw and allow different bits. #define READYUV210 \ - "movq (%[u_buf]),%%xmm0 \n" \ + "movq (%[u_buf]),%%xmm3 \n" \ "movq 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ "lea 0x8(%[u_buf]),%[u_buf] \n" \ - "punpcklwd %%xmm1,%%xmm0 \n" \ - "psraw $0x2,%%xmm0 \n" \ - "packuswb %%xmm0,%%xmm0 \n" \ - "punpcklwd %%xmm0,%%xmm0 \n" \ + "punpcklwd %%xmm1,%%xmm3 \n" \ + "psrlw $2,%%xmm3 \n" \ + "packuswb %%xmm3,%%xmm3 \n" \ + "punpcklwd %%xmm3,%%xmm3 \n" \ "movdqu (%[y_buf]),%%xmm4 \n" \ - "psllw $0x6,%%xmm4 \n" \ + "movdqa %%xmm4,%%xmm2 \n" \ + "psllw $6,%%xmm4 \n" \ + "psrlw $4,%%xmm2 \n" \ + "por %%xmm2,%%xmm4 \n" \ + "lea 0x10(%[y_buf]),%[y_buf] \n" + +#define READYUVA210 \ + "movq (%[u_buf]),%%xmm3 \n" \ + "movq 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ + "lea 0x8(%[u_buf]),%[u_buf] \n" \ + "punpcklwd %%xmm1,%%xmm3 \n" \ + "psrlw $2,%%xmm3 \n" \ + "packuswb %%xmm3,%%xmm3 \n" \ + "punpcklwd %%xmm3,%%xmm3 \n" \ + "movdqu (%[y_buf]),%%xmm4 \n" \ + "movdqa %%xmm4,%%xmm2 \n" \ + "psllw $6,%%xmm4 \n" \ + "psrlw $4,%%xmm2 \n" \ + "por %%xmm2,%%xmm4 \n" \ + "lea 0x10(%[y_buf]),%[y_buf] \n" \ + "movdqu (%[a_buf]),%%xmm5 \n" \ + "psrlw $2,%%xmm5 \n" \ + "packuswb %%xmm5,%%xmm5 \n" \ + "lea 0x10(%[a_buf]),%[a_buf] \n" + +// Read 8 UV from 444 10 bit +#define READYUV410 \ + "movdqu (%[u_buf]),%%xmm3 \n" \ + "movdqu 0x00(%[u_buf],%[v_buf],1),%%xmm2 \n" \ + "lea 0x10(%[u_buf]),%[u_buf] \n" \ + "psrlw $2,%%xmm3 \n" \ + "psrlw $2,%%xmm2 \n" \ + "movdqa %%xmm3,%%xmm1 \n" \ + "punpcklwd %%xmm2,%%xmm3 \n" \ + "punpckhwd %%xmm2,%%xmm1 \n" \ + "packuswb %%xmm1,%%xmm3 \n" \ + "movdqu (%[y_buf]),%%xmm4 \n" \ + "movdqa %%xmm4,%%xmm2 \n" \ + "psllw $6,%%xmm4 \n" \ + "psrlw $4,%%xmm2 \n" \ + "por %%xmm2,%%xmm4 \n" \ + "lea 0x10(%[y_buf]),%[y_buf] \n" + +// Read 8 UV from 444 10 bit. With 8 Alpha. +#define READYUVA410 \ + "movdqu (%[u_buf]),%%xmm3 \n" \ + "movdqu 0x00(%[u_buf],%[v_buf],1),%%xmm2 \n" \ + "lea 0x10(%[u_buf]),%[u_buf] \n" \ + "psrlw $2,%%xmm3 \n" \ + "psrlw $2,%%xmm2 \n" \ + "movdqa %%xmm3,%%xmm1 \n" \ + "punpcklwd %%xmm2,%%xmm3 \n" \ + "punpckhwd %%xmm2,%%xmm1 \n" \ + "packuswb %%xmm1,%%xmm3 \n" \ + "movdqu (%[y_buf]),%%xmm4 \n" \ + "movdqa %%xmm4,%%xmm2 \n" \ + "psllw $6,%%xmm4 \n" \ + "psrlw $4,%%xmm2 \n" \ + "por %%xmm2,%%xmm4 \n" \ + "lea 0x10(%[y_buf]),%[y_buf] \n" \ + "movdqu (%[a_buf]),%%xmm5 \n" \ + "psrlw $2,%%xmm5 \n" \ + "packuswb %%xmm5,%%xmm5 \n" \ + "lea 0x10(%[a_buf]),%[a_buf] \n" + +// Read 4 UV from 422 12 bit, upsample to 8 UV +#define READYUV212 \ + "movq (%[u_buf]),%%xmm3 \n" \ + "movq 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ + "lea 0x8(%[u_buf]),%[u_buf] \n" \ + "punpcklwd %%xmm1,%%xmm3 \n" \ + "psrlw $0x4,%%xmm3 \n" \ + "packuswb %%xmm3,%%xmm3 \n" \ + "punpcklwd %%xmm3,%%xmm3 \n" \ + "movdqu (%[y_buf]),%%xmm4 \n" \ + "movdqa %%xmm4,%%xmm2 \n" \ + "psllw $4,%%xmm4 \n" \ + "psrlw $8,%%xmm2 \n" \ + "por %%xmm2,%%xmm4 \n" \ "lea 0x10(%[y_buf]),%[y_buf] \n" // Read 4 UV from 422, upsample to 8 UV. With 8 Alpha. #define READYUVA422 \ - "movd (%[u_buf]),%%xmm0 \n" \ + "movd (%[u_buf]),%%xmm3 \n" \ "movd 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ "lea 0x4(%[u_buf]),%[u_buf] \n" \ - "punpcklbw %%xmm1,%%xmm0 \n" \ - "punpcklwd %%xmm0,%%xmm0 \n" \ + "punpcklbw %%xmm1,%%xmm3 \n" \ + "punpcklwd %%xmm3,%%xmm3 \n" \ + "movq (%[y_buf]),%%xmm4 \n" \ + "punpcklbw %%xmm4,%%xmm4 \n" \ + "lea 0x8(%[y_buf]),%[y_buf] \n" \ + "movq (%[a_buf]),%%xmm5 \n" \ + "lea 0x8(%[a_buf]),%[a_buf] \n" + +// Read 8 UV from 444. With 8 Alpha. +#define READYUVA444 \ + "movq (%[u_buf]),%%xmm3 \n" \ + "movq 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ + "lea 0x8(%[u_buf]),%[u_buf] \n" \ + "punpcklbw %%xmm1,%%xmm3 \n" \ "movq (%[y_buf]),%%xmm4 \n" \ "punpcklbw %%xmm4,%%xmm4 \n" \ "lea 0x8(%[y_buf]),%[y_buf] \n" \ @@ -1966,90 +3995,152 @@ void RGBAToUVRow_SSSE3(const uint8_t* src_rgba0, // Read 4 UV from NV12, upsample to 8 UV #define READNV12 \ - "movq (%[uv_buf]),%%xmm0 \n" \ + "movq (%[uv_buf]),%%xmm3 \n" \ "lea 0x8(%[uv_buf]),%[uv_buf] \n" \ - "punpcklwd %%xmm0,%%xmm0 \n" \ + "punpcklwd %%xmm3,%%xmm3 \n" \ "movq (%[y_buf]),%%xmm4 \n" \ "punpcklbw %%xmm4,%%xmm4 \n" \ "lea 0x8(%[y_buf]),%[y_buf] \n" // Read 4 VU from NV21, upsample to 8 UV #define READNV21 \ - "movq (%[vu_buf]),%%xmm0 \n" \ + "movq (%[vu_buf]),%%xmm3 \n" \ "lea 0x8(%[vu_buf]),%[vu_buf] \n" \ - "pshufb %[kShuffleNV21], %%xmm0 \n" \ + "pshufb %[kShuffleNV21], %%xmm3 \n" \ "movq (%[y_buf]),%%xmm4 \n" \ "punpcklbw %%xmm4,%%xmm4 \n" \ "lea 0x8(%[y_buf]),%[y_buf] \n" -// Read 4 YUY2 with 8 Y and update 4 UV to 8 UV. +// Read 4 YUY2 with 8 Y and upsample 4 UV to 8 UV. +// xmm6 kShuffleYUY2Y, +// xmm7 kShuffleYUY2UV #define READYUY2 \ "movdqu (%[yuy2_buf]),%%xmm4 \n" \ - "pshufb %[kShuffleYUY2Y], %%xmm4 \n" \ - "movdqu (%[yuy2_buf]),%%xmm0 \n" \ - "pshufb %[kShuffleYUY2UV], %%xmm0 \n" \ - "lea 0x10(%[yuy2_buf]),%[yuy2_buf] \n" + "lea 0x10(%[yuy2_buf]),%[yuy2_buf] \n" \ + "movdqa %%xmm4,%%xmm3 \n" \ + "pshufb %%xmm6,%%xmm4 \n" \ + "pshufb %%xmm7,%%xmm3 \n" -// Read 4 UYVY with 8 Y and update 4 UV to 8 UV. +// Read 4 UYVY with 8 Y and upsample 4 UV to 8 UV. +// xmm6 kShuffleUYVYY, +// xmm7 kShuffleUYVYUV #define READUYVY \ "movdqu (%[uyvy_buf]),%%xmm4 \n" \ - "pshufb %[kShuffleUYVYY], %%xmm4 \n" \ - "movdqu (%[uyvy_buf]),%%xmm0 \n" \ - "pshufb %[kShuffleUYVYUV], %%xmm0 \n" \ - "lea 0x10(%[uyvy_buf]),%[uyvy_buf] \n" + "lea 0x10(%[uyvy_buf]),%[uyvy_buf] \n" \ + "movdqa %%xmm4,%%xmm3 \n" \ + "pshufb %%xmm6,%%xmm4 \n" \ + "pshufb %%xmm7,%%xmm3 \n" + +// Read 4 UV from P210, upsample to 8 UV +#define READP210 \ + "movdqu (%[uv_buf]),%%xmm3 \n" \ + "lea 0x10(%[uv_buf]),%[uv_buf] \n" \ + "psrlw $0x8,%%xmm3 \n" \ + "packuswb %%xmm3,%%xmm3 \n" \ + "punpcklwd %%xmm3,%%xmm3 \n" \ + "movdqu (%[y_buf]),%%xmm4 \n" \ + "lea 0x10(%[y_buf]),%[y_buf] \n" + +// Read 8 UV from P410 +#define READP410 \ + "movdqu (%[uv_buf]),%%xmm3 \n" \ + "movdqu 0x10(%[uv_buf]),%%xmm1 \n" \ + "lea 0x20(%[uv_buf]),%[uv_buf] \n" \ + "psrlw $0x8,%%xmm3 \n" \ + "psrlw $0x8,%%xmm1 \n" \ + "packuswb %%xmm1,%%xmm3 \n" \ + "movdqu (%[y_buf]),%%xmm4 \n" \ + "lea 0x10(%[y_buf]),%[y_buf] \n" #if defined(__x86_64__) #define YUVTORGB_SETUP(yuvconstants) \ - "movdqa (%[yuvconstants]),%%xmm8 \n" \ - "movdqa 32(%[yuvconstants]),%%xmm9 \n" \ - "movdqa 64(%[yuvconstants]),%%xmm10 \n" \ - "movdqa 96(%[yuvconstants]),%%xmm11 \n" \ - "movdqa 128(%[yuvconstants]),%%xmm12 \n" \ - "movdqa 160(%[yuvconstants]),%%xmm13 \n" \ - "movdqa 192(%[yuvconstants]),%%xmm14 \n" + "pcmpeqb %%xmm13,%%xmm13 \n" \ + "movdqu (%[yuvconstants]),%%xmm8 \n" \ + "pxor %%xmm12,%%xmm12 \n" \ + "movdqu 32(%[yuvconstants]),%%xmm9 \n" \ + "pavgb %%xmm12,%%xmm13 \n" \ + "movdqu 64(%[yuvconstants]),%%xmm10 \n" \ + "movdqu 96(%[yuvconstants]),%%xmm11 \n" \ + "movdqu 128(%[yuvconstants]),%%xmm12 \n" + +#define YUVTORGB_SETUP_AR30(yuvconstants) \ + YUVTORGB_SETUP(yuvconstants) \ + "pcmpeqb %%xmm0,%%xmm0 \n" \ + "psrlw $14,%%xmm0 \n" \ + "psllw $3,%%xmm0 \n" \ + "psubw %%xmm0,%%xmm12 \n" + // Convert 8 pixels: 8 UV and 8 Y #define YUVTORGB16(yuvconstants) \ - "movdqa %%xmm0,%%xmm1 \n" \ - "movdqa %%xmm0,%%xmm2 \n" \ - "movdqa %%xmm0,%%xmm3 \n" \ - "movdqa %%xmm11,%%xmm0 \n" \ - "pmaddubsw %%xmm8,%%xmm1 \n" \ - "psubw %%xmm1,%%xmm0 \n" \ - "movdqa %%xmm12,%%xmm1 \n" \ - "pmaddubsw %%xmm9,%%xmm2 \n" \ - "psubw %%xmm2,%%xmm1 \n" \ - "movdqa %%xmm13,%%xmm2 \n" \ - "pmaddubsw %%xmm10,%%xmm3 \n" \ - "psubw %%xmm3,%%xmm2 \n" \ - "pmulhuw %%xmm14,%%xmm4 \n" \ + "psubb %%xmm13,%%xmm3 \n" \ + "pmulhuw %%xmm11,%%xmm4 \n" \ + "movdqa %%xmm8,%%xmm0 \n" \ + "movdqa %%xmm9,%%xmm1 \n" \ + "movdqa %%xmm10,%%xmm2 \n" \ + "paddw %%xmm12,%%xmm4 \n" \ + "pmaddubsw %%xmm3,%%xmm0 \n" \ + "pmaddubsw %%xmm3,%%xmm1 \n" \ + "pmaddubsw %%xmm3,%%xmm2 \n" \ "paddsw %%xmm4,%%xmm0 \n" \ - "paddsw %%xmm4,%%xmm1 \n" \ - "paddsw %%xmm4,%%xmm2 \n" -#define YUVTORGB_REGS \ - "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", + "paddsw %%xmm4,%%xmm2 \n" \ + "psubsw %%xmm1,%%xmm4 \n" \ + "movdqa %%xmm4,%%xmm1 \n" + +#define YUVTORGB16_AR30(yuvconstants) YUVTORGB16(yuvconstants) + +#define YUVTORGB_REGS "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", #else #define YUVTORGB_SETUP(yuvconstants) +#define YUVTORGB_SETUP_AR30(yuvconstants) + // Convert 8 pixels: 8 UV and 8 Y #define YUVTORGB16(yuvconstants) \ - "movdqa %%xmm0,%%xmm1 \n" \ - "movdqa %%xmm0,%%xmm2 \n" \ - "movdqa %%xmm0,%%xmm3 \n" \ - "movdqa 96(%[yuvconstants]),%%xmm0 \n" \ - "pmaddubsw (%[yuvconstants]),%%xmm1 \n" \ - "psubw %%xmm1,%%xmm0 \n" \ - "movdqa 128(%[yuvconstants]),%%xmm1 \n" \ - "pmaddubsw 32(%[yuvconstants]),%%xmm2 \n" \ - "psubw %%xmm2,%%xmm1 \n" \ - "movdqa 160(%[yuvconstants]),%%xmm2 \n" \ - "pmaddubsw 64(%[yuvconstants]),%%xmm3 \n" \ - "psubw %%xmm3,%%xmm2 \n" \ - "pmulhuw 192(%[yuvconstants]),%%xmm4 \n" \ + "movdqu 96(%[yuvconstants]),%%xmm0 \n" \ + "pmulhuw %%xmm0,%%xmm4 \n" \ + "pcmpeqb %%xmm0,%%xmm0 \n" \ + "pabsb %%xmm0,%%xmm0 \n" \ + "psllw $7,%%xmm0 \n" \ + "psubb %%xmm0,%%xmm3 \n" \ + "movdqu (%[yuvconstants]),%%xmm0 \n" \ + "movdqu 32(%[yuvconstants]),%%xmm1 \n" \ + "movdqu 64(%[yuvconstants]),%%xmm2 \n" \ + "pmaddubsw %%xmm3,%%xmm0 \n" \ + "pmaddubsw %%xmm3,%%xmm1 \n" \ + "pmaddubsw %%xmm3,%%xmm2 \n" \ + "movdqu 128(%[yuvconstants]),%%xmm3 \n" \ + "paddw %%xmm3,%%xmm4 \n" \ "paddsw %%xmm4,%%xmm0 \n" \ - "paddsw %%xmm4,%%xmm1 \n" \ - "paddsw %%xmm4,%%xmm2 \n" + "paddsw %%xmm4,%%xmm2 \n" \ + "psubsw %%xmm1,%%xmm4 \n" \ + "movdqa %%xmm4,%%xmm1 \n" + +#define YUVTORGB16_AR30(yuvconstants) \ + "movdqu 96(%[yuvconstants]),%%xmm0 \n" \ + "pmulhuw %%xmm0,%%xmm4 \n" \ + "pcmpeqb %%xmm0,%%xmm0 \n" \ + "pabsb %%xmm0,%%xmm0 \n" \ + "psllw $7,%%xmm0 \n" \ + "psubb %%xmm0,%%xmm3 \n" \ + "movdqu (%[yuvconstants]),%%xmm0 \n" \ + "movdqu 32(%[yuvconstants]),%%xmm1 \n" \ + "movdqu 64(%[yuvconstants]),%%xmm2 \n" \ + "pmaddubsw %%xmm3,%%xmm0 \n" \ + "pmaddubsw %%xmm3,%%xmm1 \n" \ + "pmaddubsw %%xmm3,%%xmm2 \n" \ + "movdqu 128(%[yuvconstants]),%%xmm3 \n" \ + "paddw %%xmm3,%%xmm4 \n" \ + "pcmpeqb %%xmm3,%%xmm3 \n" \ + "psrlw $14,%%xmm3 \n" \ + "psllw $3,%%xmm3 \n" \ + "psubw %%xmm3,%%xmm4 \n" \ + "paddsw %%xmm4,%%xmm0 \n" \ + "paddsw %%xmm4,%%xmm2 \n" \ + "psubsw %%xmm1,%%xmm4 \n" \ + "movdqa %%xmm4,%%xmm1 \n" + #define YUVTORGB_REGS -#endif +#endif // defined(__x86_64__) #define YUVTORGB(yuvconstants) \ YUVTORGB16(yuvconstants) \ @@ -2083,28 +4174,40 @@ void RGBAToUVRow_SSSE3(const uint8_t* src_rgba0, "movdqu %%xmm0,0x10(%[dst_rgba]) \n" \ "lea 0x20(%[dst_rgba]),%[dst_rgba] \n" +// Store 8 RGB24 values. +#define STORERGB24 \ + "punpcklbw %%xmm1,%%xmm0 \n" \ + "punpcklbw %%xmm2,%%xmm2 \n" \ + "movdqa %%xmm0,%%xmm1 \n" \ + "punpcklwd %%xmm2,%%xmm0 \n" \ + "punpckhwd %%xmm2,%%xmm1 \n" \ + "pshufb %%xmm5,%%xmm0 \n" \ + "pshufb %%xmm6,%%xmm1 \n" \ + "palignr $0xc,%%xmm0,%%xmm1 \n" \ + "movq %%xmm0,(%[dst_rgb24]) \n" \ + "movdqu %%xmm1,0x8(%[dst_rgb24]) \n" \ + "lea 0x18(%[dst_rgb24]),%[dst_rgb24] \n" + // Store 8 AR30 values. #define STOREAR30 \ - "psraw $0x4,%%xmm0 \n" \ - "psraw $0x4,%%xmm1 \n" \ - "psraw $0x4,%%xmm2 \n" \ "pminsw %%xmm7,%%xmm0 \n" \ "pminsw %%xmm7,%%xmm1 \n" \ "pminsw %%xmm7,%%xmm2 \n" \ "pmaxsw %%xmm6,%%xmm0 \n" \ "pmaxsw %%xmm6,%%xmm1 \n" \ "pmaxsw %%xmm6,%%xmm2 \n" \ - "psllw $0x4,%%xmm2 \n" \ + "movdqa %%xmm1,%%xmm3 \n" \ + "pand %%xmm7,%%xmm3 \n" \ + "pand %%xmm7,%%xmm2 \n" \ + "psrlw $4,%%xmm0 \n" \ + "psrlw $10,%%xmm1 \n" \ + "psllw $6,%%xmm3 \n" \ + "por %%xmm3,%%xmm0 \n" \ + "por %%xmm5,%%xmm2 \n" \ + "por %%xmm1,%%xmm2 \n" \ "movdqa %%xmm0,%%xmm3 \n" \ "punpcklwd %%xmm2,%%xmm0 \n" \ "punpckhwd %%xmm2,%%xmm3 \n" \ - "movdqa %%xmm1,%%xmm2 \n" \ - "punpcklwd %%xmm5,%%xmm1 \n" \ - "punpckhwd %%xmm5,%%xmm2 \n" \ - "pslld $0xa,%%xmm1 \n" \ - "pslld $0xa,%%xmm2 \n" \ - "por %%xmm1,%%xmm0 \n" \ - "por %%xmm2,%%xmm3 \n" \ "movdqu %%xmm0,(%[dst_ar30]) \n" \ "movdqu %%xmm3,0x10(%[dst_ar30]) \n" \ "lea 0x20(%[dst_ar30]), %[dst_ar30] \n" @@ -2117,16 +4220,16 @@ void OMITFP I444ToARGBRow_SSSE3(const uint8_t* y_buf, int width) { asm volatile ( YUVTORGB_SETUP(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "pcmpeqb %%xmm5,%%xmm5 \n" + "sub %[u_buf],%[v_buf] \n" + "pcmpeqb %%xmm5,%%xmm5 \n" LABELALIGN - "1: \n" + "1: \n" READYUV444 YUVTORGB(yuvconstants) STOREARGB - "sub $0x8,%[width] \n" - "jg 1b \n" + "sub $0x8,%[width] \n" + "jg 1b \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] @@ -2138,35 +4241,97 @@ void OMITFP I444ToARGBRow_SSSE3(const uint8_t* y_buf, ); } +#ifdef HAS_I444ALPHATOARGBROW_SSSE3 +void OMITFP I444AlphaToARGBRow_SSSE3(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { +#if defined(__i386__) + uintptr_t temp; + asm volatile( + "mov %[v_buf],%[temp] \n" + "sub %[u_buf],%[temp] \n" + "movd %[temp],%%xmm7 \n" + "movd %[a_buf],%%xmm6 \n" + + LABELALIGN + "1: \n" + "movd %%xmm7,%[temp] \n" + "movq (%[u_buf]),%%xmm3 \n" + "movq 0x00(%[u_buf],%[temp],1),%%xmm1 \n" + "lea 0x8(%[u_buf]),%[u_buf] \n" + "punpcklbw %%xmm1,%%xmm3 \n" + "movq (%[y_buf]),%%xmm4 \n" + "punpcklbw %%xmm4,%%xmm4 \n" + "lea 0x8(%[y_buf]),%[y_buf] \n" + "movd %%xmm6,%[temp] \n" + "movq (%[temp]),%%xmm5 \n" + "lea 0x8(%[temp]),%[temp] \n" + "movd %[temp],%%xmm6 \n" + YUVTORGB(yuvconstants) + STOREARGB + "subl $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [dst_argb] "+r"(dst_argb), + [temp] "=&r"(temp), + [width] "+m"(width) + : [v_buf] "m"(v_buf), + [a_buf] "m"(a_buf), + [yuvconstants] "r"(yuvconstants) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); +#else + asm volatile(YUVTORGB_SETUP( + yuvconstants) "sub %[u_buf],%[v_buf] \n" + + LABELALIGN "1: \n" READYUVA444 YUVTORGB(yuvconstants) + STOREARGB + "subl $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [u_buf] "+r"(u_buf), // %[u_buf] + [v_buf] "+r"(v_buf), // %[v_buf] + [a_buf] "+r"(a_buf), // %[a_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5"); +#endif +} +#endif // HAS_I444ALPHATOARGBROW_SSSE3 + +#ifdef HAS_I422TORGB24ROW_SSSE3 void OMITFP I422ToRGB24Row_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width) { +#if defined(__i386__) + uint32_t shuf0[4]; + uint32_t shuf1[4]; + memcpy(shuf0, &kShuffleMaskARGBToRGB24[0], sizeof(shuf0)); + memcpy(shuf1, &kShuffleMaskARGBToRGB24[1], sizeof(shuf1)); +#endif asm volatile ( YUVTORGB_SETUP(yuvconstants) - "movdqa %[kShuffleMaskARGBToRGB24_0],%%xmm5 \n" - "movdqa %[kShuffleMaskARGBToRGB24],%%xmm6 \n" - "sub %[u_buf],%[v_buf] \n" + "movdqu %[kShuffleMaskARGBToRGB24_1],%%xmm5 \n" + "movdqu %[kShuffleMaskARGBToRGB24_0],%%xmm6 \n" + "sub %[u_buf],%[v_buf] \n" LABELALIGN - "1: \n" + "1: \n" READYUV422 YUVTORGB(yuvconstants) - "punpcklbw %%xmm1,%%xmm0 \n" - "punpcklbw %%xmm2,%%xmm2 \n" - "movdqa %%xmm0,%%xmm1 \n" - "punpcklwd %%xmm2,%%xmm0 \n" - "punpckhwd %%xmm2,%%xmm1 \n" - "pshufb %%xmm5,%%xmm0 \n" - "pshufb %%xmm6,%%xmm1 \n" - "palignr $0xc,%%xmm0,%%xmm1 \n" - "movq %%xmm0,(%[dst_rgb24]) \n" - "movdqu %%xmm1,0x8(%[dst_rgb24]) \n" - "lea 0x18(%[dst_rgb24]),%[dst_rgb24] \n" - "subl $0x8,%[width] \n" - "jg 1b \n" + STORERGB24 + "subl $0x8,%[width] \n" + "jg 1b \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] @@ -2177,12 +4342,67 @@ void OMITFP I422ToRGB24Row_SSSE3(const uint8_t* y_buf, [width]"+rm"(width) // %[width] #endif : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] - [kShuffleMaskARGBToRGB24_0]"m"(kShuffleMaskARGBToRGB24_0), - [kShuffleMaskARGBToRGB24]"m"(kShuffleMaskARGBToRGB24) +#if defined(__i386__) + [kShuffleMaskARGBToRGB24_0]"m"(shuf0), + [kShuffleMaskARGBToRGB24_1]"m"(shuf1) +#else + [kShuffleMaskARGBToRGB24_0]"m"(kShuffleMaskARGBToRGB24[0]), + [kShuffleMaskARGBToRGB24_1]"m"(kShuffleMaskARGBToRGB24[1]) +#endif : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6" ); } +#endif // HAS_I422TORGB24ROW_SSSE3 + +#ifdef HAS_I444TORGB24ROW_SSSE3 +void OMITFP I444ToRGB24Row_SSSE3(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { +#if defined(__i386__) + uint32_t shuf0[4]; + uint32_t shuf1[4]; + memcpy(shuf0, &kShuffleMaskARGBToRGB24[0], sizeof(shuf0)); + memcpy(shuf1, &kShuffleMaskARGBToRGB24[1], sizeof(shuf1)); +#endif + asm volatile ( + YUVTORGB_SETUP(yuvconstants) + "movdqu %[kShuffleMaskARGBToRGB24_1],%%xmm5 \n" + "movdqu %[kShuffleMaskARGBToRGB24_0],%%xmm6 \n" + "sub %[u_buf],%[v_buf] \n" + + LABELALIGN + "1: \n" + READYUV444 + YUVTORGB(yuvconstants) + STORERGB24 + "subl $0x8,%[width] \n" + "jg 1b \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_rgb24]"+r"(dst_rgb24), // %[dst_rgb24] +#if defined(__i386__) + [width]"+m"(width) // %[width] +#else + [width]"+rm"(width) // %[width] +#endif + : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] +#if defined(__i386__) + [kShuffleMaskARGBToRGB24_0]"m"(shuf0), + [kShuffleMaskARGBToRGB24_1]"m"(shuf1) +#else + [kShuffleMaskARGBToRGB24_0]"m"(kShuffleMaskARGBToRGB24[0]), + [kShuffleMaskARGBToRGB24_1]"m"(kShuffleMaskARGBToRGB24[1]) +#endif + : "memory", "cc", YUVTORGB_REGS + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6" + ); +} +#endif // HAS_I444TORGB24ROW_SSSE3 void OMITFP I422ToARGBRow_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, @@ -2192,16 +4412,16 @@ void OMITFP I422ToARGBRow_SSSE3(const uint8_t* y_buf, int width) { asm volatile ( YUVTORGB_SETUP(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "pcmpeqb %%xmm5,%%xmm5 \n" + "sub %[u_buf],%[v_buf] \n" + "pcmpeqb %%xmm5,%%xmm5 \n" LABELALIGN - "1: \n" + "1: \n" READYUV422 YUVTORGB(yuvconstants) STOREARGB - "sub $0x8,%[width] \n" - "jg 1b \n" + "sub $0x8,%[width] \n" + "jg 1b \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] @@ -2213,6 +4433,7 @@ void OMITFP I422ToARGBRow_SSSE3(const uint8_t* y_buf, ); } +#ifdef HAS_I422TOAR30ROW_SSSE3 void OMITFP I422ToAR30Row_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, const uint8_t* v_buf, @@ -2220,32 +4441,37 @@ void OMITFP I422ToAR30Row_SSSE3(const uint8_t* y_buf, const struct YuvConstants* yuvconstants, int width) { asm volatile ( - YUVTORGB_SETUP(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "pcmpeqb %%xmm5,%%xmm5 \n" // AR30 constants - "psrlw $14,%%xmm5 \n" - "psllw $4,%%xmm5 \n" // 2 alpha bits - "pxor %%xmm6,%%xmm6 \n" - "pcmpeqb %%xmm7,%%xmm7 \n" // 0 for min - "psrlw $6,%%xmm7 \n" // 1023 for max + YUVTORGB_SETUP_AR30(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "pcmpeqb %%xmm5,%%xmm5 \n" // all 1s + "movdqa %%xmm5,%%xmm7 \n" + "psrlw $6,%%xmm7 \n" + "psllw $4,%%xmm7 \n" // 1023 * 16 for max + "psllw $14,%%xmm5 \n" // 0xc000 for 2 alpha bits + "pxor %%xmm6,%%xmm6 \n" // 0 for min LABELALIGN - "1: \n" + "1: \n" READYUV422 - YUVTORGB16(yuvconstants) + YUVTORGB16_AR30(yuvconstants) STOREAR30 - "sub $0x8,%[width] \n" - "jg 1b \n" + "subl $0x8,%[width] \n" + "jg 1b \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] [dst_ar30]"+r"(dst_ar30), // %[dst_ar30] +#if defined(__i386__) + [width]"+m"(width) // %[width] +#else [width]"+rm"(width) // %[width] +#endif : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" ); } +#endif // HAS_I422TOAR30ROW_SSSE3 // 10 bit YUV to ARGB void OMITFP I210ToARGBRow_SSSE3(const uint16_t* y_buf, @@ -2256,16 +4482,46 @@ void OMITFP I210ToARGBRow_SSSE3(const uint16_t* y_buf, int width) { asm volatile ( YUVTORGB_SETUP(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "pcmpeqb %%xmm5,%%xmm5 \n" + "sub %[u_buf],%[v_buf] \n" + "pcmpeqb %%xmm5,%%xmm5 \n" LABELALIGN - "1: \n" + "1: \n" READYUV210 YUVTORGB(yuvconstants) STOREARGB - "sub $0x8,%[width] \n" - "jg 1b \n" + "sub $0x8,%[width] \n" + "jg 1b \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_argb]"+r"(dst_argb), // %[dst_argb] + [width]"+rm"(width) // %[width] + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" + ); +} + +// 12 bit YUV to ARGB +void OMITFP I212ToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile ( + YUVTORGB_SETUP(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "pcmpeqb %%xmm5,%%xmm5 \n" + + LABELALIGN + "1: \n" + READYUV212 + YUVTORGB(yuvconstants) + STOREARGB + "sub $0x8,%[width] \n" + "jg 1b \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] @@ -2286,21 +4542,21 @@ void OMITFP I210ToAR30Row_SSSE3(const uint16_t* y_buf, int width) { asm volatile ( YUVTORGB_SETUP(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "pcmpeqb %%xmm5,%%xmm5 \n" - "psrlw $14,%%xmm5 \n" - "psllw $4,%%xmm5 \n" // 2 alpha bits - "pxor %%xmm6,%%xmm6 \n" - "pcmpeqb %%xmm7,%%xmm7 \n" // 0 for min - "psrlw $6,%%xmm7 \n" // 1023 for max + "sub %[u_buf],%[v_buf] \n" + "pcmpeqb %%xmm5,%%xmm5 \n" // all 1s + "movdqa %%xmm5,%%xmm7 \n" + "psrlw $6,%%xmm7 \n" + "psllw $4,%%xmm7 \n" // 1023 * 16 for max + "psllw $14,%%xmm5 \n" // 0xc000 for 2 alpha bits + "pxor %%xmm6,%%xmm6 \n" // 0 for min LABELALIGN - "1: \n" + "1: \n" READYUV210 YUVTORGB16(yuvconstants) STOREAR30 - "sub $0x8,%[width] \n" - "jg 1b \n" + "sub $0x8,%[width] \n" + "jg 1b \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] @@ -2312,6 +4568,255 @@ void OMITFP I210ToAR30Row_SSSE3(const uint16_t* y_buf, ); } +// 12 bit YUV to AR30 +void OMITFP I212ToAR30Row_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile ( + YUVTORGB_SETUP(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "pcmpeqb %%xmm5,%%xmm5 \n" // all 1s + "movdqa %%xmm5,%%xmm7 \n" + "psrlw $6,%%xmm7 \n" + "psllw $4,%%xmm7 \n" // 1023 * 16 for max + "psllw $14,%%xmm5 \n" // 0xc000 for 2 alpha bits + "pxor %%xmm6,%%xmm6 \n" // 0 for min + + LABELALIGN + "1: \n" + READYUV212 + YUVTORGB16(yuvconstants) + STOREAR30 + "sub $0x8,%[width] \n" + "jg 1b \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_ar30]"+r"(dst_ar30), // %[dst_ar30] + [width]"+rm"(width) // %[width] + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" + ); +} + +// 10 bit YUV to ARGB +void OMITFP I410ToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile ( + YUVTORGB_SETUP(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "pcmpeqb %%xmm5,%%xmm5 \n" + + LABELALIGN + "1: \n" + READYUV410 + YUVTORGB(yuvconstants) + STOREARGB + "sub $0x8,%[width] \n" + "jg 1b \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_argb]"+r"(dst_argb), // %[dst_argb] + [width]"+rm"(width) // %[width] + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" + ); +} + +#ifdef HAS_I210ALPHATOARGBROW_SSSE3 +// 10 bit YUVA to ARGB +void OMITFP I210AlphaToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { +#if defined(__i386__) + uintptr_t temp; + asm volatile( + "mov %[v_buf],%[temp] \n" + "sub %[u_buf],%[temp] \n" + "movd %[temp],%%xmm7 \n" + "movd %[a_buf],%%xmm6 \n" + + LABELALIGN + "1: \n" + "movd %%xmm7,%[temp] \n" + "movq (%[u_buf]),%%xmm3 \n" + "movq 0x00(%[u_buf],%[temp],1),%%xmm1 \n" + "lea 0x8(%[u_buf]),%[u_buf] \n" + "punpcklwd %%xmm1,%%xmm3 \n" + "psraw $2,%%xmm3 \n" + "packuswb %%xmm3,%%xmm3 \n" + "punpcklwd %%xmm3,%%xmm3 \n" + "movdqu (%[y_buf]),%%xmm4 \n" + "movdqa %%xmm4,%%xmm2 \n" + "psllw $6,%%xmm4 \n" + "psrlw $4,%%xmm2 \n" + "paddw %%xmm2,%%xmm4 \n" + "lea 0x10(%[y_buf]),%[y_buf] \n" + "movd %%xmm6,%[temp] \n" + "movdqu (%[temp]),%%xmm5 \n" + "psraw $2,%%xmm5 \n" + "packuswb %%xmm5,%%xmm5 \n" + "lea 0x10(%[temp]),%[temp] \n" + "movd %[temp],%%xmm6 \n" + YUVTORGB(yuvconstants) + STOREARGB + "subl $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [dst_argb] "+r"(dst_argb), + [temp] "=&r"(temp), + [width] "+m"(width) + : [v_buf] "m"(v_buf), + [a_buf] "m"(a_buf), + [yuvconstants] "r"(yuvconstants) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); +#else + asm volatile(YUVTORGB_SETUP( + yuvconstants) "sub %[u_buf],%[v_buf] \n" + + LABELALIGN "1: \n" READYUVA210 YUVTORGB(yuvconstants) + STOREARGB + "subl $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [u_buf] "+r"(u_buf), // %[u_buf] + [v_buf] "+r"(v_buf), // %[v_buf] + [a_buf] "+r"(a_buf), + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5"); +#endif +} +#endif // HAS_I210ALPHATOARGBROW_SSSE3 + +#ifdef HAS_I410ALPHATOARGBROW_SSSE3 +// 10 bit YUVA to ARGB +void OMITFP I410AlphaToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { +#if defined(__i386__) + uintptr_t temp; + asm volatile( + "mov %[v_buf],%[temp] \n" + "sub %[u_buf],%[temp] \n" + "movd %[temp],%%xmm7 \n" + "movd %[a_buf],%%xmm6 \n" + + LABELALIGN + "1: \n" + "movd %%xmm7,%[temp] \n" + "movdqu (%[u_buf]),%%xmm3 \n" + "movdqu 0x00(%[u_buf],%[temp],1),%%xmm2 \n" + "lea 0x10(%[u_buf]),%[u_buf] \n" + "psraw $2,%%xmm3 \n" + "psraw $2,%%xmm2 \n" + "movdqa %%xmm3,%%xmm1 \n" + "punpcklwd %%xmm2,%%xmm3 \n" + "punpckhwd %%xmm2,%%xmm1 \n" + "packuswb %%xmm1,%%xmm3 \n" + "movdqu (%[y_buf]),%%xmm4 \n" + "movdqa %%xmm4,%%xmm2 \n" + "psllw $6,%%xmm4 \n" + "psrlw $4,%%xmm2 \n" + "paddw %%xmm2,%%xmm4 \n" + "lea 0x10(%[y_buf]),%[y_buf] \n" + "movd %%xmm6,%[temp] \n" + "movdqu (%[temp]),%%xmm5 \n" + "psraw $2,%%xmm5 \n" + "packuswb %%xmm5,%%xmm5 \n" + "lea 0x10(%[temp]),%[temp] \n" + "movd %[temp],%%xmm6 \n" + YUVTORGB(yuvconstants) + STOREARGB + "subl $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [dst_argb] "+r"(dst_argb), + [temp] "=&r"(temp), + [width] "+m"(width) + : [v_buf] "m"(v_buf), + [a_buf] "m"(a_buf), + [yuvconstants] "r"(yuvconstants) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); +#else + asm volatile(YUVTORGB_SETUP( + yuvconstants) "sub %[u_buf],%[v_buf] \n" + + LABELALIGN "1: \n" READYUVA410 YUVTORGB(yuvconstants) + STOREARGB + "subl $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [u_buf] "+r"(u_buf), // %[u_buf] + [v_buf] "+r"(v_buf), // %[v_buf] + [a_buf] "+r"(a_buf), + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5"); +#endif +} +#endif // HAS_I410ALPHATOARGBROW_SSSE3 + +// 10 bit YUV to AR30 +void OMITFP I410ToAR30Row_SSSE3(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile ( + YUVTORGB_SETUP(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "pcmpeqb %%xmm5,%%xmm5 \n" // all 1s + "movdqa %%xmm5,%%xmm7 \n" + "psrlw $6,%%xmm7 \n" + "psllw $4,%%xmm7 \n" // 1023 * 16 for max + "psllw $14,%%xmm5 \n" // 0xc000 for 2 alpha bits + "pxor %%xmm6,%%xmm6 \n" // 0 for min + + LABELALIGN + "1: \n" + READYUV410 + YUVTORGB16(yuvconstants) + STOREAR30 + "sub $0x8,%[width] \n" + "jg 1b \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_ar30]"+r"(dst_ar30), // %[dst_ar30] + [width]"+rm"(width) // %[width] + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" + ); +} + #ifdef HAS_I422ALPHATOARGBROW_SSSE3 void OMITFP I422AlphaToARGBRow_SSSE3(const uint8_t* y_buf, const uint8_t* u_buf, @@ -2320,33 +4825,61 @@ void OMITFP I422AlphaToARGBRow_SSSE3(const uint8_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - // clang-format off - asm volatile ( - YUVTORGB_SETUP(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - - LABELALIGN - "1: \n" - READYUVA422 - YUVTORGB(yuvconstants) - STOREARGB - "subl $0x8,%[width] \n" - "jg 1b \n" - : [y_buf]"+r"(y_buf), // %[y_buf] - [u_buf]"+r"(u_buf), // %[u_buf] - [v_buf]"+r"(v_buf), // %[v_buf] - [a_buf]"+r"(a_buf), // %[a_buf] - [dst_argb]"+r"(dst_argb), // %[dst_argb] #if defined(__i386__) - [width]"+m"(width) // %[width] + uintptr_t temp; + asm volatile( + "mov %[v_buf],%[temp] \n" + "sub %[u_buf],%[temp] \n" + "movd %[temp],%%xmm7 \n" + "movd %[a_buf],%%xmm6 \n" + + LABELALIGN + "1: \n" + "movd %%xmm7,%[temp] \n" + "movd (%[u_buf]),%%xmm3 \n" + "movd 0x00(%[u_buf],%[temp],1),%%xmm1 \n" + "lea 0x4(%[u_buf]),%[u_buf] \n" + "punpcklbw %%xmm1,%%xmm3 \n" + "punpcklwd %%xmm3,%%xmm3 \n" + "movq (%[y_buf]),%%xmm4 \n" + "punpcklbw %%xmm4,%%xmm4 \n" + "lea 0x8(%[y_buf]),%[y_buf] \n" + "movd %%xmm6,%[temp] \n" + "movq (%[temp]),%%xmm5 \n" + "lea 0x8(%[temp]),%[temp] \n" + "movd %[temp],%%xmm6 \n" + YUVTORGB(yuvconstants) + STOREARGB + "subl $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [dst_argb] "+r"(dst_argb), + [temp] "=&r"(temp), + [width] "+m"(width) + : [v_buf] "m"(v_buf), + [a_buf] "m"(a_buf), + [yuvconstants] "r"(yuvconstants) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); #else - [width]"+rm"(width) // %[width] + asm volatile(YUVTORGB_SETUP( + yuvconstants) "sub %[u_buf],%[v_buf] \n" + + LABELALIGN "1: \n" READYUVA422 YUVTORGB(yuvconstants) + STOREARGB + "subl $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [u_buf] "+r"(u_buf), // %[u_buf] + [v_buf] "+r"(v_buf), // %[v_buf] + [a_buf] "+r"(a_buf), // %[a_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5"); #endif - : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] - : "memory", "cc", YUVTORGB_REGS - "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" - ); - // clang-format on } #endif // HAS_I422ALPHATOARGBROW_SSSE3 @@ -2355,27 +4888,20 @@ void OMITFP NV12ToARGBRow_SSSE3(const uint8_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - // clang-format off - asm volatile ( - YUVTORGB_SETUP(yuvconstants) - "pcmpeqb %%xmm5,%%xmm5 \n" + asm volatile(YUVTORGB_SETUP( + yuvconstants) "pcmpeqb %%xmm5,%%xmm5 \n" - LABELALIGN - "1: \n" - READNV12 - YUVTORGB(yuvconstants) - STOREARGB - "sub $0x8,%[width] \n" - "jg 1b \n" - : [y_buf]"+r"(y_buf), // %[y_buf] - [uv_buf]"+r"(uv_buf), // %[uv_buf] - [dst_argb]"+r"(dst_argb), // %[dst_argb] - [width]"+rm"(width) // %[width] - : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] - : "memory", "cc", YUVTORGB_REGS - "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" - ); - // clang-format on + LABELALIGN "1: \n" READNV12 YUVTORGB(yuvconstants) + STOREARGB + "sub $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [uv_buf] "+r"(uv_buf), // %[uv_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5"); } void OMITFP NV21ToARGBRow_SSSE3(const uint8_t* y_buf, @@ -2383,84 +4909,167 @@ void OMITFP NV21ToARGBRow_SSSE3(const uint8_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - // clang-format off - asm volatile ( - YUVTORGB_SETUP(yuvconstants) - "pcmpeqb %%xmm5,%%xmm5 \n" + asm volatile(YUVTORGB_SETUP( + yuvconstants) "pcmpeqb %%xmm5,%%xmm5 \n" - LABELALIGN - "1: \n" - READNV21 - YUVTORGB(yuvconstants) - STOREARGB - "sub $0x8,%[width] \n" - "jg 1b \n" - : [y_buf]"+r"(y_buf), // %[y_buf] - [vu_buf]"+r"(vu_buf), // %[vu_buf] - [dst_argb]"+r"(dst_argb), // %[dst_argb] - [width]"+rm"(width) // %[width] - : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] - [kShuffleNV21]"m"(kShuffleNV21) - : "memory", "cc", YUVTORGB_REGS - "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" - ); - // clang-format on + LABELALIGN "1: \n" READNV21 YUVTORGB(yuvconstants) + STOREARGB + "sub $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [vu_buf] "+r"(vu_buf), // %[vu_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants), // %[yuvconstants] + [kShuffleNV21] "m"(kShuffleNV21) + : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5"); } void OMITFP YUY2ToARGBRow_SSSE3(const uint8_t* yuy2_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - // clang-format off - asm volatile ( - YUVTORGB_SETUP(yuvconstants) - "pcmpeqb %%xmm5,%%xmm5 \n" + asm volatile( + "movdqa %[kShuffleYUY2Y],%%xmm6 \n" + "movdqa %[kShuffleYUY2UV],%%xmm7 \n" YUVTORGB_SETUP( + yuvconstants) "pcmpeqb %%xmm5,%%xmm5 \n" - LABELALIGN - "1: \n" - READYUY2 - YUVTORGB(yuvconstants) - STOREARGB - "sub $0x8,%[width] \n" - "jg 1b \n" - : [yuy2_buf]"+r"(yuy2_buf), // %[yuy2_buf] - [dst_argb]"+r"(dst_argb), // %[dst_argb] - [width]"+rm"(width) // %[width] - : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] - [kShuffleYUY2Y]"m"(kShuffleYUY2Y), - [kShuffleYUY2UV]"m"(kShuffleYUY2UV) - : "memory", "cc", YUVTORGB_REGS - "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" - ); - // clang-format on + LABELALIGN "1: \n" READYUY2 YUVTORGB(yuvconstants) STOREARGB + "sub $0x8,%[width] \n" + "jg 1b \n" + : [yuy2_buf] "+r"(yuy2_buf), // %[yuy2_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants), // %[yuvconstants] + [kShuffleYUY2Y] "m"(kShuffleYUY2Y), [kShuffleYUY2UV] "m"(kShuffleYUY2UV) + : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", + "xmm5", "xmm6", "xmm7"); } void OMITFP UYVYToARGBRow_SSSE3(const uint8_t* uyvy_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - // clang-format off + asm volatile( + "movdqa %[kShuffleUYVYY],%%xmm6 \n" + "movdqa %[kShuffleUYVYUV],%%xmm7 \n" YUVTORGB_SETUP( + yuvconstants) "pcmpeqb %%xmm5,%%xmm5 \n" + + LABELALIGN "1: \n" READUYVY YUVTORGB(yuvconstants) STOREARGB + "sub $0x8,%[width] \n" + "jg 1b \n" + : [uyvy_buf] "+r"(uyvy_buf), // %[uyvy_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants), // %[yuvconstants] + [kShuffleUYVYY] "m"(kShuffleUYVYY), [kShuffleUYVYUV] "m"(kShuffleUYVYUV) + : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", + "xmm5", "xmm6", "xmm7"); +} + +void OMITFP P210ToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile(YUVTORGB_SETUP( + yuvconstants) "pcmpeqb %%xmm5,%%xmm5 \n" + + LABELALIGN "1: \n" READP210 YUVTORGB(yuvconstants) + STOREARGB + "sub $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [uv_buf] "+r"(uv_buf), // %[u_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5"); +} + +void OMITFP P410ToARGBRow_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile(YUVTORGB_SETUP( + yuvconstants) "pcmpeqb %%xmm5,%%xmm5 \n" + + LABELALIGN "1: \n" READP410 YUVTORGB(yuvconstants) + STOREARGB + "sub $0x8,%[width] \n" + "jg 1b \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [uv_buf] "+r"(uv_buf), // %[u_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5"); +} + +void OMITFP P210ToAR30Row_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { asm volatile ( YUVTORGB_SETUP(yuvconstants) - "pcmpeqb %%xmm5,%%xmm5 \n" + "pcmpeqb %%xmm5,%%xmm5 \n" // all 1s + "movdqa %%xmm5,%%xmm7 \n" + "psrlw $6,%%xmm7 \n" + "psllw $4,%%xmm7 \n" // 1023 * 16 for max + "psllw $14,%%xmm5 \n" // 0xc000 for 2 alpha bits + "pxor %%xmm6,%%xmm6 \n" // 0 for min LABELALIGN - "1: \n" - READUYVY - YUVTORGB(yuvconstants) - STOREARGB - "sub $0x8,%[width] \n" - "jg 1b \n" - : [uyvy_buf]"+r"(uyvy_buf), // %[uyvy_buf] - [dst_argb]"+r"(dst_argb), // %[dst_argb] - [width]"+rm"(width) // %[width] - : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] - [kShuffleUYVYY]"m"(kShuffleUYVYY), - [kShuffleUYVYUV]"m"(kShuffleUYVYUV) - : "memory", "cc", YUVTORGB_REGS - "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" + "1: \n" + READP210 + YUVTORGB16(yuvconstants) + STOREAR30 + "sub $0x8,%[width] \n" + "jg 1b \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [uv_buf]"+r"(uv_buf), // %[uv_buf] + [dst_ar30]"+r"(dst_ar30), // %[dst_ar30] + [width]"+rm"(width) // %[width] + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" + ); +} + +void OMITFP P410ToAR30Row_SSSE3(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile ( + YUVTORGB_SETUP(yuvconstants) + "pcmpeqb %%xmm5,%%xmm5 \n" // all 1s + "movdqa %%xmm5,%%xmm7 \n" + "psrlw $6,%%xmm7 \n" + "psllw $4,%%xmm7 \n" // 1023 * 16 for max + "psllw $14,%%xmm5 \n" // 0xc000 for 2 alpha bits + "pxor %%xmm6,%%xmm6 \n" // 0 for min + + LABELALIGN + "1: \n" + READP410 + YUVTORGB16(yuvconstants) + STOREAR30 + "sub $0x8,%[width] \n" + "jg 1b \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [uv_buf]"+r"(uv_buf), // %[uv_buf] + [dst_ar30]"+r"(dst_ar30), // %[dst_ar30] + [width]"+rm"(width) // %[width] + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" ); - // clang-format on } void OMITFP I422ToRGBARow_SSSE3(const uint8_t* y_buf, @@ -2471,16 +5080,16 @@ void OMITFP I422ToRGBARow_SSSE3(const uint8_t* y_buf, int width) { asm volatile ( YUVTORGB_SETUP(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "pcmpeqb %%xmm5,%%xmm5 \n" + "sub %[u_buf],%[v_buf] \n" + "pcmpeqb %%xmm5,%%xmm5 \n" LABELALIGN - "1: \n" + "1: \n" READYUV422 YUVTORGB(yuvconstants) STORERGBA - "sub $0x8,%[width] \n" - "jg 1b \n" + "sub $0x8,%[width] \n" + "jg 1b \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] @@ -2492,16 +5101,16 @@ void OMITFP I422ToRGBARow_SSSE3(const uint8_t* y_buf, ); } -#endif // HAS_I422TOARGBROW_SSSE3 +#endif // defined(HAS_I422TOARGBROW_SSSE3) || defined(HAS_I422TOARGBROW_AVX2) // Read 16 UV from 444 #define READYUV444_AVX2 \ - "vmovdqu (%[u_buf]),%%xmm0 \n" \ + "vmovdqu (%[u_buf]),%%xmm3 \n" \ "vmovdqu 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ "lea 0x10(%[u_buf]),%[u_buf] \n" \ - "vpermq $0xd8,%%ymm0,%%ymm0 \n" \ + "vpermq $0xd8,%%ymm3,%%ymm3 \n" \ "vpermq $0xd8,%%ymm1,%%ymm1 \n" \ - "vpunpcklbw %%ymm1,%%ymm0,%%ymm0 \n" \ + "vpunpcklbw %%ymm1,%%ymm3,%%ymm3 \n" \ "vmovdqu (%[y_buf]),%%xmm4 \n" \ "vpermq $0xd8,%%ymm4,%%ymm4 \n" \ "vpunpcklbw %%ymm4,%%ymm4,%%ymm4 \n" \ @@ -2509,42 +5118,170 @@ void OMITFP I422ToRGBARow_SSSE3(const uint8_t* y_buf, // Read 8 UV from 422, upsample to 16 UV. #define READYUV422_AVX2 \ - "vmovq (%[u_buf]),%%xmm0 \n" \ + "vmovq (%[u_buf]),%%xmm3 \n" \ "vmovq 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ "lea 0x8(%[u_buf]),%[u_buf] \n" \ - "vpunpcklbw %%ymm1,%%ymm0,%%ymm0 \n" \ - "vpermq $0xd8,%%ymm0,%%ymm0 \n" \ - "vpunpcklwd %%ymm0,%%ymm0,%%ymm0 \n" \ + "vpunpcklbw %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpermq $0xd8,%%ymm3,%%ymm3 \n" \ + "vpunpcklwd %%ymm3,%%ymm3,%%ymm3 \n" \ "vmovdqu (%[y_buf]),%%xmm4 \n" \ "vpermq $0xd8,%%ymm4,%%ymm4 \n" \ "vpunpcklbw %%ymm4,%%ymm4,%%ymm4 \n" \ "lea 0x10(%[y_buf]),%[y_buf] \n" -// Read 8 UV from 210 10 bit, upsample to 16 UV -// TODO(fbarchard): Consider vshufb to replace pack/unpack +#define READYUV422_AVX512BW \ + "vmovdqu (%[u_buf]),%%xmm3 \n" \ + "vmovdqu 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ + "lea 0x10(%[u_buf]),%[u_buf] \n" \ + "vpunpcklbw %%xmm1,%%xmm3,%%xmm2 \n" \ + "vpunpckhbw %%xmm1,%%xmm3,%%xmm3 \n" \ + "vinserti64x2 $1,%%xmm3,%%ymm2,%%ymm3 \n" \ + "vmovdqa64 %%zmm16,%%zmm1 \n" \ + "vpermi2w %%zmm3,%%zmm3,%%zmm1 \n" \ + "vpmovzxbw (%[y_buf]),%%zmm4 \n" \ + "lea 0x20(%[y_buf]),%[y_buf] \n" \ + "vpsllw $8,%%zmm4,%%zmm3 \n" \ + "vpord %%zmm3,%%zmm4,%%zmm4 \n" \ + "vmovdqa64 %%zmm1,%%zmm3 \n" + +#define READYUV422_MASK_AVX512BW \ + "mov $-1,%[temp] \n" \ + "bzhi %q[width],%[temp],%[temp] \n" \ + "kmovd %k[temp],%%k1 \n" \ + "vpmovzxbw (%[y_buf]),%%zmm4%{%%k1%}%{z%} \n" \ + "mov $-1,%[temp] \n" \ + "lea 1(%q[width]),%k[y_buf] \n" \ + "shr $1,%k[y_buf] \n" \ + "bzhi %q[y_buf],%[temp],%[y_buf] \n" \ + "kmovw %k[y_buf],%%k2 \n" \ + "vmovdqu8 (%[u_buf]),%%xmm3%{%%k2%}%{z%} \n" \ + "vmovdqu8 0x00(%[u_buf],%[v_buf],1),%%xmm1%{%%k2%}%{z%} \n" \ + "vpunpcklbw %%xmm1,%%xmm3,%%xmm2 \n" \ + "vpunpckhbw %%xmm1,%%xmm3,%%xmm3 \n" \ + "vinserti64x2 $1,%%xmm3,%%ymm2,%%ymm3 \n" \ + "vmovdqa64 %%zmm16,%%zmm1 \n" \ + "vpermi2w %%zmm3,%%zmm3,%%zmm1 \n" \ + "vpsllw $8,%%zmm4,%%zmm3 \n" \ + "vpord %%zmm3,%%zmm4,%%zmm4 \n" \ + "vmovdqa64 %%zmm1,%%zmm3 \n" + +// Read 8 UV from 210, upsample to 16 UV +// TODO(fbarchard): Consider vpshufb to replace pack/unpack // TODO(fbarchard): Consider vunpcklpd to combine the 2 registers into 1. #define READYUV210_AVX2 \ - "vmovdqu (%[u_buf]),%%xmm0 \n" \ + "vmovdqu (%[u_buf]),%%xmm3 \n" \ "vmovdqu 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ "lea 0x10(%[u_buf]),%[u_buf] \n" \ - "vpermq $0xd8,%%ymm0,%%ymm0 \n" \ + "vpermq $0xd8,%%ymm3,%%ymm3 \n" \ "vpermq $0xd8,%%ymm1,%%ymm1 \n" \ - "vpunpcklwd %%ymm1,%%ymm0,%%ymm0 \n" \ - "vpsraw $0x2,%%ymm0,%%ymm0 \n" \ - "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" \ - "vpunpcklwd %%ymm0,%%ymm0,%%ymm0 \n" \ + "vpunpcklwd %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpsrlw $2,%%ymm3,%%ymm3 \n" \ + "vpackuswb %%ymm3,%%ymm3,%%ymm3 \n" \ + "vpunpcklwd %%ymm3,%%ymm3,%%ymm3 \n" \ "vmovdqu (%[y_buf]),%%ymm4 \n" \ - "vpsllw $0x6,%%ymm4,%%ymm4 \n" \ + "vpsllw $6,%%ymm4,%%ymm2 \n" \ + "vpsrlw $4,%%ymm4,%%ymm4 \n" \ + "vpor %%ymm2,%%ymm4,%%ymm4 \n" \ "lea 0x20(%[y_buf]),%[y_buf] \n" +// Read 8 UV from 210, upsample to 16 UV. With 16 Alpha. +#define READYUVA210_AVX2 \ + "vmovdqu (%[u_buf]),%%xmm3 \n" \ + "vmovdqu 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ + "lea 0x10(%[u_buf]),%[u_buf] \n" \ + "vpermq $0xd8,%%ymm3,%%ymm3 \n" \ + "vpermq $0xd8,%%ymm1,%%ymm1 \n" \ + "vpunpcklwd %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpsrlw $2,%%ymm3,%%ymm3 \n" \ + "vpackuswb %%ymm3,%%ymm3,%%ymm3 \n" \ + "vpunpcklwd %%ymm3,%%ymm3,%%ymm3 \n" \ + "vmovdqu (%[y_buf]),%%ymm4 \n" \ + "vpsllw $6,%%ymm4,%%ymm2 \n" \ + "vpsrlw $4,%%ymm4,%%ymm4 \n" \ + "vpor %%ymm2,%%ymm4,%%ymm4 \n" \ + "lea 0x20(%[y_buf]),%[y_buf] \n" \ + "vmovdqu (%[a_buf]),%%ymm5 \n" \ + "vpsrlw $2,%%ymm5,%%ymm5 \n" \ + "vpackuswb %%ymm5,%%ymm5,%%ymm5 \n" \ + "lea 0x20(%[a_buf]),%[a_buf] \n" + +// Read 16 UV from 410 +#define READYUV410_AVX2 \ + "vmovdqu (%[u_buf]),%%ymm3 \n" \ + "vmovdqu 0x00(%[u_buf],%[v_buf],1),%%ymm2 \n" \ + "lea 0x20(%[u_buf]),%[u_buf] \n" \ + "vpsrlw $2,%%ymm3,%%ymm3 \n" \ + "vpsrlw $2,%%ymm2,%%ymm2 \n" \ + "vpunpckhwd %%ymm2,%%ymm3,%%ymm1 \n" \ + "vpunpcklwd %%ymm2,%%ymm3,%%ymm3 \n" \ + "vpackuswb %%ymm1,%%ymm3,%%ymm3 \n" \ + "vmovdqu (%[y_buf]),%%ymm4 \n" \ + "vpsllw $6,%%ymm4,%%ymm2 \n" \ + "vpsrlw $4,%%ymm4,%%ymm4 \n" \ + "vpor %%ymm2,%%ymm4,%%ymm4 \n" \ + "lea 0x20(%[y_buf]),%[y_buf] \n" + +// Read 8 UV from 212 12 bit, upsample to 16 UV +#define READYUV212_AVX2 \ + "vmovdqu (%[u_buf]),%%xmm3 \n" \ + "vmovdqu 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ + "lea 0x10(%[u_buf]),%[u_buf] \n" \ + "vpermq $0xd8,%%ymm3,%%ymm3 \n" \ + "vpermq $0xd8,%%ymm1,%%ymm1 \n" \ + "vpunpcklwd %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpsrlw $0x4,%%ymm3,%%ymm3 \n" \ + "vpackuswb %%ymm3,%%ymm3,%%ymm3 \n" \ + "vpunpcklwd %%ymm3,%%ymm3,%%ymm3 \n" \ + "vmovdqu (%[y_buf]),%%ymm4 \n" \ + "vpsllw $4,%%ymm4,%%ymm2 \n" \ + "vpsrlw $8,%%ymm4,%%ymm4 \n" \ + "vpor %%ymm2,%%ymm4,%%ymm4 \n" \ + "lea 0x20(%[y_buf]),%[y_buf] \n" + +// Read 16 UV from 410. With 16 Alpha. +#define READYUVA410_AVX2 \ + "vmovdqu (%[u_buf]),%%ymm3 \n" \ + "vmovdqu 0x00(%[u_buf],%[v_buf],1),%%ymm2 \n" \ + "lea 0x20(%[u_buf]),%[u_buf] \n" \ + "vpsrlw $2,%%ymm3,%%ymm3 \n" \ + "vpsrlw $2,%%ymm2,%%ymm2 \n" \ + "vpunpckhwd %%ymm2,%%ymm3,%%ymm1 \n" \ + "vpunpcklwd %%ymm2,%%ymm3,%%ymm3 \n" \ + "vpackuswb %%ymm1,%%ymm3,%%ymm3 \n" \ + "vmovdqu (%[y_buf]),%%ymm4 \n" \ + "vpsllw $6,%%ymm4,%%ymm2 \n" \ + "vpsrlw $4,%%ymm4,%%ymm4 \n" \ + "vpor %%ymm2,%%ymm4,%%ymm4 \n" \ + "lea 0x20(%[y_buf]),%[y_buf] \n" \ + "vmovdqu (%[a_buf]),%%ymm5 \n" \ + "vpsrlw $2,%%ymm5,%%ymm5 \n" \ + "vpackuswb %%ymm5,%%ymm5,%%ymm5 \n" \ + "lea 0x20(%[a_buf]),%[a_buf] \n" + +// Read 16 UV from 444. With 16 Alpha. +#define READYUVA444_AVX2 \ + "vmovdqu (%[u_buf]),%%xmm3 \n" \ + "vmovdqu 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ + "lea 0x10(%[u_buf]),%[u_buf] \n" \ + "vpermq $0xd8,%%ymm3,%%ymm3 \n" \ + "vpermq $0xd8,%%ymm1,%%ymm1 \n" \ + "vpunpcklbw %%ymm1,%%ymm3,%%ymm3 \n" \ + "vmovdqu (%[y_buf]),%%xmm4 \n" \ + "vpermq $0xd8,%%ymm4,%%ymm4 \n" \ + "vpunpcklbw %%ymm4,%%ymm4,%%ymm4 \n" \ + "lea 0x10(%[y_buf]),%[y_buf] \n" \ + "vmovdqu (%[a_buf]),%%xmm5 \n" \ + "vpermq $0xd8,%%ymm5,%%ymm5 \n" \ + "lea 0x10(%[a_buf]),%[a_buf] \n" + // Read 8 UV from 422, upsample to 16 UV. With 16 Alpha. #define READYUVA422_AVX2 \ - "vmovq (%[u_buf]),%%xmm0 \n" \ + "vmovq (%[u_buf]),%%xmm3 \n" \ "vmovq 0x00(%[u_buf],%[v_buf],1),%%xmm1 \n" \ "lea 0x8(%[u_buf]),%[u_buf] \n" \ - "vpunpcklbw %%ymm1,%%ymm0,%%ymm0 \n" \ - "vpermq $0xd8,%%ymm0,%%ymm0 \n" \ - "vpunpcklwd %%ymm0,%%ymm0,%%ymm0 \n" \ + "vpunpcklbw %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpermq $0xd8,%%ymm3,%%ymm3 \n" \ + "vpunpcklwd %%ymm3,%%ymm3,%%ymm3 \n" \ "vmovdqu (%[y_buf]),%%xmm4 \n" \ "vpermq $0xd8,%%ymm4,%%ymm4 \n" \ "vpunpcklbw %%ymm4,%%ymm4,%%ymm4 \n" \ @@ -2555,10 +5292,10 @@ void OMITFP I422ToRGBARow_SSSE3(const uint8_t* y_buf, // Read 8 UV from NV12, upsample to 16 UV. #define READNV12_AVX2 \ - "vmovdqu (%[uv_buf]),%%xmm0 \n" \ + "vmovdqu (%[uv_buf]),%%xmm3 \n" \ "lea 0x10(%[uv_buf]),%[uv_buf] \n" \ - "vpermq $0xd8,%%ymm0,%%ymm0 \n" \ - "vpunpcklwd %%ymm0,%%ymm0,%%ymm0 \n" \ + "vpermq $0xd8,%%ymm3,%%ymm3 \n" \ + "vpunpcklwd %%ymm3,%%ymm3,%%ymm3 \n" \ "vmovdqu (%[y_buf]),%%xmm4 \n" \ "vpermq $0xd8,%%ymm4,%%ymm4 \n" \ "vpunpcklbw %%ymm4,%%ymm4,%%ymm4 \n" \ @@ -2566,75 +5303,167 @@ void OMITFP I422ToRGBARow_SSSE3(const uint8_t* y_buf, // Read 8 VU from NV21, upsample to 16 UV. #define READNV21_AVX2 \ - "vmovdqu (%[vu_buf]),%%xmm0 \n" \ + "vmovdqu (%[vu_buf]),%%xmm3 \n" \ "lea 0x10(%[vu_buf]),%[vu_buf] \n" \ - "vpermq $0xd8,%%ymm0,%%ymm0 \n" \ - "vpshufb %[kShuffleNV21], %%ymm0, %%ymm0 \n" \ + "vpermq $0xd8,%%ymm3,%%ymm3 \n" \ + "vpshufb %[kShuffleNV21], %%ymm3, %%ymm3 \n" \ "vmovdqu (%[y_buf]),%%xmm4 \n" \ "vpermq $0xd8,%%ymm4,%%ymm4 \n" \ "vpunpcklbw %%ymm4,%%ymm4,%%ymm4 \n" \ "lea 0x10(%[y_buf]),%[y_buf] \n" +// Read 4 UV from P210, upsample to 8 UV +#define READP210_AVX2 \ + "vmovdqu (%[uv_buf]),%%ymm3 \n" \ + "lea 0x20(%[uv_buf]),%[uv_buf] \n" \ + "vpsrlw $0x8,%%ymm3,%%ymm3 \n" \ + "vpackuswb %%ymm3,%%ymm3,%%ymm3 \n" \ + "vpunpcklwd %%ymm3,%%ymm3,%%ymm3 \n" \ + "vmovdqu (%[y_buf]),%%ymm4 \n" \ + "lea 0x20(%[y_buf]),%[y_buf] \n" + +// Read 8 UV from P410 +#define READP410_AVX2 \ + "vmovdqu (%[uv_buf]),%%ymm3 \n" \ + "vmovdqu 0x20(%[uv_buf]),%%ymm1 \n" \ + "lea 0x40(%[uv_buf]),%[uv_buf] \n" \ + "vpsrlw $0x8,%%ymm3,%%ymm3 \n" \ + "vpsrlw $0x8,%%ymm1,%%ymm1 \n" \ + "vpackuswb %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpermq $0xd8,%%ymm3,%%ymm3 \n" \ + "vmovdqu (%[y_buf]),%%ymm4 \n" \ + "lea 0x20(%[y_buf]),%[y_buf] \n" + // Read 8 YUY2 with 16 Y and upsample 8 UV to 16 UV. +// ymm6 kShuffleYUY2Y, +// ymm7 kShuffleYUY2UV #define READYUY2_AVX2 \ - "vmovdqu (%[yuy2_buf]),%%ymm4 \n" \ - "vpshufb %[kShuffleYUY2Y], %%ymm4, %%ymm4 \n" \ - "vmovdqu (%[yuy2_buf]),%%ymm0 \n" \ - "vpshufb %[kShuffleYUY2UV], %%ymm0, %%ymm0 \n" \ + "vmovdqu (%[yuy2_buf]),%%ymm1 \n" \ + "vpshufb %%ymm6,%%ymm1,%%ymm4 \n" \ + "vpshufb %%ymm7,%%ymm1,%%ymm3 \n" \ "lea 0x20(%[yuy2_buf]),%[yuy2_buf] \n" // Read 8 UYVY with 16 Y and upsample 8 UV to 16 UV. +// ymm6 kShuffleUYVYY, +// ymm7 kShuffleUYVYUV #define READUYVY_AVX2 \ - "vmovdqu (%[uyvy_buf]),%%ymm4 \n" \ - "vpshufb %[kShuffleUYVYY], %%ymm4, %%ymm4 \n" \ - "vmovdqu (%[uyvy_buf]),%%ymm0 \n" \ - "vpshufb %[kShuffleUYVYUV], %%ymm0, %%ymm0 \n" \ + "vmovdqu (%[uyvy_buf]),%%ymm1 \n" \ + "vpshufb %%ymm6,%%ymm1,%%ymm4 \n" \ + "vpshufb %%ymm7,%%ymm1,%%ymm3 \n" \ "lea 0x20(%[uyvy_buf]),%[uyvy_buf] \n" #if defined(__x86_64__) -#define YUVTORGB_SETUP_AVX2(yuvconstants) \ - "vmovdqa (%[yuvconstants]),%%ymm8 \n" \ - "vmovdqa 32(%[yuvconstants]),%%ymm9 \n" \ - "vmovdqa 64(%[yuvconstants]),%%ymm10 \n" \ - "vmovdqa 96(%[yuvconstants]),%%ymm11 \n" \ - "vmovdqa 128(%[yuvconstants]),%%ymm12 \n" \ - "vmovdqa 160(%[yuvconstants]),%%ymm13 \n" \ - "vmovdqa 192(%[yuvconstants]),%%ymm14 \n" +#define YUVTORGB_SETUP_AVX2(yuvconstants) \ + "vpcmpeqb %%ymm13,%%ymm13,%%ymm13 \n" \ + "vmovdqu (%[yuvconstants]),%%ymm8 \n" \ + "vpabsb %%ymm13,%%ymm13 \n" \ + "vmovdqu 32(%[yuvconstants]),%%ymm9 \n" \ + "vpsllw $7,%%ymm13,%%ymm13 \n" \ + "vmovdqu 64(%[yuvconstants]),%%ymm10 \n" \ + "vmovdqu 96(%[yuvconstants]),%%ymm11 \n" \ + "vmovdqu 128(%[yuvconstants]),%%ymm12 \n" + +#define YUVTORGB_SETUP_AVX512BW(yuvconstants) \ + "vpternlogd $0xff,%%zmm13,%%zmm13,%%zmm13 \n" \ + "vpbroadcastq (%[yuvconstants]),%%zmm8 \n" \ + "vpabsb %%zmm13,%%zmm13 \n" \ + "vpsllw $7,%%zmm13,%%zmm13 \n" \ + "vpbroadcastq 32(%[yuvconstants]),%%zmm9 \n" \ + "vpbroadcastq 64(%[yuvconstants]),%%zmm10 \n" \ + "vpbroadcastq 96(%[yuvconstants]),%%zmm11 \n" \ + "vpbroadcastq 128(%[yuvconstants]),%%zmm12 \n" \ + "vmovups (%[quadsplitperm]),%%zmm16 \n" \ + "vmovups (%[unperm]),%%zmm18 \n" + +#define YUVTORGB_SETUP_AR30_AVX2(yuvconstants) \ + YUVTORGB_SETUP_AVX2(yuvconstants) \ + "vpcmpeqb %%ymm0,%%ymm0,%%ymm0 \n" \ + "vpsrlw $14,%%ymm0,%%ymm0 \n" \ + "vpsllw $3,%%ymm0,%%ymm0 \n" \ + "vpsubw %%ymm0,%%ymm12,%%ymm12 \n" + +#define YUVTORGB_SETUP_AR30_AVX512BW(yuvconstants) \ + YUVTORGB_SETUP_AVX512BW(yuvconstants) \ + "vpternlogd $0xff,%%zmm0,%%zmm0,%%zmm0 \n" \ + "vpsrlw $14,%%zmm0,%%zmm0 \n" \ + "vpsllw $3,%%zmm0,%%zmm0 \n" \ + "vpsubw %%zmm0,%%zmm12,%%zmm12 \n" #define YUVTORGB16_AVX2(yuvconstants) \ - "vpmaddubsw %%ymm10,%%ymm0,%%ymm2 \n" \ - "vpmaddubsw %%ymm9,%%ymm0,%%ymm1 \n" \ - "vpmaddubsw %%ymm8,%%ymm0,%%ymm0 \n" \ - "vpsubw %%ymm2,%%ymm13,%%ymm2 \n" \ - "vpsubw %%ymm1,%%ymm12,%%ymm1 \n" \ - "vpsubw %%ymm0,%%ymm11,%%ymm0 \n" \ - "vpmulhuw %%ymm14,%%ymm4,%%ymm4 \n" \ + "vpsubb %%ymm13,%%ymm3,%%ymm3 \n" \ + "vpmulhuw %%ymm11,%%ymm4,%%ymm4 \n" \ + "vpmaddubsw %%ymm3,%%ymm8,%%ymm0 \n" \ + "vpmaddubsw %%ymm3,%%ymm9,%%ymm1 \n" \ + "vpmaddubsw %%ymm3,%%ymm10,%%ymm2 \n" \ + "vpaddw %%ymm4,%%ymm12,%%ymm4 \n" \ "vpaddsw %%ymm4,%%ymm0,%%ymm0 \n" \ - "vpaddsw %%ymm4,%%ymm1,%%ymm1 \n" \ + "vpsubsw %%ymm1,%%ymm4,%%ymm1 \n" \ "vpaddsw %%ymm4,%%ymm2,%%ymm2 \n" -#define YUVTORGB_REGS_AVX2 \ - "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", +#define YUVTORGB16_AR30_AVX2(yuvconstants) YUVTORGB16_AVX2(yuvconstants) + +#define YUVTORGB16_AVX512BW(yuvconstants) \ + "vpsubb %%zmm13,%%zmm3,%%zmm3 \n" \ + "vpmulhuw %%zmm11,%%zmm4,%%zmm4 \n" \ + "vpmaddubsw %%zmm3,%%zmm8,%%zmm0 \n" \ + "vpmaddubsw %%zmm3,%%zmm9,%%zmm1 \n" \ + "vpmaddubsw %%zmm3,%%zmm10,%%zmm2 \n" \ + "vpaddw %%zmm4,%%zmm12,%%zmm4 \n" \ + "vpaddsw %%zmm4,%%zmm0,%%zmm0 \n" \ + "vpsubsw %%zmm1,%%zmm4,%%zmm1 \n" \ + "vpaddsw %%zmm4,%%zmm2,%%zmm2 \n" + +#define YUVTORGB_REGS_AVX2 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", +#define YUVTORGB_REGS_AVX512BW \ + "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm16", "xmm18", #else // Convert 16 pixels: 16 UV and 16 Y. #define YUVTORGB_SETUP_AVX2(yuvconstants) +#define YUVTORGB_SETUP_AR30_AVX2(yuvconstants) +#define YUVTORGB_SETUP_AR30_AVX512BW(yuvconstants) #define YUVTORGB16_AVX2(yuvconstants) \ - "vpmaddubsw 64(%[yuvconstants]),%%ymm0,%%ymm2 \n" \ - "vpmaddubsw 32(%[yuvconstants]),%%ymm0,%%ymm1 \n" \ - "vpmaddubsw (%[yuvconstants]),%%ymm0,%%ymm0 \n" \ - "vmovdqu 160(%[yuvconstants]),%%ymm3 \n" \ - "vpsubw %%ymm2,%%ymm3,%%ymm2 \n" \ + "vpcmpeqb %%ymm0,%%ymm0,%%ymm0 \n" \ + "vpabsb %%ymm0,%%ymm0 \n" \ + "vpsllw $7,%%ymm0,%%ymm0 \n" \ + "vpsubb %%ymm0,%%ymm3,%%ymm3 \n" \ + "vpmulhuw 96(%[yuvconstants]),%%ymm4,%%ymm4 \n" \ + "vmovdqu (%[yuvconstants]),%%ymm0 \n" \ + "vmovdqu 32(%[yuvconstants]),%%ymm1 \n" \ + "vmovdqu 64(%[yuvconstants]),%%ymm2 \n" \ + "vpmaddubsw %%ymm3,%%ymm0,%%ymm0 \n" \ + "vpmaddubsw %%ymm3,%%ymm1,%%ymm1 \n" \ + "vpmaddubsw %%ymm3,%%ymm2,%%ymm2 \n" \ "vmovdqu 128(%[yuvconstants]),%%ymm3 \n" \ - "vpsubw %%ymm1,%%ymm3,%%ymm1 \n" \ - "vmovdqu 96(%[yuvconstants]),%%ymm3 \n" \ - "vpsubw %%ymm0,%%ymm3,%%ymm0 \n" \ - "vpmulhuw 192(%[yuvconstants]),%%ymm4,%%ymm4 \n" \ + "vpaddw %%ymm4,%%ymm3,%%ymm4 \n" \ "vpaddsw %%ymm4,%%ymm0,%%ymm0 \n" \ - "vpaddsw %%ymm4,%%ymm1,%%ymm1 \n" \ + "vpsubsw %%ymm1,%%ymm4,%%ymm1 \n" \ "vpaddsw %%ymm4,%%ymm2,%%ymm2 \n" + +#define YUVTORGB16_AR30_AVX2(yuvconstants) \ + "vpcmpeqb %%ymm0,%%ymm0,%%ymm0 \n" \ + "vpabsb %%ymm0,%%ymm0 \n" \ + "vpsllw $7,%%ymm0,%%ymm0 \n" \ + "vpsubb %%ymm0,%%ymm3,%%ymm3 \n" \ + "vpmulhuw 96(%[yuvconstants]),%%ymm4,%%ymm4 \n" \ + "vmovdqu (%[yuvconstants]),%%ymm0 \n" \ + "vmovdqu 32(%[yuvconstants]),%%ymm1 \n" \ + "vmovdqu 64(%[yuvconstants]),%%ymm2 \n" \ + "vpmaddubsw %%ymm3,%%ymm0,%%ymm0 \n" \ + "vpmaddubsw %%ymm3,%%ymm1,%%ymm1 \n" \ + "vpmaddubsw %%ymm3,%%ymm2,%%ymm2 \n" \ + "vmovdqu 128(%[yuvconstants]),%%ymm3 \n" \ + "vpaddw %%ymm4,%%ymm3,%%ymm4 \n" \ + "vpcmpeqb %%ymm3,%%ymm3,%%ymm3 \n" \ + "vpsrlw $14,%%ymm3,%%ymm3 \n" \ + "vpsllw $3,%%ymm3,%%ymm3 \n" \ + "vpsubw %%ymm3,%%ymm4,%%ymm4 \n" \ + "vpaddsw %%ymm4,%%ymm0,%%ymm0 \n" \ + "vpsubsw %%ymm1,%%ymm4,%%ymm1 \n" \ + "vpaddsw %%ymm4,%%ymm2,%%ymm2 \n" + #define YUVTORGB_REGS_AVX2 -#endif +#endif // defined(__x86_64__) #define YUVTORGB_AVX2(yuvconstants) \ YUVTORGB16_AVX2(yuvconstants) \ @@ -2645,6 +5474,15 @@ void OMITFP I422ToRGBARow_SSSE3(const uint8_t* y_buf, "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" \ "vpackuswb %%ymm2,%%ymm2,%%ymm2 \n" +#define YUVTORGB_AVX512BW(yuvconstants) \ + YUVTORGB16_AVX512BW(yuvconstants) \ + "vpsraw $0x6,%%zmm0,%%zmm0 \n" \ + "vpsraw $0x6,%%zmm1,%%zmm1 \n" \ + "vpsraw $0x6,%%zmm2,%%zmm2 \n" \ + "vpackuswb %%zmm0,%%zmm0,%%zmm0 \n" \ + "vpackuswb %%zmm1,%%zmm1,%%zmm1 \n" \ + "vpackuswb %%zmm2,%%zmm2,%%zmm2 \n" + // Store 16 ARGB values. #define STOREARGB_AVX2 \ "vpunpcklbw %%ymm1,%%ymm0,%%ymm0 \n" \ @@ -2655,34 +5493,186 @@ void OMITFP I422ToRGBARow_SSSE3(const uint8_t* y_buf, "vpunpckhwd %%ymm2,%%ymm0,%%ymm0 \n" \ "vmovdqu %%ymm1,(%[dst_argb]) \n" \ "vmovdqu %%ymm0,0x20(%[dst_argb]) \n" \ - "lea 0x40(%[dst_argb]), %[dst_argb] \n" + "lea 0x40(%[dst_argb]), %[dst_argb] \n" + +// Store 32 ARGB values. +#define STOREARGB_AVX512BW \ + "vpunpcklbw %%zmm1,%%zmm0,%%zmm0 \n" \ + "vpermq %%zmm0,%%zmm18,%%zmm0 \n" \ + "vpunpcklbw %%zmm5,%%zmm2,%%zmm2 \n" \ + "vpermq %%zmm2,%%zmm18,%%zmm2 \n" \ + "vpunpcklwd %%zmm2,%%zmm0,%%zmm1 \n" \ + "vpunpckhwd %%zmm2,%%zmm0,%%zmm0 \n" \ + "vmovups %%zmm1,(%[dst_argb]) \n" \ + "vmovups %%zmm0,0x40(%[dst_argb]) \n" \ + "lea 0x80(%[dst_argb]), %[dst_argb] \n" + +// Store masked ARGB values with AVX512BW. +#define STOREARGB_MASK_AVX512BW \ + "vpunpcklbw %%zmm1,%%zmm0,%%zmm0 \n" \ + "vpermq %%zmm0,%%zmm18,%%zmm0 \n" \ + "vpunpcklbw %%zmm5,%%zmm2,%%zmm2 \n" \ + "vpermq %%zmm2,%%zmm18,%%zmm2 \n" \ + "vpunpcklwd %%zmm2,%%zmm0,%%zmm1 \n" \ + "vpunpckhwd %%zmm2,%%zmm0,%%zmm0 \n" \ + "kshiftrd $16,%%k1,%%k2 \n" \ + "vmovdqu32 %%zmm1,(%[dst_argb])%{%%k1%} \n" \ + "vmovdqu32 %%zmm0,0x40(%[dst_argb])%{%%k2%} \n" + +// Store 16 RGB24 values. +#define STORERGB24_AVX2 \ + "vpunpcklbw %%ymm1,%%ymm0,%%ymm0 \n" \ + "vpunpcklbw %%ymm2,%%ymm2,%%ymm2 \n" \ + "vmovdqa %%ymm0,%%ymm1 \n" \ + "vpunpcklwd %%ymm2,%%ymm0,%%ymm0 \n" \ + "vpunpckhwd %%ymm2,%%ymm1,%%ymm1 \n" \ + "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" \ + "vpshufb %%ymm6,%%ymm1,%%ymm1 \n" \ + "vpalignr $0xc,%%ymm0,%%ymm1,%%ymm1 \n" \ + "vextracti128 $1,%%ymm0,%%xmm2 \n" \ + "vextracti128 $1,%%ymm1,%%xmm3 \n" \ + "vpunpcklqdq %%xmm1,%%xmm0,%%xmm0 \n" \ + "vpalignr $8,%%xmm1,%%xmm2,%%xmm2 \n" \ + "vmovdqu %%xmm0,(%[dst_rgb24]) \n" \ + "vmovdqu %%xmm2,0x10(%[dst_rgb24]) \n" \ + "vmovdqu %%xmm3,0x20(%[dst_rgb24]) \n" \ + "lea 0x30(%[dst_rgb24]),%[dst_rgb24] \n" + +// Store 32 RGB24 values with VBMI. +#define STORERGB24_AVX512VBMI \ + "vpermt2b %%zmm1,%%zmm20,%%zmm0 \n" \ + "vmovdqa64 %%zmm0,%%zmm3 \n" \ + "vpermt2b %%zmm2,%%zmm21,%%zmm3 \n" \ + "vpermt2b %%zmm2,%%zmm22,%%zmm0 \n" \ + "vmovdqu8 %%zmm3,(%[dst_rgb24]) \n" \ + "vmovdqu8 %%ymm0,0x40(%[dst_rgb24]) \n" \ + "lea 0x60(%[dst_rgb24]),%[dst_rgb24] \n" + +// Store masked RGB24 values with VBMI. +#define STORERGB24_MASK_AVX512VBMI \ + "lea (%q[width],%q[width],2),%k[width] \n" \ + "bzhi %q[width],%[temp],%[y_buf] \n" \ + "kmovq %[y_buf],%%k3 \n" \ + "xor %k[y_buf],%k[y_buf] \n" \ + "sub $0x40,%k[width] \n" \ + "cmovg %[temp],%[y_buf] \n" \ + "bzhi %q[width],%[y_buf],%[y_buf] \n" \ + "kmovd %k[y_buf],%%k4 \n" \ + "vpermt2b %%zmm1,%%zmm20,%%zmm0 \n" \ + "vmovdqa64 %%zmm0,%%zmm3 \n" \ + "vpermt2b %%zmm2,%%zmm21,%%zmm3 \n" \ + "vpermt2b %%zmm2,%%zmm22,%%zmm0 \n" \ + "vmovdqu8 %%zmm3,(%[dst_rgb24])%{%%k3%} \n" \ + "vmovdqu8 %%ymm0,0x40(%[dst_rgb24])%{%%k4%} \n" + +// Store 32 RGB24 values with AVX512BW. +#define STORERGB24_AVX512BW \ + "vpunpcklbw %%zmm1,%%zmm0,%%zmm0 \n" \ + "vpunpcklbw %%zmm2,%%zmm2,%%zmm2 \n" \ + "vmovdqa64 %%zmm0,%%zmm1 \n" \ + "vpunpcklwd %%zmm2,%%zmm0,%%zmm0 \n" \ + "vpunpckhwd %%zmm2,%%zmm1,%%zmm1 \n" \ + "vpshufb %%zmm5,%%zmm0,%%zmm0 \n" \ + "vpshufb %%zmm6,%%zmm1,%%zmm1 \n" \ + "vpalignr $0xc,%%zmm0,%%zmm1,%%zmm1 \n" \ + "vmovdqa64 %%zmm20,%%zmm3 \n" \ + "vpermi2q %%zmm1,%%zmm0,%%zmm3 \n" \ + "vmovdqa64 %%zmm21,%%zmm4 \n" \ + "vpermi2q %%zmm1,%%zmm0,%%zmm4 \n" \ + "vmovdqu8 %%zmm3,(%[dst_rgb24]) \n" \ + "vmovdqu8 %%ymm4,0x40(%[dst_rgb24]) \n" \ + "lea 0x60(%[dst_rgb24]),%[dst_rgb24] \n" + +// Store masked RGB24 values with AVX512BW. +#define STORERGB24_MASK_AVX512BW \ + "lea (%q[width],%q[width],2),%k[width] \n" \ + "bzhi %q[width],%[temp],%[y_buf] \n" \ + "kmovq %[y_buf],%%k3 \n" \ + "xor %k[y_buf],%k[y_buf] \n" \ + "sub $0x40,%k[width] \n" \ + "cmovg %[temp],%[y_buf] \n" \ + "bzhi %q[width],%[y_buf],%[y_buf] \n" \ + "kmovd %k[y_buf],%%k4 \n" \ + "vpunpcklbw %%zmm1,%%zmm0,%%zmm0 \n" \ + "vpunpcklbw %%zmm2,%%zmm2,%%zmm2 \n" \ + "vmovdqa64 %%zmm0,%%zmm1 \n" \ + "vpunpcklwd %%zmm2,%%zmm0,%%zmm0 \n" \ + "vpunpckhwd %%zmm2,%%zmm1,%%zmm1 \n" \ + "vpshufb %%zmm5,%%zmm0,%%zmm0 \n" \ + "vpshufb %%zmm6,%%zmm1,%%zmm1 \n" \ + "vpalignr $0xc,%%zmm0,%%zmm1,%%zmm1 \n" \ + "vmovdqa64 %%zmm20,%%zmm3 \n" \ + "vpermi2q %%zmm1,%%zmm0,%%zmm3 \n" \ + "vmovdqa64 %%zmm21,%%zmm4 \n" \ + "vpermi2q %%zmm1,%%zmm0,%%zmm4 \n" \ + "vmovdqu8 %%zmm3,(%[dst_rgb24])%{%%k3%} \n" \ + "vmovdqu8 %%ymm4,0x40(%[dst_rgb24])%{%%k4%} \n" + +// Store 32 AR30 values. +#define STOREAR30_AVX512BW \ + "vpminsw %%zmm7,%%zmm0,%%zmm0 \n" \ + "vpminsw %%zmm7,%%zmm1,%%zmm1 \n" \ + "vpminsw %%zmm7,%%zmm2,%%zmm2 \n" \ + "vpmaxsw %%zmm6,%%zmm0,%%zmm0 \n" \ + "vpmaxsw %%zmm6,%%zmm1,%%zmm1 \n" \ + "vpmaxsw %%zmm6,%%zmm2,%%zmm2 \n" \ + "vpsrlw $4,%%zmm0,%%zmm0 \n" \ + "vpsrlw $10,%%zmm1,%%zmm3 \n" \ + "vpsllw $6,%%zmm1,%%zmm1 \n" \ + "vpternlogd $0xf8,%%zmm19,%%zmm1,%%zmm0 \n" \ + "vpternlogd $0xe4,%%zmm7,%%zmm3,%%zmm2 \n" \ + "vpord %%zmm5,%%zmm2,%%zmm2 \n" \ + "vmovdqa64 %%zmm0,%%zmm3 \n" \ + "vpermt2w %%zmm2,%%zmm20,%%zmm0 \n" \ + "vpermt2w %%zmm2,%%zmm21,%%zmm3 \n" \ + "vmovdqu32 %%zmm0,(%[dst_ar30]) \n" \ + "vmovdqu32 %%zmm3,0x40(%[dst_ar30]) \n" \ + "lea 0x80(%[dst_ar30]), %[dst_ar30] \n" + +// Store masked AR30 values with AVX512BW. +#define STOREAR30_MASK_AVX512BW \ + "vpminsw %%zmm7,%%zmm0,%%zmm0 \n" \ + "vpminsw %%zmm7,%%zmm1,%%zmm1 \n" \ + "vpminsw %%zmm7,%%zmm2,%%zmm2 \n" \ + "vpmaxsw %%zmm6,%%zmm0,%%zmm0 \n" \ + "vpmaxsw %%zmm6,%%zmm1,%%zmm1 \n" \ + "vpmaxsw %%zmm6,%%zmm2,%%zmm2 \n" \ + "vpsrlw $4,%%zmm0,%%zmm0 \n" \ + "vpsrlw $10,%%zmm1,%%zmm3 \n" \ + "vpsllw $6,%%zmm1,%%zmm1 \n" \ + "vpternlogd $0xf8,%%zmm19,%%zmm1,%%zmm0 \n" \ + "vpternlogd $0xe4,%%zmm7,%%zmm3,%%zmm2 \n" \ + "vpord %%zmm5,%%zmm2,%%zmm2 \n" \ + "vmovdqa64 %%zmm0,%%zmm3 \n" \ + "vpermt2w %%zmm2,%%zmm20,%%zmm0 \n" \ + "vpermt2w %%zmm2,%%zmm21,%%zmm3 \n" \ + "kshiftrd $16,%%k1,%%k2 \n" \ + "vmovdqu32 %%zmm0,(%[dst_ar30])%{%%k1%} \n" \ + "vmovdqu32 %%zmm3,0x40(%[dst_ar30])%{%%k2%} \n" // Store 16 AR30 values. #define STOREAR30_AVX2 \ - "vpsraw $0x4,%%ymm0,%%ymm0 \n" \ - "vpsraw $0x4,%%ymm1,%%ymm1 \n" \ - "vpsraw $0x4,%%ymm2,%%ymm2 \n" \ - "vpminsw %%ymm7,%%ymm0,%%ymm0 \n" \ - "vpminsw %%ymm7,%%ymm1,%%ymm1 \n" \ - "vpminsw %%ymm7,%%ymm2,%%ymm2 \n" \ - "vpmaxsw %%ymm6,%%ymm0,%%ymm0 \n" \ - "vpmaxsw %%ymm6,%%ymm1,%%ymm1 \n" \ - "vpmaxsw %%ymm6,%%ymm2,%%ymm2 \n" \ - "vpsllw $0x4,%%ymm2,%%ymm2 \n" \ - "vpermq $0xd8,%%ymm0,%%ymm0 \n" \ - "vpermq $0xd8,%%ymm1,%%ymm1 \n" \ - "vpermq $0xd8,%%ymm2,%%ymm2 \n" \ - "vpunpckhwd %%ymm2,%%ymm0,%%ymm3 \n" \ - "vpunpcklwd %%ymm2,%%ymm0,%%ymm0 \n" \ - "vpunpckhwd %%ymm5,%%ymm1,%%ymm2 \n" \ - "vpunpcklwd %%ymm5,%%ymm1,%%ymm1 \n" \ - "vpslld $0xa,%%ymm1,%%ymm1 \n" \ - "vpslld $0xa,%%ymm2,%%ymm2 \n" \ - "vpor %%ymm1,%%ymm0,%%ymm0 \n" \ - "vpor %%ymm2,%%ymm3,%%ymm3 \n" \ - "vmovdqu %%ymm0,(%[dst_ar30]) \n" \ - "vmovdqu %%ymm3,0x20(%[dst_ar30]) \n" \ - "lea 0x40(%[dst_ar30]), %[dst_ar30] \n" + "vpminsw %%ymm7,%%ymm0,%%ymm0 \n" \ + "vpminsw %%ymm7,%%ymm1,%%ymm1 \n" \ + "vpminsw %%ymm7,%%ymm2,%%ymm2 \n" \ + "vpmaxsw %%ymm6,%%ymm0,%%ymm0 \n" \ + "vpmaxsw %%ymm6,%%ymm1,%%ymm1 \n" \ + "vpmaxsw %%ymm6,%%ymm2,%%ymm2 \n" \ + "vpand %%ymm7,%%ymm1,%%ymm3 \n" \ + "vpand %%ymm7,%%ymm2,%%ymm2 \n" \ + "vpsrlw $4,%%ymm0,%%ymm0 \n" \ + "vpsrlw $10,%%ymm1,%%ymm1 \n" \ + "vpsllw $6,%%ymm3,%%ymm3 \n" \ + "vpor %%ymm3,%%ymm0,%%ymm0 \n" \ + "vpor %%ymm5,%%ymm2,%%ymm2 \n" \ + "vpor %%ymm1,%%ymm2,%%ymm2 \n" \ + "vpermq $0xd8,%%ymm2,%%ymm2 \n" \ + "vpermq $0xd8,%%ymm0,%%ymm0 \n" \ + "vpunpcklwd %%ymm2,%%ymm0,%%ymm1 \n" \ + "vpunpckhwd %%ymm2,%%ymm0,%%ymm3 \n" \ + "vmovdqu %%ymm1,(%[dst_ar30]) \n" \ + "vmovdqu %%ymm3,0x20(%[dst_ar30]) \n" \ + "lea 0x40(%[dst_ar30]), %[dst_ar30] \n" #ifdef HAS_I444TOARGBROW_AVX2 // 16 pixels @@ -2695,17 +5685,17 @@ void OMITFP I444ToARGBRow_AVX2(const uint8_t* y_buf, int width) { asm volatile ( YUVTORGB_SETUP_AVX2(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "sub %[u_buf],%[v_buf] \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" LABELALIGN - "1: \n" + "1: \n" READYUV444_AVX2 YUVTORGB_AVX2(yuvconstants) STOREARGB_AVX2 - "sub $0x10,%[width] \n" - "jg 1b \n" - "vzeroupper \n" + "sub $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] @@ -2729,18 +5719,18 @@ void OMITFP I422ToARGBRow_AVX2(const uint8_t* y_buf, int width) { asm volatile ( YUVTORGB_SETUP_AVX2(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "sub %[u_buf],%[v_buf] \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" LABELALIGN - "1: \n" + "1: \n" READYUV422_AVX2 YUVTORGB_AVX2(yuvconstants) STOREARGB_AVX2 - "sub $0x10,%[width] \n" - "jg 1b \n" + "sub $0x10,%[width] \n" + "jg 1b \n" - "vzeroupper \n" + "vzeroupper \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] @@ -2751,7 +5741,364 @@ void OMITFP I422ToARGBRow_AVX2(const uint8_t* y_buf, "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" ); } -#endif // HAS_I422TOARGBROW_AVX2 +#endif // defined(HAS_I422TOARGBROW_AVX2) + +#if defined(HAS_I422TORGB24ROW_AVX2) +// 16 pixels +// 8 UV values upsampled to 16 UV, mixed with 16 Y producing 16 RGB24 (48 +// bytes). +void OMITFP I422ToRGB24Row_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { +#if defined(__i386__) + uint32_t shuf0[4]; + uint32_t shuf1[4]; + memcpy(shuf0, &kShuffleMaskARGBToRGB24[0], sizeof(shuf0)); + memcpy(shuf1, &kShuffleMaskARGBToRGB24[1], sizeof(shuf1)); +#endif + asm volatile ( + YUVTORGB_SETUP_AVX2(yuvconstants) + "vbroadcasti128 %[kShuffleMaskARGBToRGB24_1],%%ymm5 \n" + "vbroadcasti128 %[kShuffleMaskARGBToRGB24_0],%%ymm6 \n" + "sub %[u_buf],%[v_buf] \n" + + LABELALIGN + "1: \n" + READYUV422_AVX2 + YUVTORGB_AVX2(yuvconstants) + STORERGB24_AVX2 + "subl $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_rgb24]"+r"(dst_rgb24), // %[dst_rgb24] +#if defined(__i386__) + [width]"+m"(width) // %[width] +#else + [width]"+rm"(width) // %[width] +#endif + : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] +#if defined(__i386__) + [kShuffleMaskARGBToRGB24_0]"m"(shuf0), + [kShuffleMaskARGBToRGB24_1]"m"(shuf1) +#else + [kShuffleMaskARGBToRGB24_0]"m"(kShuffleMaskARGBToRGB24[0]), + [kShuffleMaskARGBToRGB24_1]"m"(kShuffleMaskARGBToRGB24[1]) +#endif + : "memory", "cc", YUVTORGB_REGS_AVX2 + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6" + ); +} +#endif // defined(HAS_I422TORGB24ROW_AVX2) + +#if defined(HAS_I422TOARGBROW_AVX512BW) || \ + defined(HAS_I422TORGB24ROW_AVX512VBMI) || \ + defined(HAS_I422TORGB24ROW_AVX512BW) || \ + defined(HAS_I422TOAR30ROW_AVX512BW) || \ + defined(HAS_I444TOARGBROW_AVX512BW) || \ + defined(HAS_I444ALPHATOARGBROW_AVX512BW) || \ + defined(HAS_I444TORGB24ROW_AVX512VBMI) || \ + defined(HAS_I422TORGBAROW_AVX512BW) || \ + defined(HAS_YUY2TOARGBROW_AVX512BW) || \ + defined(HAS_UYVYTOARGBROW_AVX512BW) || \ + defined(HAS_I210TOARGBROW_AVX512BW) || \ + defined(HAS_I210TOAR30ROW_AVX512BW) || \ + defined(HAS_I210ALPHATOARGBROW_AVX512BW) || \ + defined(HAS_I212TOARGBROW_AVX512BW) || \ + defined(HAS_I212TOAR30ROW_AVX512BW) || \ + defined(HAS_I410TOARGBROW_AVX512BW) || \ + defined(HAS_I410TOAR30ROW_AVX512BW) || \ + defined(HAS_I410ALPHATOARGBROW_AVX512BW) || \ + defined(HAS_P210TOARGBROW_AVX512BW) || \ + defined(HAS_P210TOAR30ROW_AVX512BW) || \ + defined(HAS_P410TOARGBROW_AVX512BW) || defined(HAS_P410TOAR30ROW_AVX512BW) +static const uint16_t kSplitQuadWords[32] = { + 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, + 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15}; +static const uint64_t kUnpermuteAVX512[8] = {0, 4, 1, 5, 2, 6, 3, 7}; +#endif + +#if defined(HAS_I422TOAR30ROW_AVX512BW) || \ + defined(HAS_I210TOAR30ROW_AVX512BW) || \ + defined(HAS_I212TOAR30ROW_AVX512BW) || \ + defined(HAS_I410TOAR30ROW_AVX512BW) || \ + defined(HAS_P210TOAR30ROW_AVX512BW) || defined(HAS_P410TOAR30ROW_AVX512BW) +static const uint16_t kPermAR30_0[32] = { + 0, 32, 1, 33, 2, 34, 3, 35, 4, 36, 5, 37, 6, 38, 7, 39, + 8, 40, 9, 41, 10, 42, 11, 43, 12, 44, 13, 45, 14, 46, 15, 47}; +static const uint16_t kPermAR30_1[32] = { + 16, 48, 17, 49, 18, 50, 19, 51, 20, 52, 21, 53, 22, 54, 23, 55, + 24, 56, 25, 57, 26, 58, 27, 59, 28, 60, 29, 61, 30, 62, 31, 63}; +#endif + +#if defined(HAS_I422TOARGBROW_AVX512BW) +// 32 pixels +// 16 UV values upsampled to 32 UV, mixed with 32 Y producing 32 ARGB (128 +// bytes). +LIBYUV_TARGET_AVX512BW +void OMITFP I422ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile ( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV422_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV422_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_argb]"+r"(dst_argb), // %[dst_argb] + [width]"+r"(width), // %[width] + [temp]"=&r"(temp) // %[temp] + : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] + [quadsplitperm]"r"(kSplitQuadWords), // %[quadsplitperm] + [unperm]"r"(kUnpermuteAVX512) // %[unperm] + : "memory", "cc", YUVTORGB_REGS_AVX512BW + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "k1", "k2" + ); +} +#endif // defined(HAS_I422TOARGBROW_AVX512BW) + +#if defined(HAS_I422TORGB24ROW_AVX512VBMI) || \ + defined(HAS_I444TORGB24ROW_AVX512VBMI) +static const uint8_t kMaskBG[64] = { + 0x00, 0x40, 0x01, 0x41, 0x02, 0x42, 0x03, 0x43, 0x04, 0x44, 0x05, + 0x45, 0x06, 0x46, 0x07, 0x47, 0x10, 0x50, 0x11, 0x51, 0x12, 0x52, + 0x13, 0x53, 0x14, 0x54, 0x15, 0x55, 0x16, 0x56, 0x17, 0x57, 0x20, + 0x60, 0x21, 0x61, 0x22, 0x62, 0x23, 0x63, 0x24, 0x64, 0x25, 0x65, + 0x26, 0x66, 0x27, 0x67, 0x30, 0x70, 0x31, 0x71, 0x32, 0x72, 0x33, + 0x73, 0x34, 0x74, 0x35, 0x75, 0x36, 0x76, 0x37, 0x77}; +static const uint8_t kMaskDST0[64] = { + 0x00, 0x01, 0x40, 0x02, 0x03, 0x41, 0x04, 0x05, 0x42, 0x06, 0x07, + 0x43, 0x08, 0x09, 0x44, 0x0a, 0x0b, 0x45, 0x0c, 0x0d, 0x46, 0x0e, + 0x0f, 0x47, 0x10, 0x11, 0x50, 0x12, 0x13, 0x51, 0x14, 0x15, 0x52, + 0x16, 0x17, 0x53, 0x18, 0x19, 0x54, 0x1a, 0x1b, 0x55, 0x1c, 0x1d, + 0x56, 0x1e, 0x1f, 0x57, 0x20, 0x21, 0x60, 0x22, 0x23, 0x61, 0x24, + 0x25, 0x62, 0x26, 0x27, 0x63, 0x28, 0x29, 0x64, 0x2a}; +static const uint8_t kMaskDST1[64] = { + 0x2b, 0x65, 0x2c, 0x2d, 0x66, 0x2e, 0x2f, 0x67, 0x30, 0x31, 0x70, + 0x32, 0x33, 0x71, 0x34, 0x35, 0x72, 0x36, 0x37, 0x73, 0x38, 0x39, + 0x74, 0x3a, 0x3b, 0x75, 0x3c, 0x3d, 0x76, 0x3e, 0x3f, 0x77, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +#endif // defined(HAS_I422TORGB24ROW_AVX512VBMI) || + // defined(HAS_I444TORGB24ROW_AVX512VBMI) + +#if defined(HAS_I422TORGB24ROW_AVX512VBMI) +// 32 pixels +// 16 UV values upsampled to 32 UV, mixed with 32 Y producing 32 RGB24 (96 +// bytes). +LIBYUV_TARGET_AVX512VBMI +void OMITFP I422ToRGB24Row_AVX512VBMI(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile ( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vmovdqu32 %[kMaskBG],%%zmm20 \n" + "vmovdqu32 %[kMaskDST0],%%zmm21 \n" + "vmovdqu32 %[kMaskDST1],%%zmm22 \n" + "sub %[u_buf],%[v_buf] \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV422_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGB24_AVX512VBMI + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV422_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGB24_MASK_AVX512VBMI + + "99: \n" + "vzeroupper \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_rgb24]"+r"(dst_rgb24), // %[dst_rgb24] + [width]"+r"(width), // %[width] + [temp]"=&r"(temp) // %[temp] + : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] + [quadsplitperm]"r"(kSplitQuadWords), // %[quadsplitperm] + [unperm]"r"(kUnpermuteAVX512), // %[unperm] + [kMaskBG]"m"(kMaskBG), // %[kMaskBG] + [kMaskDST0]"m"(kMaskDST0), // %[kMaskDST0] + [kMaskDST1]"m"(kMaskDST1) // %[kMaskDST1] + : "memory", "cc", YUVTORGB_REGS_AVX512BW + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm20", "xmm21", "xmm22", + "k1", "k2", "k3", "k4" + ); +} +#endif // defined(HAS_I422TORGB24ROW_AVX512VBMI) + +#if defined(HAS_I422TORGB24ROW_AVX512BW) +static const uint64_t kStitchRGB24_0[8] = {0, 8, 9, 2, 10, 11, 4, 12}; +static const uint64_t kStitchRGB24_1[8] = {13, 6, 14, 15, 0, 0, 0, 0}; + +// 32 pixels +// 16 UV values upsampled to 32 UV, mixed with 32 Y producing 32 RGB24 (96 +// bytes). +LIBYUV_TARGET_AVX512BW +void OMITFP I422ToRGB24Row_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile ( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vbroadcasti32x4 %[kShuffleMaskARGBToRGB24_1],%%zmm5 \n" + "vbroadcasti32x4 %[kShuffleMaskARGBToRGB24_0],%%zmm6 \n" + "vmovdqu64 %[kStitchRGB24_0],%%zmm20 \n" + "vmovdqu64 %[kStitchRGB24_1],%%zmm21 \n" + "sub %[u_buf],%[v_buf] \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV422_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGB24_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV422_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGB24_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_rgb24]"+r"(dst_rgb24), // %[dst_rgb24] + [width]"+r"(width), // %[width] + [temp]"=&r"(temp) // %[temp] + : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] + [quadsplitperm]"r"(kSplitQuadWords), // %[quadsplitperm] + [unperm]"r"(kUnpermuteAVX512), // %[unperm] + [kShuffleMaskARGBToRGB24_0]"m"(kShuffleMaskARGBToRGB24[0]), + [kShuffleMaskARGBToRGB24_1]"m"(kShuffleMaskARGBToRGB24[1]), + [kStitchRGB24_0]"m"(kStitchRGB24_0), // %[kStitchRGB24_0] + [kStitchRGB24_1]"m"(kStitchRGB24_1) // %[kStitchRGB24_1] + : "memory", "cc", YUVTORGB_REGS_AVX512BW + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm20", "xmm21", + "k1", "k2", "k3", "k4" + ); +} +#endif // defined(HAS_I422TORGB24ROW_AVX512BW) + +#if defined(HAS_I422TOAR30ROW_AVX512BW) +// 32 pixels +// 16 UV values upsampled to 32 UV, mixed with 32 Y producing 32 AR30 (128 +// bytes). +LIBYUV_TARGET_AVX512BW +void OMITFP I422ToAR30Row_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile ( + YUVTORGB_SETUP_AR30_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" // all 1s + "vpsrlw $6,%%zmm5,%%zmm7 \n" + "vpsllw $4,%%zmm7,%%zmm7 \n" // 1023 * 16 for max + "vpsllw $10,%%zmm5,%%zmm19 \n" // 0xfc00 for G mask + "vpsllw $14,%%zmm5,%%zmm5 \n" // 0xc000 for 2 alpha bits + "vpxord %%zmm6,%%zmm6,%%zmm6 \n" // 0 for min + "vmovdqu16 (%[permar30_0]),%%zmm20 \n" + "vmovdqu16 (%[permar30_1]),%%zmm21 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV422_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV422_MASK_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_ar30]"+r"(dst_ar30), // %[dst_ar30] + [width]"+r"(width), // %[width] + [temp]"=&r"(temp) // %[temp] + : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] + [quadsplitperm]"r"(kSplitQuadWords), // %[quadsplitperm] + [unperm]"r"(kUnpermuteAVX512), // %[unperm] + [permar30_0]"r"(kPermAR30_0), // %[permar30_0] + [permar30_1]"r"(kPermAR30_1) // %[permar30_1] + : "memory", "cc", YUVTORGB_REGS_AVX512BW + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", + "xmm19", "xmm20", "xmm21", "k1", "k2" + ); +} +#endif // defined(HAS_I422TOAR30ROW_AVX512BW) #if defined(HAS_I422TOAR30ROW_AVX2) // 16 pixels @@ -2763,35 +6110,38 @@ void OMITFP I422ToAR30Row_AVX2(const uint8_t* y_buf, const struct YuvConstants* yuvconstants, int width) { asm volatile ( - YUVTORGB_SETUP_AVX2(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" // AR30 constants - "vpsrlw $14,%%ymm5,%%ymm5 \n" - "vpsllw $4,%%ymm5,%%ymm5 \n" // 2 alpha bits - "vpxor %%ymm6,%%ymm6,%%ymm6 \n" // 0 for min - "vpcmpeqb %%ymm7,%%ymm7,%%ymm7 \n" // 1023 for max - "vpsrlw $6,%%ymm7,%%ymm7 \n" + YUVTORGB_SETUP_AR30_AVX2(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" // all 1s + "vpsrlw $6,%%ymm5,%%ymm7 \n" + "vpsllw $4,%%ymm7,%%ymm7 \n" // 1023 * 16 for max + "vpsllw $14,%%ymm5,%%ymm5 \n" // 0xc000 for 2 alpha bits + "vpxor %%ymm6,%%ymm6,%%ymm6 \n" // 0 for min LABELALIGN - "1: \n" + "1: \n" READYUV422_AVX2 - YUVTORGB16_AVX2(yuvconstants) + YUVTORGB16_AR30_AVX2(yuvconstants) STOREAR30_AVX2 - "sub $0x10,%[width] \n" - "jg 1b \n" + "subl $0x10,%[width] \n" + "jg 1b \n" - "vzeroupper \n" + "vzeroupper \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] [dst_ar30]"+r"(dst_ar30), // %[dst_ar30] +#if defined(__i386__) + [width]"+m"(width) // %[width] +#else [width]"+rm"(width) // %[width] +#endif : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] : "memory", "cc", YUVTORGB_REGS_AVX2 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" ); } -#endif // HAS_I422TOAR30ROW_AVX2 +#endif // defined(HAS_I422TOAR30ROW_AVX2) #if defined(HAS_I210TOARGBROW_AVX2) // 16 pixels @@ -2804,18 +6154,18 @@ void OMITFP I210ToARGBRow_AVX2(const uint16_t* y_buf, int width) { asm volatile ( YUVTORGB_SETUP_AVX2(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "sub %[u_buf],%[v_buf] \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" LABELALIGN - "1: \n" + "1: \n" READYUV210_AVX2 YUVTORGB_AVX2(yuvconstants) STOREARGB_AVX2 - "sub $0x10,%[width] \n" - "jg 1b \n" + "sub $0x10,%[width] \n" + "jg 1b \n" - "vzeroupper \n" + "vzeroupper \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] @@ -2826,7 +6176,42 @@ void OMITFP I210ToARGBRow_AVX2(const uint16_t* y_buf, "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" ); } -#endif // HAS_I210TOARGBROW_AVX2 +#endif // defined(HAS_I210TOARGBROW_AVX2) + +#if defined(HAS_I212TOARGBROW_AVX2) +// 16 pixels +// 8 UV values upsampled to 16 UV, mixed with 16 Y producing 16 ARGB (64 bytes). +void OMITFP I212ToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile ( + YUVTORGB_SETUP_AVX2(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + + LABELALIGN + "1: \n" + READYUV212_AVX2 + YUVTORGB_AVX2(yuvconstants) + STOREARGB_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + + "vzeroupper \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_argb]"+r"(dst_argb), // %[dst_argb] + [width]"+rm"(width) // %[width] + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" + ); +} +#endif // defined(HAS_I212TOARGBROW_AVX2) #if defined(HAS_I210TOAR30ROW_AVX2) // 16 pixels @@ -2839,23 +6224,22 @@ void OMITFP I210ToAR30Row_AVX2(const uint16_t* y_buf, int width) { asm volatile ( YUVTORGB_SETUP_AVX2(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" // AR30 constants - "vpsrlw $14,%%ymm5,%%ymm5 \n" - "vpsllw $4,%%ymm5,%%ymm5 \n" // 2 alpha bits - "vpxor %%ymm6,%%ymm6,%%ymm6 \n" // 0 for min - "vpcmpeqb %%ymm7,%%ymm7,%%ymm7 \n" // 1023 for max - "vpsrlw $6,%%ymm7,%%ymm7 \n" + "sub %[u_buf],%[v_buf] \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" // all 1s + "vpsrlw $6,%%ymm5,%%ymm7 \n" + "vpsllw $4,%%ymm7,%%ymm7 \n" // 1023 * 16 for max + "vpsllw $14,%%ymm5,%%ymm5 \n" // 0xc000 for 2 alpha bits + "vpxor %%ymm6,%%ymm6,%%ymm6 \n" // 0 for min LABELALIGN - "1: \n" + "1: \n" READYUV210_AVX2 YUVTORGB16_AVX2(yuvconstants) STOREAR30_AVX2 - "sub $0x10,%[width] \n" - "jg 1b \n" + "sub $0x10,%[width] \n" + "jg 1b \n" - "vzeroupper \n" + "vzeroupper \n" : [y_buf]"+r"(y_buf), // %[y_buf] [u_buf]"+r"(u_buf), // %[u_buf] [v_buf]"+r"(v_buf), // %[v_buf] @@ -2863,10 +6247,353 @@ void OMITFP I210ToAR30Row_AVX2(const uint16_t* y_buf, [width]"+rm"(width) // %[width] : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] : "memory", "cc", YUVTORGB_REGS_AVX2 - "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" ); } -#endif // HAS_I210TOAR30ROW_AVX2 +#endif // defined(HAS_I210TOAR30ROW_AVX2) + +#if defined(HAS_I212TOAR30ROW_AVX2) +// 16 pixels +// 8 UV values upsampled to 16 UV, mixed with 16 Y producing 16 AR30 (64 bytes). +void OMITFP I212ToAR30Row_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile ( + YUVTORGB_SETUP_AVX2(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" // all 1s + "vpsrlw $6,%%ymm5,%%ymm7 \n" + "vpsllw $4,%%ymm7,%%ymm7 \n" // 1023 * 16 for max + "vpsllw $14,%%ymm5,%%ymm5 \n" // 0xc000 for 2 alpha bits + "vpxor %%ymm6,%%ymm6,%%ymm6 \n" // 0 for min + + LABELALIGN + "1: \n" + READYUV212_AVX2 + YUVTORGB16_AVX2(yuvconstants) + STOREAR30_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + + "vzeroupper \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_ar30]"+r"(dst_ar30), // %[dst_ar30] + [width]"+rm"(width) // %[width] + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" + ); +} +#endif // defined(HAS_I212TOAR30ROW_AVX2) + +#if defined(HAS_I410TOARGBROW_AVX2) +// 16 pixels +// 16 UV values with 16 Y producing 16 ARGB (64 bytes). +void OMITFP I410ToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile ( + YUVTORGB_SETUP_AVX2(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + + LABELALIGN + "1: \n" + READYUV410_AVX2 + YUVTORGB_AVX2(yuvconstants) + STOREARGB_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_argb]"+r"(dst_argb), // %[dst_argb] + [width]"+rm"(width) // %[width] + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" + ); +} +#endif // defined(HAS_I410TOARGBROW_AVX2) + +#if defined(HAS_I210ALPHATOARGBROW_AVX2) +// 16 pixels +// 8 UV, 16 Y and 16 A producing 16 ARGB (64 bytes). +void OMITFP I210AlphaToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { +#if defined(__i386__) + uintptr_t temp; + asm volatile( + "mov %[v_buf],%[temp] \n" + "sub %[u_buf],%[temp] \n" + "vmovd %[temp],%%xmm7 \n" + "vmovd %[a_buf],%%xmm6 \n" + + LABELALIGN + "1: \n" + "vmovd %%xmm7,%[temp] \n" + "vmovdqu (%[u_buf]),%%xmm3 \n" + "vmovdqu 0x00(%[u_buf],%[temp],1),%%xmm1 \n" + "lea 0x10(%[u_buf]),%[u_buf] \n" + "vpermq $0xd8,%%ymm3,%%ymm3 \n" + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpunpcklwd %%ymm1,%%ymm3,%%ymm3 \n" + "vpsraw $2,%%ymm3,%%ymm3 \n" + "vpackuswb %%ymm3,%%ymm3,%%ymm3 \n" + "vpunpcklwd %%ymm3,%%ymm3,%%ymm3 \n" + "vmovdqu (%[y_buf]),%%ymm4 \n" + "vpsllw $6,%%ymm4,%%ymm2 \n" + "vpsrlw $4,%%ymm4,%%ymm4 \n" + "vpaddw %%ymm2,%%ymm4,%%ymm4 \n" + "lea 0x20(%[y_buf]),%[y_buf] \n" + "vmovd %%xmm6,%[temp] \n" + "vmovdqu (%[temp]),%%ymm5 \n" + "vpsraw $2,%%ymm5,%%ymm5 \n" + "vpackuswb %%ymm5,%%ymm5,%%ymm5 \n" + "lea 0x20(%[temp]),%[temp] \n" + "vmovd %[temp],%%xmm6 \n" + YUVTORGB_AVX2(yuvconstants) + STOREARGB_AVX2 + "subl $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [dst_argb] "+r"(dst_argb), + [temp] "=&r"(temp), + [width] "+m"(width) + : [v_buf] "m"(v_buf), + [a_buf] "m"(a_buf), + [yuvconstants] "r"(yuvconstants) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); +#else + asm volatile(YUVTORGB_SETUP_AVX2( + yuvconstants) "sub %[u_buf],%[v_buf] \n" + + LABELALIGN "1: \n" READYUVA210_AVX2 YUVTORGB_AVX2( + yuvconstants) STOREARGB_AVX2 + "subl $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + + : [y_buf] "+r"(y_buf), // %[y_buf] + [u_buf] "+r"(u_buf), // %[u_buf] + [v_buf] "+r"(v_buf), // %[v_buf] + [a_buf] "+r"(a_buf), // %[a_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 "xmm0", "xmm1", "xmm2", + "xmm3", "xmm4", "xmm5"); +#endif +} +#endif // defined(HAS_I210ALPHATOARGBROW_AVX2) + +#if defined(HAS_I410ALPHATOARGBROW_AVX2) +// 16 pixels +// 16 UV, 16 Y and 16 A producing 16 ARGB (64 bytes). +void OMITFP I410AlphaToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { +#if defined(__i386__) + uintptr_t temp; + asm volatile( + "mov %[v_buf],%[temp] \n" + "sub %[u_buf],%[temp] \n" + "vmovd %[temp],%%xmm7 \n" + "vmovd %[a_buf],%%xmm6 \n" + + LABELALIGN + "1: \n" + "vmovd %%xmm7,%[temp] \n" + "vmovdqu (%[u_buf]),%%ymm3 \n" + "vmovdqu 0x00(%[u_buf],%[temp],1),%%ymm2 \n" + "lea 0x20(%[u_buf]),%[u_buf] \n" + "vpsraw $2,%%ymm3,%%ymm3 \n" + "vpsraw $2,%%ymm2,%%ymm2 \n" + "vpunpckhwd %%ymm2,%%ymm3,%%ymm1 \n" + "vpunpcklwd %%ymm2,%%ymm3,%%ymm3 \n" + "vpackuswb %%ymm1,%%ymm3,%%ymm3 \n" + "vmovdqu (%[y_buf]),%%ymm4 \n" + "vpsllw $6,%%ymm4,%%ymm2 \n" + "vpsrlw $4,%%ymm4,%%ymm4 \n" + "vpaddw %%ymm2,%%ymm4,%%ymm4 \n" + "lea 0x20(%[y_buf]),%[y_buf] \n" + "vmovd %%xmm6,%[temp] \n" + "vmovdqu (%[temp]),%%ymm5 \n" + "vpsraw $2,%%ymm5,%%ymm5 \n" + "vpackuswb %%ymm5,%%ymm5,%%ymm5 \n" + "lea 0x20(%[temp]),%[temp] \n" + "vmovd %[temp],%%xmm6 \n" + YUVTORGB_AVX2(yuvconstants) + STOREARGB_AVX2 + "subl $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [dst_argb] "+r"(dst_argb), + [temp] "=&r"(temp), + [width] "+m"(width) + : [v_buf] "m"(v_buf), + [a_buf] "m"(a_buf), + [yuvconstants] "r"(yuvconstants) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); +#else + asm volatile(YUVTORGB_SETUP_AVX2( + yuvconstants) "sub %[u_buf],%[v_buf] \n" + + LABELALIGN "1: \n" READYUVA410_AVX2 YUVTORGB_AVX2( + yuvconstants) STOREARGB_AVX2 + "subl $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + + : [y_buf] "+r"(y_buf), // %[y_buf] + [u_buf] "+r"(u_buf), // %[u_buf] + [v_buf] "+r"(v_buf), // %[v_buf] + [a_buf] "+r"(a_buf), // %[a_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 "xmm0", "xmm1", "xmm2", + "xmm3", "xmm4", "xmm5"); +#endif +} +#endif // defined(HAS_I410ALPHATOARGBROW_AVX2) + +#if defined(HAS_I410TOAR30ROW_AVX2) +// 16 pixels +// 16 UV values with 16 Y producing 16 AR30 (64 bytes). +void OMITFP I410ToAR30Row_AVX2(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile ( + YUVTORGB_SETUP_AVX2(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" // all 1s + "vpsrlw $6,%%ymm5,%%ymm7 \n" + "vpsllw $4,%%ymm7,%%ymm7 \n" // 1023 * 16 for max + "vpsllw $14,%%ymm5,%%ymm5 \n" // 0xc000 for 2 alpha bits + "vpxor %%ymm6,%%ymm6,%%ymm6 \n" // 0 for min + + LABELALIGN + "1: \n" + READYUV410_AVX2 + YUVTORGB16_AVX2(yuvconstants) + STOREAR30_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + + "vzeroupper \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [u_buf]"+r"(u_buf), // %[u_buf] + [v_buf]"+r"(v_buf), // %[v_buf] + [dst_ar30]"+r"(dst_ar30), // %[dst_ar30] + [width]"+rm"(width) // %[width] + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" + ); +} +#endif // defined(HAS_I410TOAR30ROW_AVX2) + +#if defined(HAS_I444ALPHATOARGBROW_AVX2) +// 16 pixels +// 16 UV values with 16 Y and 16 A producing 16 ARGB. +void OMITFP I444AlphaToARGBRow_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { +#if defined(__i386__) + uintptr_t temp; + asm volatile( + "mov %[v_buf],%[temp] \n" + "sub %[u_buf],%[temp] \n" + "vmovd %[temp],%%xmm7 \n" + "vmovd %[a_buf],%%xmm6 \n" + + LABELALIGN + "1: \n" + "vmovd %%xmm7,%[temp] \n" + "vmovdqu (%[u_buf]),%%xmm3 \n" + "vmovdqu 0x00(%[u_buf],%[temp],1),%%xmm1 \n" + "lea 0x10(%[u_buf]),%[u_buf] \n" + "vpermq $0xd8,%%ymm3,%%ymm3 \n" + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpunpcklbw %%ymm1,%%ymm3,%%ymm3 \n" + "vmovdqu (%[y_buf]),%%xmm4 \n" + "vpermq $0xd8,%%ymm4,%%ymm4 \n" + "vpunpcklbw %%ymm4,%%ymm4,%%ymm4 \n" + "lea 0x10(%[y_buf]),%[y_buf] \n" + "vmovd %%xmm6,%[temp] \n" + "vmovdqu (%[temp]),%%xmm5 \n" + "vpermq $0xd8,%%ymm5,%%ymm5 \n" + "lea 0x10(%[temp]),%[temp] \n" + "vmovd %[temp],%%xmm6 \n" + YUVTORGB_AVX2(yuvconstants) + STOREARGB_AVX2 + "subl $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [dst_argb] "+r"(dst_argb), + [temp] "=&r"(temp), + [width] "+m"(width) + : [v_buf] "m"(v_buf), + [a_buf] "m"(a_buf), + [yuvconstants] "r"(yuvconstants) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); +#else + asm volatile(YUVTORGB_SETUP_AVX2( + yuvconstants) "sub %[u_buf],%[v_buf] \n" + + LABELALIGN "1: \n" READYUVA444_AVX2 YUVTORGB_AVX2( + yuvconstants) STOREARGB_AVX2 + "subl $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [u_buf] "+r"(u_buf), // %[u_buf] + [v_buf] "+r"(v_buf), // %[v_buf] + [a_buf] "+r"(a_buf), // %[a_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 "xmm0", "xmm1", "xmm2", + "xmm3", "xmm4", "xmm5"); +#endif +} +#endif // defined(HAS_I444ALPHATOARGBROW_AVX2) #if defined(HAS_I422ALPHATOARGBROW_AVX2) // 16 pixels @@ -2878,36 +6605,68 @@ void OMITFP I422AlphaToARGBRow_AVX2(const uint8_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - // clang-format off - asm volatile ( - YUVTORGB_SETUP_AVX2(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - - LABELALIGN - "1: \n" - READYUVA422_AVX2 - YUVTORGB_AVX2(yuvconstants) - STOREARGB_AVX2 - "subl $0x10,%[width] \n" - "jg 1b \n" - "vzeroupper \n" - : [y_buf]"+r"(y_buf), // %[y_buf] - [u_buf]"+r"(u_buf), // %[u_buf] - [v_buf]"+r"(v_buf), // %[v_buf] - [a_buf]"+r"(a_buf), // %[a_buf] - [dst_argb]"+r"(dst_argb), // %[dst_argb] #if defined(__i386__) - [width]"+m"(width) // %[width] + uintptr_t temp; + asm volatile( + "mov %[v_buf],%[temp] \n" + "sub %[u_buf],%[temp] \n" + "vmovd %[temp],%%xmm7 \n" + "vmovd %[a_buf],%%xmm6 \n" + + LABELALIGN + "1: \n" + "vmovd %%xmm7,%[temp] \n" + "vmovq (%[u_buf]),%%xmm3 \n" + "vmovq 0x00(%[u_buf],%[temp],1),%%xmm1 \n" + "lea 0x8(%[u_buf]),%[u_buf] \n" + "vpunpcklbw %%ymm1,%%ymm3,%%ymm3 \n" + "vpermq $0xd8,%%ymm3,%%ymm3 \n" + "vpunpcklwd %%ymm3,%%ymm3,%%ymm3 \n" + "vmovdqu (%[y_buf]),%%xmm4 \n" + "vpermq $0xd8,%%ymm4,%%ymm4 \n" + "vpunpcklbw %%ymm4,%%ymm4,%%ymm4 \n" + "lea 0x10(%[y_buf]),%[y_buf] \n" + "vmovd %%xmm6,%[temp] \n" + "vmovdqu (%[temp]),%%xmm5 \n" + "vpermq $0xd8,%%ymm5,%%ymm5 \n" + "lea 0x10(%[temp]),%[temp] \n" + "vmovd %[temp],%%xmm6 \n" + YUVTORGB_AVX2(yuvconstants) + STOREARGB_AVX2 + "subl $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [dst_argb] "+r"(dst_argb), + [temp] "=&r"(temp), + [width] "+m"(width) + : [v_buf] "m"(v_buf), + [a_buf] "m"(a_buf), + [yuvconstants] "r"(yuvconstants) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); #else - [width]"+rm"(width) // %[width] + asm volatile(YUVTORGB_SETUP_AVX2( + yuvconstants) "sub %[u_buf],%[v_buf] \n" + + LABELALIGN "1: \n" READYUVA422_AVX2 YUVTORGB_AVX2( + yuvconstants) STOREARGB_AVX2 + "subl $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [u_buf] "+r"(u_buf), // %[u_buf] + [v_buf] "+r"(v_buf), // %[v_buf] + [a_buf] "+r"(a_buf), // %[a_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 "xmm0", "xmm1", "xmm2", + "xmm3", "xmm4", "xmm5"); #endif - : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] - : "memory", "cc", YUVTORGB_REGS_AVX2 - "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" - ); - // clang-format on } -#endif // HAS_I422ALPHATOARGBROW_AVX2 +#endif // defined(HAS_I422ALPHATOARGBROW_AVX2) #if defined(HAS_I422TORGBAROW_AVX2) // 16 pixels @@ -2920,11 +6679,11 @@ void OMITFP I422ToRGBARow_AVX2(const uint8_t* y_buf, int width) { asm volatile ( YUVTORGB_SETUP_AVX2(yuvconstants) - "sub %[u_buf],%[v_buf] \n" - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "sub %[u_buf],%[v_buf] \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" LABELALIGN - "1: \n" + "1: \n" READYUV422_AVX2 YUVTORGB_AVX2(yuvconstants) @@ -2951,7 +6710,7 @@ void OMITFP I422ToRGBARow_AVX2(const uint8_t* y_buf, "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" ); } -#endif // HAS_I422TORGBAROW_AVX2 +#endif // defined(HAS_I422TORGBAROW_AVX2) #if defined(HAS_NV12TOARGBROW_AVX2) // 16 pixels. @@ -2961,30 +6720,23 @@ void OMITFP NV12ToARGBRow_AVX2(const uint8_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - // clang-format off - asm volatile ( - YUVTORGB_SETUP_AVX2(yuvconstants) - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + asm volatile(YUVTORGB_SETUP_AVX2( + yuvconstants) "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - LABELALIGN - "1: \n" - READNV12_AVX2 - YUVTORGB_AVX2(yuvconstants) - STOREARGB_AVX2 - "sub $0x10,%[width] \n" - "jg 1b \n" - "vzeroupper \n" - : [y_buf]"+r"(y_buf), // %[y_buf] - [uv_buf]"+r"(uv_buf), // %[uv_buf] - [dst_argb]"+r"(dst_argb), // %[dst_argb] - [width]"+rm"(width) // %[width] - : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] - : "memory", "cc", YUVTORGB_REGS_AVX2 - "xmm0", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" - ); - // clang-format on + LABELALIGN "1: \n" READNV12_AVX2 YUVTORGB_AVX2( + yuvconstants) STOREARGB_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [uv_buf] "+r"(uv_buf), // %[uv_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 "xmm0", "xmm0", "xmm1", + "xmm2", "xmm3", "xmm4", "xmm5"); } -#endif // HAS_NV12TOARGBROW_AVX2 +#endif // defined(HAS_NV12TOARGBROW_AVX2) #if defined(HAS_NV21TOARGBROW_AVX2) // 16 pixels. @@ -2994,31 +6746,24 @@ void OMITFP NV21ToARGBRow_AVX2(const uint8_t* y_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - // clang-format off - asm volatile ( - YUVTORGB_SETUP_AVX2(yuvconstants) - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + asm volatile(YUVTORGB_SETUP_AVX2( + yuvconstants) "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - LABELALIGN - "1: \n" - READNV21_AVX2 - YUVTORGB_AVX2(yuvconstants) - STOREARGB_AVX2 - "sub $0x10,%[width] \n" - "jg 1b \n" - "vzeroupper \n" - : [y_buf]"+r"(y_buf), // %[y_buf] - [vu_buf]"+r"(vu_buf), // %[vu_buf] - [dst_argb]"+r"(dst_argb), // %[dst_argb] - [width]"+rm"(width) // %[width] - : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] - [kShuffleNV21]"m"(kShuffleNV21) - : "memory", "cc", YUVTORGB_REGS_AVX2 - "xmm0", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" - ); - // clang-format on + LABELALIGN "1: \n" READNV21_AVX2 YUVTORGB_AVX2( + yuvconstants) STOREARGB_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [vu_buf] "+r"(vu_buf), // %[vu_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants), // %[yuvconstants] + [kShuffleNV21] "m"(kShuffleNV21) + : "memory", "cc", YUVTORGB_REGS_AVX2 "xmm0", "xmm0", "xmm1", + "xmm2", "xmm3", "xmm4", "xmm5"); } -#endif // HAS_NV21TOARGBROW_AVX2 +#endif // defined(HAS_NV21TOARGBROW_AVX2) #if defined(HAS_YUY2TOARGBROW_AVX2) // 16 pixels. @@ -3027,31 +6772,25 @@ void OMITFP YUY2ToARGBRow_AVX2(const uint8_t* yuy2_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - // clang-format off - asm volatile ( - YUVTORGB_SETUP_AVX2(yuvconstants) - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + asm volatile( + "vbroadcasti128 %[kShuffleYUY2Y],%%ymm6 \n" + "vbroadcasti128 %[kShuffleYUY2UV],%%ymm7 \n" YUVTORGB_SETUP_AVX2( + yuvconstants) "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - LABELALIGN - "1: \n" - READYUY2_AVX2 - YUVTORGB_AVX2(yuvconstants) - STOREARGB_AVX2 - "sub $0x10,%[width] \n" - "jg 1b \n" - "vzeroupper \n" - : [yuy2_buf]"+r"(yuy2_buf), // %[yuy2_buf] - [dst_argb]"+r"(dst_argb), // %[dst_argb] - [width]"+rm"(width) // %[width] - : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] - [kShuffleYUY2Y]"m"(kShuffleYUY2Y), - [kShuffleYUY2UV]"m"(kShuffleYUY2UV) - : "memory", "cc", YUVTORGB_REGS_AVX2 - "xmm0", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" - ); - // clang-format on + LABELALIGN "1: \n" READYUY2_AVX2 YUVTORGB_AVX2(yuvconstants) + STOREARGB_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [yuy2_buf] "+r"(yuy2_buf), // %[yuy2_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants), // %[yuvconstants] + [kShuffleYUY2Y] "m"(kShuffleYUY2Y), [kShuffleYUY2UV] "m"(kShuffleYUY2UV) + : "memory", "cc", YUVTORGB_REGS_AVX2 "xmm0", "xmm0", "xmm1", "xmm2", + "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); } -#endif // HAS_YUY2TOARGBROW_AVX2 +#endif // defined(HAS_YUY2TOARGBROW_AVX2) #if defined(HAS_UYVYTOARGBROW_AVX2) // 16 pixels. @@ -3060,54 +6799,170 @@ void OMITFP UYVYToARGBRow_AVX2(const uint8_t* uyvy_buf, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - // clang-format off + asm volatile( + "vbroadcasti128 %[kShuffleUYVYY],%%ymm6 \n" + "vbroadcasti128 %[kShuffleUYVYUV],%%ymm7 \n" YUVTORGB_SETUP_AVX2( + yuvconstants) "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + + LABELALIGN "1: \n" READUYVY_AVX2 YUVTORGB_AVX2(yuvconstants) + STOREARGB_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [uyvy_buf] "+r"(uyvy_buf), // %[uyvy_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants), // %[yuvconstants] + [kShuffleUYVYY] "m"(kShuffleUYVYY), [kShuffleUYVYUV] "m"(kShuffleUYVYUV) + : "memory", "cc", YUVTORGB_REGS_AVX2 "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm6", "xmm7"); +} +#endif // defined(HAS_UYVYTOARGBROW_AVX2) + +#if defined(HAS_P210TOARGBROW_AVX2) +// 16 pixels. +// 8 UV values upsampled to 16 UV, mixed with 16 Y producing 16 ARGB (64 bytes). +void OMITFP P210ToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile(YUVTORGB_SETUP_AVX2( + yuvconstants) "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + + LABELALIGN "1: \n" READP210_AVX2 YUVTORGB_AVX2( + yuvconstants) STOREARGB_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [uv_buf] "+r"(uv_buf), // %[uv_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 "xmm0", "xmm0", "xmm1", + "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif // defined(HAS_P210TOARGBROW_AVX2) + +#if defined(HAS_P410TOARGBROW_AVX2) +// 16 pixels. +// 8 UV values upsampled to 16 UV, mixed with 16 Y producing 16 ARGB (64 bytes). +void OMITFP P410ToARGBRow_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile(YUVTORGB_SETUP_AVX2( + yuvconstants) "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + + LABELALIGN "1: \n" READP410_AVX2 YUVTORGB_AVX2( + yuvconstants) STOREARGB_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), // %[y_buf] + [uv_buf] "+r"(uv_buf), // %[uv_buf] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+rm"(width) // %[width] + : [yuvconstants] "r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 "xmm0", "xmm0", "xmm1", + "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif // defined(HAS_P410TOARGBROW_AVX2) + +#if defined(HAS_P210TOAR30ROW_AVX2) +// 16 pixels +// 16 UV values with 16 Y producing 16 AR30 (64 bytes). +void OMITFP P210ToAR30Row_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { asm volatile ( YUVTORGB_SETUP_AVX2(yuvconstants) - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" // all 1s + "vpsrlw $6,%%ymm5,%%ymm7 \n" + "vpsllw $4,%%ymm7,%%ymm7 \n" // 1023 * 16 for max + "vpsllw $14,%%ymm5,%%ymm5 \n" // 0xc000 for 2 alpha bits + "vpxor %%ymm6,%%ymm6,%%ymm6 \n" // 0 for min LABELALIGN - "1: \n" - READUYVY_AVX2 - YUVTORGB_AVX2(yuvconstants) - STOREARGB_AVX2 - "sub $0x10,%[width] \n" - "jg 1b \n" - "vzeroupper \n" - : [uyvy_buf]"+r"(uyvy_buf), // %[uyvy_buf] - [dst_argb]"+r"(dst_argb), // %[dst_argb] + "1: \n" + READP210_AVX2 + YUVTORGB16_AVX2(yuvconstants) + STOREAR30_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + + "vzeroupper \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [uv_buf]"+r"(uv_buf), // %[uv_buf] + [dst_ar30]"+r"(dst_ar30), // %[dst_ar30] [width]"+rm"(width) // %[width] - : [yuvconstants]"r"(yuvconstants), // %[yuvconstants] - [kShuffleUYVYY]"m"(kShuffleUYVYY), - [kShuffleUYVYUV]"m"(kShuffleUYVYUV) - : "memory", "cc", YUVTORGB_REGS_AVX2 - "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" ); - // clang-format on } -#endif // HAS_UYVYTOARGBROW_AVX2 +#endif // defined(HAS_P210TOAR30ROW_AVX2) + +#if defined(HAS_P410TOAR30ROW_AVX2) +// 16 pixels +// 16 UV values with 16 Y producing 16 AR30 (64 bytes). +void OMITFP P410ToAR30Row_AVX2(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile ( + YUVTORGB_SETUP_AVX2(yuvconstants) + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" // all 1s + "vpsrlw $6,%%ymm5,%%ymm7 \n" + "vpsllw $4,%%ymm7,%%ymm7 \n" // 1023 * 16 for max + "vpsllw $14,%%ymm5,%%ymm5 \n" // 0xc000 for 2 alpha bits + "vpxor %%ymm6,%%ymm6,%%ymm6 \n" // 0 for min + + LABELALIGN + "1: \n" + READP410_AVX2 + YUVTORGB16_AVX2(yuvconstants) + STOREAR30_AVX2 + "sub $0x10,%[width] \n" + "jg 1b \n" + + "vzeroupper \n" + : [y_buf]"+r"(y_buf), // %[y_buf] + [uv_buf]"+r"(uv_buf), // %[uv_buf] + [dst_ar30]"+r"(dst_ar30), // %[dst_ar30] + [width]"+rm"(width) // %[width] + : [yuvconstants]"r"(yuvconstants) // %[yuvconstants] + : "memory", "cc", YUVTORGB_REGS_AVX2 + "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" + ); +} +#endif // defined(HAS_P410TOAR30ROW_AVX2) #ifdef HAS_I400TOARGBROW_SSE2 -void I400ToARGBRow_SSE2(const uint8_t* y_buf, uint8_t* dst_argb, int width) { +void I400ToARGBRow_SSE2(const uint8_t* y_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { asm volatile( - "mov $0x4a354a35,%%eax \n" // 4a35 = 18997 = 1.164 - "movd %%eax,%%xmm2 \n" - "pshufd $0x0,%%xmm2,%%xmm2 \n" - "mov $0x04880488,%%eax \n" // 0488 = 1160 = 1.164 * - // 16 - "movd %%eax,%%xmm3 \n" - "pshufd $0x0,%%xmm3,%%xmm3 \n" - "pcmpeqb %%xmm4,%%xmm4 \n" - "pslld $0x18,%%xmm4 \n" + "movdqu 96(%3),%%xmm2 \n" // yg = 18997 = 1.164 + "movdqu 128(%3),%%xmm3 \n" // ygb = 1160 = 1.164 * 16 + "pcmpeqb %%xmm4,%%xmm4 \n" // 0xff000000 + "pslld $0x18,%%xmm4 \n" LABELALIGN - "1: \n" + "1: \n" // Step 1: Scale Y contribution to 8 G values. G = (y - 16) * 1.164 "movq (%0),%%xmm0 \n" "lea 0x8(%0),%0 \n" "punpcklbw %%xmm0,%%xmm0 \n" "pmulhuw %%xmm2,%%xmm0 \n" - "psubusw %%xmm3,%%xmm0 \n" - "psrlw $6, %%xmm0 \n" + "paddsw %%xmm3,%%xmm0 \n" + "psraw $6, %%xmm0 \n" "packuswb %%xmm0,%%xmm0 \n" // Step 2: Weave into ARGB @@ -3121,41 +6976,39 @@ void I400ToARGBRow_SSE2(const uint8_t* y_buf, uint8_t* dst_argb, int width) { "movdqu %%xmm1,0x10(%1) \n" "lea 0x20(%1),%1 \n" - "sub $0x8,%2 \n" + "subl $0x8,%2 \n" "jg 1b \n" - : "+r"(y_buf), // %0 - "+r"(dst_argb), // %1 - "+rm"(width) // %2 - : - : "memory", "cc", "eax", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); + : "+r"(y_buf), // %0 + "+r"(dst_argb), // %1 + "+rm"(width) // %2 + : "r"(yuvconstants) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); } #endif // HAS_I400TOARGBROW_SSE2 #ifdef HAS_I400TOARGBROW_AVX2 // 16 pixels of Y converted to 16 pixels of ARGB (64 bytes). // note: vpunpcklbw mutates and vpackuswb unmutates. -void I400ToARGBRow_AVX2(const uint8_t* y_buf, uint8_t* dst_argb, int width) { +void I400ToARGBRow_AVX2(const uint8_t* y_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { asm volatile( - "mov $0x4a354a35,%%eax \n" // 0488 = 1160 = 1.164 * - // 16 - "vmovd %%eax,%%xmm2 \n" - "vbroadcastss %%xmm2,%%ymm2 \n" - "mov $0x4880488,%%eax \n" // 4a35 = 18997 = 1.164 - "vmovd %%eax,%%xmm3 \n" - "vbroadcastss %%xmm3,%%ymm3 \n" - "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" - "vpslld $0x18,%%ymm4,%%ymm4 \n" + "vmovdqu 96(%3),%%ymm2 \n" // yg = 18997 = 1.164 + "vmovdqu 128(%3),%%ymm3 \n" // ygb = -1160 = 1.164*16 + "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" // 0xff000000 + "vpslld $0x18,%%ymm4,%%ymm4 \n" LABELALIGN - "1: \n" + "1: \n" // Step 1: Scale Y contribution to 16 G values. G = (y - 16) * 1.164 "vmovdqu (%0),%%xmm0 \n" "lea 0x10(%0),%0 \n" "vpermq $0xd8,%%ymm0,%%ymm0 \n" "vpunpcklbw %%ymm0,%%ymm0,%%ymm0 \n" "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" - "vpsubusw %%ymm3,%%ymm0,%%ymm0 \n" - "vpsrlw $0x6,%%ymm0,%%ymm0 \n" + "vpaddsw %%ymm3,%%ymm0,%%ymm0 \n" + "vpsraw $0x6,%%ymm0,%%ymm0 \n" "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" "vpunpcklbw %%ymm0,%%ymm0,%%ymm1 \n" "vpermq $0xd8,%%ymm1,%%ymm1 \n" @@ -3165,15 +7018,15 @@ void I400ToARGBRow_AVX2(const uint8_t* y_buf, uint8_t* dst_argb, int width) { "vpor %%ymm4,%%ymm1,%%ymm1 \n" "vmovdqu %%ymm0,(%1) \n" "vmovdqu %%ymm1,0x20(%1) \n" - "lea 0x40(%1),%1 \n" + "lea 0x40(%1),%1 \n" "sub $0x10,%2 \n" "jg 1b \n" "vzeroupper \n" - : "+r"(y_buf), // %0 - "+r"(dst_argb), // %1 - "+rm"(width) // %2 - : - : "memory", "cc", "eax", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); + : "+r"(y_buf), // %0 + "+r"(dst_argb), // %1 + "+rm"(width) // %2 + : "r"(yuvconstants) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); } #endif // HAS_I400TOARGBROW_AVX2 @@ -3183,107 +7036,582 @@ static const uvec8 kShuffleMirror = {15u, 14u, 13u, 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u}; void MirrorRow_SSSE3(const uint8_t* src, uint8_t* dst, int width) { - intptr_t temp_width = (intptr_t)(width); - asm volatile( + ptrdiff_t temp_width = (ptrdiff_t)(width); + asm volatile("movdqa %3,%%xmm5 \n" - "movdqa %3,%%xmm5 \n" - - LABELALIGN - "1: \n" - "movdqu -0x10(%0,%2,1),%%xmm0 \n" - "pshufb %%xmm5,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(temp_width) // %2 - : "m"(kShuffleMirror) // %3 - : "memory", "cc", "xmm0", "xmm5"); + LABELALIGN + "1: \n" + "movdqu -0x10(%0,%2,1),%%xmm0 \n" + "pshufb %%xmm5,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(temp_width) // %2 + : "m"(kShuffleMirror) // %3 + : "memory", "cc", "xmm0", "xmm5"); } #endif // HAS_MIRRORROW_SSSE3 -#ifdef HAS_MIRRORROW_AVX2 -void MirrorRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { - intptr_t temp_width = (intptr_t)(width); - asm volatile( +#if defined(HAS_MIRRORROW_AVX512BW) || \ + defined(HAS_MIRRORSPLITUVROW_AVX512BW) || \ + defined(HAS_MIRRORUVROW_AVX512BW) +static const uint16_t kMirrorUVPermute_AVX512[32] = { + 31u, 30u, 29u, 28u, 27u, 26u, 25u, 24u, 23u, 22u, 21u, + 20u, 19u, 18u, 17u, 16u, 15u, 14u, 13u, 12u, 11u, 10u, + 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u}; +#endif // defined(HAS_MIRRORROW_AVX512BW) || + // defined(HAS_MIRRORSPLITUVROW_AVX512BW) || + // defined(HAS_MIRRORUVROW_AVX512BW) - "vbroadcastf128 %3,%%ymm5 \n" +#ifdef HAS_MIRRORROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void MirrorRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + ptrdiff_t temp_width = (ptrdiff_t)(width); + uintptr_t temp; + asm volatile( + "vbroadcasti32x4 %[shuf],%%zmm5 \n" + "sub $0x40,%[width] \n" + "jl 2f \n" LABELALIGN - "1: \n" - "vmovdqu -0x20(%0,%2,1),%%ymm0 \n" - "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" - "vpermq $0x4e,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(temp_width) // %2 - : "m"(kShuffleMirror) // %3 - : "memory", "cc", "xmm0", "xmm5"); + "1: \n" + "vmovdqu8 (%[src],%[width],1),%%zmm0 \n" + "vpshufb %%zmm5,%%zmm0,%%zmm0 \n" + "vshufi64x2 $0x1b,%%zmm0,%%zmm0,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %[width],%[temp],%[temp] \n" + "kmovq %[temp],%%k1 \n" + "vmovdqu8 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vpsrlw $0x8,%%zmm0,%%zmm1 \n" + "vpsllw $0x8,%%zmm0,%%zmm0 \n" + "vporq %%zmm1,%%zmm0,%%zmm0 \n" + "mov $0x40,%k[temp] \n" + "sub %k[width],%k[temp] \n" + "shr $0x1,%k[temp] \n" + "vpbroadcastw %k[temp],%%zmm1 \n" + "vmovdqu16 %[rev],%%zmm2 \n" + "vpsubw %%zmm1,%%zmm2,%%zmm1 \n" + "vpermw %%zmm0,%%zmm1,%%zmm0 \n" + "test $0x1,%b[width] \n" + "je 3f \n" + "valignq $0x2,%%zmm0,%%zmm0,%%zmm1 \n" + "vpalignr $0x1,%%zmm0,%%zmm1,%%zmm0 \n" + "3: \n" + "vmovdqu8 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [dst] "+r"(dst), [width] "+r"(temp_width), [temp] "=&r"(temp) + : [src] "r"(src), [shuf] "m"(kShuffleMirror), + [rev] "m"(kMirrorUVPermute_AVX512) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm5", "k1"); +} +#endif // HAS_MIRRORROW_AVX512BW + +#ifdef HAS_MIRRORROW_AVX2 +void MirrorRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { + ptrdiff_t temp_width = (ptrdiff_t)(width); + asm volatile("vbroadcasti128 %3,%%ymm5 \n" + + LABELALIGN + "1: \n" + "vmovdqu -0x20(%0,%2,1),%%ymm0 \n" + "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" + "vpermq $0x4e,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(temp_width) // %2 + : "m"(kShuffleMirror) // %3 + : "memory", "cc", "xmm0", "xmm5"); } #endif // HAS_MIRRORROW_AVX2 -#ifdef HAS_MIRRORUVROW_SSSE3 +#if defined(HAS_MIRRORSPLITUVROW_SSSE3) || \ + defined(HAS_MIRRORSPLITUVROW_AVX2) || \ + defined(HAS_MIRRORSPLITUVROW_AVX512BW) // Shuffle table for reversing the bytes of UV channels. -static const uvec8 kShuffleMirrorUV = {14u, 12u, 10u, 8u, 6u, 4u, 2u, 0u, - 15u, 13u, 11u, 9u, 7u, 5u, 3u, 1u}; -void MirrorUVRow_SSSE3(const uint8_t* src, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - intptr_t temp_width = (intptr_t)(width); +static const uvec8 kShuffleMirrorSplitUV = {14u, 12u, 10u, 8u, 6u, 4u, 2u, 0u, + 15u, 13u, 11u, 9u, 7u, 5u, 3u, 1u}; +#endif // defined(HAS_MIRRORSPLITUVROW_SSSE3) || ... + +#ifdef HAS_MIRRORSPLITUVROW_SSSE3 +void MirrorSplitUVRow_SSSE3(const uint8_t* src, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + ptrdiff_t temp_width = (ptrdiff_t)(width); asm volatile( - "movdqa %4,%%xmm1 \n" - "lea -0x10(%0,%3,2),%0 \n" - "sub %1,%2 \n" + "movdqa %4,%%xmm1 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "lea -0x10(%0),%0 \n" - "pshufb %%xmm1,%%xmm0 \n" - "movlpd %%xmm0,(%1) \n" - "movhpd %%xmm0,0x00(%1,%2,1) \n" - "lea 0x8(%1),%1 \n" - "sub $8,%3 \n" - "jg 1b \n" - : "+r"(src), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+r"(temp_width) // %3 - : "m"(kShuffleMirrorUV) // %4 + "1: \n" + "movdqu -0x10(%0,%3,2),%%xmm0 \n" + "pshufb %%xmm1,%%xmm0 \n" + "movq %%xmm0,(%1) \n" + "movhps %%xmm0,0x00(%1,%2,1) \n" + "lea 0x8(%1),%1 \n" + "sub $0x8,%3 \n" + "jg 1b \n" + : "+r"(src), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(temp_width) // %3 + : "m"(kShuffleMirrorSplitUV) // %4 : "memory", "cc", "xmm0", "xmm1"); } +#endif // HAS_MIRRORSPLITUVROW_SSSE3 + +#ifdef HAS_MIRRORSPLITUVROW_AVX512BW +static const uint64_t kMirrorSplitUVPermute[8] = {6, 4, 2, 0, 7, 5, 3, 1}; + +LIBYUV_TARGET_AVX512BW +void MirrorSplitUVRow_AVX512BW(const uint8_t* src, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + ptrdiff_t temp_width = (ptrdiff_t)(width); + uintptr_t temp; + asm volatile( + "vbroadcasti32x4 %[shuf],%%zmm1 \n" + "sub %1,%2 \n" + "vmovdqu64 %[perm],%%zmm3 \n" + "sub $0x20,%3 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%0,%3,2),%%zmm0 \n" + "vpshufb %%zmm1,%%zmm0,%%zmm0 \n" + "vpermq %%zmm0,%%zmm3,%%zmm0 \n" + "vextracti64x4 $0x1,%%zmm0,%%ymm2 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm2,0x00(%1,%2,1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%3 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%3 \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q3,%[temp],%[temp] \n" + "kmovd %k[temp],%%k1 \n" + "vmovdqu16 (%0),%%zmm0%{%%k1%}%{z%} \n" + "mov $0x20,%k[temp] \n" + "sub %k3,%k[temp] \n" + "vpbroadcastw %k[temp],%%zmm2 \n" + "vmovdqu16 %[mirror_uv],%%zmm4 \n" + "vpsubw %%zmm2,%%zmm4,%%zmm2 \n" + "vpermw %%zmm0,%%zmm2,%%zmm0 \n" + "vpmovwb %%zmm0,(%1)%{%%k1%} \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpmovwb %%zmm0,0x00(%1,%2,1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(temp_width), // %3 + [temp] "=&r"(temp) // %[temp] + : [shuf] "m"(kShuffleMirrorSplitUV), // %[shuf] + [perm] "m"(kMirrorSplitUVPermute), // %[perm] + [mirror_uv] "m"(kMirrorUVPermute_AVX512) // %[mirror_uv] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "k1"); +} +#endif // HAS_MIRRORSPLITUVROW_AVX512BW + +#ifdef HAS_MIRRORSPLITUVROW_AVX2 +void MirrorSplitUVRow_AVX2(const uint8_t* src, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + ptrdiff_t temp_width = (ptrdiff_t)(width); + asm volatile( + "vbroadcasti128 %4,%%ymm1 \n" + "lea -0x20(%0,%3,2),%0 \n" + "sub %1,%2 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "lea -0x20(%0),%0 \n" + "vpshufb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0x72,%%ymm0,%%ymm0 \n" + "vextracti128 $0x1,%%ymm0,%%xmm2 \n" + "vmovdqu %%xmm0,(%1) \n" + "vmovdqu %%xmm2,0x00(%1,%2,1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(temp_width) // %3 + : "m"(kShuffleMirrorSplitUV) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2"); +} +#endif // HAS_MIRRORSPLITUVROW_AVX2 + +#ifdef HAS_MIRRORUVROW_SSSE3 +// Shuffle table for reversing the UV. +static const uvec8 kShuffleMirrorUV = {14u, 15u, 12u, 13u, 10u, 11u, 8u, 9u, + 6u, 7u, 4u, 5u, 2u, 3u, 0u, 1u}; + +void MirrorUVRow_SSSE3(const uint8_t* src_uv, uint8_t* dst_uv, int width) { + ptrdiff_t temp_width = (ptrdiff_t)(width); + asm volatile("movdqa %3,%%xmm5 \n" + + LABELALIGN + "1: \n" + "movdqu -0x10(%0,%2,2),%%xmm0 \n" + "pshufb %%xmm5,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(temp_width) // %2 + : "m"(kShuffleMirrorUV) // %3 + : "memory", "cc", "xmm0", "xmm5"); +} #endif // HAS_MIRRORUVROW_SSSE3 +#ifdef HAS_MIRRORUVROW_AVX2 +void MirrorUVRow_AVX2(const uint8_t* src_uv, uint8_t* dst_uv, int width) { + ptrdiff_t temp_width = (ptrdiff_t)(width); + asm volatile("vbroadcasti128 %3,%%ymm5 \n" + + LABELALIGN + "1: \n" + "vmovdqu -0x20(%0,%2,2),%%ymm0 \n" + "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" + "vpermq $0x4e,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(temp_width) // %2 + : "m"(kShuffleMirrorUV) // %3 + : "memory", "cc", "xmm0", "xmm5"); +} +#endif // HAS_MIRRORUVROW_AVX2 + +#ifdef HAS_MIRRORUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void MirrorUVRow_AVX512BW(const uint8_t* src_uv, uint8_t* dst_uv, int width) { + ptrdiff_t temp_width = (ptrdiff_t)(width); + uintptr_t temp; + asm volatile( + "vmovdqu16 %[rev],%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vpermw (%[src_uv],%[width],2),%%zmm5,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%[dst_uv]) \n" + "lea 0x40(%[dst_uv]),%[dst_uv] \n" + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $-1,%k[temp] \n" + "bzhi %k[width],%k[temp],%k[temp] \n" + "kmovd %k[temp],%%k1 \n" + "vmovdqu16 (%[src_uv]),%%zmm0%{%%k1%}%{z%}\n" + "mov $0x20,%k[temp] \n" + "sub %k[width],%k[temp] \n" + "vpbroadcastw %k[temp],%%zmm1 \n" + "vpsubw %%zmm1,%%zmm5,%%zmm1 \n" + "vpermw %%zmm0,%%zmm1,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%[dst_uv])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [dst_uv] "+r"(dst_uv), [width] "+r"(temp_width), [temp] "=&r"(temp) + : [src_uv] "r"(src_uv), [rev] "m"(kMirrorUVPermute_AVX512) + : "memory", "cc", "xmm0", "xmm1", "xmm5", "k1"); +} +#endif // HAS_MIRRORUVROW_AVX512BW + +#ifdef HAS_RGB24MIRRORROW_SSSE3 + +// Shuffle first 5 pixels to last 5 mirrored. first byte zero +static const uvec8 kShuffleMirrorRGB0 = {128u, 12u, 13u, 14u, 9u, 10u, 11u, 6u, + 7u, 8u, 3u, 4u, 5u, 0u, 1u, 2u}; + +// Shuffle last 5 pixels to first 5 mirrored. last byte zero +static const uvec8 kShuffleMirrorRGB1 = { + 13u, 14u, 15u, 10u, 11u, 12u, 7u, 8u, 9u, 4u, 5u, 6u, 1u, 2u, 3u, 128u}; + +// Shuffle 5 pixels at a time (15 bytes) +void RGB24MirrorRow_SSSE3(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width) { + ptrdiff_t temp_width = (ptrdiff_t)(width); + src_rgb24 += temp_width * 3 - 48; + asm volatile( + "movdqa %3,%%xmm4 \n" + "movdqa %4,%%xmm5 \n" + + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" // first 5 + "movdqu 15(%0),%%xmm1 \n" // next 5 + "movdqu 30(%0),%%xmm2 \n" // next 5 + "movdqu 32(%0),%%xmm3 \n" // last 1 special + "pshufb %%xmm4,%%xmm0 \n" + "pshufb %%xmm4,%%xmm1 \n" + "pshufb %%xmm4,%%xmm2 \n" + "pshufb %%xmm5,%%xmm3 \n" + "lea -0x30(%0),%0 \n" + "movdqu %%xmm0,32(%1) \n" // last 5 + "movdqu %%xmm1,17(%1) \n" // next 5 + "movdqu %%xmm2,2(%1) \n" // next 5 + "movlpd %%xmm3,0(%1) \n" // first 1 + "lea 0x30(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_rgb24), // %0 + "+r"(dst_rgb24), // %1 + "+r"(temp_width) // %2 + : "m"(kShuffleMirrorRGB0), // %3 + "m"(kShuffleMirrorRGB1) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif // HAS_RGB24MIRRORROW_SSSE3 + +#ifdef HAS_RGB24MIRRORROW_AVX2 +// Shuffle first 10 pixels to last 10 mirrored. first byte zero +static const uvec8 kShuffleMirrorRGB0_AVX = { + 128u, 12u, 13u, 14u, 9u, 10u, 11u, 6u, 7u, 8u, 3u, 4u, 5u, 0u, 1u, 2u}; + +// Shuffle last 2 pixels to first 2 mirrored. last byte zero +static const uvec8 kShuffleMirrorRGB1_AVX = { + 13u, 14u, 15u, 10u, 11u, 12u, 7u, 8u, 9u, 4u, 5u, 6u, 1u, 2u, 3u, 128u}; + +void RGB24MirrorRow_AVX2(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width) { + ptrdiff_t temp_width = (ptrdiff_t)(width); + src_rgb24 += temp_width * 3 - 96; + asm volatile( + "vbroadcasti128 %3,%%ymm4 \n" + "vmovdqa %4,%%xmm5 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" // first 10 + "vinserti128 $1,15(%0),%%ymm0,%%ymm0 \n" + "vmovdqu 30(%0),%%xmm1 \n" // next 10 + "vinserti128 $1,45(%0),%%ymm1,%%ymm1 \n" + "vmovdqu 60(%0),%%xmm2 \n" // next 10 + "vinserti128 $1,75(%0),%%ymm2,%%ymm2 \n" + "vmovdqu 80(%0),%%xmm3 \n" // last 2 special + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm4,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm4,%%ymm2,%%ymm2 \n" + "vpshufb %%xmm5,%%xmm3,%%xmm3 \n" + "lea -0x60(%0),%0 \n" + "vmovdqu %%xmm0,80(%1) \n" + "vextracti128 $1,%%ymm0,65(%1) \n" + "vmovdqu %%xmm1,50(%1) \n" + "vextracti128 $1,%%ymm1,35(%1) \n" + "vmovdqu %%xmm2,20(%1) \n" + "vextracti128 $1,%%ymm2,5(%1) \n" + "vmovq %%xmm3,0(%1) \n" + "lea 0x60(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_rgb24), // %0 + "+r"(dst_rgb24), // %1 + "+r"(temp_width) // %2 + : "m"(kShuffleMirrorRGB0_AVX), // %3 + "m"(kShuffleMirrorRGB1_AVX) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif // HAS_RGB24MIRRORROW_AVX2 + +#ifdef HAS_RGB24MIRRORROW_AVX512VBMI +// Mirror 64 RGB24 pixels (192 bytes = 3 zmm) per loop. Loads and stores are +// 3 full contiguous zmm vectors. Output vector 0 is a 2 source byte permute +// of input vectors 1 and 2, and output vectors 1 and 2 are 2 source byte +// permutes of input vectors 0 and 1. Output byte 65 (byte 1 of output +// vector 1) is the only byte that comes from a third vector: byte 0 of input +// vector 2, which is merged in with a masked broadcast. +static const uint8_t kPermMirrorRGB24_0[64] = { + 125u, 126u, 127u, 122u, 123u, 124u, 119u, 120u, 121u, 116u, 117u, + 118u, 113u, 114u, 115u, 110u, 111u, 112u, 107u, 108u, 109u, 104u, + 105u, 106u, 101u, 102u, 103u, 98u, 99u, 100u, 95u, 96u, 97u, + 92u, 93u, 94u, 89u, 90u, 91u, 86u, 87u, 88u, 83u, 84u, + 85u, 80u, 81u, 82u, 77u, 78u, 79u, 74u, 75u, 76u, 71u, + 72u, 73u, 68u, 69u, 70u, 65u, 66u, 67u, 62u}; +static const uint8_t kPermMirrorRGB24_1[64] = { + 127u, 128u, 123u, 124u, 125u, 120u, 121u, 122u, 117u, 118u, 119u, + 114u, 115u, 116u, 111u, 112u, 113u, 108u, 109u, 110u, 105u, 106u, + 107u, 102u, 103u, 104u, 99u, 100u, 101u, 96u, 97u, 98u, 93u, + 94u, 95u, 90u, 91u, 92u, 87u, 88u, 89u, 84u, 85u, 86u, + 81u, 82u, 83u, 78u, 79u, 80u, 75u, 76u, 77u, 72u, 73u, + 74u, 69u, 70u, 71u, 66u, 67u, 68u, 63u, 64u}; +static const uint8_t kPermMirrorRGB24_2[64] = { + 65u, 60u, 61u, 62u, 57u, 58u, 59u, 54u, 55u, 56u, 51u, 52u, 53u, + 48u, 49u, 50u, 45u, 46u, 47u, 42u, 43u, 44u, 39u, 40u, 41u, 36u, + 37u, 38u, 33u, 34u, 35u, 30u, 31u, 32u, 27u, 28u, 29u, 24u, 25u, + 26u, 21u, 22u, 23u, 18u, 19u, 20u, 15u, 16u, 17u, 12u, 13u, 14u, + 9u, 10u, 11u, 6u, 7u, 8u, 3u, 4u, 5u, 0u, 1u, 2u}; + +// Byte mask with the low n bits set, clamped to [0, 64]. +static inline uint64_t RGB24MirrorMask(int n) { + return n <= 0 ? 0ull : n >= 64 ? ~0ull : (1ull << n) - 1ull; +} + +LIBYUV_TARGET_AVX512VBMI +void RGB24MirrorRow_AVX512VBMI(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width) { + int r = width & 63; + ptrdiff_t temp_width = (ptrdiff_t)(width - r); + if (temp_width > 0) { + const uint8_t* src = src_rgb24 + (ptrdiff_t)width * 3 - 192; + asm volatile( + "vmovdqu8 %3,%%zmm20 \n" + "vmovdqu8 %4,%%zmm21 \n" + "vmovdqu8 %5,%%zmm22 \n" + "kmovq %6,%%k1 \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%0),%%zmm0 \n" // last 64 pixels + "vmovdqu8 0x40(%0),%%zmm1 \n" + "vmovdqu8 0x80(%0),%%zmm2 \n" + "lea -0xc0(%0),%0 \n" + "vmovdqa64 %%zmm20,%%zmm3 \n" + "vmovdqa64 %%zmm21,%%zmm4 \n" + "vmovdqa64 %%zmm22,%%zmm5 \n" + "vpermi2b %%zmm2,%%zmm1,%%zmm3 \n" // out0 from in1:in2 + "vpermi2b %%zmm1,%%zmm0,%%zmm4 \n" // out1 from in0:in1 + "vpermi2b %%zmm1,%%zmm0,%%zmm5 \n" // out2 from in0:in1 + "vpbroadcastb %%xmm2,%%zmm4%{%%k1%} \n" // out1 byte 1 = in2[0] + "vmovdqu8 %%zmm3,(%1) \n" + "vmovdqu8 %%zmm4,0x40(%1) \n" + "vmovdqu8 %%zmm5,0x80(%1) \n" + "lea 0xc0(%1),%1 \n" + "sub $0x40,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst_rgb24), // %1 + "+r"(temp_width) // %2 + : "m"(kPermMirrorRGB24_0), // %3 + "m"(kPermMirrorRGB24_1), // %4 + "m"(kPermMirrorRGB24_2), // %5 + "r"((uint64_t)2) // %6 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm20", "xmm21", "xmm22", "k1"); + } + // Remaining 1 to 63 pixels are the first r pixels of the source. Masked + // loads and stores access only the 3 * r valid bytes. The tables, as + // global byte offsets into a 192 byte block, are adjusted by the 192 - 3 * r + // missing bytes. Bytes from the third vector (index >= 128) are selected + // with a mask from the sign bit of the index. + if (r) { + int nb = r * 3; + int off = 192 - nb; + asm volatile( + "kmovq %2,%%k1 \n" + "kmovq %3,%%k2 \n" + "kmovq %4,%%k3 \n" + "vmovdqu8 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu8 0x40(%0),%%zmm1%{%%k2%}%{z%}\n" + "vmovdqu8 0x80(%0),%%zmm2%{%%k3%}%{z%}\n" + "vpbroadcastb %5,%%zmm6 \n" // off + "vpbroadcastb %6,%%zmm7 \n" // off - 64 + "vmovdqu8 %7,%%zmm3 \n" + "vmovdqu8 %8,%%zmm4 \n" + "vmovdqu8 %9,%%zmm5 \n" + "vpsubb %%zmm7,%%zmm3,%%zmm3 \n" + "vpsubb %%zmm6,%%zmm4,%%zmm4 \n" + "vpsubb %%zmm6,%%zmm5,%%zmm5 \n" + + "vpmovb2m %%zmm3,%%k4 \n" // out0 + "vmovdqa64 %%zmm3,%%zmm6 \n" + "vpermi2b %%zmm1,%%zmm0,%%zmm6 \n" + "vpermb %%zmm2,%%zmm3,%%zmm6%{%%k4%}\n" + "vmovdqu8 %%zmm6,(%1)%{%%k1%} \n" + "vpmovb2m %%zmm4,%%k4 \n" // out1 + "vmovdqa64 %%zmm4,%%zmm6 \n" + "vpermi2b %%zmm1,%%zmm0,%%zmm6 \n" + "vpermb %%zmm2,%%zmm4,%%zmm6%{%%k4%}\n" + "vmovdqu8 %%zmm6,0x40(%1)%{%%k2%} \n" + "vpmovb2m %%zmm5,%%k4 \n" // out2 + "vmovdqa64 %%zmm5,%%zmm6 \n" + "vpermi2b %%zmm1,%%zmm0,%%zmm6 \n" + "vpermb %%zmm2,%%zmm5,%%zmm6%{%%k4%}\n" + "vmovdqu8 %%zmm6,0x80(%1)%{%%k3%} \n" + "vzeroupper \n" + : + : "r"(src_rgb24), // %0 + "r"(dst_rgb24), // %1 + "r"(RGB24MirrorMask(nb)), // %2 + "r"(RGB24MirrorMask(nb - 64)), // %3 + "r"(RGB24MirrorMask(nb - 128)), // %4 + "r"(off), // %5 + "r"(off - 64), // %6 + "m"(kPermMirrorRGB24_0), // %7 + "m"(kPermMirrorRGB24_1), // %8 + "m"(kPermMirrorRGB24_2) // %9 + : "memory", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7", "k1", "k2", "k3", "k4"); + } +} +#endif // HAS_RGB24MIRRORROW_AVX512VBMI + #ifdef HAS_ARGBMIRRORROW_SSE2 void ARGBMirrorRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { - intptr_t temp_width = (intptr_t)(width); - asm volatile( + ptrdiff_t temp_width = (ptrdiff_t)(width); + asm volatile("lea -0x10(%0,%2,4),%0 \n" - "lea -0x10(%0,%2,4),%0 \n" - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "pshufd $0x1b,%%xmm0,%%xmm0 \n" - "lea -0x10(%0),%0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x4,%2 \n" - "jg 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(temp_width) // %2 - : - : "memory", "cc", "xmm0"); + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "pshufd $0x1b,%%xmm0,%%xmm0 \n" + "lea -0x10(%0),%0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x4,%2 \n" + "jg 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(temp_width) // %2 + : + : "memory", "cc", "xmm0"); } #endif // HAS_ARGBMIRRORROW_SSE2 @@ -3291,56 +7619,103 @@ void ARGBMirrorRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { // Shuffle table for reversing the bytes. static const ulvec32 kARGBShuffleMirror_AVX2 = {7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u}; void ARGBMirrorRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { - intptr_t temp_width = (intptr_t)(width); - asm volatile( + ptrdiff_t temp_width = (ptrdiff_t)(width); + asm volatile("vmovdqu %3,%%ymm5 \n" - "vmovdqu %3,%%ymm5 \n" - - LABELALIGN - "1: \n" - "vpermd -0x20(%0,%2,4),%%ymm5,%%ymm0 \n" - "vmovdqu %%ymm0,(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(temp_width) // %2 - : "m"(kARGBShuffleMirror_AVX2) // %3 - : "memory", "cc", "xmm0", "xmm5"); + LABELALIGN + "1: \n" + "vpermd -0x20(%0,%2,4),%%ymm5,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(temp_width) // %2 + : "m"(kARGBShuffleMirror_AVX2) // %3 + : "memory", "cc", "xmm0", "xmm5"); } #endif // HAS_ARGBMIRRORROW_AVX2 +#ifdef HAS_ARGBMIRRORROW_AVX512BW +static const uint32_t kARGBShuffleMirror_AVX512[16] = { + 15u, 14u, 13u, 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u}; + +// Mirror 16 ARGB pixels per loop. The remaining 1 to 15 pixels are at the +// start of src. They are loaded with a k mask, permuted with the reverse +// index minus (16 - remaining), and stored with the same k mask. +LIBYUV_TARGET_AVX512BW +void ARGBMirrorRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + ptrdiff_t temp_width = (ptrdiff_t)(width); + uintptr_t temp; + asm volatile( + "vmovdqu32 %4,%%zmm5 \n" + "sub $0x10,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vpermd (%0,%2,4),%%zmm5,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x10,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%2 \n" + "jle 99f \n" + "mov $-1,%k3 \n" + "bzhi %k2,%k3,%k3 \n" + "kmovw %k3,%%k1 \n" + "mov $0x10,%k3 \n" + "sub %k2,%k3 \n" + "vpbroadcastd %k3,%%zmm1 \n" + "vpsubd %%zmm1,%%zmm5,%%zmm1 \n" + "vmovdqu32 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpermd %%zmm0,%%zmm1,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(temp_width), // %2 + "=&r"(temp) // %3 + : "m"(kARGBShuffleMirror_AVX512) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm5", "k1"); +} +#endif // HAS_ARGBMIRRORROW_AVX512BW + #ifdef HAS_SPLITUVROW_AVX2 void SplitUVRow_AVX2(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, int width) { asm volatile( - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - "vpsrlw $0x8,%%ymm5,%%ymm5 \n" - "sub %1,%2 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsrlw $0x8,%%ymm5,%%ymm5 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpsrlw $0x8,%%ymm0,%%ymm2 \n" - "vpsrlw $0x8,%%ymm1,%%ymm3 \n" - "vpand %%ymm5,%%ymm0,%%ymm0 \n" - "vpand %%ymm5,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpackuswb %%ymm3,%%ymm2,%%ymm2 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm2,%%ymm2 \n" - "vmovdqu %%ymm0,(%1) \n" - "vmovdqu %%ymm2,0x00(%1,%2,1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%3 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpsrlw $0x8,%%ymm0,%%ymm2 \n" + "vpsrlw $0x8,%%ymm1,%%ymm3 \n" + "vpand %%ymm5,%%ymm0,%%ymm0 \n" + "vpand %%ymm5,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm3,%%ymm2,%%ymm2 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm2,%%ymm2 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm2,0x00(%1,%2,1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%3 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_uv), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -3350,34 +7725,100 @@ void SplitUVRow_AVX2(const uint8_t* src_uv, } #endif // HAS_SPLITUVROW_AVX2 +#ifdef HAS_SPLITUVROW_AVX512BW +static const uint64_t kSplitUVPermute[8] = {0, 2, 4, 6, 1, 3, 5, 7}; + +LIBYUV_TARGET_AVX512BW +void SplitUVRow_AVX512BW(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + uintptr_t temp; + asm volatile( + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "vpsrlw $0x8,%%zmm5,%%zmm5 \n" + "vmovdqu64 %[perm],%%zmm4 \n" + "sub %[dst_u],%[dst_v] \n" + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src_uv]),%%zmm0 \n" + "vmovdqu8 0x40(%[src_uv]),%%zmm1 \n" + "lea 0x80(%[src_uv]),%[src_uv] \n" + "vpsrlw $0x8,%%zmm0,%%zmm2 \n" + "vpsrlw $0x8,%%zmm1,%%zmm3 \n" + "vpandd %%zmm5,%%zmm0,%%zmm0 \n" + "vpandd %%zmm5,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm3,%%zmm2,%%zmm2 \n" + "vpermq %%zmm0,%%zmm4,%%zmm0 \n" + "vpermq %%zmm2,%%zmm4,%%zmm2 \n" + "vmovdqu8 %%zmm0,(%[dst_u]) \n" + "vmovdqu8 %%zmm2,(%[dst_u],%[dst_v],1) \n" + "lea 0x40(%[dst_u]),%[dst_u] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovq %[temp],%%k1 \n" + "kshiftrq $32,%%k1,%%k2 \n" + "vmovdqu16 (%[src_uv]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 0x40(%[src_uv]),%%zmm1%{%%k2%}%{z%} \n" + "vpsrlw $0x8,%%zmm0,%%zmm2 \n" + "vpsrlw $0x8,%%zmm1,%%zmm3 \n" + "vpandd %%zmm5,%%zmm0,%%zmm0 \n" + "vpandd %%zmm5,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm3,%%zmm2,%%zmm2 \n" + "vpermq %%zmm0,%%zmm4,%%zmm0 \n" + "vpermq %%zmm2,%%zmm4,%%zmm2 \n" + "vmovdqu8 %%zmm0,(%[dst_u])%{%%k1%} \n" + "vmovdqu8 %%zmm2,(%[dst_u],%[dst_v],1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src_uv] "+r"(src_uv), [dst_u] "+r"(dst_u), [dst_v] "+r"(dst_v), + [width] "+r"(width), [temp] "=&r"(temp) + : [perm] "m"(kSplitUVPermute) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "k1", + "k2"); +} +#endif // HAS_SPLITUVROW_AVX512BW + #ifdef HAS_SPLITUVROW_SSE2 void SplitUVRow_SSE2(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, int width) { asm volatile( - "pcmpeqb %%xmm5,%%xmm5 \n" - "psrlw $0x8,%%xmm5 \n" - "sub %1,%2 \n" + "pcmpeqb %%xmm5,%%xmm5 \n" + "psrlw $0x8,%%xmm5 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "movdqa %%xmm0,%%xmm2 \n" - "movdqa %%xmm1,%%xmm3 \n" - "pand %%xmm5,%%xmm0 \n" - "pand %%xmm5,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "psrlw $0x8,%%xmm2 \n" - "psrlw $0x8,%%xmm3 \n" - "packuswb %%xmm3,%%xmm2 \n" - "movdqu %%xmm0,(%1) \n" - "movdqu %%xmm2,0x00(%1,%2,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%3 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "movdqa %%xmm0,%%xmm2 \n" + "movdqa %%xmm1,%%xmm3 \n" + "pand %%xmm5,%%xmm0 \n" + "pand %%xmm5,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "psrlw $0x8,%%xmm2 \n" + "psrlw $0x8,%%xmm3 \n" + "packuswb %%xmm3,%%xmm2 \n" + "movdqu %%xmm0,(%1) \n" + "movdqu %%xmm2,0x00(%1,%2,1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%3 \n" + "jg 1b \n" : "+r"(src_uv), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -3387,36 +7828,287 @@ void SplitUVRow_SSE2(const uint8_t* src_uv, } #endif // HAS_SPLITUVROW_SSE2 +#ifdef HAS_DETILEROW_AVX2 +void DetileRow_AVX2(const uint8_t* src, + ptrdiff_t src_tile_stride, + uint8_t* dst, + int width) { + asm volatile( + "sub $0x20,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" + "vinserti128 $0x1,(%0,%3,1),%%ymm0,%%ymm0 \n" + "lea (%0,%3,2),%0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "vmovdqu (%0),%%xmm0 \n" + "vmovdqu %%xmm0,(%1) \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "r"(src_tile_stride) // %3 + : "memory", "cc", "xmm0"); +} +#endif // HAS_DETILEROW_AVX2 + +#ifdef HAS_DETILEROW_16_AVX2 +void DetileRow_16_AVX2(const uint16_t* src, + ptrdiff_t src_tile_stride, + uint16_t* dst, + int width) { + asm volatile( + "sub $0x20,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu (%0,%3,2),%%ymm1 \n" + "lea (%0,%3,4),%0 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x20,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "r"(src_tile_stride) // %3 + : "memory", "cc", "xmm0", "xmm1"); +} +#endif // HAS_DETILEROW_16_AVX2 + +#ifdef HAS_DETILETOYUY2_AVX2 +// Read 32 Y, 16 UV, and write 16 YUYV (64 bytes). +void DetileToYUY2_AVX2(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width) { + asm volatile( + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" + "vinserti128 $0x1,(%0,%4,1),%%ymm0,%%ymm0 \n" + "lea (%0,%4,2),%0 \n" + "vmovdqu (%1),%%xmm1 \n" + "vinserti128 $0x1,(%1,%5,1),%%ymm1,%%ymm1 \n" + "lea (%1,%5,2),%1 \n" + "vpunpcklbw %%ymm1,%%ymm0,%%ymm2 \n" + "vpunpckhbw %%ymm1,%%ymm0,%%ymm3 \n" + "vperm2i128 $0x20,%%ymm3,%%ymm2,%%ymm0 \n" + "vperm2i128 $0x31,%%ymm3,%%ymm2,%%ymm1 \n" + "vmovdqu %%ymm0,(%2) \n" + "vmovdqu %%ymm1,0x20(%2) \n" + "lea 0x40(%2),%2 \n" + "subl $0x20,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(src_uv), // %1 + "+r"(dst_yuy2), // %2 + "+rm"(width) // %3 + : "r"(src_y_tile_stride), // %4 + "r"(src_uv_tile_stride) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); +} +#endif // HAS_DETILETOYUY2_AVX2 + +#ifdef HAS_UNPACKMT2T_AVX2 +void UnpackMT2T_AVX2(const uint8_t* src, uint16_t* dst, size_t size) { + static const uint32_t kMaskC0 = 0xc0c0c0c0u; + if (size >= 80) { + asm volatile( + "vpbroadcastd %[c0],%%ymm6 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[src]),%%xmm0 \n" + "vpsllw $2,%%xmm0,%%xmm1 \n" + "vinserti128 $0x1,%%xmm0,%%ymm1,%%ymm1 \n" + "vpsllw $4,%%ymm1,%%ymm0 \n" + "vpand %%ymm6,%%ymm0,%%ymm0 \n" + "vpand %%ymm6,%%ymm1,%%ymm1 \n" + "vmovdqu 0x10(%[src]),%%ymm2 \n" + "vmovdqu 0x30(%[src]),%%ymm3 \n" + "lea 0x50(%[src]),%[src] \n" + "vpsrlw $2,%%ymm2,%%ymm4 \n" + "vpsrlw $2,%%ymm3,%%ymm5 \n" + "vpandn %%ymm4,%%ymm6,%%ymm4 \n" + "vpandn %%ymm5,%%ymm6,%%ymm5 \n" + "vpor %%ymm4,%%ymm0,%%ymm0 \n" + "vpor %%ymm5,%%ymm1,%%ymm1 \n" + + "vpunpcklbw %%ymm2,%%ymm0,%%ymm4 \n" + "vpunpckhbw %%ymm2,%%ymm0,%%ymm5 \n" + "vperm2i128 $0x20,%%ymm5,%%ymm4,%%ymm0 \n" + "vperm2i128 $0x31,%%ymm5,%%ymm4,%%ymm2 \n" + "vmovdqu %%ymm0,(%[dst]) \n" + "vmovdqu %%ymm2,0x20(%[dst]) \n" + + "vpunpcklbw %%ymm3,%%ymm1,%%ymm4 \n" + "vpunpckhbw %%ymm3,%%ymm1,%%ymm5 \n" + "vperm2i128 $0x20,%%ymm5,%%ymm4,%%ymm1 \n" + "vperm2i128 $0x31,%%ymm5,%%ymm4,%%ymm3 \n" + "vmovdqu %%ymm1,0x40(%[dst]) \n" + "vmovdqu %%ymm3,0x60(%[dst]) \n" + + "lea 0x80(%[dst]),%[dst] \n" + "sub $0x50,%[size] \n" + "cmp $0x50,%[size] \n" + "jae 1b \n" + "vzeroupper \n" + : [src] "+r"(src), [dst] "+r"(dst), [size] "+r"(size) + : [c0] "m"(kMaskC0) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6"); + } +} +#endif // HAS_UNPACKMT2T_AVX2 + +#ifdef HAS_DETILESPLITUVROW_AVX2 +static const uvec8 kDeinterlaceUV = {0, 2, 4, 6, 8, 10, 12, 14, + 1, 3, 5, 7, 9, 11, 13, 15}; + +void DetileSplitUVRow_AVX2(const uint8_t* src_uv, + ptrdiff_t src_tile_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + asm volatile( + "vbroadcasti128 %4,%%ymm1 \n" + "sub $0x20,%3 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" + "vinserti128 $0x1,(%0,%5,1),%%ymm0,%%ymm0 \n" + "lea (%0,%5,2),%0 \n" + "vpshufb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "vextracti128 $0x1,%%ymm0,(%2) \n" + "lea 0x10(%2),%2 \n" + "sub $0x20,%3 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%3 \n" + "jle 99f \n" + "vmovdqu (%0),%%xmm0 \n" + "vpshufb %%xmm1,%%xmm0,%%xmm0 \n" + "vmovq %%xmm0,(%1) \n" + "vmovhps %%xmm0,(%2) \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_uv), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "m"(kDeinterlaceUV), // %4 + "r"(src_tile_stride) // %5 + : "memory", "cc", "xmm0", "xmm1"); +} +#endif // HAS_DETILESPLITUVROW_AVX2 + +#ifdef HAS_MERGEUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void MergeUVRow_AVX512BW(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width) { + uintptr_t temp; + asm volatile( + "sub %0,%1 \n" + "sub $0x20,%3 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vpmovzxbw (%0),%%zmm0 \n" + "vpmovzxbw 0x00(%0,%1,1),%%zmm1 \n" + "lea 0x20(%0),%0 \n" + "vpsllw $0x8,%%zmm1,%%zmm1 \n" + "vporq %%zmm0,%%zmm1,%%zmm2 \n" + "vmovdqu16 %%zmm2,(%2) \n" + "lea 0x40(%2),%2 \n" + "sub $0x20,%3 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%3 \n" + "jle 99f \n" + "mov $-1,%k[temp] \n" + "bzhi %k3,%k[temp],%k[temp] \n" + "kmovd %k[temp],%%k1 \n" + "vpmovzxbw (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpmovzxbw 0x00(%0,%1,1),%%zmm1%{%%k1%}%{z%} \n" + "vpsllw $0x8,%%zmm1,%%zmm1 \n" + "vporq %%zmm0,%%zmm1,%%zmm2 \n" + "vmovdqu16 %%zmm2,(%2)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_u), // %0 + "+r"(src_v), // %1 + "+r"(dst_uv), // %2 + "+r"(width), // %3 + [temp] "=&r"(temp) // %[temp] + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "k1"); +} +#endif // HAS_MERGEUVROW_AVX512BW + #ifdef HAS_MERGEUVROW_AVX2 void MergeUVRow_AVX2(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width) { - asm volatile( + asm volatile("sub %0,%1 \n" - "sub %0,%1 \n" - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x00(%0,%1,1),%%ymm1 \n" - "lea 0x20(%0),%0 \n" - "vpunpcklbw %%ymm1,%%ymm0,%%ymm2 \n" - "vpunpckhbw %%ymm1,%%ymm0,%%ymm0 \n" - "vextractf128 $0x0,%%ymm2,(%2) \n" - "vextractf128 $0x0,%%ymm0,0x10(%2) \n" - "vextractf128 $0x1,%%ymm2,0x20(%2) \n" - "vextractf128 $0x1,%%ymm0,0x30(%2) \n" - "lea 0x40(%2),%2 \n" - "sub $0x20,%3 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_u), // %0 - "+r"(src_v), // %1 - "+r"(dst_uv), // %2 - "+r"(width) // %3 - : - : "memory", "cc", "xmm0", "xmm1", "xmm2"); + LABELALIGN + "1: \n" + "vpmovzxbw (%0),%%ymm0 \n" + "vpmovzxbw 0x00(%0,%1,1),%%ymm1 \n" + "lea 0x10(%0),%0 \n" + "vpsllw $0x8,%%ymm1,%%ymm1 \n" + "vpor %%ymm0,%%ymm1,%%ymm2 \n" + "vmovdqu %%ymm2,(%2) \n" + "lea 0x20(%2),%2 \n" + "sub $0x10,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_u), // %0 + "+r"(src_v), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } #endif // HAS_MERGEUVROW_AVX2 @@ -3425,78 +8117,185 @@ void MergeUVRow_SSE2(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width) { - asm volatile( + asm volatile("sub %0,%1 \n" - "sub %0,%1 \n" - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x00(%0,%1,1),%%xmm1 \n" - "lea 0x10(%0),%0 \n" - "movdqa %%xmm0,%%xmm2 \n" - "punpcklbw %%xmm1,%%xmm0 \n" - "punpckhbw %%xmm1,%%xmm2 \n" - "movdqu %%xmm0,(%2) \n" - "movdqu %%xmm2,0x10(%2) \n" - "lea 0x20(%2),%2 \n" - "sub $0x10,%3 \n" - "jg 1b \n" - : "+r"(src_u), // %0 - "+r"(src_v), // %1 - "+r"(dst_uv), // %2 - "+r"(width) // %3 - : - : "memory", "cc", "xmm0", "xmm1", "xmm2"); + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x00(%0,%1,1),%%xmm1 \n" + "lea 0x10(%0),%0 \n" + "movdqa %%xmm0,%%xmm2 \n" + "punpcklbw %%xmm1,%%xmm0 \n" + "punpckhbw %%xmm1,%%xmm2 \n" + "movdqu %%xmm0,(%2) \n" + "movdqu %%xmm2,0x10(%2) \n" + "lea 0x20(%2),%2 \n" + "sub $0x10,%3 \n" + "jg 1b \n" + : "+r"(src_u), // %0 + "+r"(src_v), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } #endif // HAS_MERGEUVROW_SSE2 -// Use scale to convert lsb formats to msb, depending how many bits there are: -// 128 = 9 bits -// 64 = 10 bits -// 16 = 12 bits -// 1 = 16 bits #ifdef HAS_MERGEUVROW_16_AVX2 void MergeUVRow_16_AVX2(const uint16_t* src_u, const uint16_t* src_v, uint16_t* dst_uv, - int scale, + int depth, int width) { - // clang-format off - asm volatile ( - "vmovd %4,%%xmm3 \n" - "vpunpcklwd %%xmm3,%%xmm3,%%xmm3 \n" - "vbroadcastss %%xmm3,%%ymm3 \n" - "sub %0,%1 \n" + asm volatile( + "vmovd %4,%%xmm3 \n" + "vmovd %5,%%xmm4 \n" - // 16 pixels per loop. - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu (%0,%1,1),%%ymm1 \n" - "add $0x20,%0 \n" + "sub %0,%1 \n" + // 8 pixels per loop. - "vpmullw %%ymm3,%%ymm0,%%ymm0 \n" - "vpmullw %%ymm3,%%ymm1,%%ymm1 \n" - "vpunpcklwd %%ymm1,%%ymm0,%%ymm2 \n" // mutates - "vpunpckhwd %%ymm1,%%ymm0,%%ymm0 \n" - "vextractf128 $0x0,%%ymm2,(%2) \n" - "vextractf128 $0x0,%%ymm0,0x10(%2) \n" - "vextractf128 $0x1,%%ymm2,0x20(%2) \n" - "vextractf128 $0x1,%%ymm0,0x30(%2) \n" - "add $0x40,%2 \n" - "sub $0x10,%3 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_u), // %0 - "+r"(src_v), // %1 - "+r"(dst_uv), // %2 - "+r"(width) // %3 - : "r"(scale) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); - // clang-format on + LABELALIGN + "1: \n" + "vpmovzxwd (%0),%%ymm0 \n" + "vpmovzxwd 0x00(%0,%1,1),%%ymm1 \n" + "lea 0x10(%0),%0 \n" + "vpsllw %%xmm3,%%ymm0,%%ymm0 \n" + "vpslld %%xmm4,%%ymm1,%%ymm1 \n" + "vpor %%ymm0,%%ymm1,%%ymm2 \n" + "vmovdqu %%ymm2,(%2) \n" + "lea 0x20(%2),%2 \n" + "sub $0x8,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_u), // %0 + "+r"(src_v), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : "r"(16 - depth), // %4 + "r"(32 - depth) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); } -#endif // HAS_MERGEUVROW_AVX2 +#endif // HAS_MERGEUVROW_16_AVX2 + +#ifdef HAS_MERGEUVROW_16_AVX512BW +LIBYUV_TARGET_AVX512BW +void MergeUVRow_16_AVX512BW(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width) { + uintptr_t temp; + asm volatile( + "vmovd %[shift_u],%%xmm3 \n" + "vmovd %[shift_v],%%xmm4 \n" + "sub %0,%1 \n" + "sub $0x20,%3 \n" + "jl 2f \n" + + // 32 pixels per loop. + LABELALIGN + "1: \n" + "vpmovzxwd (%0),%%zmm0 \n" + "vpmovzxwd 0x20(%0),%%zmm2 \n" + "vpmovzxwd 0x00(%0,%1,1),%%zmm1 \n" + "vpmovzxwd 0x20(%0,%1,1),%%zmm5 \n" + "lea 0x40(%0),%0 \n" + "vpsllw %%xmm3,%%zmm0,%%zmm0 \n" + "vpsllw %%xmm3,%%zmm2,%%zmm2 \n" + "vpslld %%xmm4,%%zmm1,%%zmm1 \n" + "vpslld %%xmm4,%%zmm5,%%zmm5 \n" + "vpord %%zmm0,%%zmm1,%%zmm0 \n" + "vpord %%zmm2,%%zmm5,%%zmm2 \n" + "vmovdqu32 %%zmm0,(%2) \n" + "vmovdqu32 %%zmm2,0x40(%2) \n" + "lea 0x80(%2),%2 \n" + "sub $0x20,%3 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%3 \n" + "jle 99f \n" + "cmp $0x10,%3 \n" + "jl 3f \n" + "vpmovzxwd (%0),%%zmm0 \n" + "vpmovzxwd 0x00(%0,%1,1),%%zmm1 \n" + "lea 0x20(%0),%0 \n" + "vpsllw %%xmm3,%%zmm0,%%zmm0 \n" + "vpslld %%xmm4,%%zmm1,%%zmm1 \n" + "vpord %%zmm0,%%zmm1,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%2) \n" + "lea 0x40(%2),%2 \n" + "sub $0x10,%3 \n" + "jle 99f \n" + + "3: \n" + "mov $-1,%k[temp] \n" + "bzhi %k3,%k[temp],%k[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vpmovzxwd (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpmovzxwd 0x00(%0,%1,1),%%zmm1%{%%k1%}%{z%} \n" + "vpsllw %%xmm3,%%zmm0,%%zmm0 \n" + "vpslld %%xmm4,%%zmm1,%%zmm1 \n" + "vpord %%zmm0,%%zmm1,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%2)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_u), // %0 + "+r"(src_v), // %1 + "+r"(dst_uv), // %2 + "+r"(width), // %3 + [temp] "=&r"(temp) // %[temp] + : [shift_u] "r"(16 - depth), // %[shift_u] + [shift_v] "r"(32 - depth) // %[shift_v] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "k1"); +} +#endif // HAS_MERGEUVROW_16_AVX512BW + +#ifdef HAS_SPLITUVROW_16_AVX2 +const uvec8 kSplitUVShuffle16 = {0, 1, 4, 5, 8, 9, 12, 13, + 2, 3, 6, 7, 10, 11, 14, 15}; +void SplitUVRow_16_AVX2(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width) { + depth = 16 - depth; + asm volatile( + "vmovd %4,%%xmm3 \n" + "vbroadcasti128 %5,%%ymm4 \n" + "sub %1,%2 \n" + + // 16 pixels per loop. + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "add $0x40,%0 \n" + + "vpsrlw %%xmm3,%%ymm0,%%ymm0 \n" + "vpsrlw %%xmm3,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm4,%%ymm1,%%ymm1 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vextractf128 $0x0,%%ymm0,(%1) \n" + "vextractf128 $0x0,%%ymm1,0x10(%1) \n" + "vextractf128 $0x1,%%ymm0,(%1,%2) \n" + "vextractf128 $0x1,%%ymm1,0x10(%1,%2) \n" + "add $0x20,%1 \n" + "sub $0x10,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_uv), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"(depth), // %4 + "m"(kSplitUVShuffle16) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif // HAS_SPLITUVROW_16_AVX2 // Use scale to convert lsb formats to msb, depending how many bits there are: // 128 = 9 bits @@ -3508,212 +8307,903 @@ void MultiplyRow_16_AVX2(const uint16_t* src_y, uint16_t* dst_y, int scale, int width) { - // clang-format off - asm volatile ( - "vmovd %3,%%xmm3 \n" - "vpunpcklwd %%xmm3,%%xmm3,%%xmm3 \n" - "vbroadcastss %%xmm3,%%ymm3 \n" - "sub %0,%1 \n" + asm volatile( + "vmovd %3,%%xmm3 \n" + "vpbroadcastw %%xmm3,%%ymm3 \n" + "sub %0,%1 \n" - // 16 pixels per loop. - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vpmullw %%ymm3,%%ymm0,%%ymm0 \n" - "vpmullw %%ymm3,%%ymm1,%%ymm1 \n" - "vmovdqu %%ymm0,(%0,%1) \n" - "vmovdqu %%ymm1,0x20(%0,%1) \n" - "add $0x40,%0 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_y), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : "r"(scale) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm3"); - // clang-format on + // 32 pixels per loop. + LABELALIGN + "1: \n" + "vpmullw (%0),%%ymm3,%%ymm0 \n" + "vpmullw 0x20(%0),%%ymm3,%%ymm1 \n" + "vmovdqu %%ymm0,(%0,%1) \n" + "vmovdqu %%ymm1,0x20(%0,%1) \n" + "add $0x40,%0 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(scale) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm3"); } #endif // HAS_MULTIPLYROW_16_AVX2 +#ifdef HAS_MULTIPLYROW_16_AVX512BW +LIBYUV_TARGET_AVX512BW +void MultiplyRow_16_AVX512BW(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + uintptr_t temp; + asm volatile( + "vpbroadcastw %[scale],%%zmm2 \n" + "sub $0x40,%2 \n" + "jl 2f \n" + + // 64 pixels per loop. + LABELALIGN + "1: \n" + "vpmullw (%0),%%zmm2,%%zmm0 \n" + "vpmullw 0x40(%0),%%zmm2,%%zmm1 \n" + "lea 0x80(%0),%0 \n" + "vmovdqu16 %%zmm0,(%1) \n" + "vmovdqu16 %%zmm1,0x40(%1) \n" + "lea 0x80(%1),%1 \n" + "sub $0x40,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%2 \n" + "jle 99f \n" + "cmp $0x20,%2 \n" + "jl 3f \n" + "vpmullw (%0),%%zmm2,%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vmovdqu16 %%zmm0,(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x20,%2 \n" + "jle 99f \n" + + "3: \n" + "mov $-1,%k[temp] \n" + "bzhi %k2,%k[temp],%k[temp] \n" + "kmovd %k[temp],%%k1 \n" + "vmovdqu16 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpmullw %%zmm2,%%zmm0,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : [scale] "r"(scale) // %[scale] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "k1"); +} +#endif // HAS_MULTIPLYROW_16_AVX512BW + +// Use scale to convert msb formats to lsb, depending how many bits there are: +// 512 = 9 bits +// 1024 = 10 bits +// 4096 = 12 bits +// 65536 = 16 bits +#ifdef HAS_DIVIDEROW_16_AVX2 +void DivideRow_16_AVX2(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + if (scale == 65536) { // Divide by 1, so do memcpy. + if (src_y != dst_y) { + memcpy(dst_y, src_y, (size_t)width * 2); + } + return; + } + asm volatile( + "vmovd %3,%%xmm3 \n" + "vpbroadcastw %%xmm3,%%ymm3 \n" + "sub %0,%1 \n" + + // 32 pixels per loop. + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vpmulhuw %%ymm3,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm3,%%ymm1,%%ymm1 \n" + "vmovdqu %%ymm0,(%0,%1) \n" + "vmovdqu %%ymm1,0x20(%0,%1) \n" + "add $0x40,%0 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width), // %2 + "+r"(scale) // %3 + : + : "memory", "cc", "xmm0", "xmm1", "xmm3"); +} +#endif // HAS_DIVIDEROW_16_AVX2 + +#ifdef HAS_DIVIDEROW_16_AVX512BW +LIBYUV_TARGET_AVX512BW +void DivideRow_16_AVX512BW(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + if (scale == 65536) { // Divide by 1, so do memcpy. + if (src_y != dst_y) { + memcpy(dst_y, src_y, (size_t)width * 2); + } + return; + } + uintptr_t temp; + asm volatile( + "vpbroadcastw %[scale],%%zmm2 \n" + "sub $0x40,%2 \n" + "jl 2f \n" + + // 64 pixels per loop. + LABELALIGN + "1: \n" + "vpmulhuw (%0),%%zmm2,%%zmm0 \n" + "vpmulhuw 0x40(%0),%%zmm2,%%zmm1 \n" + "lea 0x80(%0),%0 \n" + "vmovdqu16 %%zmm0,(%1) \n" + "vmovdqu16 %%zmm1,0x40(%1) \n" + "lea 0x80(%1),%1 \n" + "sub $0x40,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%2 \n" + "jle 99f \n" + "cmp $0x20,%2 \n" + "jl 3f \n" + "vpmulhuw (%0),%%zmm2,%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vmovdqu16 %%zmm0,(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x20,%2 \n" + "jle 99f \n" + + "3: \n" + "mov $-1,%k[temp] \n" + "bzhi %k2,%k[temp],%k[temp] \n" + "kmovd %k[temp],%%k1 \n" + "vmovdqu16 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpmulhuw %%zmm2,%%zmm0,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : [scale] "r"(scale) // %[scale] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "k1"); +} +#endif // HAS_DIVIDEROW_16_AVX512BW + // Use scale to convert lsb formats to msb, depending how many bits there are: // 32768 = 9 bits // 16384 = 10 bits // 4096 = 12 bits // 256 = 16 bits +#ifdef HAS_CONVERT16TO8ROW_SSSE3 void Convert16To8Row_SSSE3(const uint16_t* src_y, uint8_t* dst_y, int scale, int width) { - // clang-format off - asm volatile ( - "movd %3,%%xmm2 \n" - "punpcklwd %%xmm2,%%xmm2 \n" - "pshufd $0x0,%%xmm2,%%xmm2 \n" + asm volatile( + "movd %3,%%xmm2 \n" + "punpcklwd %%xmm2,%%xmm2 \n" + "pshufd $0x0,%%xmm2,%%xmm2 \n" - // 32 pixels per loop. - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "add $0x20,%0 \n" - "pmulhuw %%xmm2,%%xmm0 \n" - "pmulhuw %%xmm2,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "add $0x10,%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_y), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : "r"(scale) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2"); - // clang-format on + // 16 pixels per loop. + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "add $0x20,%0 \n" + "pmulhuw %%xmm2,%%xmm0 \n" + "pmulhuw %%xmm2,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "add $0x10,%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(scale) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } +#endif // HAS_CONVERT16TO8ROW_SSSE3 #ifdef HAS_CONVERT16TO8ROW_AVX2 void Convert16To8Row_AVX2(const uint16_t* src_y, uint8_t* dst_y, int scale, int width) { - // clang-format off - asm volatile ( - "vmovd %3,%%xmm2 \n" - "vpunpcklwd %%xmm2,%%xmm2,%%xmm2 \n" - "vbroadcastss %%xmm2,%%ymm2 \n" + asm volatile( + "vmovd %3,%%xmm2 \n" + "vpbroadcastw %%xmm2,%%ymm2 \n" - // 32 pixels per loop. - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "add $0x40,%0 \n" - "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" - "vpmulhuw %%ymm2,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" // mutates - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,(%1) \n" - "add $0x20,%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_y), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : "r"(scale) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2"); - // clang-format on + // 32 pixels per loop. + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "add $0x40,%0 \n" + "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm2,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" // mutates + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "add $0x20,%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(scale) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } #endif // HAS_CONVERT16TO8ROW_AVX2 +#ifdef HAS_CONVERT16TO8ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void Convert16To8Row_AVX512BW(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width) { + uintptr_t temp; + asm volatile( + "vpbroadcastw %[scale],%%zmm2 \n" + "sub $0x40,%2 \n" + "jl 2f \n" + + // 64 pixels per loop. + LABELALIGN + "1: \n" + "vmovdqu16 (%0),%%zmm0 \n" + "vmovdqu16 0x40(%0),%%zmm1 \n" + "lea 0x80(%0),%0 \n" + "vpmulhuw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm2,%%zmm1,%%zmm1 \n" + "vpmovuswb %%zmm0,%%ymm0 \n" + "vpmovuswb %%zmm1,%%ymm1 \n" + "vmovdqu8 %%ymm0,(%1) \n" + "vmovdqu8 %%ymm1,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x40,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%2 \n" + "jle 99f \n" + "cmp $0x20,%2 \n" + "jl 3f \n" + "vmovdqu16 (%0),%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vpmulhuw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmovuswb %%zmm0,%%ymm0 \n" + "vmovdqu8 %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jle 99f \n" + + "3: \n" + "mov $-1,%k[temp] \n" + "bzhi %k2,%k[temp],%k[temp] \n" + "kmovd %k[temp],%%k1 \n" + "vmovdqu16 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpmulhuw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmovuswb %%zmm0,%%ymm0 \n" + "vmovdqu8 %%ymm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : [scale] "r"(scale) // %[scale] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "k1"); +} +#endif // HAS_CONVERT16TO8ROW_AVX512BW + +#ifdef HAS_HALFROW_16TO8_SSSE3 +void HalfRow_16To8_SSSE3(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + asm volatile( + "movd %4,%%xmm2 \n" + "punpcklwd %%xmm2,%%xmm2 \n" + "pshufd $0x0,%%xmm2,%%xmm2 \n" + + // 16 pixels per loop. + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu (%0,%3,2),%%xmm3 \n" + "movdqu 0x10(%0,%3,2),%%xmm4 \n" + "add $0x20,%0 \n" + "pavgw %%xmm3,%%xmm0 \n" + "pavgw %%xmm4,%%xmm1 \n" + "pmulhuw %%xmm2,%%xmm0 \n" + "pmulhuw %%xmm2,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "add $0x10,%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(width) // %2 + : "r"(src_uv_stride), // %3 + "r"(scale) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif // HAS_HALFROW_16TO8_SSSE3 + +#ifdef HAS_HALFWIDTHROW_16TO8_SSSE3 +static const uvec8 kShuffleMaskHalfWidth16To8 = { + 0u, 1u, 4u, 5u, 8u, 9u, 12u, 13u, + 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u}; + +void HalfWidthRow_16To8_SSSE3(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + asm volatile( + "movd %4,%%xmm2 \n" + "punpcklwd %%xmm2,%%xmm2 \n" + "pshufd $0x0,%%xmm2,%%xmm2 \n" + "pcmpeqd %%xmm5,%%xmm5 \n" + "pcmpeqw %%xmm6,%%xmm6 \n" + "psrld $16,%%xmm5 \n" + "pmaddwd %%xmm6,%%xmm6 \n" + "movdqa %5,%%xmm7 \n" + + // 8 pixels per loop. + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu (%0,%3,2),%%xmm3 \n" + "movdqa %%xmm0,%%xmm1 \n" + "movdqa %%xmm3,%%xmm4 \n" + "pand %%xmm5,%%xmm0 \n" + "psrld $16,%%xmm1 \n" + "pand %%xmm5,%%xmm3 \n" + "psrld $16,%%xmm4 \n" + "paddd %%xmm1,%%xmm0 \n" + "paddd %%xmm4,%%xmm3 \n" + "paddd %%xmm3,%%xmm0 \n" + "paddd %%xmm6,%%xmm0 \n" + "psrld $2,%%xmm0 \n" + "pshufb %%xmm7,%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x10(%0,%3,2),%%xmm3 \n" + "add $0x20,%0 \n" + "movdqa %%xmm1,%%xmm4 \n" + "pand %%xmm5,%%xmm1 \n" + "psrld $16,%%xmm4 \n" + "paddd %%xmm4,%%xmm1 \n" + "movdqa %%xmm3,%%xmm4 \n" + "pand %%xmm5,%%xmm3 \n" + "psrld $16,%%xmm4 \n" + "paddd %%xmm4,%%xmm3 \n" + "paddd %%xmm3,%%xmm1 \n" + "paddd %%xmm6,%%xmm1 \n" + "psrld $2,%%xmm1 \n" + "pshufb %%xmm7,%%xmm1 \n" + "punpcklqdq %%xmm1,%%xmm0 \n" + "pmulhuw %%xmm2,%%xmm0 \n" + "packuswb %%xmm0,%%xmm0 \n" + "movq %%xmm0,(%1) \n" + "add $0x08,%1 \n" + "sub $0x08,%2 \n" + "jg 1b \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(width) // %2 + : "r"(src_uv_stride), // %3 + "rm"(scale), // %4 + "m"(kShuffleMaskHalfWidth16To8) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_HALFWIDTHROW_16TO8_SSSE3 + +#ifdef HAS_HALFROW_16TO8_AVX2 +void HalfRow_16To8_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + asm volatile( + "vmovd %4,%%xmm2 \n" + "vpbroadcastw %%xmm2,%%ymm2 \n" + + // 32 pixels per loop. + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vpavgw (%0,%3,2),%%ymm0,%%ymm0 \n" + "vpavgw 0x20(%0,%3,2),%%ymm1,%%ymm1 \n" + "add $0x40,%0 \n" + "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm2,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "add $0x20,%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(width) // %2 + : "r"(src_uv_stride), // %3 + "rm"(scale) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2"); +} +#endif // HAS_HALFROW_16TO8_AVX2 + +#ifdef HAS_HALFWIDTHROW_16TO8_AVX2 +void HalfWidthRow_16To8_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + asm volatile( + "vmovd %4,%%xmm2 \n" + "vpbroadcastw %%xmm2,%%ymm2 \n" + "vpcmpeqw %%ymm5,%%ymm5,%%ymm5 \n" + "vpsrlw $15,%%ymm5,%%ymm5 \n" + "vpsllw $1,%%ymm5,%%ymm6 \n" + "vpsllw $15,%%ymm5,%%ymm7 \n" + + // 16 pixels per loop. + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu (%0,%3,2),%%ymm3 \n" + "vmovdqu 0x20(%0,%3,2),%%ymm4 \n" + "add $0x40,%0 \n" + "vpxor %%ymm7,%%ymm0,%%ymm0 \n" + "vpxor %%ymm7,%%ymm1,%%ymm1 \n" + "vpxor %%ymm7,%%ymm3,%%ymm3 \n" + "vpxor %%ymm7,%%ymm4,%%ymm4 \n" + "vpmaddwd %%ymm5,%%ymm0,%%ymm0 \n" + "vpmaddwd %%ymm5,%%ymm1,%%ymm1 \n" + "vpmaddwd %%ymm5,%%ymm3,%%ymm3 \n" + "vpmaddwd %%ymm5,%%ymm4,%%ymm4 \n" + "vpaddd %%ymm3,%%ymm0,%%ymm0 \n" + "vpaddd %%ymm4,%%ymm1,%%ymm1 \n" + "vpaddd %%ymm6,%%ymm0,%%ymm0 \n" + "vpaddd %%ymm6,%%ymm1,%%ymm1 \n" + "vpsrld $2,%%ymm0,%%ymm0 \n" + "vpsrld $2,%%ymm1,%%ymm1 \n" + "vpackusdw %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%xmm0,(%1) \n" + "add $0x10,%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(width) // %2 + : "r"(src_uv_stride), // %3 + "rm"(scale) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_HALFWIDTHROW_16TO8_AVX2 + +#if defined(HAS_HALFWIDTHROW_16TO8_ODD_AVX2) || \ + defined(HAS_HALFWIDTHROW_16TO8_AVX2) +void HalfWidthRow_16To8_Odd_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + int n = (width - 1) & ~15; + int r = (width - 1) & 15; + SIMD_ALIGNED(uint16_t pair[64]); + SIMD_ALIGNED(uint8_t out[16]); + if (n > 0) { + HalfWidthRow_16To8_AVX2(src_uv, src_uv_stride, dst_uv, scale, n); + src_uv += n * 2; + dst_uv += n; + } + if (r > 0) { + HalfWidthRow_16To8_Any_AVX2(src_uv, src_uv_stride, dst_uv, scale, r); + src_uv += r * 2; + dst_uv += r; + } + memset(pair, 0, sizeof(pair)); + pair[0] = src_uv[0]; + pair[1] = src_uv[0]; + pair[32] = src_uv[src_uv_stride]; + pair[33] = src_uv[src_uv_stride]; + HalfWidthRow_16To8_AVX2(pair, 32, out, scale, 16); + dst_uv[0] = out[0]; +} +#endif // HAS_HALFWIDTHROW_16TO8_ODD_AVX2 + +#ifdef HAS_HALFROW_AVX2 +void HalfRow_AVX2(const uint8_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int width) { + asm volatile( + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpavgb (%0,%3,1),%%ymm0,%%ymm0 \n" + "lea 0x20(%0),%0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(width) // %2 + : "r"(src_uv_stride) // %3 + : "memory", "cc", "xmm0"); +} +#endif // HAS_HALFROW_AVX2 + +#ifdef HAS_HALFROW_16_AVX2 +void HalfRow_16_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint16_t* dst_uv, + int width) { + asm volatile( + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpavgw (%0,%3,2),%%ymm0,%%ymm0 \n" + "lea 0x20(%0),%0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(width) // %2 + : "r"(src_uv_stride) // %3 + : "memory", "cc", "xmm0"); +} +#endif // HAS_HALFROW_16_AVX2 + +#ifdef HAS_HALFROW_16TO8_AVX512BW +LIBYUV_TARGET_AVX512BW +void HalfRow_16To8_AVX512BW(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const uint16_t* src_uv1 = src_uv + src_uv_stride; + uintptr_t temp; + asm volatile( + "vpbroadcastw %[scale],%%zmm2 \n" + "sub $0x40,%[width] \n" + "jl 2f \n" + + // 64 pixels per loop. + LABELALIGN + "1: \n" + "vmovdqu64 (%[src0]),%%zmm0 \n" + "vmovdqu64 0x40(%[src0]),%%zmm1 \n" + "vpavgw (%[src1]),%%zmm0,%%zmm0 \n" + "vpavgw 0x40(%[src1]),%%zmm1,%%zmm1 \n" + "add $0x80,%[src0] \n" + "add $0x80,%[src1] \n" + "vpmulhuw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm2,%%zmm1,%%zmm1 \n" + "vpmovuswb %%zmm0,(%[dst]) \n" + "vpmovuswb %%zmm1,0x20(%[dst]) \n" + "add $0x40,%[dst] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%q[temp] \n" + "bzhi %q[width],%q[temp],%q[temp] \n" + "kmovd %k[temp],%%k1 \n" + "shr $32,%q[temp] \n" + "kmovd %k[temp],%%k2 \n" + "vmovdqu16 (%[src0]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 0x40(%[src0]),%%zmm1%{%%k2%}%{z%}\n" + "vmovdqu16 (%[src1]),%%zmm3%{%%k1%}%{z%} \n" + "vmovdqu16 0x40(%[src1]),%%zmm4%{%%k2%}%{z%}\n" + "vpavgw %%zmm3,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm4,%%zmm1,%%zmm1 \n" + "vpmulhuw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm2,%%zmm1,%%zmm1 \n" + "vpmovuswb %%zmm0,(%[dst])%{%%k1%} \n" + "vpmovuswb %%zmm1,0x20(%[dst])%{%%k2%} \n" + + "99: \n" + "vzeroupper \n" + : [src0] "+r"(src_uv), [src1] "+r"(src_uv1), [dst] "+r"(dst_uv), + [width] "+r"(width), [temp] "=&r"(temp) + : [scale] "r"(scale) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "k1", "k2"); +} +#endif // HAS_HALFROW_16TO8_AVX512BW + +#ifdef HAS_HALFWIDTHROW_16TO8_AVX512BW +LIBYUV_TARGET_AVX512BW +void HalfWidthRow_16To8_AVX512BW(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const uint16_t* src_uv1 = src_uv + src_uv_stride; + uintptr_t temp; + asm volatile( + "vpbroadcastw %[scale],%%zmm2 \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "vpsrlw $15,%%zmm5,%%zmm5 \n" + "vpsllw $1,%%zmm5,%%zmm6 \n" + "vpsllw $15,%%zmm5,%%zmm7 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + // 32 pixels per loop. + LABELALIGN + "1: \n" + "vmovdqu64 (%[src0]),%%zmm0 \n" + "vmovdqu64 0x40(%[src0]),%%zmm1 \n" + "vmovdqu64 (%[src1]),%%zmm3 \n" + "vmovdqu64 0x40(%[src1]),%%zmm4 \n" + "add $0x80,%[src0] \n" + "add $0x80,%[src1] \n" + "vpxord %%zmm7,%%zmm0,%%zmm0 \n" + "vpxord %%zmm7,%%zmm1,%%zmm1 \n" + "vpxord %%zmm7,%%zmm3,%%zmm3 \n" + "vpxord %%zmm7,%%zmm4,%%zmm4 \n" + "vpmaddwd %%zmm5,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm5,%%zmm1,%%zmm1 \n" + "vpmaddwd %%zmm5,%%zmm3,%%zmm3 \n" + "vpmaddwd %%zmm5,%%zmm4,%%zmm4 \n" + "vpaddd %%zmm3,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm4,%%zmm1,%%zmm1 \n" + "vpaddd %%zmm6,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm6,%%zmm1,%%zmm1 \n" + "vpsrld $2,%%zmm0,%%zmm0 \n" + "vpsrld $2,%%zmm1,%%zmm1 \n" + "vpmovusdw %%zmm0,%%ymm0 \n" + "vpmovusdw %%zmm1,%%ymm1 \n" + "vinserti64x4 $1,%%ymm1,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmovuswb %%zmm0,(%[dst]) \n" + "add $0x20,%[dst] \n" + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $-1,%k[temp] \n" + "bzhi %k[width],%k[temp],%k[temp] \n" + "kmovw %k[temp],%%k1 \n" + "kmovd %k[temp],%%k3 \n" + "shr $16,%k[temp] \n" + "kmovw %k[temp],%%k2 \n" + "vmovdqu32 (%[src0]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src0]),%%zmm1%{%%k2%}%{z%}\n" + "vmovdqu32 (%[src1]),%%zmm3%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src1]),%%zmm4%{%%k2%}%{z%}\n" + "vpxord %%zmm7,%%zmm0,%%zmm0 \n" + "vpxord %%zmm7,%%zmm1,%%zmm1 \n" + "vpxord %%zmm7,%%zmm3,%%zmm3 \n" + "vpxord %%zmm7,%%zmm4,%%zmm4 \n" + "vpmaddwd %%zmm5,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm5,%%zmm1,%%zmm1 \n" + "vpmaddwd %%zmm5,%%zmm3,%%zmm3 \n" + "vpmaddwd %%zmm5,%%zmm4,%%zmm4 \n" + "vpaddd %%zmm3,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm4,%%zmm1,%%zmm1 \n" + "vpaddd %%zmm6,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm6,%%zmm1,%%zmm1 \n" + "vpsrld $2,%%zmm0,%%zmm0 \n" + "vpsrld $2,%%zmm1,%%zmm1 \n" + "vpmovusdw %%zmm0,%%ymm0 \n" + "vpmovusdw %%zmm1,%%ymm1 \n" + "vinserti64x4 $1,%%ymm1,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmovuswb %%zmm0,(%[dst])%{%%k3%} \n" + + "99: \n" + "vzeroupper \n" + : [src0] "+r"(src_uv), [src1] "+r"(src_uv1), [dst] "+r"(dst_uv), + [width] "+r"(width), [temp] "=&r"(temp) + : [scale] "r"(scale) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7", "k1", "k2", "k3"); +} +#endif // HAS_HALFWIDTHROW_16TO8_AVX512BW + // Use scale to convert to lsb formats depending how many bits there are: // 512 = 9 bits // 1024 = 10 bits // 4096 = 12 bits -// TODO(fbarchard): reduce to SSE2 +// 65536 = 16 bits +#ifdef HAS_CONVERT8TO16ROW_SSE2 void Convert8To16Row_SSE2(const uint8_t* src_y, uint16_t* dst_y, - int scale, + int bits, int width) { - // clang-format off - asm volatile ( - "movd %3,%%xmm2 \n" - "punpcklwd %%xmm2,%%xmm2 \n" - "pshufd $0x0,%%xmm2,%%xmm2 \n" + const int shift = 16 - bits; + asm volatile("movd %3,%%xmm2 \n" - // 32 pixels per loop. - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "punpcklbw %%xmm0,%%xmm0 \n" - "punpckhbw %%xmm1,%%xmm1 \n" - "add $0x10,%0 \n" - "pmulhuw %%xmm2,%%xmm0 \n" - "pmulhuw %%xmm2,%%xmm1 \n" - "movdqu %%xmm0,(%1) \n" - "movdqu %%xmm1,0x10(%1) \n" - "add $0x20,%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_y), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : "r"(scale) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2"); - // clang-format on + // 16 pixels per loop. + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqa %%xmm0,%%xmm1 \n" + "punpcklbw %%xmm0,%%xmm0 \n" + "punpckhbw %%xmm1,%%xmm1 \n" + "add $0x10,%0 \n" + "psrlw %%xmm2,%%xmm0 \n" + "psrlw %%xmm2,%%xmm1 \n" + "movdqu %%xmm0,(%1) \n" + "movdqu %%xmm1,0x10(%1) \n" + "add $0x20,%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(shift) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } +#endif // HAS_CONVERT8TO16ROW_SSE2 #ifdef HAS_CONVERT8TO16ROW_AVX2 void Convert8To16Row_AVX2(const uint8_t* src_y, uint16_t* dst_y, - int scale, + int bits, int width) { - // clang-format off - asm volatile ( - "vmovd %3,%%xmm2 \n" - "vpunpcklwd %%xmm2,%%xmm2,%%xmm2 \n" - "vbroadcastss %%xmm2,%%ymm2 \n" + const int shift = 16 - bits; + asm volatile("vmovd %3,%%xmm2 \n" - // 32 pixels per loop. - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "add $0x20,%0 \n" - "vpunpckhbw %%ymm0,%%ymm0,%%ymm1 \n" - "vpunpcklbw %%ymm0,%%ymm0,%%ymm0 \n" - "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" - "vpmulhuw %%ymm2,%%ymm1,%%ymm1 \n" - "vmovdqu %%ymm0,(%1) \n" - "vmovdqu %%ymm1,0x20(%1) \n" - "add $0x40,%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_y), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : "r"(scale) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2"); - // clang-format on + // 32 pixels per loop. + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "add $0x20,%0 \n" + "vpunpckhbw %%ymm0,%%ymm0,%%ymm1 \n" + "vpunpcklbw %%ymm0,%%ymm0,%%ymm0 \n" + "vpsrlw %%xmm2,%%ymm0,%%ymm0 \n" + "vpsrlw %%xmm2,%%ymm1,%%ymm1 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "add $0x40,%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(shift) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } #endif // HAS_CONVERT8TO16ROW_AVX2 +#ifdef HAS_CONVERT8TO16ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void Convert8To16Row_AVX512BW(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width) { + const int shift = 16 - bits; + uintptr_t temp; + asm volatile( + "vpbroadcastw %[c0101],%%zmm2 \n" + "vmovd %[shift],%%xmm3 \n" + "sub $0x40,%2 \n" + "jl 2f \n" + + // 64 pixels per loop. + LABELALIGN + "1: \n" + "vpmovzxbw (%0),%%zmm0 \n" + "vpmovzxbw 0x20(%0),%%zmm1 \n" + "lea 0x40(%0),%0 \n" + "vpmullw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmullw %%zmm2,%%zmm1,%%zmm1 \n" + "vpsrlw %%xmm3,%%zmm0,%%zmm0 \n" + "vpsrlw %%xmm3,%%zmm1,%%zmm1 \n" + "vmovdqu16 %%zmm0,(%1) \n" + "vmovdqu16 %%zmm1,0x40(%1) \n" + "lea 0x80(%1),%1 \n" + "sub $0x40,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%2 \n" + "jle 99f \n" + "cmp $0x20,%2 \n" + "jl 3f \n" + "vpmovzxbw (%0),%%zmm0 \n" + "lea 0x20(%0),%0 \n" + "vpmullw %%zmm2,%%zmm0,%%zmm0 \n" + "vpsrlw %%xmm3,%%zmm0,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x20,%2 \n" + "jle 99f \n" + + "3: \n" + "mov $-1,%k[temp] \n" + "bzhi %k2,%k[temp],%k[temp] \n" + "kmovd %k[temp],%%k1 \n" + "vpmovzxbw (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpmullw %%zmm2,%%zmm0,%%zmm0 \n" + "vpsrlw %%xmm3,%%zmm0,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : [shift] "r"(shift), // %[shift] + [c0101] "r"(0x0101) // %[c0101] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "k1"); +} +#endif // HAS_CONVERT8TO16ROW_AVX512BW + #ifdef HAS_SPLITRGBROW_SSSE3 - // Shuffle table for converting RGB to Planar. -static const uvec8 kShuffleMaskRGBToR0 = {0u, 3u, 6u, 9u, 12u, 15u, - 128u, 128u, 128u, 128u, 128u, 128u, - 128u, 128u, 128u, 128u}; -static const uvec8 kShuffleMaskRGBToR1 = {128u, 128u, 128u, 128u, 128u, 128u, - 2u, 5u, 8u, 11u, 14u, 128u, - 128u, 128u, 128u, 128u}; -static const uvec8 kShuffleMaskRGBToR2 = {128u, 128u, 128u, 128u, 128u, 128u, - 128u, 128u, 128u, 128u, 128u, 1u, - 4u, 7u, 10u, 13u}; - -static const uvec8 kShuffleMaskRGBToG0 = {1u, 4u, 7u, 10u, 13u, 128u, - 128u, 128u, 128u, 128u, 128u, 128u, - 128u, 128u, 128u, 128u}; -static const uvec8 kShuffleMaskRGBToG1 = {128u, 128u, 128u, 128u, 128u, 0u, - 3u, 6u, 9u, 12u, 15u, 128u, - 128u, 128u, 128u, 128u}; -static const uvec8 kShuffleMaskRGBToG2 = {128u, 128u, 128u, 128u, 128u, 128u, - 128u, 128u, 128u, 128u, 128u, 2u, - 5u, 8u, 11u, 14u}; - -static const uvec8 kShuffleMaskRGBToB0 = {2u, 5u, 8u, 11u, 14u, 128u, - 128u, 128u, 128u, 128u, 128u, 128u, - 128u, 128u, 128u, 128u}; -static const uvec8 kShuffleMaskRGBToB1 = {128u, 128u, 128u, 128u, 128u, 1u, - 4u, 7u, 10u, 13u, 128u, 128u, - 128u, 128u, 128u, 128u}; -static const uvec8 kShuffleMaskRGBToB2 = {128u, 128u, 128u, 128u, 128u, 128u, - 128u, 128u, 128u, 128u, 0u, 3u, - 6u, 9u, 12u, 15u}; +static const uvec8 kSplitRGBShuffle[9] = { + {0u, 3u, 6u, 9u, 12u, 15u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, + 128u, 128u}, + {128u, 128u, 128u, 128u, 128u, 128u, 2u, 5u, 8u, 11u, 14u, 128u, 128u, 128u, + 128u, 128u}, + {128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 1u, 4u, + 7u, 10u, 13u}, + {1u, 4u, 7u, 10u, 13u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, + 128u, 128u}, + {128u, 128u, 128u, 128u, 128u, 0u, 3u, 6u, 9u, 12u, 15u, 128u, 128u, 128u, + 128u, 128u}, + {128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 2u, 5u, + 8u, 11u, 14u}, + {2u, 5u, 8u, 11u, 14u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, + 128u, 128u}, + {128u, 128u, 128u, 128u, 128u, 1u, 4u, 7u, 10u, 13u, 128u, 128u, 128u, 128u, + 128u, 128u}, + {128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 0u, 3u, 6u, 9u, + 12u, 15u}}; void SplitRGBRow_SSSE3(const uint8_t* src_rgb, uint8_t* dst_r, @@ -3721,190 +9211,1131 @@ void SplitRGBRow_SSSE3(const uint8_t* src_rgb, uint8_t* dst_b, int width) { asm volatile( + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x20(%0),%%xmm2 \n" + "pshufb 0(%5), %%xmm0 \n" + "pshufb 16(%5), %%xmm1 \n" + "pshufb 32(%5), %%xmm2 \n" + "por %%xmm1,%%xmm0 \n" + "por %%xmm2,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "pshufb %5, %%xmm0 \n" - "pshufb %6, %%xmm1 \n" - "pshufb %7, %%xmm2 \n" - "por %%xmm1,%%xmm0 \n" - "por %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x20(%0),%%xmm2 \n" + "pshufb 48(%5),%%xmm0 \n" + "pshufb 64(%5),%%xmm1 \n" + "pshufb 80(%5), %%xmm2 \n" + "por %%xmm1,%%xmm0 \n" + "por %%xmm2,%%xmm0 \n" + "movdqu %%xmm0,(%2) \n" + "lea 0x10(%2),%2 \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "pshufb %8, %%xmm0 \n" - "pshufb %9, %%xmm1 \n" - "pshufb %10, %%xmm2 \n" - "por %%xmm1,%%xmm0 \n" - "por %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%2) \n" - "lea 0x10(%2),%2 \n" - - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "pshufb %11, %%xmm0 \n" - "pshufb %12, %%xmm1 \n" - "pshufb %13, %%xmm2 \n" - "por %%xmm1,%%xmm0 \n" - "por %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%3) \n" - "lea 0x10(%3),%3 \n" - "lea 0x30(%0),%0 \n" - "sub $0x10,%4 \n" - "jg 1b \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x20(%0),%%xmm2 \n" + "pshufb 96(%5), %%xmm0 \n" + "pshufb 112(%5), %%xmm1 \n" + "pshufb 128(%5), %%xmm2 \n" + "por %%xmm1,%%xmm0 \n" + "por %%xmm2,%%xmm0 \n" + "movdqu %%xmm0,(%3) \n" + "lea 0x10(%3),%3 \n" + "lea 0x30(%0),%0 \n" + "sub $0x10,%4 \n" + "jg 1b \n" : "+r"(src_rgb), // %0 "+r"(dst_r), // %1 "+r"(dst_g), // %2 "+r"(dst_b), // %3 "+r"(width) // %4 - : "m"(kShuffleMaskRGBToR0), // %5 - "m"(kShuffleMaskRGBToR1), // %6 - "m"(kShuffleMaskRGBToR2), // %7 - "m"(kShuffleMaskRGBToG0), // %8 - "m"(kShuffleMaskRGBToG1), // %9 - "m"(kShuffleMaskRGBToG2), // %10 - "m"(kShuffleMaskRGBToB0), // %11 - "m"(kShuffleMaskRGBToB1), // %12 - "m"(kShuffleMaskRGBToB2) // %13 + : "r"(&kSplitRGBShuffle[0]) // %5 : "memory", "cc", "xmm0", "xmm1", "xmm2"); } #endif // HAS_SPLITRGBROW_SSSE3 -#ifdef HAS_MERGERGBROW_SSSE3 +#ifdef HAS_SPLITRGBROW_SSE41 +// Shuffle table for converting RGB to Planar, SSE4.1. Note: these are used for +// the AVX2 implementation as well. +static const uvec8 kSplitRGBShuffleSSE41[5] = { + {0u, 3u, 6u, 9u, 12u, 15u, 2u, 5u, 8u, 11u, 14u, 1u, 4u, 7u, 10u, 13u}, + {1u, 4u, 7u, 10u, 13u, 0u, 3u, 6u, 9u, 12u, 15u, 2u, 5u, 8u, 11u, 14u}, + {2u, 5u, 8u, 11u, 14u, 1u, 4u, 7u, 10u, 13u, 0u, 3u, 6u, 9u, 12u, 15u}, + {0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u}, + {0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u}, +}; -// Shuffle table for converting RGB to Planar. -static const uvec8 kShuffleMaskRToRGB0 = {0u, 128u, 128u, 1u, 128u, 128u, - 2u, 128u, 128u, 3u, 128u, 128u, - 4u, 128u, 128u, 5u}; -static const uvec8 kShuffleMaskGToRGB0 = {128u, 0u, 128u, 128u, 1u, 128u, - 128u, 2u, 128u, 128u, 3u, 128u, - 128u, 4u, 128u, 128u}; -static const uvec8 kShuffleMaskBToRGB0 = {128u, 128u, 0u, 128u, 128u, 1u, - 128u, 128u, 2u, 128u, 128u, 3u, - 128u, 128u, 4u, 128u}; - -static const uvec8 kShuffleMaskGToRGB1 = {5u, 128u, 128u, 6u, 128u, 128u, - 7u, 128u, 128u, 8u, 128u, 128u, - 9u, 128u, 128u, 10u}; -static const uvec8 kShuffleMaskBToRGB1 = {128u, 5u, 128u, 128u, 6u, 128u, - 128u, 7u, 128u, 128u, 8u, 128u, - 128u, 9u, 128u, 128u}; -static const uvec8 kShuffleMaskRToRGB1 = {128u, 128u, 6u, 128u, 128u, 7u, - 128u, 128u, 8u, 128u, 128u, 9u, - 128u, 128u, 10u, 128u}; - -static const uvec8 kShuffleMaskBToRGB2 = {10u, 128u, 128u, 11u, 128u, 128u, - 12u, 128u, 128u, 13u, 128u, 128u, - 14u, 128u, 128u, 15u}; -static const uvec8 kShuffleMaskRToRGB2 = {128u, 11u, 128u, 128u, 12u, 128u, - 128u, 13u, 128u, 128u, 14u, 128u, - 128u, 15u, 128u, 128u}; -static const uvec8 kShuffleMaskGToRGB2 = {128u, 128u, 11u, 128u, 128u, 12u, - 128u, 128u, 13u, 128u, 128u, 14u, - 128u, 128u, 15u, 128u}; - -void MergeRGBRow_SSSE3(const uint8_t* src_r, - const uint8_t* src_g, - const uint8_t* src_b, - uint8_t* dst_rgb, +void SplitRGBRow_SSE41(const uint8_t* src_rgb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, int width) { asm volatile( + "movdqa 48(%5), %%xmm0 \n" + "1: \n" + "movdqu (%0),%%xmm1 \n" + "movdqu 0x10(%0),%%xmm2 \n" + "movdqu 0x20(%0),%%xmm3 \n" + "lea 0x30(%0),%0 \n" + "movdqa %%xmm1, %%xmm4 \n" + "pblendvb %%xmm3, %%xmm1 \n" + "pblendvb %%xmm2, %%xmm3 \n" + "pblendvb %%xmm4, %%xmm2 \n" + "palignr $0xF, %%xmm0, %%xmm0 \n" + "pblendvb %%xmm2, %%xmm1 \n" + "pblendvb %%xmm3, %%xmm2 \n" + "pblendvb %%xmm4, %%xmm3 \n" + "palignr $0x1, %%xmm0, %%xmm0 \n" + "pshufb 0(%5), %%xmm1 \n" + "pshufb 16(%5), %%xmm2 \n" + "pshufb 32(%5), %%xmm3 \n" + "movdqu %%xmm1,(%1) \n" + "lea 0x10(%1),%1 \n" + "movdqu %%xmm2,(%2) \n" + "lea 0x10(%2),%2 \n" + "movdqu %%xmm3,(%3) \n" + "lea 0x10(%3),%3 \n" + "sub $0x10,%4 \n" + "jg 1b \n" + : "+r"(src_rgb), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+r"(width) // %4 + : "r"(&kSplitRGBShuffleSSE41[0]) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif // HAS_SPLITRGBROW_SSE41 + +#ifdef HAS_SPLITRGBROW_AVX2 +void SplitRGBRow_AVX2(const uint8_t* src_rgb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + asm volatile( + "vbroadcasti128 48(%5), %%ymm0 \n" + "vbroadcasti128 64(%5), %%ymm7 \n" +#if defined(__x86_64__) + "vbroadcasti128 0(%5), %%ymm8 \n" + "vbroadcasti128 16(%5), %%ymm9 \n" + "vbroadcasti128 32(%5), %%ymm10 \n" +#endif + "1: \n" + "vmovdqu (%0),%%ymm4 \n" + "vmovdqu 0x20(%0),%%ymm5 \n" + "vmovdqu 0x40(%0),%%ymm6 \n" + "lea 0x60(%0),%0 \n" + "vpblendd $240, %%ymm5, %%ymm4, %%ymm1 \n" + "vperm2i128 $33, %%ymm6, %%ymm4, %%ymm2 \n" + "vpblendd $240, %%ymm6, %%ymm5, %%ymm3 \n" + "vpblendvb %%ymm0, %%ymm3, %%ymm1, %%ymm4 \n" + "vpblendvb %%ymm0, %%ymm1, %%ymm2, %%ymm5 \n" + "vpblendvb %%ymm0, %%ymm2, %%ymm3, %%ymm6 \n" + "vpblendvb %%ymm7, %%ymm5, %%ymm4, %%ymm1 \n" + "vpblendvb %%ymm7, %%ymm6, %%ymm5, %%ymm2 \n" + "vpblendvb %%ymm7, %%ymm4, %%ymm6, %%ymm3 \n" +#if defined(__x86_64__) + "vpshufb %%ymm8, %%ymm1, %%ymm1 \n" + "vpshufb %%ymm9, %%ymm2, %%ymm2 \n" + "vpshufb %%ymm10, %%ymm3, %%ymm3 \n" +#else + "vbroadcasti128 0(%5), %%ymm4 \n" + "vbroadcasti128 16(%5), %%ymm5 \n" + "vbroadcasti128 32(%5), %%ymm6 \n" + "vpshufb %%ymm4, %%ymm1, %%ymm1 \n" + "vpshufb %%ymm5, %%ymm2, %%ymm2 \n" + "vpshufb %%ymm6, %%ymm3, %%ymm3 \n" +#endif + "vmovdqu %%ymm1,(%1) \n" + "lea 0x20(%1),%1 \n" + "vmovdqu %%ymm2,(%2) \n" + "lea 0x20(%2),%2 \n" + "vmovdqu %%ymm3,(%3) \n" + "lea 0x20(%3),%3 \n" + "sub $0x20,%4 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_rgb), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+r"(width) // %4 + : "r"(&kSplitRGBShuffleSSE41[0]) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7" +#if defined(__x86_64__) + , + "xmm8", "xmm9", "xmm10" +#endif + ); +} +#endif // HAS_SPLITRGBROW_AVX2 + +#ifdef HAS_MERGERGBROW_AVX2 +// Shuffle table for converting Planar to RGB. +static const uvec8 kMergeRGBShuffle[9] = { + {0u, 128u, 128u, 1u, 128u, 128u, 2u, 128u, 128u, 3u, 128u, 128u, 4u, 128u, + 128u, 5u}, + {128u, 0u, 128u, 128u, 1u, 128u, 128u, 2u, 128u, 128u, 3u, 128u, 128u, 4u, + 128u, 128u}, + {128u, 128u, 0u, 128u, 128u, 1u, 128u, 128u, 2u, 128u, 128u, 3u, 128u, 128u, + 4u, 128u}, + {128u, 128u, 6u, 128u, 128u, 7u, 128u, 128u, 8u, 128u, 128u, 9u, 128u, 128u, + 10u, 128u}, + {5u, 128u, 128u, 6u, 128u, 128u, 7u, 128u, 128u, 8u, 128u, 128u, 9u, 128u, + 128u, 10u}, + {128u, 5u, 128u, 128u, 6u, 128u, 128u, 7u, 128u, 128u, 8u, 128u, 128u, 9u, + 128u, 128u}, + {128u, 11u, 128u, 128u, 12u, 128u, 128u, 13u, 128u, 128u, 14u, 128u, 128u, + 15u, 128u, 128u}, + {128u, 128u, 11u, 128u, 128u, 12u, 128u, 128u, 13u, 128u, 128u, 14u, 128u, + 128u, 15u, 128u}, + {10u, 128u, 128u, 11u, 128u, 128u, 12u, 128u, 128u, 13u, 128u, 128u, 14u, + 128u, 128u, 15u}}; + +void MergeRGBRow_AVX2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_rgb, + int width) { + asm volatile( + "sub %0,%1 \n" + "sub %0,%2 \n" +#if defined(__x86_64__) + "vbroadcasti128 (%5),%%ymm8 \n" + "vbroadcasti128 16(%5),%%ymm9 \n" + "vbroadcasti128 32(%5),%%ymm10 \n" + "vbroadcasti128 48(%5),%%ymm11 \n" + "vbroadcasti128 64(%5),%%ymm12 \n" + "vbroadcasti128 80(%5),%%ymm13 \n" + "vbroadcasti128 96(%5),%%ymm14 \n" + "vbroadcasti128 112(%5),%%ymm15 \n" +#endif LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu (%1),%%xmm1 \n" - "movdqu (%2),%%xmm2 \n" - "pshufb %5, %%xmm0 \n" - "pshufb %6, %%xmm1 \n" - "pshufb %7, %%xmm2 \n" - "por %%xmm1,%%xmm0 \n" - "por %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%3) \n" + "1: \n" + "vmovdqu (%0),%%ymm3 \n" + "vmovdqu (%0,%1,1),%%ymm4 \n" + "vmovdqu (%0,%2,1),%%ymm5 \n" + "lea 0x20(%0),%0 \n" - "movdqu (%0),%%xmm0 \n" - "movdqu (%1),%%xmm1 \n" - "movdqu (%2),%%xmm2 \n" - "pshufb %8, %%xmm0 \n" - "pshufb %9, %%xmm1 \n" - "pshufb %10, %%xmm2 \n" - "por %%xmm1,%%xmm0 \n" - "por %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,16(%3) \n" +#if defined(__x86_64__) + "vpshufb %%ymm8,%%ymm3,%%ymm0 \n" + "vpshufb %%ymm9,%%ymm4,%%ymm6 \n" + "vpshufb %%ymm10,%%ymm5,%%ymm7 \n" + "vpor %%ymm6,%%ymm0,%%ymm0 \n" + "vpor %%ymm7,%%ymm0,%%ymm0 \n" - "movdqu (%0),%%xmm0 \n" - "movdqu (%1),%%xmm1 \n" - "movdqu (%2),%%xmm2 \n" - "pshufb %11, %%xmm0 \n" - "pshufb %12, %%xmm1 \n" - "pshufb %13, %%xmm2 \n" - "por %%xmm1,%%xmm0 \n" - "por %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,32(%3) \n" + "vpshufb %%ymm11,%%ymm3,%%ymm1 \n" + "vpshufb %%ymm12,%%ymm4,%%ymm6 \n" + "vpshufb %%ymm13,%%ymm5,%%ymm7 \n" + "vpor %%ymm6,%%ymm1,%%ymm1 \n" + "vpor %%ymm7,%%ymm1,%%ymm1 \n" - "lea 0x10(%0),%0 \n" - "lea 0x10(%1),%1 \n" - "lea 0x10(%2),%2 \n" - "lea 0x30(%3),%3 \n" - "sub $0x10,%4 \n" - "jg 1b \n" + "vpshufb %%ymm14,%%ymm3,%%ymm2 \n" + "vpshufb %%ymm15,%%ymm4,%%ymm6 \n" + "vbroadcasti128 128(%5),%%ymm7 \n" + "vpor %%ymm6,%%ymm2,%%ymm2 \n" + "vpshufb %%ymm7,%%ymm5,%%ymm7 \n" + "vpor %%ymm7,%%ymm2,%%ymm2 \n" +#else + "vbroadcasti128 (%5),%%ymm6 \n" + "vbroadcasti128 16(%5),%%ymm7 \n" + "vpshufb %%ymm6,%%ymm3,%%ymm0 \n" + "vpshufb %%ymm7,%%ymm4,%%ymm6 \n" + "vbroadcasti128 32(%5),%%ymm7 \n" + "vpor %%ymm6,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm7,%%ymm5,%%ymm7 \n" + "vpor %%ymm7,%%ymm0,%%ymm0 \n" + + "vbroadcasti128 48(%5),%%ymm6 \n" + "vbroadcasti128 64(%5),%%ymm7 \n" + "vpshufb %%ymm6,%%ymm3,%%ymm1 \n" + "vpshufb %%ymm7,%%ymm4,%%ymm6 \n" + "vbroadcasti128 80(%5),%%ymm7 \n" + "vpor %%ymm6,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm7,%%ymm5,%%ymm7 \n" + "vpor %%ymm7,%%ymm1,%%ymm1 \n" + + "vbroadcasti128 96(%5),%%ymm6 \n" + "vbroadcasti128 112(%5),%%ymm7 \n" + "vpshufb %%ymm6,%%ymm3,%%ymm2 \n" + "vpshufb %%ymm7,%%ymm4,%%ymm6 \n" + "vbroadcasti128 128(%5),%%ymm7 \n" + "vpor %%ymm6,%%ymm2,%%ymm2 \n" + "vpshufb %%ymm7,%%ymm5,%%ymm7 \n" + "vpor %%ymm7,%%ymm2,%%ymm2 \n" +#endif + + "vperm2i128 $0x20,%%ymm1,%%ymm0,%%ymm6 \n" + "vperm2i128 $0x30,%%ymm0,%%ymm2,%%ymm7 \n" + "vperm2i128 $0x31,%%ymm2,%%ymm1,%%ymm1 \n" + "vmovdqu %%ymm6,(%3) \n" + "vmovdqu %%ymm7,0x20(%3) \n" + "vmovdqu %%ymm1,0x40(%3) \n" + "lea 0x60(%3),%3 \n" + "subl $0x20,%4 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_r), // %0 "+r"(src_g), // %1 "+r"(src_b), // %2 "+r"(dst_rgb), // %3 - "+r"(width) // %4 - : "m"(kShuffleMaskRToRGB0), // %5 - "m"(kShuffleMaskGToRGB0), // %6 - "m"(kShuffleMaskBToRGB0), // %7 - "m"(kShuffleMaskRToRGB1), // %8 - "m"(kShuffleMaskGToRGB1), // %9 - "m"(kShuffleMaskBToRGB1), // %10 - "m"(kShuffleMaskRToRGB2), // %11 - "m"(kShuffleMaskGToRGB2), // %12 - "m"(kShuffleMaskBToRGB2) // %13 + "+rm"(width) // %4 + : "r"(&kMergeRGBShuffle[0]) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7" +#if defined(__x86_64__) + , + "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15" +#endif + ); +} +#endif // HAS_MERGERGBROW_AVX2 + +#ifdef HAS_MERGEARGBROW_SSE2 +void MergeARGBRow_SSE2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width) { + asm volatile( + "sub %0,%1 \n" + "sub %0,%2 \n" + "sub %0,%3 \n" + + LABELALIGN + "1: \n" + + "movq (%0,%2),%%xmm0 \n" // B + "movq (%0),%%xmm1 \n" // R + "movq (%0,%1),%%xmm2 \n" // G + "punpcklbw %%xmm1,%%xmm0 \n" // BR + "movq (%0,%3),%%xmm1 \n" // A + "punpcklbw %%xmm1,%%xmm2 \n" // GA + "movdqa %%xmm0,%%xmm1 \n" // BR + "punpckhbw %%xmm2,%%xmm1 \n" // BGRA (hi) + "punpcklbw %%xmm2,%%xmm0 \n" // BGRA (lo) + "movdqu %%xmm0,(%4) \n" + "movdqu %%xmm1,16(%4) \n" + + "lea 8(%0),%0 \n" + "lea 32(%4),%4 \n" + "sub $0x8,%5 \n" + "jg 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(src_a), // %3 + "+r"(dst_argb), // %4 + "+r"(width) // %5 + : : "memory", "cc", "xmm0", "xmm1", "xmm2"); } -#endif // HAS_MERGERGBROW_SSSE3 +#endif // HAS_MERGEARGBROW_SSE2 + +#ifdef HAS_MERGEXRGBROW_SSE2 +void MergeXRGBRow_SSE2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width) { + asm volatile( + "1: \n" + + "movq (%2),%%xmm0 \n" // B + "movq (%0),%%xmm1 \n" // R + "movq (%1),%%xmm2 \n" // G + "punpcklbw %%xmm1,%%xmm0 \n" // BR + "pcmpeqd %%xmm1,%%xmm1 \n" // A(255) + "punpcklbw %%xmm1,%%xmm2 \n" // GA + "movdqa %%xmm0,%%xmm1 \n" // BR + "punpckhbw %%xmm2,%%xmm1 \n" // BGRA (hi) + "punpcklbw %%xmm2,%%xmm0 \n" // BGRA (lo) + "movdqu %%xmm0,(%3) \n" + "movdqu %%xmm1,16(%3) \n" + + "lea 8(%0),%0 \n" + "lea 8(%1),%1 \n" + "lea 8(%2),%2 \n" + "lea 32(%3),%3 \n" + "sub $0x8,%4 \n" + "jg 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_argb), // %3 + "+r"(width) // %4 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); +} +#endif // HAS_MERGEXRGBROW_SSE2 + +#ifdef HAS_MERGEARGBROW_AVX2 +void MergeARGBRow_AVX2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width) { + asm volatile( + "sub %0,%1 \n" + "sub %0,%2 \n" + "sub %0,%3 \n" + + LABELALIGN + "1: \n" + + "vmovdqu (%0,%2),%%xmm0 \n" // B + "vmovdqu (%0,%1),%%xmm1 \n" // R + "vinserti128 $1,(%0),%%ymm0,%%ymm0 \n" // G + "vinserti128 $1,(%0,%3),%%ymm1,%%ymm1 \n" // A + "vpunpckhbw %%ymm1,%%ymm0,%%ymm2 \n" + "vpunpcklbw %%ymm1,%%ymm0,%%ymm0 \n" + "vperm2i128 $0x31,%%ymm2,%%ymm0,%%ymm1 \n" + "vperm2i128 $0x20,%%ymm2,%%ymm0,%%ymm0 \n" + "vpunpckhwd %%ymm1,%%ymm0,%%ymm2 \n" + "vpunpcklwd %%ymm1,%%ymm0,%%ymm0 \n" + "vperm2i128 $0x31,%%ymm2,%%ymm0,%%ymm1 \n" + "vperm2i128 $0x20,%%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%4) \n" // First 8 + "vmovdqu %%ymm1,32(%4) \n" // Next 8 + + "lea 16(%0),%0 \n" + "lea 64(%4),%4 \n" + "sub $0x10,%5 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(src_a), // %3 + "+r"(dst_argb), // %4 + "+r"(width) // %5 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); +} +#endif // HAS_MERGEARGBROW_AVX2 + +#ifdef HAS_MERGEXRGBROW_AVX2 +void MergeXRGBRow_AVX2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width) { + asm volatile( + "1: \n" + + "vmovdqu (%2),%%xmm0 \n" // B + "vpcmpeqb %%ymm1,%%ymm1,%%ymm1 \n" // A(255) + "vinserti128 $0,(%1),%%ymm1,%%ymm1 \n" // R + "vinserti128 $1,(%0),%%ymm0,%%ymm0 \n" // G + "vpunpckhbw %%ymm1,%%ymm0,%%ymm2 \n" + "vpunpcklbw %%ymm1,%%ymm0,%%ymm0 \n" + "vperm2i128 $0x31,%%ymm2,%%ymm0,%%ymm1 \n" + "vperm2i128 $0x20,%%ymm2,%%ymm0,%%ymm0 \n" + "vpunpckhwd %%ymm1,%%ymm0,%%ymm2 \n" + "vpunpcklwd %%ymm1,%%ymm0,%%ymm0 \n" + "vperm2i128 $0x31,%%ymm2,%%ymm0,%%ymm1 \n" + "vperm2i128 $0x20,%%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%3) \n" // First 8 + "vmovdqu %%ymm1,32(%3) \n" // Next 8 + + "lea 16(%0),%0 \n" + "lea 16(%1),%1 \n" + "lea 16(%2),%2 \n" + "lea 64(%3),%3 \n" + "sub $0x10,%4 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_argb), // %3 + "+rm"(width) // %4 + ::"memory", + "cc", "xmm0", "xmm1", "xmm2"); +} +#endif // HAS_MERGEXRGBROW_AVX2 + +#ifdef HAS_SPLITARGBROW_SSE2 +void SplitARGBRow_SSE2(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width) { + asm volatile( + "sub %1,%2 \n" + "sub %1,%3 \n" + "sub %1,%4 \n" + + LABELALIGN + "1: \n" + + "movdqu (%0),%%xmm0 \n" // 00-0F + "movdqu 16(%0),%%xmm1 \n" // 10-1F + "movdqa %%xmm0,%%xmm2 \n" + "punpcklqdq %%xmm1,%%xmm0 \n" // 00-07 10-17 + "punpckhqdq %%xmm1,%%xmm2 \n" // 08-0F 18-1F + "movdqa %%xmm0,%%xmm1 \n" + "punpcklbw %%xmm2,%%xmm0 \n" // 08192A3B4C5D6E7F (lo) + "punpckhbw %%xmm2,%%xmm1 \n" // 08192A3B4C5D6E7F (hi) + "movdqa %%xmm0,%%xmm2 \n" + "punpcklqdq %%xmm1,%%xmm0 \n" // 08192A3B08192A3B + "punpckhqdq %%xmm1,%%xmm2 \n" // 4C5D6E7F4C5D6E7F + "movdqa %%xmm0,%%xmm1 \n" + "punpcklbw %%xmm2,%%xmm0 \n" // 048C159D26AE37BF (lo) + "punpckhbw %%xmm2,%%xmm1 \n" // 048C159D26AE37BF (hi) + "movdqa %%xmm0,%%xmm2 \n" + "punpckldq %%xmm1,%%xmm0 \n" // 048C048C159D159D (BG) + "punpckhdq %%xmm1,%%xmm2 \n" // 26AE26AE37BF37BF (RA) + "movlps %%xmm0,(%1,%3) \n" // B + "movhps %%xmm0,(%1,%2) \n" // G + "movlps %%xmm2,(%1) \n" // R + "movhps %%xmm2,(%1,%4) \n" // A + + "lea 32(%0),%0 \n" + "lea 8(%1),%1 \n" + "sub $0x8,%5 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+r"(dst_a), // %4 + "+rm"(width) // %5 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); +} +#endif // HAS_SPLITARGBROW_SSE2 + +#ifdef HAS_SPLITXRGBROW_SSE2 +void SplitXRGBRow_SSE2(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + asm volatile( + "1: \n" + + "movdqu (%0),%%xmm0 \n" // 00-0F + "movdqu 16(%0),%%xmm1 \n" // 10-1F + "movdqa %%xmm0,%%xmm2 \n" + "punpcklqdq %%xmm1,%%xmm0 \n" // 00-07 10-17 + "punpckhqdq %%xmm1,%%xmm2 \n" // 08-0F 18-1F + "movdqa %%xmm0,%%xmm1 \n" + "punpcklbw %%xmm2,%%xmm0 \n" // 08192A3B4C5D6E7F (lo) + "punpckhbw %%xmm2,%%xmm1 \n" // 08192A3B4C5D6E7F (hi) + "movdqa %%xmm0,%%xmm2 \n" + "punpcklqdq %%xmm1,%%xmm0 \n" // 08192A3B08192A3B + "punpckhqdq %%xmm1,%%xmm2 \n" // 4C5D6E7F4C5D6E7F + "movdqa %%xmm0,%%xmm1 \n" + "punpcklbw %%xmm2,%%xmm0 \n" // 048C159D26AE37BF (lo) + "punpckhbw %%xmm2,%%xmm1 \n" // 048C159D26AE37BF (hi) + "movdqa %%xmm0,%%xmm2 \n" + "punpckldq %%xmm1,%%xmm0 \n" // 048C048C159D159D (BG) + "punpckhdq %%xmm1,%%xmm2 \n" // 26AE26AE37BF37BF (RA) + "movlps %%xmm0,(%3) \n" // B + "movhps %%xmm0,(%2) \n" // G + "movlps %%xmm2,(%1) \n" // R + + "lea 32(%0),%0 \n" + "lea 8(%1),%1 \n" + "lea 8(%2),%2 \n" + "lea 8(%3),%3 \n" + "sub $0x8,%4 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+rm"(width) // %4 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); +} +#endif // HAS_SPLITXRGBROW_SSE2 + +static const uvec8 kShuffleMaskARGBSplit = {0, 4, 8, 12, 1, 5, 9, 13, + 2, 6, 10, 14, 3, 7, 11, 15}; +#ifdef HAS_SPLITARGBROW_SSSE3 +void SplitARGBRow_SSSE3(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width) { +#if defined(__i386__) + uint32_t shuf[4]; + memcpy(shuf, &kShuffleMaskARGBSplit, sizeof(shuf)); +#endif + asm volatile( + "movdqu %6,%%xmm3 \n" + "sub %1,%2 \n" + "sub %1,%3 \n" + "sub %1,%4 \n" + + LABELALIGN + "1: \n" + + "movdqu (%0),%%xmm0 \n" // 00-0F + "movdqu 16(%0),%%xmm1 \n" // 10-1F + "pshufb %%xmm3,%%xmm0 \n" // 048C159D26AE37BF (lo) + "pshufb %%xmm3,%%xmm1 \n" // 048C159D26AE37BF (hi) + "movdqa %%xmm0,%%xmm2 \n" + "punpckldq %%xmm1,%%xmm0 \n" // 048C048C159D159D (BG) + "punpckhdq %%xmm1,%%xmm2 \n" // 26AE26AE37BF37BF (RA) + "movlps %%xmm0,(%1,%3) \n" // B + "movhps %%xmm0,(%1,%2) \n" // G + "movlps %%xmm2,(%1) \n" // R + "movhps %%xmm2,(%1,%4) \n" // A + + "lea 32(%0),%0 \n" + "lea 8(%1),%1 \n" + "subl $0x8,%5 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+r"(dst_a), // %4 +#if defined(__i386__) + "+m"(width) // %5 + : "m"(shuf) // %6 +#else + "+rm"(width) // %5 + : "m"(kShuffleMaskARGBSplit) // %6 +#endif + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); +} +#endif // HAS_SPLITARGBROW_SSSE3 + +#ifdef HAS_SPLITXRGBROW_SSSE3 +void SplitXRGBRow_SSSE3(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + asm volatile( + "movdqa %5,%%xmm3 \n" + + LABELALIGN + "1: \n" + + "movdqu (%0),%%xmm0 \n" // 00-0F + "movdqu 16(%0),%%xmm1 \n" // 10-1F + "pshufb %%xmm3,%%xmm0 \n" // 048C159D26AE37BF (lo) + "pshufb %%xmm3,%%xmm1 \n" // 048C159D26AE37BF (hi) + "movdqa %%xmm0,%%xmm2 \n" + "punpckldq %%xmm1,%%xmm0 \n" // 048C048C159D159D (BG) + "punpckhdq %%xmm1,%%xmm2 \n" // 26AE26AE37BF37BF (RA) + "movlps %%xmm0,(%3) \n" // B + "movhps %%xmm0,(%2) \n" // G + "movlps %%xmm2,(%1) \n" // R + + "lea 32(%0),%0 \n" + "lea 8(%1),%1 \n" + "lea 8(%2),%2 \n" + "lea 8(%3),%3 \n" + "sub $0x8,%4 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+r"(width) // %4 + : "m"(kShuffleMaskARGBSplit) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); +} +#endif // HAS_SPLITXRGBROW_SSSE3 + +#ifdef HAS_SPLITARGBROW_AVX2 +static const ulvec32 kShuffleMaskARGBPermute = {0, 4, 1, 5, 2, 6, 3, 7}; +void SplitARGBRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width) { +#if defined(__i386__) + uint32_t shuf[4]; + uint32_t perm[8]; + memcpy(shuf, &kShuffleMaskARGBSplit, sizeof(shuf)); + memcpy(perm, &kShuffleMaskARGBPermute, sizeof(perm)); +#endif + asm volatile( + "sub %1,%2 \n" + "sub %1,%3 \n" + "sub %1,%4 \n" + "vmovdqu %7,%%ymm3 \n" + "vbroadcasti128 %6,%%ymm4 \n" + + LABELALIGN + "1: \n" + + "vmovdqu (%0),%%xmm0 \n" // 00-0F + "vmovdqu 16(%0),%%xmm1 \n" // 10-1F + "vinserti128 $1,32(%0),%%ymm0,%%ymm0 \n" // 00-0F 20-2F + "vinserti128 $1,48(%0),%%ymm1,%%ymm1 \n" // 10-1F 30-3F + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm4,%%ymm1,%%ymm1 \n" + "vpermd %%ymm0,%%ymm3,%%ymm0 \n" + "vpermd %%ymm1,%%ymm3,%%ymm1 \n" + "vpunpckhdq %%ymm1,%%ymm0,%%ymm2 \n" // GA + "vpunpckldq %%ymm1,%%ymm0,%%ymm0 \n" // BR + "vmovdqu %%xmm0,(%1,%3) \n" // B + "vextracti128 $1,%%ymm0,(%1) \n" // R + "vmovdqu %%xmm2,(%1,%2) \n" // G + "vextracti128 $1,%%ymm2,(%1,%4) \n" // A + "lea 64(%0),%0 \n" + "lea 16(%1),%1 \n" + "subl $0x10,%5 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+r"(dst_a), // %4 +#if defined(__i386__) + "+m"(width) // %5 + : "m"(shuf), // %6 + "m"(perm) // %7 +#else + "+rm"(width) // %5 + : "m"(kShuffleMaskARGBSplit), // %6 + "m"(kShuffleMaskARGBPermute) // %7 +#endif + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif // HAS_SPLITARGBROW_AVX2 + +#ifdef HAS_SPLITXRGBROW_AVX2 +void SplitXRGBRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + asm volatile( + "vmovdqa %6,%%ymm3 \n" + "vbroadcasti128 %5,%%ymm4 \n" + + LABELALIGN + "1: \n" + + "vmovdqu (%0),%%xmm0 \n" // 00-0F + "vmovdqu 16(%0),%%xmm1 \n" // 10-1F + "vinserti128 $1,32(%0),%%ymm0,%%ymm0 \n" // 00-0F 20-2F + "vinserti128 $1,48(%0),%%ymm1,%%ymm1 \n" // 10-1F 30-3F + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm4,%%ymm1,%%ymm1 \n" + "vpermd %%ymm0,%%ymm3,%%ymm0 \n" + "vpermd %%ymm1,%%ymm3,%%ymm1 \n" + "vpunpckhdq %%ymm1,%%ymm0,%%ymm2 \n" // GA + "vpunpckldq %%ymm1,%%ymm0,%%ymm0 \n" // BR + "vmovdqu %%xmm0,(%3) \n" // B + "vextracti128 $1,%%ymm0,(%1) \n" // R + "vmovdqu %%xmm2,(%2) \n" // G + + "lea 64(%0),%0 \n" + "lea 16(%1),%1 \n" + "lea 16(%2),%2 \n" + "lea 16(%3),%3 \n" + "sub $0x10,%4 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+r"(width) // %4 + : "m"(kShuffleMaskARGBSplit), // %5 + "m"(kShuffleMaskARGBPermute) // %6 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif // HAS_SPLITXRGBROW_AVX2 + +#ifdef HAS_MERGEXR30ROW_AVX2 +void MergeXR30Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int depth, + int width) { + int shift = depth - 10; + asm volatile( + "sub %0,%1 \n" + "sub %0,%2 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" // AR30 constants + "vpsrlw $14,%%ymm5,%%ymm5 \n" + "vpsllw $4,%%ymm5,%%ymm5 \n" // 2 alpha bits + "vpcmpeqb %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrlw $6,%%ymm6,%%ymm6 \n" + "vmovd %5,%%xmm4 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu (%0,%1),%%ymm1 \n" + "vmovdqu (%0,%2),%%ymm2 \n" + "vpsrlw %%xmm4,%%ymm0,%%ymm0 \n" + "vpsrlw %%xmm4,%%ymm1,%%ymm1 \n" + "vpsrlw %%xmm4,%%ymm2,%%ymm2 \n" + "vpminuw %%ymm0,%%ymm6,%%ymm0 \n" + "vpminuw %%ymm1,%%ymm6,%%ymm1 \n" + "vpminuw %%ymm2,%%ymm6,%%ymm2 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpermq $0xd8,%%ymm2,%%ymm2 \n" + "vpsllw $0x4,%%ymm0,%%ymm0 \n" // Shift R to target bit + "vpunpckhwd %%ymm0,%%ymm2,%%ymm3 \n" // RB + "vpunpcklwd %%ymm0,%%ymm2,%%ymm0 \n" + "vpunpckhwd %%ymm5,%%ymm1,%%ymm2 \n" // AG + "vpunpcklwd %%ymm5,%%ymm1,%%ymm1 \n" + "vpslld $0xa,%%ymm1,%%ymm1 \n" // Shift AG to target bit + "vpslld $0xa,%%ymm2,%%ymm2 \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" // Combine + "vpor %%ymm2,%%ymm3,%%ymm3 \n" + "vmovdqu %%ymm0,(%3) \n" + "vmovdqu %%ymm3,0x20(%3) \n" + "lea 0x20(%0),%0 \n" + "lea 0x40(%3),%3 \n" + "sub $0x10,%4 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_ar30), // %3 + "+r"(width) // %4 +#if defined(__i386__) + : "m"(shift) // %5 +#else + : "rm"(shift) // %5 +#endif + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); +} +#endif // HAS_MERGEXR30ROW_AVX2 + +#ifdef HAS_MERGEAR64ROW_AVX2 +static const lvec32 MergeAR64Permute = {0, 4, 2, 6, 1, 5, 3, 7}; +void MergeAR64Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint16_t* dst_ar64, + int depth, + int width) { + int shift = 16 - depth; + uint32_t mask16 = (depth >= 16) ? 0xffffu : ((1u << depth) - 1u); + uint32_t mask = (mask16 << 16) | mask16; +#if defined(__i386__) + uint32_t perm[8]; + memcpy(perm, &MergeAR64Permute, sizeof(perm)); +#endif + asm volatile( + "sub %0,%1 \n" + "sub %0,%2 \n" + "sub %0,%3 \n" + "vmovdqu %8,%%ymm5 \n" + "vmovd %6,%%xmm6 \n" + "vbroadcastss %7,%%ymm7 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" // R + "vmovdqu (%0,%1),%%ymm1 \n" // G + "vmovdqu (%0,%2),%%ymm2 \n" // B + "vmovdqu (%0,%3),%%ymm3 \n" // A + "vpminuw %%ymm0,%%ymm7,%%ymm0 \n" + "vpminuw %%ymm1,%%ymm7,%%ymm1 \n" + "vpminuw %%ymm2,%%ymm7,%%ymm2 \n" + "vpminuw %%ymm3,%%ymm7,%%ymm3 \n" + "vpsllw %%xmm6,%%ymm0,%%ymm0 \n" + "vpsllw %%xmm6,%%ymm1,%%ymm1 \n" + "vpsllw %%xmm6,%%ymm2,%%ymm2 \n" + "vpsllw %%xmm6,%%ymm3,%%ymm3 \n" + "vpermd %%ymm0,%%ymm5,%%ymm0 \n" + "vpermd %%ymm1,%%ymm5,%%ymm1 \n" + "vpermd %%ymm2,%%ymm5,%%ymm2 \n" + "vpermd %%ymm3,%%ymm5,%%ymm3 \n" + "vpunpcklwd %%ymm1,%%ymm2,%%ymm4 \n" // BG(low) + "vpunpckhwd %%ymm1,%%ymm2,%%ymm1 \n" // BG(hi) + "vpunpcklwd %%ymm3,%%ymm0,%%ymm2 \n" // RA(low) + "vpunpckhwd %%ymm3,%%ymm0,%%ymm0 \n" // RA(hi) + "vpunpckldq %%ymm2,%%ymm4,%%ymm3 \n" // BGRA(1) + "vpunpckhdq %%ymm2,%%ymm4,%%ymm4 \n" // BGRA(3) + "vpunpckldq %%ymm0,%%ymm1,%%ymm2 \n" // BGRA(2) + "vpunpckhdq %%ymm0,%%ymm1,%%ymm1 \n" // BGRA(4) + "vmovdqu %%ymm3,(%4) \n" + "vmovdqu %%ymm2,0x20(%4) \n" + "vmovdqu %%ymm4,0x40(%4) \n" + "vmovdqu %%ymm1,0x60(%4) \n" + "lea 0x20(%0),%0 \n" + "lea 0x80(%4),%4 \n" + "subl $0x10,%5 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(src_a), // %3 + "+r"(dst_ar64), // %4 +#if defined(__i386__) + "+m"(width) // %5 + : "m"(shift), // %6 + "m"(mask), // %7 + "m"(perm) // %8 +#else + "+rm"(width) // %5 + : "m"(shift), // %6 + "m"(mask), // %7 + "m"(MergeAR64Permute) // %8 +#endif + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_MERGEAR64ROW_AVX2 + +#ifdef HAS_MERGEXR64ROW_AVX2 +void MergeXR64Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint16_t* dst_ar64, + int depth, + int width) { + int shift = 16 - depth; + uint32_t mask16 = (depth >= 16) ? 0xffffu : ((1u << depth) - 1u); + uint32_t mask = (mask16 << 16) | mask16; +#if defined(__i386__) + uint32_t perm[8]; + memcpy(perm, &MergeAR64Permute, sizeof(perm)); +#endif + asm volatile( + "sub %0,%1 \n" + "sub %0,%2 \n" + "vmovdqu %7,%%ymm5 \n" + "vmovd %5,%%xmm6 \n" + "vbroadcastss %6,%%ymm7 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" // R + "vmovdqu (%0,%1),%%ymm1 \n" // G + "vmovdqu (%0,%2),%%ymm2 \n" // B + "vpminuw %%ymm0,%%ymm7,%%ymm0 \n" + "vpminuw %%ymm1,%%ymm7,%%ymm1 \n" + "vpminuw %%ymm2,%%ymm7,%%ymm2 \n" + "vpsllw %%xmm6,%%ymm0,%%ymm0 \n" + "vpsllw %%xmm6,%%ymm1,%%ymm1 \n" + "vpsllw %%xmm6,%%ymm2,%%ymm2 \n" + "vpermd %%ymm0,%%ymm5,%%ymm0 \n" + "vpermd %%ymm1,%%ymm5,%%ymm1 \n" + "vpermd %%ymm2,%%ymm5,%%ymm2 \n" + "vpcmpeqb %%ymm3,%%ymm3,%%ymm3 \n" // A (0xffff) + "vpunpcklwd %%ymm1,%%ymm2,%%ymm4 \n" // BG(low) + "vpunpckhwd %%ymm1,%%ymm2,%%ymm1 \n" // BG(hi) + "vpunpcklwd %%ymm3,%%ymm0,%%ymm2 \n" // RA(low) + "vpunpckhwd %%ymm3,%%ymm0,%%ymm0 \n" // RA(hi) + "vpunpckldq %%ymm2,%%ymm4,%%ymm3 \n" // BGRA(1) + "vpunpckhdq %%ymm2,%%ymm4,%%ymm4 \n" // BGRA(3) + "vpunpckldq %%ymm0,%%ymm1,%%ymm2 \n" // BGRA(2) + "vpunpckhdq %%ymm0,%%ymm1,%%ymm1 \n" // BGRA(4) + "vmovdqu %%ymm3,(%3) \n" + "vmovdqu %%ymm2,0x20(%3) \n" + "vmovdqu %%ymm4,0x40(%3) \n" + "vmovdqu %%ymm1,0x60(%3) \n" + "lea 0x20(%0),%0 \n" + "lea 0x80(%3),%3 \n" + "subl $0x10,%4 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_ar64), // %3 + "+rm"(width) // %4 + : "m"(shift), // %5 + "m"(mask), // %6 +#if defined(__i386__) + "m"(perm) // %7 +#else + "m"(MergeAR64Permute) // %7 +#endif + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_MERGEXR64ROW_AVX2 + +#ifdef HAS_MERGEARGB16TO8ROW_AVX2 +static const uvec8 MergeARGB16To8Shuffle = {0, 8, 1, 9, 2, 10, 3, 11, + 4, 12, 5, 13, 6, 14, 7, 15}; +void MergeARGB16To8Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint8_t* dst_argb, + int depth, + int width) { + int shift = depth - 8; +#if defined(__i386__) + uint32_t shuf[4]; + memcpy(shuf, &MergeARGB16To8Shuffle, sizeof(shuf)); +#endif + asm volatile( + "sub %0,%1 \n" + "sub %0,%2 \n" + "sub %0,%3 \n" + "vbroadcasti128 %7,%%ymm5 \n" + "vmovd %6,%%xmm6 \n" + "vpcmpeqb %%ymm7,%%ymm7,%%ymm7 \n" + "vpsrlw $8,%%ymm7,%%ymm7 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" // R + "vmovdqu (%0,%1),%%ymm1 \n" // G + "vmovdqu (%0,%2),%%ymm2 \n" // B + "vmovdqu (%0,%3),%%ymm3 \n" // A + "vpsrlw %%xmm6,%%ymm0,%%ymm0 \n" + "vpsrlw %%xmm6,%%ymm1,%%ymm1 \n" + "vpsrlw %%xmm6,%%ymm2,%%ymm2 \n" + "vpsrlw %%xmm6,%%ymm3,%%ymm3 \n" + "vpminuw %%ymm7,%%ymm0,%%ymm0 \n" + "vpminuw %%ymm7,%%ymm1,%%ymm1 \n" + "vpminuw %%ymm7,%%ymm2,%%ymm2 \n" + "vpminuw %%ymm7,%%ymm3,%%ymm3 \n" + "vpackuswb %%ymm1,%%ymm2,%%ymm1 \n" // BG (planar) + "vpackuswb %%ymm3,%%ymm0,%%ymm0 \n" // RA (planar) + "vpshufb %%ymm5,%%ymm1,%%ymm1 \n" // BG (interleave) + "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" // RA (interleave) + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpunpcklwd %%ymm0,%%ymm1,%%ymm2 \n" // BGRA (low) + "vpunpckhwd %%ymm0,%%ymm1,%%ymm0 \n" // BGRA (hi) + "vmovdqu %%ymm2,(%4) \n" + "vmovdqu %%ymm0,0x20(%4) \n" + "lea 0x20(%0),%0 \n" + "lea 0x40(%4),%4 \n" + "subl $0x10,%5 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(src_a), // %3 + "+r"(dst_argb), // %4 +#if defined(__i386__) + "+m"(width) // %5 + : "m"(shift), // %6 + "m"(shuf) // %7 +#else + "+rm"(width) // %5 + : "m"(shift), // %6 + "m"(MergeARGB16To8Shuffle) // %7 +#endif + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5", "xmm6", "xmm7"); +} +#endif // HAS_MERGEARGB16TO8ROW_AVX2 + +#ifdef HAS_MERGEXRGB16TO8ROW_AVX2 +void MergeXRGB16To8Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_argb, + int depth, + int width) { + int shift = depth - 8; +#if defined(__i386__) + uint32_t shuf[4]; + memcpy(shuf, &MergeARGB16To8Shuffle, sizeof(shuf)); +#endif + asm volatile( + "sub %0,%1 \n" + "sub %0,%2 \n" + "vbroadcasti128 %6,%%ymm5 \n" + "vmovd %5,%%xmm6 \n" + "vpcmpeqb %%ymm3,%%ymm3,%%ymm3 \n" + "vpsrlw $8,%%ymm3,%%ymm3 \n" // A (0xff) + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" // R + "vmovdqu (%0,%1),%%ymm1 \n" // G + "vmovdqu (%0,%2),%%ymm2 \n" // B + "vpsrlw %%xmm6,%%ymm0,%%ymm0 \n" + "vpsrlw %%xmm6,%%ymm1,%%ymm1 \n" + "vpsrlw %%xmm6,%%ymm2,%%ymm2 \n" + "vpminuw %%ymm3,%%ymm0,%%ymm0 \n" + "vpminuw %%ymm3,%%ymm1,%%ymm1 \n" + "vpminuw %%ymm3,%%ymm2,%%ymm2 \n" + "vpackuswb %%ymm1,%%ymm2,%%ymm1 \n" // BG (planar) + "vpackuswb %%ymm3,%%ymm0,%%ymm0 \n" // RA (planar) + "vpshufb %%ymm5,%%ymm1,%%ymm1 \n" // BG (interleave) + "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" // RA (interleave) + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpunpcklwd %%ymm0,%%ymm1,%%ymm2 \n" // BGRA (low) + "vpunpckhwd %%ymm0,%%ymm1,%%ymm0 \n" // BGRA (hi) + "vmovdqu %%ymm2,(%3) \n" + "vmovdqu %%ymm0,0x20(%3) \n" + "lea 0x20(%0),%0 \n" + "lea 0x40(%3),%3 \n" + "subl $0x10,%4 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_argb), // %3 + "+rm"(width) // %4 + : "m"(shift), // %5 +#if defined(__i386__) + "m"(shuf) // %6 +#else + "m"(MergeARGB16To8Shuffle) // %6 +#endif + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5", "xmm6"); +} +#endif // HAS_MERGEXRGB16TO8ROW_AVX2 #ifdef HAS_COPYROW_SSE2 void CopyRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "test $0xf,%0 \n" - "jne 2f \n" - "test $0xf,%1 \n" - "jne 2f \n" + "test $0xf,%0 \n" + "jne 2f \n" + "test $0xf,%1 \n" + "jne 2f \n" LABELALIGN - "1: \n" - "movdqa (%0),%%xmm0 \n" - "movdqa 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "movdqa %%xmm0,(%1) \n" - "movdqa %%xmm1,0x10(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "jmp 9f \n" + "1: \n" + "movdqa (%0),%%xmm0 \n" + "movdqa 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "movdqa %%xmm0,(%1) \n" + "movdqa %%xmm1,0x10(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "jmp 9f \n" LABELALIGN - "2: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "movdqu %%xmm0,(%1) \n" - "movdqu %%xmm1,0x10(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 2b \n" + "2: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "movdqu %%xmm0,(%1) \n" + "movdqu %%xmm1,0x10(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 2b \n" - LABELALIGN "9: \n" + LABELALIGN "9: \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -3916,17 +10347,16 @@ void CopyRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { #ifdef HAS_COPYROW_AVX void CopyRow_AVX(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vmovdqu %%ymm0,(%1) \n" - "vmovdqu %%ymm1,0x20(%1) \n" - "lea 0x40(%1),%1 \n" - "sub $0x40,%2 \n" - "jg 1b \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x40,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -3935,18 +10365,65 @@ void CopyRow_AVX(const uint8_t* src, uint8_t* dst, int width) { } #endif // HAS_COPYROW_AVX +#ifdef HAS_COPYROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void CopyRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + uintptr_t temp; + asm volatile( + "sub $0x80,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovups (%0),%%zmm0 \n" + "vmovups 0x40(%0),%%zmm1 \n" + "lea 0x80(%0),%0 \n" + "vmovups %%zmm0,(%1) \n" + "vmovups %%zmm1,0x40(%1) \n" + "lea 0x80(%1),%1 \n" + "sub $0x80,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x80,%2 \n" + "jle 99f \n" + "cmp $0x40,%2 \n" + "jl 3f \n" + "vmovups (%0),%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vmovups %%zmm0,(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x40,%2 \n" + "jle 99f \n" + + "3: \n" + "mov $-1,%[temp] \n" + "bzhi %q2,%[temp],%[temp] \n" + "kmovq %[temp],%%k1 \n" + "vmovdqu8 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu8 %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : + : "memory", "cc", "xmm0", "xmm1", "k1"); +} +#endif // HAS_COPYROW_AVX512BW + #ifdef HAS_COPYROW_ERMS // Multiple of 1. void CopyRow_ERMS(const uint8_t* src, uint8_t* dst, int width) { size_t width_tmp = (size_t)(width); - asm volatile( - - "rep movsb \n" - : "+S"(src), // %0 - "+D"(dst), // %1 - "+c"(width_tmp) // %2 - : - : "memory", "cc"); + asm volatile("rep movsb \n" + : "+S"(src), // %0 + "+D"(dst), // %1 + "+c"(width_tmp) // %2 + : + : "memory", "cc"); } #endif // HAS_COPYROW_ERMS @@ -3954,29 +10431,29 @@ void CopyRow_ERMS(const uint8_t* src, uint8_t* dst, int width) { // width in pixels void ARGBCopyAlphaRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "pcmpeqb %%xmm0,%%xmm0 \n" - "pslld $0x18,%%xmm0 \n" - "pcmpeqb %%xmm1,%%xmm1 \n" - "psrld $0x8,%%xmm1 \n" + "pcmpeqb %%xmm0,%%xmm0 \n" + "pslld $0x18,%%xmm0 \n" + "pcmpeqb %%xmm1,%%xmm1 \n" + "psrld $0x8,%%xmm1 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm2 \n" - "movdqu 0x10(%0),%%xmm3 \n" - "lea 0x20(%0),%0 \n" - "movdqu (%1),%%xmm4 \n" - "movdqu 0x10(%1),%%xmm5 \n" - "pand %%xmm0,%%xmm2 \n" - "pand %%xmm0,%%xmm3 \n" - "pand %%xmm1,%%xmm4 \n" - "pand %%xmm1,%%xmm5 \n" - "por %%xmm4,%%xmm2 \n" - "por %%xmm5,%%xmm3 \n" - "movdqu %%xmm2,(%1) \n" - "movdqu %%xmm3,0x10(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x8,%2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm2 \n" + "movdqu 0x10(%0),%%xmm3 \n" + "lea 0x20(%0),%0 \n" + "movdqu (%1),%%xmm4 \n" + "movdqu 0x10(%1),%%xmm5 \n" + "pand %%xmm0,%%xmm2 \n" + "pand %%xmm0,%%xmm3 \n" + "pand %%xmm1,%%xmm4 \n" + "pand %%xmm1,%%xmm5 \n" + "por %%xmm4,%%xmm2 \n" + "por %%xmm5,%%xmm3 \n" + "movdqu %%xmm2,(%1) \n" + "movdqu %%xmm3,0x10(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -3989,22 +10466,22 @@ void ARGBCopyAlphaRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { // width in pixels void ARGBCopyAlphaRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "vpcmpeqb %%ymm0,%%ymm0,%%ymm0 \n" - "vpsrld $0x8,%%ymm0,%%ymm0 \n" + "vpcmpeqb %%ymm0,%%ymm0,%%ymm0 \n" + "vpsrld $0x8,%%ymm0,%%ymm0 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm1 \n" - "vmovdqu 0x20(%0),%%ymm2 \n" - "lea 0x40(%0),%0 \n" - "vpblendvb %%ymm0,(%1),%%ymm1,%%ymm1 \n" - "vpblendvb %%ymm0,0x20(%1),%%ymm2,%%ymm2 \n" - "vmovdqu %%ymm1,(%1) \n" - "vmovdqu %%ymm2,0x20(%1) \n" - "lea 0x40(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0),%%ymm1 \n" + "vmovdqu 0x20(%0),%%ymm2 \n" + "lea 0x40(%0),%0 \n" + "vpblendvb %%ymm0,(%1),%%ymm1,%%ymm1 \n" + "vpblendvb %%ymm0,0x20(%1),%%ymm2,%%ymm2 \n" + "vmovdqu %%ymm1,(%1) \n" + "vmovdqu %%ymm2,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -4019,20 +10496,18 @@ void ARGBExtractAlphaRow_SSE2(const uint8_t* src_argb, uint8_t* dst_a, int width) { asm volatile( - - LABELALIGN - "1: \n" - "movdqu (%0), %%xmm0 \n" - "movdqu 0x10(%0), %%xmm1 \n" - "lea 0x20(%0), %0 \n" - "psrld $0x18, %%xmm0 \n" - "psrld $0x18, %%xmm1 \n" - "packssdw %%xmm1, %%xmm0 \n" - "packuswb %%xmm0, %%xmm0 \n" - "movq %%xmm0,(%1) \n" - "lea 0x8(%1), %1 \n" - "sub $0x8, %2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0), %%xmm0 \n" + "movdqu 0x10(%0), %%xmm1 \n" + "lea 0x20(%0), %0 \n" + "psrld $0x18, %%xmm0 \n" + "psrld $0x18, %%xmm1 \n" + "packssdw %%xmm1, %%xmm0 \n" + "packuswb %%xmm0, %%xmm0 \n" + "movq %%xmm0,(%1) \n" + "lea 0x8(%1), %1 \n" + "sub $0x8, %2 \n" + "jg 1b \n" : "+r"(src_argb), // %0 "+r"(dst_a), // %1 "+rm"(width) // %2 @@ -4050,29 +10525,29 @@ void ARGBExtractAlphaRow_AVX2(const uint8_t* src_argb, uint8_t* dst_a, int width) { asm volatile( - "vmovdqa %3,%%ymm4 \n" - "vbroadcastf128 %4,%%ymm5 \n" + "vmovdqa %3,%%ymm4 \n" + "vbroadcasti128 %4,%%ymm5 \n" LABELALIGN - "1: \n" - "vmovdqu (%0), %%ymm0 \n" - "vmovdqu 0x20(%0), %%ymm1 \n" - "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" // vpsrld $0x18, %%ymm0 - "vpshufb %%ymm5,%%ymm1,%%ymm1 \n" - "vmovdqu 0x40(%0), %%ymm2 \n" - "vmovdqu 0x60(%0), %%ymm3 \n" - "lea 0x80(%0), %0 \n" - "vpackssdw %%ymm1, %%ymm0, %%ymm0 \n" // mutates - "vpshufb %%ymm5,%%ymm2,%%ymm2 \n" - "vpshufb %%ymm5,%%ymm3,%%ymm3 \n" - "vpackssdw %%ymm3, %%ymm2, %%ymm2 \n" // mutates - "vpackuswb %%ymm2,%%ymm0,%%ymm0 \n" // mutates. - "vpermd %%ymm0,%%ymm4,%%ymm0 \n" // unmutate. - "vmovdqu %%ymm0,(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20, %2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0), %%ymm0 \n" + "vmovdqu 0x20(%0), %%ymm1 \n" + "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" // vpsrld $0x18, %%ymm0 + "vpshufb %%ymm5,%%ymm1,%%ymm1 \n" + "vmovdqu 0x40(%0), %%ymm2 \n" + "vmovdqu 0x60(%0), %%ymm3 \n" + "lea 0x80(%0), %0 \n" + "vpackssdw %%ymm1, %%ymm0, %%ymm0 \n" // mutates + "vpshufb %%ymm5,%%ymm2,%%ymm2 \n" + "vpshufb %%ymm5,%%ymm3,%%ymm3 \n" + "vpackssdw %%ymm3, %%ymm2, %%ymm2 \n" // mutates + "vpackuswb %%ymm2,%%ymm0,%%ymm0 \n" // mutates. + "vpermd %%ymm0,%%ymm4,%%ymm0 \n" // unmutate. + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20, %2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_argb), // %0 "+r"(dst_a), // %1 "+rm"(width) // %2 @@ -4082,35 +10557,91 @@ void ARGBExtractAlphaRow_AVX2(const uint8_t* src_argb, } #endif // HAS_ARGBEXTRACTALPHAROW_AVX2 +#ifdef HAS_ARGBEXTRACTALPHAROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBExtractAlphaRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_a, + int width) { + uintptr_t temp; + asm volatile( + "sub $0x20,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%0),%%zmm0 \n" + "vmovdqu32 0x40(%0),%%zmm1 \n" + "lea 0x80(%0),%0 \n" + "vpsrld $0x18,%%zmm0,%%zmm0 \n" + "vpsrld $0x18,%%zmm1,%%zmm1 \n" + "vpmovdb %%zmm0,(%1) \n" + "vpmovdb %%zmm1,0x10(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "cmp $0x10,%2 \n" + "jl 3f \n" + "vmovdqu32 (%0),%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vpsrld $0x18,%%zmm0,%%zmm0 \n" + "vpmovdb %%zmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%2 \n" + "jz 99f \n" + + "3: \n" + "mov $-1,%k3 \n" + "bzhi %k2,%k3,%k3 \n" + "kmovw %k3,%%k1 \n" + "vmovdqu32 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpsrld $0x18,%%zmm0,%%zmm0 \n" + "vpmovdb %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_a), // %1 + "+r"(width), // %2 + "=&r"(temp) // %3 + : + : "memory", "cc", "xmm0", "xmm1", "k1"); +} +#endif // HAS_ARGBEXTRACTALPHAROW_AVX512BW + #ifdef HAS_ARGBCOPYYTOALPHAROW_SSE2 // width in pixels void ARGBCopyYToAlphaRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "pcmpeqb %%xmm0,%%xmm0 \n" - "pslld $0x18,%%xmm0 \n" - "pcmpeqb %%xmm1,%%xmm1 \n" - "psrld $0x8,%%xmm1 \n" + "pcmpeqb %%xmm0,%%xmm0 \n" + "pslld $0x18,%%xmm0 \n" + "pcmpeqb %%xmm1,%%xmm1 \n" + "psrld $0x8,%%xmm1 \n" LABELALIGN - "1: \n" - "movq (%0),%%xmm2 \n" - "lea 0x8(%0),%0 \n" - "punpcklbw %%xmm2,%%xmm2 \n" - "punpckhwd %%xmm2,%%xmm3 \n" - "punpcklwd %%xmm2,%%xmm2 \n" - "movdqu (%1),%%xmm4 \n" - "movdqu 0x10(%1),%%xmm5 \n" - "pand %%xmm0,%%xmm2 \n" - "pand %%xmm0,%%xmm3 \n" - "pand %%xmm1,%%xmm4 \n" - "pand %%xmm1,%%xmm5 \n" - "por %%xmm4,%%xmm2 \n" - "por %%xmm5,%%xmm3 \n" - "movdqu %%xmm2,(%1) \n" - "movdqu %%xmm3,0x10(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x8,%2 \n" - "jg 1b \n" + "1: \n" + "movq (%0),%%xmm2 \n" + "lea 0x8(%0),%0 \n" + "punpcklbw %%xmm2,%%xmm2 \n" + "movdqa %%xmm2,%%xmm3 \n" + "punpckhwd %%xmm3,%%xmm3 \n" + "punpcklwd %%xmm2,%%xmm2 \n" + "movdqu (%1),%%xmm4 \n" + "movdqu 0x10(%1),%%xmm5 \n" + "pand %%xmm0,%%xmm2 \n" + "pand %%xmm0,%%xmm3 \n" + "pand %%xmm1,%%xmm4 \n" + "pand %%xmm1,%%xmm5 \n" + "por %%xmm4,%%xmm2 \n" + "por %%xmm5,%%xmm3 \n" + "movdqu %%xmm2,(%1) \n" + "movdqu %%xmm3,0x10(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -4123,24 +10654,24 @@ void ARGBCopyYToAlphaRow_SSE2(const uint8_t* src, uint8_t* dst, int width) { // width in pixels void ARGBCopyYToAlphaRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "vpcmpeqb %%ymm0,%%ymm0,%%ymm0 \n" - "vpsrld $0x8,%%ymm0,%%ymm0 \n" + "vpcmpeqb %%ymm0,%%ymm0,%%ymm0 \n" + "vpsrld $0x8,%%ymm0,%%ymm0 \n" LABELALIGN - "1: \n" - "vpmovzxbd (%0),%%ymm1 \n" - "vpmovzxbd 0x8(%0),%%ymm2 \n" - "lea 0x10(%0),%0 \n" - "vpslld $0x18,%%ymm1,%%ymm1 \n" - "vpslld $0x18,%%ymm2,%%ymm2 \n" - "vpblendvb %%ymm0,(%1),%%ymm1,%%ymm1 \n" - "vpblendvb %%ymm0,0x20(%1),%%ymm2,%%ymm2 \n" - "vmovdqu %%ymm1,(%1) \n" - "vmovdqu %%ymm2,0x20(%1) \n" - "lea 0x40(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vpmovzxbd (%0),%%ymm1 \n" + "vpmovzxbd 0x8(%0),%%ymm2 \n" + "lea 0x10(%0),%0 \n" + "vpslld $0x18,%%ymm1,%%ymm1 \n" + "vpslld $0x18,%%ymm2,%%ymm2 \n" + "vpblendvb %%ymm0,(%1),%%ymm1,%%ymm1 \n" + "vpblendvb %%ymm0,0x20(%1),%%ymm2,%%ymm2 \n" + "vmovdqu %%ymm1,(%1) \n" + "vmovdqu %%ymm2,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -4149,60 +10680,202 @@ void ARGBCopyYToAlphaRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { } #endif // HAS_ARGBCOPYYTOALPHAROW_AVX2 -#ifdef HAS_SETROW_X86 -void SetRow_X86(uint8_t* dst, uint8_t v8, int width) { - size_t width_tmp = (size_t)(width >> 2); - const uint32_t v32 = v8 * 0x01010101u; // Duplicate byte to all bytes. +#ifdef HAS_ARGBCOPYYTOALPHAROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBCopyYToAlphaRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + uintptr_t temp; asm volatile( + "kmovq %4,%%k1 \n" + "sub $0x20,%2 \n" + "jl 2f \n" - "rep stosl \n" - : "+D"(dst), // %0 - "+c"(width_tmp) // %1 - : "a"(v32) // %2 - : "memory", "cc"); + LABELALIGN + "1: \n" + "vpmovzxbd (%0),%%zmm1 \n" + "vpmovzxbd 0x10(%0),%%zmm2 \n" + "lea 0x20(%0),%0 \n" + "vpslld $0x18,%%zmm1,%%zmm1 \n" + "vpslld $0x18,%%zmm2,%%zmm2 \n" + "vmovdqu8 %%zmm1,(%1)%{%%k1%} \n" + "vmovdqu8 %%zmm2,0x40(%1)%{%%k1%} \n" + "lea 0x80(%1),%1 \n" + "sub $0x20,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "cmp $0x10,%2 \n" + "jl 3f \n" + "vpmovzxbd (%0),%%zmm1 \n" + "lea 0x10(%0),%0 \n" + "vpslld $0x18,%%zmm1,%%zmm1 \n" + "vmovdqu8 %%zmm1,(%1)%{%%k1%} \n" + "lea 0x40(%1),%1 \n" + "sub $0x10,%2 \n" + "jz 99f \n" + + "3: \n" + "mov $-1,%k3 \n" + "bzhi %k2,%k3,%k3 \n" + "kmovw %k3,%%k1 \n" + "vpmovzxbd (%0),%%zmm1%{%%k1%}%{z%} \n" + "vpslld $0x18,%%zmm1,%%zmm1 \n" + "shl $0x2,%k2 \n" + "bzhi %q2,%4,%3 \n" + "kmovq %3,%%k1 \n" + "vmovdqu8 %%zmm1,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width), // %2 + "=&r"(temp) // %3 + : "r"(0x8888888888888888ull) // %4 + : "memory", "cc", "xmm1", "xmm2", "k1"); } +#endif // HAS_ARGBCOPYYTOALPHAROW_AVX512BW +#ifdef HAS_SETROW_ERMS void SetRow_ERMS(uint8_t* dst, uint8_t v8, int width) { size_t width_tmp = (size_t)(width); - asm volatile( - - "rep stosb \n" - : "+D"(dst), // %0 - "+c"(width_tmp) // %1 - : "a"(v8) // %2 - : "memory", "cc"); + asm volatile("rep stosb \n" + : "+D"(dst), // %0 + "+c"(width_tmp) // %1 + : "a"(v8) // %2 + : "memory", "cc"); } +#endif // HAS_SETROW_ERMS -void ARGBSetRow_X86(uint8_t* dst_argb, uint32_t v32, int width) { - size_t width_tmp = (size_t)(width); +#ifdef HAS_SETROW_AVX2 +void SetRow_AVX2(uint8_t* dst, uint8_t v8, int width) { asm volatile( + "vmovd %2,%%xmm0 \n" + "vpbroadcastb %%xmm0,%%ymm0 \n" + "sub $0x40,%1 \n" + "jl 2f \n" - "rep stosl \n" - : "+D"(dst_argb), // %0 - "+c"(width_tmp) // %1 - : "a"(v32) // %2 - : "memory", "cc"); + LABELALIGN + "1: \n" + "vmovdqu %%ymm0,(%0) \n" + "vmovdqu %%ymm0,0x20(%0) \n" + "lea 0x40(%0),%0 \n" + "sub $0x40,%1 \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%1 \n" + "jle 99f \n" + "vmovdqu %%ymm0,(%0) \n" + + "99: \n" + "vzeroupper \n" + : "+r"(dst), // %0 + "+r"(width) // %1 + : "r"((int)v8) // %2 + : "memory", "cc", "xmm0"); } -#endif // HAS_SETROW_X86 +#endif // HAS_SETROW_AVX2 + +#ifdef HAS_ARGBSETROW_AVX2 +void ARGBSetRow_AVX2(uint8_t* dst_argb, uint32_t v32, int width) { + asm volatile( + "vmovd %2,%%xmm0 \n" + "vpbroadcastd %%xmm0,%%ymm0 \n" + "sub $0x20,%1 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu %%ymm0,(%0) \n" + "vmovdqu %%ymm0,0x20(%0) \n" + "vmovdqu %%ymm0,0x40(%0) \n" + "vmovdqu %%ymm0,0x60(%0) \n" + "lea 0x80(%0),%0 \n" + "sub $0x20,%1 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%1 \n" + "jle 99f \n" + "cmp $0x10,%1 \n" + "jl 3f \n" + "vmovdqu %%ymm0,(%0) \n" + "vmovdqu %%ymm0,0x20(%0) \n" + "lea 0x40(%0),%0 \n" + "sub $0x10,%1 \n" + "jle 99f \n" + + "3: \n" + "vmovdqu %%ymm0,(%0) \n" + + "99: \n" + "vzeroupper \n" + : "+r"(dst_argb), // %0 + "+r"(width) // %1 + : "r"(v32) // %2 + : "memory", "cc", "xmm0"); +} +#endif // HAS_ARGBSETROW_AVX2 + +#ifdef HAS_COPYROW_16_AVX2 +void CopyRow_16_AVX2(const uint16_t* src, uint16_t* dst, int width) { + asm volatile( + "sub $0x40,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu 0x40(%0),%%ymm2 \n" + "vmovdqu 0x60(%0),%%ymm3 \n" + "lea 0x80(%0),%0 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "vmovdqu %%ymm2,0x40(%1) \n" + "vmovdqu %%ymm3,0x60(%1) \n" + "lea 0x80(%1),%1 \n" + "sub $0x40,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%2 \n" + "jle 99f \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); +} +#endif // HAS_COPYROW_16_AVX2 #ifdef HAS_YUY2TOYROW_SSE2 void YUY2ToYRow_SSE2(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { asm volatile( - "pcmpeqb %%xmm5,%%xmm5 \n" - "psrlw $0x8,%%xmm5 \n" + "pcmpeqb %%xmm5,%%xmm5 \n" + "psrlw $0x8,%%xmm5 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "pand %%xmm5,%%xmm0 \n" - "pand %%xmm5,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "pand %%xmm5,%%xmm0 \n" + "pand %%xmm5,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" : "+r"(src_yuy2), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -4210,43 +10883,70 @@ void YUY2ToYRow_SSE2(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { : "memory", "cc", "xmm0", "xmm1", "xmm5"); } +void YUY2ToNVUVRow_SSE2(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_uv, + int width) { + asm volatile( + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x00(%0,%3,1),%%xmm2 \n" + "movdqu 0x10(%0,%3,1),%%xmm3 \n" + "lea 0x20(%0),%0 \n" + "pavgb %%xmm2,%%xmm0 \n" + "pavgb %%xmm3,%%xmm1 \n" + "psrlw $0x8,%%xmm0 \n" + "psrlw $0x8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_yuy2), // %0 + "+r"(dst_uv), // %1 + "+r"(width) // %2 + : "r"((ptrdiff_t)(stride_yuy2)) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); +} + void YUY2ToUVRow_SSE2(const uint8_t* src_yuy2, int stride_yuy2, uint8_t* dst_u, uint8_t* dst_v, int width) { asm volatile( - "pcmpeqb %%xmm5,%%xmm5 \n" - "psrlw $0x8,%%xmm5 \n" - "sub %1,%2 \n" + "pcmpeqb %%xmm5,%%xmm5 \n" + "psrlw $0x8,%%xmm5 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x00(%0,%4,1),%%xmm2 \n" - "movdqu 0x10(%0,%4,1),%%xmm3 \n" - "lea 0x20(%0),%0 \n" - "pavgb %%xmm2,%%xmm0 \n" - "pavgb %%xmm3,%%xmm1 \n" - "psrlw $0x8,%%xmm0 \n" - "psrlw $0x8,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "pand %%xmm5,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "psrlw $0x8,%%xmm1 \n" - "packuswb %%xmm1,%%xmm1 \n" - "movq %%xmm0,(%1) \n" - "movq %%xmm1,0x00(%1,%2,1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x10,%3 \n" - "jg 1b \n" - : "+r"(src_yuy2), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+r"(width) // %3 - : "r"((intptr_t)(stride_yuy2)) // %4 + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x00(%0,%4,1),%%xmm2 \n" + "movdqu 0x10(%0,%4,1),%%xmm3 \n" + "lea 0x20(%0),%0 \n" + "pavgb %%xmm2,%%xmm0 \n" + "pavgb %%xmm3,%%xmm1 \n" + "psrlw $0x8,%%xmm0 \n" + "psrlw $0x8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqa %%xmm0,%%xmm1 \n" + "pand %%xmm5,%%xmm0 \n" + "packuswb %%xmm0,%%xmm0 \n" + "psrlw $0x8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm1 \n" + "movq %%xmm0,(%1) \n" + "movq %%xmm1,0x00(%1,%2,1) \n" + "lea 0x8(%1),%1 \n" + "sub $0x10,%3 \n" + "jg 1b \n" + : "+r"(src_yuy2), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"((ptrdiff_t)(stride_yuy2)) // %4 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); } @@ -4255,28 +10955,28 @@ void YUY2ToUV422Row_SSE2(const uint8_t* src_yuy2, uint8_t* dst_v, int width) { asm volatile( - "pcmpeqb %%xmm5,%%xmm5 \n" - "psrlw $0x8,%%xmm5 \n" - "sub %1,%2 \n" + "pcmpeqb %%xmm5,%%xmm5 \n" + "psrlw $0x8,%%xmm5 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "psrlw $0x8,%%xmm0 \n" - "psrlw $0x8,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "pand %%xmm5,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "psrlw $0x8,%%xmm1 \n" - "packuswb %%xmm1,%%xmm1 \n" - "movq %%xmm0,(%1) \n" - "movq %%xmm1,0x00(%1,%2,1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x10,%3 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "psrlw $0x8,%%xmm0 \n" + "psrlw $0x8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqa %%xmm0,%%xmm1 \n" + "pand %%xmm5,%%xmm0 \n" + "packuswb %%xmm0,%%xmm0 \n" + "psrlw $0x8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm1 \n" + "movq %%xmm0,(%1) \n" + "movq %%xmm1,0x00(%1,%2,1) \n" + "lea 0x8(%1),%1 \n" + "sub $0x10,%3 \n" + "jg 1b \n" : "+r"(src_yuy2), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -4287,19 +10987,17 @@ void YUY2ToUV422Row_SSE2(const uint8_t* src_yuy2, void UYVYToYRow_SSE2(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { asm volatile( - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "psrlw $0x8,%%xmm0 \n" - "psrlw $0x8,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "psrlw $0x8,%%xmm0 \n" + "psrlw $0x8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" : "+r"(src_uyvy), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -4313,37 +11011,37 @@ void UYVYToUVRow_SSE2(const uint8_t* src_uyvy, uint8_t* dst_v, int width) { asm volatile( - "pcmpeqb %%xmm5,%%xmm5 \n" - "psrlw $0x8,%%xmm5 \n" - "sub %1,%2 \n" + "pcmpeqb %%xmm5,%%xmm5 \n" + "psrlw $0x8,%%xmm5 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x00(%0,%4,1),%%xmm2 \n" - "movdqu 0x10(%0,%4,1),%%xmm3 \n" - "lea 0x20(%0),%0 \n" - "pavgb %%xmm2,%%xmm0 \n" - "pavgb %%xmm3,%%xmm1 \n" - "pand %%xmm5,%%xmm0 \n" - "pand %%xmm5,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "pand %%xmm5,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "psrlw $0x8,%%xmm1 \n" - "packuswb %%xmm1,%%xmm1 \n" - "movq %%xmm0,(%1) \n" - "movq %%xmm1,0x00(%1,%2,1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x10,%3 \n" - "jg 1b \n" - : "+r"(src_uyvy), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+r"(width) // %3 - : "r"((intptr_t)(stride_uyvy)) // %4 + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x00(%0,%4,1),%%xmm2 \n" + "movdqu 0x10(%0,%4,1),%%xmm3 \n" + "lea 0x20(%0),%0 \n" + "pavgb %%xmm2,%%xmm0 \n" + "pavgb %%xmm3,%%xmm1 \n" + "pand %%xmm5,%%xmm0 \n" + "pand %%xmm5,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqa %%xmm0,%%xmm1 \n" + "pand %%xmm5,%%xmm0 \n" + "packuswb %%xmm0,%%xmm0 \n" + "psrlw $0x8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm1 \n" + "movq %%xmm0,(%1) \n" + "movq %%xmm1,0x00(%1,%2,1) \n" + "lea 0x8(%1),%1 \n" + "sub $0x10,%3 \n" + "jg 1b \n" + : "+r"(src_uyvy), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"((ptrdiff_t)(stride_uyvy)) // %4 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); } @@ -4352,28 +11050,28 @@ void UYVYToUV422Row_SSE2(const uint8_t* src_uyvy, uint8_t* dst_v, int width) { asm volatile( - "pcmpeqb %%xmm5,%%xmm5 \n" - "psrlw $0x8,%%xmm5 \n" - "sub %1,%2 \n" + "pcmpeqb %%xmm5,%%xmm5 \n" + "psrlw $0x8,%%xmm5 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "pand %%xmm5,%%xmm0 \n" - "pand %%xmm5,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "pand %%xmm5,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "psrlw $0x8,%%xmm1 \n" - "packuswb %%xmm1,%%xmm1 \n" - "movq %%xmm0,(%1) \n" - "movq %%xmm1,0x00(%1,%2,1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x10,%3 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "pand %%xmm5,%%xmm0 \n" + "pand %%xmm5,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqa %%xmm0,%%xmm1 \n" + "pand %%xmm5,%%xmm0 \n" + "packuswb %%xmm0,%%xmm0 \n" + "psrlw $0x8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm1 \n" + "movq %%xmm0,(%1) \n" + "movq %%xmm1,0x00(%1,%2,1) \n" + "lea 0x8(%1),%1 \n" + "sub $0x10,%3 \n" + "jg 1b \n" : "+r"(src_uyvy), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -4386,23 +11084,23 @@ void UYVYToUV422Row_SSE2(const uint8_t* src_uyvy, #ifdef HAS_YUY2TOYROW_AVX2 void YUY2ToYRow_AVX2(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { asm volatile( - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - "vpsrlw $0x8,%%ymm5,%%ymm5 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsrlw $0x8,%%ymm5,%%ymm5 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpand %%ymm5,%%ymm0,%%ymm0 \n" - "vpand %%ymm5,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpand %%ymm5,%%ymm0,%%ymm0 \n" + "vpand %%ymm5,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_yuy2), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -4410,44 +11108,71 @@ void YUY2ToYRow_AVX2(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { : "memory", "cc", "xmm0", "xmm1", "xmm5"); } +void YUY2ToNVUVRow_AVX2(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_uv, + int width) { + asm volatile( + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vpavgb 0x00(%0,%3,1),%%ymm0,%%ymm0 \n" + "vpavgb 0x20(%0,%3,1),%%ymm1,%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_yuy2), // %0 + "+r"(dst_uv), // %1 + "+r"(width) // %2 + : "r"((ptrdiff_t)(stride_yuy2)) // %3 + : "memory", "cc", "xmm0", "xmm1"); +} + void YUY2ToUVRow_AVX2(const uint8_t* src_yuy2, int stride_yuy2, uint8_t* dst_u, uint8_t* dst_v, int width) { asm volatile( - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - "vpsrlw $0x8,%%ymm5,%%ymm5 \n" - "sub %1,%2 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsrlw $0x8,%%ymm5,%%ymm5 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vpavgb 0x00(%0,%4,1),%%ymm0,%%ymm0 \n" - "vpavgb 0x20(%0,%4,1),%%ymm1,%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpsrlw $0x8,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vpand %%ymm5,%%ymm0,%%ymm1 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm1,%%ymm1 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vpavgb 0x00(%0,%4,1),%%ymm0,%%ymm0 \n" + "vpavgb 0x20(%0,%4,1),%%ymm1,%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpand %%ymm5,%%ymm0,%%ymm1 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" "vextractf128 $0x0,%%ymm1,(%1) \n" "vextractf128 $0x0,%%ymm0,0x00(%1,%2,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x20,%3 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_yuy2), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+r"(width) // %3 - : "r"((intptr_t)(stride_yuy2)) // %4 + "lea 0x10(%1),%1 \n" + "sub $0x20,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_yuy2), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"((ptrdiff_t)(stride_yuy2)) // %4 : "memory", "cc", "xmm0", "xmm1", "xmm5"); } @@ -4456,31 +11181,31 @@ void YUY2ToUV422Row_AVX2(const uint8_t* src_yuy2, uint8_t* dst_v, int width) { asm volatile( - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - "vpsrlw $0x8,%%ymm5,%%ymm5 \n" - "sub %1,%2 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsrlw $0x8,%%ymm5,%%ymm5 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpsrlw $0x8,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vpand %%ymm5,%%ymm0,%%ymm1 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm1,%%ymm1 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpand %%ymm5,%%ymm0,%%ymm1 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" "vextractf128 $0x0,%%ymm1,(%1) \n" "vextractf128 $0x0,%%ymm0,0x00(%1,%2,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x20,%3 \n" - "jg 1b \n" - "vzeroupper \n" + "lea 0x10(%1),%1 \n" + "sub $0x20,%3 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_yuy2), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -4491,21 +11216,19 @@ void YUY2ToUV422Row_AVX2(const uint8_t* src_yuy2, void UYVYToYRow_AVX2(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { asm volatile( - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpsrlw $0x8,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_uyvy), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -4518,38 +11241,38 @@ void UYVYToUVRow_AVX2(const uint8_t* src_uyvy, uint8_t* dst_v, int width) { asm volatile( - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - "vpsrlw $0x8,%%ymm5,%%ymm5 \n" - "sub %1,%2 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsrlw $0x8,%%ymm5,%%ymm5 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vpavgb 0x00(%0,%4,1),%%ymm0,%%ymm0 \n" - "vpavgb 0x20(%0,%4,1),%%ymm1,%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpand %%ymm5,%%ymm0,%%ymm0 \n" - "vpand %%ymm5,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vpand %%ymm5,%%ymm0,%%ymm1 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm1,%%ymm1 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vpavgb 0x00(%0,%4,1),%%ymm0,%%ymm0 \n" + "vpavgb 0x20(%0,%4,1),%%ymm1,%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpand %%ymm5,%%ymm0,%%ymm0 \n" + "vpand %%ymm5,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpand %%ymm5,%%ymm0,%%ymm1 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" "vextractf128 $0x0,%%ymm1,(%1) \n" "vextractf128 $0x0,%%ymm0,0x00(%1,%2,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x20,%3 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_uyvy), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+r"(width) // %3 - : "r"((intptr_t)(stride_uyvy)) // %4 + "lea 0x10(%1),%1 \n" + "sub $0x20,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_uyvy), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"((ptrdiff_t)(stride_uyvy)) // %4 : "memory", "cc", "xmm0", "xmm1", "xmm5"); } @@ -4558,31 +11281,31 @@ void UYVYToUV422Row_AVX2(const uint8_t* src_uyvy, uint8_t* dst_v, int width) { asm volatile( - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - "vpsrlw $0x8,%%ymm5,%%ymm5 \n" - "sub %1,%2 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsrlw $0x8,%%ymm5,%%ymm5 \n" + "sub %1,%2 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpand %%ymm5,%%ymm0,%%ymm0 \n" - "vpand %%ymm5,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vpand %%ymm5,%%ymm0,%%ymm1 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm1,%%ymm1 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpand %%ymm5,%%ymm0,%%ymm0 \n" + "vpand %%ymm5,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpand %%ymm5,%%ymm0,%%ymm1 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" "vextractf128 $0x0,%%ymm1,(%1) \n" "vextractf128 $0x0,%%ymm0,0x00(%1,%2,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x20,%3 \n" - "jg 1b \n" - "vzeroupper \n" + "lea 0x10(%1),%1 \n" + "sub $0x20,%3 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_uyvy), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -4592,92 +11315,347 @@ void UYVYToUV422Row_AVX2(const uint8_t* src_uyvy, } #endif // HAS_YUY2TOYROW_AVX2 -#ifdef HAS_ARGBBLENDROW_SSSE3 -// Shuffle table for isolating alpha. -static const uvec8 kShuffleAlpha = {3u, 0x80, 3u, 0x80, 7u, 0x80, 7u, 0x80, - 11u, 0x80, 11u, 0x80, 15u, 0x80, 15u, 0x80}; - -// Blend 8 pixels at a time -void ARGBBlendRow_SSSE3(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { +#ifdef HAS_YUY2TOYROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void YUY2ToYRow_AVX512BW(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { + uintptr_t temp; asm volatile( - "pcmpeqb %%xmm7,%%xmm7 \n" - "psrlw $0xf,%%xmm7 \n" - "pcmpeqb %%xmm6,%%xmm6 \n" - "psrlw $0x8,%%xmm6 \n" - "pcmpeqb %%xmm5,%%xmm5 \n" - "psllw $0x8,%%xmm5 \n" - "pcmpeqb %%xmm4,%%xmm4 \n" - "pslld $0x18,%%xmm4 \n" - "sub $0x4,%3 \n" - "jl 49f \n" + "sub $0x40,%2 \n" + "jl 2f \n" - // 4 pixel loop. LABELALIGN - "40: \n" - "movdqu (%0),%%xmm3 \n" - "lea 0x10(%0),%0 \n" - "movdqa %%xmm3,%%xmm0 \n" - "pxor %%xmm4,%%xmm3 \n" - "movdqu (%1),%%xmm2 \n" - "pshufb %4,%%xmm3 \n" - "pand %%xmm6,%%xmm2 \n" - "paddw %%xmm7,%%xmm3 \n" - "pmullw %%xmm3,%%xmm2 \n" - "movdqu (%1),%%xmm1 \n" - "lea 0x10(%1),%1 \n" - "psrlw $0x8,%%xmm1 \n" - "por %%xmm4,%%xmm0 \n" - "pmullw %%xmm3,%%xmm1 \n" - "psrlw $0x8,%%xmm2 \n" - "paddusb %%xmm2,%%xmm0 \n" - "pand %%xmm5,%%xmm1 \n" - "paddusb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%2) \n" - "lea 0x10(%2),%2 \n" - "sub $0x4,%3 \n" - "jge 40b \n" + "1: \n" + "vmovdqu16 (%0),%%zmm0 \n" + "vmovdqu16 0x40(%0),%%zmm1 \n" + "lea 0x80(%0),%0 \n" + "vpmovwb %%zmm0,(%1) \n" + "vpmovwb %%zmm1,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x40,%2 \n" + "jge 1b \n" - "49: \n" - "add $0x3,%3 \n" - "jl 99f \n" + "2: \n" + "add $0x40,%2 \n" + "jle 99f \n" + "cmp $0x20,%2 \n" + "jl 3f \n" + "vmovdqu16 (%0),%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vpmovwb %%zmm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jle 99f \n" + + "3: \n" + "mov $-1,%k[temp] \n" + "bzhi %k2,%k[temp],%k[temp] \n" + "kmovd %k[temp],%%k1 \n" + "vmovdqu16 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpmovwb %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_yuy2), // %0 + "+r"(dst_y), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : + : "memory", "cc", "xmm0", "xmm1", "k1"); +} +#endif // HAS_YUY2TOYROW_AVX512BW + +#ifdef HAS_YUY2TOUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void YUY2ToUVRow_AVX512BW(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + uintptr_t temp; + asm volatile( + "sub %1,%2 \n" + "sub $0x20,%3 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%0),%%zmm0 \n" + "vpavgb 0x00(%0,%[stride],1),%%zmm0,%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vpsrld $0x8,%%zmm0,%%zmm1 \n" + "vpsrld $0x18,%%zmm0,%%zmm0 \n" + "vpmovdb %%zmm1,(%1) \n" + "vpmovdb %%zmm0,0x00(%1,%2,1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x20,%3 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%3 \n" + "jle 99f \n" + "add $0x1,%k3 \n" + "shr $0x1,%k3 \n" + "mov $-1,%k[temp] \n" + "bzhi %k3,%k[temp],%k[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x00(%0,%[stride],1),%%zmm1%{%%k1%}%{z%} \n" + "vpavgb %%zmm1,%%zmm0,%%zmm0 \n" + "vpsrld $0x8,%%zmm0,%%zmm1 \n" + "vpsrld $0x18,%%zmm0,%%zmm0 \n" + "vpmovdb %%zmm1,(%1)%{%%k1%} \n" + "vpmovdb %%zmm0,0x00(%1,%2,1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_yuy2), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width), // %3 + [temp] "=&r"(temp) // %[temp] + : [stride] "r"((ptrdiff_t)(stride_yuy2)) // %[stride] + : "memory", "cc", "xmm0", "xmm1", "k1"); +} +#endif // HAS_YUY2TOUVROW_AVX512BW + +#ifdef HAS_UYVYTOYROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void UYVYToYRow_AVX512BW(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { + uintptr_t temp; + asm volatile( + "sub $0x40,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu16 (%0),%%zmm0 \n" + "vmovdqu16 0x40(%0),%%zmm1 \n" + "lea 0x80(%0),%0 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm1,%%zmm1 \n" + "vpmovwb %%zmm0,(%1) \n" + "vpmovwb %%zmm1,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x40,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%2 \n" + "jle 99f \n" + "cmp $0x20,%2 \n" + "jl 3f \n" + "vmovdqu16 (%0),%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpmovwb %%zmm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jle 99f \n" + + "3: \n" + "mov $-1,%k[temp] \n" + "bzhi %k2,%k[temp],%k[temp] \n" + "kmovd %k[temp],%%k1 \n" + "vmovdqu16 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpmovwb %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_uyvy), // %0 + "+r"(dst_y), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : + : "memory", "cc", "xmm0", "xmm1", "k1"); +} +#endif // HAS_UYVYTOYROW_AVX512BW + +#ifdef HAS_UYVYTOUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void UYVYToUVRow_AVX512BW(const uint8_t* src_uyvy, + int stride_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + uintptr_t temp; + asm volatile( + "sub %1,%2 \n" + "sub $0x20,%3 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%0),%%zmm0 \n" + "vpavgb 0x00(%0,%[stride],1),%%zmm0,%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vpmovdb %%zmm0,(%1) \n" + "vpsrld $0x10,%%zmm0,%%zmm0 \n" + "vpmovdb %%zmm0,0x00(%1,%2,1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x20,%3 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%3 \n" + "jle 99f \n" + "add $0x1,%k3 \n" + "shr $0x1,%k3 \n" + "mov $-1,%k[temp] \n" + "bzhi %k3,%k[temp],%k[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x00(%0,%[stride],1),%%zmm1%{%%k1%}%{z%} \n" + "vpavgb %%zmm1,%%zmm0,%%zmm0 \n" + "vpmovdb %%zmm0,(%1)%{%%k1%} \n" + "vpsrld $0x10,%%zmm0,%%zmm0 \n" + "vpmovdb %%zmm0,0x00(%1,%2,1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_uyvy), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width), // %3 + [temp] "=&r"(temp) // %[temp] + : [stride] "r"((ptrdiff_t)(stride_uyvy)) // %[stride] + : "memory", "cc", "xmm0", "xmm1", "k1"); +} +#endif // HAS_UYVYTOUVROW_AVX512BW + +#if defined(HAS_ARGBBLENDROW_AVX2) || defined(HAS_ARGBBLENDROW_AVX512BW) +// Shuffle table for isolating alpha. +SIMD_ALIGNED(static const uvec8 kShuffleAlpha[2]) = { + {3u, 0x80, 3u, 0x80, 7u, 0x80, 7u, 0x80, 11u, 0x80, 11u, 0x80, 15u, 0x80, + 15u, 0x80}, + {3u, 0x80, 3u, 0x80, 7u, 0x80, 7u, 0x80, 11u, 0x80, 11u, 0x80, 15u, 0x80, + 15u, 0x80}}; +#endif // defined(HAS_ARGBBLENDROW_AVX2) || defined(HAS_ARGBBLENDROW_AVX512BW) + +#ifdef HAS_ARGBBLENDROW_AVX2 +// Blend 8 pixels at a time, with 4-pixel and 1-pixel tails. +void ARGBBlendRow_AVX2(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + asm volatile( + "vpcmpeqb %%ymm7,%%ymm7,%%ymm7 \n" + "vpsrlw $0xf,%%ymm7,%%ymm7 \n" + "vpcmpeqb %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrlw $0x8,%%ymm6,%%ymm6 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsllw $0x8,%%ymm5,%%ymm5 \n" + "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" + "vpslld $0x18,%%ymm4,%%ymm4 \n" +#if defined(__x86_64__) + "vbroadcasti128 %4,%%ymm8 \n" +#endif + "sub $0x8,%3 \n" + "jl 2f \n" + + // 8 pixel loop. + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm3 \n" + "vmovdqu (%1),%%ymm2 \n" + "lea 0x20(%0),%0 \n" + "lea 0x20(%1),%1 \n" + "vpxor %%ymm4,%%ymm3,%%ymm0 \n" +#if defined(__x86_64__) + "vpshufb %%ymm8,%%ymm0,%%ymm0 \n" +#else + "vpshufb %4,%%ymm0,%%ymm0 \n" +#endif + "vpaddw %%ymm7,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm2,%%ymm1 \n" + "vpand %%ymm6,%%ymm2,%%ymm2 \n" + "vpmullw %%ymm0,%%ymm2,%%ymm2 \n" + "vpmullw %%ymm0,%%ymm1,%%ymm1 \n" + "vpor %%ymm4,%%ymm3,%%ymm3 \n" + "vpsrlw $0x8,%%ymm2,%%ymm2 \n" + "vpand %%ymm5,%%ymm1,%%ymm1 \n" + "vpaddusb %%ymm2,%%ymm3,%%ymm3 \n" + "vpaddusb %%ymm1,%%ymm3,%%ymm3 \n" + "vmovdqu %%ymm3,(%2) \n" + "lea 0x20(%2),%2 \n" + "sub $0x8,%3 \n" + "jge 1b \n" + + "2: \n" + "add $0x4,%3 \n" + "jl 3f \n" + "vmovdqu (%0),%%xmm3 \n" + "vmovdqu (%1),%%xmm2 \n" + "lea 0x10(%0),%0 \n" + "lea 0x10(%1),%1 \n" + "vpxor %%xmm4,%%xmm3,%%xmm0 \n" +#if defined(__x86_64__) + "vpshufb %%xmm8,%%xmm0,%%xmm0 \n" +#else + "vpshufb %4,%%xmm0,%%xmm0 \n" +#endif + "vpaddw %%xmm7,%%xmm0,%%xmm0 \n" + "vpsrlw $0x8,%%xmm2,%%xmm1 \n" + "vpand %%xmm6,%%xmm2,%%xmm2 \n" + "vpmullw %%xmm0,%%xmm2,%%xmm2 \n" + "vpmullw %%xmm0,%%xmm1,%%xmm1 \n" + "vpor %%xmm4,%%xmm3,%%xmm3 \n" + "vpsrlw $0x8,%%xmm2,%%xmm2 \n" + "vpand %%xmm5,%%xmm1,%%xmm1 \n" + "vpaddusb %%xmm2,%%xmm3,%%xmm3 \n" + "vpaddusb %%xmm1,%%xmm3,%%xmm3 \n" + "vmovdqu %%xmm3,(%2) \n" + "lea 0x10(%2),%2 \n" + "sub $0x4,%3 \n" + + "3: \n" + "add $0x3,%3 \n" + "jl 99f \n" // 1 pixel loop. - "91: \n" - "movd (%0),%%xmm3 \n" - "lea 0x4(%0),%0 \n" - "movdqa %%xmm3,%%xmm0 \n" - "pxor %%xmm4,%%xmm3 \n" - "movd (%1),%%xmm2 \n" - "pshufb %4,%%xmm3 \n" - "pand %%xmm6,%%xmm2 \n" - "paddw %%xmm7,%%xmm3 \n" - "pmullw %%xmm3,%%xmm2 \n" - "movd (%1),%%xmm1 \n" - "lea 0x4(%1),%1 \n" - "psrlw $0x8,%%xmm1 \n" - "por %%xmm4,%%xmm0 \n" - "pmullw %%xmm3,%%xmm1 \n" - "psrlw $0x8,%%xmm2 \n" - "paddusb %%xmm2,%%xmm0 \n" - "pand %%xmm5,%%xmm1 \n" - "paddusb %%xmm1,%%xmm0 \n" - "movd %%xmm0,(%2) \n" - "lea 0x4(%2),%2 \n" - "sub $0x1,%3 \n" - "jge 91b \n" - "99: \n" - : "+r"(src_argb0), // %0 - "+r"(src_argb1), // %1 - "+r"(dst_argb), // %2 - "+r"(width) // %3 - : "m"(kShuffleAlpha) // %4 + LABELALIGN + "4: \n" + "vmovd (%0),%%xmm3 \n" + "vmovd (%1),%%xmm2 \n" + "lea 0x4(%0),%0 \n" + "lea 0x4(%1),%1 \n" + "vpxor %%xmm4,%%xmm3,%%xmm0 \n" +#if defined(__x86_64__) + "vpshufb %%xmm8,%%xmm0,%%xmm0 \n" +#else + "vpshufb %4,%%xmm0,%%xmm0 \n" +#endif + "vpaddw %%xmm7,%%xmm0,%%xmm0 \n" + "vpsrlw $0x8,%%xmm2,%%xmm1 \n" + "vpand %%xmm6,%%xmm2,%%xmm2 \n" + "vpmullw %%xmm0,%%xmm2,%%xmm2 \n" + "vpmullw %%xmm0,%%xmm1,%%xmm1 \n" + "vpor %%xmm4,%%xmm3,%%xmm3 \n" + "vpsrlw $0x8,%%xmm2,%%xmm2 \n" + "vpand %%xmm5,%%xmm1,%%xmm1 \n" + "vpaddusb %%xmm2,%%xmm3,%%xmm3 \n" + "vpaddusb %%xmm1,%%xmm3,%%xmm3 \n" + "vmovd %%xmm3,(%2) \n" + "lea 0x4(%2),%2 \n" + "sub $0x1,%3 \n" + "jge 4b \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(src_argb1), // %1 + "+r"(dst_argb), // %2 + "+r"(width) // %3 + : "m"(kShuffleAlpha[0]) // %4 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7"); + "xmm7" +#if defined(__x86_64__) + , + "xmm8" +#endif + ); } -#endif // HAS_ARGBBLENDROW_SSSE3 +#endif // HAS_ARGBBLENDROW_AVX2 #ifdef HAS_BLENDPLANEROW_SSSE3 // Blend 8 pixels at a time. @@ -4691,36 +11669,36 @@ void BlendPlaneRow_SSSE3(const uint8_t* src0, uint8_t* dst, int width) { asm volatile( - "pcmpeqb %%xmm5,%%xmm5 \n" - "psllw $0x8,%%xmm5 \n" - "mov $0x80808080,%%eax \n" - "movd %%eax,%%xmm6 \n" - "pshufd $0x0,%%xmm6,%%xmm6 \n" - "mov $0x807f807f,%%eax \n" - "movd %%eax,%%xmm7 \n" - "pshufd $0x0,%%xmm7,%%xmm7 \n" - "sub %2,%0 \n" - "sub %2,%1 \n" - "sub %2,%3 \n" + "pcmpeqb %%xmm5,%%xmm5 \n" + "psllw $0x8,%%xmm5 \n" + "pcmpeqb %%xmm6,%%xmm6 \n" + "pabsb %%xmm6,%%xmm6 \n" + "psllw $7,%%xmm6 \n" + "mov $0x807f807f,%%eax \n" + "movd %%eax,%%xmm7 \n" + "pshufd $0x0,%%xmm7,%%xmm7 \n" + "sub %2,%0 \n" + "sub %2,%1 \n" + "sub %2,%3 \n" // 8 pixel loop. LABELALIGN - "1: \n" - "movq (%2),%%xmm0 \n" - "punpcklbw %%xmm0,%%xmm0 \n" - "pxor %%xmm5,%%xmm0 \n" - "movq (%0,%2,1),%%xmm1 \n" - "movq (%1,%2,1),%%xmm2 \n" - "punpcklbw %%xmm2,%%xmm1 \n" - "psubb %%xmm6,%%xmm1 \n" - "pmaddubsw %%xmm1,%%xmm0 \n" - "paddw %%xmm7,%%xmm0 \n" - "psrlw $0x8,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "movq %%xmm0,(%3,%2,1) \n" - "lea 0x8(%2),%2 \n" - "sub $0x8,%4 \n" - "jg 1b \n" + "1: \n" + "movq (%2),%%xmm0 \n" + "punpcklbw %%xmm0,%%xmm0 \n" + "pxor %%xmm5,%%xmm0 \n" + "movq (%0,%2,1),%%xmm1 \n" + "movq (%1,%2,1),%%xmm2 \n" + "punpcklbw %%xmm2,%%xmm1 \n" + "psubb %%xmm6,%%xmm1 \n" + "pmaddubsw %%xmm1,%%xmm0 \n" + "paddw %%xmm7,%%xmm0 \n" + "psrlw $0x8,%%xmm0 \n" + "packuswb %%xmm0,%%xmm0 \n" + "movq %%xmm0,(%3,%2,1) \n" + "lea 0x8(%2),%2 \n" + "sub $0x8,%4 \n" + "jg 1b \n" : "+r"(src0), // %0 "+r"(src1), // %1 "+r"(alpha), // %2 @@ -4743,44 +11721,44 @@ void BlendPlaneRow_AVX2(const uint8_t* src0, uint8_t* dst, int width) { asm volatile( - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - "vpsllw $0x8,%%ymm5,%%ymm5 \n" - "mov $0x80808080,%%eax \n" - "vmovd %%eax,%%xmm6 \n" - "vbroadcastss %%xmm6,%%ymm6 \n" - "mov $0x807f807f,%%eax \n" - "vmovd %%eax,%%xmm7 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsllw $0x8,%%ymm5,%%ymm5 \n" + "vpcmpeqb %%ymm6,%%ymm6,%%ymm6 \n" + "vpabsb %%ymm6,%%ymm6 \n" + "vpsllw $7,%%ymm6,%%ymm6 \n" + "mov $0x807f807f,%%eax \n" + "vmovd %%eax,%%xmm7 \n" "vbroadcastss %%xmm7,%%ymm7 \n" - "sub %2,%0 \n" - "sub %2,%1 \n" - "sub %2,%3 \n" + "sub %2,%0 \n" + "sub %2,%1 \n" + "sub %2,%3 \n" // 32 pixel loop. LABELALIGN - "1: \n" - "vmovdqu (%2),%%ymm0 \n" - "vpunpckhbw %%ymm0,%%ymm0,%%ymm3 \n" - "vpunpcklbw %%ymm0,%%ymm0,%%ymm0 \n" - "vpxor %%ymm5,%%ymm3,%%ymm3 \n" - "vpxor %%ymm5,%%ymm0,%%ymm0 \n" - "vmovdqu (%0,%2,1),%%ymm1 \n" - "vmovdqu (%1,%2,1),%%ymm2 \n" - "vpunpckhbw %%ymm2,%%ymm1,%%ymm4 \n" - "vpunpcklbw %%ymm2,%%ymm1,%%ymm1 \n" - "vpsubb %%ymm6,%%ymm4,%%ymm4 \n" - "vpsubb %%ymm6,%%ymm1,%%ymm1 \n" - "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" - "vpmaddubsw %%ymm1,%%ymm0,%%ymm0 \n" - "vpaddw %%ymm7,%%ymm3,%%ymm3 \n" - "vpaddw %%ymm7,%%ymm0,%%ymm0 \n" - "vpsrlw $0x8,%%ymm3,%%ymm3 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpackuswb %%ymm3,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,(%3,%2,1) \n" - "lea 0x20(%2),%2 \n" - "sub $0x20,%4 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%2),%%ymm0 \n" + "vpunpckhbw %%ymm0,%%ymm0,%%ymm3 \n" + "vpunpcklbw %%ymm0,%%ymm0,%%ymm0 \n" + "vpxor %%ymm5,%%ymm3,%%ymm3 \n" + "vpxor %%ymm5,%%ymm0,%%ymm0 \n" + "vmovdqu (%0,%2,1),%%ymm1 \n" + "vmovdqu (%1,%2,1),%%ymm2 \n" + "vpunpckhbw %%ymm2,%%ymm1,%%ymm4 \n" + "vpunpcklbw %%ymm2,%%ymm1,%%ymm1 \n" + "vpsubb %%ymm6,%%ymm4,%%ymm4 \n" + "vpsubb %%ymm6,%%ymm1,%%ymm1 \n" + "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" + "vpmaddubsw %%ymm1,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm7,%%ymm3,%%ymm3 \n" + "vpaddw %%ymm7,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm3,%%ymm3 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm3,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%3,%2,1) \n" + "lea 0x20(%2),%2 \n" + "sub $0x20,%4 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src0), // %0 "+r"(src1), // %1 "+r"(alpha), // %2 @@ -4792,95 +11770,201 @@ void BlendPlaneRow_AVX2(const uint8_t* src0, } #endif // HAS_BLENDPLANEROW_AVX2 +#ifdef HAS_BLENDPLANEROW_AVX512BW +// Blend 64 pixels at a time. +// unsigned version of math +// =((A2*C2)+(B2*(255-C2))+255)/256 +// signed version of math +// =(((A2-128)*C2)+((B2-128)*(255-C2))+32768+127)/256 +LIBYUV_TARGET_AVX512BW +void BlendPlaneRow_AVX512BW(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width) { + uintptr_t temp; + asm volatile( + "vpternlogd $0xff,%%zmm17,%%zmm17,%%zmm17 \n" + "vpsllw $0x8,%%zmm17,%%zmm16 \n" // 0xff00 + "vpabsb %%zmm17,%%zmm17 \n" // 0x0101 + "vpsllw $7,%%zmm17,%%zmm17 \n" // 0x8080 + "mov $0x807f807f,%k[temp] \n" + "vmovd %k[temp],%%xmm18 \n" + "vbroadcastss %%xmm18,%%zmm18 \n" // 0x807f + "sub %2,%0 \n" + "sub %2,%1 \n" + "sub %2,%3 \n" + "sub $64,%4 \n" + "jl 2f \n" + + // 64 pixel loop. + LABELALIGN + "1: \n" + "vmovdqu8 (%2),%%zmm0 \n" + "vpunpckhbw %%zmm0,%%zmm0,%%zmm3 \n" + "vpunpcklbw %%zmm0,%%zmm0,%%zmm0 \n" + "vpxorq %%zmm16,%%zmm3,%%zmm3 \n" + "vpxorq %%zmm16,%%zmm0,%%zmm0 \n" + "vmovdqu8 (%0,%2,1),%%zmm1 \n" + "vmovdqu8 (%1,%2,1),%%zmm2 \n" + "vpunpckhbw %%zmm2,%%zmm1,%%zmm4 \n" + "vpunpcklbw %%zmm2,%%zmm1,%%zmm1 \n" + "vpsubb %%zmm17,%%zmm4,%%zmm4 \n" + "vpsubb %%zmm17,%%zmm1,%%zmm1 \n" + "vpmaddubsw %%zmm4,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm1,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm18,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm18,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm3,%%zmm3 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm3,%%zmm0,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%3,%2,1) \n" + "add $64,%2 \n" + "sub $64,%4 \n" + "jge 1b \n" + + "2: \n" + "add $64,%4 \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q4,%[temp],%[temp] \n" + "kmovq %[temp],%%k1 \n" + "vmovdqu8 (%2),%%zmm0%{%%k1%}%{z%} \n" + "vpunpckhbw %%zmm0,%%zmm0,%%zmm3 \n" + "vpunpcklbw %%zmm0,%%zmm0,%%zmm0 \n" + "vpxorq %%zmm16,%%zmm3,%%zmm3 \n" + "vpxorq %%zmm16,%%zmm0,%%zmm0 \n" + "vmovdqu8 (%0,%2,1),%%zmm1%{%%k1%}%{z%} \n" + "vmovdqu8 (%1,%2,1),%%zmm2%{%%k1%}%{z%} \n" + "vpunpckhbw %%zmm2,%%zmm1,%%zmm4 \n" + "vpunpcklbw %%zmm2,%%zmm1,%%zmm1 \n" + "vpsubb %%zmm17,%%zmm4,%%zmm4 \n" + "vpsubb %%zmm17,%%zmm1,%%zmm1 \n" + "vpmaddubsw %%zmm4,%%zmm3,%%zmm3 \n" + "vpmaddubsw %%zmm1,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm18,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm18,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm3,%%zmm3 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm3,%%zmm0,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%3,%2,1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src0), // %0 + "+r"(src1), // %1 + "+r"(alpha), // %2 + "+r"(dst), // %3 + "+r"(width), // %4 + [temp] "=&r"(temp) // %[temp] + ::"memory", + "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm16", "xmm17", "xmm18", + "k1"); +} +#endif // HAS_BLENDPLANEROW_AVX512BW + #ifdef HAS_ARGBATTENUATEROW_SSSE3 -// Shuffle table duplicating alpha -static const uvec8 kShuffleAlpha0 = {3u, 3u, 3u, 3u, 3u, 3u, 128u, 128u, - 7u, 7u, 7u, 7u, 7u, 7u, 128u, 128u}; -static const uvec8 kShuffleAlpha1 = {11u, 11u, 11u, 11u, 11u, 11u, 128u, 128u, - 15u, 15u, 15u, 15u, 15u, 15u, 128u, 128u}; +// Shuffle table duplicating alpha. +static const vec8 kAttenuateShuffle = {6, -128, 6, -128, 6, -128, + -128, -128, 14, -128, 14, -128, + 14, -128, -128, -128}; + // Attenuate 4 pixels at a time. void ARGBAttenuateRow_SSSE3(const uint8_t* src_argb, uint8_t* dst_argb, int width) { asm volatile( - "pcmpeqb %%xmm3,%%xmm3 \n" - "pslld $0x18,%%xmm3 \n" - "movdqa %3,%%xmm4 \n" - "movdqa %4,%%xmm5 \n" + "movdqa %3,%%xmm4 \n" + "pcmpeqb %%xmm5,%%xmm5 \n" + "pslld $0x18,%%xmm5 \n" + "pxor %%xmm6,%%xmm6 \n" + "pcmpeqb %%xmm7,%%xmm7 \n" + "punpcklbw %%xmm6,%%xmm7 \n" + "sub %0,%1 \n" // 4 pixel loop. LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "pshufb %%xmm4,%%xmm0 \n" - "movdqu (%0),%%xmm1 \n" - "punpcklbw %%xmm1,%%xmm1 \n" - "pmulhuw %%xmm1,%%xmm0 \n" - "movdqu (%0),%%xmm1 \n" - "pshufb %%xmm5,%%xmm1 \n" - "movdqu (%0),%%xmm2 \n" - "punpckhbw %%xmm2,%%xmm2 \n" - "pmulhuw %%xmm2,%%xmm1 \n" - "movdqu (%0),%%xmm2 \n" - "lea 0x10(%0),%0 \n" - "pand %%xmm3,%%xmm2 \n" - "psrlw $0x8,%%xmm0 \n" - "psrlw $0x8,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "por %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x4,%2 \n" - "jg 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : "m"(kShuffleAlpha0), // %3 - "m"(kShuffleAlpha1) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + "1: \n" + "movdqu (%0),%%xmm6 \n" + "movdqa %%xmm6,%%xmm0 \n" + "movdqa %%xmm6,%%xmm1 \n" + "punpcklbw %%xmm5,%%xmm0 \n" + "punpckhbw %%xmm5,%%xmm1 \n" + "movdqa %%xmm0,%%xmm2 \n" + "movdqa %%xmm1,%%xmm3 \n" + "pshufb %%xmm4,%%xmm2 \n" // a,a,a,0 + "pshufb %%xmm4,%%xmm3 \n" + "pmullw %%xmm2,%%xmm0 \n" // rgb * alpha + "pmullw %%xmm3,%%xmm1 \n" + "paddw %%xmm7,%%xmm0 \n" // + 255 + "paddw %%xmm7,%%xmm1 \n" + "psrlw $0x8,%%xmm0 \n" + "psrlw $0x8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "pand %%xmm5,%%xmm6 \n" + "por %%xmm6,%%xmm0 \n" + "movdqu %%xmm0,(%0,%1) \n" + "lea 0x10(%0),%0 \n" + "sub $0x4,%2 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "m"(kAttenuateShuffle) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); } #endif // HAS_ARGBATTENUATEROW_SSSE3 #ifdef HAS_ARGBATTENUATEROW_AVX2 + // Shuffle table duplicating alpha. -static const uvec8 kShuffleAlpha_AVX2 = {6u, 7u, 6u, 7u, 6u, 7u, - 128u, 128u, 14u, 15u, 14u, 15u, - 14u, 15u, 128u, 128u}; +static const lvec8 kAttenuateShuffle_AVX2 = { + 6, -128, 6, -128, 6, -128, -128, -128, 14, -128, 14, + -128, 14, -128, -128, -128, 22, -128, 22, -128, 22, -128, + -128, -128, 30, -128, 30, -128, 30, -128, -128, -128}; + // Attenuate 8 pixels at a time. void ARGBAttenuateRow_AVX2(const uint8_t* src_argb, uint8_t* dst_argb, int width) { asm volatile( - "vbroadcastf128 %3,%%ymm4 \n" - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - "vpslld $0x18,%%ymm5,%%ymm5 \n" - "sub %0,%1 \n" + "vmovdqa %3,%%ymm4 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpslld $0x18,%%ymm5,%%ymm5 \n" + "vpxor %%ymm6,%%ymm6,%%ymm6 \n" + "vpcmpeqb %%ymm7,%%ymm7,%%ymm7 \n" + "vpunpcklbw %%ymm6,%%ymm7,%%ymm7 \n" + "sub %0,%1 \n" // 8 pixel loop. LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm6 \n" - "vpunpcklbw %%ymm6,%%ymm6,%%ymm0 \n" - "vpunpckhbw %%ymm6,%%ymm6,%%ymm1 \n" - "vpshufb %%ymm4,%%ymm0,%%ymm2 \n" - "vpshufb %%ymm4,%%ymm1,%%ymm3 \n" - "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" - "vpmulhuw %%ymm3,%%ymm1,%%ymm1 \n" - "vpand %%ymm5,%%ymm6,%%ymm6 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpsrlw $0x8,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpor %%ymm6,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,0x00(%0,%1,1) \n" - "lea 0x20(%0),%0 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_argb), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : "m"(kShuffleAlpha_AVX2) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); + "1: \n" + "vmovdqu (%0),%%ymm6 \n" + "vpunpcklbw %%ymm5,%%ymm6,%%ymm0 \n" + "vpunpckhbw %%ymm5,%%ymm6,%%ymm1 \n" + "vpshufb %%ymm4,%%ymm0,%%ymm2 \n" + "vpshufb %%ymm4,%%ymm1,%%ymm3 \n" + "vpmullw %%ymm2,%%ymm0,%%ymm0 \n" + "vpmullw %%ymm3,%%ymm1,%%ymm1 \n" + "vpaddw %%ymm7,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm7,%%ymm1,%%ymm1 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpand %%ymm5,%%ymm6,%%ymm1 \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,0x00(%0,%1,1) \n" + "lea 0x20(%0),%0 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "m"(kAttenuateShuffle_AVX2) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); } #endif // HAS_ARGBATTENUATEROW_AVX2 @@ -4893,33 +11977,33 @@ void ARGBUnattenuateRow_SSE2(const uint8_t* src_argb, asm volatile( // 4 pixel loop. LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movzb 0x03(%0),%3 \n" - "punpcklbw %%xmm0,%%xmm0 \n" - "movd 0x00(%4,%3,4),%%xmm2 \n" - "movzb 0x07(%0),%3 \n" - "movd 0x00(%4,%3,4),%%xmm3 \n" - "pshuflw $0x40,%%xmm2,%%xmm2 \n" - "pshuflw $0x40,%%xmm3,%%xmm3 \n" - "movlhps %%xmm3,%%xmm2 \n" - "pmulhuw %%xmm2,%%xmm0 \n" - "movdqu (%0),%%xmm1 \n" - "movzb 0x0b(%0),%3 \n" - "punpckhbw %%xmm1,%%xmm1 \n" - "movd 0x00(%4,%3,4),%%xmm2 \n" - "movzb 0x0f(%0),%3 \n" - "movd 0x00(%4,%3,4),%%xmm3 \n" - "pshuflw $0x40,%%xmm2,%%xmm2 \n" - "pshuflw $0x40,%%xmm3,%%xmm3 \n" - "movlhps %%xmm3,%%xmm2 \n" - "pmulhuw %%xmm2,%%xmm1 \n" - "lea 0x10(%0),%0 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x4,%2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movzb 0x03(%0),%3 \n" + "punpcklbw %%xmm0,%%xmm0 \n" + "movd 0x00(%4,%3,4),%%xmm2 \n" + "movzb 0x07(%0),%3 \n" + "movd 0x00(%4,%3,4),%%xmm3 \n" + "pshuflw $0x40,%%xmm2,%%xmm2 \n" + "pshuflw $0x40,%%xmm3,%%xmm3 \n" + "movlhps %%xmm3,%%xmm2 \n" + "pmulhuw %%xmm2,%%xmm0 \n" + "movdqu (%0),%%xmm1 \n" + "movzb 0x0b(%0),%3 \n" + "punpckhbw %%xmm1,%%xmm1 \n" + "movd 0x00(%4,%3,4),%%xmm2 \n" + "movzb 0x0f(%0),%3 \n" + "movd 0x00(%4,%3,4),%%xmm3 \n" + "pshuflw $0x40,%%xmm2,%%xmm2 \n" + "pshuflw $0x40,%%xmm3,%%xmm3 \n" + "movlhps %%xmm3,%%xmm2 \n" + "pmulhuw %%xmm2,%%xmm1 \n" + "lea 0x10(%0),%0 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x4,%2 \n" + "jg 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width), // %2 @@ -4939,53 +12023,53 @@ void ARGBUnattenuateRow_AVX2(const uint8_t* src_argb, int width) { uintptr_t alpha; asm volatile( - "sub %0,%1 \n" - "vbroadcastf128 %5,%%ymm5 \n" + "sub %0,%1 \n" + "vbroadcasti128 %5,%%ymm5 \n" // 8 pixel loop. LABELALIGN - "1: \n" + "1: \n" // replace VPGATHER - "movzb 0x03(%0),%3 \n" - "vmovd 0x00(%4,%3,4),%%xmm0 \n" - "movzb 0x07(%0),%3 \n" - "vmovd 0x00(%4,%3,4),%%xmm1 \n" - "movzb 0x0b(%0),%3 \n" - "vpunpckldq %%xmm1,%%xmm0,%%xmm6 \n" - "vmovd 0x00(%4,%3,4),%%xmm2 \n" - "movzb 0x0f(%0),%3 \n" - "vmovd 0x00(%4,%3,4),%%xmm3 \n" - "movzb 0x13(%0),%3 \n" - "vpunpckldq %%xmm3,%%xmm2,%%xmm7 \n" - "vmovd 0x00(%4,%3,4),%%xmm0 \n" - "movzb 0x17(%0),%3 \n" - "vmovd 0x00(%4,%3,4),%%xmm1 \n" - "movzb 0x1b(%0),%3 \n" - "vpunpckldq %%xmm1,%%xmm0,%%xmm0 \n" - "vmovd 0x00(%4,%3,4),%%xmm2 \n" - "movzb 0x1f(%0),%3 \n" - "vmovd 0x00(%4,%3,4),%%xmm3 \n" - "vpunpckldq %%xmm3,%%xmm2,%%xmm2 \n" + "movzb 0x03(%0),%3 \n" + "vmovd 0x00(%4,%3,4),%%xmm0 \n" + "movzb 0x07(%0),%3 \n" + "vmovd 0x00(%4,%3,4),%%xmm1 \n" + "movzb 0x0b(%0),%3 \n" + "vpunpckldq %%xmm1,%%xmm0,%%xmm6 \n" + "vmovd 0x00(%4,%3,4),%%xmm2 \n" + "movzb 0x0f(%0),%3 \n" + "vmovd 0x00(%4,%3,4),%%xmm3 \n" + "movzb 0x13(%0),%3 \n" + "vpunpckldq %%xmm3,%%xmm2,%%xmm7 \n" + "vmovd 0x00(%4,%3,4),%%xmm0 \n" + "movzb 0x17(%0),%3 \n" + "vmovd 0x00(%4,%3,4),%%xmm1 \n" + "movzb 0x1b(%0),%3 \n" + "vpunpckldq %%xmm1,%%xmm0,%%xmm0 \n" + "vmovd 0x00(%4,%3,4),%%xmm2 \n" + "movzb 0x1f(%0),%3 \n" + "vmovd 0x00(%4,%3,4),%%xmm3 \n" + "vpunpckldq %%xmm3,%%xmm2,%%xmm2 \n" "vpunpcklqdq %%xmm7,%%xmm6,%%xmm3 \n" "vpunpcklqdq %%xmm2,%%xmm0,%%xmm0 \n" "vinserti128 $0x1,%%xmm0,%%ymm3,%%ymm3 \n" // end of VPGATHER - "vmovdqu (%0),%%ymm6 \n" - "vpunpcklbw %%ymm6,%%ymm6,%%ymm0 \n" - "vpunpckhbw %%ymm6,%%ymm6,%%ymm1 \n" - "vpunpcklwd %%ymm3,%%ymm3,%%ymm2 \n" - "vpunpckhwd %%ymm3,%%ymm3,%%ymm3 \n" - "vpshufb %%ymm5,%%ymm2,%%ymm2 \n" - "vpshufb %%ymm5,%%ymm3,%%ymm3 \n" - "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" - "vpmulhuw %%ymm3,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,0x00(%0,%1,1) \n" - "lea 0x20(%0),%0 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "vmovdqu (%0),%%ymm6 \n" + "vpunpcklbw %%ymm6,%%ymm6,%%ymm0 \n" + "vpunpckhbw %%ymm6,%%ymm6,%%ymm1 \n" + "vpunpcklwd %%ymm3,%%ymm3,%%ymm2 \n" + "vpunpckhwd %%ymm3,%%ymm3,%%ymm3 \n" + "vpshufb %%ymm5,%%ymm2,%%ymm2 \n" + "vpshufb %%ymm5,%%ymm3,%%ymm3 \n" + "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm3,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,0x00(%0,%1,1) \n" + "lea 0x20(%0),%0 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width), // %2 @@ -4997,52 +12081,79 @@ void ARGBUnattenuateRow_AVX2(const uint8_t* src_argb, } #endif // HAS_ARGBUNATTENUATEROW_AVX2 -#ifdef HAS_ARGBGRAYROW_SSSE3 -// Convert 8 ARGB pixels (64 bytes) to 8 Gray ARGB pixels -void ARGBGrayRow_SSSE3(const uint8_t* src_argb, uint8_t* dst_argb, int width) { +#if defined(HAS_ARGBGRAYROW_AVX2) || defined(HAS_ARGBGRAYROW_AVX512BW) || \ + defined(HAS_ARGBGRAYROW_AVX512VNNI) +static const uint8_t kShufGrayDword[16] = {0, 0, 0, 0x80, 4, 4, 4, 0x80, + 8, 8, 8, 0x80, 12, 12, 12, 0x80}; +#endif // defined(HAS_ARGBGRAYROW_AVX2) || defined(HAS_ARGBGRAYROW_AVX512BW) || + // defined(HAS_ARGBGRAYROW_AVX512VNNI) + +#ifdef HAS_ARGBGRAYROW_AVX2 +void ARGBGrayRow_AVX2(const uint8_t* src_argb, uint8_t* dst_argb, int width) { + static const uint32_t kCoeff = 0x004d961du; // {29, 150, 77, 0} + static const uint32_t kOne16 = 0x00010001u; + static const uint32_t kBias = 32896u; asm volatile( - "movdqa %3,%%xmm4 \n" - "movdqa %4,%%xmm5 \n" + "vpbroadcastd %[coeff],%%ymm2 \n" + "vpcmpeqb %%ymm7,%%ymm7,%%ymm7 \n" + "vpsllw $7,%%ymm7,%%ymm3 \n" + "vpbroadcastb %%xmm3,%%ymm3 \n" // 0x80808080 + "vpslld $24,%%ymm7,%%ymm7 \n" // 0xff000000 + "vpbroadcastd %[one16],%%ymm4 \n" + "vpbroadcastd %[bias],%%ymm5 \n" + "vbroadcasti128 %[shuf],%%ymm6 \n" + "sub $0x8,%[width] \n" + "jl 2f \n" - // 8 pixel loop. LABELALIGN "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "phaddw %%xmm1,%%xmm0 \n" - "paddw %%xmm5,%%xmm0 \n" - "psrlw $0x7,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "movdqu (%0),%%xmm2 \n" - "movdqu 0x10(%0),%%xmm3 \n" - "lea 0x20(%0),%0 \n" - "psrld $0x18,%%xmm2 \n" - "psrld $0x18,%%xmm3 \n" - "packuswb %%xmm3,%%xmm2 \n" - "packuswb %%xmm2,%%xmm2 \n" - "movdqa %%xmm0,%%xmm3 \n" - "punpcklbw %%xmm0,%%xmm0 \n" - "punpcklbw %%xmm2,%%xmm3 \n" - "movdqa %%xmm0,%%xmm1 \n" - "punpcklwd %%xmm3,%%xmm0 \n" - "punpckhwd %%xmm3,%%xmm1 \n" - "movdqu %%xmm0,(%1) \n" - "movdqu %%xmm1,0x10(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : "m"(kARGBToYJ), // %3 - "m"(kAddYJ64) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); -} -#endif // HAS_ARGBGRAYROW_SSSE3 + "vmovdqu (%[src]),%%ymm0 \n" + "lea 0x20(%[src]),%[src] \n" + "vpxor %%ymm3,%%ymm0,%%ymm1 \n" + "vpmaddubsw %%ymm1,%%ymm2,%%ymm1 \n" + "vpmaddwd %%ymm4,%%ymm1,%%ymm1 \n" + "vpaddd %%ymm5,%%ymm1,%%ymm1 \n" + "vpsrld $8,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm6,%%ymm1,%%ymm1 \n" + "vpand %%ymm7,%%ymm0,%%ymm0 \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" -#ifdef HAS_ARGBSEPIAROW_SSSE3 + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" + + LABELALIGN + "3: \n" + "vmovd (%[src]),%%xmm0 \n" + "lea 0x4(%[src]),%[src] \n" + "vpxor %%xmm3,%%xmm0,%%xmm1 \n" + "vpmaddubsw %%xmm1,%%xmm2,%%xmm1 \n" + "vpmaddwd %%xmm4,%%xmm1,%%xmm1 \n" + "vpaddd %%xmm5,%%xmm1,%%xmm1 \n" + "vpsrld $8,%%xmm1,%%xmm1 \n" + "vpshufb %%xmm6,%%xmm1,%%xmm1 \n" + "vpand %%xmm7,%%xmm0,%%xmm0 \n" + "vpor %%xmm1,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,(%[dst]) \n" + "lea 0x4(%[dst]),%[dst] \n" + "sub $0x1,%[width] \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [width] "+r"(width) + : [coeff] "m"(kCoeff), [one16] "m"(kOne16), [bias] "m"(kBias), + [shuf] "m"(kShufGrayDword) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_ARGBGRAYROW_AVX2 + +#if defined(HAS_ARGBSEPIAROW_AVX2) || defined(HAS_ARGBSEPIAROW_AVX512VNNI) // b = (r * 35 + g * 68 + b * 17) >> 7 // g = (r * 45 + g * 88 + b * 22) >> 7 // r = (r * 50 + g * 98 + b * 24) >> 7 @@ -5055,318 +12166,564 @@ static const vec8 kARGBToSepiaG = {22, 88, 45, 0, 22, 88, 45, 0, static const vec8 kARGBToSepiaR = {24, 98, 50, 0, 24, 98, 50, 0, 24, 98, 50, 0, 24, 98, 50, 0}; +#endif -// Convert 8 ARGB pixels (32 bytes) to 8 Sepia ARGB pixels. -void ARGBSepiaRow_SSSE3(uint8_t* dst_argb, int width) { +#ifdef HAS_ARGBSEPIAROW_AVX2 +// Convert ARGB pixels to Sepia ARGB pixels. +void ARGBSepiaRow_AVX2(uint8_t* dst_argb, int width) { asm volatile( - "movdqa %2,%%xmm2 \n" - "movdqa %3,%%xmm3 \n" - "movdqa %4,%%xmm4 \n" + "vbroadcasti128 %2,%%ymm2 \n" + "vbroadcasti128 %3,%%ymm3 \n" + "vbroadcasti128 %4,%%ymm4 \n" + "sub $0x8,%1 \n" + "jl 2f \n" // 8 pixel loop. LABELALIGN "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm6 \n" - "pmaddubsw %%xmm2,%%xmm0 \n" - "pmaddubsw %%xmm2,%%xmm6 \n" - "phaddw %%xmm6,%%xmm0 \n" - "psrlw $0x7,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "movdqu (%0),%%xmm5 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "pmaddubsw %%xmm3,%%xmm5 \n" - "pmaddubsw %%xmm3,%%xmm1 \n" - "phaddw %%xmm1,%%xmm5 \n" - "psrlw $0x7,%%xmm5 \n" - "packuswb %%xmm5,%%xmm5 \n" - "punpcklbw %%xmm5,%%xmm0 \n" - "movdqu (%0),%%xmm5 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "pmaddubsw %%xmm4,%%xmm5 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "phaddw %%xmm1,%%xmm5 \n" - "psrlw $0x7,%%xmm5 \n" - "packuswb %%xmm5,%%xmm5 \n" - "movdqu (%0),%%xmm6 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "psrld $0x18,%%xmm6 \n" - "psrld $0x18,%%xmm1 \n" - "packuswb %%xmm1,%%xmm6 \n" - "packuswb %%xmm6,%%xmm6 \n" - "punpcklbw %%xmm6,%%xmm5 \n" - "movdqa %%xmm0,%%xmm1 \n" - "punpcklwd %%xmm5,%%xmm0 \n" - "punpckhwd %%xmm5,%%xmm1 \n" - "movdqu %%xmm0,(%0) \n" - "movdqu %%xmm1,0x10(%0) \n" - "lea 0x20(%0),%0 \n" - "sub $0x8,%1 \n" - "jg 1b \n" + "vmovdqu (%0),%%ymm0 \n" + "vpmaddubsw %%ymm2,%%ymm0,%%ymm1 \n" + "vpmaddubsw %%ymm3,%%ymm0,%%ymm5 \n" + "vpmaddubsw %%ymm4,%%ymm0,%%ymm6 \n" + "vphaddw %%ymm5,%%ymm1,%%ymm1 \n" + "vphaddw %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrlw $0x7,%%ymm1,%%ymm1 \n" + "vpsrlw $0x7,%%ymm6,%%ymm6 \n" + "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm6,%%ymm6,%%ymm6 \n" + "vpshufd $0x01,%%ymm1,%%ymm5 \n" + "vpunpcklbw %%ymm5,%%ymm1,%%ymm1 \n" + "vpsrld $0x18,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpunpcklbw %%ymm0,%%ymm6,%%ymm6 \n" + "vpunpcklwd %%ymm6,%%ymm1,%%ymm0 \n" + "vmovdqu %%ymm0,(%0) \n" + "lea 0x20(%0),%0 \n" + "sub $0x8,%1 \n" + "jge 1b \n" + + "2: \n" + "add $0x8,%1 \n" + "jle 99f \n" + + // 1 pixel remainder loop. + LABELALIGN + "3: \n" + "vmovd (%0),%%xmm0 \n" + "vpmaddubsw %%xmm2,%%xmm0,%%xmm1 \n" + "vpmaddubsw %%xmm3,%%xmm0,%%xmm5 \n" + "vpmaddubsw %%xmm4,%%xmm0,%%xmm6 \n" + "vphaddw %%xmm5,%%xmm1,%%xmm1 \n" + "vphaddw %%xmm6,%%xmm6,%%xmm6 \n" + "vpsrlw $0x7,%%xmm1,%%xmm1 \n" + "vpsrlw $0x7,%%xmm6,%%xmm6 \n" + "vpackuswb %%xmm1,%%xmm1,%%xmm1 \n" + "vpackuswb %%xmm6,%%xmm6,%%xmm6 \n" + "vpshufd $0x01,%%xmm1,%%xmm5 \n" + "vpunpcklbw %%xmm5,%%xmm1,%%xmm1 \n" + "vpsrld $0x18,%%xmm0,%%xmm0 \n" + "vpackuswb %%xmm0,%%xmm0,%%xmm0 \n" + "vpackuswb %%xmm0,%%xmm0,%%xmm0 \n" + "vpunpcklbw %%xmm0,%%xmm6,%%xmm6 \n" + "vpunpcklwd %%xmm6,%%xmm1,%%xmm0 \n" + "vmovd %%xmm0,(%0) \n" + "lea 0x04(%0),%0 \n" + "sub $0x1,%1 \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" : "+r"(dst_argb), // %0 "+r"(width) // %1 : "m"(kARGBToSepiaB), // %2 "m"(kARGBToSepiaG), // %3 "m"(kARGBToSepiaR) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6"); } -#endif // HAS_ARGBSEPIAROW_SSSE3 +#endif // HAS_ARGBSEPIAROW_AVX2 -#ifdef HAS_ARGBCOLORMATRIXROW_SSSE3 -// Tranform 8 ARGB pixels (32 bytes) with color matrix. -// Same as Sepia except matrix is provided. -void ARGBColorMatrixRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_argb, - const int8_t* matrix_argb, - int width) { +#ifdef HAS_ARGBSEPIAROW_AVX512VNNI +LIBYUV_TARGET_AVX512VNNI +void ARGBSepiaRow_AVX512VNNI(uint8_t* dst_argb, int width) { + uintptr_t temp; asm volatile( - "movdqu (%3),%%xmm5 \n" - "pshufd $0x00,%%xmm5,%%xmm2 \n" - "pshufd $0x55,%%xmm5,%%xmm3 \n" - "pshufd $0xaa,%%xmm5,%%xmm4 \n" - "pshufd $0xff,%%xmm5,%%xmm5 \n" + "vpbroadcastd %[kSepiaB],%%zmm2 \n" + "vpbroadcastd %[kSepiaG],%%zmm3 \n" + "vpbroadcastd %[kSepiaR],%%zmm4 \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "vpsrld $24,%%zmm5,%%zmm6 \n" // 0x000000ff + "vpslld $24,%%zmm5,%%zmm5 \n" // 0xff000000 + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[dst]),%%zmm0 \n" + "vpxord %%zmm1,%%zmm1,%%zmm1 \n" + "vpxord %%zmm7,%%zmm7,%%zmm7 \n" + "vpxord %%zmm8,%%zmm8,%%zmm8 \n" + "vpdpbusd %%zmm2,%%zmm0,%%zmm1 \n" + "vpdpbusd %%zmm3,%%zmm0,%%zmm7 \n" + "vpdpbusd %%zmm4,%%zmm0,%%zmm8 \n" + "vpsrld $7,%%zmm1,%%zmm1 \n" + "vpsrld $7,%%zmm7,%%zmm7 \n" + "vpsrld $7,%%zmm8,%%zmm8 \n" + "vpminud %%zmm6,%%zmm7,%%zmm7 \n" + "vpminud %%zmm6,%%zmm8,%%zmm8 \n" + "vpslld $8,%%zmm7,%%zmm7 \n" + "vpslld $16,%%zmm8,%%zmm8 \n" + "vpandd %%zmm5,%%zmm0,%%zmm0 \n" + "vpord %%zmm7,%%zmm1,%%zmm1 \n" + "vpord %%zmm8,%%zmm0,%%zmm0 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[dst]),%%zmm0%{%%k1%}%{z%} \n" + "vpxord %%zmm1,%%zmm1,%%zmm1 \n" + "vpxord %%zmm7,%%zmm7,%%zmm7 \n" + "vpxord %%zmm8,%%zmm8,%%zmm8 \n" + "vpdpbusd %%zmm2,%%zmm0,%%zmm1 \n" + "vpdpbusd %%zmm3,%%zmm0,%%zmm7 \n" + "vpdpbusd %%zmm4,%%zmm0,%%zmm8 \n" + "vpsrld $7,%%zmm1,%%zmm1 \n" + "vpsrld $7,%%zmm7,%%zmm7 \n" + "vpsrld $7,%%zmm8,%%zmm8 \n" + "vpminud %%zmm6,%%zmm7,%%zmm7 \n" + "vpminud %%zmm6,%%zmm8,%%zmm8 \n" + "vpslld $8,%%zmm7,%%zmm7 \n" + "vpslld $16,%%zmm8,%%zmm8 \n" + "vpandd %%zmm5,%%zmm0,%%zmm0 \n" + "vpord %%zmm7,%%zmm1,%%zmm1 \n" + "vpord %%zmm8,%%zmm0,%%zmm0 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [dst] "+r"(dst_argb), [width] "+r"(width), [temp] "=&r"(temp) + : [kSepiaB] "m"(kARGBToSepiaB), [kSepiaG] "m"(kARGBToSepiaG), + [kSepiaR] "m"(kARGBToSepiaR) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7", "xmm8", "k1"); +} +#endif // HAS_ARGBSEPIAROW_AVX512VNNI + +#ifdef HAS_ARGBCOLORMATRIXROW_AVX2 +static const vec8 kShufTranspose4x4 = {0, 4, 8, 12, 1, 5, 9, 13, + 2, 6, 10, 14, 3, 7, 11, 15}; +// Transform ARGB pixels with color matrix. +void ARGBColorMatrixRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + const int8_t* matrix_argb, + int width) { + asm volatile( + "vbroadcasti128 (%3),%%ymm5 \n" + "vbroadcasti128 %4,%%ymm7 \n" + "vpshufd $0x00,%%ymm5,%%ymm2 \n" + "vpshufd $0x55,%%ymm5,%%ymm3 \n" + "vpshufd $0xaa,%%ymm5,%%ymm4 \n" + "vpshufd $0xff,%%ymm5,%%ymm5 \n" + "sub $0x8,%2 \n" + "jl 2f \n" // 8 pixel loop. LABELALIGN "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm7 \n" - "pmaddubsw %%xmm2,%%xmm0 \n" - "pmaddubsw %%xmm2,%%xmm7 \n" - "movdqu (%0),%%xmm6 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "pmaddubsw %%xmm3,%%xmm6 \n" - "pmaddubsw %%xmm3,%%xmm1 \n" - "phaddsw %%xmm7,%%xmm0 \n" - "phaddsw %%xmm1,%%xmm6 \n" - "psraw $0x6,%%xmm0 \n" - "psraw $0x6,%%xmm6 \n" - "packuswb %%xmm0,%%xmm0 \n" - "packuswb %%xmm6,%%xmm6 \n" - "punpcklbw %%xmm6,%%xmm0 \n" - "movdqu (%0),%%xmm1 \n" - "movdqu 0x10(%0),%%xmm7 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "pmaddubsw %%xmm4,%%xmm7 \n" - "phaddsw %%xmm7,%%xmm1 \n" - "movdqu (%0),%%xmm6 \n" - "movdqu 0x10(%0),%%xmm7 \n" - "pmaddubsw %%xmm5,%%xmm6 \n" - "pmaddubsw %%xmm5,%%xmm7 \n" - "phaddsw %%xmm7,%%xmm6 \n" - "psraw $0x6,%%xmm1 \n" - "psraw $0x6,%%xmm6 \n" - "packuswb %%xmm1,%%xmm1 \n" - "packuswb %%xmm6,%%xmm6 \n" - "punpcklbw %%xmm6,%%xmm1 \n" - "movdqa %%xmm0,%%xmm6 \n" - "punpcklwd %%xmm1,%%xmm0 \n" - "punpckhwd %%xmm1,%%xmm6 \n" - "movdqu %%xmm0,(%1) \n" - "movdqu %%xmm6,0x10(%1) \n" - "lea 0x20(%0),%0 \n" - "lea 0x20(%1),%1 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : "r"(matrix_argb) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7"); -} -#endif // HAS_ARGBCOLORMATRIXROW_SSSE3 + "vmovdqu (%0),%%ymm0 \n" + "lea 0x20(%0),%0 \n" + "vpmaddubsw %%ymm2,%%ymm0,%%ymm1 \n" + "vpmaddubsw %%ymm3,%%ymm0,%%ymm6 \n" + "vphaddsw %%ymm6,%%ymm1,%%ymm1 \n" + "vpmaddubsw %%ymm4,%%ymm0,%%ymm6 \n" + "vpmaddubsw %%ymm5,%%ymm0,%%ymm0 \n" + "vphaddsw %%ymm0,%%ymm6,%%ymm6 \n" + "vpsraw $0x6,%%ymm1,%%ymm1 \n" + "vpsraw $0x6,%%ymm6,%%ymm6 \n" + "vpackuswb %%ymm6,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm7,%%ymm1,%%ymm1 \n" + "vmovdqu %%ymm1,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x8,%2 \n" + "jge 1b \n" -#ifdef HAS_ARGBQUANTIZEROW_SSE2 -// Quantize 4 ARGB pixels (16 bytes). -void ARGBQuantizeRow_SSE2(uint8_t* dst_argb, + "2: \n" + "add $0x8,%2 \n" + "jle 99f \n" + + // 1 pixel remainder loop. + LABELALIGN + "3: \n" + "vmovd (%0),%%xmm0 \n" + "lea 0x04(%0),%0 \n" + "vpmaddubsw %%xmm2,%%xmm0,%%xmm1 \n" + "vpmaddubsw %%xmm3,%%xmm0,%%xmm6 \n" + "vphaddsw %%xmm6,%%xmm1,%%xmm1 \n" + "vpmaddubsw %%xmm4,%%xmm0,%%xmm6 \n" + "vpmaddubsw %%xmm5,%%xmm0,%%xmm0 \n" + "vphaddsw %%xmm0,%%xmm6,%%xmm6 \n" + "vpsraw $0x6,%%xmm1,%%xmm1 \n" + "vpsraw $0x6,%%xmm6,%%xmm6 \n" + "vpackuswb %%xmm6,%%xmm1,%%xmm1 \n" + "vpshufb %%xmm7,%%xmm1,%%xmm1 \n" + "vmovd %%xmm1,(%1) \n" + "lea 0x04(%1),%1 \n" + "sub $0x1,%2 \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(matrix_argb), // %3 + "m"(kShufTranspose4x4) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); +} +#endif // HAS_ARGBCOLORMATRIXROW_AVX2 + +#ifdef HAS_ARGBCOLORMATRIXROW_AVX512VNNI +LIBYUV_TARGET_AVX512VNNI +void ARGBColorMatrixRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_argb, + const int8_t* matrix_argb, + int width) { + uintptr_t temp; + asm volatile( + "vpbroadcastd (%[mat]),%%zmm2 \n" + "vpbroadcastd 0x04(%[mat]),%%zmm3 \n" + "vpbroadcastd 0x08(%[mat]),%%zmm4 \n" + "vpbroadcastd 0x0c(%[mat]),%%zmm5 \n" + "vpternlogd $0xff,%%zmm6,%%zmm6,%%zmm6 \n" + "vpsrld $24,%%zmm6,%%zmm6 \n" // 255 + "vpxord %%zmm9,%%zmm9,%%zmm9 \n" // 0 + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src]),%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "vpxord %%zmm1,%%zmm1,%%zmm1 \n" + "vpxord %%zmm7,%%zmm7,%%zmm7 \n" + "vpxord %%zmm8,%%zmm8,%%zmm8 \n" + "vpxord %%zmm10,%%zmm10,%%zmm10 \n" + "vpdpbusd %%zmm2,%%zmm0,%%zmm1 \n" + "vpdpbusd %%zmm3,%%zmm0,%%zmm7 \n" + "vpdpbusd %%zmm4,%%zmm0,%%zmm8 \n" + "vpdpbusd %%zmm5,%%zmm0,%%zmm10 \n" + "vpsrad $6,%%zmm1,%%zmm1 \n" + "vpsrad $6,%%zmm7,%%zmm7 \n" + "vpsrad $6,%%zmm8,%%zmm8 \n" + "vpsrad $6,%%zmm10,%%zmm10 \n" + "vpmaxsd %%zmm9,%%zmm1,%%zmm1 \n" + "vpmaxsd %%zmm9,%%zmm7,%%zmm7 \n" + "vpmaxsd %%zmm9,%%zmm8,%%zmm8 \n" + "vpmaxsd %%zmm9,%%zmm10,%%zmm10 \n" + "vpminud %%zmm6,%%zmm1,%%zmm1 \n" + "vpminud %%zmm6,%%zmm7,%%zmm7 \n" + "vpminud %%zmm6,%%zmm8,%%zmm8 \n" + "vpminud %%zmm6,%%zmm10,%%zmm10 \n" + "vpslld $8,%%zmm7,%%zmm7 \n" + "vpslld $16,%%zmm8,%%zmm8 \n" + "vpslld $24,%%zmm10,%%zmm10 \n" + "vpord %%zmm7,%%zmm1,%%zmm1 \n" + "vpord %%zmm10,%%zmm8,%%zmm8 \n" + "vpord %%zmm8,%%zmm1,%%zmm1 \n" + "vmovdqu32 %%zmm1,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vpxord %%zmm1,%%zmm1,%%zmm1 \n" + "vpxord %%zmm7,%%zmm7,%%zmm7 \n" + "vpxord %%zmm8,%%zmm8,%%zmm8 \n" + "vpxord %%zmm10,%%zmm10,%%zmm10 \n" + "vpdpbusd %%zmm2,%%zmm0,%%zmm1 \n" + "vpdpbusd %%zmm3,%%zmm0,%%zmm7 \n" + "vpdpbusd %%zmm4,%%zmm0,%%zmm8 \n" + "vpdpbusd %%zmm5,%%zmm0,%%zmm10 \n" + "vpsrad $6,%%zmm1,%%zmm1 \n" + "vpsrad $6,%%zmm7,%%zmm7 \n" + "vpsrad $6,%%zmm8,%%zmm8 \n" + "vpsrad $6,%%zmm10,%%zmm10 \n" + "vpmaxsd %%zmm9,%%zmm1,%%zmm1 \n" + "vpmaxsd %%zmm9,%%zmm7,%%zmm7 \n" + "vpmaxsd %%zmm9,%%zmm8,%%zmm8 \n" + "vpmaxsd %%zmm9,%%zmm10,%%zmm10 \n" + "vpminud %%zmm6,%%zmm1,%%zmm1 \n" + "vpminud %%zmm6,%%zmm7,%%zmm7 \n" + "vpminud %%zmm6,%%zmm8,%%zmm8 \n" + "vpminud %%zmm6,%%zmm10,%%zmm10 \n" + "vpslld $8,%%zmm7,%%zmm7 \n" + "vpslld $16,%%zmm8,%%zmm8 \n" + "vpslld $24,%%zmm10,%%zmm10 \n" + "vpord %%zmm7,%%zmm1,%%zmm1 \n" + "vpord %%zmm10,%%zmm8,%%zmm8 \n" + "vpord %%zmm8,%%zmm1,%%zmm1 \n" + "vmovdqu32 %%zmm1,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [width] "+r"(width), + [temp] "=&r"(temp) + : [mat] "r"(matrix_argb) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7", "xmm8", "xmm9", "xmm10", "k1"); +} +#endif // HAS_ARGBCOLORMATRIXROW_AVX512VNNI + +#ifdef HAS_ARGBQUANTIZEROW_AVX2 +// Quantize ARGB pixels. +void ARGBQuantizeRow_AVX2(uint8_t* dst_argb, int scale, int interval_size, int interval_offset, int width) { asm volatile( - "movd %2,%%xmm2 \n" - "movd %3,%%xmm3 \n" - "movd %4,%%xmm4 \n" - "pshuflw $0x40,%%xmm2,%%xmm2 \n" - "pshufd $0x44,%%xmm2,%%xmm2 \n" - "pshuflw $0x40,%%xmm3,%%xmm3 \n" - "pshufd $0x44,%%xmm3,%%xmm3 \n" - "pshuflw $0x40,%%xmm4,%%xmm4 \n" - "pshufd $0x44,%%xmm4,%%xmm4 \n" - "pxor %%xmm5,%%xmm5 \n" - "pcmpeqb %%xmm6,%%xmm6 \n" - "pslld $0x18,%%xmm6 \n" + "vpbroadcastw %2,%%ymm2 \n" + "vpbroadcastw %3,%%ymm3 \n" + "vpbroadcastw %4,%%ymm4 \n" + "vpxor %%ymm5,%%ymm5,%%ymm5 \n" + "vpcmpeqd %%ymm6,%%ymm6,%%ymm6 \n" + "vpslld $0x18,%%ymm6,%%ymm6 \n" + "sub $0x8,%1 \n" + "jl 2f \n" - // 4 pixel loop. + // 8 pixel loop. LABELALIGN "1: \n" - "movdqu (%0),%%xmm0 \n" - "punpcklbw %%xmm5,%%xmm0 \n" - "pmulhuw %%xmm2,%%xmm0 \n" - "movdqu (%0),%%xmm1 \n" - "punpckhbw %%xmm5,%%xmm1 \n" - "pmulhuw %%xmm2,%%xmm1 \n" - "pmullw %%xmm3,%%xmm0 \n" - "movdqu (%0),%%xmm7 \n" - "pmullw %%xmm3,%%xmm1 \n" - "pand %%xmm6,%%xmm7 \n" - "paddw %%xmm4,%%xmm0 \n" - "paddw %%xmm4,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "por %%xmm7,%%xmm0 \n" - "movdqu %%xmm0,(%0) \n" - "lea 0x10(%0),%0 \n" - "sub $0x4,%1 \n" - "jg 1b \n" + "vmovdqu (%0),%%ymm0 \n" + "vpunpckhbw %%ymm5,%%ymm0,%%ymm1 \n" + "vpand %%ymm6,%%ymm0,%%ymm7 \n" + "vpunpcklbw %%ymm5,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm2,%%ymm1,%%ymm1 \n" + "vpmullw %%ymm3,%%ymm0,%%ymm0 \n" + "vpmullw %%ymm3,%%ymm1,%%ymm1 \n" + "vpaddw %%ymm4,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm4,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpandn %%ymm0,%%ymm6,%%ymm0 \n" + "vpor %%ymm7,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%0) \n" + "lea 0x20(%0),%0 \n" + "sub $0x8,%1 \n" + "jge 1b \n" + + "2: \n" + "add $0x8,%1 \n" + "jle 99f \n" + + // 1 pixel remainder loop. + LABELALIGN + "3: \n" + "vmovd (%0),%%xmm0 \n" + "vpand %%xmm6,%%xmm0,%%xmm7 \n" + "vpunpcklbw %%xmm5,%%xmm0,%%xmm0 \n" + "vpmulhuw %%xmm2,%%xmm0,%%xmm0 \n" + "vpmullw %%xmm3,%%xmm0,%%xmm0 \n" + "vpaddw %%xmm4,%%xmm0,%%xmm0 \n" + "vpackuswb %%xmm0,%%xmm0,%%xmm0 \n" + "vpandn %%xmm0,%%xmm6,%%xmm0 \n" + "vpor %%xmm7,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,(%0) \n" + "lea 0x04(%0),%0 \n" + "sub $0x1,%1 \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" : "+r"(dst_argb), // %0 "+r"(width) // %1 - : "r"(scale), // %2 - "r"(interval_size), // %3 - "r"(interval_offset) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7"); + : "m"(scale), // %2 + "m"(interval_size), // %3 + "m"(interval_offset) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); } -#endif // HAS_ARGBQUANTIZEROW_SSE2 +#endif // HAS_ARGBQUANTIZEROW_AVX2 -#ifdef HAS_ARGBSHADEROW_SSE2 -// Shade 4 pixels at a time by specified value. -void ARGBShadeRow_SSE2(const uint8_t* src_argb, +#ifdef HAS_ARGBSHADEROW_AVX2 +// Shade ARGB pixels by specified value. +void ARGBShadeRow_AVX2(const uint8_t* src_argb, uint8_t* dst_argb, int width, uint32_t value) { asm volatile( - "movd %3,%%xmm2 \n" - "punpcklbw %%xmm2,%%xmm2 \n" - "punpcklqdq %%xmm2,%%xmm2 \n" + "vpbroadcastd %3,%%ymm2 \n" + "vpunpcklbw %%ymm2,%%ymm2,%%ymm2 \n" + "sub $0x8,%2 \n" + "jl 2f \n" - // 4 pixel loop. + // 8 pixel loop. LABELALIGN "1: \n" - "movdqu (%0),%%xmm0 \n" - "lea 0x10(%0),%0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "punpcklbw %%xmm0,%%xmm0 \n" - "punpckhbw %%xmm1,%%xmm1 \n" - "pmulhuw %%xmm2,%%xmm0 \n" - "pmulhuw %%xmm2,%%xmm1 \n" - "psrlw $0x8,%%xmm0 \n" - "psrlw $0x8,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x4,%2 \n" - "jg 1b \n" + "vmovdqu (%0),%%ymm0 \n" + "lea 0x20(%0),%0 \n" + "vpunpckhbw %%ymm0,%%ymm0,%%ymm1 \n" + "vpunpcklbw %%ymm0,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm2,%%ymm1,%%ymm1 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x8,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x8,%2 \n" + "jle 99f \n" + + // 1 pixel remainder loop. + LABELALIGN + "3: \n" + "vmovd (%0),%%xmm0 \n" + "lea 0x04(%0),%0 \n" + "vpunpcklbw %%xmm0,%%xmm0,%%xmm0 \n" + "vpmulhuw %%xmm2,%%xmm0,%%xmm0 \n" + "vpsrlw $0x8,%%xmm0,%%xmm0 \n" + "vpackuswb %%xmm0,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,(%1) \n" + "lea 0x04(%1),%1 \n" + "sub $0x1,%2 \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 - : "r"(value) // %3 + : "m"(value) // %3 : "memory", "cc", "xmm0", "xmm1", "xmm2"); } -#endif // HAS_ARGBSHADEROW_SSE2 +#endif // HAS_ARGBSHADEROW_AVX2 #ifdef HAS_ARGBMULTIPLYROW_SSE2 // Multiply 2 rows of ARGB pixels together, 4 pixels at a time. -void ARGBMultiplyRow_SSE2(const uint8_t* src_argb0, +void ARGBMultiplyRow_SSE2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( - - "pxor %%xmm5,%%xmm5 \n" + "pxor %%xmm5,%%xmm5 \n" + "pcmpeqw %%xmm4,%%xmm4 \n" + "psrlw $0xf,%%xmm4 \n" + "psllw $0x7,%%xmm4 \n" // 4 pixel loop. LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "lea 0x10(%0),%0 \n" - "movdqu (%1),%%xmm2 \n" - "lea 0x10(%1),%1 \n" - "movdqu %%xmm0,%%xmm1 \n" - "movdqu %%xmm2,%%xmm3 \n" - "punpcklbw %%xmm0,%%xmm0 \n" - "punpckhbw %%xmm1,%%xmm1 \n" - "punpcklbw %%xmm5,%%xmm2 \n" - "punpckhbw %%xmm5,%%xmm3 \n" - "pmulhuw %%xmm2,%%xmm0 \n" - "pmulhuw %%xmm3,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%2) \n" - "lea 0x10(%2),%2 \n" - "sub $0x4,%3 \n" - "jg 1b \n" - : "+r"(src_argb0), // %0 + "1: \n" + "movdqu (%0),%%xmm0 \n" + "lea 0x10(%0),%0 \n" + "movdqu (%1),%%xmm2 \n" + "lea 0x10(%1),%1 \n" + "movdqa %%xmm0,%%xmm1 \n" + "movdqa %%xmm2,%%xmm3 \n" + "punpcklbw %%xmm5,%%xmm0 \n" + "punpckhbw %%xmm5,%%xmm1 \n" + "punpcklbw %%xmm5,%%xmm2 \n" + "punpckhbw %%xmm5,%%xmm3 \n" + "pmullw %%xmm2,%%xmm0 \n" + "pmullw %%xmm3,%%xmm1 \n" + "paddw %%xmm4,%%xmm0 \n" + "paddw %%xmm4,%%xmm1 \n" + "psrlw $0x8,%%xmm0 \n" + "psrlw $0x8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%2) \n" + "lea 0x10(%2),%2 \n" + "sub $0x4,%3 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 : - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); } #endif // HAS_ARGBMULTIPLYROW_SSE2 #ifdef HAS_ARGBMULTIPLYROW_AVX2 // Multiply 2 rows of ARGB pixels together, 8 pixels at a time. -void ARGBMultiplyRow_AVX2(const uint8_t* src_argb0, +void ARGBMultiplyRow_AVX2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { - asm volatile( + asm volatile("vpxor %%ymm5,%%ymm5,%%ymm5 \n" - "vpxor %%ymm5,%%ymm5,%%ymm5 \n" - - // 4 pixel loop. - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm1 \n" - "lea 0x20(%0),%0 \n" - "vmovdqu (%1),%%ymm3 \n" - "lea 0x20(%1),%1 \n" - "vpunpcklbw %%ymm1,%%ymm1,%%ymm0 \n" - "vpunpckhbw %%ymm1,%%ymm1,%%ymm1 \n" - "vpunpcklbw %%ymm5,%%ymm3,%%ymm2 \n" - "vpunpckhbw %%ymm5,%%ymm3,%%ymm3 \n" - "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" - "vpmulhuw %%ymm3,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,(%2) \n" - "lea 0x20(%2),%2 \n" - "sub $0x8,%3 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_argb0), // %0 - "+r"(src_argb1), // %1 - "+r"(dst_argb), // %2 - "+r"(width) // %3 - : - : "memory", "cc" -#if defined(__AVX2__) - , - "xmm0", "xmm1", "xmm2", "xmm3", "xmm5" -#endif - ); + // 8 pixel loop. + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm1 \n" + "lea 0x20(%0),%0 \n" + "vmovdqu (%1),%%ymm3 \n" + "lea 0x20(%1),%1 \n" + "vpunpcklbw %%ymm1,%%ymm5,%%ymm0 \n" + "vpunpckhbw %%ymm1,%%ymm5,%%ymm1 \n" + "vpsrlw $0x1,%%ymm0,%%ymm0 \n" + "vpsrlw $0x1,%%ymm1,%%ymm1 \n" + "vpunpcklbw %%ymm5,%%ymm3,%%ymm2 \n" + "vpunpckhbw %%ymm5,%%ymm3,%%ymm3 \n" + "vpmulhrsw %%ymm2,%%ymm0,%%ymm0 \n" + "vpmulhrsw %%ymm3,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%2) \n" + "lea 0x20(%2),%2 \n" + "sub $0x8,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(src_argb1), // %1 + "+r"(dst_argb), // %2 + "+r"(width) // %3 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); } #endif // HAS_ARGBMULTIPLYROW_AVX2 #ifdef HAS_ARGBADDROW_SSE2 // Add 2 rows of ARGB pixels together, 4 pixels at a time. -void ARGBAddRow_SSE2(const uint8_t* src_argb0, +void ARGBAddRow_SSE2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( // 4 pixel loop. LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "lea 0x10(%0),%0 \n" - "movdqu (%1),%%xmm1 \n" - "lea 0x10(%1),%1 \n" - "paddusb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%2) \n" - "lea 0x10(%2),%2 \n" - "sub $0x4,%3 \n" - "jg 1b \n" - : "+r"(src_argb0), // %0 + "1: \n" + "movdqu (%0),%%xmm0 \n" + "lea 0x10(%0),%0 \n" + "movdqu (%1),%%xmm1 \n" + "lea 0x10(%1),%1 \n" + "paddusb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%2) \n" + "lea 0x10(%2),%2 \n" + "sub $0x4,%3 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -5377,24 +12734,24 @@ void ARGBAddRow_SSE2(const uint8_t* src_argb0, #ifdef HAS_ARGBADDROW_AVX2 // Add 2 rows of ARGB pixels together, 4 pixels at a time. -void ARGBAddRow_AVX2(const uint8_t* src_argb0, +void ARGBAddRow_AVX2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( // 4 pixel loop. LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "lea 0x20(%0),%0 \n" - "vpaddusb (%1),%%ymm0,%%ymm0 \n" - "lea 0x20(%1),%1 \n" - "vmovdqu %%ymm0,(%2) \n" - "lea 0x20(%2),%2 \n" - "sub $0x8,%3 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_argb0), // %0 + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "lea 0x20(%0),%0 \n" + "vpaddusb (%1),%%ymm0,%%ymm0 \n" + "lea 0x20(%1),%1 \n" + "vmovdqu %%ymm0,(%2) \n" + "lea 0x20(%2),%2 \n" + "sub $0x8,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -5405,24 +12762,24 @@ void ARGBAddRow_AVX2(const uint8_t* src_argb0, #ifdef HAS_ARGBSUBTRACTROW_SSE2 // Subtract 2 rows of ARGB pixels, 4 pixels at a time. -void ARGBSubtractRow_SSE2(const uint8_t* src_argb0, +void ARGBSubtractRow_SSE2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( // 4 pixel loop. LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "lea 0x10(%0),%0 \n" - "movdqu (%1),%%xmm1 \n" - "lea 0x10(%1),%1 \n" - "psubusb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%2) \n" - "lea 0x10(%2),%2 \n" - "sub $0x4,%3 \n" - "jg 1b \n" - : "+r"(src_argb0), // %0 + "1: \n" + "movdqu (%0),%%xmm0 \n" + "lea 0x10(%0),%0 \n" + "movdqu (%1),%%xmm1 \n" + "lea 0x10(%1),%1 \n" + "psubusb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%2) \n" + "lea 0x10(%2),%2 \n" + "sub $0x4,%3 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -5433,24 +12790,24 @@ void ARGBSubtractRow_SSE2(const uint8_t* src_argb0, #ifdef HAS_ARGBSUBTRACTROW_AVX2 // Subtract 2 rows of ARGB pixels, 8 pixels at a time. -void ARGBSubtractRow_AVX2(const uint8_t* src_argb0, +void ARGBSubtractRow_AVX2(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( // 4 pixel loop. LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "lea 0x20(%0),%0 \n" - "vpsubusb (%1),%%ymm0,%%ymm0 \n" - "lea 0x20(%1),%1 \n" - "vmovdqu %%ymm0,(%2) \n" - "lea 0x20(%2),%2 \n" - "sub $0x8,%3 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_argb0), // %0 + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "lea 0x20(%0),%0 \n" + "vpsubusb (%1),%%ymm0,%%ymm0 \n" + "lea 0x20(%1),%1 \n" + "vmovdqu %%ymm0,(%2) \n" + "lea 0x20(%2),%2 \n" + "sub $0x8,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -5459,730 +12816,796 @@ void ARGBSubtractRow_AVX2(const uint8_t* src_argb0, } #endif // HAS_ARGBSUBTRACTROW_AVX2 -#ifdef HAS_SOBELXROW_SSE2 +#ifdef HAS_SOBELXROW_AVX2 // SobelX as a matrix is // -1 0 1 // -2 0 2 // -1 0 1 -void SobelXRow_SSE2(const uint8_t* src_y0, +void SobelXRow_AVX2(const uint8_t* src_y0, const uint8_t* src_y1, const uint8_t* src_y2, uint8_t* dst_sobelx, int width) { asm volatile( - "sub %0,%1 \n" - "sub %0,%2 \n" - "sub %0,%3 \n" - "pxor %%xmm5,%%xmm5 \n" + "sub %0,%1 \n" + "sub %0,%2 \n" + "sub %0,%3 \n" - // 8 pixel loop. + // 16 pixel loop. LABELALIGN "1: \n" - "movq (%0),%%xmm0 \n" - "movq 0x2(%0),%%xmm1 \n" - "punpcklbw %%xmm5,%%xmm0 \n" - "punpcklbw %%xmm5,%%xmm1 \n" - "psubw %%xmm1,%%xmm0 \n" - "movq 0x00(%0,%1,1),%%xmm1 \n" - "movq 0x02(%0,%1,1),%%xmm2 \n" - "punpcklbw %%xmm5,%%xmm1 \n" - "punpcklbw %%xmm5,%%xmm2 \n" - "psubw %%xmm2,%%xmm1 \n" - "movq 0x00(%0,%2,1),%%xmm2 \n" - "movq 0x02(%0,%2,1),%%xmm3 \n" - "punpcklbw %%xmm5,%%xmm2 \n" - "punpcklbw %%xmm5,%%xmm3 \n" - "psubw %%xmm3,%%xmm2 \n" - "paddw %%xmm2,%%xmm0 \n" - "paddw %%xmm1,%%xmm0 \n" - "paddw %%xmm1,%%xmm0 \n" - "pxor %%xmm1,%%xmm1 \n" - "psubw %%xmm0,%%xmm1 \n" - "pmaxsw %%xmm1,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "movq %%xmm0,0x00(%0,%3,1) \n" - "lea 0x8(%0),%0 \n" - "sub $0x8,%4 \n" - "jg 1b \n" + "vpmovzxbw (%0),%%ymm0 \n" + "vpmovzxbw 0x02(%0),%%ymm1 \n" + "vpsubw %%ymm1,%%ymm0,%%ymm0 \n" + "vpmovzxbw 0x00(%0,%1,1),%%ymm1 \n" + "vpmovzxbw 0x02(%0,%1,1),%%ymm2 \n" + "vpsubw %%ymm2,%%ymm1,%%ymm1 \n" + "vpmovzxbw 0x00(%0,%2,1),%%ymm2 \n" + "vpmovzxbw 0x02(%0,%2,1),%%ymm3 \n" + "vpsubw %%ymm3,%%ymm2,%%ymm2 \n" + "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm1,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm1,%%ymm0,%%ymm0 \n" + "vpabsw %%ymm0,%%ymm0 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%xmm0,0x00(%0,%3,1) \n" + "lea 0x10(%0),%0 \n" + "sub $0x10,%4 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_y0), // %0 "+r"(src_y1), // %1 "+r"(src_y2), // %2 "+r"(dst_sobelx), // %3 "+r"(width) // %4 : - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); } -#endif // HAS_SOBELXROW_SSE2 +#endif // HAS_SOBELXROW_AVX2 -#ifdef HAS_SOBELYROW_SSE2 +#ifdef HAS_SOBELYROW_AVX2 // SobelY as a matrix is // -1 -2 -1 // 0 0 0 // 1 2 1 -void SobelYRow_SSE2(const uint8_t* src_y0, +void SobelYRow_AVX2(const uint8_t* src_y0, const uint8_t* src_y1, uint8_t* dst_sobely, int width) { asm volatile( - "sub %0,%1 \n" - "sub %0,%2 \n" - "pxor %%xmm5,%%xmm5 \n" + "sub %0,%1 \n" + "sub %0,%2 \n" - // 8 pixel loop. + // 16 pixel loop. LABELALIGN "1: \n" - "movq (%0),%%xmm0 \n" - "movq 0x00(%0,%1,1),%%xmm1 \n" - "punpcklbw %%xmm5,%%xmm0 \n" - "punpcklbw %%xmm5,%%xmm1 \n" - "psubw %%xmm1,%%xmm0 \n" - "movq 0x1(%0),%%xmm1 \n" - "movq 0x01(%0,%1,1),%%xmm2 \n" - "punpcklbw %%xmm5,%%xmm1 \n" - "punpcklbw %%xmm5,%%xmm2 \n" - "psubw %%xmm2,%%xmm1 \n" - "movq 0x2(%0),%%xmm2 \n" - "movq 0x02(%0,%1,1),%%xmm3 \n" - "punpcklbw %%xmm5,%%xmm2 \n" - "punpcklbw %%xmm5,%%xmm3 \n" - "psubw %%xmm3,%%xmm2 \n" - "paddw %%xmm2,%%xmm0 \n" - "paddw %%xmm1,%%xmm0 \n" - "paddw %%xmm1,%%xmm0 \n" - "pxor %%xmm1,%%xmm1 \n" - "psubw %%xmm0,%%xmm1 \n" - "pmaxsw %%xmm1,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "movq %%xmm0,0x00(%0,%2,1) \n" - "lea 0x8(%0),%0 \n" - "sub $0x8,%3 \n" - "jg 1b \n" + "vpmovzxbw (%0),%%ymm0 \n" + "vpmovzxbw 0x00(%0,%1,1),%%ymm1 \n" + "vpsubw %%ymm1,%%ymm0,%%ymm0 \n" + "vpmovzxbw 0x01(%0),%%ymm1 \n" + "vpmovzxbw 0x01(%0,%1,1),%%ymm2 \n" + "vpsubw %%ymm2,%%ymm1,%%ymm1 \n" + "vpmovzxbw 0x02(%0),%%ymm2 \n" + "vpmovzxbw 0x02(%0,%1,1),%%ymm3 \n" + "vpsubw %%ymm3,%%ymm2,%%ymm2 \n" + "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm1,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm1,%%ymm0,%%ymm0 \n" + "vpabsw %%ymm0,%%ymm0 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%xmm0,0x00(%0,%2,1) \n" + "lea 0x10(%0),%0 \n" + "sub $0x10,%3 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_y0), // %0 "+r"(src_y1), // %1 "+r"(dst_sobely), // %2 "+r"(width) // %3 : - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); } -#endif // HAS_SOBELYROW_SSE2 +#endif // HAS_SOBELYROW_AVX2 -#ifdef HAS_SOBELROW_SSE2 +#ifdef HAS_SOBELROW_AVX2 // Adds Sobel X and Sobel Y and stores Sobel into ARGB. // A = 255 // R = Sobel // G = Sobel // B = Sobel -void SobelRow_SSE2(const uint8_t* src_sobelx, +void SobelRow_AVX2(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width) { asm volatile( - "sub %0,%1 \n" - "pcmpeqb %%xmm5,%%xmm5 \n" - "pslld $0x18,%%xmm5 \n" + "sub %0,%1 \n" + "vpcmpeqd %%ymm5,%%ymm5,%%ymm5 \n" + "vpslld $0x18,%%ymm5,%%ymm5 \n" - // 8 pixel loop. + // 16 pixel loop. LABELALIGN "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x00(%0,%1,1),%%xmm1 \n" - "lea 0x10(%0),%0 \n" - "paddusb %%xmm1,%%xmm0 \n" - "movdqa %%xmm0,%%xmm2 \n" - "punpcklbw %%xmm0,%%xmm2 \n" - "punpckhbw %%xmm0,%%xmm0 \n" - "movdqa %%xmm2,%%xmm1 \n" - "punpcklwd %%xmm2,%%xmm1 \n" - "punpckhwd %%xmm2,%%xmm2 \n" - "por %%xmm5,%%xmm1 \n" - "por %%xmm5,%%xmm2 \n" - "movdqa %%xmm0,%%xmm3 \n" - "punpcklwd %%xmm0,%%xmm3 \n" - "punpckhwd %%xmm0,%%xmm0 \n" - "por %%xmm5,%%xmm3 \n" - "por %%xmm5,%%xmm0 \n" - "movdqu %%xmm1,(%2) \n" - "movdqu %%xmm2,0x10(%2) \n" - "movdqu %%xmm3,0x20(%2) \n" - "movdqu %%xmm0,0x30(%2) \n" - "lea 0x40(%2),%2 \n" - "sub $0x10,%3 \n" - "jg 1b \n" + "vmovdqu (%0),%%xmm0 \n" + "vpaddusb 0x00(%0,%1,1),%%xmm0,%%xmm0 \n" + "lea 0x10(%0),%0 \n" + "vpshufd $0xd8,%%xmm0,%%xmm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpunpcklbw %%ymm0,%%ymm0,%%ymm0 \n" + "vpunpcklwd %%ymm0,%%ymm0,%%ymm1 \n" + "vpunpckhwd %%ymm0,%%ymm0,%%ymm0 \n" + "vpor %%ymm5,%%ymm1,%%ymm1 \n" + "vpor %%ymm5,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm1,(%2) \n" + "vmovdqu %%ymm0,0x20(%2) \n" + "lea 0x40(%2),%2 \n" + "sub $0x10,%3 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_sobelx), // %0 "+r"(src_sobely), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 : - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); + : "memory", "cc", "xmm0", "xmm1", "xmm5"); } -#endif // HAS_SOBELROW_SSE2 +#endif // HAS_SOBELROW_AVX2 -#ifdef HAS_SOBELTOPLANEROW_SSE2 +#ifdef HAS_SOBELTOPLANEROW_AVX2 // Adds Sobel X and Sobel Y and stores Sobel into a plane. -void SobelToPlaneRow_SSE2(const uint8_t* src_sobelx, +void SobelToPlaneRow_AVX2(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_y, int width) { - asm volatile( - "sub %0,%1 \n" - "pcmpeqb %%xmm5,%%xmm5 \n" - "pslld $0x18,%%xmm5 \n" + asm volatile("sub %0,%1 \n" - // 8 pixel loop. - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x00(%0,%1,1),%%xmm1 \n" - "lea 0x10(%0),%0 \n" - "paddusb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%2) \n" - "lea 0x10(%2),%2 \n" - "sub $0x10,%3 \n" - "jg 1b \n" - : "+r"(src_sobelx), // %0 - "+r"(src_sobely), // %1 - "+r"(dst_y), // %2 - "+r"(width) // %3 - : - : "memory", "cc", "xmm0", "xmm1"); + // 32 pixel loop. + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpaddusb 0x00(%0,%1,1),%%ymm0,%%ymm0 \n" + "lea 0x20(%0),%0 \n" + "vmovdqu %%ymm0,(%2) \n" + "lea 0x20(%2),%2 \n" + "sub $0x20,%3 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_sobelx), // %0 + "+r"(src_sobely), // %1 + "+r"(dst_y), // %2 + "+r"(width) // %3 + : + : "memory", "cc", "xmm0"); } -#endif // HAS_SOBELTOPLANEROW_SSE2 +#endif // HAS_SOBELTOPLANEROW_AVX2 -#ifdef HAS_SOBELXYROW_SSE2 +#ifdef HAS_SOBELXYROW_AVX2 // Mixes Sobel X, Sobel Y and Sobel into ARGB. // A = 255 // R = Sobel X // G = Sobel // B = Sobel Y -void SobelXYRow_SSE2(const uint8_t* src_sobelx, +void SobelXYRow_AVX2(const uint8_t* src_sobelx, const uint8_t* src_sobely, uint8_t* dst_argb, int width) { asm volatile( - "sub %0,%1 \n" - "pcmpeqb %%xmm5,%%xmm5 \n" + "sub %0,%1 \n" + "vpcmpeqd %%ymm5,%%ymm5,%%ymm5 \n" - // 8 pixel loop. + // 16 pixel loop. LABELALIGN "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x00(%0,%1,1),%%xmm1 \n" - "lea 0x10(%0),%0 \n" - "movdqa %%xmm0,%%xmm2 \n" - "paddusb %%xmm1,%%xmm2 \n" - "movdqa %%xmm0,%%xmm3 \n" - "punpcklbw %%xmm5,%%xmm3 \n" - "punpckhbw %%xmm5,%%xmm0 \n" - "movdqa %%xmm1,%%xmm4 \n" - "punpcklbw %%xmm2,%%xmm4 \n" - "punpckhbw %%xmm2,%%xmm1 \n" - "movdqa %%xmm4,%%xmm6 \n" - "punpcklwd %%xmm3,%%xmm6 \n" - "punpckhwd %%xmm3,%%xmm4 \n" - "movdqa %%xmm1,%%xmm7 \n" - "punpcklwd %%xmm0,%%xmm7 \n" - "punpckhwd %%xmm0,%%xmm1 \n" - "movdqu %%xmm6,(%2) \n" - "movdqu %%xmm4,0x10(%2) \n" - "movdqu %%xmm7,0x20(%2) \n" - "movdqu %%xmm1,0x30(%2) \n" - "lea 0x40(%2),%2 \n" - "sub $0x10,%3 \n" - "jg 1b \n" + "vmovdqu (%0),%%xmm0 \n" + "vmovdqu 0x00(%0,%1,1),%%xmm1 \n" + "lea 0x10(%0),%0 \n" + "vpaddusb %%xmm1,%%xmm0,%%xmm2 \n" + "vpshufd $0xd8,%%xmm0,%%xmm0 \n" + "vpshufd $0xd8,%%xmm1,%%xmm1 \n" + "vpshufd $0xd8,%%xmm2,%%xmm2 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpermq $0xd8,%%ymm2,%%ymm2 \n" + "vpunpcklbw %%ymm2,%%ymm1,%%ymm1 \n" + "vpunpcklbw %%ymm5,%%ymm0,%%ymm0 \n" + "vpunpcklwd %%ymm0,%%ymm1,%%ymm2 \n" + "vpunpckhwd %%ymm0,%%ymm1,%%ymm0 \n" + "vmovdqu %%ymm2,(%2) \n" + "vmovdqu %%ymm0,0x20(%2) \n" + "lea 0x40(%2),%2 \n" + "sub $0x10,%3 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_sobelx), // %0 "+r"(src_sobely), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 : - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7"); + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm5"); } -#endif // HAS_SOBELXYROW_SSE2 +#endif // HAS_SOBELXYROW_AVX2 -#ifdef HAS_COMPUTECUMULATIVESUMROW_SSE2 -// Creates a table of cumulative sums where each value is a sum of all values -// above and to the left of the value, inclusive of the value. -void ComputeCumulativeSumRow_SSE2(const uint8_t* row, +#ifdef HAS_COMPUTECUMULATIVESUMROW_AVX2 +static const uvec8 kCumSumTranspose = {0, 4, 8, 12, 1, 5, 9, 13, + 2, 6, 10, 14, 3, 7, 11, 15}; +static const vec8 kCumSumMaddLo[2] = { + {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, + {1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0}}; +static const vec8 kCumSumMaddHi[2] = { + {1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0}, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}; + +void ComputeCumulativeSumRow_AVX2(const uint8_t* row, int32_t* cumsum, const int32_t* previous_cumsum, int width) { asm volatile( - "pxor %%xmm0,%%xmm0 \n" - "pxor %%xmm1,%%xmm1 \n" - "sub $0x4,%3 \n" - "jl 49f \n" - "test $0xf,%1 \n" - "jne 49f \n" + "vpxor %%xmm0,%%xmm0,%%xmm0 \n" + "vbroadcasti128 %4,%%ymm5 \n" + "vmovdqu %5,%%ymm6 \n" + "vmovdqu %6,%%ymm7 \n" + "vpcmpeqd %%ymm1,%%ymm1,%%ymm1 \n" + "vpsrlw $0xf,%%ymm1,%%ymm1 \n" + "sub $0x4,%3 \n" + "jl 49f \n" // 4 pixel loop. LABELALIGN - "40: \n" - "movdqu (%0),%%xmm2 \n" - "lea 0x10(%0),%0 \n" - "movdqa %%xmm2,%%xmm4 \n" - "punpcklbw %%xmm1,%%xmm2 \n" - "movdqa %%xmm2,%%xmm3 \n" - "punpcklwd %%xmm1,%%xmm2 \n" - "punpckhwd %%xmm1,%%xmm3 \n" - "punpckhbw %%xmm1,%%xmm4 \n" - "movdqa %%xmm4,%%xmm5 \n" - "punpcklwd %%xmm1,%%xmm4 \n" - "punpckhwd %%xmm1,%%xmm5 \n" - "paddd %%xmm2,%%xmm0 \n" - "movdqu (%2),%%xmm2 \n" - "paddd %%xmm0,%%xmm2 \n" - "paddd %%xmm3,%%xmm0 \n" - "movdqu 0x10(%2),%%xmm3 \n" - "paddd %%xmm0,%%xmm3 \n" - "paddd %%xmm4,%%xmm0 \n" - "movdqu 0x20(%2),%%xmm4 \n" - "paddd %%xmm0,%%xmm4 \n" - "paddd %%xmm5,%%xmm0 \n" - "movdqu 0x30(%2),%%xmm5 \n" - "lea 0x40(%2),%2 \n" - "paddd %%xmm0,%%xmm5 \n" - "movdqu %%xmm2,(%1) \n" - "movdqu %%xmm3,0x10(%1) \n" - "movdqu %%xmm4,0x20(%1) \n" - "movdqu %%xmm5,0x30(%1) \n" - "lea 0x40(%1),%1 \n" - "sub $0x4,%3 \n" - "jge 40b \n" + "40: \n" + "vbroadcasti128 (%0),%%ymm2 \n" + "lea 0x10(%0),%0 \n" + "vpshufb %%ymm5,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm6,%%ymm2,%%ymm3 \n" + "vpmaddubsw %%ymm7,%%ymm2,%%ymm4 \n" + "vpmaddwd %%ymm1,%%ymm3,%%ymm3 \n" + "vpmaddwd %%ymm1,%%ymm4,%%ymm4 \n" + "vperm2i128 $0x11,%%ymm4,%%ymm4,%%ymm2 \n" + "vpaddd (%2),%%ymm3,%%ymm3 \n" + "vpaddd 0x20(%2),%%ymm4,%%ymm4 \n" + "lea 0x40(%2),%2 \n" + "vpaddd %%ymm0,%%ymm3,%%ymm3 \n" + "vpaddd %%ymm0,%%ymm4,%%ymm4 \n" + "vpaddd %%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm3,(%1) \n" + "vmovdqu %%ymm4,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x4,%3 \n" + "jge 40b \n" - "49: \n" - "add $0x3,%3 \n" - "jl 19f \n" + "49: \n" + "add $0x3,%3 \n" + "jl 19f \n" // 1 pixel loop. LABELALIGN - "10: \n" - "movd (%0),%%xmm2 \n" - "lea 0x4(%0),%0 \n" - "punpcklbw %%xmm1,%%xmm2 \n" - "punpcklwd %%xmm1,%%xmm2 \n" - "paddd %%xmm2,%%xmm0 \n" - "movdqu (%2),%%xmm2 \n" - "lea 0x10(%2),%2 \n" - "paddd %%xmm0,%%xmm2 \n" - "movdqu %%xmm2,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x1,%3 \n" - "jge 10b \n" + "10: \n" + "vpmovzxbd (%0),%%xmm2 \n" + "lea 0x4(%0),%0 \n" + "vpaddd %%xmm2,%%xmm0,%%xmm0 \n" + "vpaddd (%2),%%xmm0,%%xmm2 \n" + "lea 0x10(%2),%2 \n" + "vmovdqu %%xmm2,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x1,%3 \n" + "jge 10b \n" - "19: \n" + "19: \n" + "vzeroupper \n" : "+r"(row), // %0 "+r"(cumsum), // %1 "+r"(previous_cumsum), // %2 "+r"(width) // %3 - : - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + : "m"(kCumSumTranspose), // %4 + "m"(kCumSumMaddLo), // %5 + "m"(kCumSumMaddHi) // %6 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); } -#endif // HAS_COMPUTECUMULATIVESUMROW_SSE2 +#endif // HAS_COMPUTECUMULATIVESUMROW_AVX2 -#ifdef HAS_CUMULATIVESUMTOAVERAGEROW_SSE2 -void CumulativeSumToAverageRow_SSE2(const int32_t* topleft, +#ifdef HAS_CUMULATIVESUMTOAVERAGEROW_AVX2 +void CumulativeSumToAverageRow_AVX2(const int32_t* topleft, const int32_t* botleft, int width, int area, uint8_t* dst, int count) { asm volatile( - "movd %5,%%xmm5 \n" - "cvtdq2ps %%xmm5,%%xmm5 \n" - "rcpss %%xmm5,%%xmm4 \n" - "pshufd $0x0,%%xmm4,%%xmm4 \n" - "sub $0x4,%3 \n" - "jl 49f \n" - "cmpl $0x80,%5 \n" - "ja 40f \n" + "vpxor %%xmm5,%%xmm5,%%xmm5 \n" + "vcvtsi2ssl %5,%%xmm5,%%xmm5 \n" + "vpcmpeqd %%xmm4,%%xmm4,%%xmm4 \n" + "vpslld $25,%%xmm4,%%xmm4 \n" + "vpsrld $2,%%xmm4,%%xmm4 \n" + "vdivss %%xmm5,%%xmm4,%%xmm4 \n" + "vpshufd $0x0,%%xmm4,%%xmm4 \n" + "subl $0x4,%3 \n" + "jl 19f \n" + "vinserti128 $0x1,%%xmm4,%%ymm4,%%ymm4 \n" + "cmpl $0x80,%5 \n" + "ja 10f \n" + "cmpl $0x1,%5 \n" + "jle 10f \n" - "pshufd $0x0,%%xmm5,%%xmm5 \n" - "pcmpeqb %%xmm6,%%xmm6 \n" - "psrld $0x10,%%xmm6 \n" - "cvtdq2ps %%xmm6,%%xmm6 \n" - "addps %%xmm6,%%xmm5 \n" - "mulps %%xmm4,%%xmm5 \n" - "cvtps2dq %%xmm5,%%xmm5 \n" - "packssdw %%xmm5,%%xmm5 \n" + "vpcmpeqb %%xmm6,%%xmm6,%%xmm6 \n" + "vpsrld $0x10,%%xmm6,%%xmm6 \n" + "vcvtdq2ps %%xmm6,%%xmm6 \n" + "vaddss %%xmm6,%%xmm5,%%xmm6 \n" + "vmulss %%xmm4,%%xmm6,%%xmm6 \n" + "vcvtps2dq %%xmm6,%%xmm6 \n" + "vpackusdw %%xmm6,%%xmm6,%%xmm6 \n" + "vpbroadcastw %%xmm6,%%ymm6 \n" // 4 pixel small loop. LABELALIGN - "4: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x30(%0),%%xmm3 \n" - "psubd 0x00(%0,%4,4),%%xmm0 \n" - "psubd 0x10(%0,%4,4),%%xmm1 \n" - "psubd 0x20(%0,%4,4),%%xmm2 \n" - "psubd 0x30(%0,%4,4),%%xmm3 \n" - "lea 0x40(%0),%0 \n" - "psubd (%1),%%xmm0 \n" - "psubd 0x10(%1),%%xmm1 \n" - "psubd 0x20(%1),%%xmm2 \n" - "psubd 0x30(%1),%%xmm3 \n" - "paddd 0x00(%1,%4,4),%%xmm0 \n" - "paddd 0x10(%1,%4,4),%%xmm1 \n" - "paddd 0x20(%1,%4,4),%%xmm2 \n" - "paddd 0x30(%1,%4,4),%%xmm3 \n" - "lea 0x40(%1),%1 \n" - "packssdw %%xmm1,%%xmm0 \n" - "packssdw %%xmm3,%%xmm2 \n" - "pmulhuw %%xmm5,%%xmm0 \n" - "pmulhuw %%xmm5,%%xmm2 \n" - "packuswb %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%2) \n" - "lea 0x10(%2),%2 \n" - "sub $0x4,%3 \n" - "jge 4b \n" - "jmp 49f \n" + "4: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vpsubd 0x00(%0,%4,4),%%ymm0,%%ymm0\n" + "vpsubd 0x20(%0,%4,4),%%ymm1,%%ymm1\n" + "lea 0x40(%0),%0 \n" + "vpsubd (%1),%%ymm0,%%ymm0 \n" + "vpsubd 0x20(%1),%%ymm1,%%ymm1 \n" + "vpaddd 0x00(%1,%4,4),%%ymm0,%%ymm0\n" + "vpaddd 0x20(%1,%4,4),%%ymm1,%%ymm1\n" + "lea 0x40(%1),%1 \n" + "vpackusdw %%ymm1,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm6,%%ymm0,%%ymm0 \n" + "vextracti128 $0x1,%%ymm0,%%xmm1 \n" + "vpackuswb %%xmm1,%%xmm0,%%xmm0 \n" + "vpshufd $0xd8,%%xmm0,%%xmm0 \n" + "vmovdqu %%xmm0,(%2) \n" + "lea 0x10(%2),%2 \n" + "subl $0x4,%3 \n" + "jge 4b \n" + "vzeroupper \n" + "jmp 19f \n" - // 4 pixel loop + // 4 pixel loop. LABELALIGN - "40: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x20(%0),%%xmm2 \n" - "movdqu 0x30(%0),%%xmm3 \n" - "psubd 0x00(%0,%4,4),%%xmm0 \n" - "psubd 0x10(%0,%4,4),%%xmm1 \n" - "psubd 0x20(%0,%4,4),%%xmm2 \n" - "psubd 0x30(%0,%4,4),%%xmm3 \n" - "lea 0x40(%0),%0 \n" - "psubd (%1),%%xmm0 \n" - "psubd 0x10(%1),%%xmm1 \n" - "psubd 0x20(%1),%%xmm2 \n" - "psubd 0x30(%1),%%xmm3 \n" - "paddd 0x00(%1,%4,4),%%xmm0 \n" - "paddd 0x10(%1,%4,4),%%xmm1 \n" - "paddd 0x20(%1,%4,4),%%xmm2 \n" - "paddd 0x30(%1,%4,4),%%xmm3 \n" - "lea 0x40(%1),%1 \n" - "cvtdq2ps %%xmm0,%%xmm0 \n" - "cvtdq2ps %%xmm1,%%xmm1 \n" - "mulps %%xmm4,%%xmm0 \n" - "mulps %%xmm4,%%xmm1 \n" - "cvtdq2ps %%xmm2,%%xmm2 \n" - "cvtdq2ps %%xmm3,%%xmm3 \n" - "mulps %%xmm4,%%xmm2 \n" - "mulps %%xmm4,%%xmm3 \n" - "cvtps2dq %%xmm0,%%xmm0 \n" - "cvtps2dq %%xmm1,%%xmm1 \n" - "cvtps2dq %%xmm2,%%xmm2 \n" - "cvtps2dq %%xmm3,%%xmm3 \n" - "packssdw %%xmm1,%%xmm0 \n" - "packssdw %%xmm3,%%xmm2 \n" - "packuswb %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%2) \n" - "lea 0x10(%2),%2 \n" - "sub $0x4,%3 \n" - "jge 40b \n" + "10: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vpsubd 0x00(%0,%4,4),%%ymm0,%%ymm0\n" + "vpsubd 0x20(%0,%4,4),%%ymm1,%%ymm1\n" + "lea 0x40(%0),%0 \n" + "vpsubd (%1),%%ymm0,%%ymm0 \n" + "vpsubd 0x20(%1),%%ymm1,%%ymm1 \n" + "vpaddd 0x00(%1,%4,4),%%ymm0,%%ymm0\n" + "vpaddd 0x20(%1,%4,4),%%ymm1,%%ymm1\n" + "lea 0x40(%1),%1 \n" + "vcvtdq2ps %%ymm0,%%ymm0 \n" + "vcvtdq2ps %%ymm1,%%ymm1 \n" + "vmulps %%ymm4,%%ymm0,%%ymm0 \n" + "vmulps %%ymm4,%%ymm1,%%ymm1 \n" + "vcvttps2dq %%ymm0,%%ymm0 \n" + "vcvttps2dq %%ymm1,%%ymm1 \n" + "vpackusdw %%ymm1,%%ymm0,%%ymm0 \n" + "vextracti128 $0x1,%%ymm0,%%xmm1 \n" + "vpackuswb %%xmm1,%%xmm0,%%xmm0 \n" + "vpshufd $0xd8,%%xmm0,%%xmm0 \n" + "vmovdqu %%xmm0,(%2) \n" + "lea 0x10(%2),%2 \n" + "subl $0x4,%3 \n" + "jge 10b \n" + "vzeroupper \n" - "49: \n" - "add $0x3,%3 \n" - "jl 19f \n" + "19: \n" + "addl $0x3,%3 \n" + "jl 99f \n" - // 1 pixel loop + // 1 pixel loop. LABELALIGN - "10: \n" - "movdqu (%0),%%xmm0 \n" - "psubd 0x00(%0,%4,4),%%xmm0 \n" - "lea 0x10(%0),%0 \n" - "psubd (%1),%%xmm0 \n" - "paddd 0x00(%1,%4,4),%%xmm0 \n" - "lea 0x10(%1),%1 \n" - "cvtdq2ps %%xmm0,%%xmm0 \n" - "mulps %%xmm4,%%xmm0 \n" - "cvtps2dq %%xmm0,%%xmm0 \n" - "packssdw %%xmm0,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "movd %%xmm0,(%2) \n" - "lea 0x4(%2),%2 \n" - "sub $0x1,%3 \n" - "jge 10b \n" - "19: \n" - : "+r"(topleft), // %0 - "+r"(botleft), // %1 - "+r"(dst), // %2 - "+rm"(count) // %3 - : "r"((intptr_t)(width)), // %4 - "rm"(area) // %5 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); + "20: \n" + "vmovdqu (%0),%%xmm0 \n" + "vpsubd 0x00(%0,%4,4),%%xmm0,%%xmm0\n" + "lea 0x10(%0),%0 \n" + "vmovdqu 0x00(%1,%4,4),%%xmm1 \n" + "vpsubd (%1),%%xmm1,%%xmm1 \n" + "lea 0x10(%1),%1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vcvtdq2ps %%xmm0,%%xmm0 \n" + "vmulps %%xmm4,%%xmm0,%%xmm0 \n" + "vcvttps2dq %%xmm0,%%xmm0 \n" + "vpackusdw %%xmm0,%%xmm0,%%xmm0 \n" + "vpackuswb %%xmm0,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,(%2) \n" + "lea 0x4(%2),%2 \n" + "subl $0x1,%3 \n" + "jge 20b \n" + "99: \n" + : "+r"(topleft), // %0 + "+r"(botleft), // %1 + "+r"(dst), // %2 + "+rm"(count) // %3 + : "r"((ptrdiff_t)(width)), // %4 + "rm"(area) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm4", "xmm5", "xmm6"); } -#endif // HAS_CUMULATIVESUMTOAVERAGEROW_SSE2 +#endif // HAS_CUMULATIVESUMTOAVERAGEROW_AVX2 -#ifdef HAS_ARGBAFFINEROW_SSE2 +#ifdef HAS_ARGBAFFINEROW_AVX2 +static const float kAffineRamp[8] = {0.0f, 1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, 7.0f}; +static const float kAffineStep8 = 8.0f; // Copy ARGB pixels from source image with slope to a row of destination. LIBYUV_API -void ARGBAffineRow_SSE2(const uint8_t* src_argb, +void ARGBAffineRow_AVX2(const uint8_t* src_argb, int src_argb_stride, uint8_t* dst_argb, const float* src_dudv, int width) { - intptr_t src_argb_stride_temp = src_argb_stride; - intptr_t temp; asm volatile( - "movq (%3),%%xmm2 \n" - "movq 0x08(%3),%%xmm7 \n" - "shl $0x10,%1 \n" - "add $0x4,%1 \n" - "movd %1,%%xmm5 \n" - "sub $0x4,%4 \n" - "jl 49f \n" + "vbroadcastss (%[uv]),%%ymm2 \n" + "vbroadcastss 0x04(%[uv]),%%ymm3 \n" + "vbroadcastss 0x08(%[uv]),%%ymm4 \n" + "vbroadcastss 0x0c(%[uv]),%%ymm5 \n" + "vmovups %[ramp],%%ymm0 \n" + "vmulps %%ymm0,%%ymm4,%%ymm1 \n" + "vaddps %%ymm1,%%ymm2,%%ymm2 \n" + "vmulps %%ymm0,%%ymm5,%%ymm1 \n" + "vaddps %%ymm1,%%ymm3,%%ymm3 \n" + "vbroadcastss %[step8],%%ymm0 \n" + "vmulps %%ymm0,%%ymm4,%%ymm4 \n" + "vmulps %%ymm0,%%ymm5,%%ymm5 \n" + "vpbroadcastd %[stride],%%ymm6 \n" + "sub $0x8,%[width] \n" + "jl 2f \n" - "pshufd $0x44,%%xmm7,%%xmm7 \n" - "pshufd $0x0,%%xmm5,%%xmm5 \n" - "movdqa %%xmm2,%%xmm0 \n" - "addps %%xmm7,%%xmm0 \n" - "movlhps %%xmm0,%%xmm2 \n" - "movdqa %%xmm7,%%xmm4 \n" - "addps %%xmm4,%%xmm4 \n" - "movdqa %%xmm2,%%xmm3 \n" - "addps %%xmm4,%%xmm3 \n" - "addps %%xmm4,%%xmm4 \n" - - // 4 pixel loop - LABELALIGN - "40: \n" - "cvttps2dq %%xmm2,%%xmm0 \n" // x,y float->int first 2 - "cvttps2dq %%xmm3,%%xmm1 \n" // x,y float->int next 2 - "packssdw %%xmm1,%%xmm0 \n" // x, y as 8 shorts - "pmaddwd %%xmm5,%%xmm0 \n" // off = x*4 + y*stride - "movd %%xmm0,%k1 \n" - "pshufd $0x39,%%xmm0,%%xmm0 \n" - "movd %%xmm0,%k5 \n" - "pshufd $0x39,%%xmm0,%%xmm0 \n" - "movd 0x00(%0,%1,1),%%xmm1 \n" - "movd 0x00(%0,%5,1),%%xmm6 \n" - "punpckldq %%xmm6,%%xmm1 \n" - "addps %%xmm4,%%xmm2 \n" - "movq %%xmm1,(%2) \n" - "movd %%xmm0,%k1 \n" - "pshufd $0x39,%%xmm0,%%xmm0 \n" - "movd %%xmm0,%k5 \n" - "movd 0x00(%0,%1,1),%%xmm0 \n" - "movd 0x00(%0,%5,1),%%xmm6 \n" - "punpckldq %%xmm6,%%xmm0 \n" - "addps %%xmm4,%%xmm3 \n" - "movq %%xmm0,0x08(%2) \n" - "lea 0x10(%2),%2 \n" - "sub $0x4,%4 \n" - "jge 40b \n" - - "49: \n" - "add $0x3,%4 \n" - "jl 19f \n" - - // 1 pixel loop - LABELALIGN - "10: \n" - "cvttps2dq %%xmm2,%%xmm0 \n" - "packssdw %%xmm0,%%xmm0 \n" - "pmaddwd %%xmm5,%%xmm0 \n" - "addps %%xmm7,%%xmm2 \n" - "movd %%xmm0,%k1 \n" - "movd 0x00(%0,%1,1),%%xmm0 \n" - "movd %%xmm0,(%2) \n" - "lea 0x04(%2),%2 \n" - "sub $0x1,%4 \n" - "jge 10b \n" - "19: \n" - : "+r"(src_argb), // %0 - "+r"(src_argb_stride_temp), // %1 - "+r"(dst_argb), // %2 - "+r"(src_dudv), // %3 - "+rm"(width), // %4 - "=&r"(temp) // %5 - : - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7"); -} -#endif // HAS_ARGBAFFINEROW_SSE2 - -#ifdef HAS_INTERPOLATEROW_SSSE3 -// Bilinear filter 16x2 -> 16x1 -void InterpolateRow_SSSE3(uint8_t* dst_ptr, - const uint8_t* src_ptr, - ptrdiff_t src_stride, - int dst_width, - int source_y_fraction) { - asm volatile( - "sub %1,%0 \n" - "cmp $0x0,%3 \n" - "je 100f \n" - "cmp $0x80,%3 \n" - "je 50f \n" - - "movd %3,%%xmm0 \n" - "neg %3 \n" - "add $0x100,%3 \n" - "movd %3,%%xmm5 \n" - "punpcklbw %%xmm0,%%xmm5 \n" - "punpcklwd %%xmm5,%%xmm5 \n" - "pshufd $0x0,%%xmm5,%%xmm5 \n" - "mov $0x80808080,%%eax \n" - "movd %%eax,%%xmm4 \n" - "pshufd $0x0,%%xmm4,%%xmm4 \n" - - // General purpose row blend. LABELALIGN "1: \n" - "movdqu (%1),%%xmm0 \n" - "movdqu 0x00(%1,%4,1),%%xmm2 \n" - "movdqa %%xmm0,%%xmm1 \n" - "punpcklbw %%xmm2,%%xmm0 \n" - "punpckhbw %%xmm2,%%xmm1 \n" - "psubb %%xmm4,%%xmm0 \n" - "psubb %%xmm4,%%xmm1 \n" - "movdqa %%xmm5,%%xmm2 \n" - "movdqa %%xmm5,%%xmm3 \n" - "pmaddubsw %%xmm0,%%xmm2 \n" - "pmaddubsw %%xmm1,%%xmm3 \n" - "paddw %%xmm4,%%xmm2 \n" - "paddw %%xmm4,%%xmm3 \n" - "psrlw $0x8,%%xmm2 \n" - "psrlw $0x8,%%xmm3 \n" - "packuswb %%xmm3,%%xmm2 \n" - "movdqu %%xmm2,0x00(%1,%0,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - "jmp 99f \n" + "vcvttps2dq %%ymm2,%%ymm0 \n" + "vcvttps2dq %%ymm3,%%ymm1 \n" + "vpslld $2,%%ymm0,%%ymm0 \n" + "vpmulld %%ymm6,%%ymm1,%%ymm1 \n" + "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdd %%ymm7,0(%[src],%%ymm0,1),%%ymm1\n" + "vaddps %%ymm4,%%ymm2,%%ymm2 \n" + "vaddps %%ymm5,%%ymm3,%%ymm3 \n" + "vmovdqu %%ymm1,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" - // Blend 50 / 50. - LABELALIGN - "50: \n" - "movdqu (%1),%%xmm0 \n" - "movdqu 0x00(%1,%4,1),%%xmm1 \n" - "pavgb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,0x00(%1,%0,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 50b \n" - "jmp 99f \n" + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" + "vmovss 0x08(%[uv]),%%xmm4 \n" + "vmovss 0x0c(%[uv]),%%xmm5 \n" - // Blend 100 / 0 - Copy row unchanged. + // 1 pixel remainder loop. LABELALIGN - "100: \n" - "movdqu (%1),%%xmm0 \n" - "movdqu %%xmm0,0x00(%1,%0,1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 100b \n" + "3: \n" + "vcvttps2dq %%xmm2,%%xmm0 \n" + "vcvttps2dq %%xmm3,%%xmm1 \n" + "vpslld $2,%%xmm0,%%xmm0 \n" + "vpmulld %%xmm6,%%xmm1,%%xmm1 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpcmpeqd %%xmm7,%%xmm7,%%xmm7 \n" + "vpsrldq $12,%%xmm7,%%xmm7 \n" + "vpgatherdd %%xmm7,0(%[src],%%xmm0,1),%%xmm1\n" + "vaddss %%xmm4,%%xmm2,%%xmm2 \n" + "vaddss %%xmm5,%%xmm3,%%xmm3 \n" + "vmovd %%xmm1,(%[dst]) \n" + "lea 0x04(%[dst]),%[dst] \n" + "sub $0x1,%[width] \n" + "jg 3b \n" "99: \n" - : "+r"(dst_ptr), // %0 - "+r"(src_ptr), // %1 - "+rm"(dst_width), // %2 - "+r"(source_y_fraction) // %3 - : "r"((intptr_t)(src_stride)) // %4 - : "memory", "cc", "eax", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + "vzeroupper \n" + : [dst] "+r"(dst_argb), [width] "+r"(width) + : [src] "r"(src_argb), [uv] "r"(src_dudv), [stride] "m"(src_argb_stride), + [ramp] "m"(kAffineRamp), [step8] "m"(kAffineStep8) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); } -#endif // HAS_INTERPOLATEROW_SSSE3 +#endif // HAS_ARGBAFFINEROW_AVX2 #ifdef HAS_INTERPOLATEROW_AVX2 // Bilinear filter 32x2 -> 32x1 void InterpolateRow_AVX2(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride, - int dst_width, + int width, int source_y_fraction) { asm volatile( - "cmp $0x0,%3 \n" - "je 100f \n" - "sub %1,%0 \n" - "cmp $0x80,%3 \n" - "je 50f \n" + "sub %1,%0 \n" + "cmp $0x0,%3 \n" + "je 100f \n" + "cmp $0x80,%3 \n" + "je 50f \n" - "vmovd %3,%%xmm0 \n" - "neg %3 \n" - "add $0x100,%3 \n" - "vmovd %3,%%xmm5 \n" - "vpunpcklbw %%xmm0,%%xmm5,%%xmm5 \n" - "vpunpcklwd %%xmm5,%%xmm5,%%xmm5 \n" + "vmovd %3,%%xmm0 \n" + "neg %3 \n" + "add $0x100,%3 \n" + "vmovd %3,%%xmm5 \n" + "vpunpcklbw %%xmm0,%%xmm5,%%xmm5 \n" + "vpunpcklwd %%xmm5,%%xmm5,%%xmm5 \n" "vbroadcastss %%xmm5,%%ymm5 \n" - "mov $0x80808080,%%eax \n" - "vmovd %%eax,%%xmm4 \n" - "vbroadcastss %%xmm4,%%ymm4 \n" + "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" + "vpabsb %%ymm4,%%ymm4 \n" + "vpsllw $7,%%ymm4,%%ymm4 \n" // General purpose row blend. LABELALIGN - "1: \n" - "vmovdqu (%1),%%ymm0 \n" - "vmovdqu 0x00(%1,%4,1),%%ymm2 \n" - "vpunpckhbw %%ymm2,%%ymm0,%%ymm1 \n" - "vpunpcklbw %%ymm2,%%ymm0,%%ymm0 \n" - "vpsubb %%ymm4,%%ymm1,%%ymm1 \n" - "vpsubb %%ymm4,%%ymm0,%%ymm0 \n" - "vpmaddubsw %%ymm1,%%ymm5,%%ymm1 \n" - "vpmaddubsw %%ymm0,%%ymm5,%%ymm0 \n" - "vpaddw %%ymm4,%%ymm1,%%ymm1 \n" - "vpaddw %%ymm4,%%ymm0,%%ymm0 \n" - "vpsrlw $0x8,%%ymm1,%%ymm1 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,0x00(%1,%0,1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "jmp 99f \n" + "1: \n" + "vmovdqu (%1),%%ymm0 \n" + "vmovdqu 0x00(%1,%4,1),%%ymm2 \n" + "vpunpckhbw %%ymm2,%%ymm0,%%ymm1 \n" + "vpunpcklbw %%ymm2,%%ymm0,%%ymm0 \n" + "vpsubb %%ymm4,%%ymm1,%%ymm1 \n" + "vpsubb %%ymm4,%%ymm0,%%ymm0 \n" + "vpmaddubsw %%ymm1,%%ymm5,%%ymm1 \n" + "vpmaddubsw %%ymm0,%%ymm5,%%ymm0 \n" + "vpaddw %%ymm4,%%ymm1,%%ymm1 \n" + "vpaddw %%ymm4,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm1,%%ymm1 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,0x00(%1,%0,1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "jmp 99f \n" // Blend 50 / 50. LABELALIGN - "50: \n" - "vmovdqu (%1),%%ymm0 \n" - "vpavgb 0x00(%1,%4,1),%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,0x00(%1,%0,1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 50b \n" - "jmp 99f \n" + "50: \n" + "vmovdqu (%1),%%ymm0 \n" + "vpavgb 0x00(%1,%4,1),%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,0x00(%1,%0,1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 50b \n" + "jmp 99f \n" // Blend 100 / 0 - Copy row unchanged. LABELALIGN - "100: \n" - "rep movsb \n" - "jmp 999f \n" + "100: \n" + "vmovdqu (%1),%%ymm0 \n" + "vmovdqu %%ymm0,0x00(%1,%0,1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 100b \n" - "99: \n" - "vzeroupper \n" - "999: \n" - : "+D"(dst_ptr), // %0 - "+S"(src_ptr), // %1 - "+cm"(dst_width), // %2 - "+r"(source_y_fraction) // %3 - : "r"((intptr_t)(src_stride)) // %4 - : "memory", "cc", "eax", "xmm0", "xmm1", "xmm2", "xmm4", "xmm5"); + "99: \n" + "vzeroupper \n" + : "+r"(dst_ptr), // %0 + "+r"(src_ptr), // %1 + "+r"(width), // %2 + "+r"(source_y_fraction) // %3 + : "r"(src_stride) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm4", "xmm5"); } #endif // HAS_INTERPOLATEROW_AVX2 +#ifdef HAS_INTERPOLATEROW_AVX512BW +// Bilinear filter 64x2 -> 64x1 with masked tail for any width. +LIBYUV_TARGET_AVX512BW +void InterpolateRow_AVX512BW(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + asm volatile( + "sub %1,%0 \n" + "cmp $0x0,%3 \n" + "je 100f \n" + "cmp $0x80,%3 \n" + "je 50f \n" + + "imul $0xff,%3,%3 \n" + "add $0x100,%3 \n" + "vpbroadcastw %3,%%zmm5 \n" + "vpternlogd $0xff,%%zmm4,%%zmm4,%%zmm4 \n" + "vpabsb %%zmm4,%%zmm4 \n" + "vpsllw $7,%%zmm4,%%zmm4 \n" + + "sub $0x40,%2 \n" + "jl 2f \n" + + // General purpose row blend. + LABELALIGN + "1: \n" + "vmovdqu64 (%1),%%zmm0 \n" + "vmovdqu64 0x00(%1,%4,1),%%zmm2 \n" + "vpunpckhbw %%zmm2,%%zmm0,%%zmm1 \n" + "vpunpcklbw %%zmm2,%%zmm0,%%zmm0 \n" + "vpsubb %%zmm4,%%zmm1,%%zmm1 \n" + "vpsubb %%zmm4,%%zmm0,%%zmm0 \n" + "vpmaddubsw %%zmm1,%%zmm5,%%zmm1 \n" + "vpmaddubsw %%zmm0,%%zmm5,%%zmm0 \n" + "vpaddw %%zmm4,%%zmm1,%%zmm1 \n" + "vpaddw %%zmm4,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm1,%%zmm1 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu64 %%zmm0,0x00(%1,%0,1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x40,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%2 \n" + "jle 99f \n" + "mov $-1,%q3 \n" + "bzhi %q2,%q3,%q3 \n" + "kmovq %q3,%%k1 \n" + "vmovdqu8 (%1),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu8 0x00(%1,%4,1),%%zmm2%{%%k1%}%{z%}\n" + "vpunpckhbw %%zmm2,%%zmm0,%%zmm1 \n" + "vpunpcklbw %%zmm2,%%zmm0,%%zmm0 \n" + "vpsubb %%zmm4,%%zmm1,%%zmm1 \n" + "vpsubb %%zmm4,%%zmm0,%%zmm0 \n" + "vpmaddubsw %%zmm1,%%zmm5,%%zmm1 \n" + "vpmaddubsw %%zmm0,%%zmm5,%%zmm0 \n" + "vpaddw %%zmm4,%%zmm1,%%zmm1 \n" + "vpaddw %%zmm4,%%zmm0,%%zmm0 \n" + "vpsrlw $0x8,%%zmm1,%%zmm1 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu8 %%zmm0,0x00(%1,%0,1)%{%%k1%} \n" + "jmp 99f \n" + + // Blend 50 / 50. + LABELALIGN + "50: \n" + "sub $0x40,%2 \n" + "jl 52f \n" + LABELALIGN + "51: \n" + "vmovdqu64 (%1),%%zmm0 \n" + "vpavgb 0x00(%1,%4,1),%%zmm0,%%zmm0 \n" + "vmovdqu64 %%zmm0,0x00(%1,%0,1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x40,%2 \n" + "jge 51b \n" + + "52: \n" + "add $0x40,%2 \n" + "jle 99f \n" + "mov $-1,%q3 \n" + "bzhi %q2,%q3,%q3 \n" + "kmovq %q3,%%k1 \n" + "vmovdqu8 (%1),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu8 0x00(%1,%4,1),%%zmm2%{%%k1%}%{z%}\n" + "vpavgb %%zmm2,%%zmm0,%%zmm0 \n" + "vmovdqu8 %%zmm0,0x00(%1,%0,1)%{%%k1%} \n" + "jmp 99f \n" + + // Blend 100 / 0 - Copy row unchanged. + LABELALIGN + "100: \n" + "sub $0x40,%2 \n" + "jl 102f \n" + LABELALIGN + "101: \n" + "vmovdqu64 (%1),%%zmm0 \n" + "vmovdqu64 %%zmm0,0x00(%1,%0,1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x40,%2 \n" + "jge 101b \n" + + "102: \n" + "add $0x40,%2 \n" + "jle 99f \n" + "mov $-1,%q3 \n" + "bzhi %q2,%q3,%q3 \n" + "kmovq %q3,%%k1 \n" + "vmovdqu8 (%1),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu8 %%zmm0,0x00(%1,%0,1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(dst_ptr), // %0 + "+r"(src_ptr), // %1 + "+r"(width), // %2 + "+r"(source_y_fraction) // %3 + : "r"(src_stride) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm4", "xmm5", "k1"); +} +#endif // HAS_INTERPOLATEROW_AVX512BW + +#ifdef HAS_INTERPOLATEROW_16_AVX2 +// Bilinear filter 16x2 -> 16x1 +void InterpolateRow_16_AVX2(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + asm volatile( + "sub %1,%0 \n" + "cmp $0x0,%3 \n" + "je 100f \n" + "cmp $0x80,%3 \n" + "je 50f \n" + + "vmovd %3,%%xmm0 \n" + "neg %3 \n" + "add $0x100,%3 \n" + "vmovd %3,%%xmm5 \n" + "vpunpcklwd %%xmm0,%%xmm5,%%xmm5 \n" + "vpbroadcastd %%xmm5,%%ymm5 \n" + "vpcmpeqw %%ymm4,%%ymm4,%%ymm4 \n" + "vpsllw $15,%%ymm4,%%ymm4 \n" // 0x8000 unsigned bias + "vpsrlw $8,%%ymm4,%%ymm3 \n" // 0x00800080 = 8388736 + + LABELALIGN + "1: \n" + "vmovdqu (%1),%%ymm0 \n" + "vmovdqu (%1,%4,2),%%ymm1 \n" + "vpunpckhwd %%ymm1,%%ymm0,%%ymm2 \n" + "vpunpcklwd %%ymm1,%%ymm0,%%ymm0 \n" + "vpsubw %%ymm4,%%ymm2,%%ymm2 \n" + "vpsubw %%ymm4,%%ymm0,%%ymm0 \n" + "vpmaddwd %%ymm5,%%ymm2,%%ymm2 \n" + "vpmaddwd %%ymm5,%%ymm0,%%ymm0 \n" + "vpaddd %%ymm3,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm3,%%ymm0,%%ymm0 \n" + "vpsrad $0x8,%%ymm2,%%ymm2 \n" + "vpsrad $0x8,%%ymm0,%%ymm0 \n" + "vpackusdw %%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,0x00(%1,%0,1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "jmp 99f \n" + + "50: \n" LABELALIGN + "2: \n" + "vmovdqu (%1),%%ymm0 \n" + "vpavgw (%1,%4,2),%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,0x00(%1,%0,1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 2b \n" + "jmp 99f \n" + + "100: \n" LABELALIGN + "3: \n" + "vmovdqu (%1),%%ymm0 \n" + "vmovdqu %%ymm0,0x00(%1,%0,1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" + : "+r"(dst_ptr), // %0 + "+r"(src_ptr), // %1 + "+r"(width), // %2 + "+r"(source_y_fraction) // %3 + : "r"(src_stride) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif // HAS_INTERPOLATEROW_16_AVX2 + #ifdef HAS_ARGBSHUFFLEROW_SSSE3 // For BGRAToARGB, ABGRToARGB, RGBAToARGB, and ARGBToRGBA. void ARGBShuffleRow_SSSE3(const uint8_t* src_argb, uint8_t* dst_argb, const uint8_t* shuffler, int width) { - asm volatile( + asm volatile("movdqu (%3),%%xmm5 \n" - "movdqu (%3),%%xmm5 \n" - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "pshufb %%xmm5,%%xmm0 \n" - "pshufb %%xmm5,%%xmm1 \n" - "movdqu %%xmm0,(%1) \n" - "movdqu %%xmm1,0x10(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : "r"(shuffler) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm5"); + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "pshufb %%xmm5,%%xmm0 \n" + "pshufb %%xmm5,%%xmm1 \n" + "movdqu %%xmm0,(%1) \n" + "movdqu %%xmm1,0x10(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(shuffler) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm5"); } #endif // HAS_ARGBSHUFFLEROW_SSSE3 @@ -6192,64 +13615,111 @@ void ARGBShuffleRow_AVX2(const uint8_t* src_argb, uint8_t* dst_argb, const uint8_t* shuffler, int width) { - asm volatile( + asm volatile("vbroadcasti128 (%3),%%ymm5 \n" - "vbroadcastf128 (%3),%%ymm5 \n" - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" - "vpshufb %%ymm5,%%ymm1,%%ymm1 \n" - "vmovdqu %%ymm0,(%1) \n" - "vmovdqu %%ymm1,0x20(%1) \n" - "lea 0x40(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_argb), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : "r"(shuffler) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm5"); + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm5,%%ymm1,%%ymm1 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(shuffler) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm5"); } #endif // HAS_ARGBSHUFFLEROW_AVX2 +#ifdef HAS_ARGBSHUFFLEROW_AVX512BW +// For BGRAToARGB, ABGRToARGB, RGBAToARGB, and ARGBToRGBA. +LIBYUV_TARGET_AVX512BW +void ARGBShuffleRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + const uint8_t* shuffler, + int width) { + uintptr_t temp; + asm volatile( + "vbroadcasti32x4 (%[shuffler]),%%zmm5 \n" + "sub $0x20,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%0),%%zmm0 \n" + "vmovdqu8 0x40(%0),%%zmm1 \n" + "lea 0x80(%0),%0 \n" + "vpshufb %%zmm5,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm5,%%zmm1,%%zmm1 \n" + "vmovdqu8 %%zmm0,(%1) \n" + "vmovdqu8 %%zmm1,0x40(%1) \n" + "lea 0x80(%1),%1 \n" + "sub $0x20,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q2,%[temp],%[temp] \n" + "kmovd %k[temp],%%k1 \n" + "kshiftrd $16,%%k1,%%k2 \n" + "vmovdqu32 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%0),%%zmm1%{%%k2%}%{z%} \n" + "vpshufb %%zmm5,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm5,%%zmm1,%%zmm1 \n" + "vmovdqu32 %%zmm0,(%1)%{%%k1%} \n" + "vmovdqu32 %%zmm1,0x40(%1)%{%%k2%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width), // %2 + [temp] "=&r"(temp) // %[temp] + : [shuffler] "r"(shuffler) // %[shuffler] + : "memory", "cc", "xmm0", "xmm1", "xmm5", "k1", "k2"); +} +#endif // HAS_ARGBSHUFFLEROW_AVX512BW + #ifdef HAS_I422TOYUY2ROW_SSE2 void I422ToYUY2Row_SSE2(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_yuy2, int width) { - asm volatile( + asm volatile("sub %1,%2 \n" - "sub %1,%2 \n" - - LABELALIGN - "1: \n" - "movq (%1),%%xmm2 \n" - "movq 0x00(%1,%2,1),%%xmm1 \n" - "add $0x8,%1 \n" - "punpcklbw %%xmm1,%%xmm2 \n" - "movdqu (%0),%%xmm0 \n" - "add $0x10,%0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "punpcklbw %%xmm2,%%xmm0 \n" - "punpckhbw %%xmm2,%%xmm1 \n" - "movdqu %%xmm0,(%3) \n" - "movdqu %%xmm1,0x10(%3) \n" - "lea 0x20(%3),%3 \n" - "sub $0x10,%4 \n" - "jg 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_yuy2), // %3 - "+rm"(width) // %4 - : - : "memory", "cc", "xmm0", "xmm1", "xmm2"); + LABELALIGN + "1: \n" + "movq (%1),%%xmm2 \n" + "movq 0x00(%1,%2,1),%%xmm1 \n" + "add $0x8,%1 \n" + "punpcklbw %%xmm1,%%xmm2 \n" + "movdqu (%0),%%xmm0 \n" + "add $0x10,%0 \n" + "movdqa %%xmm0,%%xmm1 \n" + "punpcklbw %%xmm2,%%xmm0 \n" + "punpckhbw %%xmm2,%%xmm1 \n" + "movdqu %%xmm0,(%3) \n" + "movdqu %%xmm1,0x10(%3) \n" + "lea 0x20(%3),%3 \n" + "sub $0x10,%4 \n" + "jg 1b \n" + : "+r"(src_y), // %0 + "+r"(src_u), // %1 + "+r"(src_v), // %2 + "+r"(dst_yuy2), // %3 + "+rm"(width) // %4 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } #endif // HAS_I422TOYUY2ROW_SSE2 @@ -6259,33 +13729,31 @@ void I422ToUYVYRow_SSE2(const uint8_t* src_y, const uint8_t* src_v, uint8_t* dst_uyvy, int width) { - asm volatile( + asm volatile("sub %1,%2 \n" - "sub %1,%2 \n" - - LABELALIGN - "1: \n" - "movq (%1),%%xmm2 \n" - "movq 0x00(%1,%2,1),%%xmm1 \n" - "add $0x8,%1 \n" - "punpcklbw %%xmm1,%%xmm2 \n" - "movdqu (%0),%%xmm0 \n" - "movdqa %%xmm2,%%xmm1 \n" - "add $0x10,%0 \n" - "punpcklbw %%xmm0,%%xmm1 \n" - "punpckhbw %%xmm0,%%xmm2 \n" - "movdqu %%xmm1,(%3) \n" - "movdqu %%xmm2,0x10(%3) \n" - "lea 0x20(%3),%3 \n" - "sub $0x10,%4 \n" - "jg 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_uyvy), // %3 - "+rm"(width) // %4 - : - : "memory", "cc", "xmm0", "xmm1", "xmm2"); + LABELALIGN + "1: \n" + "movq (%1),%%xmm2 \n" + "movq 0x00(%1,%2,1),%%xmm1 \n" + "add $0x8,%1 \n" + "punpcklbw %%xmm1,%%xmm2 \n" + "movdqu (%0),%%xmm0 \n" + "movdqa %%xmm2,%%xmm1 \n" + "add $0x10,%0 \n" + "punpcklbw %%xmm0,%%xmm1 \n" + "punpckhbw %%xmm0,%%xmm2 \n" + "movdqu %%xmm1,(%3) \n" + "movdqu %%xmm2,0x10(%3) \n" + "lea 0x20(%3),%3 \n" + "sub $0x10,%4 \n" + "jg 1b \n" + : "+r"(src_y), // %0 + "+r"(src_u), // %1 + "+r"(src_v), // %2 + "+r"(dst_uyvy), // %3 + "+rm"(width) // %4 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } #endif // HAS_I422TOUYVYROW_SSE2 @@ -6295,36 +13763,34 @@ void I422ToYUY2Row_AVX2(const uint8_t* src_y, const uint8_t* src_v, uint8_t* dst_yuy2, int width) { - asm volatile( + asm volatile("sub %1,%2 \n" - "sub %1,%2 \n" - - LABELALIGN - "1: \n" - "vpmovzxbw (%1),%%ymm1 \n" - "vpmovzxbw 0x00(%1,%2,1),%%ymm2 \n" - "add $0x10,%1 \n" - "vpsllw $0x8,%%ymm2,%%ymm2 \n" - "vpor %%ymm1,%%ymm2,%%ymm2 \n" - "vmovdqu (%0),%%ymm0 \n" - "add $0x20,%0 \n" - "vpunpcklbw %%ymm2,%%ymm0,%%ymm1 \n" - "vpunpckhbw %%ymm2,%%ymm0,%%ymm2 \n" - "vextractf128 $0x0,%%ymm1,(%3) \n" - "vextractf128 $0x0,%%ymm2,0x10(%3) \n" - "vextractf128 $0x1,%%ymm1,0x20(%3) \n" - "vextractf128 $0x1,%%ymm2,0x30(%3) \n" - "lea 0x40(%3),%3 \n" - "sub $0x20,%4 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_yuy2), // %3 - "+rm"(width) // %4 - : - : "memory", "cc", "xmm0", "xmm1", "xmm2"); + LABELALIGN + "1: \n" + "vpmovzxbw (%1),%%ymm1 \n" + "vpmovzxbw 0x00(%1,%2,1),%%ymm2 \n" + "add $0x10,%1 \n" + "vpsllw $0x8,%%ymm2,%%ymm2 \n" + "vpor %%ymm1,%%ymm2,%%ymm2 \n" + "vmovdqu (%0),%%ymm0 \n" + "add $0x20,%0 \n" + "vpunpcklbw %%ymm2,%%ymm0,%%ymm1 \n" + "vpunpckhbw %%ymm2,%%ymm0,%%ymm2 \n" + "vextractf128 $0x0,%%ymm1,(%3) \n" + "vextractf128 $0x0,%%ymm2,0x10(%3) \n" + "vextractf128 $0x1,%%ymm1,0x20(%3) \n" + "vextractf128 $0x1,%%ymm2,0x30(%3) \n" + "lea 0x40(%3),%3 \n" + "sub $0x20,%4 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(src_u), // %1 + "+r"(src_v), // %2 + "+r"(dst_yuy2), // %3 + "+rm"(width) // %4 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } #endif // HAS_I422TOYUY2ROW_AVX2 @@ -6334,36 +13800,34 @@ void I422ToUYVYRow_AVX2(const uint8_t* src_y, const uint8_t* src_v, uint8_t* dst_uyvy, int width) { - asm volatile( + asm volatile("sub %1,%2 \n" - "sub %1,%2 \n" - - LABELALIGN - "1: \n" - "vpmovzxbw (%1),%%ymm1 \n" - "vpmovzxbw 0x00(%1,%2,1),%%ymm2 \n" - "add $0x10,%1 \n" - "vpsllw $0x8,%%ymm2,%%ymm2 \n" - "vpor %%ymm1,%%ymm2,%%ymm2 \n" - "vmovdqu (%0),%%ymm0 \n" - "add $0x20,%0 \n" - "vpunpcklbw %%ymm0,%%ymm2,%%ymm1 \n" - "vpunpckhbw %%ymm0,%%ymm2,%%ymm2 \n" - "vextractf128 $0x0,%%ymm1,(%3) \n" - "vextractf128 $0x0,%%ymm2,0x10(%3) \n" - "vextractf128 $0x1,%%ymm1,0x20(%3) \n" - "vextractf128 $0x1,%%ymm2,0x30(%3) \n" - "lea 0x40(%3),%3 \n" - "sub $0x20,%4 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_uyvy), // %3 - "+rm"(width) // %4 - : - : "memory", "cc", "xmm0", "xmm1", "xmm2"); + LABELALIGN + "1: \n" + "vpmovzxbw (%1),%%ymm1 \n" + "vpmovzxbw 0x00(%1,%2,1),%%ymm2 \n" + "add $0x10,%1 \n" + "vpsllw $0x8,%%ymm2,%%ymm2 \n" + "vpor %%ymm1,%%ymm2,%%ymm2 \n" + "vmovdqu (%0),%%ymm0 \n" + "add $0x20,%0 \n" + "vpunpcklbw %%ymm0,%%ymm2,%%ymm1 \n" + "vpunpckhbw %%ymm0,%%ymm2,%%ymm2 \n" + "vextractf128 $0x0,%%ymm1,(%3) \n" + "vextractf128 $0x0,%%ymm2,0x10(%3) \n" + "vextractf128 $0x1,%%ymm1,0x20(%3) \n" + "vextractf128 $0x1,%%ymm2,0x30(%3) \n" + "lea 0x40(%3),%3 \n" + "sub $0x20,%4 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(src_u), // %1 + "+r"(src_v), // %2 + "+r"(dst_uyvy), // %3 + "+rm"(width) // %4 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } #endif // HAS_I422TOUYVYROW_AVX2 @@ -6372,54 +13836,57 @@ void ARGBPolynomialRow_SSE2(const uint8_t* src_argb, uint8_t* dst_argb, const float* poly, int width) { - asm volatile( + asm volatile("pxor %%xmm3,%%xmm3 \n" - "pxor %%xmm3,%%xmm3 \n" - - // 2 pixel loop. - LABELALIGN - "1: \n" - "movq (%0),%%xmm0 \n" - "lea 0x8(%0),%0 \n" - "punpcklbw %%xmm3,%%xmm0 \n" - "movdqa %%xmm0,%%xmm4 \n" - "punpcklwd %%xmm3,%%xmm0 \n" - "punpckhwd %%xmm3,%%xmm4 \n" - "cvtdq2ps %%xmm0,%%xmm0 \n" - "cvtdq2ps %%xmm4,%%xmm4 \n" - "movdqa %%xmm0,%%xmm1 \n" - "movdqa %%xmm4,%%xmm5 \n" - "mulps 0x10(%3),%%xmm0 \n" - "mulps 0x10(%3),%%xmm4 \n" - "addps (%3),%%xmm0 \n" - "addps (%3),%%xmm4 \n" - "movdqa %%xmm1,%%xmm2 \n" - "movdqa %%xmm5,%%xmm6 \n" - "mulps %%xmm1,%%xmm2 \n" - "mulps %%xmm5,%%xmm6 \n" - "mulps %%xmm2,%%xmm1 \n" - "mulps %%xmm6,%%xmm5 \n" - "mulps 0x20(%3),%%xmm2 \n" - "mulps 0x20(%3),%%xmm6 \n" - "mulps 0x30(%3),%%xmm1 \n" - "mulps 0x30(%3),%%xmm5 \n" - "addps %%xmm2,%%xmm0 \n" - "addps %%xmm6,%%xmm4 \n" - "addps %%xmm1,%%xmm0 \n" - "addps %%xmm5,%%xmm4 \n" - "cvttps2dq %%xmm0,%%xmm0 \n" - "cvttps2dq %%xmm4,%%xmm4 \n" - "packuswb %%xmm4,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "movq %%xmm0,(%1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x2,%2 \n" - "jg 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : "r"(poly) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); + // 2 pixel loop. + LABELALIGN + "1: \n" + "movq (%0),%%xmm0 \n" + "lea 0x8(%0),%0 \n" + "punpcklbw %%xmm3,%%xmm0 \n" + "movdqa %%xmm0,%%xmm4 \n" + "punpcklwd %%xmm3,%%xmm0 \n" + "punpckhwd %%xmm3,%%xmm4 \n" + "cvtdq2ps %%xmm0,%%xmm0 \n" + "cvtdq2ps %%xmm4,%%xmm4 \n" + "movdqa %%xmm0,%%xmm1 \n" + "movdqa %%xmm4,%%xmm5 \n" + "movups 0x10(%3),%%xmm7 \n" + "mulps %%xmm7,%%xmm0 \n" + "mulps %%xmm7,%%xmm4 \n" + "movups (%3),%%xmm7 \n" + "addps %%xmm7,%%xmm0 \n" + "addps %%xmm7,%%xmm4 \n" + "movdqa %%xmm1,%%xmm2 \n" + "movdqa %%xmm5,%%xmm6 \n" + "mulps %%xmm1,%%xmm2 \n" + "mulps %%xmm5,%%xmm6 \n" + "mulps %%xmm2,%%xmm1 \n" + "mulps %%xmm6,%%xmm5 \n" + "movups 0x20(%3),%%xmm7 \n" + "mulps %%xmm7,%%xmm2 \n" + "mulps %%xmm7,%%xmm6 \n" + "movups 0x30(%3),%%xmm7 \n" + "mulps %%xmm7,%%xmm1 \n" + "mulps %%xmm7,%%xmm5 \n" + "addps %%xmm2,%%xmm0 \n" + "addps %%xmm6,%%xmm4 \n" + "addps %%xmm1,%%xmm0 \n" + "addps %%xmm5,%%xmm4 \n" + "cvttps2dq %%xmm0,%%xmm0 \n" + "cvttps2dq %%xmm4,%%xmm4 \n" + "packssdw %%xmm4,%%xmm0 \n" + "packuswb %%xmm0,%%xmm0 \n" + "movq %%xmm0,(%1) \n" + "lea 0x8(%1),%1 \n" + "sub $0x2,%2 \n" + "jg 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(poly) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); } #endif // HAS_ARGBPOLYNOMIALROW_SSE2 @@ -6429,14 +13896,14 @@ void ARGBPolynomialRow_AVX2(const uint8_t* src_argb, const float* poly, int width) { asm volatile( - "vbroadcastf128 (%3),%%ymm4 \n" - "vbroadcastf128 0x10(%3),%%ymm5 \n" - "vbroadcastf128 0x20(%3),%%ymm6 \n" - "vbroadcastf128 0x30(%3),%%ymm7 \n" + "vbroadcasti128 (%3),%%ymm4 \n" + "vbroadcasti128 0x10(%3),%%ymm5 \n" + "vbroadcasti128 0x20(%3),%%ymm6 \n" + "vbroadcasti128 0x30(%3),%%ymm7 \n" // 2 pixel loop. LABELALIGN - "1: \n" + "1: \n" "vpmovzxbd (%0),%%ymm0 \n" // 2 ARGB pixels "lea 0x8(%0),%0 \n" "vcvtdq2ps %%ymm0,%%ymm0 \n" // X 8 floats @@ -6447,118 +13914,137 @@ void ARGBPolynomialRow_AVX2(const uint8_t* src_argb, "vfmadd231ps %%ymm3,%%ymm2,%%ymm0 \n" // result += C3 * X * X * // X "vcvttps2dq %%ymm0,%%ymm0 \n" - "vpackusdw %%ymm0,%%ymm0,%%ymm0 \n" + "vpackssdw %%ymm0,%%ymm0,%%ymm0 \n" "vpermq $0xd8,%%ymm0,%%ymm0 \n" "vpackuswb %%xmm0,%%xmm0,%%xmm0 \n" "vmovq %%xmm0,(%1) \n" "lea 0x8(%1),%1 \n" "sub $0x2,%2 \n" "jg 1b \n" - "vzeroupper \n" + "vzeroupper \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 : "r"(poly) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7"); + : "memory", "cc", "xmm0", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); } #endif // HAS_ARGBPOLYNOMIALROW_AVX2 -#ifdef HAS_HALFFLOATROW_SSE2 -static float kScaleBias = 1.9259299444e-34f; -void HalfFloatRow_SSE2(const uint16_t* src, - uint16_t* dst, - float scale, - int width) { - scale *= kScaleBias; - asm volatile( - "movd %3,%%xmm4 \n" - "pshufd $0x0,%%xmm4,%%xmm4 \n" - "pxor %%xmm5,%%xmm5 \n" - "sub %0,%1 \n" - - // 16 pixel loop. - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm2 \n" // 8 shorts - "add $0x10,%0 \n" - "movdqa %%xmm2,%%xmm3 \n" - "punpcklwd %%xmm5,%%xmm2 \n" // 8 ints in xmm2/1 - "cvtdq2ps %%xmm2,%%xmm2 \n" // 8 floats - "punpckhwd %%xmm5,%%xmm3 \n" - "cvtdq2ps %%xmm3,%%xmm3 \n" - "mulps %%xmm4,%%xmm2 \n" - "mulps %%xmm4,%%xmm3 \n" - "psrld $0xd,%%xmm2 \n" - "psrld $0xd,%%xmm3 \n" - "packssdw %%xmm3,%%xmm2 \n" - "movdqu %%xmm2,-0x10(%0,%1,1) \n" - "sub $0x8,%2 \n" - "jg 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "m"(scale) // %3 - : "memory", "cc", "xmm2", "xmm3", "xmm4", "xmm5"); -} -#endif // HAS_HALFFLOATROW_SSE2 +#if defined(HAS_HALFFLOATROW_AVX2) +// 2^-112 moves the float exponent into half float position. Applied as a +// separate multiply after scale so no denormal constant is formed when +// scale < 2^-14 (see HalfFloatRow_C). +static const float kScaleBias = 1.9259299444e-34f; +#endif #ifdef HAS_HALFFLOATROW_AVX2 void HalfFloatRow_AVX2(const uint16_t* src, uint16_t* dst, float scale, int width) { - scale *= kScaleBias; asm volatile( - "vbroadcastss %3, %%ymm4 \n" - "vpxor %%ymm5,%%ymm5,%%ymm5 \n" - "sub %0,%1 \n" + "vbroadcastss %3, %%ymm4 \n" + "vbroadcastss %4, %%ymm6 \n" + "vpxor %%ymm5,%%ymm5,%%ymm5 \n" + "sub %0,%1 \n" // 16 pixel loop. LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm2 \n" // 16 shorts - "add $0x20,%0 \n" - "vpunpckhwd %%ymm5,%%ymm2,%%ymm3 \n" // mutates - "vpunpcklwd %%ymm5,%%ymm2,%%ymm2 \n" - "vcvtdq2ps %%ymm3,%%ymm3 \n" - "vcvtdq2ps %%ymm2,%%ymm2 \n" - "vmulps %%ymm3,%%ymm4,%%ymm3 \n" - "vmulps %%ymm2,%%ymm4,%%ymm2 \n" - "vpsrld $0xd,%%ymm3,%%ymm3 \n" - "vpsrld $0xd,%%ymm2,%%ymm2 \n" - "vpackssdw %%ymm3, %%ymm2, %%ymm2 \n" // unmutates - "vmovdqu %%ymm2,-0x20(%0,%1,1) \n" - "sub $0x10,%2 \n" - "jg 1b \n" + "1: \n" + "vmovdqu (%0),%%ymm2 \n" // 16 shorts + "add $0x20,%0 \n" + "vpunpckhwd %%ymm5,%%ymm2,%%ymm3 \n" // mutates + "vpunpcklwd %%ymm5,%%ymm2,%%ymm2 \n" + "vcvtdq2ps %%ymm3,%%ymm3 \n" + "vcvtdq2ps %%ymm2,%%ymm2 \n" + "vmulps %%ymm3,%%ymm4,%%ymm3 \n" // * scale + "vmulps %%ymm2,%%ymm4,%%ymm2 \n" + "vmulps %%ymm3,%%ymm6,%%ymm3 \n" // * 2^-112 + "vmulps %%ymm2,%%ymm6,%%ymm2 \n" + "vpsrld $0xd,%%ymm3,%%ymm3 \n" + "vpsrld $0xd,%%ymm2,%%ymm2 \n" + "vpackssdw %%ymm3, %%ymm2, %%ymm2 \n" // unmutates + "vmovdqu %%ymm2,-0x20(%0,%1,1) \n" + "sub $0x10,%2 \n" + "jg 1b \n" - "vzeroupper \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 #if defined(__x86_64__) - : "x"(scale) // %3 + : "x"(scale), // %3 + "x"(kScaleBias) // %4 #else - : "m"(scale) // %3 + : "m"(scale), // %3 + "m"(kScaleBias) // %4 #endif - : "memory", "cc", "xmm2", "xmm3", "xmm4", "xmm5"); + : "memory", "cc", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); } #endif // HAS_HALFFLOATROW_AVX2 +#ifdef HAS_HALFFLOATROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void HalfFloatRow_AVX512BW(const uint16_t* src, + uint16_t* dst, + float scale, + int width) { + uintptr_t temp; + asm volatile( + "vbroadcastss %[scale],%%zmm4 \n" + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vpmovzxwd (%[src]),%%zmm0 \n" + "lea 0x20(%[src]),%[src] \n" + "vcvtdq2ps %%zmm0,%%zmm0 \n" + "vmulps %%zmm4,%%zmm0,%%zmm0 \n" + "vcvtps2ph $3,%%zmm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vpmovzxwd (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vcvtdq2ps %%zmm0,%%zmm0 \n" + "vmulps %%zmm4,%%zmm0,%%zmm0 \n" + "vcvtps2ph $3,%%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : + [src] "+r"(src), [dst] "+r"(dst), [width] "+r"(width), [temp] "=&r"(temp) + : [scale] "m"(scale) + : "memory", "cc", "xmm0", "xmm4", "k1"); +} +#endif // HAS_HALFFLOATROW_AVX512BW + #ifdef HAS_HALFFLOATROW_F16C void HalfFloatRow_F16C(const uint16_t* src, uint16_t* dst, float scale, int width) { asm volatile( - "vbroadcastss %3, %%ymm4 \n" - "sub %0,%1 \n" + "vbroadcastss %3, %%ymm4 \n" + "sub %0,%1 \n" - // 16 pixel loop. + // 16 pixel loop (pure AVX1 + F16C). LABELALIGN - "1: \n" - "vpmovzxwd (%0),%%ymm2 \n" // 16 shorts -> 16 ints - "vpmovzxwd 0x10(%0),%%ymm3 \n" + "1: \n" + "vpmovzxwd (%0),%%xmm2 \n" // 16 shorts -> 16 ints + "vpmovzxwd 0x08(%0),%%xmm0 \n" + "vinsertf128 $1,%%xmm0,%%ymm2,%%ymm2 \n" + "vpmovzxwd 0x10(%0),%%xmm3 \n" + "vpmovzxwd 0x18(%0),%%xmm0 \n" + "vinsertf128 $1,%%xmm0,%%ymm3,%%ymm3 \n" "vcvtdq2ps %%ymm2,%%ymm2 \n" "vcvtdq2ps %%ymm3,%%ymm3 \n" "vmulps %%ymm2,%%ymm4,%%ymm2 \n" @@ -6570,28 +14056,28 @@ void HalfFloatRow_F16C(const uint16_t* src, "add $0x20,%0 \n" "sub $0x10,%2 \n" "jg 1b \n" - "vzeroupper \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 -#if defined(__x86_64__) - : "x"(scale) // %3 -#else - : "m"(scale) // %3 -#endif - : "memory", "cc", "xmm2", "xmm3", "xmm4"); + : "m"(scale) // %3 + : "memory", "cc", "xmm0", "xmm2", "xmm3", "xmm4"); } #endif // HAS_HALFFLOATROW_F16C #ifdef HAS_HALFFLOATROW_F16C void HalfFloat1Row_F16C(const uint16_t* src, uint16_t* dst, float, int width) { asm volatile( - "sub %0,%1 \n" - // 16 pixel loop. + "sub %0,%1 \n" + // 16 pixel loop (pure AVX1 + F16C). LABELALIGN - "1: \n" - "vpmovzxwd (%0),%%ymm2 \n" // 16 shorts -> 16 ints - "vpmovzxwd 0x10(%0),%%ymm3 \n" + "1: \n" + "vpmovzxwd (%0),%%xmm2 \n" // 16 shorts -> 16 ints + "vpmovzxwd 0x08(%0),%%xmm0 \n" + "vinsertf128 $1,%%xmm0,%%ymm2,%%ymm2 \n" + "vpmovzxwd 0x10(%0),%%xmm3 \n" + "vpmovzxwd 0x18(%0),%%xmm0 \n" + "vinsertf128 $1,%%xmm0,%%ymm3,%%ymm3 \n" "vcvtdq2ps %%ymm2,%%ymm2 \n" "vcvtdq2ps %%ymm3,%%ymm3 \n" "vcvtps2ph $3, %%ymm2, %%xmm2 \n" @@ -6601,360 +14087,5032 @@ void HalfFloat1Row_F16C(const uint16_t* src, uint16_t* dst, float, int width) { "add $0x20,%0 \n" "sub $0x10,%2 \n" "jg 1b \n" - "vzeroupper \n" + "vzeroupper \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 : - : "memory", "cc", "xmm2", "xmm3"); + : "memory", "cc", "xmm0", "xmm2", "xmm3"); } #endif // HAS_HALFFLOATROW_F16C -#ifdef HAS_ARGBCOLORTABLEROW_X86 -// Tranform ARGB pixels with color table. -void ARGBColorTableRow_X86(uint8_t* dst_argb, +#ifdef HAS_BYTETOFLOATROW_AVX2 +void ByteToFloatRow_AVX2(const uint8_t* src, + float* dst, + float scale, + int width) { + asm volatile("vbroadcastss %3,%%ymm2 \n" + + LABELALIGN + "1: \n" + "vpmovzxbd (%0),%%ymm0 \n" + "vpmovzxbd 0x08(%0),%%ymm1 \n" + "lea 0x10(%0),%0 \n" + "vcvtdq2ps %%ymm0,%%ymm0 \n" + "vcvtdq2ps %%ymm1,%%ymm1 \n" + "vmulps %%ymm2,%%ymm0,%%ymm0 \n" + "vmulps %%ymm2,%%ymm1,%%ymm1 \n" + "vmovups %%ymm0,(%1) \n" + "vmovups %%ymm1,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 +#if defined(__x86_64__) + : "x"(scale) // %3 +#else + : "m"(scale) // %3 +#endif + : "memory", "cc", "xmm0", "xmm1", "xmm2"); +} +#endif // HAS_BYTETOFLOATROW_AVX2 + +#ifdef HAS_GAUSSROW_AVX2 +static const int32_t kGaussRound128 = 128; +static const int8_t kShufGauss32To16[16] = {0, 1, 4, 5, 8, 9, 12, 13, + -1, -1, -1, -1, -1, -1, -1, -1}; +void GaussRow_AVX2(const uint32_t* src, uint16_t* dst, int width) { + asm volatile( + "vpbroadcastd %[k128],%%ymm4 \n" + "vbroadcasti128 %[kShuf],%%ymm5 \n" + "sub $0x8,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[src]),%%ymm0 \n" + "vmovdqu 0x04(%[src]),%%ymm1 \n" + "vmovdqu 0x08(%[src]),%%ymm2 \n" + "vpaddd 0x10(%[src]),%%ymm0,%%ymm0 \n" + "vpaddd 0x0c(%[src]),%%ymm1,%%ymm1 \n" + "lea 0x20(%[src]),%[src] \n" + "vpslld $2,%%ymm1,%%ymm1 \n" + "vpslld $1,%%ymm2,%%ymm3 \n" + "vpslld $2,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm3,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" + "vpaddd %%ymm4,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm2,%%ymm0,%%ymm0 \n" + "vpsrld $8,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%xmm0,(%[dst]) \n" + "lea 0x10(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" + + LABELALIGN + "3: \n" + "vmovd (%[src]),%%xmm0 \n" + "vmovd 0x04(%[src]),%%xmm1 \n" + "vmovd 0x08(%[src]),%%xmm2 \n" + "vmovd 0x0c(%[src]),%%xmm3 \n" + "vpaddd %%xmm3,%%xmm1,%%xmm1 \n" + "vmovd 0x10(%[src]),%%xmm3 \n" + "vpaddd %%xmm3,%%xmm0,%%xmm0 \n" + "lea 0x04(%[src]),%[src] \n" + "vpslld $2,%%xmm1,%%xmm1 \n" + "vpslld $1,%%xmm2,%%xmm3 \n" + "vpslld $2,%%xmm2,%%xmm2 \n" + "vpaddd %%xmm3,%%xmm2,%%xmm2 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpaddd %%xmm4,%%xmm2,%%xmm2 \n" + "vpaddd %%xmm2,%%xmm0,%%xmm0 \n" + "vpsrld $8,%%xmm0,%%xmm0 \n" + "vpextrw $0,%%xmm0,(%[dst]) \n" + "lea 0x02(%[dst]),%[dst] \n" + "sub $0x1,%[width] \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src), [dst] "+r"(dst), [width] "+r"(width) + : [k128] "m"(kGaussRound128), [kShuf] "m"(kShufGauss32To16) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif // HAS_GAUSSROW_AVX2 + +#ifdef HAS_GAUSSCOL_AVX2 +void GaussCol_AVX2(const uint16_t* src0, + const uint16_t* src1, + const uint16_t* src2, + const uint16_t* src3, + const uint16_t* src4, + uint32_t* dst, + int width) { +#if defined(__x86_64__) + ptrdiff_t off1 = (ptrdiff_t)((uintptr_t)src1 - (uintptr_t)src0); + ptrdiff_t off2 = (ptrdiff_t)((uintptr_t)src2 - (uintptr_t)src0); + ptrdiff_t off3 = (ptrdiff_t)((uintptr_t)src3 - (uintptr_t)src0); + ptrdiff_t off4 = (ptrdiff_t)((uintptr_t)src4 - (uintptr_t)src0); + asm volatile( + "vpxor %%xmm5,%%xmm5,%%xmm5 \n" + "sub $0x8,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vpmovzxwd (%[p0]),%%ymm0 \n" + "vpmovzxwd (%[p0],%[off4],1),%%ymm4 \n" + "vpmovzxwd (%[p0],%[off1],1),%%ymm1 \n" + "vpmovzxwd (%[p0],%[off3],1),%%ymm3 \n" + "vpmovzxwd (%[p0],%[off2],1),%%ymm2 \n" + "lea 0x10(%[p0]),%[p0] \n" + "vpaddd %%ymm4,%%ymm0,%%ymm0 \n" + "vpaddd %%ymm3,%%ymm1,%%ymm1 \n" + "vpslld $2,%%ymm1,%%ymm1 \n" + "vpslld $1,%%ymm2,%%ymm3 \n" + "vpslld $2,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm3,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" + "vpaddd %%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%[dp]) \n" + "lea 0x20(%[dp]),%[dp] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" + + LABELALIGN + "3: \n" + "vpinsrw $0,(%[p0]),%%xmm5,%%xmm0 \n" + "vpinsrw $0,(%[p0],%[off4],1),%%xmm5,%%xmm4\n" + "vpinsrw $0,(%[p0],%[off1],1),%%xmm5,%%xmm1\n" + "vpinsrw $0,(%[p0],%[off3],1),%%xmm5,%%xmm3\n" + "vpinsrw $0,(%[p0],%[off2],1),%%xmm5,%%xmm2\n" + "lea 0x02(%[p0]),%[p0] \n" + "vpaddd %%xmm4,%%xmm0,%%xmm0 \n" + "vpaddd %%xmm3,%%xmm1,%%xmm1 \n" + "vpslld $2,%%xmm1,%%xmm1 \n" + "vpslld $1,%%xmm2,%%xmm3 \n" + "vpslld $2,%%xmm2,%%xmm2 \n" + "vpaddd %%xmm3,%%xmm2,%%xmm2 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpaddd %%xmm2,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,(%[dp]) \n" + "lea 0x04(%[dp]),%[dp] \n" + "sub $0x1,%[width] \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" + : [p0] "+r"(src0), [dp] "+r"(dst), [width] "+r"(width) + : [off1] "r"(off1), [off2] "r"(off2), [off3] "r"(off3), + [off4] "r"(off4) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +#else + int n = width & ~7; + ptrdiff_t idx = 0; + const uint16_t* tmp; + asm volatile( + "vpxor %%xmm5,%%xmm5,%%xmm5 \n" + "cmpl $0,%[n] \n" + "jle 2f \n" + + LABELALIGN + "1: \n" + "mov %[s0],%[tmp] \n" + "vpmovzxwd (%[tmp],%[idx],2),%%ymm0 \n" + "mov %[s4],%[tmp] \n" + "vpmovzxwd (%[tmp],%[idx],2),%%ymm4 \n" + "mov %[s1],%[tmp] \n" + "vpmovzxwd (%[tmp],%[idx],2),%%ymm1 \n" + "mov %[s3],%[tmp] \n" + "vpmovzxwd (%[tmp],%[idx],2),%%ymm3 \n" + "mov %[s2],%[tmp] \n" + "vpmovzxwd (%[tmp],%[idx],2),%%ymm2 \n" + "add $0x8,%[idx] \n" + "vpaddd %%ymm4,%%ymm0,%%ymm0 \n" + "vpaddd %%ymm3,%%ymm1,%%ymm1 \n" + "vpslld $2,%%ymm1,%%ymm1 \n" + "vpslld $1,%%ymm2,%%ymm3 \n" + "vpslld $2,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm3,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm1,%%ymm0,%%ymm0 \n" + "vpaddd %%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%[dp]) \n" + "lea 0x20(%[dp]),%[dp] \n" + "cmpl %[n],%[idx] \n" + "jl 1b \n" + + "2: \n" + "cmpl %[width],%[idx] \n" + "jge 99f \n" + + LABELALIGN + "3: \n" + "mov %[s0],%[tmp] \n" + "vpinsrw $0,(%[tmp],%[idx],2),%%xmm5,%%xmm0\n" + "mov %[s4],%[tmp] \n" + "vpinsrw $0,(%[tmp],%[idx],2),%%xmm5,%%xmm4\n" + "mov %[s1],%[tmp] \n" + "vpinsrw $0,(%[tmp],%[idx],2),%%xmm5,%%xmm1\n" + "mov %[s3],%[tmp] \n" + "vpinsrw $0,(%[tmp],%[idx],2),%%xmm5,%%xmm3\n" + "mov %[s2],%[tmp] \n" + "vpinsrw $0,(%[tmp],%[idx],2),%%xmm5,%%xmm2\n" + "add $0x1,%[idx] \n" + "vpaddd %%xmm4,%%xmm0,%%xmm0 \n" + "vpaddd %%xmm3,%%xmm1,%%xmm1 \n" + "vpslld $2,%%xmm1,%%xmm1 \n" + "vpslld $1,%%xmm2,%%xmm3 \n" + "vpslld $2,%%xmm2,%%xmm2 \n" + "vpaddd %%xmm3,%%xmm2,%%xmm2 \n" + "vpaddd %%xmm1,%%xmm0,%%xmm0 \n" + "vpaddd %%xmm2,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,(%[dp]) \n" + "lea 0x04(%[dp]),%[dp] \n" + "cmpl %[width],%[idx] \n" + "jl 3b \n" + + "99: \n" + "vzeroupper \n" + : [idx] "+r"(idx), [tmp] "=&r"(tmp), [dp] "+r"(dst) + : [s0] "m"(src0), [s1] "m"(src1), [s2] "m"(src2), [s3] "m"(src3), + [s4] "m"(src4), [n] "m"(n), [width] "m"(width) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +#endif +} +#endif // HAS_GAUSSCOL_AVX2 + +#if defined(HAS_GAUSSROW_F32_AVX2) || defined(HAS_GAUSSCOL_F32_AVX2) +static const float kGaussF32_4 = 4.0f; +static const float kGaussF32_6 = 6.0f; +#endif // defined(HAS_GAUSSROW_F32_AVX2) || defined(HAS_GAUSSCOL_F32_AVX2) + +#ifdef HAS_GAUSSROW_F32_AVX2 +static const float kGaussF32_Scale = 1.0f / 256.0f; +void GaussRow_F32_AVX2(const float* src, float* dst, int width) { + asm volatile( + "vbroadcastss %[k4],%%ymm4 \n" + "vbroadcastss %[k6],%%ymm5 \n" + "vbroadcastss %[kScale],%%ymm6 \n" + "sub $0x8,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovups (%[src]),%%ymm0 \n" + "vmulps 0x04(%[src]),%%ymm4,%%ymm1 \n" + "vmulps 0x08(%[src]),%%ymm5,%%ymm2 \n" + "vmulps 0x0c(%[src]),%%ymm4,%%ymm3 \n" + "vaddps %%ymm1,%%ymm0,%%ymm0 \n" + "vaddps %%ymm2,%%ymm0,%%ymm0 \n" + "vaddps %%ymm3,%%ymm0,%%ymm0 \n" + "vaddps 0x10(%[src]),%%ymm0,%%ymm0 \n" + "lea 0x20(%[src]),%[src] \n" + "vmulps %%ymm6,%%ymm0,%%ymm0 \n" + "vmovups %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" + + LABELALIGN + "3: \n" + "vmovss (%[src]),%%xmm0 \n" + "vmulss 0x04(%[src]),%%xmm4,%%xmm1 \n" + "vmulss 0x08(%[src]),%%xmm5,%%xmm2 \n" + "vmulss 0x0c(%[src]),%%xmm4,%%xmm3 \n" + "vaddss %%xmm1,%%xmm0,%%xmm0 \n" + "vaddss %%xmm2,%%xmm0,%%xmm0 \n" + "vaddss %%xmm3,%%xmm0,%%xmm0 \n" + "vaddss 0x10(%[src]),%%xmm0,%%xmm0 \n" + "lea 0x04(%[src]),%[src] \n" + "vmulss %%xmm6,%%xmm0,%%xmm0 \n" + "vmovss %%xmm0,(%[dst]) \n" + "lea 0x04(%[dst]),%[dst] \n" + "sub $0x1,%[width] \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src), [dst] "+r"(dst), [width] "+r"(width) + : [k4] "m"(kGaussF32_4), [k6] "m"(kGaussF32_6), + [kScale] "m"(kGaussF32_Scale) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6"); +} +#endif // HAS_GAUSSROW_F32_AVX2 + +#ifdef HAS_GAUSSCOL_F32_AVX2 +void GaussCol_F32_AVX2(const float* src0, + const float* src1, + const float* src2, + const float* src3, + const float* src4, + float* dst, + int width) { +#if defined(__x86_64__) + ptrdiff_t off1 = (ptrdiff_t)((uintptr_t)src1 - (uintptr_t)src0); + ptrdiff_t off2 = (ptrdiff_t)((uintptr_t)src2 - (uintptr_t)src0); + ptrdiff_t off3 = (ptrdiff_t)((uintptr_t)src3 - (uintptr_t)src0); + ptrdiff_t off4 = (ptrdiff_t)((uintptr_t)src4 - (uintptr_t)src0); + asm volatile( + "vbroadcastss %[k4],%%ymm4 \n" + "vbroadcastss %[k6],%%ymm5 \n" + "sub $0x8,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovups (%[p0]),%%ymm0 \n" + "vmulps (%[p0],%[off1],1),%%ymm4,%%ymm1\n" + "vmulps (%[p0],%[off2],1),%%ymm5,%%ymm2\n" + "vmulps (%[p0],%[off3],1),%%ymm4,%%ymm3\n" + "vaddps %%ymm1,%%ymm0,%%ymm0 \n" + "vaddps %%ymm2,%%ymm0,%%ymm0 \n" + "vaddps %%ymm3,%%ymm0,%%ymm0 \n" + "vaddps (%[p0],%[off4],1),%%ymm0,%%ymm0\n" + "lea 0x20(%[p0]),%[p0] \n" + "vmovups %%ymm0,(%[dp]) \n" + "lea 0x20(%[dp]),%[dp] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" + + LABELALIGN + "3: \n" + "vmovss (%[p0]),%%xmm0 \n" + "vmulss (%[p0],%[off1],1),%%xmm4,%%xmm1\n" + "vmulss (%[p0],%[off2],1),%%xmm5,%%xmm2\n" + "vmulss (%[p0],%[off3],1),%%xmm4,%%xmm3\n" + "vaddss %%xmm1,%%xmm0,%%xmm0 \n" + "vaddss %%xmm2,%%xmm0,%%xmm0 \n" + "vaddss %%xmm3,%%xmm0,%%xmm0 \n" + "vaddss (%[p0],%[off4],1),%%xmm0,%%xmm0\n" + "lea 0x04(%[p0]),%[p0] \n" + "vmovss %%xmm0,(%[dp]) \n" + "lea 0x04(%[dp]),%[dp] \n" + "sub $0x1,%[width] \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" + : [p0] "+r"(src0), [dp] "+r"(dst), [width] "+r"(width) + : [off1] "r"(off1), [off2] "r"(off2), [off3] "r"(off3), + [off4] "r"(off4), [k4] "m"(kGaussF32_4), [k6] "m"(kGaussF32_6) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +#else + int n = width & ~7; + ptrdiff_t idx = 0; + const float* tmp; + asm volatile( + "vbroadcastss %[k4],%%ymm4 \n" + "vbroadcastss %[k6],%%ymm5 \n" + "cmpl $0,%[n] \n" + "jle 2f \n" + + LABELALIGN + "1: \n" + "mov %[s0],%[tmp] \n" + "vmovups (%[tmp],%[idx],4),%%ymm0 \n" + "mov %[s1],%[tmp] \n" + "vmulps (%[tmp],%[idx],4),%%ymm4,%%ymm1\n" + "mov %[s2],%[tmp] \n" + "vmulps (%[tmp],%[idx],4),%%ymm5,%%ymm2\n" + "mov %[s3],%[tmp] \n" + "vmulps (%[tmp],%[idx],4),%%ymm4,%%ymm3\n" + "vaddps %%ymm1,%%ymm0,%%ymm0 \n" + "vaddps %%ymm2,%%ymm0,%%ymm0 \n" + "vaddps %%ymm3,%%ymm0,%%ymm0 \n" + "mov %[s4],%[tmp] \n" + "vaddps (%[tmp],%[idx],4),%%ymm0,%%ymm0\n" + "add $0x8,%[idx] \n" + "vmovups %%ymm0,(%[dp]) \n" + "lea 0x20(%[dp]),%[dp] \n" + "cmpl %[n],%[idx] \n" + "jl 1b \n" + + "2: \n" + "cmpl %[width],%[idx] \n" + "jge 99f \n" + + LABELALIGN + "3: \n" + "mov %[s0],%[tmp] \n" + "vmovss (%[tmp],%[idx],4),%%xmm0 \n" + "mov %[s1],%[tmp] \n" + "vmulss (%[tmp],%[idx],4),%%xmm4,%%xmm1\n" + "mov %[s2],%[tmp] \n" + "vmulss (%[tmp],%[idx],4),%%xmm5,%%xmm2\n" + "mov %[s3],%[tmp] \n" + "vmulss (%[tmp],%[idx],4),%%xmm4,%%xmm3\n" + "vaddss %%xmm1,%%xmm0,%%xmm0 \n" + "vaddss %%xmm2,%%xmm0,%%xmm0 \n" + "vaddss %%xmm3,%%xmm0,%%xmm0 \n" + "mov %[s4],%[tmp] \n" + "vaddss (%[tmp],%[idx],4),%%xmm0,%%xmm0\n" + "add $0x1,%[idx] \n" + "vmovss %%xmm0,(%[dp]) \n" + "lea 0x04(%[dp]),%[dp] \n" + "cmpl %[width],%[idx] \n" + "jl 3b \n" + + "99: \n" + "vzeroupper \n" + : [idx] "+r"(idx), [tmp] "=&r"(tmp), [dp] "+r"(dst) + : [s0] "m"(src0), [s1] "m"(src1), [s2] "m"(src2), [s3] "m"(src3), + [s4] "m"(src4), [n] "m"(n), [width] "m"(width), [k4] "m"(kGaussF32_4), + [k6] "m"(kGaussF32_6) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +#endif +} +#endif // HAS_GAUSSCOL_F32_AVX2 + +#ifdef HAS_SCALEMAXSAMPLES_AVX2 +float ScaleMaxSamples_AVX2(const float* src, + float* dst, + float scale, + int width) { + float fmax; + asm volatile( + "vpxor %%xmm3,%%xmm3,%%xmm3 \n" + "vbroadcastss %[scale],%%ymm2 \n" + "sub $0x8,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovups (%[src]),%%ymm0 \n" + "lea 0x20(%[src]),%[src] \n" + "vmaxps %%ymm3,%%ymm0,%%ymm3 \n" + "vmulps %%ymm2,%%ymm0,%%ymm0 \n" + "vmovups %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" + + "vextractf128 $0x1,%%ymm3,%%xmm1 \n" + "vmaxps %%xmm3,%%xmm1,%%xmm3 \n" + "vpshufd $0x4e,%%xmm3,%%xmm1 \n" + "vmaxps %%xmm3,%%xmm1,%%xmm3 \n" + "vpshufd $0x55,%%xmm3,%%xmm1 \n" + "vmaxss %%xmm3,%%xmm1,%%xmm3 \n" + + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" + + LABELALIGN + "3: \n" + "vmovss (%[src]),%%xmm0 \n" + "lea 0x4(%[src]),%[src] \n" + "vmaxss %%xmm3,%%xmm0,%%xmm3 \n" + "vmulss %%xmm2,%%xmm0,%%xmm0 \n" + "vmovss %%xmm0,(%[dst]) \n" + "lea 0x4(%[dst]),%[dst] \n" + "sub $0x1,%[width] \n" + "jg 3b \n" + + "99: \n" + "vmovss %%xmm3,%[fmax] \n" + "vzeroupper \n" + : [src] "+r"(src), + [dst] "+r"(dst), + [width] "+r"(width), + [fmax] "=m"(fmax) + : [scale] "m"(scale) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); + return fmax; +} +#endif // HAS_SCALEMAXSAMPLES_AVX2 + +#ifdef HAS_SCALESUMSAMPLES_AVX2 +float ScaleSumSamples_AVX2(const float* src, + float* dst, + float scale, + int width) { + float fsum; + asm volatile( + "vpxor %%xmm3,%%xmm3,%%xmm3 \n" + "vbroadcastss %[scale],%%ymm2 \n" + "sub $0x8,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovups (%[src]),%%ymm0 \n" + "lea 0x20(%[src]),%[src] \n" + "vmulps %%ymm0,%%ymm0,%%ymm1 \n" + "vaddps %%ymm1,%%ymm3,%%ymm3 \n" + "vmulps %%ymm2,%%ymm0,%%ymm0 \n" + "vmovups %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" + + "vextractf128 $0x1,%%ymm3,%%xmm1 \n" + "vaddps %%xmm1,%%xmm3,%%xmm3 \n" + "vhaddps %%xmm3,%%xmm3,%%xmm3 \n" + "vhaddps %%xmm3,%%xmm3,%%xmm3 \n" + + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" + + LABELALIGN + "3: \n" + "vmovss (%[src]),%%xmm0 \n" + "lea 0x4(%[src]),%[src] \n" + "vmulss %%xmm0,%%xmm0,%%xmm1 \n" + "vaddss %%xmm1,%%xmm3,%%xmm3 \n" + "vmulss %%xmm2,%%xmm0,%%xmm0 \n" + "vmovss %%xmm0,(%[dst]) \n" + "lea 0x4(%[dst]),%[dst] \n" + "sub $0x1,%[width] \n" + "jg 3b \n" + + "99: \n" + "vmovss %%xmm3,%[fsum] \n" + "vzeroupper \n" + : [src] "+r"(src), + [dst] "+r"(dst), + [width] "+r"(width), + [fsum] "=m"(fsum) + : [scale] "m"(scale) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); + return fsum; +} +#endif // HAS_SCALESUMSAMPLES_AVX2 + +#ifdef HAS_SCALESAMPLES_AVX2 +void ScaleSamples_AVX2(const float* src, float* dst, float scale, int width) { + asm volatile( + "vbroadcastss %[scale],%%ymm2 \n" + "sub $0x8,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovups (%[src]),%%ymm0 \n" + "lea 0x20(%[src]),%[src] \n" + "vmulps %%ymm2,%%ymm0,%%ymm0 \n" + "vmovups %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" + + LABELALIGN + "3: \n" + "vmovss (%[src]),%%xmm0 \n" + "lea 0x4(%[src]),%[src] \n" + "vmulss %%xmm2,%%xmm0,%%xmm0 \n" + "vmovss %%xmm0,(%[dst]) \n" + "lea 0x4(%[dst]),%[dst] \n" + "sub $0x1,%[width] \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src), [dst] "+r"(dst), [width] "+r"(width) + : [scale] "m"(scale) + : "memory", "cc", "xmm0", "xmm2"); +} +#endif // HAS_SCALESAMPLES_AVX2 + +#ifdef HAS_ARGBCOLORTABLEROW_AVX2 +// Transform ARGB pixels with color table. +void ARGBColorTableRow_AVX2(uint8_t* dst_argb, + const uint8_t* table_argb, + int width) { + asm volatile( + "vpcmpeqd %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrld $24,%%ymm6,%%ymm6 \n" // 0x000000ff + "sub $0x8,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[dst]),%%ymm0 \n" + "vpand %%ymm6,%%ymm0,%%ymm1 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdd %%ymm7,0(%[table],%%ymm1,4),%%ymm2\n" + "vpand %%ymm6,%%ymm2,%%ymm2 \n" + + "vpsrld $8,%%ymm0,%%ymm1 \n" + "vpand %%ymm6,%%ymm1,%%ymm1 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdd %%ymm7,0(%[table],%%ymm1,4),%%ymm3\n" + "vpslld $8,%%ymm6,%%ymm4 \n" + "vpand %%ymm4,%%ymm3,%%ymm3 \n" + "vpor %%ymm3,%%ymm2,%%ymm2 \n" + + "vpsrld $16,%%ymm0,%%ymm1 \n" + "vpand %%ymm6,%%ymm1,%%ymm1 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdd %%ymm7,0(%[table],%%ymm1,4),%%ymm3\n" + "vpslld $16,%%ymm6,%%ymm4 \n" + "vpand %%ymm4,%%ymm3,%%ymm3 \n" + "vpor %%ymm3,%%ymm2,%%ymm2 \n" + + "vpsrld $24,%%ymm0,%%ymm1 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdd %%ymm7,0(%[table],%%ymm1,4),%%ymm3\n" + "vpslld $24,%%ymm6,%%ymm4 \n" + "vpand %%ymm4,%%ymm3,%%ymm3 \n" + "vpor %%ymm3,%%ymm2,%%ymm2 \n" + + "vmovdqu %%ymm2,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" + "vpcmpeqd %%xmm5,%%xmm5,%%xmm5 \n" + "vpsrldq $12,%%xmm5,%%xmm5 \n" + + LABELALIGN + "3: \n" + "vmovd (%[dst]),%%xmm0 \n" + "vpand %%xmm6,%%xmm0,%%xmm1 \n" + "vmovdqa %%xmm5,%%xmm7 \n" + "vpgatherdd %%xmm7,0(%[table],%%xmm1,4),%%xmm2\n" + "vpand %%xmm6,%%xmm2,%%xmm2 \n" + + "vpsrld $8,%%xmm0,%%xmm1 \n" + "vpand %%xmm6,%%xmm1,%%xmm1 \n" + "vmovdqa %%xmm5,%%xmm7 \n" + "vpgatherdd %%xmm7,0(%[table],%%xmm1,4),%%xmm3\n" + "vpslld $8,%%xmm6,%%xmm4 \n" + "vpand %%xmm4,%%xmm3,%%xmm3 \n" + "vpor %%xmm3,%%xmm2,%%xmm2 \n" + + "vpsrld $16,%%xmm0,%%xmm1 \n" + "vpand %%xmm6,%%xmm1,%%xmm1 \n" + "vmovdqa %%xmm5,%%xmm7 \n" + "vpgatherdd %%xmm7,0(%[table],%%xmm1,4),%%xmm3\n" + "vpslld $16,%%xmm6,%%xmm4 \n" + "vpand %%xmm4,%%xmm3,%%xmm3 \n" + "vpor %%xmm3,%%xmm2,%%xmm2 \n" + + "vpsrld $24,%%xmm0,%%xmm1 \n" + "vmovdqa %%xmm5,%%xmm7 \n" + "vpgatherdd %%xmm7,0(%[table],%%xmm1,4),%%xmm3\n" + "vpslld $24,%%xmm6,%%xmm4 \n" + "vpand %%xmm4,%%xmm3,%%xmm3 \n" + "vpor %%xmm3,%%xmm2,%%xmm2 \n" + + "vmovd %%xmm2,(%[dst]) \n" + "lea 0x04(%[dst]),%[dst] \n" + "sub $0x1,%[width] \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" + : [dst] "+r"(dst_argb), [width] "+r"(width) + : [table] "r"(table_argb) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); +} +#endif // HAS_ARGBCOLORTABLEROW_AVX2 + +#ifdef HAS_RGBCOLORTABLEROW_AVX2 +// Transform RGB pixels with color table. +void RGBColorTableRow_AVX2(uint8_t* dst_argb, const uint8_t* table_argb, int width) { - uintptr_t pixel_temp; asm volatile( - // 1 pixel loop. + "vpcmpeqd %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrld $24,%%ymm6,%%ymm6 \n" // 0x000000ff + "sub $0x8,%[width] \n" + "jl 2f \n" + LABELALIGN "1: \n" - "movzb (%0),%1 \n" - "lea 0x4(%0),%0 \n" - "movzb 0x00(%3,%1,4),%1 \n" - "mov %b1,-0x4(%0) \n" - "movzb -0x3(%0),%1 \n" - "movzb 0x01(%3,%1,4),%1 \n" - "mov %b1,-0x3(%0) \n" - "movzb -0x2(%0),%1 \n" - "movzb 0x02(%3,%1,4),%1 \n" - "mov %b1,-0x2(%0) \n" - "movzb -0x1(%0),%1 \n" - "movzb 0x03(%3,%1,4),%1 \n" - "mov %b1,-0x1(%0) \n" - "dec %2 \n" - "jg 1b \n" - : "+r"(dst_argb), // %0 - "=&d"(pixel_temp), // %1 - "+r"(width) // %2 - : "r"(table_argb) // %3 - : "memory", "cc"); -} -#endif // HAS_ARGBCOLORTABLEROW_X86 + "vmovdqu (%[dst]),%%ymm0 \n" + "vpand %%ymm6,%%ymm0,%%ymm1 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdd %%ymm7,0(%[table],%%ymm1,4),%%ymm2\n" + "vpand %%ymm6,%%ymm2,%%ymm2 \n" -#ifdef HAS_RGBCOLORTABLEROW_X86 -// Tranform RGB pixels with color table. -void RGBColorTableRow_X86(uint8_t* dst_argb, - const uint8_t* table_argb, + "vpsrld $8,%%ymm0,%%ymm1 \n" + "vpand %%ymm6,%%ymm1,%%ymm1 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdd %%ymm7,0(%[table],%%ymm1,4),%%ymm3\n" + "vpslld $8,%%ymm6,%%ymm4 \n" + "vpand %%ymm4,%%ymm3,%%ymm3 \n" + "vpor %%ymm3,%%ymm2,%%ymm2 \n" + + "vpsrld $16,%%ymm0,%%ymm1 \n" + "vpand %%ymm6,%%ymm1,%%ymm1 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdd %%ymm7,0(%[table],%%ymm1,4),%%ymm3\n" + "vpslld $16,%%ymm6,%%ymm4 \n" + "vpand %%ymm4,%%ymm3,%%ymm3 \n" + "vpor %%ymm3,%%ymm2,%%ymm2 \n" + + "vpslld $24,%%ymm6,%%ymm4 \n" + "vpand %%ymm4,%%ymm0,%%ymm0 \n" + "vpor %%ymm0,%%ymm2,%%ymm2 \n" + + "vmovdqu %%ymm2,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x8,%[width] \n" + "jle 99f \n" + "vpcmpeqd %%xmm5,%%xmm5,%%xmm5 \n" + "vpsrldq $12,%%xmm5,%%xmm5 \n" + + LABELALIGN + "3: \n" + "vmovd (%[dst]),%%xmm0 \n" + "vpand %%xmm6,%%xmm0,%%xmm1 \n" + "vmovdqa %%xmm5,%%xmm7 \n" + "vpgatherdd %%xmm7,0(%[table],%%xmm1,4),%%xmm2\n" + "vpand %%xmm6,%%xmm2,%%xmm2 \n" + + "vpsrld $8,%%xmm0,%%xmm1 \n" + "vpand %%xmm6,%%xmm1,%%xmm1 \n" + "vmovdqa %%xmm5,%%xmm7 \n" + "vpgatherdd %%xmm7,0(%[table],%%xmm1,4),%%xmm3\n" + "vpslld $8,%%xmm6,%%xmm4 \n" + "vpand %%xmm4,%%xmm3,%%xmm3 \n" + "vpor %%xmm3,%%xmm2,%%xmm2 \n" + + "vpsrld $16,%%xmm0,%%xmm1 \n" + "vpand %%xmm6,%%xmm1,%%xmm1 \n" + "vmovdqa %%xmm5,%%xmm7 \n" + "vpgatherdd %%xmm7,0(%[table],%%xmm1,4),%%xmm3\n" + "vpslld $16,%%xmm6,%%xmm4 \n" + "vpand %%xmm4,%%xmm3,%%xmm3 \n" + "vpor %%xmm3,%%xmm2,%%xmm2 \n" + + "vpslld $24,%%xmm6,%%xmm4 \n" + "vpand %%xmm4,%%xmm0,%%xmm0 \n" + "vpor %%xmm0,%%xmm2,%%xmm2 \n" + + "vmovd %%xmm2,(%[dst]) \n" + "lea 0x04(%[dst]),%[dst] \n" + "sub $0x1,%[width] \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" + : [dst] "+r"(dst_argb), [width] "+r"(width) + : [table] "r"(table_argb) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); +} +#endif // HAS_RGBCOLORTABLEROW_AVX2 + +#ifdef HAS_ARGBLUMACOLORTABLEROW_AVX2 +// Transform RGB pixels with luma table. +void ARGBLumaColorTableRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + int width, + const uint8_t* luma, + uint32_t lumacoeff) { + uint32_t c_br = lumacoeff & 0x00ff00ffu; + uint32_t c_ga = (lumacoeff >> 8) & 0x000000ffu; + asm volatile( + "vpcmpeqd %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrld $24,%%ymm6,%%ymm6 \n" // 0x000000ff +#if defined(__x86_64__) + "vpbroadcastd %[c_br],%%ymm8 \n" + "vpbroadcastd %[c_ga],%%ymm9 \n" + "vpsrld $1,%%ymm6,%%ymm10 \n" + "vpslld $8,%%ymm10,%%ymm10 \n" // 0x00007f00 + "vpsrld $6,%%ymm6,%%ymm11 \n" + "vpslld $3,%%ymm11,%%ymm11 \n" // 0x00000018 +#endif + "subl $0x8,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[src]),%%ymm0 \n" + "lea 0x20(%[src]),%[src] \n" + "vpsllw $8,%%ymm0,%%ymm1 \n" + "vpsrlw $8,%%ymm1,%%ymm1 \n" // [B, R] + "vpsrlw $8,%%ymm0,%%ymm2 \n" // [G, A] +#if defined(__x86_64__) + "vpmaddwd %%ymm8,%%ymm1,%%ymm1 \n" + "vpmaddwd %%ymm9,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm2,%%ymm1,%%ymm1 \n" + "vpand %%ymm10,%%ymm1,%%ymm1 \n" +#else + "vpbroadcastd %[c_br],%%ymm3 \n" + "vpmaddwd %%ymm3,%%ymm1,%%ymm1 \n" + "vpbroadcastd %[c_ga],%%ymm3 \n" + "vpmaddwd %%ymm3,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm2,%%ymm1,%%ymm1 \n" + "vpsrld $1,%%ymm6,%%ymm3 \n" + "vpslld $8,%%ymm3,%%ymm3 \n" + "vpand %%ymm3,%%ymm1,%%ymm1 \n" +#endif + + "vpand %%ymm6,%%ymm0,%%ymm3 \n" + "vpor %%ymm1,%%ymm3,%%ymm3 \n" + "vpsrld $2,%%ymm3,%%ymm3 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdd %%ymm7,0(%[luma],%%ymm3,4),%%ymm2\n" +#if defined(__x86_64__) + "vpslld $3,%%ymm0,%%ymm4 \n" + "vpand %%ymm11,%%ymm4,%%ymm4 \n" +#else + "vpslld $30,%%ymm0,%%ymm4 \n" + "vpsrld $27,%%ymm4,%%ymm4 \n" +#endif + "vpsrlvd %%ymm4,%%ymm2,%%ymm2 \n" + "vpand %%ymm6,%%ymm2,%%ymm2 \n" + + "vpsrld $8,%%ymm0,%%ymm3 \n" + "vpand %%ymm6,%%ymm3,%%ymm3 \n" + "vpor %%ymm1,%%ymm3,%%ymm3 \n" + "vpsrld $2,%%ymm3,%%ymm3 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdd %%ymm7,0(%[luma],%%ymm3,4),%%ymm5\n" +#if defined(__x86_64__) + "vpsrld $5,%%ymm0,%%ymm4 \n" + "vpand %%ymm11,%%ymm4,%%ymm4 \n" +#else + "vpslld $22,%%ymm0,%%ymm4 \n" + "vpsrld $30,%%ymm4,%%ymm4 \n" + "vpslld $3,%%ymm4,%%ymm4 \n" +#endif + "vpsrlvd %%ymm4,%%ymm5,%%ymm5 \n" + "vpand %%ymm6,%%ymm5,%%ymm5 \n" + "vpslld $8,%%ymm5,%%ymm5 \n" + "vpor %%ymm5,%%ymm2,%%ymm2 \n" + + "vpsrld $16,%%ymm0,%%ymm3 \n" + "vpand %%ymm6,%%ymm3,%%ymm3 \n" + "vpor %%ymm1,%%ymm3,%%ymm3 \n" + "vpsrld $2,%%ymm3,%%ymm3 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdd %%ymm7,0(%[luma],%%ymm3,4),%%ymm5\n" +#if defined(__x86_64__) + "vpsrld $13,%%ymm0,%%ymm4 \n" + "vpand %%ymm11,%%ymm4,%%ymm4 \n" +#else + "vpslld $14,%%ymm0,%%ymm4 \n" + "vpsrld $30,%%ymm4,%%ymm4 \n" + "vpslld $3,%%ymm4,%%ymm4 \n" +#endif + "vpsrlvd %%ymm4,%%ymm5,%%ymm5 \n" + "vpand %%ymm6,%%ymm5,%%ymm5 \n" + "vpslld $16,%%ymm5,%%ymm5 \n" + "vpor %%ymm5,%%ymm2,%%ymm2 \n" + + "vpsrld $24,%%ymm0,%%ymm0 \n" + "vpslld $24,%%ymm0,%%ymm0 \n" + "vpor %%ymm0,%%ymm2,%%ymm2 \n" + + "vmovdqu %%ymm2,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "subl $0x8,%[width] \n" + "jge 1b \n" + + "2: \n" + "addl $0x8,%[width] \n" + "jle 99f \n" + "vpcmpeqd %%xmm5,%%xmm5,%%xmm5 \n" + "vpsrldq $12,%%xmm5,%%xmm5 \n" + + LABELALIGN + "3: \n" + "vmovd (%[src]),%%xmm0 \n" + "lea 0x04(%[src]),%[src] \n" + "vpsllw $8,%%xmm0,%%xmm1 \n" + "vpsrlw $8,%%xmm1,%%xmm1 \n" + "vpsrlw $8,%%xmm0,%%xmm2 \n" +#if defined(__x86_64__) + "vpmaddwd %%xmm8,%%xmm1,%%xmm1 \n" + "vpmaddwd %%xmm9,%%xmm2,%%xmm2 \n" + "vpaddd %%xmm2,%%xmm1,%%xmm1 \n" + "vpand %%xmm10,%%xmm1,%%xmm1 \n" +#else + "vpbroadcastd %[c_br],%%xmm3 \n" + "vpmaddwd %%xmm3,%%xmm1,%%xmm1 \n" + "vpbroadcastd %[c_ga],%%xmm3 \n" + "vpmaddwd %%xmm3,%%xmm2,%%xmm2 \n" + "vpaddd %%xmm2,%%xmm1,%%xmm1 \n" + "vpsrld $1,%%xmm6,%%xmm3 \n" + "vpslld $8,%%xmm3,%%xmm3 \n" + "vpand %%xmm3,%%xmm1,%%xmm1 \n" +#endif + + "vpand %%xmm6,%%xmm0,%%xmm3 \n" + "vpor %%xmm1,%%xmm3,%%xmm3 \n" + "vpsrld $2,%%xmm3,%%xmm3 \n" + "vmovdqa %%xmm5,%%xmm7 \n" + "vpgatherdd %%xmm7,0(%[luma],%%xmm3,4),%%xmm2\n" +#if defined(__x86_64__) + "vpslld $3,%%xmm0,%%xmm4 \n" + "vpand %%xmm11,%%xmm4,%%xmm4 \n" +#else + "vpslld $30,%%xmm0,%%xmm4 \n" + "vpsrld $27,%%xmm4,%%xmm4 \n" +#endif + "vpsrlvd %%xmm4,%%xmm2,%%xmm2 \n" + "vpand %%xmm6,%%xmm2,%%xmm2 \n" + + "vpsrld $8,%%xmm0,%%xmm3 \n" + "vpand %%xmm6,%%xmm3,%%xmm3 \n" + "vpor %%xmm1,%%xmm3,%%xmm3 \n" + "vpsrld $2,%%xmm3,%%xmm3 \n" + "vmovdqa %%xmm5,%%xmm7 \n" + "vpgatherdd %%xmm7,0(%[luma],%%xmm3,4),%%xmm4\n" +#if defined(__x86_64__) + "vpsrld $5,%%xmm0,%%xmm3 \n" + "vpand %%xmm11,%%xmm3,%%xmm3 \n" +#else + "vpslld $22,%%xmm0,%%xmm3 \n" + "vpsrld $30,%%xmm3,%%xmm3 \n" + "vpslld $3,%%xmm3,%%xmm3 \n" +#endif + "vpsrlvd %%xmm3,%%xmm4,%%xmm4 \n" + "vpand %%xmm6,%%xmm4,%%xmm4 \n" + "vpslld $8,%%xmm4,%%xmm4 \n" + "vpor %%xmm4,%%xmm2,%%xmm2 \n" + + "vpsrld $16,%%xmm0,%%xmm3 \n" + "vpand %%xmm6,%%xmm3,%%xmm3 \n" + "vpor %%xmm1,%%xmm3,%%xmm3 \n" + "vpsrld $2,%%xmm3,%%xmm3 \n" + "vmovdqa %%xmm5,%%xmm7 \n" + "vpgatherdd %%xmm7,0(%[luma],%%xmm3,4),%%xmm4\n" +#if defined(__x86_64__) + "vpsrld $13,%%xmm0,%%xmm3 \n" + "vpand %%xmm11,%%xmm3,%%xmm3 \n" +#else + "vpslld $14,%%xmm0,%%xmm3 \n" + "vpsrld $30,%%xmm3,%%xmm3 \n" + "vpslld $3,%%xmm3,%%xmm3 \n" +#endif + "vpsrlvd %%xmm3,%%xmm4,%%xmm4 \n" + "vpand %%xmm6,%%xmm4,%%xmm4 \n" + "vpslld $16,%%xmm4,%%xmm4 \n" + "vpor %%xmm4,%%xmm2,%%xmm2 \n" + + "vpsrld $24,%%xmm0,%%xmm0 \n" + "vpslld $24,%%xmm0,%%xmm0 \n" + "vpor %%xmm0,%%xmm2,%%xmm2 \n" + + "vmovd %%xmm2,(%[dst]) \n" + "lea 0x04(%[dst]),%[dst] \n" + "subl $0x1,%[width] \n" + "jg 3b \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [width] "+rm"(width) + : [luma] "r"(luma), [c_br] "m"(c_br), [c_ga] "m"(c_ga) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7" +#if defined(__x86_64__) + , + "xmm8", "xmm9", "xmm10", "xmm11" +#endif + ); +} +#endif // HAS_ARGBLUMACOLORTABLEROW_AVX2 + +#if defined(HAS_NV21TOYUV24ROW_SSSE3) || defined(HAS_NV21TOYUV24ROW_AVX2) +static const uvec8 kYUV24Shuffle[3] = { + {8, 9, 0, 8, 9, 1, 10, 11, 2, 10, 11, 3, 12, 13, 4, 12}, + {9, 1, 10, 11, 2, 10, 11, 3, 12, 13, 4, 12, 13, 5, 14, 15}, + {2, 10, 11, 3, 12, 13, 4, 12, 13, 5, 14, 15, 6, 14, 15, 7}}; +#endif + +#ifdef HAS_NV21TOYUV24ROW_SSSE3 +// Convert biplanar NV21 to packed YUV24 +// NV21 has VU in memory for chroma. +// YUV24 is VUY in memory +void NV21ToYUV24Row_SSSE3(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_yuv24, int width) { - uintptr_t pixel_temp; asm volatile( - // 1 pixel loop. - LABELALIGN - "1: \n" - "movzb (%0),%1 \n" - "lea 0x4(%0),%0 \n" - "movzb 0x00(%3,%1,4),%1 \n" - "mov %b1,-0x4(%0) \n" - "movzb -0x3(%0),%1 \n" - "movzb 0x01(%3,%1,4),%1 \n" - "mov %b1,-0x3(%0) \n" - "movzb -0x2(%0),%1 \n" - "movzb 0x02(%3,%1,4),%1 \n" - "mov %b1,-0x2(%0) \n" - "dec %2 \n" - "jg 1b \n" - : "+r"(dst_argb), // %0 - "=&d"(pixel_temp), // %1 - "+r"(width) // %2 - : "r"(table_argb) // %3 - : "memory", "cc"); + "sub %0,%1 \n" + "movdqa (%4),%%xmm4 \n" // 3 shuffler constants + "movdqa 16(%4),%%xmm5 \n" + "movdqa 32(%4),%%xmm6 \n" + "1: \n" + "movdqu (%0),%%xmm2 \n" // load 16 Y values + "movdqu (%0,%1),%%xmm3 \n" // load 8 VU values + "lea 16(%0),%0 \n" + "movdqa %%xmm2,%%xmm0 \n" + "movdqa %%xmm2,%%xmm1 \n" + "shufps $0x44,%%xmm3,%%xmm0 \n" // Y 0..7, UV 0..3 + "shufps $0x99,%%xmm3,%%xmm1 \n" // Y 4..11, UV 2..5 + "shufps $0xee,%%xmm3,%%xmm2 \n" // Y 8..15, UV 4..7 + "pshufb %%xmm4, %%xmm0 \n" // weave into YUV24 + "pshufb %%xmm5, %%xmm1 \n" + "pshufb %%xmm6, %%xmm2 \n" + "movdqu %%xmm0,(%2) \n" + "movdqu %%xmm1,16(%2) \n" + "movdqu %%xmm2,32(%2) \n" + "lea 48(%2),%2 \n" + "sub $16,%3 \n" // 16 pixels per loop + "jg 1b \n" + : "+r"(src_y), // %0 + "+r"(src_vu), // %1 + "+r"(dst_yuv24), // %2 + "+r"(width) // %3 + : "r"(&kYUV24Shuffle[0]) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); } -#endif // HAS_RGBCOLORTABLEROW_X86 - -#ifdef HAS_ARGBLUMACOLORTABLEROW_SSSE3 -// Tranform RGB pixels with luma table. -void ARGBLumaColorTableRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_argb, - int width, - const uint8_t* luma, - uint32_t lumacoeff) { - uintptr_t pixel_temp; - uintptr_t table_temp; - asm volatile( - "movd %6,%%xmm3 \n" - "pshufd $0x0,%%xmm3,%%xmm3 \n" - "pcmpeqb %%xmm4,%%xmm4 \n" - "psllw $0x8,%%xmm4 \n" - "pxor %%xmm5,%%xmm5 \n" - - // 4 pixel loop. - LABELALIGN - "1: \n" - "movdqu (%2),%%xmm0 \n" - "pmaddubsw %%xmm3,%%xmm0 \n" - "phaddw %%xmm0,%%xmm0 \n" - "pand %%xmm4,%%xmm0 \n" - "punpcklwd %%xmm5,%%xmm0 \n" - "movd %%xmm0,%k1 \n" // 32 bit offset - "add %5,%1 \n" - "pshufd $0x39,%%xmm0,%%xmm0 \n" - - "movzb (%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,(%3) \n" - "movzb 0x1(%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,0x1(%3) \n" - "movzb 0x2(%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,0x2(%3) \n" - "movzb 0x3(%2),%0 \n" - "mov %b0,0x3(%3) \n" - - "movd %%xmm0,%k1 \n" // 32 bit offset - "add %5,%1 \n" - "pshufd $0x39,%%xmm0,%%xmm0 \n" - - "movzb 0x4(%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,0x4(%3) \n" - "movzb 0x5(%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,0x5(%3) \n" - "movzb 0x6(%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,0x6(%3) \n" - "movzb 0x7(%2),%0 \n" - "mov %b0,0x7(%3) \n" - - "movd %%xmm0,%k1 \n" // 32 bit offset - "add %5,%1 \n" - "pshufd $0x39,%%xmm0,%%xmm0 \n" - - "movzb 0x8(%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,0x8(%3) \n" - "movzb 0x9(%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,0x9(%3) \n" - "movzb 0xa(%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,0xa(%3) \n" - "movzb 0xb(%2),%0 \n" - "mov %b0,0xb(%3) \n" - - "movd %%xmm0,%k1 \n" // 32 bit offset - "add %5,%1 \n" - - "movzb 0xc(%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,0xc(%3) \n" - "movzb 0xd(%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,0xd(%3) \n" - "movzb 0xe(%2),%0 \n" - "movzb 0x00(%1,%0,1),%0 \n" - "mov %b0,0xe(%3) \n" - "movzb 0xf(%2),%0 \n" - "mov %b0,0xf(%3) \n" - "lea 0x10(%2),%2 \n" - "lea 0x10(%3),%3 \n" - "sub $0x4,%4 \n" - "jg 1b \n" - : "=&d"(pixel_temp), // %0 - "=&a"(table_temp), // %1 - "+r"(src_argb), // %2 - "+r"(dst_argb), // %3 - "+rm"(width) // %4 - : "r"(luma), // %5 - "rm"(lumacoeff) // %6 - : "memory", "cc", "xmm0", "xmm3", "xmm4", "xmm5"); -} -#endif // HAS_ARGBLUMACOLORTABLEROW_SSSE3 +#endif // HAS_NV21TOYUV24ROW_SSSE3 #ifdef HAS_NV21TOYUV24ROW_AVX2 - -// begin NV21ToYUV24Row_C avx2 constants -static const ulvec8 kBLEND0 = {0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, - 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, - 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00}; - -static const ulvec8 kBLEND1 = {0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80}; - -static const ulvec8 kBLEND2 = {0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00}; - -static const ulvec8 kSHUF0 = {0x00, 0x0b, 0x80, 0x01, 0x0c, 0x80, 0x02, 0x0d, - 0x80, 0x03, 0x0e, 0x80, 0x04, 0x0f, 0x80, 0x05, - 0x00, 0x0b, 0x80, 0x01, 0x0c, 0x80, 0x02, 0x0d, - 0x80, 0x03, 0x0e, 0x80, 0x04, 0x0f, 0x80, 0x05}; - -static const ulvec8 kSHUF1 = {0x80, 0x00, 0x0b, 0x80, 0x01, 0x0c, 0x80, 0x02, - 0x0d, 0x80, 0x03, 0x0e, 0x80, 0x04, 0x0f, 0x80, - 0x80, 0x00, 0x0b, 0x80, 0x01, 0x0c, 0x80, 0x02, - 0x0d, 0x80, 0x03, 0x0e, 0x80, 0x04, 0x0f, 0x80}; - -static const ulvec8 kSHUF2 = {0x0a, 0x80, 0x00, 0x0b, 0x80, 0x01, 0x0c, 0x80, - 0x02, 0x0d, 0x80, 0x03, 0x0e, 0x80, 0x04, 0x0f, - 0x0a, 0x80, 0x00, 0x0b, 0x80, 0x01, 0x0c, 0x80, - 0x02, 0x0d, 0x80, 0x03, 0x0e, 0x80, 0x04, 0x0f}; - -static const ulvec8 kSHUF3 = {0x80, 0x80, 0x06, 0x80, 0x80, 0x07, 0x80, 0x80, - 0x08, 0x80, 0x80, 0x09, 0x80, 0x80, 0x0a, 0x80, - 0x80, 0x80, 0x06, 0x80, 0x80, 0x07, 0x80, 0x80, - 0x08, 0x80, 0x80, 0x09, 0x80, 0x80, 0x0a, 0x80}; - -static const ulvec8 kSHUF4 = {0x05, 0x80, 0x80, 0x06, 0x80, 0x80, 0x07, 0x80, - 0x80, 0x08, 0x80, 0x80, 0x09, 0x80, 0x80, 0x0a, - 0x05, 0x80, 0x80, 0x06, 0x80, 0x80, 0x07, 0x80, - 0x80, 0x08, 0x80, 0x80, 0x09, 0x80, 0x80, 0x0a}; - -static const ulvec8 kSHUF5 = {0x80, 0x05, 0x80, 0x80, 0x06, 0x80, 0x80, 0x07, - 0x80, 0x80, 0x08, 0x80, 0x80, 0x09, 0x80, 0x80, - 0x80, 0x05, 0x80, 0x80, 0x06, 0x80, 0x80, 0x07, - 0x80, 0x80, 0x08, 0x80, 0x80, 0x09, 0x80, 0x80}; - -// NV21ToYUV24Row_AVX2 +// Convert biplanar NV21 to packed YUV24 +// NV21 has VU in memory for chroma. +// YUV24 is VUY in memory void NV21ToYUV24Row_AVX2(const uint8_t* src_y, const uint8_t* src_vu, uint8_t* dst_yuv24, int width) { - uint8_t* src_y_ptr; - uint64_t src_offset = 0; - uint64_t width64; - - width64 = width; - src_y_ptr = (uint8_t*)src_y; - asm volatile( - "vmovdqu %5, %%ymm0 \n" // init blend value - "vmovdqu %6, %%ymm1 \n" // init blend value - "vmovdqu %7, %%ymm2 \n" // init blend value - // "sub $0x20, %3 \n" //sub 32 from width for final loop + "sub %0,%1 \n" + "vbroadcasti128 (%4),%%ymm4 \n" // 3 shuffler constants + "vbroadcasti128 16(%4),%%ymm5 \n" + "vbroadcasti128 32(%4),%%ymm6 \n" - LABELALIGN - "1: \n" // label 1 - "vmovdqu (%0,%4), %%ymm3 \n" // src_y - "vmovdqu 1(%1,%4), %%ymm4 \n" // src_uv+1 - "vmovdqu (%1), %%ymm5 \n" // src_uv - "vpshufb %8, %%ymm3, %%ymm13 \n" // y, kSHUF0 for shuf - "vpshufb %9, %%ymm4, %%ymm14 \n" // uv+1, kSHUF1 for - // shuf - "vpshufb %10, %%ymm5, %%ymm15 \n" // uv, kSHUF2 for - // shuf - "vpshufb %11, %%ymm3, %%ymm3 \n" // y kSHUF3 for shuf - "vpshufb %12, %%ymm4, %%ymm4 \n" // uv+1 kSHUF4 for - // shuf - "vpblendvb %%ymm0, %%ymm14, %%ymm13, %%ymm12 \n" // blend 0 - "vpblendvb %%ymm0, %%ymm13, %%ymm14, %%ymm14 \n" // blend 0 - "vpblendvb %%ymm2, %%ymm15, %%ymm12, %%ymm12 \n" // blend 2 - "vpblendvb %%ymm1, %%ymm15, %%ymm14, %%ymm13 \n" // blend 1 - "vpshufb %13, %%ymm5, %%ymm15 \n" // shuffle const - "vpor %%ymm4, %%ymm3, %%ymm5 \n" // get results - "vmovdqu %%ymm12, 0x20(%2) \n" // store dst_yuv+20h - "vpor %%ymm15, %%ymm5, %%ymm3 \n" // get results - "add $0x20, %4 \n" // add to src buffer - // ptr - "vinserti128 $0x1, %%xmm3, %%ymm13, %%ymm4 \n" // insert - "vperm2i128 $0x31, %%ymm13, %%ymm3, %%ymm5 \n" // insert - "vmovdqu %%ymm4, (%2) \n" // store dst_yuv - "vmovdqu %%ymm5, 0x40(%2) \n" // store dst_yuv+40h - "add $0x60,%2 \n" // add to dst buffer - // ptr - // "cmp %3, %4 \n" //(width64 - - // 32 bytes) and src_offset - "sub $0x20,%3 \n" // 32 pixels per loop - "jg 1b \n" - "vzeroupper \n" // sse-avx2 - // transistions - - : "+r"(src_y), //%0 - "+r"(src_vu), //%1 - "+r"(dst_yuv24), //%2 - "+r"(width64), //%3 - "+r"(src_offset) //%4 - : "m"(kBLEND0), //%5 - "m"(kBLEND1), //%6 - "m"(kBLEND2), //%7 - "m"(kSHUF0), //%8 - "m"(kSHUF1), //%9 - "m"(kSHUF2), //%10 - "m"(kSHUF3), //%11 - "m"(kSHUF4), //%12 - "m"(kSHUF5) //%13 - : "memory", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm12", - "xmm13", "xmm14", "xmm15"); + "1: \n" + "vmovdqu (%0),%%ymm2 \n" // load 32 Y values + "vmovdqu (%0,%1),%%ymm3 \n" // load 16 VU values + "lea 32(%0),%0 \n" + "vshufps $0x44,%%ymm3,%%ymm2,%%ymm0 \n" // Y 0..7, UV 0..3 + "vshufps $0x99,%%ymm3,%%ymm2,%%ymm1 \n" // Y 4..11, UV 2..5 + "vshufps $0xee,%%ymm3,%%ymm2,%%ymm2 \n" // Y 8..15, UV 4..7 + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" // weave into YUV24 + "vpshufb %%ymm5,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm6,%%ymm2,%%ymm2 \n" + "vperm2i128 $0x20,%%ymm1,%%ymm0,%%ymm3 \n" + "vperm2i128 $0x30,%%ymm0,%%ymm2,%%ymm0 \n" + "vperm2i128 $0x31,%%ymm2,%%ymm1,%%ymm1 \n" + "vmovdqu %%ymm3,(%2) \n" + "vmovdqu %%ymm0,32(%2) \n" + "vmovdqu %%ymm1,64(%2) \n" + "lea 96(%2),%2 \n" + "sub $32,%3 \n" // 32 pixels per loop + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(src_vu), // %1 + "+r"(dst_yuv24), // %2 + "+r"(width) // %3 + : "r"(&kYUV24Shuffle[0]) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); } #endif // HAS_NV21TOYUV24ROW_AVX2 -#ifdef HAS_SWAPUVROW_SSSE3 +#ifdef HAS_NV21TOYUV24ROW_AVX512VBMI +static const uint8_t kNV21ToYUV24Perm_AVX512VBMI[3][64] = { + {64, 65, 0, 64, 65, 1, 66, 67, 2, 66, 67, 3, 68, 69, 4, 68, + 69, 5, 70, 71, 6, 70, 71, 7, 72, 73, 8, 72, 73, 9, 74, 75, + 10, 74, 75, 11, 76, 77, 12, 76, 77, 13, 78, 79, 14, 78, 79, 15, + 80, 81, 16, 80, 81, 17, 82, 83, 18, 82, 83, 19, 84, 85, 20, 84}, + {85, 21, 86, 87, 22, 86, 87, 23, 88, 89, 24, 88, 89, + 25, 90, 91, 26, 90, 91, 27, 92, 93, 28, 92, 93, 29, + 94, 95, 30, 94, 95, 31, 96, 97, 32, 96, 97, 33, 98, + 99, 34, 98, 99, 35, 100, 101, 36, 100, 101, 37, 102, 103, + 38, 102, 103, 39, 104, 105, 40, 104, 105, 41, 106, 107}, + {42, 106, 107, 43, 108, 109, 44, 108, 109, 45, 110, 111, 46, + 110, 111, 47, 112, 113, 48, 112, 113, 49, 114, 115, 50, 114, + 115, 51, 116, 117, 52, 116, 117, 53, 118, 119, 54, 118, 119, + 55, 120, 121, 56, 120, 121, 57, 122, 123, 58, 122, 123, 59, + 124, 125, 60, 124, 125, 61, 126, 127, 62, 126, 127, 63}}; + +LIBYUV_TARGET_AVX512VBMI +void NV21ToYUV24Row_AVX512VBMI(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_yuv24, + int width) { + uintptr_t temp; + uintptr_t mask; + asm volatile( + "sub %[src_y],%[src_vu] \n" + "vmovdqu8 (%[perm]),%%zmm4 \n" + "vmovdqu8 64(%[perm]),%%zmm5 \n" + "vmovdqu8 128(%[perm]),%%zmm16 \n" + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src_y]),%%zmm2 \n" // load 64 Y values + "vmovdqu8 (%[src_y],%[src_vu],1),%%zmm3 \n" // load 32 VU pairs + "lea 0x40(%[src_y]),%[src_y] \n" + "vmovdqa64 %%zmm2,%%zmm0 \n" + "vmovdqa64 %%zmm2,%%zmm1 \n" + "vpermt2b %%zmm3,%%zmm4,%%zmm0 \n" + "vpermt2b %%zmm3,%%zmm5,%%zmm1 \n" + "vpermt2b %%zmm3,%%zmm16,%%zmm2 \n" + "vmovdqu8 %%zmm0,(%[dst_yuv24]) \n" + "vmovdqu8 %%zmm1,0x40(%[dst_yuv24]) \n" + "vmovdqu8 %%zmm2,0x80(%[dst_yuv24]) \n" + "lea 0xc0(%[dst_yuv24]),%[dst_yuv24] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[mask] \n" + "kmovq %[mask],%%k1 \n" + "lea 1(%q[width]),%k[mask] \n" + "and $-2,%k[mask] \n" + "bzhi %q[mask],%[temp],%[mask] \n" + "kmovq %[mask],%%k2 \n" + "vmovdqu8 (%[src_y]),%%zmm2%{%%k1%}%{z%} \n" + "vmovdqu8 (%[src_y],%[src_vu],1),%%zmm3%{%%k2%}%{z%} \n" + "lea (%q[width],%q[width],2),%k[width] \n" + "bzhi %q[width],%[temp],%[mask] \n" + "kmovq %[mask],%%k1 \n" + "xor %k[mask],%k[mask] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[mask] \n" + "bzhi %q[width],%[mask],%[mask] \n" + "kmovq %[mask],%%k2 \n" + "xor %k[mask],%k[mask] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp],%[mask] \n" + "bzhi %q[width],%[mask],%[mask] \n" + "kmovq %[mask],%%k3 \n" + "vmovdqa64 %%zmm2,%%zmm0 \n" + "vmovdqa64 %%zmm2,%%zmm1 \n" + "vpermt2b %%zmm3,%%zmm4,%%zmm0 \n" + "vpermt2b %%zmm3,%%zmm5,%%zmm1 \n" + "vpermt2b %%zmm3,%%zmm16,%%zmm2 \n" + "vmovdqu8 %%zmm0,(%[dst_yuv24])%{%%k1%} \n" + "vmovdqu8 %%zmm1,0x40(%[dst_yuv24])%{%%k2%} \n" + "vmovdqu8 %%zmm2,0x80(%[dst_yuv24])%{%%k3%} \n" + + "99: \n" + "vzeroupper \n" + : [src_y] "+r"(src_y), [src_vu] "+r"(src_vu), [dst_yuv24] "+r"(dst_yuv24), + [width] "+r"(width), [temp] "=&r"(temp), [mask] "=&r"(mask) + : [perm] "r"(&kNV21ToYUV24Perm_AVX512VBMI[0][0]) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm16", + "k1", "k2", "k3"); +} +#endif // HAS_NV21TOYUV24ROW_AVX512VBMI + +#if defined(HAS_SWAPUVROW_SSSE3) || defined(HAS_SWAPUVROW_AVX2) // Shuffle table for reversing the bytes. static const uvec8 kShuffleUVToVU = {1u, 0u, 3u, 2u, 5u, 4u, 7u, 6u, 9u, 8u, 11u, 10u, 13u, 12u, 15u, 14u}; +#endif +#ifdef HAS_SWAPUVROW_SSSE3 // Convert UV plane of NV12 to VU of NV21. void SwapUVRow_SSSE3(const uint8_t* src_uv, uint8_t* dst_vu, int width) { - asm volatile( + asm volatile("movdqu %3,%%xmm5 \n" - "movdqu %3,%%xmm5 \n" - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "pshufb %%xmm5,%%xmm0 \n" - "pshufb %%xmm5,%%xmm1 \n" - "movdqu %%xmm0,(%1) \n" - "movdqu %%xmm1,0x10(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_uv), // %0 - "+r"(dst_vu), // %1 - "+r"(width) // %2 - : "m"(kShuffleUVToVU) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm5"); + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "pshufb %%xmm5,%%xmm0 \n" + "pshufb %%xmm5,%%xmm1 \n" + "movdqu %%xmm0,(%1) \n" + "movdqu %%xmm1,0x10(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_uv), // %0 + "+r"(dst_vu), // %1 + "+r"(width) // %2 + : "m"(kShuffleUVToVU) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm5"); } #endif // HAS_SWAPUVROW_SSSE3 #ifdef HAS_SWAPUVROW_AVX2 void SwapUVRow_AVX2(const uint8_t* src_uv, uint8_t* dst_vu, int width) { - asm volatile( + asm volatile("vbroadcasti128 %3,%%ymm5 \n" - "vbroadcastf128 %3,%%ymm5 \n" - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" - "vpshufb %%ymm5,%%ymm1,%%ymm1 \n" - "vmovdqu %%ymm0,(%1) \n" - "vmovdqu %%ymm1,0x20(%1) \n" - "lea 0x40(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_uv), // %0 - "+r"(dst_vu), // %1 - "+r"(width) // %2 - : "m"(kShuffleUVToVU) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm5"); + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpshufb %%ymm5,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm5,%%ymm1,%%ymm1 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_uv), // %0 + "+r"(dst_vu), // %1 + "+r"(width) // %2 + : "m"(kShuffleUVToVU) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm5"); } #endif // HAS_SWAPUVROW_AVX2 -#endif // defined(__x86_64__) || defined(__i386__) +#ifdef HAS_HALFMERGEUVROW_SSSE3 +void HalfMergeUVRow_SSSE3(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width) { + asm volatile( + "pcmpeqb %%xmm4,%%xmm4 \n" // 0x0101 + "pabsb %%xmm4,%%xmm4 \n" + "pxor %%xmm5,%%xmm5 \n" + + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" // load 16 U values + "movdqu (%1),%%xmm1 \n" // load 16 V values + "movdqu 0(%0,%4,1),%%xmm2 \n" // 16 from next row + "movdqu 0(%1,%5,1),%%xmm3 \n" + "lea 0x10(%0),%0 \n" + "pmaddubsw %%xmm4,%%xmm0 \n" // half size + "pmaddubsw %%xmm4,%%xmm1 \n" + "pmaddubsw %%xmm4,%%xmm2 \n" + "pmaddubsw %%xmm4,%%xmm3 \n" + "lea 0x10(%1),%1 \n" + "paddw %%xmm2,%%xmm0 \n" + "paddw %%xmm3,%%xmm1 \n" + "psrlw $0x1,%%xmm0 \n" + "psrlw $0x1,%%xmm1 \n" + "pavgw %%xmm5,%%xmm0 \n" + "pavgw %%xmm5,%%xmm1 \n" + "packuswb %%xmm0,%%xmm0 \n" + "packuswb %%xmm1,%%xmm1 \n" + "punpcklbw %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%2) \n" // store 8 UV pixels + "lea 0x10(%2),%2 \n" + "sub $0x10,%3 \n" // 16 src pixels per loop + "jg 1b \n" + : "+r"(src_u), // %0 + "+r"(src_v), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : "r"((ptrdiff_t)(src_stride_u)), // %4 + "r"((ptrdiff_t)(src_stride_v)) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif // HAS_HALFMERGEUVROW_SSSE3 + +#ifdef HAS_HALFMERGEUVROW_AVX2 +void HalfMergeUVRow_AVX2(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width) { + asm volatile( + "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" + "vpabsb %%ymm4,%%ymm4 \n" + "vpxor %%ymm5,%%ymm5,%%ymm5 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" // load 32 U values + "vmovdqu (%1),%%ymm1 \n" // load 32 V values + "vmovdqu 0(%0,%4,1),%%ymm2 \n" // 32 from next row + "vmovdqu 0(%1,%5,1),%%ymm3 \n" + "lea 0x20(%0),%0 \n" + "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" // half size + "vpmaddubsw %%ymm4,%%ymm1,%%ymm1 \n" + "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" + "lea 0x20(%1),%1 \n" + "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm3,%%ymm1,%%ymm1 \n" + "vpsrlw $0x1,%%ymm0,%%ymm0 \n" + "vpsrlw $0x1,%%ymm1,%%ymm1 \n" + "vpavgw %%ymm5,%%ymm0,%%ymm0 \n" + "vpavgw %%ymm5,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" + "vpunpcklbw %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%2) \n" // store 16 UV pixels + "lea 0x20(%2),%2 \n" + "sub $0x20,%3 \n" // 32 src pixels per loop + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_u), // %0 + "+r"(src_v), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : "r"((ptrdiff_t)(src_stride_u)), // %4 + "r"((ptrdiff_t)(src_stride_v)) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif // HAS_HALFMERGEUVROW_AVX2 + +#ifdef HAS_CONVERT8TO8ROW_AVX2 +void Convert8To8Row_AVX2(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width) { + asm volatile( + "sub %0,%1 \n" + "vmovd %3,%%xmm2 \n" + "vmovd %4,%%xmm3 \n" + "vpbroadcastw %%xmm2,%%ymm2 \n" + "vpbroadcastb %%xmm3,%%ymm3 \n" + "vpxor %%ymm4,%%ymm4,%%ymm4 \n" + "vpsllw $8,%%ymm2,%%ymm2 \n" + + // 32 pixels per loop. + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vpunpckhbw %%ymm4,%%ymm0,%%ymm1 \n" // mutates + "vpunpcklbw %%ymm4,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm2,%%ymm0,%%ymm0 \n" + "vpmulhuw %%ymm2,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" // unmutates + "vpaddb %%ymm3,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%0,%1) \n" + "add $0x20,%0 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(scale), // %3 + "r"(bias) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif // HAS_CONVERT8TO8ROW_AVX2 + +#ifdef HAS_CONVERT8TO8ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void Convert8To8Row_AVX512BW(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width) { + uintptr_t temp; + asm volatile( + "vpbroadcastw %k[scale],%%zmm2 \n" + "vpbroadcastb %k[bias],%%zmm3 \n" + "vpxord %%zmm4,%%zmm4,%%zmm4 \n" + "vpsllw $8,%%zmm2,%%zmm2 \n" + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src]),%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "vpunpckhbw %%zmm4,%%zmm0,%%zmm1 \n" + "vpunpcklbw %%zmm4,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm2,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vpaddb %%zmm3,%%zmm0,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovq %[temp],%%k1 \n" + "vmovdqu8 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vpunpckhbw %%zmm4,%%zmm0,%%zmm1 \n" + "vpunpcklbw %%zmm4,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm2,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vpaddb %%zmm3,%%zmm0,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_y), [dst] "+r"(dst_y), [width] "+r"(width), + [temp] "=&r"(temp) + : [scale] "r"(scale), [bias] "r"(bias) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "k1"); +} +#endif // HAS_CONVERT8TO8ROW_AVX512BW + +// =========================================================================== +// Module 1: AYUV to Planar Y / UV / VU (AVX512VBMI) +// =========================================================================== + +#ifdef HAS_AYUVTOYROW_AVX512VBMI +static const uint8_t kPermAYUVToY32[64] = { + 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, + 66, 70, 74, 78, 82, 86, 90, 94, 98, 102, 106, 110, 114, 118, 122, 126, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +LIBYUV_TARGET_AVX512VBMI +void OMITFP AYUVToYRow_AVX512VBMI(const uint8_t* src_ayuv, + uint8_t* dst_y, + int width) { + uintptr_t temp; + asm volatile( + "vmovdqu8 %[perm],%%zmm16 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src]),%%zmm0 \n" + "vmovdqu8 0x40(%[src]),%%zmm1 \n" + "lea 0x80(%[src]),%[src] \n" + "vmovdqa64 %%zmm16,%%zmm2 \n" + "vpermt2b %%zmm1,%%zmm2,%%zmm0 \n" + "vmovdqu8 %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovd %k[temp],%%k3 \n" + "kmovw %k[temp],%%k1 \n" + "kshiftrd $16,%%k3,%%k2 \n" + "vmovdqu32 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src]),%%zmm1%{%%k2%}%{z%}\n" + "vpermt2b %%zmm1,%%zmm16,%%zmm0 \n" + "vmovdqu8 %%ymm0,(%[dst])%{%%k3%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_ayuv), [dst] "+r"(dst_y), [width] "+r"(width), + [temp] "=&r"(temp) + : [perm] "m"(kPermAYUVToY32) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm16", "k1", "k2", "k3"); +} +#endif // HAS_AYUVTOYROW_AVX512VBMI + +#if defined(HAS_AYUVTOUVROW_AVX512VBMI) || defined(HAS_AYUVTOVUROW_AVX512VBMI) +static const uint8_t kPermAYUVToUV[64] = { + 1, 5, 0, 4, 9, 13, 8, 12, 17, 21, 16, 20, 25, + 29, 24, 28, 33, 37, 32, 36, 41, 45, 40, 44, 49, 53, + 48, 52, 57, 61, 56, 60, 65, 69, 64, 68, 73, 77, 72, + 76, 81, 85, 80, 84, 89, 93, 88, 92, 97, 101, 96, 100, + 105, 109, 104, 108, 113, 117, 112, 116, 121, 125, 120, 124}; + +static const uint8_t kPermAYUVToVU[64] = { + 0, 4, 1, 5, 8, 12, 9, 13, 16, 20, 17, 21, 24, + 28, 25, 29, 32, 36, 33, 37, 40, 44, 41, 45, 48, 52, + 49, 53, 56, 60, 57, 61, 64, 68, 65, 69, 72, 76, 73, + 77, 80, 84, 81, 85, 88, 92, 89, 93, 96, 100, 97, 101, + 104, 108, 105, 109, 112, 116, 113, 117, 120, 124, 121, 125}; + +LIBYUV_TARGET_AVX512VBMI +static inline void AYUVToUVOrVURow_AVX512VBMI(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + const uint8_t* perm_table, + int width) { + uintptr_t temp1; + uintptr_t temp2; + asm volatile( + "vmovdqu8 (%[perm]),%%zmm16 \n" + "vpternlogd $0xff,%%zmm18,%%zmm18,%%zmm18 \n" + "vpsrlw $15,%%zmm18,%%zmm18 \n" + "vpsllw $8,%%zmm18,%%zmm19 \n" + "vpord %%zmm19,%%zmm18,%%zmm18 \n" // 0x0101 + "vpxord %%zmm19,%%zmm19,%%zmm19 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src]),%%zmm0 \n" + "vmovdqu8 0x40(%[src]),%%zmm1 \n" + "vmovdqu8 (%[src],%[stride]),%%zmm2 \n" + "vmovdqu8 0x40(%[src],%[stride]),%%zmm3 \n" + "lea 0x80(%[src]),%[src] \n" + "vpermt2b %%zmm1,%%zmm16,%%zmm0 \n" + "vpermt2b %%zmm3,%%zmm16,%%zmm2 \n" + "vpmaddubsw %%zmm18,%%zmm0,%%zmm0 \n" + "vpmaddubsw %%zmm18,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm2,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm19,%%zmm0,%%zmm0 \n" + "vpmovwb %%zmm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp1] \n" + "bzhi %q[width],%[temp1],%[temp1] \n" + "kmovd %k[temp1],%%k3 \n" + "kmovw %k[temp1],%%k1 \n" + "kshiftrd $16,%%k3,%%k2 \n" + "vmovdqu32 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src]),%%zmm1%{%%k2%}%{z%}\n" + "vmovdqu32 (%[src],%[stride]),%%zmm2%{%%k1%}%{z%}\n" + "vmovdqu32 0x40(%[src],%[stride]),%%zmm3%{%%k2%}%{z%}\n" + "vpermt2b %%zmm1,%%zmm16,%%zmm0 \n" + "vpermt2b %%zmm3,%%zmm16,%%zmm2 \n" + // If width is odd, duplicate pixel (width - 1) into pixel width in dword + // (width >> 1). + "mov %k[width],%k[temp1] \n" + "and $1,%k[temp1] \n" + "mov %k[width],%k[temp2] \n" + "shr $1,%k[temp2] \n" + "shlx %k[temp2],%k[temp1],%k[temp1] \n" + "kmovw %k[temp1],%%k4 \n" + "vpslld $8,%%zmm0,%%zmm1 \n" + "vpord %%zmm1,%%zmm0,%%zmm0%{%%k4%} \n" + "vpslld $8,%%zmm2,%%zmm3 \n" + "vpord %%zmm3,%%zmm2,%%zmm2%{%%k4%} \n" + "vpmaddubsw %%zmm18,%%zmm0,%%zmm0 \n" + "vpmaddubsw %%zmm18,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm2,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm19,%%zmm0,%%zmm0 \n" + "lea 1(%q[width]),%k[temp2] \n" + "and $-2,%k[temp2] \n" + "mov $-1,%[temp1] \n" + "bzhi %q[temp2],%[temp1],%[temp1] \n" + "kmovd %k[temp1],%%k3 \n" + "vpmovwb %%zmm0,(%[dst])%{%%k3%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_ayuv), [dst] "+r"(dst_uv), [width] "+r"(width), + [temp1] "=&r"(temp1), [temp2] "=&r"(temp2) + : [stride] "r"((ptrdiff_t)src_stride_ayuv), [perm] "r"(perm_table) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm16", "xmm18", + "xmm19", "k1", "k2", "k3", "k4"); +} +#endif // defined(HAS_AYUVTOUVROW_AVX512VBMI) || + // defined(HAS_AYUVTOVUROW_AVX512VBMI) + +#ifdef HAS_AYUVTOUVROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void OMITFP AYUVToUVRow_AVX512VBMI(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + int width) { + AYUVToUVOrVURow_AVX512VBMI(src_ayuv, src_stride_ayuv, dst_uv, kPermAYUVToUV, + width); +} +#endif // HAS_AYUVTOUVROW_AVX512VBMI + +#ifdef HAS_AYUVTOVUROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void OMITFP AYUVToVURow_AVX512VBMI(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_vu, + int width) { + AYUVToUVOrVURow_AVX512VBMI(src_ayuv, src_stride_ayuv, dst_vu, kPermAYUVToVU, + width); +} +#endif // HAS_AYUVTOVUROW_AVX512VBMI + +#ifdef HAS_AYUVTOYROW_AVX2 +void OMITFP AYUVToYRow_AVX2(const uint8_t* src_ayuv, + uint8_t* dst_y, + int width) { + asm volatile( + "vpcmpeqd %%ymm2,%%ymm2,%%ymm2 \n" + "vpsrld $24,%%ymm2,%%ymm2 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[src]),%%ymm0 \n" + "vmovdqu 0x20(%[src]),%%ymm1 \n" + "lea 0x40(%[src]),%[src] \n" + "vpsrld $16,%%ymm0,%%ymm0 \n" + "vpsrld $16,%%ymm1,%%ymm1 \n" + "vpand %%ymm2,%%ymm0,%%ymm0 \n" + "vpand %%ymm2,%%ymm1,%%ymm1 \n" + "vpackusdw %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vextracti128 $1,%%ymm0,%%xmm1 \n" + "vpackuswb %%xmm1,%%xmm0,%%xmm0 \n" + "vmovdqu %%xmm0,(%[dst]) \n" + "lea 0x10(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src_ayuv), [dst] "+r"(dst_y), [width] "+r"(width) + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); +} +#endif // HAS_AYUVTOYROW_AVX2 + +#if defined(HAS_AYUVTOUVROW_AVX2) || defined(HAS_AYUVTOVUROW_AVX2) +static const uint8_t kShufAYUVToUV16[16] = { + 1, 5, 0, 4, 9, 13, 8, 12, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}; + +static const uint8_t kShufAYUVToVU16[16] = { + 0, 4, 1, 5, 8, 12, 9, 13, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}; + +static inline void AYUVToUVOrVURow_AVX2(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + const uint8_t* shuf_table, + int width) { + asm volatile( + "vbroadcasti128 (%[shuf]),%%ymm6 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpsrlw $15,%%ymm7,%%ymm7 \n" + "vpsllw $8,%%ymm7,%%ymm5 \n" + "vpor %%ymm5,%%ymm7,%%ymm7 \n" + "vpxor %%ymm5,%%ymm5,%%ymm5 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[src]),%%ymm0 \n" + "vmovdqu 0x20(%[src]),%%ymm1 \n" + "vmovdqu (%[src],%[stride]),%%ymm2 \n" + "vmovdqu 0x20(%[src],%[stride]),%%ymm3 \n" + "lea 0x40(%[src]),%[src] \n" + "vpshufb %%ymm6,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm6,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm6,%%ymm2,%%ymm2 \n" + "vpshufb %%ymm6,%%ymm3,%%ymm3 \n" + "vpunpcklqdq %%ymm1,%%ymm0,%%ymm0 \n" + "vpunpcklqdq %%ymm3,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm7,%%ymm0,%%ymm0 \n" + "vpmaddubsw %%ymm7,%%ymm2,%%ymm2 \n" + "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" + "vpsrlw $1,%%ymm0,%%ymm0 \n" + "vpavgw %%ymm5,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vextracti128 $1,%%ymm0,%%xmm1 \n" + "vpackuswb %%xmm1,%%xmm0,%%xmm0 \n" + "vmovdqu %%xmm0,(%[dst]) \n" + "lea 0x10(%[dst]),%[dst] \n" + "subl $0x10,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src_ayuv), [dst] "+r"(dst_uv), [width] "+rm"(width) + : [stride] "r"((ptrdiff_t)src_stride_ayuv), [shuf] "r"(shuf_table) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5", "xmm6", "xmm7"); +} +#endif // defined(HAS_AYUVTOUVROW_AVX2) || defined(HAS_AYUVTOVUROW_AVX2) + +#ifdef HAS_AYUVTOUVROW_AVX2 +void OMITFP AYUVToUVRow_AVX2(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + int width) { + AYUVToUVOrVURow_AVX2(src_ayuv, src_stride_ayuv, dst_uv, kShufAYUVToUV16, + width); +} +#endif // HAS_AYUVTOUVROW_AVX2 + +#ifdef HAS_AYUVTOVUROW_AVX2 +void OMITFP AYUVToVURow_AVX2(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_vu, + int width) { + AYUVToUVOrVURow_AVX2(src_ayuv, src_stride_ayuv, dst_vu, kShufAYUVToVU16, + width); +} +#endif // HAS_AYUVTOVUROW_AVX2 + +// =========================================================================== +// Module 2: 10-bit / 30-bit AR30 & XR30 Pack / Unpack (AVX2 / AVX512BW) +// =========================================================================== + +#ifdef HAS_AR30TOARGBROW_AVX2 +void OMITFP AR30ToARGBRow_AVX2(const uint8_t* src_ar30, + uint8_t* dst_argb, + int width) { + static const uint32_t kC0000000 = 0xc0000000u; + static const uint32_t k300000FF = 0x300000ffu; + static const uint32_t k0C00FF00 = 0x0c00ff00u; + static const uint32_t k03FF0000 = 0x03ff0000u; + asm volatile( + "vpbroadcastd %[m0],%%ymm4 \n" + "vpbroadcastd %[m1],%%ymm5 \n" + "vpbroadcastd %[m2],%%ymm6 \n" + "vpbroadcastd %[m3],%%ymm7 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[src]),%%ymm0 \n" + "lea 0x20(%[src]),%[src] \n" + "vpsrld $2,%%ymm0,%%ymm1 \n" + "vpsrld $4,%%ymm0,%%ymm2 \n" + "vpsrld $6,%%ymm0,%%ymm3 \n" + "vpand %%ymm4,%%ymm0,%%ymm0 \n" + "vpand %%ymm5,%%ymm1,%%ymm1 \n" + "vpand %%ymm6,%%ymm2,%%ymm2 \n" + "vpand %%ymm7,%%ymm3,%%ymm3 \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" + "vpor %%ymm3,%%ymm2,%%ymm2 \n" + "vpor %%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src_ar30), [dst] "+r"(dst_argb), [width] "+r"(width) + : [m0] "m"(kC0000000), [m1] "m"(k300000FF), [m2] "m"(k0C00FF00), + [m3] "m"(k03FF0000) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_AR30TOARGBROW_AVX2 + +#ifdef HAS_AR30TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP AR30ToARGBRow_AVX512BW(const uint8_t* src_ar30, + uint8_t* dst_argb, + int width) { + static const uint32_t kC0000000 = 0xc0000000u; + static const uint32_t k300000FF = 0x300000ffu; + static const uint32_t k0C00FF00 = 0x0c00ff00u; + static const uint32_t k03FF0000 = 0x03ff0000u; + uintptr_t temp; + asm volatile( + "vpbroadcastd %[m0],%%zmm16 \n" + "vpbroadcastd %[m1],%%zmm17 \n" + "vpbroadcastd %[m2],%%zmm18 \n" + "vpbroadcastd %[m3],%%zmm19 \n" + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src]),%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "vpsrld $2,%%zmm0,%%zmm1 \n" + "vpsrld $4,%%zmm0,%%zmm2 \n" + "vpsrld $6,%%zmm0,%%zmm3 \n" + "vpandd %%zmm16,%%zmm0,%%zmm0 \n" + "vpandd %%zmm17,%%zmm1,%%zmm1 \n" + "vpandd %%zmm18,%%zmm2,%%zmm2 \n" + "vpandd %%zmm19,%%zmm3,%%zmm3 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vpord %%zmm3,%%zmm2,%%zmm2 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vpsrld $2,%%zmm0,%%zmm1 \n" + "vpsrld $4,%%zmm0,%%zmm2 \n" + "vpsrld $6,%%zmm0,%%zmm3 \n" + "vpandd %%zmm16,%%zmm0,%%zmm0 \n" + "vpandd %%zmm17,%%zmm1,%%zmm1 \n" + "vpandd %%zmm18,%%zmm2,%%zmm2 \n" + "vpandd %%zmm19,%%zmm3,%%zmm3 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vpord %%zmm3,%%zmm2,%%zmm2 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_ar30), [dst] "+r"(dst_argb), [width] "+r"(width), + [temp] "=&r"(temp) + : [m0] "m"(kC0000000), [m1] "m"(k300000FF), [m2] "m"(k0C00FF00), + [m3] "m"(k03FF0000) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm16", "xmm17", + "xmm18", "xmm19", "k1"); +} +#endif // HAS_AR30TOARGBROW_AVX512BW + +#if defined(HAS_AR30TOABGRROW_AVX2) || defined(HAS_AR30TOABGRROW_AVX512BW) +static const uint8_t kShufSwapRB16[16] = {2, 1, 0, 3, 6, 5, 4, 7, + 10, 9, 8, 11, 14, 13, 12, 15}; +#endif + +#ifdef HAS_AR30TOABGRROW_AVX2 +void OMITFP AR30ToABGRRow_AVX2(const uint8_t* src_ar30, + uint8_t* dst_abgr, + int width) { + static const uint32_t kC0000000 = 0xc0000000u; + static const uint32_t k300000FF = 0x300000ffu; + static const uint32_t k0C00FF00 = 0x0c00ff00u; + static const uint32_t k03FF0000 = 0x03ff0000u; + asm volatile( + "vpbroadcastd %[m0],%%ymm4 \n" + "vpbroadcastd %[m1],%%ymm5 \n" + "vpbroadcastd %[m2],%%ymm6 \n" +#if defined(__x86_64__) + "vpbroadcastd %[m3],%%ymm8 \n" +#endif + "vbroadcasti128 %[shuf],%%ymm7 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[src]),%%ymm0 \n" + "lea 0x20(%[src]),%[src] \n" + "vpsrld $2,%%ymm0,%%ymm1 \n" + "vpsrld $4,%%ymm0,%%ymm2 \n" + "vpand %%ymm5,%%ymm1,%%ymm1 \n" + "vpand %%ymm6,%%ymm2,%%ymm2 \n" + "vpsrld $6,%%ymm0,%%ymm3 \n" + "vpand %%ymm4,%%ymm0,%%ymm0 \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" +#if defined(__x86_64__) + "vpand %%ymm8,%%ymm3,%%ymm3 \n" +#else + "vpbroadcastd %[m3],%%ymm1 \n" + "vpand %%ymm1,%%ymm3,%%ymm3 \n" +#endif + "vpor %%ymm3,%%ymm2,%%ymm2 \n" + "vpor %%ymm2,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm7,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src_ar30), [dst] "+r"(dst_abgr), [width] "+r"(width) + : [m0] "m"(kC0000000), [m1] "m"(k300000FF), [m2] "m"(k0C00FF00), + [m3] "m"(k03FF0000), [shuf] "m"(kShufSwapRB16) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7" +#if defined(__x86_64__) + , + "xmm8" +#endif + ); +} +#endif // HAS_AR30TOABGRROW_AVX2 + +#ifdef HAS_AR30TOABGRROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP AR30ToABGRRow_AVX512BW(const uint8_t* src_ar30, + uint8_t* dst_abgr, + int width) { + static const uint32_t kC0000000 = 0xc0000000u; + static const uint32_t k300000FF = 0x300000ffu; + static const uint32_t k0C00FF00 = 0x0c00ff00u; + static const uint32_t k03FF0000 = 0x03ff0000u; + uintptr_t temp; + asm volatile( + "vpbroadcastd %[m0],%%zmm16 \n" + "vpbroadcastd %[m1],%%zmm17 \n" + "vpbroadcastd %[m2],%%zmm18 \n" + "vpbroadcastd %[m3],%%zmm19 \n" + "vbroadcasti32x4 %[shuf],%%zmm20 \n" + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src]),%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "vpsrld $2,%%zmm0,%%zmm1 \n" + "vpsrld $4,%%zmm0,%%zmm2 \n" + "vpsrld $6,%%zmm0,%%zmm3 \n" + "vpandd %%zmm16,%%zmm0,%%zmm0 \n" + "vpandd %%zmm17,%%zmm1,%%zmm1 \n" + "vpandd %%zmm18,%%zmm2,%%zmm2 \n" + "vpandd %%zmm19,%%zmm3,%%zmm3 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vpord %%zmm3,%%zmm2,%%zmm2 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm20,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vpsrld $2,%%zmm0,%%zmm1 \n" + "vpsrld $4,%%zmm0,%%zmm2 \n" + "vpsrld $6,%%zmm0,%%zmm3 \n" + "vpandd %%zmm16,%%zmm0,%%zmm0 \n" + "vpandd %%zmm17,%%zmm1,%%zmm1 \n" + "vpandd %%zmm18,%%zmm2,%%zmm2 \n" + "vpandd %%zmm19,%%zmm3,%%zmm3 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vpord %%zmm3,%%zmm2,%%zmm2 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "vpshufb %%zmm20,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_ar30), [dst] "+r"(dst_abgr), [width] "+r"(width), + [temp] "=&r"(temp) + : [m0] "m"(kC0000000), [m1] "m"(k300000FF), [m2] "m"(k0C00FF00), + [m3] "m"(k03FF0000), [shuf] "m"(kShufSwapRB16) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm16", "xmm17", + "xmm18", "xmm19", "xmm20", "k1"); +} +#endif // HAS_AR30TOABGRROW_AVX512BW + +#ifdef HAS_AR30TOAB30ROW_AVX2 +void OMITFP AR30ToAB30Row_AVX2(const uint8_t* src_ar30, + uint8_t* dst_ab30, + int width) { + static const uint32_t kC00FFC00 = 0xc00ffc00u; + static const uint32_t k3FF00000 = 0x3ff00000u; + static const uint32_t k000003FF = 0x000003ffu; + asm volatile( + "vpbroadcastd %[m0],%%ymm3 \n" + "vpbroadcastd %[m1],%%ymm4 \n" + "vpbroadcastd %[m2],%%ymm5 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[src]),%%ymm0 \n" + "lea 0x20(%[src]),%[src] \n" + "vpslld $20,%%ymm0,%%ymm1 \n" + "vpsrld $20,%%ymm0,%%ymm2 \n" + "vpand %%ymm3,%%ymm0,%%ymm0 \n" + "vpand %%ymm4,%%ymm1,%%ymm1 \n" + "vpand %%ymm5,%%ymm2,%%ymm2 \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" + "vpor %%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src_ar30), [dst] "+r"(dst_ab30), [width] "+r"(width) + : [m0] "m"(kC00FFC00), [m1] "m"(k3FF00000), [m2] "m"(k000003FF) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif // HAS_AR30TOAB30ROW_AVX2 + +#ifdef HAS_AR30TOAB30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP AR30ToAB30Row_AVX512BW(const uint8_t* src_ar30, + uint8_t* dst_ab30, + int width) { + static const uint32_t kC00FFC00 = 0xc00ffc00u; + static const uint32_t k3FF00000 = 0x3ff00000u; + static const uint32_t k000003FF = 0x000003ffu; + uintptr_t temp; + asm volatile( + "vpbroadcastd %[m0],%%zmm16 \n" + "vpbroadcastd %[m1],%%zmm17 \n" + "vpbroadcastd %[m2],%%zmm18 \n" + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src]),%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "vpslld $20,%%zmm0,%%zmm1 \n" + "vpsrld $20,%%zmm0,%%zmm2 \n" + "vpandd %%zmm16,%%zmm0,%%zmm0 \n" + "vpandd %%zmm17,%%zmm1,%%zmm1 \n" + "vpandd %%zmm18,%%zmm2,%%zmm2 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vpslld $20,%%zmm0,%%zmm1 \n" + "vpsrld $20,%%zmm0,%%zmm2 \n" + "vpandd %%zmm16,%%zmm0,%%zmm0 \n" + "vpandd %%zmm17,%%zmm1,%%zmm1 \n" + "vpandd %%zmm18,%%zmm2,%%zmm2 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_ar30), [dst] "+r"(dst_ab30), [width] "+r"(width), + [temp] "=&r"(temp) + : [m0] "m"(kC00FFC00), [m1] "m"(k3FF00000), [m2] "m"(k000003FF) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm16", "xmm17", "xmm18", + "k1"); +} +#endif // HAS_AR30TOAB30ROW_AVX512BW + +#ifdef HAS_MERGEXR30ROW_10_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP MergeXR30Row_10_AVX512BW(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int depth, + int width) { + static const uint32_t kMax10 = 1023u; + static const uint32_t kAlpha30 = 0xc0000000u; + uintptr_t temp; + (void)depth; + asm volatile( + "vpbroadcastd %[max10],%%zmm16 \n" + "vpbroadcastd %[alpha],%%zmm17 \n" + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vpmovzxwd (%[r]),%%zmm0 \n" + "vpmovzxwd (%[g]),%%zmm1 \n" + "vpmovzxwd (%[b]),%%zmm2 \n" + "lea 0x20(%[r]),%[r] \n" + "lea 0x20(%[g]),%[g] \n" + "lea 0x20(%[b]),%[b] \n" + "vpminud %%zmm16,%%zmm0,%%zmm0 \n" + "vpminud %%zmm16,%%zmm1,%%zmm1 \n" + "vpminud %%zmm16,%%zmm2,%%zmm2 \n" + "vpslld $20,%%zmm0,%%zmm0 \n" + "vpslld $10,%%zmm1,%%zmm1 \n" + "vpord %%zmm17,%%zmm2,%%zmm2 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vpmovzxwd (%[r]),%%zmm0%{%%k1%}%{z%} \n" + "vpmovzxwd (%[g]),%%zmm1%{%%k1%}%{z%} \n" + "vpmovzxwd (%[b]),%%zmm2%{%%k1%}%{z%} \n" + "vpminud %%zmm16,%%zmm0,%%zmm0 \n" + "vpminud %%zmm16,%%zmm1,%%zmm1 \n" + "vpminud %%zmm16,%%zmm2,%%zmm2 \n" + "vpslld $20,%%zmm0,%%zmm0 \n" + "vpslld $10,%%zmm1,%%zmm1 \n" + "vpord %%zmm17,%%zmm2,%%zmm2 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [r] "+r"(src_r), [g] "+r"(src_g), [b] "+r"(src_b), [dst] "+r"(dst_ar30), + [width] "+r"(width), [temp] "=&r"(temp) + : [max10] "m"(kMax10), [alpha] "m"(kAlpha30) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm16", "xmm17", "k1"); +} +#endif // HAS_MERGEXR30ROW_10_AVX512BW + +#if defined(HAS_ARGBTOAR30ROW_AVX512BW) || defined(HAS_ABGRTOAR30ROW_AVX512BW) +LIBYUV_TARGET_AVX512BW +static inline void ARGBOrABGRToAR30Row_AVX512BW(const uint8_t* src, + uint8_t* dst, + const uvec8* shuf_rb, + int width) { + uintptr_t temp; + asm volatile( + "vbroadcasti32x4 (%[shuf]),%%zmm2 \n" + "vpbroadcastd %[mul_rb],%%zmm3 \n" + "vpbroadcastd %[mask_rb],%%zmm4 \n" + "vpbroadcastd %[mask_ag],%%zmm5 \n" + "vpbroadcastd %[mul_ag],%%zmm6 \n" + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src]),%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "vpshufb %%zmm2,%%zmm0,%%zmm1 \n" + "vpandd %%zmm5,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm3,%%zmm1,%%zmm1 \n" + "vpmulhuw %%zmm6,%%zmm0,%%zmm0 \n" + "vpandd %%zmm4,%%zmm1,%%zmm1 \n" + "vpslld $10,%%zmm0,%%zmm0 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vpshufb %%zmm2,%%zmm0,%%zmm1 \n" + "vpandd %%zmm5,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm3,%%zmm1,%%zmm1 \n" + "vpmulhuw %%zmm6,%%zmm0,%%zmm0 \n" + "vpandd %%zmm4,%%zmm1,%%zmm1 \n" + "vpslld $10,%%zmm0,%%zmm0 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : + [src] "+r"(src), [dst] "+r"(dst), [width] "+r"(width), [temp] "=&r"(temp) + : [shuf] "r"(shuf_rb), [mul_rb] "m"(kMulRB10), [mask_rb] "m"(kMaskRB10), + [mask_ag] "m"(kMaskAG10), [mul_ag] "m"(kMulAG10) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "k1"); +} +#endif + +#ifdef HAS_ARGBTOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP ARGBToAR30Row_AVX512BW(const uint8_t* src, + uint8_t* dst, + int width) { + ARGBOrABGRToAR30Row_AVX512BW(src, dst, &kShuffleRB30, width); +} +#endif // HAS_ARGBTOAR30ROW_AVX512BW + +#ifdef HAS_ABGRTOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP ABGRToAR30Row_AVX512BW(const uint8_t* src, + uint8_t* dst, + int width) { + ARGBOrABGRToAR30Row_AVX512BW(src, dst, &kShuffleBR30, width); +} +#endif // HAS_ABGRTOAR30ROW_AVX512BW + +// =========================================================================== +// Module 3: Planar / Channel Pack & Mirror / Interpolate_16 (AVX512VBMI / BW) +// =========================================================================== + +#ifdef HAS_MERGERGBROW_AVX512VBMI +static const uint8_t kPermMergeRGB64_0[64] = { + 0x00, 0x20, 0x40, 0x01, 0x21, 0x41, 0x02, 0x22, 0x42, 0x03, 0x23, + 0x43, 0x04, 0x24, 0x44, 0x05, 0x25, 0x45, 0x06, 0x26, 0x46, 0x07, + 0x27, 0x47, 0x08, 0x28, 0x48, 0x09, 0x29, 0x49, 0x0a, 0x2a, 0x4a, + 0x0b, 0x2b, 0x4b, 0x0c, 0x2c, 0x4c, 0x0d, 0x2d, 0x4d, 0x0e, 0x2e, + 0x4e, 0x0f, 0x2f, 0x4f, 0x10, 0x30, 0x50, 0x11, 0x31, 0x51, 0x12, + 0x32, 0x52, 0x13, 0x33, 0x53, 0x14, 0x34, 0x54, 0x15}; + +static const uint8_t kPermMergeRGB64_1[64] = { + 0x35, 0x55, 0x16, 0x36, 0x56, 0x17, 0x37, 0x57, 0x18, 0x38, 0x58, + 0x19, 0x39, 0x59, 0x1a, 0x3a, 0x5a, 0x1b, 0x3b, 0x5b, 0x1c, 0x3c, + 0x5c, 0x1d, 0x3d, 0x5d, 0x1e, 0x3e, 0x5e, 0x1f, 0x3f, 0x5f, 0x60, + 0x00, 0x20, 0x61, 0x01, 0x21, 0x62, 0x02, 0x22, 0x63, 0x03, 0x23, + 0x64, 0x04, 0x24, 0x65, 0x05, 0x25, 0x66, 0x06, 0x26, 0x67, 0x07, + 0x27, 0x68, 0x08, 0x28, 0x69, 0x09, 0x29, 0x6a, 0x0a}; + +static const uint8_t kPermMergeRGB64_2[64] = { + 0x6a, 0x2b, 0x4b, 0x6b, 0x2c, 0x4c, 0x6c, 0x2d, 0x4d, 0x6d, 0x2e, + 0x4e, 0x6e, 0x2f, 0x4f, 0x6f, 0x30, 0x50, 0x70, 0x31, 0x51, 0x71, + 0x32, 0x52, 0x72, 0x33, 0x53, 0x73, 0x34, 0x54, 0x74, 0x35, 0x55, + 0x75, 0x36, 0x56, 0x76, 0x37, 0x57, 0x77, 0x38, 0x58, 0x78, 0x39, + 0x59, 0x79, 0x3a, 0x5a, 0x7a, 0x3b, 0x5b, 0x7b, 0x3c, 0x5c, 0x7c, + 0x3d, 0x5d, 0x7d, 0x3e, 0x5e, 0x7e, 0x3f, 0x5f, 0x7f}; + +LIBYUV_TARGET_AVX512VBMI +void OMITFP MergeRGBRow_AVX512VBMI(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_rgb, + int width) { + uintptr_t temp1; + uintptr_t temp2; + asm volatile( + "vmovdqu8 %[m_rgb0],%%zmm16 \n" + "vmovdqu8 %[m_rgb1],%%zmm17 \n" + "vmovdqu8 %[m_rgb2],%%zmm18 \n" + "movabs $0xb6db6db600000000,%[temp1] \n" + "kmovq %[temp1],%%k2 \n" + "sub $0x40,%[width] \n" + "jl 2f \n" + + // 64-pixel loop (192 bytes out = 3 full 64B zmm stores, zero cache + // splits). + LABELALIGN + "1: \n" + "vmovdqu8 (%[r]),%%ymm0 \n" + "vinserti64x4 $1,(%[g]),%%zmm0,%%zmm0 \n" + "vmovdqu8 (%[b]),%%ymm2 \n" + "vinserti64x4 $1,0x20(%[r]),%%zmm2,%%zmm2 \n" + "vmovdqu8 0x20(%[g]),%%ymm4 \n" + "vinserti64x4 $1,0x20(%[b]),%%zmm4,%%zmm4 \n" + "lea 0x40(%[r]),%[r] \n" + "lea 0x40(%[g]),%[g] \n" + "lea 0x40(%[b]),%[b] \n" + "vmovdqa64 %%zmm0,%%zmm3 \n" + "vpermt2b %%zmm2,%%zmm16,%%zmm3 \n" + "vpermt2b %%zmm2,%%zmm17,%%zmm0 \n" + "vpermb %%zmm4,%%zmm17,%%zmm0%{%%k2%} \n" + "vpermt2b %%zmm4,%%zmm18,%%zmm2 \n" + "vmovdqu8 %%zmm3,(%[dst]) \n" + "vmovdqu8 %%zmm0,0x40(%[dst]) \n" + "vmovdqu8 %%zmm2,0x80(%[dst]) \n" + "lea 0xc0(%[dst]),%[dst] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jl 3f \n" + "vmovdqu8 (%[r]),%%ymm0 \n" + "vinserti64x4 $1,(%[g]),%%zmm0,%%zmm0 \n" + "vmovdqu8 (%[b]),%%ymm2 \n" + "lea 0x20(%[r]),%[r] \n" + "lea 0x20(%[g]),%[g] \n" + "lea 0x20(%[b]),%[b] \n" + "vmovdqa64 %%zmm0,%%zmm3 \n" + "vpermt2b %%zmm2,%%zmm16,%%zmm3 \n" + "vpermt2b %%zmm2,%%zmm17,%%zmm0 \n" + "vmovdqu8 %%zmm3,(%[dst]) \n" + "vmovdqu8 %%ymm0,0x40(%[dst]) \n" + "lea 0x60(%[dst]),%[dst] \n" + "sub $0x20,%[width] \n" + + "3: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp1] \n" + "bzhi %q[width],%[temp1],%[temp2] \n" + "kmovd %k[temp2],%%k1 \n" + "vmovdqu8 (%[r]),%%ymm0%{%%k1%}%{z%} \n" + "vmovdqu8 (%[g]),%%ymm1%{%%k1%}%{z%} \n" + "vmovdqu8 (%[b]),%%ymm2%{%%k1%}%{z%} \n" + "vinserti64x4 $1,%%ymm1,%%zmm0,%%zmm0 \n" + "lea (%q[width],%q[width],2),%k[width]\n" + "bzhi %q[width],%[temp1],%[temp2] \n" + "kmovq %[temp2],%%k3 \n" + "xor %k[temp2],%k[temp2] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp1],%[temp2] \n" + "bzhi %q[width],%[temp2],%[temp2] \n" + "kmovd %k[temp2],%%k4 \n" + "vmovdqa64 %%zmm0,%%zmm3 \n" + "vpermt2b %%zmm2,%%zmm16,%%zmm3 \n" + "vpermt2b %%zmm2,%%zmm17,%%zmm0 \n" + "vmovdqu8 %%zmm3,(%[dst])%{%%k3%} \n" + "vmovdqu8 %%ymm0,0x40(%[dst])%{%%k4%} \n" + + "99: \n" + "vzeroupper \n" + : [r] "+r"(src_r), [g] "+r"(src_g), [b] "+r"(src_b), [dst] "+r"(dst_rgb), + [width] "+r"(width), [temp1] "=&r"(temp1), [temp2] "=&r"(temp2) + : [m_rgb0] "m"(kPermMergeRGB64_0), [m_rgb1] "m"(kPermMergeRGB64_1), + [m_rgb2] "m"(kPermMergeRGB64_2) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm16", + "xmm17", "xmm18", "k1", "k2", "k3", "k4"); +} +#endif // HAS_MERGERGBROW_AVX512VBMI + +#ifdef HAS_RAWTORGBAROW_AVX512VBMI +static const uint8_t kPermRAWToRGBA0[64] = { + 0, 2, 1, 0, 0, 5, 4, 3, 0, 8, 7, 6, 0, 11, 10, 9, + 0, 14, 13, 12, 0, 17, 16, 15, 0, 20, 19, 18, 0, 23, 22, 21, + 0, 26, 25, 24, 0, 29, 28, 27, 0, 32, 31, 30, 0, 35, 34, 33, + 0, 38, 37, 36, 0, 41, 40, 39, 0, 44, 43, 42, 0, 47, 46, 45}; + +static const uint8_t kPermRAWToRGBA1[64] = { + 0, 50, 49, 48, 0, 53, 52, 51, 0, 56, 55, 54, 0, 59, 58, 57, + 0, 62, 61, 60, 0, 65, 64, 63, 0, 68, 67, 66, 0, 71, 70, 69, + 0, 74, 73, 72, 0, 77, 76, 75, 0, 80, 79, 78, 0, 83, 82, 81, + 0, 86, 85, 84, 0, 89, 88, 87, 0, 92, 91, 90, 0, 95, 94, 93}; + +LIBYUV_TARGET_AVX512VBMI +void OMITFP RAWToRGBARow_AVX512VBMI(const uint8_t* src_raw, + uint8_t* dst_rgba, + int width) { + static const uint32_t kAlphaLow = 0x000000ffu; + uintptr_t temp1; + uintptr_t temp2; + asm volatile( + "vmovdqu8 %[p0],%%zmm16 \n" + "vmovdqu8 %[p1],%%zmm17 \n" + "vpbroadcastd %[alpha],%%zmm18 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[src]),%%zmm0 \n" + "vmovdqu8 0x40(%[src]),%%ymm1 \n" + "lea 0x60(%[src]),%[src] \n" + "vpermb %%zmm0,%%zmm16,%%zmm2 \n" + "vpermt2b %%zmm1,%%zmm17,%%zmm0 \n" + "vpord %%zmm18,%%zmm2,%%zmm2 \n" + "vpord %%zmm18,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm2,(%[dst]) \n" + "vmovdqu32 %%zmm0,0x40(%[dst]) \n" + "lea 0x80(%[dst]),%[dst] \n" + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp1] \n" + "bzhi %q[width],%[temp1],%[temp2] \n" + "kmovw %k[temp2],%%k1 \n" + "kmovd %k[temp2],%%k2 \n" + "kshiftrd $16,%%k2,%%k2 \n" + "lea (%q[width],%q[width],2),%k[width]\n" + "bzhi %q[width],%[temp1],%[temp2] \n" + "kmovq %[temp2],%%k3 \n" + "xor %k[temp2],%k[temp2] \n" + "sub $0x40,%k[width] \n" + "cmovg %[temp1],%[temp2] \n" + "bzhi %q[width],%[temp2],%[temp2] \n" + "kmovd %k[temp2],%%k4 \n" + "vmovdqu8 (%[src]),%%zmm0%{%%k3%}%{z%} \n" + "vmovdqu8 0x40(%[src]),%%ymm1%{%%k4%}%{z%}\n" + "vpermb %%zmm0,%%zmm16,%%zmm2 \n" + "vpermt2b %%zmm1,%%zmm17,%%zmm0 \n" + "vpord %%zmm18,%%zmm2,%%zmm2 \n" + "vpord %%zmm18,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm2,(%[dst])%{%%k1%} \n" + "vmovdqu32 %%zmm0,0x40(%[dst])%{%%k2%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_raw), [dst] "+r"(dst_rgba), [width] "+r"(width), + [temp1] "=&r"(temp1), [temp2] "=&r"(temp2) + : [p0] "m"(kPermRAWToRGBA0), [p1] "m"(kPermRAWToRGBA1), + [alpha] "m"(kAlphaLow) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm16", "xmm17", "xmm18", "k1", + "k2", "k3", "k4"); +} +#endif // HAS_RAWTORGBAROW_AVX512VBMI + +#ifdef HAS_SWAPUVROW_AVX512BW +static const uint8_t kSwapUV16[16] = {1, 0, 3, 2, 5, 4, 7, 6, + 9, 8, 11, 10, 13, 12, 15, 14}; + +LIBYUV_TARGET_AVX512BW +void OMITFP SwapUVRow_AVX512BW(const uint8_t* src_uv, + uint8_t* dst_vu, + int width) { + uintptr_t temp; + asm volatile( + "vbroadcasti32x4 %[swap],%%zmm16 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu16 (%[src]),%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "vpshufb %%zmm16,%%zmm0,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovd %k[temp],%%k1 \n" + "vmovdqu16 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vpshufb %%zmm16,%%zmm0,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_uv), [dst] "+r"(dst_vu), [width] "+r"(width), + [temp] "=&r"(temp) + : [swap] "m"(kSwapUV16) + : "memory", "cc", "xmm0", "xmm16", "k1"); +} +#endif // HAS_SWAPUVROW_AVX512BW + +#ifdef HAS_MIRRORROW_16_AVX512BW +static const uint16_t kMirror16Idx[32] = { + 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, + 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + +LIBYUV_TARGET_AVX512BW +void OMITFP MirrorRow_16_AVX512BW(const uint16_t* src, + uint16_t* dst, + int width) { + intptr_t width64 = width; + uintptr_t temp1; + uintptr_t temp2; + asm volatile( + "vmovdqu16 %[rev],%%zmm16 \n" + "lea (%[src],%q[width],2),%[src] \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "sub $0x40,%[src] \n" + "vmovdqu16 (%[src]),%%zmm0 \n" + "vpermw %%zmm0,%%zmm16,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%[dst]) \n" + "add $0x40,%[dst] \n" + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $32,%k[temp2] \n" + "sub %k[width],%k[temp2] \n" + "vpbroadcastw %k[temp2],%%zmm17 \n" + "vpsubw %%zmm17,%%zmm16,%%zmm17 \n" + "mov $-1,%[temp1] \n" + "bzhi %q[width],%[temp1],%[temp1] \n" + "kmovd %k[temp1],%%k1 \n" + "neg %q[width] \n" + "vmovdqu16 (%[src],%q[width],2),%%zmm0%{%%k1%}%{z%}\n" + "vpermw %%zmm0,%%zmm17,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src), [dst] "+r"(dst), [width] "+r"(width64), + [temp1] "=&r"(temp1), [temp2] "=&r"(temp2) + : [rev] "m"(kMirror16Idx) + : "memory", "cc", "xmm0", "xmm16", "xmm17", "k1"); +} +#endif // HAS_MIRRORROW_16_AVX512BW + +#ifdef HAS_HALFMERGEUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP HalfMergeUVRow_AVX512BW(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width) { + uintptr_t temp1; + uintptr_t temp2; + asm volatile( + "vpternlogd $0xff,%%zmm16,%%zmm16,%%zmm16 \n" + "vpsrlw $15,%%zmm16,%%zmm16 \n" + "vpsllw $8,%%zmm16,%%zmm17 \n" + "vpord %%zmm17,%%zmm16,%%zmm16 \n" // 0x0101 + "vpxord %%zmm17,%%zmm17,%%zmm17 \n" // 0 + "vpternlogd $0xff,%%zmm18,%%zmm18,%%zmm18 \n" + "vpsrlw $8,%%zmm18,%%zmm18 \n" // 0x00ff + "sub $0x40,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%[u]),%%zmm0 \n" + "vmovdqu8 (%[u],%[su]),%%zmm1 \n" + "vmovdqu8 (%[v]),%%zmm2 \n" + "vmovdqu8 (%[v],%[sv]),%%zmm3 \n" + "lea 0x40(%[u]),%[u] \n" + "lea 0x40(%[v]),%[v] \n" + "vpmaddubsw %%zmm16,%%zmm0,%%zmm0 \n" + "vpmaddubsw %%zmm16,%%zmm1,%%zmm1 \n" + "vpmaddubsw %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddubsw %%zmm16,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm1,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm3,%%zmm2,%%zmm2 \n" + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm2,%%zmm2 \n" + "vpavgw %%zmm17,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm17,%%zmm2,%%zmm2 \n" + "vpsllw $8,%%zmm2,%%zmm2 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "vmovdqu8 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x40,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x40,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp1] \n" + "bzhi %q[width],%[temp1],%[temp2] \n" + "kmovq %[temp2],%%k1 \n" + "vmovdqu8 (%[u]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu8 (%[u],%[su]),%%zmm1%{%%k1%}%{z%}\n" + "vmovdqu8 (%[v]),%%zmm2%{%%k1%}%{z%} \n" + "vmovdqu8 (%[v],%[sv]),%%zmm3%{%%k1%}%{z%}\n" + // If width is odd, duplicate byte (width - 1) into high byte of word + // (width >> 1). + "mov %k[width],%k[temp1] \n" + "and $1,%k[temp1] \n" + "mov %k[width],%k[temp2] \n" + "shr $1,%k[temp2] \n" + "shlx %k[temp2],%k[temp1],%k[temp1] \n" + "kmovd %k[temp1],%%k2 \n" + "vpandd %%zmm18,%%zmm0,%%zmm4 \n" + "vpmullw %%zmm16,%%zmm4,%%zmm0%{%%k2%} \n" + "vpandd %%zmm18,%%zmm1,%%zmm4 \n" + "vpmullw %%zmm16,%%zmm4,%%zmm1%{%%k2%} \n" + "vpandd %%zmm18,%%zmm2,%%zmm4 \n" + "vpmullw %%zmm16,%%zmm4,%%zmm2%{%%k2%} \n" + "vpandd %%zmm18,%%zmm3,%%zmm4 \n" + "vpmullw %%zmm16,%%zmm4,%%zmm3%{%%k2%} \n" + "vpmaddubsw %%zmm16,%%zmm0,%%zmm0 \n" + "vpmaddubsw %%zmm16,%%zmm1,%%zmm1 \n" + "vpmaddubsw %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddubsw %%zmm16,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm1,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm3,%%zmm2,%%zmm2 \n" + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm2,%%zmm2 \n" + "vpavgw %%zmm17,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm17,%%zmm2,%%zmm2 \n" + "vpsllw $8,%%zmm2,%%zmm2 \n" + "vpord %%zmm2,%%zmm0,%%zmm0 \n" + "lea 1(%q[width]),%k[temp2] \n" + "shr $1,%k[temp2] \n" + "mov $-1,%[temp1] \n" + "bzhi %q[temp2],%[temp1],%[temp1] \n" + "kmovd %k[temp1],%%k2 \n" + "vmovdqu16 %%zmm0,(%[dst])%{%%k2%} \n" + + "99: \n" + "vzeroupper \n" + : [u] "+r"(src_u), [v] "+r"(src_v), [dst] "+r"(dst_uv), + [width] "+r"(width), [temp1] "=&r"(temp1), [temp2] "=&r"(temp2) + : [su] "r"((ptrdiff_t)src_stride_u), [sv] "r"((ptrdiff_t)src_stride_v) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm16", + "xmm17", "xmm18", "k1", "k2"); +} +#endif // HAS_HALFMERGEUVROW_AVX512BW + +#ifdef HAS_INTERPOLATEROW_16_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP InterpolateRow_16_AVX512BW(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + int y1_fraction = source_y_fraction; + int y0_fraction = 256 - y1_fraction; + const uint16_t* src_ptr1 = src_ptr + src_stride; + int y_fractions = (y1_fraction << 16) + y0_fraction; + uintptr_t temp1; + uintptr_t temp2; + asm volatile( + "cmpl $0x0,%[y1] \n" + "je 10f \n" + "cmpl $0x80,%[y1] \n" + "je 20f \n" + + "vpbroadcastd %[y_frac],%%zmm16 \n" + "vpternlogd $0xff,%%zmm17,%%zmm17,%%zmm17 \n" + "vpsllw $15,%%zmm17,%%zmm17 \n" // 0x8000 + "mov $0x800080,%k[temp1] \n" + "vpbroadcastd %k[temp1],%%zmm18 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + // 32-pixel general blend loop (vpmaddwd + vpackusdw). + LABELALIGN + "1: \n" + "vmovdqu16 (%[src]),%%zmm0 \n" + "vmovdqu16 (%[src1]),%%zmm1 \n" + "lea 0x40(%[src]),%[src] \n" + "lea 0x40(%[src1]),%[src1] \n" + "vpunpcklwd %%zmm1,%%zmm0,%%zmm2 \n" + "vpunpckhwd %%zmm1,%%zmm0,%%zmm0 \n" + "vpsubw %%zmm17,%%zmm2,%%zmm2 \n" + "vpsubw %%zmm17,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm18,%%zmm2,%%zmm2 \n" + "vpaddd %%zmm18,%%zmm0,%%zmm0 \n" + "vpsrad $8,%%zmm2,%%zmm2 \n" + "vpsrad $8,%%zmm0,%%zmm0 \n" + "vpackusdw %%zmm0,%%zmm2,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp1] \n" + "bzhi %q[width],%[temp1],%[temp2] \n" + "kmovd %k[temp2],%%k1 \n" + "vmovdqu16 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 (%[src1]),%%zmm1%{%%k1%}%{z%} \n" + "vpunpcklwd %%zmm1,%%zmm0,%%zmm2 \n" + "vpunpckhwd %%zmm1,%%zmm0,%%zmm0 \n" + "vpsubw %%zmm17,%%zmm2,%%zmm2 \n" + "vpsubw %%zmm17,%%zmm0,%%zmm0 \n" + "vpmaddwd %%zmm16,%%zmm2,%%zmm2 \n" + "vpmaddwd %%zmm16,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm18,%%zmm2,%%zmm2 \n" + "vpaddd %%zmm18,%%zmm0,%%zmm0 \n" + "vpsrad $8,%%zmm2,%%zmm2 \n" + "vpsrad $8,%%zmm0,%%zmm0 \n" + "vpackusdw %%zmm0,%%zmm2,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%[dst])%{%%k1%} \n" + "jmp 99f \n" + + // y1 == 0 fast copy path (32 uint16_t per zmm). + "10: \n" + "sub $0x20,%[width] \n" + "jl 12f \n" LABELALIGN + "11: \n" + "vmovdqu16 (%[src]),%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "vmovdqu16 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x20,%[width] \n" + "jge 11b \n" + "12: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp1] \n" + "bzhi %q[width],%[temp1],%[temp2] \n" + "kmovd %k[temp2],%%k1 \n" + "vmovdqu16 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 %%zmm0,(%[dst])%{%%k1%} \n" + "jmp 99f \n" + + // y1 == 128 fast 50/50 average path (vpavgw on 32 uint16_t per zmm). + "20: \n" + "sub $0x20,%[width] \n" + "jl 22f \n" LABELALIGN + "21: \n" + "vmovdqu16 (%[src]),%%zmm0 \n" + "vpavgw (%[src1]),%%zmm0,%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "lea 0x40(%[src1]),%[src1] \n" + "vmovdqu16 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x20,%[width] \n" + "jge 21b \n" + "22: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp1] \n" + "bzhi %q[width],%[temp1],%[temp2] \n" + "kmovd %k[temp2],%%k1 \n" + "vmovdqu16 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 (%[src1]),%%zmm1%{%%k1%}%{z%} \n" + "vpavgw %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [dst] "+r"(dst_ptr), [src] "+r"(src_ptr), [src1] "+r"(src_ptr1), + [width] "+r"(width), [temp1] "=&r"(temp1), [temp2] "=&r"(temp2) + : [y1] "r"(y1_fraction), [y_frac] "r"(y_fractions) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm16", "xmm17", "xmm18", + "k1"); +} +#endif // HAS_INTERPOLATEROW_16_AVX512BW + +// =========================================================================== +// Module 4: NV12 / NV21 & I422Alpha to ARGB / RGB24 (AVX512BW / AVX512VBMI) +// =========================================================================== + +#define READYUVNV12_AVX512BW \ + "vmovdqu16 (%[uv_buf]),%%ymm3 \n" \ + "lea 0x20(%[uv_buf]),%[uv_buf] \n" \ + "vpermw %%zmm3,%%zmm16,%%zmm1 \n" \ + "vpmovzxbw (%[y_buf]),%%zmm4 \n" \ + "lea 0x20(%[y_buf]),%[y_buf] \n" \ + "vpsllw $8,%%zmm4,%%zmm3 \n" \ + "vpord %%zmm3,%%zmm4,%%zmm4 \n" \ + "vmovdqa64 %%zmm1,%%zmm3 \n" + +#define READYUVNV12_MASK_AVX512BW \ + "mov $-1,%[temp] \n" \ + "bzhi %q[width],%[temp],%[temp] \n" \ + "kmovd %k[temp],%%k1 \n" \ + "vpmovzxbw (%[y_buf]),%%zmm4%{%%k1%}%{z%} \n" \ + "mov $-1,%[temp] \n" \ + "lea 1(%q[width]),%k[y_buf] \n" \ + "shr $1,%k[y_buf] \n" \ + "bzhi %q[y_buf],%[temp],%[y_buf] \n" \ + "kmovw %k[y_buf],%%k2 \n" \ + "vmovdqu16 (%[uv_buf]),%%ymm3%{%%k2%}%{z%} \n" \ + "vpermw %%zmm3,%%zmm16,%%zmm1 \n" \ + "vpsllw $8,%%zmm4,%%zmm3 \n" \ + "vpord %%zmm3,%%zmm4,%%zmm4 \n" \ + "vmovdqa64 %%zmm1,%%zmm3 \n" + +#define READYUVNV21_AVX512BW \ + "vmovdqu16 (%[uv_buf]),%%ymm3 \n" \ + "lea 0x20(%[uv_buf]),%[uv_buf] \n" \ + "vpsllw $8,%%ymm3,%%ymm1 \n" \ + "vpsrlw $8,%%ymm3,%%ymm3 \n" \ + "vpor %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpermw %%zmm3,%%zmm16,%%zmm1 \n" \ + "vpmovzxbw (%[y_buf]),%%zmm4 \n" \ + "lea 0x20(%[y_buf]),%[y_buf] \n" \ + "vpsllw $8,%%zmm4,%%zmm3 \n" \ + "vpord %%zmm3,%%zmm4,%%zmm4 \n" \ + "vmovdqa64 %%zmm1,%%zmm3 \n" + +#define READYUVNV21_MASK_AVX512BW \ + "mov $-1,%[temp] \n" \ + "bzhi %q[width],%[temp],%[temp] \n" \ + "kmovd %k[temp],%%k1 \n" \ + "vpmovzxbw (%[y_buf]),%%zmm4%{%%k1%}%{z%} \n" \ + "mov $-1,%[temp] \n" \ + "lea 1(%q[width]),%k[y_buf] \n" \ + "shr $1,%k[y_buf] \n" \ + "bzhi %q[y_buf],%[temp],%[y_buf] \n" \ + "kmovw %k[y_buf],%%k2 \n" \ + "vmovdqu16 (%[uv_buf]),%%ymm3%{%%k2%}%{z%} \n" \ + "vpsllw $8,%%ymm3,%%ymm1 \n" \ + "vpsrlw $8,%%ymm3,%%ymm3 \n" \ + "vpor %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpermw %%zmm3,%%zmm16,%%zmm1 \n" \ + "vpsllw $8,%%zmm4,%%zmm3 \n" \ + "vpord %%zmm3,%%zmm4,%%zmm4 \n" \ + "vmovdqa64 %%zmm1,%%zmm3 \n" + +#ifdef HAS_NV12TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP NV12ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUVNV12_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUVNV12_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [uv_buf] "+r"(uv_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_NV12TOARGBROW_AVX512BW + +#ifdef HAS_NV21TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP NV21ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* vu_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUVNV21_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUVNV21_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [uv_buf] "+r"(vu_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_NV21TOARGBROW_AVX512BW + +#ifdef HAS_NV12TORGB24ROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void OMITFP NV12ToRGB24Row_AVX512VBMI(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vmovdqu32 %[kMaskBG],%%zmm20 \n" + "vmovdqu32 %[kMaskDST0],%%zmm21 \n" + "vmovdqu32 %[kMaskDST1],%%zmm22 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUVNV12_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGB24_AVX512VBMI + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUVNV12_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGB24_MASK_AVX512VBMI + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [uv_buf] "+r"(uv_buf), + [dst_rgb24] "+r"(dst_rgb24), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512), + [kMaskBG] "m"(kMaskBG), + [kMaskDST0] "m"(kMaskDST0), + [kMaskDST1] "m"(kMaskDST1) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm20", "xmm21", "xmm22", "k1", "k2", "k3", "k4"); +} +#endif // HAS_NV12TORGB24ROW_AVX512VBMI + +#ifdef HAS_NV21TORGB24ROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void OMITFP NV21ToRGB24Row_AVX512VBMI(const uint8_t* y_buf, + const uint8_t* vu_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vmovdqu32 %[kMaskBG],%%zmm20 \n" + "vmovdqu32 %[kMaskDST0],%%zmm21 \n" + "vmovdqu32 %[kMaskDST1],%%zmm22 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUVNV21_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGB24_AVX512VBMI + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUVNV21_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGB24_MASK_AVX512VBMI + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [uv_buf] "+r"(vu_buf), + [dst_rgb24] "+r"(dst_rgb24), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512), + [kMaskBG] "m"(kMaskBG), + [kMaskDST0] "m"(kMaskDST0), + [kMaskDST1] "m"(kMaskDST1) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm20", "xmm21", "xmm22", "k1", "k2", "k3", "k4"); +} +#endif // HAS_NV21TORGB24ROW_AVX512VBMI + +#ifdef HAS_I422ALPHATOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I422AlphaToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV422_AVX512BW + "vpmovzxbw (%[a_buf]),%%zmm5 \n" + "lea 0x20(%[a_buf]),%[a_buf] \n" + "vpackuswb %%zmm5,%%zmm5,%%zmm5 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV422_MASK_AVX512BW + "vpmovzxbw (%[a_buf]),%%zmm5%{%%k1%}%{z%}\n" + "vpackuswb %%zmm5,%%zmm5,%%zmm5 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [a_buf] "+r"(a_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_I422ALPHATOARGBROW_AVX512BW + +// =========================================================================== +// Module 5: I400ToARGB & ARGB Shaders (Attenuate, Multiply, Gray, Blend) +// =========================================================================== + +#ifdef HAS_I400TOARGBROW_AVX512BW +static const uint64_t kLinearizePackQ[8] = {0, 2, 4, 6, 1, 3, 5, 7}; +static const uint8_t kBcastGrayByte[16] = {0, 0, 0, 0x80, 4, 4, 4, 0x80, + 8, 8, 8, 0x80, 12, 12, 12, 0x80}; + +LIBYUV_TARGET_AVX512BW +void OMITFP I400ToARGBRow_AVX512BW(const uint8_t* y_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + "vpbroadcastw 96(%[yuv]),%%zmm16 \n" // kYToRgb + "vpbroadcastw 128(%[yuv]),%%zmm17 \n" // kYBiasToRgb + "vmovdqu64 %[lin],%%zmm18 \n" + "vbroadcasti32x4 %[bcast],%%zmm19 \n" + "vpternlogd $0xff,%%zmm20,%%zmm20,%%zmm20 \n" + "vpslld $24,%%zmm20,%%zmm20 \n" // 0xff000000 + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vpmovzxbw (%[y]),%%zmm0 \n" + "lea 0x20(%[y]),%[y] \n" + "vpsllw $8,%%zmm0,%%zmm1 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm16,%%zmm0,%%zmm0 \n" + "vpaddsw %%zmm17,%%zmm0,%%zmm0 \n" + "vpsraw $6,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm0,%%zmm0,%%zmm0 \n" + "vpermq %%zmm0,%%zmm18,%%zmm0 \n" + "vpmovzxbd %%xmm0,%%zmm1 \n" + "vextracti128 $1,%%ymm0,%%xmm0 \n" + "vpmovzxbd %%xmm0,%%zmm0 \n" + "vpshufb %%zmm19,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm19,%%zmm0,%%zmm0 \n" + "vpord %%zmm20,%%zmm1,%%zmm1 \n" + "vpord %%zmm20,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm1,(%[dst]) \n" + "vmovdqu32 %%zmm0,0x40(%[dst]) \n" + "lea 0x80(%[dst]),%[dst] \n" + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovd %k[temp],%%k1 \n" + "kshiftrd $16,%%k1,%%k2 \n" + "vpmovzxbw (%[y]),%%zmm0%{%%k1%}%{z%} \n" + "vpsllw $8,%%zmm0,%%zmm1 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vpmulhuw %%zmm16,%%zmm0,%%zmm0 \n" + "vpaddsw %%zmm17,%%zmm0,%%zmm0 \n" + "vpsraw $6,%%zmm0,%%zmm0 \n" + "vpackuswb %%zmm0,%%zmm0,%%zmm0 \n" + "vpermq %%zmm0,%%zmm18,%%zmm0 \n" + "vpmovzxbd %%xmm0,%%zmm1 \n" + "vextracti128 $1,%%ymm0,%%xmm0 \n" + "vpmovzxbd %%xmm0,%%zmm0 \n" + "vpshufb %%zmm19,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm19,%%zmm0,%%zmm0 \n" + "vpord %%zmm20,%%zmm1,%%zmm1 \n" + "vpord %%zmm20,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm1,(%[dst])%{%%k1%} \n" + "vmovdqu32 %%zmm0,0x40(%[dst])%{%%k2%} \n" + + "99: \n" + "vzeroupper \n" + : [y] "+r"(y_buf), [dst] "+r"(dst_argb), [width] "+r"(width), + [temp] "=&r"(temp) + : [yuv] "r"(yuvconstants), [lin] "m"(kLinearizePackQ), + [bcast] "m"(kBcastGrayByte) + : "memory", "cc", "xmm0", "xmm1", "xmm16", "xmm17", "xmm18", "xmm19", + "xmm20", "k1", "k2"); +} +#endif // HAS_I400TOARGBROW_AVX512BW + +#ifdef HAS_ARGBATTENUATEROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP ARGBAttenuateRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + uintptr_t temp; + asm volatile( + "vbroadcasti32x4 %[shuf],%%zmm16 \n" + "vpternlogd $0xff,%%zmm17,%%zmm17,%%zmm17 \n" + "vpslld $24,%%zmm17,%%zmm17 \n" // 0xff000000 + "vpternlogd $0xff,%%zmm18,%%zmm18,%%zmm18 \n" + "vpsrlw $8,%%zmm18,%%zmm18 \n" // 0x00ff + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src]),%%zmm6 \n" + "lea 0x40(%[src]),%[src] \n" + "vpunpcklbw %%zmm17,%%zmm6,%%zmm0 \n" + "vpunpckhbw %%zmm17,%%zmm6,%%zmm1 \n" + "vpshufb %%zmm16,%%zmm0,%%zmm2 \n" + "vpshufb %%zmm16,%%zmm1,%%zmm3 \n" + "vpmullw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmullw %%zmm3,%%zmm1,%%zmm1 \n" + "vpaddw %%zmm18,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm18,%%zmm1,%%zmm1 \n" + "vpsrlw $8,%%zmm0,%%zmm0 \n" + "vpsrlw $8,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vpandd %%zmm17,%%zmm6,%%zmm1 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src]),%%zmm6%{%%k1%}%{z%} \n" + "vpunpcklbw %%zmm17,%%zmm6,%%zmm0 \n" + "vpunpckhbw %%zmm17,%%zmm6,%%zmm1 \n" + "vpshufb %%zmm16,%%zmm0,%%zmm2 \n" + "vpshufb %%zmm16,%%zmm1,%%zmm3 \n" + "vpmullw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmullw %%zmm3,%%zmm1,%%zmm1 \n" + "vpaddw %%zmm18,%%zmm0,%%zmm0 \n" + "vpaddw %%zmm18,%%zmm1,%%zmm1 \n" + "vpsrlw $8,%%zmm0,%%zmm0 \n" + "vpsrlw $8,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vpandd %%zmm17,%%zmm6,%%zmm1 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [width] "+r"(width), + [temp] "=&r"(temp) + : [shuf] "m"(kAttenuateShuffle_AVX2) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm6", "xmm16", + "xmm17", "xmm18", "k1"); +} +#endif // HAS_ARGBATTENUATEROW_AVX512BW + +#ifdef HAS_ARGBMULTIPLYROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP ARGBMultiplyRow_AVX512BW(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + uintptr_t temp; + asm volatile( + "vpxord %%zmm16,%%zmm16,%%zmm16 \n" + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src0]),%%zmm1 \n" + "vmovdqu32 (%[src1]),%%zmm3 \n" + "lea 0x40(%[src0]),%[src0] \n" + "lea 0x40(%[src1]),%[src1] \n" + "vpunpcklbw %%zmm1,%%zmm16,%%zmm0 \n" + "vpunpckhbw %%zmm1,%%zmm16,%%zmm1 \n" + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm1,%%zmm1 \n" + "vpunpcklbw %%zmm16,%%zmm3,%%zmm2 \n" + "vpunpckhbw %%zmm16,%%zmm3,%%zmm3 \n" + "vpmulhrsw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmulhrsw %%zmm3,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src0]),%%zmm1%{%%k1%}%{z%} \n" + "vmovdqu32 (%[src1]),%%zmm3%{%%k1%}%{z%} \n" + "vpunpcklbw %%zmm1,%%zmm16,%%zmm0 \n" + "vpunpckhbw %%zmm1,%%zmm16,%%zmm1 \n" + "vpsrlw $1,%%zmm0,%%zmm0 \n" + "vpsrlw $1,%%zmm1,%%zmm1 \n" + "vpunpcklbw %%zmm16,%%zmm3,%%zmm2 \n" + "vpunpckhbw %%zmm16,%%zmm3,%%zmm3 \n" + "vpmulhrsw %%zmm2,%%zmm0,%%zmm0 \n" + "vpmulhrsw %%zmm3,%%zmm1,%%zmm1 \n" + "vpackuswb %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src0] "+r"(src_argb), [src1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [width] "+r"(width), [temp] "=&r"(temp) + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm16", "k1"); +} +#endif // HAS_ARGBMULTIPLYROW_AVX512BW + +#ifdef HAS_ARGBGRAYROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP ARGBGrayRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + static const uint32_t kCoeff = 0x004d961du; // {29, 150, 77, 0} + static const uint32_t kOne16 = 0x00010001u; + static const uint32_t kBias = 32896u; + uintptr_t temp; + asm volatile( + "vpbroadcastd %[coeff],%%zmm16 \n" + "vpternlogd $0xff,%%zmm17,%%zmm17,%%zmm17 \n" + "vpsllw $7,%%zmm17,%%zmm17 \n" + "vpbroadcastb %%xmm17,%%zmm17 \n" // 0x80808080 + "vpbroadcastd %[one16],%%zmm18 \n" + "vpbroadcastd %[bias],%%zmm19 \n" + "vbroadcasti32x4 %[shuf],%%zmm20 \n" + "vpternlogd $0xff,%%zmm21,%%zmm21,%%zmm21 \n" + "vpslld $24,%%zmm21,%%zmm21 \n" // 0xff000000 + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src]),%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "vpsubb %%zmm17,%%zmm0,%%zmm1 \n" + "vpmaddubsw %%zmm1,%%zmm16,%%zmm1 \n" + "vpmaddwd %%zmm18,%%zmm1,%%zmm1 \n" + "vpaddd %%zmm19,%%zmm1,%%zmm1 \n" + "vpsrld $8,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm20,%%zmm1,%%zmm1 \n" + "vpandd %%zmm21,%%zmm0,%%zmm0 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vpsubb %%zmm17,%%zmm0,%%zmm1 \n" + "vpmaddubsw %%zmm1,%%zmm16,%%zmm1 \n" + "vpmaddwd %%zmm18,%%zmm1,%%zmm1 \n" + "vpaddd %%zmm19,%%zmm1,%%zmm1 \n" + "vpsrld $8,%%zmm1,%%zmm1 \n" + "vpshufb %%zmm20,%%zmm1,%%zmm1 \n" + "vpandd %%zmm21,%%zmm0,%%zmm0 \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [width] "+r"(width), + [temp] "=&r"(temp) + : [coeff] "m"(kCoeff), [one16] "m"(kOne16), [bias] "m"(kBias), + [shuf] "m"(kShufGrayDword) + : "memory", "cc", "xmm0", "xmm1", "xmm16", "xmm17", "xmm18", "xmm19", + "xmm20", "xmm21", "k1"); +} +#endif // HAS_ARGBGRAYROW_AVX512BW + +#ifdef HAS_ARGBGRAYROW_AVX512VNNI +LIBYUV_TARGET_AVX512VNNI +void OMITFP ARGBGrayRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + static const uint32_t kCoeff = 0x004d961du; // {29, 150, 77, 0} + static const uint32_t kBias = 32896u; + uintptr_t temp; + asm volatile( + "vpbroadcastd %[coeff],%%zmm16 \n" + "vpternlogd $0xff,%%zmm17,%%zmm17,%%zmm17 \n" + "vpslld $24,%%zmm17,%%zmm21 \n" // 0xff000000 + "vpsllw $7,%%zmm17,%%zmm17 \n" + "vpbroadcastb %%xmm17,%%zmm17 \n" // 0x80808080 + "vpbroadcastd %[bias],%%zmm19 \n" + "vbroadcasti32x4 %[shuf],%%zmm20 \n" + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src]),%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "vpxorq %%zmm17,%%zmm0,%%zmm1 \n" + "vmovdqa64 %%zmm19,%%zmm2 \n" + "vpdpbusd %%zmm1,%%zmm16,%%zmm2 \n" + "vpsrld $8,%%zmm2,%%zmm2 \n" + "vpshufb %%zmm20,%%zmm2,%%zmm2 \n" + "vpternlogd $0xf8,%%zmm21,%%zmm0,%%zmm2 \n" + "vmovdqu32 %%zmm2,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vpxorq %%zmm17,%%zmm0,%%zmm1 \n" + "vmovdqa64 %%zmm19,%%zmm2 \n" + "vpdpbusd %%zmm1,%%zmm16,%%zmm2 \n" + "vpsrld $8,%%zmm2,%%zmm2 \n" + "vpshufb %%zmm20,%%zmm2,%%zmm2 \n" + "vpternlogd $0xf8,%%zmm21,%%zmm0,%%zmm2 \n" + "vmovdqu32 %%zmm2,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [width] "+r"(width), + [temp] "=&r"(temp) + : [coeff] "m"(kCoeff), [bias] "m"(kBias), [shuf] "m"(kShufGrayDword) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm16", "xmm17", "xmm19", + "xmm20", "xmm21", "k1"); +} +#endif // HAS_ARGBGRAYROW_AVX512VNNI + +#ifdef HAS_ARGBBLENDROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP ARGBBlendRow_AVX512BW(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + uintptr_t temp; + asm volatile( + "vbroadcasti32x4 %[shuf],%%zmm16 \n" + "vpternlogd $0xff,%%zmm17,%%zmm17,%%zmm17 \n" + "vpslld $24,%%zmm17,%%zmm17 \n" // 0xff000000 + "vpternlogd $0xff,%%zmm18,%%zmm18,%%zmm18 \n" + "vpsllw $8,%%zmm18,%%zmm18 \n" // 0xff00 + "vpternlogd $0xff,%%zmm19,%%zmm19,%%zmm19 \n" + "vpsrlw $8,%%zmm19,%%zmm19 \n" // 0x00ff + "vpternlogd $0xff,%%zmm20,%%zmm20,%%zmm20 \n" + "vpsrlw $15,%%zmm20,%%zmm20 \n" // 0x0001 + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src0]),%%zmm3 \n" + "vmovdqu32 (%[src1]),%%zmm2 \n" + "lea 0x40(%[src0]),%[src0] \n" + "lea 0x40(%[src1]),%[src1] \n" + "vmovdqa64 %%zmm3,%%zmm0 \n" + "vpxord %%zmm17,%%zmm3,%%zmm3 \n" + "vpshufb %%zmm16,%%zmm3,%%zmm3 \n" + "vmovdqa64 %%zmm2,%%zmm1 \n" + "vpandd %%zmm19,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm20,%%zmm3,%%zmm3 \n" + "vpmullw %%zmm3,%%zmm2,%%zmm2 \n" + "vpsrlw $8,%%zmm1,%%zmm1 \n" + "vpord %%zmm17,%%zmm0,%%zmm0 \n" + "vpmullw %%zmm3,%%zmm1,%%zmm1 \n" + "vpsrlw $8,%%zmm2,%%zmm2 \n" + "vpaddusb %%zmm2,%%zmm0,%%zmm0 \n" + "vpandd %%zmm18,%%zmm1,%%zmm1 \n" + "vpaddusb %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src0]),%%zmm3%{%%k1%}%{z%} \n" + "vmovdqu32 (%[src1]),%%zmm2%{%%k1%}%{z%} \n" + "vmovdqa64 %%zmm3,%%zmm0 \n" + "vpxord %%zmm17,%%zmm3,%%zmm3 \n" + "vpshufb %%zmm16,%%zmm3,%%zmm3 \n" + "vmovdqa64 %%zmm2,%%zmm1 \n" + "vpandd %%zmm19,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm20,%%zmm3,%%zmm3 \n" + "vpmullw %%zmm3,%%zmm2,%%zmm2 \n" + "vpsrlw $8,%%zmm1,%%zmm1 \n" + "vpord %%zmm17,%%zmm0,%%zmm0 \n" + "vpmullw %%zmm3,%%zmm1,%%zmm1 \n" + "vpsrlw $8,%%zmm2,%%zmm2 \n" + "vpaddusb %%zmm2,%%zmm0,%%zmm0 \n" + "vpandd %%zmm18,%%zmm1,%%zmm1 \n" + "vpaddusb %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src0] "+r"(src_argb), [src1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [width] "+r"(width), [temp] "=&r"(temp) + : [shuf] "m"(kShuffleAlpha) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm16", "xmm17", + "xmm18", "xmm19", "xmm20", "k1"); +} +#endif // HAS_ARGBBLENDROW_AVX512BW + +#ifdef HAS_ARGBORROW_SSE2 +void ARGBOrRow_SSE2(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + asm volatile( + "movd %[value],%%xmm1 \n" + "pshufd $0x00,%%xmm1,%%xmm1 \n" + + LABELALIGN + "1: \n" + "movdqu (%[src]),%%xmm0 \n" + "lea 0x10(%[src]),%[src] \n" + "por %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%[dst]) \n" + "lea 0x10(%[dst]),%[dst] \n" + "sub $0x4,%[width] \n" + "jg 1b \n" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [width] "+r"(width) + : [value] "r"(value) + : "memory", "cc", "xmm0", "xmm1"); +} +#endif // HAS_ARGBORROW_SSE2 + +#ifdef HAS_ARGBORROW_AVX2 +void ARGBOrRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + asm volatile( + "vmovd %[value],%%xmm1 \n" + "vpbroadcastd %%xmm1,%%ymm1 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[src]),%%ymm0 \n" + "lea 0x20(%[src]),%[src] \n" + "vpor %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [width] "+r"(width) + : [value] "r"(value) + : "memory", "cc", "xmm0", "xmm1"); +} +#endif // HAS_ARGBORROW_AVX2 + +#ifdef HAS_ARGBORROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP ARGBOrRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + uintptr_t temp; + asm volatile( + "vpbroadcastd %[value],%%zmm1 \n" + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src]),%%zmm0 \n" + "lea 0x40(%[src]),%[src] \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src]),%%zmm0%{%%k1%}%{z%} \n" + "vpord %%zmm1,%%zmm0,%%zmm0 \n" + "vmovdqu32 %%zmm0,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [width] "+r"(width), + [temp] "=&r"(temp) + : [value] "r"(value) + : "memory", "cc", "xmm0", "xmm1", "k1"); +} +#endif // HAS_ARGBORROW_AVX512BW + +#ifdef HAS_ARGBALPHABLENDROW_SSSE3 +void ARGBAlphaBlendRow_SSSE3(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + asm volatile( + "pcmpeqb %%xmm5,%%xmm5 \n" + "pabsb %%xmm5,%%xmm4 \n" // 0x01010101... + "psllw $7,%%xmm4 \n" + "movdqa %%xmm4,%%xmm6 \n" // xmm6 = 0x8080... + "psrlw $7,%%xmm4 \n" // xmm4 = 0x0101... + "psubw %%xmm4,%%xmm6 \n" // 0x7f7f... + "psubw %%xmm5,%%xmm6 \n" // 0x7f80... + "psubw %%xmm5,%%xmm6 \n" // xmm6 = 0x7f81... + + LABELALIGN + "1: \n" + "movdqu (%[src0]),%%xmm0 \n" + "movdqu (%[src1]),%%xmm1 \n" + "lea 0x10(%[src0]),%[src0] \n" + "lea 0x10(%[src1]),%[src1] \n" + + "movdqa %%xmm0,%%xmm2 \n" + "movdqa %%xmm1,%%xmm3 \n" + "psrld $24,%%xmm2 \n" // sa + "psrld $24,%%xmm3 \n" // da + + "pcmpeqb %%xmm5,%%xmm5 \n" // -1 + "movdqa %%xmm2,%%xmm7 \n" + "pmullw %%xmm3,%%xmm7 \n" // da * sa + "psubw %%xmm5,%%xmm7 \n" // da * sa + 1 + "pmulhuw %%xmm4,%%xmm7 \n" // (da * sa) / 255 + + "paddd %%xmm3,%%xmm5 \n" // da - 1 + "psrld $24,%%xmm5 \n" // t = (da==0) ? 255 : 0 + + "paddw %%xmm2,%%xmm3 \n" // da + sa + "psubw %%xmm7,%%xmm3 \n" // da2 + + "por %%xmm5,%%xmm2 \n" // sa_eff + "movdqa %%xmm3,%%xmm7 \n" + "por %%xmm5,%%xmm7 \n" // den_eff + + "movdqa %%xmm2,%%xmm5 \n" + "pslld $8,%%xmm2 \n" + "psubd %%xmm5,%%xmm2 \n" // sa_eff * 255 + + "cvtdq2ps %%xmm2,%%xmm2 \n" + "cvtdq2ps %%xmm7,%%xmm7 \n" + "divps %%xmm7,%%xmm2 \n" + "cvttps2dq %%xmm2,%%xmm2 \n" // ratio + + "pcmpeqb %%xmm5,%%xmm5 \n" + "psllw $8,%%xmm5 \n" // 0xff00 + + "pmullw %%xmm4,%%xmm2 \n" + "pshufhw $0xa0,%%xmm2,%%xmm2 \n" + "pshuflw $0xa0,%%xmm2,%%xmm2 \n" + "pxor %%xmm5,%%xmm2 \n" + "movdqa %%xmm2,%%xmm7 \n" + "punpcklwd %%xmm2,%%xmm2 \n" + "punpckhwd %%xmm7,%%xmm7 \n" + + "movdqa %%xmm4,%%xmm5 \n" + "psllw $7,%%xmm5 \n" // 0x8080 + "psubb %%xmm5,%%xmm0 \n" + "psubb %%xmm5,%%xmm1 \n" + "movdqa %%xmm0,%%xmm5 \n" + "punpcklbw %%xmm1,%%xmm0 \n" + "punpckhbw %%xmm1,%%xmm5 \n" + + "pmaddubsw %%xmm0,%%xmm2 \n" + "pmaddubsw %%xmm5,%%xmm7 \n" + "paddw %%xmm6,%%xmm2 \n" + "paddw %%xmm6,%%xmm7 \n" + "pmulhuw %%xmm4,%%xmm2 \n" + "pmulhuw %%xmm4,%%xmm7 \n" + "packuswb %%xmm7,%%xmm2 \n" + + "pslld $8,%%xmm2 \n" + "psrld $8,%%xmm2 \n" + "pslld $24,%%xmm3 \n" + "por %%xmm3,%%xmm2 \n" + + "movdqu %%xmm2,(%[dst]) \n" + "lea 0x10(%[dst]),%[dst] \n" + "sub $0x4,%[width] \n" + "jg 1b \n" + : [src0] "+r"(src_argb), [src1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [width] "+rm"(width) + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_ARGBALPHABLENDROW_SSSE3 + +#ifdef HAS_ARGBALPHABLENDROW_AVX2 +void ARGBAlphaBlendRow_AVX2(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + asm volatile( + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpabsb %%ymm5,%%ymm4 \n" // 0x0101... + "vpsllw $7,%%ymm4,%%ymm6 \n" // 0x8080... + "vpsubw %%ymm4,%%ymm6,%%ymm6 \n" // 0x7f7f... + "vpsubw %%ymm5,%%ymm6,%%ymm6 \n" // 0x7f80... + "vpsubw %%ymm5,%%ymm6,%%ymm6 \n" // 0x7f81... + + LABELALIGN + "1: \n" + "vmovdqu (%[src0]),%%ymm0 \n" + "vmovdqu (%[src1]),%%ymm1 \n" + "lea 0x20(%[src0]),%[src0] \n" + "lea 0x20(%[src1]),%[src1] \n" + + "vpsrld $24,%%ymm0,%%ymm2 \n" // sa + "vpsrld $24,%%ymm1,%%ymm3 \n" // da + + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" // -1 + "vpmullw %%ymm3,%%ymm2,%%ymm7 \n" // da * sa + "vpsubw %%ymm5,%%ymm7,%%ymm7 \n" // da * sa + 1 + "vpmulhuw %%ymm4,%%ymm7,%%ymm7 \n" // (da * sa) / 255 + + "vpaddd %%ymm3,%%ymm5,%%ymm5 \n" // da - 1 + "vpsrld $24,%%ymm5,%%ymm5 \n" // t = (da==0) ? 255 : 0 + + "vpaddw %%ymm2,%%ymm3,%%ymm3 \n" // da + sa + "vpsubw %%ymm7,%%ymm3,%%ymm3 \n" // da2 + + "vpor %%ymm5,%%ymm2,%%ymm2 \n" // sa_eff + "vpor %%ymm5,%%ymm3,%%ymm7 \n" // den_eff + + "vpslld $8,%%ymm2,%%ymm5 \n" + "vpsubd %%ymm2,%%ymm5,%%ymm2 \n" // sa_eff * 255 + + "vcvtdq2ps %%ymm2,%%ymm2 \n" + "vcvtdq2ps %%ymm7,%%ymm7 \n" + "vdivps %%ymm7,%%ymm2,%%ymm2 \n" + "vcvttps2dq %%ymm2,%%ymm2 \n" // ratio + + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsllw $8,%%ymm5,%%ymm5 \n" // 0xff00 + + "vpmullw %%ymm4,%%ymm2,%%ymm2 \n" + "vpshufhw $0xa0,%%ymm2,%%ymm2 \n" + "vpshuflw $0xa0,%%ymm2,%%ymm2 \n" + "vpxor %%ymm5,%%ymm2,%%ymm2 \n" + "vpunpckhwd %%ymm2,%%ymm2,%%ymm7 \n" + "vpunpcklwd %%ymm2,%%ymm2,%%ymm2 \n" + + "vpsllw $7,%%ymm4,%%ymm5 \n" // 0x8080 + "vpsubb %%ymm5,%%ymm0,%%ymm0 \n" + "vpsubb %%ymm5,%%ymm1,%%ymm1 \n" + "vpunpckhbw %%ymm1,%%ymm0,%%ymm5 \n" + "vpunpcklbw %%ymm1,%%ymm0,%%ymm0 \n" + + "vpmaddubsw %%ymm0,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm5,%%ymm7,%%ymm7 \n" + "vpaddw %%ymm6,%%ymm2,%%ymm2 \n" + "vpaddw %%ymm6,%%ymm7,%%ymm7 \n" + "vpmulhuw %%ymm4,%%ymm2,%%ymm2 \n" + "vpmulhuw %%ymm4,%%ymm7,%%ymm7 \n" + "vpackuswb %%ymm7,%%ymm2,%%ymm2 \n" + + "vpslld $8,%%ymm2,%%ymm2 \n" + "vpsrld $8,%%ymm2,%%ymm2 \n" + "vpslld $24,%%ymm3,%%ymm3 \n" + "vpor %%ymm3,%%ymm2,%%ymm2 \n" + + "vmovdqu %%ymm2,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src0] "+r"(src_argb), [src1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [width] "+rm"(width) + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_ARGBALPHABLENDROW_AVX2 + +#ifdef HAS_ARGBALPHABLENDROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP ARGBAlphaBlendRow_AVX512BW(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + uintptr_t temp; + asm volatile( + "vpternlogd $0xff,%%zmm20,%%zmm20,%%zmm20 \n" // -1 + "vpabsb %%zmm20,%%zmm16 \n" // zmm16 = 0x0101... + "vpsllw $7,%%zmm16,%%zmm21 \n" // zmm21 = 0x8080... + "vpsubw %%zmm16,%%zmm21,%%zmm18 \n" // 0x7f7f... + "vpsubw %%zmm20,%%zmm18,%%zmm18 \n" // 0x7f80... + "vpsubw %%zmm20,%%zmm18,%%zmm18 \n" // zmm18 = 0x7f81... + "vpsllw $8,%%zmm20,%%zmm17 \n" // zmm17 = 0xff00... + + "sub $0x10,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src0]),%%zmm0 \n" + "vmovdqu32 (%[src1]),%%zmm1 \n" + "lea 0x40(%[src0]),%[src0] \n" + "lea 0x40(%[src1]),%[src1] \n" + + "vpsrld $24,%%zmm0,%%zmm2 \n" // sa + "vpsrld $24,%%zmm1,%%zmm3 \n" // da + + "vpmullw %%zmm3,%%zmm2,%%zmm7 \n" + "vpsubw %%zmm20,%%zmm7,%%zmm7 \n" // da * sa + 1 + "vpmulhuw %%zmm16,%%zmm7,%%zmm7 \n" + + "vpaddd %%zmm3,%%zmm20,%%zmm5 \n" // da - 1 + "vpsrld $24,%%zmm5,%%zmm5 \n" // t + + "vpaddw %%zmm2,%%zmm3,%%zmm3 \n" + "vpsubw %%zmm7,%%zmm3,%%zmm3 \n" // da2 + + "vpord %%zmm5,%%zmm2,%%zmm2 \n" // sa_eff + "vpord %%zmm5,%%zmm3,%%zmm7 \n" // den_eff + "vpslld $8,%%zmm2,%%zmm6 \n" + "vpsubd %%zmm2,%%zmm6,%%zmm2 \n" // sa_eff * 255 + + "vcvtdq2ps %%zmm2,%%zmm2 \n" + "vcvtdq2ps %%zmm7,%%zmm7 \n" + "vdivps %%zmm7,%%zmm2,%%zmm2 \n" + "vcvttps2dq %%zmm2,%%zmm2 \n" + + "vpmullw %%zmm16,%%zmm2,%%zmm2 \n" + "vpshufhw $0xa0,%%zmm2,%%zmm2 \n" + "vpshuflw $0xa0,%%zmm2,%%zmm2 \n" + "vpxord %%zmm17,%%zmm2,%%zmm2 \n" + "vpunpckhwd %%zmm2,%%zmm2,%%zmm7 \n" + "vpunpcklwd %%zmm2,%%zmm2,%%zmm2 \n" + + "vpsubb %%zmm21,%%zmm0,%%zmm0 \n" + "vpsubb %%zmm21,%%zmm1,%%zmm1 \n" + "vpunpckhbw %%zmm1,%%zmm0,%%zmm5 \n" + "vpunpcklbw %%zmm1,%%zmm0,%%zmm0 \n" + + "vpmaddubsw %%zmm0,%%zmm2,%%zmm2 \n" + "vpmaddubsw %%zmm5,%%zmm7,%%zmm7 \n" + "vpaddw %%zmm18,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm18,%%zmm7,%%zmm7 \n" + "vpmulhuw %%zmm16,%%zmm2,%%zmm2 \n" + "vpmulhuw %%zmm16,%%zmm7,%%zmm7 \n" + "vpackuswb %%zmm7,%%zmm2,%%zmm2 \n" + + "vpslld $8,%%zmm2,%%zmm2 \n" + "vpsrld $8,%%zmm2,%%zmm2 \n" + "vpslld $24,%%zmm3,%%zmm3 \n" + "vpord %%zmm3,%%zmm2,%%zmm2 \n" + + "vmovdqu32 %%zmm2,(%[dst]) \n" + "lea 0x40(%[dst]),%[dst] \n" + "sub $0x10,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[width] \n" + "jle 99f \n" + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k1 \n" + "vmovdqu32 (%[src0]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 (%[src1]),%%zmm1%{%%k1%}%{z%} \n" + + "vpsrld $24,%%zmm0,%%zmm2 \n" + "vpsrld $24,%%zmm1,%%zmm3 \n" + + "vpmullw %%zmm3,%%zmm2,%%zmm7 \n" + "vpsubw %%zmm20,%%zmm7,%%zmm7 \n" + "vpmulhuw %%zmm16,%%zmm7,%%zmm7 \n" + + "vpaddd %%zmm3,%%zmm20,%%zmm5 \n" + "vpsrld $24,%%zmm5,%%zmm5 \n" + + "vpaddw %%zmm2,%%zmm3,%%zmm3 \n" + "vpsubw %%zmm7,%%zmm3,%%zmm3 \n" + + "vpord %%zmm5,%%zmm2,%%zmm2 \n" + "vpord %%zmm5,%%zmm3,%%zmm7 \n" + "vpslld $8,%%zmm2,%%zmm6 \n" + "vpsubd %%zmm2,%%zmm6,%%zmm2 \n" + + "vcvtdq2ps %%zmm2,%%zmm2 \n" + "vcvtdq2ps %%zmm7,%%zmm7 \n" + "vdivps %%zmm7,%%zmm2,%%zmm2 \n" + "vcvttps2dq %%zmm2,%%zmm2 \n" + + "vpmullw %%zmm16,%%zmm2,%%zmm2 \n" + "vpshufhw $0xa0,%%zmm2,%%zmm2 \n" + "vpshuflw $0xa0,%%zmm2,%%zmm2 \n" + "vpxord %%zmm17,%%zmm2,%%zmm2 \n" + "vpunpckhwd %%zmm2,%%zmm2,%%zmm7 \n" + "vpunpcklwd %%zmm2,%%zmm2,%%zmm2 \n" + + "vpsubb %%zmm21,%%zmm0,%%zmm0 \n" + "vpsubb %%zmm21,%%zmm1,%%zmm1 \n" + "vpunpckhbw %%zmm1,%%zmm0,%%zmm5 \n" + "vpunpcklbw %%zmm1,%%zmm0,%%zmm0 \n" + + "vpmaddubsw %%zmm0,%%zmm2,%%zmm2 \n" + "vpmaddubsw %%zmm5,%%zmm7,%%zmm7 \n" + "vpaddw %%zmm18,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm18,%%zmm7,%%zmm7 \n" + "vpmulhuw %%zmm16,%%zmm2,%%zmm2 \n" + "vpmulhuw %%zmm16,%%zmm7,%%zmm7 \n" + "vpackuswb %%zmm7,%%zmm2,%%zmm2 \n" + + "vpslld $8,%%zmm2,%%zmm2 \n" + "vpsrld $8,%%zmm2,%%zmm2 \n" + "vpslld $24,%%zmm3,%%zmm3 \n" + "vpord %%zmm3,%%zmm2,%%zmm2 \n" + + "vmovdqu32 %%zmm2,(%[dst])%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : [src0] "+r"(src_argb), [src1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [width] "+r"(width), [temp] "=&r"(temp) + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5", "xmm6", "xmm7", + "xmm16", "xmm17", "xmm18", "xmm20", "xmm21", "k1"); +} +#endif // HAS_ARGBALPHABLENDROW_AVX512BW + +// =========================================================================== +// Module 6: Extended YUV (I444, YUY2, UYVY, I210, I212, I410, P210, P410) +// to ARGB / RGBA / RGB24 / AR30 (AVX512BW / AVX512VBMI) +// =========================================================================== + +#define READYUV444_AVX512BW \ + "vpmovzxbw (%[u_buf]),%%zmm3 \n" \ + "vpmovzxbw 0x00(%[u_buf],%[v_buf],1),%%zmm1 \n" \ + "lea 0x20(%[u_buf]),%[u_buf] \n" \ + "vpsllw $8,%%zmm1,%%zmm1 \n" \ + "vpord %%zmm1,%%zmm3,%%zmm3 \n" \ + "vpmovzxbw (%[y_buf]),%%zmm4 \n" \ + "lea 0x20(%[y_buf]),%[y_buf] \n" \ + "vpsllw $8,%%zmm4,%%zmm1 \n" \ + "vpord %%zmm1,%%zmm4,%%zmm4 \n" + +#define READYUV444_MASK_AVX512BW \ + "mov $-1,%[temp] \n" \ + "bzhi %q[width],%[temp],%[temp] \n" \ + "kmovd %k[temp],%%k1 \n" \ + "mov $-1,%[temp] \n" \ + "vpmovzxbw (%[u_buf]),%%zmm3%{%%k1%}%{z%} \n" \ + "vpmovzxbw 0x00(%[u_buf],%[v_buf],1),%%zmm1%{%%k1%}%{z%} \n" \ + "vpsllw $8,%%zmm1,%%zmm1 \n" \ + "vpord %%zmm1,%%zmm3,%%zmm3 \n" \ + "vpmovzxbw (%[y_buf]),%%zmm4%{%%k1%}%{z%} \n" \ + "vpsllw $8,%%zmm4,%%zmm1 \n" \ + "vpord %%zmm1,%%zmm4,%%zmm4 \n" + +#define STORERGBA_AVX512BW \ + "vpunpcklbw %%zmm0,%%zmm5,%%zmm3 \n" \ + "vpermq %%zmm3,%%zmm18,%%zmm3 \n" \ + "vpunpcklbw %%zmm2,%%zmm1,%%zmm1 \n" \ + "vpermq %%zmm1,%%zmm18,%%zmm1 \n" \ + "vpunpcklwd %%zmm1,%%zmm3,%%zmm0 \n" \ + "vpunpckhwd %%zmm1,%%zmm3,%%zmm1 \n" \ + "vmovups %%zmm0,(%[dst_rgba]) \n" \ + "vmovups %%zmm1,0x40(%[dst_rgba]) \n" \ + "lea 0x80(%[dst_rgba]),%[dst_rgba] \n" + +#define STORERGBA_MASK_AVX512BW \ + "vpunpcklbw %%zmm0,%%zmm5,%%zmm3 \n" \ + "vpermq %%zmm3,%%zmm18,%%zmm3 \n" \ + "vpunpcklbw %%zmm2,%%zmm1,%%zmm1 \n" \ + "vpermq %%zmm1,%%zmm18,%%zmm1 \n" \ + "vpunpcklwd %%zmm1,%%zmm3,%%zmm0 \n" \ + "vpunpckhwd %%zmm1,%%zmm3,%%zmm1 \n" \ + "kshiftrd $16,%%k1,%%k2 \n" \ + "vmovdqu32 %%zmm0,(%[dst_rgba])%{%%k1%} \n" \ + "vmovdqu32 %%zmm1,0x40(%[dst_rgba])%{%%k2%} \n" + +#define READYUV210_AVX512BW \ + "vmovdqu16 (%[u_buf]),%%ymm3 \n" \ + "vmovdqu16 0x00(%[u_buf],%[v_buf],1),%%ymm1 \n" \ + "lea 0x20(%[u_buf]),%[u_buf] \n" \ + "vpsrlw $2,%%ymm3,%%ymm3 \n" \ + "vpsrlw $2,%%ymm1,%%ymm1 \n" \ + "vpackuswb %%ymm3,%%ymm3,%%ymm3 \n" \ + "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" \ + "vpunpcklbw %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpermw %%zmm3,%%zmm16,%%zmm3 \n" \ + "vmovdqu16 (%[y_buf]),%%zmm4 \n" \ + "lea 0x40(%[y_buf]),%[y_buf] \n" \ + "vpsllw $6,%%zmm4,%%zmm1 \n" \ + "vpsrlw $4,%%zmm4,%%zmm4 \n" \ + "vpord %%zmm1,%%zmm4,%%zmm4 \n" + +#define READYUV210_MASK_AVX512BW \ + "mov $-1,%[temp] \n" \ + "bzhi %q[width],%[temp],%[temp] \n" \ + "kmovd %k[temp],%%k1 \n" \ + "vmovdqu16 (%[y_buf]),%%zmm4%{%%k1%}%{z%} \n" \ + "mov $-1,%[temp] \n" \ + "lea 1(%q[width]),%k[y_buf] \n" \ + "shr $1,%k[y_buf] \n" \ + "bzhi %q[y_buf],%[temp],%[y_buf] \n" \ + "kmovw %k[y_buf],%%k2 \n" \ + "vmovdqu16 (%[u_buf]),%%ymm3%{%%k2%}%{z%} \n" \ + "vmovdqu16 0x00(%[u_buf],%[v_buf],1),%%ymm1%{%%k2%}%{z%} \n" \ + "vpsrlw $2,%%ymm3,%%ymm3 \n" \ + "vpsrlw $2,%%ymm1,%%ymm1 \n" \ + "vpackuswb %%ymm3,%%ymm3,%%ymm3 \n" \ + "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" \ + "vpunpcklbw %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpermw %%zmm3,%%zmm16,%%zmm3 \n" \ + "vpsllw $6,%%zmm4,%%zmm1 \n" \ + "vpsrlw $4,%%zmm4,%%zmm4 \n" \ + "vpord %%zmm1,%%zmm4,%%zmm4 \n" + +#define READYUV212_AVX512BW \ + "vmovdqu16 (%[u_buf]),%%ymm3 \n" \ + "vmovdqu16 0x00(%[u_buf],%[v_buf],1),%%ymm1 \n" \ + "lea 0x20(%[u_buf]),%[u_buf] \n" \ + "vpsraw $4,%%ymm3,%%ymm3 \n" \ + "vpsraw $4,%%ymm1,%%ymm1 \n" \ + "vpackuswb %%ymm3,%%ymm3,%%ymm3 \n" \ + "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" \ + "vpunpcklbw %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpermw %%zmm3,%%zmm16,%%zmm3 \n" \ + "vmovdqu16 (%[y_buf]),%%zmm4 \n" \ + "lea 0x40(%[y_buf]),%[y_buf] \n" \ + "vpsllw $4,%%zmm4,%%zmm1 \n" \ + "vpsrlw $8,%%zmm4,%%zmm4 \n" \ + "vpord %%zmm1,%%zmm4,%%zmm4 \n" + +#define READYUV212_MASK_AVX512BW \ + "mov $-1,%[temp] \n" \ + "bzhi %q[width],%[temp],%[temp] \n" \ + "kmovd %k[temp],%%k1 \n" \ + "vmovdqu16 (%[y_buf]),%%zmm4%{%%k1%}%{z%} \n" \ + "mov $-1,%[temp] \n" \ + "lea 1(%q[width]),%k[y_buf] \n" \ + "shr $1,%k[y_buf] \n" \ + "bzhi %q[y_buf],%[temp],%[y_buf] \n" \ + "kmovw %k[y_buf],%%k2 \n" \ + "vmovdqu16 (%[u_buf]),%%ymm3%{%%k2%}%{z%} \n" \ + "vmovdqu16 0x00(%[u_buf],%[v_buf],1),%%ymm1%{%%k2%}%{z%} \n" \ + "vpsraw $4,%%ymm3,%%ymm3 \n" \ + "vpsraw $4,%%ymm1,%%ymm1 \n" \ + "vpackuswb %%ymm3,%%ymm3,%%ymm3 \n" \ + "vpackuswb %%ymm1,%%ymm1,%%ymm1 \n" \ + "vpunpcklbw %%ymm1,%%ymm3,%%ymm3 \n" \ + "vpermw %%zmm3,%%zmm16,%%zmm3 \n" \ + "vpsllw $4,%%zmm4,%%zmm1 \n" \ + "vpsrlw $8,%%zmm4,%%zmm4 \n" \ + "vpord %%zmm1,%%zmm4,%%zmm4 \n" + +#define READYUV410_AVX512BW \ + "vmovdqu16 (%[u_buf]),%%zmm3 \n" \ + "vmovdqu16 0x00(%[u_buf],%[v_buf],1),%%zmm1 \n" \ + "lea 0x40(%[u_buf]),%[u_buf] \n" \ + "vpsrlw $2,%%zmm3,%%zmm3 \n" \ + "vpsrlw $2,%%zmm1,%%zmm1 \n" \ + "vpackuswb %%zmm3,%%zmm3,%%zmm3 \n" \ + "vpackuswb %%zmm1,%%zmm1,%%zmm1 \n" \ + "vpunpcklbw %%zmm1,%%zmm3,%%zmm3 \n" \ + "vmovdqu16 (%[y_buf]),%%zmm4 \n" \ + "lea 0x40(%[y_buf]),%[y_buf] \n" \ + "vpsllw $6,%%zmm4,%%zmm1 \n" \ + "vpsrlw $4,%%zmm4,%%zmm4 \n" \ + "vpord %%zmm1,%%zmm4,%%zmm4 \n" + +#define READYUV410_MASK_AVX512BW \ + "mov $-1,%[temp] \n" \ + "bzhi %q[width],%[temp],%[temp] \n" \ + "kmovd %k[temp],%%k1 \n" \ + "vmovdqu16 (%[u_buf]),%%zmm3%{%%k1%}%{z%} \n" \ + "vmovdqu16 0x00(%[u_buf],%[v_buf],1),%%zmm1%{%%k1%}%{z%} \n" \ + "vpsrlw $2,%%zmm3,%%zmm3 \n" \ + "vpsrlw $2,%%zmm1,%%zmm1 \n" \ + "vpackuswb %%zmm3,%%zmm3,%%zmm3 \n" \ + "vpackuswb %%zmm1,%%zmm1,%%zmm1 \n" \ + "vpunpcklbw %%zmm1,%%zmm3,%%zmm3 \n" \ + "vmovdqu16 (%[y_buf]),%%zmm4%{%%k1%}%{z%} \n" \ + "vpsllw $6,%%zmm4,%%zmm1 \n" \ + "vpsrlw $4,%%zmm4,%%zmm4 \n" \ + "vpord %%zmm1,%%zmm4,%%zmm4 \n" + +#define READP210_AVX512BW \ + "vmovdqu16 (%[y_buf]),%%zmm4 \n" \ + "lea 0x40(%[y_buf]),%[y_buf] \n" \ + "vmovdqu32 (%[uv_buf]),%%zmm3 \n" \ + "lea 0x40(%[uv_buf]),%[uv_buf] \n" \ + "vpshufb %%zmm14,%%zmm3,%%zmm3 \n" + +#define READP210_MASK_AVX512BW \ + "mov $-1,%[temp] \n" \ + "bzhi %q[width],%[temp],%[temp] \n" \ + "kmovd %k[temp],%%k1 \n" \ + "vmovdqu16 (%[y_buf]),%%zmm4%{%%k1%}%{z%} \n" \ + "mov $-1,%[temp] \n" \ + "lea 1(%q[width]),%k[y_buf] \n" \ + "shr $1,%k[y_buf] \n" \ + "bzhi %q[y_buf],%[temp],%[y_buf] \n" \ + "kmovw %k[y_buf],%%k2 \n" \ + "vmovdqu32 (%[uv_buf]),%%zmm3%{%%k2%}%{z%} \n" \ + "vpshufb %%zmm14,%%zmm3,%%zmm3 \n" + +#define READP410_AVX512BW \ + "vmovdqu16 (%[y_buf]),%%zmm4 \n" \ + "lea 0x40(%[y_buf]),%[y_buf] \n" \ + "vmovdqu32 (%[uv_buf]),%%zmm3 \n" \ + "vmovdqu32 0x40(%[uv_buf]),%%zmm1 \n" \ + "lea 0x80(%[uv_buf]),%[uv_buf] \n" \ + "vpsrlw $8,%%zmm3,%%zmm3 \n" \ + "vpsrlw $8,%%zmm1,%%zmm1 \n" \ + "vpmovwb %%zmm3,%%ymm3 \n" \ + "vpmovwb %%zmm1,%%ymm1 \n" \ + "vinserti64x4 $1,%%ymm1,%%zmm3,%%zmm3 \n" + +#define READP410_MASK_AVX512BW \ + "mov $-1,%[temp] \n" \ + "bzhi %q[width],%[temp],%[temp] \n" \ + "kmovd %k[temp],%%k1 \n" \ + "kshiftrd $16,%%k1,%%k2 \n" \ + "vmovdqu16 (%[y_buf]),%%zmm4%{%%k1%}%{z%} \n" \ + "vmovdqu32 (%[uv_buf]),%%zmm3%{%%k1%}%{z%} \n" \ + "vmovdqu32 0x40(%[uv_buf]),%%zmm1%{%%k2%}%{z%} \n" \ + "vpsrlw $8,%%zmm3,%%zmm3 \n" \ + "vpsrlw $8,%%zmm1,%%zmm1 \n" \ + "vpmovwb %%zmm3,%%ymm3 \n" \ + "vpmovwb %%zmm1,%%ymm1 \n" \ + "vinserti64x4 $1,%%ymm1,%%zmm3,%%zmm3 \n" + +#ifdef HAS_I444TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I444ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV444_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV444_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_I444TOARGBROW_AVX512BW + +#ifdef HAS_I444ALPHATOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I444AlphaToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV444_AVX512BW + "vpmovzxbw (%[a_buf]),%%zmm5 \n" + "lea 0x20(%[a_buf]),%[a_buf] \n" + "vpackuswb %%zmm5,%%zmm5,%%zmm5 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV444_MASK_AVX512BW + "vpmovzxbw (%[a_buf]),%%zmm5%{%%k1%}%{z%}\n" + "vpackuswb %%zmm5,%%zmm5,%%zmm5 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [a_buf] "+r"(a_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_I444ALPHATOARGBROW_AVX512BW + +#ifdef HAS_I444TORGB24ROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void OMITFP I444ToRGB24Row_AVX512VBMI(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vmovdqu32 %[kMaskBG],%%zmm20 \n" + "vmovdqu32 %[kMaskDST0],%%zmm21 \n" + "vmovdqu32 %[kMaskDST1],%%zmm22 \n" + "sub %[u_buf],%[v_buf] \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV444_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGB24_AVX512VBMI + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV444_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGB24_MASK_AVX512VBMI + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [dst_rgb24] "+r"(dst_rgb24), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512), + [kMaskBG] "m"(kMaskBG), + [kMaskDST0] "m"(kMaskDST0), + [kMaskDST1] "m"(kMaskDST1) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm20", "xmm21", "xmm22", "k1", "k3", "k4"); +} +#endif // HAS_I444TORGB24ROW_AVX512VBMI + +#ifdef HAS_I422TORGBAROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I422ToRGBARow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV422_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGBA_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV422_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STORERGBA_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [dst_rgba] "+r"(dst_rgba), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_I422TORGBAROW_AVX512BW + +#ifdef HAS_YUY2TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP YUY2ToARGBRow_AVX512BW(const uint8_t* src_yuy2, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vbroadcasti32x4 %[kShufY],%%zmm14 \n" + "vbroadcasti32x4 %[kShufUV],%%zmm15 \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src_yuy2]),%%zmm1 \n" + "lea 0x40(%[src_yuy2]),%[src_yuy2] \n" + "vpshufb %%zmm14,%%zmm1,%%zmm4 \n" + "vpshufb %%zmm15,%%zmm1,%%zmm3 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovd %k[temp],%%k1 \n" + "mov $-1,%[temp] \n" + "add $1,%k[width] \n" + "shr $1,%k[width] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k2 \n" + "vmovdqu32 (%[src_yuy2]),%%zmm1%{%%k2%}%{z%}\n" + "vpshufb %%zmm14,%%zmm1,%%zmm4 \n" + "vpshufb %%zmm15,%%zmm1,%%zmm3 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [src_yuy2] "+r"(src_yuy2), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512), + [kShufY] "m"(kShuffleYUY2Y), + [kShufUV] "m"(kShuffleYUY2UV) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm14", "xmm15", "k1", "k2"); +} +#endif // HAS_YUY2TOARGBROW_AVX512BW + +#ifdef HAS_UYVYTOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP UYVYToARGBRow_AVX512BW(const uint8_t* src_uyvy, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vbroadcasti32x4 %[kShufY],%%zmm14 \n" + "vbroadcasti32x4 %[kShufUV],%%zmm15 \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu32 (%[src_uyvy]),%%zmm1 \n" + "lea 0x40(%[src_uyvy]),%[src_uyvy] \n" + "vpshufb %%zmm14,%%zmm1,%%zmm4 \n" + "vpshufb %%zmm15,%%zmm1,%%zmm3 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + "mov $-1,%[temp] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovd %k[temp],%%k1 \n" + "mov $-1,%[temp] \n" + "add $1,%k[width] \n" + "shr $1,%k[width] \n" + "bzhi %q[width],%[temp],%[temp] \n" + "kmovw %k[temp],%%k2 \n" + "vmovdqu32 (%[src_uyvy]),%%zmm1%{%%k2%}%{z%}\n" + "vpshufb %%zmm14,%%zmm1,%%zmm4 \n" + "vpshufb %%zmm15,%%zmm1,%%zmm3 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [src_uyvy] "+r"(src_uyvy), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512), + [kShufY] "m"(kShuffleUYVYY), + [kShufUV] "m"(kShuffleUYVYUV) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm14", "xmm15", "k1", "k2"); +} +#endif // HAS_UYVYTOARGBROW_AVX512BW + +#ifdef HAS_I210TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I210ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV210_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV210_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_I210TOARGBROW_AVX512BW + +#ifdef HAS_I210TOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I210ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "vpsrlw $6,%%zmm5,%%zmm7 \n" + "vpsllw $4,%%zmm7,%%zmm7 \n" + "vpsllw $10,%%zmm5,%%zmm19 \n" + "vpsllw $14,%%zmm5,%%zmm5 \n" + "vpxord %%zmm6,%%zmm6,%%zmm6 \n" + "vmovdqu16 (%[permar30_0]),%%zmm20 \n" + "vmovdqu16 (%[permar30_1]),%%zmm21 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV210_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV210_MASK_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [dst_ar30] "+r"(dst_ar30), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512), + [permar30_0] "r"(kPermAR30_0), + [permar30_1] "r"(kPermAR30_1) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm6", "xmm7", "xmm19", "xmm20", "xmm21", "k1", "k2"); +} +#endif // HAS_I210TOAR30ROW_AVX512BW + +#ifdef HAS_I210ALPHATOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I210AlphaToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV210_AVX512BW + "vmovdqu16 (%[a_buf]),%%zmm5 \n" + "lea 0x40(%[a_buf]),%[a_buf] \n" + "vpsrlw $2,%%zmm5,%%zmm5 \n" + "vpackuswb %%zmm5,%%zmm5,%%zmm5 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV210_MASK_AVX512BW + "vmovdqu16 (%[a_buf]),%%zmm5%{%%k1%}%{z%}\n" + "vpsrlw $2,%%zmm5,%%zmm5 \n" + "vpackuswb %%zmm5,%%zmm5,%%zmm5 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [a_buf] "+r"(a_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_I210ALPHATOARGBROW_AVX512BW + +#ifdef HAS_I212TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I212ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV212_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV212_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_I212TOARGBROW_AVX512BW + +#ifdef HAS_I212TOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I212ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "vpsrlw $6,%%zmm5,%%zmm7 \n" + "vpsllw $4,%%zmm7,%%zmm7 \n" + "vpsllw $10,%%zmm5,%%zmm19 \n" + "vpsllw $14,%%zmm5,%%zmm5 \n" + "vpxord %%zmm6,%%zmm6,%%zmm6 \n" + "vmovdqu16 (%[permar30_0]),%%zmm20 \n" + "vmovdqu16 (%[permar30_1]),%%zmm21 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV212_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV212_MASK_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [dst_ar30] "+r"(dst_ar30), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512), + [permar30_0] "r"(kPermAR30_0), + [permar30_1] "r"(kPermAR30_1) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm6", "xmm7", "xmm19", "xmm20", "xmm21", "k1", "k2"); +} +#endif // HAS_I212TOAR30ROW_AVX512BW + +#ifdef HAS_I410TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I410ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV410_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV410_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_I410TOARGBROW_AVX512BW + +#ifdef HAS_I410TOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I410ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "vpsrlw $6,%%zmm5,%%zmm7 \n" + "vpsllw $4,%%zmm7,%%zmm7 \n" + "vpsllw $10,%%zmm5,%%zmm19 \n" + "vpsllw $14,%%zmm5,%%zmm5 \n" + "vpxord %%zmm6,%%zmm6,%%zmm6 \n" + "vmovdqu16 (%[permar30_0]),%%zmm20 \n" + "vmovdqu16 (%[permar30_1]),%%zmm21 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV410_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV410_MASK_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [dst_ar30] "+r"(dst_ar30), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512), + [permar30_0] "r"(kPermAR30_0), + [permar30_1] "r"(kPermAR30_1) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm6", "xmm7", "xmm19", "xmm20", "xmm21", "k1", "k2"); +} +#endif // HAS_I410TOAR30ROW_AVX512BW + +#ifdef HAS_I410ALPHATOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP I410AlphaToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "sub %[u_buf],%[v_buf] \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READYUV410_AVX512BW + "vmovdqu16 (%[a_buf]),%%zmm5 \n" + "lea 0x40(%[a_buf]),%[a_buf] \n" + "vpsrlw $2,%%zmm5,%%zmm5 \n" + "vpackuswb %%zmm5,%%zmm5,%%zmm5 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READYUV410_MASK_AVX512BW + "vmovdqu16 (%[a_buf]),%%zmm5%{%%k1%}%{z%}\n" + "vpsrlw $2,%%zmm5,%%zmm5 \n" + "vpackuswb %%zmm5,%%zmm5,%%zmm5 \n" + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [u_buf] "+r"(u_buf), + [v_buf] "+r"(v_buf), + [a_buf] "+r"(a_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_I410ALPHATOARGBROW_AVX512BW + +#ifdef HAS_P210TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP P210ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vbroadcasti32x4 %[kShufUV],%%zmm14 \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READP210_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READP210_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [uv_buf] "+r"(uv_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512), + [kShufUV] "m"(kShuffleYUY2UV) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm14", "k1", "k2"); +} +#endif // HAS_P210TOARGBROW_AVX512BW + +#ifdef HAS_P210TOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP P210ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vbroadcasti32x4 %[kShufUV],%%zmm14 \n" + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "vpsrlw $6,%%zmm5,%%zmm7 \n" + "vpsllw $4,%%zmm7,%%zmm7 \n" + "vpsllw $10,%%zmm5,%%zmm19 \n" + "vpsllw $14,%%zmm5,%%zmm5 \n" + "vpxord %%zmm6,%%zmm6,%%zmm6 \n" + "vmovdqu16 (%[permar30_0]),%%zmm20 \n" + "vmovdqu16 (%[permar30_1]),%%zmm21 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READP210_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READP210_MASK_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [uv_buf] "+r"(uv_buf), + [dst_ar30] "+r"(dst_ar30), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512), + [permar30_0] "r"(kPermAR30_0), + [permar30_1] "r"(kPermAR30_1), + [kShufUV] "m"(kShuffleYUY2UV) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm6", "xmm7", "xmm14", "xmm19", "xmm20", "xmm21", + "k1", "k2"); +} +#endif // HAS_P210TOAR30ROW_AVX512BW + +#ifdef HAS_P410TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP P410ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READP410_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READP410_MASK_AVX512BW + YUVTORGB_AVX512BW(yuvconstants) + STOREARGB_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [uv_buf] "+r"(uv_buf), + [dst_argb] "+r"(dst_argb), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "k1", "k2"); +} +#endif // HAS_P410TOARGBROW_AVX512BW + +#ifdef HAS_P410TOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void OMITFP P410ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + uintptr_t temp; + asm volatile( + YUVTORGB_SETUP_AVX512BW(yuvconstants) + "vpternlogd $0xff,%%zmm5,%%zmm5,%%zmm5 \n" + "vpsrlw $6,%%zmm5,%%zmm7 \n" + "vpsllw $4,%%zmm7,%%zmm7 \n" + "vpsllw $10,%%zmm5,%%zmm19 \n" + "vpsllw $14,%%zmm5,%%zmm5 \n" + "vpxord %%zmm6,%%zmm6,%%zmm6 \n" + "vmovdqu16 (%[permar30_0]),%%zmm20 \n" + "vmovdqu16 (%[permar30_1]),%%zmm21 \n" + "sub $0x20,%[width] \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + READP410_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_AVX512BW + "sub $0x20,%[width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[width] \n" + "jle 99f \n" + + READP410_MASK_AVX512BW + YUVTORGB16_AVX512BW(yuvconstants) + STOREAR30_MASK_AVX512BW + + "99: \n" + "vzeroupper \n" + : [y_buf] "+r"(y_buf), + [uv_buf] "+r"(uv_buf), + [dst_ar30] "+r"(dst_ar30), + [width] "+r"(width), + [temp] "=&r"(temp) + : [yuvconstants] "r"(yuvconstants), + [quadsplitperm] "r"(kSplitQuadWords), + [unperm] "r"(kUnpermuteAVX512), + [permar30_0] "r"(kPermAR30_0), + [permar30_1] "r"(kPermAR30_1) + : "memory", "cc", YUVTORGB_REGS_AVX512BW "xmm0", "xmm1", "xmm2", "xmm3", + "xmm4", "xmm5", "xmm6", "xmm7", "xmm19", "xmm20", "xmm21", "k1", "k2"); +} +#endif // HAS_P410TOAR30ROW_AVX512BW + +#endif // !defined(LIBYUV_DISABLE_X86) && + // (defined(__x86_64__) || defined(__i386__)) && + // !defined(LIBYUV_ENABLE_ROWWIN) #ifdef __cplusplus } // extern "C" diff --git a/libs/libyuv/source/row_hvx.cc b/libs/libyuv/source/row_hvx.cc new file mode 100644 index 0000000000..9ed5bfac19 --- /dev/null +++ b/libs/libyuv/source/row_hvx.cc @@ -0,0 +1,1863 @@ +/* + * Copyright 2026 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/row.h" + +#if !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) +#include +#include +#include +#include + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +static __inline HVX_Vector vloada(const void* ptr) { + HVX_Vector v; + memcpy(&v, (const HVX_Vector*)ptr, sizeof(v)); + return v; +} + +static __inline HVX_UVector vloadu(const void* ptr) { + HVX_UVector v; + memcpy(&v, ptr, sizeof(v)); + return v; +} + +static __inline void vstoreu(void* ptr, HVX_UVector v) { + memcpy(ptr, &v, sizeof(v)); +} + +static __inline void vstoreu_partial(void* dst, HVX_Vector v, int n) { + if (n >= 128) { + vstoreu(dst, v); + } else if (n > 0) { + const uintptr_t addr = (uintptr_t)dst; + const uintptr_t offset = addr & 127; + HVX_Vector value = Q6_V_vlalign_VVR(v, v, addr); + HVX_VectorPred ql_not = Q6_Q_vsetq_R(addr); + HVX_VectorPred qr = Q6_Q_vsetq2_R(offset + (uintptr_t)n); + if (offset + (uintptr_t)n > 128) { + Q6_vmem_QRIV(qr, (uint8_t*)dst + 128, value); + qr = Q6_Q_vcmp_eq_VbVb(value, value); + } + ql_not = Q6_Q_or_QQn(ql_not, qr); + Q6_vmem_QnRIV(ql_not, dst, value); + } +} + +static __inline HVX_Vector vloadu_partial_zero(const void* src, int n) { + if (n >= 128) { + return vloadu(src); + } + if (n <= 0) { + return Q6_V_vzero(); + } + const uintptr_t addr = (uintptr_t)src; + const uintptr_t offset = addr & 127; + HVX_Vector v0 = vloada(src); + HVX_Vector v1 = + (offset + (uintptr_t)n > 128) ? vloada((const uint8_t*)src + 128) : v0; + HVX_Vector v = Q6_V_valign_VVR(v1, v0, addr); + return Q6_V_vmux_QVV(Q6_Q_vsetq_R(n), v, Q6_V_vzero()); +} + +void CopyRow_HVX(const uint8_t* src, uint8_t* dst, int count) { + while (count >= 128) { + vstoreu(dst, vloadu(src)); + src += 128; + dst += 128; + count -= 128; + } + if (count > 0) { + vstoreu_partial(dst, vloadu_partial_zero(src, count), count); + } +} + +void CopyRow_16_HVX(const uint16_t* src, uint16_t* dst, int count) { + CopyRow_HVX((const uint8_t*)src, (uint8_t*)dst, count * 2); +} + +void SetRow_HVX(uint8_t* dst, uint8_t v8, int width) { + HVX_Vector v = Q6_Vb_vsplat_R(v8); + while (width >= 128) { + vstoreu(dst, v); + dst += 128; + width -= 128; + } + if (width > 0) { + vstoreu_partial(dst, v, width); + } +} + +void ARGBSetRow_HVX(uint8_t* dst_argb, uint32_t v32, int width) { + HVX_Vector v = Q6_V_vsplat_R(v32); + int bytes = width * 4; + while (bytes >= 128) { + vstoreu(dst_argb, v); + dst_argb += 128; + bytes -= 128; + } + if (bytes > 0) { + vstoreu_partial(dst_argb, v, bytes); + } +} + +void ARGBOrRow_HVX(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + HVX_Vector v = Q6_V_vsplat_R(value); + int bytes = width * 4; + while (bytes >= 128) { + HVX_Vector s = vloadu(src_argb); + vstoreu(dst_argb, Q6_V_vor_VV(s, v)); + src_argb += 128; + dst_argb += 128; + bytes -= 128; + } + if (bytes > 0) { + HVX_Vector s = vloadu_partial_zero(src_argb, bytes); + vstoreu_partial(dst_argb, Q6_V_vor_VV(s, v), bytes); + } +} + +void MirrorRow_HVX(const uint8_t* src, uint8_t* dst, int width) { + HVX_Vector ctrl = Q6_Vb_vsplat_R(0x7F); + src += width; + while (width >= 128) { + src -= 128; + HVX_Vector v = vloadu(src); + v = Q6_V_vdelta_VV(v, ctrl); + vstoreu(dst, v); + dst += 128; + width -= 128; + } + if (width > 0) { + src -= width; + HVX_Vector v = vloadu_partial_zero(src, width); + v = Q6_V_vdelta_VV(v, ctrl); + v = Q6_V_valign_VVR(v, v, 128 - width); + vstoreu_partial(dst, v, width); + } +} + +void MirrorRow_16_HVX(const uint16_t* src, uint16_t* dst, int width) { + HVX_Vector ctrl = Q6_Vb_vsplat_R(0x7E); + const uint8_t* s = (const uint8_t*)(src + width); + uint8_t* d = (uint8_t*)dst; + int bytes = width * 2; + while (bytes >= 128) { + s -= 128; + HVX_Vector v = vloadu(s); + v = Q6_V_vdelta_VV(v, ctrl); + vstoreu(d, v); + d += 128; + bytes -= 128; + } + if (bytes > 0) { + s -= bytes; + HVX_Vector v = vloadu_partial_zero(s, bytes); + v = Q6_V_vdelta_VV(v, ctrl); + v = Q6_V_valign_VVR(v, v, 128 - bytes); + vstoreu_partial(d, v, bytes); + } +} + +void MirrorUVRow_HVX(const uint8_t* src_uv, uint8_t* dst_uv, int width) { + MirrorRow_16_HVX((const uint16_t*)src_uv, (uint16_t*)dst_uv, width); +} + +void MirrorSplitUVRow_HVX(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + HVX_Vector ctrl = Q6_Vb_vsplat_R(0x7F); + src_uv += width * 2; + while (width >= 128) { + src_uv -= 256; + HVX_Vector s0 = vloadu(src_uv); + HVX_Vector s1 = vloadu(src_uv + 128); + HVX_VectorPair uv = Q6_W_vdeal_VVR(s1, s0, -1); + HVX_Vector u = Q6_V_vdelta_VV(Q6_V_lo_W(uv), ctrl); + HVX_Vector v = Q6_V_vdelta_VV(Q6_V_hi_W(uv), ctrl); + vstoreu(dst_u, u); + vstoreu(dst_v, v); + dst_u += 128; + dst_v += 128; + width -= 128; + } + if (width > 0) { + int src_bytes = width * 2; + src_uv -= src_bytes; + HVX_Vector s0 = + vloadu_partial_zero(src_uv, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_uv + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair uv = Q6_W_vdeal_VVR(s1, s0, -1); + HVX_Vector u = Q6_V_vdelta_VV(Q6_V_lo_W(uv), ctrl); + HVX_Vector v = Q6_V_vdelta_VV(Q6_V_hi_W(uv), ctrl); + u = Q6_V_valign_VVR(u, u, 128 - width); + v = Q6_V_valign_VVR(v, v, 128 - width); + vstoreu_partial(dst_u, u, width); + vstoreu_partial(dst_v, v, width); + } +} + +void ARGBMirrorRow_HVX(const uint8_t* src, uint8_t* dst, int width) { + HVX_Vector ctrl = Q6_Vb_vsplat_R(0x7C); + int bytes = width * 4; + src += bytes; + while (bytes >= 128) { + src -= 128; + HVX_Vector v = vloadu(src); + v = Q6_V_vdelta_VV(v, ctrl); + vstoreu(dst, v); + dst += 128; + bytes -= 128; + } + if (bytes > 0) { + src -= bytes; + HVX_Vector v = vloadu_partial_zero(src, bytes); + v = Q6_V_vdelta_VV(v, ctrl); + v = Q6_V_valign_VVR(v, v, 128 - bytes); + vstoreu_partial(dst, v, bytes); + } +} + +void SplitUVRow_HVX(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + while (width > 0) { + int w = width >= 128 ? 128 : width; + int src_bytes = w * 2; + HVX_Vector s0 = + vloadu_partial_zero(src_uv, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_uv + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair uv = Q6_W_vdeal_VVR(s1, s0, -1); + vstoreu_partial(dst_u, Q6_V_lo_W(uv), w); + vstoreu_partial(dst_v, Q6_V_hi_W(uv), w); + src_uv += 256; + dst_u += 128; + dst_v += 128; + width -= 128; + } +} + +void MergeUVRow_HVX(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width) { + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector u = vloadu_partial_zero(src_u, w); + HVX_Vector v = vloadu_partial_zero(src_v, w); + HVX_VectorPair uv = Q6_W_vshuff_VVR(v, u, -1); + int dst_bytes = w * 2; + vstoreu_partial(dst_uv, Q6_V_lo_W(uv), dst_bytes > 128 ? 128 : dst_bytes); + if (dst_bytes > 128) { + vstoreu_partial(dst_uv + 128, Q6_V_hi_W(uv), dst_bytes - 128); + } + src_u += 128; + src_v += 128; + dst_uv += 256; + width -= 128; + } +} + +void SplitUVRow_16_HVX(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width) { + int shift = 16 - depth; + while (width > 0) { + int w = width >= 64 ? 64 : width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_uv, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = + src_bytes > 128 + ? vloadu_partial_zero((const uint8_t*)src_uv + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair uv = Q6_W_vdeal_VVR(s1, s0, -2); + HVX_Vector u = Q6_Vuh_vlsr_VuhR(Q6_V_lo_W(uv), shift); + HVX_Vector v = Q6_Vuh_vlsr_VuhR(Q6_V_hi_W(uv), shift); + vstoreu_partial(dst_u, u, w * 2); + vstoreu_partial(dst_v, v, w * 2); + src_uv += 128; + dst_u += 64; + dst_v += 64; + width -= 64; + } +} + +void MergeUVRow_16_HVX(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width) { + int shift = 16 - depth; + while (width > 0) { + int w = width >= 64 ? 64 : width; + HVX_Vector u = vloadu_partial_zero(src_u, w * 2); + HVX_Vector v = vloadu_partial_zero(src_v, w * 2); + u = Q6_Vh_vasl_VhR(u, shift); + v = Q6_Vh_vasl_VhR(v, shift); + HVX_VectorPair uv = Q6_W_vshuff_VVR(v, u, -2); + int dst_bytes = w * 4; + vstoreu_partial(dst_uv, Q6_V_lo_W(uv), dst_bytes > 128 ? 128 : dst_bytes); + if (dst_bytes > 128) { + vstoreu_partial((uint8_t*)dst_uv + 128, Q6_V_hi_W(uv), dst_bytes - 128); + } + src_u += 64; + src_v += 64; + dst_uv += 128; + width -= 64; + } +} + +void SplitARGBRow_HVX(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width) { + while (width > 0) { + int w = width >= 128 ? 128 : width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_argb, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = + src_bytes > 128 + ? vloadu_partial_zero(src_argb + 128, + src_bytes > 256 ? 128 : src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector s2 = + src_bytes > 256 + ? vloadu_partial_zero(src_argb + 256, + src_bytes > 384 ? 128 : src_bytes - 256) + : Q6_V_vzero(); + HVX_Vector s3 = src_bytes > 384 + ? vloadu_partial_zero(src_argb + 384, src_bytes - 384) + : Q6_V_vzero(); + HVX_VectorPair p01 = Q6_W_vdeal_VVR(s1, s0, -1); + HVX_VectorPair p23 = Q6_W_vdeal_VVR(s3, s2, -1); + HVX_VectorPair br = Q6_W_vdeal_VVR(Q6_V_lo_W(p23), Q6_V_lo_W(p01), -1); + HVX_VectorPair ga = Q6_W_vdeal_VVR(Q6_V_hi_W(p23), Q6_V_hi_W(p01), -1); + vstoreu_partial(dst_b, Q6_V_lo_W(br), w); + vstoreu_partial(dst_g, Q6_V_lo_W(ga), w); + vstoreu_partial(dst_r, Q6_V_hi_W(br), w); + vstoreu_partial(dst_a, Q6_V_hi_W(ga), w); + src_argb += 512; + dst_b += 128; + dst_g += 128; + dst_r += 128; + dst_a += 128; + width -= 128; + } +} + +void MergeARGBRow_HVX(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width) { + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector b = vloadu_partial_zero(src_b, w); + HVX_Vector g = vloadu_partial_zero(src_g, w); + HVX_Vector r = vloadu_partial_zero(src_r, w); + HVX_Vector a = vloadu_partial_zero(src_a, w); + HVX_VectorPair br = Q6_W_vshuff_VVR(r, b, -1); + HVX_VectorPair ga = Q6_W_vshuff_VVR(a, g, -1); + HVX_VectorPair p01 = Q6_W_vshuff_VVR(Q6_V_lo_W(ga), Q6_V_lo_W(br), -1); + HVX_VectorPair p23 = Q6_W_vshuff_VVR(Q6_V_hi_W(ga), Q6_V_hi_W(br), -1); + int dst_bytes = w * 4; + vstoreu_partial(dst_argb, Q6_V_lo_W(p01), + dst_bytes > 128 ? 128 : dst_bytes); + if (dst_bytes > 128) { + vstoreu_partial(dst_argb + 128, Q6_V_hi_W(p01), + dst_bytes > 256 ? 128 : dst_bytes - 128); + } + if (dst_bytes > 256) { + vstoreu_partial(dst_argb + 256, Q6_V_lo_W(p23), + dst_bytes > 384 ? 128 : dst_bytes - 256); + } + if (dst_bytes > 384) { + vstoreu_partial(dst_argb + 384, Q6_V_hi_W(p23), dst_bytes - 384); + } + src_b += 128; + src_g += 128; + src_r += 128; + src_a += 128; + dst_argb += 512; + width -= 128; + } +} + +void SplitXRGBRow_HVX(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + while (width > 0) { + int w = width >= 128 ? 128 : width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_argb, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = + src_bytes > 128 + ? vloadu_partial_zero(src_argb + 128, + src_bytes > 256 ? 128 : src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector s2 = + src_bytes > 256 + ? vloadu_partial_zero(src_argb + 256, + src_bytes > 384 ? 128 : src_bytes - 256) + : Q6_V_vzero(); + HVX_Vector s3 = src_bytes > 384 + ? vloadu_partial_zero(src_argb + 384, src_bytes - 384) + : Q6_V_vzero(); + HVX_VectorPair p01 = Q6_W_vdeal_VVR(s1, s0, -1); + HVX_VectorPair p23 = Q6_W_vdeal_VVR(s3, s2, -1); + HVX_VectorPair br = Q6_W_vdeal_VVR(Q6_V_lo_W(p23), Q6_V_lo_W(p01), -1); + HVX_VectorPair ga = Q6_W_vdeal_VVR(Q6_V_hi_W(p23), Q6_V_hi_W(p01), -1); + vstoreu_partial(dst_b, Q6_V_lo_W(br), w); + vstoreu_partial(dst_g, Q6_V_lo_W(ga), w); + vstoreu_partial(dst_r, Q6_V_hi_W(br), w); + src_argb += 512; + dst_b += 128; + dst_g += 128; + dst_r += 128; + width -= 128; + } +} + +void MergeXRGBRow_HVX(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width) { + HVX_Vector a = Q6_Vb_vsplat_R(0xff); + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector b = vloadu_partial_zero(src_b, w); + HVX_Vector g = vloadu_partial_zero(src_g, w); + HVX_Vector r = vloadu_partial_zero(src_r, w); + HVX_VectorPair br = Q6_W_vshuff_VVR(r, b, -1); + HVX_VectorPair ga = Q6_W_vshuff_VVR(a, g, -1); + HVX_VectorPair p01 = Q6_W_vshuff_VVR(Q6_V_lo_W(ga), Q6_V_lo_W(br), -1); + HVX_VectorPair p23 = Q6_W_vshuff_VVR(Q6_V_hi_W(ga), Q6_V_hi_W(br), -1); + int dst_bytes = w * 4; + vstoreu_partial(dst_argb, Q6_V_lo_W(p01), + dst_bytes > 128 ? 128 : dst_bytes); + if (dst_bytes > 128) { + vstoreu_partial(dst_argb + 128, Q6_V_hi_W(p01), + dst_bytes > 256 ? 128 : dst_bytes - 128); + } + if (dst_bytes > 256) { + vstoreu_partial(dst_argb + 256, Q6_V_lo_W(p23), + dst_bytes > 384 ? 128 : dst_bytes - 256); + } + if (dst_bytes > 384) { + vstoreu_partial(dst_argb + 384, Q6_V_hi_W(p23), dst_bytes - 384); + } + src_b += 128; + src_g += 128; + src_r += 128; + dst_argb += 512; + width -= 128; + } +} + +void SwapUVRow_HVX(const uint8_t* src_uv, uint8_t* dst_vu, int width) { + HVX_Vector ctrl = Q6_Vb_vsplat_R(0x01); + int bytes = width * 2; + while (bytes >= 128) { + HVX_Vector v = vloadu(src_uv); + vstoreu(dst_vu, Q6_V_vdelta_VV(v, ctrl)); + src_uv += 128; + dst_vu += 128; + bytes -= 128; + } + if (bytes > 0) { + HVX_Vector v = vloadu_partial_zero(src_uv, bytes); + vstoreu_partial(dst_vu, Q6_V_vdelta_VV(v, ctrl), bytes); + } +} + +void InterpolateRow_HVX(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + int y1_fraction = source_y_fraction; + int y0_fraction = 256 - y1_fraction; + const uint8_t* src_ptr1 = src_ptr + src_stride; + if (y1_fraction == 0) { + CopyRow_HVX(src_ptr, dst_ptr, width); + return; + } + if (y1_fraction == 128) { + while (width >= 128) { + HVX_Vector s0 = vloadu(src_ptr); + HVX_Vector s1 = vloadu(src_ptr1); + vstoreu(dst_ptr, Q6_Vub_vavg_VubVub_rnd(s0, s1)); + src_ptr += 128; + src_ptr1 += 128; + dst_ptr += 128; + width -= 128; + } + if (width > 0) { + HVX_Vector s0 = vloadu_partial_zero(src_ptr, width); + HVX_Vector s1 = vloadu_partial_zero(src_ptr1, width); + vstoreu_partial(dst_ptr, Q6_Vub_vavg_VubVub_rnd(s0, s1), width); + } + return; + } + uint32_t y0_32 = (uint32_t)y0_fraction * 0x01010101u; + uint32_t y1_32 = (uint32_t)y1_fraction * 0x01010101u; + HVX_Vector v128 = Q6_Vh_vsplat_R(128); + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector s0 = vloadu_partial_zero(src_ptr, w); + HVX_Vector s1 = vloadu_partial_zero(src_ptr1, w); + HVX_VectorPair p = Q6_Wuh_vmpy_VubRub(s0, y0_32); + p = Q6_Wuh_vmpyacc_WuhVubRub(p, s1, y1_32); + HVX_Vector lo = Q6_Vuh_vadd_VuhVuh_sat(Q6_V_lo_W(p), v128); + HVX_Vector hi = Q6_Vuh_vadd_VuhVuh_sat(Q6_V_hi_W(p), v128); + HVX_Vector out = Q6_Vb_vshuffo_VbVb(hi, lo); + vstoreu_partial(dst_ptr, out, w); + src_ptr += 128; + src_ptr1 += 128; + dst_ptr += 128; + width -= 128; + } +} + +void InterpolateRow_16_HVX(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + int y1_fraction = source_y_fraction; + int y0_fraction = 256 - y1_fraction; + const uint16_t* src_ptr1 = src_ptr + src_stride; + if (y1_fraction == 0) { + CopyRow_16_HVX(src_ptr, dst_ptr, width); + return; + } + if (y1_fraction == 128) { + int bytes = width * 2; + const uint8_t* s0_p = (const uint8_t*)src_ptr; + const uint8_t* s1_p = (const uint8_t*)src_ptr1; + uint8_t* d_p = (uint8_t*)dst_ptr; + while (bytes >= 128) { + HVX_Vector s0 = vloadu(s0_p); + HVX_Vector s1 = vloadu(s1_p); + vstoreu(d_p, Q6_Vuh_vavg_VuhVuh_rnd(s0, s1)); + s0_p += 128; + s1_p += 128; + d_p += 128; + bytes -= 128; + } + if (bytes > 0) { + HVX_Vector s0 = vloadu_partial_zero(s0_p, bytes); + HVX_Vector s1 = vloadu_partial_zero(s1_p, bytes); + vstoreu_partial(d_p, Q6_Vuh_vavg_VuhVuh_rnd(s0, s1), bytes); + } + return; + } + uint32_t y0_32 = ((uint32_t)y0_fraction << 16) | (uint32_t)y0_fraction; + uint32_t y1_32 = ((uint32_t)y1_fraction << 16) | (uint32_t)y1_fraction; + HVX_Vector v128 = Q6_V_vsplat_R(128); + while (width > 0) { + int w = width >= 64 ? 64 : width; + int bytes = w * 2; + HVX_Vector s0 = vloadu_partial_zero(src_ptr, bytes); + HVX_Vector s1 = vloadu_partial_zero(src_ptr1, bytes); + HVX_VectorPair p = Q6_Wuw_vmpy_VuhRuh(s0, y0_32); + p = Q6_Wuw_vmpyacc_WuwVuhRuh(p, s1, y1_32); + HVX_Vector lo = Q6_Vuw_vlsr_VuwR(Q6_Vw_vadd_VwVw(Q6_V_lo_W(p), v128), 8); + HVX_Vector hi = Q6_Vuw_vlsr_VuwR(Q6_Vw_vadd_VwVw(Q6_V_hi_W(p), v128), 8); + HVX_Vector out = Q6_Vh_vshuffe_VhVh(hi, lo); + vstoreu_partial(dst_ptr, out, bytes); + src_ptr += 64; + src_ptr1 += 64; + dst_ptr += 64; + width -= 64; + } +} + +void BlendPlaneRow_HVX(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width) { + HVX_Vector v255 = Q6_Vh_vsplat_R(255); + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector f = vloadu_partial_zero(src0, w); + HVX_Vector b = vloadu_partial_zero(src1, w); + HVX_Vector a = vloadu_partial_zero(alpha, w); + HVX_Vector not_a = Q6_V_vnot_V(a); + HVX_VectorPair p = Q6_Wuh_vmpy_VubVub(f, a); + p = Q6_Wuh_vmpyacc_WuhVubVub(p, b, not_a); + HVX_Vector lo = Q6_Vuh_vadd_VuhVuh_sat(Q6_V_lo_W(p), v255); + HVX_Vector hi = Q6_Vuh_vadd_VuhVuh_sat(Q6_V_hi_W(p), v255); + HVX_Vector out = Q6_Vb_vshuffo_VbVb(hi, lo); + vstoreu_partial(dst, out, w); + src0 += 128; + src1 += 128; + alpha += 128; + dst += 128; + width -= 128; + } +} + +void ARGBBlendRow_HVX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + HVX_Vector v255 = Q6_Vh_vsplat_R(255); + HVX_Vector v_alpha_mask = Q6_V_vsplat_R(0xFF000000u); + int bytes = width * 4; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + HVX_Vector fg = vloadu_partial_zero(src_argb, b_cnt); + HVX_Vector bg = vloadu_partial_zero(src_argb1, b_cnt); + HVX_Vector t = Q6_Vb_vshuffo_VbVb(fg, fg); + HVX_Vector a_vec = Q6_Vh_vshuffo_VhVh(t, t); + HVX_VectorPair p = Q6_Wuh_vmpy_VubVub(bg, a_vec); + HVX_Vector lo = Q6_Vuh_vadd_VuhVuh_sat(Q6_V_lo_W(p), v255); + HVX_Vector hi = Q6_Vuh_vadd_VuhVuh_sat(Q6_V_hi_W(p), v255); + HVX_Vector atten_bg = Q6_Vb_vshuffo_VbVb(hi, lo); + HVX_Vector scaled_bg = Q6_Vub_vsub_VubVub_sat(bg, atten_bg); + HVX_Vector out = Q6_Vub_vadd_VubVub_sat(scaled_bg, fg); + out = Q6_V_vor_VV(out, v_alpha_mask); + vstoreu_partial(dst_argb, out, b_cnt); + src_argb += 128; + src_argb1 += 128; + dst_argb += 128; + bytes -= 128; + } +} + +void ARGBAlphaBlendRow_HVX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + HVX_Vector vzero = Q6_V_vzero(); + HVX_Vector v0001 = Q6_Vh_vsplat_R(1); + HVX_Vector v00ff = Q6_Vh_vsplat_R(255); + HVX_Vector vffff = Q6_Vh_vsplat_R(-1); + HVX_Vector v_rgb_mask = Q6_V_vsplat_R(0x00FFFFFFu); + int bytes = width * 4; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + HVX_Vector fg = vloadu_partial_zero(src_argb0, b_cnt); + HVX_Vector bg = vloadu_partial_zero(src_argb1, b_cnt); + + // Broadcast sa and da to all 4 byte lanes of each 32-bit pixel. + HVX_Vector t_fg = Q6_Vb_vshuffo_VbVb(fg, fg); + HVX_Vector sa_vec = Q6_Vh_vshuffo_VhVh(t_fg, t_fg); + HVX_Vector t_bg = Q6_Vb_vshuffo_VbVb(bg, bg); + HVX_Vector da_vec = Q6_Vh_vshuffo_VhVh(t_bg, t_bg); + + // Both uint16_t halfwords of each pixel hold sa and da (0..255). + HVX_Vector sa16 = Q6_V_vand_VV(sa_vec, v00ff); + HVX_Vector da16 = Q6_V_vand_VV(da_vec, v00ff); + + // x = da * sa in both uint16_t halfwords of each pixel. + HVX_Vector x = Q6_V_lo_W(Q6_Wuh_vmpy_VubVub(da_vec, sa_vec)); + // prod_div255 = (x + 1 + (x >> 8)) >> 8. + HVX_Vector prod_div255 = Q6_Vuh_vlsr_VuhR( + Q6_Vh_vadd_VhVh(Q6_Vh_vadd_VhVh(x, v0001), Q6_Vuh_vlsr_VuhR(x, 8)), 8); + // out_a = da + sa - (da * sa) / 255. + HVX_Vector out_a16 = + Q6_Vh_vadd_VhVh(da16, Q6_Vh_vsub_VhVh(sa16, prod_div255)); + + // 8-step restoring division: ratio = (da == 0) ? 255 : (sa * 255) / out_a. + HVX_Vector rem = Q6_Vh_vsub_VhVh(Q6_Vh_vasl_VhR(sa16, 8), sa16); + HVX_VectorPred q_da_zero = Q6_Q_vcmp_eq_VhVh(da16, vzero); + rem = Q6_V_vmux_QVV(q_da_zero, vffff, rem); + HVX_Vector ratio = vzero; + + for (int bit = 7; bit >= 0; --bit) { + HVX_Vector d_sh = Q6_Vh_vasl_VhR(out_a16, bit); + HVX_VectorPred q_gt = Q6_Q_vcmp_gt_VuhVuh(d_sh, rem); + rem = Q6_V_vmux_QVV(q_gt, rem, Q6_Vh_vsub_VhVh(rem, d_sh)); + ratio = Q6_V_vmux_QVV(q_gt, ratio, + Q6_V_vor_VV(ratio, Q6_Vb_vsplat_R(1 << bit))); + } + + // Exact RGB lerp: (bg * (255 - ratio) + fg * ratio) / 255. + HVX_Vector inv_ratio = Q6_V_vnot_V(ratio); + HVX_VectorPair p_rgb = Q6_Wuh_vmpy_VubVub(fg, ratio); + p_rgb = Q6_Wuh_vmpyacc_WuhVubVub(p_rgb, bg, inv_ratio); + HVX_Vector lo = Q6_V_lo_W(p_rgb); + HVX_Vector hi = Q6_V_hi_W(p_rgb); + lo = Q6_Vh_vadd_VhVh(Q6_Vh_vadd_VhVh(lo, v0001), Q6_Vuh_vlsr_VuhR(lo, 8)); + hi = Q6_Vh_vadd_VhVh(Q6_Vh_vadd_VhVh(hi, v0001), Q6_Vuh_vlsr_VuhR(hi, 8)); + HVX_Vector out = Q6_Vb_vshuffo_VbVb(hi, lo); + out = + Q6_V_vor_VV(Q6_V_vand_VV(out, v_rgb_mask), Q6_Vw_vasl_VwR(out_a16, 24)); + vstoreu_partial(dst_argb, out, b_cnt); + src_argb0 += 128; + src_argb1 += 128; + dst_argb += 128; + bytes -= 128; + } +} + +void ARGBAttenuateRow_HVX(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + HVX_Vector v255 = Q6_Vh_vsplat_R(255); + HVX_Vector v_rgb_mask = Q6_V_vsplat_R(0x00FFFFFFu); + HVX_Vector v_a_mask = Q6_V_vsplat_R(0xFF000000u); + int bytes = width * 4; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + HVX_Vector src = vloadu_partial_zero(src_argb, b_cnt); + HVX_Vector t = Q6_Vb_vshuffo_VbVb(src, src); + HVX_Vector a_vec = Q6_Vh_vshuffo_VhVh(t, t); + HVX_VectorPair p = Q6_Wuh_vmpy_VubVub(src, a_vec); + HVX_Vector lo = Q6_Vuh_vadd_VuhVuh_sat(Q6_V_lo_W(p), v255); + HVX_Vector hi = Q6_Vuh_vadd_VuhVuh_sat(Q6_V_hi_W(p), v255); + HVX_Vector out = Q6_Vb_vshuffo_VbVb(hi, lo); + out = + Q6_V_vor_VV(Q6_V_vand_VV(out, v_rgb_mask), Q6_V_vand_VV(src, v_a_mask)); + vstoreu_partial(dst_argb, out, b_cnt); + src_argb += 128; + dst_argb += 128; + bytes -= 128; + } +} + +void ARGBMultiplyRow_HVX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + HVX_Vector v128 = Q6_Vh_vsplat_R(128); + int bytes = width * 4; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + HVX_Vector s0 = vloadu_partial_zero(src_argb, b_cnt); + HVX_Vector s1 = vloadu_partial_zero(src_argb1, b_cnt); + HVX_VectorPair p = Q6_Wuh_vmpy_VubVub(s0, s1); + HVX_Vector lo = Q6_Vuh_vadd_VuhVuh_sat(Q6_V_lo_W(p), v128); + HVX_Vector hi = Q6_Vuh_vadd_VuhVuh_sat(Q6_V_hi_W(p), v128); + HVX_Vector out = Q6_Vb_vshuffo_VbVb(hi, lo); + vstoreu_partial(dst_argb, out, b_cnt); + src_argb += 128; + src_argb1 += 128; + dst_argb += 128; + bytes -= 128; + } +} + +void ARGBAddRow_HVX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + int bytes = width * 4; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + HVX_Vector s0 = vloadu_partial_zero(src_argb, b_cnt); + HVX_Vector s1 = vloadu_partial_zero(src_argb1, b_cnt); + vstoreu_partial(dst_argb, Q6_Vub_vadd_VubVub_sat(s0, s1), b_cnt); + src_argb += 128; + src_argb1 += 128; + dst_argb += 128; + bytes -= 128; + } +} + +void ARGBSubtractRow_HVX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + int bytes = width * 4; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + HVX_Vector s0 = vloadu_partial_zero(src_argb, b_cnt); + HVX_Vector s1 = vloadu_partial_zero(src_argb1, b_cnt); + vstoreu_partial(dst_argb, Q6_Vub_vsub_VubVub_sat(s0, s1), b_cnt); + src_argb += 128; + src_argb1 += 128; + dst_argb += 128; + bytes -= 128; + } +} + +void ARGBExtractAlphaRow_HVX(const uint8_t* src_argb, + uint8_t* dst_a, + int width) { + while (width > 0) { + int w = width >= 128 ? 128 : width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_argb, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = + src_bytes > 128 + ? vloadu_partial_zero(src_argb + 128, + src_bytes > 256 ? 128 : src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector s2 = + src_bytes > 256 + ? vloadu_partial_zero(src_argb + 256, + src_bytes > 384 ? 128 : src_bytes - 256) + : Q6_V_vzero(); + HVX_Vector s3 = src_bytes > 384 + ? vloadu_partial_zero(src_argb + 384, src_bytes - 384) + : Q6_V_vzero(); + HVX_Vector ga01 = Q6_V_hi_W(Q6_W_vdeal_VVR(s1, s0, -1)); + HVX_Vector ga23 = Q6_V_hi_W(Q6_W_vdeal_VVR(s3, s2, -1)); + HVX_Vector a = Q6_V_hi_W(Q6_W_vdeal_VVR(ga23, ga01, -1)); + vstoreu_partial(dst_a, a, w); + src_argb += 512; + dst_a += 128; + width -= 128; + } +} + +void ARGBCopyAlphaRow_HVX(const uint8_t* src, uint8_t* dst, int width) { + HVX_Vector v_rgb_mask = Q6_V_vsplat_R(0x00FFFFFFu); + HVX_Vector v_a_mask = Q6_V_vsplat_R(0xFF000000u); + int bytes = width * 4; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + HVX_Vector s = vloadu_partial_zero(src, b_cnt); + HVX_Vector d = vloadu_partial_zero(dst, b_cnt); + HVX_Vector out = + Q6_V_vor_VV(Q6_V_vand_VV(d, v_rgb_mask), Q6_V_vand_VV(s, v_a_mask)); + vstoreu_partial(dst, out, b_cnt); + src += 128; + dst += 128; + bytes -= 128; + } +} + +void ARGBCopyYToAlphaRow_HVX(const uint8_t* src, uint8_t* dst, int width) { + HVX_Vector v_rgb_mask = Q6_V_vsplat_R(0x00FFFFFFu); + HVX_Vector z = Q6_V_vzero(); + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector y = vloadu_partial_zero(src, w); + HVX_VectorPair ga = Q6_W_vshuff_VVR(y, z, -1); + HVX_VectorPair p01 = Q6_W_vshuff_VVR(Q6_V_lo_W(ga), z, -1); + HVX_VectorPair p23 = Q6_W_vshuff_VVR(Q6_V_hi_W(ga), z, -1); + int dst_bytes = w * 4; + int b0 = dst_bytes > 128 ? 128 : dst_bytes; + HVX_Vector d0 = vloadu_partial_zero(dst, b0); + vstoreu_partial( + dst, Q6_V_vor_VV(Q6_V_vand_VV(d0, v_rgb_mask), Q6_V_lo_W(p01)), b0); + if (dst_bytes > 128) { + int b1 = dst_bytes > 256 ? 128 : dst_bytes - 128; + HVX_Vector d1 = vloadu_partial_zero(dst + 128, b1); + vstoreu_partial(dst + 128, + Q6_V_vor_VV(Q6_V_vand_VV(d1, v_rgb_mask), Q6_V_hi_W(p01)), + b1); + } + if (dst_bytes > 256) { + int b2 = dst_bytes > 384 ? 128 : dst_bytes - 256; + HVX_Vector d2 = vloadu_partial_zero(dst + 256, b2); + vstoreu_partial(dst + 256, + Q6_V_vor_VV(Q6_V_vand_VV(d2, v_rgb_mask), Q6_V_lo_W(p23)), + b2); + } + if (dst_bytes > 384) { + int b3 = dst_bytes - 384; + HVX_Vector d3 = vloadu_partial_zero(dst + 384, b3); + vstoreu_partial(dst + 384, + Q6_V_vor_VV(Q6_V_vand_VV(d3, v_rgb_mask), Q6_V_hi_W(p23)), + b3); + } + src += 128; + dst += 512; + width -= 128; + } +} + +void Convert16To8Row_HVX(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width) { + uint32_t scale32 = ((uint32_t)(uint16_t)scale << 16) | (uint16_t)scale; + HVX_Vector v255 = Q6_Vh_vsplat_R(255); + while (width > 0) { + int w = width >= 128 ? 128 : width; + int src_bytes = w * 2; + HVX_Vector s0 = + vloadu_partial_zero(src_y, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = + src_bytes > 128 + ? vloadu_partial_zero((const uint8_t*)src_y + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair p0 = Q6_Wuw_vmpy_VuhRuh(s0, scale32); + HVX_VectorPair p1 = Q6_Wuw_vmpy_VuhRuh(s1, scale32); + HVX_Vector h0 = Q6_Vuh_vmin_VuhVuh( + Q6_Vh_vshuffo_VhVh(Q6_V_hi_W(p0), Q6_V_lo_W(p0)), v255); + HVX_Vector h1 = Q6_Vuh_vmin_VuhVuh( + Q6_Vh_vshuffo_VhVh(Q6_V_hi_W(p1), Q6_V_lo_W(p1)), v255); + HVX_Vector out = Q6_Vb_vpacke_VhVh(h1, h0); + vstoreu_partial(dst_y, out, w); + src_y += 128; + dst_y += 128; + width -= 128; + } +} + +void Convert8To16Row_HVX(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width) { + int shift = 16 - bits; + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector s = vloadu_partial_zero(src_y, w); + HVX_VectorPair d16 = Q6_W_vshuff_VVR(s, s, -1); + HVX_Vector d0 = Q6_Vuh_vlsr_VuhR(Q6_V_lo_W(d16), shift); + HVX_Vector d1 = Q6_Vuh_vlsr_VuhR(Q6_V_hi_W(d16), shift); + int dst_bytes = w * 2; + vstoreu_partial(dst_y, d0, dst_bytes > 128 ? 128 : dst_bytes); + if (dst_bytes > 128) { + vstoreu_partial((uint8_t*)dst_y + 128, d1, dst_bytes - 128); + } + src_y += 128; + dst_y += 128; + width -= 128; + } +} + +void Convert8To8Row_HVX(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width) { + uint32_t scale32 = (uint32_t)(uint8_t)scale * 0x01010101u; + HVX_Vector vbias = Q6_Vb_vsplat_R(bias); + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector s = vloadu_partial_zero(src_y, w); + HVX_VectorPair p = Q6_Wuh_vmpy_VubRub(s, scale32); + HVX_Vector out = + Q6_Vb_vadd_VbVb(Q6_Vb_vshuffo_VbVb(Q6_V_hi_W(p), Q6_V_lo_W(p)), vbias); + vstoreu_partial(dst_y, out, w); + src_y += 128; + dst_y += 128; + width -= 128; + } +} + +void MultiplyRow_16_HVX(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + uint32_t scale32 = ((uint32_t)(uint16_t)scale << 16) | (uint16_t)scale; + while (width > 0) { + int w = width >= 64 ? 64 : width; + int bytes = w * 2; + HVX_Vector s = vloadu_partial_zero(src_y, bytes); + HVX_VectorPair p = Q6_Wuw_vmpy_VuhRuh(s, scale32); + HVX_Vector out = Q6_Vh_vshuffe_VhVh(Q6_V_hi_W(p), Q6_V_lo_W(p)); + vstoreu_partial(dst_y, out, bytes); + src_y += 64; + dst_y += 64; + width -= 64; + } +} + +void DivideRow_16_HVX(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + if (scale == 65536) { // Divide by 1, so do memcpy. + if (src_y != dst_y) { + memcpy(dst_y, src_y, (size_t)width * 2); + } + return; + } + uint32_t scale32 = ((uint32_t)(uint16_t)scale << 16) | (uint16_t)scale; + while (width > 0) { + int w = width >= 64 ? 64 : width; + int bytes = w * 2; + HVX_Vector s = vloadu_partial_zero(src_y, bytes); + HVX_VectorPair p = Q6_Wuw_vmpy_VuhRuh(s, scale32); + HVX_Vector out = Q6_Vh_vshuffo_VhVh(Q6_V_hi_W(p), Q6_V_lo_W(p)); + vstoreu_partial(dst_y, out, bytes); + src_y += 64; + dst_y += 64; + width -= 64; + } +} + +void HalfRow_16To8_HVX(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + uint32_t scale32 = ((uint32_t)(uint16_t)scale << 16) | (uint16_t)scale; + HVX_Vector v255 = Q6_Vh_vsplat_R(255); + const uint16_t* src_uv1 = src_uv + src_uv_stride; + while (width > 0) { + int w = width >= 128 ? 128 : width; + int src_bytes = w * 2; + HVX_Vector s0 = + vloadu_partial_zero(src_uv, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = + src_bytes > 128 + ? vloadu_partial_zero((const uint8_t*)src_uv + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector t0 = + vloadu_partial_zero(src_uv1, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector t1 = src_bytes > 128 + ? vloadu_partial_zero((const uint8_t*)src_uv1 + 128, + src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector a0 = Q6_Vuh_vavg_VuhVuh_rnd(s0, t0); + HVX_Vector a1 = Q6_Vuh_vavg_VuhVuh_rnd(s1, t1); + HVX_VectorPair p0 = Q6_Wuw_vmpy_VuhRuh(a0, scale32); + HVX_VectorPair p1 = Q6_Wuw_vmpy_VuhRuh(a1, scale32); + HVX_Vector h0 = Q6_Vuh_vmin_VuhVuh( + Q6_Vh_vshuffo_VhVh(Q6_V_hi_W(p0), Q6_V_lo_W(p0)), v255); + HVX_Vector h1 = Q6_Vuh_vmin_VuhVuh( + Q6_Vh_vshuffo_VhVh(Q6_V_hi_W(p1), Q6_V_lo_W(p1)), v255); + HVX_Vector out = Q6_Vb_vpacke_VhVh(h1, h0); + vstoreu_partial(dst_uv, out, w); + src_uv += 128; + src_uv1 += 128; + dst_uv += 128; + width -= 128; + } +} + +void YUY2ToYRow_HVX(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { + while (width > 0) { + int w = width >= 128 ? 128 : width; + int src_bytes = w * 2; + HVX_Vector s0 = + vloadu_partial_zero(src_yuy2, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_yuy2 + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair d = Q6_W_vdeal_VVR(s1, s0, -1); + vstoreu_partial(dst_y, Q6_V_lo_W(d), w); + src_yuy2 += 256; + dst_y += 128; + width -= 128; + } +} + +void YUY2ToUV422Row_HVX(const uint8_t* src_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + int uv_width = (width + 1) >> 1; + while (uv_width > 0) { + int w = uv_width >= 64 ? 64 : uv_width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_yuy2, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_yuy2 + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector uv = Q6_V_hi_W(Q6_W_vdeal_VVR(s1, s0, -1)); + HVX_VectorPair u_v = Q6_W_vdeal_VVR(uv, uv, -1); + vstoreu_partial(dst_u, Q6_V_lo_W(u_v), w); + vstoreu_partial(dst_v, Q6_V_hi_W(u_v), w); + src_yuy2 += 256; + dst_u += 64; + dst_v += 64; + uv_width -= 64; + } +} + +void YUY2ToUVRow_HVX(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* src_yuy2_1 = src_yuy2 + src_stride_yuy2; + int uv_width = (width + 1) >> 1; + while (uv_width > 0) { + int w = uv_width >= 64 ? 64 : uv_width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_yuy2, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_yuy2 + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector t0 = + vloadu_partial_zero(src_yuy2_1, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector t1 = src_bytes > 128 + ? vloadu_partial_zero(src_yuy2_1 + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector a0 = Q6_Vub_vavg_VubVub_rnd(s0, t0); + HVX_Vector a1 = Q6_Vub_vavg_VubVub_rnd(s1, t1); + HVX_Vector uv = Q6_V_hi_W(Q6_W_vdeal_VVR(a1, a0, -1)); + HVX_VectorPair u_v = Q6_W_vdeal_VVR(uv, uv, -1); + vstoreu_partial(dst_u, Q6_V_lo_W(u_v), w); + vstoreu_partial(dst_v, Q6_V_hi_W(u_v), w); + src_yuy2 += 256; + src_yuy2_1 += 256; + dst_u += 64; + dst_v += 64; + uv_width -= 64; + } +} + +void UYVYToYRow_HVX(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { + while (width > 0) { + int w = width >= 128 ? 128 : width; + int src_bytes = w * 2; + HVX_Vector s0 = + vloadu_partial_zero(src_uyvy, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_uyvy + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair d = Q6_W_vdeal_VVR(s1, s0, -1); + vstoreu_partial(dst_y, Q6_V_hi_W(d), w); + src_uyvy += 256; + dst_y += 128; + width -= 128; + } +} + +void UYVYToUV422Row_HVX(const uint8_t* src_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + int uv_width = (width + 1) >> 1; + while (uv_width > 0) { + int w = uv_width >= 64 ? 64 : uv_width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_uyvy, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_uyvy + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector uv = Q6_V_lo_W(Q6_W_vdeal_VVR(s1, s0, -1)); + HVX_VectorPair u_v = Q6_W_vdeal_VVR(uv, uv, -1); + vstoreu_partial(dst_u, Q6_V_lo_W(u_v), w); + vstoreu_partial(dst_v, Q6_V_hi_W(u_v), w); + src_uyvy += 256; + dst_u += 64; + dst_v += 64; + uv_width -= 64; + } +} + +void UYVYToUVRow_HVX(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* src_uyvy_1 = src_uyvy + src_stride_uyvy; + int uv_width = (width + 1) >> 1; + while (uv_width > 0) { + int w = uv_width >= 64 ? 64 : uv_width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_uyvy, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_uyvy + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector t0 = + vloadu_partial_zero(src_uyvy_1, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector t1 = src_bytes > 128 + ? vloadu_partial_zero(src_uyvy_1 + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector a0 = Q6_Vub_vavg_VubVub_rnd(s0, t0); + HVX_Vector a1 = Q6_Vub_vavg_VubVub_rnd(s1, t1); + HVX_Vector uv = Q6_V_lo_W(Q6_W_vdeal_VVR(a1, a0, -1)); + HVX_VectorPair u_v = Q6_W_vdeal_VVR(uv, uv, -1); + vstoreu_partial(dst_u, Q6_V_lo_W(u_v), w); + vstoreu_partial(dst_v, Q6_V_hi_W(u_v), w); + src_uyvy += 256; + src_uyvy_1 += 256; + dst_u += 64; + dst_v += 64; + uv_width -= 64; + } +} + +void J400ToARGBRow_HVX(const uint8_t* src_y, uint8_t* dst_argb, int width) { + HVX_Vector a = Q6_Vb_vsplat_R(0xff); + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector y = vloadu_partial_zero(src_y, w); + HVX_VectorPair yy = Q6_W_vshuff_VVR(y, y, -1); + HVX_VectorPair ya = Q6_W_vshuff_VVR(a, y, -1); + HVX_VectorPair p01 = Q6_W_vshuff_VVR(Q6_V_lo_W(ya), Q6_V_lo_W(yy), -1); + HVX_VectorPair p23 = Q6_W_vshuff_VVR(Q6_V_hi_W(ya), Q6_V_hi_W(yy), -1); + int dst_bytes = w * 4; + vstoreu_partial(dst_argb, Q6_V_lo_W(p01), + dst_bytes > 128 ? 128 : dst_bytes); + if (dst_bytes > 128) { + vstoreu_partial(dst_argb + 128, Q6_V_hi_W(p01), + dst_bytes > 256 ? 128 : dst_bytes - 128); + } + if (dst_bytes > 256) { + vstoreu_partial(dst_argb + 256, Q6_V_lo_W(p23), + dst_bytes > 384 ? 128 : dst_bytes - 256); + } + if (dst_bytes > 384) { + vstoreu_partial(dst_argb + 384, Q6_V_hi_W(p23), dst_bytes - 384); + } + src_y += 128; + dst_argb += 512; + width -= 128; + } +} + +void I400ToARGBRow_HVX(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uint16_t yg = (uint16_t)yuvconstants->kYToRgb[0]; + int16_t yb = yuvconstants->kYBiasToRgb[0]; + uint32_t yg32 = ((uint32_t)yg << 16) | yg; + HVX_Vector v_yb = Q6_Vh_vsplat_R(yb); + HVX_Vector a = Q6_Vb_vsplat_R(0xff); + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector y = vloadu_partial_zero(src_y, w); + HVX_Vector y_even_0101 = Q6_Vb_vshuffe_VbVb(y, y); + HVX_Vector y_odd_0101 = Q6_Vb_vshuffo_VbVb(y, y); + HVX_VectorPair p_even = Q6_Wuw_vmpy_VuhRuh(y_even_0101, yg32); + HVX_VectorPair p_odd = Q6_Wuw_vmpy_VuhRuh(y_odd_0101, yg32); + HVX_Vector y_lo = Q6_Vh_vasr_VhR( + Q6_Vh_vadd_VhVh( + Q6_Vh_vshuffo_VhVh(Q6_V_hi_W(p_even), Q6_V_lo_W(p_even)), v_yb), + 6); + HVX_Vector y_hi = Q6_Vh_vasr_VhR( + Q6_Vh_vadd_VhVh(Q6_Vh_vshuffo_VhVh(Q6_V_hi_W(p_odd), Q6_V_lo_W(p_odd)), + v_yb), + 6); + HVX_Vector y_out = Q6_Vub_vsat_VhVh(y_hi, y_lo); + HVX_VectorPair yy = Q6_W_vshuff_VVR(y_out, y_out, -1); + HVX_VectorPair ya = Q6_W_vshuff_VVR(a, y_out, -1); + HVX_VectorPair p01 = Q6_W_vshuff_VVR(Q6_V_lo_W(ya), Q6_V_lo_W(yy), -1); + HVX_VectorPair p23 = Q6_W_vshuff_VVR(Q6_V_hi_W(ya), Q6_V_hi_W(yy), -1); + int dst_bytes = w * 4; + vstoreu_partial(dst_argb, Q6_V_lo_W(p01), + dst_bytes > 128 ? 128 : dst_bytes); + if (dst_bytes > 128) { + vstoreu_partial(dst_argb + 128, Q6_V_hi_W(p01), + dst_bytes > 256 ? 128 : dst_bytes - 128); + } + if (dst_bytes > 256) { + vstoreu_partial(dst_argb + 256, Q6_V_lo_W(p23), + dst_bytes > 384 ? 128 : dst_bytes - 256); + } + if (dst_bytes > 384) { + vstoreu_partial(dst_argb + 384, Q6_V_hi_W(p23), dst_bytes - 384); + } + src_y += 128; + dst_argb += 512; + width -= 128; + } +} + +void ARGBToABGRRow_HVX(const uint8_t* src_argb, uint8_t* dst_abgr, int width) { + HVX_Vector ctrl = Q6_V_vsplat_R(0x00020002); + int bytes = width * 4; + while (bytes >= 128) { + vstoreu(dst_abgr, Q6_V_vdelta_VV(vloadu(src_argb), ctrl)); + src_argb += 128; + dst_abgr += 128; + bytes -= 128; + } + if (bytes > 0) { + vstoreu_partial(dst_abgr, + Q6_V_vdelta_VV(vloadu_partial_zero(src_argb, bytes), ctrl), + bytes); + } +} + +void ARGBToBGRARow_HVX(const uint8_t* src_argb, uint8_t* dst_bgra, int width) { + HVX_Vector ctrl = Q6_Vb_vsplat_R(0x03); + int bytes = width * 4; + while (bytes >= 128) { + vstoreu(dst_bgra, Q6_V_vdelta_VV(vloadu(src_argb), ctrl)); + src_argb += 128; + dst_bgra += 128; + bytes -= 128; + } + if (bytes > 0) { + vstoreu_partial(dst_bgra, + Q6_V_vdelta_VV(vloadu_partial_zero(src_argb, bytes), ctrl), + bytes); + } +} + +void ARGBToRGBARow_HVX(const uint8_t* src_argb, uint8_t* dst_rgba, int width) { + int bytes = width * 4; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + HVX_Vector v = vloadu_partial_zero(src_argb, b_cnt); + HVX_Vector out = Q6_V_vor_VV(Q6_Vw_vasl_VwR(v, 8), Q6_Vuw_vlsr_VuwR(v, 24)); + vstoreu_partial(dst_rgba, out, b_cnt); + src_argb += 128; + dst_rgba += 128; + bytes -= 128; + } +} + +void RGBAToARGBRow_HVX(const uint8_t* src_rgba, uint8_t* dst_argb, int width) { + int bytes = width * 4; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + HVX_Vector v = vloadu_partial_zero(src_rgba, b_cnt); + HVX_Vector out = Q6_V_vor_VV(Q6_Vuw_vlsr_VuwR(v, 8), Q6_Vw_vasl_VwR(v, 24)); + vstoreu_partial(dst_argb, out, b_cnt); + src_rgba += 128; + dst_argb += 128; + bytes -= 128; + } +} + +void ARGBToAR64Row_HVX(const uint8_t* src_argb, uint16_t* dst_ar64, int width) { + Convert8To16Row_HVX(src_argb, dst_ar64, 16, width * 4); +} + +void ARGBToAB64Row_HVX(const uint8_t* src_argb, uint16_t* dst_ab64, int width) { + HVX_Vector ctrl = Q6_V_vsplat_R(0x00020002); + int bytes = width * 4; + uint8_t* dst = (uint8_t*)dst_ab64; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + HVX_Vector v = Q6_V_vdelta_VV(vloadu_partial_zero(src_argb, b_cnt), ctrl); + HVX_VectorPair d16 = Q6_W_vshuff_VVR(v, v, -1); + int dst_bytes = b_cnt * 2; + vstoreu_partial(dst, Q6_V_lo_W(d16), dst_bytes > 128 ? 128 : dst_bytes); + if (dst_bytes > 128) { + vstoreu_partial(dst + 128, Q6_V_hi_W(d16), dst_bytes - 128); + } + src_argb += 128; + dst += 256; + bytes -= 128; + } +} + +void AR64ToARGBRow_HVX(const uint16_t* src_ar64, uint8_t* dst_argb, int width) { + int bytes = width * 4; + const uint8_t* src = (const uint8_t*)src_ar64; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + int src_bytes = b_cnt * 2; + HVX_Vector s0 = vloadu_partial_zero(src, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src + 128, src_bytes - 128) + : Q6_V_vzero(); + vstoreu_partial(dst_argb, Q6_Vb_vpacko_VhVh(s1, s0), b_cnt); + src += 256; + dst_argb += 128; + bytes -= 128; + } +} + +void AB64ToARGBRow_HVX(const uint16_t* src_ab64, uint8_t* dst_argb, int width) { + HVX_Vector ctrl = Q6_V_vsplat_R(0x00020002); + int bytes = width * 4; + const uint8_t* src = (const uint8_t*)src_ab64; + while (bytes > 0) { + int b_cnt = bytes >= 128 ? 128 : bytes; + int src_bytes = b_cnt * 2; + HVX_Vector s0 = vloadu_partial_zero(src, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector out = Q6_V_vdelta_VV(Q6_Vb_vpacko_VhVh(s1, s0), ctrl); + vstoreu_partial(dst_argb, out, b_cnt); + src += 256; + dst_argb += 128; + bytes -= 128; + } +} + +void AR64ToAB64Row_HVX(const uint16_t* src_ar64, + uint16_t* dst_ab64, + int width) { + HVX_Vector ctrl = Q6_V_vsplat_R(0x00000404); + int bytes = width * 8; + const uint8_t* src = (const uint8_t*)src_ar64; + uint8_t* dst = (uint8_t*)dst_ab64; + while (bytes >= 128) { + vstoreu(dst, Q6_V_vdelta_VV(vloadu(src), ctrl)); + src += 128; + dst += 128; + bytes -= 128; + } + if (bytes > 0) { + vstoreu_partial(dst, Q6_V_vdelta_VV(vloadu_partial_zero(src, bytes), ctrl), + bytes); + } +} + +static __inline void YuvToRgb_HVX(HVX_Vector y, + HVX_Vector u, + HVX_Vector v, + HVX_Vector* b_out, + HVX_Vector* g_out, + HVX_Vector* r_out, + const struct YuvConstants* yuvconstants) { + uint8_t ub = yuvconstants->kUVToB[0]; + uint8_t ug = yuvconstants->kUVToG[0]; + uint8_t vg = yuvconstants->kUVToG[1]; + uint8_t vr = yuvconstants->kUVToR[1]; + uint16_t yg = (uint16_t)yuvconstants->kYToRgb[0]; + int16_t yb = yuvconstants->kYBiasToRgb[0]; + + uint32_t yg32 = ((uint32_t)yg << 16) | yg; + HVX_Vector v_yb = Q6_Vh_vsplat_R(yb); + HVX_Vector v_ub = Q6_Vb_vsplat_R(ub); + HVX_Vector v_ug = Q6_Vb_vsplat_R(ug); + HVX_Vector v_vg = Q6_Vb_vsplat_R(vg); + HVX_Vector v_vr = Q6_Vb_vsplat_R(vr); + HVX_Vector v80 = Q6_Vb_vsplat_R(0x80); + + HVX_Vector ui = Q6_Vb_vsub_VbVb(u, v80); + HVX_Vector vi = Q6_Vb_vsub_VbVb(v, v80); + + HVX_Vector y_even_0101 = Q6_Vb_vshuffe_VbVb(y, y); + HVX_Vector y_odd_0101 = Q6_Vb_vshuffo_VbVb(y, y); + HVX_VectorPair p_even = Q6_Wuw_vmpy_VuhRuh(y_even_0101, yg32); + HVX_VectorPair p_odd = Q6_Wuw_vmpy_VuhRuh(y_odd_0101, yg32); + HVX_Vector y1_lo = Q6_Vh_vadd_VhVh( + Q6_Vh_vshuffo_VhVh(Q6_V_hi_W(p_even), Q6_V_lo_W(p_even)), v_yb); + HVX_Vector y1_hi = Q6_Vh_vadd_VhVh( + Q6_Vh_vshuffo_VhVh(Q6_V_hi_W(p_odd), Q6_V_lo_W(p_odd)), v_yb); + + HVX_VectorPair b_uv = Q6_Wh_vmpy_VubVb(v_ub, ui); + HVX_Vector b_lo = + Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh_sat(y1_lo, Q6_V_lo_W(b_uv)), 6); + HVX_Vector b_hi = + Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh_sat(y1_hi, Q6_V_hi_W(b_uv)), 6); + *b_out = Q6_Vub_vsat_VhVh(b_hi, b_lo); + + HVX_VectorPair g_uv = + Q6_Wh_vmpyacc_WhVubVb(Q6_Wh_vmpy_VubVb(v_ug, ui), v_vg, vi); + HVX_Vector g_lo = + Q6_Vh_vasr_VhR(Q6_Vh_vsub_VhVh_sat(y1_lo, Q6_V_lo_W(g_uv)), 6); + HVX_Vector g_hi = + Q6_Vh_vasr_VhR(Q6_Vh_vsub_VhVh_sat(y1_hi, Q6_V_hi_W(g_uv)), 6); + *g_out = Q6_Vub_vsat_VhVh(g_hi, g_lo); + + HVX_VectorPair r_uv = Q6_Wh_vmpy_VubVb(v_vr, vi); + HVX_Vector r_lo = + Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh_sat(y1_lo, Q6_V_lo_W(r_uv)), 6); + HVX_Vector r_hi = + Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh_sat(y1_hi, Q6_V_hi_W(r_uv)), 6); + *r_out = Q6_Vub_vsat_VhVh(r_hi, r_lo); +} + +static __inline void StoreARGB_HVX(uint8_t* dst_argb, + HVX_Vector b, + HVX_Vector g, + HVX_Vector r, + HVX_Vector a, + int w) { + HVX_VectorPair br = Q6_W_vshuff_VVR(r, b, -1); + HVX_VectorPair ga = Q6_W_vshuff_VVR(a, g, -1); + HVX_VectorPair p01 = Q6_W_vshuff_VVR(Q6_V_lo_W(ga), Q6_V_lo_W(br), -1); + HVX_VectorPair p23 = Q6_W_vshuff_VVR(Q6_V_hi_W(ga), Q6_V_hi_W(br), -1); + int dst_bytes = w * 4; + vstoreu_partial(dst_argb, Q6_V_lo_W(p01), dst_bytes > 128 ? 128 : dst_bytes); + if (dst_bytes > 128) { + vstoreu_partial(dst_argb + 128, Q6_V_hi_W(p01), + dst_bytes > 256 ? 128 : dst_bytes - 128); + } + if (dst_bytes > 256) { + vstoreu_partial(dst_argb + 256, Q6_V_lo_W(p23), + dst_bytes > 384 ? 128 : dst_bytes - 256); + } + if (dst_bytes > 384) { + vstoreu_partial(dst_argb + 384, Q6_V_hi_W(p23), dst_bytes - 384); + } +} + +void I444ToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + HVX_Vector a = Q6_Vb_vsplat_R(0xff); + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector y = vloadu_partial_zero(src_y, w); + HVX_Vector u = vloadu_partial_zero(src_u, w); + HVX_Vector v = vloadu_partial_zero(src_v, w); + HVX_Vector b, g, r; + YuvToRgb_HVX(y, u, v, &b, &g, &r, yuvconstants); + StoreARGB_HVX(dst_argb, b, g, r, a, w); + src_y += 128; + src_u += 128; + src_v += 128; + dst_argb += 512; + width -= 128; + } +} + +void I444AlphaToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + while (width > 0) { + int w = width >= 128 ? 128 : width; + HVX_Vector y = vloadu_partial_zero(src_y, w); + HVX_Vector u = vloadu_partial_zero(src_u, w); + HVX_Vector v = vloadu_partial_zero(src_v, w); + HVX_Vector a = vloadu_partial_zero(src_a, w); + HVX_Vector b, g, r; + YuvToRgb_HVX(y, u, v, &b, &g, &r, yuvconstants); + StoreARGB_HVX(dst_argb, b, g, r, a, w); + src_y += 128; + src_u += 128; + src_v += 128; + src_a += 128; + dst_argb += 512; + width -= 128; + } +} + +void I422ToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + HVX_Vector a = Q6_Vb_vsplat_R(0xff); + while (width > 0) { + int w = width >= 128 ? 128 : width; + int uv_w = (w + 1) >> 1; + HVX_Vector y = vloadu_partial_zero(src_y, w); + HVX_Vector u_sub = vloadu_partial_zero(src_u, uv_w); + HVX_Vector v_sub = vloadu_partial_zero(src_v, uv_w); + HVX_Vector u = Q6_V_lo_W(Q6_W_vshuff_VVR(u_sub, u_sub, -1)); + HVX_Vector v = Q6_V_lo_W(Q6_W_vshuff_VVR(v_sub, v_sub, -1)); + HVX_Vector b, g, r; + YuvToRgb_HVX(y, u, v, &b, &g, &r, yuvconstants); + StoreARGB_HVX(dst_argb, b, g, r, a, w); + src_y += 128; + src_u += 64; + src_v += 64; + dst_argb += 512; + width -= 128; + } +} + +void I422AlphaToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + while (width > 0) { + int w = width >= 128 ? 128 : width; + int uv_w = (w + 1) >> 1; + HVX_Vector y = vloadu_partial_zero(src_y, w); + HVX_Vector u_sub = vloadu_partial_zero(src_u, uv_w); + HVX_Vector v_sub = vloadu_partial_zero(src_v, uv_w); + HVX_Vector a = vloadu_partial_zero(src_a, w); + HVX_Vector u = Q6_V_lo_W(Q6_W_vshuff_VVR(u_sub, u_sub, -1)); + HVX_Vector v = Q6_V_lo_W(Q6_W_vshuff_VVR(v_sub, v_sub, -1)); + HVX_Vector b, g, r; + YuvToRgb_HVX(y, u, v, &b, &g, &r, yuvconstants); + StoreARGB_HVX(dst_argb, b, g, r, a, w); + src_y += 128; + src_u += 64; + src_v += 64; + src_a += 128; + dst_argb += 512; + width -= 128; + } +} + +void I422ToRGBARow_HVX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width) { + HVX_Vector a = Q6_Vb_vsplat_R(0xff); + while (width > 0) { + int w = width >= 128 ? 128 : width; + int uv_w = (w + 1) >> 1; + HVX_Vector y = vloadu_partial_zero(src_y, w); + HVX_Vector u_sub = vloadu_partial_zero(src_u, uv_w); + HVX_Vector v_sub = vloadu_partial_zero(src_v, uv_w); + HVX_Vector u = Q6_V_lo_W(Q6_W_vshuff_VVR(u_sub, u_sub, -1)); + HVX_Vector v = Q6_V_lo_W(Q6_W_vshuff_VVR(v_sub, v_sub, -1)); + HVX_Vector b, g, r; + YuvToRgb_HVX(y, u, v, &b, &g, &r, yuvconstants); + StoreARGB_HVX(dst_rgba, a, b, g, r, w); + src_y += 128; + src_u += 64; + src_v += 64; + dst_rgba += 512; + width -= 128; + } +} + +void NV12ToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + HVX_Vector a = Q6_Vb_vsplat_R(0xff); + while (width > 0) { + int w = width >= 128 ? 128 : width; + int uv_bytes = ((w + 1) >> 1) * 2; + HVX_Vector y = vloadu_partial_zero(src_y, w); + HVX_Vector uv = vloadu_partial_zero(src_uv, uv_bytes); + HVX_VectorPair u_v = Q6_W_vdeal_VVR(uv, uv, -1); + HVX_Vector u_sub = Q6_V_lo_W(u_v); + HVX_Vector v_sub = Q6_V_hi_W(u_v); + HVX_Vector u = Q6_V_lo_W(Q6_W_vshuff_VVR(u_sub, u_sub, -1)); + HVX_Vector v = Q6_V_lo_W(Q6_W_vshuff_VVR(v_sub, v_sub, -1)); + HVX_Vector b, g, r; + YuvToRgb_HVX(y, u, v, &b, &g, &r, yuvconstants); + StoreARGB_HVX(dst_argb, b, g, r, a, w); + src_y += 128; + src_uv += 128; + dst_argb += 512; + width -= 128; + } +} + +void NV21ToARGBRow_HVX(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + HVX_Vector a = Q6_Vb_vsplat_R(0xff); + while (width > 0) { + int w = width >= 128 ? 128 : width; + int uv_bytes = ((w + 1) >> 1) * 2; + HVX_Vector y = vloadu_partial_zero(src_y, w); + HVX_Vector vu = vloadu_partial_zero(src_vu, uv_bytes); + HVX_VectorPair v_u = Q6_W_vdeal_VVR(vu, vu, -1); + HVX_Vector v_sub = Q6_V_lo_W(v_u); + HVX_Vector u_sub = Q6_V_hi_W(v_u); + HVX_Vector u = Q6_V_lo_W(Q6_W_vshuff_VVR(u_sub, u_sub, -1)); + HVX_Vector v = Q6_V_lo_W(Q6_W_vshuff_VVR(v_sub, v_sub, -1)); + HVX_Vector b, g, r; + YuvToRgb_HVX(y, u, v, &b, &g, &r, yuvconstants); + StoreARGB_HVX(dst_argb, b, g, r, a, w); + src_y += 128; + src_vu += 128; + dst_argb += 512; + width -= 128; + } +} + +void ARGBToYMatrixRow_HVX(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + uint32_t coeff_y; + memcpy(&coeff_y, c->kRGBToY, sizeof(coeff_y)); + HVX_Vector v_add_y = Q6_V_vsplat_R((uint32_t)c->kAddY[0]); + while (width > 0) { + int w = width >= 128 ? 128 : width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_argb, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = + src_bytes > 128 + ? vloadu_partial_zero(src_argb + 128, + src_bytes > 256 ? 128 : src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector s2 = + src_bytes > 256 + ? vloadu_partial_zero(src_argb + 256, + src_bytes > 384 ? 128 : src_bytes - 256) + : Q6_V_vzero(); + HVX_Vector s3 = src_bytes > 384 + ? vloadu_partial_zero(src_argb + 384, src_bytes - 384) + : Q6_V_vzero(); + HVX_Vector y0 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vadd_VwVw(Q6_Vuw_vrmpy_VubRub(s0, coeff_y), v_add_y), 8); + HVX_Vector y1 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vadd_VwVw(Q6_Vuw_vrmpy_VubRub(s1, coeff_y), v_add_y), 8); + HVX_Vector y2 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vadd_VwVw(Q6_Vuw_vrmpy_VubRub(s2, coeff_y), v_add_y), 8); + HVX_Vector y3 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vadd_VwVw(Q6_Vuw_vrmpy_VubRub(s3, coeff_y), v_add_y), 8); + HVX_Vector y01 = Q6_Vh_vpacke_VwVw(y1, y0); + HVX_Vector y23 = Q6_Vh_vpacke_VwVw(y3, y2); + HVX_Vector out = Q6_Vb_vpacke_VhVh(y23, y01); + vstoreu_partial(dst_y, out, w); + src_argb += 512; + dst_y += 128; + width -= 128; + } +} + +void ARGBToUV444MatrixRow_HVX(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + int32_t coeff_u; + int32_t coeff_v; + memcpy(&coeff_u, c->kRGBToU, sizeof(coeff_u)); + memcpy(&coeff_v, c->kRGBToV, sizeof(coeff_v)); + HVX_Vector v_add_uv = Q6_V_vsplat_R((uint32_t)c->kAddUV[0]); + while (width > 0) { + int w = width >= 128 ? 128 : width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_argb, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = + src_bytes > 128 + ? vloadu_partial_zero(src_argb + 128, + src_bytes > 256 ? 128 : src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector s2 = + src_bytes > 256 + ? vloadu_partial_zero(src_argb + 256, + src_bytes > 384 ? 128 : src_bytes - 256) + : Q6_V_vzero(); + HVX_Vector s3 = src_bytes > 384 + ? vloadu_partial_zero(src_argb + 384, src_bytes - 384) + : Q6_V_vzero(); + + HVX_Vector u0 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(s0, coeff_u)), 8); + HVX_Vector u1 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(s1, coeff_u)), 8); + HVX_Vector u2 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(s2, coeff_u)), 8); + HVX_Vector u3 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(s3, coeff_u)), 8); + HVX_Vector u_out = + Q6_Vb_vpacke_VhVh(Q6_Vh_vpacke_VwVw(u3, u2), Q6_Vh_vpacke_VwVw(u1, u0)); + vstoreu_partial(dst_u, u_out, w); + + HVX_Vector v0 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(s0, coeff_v)), 8); + HVX_Vector v1 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(s1, coeff_v)), 8); + HVX_Vector v2 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(s2, coeff_v)), 8); + HVX_Vector v3 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(s3, coeff_v)), 8); + HVX_Vector v_out = + Q6_Vb_vpacke_VhVh(Q6_Vh_vpacke_VwVw(v3, v2), Q6_Vh_vpacke_VwVw(v1, v0)); + vstoreu_partial(dst_v, v_out, w); + + src_argb += 512; + dst_u += 128; + dst_v += 128; + width -= 128; + } +} + +void ARGBToUVMatrixRow_HVX(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + int32_t coeff_u; + int32_t coeff_v; + memcpy(&coeff_u, c->kRGBToU, sizeof(coeff_u)); + memcpy(&coeff_v, c->kRGBToV, sizeof(coeff_v)); + HVX_Vector v_add_uv = Q6_V_vsplat_R((uint32_t)c->kAddUV[0]); + HVX_Vector vtwo = Q6_Vh_vsplat_R(2); + const uint8_t* src_argb1 = src_argb + src_stride_argb; + + int even_width = width & ~1; + while (even_width > 0) { + int w = even_width >= 64 ? 64 : even_width; + int uv_w = w >> 1; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_argb, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_argb + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector t0 = + vloadu_partial_zero(src_argb1, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector t1 = src_bytes > 128 + ? vloadu_partial_zero(src_argb1 + 128, src_bytes - 128) + : Q6_V_vzero(); + + HVX_VectorPair ds = Q6_W_vdeal_VVR(s1, s0, -4); + HVX_VectorPair dt = Q6_W_vdeal_VVR(t1, t0, -4); + HVX_VectorPair s_even = Q6_Wuh_vunpack_Vub(Q6_V_lo_W(ds)); + HVX_VectorPair s_odd = Q6_Wuh_vunpack_Vub(Q6_V_hi_W(ds)); + HVX_VectorPair t_even = Q6_Wuh_vunpack_Vub(Q6_V_lo_W(dt)); + HVX_VectorPair t_odd = Q6_Wuh_vunpack_Vub(Q6_V_hi_W(dt)); + + HVX_Vector sum_lo = Q6_Vh_vadd_VhVh(Q6_V_lo_W(s_even), Q6_V_lo_W(s_odd)); + sum_lo = Q6_Vh_vadd_VhVh(sum_lo, Q6_V_lo_W(t_even)); + sum_lo = Q6_Vh_vadd_VhVh(sum_lo, Q6_V_lo_W(t_odd)); + sum_lo = Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh(sum_lo, vtwo), 2); + + HVX_Vector sum_hi = Q6_Vh_vadd_VhVh(Q6_V_hi_W(s_even), Q6_V_hi_W(s_odd)); + sum_hi = Q6_Vh_vadd_VhVh(sum_hi, Q6_V_hi_W(t_even)); + sum_hi = Q6_Vh_vadd_VhVh(sum_hi, Q6_V_hi_W(t_odd)); + sum_hi = Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh(sum_hi, vtwo), 2); + + HVX_Vector avg = Q6_Vub_vpack_VhVh_sat(sum_hi, sum_lo); + HVX_Vector u0 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(avg, coeff_u)), 8); + HVX_Vector v0 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(avg, coeff_v)), 8); + HVX_Vector u_out = + Q6_Vb_vpacke_VhVh(Q6_V_vzero(), Q6_Vh_vpacke_VwVw(Q6_V_vzero(), u0)); + HVX_Vector v_out = + Q6_Vb_vpacke_VhVh(Q6_V_vzero(), Q6_Vh_vpacke_VwVw(Q6_V_vzero(), v0)); + vstoreu_partial(dst_u, u_out, uv_w); + vstoreu_partial(dst_v, v_out, uv_w); + + src_argb += w * 4; + src_argb1 += w * 4; + dst_u += uv_w; + dst_v += uv_w; + even_width -= w; + } + if (width & 1) { + HVX_Vector s0 = vloadu_partial_zero(src_argb, 4); + HVX_Vector t0 = vloadu_partial_zero(src_argb1, 4); + HVX_Vector avg = Q6_Vub_vavg_VubVub_rnd(s0, t0); + HVX_Vector u0 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(avg, coeff_u)), 8); + HVX_Vector v0 = Q6_Vuw_vlsr_VuwR( + Q6_Vw_vsub_VwVw(v_add_uv, Q6_Vw_vrmpy_VubRb(avg, coeff_v)), 8); + vstoreu_partial(dst_u, u0, 1); + vstoreu_partial(dst_v, v0, 1); + } +} + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) diff --git a/libs/libyuv/source/row_lasx.cc b/libs/libyuv/source/row_lasx.cc new file mode 100644 index 0000000000..12d267ad23 --- /dev/null +++ b/libs/libyuv/source/row_lasx.cc @@ -0,0 +1,3558 @@ +/* + * Copyright 2022 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/compare_row.h" +#include "libyuv/row.h" +#include "libyuv/video_common.h" + +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + +#if !defined(LIBYUV_DISABLE_LASX) && defined(__loongarch_asx) + +#include "libyuv/basic_types.h" + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +void CopyRow_LASX(const uint8_t* src, uint8_t* dst, int count) { + asm volatile( + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src), [dst] "+r"(dst), [cnt] "+r"(count) + : + : "memory", "$xr0"); +} + +void SetRow_LASX(uint8_t* dst, uint8_t v8, int count) { + asm volatile( + "xvreplgr2vr.b $xr0, %[val]\n\t" + "1:\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [dst] "+r"(dst), [cnt] "+r"(count) + : [val] "r"(v8) + : "memory", "$xr0"); +} + +void ARGBSetRow_LASX(uint8_t* dst_argb, uint32_t v32, int width) { + asm volatile( + "xvreplgr2vr.w $xr0, %[val]\n\t" + "1:\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [val] "r"(v32) + : "memory", "$xr0"); +} + +void MirrorRow_LASX(const uint8_t* src_y, uint8_t* dst_y, int width) { + static const uint8_t kRev[16] = {15, 14, 13, 12, 11, 10, 9, 8, + 7, 6, 5, 4, 3, 2, 1, 0}; + src_y += width - 32; + asm volatile( + "vld $vr1, %[rev], 0\n\t" + "xvpermi.q $xr1, $xr1, 0x00\n\t" + "1:\n\t" + "vld $vr0, %[src], 16\n\t" + "vld $vr31, %[src], 0\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "xvshuf.b $xr0, $xr0, $xr0, $xr1\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[src], %[src], -32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_y), [dst] "+r"(dst_y), [cnt] "+r"(width) + : [rev] "r"(kRev) + : "memory", "$xr0", "$xr1", "$xr31"); +} + +void MirrorUVRow_LASX(const uint8_t* src_uv, uint8_t* dst_uv, int width) { + static const uint8_t kRevUV[16] = {14, 15, 12, 13, 10, 11, 8, 9, + 6, 7, 4, 5, 2, 3, 0, 1}; + src_uv += width * 2 - 32; + asm volatile( + "vld $vr1, %[rev], 0\n\t" + "xvpermi.q $xr1, $xr1, 0x00\n\t" + "1:\n\t" + "vld $vr0, %[src], 16\n\t" + "vld $vr31, %[src], 0\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "xvshuf.b $xr0, $xr0, $xr0, $xr1\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[src], %[src], -32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_uv), [dst] "+r"(dst_uv), [cnt] "+r"(width) + : [rev] "r"(kRevUV) + : "memory", "$xr0", "$xr1", "$xr31"); +} + +void ARGBMirrorRow_LASX(const uint8_t* src_argb, uint8_t* dst_argb, int width) { + src_argb += width * 4 - 32; + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 16\n\t" + "vld $vr31, %[src], 0\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "xvshuf4i.w $xr0, $xr0, 0x1b\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[src], %[src], -32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr31"); +} + +void MirrorSplitUVRow_LASX(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kRevUV[16] = {14, 15, 12, 13, 10, 11, 8, 9, + 6, 7, 4, 5, 2, 3, 0, 1}; + src_uv += width * 2 - 64; + asm volatile( + "vld $vr4, %[rev], 0\n\t" + "xvpermi.q $xr4, $xr4, 0x00\n\t" + "1:\n\t" + "vld $vr0, %[src], 48\n\t" + "vld $vr31, %[src], 16\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 32\n\t" + "vld $vr31, %[src], 0\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvshuf.b $xr0, $xr0, $xr0, $xr4\n\t" + "xvshuf.b $xr1, $xr1, $xr1, $xr4\n\t" + "xvpickev.b $xr2, $xr1, $xr0\n\t" + "xvpickod.b $xr3, $xr1, $xr0\n\t" + "xvst $xr2, %[du], 0\n\t" + "xvst $xr3, %[dv], 0\n\t" + "addi.d %[src], %[src], -64\n\t" + "addi.d %[du], %[du], 32\n\t" + "addi.d %[dv], %[dv], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : + [src] "+r"(src_uv), [du] "+r"(dst_u), [dv] "+r"(dst_v), [cnt] "+r"(width) + : [rev] "r"(kRevUV) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr31"); +} + +void SplitUVRow_LASX(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvpickev.b $xr2, $xr1, $xr0\n\t" + "xvpickod.b $xr3, $xr1, $xr0\n\t" + "xvst $xr2, %[du], 0\n\t" + "xvst $xr3, %[dv], 0\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[du], %[du], 32\n\t" + "addi.d %[dv], %[dv], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : + [src] "+r"(src_uv), [du] "+r"(dst_u), [dv] "+r"(dst_v), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr31"); +} + +void MergeUVRow_LASX(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width) { + asm volatile( + "1:\n\t" + "xvld $xr0, %[su], 0\n\t" + "xvld $xr1, %[sv], 0\n\t" + "xvilvl.b $xr2, $xr1, $xr0\n\t" + "xvilvh.b $xr3, $xr1, $xr0\n\t" + "vst $vr2, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr2, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr3, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr3, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[su], %[su], 32\n\t" + "addi.d %[sv], %[sv], 32\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : + [su] "+r"(src_u), [sv] "+r"(src_v), [dst] "+r"(dst_uv), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr31"); +} + +void ARGBExtractAlphaRow_LASX(const uint8_t* src_argb, + uint8_t* dst_a, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvpickod.b $xr0, $xr1, $xr0\n\t" + "xvpickod.b $xr0, $xr0, $xr0\n\t" + "xvpermi.d $xr31, $xr0, 0xd8\n\t" + "vst $vr31, %[dst], 0\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_a), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr31"); +} + +void I422ToYUY2Row_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_yuy2, + int width) { + asm volatile( + "1:\n\t" + "xvld $xr0, %[sy], 0\n\t" + "vld $vr1, %[su], 0\n\t" + "xvpermi.d $xr1, $xr1, 0xd8\n\t" + "vld $vr2, %[sv], 0\n\t" + "xvpermi.d $xr2, $xr2, 0xd8\n\t" + "xvilvl.b $xr3, $xr2, $xr1\n\t" + "xvilvl.b $xr4, $xr3, $xr0\n\t" + "xvilvh.b $xr5, $xr3, $xr0\n\t" + "vst $vr4, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr4, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr5, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr5, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sy], %[sy], 32\n\t" + "addi.d %[su], %[su], 16\n\t" + "addi.d %[sv], %[sv], 16\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_yuy2), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr31"); +} + +void I422ToUYVYRow_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uyvy, + int width) { + asm volatile( + "1:\n\t" + "xvld $xr0, %[sy], 0\n\t" + "vld $vr1, %[su], 0\n\t" + "xvpermi.d $xr1, $xr1, 0xd8\n\t" + "vld $vr2, %[sv], 0\n\t" + "xvpermi.d $xr2, $xr2, 0xd8\n\t" + "xvilvl.b $xr3, $xr2, $xr1\n\t" + "xvilvl.b $xr4, $xr0, $xr3\n\t" + "xvilvh.b $xr5, $xr0, $xr3\n\t" + "vst $vr4, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr4, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr5, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr5, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sy], %[sy], 32\n\t" + "addi.d %[su], %[su], 16\n\t" + "addi.d %[sv], %[sv], 16\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_uyvy), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr31"); +} + +void YUY2ToYRow_LASX(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvpickev.b $xr2, $xr1, $xr0\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_yuy2), [dst] "+r"(dst_y), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr31"); +} + +void UYVYToYRow_LASX(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvpickod.b $xr2, $xr1, $xr0\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_uyvy), [dst] "+r"(dst_y), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr31"); +} + +void YUY2ToUV422Row_LASX(const uint8_t* src_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvpickod.b $xr2, $xr1, $xr0\n\t" + "xvpickev.b $xr3, $xr2, $xr2\n\t" + "xvpickod.b $xr4, $xr2, $xr2\n\t" + "xvpermi.d $xr31, $xr3, 0xd8\n\t" + "vst $vr31, %[du], 0\n\t" + "xvpermi.d $xr31, $xr4, 0xd8\n\t" + "vst $vr31, %[dv], 0\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[du], %[du], 16\n\t" + "addi.d %[dv], %[dv], 16\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_yuy2), [du] "+r"(dst_u), [dv] "+r"(dst_v), + [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr31"); +} + +void UYVYToUV422Row_LASX(const uint8_t* src_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvpickev.b $xr2, $xr1, $xr0\n\t" + "xvpickev.b $xr3, $xr2, $xr2\n\t" + "xvpickod.b $xr4, $xr2, $xr2\n\t" + "xvpermi.d $xr31, $xr3, 0xd8\n\t" + "vst $vr31, %[du], 0\n\t" + "xvpermi.d $xr31, $xr4, 0xd8\n\t" + "vst $vr31, %[dv], 0\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[du], %[du], 16\n\t" + "addi.d %[dv], %[dv], 16\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_uyvy), [du] "+r"(dst_u), [dv] "+r"(dst_v), + [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr31"); +} + +void YUY2ToUVRow_LASX(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* next_yuy2 = src_yuy2 + src_stride_yuy2; + asm volatile( + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr31, %[s0], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[s0], 16\n\t" + "vld $vr31, %[s0], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "vld $vr2, %[s1], 0\n\t" + "vld $vr31, %[s1], 32\n\t" + "xvpermi.q $xr2, $xr31, 0x02\n\t" + "vld $vr3, %[s1], 16\n\t" + "vld $vr31, %[s1], 48\n\t" + "xvpermi.q $xr3, $xr31, 0x02\n\t" + "xvpickod.b $xr0, $xr1, $xr0\n\t" + "xvpickod.b $xr2, $xr3, $xr2\n\t" + "xvavgr.bu $xr0, $xr0, $xr2\n\t" + "xvpickev.b $xr1, $xr0, $xr0\n\t" + "xvpickod.b $xr2, $xr0, $xr0\n\t" + "xvpermi.d $xr31, $xr1, 0xd8\n\t" + "vst $vr31, %[du], 0\n\t" + "xvpermi.d $xr31, $xr2, 0xd8\n\t" + "vst $vr31, %[dv], 0\n\t" + "addi.d %[s0], %[s0], 64\n\t" + "addi.d %[s1], %[s1], 64\n\t" + "addi.d %[du], %[du], 16\n\t" + "addi.d %[dv], %[dv], 16\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_yuy2), [s1] "+r"(next_yuy2), [du] "+r"(dst_u), + [dv] "+r"(dst_v), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr31"); +} + +void UYVYToUVRow_LASX(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* next_uyvy = src_uyvy + src_stride_uyvy; + asm volatile( + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr31, %[s0], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[s0], 16\n\t" + "vld $vr31, %[s0], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "vld $vr2, %[s1], 0\n\t" + "vld $vr31, %[s1], 32\n\t" + "xvpermi.q $xr2, $xr31, 0x02\n\t" + "vld $vr3, %[s1], 16\n\t" + "vld $vr31, %[s1], 48\n\t" + "xvpermi.q $xr3, $xr31, 0x02\n\t" + "xvpickev.b $xr0, $xr1, $xr0\n\t" + "xvpickev.b $xr2, $xr3, $xr2\n\t" + "xvavgr.bu $xr0, $xr0, $xr2\n\t" + "xvpickev.b $xr1, $xr0, $xr0\n\t" + "xvpickod.b $xr2, $xr0, $xr0\n\t" + "xvpermi.d $xr31, $xr1, 0xd8\n\t" + "vst $vr31, %[du], 0\n\t" + "xvpermi.d $xr31, $xr2, 0xd8\n\t" + "vst $vr31, %[dv], 0\n\t" + "addi.d %[s0], %[s0], 64\n\t" + "addi.d %[s1], %[s1], 64\n\t" + "addi.d %[du], %[du], 16\n\t" + "addi.d %[dv], %[dv], 16\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_uyvy), [s1] "+r"(next_uyvy), [du] "+r"(dst_u), + [dv] "+r"(dst_v), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr31"); +} + +void I422ToARGBRow_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "xvldi $xr5, 0xff\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "xvldrepl.d $xr10, %[su], 0\n\t" + "xvshuf4i.w $xr31, $xr10, 0x01\n\t" + "xvpermi.q $xr10, $xr31, 0x02\n\t" + "xvldrepl.d $xr11, %[sv], 0\n\t" + "xvshuf4i.w $xr31, $xr11, 0x01\n\t" + "xvpermi.q $xr11, $xr31, 0x02\n\t" + "xvilvl.b $xr10, $xr10, $xr10\n\t" + "xvilvl.b $xr11, $xr11, $xr11\n\t" + "xvilvl.b $xr1, $xr11, $xr10\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvilvl.b $xr6, $xr3, $xr2\n\t" + "xvilvl.b $xr7, $xr5, $xr4\n\t" + "xvilvl.h $xr8, $xr7, $xr6\n\t" + "xvilvh.h $xr9, $xr7, $xr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr8, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr9, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr9, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[su], %[su], 8\n\t" + "addi.d %[sv], %[sv], 8\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr20", "$xr21", "$xr22", + "$xr23", "$xr24", "$xr31"); +} + +void I422ToRGBARow_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "xvldi $xr5, 0xff\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "xvldrepl.d $xr10, %[su], 0\n\t" + "xvshuf4i.w $xr31, $xr10, 0x01\n\t" + "xvpermi.q $xr10, $xr31, 0x02\n\t" + "xvldrepl.d $xr11, %[sv], 0\n\t" + "xvshuf4i.w $xr31, $xr11, 0x01\n\t" + "xvpermi.q $xr11, $xr31, 0x02\n\t" + "xvilvl.b $xr10, $xr10, $xr10\n\t" + "xvilvl.b $xr11, $xr11, $xr11\n\t" + "xvilvl.b $xr1, $xr11, $xr10\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvilvl.b $xr6, $xr2, $xr5\n\t" + "xvilvl.b $xr7, $xr4, $xr3\n\t" + "xvilvl.h $xr8, $xr7, $xr6\n\t" + "xvilvh.h $xr9, $xr7, $xr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr8, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr9, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr9, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[su], %[su], 8\n\t" + "addi.d %[sv], %[sv], 8\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr20", "$xr21", "$xr22", + "$xr23", "$xr24", "$xr31"); +} + +void I422AlphaToARGBRow_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "xvldrepl.d $xr10, %[su], 0\n\t" + "xvshuf4i.w $xr31, $xr10, 0x01\n\t" + "xvpermi.q $xr10, $xr31, 0x02\n\t" + "xvldrepl.d $xr11, %[sv], 0\n\t" + "xvshuf4i.w $xr31, $xr11, 0x01\n\t" + "xvpermi.q $xr11, $xr31, 0x02\n\t" + "xvilvl.b $xr10, $xr10, $xr10\n\t" + "xvilvl.b $xr11, $xr11, $xr11\n\t" + "xvilvl.b $xr1, $xr11, $xr10\n\t" + "vld $vr5, %[sa], 0\n\t" + "xvpermi.d $xr5, $xr5, 0xd8\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvilvl.b $xr6, $xr3, $xr2\n\t" + "xvilvl.b $xr7, $xr5, $xr4\n\t" + "xvilvl.h $xr8, $xr7, $xr6\n\t" + "xvilvh.h $xr9, $xr7, $xr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr8, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr9, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr9, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[su], %[su], 8\n\t" + "addi.d %[sv], %[sv], 8\n\t" + "addi.d %[sa], %[sa], 16\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width), [sa] "+r"(src_a) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr20", "$xr21", "$xr22", + "$xr23", "$xr24", "$xr31"); +} + +void I422ToRGB24Row_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + static const uint8_t kShuf0[16] = {0, 1, 2, 4, 5, 6, 8, 9, + 10, 12, 13, 14, 16, 17, 18, 20}; + static const uint8_t kShuf1[16] = {21, 22, 24, 25, 26, 28, 29, 30, + 0, 0, 0, 0, 0, 0, 0, 0}; + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "vld $vr12, %[s0], 0\n\t" + "xvpermi.q $xr12, $xr12, 0x00\n\t" + "vld $vr13, %[s1], 0\n\t" + "xvpermi.q $xr13, $xr13, 0x00\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "xvldrepl.d $xr10, %[su], 0\n\t" + "xvshuf4i.w $xr31, $xr10, 0x01\n\t" + "xvpermi.q $xr10, $xr31, 0x02\n\t" + "xvldrepl.d $xr11, %[sv], 0\n\t" + "xvshuf4i.w $xr31, $xr11, 0x01\n\t" + "xvpermi.q $xr11, $xr31, 0x02\n\t" + "xvilvl.b $xr10, $xr10, $xr10\n\t" + "xvilvl.b $xr11, $xr11, $xr11\n\t" + "xvilvl.b $xr1, $xr11, $xr10\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvilvl.b $xr6, $xr3, $xr2\n\t" + "xvilvl.b $xr7, $xr4, $xr4\n\t" + "xvilvl.h $xr8, $xr7, $xr6\n\t" + "xvilvh.h $xr9, $xr7, $xr6\n\t" + "xvshuf.b $xr10, $xr9, $xr8, $xr12\n\t" + "xvshuf.b $xr11, $xr9, $xr8, $xr13\n\t" + "vst $vr10, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr10, 0x01\n\t" + "vst $vr31, %[dst], 24\n\t" + "vstelm.d $vr11, %[dst], 16, 0\n\t" + "xvpermi.q $xr31, $xr11, 0x01\n\t" + "vstelm.d $vr31, %[dst], 40, 0\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[su], %[su], 8\n\t" + "addi.d %[sv], %[sv], 8\n\t" + "addi.d %[dst], %[dst], 48\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants), [s0] "r"(kShuf0), [s1] "r"(kShuf1) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr6", "$xr7", + "$xr8", "$xr9", "$xr10", "$xr11", "$xr12", "$xr13", "$xr20", "$xr21", + "$xr22", "$xr23", "$xr24", "$xr31"); +} + +void I422ToRGB565Row_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "xvldi $xr14, 31\n\t" + "xvsrli.h $xr14, $xr14, 8\n\t" + "xvldi $xr15, 63\n\t" + "xvsrli.h $xr15, $xr15, 8\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "xvldrepl.d $xr10, %[su], 0\n\t" + "xvshuf4i.w $xr31, $xr10, 0x01\n\t" + "xvpermi.q $xr10, $xr31, 0x02\n\t" + "xvldrepl.d $xr11, %[sv], 0\n\t" + "xvshuf4i.w $xr31, $xr11, 0x01\n\t" + "xvpermi.q $xr11, $xr31, 0x02\n\t" + "xvilvl.b $xr10, $xr10, $xr10\n\t" + "xvilvl.b $xr11, $xr11, $xr11\n\t" + "xvilvl.b $xr1, $xr11, $xr10\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvsrli.b $xr2, $xr2, 3\n\t" + "xvsrli.b $xr3, $xr3, 2\n\t" + "xvsrli.b $xr4, $xr4, 3\n\t" + "xvilvl.b $xr2, $xr2, $xr2\n\t" + "xvilvl.b $xr3, $xr3, $xr3\n\t" + "xvilvl.b $xr4, $xr4, $xr4\n\t" + "xvand.v $xr2, $xr2, $xr14\n\t" + "xvand.v $xr3, $xr3, $xr15\n\t" + "xvand.v $xr4, $xr4, $xr14\n\t" + "xvslli.h $xr3, $xr3, 5\n\t" + "xvslli.h $xr4, $xr4, 11\n\t" + "xvor.v $xr2, $xr2, $xr3\n\t" + "xvor.v $xr2, $xr2, $xr4\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[su], %[su], 8\n\t" + "addi.d %[sv], %[sv], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr10", "$xr11", + "$xr14", "$xr15", "$xr20", "$xr21", "$xr22", "$xr23", "$xr24", "$xr31"); +} + +void I422ToARGB4444Row_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "xvldi $xr14, 15\n\t" + "xvsrli.h $xr14, $xr14, 8\n\t" + "xvldi $xr15, 240\n\t" + "xvsrli.h $xr15, $xr15, 8\n\t" + "xvslli.h $xr15, $xr15, 8\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "xvldrepl.d $xr10, %[su], 0\n\t" + "xvshuf4i.w $xr31, $xr10, 0x01\n\t" + "xvpermi.q $xr10, $xr31, 0x02\n\t" + "xvldrepl.d $xr11, %[sv], 0\n\t" + "xvshuf4i.w $xr31, $xr11, 0x01\n\t" + "xvpermi.q $xr11, $xr31, 0x02\n\t" + "xvilvl.b $xr10, $xr10, $xr10\n\t" + "xvilvl.b $xr11, $xr11, $xr11\n\t" + "xvilvl.b $xr1, $xr11, $xr10\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvsrli.b $xr2, $xr2, 4\n\t" + "xvsrli.b $xr3, $xr3, 4\n\t" + "xvsrli.b $xr4, $xr4, 4\n\t" + "xvilvl.b $xr2, $xr2, $xr2\n\t" + "xvilvl.b $xr3, $xr3, $xr3\n\t" + "xvilvl.b $xr4, $xr4, $xr4\n\t" + "xvand.v $xr2, $xr2, $xr14\n\t" + "xvand.v $xr3, $xr3, $xr14\n\t" + "xvand.v $xr4, $xr4, $xr14\n\t" + "xvslli.h $xr3, $xr3, 4\n\t" + "xvslli.h $xr4, $xr4, 8\n\t" + "xvor.v $xr2, $xr2, $xr3\n\t" + "xvor.v $xr2, $xr2, $xr4\n\t" + "xvor.v $xr2, $xr2, $xr15\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[su], %[su], 8\n\t" + "addi.d %[sv], %[sv], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr10", "$xr11", + "$xr14", "$xr15", "$xr20", "$xr21", "$xr22", "$xr23", "$xr24", "$xr31"); +} + +void I422ToARGB1555Row_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "xvldi $xr14, 31\n\t" + "xvsrli.h $xr14, $xr14, 8\n\t" + "xvldi $xr15, 128\n\t" + "xvsrli.h $xr15, $xr15, 8\n\t" + "xvslli.h $xr15, $xr15, 8\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "xvldrepl.d $xr10, %[su], 0\n\t" + "xvshuf4i.w $xr31, $xr10, 0x01\n\t" + "xvpermi.q $xr10, $xr31, 0x02\n\t" + "xvldrepl.d $xr11, %[sv], 0\n\t" + "xvshuf4i.w $xr31, $xr11, 0x01\n\t" + "xvpermi.q $xr11, $xr31, 0x02\n\t" + "xvilvl.b $xr10, $xr10, $xr10\n\t" + "xvilvl.b $xr11, $xr11, $xr11\n\t" + "xvilvl.b $xr1, $xr11, $xr10\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvsrli.b $xr2, $xr2, 3\n\t" + "xvsrli.b $xr3, $xr3, 3\n\t" + "xvsrli.b $xr4, $xr4, 3\n\t" + "xvilvl.b $xr2, $xr2, $xr2\n\t" + "xvilvl.b $xr3, $xr3, $xr3\n\t" + "xvilvl.b $xr4, $xr4, $xr4\n\t" + "xvand.v $xr2, $xr2, $xr14\n\t" + "xvand.v $xr3, $xr3, $xr14\n\t" + "xvand.v $xr4, $xr4, $xr14\n\t" + "xvslli.h $xr3, $xr3, 5\n\t" + "xvslli.h $xr4, $xr4, 10\n\t" + "xvor.v $xr2, $xr2, $xr3\n\t" + "xvor.v $xr2, $xr2, $xr4\n\t" + "xvor.v $xr2, $xr2, $xr15\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[su], %[su], 8\n\t" + "addi.d %[sv], %[sv], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr10", "$xr11", + "$xr14", "$xr15", "$xr20", "$xr21", "$xr22", "$xr23", "$xr24", "$xr31"); +} + +void NV12ToARGBRow_LASX(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "xvldi $xr5, 0xff\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "vld $vr1, %[suv], 0\n\t" + "xvpermi.d $xr1, $xr1, 0xd8\n\t" + "xvilvl.h $xr1, $xr1, $xr1\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvilvl.b $xr6, $xr3, $xr2\n\t" + "xvilvl.b $xr7, $xr5, $xr4\n\t" + "xvilvl.h $xr8, $xr7, $xr6\n\t" + "xvilvh.h $xr9, $xr7, $xr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr8, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr9, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr9, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[suv], %[suv], 16\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [suv] "+r"(src_uv), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr20", "$xr21", "$xr22", "$xr23", "$xr24", + "$xr31"); +} + +void NV21ToARGBRow_LASX(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "xvldi $xr5, 0xff\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "vld $vr1, %[suv], 0\n\t" + "xvpermi.d $xr1, $xr1, 0xd8\n\t" + "xvshuf4i.b $xr1, $xr1, 0xb1\n\t" + "xvilvl.h $xr1, $xr1, $xr1\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvilvl.b $xr6, $xr3, $xr2\n\t" + "xvilvl.b $xr7, $xr5, $xr4\n\t" + "xvilvl.h $xr8, $xr7, $xr6\n\t" + "xvilvh.h $xr9, $xr7, $xr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr8, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr9, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr9, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[suv], %[suv], 16\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [suv] "+r"(src_vu), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr20", "$xr21", "$xr22", "$xr23", "$xr24", + "$xr31"); +} + +void NV12ToRGB565Row_LASX(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "xvldi $xr14, 31\n\t" + "xvsrli.h $xr14, $xr14, 8\n\t" + "xvldi $xr15, 63\n\t" + "xvsrli.h $xr15, $xr15, 8\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "vld $vr1, %[suv], 0\n\t" + "xvpermi.d $xr1, $xr1, 0xd8\n\t" + "xvilvl.h $xr1, $xr1, $xr1\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvsrli.b $xr2, $xr2, 3\n\t" + "xvsrli.b $xr3, $xr3, 2\n\t" + "xvsrli.b $xr4, $xr4, 3\n\t" + "xvilvl.b $xr2, $xr2, $xr2\n\t" + "xvilvl.b $xr3, $xr3, $xr3\n\t" + "xvilvl.b $xr4, $xr4, $xr4\n\t" + "xvand.v $xr2, $xr2, $xr14\n\t" + "xvand.v $xr3, $xr3, $xr15\n\t" + "xvand.v $xr4, $xr4, $xr14\n\t" + "xvslli.h $xr3, $xr3, 5\n\t" + "xvslli.h $xr4, $xr4, 11\n\t" + "xvor.v $xr2, $xr2, $xr3\n\t" + "xvor.v $xr2, $xr2, $xr4\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[suv], %[suv], 16\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [suv] "+r"(src_uv), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr14", "$xr15", + "$xr20", "$xr21", "$xr22", "$xr23", "$xr24"); +} + +void I444ToARGBRow_LASX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "xvldi $xr5, 0xff\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "vld $vr10, %[su], 0\n\t" + "xvpermi.d $xr10, $xr10, 0xd8\n\t" + "vld $vr11, %[sv], 0\n\t" + "xvpermi.d $xr11, $xr11, 0xd8\n\t" + "xvilvl.b $xr1, $xr11, $xr10\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvilvl.b $xr6, $xr3, $xr2\n\t" + "xvilvl.b $xr7, $xr5, $xr4\n\t" + "xvilvl.h $xr8, $xr7, $xr6\n\t" + "xvilvh.h $xr9, $xr7, $xr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr8, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr9, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr9, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[su], %[su], 16\n\t" + "addi.d %[sv], %[sv], 16\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr20", "$xr21", "$xr22", + "$xr23", "$xr24", "$xr31"); +} + +void I400ToARGBRow_LASX(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vld $vr23, %[c], 96\n\t" + "xvpermi.q $xr23, $xr23, 0x00\n\t" + "vld $vr24, %[c], 128\n\t" + "xvpermi.q $xr24, $xr24, 0x00\n\t" + "xvldi $xr5, 0xff\n\t" + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvssrani.bu.h $xr2, $xr0, 6\n\t" + "xvilvl.b $xr6, $xr2, $xr2\n\t" + "xvilvl.b $xr7, $xr5, $xr2\n\t" + "xvilvl.h $xr8, $xr7, $xr6\n\t" + "xvilvh.h $xr9, $xr7, $xr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr8, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr9, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr9, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr2", "$xr5", "$xr6", "$xr7", "$xr8", "$xr9", + "$xr23", "$xr24", "$xr31"); +} + +void J400ToARGBRow_LASX(const uint8_t* src_y, uint8_t* dst_argb, int width) { + asm volatile( + "xvldi $xr5, 0xff\n\t" + "1:\n\t" + "vld $vr2, %[sy], 0\n\t" + "xvpermi.d $xr2, $xr2, 0xd8\n\t" + "xvilvl.b $xr6, $xr2, $xr2\n\t" + "xvilvl.b $xr7, $xr5, $xr2\n\t" + "xvilvl.h $xr8, $xr7, $xr6\n\t" + "xvilvh.h $xr9, $xr7, $xr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr8, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr9, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr9, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$xr2", "$xr5", "$xr6", "$xr7", "$xr8", "$xr9", "$xr31"); +} + +void YUY2ToARGBRow_LASX(const uint8_t* src_yuy2, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "xvldi $xr5, 0xff\n\t" + "1:\n\t" + "xvld $xr10, %[src], 0\n\t" + "xvpickev.b $xr0, $xr10, $xr10\n\t" + "xvpickod.b $xr1, $xr10, $xr10\n\t" + "xvilvl.h $xr1, $xr1, $xr1\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvilvl.b $xr6, $xr3, $xr2\n\t" + "xvilvl.b $xr7, $xr5, $xr4\n\t" + "xvilvl.h $xr8, $xr7, $xr6\n\t" + "xvilvh.h $xr9, $xr7, $xr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr8, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr9, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr9, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_yuy2), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr20", "$xr21", "$xr22", "$xr23", + "$xr24", "$xr31"); +} + +void UYVYToARGBRow_LASX(const uint8_t* src_uyvy, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "xvldrepl.w $xr20, %[c], 0\n\t" + "xvldrepl.w $xr21, %[c], 32\n\t" + "xvldrepl.w $xr22, %[c], 64\n\t" + "xvldrepl.h $xr23, %[c], 96\n\t" + "xvldrepl.h $xr24, %[c], 128\n\t" + "xvldi $xr5, 0xff\n\t" + "1:\n\t" + "xvld $xr10, %[src], 0\n\t" + "xvpickod.b $xr0, $xr10, $xr10\n\t" + "xvpickev.b $xr1, $xr10, $xr10\n\t" + "xvilvl.h $xr1, $xr1, $xr1\n\t" + "xvilvl.b $xr0, $xr0, $xr0\n\t" + "xvxori.b $xr1, $xr1, 0x80\n\t" + "xvmuh.hu $xr0, $xr0, $xr23\n\t" + "xvadd.h $xr0, $xr0, $xr24\n\t" + "xvmulwev.h.bu.b $xr2, $xr20, $xr1\n\t" + "xvmulwod.h.bu.b $xr4, $xr22, $xr1\n\t" + "xvmulwev.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvmaddwod.h.bu.b $xr3, $xr21, $xr1\n\t" + "xvsadd.h $xr2, $xr0, $xr2\n\t" + "xvsadd.h $xr4, $xr0, $xr4\n\t" + "xvssub.h $xr3, $xr0, $xr3\n\t" + "xvssrani.bu.h $xr2, $xr2, 6\n\t" + "xvssrani.bu.h $xr3, $xr3, 6\n\t" + "xvssrani.bu.h $xr4, $xr4, 6\n\t" + "xvilvl.b $xr6, $xr3, $xr2\n\t" + "xvilvl.b $xr7, $xr5, $xr4\n\t" + "xvilvl.h $xr8, $xr7, $xr6\n\t" + "xvilvh.h $xr9, $xr7, $xr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr8, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr9, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr9, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_uyvy), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr20", "$xr21", "$xr22", "$xr23", + "$xr24", "$xr31"); +} + +static LIBYUV_NOINLINE void ARGBTo24Helper_LASX(const uint8_t* src_argb, + uint8_t* dst_24, + const uint8_t* shuf, + int width) { + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "xvpermi.q $xr4, $xr4, 0x00\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 64\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr31, %[src], 80\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "vld $vr2, %[src], 32\n\t" + "vld $vr31, %[src], 96\n\t" + "xvpermi.q $xr2, $xr31, 0x02\n\t" + "vld $vr3, %[src], 48\n\t" + "vld $vr31, %[src], 112\n\t" + "xvpermi.q $xr3, $xr31, 0x02\n\t" + "xvshuf.b $xr0, $xr0, $xr0, $xr4\n\t" + "xvshuf.b $xr1, $xr1, $xr1, $xr4\n\t" + "xvshuf.b $xr2, $xr2, $xr2, $xr4\n\t" + "xvshuf.b $xr3, $xr3, $xr3, $xr4\n\t" + "vstelm.d $vr0, %[dst], 0, 0\n\t" + "xvpermi.q $xr31, $xr0, 0x01\n\t" + "vstelm.d $vr31, %[dst], 48, 0\n\t" + "vstelm.w $vr0, %[dst], 8, 2\n\t" + "xvpermi.q $xr31, $xr0, 0x01\n\t" + "vstelm.w $vr31, %[dst], 56, 2\n\t" + "vstelm.w $vr1, %[dst], 12, 0\n\t" + "vstelm.w $vr1, %[dst], 16, 1\n\t" + "xvpermi.q $xr31, $xr1, 0x01\n\t" + "vstelm.w $vr31, %[dst], 60, 0\n\t" + "vstelm.w $vr31, %[dst], 64, 1\n\t" + "vstelm.w $vr1, %[dst], 20, 2\n\t" + "xvpermi.q $xr31, $xr1, 0x01\n\t" + "vstelm.w $vr31, %[dst], 68, 2\n\t" + "vstelm.d $vr2, %[dst], 24, 0\n\t" + "xvpermi.q $xr31, $xr2, 0x01\n\t" + "vstelm.d $vr31, %[dst], 72, 0\n\t" + "vstelm.w $vr2, %[dst], 32, 2\n\t" + "xvpermi.q $xr31, $xr2, 0x01\n\t" + "vstelm.w $vr31, %[dst], 80, 2\n\t" + "vstelm.w $vr3, %[dst], 36, 0\n\t" + "vstelm.w $vr3, %[dst], 40, 1\n\t" + "xvpermi.q $xr31, $xr3, 0x01\n\t" + "vstelm.w $vr31, %[dst], 84, 0\n\t" + "vstelm.w $vr31, %[dst], 88, 1\n\t" + "vstelm.w $vr3, %[dst], 44, 2\n\t" + "xvpermi.q $xr31, $xr3, 0x01\n\t" + "vstelm.w $vr31, %[dst], 92, 2\n\t" + "addi.d %[src], %[src], 128\n\t" + "addi.d %[dst], %[dst], 96\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_24), [cnt] "+r"(width) + : [shuf] "r"(shuf) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr31"); +} + +void ARGBToRGB24Row_LASX(const uint8_t* src_argb, + uint8_t* dst_rgb24, + int width) { + static const uint8_t kShuf[16] = {0, 1, 2, 4, 5, 6, 8, 9, + 10, 12, 13, 14, 0, 0, 0, 0}; + ARGBTo24Helper_LASX(src_argb, dst_rgb24, kShuf, width); +} + +void ARGBToRAWRow_LASX(const uint8_t* src_argb, uint8_t* dst_raw, int width) { + static const uint8_t kShuf[16] = {2, 1, 0, 6, 5, 4, 10, 9, + 8, 14, 13, 12, 0, 0, 0, 0}; + ARGBTo24Helper_LASX(src_argb, dst_raw, kShuf, width); +} + +static LIBYUV_NOINLINE void RGB24ToARGBHelper_LASX(const uint8_t* src_24, + uint8_t* dst_argb, + const uint8_t* shuf, + int width) { + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "xvpermi.q $xr4, $xr4, 0x00\n\t" + "vld $vr5, %[shuf], 16\n\t" + "xvpermi.q $xr5, $xr5, 0x00\n\t" + "xvldi $xr6, 0xff\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 12\n\t" + "vld $vr31, %[src], 60\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "vld $vr2, %[src], 24\n\t" + "vld $vr31, %[src], 72\n\t" + "xvpermi.q $xr2, $xr31, 0x02\n\t" + "vld $vr3, %[src], 32\n\t" + "vld $vr31, %[src], 80\n\t" + "xvpermi.q $xr3, $xr31, 0x02\n\t" + "xvshuf.b $xr0, $xr6, $xr0, $xr4\n\t" + "xvshuf.b $xr1, $xr6, $xr1, $xr4\n\t" + "xvshuf.b $xr2, $xr6, $xr2, $xr4\n\t" + "xvshuf.b $xr3, $xr6, $xr3, $xr5\n\t" + "vst $vr0, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr0, 0x01\n\t" + "vst $vr31, %[dst], 64\n\t" + "vst $vr1, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr1, 0x01\n\t" + "vst $vr31, %[dst], 80\n\t" + "vst $vr2, %[dst], 32\n\t" + "xvpermi.q $xr31, $xr2, 0x01\n\t" + "vst $vr31, %[dst], 96\n\t" + "vst $vr3, %[dst], 48\n\t" + "xvpermi.q $xr31, $xr3, 0x01\n\t" + "vst $vr31, %[dst], 112\n\t" + "addi.d %[src], %[src], 96\n\t" + "addi.d %[dst], %[dst], 128\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_24), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [shuf] "r"(shuf) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr31"); +} + +void RGB24ToARGBRow_LASX(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width) { + static const uint8_t kShuf[32] = {0, 1, 2, 16, 3, 4, 5, 16, 6, 7, 8, + 16, 9, 10, 11, 16, 4, 5, 6, 16, 7, 8, + 9, 16, 10, 11, 12, 16, 13, 14, 15, 16}; + RGB24ToARGBHelper_LASX(src_rgb24, dst_argb, kShuf, width); +} + +void RAWToARGBRow_LASX(const uint8_t* src_raw, uint8_t* dst_argb, int width) { + static const uint8_t kShuf[32] = {2, 1, 0, 16, 5, 4, 3, 16, 8, 7, 6, + 16, 11, 10, 9, 16, 6, 5, 4, 16, 9, 8, + 7, 16, 12, 11, 10, 16, 15, 14, 13, 16}; + RGB24ToARGBHelper_LASX(src_raw, dst_argb, kShuf, width); +} + +void RAWToRGB24Row_LASX(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { + static const uint8_t kShuf[32] = {2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, + 9, 0, 0, 0, 0, 6, 5, 4, 9, 8, 7, + 12, 11, 10, 15, 14, 13, 0, 0, 0, 0}; + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "xvpermi.q $xr4, $xr4, 0x00\n\t" + "vld $vr5, %[shuf], 16\n\t" + "xvpermi.q $xr5, $xr5, 0x00\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 12\n\t" + "vld $vr31, %[src], 60\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "vld $vr2, %[src], 24\n\t" + "vld $vr31, %[src], 72\n\t" + "xvpermi.q $xr2, $xr31, 0x02\n\t" + "vld $vr3, %[src], 32\n\t" + "vld $vr31, %[src], 80\n\t" + "xvpermi.q $xr3, $xr31, 0x02\n\t" + "xvshuf.b $xr0, $xr0, $xr0, $xr4\n\t" + "xvshuf.b $xr1, $xr1, $xr1, $xr4\n\t" + "xvshuf.b $xr2, $xr2, $xr2, $xr4\n\t" + "xvshuf.b $xr3, $xr3, $xr3, $xr5\n\t" + "vstelm.d $vr0, %[dst], 0, 0\n\t" + "xvpermi.q $xr31, $xr0, 0x01\n\t" + "vstelm.d $vr31, %[dst], 48, 0\n\t" + "vstelm.w $vr0, %[dst], 8, 2\n\t" + "xvpermi.q $xr31, $xr0, 0x01\n\t" + "vstelm.w $vr31, %[dst], 56, 2\n\t" + "vstelm.w $vr1, %[dst], 12, 0\n\t" + "vstelm.w $vr1, %[dst], 16, 1\n\t" + "xvpermi.q $xr31, $xr1, 0x01\n\t" + "vstelm.w $vr31, %[dst], 60, 0\n\t" + "vstelm.w $vr31, %[dst], 64, 1\n\t" + "vstelm.w $vr1, %[dst], 20, 2\n\t" + "xvpermi.q $xr31, $xr1, 0x01\n\t" + "vstelm.w $vr31, %[dst], 68, 2\n\t" + "vstelm.d $vr2, %[dst], 24, 0\n\t" + "xvpermi.q $xr31, $xr2, 0x01\n\t" + "vstelm.d $vr31, %[dst], 72, 0\n\t" + "vstelm.w $vr2, %[dst], 32, 2\n\t" + "xvpermi.q $xr31, $xr2, 0x01\n\t" + "vstelm.w $vr31, %[dst], 80, 2\n\t" + "vstelm.w $vr3, %[dst], 36, 0\n\t" + "vstelm.w $vr3, %[dst], 40, 1\n\t" + "xvpermi.q $xr31, $xr3, 0x01\n\t" + "vstelm.w $vr31, %[dst], 84, 0\n\t" + "vstelm.w $vr31, %[dst], 88, 1\n\t" + "vstelm.w $vr3, %[dst], 44, 2\n\t" + "xvpermi.q $xr31, $xr3, 0x01\n\t" + "vstelm.w $vr31, %[dst], 92, 2\n\t" + "addi.d %[src], %[src], 96\n\t" + "addi.d %[dst], %[dst], 96\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_raw), [dst] "+r"(dst_rgb24), [cnt] "+r"(width) + : [shuf] "r"(kShuf) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr31"); +} + +void ARGBToRGB565Row_LASX(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width) { + asm volatile( + "xvldi $xr6, 31\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "xvldi $xr7, 63\n\t" + "xvsrli.h $xr7, $xr7, 8\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvpickev.b $xr2, $xr1, $xr0\n\t" + "xvpickod.b $xr3, $xr1, $xr0\n\t" + "xvsrli.b $xr2, $xr2, 3\n\t" + "xvsrli.b $xr3, $xr3, 2\n\t" + "xvand.v $xr4, $xr2, $xr6\n\t" + "xvsrli.h $xr2, $xr2, 8\n\t" + "xvand.v $xr3, $xr3, $xr7\n\t" + "xvslli.h $xr3, $xr3, 5\n\t" + "xvslli.h $xr2, $xr2, 11\n\t" + "xvor.v $xr4, $xr4, $xr3\n\t" + "xvor.v $xr4, $xr4, $xr2\n\t" + "xvst $xr4, %[dst], 0\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_rgb), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr6", "$xr7", + "$xr31"); +} + +void ARGBToRGB565DitherRow_LASX(const uint8_t* src_argb, + uint8_t* dst_rgb, + uint32_t dither4, + int width) { + asm volatile( + "xvreplgr2vr.w $xr5, %[dith]\n\t" + "xvilvl.b $xr5, $xr5, $xr5\n\t" + "xvilvl.h $xr5, $xr5, $xr5\n\t" + "xvldi $xr6, 31\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "xvldi $xr7, 63\n\t" + "xvsrli.h $xr7, $xr7, 8\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvsadd.bu $xr0, $xr0, $xr5\n\t" + "xvpickev.b $xr2, $xr0, $xr0\n\t" + "xvpickod.b $xr3, $xr0, $xr0\n\t" + "xvsrli.b $xr2, $xr2, 3\n\t" + "xvsrli.b $xr3, $xr3, 2\n\t" + "xvand.v $xr4, $xr2, $xr6\n\t" + "xvsrli.h $xr2, $xr2, 8\n\t" + "xvand.v $xr3, $xr3, $xr7\n\t" + "xvslli.h $xr3, $xr3, 5\n\t" + "xvslli.h $xr2, $xr2, 11\n\t" + "xvor.v $xr4, $xr4, $xr3\n\t" + "xvor.v $xr4, $xr4, $xr2\n\t" + "xvpermi.d $xr31, $xr4, 0xd8\n\t" + "vst $vr31, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_rgb), [cnt] "+r"(width) + : [dith] "r"(dither4) + : "memory", "$xr0", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", "$xr7", + "$xr31"); +} + +void ARGBToARGB1555Row_LASX(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width) { + asm volatile( + "xvldi $xr6, 31\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvpickev.b $xr2, $xr1, $xr0\n\t" + "xvpickod.b $xr3, $xr1, $xr0\n\t" + "xvsrli.b $xr2, $xr2, 3\n\t" + "xvand.v $xr4, $xr2, $xr6\n\t" + "xvsrli.h $xr2, $xr2, 8\n\t" + "xvsrli.h $xr5, $xr3, 15\n\t" + "xvsrli.b $xr3, $xr3, 3\n\t" + "xvand.v $xr3, $xr3, $xr6\n\t" + "xvslli.h $xr3, $xr3, 5\n\t" + "xvslli.h $xr2, $xr2, 10\n\t" + "xvslli.h $xr5, $xr5, 15\n\t" + "xvor.v $xr4, $xr4, $xr3\n\t" + "xvor.v $xr4, $xr4, $xr2\n\t" + "xvor.v $xr4, $xr4, $xr5\n\t" + "xvst $xr4, %[dst], 0\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_rgb), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr31"); +} + +void ARGBToARGB4444Row_LASX(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvpickev.b $xr2, $xr1, $xr0\n\t" + "xvpickod.b $xr3, $xr1, $xr0\n\t" + "xvsrli.b $xr2, $xr2, 4\n\t" + "xvsrli.b $xr3, $xr3, 4\n\t" + "xvslli.b $xr3, $xr3, 4\n\t" + "xvor.v $xr2, $xr2, $xr3\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_rgb), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr31"); +} + +void RGB565ToARGBRow_LASX(const uint8_t* src_rgb565, + uint8_t* dst_argb, + int width) { + asm volatile( + "xvldi $xr6, 31\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "xvldi $xr7, 63\n\t" + "xvsrli.h $xr7, $xr7, 8\n\t" + "xvldi $xr5, 0xff\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr7\n\t" + "xvsrli.h $xr3, $xr0, 11\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 2\n\t" + "xvsrli.h $xr2, $xr2, 4\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvpickev.b $xr1, $xr1, $xr1\n\t" + "xvpickev.b $xr2, $xr2, $xr2\n\t" + "xvpickev.b $xr3, $xr3, $xr3\n\t" + "xvilvl.b $xr8, $xr2, $xr1\n\t" + "xvilvl.b $xr9, $xr5, $xr3\n\t" + "xvilvl.h $xr10, $xr9, $xr8\n\t" + "xvilvh.h $xr11, $xr9, $xr8\n\t" + "vst $vr10, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr10, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr11, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr11, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_rgb565), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr31"); +} + +void ARGB1555ToARGBRow_LASX(const uint8_t* src_argb1555, + uint8_t* dst_argb, + int width) { + asm volatile( + "xvldi $xr6, 31\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr6\n\t" + "xvsrli.h $xr3, $xr0, 10\n\t" + "xvand.v $xr3, $xr3, $xr6\n\t" + "xvsrai.h $xr5, $xr0, 15\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 3\n\t" + "xvsrli.h $xr2, $xr2, 2\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvpickev.b $xr1, $xr1, $xr1\n\t" + "xvpickev.b $xr2, $xr2, $xr2\n\t" + "xvpickev.b $xr3, $xr3, $xr3\n\t" + "xvpickev.b $xr5, $xr5, $xr5\n\t" + "xvilvl.b $xr8, $xr2, $xr1\n\t" + "xvilvl.b $xr9, $xr5, $xr3\n\t" + "xvilvl.h $xr10, $xr9, $xr8\n\t" + "xvilvh.h $xr11, $xr9, $xr8\n\t" + "vst $vr10, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr10, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr11, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr11, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb1555), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr8", "$xr9", "$xr10", "$xr11", "$xr31"); +} + +void ARGB4444ToARGBRow_LASX(const uint8_t* src_argb4444, + uint8_t* dst_argb, + int width) { + asm volatile( + "xvldi $xr6, 0x0f\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.b $xr2, $xr0, 4\n\t" + "xvslli.b $xr3, $xr1, 4\n\t" + "xvor.v $xr1, $xr1, $xr3\n\t" + "xvslli.b $xr3, $xr2, 4\n\t" + "xvor.v $xr2, $xr2, $xr3\n\t" + "xvilvl.b $xr4, $xr2, $xr1\n\t" + "xvilvh.b $xr5, $xr2, $xr1\n\t" + "vst $vr4, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr4, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr5, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr5, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb4444), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr31"); +} + +void ARGBMultiplyRow_LASX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + asm volatile( + "1:\n\t" + "xvld $xr0, %[s0], 0\n\t" + "xvld $xr1, %[s1], 0\n\t" + "xvmulwev.h.bu $xr2, $xr0, $xr1\n\t" + "xvmulwod.h.bu $xr3, $xr0, $xr1\n\t" + "xvsrari.h $xr2, $xr2, 8\n\t" + "xvsrari.h $xr3, $xr3, 8\n\t" + "xvpackev.b $xr2, $xr3, $xr2\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 32\n\t" + "addi.d %[s1], %[s1], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb), [s1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3"); +} + +void ARGBAddRow_LASX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + asm volatile( + "1:\n\t" + "xvld $xr0, %[s0], 0\n\t" + "xvld $xr1, %[s1], 0\n\t" + "xvsadd.bu $xr0, $xr0, $xr1\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 32\n\t" + "addi.d %[s1], %[s1], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb), [s1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1"); +} + +void ARGBSubtractRow_LASX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + asm volatile( + "1:\n\t" + "xvld $xr0, %[s0], 0\n\t" + "xvld $xr1, %[s1], 0\n\t" + "xvssub.bu $xr0, $xr0, $xr1\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 32\n\t" + "addi.d %[s1], %[s1], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb), [s1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1"); +} + +void ARGBAttenuateRow_LASX(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + static const uint8_t kAlpha[16] = {3, 3, 3, 16, 7, 7, 7, 16, + 11, 11, 11, 16, 15, 15, 15, 16}; + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "xvpermi.q $xr4, $xr4, 0x00\n\t" + "xvldi $xr5, 0xff\n\t" + "xvldi $xr6, 255\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvshuf.b $xr1, $xr5, $xr0, $xr4\n\t" + "xvmulwev.h.bu $xr2, $xr0, $xr1\n\t" + "xvmulwod.h.bu $xr3, $xr0, $xr1\n\t" + "xvadd.h $xr2, $xr2, $xr6\n\t" + "xvadd.h $xr3, $xr3, $xr6\n\t" + "xvpackod.b $xr2, $xr3, $xr2\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [shuf] "r"(kAlpha) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6"); +} + +void ARGBBlendRow_LASX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + static const uint8_t kAlpha[16] = {3, 3, 3, 3, 7, 7, 7, 7, + 11, 11, 11, 11, 15, 15, 15, 15}; + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "xvpermi.q $xr4, $xr4, 0x00\n\t" + "xvldi $xr5, 0xff\n\t" + "xvslli.w $xr5, $xr5, 24\n\t" + "xvldi $xr6, 1\n\t" + "xvslli.h $xr6, $xr6, 8\n\t" + "xvldi $xr8, 0\n\t" + "1:\n\t" + "xvld $xr0, %[s0], 0\n\t" + "xvld $xr1, %[s1], 0\n\t" + "xvshuf.b $xr2, $xr0, $xr0, $xr4\n\t" + "xvilvl.b $xr3, $xr8, $xr2\n\t" + "xvilvh.b $xr2, $xr8, $xr2\n\t" + "xvsub.h $xr3, $xr6, $xr3\n\t" + "xvsub.h $xr2, $xr6, $xr2\n\t" + "xvilvl.b $xr7, $xr8, $xr1\n\t" + "xvilvh.b $xr1, $xr8, $xr1\n\t" + "xvmul.h $xr7, $xr7, $xr3\n\t" + "xvmul.h $xr1, $xr1, $xr2\n\t" + "xvsrlni.b.h $xr1, $xr7, 8\n\t" + "xvsadd.bu $xr0, $xr0, $xr1\n\t" + "xvor.v $xr0, $xr0, $xr5\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 32\n\t" + "addi.d %[s1], %[s1], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb0), [s1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : [shuf] "r"(kAlpha) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8"); +} + +void ARGBOrRow_LASX(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + asm volatile( + "xvreplgr2vr.w $xr1, %[val]\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvor.v $xr0, $xr0, $xr1\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [val] "r"(value) + : "memory", "$xr0", "$xr1"); +} + +void ARGBAlphaBlendRow_LASX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + static const uint8_t kShufRatio[16] = {0, 0, 0, 0, 4, 4, 4, 4, + 8, 8, 8, 8, 12, 12, 12, 12}; + asm volatile( + "vld $vr8, %[shuf], 0\n\t" + "xvpermi.q $xr8, $xr8, 0x00\n\t" + "xvldi $xr9, 1\n\t" + "xvsrli.h $xr10, $xr9, 8\n\t" + "xvldi $xr11, 0xff\n\t" + "xvsrli.w $xr11, $xr11, 8\n\t" + "xvldi $xr12, 0\n\t" + "1:\n\t" + "xvld $xr0, %[s0], 0\n\t" + "xvld $xr1, %[s1], 0\n\t" + "xvsrli.w $xr2, $xr0, 24\n\t" + "xvsrli.w $xr3, $xr1, 24\n\t" + "xvmul.h $xr4, $xr3, $xr2\n\t" + "xvadd.h $xr4, $xr4, $xr10\n\t" + "xvmuh.hu $xr4, $xr4, $xr9\n\t" + "xvsub.w $xr4, $xr2, $xr4\n\t" + "xvadd.w $xr4, $xr3, $xr4\n\t" + "xvseq.w $xr5, $xr3, $xr12\n\t" + "xvsrli.w $xr5, $xr5, 24\n\t" + "xvor.v $xr6, $xr2, $xr5\n\t" + "xvor.v $xr7, $xr4, $xr5\n\t" + "xvslli.w $xr5, $xr6, 8\n\t" + "xvsub.w $xr5, $xr5, $xr6\n\t" + "xvffint.s.wu $xr5, $xr5\n\t" + "xvffint.s.wu $xr7, $xr7\n\t" + "xvfdiv.s $xr5, $xr5, $xr7\n\t" + "xvftintrz.wu.s $xr5, $xr5\n\t" + "xvshuf.b $xr5, $xr5, $xr5, $xr8\n\t" + "xvnor.v $xr6, $xr5, $xr5\n\t" + "xvmulwev.h.bu $xr2, $xr1, $xr6\n\t" + "xvmulwod.h.bu $xr3, $xr1, $xr6\n\t" + "xvmulwev.h.bu $xr7, $xr0, $xr5\n\t" + "xvmulwod.h.bu $xr0, $xr0, $xr5\n\t" + "xvadd.h $xr2, $xr2, $xr7\n\t" + "xvadd.h $xr3, $xr3, $xr0\n\t" + "xvadd.h $xr2, $xr2, $xr10\n\t" + "xvadd.h $xr3, $xr3, $xr10\n\t" + "xvmuh.hu $xr2, $xr2, $xr9\n\t" + "xvmuh.hu $xr3, $xr3, $xr9\n\t" + "xvslli.h $xr3, $xr3, 8\n\t" + "xvor.v $xr2, $xr2, $xr3\n\t" + "xvand.v $xr2, $xr2, $xr11\n\t" + "xvslli.w $xr4, $xr4, 24\n\t" + "xvor.v $xr2, $xr2, $xr4\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 32\n\t" + "addi.d %[s1], %[s1], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb0), [s1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : [shuf] "r"(kShufRatio) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr12"); +} + +void ARGBShadeRow_LASX(const uint8_t* src_argb, + uint8_t* dst_argb, + int width, + uint32_t value) { + asm volatile( + "xvreplgr2vr.w $xr4, %[val]\n\t" + "xvilvl.b $xr5, $xr4, $xr4\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvilvl.b $xr1, $xr0, $xr0\n\t" + "xvilvh.b $xr2, $xr0, $xr0\n\t" + "xvmuh.hu $xr1, $xr1, $xr5\n\t" + "xvmuh.hu $xr2, $xr2, $xr5\n\t" + "xvsrlni.b.h $xr2, $xr1, 8\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [val] "r"(value) + : "memory", "$xr0", "$xr1", "$xr2", "$xr4", "$xr5"); +} + +void ARGBShuffleRow_LASX(const uint8_t* src_argb, + uint8_t* dst_argb, + const uint8_t* shuffler, + int width) { + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "xvpermi.q $xr4, $xr4, 0x00\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvshuf.b $xr0, $xr0, $xr0, $xr4\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [shuf] "r"(shuffler) + : "memory", "$xr0", "$xr4"); +} + +void ARGBGrayRow_LASX(const uint8_t* src_argb, uint8_t* dst_argb, int width) { + asm volatile( + "xvldi $xr4, 29\n\t" + "xvldi $xr5, 150\n\t" + "xvldi $xr6, 77\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr31, %[src], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvpickev.b $xr2, $xr1, $xr0\n\t" + "xvpickod.b $xr3, $xr1, $xr0\n\t" + "xvmulwev.h.bu $xr7, $xr2, $xr4\n\t" + "xvmaddwod.h.bu $xr7, $xr2, $xr6\n\t" + "xvmaddwev.h.bu $xr7, $xr3, $xr5\n\t" + "xvsrlri.h $xr7, $xr7, 8\n\t" + "xvsrli.h $xr3, $xr3, 8\n\t" + "xvslli.h $xr3, $xr3, 8\n\t" + "xvor.v $xr3, $xr7, $xr3\n\t" + "xvslli.h $xr8, $xr7, 8\n\t" + "xvor.v $xr7, $xr7, $xr8\n\t" + "xvilvl.h $xr0, $xr3, $xr7\n\t" + "xvilvh.h $xr1, $xr3, $xr7\n\t" + "vst $vr0, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr0, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr1, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr1, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr31"); +} + +void ARGBSepiaRow_LASX(uint8_t* dst_argb, int width) { + asm volatile( + "xvldi $xr4, 17\n\t" + "xvldi $xr5, 68\n\t" + "xvldi $xr6, 35\n\t" + "xvldi $xr7, 22\n\t" + "xvldi $xr8, 88\n\t" + "xvldi $xr9, 45\n\t" + "xvldi $xr10, 24\n\t" + "xvldi $xr11, 98\n\t" + "xvldi $xr12, 50\n\t" + "1:\n\t" + "vld $vr0, %[dst], 0\n\t" + "vld $vr31, %[dst], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "vld $vr1, %[dst], 16\n\t" + "vld $vr31, %[dst], 48\n\t" + "xvpermi.q $xr1, $xr31, 0x02\n\t" + "xvpickev.b $xr2, $xr1, $xr0\n\t" + "xvpickod.b $xr3, $xr1, $xr0\n\t" + "xvmulwev.h.bu $xr13, $xr2, $xr4\n\t" + "xvmaddwod.h.bu $xr13, $xr2, $xr6\n\t" + "xvmaddwev.h.bu $xr13, $xr3, $xr5\n\t" + "xvmulwev.h.bu $xr14, $xr2, $xr7\n\t" + "xvmaddwod.h.bu $xr14, $xr2, $xr9\n\t" + "xvmaddwev.h.bu $xr14, $xr3, $xr8\n\t" + "xvmulwev.h.bu $xr15, $xr2, $xr10\n\t" + "xvmaddwod.h.bu $xr15, $xr2, $xr12\n\t" + "xvmaddwev.h.bu $xr15, $xr3, $xr11\n\t" + "xvsrli.h $xr13, $xr13, 7\n\t" + "xvsrli.h $xr14, $xr14, 7\n\t" + "xvsrli.h $xr15, $xr15, 7\n\t" + "xvsat.hu $xr13, $xr13, 7\n\t" + "xvsat.hu $xr14, $xr14, 7\n\t" + "xvsat.hu $xr15, $xr15, 7\n\t" + "xvpickev.b $xr13, $xr13, $xr13\n\t" + "xvpickev.b $xr14, $xr14, $xr14\n\t" + "xvpickev.b $xr15, $xr15, $xr15\n\t" + "xvpickod.b $xr3, $xr3, $xr3\n\t" + "xvilvl.b $xr2, $xr14, $xr13\n\t" + "xvilvl.b $xr3, $xr3, $xr15\n\t" + "xvilvl.h $xr0, $xr3, $xr2\n\t" + "xvilvh.h $xr1, $xr3, $xr2\n\t" + "vst $vr0, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr0, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr1, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr1, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr12", "$xr13", "$xr14", + "$xr15", "$xr31"); +} + +void ARGBColorMatrixRow_LASX(const uint8_t* src_argb, + uint8_t* dst_argb, + const int8_t* matrix_argb, + int width) { + asm volatile( + "vldrepl.w $vr4, %[mat], 0\n\t" + "vldrepl.w $vr31, %[mat], 0\n\t" + "xvpermi.q $xr4, $xr31, 0x02\n\t" + "vldrepl.w $vr5, %[mat], 4\n\t" + "vldrepl.w $vr31, %[mat], 4\n\t" + "xvpermi.q $xr5, $xr31, 0x02\n\t" + "vldrepl.w $vr6, %[mat], 8\n\t" + "vldrepl.w $vr31, %[mat], 8\n\t" + "xvpermi.q $xr6, $xr31, 0x02\n\t" + "vldrepl.w $vr7, %[mat], 12\n\t" + "vldrepl.w $vr31, %[mat], 12\n\t" + "xvpermi.q $xr7, $xr31, 0x02\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvmulwev.h.bu.b $xr8, $xr0, $xr4\n\t" + "xvmaddwod.h.bu.b $xr8, $xr0, $xr4\n\t" + "xvmulwev.h.bu.b $xr9, $xr0, $xr5\n\t" + "xvmaddwod.h.bu.b $xr9, $xr0, $xr5\n\t" + "xvmulwev.h.bu.b $xr10, $xr0, $xr6\n\t" + "xvmaddwod.h.bu.b $xr10, $xr0, $xr6\n\t" + "xvmulwev.h.bu.b $xr11, $xr0, $xr7\n\t" + "xvmaddwod.h.bu.b $xr11, $xr0, $xr7\n\t" + "xvhaddw.w.h $xr8, $xr8, $xr8\n\t" + "xvhaddw.w.h $xr9, $xr9, $xr9\n\t" + "xvhaddw.w.h $xr10, $xr10, $xr10\n\t" + "xvhaddw.w.h $xr11, $xr11, $xr11\n\t" + "xvilvl.w $xr12, $xr9, $xr8\n\t" + "xvilvh.w $xr13, $xr9, $xr8\n\t" + "xvilvl.w $xr14, $xr11, $xr10\n\t" + "xvilvh.w $xr15, $xr11, $xr10\n\t" + "xvilvl.d $xr8, $xr14, $xr12\n\t" + "xvilvh.d $xr9, $xr14, $xr12\n\t" + "xvilvl.d $xr10, $xr15, $xr13\n\t" + "xvilvh.d $xr11, $xr15, $xr13\n\t" + "xvssrani.h.w $xr9, $xr8, 6\n\t" + "xvssrani.h.w $xr11, $xr10, 6\n\t" + "xvssrani.bu.h $xr11, $xr9, 0\n\t" + "xvst $xr11, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [mat] "r"(matrix_argb) + : "memory", "$xr0", "$xr4", "$xr5", "$xr6", "$xr7", "$xr8", "$xr9", + "$xr10", "$xr11", "$xr12", "$xr13", "$xr14", "$xr15", "$xr31"); +} + +void ARGBQuantizeRow_LASX(uint8_t* dst_argb, + int scale, + int interval_size, + int interval_offset, + int width) { + asm volatile( + "xvreplgr2vr.h $xr4, %[scl]\n\t" + "xvreplgr2vr.b $xr5, %[isz]\n\t" + "xvreplgr2vr.b $xr6, %[ioff]\n\t" + "xvldi $xr7, 0xff\n\t" + "xvslli.w $xr7, $xr7, 24\n\t" + "1:\n\t" + "xvld $xr0, %[dst], 0\n\t" + "xvilvl.b $xr1, $xr0, $xr0\n\t" + "xvilvh.b $xr2, $xr0, $xr0\n\t" + "xvsrli.h $xr1, $xr1, 8\n\t" + "xvsrli.h $xr2, $xr2, 8\n\t" + "xvmuh.hu $xr1, $xr1, $xr4\n\t" + "xvmuh.hu $xr2, $xr2, $xr4\n\t" + "xvsrlni.b.h $xr2, $xr1, 0\n\t" + "xvmul.b $xr2, $xr2, $xr5\n\t" + "xvadd.b $xr2, $xr2, $xr6\n\t" + "xvand.v $xr0, $xr0, $xr7\n\t" + "xvandn.v $xr2, $xr7, $xr2\n\t" + "xvor.v $xr2, $xr2, $xr0\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [scl] "r"(scale), [isz] "r"(interval_size), [ioff] "r"(interval_offset) + : "memory", "$xr0", "$xr1", "$xr2", "$xr4", "$xr5", "$xr6", "$xr7"); +} + +void SobelRow_LASX(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_argb, + int width) { + asm volatile( + "xvldi $xr4, 0xff\n\t" + "1:\n\t" + "vld $vr0, %[sx], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "vld $vr1, %[sy], 0\n\t" + "xvpermi.d $xr1, $xr1, 0xd8\n\t" + "xvsadd.bu $xr0, $xr0, $xr1\n\t" + "xvilvl.b $xr2, $xr0, $xr0\n\t" + "xvilvl.b $xr3, $xr4, $xr0\n\t" + "xvilvl.h $xr0, $xr3, $xr2\n\t" + "xvilvh.h $xr1, $xr3, $xr2\n\t" + "vst $vr0, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr0, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr1, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr1, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sx], %[sx], 16\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sx] "+r"(src_sobelx), [sy] "+r"(src_sobely), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr31"); +} + +void SobelToPlaneRow_LASX(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_y, + int width) { + asm volatile( + "1:\n\t" + "xvld $xr0, %[sx], 0\n\t" + "xvld $xr1, %[sy], 0\n\t" + "xvsadd.bu $xr0, $xr0, $xr1\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[sx], %[sx], 32\n\t" + "addi.d %[sy], %[sy], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [sx] "+r"(src_sobelx), [sy] "+r"(src_sobely), [dst] "+r"(dst_y), + [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1"); +} + +void SobelXYRow_LASX(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_argb, + int width) { + asm volatile( + "xvldi $xr4, 0xff\n\t" + "1:\n\t" + "vld $vr0, %[sx], 0\n\t" + "xvpermi.d $xr0, $xr0, 0xd8\n\t" + "vld $vr1, %[sy], 0\n\t" + "xvpermi.d $xr1, $xr1, 0xd8\n\t" + "xvsadd.bu $xr2, $xr0, $xr1\n\t" + "xvilvl.b $xr1, $xr2, $xr1\n\t" + "xvilvl.b $xr0, $xr4, $xr0\n\t" + "xvilvl.h $xr2, $xr0, $xr1\n\t" + "xvilvh.h $xr3, $xr0, $xr1\n\t" + "vst $vr2, %[dst], 0\n\t" + "xvpermi.q $xr31, $xr2, 0x01\n\t" + "vst $vr31, %[dst], 32\n\t" + "vst $vr3, %[dst], 16\n\t" + "xvpermi.q $xr31, $xr3, 0x01\n\t" + "vst $vr31, %[dst], 48\n\t" + "addi.d %[sx], %[sx], 16\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sx] "+r"(src_sobelx), [sy] "+r"(src_sobely), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr31"); +} + +void InterpolateRow_LASX(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int32_t source_y_fraction) { + int y1_fraction = source_y_fraction; + const uint8_t* src_ptr1 = src_ptr + src_stride; + if (y1_fraction == 0) { + CopyRow_LASX(src_ptr, dst_ptr, width); + return; + } + if (y1_fraction == 128) { + asm volatile( + "1:\n\t" + "xvld $xr0, %[s0], 0\n\t" + "xvld $xr1, %[s1], 0\n\t" + "xvavgr.bu $xr0, $xr0, $xr1\n\t" + "xvst $xr0, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 32\n\t" + "addi.d %[s1], %[s1], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_ptr), [s1] "+r"(src_ptr1), [dst] "+r"(dst_ptr), + [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1"); + return; + } + uint16_t y_frac = (uint16_t)((256 - y1_fraction) + (y1_fraction << 8)); + asm volatile( + "xvreplgr2vr.h $xr3, %[yf]\n\t" + "1:\n\t" + "xvld $xr0, %[s0], 0\n\t" + "xvld $xr1, %[s1], 0\n\t" + "xvilvl.b $xr2, $xr1, $xr0\n\t" + "xvilvh.b $xr4, $xr1, $xr0\n\t" + "xvmulwev.h.bu $xr0, $xr2, $xr3\n\t" + "xvmaddwod.h.bu $xr0, $xr2, $xr3\n\t" + "xvmulwev.h.bu $xr1, $xr4, $xr3\n\t" + "xvmaddwod.h.bu $xr1, $xr4, $xr3\n\t" + "xvsrarni.b.h $xr1, $xr0, 8\n\t" + "xvst $xr1, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 32\n\t" + "addi.d %[s1], %[s1], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_ptr), [s1] "+r"(src_ptr1), [dst] "+r"(dst_ptr), + [cnt] "+r"(width) + : [yf] "r"(y_frac) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4"); +} + +void HalfFloatRow_LASX(const uint16_t* src, + uint16_t* dst, + float scale, + int width) { + const float bias = 1.9259299444e-34f; // 2^-112, see HalfFloatRow_C + asm volatile( + "xvldrepl.w $xr3, %[scale], 0\n\t" + "xvldrepl.w $xr5, %[bias], 0\n\t" + "xvldi $xr4, 0\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvilvl.h $xr1, $xr4, $xr0\n\t" + "xvilvh.h $xr2, $xr4, $xr0\n\t" + "xvffint.s.wu $xr1, $xr1\n\t" + "xvffint.s.wu $xr2, $xr2\n\t" + "xvfmul.s $xr1, $xr1, $xr3\n\t" + "xvfmul.s $xr2, $xr2, $xr3\n\t" + "xvfmul.s $xr1, $xr1, $xr5\n\t" + "xvfmul.s $xr2, $xr2, $xr5\n\t" + "xvsrlni.h.w $xr2, $xr1, 13\n\t" + "xvst $xr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src), [dst] "+r"(dst), [cnt] "+r"(width) + : [scale] "r"(&scale), [bias] "r"(&bias) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5"); +} + +void ARGBToYMatrixRow_LASX(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + asm volatile( + "xvldrepl.b $xr0, %[c], 0\n\t" + "xvldrepl.b $xr1, %[c], 1\n\t" + "xvldrepl.b $xr2, %[c], 2\n\t" + "xvldrepl.b $xr3, %[c], 3\n\t" + "xvldrepl.h $xr4, %[c], 96\n\t" + "1:\n\t" + "vld $vr5, %[src], 0\n\t" + "vld $vr31, %[src], 32\n\t" + "xvpermi.q $xr5, $xr31, 0x02\n\t" + "vld $vr6, %[src], 16\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr6, $xr31, 0x02\n\t" + "xvor.v $xr9, $xr4, $xr4\n\t" + "xvpickev.b $xr7, $xr6, $xr5\n\t" + "xvpickod.b $xr8, $xr6, $xr5\n\t" + "xvmaddwev.h.bu $xr9, $xr7, $xr0\n\t" + "xvmaddwev.h.bu $xr9, $xr8, $xr1\n\t" + "xvmaddwod.h.bu $xr9, $xr7, $xr2\n\t" + "xvmaddwod.h.bu $xr9, $xr8, $xr3\n\t" + "xvpickod.b $xr9, $xr9, $xr9\n\t" + "xvpermi.d $xr31, $xr9, 0xd8\n\t" + "vst $vr31, %[dst], 0\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_y), [cnt] "+r"(width) + : [c] "r"(c) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr31"); +} + +void RGBToYMatrixRow_LASX(const uint8_t* src_rgba, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + static const uint8_t kShuf[32] = {0, 1, 2, 0, 3, 4, 5, 0, 6, 7, 8, + 0, 9, 10, 11, 0, 4, 5, 6, 0, 7, 8, + 9, 0, 10, 11, 12, 0, 13, 14, 15, 0}; + asm volatile( + "xvldrepl.b $xr0, %[c], 0\n\t" + "xvldrepl.b $xr1, %[c], 1\n\t" + "xvldrepl.b $xr2, %[c], 2\n\t" + "xvldrepl.h $xr3, %[c], 96\n\t" + "vld $vr4, %[shuf], 0\n\t" + "xvpermi.q $xr4, $xr4, 0x00\n\t" + "vld $vr5, %[shuf], 16\n\t" + "xvpermi.q $xr5, $xr5, 0x00\n\t" + "1:\n\t" + "vld $vr6, %[src], 0\n\t" + "vld $vr31, %[src], 48\n\t" + "xvpermi.q $xr6, $xr31, 0x02\n\t" + "vld $vr7, %[src], 12\n\t" + "vld $vr31, %[src], 60\n\t" + "xvpermi.q $xr7, $xr31, 0x02\n\t" + "vld $vr8, %[src], 24\n\t" + "vld $vr31, %[src], 72\n\t" + "xvpermi.q $xr8, $xr31, 0x02\n\t" + "vld $vr9, %[src], 32\n\t" + "vld $vr31, %[src], 80\n\t" + "xvpermi.q $xr9, $xr31, 0x02\n\t" + "xvshuf.b $xr6, $xr6, $xr6, $xr4\n\t" + "xvshuf.b $xr7, $xr7, $xr7, $xr4\n\t" + "xvshuf.b $xr8, $xr8, $xr8, $xr4\n\t" + "xvshuf.b $xr9, $xr9, $xr9, $xr5\n\t" + "xvor.v $xr12, $xr3, $xr3\n\t" + "xvor.v $xr13, $xr3, $xr3\n\t" + "xvpickev.b $xr10, $xr7, $xr6\n\t" + "xvpickod.b $xr11, $xr7, $xr6\n\t" + "xvmaddwev.h.bu $xr12, $xr10, $xr0\n\t" + "xvmaddwev.h.bu $xr12, $xr11, $xr1\n\t" + "xvmaddwod.h.bu $xr12, $xr10, $xr2\n\t" + "xvpickev.b $xr10, $xr9, $xr8\n\t" + "xvpickod.b $xr11, $xr9, $xr8\n\t" + "xvmaddwev.h.bu $xr13, $xr10, $xr0\n\t" + "xvmaddwev.h.bu $xr13, $xr11, $xr1\n\t" + "xvmaddwod.h.bu $xr13, $xr10, $xr2\n\t" + "xvpickod.b $xr12, $xr13, $xr12\n\t" + "xvst $xr12, %[dst], 0\n\t" + "addi.d %[src], %[src], 96\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_rgba), [dst] "+r"(dst_y), [cnt] "+r"(width) + : [c] "r"(c), [shuf] "r"(kShuf) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr12", "$xr13", "$xr31"); +} + +void RGB565ToYRow_LASX(const uint8_t* src_rgb565, uint8_t* dst_y, int width) { + asm volatile( + "xvldi $xr6, 31\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "xvldi $xr7, 63\n\t" + "xvsrli.h $xr7, $xr7, 8\n\t" + "xvldi $xr8, 25\n\t" + "xvsrli.h $xr8, $xr8, 8\n\t" + "xvldi $xr9, 129\n\t" + "xvsrli.h $xr9, $xr9, 8\n\t" + "xvldi $xr10, 66\n\t" + "xvsrli.h $xr10, $xr10, 8\n\t" + "xvldi $xr11, 33\n\t" + "xvsrli.h $xr11, $xr11, 8\n\t" + "xvslli.h $xr11, $xr11, 7\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr7\n\t" + "xvsrli.h $xr3, $xr0, 11\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 2\n\t" + "xvsrli.h $xr2, $xr2, 4\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvmul.h $xr1, $xr1, $xr8\n\t" + "xvmadd.h $xr1, $xr2, $xr9\n\t" + "xvmadd.h $xr1, $xr3, $xr10\n\t" + "xvadd.h $xr1, $xr1, $xr11\n\t" + "xvpickod.b $xr1, $xr1, $xr1\n\t" + "xvpermi.d $xr31, $xr1, 0xd8\n\t" + "vst $vr31, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_rgb565), [dst] "+r"(dst_y), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr6", "$xr7", + "$xr8", "$xr9", "$xr10", "$xr11", "$xr31"); +} + +void ARGB1555ToYRow_LASX(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width) { + asm volatile( + "xvldi $xr6, 31\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "xvldi $xr8, 25\n\t" + "xvsrli.h $xr8, $xr8, 8\n\t" + "xvldi $xr9, 129\n\t" + "xvsrli.h $xr9, $xr9, 8\n\t" + "xvldi $xr10, 66\n\t" + "xvsrli.h $xr10, $xr10, 8\n\t" + "xvldi $xr11, 33\n\t" + "xvsrli.h $xr11, $xr11, 8\n\t" + "xvslli.h $xr11, $xr11, 7\n\t" + "1:\n\t" + "xvld $xr0, %[src], 0\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr6\n\t" + "xvsrli.h $xr3, $xr0, 10\n\t" + "xvand.v $xr3, $xr3, $xr6\n\t" + "xvsrai.h $xr5, $xr0, 15\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 3\n\t" + "xvsrli.h $xr2, $xr2, 2\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvmul.h $xr1, $xr1, $xr8\n\t" + "xvmadd.h $xr1, $xr2, $xr9\n\t" + "xvmadd.h $xr1, $xr3, $xr10\n\t" + "xvadd.h $xr1, $xr1, $xr11\n\t" + "xvpickod.b $xr1, $xr1, $xr1\n\t" + "xvpermi.d $xr31, $xr1, 0xd8\n\t" + "vst $vr31, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb1555), [dst] "+r"(dst_y), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr8", "$xr9", "$xr10", "$xr11", "$xr31"); +} + +void RGB565ToUVRow_LASX(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* next_rgb565 = src_rgb565 + src_stride_rgb565; + asm volatile( + "xvldi $xr20, 112\n\t" + "xvsrli.h $xr20, $xr20, 8\n\t" + "xvldi $xr21, 74\n\t" + "xvsrli.h $xr21, $xr21, 8\n\t" + "xvldi $xr22, 38\n\t" + "xvsrli.h $xr22, $xr22, 8\n\t" + "xvldi $xr23, 94\n\t" + "xvsrli.h $xr23, $xr23, 8\n\t" + "xvldi $xr24, 18\n\t" + "xvsrli.h $xr24, $xr24, 8\n\t" + "xvldi $xr25, 128\n\t" + "xvsrli.h $xr25, $xr25, 8\n\t" + "xvslli.h $xr25, $xr25, 8\n\t" + "xvldi $xr6, 31\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "xvldi $xr7, 63\n\t" + "xvsrli.h $xr7, $xr7, 8\n\t" + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr31, %[s0], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr7\n\t" + "xvsrli.h $xr3, $xr0, 11\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 2\n\t" + "xvsrli.h $xr2, $xr2, 4\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvor.v $xr10, $xr1, $xr1\n\t" + "xvor.v $xr11, $xr2, $xr2\n\t" + "xvor.v $xr12, $xr3, $xr3\n\t" + "vld $vr0, %[s0], 16\n\t" + "vld $vr31, %[s0], 48\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr7\n\t" + "xvsrli.h $xr3, $xr0, 11\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 2\n\t" + "xvsrli.h $xr2, $xr2, 4\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvpickev.b $xr10, $xr1, $xr10\n\t" + "xvpickev.b $xr11, $xr2, $xr11\n\t" + "xvpickev.b $xr12, $xr3, $xr12\n\t" + "vld $vr0, %[s1], 0\n\t" + "vld $vr31, %[s1], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr7\n\t" + "xvsrli.h $xr3, $xr0, 11\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 2\n\t" + "xvsrli.h $xr2, $xr2, 4\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvor.v $xr13, $xr1, $xr1\n\t" + "xvor.v $xr14, $xr2, $xr2\n\t" + "xvor.v $xr15, $xr3, $xr3\n\t" + "vld $vr0, %[s1], 16\n\t" + "vld $vr31, %[s1], 48\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr7\n\t" + "xvsrli.h $xr3, $xr0, 11\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 2\n\t" + "xvsrli.h $xr2, $xr2, 4\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvpickev.b $xr5, $xr3, $xr15\n\t" + "xvpickev.b $xr4, $xr2, $xr14\n\t" + "xvpickev.b $xr3, $xr1, $xr13\n\t" + "xvor.v $xr0, $xr10, $xr10\n\t" + "xvor.v $xr1, $xr11, $xr11\n\t" + "xvor.v $xr2, $xr12, $xr12\n\t" + "xvhaddw.hu.bu $xr0, $xr0, $xr0\n\t" + "xvhaddw.hu.bu $xr3, $xr3, $xr3\n\t" + "xvadd.h $xr0, $xr0, $xr3\n\t" + "xvsrari.h $xr0, $xr0, 2\n\t" + "xvhaddw.hu.bu $xr1, $xr1, $xr1\n\t" + "xvhaddw.hu.bu $xr4, $xr4, $xr4\n\t" + "xvadd.h $xr1, $xr1, $xr4\n\t" + "xvsrari.h $xr1, $xr1, 2\n\t" + "xvhaddw.hu.bu $xr2, $xr2, $xr2\n\t" + "xvhaddw.hu.bu $xr5, $xr5, $xr5\n\t" + "xvadd.h $xr2, $xr2, $xr5\n\t" + "xvsrari.h $xr2, $xr2, 2\n\t" + "xvor.v $xr6, $xr25, $xr25\n\t" + "xvor.v $xr7, $xr25, $xr25\n\t" + "xvmadd.h $xr6, $xr0, $xr20\n\t" + "xvmsub.h $xr6, $xr1, $xr21\n\t" + "xvmsub.h $xr6, $xr2, $xr22\n\t" + "xvmadd.h $xr7, $xr2, $xr20\n\t" + "xvmsub.h $xr7, $xr1, $xr23\n\t" + "xvmsub.h $xr7, $xr0, $xr24\n\t" + "xvpickod.b $xr6, $xr7, $xr6\n\t" + "xvpermi.d $xr31, $xr6, 0xd8\n\t" + "vst $vr31, %[du], 0\n\t" + "vstelm.d $vr6, %[dv], 0, 1\n\t" + "xvpermi.q $xr31, $xr6, 0x01\n\t" + "vstelm.d $vr31, %[dv], 8, 1\n\t" + "xvldi $xr6, 31\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "xvldi $xr7, 63\n\t" + "xvsrli.h $xr7, $xr7, 8\n\t" + "addi.d %[s0], %[s0], 64\n\t" + "addi.d %[s1], %[s1], 64\n\t" + "addi.d %[du], %[du], 16\n\t" + "addi.d %[dv], %[dv], 16\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_rgb565), [s1] "+r"(next_rgb565), [du] "+r"(dst_u), + [dv] "+r"(dst_v), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr10", "$xr11", "$xr12", "$xr13", "$xr14", "$xr15", "$xr20", + "$xr21", "$xr22", "$xr23", "$xr24", "$xr25", "$xr31"); +} + +void ARGB1555ToUVRow_LASX(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* next_argb1555 = src_argb1555 + src_stride_argb1555; + asm volatile( + "xvldi $xr20, 112\n\t" + "xvsrli.h $xr20, $xr20, 8\n\t" + "xvldi $xr21, 74\n\t" + "xvsrli.h $xr21, $xr21, 8\n\t" + "xvldi $xr22, 38\n\t" + "xvsrli.h $xr22, $xr22, 8\n\t" + "xvldi $xr23, 94\n\t" + "xvsrli.h $xr23, $xr23, 8\n\t" + "xvldi $xr24, 18\n\t" + "xvsrli.h $xr24, $xr24, 8\n\t" + "xvldi $xr25, 128\n\t" + "xvsrli.h $xr25, $xr25, 8\n\t" + "xvslli.h $xr25, $xr25, 8\n\t" + "xvldi $xr6, 31\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr31, %[s0], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr6\n\t" + "xvsrli.h $xr3, $xr0, 10\n\t" + "xvand.v $xr3, $xr3, $xr6\n\t" + "xvsrai.h $xr5, $xr0, 15\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 3\n\t" + "xvsrli.h $xr2, $xr2, 2\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvor.v $xr10, $xr1, $xr1\n\t" + "xvor.v $xr11, $xr2, $xr2\n\t" + "xvor.v $xr12, $xr3, $xr3\n\t" + "vld $vr0, %[s0], 16\n\t" + "vld $vr31, %[s0], 48\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr6\n\t" + "xvsrli.h $xr3, $xr0, 10\n\t" + "xvand.v $xr3, $xr3, $xr6\n\t" + "xvsrai.h $xr5, $xr0, 15\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 3\n\t" + "xvsrli.h $xr2, $xr2, 2\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvpickev.b $xr10, $xr1, $xr10\n\t" + "xvpickev.b $xr11, $xr2, $xr11\n\t" + "xvpickev.b $xr12, $xr3, $xr12\n\t" + "vld $vr0, %[s1], 0\n\t" + "vld $vr31, %[s1], 32\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr6\n\t" + "xvsrli.h $xr3, $xr0, 10\n\t" + "xvand.v $xr3, $xr3, $xr6\n\t" + "xvsrai.h $xr5, $xr0, 15\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 3\n\t" + "xvsrli.h $xr2, $xr2, 2\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvor.v $xr13, $xr1, $xr1\n\t" + "xvor.v $xr14, $xr2, $xr2\n\t" + "xvor.v $xr15, $xr3, $xr3\n\t" + "vld $vr0, %[s1], 16\n\t" + "vld $vr31, %[s1], 48\n\t" + "xvpermi.q $xr0, $xr31, 0x02\n\t" + "xvand.v $xr1, $xr0, $xr6\n\t" + "xvsrli.h $xr2, $xr0, 5\n\t" + "xvand.v $xr2, $xr2, $xr6\n\t" + "xvsrli.h $xr3, $xr0, 10\n\t" + "xvand.v $xr3, $xr3, $xr6\n\t" + "xvsrai.h $xr5, $xr0, 15\n\t" + "xvslli.h $xr4, $xr1, 3\n\t" + "xvsrli.h $xr1, $xr1, 2\n\t" + "xvor.v $xr1, $xr4, $xr1\n\t" + "xvslli.h $xr4, $xr2, 3\n\t" + "xvsrli.h $xr2, $xr2, 2\n\t" + "xvor.v $xr2, $xr4, $xr2\n\t" + "xvslli.h $xr4, $xr3, 3\n\t" + "xvsrli.h $xr3, $xr3, 2\n\t" + "xvor.v $xr3, $xr4, $xr3\n\t" + "xvpickev.b $xr5, $xr3, $xr15\n\t" + "xvpickev.b $xr4, $xr2, $xr14\n\t" + "xvpickev.b $xr3, $xr1, $xr13\n\t" + "xvor.v $xr0, $xr10, $xr10\n\t" + "xvor.v $xr1, $xr11, $xr11\n\t" + "xvor.v $xr2, $xr12, $xr12\n\t" + "xvhaddw.hu.bu $xr0, $xr0, $xr0\n\t" + "xvhaddw.hu.bu $xr3, $xr3, $xr3\n\t" + "xvadd.h $xr0, $xr0, $xr3\n\t" + "xvsrari.h $xr0, $xr0, 2\n\t" + "xvhaddw.hu.bu $xr1, $xr1, $xr1\n\t" + "xvhaddw.hu.bu $xr4, $xr4, $xr4\n\t" + "xvadd.h $xr1, $xr1, $xr4\n\t" + "xvsrari.h $xr1, $xr1, 2\n\t" + "xvhaddw.hu.bu $xr2, $xr2, $xr2\n\t" + "xvhaddw.hu.bu $xr5, $xr5, $xr5\n\t" + "xvadd.h $xr2, $xr2, $xr5\n\t" + "xvsrari.h $xr2, $xr2, 2\n\t" + "xvor.v $xr6, $xr25, $xr25\n\t" + "xvor.v $xr7, $xr25, $xr25\n\t" + "xvmadd.h $xr6, $xr0, $xr20\n\t" + "xvmsub.h $xr6, $xr1, $xr21\n\t" + "xvmsub.h $xr6, $xr2, $xr22\n\t" + "xvmadd.h $xr7, $xr2, $xr20\n\t" + "xvmsub.h $xr7, $xr1, $xr23\n\t" + "xvmsub.h $xr7, $xr0, $xr24\n\t" + "xvpickod.b $xr6, $xr7, $xr6\n\t" + "xvpermi.d $xr31, $xr6, 0xd8\n\t" + "vst $vr31, %[du], 0\n\t" + "vstelm.d $vr6, %[dv], 0, 1\n\t" + "xvpermi.q $xr31, $xr6, 0x01\n\t" + "vstelm.d $vr31, %[dv], 8, 1\n\t" + "xvldi $xr6, 31\n\t" + "xvsrli.h $xr6, $xr6, 8\n\t" + "addi.d %[s0], %[s0], 64\n\t" + "addi.d %[s1], %[s1], 64\n\t" + "addi.d %[du], %[du], 16\n\t" + "addi.d %[dv], %[dv], 16\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb1555), [s1] "+r"(next_argb1555), [du] "+r"(dst_u), + [dv] "+r"(dst_v), [cnt] "+r"(width) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr10", "$xr11", "$xr12", "$xr13", "$xr14", "$xr15", "$xr20", + "$xr21", "$xr22", "$xr23", "$xr24", "$xr25", "$xr31"); +} + +static LIBYUV_NOINLINE void XRGBToUVHelper_LASX(const uint8_t* src, + int stride, + uint8_t* dst_u, + uint8_t* dst_v, + const uint8_t* shuf, + int width) { + const uint8_t* next = src + stride; + asm volatile( + "xvldi $xr20, 112\n\t" + "xvsrli.h $xr20, $xr20, 8\n\t" + "xvldi $xr21, 74\n\t" + "xvsrli.h $xr21, $xr21, 8\n\t" + "xvldi $xr22, 38\n\t" + "xvsrli.h $xr22, $xr22, 8\n\t" + "xvldi $xr23, 94\n\t" + "xvsrli.h $xr23, $xr23, 8\n\t" + "xvldi $xr24, 18\n\t" + "xvsrli.h $xr24, $xr24, 8\n\t" + "xvldi $xr25, 128\n\t" + "xvsrli.h $xr25, $xr25, 8\n\t" + "xvslli.h $xr25, $xr25, 8\n\t" + "vld $vr16, %[shuf], 0\n\t" + "xvpermi.q $xr16, $xr16, 0x00\n\t" + "1:\n\t" + "vld $vr8, %[s0], 0\n\t" + "vld $vr31, %[s0], 64\n\t" + "xvpermi.q $xr8, $xr31, 0x02\n\t" + "vld $vr9, %[s0], 16\n\t" + "vld $vr31, %[s0], 80\n\t" + "xvpermi.q $xr9, $xr31, 0x02\n\t" + "vld $vr10, %[s0], 32\n\t" + "vld $vr31, %[s0], 96\n\t" + "xvpermi.q $xr10, $xr31, 0x02\n\t" + "vld $vr11, %[s0], 48\n\t" + "vld $vr31, %[s0], 112\n\t" + "xvpermi.q $xr11, $xr31, 0x02\n\t" + "xvshuf.b $xr8, $xr8, $xr8, $xr16\n\t" + "xvshuf.b $xr9, $xr9, $xr9, $xr16\n\t" + "xvshuf.b $xr10, $xr10, $xr10, $xr16\n\t" + "xvshuf.b $xr11, $xr11, $xr11, $xr16\n\t" + "xvpickev.b $xr12, $xr9, $xr8\n\t" + "xvpickod.b $xr13, $xr9, $xr8\n\t" + "xvpickev.b $xr14, $xr11, $xr10\n\t" + "xvpickod.b $xr15, $xr11, $xr10\n\t" + "xvpickev.b $xr0, $xr14, $xr12\n\t" + "xvpickod.b $xr2, $xr14, $xr12\n\t" + "xvpickev.b $xr1, $xr15, $xr13\n\t" + "vld $vr8, %[s1], 0\n\t" + "vld $vr31, %[s1], 64\n\t" + "xvpermi.q $xr8, $xr31, 0x02\n\t" + "vld $vr9, %[s1], 16\n\t" + "vld $vr31, %[s1], 80\n\t" + "xvpermi.q $xr9, $xr31, 0x02\n\t" + "vld $vr10, %[s1], 32\n\t" + "vld $vr31, %[s1], 96\n\t" + "xvpermi.q $xr10, $xr31, 0x02\n\t" + "vld $vr11, %[s1], 48\n\t" + "vld $vr31, %[s1], 112\n\t" + "xvpermi.q $xr11, $xr31, 0x02\n\t" + "xvshuf.b $xr8, $xr8, $xr8, $xr16\n\t" + "xvshuf.b $xr9, $xr9, $xr9, $xr16\n\t" + "xvshuf.b $xr10, $xr10, $xr10, $xr16\n\t" + "xvshuf.b $xr11, $xr11, $xr11, $xr16\n\t" + "xvpickev.b $xr12, $xr9, $xr8\n\t" + "xvpickod.b $xr13, $xr9, $xr8\n\t" + "xvpickev.b $xr14, $xr11, $xr10\n\t" + "xvpickod.b $xr15, $xr11, $xr10\n\t" + "xvpickev.b $xr3, $xr14, $xr12\n\t" + "xvpickod.b $xr5, $xr14, $xr12\n\t" + "xvpickev.b $xr4, $xr15, $xr13\n\t" + "xvhaddw.hu.bu $xr0, $xr0, $xr0\n\t" + "xvhaddw.hu.bu $xr3, $xr3, $xr3\n\t" + "xvadd.h $xr0, $xr0, $xr3\n\t" + "xvsrari.h $xr0, $xr0, 2\n\t" + "xvhaddw.hu.bu $xr1, $xr1, $xr1\n\t" + "xvhaddw.hu.bu $xr4, $xr4, $xr4\n\t" + "xvadd.h $xr1, $xr1, $xr4\n\t" + "xvsrari.h $xr1, $xr1, 2\n\t" + "xvhaddw.hu.bu $xr2, $xr2, $xr2\n\t" + "xvhaddw.hu.bu $xr5, $xr5, $xr5\n\t" + "xvadd.h $xr2, $xr2, $xr5\n\t" + "xvsrari.h $xr2, $xr2, 2\n\t" + "xvor.v $xr6, $xr25, $xr25\n\t" + "xvor.v $xr7, $xr25, $xr25\n\t" + "xvmadd.h $xr6, $xr0, $xr20\n\t" + "xvmsub.h $xr6, $xr1, $xr21\n\t" + "xvmsub.h $xr6, $xr2, $xr22\n\t" + "xvmadd.h $xr7, $xr2, $xr20\n\t" + "xvmsub.h $xr7, $xr1, $xr23\n\t" + "xvmsub.h $xr7, $xr0, $xr24\n\t" + "xvpickod.b $xr6, $xr7, $xr6\n\t" + "xvpermi.d $xr31, $xr6, 0xd8\n\t" + "vst $vr31, %[du], 0\n\t" + "vstelm.d $vr6, %[dv], 0, 1\n\t" + "xvpermi.q $xr31, $xr6, 0x01\n\t" + "vstelm.d $vr31, %[dv], 8, 1\n\t" + "addi.d %[s0], %[s0], 128\n\t" + "addi.d %[s1], %[s1], 128\n\t" + "addi.d %[du], %[du], 16\n\t" + "addi.d %[dv], %[dv], 16\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src), [s1] "+r"(next), [du] "+r"(dst_u), [dv] "+r"(dst_v), + [cnt] "+r"(width) + : [shuf] "r"(shuf) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr12", "$xr13", "$xr14", + "$xr15", "$xr16", "$xr20", "$xr21", "$xr22", "$xr23", "$xr24", "$xr25", + "$xr31"); +} + +void BGRAToUVRow_LASX(const uint8_t* src_bgra, + int src_stride_bgra, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kShuf[16] = {3, 2, 1, 0, 7, 6, 5, 4, + 11, 10, 9, 8, 15, 14, 13, 12}; + XRGBToUVHelper_LASX(src_bgra, src_stride_bgra, dst_u, dst_v, kShuf, width); +} + +void ABGRToUVRow_LASX(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kShuf[16] = {2, 1, 0, 3, 6, 5, 4, 7, + 10, 9, 8, 11, 14, 13, 12, 15}; + XRGBToUVHelper_LASX(src_abgr, src_stride_abgr, dst_u, dst_v, kShuf, width); +} + +void RGBAToUVRow_LASX(const uint8_t* src_rgba, + int src_stride_rgba, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kShuf[16] = {1, 2, 3, 0, 5, 6, 7, 4, + 9, 10, 11, 8, 13, 14, 15, 12}; + XRGBToUVHelper_LASX(src_rgba, src_stride_rgba, dst_u, dst_v, kShuf, width); +} + +static LIBYUV_NOINLINE void RGB24ToUVHelper_LASX(const uint8_t* src, + int stride, + uint8_t* dst_u, + uint8_t* dst_v, + const uint8_t* shuf, + int width) { + const uint8_t* next = src + stride; + asm volatile( + "xvldi $xr20, 112\n\t" + "xvsrli.h $xr20, $xr20, 8\n\t" + "xvldi $xr21, 74\n\t" + "xvsrli.h $xr21, $xr21, 8\n\t" + "xvldi $xr22, 38\n\t" + "xvsrli.h $xr22, $xr22, 8\n\t" + "xvldi $xr23, 94\n\t" + "xvsrli.h $xr23, $xr23, 8\n\t" + "xvldi $xr24, 18\n\t" + "xvsrli.h $xr24, $xr24, 8\n\t" + "xvldi $xr25, 128\n\t" + "xvsrli.h $xr25, $xr25, 8\n\t" + "xvslli.h $xr25, $xr25, 8\n\t" + "vld $vr16, %[shuf], 0\n\t" + "xvpermi.q $xr16, $xr16, 0x00\n\t" + "vld $vr17, %[shuf], 16\n\t" + "xvpermi.q $xr17, $xr17, 0x00\n\t" + "1:\n\t" + "vld $vr8, %[s0], 0\n\t" + "vld $vr31, %[s0], 48\n\t" + "xvpermi.q $xr8, $xr31, 0x02\n\t" + "vld $vr9, %[s0], 12\n\t" + "vld $vr31, %[s0], 60\n\t" + "xvpermi.q $xr9, $xr31, 0x02\n\t" + "vld $vr10, %[s0], 24\n\t" + "vld $vr31, %[s0], 72\n\t" + "xvpermi.q $xr10, $xr31, 0x02\n\t" + "vld $vr11, %[s0], 32\n\t" + "vld $vr31, %[s0], 80\n\t" + "xvpermi.q $xr11, $xr31, 0x02\n\t" + "xvshuf.b $xr8, $xr8, $xr8, $xr16\n\t" + "xvshuf.b $xr9, $xr9, $xr9, $xr16\n\t" + "xvshuf.b $xr10, $xr10, $xr10, $xr16\n\t" + "xvshuf.b $xr11, $xr11, $xr11, $xr17\n\t" + "xvpickev.b $xr12, $xr9, $xr8\n\t" + "xvpickod.b $xr13, $xr9, $xr8\n\t" + "xvpickev.b $xr14, $xr11, $xr10\n\t" + "xvpickod.b $xr15, $xr11, $xr10\n\t" + "xvpickev.b $xr0, $xr14, $xr12\n\t" + "xvpickod.b $xr2, $xr14, $xr12\n\t" + "xvpickev.b $xr1, $xr15, $xr13\n\t" + "vld $vr8, %[s1], 0\n\t" + "vld $vr31, %[s1], 48\n\t" + "xvpermi.q $xr8, $xr31, 0x02\n\t" + "vld $vr9, %[s1], 12\n\t" + "vld $vr31, %[s1], 60\n\t" + "xvpermi.q $xr9, $xr31, 0x02\n\t" + "vld $vr10, %[s1], 24\n\t" + "vld $vr31, %[s1], 72\n\t" + "xvpermi.q $xr10, $xr31, 0x02\n\t" + "vld $vr11, %[s1], 32\n\t" + "vld $vr31, %[s1], 80\n\t" + "xvpermi.q $xr11, $xr31, 0x02\n\t" + "xvshuf.b $xr8, $xr8, $xr8, $xr16\n\t" + "xvshuf.b $xr9, $xr9, $xr9, $xr16\n\t" + "xvshuf.b $xr10, $xr10, $xr10, $xr16\n\t" + "xvshuf.b $xr11, $xr11, $xr11, $xr17\n\t" + "xvpickev.b $xr12, $xr9, $xr8\n\t" + "xvpickod.b $xr13, $xr9, $xr8\n\t" + "xvpickev.b $xr14, $xr11, $xr10\n\t" + "xvpickod.b $xr15, $xr11, $xr10\n\t" + "xvpickev.b $xr3, $xr14, $xr12\n\t" + "xvpickod.b $xr5, $xr14, $xr12\n\t" + "xvpickev.b $xr4, $xr15, $xr13\n\t" + "xvhaddw.hu.bu $xr0, $xr0, $xr0\n\t" + "xvhaddw.hu.bu $xr3, $xr3, $xr3\n\t" + "xvadd.h $xr0, $xr0, $xr3\n\t" + "xvsrari.h $xr0, $xr0, 2\n\t" + "xvhaddw.hu.bu $xr1, $xr1, $xr1\n\t" + "xvhaddw.hu.bu $xr4, $xr4, $xr4\n\t" + "xvadd.h $xr1, $xr1, $xr4\n\t" + "xvsrari.h $xr1, $xr1, 2\n\t" + "xvhaddw.hu.bu $xr2, $xr2, $xr2\n\t" + "xvhaddw.hu.bu $xr5, $xr5, $xr5\n\t" + "xvadd.h $xr2, $xr2, $xr5\n\t" + "xvsrari.h $xr2, $xr2, 2\n\t" + "xvor.v $xr6, $xr25, $xr25\n\t" + "xvor.v $xr7, $xr25, $xr25\n\t" + "xvmadd.h $xr6, $xr0, $xr20\n\t" + "xvmsub.h $xr6, $xr1, $xr21\n\t" + "xvmsub.h $xr6, $xr2, $xr22\n\t" + "xvmadd.h $xr7, $xr2, $xr20\n\t" + "xvmsub.h $xr7, $xr1, $xr23\n\t" + "xvmsub.h $xr7, $xr0, $xr24\n\t" + "xvpickod.b $xr6, $xr7, $xr6\n\t" + "xvpermi.d $xr31, $xr6, 0xd8\n\t" + "vst $vr31, %[du], 0\n\t" + "vstelm.d $vr6, %[dv], 0, 1\n\t" + "xvpermi.q $xr31, $xr6, 0x01\n\t" + "vstelm.d $vr31, %[dv], 8, 1\n\t" + "addi.d %[s0], %[s0], 96\n\t" + "addi.d %[s1], %[s1], 96\n\t" + "addi.d %[du], %[du], 16\n\t" + "addi.d %[dv], %[dv], 16\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src), [s1] "+r"(next), [du] "+r"(dst_u), [dv] "+r"(dst_v), + [cnt] "+r"(width) + : [shuf] "r"(shuf) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11", "$xr12", "$xr13", "$xr14", + "$xr15", "$xr16", "$xr17", "$xr20", "$xr21", "$xr22", "$xr23", "$xr24", + "$xr25", "$xr31"); +} + +void RGB24ToUVRow_LASX(const uint8_t* src_rgb24, + int src_stride_rgb24, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kShuf[32] = {0, 1, 2, 0, 3, 4, 5, 0, 6, 7, 8, + 0, 9, 10, 11, 0, 4, 5, 6, 0, 7, 8, + 9, 0, 10, 11, 12, 0, 13, 14, 15, 0}; + RGB24ToUVHelper_LASX(src_rgb24, src_stride_rgb24, dst_u, dst_v, kShuf, width); +} + +void RAWToUVRow_LASX(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kShuf[32] = {2, 1, 0, 0, 5, 4, 3, 0, 8, 7, 6, + 0, 11, 10, 9, 0, 6, 5, 4, 0, 9, 8, + 7, 0, 12, 11, 10, 0, 15, 14, 13, 0}; + RGB24ToUVHelper_LASX(src_raw, src_stride_raw, dst_u, dst_v, kShuf, width); +} + +#ifdef HAS_SSIM4X4ROW_LASX +void Ssim4x4Row_LASX(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + const uint8_t* pa; + const uint8_t* pb; + int r; + asm volatile( + "1:\n\t" + "move %[pa], %[sa]\n\t" + "move %[pb], %[sb]\n\t" + "li.d %[r], 4\n\t" + "xvxor.v $xr8, $xr8, $xr8\n\t" + "xvxor.v $xr9, $xr9, $xr9\n\t" + "xvxor.v $xr10, $xr10, $xr10\n\t" + "xvxor.v $xr11, $xr11, $xr11\n\t" + "2:\n\t" + "xvld $xr0, %[pa], 0\n\t" + "xvld $xr1, %[pb], 0\n\t" + "add.d %[pa], %[pa], %[sta]\n\t" + "add.d %[pb], %[pb], %[stb]\n\t" + "xvhaddw.hu.bu $xr2, $xr0, $xr0\n\t" + "xvhaddw.hu.bu $xr3, $xr1, $xr1\n\t" + "xvadd.h $xr8, $xr8, $xr2\n\t" + "xvadd.h $xr9, $xr9, $xr3\n\t" + "xvmulwev.h.bu $xr2, $xr0, $xr1\n\t" + "xvmulwod.h.bu $xr3, $xr0, $xr1\n\t" + "xvhaddw.wu.hu $xr2, $xr2, $xr2\n\t" + "xvhaddw.wu.hu $xr3, $xr3, $xr3\n\t" + "xvadd.w $xr11, $xr11, $xr2\n\t" + "xvadd.w $xr11, $xr11, $xr3\n\t" + "xvmulwev.h.bu $xr2, $xr0, $xr0\n\t" + "xvmulwod.h.bu $xr3, $xr0, $xr0\n\t" + "xvmulwev.h.bu $xr4, $xr1, $xr1\n\t" + "xvmulwod.h.bu $xr5, $xr1, $xr1\n\t" + "xvhaddw.wu.hu $xr2, $xr2, $xr2\n\t" + "xvhaddw.wu.hu $xr3, $xr3, $xr3\n\t" + "xvhaddw.wu.hu $xr4, $xr4, $xr4\n\t" + "xvhaddw.wu.hu $xr5, $xr5, $xr5\n\t" + "xvadd.w $xr2, $xr2, $xr3\n\t" + "xvadd.w $xr4, $xr4, $xr5\n\t" + "xvadd.w $xr10, $xr10, $xr2\n\t" + "xvadd.w $xr10, $xr10, $xr4\n\t" + "addi.d %[r], %[r], -1\n\t" + "bnez %[r], 2b\n\t" + "xvhaddw.wu.hu $xr8, $xr8, $xr8\n\t" + "xvhaddw.wu.hu $xr9, $xr9, $xr9\n\t" + "xvilvl.w $xr0, $xr9, $xr8\n\t" + "xvilvh.w $xr1, $xr9, $xr8\n\t" + "xvilvl.w $xr2, $xr11, $xr10\n\t" + "xvilvh.w $xr3, $xr11, $xr10\n\t" + "xvilvl.d $xr4, $xr2, $xr0\n\t" + "xvilvh.d $xr5, $xr2, $xr0\n\t" + "xvilvl.d $xr6, $xr3, $xr1\n\t" + "xvilvh.d $xr7, $xr3, $xr1\n\t" + "xvor.v $xr0, $xr5, $xr5\n\t" + "xvpermi.q $xr0, $xr4, 0x20\n\t" + "xvpermi.q $xr5, $xr4, 0x31\n\t" + "xvor.v $xr1, $xr7, $xr7\n\t" + "xvpermi.q $xr1, $xr6, 0x20\n\t" + "xvpermi.q $xr7, $xr6, 0x31\n\t" + "xvst $xr0, %[dst], 0\n\t" + "xvst $xr1, %[dst], 32\n\t" + "xvst $xr5, %[dst], 64\n\t" + "xvst $xr7, %[dst], 96\n\t" + "addi.d %[sa], %[sa], 32\n\t" + "addi.d %[sb], %[sb], 32\n\t" + "addi.d %[dst], %[dst], 128\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + : [sa] "+r"(src_a), [sb] "+r"(src_b), [dst] "+r"(dst), [cnt] "+r"(width), + [pa] "=&r"(pa), [pb] "=&r"(pb), [r] "=&r"(r) + : [sta] "r"((ptrdiff_t)stride_a), [stb] "r"((ptrdiff_t)stride_b) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7", "$xr8", "$xr9", "$xr10", "$xr11"); +} +#endif // HAS_SSIM4X4ROW_LASX + +#ifdef HAS_SSIMWINDOWROW_LASX +float SsimWindowRow_LASX(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + const uint32_t* row0_next = row0 + 4; + const uint32_t* row1_next = row1 + 4; + float total; + uint32_t c1 = 26634; + uint32_t c2 = 239708; + uint32_t c0 = 0; + asm volatile( + "xvreplgr2vr.w $xr6, %[c0]\n\t" + "xvreplgr2vr.w $xr4, %[c1]\n\t" + "xvreplgr2vr.w $xr5, %[c2]\n\t" + "addi.d %[cnt], %[cnt], -2\n\t" + "bltz %[cnt], 2f\n\t" + "1:\n\t" + "xvld $xr0, %[r0], 0\n\t" + "xvld $xr1, %[r0n], 0\n\t" + "xvld $xr2, %[r1], 0\n\t" + "xvld $xr3, %[r1n], 0\n\t" + "xvadd.w $xr0, $xr0, $xr1\n\t" + "xvadd.w $xr2, $xr2, $xr3\n\t" + "xvadd.w $xr0, $xr0, $xr2\n\t" + "xvshuf4i.w $xr1, $xr0, 0x00\n\t" + "xvshuf4i.w $xr2, $xr0, 0x55\n\t" + "xvshuf4i.w $xr3, $xr0, 0xaa\n\t" + "xvshuf4i.w $xr0, $xr0, 0xff\n\t" + "xvmul.w $xr7, $xr1, $xr2\n\t" + "xvslli.w $xr7, $xr7, 1\n\t" + "xvmul.w $xr1, $xr1, $xr1\n\t" + "xvmadd.w $xr1, $xr2, $xr2\n\t" + "xvslli.w $xr0, $xr0, 7\n\t" + "xvsub.w $xr0, $xr0, $xr7\n\t" + "xvadd.w $xr7, $xr7, $xr4\n\t" + "xvadd.w $xr0, $xr0, $xr5\n\t" + "xvslli.w $xr3, $xr3, 6\n\t" + "xvsub.w $xr3, $xr3, $xr1\n\t" + "xvadd.w $xr1, $xr1, $xr4\n\t" + "xvadd.w $xr3, $xr3, $xr5\n\t" + "xvffint.s.w $xr7, $xr7\n\t" + "xvffint.s.w $xr0, $xr0\n\t" + "xvffint.s.w $xr1, $xr1\n\t" + "xvffint.s.w $xr3, $xr3\n\t" + "xvfmul.s $xr7, $xr7, $xr0\n\t" + "xvfmul.s $xr1, $xr1, $xr3\n\t" + "xvfdiv.s $xr7, $xr7, $xr1\n\t" + "xvfadd.s $xr6, $xr6, $xr7\n\t" + "addi.d %[r0], %[r0], 32\n\t" + "addi.d %[r0n], %[r0n], 32\n\t" + "addi.d %[r1], %[r1], 32\n\t" + "addi.d %[r1n], %[r1n], 32\n\t" + "addi.d %[cnt], %[cnt], -2\n\t" + "bgez %[cnt], 1b\n\t" + "xvpermi.q $xr0, $xr6, 0x01\n\t" + "vfadd.s $vr6, $vr6, $vr0\n\t" + "2:\n\t" + "addi.d %[cnt], %[cnt], 2\n\t" + "beqz %[cnt], 3f\n\t" + "vld $vr0, %[r0], 0\n\t" + "vld $vr1, %[r0n], 0\n\t" + "vld $vr2, %[r1], 0\n\t" + "vld $vr3, %[r1n], 0\n\t" + "vadd.w $vr0, $vr0, $vr1\n\t" + "vadd.w $vr2, $vr2, $vr3\n\t" + "vadd.w $vr0, $vr0, $vr2\n\t" + "vshuf4i.w $vr1, $vr0, 0x00\n\t" + "vshuf4i.w $vr2, $vr0, 0x55\n\t" + "vshuf4i.w $vr3, $vr0, 0xaa\n\t" + "vshuf4i.w $vr0, $vr0, 0xff\n\t" + "vmul.w $vr7, $vr1, $vr2\n\t" + "vslli.w $vr7, $vr7, 1\n\t" + "vmul.w $vr1, $vr1, $vr1\n\t" + "vmadd.w $vr1, $vr2, $vr2\n\t" + "vslli.w $vr0, $vr0, 7\n\t" + "vsub.w $vr0, $vr0, $vr7\n\t" + "vadd.w $vr7, $vr7, $vr4\n\t" + "vadd.w $vr0, $vr0, $vr5\n\t" + "vslli.w $vr3, $vr3, 6\n\t" + "vsub.w $vr3, $vr3, $vr1\n\t" + "vadd.w $vr1, $vr1, $vr4\n\t" + "vadd.w $vr3, $vr3, $vr5\n\t" + "vffint.s.w $vr7, $vr7\n\t" + "vffint.s.w $vr0, $vr0\n\t" + "vffint.s.w $vr1, $vr1\n\t" + "vffint.s.w $vr3, $vr3\n\t" + "vfmul.s $vr7, $vr7, $vr0\n\t" + "vfmul.s $vr1, $vr1, $vr3\n\t" + "vfdiv.s $vr7, $vr7, $vr1\n\t" + "vfadd.s $vr6, $vr6, $vr7\n\t" + "3:\n\t" + "vstelm.w $vr6, %[tot], 0, 0\n\t" + : [r0] "+r"(row0), [r0n] "+r"(row0_next), [r1] "+r"(row1), + [r1n] "+r"(row1_next), [cnt] "+r"(num_windows) + : [c0] "r"(c0), [c1] "r"(c1), [c2] "r"(c2), [tot] "r"(&total) + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4", "$xr5", "$xr6", + "$xr7"); + return total; +} +#endif // HAS_SSIMWINDOWROW_LASX + +#ifdef HAS_ARGBDETECTROW_LASX +uint32_t ARGBDetectRow_LASX(const uint8_t* argb, int width) { + uint32_t diff = 0; + uint32_t tmp; + uint32_t rgb_mask = 0x00ffff00u; + asm volatile( + "xvreplgr2vr.w $xr2, %[rgb_mask]\n\t" + "xvldi $xr3, -1\n\t" + "addi.d %[w], %[w], -8\n\t" + "bltz %[w], 2f\n\t" + "1:\n\t" + "xvld $xr0, %[argb], 0\n\t" + "addi.d %[argb], %[argb], 32\n\t" + "xvor.v $xr0, $xr0, $xr2\n\t" + "xvseq.b $xr0, $xr0, $xr3\n\t" + "xvmskltz.b $xr0, $xr0\n\t" + "xvpickve2gr.wu %[diff], $xr0, 0\n\t" + "xvpickve2gr.wu %[tmp], $xr0, 4\n\t" + "bstrins.w %[diff], %[tmp], 31, 16\n\t" + "nor %[diff], %[diff], $zero\n\t" + "bnez %[diff], 4f\n\t" + "addi.d %[w], %[w], -8\n\t" + "bgez %[w], 1b\n\t" + "2:\n\t" + "addi.d %[w], %[w], 8\n\t" + "beqz %[w], 4f\n\t" + "3:\n\t" + "vldrepl.w $vr0, %[argb], 0\n\t" + "addi.d %[argb], %[argb], 4\n\t" + "vor.v $vr0, $vr0, $vr2\n\t" + "vseq.b $vr0, $vr0, $vr3\n\t" + "vmskltz.b $vr0, $vr0\n\t" + "vpickve2gr.hu %[diff], $vr0, 0\n\t" + "nor %[diff], %[diff], $zero\n\t" + "bstrpick.w %[diff], %[diff], 15, 0\n\t" + "bnez %[diff], 4f\n\t" + "addi.d %[w], %[w], -1\n\t" + "bnez %[w], 3b\n\t" + "4:\n\t" + : [argb] "+r"(argb), [w] "+r"(width), [diff] "+r"(diff), [tmp] "=&r"(tmp) + : [rgb_mask] "r"(rgb_mask) + : "memory", "$xr0", "$xr2", "$xr3"); + if (diff) { + return (__builtin_ctz(diff) & 3) == 0 ? FOURCC_BGRA : FOURCC_ARGB; + } + return 0; +} +#endif // HAS_ARGBDETECTROW_LASX + +#ifdef HAS_HAMMINGDISTANCE_LASX +uint32_t HammingDistance_LASX(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t diff; + asm volatile( + "xvxor.v $xr4, $xr4, $xr4\n\t" + "1:\n\t" + "xvld $xr0, %[sa], 0\n\t" + "xvld $xr1, %[sb], 0\n\t" + "xvxor.v $xr0, $xr0, $xr1\n\t" + "xvpcnt.b $xr0, $xr0\n\t" + "xvhaddw.hu.bu $xr0, $xr0, $xr0\n\t" + "xvhaddw.wu.hu $xr0, $xr0, $xr0\n\t" + "xvadd.w $xr4, $xr4, $xr0\n\t" + "addi.d %[sa], %[sa], 32\n\t" + "addi.d %[sb], %[sb], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + "xvhaddw.du.wu $xr4, $xr4, $xr4\n\t" + "xvhaddw.qu.du $xr4, $xr4, $xr4\n\t" + "xvpermi.q $xr0, $xr4, 0x01\n\t" + "vadd.w $vr4, $vr4, $vr0\n\t" + "vpickve2gr.wu %[diff], $vr4, 0\n\t" + : [sa] "+r"(src_a), [sb] "+r"(src_b), [cnt] "+r"(count), [diff] "=r"(diff) + : + : "memory", "$xr0", "$xr1", "$xr4"); + return diff; +} +#endif // HAS_HAMMINGDISTANCE_LASX + +#ifdef HAS_SUMSQUAREERROR_LASX +uint32_t SumSquareError_LASX(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t sse; + asm volatile( + "xvxor.v $xr4, $xr4, $xr4\n\t" + "1:\n\t" + "xvld $xr0, %[sa], 0\n\t" + "xvld $xr1, %[sb], 0\n\t" + "xvabsd.bu $xr0, $xr0, $xr1\n\t" + "xvmulwev.h.bu $xr2, $xr0, $xr0\n\t" + "xvmulwod.h.bu $xr3, $xr0, $xr0\n\t" + "xvhaddw.wu.hu $xr2, $xr2, $xr2\n\t" + "xvhaddw.wu.hu $xr3, $xr3, $xr3\n\t" + "xvadd.w $xr4, $xr4, $xr2\n\t" + "xvadd.w $xr4, $xr4, $xr3\n\t" + "addi.d %[sa], %[sa], 32\n\t" + "addi.d %[sb], %[sb], 32\n\t" + "addi.d %[cnt], %[cnt], -32\n\t" + "bnez %[cnt], 1b\n\t" + "xvhaddw.du.wu $xr4, $xr4, $xr4\n\t" + "xvhaddw.qu.du $xr4, $xr4, $xr4\n\t" + "xvpermi.q $xr0, $xr4, 0x01\n\t" + "vadd.w $vr4, $vr4, $vr0\n\t" + "vpickve2gr.wu %[sse], $vr4, 0\n\t" + : [sa] "+r"(src_a), [sb] "+r"(src_b), [cnt] "+r"(count), [sse] "=r"(sse) + : + : "memory", "$xr0", "$xr1", "$xr2", "$xr3", "$xr4"); + return sse; +} +#endif // HAS_SUMSQUAREERROR_LASX + +#ifdef HAS_HASHDJB2_LASX +static const uint32_t kDjb2Muls_LASX[16] = { + 0x0c3525e1, 0xa3476dc1, 0x3b4039a1, 0x4f5f0981, 0x30f35d61, 0x855cb541, + 0x040a9121, 0x747c7101, 0xec41d4e1, 0x4cfa3cc1, 0x025528a1, 0x00121881, + 0x00008c61, 0x00000441, 0x00000021, 0x00000001, +}; + +uint32_t HashDjb2_LASX(const uint8_t* src, int count, uint32_t seed) { + uint32_t hash = seed; + uint32_t tmp; + uint32_t c16 = 0x92d9e201u; + asm volatile( + "xvld $xr4, %[muls], 0\n\t" + "xvld $xr5, %[muls], 32\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vbsrl.v $vr1, $vr0, 8\n\t" + "vext2xv.wu.bu $xr0, $xr0\n\t" + "vext2xv.wu.bu $xr1, $xr1\n\t" + "xvmul.w $xr0, $xr0, $xr4\n\t" + "xvmadd.w $xr0, $xr1, $xr5\n\t" + "xvhaddw.du.wu $xr0, $xr0, $xr0\n\t" + "xvhaddw.qu.du $xr0, $xr0, $xr0\n\t" + "xvpermi.q $xr1, $xr0, 0x01\n\t" + "vadd.w $vr0, $vr0, $vr1\n\t" + "vpickve2gr.wu %[tmp], $vr0, 0\n\t" + "mul.w %[hash], %[hash], %[c16]\n\t" + "add.w %[hash], %[hash], %[tmp]\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src), [cnt] "+r"(count), [hash] "+r"(hash), [tmp] "=&r"(tmp) + : [muls] "r"(kDjb2Muls_LASX), [c16] "r"(c16) + : "memory", "$xr0", "$xr1", "$xr4", "$xr5"); + return hash; +} +#endif // HAS_HASHDJB2_LASX + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_LASX) && defined(__loongarch_asx) diff --git a/libs/libyuv/source/row_lsx.cc b/libs/libyuv/source/row_lsx.cc new file mode 100644 index 0000000000..cb0ad41378 --- /dev/null +++ b/libs/libyuv/source/row_lsx.cc @@ -0,0 +1,3112 @@ +/* + * Copyright 2022 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/compare_row.h" +#include "libyuv/row.h" +#include "libyuv/video_common.h" + +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + +#if !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx) + +#include "libyuv/basic_types.h" + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +void CopyRow_LSX(const uint8_t* src, uint8_t* dst, int count) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src), [dst] "+r"(dst), [cnt] "+r"(count) + : + : "memory", "$vr0"); +} + +void SetRow_LSX(uint8_t* dst, uint8_t v8, int count) { + asm volatile( + "vreplgr2vr.b $vr0, %[val]\n\t" + "1:\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [dst] "+r"(dst), [cnt] "+r"(count) + : [val] "r"(v8) + : "memory", "$vr0"); +} + +void ARGBSetRow_LSX(uint8_t* dst_argb, uint32_t v32, int width) { + asm volatile( + "vreplgr2vr.w $vr0, %[val]\n\t" + "1:\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [val] "r"(v32) + : "memory", "$vr0"); +} + +void MirrorRow_LSX(const uint8_t* src_y, uint8_t* dst_y, int width) { + static const uint8_t kRev[16] = {15, 14, 13, 12, 11, 10, 9, 8, + 7, 6, 5, 4, 3, 2, 1, 0}; + src_y += width - 16; + asm volatile( + "vld $vr1, %[rev], 0\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vshuf.b $vr0, $vr0, $vr0, $vr1\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[src], %[src], -16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_y), [dst] "+r"(dst_y), [cnt] "+r"(width) + : [rev] "r"(kRev) + : "memory", "$vr0", "$vr1"); +} + +void MirrorUVRow_LSX(const uint8_t* src_uv, uint8_t* dst_uv, int width) { + static const uint8_t kRevUV[16] = {14, 15, 12, 13, 10, 11, 8, 9, + 6, 7, 4, 5, 2, 3, 0, 1}; + src_uv += width * 2 - 16; + asm volatile( + "vld $vr1, %[rev], 0\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vshuf.b $vr0, $vr0, $vr0, $vr1\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[src], %[src], -16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_uv), [dst] "+r"(dst_uv), [cnt] "+r"(width) + : [rev] "r"(kRevUV) + : "memory", "$vr0", "$vr1"); +} + +void ARGBMirrorRow_LSX(const uint8_t* src_argb, uint8_t* dst_argb, int width) { + src_argb += width * 4 - 16; + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vshuf4i.w $vr0, $vr0, 0x1b\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[src], %[src], -16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$vr0"); +} + +void MirrorSplitUVRow_LSX(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kRevUV[16] = {14, 15, 12, 13, 10, 11, 8, 9, + 6, 7, 4, 5, 2, 3, 0, 1}; + src_uv += width * 2 - 32; + asm volatile( + "vld $vr4, %[rev], 0\n\t" + "1:\n\t" + "vld $vr0, %[src], 16\n\t" + "vld $vr1, %[src], 0\n\t" + "vshuf.b $vr0, $vr0, $vr0, $vr4\n\t" + "vshuf.b $vr1, $vr1, $vr1, $vr4\n\t" + "vpickev.b $vr2, $vr1, $vr0\n\t" + "vpickod.b $vr3, $vr1, $vr0\n\t" + "vst $vr2, %[du], 0\n\t" + "vst $vr3, %[dv], 0\n\t" + "addi.d %[src], %[src], -32\n\t" + "addi.d %[du], %[du], 16\n\t" + "addi.d %[dv], %[dv], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : + [src] "+r"(src_uv), [du] "+r"(dst_u), [dv] "+r"(dst_v), [cnt] "+r"(width) + : [rev] "r"(kRevUV) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4"); +} + +void SplitUVRow_LSX(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 16\n\t" + "vpickev.b $vr2, $vr1, $vr0\n\t" + "vpickod.b $vr3, $vr1, $vr0\n\t" + "vst $vr2, %[du], 0\n\t" + "vst $vr3, %[dv], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[du], %[du], 16\n\t" + "addi.d %[dv], %[dv], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : + [src] "+r"(src_uv), [du] "+r"(dst_u), [dv] "+r"(dst_v), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3"); +} + +void MergeUVRow_LSX(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[su], 0\n\t" + "vld $vr1, %[sv], 0\n\t" + "vilvl.b $vr2, $vr1, $vr0\n\t" + "vilvh.b $vr3, $vr1, $vr0\n\t" + "vst $vr2, %[dst], 0\n\t" + "vst $vr3, %[dst], 16\n\t" + "addi.d %[su], %[su], 16\n\t" + "addi.d %[sv], %[sv], 16\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : + [su] "+r"(src_u), [sv] "+r"(src_v), [dst] "+r"(dst_uv), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3"); +} + +void ARGBExtractAlphaRow_LSX(const uint8_t* src_argb, + uint8_t* dst_a, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 16\n\t" + "vpickod.b $vr0, $vr1, $vr0\n\t" + "vpickod.b $vr0, $vr0, $vr0\n\t" + "vstelm.d $vr0, %[dst], 0, 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 8\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_a), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1"); +} + +void I422ToYUY2Row_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_yuy2, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "vldrepl.d $vr1, %[su], 0\n\t" + "vldrepl.d $vr2, %[sv], 0\n\t" + "vilvl.b $vr3, $vr2, $vr1\n\t" + "vilvl.b $vr4, $vr3, $vr0\n\t" + "vilvh.b $vr5, $vr3, $vr0\n\t" + "vst $vr4, %[dst], 0\n\t" + "vst $vr5, %[dst], 16\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[su], %[su], 8\n\t" + "addi.d %[sv], %[sv], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_yuy2), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5"); +} + +void I422ToUYVYRow_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uyvy, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[sy], 0\n\t" + "vldrepl.d $vr1, %[su], 0\n\t" + "vldrepl.d $vr2, %[sv], 0\n\t" + "vilvl.b $vr3, $vr2, $vr1\n\t" + "vilvl.b $vr4, $vr0, $vr3\n\t" + "vilvh.b $vr5, $vr0, $vr3\n\t" + "vst $vr4, %[dst], 0\n\t" + "vst $vr5, %[dst], 16\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[su], %[su], 8\n\t" + "addi.d %[sv], %[sv], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_uyvy), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5"); +} + +void YUY2ToYRow_LSX(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 16\n\t" + "vpickev.b $vr2, $vr1, $vr0\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_yuy2), [dst] "+r"(dst_y), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2"); +} + +void UYVYToYRow_LSX(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 16\n\t" + "vpickod.b $vr2, $vr1, $vr0\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_uyvy), [dst] "+r"(dst_y), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2"); +} + +void YUY2ToUV422Row_LSX(const uint8_t* src_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 16\n\t" + "vpickod.b $vr2, $vr1, $vr0\n\t" + "vpickev.b $vr3, $vr2, $vr2\n\t" + "vpickod.b $vr4, $vr2, $vr2\n\t" + "vstelm.d $vr3, %[du], 0, 0\n\t" + "vstelm.d $vr4, %[dv], 0, 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[du], %[du], 8\n\t" + "addi.d %[dv], %[dv], 8\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_yuy2), [du] "+r"(dst_u), [dv] "+r"(dst_v), + [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4"); +} + +void UYVYToUV422Row_LSX(const uint8_t* src_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 16\n\t" + "vpickev.b $vr2, $vr1, $vr0\n\t" + "vpickev.b $vr3, $vr2, $vr2\n\t" + "vpickod.b $vr4, $vr2, $vr2\n\t" + "vstelm.d $vr3, %[du], 0, 0\n\t" + "vstelm.d $vr4, %[dv], 0, 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[du], %[du], 8\n\t" + "addi.d %[dv], %[dv], 8\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_uyvy), [du] "+r"(dst_u), [dv] "+r"(dst_v), + [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4"); +} + +void YUY2ToUVRow_LSX(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* next_yuy2 = src_yuy2 + src_stride_yuy2; + asm volatile( + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr1, %[s0], 16\n\t" + "vld $vr2, %[s1], 0\n\t" + "vld $vr3, %[s1], 16\n\t" + "vpickod.b $vr0, $vr1, $vr0\n\t" + "vpickod.b $vr2, $vr3, $vr2\n\t" + "vavgr.bu $vr0, $vr0, $vr2\n\t" + "vpickev.b $vr1, $vr0, $vr0\n\t" + "vpickod.b $vr2, $vr0, $vr0\n\t" + "vstelm.d $vr1, %[du], 0, 0\n\t" + "vstelm.d $vr2, %[dv], 0, 0\n\t" + "addi.d %[s0], %[s0], 32\n\t" + "addi.d %[s1], %[s1], 32\n\t" + "addi.d %[du], %[du], 8\n\t" + "addi.d %[dv], %[dv], 8\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_yuy2), [s1] "+r"(next_yuy2), [du] "+r"(dst_u), + [dv] "+r"(dst_v), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3"); +} + +void UYVYToUVRow_LSX(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* next_uyvy = src_uyvy + src_stride_uyvy; + asm volatile( + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr1, %[s0], 16\n\t" + "vld $vr2, %[s1], 0\n\t" + "vld $vr3, %[s1], 16\n\t" + "vpickev.b $vr0, $vr1, $vr0\n\t" + "vpickev.b $vr2, $vr3, $vr2\n\t" + "vavgr.bu $vr0, $vr0, $vr2\n\t" + "vpickev.b $vr1, $vr0, $vr0\n\t" + "vpickod.b $vr2, $vr0, $vr0\n\t" + "vstelm.d $vr1, %[du], 0, 0\n\t" + "vstelm.d $vr2, %[dv], 0, 0\n\t" + "addi.d %[s0], %[s0], 32\n\t" + "addi.d %[s1], %[s1], 32\n\t" + "addi.d %[du], %[du], 8\n\t" + "addi.d %[dv], %[dv], 8\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_uyvy), [s1] "+r"(next_uyvy), [du] "+r"(dst_u), + [dv] "+r"(dst_v), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3"); +} + +void I422ToARGBRow_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vldi $vr5, 0xff\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vldrepl.w $vr10, %[su], 0\n\t" + "vldrepl.w $vr11, %[sv], 0\n\t" + "vilvl.b $vr10, $vr10, $vr10\n\t" + "vilvl.b $vr11, $vr11, $vr11\n\t" + "vilvl.b $vr1, $vr11, $vr10\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vilvl.b $vr6, $vr3, $vr2\n\t" + "vilvl.b $vr7, $vr5, $vr4\n\t" + "vilvl.h $vr8, $vr7, $vr6\n\t" + "vilvh.h $vr9, $vr7, $vr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "vst $vr9, %[dst], 16\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[su], %[su], 4\n\t" + "addi.d %[sv], %[sv], 4\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr20", "$vr21", "$vr22", + "$vr23", "$vr24"); +} + +void I422ToRGBARow_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vldi $vr5, 0xff\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vldrepl.w $vr10, %[su], 0\n\t" + "vldrepl.w $vr11, %[sv], 0\n\t" + "vilvl.b $vr10, $vr10, $vr10\n\t" + "vilvl.b $vr11, $vr11, $vr11\n\t" + "vilvl.b $vr1, $vr11, $vr10\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vilvl.b $vr6, $vr2, $vr5\n\t" + "vilvl.b $vr7, $vr4, $vr3\n\t" + "vilvl.h $vr8, $vr7, $vr6\n\t" + "vilvh.h $vr9, $vr7, $vr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "vst $vr9, %[dst], 16\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[su], %[su], 4\n\t" + "addi.d %[sv], %[sv], 4\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr20", "$vr21", "$vr22", + "$vr23", "$vr24"); +} + +void I422AlphaToARGBRow_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vldrepl.w $vr10, %[su], 0\n\t" + "vldrepl.w $vr11, %[sv], 0\n\t" + "vilvl.b $vr10, $vr10, $vr10\n\t" + "vilvl.b $vr11, $vr11, $vr11\n\t" + "vilvl.b $vr1, $vr11, $vr10\n\t" + "vldrepl.d $vr5, %[sa], 0\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vilvl.b $vr6, $vr3, $vr2\n\t" + "vilvl.b $vr7, $vr5, $vr4\n\t" + "vilvl.h $vr8, $vr7, $vr6\n\t" + "vilvh.h $vr9, $vr7, $vr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "vst $vr9, %[dst], 16\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[su], %[su], 4\n\t" + "addi.d %[sv], %[sv], 4\n\t" + "addi.d %[sa], %[sa], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width), [sa] "+r"(src_a) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr20", "$vr21", "$vr22", + "$vr23", "$vr24"); +} + +void I422ToRGB24Row_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + static const uint8_t kShuf0[16] = {0, 1, 2, 4, 5, 6, 8, 9, + 10, 12, 13, 14, 16, 17, 18, 20}; + static const uint8_t kShuf1[16] = {21, 22, 24, 25, 26, 28, 29, 30, + 0, 0, 0, 0, 0, 0, 0, 0}; + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vld $vr12, %[s0], 0\n\t" + "vld $vr13, %[s1], 0\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vldrepl.w $vr10, %[su], 0\n\t" + "vldrepl.w $vr11, %[sv], 0\n\t" + "vilvl.b $vr10, $vr10, $vr10\n\t" + "vilvl.b $vr11, $vr11, $vr11\n\t" + "vilvl.b $vr1, $vr11, $vr10\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vilvl.b $vr6, $vr3, $vr2\n\t" + "vilvl.b $vr7, $vr4, $vr4\n\t" + "vilvl.h $vr8, $vr7, $vr6\n\t" + "vilvh.h $vr9, $vr7, $vr6\n\t" + "vshuf.b $vr10, $vr9, $vr8, $vr12\n\t" + "vshuf.b $vr11, $vr9, $vr8, $vr13\n\t" + "vst $vr10, %[dst], 0\n\t" + "vstelm.d $vr11, %[dst], 16, 0\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[su], %[su], 4\n\t" + "addi.d %[sv], %[sv], 4\n\t" + "addi.d %[dst], %[dst], 24\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants), [s0] "r"(kShuf0), [s1] "r"(kShuf1) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr6", "$vr7", + "$vr8", "$vr9", "$vr10", "$vr11", "$vr12", "$vr13", "$vr20", "$vr21", + "$vr22", "$vr23", "$vr24"); +} + +void I422ToRGB565Row_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vldi $vr14, 31\n\t" + "vsrli.h $vr14, $vr14, 8\n\t" + "vldi $vr15, 63\n\t" + "vsrli.h $vr15, $vr15, 8\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vldrepl.w $vr10, %[su], 0\n\t" + "vldrepl.w $vr11, %[sv], 0\n\t" + "vilvl.b $vr10, $vr10, $vr10\n\t" + "vilvl.b $vr11, $vr11, $vr11\n\t" + "vilvl.b $vr1, $vr11, $vr10\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vsrli.b $vr2, $vr2, 3\n\t" + "vsrli.b $vr3, $vr3, 2\n\t" + "vsrli.b $vr4, $vr4, 3\n\t" + "vilvl.b $vr2, $vr2, $vr2\n\t" + "vilvl.b $vr3, $vr3, $vr3\n\t" + "vilvl.b $vr4, $vr4, $vr4\n\t" + "vand.v $vr2, $vr2, $vr14\n\t" + "vand.v $vr3, $vr3, $vr15\n\t" + "vand.v $vr4, $vr4, $vr14\n\t" + "vslli.h $vr3, $vr3, 5\n\t" + "vslli.h $vr4, $vr4, 11\n\t" + "vor.v $vr2, $vr2, $vr3\n\t" + "vor.v $vr2, $vr2, $vr4\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[su], %[su], 4\n\t" + "addi.d %[sv], %[sv], 4\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr10", "$vr11", + "$vr14", "$vr15", "$vr20", "$vr21", "$vr22", "$vr23", "$vr24"); +} + +void I422ToARGB4444Row_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vldi $vr14, 15\n\t" + "vsrli.h $vr14, $vr14, 8\n\t" + "vldi $vr15, 240\n\t" + "vsrli.h $vr15, $vr15, 8\n\t" + "vslli.h $vr15, $vr15, 8\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vldrepl.w $vr10, %[su], 0\n\t" + "vldrepl.w $vr11, %[sv], 0\n\t" + "vilvl.b $vr10, $vr10, $vr10\n\t" + "vilvl.b $vr11, $vr11, $vr11\n\t" + "vilvl.b $vr1, $vr11, $vr10\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vsrli.b $vr2, $vr2, 4\n\t" + "vsrli.b $vr3, $vr3, 4\n\t" + "vsrli.b $vr4, $vr4, 4\n\t" + "vilvl.b $vr2, $vr2, $vr2\n\t" + "vilvl.b $vr3, $vr3, $vr3\n\t" + "vilvl.b $vr4, $vr4, $vr4\n\t" + "vand.v $vr2, $vr2, $vr14\n\t" + "vand.v $vr3, $vr3, $vr14\n\t" + "vand.v $vr4, $vr4, $vr14\n\t" + "vslli.h $vr3, $vr3, 4\n\t" + "vslli.h $vr4, $vr4, 8\n\t" + "vor.v $vr2, $vr2, $vr3\n\t" + "vor.v $vr2, $vr2, $vr4\n\t" + "vor.v $vr2, $vr2, $vr15\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[su], %[su], 4\n\t" + "addi.d %[sv], %[sv], 4\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr10", "$vr11", + "$vr14", "$vr15", "$vr20", "$vr21", "$vr22", "$vr23", "$vr24"); +} + +void I422ToARGB1555Row_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vldi $vr14, 31\n\t" + "vsrli.h $vr14, $vr14, 8\n\t" + "vldi $vr15, 128\n\t" + "vsrli.h $vr15, $vr15, 8\n\t" + "vslli.h $vr15, $vr15, 8\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vldrepl.w $vr10, %[su], 0\n\t" + "vldrepl.w $vr11, %[sv], 0\n\t" + "vilvl.b $vr10, $vr10, $vr10\n\t" + "vilvl.b $vr11, $vr11, $vr11\n\t" + "vilvl.b $vr1, $vr11, $vr10\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vsrli.b $vr2, $vr2, 3\n\t" + "vsrli.b $vr3, $vr3, 3\n\t" + "vsrli.b $vr4, $vr4, 3\n\t" + "vilvl.b $vr2, $vr2, $vr2\n\t" + "vilvl.b $vr3, $vr3, $vr3\n\t" + "vilvl.b $vr4, $vr4, $vr4\n\t" + "vand.v $vr2, $vr2, $vr14\n\t" + "vand.v $vr3, $vr3, $vr14\n\t" + "vand.v $vr4, $vr4, $vr14\n\t" + "vslli.h $vr3, $vr3, 5\n\t" + "vslli.h $vr4, $vr4, 10\n\t" + "vor.v $vr2, $vr2, $vr3\n\t" + "vor.v $vr2, $vr2, $vr4\n\t" + "vor.v $vr2, $vr2, $vr15\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[su], %[su], 4\n\t" + "addi.d %[sv], %[sv], 4\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr10", "$vr11", + "$vr14", "$vr15", "$vr20", "$vr21", "$vr22", "$vr23", "$vr24"); +} + +void NV12ToARGBRow_LSX(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vldi $vr5, 0xff\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vldrepl.d $vr1, %[suv], 0\n\t" + "vilvl.h $vr1, $vr1, $vr1\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vilvl.b $vr6, $vr3, $vr2\n\t" + "vilvl.b $vr7, $vr5, $vr4\n\t" + "vilvl.h $vr8, $vr7, $vr6\n\t" + "vilvh.h $vr9, $vr7, $vr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "vst $vr9, %[dst], 16\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[suv], %[suv], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [suv] "+r"(src_uv), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr20", "$vr21", "$vr22", "$vr23", "$vr24"); +} + +void NV21ToARGBRow_LSX(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vldi $vr5, 0xff\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vldrepl.d $vr1, %[suv], 0\n\t" + "vshuf4i.b $vr1, $vr1, 0xb1\n\t" + "vilvl.h $vr1, $vr1, $vr1\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vilvl.b $vr6, $vr3, $vr2\n\t" + "vilvl.b $vr7, $vr5, $vr4\n\t" + "vilvl.h $vr8, $vr7, $vr6\n\t" + "vilvh.h $vr9, $vr7, $vr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "vst $vr9, %[dst], 16\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[suv], %[suv], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [suv] "+r"(src_vu), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr20", "$vr21", "$vr22", "$vr23", "$vr24"); +} + +void NV12ToRGB565Row_LSX(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vldi $vr14, 31\n\t" + "vsrli.h $vr14, $vr14, 8\n\t" + "vldi $vr15, 63\n\t" + "vsrli.h $vr15, $vr15, 8\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vldrepl.d $vr1, %[suv], 0\n\t" + "vilvl.h $vr1, $vr1, $vr1\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vsrli.b $vr2, $vr2, 3\n\t" + "vsrli.b $vr3, $vr3, 2\n\t" + "vsrli.b $vr4, $vr4, 3\n\t" + "vilvl.b $vr2, $vr2, $vr2\n\t" + "vilvl.b $vr3, $vr3, $vr3\n\t" + "vilvl.b $vr4, $vr4, $vr4\n\t" + "vand.v $vr2, $vr2, $vr14\n\t" + "vand.v $vr3, $vr3, $vr15\n\t" + "vand.v $vr4, $vr4, $vr14\n\t" + "vslli.h $vr3, $vr3, 5\n\t" + "vslli.h $vr4, $vr4, 11\n\t" + "vor.v $vr2, $vr2, $vr3\n\t" + "vor.v $vr2, $vr2, $vr4\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[suv], %[suv], 8\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [suv] "+r"(src_uv), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr14", "$vr15", + "$vr20", "$vr21", "$vr22", "$vr23", "$vr24"); +} + +void I444ToARGBRow_LSX(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vldi $vr5, 0xff\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vldrepl.d $vr10, %[su], 0\n\t" + "vldrepl.d $vr11, %[sv], 0\n\t" + "vilvl.b $vr1, $vr11, $vr10\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vilvl.b $vr6, $vr3, $vr2\n\t" + "vilvl.b $vr7, $vr5, $vr4\n\t" + "vilvl.h $vr8, $vr7, $vr6\n\t" + "vilvh.h $vr9, $vr7, $vr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "vst $vr9, %[dst], 16\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[su], %[su], 8\n\t" + "addi.d %[sv], %[sv], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [su] "+r"(src_u), [sv] "+r"(src_v), + [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr20", "$vr21", "$vr22", + "$vr23", "$vr24"); +} + +void I400ToARGBRow_LSX(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vld $vr23, %[c], 96\n\t" + "vld $vr24, %[c], 128\n\t" + "vldi $vr5, 0xff\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sy], 0\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vssrani.bu.h $vr2, $vr0, 6\n\t" + "vilvl.b $vr6, $vr2, $vr2\n\t" + "vilvl.b $vr7, $vr5, $vr2\n\t" + "vilvl.h $vr8, $vr7, $vr6\n\t" + "vilvh.h $vr9, $vr7, $vr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "vst $vr9, %[dst], 16\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr2", "$vr5", "$vr6", "$vr7", "$vr8", "$vr9", + "$vr23", "$vr24"); +} + +void J400ToARGBRow_LSX(const uint8_t* src_y, uint8_t* dst_argb, int width) { + asm volatile( + "vldi $vr5, 0xff\n\t" + "1:\n\t" + "vldrepl.d $vr2, %[sy], 0\n\t" + "vilvl.b $vr6, $vr2, $vr2\n\t" + "vilvl.b $vr7, $vr5, $vr2\n\t" + "vilvl.h $vr8, $vr7, $vr6\n\t" + "vilvh.h $vr9, $vr7, $vr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "vst $vr9, %[dst], 16\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sy] "+r"(src_y), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$vr2", "$vr5", "$vr6", "$vr7", "$vr8", "$vr9"); +} + +void YUY2ToARGBRow_LSX(const uint8_t* src_yuy2, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vldi $vr5, 0xff\n\t" + "1:\n\t" + "vld $vr10, %[src], 0\n\t" + "vpickev.b $vr0, $vr10, $vr10\n\t" + "vpickod.b $vr1, $vr10, $vr10\n\t" + "vilvl.h $vr1, $vr1, $vr1\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vilvl.b $vr6, $vr3, $vr2\n\t" + "vilvl.b $vr7, $vr5, $vr4\n\t" + "vilvl.h $vr8, $vr7, $vr6\n\t" + "vilvh.h $vr9, $vr7, $vr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "vst $vr9, %[dst], 16\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_yuy2), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr20", "$vr21", "$vr22", "$vr23", + "$vr24"); +} + +void UYVYToARGBRow_LSX(const uint8_t* src_uyvy, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + "vldrepl.w $vr20, %[c], 0\n\t" + "vldrepl.w $vr21, %[c], 32\n\t" + "vldrepl.w $vr22, %[c], 64\n\t" + "vldrepl.h $vr23, %[c], 96\n\t" + "vldrepl.h $vr24, %[c], 128\n\t" + "vldi $vr5, 0xff\n\t" + "1:\n\t" + "vld $vr10, %[src], 0\n\t" + "vpickod.b $vr0, $vr10, $vr10\n\t" + "vpickev.b $vr1, $vr10, $vr10\n\t" + "vilvl.h $vr1, $vr1, $vr1\n\t" + "vilvl.b $vr0, $vr0, $vr0\n\t" + "vxori.b $vr1, $vr1, 0x80\n\t" + "vmuh.hu $vr0, $vr0, $vr23\n\t" + "vadd.h $vr0, $vr0, $vr24\n\t" + "vmulwev.h.bu.b $vr2, $vr20, $vr1\n\t" + "vmulwod.h.bu.b $vr4, $vr22, $vr1\n\t" + "vmulwev.h.bu.b $vr3, $vr21, $vr1\n\t" + "vmaddwod.h.bu.b $vr3, $vr21, $vr1\n\t" + "vsadd.h $vr2, $vr0, $vr2\n\t" + "vsadd.h $vr4, $vr0, $vr4\n\t" + "vssub.h $vr3, $vr0, $vr3\n\t" + "vssrani.bu.h $vr2, $vr2, 6\n\t" + "vssrani.bu.h $vr3, $vr3, 6\n\t" + "vssrani.bu.h $vr4, $vr4, 6\n\t" + "vilvl.b $vr6, $vr3, $vr2\n\t" + "vilvl.b $vr7, $vr5, $vr4\n\t" + "vilvl.h $vr8, $vr7, $vr6\n\t" + "vilvh.h $vr9, $vr7, $vr6\n\t" + "vst $vr8, %[dst], 0\n\t" + "vst $vr9, %[dst], 16\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_uyvy), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [c] "r"(yuvconstants) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr20", "$vr21", "$vr22", "$vr23", + "$vr24"); +} + +static LIBYUV_NOINLINE void ARGBTo24Helper_LSX(const uint8_t* src_argb, + uint8_t* dst_24, + const uint8_t* shuf, + int width) { + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 16\n\t" + "vld $vr2, %[src], 32\n\t" + "vld $vr3, %[src], 48\n\t" + "vshuf.b $vr0, $vr0, $vr0, $vr4\n\t" + "vshuf.b $vr1, $vr1, $vr1, $vr4\n\t" + "vshuf.b $vr2, $vr2, $vr2, $vr4\n\t" + "vshuf.b $vr3, $vr3, $vr3, $vr4\n\t" + "vstelm.d $vr0, %[dst], 0, 0\n\t" + "vstelm.w $vr0, %[dst], 8, 2\n\t" + "vstelm.w $vr1, %[dst], 12, 0\n\t" + "vstelm.w $vr1, %[dst], 16, 1\n\t" + "vstelm.w $vr1, %[dst], 20, 2\n\t" + "vstelm.d $vr2, %[dst], 24, 0\n\t" + "vstelm.w $vr2, %[dst], 32, 2\n\t" + "vstelm.w $vr3, %[dst], 36, 0\n\t" + "vstelm.w $vr3, %[dst], 40, 1\n\t" + "vstelm.w $vr3, %[dst], 44, 2\n\t" + "addi.d %[src], %[src], 64\n\t" + "addi.d %[dst], %[dst], 48\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_24), [cnt] "+r"(width) + : [shuf] "r"(shuf) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4"); +} + +void ARGBToRGB24Row_LSX(const uint8_t* src_argb, + uint8_t* dst_rgb24, + int width) { + static const uint8_t kShuf[16] = {0, 1, 2, 4, 5, 6, 8, 9, + 10, 12, 13, 14, 0, 0, 0, 0}; + ARGBTo24Helper_LSX(src_argb, dst_rgb24, kShuf, width); +} + +void ARGBToRAWRow_LSX(const uint8_t* src_argb, uint8_t* dst_raw, int width) { + static const uint8_t kShuf[16] = {2, 1, 0, 6, 5, 4, 10, 9, + 8, 14, 13, 12, 0, 0, 0, 0}; + ARGBTo24Helper_LSX(src_argb, dst_raw, kShuf, width); +} + +static LIBYUV_NOINLINE void RGB24ToARGBHelper_LSX(const uint8_t* src_24, + uint8_t* dst_argb, + const uint8_t* shuf, + int width) { + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "vld $vr5, %[shuf], 16\n\t" + "vldi $vr6, 0xff\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 12\n\t" + "vld $vr2, %[src], 24\n\t" + "vld $vr3, %[src], 32\n\t" + "vshuf.b $vr0, $vr6, $vr0, $vr4\n\t" + "vshuf.b $vr1, $vr6, $vr1, $vr4\n\t" + "vshuf.b $vr2, $vr6, $vr2, $vr4\n\t" + "vshuf.b $vr3, $vr6, $vr3, $vr5\n\t" + "vst $vr0, %[dst], 0\n\t" + "vst $vr1, %[dst], 16\n\t" + "vst $vr2, %[dst], 32\n\t" + "vst $vr3, %[dst], 48\n\t" + "addi.d %[src], %[src], 48\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_24), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [shuf] "r"(shuf) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6"); +} + +void RGB24ToARGBRow_LSX(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width) { + static const uint8_t kShuf[32] = {0, 1, 2, 16, 3, 4, 5, 16, 6, 7, 8, + 16, 9, 10, 11, 16, 4, 5, 6, 16, 7, 8, + 9, 16, 10, 11, 12, 16, 13, 14, 15, 16}; + RGB24ToARGBHelper_LSX(src_rgb24, dst_argb, kShuf, width); +} + +void RAWToARGBRow_LSX(const uint8_t* src_raw, uint8_t* dst_argb, int width) { + static const uint8_t kShuf[32] = {2, 1, 0, 16, 5, 4, 3, 16, 8, 7, 6, + 16, 11, 10, 9, 16, 6, 5, 4, 16, 9, 8, + 7, 16, 12, 11, 10, 16, 15, 14, 13, 16}; + RGB24ToARGBHelper_LSX(src_raw, dst_argb, kShuf, width); +} + +void RAWToRGB24Row_LSX(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { + static const uint8_t kShuf[32] = {2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, + 9, 0, 0, 0, 0, 6, 5, 4, 9, 8, 7, + 12, 11, 10, 15, 14, 13, 0, 0, 0, 0}; + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "vld $vr5, %[shuf], 16\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 12\n\t" + "vld $vr2, %[src], 24\n\t" + "vld $vr3, %[src], 32\n\t" + "vshuf.b $vr0, $vr0, $vr0, $vr4\n\t" + "vshuf.b $vr1, $vr1, $vr1, $vr4\n\t" + "vshuf.b $vr2, $vr2, $vr2, $vr4\n\t" + "vshuf.b $vr3, $vr3, $vr3, $vr5\n\t" + "vstelm.d $vr0, %[dst], 0, 0\n\t" + "vstelm.w $vr0, %[dst], 8, 2\n\t" + "vstelm.w $vr1, %[dst], 12, 0\n\t" + "vstelm.w $vr1, %[dst], 16, 1\n\t" + "vstelm.w $vr1, %[dst], 20, 2\n\t" + "vstelm.d $vr2, %[dst], 24, 0\n\t" + "vstelm.w $vr2, %[dst], 32, 2\n\t" + "vstelm.w $vr3, %[dst], 36, 0\n\t" + "vstelm.w $vr3, %[dst], 40, 1\n\t" + "vstelm.w $vr3, %[dst], 44, 2\n\t" + "addi.d %[src], %[src], 48\n\t" + "addi.d %[dst], %[dst], 48\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_raw), [dst] "+r"(dst_rgb24), [cnt] "+r"(width) + : [shuf] "r"(kShuf) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5"); +} + +void ARGBToRGB565Row_LSX(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { + asm volatile( + "vldi $vr6, 31\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "vldi $vr7, 63\n\t" + "vsrli.h $vr7, $vr7, 8\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 16\n\t" + "vpickev.b $vr2, $vr1, $vr0\n\t" + "vpickod.b $vr3, $vr1, $vr0\n\t" + "vsrli.b $vr2, $vr2, 3\n\t" + "vsrli.b $vr3, $vr3, 2\n\t" + "vand.v $vr4, $vr2, $vr6\n\t" + "vsrli.h $vr2, $vr2, 8\n\t" + "vand.v $vr3, $vr3, $vr7\n\t" + "vslli.h $vr3, $vr3, 5\n\t" + "vslli.h $vr2, $vr2, 11\n\t" + "vor.v $vr4, $vr4, $vr3\n\t" + "vor.v $vr4, $vr4, $vr2\n\t" + "vst $vr4, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_rgb), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr6", "$vr7"); +} + +void ARGBToRGB565DitherRow_LSX(const uint8_t* src_argb, + uint8_t* dst_rgb, + uint32_t dither4, + int width) { + asm volatile( + "vreplgr2vr.w $vr5, %[dith]\n\t" + "vilvl.b $vr5, $vr5, $vr5\n\t" + "vilvl.h $vr5, $vr5, $vr5\n\t" + "vldi $vr6, 31\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "vldi $vr7, 63\n\t" + "vsrli.h $vr7, $vr7, 8\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vsadd.bu $vr0, $vr0, $vr5\n\t" + "vpickev.b $vr2, $vr0, $vr0\n\t" + "vpickod.b $vr3, $vr0, $vr0\n\t" + "vsrli.b $vr2, $vr2, 3\n\t" + "vsrli.b $vr3, $vr3, 2\n\t" + "vand.v $vr4, $vr2, $vr6\n\t" + "vsrli.h $vr2, $vr2, 8\n\t" + "vand.v $vr3, $vr3, $vr7\n\t" + "vslli.h $vr3, $vr3, 5\n\t" + "vslli.h $vr2, $vr2, 11\n\t" + "vor.v $vr4, $vr4, $vr3\n\t" + "vor.v $vr4, $vr4, $vr2\n\t" + "vstelm.d $vr4, %[dst], 0, 0\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 8\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_rgb), [cnt] "+r"(width) + : [dith] "r"(dither4) + : "memory", "$vr0", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", "$vr7"); +} + +void ARGBToARGB1555Row_LSX(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width) { + asm volatile( + "vldi $vr6, 31\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 16\n\t" + "vpickev.b $vr2, $vr1, $vr0\n\t" + "vpickod.b $vr3, $vr1, $vr0\n\t" + "vsrli.b $vr2, $vr2, 3\n\t" + "vand.v $vr4, $vr2, $vr6\n\t" + "vsrli.h $vr2, $vr2, 8\n\t" + "vsrli.h $vr5, $vr3, 15\n\t" + "vsrli.b $vr3, $vr3, 3\n\t" + "vand.v $vr3, $vr3, $vr6\n\t" + "vslli.h $vr3, $vr3, 5\n\t" + "vslli.h $vr2, $vr2, 10\n\t" + "vslli.h $vr5, $vr5, 15\n\t" + "vor.v $vr4, $vr4, $vr3\n\t" + "vor.v $vr4, $vr4, $vr2\n\t" + "vor.v $vr4, $vr4, $vr5\n\t" + "vst $vr4, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_rgb), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6"); +} + +void ARGBToARGB4444Row_LSX(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 16\n\t" + "vpickev.b $vr2, $vr1, $vr0\n\t" + "vpickod.b $vr3, $vr1, $vr0\n\t" + "vsrli.b $vr2, $vr2, 4\n\t" + "vsrli.b $vr3, $vr3, 4\n\t" + "vslli.b $vr3, $vr3, 4\n\t" + "vor.v $vr2, $vr2, $vr3\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_rgb), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3"); +} + +void RGB565ToARGBRow_LSX(const uint8_t* src_rgb565, + uint8_t* dst_argb, + int width) { + asm volatile( + "vldi $vr6, 31\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "vldi $vr7, 63\n\t" + "vsrli.h $vr7, $vr7, 8\n\t" + "vldi $vr5, 0xff\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr7\n\t" + "vsrli.h $vr3, $vr0, 11\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 2\n\t" + "vsrli.h $vr2, $vr2, 4\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vpickev.b $vr1, $vr1, $vr1\n\t" + "vpickev.b $vr2, $vr2, $vr2\n\t" + "vpickev.b $vr3, $vr3, $vr3\n\t" + "vilvl.b $vr8, $vr2, $vr1\n\t" + "vilvl.b $vr9, $vr5, $vr3\n\t" + "vilvl.h $vr10, $vr9, $vr8\n\t" + "vilvh.h $vr11, $vr9, $vr8\n\t" + "vst $vr10, %[dst], 0\n\t" + "vst $vr11, %[dst], 16\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_rgb565), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11"); +} + +void ARGB1555ToARGBRow_LSX(const uint8_t* src_argb1555, + uint8_t* dst_argb, + int width) { + asm volatile( + "vldi $vr6, 31\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr6\n\t" + "vsrli.h $vr3, $vr0, 10\n\t" + "vand.v $vr3, $vr3, $vr6\n\t" + "vsrai.h $vr5, $vr0, 15\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 3\n\t" + "vsrli.h $vr2, $vr2, 2\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vpickev.b $vr1, $vr1, $vr1\n\t" + "vpickev.b $vr2, $vr2, $vr2\n\t" + "vpickev.b $vr3, $vr3, $vr3\n\t" + "vpickev.b $vr5, $vr5, $vr5\n\t" + "vilvl.b $vr8, $vr2, $vr1\n\t" + "vilvl.b $vr9, $vr5, $vr3\n\t" + "vilvl.h $vr10, $vr9, $vr8\n\t" + "vilvh.h $vr11, $vr9, $vr8\n\t" + "vst $vr10, %[dst], 0\n\t" + "vst $vr11, %[dst], 16\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb1555), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr8", "$vr9", "$vr10", "$vr11"); +} + +void ARGB4444ToARGBRow_LSX(const uint8_t* src_argb4444, + uint8_t* dst_argb, + int width) { + asm volatile( + "vldi $vr6, 0x0f\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.b $vr2, $vr0, 4\n\t" + "vslli.b $vr3, $vr1, 4\n\t" + "vor.v $vr1, $vr1, $vr3\n\t" + "vslli.b $vr3, $vr2, 4\n\t" + "vor.v $vr2, $vr2, $vr3\n\t" + "vilvl.b $vr4, $vr2, $vr1\n\t" + "vilvh.b $vr5, $vr2, $vr1\n\t" + "vst $vr4, %[dst], 0\n\t" + "vst $vr5, %[dst], 16\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb4444), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6"); +} + +void ARGBMultiplyRow_LSX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr1, %[s1], 0\n\t" + "vmulwev.h.bu $vr2, $vr0, $vr1\n\t" + "vmulwod.h.bu $vr3, $vr0, $vr1\n\t" + "vsrari.h $vr2, $vr2, 8\n\t" + "vsrari.h $vr3, $vr3, 8\n\t" + "vpackev.b $vr2, $vr3, $vr2\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 16\n\t" + "addi.d %[s1], %[s1], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb), [s1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3"); +} + +void ARGBAddRow_LSX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr1, %[s1], 0\n\t" + "vsadd.bu $vr0, $vr0, $vr1\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 16\n\t" + "addi.d %[s1], %[s1], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb), [s1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1"); +} + +void ARGBSubtractRow_LSX(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr1, %[s1], 0\n\t" + "vssub.bu $vr0, $vr0, $vr1\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 16\n\t" + "addi.d %[s1], %[s1], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb), [s1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1"); +} + +void ARGBAttenuateRow_LSX(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + static const uint8_t kAlpha[16] = {3, 3, 3, 16, 7, 7, 7, 16, + 11, 11, 11, 16, 15, 15, 15, 16}; + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "vldi $vr5, 0xff\n\t" + "vldi $vr6, 255\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vshuf.b $vr1, $vr5, $vr0, $vr4\n\t" + "vmulwev.h.bu $vr2, $vr0, $vr1\n\t" + "vmulwod.h.bu $vr3, $vr0, $vr1\n\t" + "vadd.h $vr2, $vr2, $vr6\n\t" + "vadd.h $vr3, $vr3, $vr6\n\t" + "vpackod.b $vr2, $vr3, $vr2\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [shuf] "r"(kAlpha) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6"); +} + +void ARGBBlendRow_LSX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + static const uint8_t kAlpha[16] = {3, 3, 3, 3, 7, 7, 7, 7, + 11, 11, 11, 11, 15, 15, 15, 15}; + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "vldi $vr5, 0xff\n\t" + "vslli.w $vr5, $vr5, 24\n\t" + "vldi $vr6, 1\n\t" + "vslli.h $vr6, $vr6, 8\n\t" + "vldi $vr8, 0\n\t" + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr1, %[s1], 0\n\t" + "vshuf.b $vr2, $vr0, $vr0, $vr4\n\t" + "vilvl.b $vr3, $vr8, $vr2\n\t" + "vilvh.b $vr2, $vr8, $vr2\n\t" + "vsub.h $vr3, $vr6, $vr3\n\t" + "vsub.h $vr2, $vr6, $vr2\n\t" + "vilvl.b $vr7, $vr8, $vr1\n\t" + "vilvh.b $vr1, $vr8, $vr1\n\t" + "vmul.h $vr7, $vr7, $vr3\n\t" + "vmul.h $vr1, $vr1, $vr2\n\t" + "vsrlni.b.h $vr1, $vr7, 8\n\t" + "vsadd.bu $vr0, $vr0, $vr1\n\t" + "vor.v $vr0, $vr0, $vr5\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 16\n\t" + "addi.d %[s1], %[s1], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb0), [s1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : [shuf] "r"(kAlpha) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8"); +} + +void ARGBOrRow_LSX(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + asm volatile( + "vreplgr2vr.w $vr1, %[val]\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vor.v $vr0, $vr0, $vr1\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [val] "r"(value) + : "memory", "$vr0", "$vr1"); +} + +void ARGBAlphaBlendRow_LSX(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + static const uint8_t kShufRatio[16] = {0, 0, 0, 0, 4, 4, 4, 4, + 8, 8, 8, 8, 12, 12, 12, 12}; + asm volatile( + "vld $vr8, %[shuf], 0\n\t" + "vldi $vr9, 1\n\t" + "vsrli.h $vr10, $vr9, 8\n\t" + "vldi $vr11, 0xff\n\t" + "vsrli.w $vr11, $vr11, 8\n\t" + "vldi $vr12, 0\n\t" + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr1, %[s1], 0\n\t" + "vsrli.w $vr2, $vr0, 24\n\t" + "vsrli.w $vr3, $vr1, 24\n\t" + "vmul.h $vr4, $vr3, $vr2\n\t" + "vadd.h $vr4, $vr4, $vr10\n\t" + "vmuh.hu $vr4, $vr4, $vr9\n\t" + "vsub.w $vr4, $vr2, $vr4\n\t" + "vadd.w $vr4, $vr3, $vr4\n\t" + "vseq.w $vr5, $vr3, $vr12\n\t" + "vsrli.w $vr5, $vr5, 24\n\t" + "vor.v $vr6, $vr2, $vr5\n\t" + "vor.v $vr7, $vr4, $vr5\n\t" + "vslli.w $vr5, $vr6, 8\n\t" + "vsub.w $vr5, $vr5, $vr6\n\t" + "vffint.s.wu $vr5, $vr5\n\t" + "vffint.s.wu $vr7, $vr7\n\t" + "vfdiv.s $vr5, $vr5, $vr7\n\t" + "vftintrz.wu.s $vr5, $vr5\n\t" + "vshuf.b $vr5, $vr5, $vr5, $vr8\n\t" + "vnor.v $vr6, $vr5, $vr5\n\t" + "vmulwev.h.bu $vr2, $vr1, $vr6\n\t" + "vmulwod.h.bu $vr3, $vr1, $vr6\n\t" + "vmulwev.h.bu $vr7, $vr0, $vr5\n\t" + "vmulwod.h.bu $vr0, $vr0, $vr5\n\t" + "vadd.h $vr2, $vr2, $vr7\n\t" + "vadd.h $vr3, $vr3, $vr0\n\t" + "vadd.h $vr2, $vr2, $vr10\n\t" + "vadd.h $vr3, $vr3, $vr10\n\t" + "vmuh.hu $vr2, $vr2, $vr9\n\t" + "vmuh.hu $vr3, $vr3, $vr9\n\t" + "vslli.h $vr3, $vr3, 8\n\t" + "vor.v $vr2, $vr2, $vr3\n\t" + "vand.v $vr2, $vr2, $vr11\n\t" + "vslli.w $vr4, $vr4, 24\n\t" + "vor.v $vr2, $vr2, $vr4\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 16\n\t" + "addi.d %[s1], %[s1], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb0), [s1] "+r"(src_argb1), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : [shuf] "r"(kShufRatio) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr12"); +} + +void ARGBShadeRow_LSX(const uint8_t* src_argb, + uint8_t* dst_argb, + int width, + uint32_t value) { + asm volatile( + "vreplgr2vr.w $vr4, %[val]\n\t" + "vilvl.b $vr5, $vr4, $vr4\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vilvl.b $vr1, $vr0, $vr0\n\t" + "vilvh.b $vr2, $vr0, $vr0\n\t" + "vmuh.hu $vr1, $vr1, $vr5\n\t" + "vmuh.hu $vr2, $vr2, $vr5\n\t" + "vsrlni.b.h $vr2, $vr1, 8\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [val] "r"(value) + : "memory", "$vr0", "$vr1", "$vr2", "$vr4", "$vr5"); +} + +void ARGBShuffleRow_LSX(const uint8_t* src_argb, + uint8_t* dst_argb, + const uint8_t* shuffler, + int width) { + asm volatile( + "vld $vr4, %[shuf], 0\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vshuf.b $vr0, $vr0, $vr0, $vr4\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [shuf] "r"(shuffler) + : "memory", "$vr0", "$vr4"); +} + +void ARGBGrayRow_LSX(const uint8_t* src_argb, uint8_t* dst_argb, int width) { + asm volatile( + "vldi $vr4, 29\n\t" + "vldi $vr5, 150\n\t" + "vldi $vr6, 77\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vld $vr1, %[src], 16\n\t" + "vpickev.b $vr2, $vr1, $vr0\n\t" + "vpickod.b $vr3, $vr1, $vr0\n\t" + "vmulwev.h.bu $vr7, $vr2, $vr4\n\t" + "vmaddwod.h.bu $vr7, $vr2, $vr6\n\t" + "vmaddwev.h.bu $vr7, $vr3, $vr5\n\t" + "vsrlri.h $vr7, $vr7, 8\n\t" + "vsrli.h $vr3, $vr3, 8\n\t" + "vslli.h $vr3, $vr3, 8\n\t" + "vor.v $vr3, $vr7, $vr3\n\t" + "vslli.h $vr8, $vr7, 8\n\t" + "vor.v $vr7, $vr7, $vr8\n\t" + "vilvl.h $vr0, $vr3, $vr7\n\t" + "vilvh.h $vr1, $vr3, $vr7\n\t" + "vst $vr0, %[dst], 0\n\t" + "vst $vr1, %[dst], 16\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8"); +} + +void ARGBSepiaRow_LSX(uint8_t* dst_argb, int width) { + asm volatile( + "vldi $vr4, 17\n\t" + "vldi $vr5, 68\n\t" + "vldi $vr6, 35\n\t" + "vldi $vr7, 22\n\t" + "vldi $vr8, 88\n\t" + "vldi $vr9, 45\n\t" + "vldi $vr10, 24\n\t" + "vldi $vr11, 98\n\t" + "vldi $vr12, 50\n\t" + "1:\n\t" + "vld $vr0, %[dst], 0\n\t" + "vld $vr1, %[dst], 16\n\t" + "vpickev.b $vr2, $vr1, $vr0\n\t" + "vpickod.b $vr3, $vr1, $vr0\n\t" + "vmulwev.h.bu $vr13, $vr2, $vr4\n\t" + "vmaddwod.h.bu $vr13, $vr2, $vr6\n\t" + "vmaddwev.h.bu $vr13, $vr3, $vr5\n\t" + "vmulwev.h.bu $vr14, $vr2, $vr7\n\t" + "vmaddwod.h.bu $vr14, $vr2, $vr9\n\t" + "vmaddwev.h.bu $vr14, $vr3, $vr8\n\t" + "vmulwev.h.bu $vr15, $vr2, $vr10\n\t" + "vmaddwod.h.bu $vr15, $vr2, $vr12\n\t" + "vmaddwev.h.bu $vr15, $vr3, $vr11\n\t" + "vsrli.h $vr13, $vr13, 7\n\t" + "vsrli.h $vr14, $vr14, 7\n\t" + "vsrli.h $vr15, $vr15, 7\n\t" + "vsat.hu $vr13, $vr13, 7\n\t" + "vsat.hu $vr14, $vr14, 7\n\t" + "vsat.hu $vr15, $vr15, 7\n\t" + "vpickev.b $vr13, $vr13, $vr13\n\t" + "vpickev.b $vr14, $vr14, $vr14\n\t" + "vpickev.b $vr15, $vr15, $vr15\n\t" + "vpickod.b $vr3, $vr3, $vr3\n\t" + "vilvl.b $vr2, $vr14, $vr13\n\t" + "vilvl.b $vr3, $vr3, $vr15\n\t" + "vilvl.h $vr0, $vr3, $vr2\n\t" + "vilvh.h $vr1, $vr3, $vr2\n\t" + "vst $vr0, %[dst], 0\n\t" + "vst $vr1, %[dst], 16\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [dst] "+r"(dst_argb), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr12", "$vr13", "$vr14", + "$vr15"); +} + +void ARGBColorMatrixRow_LSX(const uint8_t* src_argb, + uint8_t* dst_argb, + const int8_t* matrix_argb, + int width) { + asm volatile( + "vldrepl.w $vr4, %[mat], 0\n\t" + "vldrepl.w $vr5, %[mat], 4\n\t" + "vldrepl.w $vr6, %[mat], 8\n\t" + "vldrepl.w $vr7, %[mat], 12\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vmulwev.h.bu.b $vr8, $vr0, $vr4\n\t" + "vmaddwod.h.bu.b $vr8, $vr0, $vr4\n\t" + "vmulwev.h.bu.b $vr9, $vr0, $vr5\n\t" + "vmaddwod.h.bu.b $vr9, $vr0, $vr5\n\t" + "vmulwev.h.bu.b $vr10, $vr0, $vr6\n\t" + "vmaddwod.h.bu.b $vr10, $vr0, $vr6\n\t" + "vmulwev.h.bu.b $vr11, $vr0, $vr7\n\t" + "vmaddwod.h.bu.b $vr11, $vr0, $vr7\n\t" + "vhaddw.w.h $vr8, $vr8, $vr8\n\t" + "vhaddw.w.h $vr9, $vr9, $vr9\n\t" + "vhaddw.w.h $vr10, $vr10, $vr10\n\t" + "vhaddw.w.h $vr11, $vr11, $vr11\n\t" + "vilvl.w $vr12, $vr9, $vr8\n\t" + "vilvh.w $vr13, $vr9, $vr8\n\t" + "vilvl.w $vr14, $vr11, $vr10\n\t" + "vilvh.w $vr15, $vr11, $vr10\n\t" + "vilvl.d $vr8, $vr14, $vr12\n\t" + "vilvh.d $vr9, $vr14, $vr12\n\t" + "vilvl.d $vr10, $vr15, $vr13\n\t" + "vilvh.d $vr11, $vr15, $vr13\n\t" + "vssrani.h.w $vr9, $vr8, 6\n\t" + "vssrani.h.w $vr11, $vr10, 6\n\t" + "vssrani.bu.h $vr11, $vr9, 0\n\t" + "vst $vr11, %[dst], 0\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [mat] "r"(matrix_argb) + : "memory", "$vr0", "$vr4", "$vr5", "$vr6", "$vr7", "$vr8", "$vr9", + "$vr10", "$vr11", "$vr12", "$vr13", "$vr14", "$vr15"); +} + +void ARGBQuantizeRow_LSX(uint8_t* dst_argb, + int scale, + int interval_size, + int interval_offset, + int width) { + asm volatile( + "vreplgr2vr.h $vr4, %[scl]\n\t" + "vreplgr2vr.b $vr5, %[isz]\n\t" + "vreplgr2vr.b $vr6, %[ioff]\n\t" + "vldi $vr7, 0xff\n\t" + "vslli.w $vr7, $vr7, 24\n\t" + "1:\n\t" + "vld $vr0, %[dst], 0\n\t" + "vilvl.b $vr1, $vr0, $vr0\n\t" + "vilvh.b $vr2, $vr0, $vr0\n\t" + "vsrli.h $vr1, $vr1, 8\n\t" + "vsrli.h $vr2, $vr2, 8\n\t" + "vmuh.hu $vr1, $vr1, $vr4\n\t" + "vmuh.hu $vr2, $vr2, $vr4\n\t" + "vsrlni.b.h $vr2, $vr1, 0\n\t" + "vmul.b $vr2, $vr2, $vr5\n\t" + "vadd.b $vr2, $vr2, $vr6\n\t" + "vand.v $vr0, $vr0, $vr7\n\t" + "vandn.v $vr2, $vr7, $vr2\n\t" + "vor.v $vr2, $vr2, $vr0\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -4\n\t" + "bnez %[cnt], 1b\n\t" + : [dst] "+r"(dst_argb), [cnt] "+r"(width) + : [scl] "r"(scale), [isz] "r"(interval_size), [ioff] "r"(interval_offset) + : "memory", "$vr0", "$vr1", "$vr2", "$vr4", "$vr5", "$vr6", "$vr7"); +} + +void SobelRow_LSX(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_argb, + int width) { + asm volatile( + "vldi $vr4, 0xff\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sx], 0\n\t" + "vldrepl.d $vr1, %[sy], 0\n\t" + "vsadd.bu $vr0, $vr0, $vr1\n\t" + "vilvl.b $vr2, $vr0, $vr0\n\t" + "vilvl.b $vr3, $vr4, $vr0\n\t" + "vilvl.h $vr0, $vr3, $vr2\n\t" + "vilvh.h $vr1, $vr3, $vr2\n\t" + "vst $vr0, %[dst], 0\n\t" + "vst $vr1, %[dst], 16\n\t" + "addi.d %[sx], %[sx], 8\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sx] "+r"(src_sobelx), [sy] "+r"(src_sobely), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4"); +} + +void SobelToPlaneRow_LSX(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_y, + int width) { + asm volatile( + "1:\n\t" + "vld $vr0, %[sx], 0\n\t" + "vld $vr1, %[sy], 0\n\t" + "vsadd.bu $vr0, $vr0, $vr1\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[sx], %[sx], 16\n\t" + "addi.d %[sy], %[sy], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sx] "+r"(src_sobelx), [sy] "+r"(src_sobely), [dst] "+r"(dst_y), + [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1"); +} + +void SobelXYRow_LSX(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_argb, + int width) { + asm volatile( + "vldi $vr4, 0xff\n\t" + "1:\n\t" + "vldrepl.d $vr0, %[sx], 0\n\t" + "vldrepl.d $vr1, %[sy], 0\n\t" + "vsadd.bu $vr2, $vr0, $vr1\n\t" + "vilvl.b $vr1, $vr2, $vr1\n\t" + "vilvl.b $vr0, $vr4, $vr0\n\t" + "vilvl.h $vr2, $vr0, $vr1\n\t" + "vilvh.h $vr3, $vr0, $vr1\n\t" + "vst $vr2, %[dst], 0\n\t" + "vst $vr3, %[dst], 16\n\t" + "addi.d %[sx], %[sx], 8\n\t" + "addi.d %[sy], %[sy], 8\n\t" + "addi.d %[dst], %[dst], 32\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [sx] "+r"(src_sobelx), [sy] "+r"(src_sobely), [dst] "+r"(dst_argb), + [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4"); +} + +void InterpolateRow_LSX(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int32_t source_y_fraction) { + int y1_fraction = source_y_fraction; + const uint8_t* src_ptr1 = src_ptr + src_stride; + if (y1_fraction == 0) { + CopyRow_LSX(src_ptr, dst_ptr, width); + return; + } + if (y1_fraction == 128) { + asm volatile( + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr1, %[s1], 0\n\t" + "vavgr.bu $vr0, $vr0, $vr1\n\t" + "vst $vr0, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 16\n\t" + "addi.d %[s1], %[s1], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_ptr), [s1] "+r"(src_ptr1), [dst] "+r"(dst_ptr), + [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1"); + return; + } + uint16_t y_frac = (uint16_t)((256 - y1_fraction) + (y1_fraction << 8)); + asm volatile( + "vreplgr2vr.h $vr3, %[yf]\n\t" + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vld $vr1, %[s1], 0\n\t" + "vilvl.b $vr2, $vr1, $vr0\n\t" + "vilvh.b $vr4, $vr1, $vr0\n\t" + "vmulwev.h.bu $vr0, $vr2, $vr3\n\t" + "vmaddwod.h.bu $vr0, $vr2, $vr3\n\t" + "vmulwev.h.bu $vr1, $vr4, $vr3\n\t" + "vmaddwod.h.bu $vr1, $vr4, $vr3\n\t" + "vsrarni.b.h $vr1, $vr0, 8\n\t" + "vst $vr1, %[dst], 0\n\t" + "addi.d %[s0], %[s0], 16\n\t" + "addi.d %[s1], %[s1], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_ptr), [s1] "+r"(src_ptr1), [dst] "+r"(dst_ptr), + [cnt] "+r"(width) + : [yf] "r"(y_frac) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4"); +} + +void HalfFloatRow_LSX(const uint16_t* src, + uint16_t* dst, + float scale, + int width) { + const float bias = 1.9259299444e-34f; // 2^-112, see HalfFloatRow_C + asm volatile( + "vldrepl.w $vr3, %[scale], 0\n\t" + "vldrepl.w $vr5, %[bias], 0\n\t" + "vldi $vr4, 0\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vilvl.h $vr1, $vr4, $vr0\n\t" + "vilvh.h $vr2, $vr4, $vr0\n\t" + "vffint.s.wu $vr1, $vr1\n\t" + "vffint.s.wu $vr2, $vr2\n\t" + "vfmul.s $vr1, $vr1, $vr3\n\t" + "vfmul.s $vr2, $vr2, $vr3\n\t" + "vfmul.s $vr1, $vr1, $vr5\n\t" + "vfmul.s $vr2, $vr2, $vr5\n\t" + "vsrlni.h.w $vr2, $vr1, 13\n\t" + "vst $vr2, %[dst], 0\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src), [dst] "+r"(dst), [cnt] "+r"(width) + : [scale] "r"(&scale), [bias] "r"(&bias) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5"); +} + +void ARGBToYMatrixRow_LSX(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + asm volatile( + "vldrepl.b $vr0, %[c], 0\n\t" + "vldrepl.b $vr1, %[c], 1\n\t" + "vldrepl.b $vr2, %[c], 2\n\t" + "vldrepl.b $vr3, %[c], 3\n\t" + "vldrepl.h $vr4, %[c], 96\n\t" + "1:\n\t" + "vld $vr5, %[src], 0\n\t" + "vld $vr6, %[src], 16\n\t" + "vor.v $vr9, $vr4, $vr4\n\t" + "vpickev.b $vr7, $vr6, $vr5\n\t" + "vpickod.b $vr8, $vr6, $vr5\n\t" + "vmaddwev.h.bu $vr9, $vr7, $vr0\n\t" + "vmaddwev.h.bu $vr9, $vr8, $vr1\n\t" + "vmaddwod.h.bu $vr9, $vr7, $vr2\n\t" + "vmaddwod.h.bu $vr9, $vr8, $vr3\n\t" + "vpickod.b $vr9, $vr9, $vr9\n\t" + "vstelm.d $vr9, %[dst], 0, 0\n\t" + "addi.d %[src], %[src], 32\n\t" + "addi.d %[dst], %[dst], 8\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb), [dst] "+r"(dst_y), [cnt] "+r"(width) + : [c] "r"(c) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9"); +} + +void RGBToYMatrixRow_LSX(const uint8_t* src_rgba, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + static const uint8_t kShuf[32] = {0, 1, 2, 0, 3, 4, 5, 0, 6, 7, 8, + 0, 9, 10, 11, 0, 4, 5, 6, 0, 7, 8, + 9, 0, 10, 11, 12, 0, 13, 14, 15, 0}; + asm volatile( + "vldrepl.b $vr0, %[c], 0\n\t" + "vldrepl.b $vr1, %[c], 1\n\t" + "vldrepl.b $vr2, %[c], 2\n\t" + "vldrepl.h $vr3, %[c], 96\n\t" + "vld $vr4, %[shuf], 0\n\t" + "vld $vr5, %[shuf], 16\n\t" + "1:\n\t" + "vld $vr6, %[src], 0\n\t" + "vld $vr7, %[src], 12\n\t" + "vld $vr8, %[src], 24\n\t" + "vld $vr9, %[src], 32\n\t" + "vshuf.b $vr6, $vr6, $vr6, $vr4\n\t" + "vshuf.b $vr7, $vr7, $vr7, $vr4\n\t" + "vshuf.b $vr8, $vr8, $vr8, $vr4\n\t" + "vshuf.b $vr9, $vr9, $vr9, $vr5\n\t" + "vor.v $vr12, $vr3, $vr3\n\t" + "vor.v $vr13, $vr3, $vr3\n\t" + "vpickev.b $vr10, $vr7, $vr6\n\t" + "vpickod.b $vr11, $vr7, $vr6\n\t" + "vmaddwev.h.bu $vr12, $vr10, $vr0\n\t" + "vmaddwev.h.bu $vr12, $vr11, $vr1\n\t" + "vmaddwod.h.bu $vr12, $vr10, $vr2\n\t" + "vpickev.b $vr10, $vr9, $vr8\n\t" + "vpickod.b $vr11, $vr9, $vr8\n\t" + "vmaddwev.h.bu $vr13, $vr10, $vr0\n\t" + "vmaddwev.h.bu $vr13, $vr11, $vr1\n\t" + "vmaddwod.h.bu $vr13, $vr10, $vr2\n\t" + "vpickod.b $vr12, $vr13, $vr12\n\t" + "vst $vr12, %[dst], 0\n\t" + "addi.d %[src], %[src], 48\n\t" + "addi.d %[dst], %[dst], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_rgba), [dst] "+r"(dst_y), [cnt] "+r"(width) + : [c] "r"(c), [shuf] "r"(kShuf) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr12", "$vr13"); +} + +void RGB565ToYRow_LSX(const uint8_t* src_rgb565, uint8_t* dst_y, int width) { + asm volatile( + "vldi $vr6, 31\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "vldi $vr7, 63\n\t" + "vsrli.h $vr7, $vr7, 8\n\t" + "vldi $vr8, 25\n\t" + "vsrli.h $vr8, $vr8, 8\n\t" + "vldi $vr9, 129\n\t" + "vsrli.h $vr9, $vr9, 8\n\t" + "vldi $vr10, 66\n\t" + "vsrli.h $vr10, $vr10, 8\n\t" + "vldi $vr11, 33\n\t" + "vsrli.h $vr11, $vr11, 8\n\t" + "vslli.h $vr11, $vr11, 7\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr7\n\t" + "vsrli.h $vr3, $vr0, 11\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 2\n\t" + "vsrli.h $vr2, $vr2, 4\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vmul.h $vr1, $vr1, $vr8\n\t" + "vmadd.h $vr1, $vr2, $vr9\n\t" + "vmadd.h $vr1, $vr3, $vr10\n\t" + "vadd.h $vr1, $vr1, $vr11\n\t" + "vpickod.b $vr1, $vr1, $vr1\n\t" + "vstelm.d $vr1, %[dst], 0, 0\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 8\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_rgb565), [dst] "+r"(dst_y), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr6", "$vr7", + "$vr8", "$vr9", "$vr10", "$vr11"); +} + +void ARGB1555ToYRow_LSX(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width) { + asm volatile( + "vldi $vr6, 31\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "vldi $vr8, 25\n\t" + "vsrli.h $vr8, $vr8, 8\n\t" + "vldi $vr9, 129\n\t" + "vsrli.h $vr9, $vr9, 8\n\t" + "vldi $vr10, 66\n\t" + "vsrli.h $vr10, $vr10, 8\n\t" + "vldi $vr11, 33\n\t" + "vsrli.h $vr11, $vr11, 8\n\t" + "vslli.h $vr11, $vr11, 7\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr6\n\t" + "vsrli.h $vr3, $vr0, 10\n\t" + "vand.v $vr3, $vr3, $vr6\n\t" + "vsrai.h $vr5, $vr0, 15\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 3\n\t" + "vsrli.h $vr2, $vr2, 2\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vmul.h $vr1, $vr1, $vr8\n\t" + "vmadd.h $vr1, $vr2, $vr9\n\t" + "vmadd.h $vr1, $vr3, $vr10\n\t" + "vadd.h $vr1, $vr1, $vr11\n\t" + "vpickod.b $vr1, $vr1, $vr1\n\t" + "vstelm.d $vr1, %[dst], 0, 0\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[dst], %[dst], 8\n\t" + "addi.d %[cnt], %[cnt], -8\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src_argb1555), [dst] "+r"(dst_y), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr8", "$vr9", "$vr10", "$vr11"); +} + +void RGB565ToUVRow_LSX(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* next_rgb565 = src_rgb565 + src_stride_rgb565; + asm volatile( + "vldi $vr20, 112\n\t" + "vsrli.h $vr20, $vr20, 8\n\t" + "vldi $vr21, 74\n\t" + "vsrli.h $vr21, $vr21, 8\n\t" + "vldi $vr22, 38\n\t" + "vsrli.h $vr22, $vr22, 8\n\t" + "vldi $vr23, 94\n\t" + "vsrli.h $vr23, $vr23, 8\n\t" + "vldi $vr24, 18\n\t" + "vsrli.h $vr24, $vr24, 8\n\t" + "vldi $vr25, 128\n\t" + "vsrli.h $vr25, $vr25, 8\n\t" + "vslli.h $vr25, $vr25, 8\n\t" + "vldi $vr6, 31\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "vldi $vr7, 63\n\t" + "vsrli.h $vr7, $vr7, 8\n\t" + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr7\n\t" + "vsrli.h $vr3, $vr0, 11\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 2\n\t" + "vsrli.h $vr2, $vr2, 4\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vor.v $vr10, $vr1, $vr1\n\t" + "vor.v $vr11, $vr2, $vr2\n\t" + "vor.v $vr12, $vr3, $vr3\n\t" + "vld $vr0, %[s0], 16\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr7\n\t" + "vsrli.h $vr3, $vr0, 11\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 2\n\t" + "vsrli.h $vr2, $vr2, 4\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vpickev.b $vr10, $vr1, $vr10\n\t" + "vpickev.b $vr11, $vr2, $vr11\n\t" + "vpickev.b $vr12, $vr3, $vr12\n\t" + "vld $vr0, %[s1], 0\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr7\n\t" + "vsrli.h $vr3, $vr0, 11\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 2\n\t" + "vsrli.h $vr2, $vr2, 4\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vor.v $vr13, $vr1, $vr1\n\t" + "vor.v $vr14, $vr2, $vr2\n\t" + "vor.v $vr15, $vr3, $vr3\n\t" + "vld $vr0, %[s1], 16\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr7\n\t" + "vsrli.h $vr3, $vr0, 11\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 2\n\t" + "vsrli.h $vr2, $vr2, 4\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vpickev.b $vr5, $vr3, $vr15\n\t" + "vpickev.b $vr4, $vr2, $vr14\n\t" + "vpickev.b $vr3, $vr1, $vr13\n\t" + "vor.v $vr0, $vr10, $vr10\n\t" + "vor.v $vr1, $vr11, $vr11\n\t" + "vor.v $vr2, $vr12, $vr12\n\t" + "vhaddw.hu.bu $vr0, $vr0, $vr0\n\t" + "vhaddw.hu.bu $vr3, $vr3, $vr3\n\t" + "vadd.h $vr0, $vr0, $vr3\n\t" + "vsrari.h $vr0, $vr0, 2\n\t" + "vhaddw.hu.bu $vr1, $vr1, $vr1\n\t" + "vhaddw.hu.bu $vr4, $vr4, $vr4\n\t" + "vadd.h $vr1, $vr1, $vr4\n\t" + "vsrari.h $vr1, $vr1, 2\n\t" + "vhaddw.hu.bu $vr2, $vr2, $vr2\n\t" + "vhaddw.hu.bu $vr5, $vr5, $vr5\n\t" + "vadd.h $vr2, $vr2, $vr5\n\t" + "vsrari.h $vr2, $vr2, 2\n\t" + "vor.v $vr6, $vr25, $vr25\n\t" + "vor.v $vr7, $vr25, $vr25\n\t" + "vmadd.h $vr6, $vr0, $vr20\n\t" + "vmsub.h $vr6, $vr1, $vr21\n\t" + "vmsub.h $vr6, $vr2, $vr22\n\t" + "vmadd.h $vr7, $vr2, $vr20\n\t" + "vmsub.h $vr7, $vr1, $vr23\n\t" + "vmsub.h $vr7, $vr0, $vr24\n\t" + "vpickod.b $vr6, $vr7, $vr6\n\t" + "vstelm.d $vr6, %[du], 0, 0\n\t" + "vstelm.d $vr6, %[dv], 0, 1\n\t" + "vldi $vr6, 31\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "vldi $vr7, 63\n\t" + "vsrli.h $vr7, $vr7, 8\n\t" + "addi.d %[s0], %[s0], 32\n\t" + "addi.d %[s1], %[s1], 32\n\t" + "addi.d %[du], %[du], 8\n\t" + "addi.d %[dv], %[dv], 8\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_rgb565), [s1] "+r"(next_rgb565), [du] "+r"(dst_u), + [dv] "+r"(dst_v), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr10", "$vr11", "$vr12", "$vr13", "$vr14", "$vr15", "$vr20", + "$vr21", "$vr22", "$vr23", "$vr24", "$vr25"); +} + +void ARGB1555ToUVRow_LSX(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* next_argb1555 = src_argb1555 + src_stride_argb1555; + asm volatile( + "vldi $vr20, 112\n\t" + "vsrli.h $vr20, $vr20, 8\n\t" + "vldi $vr21, 74\n\t" + "vsrli.h $vr21, $vr21, 8\n\t" + "vldi $vr22, 38\n\t" + "vsrli.h $vr22, $vr22, 8\n\t" + "vldi $vr23, 94\n\t" + "vsrli.h $vr23, $vr23, 8\n\t" + "vldi $vr24, 18\n\t" + "vsrli.h $vr24, $vr24, 8\n\t" + "vldi $vr25, 128\n\t" + "vsrli.h $vr25, $vr25, 8\n\t" + "vslli.h $vr25, $vr25, 8\n\t" + "vldi $vr6, 31\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "1:\n\t" + "vld $vr0, %[s0], 0\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr6\n\t" + "vsrli.h $vr3, $vr0, 10\n\t" + "vand.v $vr3, $vr3, $vr6\n\t" + "vsrai.h $vr5, $vr0, 15\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 3\n\t" + "vsrli.h $vr2, $vr2, 2\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vor.v $vr10, $vr1, $vr1\n\t" + "vor.v $vr11, $vr2, $vr2\n\t" + "vor.v $vr12, $vr3, $vr3\n\t" + "vld $vr0, %[s0], 16\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr6\n\t" + "vsrli.h $vr3, $vr0, 10\n\t" + "vand.v $vr3, $vr3, $vr6\n\t" + "vsrai.h $vr5, $vr0, 15\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 3\n\t" + "vsrli.h $vr2, $vr2, 2\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vpickev.b $vr10, $vr1, $vr10\n\t" + "vpickev.b $vr11, $vr2, $vr11\n\t" + "vpickev.b $vr12, $vr3, $vr12\n\t" + "vld $vr0, %[s1], 0\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr6\n\t" + "vsrli.h $vr3, $vr0, 10\n\t" + "vand.v $vr3, $vr3, $vr6\n\t" + "vsrai.h $vr5, $vr0, 15\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 3\n\t" + "vsrli.h $vr2, $vr2, 2\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vor.v $vr13, $vr1, $vr1\n\t" + "vor.v $vr14, $vr2, $vr2\n\t" + "vor.v $vr15, $vr3, $vr3\n\t" + "vld $vr0, %[s1], 16\n\t" + "vand.v $vr1, $vr0, $vr6\n\t" + "vsrli.h $vr2, $vr0, 5\n\t" + "vand.v $vr2, $vr2, $vr6\n\t" + "vsrli.h $vr3, $vr0, 10\n\t" + "vand.v $vr3, $vr3, $vr6\n\t" + "vsrai.h $vr5, $vr0, 15\n\t" + "vslli.h $vr4, $vr1, 3\n\t" + "vsrli.h $vr1, $vr1, 2\n\t" + "vor.v $vr1, $vr4, $vr1\n\t" + "vslli.h $vr4, $vr2, 3\n\t" + "vsrli.h $vr2, $vr2, 2\n\t" + "vor.v $vr2, $vr4, $vr2\n\t" + "vslli.h $vr4, $vr3, 3\n\t" + "vsrli.h $vr3, $vr3, 2\n\t" + "vor.v $vr3, $vr4, $vr3\n\t" + "vpickev.b $vr5, $vr3, $vr15\n\t" + "vpickev.b $vr4, $vr2, $vr14\n\t" + "vpickev.b $vr3, $vr1, $vr13\n\t" + "vor.v $vr0, $vr10, $vr10\n\t" + "vor.v $vr1, $vr11, $vr11\n\t" + "vor.v $vr2, $vr12, $vr12\n\t" + "vhaddw.hu.bu $vr0, $vr0, $vr0\n\t" + "vhaddw.hu.bu $vr3, $vr3, $vr3\n\t" + "vadd.h $vr0, $vr0, $vr3\n\t" + "vsrari.h $vr0, $vr0, 2\n\t" + "vhaddw.hu.bu $vr1, $vr1, $vr1\n\t" + "vhaddw.hu.bu $vr4, $vr4, $vr4\n\t" + "vadd.h $vr1, $vr1, $vr4\n\t" + "vsrari.h $vr1, $vr1, 2\n\t" + "vhaddw.hu.bu $vr2, $vr2, $vr2\n\t" + "vhaddw.hu.bu $vr5, $vr5, $vr5\n\t" + "vadd.h $vr2, $vr2, $vr5\n\t" + "vsrari.h $vr2, $vr2, 2\n\t" + "vor.v $vr6, $vr25, $vr25\n\t" + "vor.v $vr7, $vr25, $vr25\n\t" + "vmadd.h $vr6, $vr0, $vr20\n\t" + "vmsub.h $vr6, $vr1, $vr21\n\t" + "vmsub.h $vr6, $vr2, $vr22\n\t" + "vmadd.h $vr7, $vr2, $vr20\n\t" + "vmsub.h $vr7, $vr1, $vr23\n\t" + "vmsub.h $vr7, $vr0, $vr24\n\t" + "vpickod.b $vr6, $vr7, $vr6\n\t" + "vstelm.d $vr6, %[du], 0, 0\n\t" + "vstelm.d $vr6, %[dv], 0, 1\n\t" + "vldi $vr6, 31\n\t" + "vsrli.h $vr6, $vr6, 8\n\t" + "addi.d %[s0], %[s0], 32\n\t" + "addi.d %[s1], %[s1], 32\n\t" + "addi.d %[du], %[du], 8\n\t" + "addi.d %[dv], %[dv], 8\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src_argb1555), [s1] "+r"(next_argb1555), [du] "+r"(dst_u), + [dv] "+r"(dst_v), [cnt] "+r"(width) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr10", "$vr11", "$vr12", "$vr13", "$vr14", "$vr15", "$vr20", + "$vr21", "$vr22", "$vr23", "$vr24", "$vr25"); +} + +static LIBYUV_NOINLINE void XRGBToUVHelper_LSX(const uint8_t* src, + int stride, + uint8_t* dst_u, + uint8_t* dst_v, + const uint8_t* shuf, + int width) { + const uint8_t* next = src + stride; + asm volatile( + "vldi $vr20, 112\n\t" + "vsrli.h $vr20, $vr20, 8\n\t" + "vldi $vr21, 74\n\t" + "vsrli.h $vr21, $vr21, 8\n\t" + "vldi $vr22, 38\n\t" + "vsrli.h $vr22, $vr22, 8\n\t" + "vldi $vr23, 94\n\t" + "vsrli.h $vr23, $vr23, 8\n\t" + "vldi $vr24, 18\n\t" + "vsrli.h $vr24, $vr24, 8\n\t" + "vldi $vr25, 128\n\t" + "vsrli.h $vr25, $vr25, 8\n\t" + "vslli.h $vr25, $vr25, 8\n\t" + "vld $vr16, %[shuf], 0\n\t" + "1:\n\t" + "vld $vr8, %[s0], 0\n\t" + "vld $vr9, %[s0], 16\n\t" + "vld $vr10, %[s0], 32\n\t" + "vld $vr11, %[s0], 48\n\t" + "vshuf.b $vr8, $vr8, $vr8, $vr16\n\t" + "vshuf.b $vr9, $vr9, $vr9, $vr16\n\t" + "vshuf.b $vr10, $vr10, $vr10, $vr16\n\t" + "vshuf.b $vr11, $vr11, $vr11, $vr16\n\t" + "vpickev.b $vr12, $vr9, $vr8\n\t" + "vpickod.b $vr13, $vr9, $vr8\n\t" + "vpickev.b $vr14, $vr11, $vr10\n\t" + "vpickod.b $vr15, $vr11, $vr10\n\t" + "vpickev.b $vr0, $vr14, $vr12\n\t" + "vpickod.b $vr2, $vr14, $vr12\n\t" + "vpickev.b $vr1, $vr15, $vr13\n\t" + "vld $vr8, %[s1], 0\n\t" + "vld $vr9, %[s1], 16\n\t" + "vld $vr10, %[s1], 32\n\t" + "vld $vr11, %[s1], 48\n\t" + "vshuf.b $vr8, $vr8, $vr8, $vr16\n\t" + "vshuf.b $vr9, $vr9, $vr9, $vr16\n\t" + "vshuf.b $vr10, $vr10, $vr10, $vr16\n\t" + "vshuf.b $vr11, $vr11, $vr11, $vr16\n\t" + "vpickev.b $vr12, $vr9, $vr8\n\t" + "vpickod.b $vr13, $vr9, $vr8\n\t" + "vpickev.b $vr14, $vr11, $vr10\n\t" + "vpickod.b $vr15, $vr11, $vr10\n\t" + "vpickev.b $vr3, $vr14, $vr12\n\t" + "vpickod.b $vr5, $vr14, $vr12\n\t" + "vpickev.b $vr4, $vr15, $vr13\n\t" + "vhaddw.hu.bu $vr0, $vr0, $vr0\n\t" + "vhaddw.hu.bu $vr3, $vr3, $vr3\n\t" + "vadd.h $vr0, $vr0, $vr3\n\t" + "vsrari.h $vr0, $vr0, 2\n\t" + "vhaddw.hu.bu $vr1, $vr1, $vr1\n\t" + "vhaddw.hu.bu $vr4, $vr4, $vr4\n\t" + "vadd.h $vr1, $vr1, $vr4\n\t" + "vsrari.h $vr1, $vr1, 2\n\t" + "vhaddw.hu.bu $vr2, $vr2, $vr2\n\t" + "vhaddw.hu.bu $vr5, $vr5, $vr5\n\t" + "vadd.h $vr2, $vr2, $vr5\n\t" + "vsrari.h $vr2, $vr2, 2\n\t" + "vor.v $vr6, $vr25, $vr25\n\t" + "vor.v $vr7, $vr25, $vr25\n\t" + "vmadd.h $vr6, $vr0, $vr20\n\t" + "vmsub.h $vr6, $vr1, $vr21\n\t" + "vmsub.h $vr6, $vr2, $vr22\n\t" + "vmadd.h $vr7, $vr2, $vr20\n\t" + "vmsub.h $vr7, $vr1, $vr23\n\t" + "vmsub.h $vr7, $vr0, $vr24\n\t" + "vpickod.b $vr6, $vr7, $vr6\n\t" + "vstelm.d $vr6, %[du], 0, 0\n\t" + "vstelm.d $vr6, %[dv], 0, 1\n\t" + "addi.d %[s0], %[s0], 64\n\t" + "addi.d %[s1], %[s1], 64\n\t" + "addi.d %[du], %[du], 8\n\t" + "addi.d %[dv], %[dv], 8\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src), [s1] "+r"(next), [du] "+r"(dst_u), [dv] "+r"(dst_v), + [cnt] "+r"(width) + : [shuf] "r"(shuf) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr12", "$vr13", "$vr14", + "$vr15", "$vr16", "$vr20", "$vr21", "$vr22", "$vr23", "$vr24", "$vr25"); +} + +void BGRAToUVRow_LSX(const uint8_t* src_bgra, + int src_stride_bgra, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kShuf[16] = {3, 2, 1, 0, 7, 6, 5, 4, + 11, 10, 9, 8, 15, 14, 13, 12}; + XRGBToUVHelper_LSX(src_bgra, src_stride_bgra, dst_u, dst_v, kShuf, width); +} + +void ABGRToUVRow_LSX(const uint8_t* src_abgr, + int src_stride_abgr, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kShuf[16] = {2, 1, 0, 3, 6, 5, 4, 7, + 10, 9, 8, 11, 14, 13, 12, 15}; + XRGBToUVHelper_LSX(src_abgr, src_stride_abgr, dst_u, dst_v, kShuf, width); +} + +void RGBAToUVRow_LSX(const uint8_t* src_rgba, + int src_stride_rgba, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kShuf[16] = {1, 2, 3, 0, 5, 6, 7, 4, + 9, 10, 11, 8, 13, 14, 15, 12}; + XRGBToUVHelper_LSX(src_rgba, src_stride_rgba, dst_u, dst_v, kShuf, width); +} + +static LIBYUV_NOINLINE void RGB24ToUVHelper_LSX(const uint8_t* src, + int stride, + uint8_t* dst_u, + uint8_t* dst_v, + const uint8_t* shuf, + int width) { + const uint8_t* next = src + stride; + asm volatile( + "vldi $vr20, 112\n\t" + "vsrli.h $vr20, $vr20, 8\n\t" + "vldi $vr21, 74\n\t" + "vsrli.h $vr21, $vr21, 8\n\t" + "vldi $vr22, 38\n\t" + "vsrli.h $vr22, $vr22, 8\n\t" + "vldi $vr23, 94\n\t" + "vsrli.h $vr23, $vr23, 8\n\t" + "vldi $vr24, 18\n\t" + "vsrli.h $vr24, $vr24, 8\n\t" + "vldi $vr25, 128\n\t" + "vsrli.h $vr25, $vr25, 8\n\t" + "vslli.h $vr25, $vr25, 8\n\t" + "vld $vr16, %[shuf], 0\n\t" + "vld $vr17, %[shuf], 16\n\t" + "1:\n\t" + "vld $vr8, %[s0], 0\n\t" + "vld $vr9, %[s0], 12\n\t" + "vld $vr10, %[s0], 24\n\t" + "vld $vr11, %[s0], 32\n\t" + "vshuf.b $vr8, $vr8, $vr8, $vr16\n\t" + "vshuf.b $vr9, $vr9, $vr9, $vr16\n\t" + "vshuf.b $vr10, $vr10, $vr10, $vr16\n\t" + "vshuf.b $vr11, $vr11, $vr11, $vr17\n\t" + "vpickev.b $vr12, $vr9, $vr8\n\t" + "vpickod.b $vr13, $vr9, $vr8\n\t" + "vpickev.b $vr14, $vr11, $vr10\n\t" + "vpickod.b $vr15, $vr11, $vr10\n\t" + "vpickev.b $vr0, $vr14, $vr12\n\t" + "vpickod.b $vr2, $vr14, $vr12\n\t" + "vpickev.b $vr1, $vr15, $vr13\n\t" + "vld $vr8, %[s1], 0\n\t" + "vld $vr9, %[s1], 12\n\t" + "vld $vr10, %[s1], 24\n\t" + "vld $vr11, %[s1], 32\n\t" + "vshuf.b $vr8, $vr8, $vr8, $vr16\n\t" + "vshuf.b $vr9, $vr9, $vr9, $vr16\n\t" + "vshuf.b $vr10, $vr10, $vr10, $vr16\n\t" + "vshuf.b $vr11, $vr11, $vr11, $vr17\n\t" + "vpickev.b $vr12, $vr9, $vr8\n\t" + "vpickod.b $vr13, $vr9, $vr8\n\t" + "vpickev.b $vr14, $vr11, $vr10\n\t" + "vpickod.b $vr15, $vr11, $vr10\n\t" + "vpickev.b $vr3, $vr14, $vr12\n\t" + "vpickod.b $vr5, $vr14, $vr12\n\t" + "vpickev.b $vr4, $vr15, $vr13\n\t" + "vhaddw.hu.bu $vr0, $vr0, $vr0\n\t" + "vhaddw.hu.bu $vr3, $vr3, $vr3\n\t" + "vadd.h $vr0, $vr0, $vr3\n\t" + "vsrari.h $vr0, $vr0, 2\n\t" + "vhaddw.hu.bu $vr1, $vr1, $vr1\n\t" + "vhaddw.hu.bu $vr4, $vr4, $vr4\n\t" + "vadd.h $vr1, $vr1, $vr4\n\t" + "vsrari.h $vr1, $vr1, 2\n\t" + "vhaddw.hu.bu $vr2, $vr2, $vr2\n\t" + "vhaddw.hu.bu $vr5, $vr5, $vr5\n\t" + "vadd.h $vr2, $vr2, $vr5\n\t" + "vsrari.h $vr2, $vr2, 2\n\t" + "vor.v $vr6, $vr25, $vr25\n\t" + "vor.v $vr7, $vr25, $vr25\n\t" + "vmadd.h $vr6, $vr0, $vr20\n\t" + "vmsub.h $vr6, $vr1, $vr21\n\t" + "vmsub.h $vr6, $vr2, $vr22\n\t" + "vmadd.h $vr7, $vr2, $vr20\n\t" + "vmsub.h $vr7, $vr1, $vr23\n\t" + "vmsub.h $vr7, $vr0, $vr24\n\t" + "vpickod.b $vr6, $vr7, $vr6\n\t" + "vstelm.d $vr6, %[du], 0, 0\n\t" + "vstelm.d $vr6, %[dv], 0, 1\n\t" + "addi.d %[s0], %[s0], 48\n\t" + "addi.d %[s1], %[s1], 48\n\t" + "addi.d %[du], %[du], 8\n\t" + "addi.d %[dv], %[dv], 8\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [s0] "+r"(src), [s1] "+r"(next), [du] "+r"(dst_u), [dv] "+r"(dst_v), + [cnt] "+r"(width) + : [shuf] "r"(shuf) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr12", "$vr13", "$vr14", + "$vr15", "$vr16", "$vr17", "$vr20", "$vr21", "$vr22", "$vr23", "$vr24", + "$vr25"); +} + +void RGB24ToUVRow_LSX(const uint8_t* src_rgb24, + int src_stride_rgb24, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kShuf[32] = {0, 1, 2, 0, 3, 4, 5, 0, 6, 7, 8, + 0, 9, 10, 11, 0, 4, 5, 6, 0, 7, 8, + 9, 0, 10, 11, 12, 0, 13, 14, 15, 0}; + RGB24ToUVHelper_LSX(src_rgb24, src_stride_rgb24, dst_u, dst_v, kShuf, width); +} + +void RAWToUVRow_LSX(const uint8_t* src_raw, + int src_stride_raw, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kShuf[32] = {2, 1, 0, 0, 5, 4, 3, 0, 8, 7, 6, + 0, 11, 10, 9, 0, 6, 5, 4, 0, 9, 8, + 7, 0, 12, 11, 10, 0, 15, 14, 13, 0}; + RGB24ToUVHelper_LSX(src_raw, src_stride_raw, dst_u, dst_v, kShuf, width); +} + +#ifdef HAS_SSIM4X4ROW_LSX +void Ssim4x4Row_LSX(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + const uint8_t* pa; + const uint8_t* pb; + int r; + asm volatile( + "1:\n\t" + "move %[pa], %[sa]\n\t" + "move %[pb], %[sb]\n\t" + "li.d %[r], 4\n\t" + "vxor.v $vr8, $vr8, $vr8\n\t" + "vxor.v $vr9, $vr9, $vr9\n\t" + "vxor.v $vr10, $vr10, $vr10\n\t" + "vxor.v $vr11, $vr11, $vr11\n\t" + "2:\n\t" + "vld $vr0, %[pa], 0\n\t" + "vld $vr1, %[pb], 0\n\t" + "add.d %[pa], %[pa], %[sta]\n\t" + "add.d %[pb], %[pb], %[stb]\n\t" + "vhaddw.hu.bu $vr2, $vr0, $vr0\n\t" + "vhaddw.hu.bu $vr3, $vr1, $vr1\n\t" + "vadd.h $vr8, $vr8, $vr2\n\t" + "vadd.h $vr9, $vr9, $vr3\n\t" + "vmulwev.h.bu $vr2, $vr0, $vr1\n\t" + "vmulwod.h.bu $vr3, $vr0, $vr1\n\t" + "vhaddw.wu.hu $vr2, $vr2, $vr2\n\t" + "vhaddw.wu.hu $vr3, $vr3, $vr3\n\t" + "vadd.w $vr11, $vr11, $vr2\n\t" + "vadd.w $vr11, $vr11, $vr3\n\t" + "vmulwev.h.bu $vr2, $vr0, $vr0\n\t" + "vmulwod.h.bu $vr3, $vr0, $vr0\n\t" + "vmulwev.h.bu $vr4, $vr1, $vr1\n\t" + "vmulwod.h.bu $vr5, $vr1, $vr1\n\t" + "vhaddw.wu.hu $vr2, $vr2, $vr2\n\t" + "vhaddw.wu.hu $vr3, $vr3, $vr3\n\t" + "vhaddw.wu.hu $vr4, $vr4, $vr4\n\t" + "vhaddw.wu.hu $vr5, $vr5, $vr5\n\t" + "vadd.w $vr2, $vr2, $vr3\n\t" + "vadd.w $vr4, $vr4, $vr5\n\t" + "vadd.w $vr10, $vr10, $vr2\n\t" + "vadd.w $vr10, $vr10, $vr4\n\t" + "addi.d %[r], %[r], -1\n\t" + "bnez %[r], 2b\n\t" + "vhaddw.wu.hu $vr8, $vr8, $vr8\n\t" + "vhaddw.wu.hu $vr9, $vr9, $vr9\n\t" + "vilvl.w $vr0, $vr9, $vr8\n\t" + "vilvh.w $vr1, $vr9, $vr8\n\t" + "vilvl.w $vr2, $vr11, $vr10\n\t" + "vilvh.w $vr3, $vr11, $vr10\n\t" + "vilvl.d $vr4, $vr2, $vr0\n\t" + "vilvh.d $vr5, $vr2, $vr0\n\t" + "vilvl.d $vr6, $vr3, $vr1\n\t" + "vilvh.d $vr7, $vr3, $vr1\n\t" + "vst $vr4, %[dst], 0\n\t" + "vst $vr5, %[dst], 16\n\t" + "vst $vr6, %[dst], 32\n\t" + "vst $vr7, %[dst], 48\n\t" + "addi.d %[sa], %[sa], 16\n\t" + "addi.d %[sb], %[sb], 16\n\t" + "addi.d %[dst], %[dst], 64\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [sa] "+r"(src_a), [sb] "+r"(src_b), [dst] "+r"(dst), [cnt] "+r"(width), + [pa] "=&r"(pa), [pb] "=&r"(pb), [r] "=&r"(r) + : [sta] "r"((ptrdiff_t)stride_a), [stb] "r"((ptrdiff_t)stride_b) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11"); +} +#endif // HAS_SSIM4X4ROW_LSX + +#ifdef HAS_SSIMWINDOWROW_LSX +float SsimWindowRow_LSX(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + const uint32_t* row0_next = row0 + 4; + const uint32_t* row1_next = row1 + 4; + float total; + uint32_t c1 = 26634; + uint32_t c2 = 239708; + uint32_t c0 = 0; + asm volatile( + "vreplgr2vr.w $vr6, %[c0]\n\t" + "vreplgr2vr.w $vr4, %[c1]\n\t" + "vreplgr2vr.w $vr5, %[c2]\n\t" + "1:\n\t" + "vld $vr0, %[r0], 0\n\t" + "vld $vr1, %[r0n], 0\n\t" + "vld $vr2, %[r1], 0\n\t" + "vld $vr3, %[r1n], 0\n\t" + "vadd.w $vr0, $vr0, $vr1\n\t" + "vadd.w $vr2, $vr2, $vr3\n\t" + "vadd.w $vr0, $vr0, $vr2\n\t" + "vshuf4i.w $vr1, $vr0, 0x00\n\t" + "vshuf4i.w $vr2, $vr0, 0x55\n\t" + "vshuf4i.w $vr3, $vr0, 0xaa\n\t" + "vshuf4i.w $vr0, $vr0, 0xff\n\t" + "vmul.w $vr7, $vr1, $vr2\n\t" + "vslli.w $vr7, $vr7, 1\n\t" + "vmul.w $vr1, $vr1, $vr1\n\t" + "vmadd.w $vr1, $vr2, $vr2\n\t" + "vslli.w $vr0, $vr0, 7\n\t" + "vsub.w $vr0, $vr0, $vr7\n\t" + "vadd.w $vr7, $vr7, $vr4\n\t" + "vadd.w $vr0, $vr0, $vr5\n\t" + "vslli.w $vr3, $vr3, 6\n\t" + "vsub.w $vr3, $vr3, $vr1\n\t" + "vadd.w $vr1, $vr1, $vr4\n\t" + "vadd.w $vr3, $vr3, $vr5\n\t" + "vffint.s.w $vr7, $vr7\n\t" + "vffint.s.w $vr0, $vr0\n\t" + "vffint.s.w $vr1, $vr1\n\t" + "vffint.s.w $vr3, $vr3\n\t" + "vfmul.s $vr7, $vr7, $vr0\n\t" + "vfmul.s $vr1, $vr1, $vr3\n\t" + "vfdiv.s $vr7, $vr7, $vr1\n\t" + "vfadd.s $vr6, $vr6, $vr7\n\t" + "addi.d %[r0], %[r0], 16\n\t" + "addi.d %[r0n], %[r0n], 16\n\t" + "addi.d %[r1], %[r1], 16\n\t" + "addi.d %[r1n], %[r1n], 16\n\t" + "addi.d %[cnt], %[cnt], -1\n\t" + "bnez %[cnt], 1b\n\t" + "vstelm.w $vr6, %[tot], 0, 0\n\t" + : [r0] "+r"(row0), [r0n] "+r"(row0_next), [r1] "+r"(row1), + [r1n] "+r"(row1_next), [cnt] "+r"(num_windows) + : [c0] "r"(c0), [c1] "r"(c1), [c2] "r"(c2), [tot] "r"(&total) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7"); + return total; +} +#endif // HAS_SSIMWINDOWROW_LSX + +#ifdef HAS_ARGBDETECTROW_LSX +uint32_t ARGBDetectRow_LSX(const uint8_t* argb, int width) { + uint32_t diff = 0; + uint32_t rgb_mask = 0x00ffff00u; + asm volatile( + "vreplgr2vr.w $vr2, %[rgb_mask]\n\t" + "vldi $vr3, -1\n\t" + "addi.d %[w], %[w], -4\n\t" + "bltz %[w], 2f\n\t" + "1:\n\t" + "vld $vr0, %[argb], 0\n\t" + "addi.d %[argb], %[argb], 16\n\t" + "vor.v $vr0, $vr0, $vr2\n\t" + "vseq.b $vr0, $vr0, $vr3\n\t" + "vmskltz.b $vr0, $vr0\n\t" + "vpickve2gr.hu %[diff], $vr0, 0\n\t" + "nor %[diff], %[diff], $zero\n\t" + "bstrpick.w %[diff], %[diff], 15, 0\n\t" + "bnez %[diff], 4f\n\t" + "addi.d %[w], %[w], -4\n\t" + "bgez %[w], 1b\n\t" + "2:\n\t" + "addi.d %[w], %[w], 4\n\t" + "beqz %[w], 4f\n\t" + "3:\n\t" + "vldrepl.w $vr0, %[argb], 0\n\t" + "addi.d %[argb], %[argb], 4\n\t" + "vor.v $vr0, $vr0, $vr2\n\t" + "vseq.b $vr0, $vr0, $vr3\n\t" + "vmskltz.b $vr0, $vr0\n\t" + "vpickve2gr.hu %[diff], $vr0, 0\n\t" + "nor %[diff], %[diff], $zero\n\t" + "bstrpick.w %[diff], %[diff], 15, 0\n\t" + "bnez %[diff], 4f\n\t" + "addi.d %[w], %[w], -1\n\t" + "bnez %[w], 3b\n\t" + "4:\n\t" + : [argb] "+r"(argb), [w] "+r"(width), [diff] "+r"(diff) + : [rgb_mask] "r"(rgb_mask) + : "memory", "$vr0", "$vr2", "$vr3"); + if (diff) { + return (__builtin_ctz(diff) & 3) == 0 ? FOURCC_BGRA : FOURCC_ARGB; + } + return 0; +} +#endif // HAS_ARGBDETECTROW_LSX + +#ifdef HAS_HAMMINGDISTANCE_LSX +uint32_t HammingDistance_LSX(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t diff; + asm volatile( + "vxor.v $vr4, $vr4, $vr4\n\t" + "1:\n\t" + "vld $vr0, %[sa], 0\n\t" + "vld $vr1, %[sb], 0\n\t" + "vxor.v $vr0, $vr0, $vr1\n\t" + "vpcnt.b $vr0, $vr0\n\t" + "vhaddw.hu.bu $vr0, $vr0, $vr0\n\t" + "vhaddw.wu.hu $vr0, $vr0, $vr0\n\t" + "vadd.w $vr4, $vr4, $vr0\n\t" + "addi.d %[sa], %[sa], 16\n\t" + "addi.d %[sb], %[sb], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + "vhaddw.du.wu $vr4, $vr4, $vr4\n\t" + "vhaddw.qu.du $vr4, $vr4, $vr4\n\t" + "vpickve2gr.wu %[diff], $vr4, 0\n\t" + : [sa] "+r"(src_a), [sb] "+r"(src_b), [cnt] "+r"(count), [diff] "=r"(diff) + : + : "memory", "$vr0", "$vr1", "$vr4"); + return diff; +} +#endif // HAS_HAMMINGDISTANCE_LSX + +#ifdef HAS_SUMSQUAREERROR_LSX +uint32_t SumSquareError_LSX(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t sse; + asm volatile( + "vxor.v $vr4, $vr4, $vr4\n\t" + "1:\n\t" + "vld $vr0, %[sa], 0\n\t" + "vld $vr1, %[sb], 0\n\t" + "vabsd.bu $vr0, $vr0, $vr1\n\t" + "vmulwev.h.bu $vr2, $vr0, $vr0\n\t" + "vmulwod.h.bu $vr3, $vr0, $vr0\n\t" + "vhaddw.wu.hu $vr2, $vr2, $vr2\n\t" + "vhaddw.wu.hu $vr3, $vr3, $vr3\n\t" + "vadd.w $vr4, $vr4, $vr2\n\t" + "vadd.w $vr4, $vr4, $vr3\n\t" + "addi.d %[sa], %[sa], 16\n\t" + "addi.d %[sb], %[sb], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + "vhaddw.du.wu $vr4, $vr4, $vr4\n\t" + "vhaddw.qu.du $vr4, $vr4, $vr4\n\t" + "vpickve2gr.wu %[sse], $vr4, 0\n\t" + : [sa] "+r"(src_a), [sb] "+r"(src_b), [cnt] "+r"(count), [sse] "=r"(sse) + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4"); + return sse; +} +#endif // HAS_SUMSQUAREERROR_LSX + +#ifdef HAS_HASHDJB2_LSX +static const uint32_t kDjb2Muls_LSX[16] = { + 0x0c3525e1, 0xa3476dc1, 0x3b4039a1, 0x4f5f0981, 0x30f35d61, 0x855cb541, + 0x040a9121, 0x747c7101, 0xec41d4e1, 0x4cfa3cc1, 0x025528a1, 0x00121881, + 0x00008c61, 0x00000441, 0x00000021, 0x00000001, +}; + +uint32_t HashDjb2_LSX(const uint8_t* src, int count, uint32_t seed) { + uint32_t hash = seed; + uint32_t tmp; + uint32_t c16 = 0x92d9e201u; + asm volatile( + "vld $vr4, %[muls], 0\n\t" + "vld $vr5, %[muls], 16\n\t" + "vld $vr6, %[muls], 32\n\t" + "vld $vr7, %[muls], 48\n\t" + "1:\n\t" + "vld $vr0, %[src], 0\n\t" + "vsllwil.hu.bu $vr1, $vr0, 0\n\t" + "vexth.hu.bu $vr2, $vr0\n\t" + "vsllwil.wu.hu $vr0, $vr1, 0\n\t" + "vexth.wu.hu $vr1, $vr1\n\t" + "vsllwil.wu.hu $vr3, $vr2, 0\n\t" + "vexth.wu.hu $vr2, $vr2\n\t" + "vmul.w $vr0, $vr0, $vr4\n\t" + "vmadd.w $vr0, $vr1, $vr5\n\t" + "vmadd.w $vr0, $vr3, $vr6\n\t" + "vmadd.w $vr0, $vr2, $vr7\n\t" + "vhaddw.du.wu $vr0, $vr0, $vr0\n\t" + "vhaddw.qu.du $vr0, $vr0, $vr0\n\t" + "vpickve2gr.wu %[tmp], $vr0, 0\n\t" + "mul.w %[hash], %[hash], %[c16]\n\t" + "add.w %[hash], %[hash], %[tmp]\n\t" + "addi.d %[src], %[src], 16\n\t" + "addi.d %[cnt], %[cnt], -16\n\t" + "bnez %[cnt], 1b\n\t" + : [src] "+r"(src), [cnt] "+r"(count), [hash] "+r"(hash), [tmp] "=&r"(tmp) + : [muls] "r"(kDjb2Muls_LSX), [c16] "r"(c16) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7"); + return hash; +} +#endif // HAS_HASHDJB2_LSX + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx) diff --git a/libs/libyuv/source/row_mmi.cc b/libs/libyuv/source/row_mmi.cc deleted file mode 100644 index d8726d0937..0000000000 --- a/libs/libyuv/source/row_mmi.cc +++ /dev/null @@ -1,6042 +0,0 @@ -/* - * Copyright 2011 The LibYuv Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ -#include "libyuv/row.h" - -#include // For memcpy and memset. - -#include "libyuv/basic_types.h" - -#ifdef __cplusplus -namespace libyuv { -extern "C" { -#endif - -// This module is for Mips MMI. -#if !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) - -void RGB24ToARGBRow_MMI(const uint8_t* src_rgb24, - uint8_t* dst_argb, - int width) { - uint64_t src0, src1, dest; - const uint64_t mask = 0xff000000ULL; - - __asm__ volatile( - "1: \n\t" - "gslwlc1 %[src0], 0x03(%[src_ptr]) \n\t" - "gslwrc1 %[src0], 0x00(%[src_ptr]) \n\t" - "gslwlc1 %[src1], 0x06(%[src_ptr]) \n\t" - "gslwrc1 %[src1], 0x03(%[src_ptr]) \n\t" - - "or %[src0], %[src0], %[mask] \n\t" - "or %[src1], %[src1], %[mask] \n\t" - "punpcklwd %[dest], %[src0], %[src1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "gslwlc1 %[src0], 0x09(%[src_ptr]) \n\t" - "gslwrc1 %[src0], 0x06(%[src_ptr]) \n\t" - "gslwlc1 %[src1], 0x0c(%[src_ptr]) \n\t" - "gslwrc1 %[src1], 0x09(%[src_ptr]) \n\t" - - "or %[src0], %[src0], %[mask] \n\t" - "or %[src1], %[src1], %[mask] \n\t" - "punpcklwd %[dest], %[src0], %[src1] \n\t" - "gssdlc1 %[dest], 0x0f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x08(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x0c \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x10 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest] "=&f"(dest) - : [src_ptr] "r"(src_rgb24), [dst_ptr] "r"(dst_argb), [width] "r"(width), - [mask] "f"(mask) - : "memory"); -} - -void RAWToARGBRow_MMI(const uint8_t* src_raw, uint8_t* dst_argb, int width) { - uint64_t src0, src1, dest; - const uint64_t mask0 = 0x0; - const uint64_t mask1 = 0xff000000ULL; - const uint64_t mask2 = 0xc6; - - __asm__ volatile( - "1: \n\t" - "gslwlc1 %[src0], 0x03(%[src_ptr]) \n\t" - "gslwrc1 %[src0], 0x00(%[src_ptr]) \n\t" - "gslwlc1 %[src1], 0x06(%[src_ptr]) \n\t" - "gslwrc1 %[src1], 0x03(%[src_ptr]) \n\t" - - "or %[src0], %[src0], %[mask1] \n\t" - "punpcklbh %[src0], %[src0], %[mask0] \n\t" - "pshufh %[src0], %[src0], %[mask2] \n\t" - "or %[src1], %[src1], %[mask1] \n\t" - "punpcklbh %[src1], %[src1], %[mask0] \n\t" - "pshufh %[src1], %[src1], %[mask2] \n\t" - "packushb %[dest], %[src0], %[src1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "gslwlc1 %[src0], 0x09(%[src_ptr]) \n\t" - "gslwrc1 %[src0], 0x06(%[src_ptr]) \n\t" - "gslwlc1 %[src1], 0x0c(%[src_ptr]) \n\t" - "gslwrc1 %[src1], 0x09(%[src_ptr]) \n\t" - - "or %[src0], %[src0], %[mask1] \n\t" - "punpcklbh %[src0], %[src0], %[mask0] \n\t" - "pshufh %[src0], %[src0], %[mask2] \n\t" - "or %[src1], %[src1], %[mask1] \n\t" - "punpcklbh %[src1], %[src1], %[mask0] \n\t" - "pshufh %[src1], %[src1], %[mask2] \n\t" - "packushb %[dest], %[src0], %[src1] \n\t" - "gssdlc1 %[dest], 0x0f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x08(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x0c \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x10 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest] "=&f"(dest) - : [src_ptr] "r"(src_raw), [dst_ptr] "r"(dst_argb), [mask0] "f"(mask0), - [mask1] "f"(mask1), [mask2] "f"(mask2), [width] "r"(width) - : "memory"); -} - -void RAWToRGB24Row_MMI(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { - uint64_t src0, src1; - uint64_t ftmp[4]; - uint64_t mask0 = 0xc6; - uint64_t mask1 = 0x6c; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_raw]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_raw]) \n\t" - "gslwrc1 %[src1], 0x08(%[src_raw]) \n\t" - "gslwlc1 %[src1], 0x0b(%[src_raw]) \n\t" - - "punpcklbh %[ftmp0], %[src0], %[zero] \n\t" - "pshufh %[ftmp0], %[ftmp0], %[mask0] \n\t" - "punpckhbh %[ftmp1], %[src0], %[zero] \n\t" - "punpcklbh %[src1], %[src1], %[zero] \n\t" - "pextrh %[ftmp2], %[ftmp0], %[three] \n\t" - "pextrh %[ftmp3], %[ftmp1], %[one] \n\t" - "pinsrh_3 %[ftmp0], %[ftmp0], %[ftmp3] \n\t" - "pextrh %[ftmp3], %[ftmp1], %[two] \n\t" - "pinsrh_1 %[ftmp1], %[ftmp1], %[ftmp2] \n\t" - "pshufh %[src1], %[src1], %[mask1] \n\t" - "pextrh %[ftmp2], %[src1], %[zero] \n\t" - "pinsrh_2 %[ftmp1], %[ftmp1], %[ftmp2] \n\t" - "pinsrh_0 %[src1], %[src1], %[ftmp3] \n\t" - "packushb %[ftmp0], %[ftmp0], %[ftmp1] \n\t" - "packushb %[src1], %[src1], %[zero] \n\t" - - "gssdrc1 %[ftmp0], 0x00(%[dst_rgb24]) \n\t" - "gssdlc1 %[ftmp0], 0x07(%[dst_rgb24]) \n\t" - "gsswrc1 %[src1], 0x08(%[dst_rgb24]) \n\t" - "gsswlc1 %[src1], 0x0b(%[dst_rgb24]) \n\t" - - "daddiu %[src_raw], %[src_raw], 0x0c \n\t" - "daddiu %[dst_rgb24], %[dst_rgb24], 0x0c \n\t" - "daddiu %[width], %[width], -0x04 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [ftmp0] "=&f"(ftmp[0]), - [ftmp1] "=&f"(ftmp[1]), [ftmp2] "=&f"(ftmp[2]), [ftmp3] "=&f"(ftmp[3]) - : [src_raw] "r"(src_raw), [dst_rgb24] "r"(dst_rgb24), [width] "r"(width), - [mask0] "f"(mask0), [mask1] "f"(mask1), [zero] "f"(0x00), - [one] "f"(0x01), [two] "f"(0x02), [three] "f"(0x03) - : "memory"); -} - -void RGB565ToARGBRow_MMI(const uint8_t* src_rgb565, - uint8_t* dst_argb, - int width) { - uint64_t ftmp[5]; - uint64_t c0 = 0x001f001f001f001f; - uint64_t c1 = 0x00ff00ff00ff00ff; - uint64_t c2 = 0x0007000700070007; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_rgb565]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_rgb565]) \n\t" - "psrlh %[src1], %[src0], %[eight] \n\t" - "and %[b], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g], %[src1], %[c2] \n\t" - "psllh %[g], %[g], %[three] \n\t" - "or %[g], %[src0], %[g] \n\t" - "psrlh %[r], %[src1], %[three] \n\t" - "psllh %[src0], %[b], %[three] \n\t" - "psrlh %[src1], %[b], %[two] \n\t" - "or %[b], %[src0], %[src1] \n\t" - "psllh %[src0], %[g], %[two] \n\t" - "psrlh %[src1], %[g], %[four] \n\t" - "or %[g], %[src0], %[src1] \n\t" - "psllh %[src0], %[r], %[three] \n\t" - "psrlh %[src1], %[r], %[two] \n\t" - "or %[r], %[src0], %[src1] \n\t" - "packushb %[b], %[b], %[r] \n\t" - "packushb %[g], %[g], %[c1] \n\t" - "punpcklbh %[src0], %[b], %[g] \n\t" - "punpckhbh %[src1], %[b], %[g] \n\t" - "punpcklhw %[r], %[src0], %[src1] \n\t" - "gssdrc1 %[r], 0x00(%[dst_argb]) \n\t" - "gssdlc1 %[r], 0x07(%[dst_argb]) \n\t" - "punpckhhw %[r], %[src0], %[src1] \n\t" - "gssdrc1 %[r], 0x08(%[dst_argb]) \n\t" - "gssdlc1 %[r], 0x0f(%[dst_argb]) \n\t" - "daddiu %[src_rgb565], %[src_rgb565], 0x08 \n\t" - "daddiu %[dst_argb], %[dst_argb], 0x10 \n\t" - "daddiu %[width], %[width], -0x04 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(ftmp[0]), [src1] "=&f"(ftmp[1]), [b] "=&f"(ftmp[2]), - [g] "=&f"(ftmp[3]), [r] "=&f"(ftmp[4]) - : [src_rgb565] "r"(src_rgb565), [dst_argb] "r"(dst_argb), - [width] "r"(width), [c0] "f"(c0), [c1] "f"(c1), [c2] "f"(c2), - [eight] "f"(0x08), [five] "f"(0x05), [three] "f"(0x03), [two] "f"(0x02), - [four] "f"(0x04) - : "memory"); -} - -void ARGB1555ToARGBRow_MMI(const uint8_t* src_argb1555, - uint8_t* dst_argb, - int width) { - uint64_t ftmp[6]; - uint64_t c0 = 0x001f001f001f001f; - uint64_t c1 = 0x00ff00ff00ff00ff; - uint64_t c2 = 0x0003000300030003; - uint64_t c3 = 0x007c007c007c007c; - uint64_t c4 = 0x0001000100010001; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb1555]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb1555]) \n\t" - "psrlh %[src1], %[src0], %[eight] \n\t" - "and %[b], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g], %[src1], %[c2] \n\t" - "psllh %[g], %[g], %[three] \n\t" - "or %[g], %[src0], %[g] \n\t" - "and %[r], %[src1], %[c3] \n\t" - "psrlh %[r], %[r], %[two] \n\t" - "psrlh %[a], %[src1], %[seven] \n\t" - "psllh %[src0], %[b], %[three] \n\t" - "psrlh %[src1], %[b], %[two] \n\t" - "or %[b], %[src0], %[src1] \n\t" - "psllh %[src0], %[g], %[three] \n\t" - "psrlh %[src1], %[g], %[two] \n\t" - "or %[g], %[src0], %[src1] \n\t" - "psllh %[src0], %[r], %[three] \n\t" - "psrlh %[src1], %[r], %[two] \n\t" - "or %[r], %[src0], %[src1] \n\t" - "xor %[a], %[a], %[c1] \n\t" - "paddb %[a], %[a], %[c4] \n\t" - "packushb %[b], %[b], %[r] \n\t" - "packushb %[g], %[g], %[a] \n\t" - "punpcklbh %[src0], %[b], %[g] \n\t" - "punpckhbh %[src1], %[b], %[g] \n\t" - "punpcklhw %[r], %[src0], %[src1] \n\t" - "gssdrc1 %[r], 0x00(%[dst_argb]) \n\t" - "gssdlc1 %[r], 0x07(%[dst_argb]) \n\t" - "punpckhhw %[r], %[src0], %[src1] \n\t" - "gssdrc1 %[r], 0x08(%[dst_argb]) \n\t" - "gssdlc1 %[r], 0x0f(%[dst_argb]) \n\t" - "daddiu %[src_argb1555], %[src_argb1555], 0x08 \n\t" - "daddiu %[dst_argb], %[dst_argb], 0x10 \n\t" - "daddiu %[width], %[width], -0x04 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(ftmp[0]), [src1] "=&f"(ftmp[1]), [b] "=&f"(ftmp[2]), - [g] "=&f"(ftmp[3]), [r] "=&f"(ftmp[4]), [a] "=&f"(ftmp[5]) - : [src_argb1555] "r"(src_argb1555), [dst_argb] "r"(dst_argb), - [width] "r"(width), [c0] "f"(c0), [c1] "f"(c1), [c2] "f"(c2), - [c3] "f"(c3), [c4] "f"(c4), [eight] "f"(0x08), [five] "f"(0x05), - [three] "f"(0x03), [two] "f"(0x02), [seven] "f"(0x07) - : "memory"); -} - -void ARGB4444ToARGBRow_MMI(const uint8_t* src_argb4444, - uint8_t* dst_argb, - int width) { - uint64_t ftmp[6]; - uint64_t c0 = 0x000f000f000f000f; - uint64_t c1 = 0x00ff00ff00ff00ff; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb4444]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb4444]) \n\t" - "psrlh %[src1], %[src0], %[eight] \n\t" - "and %[b], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[g], %[src0], %[four] \n\t" - "and %[r], %[src1], %[c0] \n\t" - "psrlh %[a], %[src1], %[four] \n\t" - "psllh %[src0], %[b], %[four] \n\t" - "or %[b], %[src0], %[b] \n\t" - "psllh %[src0], %[g], %[four] \n\t" - "or %[g], %[src0], %[g] \n\t" - "psllh %[src0], %[r], %[four] \n\t" - "or %[r], %[src0], %[r] \n\t" - "psllh %[src0], %[a], %[four] \n\t" - "or %[a], %[src0], %[a] \n\t" - "packushb %[b], %[b], %[r] \n\t" - "packushb %[g], %[g], %[a] \n\t" - "punpcklbh %[src0], %[b], %[g] \n\t" - "punpckhbh %[src1], %[b], %[g] \n\t" - "punpcklhw %[r], %[src0], %[src1] \n\t" - "gssdrc1 %[r], 0x00(%[dst_argb]) \n\t" - "gssdlc1 %[r], 0x07(%[dst_argb]) \n\t" - "punpckhhw %[r], %[src0], %[src1] \n\t" - "gssdrc1 %[r], 0x08(%[dst_argb]) \n\t" - "gssdlc1 %[r], 0x0f(%[dst_argb]) \n\t" - "daddiu %[src_argb4444], %[src_argb4444], 0x08 \n\t" - "daddiu %[dst_argb], %[dst_argb], 0x10 \n\t" - "daddiu %[width], %[width], -0x04 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(ftmp[0]), [src1] "=&f"(ftmp[1]), [b] "=&f"(ftmp[2]), - [g] "=&f"(ftmp[3]), [r] "=&f"(ftmp[4]), [a] "=&f"(ftmp[5]) - : [src_argb4444] "r"(src_argb4444), [dst_argb] "r"(dst_argb), - [width] "r"(width), [c0] "f"(c0), [c1] "f"(c1), [eight] "f"(0x08), - [four] "f"(0x04) - : "memory"); -} - -void ARGBToRGB24Row_MMI(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { - uint64_t src; - - __asm__ volatile( - "1: \n\t" - "gslwlc1 %[src], 0x03(%[src_ptr]) \n\t" - "gslwrc1 %[src], 0x00(%[src_ptr]) \n\t" - "gsswlc1 %[src], 0x03(%[dst_ptr]) \n\t" - "gsswrc1 %[src], 0x00(%[dst_ptr]) \n\t" - - "gslwlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gslwrc1 %[src], 0x04(%[src_ptr]) \n\t" - "gsswlc1 %[src], 0x06(%[dst_ptr]) \n\t" - "gsswrc1 %[src], 0x03(%[dst_ptr]) \n\t" - - "gslwlc1 %[src], 0x0b(%[src_ptr]) \n\t" - "gslwrc1 %[src], 0x08(%[src_ptr]) \n\t" - "gsswlc1 %[src], 0x09(%[dst_ptr]) \n\t" - "gsswrc1 %[src], 0x06(%[dst_ptr]) \n\t" - - "gslwlc1 %[src], 0x0f(%[src_ptr]) \n\t" - "gslwrc1 %[src], 0x0c(%[src_ptr]) \n\t" - "gsswlc1 %[src], 0x0c(%[dst_ptr]) \n\t" - "gsswrc1 %[src], 0x09(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x10 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x0c \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src) - : [src_ptr] "r"(src_argb), [dst_ptr] "r"(dst_rgb), [width] "r"(width) - : "memory"); -} - -void ARGBToRAWRow_MMI(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { - uint64_t src0, src1; - uint64_t ftmp[3]; - uint64_t mask0 = 0xc6; - uint64_t mask1 = 0x18; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_argb]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_argb]) \n\t" - - "punpcklbh %[ftmp0], %[src0], %[zero] \n\t" - "pshufh %[ftmp0], %[ftmp0], %[mask0] \n\t" - "punpckhbh %[ftmp1], %[src0], %[zero] \n\t" - "punpcklbh %[ftmp2], %[src1], %[zero] \n\t" - "punpckhbh %[src1], %[src1], %[zero] \n\t" - - "pextrh %[src0], %[ftmp1], %[two] \n\t" - "pinsrh_3 %[ftmp0], %[ftmp0], %[src0] \n\t" - "pshufh %[ftmp1], %[ftmp1], %[one] \n\t" - - "pextrh %[src0], %[ftmp2], %[two] \n\t" - "pinsrh_2 %[ftmp1], %[ftmp1], %[src0] \n\t" - "pextrh %[src0], %[ftmp2], %[one] \n\t" - "pinsrh_3 %[ftmp1], %[ftmp1], %[src0] \n\t" - "pextrh %[src0], %[ftmp2], %[zero] \n\t" - "pshufh %[src1], %[src1], %[mask1] \n\t" - "pinsrh_0 %[src1], %[src1], %[src0] \n\t" - "packushb %[ftmp0], %[ftmp0], %[ftmp1] \n\t" - "packushb %[src1], %[src1], %[zero] \n\t" - - "gssdrc1 %[ftmp0], 0x00(%[dst_rgb]) \n\t" - "gssdlc1 %[ftmp0], 0x07(%[dst_rgb]) \n\t" - "gsswrc1 %[src1], 0x08(%[dst_rgb]) \n\t" - "gsswlc1 %[src1], 0x0b(%[dst_rgb]) \n\t" - - "daddiu %[src_argb], %[src_argb], 0x10 \n\t" - "daddiu %[dst_rgb], %[dst_rgb], 0x0c \n\t" - "daddiu %[width], %[width], -0x04 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [ftmp0] "=&f"(ftmp[0]), - [ftmp1] "=&f"(ftmp[1]), [ftmp2] "=&f"(ftmp[2]) - : [src_argb] "r"(src_argb), [dst_rgb] "r"(dst_rgb), [width] "r"(width), - [mask0] "f"(mask0), [mask1] "f"(mask1), [zero] "f"(0x00), - [one] "f"(0x01), [two] "f"(0x02) - : "memory"); -} - -void ARGBToRGB565Row_MMI(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { - uint64_t src0, src1; - uint64_t ftmp[3]; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_argb]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_argb]) \n\t" - - "punpcklbh %[b], %[src0], %[src1] \n\t" - "punpckhbh %[g], %[src0], %[src1] \n\t" - "punpcklbh %[src0], %[b], %[g] \n\t" - "punpckhbh %[src1], %[b], %[g] \n\t" - "punpcklbh %[b], %[src0], %[zero] \n\t" - "punpckhbh %[g], %[src0], %[zero] \n\t" - "punpcklbh %[r], %[src1], %[zero] \n\t" - - "psrlh %[b], %[b], %[three] \n\t" - "psrlh %[g], %[g], %[two] \n\t" - "psrlh %[r], %[r], %[three] \n\t" - - "psllh %[g], %[g], %[five] \n\t" - "psllh %[r], %[r], %[eleven] \n\t" - "or %[b], %[b], %[g] \n\t" - "or %[b], %[b], %[r] \n\t" - - "gssdrc1 %[b], 0x00(%[dst_rgb]) \n\t" - "gssdlc1 %[b], 0x07(%[dst_rgb]) \n\t" - - "daddiu %[src_argb], %[src_argb], 0x10 \n\t" - "daddiu %[dst_rgb], %[dst_rgb], 0x08 \n\t" - "daddiu %[width], %[width], -0x04 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [b] "=&f"(ftmp[0]), - [g] "=&f"(ftmp[1]), [r] "=&f"(ftmp[2]) - : [src_argb] "r"(src_argb), [dst_rgb] "r"(dst_rgb), [width] "r"(width), - [zero] "f"(0x00), [two] "f"(0x02), [three] "f"(0x03), [five] "f"(0x05), - [eleven] "f"(0x0b) - : "memory"); -} - -// dither4 is a row of 4 values from 4x4 dither matrix. -// The 4x4 matrix contains values to increase RGB. When converting to -// fewer bits (565) this provides an ordered dither. -// The order in the 4x4 matrix in first byte is upper left. -// The 4 values are passed as an int, then referenced as an array, so -// endian will not affect order of the original matrix. But the dither4 -// will containing the first pixel in the lower byte for little endian -// or the upper byte for big endian. -void ARGBToRGB565DitherRow_MMI(const uint8_t* src_argb, - uint8_t* dst_rgb, - const uint32_t dither4, - int width) { - uint64_t src0, src1; - uint64_t ftmp[3]; - uint64_t c0 = 0x00ff00ff00ff00ff; - - __asm__ volatile( - "punpcklbh %[dither], %[dither], %[zero] \n\t" - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_argb]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_argb]) \n\t" - - "punpcklbh %[b], %[src0], %[src1] \n\t" - "punpckhbh %[g], %[src0], %[src1] \n\t" - "punpcklbh %[src0], %[b], %[g] \n\t" - "punpckhbh %[src1], %[b], %[g] \n\t" - "punpcklbh %[b], %[src0], %[zero] \n\t" - "punpckhbh %[g], %[src0], %[zero] \n\t" - "punpcklbh %[r], %[src1], %[zero] \n\t" - - "paddh %[b], %[b], %[dither] \n\t" - "paddh %[g], %[g], %[dither] \n\t" - "paddh %[r], %[r], %[dither] \n\t" - "pcmpgth %[src0], %[b], %[c0] \n\t" - "or %[src0], %[src0], %[b] \n\t" - "and %[b], %[src0], %[c0] \n\t" - "pcmpgth %[src0], %[g], %[c0] \n\t" - "or %[src0], %[src0], %[g] \n\t" - "and %[g], %[src0], %[c0] \n\t" - "pcmpgth %[src0], %[r], %[c0] \n\t" - "or %[src0], %[src0], %[r] \n\t" - "and %[r], %[src0], %[c0] \n\t" - - "psrlh %[b], %[b], %[three] \n\t" - "psrlh %[g], %[g], %[two] \n\t" - "psrlh %[r], %[r], %[three] \n\t" - - "psllh %[g], %[g], %[five] \n\t" - "psllh %[r], %[r], %[eleven] \n\t" - "or %[b], %[b], %[g] \n\t" - "or %[b], %[b], %[r] \n\t" - - "gssdrc1 %[b], 0x00(%[dst_rgb]) \n\t" - "gssdlc1 %[b], 0x07(%[dst_rgb]) \n\t" - - "daddiu %[src_argb], %[src_argb], 0x10 \n\t" - "daddiu %[dst_rgb], %[dst_rgb], 0x08 \n\t" - "daddiu %[width], %[width], -0x04 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [b] "=&f"(ftmp[0]), - [g] "=&f"(ftmp[1]), [r] "=&f"(ftmp[2]) - : [src_argb] "r"(src_argb), [dst_rgb] "r"(dst_rgb), [width] "r"(width), - [dither] "f"(dither4), [c0] "f"(c0), [zero] "f"(0x00), [two] "f"(0x02), - [three] "f"(0x03), [five] "f"(0x05), [eleven] "f"(0x0b) - : "memory"); -} - -void ARGBToARGB1555Row_MMI(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - uint64_t src0, src1; - uint64_t ftmp[4]; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_argb]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_argb]) \n\t" - - "punpcklbh %[b], %[src0], %[src1] \n\t" - "punpckhbh %[g], %[src0], %[src1] \n\t" - "punpcklbh %[src0], %[b], %[g] \n\t" - "punpckhbh %[src1], %[b], %[g] \n\t" - "punpcklbh %[b], %[src0], %[zero] \n\t" - "punpckhbh %[g], %[src0], %[zero] \n\t" - "punpcklbh %[r], %[src1], %[zero] \n\t" - "punpckhbh %[a], %[src1], %[zero] \n\t" - - "psrlh %[b], %[b], %[three] \n\t" - "psrlh %[g], %[g], %[three] \n\t" - "psrlh %[r], %[r], %[three] \n\t" - "psrlh %[a], %[a], %[seven] \n\t" - - "psllh %[g], %[g], %[five] \n\t" - "psllh %[r], %[r], %[ten] \n\t" - "psllh %[a], %[a], %[fifteen] \n\t" - "or %[b], %[b], %[g] \n\t" - "or %[b], %[b], %[r] \n\t" - "or %[b], %[b], %[a] \n\t" - - "gssdrc1 %[b], 0x00(%[dst_rgb]) \n\t" - "gssdlc1 %[b], 0x07(%[dst_rgb]) \n\t" - - "daddiu %[src_argb], %[src_argb], 0x10 \n\t" - "daddiu %[dst_rgb], %[dst_rgb], 0x08 \n\t" - "daddiu %[width], %[width], -0x04 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [b] "=&f"(ftmp[0]), - [g] "=&f"(ftmp[1]), [r] "=&f"(ftmp[2]), [a] "=&f"(ftmp[3]) - : [src_argb] "r"(src_argb), [dst_rgb] "r"(dst_rgb), [width] "r"(width), - [zero] "f"(0x00), [three] "f"(0x03), [five] "f"(0x05), - [seven] "f"(0x07), [ten] "f"(0x0a), [fifteen] "f"(0x0f) - : "memory"); -} - -void ARGBToARGB4444Row_MMI(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - uint64_t src0, src1; - uint64_t ftmp[4]; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_argb]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_argb]) \n\t" - - "punpcklbh %[b], %[src0], %[src1] \n\t" - "punpckhbh %[g], %[src0], %[src1] \n\t" - "punpcklbh %[src0], %[b], %[g] \n\t" - "punpckhbh %[src1], %[b], %[g] \n\t" - "punpcklbh %[b], %[src0], %[zero] \n\t" - "punpckhbh %[g], %[src0], %[zero] \n\t" - "punpcklbh %[r], %[src1], %[zero] \n\t" - "punpckhbh %[a], %[src1], %[zero] \n\t" - - "psrlh %[b], %[b], %[four] \n\t" - "psrlh %[g], %[g], %[four] \n\t" - "psrlh %[r], %[r], %[four] \n\t" - "psrlh %[a], %[a], %[four] \n\t" - - "psllh %[g], %[g], %[four] \n\t" - "psllh %[r], %[r], %[eight] \n\t" - "psllh %[a], %[a], %[twelve] \n\t" - "or %[b], %[b], %[g] \n\t" - "or %[b], %[b], %[r] \n\t" - "or %[b], %[b], %[a] \n\t" - - "gssdrc1 %[b], 0x00(%[dst_rgb]) \n\t" - "gssdlc1 %[b], 0x07(%[dst_rgb]) \n\t" - - "daddiu %[src_argb], %[src_argb], 0x10 \n\t" - "daddiu %[dst_rgb], %[dst_rgb], 0x08 \n\t" - "daddiu %[width], %[width], -0x04 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [b] "=&f"(ftmp[0]), - [g] "=&f"(ftmp[1]), [r] "=&f"(ftmp[2]), [a] "=&f"(ftmp[3]) - : [src_argb] "r"(src_argb), [dst_rgb] "r"(dst_rgb), [width] "r"(width), - [zero] "f"(0x00), [four] "f"(0x04), [eight] "f"(0x08), - [twelve] "f"(0x0c) - : "memory"); -} - -void ARGBToYRow_MMI(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - uint64_t src, src_hi, src_lo; - uint64_t dest0, dest1, dest2, dest3; - const uint64_t value = 0x1080; - const uint64_t mask = 0x0001004200810019; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x00(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest0], %[src_lo], %[src_hi] \n\t" - "paddw %[dest0], %[dest0], %[src] \n\t" - "psrlw %[dest0], %[dest0], %[eight] \n\t" - - "gsldlc1 %[src], 0x0f(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x08(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest1], %[dest1], %[src] \n\t" - "psrlw %[dest1], %[dest1], %[eight] \n\t" - - "gsldlc1 %[src], 0x17(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x10(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest2], %[src_lo], %[src_hi] \n\t" - "paddw %[dest2], %[dest2], %[src] \n\t" - "psrlw %[dest2], %[dest2], %[eight] \n\t" - - "gsldlc1 %[src], 0x1f(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x18(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest3], %[src_lo], %[src_hi] \n\t" - "paddw %[dest3], %[dest3], %[src] \n\t" - "psrlw %[dest3], %[dest3], %[eight] \n\t" - - "packsswh %[src_lo], %[dest0], %[dest1] \n\t" - "packsswh %[src_hi], %[dest2], %[dest3] \n\t" - "packushb %[dest0], %[src_lo], %[src_hi] \n\t" - "gssdlc1 %[dest0], 0x07(%[dst_y]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_y]) \n\t" - - "daddiu %[src_argb0], %[src_argb0], 0x20 \n\t" - "daddiu %[dst_y], %[dst_y], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [dest2] "=&f"(dest2), - [dest3] "=&f"(dest3) - : [src_argb0] "r"(src_argb0), [dst_y] "r"(dst_y), [width] "r"(width), - [mask] "f"(mask), [value] "f"(value), [eight] "f"(0x08), - [zero] "f"(0x00) - : "memory"); -} - -void ARGBToUVRow_MMI(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t src_rgb1; - uint64_t ftmp[12]; - const uint64_t value = 0x4040; - const uint64_t mask_u = 0x0026004a00700002; - const uint64_t mask_v = 0x00020070005e0012; - - __asm__ volatile( - "1: \n\t" - "daddu %[src_rgb1], %[src_rgb0], %[src_stride_rgb] \n\t" - "gsldrc1 %[src0], 0x00(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x00(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x07(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[dest0_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest0_u], %[dest0_u], %[value] \n\t" - "pinsrh_3 %[dest0_v], %[src0], %[value] \n\t" - "pmaddhw %[dest0_u], %[dest0_u], %[mask_u] \n\t" - "pmaddhw %[dest0_v], %[dest0_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest0_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest0_u], %[src_lo] \n\t" - "psubw %[dest0_u], %[src0], %[src1] \n\t" - "psraw %[dest0_u], %[dest0_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest0_v], %[src_hi] \n\t" - "psubw %[dest0_v], %[src1], %[src0] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x10(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x17(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x10(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x17(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[dest1_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest1_u], %[dest1_u], %[value] \n\t" - "pinsrh_3 %[dest1_v], %[src0], %[value] \n\t" - "pmaddhw %[dest1_u], %[dest1_u], %[mask_u] \n\t" - "pmaddhw %[dest1_v], %[dest1_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x18(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x1f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x18(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x1f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest1_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest1_u], %[src_lo] \n\t" - "psubw %[dest1_u], %[src0], %[src1] \n\t" - "psraw %[dest1_u], %[dest1_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest1_v], %[src_hi] \n\t" - "psubw %[dest1_v], %[src1], %[src0] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x20(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x27(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x20(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x27(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[dest2_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest2_u], %[dest2_u], %[value] \n\t" - "pinsrh_3 %[dest2_v], %[src0], %[value] \n\t" - "pmaddhw %[dest2_u], %[dest2_u], %[mask_u] \n\t" - "pmaddhw %[dest2_v], %[dest2_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x28(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x2f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x28(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x2f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest2_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest2_u], %[src_lo] \n\t" - "psubw %[dest2_u], %[src0], %[src1] \n\t" - "psraw %[dest2_u], %[dest2_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest2_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest2_v], %[src_hi] \n\t" - "psubw %[dest2_v], %[src1], %[src0] \n\t" - "psraw %[dest2_v], %[dest2_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x30(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x37(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x30(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x37(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[dest3_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest3_u], %[dest3_u], %[value] \n\t" - "pinsrh_3 %[dest3_v], %[src0], %[value] \n\t" - "pmaddhw %[dest3_u], %[dest3_u], %[mask_u] \n\t" - "pmaddhw %[dest3_v], %[dest3_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x38(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x3f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x38(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x3f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest3_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest3_u], %[src_lo] \n\t" - "psubw %[dest3_u], %[src0], %[src1] \n\t" - "psraw %[dest3_u], %[dest3_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest3_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest3_v], %[src_hi] \n\t" - "psubw %[dest3_v], %[src1], %[src0] \n\t" - "psraw %[dest3_v], %[dest3_v], %[eight] \n\t" - - "packsswh %[src0], %[dest0_u], %[dest1_u] \n\t" - "packsswh %[src1], %[dest2_u], %[dest3_u] \n\t" - "packushb %[dest0_u], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_u], 0x07(%[dst_u]) \n\t" - "gssdrc1 %[dest0_u], 0x00(%[dst_u]) \n\t" - - "packsswh %[src0], %[dest0_v], %[dest1_v] \n\t" - "packsswh %[src1], %[dest2_v], %[dest3_v] \n\t" - "packushb %[dest0_v], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_v], 0x07(%[dst_v]) \n\t" - "gssdrc1 %[dest0_v], 0x00(%[dst_v]) \n\t" - - "daddiu %[src_rgb0], %[src_rgb0], 0x40 \n\t" - "daddiu %[dst_u], %[dst_u], 0x08 \n\t" - "daddiu %[dst_v], %[dst_v], 0x08 \n\t" - "daddi %[width], %[width], -0x10 \n\t" - "bgtz %[width], 1b \n\t" - : [src_rgb1] "=&r"(src_rgb1), [src0] "=&f"(ftmp[0]), - [src1] "=&f"(ftmp[1]), [src_lo] "=&f"(ftmp[2]), [src_hi] "=&f"(ftmp[3]), - [dest0_u] "=&f"(ftmp[4]), [dest0_v] "=&f"(ftmp[5]), - [dest1_u] "=&f"(ftmp[6]), [dest1_v] "=&f"(ftmp[7]), - [dest2_u] "=&f"(ftmp[8]), [dest2_v] "=&f"(ftmp[9]), - [dest3_u] "=&f"(ftmp[10]), [dest3_v] "=&f"(ftmp[11]) - : [src_rgb0] "r"(src_rgb0), [src_stride_rgb] "r"(src_stride_rgb), - [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), [width] "r"(width), - [mask_u] "f"(mask_u), [mask_v] "f"(mask_v), [value] "f"(value), - [zero] "f"(0x00), [eight] "f"(0x08), [two] "f"(0x02), - [sixteen] "f"(0x10) - : "memory"); -} - -void BGRAToYRow_MMI(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - uint64_t src, src_hi, src_lo; - uint64_t dest0, dest1, dest2, dest3; - const uint64_t value = 0x1080; - const uint64_t mask = 0x0019008100420001; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x00(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest0], %[src_lo], %[src_hi] \n\t" - "paddw %[dest0], %[dest0], %[src] \n\t" - "psrlw %[dest0], %[dest0], %[eight] \n\t" - - "gsldlc1 %[src], 0x0f(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x08(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest1], %[dest1], %[src] \n\t" - "psrlw %[dest1], %[dest1], %[eight] \n\t" - - "gsldlc1 %[src], 0x17(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x10(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest2], %[src_lo], %[src_hi] \n\t" - "paddw %[dest2], %[dest2], %[src] \n\t" - "psrlw %[dest2], %[dest2], %[eight] \n\t" - - "gsldlc1 %[src], 0x1f(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x18(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest3], %[src_lo], %[src_hi] \n\t" - "paddw %[dest3], %[dest3], %[src] \n\t" - "psrlw %[dest3], %[dest3], %[eight] \n\t" - - "packsswh %[src_lo], %[dest0], %[dest1] \n\t" - "packsswh %[src_hi], %[dest2], %[dest3] \n\t" - "packushb %[dest0], %[src_lo], %[src_hi] \n\t" - "gssdlc1 %[dest0], 0x07(%[dst_y]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_y]) \n\t" - - "daddiu %[src_argb0], %[src_argb0], 0x20 \n\t" - "daddiu %[dst_y], %[dst_y], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [dest2] "=&f"(dest2), - [dest3] "=&f"(dest3) - : [src_argb0] "r"(src_argb0), [dst_y] "r"(dst_y), [width] "r"(width), - [mask] "f"(mask), [value] "f"(value), [eight] "f"(0x08), - [zero] "f"(0x00) - : "memory"); -} - -void BGRAToUVRow_MMI(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t src_rgb1; - uint64_t ftmp[12]; - const uint64_t value = 0x4040; - const uint64_t mask_u = 0x00020070004a0026; - const uint64_t mask_v = 0x0012005e00700002; - - __asm__ volatile( - "1: \n\t" - "daddu %[src_rgb1], %[src_rgb0], %[src_stride_rgb] \n\t" - "gsldrc1 %[src0], 0x00(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x00(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x07(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsrl %[dest0_u], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[dest0_u], %[dest0_u], %[value] \n\t" - "pinsrh_0 %[dest0_v], %[src0], %[value] \n\t" - "pmaddhw %[dest0_u], %[dest0_u], %[mask_u] \n\t" - "pmaddhw %[dest0_v], %[dest0_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsrl %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_0 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest0_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest0_u], %[src_lo] \n\t" - "psubw %[dest0_u], %[src1], %[src0] \n\t" - "psraw %[dest0_u], %[dest0_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest0_v], %[src_hi] \n\t" - "psubw %[dest0_v], %[src0], %[src1] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x10(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x17(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x10(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x17(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsrl %[dest1_u], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[dest1_u], %[dest1_u], %[value] \n\t" - "pinsrh_0 %[dest1_v], %[src0], %[value] \n\t" - "pmaddhw %[dest1_u], %[dest1_u], %[mask_u] \n\t" - "pmaddhw %[dest1_v], %[dest1_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x18(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x1f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x18(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x1f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsrl %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_0 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest1_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest1_u], %[src_lo] \n\t" - "psubw %[dest1_u], %[src1], %[src0] \n\t" - "psraw %[dest1_u], %[dest1_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest1_v], %[src_hi] \n\t" - "psubw %[dest1_v], %[src0], %[src1] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x20(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x27(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x20(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x27(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsrl %[dest2_u], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[dest2_u], %[dest2_u], %[value] \n\t" - "pinsrh_0 %[dest2_v], %[src0], %[value] \n\t" - "pmaddhw %[dest2_u], %[dest2_u], %[mask_u] \n\t" - "pmaddhw %[dest2_v], %[dest2_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x28(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x2f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x28(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x2f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsrl %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_0 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest2_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest2_u], %[src_lo] \n\t" - "psubw %[dest2_u], %[src1], %[src0] \n\t" - "psraw %[dest2_u], %[dest2_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest2_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest2_v], %[src_hi] \n\t" - "psubw %[dest2_v], %[src0], %[src1] \n\t" - "psraw %[dest2_v], %[dest2_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x30(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x37(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x30(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x37(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsrl %[dest3_u], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[dest3_u], %[dest3_u], %[value] \n\t" - "pinsrh_0 %[dest3_v], %[src0], %[value] \n\t" - "pmaddhw %[dest3_u], %[dest3_u], %[mask_u] \n\t" - "pmaddhw %[dest3_v], %[dest3_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x38(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x3f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x38(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x3f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsrl %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_0 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest3_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest3_u], %[src_lo] \n\t" - "psubw %[dest3_u], %[src1], %[src0] \n\t" - "psraw %[dest3_u], %[dest3_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest3_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest3_v], %[src_hi] \n\t" - "psubw %[dest3_v], %[src0], %[src1] \n\t" - "psraw %[dest3_v], %[dest3_v], %[eight] \n\t" - - "packsswh %[src0], %[dest0_u], %[dest1_u] \n\t" - "packsswh %[src1], %[dest2_u], %[dest3_u] \n\t" - "packushb %[dest0_u], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_u], 0x07(%[dst_u]) \n\t" - "gssdrc1 %[dest0_u], 0x00(%[dst_u]) \n\t" - - "packsswh %[src0], %[dest0_v], %[dest1_v] \n\t" - "packsswh %[src1], %[dest2_v], %[dest3_v] \n\t" - "packushb %[dest0_v], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_v], 0x07(%[dst_v]) \n\t" - "gssdrc1 %[dest0_v], 0x00(%[dst_v]) \n\t" - - "daddiu %[src_rgb0], %[src_rgb0], 0x40 \n\t" - "daddiu %[dst_u], %[dst_u], 0x08 \n\t" - "daddiu %[dst_v], %[dst_v], 0x08 \n\t" - "daddi %[width], %[width], -0x10 \n\t" - "bgtz %[width], 1b \n\t" - : [src_rgb1] "=&r"(src_rgb1), [src0] "=&f"(ftmp[0]), - [src1] "=&f"(ftmp[1]), [src_lo] "=&f"(ftmp[2]), [src_hi] "=&f"(ftmp[3]), - [dest0_u] "=&f"(ftmp[4]), [dest0_v] "=&f"(ftmp[5]), - [dest1_u] "=&f"(ftmp[6]), [dest1_v] "=&f"(ftmp[7]), - [dest2_u] "=&f"(ftmp[8]), [dest2_v] "=&f"(ftmp[9]), - [dest3_u] "=&f"(ftmp[10]), [dest3_v] "=&f"(ftmp[11]) - : [src_rgb0] "r"(src_rgb0), [src_stride_rgb] "r"(src_stride_rgb), - [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), [width] "r"(width), - [mask_u] "f"(mask_u), [mask_v] "f"(mask_v), [value] "f"(value), - [zero] "f"(0x00), [eight] "f"(0x08), [two] "f"(0x02), - [sixteen] "f"(0x10) - : "memory"); -} - -void ABGRToYRow_MMI(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - uint64_t src, src_hi, src_lo; - uint64_t dest0, dest1, dest2, dest3; - const uint64_t value = 0x1080; - const uint64_t mask = 0x0001001900810042; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x00(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest0], %[src_lo], %[src_hi] \n\t" - "paddw %[dest0], %[dest0], %[src] \n\t" - "psrlw %[dest0], %[dest0], %[eight] \n\t" - - "gsldlc1 %[src], 0x0f(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x08(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest1], %[dest1], %[src] \n\t" - "psrlw %[dest1], %[dest1], %[eight] \n\t" - - "gsldlc1 %[src], 0x17(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x10(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest2], %[src_lo], %[src_hi] \n\t" - "paddw %[dest2], %[dest2], %[src] \n\t" - "psrlw %[dest2], %[dest2], %[eight] \n\t" - - "gsldlc1 %[src], 0x1f(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x18(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest3], %[src_lo], %[src_hi] \n\t" - "paddw %[dest3], %[dest3], %[src] \n\t" - "psrlw %[dest3], %[dest3], %[eight] \n\t" - - "packsswh %[src_lo], %[dest0], %[dest1] \n\t" - "packsswh %[src_hi], %[dest2], %[dest3] \n\t" - "packushb %[dest0], %[src_lo], %[src_hi] \n\t" - "gssdlc1 %[dest0], 0x07(%[dst_y]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_y]) \n\t" - - "daddiu %[src_argb0], %[src_argb0], 0x20 \n\t" - "daddiu %[dst_y], %[dst_y], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [dest2] "=&f"(dest2), - [dest3] "=&f"(dest3) - : [src_argb0] "r"(src_argb0), [dst_y] "r"(dst_y), [width] "r"(width), - [mask] "f"(mask), [value] "f"(value), [eight] "f"(0x08), - [zero] "f"(0x00) - : "memory"); -} - -void ABGRToUVRow_MMI(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t src_rgb1; - uint64_t ftmp[12]; - const uint64_t value = 0x4040; - const uint64_t mask_u = 0x00020070004a0026; - const uint64_t mask_v = 0x0012005e00700002; - - __asm__ volatile( - "1: \n\t" - "daddu %[src_rgb1], %[src_rgb0], %[src_stride_rgb] \n\t" - "gsldrc1 %[src0], 0x00(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x00(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x07(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[dest0_u], %[src0], %[value] \n\t" - "dsll %[dest0_v], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest0_v], %[dest0_v], %[value] \n\t" - "pmaddhw %[dest0_u], %[dest0_u], %[mask_u] \n\t" - "pmaddhw %[dest0_v], %[dest0_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[src_lo], %[src0], %[value] \n\t" - "dsll %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest0_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest0_u], %[src_lo] \n\t" - "psubw %[dest0_u], %[src1], %[src0] \n\t" - "psraw %[dest0_u], %[dest0_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest0_v], %[src_hi] \n\t" - "psubw %[dest0_v], %[src0], %[src1] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x10(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x17(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x10(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x17(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[dest1_u], %[src0], %[value] \n\t" - "dsll %[dest1_v], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest1_v], %[dest1_v], %[value] \n\t" - "pmaddhw %[dest1_u], %[dest1_u], %[mask_u] \n\t" - "pmaddhw %[dest1_v], %[dest1_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x18(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x1f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x18(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x1f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[src_lo], %[src0], %[value] \n\t" - "dsll %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest1_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest1_u], %[src_lo] \n\t" - "psubw %[dest1_u], %[src1], %[src0] \n\t" - "psraw %[dest1_u], %[dest1_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest1_v], %[src_hi] \n\t" - "psubw %[dest1_v], %[src0], %[src1] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x20(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x27(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x20(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x27(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[dest2_u], %[src0], %[value] \n\t" - "dsll %[dest2_v], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest2_v], %[dest2_v], %[value] \n\t" - "pmaddhw %[dest2_u], %[dest2_u], %[mask_u] \n\t" - "pmaddhw %[dest2_v], %[dest2_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x28(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x2f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x28(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x2f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[src_lo], %[src0], %[value] \n\t" - "dsll %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest2_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest2_u], %[src_lo] \n\t" - "psubw %[dest2_u], %[src1], %[src0] \n\t" - "psraw %[dest2_u], %[dest2_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest2_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest2_v], %[src_hi] \n\t" - "psubw %[dest2_v], %[src0], %[src1] \n\t" - "psraw %[dest2_v], %[dest2_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x30(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x37(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x30(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x37(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[dest3_u], %[src0], %[value] \n\t" - "dsll %[dest3_v], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest3_v], %[dest3_v], %[value] \n\t" - "pmaddhw %[dest3_u], %[dest3_u], %[mask_u] \n\t" - "pmaddhw %[dest3_v], %[dest3_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x38(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x3f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x38(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x3f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[src_lo], %[src0], %[value] \n\t" - "dsll %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest3_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest3_u], %[src_lo] \n\t" - "psubw %[dest3_u], %[src1], %[src0] \n\t" - "psraw %[dest3_u], %[dest3_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest3_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest3_v], %[src_hi] \n\t" - "psubw %[dest3_v], %[src0], %[src1] \n\t" - "psraw %[dest3_v], %[dest3_v], %[eight] \n\t" - - "packsswh %[src0], %[dest0_u], %[dest1_u] \n\t" - "packsswh %[src1], %[dest2_u], %[dest3_u] \n\t" - "packushb %[dest0_u], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_u], 0x07(%[dst_u]) \n\t" - "gssdrc1 %[dest0_u], 0x00(%[dst_u]) \n\t" - - "packsswh %[src0], %[dest0_v], %[dest1_v] \n\t" - "packsswh %[src1], %[dest2_v], %[dest3_v] \n\t" - "packushb %[dest0_v], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_v], 0x07(%[dst_v]) \n\t" - "gssdrc1 %[dest0_v], 0x00(%[dst_v]) \n\t" - - "daddiu %[src_rgb0], %[src_rgb0], 0x40 \n\t" - "daddiu %[dst_u], %[dst_u], 0x08 \n\t" - "daddiu %[dst_v], %[dst_v], 0x08 \n\t" - "daddi %[width], %[width], -0x10 \n\t" - "bgtz %[width], 1b \n\t" - : [src_rgb1] "=&r"(src_rgb1), [src0] "=&f"(ftmp[0]), - [src1] "=&f"(ftmp[1]), [src_lo] "=&f"(ftmp[2]), [src_hi] "=&f"(ftmp[3]), - [dest0_u] "=&f"(ftmp[4]), [dest0_v] "=&f"(ftmp[5]), - [dest1_u] "=&f"(ftmp[6]), [dest1_v] "=&f"(ftmp[7]), - [dest2_u] "=&f"(ftmp[8]), [dest2_v] "=&f"(ftmp[9]), - [dest3_u] "=&f"(ftmp[10]), [dest3_v] "=&f"(ftmp[11]) - : [src_rgb0] "r"(src_rgb0), [src_stride_rgb] "r"(src_stride_rgb), - [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), [width] "r"(width), - [mask_u] "f"(mask_u), [mask_v] "f"(mask_v), [value] "f"(value), - [zero] "f"(0x00), [eight] "f"(0x08), [two] "f"(0x02), - [sixteen] "f"(0x10) - : "memory"); -} - -void RGBAToYRow_MMI(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - uint64_t src, src_hi, src_lo; - uint64_t dest0, dest1, dest2, dest3; - const uint64_t value = 0x1080; - const uint64_t mask = 0x0042008100190001; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x00(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest0], %[src_lo], %[src_hi] \n\t" - "paddw %[dest0], %[dest0], %[src] \n\t" - "psrlw %[dest0], %[dest0], %[eight] \n\t" - - "gsldlc1 %[src], 0x0f(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x08(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest1], %[dest1], %[src] \n\t" - "psrlw %[dest1], %[dest1], %[eight] \n\t" - - "gsldlc1 %[src], 0x17(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x10(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest2], %[src_lo], %[src_hi] \n\t" - "paddw %[dest2], %[dest2], %[src] \n\t" - "psrlw %[dest2], %[dest2], %[eight] \n\t" - - "gsldlc1 %[src], 0x1f(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x18(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest3], %[src_lo], %[src_hi] \n\t" - "paddw %[dest3], %[dest3], %[src] \n\t" - "psrlw %[dest3], %[dest3], %[eight] \n\t" - - "packsswh %[src_lo], %[dest0], %[dest1] \n\t" - "packsswh %[src_hi], %[dest2], %[dest3] \n\t" - "packushb %[dest0], %[src_lo], %[src_hi] \n\t" - "gssdlc1 %[dest0], 0x07(%[dst_y]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_y]) \n\t" - - "daddiu %[src_argb0], %[src_argb0], 0x20 \n\t" - "daddiu %[dst_y], %[dst_y], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [dest2] "=&f"(dest2), - [dest3] "=&f"(dest3) - : [src_argb0] "r"(src_argb0), [dst_y] "r"(dst_y), [width] "r"(width), - [mask] "f"(mask), [value] "f"(value), [eight] "f"(0x08), - [zero] "f"(0x00) - : "memory"); -} - -void RGBAToUVRow_MMI(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t src_rgb1; - uint64_t ftmp[12]; - const uint64_t value = 0x4040; - const uint64_t mask_u = 0x0026004a00700002; - const uint64_t mask_v = 0x00020070005e0012; - - __asm__ volatile( - "1: \n\t" - "daddu %[src_rgb1], %[src_rgb0], %[src_stride_rgb] \n\t" - "gsldrc1 %[src0], 0x00(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x00(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x07(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_0 %[dest0_u], %[src0], %[value] \n\t" - "dsrl %[dest0_v], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[dest0_v], %[dest0_v], %[value] \n\t" - "pmaddhw %[dest0_u], %[dest0_u], %[mask_u] \n\t" - "pmaddhw %[dest0_v], %[dest0_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_0 %[src_lo], %[src0], %[value] \n\t" - "dsrl %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest0_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest0_u], %[src_lo] \n\t" - "psubw %[dest0_u], %[src0], %[src1] \n\t" - "psraw %[dest0_u], %[dest0_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest0_v], %[src_hi] \n\t" - "psubw %[dest0_v], %[src1], %[src0] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x10(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x17(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x10(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x17(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_0 %[dest1_u], %[src0], %[value] \n\t" - "dsrl %[dest1_v], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[dest1_v], %[dest1_v], %[value] \n\t" - "pmaddhw %[dest1_u], %[dest1_u], %[mask_u] \n\t" - "pmaddhw %[dest1_v], %[dest1_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x18(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x1f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x18(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x1f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_0 %[src_lo], %[src0], %[value] \n\t" - "dsrl %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest1_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest1_u], %[src_lo] \n\t" - "psubw %[dest1_u], %[src0], %[src1] \n\t" - "psraw %[dest1_u], %[dest1_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest1_v], %[src_hi] \n\t" - "psubw %[dest1_v], %[src1], %[src0] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x20(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x27(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x20(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x27(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_0 %[dest2_u], %[src0], %[value] \n\t" - "dsrl %[dest2_v], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[dest2_v], %[dest2_v], %[value] \n\t" - "pmaddhw %[dest2_u], %[dest2_u], %[mask_u] \n\t" - "pmaddhw %[dest2_v], %[dest2_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x28(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x2f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x28(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x2f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_0 %[src_lo], %[src0], %[value] \n\t" - "dsrl %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest2_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest2_u], %[src_lo] \n\t" - "psubw %[dest2_u], %[src0], %[src1] \n\t" - "psraw %[dest2_u], %[dest2_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest2_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest2_v], %[src_hi] \n\t" - "psubw %[dest2_v], %[src1], %[src0] \n\t" - "psraw %[dest2_v], %[dest2_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x30(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x37(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x30(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x37(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_0 %[dest3_u], %[src0], %[value] \n\t" - "dsrl %[dest3_v], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[dest3_v], %[dest3_v], %[value] \n\t" - "pmaddhw %[dest3_u], %[dest3_u], %[mask_u] \n\t" - "pmaddhw %[dest3_v], %[dest3_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x38(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x3f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x38(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x3f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_0 %[src_lo], %[src0], %[value] \n\t" - "dsrl %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest3_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest3_u], %[src_lo] \n\t" - "psubw %[dest3_u], %[src0], %[src1] \n\t" - "psraw %[dest3_u], %[dest3_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest3_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest3_v], %[src_hi] \n\t" - "psubw %[dest3_v], %[src1], %[src0] \n\t" - "psraw %[dest3_v], %[dest3_v], %[eight] \n\t" - - "packsswh %[src0], %[dest0_u], %[dest1_u] \n\t" - "packsswh %[src1], %[dest2_u], %[dest3_u] \n\t" - "packushb %[dest0_u], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_u], 0x07(%[dst_u]) \n\t" - "gssdrc1 %[dest0_u], 0x00(%[dst_u]) \n\t" - - "packsswh %[src0], %[dest0_v], %[dest1_v] \n\t" - "packsswh %[src1], %[dest2_v], %[dest3_v] \n\t" - "packushb %[dest0_v], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_v], 0x07(%[dst_v]) \n\t" - "gssdrc1 %[dest0_v], 0x00(%[dst_v]) \n\t" - - "daddiu %[src_rgb0], %[src_rgb0], 0x40 \n\t" - "daddiu %[dst_u], %[dst_u], 0x08 \n\t" - "daddiu %[dst_v], %[dst_v], 0x08 \n\t" - "daddi %[width], %[width], -0x10 \n\t" - "bgtz %[width], 1b \n\t" - : [src_rgb1] "=&r"(src_rgb1), [src0] "=&f"(ftmp[0]), - [src1] "=&f"(ftmp[1]), [src_lo] "=&f"(ftmp[2]), [src_hi] "=&f"(ftmp[3]), - [dest0_u] "=&f"(ftmp[4]), [dest0_v] "=&f"(ftmp[5]), - [dest1_u] "=&f"(ftmp[6]), [dest1_v] "=&f"(ftmp[7]), - [dest2_u] "=&f"(ftmp[8]), [dest2_v] "=&f"(ftmp[9]), - [dest3_u] "=&f"(ftmp[10]), [dest3_v] "=&f"(ftmp[11]) - : [src_rgb0] "r"(src_rgb0), [src_stride_rgb] "r"(src_stride_rgb), - [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), [width] "r"(width), - [mask_u] "f"(mask_u), [mask_v] "f"(mask_v), [value] "f"(value), - [zero] "f"(0x00), [eight] "f"(0x08), [two] "f"(0x02), - [sixteen] "f"(0x10) - : "memory"); -} - -void RGB24ToYRow_MMI(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - uint64_t src, src_hi, src_lo; - uint64_t dest0, dest1, dest2, dest3; - const uint64_t value = 0x1080; - const uint64_t mask = 0x0001004200810019; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x00(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "dsll %[src], %[src], %[eight] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest0], %[src_lo], %[src_hi] \n\t" - "paddw %[dest0], %[dest0], %[src] \n\t" - "psrlw %[dest0], %[dest0], %[eight] \n\t" - - "gsldlc1 %[src], 0x0d(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x06(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "dsll %[src], %[src], %[eight] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest1], %[dest1], %[src] \n\t" - "psrlw %[dest1], %[dest1], %[eight] \n\t" - - "gsldlc1 %[src], 0x13(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x0c(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "dsll %[src], %[src], %[eight] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest2], %[src_lo], %[src_hi] \n\t" - "paddw %[dest2], %[dest2], %[src] \n\t" - "psrlw %[dest2], %[dest2], %[eight] \n\t" - - "gsldlc1 %[src], 0x19(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x12(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "dsll %[src], %[src], %[eight] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest3], %[src_lo], %[src_hi] \n\t" - "paddw %[dest3], %[dest3], %[src] \n\t" - "psrlw %[dest3], %[dest3], %[eight] \n\t" - - "packsswh %[src_lo], %[dest0], %[dest1] \n\t" - "packsswh %[src_hi], %[dest2], %[dest3] \n\t" - "packushb %[dest0], %[src_lo], %[src_hi] \n\t" - "gssdlc1 %[dest0], 0x07(%[dst_y]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_y]) \n\t" - - "daddiu %[src_argb0], %[src_argb0], 0x18 \n\t" - "daddiu %[dst_y], %[dst_y], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [dest2] "=&f"(dest2), - [dest3] "=&f"(dest3) - : [src_argb0] "r"(src_argb0), [dst_y] "r"(dst_y), [width] "r"(width), - [mask] "f"(mask), [value] "f"(value), [eight] "f"(0x08), - [zero] "f"(0x00) - : "memory"); -} - -void RGB24ToUVRow_MMI(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t src_rgb1; - uint64_t ftmp[12]; - const uint64_t value = 0x4040; - const uint64_t mask_u = 0x0026004a00700002; - const uint64_t mask_v = 0x00020070005e0012; - - __asm__ volatile( - "1: \n\t" - "daddu %[src_rgb1], %[src_rgb0], %[src_stride_rgb] \n\t" - "gsldrc1 %[src0], 0x00(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x00(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x07(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[dest0_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest0_u], %[dest0_u], %[value] \n\t" - "pinsrh_3 %[dest0_v], %[src0], %[value] \n\t" - "pmaddhw %[dest0_u], %[dest0_u], %[mask_u] \n\t" - "pmaddhw %[dest0_v], %[dest0_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x06(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x0d(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x06(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x0d(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest0_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest0_u], %[src_lo] \n\t" - "psubw %[dest0_u], %[src0], %[src1] \n\t" - "psraw %[dest0_u], %[dest0_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest0_v], %[src_hi] \n\t" - "psubw %[dest0_v], %[src1], %[src0] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x0c(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x13(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x0c(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x13(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[dest1_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest1_u], %[dest1_u], %[value] \n\t" - "pinsrh_3 %[dest1_v], %[src0], %[value] \n\t" - "pmaddhw %[dest1_u], %[dest1_u], %[mask_u] \n\t" - "pmaddhw %[dest1_v], %[dest1_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x12(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x19(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x12(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x19(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest1_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest1_u], %[src_lo] \n\t" - "psubw %[dest1_u], %[src0], %[src1] \n\t" - "psraw %[dest1_u], %[dest1_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest1_v], %[src_hi] \n\t" - "psubw %[dest1_v], %[src1], %[src0] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x18(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x1f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x18(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x1f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[dest2_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest2_u], %[dest2_u], %[value] \n\t" - "pinsrh_3 %[dest2_v], %[src0], %[value] \n\t" - "pmaddhw %[dest2_u], %[dest2_u], %[mask_u] \n\t" - "pmaddhw %[dest2_v], %[dest2_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x1e(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x25(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x1e(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x25(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest2_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest2_u], %[src_lo] \n\t" - "psubw %[dest2_u], %[src0], %[src1] \n\t" - "psraw %[dest2_u], %[dest2_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest2_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest2_v], %[src_hi] \n\t" - "psubw %[dest2_v], %[src1], %[src0] \n\t" - "psraw %[dest2_v], %[dest2_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x24(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x2b(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x24(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x2b(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[dest3_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest3_u], %[dest3_u], %[value] \n\t" - "pinsrh_3 %[dest3_v], %[src0], %[value] \n\t" - "pmaddhw %[dest3_u], %[dest3_u], %[mask_u] \n\t" - "pmaddhw %[dest3_v], %[dest3_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x2a(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x31(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x2a(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x31(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest3_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest3_u], %[src_lo] \n\t" - "psubw %[dest3_u], %[src0], %[src1] \n\t" - "psraw %[dest3_u], %[dest3_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest3_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest3_v], %[src_hi] \n\t" - "psubw %[dest3_v], %[src1], %[src0] \n\t" - "psraw %[dest3_v], %[dest3_v], %[eight] \n\t" - - "packsswh %[src0], %[dest0_u], %[dest1_u] \n\t" - "packsswh %[src1], %[dest2_u], %[dest3_u] \n\t" - "packushb %[dest0_u], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_u], 0x07(%[dst_u]) \n\t" - "gssdrc1 %[dest0_u], 0x00(%[dst_u]) \n\t" - - "packsswh %[src0], %[dest0_v], %[dest1_v] \n\t" - "packsswh %[src1], %[dest2_v], %[dest3_v] \n\t" - "packushb %[dest0_v], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_v], 0x07(%[dst_v]) \n\t" - "gssdrc1 %[dest0_v], 0x00(%[dst_v]) \n\t" - - "daddiu %[src_rgb0], %[src_rgb0], 0x30 \n\t" - "daddiu %[dst_u], %[dst_u], 0x08 \n\t" - "daddiu %[dst_v], %[dst_v], 0x08 \n\t" - "daddi %[width], %[width], -0x10 \n\t" - "bgtz %[width], 1b \n\t" - : [src_rgb1] "=&r"(src_rgb1), [src0] "=&f"(ftmp[0]), - [src1] "=&f"(ftmp[1]), [src_lo] "=&f"(ftmp[2]), [src_hi] "=&f"(ftmp[3]), - [dest0_u] "=&f"(ftmp[4]), [dest0_v] "=&f"(ftmp[5]), - [dest1_u] "=&f"(ftmp[6]), [dest1_v] "=&f"(ftmp[7]), - [dest2_u] "=&f"(ftmp[8]), [dest2_v] "=&f"(ftmp[9]), - [dest3_u] "=&f"(ftmp[10]), [dest3_v] "=&f"(ftmp[11]) - : [src_rgb0] "r"(src_rgb0), [src_stride_rgb] "r"(src_stride_rgb), - [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), [width] "r"(width), - [mask_u] "f"(mask_u), [mask_v] "f"(mask_v), [value] "f"(value), - [zero] "f"(0x00), [eight] "f"(0x08), [two] "f"(0x02), - [sixteen] "f"(0x10) - : "memory"); -} - -void RAWToYRow_MMI(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - uint64_t src, src_hi, src_lo; - uint64_t dest0, dest1, dest2, dest3; - const uint64_t value = 0x1080; - const uint64_t mask = 0x0001001900810042; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x00(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "dsll %[src], %[src], %[eight] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest0], %[src_lo], %[src_hi] \n\t" - "paddw %[dest0], %[dest0], %[src] \n\t" - "psrlw %[dest0], %[dest0], %[eight] \n\t" - - "gsldlc1 %[src], 0x0d(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x06(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "dsll %[src], %[src], %[eight] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest1], %[dest1], %[src] \n\t" - "psrlw %[dest1], %[dest1], %[eight] \n\t" - - "gsldlc1 %[src], 0x13(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x0c(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "dsll %[src], %[src], %[eight] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest2], %[src_lo], %[src_hi] \n\t" - "paddw %[dest2], %[dest2], %[src] \n\t" - "psrlw %[dest2], %[dest2], %[eight] \n\t" - - "gsldlc1 %[src], 0x19(%[src_argb0]) \n\t" - "gsldrc1 %[src], 0x12(%[src_argb0]) \n\t" - "punpcklbh %[src_lo], %[src], %[zero] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "dsll %[src], %[src], %[eight] \n\t" - "punpckhbh %[src_hi], %[src], %[zero] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[dest3], %[src_lo], %[src_hi] \n\t" - "paddw %[dest3], %[dest3], %[src] \n\t" - "psrlw %[dest3], %[dest3], %[eight] \n\t" - - "packsswh %[src_lo], %[dest0], %[dest1] \n\t" - "packsswh %[src_hi], %[dest2], %[dest3] \n\t" - "packushb %[dest0], %[src_lo], %[src_hi] \n\t" - "gssdlc1 %[dest0], 0x07(%[dst_y]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_y]) \n\t" - - "daddiu %[src_argb0], %[src_argb0], 0x18 \n\t" - "daddiu %[dst_y], %[dst_y], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [dest2] "=&f"(dest2), - [dest3] "=&f"(dest3) - : [src_argb0] "r"(src_argb0), [dst_y] "r"(dst_y), [width] "r"(width), - [mask] "f"(mask), [value] "f"(value), [eight] "f"(0x08), - [zero] "f"(0x00) - : "memory"); -} - -void RAWToUVRow_MMI(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t src_rgb1; - uint64_t ftmp[12]; - const uint64_t value = 0x4040; - const uint64_t mask_u = 0x00020070004a0026; - const uint64_t mask_v = 0x0012005e00700002; - - __asm__ volatile( - "1: \n\t" - "daddu %[src_rgb1], %[src_rgb0], %[src_stride_rgb] \n\t" - "gsldrc1 %[src0], 0x00(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x00(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x07(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[dest0_u], %[src0], %[value] \n\t" - "dsll %[dest0_v], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest0_v], %[dest0_v], %[value] \n\t" - "pmaddhw %[dest0_u], %[dest0_u], %[mask_u] \n\t" - "pmaddhw %[dest0_v], %[dest0_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x06(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x0d(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x06(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x0d(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[src_lo], %[src0], %[value] \n\t" - "dsll %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest0_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest0_u], %[src_lo] \n\t" - "psubw %[dest0_u], %[src1], %[src0] \n\t" - "psraw %[dest0_u], %[dest0_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest0_v], %[src_hi] \n\t" - "psubw %[dest0_v], %[src0], %[src1] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x0c(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x13(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x0c(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x13(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[dest1_u], %[src0], %[value] \n\t" - "dsll %[dest1_v], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest1_v], %[dest1_v], %[value] \n\t" - "pmaddhw %[dest1_u], %[dest1_u], %[mask_u] \n\t" - "pmaddhw %[dest1_v], %[dest1_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x12(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x19(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x12(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x19(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[src_lo], %[src0], %[value] \n\t" - "dsll %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest1_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest1_u], %[src_lo] \n\t" - "psubw %[dest1_u], %[src1], %[src0] \n\t" - "psraw %[dest1_u], %[dest1_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest1_v], %[src_hi] \n\t" - "psubw %[dest1_v], %[src0], %[src1] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x18(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x1f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x18(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x1f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[dest2_u], %[src0], %[value] \n\t" - "dsll %[dest2_v], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest2_v], %[dest2_v], %[value] \n\t" - "pmaddhw %[dest2_u], %[dest2_u], %[mask_u] \n\t" - "pmaddhw %[dest2_v], %[dest2_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x1e(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x25(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x1e(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x25(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[src_lo], %[src0], %[value] \n\t" - "dsll %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest2_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest2_u], %[src_lo] \n\t" - "psubw %[dest2_u], %[src1], %[src0] \n\t" - "psraw %[dest2_u], %[dest2_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest2_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest2_v], %[src_hi] \n\t" - "psubw %[dest2_v], %[src0], %[src1] \n\t" - "psraw %[dest2_v], %[dest2_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x24(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x2b(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x24(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x2b(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[dest3_u], %[src0], %[value] \n\t" - "dsll %[dest3_v], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest3_v], %[dest3_v], %[value] \n\t" - "pmaddhw %[dest3_u], %[dest3_u], %[mask_u] \n\t" - "pmaddhw %[dest3_v], %[dest3_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x2a(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x31(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x2a(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x31(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "dsll %[src0], %[src0], %[eight] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "paddh %[src0], %[src_lo], %[src_hi] \n\t" - "punpcklbh %[src_lo], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_lo] \n\t" - "dsll %[src1], %[src1], %[eight] \n\t" - "punpckhbh %[src_hi], %[src1], %[zero] \n\t" - "paddh %[src0], %[src0], %[src_hi] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "pinsrh_3 %[src_lo], %[src0], %[value] \n\t" - "dsll %[src_hi], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest3_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest3_u], %[src_lo] \n\t" - "psubw %[dest3_u], %[src1], %[src0] \n\t" - "psraw %[dest3_u], %[dest3_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest3_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest3_v], %[src_hi] \n\t" - "psubw %[dest3_v], %[src0], %[src1] \n\t" - "psraw %[dest3_v], %[dest3_v], %[eight] \n\t" - - "packsswh %[src0], %[dest0_u], %[dest1_u] \n\t" - "packsswh %[src1], %[dest2_u], %[dest3_u] \n\t" - "packushb %[dest0_u], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_u], 0x07(%[dst_u]) \n\t" - "gssdrc1 %[dest0_u], 0x00(%[dst_u]) \n\t" - - "packsswh %[src0], %[dest0_v], %[dest1_v] \n\t" - "packsswh %[src1], %[dest2_v], %[dest3_v] \n\t" - "packushb %[dest0_v], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_v], 0x07(%[dst_v]) \n\t" - "gssdrc1 %[dest0_v], 0x00(%[dst_v]) \n\t" - - "daddiu %[src_rgb0], %[src_rgb0], 0x30 \n\t" - "daddiu %[dst_u], %[dst_u], 0x08 \n\t" - "daddiu %[dst_v], %[dst_v], 0x08 \n\t" - "daddi %[width], %[width], -0x10 \n\t" - "bgtz %[width], 1b \n\t" - : [src_rgb1] "=&r"(src_rgb1), [src0] "=&f"(ftmp[0]), - [src1] "=&f"(ftmp[1]), [src_lo] "=&f"(ftmp[2]), [src_hi] "=&f"(ftmp[3]), - [dest0_u] "=&f"(ftmp[4]), [dest0_v] "=&f"(ftmp[5]), - [dest1_u] "=&f"(ftmp[6]), [dest1_v] "=&f"(ftmp[7]), - [dest2_u] "=&f"(ftmp[8]), [dest2_v] "=&f"(ftmp[9]), - [dest3_u] "=&f"(ftmp[10]), [dest3_v] "=&f"(ftmp[11]) - : [src_rgb0] "r"(src_rgb0), [src_stride_rgb] "r"(src_stride_rgb), - [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), [width] "r"(width), - [mask_u] "f"(mask_u), [mask_v] "f"(mask_v), [value] "f"(value), - [zero] "f"(0x00), [eight] "f"(0x08), [two] "f"(0x02), - [sixteen] "f"(0x10) - : "memory"); -} - -void ARGBToYJRow_MMI(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - uint64_t src, src_hi, src_lo; - uint64_t dest, dest0, dest1, dest2, dest3; - uint64_t tmp0, tmp1; - const uint64_t shift = 0x07; - const uint64_t value = 0x0040; - const uint64_t mask0 = 0x0; - const uint64_t mask1 = 0x00010026004B000FULL; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - "punpcklbh %[src_lo], %[src], %[mask0] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask1] \n\t" - "punpckhbh %[src_hi], %[src], %[mask0] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask1] \n\t" - "punpcklwd %[tmp0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[tmp1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest0], %[tmp0], %[tmp1] \n\t" - "psrlw %[dest0], %[dest0], %[shift] \n\t" - - "gsldlc1 %[src], 0x0f(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x08(%[src_ptr]) \n\t" - "punpcklbh %[src_lo], %[src], %[mask0] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask1] \n\t" - "punpckhbh %[src_hi], %[src], %[mask0] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask1] \n\t" - "punpcklwd %[tmp0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[tmp1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest1], %[tmp0], %[tmp1] \n\t" - "psrlw %[dest1], %[dest1], %[shift] \n\t" - - "gsldlc1 %[src], 0x17(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x10(%[src_ptr]) \n\t" - "punpcklbh %[src_lo], %[src], %[mask0] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask1] \n\t" - "punpckhbh %[src_hi], %[src], %[mask0] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask1] \n\t" - "punpcklwd %[tmp0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[tmp1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest2], %[tmp0], %[tmp1] \n\t" - "psrlw %[dest2], %[dest2], %[shift] \n\t" - - "gsldlc1 %[src], 0x1f(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x18(%[src_ptr]) \n\t" - "punpcklbh %[src_lo], %[src], %[mask0] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask1] \n\t" - "punpckhbh %[src_hi], %[src], %[mask0] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask1] \n\t" - "punpcklwd %[tmp0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[tmp1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest3], %[tmp0], %[tmp1] \n\t" - "psrlw %[dest3], %[dest3], %[shift] \n\t" - - "packsswh %[tmp0], %[dest0], %[dest1] \n\t" - "packsswh %[tmp1], %[dest2], %[dest3] \n\t" - "packushb %[dest], %[tmp0], %[tmp1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x20 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [dest] "=&f"(dest), [src_hi] "=&f"(src_hi), - [src_lo] "=&f"(src_lo), [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), - [dest2] "=&f"(dest2), [dest3] "=&f"(dest3), [tmp0] "=&f"(tmp0), - [tmp1] "=&f"(tmp1) - : [src_ptr] "r"(src_argb0), [dst_ptr] "r"(dst_y), [mask0] "f"(mask0), - [mask1] "f"(mask1), [shift] "f"(shift), [value] "f"(value), - [width] "r"(width) - : "memory"); -} - -void ARGBToUVJRow_MMI(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t src_rgb1; - uint64_t ftmp[12]; - const uint64_t value = 0x4040; - const uint64_t mask_u = 0x002b0054007f0002; - const uint64_t mask_v = 0x0002007f006b0014; - - __asm__ volatile( - "1: \n\t" - "daddu %[src_rgb1], %[src_rgb0], %[src_stride_rgb] \n\t" - "gsldrc1 %[src0], 0x00(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x00(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x07(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "punpcklbh %[src0], %[src1], %[zero] \n\t" - "punpckhbh %[src1], %[src1], %[zero] \n\t" - "pavgh %[src0], %[src_lo], %[src0] \n\t" - "pavgh %[src1], %[src_hi], %[src1] \n\t" - "pavgh %[src0], %[src0], %[src1] \n\t" - "dsll %[dest0_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest0_u], %[dest0_u], %[value] \n\t" - "pinsrh_3 %[dest0_v], %[src0], %[value] \n\t" - "pmaddhw %[dest0_u], %[dest0_u], %[mask_u] \n\t" - "pmaddhw %[dest0_v], %[dest0_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "punpcklbh %[src0], %[src1], %[zero] \n\t" - "punpckhbh %[src1], %[src1], %[zero] \n\t" - "pavgh %[src0], %[src_lo], %[src0] \n\t" - "pavgh %[src1], %[src_hi], %[src1] \n\t" - "pavgh %[src0], %[src0], %[src1] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest0_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest0_u], %[src_lo] \n\t" - "psubw %[dest0_u], %[src0], %[src1] \n\t" - "psraw %[dest0_u], %[dest0_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest0_v], %[src_hi] \n\t" - "psubw %[dest0_v], %[src1], %[src0] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x10(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x17(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x10(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x17(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "punpcklbh %[src0], %[src1], %[zero] \n\t" - "punpckhbh %[src1], %[src1], %[zero] \n\t" - "pavgh %[src0], %[src_lo], %[src0] \n\t" - "pavgh %[src1], %[src_hi], %[src1] \n\t" - "pavgh %[src0], %[src0], %[src1] \n\t" - "dsll %[dest1_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest1_u], %[dest1_u], %[value] \n\t" - "pinsrh_3 %[dest1_v], %[src0], %[value] \n\t" - "pmaddhw %[dest1_u], %[dest1_u], %[mask_u] \n\t" - "pmaddhw %[dest1_v], %[dest1_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x18(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x1f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x18(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x1f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "punpcklbh %[src0], %[src1], %[zero] \n\t" - "punpckhbh %[src1], %[src1], %[zero] \n\t" - "pavgh %[src0], %[src_lo], %[src0] \n\t" - "pavgh %[src1], %[src_hi], %[src1] \n\t" - "pavgh %[src0], %[src0], %[src1] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest1_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest1_u], %[src_lo] \n\t" - "psubw %[dest1_u], %[src0], %[src1] \n\t" - "psraw %[dest1_u], %[dest1_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest1_v], %[src_hi] \n\t" - "psubw %[dest1_v], %[src1], %[src0] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x20(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x27(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x20(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x27(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "punpcklbh %[src0], %[src1], %[zero] \n\t" - "punpckhbh %[src1], %[src1], %[zero] \n\t" - "pavgh %[src0], %[src_lo], %[src0] \n\t" - "pavgh %[src1], %[src_hi], %[src1] \n\t" - "pavgh %[src0], %[src0], %[src1] \n\t" - "dsll %[dest2_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest2_u], %[dest2_u], %[value] \n\t" - "pinsrh_3 %[dest2_v], %[src0], %[value] \n\t" - "pmaddhw %[dest2_u], %[dest2_u], %[mask_u] \n\t" - "pmaddhw %[dest2_v], %[dest2_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x28(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x2f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x28(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x2f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "punpcklbh %[src0], %[src1], %[zero] \n\t" - "punpckhbh %[src1], %[src1], %[zero] \n\t" - "pavgh %[src0], %[src_lo], %[src0] \n\t" - "pavgh %[src1], %[src_hi], %[src1] \n\t" - "pavgh %[src0], %[src0], %[src1] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest2_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest2_u], %[src_lo] \n\t" - "psubw %[dest2_u], %[src0], %[src1] \n\t" - "psraw %[dest2_u], %[dest2_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest2_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest2_v], %[src_hi] \n\t" - "psubw %[dest2_v], %[src1], %[src0] \n\t" - "psraw %[dest2_v], %[dest2_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x30(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x37(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x30(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x37(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "punpcklbh %[src0], %[src1], %[zero] \n\t" - "punpckhbh %[src1], %[src1], %[zero] \n\t" - "pavgh %[src0], %[src_lo], %[src0] \n\t" - "pavgh %[src1], %[src_hi], %[src1] \n\t" - "pavgh %[src0], %[src0], %[src1] \n\t" - "dsll %[dest3_u], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[dest3_u], %[dest3_u], %[value] \n\t" - "pinsrh_3 %[dest3_v], %[src0], %[value] \n\t" - "pmaddhw %[dest3_u], %[dest3_u], %[mask_u] \n\t" - "pmaddhw %[dest3_v], %[dest3_v], %[mask_v] \n\t" - - "gsldrc1 %[src0], 0x38(%[src_rgb0]) \n\t" - "gsldlc1 %[src0], 0x3f(%[src_rgb0]) \n\t" - "gsldrc1 %[src1], 0x38(%[src_rgb1]) \n\t" - "gsldlc1 %[src1], 0x3f(%[src_rgb1]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "punpcklbh %[src0], %[src1], %[zero] \n\t" - "punpckhbh %[src1], %[src1], %[zero] \n\t" - "pavgh %[src0], %[src_lo], %[src0] \n\t" - "pavgh %[src1], %[src_hi], %[src1] \n\t" - "pavgh %[src0], %[src0], %[src1] \n\t" - "dsll %[src_lo], %[src0], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src0], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest3_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest3_u], %[src_lo] \n\t" - "psubw %[dest3_u], %[src0], %[src1] \n\t" - "psraw %[dest3_u], %[dest3_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest3_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest3_v], %[src_hi] \n\t" - "psubw %[dest3_v], %[src1], %[src0] \n\t" - "psraw %[dest3_v], %[dest3_v], %[eight] \n\t" - - "packsswh %[src0], %[dest0_u], %[dest1_u] \n\t" - "packsswh %[src1], %[dest2_u], %[dest3_u] \n\t" - "packushb %[dest0_u], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_u], 0x07(%[dst_u]) \n\t" - "gssdrc1 %[dest0_u], 0x00(%[dst_u]) \n\t" - - "packsswh %[src0], %[dest0_v], %[dest1_v] \n\t" - "packsswh %[src1], %[dest2_v], %[dest3_v] \n\t" - "packushb %[dest0_v], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_v], 0x07(%[dst_v]) \n\t" - "gssdrc1 %[dest0_v], 0x00(%[dst_v]) \n\t" - - "daddiu %[src_rgb0], %[src_rgb0], 0x40 \n\t" - "daddiu %[dst_u], %[dst_u], 0x08 \n\t" - "daddiu %[dst_v], %[dst_v], 0x08 \n\t" - "daddi %[width], %[width], -0x10 \n\t" - "bgtz %[width], 1b \n\t" - : [src_rgb1] "=&r"(src_rgb1), [src0] "=&f"(ftmp[0]), - [src1] "=&f"(ftmp[1]), [src_lo] "=&f"(ftmp[2]), [src_hi] "=&f"(ftmp[3]), - [dest0_u] "=&f"(ftmp[4]), [dest0_v] "=&f"(ftmp[5]), - [dest1_u] "=&f"(ftmp[6]), [dest1_v] "=&f"(ftmp[7]), - [dest2_u] "=&f"(ftmp[8]), [dest2_v] "=&f"(ftmp[9]), - [dest3_u] "=&f"(ftmp[10]), [dest3_v] "=&f"(ftmp[11]) - : [src_rgb0] "r"(src_rgb0), [src_stride_rgb] "r"(src_stride_rgb), - [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), [width] "r"(width), - [mask_u] "f"(mask_u), [mask_v] "f"(mask_v), [value] "f"(value), - [zero] "f"(0x00), [eight] "f"(0x08), [two] "f"(0x02), - [sixteen] "f"(0x10) - : "memory"); -} - -void RGB565ToYRow_MMI(const uint8_t* src_rgb565, uint8_t* dst_y, int width) { - uint64_t ftmp[11]; - const uint64_t value = 0x1080108010801080; - const uint64_t mask = 0x0001004200810019; - uint64_t c0 = 0x001f001f001f001f; - uint64_t c1 = 0x00ff00ff00ff00ff; - uint64_t c2 = 0x0007000700070007; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_rgb565]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_rgb565]) \n\t" - "psrlh %[src1], %[src0], %[eight] \n\t" - "and %[b], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g], %[src1], %[c2] \n\t" - "psllh %[g], %[g], %[three] \n\t" - "or %[g], %[src0], %[g] \n\t" - "psrlh %[r], %[src1], %[three] \n\t" - "psllh %[src0], %[b], %[three] \n\t" - "psrlh %[src1], %[b], %[two] \n\t" - "or %[b], %[src0], %[src1] \n\t" - "psllh %[src0], %[g], %[two] \n\t" - "psrlh %[src1], %[g], %[four] \n\t" - "or %[g], %[src0], %[src1] \n\t" - "psllh %[src0], %[r], %[three] \n\t" - "psrlh %[src1], %[r], %[two] \n\t" - "or %[r], %[src0], %[src1] \n\t" - "punpcklhw %[src0], %[b], %[r] \n\t" - "punpcklhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest0], %[src0], %[src1] \n\t" - "psrlw %[dest0], %[dest0], %[eight] \n\t" - - "punpckhhw %[src0], %[b], %[r] \n\t" - "punpckhhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest1], %[src0], %[src1] \n\t" - "psrlw %[dest1], %[dest1], %[eight] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_rgb565]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_rgb565]) \n\t" - "psrlh %[src1], %[src0], %[eight] \n\t" - "and %[b], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g], %[src1], %[c2] \n\t" - "psllh %[g], %[g], %[three] \n\t" - "or %[g], %[src0], %[g] \n\t" - "psrlh %[r], %[src1], %[three] \n\t" - "psllh %[src0], %[b], %[three] \n\t" - "psrlh %[src1], %[b], %[two] \n\t" - "or %[b], %[src0], %[src1] \n\t" - "psllh %[src0], %[g], %[two] \n\t" - "psrlh %[src1], %[g], %[four] \n\t" - "or %[g], %[src0], %[src1] \n\t" - "psllh %[src0], %[r], %[three] \n\t" - "psrlh %[src1], %[r], %[two] \n\t" - "or %[r], %[src0], %[src1] \n\t" - "punpcklhw %[src0], %[b], %[r] \n\t" - "punpcklhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest2], %[src0], %[src1] \n\t" - "psrlw %[dest2], %[dest2], %[eight] \n\t" - - "punpckhhw %[src0], %[b], %[r] \n\t" - "punpckhhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest3], %[src0], %[src1] \n\t" - "psrlw %[dest3], %[dest3], %[eight] \n\t" - - "packsswh %[src_lo], %[dest0], %[dest1] \n\t" - "packsswh %[src_hi], %[dest2], %[dest3] \n\t" - "packushb %[dest0], %[src_lo], %[src_hi] \n\t" - "gssdlc1 %[dest0], 0x07(%[dst_y]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_y]) \n\t" - - "daddiu %[src_rgb565], %[src_rgb565], 0x10 \n\t" - "daddiu %[dst_y], %[dst_y], 0x08 \n\t" - "daddiu %[width], %[width], -0x08 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(ftmp[0]), [src1] "=&f"(ftmp[1]), [src_lo] "=&f"(ftmp[2]), - [src_hi] "=&f"(ftmp[3]), [b] "=&f"(ftmp[4]), [g] "=&f"(ftmp[5]), - [r] "=&f"(ftmp[6]), [dest0] "=&f"(ftmp[7]), [dest1] "=&f"(ftmp[8]), - [dest2] "=&f"(ftmp[9]), [dest3] "=&f"(ftmp[10]) - : [src_rgb565] "r"(src_rgb565), [dst_y] "r"(dst_y), [value] "f"(value), - [width] "r"(width), [c0] "f"(c0), [c1] "f"(c1), [c2] "f"(c2), - [mask] "f"(mask), [eight] "f"(0x08), [five] "f"(0x05), - [three] "f"(0x03), [two] "f"(0x02), [four] "f"(0x04) - : "memory"); -} - -void ARGB1555ToYRow_MMI(const uint8_t* src_argb1555, - uint8_t* dst_y, - int width) { - uint64_t ftmp[11]; - const uint64_t value = 0x1080108010801080; - const uint64_t mask = 0x0001004200810019; - uint64_t c0 = 0x001f001f001f001f; - uint64_t c1 = 0x00ff00ff00ff00ff; - uint64_t c2 = 0x0003000300030003; - uint64_t c3 = 0x007c007c007c007c; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb1555]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb1555]) \n\t" - "psrlh %[src1], %[src0], %[eight] \n\t" - "and %[b], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g], %[src1], %[c2] \n\t" - "psllh %[g], %[g], %[three] \n\t" - "or %[g], %[src0], %[g] \n\t" - "and %[r], %[src1], %[c3] \n\t" - "psrlh %[r], %[r], %[two] \n\t" - "psllh %[src0], %[b], %[three] \n\t" - "psrlh %[src1], %[b], %[two] \n\t" - "or %[b], %[src0], %[src1] \n\t" - "psllh %[src0], %[g], %[three] \n\t" - "psrlh %[src1], %[g], %[two] \n\t" - "or %[g], %[src0], %[src1] \n\t" - "psllh %[src0], %[r], %[three] \n\t" - "psrlh %[src1], %[r], %[two] \n\t" - "or %[r], %[src0], %[src1] \n\t" - "punpcklhw %[src0], %[b], %[r] \n\t" - "punpcklhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest0], %[src0], %[src1] \n\t" - "psrlw %[dest0], %[dest0], %[eight] \n\t" - - "punpckhhw %[src0], %[b], %[r] \n\t" - "punpckhhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest1], %[src0], %[src1] \n\t" - "psrlw %[dest1], %[dest1], %[eight] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_argb1555]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_argb1555]) \n\t" - "psrlh %[src1], %[src0], %[eight] \n\t" - "and %[b], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g], %[src1], %[c2] \n\t" - "psllh %[g], %[g], %[three] \n\t" - "or %[g], %[src0], %[g] \n\t" - "and %[r], %[src1], %[c3] \n\t" - "psrlh %[r], %[r], %[two] \n\t" - "psllh %[src0], %[b], %[three] \n\t" - "psrlh %[src1], %[b], %[two] \n\t" - "or %[b], %[src0], %[src1] \n\t" - "psllh %[src0], %[g], %[three] \n\t" - "psrlh %[src1], %[g], %[two] \n\t" - "or %[g], %[src0], %[src1] \n\t" - "psllh %[src0], %[r], %[three] \n\t" - "psrlh %[src1], %[r], %[two] \n\t" - "or %[r], %[src0], %[src1] \n\t" - "punpcklhw %[src0], %[b], %[r] \n\t" - "punpcklhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest2], %[src0], %[src1] \n\t" - "psrlw %[dest2], %[dest2], %[eight] \n\t" - - "punpckhhw %[src0], %[b], %[r] \n\t" - "punpckhhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest3], %[src0], %[src1] \n\t" - "psrlw %[dest3], %[dest3], %[eight] \n\t" - - "packsswh %[src_lo], %[dest0], %[dest1] \n\t" - "packsswh %[src_hi], %[dest2], %[dest3] \n\t" - "packushb %[dest0], %[src_lo], %[src_hi] \n\t" - "gssdlc1 %[dest0], 0x07(%[dst_y]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_y]) \n\t" - - "daddiu %[src_argb1555], %[src_argb1555], 0x10 \n\t" - "daddiu %[dst_y], %[dst_y], 0x08 \n\t" - "daddiu %[width], %[width], -0x08 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(ftmp[0]), [src1] "=&f"(ftmp[1]), [src_lo] "=&f"(ftmp[2]), - [src_hi] "=&f"(ftmp[3]), [b] "=&f"(ftmp[4]), [g] "=&f"(ftmp[5]), - [r] "=&f"(ftmp[6]), [dest0] "=&f"(ftmp[7]), [dest1] "=&f"(ftmp[8]), - [dest2] "=&f"(ftmp[9]), [dest3] "=&f"(ftmp[10]) - : [src_argb1555] "r"(src_argb1555), [dst_y] "r"(dst_y), - [width] "r"(width), [value] "f"(value), [mask] "f"(mask), [c0] "f"(c0), - [c1] "f"(c1), [c2] "f"(c2), [c3] "f"(c3), [eight] "f"(0x08), - [five] "f"(0x05), [three] "f"(0x03), [two] "f"(0x02), [seven] "f"(0x07) - : "memory"); -} - -void ARGB4444ToYRow_MMI(const uint8_t* src_argb4444, - uint8_t* dst_y, - int width) { - uint64_t ftmp[11]; - uint64_t value = 0x1080108010801080; - uint64_t mask = 0x0001004200810019; - uint64_t c0 = 0x000f000f000f000f; - uint64_t c1 = 0x00ff00ff00ff00ff; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb4444]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb4444]) \n\t" - "psrlh %[src1], %[src0], %[eight] \n\t" - "and %[b], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[g], %[src0], %[four] \n\t" - "and %[r], %[src1], %[c0] \n\t" - "psllh %[src0], %[b], %[four] \n\t" - "or %[b], %[src0], %[b] \n\t" - "psllh %[src0], %[g], %[four] \n\t" - "or %[g], %[src0], %[g] \n\t" - "psllh %[src0], %[r], %[four] \n\t" - "or %[r], %[src0], %[r] \n\t" - "punpcklhw %[src0], %[b], %[r] \n\t" - "punpcklhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest0], %[src0], %[src1] \n\t" - "psrlw %[dest0], %[dest0], %[eight] \n\t" - - "punpckhhw %[src0], %[b], %[r] \n\t" - "punpckhhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest1], %[src0], %[src1] \n\t" - "psrlw %[dest1], %[dest1], %[eight] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_argb4444]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_argb4444]) \n\t" - "psrlh %[src1], %[src0], %[eight] \n\t" - "and %[b], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[g], %[src0], %[four] \n\t" - "and %[r], %[src1], %[c0] \n\t" - "psllh %[src0], %[b], %[four] \n\t" - "or %[b], %[src0], %[b] \n\t" - "psllh %[src0], %[g], %[four] \n\t" - "or %[g], %[src0], %[g] \n\t" - "psllh %[src0], %[r], %[four] \n\t" - "or %[r], %[src0], %[r] \n\t" - "punpcklhw %[src0], %[b], %[r] \n\t" - "punpcklhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest2], %[src0], %[src1] \n\t" - "psrlw %[dest2], %[dest2], %[eight] \n\t" - - "punpckhhw %[src0], %[b], %[r] \n\t" - "punpckhhw %[src1], %[g], %[value] \n\t" - "punpcklhw %[src_lo], %[src0], %[src1] \n\t" - "punpckhhw %[src_hi], %[src0], %[src1] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask] \n\t" - "punpcklwd %[src0], %[src_lo], %[src_hi] \n\t" - "punpckhwd %[src1], %[src_lo], %[src_hi] \n\t" - "paddw %[dest3], %[src0], %[src1] \n\t" - "psrlw %[dest3], %[dest3], %[eight] \n\t" - - "packsswh %[src_lo], %[dest0], %[dest1] \n\t" - "packsswh %[src_hi], %[dest2], %[dest3] \n\t" - "packushb %[dest0], %[src_lo], %[src_hi] \n\t" - "gssdlc1 %[dest0], 0x07(%[dst_y]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_y]) \n\t" - - "daddiu %[src_argb4444], %[src_argb4444], 0x10 \n\t" - "daddiu %[dst_y], %[dst_y], 0x08 \n\t" - "daddiu %[width], %[width], -0x08 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(ftmp[0]), [src1] "=&f"(ftmp[1]), [src_lo] "=&f"(ftmp[2]), - [src_hi] "=&f"(ftmp[3]), [b] "=&f"(ftmp[4]), [g] "=&f"(ftmp[5]), - [r] "=&f"(ftmp[6]), [dest0] "=&f"(ftmp[7]), [dest1] "=&f"(ftmp[8]), - [dest2] "=&f"(ftmp[9]), [dest3] "=&f"(ftmp[10]) - : [src_argb4444] "r"(src_argb4444), [dst_y] "r"(dst_y), - [width] "r"(width), [value] "f"(value), [mask] "f"(mask), [c0] "f"(c0), - [c1] "f"(c1), [eight] "f"(0x08), [four] "f"(0x04) - : "memory"); -} - -void RGB565ToUVRow_MMI(const uint8_t* src_rgb565, - int src_stride_rgb565, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t ftmp[13]; - uint64_t value = 0x2020202020202020; - uint64_t mask_u = 0x0026004a00700002; - uint64_t mask_v = 0x00020070005e0012; - uint64_t mask = 0x93; - uint64_t c0 = 0x001f001f001f001f; - uint64_t c1 = 0x00ff00ff00ff00ff; - uint64_t c2 = 0x0007000700070007; - __asm__ volatile( - "daddu %[next_rgb565], %[src_rgb565], %[next_rgb565] \n\t" - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_rgb565]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_rgb565]) \n\t" - "gsldrc1 %[src1], 0x00(%[next_rgb565]) \n\t" - "gsldlc1 %[src1], 0x07(%[next_rgb565]) \n\t" - "psrlh %[dest0_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g0], %[dest0_u], %[c2] \n\t" - "psllh %[g0], %[g0], %[three] \n\t" - "or %[g0], %[src0], %[g0] \n\t" - "psrlh %[r0], %[dest0_u], %[three] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest0_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[src1], %[src1], %[five] \n\t" - "and %[dest0_v], %[src0], %[c2] \n\t" - "psllh %[dest0_v], %[dest0_v], %[three] \n\t" - "or %[dest0_v], %[src1], %[dest0_v] \n\t" - "psrlh %[src0], %[src0], %[three] \n\t" - "paddh %[b0], %[b0], %[dest0_u] \n\t" - "paddh %[g0], %[g0], %[dest0_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest0_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest0_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest0_u], %[dest0_v] \n\t" - "psrlh %[b0], %[src0], %[six] \n\t" - "psllh %[r0], %[src0], %[one] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest0_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest0_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest0_u], %[dest0_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest0_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest0_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest0_u], %[dest0_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest0_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest0_u], %[b0] \n\t" - "psubw %[dest0_u], %[src0], %[src1] \n\t" - "psraw %[dest0_u], %[dest0_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest0_v], %[g0] \n\t" - "psubw %[dest0_v], %[src1], %[src0] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_rgb565]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_rgb565]) \n\t" - "gsldrc1 %[src1], 0x08(%[next_rgb565]) \n\t" - "gsldlc1 %[src1], 0x0f(%[next_rgb565]) \n\t" - "psrlh %[dest1_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g0], %[dest1_u], %[c2] \n\t" - "psllh %[g0], %[g0], %[three] \n\t" - "or %[g0], %[src0], %[g0] \n\t" - "psrlh %[r0], %[dest1_u], %[three] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest1_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[src1], %[src1], %[five] \n\t" - "and %[dest1_v], %[src0], %[c2] \n\t" - "psllh %[dest1_v], %[dest1_v], %[three] \n\t" - "or %[dest1_v], %[src1], %[dest1_v] \n\t" - "psrlh %[src0], %[src0], %[three] \n\t" - "paddh %[b0], %[b0], %[dest1_u] \n\t" - "paddh %[g0], %[g0], %[dest1_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest1_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest1_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest1_u], %[dest1_v] \n\t" - "psrlh %[b0], %[src0], %[six] \n\t" - "psllh %[r0], %[src0], %[one] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest1_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest1_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest1_u], %[dest1_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest1_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest1_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest1_u], %[dest1_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest1_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest1_u], %[b0] \n\t" - "psubw %[dest1_u], %[src0], %[src1] \n\t" - "psraw %[dest1_u], %[dest1_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest1_v], %[g0] \n\t" - "psubw %[dest1_v], %[src1], %[src0] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x10(%[src_rgb565]) \n\t" - "gsldlc1 %[src0], 0x17(%[src_rgb565]) \n\t" - "gsldrc1 %[src1], 0x10(%[next_rgb565]) \n\t" - "gsldlc1 %[src1], 0x17(%[next_rgb565]) \n\t" - "psrlh %[dest2_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g0], %[dest2_u], %[c2] \n\t" - "psllh %[g0], %[g0], %[three] \n\t" - "or %[g0], %[src0], %[g0] \n\t" - "psrlh %[r0], %[dest2_u], %[three] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest2_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[src1], %[src1], %[five] \n\t" - "and %[dest2_v], %[src0], %[c2] \n\t" - "psllh %[dest2_v], %[dest2_v], %[three] \n\t" - "or %[dest2_v], %[src1], %[dest2_v] \n\t" - "psrlh %[src0], %[src0], %[three] \n\t" - "paddh %[b0], %[b0], %[dest2_u] \n\t" - "paddh %[g0], %[g0], %[dest2_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest2_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest2_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest2_u], %[dest2_v] \n\t" - "psrlh %[b0], %[src0], %[six] \n\t" - "psllh %[r0], %[src0], %[one] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest2_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest2_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest2_u], %[dest2_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest2_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest2_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest2_u], %[dest2_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest2_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest2_u], %[b0] \n\t" - "psubw %[dest2_u], %[src0], %[src1] \n\t" - "psraw %[dest2_u], %[dest2_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest2_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest2_v], %[g0] \n\t" - "psubw %[dest2_v], %[src1], %[src0] \n\t" - "psraw %[dest2_v], %[dest2_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x18(%[src_rgb565]) \n\t" - "gsldlc1 %[src0], 0x1f(%[src_rgb565]) \n\t" - "gsldrc1 %[src1], 0x18(%[next_rgb565]) \n\t" - "gsldlc1 %[src1], 0x1f(%[next_rgb565]) \n\t" - "psrlh %[dest3_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g0], %[dest3_u], %[c2] \n\t" - "psllh %[g0], %[g0], %[three] \n\t" - "or %[g0], %[src0], %[g0] \n\t" - "psrlh %[r0], %[dest3_u], %[three] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest3_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[src1], %[src1], %[five] \n\t" - "and %[dest3_v], %[src0], %[c2] \n\t" - "psllh %[dest3_v], %[dest3_v], %[three] \n\t" - "or %[dest3_v], %[src1], %[dest3_v] \n\t" - "psrlh %[src0], %[src0], %[three] \n\t" - "paddh %[b0], %[b0], %[dest3_u] \n\t" - "paddh %[g0], %[g0], %[dest3_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest3_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest3_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest3_u], %[dest3_v] \n\t" - "psrlh %[b0], %[src0], %[six] \n\t" - "psllh %[r0], %[src0], %[one] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest3_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest3_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest3_u], %[dest3_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest3_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest3_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest3_u], %[dest3_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest3_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest3_u], %[b0] \n\t" - "psubw %[dest3_u], %[src0], %[src1] \n\t" - "psraw %[dest3_u], %[dest3_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest3_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest3_v], %[g0] \n\t" - "psubw %[dest3_v], %[src1], %[src0] \n\t" - "psraw %[dest3_v], %[dest3_v], %[eight] \n\t" - - "packsswh %[src0], %[dest0_u], %[dest1_u] \n\t" - "packsswh %[src1], %[dest2_u], %[dest3_u] \n\t" - "packushb %[dest0_u], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_u], 0x07(%[dst_u]) \n\t" - "gssdrc1 %[dest0_u], 0x00(%[dst_u]) \n\t" - "packsswh %[src0], %[dest0_v], %[dest1_v] \n\t" - "packsswh %[src1], %[dest2_v], %[dest3_v] \n\t" - "packushb %[dest0_v], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_v], 0x07(%[dst_v]) \n\t" - "gssdrc1 %[dest0_v], 0x00(%[dst_v]) \n\t" - - "daddiu %[src_rgb565], %[src_rgb565], 0x20 \n\t" - "daddiu %[next_rgb565], %[next_rgb565], 0x20 \n\t" - "daddiu %[dst_u], %[dst_u], 0x08 \n\t" - "daddiu %[dst_v], %[dst_v], 0x08 \n\t" - "daddiu %[width], %[width], -0x10 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(ftmp[0]), [src1] "=&f"(ftmp[1]), [b0] "=&f"(ftmp[2]), - [g0] "=&f"(ftmp[3]), [r0] "=&f"(ftmp[4]), [dest0_u] "=&f"(ftmp[5]), - [dest1_u] "=&f"(ftmp[6]), [dest2_u] "=&f"(ftmp[7]), - [dest3_u] "=&f"(ftmp[8]), [dest0_v] "=&f"(ftmp[9]), - [dest1_v] "=&f"(ftmp[10]), [dest2_v] "=&f"(ftmp[11]), - [dest3_v] "=&f"(ftmp[12]) - : [src_rgb565] "r"(src_rgb565), [next_rgb565] "r"(src_stride_rgb565), - [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), [width] "r"(width), - [value] "f"(value), [c0] "f"(c0), [c1] "f"(c1), [c2] "f"(c2), - [mask] "f"(mask), [mask_u] "f"(mask_u), [mask_v] "f"(mask_v), - [eight] "f"(0x08), [six] "f"(0x06), [five] "f"(0x05), [three] "f"(0x03), - [one] "f"(0x01) - : "memory"); -} - -void ARGB1555ToUVRow_MMI(const uint8_t* src_argb1555, - int src_stride_argb1555, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t ftmp[11]; - uint64_t value = 0x2020202020202020; - uint64_t mask_u = 0x0026004a00700002; - uint64_t mask_v = 0x00020070005e0012; - uint64_t mask = 0x93; - uint64_t c0 = 0x001f001f001f001f; - uint64_t c1 = 0x00ff00ff00ff00ff; - uint64_t c2 = 0x0003000300030003; - uint64_t c3 = 0x007c007c007c007c; - __asm__ volatile( - "daddu %[next_argb1555], %[src_argb1555], %[next_argb1555] \n\t" - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb1555]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb1555]) \n\t" - "gsldrc1 %[src1], 0x00(%[next_argb1555]) \n\t" - "gsldlc1 %[src1], 0x07(%[next_argb1555]) \n\t" - "psrlh %[dest0_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g0], %[dest0_u], %[c2] \n\t" - "psllh %[g0], %[g0], %[three] \n\t" - "or %[g0], %[src0], %[g0] \n\t" - "and %[r0], %[dest0_u], %[c3] \n\t" - "psrlh %[r0], %[r0], %[two] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest0_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[src1], %[src1], %[five] \n\t" - "and %[dest0_v], %[src0], %[c2] \n\t" - "psllh %[dest0_v], %[dest0_v], %[three] \n\t" - "or %[dest0_v], %[src1], %[dest0_v] \n\t" - "and %[src0], %[src0], %[c3] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "paddh %[b0], %[b0], %[dest0_u] \n\t" - "paddh %[g0], %[g0], %[dest0_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest0_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest0_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest0_u], %[dest0_v] \n\t" - "psrlh %[b0], %[src0], %[six] \n\t" - "psllh %[r0], %[src0], %[one] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "psrlh %[r0], %[g0], %[six] \n\t" - "psllh %[g0], %[g0], %[one] \n\t" - "or %[g0], %[g0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest0_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest0_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest0_u], %[dest0_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest0_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest0_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest0_u], %[dest0_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest0_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest0_u], %[b0] \n\t" - "psubw %[dest0_u], %[src0], %[src1] \n\t" - "psraw %[dest0_u], %[dest0_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest0_v], %[g0] \n\t" - "psubw %[dest0_v], %[src1], %[src0] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_argb1555]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_argb1555]) \n\t" - "gsldrc1 %[src1], 0x08(%[next_argb1555]) \n\t" - "gsldlc1 %[src1], 0x0f(%[next_argb1555]) \n\t" - "psrlh %[dest1_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g0], %[dest1_u], %[c2] \n\t" - "psllh %[g0], %[g0], %[three] \n\t" - "or %[g0], %[src0], %[g0] \n\t" - "and %[r0], %[dest1_u], %[c3] \n\t" - "psrlh %[r0], %[r0], %[two] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest1_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[src1], %[src1], %[five] \n\t" - "and %[dest1_v], %[src0], %[c2] \n\t" - "psllh %[dest1_v], %[dest1_v], %[three] \n\t" - "or %[dest1_v], %[src1], %[dest1_v] \n\t" - "and %[src0], %[src0], %[c3] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "paddh %[b0], %[b0], %[dest1_u] \n\t" - "paddh %[g0], %[g0], %[dest1_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest1_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest1_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest1_u], %[dest1_v] \n\t" - "psrlh %[b0], %[src0], %[six] \n\t" - "psllh %[r0], %[src0], %[one] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "psrlh %[r0], %[g0], %[six] \n\t" - "psllh %[g0], %[g0], %[one] \n\t" - "or %[g0], %[g0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest1_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest1_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest1_u], %[dest1_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest1_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest1_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest1_u], %[dest1_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest1_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest1_u], %[b0] \n\t" - "psubw %[dest1_u], %[src0], %[src1] \n\t" - "psraw %[dest1_u], %[dest1_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest1_v], %[g0] \n\t" - "psubw %[dest1_v], %[src1], %[src0] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "packsswh %[dest0_u], %[dest0_u], %[dest1_u] \n\t" - "packsswh %[dest1_u], %[dest0_v], %[dest1_v] \n\t" - - "gsldrc1 %[src0], 0x10(%[src_argb1555]) \n\t" - "gsldlc1 %[src0], 0x17(%[src_argb1555]) \n\t" - "gsldrc1 %[src1], 0x10(%[next_argb1555]) \n\t" - "gsldlc1 %[src1], 0x17(%[next_argb1555]) \n\t" - "psrlh %[dest2_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g0], %[dest2_u], %[c2] \n\t" - "psllh %[g0], %[g0], %[three] \n\t" - "or %[g0], %[src0], %[g0] \n\t" - "and %[r0], %[dest2_u], %[c3] \n\t" - "psrlh %[r0], %[r0], %[two] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest2_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[src1], %[src1], %[five] \n\t" - "and %[dest0_v], %[src0], %[c2] \n\t" - "psllh %[dest0_v], %[dest0_v], %[three] \n\t" - "or %[dest0_v], %[src1], %[dest0_v] \n\t" - "and %[src0], %[src0], %[c3] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "paddh %[b0], %[b0], %[dest2_u] \n\t" - "paddh %[g0], %[g0], %[dest0_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest2_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest0_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest2_u], %[dest0_v] \n\t" - "psrlh %[b0], %[src0], %[six] \n\t" - "psllh %[r0], %[src0], %[one] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "psrlh %[r0], %[g0], %[six] \n\t" - "psllh %[g0], %[g0], %[one] \n\t" - "or %[g0], %[g0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest2_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest0_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest2_u], %[dest0_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest0_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest2_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest2_u], %[dest2_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest2_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest2_u], %[b0] \n\t" - "psubw %[dest2_u], %[src0], %[src1] \n\t" - "psraw %[dest2_u], %[dest2_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest0_v], %[g0] \n\t" - "psubw %[dest0_v], %[src1], %[src0] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x18(%[src_argb1555]) \n\t" - "gsldlc1 %[src0], 0x1f(%[src_argb1555]) \n\t" - "gsldrc1 %[src1], 0x18(%[next_argb1555]) \n\t" - "gsldlc1 %[src1], 0x1f(%[next_argb1555]) \n\t" - "psrlh %[dest3_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[src0], %[src0], %[five] \n\t" - "and %[g0], %[dest3_u], %[c2] \n\t" - "psllh %[g0], %[g0], %[three] \n\t" - "or %[g0], %[src0], %[g0] \n\t" - "and %[r0], %[dest3_u], %[c3] \n\t" - "psrlh %[r0], %[r0], %[two] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest3_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[src1], %[src1], %[five] \n\t" - "and %[dest1_v], %[src0], %[c2] \n\t" - "psllh %[dest1_v], %[dest1_v], %[three] \n\t" - "or %[dest1_v], %[src1], %[dest1_v] \n\t" - "and %[src0], %[src0], %[c3] \n\t" - "psrlh %[src0], %[src0], %[two] \n\t" - "paddh %[b0], %[b0], %[dest3_u] \n\t" - "paddh %[g0], %[g0], %[dest1_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest3_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest1_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest3_u], %[dest1_v] \n\t" - "psrlh %[b0], %[src0], %[six] \n\t" - "psllh %[r0], %[src0], %[one] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "psrlh %[r0], %[g0], %[six] \n\t" - "psllh %[g0], %[g0], %[one] \n\t" - "or %[g0], %[g0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest3_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest1_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest3_u], %[dest1_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest1_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest3_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest3_u], %[dest3_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest3_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest3_u], %[b0] \n\t" - "psubw %[dest3_u], %[src0], %[src1] \n\t" - "psraw %[dest3_u], %[dest3_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest1_v], %[g0] \n\t" - "psubw %[dest1_v], %[src1], %[src0] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "packsswh %[src1], %[dest2_u], %[dest3_u] \n\t" - "packushb %[dest0_u], %[dest0_u], %[src1] \n\t" - "gssdlc1 %[dest0_u], 0x07(%[dst_u]) \n\t" - "gssdrc1 %[dest0_u], 0x00(%[dst_u]) \n\t" - "packsswh %[src1], %[dest0_v], %[dest1_v] \n\t" - "packushb %[dest0_v], %[dest1_u], %[src1] \n\t" - "gssdlc1 %[dest0_v], 0x07(%[dst_v]) \n\t" - "gssdrc1 %[dest0_v], 0x00(%[dst_v]) \n\t" - - "daddiu %[src_argb1555], %[src_argb1555], 0x20 \n\t" - "daddiu %[next_argb1555], %[next_argb1555], 0x20 \n\t" - "daddiu %[dst_u], %[dst_u], 0x08 \n\t" - "daddiu %[dst_v], %[dst_v], 0x08 \n\t" - "daddiu %[width], %[width], -0x10 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(ftmp[0]), [src1] "=&f"(ftmp[1]), [b0] "=&f"(ftmp[2]), - [g0] "=&f"(ftmp[3]), [r0] "=&f"(ftmp[4]), [dest0_u] "=&f"(ftmp[5]), - [dest1_u] "=&f"(ftmp[6]), [dest2_u] "=&f"(ftmp[7]), - [dest3_u] "=&f"(ftmp[8]), [dest0_v] "=&f"(ftmp[9]), - [dest1_v] "=&f"(ftmp[10]) - : [src_argb1555] "r"(src_argb1555), - [next_argb1555] "r"(src_stride_argb1555), [dst_u] "r"(dst_u), - [dst_v] "r"(dst_v), [width] "r"(width), [value] "f"(value), - [c0] "f"(c0), [c1] "f"(c1), [c2] "f"(c2), [c3] "f"(c3), - [mask] "f"(mask), [mask_u] "f"(mask_u), [mask_v] "f"(mask_v), - [eight] "f"(0x08), [six] "f"(0x06), [five] "f"(0x05), [three] "f"(0x03), - [two] "f"(0x02), [one] "f"(0x01) - : "memory"); -} - -void ARGB4444ToUVRow_MMI(const uint8_t* src_argb4444, - int src_stride_argb4444, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t ftmp[13]; - uint64_t value = 0x2020202020202020; - uint64_t mask_u = 0x0026004a00700002; - uint64_t mask_v = 0x00020070005e0012; - uint64_t mask = 0x93; - uint64_t c0 = 0x000f000f000f000f; - uint64_t c1 = 0x00ff00ff00ff00ff; - __asm__ volatile( - "daddu %[next_argb4444], %[src_argb4444], %[next_argb4444] \n\t" - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb4444]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb4444]) \n\t" - "gsldrc1 %[src1], 0x00(%[next_argb4444]) \n\t" - "gsldlc1 %[src1], 0x07(%[next_argb4444]) \n\t" - "psrlh %[dest0_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[g0], %[src0], %[four] \n\t" - "and %[r0], %[dest0_u], %[c0] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest0_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[dest0_v], %[src1], %[four] \n\t" - "and %[src0], %[src0], %[c0] \n\t" - "paddh %[b0], %[b0], %[dest0_u] \n\t" - "paddh %[g0], %[g0], %[dest0_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest0_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest0_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest0_u], %[dest0_v] \n\t" - "psrlh %[b0], %[src0], %[four] \n\t" - "psllh %[r0], %[src0], %[two] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "psrlh %[r0], %[g0], %[four] \n\t" - "psllh %[g0], %[g0], %[two] \n\t" - "or %[g0], %[g0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest0_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest0_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest0_u], %[dest0_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest0_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest0_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest0_u], %[dest0_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest0_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest0_u], %[b0] \n\t" - "psubw %[dest0_u], %[src0], %[src1] \n\t" - "psraw %[dest0_u], %[dest0_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest0_v], %[g0] \n\t" - "psubw %[dest0_v], %[src1], %[src0] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_argb4444]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_argb4444]) \n\t" - "gsldrc1 %[src1], 0x08(%[next_argb4444]) \n\t" - "gsldlc1 %[src1], 0x0f(%[next_argb4444]) \n\t" - "psrlh %[dest1_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[g0], %[src0], %[four] \n\t" - "and %[r0], %[dest1_u], %[c0] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest1_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[dest1_v], %[src1], %[four] \n\t" - "and %[src0], %[src0], %[c0] \n\t" - "paddh %[b0], %[b0], %[dest1_u] \n\t" - "paddh %[g0], %[g0], %[dest1_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest1_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest1_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest1_u], %[dest1_v] \n\t" - "psrlh %[b0], %[src0], %[four] \n\t" - "psllh %[r0], %[src0], %[two] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "psrlh %[r0], %[g0], %[four] \n\t" - "psllh %[g0], %[g0], %[two] \n\t" - "or %[g0], %[g0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest1_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest1_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest1_u], %[dest1_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest1_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest1_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest1_u], %[dest1_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest1_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest1_u], %[b0] \n\t" - "psubw %[dest1_u], %[src0], %[src1] \n\t" - "psraw %[dest1_u], %[dest1_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest1_v], %[g0] \n\t" - "psubw %[dest1_v], %[src1], %[src0] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x10(%[src_argb4444]) \n\t" - "gsldlc1 %[src0], 0x17(%[src_argb4444]) \n\t" - "gsldrc1 %[src1], 0x10(%[next_argb4444]) \n\t" - "gsldlc1 %[src1], 0x17(%[next_argb4444]) \n\t" - "psrlh %[dest2_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[g0], %[src0], %[four] \n\t" - "and %[r0], %[dest2_u], %[c0] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest2_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[dest2_v], %[src1], %[four] \n\t" - "and %[src0], %[src0], %[c0] \n\t" - "paddh %[b0], %[b0], %[dest2_u] \n\t" - "paddh %[g0], %[g0], %[dest2_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest2_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest2_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest2_u], %[dest2_v] \n\t" - "psrlh %[b0], %[src0], %[four] \n\t" - "psllh %[r0], %[src0], %[two] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "psrlh %[r0], %[g0], %[four] \n\t" - "psllh %[g0], %[g0], %[two] \n\t" - "or %[g0], %[g0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest2_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest2_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest2_u], %[dest2_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest2_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest2_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest2_u], %[dest2_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest2_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest2_u], %[b0] \n\t" - "psubw %[dest2_u], %[src0], %[src1] \n\t" - "psraw %[dest2_u], %[dest2_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest2_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest2_v], %[g0] \n\t" - "psubw %[dest2_v], %[src1], %[src0] \n\t" - "psraw %[dest2_v], %[dest2_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x18(%[src_argb4444]) \n\t" - "gsldlc1 %[src0], 0x1f(%[src_argb4444]) \n\t" - "gsldrc1 %[src1], 0x18(%[next_argb4444]) \n\t" - "gsldlc1 %[src1], 0x1f(%[next_argb4444]) \n\t" - "psrlh %[dest3_u], %[src0], %[eight] \n\t" - "and %[b0], %[src0], %[c0] \n\t" - "and %[src0], %[src0], %[c1] \n\t" - "psrlh %[g0], %[src0], %[four] \n\t" - "and %[r0], %[dest3_u], %[c0] \n\t" - "psrlh %[src0], %[src1], %[eight] \n\t" - "and %[dest3_u], %[src1], %[c0] \n\t" - "and %[src1], %[src1], %[c1] \n\t" - "psrlh %[dest3_v], %[src1], %[four] \n\t" - "and %[src0], %[src0], %[c0] \n\t" - "paddh %[b0], %[b0], %[dest3_u] \n\t" - "paddh %[g0], %[g0], %[dest3_v] \n\t" - "paddh %[r0], %[r0], %[src0] \n\t" - "punpcklhw %[src0], %[b0], %[r0] \n\t" - "punpckhhw %[src1], %[b0], %[r0] \n\t" - "punpcklwd %[dest3_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest3_v], %[src0], %[src1] \n\t" - "paddh %[src0], %[dest3_u], %[dest3_v] \n\t" - "psrlh %[b0], %[src0], %[four] \n\t" - "psllh %[r0], %[src0], %[two] \n\t" - "or %[b0], %[b0], %[r0] \n\t" - "psrlh %[r0], %[g0], %[four] \n\t" - "psllh %[g0], %[g0], %[two] \n\t" - "or %[g0], %[g0], %[r0] \n\t" - "punpcklhw %[src0], %[g0], %[value] \n\t" - "punpckhhw %[src1], %[g0], %[value] \n\t" - "punpcklwd %[dest3_u], %[src0], %[src1] \n\t" - "punpckhwd %[dest3_v], %[src0], %[src1] \n\t" - "paddh %[g0], %[dest3_u], %[dest3_v] \n\t" - "punpcklhw %[src0], %[b0], %[g0] \n\t" - "punpckhhw %[src1], %[b0], %[g0] \n\t" - - "pmaddhw %[dest3_v], %[src0], %[mask_v] \n\t" - "pshufh %[dest3_u], %[src0], %[mask] \n\t" - "pmaddhw %[dest3_u], %[dest3_u], %[mask_u] \n\t" - "pmaddhw %[g0], %[src1], %[mask_v] \n\t" - "pshufh %[b0], %[src1], %[mask] \n\t" - "pmaddhw %[b0], %[b0], %[mask_u] \n\t" - - "punpcklwd %[src0], %[dest3_u], %[b0] \n\t" - "punpckhwd %[src1], %[dest3_u], %[b0] \n\t" - "psubw %[dest3_u], %[src0], %[src1] \n\t" - "psraw %[dest3_u], %[dest3_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest3_v], %[g0] \n\t" - "punpckhwd %[src1], %[dest3_v], %[g0] \n\t" - "psubw %[dest3_v], %[src1], %[src0] \n\t" - "psraw %[dest3_v], %[dest3_v], %[eight] \n\t" - - "packsswh %[src0], %[dest0_u], %[dest1_u] \n\t" - "packsswh %[src1], %[dest2_u], %[dest3_u] \n\t" - "packushb %[dest0_u], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_u], 0x07(%[dst_u]) \n\t" - "gssdrc1 %[dest0_u], 0x00(%[dst_u]) \n\t" - "packsswh %[src0], %[dest0_v], %[dest1_v] \n\t" - "packsswh %[src1], %[dest2_v], %[dest3_v] \n\t" - "packushb %[dest0_v], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_v], 0x07(%[dst_v]) \n\t" - "gssdrc1 %[dest0_v], 0x00(%[dst_v]) \n\t" - - "daddiu %[src_argb4444], %[src_argb4444], 0x20 \n\t" - "daddiu %[next_argb4444], %[next_argb4444], 0x20 \n\t" - "daddiu %[dst_u], %[dst_u], 0x08 \n\t" - "daddiu %[dst_v], %[dst_v], 0x08 \n\t" - "daddiu %[width], %[width], -0x10 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(ftmp[0]), [src1] "=&f"(ftmp[1]), [b0] "=&f"(ftmp[2]), - [g0] "=&f"(ftmp[3]), [r0] "=&f"(ftmp[4]), [dest0_u] "=&f"(ftmp[5]), - [dest1_u] "=&f"(ftmp[6]), [dest2_u] "=&f"(ftmp[7]), - [dest3_u] "=&f"(ftmp[8]), [dest0_v] "=&f"(ftmp[9]), - [dest1_v] "=&f"(ftmp[10]), [dest2_v] "=&f"(ftmp[11]), - [dest3_v] "=&f"(ftmp[12]) - : [src_argb4444] "r"(src_argb4444), - [next_argb4444] "r"(src_stride_argb4444), [dst_u] "r"(dst_u), - [dst_v] "r"(dst_v), [width] "r"(width), [value] "f"(value), - [c0] "f"(c0), [c1] "f"(c1), [mask] "f"(mask), [mask_u] "f"(mask_u), - [mask_v] "f"(mask_v), [eight] "f"(0x08), [four] "f"(0x04), - [two] "f"(0x02) - : "memory"); -} - -void ARGBToUV444Row_MMI(const uint8_t* src_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t ftmp[12]; - const uint64_t value = 0x4040; - const uint64_t mask_u = 0x0026004a00700002; - const uint64_t mask_v = 0x00020070005e0012; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_argb]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_argb]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "dsll %[dest0_u], %[src_lo], %[sixteen] \n\t" - "pinsrh_0 %[dest0_u], %[dest0_u], %[value] \n\t" - "pinsrh_3 %[dest0_v], %[src_lo], %[value] \n\t" - "pmaddhw %[dest0_u], %[dest0_u], %[mask_u] \n\t" - "pmaddhw %[dest0_v], %[dest0_v], %[mask_v] \n\t" - - "dsll %[src_lo], %[src_hi], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest0_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest0_u], %[src_lo] \n\t" - "psubw %[dest0_u], %[src0], %[src1] \n\t" - "psraw %[dest0_u], %[dest0_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest0_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest0_v], %[src_hi] \n\t" - "psubw %[dest0_v], %[src1], %[src0] \n\t" - "psraw %[dest0_v], %[dest0_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x08(%[src_argb]) \n\t" - "gsldlc1 %[src0], 0x0f(%[src_argb]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "dsll %[dest1_u], %[src_lo], %[sixteen] \n\t" - "pinsrh_0 %[dest1_u], %[dest1_u], %[value] \n\t" - "pinsrh_3 %[dest1_v], %[src_lo], %[value] \n\t" - "pmaddhw %[dest1_u], %[dest1_u], %[mask_u] \n\t" - "pmaddhw %[dest1_v], %[dest1_v], %[mask_v] \n\t" - "dsll %[src_lo], %[src_hi], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest1_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest1_u], %[src_lo] \n\t" - "psubw %[dest1_u], %[src0], %[src1] \n\t" - "psraw %[dest1_u], %[dest1_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest1_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest1_v], %[src_hi] \n\t" - "psubw %[dest1_v], %[src1], %[src0] \n\t" - "psraw %[dest1_v], %[dest1_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x10(%[src_argb]) \n\t" - "gsldlc1 %[src0], 0x17(%[src_argb]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "dsll %[dest2_u], %[src_lo], %[sixteen] \n\t" - "pinsrh_0 %[dest2_u], %[dest2_u], %[value] \n\t" - "pinsrh_3 %[dest2_v], %[src_lo], %[value] \n\t" - "pmaddhw %[dest2_u], %[dest2_u], %[mask_u] \n\t" - "pmaddhw %[dest2_v], %[dest2_v], %[mask_v] \n\t" - "dsll %[src_lo], %[src_hi], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest2_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest2_u], %[src_lo] \n\t" - "psubw %[dest2_u], %[src0], %[src1] \n\t" - "psraw %[dest2_u], %[dest2_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest2_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest2_v], %[src_hi] \n\t" - "psubw %[dest2_v], %[src1], %[src0] \n\t" - "psraw %[dest2_v], %[dest2_v], %[eight] \n\t" - - "gsldrc1 %[src0], 0x18(%[src_argb]) \n\t" - "gsldlc1 %[src0], 0x1f(%[src_argb]) \n\t" - "punpcklbh %[src_lo], %[src0], %[zero] \n\t" - "punpckhbh %[src_hi], %[src0], %[zero] \n\t" - "dsll %[dest3_u], %[src_lo], %[sixteen] \n\t" - "pinsrh_0 %[dest3_u], %[dest3_u], %[value] \n\t" - "pinsrh_3 %[dest3_v], %[src_lo], %[value] \n\t" - "pmaddhw %[dest3_u], %[dest3_u], %[mask_u] \n\t" - "pmaddhw %[dest3_v], %[dest3_v], %[mask_v] \n\t" - "dsll %[src_lo], %[src_hi], %[sixteen] \n\t" - "pinsrh_0 %[src_lo], %[src_lo], %[value] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[value] \n\t" - "pmaddhw %[src_lo], %[src_lo], %[mask_u] \n\t" - "pmaddhw %[src_hi], %[src_hi], %[mask_v] \n\t" - - "punpcklwd %[src0], %[dest3_u], %[src_lo] \n\t" - "punpckhwd %[src1], %[dest3_u], %[src_lo] \n\t" - "psubw %[dest3_u], %[src0], %[src1] \n\t" - "psraw %[dest3_u], %[dest3_u], %[eight] \n\t" - "punpcklwd %[src0], %[dest3_v], %[src_hi] \n\t" - "punpckhwd %[src1], %[dest3_v], %[src_hi] \n\t" - "psubw %[dest3_v], %[src1], %[src0] \n\t" - "psraw %[dest3_v], %[dest3_v], %[eight] \n\t" - - "packsswh %[src0], %[dest0_u], %[dest1_u] \n\t" - "packsswh %[src1], %[dest2_u], %[dest3_u] \n\t" - "packushb %[dest0_u], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_u], 0x07(%[dst_u]) \n\t" - "gssdrc1 %[dest0_u], 0x00(%[dst_u]) \n\t" - - "packsswh %[src0], %[dest0_v], %[dest1_v] \n\t" - "packsswh %[src1], %[dest2_v], %[dest3_v] \n\t" - "packushb %[dest0_v], %[src0], %[src1] \n\t" - "gssdlc1 %[dest0_v], 0x07(%[dst_v]) \n\t" - "gssdrc1 %[dest0_v], 0x00(%[dst_v]) \n\t" - - "daddiu %[src_argb], %[src_argb], 0x20 \n\t" - "daddiu %[dst_u], %[dst_u], 0x08 \n\t" - "daddiu %[dst_v], %[dst_v], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bgtz %[width], 1b \n\t" - : [src0] "=&f"(ftmp[0]), [src1] "=&f"(ftmp[1]), [src_lo] "=&f"(ftmp[2]), - [src_hi] "=&f"(ftmp[3]), [dest0_u] "=&f"(ftmp[4]), - [dest0_v] "=&f"(ftmp[5]), [dest1_u] "=&f"(ftmp[6]), - [dest1_v] "=&f"(ftmp[7]), [dest2_u] "=&f"(ftmp[8]), - [dest2_v] "=&f"(ftmp[9]), [dest3_u] "=&f"(ftmp[10]), - [dest3_v] "=&f"(ftmp[11]) - : [src_argb] "r"(src_argb), [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), - [width] "r"(width), [mask_u] "f"(mask_u), [mask_v] "f"(mask_v), - [value] "f"(value), [zero] "f"(0x00), [sixteen] "f"(0x10), - [eight] "f"(0x08) - : "memory"); -} - -void ARGBGrayRow_MMI(const uint8_t* src_argb, uint8_t* dst_argb, int width) { - uint64_t src, src_lo, src_hi, src37, dest, dest_lo, dest_hi; - uint64_t tmp0, tmp1; - const uint64_t mask0 = 0x0; - const uint64_t mask1 = 0x01; - const uint64_t mask2 = 0x00400026004B000FULL; - const uint64_t mask3 = 0xFF000000FF000000ULL; - const uint64_t mask4 = ~mask3; - const uint64_t shift = 0x07; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - - "and %[src37], %[src], %[mask3] \n\t" - - "punpcklbh %[src_lo], %[src], %[mask0] \n\t" - "pinsrh_3 %[src_lo], %[src_lo], %[mask1] \n\t" - "pmaddhw %[dest_lo], %[src_lo], %[mask2] \n\t" - "punpcklwd %[tmp0], %[dest_lo], %[dest_lo] \n\t" - "punpckhwd %[tmp1], %[dest_lo], %[dest_lo] \n\t" - "paddw %[dest_lo], %[tmp0], %[tmp1] \n\t" - "psrlw %[dest_lo], %[dest_lo], %[shift] \n\t" - "packsswh %[dest_lo], %[dest_lo], %[dest_lo] \n\t" - - "punpckhbh %[src_hi], %[src], %[mask0] \n\t" - "pinsrh_3 %[src_hi], %[src_hi], %[mask1] \n\t" - "pmaddhw %[dest_hi], %[src_hi], %[mask2] \n\t" - "punpcklwd %[tmp0], %[dest_hi], %[dest_hi] \n\t" - "punpckhwd %[tmp1], %[dest_hi], %[dest_hi] \n\t" - "paddw %[dest_hi], %[tmp0], %[tmp1] \n\t" - "psrlw %[dest_hi], %[dest_hi], %[shift] \n\t" - "packsswh %[dest_hi], %[dest_hi], %[dest_hi] \n\t" - - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "and %[dest], %[dest], %[mask4] \n\t" - "or %[dest], %[dest], %[src37] \n\t" - - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [dest_hi] "=&f"(dest_hi), [dest_lo] "=&f"(dest_lo), - [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), [tmp0] "=&f"(tmp0), - [tmp1] "=&f"(tmp1), [src] "=&f"(src), [dest] "=&f"(dest), - [src37] "=&f"(src37) - : [src_ptr] "r"(src_argb), [dst_ptr] "r"(dst_argb), [width] "r"(width), - [shift] "f"(shift), [mask0] "f"(mask0), [mask1] "f"(mask1), - [mask2] "f"(mask2), [mask3] "f"(mask3), [mask4] "f"(mask4) - : "memory"); -} - -// Convert a row of image to Sepia tone. -void ARGBSepiaRow_MMI(uint8_t* dst_argb, int width) { - uint64_t dest, dest_lo, dest_hi, dest37, dest0, dest1, dest2; - uint64_t tmp0, tmp1; - const uint64_t mask0 = 0x0; - const uint64_t mask1 = 0x002300440011ULL; - const uint64_t mask2 = 0x002D00580016ULL; - const uint64_t mask3 = 0x003200620018ULL; - const uint64_t mask4 = 0xFF000000FF000000ULL; - const uint64_t shift = 0x07; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gsldrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "and %[dest37], %[dest], %[mask4] \n\t" - - "punpcklbh %[dest_lo], %[dest], %[mask0] \n\t" - "pmaddhw %[dest0], %[dest_lo], %[mask1] \n\t" - "pmaddhw %[dest1], %[dest_lo], %[mask2] \n\t" - "pmaddhw %[dest2], %[dest_lo], %[mask3] \n\t" - "punpcklwd %[tmp0], %[dest0], %[dest1] \n\t" - "punpckhwd %[tmp1], %[dest0], %[dest1] \n\t" - "paddw %[dest0], %[tmp0], %[tmp1] \n\t" - "psrlw %[dest0], %[dest0], %[shift] \n\t" - "punpcklwd %[tmp0], %[dest2], %[mask0] \n\t" - "punpckhwd %[tmp1], %[dest2], %[mask0] \n\t" - "paddw %[dest1], %[tmp0], %[tmp1] \n\t" - "psrlw %[dest1], %[dest1], %[shift] \n\t" - "packsswh %[dest_lo], %[dest0], %[dest1] \n\t" - - "punpckhbh %[dest_hi], %[dest], %[mask0] \n\t" - "pmaddhw %[dest0], %[dest_hi], %[mask1] \n\t" - "pmaddhw %[dest1], %[dest_hi], %[mask2] \n\t" - "pmaddhw %[dest2], %[dest_hi], %[mask3] \n\t" - "punpcklwd %[tmp0], %[dest0], %[dest1] \n\t" - "punpckhwd %[tmp1], %[dest0], %[dest1] \n\t" - "paddw %[dest0], %[tmp0], %[tmp1] \n\t" - "psrlw %[dest0], %[dest0], %[shift] \n\t" - "punpcklwd %[tmp0], %[dest2], %[mask0] \n\t" - "punpckhwd %[tmp1], %[dest2], %[mask0] \n\t" - "paddw %[dest1], %[tmp0], %[tmp1] \n\t" - "psrlw %[dest1], %[dest1], %[shift] \n\t" - "packsswh %[dest_hi], %[dest0], %[dest1] \n\t" - - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "or %[dest], %[dest], %[dest37] \n\t" - - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [dest_hi] "=&f"(dest_hi), [dest_lo] "=&f"(dest_lo), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [dest2] "=&f"(dest2), - [dest37] "=&f"(dest37), [tmp0] "=&f"(tmp0), [tmp1] "=&f"(tmp1), - [dest] "=&f"(dest) - : [dst_ptr] "r"(dst_argb), [width] "r"(width), [mask0] "f"(mask0), - [mask1] "f"(mask1), [mask2] "f"(mask2), [mask3] "f"(mask3), - [mask4] "f"(mask4), [shift] "f"(shift) - : "memory"); -} - -// Apply color matrix to a row of image. Matrix is signed. -// TODO(fbarchard): Consider adding rounding (+32). -void ARGBColorMatrixRow_MMI(const uint8_t* src_argb, - uint8_t* dst_argb, - const int8_t* matrix_argb, - int width) { - uint64_t src, src_hi, src_lo, dest, dest_lo, dest_hi, dest0, dest1, dest2, - dest3; - uint64_t matrix, matrix_hi, matrix_lo; - uint64_t tmp0, tmp1; - const uint64_t shift0 = 0x06; - const uint64_t shift1 = 0x08; - const uint64_t mask0 = 0x0; - const uint64_t mask1 = 0x08; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - - "punpcklbh %[src_lo], %[src], %[mask0] \n\t" - - "gsldlc1 %[matrix], 0x07(%[matrix_ptr]) \n\t" - "gsldrc1 %[matrix], 0x00(%[matrix_ptr]) \n\t" - "punpcklbh %[matrix_lo], %[matrix], %[mask0] \n\t" - "psllh %[matrix_lo], %[matrix_lo], %[shift1] \n\t" - "psrah %[matrix_lo], %[matrix_lo], %[shift1] \n\t" - "punpckhbh %[matrix_hi], %[matrix], %[mask0] \n\t" - "psllh %[matrix_hi], %[matrix_hi], %[shift1] \n\t" - "psrah %[matrix_hi], %[matrix_hi], %[shift1] \n\t" - "pmaddhw %[dest_lo], %[src_lo], %[matrix_lo] \n\t" - "pmaddhw %[dest_hi], %[src_lo], %[matrix_hi] \n\t" - "punpcklwd %[tmp0], %[dest_lo], %[dest_hi] \n\t" - "punpckhwd %[tmp1], %[dest_lo], %[dest_hi] \n\t" - "paddw %[dest0], %[tmp0], %[tmp1] \n\t" - "psraw %[dest0], %[dest0], %[shift0] \n\t" - - "gsldlc1 %[matrix], 0x0f(%[matrix_ptr]) \n\t" - "gsldrc1 %[matrix], 0x08(%[matrix_ptr]) \n\t" - "punpcklbh %[matrix_lo], %[matrix], %[mask0] \n\t" - "psllh %[matrix_lo], %[matrix_lo], %[shift1] \n\t" - "psrah %[matrix_lo], %[matrix_lo], %[shift1] \n\t" - "punpckhbh %[matrix_hi], %[matrix], %[mask0] \n\t" - "psllh %[matrix_hi], %[matrix_hi], %[shift1] \n\t" - "psrah %[matrix_hi], %[matrix_hi], %[shift1] \n\t" - "pmaddhw %[dest_lo], %[src_lo], %[matrix_lo] \n\t" - "pmaddhw %[dest_hi], %[src_lo], %[matrix_hi] \n\t" - "punpcklwd %[tmp0], %[dest_lo], %[dest_hi] \n\t" - "punpckhwd %[tmp1], %[dest_lo], %[dest_hi] \n\t" - "paddw %[dest1], %[tmp0], %[tmp1] \n\t" - "psraw %[dest1], %[dest1], %[shift0] \n\t" - - "punpckhbh %[src_hi], %[src], %[mask0] \n\t" - - "gsldlc1 %[matrix], 0x07(%[matrix_ptr]) \n\t" - "gsldrc1 %[matrix], 0x00(%[matrix_ptr]) \n\t" - "punpcklbh %[matrix_lo], %[matrix], %[mask0] \n\t" - "psllh %[matrix_lo], %[matrix_lo], %[shift1] \n\t" - "psrah %[matrix_lo], %[matrix_lo], %[shift1] \n\t" - "punpckhbh %[matrix_hi], %[matrix], %[mask0] \n\t" - "psllh %[matrix_hi], %[matrix_hi], %[shift1] \n\t" - "psrah %[matrix_hi], %[matrix_hi], %[shift1] \n\t" - "pmaddhw %[dest_lo], %[src_hi], %[matrix_lo] \n\t" - "pmaddhw %[dest_hi], %[src_hi], %[matrix_hi] \n\t" - "punpcklwd %[tmp0], %[dest_lo], %[dest_hi] \n\t" - "punpckhwd %[tmp1], %[dest_lo], %[dest_hi] \n\t" - "paddw %[dest2], %[tmp0], %[tmp1] \n\t" - "psraw %[dest2], %[dest2], %[shift0] \n\t" - - "gsldlc1 %[matrix], 0x0f(%[matrix_ptr]) \n\t" - "gsldrc1 %[matrix], 0x08(%[matrix_ptr]) \n\t" - "punpcklbh %[matrix_lo], %[matrix], %[mask0] \n\t" - "psllh %[matrix_lo], %[matrix_lo], %[shift1] \n\t" - "psrah %[matrix_lo], %[matrix_lo], %[shift1] \n\t" - "punpckhbh %[matrix_hi], %[matrix], %[mask0] \n\t" - "psllh %[matrix_hi], %[matrix_hi], %[shift1] \n\t" - "psrah %[matrix_hi], %[matrix_hi], %[shift1] \n\t" - "pmaddhw %[dest_lo], %[src_hi], %[matrix_lo] \n\t" - "pmaddhw %[dest_hi], %[src_hi], %[matrix_hi] \n\t" - "punpcklwd %[tmp0], %[dest_lo], %[dest_hi] \n\t" - "punpckhwd %[tmp1], %[dest_lo], %[dest_hi] \n\t" - "paddw %[dest3], %[tmp0], %[tmp1] \n\t" - "psraw %[dest3], %[dest3], %[shift0] \n\t" - - "packsswh %[tmp0], %[dest0], %[dest1] \n\t" - "packsswh %[tmp1], %[dest2], %[dest3] \n\t" - "packushb %[dest], %[tmp0], %[tmp1] \n\t" - - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), - [dest_hi] "=&f"(dest_hi), [dest_lo] "=&f"(dest_lo), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [dest2] "=&f"(dest2), - [dest3] "=&f"(dest3), [src] "=&f"(src), [dest] "=&f"(dest), - [tmp0] "=&f"(tmp0), [tmp1] "=&f"(tmp1), [matrix_hi] "=&f"(matrix_hi), - [matrix_lo] "=&f"(matrix_lo), [matrix] "=&f"(matrix) - : [src_ptr] "r"(src_argb), [matrix_ptr] "r"(matrix_argb), - [dst_ptr] "r"(dst_argb), [width] "r"(width), [shift0] "f"(shift0), - [shift1] "f"(shift1), [mask0] "f"(mask0), [mask1] "f"(mask1) - : "memory"); -} - -void ARGBShadeRow_MMI(const uint8_t* src_argb, - uint8_t* dst_argb, - int width, - uint32_t value) { - uint64_t src, src_hi, src_lo, dest, dest_lo, dest_hi; - const uint64_t shift = 0x08; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - "punpcklbh %[src_lo], %[src], %[src] \n\t" - "punpckhbh %[src_hi], %[src], %[src] \n\t" - - "punpcklbh %[value], %[value], %[value] \n\t" - - "pmulhuh %[dest_lo], %[src_lo], %[value] \n\t" - "psrlh %[dest_lo], %[dest_lo], %[shift] \n\t" - "pmulhuh %[dest_hi], %[src_hi], %[value] \n\t" - "psrlh %[dest_hi], %[dest_hi], %[shift] \n\t" - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), - [dest_hi] "=&f"(dest_hi), [dest_lo] "=&f"(dest_lo), [src] "=&f"(src), - [dest] "=&f"(dest) - : [src_ptr] "r"(src_argb), [dst_ptr] "r"(dst_argb), [width] "r"(width), - [value] "f"(value), [shift] "f"(shift) - : "memory"); -} - -void ARGBMultiplyRow_MMI(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - uint64_t src0, src0_hi, src0_lo, src1, src1_hi, src1_lo; - uint64_t dest, dest_lo, dest_hi; - const uint64_t mask = 0x0; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src0], 0x07(%[src0_ptr]) \n\t" - "gsldrc1 %[src0], 0x00(%[src0_ptr]) \n\t" - "punpcklbh %[src0_lo], %[src0], %[src0] \n\t" - "punpckhbh %[src0_hi], %[src0], %[src0] \n\t" - - "gsldlc1 %[src1], 0x07(%[src1_ptr]) \n\t" - "gsldrc1 %[src1], 0x00(%[src1_ptr]) \n\t" - "punpcklbh %[src1_lo], %[src1], %[mask] \n\t" - "punpckhbh %[src1_hi], %[src1], %[mask] \n\t" - - "pmulhuh %[dest_lo], %[src0_lo], %[src1_lo] \n\t" - "pmulhuh %[dest_hi], %[src0_hi], %[src1_hi] \n\t" - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src0_ptr], %[src0_ptr], 0x08 \n\t" - "daddiu %[src1_ptr], %[src1_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src0_hi] "=&f"(src0_hi), [src0_lo] "=&f"(src0_lo), - [src1_hi] "=&f"(src1_hi), [src1_lo] "=&f"(src1_lo), - [dest_hi] "=&f"(dest_hi), [dest_lo] "=&f"(dest_lo), [src0] "=&f"(src0), - [src1] "=&f"(src1), [dest] "=&f"(dest) - : [src0_ptr] "r"(src_argb0), [src1_ptr] "r"(src_argb1), - [dst_ptr] "r"(dst_argb), [width] "r"(width), [mask] "f"(mask) - : "memory"); -} - -void ARGBAddRow_MMI(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - uint64_t src0, src1, dest; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src0], 0x07(%[src0_ptr]) \n\t" - "gsldrc1 %[src0], 0x00(%[src0_ptr]) \n\t" - "gsldlc1 %[src1], 0x07(%[src1_ptr]) \n\t" - "gsldrc1 %[src1], 0x00(%[src1_ptr]) \n\t" - "paddusb %[dest], %[src0], %[src1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src0_ptr], %[src0_ptr], 0x08 \n\t" - "daddiu %[src1_ptr], %[src1_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest] "=&f"(dest) - : [src0_ptr] "r"(src_argb0), [src1_ptr] "r"(src_argb1), - [dst_ptr] "r"(dst_argb), [width] "r"(width) - : "memory"); -} - -void ARGBSubtractRow_MMI(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - uint64_t src0, src1, dest; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src0], 0x07(%[src0_ptr]) \n\t" - "gsldrc1 %[src0], 0x00(%[src0_ptr]) \n\t" - "gsldlc1 %[src1], 0x07(%[src1_ptr]) \n\t" - "gsldrc1 %[src1], 0x00(%[src1_ptr]) \n\t" - "psubusb %[dest], %[src0], %[src1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src0_ptr], %[src0_ptr], 0x08 \n\t" - "daddiu %[src1_ptr], %[src1_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest] "=&f"(dest) - : [src0_ptr] "r"(src_argb0), [src1_ptr] "r"(src_argb1), - [dst_ptr] "r"(dst_argb), [width] "r"(width) - : "memory"); -} - -// Sobel functions which mimics SSSE3. -void SobelXRow_MMI(const uint8_t* src_y0, - const uint8_t* src_y1, - const uint8_t* src_y2, - uint8_t* dst_sobelx, - int width) { - uint64_t y00 = 0, y10 = 0, y20 = 0; - uint64_t y02 = 0, y12 = 0, y22 = 0; - uint64_t zero = 0x0; - uint64_t sobel = 0x0; - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[y00], 0x07(%[src_y0]) \n\t" // a=src_y0[i] - "gsldrc1 %[y00], 0x00(%[src_y0]) \n\t" - "gsldlc1 %[y02], 0x09(%[src_y0]) \n\t" // a_sub=src_y0[i+2] - "gsldrc1 %[y02], 0x02(%[src_y0]) \n\t" - - "gsldlc1 %[y10], 0x07(%[src_y1]) \n\t" // b=src_y1[i] - "gsldrc1 %[y10], 0x00(%[src_y1]) \n\t" - "gsldlc1 %[y12], 0x09(%[src_y1]) \n\t" // b_sub=src_y1[i+2] - "gsldrc1 %[y12], 0x02(%[src_y1]) \n\t" - - "gsldlc1 %[y20], 0x07(%[src_y2]) \n\t" // c=src_y2[i] - "gsldrc1 %[y20], 0x00(%[src_y2]) \n\t" - "gsldlc1 %[y22], 0x09(%[src_y2]) \n\t" // c_sub=src_y2[i+2] - "gsldrc1 %[y22], 0x02(%[src_y2]) \n\t" - - "punpcklbh %[y00], %[y00], %[zero] \n\t" - "punpcklbh %[y10], %[y10], %[zero] \n\t" - "punpcklbh %[y20], %[y20], %[zero] \n\t" - - "punpcklbh %[y02], %[y02], %[zero] \n\t" - "punpcklbh %[y12], %[y12], %[zero] \n\t" - "punpcklbh %[y22], %[y22], %[zero] \n\t" - - "paddh %[y00], %[y00], %[y10] \n\t" // a+b - "paddh %[y20], %[y20], %[y10] \n\t" // c+b - "paddh %[y00], %[y00], %[y20] \n\t" // a+2b+c - - "paddh %[y02], %[y02], %[y12] \n\t" // a_sub+b_sub - "paddh %[y22], %[y22], %[y12] \n\t" // c_sub+b_sub - "paddh %[y02], %[y02], %[y22] \n\t" // a_sub+2b_sub+c_sub - - "pmaxsh %[y10], %[y00], %[y02] \n\t" - "pminsh %[y20], %[y00], %[y02] \n\t" - "psubh %[sobel], %[y10], %[y20] \n\t" // Abs - - "gsldlc1 %[y00], 0x0B(%[src_y0]) \n\t" - "gsldrc1 %[y00], 0x04(%[src_y0]) \n\t" - "gsldlc1 %[y02], 0x0D(%[src_y0]) \n\t" - "gsldrc1 %[y02], 0x06(%[src_y0]) \n\t" - - "gsldlc1 %[y10], 0x0B(%[src_y1]) \n\t" - "gsldrc1 %[y10], 0x04(%[src_y1]) \n\t" - "gsldlc1 %[y12], 0x0D(%[src_y1]) \n\t" - "gsldrc1 %[y12], 0x06(%[src_y1]) \n\t" - - "gsldlc1 %[y20], 0x0B(%[src_y2]) \n\t" - "gsldrc1 %[y20], 0x04(%[src_y2]) \n\t" - "gsldlc1 %[y22], 0x0D(%[src_y2]) \n\t" - "gsldrc1 %[y22], 0x06(%[src_y2]) \n\t" - - "punpcklbh %[y00], %[y00], %[zero] \n\t" - "punpcklbh %[y10], %[y10], %[zero] \n\t" - "punpcklbh %[y20], %[y20], %[zero] \n\t" - - "punpcklbh %[y02], %[y02], %[zero] \n\t" - "punpcklbh %[y12], %[y12], %[zero] \n\t" - "punpcklbh %[y22], %[y22], %[zero] \n\t" - - "paddh %[y00], %[y00], %[y10] \n\t" - "paddh %[y20], %[y20], %[y10] \n\t" - "paddh %[y00], %[y00], %[y20] \n\t" - - "paddh %[y02], %[y02], %[y12] \n\t" - "paddh %[y22], %[y22], %[y12] \n\t" - "paddh %[y02], %[y02], %[y22] \n\t" - - "pmaxsh %[y10], %[y00], %[y02] \n\t" - "pminsh %[y20], %[y00], %[y02] \n\t" - "psubh %[y00], %[y10], %[y20] \n\t" - - "packushb %[sobel], %[sobel], %[y00] \n\t" // clamp255 - "gssdrc1 %[sobel], 0(%[dst_sobelx]) \n\t" - "gssdlc1 %[sobel], 7(%[dst_sobelx]) \n\t" - - "daddiu %[src_y0], %[src_y0], 8 \n\t" - "daddiu %[src_y1], %[src_y1], 8 \n\t" - "daddiu %[src_y2], %[src_y2], 8 \n\t" - "daddiu %[dst_sobelx], %[dst_sobelx], 8 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [sobel] "=&f"(sobel), [y00] "=&f"(y00), [y10] "=&f"(y10), - [y20] "=&f"(y20), [y02] "=&f"(y02), [y12] "=&f"(y12), [y22] "=&f"(y22) - : [src_y0] "r"(src_y0), [src_y1] "r"(src_y1), [src_y2] "r"(src_y2), - [dst_sobelx] "r"(dst_sobelx), [width] "r"(width), [zero] "f"(zero) - : "memory"); -} - -void SobelYRow_MMI(const uint8_t* src_y0, - const uint8_t* src_y1, - uint8_t* dst_sobely, - int width) { - uint64_t y00 = 0, y01 = 0, y02 = 0; - uint64_t y10 = 0, y11 = 0, y12 = 0; - uint64_t zero = 0x0; - uint64_t sobel = 0x0; - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[y00], 0x07(%[src_y0]) \n\t" // a=src_y0[i] - "gsldrc1 %[y00], 0x00(%[src_y0]) \n\t" - "gsldlc1 %[y01], 0x08(%[src_y0]) \n\t" // b=src_y0[i+1] - "gsldrc1 %[y01], 0x01(%[src_y0]) \n\t" - "gsldlc1 %[y02], 0x09(%[src_y0]) \n\t" // c=src_y0[i+2] - "gsldrc1 %[y02], 0x02(%[src_y0]) \n\t" - - "gsldlc1 %[y10], 0x07(%[src_y1]) \n\t" // a_sub=src_y1[i] - "gsldrc1 %[y10], 0x00(%[src_y1]) \n\t" - "gsldlc1 %[y11], 0x08(%[src_y1]) \n\t" // b_sub=src_y1[i+1] - "gsldrc1 %[y11], 0x01(%[src_y1]) \n\t" - "gsldlc1 %[y12], 0x09(%[src_y1]) \n\t" // c_sub=src_y1[i+2] - "gsldrc1 %[y12], 0x02(%[src_y1]) \n\t" - - "punpcklbh %[y00], %[y00], %[zero] \n\t" - "punpcklbh %[y01], %[y01], %[zero] \n\t" - "punpcklbh %[y02], %[y02], %[zero] \n\t" - - "punpcklbh %[y10], %[y10], %[zero] \n\t" - "punpcklbh %[y11], %[y11], %[zero] \n\t" - "punpcklbh %[y12], %[y12], %[zero] \n\t" - - "paddh %[y00], %[y00], %[y01] \n\t" // a+b - "paddh %[y02], %[y02], %[y01] \n\t" // c+b - "paddh %[y00], %[y00], %[y02] \n\t" // a+2b+c - - "paddh %[y10], %[y10], %[y11] \n\t" // a_sub+b_sub - "paddh %[y12], %[y12], %[y11] \n\t" // c_sub+b_sub - "paddh %[y10], %[y10], %[y12] \n\t" // a_sub+2b_sub+c_sub - - "pmaxsh %[y02], %[y00], %[y10] \n\t" - "pminsh %[y12], %[y00], %[y10] \n\t" - "psubh %[sobel], %[y02], %[y12] \n\t" // Abs - - "gsldlc1 %[y00], 0x0B(%[src_y0]) \n\t" - "gsldrc1 %[y00], 0x04(%[src_y0]) \n\t" - "gsldlc1 %[y01], 0x0C(%[src_y0]) \n\t" - "gsldrc1 %[y01], 0x05(%[src_y0]) \n\t" - "gsldlc1 %[y02], 0x0D(%[src_y0]) \n\t" - "gsldrc1 %[y02], 0x06(%[src_y0]) \n\t" - - "gsldlc1 %[y10], 0x0B(%[src_y1]) \n\t" - "gsldrc1 %[y10], 0x04(%[src_y1]) \n\t" - "gsldlc1 %[y11], 0x0C(%[src_y1]) \n\t" - "gsldrc1 %[y11], 0x05(%[src_y1]) \n\t" - "gsldlc1 %[y12], 0x0D(%[src_y1]) \n\t" - "gsldrc1 %[y12], 0x06(%[src_y1]) \n\t" - - "punpcklbh %[y00], %[y00], %[zero] \n\t" - "punpcklbh %[y01], %[y01], %[zero] \n\t" - "punpcklbh %[y02], %[y02], %[zero] \n\t" - - "punpcklbh %[y10], %[y10], %[zero] \n\t" - "punpcklbh %[y11], %[y11], %[zero] \n\t" - "punpcklbh %[y12], %[y12], %[zero] \n\t" - - "paddh %[y00], %[y00], %[y01] \n\t" - "paddh %[y02], %[y02], %[y01] \n\t" - "paddh %[y00], %[y00], %[y02] \n\t" - - "paddh %[y10], %[y10], %[y11] \n\t" - "paddh %[y12], %[y12], %[y11] \n\t" - "paddh %[y10], %[y10], %[y12] \n\t" - - "pmaxsh %[y02], %[y00], %[y10] \n\t" - "pminsh %[y12], %[y00], %[y10] \n\t" - "psubh %[y00], %[y02], %[y12] \n\t" - - "packushb %[sobel], %[sobel], %[y00] \n\t" // clamp255 - "gssdrc1 %[sobel], 0(%[dst_sobely]) \n\t" - "gssdlc1 %[sobel], 7(%[dst_sobely]) \n\t" - - "daddiu %[src_y0], %[src_y0], 8 \n\t" - "daddiu %[src_y1], %[src_y1], 8 \n\t" - "daddiu %[dst_sobely], %[dst_sobely], 8 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [sobel] "=&f"(sobel), [y00] "=&f"(y00), [y01] "=&f"(y01), - [y02] "=&f"(y02), [y10] "=&f"(y10), [y11] "=&f"(y11), [y12] "=&f"(y12) - : [src_y0] "r"(src_y0), [src_y1] "r"(src_y1), - [dst_sobely] "r"(dst_sobely), [width] "r"(width), [zero] "f"(zero) - : "memory"); -} - -void SobelRow_MMI(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_argb, - int width) { - double temp[3]; - uint64_t c1 = 0xff000000ff000000; - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[t0], 0x07(%[src_sobelx]) \n\t" // a=src_sobelx[i] - "gsldrc1 %[t0], 0x00(%[src_sobelx]) \n\t" - "gsldlc1 %[t1], 0x07(%[src_sobely]) \n\t" // b=src_sobely[i] - "gsldrc1 %[t1], 0x00(%[src_sobely]) \n\t" - // s7 s6 s5 s4 s3 s2 s1 s0 = a+b - "paddusb %[t2] , %[t0], %[t1] \n\t" - - // s3 s2 s1 s0->s3 s3 s2 s2 s1 s1 s0 s0 - "punpcklbh %[t0], %[t2], %[t2] \n\t" - - // s1 s1 s0 s0->s1 s2 s1 s1 s0 s0 s0 s0 - "punpcklbh %[t1], %[t0], %[t0] \n\t" - "or %[t1], %[t1], %[c1] \n\t" - // 255 s1 s1 s1 s55 s0 s0 s0 - "gssdrc1 %[t1], 0x00(%[dst_argb]) \n\t" - "gssdlc1 %[t1], 0x07(%[dst_argb]) \n\t" - - // s3 s3 s2 s2->s3 s3 s3 s3 s2 s2 s2 s2 - "punpckhbh %[t1], %[t0], %[t0] \n\t" - "or %[t1], %[t1], %[c1] \n\t" - // 255 s3 s3 s3 255 s2 s2 s2 - "gssdrc1 %[t1], 0x08(%[dst_argb]) \n\t" - "gssdlc1 %[t1], 0x0f(%[dst_argb]) \n\t" - - // s7 s6 s5 s4->s7 s7 s6 s6 s5 s5 s4 s4 - "punpckhbh %[t0], %[t2], %[t2] \n\t" - - // s5 s5 s4 s4->s5 s5 s5 s5 s4 s4 s4 s4 - "punpcklbh %[t1], %[t0], %[t0] \n\t" - "or %[t1], %[t1], %[c1] \n\t" - "gssdrc1 %[t1], 0x10(%[dst_argb]) \n\t" - "gssdlc1 %[t1], 0x17(%[dst_argb]) \n\t" - - // s7 s7 s6 s6->s7 s7 s7 s7 s6 s6 s6 s6 - "punpckhbh %[t1], %[t0], %[t0] \n\t" - "or %[t1], %[t1], %[c1] \n\t" - "gssdrc1 %[t1], 0x18(%[dst_argb]) \n\t" - "gssdlc1 %[t1], 0x1f(%[dst_argb]) \n\t" - - "daddiu %[dst_argb], %[dst_argb], 32 \n\t" - "daddiu %[src_sobelx], %[src_sobelx], 8 \n\t" - "daddiu %[src_sobely], %[src_sobely], 8 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [t0] "=&f"(temp[0]), [t1] "=&f"(temp[1]), [t2] "=&f"(temp[2]) - : [src_sobelx] "r"(src_sobelx), [src_sobely] "r"(src_sobely), - [dst_argb] "r"(dst_argb), [width] "r"(width), [c1] "f"(c1) - : "memory"); -} - -void SobelToPlaneRow_MMI(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_y, - int width) { - uint64_t tr = 0; - uint64_t tb = 0; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[tr], 0x0(%[src_sobelx]) \n\t" - "gsldlc1 %[tr], 0x7(%[src_sobelx]) \n\t" // r=src_sobelx[i] - "gsldrc1 %[tb], 0x0(%[src_sobely]) \n\t" - "gsldlc1 %[tb], 0x7(%[src_sobely]) \n\t" // b=src_sobely[i] - "paddusb %[tr], %[tr], %[tb] \n\t" // g - "gssdrc1 %[tr], 0x0(%[dst_y]) \n\t" - "gssdlc1 %[tr], 0x7(%[dst_y]) \n\t" - - "daddiu %[dst_y], %[dst_y], 8 \n\t" - "daddiu %[src_sobelx], %[src_sobelx], 8 \n\t" - "daddiu %[src_sobely], %[src_sobely], 8 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [tr] "=&f"(tr), [tb] "=&f"(tb) - : [src_sobelx] "r"(src_sobelx), [src_sobely] "r"(src_sobely), - [dst_y] "r"(dst_y), [width] "r"(width) - : "memory"); -} - -void SobelXYRow_MMI(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_argb, - int width) { - uint64_t temp[3]; - uint64_t result = 0; - uint64_t gb = 0; - uint64_t cr = 0; - uint64_t c1 = 0xffffffffffffffff; - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[tr], 0x07(%[src_sobelx]) \n\t" // r=src_sobelx[i] - "gsldrc1 %[tr], 0x00(%[src_sobelx]) \n\t" - "gsldlc1 %[tb], 0x07(%[src_sobely]) \n\t" // b=src_sobely[i] - "gsldrc1 %[tb], 0x00(%[src_sobely]) \n\t" - "paddusb %[tg] , %[tr], %[tb] \n\t" // g - - // g3 b3 g2 b2 g1 b1 g0 b0 - "punpcklbh %[gb], %[tb], %[tg] \n\t" - // c3 r3 r2 r2 c1 r1 c0 r0 - "punpcklbh %[cr], %[tr], %[c1] \n\t" - // c1 r1 g1 b1 c0 r0 g0 b0 - "punpcklhw %[result], %[gb], %[cr] \n\t" - "gssdrc1 %[result], 0x00(%[dst_argb]) \n\t" - "gssdlc1 %[result], 0x07(%[dst_argb]) \n\t" - // c3 r3 g3 b3 c2 r2 g2 b2 - "punpckhhw %[result], %[gb], %[cr] \n\t" - "gssdrc1 %[result], 0x08(%[dst_argb]) \n\t" - "gssdlc1 %[result], 0x0f(%[dst_argb]) \n\t" - - // g7 b7 g6 b6 g5 b5 g4 b4 - "punpckhbh %[gb], %[tb], %[tg] \n\t" - // c7 r7 c6 r6 c5 r5 c4 r4 - "punpckhbh %[cr], %[tr], %[c1] \n\t" - // c5 r5 g5 b5 c4 r4 g4 b4 - "punpcklhw %[result], %[gb], %[cr] \n\t" - "gssdrc1 %[result], 0x10(%[dst_argb]) \n\t" - "gssdlc1 %[result], 0x17(%[dst_argb]) \n\t" - // c7 r7 g7 b7 c6 r6 g6 b6 - "punpckhhw %[result], %[gb], %[cr] \n\t" - "gssdrc1 %[result], 0x18(%[dst_argb]) \n\t" - "gssdlc1 %[result], 0x1f(%[dst_argb]) \n\t" - - "daddiu %[dst_argb], %[dst_argb], 32 \n\t" - "daddiu %[src_sobelx], %[src_sobelx], 8 \n\t" - "daddiu %[src_sobely], %[src_sobely], 8 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [tr] "=&f"(temp[0]), [tb] "=&f"(temp[1]), [tg] "=&f"(temp[2]), - [gb] "=&f"(gb), [cr] "=&f"(cr), [result] "=&f"(result) - : [src_sobelx] "r"(src_sobelx), [src_sobely] "r"(src_sobely), - [dst_argb] "r"(dst_argb), [width] "r"(width), [c1] "f"(c1) - : "memory"); -} - -void J400ToARGBRow_MMI(const uint8_t* src_y, uint8_t* dst_argb, int width) { - // Copy a Y to RGB. - uint64_t src, dest; - const uint64_t mask0 = 0x00ffffff00ffffffULL; - const uint64_t mask1 = ~mask0; - - __asm__ volatile( - "1: \n\t" - "gslwlc1 %[src], 0x03(%[src_ptr]) \n\t" - "gslwrc1 %[src], 0x00(%[src_ptr]) \n\t" - "punpcklbh %[src], %[src], %[src] \n\t" - "punpcklhw %[dest], %[src], %[src] \n\t" - "and %[dest], %[dest], %[mask0] \n\t" - "or %[dest], %[dest], %[mask1] \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - - "punpckhhw %[dest], %[src], %[src] \n\t" - "and %[dest], %[dest], %[mask0] \n\t" - "or %[dest], %[dest], %[mask1] \n\t" - "gssdrc1 %[dest], 0x08(%[dst_ptr]) \n\t" - "gssdlc1 %[dest], 0x0f(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x04 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x10 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [dest] "=&f"(dest) - : [src_ptr] "r"(src_y), [dst_ptr] "r"(dst_argb), [mask0] "f"(mask0), - [mask1] "f"(mask1), [width] "r"(width) - : "memory"); -} - -void I400ToARGBRow_MMI(const uint8_t* src_y, uint8_t* rgb_buf, int width) { - uint64_t src, src_lo, src_hi, dest, dest_lo, dest_hi; - const uint64_t mask0 = 0x0; - const uint64_t mask1 = 0x55; - const uint64_t mask2 = 0xAA; - const uint64_t mask3 = 0xFF; - const uint64_t mask4 = 0x4A354A354A354A35ULL; - const uint64_t mask5 = 0x0488048804880488ULL; - const uint64_t shift0 = 0x08; - const uint64_t shift1 = 0x06; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - "punpcklbh %[src_lo], %[src], %[mask0] \n\t" - "punpckhbh %[src_hi], %[src], %[mask0] \n\t" - - "pshufh %[src], %[src_lo], %[mask0] \n\t" - "psllh %[dest_lo], %[src], %[shift0] \n\t" - "paddush %[dest_lo], %[dest_lo], %[src] \n\t" - "pmulhuh %[dest_lo], %[dest_lo], %[mask4] \n\t" - "psubh %[dest_lo], %[dest_lo], %[mask5] \n\t" - "psrah %[dest_lo], %[dest_lo], %[shift1] \n\t" - "pinsrh_3 %[dest_lo], %[dest_lo], %[mask3] \n\t" - "pshufh %[src], %[src_lo], %[mask1] \n\t" - "psllh %[dest_hi], %[src], %[shift0] \n\t" - "paddush %[dest_hi], %[dest_hi], %[src] \n\t" - "pmulhuh %[dest_hi], %[dest_hi], %[mask4] \n\t" - "psubh %[dest_hi], %[dest_hi], %[mask5] \n\t" - "psrah %[dest_hi], %[dest_hi], %[shift1] \n\t" - "pinsrh_3 %[dest_hi], %[dest_hi], %[mask3] \n\t" - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "pshufh %[src], %[src_lo], %[mask2] \n\t" - "psllh %[dest_lo], %[src], %[shift0] \n\t" - "paddush %[dest_lo], %[dest_lo], %[src] \n\t" - "pmulhuh %[dest_lo], %[dest_lo], %[mask4] \n\t" - "psubh %[dest_lo], %[dest_lo], %[mask5] \n\t" - "psrah %[dest_lo], %[dest_lo], %[shift1] \n\t" - "pinsrh_3 %[dest_lo], %[dest_lo], %[mask3] \n\t" - "pshufh %[src], %[src_lo], %[mask3] \n\t" - "psllh %[dest_hi], %[src], %[shift0] \n\t" - "paddush %[dest_hi], %[dest_hi], %[src] \n\t" - "pmulhuh %[dest_hi], %[dest_hi], %[mask4] \n\t" - "psubh %[dest_hi], %[dest_hi], %[mask5] \n\t" - "psrah %[dest_hi], %[dest_hi], %[shift1] \n\t" - "pinsrh_3 %[dest_hi], %[dest_hi], %[mask3] \n\t" - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "gssdlc1 %[dest], 0x0f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x08(%[dst_ptr]) \n\t" - - "pshufh %[src], %[src_hi], %[mask0] \n\t" - "psllh %[dest_lo], %[src], %[shift0] \n\t" - "paddush %[dest_lo], %[dest_lo], %[src] \n\t" - "pmulhuh %[dest_lo], %[dest_lo], %[mask4] \n\t" - "psubh %[dest_lo], %[dest_lo], %[mask5] \n\t" - "psrah %[dest_lo], %[dest_lo], %[shift1] \n\t" - "pinsrh_3 %[dest_lo], %[dest_lo], %[mask3] \n\t" - "pshufh %[src], %[src_hi], %[mask1] \n\t" - "psllh %[dest_hi], %[src], %[shift0] \n\t" - "paddush %[dest_hi], %[dest_hi], %[src] \n\t" - "pmulhuh %[dest_hi], %[dest_hi], %[mask4] \n\t" - "psubh %[dest_hi], %[dest_hi], %[mask5] \n\t" - "psrah %[dest_hi], %[dest_hi], %[shift1] \n\t" - "pinsrh_3 %[dest_hi], %[dest_hi], %[mask3] \n\t" - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "gssdlc1 %[dest], 0x17(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x10(%[dst_ptr]) \n\t" - - "pshufh %[src], %[src_hi], %[mask2] \n\t" - "psllh %[dest_lo], %[src], %[shift0] \n\t" - "paddush %[dest_lo], %[dest_lo], %[src] \n\t" - "pmulhuh %[dest_lo], %[dest_lo], %[mask4] \n\t" - "psubh %[dest_lo], %[dest_lo], %[mask5] \n\t" - "psrah %[dest_lo], %[dest_lo], %[shift1] \n\t" - "pinsrh_3 %[dest_lo], %[dest_lo], %[mask3] \n\t" - "pshufh %[src], %[src_hi], %[mask3] \n\t" - "psllh %[dest_hi], %[src], %[shift0] \n\t" - "paddush %[dest_hi], %[dest_hi], %[src] \n\t" - "pmulhuh %[dest_hi], %[dest_hi], %[mask4] \n\t" - "psubh %[dest_hi], %[dest_hi], %[mask5] \n\t" - "psrah %[dest_hi], %[dest_hi], %[shift1] \n\t" - "pinsrh_3 %[dest_hi], %[dest_hi], %[mask3] \n\t" - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "gssdlc1 %[dest], 0x1f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x18(%[dst_ptr]) \n\t" - - "daddi %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x20 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [dest] "=&f"(dest), [src_hi] "=&f"(src_hi), - [src_lo] "=&f"(src_lo), [dest_hi] "=&f"(dest_hi), - [dest_lo] "=&f"(dest_lo) - : [src_ptr] "r"(src_y), [dst_ptr] "r"(rgb_buf), [mask0] "f"(mask0), - [mask1] "f"(mask1), [mask2] "f"(mask2), [mask3] "f"(mask3), - [mask4] "f"(mask4), [mask5] "f"(mask5), [shift0] "f"(shift0), - [shift1] "f"(shift1), [width] "r"(width) - : "memory"); -} - -void MirrorRow_MMI(const uint8_t* src, uint8_t* dst, int width) { - uint64_t source, src0, src1, dest; - const uint64_t mask0 = 0x0; - const uint64_t mask1 = 0x1b; - - src += width - 1; - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[source], 0(%[src_ptr]) \n\t" - "gsldrc1 %[source], -7(%[src_ptr]) \n\t" - "punpcklbh %[src0], %[source], %[mask0] \n\t" - "pshufh %[src0], %[src0], %[mask1] \n\t" - "punpckhbh %[src1], %[source], %[mask0] \n\t" - "pshufh %[src1], %[src1], %[mask1] \n\t" - "packushb %[dest], %[src1], %[src0] \n\t" - - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddi %[src_ptr], %[src_ptr], -0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [source] "=&f"(source), [dest] "=&f"(dest), [src0] "=&f"(src0), - [src1] "=&f"(src1) - : [src_ptr] "r"(src), [dst_ptr] "r"(dst), [mask0] "f"(mask0), - [mask1] "f"(mask1), [width] "r"(width) - : "memory"); -} - -void MirrorUVRow_MMI(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t src0, src1, dest0, dest1; - const uint64_t mask0 = 0x00ff00ff00ff00ffULL; - const uint64_t mask1 = 0x1b; - const uint64_t shift = 0x08; - - src_uv += (width - 1) << 1; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src0], 1(%[src_ptr]) \n\t" - "gsldrc1 %[src0], -6(%[src_ptr]) \n\t" - "gsldlc1 %[src1], -7(%[src_ptr]) \n\t" - "gsldrc1 %[src1], -14(%[src_ptr]) \n\t" - - "and %[dest0], %[src0], %[mask0] \n\t" - "pshufh %[dest0], %[dest0], %[mask1] \n\t" - "and %[dest1], %[src1], %[mask0] \n\t" - "pshufh %[dest1], %[dest1], %[mask1] \n\t" - "packushb %[dest0], %[dest0], %[dest1] \n\t" - "gssdlc1 %[dest0], 0x07(%[dstu_ptr]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dstu_ptr]) \n\t" - - "psrlh %[dest0], %[src0], %[shift] \n\t" - "pshufh %[dest0], %[dest0], %[mask1] \n\t" - "psrlh %[dest1], %[src1], %[shift] \n\t" - "pshufh %[dest1], %[dest1], %[mask1] \n\t" - "packushb %[dest0], %[dest0], %[dest1] \n\t" - "gssdlc1 %[dest0], 0x07(%[dstv_ptr]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dstv_ptr]) \n\t" - - "daddi %[src_ptr], %[src_ptr], -0x10 \n\t" - "daddiu %[dstu_ptr], %[dstu_ptr], 0x08 \n\t" - "daddiu %[dstv_ptr], %[dstv_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [src0] "=&f"(src0), - [src1] "=&f"(src1) - : [src_ptr] "r"(src_uv), [dstu_ptr] "r"(dst_u), [dstv_ptr] "r"(dst_v), - [width] "r"(width), [mask0] "f"(mask0), [mask1] "f"(mask1), - [shift] "f"(shift) - : "memory"); -} - -void ARGBMirrorRow_MMI(const uint8_t* src, uint8_t* dst, int width) { - src += (width - 1) * 4; - uint64_t temp = 0x0; - uint64_t shuff = 0x4e; // 01 00 11 10 - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[temp], 3(%[src]) \n\t" - "gsldrc1 %[temp], -4(%[src]) \n\t" - "pshufh %[temp], %[temp], %[shuff] \n\t" - "gssdrc1 %[temp], 0x0(%[dst]) \n\t" - "gssdlc1 %[temp], 0x7(%[dst]) \n\t" - - "daddiu %[src], %[src], -0x08 \n\t" - "daddiu %[dst], %[dst], 0x08 \n\t" - "daddiu %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [temp] "=&f"(temp) - : [src] "r"(src), [dst] "r"(dst), [width] "r"(width), [shuff] "f"(shuff) - : "memory"); -} - -void SplitUVRow_MMI(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t c0 = 0x00ff00ff00ff00ff; - uint64_t temp[4]; - uint64_t shift = 0x08; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[t0], 0x00(%[src_uv]) \n\t" - "gsldlc1 %[t0], 0x07(%[src_uv]) \n\t" - "gsldrc1 %[t1], 0x08(%[src_uv]) \n\t" - "gsldlc1 %[t1], 0x0f(%[src_uv]) \n\t" - - "and %[t2], %[t0], %[c0] \n\t" - "and %[t3], %[t1], %[c0] \n\t" - "packushb %[t2], %[t2], %[t3] \n\t" - "gssdrc1 %[t2], 0x0(%[dst_u]) \n\t" - "gssdlc1 %[t2], 0x7(%[dst_u]) \n\t" - - "psrlh %[t2], %[t0], %[shift] \n\t" - "psrlh %[t3], %[t1], %[shift] \n\t" - "packushb %[t2], %[t2], %[t3] \n\t" - "gssdrc1 %[t2], 0x0(%[dst_v]) \n\t" - "gssdlc1 %[t2], 0x7(%[dst_v]) \n\t" - - "daddiu %[src_uv], %[src_uv], 16 \n\t" - "daddiu %[dst_u], %[dst_u], 8 \n\t" - "daddiu %[dst_v], %[dst_v], 8 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [t0] "=&f"(temp[0]), [t1] "=&f"(temp[1]), [t2] "=&f"(temp[2]), - [t3] "=&f"(temp[3]) - : [src_uv] "r"(src_uv), [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), - [width] "r"(width), [c0] "f"(c0), [shift] "f"(shift) - : "memory"); -} - -void MergeUVRow_MMI(const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_uv, - int width) { - uint64_t temp[3]; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[t0], 0x0(%[src_u]) \n\t" - "gsldlc1 %[t0], 0x7(%[src_u]) \n\t" - "gsldrc1 %[t1], 0x0(%[src_v]) \n\t" - "gsldlc1 %[t1], 0x7(%[src_v]) \n\t" - "punpcklbh %[t2], %[t0], %[t1] \n\t" - "gssdrc1 %[t2], 0x0(%[dst_uv]) \n\t" - "gssdlc1 %[t2], 0x7(%[dst_uv]) \n\t" - "punpckhbh %[t2], %[t0], %[t1] \n\t" - "gssdrc1 %[t2], 0x8(%[dst_uv]) \n\t" - "gssdlc1 %[t2], 0xf(%[dst_uv]) \n\t" - - "daddiu %[src_u], %[src_u], 8 \n\t" - "daddiu %[src_v], %[src_v], 8 \n\t" - "daddiu %[dst_uv], %[dst_uv], 16 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [t0] "=&f"(temp[0]), [t1] "=&f"(temp[1]), [t2] "=&f"(temp[2]) - : [dst_uv] "r"(dst_uv), [src_u] "r"(src_u), [src_v] "r"(src_v), - [width] "r"(width) - : "memory"); -} - -void SplitRGBRow_MMI(const uint8_t* src_rgb, - uint8_t* dst_r, - uint8_t* dst_g, - uint8_t* dst_b, - int width) { - uint64_t src[4]; - uint64_t dest_hi, dest_lo, dest; - - __asm__ volatile( - "1: \n\t" - "gslwlc1 %[src0], 0x03(%[src_ptr]) \n\t" - "gslwrc1 %[src0], 0x00(%[src_ptr]) \n\t" - "gslwlc1 %[src1], 0x06(%[src_ptr]) \n\t" - "gslwrc1 %[src1], 0x03(%[src_ptr]) \n\t" - "punpcklbh %[dest_lo], %[src0], %[src1] \n\t" - "gslwlc1 %[src2], 0x09(%[src_ptr]) \n\t" - "gslwrc1 %[src2], 0x06(%[src_ptr]) \n\t" - "gslwlc1 %[src3], 0x0c(%[src_ptr]) \n\t" - "gslwrc1 %[src3], 0x09(%[src_ptr]) \n\t" - "punpcklbh %[dest_hi], %[src2], %[src3] \n\t" - - "punpcklhw %[dest], %[dest_lo], %[dest_hi] \n\t" - "gsswlc1 %[dest], 0x03(%[dstr_ptr]) \n\t" - "gsswrc1 %[dest], 0x00(%[dstr_ptr]) \n\t" - "punpckhwd %[dest], %[dest], %[dest] \n\t" - "gsswlc1 %[dest], 0x03(%[dstg_ptr]) \n\t" - "gsswrc1 %[dest], 0x00(%[dstg_ptr]) \n\t" - "punpckhhw %[dest], %[dest_lo], %[dest_hi] \n\t" - "gsswlc1 %[dest], 0x03(%[dstb_ptr]) \n\t" - "gsswrc1 %[dest], 0x00(%[dstb_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x0c \n\t" - "daddiu %[dstr_ptr], %[dstr_ptr], 0x04 \n\t" - "daddiu %[dstg_ptr], %[dstg_ptr], 0x04 \n\t" - "daddiu %[dstb_ptr], %[dstb_ptr], 0x04 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src[0]), [src1] "=&f"(src[1]), [src2] "=&f"(src[2]), - [src3] "=&f"(src[3]), [dest_hi] "=&f"(dest_hi), - [dest_lo] "=&f"(dest_lo), [dest] "=&f"(dest) - : [src_ptr] "r"(src_rgb), [dstr_ptr] "r"(dst_r), [dstg_ptr] "r"(dst_g), - [dstb_ptr] "r"(dst_b), [width] "r"(width) - : "memory"); -} - -void MergeRGBRow_MMI(const uint8_t* src_r, - const uint8_t* src_g, - const uint8_t* src_b, - uint8_t* dst_rgb, - int width) { - uint64_t srcr, srcg, srcb, dest; - uint64_t srcrg_hi, srcrg_lo, srcbz_hi, srcbz_lo; - const uint64_t temp = 0x0; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[srcr], 0x07(%[srcr_ptr]) \n\t" - "gsldrc1 %[srcr], 0x00(%[srcr_ptr]) \n\t" - "gsldlc1 %[srcg], 0x07(%[srcg_ptr]) \n\t" - "gsldrc1 %[srcg], 0x00(%[srcg_ptr]) \n\t" - "punpcklbh %[srcrg_lo], %[srcr], %[srcg] \n\t" - "punpckhbh %[srcrg_hi], %[srcr], %[srcg] \n\t" - - "gsldlc1 %[srcb], 0x07(%[srcb_ptr]) \n\t" - "gsldrc1 %[srcb], 0x00(%[srcb_ptr]) \n\t" - "punpcklbh %[srcbz_lo], %[srcb], %[temp] \n\t" - "punpckhbh %[srcbz_hi], %[srcb], %[temp] \n\t" - - "punpcklhw %[dest], %[srcrg_lo], %[srcbz_lo] \n\t" - "gsswlc1 %[dest], 0x03(%[dst_ptr]) \n\t" - "gsswrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - "punpckhwd %[dest], %[dest], %[dest] \n\t" - "gsswlc1 %[dest], 0x06(%[dst_ptr]) \n\t" - "gsswrc1 %[dest], 0x03(%[dst_ptr]) \n\t" - "punpckhhw %[dest], %[srcrg_lo], %[srcbz_lo] \n\t" - "gsswlc1 %[dest], 0x09(%[dst_ptr]) \n\t" - "gsswrc1 %[dest], 0x06(%[dst_ptr]) \n\t" - "punpckhwd %[dest], %[dest], %[dest] \n\t" - "gsswlc1 %[dest], 0x0c(%[dst_ptr]) \n\t" - "gsswrc1 %[dest], 0x09(%[dst_ptr]) \n\t" - "punpcklhw %[dest], %[srcrg_hi], %[srcbz_hi] \n\t" - "gsswlc1 %[dest], 0x0f(%[dst_ptr]) \n\t" - "gsswrc1 %[dest], 0x0c(%[dst_ptr]) \n\t" - "punpckhwd %[dest], %[dest], %[dest] \n\t" - "gsswlc1 %[dest], 0x12(%[dst_ptr]) \n\t" - "gsswrc1 %[dest], 0x0f(%[dst_ptr]) \n\t" - "punpckhhw %[dest], %[srcrg_hi], %[srcbz_hi] \n\t" - "gsswlc1 %[dest], 0x15(%[dst_ptr]) \n\t" - "gsswrc1 %[dest], 0x12(%[dst_ptr]) \n\t" - "punpckhwd %[dest], %[dest], %[dest] \n\t" - "gsswlc1 %[dest], 0x18(%[dst_ptr]) \n\t" - "gsswrc1 %[dest], 0x15(%[dst_ptr]) \n\t" - - "daddiu %[srcr_ptr], %[srcr_ptr], 0x08 \n\t" - "daddiu %[srcg_ptr], %[srcg_ptr], 0x08 \n\t" - "daddiu %[srcb_ptr], %[srcb_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x18 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [srcr] "=&f"(srcr), [srcg] "=&f"(srcg), [srcb] "=&f"(srcb), - [dest] "=&f"(dest), [srcrg_hi] "=&f"(srcrg_hi), - [srcrg_lo] "=&f"(srcrg_lo), [srcbz_hi] "=&f"(srcbz_hi), - [srcbz_lo] "=&f"(srcbz_lo) - : [srcr_ptr] "r"(src_r), [srcg_ptr] "r"(src_g), [srcb_ptr] "r"(src_b), - [dst_ptr] "r"(dst_rgb), [width] "r"(width), [temp] "f"(temp) - : "memory"); -} - -// Filter 2 rows of YUY2 UV's (422) into U and V (420). -void YUY2ToUVRow_MMI(const uint8_t* src_yuy2, - int src_stride_yuy2, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t c0 = 0xff00ff00ff00ff00; - uint64_t c1 = 0x00ff00ff00ff00ff; - uint64_t temp[3]; - uint64_t data[4]; - uint64_t shift = 0x08; - uint64_t src_stride = 0x0; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[t0], 0x00(%[src_yuy2]) \n\t" - "gsldlc1 %[t0], 0x07(%[src_yuy2]) \n\t" - "daddu %[src_stride], %[src_yuy2], %[src_stride_yuy2] \n\t" - "gsldrc1 %[t1], 0x00(%[src_stride]) \n\t" - "gsldlc1 %[t1], 0x07(%[src_stride]) \n\t" - "pavgb %[t0], %[t0], %[t1] \n\t" - - "gsldrc1 %[t2], 0x08(%[src_yuy2]) \n\t" - "gsldlc1 %[t2], 0x0f(%[src_yuy2]) \n\t" - "gsldrc1 %[t1], 0x08(%[src_stride]) \n\t" - "gsldlc1 %[t1], 0x0f(%[src_stride]) \n\t" - "pavgb %[t1], %[t2], %[t1] \n\t" - - "and %[t0], %[t0], %[c0] \n\t" - "and %[t1], %[t1], %[c0] \n\t" - "psrlh %[t0], %[t0], %[shift] \n\t" - "psrlh %[t1], %[t1], %[shift] \n\t" - "packushb %[t0], %[t0], %[t1] \n\t" - "mov.s %[t1], %[t0] \n\t" - "and %[d0], %[t0], %[c1] \n\t" - "psrlh %[d1], %[t1], %[shift] \n\t" - - "gsldrc1 %[t0], 0x10(%[src_yuy2]) \n\t" - "gsldlc1 %[t0], 0x17(%[src_yuy2]) \n\t" - "gsldrc1 %[t1], 0x10(%[src_stride]) \n\t" - "gsldlc1 %[t1], 0x17(%[src_stride]) \n\t" - "pavgb %[t0], %[t0], %[t1] \n\t" - - "gsldrc1 %[t2], 0x18(%[src_yuy2]) \n\t" - "gsldlc1 %[t2], 0x1f(%[src_yuy2]) \n\t" - "gsldrc1 %[t1], 0x18(%[src_stride]) \n\t" - "gsldlc1 %[t1], 0x1f(%[src_stride]) \n\t" - "pavgb %[t1], %[t2], %[t1] \n\t" - - "and %[t0], %[t0], %[c0] \n\t" - "and %[t1], %[t1], %[c0] \n\t" - "psrlh %[t0], %[t0], %[shift] \n\t" - "psrlh %[t1], %[t1], %[shift] \n\t" - "packushb %[t0], %[t0], %[t1] \n\t" - "mov.s %[t1], %[t0] \n\t" - "and %[d2], %[t0], %[c1] \n\t" - "psrlh %[d3], %[t1], %[shift] \n\t" - - "packushb %[d0], %[d0], %[d2] \n\t" - "packushb %[d1], %[d1], %[d3] \n\t" - "gssdrc1 %[d0], 0x0(%[dst_u]) \n\t" - "gssdlc1 %[d0], 0x7(%[dst_u]) \n\t" - "gssdrc1 %[d1], 0x0(%[dst_v]) \n\t" - "gssdlc1 %[d1], 0x7(%[dst_v]) \n\t" - "daddiu %[src_yuy2], %[src_yuy2], 32 \n\t" - "daddiu %[dst_u], %[dst_u], 8 \n\t" - "daddiu %[dst_v], %[dst_v], 8 \n\t" - "daddiu %[width], %[width], -16 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [t0] "=&f"(temp[0]), [t1] "=&f"(temp[1]), [t2] "=&f"(temp[2]), - [d0] "=&f"(data[0]), [d1] "=&f"(data[1]), [d2] "=&f"(data[2]), - [d3] "=&f"(data[3]), [src_stride] "=&r"(src_stride) - : [src_yuy2] "r"(src_yuy2), [src_stride_yuy2] "r"(src_stride_yuy2), - [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), [width] "r"(width), - [c0] "f"(c0), [c1] "f"(c1), [shift] "f"(shift) - : "memory"); -} - -// Copy row of YUY2 UV's (422) into U and V (422). -void YUY2ToUV422Row_MMI(const uint8_t* src_yuy2, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - uint64_t c0 = 0xff00ff00ff00ff00; - uint64_t c1 = 0x00ff00ff00ff00ff; - uint64_t temp[2]; - uint64_t data[4]; - uint64_t shift = 0x08; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[t0], 0x00(%[src_yuy2]) \n\t" - "gsldlc1 %[t0], 0x07(%[src_yuy2]) \n\t" - "gsldrc1 %[t1], 0x08(%[src_yuy2]) \n\t" - "gsldlc1 %[t1], 0x0f(%[src_yuy2]) \n\t" - "and %[t0], %[t0], %[c0] \n\t" - "and %[t1], %[t1], %[c0] \n\t" - "psrlh %[t0], %[t0], %[shift] \n\t" - "psrlh %[t1], %[t1], %[shift] \n\t" - "packushb %[t0], %[t0], %[t1] \n\t" - "mov.s %[t1], %[t0] \n\t" - "and %[d0], %[t0], %[c1] \n\t" - "psrlh %[d1], %[t1], %[shift] \n\t" - - "gsldrc1 %[t0], 0x10(%[src_yuy2]) \n\t" - "gsldlc1 %[t0], 0x17(%[src_yuy2]) \n\t" - "gsldrc1 %[t1], 0x18(%[src_yuy2]) \n\t" - "gsldlc1 %[t1], 0x1f(%[src_yuy2]) \n\t" - "and %[t0], %[t0], %[c0] \n\t" - "and %[t1], %[t1], %[c0] \n\t" - "psrlh %[t0], %[t0], %[shift] \n\t" - "psrlh %[t1], %[t1], %[shift] \n\t" - "packushb %[t0], %[t0], %[t1] \n\t" - "mov.s %[t1], %[t0] \n\t" - "and %[d2], %[t0], %[c1] \n\t" - "psrlh %[d3], %[t1], %[shift] \n\t" - - "packushb %[d0], %[d0], %[d2] \n\t" - "packushb %[d1], %[d1], %[d3] \n\t" - "gssdrc1 %[d0], 0x0(%[dst_u]) \n\t" - "gssdlc1 %[d0], 0x7(%[dst_u]) \n\t" - "gssdrc1 %[d1], 0x0(%[dst_v]) \n\t" - "gssdlc1 %[d1], 0x7(%[dst_v]) \n\t" - "daddiu %[src_yuy2], %[src_yuy2], 32 \n\t" - "daddiu %[dst_u], %[dst_u], 8 \n\t" - "daddiu %[dst_v], %[dst_v], 8 \n\t" - "daddiu %[width], %[width], -16 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [t0] "=&f"(temp[0]), [t1] "=&f"(temp[1]), [d0] "=&f"(data[0]), - [d1] "=&f"(data[1]), [d2] "=&f"(data[2]), [d3] "=&f"(data[3]) - : [src_yuy2] "r"(src_yuy2), [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), - [width] "r"(width), [c0] "f"(c0), [c1] "f"(c1), [shift] "f"(shift) - : "memory"); -} - -// Copy row of YUY2 Y's (422) into Y (420/422). -void YUY2ToYRow_MMI(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { - uint64_t c0 = 0x00ff00ff00ff00ff; - uint64_t temp[2]; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[t0], 0x00(%[src_yuy2]) \n\t" - "gsldlc1 %[t0], 0x07(%[src_yuy2]) \n\t" - "gsldrc1 %[t1], 0x08(%[src_yuy2]) \n\t" - "gsldlc1 %[t1], 0x0f(%[src_yuy2]) \n\t" - "and %[t0], %[t0], %[c0] \n\t" - "and %[t1], %[t1], %[c0] \n\t" - "packushb %[t0], %[t0], %[t1] \n\t" - "gssdrc1 %[t0], 0x0(%[dst_y]) \n\t" - "gssdlc1 %[t0], 0x7(%[dst_y]) \n\t" - "daddiu %[src_yuy2], %[src_yuy2], 16 \n\t" - "daddiu %[dst_y], %[dst_y], 8 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [t0] "=&f"(temp[0]), [t1] "=&f"(temp[1]) - : [src_yuy2] "r"(src_yuy2), [dst_y] "r"(dst_y), [width] "r"(width), - [c0] "f"(c0) - : "memory"); -} - -// Filter 2 rows of UYVY UV's (422) into U and V (420). -void UYVYToUVRow_MMI(const uint8_t* src_uyvy, - int src_stride_uyvy, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - // Output a row of UV values. - uint64_t c0 = 0x00ff00ff00ff00ff; - uint64_t temp[3]; - uint64_t data[4]; - uint64_t shift = 0x08; - uint64_t src_stride = 0x0; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[t0], 0x00(%[src_uyvy]) \n\t" - "gsldlc1 %[t0], 0x07(%[src_uyvy]) \n\t" - "daddu %[src_stride], %[src_uyvy], %[src_stride_uyvy] \n\t" - "gsldrc1 %[t1], 0x00(%[src_stride]) \n\t" - "gsldlc1 %[t1], 0x07(%[src_stride]) \n\t" - "pavgb %[t0], %[t0], %[t1] \n\t" - - "gsldrc1 %[t2], 0x08(%[src_uyvy]) \n\t" - "gsldlc1 %[t2], 0x0f(%[src_uyvy]) \n\t" - "gsldrc1 %[t1], 0x08(%[src_stride]) \n\t" - "gsldlc1 %[t1], 0x0f(%[src_stride]) \n\t" - "pavgb %[t1], %[t2], %[t1] \n\t" - - "and %[t0], %[t0], %[c0] \n\t" - "and %[t1], %[t1], %[c0] \n\t" - "packushb %[t0], %[t0], %[t1] \n\t" - "mov.s %[t1], %[t0] \n\t" - "and %[d0], %[t0], %[c0] \n\t" - "psrlh %[d1], %[t1], %[shift] \n\t" - - "gsldrc1 %[t0], 0x10(%[src_uyvy]) \n\t" - "gsldlc1 %[t0], 0x17(%[src_uyvy]) \n\t" - "gsldrc1 %[t1], 0x10(%[src_stride]) \n\t" - "gsldlc1 %[t1], 0x17(%[src_stride]) \n\t" - "pavgb %[t0], %[t0], %[t1] \n\t" - - "gsldrc1 %[t2], 0x18(%[src_uyvy]) \n\t" - "gsldlc1 %[t2], 0x1f(%[src_uyvy]) \n\t" - "gsldrc1 %[t1], 0x18(%[src_stride]) \n\t" - "gsldlc1 %[t1], 0x1f(%[src_stride]) \n\t" - "pavgb %[t1], %[t2], %[t1] \n\t" - - "and %[t0], %[t0], %[c0] \n\t" - "and %[t1], %[t1], %[c0] \n\t" - "packushb %[t0], %[t0], %[t1] \n\t" - "mov.s %[t1], %[t0] \n\t" - "and %[d2], %[t0], %[c0] \n\t" - "psrlh %[d3], %[t1], %[shift] \n\t" - - "packushb %[d0], %[d0], %[d2] \n\t" - "packushb %[d1], %[d1], %[d3] \n\t" - "gssdrc1 %[d0], 0x0(%[dst_u]) \n\t" - "gssdlc1 %[d0], 0x7(%[dst_u]) \n\t" - "gssdrc1 %[d1], 0x0(%[dst_v]) \n\t" - "gssdlc1 %[d1], 0x7(%[dst_v]) \n\t" - "daddiu %[src_uyvy], %[src_uyvy], 32 \n\t" - "daddiu %[dst_u], %[dst_u], 8 \n\t" - "daddiu %[dst_v], %[dst_v], 8 \n\t" - "daddiu %[width], %[width], -16 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [t0] "=&f"(temp[0]), [t1] "=&f"(temp[1]), [t2] "=&f"(temp[2]), - [d0] "=&f"(data[0]), [d1] "=&f"(data[1]), [d2] "=&f"(data[2]), - [d3] "=&f"(data[3]), [src_stride] "=&r"(src_stride) - : [src_uyvy] "r"(src_uyvy), [src_stride_uyvy] "r"(src_stride_uyvy), - [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), [width] "r"(width), - [c0] "f"(c0), [shift] "f"(shift) - : "memory"); -} - -// Copy row of UYVY UV's (422) into U and V (422). -void UYVYToUV422Row_MMI(const uint8_t* src_uyvy, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - // Output a row of UV values. - uint64_t c0 = 0x00ff00ff00ff00ff; - uint64_t temp[2]; - uint64_t data[4]; - uint64_t shift = 0x08; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[t0], 0x00(%[src_uyvy]) \n\t" - "gsldlc1 %[t0], 0x07(%[src_uyvy]) \n\t" - "gsldrc1 %[t1], 0x08(%[src_uyvy]) \n\t" - "gsldlc1 %[t1], 0x0f(%[src_uyvy]) \n\t" - "and %[t0], %[t0], %[c0] \n\t" - "and %[t1], %[t1], %[c0] \n\t" - "packushb %[t0], %[t0], %[t1] \n\t" - "mov.s %[t1], %[t0] \n\t" - "and %[d0], %[t0], %[c0] \n\t" - "psrlh %[d1], %[t1], %[shift] \n\t" - - "gsldrc1 %[t0], 0x10(%[src_uyvy]) \n\t" - "gsldlc1 %[t0], 0x17(%[src_uyvy]) \n\t" - "gsldrc1 %[t1], 0x18(%[src_uyvy]) \n\t" - "gsldlc1 %[t1], 0x1f(%[src_uyvy]) \n\t" - "and %[t0], %[t0], %[c0] \n\t" - "and %[t1], %[t1], %[c0] \n\t" - "packushb %[t0], %[t0], %[t1] \n\t" - "mov.s %[t1], %[t0] \n\t" - "and %[d2], %[t0], %[c0] \n\t" - "psrlh %[d3], %[t1], %[shift] \n\t" - - "packushb %[d0], %[d0], %[d2] \n\t" - "packushb %[d1], %[d1], %[d3] \n\t" - "gssdrc1 %[d0], 0x0(%[dst_u]) \n\t" - "gssdlc1 %[d0], 0x7(%[dst_u]) \n\t" - "gssdrc1 %[d1], 0x0(%[dst_v]) \n\t" - "gssdlc1 %[d1], 0x7(%[dst_v]) \n\t" - "daddiu %[src_uyvy], %[src_uyvy], 32 \n\t" - "daddiu %[dst_u], %[dst_u], 8 \n\t" - "daddiu %[dst_v], %[dst_v], 8 \n\t" - "daddiu %[width], %[width], -16 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [t0] "=&f"(temp[0]), [t1] "=&f"(temp[1]), [d0] "=&f"(data[0]), - [d1] "=&f"(data[1]), [d2] "=&f"(data[2]), [d3] "=&f"(data[3]) - : [src_uyvy] "r"(src_uyvy), [dst_u] "r"(dst_u), [dst_v] "r"(dst_v), - [width] "r"(width), [c0] "f"(c0), [shift] "f"(shift) - : "memory"); -} - -// Copy row of UYVY Y's (422) into Y (420/422). -void UYVYToYRow_MMI(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { - // Output a row of Y values. - uint64_t c0 = 0x00ff00ff00ff00ff; - uint64_t shift = 0x08; - uint64_t temp[2]; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[t0], 0x00(%[src_uyvy]) \n\t" - "gsldlc1 %[t0], 0x07(%[src_uyvy]) \n\t" - "gsldrc1 %[t1], 0x08(%[src_uyvy]) \n\t" - "gsldlc1 %[t1], 0x0f(%[src_uyvy]) \n\t" - "dsrl %[t0], %[t0], %[shift] \n\t" - "dsrl %[t1], %[t1], %[shift] \n\t" - "and %[t0], %[t0], %[c0] \n\t" - "and %[t1], %[t1], %[c0] \n\t" - "and %[t1], %[t1], %[c0] \n\t" - "packushb %[t0], %[t0], %[t1] \n\t" - "gssdrc1 %[t0], 0x0(%[dst_y]) \n\t" - "gssdlc1 %[t0], 0x7(%[dst_y]) \n\t" - "daddiu %[src_uyvy], %[src_uyvy], 16 \n\t" - "daddiu %[dst_y], %[dst_y], 8 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [t0] "=&f"(temp[0]), [t1] "=&f"(temp[1]) - : [src_uyvy] "r"(src_uyvy), [dst_y] "r"(dst_y), [width] "r"(width), - [c0] "f"(c0), [shift] "f"(shift) - : "memory"); -} - -// Blend src_argb0 over src_argb1 and store to dst_argb. -// dst_argb may be src_argb0 or src_argb1. -// This code mimics the SSSE3 version for better testability. -void ARGBBlendRow_MMI(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - uint64_t src0, src1, dest, alpha, src0_hi, src0_lo, src1_hi, src1_lo, dest_hi, - dest_lo; - const uint64_t mask0 = 0x0; - const uint64_t mask1 = 0x00FFFFFF00FFFFFFULL; - const uint64_t mask2 = 0x00FF00FF00FF00FFULL; - const uint64_t mask3 = 0xFF; - const uint64_t mask4 = ~mask1; - const uint64_t shift = 0x08; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src0], 0x07(%[src0_ptr]) \n\t" - "gsldrc1 %[src0], 0x00(%[src0_ptr]) \n\t" - "punpcklbh %[src0_lo], %[src0], %[mask0] \n\t" - - "gsldlc1 %[src1], 0x07(%[src1_ptr]) \n\t" - "gsldrc1 %[src1], 0x00(%[src1_ptr]) \n\t" - "punpcklbh %[src1_lo], %[src1], %[mask0] \n\t" - - "psubush %[alpha], %[mask2], %[src0_lo] \n\t" - "pshufh %[alpha], %[alpha], %[mask3] \n\t" - "pmullh %[dest_lo], %[src1_lo], %[alpha] \n\t" - "psrlh %[dest_lo], %[dest_lo], %[shift] \n\t" - "paddush %[dest_lo], %[dest_lo], %[src0_lo] \n\t" - - "punpckhbh %[src0_hi], %[src0], %[mask0] \n\t" - "punpckhbh %[src1_hi], %[src1], %[mask0] \n\t" - - "psubush %[alpha], %[mask2], %[src0_hi] \n\t" - "pshufh %[alpha], %[alpha], %[mask3] \n\t" - "pmullh %[dest_hi], %[src1_hi], %[alpha] \n\t" - "psrlh %[dest_hi], %[dest_hi], %[shift] \n\t" - "paddush %[dest_hi], %[dest_hi], %[src0_hi] \n\t" - - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "and %[dest], %[dest], %[mask1] \n\t" - "or %[dest], %[dest], %[mask4] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src0_ptr], %[src0_ptr], 0x08 \n\t" - "daddiu %[src1_ptr], %[src1_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [alpha] "=&f"(alpha), - [dest] "=&f"(dest), [src0_hi] "=&f"(src0_hi), [src0_lo] "=&f"(src0_lo), - [src1_hi] "=&f"(src1_hi), [src1_lo] "=&f"(src1_lo), - [dest_hi] "=&f"(dest_hi), [dest_lo] "=&f"(dest_lo) - : [src0_ptr] "r"(src_argb0), [src1_ptr] "r"(src_argb1), - [dst_ptr] "r"(dst_argb), [mask0] "f"(mask0), [mask1] "f"(mask1), - [mask2] "f"(mask2), [mask3] "f"(mask3), [mask4] "f"(mask4), - [shift] "f"(shift), [width] "r"(width) - : "memory"); -} - -void BlendPlaneRow_MMI(const uint8_t* src0, - const uint8_t* src1, - const uint8_t* alpha, - uint8_t* dst, - int width) { - uint64_t source0, source1, dest, alph; - uint64_t src0_hi, src0_lo, src1_hi, src1_lo, alpha_hi, alpha_lo, dest_hi, - dest_lo; - uint64_t alpha_rev, alpha_rev_lo, alpha_rev_hi; - const uint64_t mask0 = 0x0; - const uint64_t mask1 = 0xFFFFFFFFFFFFFFFFULL; - const uint64_t mask2 = 0x00FF00FF00FF00FFULL; - const uint64_t shift = 0x08; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src0], 0x07(%[src0_ptr]) \n\t" - "gsldrc1 %[src0], 0x00(%[src0_ptr]) \n\t" - "punpcklbh %[src0_lo], %[src0], %[mask0] \n\t" - "punpckhbh %[src0_hi], %[src0], %[mask0] \n\t" - - "gsldlc1 %[src1], 0x07(%[src1_ptr]) \n\t" - "gsldrc1 %[src1], 0x00(%[src1_ptr]) \n\t" - "punpcklbh %[src1_lo], %[src1], %[mask0] \n\t" - "punpckhbh %[src1_hi], %[src1], %[mask0] \n\t" - - "gsldlc1 %[alpha], 0x07(%[alpha_ptr]) \n\t" - "gsldrc1 %[alpha], 0x00(%[alpha_ptr]) \n\t" - "psubusb %[alpha_r], %[mask1], %[alpha] \n\t" - "punpcklbh %[alpha_lo], %[alpha], %[mask0] \n\t" - "punpckhbh %[alpha_hi], %[alpha], %[mask0] \n\t" - "punpcklbh %[alpha_rlo], %[alpha_r], %[mask0] \n\t" - "punpckhbh %[alpha_rhi], %[alpha_r], %[mask0] \n\t" - - "pmullh %[dest_lo], %[src0_lo], %[alpha_lo] \n\t" - "pmullh %[dest], %[src1_lo], %[alpha_rlo] \n\t" - "paddush %[dest_lo], %[dest_lo], %[dest] \n\t" - "paddush %[dest_lo], %[dest_lo], %[mask2] \n\t" - "psrlh %[dest_lo], %[dest_lo], %[shift] \n\t" - - "pmullh %[dest_hi], %[src0_hi], %[alpha_hi] \n\t" - "pmullh %[dest], %[src1_hi], %[alpha_rhi] \n\t" - "paddush %[dest_hi], %[dest_hi], %[dest] \n\t" - "paddush %[dest_hi], %[dest_hi], %[mask2] \n\t" - "psrlh %[dest_hi], %[dest_hi], %[shift] \n\t" - - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src0_ptr], %[src0_ptr], 0x08 \n\t" - "daddiu %[src1_ptr], %[src1_ptr], 0x08 \n\t" - "daddiu %[alpha_ptr], %[alpha_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(source0), [src1] "=&f"(source1), [alpha] "=&f"(alph), - [dest] "=&f"(dest), [src0_hi] "=&f"(src0_hi), [src0_lo] "=&f"(src0_lo), - [src1_hi] "=&f"(src1_hi), [src1_lo] "=&f"(src1_lo), - [alpha_hi] "=&f"(alpha_hi), [alpha_lo] "=&f"(alpha_lo), - [dest_hi] "=&f"(dest_hi), [dest_lo] "=&f"(dest_lo), - [alpha_rlo] "=&f"(alpha_rev_lo), [alpha_rhi] "=&f"(alpha_rev_hi), - [alpha_r] "=&f"(alpha_rev) - : [src0_ptr] "r"(src0), [src1_ptr] "r"(src1), [alpha_ptr] "r"(alpha), - [dst_ptr] "r"(dst), [mask0] "f"(mask0), [mask1] "f"(mask1), - [mask2] "f"(mask2), [shift] "f"(shift), [width] "r"(width) - : "memory"); -} - -// Multiply source RGB by alpha and store to destination. -// This code mimics the SSSE3 version for better testability. -void ARGBAttenuateRow_MMI(const uint8_t* src_argb, - uint8_t* dst_argb, - int width) { - uint64_t src, src_hi, src_lo, dest, dest_hi, dest_lo, alpha; - const uint64_t mask0 = 0xFF; - const uint64_t mask1 = 0xFF000000FF000000ULL; - const uint64_t mask2 = ~mask1; - const uint64_t shift = 0x08; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - "punpcklbh %[src_lo], %[src], %[src] \n\t" - "punpckhbh %[src_hi], %[src], %[src] \n\t" - - "pshufh %[alpha], %[src_lo], %[mask0] \n\t" - "pmulhuh %[dest_lo], %[alpha], %[src_lo] \n\t" - "psrlh %[dest_lo], %[dest_lo], %[shift] \n\t" - "pshufh %[alpha], %[src_hi], %[mask0] \n\t" - "pmulhuh %[dest_hi], %[alpha], %[src_hi] \n\t" - "psrlh %[dest_hi], %[dest_hi], %[shift] \n\t" - - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "and %[dest], %[dest], %[mask2] \n\t" - "and %[src], %[src], %[mask1] \n\t" - "or %[dest], %[dest], %[src] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [dest] "=&f"(dest), [src_hi] "=&f"(src_hi), - [src_lo] "=&f"(src_lo), [dest_hi] "=&f"(dest_hi), - [dest_lo] "=&f"(dest_lo), [alpha] "=&f"(alpha) - : [src_ptr] "r"(src_argb), [dst_ptr] "r"(dst_argb), [mask0] "f"(mask0), - [mask1] "f"(mask1), [mask2] "f"(mask2), [shift] "f"(shift), - [width] "r"(width) - : "memory"); -} - -void ComputeCumulativeSumRow_MMI(const uint8_t* row, - int32_t* cumsum, - const int32_t* previous_cumsum, - int width) { - int64_t row_sum[2] = {0, 0}; - uint64_t src, dest0, dest1, presrc0, presrc1, dest; - const uint64_t mask = 0x0; - - __asm__ volatile( - "xor %[row_sum0], %[row_sum0], %[row_sum0] \n\t" - "xor %[row_sum1], %[row_sum1], %[row_sum1] \n\t" - - "1: \n\t" - "gslwlc1 %[src], 0x03(%[row_ptr]) \n\t" - "gslwrc1 %[src], 0x00(%[row_ptr]) \n\t" - - "punpcklbh %[src], %[src], %[mask] \n\t" - "punpcklhw %[dest0], %[src], %[mask] \n\t" - "punpckhhw %[dest1], %[src], %[mask] \n\t" - - "paddw %[row_sum0], %[row_sum0], %[dest0] \n\t" - "paddw %[row_sum1], %[row_sum1], %[dest1] \n\t" - - "gsldlc1 %[presrc0], 0x07(%[pre_ptr]) \n\t" - "gsldrc1 %[presrc0], 0x00(%[pre_ptr]) \n\t" - "gsldlc1 %[presrc1], 0x0f(%[pre_ptr]) \n\t" - "gsldrc1 %[presrc1], 0x08(%[pre_ptr]) \n\t" - - "paddw %[dest0], %[row_sum0], %[presrc0] \n\t" - "paddw %[dest1], %[row_sum1], %[presrc1] \n\t" - - "gssdlc1 %[dest0], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_ptr]) \n\t" - "gssdlc1 %[dest1], 0x0f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest1], 0x08(%[dst_ptr]) \n\t" - - "daddiu %[row_ptr], %[row_ptr], 0x04 \n\t" - "daddiu %[pre_ptr], %[pre_ptr], 0x10 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x10 \n\t" - "daddi %[width], %[width], -0x01 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [dest] "=&f"(dest), [dest0] "=&f"(dest0), - [dest1] "=&f"(dest1), [row_sum0] "+&f"(row_sum[0]), - [row_sum1] "+&f"(row_sum[1]), [presrc0] "=&f"(presrc0), - [presrc1] "=&f"(presrc1) - : [row_ptr] "r"(row), [pre_ptr] "r"(previous_cumsum), - [dst_ptr] "r"(cumsum), [width] "r"(width), [mask] "f"(mask) - : "memory"); -} - -// C version 2x2 -> 2x1. -void InterpolateRow_MMI(uint8_t* dst_ptr, - const uint8_t* src_ptr, - ptrdiff_t src_stride, - int width, - int source_y_fraction) { - if (source_y_fraction == 0) { - __asm__ volatile( - "1: \n\t" - "ld $t0, 0x0(%[src_ptr]) \n\t" - "sd $t0, 0x0(%[dst_ptr]) \n\t" - "daddiu %[src_ptr], %[src_ptr], 8 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 8 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : - : [dst_ptr] "r"(dst_ptr), [src_ptr] "r"(src_ptr), [width] "r"(width) - : "memory"); - return; - } - if (source_y_fraction == 128) { - uint64_t uv = 0x0; - uint64_t uv_stride = 0x0; - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[uv], 0x0(%[src_ptr]) \n\t" - "gsldlc1 %[uv], 0x7(%[src_ptr]) \n\t" - "daddu $t0, %[src_ptr], %[stride] \n\t" - "gsldrc1 %[uv_stride], 0x0($t0) \n\t" - "gsldlc1 %[uv_stride], 0x7($t0) \n\t" - - "pavgb %[uv], %[uv], %[uv_stride] \n\t" - "gssdrc1 %[uv], 0x0(%[dst_ptr]) \n\t" - "gssdlc1 %[uv], 0x7(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 8 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 8 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [uv] "=&f"(uv), [uv_stride] "=&f"(uv_stride) - : [src_ptr] "r"(src_ptr), [dst_ptr] "r"(dst_ptr), [width] "r"(width), - [stride] "r"((int64_t)src_stride) - : "memory"); - return; - } - const uint8_t* src_ptr1 = src_ptr + src_stride; - uint64_t temp; - uint64_t data[4]; - uint64_t zero = 0x0; - uint64_t c0 = 0x0080008000800080; - uint64_t fy0 = 0x0100010001000100; - uint64_t shift = 0x8; - __asm__ volatile( - "pshufh %[fy1], %[fy1], %[zero] \n\t" - "psubh %[fy0], %[fy0], %[fy1] \n\t" - "1: \n\t" - "gsldrc1 %[t0], 0x0(%[src_ptr]) \n\t" - "gsldlc1 %[t0], 0x7(%[src_ptr]) \n\t" - "punpcklbh %[d0], %[t0], %[zero] \n\t" - "punpckhbh %[d1], %[t0], %[zero] \n\t" - "gsldrc1 %[t0], 0x0(%[src_ptr1]) \n\t" - "gsldlc1 %[t0], 0x7(%[src_ptr1]) \n\t" - "punpcklbh %[d2], %[t0], %[zero] \n\t" - "punpckhbh %[d3], %[t0], %[zero] \n\t" - - "pmullh %[d0], %[d0], %[fy0] \n\t" - "pmullh %[d2], %[d2], %[fy1] \n\t" - "paddh %[d0], %[d0], %[d2] \n\t" - "paddh %[d0], %[d0], %[c0] \n\t" - "psrlh %[d0], %[d0], %[shift] \n\t" - - "pmullh %[d1], %[d1], %[fy0] \n\t" - "pmullh %[d3], %[d3], %[fy1] \n\t" - "paddh %[d1], %[d1], %[d3] \n\t" - "paddh %[d1], %[d1], %[c0] \n\t" - "psrlh %[d1], %[d1], %[shift] \n\t" - - "packushb %[d0], %[d0], %[d1] \n\t" - "gssdrc1 %[d0], 0x0(%[dst_ptr]) \n\t" - "gssdlc1 %[d0], 0x7(%[dst_ptr]) \n\t" - "daddiu %[src_ptr], %[src_ptr], 8 \n\t" - "daddiu %[src_ptr1], %[src_ptr1], 8 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 8 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [t0] "=&f"(temp), [d0] "=&f"(data[0]), [d1] "=&f"(data[1]), - [d2] "=&f"(data[2]), [d3] "=&f"(data[3]) - : [src_ptr] "r"(src_ptr), [src_ptr1] "r"(src_ptr1), - [dst_ptr] "r"(dst_ptr), [width] "r"(width), - [fy1] "f"(source_y_fraction), [fy0] "f"(fy0), [c0] "f"(c0), - [shift] "f"(shift), [zero] "f"(zero) - : "memory"); -} - -// Use first 4 shuffler values to reorder ARGB channels. -void ARGBShuffleRow_MMI(const uint8_t* src_argb, - uint8_t* dst_argb, - const uint8_t* shuffler, - int width) { - uint64_t source, dest0, dest1, dest; - const uint64_t mask0 = 0x0; - const uint64_t mask1 = (shuffler[0] & 0x03) | ((shuffler[1] & 0x03) << 2) | - ((shuffler[2] & 0x03) << 4) | - ((shuffler[3] & 0x03) << 6); - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - - "punpcklbh %[dest0], %[src], %[mask0] \n\t" - "pshufh %[dest0], %[dest0], %[mask1] \n\t" - "punpckhbh %[dest1], %[src], %[mask0] \n\t" - "pshufh %[dest1], %[dest1], %[mask1] \n\t" - "packushb %[dest], %[dest0], %[dest1] \n\t" - - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(source), [dest] "=&f"(dest), [dest0] "=&f"(dest0), - [dest1] "=&f"(dest1) - : [src_ptr] "r"(src_argb), [dst_ptr] "r"(dst_argb), [mask0] "f"(mask0), - [mask1] "f"(mask1), [width] "r"(width) - : "memory"); -} - -void I422ToYUY2Row_MMI(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_frame, - int width) { - uint64_t temp[3]; - uint64_t vu = 0x0; - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[ty], 0x7(%[src_y]) \n\t" // r=src_sobelx[i] - "gsldrc1 %[ty], 0x0(%[src_y]) \n\t" // r=src_sobelx[i] - "gslwlc1 %[tu], 0x3(%[src_u]) \n\t" // b=src_sobely[i] - "gslwrc1 %[tu], 0x0(%[src_u]) \n\t" // b=src_sobely[i] - "gslwlc1 %[tv], 0x3(%[src_v]) \n\t" // b=src_sobely[i] - "gslwrc1 %[tv], 0x0(%[src_v]) \n\t" // b=src_sobely[i] - "punpcklbh %[vu], %[tu], %[tv] \n\t" // g - "punpcklbh %[tu], %[ty], %[vu] \n\t" // g - "gssdlc1 %[tu], 0x7(%[dst_frame]) \n\t" - "gssdrc1 %[tu], 0x0(%[dst_frame]) \n\t" - "punpckhbh %[tu], %[ty], %[vu] \n\t" // g - "gssdlc1 %[tu], 0x0F(%[dst_frame]) \n\t" - "gssdrc1 %[tu], 0x08(%[dst_frame]) \n\t" - "daddiu %[src_y], %[src_y], 8 \n\t" - "daddiu %[src_u], %[src_u], 4 \n\t" - "daddiu %[src_v], %[src_v], 4 \n\t" - "daddiu %[dst_frame], %[dst_frame], 16 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [ty] "=&f"(temp[1]), [tu] "=&f"(temp[1]), [tv] "=&f"(temp[1]), - [vu] "=&f"(vu) - : [src_y] "r"(src_y), [src_u] "r"(src_u), [src_v] "r"(src_v), - [dst_frame] "r"(dst_frame), [width] "r"(width) - : "memory"); -} - -void I422ToUYVYRow_MMI(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_frame, - int width) { - uint64_t temp[3]; - uint64_t vu = 0x0; - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[ty], 0x7(%[src_y]) \n\t" // r=src_sobelx[i] - "gsldrc1 %[ty], 0x0(%[src_y]) \n\t" // r=src_sobelx[i] - "gslwlc1 %[tu], 0x3(%[src_u]) \n\t" // b=src_sobely[i] - "gslwrc1 %[tu], 0x0(%[src_u]) \n\t" // b=src_sobely[i] - "gslwlc1 %[tv], 0x3(%[src_v]) \n\t" // b=src_sobely[i] - "gslwrc1 %[tv], 0x0(%[src_v]) \n\t" // b=src_sobely[i] - "punpcklbh %[vu], %[tu], %[tv] \n\t" // g - "punpcklbh %[tu], %[vu], %[ty] \n\t" // g - "gssdlc1 %[tu], 0x7(%[dst_frame]) \n\t" - "gssdrc1 %[tu], 0x0(%[dst_frame]) \n\t" - "punpckhbh %[tu], %[vu], %[ty] \n\t" // g - "gssdlc1 %[tu], 0x0F(%[dst_frame]) \n\t" - "gssdrc1 %[tu], 0x08(%[dst_frame]) \n\t" - "daddiu %[src_y], %[src_y], 8 \n\t" - "daddiu %[src_u], %[src_u], 4 \n\t" - "daddiu %[src_v], %[src_v], 4 \n\t" - "daddiu %[dst_frame], %[dst_frame], 16 \n\t" - "daddiu %[width], %[width], -8 \n\t" - "bgtz %[width], 1b \n\t" - "nop \n\t" - : [ty] "=&f"(temp[1]), [tu] "=&f"(temp[1]), [tv] "=&f"(temp[1]), - [vu] "=&f"(vu) - : [src_y] "r"(src_y), [src_u] "r"(src_u), [src_v] "r"(src_v), - [dst_frame] "r"(dst_frame), [width] "r"(width) - : "memory"); -} - -void ARGBCopyAlphaRow_MMI(const uint8_t* src, uint8_t* dst, int width) { - uint64_t source, dest; - const uint64_t mask0 = 0xff000000ff000000ULL; - const uint64_t mask1 = ~mask0; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - "gsldlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gsldrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "and %[src], %[src], %[mask0] \n\t" - "and %[dest], %[dest], %[mask1] \n\t" - "or %[dest], %[src], %[dest] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(source), [dest] "=&f"(dest) - : [src_ptr] "r"(src), [dst_ptr] "r"(dst), [mask0] "f"(mask0), - [mask1] "f"(mask1), [width] "r"(width) - : "memory"); -} - -void ARGBExtractAlphaRow_MMI(const uint8_t* src_argb, - uint8_t* dst_a, - int width) { - uint64_t src, dest0, dest1, dest_lo, dest_hi, dest; - const uint64_t mask = 0xff000000ff000000ULL; - const uint64_t shift = 0x18; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - "and %[dest0], %[src], %[mask] \n\t" - "psrlw %[dest0], %[dest0], %[shift] \n\t" - "gsldlc1 %[src], 0x0f(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x08(%[src_ptr]) \n\t" - "and %[dest1], %[src], %[mask] \n\t" - "psrlw %[dest1], %[dest1], %[shift] \n\t" - "packsswh %[dest_lo], %[dest0], %[dest1] \n\t" - - "gsldlc1 %[src], 0x17(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x10(%[src_ptr]) \n\t" - "and %[dest0], %[src], %[mask] \n\t" - "psrlw %[dest0], %[dest0], %[shift] \n\t" - "gsldlc1 %[src], 0x1f(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x18(%[src_ptr]) \n\t" - "and %[dest1], %[src], %[mask] \n\t" - "psrlw %[dest1], %[dest1], %[shift] \n\t" - "packsswh %[dest_hi], %[dest0], %[dest1] \n\t" - - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x20 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [dest] "=&f"(dest), [dest0] "=&f"(dest0), - [dest1] "=&f"(dest1), [dest_lo] "=&f"(dest_lo), [dest_hi] "=&f"(dest_hi) - : [src_ptr] "r"(src_argb), [dst_ptr] "r"(dst_a), [mask] "f"(mask), - [shift] "f"(shift), [width] "r"(width) - : "memory"); -} - -void ARGBCopyYToAlphaRow_MMI(const uint8_t* src, uint8_t* dst, int width) { - uint64_t source, dest0, dest1, dest; - const uint64_t mask0 = 0x0; - const uint64_t mask1 = 0x00ffffff00ffffffULL; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - - "punpcklbh %[dest0], %[mask0], %[src] \n\t" - "punpcklhw %[dest1], %[mask0], %[dest0] \n\t" - "gsldlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gsldrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - "and %[dest], %[dest], %[mask1] \n\t" - "or %[dest], %[dest], %[dest1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - "punpckhhw %[dest1], %[mask0], %[dest0] \n\t" - "gsldlc1 %[dest], 0x0f(%[dst_ptr]) \n\t" - "gsldrc1 %[dest], 0x08(%[dst_ptr]) \n\t" - "and %[dest], %[dest], %[mask1] \n\t" - "or %[dest], %[dest], %[dest1] \n\t" - "gssdlc1 %[dest], 0x0f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x08(%[dst_ptr]) \n\t" - - "punpckhbh %[dest0], %[mask0], %[src] \n\t" - "punpcklhw %[dest1], %[mask0], %[dest0] \n\t" - "gsldlc1 %[dest], 0x17(%[dst_ptr]) \n\t" - "gsldrc1 %[dest], 0x10(%[dst_ptr]) \n\t" - "and %[dest], %[dest], %[mask1] \n\t" - "or %[dest], %[dest], %[dest1] \n\t" - "gssdlc1 %[dest], 0x17(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x10(%[dst_ptr]) \n\t" - "punpckhhw %[dest1], %[mask0], %[dest0] \n\t" - "gsldlc1 %[dest], 0x1f(%[dst_ptr]) \n\t" - "gsldrc1 %[dest], 0x18(%[dst_ptr]) \n\t" - "and %[dest], %[dest], %[mask1] \n\t" - "or %[dest], %[dest], %[dest1] \n\t" - "gssdlc1 %[dest], 0x1f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x18(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x20 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(source), [dest] "=&f"(dest), [dest0] "=&f"(dest0), - [dest1] "=&f"(dest1) - : [src_ptr] "r"(src), [dst_ptr] "r"(dst), [mask0] "f"(mask0), - [mask1] "f"(mask1), [width] "r"(width) - : "memory"); -} - -#endif // !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) - -#ifdef __cplusplus -} // extern "C" -} // namespace libyuv -#endif diff --git a/libs/libyuv/source/row_msa.cc b/libs/libyuv/source/row_msa.cc deleted file mode 100644 index 5c0239a37f..0000000000 --- a/libs/libyuv/source/row_msa.cc +++ /dev/null @@ -1,3512 +0,0 @@ -/* - * Copyright 2016 The LibYuv Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include - -#include "libyuv/row.h" - -// This module is for GCC MSA -#if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) -#include "libyuv/macros_msa.h" - -#ifdef __cplusplus -namespace libyuv { -extern "C" { -#endif - -#define ALPHA_VAL (-1) - -// Fill YUV -> RGB conversion constants into vectors -#define YUVTORGB_SETUP(yuvconst, ub, vr, ug, vg, bb, bg, br, yg) \ - { \ - ub = __msa_fill_w(yuvconst->kUVToB[0]); \ - vr = __msa_fill_w(yuvconst->kUVToR[1]); \ - ug = __msa_fill_w(yuvconst->kUVToG[0]); \ - vg = __msa_fill_w(yuvconst->kUVToG[1]); \ - bb = __msa_fill_w(yuvconst->kUVBiasB[0]); \ - bg = __msa_fill_w(yuvconst->kUVBiasG[0]); \ - br = __msa_fill_w(yuvconst->kUVBiasR[0]); \ - yg = __msa_fill_w(yuvconst->kYToRgb[0]); \ - } - -// Load YUV 422 pixel data -#define READYUV422(psrc_y, psrc_u, psrc_v, out_y, out_u, out_v) \ - { \ - uint64_t y_m; \ - uint32_t u_m, v_m; \ - v4i32 zero_m = {0}; \ - y_m = LD(psrc_y); \ - u_m = LW(psrc_u); \ - v_m = LW(psrc_v); \ - out_y = (v16u8)__msa_insert_d((v2i64)zero_m, 0, (int64_t)y_m); \ - out_u = (v16u8)__msa_insert_w(zero_m, 0, (int32_t)u_m); \ - out_v = (v16u8)__msa_insert_w(zero_m, 0, (int32_t)v_m); \ - } - -// Clip input vector elements between 0 to 255 -#define CLIP_0TO255(in0, in1, in2, in3, in4, in5) \ - { \ - v4i32 max_m = __msa_ldi_w(0xFF); \ - \ - in0 = __msa_maxi_s_w(in0, 0); \ - in1 = __msa_maxi_s_w(in1, 0); \ - in2 = __msa_maxi_s_w(in2, 0); \ - in3 = __msa_maxi_s_w(in3, 0); \ - in4 = __msa_maxi_s_w(in4, 0); \ - in5 = __msa_maxi_s_w(in5, 0); \ - in0 = __msa_min_s_w(max_m, in0); \ - in1 = __msa_min_s_w(max_m, in1); \ - in2 = __msa_min_s_w(max_m, in2); \ - in3 = __msa_min_s_w(max_m, in3); \ - in4 = __msa_min_s_w(max_m, in4); \ - in5 = __msa_min_s_w(max_m, in5); \ - } - -// Convert 8 pixels of YUV 420 to RGB. -#define YUVTORGB(in_y, in_uv, ubvr, ugvg, bb, bg, br, yg, out_b, out_g, out_r) \ - { \ - v8i16 vec0_m, vec1_m; \ - v4i32 reg0_m, reg1_m, reg2_m, reg3_m, reg4_m; \ - v4i32 reg5_m, reg6_m, reg7_m; \ - v16i8 zero_m = {0}; \ - \ - vec0_m = (v8i16)__msa_ilvr_b((v16i8)in_y, (v16i8)in_y); \ - vec1_m = (v8i16)__msa_ilvr_b((v16i8)zero_m, (v16i8)in_uv); \ - reg0_m = (v4i32)__msa_ilvr_h((v8i16)zero_m, (v8i16)vec0_m); \ - reg1_m = (v4i32)__msa_ilvl_h((v8i16)zero_m, (v8i16)vec0_m); \ - reg2_m = (v4i32)__msa_ilvr_h((v8i16)zero_m, (v8i16)vec1_m); \ - reg3_m = (v4i32)__msa_ilvl_h((v8i16)zero_m, (v8i16)vec1_m); \ - reg0_m *= yg; \ - reg1_m *= yg; \ - reg2_m *= ubvr; \ - reg3_m *= ubvr; \ - reg0_m = __msa_srai_w(reg0_m, 16); \ - reg1_m = __msa_srai_w(reg1_m, 16); \ - reg4_m = __msa_dotp_s_w((v8i16)vec1_m, (v8i16)ugvg); \ - reg5_m = __msa_ilvev_w(reg2_m, reg2_m); \ - reg6_m = __msa_ilvev_w(reg3_m, reg3_m); \ - reg7_m = __msa_ilvr_w(reg4_m, reg4_m); \ - reg2_m = __msa_ilvod_w(reg2_m, reg2_m); \ - reg3_m = __msa_ilvod_w(reg3_m, reg3_m); \ - reg4_m = __msa_ilvl_w(reg4_m, reg4_m); \ - reg5_m = reg0_m - reg5_m; \ - reg6_m = reg1_m - reg6_m; \ - reg2_m = reg0_m - reg2_m; \ - reg3_m = reg1_m - reg3_m; \ - reg7_m = reg0_m - reg7_m; \ - reg4_m = reg1_m - reg4_m; \ - reg5_m += bb; \ - reg6_m += bb; \ - reg7_m += bg; \ - reg4_m += bg; \ - reg2_m += br; \ - reg3_m += br; \ - reg5_m = __msa_srai_w(reg5_m, 6); \ - reg6_m = __msa_srai_w(reg6_m, 6); \ - reg7_m = __msa_srai_w(reg7_m, 6); \ - reg4_m = __msa_srai_w(reg4_m, 6); \ - reg2_m = __msa_srai_w(reg2_m, 6); \ - reg3_m = __msa_srai_w(reg3_m, 6); \ - CLIP_0TO255(reg5_m, reg6_m, reg7_m, reg4_m, reg2_m, reg3_m); \ - out_b = __msa_pckev_h((v8i16)reg6_m, (v8i16)reg5_m); \ - out_g = __msa_pckev_h((v8i16)reg4_m, (v8i16)reg7_m); \ - out_r = __msa_pckev_h((v8i16)reg3_m, (v8i16)reg2_m); \ - } - -// Pack and Store 8 ARGB values. -#define STOREARGB(in0, in1, in2, in3, pdst_argb) \ - { \ - v8i16 vec0_m, vec1_m; \ - v16u8 dst0_m, dst1_m; \ - vec0_m = (v8i16)__msa_ilvev_b((v16i8)in1, (v16i8)in0); \ - vec1_m = (v8i16)__msa_ilvev_b((v16i8)in3, (v16i8)in2); \ - dst0_m = (v16u8)__msa_ilvr_h(vec1_m, vec0_m); \ - dst1_m = (v16u8)__msa_ilvl_h(vec1_m, vec0_m); \ - ST_UB2(dst0_m, dst1_m, pdst_argb, 16); \ - } - -// Takes ARGB input and calculates Y. -#define ARGBTOY(argb0, argb1, argb2, argb3, const0, const1, const2, shift, \ - y_out) \ - { \ - v16u8 vec0_m, vec1_m, vec2_m, vec3_m; \ - v8u16 reg0_m, reg1_m; \ - \ - vec0_m = (v16u8)__msa_pckev_h((v8i16)argb1, (v8i16)argb0); \ - vec1_m = (v16u8)__msa_pckev_h((v8i16)argb3, (v8i16)argb2); \ - vec2_m = (v16u8)__msa_pckod_h((v8i16)argb1, (v8i16)argb0); \ - vec3_m = (v16u8)__msa_pckod_h((v8i16)argb3, (v8i16)argb2); \ - reg0_m = __msa_dotp_u_h(vec0_m, const0); \ - reg1_m = __msa_dotp_u_h(vec1_m, const0); \ - reg0_m = __msa_dpadd_u_h(reg0_m, vec2_m, const1); \ - reg1_m = __msa_dpadd_u_h(reg1_m, vec3_m, const1); \ - reg0_m += const2; \ - reg1_m += const2; \ - reg0_m = (v8u16)__msa_srai_h((v8i16)reg0_m, shift); \ - reg1_m = (v8u16)__msa_srai_h((v8i16)reg1_m, shift); \ - y_out = (v16u8)__msa_pckev_b((v16i8)reg1_m, (v16i8)reg0_m); \ - } - -// Loads current and next row of ARGB input and averages it to calculate U and V -#define READ_ARGB(s_ptr, t_ptr, argb0, argb1, argb2, argb3) \ - { \ - v16u8 src0_m, src1_m, src2_m, src3_m, src4_m, src5_m, src6_m, src7_m; \ - v16u8 vec0_m, vec1_m, vec2_m, vec3_m, vec4_m, vec5_m, vec6_m, vec7_m; \ - v16u8 vec8_m, vec9_m; \ - v8u16 reg0_m, reg1_m, reg2_m, reg3_m, reg4_m, reg5_m, reg6_m, reg7_m; \ - v8u16 reg8_m, reg9_m; \ - \ - src0_m = (v16u8)__msa_ld_b((void*)s, 0); \ - src1_m = (v16u8)__msa_ld_b((void*)s, 16); \ - src2_m = (v16u8)__msa_ld_b((void*)s, 32); \ - src3_m = (v16u8)__msa_ld_b((void*)s, 48); \ - src4_m = (v16u8)__msa_ld_b((void*)t, 0); \ - src5_m = (v16u8)__msa_ld_b((void*)t, 16); \ - src6_m = (v16u8)__msa_ld_b((void*)t, 32); \ - src7_m = (v16u8)__msa_ld_b((void*)t, 48); \ - vec0_m = (v16u8)__msa_ilvr_b((v16i8)src0_m, (v16i8)src4_m); \ - vec1_m = (v16u8)__msa_ilvr_b((v16i8)src1_m, (v16i8)src5_m); \ - vec2_m = (v16u8)__msa_ilvr_b((v16i8)src2_m, (v16i8)src6_m); \ - vec3_m = (v16u8)__msa_ilvr_b((v16i8)src3_m, (v16i8)src7_m); \ - vec4_m = (v16u8)__msa_ilvl_b((v16i8)src0_m, (v16i8)src4_m); \ - vec5_m = (v16u8)__msa_ilvl_b((v16i8)src1_m, (v16i8)src5_m); \ - vec6_m = (v16u8)__msa_ilvl_b((v16i8)src2_m, (v16i8)src6_m); \ - vec7_m = (v16u8)__msa_ilvl_b((v16i8)src3_m, (v16i8)src7_m); \ - reg0_m = __msa_hadd_u_h(vec0_m, vec0_m); \ - reg1_m = __msa_hadd_u_h(vec1_m, vec1_m); \ - reg2_m = __msa_hadd_u_h(vec2_m, vec2_m); \ - reg3_m = __msa_hadd_u_h(vec3_m, vec3_m); \ - reg4_m = __msa_hadd_u_h(vec4_m, vec4_m); \ - reg5_m = __msa_hadd_u_h(vec5_m, vec5_m); \ - reg6_m = __msa_hadd_u_h(vec6_m, vec6_m); \ - reg7_m = __msa_hadd_u_h(vec7_m, vec7_m); \ - reg8_m = (v8u16)__msa_pckev_d((v2i64)reg4_m, (v2i64)reg0_m); \ - reg9_m = (v8u16)__msa_pckev_d((v2i64)reg5_m, (v2i64)reg1_m); \ - reg8_m += (v8u16)__msa_pckod_d((v2i64)reg4_m, (v2i64)reg0_m); \ - reg9_m += (v8u16)__msa_pckod_d((v2i64)reg5_m, (v2i64)reg1_m); \ - reg0_m = (v8u16)__msa_pckev_d((v2i64)reg6_m, (v2i64)reg2_m); \ - reg1_m = (v8u16)__msa_pckev_d((v2i64)reg7_m, (v2i64)reg3_m); \ - reg0_m += (v8u16)__msa_pckod_d((v2i64)reg6_m, (v2i64)reg2_m); \ - reg1_m += (v8u16)__msa_pckod_d((v2i64)reg7_m, (v2i64)reg3_m); \ - reg8_m = (v8u16)__msa_srai_h((v8i16)reg8_m, 2); \ - reg9_m = (v8u16)__msa_srai_h((v8i16)reg9_m, 2); \ - reg0_m = (v8u16)__msa_srai_h((v8i16)reg0_m, 2); \ - reg1_m = (v8u16)__msa_srai_h((v8i16)reg1_m, 2); \ - argb0 = (v16u8)__msa_pckev_b((v16i8)reg9_m, (v16i8)reg8_m); \ - argb1 = (v16u8)__msa_pckev_b((v16i8)reg1_m, (v16i8)reg0_m); \ - src0_m = (v16u8)__msa_ld_b((void*)s, 64); \ - src1_m = (v16u8)__msa_ld_b((void*)s, 80); \ - src2_m = (v16u8)__msa_ld_b((void*)s, 96); \ - src3_m = (v16u8)__msa_ld_b((void*)s, 112); \ - src4_m = (v16u8)__msa_ld_b((void*)t, 64); \ - src5_m = (v16u8)__msa_ld_b((void*)t, 80); \ - src6_m = (v16u8)__msa_ld_b((void*)t, 96); \ - src7_m = (v16u8)__msa_ld_b((void*)t, 112); \ - vec2_m = (v16u8)__msa_ilvr_b((v16i8)src0_m, (v16i8)src4_m); \ - vec3_m = (v16u8)__msa_ilvr_b((v16i8)src1_m, (v16i8)src5_m); \ - vec4_m = (v16u8)__msa_ilvr_b((v16i8)src2_m, (v16i8)src6_m); \ - vec5_m = (v16u8)__msa_ilvr_b((v16i8)src3_m, (v16i8)src7_m); \ - vec6_m = (v16u8)__msa_ilvl_b((v16i8)src0_m, (v16i8)src4_m); \ - vec7_m = (v16u8)__msa_ilvl_b((v16i8)src1_m, (v16i8)src5_m); \ - vec8_m = (v16u8)__msa_ilvl_b((v16i8)src2_m, (v16i8)src6_m); \ - vec9_m = (v16u8)__msa_ilvl_b((v16i8)src3_m, (v16i8)src7_m); \ - reg0_m = __msa_hadd_u_h(vec2_m, vec2_m); \ - reg1_m = __msa_hadd_u_h(vec3_m, vec3_m); \ - reg2_m = __msa_hadd_u_h(vec4_m, vec4_m); \ - reg3_m = __msa_hadd_u_h(vec5_m, vec5_m); \ - reg4_m = __msa_hadd_u_h(vec6_m, vec6_m); \ - reg5_m = __msa_hadd_u_h(vec7_m, vec7_m); \ - reg6_m = __msa_hadd_u_h(vec8_m, vec8_m); \ - reg7_m = __msa_hadd_u_h(vec9_m, vec9_m); \ - reg8_m = (v8u16)__msa_pckev_d((v2i64)reg4_m, (v2i64)reg0_m); \ - reg9_m = (v8u16)__msa_pckev_d((v2i64)reg5_m, (v2i64)reg1_m); \ - reg8_m += (v8u16)__msa_pckod_d((v2i64)reg4_m, (v2i64)reg0_m); \ - reg9_m += (v8u16)__msa_pckod_d((v2i64)reg5_m, (v2i64)reg1_m); \ - reg0_m = (v8u16)__msa_pckev_d((v2i64)reg6_m, (v2i64)reg2_m); \ - reg1_m = (v8u16)__msa_pckev_d((v2i64)reg7_m, (v2i64)reg3_m); \ - reg0_m += (v8u16)__msa_pckod_d((v2i64)reg6_m, (v2i64)reg2_m); \ - reg1_m += (v8u16)__msa_pckod_d((v2i64)reg7_m, (v2i64)reg3_m); \ - reg8_m = (v8u16)__msa_srai_h((v8i16)reg8_m, 2); \ - reg9_m = (v8u16)__msa_srai_h((v8i16)reg9_m, 2); \ - reg0_m = (v8u16)__msa_srai_h((v8i16)reg0_m, 2); \ - reg1_m = (v8u16)__msa_srai_h((v8i16)reg1_m, 2); \ - argb2 = (v16u8)__msa_pckev_b((v16i8)reg9_m, (v16i8)reg8_m); \ - argb3 = (v16u8)__msa_pckev_b((v16i8)reg1_m, (v16i8)reg0_m); \ - } - -// Takes ARGB input and calculates U and V. -#define ARGBTOUV(argb0, argb1, argb2, argb3, const0, const1, const2, const3, \ - shf0, shf1, shf2, shf3, v_out, u_out) \ - { \ - v16u8 vec0_m, vec1_m, vec2_m, vec3_m, vec4_m, vec5_m, vec6_m, vec7_m; \ - v8u16 reg0_m, reg1_m, reg2_m, reg3_m; \ - \ - vec0_m = (v16u8)__msa_vshf_b(shf0, (v16i8)argb1, (v16i8)argb0); \ - vec1_m = (v16u8)__msa_vshf_b(shf0, (v16i8)argb3, (v16i8)argb2); \ - vec2_m = (v16u8)__msa_vshf_b(shf1, (v16i8)argb1, (v16i8)argb0); \ - vec3_m = (v16u8)__msa_vshf_b(shf1, (v16i8)argb3, (v16i8)argb2); \ - vec4_m = (v16u8)__msa_vshf_b(shf2, (v16i8)argb1, (v16i8)argb0); \ - vec5_m = (v16u8)__msa_vshf_b(shf2, (v16i8)argb3, (v16i8)argb2); \ - vec6_m = (v16u8)__msa_vshf_b(shf3, (v16i8)argb1, (v16i8)argb0); \ - vec7_m = (v16u8)__msa_vshf_b(shf3, (v16i8)argb3, (v16i8)argb2); \ - reg0_m = __msa_dotp_u_h(vec0_m, const1); \ - reg1_m = __msa_dotp_u_h(vec1_m, const1); \ - reg2_m = __msa_dotp_u_h(vec4_m, const1); \ - reg3_m = __msa_dotp_u_h(vec5_m, const1); \ - reg0_m += const3; \ - reg1_m += const3; \ - reg2_m += const3; \ - reg3_m += const3; \ - reg0_m -= __msa_dotp_u_h(vec2_m, const0); \ - reg1_m -= __msa_dotp_u_h(vec3_m, const0); \ - reg2_m -= __msa_dotp_u_h(vec6_m, const2); \ - reg3_m -= __msa_dotp_u_h(vec7_m, const2); \ - v_out = (v16u8)__msa_pckod_b((v16i8)reg1_m, (v16i8)reg0_m); \ - u_out = (v16u8)__msa_pckod_b((v16i8)reg3_m, (v16i8)reg2_m); \ - } - -// Load I444 pixel data -#define READI444(psrc_y, psrc_u, psrc_v, out_y, out_u, out_v) \ - { \ - uint64_t y_m, u_m, v_m; \ - v2i64 zero_m = {0}; \ - y_m = LD(psrc_y); \ - u_m = LD(psrc_u); \ - v_m = LD(psrc_v); \ - out_y = (v16u8)__msa_insert_d(zero_m, 0, (int64_t)y_m); \ - out_u = (v16u8)__msa_insert_d(zero_m, 0, (int64_t)u_m); \ - out_v = (v16u8)__msa_insert_d(zero_m, 0, (int64_t)v_m); \ - } - -void MirrorRow_MSA(const uint8_t* src, uint8_t* dst, int width) { - int x; - v16u8 src0, src1, src2, src3; - v16u8 dst0, dst1, dst2, dst3; - v16i8 shuffler = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; - src += width - 64; - - for (x = 0; x < width; x += 64) { - LD_UB4(src, 16, src3, src2, src1, src0); - VSHF_B2_UB(src3, src3, src2, src2, shuffler, shuffler, dst3, dst2); - VSHF_B2_UB(src1, src1, src0, src0, shuffler, shuffler, dst1, dst0); - ST_UB4(dst0, dst1, dst2, dst3, dst, 16); - dst += 64; - src -= 64; - } -} - -void ARGBMirrorRow_MSA(const uint8_t* src, uint8_t* dst, int width) { - int x; - v16u8 src0, src1, src2, src3; - v16u8 dst0, dst1, dst2, dst3; - v16i8 shuffler = {12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3}; - src += width * 4 - 64; - - for (x = 0; x < width; x += 16) { - LD_UB4(src, 16, src3, src2, src1, src0); - VSHF_B2_UB(src3, src3, src2, src2, shuffler, shuffler, dst3, dst2); - VSHF_B2_UB(src1, src1, src0, src0, shuffler, shuffler, dst1, dst0); - ST_UB4(dst0, dst1, dst2, dst3, dst, 16); - dst += 64; - src -= 64; - } -} - -void I422ToYUY2Row_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_yuy2, - int width) { - int x; - v16u8 src_u0, src_v0, src_y0, src_y1, vec_uv0, vec_uv1; - v16u8 dst_yuy2_0, dst_yuy2_1, dst_yuy2_2, dst_yuy2_3; - - for (x = 0; x < width; x += 32) { - src_u0 = LD_UB(src_u); - src_v0 = LD_UB(src_v); - LD_UB2(src_y, 16, src_y0, src_y1); - ILVRL_B2_UB(src_v0, src_u0, vec_uv0, vec_uv1); - ILVRL_B2_UB(vec_uv0, src_y0, dst_yuy2_0, dst_yuy2_1); - ILVRL_B2_UB(vec_uv1, src_y1, dst_yuy2_2, dst_yuy2_3); - ST_UB4(dst_yuy2_0, dst_yuy2_1, dst_yuy2_2, dst_yuy2_3, dst_yuy2, 16); - src_u += 16; - src_v += 16; - src_y += 32; - dst_yuy2 += 64; - } -} - -void I422ToUYVYRow_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_uyvy, - int width) { - int x; - v16u8 src_u0, src_v0, src_y0, src_y1, vec_uv0, vec_uv1; - v16u8 dst_uyvy0, dst_uyvy1, dst_uyvy2, dst_uyvy3; - - for (x = 0; x < width; x += 32) { - src_u0 = LD_UB(src_u); - src_v0 = LD_UB(src_v); - LD_UB2(src_y, 16, src_y0, src_y1); - ILVRL_B2_UB(src_v0, src_u0, vec_uv0, vec_uv1); - ILVRL_B2_UB(src_y0, vec_uv0, dst_uyvy0, dst_uyvy1); - ILVRL_B2_UB(src_y1, vec_uv1, dst_uyvy2, dst_uyvy3); - ST_UB4(dst_uyvy0, dst_uyvy1, dst_uyvy2, dst_uyvy3, dst_uyvy, 16); - src_u += 16; - src_v += 16; - src_y += 32; - dst_uyvy += 64; - } -} - -void I422ToARGBRow_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - int x; - v16u8 src0, src1, src2; - v8i16 vec0, vec1, vec2; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 8) { - READYUV422(src_y, src_u, src_v, src0, src1, src2); - src1 = (v16u8)__msa_ilvr_b((v16i8)src2, (v16i8)src1); - YUVTORGB(src0, src1, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec1, vec2); - STOREARGB(vec0, vec1, vec2, alpha, dst_argb); - src_y += 8; - src_u += 4; - src_v += 4; - dst_argb += 32; - } -} - -void I422ToRGBARow_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - int x; - v16u8 src0, src1, src2; - v8i16 vec0, vec1, vec2; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 8) { - READYUV422(src_y, src_u, src_v, src0, src1, src2); - src1 = (v16u8)__msa_ilvr_b((v16i8)src2, (v16i8)src1); - YUVTORGB(src0, src1, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec1, vec2); - STOREARGB(alpha, vec0, vec1, vec2, dst_argb); - src_y += 8; - src_u += 4; - src_v += 4; - dst_argb += 32; - } -} - -void I422AlphaToARGBRow_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - const uint8_t* src_a, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - int x; - int64_t data_a; - v16u8 src0, src1, src2, src3; - v8i16 vec0, vec1, vec2; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - v4i32 zero = {0}; - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 8) { - data_a = LD(src_a); - READYUV422(src_y, src_u, src_v, src0, src1, src2); - src1 = (v16u8)__msa_ilvr_b((v16i8)src2, (v16i8)src1); - src3 = (v16u8)__msa_insert_d((v2i64)zero, 0, data_a); - YUVTORGB(src0, src1, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec1, vec2); - src3 = (v16u8)__msa_ilvr_b((v16i8)src3, (v16i8)src3); - STOREARGB(vec0, vec1, vec2, src3, dst_argb); - src_y += 8; - src_u += 4; - src_v += 4; - src_a += 8; - dst_argb += 32; - } -} - -void I422ToRGB24Row_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int32_t width) { - int x; - int64_t data_u, data_v; - v16u8 src0, src1, src2, src3, src4, dst0, dst1, dst2; - v8i16 vec0, vec1, vec2, vec3, vec4, vec5; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - v16u8 reg0, reg1, reg2, reg3; - v2i64 zero = {0}; - v16i8 shuffler0 = {0, 1, 16, 2, 3, 17, 4, 5, 18, 6, 7, 19, 8, 9, 20, 10}; - v16i8 shuffler1 = {0, 21, 1, 2, 22, 3, 4, 23, 5, 6, 24, 7, 8, 25, 9, 10}; - v16i8 shuffler2 = {26, 6, 7, 27, 8, 9, 28, 10, - 11, 29, 12, 13, 30, 14, 15, 31}; - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((v16u8*)src_y, 0); - data_u = LD(src_u); - data_v = LD(src_v); - src1 = (v16u8)__msa_insert_d(zero, 0, data_u); - src2 = (v16u8)__msa_insert_d(zero, 0, data_v); - src1 = (v16u8)__msa_ilvr_b((v16i8)src2, (v16i8)src1); - src3 = (v16u8)__msa_sldi_b((v16i8)src0, (v16i8)src0, 8); - src4 = (v16u8)__msa_sldi_b((v16i8)src1, (v16i8)src1, 8); - YUVTORGB(src0, src1, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec1, vec2); - YUVTORGB(src3, src4, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec3, vec4, vec5); - reg0 = (v16u8)__msa_ilvev_b((v16i8)vec1, (v16i8)vec0); - reg2 = (v16u8)__msa_ilvev_b((v16i8)vec4, (v16i8)vec3); - reg3 = (v16u8)__msa_pckev_b((v16i8)vec5, (v16i8)vec2); - reg1 = (v16u8)__msa_sldi_b((v16i8)reg2, (v16i8)reg0, 11); - dst0 = (v16u8)__msa_vshf_b(shuffler0, (v16i8)reg3, (v16i8)reg0); - dst1 = (v16u8)__msa_vshf_b(shuffler1, (v16i8)reg3, (v16i8)reg1); - dst2 = (v16u8)__msa_vshf_b(shuffler2, (v16i8)reg3, (v16i8)reg2); - ST_UB2(dst0, dst1, dst_argb, 16); - ST_UB(dst2, (dst_argb + 32)); - src_y += 16; - src_u += 8; - src_v += 8; - dst_argb += 48; - } -} - -// TODO(fbarchard): Consider AND instead of shift to isolate 5 upper bits of R. -void I422ToRGB565Row_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_rgb565, - const struct YuvConstants* yuvconstants, - int width) { - int x; - v16u8 src0, src1, src2, dst0; - v8i16 vec0, vec1, vec2; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 8) { - READYUV422(src_y, src_u, src_v, src0, src1, src2); - src1 = (v16u8)__msa_ilvr_b((v16i8)src2, (v16i8)src1); - YUVTORGB(src0, src1, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec2, vec1); - vec0 = __msa_srai_h(vec0, 3); - vec1 = __msa_srai_h(vec1, 3); - vec2 = __msa_srai_h(vec2, 2); - vec1 = __msa_slli_h(vec1, 11); - vec2 = __msa_slli_h(vec2, 5); - vec0 |= vec1; - dst0 = (v16u8)(vec2 | vec0); - ST_UB(dst0, dst_rgb565); - src_y += 8; - src_u += 4; - src_v += 4; - dst_rgb565 += 16; - } -} - -// TODO(fbarchard): Consider AND instead of shift to isolate 4 upper bits of G. -void I422ToARGB4444Row_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb4444, - const struct YuvConstants* yuvconstants, - int width) { - int x; - v16u8 src0, src1, src2, dst0; - v8i16 vec0, vec1, vec2; - v8u16 reg0, reg1, reg2; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - v8u16 const_0xF000 = (v8u16)__msa_fill_h(0xF000); - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 8) { - READYUV422(src_y, src_u, src_v, src0, src1, src2); - src1 = (v16u8)__msa_ilvr_b((v16i8)src2, (v16i8)src1); - YUVTORGB(src0, src1, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec1, vec2); - reg0 = (v8u16)__msa_srai_h(vec0, 4); - reg1 = (v8u16)__msa_srai_h(vec1, 4); - reg2 = (v8u16)__msa_srai_h(vec2, 4); - reg1 = (v8u16)__msa_slli_h((v8i16)reg1, 4); - reg2 = (v8u16)__msa_slli_h((v8i16)reg2, 8); - reg1 |= const_0xF000; - reg0 |= reg2; - dst0 = (v16u8)(reg1 | reg0); - ST_UB(dst0, dst_argb4444); - src_y += 8; - src_u += 4; - src_v += 4; - dst_argb4444 += 16; - } -} - -void I422ToARGB1555Row_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb1555, - const struct YuvConstants* yuvconstants, - int width) { - int x; - v16u8 src0, src1, src2, dst0; - v8i16 vec0, vec1, vec2; - v8u16 reg0, reg1, reg2; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - v8u16 const_0x8000 = (v8u16)__msa_fill_h(0x8000); - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 8) { - READYUV422(src_y, src_u, src_v, src0, src1, src2); - src1 = (v16u8)__msa_ilvr_b((v16i8)src2, (v16i8)src1); - YUVTORGB(src0, src1, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec1, vec2); - reg0 = (v8u16)__msa_srai_h(vec0, 3); - reg1 = (v8u16)__msa_srai_h(vec1, 3); - reg2 = (v8u16)__msa_srai_h(vec2, 3); - reg1 = (v8u16)__msa_slli_h((v8i16)reg1, 5); - reg2 = (v8u16)__msa_slli_h((v8i16)reg2, 10); - reg1 |= const_0x8000; - reg0 |= reg2; - dst0 = (v16u8)(reg1 | reg0); - ST_UB(dst0, dst_argb1555); - src_y += 8; - src_u += 4; - src_v += 4; - dst_argb1555 += 16; - } -} - -void YUY2ToYRow_MSA(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1; - - for (x = 0; x < width; x += 32) { - LD_UB4(src_yuy2, 16, src0, src1, src2, src3); - dst0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - dst1 = (v16u8)__msa_pckev_b((v16i8)src3, (v16i8)src2); - ST_UB2(dst0, dst1, dst_y, 16); - src_yuy2 += 64; - dst_y += 32; - } -} - -void YUY2ToUVRow_MSA(const uint8_t* src_yuy2, - int src_stride_yuy2, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - const uint8_t* src_yuy2_next = src_yuy2 + src_stride_yuy2; - int x; - v16u8 src0, src1, src2, src3, src4, src5, src6, src7; - v16u8 vec0, vec1, dst0, dst1; - - for (x = 0; x < width; x += 32) { - LD_UB4(src_yuy2, 16, src0, src1, src2, src3); - LD_UB4(src_yuy2_next, 16, src4, src5, src6, src7); - src0 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - src1 = (v16u8)__msa_pckod_b((v16i8)src3, (v16i8)src2); - src2 = (v16u8)__msa_pckod_b((v16i8)src5, (v16i8)src4); - src3 = (v16u8)__msa_pckod_b((v16i8)src7, (v16i8)src6); - vec0 = __msa_aver_u_b(src0, src2); - vec1 = __msa_aver_u_b(src1, src3); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - dst1 = (v16u8)__msa_pckod_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst_u); - ST_UB(dst1, dst_v); - src_yuy2 += 64; - src_yuy2_next += 64; - dst_u += 16; - dst_v += 16; - } -} - -void YUY2ToUV422Row_MSA(const uint8_t* src_yuy2, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1; - - for (x = 0; x < width; x += 32) { - LD_UB4(src_yuy2, 16, src0, src1, src2, src3); - src0 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - src1 = (v16u8)__msa_pckod_b((v16i8)src3, (v16i8)src2); - dst0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - dst1 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - ST_UB(dst0, dst_u); - ST_UB(dst1, dst_v); - src_yuy2 += 64; - dst_u += 16; - dst_v += 16; - } -} - -void UYVYToYRow_MSA(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1; - - for (x = 0; x < width; x += 32) { - LD_UB4(src_uyvy, 16, src0, src1, src2, src3); - dst0 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - dst1 = (v16u8)__msa_pckod_b((v16i8)src3, (v16i8)src2); - ST_UB2(dst0, dst1, dst_y, 16); - src_uyvy += 64; - dst_y += 32; - } -} - -void UYVYToUVRow_MSA(const uint8_t* src_uyvy, - int src_stride_uyvy, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - const uint8_t* src_uyvy_next = src_uyvy + src_stride_uyvy; - int x; - v16u8 src0, src1, src2, src3, src4, src5, src6, src7; - v16u8 vec0, vec1, dst0, dst1; - - for (x = 0; x < width; x += 32) { - LD_UB4(src_uyvy, 16, src0, src1, src2, src3); - LD_UB4(src_uyvy_next, 16, src4, src5, src6, src7); - src0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - src1 = (v16u8)__msa_pckev_b((v16i8)src3, (v16i8)src2); - src2 = (v16u8)__msa_pckev_b((v16i8)src5, (v16i8)src4); - src3 = (v16u8)__msa_pckev_b((v16i8)src7, (v16i8)src6); - vec0 = __msa_aver_u_b(src0, src2); - vec1 = __msa_aver_u_b(src1, src3); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - dst1 = (v16u8)__msa_pckod_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst_u); - ST_UB(dst1, dst_v); - src_uyvy += 64; - src_uyvy_next += 64; - dst_u += 16; - dst_v += 16; - } -} - -void UYVYToUV422Row_MSA(const uint8_t* src_uyvy, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1; - - for (x = 0; x < width; x += 32) { - LD_UB4(src_uyvy, 16, src0, src1, src2, src3); - src0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - src1 = (v16u8)__msa_pckev_b((v16i8)src3, (v16i8)src2); - dst0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - dst1 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - ST_UB(dst0, dst_u); - ST_UB(dst1, dst_v); - src_uyvy += 64; - dst_u += 16; - dst_v += 16; - } -} - -void ARGBToYRow_MSA(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - int x; - v16u8 src0, src1, src2, src3, vec0, vec1, vec2, vec3, dst0; - v8u16 reg0, reg1, reg2, reg3, reg4, reg5; - v16i8 zero = {0}; - v8u16 const_0x19 = (v8u16)__msa_ldi_h(0x19); - v8u16 const_0x81 = (v8u16)__msa_ldi_h(0x81); - v8u16 const_0x42 = (v8u16)__msa_ldi_h(0x42); - v8u16 const_0x1080 = (v8u16)__msa_fill_h(0x1080); - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 16); - src2 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 32); - src3 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 48); - vec0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - vec1 = (v16u8)__msa_pckev_b((v16i8)src3, (v16i8)src2); - vec2 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - vec3 = (v16u8)__msa_pckod_b((v16i8)src3, (v16i8)src2); - reg0 = (v8u16)__msa_ilvev_b(zero, (v16i8)vec0); - reg1 = (v8u16)__msa_ilvev_b(zero, (v16i8)vec1); - reg2 = (v8u16)__msa_ilvev_b(zero, (v16i8)vec2); - reg3 = (v8u16)__msa_ilvev_b(zero, (v16i8)vec3); - reg4 = (v8u16)__msa_ilvod_b(zero, (v16i8)vec0); - reg5 = (v8u16)__msa_ilvod_b(zero, (v16i8)vec1); - reg0 *= const_0x19; - reg1 *= const_0x19; - reg2 *= const_0x81; - reg3 *= const_0x81; - reg4 *= const_0x42; - reg5 *= const_0x42; - reg0 += reg2; - reg1 += reg3; - reg0 += reg4; - reg1 += reg5; - reg0 += const_0x1080; - reg1 += const_0x1080; - reg0 = (v8u16)__msa_srai_h((v8i16)reg0, 8); - reg1 = (v8u16)__msa_srai_h((v8i16)reg1, 8); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg1, (v16i8)reg0); - ST_UB(dst0, dst_y); - src_argb0 += 64; - dst_y += 16; - } -} - -void ARGBToUVRow_MSA(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - const uint8_t* src_argb0_next = src_argb0 + src_stride_argb; - v16u8 src0, src1, src2, src3, src4, src5, src6, src7; - v16u8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9; - v8u16 reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9; - v16u8 dst0, dst1; - v8u16 const_0x70 = (v8u16)__msa_ldi_h(0x70); - v8u16 const_0x4A = (v8u16)__msa_ldi_h(0x4A); - v8u16 const_0x26 = (v8u16)__msa_ldi_h(0x26); - v8u16 const_0x5E = (v8u16)__msa_ldi_h(0x5E); - v8u16 const_0x12 = (v8u16)__msa_ldi_h(0x12); - v8u16 const_0x8080 = (v8u16)__msa_fill_h(0x8080); - - for (x = 0; x < width; x += 32) { - src0 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 16); - src2 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 32); - src3 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 48); - src4 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 64); - src5 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 80); - src6 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 96); - src7 = (v16u8)__msa_ld_b((v16u8*)src_argb0, 112); - vec0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - vec1 = (v16u8)__msa_pckev_b((v16i8)src3, (v16i8)src2); - vec2 = (v16u8)__msa_pckev_b((v16i8)src5, (v16i8)src4); - vec3 = (v16u8)__msa_pckev_b((v16i8)src7, (v16i8)src6); - vec4 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - vec5 = (v16u8)__msa_pckod_b((v16i8)src3, (v16i8)src2); - vec6 = (v16u8)__msa_pckod_b((v16i8)src5, (v16i8)src4); - vec7 = (v16u8)__msa_pckod_b((v16i8)src7, (v16i8)src6); - vec8 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - vec9 = (v16u8)__msa_pckev_b((v16i8)vec3, (v16i8)vec2); - vec4 = (v16u8)__msa_pckev_b((v16i8)vec5, (v16i8)vec4); - vec5 = (v16u8)__msa_pckev_b((v16i8)vec7, (v16i8)vec6); - vec0 = (v16u8)__msa_pckod_b((v16i8)vec1, (v16i8)vec0); - vec1 = (v16u8)__msa_pckod_b((v16i8)vec3, (v16i8)vec2); - reg0 = __msa_hadd_u_h(vec8, vec8); - reg1 = __msa_hadd_u_h(vec9, vec9); - reg2 = __msa_hadd_u_h(vec4, vec4); - reg3 = __msa_hadd_u_h(vec5, vec5); - reg4 = __msa_hadd_u_h(vec0, vec0); - reg5 = __msa_hadd_u_h(vec1, vec1); - src0 = (v16u8)__msa_ld_b((v16u8*)src_argb0_next, 0); - src1 = (v16u8)__msa_ld_b((v16u8*)src_argb0_next, 16); - src2 = (v16u8)__msa_ld_b((v16u8*)src_argb0_next, 32); - src3 = (v16u8)__msa_ld_b((v16u8*)src_argb0_next, 48); - src4 = (v16u8)__msa_ld_b((v16u8*)src_argb0_next, 64); - src5 = (v16u8)__msa_ld_b((v16u8*)src_argb0_next, 80); - src6 = (v16u8)__msa_ld_b((v16u8*)src_argb0_next, 96); - src7 = (v16u8)__msa_ld_b((v16u8*)src_argb0_next, 112); - vec0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - vec1 = (v16u8)__msa_pckev_b((v16i8)src3, (v16i8)src2); - vec2 = (v16u8)__msa_pckev_b((v16i8)src5, (v16i8)src4); - vec3 = (v16u8)__msa_pckev_b((v16i8)src7, (v16i8)src6); - vec4 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - vec5 = (v16u8)__msa_pckod_b((v16i8)src3, (v16i8)src2); - vec6 = (v16u8)__msa_pckod_b((v16i8)src5, (v16i8)src4); - vec7 = (v16u8)__msa_pckod_b((v16i8)src7, (v16i8)src6); - vec8 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - vec9 = (v16u8)__msa_pckev_b((v16i8)vec3, (v16i8)vec2); - vec4 = (v16u8)__msa_pckev_b((v16i8)vec5, (v16i8)vec4); - vec5 = (v16u8)__msa_pckev_b((v16i8)vec7, (v16i8)vec6); - vec0 = (v16u8)__msa_pckod_b((v16i8)vec1, (v16i8)vec0); - vec1 = (v16u8)__msa_pckod_b((v16i8)vec3, (v16i8)vec2); - reg0 += __msa_hadd_u_h(vec8, vec8); - reg1 += __msa_hadd_u_h(vec9, vec9); - reg2 += __msa_hadd_u_h(vec4, vec4); - reg3 += __msa_hadd_u_h(vec5, vec5); - reg4 += __msa_hadd_u_h(vec0, vec0); - reg5 += __msa_hadd_u_h(vec1, vec1); - reg0 = (v8u16)__msa_srai_h((v8i16)reg0, 2); - reg1 = (v8u16)__msa_srai_h((v8i16)reg1, 2); - reg2 = (v8u16)__msa_srai_h((v8i16)reg2, 2); - reg3 = (v8u16)__msa_srai_h((v8i16)reg3, 2); - reg4 = (v8u16)__msa_srai_h((v8i16)reg4, 2); - reg5 = (v8u16)__msa_srai_h((v8i16)reg5, 2); - reg6 = reg0 * const_0x70; - reg7 = reg1 * const_0x70; - reg8 = reg2 * const_0x4A; - reg9 = reg3 * const_0x4A; - reg6 += const_0x8080; - reg7 += const_0x8080; - reg8 += reg4 * const_0x26; - reg9 += reg5 * const_0x26; - reg0 *= const_0x12; - reg1 *= const_0x12; - reg2 *= const_0x5E; - reg3 *= const_0x5E; - reg4 *= const_0x70; - reg5 *= const_0x70; - reg2 += reg0; - reg3 += reg1; - reg4 += const_0x8080; - reg5 += const_0x8080; - reg6 -= reg8; - reg7 -= reg9; - reg4 -= reg2; - reg5 -= reg3; - reg6 = (v8u16)__msa_srai_h((v8i16)reg6, 8); - reg7 = (v8u16)__msa_srai_h((v8i16)reg7, 8); - reg4 = (v8u16)__msa_srai_h((v8i16)reg4, 8); - reg5 = (v8u16)__msa_srai_h((v8i16)reg5, 8); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg7, (v16i8)reg6); - dst1 = (v16u8)__msa_pckev_b((v16i8)reg5, (v16i8)reg4); - ST_UB(dst0, dst_u); - ST_UB(dst1, dst_v); - src_argb0 += 128; - src_argb0_next += 128; - dst_u += 16; - dst_v += 16; - } -} - -void ARGBToRGB24Row_MSA(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1, dst2; - v16i8 shuffler0 = {0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 16, 17, 18, 20}; - v16i8 shuffler1 = {5, 6, 8, 9, 10, 12, 13, 14, - 16, 17, 18, 20, 21, 22, 24, 25}; - v16i8 shuffler2 = {10, 12, 13, 14, 16, 17, 18, 20, - 21, 22, 24, 25, 26, 28, 29, 30}; - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb, 32); - src3 = (v16u8)__msa_ld_b((void*)src_argb, 48); - dst0 = (v16u8)__msa_vshf_b(shuffler0, (v16i8)src1, (v16i8)src0); - dst1 = (v16u8)__msa_vshf_b(shuffler1, (v16i8)src2, (v16i8)src1); - dst2 = (v16u8)__msa_vshf_b(shuffler2, (v16i8)src3, (v16i8)src2); - ST_UB2(dst0, dst1, dst_rgb, 16); - ST_UB(dst2, (dst_rgb + 32)); - src_argb += 64; - dst_rgb += 48; - } -} - -void ARGBToRAWRow_MSA(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1, dst2; - v16i8 shuffler0 = {2, 1, 0, 6, 5, 4, 10, 9, 8, 14, 13, 12, 18, 17, 16, 22}; - v16i8 shuffler1 = {5, 4, 10, 9, 8, 14, 13, 12, - 18, 17, 16, 22, 21, 20, 26, 25}; - v16i8 shuffler2 = {8, 14, 13, 12, 18, 17, 16, 22, - 21, 20, 26, 25, 24, 30, 29, 28}; - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb, 32); - src3 = (v16u8)__msa_ld_b((void*)src_argb, 48); - dst0 = (v16u8)__msa_vshf_b(shuffler0, (v16i8)src1, (v16i8)src0); - dst1 = (v16u8)__msa_vshf_b(shuffler1, (v16i8)src2, (v16i8)src1); - dst2 = (v16u8)__msa_vshf_b(shuffler2, (v16i8)src3, (v16i8)src2); - ST_UB2(dst0, dst1, dst_rgb, 16); - ST_UB(dst2, (dst_rgb + 32)); - src_argb += 64; - dst_rgb += 48; - } -} - -void ARGBToRGB565Row_MSA(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { - int x; - v16u8 src0, src1, dst0; - v16u8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7; - v16i8 zero = {0}; - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((void*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb, 16); - vec0 = (v16u8)__msa_srai_b((v16i8)src0, 3); - vec1 = (v16u8)__msa_slli_b((v16i8)src0, 3); - vec2 = (v16u8)__msa_srai_b((v16i8)src0, 5); - vec4 = (v16u8)__msa_srai_b((v16i8)src1, 3); - vec5 = (v16u8)__msa_slli_b((v16i8)src1, 3); - vec6 = (v16u8)__msa_srai_b((v16i8)src1, 5); - vec1 = (v16u8)__msa_sldi_b(zero, (v16i8)vec1, 1); - vec2 = (v16u8)__msa_sldi_b(zero, (v16i8)vec2, 1); - vec5 = (v16u8)__msa_sldi_b(zero, (v16i8)vec5, 1); - vec6 = (v16u8)__msa_sldi_b(zero, (v16i8)vec6, 1); - vec3 = (v16u8)__msa_sldi_b(zero, (v16i8)src0, 2); - vec7 = (v16u8)__msa_sldi_b(zero, (v16i8)src1, 2); - vec0 = __msa_binsli_b(vec0, vec1, 2); - vec1 = __msa_binsli_b(vec2, vec3, 4); - vec4 = __msa_binsli_b(vec4, vec5, 2); - vec5 = __msa_binsli_b(vec6, vec7, 4); - vec0 = (v16u8)__msa_ilvev_b((v16i8)vec1, (v16i8)vec0); - vec4 = (v16u8)__msa_ilvev_b((v16i8)vec5, (v16i8)vec4); - dst0 = (v16u8)__msa_pckev_h((v8i16)vec4, (v8i16)vec0); - ST_UB(dst0, dst_rgb); - src_argb += 32; - dst_rgb += 16; - } -} - -void ARGBToARGB1555Row_MSA(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - int x; - v16u8 src0, src1, dst0; - v16u8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9; - v16i8 zero = {0}; - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((void*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb, 16); - vec0 = (v16u8)__msa_srai_b((v16i8)src0, 3); - vec1 = (v16u8)__msa_slli_b((v16i8)src0, 2); - vec2 = (v16u8)__msa_srai_b((v16i8)vec0, 3); - vec1 = (v16u8)__msa_sldi_b(zero, (v16i8)vec1, 1); - vec2 = (v16u8)__msa_sldi_b(zero, (v16i8)vec2, 1); - vec3 = (v16u8)__msa_srai_b((v16i8)src0, 1); - vec5 = (v16u8)__msa_srai_b((v16i8)src1, 3); - vec6 = (v16u8)__msa_slli_b((v16i8)src1, 2); - vec7 = (v16u8)__msa_srai_b((v16i8)vec5, 3); - vec6 = (v16u8)__msa_sldi_b(zero, (v16i8)vec6, 1); - vec7 = (v16u8)__msa_sldi_b(zero, (v16i8)vec7, 1); - vec8 = (v16u8)__msa_srai_b((v16i8)src1, 1); - vec3 = (v16u8)__msa_sldi_b(zero, (v16i8)vec3, 2); - vec8 = (v16u8)__msa_sldi_b(zero, (v16i8)vec8, 2); - vec4 = (v16u8)__msa_sldi_b(zero, (v16i8)src0, 3); - vec9 = (v16u8)__msa_sldi_b(zero, (v16i8)src1, 3); - vec0 = __msa_binsli_b(vec0, vec1, 2); - vec5 = __msa_binsli_b(vec5, vec6, 2); - vec1 = __msa_binsli_b(vec2, vec3, 5); - vec6 = __msa_binsli_b(vec7, vec8, 5); - vec1 = __msa_binsli_b(vec1, vec4, 0); - vec6 = __msa_binsli_b(vec6, vec9, 0); - vec0 = (v16u8)__msa_ilvev_b((v16i8)vec1, (v16i8)vec0); - vec1 = (v16u8)__msa_ilvev_b((v16i8)vec6, (v16i8)vec5); - dst0 = (v16u8)__msa_pckev_h((v8i16)vec1, (v8i16)vec0); - ST_UB(dst0, dst_rgb); - src_argb += 32; - dst_rgb += 16; - } -} - -void ARGBToARGB4444Row_MSA(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - int x; - v16u8 src0, src1; - v16u8 vec0, vec1; - v16u8 dst0; - v16i8 zero = {0}; - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((void*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb, 16); - vec0 = (v16u8)__msa_srai_b((v16i8)src0, 4); - vec1 = (v16u8)__msa_srai_b((v16i8)src1, 4); - src0 = (v16u8)__msa_sldi_b(zero, (v16i8)src0, 1); - src1 = (v16u8)__msa_sldi_b(zero, (v16i8)src1, 1); - vec0 = __msa_binsli_b(vec0, src0, 3); - vec1 = __msa_binsli_b(vec1, src1, 3); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst_rgb); - src_argb += 32; - dst_rgb += 16; - } -} - -void ARGBToUV444Row_MSA(const uint8_t* src_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int32_t width) { - int32_t x; - v16u8 src0, src1, src2, src3, reg0, reg1, reg2, reg3, dst0, dst1; - v8u16 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7; - v8u16 vec8, vec9, vec10, vec11; - v8u16 const_112 = (v8u16)__msa_ldi_h(112); - v8u16 const_74 = (v8u16)__msa_ldi_h(74); - v8u16 const_38 = (v8u16)__msa_ldi_h(38); - v8u16 const_94 = (v8u16)__msa_ldi_h(94); - v8u16 const_18 = (v8u16)__msa_ldi_h(18); - v8u16 const_32896 = (v8u16)__msa_fill_h(32896); - v16i8 zero = {0}; - - for (x = width; x > 0; x -= 16) { - src0 = (v16u8)__msa_ld_b((void*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb, 32); - src3 = (v16u8)__msa_ld_b((void*)src_argb, 48); - reg0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - reg1 = (v16u8)__msa_pckev_b((v16i8)src3, (v16i8)src2); - reg2 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - reg3 = (v16u8)__msa_pckod_b((v16i8)src3, (v16i8)src2); - src0 = (v16u8)__msa_pckev_b((v16i8)reg1, (v16i8)reg0); - src1 = (v16u8)__msa_pckev_b((v16i8)reg3, (v16i8)reg2); - src2 = (v16u8)__msa_pckod_b((v16i8)reg1, (v16i8)reg0); - vec0 = (v8u16)__msa_ilvr_b(zero, (v16i8)src0); - vec1 = (v8u16)__msa_ilvl_b(zero, (v16i8)src0); - vec2 = (v8u16)__msa_ilvr_b(zero, (v16i8)src1); - vec3 = (v8u16)__msa_ilvl_b(zero, (v16i8)src1); - vec4 = (v8u16)__msa_ilvr_b(zero, (v16i8)src2); - vec5 = (v8u16)__msa_ilvl_b(zero, (v16i8)src2); - vec10 = vec0 * const_18; - vec11 = vec1 * const_18; - vec8 = vec2 * const_94; - vec9 = vec3 * const_94; - vec6 = vec4 * const_112; - vec7 = vec5 * const_112; - vec0 *= const_112; - vec1 *= const_112; - vec2 *= const_74; - vec3 *= const_74; - vec4 *= const_38; - vec5 *= const_38; - vec8 += vec10; - vec9 += vec11; - vec6 += const_32896; - vec7 += const_32896; - vec0 += const_32896; - vec1 += const_32896; - vec2 += vec4; - vec3 += vec5; - vec0 -= vec2; - vec1 -= vec3; - vec6 -= vec8; - vec7 -= vec9; - vec0 = (v8u16)__msa_srai_h((v8i16)vec0, 8); - vec1 = (v8u16)__msa_srai_h((v8i16)vec1, 8); - vec6 = (v8u16)__msa_srai_h((v8i16)vec6, 8); - vec7 = (v8u16)__msa_srai_h((v8i16)vec7, 8); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - dst1 = (v16u8)__msa_pckev_b((v16i8)vec7, (v16i8)vec6); - ST_UB(dst0, dst_u); - ST_UB(dst1, dst_v); - src_argb += 64; - dst_u += 16; - dst_v += 16; - } -} - -void ARGBMultiplyRow_MSA(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - int x; - v16u8 src0, src1, dst0; - v8u16 vec0, vec1, vec2, vec3; - v4u32 reg0, reg1, reg2, reg3; - v8i16 zero = {0}; - - for (x = 0; x < width; x += 4) { - src0 = (v16u8)__msa_ld_b((void*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb1, 0); - vec0 = (v8u16)__msa_ilvr_b((v16i8)src0, (v16i8)src0); - vec1 = (v8u16)__msa_ilvl_b((v16i8)src0, (v16i8)src0); - vec2 = (v8u16)__msa_ilvr_b((v16i8)zero, (v16i8)src1); - vec3 = (v8u16)__msa_ilvl_b((v16i8)zero, (v16i8)src1); - reg0 = (v4u32)__msa_ilvr_h(zero, (v8i16)vec0); - reg1 = (v4u32)__msa_ilvl_h(zero, (v8i16)vec0); - reg2 = (v4u32)__msa_ilvr_h(zero, (v8i16)vec1); - reg3 = (v4u32)__msa_ilvl_h(zero, (v8i16)vec1); - reg0 *= (v4u32)__msa_ilvr_h(zero, (v8i16)vec2); - reg1 *= (v4u32)__msa_ilvl_h(zero, (v8i16)vec2); - reg2 *= (v4u32)__msa_ilvr_h(zero, (v8i16)vec3); - reg3 *= (v4u32)__msa_ilvl_h(zero, (v8i16)vec3); - reg0 = (v4u32)__msa_srai_w((v4i32)reg0, 16); - reg1 = (v4u32)__msa_srai_w((v4i32)reg1, 16); - reg2 = (v4u32)__msa_srai_w((v4i32)reg2, 16); - reg3 = (v4u32)__msa_srai_w((v4i32)reg3, 16); - vec0 = (v8u16)__msa_pckev_h((v8i16)reg1, (v8i16)reg0); - vec1 = (v8u16)__msa_pckev_h((v8i16)reg3, (v8i16)reg2); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst_argb); - src_argb0 += 16; - src_argb1 += 16; - dst_argb += 16; - } -} - -void ARGBAddRow_MSA(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1; - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((void*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb0, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb1, 0); - src3 = (v16u8)__msa_ld_b((void*)src_argb1, 16); - dst0 = __msa_adds_u_b(src0, src2); - dst1 = __msa_adds_u_b(src1, src3); - ST_UB2(dst0, dst1, dst_argb, 16); - src_argb0 += 32; - src_argb1 += 32; - dst_argb += 32; - } -} - -void ARGBSubtractRow_MSA(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1; - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((void*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb0, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb1, 0); - src3 = (v16u8)__msa_ld_b((void*)src_argb1, 16); - dst0 = __msa_subs_u_b(src0, src2); - dst1 = __msa_subs_u_b(src1, src3); - ST_UB2(dst0, dst1, dst_argb, 16); - src_argb0 += 32; - src_argb1 += 32; - dst_argb += 32; - } -} - -void ARGBAttenuateRow_MSA(const uint8_t* src_argb, - uint8_t* dst_argb, - int width) { - int x; - v16u8 src0, src1, dst0, dst1; - v8u16 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9; - v4u32 reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7; - v8i16 zero = {0}; - v16u8 mask = {0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255}; - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((void*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb, 16); - vec0 = (v8u16)__msa_ilvr_b((v16i8)src0, (v16i8)src0); - vec1 = (v8u16)__msa_ilvl_b((v16i8)src0, (v16i8)src0); - vec2 = (v8u16)__msa_ilvr_b((v16i8)src1, (v16i8)src1); - vec3 = (v8u16)__msa_ilvl_b((v16i8)src1, (v16i8)src1); - vec4 = (v8u16)__msa_fill_h(vec0[3]); - vec5 = (v8u16)__msa_fill_h(vec0[7]); - vec6 = (v8u16)__msa_fill_h(vec1[3]); - vec7 = (v8u16)__msa_fill_h(vec1[7]); - vec4 = (v8u16)__msa_pckev_d((v2i64)vec5, (v2i64)vec4); - vec5 = (v8u16)__msa_pckev_d((v2i64)vec7, (v2i64)vec6); - vec6 = (v8u16)__msa_fill_h(vec2[3]); - vec7 = (v8u16)__msa_fill_h(vec2[7]); - vec8 = (v8u16)__msa_fill_h(vec3[3]); - vec9 = (v8u16)__msa_fill_h(vec3[7]); - vec6 = (v8u16)__msa_pckev_d((v2i64)vec7, (v2i64)vec6); - vec7 = (v8u16)__msa_pckev_d((v2i64)vec9, (v2i64)vec8); - reg0 = (v4u32)__msa_ilvr_h(zero, (v8i16)vec4); - reg1 = (v4u32)__msa_ilvl_h(zero, (v8i16)vec4); - reg2 = (v4u32)__msa_ilvr_h(zero, (v8i16)vec5); - reg3 = (v4u32)__msa_ilvl_h(zero, (v8i16)vec5); - reg4 = (v4u32)__msa_ilvr_h(zero, (v8i16)vec6); - reg5 = (v4u32)__msa_ilvl_h(zero, (v8i16)vec6); - reg6 = (v4u32)__msa_ilvr_h(zero, (v8i16)vec7); - reg7 = (v4u32)__msa_ilvl_h(zero, (v8i16)vec7); - reg0 *= (v4u32)__msa_ilvr_h(zero, (v8i16)vec0); - reg1 *= (v4u32)__msa_ilvl_h(zero, (v8i16)vec0); - reg2 *= (v4u32)__msa_ilvr_h(zero, (v8i16)vec1); - reg3 *= (v4u32)__msa_ilvl_h(zero, (v8i16)vec1); - reg4 *= (v4u32)__msa_ilvr_h(zero, (v8i16)vec2); - reg5 *= (v4u32)__msa_ilvl_h(zero, (v8i16)vec2); - reg6 *= (v4u32)__msa_ilvr_h(zero, (v8i16)vec3); - reg7 *= (v4u32)__msa_ilvl_h(zero, (v8i16)vec3); - reg0 = (v4u32)__msa_srai_w((v4i32)reg0, 24); - reg1 = (v4u32)__msa_srai_w((v4i32)reg1, 24); - reg2 = (v4u32)__msa_srai_w((v4i32)reg2, 24); - reg3 = (v4u32)__msa_srai_w((v4i32)reg3, 24); - reg4 = (v4u32)__msa_srai_w((v4i32)reg4, 24); - reg5 = (v4u32)__msa_srai_w((v4i32)reg5, 24); - reg6 = (v4u32)__msa_srai_w((v4i32)reg6, 24); - reg7 = (v4u32)__msa_srai_w((v4i32)reg7, 24); - vec0 = (v8u16)__msa_pckev_h((v8i16)reg1, (v8i16)reg0); - vec1 = (v8u16)__msa_pckev_h((v8i16)reg3, (v8i16)reg2); - vec2 = (v8u16)__msa_pckev_h((v8i16)reg5, (v8i16)reg4); - vec3 = (v8u16)__msa_pckev_h((v8i16)reg7, (v8i16)reg6); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - dst1 = (v16u8)__msa_pckev_b((v16i8)vec3, (v16i8)vec2); - dst0 = __msa_bmnz_v(dst0, src0, mask); - dst1 = __msa_bmnz_v(dst1, src1, mask); - ST_UB2(dst0, dst1, dst_argb, 16); - src_argb += 32; - dst_argb += 32; - } -} - -void ARGBToRGB565DitherRow_MSA(const uint8_t* src_argb, - uint8_t* dst_rgb, - uint32_t dither4, - int width) { - int x; - v16u8 src0, src1, dst0, vec0, vec1; - v8i16 vec_d0; - v8i16 reg0, reg1, reg2; - v16i8 zero = {0}; - v8i16 max = __msa_ldi_h(0xFF); - - vec_d0 = (v8i16)__msa_fill_w(dither4); - vec_d0 = (v8i16)__msa_ilvr_b(zero, (v16i8)vec_d0); - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((void*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb, 16); - vec0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - vec1 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - reg0 = (v8i16)__msa_ilvev_b(zero, (v16i8)vec0); - reg1 = (v8i16)__msa_ilvev_b(zero, (v16i8)vec1); - reg2 = (v8i16)__msa_ilvod_b(zero, (v16i8)vec0); - reg0 += vec_d0; - reg1 += vec_d0; - reg2 += vec_d0; - reg0 = __msa_maxi_s_h((v8i16)reg0, 0); - reg1 = __msa_maxi_s_h((v8i16)reg1, 0); - reg2 = __msa_maxi_s_h((v8i16)reg2, 0); - reg0 = __msa_min_s_h((v8i16)max, (v8i16)reg0); - reg1 = __msa_min_s_h((v8i16)max, (v8i16)reg1); - reg2 = __msa_min_s_h((v8i16)max, (v8i16)reg2); - reg0 = __msa_srai_h(reg0, 3); - reg2 = __msa_srai_h(reg2, 3); - reg1 = __msa_srai_h(reg1, 2); - reg2 = __msa_slli_h(reg2, 11); - reg1 = __msa_slli_h(reg1, 5); - reg0 |= reg1; - dst0 = (v16u8)(reg0 | reg2); - ST_UB(dst0, dst_rgb); - src_argb += 32; - dst_rgb += 16; - } -} - -void ARGBShuffleRow_MSA(const uint8_t* src_argb, - uint8_t* dst_argb, - const uint8_t* shuffler, - int width) { - int x; - v16u8 src0, src1, dst0, dst1; - v16i8 vec0; - v16i8 shuffler_vec = {0, 0, 0, 0, 4, 4, 4, 4, 8, 8, 8, 8, 12, 12, 12, 12}; - int32_t val = LW((int32_t*)shuffler); - - vec0 = (v16i8)__msa_fill_w(val); - shuffler_vec += vec0; - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((v16u8*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((v16u8*)src_argb, 16); - dst0 = (v16u8)__msa_vshf_b(shuffler_vec, (v16i8)src0, (v16i8)src0); - dst1 = (v16u8)__msa_vshf_b(shuffler_vec, (v16i8)src1, (v16i8)src1); - ST_UB2(dst0, dst1, dst_argb, 16); - src_argb += 32; - dst_argb += 32; - } -} - -void ARGBShadeRow_MSA(const uint8_t* src_argb, - uint8_t* dst_argb, - int width, - uint32_t value) { - int x; - v16u8 src0, dst0; - v8u16 vec0, vec1; - v4u32 reg0, reg1, reg2, reg3, rgba_scale; - v8i16 zero = {0}; - - rgba_scale[0] = value; - rgba_scale = (v4u32)__msa_ilvr_b((v16i8)rgba_scale, (v16i8)rgba_scale); - rgba_scale = (v4u32)__msa_ilvr_h(zero, (v8i16)rgba_scale); - - for (x = 0; x < width; x += 4) { - src0 = (v16u8)__msa_ld_b((v16u8*)src_argb, 0); - vec0 = (v8u16)__msa_ilvr_b((v16i8)src0, (v16i8)src0); - vec1 = (v8u16)__msa_ilvl_b((v16i8)src0, (v16i8)src0); - reg0 = (v4u32)__msa_ilvr_h(zero, (v8i16)vec0); - reg1 = (v4u32)__msa_ilvl_h(zero, (v8i16)vec0); - reg2 = (v4u32)__msa_ilvr_h(zero, (v8i16)vec1); - reg3 = (v4u32)__msa_ilvl_h(zero, (v8i16)vec1); - reg0 *= rgba_scale; - reg1 *= rgba_scale; - reg2 *= rgba_scale; - reg3 *= rgba_scale; - reg0 = (v4u32)__msa_srai_w((v4i32)reg0, 24); - reg1 = (v4u32)__msa_srai_w((v4i32)reg1, 24); - reg2 = (v4u32)__msa_srai_w((v4i32)reg2, 24); - reg3 = (v4u32)__msa_srai_w((v4i32)reg3, 24); - vec0 = (v8u16)__msa_pckev_h((v8i16)reg1, (v8i16)reg0); - vec1 = (v8u16)__msa_pckev_h((v8i16)reg3, (v8i16)reg2); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst_argb); - src_argb += 16; - dst_argb += 16; - } -} - -void ARGBGrayRow_MSA(const uint8_t* src_argb, uint8_t* dst_argb, int width) { - int x; - v16u8 src0, src1, vec0, vec1, dst0, dst1; - v8u16 reg0; - v16u8 const_0x26 = (v16u8)__msa_ldi_h(0x26); - v16u8 const_0x4B0F = (v16u8)__msa_fill_h(0x4B0F); - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((v16u8*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((v16u8*)src_argb, 16); - vec0 = (v16u8)__msa_pckev_h((v8i16)src1, (v8i16)src0); - vec1 = (v16u8)__msa_pckod_h((v8i16)src1, (v8i16)src0); - reg0 = __msa_dotp_u_h(vec0, const_0x4B0F); - reg0 = __msa_dpadd_u_h(reg0, vec1, const_0x26); - reg0 = (v8u16)__msa_srari_h((v8i16)reg0, 7); - vec0 = (v16u8)__msa_ilvev_b((v16i8)reg0, (v16i8)reg0); - vec1 = (v16u8)__msa_ilvod_b((v16i8)vec1, (v16i8)vec0); - dst0 = (v16u8)__msa_ilvr_b((v16i8)vec1, (v16i8)vec0); - dst1 = (v16u8)__msa_ilvl_b((v16i8)vec1, (v16i8)vec0); - ST_UB2(dst0, dst1, dst_argb, 16); - src_argb += 32; - dst_argb += 32; - } -} - -void ARGBSepiaRow_MSA(uint8_t* dst_argb, int width) { - int x; - v16u8 src0, src1, dst0, dst1, vec0, vec1, vec2, vec3, vec4, vec5; - v8u16 reg0, reg1, reg2; - v16u8 const_0x4411 = (v16u8)__msa_fill_h(0x4411); - v16u8 const_0x23 = (v16u8)__msa_ldi_h(0x23); - v16u8 const_0x5816 = (v16u8)__msa_fill_h(0x5816); - v16u8 const_0x2D = (v16u8)__msa_ldi_h(0x2D); - v16u8 const_0x6218 = (v16u8)__msa_fill_h(0x6218); - v16u8 const_0x32 = (v16u8)__msa_ldi_h(0x32); - v8u16 const_0xFF = (v8u16)__msa_ldi_h(0xFF); - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((v16u8*)dst_argb, 0); - src1 = (v16u8)__msa_ld_b((v16u8*)dst_argb, 16); - vec0 = (v16u8)__msa_pckev_h((v8i16)src1, (v8i16)src0); - vec1 = (v16u8)__msa_pckod_h((v8i16)src1, (v8i16)src0); - vec3 = (v16u8)__msa_pckod_b((v16i8)vec1, (v16i8)vec1); - reg0 = (v8u16)__msa_dotp_u_h(vec0, const_0x4411); - reg1 = (v8u16)__msa_dotp_u_h(vec0, const_0x5816); - reg2 = (v8u16)__msa_dotp_u_h(vec0, const_0x6218); - reg0 = (v8u16)__msa_dpadd_u_h(reg0, vec1, const_0x23); - reg1 = (v8u16)__msa_dpadd_u_h(reg1, vec1, const_0x2D); - reg2 = (v8u16)__msa_dpadd_u_h(reg2, vec1, const_0x32); - reg0 = (v8u16)__msa_srai_h((v8i16)reg0, 7); - reg1 = (v8u16)__msa_srai_h((v8i16)reg1, 7); - reg2 = (v8u16)__msa_srai_h((v8i16)reg2, 7); - reg1 = (v8u16)__msa_min_u_h((v8u16)reg1, const_0xFF); - reg2 = (v8u16)__msa_min_u_h((v8u16)reg2, const_0xFF); - vec0 = (v16u8)__msa_pckev_b((v16i8)reg0, (v16i8)reg0); - vec1 = (v16u8)__msa_pckev_b((v16i8)reg1, (v16i8)reg1); - vec2 = (v16u8)__msa_pckev_b((v16i8)reg2, (v16i8)reg2); - vec4 = (v16u8)__msa_ilvr_b((v16i8)vec2, (v16i8)vec0); - vec5 = (v16u8)__msa_ilvr_b((v16i8)vec3, (v16i8)vec1); - dst0 = (v16u8)__msa_ilvr_b((v16i8)vec5, (v16i8)vec4); - dst1 = (v16u8)__msa_ilvl_b((v16i8)vec5, (v16i8)vec4); - ST_UB2(dst0, dst1, dst_argb, 16); - dst_argb += 32; - } -} - -void ARGB4444ToARGBRow_MSA(const uint8_t* src_argb4444, - uint8_t* dst_argb, - int width) { - int x; - v16u8 src0, src1; - v8u16 vec0, vec1, vec2, vec3; - v16u8 dst0, dst1, dst2, dst3; - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((v16u8*)src_argb4444, 0); - src1 = (v16u8)__msa_ld_b((v16u8*)src_argb4444, 16); - vec0 = (v8u16)__msa_andi_b(src0, 0x0F); - vec1 = (v8u16)__msa_andi_b(src1, 0x0F); - vec2 = (v8u16)__msa_andi_b(src0, 0xF0); - vec3 = (v8u16)__msa_andi_b(src1, 0xF0); - vec0 |= (v8u16)__msa_slli_b((v16i8)vec0, 4); - vec1 |= (v8u16)__msa_slli_b((v16i8)vec1, 4); - vec2 |= (v8u16)__msa_srli_b((v16i8)vec2, 4); - vec3 |= (v8u16)__msa_srli_b((v16i8)vec3, 4); - dst0 = (v16u8)__msa_ilvr_b((v16i8)vec2, (v16i8)vec0); - dst1 = (v16u8)__msa_ilvl_b((v16i8)vec2, (v16i8)vec0); - dst2 = (v16u8)__msa_ilvr_b((v16i8)vec3, (v16i8)vec1); - dst3 = (v16u8)__msa_ilvl_b((v16i8)vec3, (v16i8)vec1); - ST_UB4(dst0, dst1, dst2, dst3, dst_argb, 16); - src_argb4444 += 32; - dst_argb += 64; - } -} - -void ARGB1555ToARGBRow_MSA(const uint8_t* src_argb1555, - uint8_t* dst_argb, - int width) { - int x; - v8u16 src0, src1; - v8u16 vec0, vec1, vec2, vec3, vec4, vec5; - v16u8 reg0, reg1, reg2, reg3, reg4, reg5, reg6; - v16u8 dst0, dst1, dst2, dst3; - v8u16 const_0x1F = (v8u16)__msa_ldi_h(0x1F); - - for (x = 0; x < width; x += 16) { - src0 = (v8u16)__msa_ld_h((void*)src_argb1555, 0); - src1 = (v8u16)__msa_ld_h((void*)src_argb1555, 16); - vec0 = src0 & const_0x1F; - vec1 = src1 & const_0x1F; - src0 = (v8u16)__msa_srli_h((v8i16)src0, 5); - src1 = (v8u16)__msa_srli_h((v8i16)src1, 5); - vec2 = src0 & const_0x1F; - vec3 = src1 & const_0x1F; - src0 = (v8u16)__msa_srli_h((v8i16)src0, 5); - src1 = (v8u16)__msa_srli_h((v8i16)src1, 5); - vec4 = src0 & const_0x1F; - vec5 = src1 & const_0x1F; - src0 = (v8u16)__msa_srli_h((v8i16)src0, 5); - src1 = (v8u16)__msa_srli_h((v8i16)src1, 5); - reg0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - reg1 = (v16u8)__msa_pckev_b((v16i8)vec3, (v16i8)vec2); - reg2 = (v16u8)__msa_pckev_b((v16i8)vec5, (v16i8)vec4); - reg3 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - reg4 = (v16u8)__msa_slli_b((v16i8)reg0, 3); - reg5 = (v16u8)__msa_slli_b((v16i8)reg1, 3); - reg6 = (v16u8)__msa_slli_b((v16i8)reg2, 3); - reg4 |= (v16u8)__msa_srai_b((v16i8)reg0, 2); - reg5 |= (v16u8)__msa_srai_b((v16i8)reg1, 2); - reg6 |= (v16u8)__msa_srai_b((v16i8)reg2, 2); - reg3 = -reg3; - reg0 = (v16u8)__msa_ilvr_b((v16i8)reg6, (v16i8)reg4); - reg1 = (v16u8)__msa_ilvl_b((v16i8)reg6, (v16i8)reg4); - reg2 = (v16u8)__msa_ilvr_b((v16i8)reg3, (v16i8)reg5); - reg3 = (v16u8)__msa_ilvl_b((v16i8)reg3, (v16i8)reg5); - dst0 = (v16u8)__msa_ilvr_b((v16i8)reg2, (v16i8)reg0); - dst1 = (v16u8)__msa_ilvl_b((v16i8)reg2, (v16i8)reg0); - dst2 = (v16u8)__msa_ilvr_b((v16i8)reg3, (v16i8)reg1); - dst3 = (v16u8)__msa_ilvl_b((v16i8)reg3, (v16i8)reg1); - ST_UB4(dst0, dst1, dst2, dst3, dst_argb, 16); - src_argb1555 += 32; - dst_argb += 64; - } -} - -void RGB565ToARGBRow_MSA(const uint8_t* src_rgb565, - uint8_t* dst_argb, - int width) { - int x; - v8u16 src0, src1, vec0, vec1, vec2, vec3, vec4, vec5; - v8u16 reg0, reg1, reg2, reg3, reg4, reg5; - v16u8 res0, res1, res2, res3, dst0, dst1, dst2, dst3; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - v8u16 const_0x1F = (v8u16)__msa_ldi_h(0x1F); - v8u16 const_0x7E0 = (v8u16)__msa_fill_h(0x7E0); - v8u16 const_0xF800 = (v8u16)__msa_fill_h(0xF800); - - for (x = 0; x < width; x += 16) { - src0 = (v8u16)__msa_ld_h((void*)src_rgb565, 0); - src1 = (v8u16)__msa_ld_h((void*)src_rgb565, 16); - vec0 = src0 & const_0x1F; - vec1 = src0 & const_0x7E0; - vec2 = src0 & const_0xF800; - vec3 = src1 & const_0x1F; - vec4 = src1 & const_0x7E0; - vec5 = src1 & const_0xF800; - reg0 = (v8u16)__msa_slli_h((v8i16)vec0, 3); - reg1 = (v8u16)__msa_srli_h((v8i16)vec1, 3); - reg2 = (v8u16)__msa_srli_h((v8i16)vec2, 8); - reg3 = (v8u16)__msa_slli_h((v8i16)vec3, 3); - reg4 = (v8u16)__msa_srli_h((v8i16)vec4, 3); - reg5 = (v8u16)__msa_srli_h((v8i16)vec5, 8); - reg0 |= (v8u16)__msa_srli_h((v8i16)vec0, 2); - reg1 |= (v8u16)__msa_srli_h((v8i16)vec1, 9); - reg2 |= (v8u16)__msa_srli_h((v8i16)vec2, 13); - reg3 |= (v8u16)__msa_srli_h((v8i16)vec3, 2); - reg4 |= (v8u16)__msa_srli_h((v8i16)vec4, 9); - reg5 |= (v8u16)__msa_srli_h((v8i16)vec5, 13); - res0 = (v16u8)__msa_ilvev_b((v16i8)reg2, (v16i8)reg0); - res1 = (v16u8)__msa_ilvev_b((v16i8)alpha, (v16i8)reg1); - res2 = (v16u8)__msa_ilvev_b((v16i8)reg5, (v16i8)reg3); - res3 = (v16u8)__msa_ilvev_b((v16i8)alpha, (v16i8)reg4); - dst0 = (v16u8)__msa_ilvr_b((v16i8)res1, (v16i8)res0); - dst1 = (v16u8)__msa_ilvl_b((v16i8)res1, (v16i8)res0); - dst2 = (v16u8)__msa_ilvr_b((v16i8)res3, (v16i8)res2); - dst3 = (v16u8)__msa_ilvl_b((v16i8)res3, (v16i8)res2); - ST_UB4(dst0, dst1, dst2, dst3, dst_argb, 16); - src_rgb565 += 32; - dst_argb += 64; - } -} - -void RGB24ToARGBRow_MSA(const uint8_t* src_rgb24, - uint8_t* dst_argb, - int width) { - int x; - v16u8 src0, src1, src2; - v16u8 vec0, vec1, vec2; - v16u8 dst0, dst1, dst2, dst3; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - v16i8 shuffler = {0, 1, 2, 16, 3, 4, 5, 17, 6, 7, 8, 18, 9, 10, 11, 19}; - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_rgb24, 0); - src1 = (v16u8)__msa_ld_b((void*)src_rgb24, 16); - src2 = (v16u8)__msa_ld_b((void*)src_rgb24, 32); - vec0 = (v16u8)__msa_sldi_b((v16i8)src1, (v16i8)src0, 12); - vec1 = (v16u8)__msa_sldi_b((v16i8)src2, (v16i8)src1, 8); - vec2 = (v16u8)__msa_sldi_b((v16i8)src2, (v16i8)src2, 4); - dst0 = (v16u8)__msa_vshf_b(shuffler, (v16i8)alpha, (v16i8)src0); - dst1 = (v16u8)__msa_vshf_b(shuffler, (v16i8)alpha, (v16i8)vec0); - dst2 = (v16u8)__msa_vshf_b(shuffler, (v16i8)alpha, (v16i8)vec1); - dst3 = (v16u8)__msa_vshf_b(shuffler, (v16i8)alpha, (v16i8)vec2); - ST_UB4(dst0, dst1, dst2, dst3, dst_argb, 16); - src_rgb24 += 48; - dst_argb += 64; - } -} - -void RAWToARGBRow_MSA(const uint8_t* src_raw, uint8_t* dst_argb, int width) { - int x; - v16u8 src0, src1, src2; - v16u8 vec0, vec1, vec2; - v16u8 dst0, dst1, dst2, dst3; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - v16i8 mask = {2, 1, 0, 16, 5, 4, 3, 17, 8, 7, 6, 18, 11, 10, 9, 19}; - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_raw, 0); - src1 = (v16u8)__msa_ld_b((void*)src_raw, 16); - src2 = (v16u8)__msa_ld_b((void*)src_raw, 32); - vec0 = (v16u8)__msa_sldi_b((v16i8)src1, (v16i8)src0, 12); - vec1 = (v16u8)__msa_sldi_b((v16i8)src2, (v16i8)src1, 8); - vec2 = (v16u8)__msa_sldi_b((v16i8)src2, (v16i8)src2, 4); - dst0 = (v16u8)__msa_vshf_b(mask, (v16i8)alpha, (v16i8)src0); - dst1 = (v16u8)__msa_vshf_b(mask, (v16i8)alpha, (v16i8)vec0); - dst2 = (v16u8)__msa_vshf_b(mask, (v16i8)alpha, (v16i8)vec1); - dst3 = (v16u8)__msa_vshf_b(mask, (v16i8)alpha, (v16i8)vec2); - ST_UB4(dst0, dst1, dst2, dst3, dst_argb, 16); - src_raw += 48; - dst_argb += 64; - } -} - -void ARGB1555ToYRow_MSA(const uint8_t* src_argb1555, - uint8_t* dst_y, - int width) { - int x; - v8u16 src0, src1, vec0, vec1, vec2, vec3, vec4, vec5; - v8u16 reg0, reg1, reg2, reg3, reg4, reg5; - v16u8 dst0; - v8u16 const_0x19 = (v8u16)__msa_ldi_h(0x19); - v8u16 const_0x81 = (v8u16)__msa_ldi_h(0x81); - v8u16 const_0x42 = (v8u16)__msa_ldi_h(0x42); - v8u16 const_0x1F = (v8u16)__msa_ldi_h(0x1F); - v8u16 const_0x1080 = (v8u16)__msa_fill_h(0x1080); - - for (x = 0; x < width; x += 16) { - src0 = (v8u16)__msa_ld_b((void*)src_argb1555, 0); - src1 = (v8u16)__msa_ld_b((void*)src_argb1555, 16); - vec0 = src0 & const_0x1F; - vec1 = src1 & const_0x1F; - src0 = (v8u16)__msa_srai_h((v8i16)src0, 5); - src1 = (v8u16)__msa_srai_h((v8i16)src1, 5); - vec2 = src0 & const_0x1F; - vec3 = src1 & const_0x1F; - src0 = (v8u16)__msa_srai_h((v8i16)src0, 5); - src1 = (v8u16)__msa_srai_h((v8i16)src1, 5); - vec4 = src0 & const_0x1F; - vec5 = src1 & const_0x1F; - reg0 = (v8u16)__msa_slli_h((v8i16)vec0, 3); - reg1 = (v8u16)__msa_slli_h((v8i16)vec1, 3); - reg0 |= (v8u16)__msa_srai_h((v8i16)vec0, 2); - reg1 |= (v8u16)__msa_srai_h((v8i16)vec1, 2); - reg2 = (v8u16)__msa_slli_h((v8i16)vec2, 3); - reg3 = (v8u16)__msa_slli_h((v8i16)vec3, 3); - reg2 |= (v8u16)__msa_srai_h((v8i16)vec2, 2); - reg3 |= (v8u16)__msa_srai_h((v8i16)vec3, 2); - reg4 = (v8u16)__msa_slli_h((v8i16)vec4, 3); - reg5 = (v8u16)__msa_slli_h((v8i16)vec5, 3); - reg4 |= (v8u16)__msa_srai_h((v8i16)vec4, 2); - reg5 |= (v8u16)__msa_srai_h((v8i16)vec5, 2); - reg0 *= const_0x19; - reg1 *= const_0x19; - reg2 *= const_0x81; - reg3 *= const_0x81; - reg4 *= const_0x42; - reg5 *= const_0x42; - reg0 += reg2; - reg1 += reg3; - reg0 += reg4; - reg1 += reg5; - reg0 += const_0x1080; - reg1 += const_0x1080; - reg0 = (v8u16)__msa_srai_h((v8i16)reg0, 8); - reg1 = (v8u16)__msa_srai_h((v8i16)reg1, 8); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg1, (v16i8)reg0); - ST_UB(dst0, dst_y); - src_argb1555 += 32; - dst_y += 16; - } -} - -void RGB565ToYRow_MSA(const uint8_t* src_rgb565, uint8_t* dst_y, int width) { - int x; - v8u16 src0, src1, vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7; - v8u16 reg0, reg1, reg2, reg3, reg4, reg5; - v4u32 res0, res1, res2, res3; - v16u8 dst0; - v4u32 const_0x810019 = (v4u32)__msa_fill_w(0x810019); - v4u32 const_0x010042 = (v4u32)__msa_fill_w(0x010042); - v8i16 const_0x1080 = __msa_fill_h(0x1080); - v8u16 const_0x1F = (v8u16)__msa_ldi_h(0x1F); - v8u16 const_0x7E0 = (v8u16)__msa_fill_h(0x7E0); - v8u16 const_0xF800 = (v8u16)__msa_fill_h(0xF800); - - for (x = 0; x < width; x += 16) { - src0 = (v8u16)__msa_ld_b((void*)src_rgb565, 0); - src1 = (v8u16)__msa_ld_b((void*)src_rgb565, 16); - vec0 = src0 & const_0x1F; - vec1 = src0 & const_0x7E0; - vec2 = src0 & const_0xF800; - vec3 = src1 & const_0x1F; - vec4 = src1 & const_0x7E0; - vec5 = src1 & const_0xF800; - reg0 = (v8u16)__msa_slli_h((v8i16)vec0, 3); - reg1 = (v8u16)__msa_srli_h((v8i16)vec1, 3); - reg2 = (v8u16)__msa_srli_h((v8i16)vec2, 8); - reg3 = (v8u16)__msa_slli_h((v8i16)vec3, 3); - reg4 = (v8u16)__msa_srli_h((v8i16)vec4, 3); - reg5 = (v8u16)__msa_srli_h((v8i16)vec5, 8); - reg0 |= (v8u16)__msa_srli_h((v8i16)vec0, 2); - reg1 |= (v8u16)__msa_srli_h((v8i16)vec1, 9); - reg2 |= (v8u16)__msa_srli_h((v8i16)vec2, 13); - reg3 |= (v8u16)__msa_srli_h((v8i16)vec3, 2); - reg4 |= (v8u16)__msa_srli_h((v8i16)vec4, 9); - reg5 |= (v8u16)__msa_srli_h((v8i16)vec5, 13); - vec0 = (v8u16)__msa_ilvr_h((v8i16)reg1, (v8i16)reg0); - vec1 = (v8u16)__msa_ilvl_h((v8i16)reg1, (v8i16)reg0); - vec2 = (v8u16)__msa_ilvr_h((v8i16)reg4, (v8i16)reg3); - vec3 = (v8u16)__msa_ilvl_h((v8i16)reg4, (v8i16)reg3); - vec4 = (v8u16)__msa_ilvr_h(const_0x1080, (v8i16)reg2); - vec5 = (v8u16)__msa_ilvl_h(const_0x1080, (v8i16)reg2); - vec6 = (v8u16)__msa_ilvr_h(const_0x1080, (v8i16)reg5); - vec7 = (v8u16)__msa_ilvl_h(const_0x1080, (v8i16)reg5); - res0 = __msa_dotp_u_w(vec0, (v8u16)const_0x810019); - res1 = __msa_dotp_u_w(vec1, (v8u16)const_0x810019); - res2 = __msa_dotp_u_w(vec2, (v8u16)const_0x810019); - res3 = __msa_dotp_u_w(vec3, (v8u16)const_0x810019); - res0 = __msa_dpadd_u_w(res0, vec4, (v8u16)const_0x010042); - res1 = __msa_dpadd_u_w(res1, vec5, (v8u16)const_0x010042); - res2 = __msa_dpadd_u_w(res2, vec6, (v8u16)const_0x010042); - res3 = __msa_dpadd_u_w(res3, vec7, (v8u16)const_0x010042); - res0 = (v4u32)__msa_srai_w((v4i32)res0, 8); - res1 = (v4u32)__msa_srai_w((v4i32)res1, 8); - res2 = (v4u32)__msa_srai_w((v4i32)res2, 8); - res3 = (v4u32)__msa_srai_w((v4i32)res3, 8); - vec0 = (v8u16)__msa_pckev_h((v8i16)res1, (v8i16)res0); - vec1 = (v8u16)__msa_pckev_h((v8i16)res3, (v8i16)res2); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst_y); - src_rgb565 += 32; - dst_y += 16; - } -} - -void RGB24ToYRow_MSA(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - int x; - v16u8 src0, src1, src2, reg0, reg1, reg2, reg3, dst0; - v8u16 vec0, vec1, vec2, vec3; - v8u16 const_0x8119 = (v8u16)__msa_fill_h(0x8119); - v8u16 const_0x42 = (v8u16)__msa_fill_h(0x42); - v8u16 const_0x1080 = (v8u16)__msa_fill_h(0x1080); - v16i8 mask0 = {0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11, 12}; - v16i8 mask1 = {12, 13, 14, 15, 15, 16, 17, 18, - 18, 19, 20, 21, 21, 22, 23, 24}; - v16i8 mask2 = {8, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 17, 17, 18, 19, 20}; - v16i8 mask3 = {4, 5, 6, 7, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15, 16}; - v16i8 zero = {0}; - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb0, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb0, 32); - reg0 = (v16u8)__msa_vshf_b(mask0, zero, (v16i8)src0); - reg1 = (v16u8)__msa_vshf_b(mask1, (v16i8)src1, (v16i8)src0); - reg2 = (v16u8)__msa_vshf_b(mask2, (v16i8)src2, (v16i8)src1); - reg3 = (v16u8)__msa_vshf_b(mask3, zero, (v16i8)src2); - vec0 = (v8u16)__msa_pckev_h((v8i16)reg1, (v8i16)reg0); - vec1 = (v8u16)__msa_pckev_h((v8i16)reg3, (v8i16)reg2); - vec2 = (v8u16)__msa_pckod_h((v8i16)reg1, (v8i16)reg0); - vec3 = (v8u16)__msa_pckod_h((v8i16)reg3, (v8i16)reg2); - vec0 = __msa_dotp_u_h((v16u8)vec0, (v16u8)const_0x8119); - vec1 = __msa_dotp_u_h((v16u8)vec1, (v16u8)const_0x8119); - vec0 = __msa_dpadd_u_h(vec0, (v16u8)vec2, (v16u8)const_0x42); - vec1 = __msa_dpadd_u_h(vec1, (v16u8)vec3, (v16u8)const_0x42); - vec0 += const_0x1080; - vec1 += const_0x1080; - vec0 = (v8u16)__msa_srai_h((v8i16)vec0, 8); - vec1 = (v8u16)__msa_srai_h((v8i16)vec1, 8); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst_y); - src_argb0 += 48; - dst_y += 16; - } -} - -void RAWToYRow_MSA(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - int x; - v16u8 src0, src1, src2, reg0, reg1, reg2, reg3, dst0; - v8u16 vec0, vec1, vec2, vec3; - v8u16 const_0x8142 = (v8u16)__msa_fill_h(0x8142); - v8u16 const_0x19 = (v8u16)__msa_fill_h(0x19); - v8u16 const_0x1080 = (v8u16)__msa_fill_h(0x1080); - v16i8 mask0 = {0, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11, 12}; - v16i8 mask1 = {12, 13, 14, 15, 15, 16, 17, 18, - 18, 19, 20, 21, 21, 22, 23, 24}; - v16i8 mask2 = {8, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 17, 17, 18, 19, 20}; - v16i8 mask3 = {4, 5, 6, 7, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15, 16}; - v16i8 zero = {0}; - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb0, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb0, 32); - reg0 = (v16u8)__msa_vshf_b(mask0, zero, (v16i8)src0); - reg1 = (v16u8)__msa_vshf_b(mask1, (v16i8)src1, (v16i8)src0); - reg2 = (v16u8)__msa_vshf_b(mask2, (v16i8)src2, (v16i8)src1); - reg3 = (v16u8)__msa_vshf_b(mask3, zero, (v16i8)src2); - vec0 = (v8u16)__msa_pckev_h((v8i16)reg1, (v8i16)reg0); - vec1 = (v8u16)__msa_pckev_h((v8i16)reg3, (v8i16)reg2); - vec2 = (v8u16)__msa_pckod_h((v8i16)reg1, (v8i16)reg0); - vec3 = (v8u16)__msa_pckod_h((v8i16)reg3, (v8i16)reg2); - vec0 = __msa_dotp_u_h((v16u8)vec0, (v16u8)const_0x8142); - vec1 = __msa_dotp_u_h((v16u8)vec1, (v16u8)const_0x8142); - vec0 = __msa_dpadd_u_h(vec0, (v16u8)vec2, (v16u8)const_0x19); - vec1 = __msa_dpadd_u_h(vec1, (v16u8)vec3, (v16u8)const_0x19); - vec0 += const_0x1080; - vec1 += const_0x1080; - vec0 = (v8u16)__msa_srai_h((v8i16)vec0, 8); - vec1 = (v8u16)__msa_srai_h((v8i16)vec1, 8); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst_y); - src_argb0 += 48; - dst_y += 16; - } -} - -void ARGB1555ToUVRow_MSA(const uint8_t* src_argb1555, - int src_stride_argb1555, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - const uint16_t* s = (const uint16_t*)src_argb1555; - const uint16_t* t = (const uint16_t*)(src_argb1555 + src_stride_argb1555); - int64_t res0, res1; - v8u16 src0, src1, src2, src3, reg0, reg1, reg2, reg3; - v8u16 vec0, vec1, vec2, vec3, vec4, vec5, vec6; - v16u8 dst0; - v8u16 const_0x70 = (v8u16)__msa_ldi_h(0x70); - v8u16 const_0x4A = (v8u16)__msa_ldi_h(0x4A); - v8u16 const_0x26 = (v8u16)__msa_ldi_h(0x26); - v8u16 const_0x5E = (v8u16)__msa_ldi_h(0x5E); - v8u16 const_0x12 = (v8u16)__msa_ldi_h(0x12); - v8u16 const_0x8080 = (v8u16)__msa_fill_h(0x8080); - v8u16 const_0x1F = (v8u16)__msa_ldi_h(0x1F); - - for (x = 0; x < width; x += 16) { - src0 = (v8u16)__msa_ld_b((void*)s, 0); - src1 = (v8u16)__msa_ld_b((void*)s, 16); - src2 = (v8u16)__msa_ld_b((void*)t, 0); - src3 = (v8u16)__msa_ld_b((void*)t, 16); - vec0 = src0 & const_0x1F; - vec1 = src1 & const_0x1F; - vec0 += src2 & const_0x1F; - vec1 += src3 & const_0x1F; - vec0 = (v8u16)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - src0 = (v8u16)__msa_srai_h((v8i16)src0, 5); - src1 = (v8u16)__msa_srai_h((v8i16)src1, 5); - src2 = (v8u16)__msa_srai_h((v8i16)src2, 5); - src3 = (v8u16)__msa_srai_h((v8i16)src3, 5); - vec2 = src0 & const_0x1F; - vec3 = src1 & const_0x1F; - vec2 += src2 & const_0x1F; - vec3 += src3 & const_0x1F; - vec2 = (v8u16)__msa_pckev_b((v16i8)vec3, (v16i8)vec2); - src0 = (v8u16)__msa_srai_h((v8i16)src0, 5); - src1 = (v8u16)__msa_srai_h((v8i16)src1, 5); - src2 = (v8u16)__msa_srai_h((v8i16)src2, 5); - src3 = (v8u16)__msa_srai_h((v8i16)src3, 5); - vec4 = src0 & const_0x1F; - vec5 = src1 & const_0x1F; - vec4 += src2 & const_0x1F; - vec5 += src3 & const_0x1F; - vec4 = (v8u16)__msa_pckev_b((v16i8)vec5, (v16i8)vec4); - vec0 = __msa_hadd_u_h((v16u8)vec0, (v16u8)vec0); - vec2 = __msa_hadd_u_h((v16u8)vec2, (v16u8)vec2); - vec4 = __msa_hadd_u_h((v16u8)vec4, (v16u8)vec4); - vec6 = (v8u16)__msa_slli_h((v8i16)vec0, 1); - vec6 |= (v8u16)__msa_srai_h((v8i16)vec0, 6); - vec0 = (v8u16)__msa_slli_h((v8i16)vec2, 1); - vec0 |= (v8u16)__msa_srai_h((v8i16)vec2, 6); - vec2 = (v8u16)__msa_slli_h((v8i16)vec4, 1); - vec2 |= (v8u16)__msa_srai_h((v8i16)vec4, 6); - reg0 = vec6 * const_0x70; - reg1 = vec0 * const_0x4A; - reg2 = vec2 * const_0x70; - reg3 = vec0 * const_0x5E; - reg0 += const_0x8080; - reg1 += vec2 * const_0x26; - reg2 += const_0x8080; - reg3 += vec6 * const_0x12; - reg0 -= reg1; - reg2 -= reg3; - reg0 = (v8u16)__msa_srai_h((v8i16)reg0, 8); - reg2 = (v8u16)__msa_srai_h((v8i16)reg2, 8); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg2, (v16i8)reg0); - res0 = __msa_copy_u_d((v2i64)dst0, 0); - res1 = __msa_copy_u_d((v2i64)dst0, 1); - SD(res0, dst_u); - SD(res1, dst_v); - s += 16; - t += 16; - dst_u += 8; - dst_v += 8; - } -} - -void RGB565ToUVRow_MSA(const uint8_t* src_rgb565, - int src_stride_rgb565, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - const uint16_t* s = (const uint16_t*)src_rgb565; - const uint16_t* t = (const uint16_t*)(src_rgb565 + src_stride_rgb565); - int64_t res0, res1; - v8u16 src0, src1, src2, src3, reg0, reg1, reg2, reg3; - v8u16 vec0, vec1, vec2, vec3, vec4, vec5; - v16u8 dst0; - v8u16 const_0x70 = (v8u16)__msa_ldi_h(0x70); - v8u16 const_0x4A = (v8u16)__msa_ldi_h(0x4A); - v8u16 const_0x26 = (v8u16)__msa_ldi_h(0x26); - v8u16 const_0x5E = (v8u16)__msa_ldi_h(0x5E); - v8u16 const_0x12 = (v8u16)__msa_ldi_h(0x12); - v8u16 const_32896 = (v8u16)__msa_fill_h(0x8080); - v8u16 const_0x1F = (v8u16)__msa_ldi_h(0x1F); - v8u16 const_0x3F = (v8u16)__msa_fill_h(0x3F); - - for (x = 0; x < width; x += 16) { - src0 = (v8u16)__msa_ld_b((void*)s, 0); - src1 = (v8u16)__msa_ld_b((void*)s, 16); - src2 = (v8u16)__msa_ld_b((void*)t, 0); - src3 = (v8u16)__msa_ld_b((void*)t, 16); - vec0 = src0 & const_0x1F; - vec1 = src1 & const_0x1F; - vec0 += src2 & const_0x1F; - vec1 += src3 & const_0x1F; - vec0 = (v8u16)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - src0 = (v8u16)__msa_srai_h((v8i16)src0, 5); - src1 = (v8u16)__msa_srai_h((v8i16)src1, 5); - src2 = (v8u16)__msa_srai_h((v8i16)src2, 5); - src3 = (v8u16)__msa_srai_h((v8i16)src3, 5); - vec2 = src0 & const_0x3F; - vec3 = src1 & const_0x3F; - vec2 += src2 & const_0x3F; - vec3 += src3 & const_0x3F; - vec1 = (v8u16)__msa_pckev_b((v16i8)vec3, (v16i8)vec2); - src0 = (v8u16)__msa_srai_h((v8i16)src0, 6); - src1 = (v8u16)__msa_srai_h((v8i16)src1, 6); - src2 = (v8u16)__msa_srai_h((v8i16)src2, 6); - src3 = (v8u16)__msa_srai_h((v8i16)src3, 6); - vec4 = src0 & const_0x1F; - vec5 = src1 & const_0x1F; - vec4 += src2 & const_0x1F; - vec5 += src3 & const_0x1F; - vec2 = (v8u16)__msa_pckev_b((v16i8)vec5, (v16i8)vec4); - vec0 = __msa_hadd_u_h((v16u8)vec0, (v16u8)vec0); - vec1 = __msa_hadd_u_h((v16u8)vec1, (v16u8)vec1); - vec2 = __msa_hadd_u_h((v16u8)vec2, (v16u8)vec2); - vec3 = (v8u16)__msa_slli_h((v8i16)vec0, 1); - vec3 |= (v8u16)__msa_srai_h((v8i16)vec0, 6); - vec4 = (v8u16)__msa_slli_h((v8i16)vec2, 1); - vec4 |= (v8u16)__msa_srai_h((v8i16)vec2, 6); - reg0 = vec3 * const_0x70; - reg1 = vec1 * const_0x4A; - reg2 = vec4 * const_0x70; - reg3 = vec1 * const_0x5E; - reg0 += const_32896; - reg1 += vec4 * const_0x26; - reg2 += const_32896; - reg3 += vec3 * const_0x12; - reg0 -= reg1; - reg2 -= reg3; - reg0 = (v8u16)__msa_srai_h((v8i16)reg0, 8); - reg2 = (v8u16)__msa_srai_h((v8i16)reg2, 8); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg2, (v16i8)reg0); - res0 = __msa_copy_u_d((v2i64)dst0, 0); - res1 = __msa_copy_u_d((v2i64)dst0, 1); - SD(res0, dst_u); - SD(res1, dst_v); - s += 16; - t += 16; - dst_u += 8; - dst_v += 8; - } -} - -void RGB24ToUVRow_MSA(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - const uint8_t* s = src_rgb0; - const uint8_t* t = src_rgb0 + src_stride_rgb; - int64_t res0, res1; - v16u8 src0, src1, src2, src3, src4, src5, src6, src7; - v16u8 inp0, inp1, inp2, inp3, inp4, inp5; - v8u16 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7; - v8i16 reg0, reg1, reg2, reg3; - v16u8 dst0; - v8u16 const_0x70 = (v8u16)__msa_fill_h(0x70); - v8u16 const_0x4A = (v8u16)__msa_fill_h(0x4A); - v8u16 const_0x26 = (v8u16)__msa_fill_h(0x26); - v8u16 const_0x5E = (v8u16)__msa_fill_h(0x5E); - v8u16 const_0x12 = (v8u16)__msa_fill_h(0x12); - v8u16 const_0x8080 = (v8u16)__msa_fill_h(0x8080); - v16i8 mask = {0, 1, 2, 16, 3, 4, 5, 17, 6, 7, 8, 18, 9, 10, 11, 19}; - v16i8 zero = {0}; - - for (x = 0; x < width; x += 16) { - inp0 = (v16u8)__msa_ld_b((void*)s, 0); - inp1 = (v16u8)__msa_ld_b((void*)s, 16); - inp2 = (v16u8)__msa_ld_b((void*)s, 32); - inp3 = (v16u8)__msa_ld_b((void*)t, 0); - inp4 = (v16u8)__msa_ld_b((void*)t, 16); - inp5 = (v16u8)__msa_ld_b((void*)t, 32); - src1 = (v16u8)__msa_sldi_b((v16i8)inp1, (v16i8)inp0, 12); - src5 = (v16u8)__msa_sldi_b((v16i8)inp4, (v16i8)inp3, 12); - src2 = (v16u8)__msa_sldi_b((v16i8)inp2, (v16i8)inp1, 8); - src6 = (v16u8)__msa_sldi_b((v16i8)inp5, (v16i8)inp4, 8); - src3 = (v16u8)__msa_sldi_b((v16i8)inp2, (v16i8)inp2, 4); - src7 = (v16u8)__msa_sldi_b((v16i8)inp5, (v16i8)inp5, 4); - src0 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)inp0); - src1 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src1); - src2 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src2); - src3 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src3); - src4 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)inp3); - src5 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src5); - src6 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src6); - src7 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src7); - vec0 = (v8u16)__msa_ilvr_b((v16i8)src4, (v16i8)src0); - vec1 = (v8u16)__msa_ilvl_b((v16i8)src4, (v16i8)src0); - vec2 = (v8u16)__msa_ilvr_b((v16i8)src5, (v16i8)src1); - vec3 = (v8u16)__msa_ilvl_b((v16i8)src5, (v16i8)src1); - vec4 = (v8u16)__msa_ilvr_b((v16i8)src6, (v16i8)src2); - vec5 = (v8u16)__msa_ilvl_b((v16i8)src6, (v16i8)src2); - vec6 = (v8u16)__msa_ilvr_b((v16i8)src7, (v16i8)src3); - vec7 = (v8u16)__msa_ilvl_b((v16i8)src7, (v16i8)src3); - vec0 = (v8u16)__msa_hadd_u_h((v16u8)vec0, (v16u8)vec0); - vec1 = (v8u16)__msa_hadd_u_h((v16u8)vec1, (v16u8)vec1); - vec2 = (v8u16)__msa_hadd_u_h((v16u8)vec2, (v16u8)vec2); - vec3 = (v8u16)__msa_hadd_u_h((v16u8)vec3, (v16u8)vec3); - vec4 = (v8u16)__msa_hadd_u_h((v16u8)vec4, (v16u8)vec4); - vec5 = (v8u16)__msa_hadd_u_h((v16u8)vec5, (v16u8)vec5); - vec6 = (v8u16)__msa_hadd_u_h((v16u8)vec6, (v16u8)vec6); - vec7 = (v8u16)__msa_hadd_u_h((v16u8)vec7, (v16u8)vec7); - reg0 = (v8i16)__msa_pckev_d((v2i64)vec1, (v2i64)vec0); - reg1 = (v8i16)__msa_pckev_d((v2i64)vec3, (v2i64)vec2); - reg2 = (v8i16)__msa_pckev_d((v2i64)vec5, (v2i64)vec4); - reg3 = (v8i16)__msa_pckev_d((v2i64)vec7, (v2i64)vec6); - reg0 += (v8i16)__msa_pckod_d((v2i64)vec1, (v2i64)vec0); - reg1 += (v8i16)__msa_pckod_d((v2i64)vec3, (v2i64)vec2); - reg2 += (v8i16)__msa_pckod_d((v2i64)vec5, (v2i64)vec4); - reg3 += (v8i16)__msa_pckod_d((v2i64)vec7, (v2i64)vec6); - reg0 = __msa_srai_h((v8i16)reg0, 2); - reg1 = __msa_srai_h((v8i16)reg1, 2); - reg2 = __msa_srai_h((v8i16)reg2, 2); - reg3 = __msa_srai_h((v8i16)reg3, 2); - vec4 = (v8u16)__msa_pckev_h(reg1, reg0); - vec5 = (v8u16)__msa_pckev_h(reg3, reg2); - vec6 = (v8u16)__msa_pckod_h(reg1, reg0); - vec7 = (v8u16)__msa_pckod_h(reg3, reg2); - vec0 = (v8u16)__msa_pckev_h((v8i16)vec5, (v8i16)vec4); - vec1 = (v8u16)__msa_pckev_h((v8i16)vec7, (v8i16)vec6); - vec2 = (v8u16)__msa_pckod_h((v8i16)vec5, (v8i16)vec4); - vec3 = vec0 * const_0x70; - vec4 = vec1 * const_0x4A; - vec5 = vec2 * const_0x26; - vec2 *= const_0x70; - vec1 *= const_0x5E; - vec0 *= const_0x12; - reg0 = __msa_subv_h((v8i16)vec3, (v8i16)vec4); - reg1 = __msa_subv_h((v8i16)const_0x8080, (v8i16)vec5); - reg2 = __msa_subv_h((v8i16)vec2, (v8i16)vec1); - reg3 = __msa_subv_h((v8i16)const_0x8080, (v8i16)vec0); - reg0 += reg1; - reg2 += reg3; - reg0 = __msa_srai_h(reg0, 8); - reg2 = __msa_srai_h(reg2, 8); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg2, (v16i8)reg0); - res0 = __msa_copy_u_d((v2i64)dst0, 0); - res1 = __msa_copy_u_d((v2i64)dst0, 1); - SD(res0, dst_u); - SD(res1, dst_v); - t += 48; - s += 48; - dst_u += 8; - dst_v += 8; - } -} - -void RAWToUVRow_MSA(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - const uint8_t* s = src_rgb0; - const uint8_t* t = src_rgb0 + src_stride_rgb; - int64_t res0, res1; - v16u8 inp0, inp1, inp2, inp3, inp4, inp5; - v16u8 src0, src1, src2, src3, src4, src5, src6, src7; - v8u16 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7; - v8i16 reg0, reg1, reg2, reg3; - v16u8 dst0; - v8u16 const_0x70 = (v8u16)__msa_fill_h(0x70); - v8u16 const_0x4A = (v8u16)__msa_fill_h(0x4A); - v8u16 const_0x26 = (v8u16)__msa_fill_h(0x26); - v8u16 const_0x5E = (v8u16)__msa_fill_h(0x5E); - v8u16 const_0x12 = (v8u16)__msa_fill_h(0x12); - v8u16 const_0x8080 = (v8u16)__msa_fill_h(0x8080); - v16i8 mask = {0, 1, 2, 16, 3, 4, 5, 17, 6, 7, 8, 18, 9, 10, 11, 19}; - v16i8 zero = {0}; - - for (x = 0; x < width; x += 16) { - inp0 = (v16u8)__msa_ld_b((void*)s, 0); - inp1 = (v16u8)__msa_ld_b((void*)s, 16); - inp2 = (v16u8)__msa_ld_b((void*)s, 32); - inp3 = (v16u8)__msa_ld_b((void*)t, 0); - inp4 = (v16u8)__msa_ld_b((void*)t, 16); - inp5 = (v16u8)__msa_ld_b((void*)t, 32); - src1 = (v16u8)__msa_sldi_b((v16i8)inp1, (v16i8)inp0, 12); - src5 = (v16u8)__msa_sldi_b((v16i8)inp4, (v16i8)inp3, 12); - src2 = (v16u8)__msa_sldi_b((v16i8)inp2, (v16i8)inp1, 8); - src6 = (v16u8)__msa_sldi_b((v16i8)inp5, (v16i8)inp4, 8); - src3 = (v16u8)__msa_sldi_b((v16i8)inp2, (v16i8)inp2, 4); - src7 = (v16u8)__msa_sldi_b((v16i8)inp5, (v16i8)inp5, 4); - src0 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)inp0); - src1 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src1); - src2 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src2); - src3 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src3); - src4 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)inp3); - src5 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src5); - src6 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src6); - src7 = (v16u8)__msa_vshf_b(mask, (v16i8)zero, (v16i8)src7); - vec0 = (v8u16)__msa_ilvr_b((v16i8)src4, (v16i8)src0); - vec1 = (v8u16)__msa_ilvl_b((v16i8)src4, (v16i8)src0); - vec2 = (v8u16)__msa_ilvr_b((v16i8)src5, (v16i8)src1); - vec3 = (v8u16)__msa_ilvl_b((v16i8)src5, (v16i8)src1); - vec4 = (v8u16)__msa_ilvr_b((v16i8)src6, (v16i8)src2); - vec5 = (v8u16)__msa_ilvl_b((v16i8)src6, (v16i8)src2); - vec6 = (v8u16)__msa_ilvr_b((v16i8)src7, (v16i8)src3); - vec7 = (v8u16)__msa_ilvl_b((v16i8)src7, (v16i8)src3); - vec0 = (v8u16)__msa_hadd_u_h((v16u8)vec0, (v16u8)vec0); - vec1 = (v8u16)__msa_hadd_u_h((v16u8)vec1, (v16u8)vec1); - vec2 = (v8u16)__msa_hadd_u_h((v16u8)vec2, (v16u8)vec2); - vec3 = (v8u16)__msa_hadd_u_h((v16u8)vec3, (v16u8)vec3); - vec4 = (v8u16)__msa_hadd_u_h((v16u8)vec4, (v16u8)vec4); - vec5 = (v8u16)__msa_hadd_u_h((v16u8)vec5, (v16u8)vec5); - vec6 = (v8u16)__msa_hadd_u_h((v16u8)vec6, (v16u8)vec6); - vec7 = (v8u16)__msa_hadd_u_h((v16u8)vec7, (v16u8)vec7); - reg0 = (v8i16)__msa_pckev_d((v2i64)vec1, (v2i64)vec0); - reg1 = (v8i16)__msa_pckev_d((v2i64)vec3, (v2i64)vec2); - reg2 = (v8i16)__msa_pckev_d((v2i64)vec5, (v2i64)vec4); - reg3 = (v8i16)__msa_pckev_d((v2i64)vec7, (v2i64)vec6); - reg0 += (v8i16)__msa_pckod_d((v2i64)vec1, (v2i64)vec0); - reg1 += (v8i16)__msa_pckod_d((v2i64)vec3, (v2i64)vec2); - reg2 += (v8i16)__msa_pckod_d((v2i64)vec5, (v2i64)vec4); - reg3 += (v8i16)__msa_pckod_d((v2i64)vec7, (v2i64)vec6); - reg0 = __msa_srai_h(reg0, 2); - reg1 = __msa_srai_h(reg1, 2); - reg2 = __msa_srai_h(reg2, 2); - reg3 = __msa_srai_h(reg3, 2); - vec4 = (v8u16)__msa_pckev_h((v8i16)reg1, (v8i16)reg0); - vec5 = (v8u16)__msa_pckev_h((v8i16)reg3, (v8i16)reg2); - vec6 = (v8u16)__msa_pckod_h((v8i16)reg1, (v8i16)reg0); - vec7 = (v8u16)__msa_pckod_h((v8i16)reg3, (v8i16)reg2); - vec0 = (v8u16)__msa_pckod_h((v8i16)vec5, (v8i16)vec4); - vec1 = (v8u16)__msa_pckev_h((v8i16)vec7, (v8i16)vec6); - vec2 = (v8u16)__msa_pckev_h((v8i16)vec5, (v8i16)vec4); - vec3 = vec0 * const_0x70; - vec4 = vec1 * const_0x4A; - vec5 = vec2 * const_0x26; - vec2 *= const_0x70; - vec1 *= const_0x5E; - vec0 *= const_0x12; - reg0 = __msa_subv_h((v8i16)vec3, (v8i16)vec4); - reg1 = __msa_subv_h((v8i16)const_0x8080, (v8i16)vec5); - reg2 = __msa_subv_h((v8i16)vec2, (v8i16)vec1); - reg3 = __msa_subv_h((v8i16)const_0x8080, (v8i16)vec0); - reg0 += reg1; - reg2 += reg3; - reg0 = __msa_srai_h(reg0, 8); - reg2 = __msa_srai_h(reg2, 8); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg2, (v16i8)reg0); - res0 = __msa_copy_u_d((v2i64)dst0, 0); - res1 = __msa_copy_u_d((v2i64)dst0, 1); - SD(res0, dst_u); - SD(res1, dst_v); - t += 48; - s += 48; - dst_u += 8; - dst_v += 8; - } -} - -void NV12ToARGBRow_MSA(const uint8_t* src_y, - const uint8_t* src_uv, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - int x; - uint64_t val0, val1; - v16u8 src0, src1, res0, res1, dst0, dst1; - v8i16 vec0, vec1, vec2; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - v16u8 zero = {0}; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 8) { - val0 = LD(src_y); - val1 = LD(src_uv); - src0 = (v16u8)__msa_insert_d((v2i64)zero, 0, val0); - src1 = (v16u8)__msa_insert_d((v2i64)zero, 0, val1); - YUVTORGB(src0, src1, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec1, vec2); - res0 = (v16u8)__msa_ilvev_b((v16i8)vec2, (v16i8)vec0); - res1 = (v16u8)__msa_ilvev_b((v16i8)alpha, (v16i8)vec1); - dst0 = (v16u8)__msa_ilvr_b((v16i8)res1, (v16i8)res0); - dst1 = (v16u8)__msa_ilvl_b((v16i8)res1, (v16i8)res0); - ST_UB2(dst0, dst1, dst_argb, 16); - src_y += 8; - src_uv += 8; - dst_argb += 32; - } -} - -void NV12ToRGB565Row_MSA(const uint8_t* src_y, - const uint8_t* src_uv, - uint8_t* dst_rgb565, - const struct YuvConstants* yuvconstants, - int width) { - int x; - uint64_t val0, val1; - v16u8 src0, src1, dst0; - v8i16 vec0, vec1, vec2; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - v16u8 zero = {0}; - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 8) { - val0 = LD(src_y); - val1 = LD(src_uv); - src0 = (v16u8)__msa_insert_d((v2i64)zero, 0, val0); - src1 = (v16u8)__msa_insert_d((v2i64)zero, 0, val1); - YUVTORGB(src0, src1, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec1, vec2); - vec0 = vec0 >> 3; - vec1 = (vec1 >> 2) << 5; - vec2 = (vec2 >> 3) << 11; - dst0 = (v16u8)(vec0 | vec1 | vec2); - ST_UB(dst0, dst_rgb565); - src_y += 8; - src_uv += 8; - dst_rgb565 += 16; - } -} - -void NV21ToARGBRow_MSA(const uint8_t* src_y, - const uint8_t* src_vu, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - int x; - uint64_t val0, val1; - v16u8 src0, src1, res0, res1, dst0, dst1; - v8i16 vec0, vec1, vec2; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - v16u8 zero = {0}; - v16i8 shuffler = {1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14}; - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 8) { - val0 = LD(src_y); - val1 = LD(src_vu); - src0 = (v16u8)__msa_insert_d((v2i64)zero, 0, val0); - src1 = (v16u8)__msa_insert_d((v2i64)zero, 0, val1); - src1 = (v16u8)__msa_vshf_b(shuffler, (v16i8)src1, (v16i8)src1); - YUVTORGB(src0, src1, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec1, vec2); - res0 = (v16u8)__msa_ilvev_b((v16i8)vec2, (v16i8)vec0); - res1 = (v16u8)__msa_ilvev_b((v16i8)alpha, (v16i8)vec1); - dst0 = (v16u8)__msa_ilvr_b((v16i8)res1, (v16i8)res0); - dst1 = (v16u8)__msa_ilvl_b((v16i8)res1, (v16i8)res0); - ST_UB2(dst0, dst1, dst_argb, 16); - src_y += 8; - src_vu += 8; - dst_argb += 32; - } -} - -void SobelRow_MSA(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_argb, - int width) { - int x; - v16u8 src0, src1, vec0, dst0, dst1, dst2, dst3; - v16i8 mask0 = {0, 0, 0, 16, 1, 1, 1, 16, 2, 2, 2, 16, 3, 3, 3, 16}; - v16i8 const_0x4 = __msa_ldi_b(0x4); - v16i8 mask1 = mask0 + const_0x4; - v16i8 mask2 = mask1 + const_0x4; - v16i8 mask3 = mask2 + const_0x4; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_sobelx, 0); - src1 = (v16u8)__msa_ld_b((void*)src_sobely, 0); - vec0 = __msa_adds_u_b(src0, src1); - dst0 = (v16u8)__msa_vshf_b(mask0, (v16i8)alpha, (v16i8)vec0); - dst1 = (v16u8)__msa_vshf_b(mask1, (v16i8)alpha, (v16i8)vec0); - dst2 = (v16u8)__msa_vshf_b(mask2, (v16i8)alpha, (v16i8)vec0); - dst3 = (v16u8)__msa_vshf_b(mask3, (v16i8)alpha, (v16i8)vec0); - ST_UB4(dst0, dst1, dst2, dst3, dst_argb, 16); - src_sobelx += 16; - src_sobely += 16; - dst_argb += 64; - } -} - -void SobelToPlaneRow_MSA(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_y, - int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1; - - for (x = 0; x < width; x += 32) { - src0 = (v16u8)__msa_ld_b((void*)src_sobelx, 0); - src1 = (v16u8)__msa_ld_b((void*)src_sobelx, 16); - src2 = (v16u8)__msa_ld_b((void*)src_sobely, 0); - src3 = (v16u8)__msa_ld_b((void*)src_sobely, 16); - dst0 = __msa_adds_u_b(src0, src2); - dst1 = __msa_adds_u_b(src1, src3); - ST_UB2(dst0, dst1, dst_y, 16); - src_sobelx += 32; - src_sobely += 32; - dst_y += 32; - } -} - -void SobelXYRow_MSA(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_argb, - int width) { - int x; - v16u8 src0, src1, vec0, vec1, vec2; - v16u8 reg0, reg1, dst0, dst1, dst2, dst3; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_sobelx, 0); - src1 = (v16u8)__msa_ld_b((void*)src_sobely, 0); - vec0 = __msa_adds_u_b(src0, src1); - vec1 = (v16u8)__msa_ilvr_b((v16i8)src0, (v16i8)src1); - vec2 = (v16u8)__msa_ilvl_b((v16i8)src0, (v16i8)src1); - reg0 = (v16u8)__msa_ilvr_b((v16i8)alpha, (v16i8)vec0); - reg1 = (v16u8)__msa_ilvl_b((v16i8)alpha, (v16i8)vec0); - dst0 = (v16u8)__msa_ilvr_b((v16i8)reg0, (v16i8)vec1); - dst1 = (v16u8)__msa_ilvl_b((v16i8)reg0, (v16i8)vec1); - dst2 = (v16u8)__msa_ilvr_b((v16i8)reg1, (v16i8)vec2); - dst3 = (v16u8)__msa_ilvl_b((v16i8)reg1, (v16i8)vec2); - ST_UB4(dst0, dst1, dst2, dst3, dst_argb, 16); - src_sobelx += 16; - src_sobely += 16; - dst_argb += 64; - } -} - -void ARGBToYJRow_MSA(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - int x; - v16u8 src0, src1, src2, src3, dst0; - v16u8 const_0x4B0F = (v16u8)__msa_fill_h(0x4B0F); - v16u8 const_0x26 = (v16u8)__msa_fill_h(0x26); - v8u16 const_0x40 = (v8u16)__msa_fill_h(0x40); - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb0, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb0, 32); - src3 = (v16u8)__msa_ld_b((void*)src_argb0, 48); - ARGBTOY(src0, src1, src2, src3, const_0x4B0F, const_0x26, const_0x40, 7, - dst0); - ST_UB(dst0, dst_y); - src_argb0 += 64; - dst_y += 16; - } -} - -void BGRAToYRow_MSA(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - int x; - v16u8 src0, src1, src2, src3, dst0; - v16u8 const_0x4200 = (v16u8)__msa_fill_h(0x4200); - v16u8 const_0x1981 = (v16u8)__msa_fill_h(0x1981); - v8u16 const_0x1080 = (v8u16)__msa_fill_h(0x1080); - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb0, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb0, 32); - src3 = (v16u8)__msa_ld_b((void*)src_argb0, 48); - ARGBTOY(src0, src1, src2, src3, const_0x4200, const_0x1981, const_0x1080, 8, - dst0); - ST_UB(dst0, dst_y); - src_argb0 += 64; - dst_y += 16; - } -} - -void ABGRToYRow_MSA(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - int x; - v16u8 src0, src1, src2, src3, dst0; - v16u8 const_0x8142 = (v16u8)__msa_fill_h(0x8142); - v16u8 const_0x19 = (v16u8)__msa_fill_h(0x19); - v8u16 const_0x1080 = (v8u16)__msa_fill_h(0x1080); - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb0, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb0, 32); - src3 = (v16u8)__msa_ld_b((void*)src_argb0, 48); - ARGBTOY(src0, src1, src2, src3, const_0x8142, const_0x19, const_0x1080, 8, - dst0); - ST_UB(dst0, dst_y); - src_argb0 += 64; - dst_y += 16; - } -} - -void RGBAToYRow_MSA(const uint8_t* src_argb0, uint8_t* dst_y, int width) { - int x; - v16u8 src0, src1, src2, src3, dst0; - v16u8 const_0x1900 = (v16u8)__msa_fill_h(0x1900); - v16u8 const_0x4281 = (v16u8)__msa_fill_h(0x4281); - v8u16 const_0x1080 = (v8u16)__msa_fill_h(0x1080); - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb0, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb0, 32); - src3 = (v16u8)__msa_ld_b((void*)src_argb0, 48); - ARGBTOY(src0, src1, src2, src3, const_0x1900, const_0x4281, const_0x1080, 8, - dst0); - ST_UB(dst0, dst_y); - src_argb0 += 64; - dst_y += 16; - } -} - -void ARGBToUVJRow_MSA(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - const uint8_t* s = src_rgb0; - const uint8_t* t = src_rgb0 + src_stride_rgb; - v16u8 src0, src1, src2, src3, src4, src5, src6, src7; - v16u8 vec0, vec1, vec2, vec3; - v16u8 dst0, dst1; - v16i8 shuffler0 = {0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29}; - v16i8 shuffler1 = {2, 3, 6, 7, 10, 11, 14, 15, - 18, 19, 22, 23, 26, 27, 30, 31}; - v16i8 shuffler2 = {0, 3, 4, 7, 8, 11, 12, 15, 16, 19, 20, 23, 24, 27, 28, 31}; - v16i8 shuffler3 = {1, 2, 5, 6, 9, 10, 13, 14, 17, 18, 21, 22, 25, 26, 29, 30}; - v16u8 const_0x7F = (v16u8)__msa_fill_h(0x7F); - v16u8 const_0x6B14 = (v16u8)__msa_fill_h(0x6B14); - v16u8 const_0x2B54 = (v16u8)__msa_fill_h(0x2B54); - v8u16 const_0x8080 = (v8u16)__msa_fill_h(0x8080); - - for (x = 0; x < width; x += 32) { - src0 = (v16u8)__msa_ld_b((void*)s, 0); - src1 = (v16u8)__msa_ld_b((void*)s, 16); - src2 = (v16u8)__msa_ld_b((void*)s, 32); - src3 = (v16u8)__msa_ld_b((void*)s, 48); - src4 = (v16u8)__msa_ld_b((void*)t, 0); - src5 = (v16u8)__msa_ld_b((void*)t, 16); - src6 = (v16u8)__msa_ld_b((void*)t, 32); - src7 = (v16u8)__msa_ld_b((void*)t, 48); - src0 = __msa_aver_u_b(src0, src4); - src1 = __msa_aver_u_b(src1, src5); - src2 = __msa_aver_u_b(src2, src6); - src3 = __msa_aver_u_b(src3, src7); - src4 = (v16u8)__msa_pckev_w((v4i32)src1, (v4i32)src0); - src5 = (v16u8)__msa_pckev_w((v4i32)src3, (v4i32)src2); - src6 = (v16u8)__msa_pckod_w((v4i32)src1, (v4i32)src0); - src7 = (v16u8)__msa_pckod_w((v4i32)src3, (v4i32)src2); - vec0 = __msa_aver_u_b(src4, src6); - vec1 = __msa_aver_u_b(src5, src7); - src0 = (v16u8)__msa_ld_b((void*)s, 64); - src1 = (v16u8)__msa_ld_b((void*)s, 80); - src2 = (v16u8)__msa_ld_b((void*)s, 96); - src3 = (v16u8)__msa_ld_b((void*)s, 112); - src4 = (v16u8)__msa_ld_b((void*)t, 64); - src5 = (v16u8)__msa_ld_b((void*)t, 80); - src6 = (v16u8)__msa_ld_b((void*)t, 96); - src7 = (v16u8)__msa_ld_b((void*)t, 112); - src0 = __msa_aver_u_b(src0, src4); - src1 = __msa_aver_u_b(src1, src5); - src2 = __msa_aver_u_b(src2, src6); - src3 = __msa_aver_u_b(src3, src7); - src4 = (v16u8)__msa_pckev_w((v4i32)src1, (v4i32)src0); - src5 = (v16u8)__msa_pckev_w((v4i32)src3, (v4i32)src2); - src6 = (v16u8)__msa_pckod_w((v4i32)src1, (v4i32)src0); - src7 = (v16u8)__msa_pckod_w((v4i32)src3, (v4i32)src2); - vec2 = __msa_aver_u_b(src4, src6); - vec3 = __msa_aver_u_b(src5, src7); - ARGBTOUV(vec0, vec1, vec2, vec3, const_0x6B14, const_0x7F, const_0x2B54, - const_0x8080, shuffler1, shuffler0, shuffler2, shuffler3, dst0, - dst1); - ST_UB(dst0, dst_v); - ST_UB(dst1, dst_u); - s += 128; - t += 128; - dst_v += 16; - dst_u += 16; - } -} - -void BGRAToUVRow_MSA(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - const uint8_t* s = src_rgb0; - const uint8_t* t = src_rgb0 + src_stride_rgb; - v16u8 dst0, dst1, vec0, vec1, vec2, vec3; - v16i8 shuffler0 = {0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29}; - v16i8 shuffler1 = {2, 3, 6, 7, 10, 11, 14, 15, - 18, 19, 22, 23, 26, 27, 30, 31}; - v16i8 shuffler2 = {0, 3, 4, 7, 8, 11, 12, 15, 16, 19, 20, 23, 24, 27, 28, 31}; - v16i8 shuffler3 = {2, 1, 6, 5, 10, 9, 14, 13, 18, 17, 22, 21, 26, 25, 30, 29}; - v16u8 const_0x125E = (v16u8)__msa_fill_h(0x125E); - v16u8 const_0x7000 = (v16u8)__msa_fill_h(0x7000); - v16u8 const_0x264A = (v16u8)__msa_fill_h(0x264A); - v8u16 const_0x8080 = (v8u16)__msa_fill_h(0x8080); - - for (x = 0; x < width; x += 32) { - READ_ARGB(s, t, vec0, vec1, vec2, vec3); - ARGBTOUV(vec0, vec1, vec2, vec3, const_0x125E, const_0x7000, const_0x264A, - const_0x8080, shuffler0, shuffler1, shuffler2, shuffler3, dst0, - dst1); - ST_UB(dst0, dst_v); - ST_UB(dst1, dst_u); - s += 128; - t += 128; - dst_v += 16; - dst_u += 16; - } -} - -void ABGRToUVRow_MSA(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - const uint8_t* s = src_rgb0; - const uint8_t* t = src_rgb0 + src_stride_rgb; - v16u8 src0, src1, src2, src3; - v16u8 dst0, dst1; - v16i8 shuffler0 = {0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29}; - v16i8 shuffler1 = {2, 3, 6, 7, 10, 11, 14, 15, - 18, 19, 22, 23, 26, 27, 30, 31}; - v16i8 shuffler2 = {0, 3, 4, 7, 8, 11, 12, 15, 16, 19, 20, 23, 24, 27, 28, 31}; - v16i8 shuffler3 = {1, 2, 5, 6, 9, 10, 13, 14, 17, 18, 21, 22, 25, 26, 29, 30}; - v16u8 const_0x4A26 = (v16u8)__msa_fill_h(0x4A26); - v16u8 const_0x0070 = (v16u8)__msa_fill_h(0x0070); - v16u8 const_0x125E = (v16u8)__msa_fill_h(0x125E); - v8u16 const_0x8080 = (v8u16)__msa_fill_h(0x8080); - - for (x = 0; x < width; x += 32) { - READ_ARGB(s, t, src0, src1, src2, src3); - ARGBTOUV(src0, src1, src2, src3, const_0x4A26, const_0x0070, const_0x125E, - const_0x8080, shuffler1, shuffler0, shuffler2, shuffler3, dst0, - dst1); - ST_UB(dst0, dst_u); - ST_UB(dst1, dst_v); - s += 128; - t += 128; - dst_u += 16; - dst_v += 16; - } -} - -void RGBAToUVRow_MSA(const uint8_t* src_rgb0, - int src_stride_rgb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - const uint8_t* s = src_rgb0; - const uint8_t* t = src_rgb0 + src_stride_rgb; - v16u8 dst0, dst1, vec0, vec1, vec2, vec3; - v16i8 shuffler0 = {0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29}; - v16i8 shuffler1 = {2, 3, 6, 7, 10, 11, 14, 15, - 18, 19, 22, 23, 26, 27, 30, 31}; - v16i8 shuffler2 = {0, 3, 4, 7, 8, 11, 12, 15, 16, 19, 20, 23, 24, 27, 28, 31}; - v16i8 shuffler3 = {2, 1, 6, 5, 10, 9, 14, 13, 18, 17, 22, 21, 26, 25, 30, 29}; - v16u8 const_0x125E = (v16u8)__msa_fill_h(0x264A); - v16u8 const_0x7000 = (v16u8)__msa_fill_h(0x7000); - v16u8 const_0x264A = (v16u8)__msa_fill_h(0x125E); - v8u16 const_0x8080 = (v8u16)__msa_fill_h(0x8080); - - for (x = 0; x < width; x += 32) { - READ_ARGB(s, t, vec0, vec1, vec2, vec3); - ARGBTOUV(vec0, vec1, vec2, vec3, const_0x125E, const_0x7000, const_0x264A, - const_0x8080, shuffler0, shuffler1, shuffler2, shuffler3, dst0, - dst1); - ST_UB(dst0, dst_u); - ST_UB(dst1, dst_v); - s += 128; - t += 128; - dst_u += 16; - dst_v += 16; - } -} - -void I444ToARGBRow_MSA(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - int x; - v16u8 src0, src1, src2, dst0, dst1; - v8u16 vec0, vec1, vec2; - v4i32 reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - v8i16 zero = {0}; - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - - for (x = 0; x < width; x += 8) { - READI444(src_y, src_u, src_v, src0, src1, src2); - vec0 = (v8u16)__msa_ilvr_b((v16i8)src0, (v16i8)src0); - reg0 = (v4i32)__msa_ilvr_h((v8i16)zero, (v8i16)vec0); - reg1 = (v4i32)__msa_ilvl_h((v8i16)zero, (v8i16)vec0); - reg0 *= vec_yg; - reg1 *= vec_yg; - reg0 = __msa_srai_w(reg0, 16); - reg1 = __msa_srai_w(reg1, 16); - reg4 = reg0 + vec_br; - reg5 = reg1 + vec_br; - reg2 = reg0 + vec_bg; - reg3 = reg1 + vec_bg; - reg0 += vec_bb; - reg1 += vec_bb; - vec0 = (v8u16)__msa_ilvr_b((v16i8)zero, (v16i8)src1); - vec1 = (v8u16)__msa_ilvr_b((v16i8)zero, (v16i8)src2); - reg6 = (v4i32)__msa_ilvr_h((v8i16)zero, (v8i16)vec0); - reg7 = (v4i32)__msa_ilvl_h((v8i16)zero, (v8i16)vec0); - reg8 = (v4i32)__msa_ilvr_h((v8i16)zero, (v8i16)vec1); - reg9 = (v4i32)__msa_ilvl_h((v8i16)zero, (v8i16)vec1); - reg0 -= reg6 * vec_ub; - reg1 -= reg7 * vec_ub; - reg2 -= reg6 * vec_ug; - reg3 -= reg7 * vec_ug; - reg4 -= reg8 * vec_vr; - reg5 -= reg9 * vec_vr; - reg2 -= reg8 * vec_vg; - reg3 -= reg9 * vec_vg; - reg0 = __msa_srai_w(reg0, 6); - reg1 = __msa_srai_w(reg1, 6); - reg2 = __msa_srai_w(reg2, 6); - reg3 = __msa_srai_w(reg3, 6); - reg4 = __msa_srai_w(reg4, 6); - reg5 = __msa_srai_w(reg5, 6); - CLIP_0TO255(reg0, reg1, reg2, reg3, reg4, reg5); - vec0 = (v8u16)__msa_pckev_h((v8i16)reg1, (v8i16)reg0); - vec1 = (v8u16)__msa_pckev_h((v8i16)reg3, (v8i16)reg2); - vec2 = (v8u16)__msa_pckev_h((v8i16)reg5, (v8i16)reg4); - vec0 = (v8u16)__msa_ilvev_b((v16i8)vec1, (v16i8)vec0); - vec1 = (v8u16)__msa_ilvev_b((v16i8)alpha, (v16i8)vec2); - dst0 = (v16u8)__msa_ilvr_h((v8i16)vec1, (v8i16)vec0); - dst1 = (v16u8)__msa_ilvl_h((v8i16)vec1, (v8i16)vec0); - ST_UB2(dst0, dst1, dst_argb, 16); - src_y += 8; - src_u += 8; - src_v += 8; - dst_argb += 32; - } -} - -void I400ToARGBRow_MSA(const uint8_t* src_y, uint8_t* dst_argb, int width) { - int x; - v16u8 src0, res0, res1, res2, res3, res4, dst0, dst1, dst2, dst3; - v8i16 vec0, vec1; - v4i32 reg0, reg1, reg2, reg3; - v4i32 vec_yg = __msa_fill_w(0x4A35); - v8i16 vec_ygb = __msa_fill_h(0xFB78); - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - v8i16 max = __msa_ldi_h(0xFF); - v8i16 zero = {0}; - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_y, 0); - vec0 = (v8i16)__msa_ilvr_b((v16i8)src0, (v16i8)src0); - vec1 = (v8i16)__msa_ilvl_b((v16i8)src0, (v16i8)src0); - reg0 = (v4i32)__msa_ilvr_h(zero, vec0); - reg1 = (v4i32)__msa_ilvl_h(zero, vec0); - reg2 = (v4i32)__msa_ilvr_h(zero, vec1); - reg3 = (v4i32)__msa_ilvl_h(zero, vec1); - reg0 *= vec_yg; - reg1 *= vec_yg; - reg2 *= vec_yg; - reg3 *= vec_yg; - reg0 = __msa_srai_w(reg0, 16); - reg1 = __msa_srai_w(reg1, 16); - reg2 = __msa_srai_w(reg2, 16); - reg3 = __msa_srai_w(reg3, 16); - vec0 = (v8i16)__msa_pckev_h((v8i16)reg1, (v8i16)reg0); - vec1 = (v8i16)__msa_pckev_h((v8i16)reg3, (v8i16)reg2); - vec0 += vec_ygb; - vec1 += vec_ygb; - vec0 = __msa_srai_h(vec0, 6); - vec1 = __msa_srai_h(vec1, 6); - vec0 = __msa_maxi_s_h(vec0, 0); - vec1 = __msa_maxi_s_h(vec1, 0); - vec0 = __msa_min_s_h(max, vec0); - vec1 = __msa_min_s_h(max, vec1); - res0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - res1 = (v16u8)__msa_ilvr_b((v16i8)res0, (v16i8)res0); - res2 = (v16u8)__msa_ilvl_b((v16i8)res0, (v16i8)res0); - res3 = (v16u8)__msa_ilvr_b((v16i8)alpha, (v16i8)res0); - res4 = (v16u8)__msa_ilvl_b((v16i8)alpha, (v16i8)res0); - dst0 = (v16u8)__msa_ilvr_b((v16i8)res3, (v16i8)res1); - dst1 = (v16u8)__msa_ilvl_b((v16i8)res3, (v16i8)res1); - dst2 = (v16u8)__msa_ilvr_b((v16i8)res4, (v16i8)res2); - dst3 = (v16u8)__msa_ilvl_b((v16i8)res4, (v16i8)res2); - ST_UB4(dst0, dst1, dst2, dst3, dst_argb, 16); - src_y += 16; - dst_argb += 64; - } -} - -void J400ToARGBRow_MSA(const uint8_t* src_y, uint8_t* dst_argb, int width) { - int x; - v16u8 src0, vec0, vec1, vec2, vec3, dst0, dst1, dst2, dst3; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_y, 0); - vec0 = (v16u8)__msa_ilvr_b((v16i8)src0, (v16i8)src0); - vec1 = (v16u8)__msa_ilvl_b((v16i8)src0, (v16i8)src0); - vec2 = (v16u8)__msa_ilvr_b((v16i8)alpha, (v16i8)src0); - vec3 = (v16u8)__msa_ilvl_b((v16i8)alpha, (v16i8)src0); - dst0 = (v16u8)__msa_ilvr_b((v16i8)vec2, (v16i8)vec0); - dst1 = (v16u8)__msa_ilvl_b((v16i8)vec2, (v16i8)vec0); - dst2 = (v16u8)__msa_ilvr_b((v16i8)vec3, (v16i8)vec1); - dst3 = (v16u8)__msa_ilvl_b((v16i8)vec3, (v16i8)vec1); - ST_UB4(dst0, dst1, dst2, dst3, dst_argb, 16); - src_y += 16; - dst_argb += 64; - } -} - -void YUY2ToARGBRow_MSA(const uint8_t* src_yuy2, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - int x; - v16u8 src0, src1, src2; - v8i16 vec0, vec1, vec2; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((void*)src_yuy2, 0); - src1 = (v16u8)__msa_pckev_b((v16i8)src0, (v16i8)src0); - src2 = (v16u8)__msa_pckod_b((v16i8)src0, (v16i8)src0); - YUVTORGB(src1, src2, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec1, vec2); - STOREARGB(vec0, vec1, vec2, alpha, dst_argb); - src_yuy2 += 16; - dst_argb += 32; - } -} - -void UYVYToARGBRow_MSA(const uint8_t* src_uyvy, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - int x; - v16u8 src0, src1, src2; - v8i16 vec0, vec1, vec2; - v4i32 vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, vec_br, vec_yg; - v4i32 vec_ubvr, vec_ugvg; - v16u8 alpha = (v16u8)__msa_ldi_b(ALPHA_VAL); - - YUVTORGB_SETUP(yuvconstants, vec_ub, vec_vr, vec_ug, vec_vg, vec_bb, vec_bg, - vec_br, vec_yg); - vec_ubvr = __msa_ilvr_w(vec_vr, vec_ub); - vec_ugvg = (v4i32)__msa_ilvev_h((v8i16)vec_vg, (v8i16)vec_ug); - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((void*)src_uyvy, 0); - src1 = (v16u8)__msa_pckod_b((v16i8)src0, (v16i8)src0); - src2 = (v16u8)__msa_pckev_b((v16i8)src0, (v16i8)src0); - YUVTORGB(src1, src2, vec_ubvr, vec_ugvg, vec_bb, vec_bg, vec_br, vec_yg, - vec0, vec1, vec2); - STOREARGB(vec0, vec1, vec2, alpha, dst_argb); - src_uyvy += 16; - dst_argb += 32; - } -} - -void InterpolateRow_MSA(uint8_t* dst_ptr, - const uint8_t* src_ptr, - ptrdiff_t src_stride, - int width, - int32_t source_y_fraction) { - int32_t y1_fraction = source_y_fraction; - int32_t y0_fraction = 256 - y1_fraction; - uint16_t y_fractions; - const uint8_t* s = src_ptr; - const uint8_t* t = src_ptr + src_stride; - int x; - v16u8 src0, src1, src2, src3, dst0, dst1; - v8u16 vec0, vec1, vec2, vec3, y_frac; - - if (0 == y1_fraction) { - memcpy(dst_ptr, src_ptr, width); - return; - } - - if (128 == y1_fraction) { - for (x = 0; x < width; x += 32) { - src0 = (v16u8)__msa_ld_b((void*)s, 0); - src1 = (v16u8)__msa_ld_b((void*)s, 16); - src2 = (v16u8)__msa_ld_b((void*)t, 0); - src3 = (v16u8)__msa_ld_b((void*)t, 16); - dst0 = __msa_aver_u_b(src0, src2); - dst1 = __msa_aver_u_b(src1, src3); - ST_UB2(dst0, dst1, dst_ptr, 16); - s += 32; - t += 32; - dst_ptr += 32; - } - return; - } - - y_fractions = (uint16_t)(y0_fraction + (y1_fraction << 8)); - y_frac = (v8u16)__msa_fill_h(y_fractions); - - for (x = 0; x < width; x += 32) { - src0 = (v16u8)__msa_ld_b((void*)s, 0); - src1 = (v16u8)__msa_ld_b((void*)s, 16); - src2 = (v16u8)__msa_ld_b((void*)t, 0); - src3 = (v16u8)__msa_ld_b((void*)t, 16); - vec0 = (v8u16)__msa_ilvr_b((v16i8)src2, (v16i8)src0); - vec1 = (v8u16)__msa_ilvl_b((v16i8)src2, (v16i8)src0); - vec2 = (v8u16)__msa_ilvr_b((v16i8)src3, (v16i8)src1); - vec3 = (v8u16)__msa_ilvl_b((v16i8)src3, (v16i8)src1); - vec0 = (v8u16)__msa_dotp_u_h((v16u8)vec0, (v16u8)y_frac); - vec1 = (v8u16)__msa_dotp_u_h((v16u8)vec1, (v16u8)y_frac); - vec2 = (v8u16)__msa_dotp_u_h((v16u8)vec2, (v16u8)y_frac); - vec3 = (v8u16)__msa_dotp_u_h((v16u8)vec3, (v16u8)y_frac); - vec0 = (v8u16)__msa_srari_h((v8i16)vec0, 8); - vec1 = (v8u16)__msa_srari_h((v8i16)vec1, 8); - vec2 = (v8u16)__msa_srari_h((v8i16)vec2, 8); - vec3 = (v8u16)__msa_srari_h((v8i16)vec3, 8); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - dst1 = (v16u8)__msa_pckev_b((v16i8)vec3, (v16i8)vec2); - ST_UB2(dst0, dst1, dst_ptr, 16); - s += 32; - t += 32; - dst_ptr += 32; - } -} - -void ARGBSetRow_MSA(uint8_t* dst_argb, uint32_t v32, int width) { - int x; - v4i32 dst0 = __builtin_msa_fill_w(v32); - - for (x = 0; x < width; x += 4) { - ST_UB(dst0, dst_argb); - dst_argb += 16; - } -} - -void RAWToRGB24Row_MSA(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { - int x; - v16u8 src0, src1, src2, src3, src4, dst0, dst1, dst2; - v16i8 shuffler0 = {2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, 17}; - v16i8 shuffler1 = {8, 7, 12, 11, 10, 15, 14, 13, - 18, 17, 16, 21, 20, 19, 24, 23}; - v16i8 shuffler2 = {14, 19, 18, 17, 22, 21, 20, 25, - 24, 23, 28, 27, 26, 31, 30, 29}; - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_raw, 0); - src1 = (v16u8)__msa_ld_b((void*)src_raw, 16); - src2 = (v16u8)__msa_ld_b((void*)src_raw, 32); - src3 = (v16u8)__msa_sldi_b((v16i8)src1, (v16i8)src0, 8); - src4 = (v16u8)__msa_sldi_b((v16i8)src2, (v16i8)src1, 8); - dst0 = (v16u8)__msa_vshf_b(shuffler0, (v16i8)src1, (v16i8)src0); - dst1 = (v16u8)__msa_vshf_b(shuffler1, (v16i8)src4, (v16i8)src3); - dst2 = (v16u8)__msa_vshf_b(shuffler2, (v16i8)src2, (v16i8)src1); - ST_UB2(dst0, dst1, dst_rgb24, 16); - ST_UB(dst2, (dst_rgb24 + 32)); - src_raw += 48; - dst_rgb24 += 48; - } -} - -void MergeUVRow_MSA(const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_uv, - int width) { - int x; - v16u8 src0, src1, dst0, dst1; - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_u, 0); - src1 = (v16u8)__msa_ld_b((void*)src_v, 0); - dst0 = (v16u8)__msa_ilvr_b((v16i8)src1, (v16i8)src0); - dst1 = (v16u8)__msa_ilvl_b((v16i8)src1, (v16i8)src0); - ST_UB2(dst0, dst1, dst_uv, 16); - src_u += 16; - src_v += 16; - dst_uv += 32; - } -} - -void ARGBExtractAlphaRow_MSA(const uint8_t* src_argb, - uint8_t* dst_a, - int width) { - int i; - v16u8 src0, src1, src2, src3, vec0, vec1, dst0; - - for (i = 0; i < width; i += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb, 32); - src3 = (v16u8)__msa_ld_b((void*)src_argb, 48); - vec0 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - vec1 = (v16u8)__msa_pckod_b((v16i8)src3, (v16i8)src2); - dst0 = (v16u8)__msa_pckod_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst_a); - src_argb += 64; - dst_a += 16; - } -} - -void ARGBBlendRow_MSA(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1; - v8u16 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7; - v8u16 vec8, vec9, vec10, vec11, vec12, vec13; - v8u16 const_256 = (v8u16)__msa_ldi_h(256); - v16u8 const_255 = (v16u8)__msa_ldi_b(255); - v16u8 mask = {0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255}; - v16i8 zero = {0}; - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((void*)src_argb0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_argb0, 16); - src2 = (v16u8)__msa_ld_b((void*)src_argb1, 0); - src3 = (v16u8)__msa_ld_b((void*)src_argb1, 16); - vec0 = (v8u16)__msa_ilvr_b(zero, (v16i8)src0); - vec1 = (v8u16)__msa_ilvl_b(zero, (v16i8)src0); - vec2 = (v8u16)__msa_ilvr_b(zero, (v16i8)src1); - vec3 = (v8u16)__msa_ilvl_b(zero, (v16i8)src1); - vec4 = (v8u16)__msa_ilvr_b(zero, (v16i8)src2); - vec5 = (v8u16)__msa_ilvl_b(zero, (v16i8)src2); - vec6 = (v8u16)__msa_ilvr_b(zero, (v16i8)src3); - vec7 = (v8u16)__msa_ilvl_b(zero, (v16i8)src3); - vec8 = (v8u16)__msa_fill_h(vec0[3]); - vec9 = (v8u16)__msa_fill_h(vec0[7]); - vec10 = (v8u16)__msa_fill_h(vec1[3]); - vec11 = (v8u16)__msa_fill_h(vec1[7]); - vec8 = (v8u16)__msa_pckev_d((v2i64)vec9, (v2i64)vec8); - vec9 = (v8u16)__msa_pckev_d((v2i64)vec11, (v2i64)vec10); - vec10 = (v8u16)__msa_fill_h(vec2[3]); - vec11 = (v8u16)__msa_fill_h(vec2[7]); - vec12 = (v8u16)__msa_fill_h(vec3[3]); - vec13 = (v8u16)__msa_fill_h(vec3[7]); - vec10 = (v8u16)__msa_pckev_d((v2i64)vec11, (v2i64)vec10); - vec11 = (v8u16)__msa_pckev_d((v2i64)vec13, (v2i64)vec12); - vec8 = const_256 - vec8; - vec9 = const_256 - vec9; - vec10 = const_256 - vec10; - vec11 = const_256 - vec11; - vec8 *= vec4; - vec9 *= vec5; - vec10 *= vec6; - vec11 *= vec7; - vec8 = (v8u16)__msa_srai_h((v8i16)vec8, 8); - vec9 = (v8u16)__msa_srai_h((v8i16)vec9, 8); - vec10 = (v8u16)__msa_srai_h((v8i16)vec10, 8); - vec11 = (v8u16)__msa_srai_h((v8i16)vec11, 8); - vec0 += vec8; - vec1 += vec9; - vec2 += vec10; - vec3 += vec11; - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - dst1 = (v16u8)__msa_pckev_b((v16i8)vec3, (v16i8)vec2); - dst0 = __msa_bmnz_v(dst0, const_255, mask); - dst1 = __msa_bmnz_v(dst1, const_255, mask); - ST_UB2(dst0, dst1, dst_argb, 16); - src_argb0 += 32; - src_argb1 += 32; - dst_argb += 32; - } -} - -void ARGBQuantizeRow_MSA(uint8_t* dst_argb, - int scale, - int interval_size, - int interval_offset, - int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1, dst2, dst3; - v8i16 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7; - v4i32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; - v4i32 tmp8, tmp9, tmp10, tmp11, tmp12, tmp13, tmp14, tmp15; - v4i32 vec_scale = __msa_fill_w(scale); - v16u8 vec_int_sz = (v16u8)__msa_fill_b(interval_size); - v16u8 vec_int_ofst = (v16u8)__msa_fill_b(interval_offset); - v16i8 mask = {0, 1, 2, 19, 4, 5, 6, 23, 8, 9, 10, 27, 12, 13, 14, 31}; - v16i8 zero = {0}; - - for (x = 0; x < width; x += 8) { - src0 = (v16u8)__msa_ld_b((void*)dst_argb, 0); - src1 = (v16u8)__msa_ld_b((void*)dst_argb, 16); - src2 = (v16u8)__msa_ld_b((void*)dst_argb, 32); - src3 = (v16u8)__msa_ld_b((void*)dst_argb, 48); - vec0 = (v8i16)__msa_ilvr_b(zero, (v16i8)src0); - vec1 = (v8i16)__msa_ilvl_b(zero, (v16i8)src0); - vec2 = (v8i16)__msa_ilvr_b(zero, (v16i8)src1); - vec3 = (v8i16)__msa_ilvl_b(zero, (v16i8)src1); - vec4 = (v8i16)__msa_ilvr_b(zero, (v16i8)src2); - vec5 = (v8i16)__msa_ilvl_b(zero, (v16i8)src2); - vec6 = (v8i16)__msa_ilvr_b(zero, (v16i8)src3); - vec7 = (v8i16)__msa_ilvl_b(zero, (v16i8)src3); - tmp0 = (v4i32)__msa_ilvr_h((v8i16)zero, (v8i16)vec0); - tmp1 = (v4i32)__msa_ilvl_h((v8i16)zero, (v8i16)vec0); - tmp2 = (v4i32)__msa_ilvr_h((v8i16)zero, (v8i16)vec1); - tmp3 = (v4i32)__msa_ilvl_h((v8i16)zero, (v8i16)vec1); - tmp4 = (v4i32)__msa_ilvr_h((v8i16)zero, (v8i16)vec2); - tmp5 = (v4i32)__msa_ilvl_h((v8i16)zero, (v8i16)vec2); - tmp6 = (v4i32)__msa_ilvr_h((v8i16)zero, (v8i16)vec3); - tmp7 = (v4i32)__msa_ilvl_h((v8i16)zero, (v8i16)vec3); - tmp8 = (v4i32)__msa_ilvr_h((v8i16)zero, (v8i16)vec4); - tmp9 = (v4i32)__msa_ilvl_h((v8i16)zero, (v8i16)vec4); - tmp10 = (v4i32)__msa_ilvr_h((v8i16)zero, (v8i16)vec5); - tmp11 = (v4i32)__msa_ilvl_h((v8i16)zero, (v8i16)vec5); - tmp12 = (v4i32)__msa_ilvr_h((v8i16)zero, (v8i16)vec6); - tmp13 = (v4i32)__msa_ilvl_h((v8i16)zero, (v8i16)vec6); - tmp14 = (v4i32)__msa_ilvr_h((v8i16)zero, (v8i16)vec7); - tmp15 = (v4i32)__msa_ilvl_h((v8i16)zero, (v8i16)vec7); - tmp0 *= vec_scale; - tmp1 *= vec_scale; - tmp2 *= vec_scale; - tmp3 *= vec_scale; - tmp4 *= vec_scale; - tmp5 *= vec_scale; - tmp6 *= vec_scale; - tmp7 *= vec_scale; - tmp8 *= vec_scale; - tmp9 *= vec_scale; - tmp10 *= vec_scale; - tmp11 *= vec_scale; - tmp12 *= vec_scale; - tmp13 *= vec_scale; - tmp14 *= vec_scale; - tmp15 *= vec_scale; - tmp0 >>= 16; - tmp1 >>= 16; - tmp2 >>= 16; - tmp3 >>= 16; - tmp4 >>= 16; - tmp5 >>= 16; - tmp6 >>= 16; - tmp7 >>= 16; - tmp8 >>= 16; - tmp9 >>= 16; - tmp10 >>= 16; - tmp11 >>= 16; - tmp12 >>= 16; - tmp13 >>= 16; - tmp14 >>= 16; - tmp15 >>= 16; - vec0 = (v8i16)__msa_pckev_h((v8i16)tmp1, (v8i16)tmp0); - vec1 = (v8i16)__msa_pckev_h((v8i16)tmp3, (v8i16)tmp2); - vec2 = (v8i16)__msa_pckev_h((v8i16)tmp5, (v8i16)tmp4); - vec3 = (v8i16)__msa_pckev_h((v8i16)tmp7, (v8i16)tmp6); - vec4 = (v8i16)__msa_pckev_h((v8i16)tmp9, (v8i16)tmp8); - vec5 = (v8i16)__msa_pckev_h((v8i16)tmp11, (v8i16)tmp10); - vec6 = (v8i16)__msa_pckev_h((v8i16)tmp13, (v8i16)tmp12); - vec7 = (v8i16)__msa_pckev_h((v8i16)tmp15, (v8i16)tmp14); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - dst1 = (v16u8)__msa_pckev_b((v16i8)vec3, (v16i8)vec2); - dst2 = (v16u8)__msa_pckev_b((v16i8)vec5, (v16i8)vec4); - dst3 = (v16u8)__msa_pckev_b((v16i8)vec7, (v16i8)vec6); - dst0 *= vec_int_sz; - dst1 *= vec_int_sz; - dst2 *= vec_int_sz; - dst3 *= vec_int_sz; - dst0 += vec_int_ofst; - dst1 += vec_int_ofst; - dst2 += vec_int_ofst; - dst3 += vec_int_ofst; - dst0 = (v16u8)__msa_vshf_b(mask, (v16i8)src0, (v16i8)dst0); - dst1 = (v16u8)__msa_vshf_b(mask, (v16i8)src1, (v16i8)dst1); - dst2 = (v16u8)__msa_vshf_b(mask, (v16i8)src2, (v16i8)dst2); - dst3 = (v16u8)__msa_vshf_b(mask, (v16i8)src3, (v16i8)dst3); - ST_UB4(dst0, dst1, dst2, dst3, dst_argb, 16); - dst_argb += 64; - } -} - -void ARGBColorMatrixRow_MSA(const uint8_t* src_argb, - uint8_t* dst_argb, - const int8_t* matrix_argb, - int width) { - int32_t x; - v16i8 src0; - v16u8 src1, src2, dst0, dst1; - v8i16 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9; - v8i16 vec10, vec11, vec12, vec13, vec14, vec15, vec16, vec17; - v4i32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; - v4i32 tmp8, tmp9, tmp10, tmp11, tmp12, tmp13, tmp14, tmp15; - v16i8 zero = {0}; - v8i16 max = __msa_ldi_h(255); - - src0 = __msa_ld_b((void*)matrix_argb, 0); - vec0 = (v8i16)__msa_ilvr_b(zero, src0); - vec1 = (v8i16)__msa_ilvl_b(zero, src0); - - for (x = 0; x < width; x += 8) { - src1 = (v16u8)__msa_ld_b((void*)src_argb, 0); - src2 = (v16u8)__msa_ld_b((void*)src_argb, 16); - vec2 = (v8i16)__msa_ilvr_b(zero, (v16i8)src1); - vec3 = (v8i16)__msa_ilvl_b(zero, (v16i8)src1); - vec4 = (v8i16)__msa_ilvr_b(zero, (v16i8)src2); - vec5 = (v8i16)__msa_ilvl_b(zero, (v16i8)src2); - vec6 = (v8i16)__msa_pckod_d((v2i64)vec2, (v2i64)vec2); - vec7 = (v8i16)__msa_pckod_d((v2i64)vec3, (v2i64)vec3); - vec8 = (v8i16)__msa_pckod_d((v2i64)vec4, (v2i64)vec4); - vec9 = (v8i16)__msa_pckod_d((v2i64)vec5, (v2i64)vec5); - vec2 = (v8i16)__msa_pckev_d((v2i64)vec2, (v2i64)vec2); - vec3 = (v8i16)__msa_pckev_d((v2i64)vec3, (v2i64)vec3); - vec4 = (v8i16)__msa_pckev_d((v2i64)vec4, (v2i64)vec4); - vec5 = (v8i16)__msa_pckev_d((v2i64)vec5, (v2i64)vec5); - vec10 = vec2 * vec0; - vec11 = vec2 * vec1; - vec12 = vec6 * vec0; - vec13 = vec6 * vec1; - tmp0 = __msa_hadd_s_w(vec10, vec10); - tmp1 = __msa_hadd_s_w(vec11, vec11); - tmp2 = __msa_hadd_s_w(vec12, vec12); - tmp3 = __msa_hadd_s_w(vec13, vec13); - vec14 = vec3 * vec0; - vec15 = vec3 * vec1; - vec16 = vec7 * vec0; - vec17 = vec7 * vec1; - tmp4 = __msa_hadd_s_w(vec14, vec14); - tmp5 = __msa_hadd_s_w(vec15, vec15); - tmp6 = __msa_hadd_s_w(vec16, vec16); - tmp7 = __msa_hadd_s_w(vec17, vec17); - vec10 = __msa_pckev_h((v8i16)tmp1, (v8i16)tmp0); - vec11 = __msa_pckev_h((v8i16)tmp3, (v8i16)tmp2); - vec12 = __msa_pckev_h((v8i16)tmp5, (v8i16)tmp4); - vec13 = __msa_pckev_h((v8i16)tmp7, (v8i16)tmp6); - tmp0 = __msa_hadd_s_w(vec10, vec10); - tmp1 = __msa_hadd_s_w(vec11, vec11); - tmp2 = __msa_hadd_s_w(vec12, vec12); - tmp3 = __msa_hadd_s_w(vec13, vec13); - tmp0 = __msa_srai_w(tmp0, 6); - tmp1 = __msa_srai_w(tmp1, 6); - tmp2 = __msa_srai_w(tmp2, 6); - tmp3 = __msa_srai_w(tmp3, 6); - vec2 = vec4 * vec0; - vec6 = vec4 * vec1; - vec3 = vec8 * vec0; - vec7 = vec8 * vec1; - tmp8 = __msa_hadd_s_w(vec2, vec2); - tmp9 = __msa_hadd_s_w(vec6, vec6); - tmp10 = __msa_hadd_s_w(vec3, vec3); - tmp11 = __msa_hadd_s_w(vec7, vec7); - vec4 = vec5 * vec0; - vec8 = vec5 * vec1; - vec5 = vec9 * vec0; - vec9 = vec9 * vec1; - tmp12 = __msa_hadd_s_w(vec4, vec4); - tmp13 = __msa_hadd_s_w(vec8, vec8); - tmp14 = __msa_hadd_s_w(vec5, vec5); - tmp15 = __msa_hadd_s_w(vec9, vec9); - vec14 = __msa_pckev_h((v8i16)tmp9, (v8i16)tmp8); - vec15 = __msa_pckev_h((v8i16)tmp11, (v8i16)tmp10); - vec16 = __msa_pckev_h((v8i16)tmp13, (v8i16)tmp12); - vec17 = __msa_pckev_h((v8i16)tmp15, (v8i16)tmp14); - tmp4 = __msa_hadd_s_w(vec14, vec14); - tmp5 = __msa_hadd_s_w(vec15, vec15); - tmp6 = __msa_hadd_s_w(vec16, vec16); - tmp7 = __msa_hadd_s_w(vec17, vec17); - tmp4 = __msa_srai_w(tmp4, 6); - tmp5 = __msa_srai_w(tmp5, 6); - tmp6 = __msa_srai_w(tmp6, 6); - tmp7 = __msa_srai_w(tmp7, 6); - vec10 = __msa_pckev_h((v8i16)tmp1, (v8i16)tmp0); - vec11 = __msa_pckev_h((v8i16)tmp3, (v8i16)tmp2); - vec12 = __msa_pckev_h((v8i16)tmp5, (v8i16)tmp4); - vec13 = __msa_pckev_h((v8i16)tmp7, (v8i16)tmp6); - vec10 = __msa_maxi_s_h(vec10, 0); - vec11 = __msa_maxi_s_h(vec11, 0); - vec12 = __msa_maxi_s_h(vec12, 0); - vec13 = __msa_maxi_s_h(vec13, 0); - vec10 = __msa_min_s_h(vec10, max); - vec11 = __msa_min_s_h(vec11, max); - vec12 = __msa_min_s_h(vec12, max); - vec13 = __msa_min_s_h(vec13, max); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec11, (v16i8)vec10); - dst1 = (v16u8)__msa_pckev_b((v16i8)vec13, (v16i8)vec12); - ST_UB2(dst0, dst1, dst_argb, 16); - src_argb += 32; - dst_argb += 32; - } -} - -void SplitUVRow_MSA(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1, dst2, dst3; - - for (x = 0; x < width; x += 32) { - src0 = (v16u8)__msa_ld_b((void*)src_uv, 0); - src1 = (v16u8)__msa_ld_b((void*)src_uv, 16); - src2 = (v16u8)__msa_ld_b((void*)src_uv, 32); - src3 = (v16u8)__msa_ld_b((void*)src_uv, 48); - dst0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - dst1 = (v16u8)__msa_pckev_b((v16i8)src3, (v16i8)src2); - dst2 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - dst3 = (v16u8)__msa_pckod_b((v16i8)src3, (v16i8)src2); - ST_UB2(dst0, dst1, dst_u, 16); - ST_UB2(dst2, dst3, dst_v, 16); - src_uv += 64; - dst_u += 32; - dst_v += 32; - } -} - -void SetRow_MSA(uint8_t* dst, uint8_t v8, int width) { - int x; - v16u8 dst0 = (v16u8)__msa_fill_b(v8); - - for (x = 0; x < width; x += 16) { - ST_UB(dst0, dst); - dst += 16; - } -} - -void MirrorUVRow_MSA(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - int x; - v16u8 src0, src1, src2, src3; - v16u8 dst0, dst1, dst2, dst3; - v16i8 mask0 = {30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0}; - v16i8 mask1 = {31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1}; - - src_uv += (2 * width); - - for (x = 0; x < width; x += 32) { - src_uv -= 64; - src2 = (v16u8)__msa_ld_b((void*)src_uv, 0); - src3 = (v16u8)__msa_ld_b((void*)src_uv, 16); - src0 = (v16u8)__msa_ld_b((void*)src_uv, 32); - src1 = (v16u8)__msa_ld_b((void*)src_uv, 48); - dst0 = (v16u8)__msa_vshf_b(mask1, (v16i8)src1, (v16i8)src0); - dst1 = (v16u8)__msa_vshf_b(mask1, (v16i8)src3, (v16i8)src2); - dst2 = (v16u8)__msa_vshf_b(mask0, (v16i8)src1, (v16i8)src0); - dst3 = (v16u8)__msa_vshf_b(mask0, (v16i8)src3, (v16i8)src2); - ST_UB2(dst0, dst1, dst_v, 16); - ST_UB2(dst2, dst3, dst_u, 16); - dst_u += 32; - dst_v += 32; - } -} - -void SobelXRow_MSA(const uint8_t* src_y0, - const uint8_t* src_y1, - const uint8_t* src_y2, - uint8_t* dst_sobelx, - int32_t width) { - int x; - v16u8 src0, src1, src2, src3, src4, src5, dst0; - v8i16 vec0, vec1, vec2, vec3, vec4, vec5; - v16i8 mask0 = {0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9}; - v16i8 tmp = __msa_ldi_b(8); - v16i8 mask1 = mask0 + tmp; - v8i16 zero = {0}; - v8i16 max = __msa_ldi_h(255); - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_y0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_y0, 16); - src2 = (v16u8)__msa_ld_b((void*)src_y1, 0); - src3 = (v16u8)__msa_ld_b((void*)src_y1, 16); - src4 = (v16u8)__msa_ld_b((void*)src_y2, 0); - src5 = (v16u8)__msa_ld_b((void*)src_y2, 16); - vec0 = (v8i16)__msa_vshf_b(mask0, (v16i8)src1, (v16i8)src0); - vec1 = (v8i16)__msa_vshf_b(mask1, (v16i8)src1, (v16i8)src0); - vec2 = (v8i16)__msa_vshf_b(mask0, (v16i8)src3, (v16i8)src2); - vec3 = (v8i16)__msa_vshf_b(mask1, (v16i8)src3, (v16i8)src2); - vec4 = (v8i16)__msa_vshf_b(mask0, (v16i8)src5, (v16i8)src4); - vec5 = (v8i16)__msa_vshf_b(mask1, (v16i8)src5, (v16i8)src4); - vec0 = (v8i16)__msa_hsub_u_h((v16u8)vec0, (v16u8)vec0); - vec1 = (v8i16)__msa_hsub_u_h((v16u8)vec1, (v16u8)vec1); - vec2 = (v8i16)__msa_hsub_u_h((v16u8)vec2, (v16u8)vec2); - vec3 = (v8i16)__msa_hsub_u_h((v16u8)vec3, (v16u8)vec3); - vec4 = (v8i16)__msa_hsub_u_h((v16u8)vec4, (v16u8)vec4); - vec5 = (v8i16)__msa_hsub_u_h((v16u8)vec5, (v16u8)vec5); - vec0 += vec2; - vec1 += vec3; - vec4 += vec2; - vec5 += vec3; - vec0 += vec4; - vec1 += vec5; - vec0 = __msa_add_a_h(zero, vec0); - vec1 = __msa_add_a_h(zero, vec1); - vec0 = __msa_maxi_s_h(vec0, 0); - vec1 = __msa_maxi_s_h(vec1, 0); - vec0 = __msa_min_s_h(max, vec0); - vec1 = __msa_min_s_h(max, vec1); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst_sobelx); - src_y0 += 16; - src_y1 += 16; - src_y2 += 16; - dst_sobelx += 16; - } -} - -void SobelYRow_MSA(const uint8_t* src_y0, - const uint8_t* src_y1, - uint8_t* dst_sobely, - int32_t width) { - int x; - v16u8 src0, src1, dst0; - v8i16 vec0, vec1, vec2, vec3, vec4, vec5, vec6; - v8i16 zero = {0}; - v8i16 max = __msa_ldi_h(255); - - for (x = 0; x < width; x += 16) { - src0 = (v16u8)__msa_ld_b((void*)src_y0, 0); - src1 = (v16u8)__msa_ld_b((void*)src_y1, 0); - vec0 = (v8i16)__msa_ilvr_b((v16i8)zero, (v16i8)src0); - vec1 = (v8i16)__msa_ilvl_b((v16i8)zero, (v16i8)src0); - vec2 = (v8i16)__msa_ilvr_b((v16i8)zero, (v16i8)src1); - vec3 = (v8i16)__msa_ilvl_b((v16i8)zero, (v16i8)src1); - vec0 -= vec2; - vec1 -= vec3; - vec6[0] = src_y0[16] - src_y1[16]; - vec6[1] = src_y0[17] - src_y1[17]; - vec2 = (v8i16)__msa_sldi_b((v16i8)vec1, (v16i8)vec0, 2); - vec3 = (v8i16)__msa_sldi_b((v16i8)vec6, (v16i8)vec1, 2); - vec4 = (v8i16)__msa_sldi_b((v16i8)vec1, (v16i8)vec0, 4); - vec5 = (v8i16)__msa_sldi_b((v16i8)vec6, (v16i8)vec1, 4); - vec0 += vec2; - vec1 += vec3; - vec4 += vec2; - vec5 += vec3; - vec0 += vec4; - vec1 += vec5; - vec0 = __msa_add_a_h(zero, vec0); - vec1 = __msa_add_a_h(zero, vec1); - vec0 = __msa_maxi_s_h(vec0, 0); - vec1 = __msa_maxi_s_h(vec1, 0); - vec0 = __msa_min_s_h(max, vec0); - vec1 = __msa_min_s_h(max, vec1); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst_sobely); - src_y0 += 16; - src_y1 += 16; - dst_sobely += 16; - } -} - -void HalfFloatRow_MSA(const uint16_t* src, - uint16_t* dst, - float scale, - int width) { - int i; - v8u16 src0, src1, src2, src3, dst0, dst1, dst2, dst3; - v4u32 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7; - v4f32 fvec0, fvec1, fvec2, fvec3, fvec4, fvec5, fvec6, fvec7; - v4f32 mult_vec; - v8i16 zero = {0}; - mult_vec[0] = 1.9259299444e-34f * scale; - mult_vec = (v4f32)__msa_splati_w((v4i32)mult_vec, 0); - - for (i = 0; i < width; i += 32) { - src0 = (v8u16)__msa_ld_h((void*)src, 0); - src1 = (v8u16)__msa_ld_h((void*)src, 16); - src2 = (v8u16)__msa_ld_h((void*)src, 32); - src3 = (v8u16)__msa_ld_h((void*)src, 48); - vec0 = (v4u32)__msa_ilvr_h(zero, (v8i16)src0); - vec1 = (v4u32)__msa_ilvl_h(zero, (v8i16)src0); - vec2 = (v4u32)__msa_ilvr_h(zero, (v8i16)src1); - vec3 = (v4u32)__msa_ilvl_h(zero, (v8i16)src1); - vec4 = (v4u32)__msa_ilvr_h(zero, (v8i16)src2); - vec5 = (v4u32)__msa_ilvl_h(zero, (v8i16)src2); - vec6 = (v4u32)__msa_ilvr_h(zero, (v8i16)src3); - vec7 = (v4u32)__msa_ilvl_h(zero, (v8i16)src3); - fvec0 = __msa_ffint_u_w(vec0); - fvec1 = __msa_ffint_u_w(vec1); - fvec2 = __msa_ffint_u_w(vec2); - fvec3 = __msa_ffint_u_w(vec3); - fvec4 = __msa_ffint_u_w(vec4); - fvec5 = __msa_ffint_u_w(vec5); - fvec6 = __msa_ffint_u_w(vec6); - fvec7 = __msa_ffint_u_w(vec7); - fvec0 *= mult_vec; - fvec1 *= mult_vec; - fvec2 *= mult_vec; - fvec3 *= mult_vec; - fvec4 *= mult_vec; - fvec5 *= mult_vec; - fvec6 *= mult_vec; - fvec7 *= mult_vec; - vec0 = ((v4u32)fvec0) >> 13; - vec1 = ((v4u32)fvec1) >> 13; - vec2 = ((v4u32)fvec2) >> 13; - vec3 = ((v4u32)fvec3) >> 13; - vec4 = ((v4u32)fvec4) >> 13; - vec5 = ((v4u32)fvec5) >> 13; - vec6 = ((v4u32)fvec6) >> 13; - vec7 = ((v4u32)fvec7) >> 13; - dst0 = (v8u16)__msa_pckev_h((v8i16)vec1, (v8i16)vec0); - dst1 = (v8u16)__msa_pckev_h((v8i16)vec3, (v8i16)vec2); - dst2 = (v8u16)__msa_pckev_h((v8i16)vec5, (v8i16)vec4); - dst3 = (v8u16)__msa_pckev_h((v8i16)vec7, (v8i16)vec6); - ST_UH2(dst0, dst1, dst, 8); - ST_UH2(dst2, dst3, dst + 16, 8); - src += 32; - dst += 32; - } -} - -#ifdef __cplusplus -} // extern "C" -} // namespace libyuv -#endif - -#endif // !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) diff --git a/libs/libyuv/source/row_neon.cc b/libs/libyuv/source/row_neon.cc index a9dc4e46b7..ae4782d6b2 100644 --- a/libs/libyuv/source/row_neon.cc +++ b/libs/libyuv/source/row_neon.cc @@ -8,103 +8,141 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "libyuv/row.h" +#include -#include +#include "libyuv/convert_from_argb.h" // For ArgbConstants +#include "libyuv/row.h" #ifdef __cplusplus namespace libyuv { extern "C" { #endif +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + // This module is for GCC Neon #if !defined(LIBYUV_DISABLE_NEON) && defined(__ARM_NEON__) && \ !defined(__aarch64__) +// d8-d15, r4-r11,r14(lr) need to be preserved if used. r13(sp),r15(pc) are +// reserved. + +// q0: Y uint16x8_t +// d2: U uint8x8_t +// d3: V uint8x8_t + // Read 8 Y, 4 U and 4 V from 422 #define READYUV422 \ - "vld1.8 {d0}, [%0]! \n" \ - "vld1.32 {d2[0]}, [%1]! \n" \ - "vld1.32 {d2[1]}, [%2]! \n" + "vld1.8 {d0}, [%[src_y]]! \n" \ + "vld1.32 {d2[0]}, [%[src_u]]! \n" \ + "vld1.32 {d2[1]}, [%[src_v]]! \n" \ + "vmov.u8 d1, d0 \n" \ + "vmovl.u8 q1, d2 \n" \ + "vzip.u8 d0, d1 \n" \ + "vsli.u16 q1, q1, #8 \n" // Read 8 Y, 8 U and 8 V from 444 #define READYUV444 \ - "vld1.8 {d0}, [%0]! \n" \ - "vld1.8 {d2}, [%1]! \n" \ - "vld1.8 {d3}, [%2]! \n" \ - "vpaddl.u8 q1, q1 \n" \ - "vrshrn.u16 d2, q1, #1 \n" + "vld1.8 {d0}, [%[src_y]]! \n" \ + "vld1.8 {d2}, [%[src_u]]! \n" \ + "vmovl.u8 q0, d0 \n" \ + "vld1.8 {d3}, [%[src_v]]! \n" \ + "vsli.u16 q0, q0, #8 \n" // Read 8 Y, and set 4 U and 4 V to 128 #define READYUV400 \ - "vld1.8 {d0}, [%0]! \n" \ - "vmov.u8 d2, #128 \n" + "vld1.8 {d0}, [%[src_y]]! \n" \ + "vmov.u8 q1, #128 \n" \ + "vmovl.u8 q0, d0 \n" \ + "vsli.u16 q0, q0, #8 \n" // Read 8 Y and 4 UV from NV12 -#define READNV12 \ - "vld1.8 {d0}, [%0]! \n" \ - "vld1.8 {d2}, [%1]! \n" \ - "vmov.u8 d3, d2 \n" /* split odd/even uv apart */ \ - "vuzp.u8 d2, d3 \n" \ - "vtrn.u32 d2, d3 \n" +#define READNV12 \ + "vld1.8 {d0}, [%[src_y]]! \n" \ + "vld1.8 {d2}, [%[src_uv]]! \n" \ + "vmov.u8 d1, d0 \n" \ + "vmov.u8 d3, d2 \n" \ + "vzip.u8 d0, d1 \n" \ + "vsli.u16 d2, d2, #8 \n" /* Duplicate low byte (U) */ \ + "vsri.u16 d3, d3, #8 \n" /* Duplicate high byte (V) */ // Read 8 Y and 4 VU from NV21 #define READNV21 \ - "vld1.8 {d0}, [%0]! \n" \ - "vld1.8 {d2}, [%1]! \n" \ - "vmov.u8 d3, d2 \n" /* split odd/even uv apart */ \ - "vuzp.u8 d3, d2 \n" \ - "vtrn.u32 d2, d3 \n" + "vld1.8 {d0}, [%[src_y]]! \n" \ + "vld1.8 {d2}, [%[src_vu]]! \n" \ + "vmov.u8 d1, d0 \n" \ + "vmov.u8 d3, d2 \n" \ + "vzip.u8 d0, d1 \n" \ + "vsri.u16 d2, d2, #8 \n" /* Duplicate high byte (U) */ \ + "vsli.u16 d3, d3, #8 \n" /* Duplicate low byte (V) */ // Read 8 YUY2 #define READYUY2 \ - "vld2.8 {d0, d2}, [%0]! \n" \ + "vld2.8 {d0, d2}, [%[src_yuy2]]! \n" \ + "vmovl.u8 q0, d0 \n" \ "vmov.u8 d3, d2 \n" \ - "vuzp.u8 d2, d3 \n" \ - "vtrn.u32 d2, d3 \n" + "vsli.u16 q0, q0, #8 \n" \ + "vsli.u16 d2, d2, #8 \n" \ + "vsri.u16 d3, d3, #8 \n" // Read 8 UYVY #define READUYVY \ - "vld2.8 {d2, d3}, [%0]! \n" \ - "vmov.u8 d0, d3 \n" \ + "vld2.8 {d2, d3}, [%[src_uyvy]]! \n" \ + "vmovl.u8 q0, d3 \n" \ "vmov.u8 d3, d2 \n" \ - "vuzp.u8 d2, d3 \n" \ - "vtrn.u32 d2, d3 \n" + "vsli.u16 q0, q0, #8 \n" \ + "vsli.u16 d2, d2, #8 \n" \ + "vsri.u16 d3, d3, #8 \n" -#define YUVTORGB_SETUP \ - "vld1.8 {d24}, [%[kUVToRB]] \n" \ - "vld1.8 {d25}, [%[kUVToG]] \n" \ - "vld1.16 {d26[], d27[]}, [%[kUVBiasBGR]]! \n" \ - "vld1.16 {d8[], d9[]}, [%[kUVBiasBGR]]! \n" \ - "vld1.16 {d28[], d29[]}, [%[kUVBiasBGR]] \n" \ - "vld1.32 {d30[], d31[]}, [%[kYToRgb]] \n" +// TODO: Use single register for kUVCoeff and multiply by lane +#define YUVTORGB_SETUP \ + "vld1.16 {d31}, [%[kRGBCoeffBias]] \n" \ + "vld4.8 {d26[], d27[], d28[], d29[]}, [%[kUVCoeff]] \n" \ + "vdup.u16 q10, d31[1] \n" \ + "vdup.u16 q11, d31[2] \n" \ + "vdup.u16 q12, d31[3] \n" \ + "vdup.u16 d31, d31[0] \n" -#define YUVTORGB \ - "vmull.u8 q8, d2, d24 \n" /* u/v B/R component */ \ - "vmull.u8 q9, d2, d25 \n" /* u/v G component */ \ - "vmovl.u8 q0, d0 \n" /* Y */ \ - "vmovl.s16 q10, d1 \n" \ - "vmovl.s16 q0, d0 \n" \ - "vmul.s32 q10, q10, q15 \n" \ - "vmul.s32 q0, q0, q15 \n" \ - "vqshrun.s32 d0, q0, #16 \n" \ - "vqshrun.s32 d1, q10, #16 \n" /* Y */ \ - "vadd.s16 d18, d19 \n" \ - "vshll.u16 q1, d16, #16 \n" /* Replicate u * UB */ \ - "vshll.u16 q10, d17, #16 \n" /* Replicate v * VR */ \ - "vshll.u16 q3, d18, #16 \n" /* Replicate (v*VG + u*UG)*/ \ - "vaddw.u16 q1, q1, d16 \n" \ - "vaddw.u16 q10, q10, d17 \n" \ - "vaddw.u16 q3, q3, d18 \n" \ - "vqadd.s16 q8, q0, q13 \n" /* B */ \ - "vqadd.s16 q9, q0, q14 \n" /* R */ \ - "vqadd.s16 q0, q0, q4 \n" /* G */ \ - "vqadd.s16 q8, q8, q1 \n" /* B */ \ - "vqadd.s16 q9, q9, q10 \n" /* R */ \ - "vqsub.s16 q0, q0, q3 \n" /* G */ \ - "vqshrun.s16 d20, q8, #6 \n" /* B */ \ - "vqshrun.s16 d22, q9, #6 \n" /* R */ \ - "vqshrun.s16 d21, q0, #6 \n" /* G */ +// q0: B uint16x8_t +// q1: G uint16x8_t +// q2: R uint16x8_t + +// Convert from YUV to 2.14 fixed point RGB +#define YUVTORGB \ + "vmull.u16 q2, d1, d31 \n" \ + "vmull.u8 q8, d3, d29 \n" /* DGV */ \ + "vmull.u16 q0, d0, d31 \n" \ + "vmlal.u8 q8, d2, d28 \n" /* DG */ \ + "vqshrn.u32 d0, q0, #16 \n" \ + "vqshrn.u32 d1, q2, #16 \n" /* Y */ \ + "vmull.u8 q9, d2, d26 \n" /* DB */ \ + "vmull.u8 q2, d3, d27 \n" /* DR */ \ + "vadd.u16 q4, q0, q11 \n" /* G */ \ + "vadd.u16 q2, q0, q2 \n" /* R */ \ + "vadd.u16 q0, q0, q9 \n" /* B */ \ + "vqsub.u16 q1, q4, q8 \n" /* G */ \ + "vqsub.u16 q0, q0, q10 \n" /* B */ \ + "vqsub.u16 q2, q2, q12 \n" /* R */ + +// Convert from 2.14 fixed point RGB To 8 bit RGB +#define RGBTORGB8 \ + "vqshrn.u16 d4, q2, #6 \n" /* R */ \ + "vqshrn.u16 d2, q1, #6 \n" /* G */ \ + "vqshrn.u16 d0, q0, #6 \n" /* B */ + +#define YUVTORGB_REGS \ + "q0", "q1", "q2", "q4", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "d31" + +#define STORERGBA \ + "vmov.u8 d1, d0 \n" \ + "vmov.u8 d3, d4 \n" \ + "vmov.u8 d0, d6 \n" \ + "vst4.8 {d0, d1, d2, d3}, [%[dst_rgba]]! \n" void I444ToARGBRow_NEON(const uint8_t* src_y, const uint8_t* src_u, @@ -114,22 +152,43 @@ void I444ToARGBRow_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "vmov.u8 d23, #255 \n" - "1: \n" READYUV444 YUVTORGB - "subs %4, %4, #8 \n" - "vst4.8 {d20, d21, d22, d23}, [%3]! \n" - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_argb), // %3 - "+r"(width) // %4 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + "vmov.u8 d6, #255 \n" + "1: \n" // + READYUV444 + "subs %[width], %[width], #8 \n" YUVTORGB RGBTORGB8 + "vst4.8 {d0, d2, d4, d6}, [%[dst_argb]]! \n" + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "d6"); +} + +void I444ToRGB24Row_NEON(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + YUVTORGB_SETUP + "1: \n" // + READYUV444 + "subs %[width], %[width], #8 \n" YUVTORGB RGBTORGB8 + "vst3.8 {d0, d2, d4}, [%[dst_rgb24]]! \n" + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS); } void I422ToARGBRow_NEON(const uint8_t* src_y, @@ -140,22 +199,46 @@ void I422ToARGBRow_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "vmov.u8 d23, #255 \n" - "1: \n" READYUV422 YUVTORGB - "subs %4, %4, #8 \n" - "vst4.8 {d20, d21, d22, d23}, [%3]! \n" - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_argb), // %3 - "+r"(width) // %4 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + "vmov.u8 d6, #255 \n" + "1: \n" // + READYUV422 + "subs %[width], %[width], #8 \n" YUVTORGB RGBTORGB8 + "vst4.8 {d0, d2, d4, d6}, [%[dst_argb]]! \n" + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "d6"); +} + +void I444AlphaToARGBRow_NEON(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + YUVTORGB_SETUP + "1: \n" // + READYUV444 + "subs %[width], %[width], #8 \n" YUVTORGB RGBTORGB8 + "vld1.8 {d6}, [%[src_a]]! \n" + "vst4.8 {d0, d2, d4, d6}, [%[dst_argb]]! \n" + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "d6"); } void I422AlphaToARGBRow_NEON(const uint8_t* src_y, @@ -167,23 +250,21 @@ void I422AlphaToARGBRow_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "1: \n" READYUV422 YUVTORGB - "subs %5, %5, #8 \n" - "vld1.8 {d23}, [%3]! \n" - "vst4.8 {d20, d21, d22, d23}, [%4]! \n" - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(src_a), // %3 - "+r"(dst_argb), // %4 - "+r"(width) // %5 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + "1: \n" // + READYUV422 + "subs %[width], %[width], #8 \n" YUVTORGB RGBTORGB8 + "vld1.8 {d6}, [%[src_a]]! \n" + "vst4.8 {d0, d2, d4, d6}, [%[dst_argb]]! \n" + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "d6"); } void I422ToRGBARow_NEON(const uint8_t* src_y, @@ -194,22 +275,22 @@ void I422ToRGBARow_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "1: \n" READYUV422 YUVTORGB - "subs %4, %4, #8 \n" - "vmov.u8 d19, #255 \n" // YUVTORGB modified d19 - "vst4.8 {d19, d20, d21, d22}, [%3]! \n" - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_rgba), // %3 - "+r"(width) // %4 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + "vmov.u8 d6, #255 \n" + "1: \n" // + READYUV422 // + "subs %[width], %[width], #8 \n" // + YUVTORGB // + RGBTORGB8 // + STORERGBA // + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgba] "+r"(dst_rgba), // %[dst_rgba] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "d6"); } void I422ToRGB24Row_NEON(const uint8_t* src_y, @@ -220,29 +301,27 @@ void I422ToRGB24Row_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "1: \n" READYUV422 YUVTORGB - "subs %4, %4, #8 \n" - "vst3.8 {d20, d21, d22}, [%3]! \n" - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_rgb24), // %3 - "+r"(width) // %4 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + "1: \n" // + READYUV422 + "subs %[width], %[width], #8 \n" YUVTORGB RGBTORGB8 + "vst3.8 {d0, d2, d4}, [%[dst_rgb24]]! \n" + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS); } #define ARGBTORGB565 \ - "vshll.u8 q0, d22, #8 \n" /* R */ \ - "vshll.u8 q8, d21, #8 \n" /* G */ \ - "vshll.u8 q9, d20, #8 \n" /* B */ \ - "vsri.16 q0, q8, #5 \n" /* RG */ \ - "vsri.16 q0, q9, #11 \n" /* RGB */ + "vshll.u8 q2, d4, #8 \n" /* R */ \ + "vshll.u8 q1, d2, #8 \n" /* G */ \ + "vshll.u8 q0, d0, #8 \n" /* B */ \ + "vsri.16 q2, q1, #5 \n" /* RG */ \ + "vsri.16 q2, q0, #11 \n" /* RGB */ void I422ToRGB565Row_NEON(const uint8_t* src_y, const uint8_t* src_u, @@ -252,31 +331,29 @@ void I422ToRGB565Row_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "1: \n" READYUV422 YUVTORGB - "subs %4, %4, #8 \n" ARGBTORGB565 - "vst1.8 {q0}, [%3]! \n" // store 8 pixels RGB565. - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_rgb565), // %3 - "+r"(width) // %4 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + "1: \n" // + READYUV422 "subs %[width], %[width], #8 \n" YUVTORGB + RGBTORGB8 ARGBTORGB565 + "vst1.8 {q2}, [%[dst_rgb565]]! \n" // store 8 pixels RGB565. + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgb565] "+r"(dst_rgb565), // %[dst_rgb565] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS); } #define ARGBTOARGB1555 \ - "vshll.u8 q0, d23, #8 \n" /* A */ \ - "vshll.u8 q8, d22, #8 \n" /* R */ \ - "vshll.u8 q9, d21, #8 \n" /* G */ \ - "vshll.u8 q10, d20, #8 \n" /* B */ \ - "vsri.16 q0, q8, #1 \n" /* AR */ \ - "vsri.16 q0, q9, #6 \n" /* ARG */ \ - "vsri.16 q0, q10, #11 \n" /* ARGB */ + "vshll.u8 q3, d6, #8 \n" /* A */ \ + "vshll.u8 q2, d4, #8 \n" /* R */ \ + "vshll.u8 q1, d2, #8 \n" /* G */ \ + "vshll.u8 q0, d0, #8 \n" /* B */ \ + "vsri.16 q3, q2, #1 \n" /* AR */ \ + "vsri.16 q3, q1, #6 \n" /* ARG */ \ + "vsri.16 q3, q0, #11 \n" /* ARGB */ void I422ToARGB1555Row_NEON(const uint8_t* src_y, const uint8_t* src_u, @@ -286,31 +363,29 @@ void I422ToARGB1555Row_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "1: \n" READYUV422 YUVTORGB - "subs %4, %4, #8 \n" - "vmov.u8 d23, #255 \n" ARGBTOARGB1555 - "vst1.8 {q0}, [%3]! \n" // store 8 pixels - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_argb1555), // %3 - "+r"(width) // %4 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + "1: \n" // + READYUV422 + "subs %[width], %[width], #8 \n" YUVTORGB RGBTORGB8 + "vmov.u8 d6, #0xff \n" ARGBTOARGB1555 + "vst1.8 {q3}, [%[dst_argb1555]]! \n" // store 8 pixels RGB1555. + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb1555] "+r"(dst_argb1555), // %[dst_argb1555] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "q3"); } #define ARGBTOARGB4444 \ - "vshr.u8 d20, d20, #4 \n" /* B */ \ - "vbic.32 d21, d21, d4 \n" /* G */ \ - "vshr.u8 d22, d22, #4 \n" /* R */ \ - "vbic.32 d23, d23, d4 \n" /* A */ \ - "vorr d0, d20, d21 \n" /* BG */ \ - "vorr d1, d22, d23 \n" /* RA */ \ + "vshr.u8 d0, d0, #4 \n" /* B */ \ + "vbic.32 d2, d2, d7 \n" /* G */ \ + "vshr.u8 d4, d4, #4 \n" /* R */ \ + "vbic.32 d6, d6, d7 \n" /* A */ \ + "vorr d0, d0, d2 \n" /* BG */ \ + "vorr d1, d4, d6 \n" /* RA */ \ "vzip.u8 d0, d1 \n" /* BGRA */ void I422ToARGB4444Row_NEON(const uint8_t* src_y, @@ -321,56 +396,53 @@ void I422ToARGB4444Row_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "vmov.u8 d4, #0x0f \n" // vbic bits to clear - "1: \n" - - READYUV422 YUVTORGB - "subs %4, %4, #8 \n" - "vmov.u8 d23, #255 \n" ARGBTOARGB4444 - "vst1.8 {q0}, [%3]! \n" // store 8 pixels - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_argb4444), // %3 - "+r"(width) // %4 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + "vmov.u8 d6, #255 \n" + "vmov.u8 d7, #0x0f \n" // vbic bits to clear + "1: \n" // + READYUV422 YUVTORGB RGBTORGB8 + "subs %[width], %[width], #8 \n" ARGBTOARGB4444 + "vst1.8 {q0}, [%[dst_argb4444]]! \n" // store 8 pixels + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb4444] "+r"(dst_argb4444), // %[dst_argb4444] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "q3"); } -void I400ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, int width) { +void I400ToARGBRow_NEON(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { asm volatile( YUVTORGB_SETUP - "vmov.u8 d23, #255 \n" - "1: \n" READYUV400 YUVTORGB - "subs %2, %2, #8 \n" - "vst4.8 {d20, d21, d22, d23}, [%1]! \n" - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : [kUVToRB] "r"(&kYuvI601Constants.kUVToRB), - [kUVToG] "r"(&kYuvI601Constants.kUVToG), - [kUVBiasBGR] "r"(&kYuvI601Constants.kUVBiasBGR), - [kYToRgb] "r"(&kYuvI601Constants.kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + "vmov.u8 d6, #255 \n" + "1: \n" // + READYUV400 YUVTORGB RGBTORGB8 + "subs %[width], %[width], #8 \n" + "vst4.8 {d0, d2, d4, d6}, [%[dst_argb]]! \n" + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "d6"); } void J400ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, int width) { asm volatile( - "vmov.u8 d23, #255 \n" - "1: \n" - "vld1.8 {d20}, [%0]! \n" - "vmov d21, d20 \n" - "vmov d22, d20 \n" - "subs %2, %2, #8 \n" - "vst4.8 {d20, d21, d22, d23}, [%1]! \n" - "bgt 1b \n" + "vmov.u8 d23, #255 \n" + "1: \n" + "vld1.8 {d20}, [%0]! \n" + "subs %2, %2, #8 \n" + "vmov d21, d20 \n" + "vmov d22, d20 \n" + "vst4.8 {d20, d21, d22, d23}, [%1]! \n" + "bgt 1b \n" : "+r"(src_y), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -383,22 +455,21 @@ void NV12ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - asm volatile(YUVTORGB_SETUP - "vmov.u8 d23, #255 \n" - "1: \n" READNV12 YUVTORGB - "subs %3, %3, #8 \n" - "vst4.8 {d20, d21, d22, d23}, [%2]! \n" - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_uv), // %1 - "+r"(dst_argb), // %2 - "+r"(width) // %3 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", - "q10", "q11", "q12", "q13", "q14", "q15"); + asm volatile( + YUVTORGB_SETUP + "vmov.u8 d6, #255 \n" + "1: \n" // + READNV12 YUVTORGB RGBTORGB8 + "subs %[width], %[width], #8 \n" + "vst4.8 {d0, d2, d4, d6}, [%[dst_argb]]! \n" + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "d6"); } void NV21ToARGBRow_NEON(const uint8_t* src_y, @@ -406,22 +477,21 @@ void NV21ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - asm volatile(YUVTORGB_SETUP - "vmov.u8 d23, #255 \n" - "1: \n" READNV21 YUVTORGB - "subs %3, %3, #8 \n" - "vst4.8 {d20, d21, d22, d23}, [%2]! \n" - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_vu), // %1 - "+r"(dst_argb), // %2 - "+r"(width) // %3 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", - "q10", "q11", "q12", "q13", "q14", "q15"); + asm volatile( + YUVTORGB_SETUP + "vmov.u8 d6, #255 \n" + "1: \n" // + READNV21 YUVTORGB RGBTORGB8 + "subs %[width], %[width], #8 \n" + "vst4.8 {d0, d2, d4, d6}, [%[dst_argb]]! \n" + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_vu] "+r"(src_vu), // %[src_vu] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "d6"); } void NV12ToRGB24Row_NEON(const uint8_t* src_y, @@ -430,25 +500,18 @@ void NV12ToRGB24Row_NEON(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) { asm volatile( - - YUVTORGB_SETUP - - "1: \n" - - READNV12 YUVTORGB - "subs %3, %3, #8 \n" - "vst3.8 {d20, d21, d22}, [%2]! \n" - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_uv), // %1 - "+r"(dst_rgb24), // %2 - "+r"(width) // %3 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + YUVTORGB_SETUP "1: \n" // + READNV12 YUVTORGB RGBTORGB8 + "subs %[width], %[width], #8 \n" + "vst3.8 {d0, d2, d4}, [%[dst_rgb24]]! \n" + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS); } void NV21ToRGB24Row_NEON(const uint8_t* src_y, @@ -457,25 +520,18 @@ void NV21ToRGB24Row_NEON(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) { asm volatile( - - YUVTORGB_SETUP - - "1: \n" - - READNV21 YUVTORGB - "subs %3, %3, #8 \n" - "vst3.8 {d20, d21, d22}, [%2]! \n" - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_vu), // %1 - "+r"(dst_rgb24), // %2 - "+r"(width) // %3 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + YUVTORGB_SETUP "1: \n" // + READNV21 YUVTORGB RGBTORGB8 + "subs %[width], %[width], #8 \n" + "vst3.8 {d0, d2, d4}, [%[dst_rgb24]]! \n" + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_vu] "+r"(src_vu), // %[src_vu] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS); } void NV12ToRGB565Row_NEON(const uint8_t* src_y, @@ -485,62 +541,58 @@ void NV12ToRGB565Row_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "1: \n" READNV12 YUVTORGB - "subs %3, %3, #8 \n" ARGBTORGB565 - "vst1.8 {q0}, [%2]! \n" // store 8 pixels RGB565. - "bgt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_uv), // %1 - "+r"(dst_rgb565), // %2 - "+r"(width) // %3 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", "q10", "q11", - "q12", "q13", "q14", "q15"); + "1: \n" // + READNV12 YUVTORGB RGBTORGB8 + "subs %[width], %[width], #8 \n" ARGBTORGB565 + "vst1.8 {q2}, [%[dst_rgb565]]! \n" // store 8 pixels RGB565. + "bgt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_rgb565] "+r"(dst_rgb565), // %[dst_rgb565] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS); } void YUY2ToARGBRow_NEON(const uint8_t* src_yuy2, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - asm volatile(YUVTORGB_SETUP - "vmov.u8 d23, #255 \n" - "1: \n" READYUY2 YUVTORGB - "subs %2, %2, #8 \n" - "vst4.8 {d20, d21, d22, d23}, [%1]! \n" - "bgt 1b \n" - : "+r"(src_yuy2), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", - "q10", "q11", "q12", "q13", "q14", "q15"); + asm volatile( + YUVTORGB_SETUP + "vmov.u8 d6, #255 \n" + "1: \n" // + READYUY2 YUVTORGB RGBTORGB8 + "subs %[width], %[width], #8 \n" + "vst4.8 {d0, d2, d4, d6}, [%[dst_argb]]! \n" + "bgt 1b \n" + : [src_yuy2] "+r"(src_yuy2), // %[src_yuy2] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "d6"); } void UYVYToARGBRow_NEON(const uint8_t* src_uyvy, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - asm volatile(YUVTORGB_SETUP - "vmov.u8 d23, #255 \n" - "1: \n" READUYVY YUVTORGB - "subs %2, %2, #8 \n" - "vst4.8 {d20, d21, d22, d23}, [%1]! \n" - "bgt 1b \n" - : "+r"(src_uyvy), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q8", "q9", - "q10", "q11", "q12", "q13", "q14", "q15"); + asm volatile( + YUVTORGB_SETUP + "vmov.u8 d6, #255 \n" + "1: \n" // + READUYVY YUVTORGB RGBTORGB8 + "subs %[width], %[width], #8 \n" + "vst4.8 {d0, d2, d4, d6}, [%[dst_argb]]! \n" + "bgt 1b \n" + : [src_uyvy] "+r"(src_uyvy), // %[src_uyvy] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "d6"); } // Reads 16 pairs of UV and write even values to dst_u and odd to dst_v. @@ -549,12 +601,12 @@ void SplitUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_v, int width) { asm volatile( - "1: \n" - "vld2.8 {q0, q1}, [%0]! \n" // load 16 pairs of UV - "subs %3, %3, #16 \n" // 16 processed per loop - "vst1.8 {q0}, [%1]! \n" // store U - "vst1.8 {q1}, [%2]! \n" // store V - "bgt 1b \n" + "1: \n" + "vld2.8 {q0, q1}, [%0]! \n" // load 16 pairs of UV + "subs %3, %3, #16 \n" // 16 processed per loop + "vst1.8 {q0}, [%1]! \n" // store U + "vst1.8 {q1}, [%2]! \n" // store V + "bgt 1b \n" : "+r"(src_uv), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -564,18 +616,179 @@ void SplitUVRow_NEON(const uint8_t* src_uv, ); } +// Reads 16 byte Y's from tile and writes out 16 Y's. +// MM21 Y tiles are 16x32 so src_tile_stride = 512 bytes +// MM21 UV tiles are 8x16 so src_tile_stride = 256 bytes +// width measured in bytes so 8 UV = 16. +void DetileRow_NEON(const uint8_t* src, + ptrdiff_t src_tile_stride, + uint8_t* dst, + int width) { + asm volatile( + "1: \n" + "vld1.8 {q0}, [%0], %3 \n" // load 16 bytes + "subs %2, %2, #16 \n" // 16 processed per loop + "pld [%0, #1792] \n" + "vst1.8 {q0}, [%1]! \n" // store 16 bytes + "bgt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "r"(src_tile_stride) // %3 + : "cc", "memory", "q0" // Clobber List + ); +} + +// Reads 16 byte Y's of 16 bits from tile and writes out 16 Y's. +void DetileRow_16_NEON(const uint16_t* src, + ptrdiff_t src_tile_stride, + uint16_t* dst, + int width) { + asm volatile( + "1: \n" + "vld1.16 {q0, q1}, [%0], %3 \n" // load 16 pixels + "subs %2, %2, #16 \n" // 16 processed per loop + "pld [%0, #3584] \n" + "vst1.16 {q0, q1}, [%1]! \n" // store 16 pixels + "bgt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "r"(src_tile_stride * 2) // %3 + : "cc", "memory", "q0", "q1" // Clobber List + ); +} + +// Read 16 bytes of UV, detile, and write 8 bytes of U and 8 bytes of V. +void DetileSplitUVRow_NEON(const uint8_t* src_uv, + ptrdiff_t src_tile_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + asm volatile( + "1: \n" + "vld2.8 {d0, d1}, [%0], %4 \n" + "subs %3, %3, #16 \n" + "pld [%0, #1792] \n" + "vst1.8 {d0}, [%1]! \n" + "vst1.8 {d1}, [%2]! \n" + "bgt 1b \n" + : "+r"(src_uv), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"(src_tile_stride) // %4 + : "cc", "memory", "d0", "d1" // Clobber List + ); +} + +#if defined(LIBYUV_USE_ST2) +// Read 16 Y, 8 UV, and write 8 YUYV. +void DetileToYUY2_NEON(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width) { + asm volatile( + "1: \n" + "vld1.8 {q0}, [%0], %4 \n" // Load 16 Y + "pld [%0, #1792] \n" + "vld1.8 {q1}, [%1], %5 \n" // Load 8 UV + "pld [%1, #1792] \n" + "subs %3, %3, #16 \n" + "vst2.8 {q0, q1}, [%2]! \n" + "bgt 1b \n" + : "+r"(src_y), // %0 + "+r"(src_uv), // %1 + "+r"(dst_yuy2), // %2 + "+r"(width) // %3 + : "r"(src_y_tile_stride), // %4 + "r"(src_uv_tile_stride) // %5 + : "cc", "memory", "d0", "d1", "d2", "d3" // Clobber list + ); +} +#else +// Read 16 Y, 8 UV, and write 8 YUYV. +void DetileToYUY2_NEON(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width) { + asm volatile( + "1: \n" + "vld1.8 {q0}, [%0], %4 \n" // Load 16 Y + "vld1.8 {q1}, [%1], %5 \n" // Load 8 UV + "subs %3, %3, #16 \n" + "pld [%0, #1792] \n" + "vzip.8 q0, q1 \n" + "pld [%1, #1792] \n" + "vst1.8 {q0, q1}, [%2]! \n" + "bgt 1b \n" + : "+r"(src_y), // %0 + "+r"(src_uv), // %1 + "+r"(dst_yuy2), // %2 + "+r"(width) // %3 + : "r"(src_y_tile_stride), // %4 + "r"(src_uv_tile_stride) // %5 + : "cc", "memory", "q0", "q1", "q2", "q3" // Clobber list + ); +} +#endif + +void UnpackMT2T_NEON(const uint8_t* src, uint16_t* dst, size_t size) { + asm volatile( + "1: \n" + "vld1.8 {q14}, [%0]! \n" // Load lower bits. + "vld1.8 {q9}, [%0]! \n" // Load upper bits row + // by row. + "vld1.8 {q11}, [%0]! \n" + "vld1.8 {q13}, [%0]! \n" + "vld1.8 {q15}, [%0]! \n" + "subs %2, %2, #80 \n" + "vshl.u8 q8, q14, #6 \n" // Shift lower bit data + // appropriately. + "vshl.u8 q10, q14, #4 \n" + "vshl.u8 q12, q14, #2 \n" + "vzip.u8 q8, q9 \n" // Interleave upper and + // lower bits. + "vzip.u8 q10, q11 \n" + "vzip.u8 q12, q13 \n" + "vzip.u8 q14, q15 \n" + "vsri.u16 q8, q8, #10 \n" // Copy upper 6 bits + // into lower 6 bits for + // better accuracy in + // conversions. + "vsri.u16 q9, q9, #10 \n" + "vsri.u16 q10, q10, #10 \n" + "vsri.u16 q11, q11, #10 \n" + "vsri.u16 q12, q12, #10 \n" + "vsri.u16 q13, q13, #10 \n" + "vsri.u16 q14, q14, #10 \n" + "vsri.u16 q15, q15, #10 \n" + "vstmia %1!, {q8-q15} \n" // Store pixel block (64 + // pixels). + "bgt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(size) // %2 + : + : "cc", "memory", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15"); +} + // Reads 16 U's and V's and writes out 16 pairs of UV. void MergeUVRow_NEON(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width) { asm volatile( - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load U - "vld1.8 {q1}, [%1]! \n" // load V - "subs %3, %3, #16 \n" // 16 processed per loop - "vst2.8 {q0, q1}, [%2]! \n" // store 16 pairs of UV - "bgt 1b \n" + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load U + "vld1.8 {q1}, [%1]! \n" // load V + "subs %3, %3, #16 \n" // 16 processed per loop + "vst2.8 {q0, q1}, [%2]! \n" // store 16 pairs of UV + "bgt 1b \n" : "+r"(src_u), // %0 "+r"(src_v), // %1 "+r"(dst_uv), // %2 @@ -592,21 +805,21 @@ void SplitRGBRow_NEON(const uint8_t* src_rgb, uint8_t* dst_b, int width) { asm volatile( - "1: \n" - "vld3.8 {d0, d2, d4}, [%0]! \n" // load 8 RGB - "vld3.8 {d1, d3, d5}, [%0]! \n" // next 8 RGB - "subs %4, %4, #16 \n" // 16 processed per loop - "vst1.8 {q0}, [%1]! \n" // store R - "vst1.8 {q1}, [%2]! \n" // store G - "vst1.8 {q2}, [%3]! \n" // store B - "bgt 1b \n" + "1: \n" + "vld3.8 {d0, d2, d4}, [%0]! \n" // load 8 RGB + "vld3.8 {d1, d3, d5}, [%0]! \n" // next 8 RGB + "subs %4, %4, #16 \n" // 16 processed per loop + "vst1.8 {q0}, [%1]! \n" // store R + "vst1.8 {q1}, [%2]! \n" // store G + "vst1.8 {q2}, [%3]! \n" // store B + "bgt 1b \n" : "+r"(src_rgb), // %0 "+r"(dst_r), // %1 "+r"(dst_g), // %2 "+r"(dst_b), // %3 "+r"(width) // %4 : // Input registers - : "cc", "memory", "d0", "d1", "d2" // Clobber List + : "cc", "memory", "q0", "q1", "q2" // Clobber List ); } @@ -617,14 +830,14 @@ void MergeRGBRow_NEON(const uint8_t* src_r, uint8_t* dst_rgb, int width) { asm volatile( - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load R - "vld1.8 {q1}, [%1]! \n" // load G - "vld1.8 {q2}, [%2]! \n" // load B - "subs %4, %4, #16 \n" // 16 processed per loop - "vst3.8 {d0, d2, d4}, [%3]! \n" // store 8 RGB - "vst3.8 {d1, d3, d5}, [%3]! \n" // next 8 RGB - "bgt 1b \n" + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load R + "vld1.8 {q1}, [%1]! \n" // load G + "vld1.8 {q2}, [%2]! \n" // load B + "subs %4, %4, #16 \n" // 16 processed per loop + "vst3.8 {d0, d2, d4}, [%3]! \n" // store 8 RGB + "vst3.8 {d1, d3, d5}, [%3]! \n" // next 8 RGB + "bgt 1b \n" : "+r"(src_r), // %0 "+r"(src_g), // %1 "+r"(src_b), // %2 @@ -635,14 +848,341 @@ void MergeRGBRow_NEON(const uint8_t* src_r, ); } +// Reads 16 packed ARGB and write to planar dst_r, dst_g, dst_b, dst_a. +void SplitARGBRow_NEON(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width) { + asm volatile( + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB + "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // next 8 ARGB + "subs %5, %5, #16 \n" // 16 processed per loop + "vst1.8 {q0}, [%3]! \n" // store B + "vst1.8 {q1}, [%2]! \n" // store G + "vst1.8 {q2}, [%1]! \n" // store R + "vst1.8 {q3}, [%4]! \n" // store A + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+r"(dst_a), // %4 + "+r"(width) // %5 + : // Input registers + : "cc", "memory", "q0", "q1", "q2", "q3" // Clobber List + ); +} + +// Reads 16 planar R's, G's and B's and writes out 16 packed ARGB at a time +void MergeARGBRow_NEON(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width) { + asm volatile( + "1: \n" + "vld1.8 {q2}, [%0]! \n" // load R + "vld1.8 {q1}, [%1]! \n" // load G + "vld1.8 {q0}, [%2]! \n" // load B + "vld1.8 {q3}, [%3]! \n" // load A + "subs %5, %5, #16 \n" // 16 processed per loop + "vst4.8 {d0, d2, d4, d6}, [%4]! \n" // store 8 ARGB + "vst4.8 {d1, d3, d5, d7}, [%4]! \n" // next 8 ARGB + "bgt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(src_a), // %3 + "+r"(dst_argb), // %4 + "+r"(width) // %5 + : // Input registers + : "cc", "memory", "q0", "q1", "q2", "q3" // Clobber List + ); +} + +// Reads 16 packed ARGB and write to planar dst_r, dst_g, dst_b. +void SplitXRGBRow_NEON(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + asm volatile( + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB + "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // next 8 ARGB + "subs %4, %4, #16 \n" // 16 processed per loop + "vst1.8 {q0}, [%3]! \n" // store B + "vst1.8 {q1}, [%2]! \n" // store G + "vst1.8 {q2}, [%1]! \n" // store R + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+r"(width) // %4 + : // Input registers + : "cc", "memory", "q0", "q1", "q2", "q3" // Clobber List + ); +} + +// Reads 16 planar R's, G's, B's and A's and writes out 16 packed ARGB at a time +void MergeXRGBRow_NEON(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width) { + asm volatile( + "vmov.u8 q3, #255 \n" // load A(255) + "1: \n" + "vld1.8 {q2}, [%0]! \n" // load R + "vld1.8 {q1}, [%1]! \n" // load G + "vld1.8 {q0}, [%2]! \n" // load B + "subs %4, %4, #16 \n" // 16 processed per loop + "vst4.8 {d0, d2, d4, d6}, [%3]! \n" // store 8 ARGB + "vst4.8 {d1, d3, d5, d7}, [%3]! \n" // next 8 ARGB + "bgt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_argb), // %3 + "+r"(width) // %4 + : // Input registers + : "cc", "memory", "q0", "q1", "q2", "q3" // Clobber List + ); +} + +void MergeXR30Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int depth, + int width) { + int shift = 10 - depth; + asm volatile( + "vmov.u32 q14, #1023 \n" + "vdup.32 q15, %5 \n" + "1: \n" + "vld1.16 {d4}, [%2]! \n" // B + "vld1.16 {d2}, [%1]! \n" // G + "vld1.16 {d0}, [%0]! \n" // R + "subs %4, %4, #4 \n" + "vmovl.u16 q2, d4 \n" // B + "vmovl.u16 q1, d2 \n" // G + "vmovl.u16 q0, d0 \n" // R + "vshl.u32 q2, q2, q15 \n" // 000B + "vshl.u32 q1, q1, q15 \n" + "vshl.u32 q0, q0, q15 \n" + "vmin.u32 q2, q2, q14 \n" + "vmin.u32 q1, q1, q14 \n" + "vmin.u32 q0, q0, q14 \n" + "vsli.u32 q2, q1, #10 \n" // 00GB + "vsli.u32 q2, q0, #20 \n" // 0RGB + "vorr.u32 q2, #0xc0000000 \n" // ARGB (AR30) + "vst1.8 {q2}, [%3]! \n" + "bgt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_ar30), // %3 + "+r"(width) // %4 + : "r"(shift) // %5 + : "memory", "cc", "q0", "q1", "q2", "q14", "q15"); +} + +void MergeXR30Row_10_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int /* depth */, + int width) { + asm volatile( + "vmov.u32 q14, #1023 \n" + "1: \n" + "vld1.16 {d4}, [%2]! \n" // B + "vld1.16 {d2}, [%1]! \n" // G + "vld1.16 {d0}, [%0]! \n" // R + "subs %4, %4, #4 \n" + "vmovl.u16 q2, d4 \n" // 000B + "vmovl.u16 q1, d2 \n" // G + "vmovl.u16 q0, d0 \n" // R + "vmin.u32 q2, q2, q14 \n" + "vmin.u32 q1, q1, q14 \n" + "vmin.u32 q0, q0, q14 \n" + "vsli.u32 q2, q1, #10 \n" // 00GB + "vsli.u32 q2, q0, #20 \n" // 0RGB + "vorr.u32 q2, #0xc0000000 \n" // ARGB (AR30) + "vst1.8 {q2}, [%3]! \n" + "bgt 1b \n" + "3: \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_ar30), // %3 + "+r"(width) // %4 + : + : "memory", "cc", "q0", "q1", "q2", "q14"); +} + +void MergeAR64Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint16_t* dst_ar64, + int depth, + int width) { + int shift = 16 - depth; + int mask = (1 << depth) - 1; + asm volatile( + + "vdup.u16 q15, %6 \n" + "vdup.u16 q14, %7 \n" + "1: \n" + "vld1.16 {q2}, [%0]! \n" // R + "vld1.16 {q1}, [%1]! \n" // G + "vld1.16 {q0}, [%2]! \n" // B + "vld1.16 {q3}, [%3]! \n" // A + "subs %5, %5, #8 \n" + "vmin.u16 q2, q2, q14 \n" + "vmin.u16 q1, q1, q14 \n" + "vmin.u16 q0, q0, q14 \n" + "vmin.u16 q3, q3, q14 \n" + "vshl.u16 q2, q2, q15 \n" + "vshl.u16 q1, q1, q15 \n" + "vshl.u16 q0, q0, q15 \n" + "vshl.u16 q3, q3, q15 \n" + "vst4.16 {d0, d2, d4, d6}, [%4]! \n" + "vst4.16 {d1, d3, d5, d7}, [%4]! \n" + "bgt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(src_a), // %3 + "+r"(dst_ar64), // %4 + "+r"(width) // %5 + : "r"(shift), // %6 + "r"(mask) // %7 + : "memory", "cc", "q0", "q1", "q2", "q3", "q14", "q15"); +} + +void MergeXR64Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint16_t* dst_ar64, + int depth, + int width) { + int shift = 16 - depth; + int mask = (1 << depth) - 1; + asm volatile( + + "vmov.u8 q3, #0xff \n" // A (0xffff) + "vdup.u16 q15, %5 \n" + "vdup.u16 q14, %6 \n" + "1: \n" + "vld1.16 {q2}, [%0]! \n" // R + "vld1.16 {q1}, [%1]! \n" // G + "vld1.16 {q0}, [%2]! \n" // B + "subs %4, %4, #8 \n" + "vmin.u16 q2, q2, q14 \n" + "vmin.u16 q1, q1, q14 \n" + "vmin.u16 q0, q0, q14 \n" + "vshl.u16 q2, q2, q15 \n" + "vshl.u16 q1, q1, q15 \n" + "vshl.u16 q0, q0, q15 \n" + "vst4.16 {d0, d2, d4, d6}, [%3]! \n" + "vst4.16 {d1, d3, d5, d7}, [%3]! \n" + "bgt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_ar64), // %3 + "+r"(width) // %4 + : "r"(shift), // %5 + "r"(mask) // %6 + : "memory", "cc", "q0", "q1", "q2", "q3", "q14", "q15"); +} + +void MergeARGB16To8Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint8_t* dst_argb, + int depth, + int width) { + int shift = 8 - depth; + asm volatile( + + "vdup.16 q15, %6 \n" + "1: \n" + "vld1.16 {q2}, [%0]! \n" // R + "vld1.16 {q1}, [%1]! \n" // G + "vld1.16 {q0}, [%2]! \n" // B + "vld1.16 {q3}, [%3]! \n" // A + "subs %5, %5, #8 \n" + "vshl.u16 q2, q2, q15 \n" + "vshl.u16 q1, q1, q15 \n" + "vshl.u16 q0, q0, q15 \n" + "vshl.u16 q3, q3, q15 \n" + "vqmovn.u16 d0, q0 \n" + "vqmovn.u16 d1, q1 \n" + "vqmovn.u16 d2, q2 \n" + "vqmovn.u16 d3, q3 \n" + "vst4.8 {d0, d1, d2, d3}, [%4]! \n" + "bgt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(src_a), // %3 + "+r"(dst_argb), // %4 + "+r"(width) // %5 + : "r"(shift) // %6 + : "memory", "cc", "q0", "q1", "q2", "q3", "q15"); +} + +void MergeXRGB16To8Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_argb, + int depth, + int width) { + int shift = 8 - depth; + asm volatile( + + "vdup.16 q15, %5 \n" + "vmov.u8 d6, #0xff \n" // A (0xff) + "1: \n" + "vld1.16 {q2}, [%0]! \n" // R + "vld1.16 {q1}, [%1]! \n" // G + "vld1.16 {q0}, [%2]! \n" // B + "subs %4, %4, #8 \n" + "vshl.u16 q2, q2, q15 \n" + "vshl.u16 q1, q1, q15 \n" + "vshl.u16 q0, q0, q15 \n" + "vqmovn.u16 d5, q2 \n" + "vqmovn.u16 d4, q1 \n" + "vqmovn.u16 d3, q0 \n" + "vst4.u8 {d3, d4, d5, d6}, [%3]! \n" + "bgt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_argb), // %3 + "+r"(width) // %4 + : "r"(shift) // %5 + : "memory", "cc", "q0", "q1", "q2", "d6", "q15"); +} + // Copy multiple of 32. vld4.8 allow unaligned and is fastest on a15. void CopyRow_NEON(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "1: \n" - "vld1.8 {d0, d1, d2, d3}, [%0]! \n" // load 32 - "subs %2, %2, #32 \n" // 32 processed per loop - "vst1.8 {d0, d1, d2, d3}, [%1]! \n" // store 32 - "bgt 1b \n" + "1: \n" + "vld1.8 {d0, d1, d2, d3}, [%0]! \n" // load 32 + "subs %2, %2, #32 \n" // 32 processed per loop + "vst1.8 {d0, d1, d2, d3}, [%1]! \n" // store 32 + "bgt 1b \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 // Output registers @@ -654,11 +1194,11 @@ void CopyRow_NEON(const uint8_t* src, uint8_t* dst, int width) { // SetRow writes 'width' bytes using an 8 bit value repeated. void SetRow_NEON(uint8_t* dst, uint8_t v8, int width) { asm volatile( - "vdup.8 q0, %2 \n" // duplicate 16 bytes - "1: \n" - "subs %1, %1, #16 \n" // 16 bytes per loop - "vst1.8 {q0}, [%0]! \n" // store - "bgt 1b \n" + "vdup.8 q0, %2 \n" // duplicate 16 bytes + "1: \n" + "subs %1, %1, #16 \n" // 16 bytes per loop + "vst1.8 {q0}, [%0]! \n" // store + "bgt 1b \n" : "+r"(dst), // %0 "+r"(width) // %1 : "r"(v8) // %2 @@ -668,11 +1208,11 @@ void SetRow_NEON(uint8_t* dst, uint8_t v8, int width) { // ARGBSetRow writes 'width' pixels using an 32 bit value repeated. void ARGBSetRow_NEON(uint8_t* dst, uint32_t v32, int width) { asm volatile( - "vdup.u32 q0, %2 \n" // duplicate 4 ints - "1: \n" - "subs %1, %1, #4 \n" // 4 pixels per loop - "vst1.8 {q0}, [%0]! \n" // store - "bgt 1b \n" + "vdup.u32 q0, %2 \n" // duplicate 4 ints + "1: \n" + "subs %1, %1, #4 \n" // 4 pixels per loop + "vst1.8 {q0}, [%0]! \n" // store + "bgt 1b \n" : "+r"(dst), // %0 "+r"(width) // %1 : "r"(v32) // %2 @@ -682,41 +1222,62 @@ void ARGBSetRow_NEON(uint8_t* dst, uint32_t v32, int width) { void MirrorRow_NEON(const uint8_t* src, uint8_t* dst, int width) { asm volatile( // Start at end of source row. - "mov r3, #-16 \n" - "add %0, %0, %2 \n" - "sub %0, #16 \n" + "add %0, %0, %2 \n" + "sub %0, %0, #32 \n" // 32 bytes per loop - "1: \n" - "vld1.8 {q0}, [%0], r3 \n" // src -= 16 - "subs %2, #16 \n" // 16 pixels per loop. - "vrev64.8 q0, q0 \n" - "vst1.8 {d1}, [%1]! \n" // dst += 16 - "vst1.8 {d0}, [%1]! \n" - "bgt 1b \n" + "1: \n" + "vld1.8 {q1, q2}, [%0], %3 \n" // src -= 32 + "subs %2, #32 \n" // 32 pixels per loop. + "vrev64.8 q0, q2 \n" + "vrev64.8 q1, q1 \n" + "vswp d0, d1 \n" + "vswp d2, d3 \n" + "vst1.8 {q0, q1}, [%1]! \n" // dst += 32 + "bgt 1b \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 - : - : "cc", "memory", "r3", "q0"); + : "r"(-32) // %3 + : "cc", "memory", "q0", "q1", "q2"); } -void MirrorUVRow_NEON(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { +void MirrorUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_uv, int width) { asm volatile( // Start at end of source row. - "mov r12, #-16 \n" - "add %0, %0, %3, lsl #1 \n" - "sub %0, #16 \n" + "mov r12, #-16 \n" + "add %0, %0, %2, lsl #1 \n" + "sub %0, #16 \n" - "1: \n" - "vld2.8 {d0, d1}, [%0], r12 \n" // src -= 16 - "subs %3, #8 \n" // 8 pixels per loop. - "vrev64.8 q0, q0 \n" - "vst1.8 {d0}, [%1]! \n" // dst += 8 - "vst1.8 {d1}, [%2]! \n" - "bgt 1b \n" + "1: \n" + "vld2.8 {d0, d1}, [%0], r12 \n" // src -= 16 + "subs %2, #8 \n" // 8 pixels per loop. + "vrev64.8 q0, q0 \n" + "vst2.8 {d0, d1}, [%1]! \n" // dst += 16 + "bgt 1b \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(width) // %2 + : + : "cc", "memory", "r12", "q0"); +} + +void MirrorSplitUVRow_NEON(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + asm volatile( + // Start at end of source row. + "mov r12, #-16 \n" + "add %0, %0, %3, lsl #1 \n" + "sub %0, #16 \n" + + "1: \n" + "vld2.8 {d0, d1}, [%0], r12 \n" // src -= 16 + "subs %3, #8 \n" // 8 pixels per loop. + "vrev64.8 q0, q0 \n" + "vst1.8 {d0}, [%1]! \n" // dst += 8 + "vst1.8 {d1}, [%2]! \n" + "bgt 1b \n" : "+r"(src_uv), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -725,37 +1286,57 @@ void MirrorUVRow_NEON(const uint8_t* src_uv, : "cc", "memory", "r12", "q0"); } -void ARGBMirrorRow_NEON(const uint8_t* src, uint8_t* dst, int width) { +void ARGBMirrorRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width) { asm volatile( - // Start at end of source row. - "mov r3, #-16 \n" - "add %0, %0, %2, lsl #2 \n" - "sub %0, #16 \n" + "add %0, %0, %2, lsl #2 \n" + "sub %0, #32 \n" - "1: \n" - "vld1.8 {q0}, [%0], r3 \n" // src -= 16 - "subs %2, #4 \n" // 4 pixels per loop. - "vrev64.32 q0, q0 \n" - "vst1.8 {d1}, [%1]! \n" // dst += 16 - "vst1.8 {d0}, [%1]! \n" - "bgt 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : - : "cc", "memory", "r3", "q0"); + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0], %3 \n" // src -= 32 + "subs %2, #8 \n" // 8 pixels per loop. + "vrev64.8 d0, d0 \n" + "vrev64.8 d1, d1 \n" + "vrev64.8 d2, d2 \n" + "vrev64.8 d3, d3 \n" + "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // dst += 32 + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(-32) // %3 + : "cc", "memory", "d0", "d1", "d2", "d3"); +} + +void RGB24MirrorRow_NEON(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width) { + src_rgb24 += width * 3 - 24; + asm volatile( + "1: \n" + "vld3.8 {d0, d1, d2}, [%0], %3 \n" // src -= 24 + "subs %2, #8 \n" // 8 pixels per loop. + "vrev64.8 d0, d0 \n" + "vrev64.8 d1, d1 \n" + "vrev64.8 d2, d2 \n" + "vst3.8 {d0, d1, d2}, [%1]! \n" // dst += 24 + "bgt 1b \n" + : "+r"(src_rgb24), // %0 + "+r"(dst_rgb24), // %1 + "+r"(width) // %2 + : "r"(-24) // %3 + : "cc", "memory", "d0", "d1", "d2"); } void RGB24ToARGBRow_NEON(const uint8_t* src_rgb24, uint8_t* dst_argb, int width) { asm volatile( - "vmov.u8 d4, #255 \n" // Alpha - "1: \n" - "vld3.8 {d1, d2, d3}, [%0]! \n" // load 8 pixels of RGB24. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vst4.8 {d1, d2, d3, d4}, [%1]! \n" // store 8 pixels of ARGB. - "bgt 1b \n" + "vmov.u8 d4, #255 \n" // Alpha + "1: \n" + "vld3.8 {d1, d2, d3}, [%0]! \n" // load 8 pixels of RGB24. + "subs %2, %2, #8 \n" // 8 processed per loop. + "vst4.8 {d1, d2, d3, d4}, [%1]! \n" // store 8 pixels of ARGB. + "bgt 1b \n" : "+r"(src_rgb24), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -766,13 +1347,13 @@ void RGB24ToARGBRow_NEON(const uint8_t* src_rgb24, void RAWToARGBRow_NEON(const uint8_t* src_raw, uint8_t* dst_argb, int width) { asm volatile( - "vmov.u8 d4, #255 \n" // Alpha - "1: \n" - "vld3.8 {d1, d2, d3}, [%0]! \n" // load 8 pixels of RAW. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vswp.u8 d1, d3 \n" // swap R, B - "vst4.8 {d1, d2, d3, d4}, [%1]! \n" // store 8 pixels of ARGB. - "bgt 1b \n" + "vmov.u8 d4, #255 \n" // Alpha + "1: \n" + "vld3.8 {d1, d2, d3}, [%0]! \n" // load 8 pixels of RAW. + "subs %2, %2, #8 \n" // 8 processed per loop. + "vswp.u8 d1, d3 \n" // swap R, B + "vst4.8 {d1, d2, d3, d4}, [%1]! \n" // store 8 pixels of ARGB. + "bgt 1b \n" : "+r"(src_raw), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -781,20 +1362,37 @@ void RAWToARGBRow_NEON(const uint8_t* src_raw, uint8_t* dst_argb, int width) { ); } +void RAWToRGBARow_NEON(const uint8_t* src_raw, uint8_t* dst_rgba, int width) { + asm volatile( + "vmov.u8 d0, #255 \n" // Alpha + "1: \n" + "vld3.8 {d1, d2, d3}, [%0]! \n" // load 8 pixels of RAW. + "subs %2, %2, #8 \n" // 8 processed per loop. + "vswp.u8 d1, d3 \n" // swap R, B + "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // store 8 pixels of RGBA. + "bgt 1b \n" + : "+r"(src_raw), // %0 + "+r"(dst_rgba), // %1 + "+r"(width) // %2 + : + : "cc", "memory", "d0", "d1", "d2", "d3" // Clobber List + ); +} void RAWToRGB24Row_NEON(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { asm volatile( - "1: \n" - "vld3.8 {d1, d2, d3}, [%0]! \n" // load 8 pixels of RAW. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vswp.u8 d1, d3 \n" // swap R, B - "vst3.8 {d1, d2, d3}, [%1]! \n" // store 8 pixels of - // RGB24. - "bgt 1b \n" + "1: \n" + "vld3.8 {d0, d2, d4}, [%0]! \n" // load 16 pixels of RAW. + "vld3.8 {d1, d3, d5}, [%0]! \n" + "subs %2, %2, #16 \n" // 16 processed per loop. + "vswp.u8 q0, q2 \n" // swap R, B + "vst3.8 {d0, d2, d4}, [%1]! \n" // store 16 pixels of + "vst3.8 {d1, d3, d5}, [%1]! \n" // RGB24. + "bgt 1b \n" : "+r"(src_raw), // %0 "+r"(dst_rgb24), // %1 "+r"(width) // %2 : - : "cc", "memory", "d1", "d2", "d3" // Clobber List + : "cc", "memory", "q0", "q1", "q2" // Clobber List ); } @@ -814,13 +1412,13 @@ void RGB565ToARGBRow_NEON(const uint8_t* src_rgb565, uint8_t* dst_argb, int width) { asm volatile( - "vmov.u8 d3, #255 \n" // Alpha - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load 8 RGB565 pixels. - "subs %2, %2, #8 \n" // 8 processed per loop. + "vmov.u8 d3, #255 \n" // Alpha + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 8 RGB565 pixels. + "subs %2, %2, #8 \n" // 8 processed per loop. RGB565TOARGB - "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // store 8 pixels of ARGB. - "bgt 1b \n" + "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // store 8 pixels of ARGB. + "bgt 1b \n" : "+r"(src_rgb565), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -860,13 +1458,13 @@ void ARGB1555ToARGBRow_NEON(const uint8_t* src_argb1555, uint8_t* dst_argb, int width) { asm volatile( - "vmov.u8 d3, #255 \n" // Alpha - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load 8 ARGB1555 pixels. - "subs %2, %2, #8 \n" // 8 processed per loop. + "vmov.u8 d3, #255 \n" // Alpha + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 8 ARGB1555 pixels. + "subs %2, %2, #8 \n" // 8 processed per loop. ARGB1555TOARGB - "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // store 8 pixels of ARGB. - "bgt 1b \n" + "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // store 8 pixels of ARGB. + "bgt 1b \n" : "+r"(src_argb1555), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -889,13 +1487,13 @@ void ARGB4444ToARGBRow_NEON(const uint8_t* src_argb4444, uint8_t* dst_argb, int width) { asm volatile( - "vmov.u8 d3, #255 \n" // Alpha - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load 8 ARGB4444 pixels. - "subs %2, %2, #8 \n" // 8 processed per loop. + "vmov.u8 d3, #255 \n" // Alpha + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 8 ARGB4444 pixels. + "subs %2, %2, #8 \n" // 8 processed per loop. ARGB4444TOARGB - "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // store 8 pixels of ARGB. - "bgt 1b \n" + "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // store 8 pixels of ARGB. + "bgt 1b \n" : "+r"(src_argb4444), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -908,28 +1506,29 @@ void ARGBToRGB24Row_NEON(const uint8_t* src_argb, uint8_t* dst_rgb24, int width) { asm volatile( - "1: \n" - "vld4.8 {d1, d2, d3, d4}, [%0]! \n" // load 8 pixels of ARGB. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vst3.8 {d1, d2, d3}, [%1]! \n" // store 8 pixels of - // RGB24. - "bgt 1b \n" + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 16 pixels of ARGB. + "vld4.8 {d1, d3, d5, d7}, [%0]! \n" + "subs %2, %2, #16 \n" // 16 processed per loop. + "vst3.8 {d0, d2, d4}, [%1]! \n" // store 16 RGB24 pixels. + "vst3.8 {d1, d3, d5}, [%1]! \n" + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_rgb24), // %1 "+r"(width) // %2 : - : "cc", "memory", "d1", "d2", "d3", "d4" // Clobber List + : "cc", "memory", "q0", "q1", "q2", "q3" // Clobber List ); } void ARGBToRAWRow_NEON(const uint8_t* src_argb, uint8_t* dst_raw, int width) { asm volatile( - "1: \n" - "vld4.8 {d1, d2, d3, d4}, [%0]! \n" // load 8 pixels of ARGB. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vswp.u8 d1, d3 \n" // swap R, B - "vst3.8 {d1, d2, d3}, [%1]! \n" // store 8 pixels of RAW. - "bgt 1b \n" + "1: \n" + "vld4.8 {d1, d2, d3, d4}, [%0]! \n" // load 8 pixels of ARGB. + "subs %2, %2, #8 \n" // 8 processed per loop. + "vswp.u8 d1, d3 \n" // swap R, B + "vst3.8 {d1, d2, d3}, [%1]! \n" // store 8 pixels of RAW. + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_raw), // %1 "+r"(width) // %2 @@ -940,11 +1539,11 @@ void ARGBToRAWRow_NEON(const uint8_t* src_argb, uint8_t* dst_raw, int width) { void YUY2ToYRow_NEON(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { asm volatile( - "1: \n" - "vld2.8 {q0, q1}, [%0]! \n" // load 16 pixels of YUY2. - "subs %2, %2, #16 \n" // 16 processed per loop. - "vst1.8 {q0}, [%1]! \n" // store 16 pixels of Y. - "bgt 1b \n" + "1: \n" + "vld2.8 {q0, q1}, [%0]! \n" // load 16 pixels of YUY2. + "subs %2, %2, #16 \n" // 16 processed per loop. + "vst1.8 {q0}, [%1]! \n" // store 16 pixels of Y. + "bgt 1b \n" : "+r"(src_yuy2), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -955,11 +1554,11 @@ void YUY2ToYRow_NEON(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { void UYVYToYRow_NEON(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { asm volatile( - "1: \n" - "vld2.8 {q0, q1}, [%0]! \n" // load 16 pixels of UYVY. - "subs %2, %2, #16 \n" // 16 processed per loop. - "vst1.8 {q1}, [%1]! \n" // store 16 pixels of Y. - "bgt 1b \n" + "1: \n" + "vld2.8 {q0, q1}, [%0]! \n" // load 16 pixels of UYVY. + "subs %2, %2, #16 \n" // 16 processed per loop. + "vst1.8 {q1}, [%1]! \n" // store 16 pixels of Y. + "bgt 1b \n" : "+r"(src_uyvy), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -973,12 +1572,12 @@ void YUY2ToUV422Row_NEON(const uint8_t* src_yuy2, uint8_t* dst_v, int width) { asm volatile( - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 16 pixels of YUY2. - "subs %3, %3, #16 \n" // 16 pixels = 8 UVs. - "vst1.8 {d1}, [%1]! \n" // store 8 U. - "vst1.8 {d3}, [%2]! \n" // store 8 V. - "bgt 1b \n" + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 16 pixels of YUY2. + "subs %3, %3, #16 \n" // 16 pixels = 8 UVs. + "vst1.8 {d1}, [%1]! \n" // store 8 U. + "vst1.8 {d3}, [%2]! \n" // store 8 V. + "bgt 1b \n" : "+r"(src_yuy2), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -993,12 +1592,12 @@ void UYVYToUV422Row_NEON(const uint8_t* src_uyvy, uint8_t* dst_v, int width) { asm volatile( - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 16 pixels of UYVY. - "subs %3, %3, #16 \n" // 16 pixels = 8 UVs. - "vst1.8 {d0}, [%1]! \n" // store 8 U. - "vst1.8 {d2}, [%2]! \n" // store 8 V. - "bgt 1b \n" + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 16 pixels of UYVY. + "subs %3, %3, #16 \n" // 16 pixels = 8 UVs. + "vst1.8 {d0}, [%1]! \n" // store 8 U. + "vst1.8 {d2}, [%2]! \n" // store 8 V. + "bgt 1b \n" : "+r"(src_uyvy), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -1014,16 +1613,16 @@ void YUY2ToUVRow_NEON(const uint8_t* src_yuy2, uint8_t* dst_v, int width) { asm volatile( - "add %1, %0, %1 \n" // stride + src_yuy2 - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 16 pixels of YUY2. - "subs %4, %4, #16 \n" // 16 pixels = 8 UVs. - "vld4.8 {d4, d5, d6, d7}, [%1]! \n" // load next row YUY2. - "vrhadd.u8 d1, d1, d5 \n" // average rows of U - "vrhadd.u8 d3, d3, d7 \n" // average rows of V - "vst1.8 {d1}, [%2]! \n" // store 8 U. - "vst1.8 {d3}, [%3]! \n" // store 8 V. - "bgt 1b \n" + "add %1, %0, %1 \n" // stride + src_yuy2 + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 16 pixels of YUY2. + "vld4.8 {d4, d5, d6, d7}, [%1]! \n" // load next row YUY2. + "subs %4, %4, #16 \n" // 16 pixels = 8 UVs. + "vrhadd.u8 d1, d1, d5 \n" // average rows of U + "vrhadd.u8 d3, d3, d7 \n" // average rows of V + "vst1.8 {d1}, [%2]! \n" // store 8 U. + "vst1.8 {d3}, [%3]! \n" // store 8 V. + "bgt 1b \n" : "+r"(src_yuy2), // %0 "+r"(stride_yuy2), // %1 "+r"(dst_u), // %2 @@ -1041,16 +1640,16 @@ void UYVYToUVRow_NEON(const uint8_t* src_uyvy, uint8_t* dst_v, int width) { asm volatile( - "add %1, %0, %1 \n" // stride + src_uyvy - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 16 pixels of UYVY. - "subs %4, %4, #16 \n" // 16 pixels = 8 UVs. - "vld4.8 {d4, d5, d6, d7}, [%1]! \n" // load next row UYVY. - "vrhadd.u8 d0, d0, d4 \n" // average rows of U - "vrhadd.u8 d2, d2, d6 \n" // average rows of V - "vst1.8 {d0}, [%2]! \n" // store 8 U. - "vst1.8 {d2}, [%3]! \n" // store 8 V. - "bgt 1b \n" + "add %1, %0, %1 \n" // stride + src_uyvy + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 16 pixels of UYVY. + "vld4.8 {d4, d5, d6, d7}, [%1]! \n" // load next row UYVY. + "subs %4, %4, #16 \n" // 16 pixels = 8 UVs. + "vrhadd.u8 d0, d0, d4 \n" // average rows of U + "vrhadd.u8 d2, d2, d6 \n" // average rows of V + "vst1.8 {d0}, [%2]! \n" // store 8 U. + "vst1.8 {d2}, [%3]! \n" // store 8 V. + "bgt 1b \n" : "+r"(src_uyvy), // %0 "+r"(stride_uyvy), // %1 "+r"(dst_u), // %2 @@ -1062,20 +1661,43 @@ void UYVYToUVRow_NEON(const uint8_t* src_uyvy, ); } +void YUY2ToNVUVRow_NEON(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_uv, + int width) { + asm volatile( + "add %1, %0, %1 \n" // stride + src_yuy2 + "1: \n" + "vld2.8 {q0, q1}, [%0]! \n" // load 16 pixels of YUY2. + "subs %3, %3, #16 \n" // 16 pixels = 8 UVs. + "vld2.8 {q2, q3}, [%1]! \n" // load next row YUY2. + "vrhadd.u8 q4, q1, q3 \n" // average rows of UV + "vst1.8 {q4}, [%2]! \n" // store 8 UV. + "bgt 1b \n" + : "+r"(src_yuy2), // %0 + "+r"(stride_yuy2), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : + : "memory", "cc", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", + "d9" // Clobber List + ); +} + // For BGRAToARGB, ABGRToARGB, RGBAToARGB, and ARGBToRGBA. void ARGBShuffleRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, const uint8_t* shuffler, int width) { asm volatile( - "vld1.8 {q2}, [%3] \n" // shuffler - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load 4 pixels. - "subs %2, %2, #4 \n" // 4 processed per loop - "vtbl.8 d2, {d0, d1}, d4 \n" // look up 2 first pixels - "vtbl.8 d3, {d0, d1}, d5 \n" // look up 2 next pixels - "vst1.8 {q1}, [%1]! \n" // store 4. - "bgt 1b \n" + "vld1.8 {q2}, [%3] \n" // shuffler + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 4 pixels. + "subs %2, %2, #4 \n" // 4 processed per loop + "vtbl.8 d2, {d0, d1}, d4 \n" // look up 2 first pixels + "vtbl.8 d3, {d0, d1}, d5 \n" // look up 2 next pixels + "vst1.8 {q1}, [%1]! \n" // store 4. + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -1090,13 +1712,13 @@ void I422ToYUY2Row_NEON(const uint8_t* src_y, uint8_t* dst_yuy2, int width) { asm volatile( - "1: \n" - "vld2.8 {d0, d2}, [%0]! \n" // load 16 Ys - "vld1.8 {d1}, [%1]! \n" // load 8 Us - "vld1.8 {d3}, [%2]! \n" // load 8 Vs - "subs %4, %4, #16 \n" // 16 pixels - "vst4.8 {d0, d1, d2, d3}, [%3]! \n" // Store 8 YUY2/16 pixels. - "bgt 1b \n" + "1: \n" + "vld2.8 {d0, d2}, [%0]! \n" // load 16 Ys + "vld1.8 {d1}, [%1]! \n" // load 8 Us + "vld1.8 {d3}, [%2]! \n" // load 8 Vs + "subs %4, %4, #16 \n" // 16 pixels + "vst4.8 {d0, d1, d2, d3}, [%3]! \n" // Store 8 YUY2/16 pixels. + "bgt 1b \n" : "+r"(src_y), // %0 "+r"(src_u), // %1 "+r"(src_v), // %2 @@ -1112,13 +1734,13 @@ void I422ToUYVYRow_NEON(const uint8_t* src_y, uint8_t* dst_uyvy, int width) { asm volatile( - "1: \n" - "vld2.8 {d1, d3}, [%0]! \n" // load 16 Ys - "vld1.8 {d0}, [%1]! \n" // load 8 Us - "vld1.8 {d2}, [%2]! \n" // load 8 Vs - "subs %4, %4, #16 \n" // 16 pixels - "vst4.8 {d0, d1, d2, d3}, [%3]! \n" // Store 8 UYVY/16 pixels. - "bgt 1b \n" + "1: \n" + "vld2.8 {d1, d3}, [%0]! \n" // load 16 Ys + "vld1.8 {d0}, [%1]! \n" // load 8 Us + "vld1.8 {d2}, [%2]! \n" // load 8 Vs + "subs %4, %4, #16 \n" // 16 pixels + "vst4.8 {d0, d1, d2, d3}, [%3]! \n" // Store 8 UYVY/16 pixels. + "bgt 1b \n" : "+r"(src_y), // %0 "+r"(src_u), // %1 "+r"(src_v), // %2 @@ -1132,110 +1754,87 @@ void ARGBToRGB565Row_NEON(const uint8_t* src_argb, uint8_t* dst_rgb565, int width) { asm volatile( - "1: \n" - "vld4.8 {d20, d21, d22, d23}, [%0]! \n" // load 8 pixels of ARGB. - "subs %2, %2, #8 \n" // 8 processed per loop. + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 pixels of ARGB. + "subs %2, %2, #8 \n" // 8 processed per loop. ARGBTORGB565 - "vst1.8 {q0}, [%1]! \n" // store 8 pixels RGB565. - "bgt 1b \n" + "vst1.8 {q2}, [%1]! \n" // store 8 pixels RGB565. + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_rgb565), // %1 "+r"(width) // %2 : - : "cc", "memory", "q0", "q8", "q9", "q10", "q11"); + : "cc", "memory", "q0", "q1", "q2", "d6"); } void ARGBToRGB565DitherRow_NEON(const uint8_t* src_argb, uint8_t* dst_rgb, - const uint32_t dither4, + uint32_t dither4, int width) { asm volatile( - "vdup.32 d2, %2 \n" // dither4 - "1: \n" - "vld4.8 {d20, d21, d22, d23}, [%1]! \n" // load 8 pixels of ARGB. - "subs %3, %3, #8 \n" // 8 processed per loop. - "vqadd.u8 d20, d20, d2 \n" - "vqadd.u8 d21, d21, d2 \n" - "vqadd.u8 d22, d22, d2 \n" // add for dither + "vdup.32 d7, %3 \n" // dither4 + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 pixels of ARGB. + "subs %2, %2, #8 \n" // 8 processed per loop. + "vqadd.u8 d0, d0, d7 \n" + "vqadd.u8 d2, d2, d7 \n" + "vqadd.u8 d4, d4, d7 \n" // add for dither ARGBTORGB565 - "vst1.8 {q0}, [%0]! \n" // store 8 RGB565. - "bgt 1b \n" - : "+r"(dst_rgb) // %0 - : "r"(src_argb), // %1 - "r"(dither4), // %2 - "r"(width) // %3 - : "cc", "memory", "q0", "q1", "q8", "q9", "q10", "q11"); + "vst1.8 {q2}, [%1]! \n" // store 8 RGB565. + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_rgb), // %1 + "+r"(width) // %2 + : "r"(dither4) // %3 + : "cc", "memory", "q0", "q1", "q2", "q3"); } void ARGBToARGB1555Row_NEON(const uint8_t* src_argb, uint8_t* dst_argb1555, int width) { asm volatile( - "1: \n" - "vld4.8 {d20, d21, d22, d23}, [%0]! \n" // load 8 pixels of ARGB. - "subs %2, %2, #8 \n" // 8 processed per loop. + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 pixels of ARGB. + "subs %2, %2, #8 \n" // 8 processed per loop. ARGBTOARGB1555 - "vst1.8 {q0}, [%1]! \n" // store 8 ARGB1555. - "bgt 1b \n" + "vst1.8 {q3}, [%1]! \n" // store 8 ARGB1555. + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb1555), // %1 "+r"(width) // %2 : - : "cc", "memory", "q0", "q8", "q9", "q10", "q11"); + : "cc", "memory", "q0", "q1", "q2", "q3"); } void ARGBToARGB4444Row_NEON(const uint8_t* src_argb, uint8_t* dst_argb4444, int width) { asm volatile( - "vmov.u8 d4, #0x0f \n" // bits to clear with + "vmov.u8 d7, #0x0f \n" // bits to clear with // vbic. - "1: \n" - "vld4.8 {d20, d21, d22, d23}, [%0]! \n" // load 8 pixels of ARGB. - "subs %2, %2, #8 \n" // 8 processed per loop. + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 pixels of ARGB. + "subs %2, %2, #8 \n" // 8 processed per loop. ARGBTOARGB4444 - "vst1.8 {q0}, [%1]! \n" // store 8 ARGB4444. - "bgt 1b \n" + "vst1.8 {q0}, [%1]! \n" // store 8 ARGB4444. + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb4444), // %1 "+r"(width) // %2 : - : "cc", "memory", "q0", "q8", "q9", "q10", "q11"); -} - -void ARGBToYRow_NEON(const uint8_t* src_argb, uint8_t* dst_y, int width) { - asm volatile( - "vmov.u8 d24, #13 \n" // B * 0.1016 coefficient - "vmov.u8 d25, #65 \n" // G * 0.5078 coefficient - "vmov.u8 d26, #33 \n" // R * 0.2578 coefficient - "vmov.u8 d27, #16 \n" // Add 16 constant - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 ARGB pixels. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vmull.u8 q2, d0, d24 \n" // B - "vmlal.u8 q2, d1, d25 \n" // G - "vmlal.u8 q2, d2, d26 \n" // R - "vqrshrun.s16 d0, q2, #7 \n" // 16 bit to 8 bit Y - "vqadd.u8 d0, d27 \n" - "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. - "bgt 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : - : "cc", "memory", "q0", "q1", "q2", "q12", "q13"); + : "cc", "memory", "q0", "q1", "q2", "q3"); } void ARGBExtractAlphaRow_NEON(const uint8_t* src_argb, uint8_t* dst_a, int width) { asm volatile( - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels - "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ARGB pixels - "subs %2, %2, #16 \n" // 16 processed per loop - "vst1.8 {q3}, [%1]! \n" // store 16 A's. - "bgt 1b \n" + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels + "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ARGB pixels + "subs %2, %2, #16 \n" // 16 processed per loop + "vst1.8 {q3}, [%1]! \n" // store 16 A's. + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_a), // %1 "+r"(width) // %2 @@ -1244,66 +1843,133 @@ void ARGBExtractAlphaRow_NEON(const uint8_t* src_argb, ); } -void ARGBToYJRow_NEON(const uint8_t* src_argb, uint8_t* dst_y, int width) { +void ARGBCopyYToAlphaRow_NEON(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "vmov.u8 d24, #15 \n" // B * 0.11400 coefficient - "vmov.u8 d25, #75 \n" // G * 0.58700 coefficient - "vmov.u8 d26, #38 \n" // R * 0.29900 coefficient - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 ARGB pixels. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vmull.u8 q2, d0, d24 \n" // B - "vmlal.u8 q2, d1, d25 \n" // G - "vmlal.u8 q2, d2, d26 \n" // R - "vqrshrun.s16 d0, q2, #7 \n" // 15 bit to 8 bit Y - "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. - "bgt 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%1] \n" // load 8 ARGB + "pld [%0, #448] \n" + "vld1.8 {d3}, [%0]! \n" // replace A with 8 Y + "pld [%1, #448] \n" + "vst4.8 {d0, d1, d2, d3}, [%1]! \n" + "vld4.8 {d4, d5, d6, d7}, [%1] \n" // load 8 ARGB + "vld1.8 {d7}, [%0]! \n" // replace A with 8 Y + "vst4.8 {d4, d5, d6, d7}, [%1]! \n" + "subs %2, %2, #16 \n" + "bgt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 : - : "cc", "memory", "q0", "q1", "q2", "q12", "q13"); + : "cc", "memory", "q0", "q1", "q2", "q3"); } // 8x1 pixels. -void ARGBToUV444Row_NEON(const uint8_t* src_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { +void ARGBToUV444MatrixRow_NEON(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { asm volatile( - "vmov.u8 d24, #112 \n" // UB / VR 0.875 - // coefficient - "vmov.u8 d25, #74 \n" // UG -0.5781 coefficient - "vmov.u8 d26, #38 \n" // UR -0.2969 coefficient - "vmov.u8 d27, #18 \n" // VB -0.1406 coefficient - "vmov.u8 d28, #94 \n" // VG -0.7344 coefficient - "vmov.u16 q15, #0x8080 \n" // 128.5 - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 ARGB pixels. - "subs %3, %3, #8 \n" // 8 processed per loop. - "vmull.u8 q2, d0, d24 \n" // B - "vmlsl.u8 q2, d1, d25 \n" // G - "vmlsl.u8 q2, d2, d26 \n" // R - "vadd.u16 q2, q2, q15 \n" // +128 -> unsigned + "vld1.8 {d24}, [%4] \n" // load kRGBToU + "vld1.8 {d25}, [%5] \n" // load kRGBToV + "vld1.16 {d26[0]}, [%6] \n" // load kAddUV[0] + "vmovl.s8 q10, d24 \n" // U coeffs (8 shorts) + "vmovl.s8 q11, d25 \n" // V coeffs (8 shorts) + "vdup.16 q6, d26[0] \n" // bias + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 ARGB pixels. + "subs %3, %3, #8 \n" // 8 processed per loop. - "vmull.u8 q3, d2, d24 \n" // R - "vmlsl.u8 q3, d1, d28 \n" // G - "vmlsl.u8 q3, d0, d27 \n" // B - "vadd.u16 q3, q3, q15 \n" // +128 -> unsigned + "vmovl.u8 q4, d0 \n" // B + "vmovl.u8 q5, d1 \n" // G + "vmovl.u8 q7, d2 \n" // R + "vmovl.u8 q8, d3 \n" // A - "vqshrn.u16 d0, q2, #8 \n" // 16 bit to 8 bit U - "vqshrn.u16 d1, q3, #8 \n" // 16 bit to 8 bit V + "vdup.16 q12, d20[0] \n" + "vmul.s16 q2, q4, q12 \n" // U = B * U0 + "vdup.16 q12, d20[1] \n" + "vmla.s16 q2, q5, q12 \n" // U += G * U1 + "vdup.16 q12, d20[2] \n" + "vmla.s16 q2, q7, q12 \n" // U += R * U2 + "vdup.16 q12, d20[3] \n" + "vmla.s16 q2, q8, q12 \n" // U += A * U3 - "vst1.8 {d0}, [%1]! \n" // store 8 pixels U. - "vst1.8 {d1}, [%2]! \n" // store 8 pixels V. - "bgt 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+r"(width) // %3 - : - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q12", "q13", "q14", - "q15"); + "vdup.16 q12, d22[0] \n" + "vmul.s16 q3, q4, q12 \n" // V = B * V0 + "vdup.16 q12, d22[1] \n" + "vmla.s16 q3, q5, q12 \n" // V += G * V1 + "vdup.16 q12, d22[2] \n" + "vmla.s16 q3, q7, q12 \n" // V += R * V2 + "vdup.16 q12, d22[3] \n" + "vmla.s16 q3, q8, q12 \n" // V += A * V3 + + "vsubhn.s16 d0, q6, q2 \n" // 128.0 - U + "vsubhn.s16 d1, q6, q3 \n" // 128.0 - V + + "vst1.8 {d0}, [%1]! \n" // store 8 pixels U. + "vst1.8 {d1}, [%2]! \n" // store 8 pixels V. + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"(&c->kRGBToU), // %4 + "r"(&c->kRGBToV), // %5 + "r"(&c->kAddUV) // %6 + : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", + "q10", "q11", "q12", "q13"); +} + +// 8x1 pixels. +void RGBToUV444MatrixRow_NEON(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + asm volatile( + "vld1.8 {d24}, [%4] \n" // load kRGBToU + "vld1.8 {d25}, [%5] \n" // load kRGBToV + "vld1.16 {d26[0]}, [%6] \n" // load kAddUV[0] + "vmovl.s8 q10, d24 \n" // U coeffs (8 shorts) + "vmovl.s8 q11, d25 \n" // V coeffs (8 shorts) + "vdup.16 q6, d26[0] \n" // bias + "1: \n" + "vld3.8 {d0, d1, d2}, [%0]! \n" // load 8 RGB pixels. + "subs %3, %3, #8 \n" // 8 processed per loop. + + "vmovl.u8 q4, d0 \n" // B + "vmovl.u8 q5, d1 \n" // G + "vmovl.u8 q7, d2 \n" // R + + "vdup.16 q12, d20[0] \n" + "vmul.s16 q2, q4, q12 \n" // U = B * U0 + "vdup.16 q12, d20[1] \n" + "vmla.s16 q2, q5, q12 \n" // U += G * U1 + "vdup.16 q12, d20[2] \n" + "vmla.s16 q2, q7, q12 \n" // U += R * U2 + + "vdup.16 q12, d22[0] \n" + "vmul.s16 q3, q4, q12 \n" // V = B * V0 + "vdup.16 q12, d22[1] \n" + "vmla.s16 q3, q5, q12 \n" // V += G * V1 + "vdup.16 q12, d22[2] \n" + "vmla.s16 q3, q7, q12 \n" // V += R * V2 + + "vsubhn.s16 d0, q6, q2 \n" // 128.0 - U + "vsubhn.s16 d1, q6, q3 \n" // 128.0 - V + + "vst1.8 {d0}, [%1]! \n" // store 8 pixels U. + "vst1.8 {d1}, [%2]! \n" // store 8 pixels V. + "bgt 1b \n" + : "+r"(src_rgb), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"(&c->kRGBToU), // %4 + "r"(&c->kRGBToV), // %5 + "r"(&c->kAddUV) // %6 + : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q10", + "q11", "q12", "q13"); } // clang-format off @@ -1312,240 +1978,145 @@ void ARGBToUV444Row_NEON(const uint8_t* src_argb, "vmul.s16 q8, " #QB ", q10 \n" /* B */ \ "vmls.s16 q8, " #QG ", q11 \n" /* G */ \ "vmls.s16 q8, " #QR ", q12 \n" /* R */ \ - "vadd.u16 q8, q8, q15 \n" /* +128 -> unsigned */ \ "vmul.s16 q9, " #QR ", q10 \n" /* R */ \ "vmls.s16 q9, " #QG ", q14 \n" /* G */ \ "vmls.s16 q9, " #QB ", q13 \n" /* B */ \ - "vadd.u16 q9, q9, q15 \n" /* +128 -> unsigned */ \ - "vqshrn.u16 d0, q8, #8 \n" /* 16 bit to 8 bit U */ \ - "vqshrn.u16 d1, q9, #8 \n" /* 16 bit to 8 bit V */ + "vaddhn.u16 d0, q8, q15 \n" /* +128 -> unsigned */ \ + "vaddhn.u16 d1, q9, q15 \n" /* +128 -> unsigned */ // clang-format on // TODO(fbarchard): Consider vhadd vertical, then vpaddl horizontal, avoid shr. -void ARGBToUVRow_NEON(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - asm volatile ( - "add %1, %0, %1 \n" // src_stride + src_argb - "vmov.s16 q10, #112 / 2 \n" // UB / VR 0.875 coefficient - "vmov.s16 q11, #74 / 2 \n" // UG -0.5781 coefficient - "vmov.s16 q12, #38 / 2 \n" // UR -0.2969 coefficient - "vmov.s16 q13, #18 / 2 \n" // VB -0.1406 coefficient - "vmov.s16 q14, #94 / 2 \n" // VG -0.7344 coefficient - "vmov.u16 q15, #0x8080 \n" // 128.5 - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels. - "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ARGB pixels. - "vpaddl.u8 q0, q0 \n" // B 16 bytes -> 8 shorts. - "vpaddl.u8 q1, q1 \n" // G 16 bytes -> 8 shorts. - "vpaddl.u8 q2, q2 \n" // R 16 bytes -> 8 shorts. - "vld4.8 {d8, d10, d12, d14}, [%1]! \n" // load 8 more ARGB pixels. - "vld4.8 {d9, d11, d13, d15}, [%1]! \n" // load last 8 ARGB pixels. - "vpadal.u8 q0, q4 \n" // B 16 bytes -> 8 shorts. - "vpadal.u8 q1, q5 \n" // G 16 bytes -> 8 shorts. - "vpadal.u8 q2, q6 \n" // R 16 bytes -> 8 shorts. +void ARGBToUVMatrixRow_NEON(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + const uint8_t* src_argb_1 = src_argb + src_stride_argb; + asm volatile( + "vld1.8 {d24}, [%5] \n" // load kRGBToU (8 bytes, + // only 4 used) + "vld1.8 {d25}, [%6] \n" // load kRGBToV + "vmovl.s8 q14, d24 \n" // U coeffs in d28 + "vmovl.s8 q15, d25 \n" // V coeffs in d30 + "vmov.u16 q11, #0x8000 \n" // 128.0 bias - "vrshr.u16 q0, q0, #1 \n" // 2x average - "vrshr.u16 q1, q1, #1 \n" - "vrshr.u16 q2, q2, #1 \n" + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels. + "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ARGB + // pixels. + "subs %4, %4, #16 \n" // 16 processed per loop. + "vpaddl.u8 q0, q0 \n" // B 16 bytes -> 8 shorts. + "vpaddl.u8 q1, q1 \n" // G 16 bytes -> 8 shorts. + "vpaddl.u8 q2, q2 \n" // R 16 bytes -> 8 shorts. + "vpaddl.u8 q3, q3 \n" // A 16 bytes -> 8 shorts. + "vld4.8 {d8, d10, d12, d14}, [%1]! \n" // load 8 more pixels. + "vld4.8 {d9, d11, d13, d15}, [%1]! \n" + "vpadal.u8 q0, q4 \n" // B + "vpadal.u8 q1, q5 \n" // G + "vpadal.u8 q2, q6 \n" // R + "vpadal.u8 q3, q7 \n" // A - "subs %4, %4, #16 \n" // 32 processed per loop. - RGBTOUV(q0, q1, q2) - "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. - "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. - "bgt 1b \n" - : "+r"(src_argb), // %0 - "+r"(src_stride_argb), // %1 - "+r"(dst_u), // %2 - "+r"(dst_v), // %3 - "+r"(width) // %4 - : - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", - "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" - ); + "vrshr.u16 q0, q0, #2 \n" // average of 4 + "vrshr.u16 q1, q1, #2 \n" + "vrshr.u16 q2, q2, #2 \n" + "vrshr.u16 q3, q3, #2 \n" + + "vdup.16 q12, d28[0] \n" + "vmul.s16 q8, q0, q12 \n" // U = B * U0 + "vdup.16 q12, d28[1] \n" + "vmla.s16 q8, q1, q12 \n" // U += G * U1 + "vdup.16 q12, d28[2] \n" + "vmla.s16 q8, q2, q12 \n" // U += R * U2 + "vdup.16 q12, d28[3] \n" + "vmla.s16 q8, q3, q12 \n" // U += A * U3 + + "vdup.16 q12, d30[0] \n" + "vmul.s16 q9, q0, q12 \n" // V = B * V0 + "vdup.16 q12, d30[1] \n" + "vmla.s16 q9, q1, q12 \n" // V += G * V1 + "vdup.16 q12, d30[2] \n" + "vmla.s16 q9, q2, q12 \n" // V += R * V2 + "vdup.16 q12, d30[3] \n" + "vmla.s16 q9, q3, q12 \n" // V += A * V3 + + "vsubhn.s16 d0, q11, q8 \n" // 128.0 - U + "vsubhn.s16 d1, q11, q9 \n" // 128.0 - V + + "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. + "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(src_argb_1), // %1 + "+r"(dst_u), // %2 + "+r"(dst_v), // %3 + "+r"(width) // %4 + : "r"(&c->kRGBToU), // %5 + "r"(&c->kRGBToV) // %6 + : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", + "q9", "q11", "q12", "q14", "q15"); } -// TODO(fbarchard): Subsample match C code. -void ARGBToUVJRow_NEON(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - asm volatile ( - "add %1, %0, %1 \n" // src_stride + src_argb - "vmov.s16 q10, #127 / 2 \n" // UB / VR 0.500 coefficient - "vmov.s16 q11, #84 / 2 \n" // UG -0.33126 coefficient - "vmov.s16 q12, #43 / 2 \n" // UR -0.16874 coefficient - "vmov.s16 q13, #20 / 2 \n" // VB -0.08131 coefficient - "vmov.s16 q14, #107 / 2 \n" // VG -0.41869 coefficient - "vmov.u16 q15, #0x8080 \n" // 128.5 - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels. - "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ARGB pixels. - "vpaddl.u8 q0, q0 \n" // B 16 bytes -> 8 shorts. - "vpaddl.u8 q1, q1 \n" // G 16 bytes -> 8 shorts. - "vpaddl.u8 q2, q2 \n" // R 16 bytes -> 8 shorts. - "vld4.8 {d8, d10, d12, d14}, [%1]! \n" // load 8 more ARGB pixels. - "vld4.8 {d9, d11, d13, d15}, [%1]! \n" // load last 8 ARGB pixels. - "vpadal.u8 q0, q4 \n" // B 16 bytes -> 8 shorts. - "vpadal.u8 q1, q5 \n" // G 16 bytes -> 8 shorts. - "vpadal.u8 q2, q6 \n" // R 16 bytes -> 8 shorts. +void RGBToUVMatrixRow_NEON(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + const uint8_t* src_rgb_1 = src_rgb + src_stride_rgb; + asm volatile( + "vld1.8 {d24}, [%5] \n" // load kRGBToU + "vld1.8 {d25}, [%6] \n" // load kRGBToV + "vmovl.s8 q14, d24 \n" // U coeffs in d28 + "vmovl.s8 q15, d25 \n" // V coeffs in d30 + "vmov.u16 q11, #0x8000 \n" // 128.0 bias - "vrshr.u16 q0, q0, #1 \n" // 2x average - "vrshr.u16 q1, q1, #1 \n" - "vrshr.u16 q2, q2, #1 \n" + "1: \n" + "vld3.8 {d0, d2, d4}, [%0]! \n" // load 8 RGB pixels. + "vld3.8 {d1, d3, d5}, [%0]! \n" // load next 8 RGB pixels. + "subs %4, %4, #16 \n" // 16 processed per loop. + "vpaddl.u8 q0, q0 \n" // B 16 bytes -> 8 shorts. + "vpaddl.u8 q1, q1 \n" // G 16 bytes -> 8 shorts. + "vpaddl.u8 q2, q2 \n" // R 16 bytes -> 8 shorts. + "vld3.8 {d6, d8, d10}, [%1]! \n" // load 8 more pixels. + "vld3.8 {d7, d9, d11}, [%1]! \n" + "vpadal.u8 q0, q3 \n" // B + "vpadal.u8 q1, q4 \n" // G + "vpadal.u8 q2, q5 \n" // R - "subs %4, %4, #16 \n" // 32 processed per loop. - RGBTOUV(q0, q1, q2) - "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. - "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. - "bgt 1b \n" - : "+r"(src_argb), // %0 - "+r"(src_stride_argb), // %1 - "+r"(dst_u), // %2 - "+r"(dst_v), // %3 - "+r"(width) // %4 - : - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", - "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" - ); -} + "vrshr.u16 q0, q0, #2 \n" // average of 4 + "vrshr.u16 q1, q1, #2 \n" + "vrshr.u16 q2, q2, #2 \n" -void BGRAToUVRow_NEON(const uint8_t* src_bgra, - int src_stride_bgra, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - asm volatile ( - "add %1, %0, %1 \n" // src_stride + src_bgra - "vmov.s16 q10, #112 / 2 \n" // UB / VR 0.875 coefficient - "vmov.s16 q11, #74 / 2 \n" // UG -0.5781 coefficient - "vmov.s16 q12, #38 / 2 \n" // UR -0.2969 coefficient - "vmov.s16 q13, #18 / 2 \n" // VB -0.1406 coefficient - "vmov.s16 q14, #94 / 2 \n" // VG -0.7344 coefficient - "vmov.u16 q15, #0x8080 \n" // 128.5 - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 BGRA pixels. - "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 BGRA pixels. - "vpaddl.u8 q3, q3 \n" // B 16 bytes -> 8 shorts. - "vpaddl.u8 q2, q2 \n" // G 16 bytes -> 8 shorts. - "vpaddl.u8 q1, q1 \n" // R 16 bytes -> 8 shorts. - "vld4.8 {d8, d10, d12, d14}, [%1]! \n" // load 8 more BGRA pixels. - "vld4.8 {d9, d11, d13, d15}, [%1]! \n" // load last 8 BGRA pixels. - "vpadal.u8 q3, q7 \n" // B 16 bytes -> 8 shorts. - "vpadal.u8 q2, q6 \n" // G 16 bytes -> 8 shorts. - "vpadal.u8 q1, q5 \n" // R 16 bytes -> 8 shorts. + "vdup.16 q12, d28[0] \n" + "vmul.s16 q8, q0, q12 \n" // U = B * U0 + "vdup.16 q12, d28[1] \n" + "vmla.s16 q8, q1, q12 \n" // U += G * U1 + "vdup.16 q12, d28[2] \n" + "vmla.s16 q8, q2, q12 \n" // U += R * U2 - "vrshr.u16 q1, q1, #1 \n" // 2x average - "vrshr.u16 q2, q2, #1 \n" - "vrshr.u16 q3, q3, #1 \n" + "vdup.16 q12, d30[0] \n" + "vmul.s16 q9, q0, q12 \n" // V = B * V0 + "vdup.16 q12, d30[1] \n" + "vmla.s16 q9, q1, q12 \n" // V += G * V1 + "vdup.16 q12, d30[2] \n" + "vmla.s16 q9, q2, q12 \n" // V += R * V2 - "subs %4, %4, #16 \n" // 32 processed per loop. - RGBTOUV(q3, q2, q1) - "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. - "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. - "bgt 1b \n" - : "+r"(src_bgra), // %0 - "+r"(src_stride_bgra), // %1 - "+r"(dst_u), // %2 - "+r"(dst_v), // %3 - "+r"(width) // %4 - : - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", - "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" - ); -} + "vsubhn.s16 d0, q11, q8 \n" // 128.0 - U + "vsubhn.s16 d1, q11, q9 \n" // 128.0 - V -void ABGRToUVRow_NEON(const uint8_t* src_abgr, - int src_stride_abgr, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - asm volatile ( - "add %1, %0, %1 \n" // src_stride + src_abgr - "vmov.s16 q10, #112 / 2 \n" // UB / VR 0.875 coefficient - "vmov.s16 q11, #74 / 2 \n" // UG -0.5781 coefficient - "vmov.s16 q12, #38 / 2 \n" // UR -0.2969 coefficient - "vmov.s16 q13, #18 / 2 \n" // VB -0.1406 coefficient - "vmov.s16 q14, #94 / 2 \n" // VG -0.7344 coefficient - "vmov.u16 q15, #0x8080 \n" // 128.5 - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ABGR pixels. - "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ABGR pixels. - "vpaddl.u8 q2, q2 \n" // B 16 bytes -> 8 shorts. - "vpaddl.u8 q1, q1 \n" // G 16 bytes -> 8 shorts. - "vpaddl.u8 q0, q0 \n" // R 16 bytes -> 8 shorts. - "vld4.8 {d8, d10, d12, d14}, [%1]! \n" // load 8 more ABGR pixels. - "vld4.8 {d9, d11, d13, d15}, [%1]! \n" // load last 8 ABGR pixels. - "vpadal.u8 q2, q6 \n" // B 16 bytes -> 8 shorts. - "vpadal.u8 q1, q5 \n" // G 16 bytes -> 8 shorts. - "vpadal.u8 q0, q4 \n" // R 16 bytes -> 8 shorts. - - "vrshr.u16 q0, q0, #1 \n" // 2x average - "vrshr.u16 q1, q1, #1 \n" - "vrshr.u16 q2, q2, #1 \n" - - "subs %4, %4, #16 \n" // 32 processed per loop. - RGBTOUV(q2, q1, q0) - "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. - "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. - "bgt 1b \n" - : "+r"(src_abgr), // %0 - "+r"(src_stride_abgr), // %1 - "+r"(dst_u), // %2 - "+r"(dst_v), // %3 - "+r"(width) // %4 - : - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", - "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" - ); -} - -void RGBAToUVRow_NEON(const uint8_t* src_rgba, - int src_stride_rgba, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - asm volatile ( - "add %1, %0, %1 \n" // src_stride + src_rgba - "vmov.s16 q10, #112 / 2 \n" // UB / VR 0.875 coefficient - "vmov.s16 q11, #74 / 2 \n" // UG -0.5781 coefficient - "vmov.s16 q12, #38 / 2 \n" // UR -0.2969 coefficient - "vmov.s16 q13, #18 / 2 \n" // VB -0.1406 coefficient - "vmov.s16 q14, #94 / 2 \n" // VG -0.7344 coefficient - "vmov.u16 q15, #0x8080 \n" // 128.5 - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 RGBA pixels. - "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 RGBA pixels. - "vpaddl.u8 q0, q1 \n" // B 16 bytes -> 8 shorts. - "vpaddl.u8 q1, q2 \n" // G 16 bytes -> 8 shorts. - "vpaddl.u8 q2, q3 \n" // R 16 bytes -> 8 shorts. - "vld4.8 {d8, d10, d12, d14}, [%1]! \n" // load 8 more RGBA pixels. - "vld4.8 {d9, d11, d13, d15}, [%1]! \n" // load last 8 RGBA pixels. - "vpadal.u8 q0, q5 \n" // B 16 bytes -> 8 shorts. - "vpadal.u8 q1, q6 \n" // G 16 bytes -> 8 shorts. - "vpadal.u8 q2, q7 \n" // R 16 bytes -> 8 shorts. - - "vrshr.u16 q0, q0, #1 \n" // 2x average - "vrshr.u16 q1, q1, #1 \n" - "vrshr.u16 q2, q2, #1 \n" - - "subs %4, %4, #16 \n" // 32 processed per loop. - RGBTOUV(q0, q1, q2) - "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. - "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. - "bgt 1b \n" - : "+r"(src_rgba), // %0 - "+r"(src_stride_rgba), // %1 - "+r"(dst_u), // %2 - "+r"(dst_v), // %3 - "+r"(width) // %4 - : - : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", - "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" - ); + "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. + "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. + "bgt 1b \n" + : "+r"(src_rgb), // %0 + "+r"(src_rgb_1), // %1 + "+r"(dst_u), // %2 + "+r"(dst_v), // %3 + "+r"(width) // %4 + : "r"(&c->kRGBToU), // %5 + "r"(&c->kRGBToV) // %6 + : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q8", "q9", "q11", + "q12", "q14", "q15"); } void RGB24ToUVRow_NEON(const uint8_t* src_rgb24, @@ -1554,34 +2125,34 @@ void RGB24ToUVRow_NEON(const uint8_t* src_rgb24, uint8_t* dst_v, int width) { asm volatile ( - "add %1, %0, %1 \n" // src_stride + src_rgb24 - "vmov.s16 q10, #112 / 2 \n" // UB / VR 0.875 coefficient - "vmov.s16 q11, #74 / 2 \n" // UG -0.5781 coefficient - "vmov.s16 q12, #38 / 2 \n" // UR -0.2969 coefficient - "vmov.s16 q13, #18 / 2 \n" // VB -0.1406 coefficient - "vmov.s16 q14, #94 / 2 \n" // VG -0.7344 coefficient - "vmov.u16 q15, #0x8080 \n" // 128.5 - "1: \n" - "vld3.8 {d0, d2, d4}, [%0]! \n" // load 8 RGB24 pixels. - "vld3.8 {d1, d3, d5}, [%0]! \n" // load next 8 RGB24 pixels. - "vpaddl.u8 q0, q0 \n" // B 16 bytes -> 8 shorts. - "vpaddl.u8 q1, q1 \n" // G 16 bytes -> 8 shorts. - "vpaddl.u8 q2, q2 \n" // R 16 bytes -> 8 shorts. - "vld3.8 {d8, d10, d12}, [%1]! \n" // load 8 more RGB24 pixels. - "vld3.8 {d9, d11, d13}, [%1]! \n" // load last 8 RGB24 pixels. - "vpadal.u8 q0, q4 \n" // B 16 bytes -> 8 shorts. - "vpadal.u8 q1, q5 \n" // G 16 bytes -> 8 shorts. - "vpadal.u8 q2, q6 \n" // R 16 bytes -> 8 shorts. + "add %1, %0, %1 \n" // src_stride + src_rgb24 + "vmov.s16 q10, #112 \n" // UB/VR 0.875 coefficient + "vmov.s16 q11, #74 \n" // UG -0.5781 coefficient + "vmov.s16 q12, #38 \n" // UR -0.2969 coefficient + "vmov.s16 q13, #18 \n" // VB -0.1406 coefficient + "vmov.s16 q14, #94 \n" // VG -0.7344 coefficient + "vmov.u16 q15, #0x8000 \n" // 128.0 + "1: \n" + "vld3.8 {d0, d2, d4}, [%0]! \n" // load 8 RGB24 pixels. + "vld3.8 {d1, d3, d5}, [%0]! \n" // load next 8 RGB24 pixels. + "subs %4, %4, #16 \n" // 16 processed per loop. + "vpaddl.u8 q0, q0 \n" // B 16 bytes -> 8 shorts. + "vpaddl.u8 q1, q1 \n" // G 16 bytes -> 8 shorts. + "vpaddl.u8 q2, q2 \n" // R 16 bytes -> 8 shorts. + "vld3.8 {d8, d10, d12}, [%1]! \n" // load 8 more RGB24 pixels. + "vld3.8 {d9, d11, d13}, [%1]! \n" // load last 8 RGB24 pixels. + "vpadal.u8 q0, q4 \n" // B 16 bytes -> 8 shorts. + "vpadal.u8 q1, q5 \n" // G 16 bytes -> 8 shorts. + "vpadal.u8 q2, q6 \n" // R 16 bytes -> 8 shorts. - "vrshr.u16 q0, q0, #1 \n" // 2x average - "vrshr.u16 q1, q1, #1 \n" - "vrshr.u16 q2, q2, #1 \n" + "vrshr.u16 q0, q0, #2 \n" // average of 4 + "vrshr.u16 q1, q1, #2 \n" + "vrshr.u16 q2, q2, #2 \n" - "subs %4, %4, #16 \n" // 32 processed per loop. RGBTOUV(q0, q1, q2) - "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. - "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. - "bgt 1b \n" + "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. + "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. + "bgt 1b \n" : "+r"(src_rgb24), // %0 "+r"(src_stride_rgb24), // %1 "+r"(dst_u), // %2 @@ -1599,34 +2170,34 @@ void RAWToUVRow_NEON(const uint8_t* src_raw, uint8_t* dst_v, int width) { asm volatile ( - "add %1, %0, %1 \n" // src_stride + src_raw - "vmov.s16 q10, #112 / 2 \n" // UB / VR 0.875 coefficient - "vmov.s16 q11, #74 / 2 \n" // UG -0.5781 coefficient - "vmov.s16 q12, #38 / 2 \n" // UR -0.2969 coefficient - "vmov.s16 q13, #18 / 2 \n" // VB -0.1406 coefficient - "vmov.s16 q14, #94 / 2 \n" // VG -0.7344 coefficient - "vmov.u16 q15, #0x8080 \n" // 128.5 - "1: \n" - "vld3.8 {d0, d2, d4}, [%0]! \n" // load 8 RAW pixels. - "vld3.8 {d1, d3, d5}, [%0]! \n" // load next 8 RAW pixels. - "vpaddl.u8 q2, q2 \n" // B 16 bytes -> 8 shorts. - "vpaddl.u8 q1, q1 \n" // G 16 bytes -> 8 shorts. - "vpaddl.u8 q0, q0 \n" // R 16 bytes -> 8 shorts. - "vld3.8 {d8, d10, d12}, [%1]! \n" // load 8 more RAW pixels. - "vld3.8 {d9, d11, d13}, [%1]! \n" // load last 8 RAW pixels. - "vpadal.u8 q2, q6 \n" // B 16 bytes -> 8 shorts. - "vpadal.u8 q1, q5 \n" // G 16 bytes -> 8 shorts. - "vpadal.u8 q0, q4 \n" // R 16 bytes -> 8 shorts. + "add %1, %0, %1 \n" // src_stride + src_raw + "vmov.s16 q10, #112 \n" // UB/VR 0.875 coefficient + "vmov.s16 q11, #74 \n" // UG -0.5781 coefficient + "vmov.s16 q12, #38 \n" // UR -0.2969 coefficient + "vmov.s16 q13, #18 \n" // VB -0.1406 coefficient + "vmov.s16 q14, #94 \n" // VG -0.7344 coefficient + "vmov.u16 q15, #0x8000 \n" // 128.0 + "1: \n" + "vld3.8 {d0, d2, d4}, [%0]! \n" // load 8 RAW pixels. + "vld3.8 {d1, d3, d5}, [%0]! \n" // load next 8 RAW pixels. + "subs %4, %4, #16 \n" // 16 processed per loop. + "vpaddl.u8 q2, q2 \n" // B 16 bytes -> 8 shorts. + "vpaddl.u8 q1, q1 \n" // G 16 bytes -> 8 shorts. + "vpaddl.u8 q0, q0 \n" // R 16 bytes -> 8 shorts. + "vld3.8 {d8, d10, d12}, [%1]! \n" // load 8 more RAW pixels. + "vld3.8 {d9, d11, d13}, [%1]! \n" // load last 8 RAW pixels. + "vpadal.u8 q2, q6 \n" // B 16 bytes -> 8 shorts. + "vpadal.u8 q1, q5 \n" // G 16 bytes -> 8 shorts. + "vpadal.u8 q0, q4 \n" // R 16 bytes -> 8 shorts. - "vrshr.u16 q0, q0, #1 \n" // 2x average - "vrshr.u16 q1, q1, #1 \n" - "vrshr.u16 q2, q2, #1 \n" + "vrshr.u16 q0, q0, #2 \n" // average of 4 + "vrshr.u16 q1, q1, #2 \n" + "vrshr.u16 q2, q2, #2 \n" - "subs %4, %4, #16 \n" // 32 processed per loop. RGBTOUV(q2, q1, q0) - "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. - "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. - "bgt 1b \n" + "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. + "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. + "bgt 1b \n" : "+r"(src_raw), // %0 "+r"(src_stride_raw), // %1 "+r"(dst_u), // %2 @@ -1645,55 +2216,54 @@ void RGB565ToUVRow_NEON(const uint8_t* src_rgb565, uint8_t* dst_v, int width) { asm volatile( - "add %1, %0, %1 \n" // src_stride + src_argb - "vmov.s16 q10, #112 / 2 \n" // UB / VR 0.875 - // coefficient - "vmov.s16 q11, #74 / 2 \n" // UG -0.5781 coefficient - "vmov.s16 q12, #38 / 2 \n" // UR -0.2969 coefficient - "vmov.s16 q13, #18 / 2 \n" // VB -0.1406 coefficient - "vmov.s16 q14, #94 / 2 \n" // VG -0.7344 coefficient - "vmov.u16 q15, #0x8080 \n" // 128.5 - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load 8 RGB565 pixels. + "add %1, %0, %1 \n" // src_stride + src_argb + "vmov.s16 q10, #112 \n" // UB/VR 0.875 coefficient + "vmov.s16 q11, #74 \n" // UG -0.5781 coefficient + "vmov.s16 q12, #38 \n" // UR -0.2969 coefficient + "vmov.s16 q13, #18 \n" // VB -0.1406 coefficient + "vmov.s16 q14, #94 \n" // VG -0.7344 coefficient + "vmov.u16 q15, #0x8000 \n" // 128.0 + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 8 RGB565 pixels. + "subs %4, %4, #16 \n" // 16 processed per loop. RGB565TOARGB - "vpaddl.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. - "vpaddl.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. - "vpaddl.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. - "vld1.8 {q0}, [%0]! \n" // next 8 RGB565 pixels. + "vpaddl.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. + "vpaddl.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. + "vpaddl.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. + "vld1.8 {q0}, [%0]! \n" // next 8 RGB565 pixels. RGB565TOARGB - "vpaddl.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. - "vpaddl.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. - "vpaddl.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. + "vpaddl.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. + "vpaddl.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. + "vpaddl.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. - "vld1.8 {q0}, [%1]! \n" // load 8 RGB565 pixels. + "vld1.8 {q0}, [%1]! \n" // load 8 RGB565 pixels. RGB565TOARGB - "vpadal.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. - "vpadal.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. - "vpadal.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. - "vld1.8 {q0}, [%1]! \n" // next 8 RGB565 pixels. + "vpadal.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. + "vpadal.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. + "vpadal.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. + "vld1.8 {q0}, [%1]! \n" // next 8 RGB565 pixels. RGB565TOARGB - "vpadal.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. - "vpadal.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. - "vpadal.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. + "vpadal.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. + "vpadal.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. + "vpadal.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. - "vrshr.u16 q4, q4, #1 \n" // 2x average - "vrshr.u16 q5, q5, #1 \n" - "vrshr.u16 q6, q6, #1 \n" + "vrshr.u16 q4, q4, #2 \n" // average of 4 + "vrshr.u16 q5, q5, #2 \n" + "vrshr.u16 q6, q6, #2 \n" - "subs %4, %4, #16 \n" // 16 processed per loop. - "vmul.s16 q8, q4, q10 \n" // B - "vmls.s16 q8, q5, q11 \n" // G - "vmls.s16 q8, q6, q12 \n" // R - "vadd.u16 q8, q8, q15 \n" // +128 -> unsigned - "vmul.s16 q9, q6, q10 \n" // R - "vmls.s16 q9, q5, q14 \n" // G - "vmls.s16 q9, q4, q13 \n" // B - "vadd.u16 q9, q9, q15 \n" // +128 -> unsigned + "vmul.s16 q8, q4, q10 \n" // B + "vmls.s16 q8, q5, q11 \n" // G + "vmls.s16 q8, q6, q12 \n" // R + "vadd.u16 q8, q8, q15 \n" // +128 -> unsigned + "vmul.s16 q9, q6, q10 \n" // R + "vmls.s16 q9, q5, q14 \n" // G + "vmls.s16 q9, q4, q13 \n" // B + "vadd.u16 q9, q9, q15 \n" // +128 -> unsigned "vqshrn.u16 d0, q8, #8 \n" // 16 bit to 8 bit U "vqshrn.u16 d1, q9, #8 \n" // 16 bit to 8 bit V - "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. - "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. - "bgt 1b \n" + "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. + "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. + "bgt 1b \n" : "+r"(src_rgb565), // %0 "+r"(src_stride_rgb565), // %1 "+r"(dst_u), // %2 @@ -1711,55 +2281,54 @@ void ARGB1555ToUVRow_NEON(const uint8_t* src_argb1555, uint8_t* dst_v, int width) { asm volatile( - "add %1, %0, %1 \n" // src_stride + src_argb - "vmov.s16 q10, #112 / 2 \n" // UB / VR 0.875 - // coefficient - "vmov.s16 q11, #74 / 2 \n" // UG -0.5781 coefficient - "vmov.s16 q12, #38 / 2 \n" // UR -0.2969 coefficient - "vmov.s16 q13, #18 / 2 \n" // VB -0.1406 coefficient - "vmov.s16 q14, #94 / 2 \n" // VG -0.7344 coefficient - "vmov.u16 q15, #0x8080 \n" // 128.5 - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load 8 ARGB1555 pixels. + "add %1, %0, %1 \n" // src_stride + src_argb + "vmov.s16 q10, #112 \n" // UB/VR 0.875 coefficient + "vmov.s16 q11, #74 \n" // UG -0.5781 coefficient + "vmov.s16 q12, #38 \n" // UR -0.2969 coefficient + "vmov.s16 q13, #18 \n" // VB -0.1406 coefficient + "vmov.s16 q14, #94 \n" // VG -0.7344 coefficient + "vmov.u16 q15, #0x8000 \n" // 128.0 + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 8 ARGB1555 pixels. + "subs %4, %4, #16 \n" // 16 processed per loop. RGB555TOARGB - "vpaddl.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. - "vpaddl.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. - "vpaddl.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. - "vld1.8 {q0}, [%0]! \n" // next 8 ARGB1555 pixels. + "vpaddl.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. + "vpaddl.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. + "vpaddl.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. + "vld1.8 {q0}, [%0]! \n" // next 8 ARGB1555 pixels. RGB555TOARGB - "vpaddl.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. - "vpaddl.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. - "vpaddl.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. + "vpaddl.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. + "vpaddl.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. + "vpaddl.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. - "vld1.8 {q0}, [%1]! \n" // load 8 ARGB1555 pixels. + "vld1.8 {q0}, [%1]! \n" // load 8 ARGB1555 pixels. RGB555TOARGB - "vpadal.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. - "vpadal.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. - "vpadal.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. - "vld1.8 {q0}, [%1]! \n" // next 8 ARGB1555 pixels. + "vpadal.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. + "vpadal.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. + "vpadal.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. + "vld1.8 {q0}, [%1]! \n" // next 8 ARGB1555 pixels. RGB555TOARGB - "vpadal.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. - "vpadal.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. - "vpadal.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. + "vpadal.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. + "vpadal.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. + "vpadal.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. - "vrshr.u16 q4, q4, #1 \n" // 2x average - "vrshr.u16 q5, q5, #1 \n" - "vrshr.u16 q6, q6, #1 \n" + "vrshr.u16 q4, q4, #2 \n" // average of 4 + "vrshr.u16 q5, q5, #2 \n" + "vrshr.u16 q6, q6, #2 \n" - "subs %4, %4, #16 \n" // 16 processed per loop. - "vmul.s16 q8, q4, q10 \n" // B - "vmls.s16 q8, q5, q11 \n" // G - "vmls.s16 q8, q6, q12 \n" // R - "vadd.u16 q8, q8, q15 \n" // +128 -> unsigned - "vmul.s16 q9, q6, q10 \n" // R - "vmls.s16 q9, q5, q14 \n" // G - "vmls.s16 q9, q4, q13 \n" // B - "vadd.u16 q9, q9, q15 \n" // +128 -> unsigned + "vmul.s16 q8, q4, q10 \n" // B + "vmls.s16 q8, q5, q11 \n" // G + "vmls.s16 q8, q6, q12 \n" // R + "vadd.u16 q8, q8, q15 \n" // +128 -> unsigned + "vmul.s16 q9, q6, q10 \n" // R + "vmls.s16 q9, q5, q14 \n" // G + "vmls.s16 q9, q4, q13 \n" // B + "vadd.u16 q9, q9, q15 \n" // +128 -> unsigned "vqshrn.u16 d0, q8, #8 \n" // 16 bit to 8 bit U "vqshrn.u16 d1, q9, #8 \n" // 16 bit to 8 bit V - "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. - "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. - "bgt 1b \n" + "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. + "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. + "bgt 1b \n" : "+r"(src_argb1555), // %0 "+r"(src_stride_argb1555), // %1 "+r"(dst_u), // %2 @@ -1776,56 +2345,46 @@ void ARGB4444ToUVRow_NEON(const uint8_t* src_argb4444, uint8_t* dst_u, uint8_t* dst_v, int width) { - asm volatile( - "add %1, %0, %1 \n" // src_stride + src_argb - "vmov.s16 q10, #112 / 2 \n" // UB / VR 0.875 - // coefficient - "vmov.s16 q11, #74 / 2 \n" // UG -0.5781 coefficient - "vmov.s16 q12, #38 / 2 \n" // UR -0.2969 coefficient - "vmov.s16 q13, #18 / 2 \n" // VB -0.1406 coefficient - "vmov.s16 q14, #94 / 2 \n" // VG -0.7344 coefficient - "vmov.u16 q15, #0x8080 \n" // 128.5 - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load 8 ARGB4444 pixels. + asm volatile ( + "add %1, %0, %1 \n" // src_stride + src_argb + "vmov.s16 q10, #112 \n" // UB/VR 0.875 coefficient + "vmov.s16 q11, #74 \n" // UG -0.5781 coefficient + "vmov.s16 q12, #38 \n" // UR -0.2969 coefficient + "vmov.s16 q13, #18 \n" // VB -0.1406 coefficient + "vmov.s16 q14, #94 \n" // VG -0.7344 coefficient + "vmov.u16 q15, #0x8000 \n" // 128.0 + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 8 ARGB4444 pixels. + "subs %4, %4, #16 \n" // 16 processed per loop. ARGB4444TOARGB - "vpaddl.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. - "vpaddl.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. - "vpaddl.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. - "vld1.8 {q0}, [%0]! \n" // next 8 ARGB4444 pixels. + "vpaddl.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. + "vpaddl.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. + "vpaddl.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. + "vld1.8 {q0}, [%0]! \n" // next 8 ARGB4444 pixels. ARGB4444TOARGB - "vpaddl.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. - "vpaddl.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. - "vpaddl.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. + "vpaddl.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. + "vpaddl.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. + "vpaddl.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. - "vld1.8 {q0}, [%1]! \n" // load 8 ARGB4444 pixels. + "vld1.8 {q0}, [%1]! \n" // load 8 ARGB4444 pixels. ARGB4444TOARGB - "vpadal.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. - "vpadal.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. - "vpadal.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. - "vld1.8 {q0}, [%1]! \n" // next 8 ARGB4444 pixels. + "vpadal.u8 d8, d0 \n" // B 8 bytes -> 4 shorts. + "vpadal.u8 d10, d1 \n" // G 8 bytes -> 4 shorts. + "vpadal.u8 d12, d2 \n" // R 8 bytes -> 4 shorts. + "vld1.8 {q0}, [%1]! \n" // next 8 ARGB4444 pixels. ARGB4444TOARGB - "vpadal.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. - "vpadal.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. - "vpadal.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. + "vpadal.u8 d9, d0 \n" // B 8 bytes -> 4 shorts. + "vpadal.u8 d11, d1 \n" // G 8 bytes -> 4 shorts. + "vpadal.u8 d13, d2 \n" // R 8 bytes -> 4 shorts. - "vrshr.u16 q4, q4, #1 \n" // 2x average - "vrshr.u16 q5, q5, #1 \n" - "vrshr.u16 q6, q6, #1 \n" + "vrshr.u16 q0, q4, #2 \n" // average of 4 + "vrshr.u16 q1, q5, #2 \n" + "vrshr.u16 q2, q6, #2 \n" - "subs %4, %4, #16 \n" // 16 processed per loop. - "vmul.s16 q8, q4, q10 \n" // B - "vmls.s16 q8, q5, q11 \n" // G - "vmls.s16 q8, q6, q12 \n" // R - "vadd.u16 q8, q8, q15 \n" // +128 -> unsigned - "vmul.s16 q9, q6, q10 \n" // R - "vmls.s16 q9, q5, q14 \n" // G - "vmls.s16 q9, q4, q13 \n" // B - "vadd.u16 q9, q9, q15 \n" // +128 -> unsigned - "vqshrn.u16 d0, q8, #8 \n" // 16 bit to 8 bit U - "vqshrn.u16 d1, q9, #8 \n" // 16 bit to 8 bit V - "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. - "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. - "bgt 1b \n" + RGBTOUV(q0, q1, q2) + "vst1.8 {d0}, [%2]! \n" // store 8 pixels U. + "vst1.8 {d1}, [%3]! \n" // store 8 pixels V. + "bgt 1b \n" : "+r"(src_argb4444), // %0 "+r"(src_stride_argb4444), // %1 "+r"(dst_u), // %2 @@ -1838,21 +2397,21 @@ void ARGB4444ToUVRow_NEON(const uint8_t* src_argb4444, void RGB565ToYRow_NEON(const uint8_t* src_rgb565, uint8_t* dst_y, int width) { asm volatile( - "vmov.u8 d24, #13 \n" // B * 0.1016 coefficient - "vmov.u8 d25, #65 \n" // G * 0.5078 coefficient - "vmov.u8 d26, #33 \n" // R * 0.2578 coefficient - "vmov.u8 d27, #16 \n" // Add 16 constant - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load 8 RGB565 pixels. - "subs %2, %2, #8 \n" // 8 processed per loop. + "vmov.u8 d24, #25 \n" // B * 0.1016 coefficient + "vmov.u8 d25, #129 \n" // G * 0.5078 coefficient + "vmov.u8 d26, #66 \n" // R * 0.2578 coefficient + "vmov.u8 d27, #16 \n" // Add 16 constant + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 8 RGB565 pixels. + "subs %2, %2, #8 \n" // 8 processed per loop. RGB565TOARGB - "vmull.u8 q2, d0, d24 \n" // B - "vmlal.u8 q2, d1, d25 \n" // G - "vmlal.u8 q2, d2, d26 \n" // R - "vqrshrun.s16 d0, q2, #7 \n" // 16 bit to 8 bit Y - "vqadd.u8 d0, d27 \n" - "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. - "bgt 1b \n" + "vmull.u8 q2, d0, d24 \n" // B + "vmlal.u8 q2, d1, d25 \n" // G + "vmlal.u8 q2, d2, d26 \n" // R + "vqrshrn.u16 d0, q2, #8 \n" // 16 bit to 8 bit Y + "vqadd.u8 d0, d27 \n" + "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. + "bgt 1b \n" : "+r"(src_rgb565), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -1864,21 +2423,21 @@ void ARGB1555ToYRow_NEON(const uint8_t* src_argb1555, uint8_t* dst_y, int width) { asm volatile( - "vmov.u8 d24, #13 \n" // B * 0.1016 coefficient - "vmov.u8 d25, #65 \n" // G * 0.5078 coefficient - "vmov.u8 d26, #33 \n" // R * 0.2578 coefficient - "vmov.u8 d27, #16 \n" // Add 16 constant - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load 8 ARGB1555 pixels. - "subs %2, %2, #8 \n" // 8 processed per loop. + "vmov.u8 d24, #25 \n" // B * 0.1016 coefficient + "vmov.u8 d25, #129 \n" // G * 0.5078 coefficient + "vmov.u8 d26, #66 \n" // R * 0.2578 coefficient + "vmov.u8 d27, #16 \n" // Add 16 constant + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 8 ARGB1555 pixels. + "subs %2, %2, #8 \n" // 8 processed per loop. ARGB1555TOARGB - "vmull.u8 q2, d0, d24 \n" // B - "vmlal.u8 q2, d1, d25 \n" // G - "vmlal.u8 q2, d2, d26 \n" // R - "vqrshrun.s16 d0, q2, #7 \n" // 16 bit to 8 bit Y - "vqadd.u8 d0, d27 \n" - "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. - "bgt 1b \n" + "vmull.u8 q2, d0, d24 \n" // B + "vmlal.u8 q2, d1, d25 \n" // G + "vmlal.u8 q2, d2, d26 \n" // R + "vqrshrn.u16 d0, q2, #8 \n" // 16 bit to 8 bit Y + "vqadd.u8 d0, d27 \n" + "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. + "bgt 1b \n" : "+r"(src_argb1555), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -1890,21 +2449,21 @@ void ARGB4444ToYRow_NEON(const uint8_t* src_argb4444, uint8_t* dst_y, int width) { asm volatile( - "vmov.u8 d24, #13 \n" // B * 0.1016 coefficient - "vmov.u8 d25, #65 \n" // G * 0.5078 coefficient - "vmov.u8 d26, #33 \n" // R * 0.2578 coefficient - "vmov.u8 d27, #16 \n" // Add 16 constant - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load 8 ARGB4444 pixels. - "subs %2, %2, #8 \n" // 8 processed per loop. + "vmov.u8 d24, #25 \n" // B * 0.1016 coefficient + "vmov.u8 d25, #129 \n" // G * 0.5078 coefficient + "vmov.u8 d26, #66 \n" // R * 0.2578 coefficient + "vmov.u8 d27, #16 \n" // Add 16 constant + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 8 ARGB4444 pixels. + "subs %2, %2, #8 \n" // 8 processed per loop. ARGB4444TOARGB - "vmull.u8 q2, d0, d24 \n" // B - "vmlal.u8 q2, d1, d25 \n" // G - "vmlal.u8 q2, d2, d26 \n" // R - "vqrshrun.s16 d0, q2, #7 \n" // 16 bit to 8 bit Y - "vqadd.u8 d0, d27 \n" - "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. - "bgt 1b \n" + "vmull.u8 q2, d0, d24 \n" // B + "vmlal.u8 q2, d1, d25 \n" // G + "vmlal.u8 q2, d2, d26 \n" // R + "vqrshrn.u16 d0, q2, #8 \n" // 16 bit to 8 bit Y + "vqadd.u8 d0, d27 \n" + "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. + "bgt 1b \n" : "+r"(src_argb4444), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -1912,119 +2471,178 @@ void ARGB4444ToYRow_NEON(const uint8_t* src_argb4444, : "cc", "memory", "q0", "q1", "q2", "q3", "q12", "q13"); } -void BGRAToYRow_NEON(const uint8_t* src_bgra, uint8_t* dst_y, int width) { +void ARGBToAR64Row_NEON(const uint8_t* src_argb, + uint16_t* dst_ar64, + int width) { asm volatile( - "vmov.u8 d4, #33 \n" // R * 0.2578 coefficient - "vmov.u8 d5, #65 \n" // G * 0.5078 coefficient - "vmov.u8 d6, #13 \n" // B * 0.1016 coefficient - "vmov.u8 d7, #16 \n" // Add 16 constant - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 pixels of BGRA. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vmull.u8 q8, d1, d4 \n" // R - "vmlal.u8 q8, d2, d5 \n" // G - "vmlal.u8 q8, d3, d6 \n" // B - "vqrshrun.s16 d0, q8, #7 \n" // 16 bit to 8 bit Y - "vqadd.u8 d0, d7 \n" - "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. - "bgt 1b \n" - : "+r"(src_bgra), // %0 - "+r"(dst_y), // %1 + "1: \n" + "vld1.8 {q0}, [%0]! \n" + "vld1.8 {q2}, [%0]! \n" + "subs %2, %2, #8 \n" // 8 processed per loop. + "vmov.u8 q1, q0 \n" + "vmov.u8 q3, q2 \n" + "vst2.8 {q0, q1}, [%1]! \n" // store 4 pixels + "vst2.8 {q2, q3}, [%1]! \n" // store 4 pixels + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_ar64), // %1 "+r"(width) // %2 : - : "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "q8"); + : "cc", "memory", "q0", "q1", "q2", "q3"); } -void ABGRToYRow_NEON(const uint8_t* src_abgr, uint8_t* dst_y, int width) { +static const uvec8 kShuffleARGBToABGR = {2, 1, 0, 3, 6, 5, 4, 7, + 10, 9, 8, 11, 14, 13, 12, 15}; + +void ARGBToAB64Row_NEON(const uint8_t* src_argb, + uint16_t* dst_ab64, + int width) { asm volatile( - "vmov.u8 d4, #33 \n" // R * 0.2578 coefficient - "vmov.u8 d5, #65 \n" // G * 0.5078 coefficient - "vmov.u8 d6, #13 \n" // B * 0.1016 coefficient - "vmov.u8 d7, #16 \n" // Add 16 constant - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 pixels of ABGR. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vmull.u8 q8, d0, d4 \n" // R - "vmlal.u8 q8, d1, d5 \n" // G - "vmlal.u8 q8, d2, d6 \n" // B - "vqrshrun.s16 d0, q8, #7 \n" // 16 bit to 8 bit Y - "vqadd.u8 d0, d7 \n" - "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. - "bgt 1b \n" - : "+r"(src_abgr), // %0 - "+r"(dst_y), // %1 + "vld1.8 {q4}, [%3] \n" // shuffler + + "1: \n" + "vld1.8 {q0}, [%0]! \n" + "vld1.8 {q2}, [%0]! \n" + "subs %2, %2, #8 \n" // 8 processed per loop. + "vtbl.8 d2, {d0, d1}, d8 \n" + "vtbl.8 d3, {d0, d1}, d9 \n" + "vtbl.8 d6, {d4, d5}, d8 \n" + "vtbl.8 d7, {d4, d5}, d9 \n" + "vmov.u8 q0, q1 \n" + "vmov.u8 q2, q3 \n" + "vst2.8 {q0, q1}, [%1]! \n" // store 4 pixels + "vst2.8 {q2, q3}, [%1]! \n" // store 4 pixels + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_ab64), // %1 + "+r"(width) // %2 + : "r"(&kShuffleARGBToABGR) // %3 + : "cc", "memory", "q0", "q1", "q2", "q3", "q4"); +} + +void AR64ToARGBRow_NEON(const uint16_t* src_ar64, + uint8_t* dst_argb, + int width) { + asm volatile( + "1: \n" + "vld1.16 {q0}, [%0]! \n" + "vld1.16 {q1}, [%0]! \n" + "vld1.16 {q2}, [%0]! \n" + "vld1.16 {q3}, [%0]! \n" + "subs %2, %2, #8 \n" // 8 processed per loop. + "vshrn.u16 d0, q0, #8 \n" + "vshrn.u16 d1, q1, #8 \n" + "vshrn.u16 d4, q2, #8 \n" + "vshrn.u16 d5, q3, #8 \n" + "vst1.8 {q0}, [%1]! \n" // store 4 pixels + "vst1.8 {q2}, [%1]! \n" // store 4 pixels + "bgt 1b \n" + : "+r"(src_ar64), // %0 + "+r"(dst_argb), // %1 "+r"(width) // %2 : - : "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "q8"); + : "cc", "memory", "q0", "q1", "q2", "q3"); } -void RGBAToYRow_NEON(const uint8_t* src_rgba, uint8_t* dst_y, int width) { +static const uvec8 kShuffleAB64ToARGB = {5, 3, 1, 7, 13, 11, 9, 15}; + +void AB64ToARGBRow_NEON(const uint16_t* src_ab64, + uint8_t* dst_argb, + int width) { asm volatile( - "vmov.u8 d4, #13 \n" // B * 0.1016 coefficient - "vmov.u8 d5, #65 \n" // G * 0.5078 coefficient - "vmov.u8 d6, #33 \n" // R * 0.2578 coefficient - "vmov.u8 d7, #16 \n" // Add 16 constant - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 pixels of RGBA. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vmull.u8 q8, d1, d4 \n" // B - "vmlal.u8 q8, d2, d5 \n" // G - "vmlal.u8 q8, d3, d6 \n" // R - "vqrshrun.s16 d0, q8, #7 \n" // 16 bit to 8 bit Y - "vqadd.u8 d0, d7 \n" - "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. - "bgt 1b \n" - : "+r"(src_rgba), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : - : "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "q8"); + "vld1.8 {d8}, [%3] \n" // shuffler + + "1: \n" + "vld1.16 {q0}, [%0]! \n" + "vld1.16 {q1}, [%0]! \n" + "vld1.16 {q2}, [%0]! \n" + "vld1.16 {q3}, [%0]! \n" + "subs %2, %2, #8 \n" // 8 processed per loop. + "vtbl.8 d0, {d0, d1}, d8 \n" + "vtbl.8 d1, {d2, d3}, d8 \n" + "vtbl.8 d4, {d4, d5}, d8 \n" + "vtbl.8 d5, {d6, d7}, d8 \n" + "vst1.8 {q0}, [%1]! \n" // store 4 pixels + "vst1.8 {q2}, [%1]! \n" // store 4 pixels + "bgt 1b \n" + : "+r"(src_ab64), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(&kShuffleAB64ToARGB) // %3 + : "cc", "memory", "q0", "q1", "q2", "q3", "q4"); } -void RGB24ToYRow_NEON(const uint8_t* src_rgb24, uint8_t* dst_y, int width) { +// ARGB expects first 3 values to contain RGB and 4th value is ignored. +void ARGBToYMatrixRow_NEON(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { asm volatile( - "vmov.u8 d4, #13 \n" // B * 0.1016 coefficient - "vmov.u8 d5, #65 \n" // G * 0.5078 coefficient - "vmov.u8 d6, #33 \n" // R * 0.2578 coefficient - "vmov.u8 d7, #16 \n" // Add 16 constant - "1: \n" - "vld3.8 {d0, d1, d2}, [%0]! \n" // load 8 pixels of RGB24. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vmull.u8 q8, d0, d4 \n" // B - "vmlal.u8 q8, d1, d5 \n" // G - "vmlal.u8 q8, d2, d6 \n" // R - "vqrshrun.s16 d0, q8, #7 \n" // 16 bit to 8 bit Y - "vqadd.u8 d0, d7 \n" - "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. - "bgt 1b \n" - : "+r"(src_rgb24), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : - : "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "q8"); + "vld1.8 {d24}, [%3] \n" // load kRGBToY + "vld1.16 {d25[0]}, [%4] \n" // load kAddY[0] + "vdup.8 d20, d24[0] \n" // B + "vdup.8 d21, d24[1] \n" // G + "vdup.8 d22, d24[2] \n" // R + "vdup.8 d23, d24[3] \n" // A + "vdup.16 q12, d25[0] \n" // bias + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 pixels of ARGB + "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 pixels + "subs %1, %1, #16 \n" // 16 processed per loop. + "vmull.u8 q8, d0, d20 \n" // B + "vmull.u8 q9, d1, d20 \n" + "vmlal.u8 q8, d2, d21 \n" // G + "vmlal.u8 q9, d3, d21 \n" + "vmlal.u8 q8, d4, d22 \n" // R + "vmlal.u8 q9, d5, d22 \n" + "vmlal.u8 q8, d6, d23 \n" // A + "vmlal.u8 q9, d7, d23 \n" + "vaddhn.u16 d0, q8, q12 \n" // 16 bit to 8 bit Y + "vaddhn.u16 d1, q9, q12 \n" + "vst1.8 {d0, d1}, [%2]! \n" // store 16 pixels Y. + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(width), // %1 + "+r"(dst_y) // %2 + : "r"(&c->kRGBToY), // %3 + "r"(&c->kAddY) // %4 + : "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", + "d24", "d25"); } -void RAWToYRow_NEON(const uint8_t* src_raw, uint8_t* dst_y, int width) { +void RGBToYMatrixRow_NEON(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { asm volatile( - "vmov.u8 d4, #33 \n" // R * 0.2578 coefficient - "vmov.u8 d5, #65 \n" // G * 0.5078 coefficient - "vmov.u8 d6, #13 \n" // B * 0.1016 coefficient - "vmov.u8 d7, #16 \n" // Add 16 constant - "1: \n" - "vld3.8 {d0, d1, d2}, [%0]! \n" // load 8 pixels of RAW. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vmull.u8 q8, d0, d4 \n" // B - "vmlal.u8 q8, d1, d5 \n" // G - "vmlal.u8 q8, d2, d6 \n" // R - "vqrshrun.s16 d0, q8, #7 \n" // 16 bit to 8 bit Y - "vqadd.u8 d0, d7 \n" - "vst1.8 {d0}, [%1]! \n" // store 8 pixels Y. - "bgt 1b \n" - : "+r"(src_raw), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : - : "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "q8"); + "vld1.8 {d24}, [%3] \n" // load kRGBToY + "vld1.16 {d25[0]}, [%4] \n" // load kAddY[0] + "vdup.8 d20, d24[0] \n" // BY + "vdup.8 d21, d24[1] \n" // GY + "vdup.8 d22, d24[2] \n" // RY + "vdup.16 q12, d25[0] \n" // AY + "1: \n" + "vld3.8 {d2, d4, d6}, [%0]! \n" // load 16 pixels of + // RGB24. + "vld3.8 {d3, d5, d7}, [%0]! \n" + "subs %2, %2, #16 \n" // 16 processed per loop. + "vmull.u8 q8, d2, d20 \n" // B + "vmull.u8 q9, d3, d20 \n" + "vmlal.u8 q8, d4, d21 \n" // G + "vmlal.u8 q9, d5, d21 \n" + "vmlal.u8 q8, d6, d22 \n" // R + "vmlal.u8 q9, d7, d22 \n" + "vaddhn.u16 d0, q8, q12 \n" // 16 bit to 8 bit Y + "vaddhn.u16 d1, q9, q12 \n" + "vst1.8 {d0, d1}, [%1]! \n" // store 16 pixels Y. + "bgt 1b \n" + : "+r"(src_rgb), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(&c->kRGBToY), // %3 + "r"(&c->kAddY) // %4 + : "cc", "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11", "q12", + "d24", "d25"); } // Bilinear filter 16x2 -> 16x1 @@ -2035,48 +2653,48 @@ void InterpolateRow_NEON(uint8_t* dst_ptr, int source_y_fraction) { int y1_fraction = source_y_fraction; asm volatile( - "cmp %4, #0 \n" - "beq 100f \n" - "add %2, %1 \n" - "cmp %4, #128 \n" - "beq 50f \n" + "cmp %4, #0 \n" + "beq 100f \n" + "add %2, %1 \n" + "cmp %4, #128 \n" + "beq 50f \n" - "vdup.8 d5, %4 \n" - "rsb %4, #256 \n" - "vdup.8 d4, %4 \n" + "vdup.8 d5, %4 \n" + "rsb %4, #256 \n" + "vdup.8 d4, %4 \n" // General purpose row blend. - "1: \n" - "vld1.8 {q0}, [%1]! \n" - "vld1.8 {q1}, [%2]! \n" - "subs %3, %3, #16 \n" - "vmull.u8 q13, d0, d4 \n" - "vmull.u8 q14, d1, d4 \n" - "vmlal.u8 q13, d2, d5 \n" - "vmlal.u8 q14, d3, d5 \n" - "vrshrn.u16 d0, q13, #8 \n" - "vrshrn.u16 d1, q14, #8 \n" - "vst1.8 {q0}, [%0]! \n" - "bgt 1b \n" - "b 99f \n" + "1: \n" + "vld1.8 {q0}, [%1]! \n" + "vld1.8 {q1}, [%2]! \n" + "subs %3, %3, #16 \n" + "vmull.u8 q13, d0, d4 \n" + "vmull.u8 q14, d1, d4 \n" + "vmlal.u8 q13, d2, d5 \n" + "vmlal.u8 q14, d3, d5 \n" + "vrshrn.u16 d0, q13, #8 \n" + "vrshrn.u16 d1, q14, #8 \n" + "vst1.8 {q0}, [%0]! \n" + "bgt 1b \n" + "b 99f \n" // Blend 50 / 50. - "50: \n" - "vld1.8 {q0}, [%1]! \n" - "vld1.8 {q1}, [%2]! \n" - "subs %3, %3, #16 \n" - "vrhadd.u8 q0, q1 \n" - "vst1.8 {q0}, [%0]! \n" - "bgt 50b \n" - "b 99f \n" + "50: \n" + "vld1.8 {q0}, [%1]! \n" + "vld1.8 {q1}, [%2]! \n" + "subs %3, %3, #16 \n" + "vrhadd.u8 q0, q1 \n" + "vst1.8 {q0}, [%0]! \n" + "bgt 50b \n" + "b 99f \n" // Blend 100 / 0 - Copy row unchanged. - "100: \n" - "vld1.8 {q0}, [%1]! \n" - "subs %3, %3, #16 \n" - "vst1.8 {q0}, [%0]! \n" - "bgt 100b \n" + "100: \n" + "vld1.8 {q0}, [%1]! \n" + "subs %3, %3, #16 \n" + "vst1.8 {q0}, [%0]! \n" + "bgt 100b \n" - "99: \n" + "99: \n" : "+r"(dst_ptr), // %0 "+r"(src_ptr), // %1 "+r"(src_stride), // %2 @@ -2086,59 +2704,119 @@ void InterpolateRow_NEON(uint8_t* dst_ptr, : "cc", "memory", "q0", "q1", "d4", "d5", "q13", "q14"); } +// Bilinear filter 8x2 -> 8x1 +void InterpolateRow_16_NEON(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int dst_width, + int source_y_fraction) { + int y1_fraction = source_y_fraction; + int y0_fraction = 256 - y1_fraction; + const uint16_t* src_ptr1 = src_ptr + src_stride; + + asm volatile( + "cmp %4, #0 \n" + "beq 100f \n" + "cmp %4, #128 \n" + "beq 50f \n" + + "vdup.16 d17, %4 \n" + "vdup.16 d16, %5 \n" + // General purpose row blend. + "1: \n" + "vld1.16 {q0}, [%1]! \n" + "vld1.16 {q1}, [%2]! \n" + "subs %3, %3, #8 \n" + "vmull.u16 q2, d0, d16 \n" + "vmull.u16 q3, d1, d16 \n" + "vmlal.u16 q2, d2, d17 \n" + "vmlal.u16 q3, d3, d17 \n" + "vrshrn.u32 d0, q2, #8 \n" + "vrshrn.u32 d1, q3, #8 \n" + "vst1.16 {q0}, [%0]! \n" + "bgt 1b \n" + "b 99f \n" + + // Blend 50 / 50. + "50: \n" + "vld1.16 {q0}, [%1]! \n" + "vld1.16 {q1}, [%2]! \n" + "subs %3, %3, #8 \n" + "vrhadd.u16 q0, q1 \n" + "vst1.16 {q0}, [%0]! \n" + "bgt 50b \n" + "b 99f \n" + + // Blend 100 / 0 - Copy row unchanged. + "100: \n" + "vld1.16 {q0}, [%1]! \n" + "subs %3, %3, #8 \n" + "vst1.16 {q0}, [%0]! \n" + "bgt 100b \n" + + "99: \n" + : "+r"(dst_ptr), // %0 + "+r"(src_ptr), // %1 + "+r"(src_ptr1), // %2 + "+r"(dst_width) // %3 + : "r"(y1_fraction), // %4 + "r"(y0_fraction) // %5 + : "cc", "memory", "q0", "q1", "q2", "q3", "q8"); +} + // dr * (256 - sa) / 256 + sr = dr - dr * sa / 256 + sr -void ARGBBlendRow_NEON(const uint8_t* src_argb0, +void ARGBBlendRow_NEON(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( - "subs %3, #8 \n" - "blt 89f \n" + "subs %3, #8 \n" + "blt 89f \n" // Blend 8 pixels. - "8: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 pixels of ARGB0. - "vld4.8 {d4, d5, d6, d7}, [%1]! \n" // load 8 pixels of ARGB1. - "subs %3, %3, #8 \n" // 8 processed per loop. - "vmull.u8 q10, d4, d3 \n" // db * a - "vmull.u8 q11, d5, d3 \n" // dg * a - "vmull.u8 q12, d6, d3 \n" // dr * a + "8: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 pixels of ARGB0. + "vld4.8 {d4, d5, d6, d7}, [%1]! \n" // load 8 pixels of ARGB1. + "subs %3, %3, #8 \n" // 8 processed per loop. + "vmull.u8 q10, d4, d3 \n" // db * a + "vmull.u8 q11, d5, d3 \n" // dg * a + "vmull.u8 q12, d6, d3 \n" // dr * a "vqrshrn.u16 d20, q10, #8 \n" // db >>= 8 "vqrshrn.u16 d21, q11, #8 \n" // dg >>= 8 "vqrshrn.u16 d22, q12, #8 \n" // dr >>= 8 - "vqsub.u8 q2, q2, q10 \n" // dbg - dbg * a / 256 - "vqsub.u8 d6, d6, d22 \n" // dr - dr * a / 256 - "vqadd.u8 q0, q0, q2 \n" // + sbg - "vqadd.u8 d2, d2, d6 \n" // + sr - "vmov.u8 d3, #255 \n" // a = 255 - "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 pixels of ARGB. - "bge 8b \n" + "vqsub.u8 q2, q2, q10 \n" // dbg - dbg * a / 256 + "vqsub.u8 d6, d6, d22 \n" // dr - dr * a / 256 + "vqadd.u8 q0, q0, q2 \n" // + sbg + "vqadd.u8 d2, d2, d6 \n" // + sr + "vmov.u8 d3, #255 \n" // a = 255 + "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 pixels of ARGB. + "bge 8b \n" - "89: \n" - "adds %3, #8-1 \n" - "blt 99f \n" + "89: \n" + "adds %3, #8-1 \n" + "blt 99f \n" // Blend 1 pixels. - "1: \n" - "vld4.8 {d0[0],d1[0],d2[0],d3[0]}, [%0]! \n" // load 1 pixel ARGB0. - "vld4.8 {d4[0],d5[0],d6[0],d7[0]}, [%1]! \n" // load 1 pixel ARGB1. - "subs %3, %3, #1 \n" // 1 processed per loop. - "vmull.u8 q10, d4, d3 \n" // db * a - "vmull.u8 q11, d5, d3 \n" // dg * a - "vmull.u8 q12, d6, d3 \n" // dr * a - "vqrshrn.u16 d20, q10, #8 \n" // db >>= 8 - "vqrshrn.u16 d21, q11, #8 \n" // dg >>= 8 - "vqrshrn.u16 d22, q12, #8 \n" // dr >>= 8 - "vqsub.u8 q2, q2, q10 \n" // dbg - dbg * a / 256 - "vqsub.u8 d6, d6, d22 \n" // dr - dr * a / 256 - "vqadd.u8 q0, q0, q2 \n" // + sbg - "vqadd.u8 d2, d2, d6 \n" // + sr - "vmov.u8 d3, #255 \n" // a = 255 - "vst4.8 {d0[0],d1[0],d2[0],d3[0]}, [%2]! \n" // store 1 pixel. - "bge 1b \n" + "1: \n" + "vld4.8 {d0[0],d1[0],d2[0],d3[0]}, [%0]! \n" // load 1 pixel ARGB0. + "vld4.8 {d4[0],d5[0],d6[0],d7[0]}, [%1]! \n" // load 1 pixel ARGB1. + "subs %3, %3, #1 \n" // 1 processed per loop. + "vmull.u8 q10, d4, d3 \n" // db * a + "vmull.u8 q11, d5, d3 \n" // dg * a + "vmull.u8 q12, d6, d3 \n" // dr * a + "vqrshrn.u16 d20, q10, #8 \n" // db >>= 8 + "vqrshrn.u16 d21, q11, #8 \n" // dg >>= 8 + "vqrshrn.u16 d22, q12, #8 \n" // dr >>= 8 + "vqsub.u8 q2, q2, q10 \n" // dbg - dbg * a / 256 + "vqsub.u8 d6, d6, d22 \n" // dr - dr * a / 256 + "vqadd.u8 q0, q0, q2 \n" // + sbg + "vqadd.u8 d2, d2, d6 \n" // + sr + "vmov.u8 d3, #255 \n" // a = 255 + "vst4.8 {d0[0],d1[0],d2[0],d3[0]}, [%2]! \n" // store 1 pixel. + "bge 1b \n" - "99: \n" + "99: \n" - : "+r"(src_argb0), // %0 + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -2146,28 +2824,127 @@ void ARGBBlendRow_NEON(const uint8_t* src_argb0, : "cc", "memory", "q0", "q1", "q2", "q3", "q10", "q11", "q12"); } +void ARGBOrRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + asm volatile( + "vdup.32 q2, %3 \n" + "1: \n" + "vld1.8 {q0, q1}, [%0]! \n" + "subs %2, %2, #8 \n" + "vorr q0, q0, q2 \n" + "vorr q1, q1, q2 \n" + "vst1.8 {q0, q1}, [%1]! \n" + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(value) // %3 + : "memory", "cc", "q0", "q1", "q2"); +} + +void ARGBAlphaBlendRow_NEON(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + asm volatile( + "vmov.u8 d28, #255 \n" + "vmov.i16 q15, #1 \n" + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" + "vld4.8 {d4, d5, d6, d7}, [%1]! \n" + "subs %3, %3, #8 \n" + "vmov q8, q15 \n" + "vmlal.u8 q8, d7, d3 \n" + "vsra.u16 q8, q8, #8 \n" + "vshrn.i16 d16, q8, #8 \n" + "vsub.i8 d16, d3, d16 \n" + "vadd.i8 d7, d7, d16 \n" + "vceq.i8 d17, d7, #0 \n" + "vorr d18, d3, d17 \n" + "vorr d19, d7, d17 \n" + "vmull.u8 q8, d18, d28 \n" + "vmovl.u8 q9, d19 \n" + "vmovl.u16 q10, d16 \n" + "vmovl.u16 q11, d17 \n" + "vmovl.u16 q12, d18 \n" + "vmovl.u16 q13, d19 \n" + "vcvt.f32.u32 q10, q10 \n" + "vcvt.f32.u32 q11, q11 \n" + "vcvt.f32.u32 q12, q12 \n" + "vcvt.f32.u32 q13, q13 \n" + "vrecpe.f32 q8, q12 \n" + "vrecpe.f32 q9, q13 \n" + "vrecps.f32 q4, q12, q8 \n" + "vrecps.f32 q5, q13, q9 \n" + "vmul.f32 q8, q8, q4 \n" + "vmul.f32 q9, q9, q5 \n" + "vrecps.f32 q4, q12, q8 \n" + "vrecps.f32 q5, q13, q9 \n" + "vmul.f32 q8, q8, q4 \n" + "vmul.f32 q9, q9, q5 \n" + "vsra.u32 q8, q8, #29 \n" + "vsra.u32 q9, q9, #29 \n" + "vmul.f32 q10, q10, q8 \n" + "vmul.f32 q11, q11, q9 \n" + "vcvt.u32.f32 q10, q10 \n" + "vcvt.u32.f32 q11, q11 \n" + "vmovn.i32 d16, q10 \n" + "vmovn.i32 d17, q11 \n" + "vmovn.i16 d16, q8 \n" + "vsub.i8 d17, d28, d16 \n" + "vmov q9, q15 \n" + "vmov q10, q15 \n" + "vmov q11, q15 \n" + "vmlal.u8 q9, d4, d17 \n" + "vmlal.u8 q10, d5, d17 \n" + "vmlal.u8 q11, d6, d17 \n" + "vmlal.u8 q9, d0, d16 \n" + "vmlal.u8 q10, d1, d16 \n" + "vmlal.u8 q11, d2, d16 \n" + "vsra.u16 q9, q9, #8 \n" + "vsra.u16 q10, q10, #8 \n" + "vsra.u16 q11, q11, #8 \n" + "vshrn.i16 d0, q9, #8 \n" + "vshrn.i16 d1, q10, #8 \n" + "vshrn.i16 d2, q11, #8 \n" + "vmov d3, d7 \n" + "vst4.8 {d0, d1, d2, d3}, [%2]! \n" + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(src_argb1), // %1 + "+r"(dst_argb), // %2 + "+r"(width) // %3 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q8", "q9", "q10", + "q11", "q12", "q13", "q14", "q15"); +} + // Attenuate 8 pixels at a time. void ARGBAttenuateRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width) { asm volatile( + "vmov.u16 q15, #0x00ff \n" // 255 for rounding up + // Attenuate 8 pixels. - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 pixels of ARGB. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vmull.u8 q10, d0, d3 \n" // b * a - "vmull.u8 q11, d1, d3 \n" // g * a - "vmull.u8 q12, d2, d3 \n" // r * a - "vqrshrn.u16 d0, q10, #8 \n" // b >>= 8 - "vqrshrn.u16 d1, q11, #8 \n" // g >>= 8 - "vqrshrn.u16 d2, q12, #8 \n" // r >>= 8 - "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // store 8 pixels of ARGB. - "bgt 1b \n" + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 pixels of ARGB. + "subs %2, %2, #8 \n" // 8 processed per loop. + "vmull.u8 q10, d0, d3 \n" // b * a + "vmull.u8 q11, d1, d3 \n" // g * a + "vmull.u8 q12, d2, d3 \n" // r * a + "vaddhn.u16 d0, q10, q15 \n" // (b + 255) >> 8 + "vaddhn.u16 d1, q11, q15 \n" // (g + 255) >> 8 + "vaddhn.u16 d2, q12, q15 \n" // (r + 255) >> 8 + "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // store 8 pixels of ARGB. + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 : - : "cc", "memory", "q0", "q1", "q10", "q11", "q12"); + : "cc", "memory", "q0", "q1", "q10", "q11", "q12", "q15"); } // Quantize 8 ARGB pixels (32 bytes). @@ -2178,32 +2955,32 @@ void ARGBQuantizeRow_NEON(uint8_t* dst_argb, int interval_offset, int width) { asm volatile( - "vdup.u16 q8, %2 \n" - "vshr.u16 q8, q8, #1 \n" // scale >>= 1 - "vdup.u16 q9, %3 \n" // interval multiply. - "vdup.u16 q10, %4 \n" // interval add + "vdup.u16 q8, %2 \n" + "vshr.u16 q8, q8, #1 \n" // scale >>= 1 + "vdup.u16 q9, %3 \n" // interval multiply. + "vdup.u16 q10, %4 \n" // interval add // 8 pixel loop. - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0] \n" // load 8 pixels of ARGB. - "subs %1, %1, #8 \n" // 8 processed per loop. - "vmovl.u8 q0, d0 \n" // b (0 .. 255) - "vmovl.u8 q1, d2 \n" - "vmovl.u8 q2, d4 \n" + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0] \n" // load 8 pixels of ARGB. + "subs %1, %1, #8 \n" // 8 processed per loop. + "vmovl.u8 q0, d0 \n" // b (0 .. 255) + "vmovl.u8 q1, d2 \n" + "vmovl.u8 q2, d4 \n" "vqdmulh.s16 q0, q0, q8 \n" // b * scale "vqdmulh.s16 q1, q1, q8 \n" // g "vqdmulh.s16 q2, q2, q8 \n" // r - "vmul.u16 q0, q0, q9 \n" // b * interval_size - "vmul.u16 q1, q1, q9 \n" // g - "vmul.u16 q2, q2, q9 \n" // r - "vadd.u16 q0, q0, q10 \n" // b + interval_offset - "vadd.u16 q1, q1, q10 \n" // g - "vadd.u16 q2, q2, q10 \n" // r - "vqmovn.u16 d0, q0 \n" - "vqmovn.u16 d2, q1 \n" - "vqmovn.u16 d4, q2 \n" - "vst4.8 {d0, d2, d4, d6}, [%0]! \n" // store 8 pixels of ARGB. - "bgt 1b \n" + "vmul.u16 q0, q0, q9 \n" // b * interval_size + "vmul.u16 q1, q1, q9 \n" // g + "vmul.u16 q2, q2, q9 \n" // r + "vadd.u16 q0, q0, q10 \n" // b + interval_offset + "vadd.u16 q1, q1, q10 \n" // g + "vadd.u16 q2, q2, q10 \n" // r + "vqmovn.u16 d0, q0 \n" + "vqmovn.u16 d2, q1 \n" + "vqmovn.u16 d4, q2 \n" + "vst4.8 {d0, d2, d4, d6}, [%0]! \n" // store 8 pixels of ARGB. + "bgt 1b \n" : "+r"(dst_argb), // %0 "+r"(width) // %1 : "r"(scale), // %2 @@ -2220,28 +2997,28 @@ void ARGBShadeRow_NEON(const uint8_t* src_argb, int width, uint32_t value) { asm volatile( - "vdup.u32 q0, %3 \n" // duplicate scale value. - "vzip.u8 d0, d1 \n" // d0 aarrggbb. - "vshr.u16 q0, q0, #1 \n" // scale / 2. + "vdup.u32 q0, %3 \n" // duplicate scale value. + "vzip.u8 d0, d1 \n" // d0 aarrggbb. + "vshr.u16 q0, q0, #1 \n" // scale / 2. // 8 pixel loop. - "1: \n" - "vld4.8 {d20, d22, d24, d26}, [%0]! \n" // load 8 pixels of ARGB. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vmovl.u8 q10, d20 \n" // b (0 .. 255) - "vmovl.u8 q11, d22 \n" - "vmovl.u8 q12, d24 \n" - "vmovl.u8 q13, d26 \n" + "1: \n" + "vld4.8 {d20, d22, d24, d26}, [%0]! \n" // load 8 pixels of ARGB. + "subs %2, %2, #8 \n" // 8 processed per loop. + "vmovl.u8 q10, d20 \n" // b (0 .. 255) + "vmovl.u8 q11, d22 \n" + "vmovl.u8 q12, d24 \n" + "vmovl.u8 q13, d26 \n" "vqrdmulh.s16 q10, q10, d0[0] \n" // b * scale * 2 "vqrdmulh.s16 q11, q11, d0[1] \n" // g "vqrdmulh.s16 q12, q12, d0[2] \n" // r "vqrdmulh.s16 q13, q13, d0[3] \n" // a - "vqmovn.u16 d20, q10 \n" - "vqmovn.u16 d22, q11 \n" - "vqmovn.u16 d24, q12 \n" - "vqmovn.u16 d26, q13 \n" - "vst4.8 {d20, d22, d24, d26}, [%1]! \n" // store 8 pixels of ARGB. - "bgt 1b \n" + "vqmovn.u16 d20, q10 \n" + "vqmovn.u16 d22, q11 \n" + "vqmovn.u16 d24, q12 \n" + "vqmovn.u16 d26, q13 \n" + "vst4.8 {d20, d22, d24, d26}, [%1]! \n" // store 8 pixels of ARGB. + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -2251,23 +3028,23 @@ void ARGBShadeRow_NEON(const uint8_t* src_argb, // Convert 8 ARGB pixels (64 bytes) to 8 Gray ARGB pixels // Similar to ARGBToYJ but stores ARGB. -// C code is (15 * b + 75 * g + 38 * r + 64) >> 7; +// C code is (29 * b + 150 * g + 77 * r + 128) >> 8; void ARGBGrayRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width) { asm volatile( - "vmov.u8 d24, #15 \n" // B * 0.11400 coefficient - "vmov.u8 d25, #75 \n" // G * 0.58700 coefficient - "vmov.u8 d26, #38 \n" // R * 0.29900 coefficient - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 ARGB pixels. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vmull.u8 q2, d0, d24 \n" // B - "vmlal.u8 q2, d1, d25 \n" // G - "vmlal.u8 q2, d2, d26 \n" // R - "vqrshrun.s16 d0, q2, #7 \n" // 15 bit to 8 bit B - "vmov d1, d0 \n" // G - "vmov d2, d0 \n" // R - "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // store 8 ARGB pixels. - "bgt 1b \n" + "vmov.u8 d24, #29 \n" // B * 0.1140 coefficient + "vmov.u8 d25, #150 \n" // G * 0.5870 coefficient + "vmov.u8 d26, #77 \n" // R * 0.2990 coefficient + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 ARGB pixels. + "subs %2, %2, #8 \n" // 8 processed per loop. + "vmull.u8 q2, d0, d24 \n" // B + "vmlal.u8 q2, d1, d25 \n" // G + "vmlal.u8 q2, d2, d26 \n" // R + "vqrshrn.u16 d0, q2, #8 \n" // 16 bit to 8 bit B + "vmov d1, d0 \n" // G + "vmov d2, d0 \n" // R + "vst4.8 {d0, d1, d2, d3}, [%1]! \n" // store 8 ARGB pixels. + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -2281,37 +3058,37 @@ void ARGBGrayRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width) { // r = (r * 50 + g * 98 + b * 24) >> 7 void ARGBSepiaRow_NEON(uint8_t* dst_argb, int width) { asm volatile( - "vmov.u8 d20, #17 \n" // BB coefficient - "vmov.u8 d21, #68 \n" // BG coefficient - "vmov.u8 d22, #35 \n" // BR coefficient - "vmov.u8 d24, #22 \n" // GB coefficient - "vmov.u8 d25, #88 \n" // GG coefficient - "vmov.u8 d26, #45 \n" // GR coefficient - "vmov.u8 d28, #24 \n" // BB coefficient - "vmov.u8 d29, #98 \n" // BG coefficient - "vmov.u8 d30, #50 \n" // BR coefficient - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0] \n" // load 8 ARGB pixels. - "subs %1, %1, #8 \n" // 8 processed per loop. - "vmull.u8 q2, d0, d20 \n" // B to Sepia B - "vmlal.u8 q2, d1, d21 \n" // G - "vmlal.u8 q2, d2, d22 \n" // R - "vmull.u8 q3, d0, d24 \n" // B to Sepia G - "vmlal.u8 q3, d1, d25 \n" // G - "vmlal.u8 q3, d2, d26 \n" // R - "vmull.u8 q8, d0, d28 \n" // B to Sepia R - "vmlal.u8 q8, d1, d29 \n" // G - "vmlal.u8 q8, d2, d30 \n" // R - "vqshrn.u16 d0, q2, #7 \n" // 16 bit to 8 bit B - "vqshrn.u16 d1, q3, #7 \n" // 16 bit to 8 bit G - "vqshrn.u16 d2, q8, #7 \n" // 16 bit to 8 bit R - "vst4.8 {d0, d1, d2, d3}, [%0]! \n" // store 8 ARGB pixels. - "bgt 1b \n" + "vmov.u8 d20, #17 \n" // BB coefficient + "vmov.u8 d21, #68 \n" // BG coefficient + "vmov.u8 d22, #35 \n" // BR coefficient + "vmov.u8 d24, #22 \n" // GB coefficient + "vmov.u8 d25, #88 \n" // GG coefficient + "vmov.u8 d26, #45 \n" // GR coefficient + "vmov.u8 d28, #24 \n" // BB coefficient + "vmov.u8 d29, #98 \n" // BG coefficient + "vmov.u8 d30, #50 \n" // BR coefficient + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0] \n" // load 8 ARGB pixels. + "subs %1, %1, #8 \n" // 8 processed per loop. + "vmull.u8 q2, d0, d20 \n" // B to Sepia B + "vmlal.u8 q2, d1, d21 \n" // G + "vmlal.u8 q2, d2, d22 \n" // R + "vmull.u8 q3, d0, d24 \n" // B to Sepia G + "vmlal.u8 q3, d1, d25 \n" // G + "vmlal.u8 q3, d2, d26 \n" // R + "vmull.u8 q8, d0, d28 \n" // B to Sepia R + "vmlal.u8 q8, d1, d29 \n" // G + "vmlal.u8 q8, d2, d30 \n" // R + "vqshrn.u16 d0, q2, #7 \n" // 16 bit to 8 bit B + "vqshrn.u16 d1, q3, #7 \n" // 16 bit to 8 bit G + "vqshrn.u16 d2, q8, #7 \n" // 16 bit to 8 bit R + "vst4.8 {d0, d1, d2, d3}, [%0]! \n" // store 8 ARGB pixels. + "bgt 1b \n" : "+r"(dst_argb), // %0 "+r"(width) // %1 : - : "cc", "memory", "q0", "q1", "q2", "q3", "q10", "q11", "q12", "q13", - "q14", "q15"); + : "memory", "cc", "q0", "q1", "q2", "q3", "q8", "q10", "q11", "q12", + "q13", "q14", "q15"); } // Tranform 8 ARGB pixels (32 bytes) with color matrix. @@ -2322,51 +3099,51 @@ void ARGBColorMatrixRow_NEON(const uint8_t* src_argb, const int8_t* matrix_argb, int width) { asm volatile( - "vld1.8 {q2}, [%3] \n" // load 3 ARGB vectors. - "vmovl.s8 q0, d4 \n" // B,G coefficients s16. - "vmovl.s8 q1, d5 \n" // R,A coefficients s16. + "vld1.8 {q2}, [%3] \n" // load 3 ARGB vectors. + "vmovl.s8 q0, d4 \n" // B,G coefficients s16. + "vmovl.s8 q1, d5 \n" // R,A coefficients s16. - "1: \n" - "vld4.8 {d16, d18, d20, d22}, [%0]! \n" // load 8 ARGB pixels. - "subs %2, %2, #8 \n" // 8 processed per loop. - "vmovl.u8 q8, d16 \n" // b (0 .. 255) 16 bit - "vmovl.u8 q9, d18 \n" // g - "vmovl.u8 q10, d20 \n" // r - "vmovl.u8 q11, d22 \n" // a - "vmul.s16 q12, q8, d0[0] \n" // B = B * Matrix B - "vmul.s16 q13, q8, d1[0] \n" // G = B * Matrix G - "vmul.s16 q14, q8, d2[0] \n" // R = B * Matrix R - "vmul.s16 q15, q8, d3[0] \n" // A = B * Matrix A - "vmul.s16 q4, q9, d0[1] \n" // B += G * Matrix B - "vmul.s16 q5, q9, d1[1] \n" // G += G * Matrix G - "vmul.s16 q6, q9, d2[1] \n" // R += G * Matrix R - "vmul.s16 q7, q9, d3[1] \n" // A += G * Matrix A - "vqadd.s16 q12, q12, q4 \n" // Accumulate B - "vqadd.s16 q13, q13, q5 \n" // Accumulate G - "vqadd.s16 q14, q14, q6 \n" // Accumulate R - "vqadd.s16 q15, q15, q7 \n" // Accumulate A - "vmul.s16 q4, q10, d0[2] \n" // B += R * Matrix B - "vmul.s16 q5, q10, d1[2] \n" // G += R * Matrix G - "vmul.s16 q6, q10, d2[2] \n" // R += R * Matrix R - "vmul.s16 q7, q10, d3[2] \n" // A += R * Matrix A - "vqadd.s16 q12, q12, q4 \n" // Accumulate B - "vqadd.s16 q13, q13, q5 \n" // Accumulate G - "vqadd.s16 q14, q14, q6 \n" // Accumulate R - "vqadd.s16 q15, q15, q7 \n" // Accumulate A - "vmul.s16 q4, q11, d0[3] \n" // B += A * Matrix B - "vmul.s16 q5, q11, d1[3] \n" // G += A * Matrix G - "vmul.s16 q6, q11, d2[3] \n" // R += A * Matrix R - "vmul.s16 q7, q11, d3[3] \n" // A += A * Matrix A - "vqadd.s16 q12, q12, q4 \n" // Accumulate B - "vqadd.s16 q13, q13, q5 \n" // Accumulate G - "vqadd.s16 q14, q14, q6 \n" // Accumulate R - "vqadd.s16 q15, q15, q7 \n" // Accumulate A + "1: \n" + "vld4.8 {d16, d18, d20, d22}, [%0]! \n" // load 8 ARGB pixels. + "subs %2, %2, #8 \n" // 8 processed per loop. + "vmovl.u8 q8, d16 \n" // b (0 .. 255) 16 bit + "vmovl.u8 q9, d18 \n" // g + "vmovl.u8 q10, d20 \n" // r + "vmovl.u8 q11, d22 \n" // a + "vmul.s16 q12, q8, d0[0] \n" // B = B * Matrix B + "vmul.s16 q13, q8, d1[0] \n" // G = B * Matrix G + "vmul.s16 q14, q8, d2[0] \n" // R = B * Matrix R + "vmul.s16 q15, q8, d3[0] \n" // A = B * Matrix A + "vmul.s16 q4, q9, d0[1] \n" // B += G * Matrix B + "vmul.s16 q5, q9, d1[1] \n" // G += G * Matrix G + "vmul.s16 q6, q9, d2[1] \n" // R += G * Matrix R + "vmul.s16 q7, q9, d3[1] \n" // A += G * Matrix A + "vqadd.s16 q12, q12, q4 \n" // Accumulate B + "vqadd.s16 q13, q13, q5 \n" // Accumulate G + "vqadd.s16 q14, q14, q6 \n" // Accumulate R + "vqadd.s16 q15, q15, q7 \n" // Accumulate A + "vmul.s16 q4, q10, d0[2] \n" // B += R * Matrix B + "vmul.s16 q5, q10, d1[2] \n" // G += R * Matrix G + "vmul.s16 q6, q10, d2[2] \n" // R += R * Matrix R + "vmul.s16 q7, q10, d3[2] \n" // A += R * Matrix A + "vqadd.s16 q12, q12, q4 \n" // Accumulate B + "vqadd.s16 q13, q13, q5 \n" // Accumulate G + "vqadd.s16 q14, q14, q6 \n" // Accumulate R + "vqadd.s16 q15, q15, q7 \n" // Accumulate A + "vmul.s16 q4, q11, d0[3] \n" // B += A * Matrix B + "vmul.s16 q5, q11, d1[3] \n" // G += A * Matrix G + "vmul.s16 q6, q11, d2[3] \n" // R += A * Matrix R + "vmul.s16 q7, q11, d3[3] \n" // A += A * Matrix A + "vqadd.s16 q12, q12, q4 \n" // Accumulate B + "vqadd.s16 q13, q13, q5 \n" // Accumulate G + "vqadd.s16 q14, q14, q6 \n" // Accumulate R + "vqadd.s16 q15, q15, q7 \n" // Accumulate A "vqshrun.s16 d16, q12, #6 \n" // 16 bit to 8 bit B "vqshrun.s16 d18, q13, #6 \n" // 16 bit to 8 bit G "vqshrun.s16 d20, q14, #6 \n" // 16 bit to 8 bit R "vqshrun.s16 d22, q15, #6 \n" // 16 bit to 8 bit A - "vst4.8 {d16, d18, d20, d22}, [%1]! \n" // store 8 ARGB pixels. - "bgt 1b \n" + "vst4.8 {d16, d18, d20, d22}, [%1]! \n" // store 8 ARGB pixels. + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -2376,27 +3153,27 @@ void ARGBColorMatrixRow_NEON(const uint8_t* src_argb, } // Multiply 2 rows of ARGB pixels together, 8 pixels at a time. -void ARGBMultiplyRow_NEON(const uint8_t* src_argb0, +void ARGBMultiplyRow_NEON(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( // 8 pixel loop. - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels. - "vld4.8 {d1, d3, d5, d7}, [%1]! \n" // load 8 more ARGB - "subs %3, %3, #8 \n" // 8 processed per loop. - "vmull.u8 q0, d0, d1 \n" // multiply B - "vmull.u8 q1, d2, d3 \n" // multiply G - "vmull.u8 q2, d4, d5 \n" // multiply R - "vmull.u8 q3, d6, d7 \n" // multiply A - "vrshrn.u16 d0, q0, #8 \n" // 16 bit to 8 bit B - "vrshrn.u16 d1, q1, #8 \n" // 16 bit to 8 bit G - "vrshrn.u16 d2, q2, #8 \n" // 16 bit to 8 bit R - "vrshrn.u16 d3, q3, #8 \n" // 16 bit to 8 bit A - "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 ARGB pixels. - "bgt 1b \n" - : "+r"(src_argb0), // %0 + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels. + "vld4.8 {d1, d3, d5, d7}, [%1]! \n" // load 8 more ARGB + "subs %3, %3, #8 \n" // 8 processed per loop. + "vmull.u8 q0, d0, d1 \n" // multiply B + "vmull.u8 q1, d2, d3 \n" // multiply G + "vmull.u8 q2, d4, d5 \n" // multiply R + "vmull.u8 q3, d6, d7 \n" // multiply A + "vrshrn.u16 d0, q0, #8 \n" // 16 bit to 8 bit B + "vrshrn.u16 d1, q1, #8 \n" // 16 bit to 8 bit G + "vrshrn.u16 d2, q2, #8 \n" // 16 bit to 8 bit R + "vrshrn.u16 d3, q3, #8 \n" // 16 bit to 8 bit A + "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 ARGB pixels. + "bgt 1b \n" + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -2405,21 +3182,21 @@ void ARGBMultiplyRow_NEON(const uint8_t* src_argb0, } // Add 2 rows of ARGB pixels together, 8 pixels at a time. -void ARGBAddRow_NEON(const uint8_t* src_argb0, +void ARGBAddRow_NEON(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( // 8 pixel loop. - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 ARGB pixels. - "vld4.8 {d4, d5, d6, d7}, [%1]! \n" // load 8 more ARGB - "subs %3, %3, #8 \n" // 8 processed per loop. - "vqadd.u8 q0, q0, q2 \n" // add B, G - "vqadd.u8 q1, q1, q3 \n" // add R, A - "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 ARGB pixels. - "bgt 1b \n" - : "+r"(src_argb0), // %0 + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 ARGB pixels. + "vld4.8 {d4, d5, d6, d7}, [%1]! \n" // load 8 more ARGB + "subs %3, %3, #8 \n" // 8 processed per loop. + "vqadd.u8 q0, q0, q2 \n" // add B, G + "vqadd.u8 q1, q1, q3 \n" // add R, A + "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 ARGB pixels. + "bgt 1b \n" + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -2428,21 +3205,21 @@ void ARGBAddRow_NEON(const uint8_t* src_argb0, } // Subtract 2 rows of ARGB pixels, 8 pixels at a time. -void ARGBSubtractRow_NEON(const uint8_t* src_argb0, +void ARGBSubtractRow_NEON(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( // 8 pixel loop. - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 ARGB pixels. - "vld4.8 {d4, d5, d6, d7}, [%1]! \n" // load 8 more ARGB - "subs %3, %3, #8 \n" // 8 processed per loop. - "vqsub.u8 q0, q0, q2 \n" // subtract B, G - "vqsub.u8 q1, q1, q3 \n" // subtract R, A - "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 ARGB pixels. - "bgt 1b \n" - : "+r"(src_argb0), // %0 + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // load 8 ARGB pixels. + "vld4.8 {d4, d5, d6, d7}, [%1]! \n" // load 8 more ARGB + "subs %3, %3, #8 \n" // 8 processed per loop. + "vqsub.u8 q0, q0, q2 \n" // subtract B, G + "vqsub.u8 q1, q1, q3 \n" // subtract R, A + "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 ARGB pixels. + "bgt 1b \n" + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -2450,6 +3227,72 @@ void ARGBSubtractRow_NEON(const uint8_t* src_argb0, : "cc", "memory", "q0", "q1", "q2", "q3"); } +// Blend 32 pixels at a time. +// dst = (((a) * src0) + ((255 - a) * src1) + 255) >> 8 +void BlendPlaneRow_NEON(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width) { + asm volatile( + "vmov.u16 q15, #255 \n" + "subs %4, %4, #32 \n" + "blt 19f \n" + "1: \n" + "vld1.8 {q0, q1}, [%0]! \n" // load 32 src0 + "vld1.8 {q2, q3}, [%1]! \n" // load 32 src1 + "vld1.8 {q8, q9}, [%2]! \n" // load 32 alpha + "subs %4, %4, #32 \n" // 32 processed per loop + "vmvn.8 q10, q8 \n" // 255 - alpha0 + "vmvn.8 q11, q9 \n" // 255 - alpha1 + "vmull.u8 q4, d0, d16 \n" // low src0 * alpha + "pld [%0, #448] \n" + "vmull.u8 q5, d1, d17 \n" // high src0 * alpha + "pld [%1, #448] \n" + "vmull.u8 q6, d2, d18 \n" + "pld [%2, #448] \n" + "vmull.u8 q7, d3, d19 \n" + "vmlal.u8 q4, d4, d20 \n" // low + src1 * (255 - + // alpha) + "vmlal.u8 q5, d5, d21 \n" // high + src1 * (255 - + // alpha) + "vmlal.u8 q6, d6, d22 \n" + "vmlal.u8 q7, d7, d23 \n" + "vaddhn.u16 d0, q4, q15 \n" // (low + 255) >> 8 + "vaddhn.u16 d1, q5, q15 \n" // (high + 255) >> 8 + "vaddhn.u16 d2, q6, q15 \n" + "vaddhn.u16 d3, q7, q15 \n" + "vst1.8 {q0, q1}, [%3]! \n" // store 32 dst + "bge 1b \n" + "19: \n" + "adds %4, %4, #32 \n" + "ble 99f \n" + + // 16 pixel tail + "vld1.8 {q0}, [%0]! \n" // load 16 src0 + "vld1.8 {q1}, [%1]! \n" // load 16 src1 + "vld1.8 {q2}, [%2]! \n" // load 16 alpha + "vmvn.8 q12, q2 \n" // 255 - alpha + "vmull.u8 q4, d0, d4 \n" // low src0 * alpha + "vmull.u8 q5, d1, d5 \n" // high src0 * alpha + "vmlal.u8 q4, d2, d24 \n" // low + src1 * (255 - + // alpha) + "vmlal.u8 q5, d3, d25 \n" // high + src1 * (255 - + // alpha) + "vaddhn.u16 d0, q4, q15 \n" // + 255 >> 8 + "vaddhn.u16 d1, q5, q15 \n" // + 255 >> 8 + "vst1.8 {q0}, [%3]! \n" // store 16 dst + "99: \n" + : "+r"(src0), // %0 + "+r"(src1), // %1 + "+r"(alpha), // %2 + "+r"(dst), // %3 + "+r"(width) // %4 + : + : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", + "q9", "q10", "q11", "q12", "q15"); +} + // Adds Sobel X and Sobel Y and stores Sobel into ARGB. // A = 255 // R = Sobel @@ -2460,17 +3303,17 @@ void SobelRow_NEON(const uint8_t* src_sobelx, uint8_t* dst_argb, int width) { asm volatile( - "vmov.u8 d3, #255 \n" // alpha + "vmov.u8 d3, #255 \n" // alpha // 8 pixel loop. - "1: \n" - "vld1.8 {d0}, [%0]! \n" // load 8 sobelx. - "vld1.8 {d1}, [%1]! \n" // load 8 sobely. - "subs %3, %3, #8 \n" // 8 processed per loop. - "vqadd.u8 d0, d0, d1 \n" // add - "vmov.u8 d1, d0 \n" - "vmov.u8 d2, d0 \n" - "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 ARGB pixels. - "bgt 1b \n" + "1: \n" + "vld1.8 {d0}, [%0]! \n" // load 8 sobelx. + "vld1.8 {d1}, [%1]! \n" // load 8 sobely. + "subs %3, %3, #8 \n" // 8 processed per loop. + "vqadd.u8 d0, d0, d1 \n" // add + "vmov.u8 d1, d0 \n" + "vmov.u8 d2, d0 \n" + "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 ARGB pixels. + "bgt 1b \n" : "+r"(src_sobelx), // %0 "+r"(src_sobely), // %1 "+r"(dst_argb), // %2 @@ -2486,13 +3329,13 @@ void SobelToPlaneRow_NEON(const uint8_t* src_sobelx, int width) { asm volatile( // 16 pixel loop. - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load 16 sobelx. - "vld1.8 {q1}, [%1]! \n" // load 16 sobely. - "subs %3, %3, #16 \n" // 16 processed per loop. - "vqadd.u8 q0, q0, q1 \n" // add - "vst1.8 {q0}, [%2]! \n" // store 16 pixels. - "bgt 1b \n" + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 16 sobelx. + "vld1.8 {q1}, [%1]! \n" // load 16 sobely. + "subs %3, %3, #16 \n" // 16 processed per loop. + "vqadd.u8 q0, q0, q1 \n" // add + "vst1.8 {q0}, [%2]! \n" // store 16 pixels. + "bgt 1b \n" : "+r"(src_sobelx), // %0 "+r"(src_sobely), // %1 "+r"(dst_y), // %2 @@ -2511,15 +3354,15 @@ void SobelXYRow_NEON(const uint8_t* src_sobelx, uint8_t* dst_argb, int width) { asm volatile( - "vmov.u8 d3, #255 \n" // alpha + "vmov.u8 d3, #255 \n" // alpha // 8 pixel loop. - "1: \n" - "vld1.8 {d2}, [%0]! \n" // load 8 sobelx. - "vld1.8 {d0}, [%1]! \n" // load 8 sobely. - "subs %3, %3, #8 \n" // 8 processed per loop. - "vqadd.u8 d1, d0, d2 \n" // add - "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 ARGB pixels. - "bgt 1b \n" + "1: \n" + "vld1.8 {d2}, [%0]! \n" // load 8 sobelx. + "vld1.8 {d0}, [%1]! \n" // load 8 sobely. + "subs %3, %3, #8 \n" // 8 processed per loop. + "vqadd.u8 d1, d0, d2 \n" // add + "vst4.8 {d0, d1, d2, d3}, [%2]! \n" // store 8 ARGB pixels. + "bgt 1b \n" : "+r"(src_sobelx), // %0 "+r"(src_sobely), // %1 "+r"(dst_argb), // %2 @@ -2538,24 +3381,24 @@ void SobelXRow_NEON(const uint8_t* src_y0, uint8_t* dst_sobelx, int width) { asm volatile( - "1: \n" - "vld1.8 {d0}, [%0],%5 \n" // top - "vld1.8 {d1}, [%0],%6 \n" - "vsubl.u8 q0, d0, d1 \n" - "vld1.8 {d2}, [%1],%5 \n" // center * 2 - "vld1.8 {d3}, [%1],%6 \n" - "vsubl.u8 q1, d2, d3 \n" - "vadd.s16 q0, q0, q1 \n" - "vadd.s16 q0, q0, q1 \n" - "vld1.8 {d2}, [%2],%5 \n" // bottom - "vld1.8 {d3}, [%2],%6 \n" - "subs %4, %4, #8 \n" // 8 pixels - "vsubl.u8 q1, d2, d3 \n" - "vadd.s16 q0, q0, q1 \n" - "vabs.s16 q0, q0 \n" - "vqmovn.u16 d0, q0 \n" - "vst1.8 {d0}, [%3]! \n" // store 8 sobelx - "bgt 1b \n" + "1: \n" + "vld1.8 {d0}, [%0],%5 \n" // top + "vld1.8 {d1}, [%0],%6 \n" + "subs %4, %4, #8 \n" // 8 pixels + "vsubl.u8 q0, d0, d1 \n" + "vld1.8 {d2}, [%1],%5 \n" // center * 2 + "vld1.8 {d3}, [%1],%6 \n" + "vsubl.u8 q1, d2, d3 \n" + "vadd.s16 q0, q0, q1 \n" + "vadd.s16 q0, q0, q1 \n" + "vld1.8 {d2}, [%2],%5 \n" // bottom + "vld1.8 {d3}, [%2],%6 \n" + "vsubl.u8 q1, d2, d3 \n" + "vadd.s16 q0, q0, q1 \n" + "vabs.s16 q0, q0 \n" + "vqmovn.u16 d0, q0 \n" + "vst1.8 {d0}, [%3]! \n" // store 8 sobelx + "bgt 1b \n" : "+r"(src_y0), // %0 "+r"(src_y1), // %1 "+r"(src_y2), // %2 @@ -2576,24 +3419,24 @@ void SobelYRow_NEON(const uint8_t* src_y0, uint8_t* dst_sobely, int width) { asm volatile( - "1: \n" - "vld1.8 {d0}, [%0],%4 \n" // left - "vld1.8 {d1}, [%1],%4 \n" - "vsubl.u8 q0, d0, d1 \n" - "vld1.8 {d2}, [%0],%4 \n" // center * 2 - "vld1.8 {d3}, [%1],%4 \n" - "vsubl.u8 q1, d2, d3 \n" - "vadd.s16 q0, q0, q1 \n" - "vadd.s16 q0, q0, q1 \n" - "vld1.8 {d2}, [%0],%5 \n" // right - "vld1.8 {d3}, [%1],%5 \n" - "subs %3, %3, #8 \n" // 8 pixels - "vsubl.u8 q1, d2, d3 \n" - "vadd.s16 q0, q0, q1 \n" - "vabs.s16 q0, q0 \n" - "vqmovn.u16 d0, q0 \n" - "vst1.8 {d0}, [%2]! \n" // store 8 sobely - "bgt 1b \n" + "1: \n" + "vld1.8 {d0}, [%0],%4 \n" // left + "vld1.8 {d1}, [%1],%4 \n" + "subs %3, %3, #8 \n" // 8 pixels + "vsubl.u8 q0, d0, d1 \n" + "vld1.8 {d2}, [%0],%4 \n" // center * 2 + "vld1.8 {d3}, [%1],%4 \n" + "vsubl.u8 q1, d2, d3 \n" + "vadd.s16 q0, q0, q1 \n" + "vadd.s16 q0, q0, q1 \n" + "vld1.8 {d2}, [%0],%5 \n" // right + "vld1.8 {d3}, [%1],%5 \n" + "vsubl.u8 q1, d2, d3 \n" + "vadd.s16 q0, q0, q1 \n" + "vabs.s16 q0, q0 \n" + "vqmovn.u16 d0, q0 \n" + "vst1.8 {d0}, [%2]! \n" // store 8 sobely + "bgt 1b \n" : "+r"(src_y0), // %0 "+r"(src_y1), // %1 "+r"(dst_sobely), // %2 @@ -2605,59 +3448,46 @@ void SobelYRow_NEON(const uint8_t* src_y0, } // %y passes a float as a scalar vector for vector * scalar multiply. -// the regoster must be d0 to d15 and indexed with [0] or [1] to access +// the register must be d0 to d15 and indexed with [0] or [1] to access // the float in the first or second float of the d-reg -void HalfFloat1Row_NEON(const uint16_t* src, - uint16_t* dst, - float /*unused*/, - int width) { - asm volatile( - - "1: \n" - "vld1.8 {q1}, [%0]! \n" // load 8 shorts - "subs %2, %2, #8 \n" // 8 pixels per loop - "vmovl.u16 q2, d2 \n" // 8 int's - "vmovl.u16 q3, d3 \n" - "vcvt.f32.u32 q2, q2 \n" // 8 floats - "vcvt.f32.u32 q3, q3 \n" - "vmul.f32 q2, q2, %y3 \n" // adjust exponent - "vmul.f32 q3, q3, %y3 \n" - "vqshrn.u32 d2, q2, #13 \n" // isolate halffloat - "vqshrn.u32 d3, q3, #13 \n" - "vst1.8 {q1}, [%1]! \n" - "bgt 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "w"(1.9259299444e-34f) // %3 - : "cc", "memory", "q1", "q2", "q3"); -} - void HalfFloatRow_NEON(const uint16_t* src, uint16_t* dst, float scale, int width) { asm volatile( - "1: \n" - "vld1.8 {q1}, [%0]! \n" // load 8 shorts - "subs %2, %2, #8 \n" // 8 pixels per loop - "vmovl.u16 q2, d2 \n" // 8 int's - "vmovl.u16 q3, d3 \n" - "vcvt.f32.u32 q2, q2 \n" // 8 floats - "vcvt.f32.u32 q3, q3 \n" - "vmul.f32 q2, q2, %y3 \n" // adjust exponent - "vmul.f32 q3, q3, %y3 \n" - "vqshrn.u32 d2, q2, #13 \n" // isolate halffloat - "vqshrn.u32 d3, q3, #13 \n" - "vst1.8 {q1}, [%1]! \n" - "bgt 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "w"(scale * 1.9259299444e-34f) // %3 - : "cc", "memory", "q1", "q2", "q3"); + "1: \n" + "vld1.16 {q0, q1}, [%0]! \n" // load 16 shorts + "subs %2, %2, #16 \n" // 16 pixels per loop + "vmovl.u16 q8, d0 \n" + "vmovl.u16 q9, d1 \n" + "vmovl.u16 q10, d2 \n" + "vmovl.u16 q11, d3 \n" + "vcvt.f32.u32 q8, q8 \n" + "vcvt.f32.u32 q9, q9 \n" + "vcvt.f32.u32 q10, q10 \n" + "vcvt.f32.u32 q11, q11 \n" + "vmul.f32 q8, q8, %y3 \n" // * scale + "vmul.f32 q9, q9, %y3 \n" + "vmul.f32 q10, q10, %y3 \n" + "vmul.f32 q11, q11, %y3 \n" + "vmul.f32 q8, q8, %y4 \n" // adjust exponent + "vmul.f32 q9, q9, %y4 \n" + "vmul.f32 q10, q10, %y4 \n" + "vmul.f32 q11, q11, %y4 \n" + "vqshrn.u32 d0, q8, #13 \n" // isolate halffloat + "vqshrn.u32 d1, q9, #13 \n" + "vqshrn.u32 d2, q10, #13 \n" + "vqshrn.u32 d3, q11, #13 \n" + "vst1.16 {q0, q1}, [%1]! \n" // store 16 fp16 + "bgt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "w"(scale), // %3 + "w"(1.9259299444e-34f) // %4 2^-112, see HalfFloatRow_C + : "cc", "memory", "q0", "q1", "q8", "q9", "q10", "q11"); } void ByteToFloatRow_NEON(const uint8_t* src, @@ -2666,18 +3496,18 @@ void ByteToFloatRow_NEON(const uint8_t* src, int width) { asm volatile( - "1: \n" - "vld1.8 {d2}, [%0]! \n" // load 8 bytes - "subs %2, %2, #8 \n" // 8 pixels per loop - "vmovl.u8 q1, d2 \n" // 8 shorts - "vmovl.u16 q2, d2 \n" // 8 ints - "vmovl.u16 q3, d3 \n" - "vcvt.f32.u32 q2, q2 \n" // 8 floats - "vcvt.f32.u32 q3, q3 \n" - "vmul.f32 q2, q2, %y3 \n" // scale - "vmul.f32 q3, q3, %y3 \n" - "vst1.8 {q2, q3}, [%1]! \n" // store 8 floats - "bgt 1b \n" + "1: \n" + "vld1.8 {d2}, [%0]! \n" // load 8 bytes + "subs %2, %2, #8 \n" // 8 pixels per loop + "vmovl.u8 q1, d2 \n" // 8 shorts + "vmovl.u16 q2, d2 \n" // 8 ints + "vmovl.u16 q3, d3 \n" + "vcvt.f32.u32 q2, q2 \n" // 8 floats + "vcvt.f32.u32 q3, q3 \n" + "vmul.f32 q2, q2, %y3 \n" // scale + "vmul.f32 q3, q3, %y3 \n" + "vst1.8 {q2, q3}, [%1]! \n" // store 8 floats + "bgt 1b \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -2694,26 +3524,26 @@ void GaussCol_NEON(const uint16_t* src0, uint32_t* dst, int width) { asm volatile( - "vmov.u16 d6, #4 \n" // constant 4 - "vmov.u16 d7, #6 \n" // constant 6 + "vmov.u16 d6, #4 \n" // constant 4 + "vmov.u16 d7, #6 \n" // constant 6 - "1: \n" - "vld1.16 {q1}, [%0]! \n" // load 8 samples, 5 rows - "vld1.16 {q2}, [%4]! \n" - "vaddl.u16 q0, d2, d4 \n" // * 1 - "vaddl.u16 q1, d3, d5 \n" // * 1 - "vld1.16 {q2}, [%1]! \n" - "vmlal.u16 q0, d4, d6 \n" // * 4 - "vmlal.u16 q1, d5, d6 \n" // * 4 - "vld1.16 {q2}, [%2]! \n" - "vmlal.u16 q0, d4, d7 \n" // * 6 - "vmlal.u16 q1, d5, d7 \n" // * 6 - "vld1.16 {q2}, [%3]! \n" - "vmlal.u16 q0, d4, d6 \n" // * 4 - "vmlal.u16 q1, d5, d6 \n" // * 4 - "subs %6, %6, #8 \n" // 8 processed per loop - "vst1.32 {q0, q1}, [%5]! \n" // store 8 samples - "bgt 1b \n" + "1: \n" + "vld1.16 {q1}, [%0]! \n" // load 8 samples, 5 rows + "vld1.16 {q2}, [%4]! \n" + "subs %6, %6, #8 \n" // 8 processed per loop + "vaddl.u16 q0, d2, d4 \n" // * 1 + "vaddl.u16 q1, d3, d5 \n" // * 1 + "vld1.16 {q2}, [%1]! \n" + "vmlal.u16 q0, d4, d6 \n" // * 4 + "vmlal.u16 q1, d5, d6 \n" // * 4 + "vld1.16 {q2}, [%2]! \n" + "vmlal.u16 q0, d4, d7 \n" // * 6 + "vmlal.u16 q1, d5, d7 \n" // * 6 + "vld1.16 {q2}, [%3]! \n" + "vmlal.u16 q0, d4, d6 \n" // * 4 + "vmlal.u16 q1, d5, d6 \n" // * 4 + "vst1.32 {q0, q1}, [%5]! \n" // store 8 samples + "bgt 1b \n" : "+r"(src0), // %0 "+r"(src1), // %1 "+r"(src2), // %2 @@ -2731,12 +3561,13 @@ void GaussRow_NEON(const uint32_t* src, uint16_t* dst, int width) { const uint32_t* src2 = src + 2; const uint32_t* src3 = src + 3; asm volatile( - "vmov.u32 q10, #4 \n" // constant 4 - "vmov.u32 q11, #6 \n" // constant 6 + "vmov.u32 q10, #4 \n" // constant 4 + "vmov.u32 q11, #6 \n" // constant 6 - "1: \n" + "1: \n" "vld1.32 {q0, q1}, [%0]! \n" // load 12 source samples "vld1.32 {q2}, [%0] \n" + "subs %5, %5, #8 \n" // 8 processed per loop "vadd.u32 q0, q0, q1 \n" // * 1 "vadd.u32 q1, q1, q2 \n" // * 1 "vld1.32 {q2, q3}, [%2]! \n" @@ -2748,7 +3579,6 @@ void GaussRow_NEON(const uint32_t* src, uint16_t* dst, int width) { "vadd.u32 q3, q3, q9 \n" "vmla.u32 q0, q2, q10 \n" // * 4 "vmla.u32 q1, q3, q10 \n" // * 4 - "subs %5, %5, #8 \n" // 8 processed per loop "vqshrn.u32 d0, q0, #8 \n" // round and pack "vqshrn.u32 d1, q1, #8 \n" "vst1.u16 {q0}, [%4]! \n" // store 8 samples @@ -2769,17 +3599,17 @@ void NV21ToYUV24Row_NEON(const uint8_t* src_y, uint8_t* dst_yuv24, int width) { asm volatile( - "1: \n" - "vld1.8 {q2}, [%0]! \n" // load 16 Y values - "vld2.8 {d0, d2}, [%1]! \n" // load 8 VU values - "vmov d1, d0 \n" - "vzip.u8 d0, d1 \n" // VV - "vmov d3, d2 \n" - "vzip.u8 d2, d3 \n" // UU - "subs %3, %3, #16 \n" // 16 pixels per loop - "vst3.8 {d0, d2, d4}, [%2]! \n" // store 16 YUV pixels - "vst3.8 {d1, d3, d5}, [%2]! \n" - "bgt 1b \n" + "1: \n" + "vld1.8 {q2}, [%0]! \n" // load 16 Y values + "vld2.8 {d0, d2}, [%1]! \n" // load 8 VU values + "subs %3, %3, #16 \n" // 16 pixels per loop + "vmov d1, d0 \n" + "vzip.u8 d0, d1 \n" // VV + "vmov d3, d2 \n" + "vzip.u8 d2, d3 \n" // UU + "vst3.8 {d0, d2, d4}, [%2]! \n" // store 16 YUV pixels + "vst3.8 {d1, d3, d5}, [%2]! \n" + "bgt 1b \n" : "+r"(src_y), // %0 "+r"(src_vu), // %1 "+r"(dst_yuv24), // %2 @@ -2793,24 +3623,24 @@ void AYUVToUVRow_NEON(const uint8_t* src_ayuv, uint8_t* dst_uv, int width) { asm volatile( - "add %1, %0, %1 \n" // src_stride + src_AYUV - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 AYUV pixels. - "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 AYUV + "add %1, %0, %1 \n" // src_stride + src_AYUV + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 AYUV pixels. + "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 AYUV // pixels. - "vpaddl.u8 q0, q0 \n" // V 16 bytes -> 8 shorts. - "vpaddl.u8 q1, q1 \n" // U 16 bytes -> 8 shorts. - "vld4.8 {d8, d10, d12, d14}, [%1]! \n" // load 8 more AYUV + "subs %3, %3, #16 \n" // 16 processed per loop. + "vpaddl.u8 q0, q0 \n" // V 16 bytes -> 8 shorts. + "vpaddl.u8 q1, q1 \n" // U 16 bytes -> 8 shorts. + "vld4.8 {d8, d10, d12, d14}, [%1]! \n" // load 8 more AYUV // pixels. - "vld4.8 {d9, d11, d13, d15}, [%1]! \n" // load last 8 AYUV + "vld4.8 {d9, d11, d13, d15}, [%1]! \n" // load last 8 AYUV // pixels. - "vpadal.u8 q0, q4 \n" // B 16 bytes -> 8 shorts. - "vpadal.u8 q1, q5 \n" // G 16 bytes -> 8 shorts. + "vpadal.u8 q0, q4 \n" // B 16 bytes -> 8 shorts. + "vpadal.u8 q1, q5 \n" // G 16 bytes -> 8 shorts. "vqrshrun.s16 d1, q0, #2 \n" // 2x2 average "vqrshrun.s16 d0, q1, #2 \n" - "subs %3, %3, #16 \n" // 16 processed per loop. - "vst2.8 {d0, d1}, [%2]! \n" // store 8 pixels UV. - "bgt 1b \n" + "vst2.8 {d0, d1}, [%2]! \n" // store 8 pixels UV. + "bgt 1b \n" : "+r"(src_ayuv), // %0 "+r"(src_stride_ayuv), // %1 "+r"(dst_uv), // %2 @@ -2824,24 +3654,24 @@ void AYUVToVURow_NEON(const uint8_t* src_ayuv, uint8_t* dst_vu, int width) { asm volatile( - "add %1, %0, %1 \n" // src_stride + src_AYUV - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 AYUV pixels. - "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 AYUV + "add %1, %0, %1 \n" // src_stride + src_AYUV + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 AYUV pixels. + "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 AYUV // pixels. - "vpaddl.u8 q0, q0 \n" // V 16 bytes -> 8 shorts. - "vpaddl.u8 q1, q1 \n" // U 16 bytes -> 8 shorts. - "vld4.8 {d8, d10, d12, d14}, [%1]! \n" // load 8 more AYUV + "subs %3, %3, #16 \n" // 16 processed per loop. + "vpaddl.u8 q0, q0 \n" // V 16 bytes -> 8 shorts. + "vpaddl.u8 q1, q1 \n" // U 16 bytes -> 8 shorts. + "vld4.8 {d8, d10, d12, d14}, [%1]! \n" // load 8 more AYUV // pixels. - "vld4.8 {d9, d11, d13, d15}, [%1]! \n" // load last 8 AYUV + "vld4.8 {d9, d11, d13, d15}, [%1]! \n" // load last 8 AYUV // pixels. - "vpadal.u8 q0, q4 \n" // B 16 bytes -> 8 shorts. - "vpadal.u8 q1, q5 \n" // G 16 bytes -> 8 shorts. + "vpadal.u8 q0, q4 \n" // B 16 bytes -> 8 shorts. + "vpadal.u8 q1, q5 \n" // G 16 bytes -> 8 shorts. "vqrshrun.s16 d0, q0, #2 \n" // 2x2 average "vqrshrun.s16 d1, q1, #2 \n" - "subs %3, %3, #16 \n" // 16 processed per loop. - "vst2.8 {d0, d1}, [%2]! \n" // store 8 pixels VU. - "bgt 1b \n" + "vst2.8 {d0, d1}, [%2]! \n" // store 8 pixels VU. + "bgt 1b \n" : "+r"(src_ayuv), // %0 "+r"(src_stride_ayuv), // %1 "+r"(dst_vu), // %2 @@ -2854,12 +3684,12 @@ void AYUVToVURow_NEON(const uint8_t* src_ayuv, // Similar to ARGBExtractAlphaRow_NEON void AYUVToYRow_NEON(const uint8_t* src_ayuv, uint8_t* dst_y, int width) { asm volatile( - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 AYUV pixels - "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 AYUV pixels - "subs %2, %2, #16 \n" // 16 processed per loop - "vst1.8 {q2}, [%1]! \n" // store 16 Y's. - "bgt 1b \n" + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 AYUV pixels + "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 AYUV pixels + "subs %2, %2, #16 \n" // 16 processed per loop + "vst1.8 {q2}, [%1]! \n" // store 16 Y's. + "bgt 1b \n" : "+r"(src_ayuv), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -2870,13 +3700,13 @@ void AYUVToYRow_NEON(const uint8_t* src_ayuv, uint8_t* dst_y, int width) { // Convert UV plane of NV12 to VU of NV21. void SwapUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_vu, int width) { asm volatile( - "1: \n" - "vld2.8 {d0, d2}, [%0]! \n" // load 16 UV values - "vld2.8 {d1, d3}, [%0]! \n" - "vorr.u8 q2, q0, q0 \n" // move U after V - "subs %2, %2, #16 \n" // 16 pixels per loop - "vst2.8 {q1, q2}, [%1]! \n" // store 16 VU pixels - "bgt 1b \n" + "1: \n" + "vld2.8 {d0, d2}, [%0]! \n" // load 16 UV values + "vld2.8 {d1, d3}, [%0]! \n" + "subs %2, %2, #16 \n" // 16 pixels per loop + "vmov.u8 q2, q0 \n" // move U after V + "vst2.8 {q1, q2}, [%1]! \n" // store 16 VU pixels + "bgt 1b \n" : "+r"(src_uv), // %0 "+r"(dst_vu), // %1 "+r"(width) // %2 @@ -2884,6 +3714,719 @@ void SwapUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_vu, int width) { : "cc", "memory", "q0", "q1", "q2"); } +void HalfMergeUVRow_NEON(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width) { + const uint8_t* src_u_1 = src_u + src_stride_u; + const uint8_t* src_v_1 = src_v + src_stride_v; + asm volatile( + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 16 U values + "vld1.8 {q1}, [%2]! \n" // load 16 V values + "vld1.8 {q2}, [%1]! \n" + "vld1.8 {q3}, [%3]! \n" + "subs %5, %5, #16 \n" // 16 src pixels per loop + "vpaddl.u8 q0, q0 \n" // half size + "vpaddl.u8 q1, q1 \n" + "vpadal.u8 q0, q2 \n" + "vpadal.u8 q1, q3 \n" + "vqrshrn.u16 d0, q0, #2 \n" + "vqrshrn.u16 d1, q1, #2 \n" + "vst2.8 {d0, d1}, [%4]! \n" // store 8 UV pixels + "bgt 1b \n" + : "+r"(src_u), // %0 + "+r"(src_u_1), // %1 + "+r"(src_v), // %2 + "+r"(src_v_1), // %3 + "+r"(dst_uv), // %4 + "+r"(width) // %5 + : + : "cc", "memory", "q0", "q1", "q2", "q3"); +} + +void SplitUVRow_16_NEON(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width) { + int shift = depth - 16; // Negative for right shift. + asm volatile( + "vdup.16 q2, %4 \n" + "1: \n" + "vld2.16 {q0, q1}, [%0]! \n" // load 8 UV + "subs %3, %3, #8 \n" // 8 src pixels per loop + "vshl.u16 q0, q0, q2 \n" + "vshl.u16 q1, q1, q2 \n" + "vst1.16 {q0}, [%1]! \n" // store 8 U pixels + "vst1.16 {q1}, [%2]! \n" // store 8 V pixels + "bgt 1b \n" + : "+r"(src_uv), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"(shift) // %4 + : "cc", "memory", "q0", "q1", "q2"); +} + +void MergeUVRow_16_NEON(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width) { + int shift = 16 - depth; + asm volatile( + "vdup.16 q2, %4 \n" + "1: \n" + "vld1.16 {q0}, [%0]! \n" // load 8 U + "vld1.16 {q1}, [%1]! \n" // load 8 V + "subs %3, %3, #8 \n" // 8 src pixels per loop + "vshl.u16 q0, q0, q2 \n" + "vshl.u16 q1, q1, q2 \n" + "vst2.16 {q0, q1}, [%2]! \n" // store 8 UV pixels + "bgt 1b \n" + : "+r"(src_u), // %0 + "+r"(src_v), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : "r"(shift) // %4 + : "cc", "memory", "q0", "q1", "q2"); +} + +void MultiplyRow_16_NEON(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + asm volatile( + "vdup.16 q2, %3 \n" + "1: \n" + "vld1.16 {q0}, [%0]! \n" + "vld1.16 {q1}, [%0]! \n" + "subs %2, %2, #16 \n" // 16 src pixels per loop + "vmul.u16 q0, q0, q2 \n" + "vmul.u16 q1, q1, q2 \n" + "vst1.16 {q0}, [%1]! \n" + "vst1.16 {q1}, [%1]! \n" + "bgt 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(scale) // %3 + : "cc", "memory", "q0", "q1", "q2"); +} + +void DivideRow_16_NEON(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + if (scale == 65536) { // Divide by 1, so do memcpy. + if (src_y != dst_y) { + memcpy(dst_y, src_y, (size_t)width * 2); + } + return; + } + asm volatile( + "vdup.16 d8, %3 \n" + "1: \n" + "vld1.16 {q2, q3}, [%0]! \n" + "subs %2, %2, #16 \n" // 16 src pixels per loop + "vmull.u16 q0, d4, d8 \n" + "vmull.u16 q1, d5, d8 \n" + "vmull.u16 q2, d6, d8 \n" + "vmull.u16 q3, d7, d8 \n" + "vshrn.u32 d0, q0, #16 \n" + "vshrn.u32 d1, q1, #16 \n" + "vshrn.u32 d2, q2, #16 \n" + "vshrn.u32 d3, q3, #16 \n" + "vst1.16 {q0, q1}, [%1]! \n" // store 16 pixels + "bgt 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(scale) // %3 + : "cc", "memory", "q0", "q1", "q2", "q3", "d8"); +} + +// Use scale to convert lsb formats to msb, depending how many bits there are: +// 32768 = 9 bits = shr 1 +// 16384 = 10 bits = shr 2 +// 4096 = 12 bits = shr 4 +// 256 = 16 bits = shr 8 +void Convert16To8Row_NEON(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width) { + const int shift = 15 - __builtin_clz((int32_t)scale); // Negative shl is shr + asm volatile( + "vdup.16 q2, %3 \n" + "1: \n" + "vld1.16 {q0}, [%0]! \n" + "vld1.16 {q1}, [%0]! \n" + "subs %2, %2, #16 \n" // 16 src pixels per loop + "vshl.u16 q0, q0, q2 \n" // shr = q2 is negative + "vshl.u16 q1, q1, q2 \n" + "vqmovn.u16 d0, q0 \n" + "vqmovn.u16 d1, q1 \n" + "vst1.8 {q0}, [%1]! \n" + "bgt 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(shift) // %3 + : "cc", "memory", "q0", "q1", "q2"); +} + +void HalfRow_16To8_NEON(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const uint16_t* src_uv1 = src_uv + src_uv_stride; + const int shift = 15 - __builtin_clz((int32_t)scale); // Negative shl is shr + asm volatile( + "vdup.16 q4, %4 \n" + "1: \n" + "vld1.16 {q0, q1}, [%0]! \n" + "vld1.16 {q2, q3}, [%1]! \n" + "subs %3, %3, #16 \n" // 16 src pixels per loop + "vrhadd.u16 q0, q0, q2 \n" + "vrhadd.u16 q1, q1, q3 \n" + "vshl.u16 q0, q0, q4 \n" // shr = q4 is negative + "vshl.u16 q1, q1, q4 \n" + "vqmovn.u16 d0, q0 \n" + "vqmovn.u16 d1, q1 \n" + "vst1.8 {q0}, [%2]! \n" + "bgt 1b \n" + : "+r"(src_uv), // %0 + "+r"(src_uv1), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : "r"(shift) // %4 + : "cc", "memory", "q0", "q1", "q2", "q3", "q4"); +} + +void HalfWidthRow_16To8_NEON(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const uint16_t* src_uv1 = src_uv + src_uv_stride; + const int shift = 15 - __builtin_clz((int32_t)scale); // Negative shl is shr + asm volatile( + "vdup.16 q4, %4 \n" + "1: \n" + "vld1.16 {q0, q1}, [%0]! \n" + "vld1.16 {q2, q3}, [%1]! \n" + "subs %3, %3, #8 \n" // 8 dst pixels per loop + "vpaddl.u16 q0, q0 \n" + "vpaddl.u16 q1, q1 \n" + "vpadal.u16 q0, q2 \n" + "vpadal.u16 q1, q3 \n" + "vrshrn.u32 d0, q0, #2 \n" + "vrshrn.u32 d1, q1, #2 \n" + "vshl.u16 q0, q0, q4 \n" // shr = q4 is negative + "vqmovn.u16 d0, q0 \n" + "vst1.8 {d0}, [%2]! \n" + "bgt 1b \n" + : "+r"(src_uv), // %0 + "+r"(src_uv1), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : "r"(shift) // %4 + : "cc", "memory", "q0", "q1", "q2", "q3", "q4"); +} + +// Use scale to convert J420 to I420 +// scale parameter is 8.8 fixed point but limited to 0 to 255 +// Function is based on DivideRow, but adds a bias +// Does not clamp +void Convert8To8Row_NEON(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width) { + asm volatile( + "vdup.8 d8, %3 \n" + "vdup.8 q5, %4 \n" + "1: \n" + "vld1.8 {q2, q3}, [%0]! \n" + "subs %2, %2, #32 \n" // 32 src pixels per loop + "vmull.u8 q0, d4, d8 \n" + "vmull.u8 q1, d5, d8 \n" + "vmull.u8 q2, d6, d8 \n" + "vmull.u8 q3, d7, d8 \n" + "vuzp.8 q0, q1 \n" + "vuzp.8 q2, q3 \n" + "vadd.u8 q0, q1, q5 \n" + "vadd.u8 q1, q3, q5 \n" + "vst1.8 {q0, q1}, [%1]! \n" // store 32 pixels + "bgt 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(scale), // %3 + "r"(bias) // %4 + : "cc", "memory", "q0", "q1", "q2", "q3", "d8", "q5"); +} + +// Use scale to convert lsb formats to msb, depending how many bits there are: +// 512 = 9 bits +// 1024 = 10 bits +// 4096 = 12 bits +void Convert8To16Row_NEON(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width) { + // (src * 0x0101) >> (16 - bits). + // Use negative shift for right shift with vshl. + const int shift = bits - 16; + asm volatile( + "vdup.16 q2, %3 \n" + "1: \n" + "vld1.8 {q0}, [%0]! \n" + "vmov q1, q0 \n" + "vzip.8 q0, q1 \n" + "subs %2, %2, #16 \n" + "vshl.u16 q0, q0, q2 \n" + "vshl.u16 q1, q1, q2 \n" + "vst1.16 {q0, q1}, [%1]! \n" + "bgt 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(shift) // %3 + : "cc", "memory", "q0", "q1", "q2"); +} + +void CopyRow_16_NEON(const uint16_t* src, uint16_t* dst, int count) { + asm volatile( + "1: \n" + "vld1.16 {d0, d1, d2, d3}, [%0]! \n" // load 16 + "subs %2, %2, #16 \n" // 16 processed per loop + "vst1.16 {d0, d1, d2, d3}, [%1]! \n" // store 16 + "bgt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(count) // %2 + : + : "memory", "cc", "q0", "q1"); +} + +void MirrorRow_16_NEON(const uint16_t* src, uint16_t* dst, int width) { + asm volatile( + // Start at end of source row. + "add %0, %0, %2, lsl #1 \n" + "sub %0, %0, #32 \n" // 32 bytes per loop + "1: \n" + "vld1.16 {q1, q2}, [%0], %3 \n" // src -= 32 + "subs %2, %2, #16 \n" // 16 pixels per loop. + "vrev64.16 q0, q2 \n" + "vrev64.16 q1, q1 \n" + "vswp d0, d1 \n" + "vswp d2, d3 \n" + "vst1.16 {q0, q1}, [%1]! \n" // dst += 32 + "bgt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "r"(-32) // %3 + : "memory", "cc", "q0", "q1", "q2"); +} + +void AR30ToARGBRow_NEON(const uint8_t* src_ar30, uint8_t* dst_argb, int width) { + asm volatile( + "vmov.i32 q8, #0x0000ff00 \n" + "vmov.i32 q9, #0x000fffff \n" + "vshl.i32 q9, q9, #8 \n" // 0x0fffff00 + "1: \n" + "vld1.8 {q0, q1}, [%0]! \n" // load 8 AR30 pixels + "subs %2, %2, #8 \n" // 8 pixels per loop + "vsri.32 q0, q0, #2 \n" + "vsri.32 q1, q1, #2 \n" + "vshr.u32 q2, q0, #2 \n" + "vshr.u32 q3, q1, #2 \n" + "vshr.u32 q4, q0, #4 \n" + "vshr.u32 q5, q1, #4 \n" + "vbit q0, q4, q9 \n" + "vbit q1, q5, q9 \n" + "vbit q0, q2, q8 \n" + "vbit q1, q3, q8 \n" + "vst1.8 {q0, q1}, [%1]! \n" // store 8 ARGB pixels + "bgt 1b \n" + : "+r"(src_ar30), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q8", "q9"); +} + +void AR30ToABGRRow_NEON(const uint8_t* src_ar30, uint8_t* dst_abgr, int width) { + asm volatile( + "vmov.i64 q8, #0x00ffff0000ffff00 \n" + "1: \n" + "vld1.8 {q0, q1}, [%0]! \n" // load 8 AR30 pixels + "subs %2, %2, #8 \n" // 8 pixels per loop + "vsri.32 q0, q0, #2 \n" + "vsri.32 q1, q1, #2 \n" + "vshr.u32 q2, q0, #2 \n" + "vshr.u32 q3, q1, #2 \n" + "vsli.32 q2, q0, #16 \n" + "vsli.32 q3, q1, #16 \n" + "vsri.32 q0, q0, #4 \n" + "vsri.32 q1, q1, #4 \n" + "vsri.32 q0, q0, #16 \n" + "vsri.32 q1, q1, #16 \n" + "vbit q0, q2, q8 \n" + "vbit q1, q3, q8 \n" + "vst1.8 {q0, q1}, [%1]! \n" // store 8 ABGR pixels + "bgt 1b \n" + : "+r"(src_ar30), // %0 + "+r"(dst_abgr), // %1 + "+r"(width) // %2 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q8"); +} + +void AR30ToAB30Row_NEON(const uint8_t* src_ar30, uint8_t* dst_ab30, int width) { + asm volatile( + "vmov.i8 q9, #0xff \n" + "vshr.u32 q9, q9, #22 \n" // 0x000003ff + "vshl.i32 q8, q9, #20 \n" // 0x3ff00000 + "1: \n" + "vld1.8 {q0, q1}, [%0]! \n" // load 8 AR30 pixels + "subs %2, %2, #8 \n" // 8 pixels per loop + "vshl.i32 q2, q0, #20 \n" + "vshl.i32 q3, q1, #20 \n" + "vshr.u32 q4, q0, #20 \n" + "vshr.u32 q5, q1, #20 \n" + "vbit q0, q2, q8 \n" + "vbit q1, q3, q8 \n" + "vbit q0, q4, q9 \n" + "vbit q1, q5, q9 \n" + "vst1.8 {q0, q1}, [%1]! \n" // store 8 AB30 pixels + "bgt 1b \n" + : "+r"(src_ar30), // %0 + "+r"(dst_ab30), // %1 + "+r"(width) // %2 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q8", "q9"); +} + +void ARGBCopyAlphaRow_NEON(const uint8_t* src, uint8_t* dst, int width) { + asm volatile( + "vmov.i32 q4, #0xff000000 \n" + "1: \n" + "vld1.8 {q0, q1}, [%0]! \n" // load 8 src pixels + "vld1.8 {q2, q3}, [%1] \n" // load 8 dst pixels + "subs %2, %2, #8 \n" // 8 pixels per loop + "vbit q2, q0, q4 \n" + "vbit q3, q1, q4 \n" + "vst1.8 {q2, q3}, [%1]! \n" // store 8 dst pixels + "bgt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4"); +} + +void ARGBUnattenuateRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + uint32_t tmp, addr; + asm volatile( + "vmov.i32 q8, #0xff000000 \n" + "1: \n" + "ldrb %3, [%0, #3] \n" + "add %4, %5, %3, lsl #2 \n" + "vld1.16 {d6[0]}, [%4] \n" + "ldrb %3, [%0, #7] \n" + "add %4, %5, %3, lsl #2 \n" + "vld1.16 {d6[1]}, [%4] \n" + "ldrb %3, [%0, #11] \n" + "add %4, %5, %3, lsl #2 \n" + "vld1.16 {d6[2]}, [%4] \n" + "ldrb %3, [%0, #15] \n" + "add %4, %5, %3, lsl #2 \n" + "vld1.16 {d6[3]}, [%4] \n" + "vld1.8 {q0}, [%0]! \n" + "subs %2, %2, #4 \n" + "vmov q1, q0 \n" + "vmov q2, q0 \n" + "vzip.8 q1, q2 \n" + "vmull.u16 q4, d2, d6[0] \n" + "vmull.u16 q5, d3, d6[1] \n" + "vmull.u16 q6, d4, d6[2] \n" + "vmull.u16 q7, d5, d6[3] \n" + "vshrn.i32 d8, q4, #16 \n" + "vshrn.i32 d9, q5, #16 \n" + "vshrn.i32 d12, q6, #16 \n" + "vshrn.i32 d13, q7, #16 \n" + "vqmovn.u16 d2, q4 \n" + "vqmovn.u16 d3, q6 \n" + "vbit q1, q0, q8 \n" + "vst1.8 {q1}, [%1]! \n" + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width), // %2 + "=&r"(tmp), // %3 + "=&r"(addr) // %4 + : "r"(fixed_invtbl8) // %5 + : "memory", "cc", "q0", "q1", "q2", "d6", "q4", "q5", "q6", "q7", "q8"); +} + +void ARGBPolynomialRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + const float* poly, + int width) { + asm volatile( + "vld1.32 {q8, q9}, [%3]! \n" // c0, c1 + "vld1.32 {q10, q11}, [%3] \n" // c2, c3 + "1: \n" + "vld1.8 {d0}, [%0]! \n" // load 2 pixels + "subs %2, %2, #2 \n" // 2 pixels per loop + "vmovl.u8 q0, d0 \n" + "vmovl.u16 q1, d0 \n" + "vmovl.u16 q2, d1 \n" + "vcvt.f32.u32 q1, q1 \n" // x0 + "vcvt.f32.u32 q2, q2 \n" // x1 + "vmul.f32 q3, q9, q1 \n" // c1 * x0 + "vmul.f32 q4, q9, q2 \n" // c1 * x1 + "vmul.f32 q5, q1, q1 \n" // x0 * x0 + "vmul.f32 q6, q2, q2 \n" // x1 * x1 + "vadd.f32 q3, q8, q3 \n" // c0 + c1 * x0 + "vadd.f32 q4, q8, q4 \n" // c0 + c1 * x1 + "vmla.f32 q3, q10, q5 \n" // + c2 * x0^2 + "vmla.f32 q4, q10, q6 \n" // + c2 * x1^2 + "vmul.f32 q5, q5, q1 \n" // x0^3 + "vmul.f32 q6, q6, q2 \n" // x1^3 + "vmla.f32 q3, q11, q5 \n" // + c3 * x0^3 + "vmla.f32 q4, q11, q6 \n" // + c3 * x1^3 + "vcvt.s32.f32 q3, q3 \n" + "vcvt.s32.f32 q4, q4 \n" + "vqmovn.s32 d6, q3 \n" + "vqmovn.s32 d7, q4 \n" + "vqmovun.s16 d6, q3 \n" + "vst1.8 {d6}, [%1]! \n" + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width), // %2 + "+r"(poly) // %3 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q8", "q9", + "q10", "q11"); +} + +void ARGBColorTableRow_NEON(uint8_t* dst_argb, + const uint8_t* table_argb, + int width) { + const uint8_t* table_g = table_argb + 1; + const uint8_t* table_r = table_argb + 2; + const uint8_t* table_a = table_argb + 3; + uint32_t b, g, r, a; + asm volatile( + "1: \n" + "ldrb %2, [%0] \n" + "ldrb %3, [%0, #1] \n" + "ldrb %4, [%0, #2] \n" + "ldrb %5, [%0, #3] \n" + "ldrb %2, [%6, %2, lsl #2] \n" + "ldrb %3, [%7, %3, lsl #2] \n" + "ldrb %4, [%8, %4, lsl #2] \n" + "ldrb %5, [%9, %5, lsl #2] \n" + "subs %1, %1, #1 \n" + "strb %2, [%0] \n" + "strb %3, [%0, #1] \n" + "strb %4, [%0, #2] \n" + "strb %5, [%0, #3] \n" + "add %0, %0, #4 \n" + "bgt 1b \n" + : "+r"(dst_argb), // %0 + "+r"(width), // %1 + "=&r"(b), // %2 + "=&r"(g), // %3 + "=&r"(r), // %4 + "=&r"(a) // %5 + : "r"(table_argb), // %6 + "r"(table_g), // %7 + "r"(table_r), // %8 + "r"(table_a) // %9 + : "memory", "cc"); +} + +void RGBColorTableRow_NEON(uint8_t* dst_argb, + const uint8_t* table_argb, + int width) { + const uint8_t* table_g = table_argb + 1; + const uint8_t* table_r = table_argb + 2; + uint32_t b, g, r; + asm volatile( + "1: \n" + "ldrb %2, [%0] \n" + "ldrb %3, [%0, #1] \n" + "ldrb %4, [%0, #2] \n" + "ldrb %2, [%5, %2, lsl #2] \n" + "ldrb %3, [%6, %3, lsl #2] \n" + "ldrb %4, [%7, %4, lsl #2] \n" + "subs %1, %1, #1 \n" + "strb %2, [%0] \n" + "strb %3, [%0, #1] \n" + "strb %4, [%0, #2] \n" + "add %0, %0, #4 \n" + "bgt 1b \n" + : "+r"(dst_argb), // %0 + "+r"(width), // %1 + "=&r"(b), // %2 + "=&r"(g), // %3 + "=&r"(r) // %4 + : "r"(table_argb), // %5 + "r"(table_g), // %6 + "r"(table_r) // %7 + : "memory", "cc"); +} + +void ARGBLumaColorTableRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + int width, + const uint8_t* luma, + uint32_t lumacoeff) { + uint32_t idx, addr; + asm volatile( + "vdup.32 q4, %6 \n" // lumacoeff + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load 4 ARGB pixels + "subs %2, %2, #4 \n" // 4 pixels per loop + "vmull.u8 q1, d0, d8 \n" + "vmull.u8 q2, d1, d9 \n" + "vpadd.i16 d2, d2, d3 \n" + "vpadd.i16 d3, d4, d5 \n" + "vpadd.i16 d2, d2, d3 \n" + "vbic.i16 d2, #0x8000 \n" // clear bit 15 + "vshrn.i16 d2, q1, #8 \n" // L_k & 0x7f + "vmov d3, d2 \n" + "vzip.8 d2, d3 \n" + "vmov d3, d2 \n" + "vzip.8 d2, d3 \n" + "vmov q2, q0 \n" + "vzip.8 q2, q1 \n" // q2: p0,1; q1: p2,3 + "vmov.u16 %3, d4[0] \n" + "add %4, %5, %3 \n" + "vld1.8 {d0[0]}, [%4] \n" + "vmov.u16 %3, d4[1] \n" + "add %4, %5, %3 \n" + "vld1.8 {d0[1]}, [%4] \n" + "vmov.u16 %3, d4[2] \n" + "add %4, %5, %3 \n" + "vld1.8 {d0[2]}, [%4] \n" + "vmov.u16 %3, d5[0] \n" + "add %4, %5, %3 \n" + "vld1.8 {d0[4]}, [%4] \n" + "vmov.u16 %3, d5[1] \n" + "add %4, %5, %3 \n" + "vld1.8 {d0[5]}, [%4] \n" + "vmov.u16 %3, d5[2] \n" + "add %4, %5, %3 \n" + "vld1.8 {d0[6]}, [%4] \n" + "vmov.u16 %3, d2[0] \n" + "add %4, %5, %3 \n" + "vld1.8 {d1[0]}, [%4] \n" + "vmov.u16 %3, d2[1] \n" + "add %4, %5, %3 \n" + "vld1.8 {d1[1]}, [%4] \n" + "vmov.u16 %3, d2[2] \n" + "add %4, %5, %3 \n" + "vld1.8 {d1[2]}, [%4] \n" + "vmov.u16 %3, d3[0] \n" + "add %4, %5, %3 \n" + "vld1.8 {d1[4]}, [%4] \n" + "vmov.u16 %3, d3[1] \n" + "add %4, %5, %3 \n" + "vld1.8 {d1[5]}, [%4] \n" + "vmov.u16 %3, d3[2] \n" + "add %4, %5, %3 \n" + "vld1.8 {d1[6]}, [%4] \n" + "vst1.8 {q0}, [%1]! \n" + "bgt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width), // %2 + "=&r"(idx), // %3 + "=&r"(addr) // %4 + : "r"(luma), // %5 + "r"(lumacoeff) // %6 + : "memory", "cc", "q0", "q1", "q2", "q4"); +} + +void ARGBAffineRow_NEON(const uint8_t* src_argb, + int src_argb_stride, + uint8_t* dst_argb, + const float* uv_dudv, + int width) { + uint32_t off0, off1; + asm volatile( + "vld1.32 {d4, d5}, [%5] \n" // d4=[u,v], d5=[du,dv] + "vmov d12, d5 \n" // d12=[du,dv] + "vdup.32 d10, %4 \n" // [stride, stride] + "vmov.i32 d11, #4 \n" // [4, 4] + "vtrn.32 d11, d10 \n" // q5=[4, stride, 4, + // stride] + "subs %1, %1, #4 \n" + "blt 2f \n" + "vmov d13, d12 \n" // q6=[du, dv, du, dv] + "vadd.f32 q4, q6, q6 \n" // 2 * [du, dv, du, dv] + "vadd.f32 d5, d4, d12 \n" // [u+du, v+dv] + "vadd.f32 q3, q2, q4 \n" // [u+2du, v+2dv, u+3du, + // v+3dv] + "vadd.f32 q4, q4, q4 \n" // 4 * [du, dv, du, dv] + "1: \n" + "vcvt.s32.f32 q0, q2 \n" + "vcvt.s32.f32 q1, q3 \n" + "vadd.f32 q2, q2, q4 \n" + "vadd.f32 q3, q3, q4 \n" + "vmul.i32 q0, q0, q5 \n" + "vmul.i32 q1, q1, q5 \n" + "vpadd.i32 d14, d0, d1 \n" + "vpadd.i32 d15, d2, d3 \n" + "vmov %2, %3, d14 \n" + "ldr %2, [%6, %2] \n" + "ldr %3, [%6, %3] \n" + "str %2, [%0], #4 \n" + "str %3, [%0], #4 \n" + "vmov %2, %3, d15 \n" + "ldr %2, [%6, %2] \n" + "ldr %3, [%6, %3] \n" + "str %2, [%0], #4 \n" + "str %3, [%0], #4 \n" + "subs %1, %1, #4 \n" + "bge 1b \n" + "2: \n" + "adds %1, %1, #4 \n" + "beq 4f \n" + "3: \n" + "vcvt.s32.f32 d0, d4 \n" + "vadd.f32 d4, d4, d12 \n" + "vmul.i32 d0, d0, d10 \n" + "vpadd.i32 d0, d0, d0 \n" + "vmov.32 %2, d0[0] \n" + "ldr %2, [%6, %2] \n" + "str %2, [%0], #4 \n" + "subs %1, %1, #1 \n" + "bgt 3b \n" + "4: \n" + : "+r"(dst_argb), // %0 + "+r"(width), // %1 + "=&r"(off0), // %2 + "=&r"(off1) // %3 + : "r"(src_argb_stride), // %4 + "r"(uv_dudv), // %5 + "r"(src_argb) // %6 + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7"); +} + #endif // !defined(LIBYUV_DISABLE_NEON) && defined(__ARM_NEON__).. #ifdef __cplusplus diff --git a/libs/libyuv/source/row_neon64.cc b/libs/libyuv/source/row_neon64.cc index e70953f299..e39360537b 100644 --- a/libs/libyuv/source/row_neon64.cc +++ b/libs/libyuv/source/row_neon64.cc @@ -8,6 +8,9 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include + +#include "libyuv/convert_from_argb.h" #include "libyuv/row.h" #ifdef __cplusplus @@ -15,102 +18,237 @@ namespace libyuv { extern "C" { #endif +// Enable LIBYUV_USE_ST2, LIBYUV_USE_ST3, LIBYUV_USE_ST4 for CPUs that prefer +// STn over ZIP1+ST1 +// Exynos M1, M2, M3 are slow with ST2, ST3 and ST4 instructions. + +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + // This module is for GCC Neon armv8 64 bit. #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) +// v0.8h: Y +// v1.16b: 8U, 8V + // Read 8 Y, 4 U and 4 V from 422 #define READYUV422 \ - "ld1 {v0.8b}, [%0], #8 \n" \ - "ld1 {v1.s}[0], [%1], #4 \n" \ - "ld1 {v1.s}[1], [%2], #4 \n" + "ldr d0, [%[src_y]], #8 \n" \ + "ldr s1, [%[src_u]], #4 \n" \ + "ldr s2, [%[src_v]], #4 \n" \ + "zip1 v0.16b, v0.16b, v0.16b \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "zip1 v1.8b, v1.8b, v1.8b \n" \ + "zip1 v2.8b, v2.8b, v2.8b \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" + +// Read 8 Y, 4 U and 4 V from 210 +#define READYUV210 \ + "ldr q2, [%[src_y]], #16 \n" \ + "ldr d1, [%[src_u]], #8 \n" \ + "ldr d3, [%[src_v]], #8 \n" \ + "shl v0.8h, v2.8h, #6 \n" \ + "usra v0.8h, v2.8h, #4 \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "zip1 v2.8h, v3.8h, v3.8h \n" \ + "zip1 v3.8h, v1.8h, v1.8h \n" \ + "uqshrn v1.8b, v3.8h, #2 \n" \ + "uqshrn2 v1.16b, v2.8h, #2 \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" + +// Read 8 Y, 4 U and 4 V interleaved from 210 +#define READYUVP210 \ + "ldr q0, [%[src_y]], #16 \n" \ + "ldr q1, [%[src_uv]], #16 \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "tbl v1.16b, {v1.16b}, v2.16b \n" + +// Read 8 Y, 4 U and 4 V from 212 +#define READYUV212 \ + "ldr q2, [%[src_y]], #16 \n" \ + "ldr d1, [%[src_u]], #8 \n" \ + "ldr d3, [%[src_v]], #8 \n" \ + "shl v0.8h, v2.8h, #4 \n" \ + "usra v0.8h, v2.8h, #8 \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "zip1 v2.8h, v3.8h, v3.8h \n" \ + "zip1 v3.8h, v1.8h, v1.8h \n" \ + "uqshrn v1.8b, v3.8h, #4 \n" \ + "uqshrn2 v1.16b, v2.8h, #4 \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" + +// Read 8 Y, 8 U and 8 V from 410 +#define READYUV410 \ + "ldr q1, [%[src_y]], #16 \n" \ + "ldr q2, [%[src_u]], #16 \n" \ + "ldr q3, [%[src_v]], #16 \n" \ + "shl v0.8h, v1.8h, #6 \n" \ + "usra v0.8h, v1.8h, #4 \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "uqshrn v1.8b, v2.8h, #2 \n" \ + "uqshrn2 v1.16b, v3.8h, #2 \n" \ + "prfm pldl1keep, [%[src_u], 128] \n" \ + "prfm pldl1keep, [%[src_v], 128] \n" + +// Read 8 Y, 8 U and 8 V interleaved from 410 +#define READYUVP410 \ + "ldr q0, [%[src_y]], #16 \n" \ + "ldp q4, q5, [%[src_uv]], #32 \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "tbl v1.16b, {v4.16b, v5.16b}, v2.16b \n" // Read 8 Y, 8 U and 8 V from 444 #define READYUV444 \ - "ld1 {v0.8b}, [%0], #8 \n" \ - "ld1 {v1.d}[0], [%1], #8 \n" \ - "ld1 {v1.d}[1], [%2], #8 \n" \ - "uaddlp v1.8h, v1.16b \n" \ - "rshrn v1.8b, v1.8h, #1 \n" + "ldr d0, [%[src_y]], #8 \n" \ + "ldr d1, [%[src_u]], #8 \n" \ + "ldr d2, [%[src_v]], #8 \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "prfm pldl1keep, [%[src_u], 448] \n" \ + "zip1 v0.16b, v0.16b, v0.16b \n" \ + "prfm pldl1keep, [%[src_v], 448] \n" -// Read 8 Y, and set 4 U and 4 V to 128 +// Read 8 Y #define READYUV400 \ - "ld1 {v0.8b}, [%0], #8 \n" \ - "movi v1.8b , #128 \n" + "ldr d0, [%[src_y]], #8 \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "zip1 v0.16b, v0.16b, v0.16b \n" -// Read 8 Y and 4 UV from NV12 +static const uvec8 kNV12Table = {0, 0, 2, 2, 4, 4, 6, 6, + 1, 1, 3, 3, 5, 5, 7, 7}; +static const uvec8 kNV12InterleavedTable = {0, 0, 4, 4, 8, 8, 12, 12, + 2, 2, 6, 6, 10, 10, 14, 14}; +static const uvec8 kNV21Table = {1, 1, 3, 3, 5, 5, 7, 7, + 0, 0, 2, 2, 4, 4, 6, 6}; +static const uvec8 kNV21InterleavedTable = {1, 1, 5, 5, 9, 9, 13, 13, + 3, 3, 7, 7, 11, 11, 15, 15}; + +// Read 8 Y and 4 UV from NV12 or NV21 #define READNV12 \ - "ld1 {v0.8b}, [%0], #8 \n" \ - "ld1 {v2.8b}, [%1], #8 \n" \ - "uzp1 v1.8b, v2.8b, v2.8b \n" \ - "uzp2 v3.8b, v2.8b, v2.8b \n" \ - "ins v1.s[1], v3.s[0] \n" - -// Read 8 Y and 4 VU from NV21 -#define READNV21 \ - "ld1 {v0.8b}, [%0], #8 \n" \ - "ld1 {v2.8b}, [%1], #8 \n" \ - "uzp1 v3.8b, v2.8b, v2.8b \n" \ - "uzp2 v1.8b, v2.8b, v2.8b \n" \ - "ins v1.s[1], v3.s[0] \n" + "ldr d0, [%[src_y]], #8 \n" \ + "ldr d1, [%[src_uv]], #8 \n" \ + "zip1 v0.16b, v0.16b, v0.16b \n" \ + "prfm pldl1keep, [%[src_y], 448] \n" \ + "tbl v1.16b, {v1.16b}, v2.16b \n" \ + "prfm pldl1keep, [%[src_uv], 448] \n" // Read 8 YUY2 #define READYUY2 \ - "ld2 {v0.8b, v1.8b}, [%0], #16 \n" \ - "uzp2 v3.8b, v1.8b, v1.8b \n" \ - "uzp1 v1.8b, v1.8b, v1.8b \n" \ - "ins v1.s[1], v3.s[0] \n" + "ld1 {v3.16b}, [%[src_yuy2]], #16 \n" \ + "trn1 v0.16b, v3.16b, v3.16b \n" \ + "prfm pldl1keep, [%[src_yuy2], 448] \n" \ + "tbl v1.16b, {v3.16b}, v2.16b \n" // Read 8 UYVY #define READUYVY \ - "ld2 {v2.8b, v3.8b}, [%0], #16 \n" \ - "orr v0.8b, v3.8b, v3.8b \n" \ - "uzp1 v1.8b, v2.8b, v2.8b \n" \ - "uzp2 v3.8b, v2.8b, v2.8b \n" \ - "ins v1.s[1], v3.s[0] \n" + "ld1 {v3.16b}, [%[src_uyvy]], #16 \n" \ + "trn2 v0.16b, v3.16b, v3.16b \n" \ + "prfm pldl1keep, [%[src_uyvy], 448] \n" \ + "tbl v1.16b, {v3.16b}, v2.16b \n" -#define YUVTORGB_SETUP \ - "ld1r {v24.8h}, [%[kUVBiasBGR]], #2 \n" \ - "ld1r {v25.8h}, [%[kUVBiasBGR]], #2 \n" \ - "ld1r {v26.8h}, [%[kUVBiasBGR]] \n" \ - "ld1r {v31.4s}, [%[kYToRgb]] \n" \ - "ld2 {v27.8h, v28.8h}, [%[kUVToRB]] \n" \ - "ld2 {v29.8h, v30.8h}, [%[kUVToG]] \n" +// UB VR UG VG +// YG BB BG BR +#define YUVTORGB_SETUP \ + "ld4r {v28.16b, v29.16b, v30.16b, v31.16b}, [%[kUVCoeff]] \n" \ + "ld4r {v24.8h, v25.8h, v26.8h, v27.8h}, [%[kRGBCoeffBias]] \n" -#define YUVTORGB(vR, vG, vB) \ - "uxtl v0.8h, v0.8b \n" /* Extract Y */ \ - "shll v2.8h, v1.8b, #8 \n" /* Replicate UV */ \ - "ushll2 v3.4s, v0.8h, #0 \n" /* Y */ \ - "ushll v0.4s, v0.4h, #0 \n" \ - "mul v3.4s, v3.4s, v31.4s \n" \ - "mul v0.4s, v0.4s, v31.4s \n" \ - "sqshrun v0.4h, v0.4s, #16 \n" \ - "sqshrun2 v0.8h, v3.4s, #16 \n" /* Y */ \ - "uaddw v1.8h, v2.8h, v1.8b \n" /* Replicate UV */ \ - "mov v2.d[0], v1.d[1] \n" /* Extract V */ \ - "uxtl v2.8h, v2.8b \n" \ - "uxtl v1.8h, v1.8b \n" /* Extract U */ \ - "mul v3.8h, v1.8h, v27.8h \n" \ - "mul v5.8h, v1.8h, v29.8h \n" \ - "mul v6.8h, v2.8h, v30.8h \n" \ - "mul v7.8h, v2.8h, v28.8h \n" \ - "sqadd v6.8h, v6.8h, v5.8h \n" \ - "sqadd " #vB \ - ".8h, v24.8h, v0.8h \n" /* B */ \ - "sqadd " #vG \ - ".8h, v25.8h, v0.8h \n" /* G */ \ - "sqadd " #vR \ - ".8h, v26.8h, v0.8h \n" /* R */ \ - "sqadd " #vB ".8h, " #vB \ - ".8h, v3.8h \n" /* B */ \ - "sqsub " #vG ".8h, " #vG \ - ".8h, v6.8h \n" /* G */ \ - "sqadd " #vR ".8h, " #vR \ - ".8h, v7.8h \n" /* R */ \ - "sqshrun " #vB ".8b, " #vB \ - ".8h, #6 \n" /* B */ \ - "sqshrun " #vG ".8b, " #vG \ - ".8h, #6 \n" /* G */ \ - "sqshrun " #vR ".8b, " #vR ".8h, #6 \n" /* R */ +#define YUVTORGB_SETUP_AR30 \ + YUVTORGB_SETUP \ + "movi v2.8h, #24 \n" \ + "add v25.8h, v25.8h, v2.8h \n" \ + "sub v26.8h, v26.8h, v2.8h \n" \ + "add v27.8h, v27.8h, v2.8h \n" + +// v16.8h: B +// v17.8h: G +// v18.8h: R + +// Convert from YUV (NV12 or NV21) to 2.14 fixed point RGB. +// Similar to I4XXTORGB but U/V components are in the low/high halves of v1. +#define NVTORGB \ + "umull2 v3.4s, v0.8h, v24.8h \n" \ + "umull v6.8h, v1.8b, v30.8b \n" \ + "umull v0.4s, v0.4h, v24.4h \n" \ + "umlal2 v6.8h, v1.16b, v31.16b \n" /* DG */ \ + "uzp2 v0.8h, v0.8h, v3.8h \n" /* Y */ \ + "umull v4.8h, v1.8b, v28.8b \n" /* DB */ \ + "umull2 v5.8h, v1.16b, v29.16b \n" /* DR */ \ + "add v17.8h, v0.8h, v26.8h \n" /* G */ \ + "add v16.8h, v0.8h, v4.8h \n" /* B */ \ + "add v18.8h, v0.8h, v5.8h \n" /* R */ \ + "uqsub v17.8h, v17.8h, v6.8h \n" /* G */ \ + "uqsub v16.8h, v16.8h, v25.8h \n" /* B */ \ + "uqsub v18.8h, v18.8h, v27.8h \n" /* R */ + +// Convert from YUV (I444 or I420) to 2.14 fixed point RGB. +// Similar to NVTORGB but U/V components are in v1/v2. +#define I4XXTORGB \ + "umull2 v3.4s, v0.8h, v24.8h \n" \ + "umull v6.8h, v1.8b, v30.8b \n" \ + "umull v0.4s, v0.4h, v24.4h \n" \ + "umlal v6.8h, v2.8b, v31.8b \n" /* DG */ \ + "uzp2 v0.8h, v0.8h, v3.8h \n" /* Y */ \ + "umull v4.8h, v1.8b, v28.8b \n" /* DB */ \ + "umull v5.8h, v2.8b, v29.8b \n" /* DR */ \ + "add v17.8h, v0.8h, v26.8h \n" /* G */ \ + "add v16.8h, v0.8h, v4.8h \n" /* B */ \ + "add v18.8h, v0.8h, v5.8h \n" /* R */ \ + "uqsub v17.8h, v17.8h, v6.8h \n" /* G */ \ + "uqsub v16.8h, v16.8h, v25.8h \n" /* B */ \ + "uqsub v18.8h, v18.8h, v27.8h \n" /* R */ + +// Convert from YUV I400 to 2.14 fixed point RGB +#define I400TORGB \ + "umull2 v3.4s, v0.8h, v24.8h \n" \ + "umull v0.4s, v0.4h, v24.4h \n" \ + "uzp2 v0.8h, v0.8h, v3.8h \n" /* Y */ \ + "add v17.8h, v0.8h, v26.8h \n" /* G */ \ + "add v16.8h, v0.8h, v4.8h \n" /* B */ \ + "add v18.8h, v0.8h, v5.8h \n" /* R */ \ + "uqsub v17.8h, v17.8h, v6.8h \n" /* G */ \ + "uqsub v16.8h, v16.8h, v25.8h \n" /* B */ \ + "uqsub v18.8h, v18.8h, v27.8h \n" /* R */ + +// Convert from 2.14 fixed point RGB To 8 bit RGB +#define RGBTORGB8 \ + "uqshrn v17.8b, v17.8h, #6 \n" \ + "uqshrn v16.8b, v16.8h, #6 \n" \ + "uqshrn v18.8b, v18.8h, #6 \n" + +// Convert from 2.14 fixed point RGB to 8 bit RGB, placing the results in the +// top half of each lane. +#define RGBTORGB8_TOP \ + "uqshl v17.8h, v17.8h, #2 \n" \ + "uqshl v16.8h, v16.8h, #2 \n" \ + "uqshl v18.8h, v18.8h, #2 \n" + +// Store 2.14 fixed point RGB as AR30 elements +#define STOREAR30 \ + /* Inputs: \ + * v16.8h: xxbbbbbbbbbbxxxx \ + * v17.8h: xxggggggggggxxxx \ + * v18.8h: xxrrrrrrrrrrxxxx \ + * v22.8h: 0011111111110000 (umin limit) \ + * v23.8h: 1100000000000000 (alpha) \ + */ \ + "uqshl v0.8h, v16.8h, #2 \n" /* bbbbbbbbbbxxxxxx */ \ + "uqshl v1.8h, v17.8h, #2 \n" /* ggggggggggxxxxxx */ \ + "umin v6.8h, v18.8h, v22.8h \n" /* 00rrrrrrrrrrxxxx */ \ + "shl v4.8h, v1.8h, #4 \n" /* ggggggxxxxxx0000 */ \ + "orr v5.16b, v6.16b, v23.16b \n" /* 11rrrrrrrrrrxxxx */ \ + "sri v4.8h, v0.8h, #6 \n" /* ggggggbbbbbbbbbb */ \ + "sri v5.8h, v1.8h, #12 \n" /* 11rrrrrrrrrrgggg */ \ + "st2 {v4.8h, v5.8h}, [%[dst_ar30]], #32 \n" + +#define YUVTORGB_REGS \ + "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18", "v24", \ + "v25", "v26", "v27", "v28", "v29", "v30", "v31" void I444ToARGBRow_NEON(const uint8_t* src_y, const uint8_t* src_u, @@ -118,27 +256,204 @@ void I444ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "movi v23.8b, #255 \n" /* A */ - "1: \n" - READYUV444 - YUVTORGB(v22, v21, v20) - "subs %w4, %w4, #8 \n" - "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%3], #32 \n" - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_argb), // %3 - "+r"(width) // %4 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "movi v19.8b, #255 \n" /* A */ + "1: \n" // + READYUV444 + "subs %w[width], %w[width], #8 \n" I4XXTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); +} + +void I444ToRGB24Row_NEON(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + YUVTORGB_SETUP + "1: \n" // + READYUV444 + "subs %w[width], %w[width], #8 \n" I4XXTORGB RGBTORGB8 + "st3 {v16.8b,v17.8b,v18.8b}, [%[dst_rgb24]], #24 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS); +} + +void I210ToAR30Row_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + const uvec8* uv_coeff = &yuvconstants->kUVCoeff; + const vec16* rgb_coeff = &yuvconstants->kRGBCoeffBias; + uint16_t limit = 0x3ff0; + uint16_t alpha = 0xc000; + asm volatile(YUVTORGB_SETUP + "dup v22.8h, %w[limit] \n" + "dup v23.8h, %w[alpha] \n" + "1: \n" // + READYUV210 + "subs %w[width], %w[width], #8 \n" NVTORGB STOREAR30 + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(uv_coeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(rgb_coeff), // %[kRGBCoeffBias] + [limit] "r"(limit), // %[limit] + [alpha] "r"(alpha) // %[alpha] + : "cc", "memory", YUVTORGB_REGS, "v22", "v23"); +} + +void I410ToAR30Row_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + const uvec8* uv_coeff = &yuvconstants->kUVCoeff; + const vec16* rgb_coeff = &yuvconstants->kRGBCoeffBias; + uint16_t limit = 0x3ff0; + uint16_t alpha = 0xc000; + asm volatile(YUVTORGB_SETUP + "dup v22.8h, %w[limit] \n" + "dup v23.8h, %w[alpha] \n" + "1: \n" // + READYUV410 + "subs %w[width], %w[width], #8 \n" NVTORGB STOREAR30 + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(uv_coeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(rgb_coeff), // %[kRGBCoeffBias] + [limit] "r"(limit), // %[limit] + [alpha] "r"(alpha) // %[alpha] + : "cc", "memory", YUVTORGB_REGS, "v22", "v23"); +} + +void I212ToAR30Row_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + const uvec8* uv_coeff = &yuvconstants->kUVCoeff; + const vec16* rgb_coeff = &yuvconstants->kRGBCoeffBias; + const uint16_t limit = 0x3ff0; + asm volatile(YUVTORGB_SETUP + "dup v22.8h, %w[limit] \n" + "movi v23.8h, #0xc0, lsl #8 \n" // A + "1: \n" // + READYUV212 + "subs %w[width], %w[width], #8 \n" NVTORGB STOREAR30 + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(uv_coeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(rgb_coeff), // %[kRGBCoeffBias] + [limit] "r"(limit) // %[limit] + : "cc", "memory", YUVTORGB_REGS, "v22", "v23"); +} + +void I210ToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + YUVTORGB_SETUP + "movi v19.8b, #255 \n" + "1: \n" // + READYUV210 + "subs %w[width], %w[width], #8 \n" NVTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); +} + +void I410ToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + YUVTORGB_SETUP + "movi v19.8b, #255 \n" + "1: \n" // + READYUV410 + "subs %w[width], %w[width], #8 \n" NVTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); +} + +void I212ToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + const uvec8* uv_coeff = &yuvconstants->kUVCoeff; + const vec16* rgb_coeff = &yuvconstants->kRGBCoeffBias; + asm volatile( + YUVTORGB_SETUP + "movi v19.8b, #255 \n" + "1: \n" // + READYUV212 + "subs %w[width], %w[width], #8 \n" NVTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(uv_coeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(rgb_coeff) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); } void I422ToARGBRow_NEON(const uint8_t* src_y, @@ -147,27 +462,240 @@ void I422ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "movi v23.8b, #255 \n" /* A */ - "1: \n" - READYUV422 - YUVTORGB(v22, v21, v20) - "subs %w4, %w4, #8 \n" - "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%3], #32 \n" - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_argb), // %3 - "+r"(width) // %4 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "movi v19.8b, #255 \n" /* A */ + "1: \n" // + READYUV422 + "subs %w[width], %w[width], #8 \n" I4XXTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); +} + +uint8_t kP210LoadShuffleIndices[] = {1, 1, 5, 5, 9, 9, 13, 13, + 3, 3, 7, 7, 11, 11, 15, 15}; + +void P210ToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + const uvec8* uv_coeff = &yuvconstants->kUVCoeff; + const vec16* rgb_coeff = &yuvconstants->kRGBCoeffBias; + asm volatile( + YUVTORGB_SETUP + "movi v19.8b, #255 \n" + "ldr q2, [%[kIndices]] \n" + "1: \n" // + READYUVP210 + "subs %w[width], %w[width], #8 \n" NVTORGB RGBTORGB8 + "st4 {v16.8b, v17.8b, v18.8b, v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(uv_coeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(rgb_coeff), // %[kRGBCoeffBias] + [kIndices] "r"(kP210LoadShuffleIndices) // %[kIndices] + : "cc", "memory", YUVTORGB_REGS, "v19"); +} + +uint8_t kP410LoadShuffleIndices[] = {1, 5, 9, 13, 17, 21, 25, 29, + 3, 7, 11, 15, 19, 23, 27, 31}; + +void P410ToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + const uvec8* uv_coeff = &yuvconstants->kUVCoeff; + const vec16* rgb_coeff = &yuvconstants->kRGBCoeffBias; + asm volatile( + YUVTORGB_SETUP + "movi v19.8b, #255 \n" + "ldr q2, [%[kIndices]] \n" + "1: \n" // + READYUVP410 + "subs %w[width], %w[width], #8 \n" NVTORGB RGBTORGB8 + "st4 {v16.8b, v17.8b, v18.8b, v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(uv_coeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(rgb_coeff), // %[kRGBCoeffBias] + [kIndices] "r"(kP410LoadShuffleIndices) // %[kIndices] + : "cc", "memory", YUVTORGB_REGS, "v19"); +} + +void P210ToAR30Row_NEON(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + const uvec8* uv_coeff = &yuvconstants->kUVCoeff; + const vec16* rgb_coeff = &yuvconstants->kRGBCoeffBias; + const uint16_t limit = 0x3ff0; + asm volatile(YUVTORGB_SETUP + "dup v22.8h, %w[limit] \n" + "movi v23.8h, #0xc0, lsl #8 \n" // A + "ldr q2, [%[kIndices]] \n" + "1: \n" // + READYUVP210 + "subs %w[width], %w[width], #8 \n" NVTORGB STOREAR30 + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(uv_coeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(rgb_coeff), // %[kRGBCoeffBias] + [limit] "r"(limit), // %[limit] + [kIndices] "r"(kP210LoadShuffleIndices) // %[kIndices] + : "cc", "memory", YUVTORGB_REGS, "v22", "v23"); +} + +void P410ToAR30Row_NEON(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + const uvec8* uv_coeff = &yuvconstants->kUVCoeff; + const vec16* rgb_coeff = &yuvconstants->kRGBCoeffBias; + uint16_t limit = 0x3ff0; + asm volatile(YUVTORGB_SETUP + "dup v22.8h, %w[limit] \n" + "movi v23.8h, #0xc0, lsl #8 \n" // A + "ldr q2, [%[kIndices]] \n" + "1: \n" // + READYUVP410 + "subs %w[width], %w[width], #8 \n" NVTORGB STOREAR30 + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(uv_coeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(rgb_coeff), // %[kRGBCoeffBias] + [limit] "r"(limit), // %[limit] + [kIndices] "r"(kP410LoadShuffleIndices) // %[kIndices] + : "cc", "memory", YUVTORGB_REGS, "v22", "v23"); +} + +void I422ToAR30Row_NEON(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + const uvec8* uv_coeff = &yuvconstants->kUVCoeff; + const vec16* rgb_coeff = &yuvconstants->kRGBCoeffBias; + const uint16_t limit = 0x3ff0; + asm volatile( + YUVTORGB_SETUP_AR30 + "dup v22.8h, %w[limit] \n" + "movi v23.8h, #0xc0, lsl #8 \n" // A + "1: \n" // + READYUV422 + "subs %w[width], %w[width], #8 \n" I4XXTORGB STOREAR30 + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(uv_coeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(rgb_coeff), // %[kRGBCoeffBias] + [limit] "r"(limit) // %[limit] + : "cc", "memory", YUVTORGB_REGS, "v22", "v23"); +} + +void I444AlphaToARGBRow_NEON(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + YUVTORGB_SETUP + "1: \n" + "ld1 {v19.8b}, [%[src_a]], #8 \n" READYUV444 + "subs %w[width], %w[width], #8 \n" + "prfm pldl1keep, [%[src_a], 448] \n" I4XXTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); +} + +void I410AlphaToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + YUVTORGB_SETUP + "1: \n" + "ld1 {v19.16b}, [%[src_a]], #16 \n" READYUV410 + "subs %w[width], %w[width], #8 \n" + "uqshrn v19.8b, v19.8h, #2 \n" NVTORGB RGBTORGB8 + "st4 {v16.8b, v17.8b, v18.8b, v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); +} + +void I210AlphaToARGBRow_NEON(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + YUVTORGB_SETUP + "1: \n" + "ld1 {v19.16b}, [%[src_a]], #16 \n" READYUV210 + "subs %w[width], %w[width], #8 \n" + "uqshrn v19.8b, v19.8h, #2 \n" NVTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); } void I422AlphaToARGBRow_NEON(const uint8_t* src_y, @@ -177,28 +705,23 @@ void I422AlphaToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "1: \n" - READYUV422 - YUVTORGB(v22, v21, v20) - "ld1 {v23.8b}, [%3], #8 \n" - "subs %w5, %w5, #8 \n" - "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%4], #32 \n" - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(src_a), // %3 - "+r"(dst_argb), // %4 - "+r"(width) // %5 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "1: \n" + "ld1 {v19.8b}, [%[src_a]], #8 \n" READYUV422 + "subs %w[width], %w[width], #8 \n" + "prfm pldl1keep, [%[src_a], 448] \n" I4XXTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); } void I422ToRGBARow_NEON(const uint8_t* src_y, @@ -207,27 +730,22 @@ void I422ToRGBARow_NEON(const uint8_t* src_y, uint8_t* dst_rgba, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "movi v20.8b, #255 \n" /* A */ - "1: \n" - READYUV422 - YUVTORGB(v23, v22, v21) - "subs %w4, %w4, #8 \n" - "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%3], #32 \n" - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_rgba), // %3 - "+r"(width) // %4 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "movi v15.8b, #255 \n" /* A */ + "1: \n" // + READYUV422 + "subs %w[width], %w[width], #8 \n" I4XXTORGB RGBTORGB8 + "st4 {v15.8b,v16.8b,v17.8b,v18.8b}, [%[dst_rgba]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgba] "+r"(dst_rgba), // %[dst_rgba] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v15"); } void I422ToRGB24Row_NEON(const uint8_t* src_y, @@ -236,34 +754,41 @@ void I422ToRGB24Row_NEON(const uint8_t* src_y, uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "1: \n" - READYUV422 - YUVTORGB(v22, v21, v20) - "subs %w4, %w4, #8 \n" - "st3 {v20.8b,v21.8b,v22.8b}, [%3], #24 \n" - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_rgb24), // %3 - "+r"(width) // %4 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "1: \n" // + READYUV422 + "subs %w[width], %w[width], #8 \n" I4XXTORGB RGBTORGB8 + "st3 {v16.8b,v17.8b,v18.8b}, [%[dst_rgb24]], #24 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS); } -#define ARGBTORGB565 \ - "shll v0.8h, v22.8b, #8 \n" /* R */ \ - "shll v21.8h, v21.8b, #8 \n" /* G */ \ - "shll v20.8h, v20.8b, #8 \n" /* B */ \ - "sri v0.8h, v21.8h, #5 \n" /* RG */ \ - "sri v0.8h, v20.8h, #11 \n" /* RGB */ +#define ARGBTORGB565 \ + /* Inputs: \ + * v16: bbbbbxxx \ + * v17: ggggggxx \ + * v18: rrrrrxxx */ \ + "shll v18.8h, v18.8b, #8 \n" /* rrrrrrxx00000000 */ \ + "shll v17.8h, v17.8b, #8 \n" /* gggggxxx00000000 */ \ + "shll v16.8h, v16.8b, #8 \n" /* bbbbbbxx00000000 */ \ + "sri v18.8h, v17.8h, #5 \n" /* rrrrrgggggg00000 */ \ + "sri v18.8h, v16.8h, #11 \n" /* rrrrrggggggbbbbb */ + +#define ARGBTORGB565_FROM_TOP \ + /* Inputs: \ + * v16: bbbbbxxxxxxxxxxx \ + * v17: ggggggxxxxxxxxxx \ + * v18: rrrrrxxxxxxxxxxx */ \ + "sri v18.8h, v17.8h, #5 \n" /* rrrrrgggggg00000 */ \ + "sri v18.8h, v16.8h, #11 \n" /* rrrrrggggggbbbbb */ void I422ToRGB565Row_NEON(const uint8_t* src_y, const uint8_t* src_u, @@ -273,33 +798,37 @@ void I422ToRGB565Row_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "1: \n" READYUV422 YUVTORGB( - v22, v21, - v20) "subs %w4, %w4, #8 \n" ARGBTORGB565 - "st1 {v0.8h}, [%3], #16 \n" // store 8 pixels - // RGB565. - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_rgb565), // %3 - "+r"(width) // %4 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"); + "1: \n" // + READYUV422 "subs %w[width], %w[width], #8 \n" I4XXTORGB + RGBTORGB8_TOP ARGBTORGB565_FROM_TOP + "st1 {v18.8h}, [%[dst_rgb565]], #16 \n" // store 8 pixels RGB565. + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgb565] "+r"(dst_rgb565), // %[dst_rgb565] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS); } -#define ARGBTOARGB1555 \ - "shll v0.8h, v23.8b, #8 \n" /* A */ \ - "shll v22.8h, v22.8b, #8 \n" /* R */ \ - "shll v21.8h, v21.8b, #8 \n" /* G */ \ - "shll v20.8h, v20.8b, #8 \n" /* B */ \ - "sri v0.8h, v22.8h, #1 \n" /* AR */ \ - "sri v0.8h, v21.8h, #6 \n" /* ARG */ \ - "sri v0.8h, v20.8h, #11 \n" /* ARGB */ +#define ARGBTOARGB1555 \ + /* Inputs: \ + * v16: gggggxxxbbbbbxxx v17: axxxxxxxrrrrrxxx */ \ + "shl v1.8h, v16.8h, #8 \n" /* bbbbbxxx00000000 */ \ + "shl v2.8h, v17.8h, #8 \n" /* rrrrrxxx00000000 */ \ + "sri v17.8h, v2.8h, #1 \n" /* arrrrrxxxrrrrxxx */ \ + "sri v17.8h, v16.8h, #6 \n" /* arrrrrgggggxxxbb */ \ + "sri v17.8h, v1.8h, #11 \n" /* arrrrrgggggbbbbb */ + +#define ARGBTOARGB1555_FROM_TOP \ + /* Inputs: \ + * v16: bbbbbxxxxxxxxxxx v17: gggggxxxxxxxxxxx \ + * v18: rrrrrxxxxxxxxxxx v19: axxxxxxxxxxxxxxx */ \ + "sri v19.8h, v18.8h, #1 \n" /* arrrrrxxxxxxxxxx */ \ + "sri v19.8h, v17.8h, #6 \n" /* arrrrrgggggxxxxx */ \ + "sri v19.8h, v16.8h, #11 \n" /* arrrrrgggggbbbbb */ void I422ToARGB1555Row_NEON(const uint8_t* src_y, const uint8_t* src_u, @@ -309,35 +838,28 @@ void I422ToARGB1555Row_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "movi v23.8b, #255 \n" - "1: \n" READYUV422 YUVTORGB( - v22, v21, - v20) "subs %w4, %w4, #8 \n" ARGBTOARGB1555 - "st1 {v0.8h}, [%3], #16 \n" // store 8 pixels - // RGB565. - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_argb1555), // %3 - "+r"(width) // %4 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"); + "movi v19.8h, #0x80, lsl #8 \n" + "1: \n" // + READYUV422 "subs %w[width], %w[width], #8 \n" // + I4XXTORGB RGBTORGB8_TOP ARGBTOARGB1555_FROM_TOP + "st1 {v19.8h}, [%[dst_argb1555]], #16 \n" // store 8 pixels + // RGB1555. + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb1555] "+r"(dst_argb1555), // %[dst_argb1555] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); } -#define ARGBTOARGB4444 \ - /* Input v20.8b<=B, v21.8b<=G, v22.8b<=R, v23.8b<=A, v4.8b<=0x0f */ \ - "ushr v20.8b, v20.8b, #4 \n" /* B */ \ - "bic v21.8b, v21.8b, v4.8b \n" /* G */ \ - "ushr v22.8b, v22.8b, #4 \n" /* R */ \ - "bic v23.8b, v23.8b, v4.8b \n" /* A */ \ - "orr v0.8b, v20.8b, v21.8b \n" /* BG */ \ - "orr v1.8b, v22.8b, v23.8b \n" /* RA */ \ - "zip1 v0.16b, v0.16b, v1.16b \n" /* BGRA */ +#define ARGBTOARGB4444 \ + /* Input v16.8b<=B, v17.8b<=G, v18.8b<=R, v19.8b<=A */ \ + "sri v17.8b, v16.8b, #4 \n" /* BG */ \ + "sri v19.8b, v18.8b, #4 \n" /* RA */ \ + "zip1 v0.16b, v17.16b, v19.16b \n" /* BGRA */ void I422ToARGB4444Row_NEON(const uint8_t* src_y, const uint8_t* src_u, @@ -345,95 +867,112 @@ void I422ToARGB4444Row_NEON(const uint8_t* src_y, uint8_t* dst_argb4444, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "movi v4.16b, #0x0f \n" // bits to clear with vbic. - "1: \n" - READYUV422 - YUVTORGB(v22, v21, v20) - "subs %w4, %w4, #8 \n" - "movi v23.8b, #255 \n" - ARGBTOARGB4444 - "st1 {v0.8h}, [%3], #16 \n" // store 8 pixels ARGB4444. - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_u), // %1 - "+r"(src_v), // %2 - "+r"(dst_argb4444), // %3 - "+r"(width) // %4 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "1: \n" // + READYUV422 + "subs %w[width], %w[width], #8 \n" I4XXTORGB RGBTORGB8 + "movi v19.8b, #255 \n" ARGBTOARGB4444 + "st1 {v0.8h}, [%[dst_argb4444]], #16 \n" // store 8 + // pixels + // ARGB4444. + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb4444] "+r"(dst_argb4444), // %[dst_argb4444] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); } -void I400ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, int width) { - asm volatile ( - YUVTORGB_SETUP - "movi v23.8b, #255 \n" - "1: \n" - READYUV400 - YUVTORGB(v22, v21, v20) - "subs %w2, %w2, #8 \n" - "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%1], #32 \n" - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : [kUVToRB]"r"(&kYuvI601Constants.kUVToRB), - [kUVToG]"r"(&kYuvI601Constants.kUVToG), - [kUVBiasBGR]"r"(&kYuvI601Constants.kUVBiasBGR), - [kYToRgb]"r"(&kYuvI601Constants.kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); +void I400ToARGBRow_NEON(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + asm volatile( + YUVTORGB_SETUP + "movi v1.16b, #128 \n" + "movi v19.8b, #255 \n" + "umull v6.8h, v1.8b, v30.8b \n" + "umlal2 v6.8h, v1.16b, v31.16b \n" /* DG */ + "umull v4.8h, v1.8b, v28.8b \n" /* DB */ + "umull2 v5.8h, v1.16b, v29.16b \n" /* DR */ + "1: \n" // + READYUV400 I400TORGB + "subs %w[width], %w[width], #8 \n" RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_REGS, "v19"); } +#if defined(LIBYUV_USE_ST4) void J400ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, int width) { asm volatile( - "movi v23.8b, #255 \n" - "1: \n" - "ld1 {v20.8b}, [%0], #8 \n" - "orr v21.8b, v20.8b, v20.8b \n" - "orr v22.8b, v20.8b, v20.8b \n" - "subs %w2, %w2, #8 \n" - "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%1], #32 \n" - "b.gt 1b \n" + "movi v23.8b, #255 \n" + "1: \n" + "ld1 {v20.8b}, [%0], #8 \n" + "subs %w2, %w2, #8 \n" + "prfm pldl1keep, [%0, 448] \n" + "mov v21.8b, v20.8b \n" + "mov v22.8b, v20.8b \n" + "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%1], #32 \n" + "b.gt 1b \n" : "+r"(src_y), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 : : "cc", "memory", "v20", "v21", "v22", "v23"); } +#else +void J400ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, int width) { + asm volatile( + "movi v20.8b, #255 \n" + "1: \n" + "ldr d16, [%0], #8 \n" + "subs %w2, %w2, #8 \n" + "zip1 v18.16b, v16.16b, v16.16b \n" // YY + "zip1 v19.16b, v16.16b, v20.16b \n" // YA + "prfm pldl1keep, [%0, 448] \n" + "zip1 v16.16b, v18.16b, v19.16b \n" // YYYA + "zip2 v17.16b, v18.16b, v19.16b \n" + "stp q16, q17, [%1], #32 \n" + "b.gt 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : + : "cc", "memory", "v16", "v17", "v18", "v19", "v20"); +} +#endif // LIBYUV_USE_ST4 void NV12ToARGBRow_NEON(const uint8_t* src_y, const uint8_t* src_uv, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "movi v23.8b, #255 \n" - "1: \n" - READNV12 - YUVTORGB(v22, v21, v20) - "subs %w3, %w3, #8 \n" - "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%2], #32 \n" - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_uv), // %1 - "+r"(dst_argb), // %2 - "+r"(width) // %3 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "movi v19.8b, #255 \n" + "ldr q2, [%[kNV12Table]] \n" + "1: \n" // + READNV12 "subs %w[width], %w[width], #8 \n" NVTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [kNV12Table] "r"(&kNV12Table) + : "cc", "memory", YUVTORGB_REGS, "v2", "v19"); } void NV21ToARGBRow_NEON(const uint8_t* src_y, @@ -441,26 +980,22 @@ void NV21ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "movi v23.8b, #255 \n" - "1: \n" - READNV21 - YUVTORGB(v22, v21, v20) - "subs %w3, %w3, #8 \n" - "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%2], #32 \n" - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_vu), // %1 - "+r"(dst_argb), // %2 - "+r"(width) // %3 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "movi v19.8b, #255 \n" + "ldr q2, [%[kNV12Table]] \n" + "1: \n" // + READNV12 "subs %w[width], %w[width], #8 \n" NVTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_vu), // %[src_uv] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [kNV12Table] "r"(&kNV21Table) + : "cc", "memory", YUVTORGB_REGS, "v2", "v19"); } void NV12ToRGB24Row_NEON(const uint8_t* src_y, @@ -468,25 +1003,21 @@ void NV12ToRGB24Row_NEON(const uint8_t* src_y, uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "1: \n" - READNV12 - YUVTORGB(v22, v21, v20) - "subs %w3, %w3, #8 \n" - "st3 {v20.8b,v21.8b,v22.8b}, [%2], #24 \n" - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_uv), // %1 - "+r"(dst_rgb24), // %2 - "+r"(width) // %3 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "ldr q2, [%[kNV12Table]] \n" + "1: \n" // + READNV12 "subs %w[width], %w[width], #8 \n" NVTORGB RGBTORGB8 + "st3 {v16.8b,v17.8b,v18.8b}, [%[dst_rgb24]], #24 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [kNV12Table] "r"(&kNV12Table) + : "cc", "memory", YUVTORGB_REGS, "v2"); } void NV21ToRGB24Row_NEON(const uint8_t* src_y, @@ -494,25 +1025,21 @@ void NV21ToRGB24Row_NEON(const uint8_t* src_y, uint8_t* dst_rgb24, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "1: \n" - READNV21 - YUVTORGB(v22, v21, v20) - "subs %w3, %w3, #8 \n" - "st3 {v20.8b,v21.8b,v22.8b}, [%2], #24 \n" - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_vu), // %1 - "+r"(dst_rgb24), // %2 - "+r"(width) // %3 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "ldr q2, [%[kNV12Table]] \n" + "1: \n" // + READNV12 "subs %w[width], %w[width], #8 \n" NVTORGB RGBTORGB8 + "st3 {v16.8b,v17.8b,v18.8b}, [%[dst_rgb24]], #24 \n" + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_vu), // %[src_uv] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [kNV12Table] "r"(&kNV21Table) + : "cc", "memory", YUVTORGB_REGS, "v2"); } void NV12ToRGB565Row_NEON(const uint8_t* src_y, @@ -522,72 +1049,64 @@ void NV12ToRGB565Row_NEON(const uint8_t* src_y, int width) { asm volatile( YUVTORGB_SETUP - "1: \n" READNV12 YUVTORGB( - v22, v21, - v20) "subs %w3, %w3, #8 \n" ARGBTORGB565 - "st1 {v0.8h}, [%2], 16 \n" // store 8 pixels - // RGB565. - "b.gt 1b \n" - : "+r"(src_y), // %0 - "+r"(src_uv), // %1 - "+r"(dst_rgb565), // %2 - "+r"(width) // %3 - : [kUVToRB] "r"(&yuvconstants->kUVToRB), - [kUVToG] "r"(&yuvconstants->kUVToG), - [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR), - [kYToRgb] "r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"); + "ldr q2, [%[kNV12Table]] \n" + "1: \n" // + READNV12 "subs %w[width], %w[width], #8 \n" NVTORGB + RGBTORGB8_TOP ARGBTORGB565_FROM_TOP + "st1 {v18.8h}, [%[dst_rgb565]], #16 \n" // store 8 + // pixels + // RGB565. + "b.gt 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_rgb565] "+r"(dst_rgb565), // %[dst_rgb565] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [kNV12Table] "r"(&kNV12Table) + : "cc", "memory", YUVTORGB_REGS, "v2"); } void YUY2ToARGBRow_NEON(const uint8_t* src_yuy2, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "movi v23.8b, #255 \n" - "1: \n" - READYUY2 - YUVTORGB(v22, v21, v20) - "subs %w2, %w2, #8 \n" - "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%1], #32 \n" - "b.gt 1b \n" - : "+r"(src_yuy2), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "movi v19.8b, #255 \n" + "ldr q2, [%[kNV21InterleavedTable]] \n" + "1: \n" // + READYUY2 "subs %w[width], %w[width], #8 \n" NVTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_yuy2] "+r"(src_yuy2), // %[src_yuy2] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [kNV21InterleavedTable] "r"(&kNV21InterleavedTable) + : "cc", "memory", YUVTORGB_REGS, "v2", "v19"); } void UYVYToARGBRow_NEON(const uint8_t* src_uyvy, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) { - asm volatile ( - YUVTORGB_SETUP - "movi v23.8b, #255 \n" - "1: \n" - READUYVY - YUVTORGB(v22, v21, v20) - "subs %w2, %w2, #8 \n" - "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%1], 32 \n" - "b.gt 1b \n" - : "+r"(src_uyvy), // %0 - "+r"(dst_argb), // %1 - "+r"(width) // %2 - : [kUVToRB]"r"(&yuvconstants->kUVToRB), - [kUVToG]"r"(&yuvconstants->kUVToG), - [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR), - [kYToRgb]"r"(&yuvconstants->kYToRgb) - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", - "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30" - ); + asm volatile( + YUVTORGB_SETUP + "movi v19.8b, #255 \n" + "ldr q2, [%[kNV12InterleavedTable]] \n" + "1: \n" // + READUYVY "subs %w[width], %w[width], #8 \n" NVTORGB RGBTORGB8 + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%[dst_argb]], #32 \n" + "b.gt 1b \n" + : [src_uyvy] "+r"(src_uyvy), // %[src_yuy2] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias), // %[kRGBCoeffBias] + [kNV12InterleavedTable] "r"(&kNV12InterleavedTable) + : "cc", "memory", YUVTORGB_REGS, "v2", "v19"); } // Reads 16 pairs of UV and write even values to dst_u and odd to dst_v. @@ -596,12 +1115,13 @@ void SplitUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_v, int width) { asm volatile( - "1: \n" - "ld2 {v0.16b,v1.16b}, [%0], #32 \n" // load 16 pairs of UV - "subs %w3, %w3, #16 \n" // 16 processed per loop - "st1 {v0.16b}, [%1], #16 \n" // store U - "st1 {v1.16b}, [%2], #16 \n" // store V - "b.gt 1b \n" + "1: \n" + "ld2 {v0.16b,v1.16b}, [%0], #32 \n" // load 16 pairs of UV + "subs %w3, %w3, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 448] \n" + "st1 {v0.16b}, [%1], #16 \n" // store U + "st1 {v1.16b}, [%2], #16 \n" // store V + "b.gt 1b \n" : "+r"(src_uv), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -611,18 +1131,181 @@ void SplitUVRow_NEON(const uint8_t* src_uv, ); } +// Reads 16 byte Y's from tile and writes out 16 Y's. +// MM21 Y tiles are 16x32 so src_tile_stride = 512 bytes +// MM21 UV tiles are 8x16 so src_tile_stride = 256 bytes +// width measured in bytes so 8 UV = 16. +void DetileRow_NEON(const uint8_t* src, + ptrdiff_t src_tile_stride, + uint8_t* dst, + int width) { + asm volatile( + "1: \n" + "ld1 {v0.16b}, [%0], %3 \n" // load 16 bytes + "subs %w2, %w2, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 1792] \n" // 7 tiles of 256b ahead + "st1 {v0.16b}, [%1], #16 \n" // store 16 bytes + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "r"(src_tile_stride) // %3 + : "cc", "memory", "v0" // Clobber List + ); +} + +// Reads 16 byte Y's of 16 bits from tile and writes out 16 Y's. +void DetileRow_16_NEON(const uint16_t* src, + ptrdiff_t src_tile_stride, + uint16_t* dst, + int width) { + asm volatile( + "1: \n" + "ld1 {v0.8h,v1.8h}, [%0], %3 \n" // load 16 pixels + "subs %w2, %w2, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 3584] \n" // 7 tiles of 512b ahead + "st1 {v0.8h,v1.8h}, [%1], #32 \n" // store 16 pixels + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "r"(src_tile_stride * 2) // %3 + : "cc", "memory", "v0", "v1" // Clobber List + ); +} + +// Read 16 bytes of UV, detile, and write 8 bytes of U and 8 bytes of V. +void DetileSplitUVRow_NEON(const uint8_t* src_uv, + ptrdiff_t src_tile_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + asm volatile( + "1: \n" + "ld2 {v0.8b,v1.8b}, [%0], %4 \n" + "subs %w3, %w3, #16 \n" + "prfm pldl1keep, [%0, 1792] \n" + "st1 {v0.8b}, [%1], #8 \n" + "st1 {v1.8b}, [%2], #8 \n" + "b.gt 1b \n" + : "+r"(src_uv), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"(src_tile_stride) // %4 + : "cc", "memory", "v0", "v1" // Clobber List + ); +} + +#if defined(LIBYUV_USE_ST2) +// Read 16 Y, 8 UV, and write 8 YUY2 +void DetileToYUY2_NEON(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width) { + asm volatile( + "1: \n" + "ld1 {v0.16b}, [%0], %4 \n" // load 16 Ys + "subs %w3, %w3, #16 \n" // store 8 YUY2 + "prfm pldl1keep, [%0, 1792] \n" + "ld1 {v1.16b}, [%1], %5 \n" // load 8 UVs + "prfm pldl1keep, [%1, 1792] \n" + "st2 {v0.16b,v1.16b}, [%2], #32 \n" + "b.gt 1b \n" + : "+r"(src_y), // %0 + "+r"(src_uv), // %1 + "+r"(dst_yuy2), // %2 + "+r"(width) // %3 + : "r"(src_y_tile_stride), // %4 + "r"(src_uv_tile_stride) // %5 + : "cc", "memory", "v0", "v1" // Clobber list + ); +} +#else +// Read 16 Y, 8 UV, and write 8 YUY2 +void DetileToYUY2_NEON(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width) { + asm volatile( + "1: \n" + "ld1 {v0.16b}, [%0], %4 \n" // load 16 Ys + "ld1 {v1.16b}, [%1], %5 \n" // load 8 UVs + "subs %w3, %w3, #16 \n" + "prfm pldl1keep, [%0, 1792] \n" + "zip1 v2.16b, v0.16b, v1.16b \n" + "prfm pldl1keep, [%1, 1792] \n" + "zip2 v3.16b, v0.16b, v1.16b \n" + "st1 {v2.16b,v3.16b}, [%2], #32 \n" // store 8 YUY2 + "b.gt 1b \n" + : "+r"(src_y), // %0 + "+r"(src_uv), // %1 + "+r"(dst_yuy2), // %2 + "+r"(width) // %3 + : "r"(src_y_tile_stride), // %4 + "r"(src_uv_tile_stride) // %5 + : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber list + ); +} +#endif + +// Unpack MT2T into tiled P010 64 pixels at a time. See +// tinyurl.com/mtk-10bit-video-format for format documentation. +void UnpackMT2T_NEON(const uint8_t* src, uint16_t* dst, size_t size) { + asm volatile( + "1: \n" + "ld1 {v7.16b}, [%0], #16 \n" + "ld1 {v0.16b-v3.16b}, [%0], #64 \n" + "subs %2, %2, #80 \n" + "shl v4.16b, v7.16b, #6 \n" + "shl v5.16b, v7.16b, #4 \n" + "shl v6.16b, v7.16b, #2 \n" + "zip1 v16.16b, v4.16b, v0.16b \n" + "zip1 v18.16b, v5.16b, v1.16b \n" + "zip1 v20.16b, v6.16b, v2.16b \n" + "zip1 v22.16b, v7.16b, v3.16b \n" + "zip2 v17.16b, v4.16b, v0.16b \n" + "zip2 v19.16b, v5.16b, v1.16b \n" + "zip2 v21.16b, v6.16b, v2.16b \n" + "zip2 v23.16b, v7.16b, v3.16b \n" + "sri v16.8h, v16.8h, #10 \n" + "sri v17.8h, v17.8h, #10 \n" + "sri v18.8h, v18.8h, #10 \n" + "sri v19.8h, v19.8h, #10 \n" + "st1 {v16.8h-v19.8h}, [%1], #64 \n" + "sri v20.8h, v20.8h, #10 \n" + "sri v21.8h, v21.8h, #10 \n" + "sri v22.8h, v22.8h, #10 \n" + "sri v23.8h, v23.8h, #10 \n" + "st1 {v20.8h-v23.8h}, [%1], #64 \n" + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(size) // %2 + : + : "cc", "memory", "w0", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", + "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23"); +} + +#if defined(LIBYUV_USE_ST2) // Reads 16 U's and V's and writes out 16 pairs of UV. void MergeUVRow_NEON(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width) { asm volatile( - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load U - "ld1 {v1.16b}, [%1], #16 \n" // load V - "subs %w3, %w3, #16 \n" // 16 processed per loop - "st2 {v0.16b,v1.16b}, [%2], #32 \n" // store 16 pairs of UV - "b.gt 1b \n" + "1: \n" + "ld1 {v0.16b}, [%0], #16 \n" // load U + "ld1 {v1.16b}, [%1], #16 \n" // load V + "subs %w3, %w3, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 448] \n" + "prfm pldl1keep, [%1, 448] \n" + "st2 {v0.16b,v1.16b}, [%2], #32 \n" // store 16 pairs of UV + "b.gt 1b \n" : "+r"(src_u), // %0 "+r"(src_v), // %1 "+r"(dst_uv), // %2 @@ -632,6 +1315,86 @@ void MergeUVRow_NEON(const uint8_t* src_u, ); } +void MergeUVRow_16_NEON(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width) { + int shift = 16 - depth; + asm volatile( + "dup v2.8h, %w4 \n" + "1: \n" + "ld1 {v0.8h}, [%0], #16 \n" // load 8 U + "ld1 {v1.8h}, [%1], #16 \n" // load 8 V + "subs %w3, %w3, #8 \n" // 8 src pixels per loop + "ushl v0.8h, v0.8h, v2.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "ushl v1.8h, v1.8h, v2.8h \n" + "prfm pldl1keep, [%1, 448] \n" + "st2 {v0.8h, v1.8h}, [%2], #32 \n" // store 8 UV pixels + "b.gt 1b \n" + : "+r"(src_u), // %0 + "+r"(src_v), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : "r"(shift) // %4 + : "cc", "memory", "v0", "v1", "v2"); +} +#else +// Reads 16 U's and V's and writes out 16 pairs of UV. +void MergeUVRow_NEON(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width) { + asm volatile( + "1: \n" + "ld1 {v0.16b}, [%0], #16 \n" // load U + "ld1 {v1.16b}, [%1], #16 \n" // load V + "subs %w3, %w3, #16 \n" // 16 processed per loop + "zip1 v2.16b, v0.16b, v1.16b \n" + "prfm pldl1keep, [%0, 448] \n" + "zip2 v3.16b, v0.16b, v1.16b \n" + "prfm pldl1keep, [%1, 448] \n" + "st1 {v2.16b,v3.16b}, [%2], #32 \n" // store 16 pairs of UV + "b.gt 1b \n" + : "+r"(src_u), // %0 + "+r"(src_v), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 // Output registers + : // Input registers + : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List + ); +} + +void MergeUVRow_16_NEON(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width) { + int shift = 16 - depth; + asm volatile( + "dup v4.8h, %w4 \n" + "1: \n" + "ld1 {v0.8h}, [%0], #16 \n" // load 8 U + "ld1 {v1.8h}, [%1], #16 \n" // load 8 V + "subs %w3, %w3, #8 \n" // 8 src pixels per loop + "ushl v0.8h, v0.8h, v4.8h \n" + "ushl v1.8h, v1.8h, v4.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "zip1 v2.8h, v0.8h, v1.8h \n" + "zip2 v3.8h, v0.8h, v1.8h \n" + "prfm pldl1keep, [%1, 448] \n" + "st1 {v2.8h, v3.8h}, [%2], #32 \n" // store 8 UV pixels + "b.gt 1b \n" + : "+r"(src_u), // %0 + "+r"(src_v), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : "r"(shift) // %4 + : "cc", "memory", "v0", "v1", "v2", "v1", "v2", "v3", "v4"); +} +#endif // LIBYUV_USE_ST2 + // Reads 16 packed RGB and write to planar dst_r, dst_g, dst_b. void SplitRGBRow_NEON(const uint8_t* src_rgb, uint8_t* dst_r, @@ -639,13 +1402,14 @@ void SplitRGBRow_NEON(const uint8_t* src_rgb, uint8_t* dst_b, int width) { asm volatile( - "1: \n" - "ld3 {v0.16b,v1.16b,v2.16b}, [%0], #48 \n" // load 16 RGB - "subs %w4, %w4, #16 \n" // 16 processed per loop - "st1 {v0.16b}, [%1], #16 \n" // store R - "st1 {v1.16b}, [%2], #16 \n" // store G - "st1 {v2.16b}, [%3], #16 \n" // store B - "b.gt 1b \n" + "1: \n" + "ld3 {v0.16b,v1.16b,v2.16b}, [%0], #48 \n" // load 16 RGB + "subs %w4, %w4, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 448] \n" + "st1 {v0.16b}, [%1], #16 \n" // store R + "st1 {v1.16b}, [%2], #16 \n" // store G + "st1 {v2.16b}, [%3], #16 \n" // store B + "b.gt 1b \n" : "+r"(src_rgb), // %0 "+r"(dst_r), // %1 "+r"(dst_g), // %2 @@ -663,13 +1427,16 @@ void MergeRGBRow_NEON(const uint8_t* src_r, uint8_t* dst_rgb, int width) { asm volatile( - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load R - "ld1 {v1.16b}, [%1], #16 \n" // load G - "ld1 {v2.16b}, [%2], #16 \n" // load B - "subs %w4, %w4, #16 \n" // 16 processed per loop - "st3 {v0.16b,v1.16b,v2.16b}, [%3], #48 \n" // store 16 RGB - "b.gt 1b \n" + "1: \n" + "ld1 {v0.16b}, [%0], #16 \n" // load R + "ld1 {v1.16b}, [%1], #16 \n" // load G + "ld1 {v2.16b}, [%2], #16 \n" // load B + "subs %w4, %w4, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 448] \n" + "prfm pldl1keep, [%1, 448] \n" + "prfm pldl1keep, [%2, 448] \n" + "st3 {v0.16b,v1.16b,v2.16b}, [%3], #48 \n" // store 16 RGB + "b.gt 1b \n" : "+r"(src_r), // %0 "+r"(src_g), // %1 "+r"(src_b), // %2 @@ -680,14 +1447,402 @@ void MergeRGBRow_NEON(const uint8_t* src_r, ); } +// Reads 16 packed ARGB and write to planar dst_r, dst_g, dst_b, dst_a. +void SplitARGBRow_NEON(const uint8_t* src_rgba, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width) { + asm volatile( + "1: \n" + "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 ARGB + "subs %w5, %w5, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 448] \n" + "st1 {v0.16b}, [%3], #16 \n" // store B + "st1 {v1.16b}, [%2], #16 \n" // store G + "st1 {v2.16b}, [%1], #16 \n" // store R + "st1 {v3.16b}, [%4], #16 \n" // store A + "b.gt 1b \n" + : "+r"(src_rgba), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+r"(dst_a), // %4 + "+r"(width) // %5 + : // Input registers + : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List + ); +} + +#if defined(LIBYUV_USE_ST4) +// Reads 16 planar R's, G's, B's and A's and writes out 16 packed ARGB at a time +void MergeARGBRow_NEON(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width) { + asm volatile( + "1: \n" + "ld1 {v0.16b}, [%2], #16 \n" // load B + "ld1 {v1.16b}, [%1], #16 \n" // load G + "ld1 {v2.16b}, [%0], #16 \n" // load R + "ld1 {v3.16b}, [%3], #16 \n" // load A + "subs %w5, %w5, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 448] \n" + "prfm pldl1keep, [%1, 448] \n" + "prfm pldl1keep, [%2, 448] \n" + "prfm pldl1keep, [%3, 448] \n" + "st4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%4], #64 \n" // store 16ARGB + "b.gt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(src_a), // %3 + "+r"(dst_argb), // %4 + "+r"(width) // %5 + : // Input registers + : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List + ); +} +#else +// Reads 16 planar R's, G's, B's and A's and writes out 16 packed ARGB at a time +void MergeARGBRow_NEON(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width) { + asm volatile( + "1: \n" + "ld1 {v0.16b}, [%2], #16 \n" // load B + "ld1 {v1.16b}, [%1], #16 \n" // load G + "ld1 {v2.16b}, [%0], #16 \n" // load R + "ld1 {v3.16b}, [%3], #16 \n" // load A + "subs %w5, %w5, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%2, 448] \n" + "zip1 v4.16b, v0.16b, v1.16b \n" // BG + "zip1 v5.16b, v2.16b, v3.16b \n" // RA + "prfm pldl1keep, [%1, 448] \n" + "zip2 v6.16b, v0.16b, v1.16b \n" // BG + "zip2 v7.16b, v2.16b, v3.16b \n" // RA + "prfm pldl1keep, [%0, 448] \n" + "zip1 v0.8h, v4.8h, v5.8h \n" // BGRA + "zip2 v1.8h, v4.8h, v5.8h \n" + "prfm pldl1keep, [%3, 448] \n" + "zip1 v2.8h, v6.8h, v7.8h \n" + "zip2 v3.8h, v6.8h, v7.8h \n" + "st1 {v0.16b,v1.16b,v2.16b,v3.16b}, [%4], #64 \n" // store 16ARGB + "b.gt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(src_a), // %3 + "+r"(dst_argb), // %4 + "+r"(width) // %5 + : // Input registers + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", + "v7" // Clobber List + ); +} +#endif // LIBYUV_USE_ST4 + +// Reads 16 packed ARGB and write to planar dst_r, dst_g, dst_b. +void SplitXRGBRow_NEON(const uint8_t* src_rgba, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + asm volatile( + "1: \n" + "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 ARGB + "subs %w4, %w4, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 448] \n" + "st1 {v0.16b}, [%3], #16 \n" // store B + "st1 {v1.16b}, [%2], #16 \n" // store G + "st1 {v2.16b}, [%1], #16 \n" // store R + "b.gt 1b \n" + : "+r"(src_rgba), // %0 + "+r"(dst_r), // %1 + "+r"(dst_g), // %2 + "+r"(dst_b), // %3 + "+r"(width) // %4 + : // Input registers + : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List + ); +} + +// Reads 16 planar R's, G's and B's and writes out 16 packed ARGB at a time +void MergeXRGBRow_NEON(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width) { + asm volatile( + "movi v3.16b, #255 \n" // load A(255) + "1: \n" + "ld1 {v2.16b}, [%0], #16 \n" // load R + "ld1 {v1.16b}, [%1], #16 \n" // load G + "ld1 {v0.16b}, [%2], #16 \n" // load B + "subs %w4, %w4, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 448] \n" + "prfm pldl1keep, [%1, 448] \n" + "prfm pldl1keep, [%2, 448] \n" + "st4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%3], #64 \n" // store 16ARGB + "b.gt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_argb), // %3 + "+r"(width) // %4 + : // Input registers + : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List + ); +} + +void MergeXR30Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int depth, + int width) { + int shift = 10 - depth; + asm volatile( + "movi v30.16b, #255 \n" + "ushr v30.4s, v30.4s, #22 \n" // 1023 + "dup v31.4s, %w5 \n" + "1: \n" + "ldr d2, [%2], #8 \n" // B + "ldr d1, [%1], #8 \n" // G + "ldr d0, [%0], #8 \n" // R + "subs %w4, %w4, #4 \n" + "ushll v2.4s, v2.4h, #0 \n" // B + "ushll v1.4s, v1.4h, #0 \n" // G + "ushll v0.4s, v0.4h, #0 \n" // R + "ushl v2.4s, v2.4s, v31.4s \n" // 000B + "ushl v1.4s, v1.4s, v31.4s \n" // G + "ushl v0.4s, v0.4s, v31.4s \n" // R + "umin v2.4s, v2.4s, v30.4s \n" + "umin v1.4s, v1.4s, v30.4s \n" + "umin v0.4s, v0.4s, v30.4s \n" + "sli v2.4s, v1.4s, #10 \n" // 00GB + "sli v2.4s, v0.4s, #20 \n" // 0RGB + "orr v2.4s, #0xc0, lsl #24 \n" // ARGB (AR30) + "str q2, [%3], #16 \n" + "b.gt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_ar30), // %3 + "+r"(width) // %4 + : "r"(shift) // %5 + : "memory", "cc", "v0", "v1", "v2", "v30", "v31"); +} + +void MergeXR30Row_10_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int /* depth */, + int width) { + // Neon has no "shift left and accumulate/orr", so use a multiply-add to + // perform the shift instead. + int limit = 1023; + asm volatile( + "dup v5.8h, %w[limit] \n" + "movi v6.8h, #16 \n" // 1 << 4 + "movi v7.8h, #4, lsl #8 \n" // 1 << 10 + "1: \n" + "ldr q0, [%0], #16 \n" // xxxxxxRrrrrrrrrr + "ldr q1, [%1], #16 \n" // xxxxxxGggggggggg + "ldr q2, [%2], #16 \n" // xxxxxxBbbbbbbbbb + "subs %w4, %w4, #8 \n" + "umin v0.8h, v0.8h, v5.8h \n" // 000000Rrrrrrrrrr + "umin v1.8h, v1.8h, v5.8h \n" // 000000Gggggggggg + "movi v4.8h, #0xc0, lsl #8 \n" // 1100000000000000 + "umin v3.8h, v2.8h, v5.8h \n" // 000000Bbbbbbbbbb + "mla v4.8h, v0.8h, v6.8h \n" // 11Rrrrrrrrrr0000 + "mla v3.8h, v1.8h, v7.8h \n" // ggggggBbbbbbbbbb + "usra v4.8h, v1.8h, #6 \n" // 11RrrrrrrrrrGggg + "st2 {v3.8h, v4.8h}, [%3], #32 \n" + "b.gt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_ar30), // %3 + "+r"(width) // %4 + : [limit] "r"(limit) + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); +} + +void MergeAR64Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint16_t* dst_ar64, + int depth, + int width) { + int shift = 16 - depth; + int mask = (1 << depth) - 1; + asm volatile( + + "dup v30.8h, %w7 \n" + "dup v31.8h, %w6 \n" + "1: \n" + "ldr q2, [%0], #16 \n" // R + "ldr q1, [%1], #16 \n" // G + "ldr q0, [%2], #16 \n" // B + "ldr q3, [%3], #16 \n" // A + "subs %w5, %w5, #8 \n" + "umin v2.8h, v2.8h, v30.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "umin v1.8h, v1.8h, v30.8h \n" + "prfm pldl1keep, [%1, 448] \n" + "umin v0.8h, v0.8h, v30.8h \n" + "prfm pldl1keep, [%2, 448] \n" + "umin v3.8h, v3.8h, v30.8h \n" + "prfm pldl1keep, [%3, 448] \n" + "ushl v2.8h, v2.8h, v31.8h \n" + "ushl v1.8h, v1.8h, v31.8h \n" + "ushl v0.8h, v0.8h, v31.8h \n" + "ushl v3.8h, v3.8h, v31.8h \n" + "st4 {v0.8h, v1.8h, v2.8h, v3.8h}, [%4], #64 \n" + "b.gt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(src_a), // %3 + "+r"(dst_ar64), // %4 + "+r"(width) // %5 + : "r"(shift), // %6 + "r"(mask) // %7 + : "memory", "cc", "v0", "v1", "v2", "v3", "v30", "v31"); +} + +void MergeXR64Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint16_t* dst_ar64, + int depth, + int width) { + int shift = 16 - depth; + int mask = (1 << depth) - 1; + asm volatile( + + "movi v3.16b, #0xff \n" // A (0xffff) + "dup v30.8h, %w6 \n" + "dup v31.8h, %w5 \n" + + "1: \n" + "ldr q2, [%0], #16 \n" // R + "ldr q1, [%1], #16 \n" // G + "ldr q0, [%2], #16 \n" // B + "subs %w4, %w4, #8 \n" + "umin v2.8h, v2.8h, v30.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "umin v1.8h, v1.8h, v30.8h \n" + "prfm pldl1keep, [%1, 448] \n" + "umin v0.8h, v0.8h, v30.8h \n" + "prfm pldl1keep, [%2, 448] \n" + "ushl v2.8h, v2.8h, v31.8h \n" + "ushl v1.8h, v1.8h, v31.8h \n" + "ushl v0.8h, v0.8h, v31.8h \n" + "st4 {v0.8h, v1.8h, v2.8h, v3.8h}, [%3], #64 \n" + "b.gt 1b \n" + : "+r"(src_r), // %0 + "+r"(src_g), // %1 + "+r"(src_b), // %2 + "+r"(dst_ar64), // %3 + "+r"(width) // %4 + : "r"(shift), // %5 + "r"(mask) // %6 + : "memory", "cc", "v0", "v1", "v2", "v3", "v30", "v31"); +} + +void MergeARGB16To8Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint8_t* dst_argb, + int depth, + int width) { + // Shift is 8 - depth, +8 so the result is in the top half of each lane. + int shift = 16 - depth; + asm volatile( + "dup v31.8h, %w6 \n" + "1: \n" + "ldr q0, [%0], #16 \n" // B + "ldr q1, [%1], #16 \n" // G + "ldr q2, [%2], #16 \n" // R + "ldr q3, [%3], #16 \n" // A + "subs %w5, %w5, #8 \n" + "uqshl v0.8h, v0.8h, v31.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "uqshl v1.8h, v1.8h, v31.8h \n" + "prfm pldl1keep, [%1, 448] \n" + "uqshl v2.8h, v2.8h, v31.8h \n" + "prfm pldl1keep, [%2, 448] \n" + "uqshl v3.8h, v3.8h, v31.8h \n" + "prfm pldl1keep, [%3, 448] \n" + "trn2 v0.16b, v0.16b, v1.16b \n" + "trn2 v1.16b, v2.16b, v3.16b \n" + "st2 {v0.8h, v1.8h}, [%4], #32 \n" + "b.gt 1b \n" + : "+r"(src_b), // %0 + "+r"(src_g), // %1 + "+r"(src_r), // %2 + "+r"(src_a), // %3 + "+r"(dst_argb), // %4 + "+r"(width) // %5 + : "r"(shift) // %6 + : "memory", "cc", "v0", "v1", "v2", "v3", "v31"); +} + +void MergeXRGB16To8Row_NEON(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_argb, + int depth, + int width) { + // Shift is 8 - depth, +8 so the result is in the top half of each lane. + int shift = 16 - depth; + asm volatile( + "dup v31.8h, %w5 \n" + "movi v3.16b, #0xff \n" // A (0xff) + "1: \n" + "ldr q0, [%0], #16 \n" // B + "ldr q1, [%1], #16 \n" // G + "ldr q2, [%2], #16 \n" // R + "subs %w4, %w4, #8 \n" + "uqshl v0.8h, v0.8h, v31.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "uqshl v1.8h, v1.8h, v31.8h \n" + "prfm pldl1keep, [%1, 448] \n" + "uqshl v2.8h, v2.8h, v31.8h \n" + "prfm pldl1keep, [%2, 448] \n" + "trn2 v0.16b, v0.16b, v1.16b \n" + "trn2 v1.16b, v2.16b, v3.16b \n" + "st2 {v0.8h, v1.8h}, [%3], #32 \n" + "b.gt 1b \n" + : "+r"(src_b), // %0 + "+r"(src_g), // %1 + "+r"(src_r), // %2 + "+r"(dst_argb), // %3 + "+r"(width) // %4 + : "r"(shift) // %5 + : "memory", "cc", "v0", "v1", "v2", "v3", "v31"); +} + // Copy multiple of 32. void CopyRow_NEON(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "1: \n" - "ldp q0, q1, [%0], #32 \n" - "subs %w2, %w2, #32 \n" // 32 processed per loop - "stp q0, q1, [%1], #32 \n" - "b.gt 1b \n" + "1: \n" + "ldp q0, q1, [%0], #32 \n" + "prfm pldl1keep, [%0, 448] \n" + "subs %w2, %w2, #32 \n" // 32 processed per loop + "stp q0, q1, [%1], #32 \n" + "b.gt 1b \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 // Output registers @@ -699,11 +1854,11 @@ void CopyRow_NEON(const uint8_t* src, uint8_t* dst, int width) { // SetRow writes 'width' bytes using an 8 bit value repeated. void SetRow_NEON(uint8_t* dst, uint8_t v8, int width) { asm volatile( - "dup v0.16b, %w2 \n" // duplicate 16 bytes - "1: \n" - "subs %w1, %w1, #16 \n" // 16 bytes per loop - "st1 {v0.16b}, [%0], #16 \n" // store - "b.gt 1b \n" + "dup v0.16b, %w2 \n" // duplicate 16 bytes + "1: \n" + "subs %w1, %w1, #16 \n" // 16 bytes per loop + "st1 {v0.16b}, [%0], #16 \n" // store + "b.gt 1b \n" : "+r"(dst), // %0 "+r"(width) // %1 : "r"(v8) // %2 @@ -712,89 +1867,157 @@ void SetRow_NEON(uint8_t* dst, uint8_t v8, int width) { void ARGBSetRow_NEON(uint8_t* dst, uint32_t v32, int width) { asm volatile( - "dup v0.4s, %w2 \n" // duplicate 4 ints - "1: \n" - "subs %w1, %w1, #4 \n" // 4 ints per loop - "st1 {v0.16b}, [%0], #16 \n" // store - "b.gt 1b \n" + "dup v0.4s, %w2 \n" // duplicate 4 ints + "1: \n" + "subs %w1, %w1, #4 \n" // 4 ints per loop + "st1 {v0.16b}, [%0], #16 \n" // store + "b.gt 1b \n" : "+r"(dst), // %0 "+r"(width) // %1 : "r"(v32) // %2 : "cc", "memory", "v0"); } +// Shuffle table for reversing the bytes. +static const uvec8 kShuffleMirror = {15u, 14u, 13u, 12u, 11u, 10u, 9u, 8u, + 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u}; + void MirrorRow_NEON(const uint8_t* src, uint8_t* dst, int width) { asm volatile( // Start at end of source row. - "add %0, %0, %w2, sxtw \n" - "sub %0, %0, #16 \n" - "1: \n" - "ld1 {v0.16b}, [%0], %3 \n" // src -= 16 - "subs %w2, %w2, #16 \n" // 16 pixels per loop. - "rev64 v0.16b, v0.16b \n" - "st1 {v0.D}[1], [%1], #8 \n" // dst += 16 - "st1 {v0.D}[0], [%1], #8 \n" - "b.gt 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "r"((ptrdiff_t)-16) // %3 - : "cc", "memory", "v0"); + "ld1 {v3.16b}, [%3] \n" // shuffler + "add %0, %0, %w2, sxtw \n" + "sub %0, %0, #32 \n" + "1: \n" + "ldr q2, [%0, 16] \n" + "ldr q1, [%0], -32 \n" // src -= 32 + "subs %w2, %w2, #32 \n" // 32 pixels per loop. + "tbl v0.16b, {v2.16b}, v3.16b \n" + "tbl v1.16b, {v1.16b}, v3.16b \n" + "st1 {v0.16b, v1.16b}, [%1], #32 \n" // store 32 pixels + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "r"(&kShuffleMirror) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3"); } -void MirrorUVRow_NEON(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { +// Shuffle table for reversing the UV. +static const uvec8 kShuffleMirrorUV = {14u, 15u, 12u, 13u, 10u, 11u, 8u, 9u, + 6u, 7u, 4u, 5u, 2u, 3u, 0u, 1u}; + +void MirrorUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_uv, int width) { asm volatile( // Start at end of source row. - "add %0, %0, %w3, sxtw #1 \n" - "sub %0, %0, #16 \n" - "1: \n" - "ld2 {v0.8b, v1.8b}, [%0], %4 \n" // src -= 16 - "subs %w3, %w3, #8 \n" // 8 pixels per loop. - "rev64 v0.8b, v0.8b \n" - "rev64 v1.8b, v1.8b \n" - "st1 {v0.8b}, [%1], #8 \n" // dst += 8 - "st1 {v1.8b}, [%2], #8 \n" - "b.gt 1b \n" - : "+r"(src_uv), // %0 - "+r"(dst_u), // %1 - "+r"(dst_v), // %2 - "+r"(width) // %3 - : "r"((ptrdiff_t)-16) // %4 - : "cc", "memory", "v0", "v1"); + "ld1 {v4.16b}, [%3] \n" // shuffler + "add %0, %0, %w2, sxtw #1 \n" + "sub %0, %0, #32 \n" + "1: \n" + "ldr q1, [%0, 16] \n" + "ldr q0, [%0], -32 \n" // src -= 32 + "subs %w2, %w2, #16 \n" // 16 pixels per loop. + "tbl v2.16b, {v1.16b}, v4.16b \n" + "tbl v3.16b, {v0.16b}, v4.16b \n" + "st1 {v2.16b, v3.16b}, [%1], #32 \n" // dst += 32 + "b.gt 1b \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(width) // %2 + : "r"(&kShuffleMirrorUV) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4"); } -void ARGBMirrorRow_NEON(const uint8_t* src, uint8_t* dst, int width) { +void MirrorSplitUVRow_NEON(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { asm volatile( // Start at end of source row. - "add %0, %0, %w2, sxtw #2 \n" - "sub %0, %0, #16 \n" - "1: \n" - "ld1 {v0.16b}, [%0], %3 \n" // src -= 16 - "subs %w2, %w2, #4 \n" // 4 pixels per loop. - "rev64 v0.4s, v0.4s \n" - "st1 {v0.D}[1], [%1], #8 \n" // dst += 16 - "st1 {v0.D}[0], [%1], #8 \n" - "b.gt 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "r"((ptrdiff_t)-16) // %3 - : "cc", "memory", "v0"); + "ld1 {v4.16b}, [%4] \n" // shuffler + "add %0, %0, %w3, sxtw #1 \n" + "sub %0, %0, #32 \n" + "1: \n" + "ldr q1, [%0, 16] \n" + "ldr q0, [%0], -32 \n" // src -= 32 + "subs %w3, %w3, #16 \n" // 16 pixels per loop. + "tbl v2.16b, {v1.16b}, v4.16b \n" + "tbl v3.16b, {v0.16b}, v4.16b \n" + "uzp1 v0.16b, v2.16b, v3.16b \n" // U + "uzp2 v1.16b, v2.16b, v3.16b \n" // V + "st1 {v0.16b}, [%1], #16 \n" // dst += 16 + "st1 {v1.16b}, [%2], #16 \n" + "b.gt 1b \n" + : "+r"(src_uv), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"(&kShuffleMirrorUV) // %4 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4"); +} + +// Shuffle table for reversing the ARGB. +static const uvec8 kShuffleMirrorARGB = {12u, 13u, 14u, 15u, 8u, 9u, 10u, 11u, + 4u, 5u, 6u, 7u, 0u, 1u, 2u, 3u}; + +void ARGBMirrorRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width) { + asm volatile( + // Start at end of source row. + "ld1 {v4.16b}, [%3] \n" // shuffler + "add %0, %0, %w2, sxtw #2 \n" + "sub %0, %0, #32 \n" + "1: \n" + "ldr q1, [%0, 16] \n" + "ldr q0, [%0], -32 \n" // src -= 32 + "subs %w2, %w2, #8 \n" // 8 pixels per loop. + "tbl v2.16b, {v1.16b}, v4.16b \n" + "tbl v3.16b, {v0.16b}, v4.16b \n" + "st1 {v2.16b, v3.16b}, [%1], #32 \n" // dst += 32 + "b.gt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(&kShuffleMirrorARGB) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4"); +} + +void RGB24MirrorRow_NEON(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width) { + asm volatile( + "ld1 {v3.16b}, [%4] \n" // shuffler + "add %0, %0, %w2, sxtw #1 \n" // Start at end of row. + "add %0, %0, %w2, sxtw \n" + "sub %0, %0, #48 \n" + + "1: \n" + "ld3 {v0.16b, v1.16b, v2.16b}, [%0], %3 \n" // src -= 48 + "subs %w2, %w2, #16 \n" // 16 pixels per loop. + "tbl v0.16b, {v0.16b}, v3.16b \n" + "tbl v1.16b, {v1.16b}, v3.16b \n" + "tbl v2.16b, {v2.16b}, v3.16b \n" + "st3 {v0.16b, v1.16b, v2.16b}, [%1], #48 \n" // dst += 48 + "b.gt 1b \n" + : "+r"(src_rgb24), // %0 + "+r"(dst_rgb24), // %1 + "+r"(width) // %2 + : "r"((ptrdiff_t)-48), // %3 + "r"(&kShuffleMirror) // %4 + : "cc", "memory", "v0", "v1", "v2", "v3"); } void RGB24ToARGBRow_NEON(const uint8_t* src_rgb24, uint8_t* dst_argb, int width) { asm volatile( - "movi v4.8b, #255 \n" // Alpha - "1: \n" - "ld3 {v1.8b,v2.8b,v3.8b}, [%0], #24 \n" // load 8 pixels of RGB24. - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "st4 {v1.8b,v2.8b,v3.8b,v4.8b}, [%1], #32 \n" // store 8 ARGB - "b.gt 1b \n" + "movi v4.8b, #255 \n" // Alpha + "1: \n" + "ld3 {v1.8b,v2.8b,v3.8b}, [%0], #24 \n" // load 8 pixels of + // RGB24. + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "prfm pldl1keep, [%0, 448] \n" + "st4 {v1.8b,v2.8b,v3.8b,v4.8b}, [%1], #32 \n" // store 8 ARGB + "b.gt 1b \n" : "+r"(src_rgb24), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -805,14 +2028,15 @@ void RGB24ToARGBRow_NEON(const uint8_t* src_rgb24, void RAWToARGBRow_NEON(const uint8_t* src_raw, uint8_t* dst_argb, int width) { asm volatile( - "movi v5.8b, #255 \n" // Alpha - "1: \n" - "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // read r g b - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "orr v3.8b, v1.8b, v1.8b \n" // move g - "orr v4.8b, v0.8b, v0.8b \n" // move r - "st4 {v2.8b,v3.8b,v4.8b,v5.8b}, [%1], #32 \n" // store b g r a - "b.gt 1b \n" + "movi v5.8b, #255 \n" // Alpha + "1: \n" + "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // read r g b + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "mov v3.8b, v1.8b \n" // move g + "prfm pldl1keep, [%0, 448] \n" + "mov v4.8b, v0.8b \n" // move r + "st4 {v2.8b,v3.8b,v4.8b,v5.8b}, [%1], #32 \n" // store b g r a + "b.gt 1b \n" : "+r"(src_raw), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -821,15 +2045,35 @@ void RAWToARGBRow_NEON(const uint8_t* src_raw, uint8_t* dst_argb, int width) { ); } +void RAWToRGBARow_NEON(const uint8_t* src_raw, uint8_t* dst_rgba, int width) { + asm volatile( + "movi v0.8b, #255 \n" // Alpha + "1: \n" + "ld3 {v3.8b,v4.8b,v5.8b}, [%0], #24 \n" // read r g b + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "mov v2.8b, v4.8b \n" // move g + "prfm pldl1keep, [%0, 448] \n" + "mov v1.8b, v5.8b \n" // move r + "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store a b g r + "b.gt 1b \n" + : "+r"(src_raw), // %0 + "+r"(dst_rgba), // %1 + "+r"(width) // %2 + : + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5" // Clobber List + ); +} + void RAWToRGB24Row_NEON(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { asm volatile( - "1: \n" - "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // read r g b - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "orr v3.8b, v1.8b, v1.8b \n" // move g - "orr v4.8b, v0.8b, v0.8b \n" // move r - "st3 {v2.8b,v3.8b,v4.8b}, [%1], #24 \n" // store b g r - "b.gt 1b \n" + "1: \n" + "ld3 {v0.16b,v1.16b,v2.16b}, [%0], #48 \n" // read 16 r g b + "subs %w2, %w2, #16 \n" // 16 per loop. + "mov v3.16b, v1.16b \n" // move g + "prfm pldl1keep, [%0, 448] \n" + "mov v4.16b, v0.16b \n" // move r + "st3 {v2.16b,v3.16b,v4.16b}, [%1], #48 \n" // store 16 b g r + "b.gt 1b \n" : "+r"(src_raw), // %0 "+r"(dst_rgb24), // %1 "+r"(width) // %2 @@ -838,30 +2082,29 @@ void RAWToRGB24Row_NEON(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { ); } -#define RGB565TOARGB \ - "shrn v6.8b, v0.8h, #5 \n" /* G xxGGGGGG */ \ - "shl v6.8b, v6.8b, #2 \n" /* G GGGGGG00 upper 6 */ \ - "ushr v4.8b, v6.8b, #6 \n" /* G 000000GG lower 2 */ \ - "orr v1.8b, v4.8b, v6.8b \n" /* G */ \ - "xtn v2.8b, v0.8h \n" /* B xxxBBBBB */ \ - "ushr v0.8h, v0.8h, #11 \n" /* R 000RRRRR */ \ - "xtn2 v2.16b,v0.8h \n" /* R in upper part */ \ - "shl v2.16b, v2.16b, #3 \n" /* R,B BBBBB000 upper 5 */ \ - "ushr v0.16b, v2.16b, #5 \n" /* R,B 00000BBB lower 3 */ \ - "orr v0.16b, v0.16b, v2.16b \n" /* R,B */ \ - "dup v2.2D, v0.D[1] \n" /* R */ +#define RGB565TOARGB \ + /* Input: v0/v4.8h: RRRRRGGGGGGBBBBB */ \ + "shrn v1.8b, v0.8h, #3 \n" /* G GGGGGGxx */ \ + "shrn2 v1.16b, v4.8h, #3 \n" /* G GGGGGGxx */ \ + "uzp2 v2.16b, v0.16b, v4.16b \n" /* R RRRRRxxx */ \ + "uzp1 v0.16b, v0.16b, v4.16b \n" /* B xxxBBBBB */ \ + "sri v1.16b, v1.16b, #6 \n" /* G GGGGGGGG, fill 2 */ \ + "shl v0.16b, v0.16b, #3 \n" /* B BBBBB000 */ \ + "sri v2.16b, v2.16b, #5 \n" /* R RRRRRRRR, fill 3 */ \ + "sri v0.16b, v0.16b, #5 \n" /* R BBBBBBBB, fill 3 */ void RGB565ToARGBRow_NEON(const uint8_t* src_rgb565, uint8_t* dst_argb, int width) { asm volatile( - "movi v3.8b, #255 \n" // Alpha - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load 8 RGB565 pixels. - "subs %w2, %w2, #8 \n" // 8 processed per loop. - RGB565TOARGB - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 ARGB - "b.gt 1b \n" + "movi v3.16b, #255 \n" // Alpha + "1: \n" + "ldp q0, q4, [%0], #32 \n" // load 16 RGB565 pixels + "subs %w2, %w2, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 448] \n" RGB565TOARGB + "st4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%1] \n" // store 16 ARGB + "add %1, %1, #64 \n" + "b.gt 1b \n" : "+r"(src_rgb565), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -870,86 +2113,80 @@ void RGB565ToARGBRow_NEON(const uint8_t* src_rgb565, ); } -#define ARGB1555TOARGB \ - "ushr v2.8h, v0.8h, #10 \n" /* R xxxRRRRR */ \ - "shl v2.8h, v2.8h, #3 \n" /* R RRRRR000 upper 5 */ \ - "xtn v3.8b, v2.8h \n" /* RRRRR000 AAAAAAAA */ \ - \ - "sshr v2.8h, v0.8h, #15 \n" /* A AAAAAAAA */ \ - "xtn2 v3.16b, v2.8h \n" \ - \ - "xtn v2.8b, v0.8h \n" /* B xxxBBBBB */ \ - "shrn2 v2.16b,v0.8h, #5 \n" /* G xxxGGGGG */ \ - \ - "ushr v1.16b, v3.16b, #5 \n" /* R,A 00000RRR lower 3 */ \ - "shl v0.16b, v2.16b, #3 \n" /* B,G BBBBB000 upper 5 */ \ - "ushr v2.16b, v0.16b, #5 \n" /* B,G 00000BBB lower 3 */ \ - \ - "orr v0.16b, v0.16b, v2.16b \n" /* B,G */ \ - "orr v2.16b, v1.16b, v3.16b \n" /* R,A */ \ - "dup v1.2D, v0.D[1] \n" \ - "dup v3.2D, v2.D[1] \n" +#define ARGB1555TOARGB \ + /* Input: ARRRRRGGGGGBBBBB */ \ + "shrn v2.8b, v0.8h, #7 \n" /* RRRRRxxx */ \ + "uzp1 v29.16b, v0.16b, v4.16b \n" /* xxxBBBBB */ \ + "shrn v1.8b, v0.8h, #2 \n" /* GGGGGxxx */ \ + "uzp2 v3.16b, v0.16b, v4.16b \n" /* Axxxxxxx */ \ + "shrn2 v2.16b, v4.8h, #7 \n" /* RRRRRxxx */ \ + "shl v0.16b, v29.16b, #3 \n" /* BBBBB000 */ \ + "shrn2 v1.16b, v4.8h, #2 \n" /* GGGGGxxx */ \ + "sshr v3.16b, v3.16b, #7 \n" /* AAAAAAAA */ \ + "sri v2.16b, v2.16b, #5 \n" /* RRRRRRRR */ \ + "sri v1.16b, v1.16b, #5 \n" /* GGGGGGGG */ \ + "sri v0.16b, v0.16b, #5 \n" /* BBBBBBBB */ // RGB555TOARGB is same as ARGB1555TOARGB but ignores alpha. -#define RGB555TOARGB \ - "ushr v2.8h, v0.8h, #10 \n" /* R xxxRRRRR */ \ - "shl v2.8h, v2.8h, #3 \n" /* R RRRRR000 upper 5 */ \ - "xtn v3.8b, v2.8h \n" /* RRRRR000 */ \ - \ - "xtn v2.8b, v0.8h \n" /* B xxxBBBBB */ \ - "shrn2 v2.16b,v0.8h, #5 \n" /* G xxxGGGGG */ \ - \ - "ushr v1.16b, v3.16b, #5 \n" /* R 00000RRR lower 3 */ \ - "shl v0.16b, v2.16b, #3 \n" /* B,G BBBBB000 upper 5 */ \ - "ushr v2.16b, v0.16b, #5 \n" /* B,G 00000BBB lower 3 */ \ - \ - "orr v0.16b, v0.16b, v2.16b \n" /* B,G */ \ - "orr v2.16b, v1.16b, v3.16b \n" /* R */ \ - "dup v1.2D, v0.D[1] \n" /* G */ +#define RGB555TOARGB \ + /* Input: xRRRRRGGGGGBBBBB */ \ + "uzp1 v29.16b, v0.16b, v3.16b \n" /* xxxBBBBB */ \ + "shrn v2.8b, v0.8h, #7 \n" /* RRRRRxxx */ \ + "shrn v1.8b, v0.8h, #2 \n" /* GGGGGxxx */ \ + "shl v0.16b, v29.16b, #3 \n" /* BBBBB000 */ \ + "shrn2 v2.16b, v3.8h, #7 \n" /* RRRRRxxx */ \ + "shrn2 v1.16b, v3.8h, #2 \n" /* GGGGGxxx */ \ + \ + "sri v0.16b, v0.16b, #5 \n" /* BBBBBBBB */ \ + "sri v2.16b, v2.16b, #5 \n" /* RRRRRRRR */ \ + "sri v1.16b, v1.16b, #5 \n" /* GGGGGGGG */ void ARGB1555ToARGBRow_NEON(const uint8_t* src_argb1555, uint8_t* dst_argb, int width) { asm volatile( - "movi v3.8b, #255 \n" // Alpha - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB1555 pixels. - "subs %w2, %w2, #8 \n" // 8 processed per loop. + "1: \n" + "ldp q0, q4, [%0], #32 \n" // load 16 ARGB1555 pixels + "prfm pldl1keep, [%0, 448] \n" + "subs %w2, %w2, #16 \n" // 16 processed per loop ARGB1555TOARGB - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 ARGB - // pixels - "b.gt 1b \n" + "st4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%1] \n" // store 16 ARGB + "add %1, %1, #64 \n" + "b.gt 1b \n" : "+r"(src_argb1555), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 : - : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v29" // Clobber List ); } -#define ARGB4444TOARGB \ - "shrn v1.8b, v0.8h, #8 \n" /* v1(l) AR */ \ - "xtn2 v1.16b, v0.8h \n" /* v1(h) GB */ \ - "shl v2.16b, v1.16b, #4 \n" /* B,R BBBB0000 */ \ - "ushr v3.16b, v1.16b, #4 \n" /* G,A 0000GGGG */ \ - "ushr v0.16b, v2.16b, #4 \n" /* B,R 0000BBBB */ \ - "shl v1.16b, v3.16b, #4 \n" /* G,A GGGG0000 */ \ - "orr v2.16b, v0.16b, v2.16b \n" /* B,R BBBBBBBB */ \ - "orr v3.16b, v1.16b, v3.16b \n" /* G,A GGGGGGGG */ \ - "dup v0.2D, v2.D[1] \n" \ - "dup v1.2D, v3.D[1] \n" +#define ARGB4444TOARGB \ + /* Input: v1.8h = AAAARRRR_GGGGBBBB */ \ + "shl v0.16b, v1.16b, #4 \n" /* RRRR0000_BBBB0000 */ \ + "sri v1.16b, v1.16b, #4 \n" /* AAAAAAAA_GGGGGGGG */ \ + "sri v0.16b, v0.16b, #4 \n" /* RRRRRRRR_BBBBBBBB */ + +#define ARGB4444TORGB \ + /* Input: v0.8h = xxxxRRRRGGGGBBBB */ \ + "uzp1 v1.16b, v0.16b, v3.16b \n" /* GGGGBBBB */ \ + "shrn v2.8b, v0.8h, #4 \n" /* RRRRxxxx */ \ + "shl v0.16b, v1.16b, #4 \n" /* BBBB0000 */ \ + "shrn2 v2.16b, v3.8h, #4 \n" /* RRRRxxxx */ \ + "sri v1.16b, v1.16b, #4 \n" /* GGGGGGGG */ \ + "sri v2.16b, v2.16b, #4 \n" /* RRRRRRRR */ \ + "sri v0.16b, v0.16b, #4 \n" /* BBBBBBBB */ void ARGB4444ToARGBRow_NEON(const uint8_t* src_argb4444, uint8_t* dst_argb, int width) { asm volatile( - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB4444 pixels. - "subs %w2, %w2, #8 \n" // 8 processed per loop. - ARGB4444TOARGB - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 ARGB - // pixels - "b.gt 1b \n" + "1: \n" + "ld1 {v1.16b}, [%0], #16 \n" // load 8 ARGB4444 pixels. + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "prfm pldl1keep, [%0, 448] \n" ARGB4444TOARGB + "st2 {v0.16b, v1.16b}, [%1], #32 \n" // store 8 ARGB. + "b.gt 1b \n" : "+r"(src_argb4444), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -958,33 +2195,87 @@ void ARGB4444ToARGBRow_NEON(const uint8_t* src_argb4444, ); } +static const int16_t kAR30Row_BoxShifts[] = {0, -6, 0, -6, 0, -6, 0, -6}; + +static const uint8_t kABGRToAR30Row_BoxIndices[] = { + 2, 2, 1, 1, 6, 6, 5, 5, 10, 10, 9, 9, 14, 14, 13, 13, + 0, 0, 3, 3, 4, 4, 7, 7, 8, 8, 11, 11, 12, 12, 15, 15}; +static const uint8_t kARGBToAR30Row_BoxIndices[] = { + 0, 0, 1, 1, 4, 4, 5, 5, 8, 8, 9, 9, 12, 12, 13, 13, + 2, 2, 3, 3, 6, 6, 7, 7, 10, 10, 11, 11, 14, 14, 15, 15}; + +// ARGB or ABGR as input, reordering based on TBL indices parameter. +static void ABCDToAR30Row_NEON(const uint8_t* src_abcd, + uint8_t* dst_ar30, + int width, + const uint8_t* indices) { + asm volatile( + "movi v2.4s, #0xf, msl 16 \n" // 0xfffff + "ldr q3, [%[kAR30Row_BoxShifts]] \n" + "ldp q4, q5, [%[indices]] \n" + "1: \n" + "ldp q0, q20, [%[src]], #32 \n" + "subs %w[width], %w[width], #8 \n" + "tbl v1.16b, {v0.16b}, v5.16b \n" + "tbl v21.16b, {v20.16b}, v5.16b \n" + "tbl v0.16b, {v0.16b}, v4.16b \n" + "tbl v20.16b, {v20.16b}, v4.16b \n" + "ushl v0.8h, v0.8h, v3.8h \n" + "ushl v20.8h, v20.8h, v3.8h \n" + "ushl v1.8h, v1.8h, v3.8h \n" + "ushl v21.8h, v21.8h, v3.8h \n" + "ushr v0.4s, v0.4s, #6 \n" + "ushr v20.4s, v20.4s, #6 \n" + "shl v1.4s, v1.4s, #14 \n" + "shl v21.4s, v21.4s, #14 \n" + "bif v0.16b, v1.16b, v2.16b \n" + "bif v20.16b, v21.16b, v2.16b \n" + "stp q0, q20, [%[dst]], #32 \n" + "b.gt 1b \n" + : [src] "+r"(src_abcd), // %[src] + [dst] "+r"(dst_ar30), // %[dst] + [width] "+r"(width) // %[width] + : [kAR30Row_BoxShifts] "r"(kAR30Row_BoxShifts), // %[kAR30Row_BoxShifts] + [indices] "r"(indices) // %[indices] + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v20", "v21"); +} + +void ABGRToAR30Row_NEON(const uint8_t* src_abgr, uint8_t* dst_ar30, int width) { + ABCDToAR30Row_NEON(src_abgr, dst_ar30, width, kABGRToAR30Row_BoxIndices); +} + +void ARGBToAR30Row_NEON(const uint8_t* src_argb, uint8_t* dst_ar30, int width) { + ABCDToAR30Row_NEON(src_argb, dst_ar30, width, kARGBToAR30Row_BoxIndices); +} + void ARGBToRGB24Row_NEON(const uint8_t* src_argb, uint8_t* dst_rgb24, int width) { asm volatile( - "1: \n" - "ld4 {v1.8b,v2.8b,v3.8b,v4.8b}, [%0], #32 \n" // load 8 ARGB - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "st3 {v1.8b,v2.8b,v3.8b}, [%1], #24 \n" // store 8 pixels of - // RGB24. - "b.gt 1b \n" + "1: \n" + "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 ARGB + "subs %w2, %w2, #16 \n" // 16 pixels per loop. + "prfm pldl1keep, [%0, 448] \n" + "st3 {v0.16b,v1.16b,v2.16b}, [%1], #48 \n" // store 8 RGB24 + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_rgb24), // %1 "+r"(width) // %2 : - : "cc", "memory", "v1", "v2", "v3", "v4" // Clobber List + : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List ); } void ARGBToRAWRow_NEON(const uint8_t* src_argb, uint8_t* dst_raw, int width) { asm volatile( - "1: \n" - "ld4 {v1.8b,v2.8b,v3.8b,v4.8b}, [%0], #32 \n" // load b g r a - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "orr v4.8b, v2.8b, v2.8b \n" // mov g - "orr v5.8b, v1.8b, v1.8b \n" // mov b - "st3 {v3.8b,v4.8b,v5.8b}, [%1], #24 \n" // store r g b - "b.gt 1b \n" + "1: \n" + "ld4 {v1.8b,v2.8b,v3.8b,v4.8b}, [%0], #32 \n" // load b g r a + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "mov v4.8b, v2.8b \n" // mov g + "prfm pldl1keep, [%0, 448] \n" + "mov v5.8b, v1.8b \n" // mov b + "st3 {v3.8b,v4.8b,v5.8b}, [%1], #24 \n" // store r g b + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_raw), // %1 "+r"(width) // %2 @@ -995,11 +2286,12 @@ void ARGBToRAWRow_NEON(const uint8_t* src_argb, uint8_t* dst_raw, int width) { void YUY2ToYRow_NEON(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { asm volatile( - "1: \n" - "ld2 {v0.16b,v1.16b}, [%0], #32 \n" // load 16 pixels of YUY2. - "subs %w2, %w2, #16 \n" // 16 processed per loop. - "st1 {v0.16b}, [%1], #16 \n" // store 16 pixels of Y. - "b.gt 1b \n" + "1: \n" + "ld2 {v0.16b,v1.16b}, [%0], #32 \n" // load 16 pixels of YUY2. + "subs %w2, %w2, #16 \n" // 16 processed per loop. + "prfm pldl1keep, [%0, 448] \n" + "st1 {v0.16b}, [%1], #16 \n" // store 16 pixels of Y. + "b.gt 1b \n" : "+r"(src_yuy2), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -1010,11 +2302,12 @@ void YUY2ToYRow_NEON(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { void UYVYToYRow_NEON(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { asm volatile( - "1: \n" - "ld2 {v0.16b,v1.16b}, [%0], #32 \n" // load 16 pixels of UYVY. - "subs %w2, %w2, #16 \n" // 16 processed per loop. - "st1 {v1.16b}, [%1], #16 \n" // store 16 pixels of Y. - "b.gt 1b \n" + "1: \n" + "ld2 {v0.16b,v1.16b}, [%0], #32 \n" // load 16 pixels of UYVY. + "subs %w2, %w2, #16 \n" // 16 processed per loop. + "prfm pldl1keep, [%0, 448] \n" + "st1 {v1.16b}, [%1], #16 \n" // store 16 pixels of Y. + "b.gt 1b \n" : "+r"(src_uyvy), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -1028,12 +2321,13 @@ void YUY2ToUV422Row_NEON(const uint8_t* src_yuy2, uint8_t* dst_v, int width) { asm volatile( - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 YUY2 - "subs %w3, %w3, #16 \n" // 16 pixels = 8 UVs. - "st1 {v1.8b}, [%1], #8 \n" // store 8 U. - "st1 {v3.8b}, [%2], #8 \n" // store 8 V. - "b.gt 1b \n" + "1: \n" + "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 YUY2 + "subs %w3, %w3, #16 \n" // 16 pixels = 8 UVs. + "prfm pldl1keep, [%0, 448] \n" + "st1 {v1.8b}, [%1], #8 \n" // store 8 U. + "st1 {v3.8b}, [%2], #8 \n" // store 8 V. + "b.gt 1b \n" : "+r"(src_yuy2), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -1048,12 +2342,13 @@ void UYVYToUV422Row_NEON(const uint8_t* src_uyvy, uint8_t* dst_v, int width) { asm volatile( - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 UYVY - "subs %w3, %w3, #16 \n" // 16 pixels = 8 UVs. - "st1 {v0.8b}, [%1], #8 \n" // store 8 U. - "st1 {v2.8b}, [%2], #8 \n" // store 8 V. - "b.gt 1b \n" + "1: \n" + "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 UYVY + "subs %w3, %w3, #16 \n" // 16 pixels = 8 UVs. + "prfm pldl1keep, [%0, 448] \n" + "st1 {v0.8b}, [%1], #8 \n" // store 8 U. + "st1 {v2.8b}, [%2], #8 \n" // store 8 V. + "b.gt 1b \n" : "+r"(src_uyvy), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 @@ -1070,15 +2365,16 @@ void YUY2ToUVRow_NEON(const uint8_t* src_yuy2, int width) { const uint8_t* src_yuy2b = src_yuy2 + stride_yuy2; asm volatile( - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 pixels - "subs %w4, %w4, #16 \n" // 16 pixels = 8 UVs. - "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load next row - "urhadd v1.8b, v1.8b, v5.8b \n" // average rows of U - "urhadd v3.8b, v3.8b, v7.8b \n" // average rows of V - "st1 {v1.8b}, [%2], #8 \n" // store 8 U. - "st1 {v3.8b}, [%3], #8 \n" // store 8 V. - "b.gt 1b \n" + "1: \n" + "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 pixels + "subs %w4, %w4, #16 \n" // 16 pixels = 8 UVs. + "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load next row + "urhadd v1.8b, v1.8b, v5.8b \n" // average rows of U + "prfm pldl1keep, [%0, 448] \n" + "urhadd v3.8b, v3.8b, v7.8b \n" // average rows of V + "st1 {v1.8b}, [%2], #8 \n" // store 8 U. + "st1 {v3.8b}, [%3], #8 \n" // store 8 V. + "b.gt 1b \n" : "+r"(src_yuy2), // %0 "+r"(src_yuy2b), // %1 "+r"(dst_u), // %2 @@ -1097,15 +2393,16 @@ void UYVYToUVRow_NEON(const uint8_t* src_uyvy, int width) { const uint8_t* src_uyvyb = src_uyvy + stride_uyvy; asm volatile( - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 pixels - "subs %w4, %w4, #16 \n" // 16 pixels = 8 UVs. - "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load next row - "urhadd v0.8b, v0.8b, v4.8b \n" // average rows of U - "urhadd v2.8b, v2.8b, v6.8b \n" // average rows of V - "st1 {v0.8b}, [%2], #8 \n" // store 8 U. - "st1 {v2.8b}, [%3], #8 \n" // store 8 V. - "b.gt 1b \n" + "1: \n" + "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 pixels + "subs %w4, %w4, #16 \n" // 16 pixels = 8 UVs. + "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load next row + "urhadd v0.8b, v0.8b, v4.8b \n" // average rows of U + "prfm pldl1keep, [%0, 448] \n" + "urhadd v2.8b, v2.8b, v6.8b \n" // average rows of V + "st1 {v0.8b}, [%2], #8 \n" // store 8 U. + "st1 {v2.8b}, [%3], #8 \n" // store 8 V. + "b.gt 1b \n" : "+r"(src_uyvy), // %0 "+r"(src_uyvyb), // %1 "+r"(dst_u), // %2 @@ -1117,19 +2414,43 @@ void UYVYToUVRow_NEON(const uint8_t* src_uyvy, ); } +void YUY2ToNVUVRow_NEON(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_uv, + int width) { + const uint8_t* src_yuy2b = src_yuy2 + stride_yuy2; + asm volatile( + "1: \n" + "ld2 {v0.16b,v1.16b}, [%0], #32 \n" // load 16 pixels + "subs %w3, %w3, #16 \n" // 16 pixels = 8 UVs. + "ld2 {v2.16b,v3.16b}, [%1], #32 \n" // load next row + "urhadd v4.16b, v1.16b, v3.16b \n" // average rows of UV + "prfm pldl1keep, [%0, 448] \n" + "st1 {v4.16b}, [%2], #16 \n" // store 8 UV. + "b.gt 1b \n" + : "+r"(src_yuy2), // %0 + "+r"(src_yuy2b), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : + : "cc", "memory", "v0", "v1", "v2", "v3", "v4" // Clobber List + ); +} + // For BGRAToARGB, ABGRToARGB, RGBAToARGB, and ARGBToRGBA. void ARGBShuffleRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, const uint8_t* shuffler, int width) { asm volatile( - "ld1 {v2.16b}, [%3] \n" // shuffler - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load 4 pixels. - "subs %w2, %w2, #4 \n" // 4 processed per loop - "tbl v1.16b, {v0.16b}, v2.16b \n" // look up 4 pixels - "st1 {v1.16b}, [%1], #16 \n" // store 4. - "b.gt 1b \n" + "ld1 {v2.16b}, [%3] \n" // shuffler + "1: \n" + "ld1 {v0.16b}, [%0], #16 \n" // load 4 pixels. + "subs %w2, %w2, #4 \n" // 4 processed per loop + "prfm pldl1keep, [%0, 448] \n" + "tbl v1.16b, {v0.16b}, v2.16b \n" // look up 4 pixels + "st1 {v1.16b}, [%1], #16 \n" // store 4. + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -1144,14 +2465,15 @@ void I422ToYUY2Row_NEON(const uint8_t* src_y, uint8_t* dst_yuy2, int width) { asm volatile( - "1: \n" - "ld2 {v0.8b, v1.8b}, [%0], #16 \n" // load 16 Ys - "orr v2.8b, v1.8b, v1.8b \n" - "ld1 {v1.8b}, [%1], #8 \n" // load 8 Us - "ld1 {v3.8b}, [%2], #8 \n" // load 8 Vs - "subs %w4, %w4, #16 \n" // 16 pixels - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%3], #32 \n" // Store 16 pixels. - "b.gt 1b \n" + "1: \n" + "ld2 {v0.8b, v1.8b}, [%0], #16 \n" // load 16 Ys + "subs %w4, %w4, #16 \n" // 16 pixels + "mov v2.8b, v1.8b \n" + "prfm pldl1keep, [%0, 448] \n" + "ld1 {v1.8b}, [%1], #8 \n" // load 8 Us + "ld1 {v3.8b}, [%2], #8 \n" // load 8 Vs + "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%3], #32 \n" // Store 16 pixels. + "b.gt 1b \n" : "+r"(src_y), // %0 "+r"(src_u), // %1 "+r"(src_v), // %2 @@ -1167,14 +2489,15 @@ void I422ToUYVYRow_NEON(const uint8_t* src_y, uint8_t* dst_uyvy, int width) { asm volatile( - "1: \n" - "ld2 {v1.8b,v2.8b}, [%0], #16 \n" // load 16 Ys - "orr v3.8b, v2.8b, v2.8b \n" - "ld1 {v0.8b}, [%1], #8 \n" // load 8 Us - "ld1 {v2.8b}, [%2], #8 \n" // load 8 Vs - "subs %w4, %w4, #16 \n" // 16 pixels - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%3], #32 \n" // Store 16 pixels. - "b.gt 1b \n" + "1: \n" + "ld2 {v1.8b,v2.8b}, [%0], #16 \n" // load 16 Ys + "subs %w4, %w4, #16 \n" // 16 pixels + "mov v3.8b, v2.8b \n" + "prfm pldl1keep, [%0, 448] \n" + "ld1 {v0.8b}, [%1], #8 \n" // load 8 Us + "ld1 {v2.8b}, [%2], #8 \n" // load 8 Vs + "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%3], #32 \n" // Store 16 pixels. + "b.gt 1b \n" : "+r"(src_y), // %0 "+r"(src_u), // %1 "+r"(src_v), // %2 @@ -1188,111 +2511,235 @@ void ARGBToRGB565Row_NEON(const uint8_t* src_argb, uint8_t* dst_rgb565, int width) { asm volatile( - "1: \n" - "ld4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%0], #32 \n" // load 8 pixels - "subs %w2, %w2, #8 \n" // 8 processed per loop. - ARGBTORGB565 - "st1 {v0.16b}, [%1], #16 \n" // store 8 pixels RGB565. - "b.gt 1b \n" + "1: \n" + "ld4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%0], #32 \n" // load 8 + // pixels + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "prfm pldl1keep, [%0, 448] \n" ARGBTORGB565 + "st1 {v18.16b}, [%1], #16 \n" // store 8 pixels RGB565. + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_rgb565), // %1 "+r"(width) // %2 : - : "cc", "memory", "v0", "v20", "v21", "v22", "v23"); + : "cc", "memory", "v16", "v17", "v18", "v19"); } void ARGBToRGB565DitherRow_NEON(const uint8_t* src_argb, uint8_t* dst_rgb, - const uint32_t dither4, + uint32_t dither4, int width) { asm volatile( - "dup v1.4s, %w2 \n" // dither4 - "1: \n" - "ld4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%1], #32 \n" // load 8 pixels - "subs %w3, %w3, #8 \n" // 8 processed per loop. - "uqadd v20.8b, v20.8b, v1.8b \n" - "uqadd v21.8b, v21.8b, v1.8b \n" - "uqadd v22.8b, v22.8b, v1.8b \n" ARGBTORGB565 - "st1 {v0.16b}, [%0], #16 \n" // store 8 pixels RGB565. - "b.gt 1b \n" - : "+r"(dst_rgb) // %0 - : "r"(src_argb), // %1 - "r"(dither4), // %2 - "r"(width) // %3 - : "cc", "memory", "v0", "v1", "v20", "v21", "v22", "v23"); + "dup v1.4s, %w3 \n" // dither4 + "1: \n" + "ld4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%0], #32 \n" // load 8 ARGB + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "uqadd v16.8b, v16.8b, v1.8b \n" + "prfm pldl1keep, [%0, 448] \n" + "uqadd v17.8b, v17.8b, v1.8b \n" + "uqadd v18.8b, v18.8b, v1.8b \n" ARGBTORGB565 + "st1 {v18.16b}, [%1], #16 \n" // store 8 pixels RGB565. + "b.gt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_rgb), // %1 + "+r"(width) // %2 + : "r"(dither4) // %3 + : "cc", "memory", "v1", "v16", "v17", "v18", "v19"); } void ARGBToARGB1555Row_NEON(const uint8_t* src_argb, uint8_t* dst_argb1555, int width) { asm volatile( - "1: \n" - "ld4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%0], #32 \n" // load 8 pixels - "subs %w2, %w2, #8 \n" // 8 processed per loop. - ARGBTOARGB1555 - "st1 {v0.16b}, [%1], #16 \n" // store 8 pixels - // ARGB1555. - "b.gt 1b \n" + "1: \n" + "ld2 {v16.8h,v17.8h}, [%0], #32 \n" // load 8 pixels + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "prfm pldl1keep, [%0, 448] \n" ARGBTOARGB1555 + "st1 {v17.16b}, [%1], #16 \n" // store 8 pixels + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb1555), // %1 "+r"(width) // %2 : - : "cc", "memory", "v0", "v20", "v21", "v22", "v23"); + : "cc", "memory", "v1", "v2", "v16", "v17"); } void ARGBToARGB4444Row_NEON(const uint8_t* src_argb, uint8_t* dst_argb4444, int width) { asm volatile( - "movi v4.16b, #0x0f \n" // bits to clear with - // vbic. - "1: \n" - "ld4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%0], #32 \n" // load 8 pixels - "subs %w2, %w2, #8 \n" // 8 processed per loop. - ARGBTOARGB4444 - "st1 {v0.16b}, [%1], #16 \n" // store 8 pixels - // ARGB4444. - "b.gt 1b \n" + "1: \n" + "ld2 {v16.16b, v17.16b}, [%0], #32 \n" // load 8 pixels + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "sri v17.16b, v16.16b, #4 \n" + "prfm pldl1keep, [%0, 448] \n" + "st1 {v17.16b}, [%1], #16 \n" // store 8 pixels + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb4444), // %1 "+r"(width) // %2 : - : "cc", "memory", "v0", "v1", "v4", "v20", "v21", "v22", "v23"); + : "cc", "memory", "v16", "v17"); } -void ARGBToYRow_NEON(const uint8_t* src_argb, uint8_t* dst_y, int width) { +#if defined(LIBYUV_USE_ST2) +void ARGBToAR64Row_NEON(const uint8_t* src_argb, + uint16_t* dst_ar64, + int width) { asm volatile( - "movi v4.8b, #13 \n" // B * 0.1016 coefficient - "movi v5.8b, #65 \n" // G * 0.5078 coefficient - "movi v6.8b, #33 \n" // R * 0.2578 coefficient - "movi v7.8b, #16 \n" // Add 16 constant - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "umull v3.8h, v0.8b, v4.8b \n" // B - "umlal v3.8h, v1.8b, v5.8b \n" // G - "umlal v3.8h, v2.8b, v6.8b \n" // R - "sqrshrun v0.8b, v3.8h, #7 \n" // 16 bit to 8 bit Y - "uqadd v0.8b, v0.8b, v7.8b \n" - "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y. - "b.gt 1b \n" + "1: \n" + "ldp q0, q2, [%0], #32 \n" // load 8 pixels + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "mov v1.16b, v0.16b \n" + "prfm pldl1keep, [%0, 448] \n" + "mov v3.16b, v2.16b \n" + "st2 {v0.16b, v1.16b}, [%1], #32 \n" // store 4 pixels + "st2 {v2.16b, v3.16b}, [%1], #32 \n" // store 4 pixels + "b.gt 1b \n" : "+r"(src_argb), // %0 - "+r"(dst_y), // %1 + "+r"(dst_ar64), // %1 "+r"(width) // %2 : + : "cc", "memory", "v0", "v1", "v2", "v3"); +} + +static const uvec8 kShuffleARGBToABGR = {2, 1, 0, 3, 6, 5, 4, 7, + 10, 9, 8, 11, 14, 13, 12, 15}; + +void ARGBToAB64Row_NEON(const uint8_t* src_argb, + uint16_t* dst_ab64, + int width) { + asm volatile( + "ldr q4, [%3] \n" // shuffler + "1: \n" + "ldp q0, q2, [%0], #32 \n" // load 8 pixels + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "tbl v0.16b, {v0.16b}, v4.16b \n" + "tbl v2.16b, {v2.16b}, v4.16b \n" + "prfm pldl1keep, [%0, 448] \n" + "mov v1.16b, v0.16b \n" + "mov v3.16b, v2.16b \n" + "st2 {v0.16b, v1.16b}, [%1], #32 \n" // store 4 pixels + "st2 {v2.16b, v3.16b}, [%1], #32 \n" // store 4 pixels + "b.gt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_ab64), // %1 + "+r"(width) // %2 + : "r"(&kShuffleARGBToABGR) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4"); +} +#else +void ARGBToAR64Row_NEON(const uint8_t* src_argb, + uint16_t* dst_ar64, + int width) { + asm volatile( + "1: \n" + "ldp q0, q1, [%0], #32 \n" // load 8 ARGB pixels + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "zip1 v2.16b, v0.16b, v0.16b \n" + "zip2 v3.16b, v0.16b, v0.16b \n" + "prfm pldl1keep, [%0, 448] \n" + "zip1 v4.16b, v1.16b, v1.16b \n" + "zip2 v5.16b, v1.16b, v1.16b \n" + "st1 {v2.8h, v3.8h, v4.8h, v5.8h}, [%1], #64 \n" // 8 AR64 + "b.gt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_ar64), // %1 + "+r"(width) // %2 + : + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5"); +} + +static const uvec8 kShuffleARGBToAB64[2] = { + {2, 2, 1, 1, 0, 0, 3, 3, 6, 6, 5, 5, 4, 4, 7, 7}, + {10, 10, 9, 9, 8, 8, 11, 11, 14, 14, 13, 13, 12, 12, 15, 15}}; + +void ARGBToAB64Row_NEON(const uint8_t* src_argb, + uint16_t* dst_ab64, + int width) { + asm volatile( + "ldp q6, q7, [%3] \n" // 2 shufflers + "1: \n" + "ldp q0, q1, [%0], #32 \n" // load 8 pixels + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "tbl v2.16b, {v0.16b}, v6.16b \n" // ARGB to AB64 + "tbl v3.16b, {v0.16b}, v7.16b \n" + "prfm pldl1keep, [%0, 448] \n" + "tbl v4.16b, {v1.16b}, v6.16b \n" + "tbl v5.16b, {v1.16b}, v7.16b \n" + "st1 {v2.8h, v3.8h, v4.8h, v5.8h}, [%1], #64 \n" // 8 AR64 + "b.gt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_ab64), // %1 + "+r"(width) // %2 + : "r"(&kShuffleARGBToAB64[0]) // %3 : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); } +#endif // LIBYUV_USE_ST2 + +static const uvec8 kShuffleAR64ToARGB = {1, 3, 5, 7, 9, 11, 13, 15, + 17, 19, 21, 23, 25, 27, 29, 31}; + +void AR64ToARGBRow_NEON(const uint16_t* src_ar64, + uint8_t* dst_argb, + int width) { + asm volatile( + "ldr q4, [%3] \n" // shuffler + "1: \n" + "ldp q0, q1, [%0], #32 \n" // load 4 pixels + "ldp q2, q3, [%0], #32 \n" // load 4 pixels + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "tbl v0.16b, {v0.16b, v1.16b}, v4.16b \n" + "prfm pldl1keep, [%0, 448] \n" + "tbl v2.16b, {v2.16b, v3.16b}, v4.16b \n" + "stp q0, q2, [%1], #32 \n" // store 8 pixels + "b.gt 1b \n" + : "+r"(src_ar64), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(&kShuffleAR64ToARGB) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4"); +} + +static const uvec8 kShuffleAB64ToARGB = {5, 3, 1, 7, 13, 11, 9, 15, + 21, 19, 17, 23, 29, 27, 25, 31}; + +void AB64ToARGBRow_NEON(const uint16_t* src_ab64, + uint8_t* dst_argb, + int width) { + asm volatile( + "ldr q4, [%3] \n" // shuffler + "1: \n" + "ldp q0, q1, [%0], #32 \n" // load 4 pixels + "ldp q2, q3, [%0], #32 \n" // load 4 pixels + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "tbl v0.16b, {v0.16b, v1.16b}, v4.16b \n" + "prfm pldl1keep, [%0, 448] \n" + "tbl v2.16b, {v2.16b, v3.16b}, v4.16b \n" + "stp q0, q2, [%1], #32 \n" // store 8 pixels + "b.gt 1b \n" + : "+r"(src_ab64), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(&kShuffleAB64ToARGB) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4"); +} void ARGBExtractAlphaRow_NEON(const uint8_t* src_argb, uint8_t* dst_a, int width) { asm volatile( - "1: \n" - "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load row 16 - // pixels - "subs %w2, %w2, #16 \n" // 16 processed per loop - "st1 {v3.16b}, [%1], #16 \n" // store 16 A's. - "b.gt 1b \n" + "1: \n" + "ldp q0, q1, [%0] \n" // load 8 ARGB pixels + "ldp q2, q3, [%0, #32] \n" // load next 8 ARGB pixels + "add %0, %0, #64 \n" + "prfm pldl1keep, [%0, 448] \n" + "uzp2 v0.8h, v0.8h, v1.8h \n" + "uzp2 v2.8h, v2.8h, v3.8h \n" + "uzp2 v0.16b, v0.16b, v2.16b \n" + "subs %w2, %w2, #16 \n" // 16 processed per loop + "str q0, [%1], #16 \n" // store 16 A's. + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_a), // %1 "+r"(width) // %2 @@ -1301,76 +2748,208 @@ void ARGBExtractAlphaRow_NEON(const uint8_t* src_argb, ); } -void ARGBToYJRow_NEON(const uint8_t* src_argb, uint8_t* dst_y, int width) { +void ARGBCopyYToAlphaRow_NEON(const uint8_t* src, uint8_t* dst, int width) { asm volatile( - "movi v4.8b, #15 \n" // B * 0.11400 coefficient - "movi v5.8b, #75 \n" // G * 0.58700 coefficient - "movi v6.8b, #38 \n" // R * 0.29900 coefficient - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "umull v3.8h, v0.8b, v4.8b \n" // B - "umlal v3.8h, v1.8b, v5.8b \n" // G - "umlal v3.8h, v2.8b, v6.8b \n" // R - "sqrshrun v0.8b, v3.8h, #7 \n" // 15 bit to 8 bit Y - "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y. - "b.gt 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 + "1: \n" + "ldr q4, [%0], #16 \n" + "ldp q0, q1, [%1] \n" + "ldp q2, q3, [%1, #32] \n" + "prfm pldl1keep, [%0, 448] \n" + "prfm pldl1keep, [%1, 448] \n" + "zip1 v6.16b, v4.16b, v4.16b \n" + "zip2 v7.16b, v4.16b, v4.16b \n" + "zip1 v4.8h, v6.8h, v6.8h \n" + "zip2 v5.8h, v6.8h, v6.8h \n" + "zip1 v6.8h, v7.8h, v7.8h \n" + "zip2 v7.8h, v7.8h, v7.8h \n" + "sli v0.4s, v4.4s, #24 \n" + "sli v1.4s, v5.4s, #24 \n" + "sli v2.4s, v6.4s, #24 \n" + "sli v3.4s, v7.4s, #24 \n" + "stp q0, q1, [%1] \n" + "stp q2, q3, [%1, #32] \n" + "add %1, %1, #64 \n" + "subs %w2, %w2, #16 \n" + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6"); + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); } +// Coefficients expressed as negatives to allow 128 +struct RgbUVConstants { + int8_t kRGBToU[4]; + int8_t kRGBToV[4]; +}; + // 8x1 pixels. -void ARGBToUV444Row_NEON(const uint8_t* src_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { +void ARGBToUV444MatrixRow_NEON(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { asm volatile( - "movi v24.8b, #112 \n" // UB / VR 0.875 - // coefficient - "movi v25.8b, #74 \n" // UG -0.5781 coefficient - "movi v26.8b, #38 \n" // UR -0.2969 coefficient - "movi v27.8b, #18 \n" // VB -0.1406 coefficient - "movi v28.8b, #94 \n" // VG -0.7344 coefficient - "movi v29.16b,#0x80 \n" // 128.5 - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB - // pixels. - "subs %w3, %w3, #8 \n" // 8 processed per loop. - "umull v4.8h, v0.8b, v24.8b \n" // B - "umlsl v4.8h, v1.8b, v25.8b \n" // G - "umlsl v4.8h, v2.8b, v26.8b \n" // R - "add v4.8h, v4.8h, v29.8h \n" // +128 -> unsigned + "ldr q16, [%[c], #16] \n" // kRGBToU + "ldr q17, [%[c], #32] \n" // kRGBToV + "ldr s0, [%[c], #64] \n" // kAddUV + "sxtl v16.8h, v16.8b \n" // sign extend U coeffs + // to 16-bit + "sxtl v17.8h, v17.8b \n" // sign extend V coeffs + // to 16-bit + "dup v20.8h, v16.h[0] \n" // U0 + "dup v21.8h, v16.h[1] \n" // U1 + "dup v22.8h, v16.h[2] \n" // U2 + "dup v23.8h, v16.h[3] \n" // U3 + "dup v24.8h, v17.h[0] \n" // V0 + "dup v26.8h, v17.h[1] \n" // V1 + "dup v27.8h, v17.h[2] \n" // V2 + "dup v28.8h, v17.h[3] \n" // V3 + "dup v25.8h, v0.h[0] \n" // kAddUV + "1: \n" + "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB + "subs %w3, %w3, #8 \n" // 8 processed per loop. - "umull v3.8h, v2.8b, v24.8b \n" // R - "umlsl v3.8h, v1.8b, v28.8b \n" // G - "umlsl v3.8h, v0.8b, v27.8b \n" // B - "add v3.8h, v3.8h, v29.8h \n" // +128 -> unsigned + "uxtl v4.8h, v0.8b \n" + "uxtl v5.8h, v1.8b \n" + "uxtl v6.8h, v2.8b \n" + "uxtl v7.8h, v3.8b \n" - "uqshrn v0.8b, v4.8h, #8 \n" // 16 bit to 8 bit U - "uqshrn v1.8b, v3.8h, #8 \n" // 16 bit to 8 bit V + // U = B*U0 + G*U1 + R*U2 + A*U3 + "mul v18.8h, v4.8h, v20.8h \n" + "mla v18.8h, v5.8h, v21.8h \n" + "mla v18.8h, v6.8h, v22.8h \n" + "mla v18.8h, v7.8h, v23.8h \n" - "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels U. - "st1 {v1.8b}, [%2], #8 \n" // store 8 pixels V. - "b.gt 1b \n" + // V = B*V0 + G*V1 + R*V2 + A*V3 + "mul v19.8h, v4.8h, v24.8h \n" + "mla v19.8h, v5.8h, v26.8h \n" + "mla v19.8h, v6.8h, v27.8h \n" + "mla v19.8h, v7.8h, v28.8h \n" + + "subhn v0.8b, v25.8h, v18.8h \n" + "subhn v1.8b, v25.8h, v19.8h \n" + + "st1 {v0.8b}, [%1], #8 \n" + "st1 {v1.8b}, [%2], #8 \n" + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_u), // %1 "+r"(dst_v), // %2 "+r"(width) // %3 - : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v24", "v25", "v26", - "v27", "v28", "v29"); + : [c] "r"(c) // %4 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", + "v27", "v28"); } +// 8x1 pixels. +void RGBToUV444MatrixRow_NEON(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + asm volatile( + "ldr q16, [%[c], #16] \n" // kRGBToU + "ldr q17, [%[c], #32] \n" // kRGBToV + "ldr s0, [%[c], #64] \n" // kAddUV + "sxtl v16.8h, v16.8b \n" // sign extend U coeffs + // to 16-bit + "sxtl v17.8h, v17.8b \n" // sign extend V coeffs + // to 16-bit + "dup v20.8h, v16.h[0] \n" // U0 + "dup v21.8h, v16.h[1] \n" // U1 + "dup v22.8h, v16.h[2] \n" // U2 + "dup v24.8h, v17.h[0] \n" // V0 + "dup v26.8h, v17.h[1] \n" // V1 + "dup v27.8h, v17.h[2] \n" // V2 + "dup v25.8h, v0.h[0] \n" // kAddUV + "1: \n" + "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // load 8 RGB + "subs %w3, %w3, #8 \n" // 8 processed per loop. + + "uxtl v4.8h, v0.8b \n" // B + "uxtl v5.8h, v1.8b \n" // G + "uxtl v6.8h, v2.8b \n" // R + + // U = B*U0 + G*U1 + R*U2 + "mul v18.8h, v4.8h, v20.8h \n" + "mla v18.8h, v5.8h, v21.8h \n" + "mla v18.8h, v6.8h, v22.8h \n" + + // V = B*V0 + G*V1 + R*V2 + "mul v19.8h, v4.8h, v24.8h \n" + "mla v19.8h, v5.8h, v26.8h \n" + "mla v19.8h, v6.8h, v27.8h \n" + + "subhn v0.8b, v25.8h, v18.8h \n" + "subhn v1.8b, v25.8h, v19.8h \n" + + "st1 {v0.8b}, [%1], #8 \n" + "st1 {v1.8b}, [%2], #8 \n" + "b.gt 1b \n" + : "+r"(src_rgb), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : [c] "r"(c) // %4 + : "cc", "memory", "v0", "v1", "v2", "v4", "v5", "v6", "v16", "v17", "v18", + "v19", "v20", "v21", "v22", "v24", "v25", "v26", "v27"); +} + +void ARGBToUV444MatrixRow_NEON_I8MM(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + asm volatile( + "ldr q16, [%[c], #16] \n" // kRGBToU + "ldr q17, [%[c], #32] \n" // kRGBToV + "ldr s0, [%[c], #64] \n" // kAddUV + "dup v29.8h, v0.h[0] \n" // 128.0 + "1: \n" + "ldp q0, q1, [%[src]], #32 \n" + "subs %w[width], %w[width], #8 \n" // 8 processed per loop. + "movi v2.4s, #0 \n" + "movi v3.4s, #0 \n" + "movi v4.4s, #0 \n" + "movi v5.4s, #0 \n" + "usdot v2.4s, v0.16b, v16.16b \n" + "usdot v3.4s, v1.16b, v16.16b \n" + "usdot v4.4s, v0.16b, v17.16b \n" + "usdot v5.4s, v1.16b, v17.16b \n" + "prfm pldl1keep, [%[src], 448] \n" + "uzp1 v0.8h, v2.8h, v3.8h \n" + "uzp1 v1.8h, v4.8h, v5.8h \n" + "subhn v0.8b, v29.8h, v0.8h \n" // -signed -> unsigned + "subhn v1.8b, v29.8h, v1.8h \n" + "str d0, [%[dst_u]], #8 \n" // store 8 pixels U. + "str d1, [%[dst_v]], #8 \n" // store 8 pixels V. + "b.gt 1b \n" + : [src] "+r"(src_argb), // %[src] + [dst_u] "+r"(dst_u), // %[dst_u] + [dst_v] "+r"(dst_v), // %[dst_v] + [width] "+r"(width) // %[width] + : [c] "r"(c) // %[c] + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v16", "v17", + "v29"); +} + +// RGB to BT601 coefficients +// UB 0.875 coefficient = 112 +// UG -0.5781 coefficient = -74 +// UR -0.2969 coefficient = -38 +// VB -0.1406 coefficient = -18 +// VG -0.7344 coefficient = -94 +// VR 0.875 coefficient = 112 #define RGBTOUV_SETUP_REG \ - "movi v20.8h, #56, lsl #0 \n" /* UB/VR coefficient (0.875) / 2 */ \ - "movi v21.8h, #37, lsl #0 \n" /* UG coefficient (-0.5781) / 2 */ \ - "movi v22.8h, #19, lsl #0 \n" /* UR coefficient (-0.2969) / 2 */ \ - "movi v23.8h, #9, lsl #0 \n" /* VB coefficient (-0.1406) / 2 */ \ - "movi v24.8h, #47, lsl #0 \n" /* VG coefficient (-0.7344) / 2 */ \ - "movi v25.16b, #0x80 \n" /* 128.5 (0x8080 in 16-bit) */ + "movi v20.8h, #112 \n" /* UB/VR coefficient (0.875) */ \ + "movi v21.8h, #74 \n" /* UG coefficient (-0.5781) */ \ + "movi v22.8h, #38 \n" /* UR coefficient (-0.2969) */ \ + "movi v23.8h, #18 \n" /* VB coefficient (-0.1406) */ \ + "movi v24.8h, #94 \n" /* VG coefficient (-0.7344) */ \ + "movi v25.8h, #0x80, lsl #8 \n" /* 128.0 (0x8000 in 16-bit) */ // 16x2 pixels -> 8x1. width is number of argb pixels. e.g. 16. // clang-format off @@ -1381,210 +2960,155 @@ void ARGBToUV444Row_NEON(const uint8_t* src_argb, "mls v4.8h, " #QG ",v24.8h \n" /* G */ \ "mls v3.8h, " #QR ",v22.8h \n" /* R */ \ "mls v4.8h, " #QB ",v23.8h \n" /* B */ \ - "add v3.8h, v3.8h, v25.8h \n" /* +128 -> unsigned */ \ - "add v4.8h, v4.8h, v25.8h \n" /* +128 -> unsigned */ \ - "uqshrn v0.8b, v3.8h, #8 \n" /* 16 bit to 8 bit U */ \ - "uqshrn v1.8b, v4.8h, #8 \n" /* 16 bit to 8 bit V */ + "addhn v0.8b, v3.8h, v25.8h \n" /* +128 -> unsigned */ \ + "addhn v1.8b, v4.8h, v25.8h \n" /* +128 -> unsigned */ // clang-format on // TODO(fbarchard): Consider vhadd vertical, then vpaddl horizontal, avoid shr. // TODO(fbarchard): consider ptrdiff_t for all strides. -void ARGBToUVRow_NEON(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { +void ARGBToUVMatrixRow_NEON(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { const uint8_t* src_argb_1 = src_argb + src_stride_argb; - asm volatile ( - RGBTOUV_SETUP_REG - "1: \n" - "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 pixels. - "uaddlp v0.8h, v0.16b \n" // B 16 bytes -> 8 shorts. - "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts. - "uaddlp v2.8h, v2.16b \n" // R 16 bytes -> 8 shorts. + asm volatile( + "ldr q16, [%[c], #16] \n" // kRGBToU + "ldr q17, [%[c], #32] \n" // kRGBToV + "sxtl v16.8h, v16.8b \n" // sign extend U coeffs + // to 16-bit + "sxtl v17.8h, v17.8b \n" // sign extend V coeffs + // to 16-bit + "dup v20.8h, v16.h[0] \n" // U0 + "dup v21.8h, v16.h[1] \n" // U1 + "dup v22.8h, v16.h[2] \n" // U2 + "dup v23.8h, v16.h[3] \n" // U3 + "dup v24.8h, v17.h[0] \n" // V0 + "dup v26.8h, v17.h[1] \n" // V1 + "dup v27.8h, v17.h[2] \n" // V2 + "dup v28.8h, v17.h[3] \n" // V3 + "movi v25.8h, #0x80, lsl #8 \n" // 128.0 in 16-bit + // (0x8000) - "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load next 16 - "uadalp v0.8h, v4.16b \n" // B 16 bytes -> 8 shorts. - "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts. - "uadalp v2.8h, v6.16b \n" // R 16 bytes -> 8 shorts. + "1: \n" + "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 + // pixels. + "subs %w4, %w4, #16 \n" // 16 processed per loop. + "uaddlp v0.8h, v0.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%0, 448] \n" + "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts. + "uaddlp v2.8h, v2.16b \n" // R 16 bytes -> 8 shorts. + "uaddlp v18.8h, v3.16b \n" // A 16 bytes -> 8 shorts. - "urshr v0.8h, v0.8h, #1 \n" // 2x average - "urshr v1.8h, v1.8h, #1 \n" - "urshr v2.8h, v2.8h, #1 \n" + "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load 16 + // more. + "uadalp v0.8h, v4.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%1, 448] \n" + "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts. + "uadalp v2.8h, v6.16b \n" // R 16 bytes -> 8 shorts. + "uadalp v18.8h, v7.16b \n" // A 16 bytes -> 8 shorts. - "subs %w4, %w4, #16 \n" // 32 processed per loop. - RGBTOUV(v0.8h, v1.8h, v2.8h) - "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. - "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. - "b.gt 1b \n" - : "+r"(src_argb), // %0 - "+r"(src_argb_1), // %1 - "+r"(dst_u), // %2 - "+r"(dst_v), // %3 - "+r"(width) // %4 - : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", - "v20", "v21", "v22", "v23", "v24", "v25" - ); + "urshr v0.8h, v0.8h, #2 \n" // average of 4 + "urshr v1.8h, v1.8h, #2 \n" + "urshr v2.8h, v2.8h, #2 \n" + "urshr v18.8h, v18.8h, #2 \n" + + // U = B*U0 + G*U1 + R*U2 + A*U3 + "mul v3.8h, v0.8h, v20.8h \n" + "mla v3.8h, v1.8h, v21.8h \n" + "mla v3.8h, v2.8h, v22.8h \n" + "mla v3.8h, v18.8h, v23.8h \n" + + // V = B*V0 + G*V1 + R*V2 + A*V3 + "mul v4.8h, v0.8h, v24.8h \n" + "mla v4.8h, v1.8h, v26.8h \n" + "mla v4.8h, v2.8h, v27.8h \n" + "mla v4.8h, v18.8h, v28.8h \n" + + // U = (128.0 - U) >> 8, V = (128.0 - V) >> 8 + "subhn v0.8b, v25.8h, v3.8h \n" + "subhn v1.8b, v25.8h, v4.8h \n" + + "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. + "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. + "b.gt 1b \n" + : "+r"(src_argb), // %0 + "+r"(src_argb_1), // %1 + "+r"(dst_u), // %2 + "+r"(dst_v), // %3 + "+r"(width) // %4 + : [c] "r"(c) // %5 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", + "v28"); } -// TODO(fbarchard): Subsample match C code. -void ARGBToUVJRow_NEON(const uint8_t* src_argb, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - const uint8_t* src_argb_1 = src_argb + src_stride_argb; - asm volatile ( - "movi v20.8h, #63, lsl #0 \n" // UB/VR coeff (0.500) / 2 - "movi v21.8h, #42, lsl #0 \n" // UG coeff (-0.33126) / 2 - "movi v22.8h, #21, lsl #0 \n" // UR coeff (-0.16874) / 2 - "movi v23.8h, #10, lsl #0 \n" // VB coeff (-0.08131) / 2 - "movi v24.8h, #53, lsl #0 \n" // VG coeff (-0.41869) / 2 - "movi v25.16b, #0x80 \n" // 128.5 (0x8080 in 16-bit) - "1: \n" - "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 pixels. - "uaddlp v0.8h, v0.16b \n" // B 16 bytes -> 8 shorts. - "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts. - "uaddlp v2.8h, v2.16b \n" // R 16 bytes -> 8 shorts. - "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load next 16 - "uadalp v0.8h, v4.16b \n" // B 16 bytes -> 8 shorts. - "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts. - "uadalp v2.8h, v6.16b \n" // R 16 bytes -> 8 shorts. +void RGBToUVMatrixRow_NEON(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + const uint8_t* src_rgb_1 = src_rgb + src_stride_rgb; + asm volatile( + "ldr q16, [%[c], #16] \n" // kRGBToU + "ldr q17, [%[c], #32] \n" // kRGBToV + "sxtl v16.8h, v16.8b \n" // sign extend U coeffs + "sxtl v17.8h, v17.8b \n" // sign extend V coeffs + "dup v20.8h, v16.h[0] \n" // U0 + "dup v21.8h, v16.h[1] \n" // U1 + "dup v22.8h, v16.h[2] \n" // U2 + "dup v24.8h, v17.h[0] \n" // V0 + "dup v26.8h, v17.h[1] \n" // V1 + "dup v27.8h, v17.h[2] \n" // V2 + "movi v25.8h, #0x80, lsl #8 \n" // 128.0 in 16-bit + // (0x8000) - "urshr v0.8h, v0.8h, #1 \n" // 2x average - "urshr v1.8h, v1.8h, #1 \n" - "urshr v2.8h, v2.8h, #1 \n" + "1: \n" + "ld3 {v0.16b,v1.16b,v2.16b}, [%0], #48 \n" // load 16 pixels. + "subs %w4, %w4, #16 \n" // 16 processed per loop. + "uaddlp v0.8h, v0.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%0, 448] \n" + "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts. + "uaddlp v2.8h, v2.16b \n" // R 16 bytes -> 8 shorts. - "subs %w4, %w4, #16 \n" // 32 processed per loop. - RGBTOUV(v0.8h, v1.8h, v2.8h) - "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. - "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. - "b.gt 1b \n" - : "+r"(src_argb), // %0 - "+r"(src_argb_1), // %1 - "+r"(dst_u), // %2 - "+r"(dst_v), // %3 - "+r"(width) // %4 - : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", - "v20", "v21", "v22", "v23", "v24", "v25" - ); -} + "ld3 {v4.16b,v5.16b,v6.16b}, [%1], #48 \n" // load 16 more. + "uadalp v0.8h, v4.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%1, 448] \n" + "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts. + "uadalp v2.8h, v6.16b \n" // R 16 bytes -> 8 shorts. -void BGRAToUVRow_NEON(const uint8_t* src_bgra, - int src_stride_bgra, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - const uint8_t* src_bgra_1 = src_bgra + src_stride_bgra; - asm volatile ( - RGBTOUV_SETUP_REG - "1: \n" - "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 pixels. - "uaddlp v0.8h, v3.16b \n" // B 16 bytes -> 8 shorts. - "uaddlp v3.8h, v2.16b \n" // G 16 bytes -> 8 shorts. - "uaddlp v2.8h, v1.16b \n" // R 16 bytes -> 8 shorts. - "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load 16 more - "uadalp v0.8h, v7.16b \n" // B 16 bytes -> 8 shorts. - "uadalp v3.8h, v6.16b \n" // G 16 bytes -> 8 shorts. - "uadalp v2.8h, v5.16b \n" // R 16 bytes -> 8 shorts. + "urshr v0.8h, v0.8h, #2 \n" // average of 4 + "urshr v1.8h, v1.8h, #2 \n" + "urshr v2.8h, v2.8h, #2 \n" - "urshr v0.8h, v0.8h, #1 \n" // 2x average - "urshr v1.8h, v3.8h, #1 \n" - "urshr v2.8h, v2.8h, #1 \n" + // U = B*U0 + G*U1 + R*U2 + "mul v3.8h, v0.8h, v20.8h \n" + "mla v3.8h, v1.8h, v21.8h \n" + "mla v3.8h, v2.8h, v22.8h \n" - "subs %w4, %w4, #16 \n" // 32 processed per loop. - RGBTOUV(v0.8h, v1.8h, v2.8h) - "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. - "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. - "b.gt 1b \n" - : "+r"(src_bgra), // %0 - "+r"(src_bgra_1), // %1 - "+r"(dst_u), // %2 - "+r"(dst_v), // %3 - "+r"(width) // %4 - : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", - "v20", "v21", "v22", "v23", "v24", "v25" - ); -} + // V = B*V0 + G*V1 + R*V2 + "mul v4.8h, v0.8h, v24.8h \n" + "mla v4.8h, v1.8h, v26.8h \n" + "mla v4.8h, v2.8h, v27.8h \n" -void ABGRToUVRow_NEON(const uint8_t* src_abgr, - int src_stride_abgr, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - const uint8_t* src_abgr_1 = src_abgr + src_stride_abgr; - asm volatile ( - RGBTOUV_SETUP_REG - "1: \n" - "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 pixels. - "uaddlp v3.8h, v2.16b \n" // B 16 bytes -> 8 shorts. - "uaddlp v2.8h, v1.16b \n" // G 16 bytes -> 8 shorts. - "uaddlp v1.8h, v0.16b \n" // R 16 bytes -> 8 shorts. - "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load 16 more. - "uadalp v3.8h, v6.16b \n" // B 16 bytes -> 8 shorts. - "uadalp v2.8h, v5.16b \n" // G 16 bytes -> 8 shorts. - "uadalp v1.8h, v4.16b \n" // R 16 bytes -> 8 shorts. + // U = (128.0 - U) >> 8, V = (128.0 - V) >> 8 + "subhn v0.8b, v25.8h, v3.8h \n" + "subhn v1.8b, v25.8h, v4.8h \n" - "urshr v0.8h, v3.8h, #1 \n" // 2x average - "urshr v2.8h, v2.8h, #1 \n" - "urshr v1.8h, v1.8h, #1 \n" - - "subs %w4, %w4, #16 \n" // 32 processed per loop. - RGBTOUV(v0.8h, v2.8h, v1.8h) - "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. - "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. - "b.gt 1b \n" - : "+r"(src_abgr), // %0 - "+r"(src_abgr_1), // %1 - "+r"(dst_u), // %2 - "+r"(dst_v), // %3 - "+r"(width) // %4 - : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", - "v20", "v21", "v22", "v23", "v24", "v25" - ); -} - -void RGBAToUVRow_NEON(const uint8_t* src_rgba, - int src_stride_rgba, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - const uint8_t* src_rgba_1 = src_rgba + src_stride_rgba; - asm volatile ( - RGBTOUV_SETUP_REG - "1: \n" - "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 pixels. - "uaddlp v0.8h, v1.16b \n" // B 16 bytes -> 8 shorts. - "uaddlp v1.8h, v2.16b \n" // G 16 bytes -> 8 shorts. - "uaddlp v2.8h, v3.16b \n" // R 16 bytes -> 8 shorts. - "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load 16 more. - "uadalp v0.8h, v5.16b \n" // B 16 bytes -> 8 shorts. - "uadalp v1.8h, v6.16b \n" // G 16 bytes -> 8 shorts. - "uadalp v2.8h, v7.16b \n" // R 16 bytes -> 8 shorts. - - "urshr v0.8h, v0.8h, #1 \n" // 2x average - "urshr v1.8h, v1.8h, #1 \n" - "urshr v2.8h, v2.8h, #1 \n" - - "subs %w4, %w4, #16 \n" // 32 processed per loop. - RGBTOUV(v0.8h, v1.8h, v2.8h) - "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. - "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. - "b.gt 1b \n" - : "+r"(src_rgba), // %0 - "+r"(src_rgba_1), // %1 - "+r"(dst_u), // %2 - "+r"(dst_v), // %3 - "+r"(width) // %4 - : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", - "v20", "v21", "v22", "v23", "v24", "v25" - ); + "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. + "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. + "b.gt 1b \n" + : "+r"(src_rgb), // %0 + "+r"(src_rgb_1), // %1 + "+r"(dst_u), // %2 + "+r"(dst_v), // %3 + "+r"(width) // %4 + : [c] "r"(c) // %5 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v20", "v21", "v22", "v24", "v25", "v26", "v27"); } void RGB24ToUVRow_NEON(const uint8_t* src_rgb24, @@ -1595,25 +3119,27 @@ void RGB24ToUVRow_NEON(const uint8_t* src_rgb24, const uint8_t* src_rgb24_1 = src_rgb24 + src_stride_rgb24; asm volatile ( RGBTOUV_SETUP_REG - "1: \n" - "ld3 {v0.16b,v1.16b,v2.16b}, [%0], #48 \n" // load 16 pixels. - "uaddlp v0.8h, v0.16b \n" // B 16 bytes -> 8 shorts. - "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts. - "uaddlp v2.8h, v2.16b \n" // R 16 bytes -> 8 shorts. - "ld3 {v4.16b,v5.16b,v6.16b}, [%1], #48 \n" // load 16 more. - "uadalp v0.8h, v4.16b \n" // B 16 bytes -> 8 shorts. - "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts. - "uadalp v2.8h, v6.16b \n" // R 16 bytes -> 8 shorts. + "1: \n" + "ld3 {v0.16b,v1.16b,v2.16b}, [%0], #48 \n" // load 16 pixels. + "subs %w4, %w4, #16 \n" // 16 processed per loop. + "uaddlp v0.8h, v0.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%0, 448] \n" + "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts. + "uaddlp v2.8h, v2.16b \n" // R 16 bytes -> 8 shorts. + "ld3 {v4.16b,v5.16b,v6.16b}, [%1], #48 \n" // load 16 more. + "uadalp v0.8h, v4.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%1, 448] \n" + "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts. + "uadalp v2.8h, v6.16b \n" // R 16 bytes -> 8 shorts. - "urshr v0.8h, v0.8h, #1 \n" // 2x average - "urshr v1.8h, v1.8h, #1 \n" - "urshr v2.8h, v2.8h, #1 \n" + "urshr v0.8h, v0.8h, #2 \n" // average of 4 + "urshr v1.8h, v1.8h, #2 \n" + "urshr v2.8h, v2.8h, #2 \n" - "subs %w4, %w4, #16 \n" // 32 processed per loop. RGBTOUV(v0.8h, v1.8h, v2.8h) - "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. - "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. - "b.gt 1b \n" + "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. + "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. + "b.gt 1b \n" : "+r"(src_rgb24), // %0 "+r"(src_rgb24_1), // %1 "+r"(dst_u), // %2 @@ -1633,25 +3159,27 @@ void RAWToUVRow_NEON(const uint8_t* src_raw, const uint8_t* src_raw_1 = src_raw + src_stride_raw; asm volatile ( RGBTOUV_SETUP_REG - "1: \n" - "ld3 {v0.16b,v1.16b,v2.16b}, [%0], #48 \n" // load 8 RAW pixels. - "uaddlp v2.8h, v2.16b \n" // B 16 bytes -> 8 shorts. - "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts. - "uaddlp v0.8h, v0.16b \n" // R 16 bytes -> 8 shorts. - "ld3 {v4.16b,v5.16b,v6.16b}, [%1], #48 \n" // load 8 more RAW pixels - "uadalp v2.8h, v6.16b \n" // B 16 bytes -> 8 shorts. - "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts. - "uadalp v0.8h, v4.16b \n" // R 16 bytes -> 8 shorts. + "1: \n" + "ld3 {v0.16b,v1.16b,v2.16b}, [%0], #48 \n" // load 16 RAW pixels. + "subs %w4, %w4, #16 \n" // 16 processed per loop. + "uaddlp v2.8h, v2.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%0, 448] \n" + "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts. + "uaddlp v0.8h, v0.16b \n" // R 16 bytes -> 8 shorts. + "ld3 {v4.16b,v5.16b,v6.16b}, [%1], #48 \n" // load 8 more RAW pixels + "uadalp v2.8h, v6.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%1, 448] \n" + "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts. + "uadalp v0.8h, v4.16b \n" // R 16 bytes -> 8 shorts. - "urshr v2.8h, v2.8h, #1 \n" // 2x average - "urshr v1.8h, v1.8h, #1 \n" - "urshr v0.8h, v0.8h, #1 \n" + "urshr v2.8h, v2.8h, #2 \n" // average of 4 + "urshr v1.8h, v1.8h, #2 \n" + "urshr v0.8h, v0.8h, #2 \n" - "subs %w4, %w4, #16 \n" // 32 processed per loop. RGBTOUV(v2.8h, v1.8h, v0.8h) - "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. - "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. - "b.gt 1b \n" + "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. + "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. + "b.gt 1b \n" : "+r"(src_raw), // %0 "+r"(src_raw_1), // %1 "+r"(dst_u), // %2 @@ -1663,7 +3191,7 @@ void RAWToUVRow_NEON(const uint8_t* src_raw, ); } -// 16x2 pixels -> 8x1. width is number of argb pixels. e.g. 16. +// 16x2 pixels -> 8x1. width is number of rgb pixels. e.g. 16. void RGB565ToUVRow_NEON(const uint8_t* src_rgb565, int src_stride_rgb565, uint8_t* dst_u, @@ -1671,67 +3199,40 @@ void RGB565ToUVRow_NEON(const uint8_t* src_rgb565, int width) { const uint8_t* src_rgb565_1 = src_rgb565 + src_stride_rgb565; asm volatile( - "movi v22.8h, #56, lsl #0 \n" // UB / VR coeff (0.875) / - // 2 - "movi v23.8h, #37, lsl #0 \n" // UG coeff (-0.5781) / 2 - "movi v24.8h, #19, lsl #0 \n" // UR coeff (-0.2969) / 2 - "movi v25.8h, #9 , lsl #0 \n" // VB coeff (-0.1406) / 2 - "movi v26.8h, #47, lsl #0 \n" // VG coeff (-0.7344) / 2 - "movi v27.16b, #0x80 \n" // 128.5 0x8080 in 16bit - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load 8 RGB565 pixels. + RGBTOUV_SETUP_REG + "1: \n" + "ldp q0, q4, [%0], #32 \n" // load 16 RGB565 pixels. + "subs %w4, %w4, #16 \n" // 16 processed per loop. RGB565TOARGB - "uaddlp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uaddlp v18.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uaddlp v20.4h, v2.8b \n" // R 8 bytes -> 4 shorts. - "ld1 {v0.16b}, [%0], #16 \n" // next 8 RGB565 pixels. + "uaddlp v16.8h, v0.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%0, 448] \n" + "uaddlp v17.8h, v1.16b \n" // G 16 bytes -> 8 shorts. + "uaddlp v18.8h, v2.16b \n" // R 16 bytes -> 8 shorts. + + "ldp q0, q4, [%1], #32 \n" // load 16 RGB565 pixels. RGB565TOARGB - "uaddlp v17.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uaddlp v19.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uaddlp v21.4h, v2.8b \n" // R 8 bytes -> 4 shorts. + "uadalp v16.8h, v0.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%1, 448] \n" + "uadalp v17.8h, v1.16b \n" // G 16 bytes -> 8 shorts. + "uadalp v18.8h, v2.16b \n" // R 16 bytes -> 8 shorts. - "ld1 {v0.16b}, [%1], #16 \n" // load 8 RGB565 pixels. - RGB565TOARGB - "uadalp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uadalp v18.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uadalp v20.4h, v2.8b \n" // R 8 bytes -> 4 shorts. - "ld1 {v0.16b}, [%1], #16 \n" // next 8 RGB565 pixels. - RGB565TOARGB - "uadalp v17.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uadalp v19.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uadalp v21.4h, v2.8b \n" // R 8 bytes -> 4 shorts. + "urshr v0.8h, v16.8h, #2 \n" // average of 4 + "urshr v1.8h, v17.8h, #2 \n" + "urshr v2.8h, v18.8h, #2 \n" - "ins v16.D[1], v17.D[0] \n" - "ins v18.D[1], v19.D[0] \n" - "ins v20.D[1], v21.D[0] \n" - - "urshr v4.8h, v16.8h, #1 \n" // 2x average - "urshr v5.8h, v18.8h, #1 \n" - "urshr v6.8h, v20.8h, #1 \n" - - "subs %w4, %w4, #16 \n" // 16 processed per loop. - "mul v16.8h, v4.8h, v22.8h \n" // B - "mls v16.8h, v5.8h, v23.8h \n" // G - "mls v16.8h, v6.8h, v24.8h \n" // R - "add v16.8h, v16.8h, v27.8h \n" // +128 -> unsigned - "mul v17.8h, v6.8h, v22.8h \n" // R - "mls v17.8h, v5.8h, v26.8h \n" // G - "mls v17.8h, v4.8h, v25.8h \n" // B - "add v17.8h, v17.8h, v27.8h \n" // +128 -> unsigned - "uqshrn v0.8b, v16.8h, #8 \n" // 16 bit to 8 bit U - "uqshrn v1.8b, v17.8h, #8 \n" // 16 bit to 8 bit V - "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. - "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. - "b.gt 1b \n" + RGBTOUV(v0.8h, v1.8h, v2.8h) + "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. + "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. + "b.gt 1b \n" : "+r"(src_rgb565), // %0 "+r"(src_rgb565_1), // %1 - "+r"(dst_u), // %2 - "+r"(dst_v), // %3 - "+r"(width) // %4 + "+r"(dst_u), // %2 + "+r"(dst_v), // %3 + "+r"(width) // %4 : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", - "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", - "v27"); + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v16", "v17", + "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", + "v28"); } // 16x2 pixels -> 8x1. width is number of argb pixels. e.g. 16. @@ -1743,51 +3244,30 @@ void ARGB1555ToUVRow_NEON(const uint8_t* src_argb1555, const uint8_t* src_argb1555_1 = src_argb1555 + src_stride_argb1555; asm volatile( RGBTOUV_SETUP_REG - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB1555 pixels. + "1: \n" + "ldp q0, q3, [%0], #32 \n" // load 16 ARGB1555 pixels. + "subs %w4, %w4, #16 \n" // 16 processed per loop. RGB555TOARGB - "uaddlp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uaddlp v17.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uaddlp v18.4h, v2.8b \n" // R 8 bytes -> 4 shorts. - "ld1 {v0.16b}, [%0], #16 \n" // next 8 ARGB1555 pixels. + "uaddlp v16.8h, v0.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%0, 448] \n" + "uaddlp v17.8h, v1.16b \n" // G 16 bytes -> 8 shorts. + "uaddlp v18.8h, v2.16b \n" // R 16 bytes -> 8 shorts. + + "ldp q0, q3, [%1], #32 \n" // load 16 ARGB1555 pixels. RGB555TOARGB - "uaddlp v26.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uaddlp v27.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uaddlp v28.4h, v2.8b \n" // R 8 bytes -> 4 shorts. + "uadalp v16.8h, v0.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%1, 448] \n" + "uadalp v17.8h, v1.16b \n" // G 16 bytes -> 8 shorts. + "uadalp v18.8h, v2.16b \n" // R 16 bytes -> 8 shorts. - "ld1 {v0.16b}, [%1], #16 \n" // load 8 ARGB1555 pixels. - RGB555TOARGB - "uadalp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uadalp v17.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uadalp v18.4h, v2.8b \n" // R 8 bytes -> 4 shorts. - "ld1 {v0.16b}, [%1], #16 \n" // next 8 ARGB1555 pixels. - RGB555TOARGB - "uadalp v26.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uadalp v27.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uadalp v28.4h, v2.8b \n" // R 8 bytes -> 4 shorts. + "urshr v0.8h, v16.8h, #2 \n" // average of 4 + "urshr v1.8h, v17.8h, #2 \n" + "urshr v2.8h, v18.8h, #2 \n" - "ins v16.D[1], v26.D[0] \n" - "ins v17.D[1], v27.D[0] \n" - "ins v18.D[1], v28.D[0] \n" - - "urshr v4.8h, v16.8h, #1 \n" // 2x average - "urshr v5.8h, v17.8h, #1 \n" - "urshr v6.8h, v18.8h, #1 \n" - - "subs %w4, %w4, #16 \n" // 16 processed per loop. - "mul v2.8h, v4.8h, v20.8h \n" // B - "mls v2.8h, v5.8h, v21.8h \n" // G - "mls v2.8h, v6.8h, v22.8h \n" // R - "add v2.8h, v2.8h, v25.8h \n" // +128 -> unsigned - "mul v3.8h, v6.8h, v20.8h \n" // R - "mls v3.8h, v5.8h, v24.8h \n" // G - "mls v3.8h, v4.8h, v23.8h \n" // B - "add v3.8h, v3.8h, v25.8h \n" // +128 -> unsigned - "uqshrn v0.8b, v2.8h, #8 \n" // 16 bit to 8 bit U - "uqshrn v1.8b, v3.8h, #8 \n" // 16 bit to 8 bit V - "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. - "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. - "b.gt 1b \n" + RGBTOUV(v0.8h, v1.8h, v2.8h) + "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. + "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. + "b.gt 1b \n" : "+r"(src_argb1555), // %0 "+r"(src_argb1555_1), // %1 "+r"(dst_u), // %2 @@ -1796,7 +3276,7 @@ void ARGB1555ToUVRow_NEON(const uint8_t* src_argb1555, : : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", - "v28"); + "v28", "v29"); } // 16x2 pixels -> 8x1. width is number of argb pixels. e.g. 16. @@ -1807,52 +3287,31 @@ void ARGB4444ToUVRow_NEON(const uint8_t* src_argb4444, int width) { const uint8_t* src_argb4444_1 = src_argb4444 + src_stride_argb4444; asm volatile( - RGBTOUV_SETUP_REG - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB4444 pixels. - ARGB4444TOARGB - "uaddlp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uaddlp v17.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uaddlp v18.4h, v2.8b \n" // R 8 bytes -> 4 shorts. - "ld1 {v0.16b}, [%0], #16 \n" // next 8 ARGB4444 pixels. - ARGB4444TOARGB - "uaddlp v26.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uaddlp v27.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uaddlp v28.4h, v2.8b \n" // R 8 bytes -> 4 shorts. + RGBTOUV_SETUP_REG // sets v20-v25 + "1: \n" + "ldp q0, q3, [%0], #32 \n" // load 16 ARGB4444 pixels. + "subs %w4, %w4, #16 \n" // 16 processed per loop. + ARGB4444TORGB + "uaddlp v16.8h, v0.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%0, 448] \n" + "uaddlp v17.8h, v1.16b \n" // G 16 bytes -> 8 shorts. + "uaddlp v18.8h, v2.16b \n" // R 16 bytes -> 8 shorts. - "ld1 {v0.16b}, [%1], #16 \n" // load 8 ARGB4444 pixels. - ARGB4444TOARGB - "uadalp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uadalp v17.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uadalp v18.4h, v2.8b \n" // R 8 bytes -> 4 shorts. - "ld1 {v0.16b}, [%1], #16 \n" // next 8 ARGB4444 pixels. - ARGB4444TOARGB - "uadalp v26.4h, v0.8b \n" // B 8 bytes -> 4 shorts. - "uadalp v27.4h, v1.8b \n" // G 8 bytes -> 4 shorts. - "uadalp v28.4h, v2.8b \n" // R 8 bytes -> 4 shorts. + "ldp q0, q3, [%1], #32 \n" // load 16 ARGB4444 pixels. + ARGB4444TORGB + "uadalp v16.8h, v0.16b \n" // B 16 bytes -> 8 shorts. + "prfm pldl1keep, [%1, 448] \n" + "uadalp v17.8h, v1.16b \n" // G 16 bytes -> 8 shorts. + "uadalp v18.8h, v2.16b \n" // R 16 bytes -> 8 shorts. - "ins v16.D[1], v26.D[0] \n" - "ins v17.D[1], v27.D[0] \n" - "ins v18.D[1], v28.D[0] \n" + "urshr v0.8h, v16.8h, #2 \n" // average of 4 + "urshr v1.8h, v17.8h, #2 \n" + "urshr v2.8h, v18.8h, #2 \n" - "urshr v4.8h, v16.8h, #1 \n" // 2x average - "urshr v5.8h, v17.8h, #1 \n" - "urshr v6.8h, v18.8h, #1 \n" - - "subs %w4, %w4, #16 \n" // 16 processed per loop. - "mul v2.8h, v4.8h, v20.8h \n" // B - "mls v2.8h, v5.8h, v21.8h \n" // G - "mls v2.8h, v6.8h, v22.8h \n" // R - "add v2.8h, v2.8h, v25.8h \n" // +128 -> unsigned - "mul v3.8h, v6.8h, v20.8h \n" // R - "mls v3.8h, v5.8h, v24.8h \n" // G - "mls v3.8h, v4.8h, v23.8h \n" // B - "add v3.8h, v3.8h, v25.8h \n" // +128 -> unsigned - "uqshrn v0.8b, v2.8h, #8 \n" // 16 bit to 8 bit U - "uqshrn v1.8b, v3.8h, #8 \n" // 16 bit to 8 bit V - "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. - "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. - "b.gt 1b \n" + RGBTOUV(v0.8h, v1.8h, v2.8h) + "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U. + "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V. + "b.gt 1b \n" : "+r"(src_argb4444), // %0 "+r"(src_argb4444_1), // %1 "+r"(dst_u), // %2 @@ -1866,23 +3325,109 @@ void ARGB4444ToUVRow_NEON(const uint8_t* src_argb4444, ); } +// Process any of ARGB, ABGR, BGRA, RGBA, by adjusting the ArgbConstants layout. +static void ARGBToUVMatrixRow_NEON_I8MM_Impl(const uint8_t* src, + int src_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + const uint8_t* src1 = src + src_stride; + asm volatile( + "movi v23.8h, #0x80, lsl #8 \n" // 128.0 (0x8000 in + // 16-bit) + "ldr q24, [%[c], #16] \n" // kRGBToU + "ldr q25, [%[c], #32] \n" // kRGBToV + + "1: \n" + "ld2 {v0.4s, v1.4s}, [%[src]], #32 \n" // load 8 pixels + "ld2 {v2.4s, v3.4s}, [%[src]], #32 \n" // load 8 pixels + "subs %w[width], %w[width], #16 \n" // 16 processed per loop + "uaddl v4.8h, v0.8b, v1.8b \n" // ABCDABCD + "uaddl2 v5.8h, v0.16b, v1.16b \n" // ABCDABCD + "uaddl v6.8h, v2.8b, v3.8b \n" // ABCDABCD + "uaddl2 v7.8h, v2.16b, v3.16b \n" // ABCDABCD + + "ld2 {v0.4s, v1.4s}, [%[src1]], #32 \n" // load 8 pixels + "ld2 {v2.4s, v3.4s}, [%[src1]], #32 \n" // load 8 pixels + "uaddw v4.8h, v4.8h, v0.8b \n" // ABCDABCD + "uaddw2 v5.8h, v5.8h, v0.16b \n" // ABCDABCD + "uaddw v6.8h, v6.8h, v2.8b \n" // ABCDABCD + "uaddw2 v7.8h, v7.8h, v2.16b \n" // ABCDABCD + "prfm pldl1keep, [%[src], 448] \n" + "uaddw v4.8h, v4.8h, v1.8b \n" // ABCDABCD + "uaddw2 v5.8h, v5.8h, v1.16b \n" // ABCDABCD + "uaddw v6.8h, v6.8h, v3.8b \n" // ABCDABCD + "uaddw2 v7.8h, v7.8h, v3.16b \n" // ABCDABCD + "prfm pldl1keep, [%[src1], 448] \n" + + "rshrn v4.8b, v4.8h, #2 \n" // average of 4 pixels + "rshrn v6.8b, v6.8h, #2 \n" // average of 4 pixels + "rshrn2 v4.16b, v5.8h, #2 \n" // average of 4 pixels + "rshrn2 v6.16b, v7.8h, #2 \n" // average of 4 pixels + + "movi v0.4s, #0 \n" // U + "movi v1.4s, #0 \n" // U + "usdot v0.4s, v4.16b, v24.16b \n" + "usdot v1.4s, v6.16b, v24.16b \n" + + "movi v2.4s, #0 \n" // V + "movi v3.4s, #0 \n" // V + "usdot v2.4s, v4.16b, v25.16b \n" + "usdot v3.4s, v6.16b, v25.16b \n" + + "uzp1 v0.8h, v0.8h, v1.8h \n" // U + "uzp1 v1.8h, v2.8h, v3.8h \n" // V + + "subhn v0.8b, v23.8h, v0.8h \n" // +128 -> unsigned + "subhn v1.8b, v23.8h, v1.8h \n" // +128 -> unsigned + + "str d0, [%[dst_u]], #8 \n" // store 8 pixels U + "str d1, [%[dst_v]], #8 \n" // store 8 pixels V + "b.gt 1b \n" + : [src] "+r"(src), // %[src] + [src1] "+r"(src1), // %[src1] + [dst_u] "+r"(dst_u), // %[dst_u] + [dst_v] "+r"(dst_v), // %[dst_v] + [width] "+r"(width) // %[width] + : [c] "r"(c) // %[c] + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v23", + "v24", "v25"); +} + +void ARGBToUVMatrixRow_NEON_I8MM(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + ARGBToUVMatrixRow_NEON_I8MM_Impl(src_argb, src_stride_argb, dst_u, dst_v, + width, c); +} + void RGB565ToYRow_NEON(const uint8_t* src_rgb565, uint8_t* dst_y, int width) { asm volatile( - "movi v24.8b, #13 \n" // B * 0.1016 coefficient - "movi v25.8b, #65 \n" // G * 0.5078 coefficient - "movi v26.8b, #33 \n" // R * 0.2578 coefficient - "movi v27.8b, #16 \n" // Add 16 constant - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load 8 RGB565 pixels. - "subs %w2, %w2, #8 \n" // 8 processed per loop. + "movi v24.16b, #25 \n" // B * 0.1016 coefficient + "movi v25.16b, #129 \n" // G * 0.5078 coefficient + "movi v26.16b, #66 \n" // R * 0.2578 coefficient + "movi v27.16b, #16 \n" // Add 16 constant + "1: \n" + "ldp q0, q4, [%0], #32 \n" // load 16 RGB565 pixels. + "subs %w2, %w2, #16 \n" // 16 processed per loop. RGB565TOARGB - "umull v3.8h, v0.8b, v24.8b \n" // B - "umlal v3.8h, v1.8b, v25.8b \n" // G - "umlal v3.8h, v2.8b, v26.8b \n" // R - "sqrshrun v0.8b, v3.8h, #7 \n" // 16 bit to 8 bit Y - "uqadd v0.8b, v0.8b, v27.8b \n" - "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y. - "b.gt 1b \n" + "umull v3.8h, v0.8b, v24.8b \n" // B + "umull2 v4.8h, v0.16b, v24.16b \n" // B + "prfm pldl1keep, [%0, 448] \n" + "umlal v3.8h, v1.8b, v25.8b \n" // G + "umlal2 v4.8h, v1.16b, v25.16b \n" // G + "umlal v3.8h, v2.8b, v26.8b \n" // R + "umlal2 v4.8h, v2.16b, v26.16b \n" // R + "uqrshrn v0.8b, v3.8h, #8 \n" // 16 bit to 8 bit Y + "uqrshrn v1.8b, v4.8h, #8 \n" // 16 bit to 8 bit Y + "uqadd v0.8b, v0.8b, v27.8b \n" + "uqadd v1.8b, v1.8b, v27.8b \n" + "stp d0, d1, [%1], #16 \n" // store 8 pixels Y. + "b.gt 1b \n" : "+r"(src_rgb565), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -1895,167 +3440,215 @@ void ARGB1555ToYRow_NEON(const uint8_t* src_argb1555, uint8_t* dst_y, int width) { asm volatile( - "movi v4.8b, #13 \n" // B * 0.1016 coefficient - "movi v5.8b, #65 \n" // G * 0.5078 coefficient - "movi v6.8b, #33 \n" // R * 0.2578 coefficient - "movi v7.8b, #16 \n" // Add 16 constant - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB1555 pixels. - "subs %w2, %w2, #8 \n" // 8 processed per loop. - ARGB1555TOARGB - "umull v3.8h, v0.8b, v4.8b \n" // B - "umlal v3.8h, v1.8b, v5.8b \n" // G - "umlal v3.8h, v2.8b, v6.8b \n" // R - "sqrshrun v0.8b, v3.8h, #7 \n" // 16 bit to 8 bit Y - "uqadd v0.8b, v0.8b, v7.8b \n" - "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y. - "b.gt 1b \n" + "movi v4.16b, #25 \n" // B * 0.1016 coefficient + "movi v5.16b, #129 \n" // G * 0.5078 coefficient + "movi v6.16b, #66 \n" // R * 0.2578 coefficient + "movi v7.16b, #16 \n" // Add 16 constant + "1: \n" + "ldp q0, q3, [%0], #32 \n" // load 16 ARGB1555 + // pixels. + "subs %w2, %w2, #16 \n" // 16 processed per loop. + RGB555TOARGB + "umull v16.8h, v0.8b, v4.8b \n" // B + "umull2 v17.8h, v0.16b, v4.16b \n" // B + "prfm pldl1keep, [%0, 448] \n" + "umlal v16.8h, v1.8b, v5.8b \n" // G + "umlal2 v17.8h, v1.16b, v5.16b \n" // G + "umlal v16.8h, v2.8b, v6.8b \n" // R + "umlal2 v17.8h, v2.16b, v6.16b \n" // R + "uqrshrn v0.8b, v16.8h, #8 \n" // 16 bit to 8 bit Y + "uqrshrn2 v0.16b, v17.8h, #8 \n" // 16 bit to 8 bit Y + "uqadd v0.16b, v0.16b, v7.16b \n" + "str q0, [%1], #16 \n" // store pixels Y. + "b.gt 1b \n" : "+r"(src_argb1555), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v29"); } void ARGB4444ToYRow_NEON(const uint8_t* src_argb4444, uint8_t* dst_y, int width) { asm volatile( - "movi v24.8b, #13 \n" // B * 0.1016 coefficient - "movi v25.8b, #65 \n" // G * 0.5078 coefficient - "movi v26.8b, #33 \n" // R * 0.2578 coefficient - "movi v27.8b, #16 \n" // Add 16 constant - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB4444 pixels. - "subs %w2, %w2, #8 \n" // 8 processed per loop. - ARGB4444TOARGB - "umull v3.8h, v0.8b, v24.8b \n" // B - "umlal v3.8h, v1.8b, v25.8b \n" // G - "umlal v3.8h, v2.8b, v26.8b \n" // R - "sqrshrun v0.8b, v3.8h, #7 \n" // 16 bit to 8 bit Y - "uqadd v0.8b, v0.8b, v27.8b \n" - "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y. - "b.gt 1b \n" + "movi v24.16b, #25 \n" // B * 0.1016 coefficient + "movi v25.16b, #129 \n" // G * 0.5078 coefficient + "movi v26.16b, #66 \n" // R * 0.2578 coefficient + "movi v27.16b, #16 \n" // Add 16 constant + "1: \n" + "ldp q0, q3, [%0], #32 \n" // load 16 ARGB4444 + // pixels. + "subs %w2, %w2, #16 \n" // 16 processed per loop. + ARGB4444TORGB + "umull v16.8h, v0.8b, v24.8b \n" // B + "umull2 v17.8h, v0.16b, v24.16b \n" // B + "prfm pldl1keep, [%0, 448] \n" + "umlal v16.8h, v1.8b, v25.8b \n" // G + "umlal2 v17.8h, v1.16b, v25.16b \n" // G + "umlal v16.8h, v2.8b, v26.8b \n" // R + "umlal2 v17.8h, v2.16b, v26.16b \n" // R + "uqrshrn v0.8b, v16.8h, #8 \n" // 16 bit to 8 bit Y + "uqrshrn2 v0.16b, v17.8h, #8 \n" // 16 bit to 8 bit Y + "uqadd v0.16b, v0.16b, v27.16b \n" + "str q0, [%1], #16 \n" // store 8 pixels Y. + "b.gt 1b \n" : "+r"(src_argb4444), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 : - : "cc", "memory", "v0", "v1", "v2", "v3", "v24", "v25", "v26", "v27"); + : "memory", "cc", "v0", "v1", "v2", "v3", "v16", "v17", "v24", "v25", + "v26", "v27"); } -void BGRAToYRow_NEON(const uint8_t* src_bgra, uint8_t* dst_y, int width) { +// ARGB expects first 3 values to contain RGB and 4th value is ignored. +void ARGBToYMatrixRow_NEON(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { asm volatile( - "movi v4.8b, #33 \n" // R * 0.2578 coefficient - "movi v5.8b, #65 \n" // G * 0.5078 coefficient - "movi v6.8b, #13 \n" // B * 0.1016 coefficient - "movi v7.8b, #16 \n" // Add 16 constant - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 pixels. - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "umull v16.8h, v1.8b, v4.8b \n" // R - "umlal v16.8h, v2.8b, v5.8b \n" // G - "umlal v16.8h, v3.8b, v6.8b \n" // B - "sqrshrun v0.8b, v16.8h, #7 \n" // 16 bit to 8 bit Y - "uqadd v0.8b, v0.8b, v7.8b \n" - "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y. - "b.gt 1b \n" - : "+r"(src_bgra), // %0 + "ldr s16, [%3] \n" // load 4 coeffs + "ldr s17, [%3, #48] \n" // load kAddY[0] + "dup v18.16b, v16.b[0] \n" // B + "dup v19.16b, v16.b[1] \n" // G + "dup v20.16b, v16.b[2] \n" // R + "dup v21.16b, v16.b[3] \n" // A + "dup v22.8h, v17.h[0] \n" // bias + "1: \n" + "ld4 {v2.16b,v3.16b,v4.16b,v5.16b}, [%0], #64 \n" // load 16 + "subs %w2, %w2, #16 \n" // 16 processed per loop. + "umull v0.8h, v2.8b, v18.8b \n" // B + "umull2 v1.8h, v2.16b, v18.16b \n" + "prfm pldl1keep, [%0, 448] \n" + "umlal v0.8h, v3.8b, v19.8b \n" // G + "umlal2 v1.8h, v3.16b, v19.16b \n" + "umlal v0.8h, v4.8b, v20.8b \n" // R + "umlal2 v1.8h, v4.16b, v20.16b \n" + "umlal v0.8h, v5.8b, v21.8b \n" // A + "umlal2 v1.8h, v5.16b, v21.16b \n" + "addhn v0.8b, v0.8h, v22.8h \n" // 16 bit to 8 bit Y + "addhn v1.8b, v1.8h, v22.8h \n" + "st1 {v0.8b, v1.8b}, [%1], #16 \n" // store 16 pixels Y. + "b.gt 1b \n" + : "+r"(src_argb), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 - : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16"); + : "r"(c) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v16", "v17", "v18", + "v19", "v20", "v21", "v22"); } -void ABGRToYRow_NEON(const uint8_t* src_abgr, uint8_t* dst_y, int width) { +void ARGBToYMatrixRow_NEON_DotProd(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { asm volatile( - "movi v4.8b, #33 \n" // R * 0.2578 coefficient - "movi v5.8b, #65 \n" // G * 0.5078 coefficient - "movi v6.8b, #13 \n" // B * 0.1016 coefficient - "movi v7.8b, #16 \n" // Add 16 constant - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 pixels. - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "umull v16.8h, v0.8b, v4.8b \n" // R - "umlal v16.8h, v1.8b, v5.8b \n" // G - "umlal v16.8h, v2.8b, v6.8b \n" // B - "sqrshrun v0.8b, v16.8h, #7 \n" // 16 bit to 8 bit Y - "uqadd v0.8b, v0.8b, v7.8b \n" - "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y. - "b.gt 1b \n" - : "+r"(src_abgr), // %0 + "ldr s16, [%3] \n" // load 4 coeffs + "ldr s17, [%3, #48] \n" // load kAddY[0] + "dup v18.4s, v16.s[0] \n" + "dup v19.8h, v17.h[0] \n" + "1: \n" + "ld1 {v4.16b, v5.16b, v6.16b, v7.16b}, [%0], #64 \n" // load 16 + "subs %w2, %w2, #16 \n" // 16 processed per loop. + "movi v0.16b, #0 \n" + "movi v1.16b, #0 \n" + "movi v2.16b, #0 \n" + "movi v3.16b, #0 \n" + "udot v0.4s, v4.16b, v18.16b \n" + "udot v1.4s, v5.16b, v18.16b \n" + "udot v2.4s, v6.16b, v18.16b \n" + "udot v3.4s, v7.16b, v18.16b \n" + "uzp1 v0.8h, v0.8h, v1.8h \n" + "uzp1 v1.8h, v2.8h, v3.8h \n" + "addhn v0.8b, v0.8h, v19.8h \n" + "addhn v1.8b, v1.8h, v19.8h \n" + "st1 {v0.8b, v1.8b}, [%1], #16 \n" // store 16 pixels Y. + "b.gt 1b \n" + : "+r"(src_argb), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 - : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16"); + : "r"(c) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19"); } -void RGBAToYRow_NEON(const uint8_t* src_rgba, uint8_t* dst_y, int width) { +void RGBToYMatrixRow_NEON_DotProd(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { asm volatile( - "movi v4.8b, #13 \n" // B * 0.1016 coefficient - "movi v5.8b, #65 \n" // G * 0.5078 coefficient - "movi v6.8b, #33 \n" // R * 0.2578 coefficient - "movi v7.8b, #16 \n" // Add 16 constant - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 pixels. - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "umull v16.8h, v1.8b, v4.8b \n" // B - "umlal v16.8h, v2.8b, v5.8b \n" // G - "umlal v16.8h, v3.8b, v6.8b \n" // R - "sqrshrun v0.8b, v16.8h, #7 \n" // 16 bit to 8 bit Y - "uqadd v0.8b, v0.8b, v7.8b \n" - "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y. - "b.gt 1b \n" - : "+r"(src_rgba), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16"); -} - -void RGB24ToYRow_NEON(const uint8_t* src_rgb24, uint8_t* dst_y, int width) { - asm volatile( - "movi v4.8b, #13 \n" // B * 0.1016 coefficient - "movi v5.8b, #65 \n" // G * 0.5078 coefficient - "movi v6.8b, #33 \n" // R * 0.2578 coefficient - "movi v7.8b, #16 \n" // Add 16 constant - "1: \n" - "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // load 8 pixels. - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "umull v16.8h, v0.8b, v4.8b \n" // B - "umlal v16.8h, v1.8b, v5.8b \n" // G - "umlal v16.8h, v2.8b, v6.8b \n" // R - "sqrshrun v0.8b, v16.8h, #7 \n" // 16 bit to 8 bit Y - "uqadd v0.8b, v0.8b, v7.8b \n" - "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y. - "b.gt 1b \n" - : "+r"(src_rgb24), // %0 - "+r"(dst_y), // %1 - "+r"(width) // %2 - : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16"); -} - -void RAWToYRow_NEON(const uint8_t* src_raw, uint8_t* dst_y, int width) { - asm volatile( - "movi v4.8b, #33 \n" // R * 0.2578 coefficient - "movi v5.8b, #65 \n" // G * 0.5078 coefficient - "movi v6.8b, #13 \n" // B * 0.1016 coefficient - "movi v7.8b, #16 \n" // Add 16 constant - "1: \n" - "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // load 8 pixels. - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "umull v16.8h, v0.8b, v4.8b \n" // B - "umlal v16.8h, v1.8b, v5.8b \n" // G - "umlal v16.8h, v2.8b, v6.8b \n" // R - "sqrshrun v0.8b, v16.8h, #7 \n" // 16 bit to 8 bit Y - "uqadd v0.8b, v0.8b, v7.8b \n" - "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y. - "b.gt 1b \n" - : "+r"(src_raw), // %0 + "ldr s16, [%3] \n" // load 4 coeffs + "ldr s17, [%3, #48] \n" // load kAddY[0] + "dup v18.4s, v16.s[0] \n" + "dup v19.8h, v17.h[0] \n" + "movi v7.16b, #0 \n" // zero alpha + "1: \n" + "ld3 {v4.16b, v5.16b, v6.16b}, [%0], #48 \n" // load 16 pixels + "subs %w2, %w2, #16 \n" // 16 processed per loop. + "zip1 v24.16b, v4.16b, v5.16b \n" // B0 G0 B1 G1 ... + "zip1 v25.16b, v6.16b, v7.16b \n" // R0 0 R1 0 ... + "zip2 v26.16b, v4.16b, v5.16b \n" // B8 G8 B9 G9 ... + "zip2 v27.16b, v6.16b, v7.16b \n" // R8 0 R9 0 ... + "zip1 v20.8h, v24.8h, v25.8h \n" // pixels 0..3 + "zip2 v21.8h, v24.8h, v25.8h \n" // pixels 4..7 + "zip1 v22.8h, v26.8h, v27.8h \n" // pixels 8..11 + "zip2 v23.8h, v26.8h, v27.8h \n" // pixels 12..15 + "movi v0.16b, #0 \n" + "movi v1.16b, #0 \n" + "movi v2.16b, #0 \n" + "movi v3.16b, #0 \n" + "udot v0.4s, v20.16b, v18.16b \n" + "udot v1.4s, v21.16b, v18.16b \n" + "udot v2.4s, v22.16b, v18.16b \n" + "udot v3.4s, v23.16b, v18.16b \n" + "uzp1 v0.8h, v0.8h, v1.8h \n" + "uzp1 v1.8h, v2.8h, v3.8h \n" + "addhn v0.8b, v0.8h, v19.8h \n" + "addhn v1.8b, v1.8h, v19.8h \n" + "st1 {v0.8b, v1.8b}, [%1], #16 \n" // store 16 pixels Y. + "b.gt 1b \n" + : "+r"(src_rgb), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 - : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16"); + : "r"(c) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", + "v27"); +} + +// RGBA expects first value to be A and ignored, then 3 values to contain RGB. +void RGBToYMatrixRow_NEON(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + asm volatile( + "ldr s16, [%3] \n" // load 4 coeffs + "ldr s17, [%3, #48] \n" // load kAddY[0] + "dup v18.16b, v16.b[0] \n" // B + "dup v19.16b, v16.b[1] \n" // G + "dup v20.16b, v16.b[2] \n" // R + "dup v21.8h, v17.h[0] \n" // bias + "1: \n" + "ld3 {v2.16b,v3.16b,v4.16b}, [%0], #48 \n" // load 16 pixels. + "subs %w2, %w2, #16 \n" // 16 processed per loop. + "umull v0.8h, v2.8b, v18.8b \n" // B + "umull2 v1.8h, v2.16b, v18.16b \n" + "prfm pldl1keep, [%0, 448] \n" + "umlal v0.8h, v3.8b, v19.8b \n" // G + "umlal2 v1.8h, v3.16b, v19.16b \n" + "umlal v0.8h, v4.8b, v20.8b \n" // R + "umlal2 v1.8h, v4.16b, v20.16b \n" + "addhn v0.8b, v0.8h, v21.8h \n" // 16 bit to 8 bit Y + "addhn v1.8b, v1.8h, v21.8h \n" + "st1 {v0.8b, v1.8b}, [%1], #16 \n" // store 16 pixels Y. + "b.gt 1b \n" + : "+r"(src_rgb), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(c) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v16", "v17", "v18", + "v19", "v20", "v21"); } // Bilinear filter 16x2 -> 16x1 @@ -2064,120 +3657,209 @@ void InterpolateRow_NEON(uint8_t* dst_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction) { - int y1_fraction = source_y_fraction; - int y0_fraction = 256 - y1_fraction; + const int y1_fraction = source_y_fraction; + const int y0_fraction = 256 - y1_fraction; const uint8_t* src_ptr1 = src_ptr + src_stride; asm volatile( - "cmp %w4, #0 \n" - "b.eq 100f \n" - "cmp %w4, #128 \n" - "b.eq 50f \n" + "cmp %w4, #0 \n" + "b.eq 100f \n" + "cmp %w4, #128 \n" + "b.eq 50f \n" - "dup v5.16b, %w4 \n" - "dup v4.16b, %w5 \n" + "dup v5.16b, %w4 \n" + "dup v4.16b, %w5 \n" // General purpose row blend. - "1: \n" - "ld1 {v0.16b}, [%1], #16 \n" - "ld1 {v1.16b}, [%2], #16 \n" - "subs %w3, %w3, #16 \n" - "umull v2.8h, v0.8b, v4.8b \n" - "umull2 v3.8h, v0.16b, v4.16b \n" - "umlal v2.8h, v1.8b, v5.8b \n" - "umlal2 v3.8h, v1.16b, v5.16b \n" - "rshrn v0.8b, v2.8h, #8 \n" - "rshrn2 v0.16b, v3.8h, #8 \n" - "st1 {v0.16b}, [%0], #16 \n" - "b.gt 1b \n" - "b 99f \n" + "1: \n" + "ld1 {v0.16b}, [%1], #16 \n" + "ld1 {v1.16b}, [%2], #16 \n" + "subs %w3, %w3, #16 \n" + "umull v2.8h, v0.8b, v4.8b \n" + "umull2 v3.8h, v0.16b, v4.16b \n" + "umlal v2.8h, v1.8b, v5.8b \n" + "umlal2 v3.8h, v1.16b, v5.16b \n" + "rshrn v0.8b, v2.8h, #8 \n" + "rshrn v1.8b, v3.8h, #8 \n" + "stp d0, d1, [%0], #16 \n" + "b.gt 1b \n" + "b 99f \n" // Blend 50 / 50. - "50: \n" - "ld1 {v0.16b}, [%1], #16 \n" - "ld1 {v1.16b}, [%2], #16 \n" - "subs %w3, %w3, #16 \n" - "urhadd v0.16b, v0.16b, v1.16b \n" - "st1 {v0.16b}, [%0], #16 \n" - "b.gt 50b \n" - "b 99f \n" + "50: \n" + "ld1 {v0.16b}, [%1], #16 \n" + "ld1 {v1.16b}, [%2], #16 \n" + "subs %w3, %w3, #16 \n" + "urhadd v0.16b, v0.16b, v1.16b \n" + "st1 {v0.16b}, [%0], #16 \n" + "b.gt 50b \n" + "b 99f \n" // Blend 100 / 0 - Copy row unchanged. - "100: \n" - "ld1 {v0.16b}, [%1], #16 \n" - "subs %w3, %w3, #16 \n" - "st1 {v0.16b}, [%0], #16 \n" - "b.gt 100b \n" + "100: \n" + "ld1 {v0.16b}, [%1], #16 \n" + "subs %w3, %w3, #16 \n" + "st1 {v0.16b}, [%0], #16 \n" + "b.gt 100b \n" - "99: \n" - : "+r"(dst_ptr), // %0 - "+r"(src_ptr), // %1 - "+r"(src_ptr1), // %2 - "+r"(dst_width), // %3 - "+r"(y1_fraction), // %4 - "+r"(y0_fraction) // %5 - : - : "cc", "memory", "v0", "v1", "v3", "v4", "v5"); + "99: \n" + : "+r"(dst_ptr), // %0 + "+r"(src_ptr), // %1 + "+r"(src_ptr1), // %2 + "+r"(dst_width) // %3 + : "r"(y1_fraction), // %4 + "r"(y0_fraction) // %5 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5"); +} + +// Bilinear filter 8x2 -> 8x1 +void InterpolateRow_16_NEON(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int dst_width, + int source_y_fraction) { + int y1_fraction = source_y_fraction; + int y0_fraction = 256 - y1_fraction; + const uint16_t* src_ptr1 = src_ptr + src_stride; + + asm volatile( + "cmp %w4, #0 \n" + "b.eq 100f \n" + "cmp %w4, #128 \n" + "b.eq 50f \n" + + "dup v5.8h, %w4 \n" + "dup v4.8h, %w5 \n" + "subs %w3, %w3, #16 \n" + "b.lt 2f \n" + + // 16-element unrolled loop (32 bytes). + "1: \n" + "ldp q0, q1, [%1], #32 \n" + "ldp q6, q7, [%2], #32 \n" + "subs %w3, %w3, #16 \n" + "umull v16.4s, v0.4h, v4.4h \n" + "umull2 v17.4s, v0.8h, v4.8h \n" + "umull v18.4s, v1.4h, v4.4h \n" + "umull2 v19.4s, v1.8h, v4.8h \n" + "umlal v16.4s, v6.4h, v5.4h \n" + "umlal2 v17.4s, v6.8h, v5.8h \n" + "umlal v18.4s, v7.4h, v5.4h \n" + "umlal2 v19.4s, v7.8h, v5.8h \n" + "rshrn v0.4h, v16.4s, #8 \n" + "rshrn v1.4h, v17.4s, #8 \n" + "rshrn v2.4h, v18.4s, #8 \n" + "rshrn v3.4h, v19.4s, #8 \n" + "stp d0, d1, [%0], #16 \n" + "stp d2, d3, [%0], #16 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w3, %w3, #16 \n" + "b.eq 99f \n" + + // 8-element tail (16 bytes). + "ld1 {v0.8h}, [%1] \n" + "ld1 {v1.8h}, [%2] \n" + "umull v16.4s, v0.4h, v4.4h \n" + "umull2 v17.4s, v0.8h, v4.8h \n" + "umlal v16.4s, v1.4h, v5.4h \n" + "umlal2 v17.4s, v1.8h, v5.8h \n" + "rshrn v0.4h, v16.4s, #8 \n" + "rshrn v1.4h, v17.4s, #8 \n" + "stp d0, d1, [%0] \n" + "b 99f \n" + + // Blend 50 / 50. + "50: \n" + "ld1 {v0.8h}, [%1], #16 \n" + "ld1 {v1.8h}, [%2], #16 \n" + "subs %w3, %w3, #8 \n" + "urhadd v0.8h, v0.8h, v1.8h \n" + "st1 {v0.8h}, [%0], #16 \n" + "b.gt 50b \n" + "b 99f \n" + + // Blend 100 / 0 - Copy row unchanged. + "100: \n" + "ld1 {v0.8h}, [%1], #16 \n" + "subs %w3, %w3, #8 \n" + "st1 {v0.8h}, [%0], #16 \n" + "b.gt 100b \n" + + "99: \n" + : "+r"(dst_ptr), // %0 + "+r"(src_ptr), // %1 + "+r"(src_ptr1), // %2 + "+r"(dst_width) // %3 + : "r"(y1_fraction), // %4 + "r"(y0_fraction) // %5 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19"); } // dr * (256 - sa) / 256 + sr = dr - dr * sa / 256 + sr -void ARGBBlendRow_NEON(const uint8_t* src_argb0, +void ARGBBlendRow_NEON(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( - "subs %w3, %w3, #8 \n" - "b.lt 89f \n" + "subs %w3, %w3, #8 \n" + "b.lt 89f \n" // Blend 8 pixels. - "8: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB0 - // pixels - "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load 8 ARGB1 - // pixels - "subs %w3, %w3, #8 \n" // 8 processed per loop. - "umull v16.8h, v4.8b, v3.8b \n" // db * a - "umull v17.8h, v5.8b, v3.8b \n" // dg * a - "umull v18.8h, v6.8b, v3.8b \n" // dr * a - "uqrshrn v16.8b, v16.8h, #8 \n" // db >>= 8 - "uqrshrn v17.8b, v17.8h, #8 \n" // dg >>= 8 - "uqrshrn v18.8b, v18.8h, #8 \n" // dr >>= 8 - "uqsub v4.8b, v4.8b, v16.8b \n" // db - (db * a / 256) - "uqsub v5.8b, v5.8b, v17.8b \n" // dg - (dg * a / 256) - "uqsub v6.8b, v6.8b, v18.8b \n" // dr - (dr * a / 256) - "uqadd v0.8b, v0.8b, v4.8b \n" // + sb - "uqadd v1.8b, v1.8b, v5.8b \n" // + sg - "uqadd v2.8b, v2.8b, v6.8b \n" // + sr - "movi v3.8b, #255 \n" // a = 255 - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB - // pixels - "b.ge 8b \n" + "8: \n" + "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB0 + "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load 8 ARGB1 + "subs %w3, %w3, #8 \n" // 8 processed per loop. + "umull v16.8h, v4.8b, v3.8b \n" // db * a + "prfm pldl1keep, [%0, 448] \n" + "umull v17.8h, v5.8b, v3.8b \n" // dg * a + "prfm pldl1keep, [%1, 448] \n" + "umull v18.8h, v6.8b, v3.8b \n" // dr * a + "uqrshrn v16.8b, v16.8h, #8 \n" // db >>= 8 + "uqrshrn v17.8b, v17.8h, #8 \n" // dg >>= 8 + "uqrshrn v18.8b, v18.8h, #8 \n" // dr >>= 8 + "uqsub v4.8b, v4.8b, v16.8b \n" // db - (db * a / 256) + "uqsub v5.8b, v5.8b, v17.8b \n" // dg - (dg * a / 256) + "uqsub v6.8b, v6.8b, v18.8b \n" // dr - (dr * a / 256) + "uqadd v0.8b, v0.8b, v4.8b \n" // + sb + "uqadd v1.8b, v1.8b, v5.8b \n" // + sg + "uqadd v2.8b, v2.8b, v6.8b \n" // + sr + "movi v3.8b, #255 \n" // a = 255 + "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB + // pixels + "b.ge 8b \n" - "89: \n" - "adds %w3, %w3, #8-1 \n" - "b.lt 99f \n" + "89: \n" + "adds %w3, %w3, #8-1 \n" + "b.lt 99f \n" // Blend 1 pixels. - "1: \n" - "ld4 {v0.b,v1.b,v2.b,v3.b}[0], [%0], #4 \n" // load 1 pixel ARGB0. - "ld4 {v4.b,v5.b,v6.b,v7.b}[0], [%1], #4 \n" // load 1 pixel ARGB1. - "subs %w3, %w3, #1 \n" // 1 processed per loop. - "umull v16.8h, v4.8b, v3.8b \n" // db * a - "umull v17.8h, v5.8b, v3.8b \n" // dg * a - "umull v18.8h, v6.8b, v3.8b \n" // dr * a - "uqrshrn v16.8b, v16.8h, #8 \n" // db >>= 8 - "uqrshrn v17.8b, v17.8h, #8 \n" // dg >>= 8 - "uqrshrn v18.8b, v18.8h, #8 \n" // dr >>= 8 - "uqsub v4.8b, v4.8b, v16.8b \n" // db - (db * a / 256) - "uqsub v5.8b, v5.8b, v17.8b \n" // dg - (dg * a / 256) - "uqsub v6.8b, v6.8b, v18.8b \n" // dr - (dr * a / 256) - "uqadd v0.8b, v0.8b, v4.8b \n" // + sb - "uqadd v1.8b, v1.8b, v5.8b \n" // + sg - "uqadd v2.8b, v2.8b, v6.8b \n" // + sr - "movi v3.8b, #255 \n" // a = 255 - "st4 {v0.b,v1.b,v2.b,v3.b}[0], [%2], #4 \n" // store 1 pixel. - "b.ge 1b \n" + "1: \n" + "ld4 {v0.b,v1.b,v2.b,v3.b}[0], [%0], #4 \n" // load 1 pixel + // ARGB0. + "ld4 {v4.b,v5.b,v6.b,v7.b}[0], [%1], #4 \n" // load 1 pixel + // ARGB1. + "subs %w3, %w3, #1 \n" // 1 processed per loop. + "umull v16.8h, v4.8b, v3.8b \n" // db * a + "prfm pldl1keep, [%0, 448] \n" + "umull v17.8h, v5.8b, v3.8b \n" // dg * a + "prfm pldl1keep, [%1, 448] \n" + "umull v18.8h, v6.8b, v3.8b \n" // dr * a + "uqrshrn v16.8b, v16.8h, #8 \n" // db >>= 8 + "uqrshrn v17.8b, v17.8h, #8 \n" // dg >>= 8 + "uqrshrn v18.8b, v18.8h, #8 \n" // dr >>= 8 + "uqsub v4.8b, v4.8b, v16.8b \n" // db - (db * a / 256) + "uqsub v5.8b, v5.8b, v17.8b \n" // dg - (dg * a / 256) + "uqsub v6.8b, v6.8b, v18.8b \n" // dr - (dr * a / 256) + "uqadd v0.8b, v0.8b, v4.8b \n" // + sb + "uqadd v1.8b, v1.8b, v5.8b \n" // + sg + "uqadd v2.8b, v2.8b, v6.8b \n" // + sr + "movi v3.8b, #255 \n" // a = 255 + "st4 {v0.b,v1.b,v2.b,v3.b}[0], [%2], #4 \n" // store 1 pixel. + "b.ge 1b \n" - "99: \n" + "99: \n" - : "+r"(src_argb0), // %0 + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -2186,29 +3868,116 @@ void ARGBBlendRow_NEON(const uint8_t* src_argb0, "v17", "v18"); } +void ARGBOrRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + asm volatile( + "dup v2.4s, %w3 \n" + "1: \n" + "ldp q0, q1, [%0], #32 \n" + "subs %w2, %w2, #8 \n" + "orr v0.16b, v0.16b, v2.16b \n" + "orr v1.16b, v1.16b, v2.16b \n" + "stp q0, q1, [%1], #32 \n" + "b.gt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(value) // %3 + : "memory", "cc", "v0", "v1", "v2"); +} + +void ARGBAlphaBlendRow_NEON(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + asm volatile( + "movi v28.8b, #255 \n" + "movi v29.8h, #1 \n" + "1: \n" + "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" + "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" + "subs %w3, %w3, #8 \n" + "mov v16.16b, v29.16b \n" + "umlal v16.8h, v7.8b, v3.8b \n" + "usra v16.8h, v16.8h, #8 \n" + "shrn v16.8b, v16.8h, #8 \n" + "cmeq v17.8b, v7.8b, #0 \n" + "sub v16.8b, v3.8b, v16.8b \n" + "add v7.8b, v7.8b, v16.8b \n" + "orr v18.8b, v3.8b, v17.8b \n" + "orr v19.8b, v7.8b, v17.8b \n" + "umull v16.8h, v18.8b, v28.8b \n" + "uxtl v17.8h, v19.8b \n" + "uxtl v20.4s, v16.4h \n" + "uxtl2 v21.4s, v16.8h \n" + "uxtl v22.4s, v17.4h \n" + "uxtl2 v23.4s, v17.8h \n" + "ucvtf v20.4s, v20.4s \n" + "ucvtf v21.4s, v21.4s \n" + "ucvtf v22.4s, v22.4s \n" + "ucvtf v23.4s, v23.4s \n" + "fdiv v20.4s, v20.4s, v22.4s \n" + "fdiv v21.4s, v21.4s, v23.4s \n" + "fcvtzu v20.4s, v20.4s \n" + "fcvtzu v21.4s, v21.4s \n" + "xtn v16.4h, v20.4s \n" + "xtn2 v16.8h, v21.4s \n" + "xtn v16.8b, v16.8h \n" + "sub v17.8b, v28.8b, v16.8b \n" + "mov v20.16b, v29.16b \n" + "mov v21.16b, v29.16b \n" + "mov v22.16b, v29.16b \n" + "umlal v20.8h, v4.8b, v17.8b \n" + "umlal v21.8h, v5.8b, v17.8b \n" + "umlal v22.8h, v6.8b, v17.8b \n" + "umlal v20.8h, v0.8b, v16.8b \n" + "umlal v21.8h, v1.8b, v16.8b \n" + "umlal v22.8h, v2.8b, v16.8b \n" + "usra v20.8h, v20.8h, #8 \n" + "usra v21.8h, v21.8h, #8 \n" + "usra v22.8h, v22.8h, #8 \n" + "shrn v0.8b, v20.8h, #8 \n" + "shrn v1.8b, v21.8h, #8 \n" + "shrn v2.8b, v22.8h, #8 \n" + "mov v3.8b, v7.8b \n" + "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" + "b.gt 1b \n" + : "+r"(src_argb), // %0 + "+r"(src_argb1), // %1 + "+r"(dst_argb), // %2 + "+r"(width) // %3 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v28", "v29"); +} + // Attenuate 8 pixels at a time. void ARGBAttenuateRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width) { asm volatile( + "movi v7.8h, #0x00ff \n" // 255 for rounding up + // Attenuate 8 pixels. - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "umull v4.8h, v0.8b, v3.8b \n" // b * a - "umull v5.8h, v1.8b, v3.8b \n" // g * a - "umull v6.8h, v2.8b, v3.8b \n" // r * a - "uqrshrn v0.8b, v4.8h, #8 \n" // b >>= 8 - "uqrshrn v1.8b, v5.8h, #8 \n" // g >>= 8 - "uqrshrn v2.8b, v6.8h, #8 \n" // r >>= 8 - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 ARGB - // pixels - "b.gt 1b \n" + "1: \n" + "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "umull v4.8h, v0.8b, v3.8b \n" // b * a + "prfm pldl1keep, [%0, 448] \n" + "umull v5.8h, v1.8b, v3.8b \n" // g * a + "umull v6.8h, v2.8b, v3.8b \n" // r * a + "addhn v0.8b, v4.8h, v7.8h \n" // (b + 255) >> 8 + "addhn v1.8b, v5.8h, v7.8h \n" // (g + 255) >> 8 + "addhn v2.8b, v6.8h, v7.8h \n" // (r + 255) >> 8 + "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 ARGB + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 : - : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6"); + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); } // Quantize 8 ARGB pixels (32 bytes). @@ -2219,32 +3988,33 @@ void ARGBQuantizeRow_NEON(uint8_t* dst_argb, int interval_offset, int width) { asm volatile( - "dup v4.8h, %w2 \n" - "ushr v4.8h, v4.8h, #1 \n" // scale >>= 1 - "dup v5.8h, %w3 \n" // interval multiply. - "dup v6.8h, %w4 \n" // interval add + "dup v4.8h, %w2 \n" + "ushr v4.8h, v4.8h, #1 \n" // scale >>= 1 + "dup v5.8h, %w3 \n" // interval multiply. + "dup v6.8h, %w4 \n" // interval add // 8 pixel loop. - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0] \n" // load 8 ARGB. - "subs %w1, %w1, #8 \n" // 8 processed per loop. - "uxtl v0.8h, v0.8b \n" // b (0 .. 255) - "uxtl v1.8h, v1.8b \n" - "uxtl v2.8h, v2.8b \n" - "sqdmulh v0.8h, v0.8h, v4.8h \n" // b * scale - "sqdmulh v1.8h, v1.8h, v4.8h \n" // g - "sqdmulh v2.8h, v2.8h, v4.8h \n" // r - "mul v0.8h, v0.8h, v5.8h \n" // b * interval_size - "mul v1.8h, v1.8h, v5.8h \n" // g - "mul v2.8h, v2.8h, v5.8h \n" // r - "add v0.8h, v0.8h, v6.8h \n" // b + interval_offset - "add v1.8h, v1.8h, v6.8h \n" // g - "add v2.8h, v2.8h, v6.8h \n" // r - "uqxtn v0.8b, v0.8h \n" - "uqxtn v1.8b, v1.8h \n" - "uqxtn v2.8b, v2.8h \n" - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // store 8 ARGB - "b.gt 1b \n" + "1: \n" + "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0] \n" // load 8 ARGB. + "subs %w1, %w1, #8 \n" // 8 processed per loop. + "uxtl v0.8h, v0.8b \n" // b (0 .. 255) + "prfm pldl1keep, [%0, 448] \n" + "uxtl v1.8h, v1.8b \n" + "uxtl v2.8h, v2.8b \n" + "sqdmulh v0.8h, v0.8h, v4.8h \n" // b * scale + "sqdmulh v1.8h, v1.8h, v4.8h \n" // g + "sqdmulh v2.8h, v2.8h, v4.8h \n" // r + "mul v0.8h, v0.8h, v5.8h \n" // b * interval_size + "mul v1.8h, v1.8h, v5.8h \n" // g + "mul v2.8h, v2.8h, v5.8h \n" // r + "add v0.8h, v0.8h, v6.8h \n" // b + interval_offset + "add v1.8h, v1.8h, v6.8h \n" // g + "add v2.8h, v2.8h, v6.8h \n" // r + "uqxtn v0.8b, v0.8h \n" + "uqxtn v1.8b, v1.8h \n" + "uqxtn v2.8b, v2.8h \n" + "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // store 8 ARGB + "b.gt 1b \n" : "+r"(dst_argb), // %0 "+r"(width) // %1 : "r"(scale), // %2 @@ -2254,35 +4024,37 @@ void ARGBQuantizeRow_NEON(uint8_t* dst_argb, } // Shade 8 pixels at a time by specified value. -// NOTE vqrdmulh.s16 q10, q10, d0[0] must use a scaler register from 0 to 8. -// Rounding in vqrdmulh does +1 to high if high bit of low s16 is set. +// sqrdmulh is a rounding instruction, so +1 if high bit of low half of +// multiply result is set. void ARGBShadeRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width, uint32_t value) { asm volatile( - "dup v0.4s, %w3 \n" // duplicate scale value. - "zip1 v0.8b, v0.8b, v0.8b \n" // v0.8b aarrggbb. - "ushr v0.8h, v0.8h, #1 \n" // scale / 2. + "dup v0.4s, %w3 \n" // duplicate scale value. + "zip1 v0.16b, v0.16b, v0.16b \n" // v0.16b + // aarrggbbaarrggbb. + "ushr v0.8h, v0.8h, #1 \n" // scale / 2. // 8 pixel loop. - "1: \n" - "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%0], #32 \n" // load 8 ARGB - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "uxtl v4.8h, v4.8b \n" // b (0 .. 255) - "uxtl v5.8h, v5.8b \n" - "uxtl v6.8h, v6.8b \n" - "uxtl v7.8h, v7.8b \n" - "sqrdmulh v4.8h, v4.8h, v0.h[0] \n" // b * scale * 2 - "sqrdmulh v5.8h, v5.8h, v0.h[1] \n" // g - "sqrdmulh v6.8h, v6.8h, v0.h[2] \n" // r - "sqrdmulh v7.8h, v7.8h, v0.h[3] \n" // a - "uqxtn v4.8b, v4.8h \n" - "uqxtn v5.8b, v5.8h \n" - "uqxtn v6.8b, v6.8h \n" - "uqxtn v7.8b, v7.8h \n" - "st4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // store 8 ARGB - "b.gt 1b \n" + "1: \n" + "ld1 {v4.8b,v5.8b,v6.8b,v7.8b}, [%0], #32 \n" // load 8 ARGB + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "uxtl v4.8h, v4.8b \n" + "prfm pldl1keep, [%0, 448] \n" + "uxtl v5.8h, v5.8b \n" + "uxtl v6.8h, v6.8b \n" + "uxtl v7.8h, v7.8b \n" + "sqrdmulh v4.8h, v4.8h, v0.8h \n" // argb * scale * 2 + "sqrdmulh v5.8h, v5.8h, v0.8h \n" + "sqrdmulh v6.8h, v6.8h, v0.8h \n" + "sqrdmulh v7.8h, v7.8h, v0.8h \n" + "uqxtn v4.8b, v4.8h \n" + "uqxtn v5.8b, v5.8h \n" + "uqxtn v6.8b, v6.8h \n" + "uqxtn v7.8b, v7.8h \n" + "st1 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // store 8 ARGB + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -2292,23 +4064,24 @@ void ARGBShadeRow_NEON(const uint8_t* src_argb, // Convert 8 ARGB pixels (64 bytes) to 8 Gray ARGB pixels // Similar to ARGBToYJ but stores ARGB. -// C code is (15 * b + 75 * g + 38 * r + 64) >> 7; +// C code is (29 * b + 150 * g + 77 * r + 128) >> 8; void ARGBGrayRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width) { asm volatile( - "movi v24.8b, #15 \n" // B * 0.11400 coefficient - "movi v25.8b, #75 \n" // G * 0.58700 coefficient - "movi v26.8b, #38 \n" // R * 0.29900 coefficient - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "umull v4.8h, v0.8b, v24.8b \n" // B - "umlal v4.8h, v1.8b, v25.8b \n" // G - "umlal v4.8h, v2.8b, v26.8b \n" // R - "sqrshrun v0.8b, v4.8h, #7 \n" // 15 bit to 8 bit B - "orr v1.8b, v0.8b, v0.8b \n" // G - "orr v2.8b, v0.8b, v0.8b \n" // R - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 pixels. - "b.gt 1b \n" + "movi v24.8b, #29 \n" // B * 0.1140 coefficient + "movi v25.8b, #150 \n" // G * 0.5870 coefficient + "movi v26.8b, #77 \n" // R * 0.2990 coefficient + "1: \n" + "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "umull v4.8h, v0.8b, v24.8b \n" // B + "prfm pldl1keep, [%0, 448] \n" + "umlal v4.8h, v1.8b, v25.8b \n" // G + "umlal v4.8h, v2.8b, v26.8b \n" // R + "uqrshrn v0.8b, v4.8h, #8 \n" // 16 bit to 8 bit B + "mov v1.8b, v0.8b \n" // G + "mov v2.8b, v0.8b \n" // R + "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 pixels. + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -2316,6 +4089,38 @@ void ARGBGrayRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width) { : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v24", "v25", "v26"); } +static const uvec8 kARGBGrayRowCoeffs = {29, 150, 77, 0}; +static const uvec8 kARGBGrayRowIndices = {0, 0, 0, 19, 2, 2, 2, 23, + 4, 4, 4, 27, 6, 6, 6, 31}; + +void ARGBGrayRow_NEON_DotProd(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + asm volatile( + "ld1r {v24.4s}, [%[coeffs]] \n" + "ldr q25, [%[indices]] \n" + "1: \n" + "ldp q1, q3, [%[src]], #32 \n" // load 8 ARGB + "subs %w[width], %w[width], #8 \n" // 8 processed per loop + "movi v0.4s, #0 \n" + "movi v2.4s, #0 \n" + "udot v0.4s, v1.16b, v24.16b \n" + "udot v2.4s, v3.16b, v24.16b \n" + "prfm pldl1keep, [%[src], 448] \n" + "uqrshrn v0.8b, v0.8h, #8 \n" + "uqrshrn v2.8b, v2.8h, #8 \n" + "tbl v0.16b, {v0.16b, v1.16b}, v25.16b \n" // merge in alpha + "tbl v1.16b, {v2.16b, v3.16b}, v25.16b \n" + "stp q0, q1, [%[dst]], #32 \n" // store 8 pixels + "b.gt 1b \n" + : [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_argb), // %[dst] + [width] "+r"(width) // %[width] + : [coeffs] "r"(&kARGBGrayRowCoeffs), // %[coeffs] + [indices] "r"(&kARGBGrayRowIndices) // %[indices] + : "cc", "memory", "v0", "v1", "v2", "v3", "v24", "v25"); +} + // Convert 8 ARGB pixels (32 bytes) to 8 Sepia ARGB pixels. // b = (r * 35 + g * 68 + b * 17) >> 7 // g = (r * 45 + g * 88 + b * 22) >> 7 @@ -2323,32 +4128,33 @@ void ARGBGrayRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width) { void ARGBSepiaRow_NEON(uint8_t* dst_argb, int width) { asm volatile( - "movi v20.8b, #17 \n" // BB coefficient - "movi v21.8b, #68 \n" // BG coefficient - "movi v22.8b, #35 \n" // BR coefficient - "movi v24.8b, #22 \n" // GB coefficient - "movi v25.8b, #88 \n" // GG coefficient - "movi v26.8b, #45 \n" // GR coefficient - "movi v28.8b, #24 \n" // BB coefficient - "movi v29.8b, #98 \n" // BG coefficient - "movi v30.8b, #50 \n" // BR coefficient - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0] \n" // load 8 ARGB pixels. - "subs %w1, %w1, #8 \n" // 8 processed per loop. - "umull v4.8h, v0.8b, v20.8b \n" // B to Sepia B - "umlal v4.8h, v1.8b, v21.8b \n" // G - "umlal v4.8h, v2.8b, v22.8b \n" // R - "umull v5.8h, v0.8b, v24.8b \n" // B to Sepia G - "umlal v5.8h, v1.8b, v25.8b \n" // G - "umlal v5.8h, v2.8b, v26.8b \n" // R - "umull v6.8h, v0.8b, v28.8b \n" // B to Sepia R - "umlal v6.8h, v1.8b, v29.8b \n" // G - "umlal v6.8h, v2.8b, v30.8b \n" // R - "uqshrn v0.8b, v4.8h, #7 \n" // 16 bit to 8 bit B - "uqshrn v1.8b, v5.8h, #7 \n" // 16 bit to 8 bit G - "uqshrn v2.8b, v6.8h, #7 \n" // 16 bit to 8 bit R - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // store 8 pixels. - "b.gt 1b \n" + "movi v20.8b, #17 \n" // BB coefficient + "movi v21.8b, #68 \n" // BG coefficient + "movi v22.8b, #35 \n" // BR coefficient + "movi v24.8b, #22 \n" // GB coefficient + "movi v25.8b, #88 \n" // GG coefficient + "movi v26.8b, #45 \n" // GR coefficient + "movi v28.8b, #24 \n" // BB coefficient + "movi v29.8b, #98 \n" // BG coefficient + "movi v30.8b, #50 \n" // BR coefficient + "1: \n" + "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0] \n" // load 8 ARGB pixels. + "subs %w1, %w1, #8 \n" // 8 processed per loop. + "umull v4.8h, v0.8b, v20.8b \n" // B to Sepia B + "prfm pldl1keep, [%0, 448] \n" + "umlal v4.8h, v1.8b, v21.8b \n" // G + "umlal v4.8h, v2.8b, v22.8b \n" // R + "umull v5.8h, v0.8b, v24.8b \n" // B to Sepia G + "umlal v5.8h, v1.8b, v25.8b \n" // G + "umlal v5.8h, v2.8b, v26.8b \n" // R + "umull v6.8h, v0.8b, v28.8b \n" // B to Sepia R + "umlal v6.8h, v1.8b, v29.8b \n" // G + "umlal v6.8h, v2.8b, v30.8b \n" // R + "uqshrn v0.8b, v4.8h, #7 \n" // 16 bit to 8 bit B + "uqshrn v1.8b, v5.8h, #7 \n" // 16 bit to 8 bit G + "uqshrn v2.8b, v6.8h, #7 \n" // 16 bit to 8 bit R + "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // store 8 pixels. + "b.gt 1b \n" : "+r"(dst_argb), // %0 "+r"(width) // %1 : @@ -2356,6 +4162,47 @@ void ARGBSepiaRow_NEON(uint8_t* dst_argb, int width) { "v21", "v22", "v24", "v25", "v26", "v28", "v29", "v30"); } +static const uvec8 kARGBSepiaRowCoeffs = {17, 68, 35, 0, 22, 88, + 45, 0, 24, 98, 50, 0}; +static const uvec8 kARGBSepiaRowAlphaIndices = {3, 7, 11, 15, 19, 23, 27, 31}; + +void ARGBSepiaRow_NEON_DotProd(uint8_t* dst_argb, int width) { + asm volatile( + "ld3r {v20.4s, v21.4s, v22.4s}, [%[coeffs]] \n" + "ldr d23, [%[indices]] \n" + "1: \n" + "ldp q0, q1, [%[dst]] \n" + "subs %w1, %w1, #8 \n" + "movi v2.4s, #0 \n" + "movi v3.4s, #0 \n" + "movi v4.4s, #0 \n" + "movi v5.4s, #0 \n" + "movi v6.4s, #0 \n" + "movi v7.4s, #0 \n" + "udot v2.4s, v0.16b, v20.16b \n" + "udot v3.4s, v1.16b, v20.16b \n" + "udot v4.4s, v0.16b, v21.16b \n" + "udot v5.4s, v1.16b, v21.16b \n" + "udot v6.4s, v0.16b, v22.16b \n" + "udot v7.4s, v1.16b, v22.16b \n" + "prfm pldl1keep, [%[dst], 448] \n" + "uzp1 v6.8h, v6.8h, v7.8h \n" + "uzp1 v5.8h, v4.8h, v5.8h \n" + "uzp1 v4.8h, v2.8h, v3.8h \n" + "tbl v3.16b, {v0.16b, v1.16b}, v23.16b \n" + "uqshrn v0.8b, v4.8h, #7 \n" + "uqshrn v1.8b, v5.8h, #7 \n" + "uqshrn v2.8b, v6.8h, #7 \n" + "st4 {v0.8b, v1.8b, v2.8b, v3.8b}, [%[dst]], #32 \n" + "b.gt 1b \n" + : [dst] "+r"(dst_argb), // %[dst] + [width] "+r"(width) // %[width] + : [coeffs] "r"(&kARGBSepiaRowCoeffs), // %[coeffs] + [indices] "r"(&kARGBSepiaRowAlphaIndices) // %[indices] + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", + "v21", "v22", "v23", "v24", "v25", "v26", "v28", "v29", "v30"); +} + // Tranform 8 ARGB pixels (32 bytes) with color matrix. // TODO(fbarchard): Was same as Sepia except matrix is provided. This function // needs to saturate. Consider doing a non-saturating version. @@ -2364,51 +4211,52 @@ void ARGBColorMatrixRow_NEON(const uint8_t* src_argb, const int8_t* matrix_argb, int width) { asm volatile( - "ld1 {v2.16b}, [%3] \n" // load 3 ARGB vectors. - "sxtl v0.8h, v2.8b \n" // B,G coefficients s16. - "sxtl2 v1.8h, v2.16b \n" // R,A coefficients s16. + "ld1 {v2.16b}, [%3] \n" // load 3 ARGB vectors. + "sxtl v0.8h, v2.8b \n" // B,G coefficients s16. + "sxtl2 v1.8h, v2.16b \n" // R,A coefficients s16. - "1: \n" - "ld4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%0], #32 \n" // load 8 ARGB - "subs %w2, %w2, #8 \n" // 8 processed per loop. - "uxtl v16.8h, v16.8b \n" // b (0 .. 255) 16 bit - "uxtl v17.8h, v17.8b \n" // g - "uxtl v18.8h, v18.8b \n" // r - "uxtl v19.8h, v19.8b \n" // a - "mul v22.8h, v16.8h, v0.h[0] \n" // B = B * Matrix B - "mul v23.8h, v16.8h, v0.h[4] \n" // G = B * Matrix G - "mul v24.8h, v16.8h, v1.h[0] \n" // R = B * Matrix R - "mul v25.8h, v16.8h, v1.h[4] \n" // A = B * Matrix A - "mul v4.8h, v17.8h, v0.h[1] \n" // B += G * Matrix B - "mul v5.8h, v17.8h, v0.h[5] \n" // G += G * Matrix G - "mul v6.8h, v17.8h, v1.h[1] \n" // R += G * Matrix R - "mul v7.8h, v17.8h, v1.h[5] \n" // A += G * Matrix A - "sqadd v22.8h, v22.8h, v4.8h \n" // Accumulate B - "sqadd v23.8h, v23.8h, v5.8h \n" // Accumulate G - "sqadd v24.8h, v24.8h, v6.8h \n" // Accumulate R - "sqadd v25.8h, v25.8h, v7.8h \n" // Accumulate A - "mul v4.8h, v18.8h, v0.h[2] \n" // B += R * Matrix B - "mul v5.8h, v18.8h, v0.h[6] \n" // G += R * Matrix G - "mul v6.8h, v18.8h, v1.h[2] \n" // R += R * Matrix R - "mul v7.8h, v18.8h, v1.h[6] \n" // A += R * Matrix A - "sqadd v22.8h, v22.8h, v4.8h \n" // Accumulate B - "sqadd v23.8h, v23.8h, v5.8h \n" // Accumulate G - "sqadd v24.8h, v24.8h, v6.8h \n" // Accumulate R - "sqadd v25.8h, v25.8h, v7.8h \n" // Accumulate A - "mul v4.8h, v19.8h, v0.h[3] \n" // B += A * Matrix B - "mul v5.8h, v19.8h, v0.h[7] \n" // G += A * Matrix G - "mul v6.8h, v19.8h, v1.h[3] \n" // R += A * Matrix R - "mul v7.8h, v19.8h, v1.h[7] \n" // A += A * Matrix A - "sqadd v22.8h, v22.8h, v4.8h \n" // Accumulate B - "sqadd v23.8h, v23.8h, v5.8h \n" // Accumulate G - "sqadd v24.8h, v24.8h, v6.8h \n" // Accumulate R - "sqadd v25.8h, v25.8h, v7.8h \n" // Accumulate A - "sqshrun v16.8b, v22.8h, #6 \n" // 16 bit to 8 bit B - "sqshrun v17.8b, v23.8h, #6 \n" // 16 bit to 8 bit G - "sqshrun v18.8b, v24.8h, #6 \n" // 16 bit to 8 bit R - "sqshrun v19.8b, v25.8h, #6 \n" // 16 bit to 8 bit A - "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%1], #32 \n" // store 8 ARGB - "b.gt 1b \n" + "1: \n" + "ld4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%0], #32 \n" // load 8 ARGB + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "uxtl v16.8h, v16.8b \n" // b (0 .. 255) 16 bit + "prfm pldl1keep, [%0, 448] \n" + "uxtl v17.8h, v17.8b \n" // g + "uxtl v18.8h, v18.8b \n" // r + "uxtl v19.8h, v19.8b \n" // a + "mul v22.8h, v16.8h, v0.h[0] \n" // B = B * Matrix B + "mul v23.8h, v16.8h, v0.h[4] \n" // G = B * Matrix G + "mul v24.8h, v16.8h, v1.h[0] \n" // R = B * Matrix R + "mul v25.8h, v16.8h, v1.h[4] \n" // A = B * Matrix A + "mul v4.8h, v17.8h, v0.h[1] \n" // B += G * Matrix B + "mul v5.8h, v17.8h, v0.h[5] \n" // G += G * Matrix G + "mul v6.8h, v17.8h, v1.h[1] \n" // R += G * Matrix R + "mul v7.8h, v17.8h, v1.h[5] \n" // A += G * Matrix A + "sqadd v22.8h, v22.8h, v4.8h \n" // Accumulate B + "sqadd v23.8h, v23.8h, v5.8h \n" // Accumulate G + "sqadd v24.8h, v24.8h, v6.8h \n" // Accumulate R + "sqadd v25.8h, v25.8h, v7.8h \n" // Accumulate A + "mul v4.8h, v18.8h, v0.h[2] \n" // B += R * Matrix B + "mul v5.8h, v18.8h, v0.h[6] \n" // G += R * Matrix G + "mul v6.8h, v18.8h, v1.h[2] \n" // R += R * Matrix R + "mul v7.8h, v18.8h, v1.h[6] \n" // A += R * Matrix A + "sqadd v22.8h, v22.8h, v4.8h \n" // Accumulate B + "sqadd v23.8h, v23.8h, v5.8h \n" // Accumulate G + "sqadd v24.8h, v24.8h, v6.8h \n" // Accumulate R + "sqadd v25.8h, v25.8h, v7.8h \n" // Accumulate A + "mul v4.8h, v19.8h, v0.h[3] \n" // B += A * Matrix B + "mul v5.8h, v19.8h, v0.h[7] \n" // G += A * Matrix G + "mul v6.8h, v19.8h, v1.h[3] \n" // R += A * Matrix R + "mul v7.8h, v19.8h, v1.h[7] \n" // A += A * Matrix A + "sqadd v22.8h, v22.8h, v4.8h \n" // Accumulate B + "sqadd v23.8h, v23.8h, v5.8h \n" // Accumulate G + "sqadd v24.8h, v24.8h, v6.8h \n" // Accumulate R + "sqadd v25.8h, v25.8h, v7.8h \n" // Accumulate A + "sqshrun v16.8b, v22.8h, #6 \n" // 16 bit to 8 bit B + "sqshrun v17.8b, v23.8h, #6 \n" // 16 bit to 8 bit G + "sqshrun v18.8b, v24.8h, #6 \n" // 16 bit to 8 bit R + "sqshrun v19.8b, v25.8h, #6 \n" // 16 bit to 8 bit A + "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%1], #32 \n" // store 8 ARGB + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(width) // %2 @@ -2417,29 +4265,86 @@ void ARGBColorMatrixRow_NEON(const uint8_t* src_argb, "v17", "v18", "v19", "v22", "v23", "v24", "v25"); } -// TODO(fbarchard): fix vqshrun in ARGBMultiplyRow_NEON and reenable. +void ARGBColorMatrixRow_NEON_I8MM(const uint8_t* src_argb, + uint8_t* dst_argb, + const int8_t* matrix_argb, + int width) { + asm volatile( + "ld1 {v31.16b}, [%[matrix_argb]] \n" + + "1: \n" + "ld1 {v0.16b, v1.16b}, [%[src_argb]], #32 \n" + "subs %w2, %w2, #8 \n" // 8 processed per loop. + + "movi v16.4s, #0 \n" + "movi v17.4s, #0 \n" + "movi v18.4s, #0 \n" + "movi v19.4s, #0 \n" + "movi v20.4s, #0 \n" + "movi v21.4s, #0 \n" + "movi v22.4s, #0 \n" + "movi v23.4s, #0 \n" + + "prfm pldl1keep, [%[src_argb], 448] \n" + + "sudot v16.4s, v31.16b, v0.4b[0] \n" + "sudot v17.4s, v31.16b, v0.4b[1] \n" + "sudot v18.4s, v31.16b, v0.4b[2] \n" + "sudot v19.4s, v31.16b, v0.4b[3] \n" + "sudot v20.4s, v31.16b, v1.4b[0] \n" + "sudot v21.4s, v31.16b, v1.4b[1] \n" + "sudot v22.4s, v31.16b, v1.4b[2] \n" + "sudot v23.4s, v31.16b, v1.4b[3] \n" + + "shrn v16.4h, v16.4s, #6 \n" + "shrn v18.4h, v18.4s, #6 \n" + "shrn v20.4h, v20.4s, #6 \n" + "shrn v22.4h, v22.4s, #6 \n" + "shrn2 v16.8h, v17.4s, #6 \n" + "shrn2 v18.8h, v19.4s, #6 \n" + "shrn2 v20.8h, v21.4s, #6 \n" + "shrn2 v22.8h, v23.4s, #6 \n" + + "uqxtn v16.8b, v16.8h \n" + "uqxtn v18.8b, v18.8h \n" + "uqxtn v20.8b, v20.8h \n" + "uqxtn v22.8b, v22.8h \n" + + "stp d16, d18, [%[dst_argb]], #16 \n" + "stp d20, d22, [%[dst_argb]], #16 \n" + "b.gt 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width) // %[width] + : [matrix_argb] "r"(matrix_argb) // %[matrix_argb] + : "cc", "memory", "v0", "v1", "v16", "v17", "v18", "v19", "v20", "v21", + "v22", "v23", "v31"); +} + // Multiply 2 rows of ARGB pixels together, 8 pixels at a time. -void ARGBMultiplyRow_NEON(const uint8_t* src_argb0, +void ARGBMultiplyRow_NEON(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( // 8 pixel loop. - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB - "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load 8 more - "subs %w3, %w3, #8 \n" // 8 processed per loop. - "umull v0.8h, v0.8b, v4.8b \n" // multiply B - "umull v1.8h, v1.8b, v5.8b \n" // multiply G - "umull v2.8h, v2.8b, v6.8b \n" // multiply R - "umull v3.8h, v3.8b, v7.8b \n" // multiply A - "rshrn v0.8b, v0.8h, #8 \n" // 16 bit to 8 bit B - "rshrn v1.8b, v1.8h, #8 \n" // 16 bit to 8 bit G - "rshrn v2.8b, v2.8h, #8 \n" // 16 bit to 8 bit R - "rshrn v3.8b, v3.8h, #8 \n" // 16 bit to 8 bit A - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB - "b.gt 1b \n" - : "+r"(src_argb0), // %0 + "1: \n" + "ld1 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB + "ld1 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load 8 more + "subs %w3, %w3, #8 \n" // 8 processed per loop. + "umull v0.8h, v0.8b, v4.8b \n" // multiply B + "prfm pldl1keep, [%0, 448] \n" + "umull v1.8h, v1.8b, v5.8b \n" // multiply G + "prfm pldl1keep, [%1, 448] \n" + "umull v2.8h, v2.8b, v6.8b \n" // multiply R + "umull v3.8h, v3.8b, v7.8b \n" // multiply A + "rshrn v0.8b, v0.8h, #8 \n" // 16 bit to 8 bit B + "rshrn v1.8b, v1.8h, #8 \n" // 16 bit to 8 bit G + "rshrn v2.8b, v2.8h, #8 \n" // 16 bit to 8 bit R + "rshrn v3.8b, v3.8h, #8 \n" // 16 bit to 8 bit A + "st1 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB + "b.gt 1b \n" + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -2448,23 +4353,23 @@ void ARGBMultiplyRow_NEON(const uint8_t* src_argb0, } // Add 2 rows of ARGB pixels together, 8 pixels at a time. -void ARGBAddRow_NEON(const uint8_t* src_argb0, +void ARGBAddRow_NEON(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( // 8 pixel loop. - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB - "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load 8 more - "subs %w3, %w3, #8 \n" // 8 processed per loop. - "uqadd v0.8b, v0.8b, v4.8b \n" - "uqadd v1.8b, v1.8b, v5.8b \n" - "uqadd v2.8b, v2.8b, v6.8b \n" - "uqadd v3.8b, v3.8b, v7.8b \n" - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB - "b.gt 1b \n" - : "+r"(src_argb0), // %0 + "1: \n" + "ldp q0, q1, [%0], #32 \n" // load 8 ARGB + "ldp q4, q5, [%1], #32 \n" // load 8 more + "subs %w3, %w3, #8 \n" // 8 processed per loop. + "prfm pldl1keep, [%0, 448] \n" + "prfm pldl1keep, [%1, 448] \n" + "uqadd v0.16b, v0.16b, v4.16b \n" + "uqadd v1.16b, v1.16b, v5.16b \n" + "stp q0, q1, [%2], #32 \n" // store 8 ARGB + "b.gt 1b \n" + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -2473,23 +4378,23 @@ void ARGBAddRow_NEON(const uint8_t* src_argb0, } // Subtract 2 rows of ARGB pixels, 8 pixels at a time. -void ARGBSubtractRow_NEON(const uint8_t* src_argb0, +void ARGBSubtractRow_NEON(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) { asm volatile( // 8 pixel loop. - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB - "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load 8 more - "subs %w3, %w3, #8 \n" // 8 processed per loop. - "uqsub v0.8b, v0.8b, v4.8b \n" - "uqsub v1.8b, v1.8b, v5.8b \n" - "uqsub v2.8b, v2.8b, v6.8b \n" - "uqsub v3.8b, v3.8b, v7.8b \n" - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB - "b.gt 1b \n" - : "+r"(src_argb0), // %0 + "1: \n" + "ldp q0, q1, [%0], #32 \n" // load 8 ARGB + "ldp q4, q5, [%1], #32 \n" // load 8 more + "subs %w3, %w3, #8 \n" // 8 processed per loop. + "prfm pldl1keep, [%0, 448] \n" + "prfm pldl1keep, [%1, 448] \n" + "uqsub v0.16b, v0.16b, v4.16b \n" + "uqsub v1.16b, v1.16b, v5.16b \n" + "stp q0, q1, [%2], #32 \n" // store 8 ARGB + "b.gt 1b \n" + : "+r"(src_argb), // %0 "+r"(src_argb1), // %1 "+r"(dst_argb), // %2 "+r"(width) // %3 @@ -2497,6 +4402,68 @@ void ARGBSubtractRow_NEON(const uint8_t* src_argb0, : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); } +// Blend 32 pixels at a time. +// dst = (((a) * src0) + ((255 - a) * src1) + 255) >> 8 +void BlendPlaneRow_NEON(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width) { + asm volatile( + "movi v15.8h, #255 \n" + "subs %w4, %w4, #32 \n" + "blt 19f \n" + "1: \n" + "ld1 {v0.16b, v1.16b}, [%0], #32 \n" // load 32 src0 + "ld1 {v2.16b, v3.16b}, [%1], #32 \n" // load 32 src1 + "ld1 {v4.16b, v5.16b}, [%2], #32 \n" // load 32 alpha + "subs %w4, %w4, #32 \n" // 32 processed per loop + "mvn v6.16b, v4.16b \n" // 255 - alpha0 + "mvn v7.16b, v5.16b \n" // 255 - alpha1 + "umull v8.8h, v0.8b, v4.8b \n" // low src0 * alpha + "prfm pldl1keep, [%0, 448] \n" + "umull2 v9.8h, v0.16b, v4.16b \n" // high src0 * alpha + "prfm pldl1keep, [%1, 448] \n" + "umull v10.8h, v1.8b, v5.8b \n" + "prfm pldl1keep, [%2, 448] \n" + "umull2 v11.8h, v1.16b, v5.16b \n" + "umlal v8.8h, v2.8b, v6.8b \n" // low + src1 * (255 - + // alpha) + "umlal2 v9.8h, v2.16b, v6.16b \n" // high + src1 * (255 - + // alpha) + "umlal v10.8h, v3.8b, v7.8b \n" + "umlal2 v11.8h, v3.16b, v7.16b \n" + "addhn v0.8b, v8.8h, v15.8h \n" // (low + 255) >> 8 + "addhn v1.8b, v9.8h, v15.8h \n" // (high + 255) >> 8 + "addhn v2.8b, v10.8h, v15.8h \n" + "addhn v3.8b, v11.8h, v15.8h \n" + "st1 {v0.8b, v1.8b, v2.8b, v3.8b}, [%3], #32 \n" // store 32 dst + "b.ge 1b \n" + "19: \n" + "adds %w4, %w4, #32 \n" + "b.le 99f \n" + + // 16 pixel tail + "ld1 {v0.16b}, [%0], #16 \n" // load 16 src0 + "ld1 {v1.16b}, [%1], #16 \n" // load 16 src1 + "ld1 {v2.16b}, [%2], #16 \n" // load 16 alpha + "mvn v3.16b, v2.16b \n" // 255 - alpha + "umull v4.8h, v0.8b, v2.8b \n" // low src0 * alpha + "umull2 v5.8h, v0.16b, v2.16b \n" // high src0 * alpha + "umlal v4.8h, v1.8b, v3.8b \n" // low + src1 * (255 - + // alpha) + "umlal2 v5.8h, v1.16b, v3.16b \n" // high + src1 * (255 - + // alpha) + "addhn v0.8b, v4.8h, v15.8h \n" // (low + 255) >> 8 + "addhn v1.8b, v5.8h, v15.8h \n" // (high + 255) >> 8 + "st1 {v0.8b, v1.8b}, [%3], #16 \n" // store 16 dst + "99: \n" + : "+r"(src0), "+r"(src1), "+r"(alpha), "+r"(dst), "+r"(width) + : + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", + "v9", "v10", "v11", "v15"); +} + // Adds Sobel X and Sobel Y and stores Sobel into ARGB. // A = 255 // R = Sobel @@ -2507,17 +4474,19 @@ void SobelRow_NEON(const uint8_t* src_sobelx, uint8_t* dst_argb, int width) { asm volatile( - "movi v3.8b, #255 \n" // alpha + "movi v3.8b, #255 \n" // alpha // 8 pixel loop. - "1: \n" - "ld1 {v0.8b}, [%0], #8 \n" // load 8 sobelx. - "ld1 {v1.8b}, [%1], #8 \n" // load 8 sobely. - "subs %w3, %w3, #8 \n" // 8 processed per loop. - "uqadd v0.8b, v0.8b, v1.8b \n" // add - "orr v1.8b, v0.8b, v0.8b \n" - "orr v2.8b, v0.8b, v0.8b \n" - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB - "b.gt 1b \n" + "1: \n" + "ld1 {v0.8b}, [%0], #8 \n" // load 8 sobelx. + "ld1 {v1.8b}, [%1], #8 \n" // load 8 sobely. + "subs %w3, %w3, #8 \n" // 8 processed per loop. + "uqadd v0.8b, v0.8b, v1.8b \n" // add + "prfm pldl1keep, [%0, 448] \n" + "mov v1.8b, v0.8b \n" + "prfm pldl1keep, [%1, 448] \n" + "mov v2.8b, v0.8b \n" + "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB + "b.gt 1b \n" : "+r"(src_sobelx), // %0 "+r"(src_sobely), // %1 "+r"(dst_argb), // %2 @@ -2533,13 +4502,15 @@ void SobelToPlaneRow_NEON(const uint8_t* src_sobelx, int width) { asm volatile( // 16 pixel loop. - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load 16 sobelx. - "ld1 {v1.16b}, [%1], #16 \n" // load 16 sobely. - "subs %w3, %w3, #16 \n" // 16 processed per loop. - "uqadd v0.16b, v0.16b, v1.16b \n" // add - "st1 {v0.16b}, [%2], #16 \n" // store 16 pixels. - "b.gt 1b \n" + "1: \n" + "ld1 {v0.16b}, [%0], #16 \n" // load 16 sobelx. + "ld1 {v1.16b}, [%1], #16 \n" // load 16 sobely. + "subs %w3, %w3, #16 \n" // 16 processed per loop. + "prfm pldl1keep, [%0, 448] \n" + "uqadd v0.16b, v0.16b, v1.16b \n" // add + "prfm pldl1keep, [%1, 448] \n" + "st1 {v0.16b}, [%2], #16 \n" // store 16 pixels. + "b.gt 1b \n" : "+r"(src_sobelx), // %0 "+r"(src_sobely), // %1 "+r"(dst_y), // %2 @@ -2558,15 +4529,17 @@ void SobelXYRow_NEON(const uint8_t* src_sobelx, uint8_t* dst_argb, int width) { asm volatile( - "movi v3.8b, #255 \n" // alpha + "movi v3.8b, #255 \n" // alpha // 8 pixel loop. - "1: \n" - "ld1 {v2.8b}, [%0], #8 \n" // load 8 sobelx. - "ld1 {v0.8b}, [%1], #8 \n" // load 8 sobely. - "subs %w3, %w3, #8 \n" // 8 processed per loop. - "uqadd v1.8b, v0.8b, v2.8b \n" // add - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB - "b.gt 1b \n" + "1: \n" + "ld1 {v2.8b}, [%0], #8 \n" // load 8 sobelx. + "ld1 {v0.8b}, [%1], #8 \n" // load 8 sobely. + "subs %w3, %w3, #8 \n" // 8 processed per loop. + "prfm pldl1keep, [%0, 448] \n" + "uqadd v1.8b, v0.8b, v2.8b \n" // add + "prfm pldl1keep, [%1, 448] \n" + "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB + "b.gt 1b \n" : "+r"(src_sobelx), // %0 "+r"(src_sobely), // %1 "+r"(dst_argb), // %2 @@ -2575,6 +4548,214 @@ void SobelXYRow_NEON(const uint8_t* src_sobelx, : "cc", "memory", "v0", "v1", "v2", "v3"); } +#ifdef HAS_COMPUTECUMULATIVESUMROW_NEON +void ComputeCumulativeSumRow_NEON(const uint8_t* row, + int32_t* cumsum, + const int32_t* previous_cumsum, + int width) { + asm volatile( + "movi v0.4s, #0 \n" + "movi v1.16b, #0 \n" + "subs %w3, %w3, #4 \n" + "b.lt 49f \n" + + // 4 pixel loop. + "40: \n" + "ldr q2, [%0], #16 \n" + "ldp q16, q17, [%2] \n" + "ldp q18, q19, [%2, #32] \n" + "add %2, %2, #64 \n" + "ext v3.16b, v1.16b, v2.16b, #12 \n" + "uaddl v4.8h, v2.8b, v3.8b \n" + "uaddl2 v5.8h, v2.16b, v3.16b \n" + "add v5.8h, v5.8h, v4.8h \n" + "uaddw v16.4s, v16.4s, v4.4h \n" + "uaddw2 v17.4s, v17.4s, v4.8h \n" + "uaddw v18.4s, v18.4s, v5.4h \n" + "uaddw2 v19.4s, v19.4s, v5.8h \n" + "add v16.4s, v16.4s, v0.4s \n" + "add v17.4s, v17.4s, v0.4s \n" + "add v18.4s, v18.4s, v0.4s \n" + "add v19.4s, v19.4s, v0.4s \n" + "uaddw2 v0.4s, v0.4s, v5.8h \n" + "stp q16, q17, [%1] \n" + "stp q18, q19, [%1, #32] \n" + "add %1, %1, #64 \n" + "subs %w3, %w3, #4 \n" + "b.ge 40b \n" + + "49: \n" + "adds %w3, %w3, #3 \n" + "b.lt 19f \n" + + // 1 pixel loop. + "10: \n" + "ldr s2, [%0], #4 \n" + "ldr q16, [%2], #16 \n" + "ushll v2.8h, v2.8b, #0 \n" + "uaddw v0.4s, v0.4s, v2.4h \n" + "add v16.4s, v16.4s, v0.4s \n" + "str q16, [%1], #16 \n" + "subs %w3, %w3, #1 \n" + "b.ge 10b \n" + + "19: \n" + : "+r"(row), // %0 + "+r"(cumsum), // %1 + "+r"(previous_cumsum), // %2 + "+r"(width) // %3 + : + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v16", "v17", "v18", + "v19"); +} +#endif // HAS_COMPUTECUMULATIVESUMROW_NEON + +#ifdef HAS_CUMULATIVESUMTOAVERAGEROW_NEON +void CumulativeSumToAverageRow_NEON(const int32_t* topleft, + const int32_t* botleft, + int width, + int area, + uint8_t* dst, + int count) { + const int32_t* topright; + const int32_t* botright; + int scale; + asm volatile( + "ucvtf s4, %w7 \n" + "fmov s5, #1.0 \n" + "fdiv s4, s5, s4 \n" + "subs %w3, %w3, #4 \n" + "b.lt 49f \n" + "add %4, %0, %8 \n" + "add %5, %1, %8 \n" + "sub %w6, %w7, #2 \n" + "cmp %w6, #126 \n" + "b.hi 40f \n" + "mov %w6, #32767 \n" + "add %w6, %w6, %w7 \n" + "udiv %w6, %w6, %w7 \n" + "dup v6.8h, %w6 \n" + + // 4 pixel small loop. + "4: \n" + "ldp q0, q1, [%0] \n" + "ldp q2, q3, [%0, #32] \n" + "add %0, %0, #64 \n" + "ldp q16, q17, [%4] \n" + "ldp q18, q19, [%4, #32] \n" + "add %4, %4, #64 \n" + "ldp q20, q21, [%1] \n" + "ldp q22, q23, [%1, #32] \n" + "add %1, %1, #64 \n" + "ldp q24, q25, [%5] \n" + "ldp q26, q27, [%5, #32] \n" + "add %5, %5, #64 \n" + "sub v0.4s, v0.4s, v16.4s \n" + "sub v1.4s, v1.4s, v17.4s \n" + "sub v2.4s, v2.4s, v18.4s \n" + "sub v3.4s, v3.4s, v19.4s \n" + "sub v24.4s, v24.4s, v20.4s \n" + "sub v25.4s, v25.4s, v21.4s \n" + "sub v26.4s, v26.4s, v22.4s \n" + "sub v27.4s, v27.4s, v23.4s \n" + "add v0.4s, v0.4s, v24.4s \n" + "add v1.4s, v1.4s, v25.4s \n" + "add v2.4s, v2.4s, v26.4s \n" + "add v3.4s, v3.4s, v27.4s \n" + "uzp1 v0.8h, v0.8h, v1.8h \n" + "uzp1 v2.8h, v2.8h, v3.8h \n" + "sqdmulh v0.8h, v0.8h, v6.8h \n" + "sqdmulh v2.8h, v2.8h, v6.8h \n" + "uzp1 v0.16b, v0.16b, v2.16b \n" + "str q0, [%2], #16 \n" + "subs %w3, %w3, #4 \n" + "b.ge 4b \n" + "b 49f \n" + + // 4 pixel loop. + "40: \n" + "ldp q0, q1, [%0] \n" + "ldp q2, q3, [%0, #32] \n" + "add %0, %0, #64 \n" + "ldp q16, q17, [%4] \n" + "ldp q18, q19, [%4, #32] \n" + "add %4, %4, #64 \n" + "ldp q20, q21, [%1] \n" + "ldp q22, q23, [%1, #32] \n" + "add %1, %1, #64 \n" + "ldp q24, q25, [%5] \n" + "ldp q26, q27, [%5, #32] \n" + "add %5, %5, #64 \n" + "sub v0.4s, v0.4s, v16.4s \n" + "sub v1.4s, v1.4s, v17.4s \n" + "sub v2.4s, v2.4s, v18.4s \n" + "sub v3.4s, v3.4s, v19.4s \n" + "sub v24.4s, v24.4s, v20.4s \n" + "sub v25.4s, v25.4s, v21.4s \n" + "sub v26.4s, v26.4s, v22.4s \n" + "sub v27.4s, v27.4s, v23.4s \n" + "add v0.4s, v0.4s, v24.4s \n" + "add v1.4s, v1.4s, v25.4s \n" + "add v2.4s, v2.4s, v26.4s \n" + "add v3.4s, v3.4s, v27.4s \n" + "scvtf v0.4s, v0.4s \n" + "scvtf v1.4s, v1.4s \n" + "scvtf v2.4s, v2.4s \n" + "scvtf v3.4s, v3.4s \n" + "fmul v0.4s, v0.4s, v4.s[0] \n" + "fmul v1.4s, v1.4s, v4.s[0] \n" + "fmul v2.4s, v2.4s, v4.s[0] \n" + "fmul v3.4s, v3.4s, v4.s[0] \n" + "fcvtzs v0.4s, v0.4s \n" + "fcvtzs v1.4s, v1.4s \n" + "fcvtzs v2.4s, v2.4s \n" + "fcvtzs v3.4s, v3.4s \n" + "uqxtn v0.4h, v0.4s \n" + "uqxtn2 v0.8h, v1.4s \n" + "uqxtn v2.4h, v2.4s \n" + "uqxtn2 v2.8h, v3.4s \n" + "uqxtn v0.8b, v0.8h \n" + "uqxtn2 v0.16b, v2.8h \n" + "str q0, [%2], #16 \n" + "subs %w3, %w3, #4 \n" + "b.ge 40b \n" + + "49: \n" + "adds %w3, %w3, #3 \n" + "b.lt 19f \n" + + // 1 pixel loop. + "10: \n" + "ldr q1, [%0, %8] \n" + "ldr q0, [%0], #16 \n" + "ldr q3, [%1, %8] \n" + "ldr q2, [%1], #16 \n" + "sub v0.4s, v0.4s, v1.4s \n" + "sub v3.4s, v3.4s, v2.4s \n" + "add v0.4s, v0.4s, v3.4s \n" + "scvtf v0.4s, v0.4s \n" + "fmul v0.4s, v0.4s, v4.s[0] \n" + "fcvtzs v0.4s, v0.4s \n" + "uqxtn v0.4h, v0.4s \n" + "uqxtn v0.8b, v0.8h \n" + "str s0, [%2], #4 \n" + "subs %w3, %w3, #1 \n" + "b.ge 10b \n" + "19: \n" + : "+r"(topleft), // %0 + "+r"(botleft), // %1 + "+r"(dst), // %2 + "+r"(count), // %3 + "=&r"(topright), // %4 + "=&r"(botright), // %5 + "=&r"(scale) // %6 + : "r"(area), // %7 + "r"((ptrdiff_t)width * 4) // %8 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v16", "v17", + "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27"); +} +#endif // HAS_CUMULATIVESUMTOAVERAGEROW_NEON + // SobelX as a matrix is // -1 0 1 // -2 0 2 @@ -2585,24 +4766,27 @@ void SobelXRow_NEON(const uint8_t* src_y0, uint8_t* dst_sobelx, int width) { asm volatile( - "1: \n" - "ld1 {v0.8b}, [%0],%5 \n" // top - "ld1 {v1.8b}, [%0],%6 \n" - "usubl v0.8h, v0.8b, v1.8b \n" - "ld1 {v2.8b}, [%1],%5 \n" // center * 2 - "ld1 {v3.8b}, [%1],%6 \n" - "usubl v1.8h, v2.8b, v3.8b \n" - "add v0.8h, v0.8h, v1.8h \n" - "add v0.8h, v0.8h, v1.8h \n" - "ld1 {v2.8b}, [%2],%5 \n" // bottom - "ld1 {v3.8b}, [%2],%6 \n" - "subs %w4, %w4, #8 \n" // 8 pixels - "usubl v1.8h, v2.8b, v3.8b \n" - "add v0.8h, v0.8h, v1.8h \n" - "abs v0.8h, v0.8h \n" - "uqxtn v0.8b, v0.8h \n" - "st1 {v0.8b}, [%3], #8 \n" // store 8 sobelx - "b.gt 1b \n" + "1: \n" + "ld1 {v0.8b}, [%0],%5 \n" // top + "ld1 {v1.8b}, [%0],%6 \n" + "subs %w4, %w4, #8 \n" // 8 pixels + "usubl v0.8h, v0.8b, v1.8b \n" + "prfm pldl1keep, [%0, 448] \n" + "ld1 {v2.8b}, [%1],%5 \n" // center * 2 + "ld1 {v3.8b}, [%1],%6 \n" + "usubl v1.8h, v2.8b, v3.8b \n" + "prfm pldl1keep, [%1, 448] \n" + "add v0.8h, v0.8h, v1.8h \n" + "add v0.8h, v0.8h, v1.8h \n" + "ld1 {v2.8b}, [%2],%5 \n" // bottom + "ld1 {v3.8b}, [%2],%6 \n" + "prfm pldl1keep, [%2, 448] \n" + "usubl v1.8h, v2.8b, v3.8b \n" + "add v0.8h, v0.8h, v1.8h \n" + "abs v0.8h, v0.8h \n" + "uqxtn v0.8b, v0.8h \n" + "st1 {v0.8b}, [%3], #8 \n" // store 8 sobelx + "b.gt 1b \n" : "+r"(src_y0), // %0 "+r"(src_y1), // %1 "+r"(src_y2), // %2 @@ -2623,24 +4807,26 @@ void SobelYRow_NEON(const uint8_t* src_y0, uint8_t* dst_sobely, int width) { asm volatile( - "1: \n" - "ld1 {v0.8b}, [%0],%4 \n" // left - "ld1 {v1.8b}, [%1],%4 \n" - "usubl v0.8h, v0.8b, v1.8b \n" - "ld1 {v2.8b}, [%0],%4 \n" // center * 2 - "ld1 {v3.8b}, [%1],%4 \n" - "usubl v1.8h, v2.8b, v3.8b \n" - "add v0.8h, v0.8h, v1.8h \n" - "add v0.8h, v0.8h, v1.8h \n" - "ld1 {v2.8b}, [%0],%5 \n" // right - "ld1 {v3.8b}, [%1],%5 \n" - "subs %w3, %w3, #8 \n" // 8 pixels - "usubl v1.8h, v2.8b, v3.8b \n" - "add v0.8h, v0.8h, v1.8h \n" - "abs v0.8h, v0.8h \n" - "uqxtn v0.8b, v0.8h \n" - "st1 {v0.8b}, [%2], #8 \n" // store 8 sobely - "b.gt 1b \n" + "1: \n" + "ld1 {v0.8b}, [%0],%4 \n" // left + "ld1 {v1.8b}, [%1],%4 \n" + "subs %w3, %w3, #8 \n" // 8 pixels + "usubl v0.8h, v0.8b, v1.8b \n" + "ld1 {v2.8b}, [%0],%4 \n" // center * 2 + "ld1 {v3.8b}, [%1],%4 \n" + "usubl v1.8h, v2.8b, v3.8b \n" + "add v0.8h, v0.8h, v1.8h \n" + "add v0.8h, v0.8h, v1.8h \n" + "ld1 {v2.8b}, [%0],%5 \n" // right + "ld1 {v3.8b}, [%1],%5 \n" + "usubl v1.8h, v2.8b, v3.8b \n" + "prfm pldl1keep, [%0, 448] \n" + "add v0.8h, v0.8h, v1.8h \n" + "prfm pldl1keep, [%1, 448] \n" + "abs v0.8h, v0.8h \n" + "uqxtn v0.8b, v0.8h \n" + "st1 {v0.8b}, [%2], #8 \n" // store 8 sobely + "b.gt 1b \n" : "+r"(src_y0), // %0 "+r"(src_y1), // %1 "+r"(dst_sobely), // %2 @@ -2651,53 +4837,43 @@ void SobelYRow_NEON(const uint8_t* src_y0, ); } -// Caveat - rounds float to half float whereas scaling version truncates. -void HalfFloat1Row_NEON(const uint16_t* src, - uint16_t* dst, - float /*unused*/, - int width) { - asm volatile( - "1: \n" - "ld1 {v1.16b}, [%0], #16 \n" // load 8 shorts - "subs %w2, %w2, #8 \n" // 8 pixels per loop - "uxtl v2.4s, v1.4h \n" // 8 int's - "uxtl2 v3.4s, v1.8h \n" - "scvtf v2.4s, v2.4s \n" // 8 floats - "scvtf v3.4s, v3.4s \n" - "fcvtn v1.4h, v2.4s \n" // 8 half floats - "fcvtn2 v1.8h, v3.4s \n" - "st1 {v1.16b}, [%1], #16 \n" // store 8 shorts - "b.gt 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : - : "cc", "memory", "v1", "v2", "v3"); -} - void HalfFloatRow_NEON(const uint16_t* src, uint16_t* dst, float scale, int width) { asm volatile( - "1: \n" - "ld1 {v1.16b}, [%0], #16 \n" // load 8 shorts - "subs %w2, %w2, #8 \n" // 8 pixels per loop - "uxtl v2.4s, v1.4h \n" // 8 int's - "uxtl2 v3.4s, v1.8h \n" - "scvtf v2.4s, v2.4s \n" // 8 floats - "scvtf v3.4s, v3.4s \n" - "fmul v2.4s, v2.4s, %3.s[0] \n" // adjust exponent - "fmul v3.4s, v3.4s, %3.s[0] \n" - "uqshrn v1.4h, v2.4s, #13 \n" // isolate halffloat - "uqshrn2 v1.8h, v3.4s, #13 \n" - "st1 {v1.16b}, [%1], #16 \n" // store 8 shorts - "b.gt 1b \n" - : "+r"(src), // %0 - "+r"(dst), // %1 - "+r"(width) // %2 - : "w"(scale * 1.9259299444e-34f) // %3 - : "cc", "memory", "v1", "v2", "v3"); + "1: \n" + "ldp q0, q1, [%0], #32 \n" // load 16 shorts + "subs %w2, %w2, #16 \n" // 16 pixels per loop + "uxtl v2.4s, v0.4h \n" + "uxtl v4.4s, v1.4h \n" + "uxtl2 v3.4s, v0.8h \n" + "uxtl2 v5.4s, v1.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "scvtf v2.4s, v2.4s \n" + "scvtf v4.4s, v4.4s \n" + "scvtf v3.4s, v3.4s \n" + "scvtf v5.4s, v5.4s \n" + "fmul v2.4s, v2.4s, %3.s[0] \n" // * scale + "fmul v4.4s, v4.4s, %3.s[0] \n" + "fmul v3.4s, v3.4s, %3.s[0] \n" + "fmul v5.4s, v5.4s, %3.s[0] \n" + "fmul v2.4s, v2.4s, %4.s[0] \n" // adjust exponent + "fmul v4.4s, v4.4s, %4.s[0] \n" + "fmul v3.4s, v3.4s, %4.s[0] \n" + "fmul v5.4s, v5.4s, %4.s[0] \n" + "uqshrn v0.4h, v2.4s, #13 \n" // isolate halffloat + "uqshrn v1.4h, v4.4s, #13 \n" + "uqshrn2 v0.8h, v3.4s, #13 \n" + "uqshrn2 v1.8h, v5.4s, #13 \n" + "stp q0, q1, [%1], #32 \n" // store 16 fp16 + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "w"(scale), // %3 + "w"(1.9259299444e-34f) // %4 2^-112, see HalfFloatRow_C + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5"); } void ByteToFloatRow_NEON(const uint8_t* src, @@ -2705,18 +4881,19 @@ void ByteToFloatRow_NEON(const uint8_t* src, float scale, int width) { asm volatile( - "1: \n" - "ld1 {v1.8b}, [%0], #8 \n" // load 8 bytes - "subs %w2, %w2, #8 \n" // 8 pixels per loop - "uxtl v1.8h, v1.8b \n" // 8 shorts - "uxtl v2.4s, v1.4h \n" // 8 ints - "uxtl2 v3.4s, v1.8h \n" - "scvtf v2.4s, v2.4s \n" // 8 floats - "scvtf v3.4s, v3.4s \n" - "fmul v2.4s, v2.4s, %3.s[0] \n" // scale - "fmul v3.4s, v3.4s, %3.s[0] \n" - "st1 {v2.16b, v3.16b}, [%1], #32 \n" // store 8 floats - "b.gt 1b \n" + "1: \n" + "ld1 {v1.8b}, [%0], #8 \n" // load 8 bytes + "subs %w2, %w2, #8 \n" // 8 pixels per loop + "uxtl v1.8h, v1.8b \n" // 8 shorts + "prfm pldl1keep, [%0, 448] \n" + "uxtl v2.4s, v1.4h \n" // 8 ints + "uxtl2 v3.4s, v1.8h \n" + "scvtf v2.4s, v2.4s \n" // 8 floats + "scvtf v3.4s, v3.4s \n" + "fmul v2.4s, v2.4s, %3.s[0] \n" // scale + "fmul v3.4s, v3.4s, %3.s[0] \n" + "st1 {v2.16b, v3.16b}, [%1], #32 \n" // store 8 floats + "b.gt 1b \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -2724,26 +4901,108 @@ void ByteToFloatRow_NEON(const uint8_t* src, : "cc", "memory", "v1", "v2", "v3"); } +// Convert FP16 Half Floats to FP32 Floats +void ConvertFP16ToFP32Row_NEON(const uint16_t* src, // fp16 + float* dst, + int width) { + asm volatile( + "1: \n" + "ld1 {v1.8h}, [%0], #16 \n" // load 8 halffloats + "subs %w2, %w2, #8 \n" // 8 floats per loop + "prfm pldl1keep, [%0, 448] \n" + "fcvtl v2.4s, v1.4h \n" // 8 floats + "fcvtl2 v3.4s, v1.8h \n" + "stp q2, q3, [%1], #32 \n" // store 8 floats + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : + : "cc", "memory", "v1", "v2", "v3"); +} + +// Convert FP16 Half Floats to FP32 Floats +// Read a column and write a row +void ConvertFP16ToFP32Column_NEON(const uint16_t* src, // fp16 + int src_stride, // stride in elements + float* dst, + int width) { + asm volatile( + "subs %w2, %w2, #8 \n" // Is there 8 rows? + "b.lt 2f \n" + "1: \n" + "ld1 {v0.h}[0], [%0], %3 \n" // load 8 halffloats + "ld1 {v0.h}[1], [%0], %3 \n" + "ld1 {v0.h}[2], [%0], %3 \n" + "ld1 {v0.h}[3], [%0], %3 \n" + "ld1 {v1.h}[0], [%0], %3 \n" + "ld1 {v1.h}[1], [%0], %3 \n" + "ld1 {v1.h}[2], [%0], %3 \n" + "ld1 {v1.h}[3], [%0], %3 \n" + "subs %w2, %w2, #8 \n" // 8 rows per loop + "prfm pldl1keep, [%0, 448] \n" + "fcvtl v2.4s, v0.4h \n" // 4 floats + "fcvtl v3.4s, v1.4h \n" // 4 more floats + "stp q2, q3, [%1], #32 \n" // store 8 floats + "b.ge 1b \n" + "2: \n" + "adds %w2, %w2, #8 \n" // Restore remainder. + "b.eq 3f \n" + "4: \n" + "ld1 {v1.h}[0], [%0], %3 \n" // load 1 halffloats + "subs %w2, %w2, #1 \n" // 1 floats per loop + "fcvtl v2.4s, v1.4h \n" // 1 floats + "str s2, [%1], #4 \n" // store 1 floats + "b.gt 4b \n" + "3: \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "r"((ptrdiff_t)src_stride * 2) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3"); +} + +// Convert FP32 Floats to FP16 Half Floats +void ConvertFP32ToFP16Row_NEON(const float* src, + uint16_t* dst, // fp16 + int width) { + asm volatile( + "1: \n" + "ldp q2, q3, [%0], #32 \n" // load 8 floats + "subs %w2, %w2, #8 \n" // 8 floats per loop + "prfm pldl1keep, [%0, 448] \n" + "fcvtn v1.4h, v2.4s \n" // 8 fp16 halffloats + "fcvtn2 v1.8h, v3.4s \n" + "str q1, [%1], #16 \n" // store 8 fp16 halffloats + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : + : "cc", "memory", "v1", "v2", "v3"); +} + float ScaleMaxSamples_NEON(const float* src, float* dst, float scale, int width) { float fmax; asm volatile( - "movi v5.4s, #0 \n" // max - "movi v6.4s, #0 \n" + "movi v5.4s, #0 \n" // max + "movi v6.4s, #0 \n" - "1: \n" - "ld1 {v1.4s, v2.4s}, [%0], #32 \n" // load 8 samples - "subs %w2, %w2, #8 \n" // 8 processed per loop - "fmul v3.4s, v1.4s, %4.s[0] \n" // scale - "fmul v4.4s, v2.4s, %4.s[0] \n" // scale - "fmax v5.4s, v5.4s, v1.4s \n" // max - "fmax v6.4s, v6.4s, v2.4s \n" - "st1 {v3.4s, v4.4s}, [%1], #32 \n" // store 8 samples - "b.gt 1b \n" - "fmax v5.4s, v5.4s, v6.4s \n" // max - "fmaxv %s3, v5.4s \n" // signed max acculator + "1: \n" + "ld1 {v1.4s, v2.4s}, [%0], #32 \n" // load 8 samples + "subs %w2, %w2, #8 \n" // 8 processed per loop + "fmul v3.4s, v1.4s, %4.s[0] \n" // scale + "prfm pldl1keep, [%0, 448] \n" + "fmul v4.4s, v2.4s, %4.s[0] \n" // scale + "fmax v5.4s, v5.4s, v1.4s \n" // max + "fmax v6.4s, v6.4s, v2.4s \n" + "st1 {v3.4s, v4.4s}, [%1], #32 \n" // store 8 samples + "b.gt 1b \n" + "fmax v5.4s, v5.4s, v6.4s \n" // max + "fmaxv %s3, v5.4s \n" // signed max acculator : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width), // %2 @@ -2759,21 +5018,22 @@ float ScaleSumSamples_NEON(const float* src, int width) { float fsum; asm volatile( - "movi v5.4s, #0 \n" // max - "movi v6.4s, #0 \n" // max + "movi v5.4s, #0 \n" // max + "movi v6.4s, #0 \n" // max - "1: \n" - "ld1 {v1.4s, v2.4s}, [%0], #32 \n" // load 8 samples - "subs %w2, %w2, #8 \n" // 8 processed per loop - "fmul v3.4s, v1.4s, %4.s[0] \n" // scale - "fmul v4.4s, v2.4s, %4.s[0] \n" - "fmla v5.4s, v1.4s, v1.4s \n" // sum of squares - "fmla v6.4s, v2.4s, v2.4s \n" - "st1 {v3.4s, v4.4s}, [%1], #32 \n" // store 8 samples - "b.gt 1b \n" - "faddp v5.4s, v5.4s, v6.4s \n" - "faddp v5.4s, v5.4s, v5.4s \n" - "faddp %3.4s, v5.4s, v5.4s \n" // sum + "1: \n" + "ld1 {v1.4s, v2.4s}, [%0], #32 \n" // load 8 samples + "subs %w2, %w2, #8 \n" // 8 processed per loop + "fmul v3.4s, v1.4s, %4.s[0] \n" // scale + "prfm pldl1keep, [%0, 448] \n" + "fmul v4.4s, v2.4s, %4.s[0] \n" + "fmla v5.4s, v1.4s, v1.4s \n" // sum of squares + "fmla v6.4s, v2.4s, v2.4s \n" + "st1 {v3.4s, v4.4s}, [%1], #32 \n" // store 8 samples + "b.gt 1b \n" + "faddp v5.4s, v5.4s, v6.4s \n" + "faddp v5.4s, v5.4s, v5.4s \n" + "faddp %3.4s, v5.4s, v5.4s \n" // sum : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width), // %2 @@ -2785,13 +5045,14 @@ float ScaleSumSamples_NEON(const float* src, void ScaleSamples_NEON(const float* src, float* dst, float scale, int width) { asm volatile( - "1: \n" - "ld1 {v1.4s, v2.4s}, [%0], #32 \n" // load 8 samples - "subs %w2, %w2, #8 \n" // 8 processed per loop - "fmul v1.4s, v1.4s, %3.s[0] \n" // scale - "fmul v2.4s, v2.4s, %3.s[0] \n" // scale - "st1 {v1.4s, v2.4s}, [%1], #32 \n" // store 8 samples - "b.gt 1b \n" + "1: \n" + "ld1 {v1.4s, v2.4s}, [%0], #32 \n" // load 8 samples + "subs %w2, %w2, #8 \n" // 8 processed per loop + "prfm pldl1keep, [%0, 448] \n" + "fmul v1.4s, v1.4s, %3.s[0] \n" // scale + "fmul v2.4s, v2.4s, %3.s[0] \n" // scale + "st1 {v1.4s, v2.4s}, [%1], #32 \n" // store 8 samples + "b.gt 1b \n" : "+r"(src), // %0 "+r"(dst), // %1 "+r"(width) // %2 @@ -2808,26 +5069,31 @@ void GaussCol_NEON(const uint16_t* src0, uint32_t* dst, int width) { asm volatile( - "movi v6.8h, #4 \n" // constant 4 - "movi v7.8h, #6 \n" // constant 6 + "movi v6.8h, #4 \n" // constant 4 + "movi v7.8h, #6 \n" // constant 6 - "1: \n" - "ld1 {v1.8h}, [%0], #16 \n" // load 8 samples, 5 rows - "ld1 {v2.8h}, [%4], #16 \n" - "uaddl v0.4s, v1.4h, v2.4h \n" // * 1 - "uaddl2 v1.4s, v1.8h, v2.8h \n" // * 1 - "ld1 {v2.8h}, [%1], #16 \n" - "umlal v0.4s, v2.4h, v6.4h \n" // * 4 - "umlal2 v1.4s, v2.8h, v6.8h \n" // * 4 - "ld1 {v2.8h}, [%2], #16 \n" - "umlal v0.4s, v2.4h, v7.4h \n" // * 6 - "umlal2 v1.4s, v2.8h, v7.8h \n" // * 6 - "ld1 {v2.8h}, [%3], #16 \n" - "umlal v0.4s, v2.4h, v6.4h \n" // * 4 - "umlal2 v1.4s, v2.8h, v6.8h \n" // * 4 - "subs %w6, %w6, #8 \n" // 8 processed per loop - "st1 {v0.4s,v1.4s}, [%5], #32 \n" // store 8 samples - "b.gt 1b \n" + "1: \n" + "ld1 {v1.8h}, [%0], #16 \n" // load 8 samples, 5 rows + "ld1 {v2.8h}, [%4], #16 \n" + "subs %w6, %w6, #8 \n" // 8 processed per loop + "uaddl v0.4s, v1.4h, v2.4h \n" // * 1 + "prfm pldl1keep, [%0, 448] \n" + "uaddl2 v1.4s, v1.8h, v2.8h \n" // * 1 + "ld1 {v2.8h}, [%1], #16 \n" + "umlal v0.4s, v2.4h, v6.4h \n" // * 4 + "prfm pldl1keep, [%1, 448] \n" + "umlal2 v1.4s, v2.8h, v6.8h \n" // * 4 + "ld1 {v2.8h}, [%2], #16 \n" + "umlal v0.4s, v2.4h, v7.4h \n" // * 6 + "prfm pldl1keep, [%2, 448] \n" + "umlal2 v1.4s, v2.8h, v7.8h \n" // * 6 + "ld1 {v2.8h}, [%3], #16 \n" + "umlal v0.4s, v2.4h, v6.4h \n" // * 4 + "prfm pldl1keep, [%3, 448] \n" + "umlal2 v1.4s, v2.8h, v6.8h \n" // * 4 + "st1 {v0.4s,v1.4s}, [%5], #32 \n" // store 8 samples + "prfm pldl1keep, [%4, 448] \n" + "b.gt 1b \n" : "+r"(src0), // %0 "+r"(src1), // %1 "+r"(src2), // %2 @@ -2845,27 +5111,28 @@ void GaussRow_NEON(const uint32_t* src, uint16_t* dst, int width) { const uint32_t* src2 = src + 2; const uint32_t* src3 = src + 3; asm volatile( - "movi v6.4s, #4 \n" // constant 4 - "movi v7.4s, #6 \n" // constant 6 + "movi v6.4s, #4 \n" // constant 4 + "movi v7.4s, #6 \n" // constant 6 - "1: \n" - "ld1 {v0.4s,v1.4s,v2.4s}, [%0], %6 \n" // load 12 source samples - "add v0.4s, v0.4s, v1.4s \n" // * 1 - "add v1.4s, v1.4s, v2.4s \n" // * 1 - "ld1 {v2.4s,v3.4s}, [%2], #32 \n" - "mla v0.4s, v2.4s, v7.4s \n" // * 6 - "mla v1.4s, v3.4s, v7.4s \n" // * 6 - "ld1 {v2.4s,v3.4s}, [%1], #32 \n" - "ld1 {v4.4s,v5.4s}, [%3], #32 \n" - "add v2.4s, v2.4s, v4.4s \n" // add rows for * 4 - "add v3.4s, v3.4s, v5.4s \n" - "mla v0.4s, v2.4s, v6.4s \n" // * 4 - "mla v1.4s, v3.4s, v6.4s \n" // * 4 - "subs %w5, %w5, #8 \n" // 8 processed per loop - "uqrshrn v0.4h, v0.4s, #8 \n" // round and pack - "uqrshrn2 v0.8h, v1.4s, #8 \n" - "st1 {v0.8h}, [%4], #16 \n" // store 8 samples - "b.gt 1b \n" + "1: \n" + "ld1 {v0.4s,v1.4s,v2.4s}, [%0], %6 \n" // load 12 source samples + "subs %w5, %w5, #8 \n" // 8 processed per loop + "add v0.4s, v0.4s, v1.4s \n" // * 1 + "add v1.4s, v1.4s, v2.4s \n" // * 1 + "ld1 {v2.4s,v3.4s}, [%2], #32 \n" + "mla v0.4s, v2.4s, v7.4s \n" // * 6 + "mla v1.4s, v3.4s, v7.4s \n" // * 6 + "ld1 {v2.4s,v3.4s}, [%1], #32 \n" + "ld1 {v4.4s,v5.4s}, [%3], #32 \n" + "add v2.4s, v2.4s, v4.4s \n" // add rows for * 4 + "add v3.4s, v3.4s, v5.4s \n" + "prfm pldl1keep, [%0, 448] \n" + "mla v0.4s, v2.4s, v6.4s \n" // * 4 + "mla v1.4s, v3.4s, v6.4s \n" // * 4 + "uqrshrn v0.4h, v0.4s, #8 \n" // round and pack + "uqrshrn2 v0.8h, v1.4s, #8 \n" + "st1 {v0.8h}, [%4], #16 \n" // store 8 samples + "b.gt 1b \n" : "+r"(src), // %0 "+r"(src1), // %1 "+r"(src2), // %2 @@ -2876,20 +5143,104 @@ void GaussRow_NEON(const uint32_t* src, uint16_t* dst, int width) { : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); } +static const vecf32 kGaussCoefficients = {4.0f, 6.0f, 1.0f / 256.0f, 0.0f}; + +// filter 5 rows with 1, 4, 6, 4, 1 coefficients to produce 1 row. +void GaussCol_F32_NEON(const float* src0, + const float* src1, + const float* src2, + const float* src3, + const float* src4, + float* dst, + int width) { + asm volatile( + "ld2r {v6.4s, v7.4s}, [%7] \n" // constants 4 and 6 + + "1: \n" + "ld1 {v0.4s, v1.4s}, [%0], #32 \n" // load 8 samples, 5 rows + "ld1 {v2.4s, v3.4s}, [%1], #32 \n" + "subs %w6, %w6, #8 \n" // 8 processed per loop + "fmla v0.4s, v2.4s, v6.4s \n" // * 4 + "ld1 {v4.4s, v5.4s}, [%2], #32 \n" + "fmla v1.4s, v3.4s, v6.4s \n" + "prfm pldl1keep, [%0, 448] \n" + "fmla v0.4s, v4.4s, v7.4s \n" // * 6 + "ld1 {v2.4s, v3.4s}, [%3], #32 \n" + "fmla v1.4s, v5.4s, v7.4s \n" + "prfm pldl1keep, [%1, 448] \n" + "fmla v0.4s, v2.4s, v6.4s \n" // * 4 + "ld1 {v4.4s, v5.4s}, [%4], #32 \n" + "fmla v1.4s, v3.4s, v6.4s \n" + "prfm pldl1keep, [%2, 448] \n" + "fadd v0.4s, v0.4s, v4.4s \n" // * 1 + "prfm pldl1keep, [%3, 448] \n" + "fadd v1.4s, v1.4s, v5.4s \n" + "prfm pldl1keep, [%4, 448] \n" + "st1 {v0.4s, v1.4s}, [%5], #32 \n" // store 8 samples + "b.gt 1b \n" + : "+r"(src0), // %0 + "+r"(src1), // %1 + "+r"(src2), // %2 + "+r"(src3), // %3 + "+r"(src4), // %4 + "+r"(dst), // %5 + "+r"(width) // %6 + : "r"(&kGaussCoefficients) // %7 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); +} + +// filter 5 rows with 1, 4, 6, 4, 1 coefficients to produce 1 row. +void GaussRow_F32_NEON(const float* src, float* dst, int width) { + asm volatile( + "ld3r {v6.4s, v7.4s, v8.4s}, [%3] \n" // constants 4, 6, 1/256 + + "1: \n" + "ld1 {v0.4s, v1.4s, v2.4s}, [%0], %4 \n" // load 12 samples, 5 + // rows + "subs %w2, %w2, #8 \n" // 8 processed per loop + "fadd v0.4s, v0.4s, v1.4s \n" // * 1 + "ld1 {v4.4s, v5.4s}, [%0], %5 \n" + "fadd v1.4s, v1.4s, v2.4s \n" + "fmla v0.4s, v4.4s, v7.4s \n" // * 6 + "ld1 {v2.4s, v3.4s}, [%0], %4 \n" + "fmla v1.4s, v5.4s, v7.4s \n" + "ld1 {v4.4s, v5.4s}, [%0], %6 \n" + "fadd v2.4s, v2.4s, v4.4s \n" + "fadd v3.4s, v3.4s, v5.4s \n" + "fmla v0.4s, v2.4s, v6.4s \n" // * 4 + "fmla v1.4s, v3.4s, v6.4s \n" + "prfm pldl1keep, [%0, 448] \n" + "fmul v0.4s, v0.4s, v8.4s \n" // / 256 + "fmul v1.4s, v1.4s, v8.4s \n" + "st1 {v0.4s, v1.4s}, [%1], #32 \n" // store 8 samples + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "r"(&kGaussCoefficients), // %3 + "r"(8LL), // %4 + "r"(-4LL), // %5 + "r"(20LL) // %6 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8"); +} + +#if defined(LIBYUV_USE_ST3) // Convert biplanar NV21 to packed YUV24 void NV21ToYUV24Row_NEON(const uint8_t* src_y, const uint8_t* src_vu, uint8_t* dst_yuv24, int width) { asm volatile( - "1: \n" - "ld1 {v2.16b}, [%0], #16 \n" // load 16 Y values - "ld2 {v0.8b, v1.8b}, [%1], #16 \n" // load 8 VU values - "zip1 v0.16b, v0.16b, v0.16b \n" // replicate V values - "zip1 v1.16b, v1.16b, v1.16b \n" // replicate U values - "subs %w3, %w3, #16 \n" // 16 pixels per loop - "st3 {v0.16b,v1.16b,v2.16b}, [%2], #48 \n" // store 16 YUV pixels - "b.gt 1b \n" + "1: \n" + "ld1 {v2.16b}, [%0], #16 \n" // load 16 Y values + "ld2 {v0.8b, v1.8b}, [%1], #16 \n" // load 8 VU values + "subs %w3, %w3, #16 \n" // 16 pixels per loop + "zip1 v0.16b, v0.16b, v0.16b \n" // replicate V values + "prfm pldl1keep, [%0, 448] \n" + "zip1 v1.16b, v1.16b, v1.16b \n" // replicate U values + "prfm pldl1keep, [%1, 448] \n" + "st3 {v0.16b,v1.16b,v2.16b}, [%2], #48 \n" // store 16 YUV pixels + "b.gt 1b \n" : "+r"(src_y), // %0 "+r"(src_vu), // %1 "+r"(dst_yuv24), // %2 @@ -2897,7 +5248,44 @@ void NV21ToYUV24Row_NEON(const uint8_t* src_y, : : "cc", "memory", "v0", "v1", "v2"); } +#else +static const uvec8 kYUV24Shuffle[3] = { + {16, 17, 0, 16, 17, 1, 18, 19, 2, 18, 19, 3, 20, 21, 4, 20}, + {21, 5, 22, 23, 6, 22, 23, 7, 24, 25, 8, 24, 25, 9, 26, 27}, + {10, 26, 27, 11, 28, 29, 12, 28, 29, 13, 30, 31, 14, 30, 31, 15}}; +// Convert biplanar NV21 to packed YUV24 +// NV21 has VU in memory for chroma. +// YUV24 is VUY in memory +void NV21ToYUV24Row_NEON(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_yuv24, + int width) { + asm volatile( + "ld1 {v5.16b,v6.16b,v7.16b}, [%4] \n" // 3 shuffler constants + "1: \n" + "ld1 {v0.16b}, [%0], #16 \n" // load 16 Y values + "ld1 {v1.16b}, [%1], #16 \n" // load 8 VU values + "subs %w3, %w3, #16 \n" // 16 pixels per loop + "tbl v2.16b, {v0.16b,v1.16b}, v5.16b \n" // weave into YUV24 + "prfm pldl1keep, [%0, 448] \n" + "tbl v3.16b, {v0.16b,v1.16b}, v6.16b \n" + "prfm pldl1keep, [%1, 448] \n" + "tbl v4.16b, {v0.16b,v1.16b}, v7.16b \n" + "st1 {v2.16b,v3.16b,v4.16b}, [%2], #48 \n" // store 16 YUV pixels + "b.gt 1b \n" + : "+r"(src_y), // %0 + "+r"(src_vu), // %1 + "+r"(dst_yuv24), // %2 + "+r"(width) // %3 + : "r"(&kYUV24Shuffle[0]) // %4 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); +} +#endif // LIBYUV_USE_ST3 + +// Note ST2 8b version is faster than zip+ST1 + +// AYUV is VUYA in memory. UV for NV12 is UV order in memory. void AYUVToUVRow_NEON(const uint8_t* src_ayuv, int src_stride_ayuv, uint8_t* dst_uv, @@ -2905,18 +5293,20 @@ void AYUVToUVRow_NEON(const uint8_t* src_ayuv, const uint8_t* src_ayuv_1 = src_ayuv + src_stride_ayuv; asm volatile( - "1: \n" - "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 ayuv - "uaddlp v0.8h, v0.16b \n" // V 16 bytes -> 8 shorts. - "uaddlp v1.8h, v1.16b \n" // U 16 bytes -> 8 shorts. - "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load next 16 - "uadalp v0.8h, v4.16b \n" // V 16 bytes -> 8 shorts. - "uadalp v1.8h, v5.16b \n" // U 16 bytes -> 8 shorts. - "uqrshrn v3.8b, v0.8h, #2 \n" // 2x2 average - "uqrshrn v2.8b, v1.8h, #2 \n" - "subs %w3, %w3, #16 \n" // 16 processed per loop. - "st2 {v2.8b,v3.8b}, [%2], #16 \n" // store 8 pixels UV. - "b.gt 1b \n" + "1: \n" + "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 ayuv + "subs %w3, %w3, #16 \n" // 16 processed per loop. + "uaddlp v0.8h, v0.16b \n" // V 16 bytes -> 8 shorts. + "prfm pldl1keep, [%0, 448] \n" + "uaddlp v1.8h, v1.16b \n" // U 16 bytes -> 8 shorts. + "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load next 16 + "uadalp v0.8h, v4.16b \n" // V 16 bytes -> 8 shorts. + "uadalp v1.8h, v5.16b \n" // U 16 bytes -> 8 shorts. + "prfm pldl1keep, [%1, 448] \n" + "uqrshrn v3.8b, v0.8h, #2 \n" // 2x2 average + "uqrshrn v2.8b, v1.8h, #2 \n" + "st2 {v2.8b,v3.8b}, [%2], #16 \n" // store 8 pixels UV. + "b.gt 1b \n" : "+r"(src_ayuv), // %0 "+r"(src_ayuv_1), // %1 "+r"(dst_uv), // %2 @@ -2932,19 +5322,20 @@ void AYUVToVURow_NEON(const uint8_t* src_ayuv, const uint8_t* src_ayuv_1 = src_ayuv + src_stride_ayuv; asm volatile( - "1: \n" - "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 - // pixels. - "uaddlp v0.8h, v0.16b \n" // V 16 bytes -> 8 shorts. - "uaddlp v1.8h, v1.16b \n" // U 16 bytes -> 8 shorts. - "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load next 16 - "uadalp v0.8h, v4.16b \n" // V 16 bytes -> 8 shorts. - "uadalp v1.8h, v5.16b \n" // U 16 bytes -> 8 shorts. - "uqrshrn v0.8b, v0.8h, #2 \n" // 2x2 average - "uqrshrn v1.8b, v1.8h, #2 \n" - "subs %w3, %w3, #16 \n" // 16 processed per loop. - "st2 {v0.8b,v1.8b}, [%2], #16 \n" // store 8 pixels VU. - "b.gt 1b \n" + "1: \n" + "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 ayuv + "subs %w3, %w3, #16 \n" // 16 processed per loop. + "uaddlp v0.8h, v0.16b \n" // V 16 bytes -> 8 shorts. + "prfm pldl1keep, [%0, 448] \n" + "uaddlp v1.8h, v1.16b \n" // U 16 bytes -> 8 shorts. + "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load next 16 + "uadalp v0.8h, v4.16b \n" // V 16 bytes -> 8 shorts. + "uadalp v1.8h, v5.16b \n" // U 16 bytes -> 8 shorts. + "prfm pldl1keep, [%1, 448] \n" + "uqrshrn v0.8b, v0.8h, #2 \n" // 2x2 average + "uqrshrn v1.8b, v1.8h, #2 \n" + "st2 {v0.8b,v1.8b}, [%2], #16 \n" // store 8 pixels VU. + "b.gt 1b \n" : "+r"(src_ayuv), // %0 "+r"(src_ayuv_1), // %1 "+r"(dst_vu), // %2 @@ -2956,12 +5347,12 @@ void AYUVToVURow_NEON(const uint8_t* src_ayuv, // Copy row of AYUV Y's into Y void AYUVToYRow_NEON(const uint8_t* src_ayuv, uint8_t* dst_y, int width) { asm volatile( - "1: \n" - "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 - // pixels - "subs %w2, %w2, #16 \n" // 16 pixels per loop - "st1 {v2.16b}, [%1], #16 \n" // store 16 Y pixels - "b.gt 1b \n" + "1: \n" + "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 + "subs %w2, %w2, #16 \n" // 16 pixels per loop + "prfm pldl1keep, [%0, 448] \n" + "st1 {v2.16b}, [%1], #16 \n" // store 16 Y pixels + "b.gt 1b \n" : "+r"(src_ayuv), // %0 "+r"(dst_y), // %1 "+r"(width) // %2 @@ -2972,19 +5363,758 @@ void AYUVToYRow_NEON(const uint8_t* src_ayuv, uint8_t* dst_y, int width) { // Convert UV plane of NV12 to VU of NV21. void SwapUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_vu, int width) { asm volatile( - "1: \n" - "ld2 {v0.16b, v1.16b}, [%0], #32 \n" // load 16 UV values - "orr v2.16b, v0.16b, v0.16b \n" // move U after V - "subs %w2, %w2, #16 \n" // 16 pixels per loop - "st2 {v1.16b, v2.16b}, [%1], #32 \n" // store 16 VU pixels - "b.gt 1b \n" + "1: \n" + "ld1 {v0.16b}, [%0], 16 \n" // load 16 UV values + "ld1 {v1.16b}, [%0], 16 \n" + "subs %w2, %w2, #16 \n" // 16 pixels per loop + "rev16 v0.16b, v0.16b \n" + "prfm pldl1keep, [%0, 448] \n" + "rev16 v1.16b, v1.16b \n" + "stp q0, q1, [%1], 32 \n" // store 16 VU pixels + "b.gt 1b \n" : "+r"(src_uv), // %0 "+r"(dst_vu), // %1 "+r"(width) // %2 : + : "cc", "memory", "v0", "v1"); +} + +void HalfMergeUVRow_NEON(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width) { + const uint8_t* src_u_1 = src_u + src_stride_u; + const uint8_t* src_v_1 = src_v + src_stride_v; + asm volatile( + "1: \n" + "ld1 {v0.16b}, [%0], #16 \n" // load 16 U values + "ld1 {v1.16b}, [%2], #16 \n" // load 16 V values + "ld1 {v2.16b}, [%1], #16 \n" + "ld1 {v3.16b}, [%3], #16 \n" + "subs %w5, %w5, #16 \n" // 16 src pixels per loop + "uaddlp v0.8h, v0.16b \n" // half size + "prfm pldl1keep, [%0, 448] \n" + "uaddlp v1.8h, v1.16b \n" + "prfm pldl1keep, [%2, 448] \n" + "uadalp v0.8h, v2.16b \n" + "prfm pldl1keep, [%1, 448] \n" + "uadalp v1.8h, v3.16b \n" + "prfm pldl1keep, [%3, 448] \n" + "uqrshrn v0.8b, v0.8h, #2 \n" + "uqrshrn v1.8b, v1.8h, #2 \n" + "st2 {v0.8b, v1.8b}, [%4], #16 \n" // store 8 UV pixels + "b.gt 1b \n" + : "+r"(src_u), // %0 + "+r"(src_u_1), // %1 + "+r"(src_v), // %2 + "+r"(src_v_1), // %3 + "+r"(dst_uv), // %4 + "+r"(width) // %5 + : + : "cc", "memory", "v0", "v1", "v2", "v3"); +} + +void SplitUVRow_16_NEON(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width) { + int shift = depth - 16; // Negative for right shift. + asm volatile( + "dup v2.8h, %w4 \n" + "1: \n" + "ld2 {v0.8h, v1.8h}, [%0], #32 \n" // load 8 UV + "subs %w3, %w3, #8 \n" // 8 src pixels per loop + "ushl v0.8h, v0.8h, v2.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "ushl v1.8h, v1.8h, v2.8h \n" + "st1 {v0.8h}, [%1], #16 \n" // store 8 U pixels + "st1 {v1.8h}, [%2], #16 \n" // store 8 V pixels + "b.gt 1b \n" + : "+r"(src_uv), // %0 + "+r"(dst_u), // %1 + "+r"(dst_v), // %2 + "+r"(width) // %3 + : "r"(shift) // %4 : "cc", "memory", "v0", "v1", "v2"); } +void MultiplyRow_16_NEON(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + asm volatile( + "dup v2.8h, %w3 \n" + "1: \n" + "ldp q0, q1, [%0], #32 \n" + "subs %w2, %w2, #16 \n" // 16 src pixels per loop + "mul v0.8h, v0.8h, v2.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "mul v1.8h, v1.8h, v2.8h \n" + "stp q0, q1, [%1], #32 \n" // store 16 pixels + "b.gt 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(scale) // %3 + : "cc", "memory", "v0", "v1", "v2"); +} + +void DivideRow_16_NEON(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + if (scale == 65536) { // Divide by 1, so do memcpy. + if (src_y != dst_y) { + memcpy(dst_y, src_y, (size_t)width * 2); + } + return; + } + asm volatile( + "dup v4.8h, %w3 \n" + "1: \n" + "ldp q2, q3, [%0], #32 \n" + "subs %w2, %w2, #16 \n" // 16 src pixels per loop + "umull v0.4s, v2.4h, v4.4h \n" + "umull2 v1.4s, v2.8h, v4.8h \n" + "umull v2.4s, v3.4h, v4.4h \n" + "umull2 v3.4s, v3.8h, v4.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "uzp2 v0.8h, v0.8h, v1.8h \n" + "uzp2 v1.8h, v2.8h, v3.8h \n" + "stp q0, q1, [%1], #32 \n" // store 16 pixels + "b.gt 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(scale) // %3 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4"); +} + +// Use scale to convert lsb formats to msb, depending how many bits there are: +// 32768 = 9 bits = shr 1 +// 16384 = 10 bits = shr 2 +// 4096 = 12 bits = shr 4 +// 256 = 16 bits = shr 8 +void Convert16To8Row_NEON(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width) { + // 15 - clz(scale), + 8 to shift result into the high half of the lane to + // saturate, then we can just use UZP2 to narrow rather than a pair of + // saturating narrow instructions. + const int shift = 23 - __builtin_clz((int32_t)scale); + asm volatile( + "dup v2.8h, %w3 \n" + "1: \n" + "ldp q0, q1, [%0], #32 \n" + "subs %w2, %w2, #16 \n" // 16 src pixels per loop + "uqshl v0.8h, v0.8h, v2.8h \n" + "uqshl v1.8h, v1.8h, v2.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "uzp2 v0.16b, v0.16b, v1.16b \n" + "str q0, [%1], #16 \n" // store 16 pixels + "b.gt 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(shift) // %3 + : "cc", "memory", "v0", "v1", "v2"); +} + +void HalfRow_16To8_NEON(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const uint16_t* src_uv1 = src_uv + src_uv_stride; + const int shift = 23 - __builtin_clz((int32_t)scale); + asm volatile( + "dup v4.8h, %w4 \n" + "1: \n" + "ldp q0, q1, [%0], #32 \n" + "ldp q2, q3, [%1], #32 \n" + "subs %w3, %w3, #16 \n" + "urhadd v0.8h, v0.8h, v2.8h \n" + "urhadd v1.8h, v1.8h, v3.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "prfm pldl1keep, [%1, 448] \n" + "uqshl v0.8h, v0.8h, v4.8h \n" + "uqshl v1.8h, v1.8h, v4.8h \n" + "uzp2 v0.16b, v0.16b, v1.16b \n" + "str q0, [%2], #16 \n" + "b.gt 1b \n" + : "+r"(src_uv), // %0 + "+r"(src_uv1), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : "r"(shift) // %4 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4"); +} + +void HalfWidthRow_16To8_NEON(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const uint16_t* src_uv1 = src_uv + src_uv_stride; + const int shift = 23 - __builtin_clz((int32_t)scale); + asm volatile( + "dup v4.8h, %w4 \n" + "1: \n" + "ldp q0, q1, [%0], #32 \n" + "ldp q2, q3, [%1], #32 \n" + "subs %w3, %w3, #8 \n" + "uaddlp v0.4s, v0.8h \n" + "uaddlp v1.4s, v1.8h \n" + "prfm pldl1keep, [%0, 448] \n" + "uadalp v0.4s, v2.8h \n" + "uadalp v1.4s, v3.8h \n" + "prfm pldl1keep, [%1, 448] \n" + "rshrn v0.4h, v0.4s, #2 \n" + "rshrn2 v0.8h, v1.4s, #2 \n" + "uqshl v0.8h, v0.8h, v4.8h \n" + "uzp2 v0.16b, v0.16b, v0.16b \n" + "str d0, [%2], #8 \n" + "b.gt 1b \n" + : "+r"(src_uv), // %0 + "+r"(src_uv1), // %1 + "+r"(dst_uv), // %2 + "+r"(width) // %3 + : "r"(shift) // %4 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4"); +} + +// Use scale to convert J420 to I420 +// scale parameter is 8.8 fixed point but limited to 0 to 255 +// Function is based on DivideRow, but adds a bias +// Does not clamp +void Convert8To8Row_NEON(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width) { + asm volatile( + "dup v4.16b, %w3 \n" // scale + "dup v5.16b, %w4 \n" // bias + "1: \n" + "ldp q2, q3, [%0], #32 \n" + "subs %w2, %w2, #32 \n" // 32 pixels per loop + "umull v0.8h, v2.8b, v4.8b \n" + "umull2 v1.8h, v2.16b, v4.16b \n" + "umull v2.8h, v3.8b, v4.8b \n" + "umull2 v3.8h, v3.16b, v4.16b \n" + "prfm pldl1keep, [%0, 448] \n" + "uzp2 v0.16b, v0.16b, v1.16b \n" + "uzp2 v1.16b, v2.16b, v3.16b \n" + "add v0.16b, v0.16b, v5.16b \n" // add bias (16) + "add v1.16b, v1.16b, v5.16b \n" + "stp q0, q1, [%1], #32 \n" // store 32 pixels + "b.gt 1b \n" + : "+r"(src_y), // %0 + "+r"(dst_y), // %1 + "+r"(width) // %2 + : "r"(scale), // %3 + "r"(bias) // %4 + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5"); +} + +// Use scale to convert lsb formats to msb, depending how many bits there are: +// 1024 = 10 bits +// 4096 = 12 bits +// 65536 = 16 bits +void Convert8To16Row_NEON(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width) { + // (src * 0x0101) >> (16 - bits). + // Use negative shift for right shift with ushl. + const int shift = bits - 16; + asm volatile( + "dup v2.8h, %w[shift] \n" + "1: \n" + "ldr q0, [%[src]], #16 \n" + "zip2 v1.16b, v0.16b, v0.16b \n" + "zip1 v0.16b, v0.16b, v0.16b \n" + "subs %w[width], %w[width], #16 \n" + "ushl v1.8h, v1.8h, v2.8h \n" + "ushl v0.8h, v0.8h, v2.8h \n" + "stp q0, q1, [%[dst]], #32 \n" + "b.ne 1b \n" + : [src] "+r"(src_y), // %[src] + [dst] "+r"(dst_y), // %[dst] + [width] "+r"(width) // %[width] + : [shift] "r"(shift) // %[shift] + : "cc", "memory", "v0", "v1", "v2"); +} + +void CopyRow_16_NEON(const uint16_t* src, uint16_t* dst, int count) { + asm volatile( + "1: \n" + "ldp q0, q1, [%0], #32 \n" + "subs %w2, %w2, #16 \n" // 16 processed per loop + "stp q0, q1, [%1], #32 \n" + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(count) // %2 + : + : "memory", "cc", "v0", "v1"); +} + +void MirrorRow_16_NEON(const uint16_t* src, uint16_t* dst, int width) { + asm volatile( + // Start at end of source row. + "ld1 {v4.16b}, [%3] \n" // shuffler + "add %0, %0, %w2, sxtw #1 \n" + "sub %0, %0, #32 \n" + "1: \n" + "ldr q1, [%0, 16] \n" + "ldr q0, [%0], -32 \n" // src -= 32 + "subs %w2, %w2, #16 \n" // 16 pixels per loop. + "tbl v2.16b, {v1.16b}, v4.16b \n" + "tbl v3.16b, {v0.16b}, v4.16b \n" + "stp q2, q3, [%1], #32 \n" // dst += 32 + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : "r"(&kShuffleMirrorUV) // %3 + : "memory", "cc", "v0", "v1", "v2", "v3", "v4"); +} + +void AR30ToARGBRow_NEON(const uint8_t* src_ar30, uint8_t* dst_argb, int width) { + asm volatile( + "movi v16.4s, #0xff, lsl #8 \n" // 0x0000ff00 + "movi v17.4s, #0x0f, msl #16 \n" // 0x000fffff + "shl v17.4s, v17.4s, #8 \n" // 0x0fffff00 + "1: \n" + "ldp q0, q1, [%0], #32 \n" // load 8 AR30 pixels + "subs %w2, %w2, #8 \n" // 8 pixels per loop + "sri v0.4s, v0.4s, #2 \n" + "sri v1.4s, v1.4s, #2 \n" + "ushr v2.4s, v0.4s, #2 \n" + "ushr v3.4s, v1.4s, #2 \n" + "ushr v4.4s, v0.4s, #4 \n" + "ushr v5.4s, v1.4s, #4 \n" + "bit v0.16b, v4.16b, v17.16b \n" + "bit v1.16b, v5.16b, v17.16b \n" + "bit v0.16b, v2.16b, v16.16b \n" + "bit v1.16b, v3.16b, v16.16b \n" + "stp q0, q1, [%1], #32 \n" // store 8 ARGB pixels + "b.gt 1b \n" + : "+r"(src_ar30), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v16", "v17"); +} + +void AR30ToABGRRow_NEON(const uint8_t* src_ar30, uint8_t* dst_abgr, int width) { + asm volatile( + "movi v16.2d, #0x00ffff0000ffff00 \n" + "1: \n" + "ldp q0, q1, [%0], #32 \n" // load 8 AR30 pixels + "subs %w2, %w2, #8 \n" // 8 pixels per loop + "sri v0.4s, v0.4s, #2 \n" + "sri v1.4s, v1.4s, #2 \n" + "ushr v2.4s, v0.4s, #2 \n" + "ushr v3.4s, v1.4s, #2 \n" + "sli v2.4s, v0.4s, #16 \n" + "sli v3.4s, v1.4s, #16 \n" + "sri v0.4s, v0.4s, #4 \n" + "sri v1.4s, v1.4s, #4 \n" + "sri v0.4s, v0.4s, #16 \n" + "sri v1.4s, v1.4s, #16 \n" + "bit v0.16b, v2.16b, v16.16b \n" + "bit v1.16b, v3.16b, v16.16b \n" + "stp q0, q1, [%1], #32 \n" // store 8 ABGR pixels + "b.gt 1b \n" + : "+r"(src_ar30), // %0 + "+r"(dst_abgr), // %1 + "+r"(width) // %2 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v16"); +} + +void AR30ToAB30Row_NEON(const uint8_t* src_ar30, uint8_t* dst_ab30, int width) { + asm volatile( + "movi v17.16b, #0xff \n" + "ushr v17.4s, v17.4s, #22 \n" // 0x000003ff + "shl v16.4s, v17.4s, #20 \n" // 0x3ff00000 + "1: \n" + "ldp q0, q1, [%0], #32 \n" // load 8 AR30 pixels + "subs %w2, %w2, #8 \n" // 8 pixels per loop + "shl v2.4s, v0.4s, #20 \n" + "shl v3.4s, v1.4s, #20 \n" + "ushr v4.4s, v0.4s, #20 \n" + "ushr v5.4s, v1.4s, #20 \n" + "bit v0.16b, v2.16b, v16.16b \n" + "bit v1.16b, v3.16b, v16.16b \n" + "bit v0.16b, v4.16b, v17.16b \n" + "bit v1.16b, v5.16b, v17.16b \n" + "stp q0, q1, [%1], #32 \n" // store 8 AB30 pixels + "b.gt 1b \n" + : "+r"(src_ar30), // %0 + "+r"(dst_ab30), // %1 + "+r"(width) // %2 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v16", "v17"); +} + +void ARGBCopyAlphaRow_NEON(const uint8_t* src, uint8_t* dst, int width) { + asm volatile( + "movi v4.4s, #0xff, lsl #24 \n" // 0xff000000 + "1: \n" + "ldp q0, q1, [%0], #32 \n" // load 8 src pixels + "ldp q2, q3, [%1] \n" // load 8 dst pixels + "subs %w2, %w2, #8 \n" // 8 pixels per loop + "bit v2.16b, v0.16b, v4.16b \n" + "bit v3.16b, v1.16b, v4.16b \n" + "stp q2, q3, [%1], #32 \n" // store 8 dst pixels + "b.gt 1b \n" + : "+r"(src), // %0 + "+r"(dst), // %1 + "+r"(width) // %2 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4"); +} + +void ARGBUnattenuateRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + uint64_t tmp; + asm volatile( + "movi v16.4s, #0xff, lsl #24 \n" // 0xff000000 + "1: \n" + "ldrb %w3, [%0, #3] \n" + "ldr s4, [%4, %w3, uxtw #2] \n" + "ldrb %w3, [%0, #7] \n" + "ldr s5, [%4, %w3, uxtw #2] \n" + "ldrb %w3, [%0, #11] \n" + "ldr s6, [%4, %w3, uxtw #2] \n" + "ldrb %w3, [%0, #15] \n" + "ldr s7, [%4, %w3, uxtw #2] \n" + "ldr q0, [%0], #16 \n" + "subs %w2, %w2, #4 \n" + "zip1 v1.16b, v0.16b, v0.16b \n" + "zip2 v2.16b, v0.16b, v0.16b \n" + "umull v3.4s, v1.4h, v4.h[0] \n" + "umull2 v5.4s, v1.8h, v5.h[0] \n" + "umull v6.4s, v2.4h, v6.h[0] \n" + "umull2 v7.4s, v2.8h, v7.h[0] \n" + "uzp2 v3.8h, v3.8h, v5.8h \n" + "uzp2 v6.8h, v6.8h, v7.8h \n" + "uqxtn v1.8b, v3.8h \n" + "uqxtn2 v1.16b, v6.8h \n" + "bit v1.16b, v0.16b, v16.16b \n" + "str q1, [%1], #16 \n" + "b.gt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width), // %2 + "=&r"(tmp) // %3 + : "r"(fixed_invtbl8) // %4 + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16"); +} + +void ARGBPolynomialRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + const float* poly, + int width) { + asm volatile( + "ldp q16, q17, [%3] \n" // c0, c1 + "ldp q18, q19, [%3, #32] \n" // c2, c3 + "subs %w2, %w2, #4 \n" + "b.lt 2f \n" + "1: \n" + "ldr q0, [%0], #16 \n" // load 4 pixels + "subs %w2, %w2, #4 \n" + "uxtl v1.8h, v0.8b \n" + "uxtl2 v3.8h, v0.16b \n" + "uxtl v0.4s, v1.4h \n" + "uxtl2 v1.4s, v1.8h \n" + "uxtl v2.4s, v3.4h \n" + "uxtl2 v3.4s, v3.8h \n" + "ucvtf v0.4s, v0.4s \n" // x0 + "ucvtf v1.4s, v1.4s \n" // x1 + "ucvtf v2.4s, v2.4s \n" // x2 + "ucvtf v3.4s, v3.4s \n" // x3 + "fmul v20.4s, v0.4s, v0.4s \n" // x0^2 + "fmul v21.4s, v1.4s, v1.4s \n" // x1^2 + "fmul v22.4s, v2.4s, v2.4s \n" // x2^2 + "fmul v23.4s, v3.4s, v3.4s \n" // x3^2 + "fmul v4.4s, v17.4s, v0.4s \n" // c1 * x0 + "fmul v5.4s, v17.4s, v1.4s \n" // c1 * x1 + "fmul v6.4s, v17.4s, v2.4s \n" // c1 * x2 + "fmul v7.4s, v17.4s, v3.4s \n" // c1 * x3 + "fmul v0.4s, v20.4s, v0.4s \n" // x0^3 + "fmul v1.4s, v21.4s, v1.4s \n" // x1^3 + "fmul v2.4s, v22.4s, v2.4s \n" // x2^3 + "fmul v3.4s, v23.4s, v3.4s \n" // x3^3 + "fadd v4.4s, v16.4s, v4.4s \n" // c0 + c1 * x0 + "fadd v5.4s, v16.4s, v5.4s \n" // c0 + c1 * x1 + "fadd v6.4s, v16.4s, v6.4s \n" // c0 + c1 * x2 + "fadd v7.4s, v16.4s, v7.4s \n" // c0 + c1 * x3 + "fmla v4.4s, v18.4s, v20.4s \n" // + c2 * x0^2 + "fmla v5.4s, v18.4s, v21.4s \n" // + c2 * x1^2 + "fmla v6.4s, v18.4s, v22.4s \n" // + c2 * x2^2 + "fmla v7.4s, v18.4s, v23.4s \n" // + c2 * x3^2 + "fmla v4.4s, v19.4s, v0.4s \n" // + c3 * x0^3 + "fmla v5.4s, v19.4s, v1.4s \n" // + c3 * x1^3 + "fmla v6.4s, v19.4s, v2.4s \n" // + c3 * x2^3 + "fmla v7.4s, v19.4s, v3.4s \n" // + c3 * x3^3 + "fcvtzs v4.4s, v4.4s \n" + "fcvtzs v5.4s, v5.4s \n" + "fcvtzs v6.4s, v6.4s \n" + "fcvtzs v7.4s, v7.4s \n" + "sqxtn v4.4h, v4.4s \n" + "sqxtn2 v4.8h, v5.4s \n" + "sqxtn v6.4h, v6.4s \n" + "sqxtn2 v6.8h, v7.4s \n" + "sqxtun v4.8b, v4.8h \n" + "sqxtun2 v4.16b, v6.8h \n" + "str q4, [%1], #16 \n" + "b.ge 1b \n" + "2: \n" + "adds %w2, %w2, #4 \n" + "b.eq 3f \n" + "ldr d0, [%0], #8 \n" // load 2 pixels + "uxtl v0.8h, v0.8b \n" + "uxtl v1.4s, v0.4h \n" + "uxtl2 v2.4s, v0.8h \n" + "ucvtf v1.4s, v1.4s \n" // x0 + "ucvtf v2.4s, v2.4s \n" // x1 + "fmul v5.4s, v1.4s, v1.4s \n" // x0^2 + "fmul v6.4s, v2.4s, v2.4s \n" // x1^2 + "fmul v3.4s, v17.4s, v1.4s \n" // c1 * x0 + "fmul v4.4s, v17.4s, v2.4s \n" // c1 * x1 + "fmul v1.4s, v5.4s, v1.4s \n" // x0^3 + "fmul v2.4s, v6.4s, v2.4s \n" // x1^3 + "fadd v3.4s, v16.4s, v3.4s \n" // c0 + c1 * x0 + "fadd v4.4s, v16.4s, v4.4s \n" // c0 + c1 * x1 + "fmla v3.4s, v18.4s, v5.4s \n" // + c2 * x0^2 + "fmla v4.4s, v18.4s, v6.4s \n" // + c2 * x1^2 + "fmla v3.4s, v19.4s, v1.4s \n" // + c3 * x0^3 + "fmla v4.4s, v19.4s, v2.4s \n" // + c3 * x1^3 + "fcvtzs v3.4s, v3.4s \n" + "fcvtzs v4.4s, v4.4s \n" + "sqxtn v3.4h, v3.4s \n" + "sqxtn2 v3.8h, v4.4s \n" + "sqxtun v3.8b, v3.8h \n" + "str d3, [%1], #8 \n" + "3: \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width) // %2 + : "r"(poly) // %3 + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23"); +} + +void ARGBColorTableRow_NEON(uint8_t* dst_argb, + const uint8_t* table_argb, + int width) { + uint64_t b, g, r, a; + asm volatile( + "1: \n" + "ldrb %w2, [%0] \n" + "ldrb %w3, [%0, #1] \n" + "ldrb %w4, [%0, #2] \n" + "ldrb %w5, [%0, #3] \n" + "subs %w1, %w1, #1 \n" + "ldr %w2, [%6, %w2, uxtw #2] \n" + "ldr %w3, [%6, %w3, uxtw #2] \n" + "ldr %w4, [%6, %w4, uxtw #2] \n" + "ldr %w5, [%6, %w5, uxtw #2] \n" + "bfi %w3, %w2, #0, #8 \n" + "lsr %w4, %w4, #16 \n" + "lsr %w5, %w5, #24 \n" + "strh %w3, [%0] \n" + "strb %w4, [%0, #2] \n" + "strb %w5, [%0, #3] \n" + "add %0, %0, #4 \n" + "b.gt 1b \n" + : "+r"(dst_argb), // %0 + "+r"(width), // %1 + "=&r"(b), // %2 + "=&r"(g), // %3 + "=&r"(r), // %4 + "=&r"(a) // %5 + : "r"(table_argb) // %6 + : "memory", "cc"); +} + +void RGBColorTableRow_NEON(uint8_t* dst_argb, + const uint8_t* table_argb, + int width) { + uint64_t b, g, r; + asm volatile( + "1: \n" + "ldrb %w2, [%0] \n" + "ldrb %w3, [%0, #1] \n" + "ldrb %w4, [%0, #2] \n" + "subs %w1, %w1, #1 \n" + "ldr %w2, [%5, %w2, uxtw #2] \n" + "ldr %w3, [%5, %w3, uxtw #2] \n" + "ldr %w4, [%5, %w4, uxtw #2] \n" + "bfi %w3, %w2, #0, #8 \n" + "lsr %w4, %w4, #16 \n" + "strh %w3, [%0] \n" + "strb %w4, [%0, #2] \n" + "add %0, %0, #4 \n" + "b.gt 1b \n" + : "+r"(dst_argb), // %0 + "+r"(width), // %1 + "=&r"(b), // %2 + "=&r"(g), // %3 + "=&r"(r) // %4 + : "r"(table_argb) // %5 + : "memory", "cc"); +} + +static const uvec8 kLumaTblIdx = {1, 1, 1, 1, 3, 3, 3, 3, + 5, 5, 5, 5, 7, 7, 7, 7}; + +void ARGBLumaColorTableRow_NEON(const uint8_t* src_argb, + uint8_t* dst_argb, + int width, + const uint8_t* luma, + uint32_t lumacoeff) { + uint64_t p0, p1, t0, t1; + asm volatile( + "dup v4.4s, %w8 \n" // broadcast 4 byte coeffs + "ldr q5, [%9] \n" + "movi v6.4s, #0xff, lsl #24 \n" + "1: \n" + "ldr q0, [%0], #16 \n" // load 4 ARGB pixels + "subs %w2, %w2, #4 \n" // 4 pixels per loop + "umull v1.8h, v0.8b, v4.8b \n" + "umull2 v2.8h, v0.16b, v4.16b \n" + "addp v1.8h, v1.8h, v2.8h \n" + "addp v1.8h, v1.8h, v1.8h \n" + "bic v1.8h, #0x80, lsl #8 \n" // clear bit 15 + "tbl v1.16b, {v1.16b}, v5.16b \n" + "zip2 v2.16b, v0.16b, v1.16b \n" // offsets pixels 2, 3 + "zip1 v1.16b, v0.16b, v1.16b \n" // offsets pixels 0, 1 + "umov %3, v1.d[0] \n" + "umov %4, v1.d[1] \n" + "add %5, %7, %w3, uxth \n" + "ubfx %6, %3, #16, #16 \n" + "ldr b3, [%5] \n" + "add %6, %7, %6 \n" + "ubfx %5, %3, #32, #16 \n" + "ld1 {v3.b}[1], [%6] \n" + "add %5, %7, %5 \n" + "add %6, %7, %w4, uxth \n" + "ld1 {v3.b}[2], [%5] \n" + "ld1 {v3.b}[4], [%6] \n" + "ubfx %5, %4, #16, #16 \n" + "ubfx %6, %4, #32, #16 \n" + "add %5, %7, %5 \n" + "add %6, %7, %6 \n" + "ld1 {v3.b}[5], [%5] \n" + "ld1 {v3.b}[6], [%6] \n" + "umov %3, v2.d[0] \n" + "umov %4, v2.d[1] \n" + "add %5, %7, %w3, uxth \n" + "ubfx %6, %3, #16, #16 \n" + "ld1 {v3.b}[8], [%5] \n" + "add %6, %7, %6 \n" + "ubfx %5, %3, #32, #16 \n" + "ld1 {v3.b}[9], [%6] \n" + "add %5, %7, %5 \n" + "add %6, %7, %w4, uxth \n" + "ld1 {v3.b}[10], [%5] \n" + "ld1 {v3.b}[12], [%6] \n" + "ubfx %5, %4, #16, #16 \n" + "ubfx %6, %4, #32, #16 \n" + "add %5, %7, %5 \n" + "add %6, %7, %6 \n" + "ld1 {v3.b}[13], [%5] \n" + "ld1 {v3.b}[14], [%6] \n" + "bit v3.16b, v0.16b, v6.16b \n" + "str q3, [%1], #16 \n" + "b.gt 1b \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(width), // %2 + "=&r"(p0), // %3 + "=&r"(p1), // %4 + "=&r"(t0), // %5 + "=&r"(t1) // %6 + : "r"(luma), // %7 + "r"(lumacoeff), // %8 + "r"(&kLumaTblIdx) // %9 + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6"); +} + +void ARGBAffineRow_NEON(const uint8_t* src_argb, + int src_argb_stride, + uint8_t* dst_argb, + const float* uv_dudv, + int width) { + int64_t off0, off1; + asm volatile( + "ld1r {v2.2d}, [%2], #8 \n" // [u, v, u, v] + "ld1r {v6.2d}, [%2] \n" // [du, dv, du, dv] + "dup v5.2s, %w5 \n" // [stride, stride] + "movi v4.2s, #4 \n" // [4, 4] + "zip1 v5.4s, v4.4s, v5.4s \n" // [4, stride, 4, stride] + "subs %w1, %w1, #4 \n" + "b.lt 2f \n" + "fadd v4.4s, v6.4s, v6.4s \n" // 2 * [du, dv, du, dv] + "fadd v3.2s, v2.2s, v6.2s \n" // [u+du, v+dv] + "ins v2.d[1], v3.d[0] \n" // [u, v, u+du, v+dv] + "fadd v3.4s, v2.4s, v4.4s \n" // [u+2du, v+2dv, u+3du, + // v+3dv] + "fadd v4.4s, v4.4s, v4.4s \n" // 4 * [du, dv, du, dv] + "1: \n" + "fcvtzs v0.4s, v2.4s \n" + "fcvtzs v1.4s, v3.4s \n" + "fadd v2.4s, v2.4s, v4.4s \n" + "fadd v3.4s, v3.4s, v4.4s \n" + "mul v0.4s, v0.4s, v5.4s \n" + "mul v1.4s, v1.4s, v5.4s \n" + "addp v7.4s, v0.4s, v1.4s \n" + "smov %3, v7.s[0] \n" + "smov %4, v7.s[1] \n" + "ldr %w3, [%6, %3] \n" + "ldr %w4, [%6, %4] \n" + "stp %w3, %w4, [%0], #8 \n" + "smov %3, v7.s[2] \n" + "smov %4, v7.s[3] \n" + "ldr %w3, [%6, %3] \n" + "ldr %w4, [%6, %4] \n" + "stp %w3, %w4, [%0], #8 \n" + "subs %w1, %w1, #4 \n" + "b.ge 1b \n" + "2: \n" + "adds %w1, %w1, #4 \n" + "b.eq 4f \n" + "3: \n" + "fcvtzs v0.2s, v2.2s \n" + "fadd v2.2s, v2.2s, v6.2s \n" + "mul v0.2s, v0.2s, v5.2s \n" + "addp v0.2s, v0.2s, v0.2s \n" + "smov %3, v0.s[0] \n" + "ldr %w3, [%6, %3] \n" + "str %w3, [%0], #4 \n" + "subs %w1, %w1, #1 \n" + "b.gt 3b \n" + "4: \n" + : "+r"(dst_argb), // %0 + "+r"(width), // %1 + "+r"(uv_dudv), // %2 + "=&r"(off0), // %3 + "=&r"(off1) // %4 + : "r"(src_argb_stride), // %5 + "r"(src_argb) // %6 + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); +} + #endif // !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) #ifdef __cplusplus diff --git a/libs/libyuv/source/row_rvv.cc b/libs/libyuv/source/row_rvv.cc new file mode 100644 index 0000000000..e137d58d0e --- /dev/null +++ b/libs/libyuv/source/row_rvv.cc @@ -0,0 +1,3199 @@ +/* + * Copyright 2023 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +/* + * Copyright (c) 2023 SiFive, Inc. All rights reserved. + * + * Contributed by Darren Hsieh + * Contributed by Bruce Lai + */ + +#include "libyuv/compare_row.h" +#include "libyuv/row.h" +#include "libyuv/video_common.h" + +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + +// This module is for RVV (RISC-V Vector extension) +#if !defined(LIBYUV_DISABLE_RVV) && defined(__riscv_vector) +#include + +// vsetvli/vsetivli write the vl and vtype CSRs. Only "vl" is declared, and +// only for GCC; clang historically rejected it. The "vtype" register is +// intentionally not declared, and whether it should be is unresolved. +// TODO(fbarchard): consider adding "vtype" (and "vl" for clang) to the +// clobber list once confirmed with compiler maintainers. +#ifndef RVV_VL_CLOBBER +#ifdef __clang__ +#define RVV_VL_CLOBBER +#else +#define RVV_VL_CLOBBER "vl", +#endif +#endif + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// Fill YUV -> RGB conversion constants into registers +// NOTE: To match behavior on other platforms, vxrm (fixed-point rounding mode +// register) is set to round-to-nearest-up mode(0). +#define YUVTORGB_SETUP \ + "csrwi vxrm, 0 \n" \ + "lbu %[ub], 0(%[yuvconst]) \n" \ + "lbu %[vr], 1(%[yuvconst]) \n" \ + "lbu %[ug], 2(%[yuvconst]) \n" \ + "lbu %[vg], 3(%[yuvconst]) \n" \ + "lhu %[yg], 16(%[yuvconst])\n" \ + "lh %[bb], 18(%[yuvconst])\n" \ + "lh %[bg], 20(%[yuvconst])\n" \ + "lh %[br], 22(%[yuvconst])\n" \ + "addi %[bb], %[bb], 32 \n" \ + "addi %[bg], %[bg], -32 \n" \ + "addi %[br], %[br], 32 \n" \ + "li %[k0101], 0x0101 \n" + +// Fill YUV -> AR30 conversion constants into registers +#define YUVTORGB_SETUP_AR30 \ + "csrwi vxrm, 0 \n" \ + "lbu %[ub], 0(%[yuvconst]) \n" \ + "lbu %[vr], 1(%[yuvconst]) \n" \ + "lbu %[ug], 2(%[yuvconst]) \n" \ + "lbu %[vg], 3(%[yuvconst]) \n" \ + "lhu %[yg], 16(%[yuvconst])\n" \ + "lh %[bb], 18(%[yuvconst])\n" \ + "lh %[bg], 20(%[yuvconst])\n" \ + "lh %[br], 22(%[yuvconst])\n" \ + "addi %[bb], %[bb], 24 \n" \ + "addi %[bg], %[bg], -24 \n" \ + "addi %[br], %[br], 24 \n" \ + "li %[k0101], 0x0101 \n" + +// Read [2*VLEN/8] Y, [VLEN/8] U and [VLEN/8] V from 422 +#define READYUV422 \ + "addi %[vl], %[w], 1 \n" \ + "srli %[vl], %[vl], 1 \n" \ + "vsetvli %[vl], %[vl], e8, m1, ta, ma \n" \ + "vle8.v v0, (%[src_u]) \n" \ + "vle8.v v1, (%[src_v]) \n" \ + "vwcvtu.x.x.v v2, v0 \n" \ + "vwcvtu.x.x.v v4, v1 \n" \ + "vsetvli zero, zero, e16, m2, ta, ma \n" \ + "vmul.vx v2, v2, %[k0101] \n" \ + "vmul.vx v4, v4, %[k0101] \n" \ + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" \ + "vle8.v v0, (%[src_y]) \n" \ + "vwcvtu.x.x.v v8, v0 \n" + +// Read [2*VLEN/8] Y, [2*VLEN/8] U, and [2*VLEN/8] V from 444 +#define READYUV444 \ + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" \ + "vle8.v v0, (%[src_y]) \n" \ + "vle8.v v2, (%[src_u]) \n" \ + "vle8.v v4, (%[src_v]) \n" \ + "vwcvtu.x.x.v v8, v0 \n" + +// Read [2*VLEN/8] Y from src_y; Read [VLEN/8] U and [VLEN/8] V from src_uv +#define READNV12 \ + "addi %[vl], %[w], 1 \n" \ + "srli %[vl], %[vl], 1 \n" \ + "vsetvli %[vl], %[vl], e8, m1, ta, ma \n" \ + "vlseg2e8.v v0, (%[src_uv]) \n" \ + "vwcvtu.x.x.v v2, v0 \n" \ + "vwcvtu.x.x.v v4, v1 \n" \ + "vsetvli zero, zero, e16, m2, ta, ma \n" \ + "vmul.vx v2, v2, %[k0101] \n" \ + "vmul.vx v4, v4, %[k0101] \n" \ + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" \ + "vle8.v v0, (%[src_y]) \n" \ + "vwcvtu.x.x.v v8, v0 \n" + +// Read 2*[VLEN/8] Y from src_y; Read [VLEN/8] U and [VLEN/8] V from src_vu +#define READNV21 \ + "addi %[vl], %[w], 1 \n" \ + "srli %[vl], %[vl], 1 \n" \ + "vsetvli %[vl], %[vl], e8, m1, ta, ma \n" \ + "vlseg2e8.v v0, (%[src_vu]) \n" \ + "vwcvtu.x.x.v v4, v0 \n" \ + "vwcvtu.x.x.v v2, v1 \n" \ + "vsetvli zero, zero, e16, m2, ta, ma \n" \ + "vmul.vx v2, v2, %[k0101] \n" \ + "vmul.vx v4, v4, %[k0101] \n" \ + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" \ + "vle8.v v0, (%[src_y]) \n" \ + "vwcvtu.x.x.v v8, v0 \n" + +// Convert from YUV to fixed point RGB +#define YUVTORGB \ + "vwmulu.vx v12, v2, %[ug] \n" \ + "vwmaccu.vx v12, %[vg], v4 \n" \ + "vwmulu.vx v0, v2, %[ub] \n" \ + "vsetvli zero, zero, e16, m4, ta, ma \n" \ + "vmul.vx v8, v8, %[k0101] \n" \ + "vmulhu.vx v8, v8, %[yg] \n" \ + "vadd.vx v16, v8, %[bg] \n" \ + "vadd.vv v0, v8, v0 \n" \ + "vsetvli zero, zero, e8, m2, ta, ma \n" \ + "vwmaccu.vx v8, %[vr], v4 \n" \ + "vsetvli zero, zero, e16, m4, ta, ma \n" \ + "vssubu.vv v12, v16, v12 \n" \ + "vssubu.vx v0, v0, %[bb] \n" \ + "vssubu.vx v8, v8, %[br] \n" + +// Convert from fixed point RGB To 8 bit RGB +#define RGBTORGB8 \ + "vsetvli zero, zero, e8, m2, ta, ma \n" \ + "vnclipu.wi v26, v12, 6 \n" \ + "vnclipu.wi v24, v0, 6 \n" \ + "vnclipu.wi v28, v8, 6 \n" + +#define YUVTORGB_REGS \ + "v0", "v1", "v2", "v3", "v4", "v5", "v8", "v9", "v10", "v11", "v12", "v13", \ + "v14", "v15", "v16", "v17", "v18", "v19", "v24", "v25", "v26", "v27", \ + "v28", "v29" + +#ifdef HAS_ARGBTOAR64ROW_RVV +void ARGBToAR64Row_RVV(const uint8_t* src_argb, uint16_t* dst_ar64, int width) { + int vl; + asm volatile( + "slli %[w], %[w], 2 \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle8.v v16, (%[src_argb]) \n" + "vwcvtu.x.x.v v8, v16 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vmul.vx v8, v8, %[k0101] \n" + "vse16.v v8, (%[dst_ar64]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_argb], %[src_argb], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_ar64], %[dst_ar64], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_ar64] "+r"(dst_ar64), // %[dst_ar64] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [k0101] "r"(0x0101) + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17"); +} +#endif + +#ifdef HAS_ARGBTOAB64ROW_RVV +void ARGBToAB64Row_RVV(const uint8_t* src_argb, uint16_t* dst_ab64, int width) { + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m1, ta, ma \n" + "vlseg4e8.v v4, (%[src_argb]) \n" + "vwcvtu.x.x.v v12, v4 \n" + "vwcvtu.x.x.v v10, v5 \n" + "vwcvtu.x.x.v v8, v6 \n" + "vwcvtu.x.x.v v14, v7 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vmul.vx v8, v8, %[k0101] \n" + "vmul.vx v10, v10, %[k0101] \n" + "vmul.vx v12, v12, %[k0101] \n" + "vmul.vx v14, v14, %[k0101] \n" + "vsseg4e16.v v8, (%[dst_ab64]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_ab64], %[dst_ab64], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_ab64] "+r"(dst_ab64), // %[dst_ab64] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [k0101] "r"(0x0101) + : RVV_VL_CLOBBER "memory", "v4", "v5", "v6", "v7", "v8", "v9", "v10", + "v11", "v12", "v13", "v14", "v15"); +} +#endif + +#ifdef HAS_AR64TOARGBROW_RVV +void AR64ToARGBRow_RVV(const uint16_t* src_ar64, uint8_t* dst_argb, int width) { + int vl; + asm volatile( + "slli %[w], %[w], 2 \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle16.v v8, (%[src_ar64]) \n" + "vnsrl.wi v16, v8, 8 \n" + "vse8.v v16, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[src_ar64], %[src_ar64], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_ar64] "+r"(src_ar64), // %[src_ar64] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17"); +} +#endif + +#ifdef HAS_AR64TOAB64ROW_RVV +void AR64ToAB64Row_RVV(const uint16_t* src_ar64, + uint16_t* dst_ab64, + int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e16, m2, ta, ma \n" + "vlseg4e16.v v8, (%[src_ar64]) \n" + "vmv2r.v v16, v12 \n" + "vmv2r.v v18, v10 \n" + "vmv2r.v v20, v8 \n" + "vmv2r.v v22, v14 \n" + "vsseg4e16.v v16, (%[dst_ab64]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 3 \n" + "add %[src_ar64], %[src_ar64], %[vl]\n" + "add %[dst_ab64], %[dst_ab64], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_ar64] "+r"(src_ar64), // %[src_ar64] + [dst_ab64] "+r"(dst_ab64), // %[dst_ab64] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23"); +} +#endif + +#ifdef HAS_AB64TOARGBROW_RVV +void AB64ToARGBRow_RVV(const uint16_t* src_ab64, uint8_t* dst_argb, int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m1, ta, ma \n" + "vlseg4e16.v v8, (%[src_ab64]) \n" + "vnsrl.wi v4, v12, 8 \n" + "vnsrl.wi v5, v10, 8 \n" + "vnsrl.wi v6, v8, 8 \n" + "vnsrl.wi v7, v14, 8 \n" + "vsseg4e8.v v4, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[src_ab64], %[src_ab64], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_ab64] "+r"(src_ab64), // %[src_ab64] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v4", "v5", "v6", "v7", "v8", "v9", "v10", + "v11", "v12", "v13", "v14", "v15"); +} +#endif + +#ifdef HAS_RAWTOARGBROW_RVV +void RAWToARGBRow_RVV(const uint8_t* src_raw, uint8_t* dst_argb, int width) { + size_t vl, tmp; + asm volatile( + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vmv.v.i v14, -1 \n" + + "1: \n" + "vlseg3e8.v v16, (%[src_raw]) \n" + "vmv2r.v v8, v20 \n" + "vmv2r.v v10, v18 \n" + "vmv2r.v v12, v16 \n" + "vsseg4e8.v v8, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[tmp], %[vl], 1 \n" + "add %[src_raw], %[src_raw], %[vl] \n" + "add %[src_raw], %[src_raw], %[tmp]\n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "bgtz %[w], 1b \n" + : [src_raw] "+r"(src_raw), // %[src_raw] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21"); +} +#endif + +#ifdef HAS_RAWTORGBAROW_RVV +void RAWToRGBARow_RVV(const uint8_t* src_raw, uint8_t* dst_rgba, int width) { + size_t vl, tmp; + asm volatile( + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vmv.v.i v8, -1 \n" + + "1: \n" + "vlseg3e8.v v16, (%[src_raw]) \n" + "vmv2r.v v10, v20 \n" + "vmv2r.v v12, v18 \n" + "vmv2r.v v14, v16 \n" + "vsseg4e8.v v8, (%[dst_rgba]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[tmp], %[vl], 1 \n" + "add %[src_raw], %[src_raw], %[vl] \n" + "add %[src_raw], %[src_raw], %[tmp]\n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_rgba], %[dst_rgba], %[vl]\n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "bgtz %[w], 1b \n" + : [src_raw] "+r"(src_raw), // %[src_raw] + [dst_rgba] "+r"(dst_rgba), // %[dst_rgba] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21"); +} +#endif + +#ifdef HAS_RAWTORGB24ROW_RVV +void RAWToRGB24Row_RVV(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { + size_t vl, tmp; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg3e8.v v16, (%[src_raw]) \n" + "vmv2r.v v8, v20 \n" + "vmv2r.v v10, v18 \n" + "vmv2r.v v12, v16 \n" + "vsseg3e8.v v8, (%[dst_rgb24]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[tmp], %[vl], 1 \n" + "add %[tmp], %[tmp], %[vl] \n" + "add %[src_raw], %[src_raw], %[tmp]\n" + "add %[dst_rgb24], %[dst_rgb24], %[tmp]\n" + "bgtz %[w], 1b \n" + : [src_raw] "+r"(src_raw), // %[src_raw] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v16", + "v17", "v18", "v19", "v20", "v21"); +} +#endif + +#ifdef HAS_ARGBTORAWROW_RVV +void ARGBToRAWRow_RVV(const uint8_t* src_argb, uint8_t* dst_raw, int width) { + size_t vl, tmp; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v8, (%[src_argb]) \n" + "vmv2r.v v16, v12 \n" + "vmv2r.v v18, v10 \n" + "vmv2r.v v20, v8 \n" + "vsseg3e8.v v16, (%[dst_raw]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[tmp], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[tmp]\n" + "slli %[tmp], %[vl], 1 \n" + "add %[dst_raw], %[dst_raw], %[vl] \n" + "add %[dst_raw], %[dst_raw], %[tmp]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_raw] "+r"(dst_raw), // %[dst_raw] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21"); +} +#endif + +#ifdef HAS_ARGBTORGB24ROW_RVV +void ARGBToRGB24Row_RVV(const uint8_t* src_argb, + uint8_t* dst_rgb24, + int width) { + size_t vl, tmp; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v8, (%[src_argb]) \n" + "vsseg3e8.v v8, (%[dst_rgb24]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[tmp], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[tmp]\n" + "slli %[tmp], %[vl], 1 \n" + "add %[dst_rgb24], %[dst_rgb24], %[vl]\n" + "add %[dst_rgb24], %[dst_rgb24], %[tmp]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_ARGBTOABGRROW_RVV +void ARGBToABGRRow_RVV(const uint8_t* src_argb, uint8_t* dst_abgr, int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v8, (%[src_argb]) \n" + "vmv2r.v v16, v12 \n" + "vmv2r.v v18, v10 \n" + "vmv2r.v v20, v8 \n" + "vmv2r.v v22, v14 \n" + "vsseg4e8.v v16, (%[dst_abgr]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[vl]\n" + "add %[dst_abgr], %[dst_abgr], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_abgr] "+r"(dst_abgr), // %[dst_abgr] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23"); +} +#endif + +#ifdef HAS_ARGBTOBGRAROW_RVV +void ARGBToBGRARow_RVV(const uint8_t* src_argb, uint8_t* dst_bgra, int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e32, m4, ta, ma \n" + "vle32.v v8, (%[src_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "vsrl.vi v12, v8, 16 \n" + "vsll.vi v8, v8, 16 \n" + "vor.vv v8, v8, v12 \n" + "slli %[vl], %[vl], 1 \n" + "vsetvli zero, %[vl], e16, m4, ta, ma \n" + "vsrl.vi v12, v8, 8 \n" + "vsll.vi v8, v8, 8 \n" + "vor.vv v8, v8, v12 \n" + "vse16.v v8, (%[dst_bgra]) \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_argb], %[src_argb], %[vl]\n" + "add %[dst_bgra], %[dst_bgra], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_bgra] "+r"(dst_bgra), // %[dst_bgra] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_ARGBTORGBAROW_RVV +void ARGBToRGBARow_RVV(const uint8_t* src_argb, uint8_t* dst_rgba, int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e32, m4, ta, ma \n" + "vle32.v v8, (%[src_argb]) \n" + "vsrl.vi v12, v8, 24 \n" + "vsll.vi v8, v8, 8 \n" + "vor.vv v8, v8, v12 \n" + "vse32.v v8, (%[dst_rgba]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[vl]\n" + "add %[dst_rgba], %[dst_rgba], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_rgba] "+r"(dst_rgba), // %[dst_rgba] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_RGBATOARGBROW_RVV +void RGBAToARGBRow_RVV(const uint8_t* src_rgba, uint8_t* dst_argb, int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e32, m4, ta, ma \n" + "vle32.v v8, (%[src_rgba]) \n" + "vsrl.vi v12, v8, 8 \n" + "vsll.vi v8, v8, 24 \n" + "vor.vv v8, v8, v12 \n" + "vse32.v v8, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_rgba], %[src_rgba], %[vl]\n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_rgba] "+r"(src_rgba), // %[src_rgba] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_RGB24TOARGBROW_RVV +void RGB24ToARGBRow_RVV(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width) { + size_t vl, tmp; + asm volatile( + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vmv.v.i v14, -1 \n" + + "1: \n" + "vlseg3e8.v v8, (%[src_rgb24]) \n" + "vsseg4e8.v v8, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[tmp], %[vl], 1 \n" + "add %[src_rgb24], %[src_rgb24], %[vl]\n" + "add %[src_rgb24], %[src_rgb24], %[tmp]\n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "bgtz %[w], 1b \n" + : [src_rgb24] "+r"(src_rgb24), // %[src_rgb24] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_I444TOARGBROW_RVV +void I444ToARGBRow_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP // + "vsetvli zero, %[w], e8, m2, ta, ma \n" + "vmv.v.i v30, -1 \n" + + "1: \n" // + READYUV444 // + "sub %[w], %[w], %[vl] \n" // + YUVTORGB // + RGBTORGB8 // + "vsseg4e8.v v24, (%[dst_argb]) \n" + "add %[src_y], %[src_y], %[vl] \n" + "add %[src_u], %[src_u], %[vl] \n" + "add %[src_v], %[src_v], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", YUVTORGB_REGS, "v30", "v31"); +} +#endif + +#ifdef HAS_I444ALPHATOARGBROW_RVV +void I444AlphaToARGBRow_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP // + + "1: \n" // + READYUV444 // + "vle8.v v30, (%[src_a]) \n" // + YUVTORGB // + RGBTORGB8 // + "vsseg4e8.v v24, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_y], %[src_y], %[vl] \n" + "add %[src_u], %[src_u], %[vl] \n" + "add %[src_v], %[src_v], %[vl] \n" + "add %[src_a], %[src_a], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", YUVTORGB_REGS, "v30", "v31"); +} +#endif + +#ifdef HAS_I444TORGB24ROW_RVV +void I444ToRGB24Row_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP // + + "1: \n" // + READYUV444 // + "sub %[w], %[w], %[vl] \n" // + YUVTORGB // + RGBTORGB8 // + "vsseg3e8.v v24, (%[dst_rgb24]) \n" + "add %[src_y], %[src_y], %[vl] \n" + "add %[src_u], %[src_u], %[vl] \n" + "add %[src_v], %[src_v], %[vl] \n" + "add %[dst_rgb24], %[dst_rgb24], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_rgb24], %[dst_rgb24], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", YUVTORGB_REGS); +} +#endif + +#ifdef HAS_I422TOARGBROW_RVV +void I422ToARGBRow_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP // + "vsetvli zero, %[w], e8, m2, ta, ma \n" + "vmv.v.i v30, -1 \n" + + "1: \n" // + READYUV422 // + "sub %[w], %[w], %[vl] \n" // + YUVTORGB // + RGBTORGB8 // + "vsseg4e8.v v24, (%[dst_argb]) \n" + "add %[src_y], %[src_y], %[vl] \n" + "srli %[k0101], %[vl], 1 \n" + "add %[src_u], %[src_u], %[k0101] \n" + "add %[src_v], %[src_v], %[k0101] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "li %[k0101], 0x0101 \n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", YUVTORGB_REGS, "v30", "v31"); +} +#endif + +#ifdef HAS_I422ALPHATOARGBROW_RVV +void I422AlphaToARGBRow_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP // + + "1: \n" // + READYUV422 // + "vle8.v v30, (%[src_a]) \n" // + YUVTORGB // + RGBTORGB8 // + "vsseg4e8.v v24, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_y], %[src_y], %[vl] \n" + "add %[src_a], %[src_a], %[vl] \n" + "srli %[k0101], %[vl], 1 \n" + "add %[src_u], %[src_u], %[k0101] \n" + "add %[src_v], %[src_v], %[k0101] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "li %[k0101], 0x0101 \n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", YUVTORGB_REGS, "v30", "v31"); +} +#endif + +#ifdef HAS_I422TORGBAROW_RVV +void I422ToRGBARow_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP // + + "1: \n" // + READYUV422 // + "sub %[w], %[w], %[vl] \n" // + YUVTORGB // + RGBTORGB8 // + "vmv.v.i v22, -1 \n" + "vsseg4e8.v v22, (%[dst_rgba]) \n" + "add %[src_y], %[src_y], %[vl] \n" + "srli %[k0101], %[vl], 1 \n" + "add %[src_u], %[src_u], %[k0101] \n" + "add %[src_v], %[src_v], %[k0101] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_rgba], %[dst_rgba], %[vl]\n" + "li %[k0101], 0x0101 \n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgba] "+r"(dst_rgba), // %[dst_rgba] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", YUVTORGB_REGS, "v22", "v23"); +} +#endif + +#ifdef HAS_I422TORGB24ROW_RVV +void I422ToRGB24Row_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP // + + "1: \n" // + READYUV422 // + "sub %[w], %[w], %[vl] \n" // + YUVTORGB // + RGBTORGB8 // + "vsseg3e8.v v24, (%[dst_rgb24]) \n" + "add %[src_y], %[src_y], %[vl] \n" + "srli %[k0101], %[vl], 1 \n" + "add %[src_u], %[src_u], %[k0101] \n" + "add %[src_v], %[src_v], %[k0101] \n" + "add %[dst_rgb24], %[dst_rgb24], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_rgb24], %[dst_rgb24], %[vl]\n" + "li %[k0101], 0x0101 \n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", YUVTORGB_REGS); +} +#endif + +#ifdef HAS_I422TOAR30ROW_RVV +void I422ToAR30Row_RVV(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP_AR30 // + + "1: \n" + "addi %[vl], %[w], 1 \n" + "srli %[vl], %[vl], 1 \n" + "vsetvli %[vl], %[vl], e8, mf2, ta, ma \n" + "vle8.v v0, (%[src_u]) \n" + "vle8.v v1, (%[src_v]) \n" + "vwcvtu.x.x.v v2, v0 \n" + "vwcvtu.x.x.v v4, v1 \n" + "vsetvli zero, zero, e16, m1, ta, ma \n" + "vmul.vx v2, v2, %[k0101] \n" + "vmul.vx v4, v4, %[k0101] \n" + "vsetvli %[vl], %[w], e8, m1, ta, ma \n" + "vle8.v v0, (%[src_y]) \n" + "vwcvtu.x.x.v v8, v0 \n" + "vwmulu.vx v12, v2, %[ug] \n" + "vwmaccu.vx v12, %[vg], v4 \n" + "vwmulu.vx v0, v2, %[ub] \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vmul.vx v8, v8, %[k0101] \n" + "vmulhu.vx v8, v8, %[yg] \n" + "vadd.vx v16, v8, %[bg] \n" + "vadd.vv v0, v8, v0 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vwmaccu.vx v8, %[vr], v4 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vssubu.vv v12, v16, v12 \n" + "vssubu.vx v0, v0, %[bb] \n" + "vssubu.vx v8, v8, %[br] \n" + "vsrl.vi v0, v0, 4 \n" + "vsrl.vi v12, v12, 4 \n" + "vsrl.vi v8, v8, 4 \n" + "li %[k0101], 1023 \n" + "vminu.vx v0, v0, %[k0101] \n" + "vminu.vx v12, v12, %[k0101] \n" + "vminu.vx v8, v8, %[k0101] \n" + "vwcvtu.x.x.v v16, v0 \n" + "li %[k0101], 1024 \n" + "vwmaccu.vx v16, %[k0101], v12 \n" + "li %[k0101], 0x0c00 \n" + "vor.vx v8, v8, %[k0101] \n" + "vwcvtu.x.x.v v20, v8 \n" + "vsetvli zero, zero, e32, m4, ta, ma \n" + "vsll.vi v20, v20, 20 \n" + "vor.vv v16, v16, v20 \n" + "vse32.v v16, (%[dst_ar30]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_y], %[src_y], %[vl] \n" + "srli %[k0101], %[vl], 1 \n" + "add %[src_u], %[src_u], %[k0101] \n" + "add %[src_v], %[src_v], %[k0101] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_ar30], %[dst_ar30], %[vl]\n" + "li %[k0101], 0x0101 \n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_ar30] "+r"(dst_ar30), // %[dst_ar30] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v4", "v8", "v9", "v12", + "v13", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23"); +} +#endif + +#ifdef HAS_I400TOARGBROW_RVV +void I400ToARGBRow_RVV(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + const bool is_yb_positive = (yuvconstants->kRGBCoeffBias[4] >= 0); + uint16_t yg = yuvconstants->kRGBCoeffBias[0]; + uint16_t yb = is_yb_positive + ? (uint16_t)(yuvconstants->kRGBCoeffBias[4] - 32) + : (uint16_t)(-yuvconstants->kRGBCoeffBias[4] + 32); + size_t k0101; + if (is_yb_positive) { + asm volatile( + "csrwi vxrm, 0 \n" + "li %[k0101], 0x0101 \n" + "vsetvli zero, %[w], e16, m4, ta, ma \n" + "vmv.v.x v20, %[yg] \n" + "vmv.v.x v24, %[yb] \n" + "vsetvli zero, %[w], e8, m2, ta, ma \n" + "vmv.v.i v14, -1 \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle8.v v0, (%[src_y]) \n" + "vwcvtu.x.x.v v16, v0 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vmul.vx v16, v16, %[k0101] \n" + "vmulhu.vv v16, v16, v20 \n" + "vsaddu.vv v16, v16, v24 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnclipu.wi v8, v16, 6 \n" + "vmv2r.v v10, v8 \n" + "vmv2r.v v12, v8 \n" + "vsseg4e8.v v8, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_y], %[src_y], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [k0101] "=&r"(k0101) // %[k0101] + : [yg] "r"(yg), // %[yg] + [yb] "r"(yb) // %[yb] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v8", "v9", "v10", "v11", "v12", + "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", + "v23", "v24", "v25", "v26", "v27"); + } else { + asm volatile( + "csrwi vxrm, 0 \n" + "li %[k0101], 0x0101 \n" + "vsetvli zero, %[w], e16, m4, ta, ma \n" + "vmv.v.x v20, %[yg] \n" + "vmv.v.x v24, %[yb] \n" + "vsetvli zero, %[w], e8, m2, ta, ma \n" + "vmv.v.i v14, -1 \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle8.v v0, (%[src_y]) \n" + "vwcvtu.x.x.v v16, v0 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vmul.vx v16, v16, %[k0101] \n" + "vmulhu.vv v16, v16, v20 \n" + "vssubu.vv v16, v16, v24 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnclipu.wi v8, v16, 6 \n" + "vmv2r.v v10, v8 \n" + "vmv2r.v v12, v8 \n" + "vsseg4e8.v v8, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_y], %[src_y], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [k0101] "=&r"(k0101) // %[k0101] + : [yg] "r"(yg), // %[yg] + [yb] "r"(yb) // %[yb] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v8", "v9", "v10", "v11", "v12", + "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", + "v23", "v24", "v25", "v26", "v27"); + } +} +#endif + +#ifdef HAS_J400TOARGBROW_RVV +void J400ToARGBRow_RVV(const uint8_t* src_y, uint8_t* dst_argb, int width) { + size_t vl; + asm volatile( + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vmv.v.i v14, -1 \n" + + "1: \n" + "vle8.v v8, (%[src_y]) \n" + "vmv2r.v v10, v8 \n" + "vmv2r.v v12, v8 \n" + "vsseg4e8.v v8, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_y], %[src_y], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_COPYROW_RVV +void CopyRow_RVV(const uint8_t* src, uint8_t* dst, int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m4, ta, ma \n" + "vle8.v v8, (%[src]) \n" + "vse8.v v8, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src], %[src], %[vl] \n" + "add %[dst], %[dst], %[vl] \n" + "bgtz %[w], 1b \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11"); +} +#endif + +#ifdef HAS_NV12TOARGBROW_RVV +void NV12ToARGBRow_RVV(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP // + "vsetvli zero, %[w], e8, m2, ta, ma \n" + "vmv.v.i v30, -1 \n" + + "1: \n" // + READNV12 // + "sub %[w], %[w], %[vl] \n" // + YUVTORGB // + RGBTORGB8 // + "vsseg4e8.v v24, (%[dst_argb]) \n" + "add %[src_y], %[src_y], %[vl] \n" + "add %[src_uv], %[src_uv], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", YUVTORGB_REGS, "v30", "v31"); +} +#endif + +#ifdef HAS_NV12TORGB24ROW_RVV +void NV12ToRGB24Row_RVV(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP // + + "1: \n" // + READNV12 // + "sub %[w], %[w], %[vl] \n" // + YUVTORGB // + RGBTORGB8 // + "vsseg3e8.v v24, (%[dst_rgb24]) \n" + "add %[src_y], %[src_y], %[vl] \n" + "add %[src_uv], %[src_uv], %[vl] \n" + "add %[dst_rgb24], %[dst_rgb24], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_rgb24], %[dst_rgb24], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", YUVTORGB_REGS); +} +#endif + +#ifdef HAS_NV21TOARGBROW_RVV +void NV21ToARGBRow_RVV(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP // + "vsetvli zero, %[w], e8, m2, ta, ma \n" + "vmv.v.i v30, -1 \n" + + "1: \n" // + READNV21 // + "sub %[w], %[w], %[vl] \n" // + YUVTORGB // + RGBTORGB8 // + "vsseg4e8.v v24, (%[dst_argb]) \n" + "add %[src_y], %[src_y], %[vl] \n" + "add %[src_vu], %[src_vu], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_vu] "+r"(src_vu), // %[src_vu] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", YUVTORGB_REGS, "v30", "v31"); +} +#endif + +#ifdef HAS_NV21TORGB24ROW_RVV +void NV21ToRGB24Row_RVV(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + size_t vl; + size_t ub, vr, ug, vg; + size_t yg, bb, bg, br; + size_t k0101; + asm volatile( // + YUVTORGB_SETUP // + + "1: \n" // + READNV21 // + "sub %[w], %[w], %[vl] \n" // + YUVTORGB // + RGBTORGB8 // + "vsseg3e8.v v24, (%[dst_rgb24]) \n" + "add %[src_y], %[src_y], %[vl] \n" + "add %[src_vu], %[src_vu], %[vl] \n" + "add %[dst_rgb24], %[dst_rgb24], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_rgb24], %[dst_rgb24], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_vu] "+r"(src_vu), // %[src_vu] + [dst_rgb24] "+r"(dst_rgb24), // %[dst_rgb24] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [ub] "=&r"(ub), // %[ub] + [vr] "=&r"(vr), // %[vr] + [ug] "=&r"(ug), // %[ug] + [vg] "=&r"(vg), // %[vg] + [yg] "=&r"(yg), // %[yg] + [bb] "=&r"(bb), // %[bb] + [bg] "=&r"(bg), // %[bg] + [br] "=&r"(br), // %[br] + [k0101] "=&r"(k0101) // %[k0101] + : [yuvconst] "r"(yuvconstants) // %[yuvconst] + : RVV_VL_CLOBBER "memory", YUVTORGB_REGS); +} +#endif + +// Bilinear filter [VLEN/8]x2 -> [VLEN/8]x1 +#ifdef HAS_INTERPOLATEROW_RVV +void InterpolateRow_RVV(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int dst_width, + int source_y_fraction) { + int y1_fraction = source_y_fraction; + int y0_fraction = 256 - y1_fraction; + const uint8_t* src_ptr1 = src_ptr + src_stride; + size_t dst_w = (size_t)dst_width; + size_t vl; + assert(source_y_fraction >= 0); + assert(source_y_fraction < 256); + // Blend 100 / 0 - Copy row unchanged. + if (y1_fraction == 0) { + asm volatile( + "1: \n" + "vsetvli %[vl], %[dst_w], e8, m4, ta, ma\n" + "vle8.v v8, (%[src_ptr]) \n" + "vse8.v v8, (%[dst_ptr]) \n" + "sub %[dst_w], %[dst_w], %[vl] \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "bgtz %[dst_w], 1b \n" + : [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_w] "+r"(dst_w), // %[dst_w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11"); + return; + } + // Blend 50 / 50. + if (y1_fraction == 128) { + asm volatile( + "csrwi vxrm, 0 \n" + + "1: \n" + "vsetvli %[vl], %[dst_w], e8, m4, ta, ma\n" + "vle8.v v8, (%[src_ptr]) \n" + "vle8.v v12, (%[src_ptr1]) \n" + "vaaddu.vv v8, v8, v12 \n" + "vse8.v v8, (%[dst_ptr]) \n" + "sub %[dst_w], %[dst_w], %[vl] \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "add %[src_ptr1], %[src_ptr1], %[vl]\n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "bgtz %[dst_w], 1b \n" + : [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "+r"(src_ptr1), // %[src_ptr1] + [dst_w] "+r"(dst_w), // %[dst_w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", + "v14", "v15"); + return; + } + // General purpose row blend. + asm volatile( + "vsetvli zero, %[dst_w], e16, m4, ta, ma\n" + "vmv.v.x v12, %[c128] \n" + + "1: \n" + "vsetvli %[vl], %[dst_w], e8, m2, ta, ma\n" + "vle8.v v16, (%[src_ptr]) \n" + "vmv4r.v v8, v12 \n" + "vwmaccu.vx v8, %[y0_fraction], v16 \n" + "vle8.v v16, (%[src_ptr1]) \n" + "vwmaccu.vx v8, %[y1_fraction], v16 \n" + "vnsrl.wi v16, v8, 8 \n" + "vse8.v v16, (%[dst_ptr]) \n" + "sub %[dst_w], %[dst_w], %[vl] \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "add %[src_ptr1], %[src_ptr1], %[vl]\n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "bgtz %[dst_w], 1b \n" + : [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "+r"(src_ptr1), // %[src_ptr1] + [dst_w] "+r"(dst_w), // %[dst_w] + [vl] "=&r"(vl) // %[vl] + : [y0_fraction] "r"(y0_fraction), // %[y0_fraction] + [y1_fraction] "r"(y1_fraction), // %[y1_fraction] + [c128] "r"(128) // %[c128] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17"); +} +#endif + +#ifdef HAS_SPLITRGBROW_RVV +void SplitRGBRow_RVV(const uint8_t* src_rgb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + size_t vl, tmp; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg3e8.v v8, (%[src_rgb]) \n" + "vse8.v v8, (%[dst_r]) \n" + "vse8.v v10, (%[dst_g]) \n" + "vse8.v v12, (%[dst_b]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_r], %[dst_r], %[vl] \n" + "add %[dst_g], %[dst_g], %[vl] \n" + "add %[dst_b], %[dst_b], %[vl] \n" + "slli %[tmp], %[vl], 1 \n" + "add %[src_rgb], %[src_rgb], %[vl] \n" + "add %[src_rgb], %[src_rgb], %[tmp]\n" + "bgtz %[w], 1b \n" + : [src_rgb] "+r"(src_rgb), // %[src_rgb] + [dst_r] "+r"(dst_r), // %[dst_r] + [dst_g] "+r"(dst_g), // %[dst_g] + [dst_b] "+r"(dst_b), // %[dst_b] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13"); +} +#endif + +#ifdef HAS_MERGERGBROW_RVV +void MergeRGBRow_RVV(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_rgb, + int width) { + size_t vl, tmp; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle8.v v8, (%[src_r]) \n" + "vle8.v v10, (%[src_g]) \n" + "vle8.v v12, (%[src_b]) \n" + "vsseg3e8.v v8, (%[dst_rgb]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_r], %[src_r], %[vl] \n" + "add %[src_g], %[src_g], %[vl] \n" + "add %[src_b], %[src_b], %[vl] \n" + "slli %[tmp], %[vl], 1 \n" + "add %[dst_rgb], %[dst_rgb], %[vl] \n" + "add %[dst_rgb], %[dst_rgb], %[tmp]\n" + "bgtz %[w], 1b \n" + : [src_r] "+r"(src_r), // %[src_r] + [src_g] "+r"(src_g), // %[src_g] + [src_b] "+r"(src_b), // %[src_b] + [dst_rgb] "+r"(dst_rgb), // %[dst_rgb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13"); +} +#endif + +#ifdef HAS_SPLITARGBROW_RVV +void SplitARGBRow_RVV(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v8, (%[src_argb]) \n" + "vse8.v v14, (%[dst_a]) \n" + "vse8.v v12, (%[dst_r]) \n" + "vse8.v v10, (%[dst_g]) \n" + "vse8.v v8, (%[dst_b]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_a], %[dst_a], %[vl] \n" + "add %[dst_r], %[dst_r], %[vl] \n" + "add %[dst_g], %[dst_g], %[vl] \n" + "add %[dst_b], %[dst_b], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_r] "+r"(dst_r), // %[dst_r] + [dst_g] "+r"(dst_g), // %[dst_g] + [dst_b] "+r"(dst_b), // %[dst_b] + [dst_a] "+r"(dst_a), // %[dst_a] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_MERGEARGBROW_RVV +void MergeARGBRow_RVV(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle8.v v12, (%[src_r]) \n" + "vle8.v v10, (%[src_g]) \n" + "vle8.v v8, (%[src_b]) \n" + "vle8.v v14, (%[src_a]) \n" + "vsseg4e8.v v8, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_r], %[src_r], %[vl] \n" + "add %[src_g], %[src_g], %[vl] \n" + "add %[src_b], %[src_b], %[vl] \n" + "add %[src_a], %[src_a], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_r] "+r"(src_r), // %[src_r] + [src_g] "+r"(src_g), // %[src_g] + [src_b] "+r"(src_b), // %[src_b] + [src_a] "+r"(src_a), // %[src_a] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_SPLITXRGBROW_RVV +void SplitXRGBRow_RVV(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v8, (%[src_argb]) \n" + "vse8.v v12, (%[dst_r]) \n" + "vse8.v v10, (%[dst_g]) \n" + "vse8.v v8, (%[dst_b]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_r], %[dst_r], %[vl] \n" + "add %[dst_g], %[dst_g], %[vl] \n" + "add %[dst_b], %[dst_b], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_r] "+r"(dst_r), // %[dst_r] + [dst_g] "+r"(dst_g), // %[dst_g] + [dst_b] "+r"(dst_b), // %[dst_b] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_MERGEXRGBROW_RVV +void MergeXRGBRow_RVV(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width) { + size_t vl; + asm volatile( + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vmv.v.i v14, -1 \n" + + "1: \n" + "vle8.v v12, (%[src_r]) \n" + "vle8.v v10, (%[src_g]) \n" + "vle8.v v8, (%[src_b]) \n" + "vsseg4e8.v v8, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_r], %[src_r], %[vl] \n" + "add %[src_g], %[src_g], %[vl] \n" + "add %[src_b], %[src_b], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "bgtz %[w], 1b \n" + : [src_r] "+r"(src_r), // %[src_r] + [src_g] "+r"(src_g), // %[src_g] + [src_b] "+r"(src_b), // %[src_b] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_SPLITUVROW_RVV +void SplitUVRow_RVV(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m4, ta, ma \n" + "vlseg2e8.v v8, (%[src_uv]) \n" + "vse8.v v8, (%[dst_u]) \n" + "vse8.v v12, (%[dst_v]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_u], %[dst_u], %[vl] \n" + "add %[dst_v], %[dst_v], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_uv], %[src_uv], %[vl] \n" + "bgtz %[w], 1b \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_u] "+r"(dst_u), // %[dst_u] + [dst_v] "+r"(dst_v), // %[dst_v] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_MERGEUVROW_RVV +void MergeUVRow_RVV(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m4, ta, ma \n" + "vle8.v v8, (%[src_u]) \n" + "vle8.v v12, (%[src_v]) \n" + "vsseg2e8.v v8, (%[dst_uv]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_u], %[src_u], %[vl] \n" + "add %[src_v], %[src_v], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_uv], %[dst_uv], %[vl] \n" + "bgtz %[w], 1b \n" + : [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_SWAPUVROW_RVV +void SwapUVRow_RVV(const uint8_t* src_uv, uint8_t* dst_vu, int width) { + assert(width != 0); + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e16, m4, ta, ma \n" + "vle16.v v8, (%[src_uv]) \n" + "vsrl.vi v12, v8, 8 \n" + "vsll.vi v8, v8, 8 \n" + "vor.vv v8, v8, v12 \n" + "vse16.v v8, (%[dst_vu]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_uv], %[src_uv], %[vl] \n" + "add %[dst_vu], %[dst_vu], %[vl] \n" + "bgtz %[w], 1b \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_vu] "+r"(dst_vu), // %[dst_vu] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +// ARGB expects first 3 values to contain RGB and 4th value is ignored +#ifdef HAS_ARGBTOYMATRIXROW_RVV +void ARGBToYMatrixRow_RVV(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + assert(width != 0); + size_t vl, tmp; + asm volatile( + "lhu %[tmp], 48(%[c]) \n" + "vsetvli zero, %[w], e16, m4, ta, ma \n" + "vmv.v.x v8, %[tmp] \n" + "lbu %[vl], 0(%[c]) \n" + "lbu %[tmp], 1(%[c]) \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vmv.v.x v12, %[vl] \n" + "vmv.v.x v14, %[tmp] \n" + "lbu %[vl], 2(%[c]) \n" + "lbu %[tmp], 3(%[c]) \n" + "vmv.v.x v16, %[vl] \n" + "vmv.v.x v18, %[tmp] \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v24, (%[src_argb]) \n" + "vwmulu.vv v20, v24, v12 \n" + "vwmaccu.vv v20, v14, v26 \n" + "vwmaccu.vv v20, v16, v28 \n" + "vwmaccu.vv v20, v18, v30 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vadd.vv v20, v20, v8 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v24, v20, 8 \n" + "vse8.v v24, (%[dst_y]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_y], %[dst_y], %[vl] \n" + "slli %[tmp], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[tmp]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_y] "+r"(dst_y), // %[dst_y] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : [c] "r"(c) // %[c] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", + "v25", "v26", "v27", "v28", "v29", "v30", "v31"); +} +#endif + +#ifdef HAS_RGBTOYMATRIXROW_RVV +void RGBToYMatrixRow_RVV(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + assert(width != 0); + size_t vl, tmp; + asm volatile( + "lhu %[tmp], 48(%[c]) \n" + "vsetvli zero, %[w], e16, m4, ta, ma \n" + "vmv.v.x v8, %[tmp] \n" + "lbu %[vl], 0(%[c]) \n" + "lbu %[tmp], 1(%[c]) \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vmv.v.x v12, %[vl] \n" + "vmv.v.x v14, %[tmp] \n" + "lbu %[vl], 2(%[c]) \n" + "vmv.v.x v16, %[vl] \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg3e8.v v24, (%[src_rgb]) \n" + "vwmulu.vv v20, v28, v16 \n" + "vwmaccu.vv v20, v14, v26 \n" + "vwmaccu.vv v20, v12, v24 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vadd.vv v20, v20, v8 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v18, v20, 8 \n" + "vse8.v v18, (%[dst_y]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_y], %[dst_y], %[vl] \n" + "slli %[tmp], %[vl], 1 \n" + "add %[src_rgb], %[src_rgb], %[vl] \n" + "add %[src_rgb], %[src_rgb], %[tmp]\n" + "bgtz %[w], 1b \n" + : [src_rgb] "+r"(src_rgb), // %[src_rgb] + [dst_y] "+r"(dst_y), // %[dst_y] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : [c] "r"(c) // %[c] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", + "v25", "v26", "v27", "v28", "v29"); +} +#endif + +#ifdef HAS_ARGBTOUV444MATRIXROW_RVV +void ARGBToUV444MatrixRow_RVV(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + assert(width != 0); + size_t vl, tmp; + asm volatile( + "lh %[tmp], 64(%[c]) \n" + "vsetvli zero, %[w], e16, m4, ta, ma \n" + "vmv.v.x v16, %[tmp] \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "lb %[vl], 16(%[c]) \n" + "lb %[tmp], 17(%[c]) \n" + "vmv.v.x v0, %[vl] \n" + "vmv.v.x v2, %[tmp] \n" + "lb %[vl], 18(%[c]) \n" + "lb %[tmp], 19(%[c]) \n" + "vmv.v.x v4, %[vl] \n" + "vmv.v.x v6, %[tmp] \n" + "lb %[vl], 32(%[c]) \n" + "lb %[tmp], 33(%[c]) \n" + "vmv.v.x v8, %[vl] \n" + "vmv.v.x v10, %[tmp] \n" + "lb %[vl], 34(%[c]) \n" + "lb %[tmp], 35(%[c]) \n" + "vmv.v.x v12, %[vl] \n" + "vmv.v.x v14, %[tmp] \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v24, (%[src_argb]) \n" + "vwmulsu.vv v20, v0, v24 \n" + "vwmaccsu.vv v20, v2, v26 \n" + "vwmaccsu.vv v20, v4, v28 \n" + "vwmaccsu.vv v20, v6, v30 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vsub.vv v20, v16, v20 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v20, v20, 8 \n" + "vse8.v v20, (%[dst_u]) \n" + "vwmulsu.vv v20, v8, v24 \n" + "vwmaccsu.vv v20, v10, v26 \n" + "vwmaccsu.vv v20, v12, v28 \n" + "vwmaccsu.vv v20, v14, v30 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vsub.vv v20, v16, v20 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v20, v20, 8 \n" + "vse8.v v20, (%[dst_v]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_u], %[dst_u], %[vl] \n" + "add %[dst_v], %[dst_v], %[vl] \n" + "slli %[tmp], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[tmp]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_u] "+r"(dst_u), // %[dst_u] + [dst_v] "+r"(dst_v), // %[dst_v] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : [c] "r"(c) // %[c] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", + "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", + "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", + "v28", "v29", "v30", "v31"); +} +#endif + +#ifdef HAS_ARGBTOUVMATRIXROW_RVV +void ARGBToUVMatrixRow_RVV(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + assert(width != 0); + const uint8_t* src_argb_0 = src_argb; + const uint8_t* src_argb_1 = src_argb + src_stride_argb; + int w = width >> 1; + if (w > 0) { + size_t w_len = (size_t)w; + size_t vl, tmp; + asm volatile( + "lh %[tmp], 64(%[c]) \n" + "vsetvli zero, %[w_len], e16, m2, ta, ma\n" + "vmv.v.x v8, %[tmp] \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "lb %[vl], 16(%[c]) \n" + "lb %[tmp], 17(%[c]) \n" + "vmv.v.x v10, %[vl] \n" + "vmv.v.x v11, %[tmp] \n" + "lb %[vl], 18(%[c]) \n" + "lb %[tmp], 19(%[c]) \n" + "vmv.v.x v12, %[vl] \n" + "vmv.v.x v13, %[tmp] \n" + "lb %[vl], 32(%[c]) \n" + "lb %[tmp], 33(%[c]) \n" + "vmv.v.x v14, %[vl] \n" + "vmv.v.x v15, %[tmp] \n" + "lb %[vl], 34(%[c]) \n" + "lb %[tmp], 35(%[c]) \n" + "vmv.v.x v16, %[vl] \n" + "vmv.v.x v17, %[tmp] \n" + + "1: \n" + "vsetvli %[vl], %[w_len], e8, m1, ta, ma\n" + "vlseg8e8.v v20, (%[src_argb_0]) \n" + "vlseg8e8.v v0, (%[src_argb_1]) \n" + "vwaddu.vv v18, v20, v24 \n" + "vwaddu.wv v18, v18, v0 \n" + "vwaddu.wv v18, v18, v4 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vi v18, v18, 2 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v20, v18, 2 \n" + "vwaddu.vv v18, v21, v25 \n" + "vwaddu.wv v18, v18, v1 \n" + "vwaddu.wv v18, v18, v5 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vi v18, v18, 2 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v21, v18, 2 \n" + "vwaddu.vv v18, v22, v26 \n" + "vwaddu.wv v18, v18, v2 \n" + "vwaddu.wv v18, v18, v6 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vi v18, v18, 2 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v22, v18, 2 \n" + "vwaddu.vv v18, v23, v27 \n" + "vwaddu.wv v18, v18, v3 \n" + "vwaddu.wv v18, v18, v7 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vi v18, v18, 2 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v23, v18, 2 \n" + "vwmulsu.vv v18, v10, v20 \n" + "vwmaccsu.vv v18, v11, v21 \n" + "vwmaccsu.vv v18, v12, v22 \n" + "vwmaccsu.vv v18, v13, v23 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vsub.vv v18, v8, v18 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v24, v18, 8 \n" + "vse8.v v24, (%[dst_u]) \n" + "vwmulsu.vv v18, v14, v20 \n" + "vwmaccsu.vv v18, v15, v21 \n" + "vwmaccsu.vv v18, v16, v22 \n" + "vwmaccsu.vv v18, v17, v23 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vsub.vv v18, v8, v18 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v20, v18, 8 \n" + "vse8.v v20, (%[dst_v]) \n" + "sub %[w_len], %[w_len], %[vl] \n" + "add %[dst_u], %[dst_u], %[vl] \n" + "add %[dst_v], %[dst_v], %[vl] \n" + "slli %[tmp], %[vl], 3 \n" + "add %[src_argb_0], %[src_argb_0], %[tmp]\n" + "add %[src_argb_1], %[src_argb_1], %[tmp]\n" + "bgtz %[w_len], 1b \n" + : [src_argb_0] "+r"(src_argb_0), // %[src_argb_0] + [src_argb_1] "+r"(src_argb_1), // %[src_argb_1] + [dst_u] "+r"(dst_u), // %[dst_u] + [dst_v] "+r"(dst_v), // %[dst_v] + [w_len] "+r"(w_len), // %[w_len] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : [c] "r"(c) // %[c] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", + "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", + "v27"); + } + if (width & 1) { + uint8_t b = (src_argb_0[0] + src_argb_1[0] + 1) >> 1; + uint8_t g = (src_argb_0[1] + src_argb_1[1] + 1) >> 1; + uint8_t r = (src_argb_0[2] + src_argb_1[2] + 1) >> 1; + uint8_t a = (src_argb_0[3] + src_argb_1[3] + 1) >> 1; + dst_u[0] = (c->kAddUV[0] - (c->kRGBToU[0] * b + c->kRGBToU[1] * g + + c->kRGBToU[2] * r + c->kRGBToU[3] * a)) >> + 8; + dst_v[0] = (c->kAddUV[0] - (c->kRGBToV[0] * b + c->kRGBToV[1] * g + + c->kRGBToV[2] * r + c->kRGBToV[3] * a)) >> + 8; + } +} +#endif + +#ifdef HAS_RGBTOUV444MATRIXROW_RVV +void RGBToUV444MatrixRow_RVV(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + assert(width != 0); + size_t vl, tmp; + asm volatile( + "lh %[tmp], 64(%[c]) \n" + "vsetvli zero, %[w], e16, m4, ta, ma \n" + "vmv.v.x v16, %[tmp] \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "lb %[vl], 16(%[c]) \n" + "lb %[tmp], 17(%[c]) \n" + "vmv.v.x v0, %[vl] \n" + "vmv.v.x v2, %[tmp] \n" + "lb %[vl], 18(%[c]) \n" + "vmv.v.x v4, %[vl] \n" + "lb %[vl], 32(%[c]) \n" + "lb %[tmp], 33(%[c]) \n" + "vmv.v.x v8, %[vl] \n" + "vmv.v.x v10, %[tmp] \n" + "lb %[vl], 34(%[c]) \n" + "vmv.v.x v12, %[vl] \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg3e8.v v24, (%[src_rgb]) \n" + "vwmulsu.vv v20, v4, v28 \n" + "vwmaccsu.vv v20, v2, v26 \n" + "vwmaccsu.vv v20, v0, v24 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vsub.vv v20, v16, v20 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v20, v20, 8 \n" + "vse8.v v20, (%[dst_u]) \n" + "vwmulsu.vv v20, v12, v28 \n" + "vwmaccsu.vv v20, v10, v26 \n" + "vwmaccsu.vv v20, v8, v24 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vsub.vv v20, v16, v20 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v20, v20, 8 \n" + "vse8.v v20, (%[dst_v]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_u], %[dst_u], %[vl] \n" + "add %[dst_v], %[dst_v], %[vl] \n" + "slli %[tmp], %[vl], 1 \n" + "add %[src_rgb], %[src_rgb], %[vl] \n" + "add %[src_rgb], %[src_rgb], %[tmp]\n" + "bgtz %[w], 1b \n" + : [src_rgb] "+r"(src_rgb), // %[src_rgb] + [dst_u] "+r"(dst_u), // %[dst_u] + [dst_v] "+r"(dst_v), // %[dst_v] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : [c] "r"(c) // %[c] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v8", "v9", + "v10", "v11", "v12", "v13", "v16", "v17", "v18", "v19", "v20", "v21", + "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29"); +} +#endif + +#ifdef HAS_RGBTOUVMATRIXROW_RVV +void RGBToUVMatrixRow_RVV(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + assert(width != 0); + const uint8_t* src_rgb_0 = src_rgb; + const uint8_t* src_rgb_1 = src_rgb + src_stride_rgb; + int w = width >> 1; + if (w > 0) { + size_t w_len = (size_t)w; + size_t vl, tmp; + asm volatile( + "lh %[tmp], 64(%[c]) \n" + "vsetvli zero, %[w_len], e16, m2, ta, ma\n" + "vmv.v.x v8, %[tmp] \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "lb %[vl], 16(%[c]) \n" + "lb %[tmp], 17(%[c]) \n" + "vmv.v.x v10, %[vl] \n" + "vmv.v.x v11, %[tmp] \n" + "lb %[vl], 18(%[c]) \n" + "vmv.v.x v12, %[vl] \n" + "lb %[vl], 32(%[c]) \n" + "lb %[tmp], 33(%[c]) \n" + "vmv.v.x v14, %[vl] \n" + "vmv.v.x v15, %[tmp] \n" + "lb %[vl], 34(%[c]) \n" + "vmv.v.x v16, %[vl] \n" + + "1: \n" + "vsetvli %[vl], %[w_len], e8, m1, ta, ma\n" + "vlseg6e8.v v20, (%[src_rgb_0]) \n" + "vlseg6e8.v v0, (%[src_rgb_1]) \n" + "vwaddu.vv v18, v20, v23 \n" + "vwaddu.wv v18, v18, v0 \n" + "vwaddu.wv v18, v18, v3 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vi v18, v18, 2 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v20, v18, 2 \n" + "vwaddu.vv v18, v21, v24 \n" + "vwaddu.wv v18, v18, v1 \n" + "vwaddu.wv v18, v18, v4 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vi v18, v18, 2 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v21, v18, 2 \n" + "vwaddu.vv v18, v22, v25 \n" + "vwaddu.wv v18, v18, v2 \n" + "vwaddu.wv v18, v18, v5 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vi v18, v18, 2 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v22, v18, 2 \n" + "vwmulsu.vv v18, v12, v22 \n" + "vwmaccsu.vv v18, v11, v21 \n" + "vwmaccsu.vv v18, v10, v20 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vsub.vv v18, v8, v18 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v24, v18, 8 \n" + "vse8.v v24, (%[dst_u]) \n" + "vwmulsu.vv v18, v16, v22 \n" + "vwmaccsu.vv v18, v15, v21 \n" + "vwmaccsu.vv v18, v14, v20 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vsub.vv v18, v8, v18 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v20, v18, 8 \n" + "vse8.v v20, (%[dst_v]) \n" + "sub %[w_len], %[w_len], %[vl] \n" + "add %[dst_u], %[dst_u], %[vl] \n" + "add %[dst_v], %[dst_v], %[vl] \n" + "slli %[tmp], %[vl], 1 \n" + "add %[tmp], %[tmp], %[vl] \n" + "slli %[tmp], %[tmp], 1 \n" + "add %[src_rgb_0], %[src_rgb_0], %[tmp]\n" + "add %[src_rgb_1], %[src_rgb_1], %[tmp]\n" + "bgtz %[w_len], 1b \n" + : [src_rgb_0] "+r"(src_rgb_0), // %[src_rgb_0] + [src_rgb_1] "+r"(src_rgb_1), // %[src_rgb_1] + [dst_u] "+r"(dst_u), // %[dst_u] + [dst_v] "+r"(dst_v), // %[dst_v] + [w_len] "+r"(w_len), // %[w_len] + [vl] "=&r"(vl), // %[vl] + [tmp] "=&r"(tmp) // %[tmp] + : [c] "r"(c) // %[c] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v8", + "v9", "v10", "v11", "v12", "v14", "v15", "v16", "v18", "v19", "v20", + "v21", "v22", "v23", "v24", "v25"); + } + if (width & 1) { + uint8_t b = (src_rgb_0[0] + src_rgb_1[0] + 1) >> 1; + uint8_t g = (src_rgb_0[1] + src_rgb_1[1] + 1) >> 1; + uint8_t r = (src_rgb_0[2] + src_rgb_1[2] + 1) >> 1; + dst_u[0] = (c->kAddUV[0] - + (c->kRGBToU[0] * b + c->kRGBToU[1] * g + c->kRGBToU[2] * r)) >> + 8; + dst_v[0] = (c->kAddUV[0] - + (c->kRGBToV[0] * b + c->kRGBToV[1] * g + c->kRGBToV[2] * r)) >> + 8; + } +} +#endif + +// Blend src_argb over src_argb1 and store to dst_argb. +// dst_argb may be src_argb or src_argb1. +// src_argb: RGB values have already been pre-multiplied by the a. +#ifdef HAS_ARGBBLENDROW_RVV +void ARGBBlendRow_RVV(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + size_t vl; + asm volatile( + "vsetvli %[vl], zero, e8, m2, ta, ma \n" + "vmv.v.i v14, -1 \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v16, (%[src_argb]) \n" + "vlseg4e8.v v24, (%[src_argb1]) \n" + "vmulhu.vv v8, v24, v22 \n" + "vmulhu.vv v10, v26, v22 \n" + "vmulhu.vv v12, v28, v22 \n" + "vsub.vv v8, v24, v8 \n" + "vsub.vv v10, v26, v10 \n" + "vsub.vv v12, v28, v12 \n" + "vsaddu.vv v8, v8, v16 \n" + "vsaddu.vv v10, v10, v18 \n" + "vsaddu.vv v12, v12, v20 \n" + "vsseg4e8.v v8, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[vl]\n" + "add %[src_argb1], %[src_argb1], %[vl]\n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [src_argb1] "+r"(src_argb1), // %[src_argb1] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", + "v25", "v26", "v27", "v28", "v29", "v30", "v31"); +} +#endif + +#ifdef HAS_ARGBORROW_RVV +void ARGBOrRow_RVV(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + size_t vl; + int w = width * 4; + asm volatile( + "vsetvli %[vl], zero, e32, m8, ta, ma \n" + "vmv.v.x v16, %[val] \n" + "1: \n" + "vsetvli %[vl], %[w], e8, m8, ta, ma \n" + "vle8.v v8, (%[src]) \n" + "vor.vv v8, v8, v16 \n" + "vse8.v v8, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src], %[src], %[vl] \n" + "add %[dst], %[dst], %[vl] \n" + "bgtz %[w], 1b \n" + : [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_argb), // %[dst] + [w] "+r"(w), // %[w] + [vl] "=&r"(vl) // %[vl] + : [val] "r"(value) // %[val] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23"); +} +#endif + +#ifdef HAS_ARGBALPHABLENDROW_RVV +void ARGBAlphaBlendRow_RVV(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v16, (%[src_argb]) \n" + "vlseg4e8.v v24, (%[src_argb1]) \n" + "vwmulu.vv v4, v30, v22 \n" + "vwmulu.vx v8, v22, %[k255] \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vadd.vi v4, v4, 1 \n" + "vmulhu.vx v4, v4, %[k0101] \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v0, v4, 0 \n" + "vsub.vv v0, v22, v0 \n" + "vadd.vv v30, v30, v0 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vzext.vf2 v12, v30 \n" + "vdivu.vv v8, v8, v12 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v0, v8, 0 \n" + "vrsub.vx v2, v0, %[k255] \n" + "vwmulu.vv v4, v24, v2 \n" + "vwmulu.vv v8, v26, v2 \n" + "vwmulu.vv v12, v28, v2 \n" + "vwmaccu.vv v4, v0, v16 \n" + "vwmaccu.vv v8, v0, v18 \n" + "vwmaccu.vv v12, v0, v20 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vadd.vi v4, v4, 1 \n" + "vadd.vi v8, v8, 1 \n" + "vadd.vi v12, v12, 1 \n" + "vmulhu.vx v4, v4, %[k0101] \n" + "vmulhu.vx v8, v8, %[k0101] \n" + "vmulhu.vx v12, v12, %[k0101] \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v24, v4, 0 \n" + "vnsrl.wi v26, v8, 0 \n" + "vnsrl.wi v28, v12, 0 \n" + "vsseg4e8.v v24, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[vl] \n" + "add %[src_argb1], %[src_argb1], %[vl]\n" + "add %[dst_argb], %[dst_argb], %[vl] \n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [src_argb1] "+r"(src_argb1), // %[src_argb1] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [k0101] "r"(0x0101), // %[k0101] + [k255] "r"(255) // %[k255] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", + "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", + "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", + "v28", "v29", "v30", "v31"); +} +#endif + +#ifdef HAS_BLENDPLANEROW_RVV +void BlendPlaneRow_RVV(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width) { + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle8.v v16, (%[src0]) \n" + "vle8.v v18, (%[src1]) \n" + "vle8.v v20, (%[alpha]) \n" + "vrsub.vx v22, v20, %[k255] \n" + "vwmulu.vv v8, v20, v16 \n" + "vwmaccu.vv v8, v22, v18 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vadd.vx v8, v8, %[k255] \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v16, v8, 8 \n" + "vse8.v v16, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src0], %[src0], %[vl] \n" + "add %[src1], %[src1], %[vl] \n" + "add %[alpha], %[alpha], %[vl] \n" + "add %[dst], %[dst], %[vl] \n" + "bgtz %[w], 1b \n" + : [src0] "+r"(src0), // %[src0] + [src1] "+r"(src1), // %[src1] + [alpha] "+r"(alpha), // %[alpha] + [dst] "+r"(dst), // %[dst] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [k255] "r"(255) + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17", "v18", + "v19", "v20", "v21", "v22", "v23"); +} +#endif + +// Attenuate: (f * a + 255) >> 8 +#ifdef HAS_ARGBATTENUATEROW_RVV +void ARGBAttenuateRow_RVV(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v8, (%[src_argb]) \n" + "vwmulu.vv v16, v8, v14 \n" + "vwmulu.vv v20, v10, v14 \n" + "vwmulu.vv v24, v12, v14 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vadd.vx v16, v16, %[k255] \n" + "vadd.vx v20, v20, %[k255] \n" + "vadd.vx v24, v24, %[k255] \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v8, v16, 8 \n" + "vnsrl.wi v10, v20, 8 \n" + "vnsrl.wi v12, v24, 8 \n" + "vsseg4e8.v v8, (%[dst_argb]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[vl]\n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [k255] "r"(255) + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", + "v25", "v26", "v27"); +} +#endif + +#ifdef HAS_ARGBMULTIPLYROW_RVV +void ARGBMultiplyRow_RVV(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + assert(width != 0); + size_t w = (size_t)width * 4; + size_t vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle8.v v8, (%[src0]) \n" + "vle8.v v10, (%[src1]) \n" + "vwmulu.vv v12, v8, v10 \n" + "vwaddu.wx v12, v12, %[k128] \n" + "vnsrl.wi v8, v12, 8 \n" + "vse8.v v8, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src0], %[src0], %[vl] \n" + "add %[src1], %[src1], %[vl] \n" + "add %[dst], %[dst], %[vl] \n" + "bgtz %[w], 1b \n" + : [src0] "+r"(src_argb), // %[src0] + [src1] "+r"(src_argb1), // %[src1] + [dst] "+r"(dst_argb), // %[dst] + [w] "+r"(w), // %[w] + [vl] "=&r"(vl) // %[vl] + : [k128] "r"(128) // %[k128] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_ARGBEXTRACTALPHAROW_RVV +void ARGBExtractAlphaRow_RVV(const uint8_t* src_argb, + uint8_t* dst_a, + int width) { + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e16, m4, ta, ma \n" + "vle32.v v8, (%[src_argb]) \n" + "vnsrl.wi v16, v8, 16 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v8, v16, 8 \n" + "vse8.v v8, (%[dst_a]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_a], %[dst_a], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_argb], %[src_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_a] "+r"(dst_a), // %[dst_a] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19"); +} +#endif + +#ifdef HAS_ARGBCOPYYTOALPHAROW_RVV +void ARGBCopyYToAlphaRow_RVV(const uint8_t* src, uint8_t* dst, int width) { + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e32, m8, ta, ma \n" + "vle8.v v16, (%[src]) \n" + "vle32.v v8, (%[dst]) \n" + "vzext.vf4 v24, v16 \n" + "vand.vx v8, v8, %[mask] \n" + "vsll.vi v24, v24, 24 \n" + "vor.vv v8, v8, v24 \n" + "vse32.v v8, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src], %[src], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst], %[dst], %[vl] \n" + "bgtz %[w], 1b \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [mask] "r"(0x00ffffffu) // %[mask] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v24", "v25", "v26", "v27", "v28", "v29", "v30", + "v31"); +} +#endif + +#ifdef HAS_CONVERT16TO8ROW_RVV +void Convert16To8Row_RVV(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width) { + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle16.v v8, (%[src_y]) \n" + "vnsrl.wx v16, v8, %[shift] \n" + "vse8.v v16, (%[dst_y]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_y], %[dst_y], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_y], %[src_y], %[vl] \n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [dst_y] "+r"(dst_y), // %[dst_y] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [shift] "r"(__builtin_clz((int32_t)scale) - 15) // %[shift] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17"); +} +#endif + +#ifdef HAS_CONVERT8TO16ROW_RVV +// Use scale to convert lsb formats to msb, depending how many bits there are: +// 512 = 9 bits +// 1024 = 10 bits +// 4096 = 12 bits +// 65536 = 16 bits +void Convert8To16Row_RVV(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width) { + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle8.v v16, (%[src_y]) \n" + "vwcvtu.x.x.v v8, v16 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vmul.vx v8, v8, %[k0101] \n" + "vsrl.vx v8, v8, %[shift] \n" + "vse16.v v8, (%[dst_y]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_y], %[src_y], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_y], %[dst_y], %[vl] \n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [dst_y] "+r"(dst_y), // %[dst_y] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [shift] "r"(16 - bits), [k0101] "r"(0x0101) + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17"); +} +#endif + +#ifdef HAS_MULTIPLYROW_16_RVV +void MultiplyRow_16_RVV(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e16, m4, ta, ma \n" + "vle16.v v8, (%[src_y]) \n" + "vmul.vx v8, v8, %[scale] \n" + "vse16.v v8, (%[dst_y]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_y], %[src_y], %[vl] \n" + "add %[dst_y], %[dst_y], %[vl] \n" + "bgtz %[w], 1b \n" + : [src_y] "+r"(src_y), // %[src_y] + [dst_y] "+r"(dst_y), // %[dst_y] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [scale] "r"(scale) // %[scale] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11"); +} +#endif + +#ifdef HAS_HALFROW_16TO8_RVV +void HalfRow_16To8_RVV(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + int vl; + asm volatile( + "slli %[src_uv1], %[src_uv1], 1 \n" + "add %[src_uv1], %[src_uv], %[src_uv1]\n" + "csrwi vxrm, 0 \n" + + "1: \n" + "vsetvli %[vl], %[w], e16, m4, ta, ma \n" + "vle16.v v8, (%[src_uv]) \n" + "vle16.v v12, (%[src_uv1]) \n" + "vaaddu.vv v8, v8, v12 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wx v16, v8, %[shift] \n" + "vse8.v v16, (%[dst_uv]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_uv], %[dst_uv], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_uv], %[src_uv], %[vl] \n" + "add %[src_uv1], %[src_uv1], %[vl] \n" + "bgtz %[w], 1b \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [src_uv1] "+r"(src_uv_stride), // %[src_uv1] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [shift] "r"(__builtin_clz((int32_t)scale) - 15) // %[shift] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17"); +} +#endif + +#ifdef HAS_HALFWIDTHROW_16TO8_RVV +void HalfWidthRow_16To8_RVV(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + int vl; + asm volatile( + "slli %[t], %[t], 1 \n" + "add %[t], %[s], %[t] \n" + + "1: \n" + "vsetvli %[vl], %[w], e16, m2, ta, ma \n" + "vlseg2e16.v v16, (%[s]) \n" + "vlseg2e16.v v20, (%[t]) \n" + "vwaddu.vx v8, v16, %[c2] \n" + "vwaddu.wv v8, v8, v18 \n" + "vwaddu.wv v8, v8, v20 \n" + "vwaddu.wv v8, v8, v22 \n" + "vnsrl.wi v16, v8, 2 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wx v8, v16, %[shift] \n" + "vse8.v v8, (%[dst_uv]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_uv], %[dst_uv], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[s], %[s], %[vl] \n" + "add %[t], %[t], %[vl] \n" + "bgtz %[w], 1b \n" + : [s] "+r"(src_uv), // %[s] + [t] "+r"(src_uv_stride), // %[t] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [shift] "r"(__builtin_clz((int32_t)scale) - 15), // %[shift] + [c2] "r"(2) // %[c2] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17", "v18", + "v19", "v20", "v21", "v22", "v23"); +} +#endif + +#ifdef HAS_ARGBMIRRORROW_RVV +void ARGBMirrorRow_RVV(const uint8_t* src, uint8_t* dst, int width) { + int vl; + ptrdiff_t byte_vl; + src += (ptrdiff_t)width * 4; + asm volatile( + "vsetvli %[vl], %[w], e32, m8, ta, ma \n" + "slli %[byte_vl], %[vl], 2 \n" + "vid.v v16 \n" + "addi %[vl], %[vl], -1 \n" + "vrsub.vx v16, v16, %[vl] \n" + "addi %[vl], %[vl], 1 \n" + "sub %[w], %[w], %[vl] \n" + "bltz %[w], 2f \n" + "1: \n" + "sub %[src], %[src], %[byte_vl] \n" + "vle32.v v8, (%[src]) \n" + "vrgather.vv v0, v8, v16 \n" + "vse32.v v0, (%[dst]) \n" + "add %[dst], %[dst], %[byte_vl] \n" + "sub %[w], %[w], %[vl] \n" + "bgez %[w], 1b \n" + "2: \n" + "add %[w], %[w], %[vl] \n" + "beqz %[w], 3f \n" + "vsetvli %[vl], %[w], e32, m8, ta, ma \n" + "slli %[byte_vl], %[vl], 2 \n" + "vid.v v16 \n" + "addi %[vl], %[vl], -1 \n" + "vrsub.vx v16, v16, %[vl] \n" + "sub %[src], %[src], %[byte_vl] \n" + "vle32.v v8, (%[src]) \n" + "vrgather.vv v0, v8, v16 \n" + "vse32.v v0, (%[dst]) \n" + "3: \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [byte_vl] "=&r"(byte_vl) // %[byte_vl] + : + : RVV_VL_CLOBBER "vtype", "memory", "v0", "v1", "v2", "v3", "v4", "v5", + "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23"); +} +#endif // HAS_ARGBMIRRORROW_RVV + +#ifdef HAS_ARGBSETROW_RVV +void ARGBSetRow_RVV(uint8_t* dst_argb, uint32_t v32, int width) { + size_t vl; + asm volatile( + "vsetvli %[vl], %[w], e32, m8, ta, ma \n" + "vmv.v.x v8, %[v32] \n" + "1: \n" + "vsetvli %[vl], %[w], e32, m8, ta, ma \n" + "vse32.v v8, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst], %[dst], %[vl] \n" + "bnez %[w], 1b \n" + : [dst] "+r"(dst_argb), // %[dst] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl) // %[vl] + : [v32] "r"(v32) // %[v32] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif // HAS_ARGBSETROW_RVV + +#ifdef HAS_ARGBSHUFFLEROW_RVV +// Shuffle the 4 bytes of each ARGB pixel with a 16 byte shuffler table (only +// the first 4 entries are used, the pattern repeats every pixel), e.g. +// {0, 1, 2, 3} is a copy and {2, 1, 0, 3} swaps R and B. +// Byte index vector: index[i] = (i & ~3) + shuffler[i & 3], gathered with a +// 16 bit index so any VLEN works (e8 indices would be limited to 256 bytes). +void ARGBShuffleRow_RVV(const uint8_t* src_argb, + uint8_t* dst_argb, + const uint8_t* shuffler, + int width) { + size_t vl; + size_t w = (size_t)width * 4; // bytes + // The 4 shuffler bytes packed little endian so a 32 bit broadcast lays them + // out as s0 s1 s2 s3 s0 s1 s2 s3 ... in memory order. + uint32_t pattern = (uint32_t)shuffler[0] | ((uint32_t)shuffler[1] << 8) | + ((uint32_t)shuffler[2] << 16) | + ((uint32_t)shuffler[3] << 24); + asm volatile( + // v16..v23 (e16, m8): index = (i & ~3) + shuffler[i & 3]. + "vsetvli %[vl], %[w], e16, m8, ta, ma \n" + "vid.v v16 \n" + "vand.vi v16, v16, -4 \n" + "srli %[vl], %[vl], 2 \n" + "vsetvli zero, %[vl], e32, m4, ta, ma \n" + "vmv.v.x v8, %[pattern] \n" // s0 s1 s2 s3 ... + "vsetvli %[vl], %[w], e16, m8, ta, ma \n" + "vzext.vf2 v24, v8 \n" // bytes -> e16 + "vadd.vv v16, v16, v24 \n" + "1: \n" + "vsetvli %[vl], %[w], e8, m4, ta, ma \n" + "vle8.v v8, (%[src]) \n" + "vrgatherei16.vv v0, v8, v16 \n" + "vse8.v v0, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src], %[src], %[vl] \n" + "add %[dst], %[dst], %[vl] \n" + "bnez %[w], 1b \n" + : [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_argb), // %[dst] + [w] "+r"(w), // %[w] + [vl] "=&r"(vl) // %[vl] + : [pattern] "r"(pattern) // %[pattern] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v3", "v8", "v9", "v10", + "v11", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", + "v25", "v26", "v27", "v28", "v29", "v30", "v31"); +} +#endif // HAS_ARGBSHUFFLEROW_RVV + +#ifdef HAS_MIRRORUVROW_RVV +void MirrorUVRow_RVV(const uint8_t* src_uv, uint8_t* dst_uv, int width) { + int vl; + ptrdiff_t byte_vl; + src_uv += (ptrdiff_t)width * 2; + asm volatile( + "vsetvli %[vl], %[w], e16, m8, ta, ma \n" + "slli %[byte_vl], %[vl], 1 \n" + "vid.v v16 \n" + "addi %[vl], %[vl], -1 \n" + "vrsub.vx v16, v16, %[vl] \n" + "addi %[vl], %[vl], 1 \n" + "sub %[w], %[w], %[vl] \n" + "bltz %[w], 2f \n" + "1: \n" + "sub %[src], %[src], %[byte_vl] \n" + "vle16.v v8, (%[src]) \n" + "vrgather.vv v0, v8, v16 \n" + "vse16.v v0, (%[dst]) \n" + "add %[dst], %[dst], %[byte_vl] \n" + "sub %[w], %[w], %[vl] \n" + "bgez %[w], 1b \n" + "2: \n" + "add %[w], %[w], %[vl] \n" + "beqz %[w], 3f \n" + "vsetvli %[vl], %[w], e16, m8, ta, ma \n" + "slli %[byte_vl], %[vl], 1 \n" + "vid.v v16 \n" + "addi %[vl], %[vl], -1 \n" + "vrsub.vx v16, v16, %[vl] \n" + "sub %[src], %[src], %[byte_vl] \n" + "vle16.v v8, (%[src]) \n" + "vrgather.vv v0, v8, v16 \n" + "vse16.v v0, (%[dst]) \n" + "3: \n" + : [src] "+r"(src_uv), // %[src] + [dst] "+r"(dst_uv), // %[dst] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [byte_vl] "=&r"(byte_vl) // %[byte_vl] + : + : RVV_VL_CLOBBER "vtype", "memory", "v0", "v1", "v2", "v3", "v4", "v5", + "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23"); +} +#endif // HAS_MIRRORUVROW_RVV + +#ifdef HAS_SSIM4X4ROW_RVV +#define SSIM4X4_LOAD_RVV(ptr_a, ptr_b) \ + "vlseg4e8.v v0, (" #ptr_a \ + ") \n" \ + "vlseg4e8.v v4, (" #ptr_b \ + ") \n" \ + "vwaddu.vv v10, v0, v1 \n" \ + "vwaddu.vv v11, v2, v3 \n" \ + "vwaddu.vv v12, v4, v5 \n" \ + "vwaddu.vv v13, v6, v7 \n" \ + "vwmulu.vv v14, v0, v4 \n" \ + "vwmulu.vv v15, v1, v5 \n" \ + "vwmulu.vv v24, v2, v6 \n" \ + "vwmulu.vv v25, v3, v7 \n" \ + "vwmulu.vv v26, v0, v0 \n" \ + "vwmulu.vv v27, v1, v1 \n" \ + "vwmulu.vv v28, v2, v2 \n" \ + "vwmulu.vv v29, v3, v3 \n" \ + "vwmulu.vv v0, v4, v4 \n" \ + "vwmulu.vv v1, v5, v5 \n" \ + "vwmulu.vv v2, v6, v6 \n" \ + "vwmulu.vv v3, v7, v7 \n" + +#define SSIM4X4_ACCUM_RVV(ptr_a, ptr_b) \ + "vsetvli zero, zero, e8, mf2, ta, ma \n" \ + SSIM4X4_LOAD_RVV(ptr_a, ptr_b) \ + "vsetvli zero, zero, e16, m1, ta, ma \n" \ + "vadd.vv v10, v10, v11 \n" \ + "vadd.vv v12, v12, v13 \n" \ + "vadd.vv v8, v8, v10 \n" \ + "vadd.vv v9, v9, v12 \n" \ + "vwaddu.wv v22, v22, v14 \n" \ + "vwaddu.wv v22, v22, v15 \n" \ + "vwaddu.wv v22, v22, v24 \n" \ + "vwaddu.wv v22, v22, v25 \n" \ + "vwaddu.wv v20, v20, v26 \n" \ + "vwaddu.wv v20, v20, v27 \n" \ + "vwaddu.wv v20, v20, v28 \n" \ + "vwaddu.wv v20, v20, v29 \n" \ + "vwaddu.wv v20, v20, v0 \n" \ + "vwaddu.wv v20, v20, v1 \n" \ + "vwaddu.wv v20, v20, v2 \n" \ + "vwaddu.wv v20, v20, v3 \n" + +void Ssim4x4Row_RVV(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + size_t vl; + size_t byte_vl; + const uint8_t* tmp_a; + const uint8_t* tmp_b; + width >>= 2; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, mf2, ta, ma \n" + "add %[tmp_a], %[src_a], %[stride_a]\n" + "add %[tmp_b], %[src_b], %[stride_b]\n" + SSIM4X4_LOAD_RVV(%[src_a], %[src_b]) + "vsetvli zero, zero, e16, m1, ta, ma \n" + "vadd.vv v8, v10, v11 \n" + "vadd.vv v9, v12, v13 \n" + "vwaddu.vv v22, v14, v15 \n" + "vwaddu.wv v22, v22, v24 \n" + "vwaddu.wv v22, v22, v25 \n" + "vwaddu.vv v20, v26, v27 \n" + "vwaddu.wv v20, v20, v28 \n" + "vwaddu.wv v20, v20, v29 \n" + "vwaddu.wv v20, v20, v0 \n" + "vwaddu.wv v20, v20, v1 \n" + "vwaddu.wv v20, v20, v2 \n" + "vwaddu.wv v20, v20, v3 \n" + SSIM4X4_ACCUM_RVV(%[tmp_a], %[tmp_b]) + "add %[tmp_a], %[tmp_a], %[stride_a]\n" + "add %[tmp_b], %[tmp_b], %[stride_b]\n" + SSIM4X4_ACCUM_RVV(%[tmp_a], %[tmp_b]) + "add %[tmp_a], %[tmp_a], %[stride_a]\n" + "add %[tmp_b], %[tmp_b], %[stride_b]\n" + SSIM4X4_ACCUM_RVV(%[tmp_a], %[tmp_b]) + "vwcvtu.x.x.v v16, v8 \n" + "vwcvtu.x.x.v v18, v9 \n" + "vsetvli zero, zero, e32, m2, ta, ma \n" + "vsseg4e32.v v16, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[byte_vl], %[vl], 2 \n" + "add %[src_a], %[src_a], %[byte_vl]\n" + "add %[src_b], %[src_b], %[byte_vl]\n" + "slli %[byte_vl], %[vl], 4 \n" + "add %[dst], %[dst], %[byte_vl] \n" + "bgtz %[w], 1b \n" + : [src_a] "+r"(src_a), // %[src_a] + [src_b] "+r"(src_b), // %[src_b] + [dst] "+r"(dst), // %[dst] + [w] "+r"(width), // %[w] + [vl] "=&r"(vl), // %[vl] + [byte_vl] "=&r"(byte_vl), // %[byte_vl] + [tmp_a] "=&r"(tmp_a), // %[tmp_a] + [tmp_b] "=&r"(tmp_b) // %[tmp_b] + : [stride_a] "r"((ptrdiff_t)stride_a), // %[stride_a] + [stride_b] "r"((ptrdiff_t)stride_b) // %[stride_b] + : RVV_VL_CLOBBER "vtype", "memory", "v0", "v1", "v2", "v3", "v4", "v5", + "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", + "v27", "v28", "v29"); +} +#undef SSIM4X4_LOAD_RVV +#undef SSIM4X4_ACCUM_RVV +#endif // HAS_SSIM4X4ROW_RVV + +#ifdef HAS_SSIMWINDOWROW_RVV +float SsimWindowRow_RVV(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + size_t vl; + size_t byte_vl; + const uint32_t* row0_next = row0 + 4; + const uint32_t* row1_next = row1 + 4; + float total; + asm volatile( + "vsetvli %[vl], zero, e32, m2, ta, ma \n" + "vmv.v.i v0, 0 \n" + "vmv.s.x v4, zero \n" + "1: \n" + "vsetvli %[vl], %[w], e32, m2, tu, ma \n" + "vlseg4e32.v v8, (%[row0]) \n" + "vlseg4e32.v v16, (%[row0_next]) \n" + "vadd.vv v8, v8, v16 \n" + "vadd.vv v10, v10, v18 \n" + "vadd.vv v12, v12, v20 \n" + "vadd.vv v14, v14, v22 \n" + "vlseg4e32.v v16, (%[row1]) \n" + "vlseg4e32.v v24, (%[row1_next]) \n" + "vadd.vv v16, v16, v24 \n" + "vadd.vv v18, v18, v26 \n" + "vadd.vv v20, v20, v28 \n" + "vadd.vv v22, v22, v30 \n" + "vadd.vv v8, v8, v16 \n" + "vadd.vv v10, v10, v18 \n" + "vadd.vv v12, v12, v20 \n" + "vadd.vv v14, v14, v22 \n" + "vmul.vv v16, v8, v10 \n" + "vsll.vi v16, v16, 1 \n" + "vmul.vv v18, v8, v8 \n" + "vmacc.vv v18, v10, v10 \n" + "vsll.vi v14, v14, 7 \n" + "vsub.vv v14, v14, v16 \n" + "vadd.vx v16, v16, %[c1] \n" + "vadd.vx v14, v14, %[c2] \n" + "vsll.vi v12, v12, 6 \n" + "vsub.vv v12, v12, v18 \n" + "vadd.vx v18, v18, %[c1] \n" + "vadd.vx v12, v12, %[c2] \n" + "vfcvt.f.x.v v16, v16 \n" + "vfcvt.f.x.v v14, v14 \n" + "vfcvt.f.x.v v18, v18 \n" + "vfcvt.f.x.v v12, v12 \n" + "vfmul.vv v16, v16, v14 \n" + "vfmul.vv v18, v18, v12 \n" + "vfdiv.vv v8, v16, v18 \n" + "vfadd.vv v0, v0, v8 \n" + "sub %[w], %[w], %[vl] \n" + "slli %[byte_vl], %[vl], 4 \n" + "add %[row0], %[row0], %[byte_vl] \n" + "add %[row0_next], %[row0_next], %[byte_vl]\n" + "add %[row1], %[row1], %[byte_vl] \n" + "add %[row1_next], %[row1_next], %[byte_vl]\n" + "bgtz %[w], 1b \n" + "vsetvli %[vl], zero, e32, m2, ta, ma \n" + "vfredusum.vs v4, v0, v4 \n" + "vfmv.f.s %[total], v4 \n" + : [row0] "+r"(row0), // %[row0] + [row0_next] "+r"(row0_next), // %[row0_next] + [row1] "+r"(row1), // %[row1] + [row1_next] "+r"(row1_next), // %[row1_next] + [w] "+r"(num_windows), // %[w] + [vl] "=&r"(vl), // %[vl] + [byte_vl] "=&r"(byte_vl), // %[byte_vl] + [total] "=f"(total) // %[total] + : [c1] "r"(26634), // %[c1] + [c2] "r"(239708) // %[c2] + : "memory", RVV_VL_CLOBBER "vtype", "v0", "v1", "v4", "v8", "v9", "v10", + "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", + "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", + "v31"); + return total; +} +#endif // HAS_SSIMWINDOWROW_RVV + +#ifdef HAS_ARGBDETECTROW_RVV +uint32_t ARGBDetectRow_RVV(const uint8_t* argb, int width) { + size_t vl; + size_t byte_vl; + long idx = -1; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e32, m8, ta, ma \n" + "slli %[byte_vl], %[vl], 2 \n" + "vsetvli zero, %[byte_vl], e8, m8, ta, ma \n" + "vle8.v v8, (%[argb]) \n" + "vsetvli zero, %[vl], e32, m8, ta, ma \n" + "vor.vx v8, v8, %[mask_rgb] \n" + "sub %[w], %[w], %[vl] \n" + "add %[argb], %[argb], %[byte_vl] \n" + "vsetvli zero, %[byte_vl], e8, m8, ta, ma \n" + "vmsne.vi v0, v8, -1 \n" + "vfirst.m %[idx], v0 \n" + "bgez %[idx], 2f \n" + "bgtz %[w], 1b \n" + "2: \n" + : [argb] "+r"(argb), [w] "+r"(width), [vl] "=&r"(vl), + [byte_vl] "=&r"(byte_vl), [idx] "+r"(idx) + : [mask_rgb] "r"(0x00ffff00u) + : "memory", RVV_VL_CLOBBER "vtype", "v0", "v8", "v9", "v10", "v11", "v12", + "v13", "v14", "v15"); + if (idx >= 0) { + return (idx & 3) == 0 ? FOURCC_BGRA : FOURCC_ARGB; + } + return 0; +} +#endif // HAS_ARGBDETECTROW_RVV + +#ifdef HAS_SUMSQUAREERROR_RVV +uint32_t SumSquareError_RVV(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + size_t vl; + uint32_t sse; + asm volatile( + "vsetvli %[vl], zero, e32, m8, ta, ma \n" + "vmv.v.i v24, 0 \n" + "vmv.s.x v0, zero \n" + "1: \n" + "vsetvli %[vl], %[count], e8, m2, tu, ma \n" + "vle8.v v8, (%[src_a]) \n" + "vle8.v v10, (%[src_b]) \n" + "vwsubu.vv v12, v8, v10 \n" + "sub %[count], %[count], %[vl] \n" + "add %[src_a], %[src_a], %[vl] \n" + "add %[src_b], %[src_b], %[vl] \n" + "vsetvli zero, %[vl], e16, m4, tu, ma \n" + "vwmacc.vv v24, v12, v12 \n" + "bgtz %[count], 1b \n" + "vsetvli %[vl], zero, e32, m8, ta, ma \n" + "vredsum.vs v0, v24, v0 \n" + "vmv.x.s %[sse], v0 \n" + : [src_a] "+r"(src_a), [src_b] "+r"(src_b), [count] "+r"(count), + [vl] "=&r"(vl), [sse] "=r"(sse) + : + : "memory", RVV_VL_CLOBBER "vtype", "v0", "v8", "v9", "v10", "v11", "v12", + "v13", "v14", "v15", "v24", "v25", "v26", "v27", "v28", "v29", "v30", + "v31"); + return sse; +} +#endif // HAS_SUMSQUAREERROR_RVV + +#ifdef HAS_HAMMINGDISTANCE_RVV +static const uint8_t kNibblePopcnt_RVV[16] = {0, 1, 1, 2, 1, 2, 2, 3, + 1, 2, 2, 3, 2, 3, 3, 4}; + +uint32_t HammingDistance_RVV(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + size_t vl; + uint32_t diff; + asm volatile( + "vsetivli zero, 16, e8, m1, ta, ma \n" + "vle8.v v4, (%[lut]) \n" + "vsetvli %[vl], zero, e32, m4, ta, ma \n" + "vmv.v.i v24, 0 \n" + "vsetvli %[vl], zero, e32, m1, ta, ma \n" + "vmv.s.x v0, zero \n" + "1: \n" + "vsetvli %[vl], %[count], e8, m1, tu, ma \n" + "vle8.v v8, (%[src_a]) \n" + "vle8.v v9, (%[src_b]) \n" + "vxor.vv v8, v8, v9 \n" + "vand.vi v10, v8, 15 \n" + "vsrl.vi v8, v8, 4 \n" + "vrgather.vv v11, v4, v10 \n" + "vrgather.vv v12, v4, v8 \n" + "vwaddu.vv v16, v11, v12 \n" + "sub %[count], %[count], %[vl] \n" + "add %[src_a], %[src_a], %[vl] \n" + "add %[src_b], %[src_b], %[vl] \n" + "vsetvli zero, %[vl], e16, m2, tu, ma \n" + "vwaddu.wv v24, v24, v16 \n" + "bgtz %[count], 1b \n" + "vsetvli %[vl], zero, e32, m4, ta, ma \n" + "vredsum.vs v0, v24, v0 \n" + "vsetvli %[vl], zero, e32, m1, ta, ma \n" + "vmv.x.s %[diff], v0 \n" + : [src_a] "+r"(src_a), [src_b] "+r"(src_b), [count] "+r"(count), + [vl] "=&r"(vl), [diff] "=r"(diff) + : [lut] "r"(kNibblePopcnt_RVV) + : "memory", RVV_VL_CLOBBER "vtype", "v0", "v4", "v8", "v9", "v10", "v11", + "v12", "v16", "v17", "v24", "v25", "v26", "v27"); + return diff; +} +#endif // HAS_HAMMINGDISTANCE_RVV + +#ifdef HAS_HASHDJB2_RVV +static const uint32_t kDjb2Muls_RVV[17] = { + 0x92d9e201, // 33 ^ 16 + 0x0c3525e1, 0xa3476dc1, 0x3b4039a1, 0x4f5f0981, 0x30f35d61, 0x855cb541, + 0x040a9121, 0x747c7101, 0xec41d4e1, 0x4cfa3cc1, 0x025528a1, 0x00121881, + 0x00008c61, 0x00000441, 0x00000021, 0x00000001, +}; + +uint32_t HashDjb2_RVV(const uint8_t* src, int count, uint32_t seed) { + uint32_t hash = seed; + uint32_t tmp; + const uint32_t c16 = 0x92d9e201u; + const int rem = count & 15; + const uint32_t* tail_muls = &kDjb2Muls_RVV[17 - rem]; + const uint32_t pow_n = kDjb2Muls_RVV[16 - rem]; + asm volatile( + "vsetivli zero, 16, e32, m4, ta, ma \n" + "vmv.s.x v4, zero \n" + "addi %[count], %[count], -16 \n" + "bltz %[count], 2f \n" + "vle32.v v16, (%[muls16]) \n" + "1: \n" + "vle8.v v8, (%[src]) \n" + "vzext.vf4 v12, v8 \n" + "vmul.vv v12, v12, v16 \n" + "vredsum.vs v0, v12, v4 \n" + "vmv.x.s %[tmp], v0 \n" + "mul %[hash], %[hash], %[c16] \n" + "add %[hash], %[hash], %[tmp] \n" + "addi %[src], %[src], 16 \n" + "addi %[count], %[count], -16 \n" + "bgez %[count], 1b \n" + "2: \n" + "addi %[count], %[count], 16 \n" + "beqz %[count], 3f \n" + "vsetvli zero, %[count], e32, m4, ta, ma \n" + "vle32.v v16, (%[tail_muls]) \n" + "vle8.v v8, (%[src]) \n" + "vzext.vf4 v12, v8 \n" + "vmul.vv v12, v12, v16 \n" + "vredsum.vs v0, v12, v4 \n" + "vmv.x.s %[tmp], v0 \n" + "mul %[hash], %[hash], %[pow_n] \n" + "add %[hash], %[hash], %[tmp] \n" + "3: \n" + : + [src] "+r"(src), [count] "+r"(count), [hash] "+r"(hash), [tmp] "=&r"(tmp) + : [muls16] "r"(kDjb2Muls_RVV + 1), [c16] "r"(c16), + [tail_muls] "r"(tail_muls), [pow_n] "r"(pow_n) + : "memory", RVV_VL_CLOBBER "vtype", "v0", "v4", "v8", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19"); + return hash; +} +#endif // HAS_HASHDJB2_RVV + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_RVV) && defined(__riscv_vector) diff --git a/libs/libyuv/source/row_sme.cc b/libs/libyuv/source/row_sme.cc new file mode 100644 index 0000000000..21abac9220 --- /dev/null +++ b/libs/libyuv/source/row_sme.cc @@ -0,0 +1,1169 @@ +/* + * Copyright 2024 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/compare_row.h" +#include "libyuv/row.h" +#include "libyuv/row_sve.h" + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + +#if !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && \ + defined(__aarch64__) + +#define RGBTOARGB8_SVE_2X \ + /* Inputs: B: z16.h, G: z17.h, R: z18.h, A: z19.b */ \ + "uqshrnb z16.b, z16.h, #6 \n" /* B0 */ \ + "uqshrnb z17.b, z17.h, #6 \n" /* G0 */ \ + "uqshrnb z18.b, z18.h, #6 \n" /* R0 */ \ + "uqshrnt z16.b, z20.h, #6 \n" /* B1 */ \ + "uqshrnt z17.b, z21.h, #6 \n" /* G1 */ \ + "uqshrnt z18.b, z22.h, #6 \n" /* R1 */ + +__arm_locally_streaming void I444ToARGBRow_SME( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + // Streaming-SVE only, no use of ZA tile. + uint64_t vl; + asm volatile( + "cntb %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // A + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.b \n" + "1: \n" // + READYUV444_SVE_2X I444TORGB_SVE_2X RGBTOARGB8_SVE_2X + "subs %w[width], %w[width], %w[vl] \n" + "st4b {z16.b, z17.b, z18.b, z19.b}, p1, [%[dst_argb]] \n" + "incb %[dst_argb], all, mul #4 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.b, wzr, %w[width] \n" // + READYUV444_SVE_2X I444TORGB_SVE_2X RGBTOARGB8_SVE_2X + "st4b {z16.b, z17.b, z18.b, z19.b}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +__arm_locally_streaming void I444ToRGB24Row_SME( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + I444ToRGB24Row_SVE_SC(src_y, src_u, src_v, dst_rgb24, yuvconstants, width); +} + +__arm_locally_streaming void I400ToARGBRow_SME( + const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + // Streaming-SVE only, no use of ZA tile. + I400ToARGBRow_SVE_SC(src_y, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void I422ToARGBRow_SME( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + // Streaming-SVE only, no use of ZA tile. + I422ToARGBRow_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void I422ToRGB24Row_SME( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I422ToRGB24Row_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void I422ToRGB565Row_SME( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width) { + I422ToRGB565Row_SVE_SC(src_y, src_u, src_v, dst_rgb565, yuvconstants, width); +} + +__arm_locally_streaming void I422ToARGB1555Row_SME( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width) { + I422ToARGB1555Row_SVE_SC(src_y, src_u, src_v, dst_argb1555, yuvconstants, + width); +} + +__arm_locally_streaming void I422ToARGB4444Row_SME( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width) { + I422ToARGB4444Row_SVE_SC(src_y, src_u, src_v, dst_argb4444, yuvconstants, + width); +} + +__arm_locally_streaming void I422ToRGBARow_SME( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I422ToRGBARow_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void I422ToAR30Row_SME( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I422ToAR30Row_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void I422AlphaToARGBRow_SME( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I422AlphaToARGBRow_SVE_SC(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); +} + +__arm_locally_streaming void I444AlphaToARGBRow_SME( + const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I444AlphaToARGBRow_SVE_SC(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); +} + +__arm_locally_streaming void NV12ToARGBRow_SME( + const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + NV12ToARGBRow_SVE_SC(src_y, src_uv, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void NV21ToARGBRow_SME( + const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + NV21ToARGBRow_SVE_SC(src_y, src_vu, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void NV12ToRGB24Row_SME( + const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + NV12ToRGB24Row_SVE_SC(src_y, src_uv, dst_rgb24, yuvconstants, width); +} + +__arm_locally_streaming void NV21ToRGB24Row_SME( + const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + NV21ToRGB24Row_SVE_SC(src_y, src_vu, dst_rgb24, yuvconstants, width); +} + +__arm_locally_streaming void YUY2ToARGBRow_SME( + const uint8_t* src_yuy2, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUY2ToARGBRow_SVE_SC(src_yuy2, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void UYVYToARGBRow_SME( + const uint8_t* src_uyvy, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + UYVYToARGBRow_SVE_SC(src_uyvy, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void I210ToARGBRow_SME( + const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I210ToARGBRow_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void I210AlphaToARGBRow_SME( + const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I210AlphaToARGBRow_SVE_SC(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); +} + +__arm_locally_streaming void I210ToAR30Row_SME( + const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + I210ToAR30Row_SVE_SC(src_y, src_u, src_v, dst_ar30, yuvconstants, width); +} + +__arm_locally_streaming void P210ToARGBRow_SME( + const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + P210ToARGBRow_SVE_SC(src_y, src_uv, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void P210ToAR30Row_SME( + const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + P210ToAR30Row_SVE_SC(src_y, src_uv, dst_ar30, yuvconstants, width); +} + +__arm_locally_streaming void I410ToARGBRow_SME( + const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I410ToARGBRow_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void I410AlphaToARGBRow_SME( + const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I410AlphaToARGBRow_SVE_SC(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); +} + +__arm_locally_streaming void I410ToAR30Row_SME( + const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + I410ToAR30Row_SVE_SC(src_y, src_u, src_v, dst_ar30, yuvconstants, width); +} + +__arm_locally_streaming void P410ToARGBRow_SME( + const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + P410ToARGBRow_SVE_SC(src_y, src_uv, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void P410ToAR30Row_SME( + const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + P410ToAR30Row_SVE_SC(src_y, src_uv, dst_ar30, yuvconstants, width); +} + +__arm_locally_streaming void I212ToAR30Row_SME( + const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + I212ToAR30Row_SVE_SC(src_y, src_u, src_v, dst_ar30, yuvconstants, width); +} + +__arm_locally_streaming void I212ToARGBRow_SME( + const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I212ToARGBRow_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +__arm_locally_streaming void MultiplyRow_16_SME(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + // Streaming-SVE only, no use of ZA tile. + int vl; + asm volatile( + "cnth %x[vl] \n" + "mov z0.h, %w[scale] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p0.h \n" + "1: \n" + "ld1h {z1.h}, p0/z, [%[src_y]] \n" + "incb %[src_y] \n" + "mul z1.h, z0.h, z1.h \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1h {z1.h}, p0, [%[dst_y]] \n" + "incb %[dst_y] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p0.h, wzr, %w[width] \n" + "ld1h {z1.h}, p0/z, [%[src_y]] \n" + "mul z1.h, z0.h, z1.h \n" + "st1h {z1.h}, p0, [%[dst_y]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [dst_y] "+r"(dst_y), // %[dst_y] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [scale] "r"(scale) // %[scale] + : "memory", "cc", "z0", "z1", "p0"); +} + +__arm_locally_streaming void ARGBMultiplyRow_SME(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + // Streaming-SVE only, no use of ZA tile. + width *= 4; + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p0.b \n" + "1: \n" + "ld1b {z0.b}, p0/z, [%[src_argb]] \n" + "ld1b {z1.b}, p0/z, [%[src_argb1]] \n" + "incb %[src_argb] \n" + "incb %[src_argb1] \n" + "umullb z2.h, z0.b, z1.b \n" + "umullt z1.h, z0.b, z1.b \n" + "rshrnb z0.b, z2.h, #8 \n" + "rshrnt z0.b, z1.h, #8 \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1b {z0.b}, p0, [%[dst_argb]] \n" + "incb %[dst_argb] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p0.b, wzr, %w[width] \n" + "ld1b {z0.b}, p0/z, [%[src_argb]] \n" + "ld1b {z1.b}, p0/z, [%[src_argb1]] \n" + "umullb z2.h, z0.b, z1.b \n" + "umullt z1.h, z0.b, z1.b \n" + "rshrnb z0.b, z2.h, #8 \n" + "rshrnt z0.b, z1.h, #8 \n" + "st1b {z0.b}, p0, [%[dst_argb]] \n" + + "99: \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [src_argb1] "+r"(src_argb1), // %[src_argb1] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "z2", "p0", "p1"); +} + +__arm_locally_streaming void MergeUVRow_SME(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width) { + // Streaming-SVE only, no use of ZA tile. + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p0.b \n" + "1: \n" + "ld1b {z1.b}, p0/z, [%[src_u]] \n" + "ld1b {z2.b}, p0/z, [%[src_v]] \n" + "incb %[src_u] \n" + "incb %[src_v] \n" + "subs %w[width], %w[width], %w[vl] \n" + "st2b {z1.b, z2.b}, p0, [%[dst_uv]] \n" + "incb %[dst_uv], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p0.b, wzr, %w[width] \n" + "ld1b {z1.b}, p0/z, [%[src_u]] \n" + "ld1b {z2.b}, p0/z, [%[src_v]] \n" + "subs %w[width], %w[width], %w[vl] \n" + "st2b {z1.b, z2.b}, p0, [%[dst_uv]] \n" + + "99: \n" + : [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "z2", "p0"); +} + +__arm_locally_streaming void MergeUVRow_16_SME(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width) { + int shift = 16 - depth; + // Streaming-SVE only, no use of ZA tile. + int vl; + asm volatile( + "cnth %x[vl] \n" + "mov z0.h, %w[shift] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p0.h \n" + "1: \n" + "ld1h {z1.h}, p0/z, [%[src_u]] \n" + "ld1h {z2.h}, p0/z, [%[src_v]] \n" + "incb %[src_u] \n" + "incb %[src_v] \n" + "lsl z1.h, p0/m, z1.h, z0.h \n" + "lsl z2.h, p0/m, z2.h, z0.h \n" + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z1.h, z2.h}, p0, [%[dst_uv]] \n" + "incb %[dst_uv], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p0.h, wzr, %w[width] \n" + "ld1h {z1.h}, p0/z, [%[src_u]] \n" + "ld1h {z2.h}, p0/z, [%[src_v]] \n" + "lsl z1.h, p0/m, z1.h, z0.h \n" + "lsl z2.h, p0/m, z2.h, z0.h \n" + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z1.h, z2.h}, p0, [%[dst_uv]] \n" + + "99: \n" + : [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [shift] "r"(shift) // %[shift] + : "memory", "cc", "z0", "z1", "z2", "p0"); +} + +// Use scale to convert lsb formats to msb, depending how many bits there are: +// 32768 = 9 bits = shr 1 +// 16384 = 10 bits = shr 2 +// 4096 = 12 bits = shr 4 +// 256 = 16 bits = shr 8 +__arm_locally_streaming void Convert16To8Row_SME(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width) { + // 15 - clz(scale), + 8 to shift result into the high half of the lane to + // saturate, then we can just use UZP2 to narrow rather than a pair of + // saturating narrow instructions. + const int shift = 23 - __builtin_clz((int32_t)scale); + int vl; + asm volatile( + "cntb %x[vl] \n" + "dup z0.h, %w[shift] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p0.b \n" + "1: \n" + "ld1h {z1.h}, p0/z, [%[src_y]] \n" + "ld1h {z2.h}, p0/z, [%[src_y], #1, mul vl] \n" + "incb %[src_y], all, mul #2 \n" + "uqshl z1.h, p0/m, z1.h, z0.h \n" + "uqshl z2.h, p0/m, z2.h, z0.h \n" + "subs %w[width], %w[width], %w[vl] \n" + "uzp2 z1.b, z1.b, z2.b \n" + "st1b {z1.b}, p0, [%[dst_y]] \n" + "incb %[dst_y] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + // We need separate predicates for the load and store instructions since + // they are operating on different element sizes (.b vs .h). + "cnth %x[vl] \n" + "whilelt p0.h, wzr, %w[width] \n" + "whilelt p1.h, %w[vl], %w[width] \n" + "whilelt p2.b, wzr, %w[width] \n" + "ld1h {z1.h}, p0/z, [%[src_y]] \n" + "ld1h {z2.h}, p1/z, [%[src_y], #1, mul vl] \n" + "uqshl z1.h, p0/m, z1.h, z0.h \n" + "uqshl z2.h, p1/m, z2.h, z0.h \n" + "uzp2 z1.b, z1.b, z2.b \n" + "st1b {z1.b}, p2, [%[dst_y]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [dst_y] "+r"(dst_y), // %[dst_y] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [shift] "r"(shift) // %[shift] + : "cc", "memory", "z0", "z1", "z2", "p0", "p1", "p2"); +} + +__arm_locally_streaming void CopyRow_SME(const uint8_t* src, + uint8_t* dst, + int width) { + // Streaming-SVE only, no use of ZA tile. + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p0.b \n" + "1: \n" + "ld1b {z0.b}, p0/z, [%[src]] \n" + "incb %[src] \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1b {z0.b}, p0, [%[dst]] \n" + "incb %[dst] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p0.b, wzr, %w[width] \n" + "ld1b {z0.b}, p0/z, [%[src]] \n" + "st1b {z0.b}, p0, [%[dst]] \n" + + "99: \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "memory", "cc", "z0", "p0"); +} + +__arm_locally_streaming static void HalfRow_SME(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width) { + const uint8_t* src_ptr1 = src_ptr + src_stride; + + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p0.b \n" + "1: \n" + "ld1b {z2.b}, p0/z, [%[src_ptr]] \n" + "ld1b {z3.b}, p0/z, [%[src_ptr1]] \n" + "incb %[src_ptr] \n" + "incb %[src_ptr1] \n" + "urhadd z2.b, p0/m, z2.b, z3.b \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1b {z2.b}, p0, [%[dst_ptr]] \n" + "incb %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p0.b, wzr, %w[width] \n" + "ld1b {z2.b}, p0/z, [%[src_ptr]] \n" + "ld1b {z3.b}, p0/z, [%[src_ptr1]] \n" + "urhadd z2.b, p0/m, z2.b, z3.b \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1b {z2.b}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "+r"(src_ptr1), // %[src_ptr1] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "cc", "memory", "z0", "z1", "z2", "z3", "p0"); +} + +__arm_locally_streaming void InterpolateRow_SME(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + int y1_fraction = source_y_fraction; + int y0_fraction = 256 - y1_fraction; + const uint8_t* src_ptr1 = src_ptr + src_stride; + + if (y0_fraction == 0) { + CopyRow_SME(src_ptr1, dst_ptr, width); + return; + } + if (y0_fraction == 128) { + HalfRow_SME(dst_ptr, src_ptr, src_stride, width); + return; + } + if (y0_fraction == 256) { + CopyRow_SME(src_ptr, dst_ptr, width); + return; + } + + int vl; + asm volatile( + "cntb %x[vl] \n" + "dup z0.b, %w[y0_fraction] \n" + "dup z1.b, %w[y1_fraction] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p0.b \n" + "1: \n" + "ld1b {z2.b}, p0/z, [%[src_ptr]] \n" + "ld1b {z3.b}, p0/z, [%[src_ptr1]] \n" + "incb %[src_ptr] \n" + "incb %[src_ptr1] \n" + "umullb z4.h, z2.b, z0.b \n" + "umullt z2.h, z2.b, z0.b \n" + "subs %w[width], %w[width], %w[vl] \n" + "umlalb z4.h, z3.b, z1.b \n" + "umlalt z2.h, z3.b, z1.b \n" + "rshrnb z3.b, z4.h, #8 \n" + "rshrnt z3.b, z2.h, #8 \n" + "st1b {z3.b}, p0, [%[dst_ptr]] \n" + "incb %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p0.b, wzr, %w[width] \n" + "ld1b {z2.b}, p0/z, [%[src_ptr]] \n" + "ld1b {z3.b}, p0/z, [%[src_ptr1]] \n" + "umullb z4.h, z2.b, z0.b \n" + "umullt z2.h, z2.b, z0.b \n" + "umlalb z4.h, z3.b, z1.b \n" + "umlalt z2.h, z3.b, z1.b \n" + "rshrnb z3.b, z4.h, #8 \n" + "rshrnt z3.b, z2.h, #8 \n" + "st1b {z3.b}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "+r"(src_ptr1), // %[src_ptr1] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [y0_fraction] "r"(y0_fraction), // %[y0_fraction] + [y1_fraction] "r"(y1_fraction) // %[y1_fraction] + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "p0"); +} + +__arm_locally_streaming static void HalfRow_16_SME(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width) { + const uint16_t* src_ptr1 = src_ptr + src_stride; + + int vl; + asm volatile( + "cnth %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p0.h \n" + "1: \n" + "ld1h {z2.h}, p0/z, [%[src_ptr]] \n" + "ld1h {z3.h}, p0/z, [%[src_ptr1]] \n" + "incb %[src_ptr] \n" + "incb %[src_ptr1] \n" + "urhadd z2.h, p0/m, z2.h, z3.h \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1h {z2.h}, p0, [%[dst_ptr]] \n" + "incb %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p0.h, wzr, %w[width] \n" + "ld1h {z2.h}, p0/z, [%[src_ptr]] \n" + "ld1h {z3.h}, p0/z, [%[src_ptr1]] \n" + "urhadd z2.h, p0/m, z2.h, z3.h \n" + "st1h {z2.h}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "+r"(src_ptr1), // %[src_ptr1] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "cc", "memory", "z0", "z1", "z2", "z3", "p0"); +} + +__arm_locally_streaming void InterpolateRow_16_SME(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + int y1_fraction = source_y_fraction; + int y0_fraction = 256 - y1_fraction; + const uint16_t* src_ptr1 = src_ptr + src_stride; + + if (y0_fraction == 0) { + CopyRow_SME((const uint8_t*)src_ptr1, (uint8_t*)dst_ptr, + width * sizeof(uint16_t)); + return; + } + if (y0_fraction == 128) { + HalfRow_16_SME(dst_ptr, src_ptr, src_stride, width); + return; + } + if (y0_fraction == 256) { + CopyRow_SME((const uint8_t*)src_ptr, (uint8_t*)dst_ptr, + width * sizeof(uint16_t)); + return; + } + + int vl; + asm volatile( + "cnth %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "dup z0.h, %w[y0_fraction] \n" + "dup z1.h, %w[y1_fraction] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p0.h \n" + "1: \n" + "ld1h {z2.h}, p0/z, [%[src_ptr]] \n" + "ld1h {z3.h}, p0/z, [%[src_ptr1]] \n" + "incb %[src_ptr] \n" + "incb %[src_ptr1] \n" + "umullb z4.s, z2.h, z0.h \n" + "umullt z2.s, z2.h, z0.h \n" + "subs %w[width], %w[width], %w[vl] \n" + "umlalb z4.s, z3.h, z1.h \n" + "umlalt z2.s, z3.h, z1.h \n" + "rshrnb z3.h, z4.s, #8 \n" + "rshrnt z3.h, z2.s, #8 \n" + "st1h {z3.h}, p0, [%[dst_ptr]] \n" + "incb %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p0.h, wzr, %w[width] \n" + "ld1h {z2.h}, p0/z, [%[src_ptr]] \n" + "ld1h {z3.h}, p0/z, [%[src_ptr1]] \n" + "umullb z4.s, z2.h, z0.h \n" + "umullt z2.s, z2.h, z0.h \n" + "umlalb z4.s, z3.h, z1.h \n" + "umlalt z2.s, z3.h, z1.h \n" + "rshrnb z3.h, z4.s, #8 \n" + "rshrnt z3.h, z2.s, #8 \n" + "st1h {z3.h}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "+r"(src_ptr1), // %[src_ptr1] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [y0_fraction] "r"(y0_fraction), // %[y0_fraction] + [y1_fraction] "r"(y1_fraction) // %[y1_fraction] + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "p0"); +} + +__arm_locally_streaming void HalfRow_16To8_SME(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int scale, + int width) { + const uint16_t* src_ptr1 = src_ptr + src_stride; + + // 15 - clz(scale), + 8 to shift result into the high half of the lane to + // saturate, then we can just use UZP2 to narrow rather than a pair of + // saturating narrow instructions. + const int shift = 23 - __builtin_clz((int32_t)scale); + + int vl; + asm volatile( + "cnth %x[vl] \n" + "dup z31.h, %w[shift] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p0.h \n" + "1: \n" + "ld1h {z2.h}, p0/z, [%[src_ptr]] \n" + "ld1h {z3.h}, p0/z, [%[src_ptr1]] \n" + "incb %[src_ptr] \n" + "incb %[src_ptr1] \n" + "urhadd z2.h, p0/m, z2.h, z3.h \n" + "subs %w[width], %w[width], %w[vl] \n" + "uqshl z2.h, p0/m, z2.h, z31.h \n" + "shrnb z2.b, z2.h, #8 \n" + "st1b {z2.h}, p0, [%[dst_ptr]] \n" + "inch %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p0.h, wzr, %w[width] \n" + "ld1h {z2.h}, p0/z, [%[src_ptr]] \n" + "ld1h {z3.h}, p0/z, [%[src_ptr1]] \n" + "urhadd z2.h, p0/m, z2.h, z3.h \n" + "uqshl z2.h, p0/m, z2.h, z31.h \n" + "shrnb z2.b, z2.h, #8 \n" + "st1b {z2.h}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "+r"(src_ptr1), // %[src_ptr1] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [shift] "r"(shift) // %[shift] + : "cc", "memory", "z0", "z1", "z2", "z3", "z31", "p0"); +} + +__arm_locally_streaming void HalfWidthRow_16To8_SME(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int scale, + int width) { + const uint16_t* src_ptr1 = src_ptr + src_stride; + const int shift = 23 - __builtin_clz((int32_t)scale); + int vl; + asm volatile( + "cnth %x[vl] \n" + "dup z31.h, %w[shift] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.h \n" + "1: \n" + "ld2h {z0.h, z1.h}, p0/z, [%[src_ptr]] \n" + "ld2h {z2.h, z3.h}, p0/z, [%[src_ptr1]] \n" + "incb %[src_ptr], all, mul #2 \n" + "incb %[src_ptr1], all, mul #2 \n" + "uaddlb z4.s, z0.h, z1.h \n" + "uaddlt z5.s, z0.h, z1.h \n" + "uaddlb z6.s, z2.h, z3.h \n" + "uaddlt z7.s, z2.h, z3.h \n" + "add z4.s, z4.s, z6.s \n" + "add z5.s, z5.s, z7.s \n" + "rshrnb z0.h, z4.s, #2 \n" + "rshrnt z0.h, z5.s, #2 \n" + "subs %w[width], %w[width], %w[vl] \n" + "uqshl z0.h, p0/m, z0.h, z31.h \n" + "shrnb z0.b, z0.h, #8 \n" + "st1b {z0.h}, p0, [%[dst_ptr]] \n" + "inch %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.h, wzr, %w[width] \n" + "ld2h {z0.h, z1.h}, p0/z, [%[src_ptr]] \n" + "ld2h {z2.h, z3.h}, p0/z, [%[src_ptr1]] \n" + "uaddlb z4.s, z0.h, z1.h \n" + "uaddlt z5.s, z0.h, z1.h \n" + "uaddlb z6.s, z2.h, z3.h \n" + "uaddlt z7.s, z2.h, z3.h \n" + "add z4.s, z4.s, z6.s \n" + "add z5.s, z5.s, z7.s \n" + "rshrnb z0.h, z4.s, #2 \n" + "rshrnt z0.h, z5.s, #2 \n" + "uqshl z0.h, p0/m, z0.h, z31.h \n" + "shrnb z0.b, z0.h, #8 \n" + "st1b {z0.h}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "+r"(src_ptr1), // %[src_ptr1] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [shift] "r"(shift) // %[shift] + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z31", + "p0"); +} + +__arm_locally_streaming void Convert8To8Row_SME(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width) { + Convert8To8Row_SVE_SC(src_y, dst_y, scale, bias, width); +} + +#define CONVERT8TO16_SVE \ + "ld1b {z0.h}, p0/z, [%[src]] \n" \ + "ld1b {z1.h}, p1/z, [%[src], #1, mul vl] \n" \ + "incb %[src] \n" \ + "subs %w[width], %w[width], %w[vl], lsl #1 \n" \ + "trn1 z0.b, z0.b, z0.b \n" \ + "trn1 z1.b, z1.b, z1.b \n" \ + "lsr z0.h, p0/m, z0.h, z2.h \n" \ + "lsr z1.h, p1/m, z1.h, z2.h \n" \ + "prfm pldl1keep, [%[src], 448] \n" \ + "st1h {z0.h}, p0, [%[dst]] \n" \ + "st1h {z1.h}, p1, [%[dst], #1, mul vl] \n" \ + "incb %[dst], all, mul #2 \n" + +__arm_locally_streaming void Convert8To16Row_SME(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width) { + // (src * 0x0101) >> (16 - bits). + const int shift = 16 - bits; + + uint64_t vl; + asm volatile( + "dup z2.h, %w[shift] \n" + "cnth %[vl] \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.lt 2f \n" + + // Run bulk of computation with all-true predicates to avoid predicate + // generation overhead. + "ptrue p0.h \n" + "ptrue p1.h \n" + "1: \n" // + CONVERT8TO16_SVE + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #1 \n" + "b.eq 99f \n" + + // Calculate predicates for the final iteration to deal with the tail. + "whilelt p0.h, wzr, %w[width] \n" + "whilelt p1.h, %w[vl], %w[width] \n" // + CONVERT8TO16_SVE + + "99: \n" + : [src] "+r"(src_y), // %[src] + [dst] "+r"(dst_y), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [shift] "r"(shift) // %[shift] + : "cc", "memory", "z0", "z1", "z2", "p0", "p1"); +} + +__arm_locally_streaming void ARGBToUVMatrixRow_SME( + const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + int8_t uvconstants[8] = {(int8_t)c->kRGBToU[0], (int8_t)c->kRGBToU[1], + (int8_t)c->kRGBToU[2], (int8_t)c->kRGBToU[3], + (int8_t)c->kRGBToV[0], (int8_t)c->kRGBToV[1], + (int8_t)c->kRGBToV[2], (int8_t)c->kRGBToV[3]}; + ARGBToUVMatrixRow_SVE_SC(src_argb, src_stride_argb, dst_u, dst_v, width, + uvconstants); +} + +__arm_locally_streaming void ARGBToYMatrixRow_SME( + const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + ARGBToYMatrixRow_SVE_SC(src_argb, dst_y, width, c); +} + +#ifdef HAS_SSIM4X4ROW_SME +__arm_locally_streaming void Ssim4x4Row_SME(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + Ssim4x4Row_SVE_SC(src_a, stride_a, src_b, stride_b, dst, width); +} +#endif // HAS_SSIM4X4ROW_SME + +#ifdef HAS_SSIMWINDOWROW_SME +__arm_locally_streaming float SsimWindowRow_SME(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + return SsimWindowRow_SVE_SC(row0, row1, num_windows); +} +#endif // HAS_SSIMWINDOWROW_SME + +#ifdef HAS_ARGBORROW_SME +__arm_locally_streaming void ARGBOrRow_SME(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + ARGBOrRow_SVE_SC(src_argb, dst_argb, value, width); +} +#endif // HAS_ARGBORROW_SME + +#ifdef HAS_ARGBALPHABLENDROW_SME +__arm_locally_streaming void ARGBAlphaBlendRow_SME(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + ARGBAlphaBlendRow_SVE_SC(src_argb0, src_argb1, dst_argb, width); +} +#endif // HAS_ARGBALPHABLENDROW_SME + +#endif // !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && + // defined(__aarch64__) + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif diff --git a/libs/libyuv/source/row_sve.cc b/libs/libyuv/source/row_sve.cc new file mode 100644 index 0000000000..cb5f739934 --- /dev/null +++ b/libs/libyuv/source/row_sve.cc @@ -0,0 +1,1785 @@ +/* + * Copyright 2024 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "libyuv/row_sve.h" +#include "libyuv/compare_row.h" +#include "libyuv/row.h" + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + +#if !defined(LIBYUV_DISABLE_SVE) && defined(__aarch64__) + +#define RGBTOARGB8_SVE_2X \ + /* Inputs: B: z16.h, G: z17.h, R: z18.h, A: z19.b */ \ + "uqshrnb z16.b, z16.h, #6 \n" /* B0 */ \ + "uqshrnb z17.b, z17.h, #6 \n" /* G0 */ \ + "uqshrnb z18.b, z18.h, #6 \n" /* R0 */ \ + "uqshrnt z16.b, z20.h, #6 \n" /* B1 */ \ + "uqshrnt z17.b, z21.h, #6 \n" /* G1 */ \ + "uqshrnt z18.b, z22.h, #6 \n" /* R1 */ + +#define RGBTOARGB8_SVE_TOP_2X \ + /* Inputs: B: z16.h, G: z17.h, R: z18.h */ \ + "uqshl z16.h, p0/m, z16.h, #2 \n" /* B0 */ \ + "uqshl z17.h, p0/m, z17.h, #2 \n" /* G0 */ \ + "uqshl z18.h, p0/m, z18.h, #2 \n" /* R0 */ \ + "uqshl z20.h, p0/m, z20.h, #2 \n" /* B1 */ \ + "uqshl z21.h, p0/m, z21.h, #2 \n" /* G1 */ \ + "uqshl z22.h, p0/m, z22.h, #2 \n" /* R1 */ + +void I444ToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + uint64_t vl; + asm volatile( + "cnth %[vl] \n" + "ptrue p0.b \n" // + YUVTORGB_SVE_SETUP + "dup z19.b, #255 \n" // Alpha + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with an all-true predicate to avoid predicate + // generation overhead. + "ptrue p1.h \n" + "1: \n" // + READYUV444_SVE I4XXTORGB_SVE RGBTOARGB8_SVE + "subs %w[width], %w[width], %w[vl] \n" + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + "add %[dst_argb], %[dst_argb], %[vl], lsl #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p1.h, wzr, %w[width] \n" // + READYUV444_SVE I4XXTORGB_SVE RGBTOARGB8_SVE + "st2h {z16.h, z17.h}, p1, [%[dst_argb]] \n" + + "99: \n" + : [src_y] "+r"(src_y), // %[src_y] + [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kUVCoeff] "r"(&yuvconstants->kUVCoeff), // %[kUVCoeff] + [kRGBCoeffBias] "r"(&yuvconstants->kRGBCoeffBias) // %[kRGBCoeffBias] + : "cc", "memory", YUVTORGB_SVE_REGS); +} + +void I444ToRGB24Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + I444ToRGB24Row_SVE_SC(src_y, src_u, src_v, dst_rgb24, yuvconstants, width); +} + +void I400ToARGBRow_SVE2(const uint8_t* src_y, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I400ToARGBRow_SVE_SC(src_y, dst_argb, yuvconstants, width); +} + +void I422ToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I422ToARGBRow_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +void I422ToRGB24Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I422ToRGB24Row_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +void I422ToRGB565Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width) { + I422ToRGB565Row_SVE_SC(src_y, src_u, src_v, dst_rgb565, yuvconstants, width); +} + +void I422ToARGB1555Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width) { + I422ToARGB1555Row_SVE_SC(src_y, src_u, src_v, dst_argb1555, yuvconstants, + width); +} + +void I422ToARGB4444Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width) { + I422ToARGB4444Row_SVE_SC(src_y, src_u, src_v, dst_argb4444, yuvconstants, + width); +} + +void I422ToRGBARow_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width) { + I422ToRGBARow_SVE_SC(src_y, src_u, src_v, dst_rgba, yuvconstants, width); +} + +void I422ToAR30Row_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I422ToAR30Row_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +void I422AlphaToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I422AlphaToARGBRow_SVE_SC(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); +} + +void I444AlphaToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + const uint8_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I444AlphaToARGBRow_SVE_SC(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); +} + +void NV12ToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + NV12ToARGBRow_SVE_SC(src_y, src_uv, dst_argb, yuvconstants, width); +} + +void NV21ToARGBRow_SVE2(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + NV21ToARGBRow_SVE_SC(src_y, src_vu, dst_argb, yuvconstants, width); +} + +void NV12ToRGB24Row_SVE2(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + NV12ToRGB24Row_SVE_SC(src_y, src_uv, dst_rgb24, yuvconstants, width); +} + +void NV21ToRGB24Row_SVE2(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + NV21ToRGB24Row_SVE_SC(src_y, src_vu, dst_rgb24, yuvconstants, width); +} + +void ARGBToUVMatrixRow_SVE2(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + int8_t uvconstants[8] = {(int8_t)c->kRGBToU[0], (int8_t)c->kRGBToU[1], + (int8_t)c->kRGBToU[2], (int8_t)c->kRGBToU[3], + (int8_t)c->kRGBToV[0], (int8_t)c->kRGBToV[1], + (int8_t)c->kRGBToV[2], (int8_t)c->kRGBToV[3]}; + ARGBToUVMatrixRow_SVE_SC(src_argb, src_stride_argb, dst_u, dst_v, width, + uvconstants); +} + +void ARGBToYMatrixRow_SVE2(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + ARGBToYMatrixRow_SVE_SC(src_argb, dst_y, width, c); +} + +#define ARGBTORGB565_SVE \ + /* Inputs: \ + * z0: rrrrrxxxbbbbbxxx \ + * z1: xxxxxxxxggggggxx \ + * z3: 0000000000000011 (3, 0, 3, 0, ...) \ + * z4: 0000011111100000 \ + */ \ + "lsr z0.b, p0/m, z0.b, z3.b \n" \ + "lsl z1.h, z1.h, #3 \n" \ + "bsl z1.d, z1.d, z0.d, z4.d \n" + +void ARGBToRGB565Row_SVE2(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width) { + unsigned bsl_mask = 0x7e0; + uint64_t vl; + width *= 2; + asm volatile( + "mov z3.h, #3 \n" + "dup z4.h, %w[bsl_mask] \n" + + "cntb %[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "1: \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src]] \n" // BR, GA + "incb %[src], all, mul #2 \n" + "subs %w[width], %w[width], %w[vl] \n" // + ARGBTORGB565_SVE + "st1b {z1.b}, p0, [%[dst]] \n" + "incb %[dst] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[width] \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src]] \n" // BR, GA + ARGBTORGB565_SVE + "st1b {z1.b}, p0, [%[dst]] \n" + + "99: \n" + : [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_rgb), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [bsl_mask] "r"(bsl_mask) // %[bsl_mask] + : "cc", "memory", "z0", "z1", "z3", "z4", "p0"); +} + +void ARGBToRGB565DitherRow_SVE2(const uint8_t* src_argb, + uint8_t* dst_rgb, + uint32_t dither4, + int width) { + unsigned bsl_mask = 0x7e0; + uint64_t vl; + width *= 2; + asm volatile( + "mov z3.h, #3 \n" + "dup z4.h, %w[bsl_mask] \n" + "dup z2.s, %w[dither4] \n" + "zip1 z2.b, z2.b, z2.b \n" + + "cntb %[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "1: \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src]] \n" // BR, GA + "incb %[src], all, mul #2 \n" + "uqadd z0.b, z0.b, z2.b \n" + "uqadd z1.b, z1.b, z2.b \n" + "subs %w[width], %w[width], %w[vl] \n" // + ARGBTORGB565_SVE + "st1b {z1.b}, p0, [%[dst]] \n" + "incb %[dst] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[width] \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src]] \n" // BR, GA + "uqadd z0.b, z0.b, z2.b \n" + "uqadd z1.b, z1.b, z2.b \n" // + ARGBTORGB565_SVE + "st1b {z1.b}, p0, [%[dst]] \n" + + "99: \n" + : [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_rgb), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [bsl_mask] "r"(bsl_mask), // %[bsl_mask] + [dither4] "r"(dither4) // %[dither4] + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "p0"); +} + +#define ARGB1555TOARGB \ + /* Input: z1/z3.h = arrrrrgggggbbbbb */ \ + "lsl z0.h, z1.h, #3 \n" /* rrrgggggbbbbb000 */ \ + "lsl z2.h, z3.h, #3 \n" /* rrrgggggbbbbb000 */ \ + "asr z1.h, z1.h, #7 \n" /* aaaaaaaarrrrrggg */ \ + "asr z3.h, z3.h, #7 \n" /* aaaaaaaarrrrrggg */ \ + "lsl z0.b, p0/m, z0.b, z4.b \n" /* ggggg000bbbbb000 */ \ + "lsl z2.b, p0/m, z2.b, z4.b \n" /* ggggg000bbbbb000 */ \ + "sri z1.b, z1.b, #5 \n" /* aaaaaaaarrrrrrrr */ \ + "sri z3.b, z3.b, #5 \n" /* aaaaaaaarrrrrrrr */ \ + "sri z0.b, z0.b, #5 \n" /* ggggggggbbbbbbbb */ \ + "sri z2.b, z2.b, #5 \n" /* ggggggggbbbbbbbb */ + +void ARGB1555ToARGBRow_SVE2(const uint8_t* src_argb1555, + uint8_t* dst_argb, + int width) { + uint64_t vl; + asm volatile( + "mov z4.h, #0x0300 \n" + "ptrue p0.b \n" + + "cnth %x[vl] \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.lt 2f \n" + + "1: \n" + "ld1h {z1.h}, p0/z, [%[src]] \n" + "ld1h {z3.h}, p0/z, [%[src], #1, mul vl] \n" + "incb %[src], all, mul #2 \n" // + ARGB1555TOARGB + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "st2h {z0.h, z1.h}, p0, [%[dst]] \n" + "st2h {z2.h, z3.h}, p0, [%[dst], #2, mul vl] \n" + "incb %[dst], all, mul #4 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #1 \n" + "b.eq 99f \n" + + "whilelt p1.h, wzr, %w[width] \n" + "whilelt p2.h, %w[vl], %w[width] \n" + "ld1h {z1.h}, p1/z, [%[src]] \n" + "ld1h {z3.h}, p2/z, [%[src], #1, mul vl] \n" // + ARGB1555TOARGB + "st2h {z0.h, z1.h}, p1, [%[dst]] \n" + "st2h {z2.h, z3.h}, p2, [%[dst], #2, mul vl] \n" + + "99: \n" + : [src] "+r"(src_argb1555), // %[src] + [dst] "+r"(dst_argb), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "p0", "p1", "p2"); +} + +// clang-format off +#define AYUVTOUV_SVE(zU0, zV0, zU1, zV1) /* e.g. */ \ + "ld2h {z0.h, z1.h}, p0/z, [%[src0]] \n" /* VUVU.. YAYA.. */ \ + "ld2h {z1.h, z2.h}, p1/z, [%[src0], #2, mul vl] \n" /* VUVU.. YAYA.. */ \ + "ld2h {z2.h, z3.h}, p0/z, [%[src1]] \n" /* VUVU.. YAYA.. */ \ + "ld2h {z3.h, z4.h}, p1/z, [%[src1], #2, mul vl] \n" /* VUVU.. YAYA.. */ \ + "incb %[src0], all, mul #4 \n" \ + "incb %[src1], all, mul #4 \n" \ + "uaddlb z4.h, z0.b, z2.b \n" /* V */ \ + "uaddlt z5.h, z0.b, z2.b \n" /* U */ \ + "uaddlb z6.h, z1.b, z3.b \n" /* V */ \ + "uaddlt z7.h, z1.b, z3.b \n" /* U */ \ + "addp " #zU0 ".h, p0/m, " #zU0 ".h, " #zV0 ".h \n" /* UV */ \ + "addp " #zU1 ".h, p1/m, " #zU1 ".h, " #zV1 ".h \n" /* UV */ \ + "subs %w[width], %w[width], %w[vl] \n" \ + "urshr " #zU0 ".h, p0/m, " #zU0 ".h, #2 \n" /* U0V0 */ \ + "urshr " #zU1 ".h, p1/m, " #zU1 ".h, #2 \n" /* U0V0 */ \ + "st1b {" #zU0 ".h}, p0, [%[dst]] \n" \ + "st1b {" #zU1 ".h}, p1, [%[dst], #1, mul vl] \n" \ + "incb %[dst] \n" +// clang-format on + +// Filter 2 rows of AYUV UV's (444) into UV (420). +// AYUV is VUYA in memory. UV for NV12 is UV order in memory. +void AYUVToUVRow_SVE2(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + int width) { + // Output a row of UV values, filtering 2x2 rows of AYUV. + const uint8_t* src_ayuv1 = src_ayuv + src_stride_ayuv; + int vl; + asm volatile ( + "cntb %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.h \n" + "ptrue p1.h \n" + "1: \n" + AYUVTOUV_SVE(z5, z4, z7, z6) + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "cnth %x[vl] \n" + "whilelt p0.h, wzr, %w[width] \n" // first row + "whilelt p1.h, %w[vl], %w[width] \n" // second row + AYUVTOUV_SVE(z5, z4, z7, z6) + + "99: \n" + : [src0]"+r"(src_ayuv), // %[src0] + [src1]"+r"(src_ayuv1), // %[src1] + [dst]"+r"(dst_uv), // %[dst] + [width]"+r"(width), // %[width] + [vl]"=&r"(vl) // %[vl] + : + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "p0", + "p1"); +} + +// Filter 2 rows of AYUV UV's (444) into VU (420). +void AYUVToVURow_SVE2(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_vu, + int width) { + // Output a row of VU values, filtering 2x2 rows of AYUV. + const uint8_t* src_ayuv1 = src_ayuv + src_stride_ayuv; + int vl; + asm volatile ( + "cntb %x[vl] \n" + "cmp %w[width], %w[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.h \n" + "ptrue p1.h \n" + "1: \n" + AYUVTOUV_SVE(z4, z5, z6, z7) + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "cnth %x[vl] \n" + "whilelt p0.h, wzr, %w[width] \n" // first row + "whilelt p1.h, %w[vl], %w[width] \n" // second row + AYUVTOUV_SVE(z4, z5, z6, z7) + + "99: \n" + : [src0]"+r"(src_ayuv), // %[src0] + [src1]"+r"(src_ayuv1), // %[src1] + [dst]"+r"(dst_vu), // %[dst] + [width]"+r"(width), // %[width] + [vl]"=&r"(vl) // %[vl] + : + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "p0", + "p1"); +} + +void YUY2ToARGBRow_SVE2(const uint8_t* src_yuy2, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUY2ToARGBRow_SVE_SC(src_yuy2, dst_argb, yuvconstants, width); +} + +void UYVYToARGBRow_SVE2(const uint8_t* src_uyvy, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + UYVYToARGBRow_SVE_SC(src_uyvy, dst_argb, yuvconstants, width); +} + +static inline void RAWToWXYZRow_SVE2(const uint8_t* src_raw, + uint8_t* dst_wxyz, + int width, + uint32_t idx_start, + uint32_t idx_step, + uint32_t alpha) { + uint32_t vl; + asm("cntw %x0" : "=r"(vl)); + uint32_t vl_mul3 = vl * 3; + uint32_t rem_mul3; + asm volatile( + "index z31.s, %w[idx_start], %w[idx_step] \n" + "dup z30.s, %w[alpha] \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.lt 2f \n" + + // Run bulk of computation with the same predicates to avoid predicate + // generation overhead. We set up p1 to only load 3/4 of a vector. + "ptrue p0.s \n" + "whilelt p1.b, wzr, %w[vl_mul3] \n" + "1: \n" + "ld1b {z0.b}, p1/z, [%[src]] \n" + "add %[src], %[src], %x[vl_mul3] \n" + "ld1b {z1.b}, p1/z, [%[src]] \n" + "add %[src], %[src], %x[vl_mul3] \n" + "tbl z0.b, {z0.b}, z31.b \n" + "tbl z1.b, {z1.b}, z31.b \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "orr z0.d, z0.d, z30.d \n" + "orr z1.d, z1.d, z30.d \n" + "st1w {z0.s}, p0, [%[dst]] \n" + "st1w {z1.s}, p0, [%[dst], #1, mul vl] \n" + "incb %[dst], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #1 \n" + "b.eq 99f \n" + + // Calculate a pair of predicates for the final iteration to deal with + // the tail. + "3: \n" + "add %w[rem_mul3], %w[width], %w[width], lsl #1 \n" + "whilelt p0.s, wzr, %w[width] \n" + "whilelt p1.b, wzr, %w[rem_mul3] \n" + "ld1b {z0.b}, p1/z, [%[src]] \n" + "add %[src], %[src], %x[vl_mul3] \n" + "tbl z0.b, {z0.b}, z31.b \n" + "subs %w[width], %w[width], %w[vl] \n" + "orr z0.d, z0.d, z30.d \n" + "st1w {z0.s}, p0, [%[dst]] \n" + "incb %[dst] \n" + "b.gt 3b \n" + + "99: \n" + : [src] "+r"(src_raw), // %[src] + [dst] "+r"(dst_wxyz), // %[dst] + [width] "+r"(width), // %[width] + [vl_mul3] "+r"(vl_mul3), // %[vl_mul3] + [rem_mul3] "=&r"(rem_mul3) // %[rem_mul3] + : [idx_start] "r"(idx_start), // %[idx_start] + [idx_step] "r"(idx_step), // %[idx_step] + [alpha] "r"(alpha), // %[alpha] + [vl] "r"(vl) // %[vl] + : "cc", "memory", "z0", "z1", "z30", "z31", "p0", "p1"); +} + +void RAWToARGBRow_SVE2(const uint8_t* src_raw, uint8_t* dst_argb, int width) { + RAWToWXYZRow_SVE2(src_raw, dst_argb, width, 0xff000102U, 0x00030303U, + 0xff000000U); +} + +void RAWToRGBARow_SVE2(const uint8_t* src_raw, uint8_t* dst_rgba, int width) { + RAWToWXYZRow_SVE2(src_raw, dst_rgba, width, 0x000102ffU, 0x03030300U, + 0x000000ffU); +} + +void RGB24ToARGBRow_SVE2(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width) { + RAWToWXYZRow_SVE2(src_rgb24, dst_argb, width, 0xff020100U, 0x00030303U, + 0xff000000U); +} + +static const uint8_t kRAWToRGB24Indices[] = { + 2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, + 17, 16, 15, 20, 19, 18, 23, 22, 21, 26, 25, 24, 29, 28, 27, + 32, 31, 30, 35, 34, 33, 38, 37, 36, 41, 40, 39, 44, 43, 42, + 47, 46, 45, 50, 49, 48, 53, 52, 51, 56, 55, 54, 59, 58, 57, + 62, 61, 60, 65, 64, 63, 68, 67, 66, 71, 70, 69, 74, 73, 72, + 77, 76, 75, 80, 79, 78, 83, 82, 81, 86, 85, 84, 89, 88, 87, + 92, 91, 90, 95, 94, 93, 98, 97, 96, 101, 100, 99, 104, 103, 102, + 107, 106, 105, 110, 109, 108, 113, 112, 111, 116, 115, 114, 119, 118, 117, + 122, 121, 120, 125, 124, 123, 128, 127, 126, 131, 130, 129, 134, 133, 132, + 137, 136, 135, 140, 139, 138, 143, 142, 141, 146, 145, 144, 149, 148, 147, + 152, 151, 150, 155, 154, 153, 158, 157, 156, 161, 160, 159, 164, 163, 162, + 167, 166, 165, 170, 169, 168, 173, 172, 171, 176, 175, 174, 179, 178, 177, + 182, 181, 180, 185, 184, 183, 188, 187, 186, 191, 190, 189, 194, 193, 192, + 197, 196, 195, 200, 199, 198, 203, 202, 201, 206, 205, 204, 209, 208, 207, + 212, 211, 210, 215, 214, 213, 218, 217, 216, 221, 220, 219, 224, 223, 222, + 227, 226, 225, 230, 229, 228, 233, 232, 231, 236, 235, 234, 239, 238, 237, + 242, 241, 240, 245, 244, 243, 248, 247, 246, 251, 250, 249, 254, 253, 252}; + +void RAWToRGB24Row_SVE2(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { + // width is in elements, convert to bytes. + width *= 3; + // we use the mul3 predicate pattern throughout to use the largest multiple + // of three number of lanes, for instance with a vector length of 16 bytes + // only the first 15 bytes will be used for load/store instructions. + uint32_t vl; + asm volatile( + "cntb %x[vl], mul3 \n" + "ptrue p0.b, mul3 \n" + "ld1b {z31.b}, p0/z, [%[kIndices]] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + // Run bulk of computation with the same predicate to avoid predicate + // generation overhead. + "1: \n" + "ld1b {z0.b}, p0/z, [%[src]] \n" + "add %[src], %[src], %x[vl] \n" + "tbl z0.b, {z0.b}, z31.b \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1b {z0.b}, p0, [%[dst]] \n" + "add %[dst], %[dst], %x[vl] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + // Calculate a predicate for the final iteration to deal with the tail. + "whilelt p0.b, wzr, %w[width] \n" + "ld1b {z0.b}, p0/z, [%[src]] \n" + "tbl z0.b, {z0.b}, z31.b \n" + "st1b {z0.b}, p0, [%[dst]] \n" + + "99: \n" + : [src] "+r"(src_raw), // %[src] + [dst] "+r"(dst_rgb24), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [kIndices] "r"(kRAWToRGB24Indices) // %[kIndices] + : "cc", "memory", "z0", "z31", "p0"); +} + +static inline void ARGBToXYZRow_SVE2(const uint8_t* src_argb, + uint8_t* dst_xyz, + int width, + const uint8_t* indices) { + uint32_t vl; + asm("cntw %x0" : "=r"(vl)); + uint32_t vl_mul3 = vl * 3; + uint32_t rem_mul3; + asm volatile( + "whilelt p1.b, wzr, %w[vl_mul3] \n" + "ld1b {z31.b}, p1/z, [%[indices]] \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.lt 2f \n" + + // Run bulk of computation with the same predicates to avoid predicate + // generation overhead. We set up p1 to only store 3/4 of a vector. + "ptrue p0.s \n" + "1: \n" + "ld1w {z0.s}, p0/z, [%[src]] \n" + "ld1w {z1.s}, p0/z, [%[src], #1, mul vl] \n" + "incb %[src], all, mul #2 \n" + "tbl z0.b, {z0.b}, z31.b \n" + "tbl z1.b, {z1.b}, z31.b \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "st1b {z0.b}, p1, [%[dst]] \n" + "add %[dst], %[dst], %x[vl_mul3] \n" + "st1b {z1.b}, p1, [%[dst]] \n" + "add %[dst], %[dst], %x[vl_mul3] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #1 \n" + "b.eq 99f \n" + + // Calculate predicates for the final iteration to deal with the tail. + "add %w[rem_mul3], %w[width], %w[width], lsl #1 \n" + "whilelt p0.s, wzr, %w[width] \n" + "whilelt p1.b, wzr, %w[rem_mul3] \n" + "whilelt p2.s, %w[vl], %w[width] \n" + "whilelt p3.b, %w[vl_mul3], %w[rem_mul3] \n" + "ld1w {z0.s}, p0/z, [%[src]] \n" + "ld1w {z1.s}, p2/z, [%[src], #1, mul vl] \n" + "tbl z0.b, {z0.b}, z31.b \n" + "tbl z1.b, {z1.b}, z31.b \n" + "st1b {z0.b}, p1, [%[dst]] \n" + "add %[dst], %[dst], %x[vl_mul3] \n" + "st1b {z1.b}, p3, [%[dst]] \n" + + "99: \n" + : [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_xyz), // %[dst] + [width] "+r"(width), // %[width] + [rem_mul3] "=&r"(rem_mul3) // %[rem_mul3] + : [indices] "r"(indices), // %[indices] + [vl_mul3] "r"(vl_mul3), // %[vl_mul3] + [vl] "r"(vl) // %[vl] + : "cc", "memory", "z0", "z1", "z31", "p0", "p1", "p2", "p3"); +} + +static const uint8_t kARGBToRGB24RowIndices[] = { + 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 16, 17, 18, + 20, 21, 22, 24, 25, 26, 28, 29, 30, 32, 33, 34, 36, 37, 38, + 40, 41, 42, 44, 45, 46, 48, 49, 50, 52, 53, 54, 56, 57, 58, + 60, 61, 62, 64, 65, 66, 68, 69, 70, 72, 73, 74, 76, 77, 78, + 80, 81, 82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 96, 97, 98, + 100, 101, 102, 104, 105, 106, 108, 109, 110, 112, 113, 114, 116, 117, 118, + 120, 121, 122, 124, 125, 126, 128, 129, 130, 132, 133, 134, 136, 137, 138, + 140, 141, 142, 144, 145, 146, 148, 149, 150, 152, 153, 154, 156, 157, 158, + 160, 161, 162, 164, 165, 166, 168, 169, 170, 172, 173, 174, 176, 177, 178, + 180, 181, 182, 184, 185, 186, 188, 189, 190, 192, 193, 194, 196, 197, 198, + 200, 201, 202, 204, 205, 206, 208, 209, 210, 212, 213, 214, 216, 217, 218, + 220, 221, 222, 224, 225, 226, 228, 229, 230, 232, 233, 234, 236, 237, 238, + 240, 241, 242, 244, 245, 246, 248, 249, 250, 252, 253, 254, +}; + +static const uint8_t kARGBToRAWRowIndices[] = { + 2, 1, 0, 6, 5, 4, 10, 9, 8, 14, 13, 12, 18, 17, 16, + 22, 21, 20, 26, 25, 24, 30, 29, 28, 34, 33, 32, 38, 37, 36, + 42, 41, 40, 46, 45, 44, 50, 49, 48, 54, 53, 52, 58, 57, 56, + 62, 61, 60, 66, 65, 64, 70, 69, 68, 74, 73, 72, 78, 77, 76, + 82, 81, 80, 86, 85, 84, 90, 89, 88, 94, 93, 92, 98, 97, 96, + 102, 101, 100, 106, 105, 104, 110, 109, 108, 114, 113, 112, 118, 117, 116, + 122, 121, 120, 126, 125, 124, 130, 129, 128, 134, 133, 132, 138, 137, 136, + 142, 141, 140, 146, 145, 144, 150, 149, 148, 154, 153, 152, 158, 157, 156, + 162, 161, 160, 166, 165, 164, 170, 169, 168, 174, 173, 172, 178, 177, 176, + 182, 181, 180, 186, 185, 184, 190, 189, 188, 194, 193, 192, 198, 197, 196, + 202, 201, 200, 206, 205, 204, 210, 209, 208, 214, 213, 212, 218, 217, 216, + 222, 221, 220, 226, 225, 224, 230, 229, 228, 234, 233, 232, 238, 237, 236, + 242, 241, 240, 246, 245, 244, 250, 249, 248, 254, 253, 252, +}; + +void ARGBToRGB24Row_SVE2(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { + ARGBToXYZRow_SVE2(src_argb, dst_rgb, width, kARGBToRGB24RowIndices); +} + +void ARGBToRAWRow_SVE2(const uint8_t* src_argb, uint8_t* dst_rgb, int width) { + ARGBToXYZRow_SVE2(src_argb, dst_rgb, width, kARGBToRAWRowIndices); +} + +void DivideRow_16_SVE2(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + if (scale == 65536) { // Divide by 1, so do memcpy. + if (src_y != dst_y) { + memcpy(dst_y, src_y, (size_t)width * 2); + } + return; + } + uint64_t vl; + asm volatile( + "cnth %x[vl] \n" + "dup z0.h, %w[scale] \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.lt 2f \n" + + // Run bulk of computation with the same predicates to avoid predicate + // generation overhead. + "ptrue p0.h \n" + "1: \n" + "ld1h {z1.h}, p0/z, [%[src]] \n" + "ld1h {z2.h}, p0/z, [%[src], #1, mul vl] \n" + "incb %[src], all, mul #2 \n" + "umulh z1.h, z1.h, z0.h \n" + "umulh z2.h, z2.h, z0.h \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "st1h {z1.h}, p0, [%[dst]] \n" + "st1h {z2.h}, p0, [%[dst], #1, mul vl] \n" + "incb %[dst], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #1 \n" + "b.eq 99f \n" + + // Calculate a pair of predicates for the final iteration to deal with + // the tail. + "whilelt p0.h, wzr, %w[width] \n" + "whilelt p1.h, %w[vl], %w[width] \n" + "ld1h {z1.h}, p0/z, [%[src]] \n" + "ld1h {z2.h}, p1/z, [%[src], #1, mul vl] \n" + "umulh z1.h, z1.h, z0.h \n" + "umulh z2.h, z2.h, z0.h \n" + "st1h {z1.h}, p0, [%[dst]] \n" + "st1h {z2.h}, p1, [%[dst], #1, mul vl] \n" + + "99: \n" + : [src] "+r"(src_y), // %[src] + [dst] "+r"(dst_y), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [scale] "r"(scale) // %[scale] + : "cc", "memory", "z0", "z1", "z2", "p0", "p1"); +} + +#define HALFFLOAT_SVE \ + "scvtf z0.s, p0/m, z0.s \n" \ + "scvtf z1.s, p0/m, z1.s \n" \ + "scvtf z2.s, p0/m, z2.s \n" \ + "scvtf z3.s, p0/m, z3.s \n" \ + "fmul z0.s, z0.s, z4.s \n" \ + "fmul z1.s, z1.s, z4.s \n" \ + "fmul z2.s, z2.s, z4.s \n" \ + "fmul z3.s, z3.s, z4.s \n" \ + "fmul z0.s, z0.s, z5.s \n" \ + "fmul z1.s, z1.s, z5.s \n" \ + "fmul z2.s, z2.s, z5.s \n" \ + "fmul z3.s, z3.s, z5.s \n" \ + "uqshrnb z0.h, z0.s, #13 \n" \ + "uqshrnb z1.h, z1.s, #13 \n" \ + "uqshrnb z2.h, z2.s, #13 \n" \ + "uqshrnb z3.h, z3.s, #13 \n" + +void HalfFloatRow_SVE2(const uint16_t* src, + uint16_t* dst, + float scale, + int width) { + uint64_t vl; + asm("cntw %x0" : "=r"(vl)); + asm volatile( + "mov z4.s, %s[scale] \n" + "mov z5.s, %s[bias] \n" + "subs %w[width], %w[width], %w[vl], lsl #2 \n" + "b.lt 2f \n" + + // Run bulk of computation with all-true predicates to avoid predicate + // generation overhead. + "ptrue p0.s \n" + "1: \n" + "ld1h {z0.s}, p0/z, [%[src]] \n" + "ld1h {z1.s}, p0/z, [%[src], #1, mul vl] \n" + "ld1h {z2.s}, p0/z, [%[src], #2, mul vl] \n" + "ld1h {z3.s}, p0/z, [%[src], #3, mul vl] \n" + "incb %[src], all, mul #2 \n" // + HALFFLOAT_SVE + "subs %w[width], %w[width], %w[vl], lsl #2 \n" + "st1h {z0.s}, p0, [%[dst]] \n" + "st1h {z1.s}, p0, [%[dst], #1, mul vl] \n" + "st1h {z2.s}, p0, [%[dst], #2, mul vl] \n" + "st1h {z3.s}, p0, [%[dst], #3, mul vl] \n" + "incb %[dst], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #2 \n" + "b.eq 99f \n" + + // Calculate predicates for the final iteration to deal with the tail. + "whilelt p0.s, wzr, %w[width] \n" + "whilelt p1.s, %w[vl], %w[width] \n" + "whilelt p2.s, %w[vl2], %w[width] \n" + "whilelt p3.s, %w[vl3], %w[width] \n" + "ld1h {z0.s}, p0/z, [%[src]] \n" + "ld1h {z1.s}, p1/z, [%[src], #1, mul vl] \n" + "ld1h {z2.s}, p2/z, [%[src], #2, mul vl] \n" + "ld1h {z3.s}, p3/z, [%[src], #3, mul vl] \n" // + HALFFLOAT_SVE + "st1h {z0.s}, p0, [%[dst]] \n" + "st1h {z1.s}, p1, [%[dst], #1, mul vl] \n" + "st1h {z2.s}, p2, [%[dst], #2, mul vl] \n" + "st1h {z3.s}, p3, [%[dst], #3, mul vl] \n" + + "99: \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [width] "+r"(width) // %[width] + : [vl] "r"(vl), // %[vl] + [vl2] "r"(vl * 2), // %[vl2] + [vl3] "r"(vl * 3), // %[vl3] + [scale] "w"(scale), // %[scale] + [bias] "w"(1.9259299444e-34f) // %[bias] 2^-112 + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "z5", "p0", "p1", "p2", + "p3"); +} + +void HalfFloat1Row_SVE2(const uint16_t* src, + uint16_t* dst, + float scale, + int width) { + uint64_t vl; + asm volatile( + "cnth %x[vl] \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "b.lt 2f \n" + + // Run bulk of computation with all-true predicates to avoid predicate + // generation overhead. + "ptrue p0.h \n" + "1: \n" + "ld1h {z0.h}, p0/z, [%[src]] \n" + "ld1h {z1.h}, p0/z, [%[src], #1, mul vl] \n" + "incb %[src], all, mul #2 \n" + "ucvtf z0.h, p0/m, z0.h \n" + "ucvtf z1.h, p0/m, z1.h \n" + "subs %w[width], %w[width], %w[vl], lsl #1 \n" + "st1h {z0.h}, p0, [%[dst]] \n" + "st1h {z1.h}, p0, [%[dst], #1, mul vl] \n" + "incb %[dst], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl], lsl #1 \n" + "b.eq 99f \n" + + // Calculate predicates for the final iteration to deal with the tail. + "whilelt p0.h, wzr, %w[width] \n" + "whilelt p1.h, %w[vl], %w[width] \n" + "ld1h {z0.h}, p0/z, [%[src]] \n" + "ld1h {z1.h}, p1/z, [%[src], #1, mul vl] \n" + "ucvtf z0.h, p0/m, z0.h \n" + "ucvtf z1.h, p0/m, z1.h \n" + "st1h {z0.h}, p0, [%[dst]] \n" + "st1h {z1.h}, p1, [%[dst], #1, mul vl] \n" + + "99: \n" + : [src] "+r"(src), // %[src] + [dst] "+r"(dst), // %[dst] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "cc", "memory", "z0", "z1", "p0", "p1"); +} + +void I210ToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I210ToARGBRow_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +void I210AlphaToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I210AlphaToARGBRow_SVE_SC(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); +} + +void I210ToAR30Row_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + I210ToAR30Row_SVE_SC(src_y, src_u, src_v, dst_ar30, yuvconstants, width); +} + +void P210ToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + P210ToARGBRow_SVE_SC(src_y, src_uv, dst_argb, yuvconstants, width); +} + +void P210ToAR30Row_SVE2(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + P210ToAR30Row_SVE_SC(src_y, src_uv, dst_ar30, yuvconstants, width); +} + +void I410ToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I410ToARGBRow_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +void I410AlphaToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + const uint16_t* src_a, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I410AlphaToARGBRow_SVE_SC(src_y, src_u, src_v, src_a, dst_argb, yuvconstants, + width); +} + +void I410ToAR30Row_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + I410ToAR30Row_SVE_SC(src_y, src_u, src_v, dst_ar30, yuvconstants, width); +} + +void P410ToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + P410ToARGBRow_SVE_SC(src_y, src_uv, dst_argb, yuvconstants, width); +} + +void P410ToAR30Row_SVE2(const uint16_t* src_y, + const uint16_t* src_uv, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + P410ToAR30Row_SVE_SC(src_y, src_uv, dst_ar30, yuvconstants, width); +} + +void I212ToAR30Row_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + I212ToAR30Row_SVE_SC(src_y, src_u, src_v, dst_ar30, yuvconstants, width); +} + +void I212ToARGBRow_SVE2(const uint16_t* src_y, + const uint16_t* src_u, + const uint16_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + I212ToARGBRow_SVE_SC(src_y, src_u, src_v, dst_argb, yuvconstants, width); +} + +void Convert8To8Row_SVE2(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width) { + Convert8To8Row_SVE_SC(src_y, dst_y, scale, bias, width); +} + +void MergeUVRow_SVE2(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width) { + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "1: \n" + "ld1b {z1.b}, p0/z, [%[src_u]] \n" + "ld1b {z2.b}, p0/z, [%[src_v]] \n" + "incb %[src_u] \n" + "incb %[src_v] \n" + "subs %w[width], %w[width], %w[vl] \n" + "st2b {z1.b, z2.b}, p0, [%[dst_uv]] \n" + "incb %[dst_uv], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[width] \n" + "ld1b {z1.b}, p0/z, [%[src_u]] \n" + "ld1b {z2.b}, p0/z, [%[src_v]] \n" + "st2b {z1.b, z2.b}, p0, [%[dst_uv]] \n" + + "99: \n" + : [src_u] "+r"(src_u), // %[src_u] + [src_v] "+r"(src_v), // %[src_v] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "memory", "cc", "z1", "z2", "p0"); +} + +void SplitUVRow_SVE2(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "1: \n" + "ld2b {z1.b, z2.b}, p0/z, [%[src_uv]] \n" + "incb %[src_uv], all, mul #2 \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1b {z1.b}, p0, [%[dst_u]] \n" + "st1b {z2.b}, p0, [%[dst_v]] \n" + "incb %[dst_u] \n" + "incb %[dst_v] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[width] \n" + "ld2b {z1.b, z2.b}, p0/z, [%[src_uv]] \n" + "st1b {z1.b}, p0, [%[dst_u]] \n" + "st1b {z2.b}, p0, [%[dst_v]] \n" + + "99: \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_u] "+r"(dst_u), // %[dst_u] + [dst_v] "+r"(dst_v), // %[dst_v] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "memory", "cc", "z1", "z2", "p0"); +} + +void HalfMergeUVRow_SVE2(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width) { + const uint8_t* src_u1 = src_u + src_stride_u; + const uint8_t* src_v1 = src_v + src_stride_v; + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "1: \n" + "ld1b {z1.b}, p0/z, [%[src_u]] \n" + "ld1b {z2.b}, p0/z, [%[src_u1]] \n" + "ld1b {z3.b}, p0/z, [%[src_v]] \n" + "ld1b {z4.b}, p0/z, [%[src_v1]] \n" + "incb %[src_u] \n" + "incb %[src_u1] \n" + "incb %[src_v] \n" + "incb %[src_v1] \n" + "uaddlb z5.h, z1.b, z2.b \n" + "uaddlb z6.h, z3.b, z4.b \n" + "uaddlt z1.h, z1.b, z2.b \n" + "uaddlt z3.h, z3.b, z4.b \n" + "add z1.h, z1.h, z5.h \n" + "add z3.h, z3.h, z6.h \n" + "rshrnb z1.b, z1.h, #2 \n" + "rshrnt z1.b, z3.h, #2 \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1b {z1.b}, p0, [%[dst_uv]] \n" + "incb %[dst_uv] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[width] \n" + "ld1b {z1.b}, p0/z, [%[src_u]] \n" + "ld1b {z2.b}, p0/z, [%[src_u1]] \n" + "ld1b {z3.b}, p0/z, [%[src_v]] \n" + "ld1b {z4.b}, p0/z, [%[src_v1]] \n" + "uaddlb z5.h, z1.b, z2.b \n" + "uaddlb z6.h, z3.b, z4.b \n" + "uaddlt z1.h, z1.b, z2.b \n" + "uaddlt z3.h, z3.b, z4.b \n" + "add z1.h, z1.h, z5.h \n" + "add z3.h, z3.h, z6.h \n" + "rshrnb z1.b, z1.h, #2 \n" + "rshrnt z1.b, z3.h, #2 \n" + "st1b {z1.b}, p0, [%[dst_uv]] \n" + + "99: \n" + : [src_u] "+r"(src_u), // %[src_u] + [src_u1] "+r"(src_u1), // %[src_u1] + [src_v] "+r"(src_v), // %[src_v] + [src_v1] "+r"(src_v1), // %[src_v1] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "cc", "memory", "z1", "z2", "z3", "z4", "z5", "z6", "p0"); +} + +void CopyRow_SVE2(const uint8_t* src, uint8_t* dst, int width) { + int vl; + int vl2; + asm volatile( + "cntb %x[vl] \n" + "lsl %w[vl2], %w[vl], #1 \n" + "subs %w[width], %w[width], %w[vl2] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "1: \n" + "ld1b {z0.b}, p0/z, [%[src], #0, mul vl] \n" + "ld1b {z1.b}, p0/z, [%[src], #1, mul vl] \n" + "incb %[src], all, mul #2 \n" + "subs %w[width], %w[width], %w[vl2] \n" + "st1b {z0.b}, p0, [%[dst], #0, mul vl] \n" + "st1b {z1.b}, p0, [%[dst], #1, mul vl] \n" + "incb %[dst], all, mul #2 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl2] \n" + "b.eq 99f \n" + + "3: \n" + "whilelt p0.b, wzr, %w[width] \n" + "ld1b {z0.b}, p0/z, [%[src]] \n" + "incb %[src] \n" + "st1b {z0.b}, p0, [%[dst]] \n" + "incb %[dst] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.gt 3b \n" + + "99: \n" + : [src] "+r"(src), [dst] "+r"(dst), [width] "+r"(width), [vl] "=&r"(vl), + [vl2] "=&r"(vl2) + : + : "cc", "memory", "z0", "z1", "p0"); +} + +void InterpolateRow_SVE2(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + int y1_fraction = source_y_fraction; + int y0_fraction = 256 - y1_fraction; + const uint8_t* src_ptr1 = src_ptr + src_stride; + + if (y0_fraction == 0) { + CopyRow_SVE2(src_ptr1, dst_ptr, width); + return; + } + if (y0_fraction == 256) { + CopyRow_SVE2(src_ptr, dst_ptr, width); + return; + } + if (y0_fraction == 128) { + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "1: \n" + "ld1b {z2.b}, p0/z, [%[src_ptr]] \n" + "ld1b {z3.b}, p0/z, [%[src_ptr1]] \n" + "incb %[src_ptr] \n" + "incb %[src_ptr1] \n" + "subs %w[width], %w[width], %w[vl] \n" + "urhadd z2.b, p0/m, z2.b, z3.b \n" + "st1b {z2.b}, p0, [%[dst_ptr]] \n" + "incb %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[width] \n" + "ld1b {z2.b}, p0/z, [%[src_ptr]] \n" + "ld1b {z3.b}, p0/z, [%[src_ptr1]] \n" + "urhadd z2.b, p0/m, z2.b, z3.b \n" + "st1b {z2.b}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), [src_ptr1] "+r"(src_ptr1), + [dst_ptr] "+r"(dst_ptr), [width] "+r"(width), [vl] "=&r"(vl) + : + : "cc", "memory", "z2", "z3", "p0"); + return; + } + + int vl; + asm volatile( + "cntb %x[vl] \n" + "dup z0.b, %w[y0_fraction] \n" + "dup z1.b, %w[y1_fraction] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "1: \n" + "ld1b {z2.b}, p0/z, [%[src_ptr]] \n" + "ld1b {z3.b}, p0/z, [%[src_ptr1]] \n" + "incb %[src_ptr] \n" + "incb %[src_ptr1] \n" + "umullb z4.h, z2.b, z0.b \n" + "umullt z2.h, z2.b, z0.b \n" + "subs %w[width], %w[width], %w[vl] \n" + "umlalb z4.h, z3.b, z1.b \n" + "umlalt z2.h, z3.b, z1.b \n" + "rshrnb z3.b, z4.h, #8 \n" + "rshrnt z3.b, z2.h, #8 \n" + "st1b {z3.b}, p0, [%[dst_ptr]] \n" + "incb %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[width] \n" + "ld1b {z2.b}, p0/z, [%[src_ptr]] \n" + "ld1b {z3.b}, p0/z, [%[src_ptr1]] \n" + "umullb z4.h, z2.b, z0.b \n" + "umullt z2.h, z2.b, z0.b \n" + "umlalb z4.h, z3.b, z1.b \n" + "umlalt z2.h, z3.b, z1.b \n" + "rshrnb z3.b, z4.h, #8 \n" + "rshrnt z3.b, z2.h, #8 \n" + "st1b {z3.b}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "+r"(src_ptr1), // %[src_ptr1] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [y0_fraction] "r"(y0_fraction), // %[y0_fraction] + [y1_fraction] "r"(y1_fraction) // %[y1_fraction] + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "p0"); +} + +void YUY2ToYRow_SVE2(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "1: \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_yuy2]] \n" + "incb %[src_yuy2], all, mul #2 \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1b {z0.b}, p0, [%[dst_y]] \n" + "incb %[dst_y] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[width] \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_yuy2]] \n" + "st1b {z0.b}, p0, [%[dst_y]] \n" + + "99: \n" + : [src_yuy2] "+r"(src_yuy2), // %[src_yuy2] + [dst_y] "+r"(dst_y), // %[dst_y] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "p0"); +} + +void UYVYToYRow_SVE2(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "1: \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_uyvy]] \n" + "incb %[src_uyvy], all, mul #2 \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1b {z1.b}, p0, [%[dst_y]] \n" + "incb %[dst_y] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[width] \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_uyvy]] \n" + "st1b {z1.b}, p0, [%[dst_y]] \n" + + "99: \n" + : [src_uyvy] "+r"(src_uyvy), // %[src_uyvy] + [dst_y] "+r"(dst_y), // %[dst_y] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "p0"); +} + +void YUY2ToUVRow_SVE2(const uint8_t* src_yuy2, + int src_stride_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* src_yuy2_1 = src_yuy2 + src_stride_yuy2; + int vl; + int vl_half; + int width_half; + if (src_stride_yuy2 == 0) { + src_yuy2_1 = src_yuy2; + } + asm volatile( + "cntb %x[vl] \n" + "lsr %w[vl_half], %w[vl], #1 \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "whilelt p1.b, wzr, %w[vl_half] \n" + "1: \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_yuy2]] \n" + "ld2b {z4.b, z5.b}, p0/z, [%[src_yuy2_1]] \n" + "incb %[src_yuy2], all, mul #2 \n" + "incb %[src_yuy2_1], all, mul #2 \n" + "urhadd z1.b, p0/m, z1.b, z5.b \n" + "uzp1 z0.b, z1.b, z1.b \n" + "uzp2 z2.b, z1.b, z1.b \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1b {z0.b}, p1, [%[dst_u]] \n" + "st1b {z2.b}, p1, [%[dst_v]] \n" + "add %[dst_u], %[dst_u], %x[vl_half] \n" + "add %[dst_v], %[dst_v], %x[vl_half] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "add %w[width_half], %w[width], #1 \n" + "lsr %w[width_half], %w[width_half], #1 \n" + "whilelt p1.b, wzr, %w[width_half] \n" + "zip1 p0.b, p1.b, p1.b \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_yuy2]] \n" + "ld2b {z4.b, z5.b}, p0/z, [%[src_yuy2_1]] \n" + "urhadd z1.b, p0/m, z1.b, z5.b \n" + "uzp1 z0.b, z1.b, z1.b \n" + "uzp2 z2.b, z1.b, z1.b \n" + "st1b {z0.b}, p1, [%[dst_u]] \n" + "st1b {z2.b}, p1, [%[dst_v]] \n" + + "99: \n" + : [src_yuy2] "+r"(src_yuy2), // %[src_yuy2] + [src_yuy2_1] "+r"(src_yuy2_1), // %[src_yuy2_1] + [dst_u] "+r"(dst_u), // %[dst_u] + [dst_v] "+r"(dst_v), // %[dst_v] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl), // %[vl] + [vl_half] "=&r"(vl_half), // %[vl_half] + [width_half] "=&r"(width_half) // %[width_half] + : + : "memory", "cc", "z0", "z1", "z2", "z4", "z5", "p0", "p1"); +} + +void UYVYToUVRow_SVE2(const uint8_t* src_uyvy, + int src_stride_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const uint8_t* src_uyvy_1 = src_uyvy + src_stride_uyvy; + int vl; + int vl_half; + int width_half; + if (src_stride_uyvy == 0) { + src_uyvy_1 = src_uyvy; + } + asm volatile( + "cntb %x[vl] \n" + "lsr %w[vl_half], %w[vl], #1 \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "whilelt p1.b, wzr, %w[vl_half] \n" + "1: \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_uyvy]] \n" + "ld2b {z4.b, z5.b}, p0/z, [%[src_uyvy_1]] \n" + "incb %[src_uyvy], all, mul #2 \n" + "incb %[src_uyvy_1], all, mul #2 \n" + "urhadd z0.b, p0/m, z0.b, z4.b \n" + "uzp1 z1.b, z0.b, z0.b \n" + "uzp2 z2.b, z0.b, z0.b \n" + "subs %w[width], %w[width], %w[vl] \n" + "st1b {z1.b}, p1, [%[dst_u]] \n" + "st1b {z2.b}, p1, [%[dst_v]] \n" + "add %[dst_u], %[dst_u], %x[vl_half] \n" + "add %[dst_v], %[dst_v], %x[vl_half] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "add %w[width_half], %w[width], #1 \n" + "lsr %w[width_half], %w[width_half], #1 \n" + "whilelt p1.b, wzr, %w[width_half] \n" + "zip1 p0.b, p1.b, p1.b \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_uyvy]] \n" + "ld2b {z4.b, z5.b}, p0/z, [%[src_uyvy_1]] \n" + "urhadd z0.b, p0/m, z0.b, z4.b \n" + "uzp1 z1.b, z0.b, z0.b \n" + "uzp2 z2.b, z0.b, z0.b \n" + "st1b {z1.b}, p1, [%[dst_u]] \n" + "st1b {z2.b}, p1, [%[dst_v]] \n" + + "99: \n" + : [src_uyvy] "+r"(src_uyvy), // %[src_uyvy] + [src_uyvy_1] "+r"(src_uyvy_1), // %[src_uyvy_1] + [dst_u] "+r"(dst_u), // %[dst_u] + [dst_v] "+r"(dst_v), // %[dst_v] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl), // %[vl] + [vl_half] "=&r"(vl_half), // %[vl_half] + [width_half] "=&r"(width_half) // %[width_half] + : + : "memory", "cc", "z0", "z1", "z2", "z4", "z5", "p0", "p1"); +} + +#ifdef HAS_CONVERT16TO8ROW_SVE2 +// Disabled: NEON version is faster for 128 bit vectors. +void Convert16To8Row_SVE2(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width) { + const int shift = 23 - __builtin_clz((int32_t)scale); + int vl; + asm volatile( + "cnth %x[vl] \n" + "dup z31.h, %w[shift] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.h \n" + "1: \n" + "ld1h {z2.h}, p0/z, [%[src_ptr]] \n" + "incb %[src_ptr] \n" + "subs %w[width], %w[width], %w[vl] \n" + "uqshl z2.h, p0/m, z2.h, z31.h \n" + "shrnb z2.b, z2.h, #8 \n" + "st1b {z2.h}, p0, [%[dst_ptr]] \n" + "inch %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.h, wzr, %w[width] \n" + "ld1h {z2.h}, p0/z, [%[src_ptr]] \n" + "uqshl z2.h, p0/m, z2.h, z31.h \n" + "shrnb z2.b, z2.h, #8 \n" + "st1b {z2.h}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_y), // %[src_ptr] + [dst_ptr] "+r"(dst_y), // %[dst_ptr] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [shift] "r"(shift) // %[shift] + : "cc", "memory", "z2", "z31", "p0"); +} +#endif // HAS_CONVERT16TO8ROW_SVE2 + +#ifdef HAS_HALFROW_16TO8_SVE2 +// Disabled: NEON version is faster for 128 bit vectors. +void HalfRow_16To8_SVE2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const uint16_t* src_uv1 = src_uv + src_uv_stride; + const int shift = 23 - __builtin_clz((int32_t)scale); + int vl; + asm volatile( + "cnth %x[vl] \n" + "dup z31.h, %w[shift] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.h \n" + "1: \n" + "ld1h {z2.h}, p0/z, [%[src_ptr]] \n" + "ld1h {z3.h}, p0/z, [%[src_ptr1]] \n" + "incb %[src_ptr] \n" + "incb %[src_ptr1] \n" + "urhadd z2.h, p0/m, z2.h, z3.h \n" + "subs %w[width], %w[width], %w[vl] \n" + "uqshl z2.h, p0/m, z2.h, z31.h \n" + "shrnb z2.b, z2.h, #8 \n" + "st1b {z2.h}, p0, [%[dst_ptr]] \n" + "inch %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.h, wzr, %w[width] \n" + "ld1h {z2.h}, p0/z, [%[src_ptr]] \n" + "ld1h {z3.h}, p0/z, [%[src_ptr1]] \n" + "urhadd z2.h, p0/m, z2.h, z3.h \n" + "uqshl z2.h, p0/m, z2.h, z31.h \n" + "shrnb z2.b, z2.h, #8 \n" + "st1b {z2.h}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_uv), // %[src_ptr] + [src_ptr1] "+r"(src_uv1), // %[src_ptr1] + [dst_ptr] "+r"(dst_uv), // %[dst_ptr] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl) // %[vl] + : [shift] "r"(shift) // %[shift] + : "cc", "memory", "z2", "z3", "z31", "p0"); +} +#endif // HAS_HALFROW_16TO8_SVE2 + +#ifdef HAS_HALFWIDTHROW_16TO8_SVE2 +// Disabled: NEON version is faster for 128 bit vectors. +void HalfWidthRow_16To8_SVE2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const uint16_t* src_uv1 = src_uv + src_uv_stride; + const int shift = 23 - __builtin_clz((int32_t)scale); + int vl; + int vl_input; + asm volatile( + "cnth %x[vl] \n" + "dup z31.h, %w[shift] \n" + "subs %w[width], %w[width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.h \n" + "1: \n" + "ld1h {z0.h}, p0/z, [%[src_ptr]] \n" + "ld1h {z1.h}, p0/z, [%[src_ptr], #1, mul vl] \n" + "ld1h {z2.h}, p0/z, [%[src_ptr1]] \n" + "ld1h {z3.h}, p0/z, [%[src_ptr1], #1, mul vl] \n" + "incb %[src_ptr], all, mul #4 \n" + "incb %[src_ptr1], all, mul #4 \n" + "uzp1 z4.h, z0.h, z1.h \n" + "uzp2 z5.h, z0.h, z1.h \n" + "uzp1 z6.h, z2.h, z3.h \n" + "uzp2 z7.h, z2.h, z3.h \n" + "uaddlb z0.s, z4.h, z5.h \n" + "uaddlt z1.s, z4.h, z5.h \n" + "uaddlb z2.s, z6.h, z7.h \n" + "uaddlt z3.s, z6.h, z7.h \n" + "add z0.s, z0.s, z2.s \n" + "add z1.s, z1.s, z3.s \n" + "rshrnb z0.h, z0.s, #2 \n" + "rshrnt z0.h, z1.s, #2 \n" + "subs %w[width], %w[width], %w[vl] \n" + "uqshl z0.h, p0/m, z0.h, z31.h \n" + "shrnb z0.b, z0.h, #8 \n" + "st1b {z0.h}, p0, [%[dst_ptr]] \n" + "inch %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[width], %w[width], %w[vl] \n" + "b.eq 99f \n" + + "lsl %w[vl_input], %w[width], #1 \n" + "whilelt p0.h, wzr, %w[vl_input] \n" + "whilelt p1.h, %w[vl], %w[vl_input] \n" + "whilelt p2.h, wzr, %w[width] \n" + "ld1h {z0.h}, p0/z, [%[src_ptr]] \n" + "ld1h {z1.h}, p1/z, [%[src_ptr], #1, mul vl] \n" + "ld1h {z2.h}, p0/z, [%[src_ptr1]] \n" + "ld1h {z3.h}, p1/z, [%[src_ptr1], #1, mul vl] \n" + "uzp1 z4.h, z0.h, z1.h \n" + "uzp2 z5.h, z0.h, z1.h \n" + "uzp1 z6.h, z2.h, z3.h \n" + "uzp2 z7.h, z2.h, z3.h \n" + "uaddlb z0.s, z4.h, z5.h \n" + "uaddlt z1.s, z4.h, z5.h \n" + "uaddlb z2.s, z6.h, z7.h \n" + "uaddlt z3.s, z6.h, z7.h \n" + "add z0.s, z0.s, z2.s \n" + "add z1.s, z1.s, z3.s \n" + "rshrnb z0.h, z0.s, #2 \n" + "rshrnt z0.h, z1.s, #2 \n" + "uqshl z0.h, p2/m, z0.h, z31.h \n" + "shrnb z0.b, z0.h, #8 \n" + "st1b {z0.h}, p2, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_uv), // %[src_ptr] + [src_ptr1] "+r"(src_uv1), // %[src_ptr1] + [dst_ptr] "+r"(dst_uv), // %[dst_ptr] + [width] "+r"(width), // %[width] + [vl] "=&r"(vl), // %[vl] + [vl_input] "=&r"(vl_input) // %[vl_input] + : [shift] "r"(shift) // %[shift] + : "cc", "memory", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z31", + "p0", "p1", "p2"); +} +#endif // HAS_HALFWIDTHROW_16TO8_SVE2 + +#ifdef HAS_SSIM4X4ROW_SVE2 +void Ssim4x4Row_SVE2(const uint8_t* src_a, + int stride_a, + const uint8_t* src_b, + int stride_b, + uint32_t* dst, + int width) { + Ssim4x4Row_SVE_SC(src_a, stride_a, src_b, stride_b, dst, width); +} +#endif // HAS_SSIM4X4ROW_SVE2 + +#ifdef HAS_SSIMWINDOWROW_SVE2 +float SsimWindowRow_SVE2(const uint32_t* row0, + const uint32_t* row1, + int num_windows) { + return SsimWindowRow_SVE_SC(row0, row1, num_windows); +} +#endif // HAS_SSIMWINDOWROW_SVE2 + +#ifdef HAS_ARGBORROW_SVE2 +void ARGBOrRow_SVE2(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + ARGBOrRow_SVE_SC(src_argb, dst_argb, value, width); +} +#endif // HAS_ARGBORROW_SVE2 + +#ifdef HAS_ARGBALPHABLENDROW_SVE2 +void ARGBAlphaBlendRow_SVE2(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + ARGBAlphaBlendRow_SVE_SC(src_argb0, src_argb1, dst_argb, width); +} +#endif // HAS_ARGBALPHABLENDROW_SVE2 + +#endif // !defined(LIBYUV_DISABLE_SVE) && defined(__aarch64__) + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif diff --git a/libs/libyuv/source/row_wasm.cc b/libs/libyuv/source/row_wasm.cc new file mode 100644 index 0000000000..df9e3917a4 --- /dev/null +++ b/libs/libyuv/source/row_wasm.cc @@ -0,0 +1,2047 @@ +/* + * Copyright 2026 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/row.h" + +#if !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) +#include + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +#ifdef __wasm_relaxed_simd__ +#define LIBYUV_WASM_SWIZZLE wasm_i8x16_relaxed_swizzle +#else +#define LIBYUV_WASM_SWIZZLE wasm_i8x16_swizzle +#endif + +// V8 materializes v128.const values and arbitrary i8x16.shuffle masks with +// several instructions at every use, including inside loops. These helpers +// make constants opaque to clang so they are built once, before the loop, +// and kept in registers. Use swizzle with a LoadConst() table instead of +// i8x16.shuffle unless the pattern maps to a native instruction (unpack, +// 32-bit lane shuffle, concat/palignr, even/odd byte unzip). +// Loops that access ptr + 16 etc. use asm("" : "+r"(ptr)) so LLVM keeps the +// constant offsets in the load/store instructions instead of creating extra +// pointer induction variables. +static inline v128_t LoadConst(const void* p) { + asm("" : "+r"(p)); + return wasm_v128_load(p); +} +static inline v128_t SplatConst8(int v) { + asm("" : "+r"(v)); + return wasm_i8x16_splat(v); +} +static inline v128_t SplatConst16(int v) { + asm("" : "+r"(v)); + return wasm_i16x8_splat(v); +} +static inline v128_t SplatConst32(int v) { + asm("" : "+r"(v)); + return wasm_i32x4_splat(v); +} + +#ifdef HAS_RAWTORGB24ROW_WASMSIMD +static const uint8_t kRawToRGB24SwizzleTable[96] = { + 2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 1, 0, 128, 4, 3, 2, 7, 6, 5, 10, 9, 8, 13, 12, + 11, 128, 15, 128, 1, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 2, 128, 128, 3, 2, 1, 6, 5, 4, 9, 8, 7, 12, + 11, 10, 15, 14, 13, 14, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128}; + +void RAWToRGB24Row_WASMSIMD(const uint8_t* src_raw, + uint8_t* dst_rgb24, + int width) { + const uint8_t* shuf = kRawToRGB24SwizzleTable; + // Load shuffle masks into Wasm locals outside the loop so Binaryen's + // precompute-propagate pass does not sink v128.const into the loop. + asm("" : "+r"(shuf)); + v128_t kShuf0_0 = wasm_v128_load(shuf); + v128_t kShuf0_1 = wasm_v128_load(shuf + 16); + v128_t kShuf1_1 = wasm_v128_load(shuf + 32); + v128_t kShuf1_02 = wasm_v128_load(shuf + 48); + v128_t kShuf2_2 = wasm_v128_load(shuf + 64); + v128_t kShuf2_1 = wasm_v128_load(shuf + 80); + + while (width >= 32) { + // Prevent LLVM LSR from splitting constant load/store offsets into separate + // pointer induction variables. + asm("" : "+r"(src_raw), "+r"(dst_rgb24)); + v128_t s0 = wasm_v128_load(src_raw); + v128_t s1 = wasm_v128_load(src_raw + 16); + v128_t s2 = wasm_v128_load(src_raw + 32); + v128_t s3 = wasm_v128_load(src_raw + 48); + v128_t s4 = wasm_v128_load(src_raw + 64); + v128_t s5 = wasm_v128_load(src_raw + 80); + + v128_t s02 = wasm_i8x16_shuffle(s0, s2, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29); + v128_t s35 = wasm_i8x16_shuffle(s3, s5, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29); + + v128_t d0 = wasm_v128_or(LIBYUV_WASM_SWIZZLE(s0, kShuf0_0), + LIBYUV_WASM_SWIZZLE(s1, kShuf0_1)); + v128_t d1 = wasm_v128_or(LIBYUV_WASM_SWIZZLE(s1, kShuf1_1), + LIBYUV_WASM_SWIZZLE(s02, kShuf1_02)); + v128_t d2 = wasm_v128_or(LIBYUV_WASM_SWIZZLE(s2, kShuf2_2), + LIBYUV_WASM_SWIZZLE(s1, kShuf2_1)); + v128_t d3 = wasm_v128_or(LIBYUV_WASM_SWIZZLE(s3, kShuf0_0), + LIBYUV_WASM_SWIZZLE(s4, kShuf0_1)); + v128_t d4 = wasm_v128_or(LIBYUV_WASM_SWIZZLE(s4, kShuf1_1), + LIBYUV_WASM_SWIZZLE(s35, kShuf1_02)); + v128_t d5 = wasm_v128_or(LIBYUV_WASM_SWIZZLE(s5, kShuf2_2), + LIBYUV_WASM_SWIZZLE(s4, kShuf2_1)); + + wasm_v128_store(dst_rgb24, d0); + wasm_v128_store(dst_rgb24 + 16, d1); + wasm_v128_store(dst_rgb24 + 32, d2); + wasm_v128_store(dst_rgb24 + 48, d3); + wasm_v128_store(dst_rgb24 + 64, d4); + wasm_v128_store(dst_rgb24 + 80, d5); + + src_raw += 96; + dst_rgb24 += 96; + width -= 32; + } + if (width > 0) { + asm("" : "+r"(src_raw), "+r"(dst_rgb24)); + v128_t s0 = wasm_v128_load(src_raw); + v128_t s1 = wasm_v128_load(src_raw + 16); + v128_t s2 = wasm_v128_load(src_raw + 32); + + v128_t s02 = wasm_i8x16_shuffle(s0, s2, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29); + + v128_t d0 = wasm_v128_or(LIBYUV_WASM_SWIZZLE(s0, kShuf0_0), + LIBYUV_WASM_SWIZZLE(s1, kShuf0_1)); + v128_t d1 = wasm_v128_or(LIBYUV_WASM_SWIZZLE(s1, kShuf1_1), + LIBYUV_WASM_SWIZZLE(s02, kShuf1_02)); + v128_t d2 = wasm_v128_or(LIBYUV_WASM_SWIZZLE(s2, kShuf2_2), + LIBYUV_WASM_SWIZZLE(s1, kShuf2_1)); + + wasm_v128_store(dst_rgb24, d0); + wasm_v128_store(dst_rgb24 + 16, d1); + wasm_v128_store(dst_rgb24 + 32, d2); + } +} +#endif // HAS_RAWTORGB24ROW_WASMSIMD + +#if defined(HAS_RAWTOARGBROW_WASMSIMD) || defined(HAS_RGB24TOARGBROW_WASMSIMD) +// 16 pixels of 3 bytes to 4 bytes. shuf holds 2 masks: one for loads at +// offsets 0, 12, 24 and one for the load at offset 32 (avoids over-read). +static void RGB3ToARGBRow_WASMSIMD(const uint8_t* src, + uint8_t* dst_argb, + int width, + const uint8_t* shuf) { + v128_t m0 = LoadConst(shuf); + v128_t m1 = LoadConst(shuf + 16); + v128_t alpha = SplatConst32((int)0xff000000); + do { + asm("" : "+r"(src), "+r"(dst_argb)); + v128_t d0 = LIBYUV_WASM_SWIZZLE(wasm_v128_load(src), m0); + v128_t d1 = LIBYUV_WASM_SWIZZLE(wasm_v128_load(src + 12), m0); + v128_t d2 = LIBYUV_WASM_SWIZZLE(wasm_v128_load(src + 24), m0); + v128_t d3 = LIBYUV_WASM_SWIZZLE(wasm_v128_load(src + 32), m1); + wasm_v128_store(dst_argb, wasm_v128_or(d0, alpha)); + wasm_v128_store(dst_argb + 16, wasm_v128_or(d1, alpha)); + wasm_v128_store(dst_argb + 32, wasm_v128_or(d2, alpha)); + wasm_v128_store(dst_argb + 48, wasm_v128_or(d3, alpha)); + src += 48; + dst_argb += 64; + width -= 16; + } while (width > 0); +} +#endif + +#ifdef HAS_RAWTOARGBROW_WASMSIMD +static const uint8_t kShuffleRAWToARGB[32] = { + 2, 1, 0, 128, 5, 4, 3, 128, 8, 7, 6, 128, 11, 10, 9, 128, + 6, 5, 4, 128, 9, 8, 7, 128, 12, 11, 10, 128, 15, 14, 13, 128}; +void RAWToARGBRow_WASMSIMD(const uint8_t* src_raw, + uint8_t* dst_argb, + int width) { + RGB3ToARGBRow_WASMSIMD(src_raw, dst_argb, width, kShuffleRAWToARGB); +} +#endif // HAS_RAWTOARGBROW_WASMSIMD + +#ifdef HAS_RGB24TOARGBROW_WASMSIMD +static const uint8_t kShuffleRGB24ToARGB[32] = { + 0, 1, 2, 128, 3, 4, 5, 128, 6, 7, 8, 128, 9, 10, 11, 128, + 4, 5, 6, 128, 7, 8, 9, 128, 10, 11, 12, 128, 13, 14, 15, 128}; +void RGB24ToARGBRow_WASMSIMD(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width) { + RGB3ToARGBRow_WASMSIMD(src_rgb24, dst_argb, width, kShuffleRGB24ToARGB); +} +#endif // HAS_RGB24TOARGBROW_WASMSIMD + +#if defined(HAS_ARGBTOYMATRIXROW_WASMSIMD) || \ + defined(HAS_ARGBTOUV444MATRIXROW_WASMSIMD) || \ + defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) || \ + defined(HAS_RGBTOYMATRIXROW_WASMSIMD) || \ + defined(HAS_RGBTOUV444MATRIXROW_WASMSIMD) || \ + defined(HAS_RGBTOUVMATRIXROW_WASMSIMD) || \ + defined(HAS_RGB565TOYMATRIXROW_WASMSIMD) || \ + defined(HAS_ARGB1555TOYMATRIXROW_WASMSIMD) || \ + defined(HAS_ARGB4444TOYMATRIXROW_WASMSIMD) || \ + defined(HAS_RGB565TOUVMATRIXROW_WASMSIMD) || \ + defined(HAS_ARGB1555TOUVMATRIXROW_WASMSIMD) || \ + defined(HAS_ARGB4444TOUVMATRIXROW_WASMSIMD) +// RGB to YUV. Math is in 16 bit lanes, which wrap, but sum + bias fits in +// 16 bits so the results match the C code. i32x4.dot_i16x8_s would be best +// on x86 but is 3 instructions on Arm, so i16x8.mul (mul + mla on Arm) and +// horizontal adds that are cheap on both are used instead. + +// lo * k0 + hi * k1. +static inline v128_t MulAdd16(v128_t lo, v128_t hi, v128_t k0, v128_t k1) { + return wasm_i16x8_add(wasm_i16x8_mul(lo, k0), wasm_i16x8_mul(hi, k1)); +} + +// Sums adjacent 16 bit lanes of t0 and t1. +static inline v128_t HAddPairs16(v128_t t0, v128_t t1) { + return wasm_i16x8_add(wasm_i16x8_shuffle(t0, t1, 0, 2, 4, 6, 8, 10, 12, 14), + wasm_i16x8_shuffle(t0, t1, 1, 3, 5, 7, 9, 11, 13, 15)); +} + +// Splats 16 bit {lo, hi} into each 32 bit lane. +static inline v128_t SplatPair16(int lo, int hi) { + return SplatConst32((lo & 0xffff) | (hi << 16)); +} + +// (bias - sum) >> 8 for U and V. +static inline v128_t SubShr8(v128_t bias, v128_t sum) { + return wasm_u16x8_shr(wasm_i16x8_sub(bias, sum), 8); +} +#endif + +#if defined(HAS_ARGBTOUV444MATRIXROW_WASMSIMD) || \ + defined(HAS_RGBTOYMATRIXROW_WASMSIMD) || \ + defined(HAS_RGBTOUV444MATRIXROW_WASMSIMD) +// Swizzles 4 pixels to 16 bit {c0 x4, c2 x4} and {c1 x4, c3 x4}, so the 2 +// halves of the products are summed with a 64 bit interleave. +static const uint8_t kShuffleARGBToPlanar[32] = { + 0, 128, 4, 128, 8, 128, 12, 128, 2, 128, 6, 128, 10, 128, 14, 128, + 1, 128, 5, 128, 9, 128, 13, 128, 3, 128, 7, 128, 11, 128, 15, 128}; +// RGB24 to {b x4, r x4} and {g x4, 0 x4}. The second pair of masks is for +// the load at offset 32 (avoids over-read). +static const uint8_t kShuffleRGBToPlanar[64] = { + 0, 128, 3, 128, 6, 128, 9, 128, 2, 128, 5, 128, 8, 128, 11, 128, + 1, 128, 4, 128, 7, 128, 10, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 4, 128, 7, 128, 10, 128, 13, 128, 6, 128, 9, 128, 12, 128, 15, 128, + 5, 128, 8, 128, 11, 128, 14, 128, 128, 128, 128, 128, 128, 128, 128, 128}; + +// {a x4, b x4} as 16 bit lanes. +static inline v128_t Splat4x2(int a, int b) { + asm("" : "+r"(a), "+r"(b)); + return wasm_i16x8_make(a, a, a, a, b, b, b, b); +} + +// Sums the 64 bit halves of t0 and t1. +static inline v128_t HAddHalves64(v128_t t0, v128_t t1) { + return wasm_i16x8_add(wasm_i64x2_shuffle(t0, t1, 0, 2), + wasm_i64x2_shuffle(t0, t1, 1, 3)); +} + +// 16 U and V from 16 pixels swizzled by m (m[0], m[1] for the first 3 +// vectors, m[2], m[3] for the last). +static inline void PlanarToUV16(const v128_t* s, + const v128_t* m, + v128_t ku02, + v128_t ku13, + v128_t kv02, + v128_t kv13, + v128_t bias_u, + v128_t bias_v, + uint8_t* dst_u, + uint8_t* dst_v) { + v128_t u[4], v[4]; + for (int i = 0; i < 4; ++i) { + v128_t lo = LIBYUV_WASM_SWIZZLE(s[i], m[i == 3 ? 2 : 0]); + v128_t hi = LIBYUV_WASM_SWIZZLE(s[i], m[i == 3 ? 3 : 1]); + u[i] = MulAdd16(lo, hi, ku02, ku13); + v[i] = MulAdd16(lo, hi, kv02, kv13); + } + wasm_v128_store(dst_u, wasm_u8x16_narrow_i16x8( + SubShr8(bias_u, HAddHalves64(u[0], u[1])), + SubShr8(bias_u, HAddHalves64(u[2], u[3])))); + wasm_v128_store(dst_v, wasm_u8x16_narrow_i16x8( + SubShr8(bias_v, HAddHalves64(v[0], v[1])), + SubShr8(bias_v, HAddHalves64(v[2], v[3])))); +} +#endif + +#if defined(HAS_ARGBTOUVMATRIXROW_WASMSIMD) || \ + defined(HAS_RGBTOUVMATRIXROW_WASMSIMD) +// Rounded 2x2 average of 8 pixels held as 16 bit {c0, c2} or {c1, c3} +// pairs. a = row 0, b = row 1, 4 pixels per vector. Returns 4 pixels. +static inline v128_t Avg2x2Pairs(v128_t a0, + v128_t a1, + v128_t b0, + v128_t b1, + v128_t two) { + v128_t s0 = wasm_i16x8_add(a0, b0); + v128_t s1 = wasm_i16x8_add(a1, b1); + v128_t s = wasm_i16x8_add(wasm_i32x4_shuffle(s0, s1, 0, 2, 4, 6), + wasm_i32x4_shuffle(s0, s1, 1, 3, 5, 7)); + return wasm_u16x8_shr(wasm_i16x8_add(s, two), 2); +} + +// Stores 8 U and 8 V from 2 vectors each of {c0, c2} and {c1, c3} pairs. +static inline void PairsToUV8(const v128_t* lo, + const v128_t* hi, + v128_t ku02, + v128_t ku13, + v128_t kv02, + v128_t kv13, + v128_t bias_u, + v128_t bias_v, + uint8_t* dst_u, + uint8_t* dst_v) { + v128_t u = HAddPairs16(MulAdd16(lo[0], hi[0], ku02, ku13), + MulAdd16(lo[1], hi[1], ku02, ku13)); + v128_t v = HAddPairs16(MulAdd16(lo[0], hi[0], kv02, kv13), + MulAdd16(lo[1], hi[1], kv02, kv13)); + v128_t uv = wasm_u8x16_narrow_i16x8(SubShr8(bias_u, u), SubShr8(bias_v, v)); + wasm_v128_store64_lane(dst_u, uv, 0); + wasm_v128_store64_lane(dst_v, uv, 1); +} +#endif + +#ifdef HAS_ARGBTOYMATRIXROW_WASMSIMD +void ARGBToYMatrixRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + v128_t mask = SplatConst16(0xff); + v128_t k02 = SplatPair16(c->kRGBToY[0], c->kRGBToY[2]); + v128_t k13 = SplatPair16(c->kRGBToY[1], c->kRGBToY[3]); + v128_t bias = SplatConst16(c->kAddY[0]); + do { + v128_t t[4]; + for (int i = 0; i < 4; ++i) { + v128_t s = wasm_v128_load(src_argb + i * 16); + t[i] = MulAdd16(wasm_v128_and(s, mask), wasm_u16x8_shr(s, 8), k02, k13); + } + v128_t y0 = wasm_i16x8_add(HAddPairs16(t[0], t[1]), bias); + v128_t y1 = wasm_i16x8_add(HAddPairs16(t[2], t[3]), bias); + wasm_v128_store(dst_y, wasm_u8x16_narrow_i16x8(wasm_u16x8_shr(y0, 8), + wasm_u16x8_shr(y1, 8))); + src_argb += 64; + dst_y += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_ARGBTOYMATRIXROW_WASMSIMD + +#ifdef HAS_RGBTOYMATRIXROW_WASMSIMD +// RGB24 is alpha 255 in the C version, so 255 * kRGBToY[3] is in the bias. +void RGBToYMatrixRow_WASMSIMD(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + v128_t m[4]; + for (int i = 0; i < 4; ++i) { + m[i] = LoadConst(kShuffleRGBToPlanar + i * 16); + } + v128_t k02 = Splat4x2(c->kRGBToY[0], c->kRGBToY[2]); + v128_t k13 = Splat4x2(c->kRGBToY[1], 0); + v128_t bias = SplatConst16(c->kAddY[0] + 255 * c->kRGBToY[3]); + do { + v128_t t[4]; + for (int i = 0; i < 4; ++i) { + v128_t s = wasm_v128_load(src_rgb + (i == 3 ? 32 : i * 12)); + t[i] = MulAdd16(LIBYUV_WASM_SWIZZLE(s, m[i == 3 ? 2 : 0]), + LIBYUV_WASM_SWIZZLE(s, m[i == 3 ? 3 : 1]), k02, k13); + } + v128_t y0 = wasm_i16x8_add(HAddHalves64(t[0], t[1]), bias); + v128_t y1 = wasm_i16x8_add(HAddHalves64(t[2], t[3]), bias); + wasm_v128_store(dst_y, wasm_u8x16_narrow_i16x8(wasm_u16x8_shr(y0, 8), + wasm_u16x8_shr(y1, 8))); + src_rgb += 48; + dst_y += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_RGBTOYMATRIXROW_WASMSIMD + +#ifdef HAS_ARGBTOUV444MATRIXROW_WASMSIMD +void ARGBToUV444MatrixRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + v128_t m[4]; + m[0] = m[2] = LoadConst(kShuffleARGBToPlanar); + m[1] = m[3] = LoadConst(kShuffleARGBToPlanar + 16); + v128_t ku02 = Splat4x2(c->kRGBToU[0], c->kRGBToU[2]); + v128_t ku13 = Splat4x2(c->kRGBToU[1], c->kRGBToU[3]); + v128_t kv02 = Splat4x2(c->kRGBToV[0], c->kRGBToV[2]); + v128_t kv13 = Splat4x2(c->kRGBToV[1], c->kRGBToV[3]); + v128_t bias = SplatConst16(c->kAddUV[0]); + do { + v128_t s[4]; + for (int i = 0; i < 4; ++i) { + s[i] = wasm_v128_load(src_argb + i * 16); + } + PlanarToUV16(s, m, ku02, ku13, kv02, kv13, bias, bias, dst_u, dst_v); + src_argb += 64; + dst_u += 16; + dst_v += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_ARGBTOUV444MATRIXROW_WASMSIMD + +#ifdef HAS_RGBTOUV444MATRIXROW_WASMSIMD +void RGBToUV444MatrixRow_WASMSIMD(const uint8_t* src_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + v128_t m[4]; + for (int i = 0; i < 4; ++i) { + m[i] = LoadConst(kShuffleRGBToPlanar + i * 16); + } + v128_t ku02 = Splat4x2(c->kRGBToU[0], c->kRGBToU[2]); + v128_t ku13 = Splat4x2(c->kRGBToU[1], 0); + v128_t kv02 = Splat4x2(c->kRGBToV[0], c->kRGBToV[2]); + v128_t kv13 = Splat4x2(c->kRGBToV[1], 0); + v128_t bias_u = SplatConst16(c->kAddUV[0] - 255 * c->kRGBToU[3]); + v128_t bias_v = SplatConst16(c->kAddUV[0] - 255 * c->kRGBToV[3]); + do { + v128_t s[4]; + for (int i = 0; i < 4; ++i) { + s[i] = wasm_v128_load(src_rgb + (i == 3 ? 32 : i * 12)); + } + PlanarToUV16(s, m, ku02, ku13, kv02, kv13, bias_u, bias_v, dst_u, dst_v); + src_rgb += 48; + dst_u += 16; + dst_v += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_RGBTOUV444MATRIXROW_WASMSIMD + +#ifdef HAS_ARGBTOUVMATRIXROW_WASMSIMD +void ARGBToUVMatrixRow_WASMSIMD(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + const uint8_t* src_argb1 = src_argb + src_stride_argb; + v128_t mask = SplatConst16(0xff); + v128_t two = SplatConst16(2); + v128_t ku02 = SplatPair16(c->kRGBToU[0], c->kRGBToU[2]); + v128_t ku13 = SplatPair16(c->kRGBToU[1], c->kRGBToU[3]); + v128_t kv02 = SplatPair16(c->kRGBToV[0], c->kRGBToV[2]); + v128_t kv13 = SplatPair16(c->kRGBToV[1], c->kRGBToV[3]); + v128_t bias = SplatConst16(c->kAddUV[0]); + do { + v128_t lo[2], hi[2]; + for (int i = 0; i < 2; ++i) { + v128_t a0 = wasm_v128_load(src_argb + i * 32); + v128_t a1 = wasm_v128_load(src_argb + i * 32 + 16); + v128_t b0 = wasm_v128_load(src_argb1 + i * 32); + v128_t b1 = wasm_v128_load(src_argb1 + i * 32 + 16); + lo[i] = + Avg2x2Pairs(wasm_v128_and(a0, mask), wasm_v128_and(a1, mask), + wasm_v128_and(b0, mask), wasm_v128_and(b1, mask), two); + hi[i] = Avg2x2Pairs(wasm_u16x8_shr(a0, 8), wasm_u16x8_shr(a1, 8), + wasm_u16x8_shr(b0, 8), wasm_u16x8_shr(b1, 8), two); + } + PairsToUV8(lo, hi, ku02, ku13, kv02, kv13, bias, bias, dst_u, dst_v); + src_argb += 64; + src_argb1 += 64; + dst_u += 8; + dst_v += 8; + width -= 16; + } while (width > 0); +} +#endif // HAS_ARGBTOUVMATRIXROW_WASMSIMD + +#ifdef HAS_RGBTOUVMATRIXROW_WASMSIMD +// Swizzles 4 RGB24 pixels to 16 bit {b, r} and {g, 0} pairs. The second +// pair of masks is for the load at offset 32 (avoids over-read). +static const uint8_t kShuffleRGBToPairs[64] = { + 0, 128, 2, 128, 3, 128, 5, 128, 6, 128, 8, 128, 9, 128, 11, 128, + 1, 128, 128, 128, 4, 128, 128, 128, 7, 128, 128, 128, 10, 128, 128, 128, + 4, 128, 6, 128, 7, 128, 9, 128, 10, 128, 12, 128, 13, 128, 15, 128, + 5, 128, 128, 128, 8, 128, 128, 128, 11, 128, 128, 128, 14, 128, 128, 128}; + +void RGBToUVMatrixRow_WASMSIMD(const uint8_t* src_rgb, + int src_stride_rgb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + const uint8_t* src_rgb1 = src_rgb + src_stride_rgb; + v128_t m[4]; + for (int i = 0; i < 4; ++i) { + m[i] = LoadConst(kShuffleRGBToPairs + i * 16); + } + v128_t two = SplatConst16(2); + v128_t ku02 = SplatPair16(c->kRGBToU[0], c->kRGBToU[2]); + v128_t ku13 = SplatPair16(c->kRGBToU[1], 0); + v128_t kv02 = SplatPair16(c->kRGBToV[0], c->kRGBToV[2]); + v128_t kv13 = SplatPair16(c->kRGBToV[1], 0); + v128_t bias_u = SplatConst16(c->kAddUV[0] - 255 * c->kRGBToU[3]); + v128_t bias_v = SplatConst16(c->kAddUV[0] - 255 * c->kRGBToV[3]); + do { + v128_t lo[2], hi[2]; + for (int i = 0; i < 2; ++i) { + // Pixels 8 * i to 8 * i + 3 at offset 24 * i, the rest at 12 or 32. + int off = i ? 32 : 12; + v128_t a0 = wasm_v128_load(src_rgb + i * 24); + v128_t a1 = wasm_v128_load(src_rgb + off); + v128_t b0 = wasm_v128_load(src_rgb1 + i * 24); + v128_t b1 = wasm_v128_load(src_rgb1 + off); + v128_t ml = m[i * 2]; + v128_t mh = m[i * 2 + 1]; + lo[i] = Avg2x2Pairs( + LIBYUV_WASM_SWIZZLE(a0, m[0]), LIBYUV_WASM_SWIZZLE(a1, ml), + LIBYUV_WASM_SWIZZLE(b0, m[0]), LIBYUV_WASM_SWIZZLE(b1, ml), two); + hi[i] = Avg2x2Pairs( + LIBYUV_WASM_SWIZZLE(a0, m[1]), LIBYUV_WASM_SWIZZLE(a1, mh), + LIBYUV_WASM_SWIZZLE(b0, m[1]), LIBYUV_WASM_SWIZZLE(b1, mh), two); + } + PairsToUV8(lo, hi, ku02, ku13, kv02, kv13, bias_u, bias_v, dst_u, dst_v); + src_rgb += 48; + src_rgb1 += 48; + dst_u += 8; + dst_v += 8; + width -= 16; + } while (width > 0); +} +#endif // HAS_RGBTOUVMATRIXROW_WASMSIMD + +// 16 bit pixel formats keep each channel in its own 16 bit lane. +// 5 and 6 bit channels expand as (v * 33) >> 2 and (v * 65) >> 4, and 4 bit +// channels as v * 17, which match the C bit replication. + +#if defined(HAS_RGB565TOUVMATRIXROW_WASMSIMD) || \ + defined(HAS_ARGB1555TOUVMATRIXROW_WASMSIMD) || \ + defined(HAS_ARGB4444TOUVMATRIXROW_WASMSIMD) +// Rounded 2x2 average of 16 pixels of 1 channel. a = row 0, b = row 1. +static inline v128_t Avg2x2Lanes(v128_t a0, + v128_t a1, + v128_t b0, + v128_t b1, + v128_t two) { + v128_t s = HAddPairs16(wasm_i16x8_add(a0, b0), wasm_i16x8_add(a1, b1)); + return wasm_u16x8_shr(wasm_i16x8_add(s, two), 2); +} + +// Stores 8 U and 8 V from 8 pixels of 16 bit channels. k holds U +// coefficients for b, g, r, a, then V coefficients, then bias U and V. +static inline void ChannelsToUV8(v128_t b, + v128_t g, + v128_t r, + v128_t a, + const v128_t* k, + uint8_t* dst_u, + uint8_t* dst_v) { + v128_t u = + wasm_i16x8_add(MulAdd16(b, g, k[0], k[1]), MulAdd16(r, a, k[2], k[3])); + v128_t v = + wasm_i16x8_add(MulAdd16(b, g, k[4], k[5]), MulAdd16(r, a, k[6], k[7])); + v128_t uv = wasm_u8x16_narrow_i16x8(SubShr8(k[8], u), SubShr8(k[9], v)); + wasm_v128_store64_lane(dst_u, uv, 0); + wasm_v128_store64_lane(dst_v, uv, 1); +} + +// U and V coefficients for ChannelsToUV8. The alpha term is folded into the +// bias if alpha is always 255 (opaque). +static inline void LoadUVChannelConstants(const struct ArgbConstants* c, + int opaque, + v128_t* k) { + for (int i = 0; i < 4; ++i) { + k[i] = SplatConst16(c->kRGBToU[i]); + k[i + 4] = SplatConst16(c->kRGBToV[i]); + } + k[8] = SplatConst16(c->kAddUV[0] - opaque * 255 * c->kRGBToU[3]); + k[9] = SplatConst16(c->kAddUV[0] - opaque * 255 * c->kRGBToV[3]); +} +#endif +#ifdef HAS_RGB565TOYMATRIXROW_WASMSIMD +void RGB565ToYMatrixRow_WASMSIMD(const uint8_t* src_rgb565, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + v128_t m5 = SplatConst16(0x1f); + v128_t m6 = SplatConst16(0x3f); + v128_t k33 = SplatConst16(33); + v128_t k65 = SplatConst16(65); + v128_t kb = SplatConst16(c->kRGBToY[0]); + v128_t kg = SplatConst16(c->kRGBToY[1]); + v128_t kr = SplatConst16(c->kRGBToY[2]); + v128_t bias = SplatConst16(c->kAddY[0] + 255 * c->kRGBToY[3]); + do { + v128_t y[2]; + for (int i = 0; i < 2; ++i) { + v128_t x = wasm_v128_load(src_rgb565 + i * 16); + v128_t b = wasm_u16x8_shr(wasm_i16x8_mul(wasm_v128_and(x, m5), k33), 2); + v128_t g = wasm_u16x8_shr( + wasm_i16x8_mul(wasm_v128_and(wasm_u16x8_shr(x, 5), m6), k65), 4); + v128_t r = wasm_u16x8_shr(wasm_i16x8_mul(wasm_u16x8_shr(x, 11), k33), 2); + v128_t s = wasm_i16x8_add(wasm_i16x8_mul(b, kb), bias); + y[i] = wasm_u16x8_shr(wasm_i16x8_add(s, MulAdd16(g, r, kg, kr)), 8); + } + wasm_v128_store(dst_y, wasm_u8x16_narrow_i16x8(y[0], y[1])); + src_rgb565 += 32; + dst_y += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_RGB565TOYMATRIXROW_WASMSIMD + +#ifdef HAS_ARGB1555TOYMATRIXROW_WASMSIMD +void ARGB1555ToYMatrixRow_WASMSIMD(const uint8_t* src_argb1555, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + v128_t m5 = SplatConst16(0x1f); + v128_t k33 = SplatConst16(33); + v128_t kb = SplatConst16(c->kRGBToY[0]); + v128_t kg = SplatConst16(c->kRGBToY[1]); + v128_t kr = SplatConst16(c->kRGBToY[2]); + v128_t ka = SplatConst16(255 * c->kRGBToY[3]); + v128_t bias = SplatConst16(c->kAddY[0]); + do { + v128_t y[2]; + for (int i = 0; i < 2; ++i) { + v128_t x = wasm_v128_load(src_argb1555 + i * 16); + v128_t b = wasm_u16x8_shr(wasm_i16x8_mul(wasm_v128_and(x, m5), k33), 2); + v128_t g = wasm_u16x8_shr( + wasm_i16x8_mul(wasm_v128_and(wasm_u16x8_shr(x, 5), m5), k33), 2); + v128_t r = wasm_u16x8_shr( + wasm_i16x8_mul(wasm_v128_and(wasm_u16x8_shr(x, 10), m5), k33), 2); + // Alpha is 0 or 255. + v128_t s = wasm_i16x8_add(wasm_v128_and(wasm_i16x8_shr(x, 15), ka), bias); + s = wasm_i16x8_add(s, wasm_i16x8_mul(b, kb)); + y[i] = wasm_u16x8_shr(wasm_i16x8_add(s, MulAdd16(g, r, kg, kr)), 8); + } + wasm_v128_store(dst_y, wasm_u8x16_narrow_i16x8(y[0], y[1])); + src_argb1555 += 32; + dst_y += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_ARGB1555TOYMATRIXROW_WASMSIMD + +#ifdef HAS_ARGB4444TOYMATRIXROW_WASMSIMD +// 4 bit channels expand as v * 17, so the coefficients are scaled by 17. +void ARGB4444ToYMatrixRow_WASMSIMD(const uint8_t* src_argb4444, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + v128_t m4 = SplatConst16(0x0f); + v128_t kb = SplatConst16(c->kRGBToY[0] * 17); + v128_t kg = SplatConst16(c->kRGBToY[1] * 17); + v128_t kr = SplatConst16(c->kRGBToY[2] * 17); + v128_t ka = SplatConst16(c->kRGBToY[3] * 17); + v128_t bias = SplatConst16(c->kAddY[0]); + do { + v128_t y[2]; + for (int i = 0; i < 2; ++i) { + v128_t x = wasm_v128_load(src_argb4444 + i * 16); + v128_t s = wasm_i16x8_add( + MulAdd16(wasm_v128_and(x, m4), wasm_u16x8_shr(x, 12), kb, ka), bias); + s = wasm_i16x8_add( + s, MulAdd16(wasm_v128_and(wasm_u16x8_shr(x, 4), m4), + wasm_v128_and(wasm_u16x8_shr(x, 8), m4), kg, kr)); + y[i] = wasm_u16x8_shr(s, 8); + } + wasm_v128_store(dst_y, wasm_u8x16_narrow_i16x8(y[0], y[1])); + src_argb4444 += 32; + dst_y += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_ARGB4444TOYMATRIXROW_WASMSIMD + +#ifdef HAS_RGB565TOUVMATRIXROW_WASMSIMD +void RGB565ToUVMatrixRow_WASMSIMD(const uint8_t* src_rgb565, + int src_stride_rgb565, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + const uint8_t* src_rgb565_1 = src_rgb565 + src_stride_rgb565; + v128_t m5 = SplatConst16(0x1f); + v128_t m6 = SplatConst16(0x3f); + v128_t k33 = SplatConst16(33); + v128_t k65 = SplatConst16(65); + v128_t two = SplatConst16(2); + v128_t k[10]; + LoadUVChannelConstants(c, 1, k); + do { + v128_t b[4], g[4], r[4]; + for (int i = 0; i < 4; ++i) { + v128_t x = + wasm_v128_load((i & 2 ? src_rgb565_1 : src_rgb565) + (i & 1) * 16); + b[i] = wasm_u16x8_shr(wasm_i16x8_mul(wasm_v128_and(x, m5), k33), 2); + g[i] = wasm_u16x8_shr( + wasm_i16x8_mul(wasm_v128_and(wasm_u16x8_shr(x, 5), m6), k65), 4); + r[i] = wasm_u16x8_shr(wasm_i16x8_mul(wasm_u16x8_shr(x, 11), k33), 2); + } + ChannelsToUV8(Avg2x2Lanes(b[0], b[1], b[2], b[3], two), + Avg2x2Lanes(g[0], g[1], g[2], g[3], two), + Avg2x2Lanes(r[0], r[1], r[2], r[3], two), + wasm_i16x8_const_splat(0), k, dst_u, dst_v); + src_rgb565 += 32; + src_rgb565_1 += 32; + dst_u += 8; + dst_v += 8; + width -= 16; + } while (width > 0); +} +#endif // HAS_RGB565TOUVMATRIXROW_WASMSIMD + +#ifdef HAS_ARGB1555TOUVMATRIXROW_WASMSIMD +void ARGB1555ToUVMatrixRow_WASMSIMD(const uint8_t* src_argb1555, + int src_stride_argb1555, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + const uint8_t* src_argb1555_1 = src_argb1555 + src_stride_argb1555; + v128_t m5 = SplatConst16(0x1f); + v128_t k33 = SplatConst16(33); + v128_t two = SplatConst16(2); + v128_t k[10]; + LoadUVChannelConstants(c, 0, k); + do { + v128_t b[4], g[4], r[4], a[4]; + for (int i = 0; i < 4; ++i) { + v128_t x = wasm_v128_load((i & 2 ? src_argb1555_1 : src_argb1555) + + (i & 1) * 16); + b[i] = wasm_u16x8_shr(wasm_i16x8_mul(wasm_v128_and(x, m5), k33), 2); + g[i] = wasm_u16x8_shr( + wasm_i16x8_mul(wasm_v128_and(wasm_u16x8_shr(x, 5), m5), k33), 2); + r[i] = wasm_u16x8_shr( + wasm_i16x8_mul(wasm_v128_and(wasm_u16x8_shr(x, 10), m5), k33), 2); + a[i] = wasm_u16x8_shr(wasm_i16x8_shr(x, 15), 8); + } + ChannelsToUV8(Avg2x2Lanes(b[0], b[1], b[2], b[3], two), + Avg2x2Lanes(g[0], g[1], g[2], g[3], two), + Avg2x2Lanes(r[0], r[1], r[2], r[3], two), + Avg2x2Lanes(a[0], a[1], a[2], a[3], two), k, dst_u, dst_v); + src_argb1555 += 32; + src_argb1555_1 += 32; + dst_u += 8; + dst_v += 8; + width -= 16; + } while (width > 0); +} +#endif // HAS_ARGB1555TOUVMATRIXROW_WASMSIMD + +#ifdef HAS_ARGB4444TOUVMATRIXROW_WASMSIMD +// Sums the nibble pairs {b, r} and {g, a} of 2x2 pixels in bytes, then +// expands the sums by 17 before rounding. +void ARGB4444ToUVMatrixRow_WASMSIMD(const uint8_t* src_argb4444, + int src_stride_argb4444, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + const uint8_t* src_argb4444_1 = src_argb4444 + src_stride_argb4444; + v128_t m4 = SplatConst16(0x0f0f); + v128_t m8 = SplatConst16(0xff); + v128_t k17 = SplatConst16(17); + v128_t two = SplatConst16(2); + v128_t k[10]; + LoadUVChannelConstants(c, 0, k); + do { + v128_t s[2], t[2]; + for (int i = 0; i < 2; ++i) { + v128_t a = wasm_v128_load(src_argb4444 + i * 16); + v128_t b = wasm_v128_load(src_argb4444_1 + i * 16); + s[i] = wasm_i16x8_add(wasm_v128_and(a, m4), wasm_v128_and(b, m4)); + t[i] = wasm_i16x8_add(wasm_v128_and(wasm_u16x8_shr(a, 4), m4), + wasm_v128_and(wasm_u16x8_shr(b, 4), m4)); + } + v128_t br = HAddPairs16(s[0], s[1]); + v128_t ga = HAddPairs16(t[0], t[1]); + v128_t ch[4] = {wasm_v128_and(br, m8), wasm_v128_and(ga, m8), + wasm_u16x8_shr(br, 8), wasm_u16x8_shr(ga, 8)}; + for (int i = 0; i < 4; ++i) { + ch[i] = + wasm_u16x8_shr(wasm_i16x8_add(wasm_i16x8_mul(ch[i], k17), two), 2); + } + ChannelsToUV8(ch[0], ch[1], ch[2], ch[3], k, dst_u, dst_v); + src_argb4444 += 32; + src_argb4444_1 += 32; + dst_u += 8; + dst_v += 8; + width -= 16; + } while (width > 0); +} +#endif // HAS_ARGB4444TOUVMATRIXROW_WASMSIMD + +#ifdef HAS_CONVERT8TO16ROW_WASMSIMD +// For bits 8 to 16, (y * 0x0101) >> (16 - bits) == p + (p >> 8) where +// p = y << (bits - 8). This avoids a variable shift count. +void Convert8To16Row_WASMSIMD(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width) { + if (bits < 8) { + Convert8To16Row_C(src_y, dst_y, bits, width); + return; + } + v128_t scale = SplatConst16(1 << (bits - 8)); + do { + asm("" : "+r"(dst_y)); + v128_t y = wasm_v128_load(src_y); + v128_t y0 = wasm_i16x8_mul(wasm_u16x8_extend_low_u8x16(y), scale); + v128_t y1 = wasm_i16x8_mul(wasm_u16x8_extend_high_u8x16(y), scale); + wasm_v128_store(dst_y, wasm_i16x8_add(y0, wasm_u16x8_shr(y0, 8))); + wasm_v128_store(dst_y + 8, wasm_i16x8_add(y1, wasm_u16x8_shr(y1, 8))); + src_y += 16; + dst_y += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_CONVERT8TO16ROW_WASMSIMD + +#ifdef HAS_MULTIPLYROW_16_WASMSIMD +void MultiplyRow_16_WASMSIMD(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + v128_t vscale = wasm_i16x8_splat(scale); + do { + asm("" : "+r"(src_y), "+r"(dst_y)); + v128_t y0 = wasm_v128_load(src_y); + v128_t y1 = wasm_v128_load(src_y + 8); + y0 = wasm_i16x8_mul(y0, vscale); + y1 = wasm_i16x8_mul(y1, vscale); + wasm_v128_store(dst_y, y0); + wasm_v128_store(dst_y + 8, y1); + src_y += 16; + dst_y += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_MULTIPLYROW_16_WASMSIMD + +#ifdef HAS_MERGEUVROW_WASMSIMD +void MergeUVRow_WASMSIMD(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width) { + do { + asm("" : "+r"(dst_uv)); + v128_t u = wasm_v128_load(src_u); + v128_t v = wasm_v128_load(src_v); + v128_t uv0 = wasm_i8x16_shuffle(u, v, 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, + 21, 6, 22, 7, 23); + v128_t uv1 = wasm_i8x16_shuffle(u, v, 8, 24, 9, 25, 10, 26, 11, 27, 12, 28, + 13, 29, 14, 30, 15, 31); + wasm_v128_store(dst_uv, uv0); + wasm_v128_store(dst_uv + 16, uv1); + src_u += 16; + src_v += 16; + dst_uv += 32; + width -= 16; + } while (width > 0); +} +#endif // HAS_MERGEUVROW_WASMSIMD + +#ifdef HAS_MIRRORROW_WASMSIMD +static const uint8_t kShuffleMirror[16] = {15, 14, 13, 12, 11, 10, 9, 8, + 7, 6, 5, 4, 3, 2, 1, 0}; +void MirrorRow_WASMSIMD(const uint8_t* src, uint8_t* dst, int width) { + v128_t shuf = LoadConst(kShuffleMirror); + src += width - 16; + do { + wasm_v128_store(dst, LIBYUV_WASM_SWIZZLE(wasm_v128_load(src), shuf)); + src -= 16; + dst += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_MIRRORROW_WASMSIMD + +#ifdef HAS_MIRRORUVROW_WASMSIMD +static const uint8_t kShuffleMirrorUV[16] = {14, 15, 12, 13, 10, 11, 8, 9, + 6, 7, 4, 5, 2, 3, 0, 1}; +void MirrorUVRow_WASMSIMD(const uint8_t* src_uv, uint8_t* dst_uv, int width) { + v128_t shuf = LoadConst(kShuffleMirrorUV); + src_uv += (width - 8) * 2; + do { + wasm_v128_store(dst_uv, LIBYUV_WASM_SWIZZLE(wasm_v128_load(src_uv), shuf)); + src_uv -= 16; + dst_uv += 16; + width -= 8; + } while (width > 0); +} +#endif // HAS_MIRRORUVROW_WASMSIMD + +#ifdef HAS_SWAPUVROW_WASMSIMD +void SwapUVRow_WASMSIMD(const uint8_t* src_uv, uint8_t* dst_vu, int width) { + do { + // Keep constant offsets in the load/store instructions. + asm("" : "+r"(src_uv), "+r"(dst_vu)); + v128_t uv0 = wasm_v128_load(src_uv); + v128_t uv1 = wasm_v128_load(src_uv + 16); + // 16 bit byte swap: rev16 on Arm, shifts on x86. + wasm_v128_store( + dst_vu, wasm_v128_or(wasm_i16x8_shl(uv0, 8), wasm_u16x8_shr(uv0, 8))); + wasm_v128_store(dst_vu + 16, wasm_v128_or(wasm_i16x8_shl(uv1, 8), + wasm_u16x8_shr(uv1, 8))); + src_uv += 32; + dst_vu += 32; + width -= 16; + } while (width > 0); +} +#endif // HAS_SWAPUVROW_WASMSIMD + +#ifdef HAS_MIRRORSPLITUVROW_WASMSIMD +// Reverses 8 UV pairs into 8 U then 8 V. +static const uint8_t kShuffleMirrorSplitUV[16] = {14, 12, 10, 8, 6, 4, 2, 0, + 15, 13, 11, 9, 7, 5, 3, 1}; +void MirrorSplitUVRow_WASMSIMD(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + v128_t shuf = LoadConst(kShuffleMirrorSplitUV); + src_uv += (width - 16) * 2; + do { + asm("" : "+r"(src_uv)); + v128_t a = LIBYUV_WASM_SWIZZLE(wasm_v128_load(src_uv), shuf); + v128_t b = LIBYUV_WASM_SWIZZLE(wasm_v128_load(src_uv + 16), shuf); + wasm_v128_store(dst_u, wasm_i64x2_shuffle(b, a, 0, 2)); + wasm_v128_store(dst_v, wasm_i64x2_shuffle(b, a, 1, 3)); + src_uv -= 32; + dst_u += 16; + dst_v += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_MIRRORSPLITUVROW_WASMSIMD + +#ifdef HAS_RGB24MIRRORROW_WASMSIMD +// Each 16 byte output needs 18 source bytes, so it is the OR of 2 swizzles. +static const uint8_t kShuffleRGB24Mirror[96] = { + 13, 14, 15, 10, 11, 12, 7, 8, 9, 4, 5, 6, 1, 2, + 3, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 14, 15, 128, 11, 12, 13, 8, 9, 10, 5, 6, + 7, 2, 3, 4, 128, 0, 128, 1, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 0, 128, 128, 12, 13, 14, 9, 10, + 11, 6, 7, 8, 3, 4, 5, 0, 1, 2, 1, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}; +void RGB24MirrorRow_WASMSIMD(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width) { + const uint8_t* shuf = kShuffleRGB24Mirror; + v128_t m0a = LoadConst(shuf); + v128_t m0b = LoadConst(shuf + 16); + v128_t m1a = LoadConst(shuf + 32); + v128_t m1b = LoadConst(shuf + 48); + v128_t m2a = LoadConst(shuf + 64); + v128_t m2b = LoadConst(shuf + 80); + src_rgb24 += (width - 16) * 3; + do { + asm("" : "+r"(src_rgb24), "+r"(dst_rgb24)); + v128_t s0 = wasm_v128_load(src_rgb24); + v128_t s1 = wasm_v128_load(src_rgb24 + 16); + v128_t s2 = wasm_v128_load(src_rgb24 + 32); + // Bytes 15 and 32 of the 48 source bytes. + v128_t s02 = wasm_i8x16_shuffle(s0, s2, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30); + wasm_v128_store(dst_rgb24, wasm_v128_or(LIBYUV_WASM_SWIZZLE(s2, m0a), + LIBYUV_WASM_SWIZZLE(s1, m0b))); + wasm_v128_store(dst_rgb24 + 16, + wasm_v128_or(LIBYUV_WASM_SWIZZLE(s1, m1a), + LIBYUV_WASM_SWIZZLE(s02, m1b))); + wasm_v128_store(dst_rgb24 + 32, wasm_v128_or(LIBYUV_WASM_SWIZZLE(s0, m2a), + LIBYUV_WASM_SWIZZLE(s1, m2b))); + src_rgb24 -= 48; + dst_rgb24 += 48; + width -= 16; + } while (width > 0); +} +#endif // HAS_RGB24MIRRORROW_WASMSIMD + +#ifdef HAS_ARGBMIRRORROW_WASMSIMD +void ARGBMirrorRow_WASMSIMD(const uint8_t* src, uint8_t* dst, int width) { + src += (width - 4) * 4; + do { + v128_t v = wasm_v128_load(src); + v = wasm_i32x4_shuffle(v, v, 3, 2, 1, 0); + wasm_v128_store(dst, v); + src -= 16; + dst += 16; + width -= 4; + } while (width > 0); +} +#endif // HAS_ARGBMIRRORROW_WASMSIMD + +#ifdef HAS_INTERPOLATEROW_WASMSIMD +void InterpolateRow_WASMSIMD(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + const uint8_t* src_ptr1 = src_ptr + src_stride; + if (source_y_fraction == 0) { + do { + wasm_v128_store(dst_ptr, wasm_v128_load(src_ptr)); + src_ptr += 16; + dst_ptr += 16; + width -= 16; + } while (width > 0); + return; + } + if (source_y_fraction == 128) { + do { + v128_t s0 = wasm_v128_load(src_ptr); + v128_t s1 = wasm_v128_load(src_ptr1); + wasm_v128_store(dst_ptr, wasm_u8x16_avgr(s0, s1)); + src_ptr += 16; + src_ptr1 += 16; + dst_ptr += 16; + width -= 16; + } while (width > 0); + return; + } + // s0 * (256 - f) + s1 * f + 128 fits in 16 bits. Both weights fit in 8 + // bits since f is 1 to 255. The high bytes are the result (uzp2 on Arm). + v128_t w0 = SplatConst8(256 - source_y_fraction); + v128_t w1 = SplatConst8(source_y_fraction); + v128_t round = SplatConst16(128); + do { + v128_t s0 = wasm_v128_load(src_ptr); + v128_t s1 = wasm_v128_load(src_ptr1); + v128_t lo = wasm_i16x8_add(wasm_u16x8_extmul_low_u8x16(s0, w0), + wasm_u16x8_extmul_low_u8x16(s1, w1)); + v128_t hi = wasm_i16x8_add(wasm_u16x8_extmul_high_u8x16(s0, w0), + wasm_u16x8_extmul_high_u8x16(s1, w1)); + lo = wasm_i16x8_add(lo, round); + hi = wasm_i16x8_add(hi, round); + wasm_v128_store( + dst_ptr, wasm_i8x16_shuffle(lo, hi, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, + 21, 23, 25, 27, 29, 31)); + src_ptr += 16; + src_ptr1 += 16; + dst_ptr += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_INTERPOLATEROW_WASMSIMD + +#ifdef HAS_INTERPOLATEROW_16_WASMSIMD +void InterpolateRow_16_WASMSIMD(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + const uint16_t* src_ptr1 = src_ptr + src_stride; + if (source_y_fraction == 0) { + do { + wasm_v128_store(dst_ptr, wasm_v128_load(src_ptr)); + src_ptr += 8; + dst_ptr += 8; + width -= 8; + } while (width > 0); + return; + } + if (source_y_fraction == 128) { + do { + v128_t s0 = wasm_v128_load(src_ptr); + v128_t s1 = wasm_v128_load(src_ptr1); + wasm_v128_store(dst_ptr, wasm_u16x8_avgr(s0, s1)); + src_ptr += 8; + src_ptr1 += 8; + dst_ptr += 8; + width -= 8; + } while (width > 0); + return; + } + // s0 * (256 - f) + s1 * f + 128 fits in 24 bits. Shift the result into + // the high 16 bits of each lane, then take the odd 16 bit lanes. + v128_t w0 = SplatConst16(256 - source_y_fraction); + v128_t w1 = SplatConst16(source_y_fraction); + v128_t round = SplatConst32(128); + do { + v128_t s0 = wasm_v128_load(src_ptr); + v128_t s1 = wasm_v128_load(src_ptr1); + v128_t lo = wasm_i32x4_add(wasm_u32x4_extmul_low_u16x8(s0, w0), + wasm_u32x4_extmul_low_u16x8(s1, w1)); + v128_t hi = wasm_i32x4_add(wasm_u32x4_extmul_high_u16x8(s0, w0), + wasm_u32x4_extmul_high_u16x8(s1, w1)); + lo = wasm_i32x4_shl(wasm_i32x4_add(lo, round), 8); + hi = wasm_i32x4_shl(wasm_i32x4_add(hi, round), 8); + wasm_v128_store(dst_ptr, + wasm_i16x8_shuffle(lo, hi, 1, 3, 5, 7, 9, 11, 13, 15)); + src_ptr += 8; + src_ptr1 += 8; + dst_ptr += 8; + width -= 8; + } while (width > 0); +} +#endif // HAS_INTERPOLATEROW_16_WASMSIMD + +#ifdef HAS_J400TOARGBROW_WASMSIMD +static const uint8_t kShuffleJ400ToARGB[64] = { + 0, 0, 0, 128, 1, 1, 1, 128, 2, 2, 2, 128, 3, 3, 3, 128, + 4, 4, 4, 128, 5, 5, 5, 128, 6, 6, 6, 128, 7, 7, 7, 128, + 8, 8, 8, 128, 9, 9, 9, 128, 10, 10, 10, 128, 11, 11, 11, 128, + 12, 12, 12, 128, 13, 13, 13, 128, 14, 14, 14, 128, 15, 15, 15, 128}; +void J400ToARGBRow_WASMSIMD(const uint8_t* src_y, + uint8_t* dst_argb, + int width) { + v128_t shuf0 = LoadConst(kShuffleJ400ToARGB); + v128_t shuf1 = LoadConst(kShuffleJ400ToARGB + 16); + v128_t shuf2 = LoadConst(kShuffleJ400ToARGB + 32); + v128_t shuf3 = LoadConst(kShuffleJ400ToARGB + 48); + v128_t alpha = SplatConst32((int)0xff000000); + do { + asm("" : "+r"(dst_argb)); + v128_t y = wasm_v128_load(src_y); + wasm_v128_store(dst_argb, + wasm_v128_or(LIBYUV_WASM_SWIZZLE(y, shuf0), alpha)); + wasm_v128_store(dst_argb + 16, + wasm_v128_or(LIBYUV_WASM_SWIZZLE(y, shuf1), alpha)); + wasm_v128_store(dst_argb + 32, + wasm_v128_or(LIBYUV_WASM_SWIZZLE(y, shuf2), alpha)); + wasm_v128_store(dst_argb + 48, + wasm_v128_or(LIBYUV_WASM_SWIZZLE(y, shuf3), alpha)); + src_y += 16; + dst_argb += 64; + width -= 16; + } while (width > 0); +} +#endif // HAS_J400TOARGBROW_WASMSIMD + +#ifdef HAS_RGB565TOARGBROW_WASMSIMD +void RGB565ToARGBRow_WASMSIMD(const uint8_t* src_rgb565, + uint8_t* dst_argb, + int width) { + v128_t mask_b5 = SplatConst16(0x001f); + v128_t mask_g6 = SplatConst16(0x07e0); + v128_t mask_r5 = SplatConst16(0xf800); + v128_t mask_hi = SplatConst16(0xff00); + do { + asm("" : "+r"(dst_argb)); + v128_t p = wasm_v128_load(src_rgb565); + v128_t b5 = wasm_v128_and(p, mask_b5); + v128_t b8 = wasm_v128_or(wasm_i16x8_shl(b5, 3), wasm_u16x8_shr(b5, 2)); + v128_t g6 = wasm_v128_and(p, mask_g6); + v128_t g8_hi = wasm_v128_and( + wasm_v128_or(wasm_i16x8_shl(g6, 5), wasm_u16x8_shr(g6, 1)), mask_hi); + v128_t bg = wasm_v128_or(b8, g8_hi); + + v128_t r8 = wasm_v128_or(wasm_u16x8_shr(wasm_v128_and(p, mask_r5), 8), + wasm_u16x8_shr(p, 13)); + v128_t ra = wasm_v128_or(r8, mask_hi); + + v128_t d0 = wasm_i16x8_shuffle(bg, ra, 0, 8, 1, 9, 2, 10, 3, 11); + v128_t d1 = wasm_i16x8_shuffle(bg, ra, 4, 12, 5, 13, 6, 14, 7, 15); + wasm_v128_store(dst_argb, d0); + wasm_v128_store(dst_argb + 16, d1); + src_rgb565 += 16; + dst_argb += 32; + width -= 8; + } while (width > 0); +} +#endif // HAS_RGB565TOARGBROW_WASMSIMD + +#ifdef HAS_ARGB1555TOARGBROW_WASMSIMD +// 5 to 8 bit replication with multiplies: (v * 0x108) >> 5 == v << 3 | v >> 2. +void ARGB1555ToARGBRow_WASMSIMD(const uint8_t* src_argb1555, + uint8_t* dst_argb, + int width) { + v128_t mask_b5 = SplatConst16(0x001f); + v128_t mask_g5 = SplatConst16(0x03e0); + v128_t mask_hi = SplatConst16(0xff00); + v128_t mul_br = SplatConst16(0x0108); + v128_t mul_g = SplatConst16(0x0042); + do { + asm("" : "+r"(dst_argb)); + v128_t p = wasm_v128_load(src_argb1555); + v128_t b8 = + wasm_u16x8_shr(wasm_i16x8_mul(wasm_v128_and(p, mask_b5), mul_br), 5); + // g5 << 5 times 0x42 is g5 << 11 | g5 << 6; the high byte is g8. + v128_t g8_hi = wasm_v128_and( + wasm_i16x8_mul(wasm_v128_and(p, mask_g5), mul_g), mask_hi); + v128_t bg = wasm_v128_or(b8, g8_hi); + v128_t r5 = wasm_u16x8_shr(wasm_i16x8_shl(p, 1), 11); + v128_t r8 = wasm_u16x8_shr(wasm_i16x8_mul(r5, mul_br), 5); + v128_t a8_hi = wasm_v128_and(wasm_i16x8_shr(p, 15), mask_hi); + v128_t ra = wasm_v128_or(r8, a8_hi); + + v128_t d0 = wasm_i16x8_shuffle(bg, ra, 0, 8, 1, 9, 2, 10, 3, 11); + v128_t d1 = wasm_i16x8_shuffle(bg, ra, 4, 12, 5, 13, 6, 14, 7, 15); + wasm_v128_store(dst_argb, d0); + wasm_v128_store(dst_argb + 16, d1); + src_argb1555 += 16; + dst_argb += 32; + width -= 8; + } while (width > 0); +} +#endif // HAS_ARGB1555TOARGBROW_WASMSIMD + +#ifdef HAS_ARGB4444TOARGBROW_WASMSIMD +void ARGB4444ToARGBRow_WASMSIMD(const uint8_t* src_argb4444, + uint8_t* dst_argb, + int width) { + v128_t mask_lo = SplatConst8(0x0f); + v128_t mask_hi = SplatConst8(0xf0); + do { + asm("" : "+r"(dst_argb)); + v128_t v = wasm_v128_load(src_argb4444); + v128_t v_lo = wasm_v128_and(v, mask_lo); + v_lo = wasm_v128_or(v_lo, wasm_i16x8_shl(v_lo, 4)); + v128_t v_hi = wasm_v128_and(v, mask_hi); + v_hi = wasm_v128_or(v_hi, wasm_u16x8_shr(v_hi, 4)); + + v128_t d0 = wasm_i8x16_shuffle(v_lo, v_hi, 0, 16, 1, 17, 2, 18, 3, 19, 4, + 20, 5, 21, 6, 22, 7, 23); + v128_t d1 = wasm_i8x16_shuffle(v_lo, v_hi, 8, 24, 9, 25, 10, 26, 11, 27, 12, + 28, 13, 29, 14, 30, 15, 31); + wasm_v128_store(dst_argb, d0); + wasm_v128_store(dst_argb + 16, d1); + src_argb4444 += 16; + dst_argb += 32; + width -= 8; + } while (width > 0); +} +#endif // HAS_ARGB4444TOARGBROW_WASMSIMD + +#ifdef HAS_ARGBTORGB565DITHERROW_WASMSIMD +void ARGBToRGB565DitherRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_rgb, + uint32_t dither4, + int width) { + v128_t dither = wasm_i32x4_splat((int32_t)dither4); + dither = wasm_i8x16_shuffle(dither, dither, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, + 2, 3, 3, 3, 3); + v128_t mask_b = SplatConst32(0x0000001f); + v128_t mask_g = SplatConst32(0x000007e0); + v128_t mask_r = SplatConst32(0x0000f800); + do { + asm("" : "+r"(src_argb)); + v128_t s0 = wasm_u8x16_add_sat(wasm_v128_load(src_argb), dither); + v128_t s1 = wasm_u8x16_add_sat(wasm_v128_load(src_argb + 16), dither); + v128_t b0 = wasm_v128_and(wasm_u32x4_shr(s0, 3), mask_b); + v128_t g0 = wasm_v128_and(wasm_u32x4_shr(s0, 5), mask_g); + v128_t r0 = wasm_v128_and(wasm_u32x4_shr(s0, 8), mask_r); + v128_t b1 = wasm_v128_and(wasm_u32x4_shr(s1, 3), mask_b); + v128_t g1 = wasm_v128_and(wasm_u32x4_shr(s1, 5), mask_g); + v128_t r1 = wasm_v128_and(wasm_u32x4_shr(s1, 8), mask_r); + v128_t p0 = wasm_v128_or(wasm_v128_or(b0, g0), r0); + v128_t p1 = wasm_v128_or(wasm_v128_or(b1, g1), r1); + wasm_v128_store(dst_rgb, wasm_u16x8_narrow_i32x4(p0, p1)); + src_argb += 32; + dst_rgb += 16; + width -= 8; + } while (width > 0); +} +#endif // HAS_ARGBTORGB565DITHERROW_WASMSIMD + +#ifdef HAS_ARGBTORGB565ROW_WASMSIMD +void ARGBToRGB565Row_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width) { + v128_t mask_b = SplatConst32(0x0000001f); + v128_t mask_g = SplatConst32(0x000007e0); + v128_t mask_r = SplatConst32(0x0000f800); + do { + asm("" : "+r"(src_argb)); + v128_t s0 = wasm_v128_load(src_argb); + v128_t s1 = wasm_v128_load(src_argb + 16); + v128_t b0 = wasm_v128_and(wasm_u32x4_shr(s0, 3), mask_b); + v128_t g0 = wasm_v128_and(wasm_u32x4_shr(s0, 5), mask_g); + v128_t r0 = wasm_v128_and(wasm_u32x4_shr(s0, 8), mask_r); + v128_t b1 = wasm_v128_and(wasm_u32x4_shr(s1, 3), mask_b); + v128_t g1 = wasm_v128_and(wasm_u32x4_shr(s1, 5), mask_g); + v128_t r1 = wasm_v128_and(wasm_u32x4_shr(s1, 8), mask_r); + v128_t p0 = wasm_v128_or(wasm_v128_or(b0, g0), r0); + v128_t p1 = wasm_v128_or(wasm_v128_or(b1, g1), r1); + wasm_v128_store(dst_rgb, wasm_u16x8_narrow_i32x4(p0, p1)); + src_argb += 32; + dst_rgb += 16; + width -= 8; + } while (width > 0); +} +#endif // HAS_ARGBTORGB565ROW_WASMSIMD + +#ifdef HAS_ARGBTOARGB1555ROW_WASMSIMD +void ARGBToARGB1555Row_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_argb1555, + int width) { + v128_t mask_b = SplatConst32(0x0000001f); + v128_t mask_g = SplatConst32(0x000003e0); + v128_t mask_r = SplatConst32(0x00007c00); + v128_t mask_a = SplatConst32(0x00008000); + do { + asm("" : "+r"(src_argb)); + v128_t s0 = wasm_v128_load(src_argb); + v128_t s1 = wasm_v128_load(src_argb + 16); + v128_t b0 = wasm_v128_and(wasm_u32x4_shr(s0, 3), mask_b); + v128_t g0 = wasm_v128_and(wasm_u32x4_shr(s0, 6), mask_g); + v128_t r0 = wasm_v128_and(wasm_u32x4_shr(s0, 9), mask_r); + v128_t a0 = wasm_v128_and(wasm_u32x4_shr(s0, 16), mask_a); + v128_t b1 = wasm_v128_and(wasm_u32x4_shr(s1, 3), mask_b); + v128_t g1 = wasm_v128_and(wasm_u32x4_shr(s1, 6), mask_g); + v128_t r1 = wasm_v128_and(wasm_u32x4_shr(s1, 9), mask_r); + v128_t a1 = wasm_v128_and(wasm_u32x4_shr(s1, 16), mask_a); + v128_t p0 = wasm_v128_or(wasm_v128_or(b0, g0), wasm_v128_or(r0, a0)); + v128_t p1 = wasm_v128_or(wasm_v128_or(b1, g1), wasm_v128_or(r1, a1)); + wasm_v128_store(dst_argb1555, wasm_u16x8_narrow_i32x4(p0, p1)); + src_argb += 32; + dst_argb1555 += 16; + width -= 8; + } while (width > 0); +} +#endif // HAS_ARGBTOARGB1555ROW_WASMSIMD + +#ifdef HAS_ARGBTOARGB4444ROW_WASMSIMD +void ARGBToARGB4444Row_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_argb4444, + int width) { + v128_t mask_lo = SplatConst16(0x000f); + v128_t mask_hi = SplatConst16(0x00f0); + do { + asm("" : "+r"(src_argb)); + v128_t s0 = wasm_v128_load(src_argb); + v128_t s1 = wasm_v128_load(src_argb + 16); + v128_t n0 = wasm_v128_or(wasm_v128_and(wasm_u16x8_shr(s0, 4), mask_lo), + wasm_v128_and(wasm_u16x8_shr(s0, 8), mask_hi)); + v128_t n1 = wasm_v128_or(wasm_v128_and(wasm_u16x8_shr(s1, 4), mask_lo), + wasm_v128_and(wasm_u16x8_shr(s1, 8), mask_hi)); + wasm_v128_store(dst_argb4444, wasm_u8x16_narrow_i16x8(n0, n1)); + src_argb += 32; + dst_argb4444 += 16; + width -= 8; + } while (width > 0); +} +#endif // HAS_ARGBTOARGB4444ROW_WASMSIMD + +#ifdef HAS_ARGBSHUFFLEROW_WASMSIMD +void ARGBShuffleRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_argb, + const uint8_t* shuffler, + int width) { + v128_t shuf = wasm_v128_load(shuffler); + while (width >= 8) { + asm("" : "+r"(src_argb), "+r"(dst_argb)); + v128_t s0 = wasm_v128_load(src_argb); + v128_t s1 = wasm_v128_load(src_argb + 16); + wasm_v128_store(dst_argb, LIBYUV_WASM_SWIZZLE(s0, shuf)); + wasm_v128_store(dst_argb + 16, LIBYUV_WASM_SWIZZLE(s1, shuf)); + src_argb += 32; + dst_argb += 32; + width -= 8; + } + if (width > 0) { + v128_t s0 = wasm_v128_load(src_argb); + wasm_v128_store(dst_argb, LIBYUV_WASM_SWIZZLE(s0, shuf)); + } +} +#endif // HAS_ARGBSHUFFLEROW_WASMSIMD + +#if defined(HAS_I422TOARGBROW_WASMSIMD) || \ + defined(HAS_I422TOAR30ROW_WASMSIMD) || \ + defined(HAS_NV12TOARGBROW_WASMSIMD) || \ + defined(HAS_NV21TOARGBROW_WASMSIMD) || \ + defined(HAS_I422TORGB24ROW_WASMSIMD) || \ + defined(HAS_I422TORGB565ROW_WASMSIMD) || \ + defined(HAS_I422TOARGB1555ROW_WASMSIMD) || \ + defined(HAS_I422TOARGB4444ROW_WASMSIMD) || \ + defined(HAS_NV12TORGB565ROW_WASMSIMD) +// Interleaves map to punpck on x64 and zip on arm64 when the two inputs +// differ. V8 arm64 lowers shuffle(x, x) to tbl with a rebuilt mask. +static __inline v128_t ZipLo8_WASMSIMD(v128_t a, v128_t b) { + return wasm_i8x16_shuffle(a, b, 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, + 22, 7, 23); +} +static __inline v128_t ZipHi8_WASMSIMD(v128_t a, v128_t b) { + return wasm_i8x16_shuffle(a, b, 8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, + 14, 30, 15, 31); +} + +// YuvConstants splatted to 16-bit lanes, built once per row. +struct YuvCoefs_WASMSIMD { + v128_t ub, ug, vg, vr, yg, yb, x80, k00ff, k0101; +}; + +static __inline void LoadYuvCoefs_WASMSIMD(const struct YuvConstants* yc, + int yb_adjust, + struct YuvCoefs_WASMSIMD* c) { + c->ub = wasm_i16x8_splat(yc->kUVToB[0]); + c->ug = wasm_i16x8_splat(yc->kUVToG[0]); + c->vg = wasm_i16x8_splat(yc->kUVToG[1]); + c->vr = wasm_i16x8_splat(yc->kUVToR[1]); + c->yg = wasm_i16x8_splat(yc->kYToRgb[0]); + c->yb = wasm_i16x8_splat(yc->kYBiasToRgb[0] - yb_adjust); + c->x80 = SplatConst8(0x80); + c->k00ff = SplatConst16(0x00ff); + c->k0101 = SplatConst16(0x0101); +} + +// Returns ((y * 0x0101 * yg) >> 16) + yb for 8 Y in 16-bit lanes. +static __inline v128_t YToRgb_WASMSIMD(v128_t y, + const struct YuvCoefs_WASMSIMD* c) { + // The barrier keeps clang from widening yg outside the loop, which would + // turn extmul (umull on arm64) into extend + i32x4.mul. + v128_t yg = c->yg; + asm volatile("" : "+r"(yg)); + v128_t y16 = wasm_i16x8_mul(y, c->k0101); + v128_t lo = wasm_u32x4_extmul_low_u16x8(y16, yg); + v128_t hi = wasm_u32x4_extmul_high_u16x8(y16, yg); + return wasm_i16x8_add(wasm_i16x8_shuffle(lo, hi, 1, 3, 5, 7, 9, 11, 13, 15), + c->yb); +} + +// Converts 16 pixels to B, G, R with 6 fractional bits (unclamped int16). +// y = 16 Y. uv = 8 U/V pairs, U in the low byte of each 16-bit lane (V if vu). +// Even and odd pixels are kept apart so each pair shares its chroma terms: +// rgb[0], rgb[2], rgb[4] = even B, G, R and rgb[1], rgb[3], rgb[5] = odd. +static __inline void YuvToRgb16_WASMSIMD(v128_t y, + v128_t uv, + int vu, + const struct YuvCoefs_WASMSIMD* c, + v128_t* rgb) { + v128_t ye = YToRgb_WASMSIMD(wasm_v128_and(y, c->k00ff), c); + v128_t yo = YToRgb_WASMSIMD(wasm_u16x8_shr(y, 8), c); + // u - 128 and v - 128 as int8, sign extended to int16. + v128_t uvs = wasm_v128_xor(uv, c->x80); + v128_t lo = wasm_i16x8_shr(wasm_i16x8_shl(uvs, 8), 8); + v128_t hi = wasm_i16x8_shr(uvs, 8); + v128_t ui = vu ? hi : lo; + v128_t vi = vu ? lo : hi; + v128_t b = wasm_i16x8_mul(ui, c->ub); + v128_t g = + wasm_i16x8_add(wasm_i16x8_mul(ui, c->ug), wasm_i16x8_mul(vi, c->vg)); + v128_t r = wasm_i16x8_mul(vi, c->vr); + rgb[0] = wasm_i16x8_add_sat(ye, b); + rgb[1] = wasm_i16x8_add_sat(yo, b); + rgb[2] = wasm_i16x8_sub_sat(ye, g); + rgb[3] = wasm_i16x8_sub_sat(yo, g); + rgb[4] = wasm_i16x8_add_sat(ye, r); + rgb[5] = wasm_i16x8_add_sat(yo, r); +} + +// Loads 16 Y and 8 U/V, or 8 Y and 4 U/V when width < 16. +static __inline void ReadI422_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + int width, + v128_t* y, + v128_t* uv) { + if (width >= 16) { + *y = wasm_v128_load(src_y); + *uv = ZipLo8_WASMSIMD(wasm_v128_load64_zero(src_u), + wasm_v128_load64_zero(src_v)); + } else { + *y = wasm_v128_load64_zero(src_y); + *uv = ZipLo8_WASMSIMD(wasm_v128_load32_zero(src_u), + wasm_v128_load32_zero(src_v)); + } +} + +// Loads 16 Y and 8 UV pairs, or 8 Y and 4 UV pairs when width < 16. +static __inline void ReadNV12_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_uv, + int width, + v128_t* y, + v128_t* uv) { + if (width >= 16) { + *y = wasm_v128_load(src_y); + *uv = wasm_v128_load(src_uv); + } else { + *y = wasm_v128_load64_zero(src_y); + *uv = wasm_v128_load64_zero(src_uv); + } +} +#endif + +#if defined(HAS_I422TOARGBROW_WASMSIMD) || \ + defined(HAS_NV12TOARGBROW_WASMSIMD) || defined(HAS_NV21TOARGBROW_WASMSIMD) +// Clamps even/odd B, G, R to 8 bits and stores 16 ARGB pixels, or 8 when +// width < 16. +static __inline void StoreARGB_WASMSIMD(const v128_t* rgb, + v128_t ff, + uint8_t* dst_argb, + int width) { + v128_t bg_e = wasm_u8x16_narrow_i16x8(wasm_i16x8_shr(rgb[0], 6), + wasm_i16x8_shr(rgb[2], 6)); + v128_t gb_o = wasm_u8x16_narrow_i16x8(wasm_i16x8_shr(rgb[3], 6), + wasm_i16x8_shr(rgb[1], 6)); + v128_t rr = wasm_u8x16_narrow_i16x8(wasm_i16x8_shr(rgb[4], 6), + wasm_i16x8_shr(rgb[5], 6)); + v128_t br_e = ZipLo8_WASMSIMD(bg_e, rr); + v128_t ga_e = ZipHi8_WASMSIMD(bg_e, ff); + v128_t br_o = ZipHi8_WASMSIMD(gb_o, rr); + v128_t ga_o = ZipLo8_WASMSIMD(gb_o, ff); + v128_t e = ZipLo8_WASMSIMD(br_e, ga_e); // Pixels 0, 2, 4, 6. + v128_t o = ZipLo8_WASMSIMD(br_o, ga_o); // Pixels 1, 3, 5, 7. + wasm_v128_store(dst_argb, wasm_i32x4_shuffle(e, o, 0, 4, 1, 5)); + wasm_v128_store(dst_argb + 16, wasm_i32x4_shuffle(e, o, 2, 6, 3, 7)); + if (width >= 16) { + e = ZipHi8_WASMSIMD(br_e, ga_e); + o = ZipHi8_WASMSIMD(br_o, ga_o); + wasm_v128_store(dst_argb + 32, wasm_i32x4_shuffle(e, o, 0, 4, 1, 5)); + wasm_v128_store(dst_argb + 48, wasm_i32x4_shuffle(e, o, 2, 6, 3, 7)); + } +} +#endif + +#ifdef HAS_I422TOARGBROW_WASMSIMD +void I422ToARGBRow_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + struct YuvCoefs_WASMSIMD c; + v128_t ff = SplatConst8(0xff); + LoadYuvCoefs_WASMSIMD(yuvconstants, 0, &c); + do { + v128_t y, uv, rgb[6]; + ReadI422_WASMSIMD(src_y, src_u, src_v, width, &y, &uv); + YuvToRgb16_WASMSIMD(y, uv, 0, &c, rgb); + StoreARGB_WASMSIMD(rgb, ff, dst_argb, width); + src_y += 16; + src_u += 8; + src_v += 8; + dst_argb += 64; + width -= 16; + } while (width > 0); +} +#endif // HAS_I422TOARGBROW_WASMSIMD + +#ifdef HAS_I422TOAR30ROW_WASMSIMD +// Clamps B, G, R with 6 fractional bits to 10 bits and packs them into the +// low and high 16 bits of AR30, without the alpha bits. +static __inline void RgbToAR30_WASMSIMD(v128_t b, + v128_t g, + v128_t r, + v128_t zero, + v128_t k3ff0, + v128_t* lo, + v128_t* hi) { + b = wasm_i16x8_max(wasm_i16x8_min(b, k3ff0), zero); + g = wasm_i16x8_max(wasm_i16x8_min(g, k3ff0), zero); + r = wasm_i16x8_max(wasm_i16x8_min(r, k3ff0), zero); + *lo = wasm_v128_or(wasm_u16x8_shr(b, 4), + wasm_i16x8_shl(wasm_v128_and(g, k3ff0), 6)); + *hi = wasm_v128_or(wasm_v128_and(r, k3ff0), wasm_u16x8_shr(g, 10)); +} + +void I422ToAR30Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + struct YuvCoefs_WASMSIMD c; + v128_t zero = SplatConst16(0); + v128_t k3ff0 = SplatConst16(0x3ff0); + v128_t kc000 = SplatConst16(0xc000); + LoadYuvCoefs_WASMSIMD(yuvconstants, 24, &c); // AR30 bias. + do { + v128_t y, uv, rgb[6], lo_e, hi_e, lo_o, hi_o; + ReadI422_WASMSIMD(src_y, src_u, src_v, width, &y, &uv); + YuvToRgb16_WASMSIMD(y, uv, 0, &c, rgb); + RgbToAR30_WASMSIMD(rgb[0], rgb[2], rgb[4], zero, k3ff0, &lo_e, &hi_e); + RgbToAR30_WASMSIMD(rgb[1], rgb[3], rgb[5], zero, k3ff0, &lo_o, &hi_o); + hi_e = wasm_v128_or(hi_e, kc000); + hi_o = wasm_v128_or(hi_o, kc000); + // Even pixels 0, 2, 4, 6 and odd pixels 1, 3, 5, 7 as 32 bits. + v128_t e = wasm_i16x8_shuffle(lo_e, hi_e, 0, 8, 1, 9, 2, 10, 3, 11); + v128_t o = wasm_i16x8_shuffle(lo_o, hi_o, 0, 8, 1, 9, 2, 10, 3, 11); + wasm_v128_store(dst_ar30, wasm_i32x4_shuffle(e, o, 0, 4, 1, 5)); + wasm_v128_store(dst_ar30 + 16, wasm_i32x4_shuffle(e, o, 2, 6, 3, 7)); + if (width >= 16) { + e = wasm_i16x8_shuffle(lo_e, hi_e, 4, 12, 5, 13, 6, 14, 7, 15); + o = wasm_i16x8_shuffle(lo_o, hi_o, 4, 12, 5, 13, 6, 14, 7, 15); + wasm_v128_store(dst_ar30 + 32, wasm_i32x4_shuffle(e, o, 0, 4, 1, 5)); + wasm_v128_store(dst_ar30 + 48, wasm_i32x4_shuffle(e, o, 2, 6, 3, 7)); + } + src_y += 16; + src_u += 8; + src_v += 8; + dst_ar30 += 64; + width -= 16; + } while (width > 0); +} +#endif // HAS_I422TOAR30ROW_WASMSIMD + +#ifdef HAS_NV12TOARGBROW_WASMSIMD +void NV12ToARGBRow_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + struct YuvCoefs_WASMSIMD c; + v128_t ff = SplatConst8(0xff); + LoadYuvCoefs_WASMSIMD(yuvconstants, 0, &c); + do { + v128_t y, uv, rgb[6]; + ReadNV12_WASMSIMD(src_y, src_uv, width, &y, &uv); + YuvToRgb16_WASMSIMD(y, uv, 0, &c, rgb); + StoreARGB_WASMSIMD(rgb, ff, dst_argb, width); + src_y += 16; + src_uv += 16; + dst_argb += 64; + width -= 16; + } while (width > 0); +} +#endif // HAS_NV12TOARGBROW_WASMSIMD + +#ifdef HAS_NV21TOARGBROW_WASMSIMD +void NV21ToARGBRow_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + struct YuvCoefs_WASMSIMD c; + v128_t ff = SplatConst8(0xff); + LoadYuvCoefs_WASMSIMD(yuvconstants, 0, &c); + do { + v128_t y, vu, rgb[6]; + ReadNV12_WASMSIMD(src_y, src_vu, width, &y, &vu); + YuvToRgb16_WASMSIMD(y, vu, 1, &c, rgb); + StoreARGB_WASMSIMD(rgb, ff, dst_argb, width); + src_y += 16; + src_vu += 16; + dst_argb += 64; + width -= 16; + } while (width > 0); +} +#endif // HAS_NV21TOARGBROW_WASMSIMD + +#ifdef HAS_I422TORGB24ROW_WASMSIMD +// Swizzles that interleave B/G pairs and R into 3 vectors of RGB24. R is +// 8 even pixels followed by 8 odd pixels. +static const uint8_t kI422ToRGB24Swizzle[96] = { + 0, 1, 128, 2, 3, 128, 4, 5, 128, 6, 7, 128, 8, 9, + 128, 10, 128, 128, 0, 128, 128, 8, 128, 128, 1, 128, 128, 9, + 128, 128, 2, 128, 3, 128, 4, 5, 128, 6, 7, 128, 8, 9, + 128, 10, 11, 128, 12, 13, 128, 10, 128, 128, 3, 128, 128, 11, + 128, 128, 4, 128, 128, 12, 128, 128, 128, 6, 7, 128, 8, 9, + 128, 10, 11, 128, 12, 13, 128, 14, 15, 128, 5, 128, 128, 13, + 128, 128, 6, 128, 128, 14, 128, 128, 7, 128, 128, 15}; + +void I422ToRGB24Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + struct YuvCoefs_WASMSIMD c; + v128_t m0 = LoadConst(kI422ToRGB24Swizzle); + v128_t m1 = LoadConst(kI422ToRGB24Swizzle + 16); + v128_t m2 = LoadConst(kI422ToRGB24Swizzle + 32); + v128_t m3 = LoadConst(kI422ToRGB24Swizzle + 48); + v128_t m4 = LoadConst(kI422ToRGB24Swizzle + 64); + v128_t m5 = LoadConst(kI422ToRGB24Swizzle + 80); + LoadYuvCoefs_WASMSIMD(yuvconstants, 0, &c); + do { + v128_t y, uv, rgb[6]; + ReadI422_WASMSIMD(src_y, src_u, src_v, 16, &y, &uv); + YuvToRgb16_WASMSIMD(y, uv, 0, &c, rgb); + v128_t bg_e = wasm_u8x16_narrow_i16x8(wasm_i16x8_shr(rgb[0], 6), + wasm_i16x8_shr(rgb[2], 6)); + v128_t bg_o = wasm_u8x16_narrow_i16x8(wasm_i16x8_shr(rgb[1], 6), + wasm_i16x8_shr(rgb[3], 6)); + v128_t r = wasm_u8x16_narrow_i16x8(wasm_i16x8_shr(rgb[4], 6), + wasm_i16x8_shr(rgb[5], 6)); + v128_t b = ZipLo8_WASMSIMD(bg_e, bg_o); + v128_t g = ZipHi8_WASMSIMD(bg_e, bg_o); + v128_t bg0 = ZipLo8_WASMSIMD(b, g); + v128_t bg2 = ZipHi8_WASMSIMD(b, g); + v128_t bg1 = wasm_i8x16_shuffle(bg0, bg2, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23); + wasm_v128_store(dst_rgb24, wasm_v128_or(LIBYUV_WASM_SWIZZLE(bg0, m0), + LIBYUV_WASM_SWIZZLE(r, m1))); + wasm_v128_store(dst_rgb24 + 16, wasm_v128_or(LIBYUV_WASM_SWIZZLE(bg1, m2), + LIBYUV_WASM_SWIZZLE(r, m3))); + wasm_v128_store(dst_rgb24 + 32, wasm_v128_or(LIBYUV_WASM_SWIZZLE(bg2, m4), + LIBYUV_WASM_SWIZZLE(r, m5))); + src_y += 16; + src_u += 8; + src_v += 8; + dst_rgb24 += 48; + width -= 16; + } while (width > 0); +} +#endif // HAS_I422TORGB24ROW_WASMSIMD + +#if defined(HAS_I422TORGB565ROW_WASMSIMD) || \ + defined(HAS_I422TOARGB1555ROW_WASMSIMD) || \ + defined(HAS_I422TOARGB4444ROW_WASMSIMD) || \ + defined(HAS_NV12TORGB565ROW_WASMSIMD) +// Clamps x with 6 fractional bits to 8 bits, keeps the top 'bits' and moves +// them to bit 'pos'. +static __inline v128_t PackChannel_WASMSIMD(v128_t x, + v128_t zero, + v128_t k3fff, + int bits, + int pos) { + x = wasm_i16x8_max(wasm_i16x8_min(x, k3fff), zero); + return wasm_i16x8_shl(wasm_u16x8_shr(x, 14 - bits), pos); +} + +// Packs even/odd B, G, R into 16 bit pixels with the given channel sizes and +// stores 16 pixels, or 8 when width < 16. k = {0, 0x3fff, alpha} in 16-bit +// lanes. Alpha is set if the channels use fewer than 16 bits. +static __inline void Store16Bit_WASMSIMD(const v128_t* rgb, + int bbits, + int gbits, + int rbits, + const v128_t* k, + uint8_t* dst, + int width) { + v128_t p[2]; + int i; + for (i = 0; i < 2; ++i) { + p[i] = wasm_v128_or( + PackChannel_WASMSIMD(rgb[i], k[0], k[1], bbits, 0), + wasm_v128_or(PackChannel_WASMSIMD(rgb[2 + i], k[0], k[1], gbits, bbits), + PackChannel_WASMSIMD(rgb[4 + i], k[0], k[1], rbits, + bbits + gbits))); + if (bbits + gbits + rbits < 16) { + p[i] = wasm_v128_or(p[i], k[2]); + } + } + wasm_v128_store(dst, + wasm_i16x8_shuffle(p[0], p[1], 0, 8, 1, 9, 2, 10, 3, 11)); + if (width >= 16) { + wasm_v128_store(dst + 16, + wasm_i16x8_shuffle(p[0], p[1], 4, 12, 5, 13, 6, 14, 7, 15)); + } +} +#endif + +#ifdef HAS_I422TORGB565ROW_WASMSIMD +void I422ToRGB565Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width) { + struct YuvCoefs_WASMSIMD c; + v128_t k[2] = {SplatConst16(0), SplatConst16(0x3fff)}; + LoadYuvCoefs_WASMSIMD(yuvconstants, 0, &c); + do { + v128_t y, uv, rgb[6]; + ReadI422_WASMSIMD(src_y, src_u, src_v, width, &y, &uv); + YuvToRgb16_WASMSIMD(y, uv, 0, &c, rgb); + Store16Bit_WASMSIMD(rgb, 5, 6, 5, k, dst_rgb565, width); + src_y += 16; + src_u += 8; + src_v += 8; + dst_rgb565 += 32; + width -= 16; + } while (width > 0); +} +#endif // HAS_I422TORGB565ROW_WASMSIMD + +#ifdef HAS_I422TOARGB1555ROW_WASMSIMD +void I422ToARGB1555Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb1555, + const struct YuvConstants* yuvconstants, + int width) { + struct YuvCoefs_WASMSIMD c; + v128_t k[3] = {SplatConst16(0), SplatConst16(0x3fff), SplatConst16(0x8000)}; + LoadYuvCoefs_WASMSIMD(yuvconstants, 0, &c); + do { + v128_t y, uv, rgb[6]; + ReadI422_WASMSIMD(src_y, src_u, src_v, width, &y, &uv); + YuvToRgb16_WASMSIMD(y, uv, 0, &c, rgb); + Store16Bit_WASMSIMD(rgb, 5, 5, 5, k, dst_argb1555, width); + src_y += 16; + src_u += 8; + src_v += 8; + dst_argb1555 += 32; + width -= 16; + } while (width > 0); +} +#endif // HAS_I422TOARGB1555ROW_WASMSIMD + +#ifdef HAS_I422TOARGB4444ROW_WASMSIMD +void I422ToARGB4444Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb4444, + const struct YuvConstants* yuvconstants, + int width) { + struct YuvCoefs_WASMSIMD c; + v128_t k[3] = {SplatConst16(0), SplatConst16(0x3fff), SplatConst16(0xf000)}; + LoadYuvCoefs_WASMSIMD(yuvconstants, 0, &c); + do { + v128_t y, uv, rgb[6]; + ReadI422_WASMSIMD(src_y, src_u, src_v, width, &y, &uv); + YuvToRgb16_WASMSIMD(y, uv, 0, &c, rgb); + Store16Bit_WASMSIMD(rgb, 4, 4, 4, k, dst_argb4444, width); + src_y += 16; + src_u += 8; + src_v += 8; + dst_argb4444 += 32; + width -= 16; + } while (width > 0); +} +#endif // HAS_I422TOARGB4444ROW_WASMSIMD + +#ifdef HAS_NV12TORGB565ROW_WASMSIMD +void NV12ToRGB565Row_WASMSIMD(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_rgb565, + const struct YuvConstants* yuvconstants, + int width) { + struct YuvCoefs_WASMSIMD c; + v128_t k[2] = {SplatConst16(0), SplatConst16(0x3fff)}; + LoadYuvCoefs_WASMSIMD(yuvconstants, 0, &c); + do { + v128_t y, uv, rgb[6]; + ReadNV12_WASMSIMD(src_y, src_uv, width, &y, &uv); + YuvToRgb16_WASMSIMD(y, uv, 0, &c, rgb); + Store16Bit_WASMSIMD(rgb, 5, 6, 5, k, dst_rgb565, width); + src_y += 16; + src_uv += 16; + dst_rgb565 += 32; + width -= 16; + } while (width > 0); +} +#endif // HAS_NV12TORGB565ROW_WASMSIMD + +#ifdef HAS_ARGBBLENDROW_WASMSIMD +// Broadcast 255 - alpha (from byte 3 of each pixel) to 16 bit lanes. +static const uint8_t kShuffleAlpha16[16] = {3, 128, 3, 128, 7, 128, 7, 128, + 11, 128, 11, 128, 15, 128, 15, 128}; +void ARGBBlendRow_WASMSIMD(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + v128_t shuf_a = LoadConst(kShuffleAlpha16); + v128_t one = SplatConst16(1); + v128_t mask_lo = SplatConst16(0x00ff); + v128_t mask_alpha = SplatConst32((int)0xff000000); + + while (width >= 4) { + v128_t s0 = wasm_v128_load(src_argb); + v128_t s1 = wasm_v128_load(src_argb1); + src_argb += 16; + src_argb1 += 16; + + // a = 256 - alpha. + v128_t a = wasm_i16x8_add( + LIBYUV_WASM_SWIZZLE(wasm_v128_xor(s0, mask_alpha), shuf_a), one); + v128_t s1_lo = + wasm_u16x8_shr(wasm_i16x8_mul(wasm_v128_and(s1, mask_lo), a), 8); + v128_t s1_hi = + wasm_v128_andnot(wasm_i16x8_mul(wasm_u16x8_shr(s1, 8), a), mask_lo); + + v128_t res = wasm_v128_or(s0, mask_alpha); + res = wasm_u8x16_add_sat(res, s1_lo); + res = wasm_u8x16_add_sat(res, s1_hi); + + wasm_v128_store(dst_argb, res); + dst_argb += 16; + width -= 4; + } + + while (width > 0) { + uint32_t s0 = *(const uint32_t*)src_argb; + uint32_t s1 = *(const uint32_t*)src_argb1; + src_argb += 4; + src_argb1 += 4; + + uint32_t a = 256 - (s0 >> 24); + uint32_t b = (((s1 & 0x000000ff) * a) >> 8) + (s0 & 0x000000ff); + uint32_t g = (((s1 & 0x0000ff00) * a) >> 8) + (s0 & 0x0000ff00); + uint32_t r = (((s1 & 0x00ff0000) >> 8) * a) + (s0 & 0x00ff0000); + + b = (b > 255) ? 255 : b; + g = (g > 0xff00) ? 0xff00 : (g & 0xff00); + r = (r > 0x00ff0000) ? 0x00ff0000 : (r & 0x00ff0000); + + *(uint32_t*)dst_argb = 0xff000000u | r | g | b; + dst_argb += 4; + --width; + } +} +#endif // HAS_ARGBBLENDROW_WASMSIMD + +#ifdef HAS_BLENDPLANEROW_WASMSIMD +void BlendPlaneRow_WASMSIMD(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width) { + // src0 * a + src1 * (255 - a) + 255 fits in 16 bits. 255 - a is a ^ 255. + // The high bytes are the result (uzp2 on Arm). + v128_t c255 = SplatConst16(255); + v128_t ff = SplatConst8(255); + do { + v128_t s0 = wasm_v128_load(src0); + v128_t s1 = wasm_v128_load(src1); + v128_t a = wasm_v128_load(alpha); + v128_t ia = wasm_v128_xor(a, ff); + src0 += 16; + src1 += 16; + alpha += 16; + v128_t lo = wasm_i16x8_add(wasm_u16x8_extmul_low_u8x16(s0, a), + wasm_u16x8_extmul_low_u8x16(s1, ia)); + v128_t hi = wasm_i16x8_add(wasm_u16x8_extmul_high_u8x16(s0, a), + wasm_u16x8_extmul_high_u8x16(s1, ia)); + lo = wasm_i16x8_add(lo, c255); + hi = wasm_i16x8_add(hi, c255); + wasm_v128_store(dst, wasm_i8x16_shuffle(lo, hi, 1, 3, 5, 7, 9, 11, 13, 15, + 17, 19, 21, 23, 25, 27, 29, 31)); + dst += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_BLENDPLANEROW_WASMSIMD + +#ifdef HAS_ARGBEXTRACTALPHAROW_WASMSIMD +void ARGBExtractAlphaRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_a, + int width) { + do { + asm("" : "+r"(src_argb), "+r"(dst_a)); + v128_t s0 = wasm_v128_load(src_argb); + v128_t s1 = wasm_v128_load(src_argb + 16); + v128_t s2 = wasm_v128_load(src_argb + 32); + v128_t s3 = wasm_v128_load(src_argb + 48); + s0 = wasm_u32x4_shr(s0, 24); + s1 = wasm_u32x4_shr(s1, 24); + s2 = wasm_u32x4_shr(s2, 24); + s3 = wasm_u32x4_shr(s3, 24); + v128_t a = wasm_u8x16_narrow_i16x8(wasm_i16x8_narrow_i32x4(s0, s1), + wasm_i16x8_narrow_i32x4(s2, s3)); + wasm_v128_store(dst_a, a); + src_argb += 64; + dst_a += 16; + width -= 16; + } while (width > 0); +} +#endif // HAS_ARGBEXTRACTALPHAROW_WASMSIMD + +#ifdef HAS_ARGBCOPYYTOALPHAROW_WASMSIMD +// Swizzle Y[i] to the alpha byte of 32 bit lane i; 128 indices give 0. +static const uint8_t kYToAlphaSwizzleTable[64] = { + 128, 128, 128, 0, 128, 128, 128, 1, 128, 128, 128, 2, 128, 128, 128, 3, + 128, 128, 128, 4, 128, 128, 128, 5, 128, 128, 128, 6, 128, 128, 128, 7, + 128, 128, 128, 8, 128, 128, 128, 9, 128, 128, 128, 10, 128, 128, 128, 11, + 128, 128, 128, 12, 128, 128, 128, 13, 128, 128, 128, 14, 128, 128, 128, 15}; + +void ARGBCopyYToAlphaRow_WASMSIMD(const uint8_t* src, uint8_t* dst, int width) { + v128_t rgb_mask = SplatConst32(0x00ffffff); + v128_t idx0 = LoadConst(kYToAlphaSwizzleTable); + v128_t idx1 = LoadConst(kYToAlphaSwizzleTable + 16); + v128_t idx2 = LoadConst(kYToAlphaSwizzleTable + 32); + v128_t idx3 = LoadConst(kYToAlphaSwizzleTable + 48); + do { + asm("" : "+r"(src), "+r"(dst)); + v128_t y = wasm_v128_load(src); + v128_t d0 = wasm_v128_and(wasm_v128_load(dst), rgb_mask); + v128_t d1 = wasm_v128_and(wasm_v128_load(dst + 16), rgb_mask); + v128_t d2 = wasm_v128_and(wasm_v128_load(dst + 32), rgb_mask); + v128_t d3 = wasm_v128_and(wasm_v128_load(dst + 48), rgb_mask); + wasm_v128_store(dst, wasm_v128_or(d0, LIBYUV_WASM_SWIZZLE(y, idx0))); + wasm_v128_store(dst + 16, wasm_v128_or(d1, LIBYUV_WASM_SWIZZLE(y, idx1))); + wasm_v128_store(dst + 32, wasm_v128_or(d2, LIBYUV_WASM_SWIZZLE(y, idx2))); + wasm_v128_store(dst + 48, wasm_v128_or(d3, LIBYUV_WASM_SWIZZLE(y, idx3))); + src += 16; + dst += 64; + width -= 16; + } while (width > 0); +} +#endif // HAS_ARGBCOPYYTOALPHAROW_WASMSIMD + +#ifdef HAS_ARGBORROW_WASMSIMD +void ARGBOrRow_WASMSIMD(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + v128_t val = wasm_i32x4_splat((int32_t)value); + do { + asm("" : "+r"(src_argb), "+r"(dst_argb)); + v128_t s = wasm_v128_load(src_argb); + wasm_v128_store(dst_argb, wasm_v128_or(s, val)); + src_argb += 16; + dst_argb += 16; + width -= 4; + } while (width > 0); +} +#endif // HAS_ARGBORROW_WASMSIMD + +#ifdef HAS_ARGBALPHABLENDROW_WASMSIMD +void ARGBAlphaBlendRow_WASMSIMD(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + v128_t c1 = SplatConst16(1); + v128_t c00ffffff = SplatConst32(0x00ffffff); + do { + asm("" : "+r"(src_argb0), "+r"(src_argb1), "+r"(dst_argb)); + v128_t s = wasm_v128_load(src_argb0); + v128_t d = wasm_v128_load(src_argb1); + src_argb0 += 16; + src_argb1 += 16; + v128_t sa = wasm_u32x4_shr(s, 24); + v128_t da = wasm_u32x4_shr(d, 24); + v128_t prod16 = wasm_i16x8_add(wasm_i16x8_mul(da, sa), c1); + v128_t da_sa = + wasm_u16x8_shr(wasm_i16x8_add(prod16, wasm_u16x8_shr(prod16, 8)), 8); + v128_t da2 = wasm_i32x4_add(da, wasm_i32x4_sub(sa, da_sa)); + v128_t t = wasm_u32x4_shr(wasm_i32x4_eq(da, wasm_i32x4_const_splat(0)), 24); + v128_t sa_eff = wasm_v128_or(sa, t); + v128_t den_eff = wasm_v128_or(da2, t); + v128_t num = wasm_i32x4_sub(wasm_i32x4_shl(sa_eff, 8), sa_eff); + v128_t ratio = wasm_u32x4_trunc_sat_f32x4(wasm_f32x4_div( + wasm_f32x4_convert_u32x4(num), wasm_f32x4_convert_u32x4(den_eff))); + v128_t r8 = wasm_i8x16_shuffle(ratio, ratio, 0, 0, 0, 0, 4, 4, 4, 4, 8, 8, + 8, 8, 12, 12, 12, 12); + v128_t inv_r8 = wasm_v128_not(r8); + v128_t acc_lo = + wasm_i16x8_add(wasm_i16x8_add(wasm_u16x8_extmul_low_u8x16(d, inv_r8), + wasm_u16x8_extmul_low_u8x16(s, r8)), + c1); + v128_t acc_hi = + wasm_i16x8_add(wasm_i16x8_add(wasm_u16x8_extmul_high_u8x16(d, inv_r8), + wasm_u16x8_extmul_high_u8x16(s, r8)), + c1); + acc_lo = + wasm_u16x8_shr(wasm_i16x8_add(acc_lo, wasm_u16x8_shr(acc_lo, 8)), 8); + acc_hi = + wasm_u16x8_shr(wasm_i16x8_add(acc_hi, wasm_u16x8_shr(acc_hi, 8)), 8); + v128_t rgb = wasm_u8x16_narrow_i16x8(acc_lo, acc_hi); + v128_t out = wasm_v128_or(wasm_v128_and(rgb, c00ffffff), + wasm_i32x4_shl(da2, 24)); + wasm_v128_store(dst_argb, out); + dst_argb += 16; + width -= 4; + } while (width > 0); +} +#endif // HAS_ARGBALPHABLENDROW_WASMSIMD + +#undef LIBYUV_WASM_SWIZZLE + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) diff --git a/libs/libyuv/source/row_win.cc b/libs/libyuv/source/row_win.cc index f976d40260..ba6f7b56e3 100644 --- a/libs/libyuv/source/row_win.cc +++ b/libs/libyuv/source/row_win.cc @@ -8,15 +8,22 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "libyuv/convert_from_argb.h" // For ArgbConstants #include "libyuv/row.h" -// This module is for Visual C 32/64 bit and clangcl 32 bit -#if !defined(LIBYUV_DISABLE_X86) && defined(_MSC_VER) && \ - (defined(_M_IX86) || (defined(_M_X64) && !defined(__clang__))) +// This module is for Visual C 32/64 bit +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || \ + defined(_M_IX86)) && \ + ((defined(_MSC_VER) && !defined(__clang__)) || \ + defined(LIBYUV_ENABLE_ROWWIN)) -#if defined(_M_X64) #include +#include // For AVX2 intrinsics +#include // For memcpy #include // For _mm_maddubs_epi16 +#if defined(_MSC_VER) && !defined(__clang__) +#include #endif #ifdef __cplusplus @@ -24,15 +31,170 @@ namespace libyuv { extern "C" { #endif -// 64 bit -#if defined(_M_X64) +#if defined(__clang__) || defined(__GNUC__) +#define LIBYUV_TARGET_SSSE3 __attribute__((target("ssse3"))) +#define LIBYUV_TARGET_AVX __attribute__((target("avx"))) +#define LIBYUV_TARGET_AVX2 __attribute__((target("avx2"))) +#define LIBYUV_TARGET_AVX2_FMA __attribute__((target("avx2,fma"))) +#define LIBYUV_TARGET_AVX512BW \ + __attribute__((target("avx512bw,avx512vl,avx512f"))) +#define LIBYUV_TARGET_AVX512VBMI \ + __attribute__((target("avx512vbmi,avx512bw,avx512vl,avx512f"))) +#define LIBYUV_TARGET_AVX512VNNI \ + __attribute__((target("avx512vnni,avx512bw,avx512vl,avx512f"))) +#define LIBYUV_TARGET_AVX512VNNIVBMI \ + __attribute__((target("avx512vnni,avx512vbmi,avx512bw,avx512vl,avx512f"))) +#else +#define LIBYUV_TARGET_SSSE3 +#define LIBYUV_TARGET_AVX +#define LIBYUV_TARGET_AVX2 +#define LIBYUV_TARGET_AVX2_FMA +#define LIBYUV_TARGET_AVX512BW +#define LIBYUV_TARGET_AVX512VBMI +#define LIBYUV_TARGET_AVX512VNNI +#define LIBYUV_TARGET_AVX512VNNIVBMI +#endif // defined(__clang__) || defined(__GNUC__) + +#if defined(__x86_64__) || defined(_M_X64) +// Under MemorySanitizer, use portable lane-by-lane C loops for single-source +// variable permutes and 512-bit float-to-int truncation so shadow propagation +// relies only on standard C memory/array semantics rather than target-specific +// LLVM intrinsic modeling. In non-MSan builds, call the native AVX-512 +// intrinsics directly. +LIBYUV_TARGET_AVX512VBMI +static inline __m512i PermutexvarEpi8(__m512i idx, __m512i v) { +#if defined(LIBYUV_MSAN) + uint8_t idx_arr[64]; + uint8_t v_arr[64]; + uint8_t out_arr[64]; + _mm512_storeu_si512((__m512i*)idx_arr, idx); + _mm512_storeu_si512((__m512i*)v_arr, v); + for (int i = 0; i < 64; ++i) { + out_arr[i] = v_arr[idx_arr[i] & 63]; + } + return _mm512_loadu_si512((const __m512i*)out_arr); +#else + return _mm512_permutexvar_epi8(idx, v); +#endif +} + +LIBYUV_TARGET_AVX512VBMI +static inline __m512i MaskPermutexvarEpi8(__m512i src, + __mmask64 k, + __m512i idx, + __m512i v) { +#if defined(LIBYUV_MSAN) + uint8_t src_arr[64]; + uint8_t idx_arr[64]; + uint8_t v_arr[64]; + uint8_t out_arr[64]; + _mm512_storeu_si512((__m512i*)src_arr, src); + _mm512_storeu_si512((__m512i*)idx_arr, idx); + _mm512_storeu_si512((__m512i*)v_arr, v); + for (int i = 0; i < 64; ++i) { + out_arr[i] = ((k >> i) & 1) ? v_arr[idx_arr[i] & 63] : src_arr[i]; + } + return _mm512_loadu_si512((const __m512i*)out_arr); +#else + return _mm512_mask_permutexvar_epi8(src, k, idx, v); +#endif +} + +LIBYUV_TARGET_AVX512BW +static inline __m512i PermutexvarEpi16(__m512i idx, __m512i v) { +#if defined(LIBYUV_MSAN) + uint16_t idx_arr[32]; + uint16_t v_arr[32]; + uint16_t out_arr[32]; + _mm512_storeu_si512((__m512i*)idx_arr, idx); + _mm512_storeu_si512((__m512i*)v_arr, v); + for (int i = 0; i < 32; ++i) { + out_arr[i] = v_arr[idx_arr[i] & 31]; + } + return _mm512_loadu_si512((const __m512i*)out_arr); +#else + return _mm512_permutexvar_epi16(idx, v); +#endif +} + +LIBYUV_TARGET_AVX512BW +static inline __m512i PermutexvarEpi32(__m512i idx, __m512i v) { +#if defined(LIBYUV_MSAN) + uint32_t idx_arr[16]; + uint32_t v_arr[16]; + uint32_t out_arr[16]; + _mm512_storeu_si512((__m512i*)idx_arr, idx); + _mm512_storeu_si512((__m512i*)v_arr, v); + for (int i = 0; i < 16; ++i) { + out_arr[i] = v_arr[idx_arr[i] & 15]; + } + return _mm512_loadu_si512((const __m512i*)out_arr); +#else + return _mm512_permutexvar_epi32(idx, v); +#endif +} + +LIBYUV_TARGET_AVX512BW +static inline __m512i PermutexvarEpi64(__m512i idx, __m512i v) { +#if defined(LIBYUV_MSAN) + uint64_t idx_arr[8]; + uint64_t v_arr[8]; + uint64_t out_arr[8]; + _mm512_storeu_si512((__m512i*)idx_arr, idx); + _mm512_storeu_si512((__m512i*)v_arr, v); + for (int i = 0; i < 8; ++i) { + out_arr[i] = v_arr[idx_arr[i] & 7]; + } + return _mm512_loadu_si512((const __m512i*)out_arr); +#else + return _mm512_permutexvar_epi64(idx, v); +#endif +} + +LIBYUV_TARGET_AVX512BW +static inline __m512i CvttpsEpi32(__m512 v) { +#if defined(LIBYUV_MSAN) + float v_arr[16]; + int32_t out_arr[16]; + _mm512_storeu_ps(v_arr, v); + for (int i = 0; i < 16; ++i) { + out_arr[i] = (int32_t)v_arr[i]; + } + return _mm512_loadu_si512((const __m512i*)out_arr); +#else + return _mm512_cvttps_epi32(v); +#endif +} +#endif // defined(__x86_64__) || defined(_M_X64) + +// Read 8 UV from 444 +#define READYUV444 \ + xmm3 = _mm_loadl_epi64((__m128i*)u_buf); \ + xmm1 = _mm_loadl_epi64((__m128i*)(u_buf + offset)); \ + xmm3 = _mm_unpacklo_epi8(xmm3, xmm1); \ + u_buf += 8; \ + xmm4 = _mm_loadl_epi64((__m128i*)y_buf); \ + xmm4 = _mm_unpacklo_epi8(xmm4, xmm4); \ + y_buf += 8; + +// Read 8 UV from 444, With 8 Alpha. +#define READYUVA444 \ + xmm3 = _mm_loadl_epi64((__m128i*)u_buf); \ + xmm1 = _mm_loadl_epi64((__m128i*)(u_buf + offset)); \ + xmm3 = _mm_unpacklo_epi8(xmm3, xmm1); \ + u_buf += 8; \ + xmm4 = _mm_loadl_epi64((__m128i*)y_buf); \ + xmm4 = _mm_unpacklo_epi8(xmm4, xmm4); \ + y_buf += 8; \ + xmm5 = _mm_loadl_epi64((__m128i*)a_buf); \ + a_buf += 8; // Read 4 UV from 422, upsample to 8 UV. #define READYUV422 \ - xmm0 = _mm_cvtsi32_si128(*(uint32_t*)u_buf); \ + xmm3 = _mm_cvtsi32_si128(*(uint32_t*)u_buf); \ xmm1 = _mm_cvtsi32_si128(*(uint32_t*)(u_buf + offset)); \ - xmm0 = _mm_unpacklo_epi8(xmm0, xmm1); \ - xmm0 = _mm_unpacklo_epi16(xmm0, xmm0); \ + xmm3 = _mm_unpacklo_epi8(xmm3, xmm1); \ + xmm3 = _mm_unpacklo_epi16(xmm3, xmm3); \ u_buf += 4; \ xmm4 = _mm_loadl_epi64((__m128i*)y_buf); \ xmm4 = _mm_unpacklo_epi8(xmm4, xmm4); \ @@ -40,10 +202,10 @@ extern "C" { // Read 4 UV from 422, upsample to 8 UV. With 8 Alpha. #define READYUVA422 \ - xmm0 = _mm_cvtsi32_si128(*(uint32_t*)u_buf); \ + xmm3 = _mm_cvtsi32_si128(*(uint32_t*)u_buf); \ xmm1 = _mm_cvtsi32_si128(*(uint32_t*)(u_buf + offset)); \ - xmm0 = _mm_unpacklo_epi8(xmm0, xmm1); \ - xmm0 = _mm_unpacklo_epi16(xmm0, xmm0); \ + xmm3 = _mm_unpacklo_epi8(xmm3, xmm1); \ + xmm3 = _mm_unpacklo_epi16(xmm3, xmm3); \ u_buf += 4; \ xmm4 = _mm_loadl_epi64((__m128i*)y_buf); \ xmm4 = _mm_unpacklo_epi8(xmm4, xmm4); \ @@ -52,24 +214,21 @@ extern "C" { a_buf += 8; // Convert 8 pixels: 8 UV and 8 Y. -#define YUVTORGB(yuvconstants) \ - xmm1 = _mm_loadu_si128(&xmm0); \ - xmm2 = _mm_loadu_si128(&xmm0); \ - xmm0 = _mm_maddubs_epi16(xmm0, *(__m128i*)yuvconstants->kUVToB); \ - xmm1 = _mm_maddubs_epi16(xmm1, *(__m128i*)yuvconstants->kUVToG); \ - xmm2 = _mm_maddubs_epi16(xmm2, *(__m128i*)yuvconstants->kUVToR); \ - xmm0 = _mm_sub_epi16(*(__m128i*)yuvconstants->kUVBiasB, xmm0); \ - xmm1 = _mm_sub_epi16(*(__m128i*)yuvconstants->kUVBiasG, xmm1); \ - xmm2 = _mm_sub_epi16(*(__m128i*)yuvconstants->kUVBiasR, xmm2); \ - xmm4 = _mm_mulhi_epu16(xmm4, *(__m128i*)yuvconstants->kYToRgb); \ - xmm0 = _mm_adds_epi16(xmm0, xmm4); \ - xmm1 = _mm_adds_epi16(xmm1, xmm4); \ - xmm2 = _mm_adds_epi16(xmm2, xmm4); \ - xmm0 = _mm_srai_epi16(xmm0, 6); \ - xmm1 = _mm_srai_epi16(xmm1, 6); \ - xmm2 = _mm_srai_epi16(xmm2, 6); \ - xmm0 = _mm_packus_epi16(xmm0, xmm0); \ - xmm1 = _mm_packus_epi16(xmm1, xmm1); \ +#define YUVTORGB(yuvconstants) \ + xmm3 = _mm_sub_epi8(xmm3, _mm_set1_epi8((char)0x80)); \ + xmm4 = _mm_mulhi_epu16(xmm4, *(__m128i*)yuvconstants->kYToRgb); \ + xmm4 = _mm_add_epi16(xmm4, *(__m128i*)yuvconstants->kYBiasToRgb); \ + xmm0 = _mm_maddubs_epi16(*(__m128i*)yuvconstants->kUVToB, xmm3); \ + xmm1 = _mm_maddubs_epi16(*(__m128i*)yuvconstants->kUVToG, xmm3); \ + xmm2 = _mm_maddubs_epi16(*(__m128i*)yuvconstants->kUVToR, xmm3); \ + xmm0 = _mm_adds_epi16(xmm4, xmm0); \ + xmm1 = _mm_subs_epi16(xmm4, xmm1); \ + xmm2 = _mm_adds_epi16(xmm4, xmm2); \ + xmm0 = _mm_srai_epi16(xmm0, 6); \ + xmm1 = _mm_srai_epi16(xmm1, 6); \ + xmm2 = _mm_srai_epi16(xmm2, 6); \ + xmm0 = _mm_packus_epi16(xmm0, xmm0); \ + xmm1 = _mm_packus_epi16(xmm1, xmm1); \ xmm2 = _mm_packus_epi16(xmm2, xmm2); // Store 8 ARGB values. @@ -83,6152 +242,10616 @@ extern "C" { _mm_storeu_si128((__m128i*)(dst_argb + 16), xmm1); \ dst_argb += 32; -#if defined(HAS_I422TOARGBROW_SSSE3) -void I422ToARGBRow_SSSE3(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __m128i xmm0, xmm1, xmm2, xmm4; - const __m128i xmm5 = _mm_set1_epi8(-1); - const ptrdiff_t offset = (uint8_t*)v_buf - (uint8_t*)u_buf; +// Store 8 AR30 values. +#define STOREAR30 \ + xmm1 = _mm_and_si128(xmm1, xmm7); \ + xmm2 = _mm_and_si128(xmm2, xmm7); \ + xmm0 = _mm_srli_epi16(xmm0, 4); \ + xmm3 = _mm_slli_epi16(xmm1, 6); \ + xmm0 = _mm_or_si128(xmm0, xmm3); \ + xmm1 = _mm_srli_epi16(xmm1, 10); \ + xmm2 = _mm_or_si128(xmm2, xmm6); \ + xmm2 = _mm_or_si128(xmm2, xmm1); \ + xmm1 = _mm_unpackhi_epi16(xmm0, xmm2); \ + xmm0 = _mm_unpacklo_epi16(xmm0, xmm2); \ + _mm_storeu_si128((__m128i*)dst_ar30, xmm0); \ + _mm_storeu_si128((__m128i*)(dst_ar30 + 16), xmm1); \ + dst_ar30 += 32; + +// Convert 32 ARGB pixels (128 bytes) to 32 UV444 values. +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) || defined(HAS_ARGBTOUV444MATRIXROW_AVX2) +LIBYUV_TARGET_AVX2 +void ARGBToUV444MatrixRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + __m256i ymm_u = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)c->kRGBToU)); + __m256i ymm_v = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)c->kRGBToV)); + __m256i ymm5 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)c->kAddUV)); + __m256i perm_mask = _mm256_setr_epi32(0, 4, 1, 5, 2, 6, 3, 7); + while (width > 0) { - READYUV422 - YUVTORGB(yuvconstants) - STOREARGB - width -= 8; + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_argb); + __m256i ymm1 = _mm256_loadu_si256((const __m256i*)(src_argb + 32)); + __m256i ymm2 = _mm256_loadu_si256((const __m256i*)(src_argb + 64)); + __m256i ymm3 = _mm256_loadu_si256((const __m256i*)(src_argb + 96)); + src_argb += 128; + + __m256i ymm0_u = _mm256_maddubs_epi16(ymm0, ymm_u); + __m256i ymm1_u = _mm256_maddubs_epi16(ymm1, ymm_u); + __m256i ymm2_u = _mm256_maddubs_epi16(ymm2, ymm_u); + __m256i ymm3_u = _mm256_maddubs_epi16(ymm3, ymm_u); + + __m256i ymm0_v = _mm256_maddubs_epi16(ymm0, ymm_v); + __m256i ymm1_v = _mm256_maddubs_epi16(ymm1, ymm_v); + __m256i ymm2_v = _mm256_maddubs_epi16(ymm2, ymm_v); + __m256i ymm3_v = _mm256_maddubs_epi16(ymm3, ymm_v); + + ymm0_u = _mm256_hadd_epi16(ymm0_u, ymm1_u); + ymm2_u = _mm256_hadd_epi16(ymm2_u, ymm3_u); + + ymm0_v = _mm256_hadd_epi16(ymm0_v, ymm1_v); + ymm2_v = _mm256_hadd_epi16(ymm2_v, ymm3_v); + + ymm0_u = _mm256_sub_epi16(ymm5, ymm0_u); + ymm2_u = _mm256_sub_epi16(ymm5, ymm2_u); + + ymm0_v = _mm256_sub_epi16(ymm5, ymm0_v); + ymm2_v = _mm256_sub_epi16(ymm5, ymm2_v); + + ymm0_u = _mm256_srli_epi16(ymm0_u, 8); + ymm2_u = _mm256_srli_epi16(ymm2_u, 8); + + ymm0_v = _mm256_srli_epi16(ymm0_v, 8); + ymm2_v = _mm256_srli_epi16(ymm2_v, 8); + + ymm0_u = _mm256_packus_epi16(ymm0_u, ymm2_u); + ymm0_u = _mm256_permutevar8x32_epi32(ymm0_u, perm_mask); + + ymm0_v = _mm256_packus_epi16(ymm0_v, ymm2_v); + ymm0_v = _mm256_permutevar8x32_epi32(ymm0_v, perm_mask); + + _mm256_storeu_si256((__m256i*)dst_u, ymm0_u); + _mm256_storeu_si256((__m256i*)dst_v, ymm0_v); + dst_u += 32; + dst_v += 32; + width -= 32; } + _mm256_zeroupper(); } -#endif +#endif // defined(HAS_ARGBTOYMATRIXROW_AVX2) || + // defined(HAS_ARGBTOUV444MATRIXROW_AVX2) + +#if defined(HAS_ARGBTOYMATRIXROW_AVX2) +LIBYUV_TARGET_AVX2 +void ARGBToYMatrixRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + __m256i ymm5 = _mm256_set1_epi8((char)0x80); + __m256i ymm4 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)c->kRGBToY)); + __m256i ymm7 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)c->kAddY)); + __m256i ymm6 = _mm256_maddubs_epi16(ymm4, ymm5); + ymm6 = _mm256_hadd_epi16(ymm6, ymm6); + ymm7 = _mm256_sub_epi16(ymm7, ymm6); + __m256i perm_mask = _mm256_setr_epi32(0, 4, 1, 5, 2, 6, 3, 7); -#if defined(HAS_I422ALPHATOARGBROW_SSSE3) -void I422AlphaToARGBRow_SSSE3(const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - const uint8_t* a_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __m128i xmm0, xmm1, xmm2, xmm4, xmm5; - const ptrdiff_t offset = (uint8_t*)v_buf - (uint8_t*)u_buf; while (width > 0) { - READYUVA422 - YUVTORGB(yuvconstants) - STOREARGB - width -= 8; + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_argb); + __m256i ymm1 = _mm256_loadu_si256((const __m256i*)(src_argb + 32)); + __m256i ymm2 = _mm256_loadu_si256((const __m256i*)(src_argb + 64)); + __m256i ymm3 = _mm256_loadu_si256((const __m256i*)(src_argb + 96)); + src_argb += 128; + + ymm0 = _mm256_sub_epi8(ymm0, ymm5); + ymm1 = _mm256_sub_epi8(ymm1, ymm5); + ymm2 = _mm256_sub_epi8(ymm2, ymm5); + ymm3 = _mm256_sub_epi8(ymm3, ymm5); + + ymm0 = _mm256_maddubs_epi16(ymm4, ymm0); + ymm1 = _mm256_maddubs_epi16(ymm4, ymm1); + ymm2 = _mm256_maddubs_epi16(ymm4, ymm2); + ymm3 = _mm256_maddubs_epi16(ymm4, ymm3); + + ymm0 = _mm256_hadd_epi16(ymm0, ymm1); + ymm2 = _mm256_hadd_epi16(ymm2, ymm3); + + ymm0 = _mm256_add_epi16(ymm0, ymm7); + ymm2 = _mm256_add_epi16(ymm2, ymm7); + + ymm0 = _mm256_srli_epi16(ymm0, 8); + ymm2 = _mm256_srli_epi16(ymm2, 8); + + ymm0 = _mm256_packus_epi16(ymm0, ymm2); + ymm0 = _mm256_permutevar8x32_epi32(ymm0, perm_mask); + + _mm256_storeu_si256((__m256i*)dst_y, ymm0); + dst_y += 32; + width -= 32; } + _mm256_zeroupper(); } -#endif +#endif // defined(HAS_ARGBTOYMATRIXROW_AVX2) -// 32 bit -#else // defined(_M_X64) -#ifdef HAS_ARGBTOYROW_SSSE3 +#ifdef HAS_RAWTOARGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void RAWToARGBRow_AVX2(const uint8_t* src_raw, uint8_t* dst_argb, int width) { + __m256i ymm_alpha = _mm256_set1_epi32(0xff000000); + __m128i shuf_low = + _mm_set_epi8(-1, 9, 10, 11, -1, 6, 7, 8, -1, 3, 4, 5, -1, 0, 1, 2); + __m128i shuf_high = + _mm_set_epi8(-1, 13, 14, 15, -1, 10, 11, 12, -1, 7, 8, 9, -1, 4, 5, 6); + __m256i ymm_shuf = _mm256_broadcastsi128_si256(shuf_low); + __m256i ymm_shuf2 = _mm256_broadcastsi128_si256(shuf_high); -// Constants for ARGB. -static const vec8 kARGBToY = {13, 65, 33, 0, 13, 65, 33, 0, - 13, 65, 33, 0, 13, 65, 33, 0}; + while (width > 0) { + __m128i xmm0 = _mm_loadu_si128((const __m128i*)src_raw); + __m256i ymm0 = _mm256_castsi128_si256(xmm0); + ymm0 = _mm256_inserti128_si256( + ymm0, _mm_loadu_si128((const __m128i*)(src_raw + 12)), 1); -// JPeg full range. -static const vec8 kARGBToYJ = {15, 75, 38, 0, 15, 75, 38, 0, - 15, 75, 38, 0, 15, 75, 38, 0}; + __m128i xmm1 = _mm_loadu_si128((const __m128i*)(src_raw + 24)); + __m256i ymm1 = _mm256_castsi128_si256(xmm1); + ymm1 = _mm256_inserti128_si256( + ymm1, _mm_loadu_si128((const __m128i*)(src_raw + 36)), 1); -static const vec8 kARGBToU = {112, -74, -38, 0, 112, -74, -38, 0, - 112, -74, -38, 0, 112, -74, -38, 0}; + __m128i xmm2 = _mm_loadu_si128((const __m128i*)(src_raw + 48)); + __m256i ymm2 = _mm256_castsi128_si256(xmm2); + ymm2 = _mm256_inserti128_si256( + ymm2, _mm_loadu_si128((const __m128i*)(src_raw + 60)), 1); -static const vec8 kARGBToUJ = {127, -84, -43, 0, 127, -84, -43, 0, - 127, -84, -43, 0, 127, -84, -43, 0}; + __m128i xmm3 = _mm_loadu_si128((const __m128i*)(src_raw + 68)); + __m256i ymm3 = _mm256_castsi128_si256(xmm3); + ymm3 = _mm256_inserti128_si256( + ymm3, _mm_loadu_si128((const __m128i*)(src_raw + 80)), 1); -static const vec8 kARGBToV = { - -18, -94, 112, 0, -18, -94, 112, 0, -18, -94, 112, 0, -18, -94, 112, 0, -}; + ymm0 = _mm256_shuffle_epi8(ymm0, ymm_shuf); + ymm1 = _mm256_shuffle_epi8(ymm1, ymm_shuf); + ymm2 = _mm256_shuffle_epi8(ymm2, ymm_shuf); + ymm3 = _mm256_shuffle_epi8(ymm3, ymm_shuf2); -static const vec8 kARGBToVJ = {-20, -107, 127, 0, -20, -107, 127, 0, - -20, -107, 127, 0, -20, -107, 127, 0}; + ymm0 = _mm256_or_si256(ymm0, ymm_alpha); + ymm1 = _mm256_or_si256(ymm1, ymm_alpha); + ymm2 = _mm256_or_si256(ymm2, ymm_alpha); + ymm3 = _mm256_or_si256(ymm3, ymm_alpha); -// vpshufb for vphaddw + vpackuswb packed to shorts. -static const lvec8 kShufARGBToUV_AVX = { - 0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15, - 0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15}; + _mm256_storeu_si256((__m256i*)dst_argb, ymm0); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), ymm1); + _mm256_storeu_si256((__m256i*)(dst_argb + 64), ymm2); + _mm256_storeu_si256((__m256i*)(dst_argb + 96), ymm3); -// Constants for BGRA. -static const vec8 kBGRAToY = {0, 33, 65, 13, 0, 33, 65, 13, - 0, 33, 65, 13, 0, 33, 65, 13}; + src_raw += 96; + dst_argb += 128; + width -= 32; + } + _mm256_zeroupper(); +} +#endif // HAS_RAWTOARGBROW_AVX2 -static const vec8 kBGRAToU = {0, -38, -74, 112, 0, -38, -74, 112, - 0, -38, -74, 112, 0, -38, -74, 112}; +#if defined(HAS_RAWTOARGBROW_AVX512BW) || \ + defined(HAS_RGB24TOARGBROW_AVX512BW) || \ + defined(HAS_RAWTORGB24ROW_AVX512BW) || \ + defined(HAS_RGBTOYMATRIXROW_AVX512BW) +static const uint64_t kPermqRGB24ToARGB0_AVX512BW[8] = {0, 1, 1, 2, 3, 4, 4, 5}; +static const uint64_t kPermqRGB24ToARGB1_AVX512BW[8] = {6, 7, 7, 8, + 9, 10, 10, 11}; +static const uint64_t kPermqRGB24ToARGB2_AVX512BW[8] = {4, 5, 5, 6, 7, 8, 8, 9}; +static const uint64_t kPermqRGB24ToARGB3_AVX512BW[8] = {2, 3, 3, 4, 5, 6, 6, 7}; +#endif // defined(HAS_RAWTOARGBROW_AVX512BW) || + // defined(HAS_RGB24TOARGBROW_AVX512BW) || + // defined(HAS_RAWTORGB24ROW_AVX512BW) || + // defined(HAS_RGBTOYMATRIXROW_AVX512BW) -static const vec8 kBGRAToV = {0, 112, -94, -18, 0, 112, -94, -18, - 0, 112, -94, -18, 0, 112, -94, -18}; +#if defined(HAS_RGB24TOARGBROW_AVX512BW) || \ + defined(HAS_RGBTOYMATRIXROW_AVX512BW) +static const uint8_t kShuffleMaskRGB24ToARGB_AVX512BW[32] = { + 0u, 1u, 2u, 128u, 3u, 4u, 5u, 128u, 6u, 7u, 8u, + 128u, 9u, 10u, 11u, 128u, 4u, 5u, 6u, 128u, 7u, 8u, + 9u, 128u, 10u, 11u, 12u, 128u, 13u, 14u, 15u, 128u}; +#endif // defined(HAS_RGB24TOARGBROW_AVX512BW) || + // defined(HAS_RGBTOYMATRIXROW_AVX512BW) -// Constants for ABGR. -static const vec8 kABGRToY = {33, 65, 13, 0, 33, 65, 13, 0, - 33, 65, 13, 0, 33, 65, 13, 0}; - -static const vec8 kABGRToU = {-38, -74, 112, 0, -38, -74, 112, 0, - -38, -74, 112, 0, -38, -74, 112, 0}; - -static const vec8 kABGRToV = {112, -94, -18, 0, 112, -94, -18, 0, - 112, -94, -18, 0, 112, -94, -18, 0}; - -// Constants for RGBA. -static const vec8 kRGBAToY = {0, 13, 65, 33, 0, 13, 65, 33, - 0, 13, 65, 33, 0, 13, 65, 33}; - -static const vec8 kRGBAToU = {0, 112, -74, -38, 0, 112, -74, -38, - 0, 112, -74, -38, 0, 112, -74, -38}; - -static const vec8 kRGBAToV = {0, -18, -94, 112, 0, -18, -94, 112, - 0, -18, -94, 112, 0, -18, -94, 112}; - -static const uvec8 kAddY16 = {16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, - 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u}; - -// 7 bit fixed point 0.5. -static const vec16 kAddYJ64 = {64, 64, 64, 64, 64, 64, 64, 64}; - -static const uvec8 kAddUV128 = {128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, - 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u}; - -static const uvec16 kAddUVJ128 = {0x8080u, 0x8080u, 0x8080u, 0x8080u, - 0x8080u, 0x8080u, 0x8080u, 0x8080u}; - -// Shuffle table for converting RGB24 to ARGB. -static const uvec8 kShuffleMaskRGB24ToARGB = { - 0u, 1u, 2u, 12u, 3u, 4u, 5u, 13u, 6u, 7u, 8u, 14u, 9u, 10u, 11u, 15u}; - -// Shuffle table for converting RAW to ARGB. -static const uvec8 kShuffleMaskRAWToARGB = {2u, 1u, 0u, 12u, 5u, 4u, 3u, 13u, - 8u, 7u, 6u, 14u, 11u, 10u, 9u, 15u}; +#if defined(HAS_RAWTOARGBROW_AVX512BW) +static const uint8_t kShuffleMaskRAWToARGB_AVX512BW[32] = { + 2u, 1u, 0u, 128u, 5u, 4u, 3u, 128u, 8u, 7u, 6u, + 128u, 11u, 10u, 9u, 128u, 6u, 5u, 4u, 128u, 9u, 8u, + 7u, 128u, 12u, 11u, 10u, 128u, 15u, 14u, 13u, 128u}; +#endif // defined(HAS_RAWTOARGBROW_AVX512BW) +#if defined(HAS_RAWTORGB24ROW_SSSE3) // Shuffle table for converting RAW to RGB24. First 8. -static const uvec8 kShuffleMaskRAWToRGB24_0 = { +static const uint8_t kShuffleMaskRAWToRGB24_0[16] = { 2u, 1u, 0u, 5u, 4u, 3u, 8u, 7u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u}; // Shuffle table for converting RAW to RGB24. Middle 8. -static const uvec8 kShuffleMaskRAWToRGB24_1 = { +static const uint8_t kShuffleMaskRAWToRGB24_1[16] = { 2u, 7u, 6u, 5u, 10u, 9u, 8u, 13u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u}; // Shuffle table for converting RAW to RGB24. Last 8. -static const uvec8 kShuffleMaskRAWToRGB24_2 = { +static const uint8_t kShuffleMaskRAWToRGB24_2[16] = { 8u, 7u, 12u, 11u, 10u, 15u, 14u, 13u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u}; +#endif // defined(HAS_RAWTORGB24ROW_SSSE3) -// Shuffle table for converting ARGB to RGB24. -static const uvec8 kShuffleMaskARGBToRGB24 = { - 0u, 1u, 2u, 4u, 5u, 6u, 8u, 9u, 10u, 12u, 13u, 14u, 128u, 128u, 128u, 128u}; +#if defined(HAS_RAWTORGB24ROW_AVX2) || defined(HAS_RAWTORGB24ROW_AVX512BW) +static const uint8_t kShuffleMaskRAWToRGB24_AVX2[32] = { + 2u, 1u, 0u, 5u, 4u, 3u, 8u, 7u, 6u, 11u, 10u, + 9u, 128u, 128u, 128u, 128u, 6u, 5u, 4u, 9u, 8u, 7u, + 12u, 11u, 10u, 15u, 14u, 13u, 128u, 128u, 128u, 128u}; +#endif // defined(HAS_RAWTORGB24ROW_AVX2) || + // defined(HAS_RAWTORGB24ROW_AVX512BW) -// Shuffle table for converting ARGB to RAW. -static const uvec8 kShuffleMaskARGBToRAW = { - 2u, 1u, 0u, 6u, 5u, 4u, 10u, 9u, 8u, 14u, 13u, 12u, 128u, 128u, 128u, 128u}; +#if defined(HAS_RAWTORGB24ROW_AVX2) +static const uint32_t kPermd0_AVX2[8] = {0, 1, 2, 4, 5, 6, 3, 7}; +static const uint32_t kPermd1_AVX2[8] = {2, 4, 5, 6, 3, 7, 0, 1}; +static const uint32_t kPermd2_AVX2[8] = {5, 6, 3, 7, 0, 1, 2, 4}; +#endif // defined(HAS_RAWTORGB24ROW_AVX2) -// Shuffle table for converting ARGBToRGB24 for I422ToRGB24. First 8 + next 4 -static const uvec8 kShuffleMaskARGBToRGB24_0 = { - 0u, 1u, 2u, 4u, 5u, 6u, 8u, 9u, 128u, 128u, 128u, 128u, 10u, 12u, 13u, 14u}; +#if defined(HAS_RAWTORGB24ROW_AVX512BW) || \ + defined(HAS_ARGBTORGB24ROW_AVX512BW) || \ + defined(HAS_ARGBTORAWROW_AVX512BW) +static const uint32_t kPermdRGB24_0_AVX512BW[16] = { + 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 16, 17, 18, 20}; +static const uint32_t kPermdRGB24_1_AVX512BW[16] = { + 5, 6, 8, 9, 10, 12, 13, 14, 16, 17, 18, 20, 21, 22, 24, 25}; +static const uint32_t kPermdRGB24_2_AVX512BW[16] = { + 10, 12, 13, 14, 16, 17, 18, 20, 21, 22, 24, 25, 26, 28, 29, 30}; +#endif +#if defined(HAS_RAWTORGB24ROW_AVX512VBMI) +static const uint8_t kPermRAWToRGB24_0[64] = { + 0x02, 0x01, 0x00, 0x05, 0x04, 0x03, 0x08, 0x07, 0x06, 0x0b, 0x0a, + 0x09, 0x0e, 0x0d, 0x0c, 0x11, 0x10, 0x0f, 0x14, 0x13, 0x12, 0x17, + 0x16, 0x15, 0x1a, 0x19, 0x18, 0x1d, 0x1c, 0x1b, 0x20, 0x1f, 0x1e, + 0x23, 0x22, 0x21, 0x26, 0x25, 0x24, 0x29, 0x28, 0x27, 0x2c, 0x2b, + 0x2a, 0x2f, 0x2e, 0x2d, 0x32, 0x31, 0x30, 0x35, 0x34, 0x33, 0x38, + 0x37, 0x36, 0x3b, 0x3a, 0x39, 0x3e, 0x3d, 0x3c, 0x41}; +static const uint8_t kPermRAWToRGB24_1[64] = { + 0x00, 0x7f, 0x04, 0x03, 0x02, 0x07, 0x06, 0x05, 0x0a, 0x09, 0x08, + 0x0d, 0x0c, 0x0b, 0x10, 0x0f, 0x0e, 0x13, 0x12, 0x11, 0x16, 0x15, + 0x14, 0x19, 0x18, 0x17, 0x1c, 0x1b, 0x1a, 0x1f, 0x1e, 0x1d, 0x22, + 0x21, 0x20, 0x25, 0x24, 0x23, 0x28, 0x27, 0x26, 0x2b, 0x2a, 0x29, + 0x2e, 0x2d, 0x2c, 0x31, 0x30, 0x2f, 0x34, 0x33, 0x32, 0x37, 0x36, + 0x35, 0x3a, 0x39, 0x38, 0x3d, 0x3c, 0x3b, 0x00, 0x3f}; +static const uint8_t kPermRAWToRGB24_2[64] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, + 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, + 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, + 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, + 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x40, 0x3f}; +static const uint8_t kPermRAWToRGB24_3[64] = { + 0x3e, 0x43, 0x42, 0x41, 0x46, 0x45, 0x44, 0x49, 0x48, 0x47, 0x4c, + 0x4b, 0x4a, 0x4f, 0x4e, 0x4d, 0x52, 0x51, 0x50, 0x55, 0x54, 0x53, + 0x58, 0x57, 0x56, 0x5b, 0x5a, 0x59, 0x5e, 0x5d, 0x5c, 0x61, 0x60, + 0x5f, 0x64, 0x63, 0x62, 0x67, 0x66, 0x65, 0x6a, 0x69, 0x68, 0x6d, + 0x6c, 0x6b, 0x70, 0x6f, 0x6e, 0x73, 0x72, 0x71, 0x76, 0x75, 0x74, + 0x79, 0x78, 0x77, 0x7c, 0x7b, 0x7a, 0x7f, 0x7e, 0x7d}; +#endif // defined(HAS_RAWTORGB24ROW_AVX512VBMI) -// YUY2 shuf 16 Y to 32 Y. -static const lvec8 kShuffleYUY2Y = {0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, - 10, 12, 12, 14, 14, 0, 0, 2, 2, 4, 4, - 6, 6, 8, 8, 10, 10, 12, 12, 14, 14}; +#if defined(HAS_RAWTOARGBROW_AVX512BW) || defined(HAS_RGB24TOARGBROW_AVX512BW) +LIBYUV_TARGET_AVX512BW +static void RGBToARGBRow_AVX512BW(const uint8_t* src_raw, + uint8_t* dst_argb, + const uint32_t* shuffler, + int width) { + __m512i zmm_alpha = _mm512_set1_epi32(0xff000000); + __m512i zmm_q0 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB0_AVX512BW); + __m512i zmm_q1 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB1_AVX512BW); + __m512i zmm_q2 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB2_AVX512BW); + __m512i zmm_q3 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB3_AVX512BW); + __m512i zmm_shuf = + _mm512_broadcast_i64x4(_mm256_loadu_si256((const __m256i*)shuffler)); -// YUY2 shuf 8 UV to 16 UV. -static const lvec8 kShuffleYUY2UV = {1, 3, 1, 3, 5, 7, 5, 7, 9, 11, 9, - 11, 13, 15, 13, 15, 1, 3, 1, 3, 5, 7, - 5, 7, 9, 11, 9, 11, 13, 15, 13, 15}; + while (width >= 64) { + __m512i zmm_raw0 = _mm512_loadu_si512((const __m512i*)src_raw); + __m512i zmm_raw1 = _mm512_loadu_si512((const __m512i*)(src_raw + 64)); + __m512i zmm_raw2 = _mm512_loadu_si512((const __m512i*)(src_raw + 128)); -// UYVY shuf 16 Y to 32 Y. -static const lvec8 kShuffleUYVYY = {1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11, - 11, 13, 13, 15, 15, 1, 1, 3, 3, 5, 5, - 7, 7, 9, 9, 11, 11, 13, 13, 15, 15}; + __m512i zmm0 = PermutexvarEpi64(zmm_q0, zmm_raw0); + __m512i zmm1 = _mm512_permutex2var_epi64(zmm_raw0, zmm_q1, zmm_raw1); + __m512i zmm2 = _mm512_permutex2var_epi64(zmm_raw1, zmm_q2, zmm_raw2); + __m512i zmm3 = PermutexvarEpi64(zmm_q3, zmm_raw2); -// UYVY shuf 8 UV to 16 UV. -static const lvec8 kShuffleUYVYUV = {0, 2, 0, 2, 4, 6, 4, 6, 8, 10, 8, - 10, 12, 14, 12, 14, 0, 2, 0, 2, 4, 6, - 4, 6, 8, 10, 8, 10, 12, 14, 12, 14}; + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); -// NV21 shuf 8 VU to 16 UV. -static const lvec8 kShuffleNV21 = { - 1, 0, 1, 0, 3, 2, 3, 2, 5, 4, 5, 4, 7, 6, 7, 6, - 1, 0, 1, 0, 3, 2, 3, 2, 5, 4, 5, 4, 7, 6, 7, 6, -}; + zmm0 = _mm512_or_si512(zmm0, zmm_alpha); + zmm1 = _mm512_or_si512(zmm1, zmm_alpha); + zmm2 = _mm512_or_si512(zmm2, zmm_alpha); + zmm3 = _mm512_or_si512(zmm3, zmm_alpha); -// Duplicates gray value 3 times and fills in alpha opaque. -__declspec(naked) void J400ToARGBRow_SSE2(const uint8_t* src_y, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, [esp + 4] // src_y - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - pcmpeqb xmm5, xmm5 // generate mask 0xff000000 - pslld xmm5, 24 + _mm512_storeu_si512(dst_argb, zmm0); + _mm512_storeu_si512(dst_argb + 64, zmm1); + _mm512_storeu_si512(dst_argb + 128, zmm2); + _mm512_storeu_si512(dst_argb + 192, zmm3); - convertloop: - movq xmm0, qword ptr [eax] - lea eax, [eax + 8] - punpcklbw xmm0, xmm0 - movdqa xmm1, xmm0 - punpcklwd xmm0, xmm0 - punpckhwd xmm1, xmm1 - por xmm0, xmm5 - por xmm1, xmm5 - movdqu [edx], xmm0 - movdqu [edx + 16], xmm1 - lea edx, [edx + 32] - sub ecx, 8 - jg convertloop - ret + src_raw += 192; + dst_argb += 256; + width -= 64; + } + if (width > 0) { + uint64_t dst_mask = (1ULL << width) - 1ULL; + int src_bytes = width * 3; + __mmask64 src_mask0 = + (src_bytes >= 64) ? ~0ULL : ((1ULL << src_bytes) - 1ULL); + __mmask64 src_mask1 = + (src_bytes >= 128) + ? ~0ULL + : ((src_bytes > 64) ? ((1ULL << (src_bytes - 64)) - 1ULL) : 0ULL); + __mmask64 src_mask2 = + (src_bytes > 128) ? ((1ULL << (src_bytes - 128)) - 1ULL) : 0ULL; + + __m512i zmm_raw0 = _mm512_maskz_loadu_epi8(src_mask0, src_raw); + __m512i zmm_raw1 = _mm512_maskz_loadu_epi8(src_mask1, src_raw + 64); + __m512i zmm_raw2 = _mm512_maskz_loadu_epi8(src_mask2, src_raw + 128); + + __m512i zmm0 = PermutexvarEpi64(zmm_q0, zmm_raw0); + __m512i zmm1 = _mm512_permutex2var_epi64(zmm_raw0, zmm_q1, zmm_raw1); + __m512i zmm2 = _mm512_permutex2var_epi64(zmm_raw1, zmm_q2, zmm_raw2); + __m512i zmm3 = PermutexvarEpi64(zmm_q3, zmm_raw2); + + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + zmm0 = _mm512_or_si512(zmm0, zmm_alpha); + zmm1 = _mm512_or_si512(zmm1, zmm_alpha); + zmm2 = _mm512_or_si512(zmm2, zmm_alpha); + zmm3 = _mm512_or_si512(zmm3, zmm_alpha); + + _mm512_mask_storeu_epi32(dst_argb, (__mmask16)dst_mask, zmm0); + _mm512_mask_storeu_epi32(dst_argb + 64, (__mmask16)(dst_mask >> 16), zmm1); + _mm512_mask_storeu_epi32(dst_argb + 128, (__mmask16)(dst_mask >> 32), zmm2); + _mm512_mask_storeu_epi32(dst_argb + 192, (__mmask16)(dst_mask >> 48), zmm3); + } + _mm256_zeroupper(); +} +#endif // defined(HAS_RAWTOARGBROW_AVX512BW) || + // defined(HAS_RGB24TOARGBROW_AVX512BW) + +#ifdef HAS_RAWTOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void RAWToARGBRow_AVX512BW(const uint8_t* src_raw, + uint8_t* dst_argb, + int width) { + RGBToARGBRow_AVX512BW(src_raw, dst_argb, + (const uint32_t*)kShuffleMaskRAWToARGB_AVX512BW, width); +} +#endif // HAS_RAWTOARGBROW_AVX512BW + +#ifdef HAS_RGB24TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void RGB24ToARGBRow_AVX512BW(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width) { + RGBToARGBRow_AVX512BW(src_rgb24, dst_argb, + (const uint32_t*)kShuffleMaskRGB24ToARGB_AVX512BW, + width); +} +#endif // HAS_RGB24TOARGBROW_AVX512BW + +#ifdef HAS_RAWTORGB24ROW_SSSE3 +LIBYUV_TARGET_SSSE3 +void RAWToRGB24Row_SSSE3(const uint8_t* src_raw, + uint8_t* dst_rgb24, + int width) { + __m128i shuf0 = _mm_loadu_si128((const __m128i*)kShuffleMaskRAWToRGB24_0); + __m128i shuf1 = _mm_loadu_si128((const __m128i*)kShuffleMaskRAWToRGB24_1); + __m128i shuf2 = _mm_loadu_si128((const __m128i*)kShuffleMaskRAWToRGB24_2); + + while (width > 0) { + __m128i raw0 = _mm_loadu_si128((const __m128i*)src_raw); + __m128i raw1 = _mm_loadu_si128((const __m128i*)(src_raw + 4)); + __m128i raw2 = _mm_loadu_si128((const __m128i*)(src_raw + 8)); + + raw0 = _mm_shuffle_epi8(raw0, shuf0); + raw1 = _mm_shuffle_epi8(raw1, shuf1); + raw2 = _mm_shuffle_epi8(raw2, shuf2); + + _mm_storel_epi64((__m128i*)dst_rgb24, raw0); + _mm_storel_epi64((__m128i*)(dst_rgb24 + 8), raw1); + _mm_storel_epi64((__m128i*)(dst_rgb24 + 16), raw2); + + src_raw += 24; + dst_rgb24 += 24; + width -= 8; } } +#endif // HAS_RAWTORGB24ROW_SSSE3 + +#ifdef HAS_RAWTORGB24ROW_AVX2 +LIBYUV_TARGET_AVX2 +void RAWToRGB24Row_AVX2(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) { + __m256i ymm_shuf = + _mm256_loadu_si256((const __m256i*)kShuffleMaskRAWToRGB24_AVX2); + __m256i ymm_p0 = _mm256_loadu_si256((const __m256i*)kPermd0_AVX2); + __m256i ymm_p1 = _mm256_loadu_si256((const __m256i*)kPermd1_AVX2); + __m256i ymm_p2 = _mm256_loadu_si256((const __m256i*)kPermd2_AVX2); + + while (width > 0) { + __m256i raw0 = _mm256_loadu_si256((const __m256i*)src_raw); + __m256i raw1 = _mm256_loadu_si256((const __m256i*)(src_raw + 32)); + __m256i raw2 = _mm256_loadu_si256((const __m256i*)(src_raw + 64)); + + __m256i m01 = _mm256_permute2x128_si256(raw0, raw1, 0x21); + __m256i b0 = _mm256_permute4x64_epi64(raw0, 0x94); + __m256i m12 = _mm256_permute2x128_si256(raw1, raw2, 0x21); + __m256i b3 = _mm256_permute4x64_epi64(raw2, 0xe9); + __m256i b1 = _mm256_permute4x64_epi64(m01, 0xe9); + __m256i b2 = _mm256_permute4x64_epi64(m12, 0x94); + + b0 = _mm256_shuffle_epi8(b0, ymm_shuf); + b1 = _mm256_shuffle_epi8(b1, ymm_shuf); + b2 = _mm256_shuffle_epi8(b2, ymm_shuf); + b3 = _mm256_shuffle_epi8(b3, ymm_shuf); + + __m256i d0 = _mm256_permutevar8x32_epi32(b0, ymm_p0); + __m256i d1 = _mm256_permutevar8x32_epi32(b1, ymm_p1); + __m256i d2 = _mm256_permutevar8x32_epi32(b2, ymm_p2); + __m256i d3 = _mm256_permutevar8x32_epi32(b3, ymm_p0); + + // Dst0 = blend(d0, d1) + __m256i dst0 = _mm256_blend_epi32(d0, d1, 0xc0); + _mm256_storeu_si256((__m256i*)dst_rgb24, dst0); + + // Dst1 = blend(d1, d2) + __m256i dst1 = _mm256_blend_epi32(d1, d2, 0xf0); + d3 = _mm256_permute4x64_epi64(d3, 0x90); + _mm256_storeu_si256((__m256i*)(dst_rgb24 + 32), dst1); + + // Dst2 = blend(d2, d3) + __m256i dst2 = _mm256_blend_epi32(d2, d3, 0xfc); + _mm256_storeu_si256((__m256i*)(dst_rgb24 + 64), dst2); + + src_raw += 96; + dst_rgb24 += 96; + width -= 32; + } + _mm256_zeroupper(); +} +#endif // HAS_RAWTORGB24ROW_AVX2 + +#ifdef HAS_RAWTORGB24ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void RAWToRGB24Row_AVX512BW(const uint8_t* src_raw, + uint8_t* dst_rgb24, + int width) { + __m512i zmm_q0 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB0_AVX512BW); + __m512i zmm_q1 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB1_AVX512BW); + __m512i zmm_q2 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB2_AVX512BW); + __m512i zmm_q3 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB3_AVX512BW); + __m512i zmm_shuf = _mm512_broadcast_i64x4( + _mm256_loadu_si256((const __m256i*)kShuffleMaskRAWToRGB24_AVX2)); + __m512i zmm_d0 = _mm512_loadu_si512((const __m512i*)kPermdRGB24_0_AVX512BW); + __m512i zmm_d1 = _mm512_loadu_si512((const __m512i*)kPermdRGB24_1_AVX512BW); + __m512i zmm_d2 = _mm512_loadu_si512((const __m512i*)kPermdRGB24_2_AVX512BW); + + while (width >= 64) { + __m512i zmm_raw0 = _mm512_loadu_si512((const __m512i*)src_raw); + __m512i zmm_raw1 = _mm512_loadu_si512((const __m512i*)(src_raw + 64)); + __m512i zmm_raw2 = _mm512_loadu_si512((const __m512i*)(src_raw + 128)); + + __m512i zmm0 = PermutexvarEpi64(zmm_q0, zmm_raw0); + __m512i zmm1 = _mm512_permutex2var_epi64(zmm_raw0, zmm_q1, zmm_raw1); + __m512i zmm2 = _mm512_permutex2var_epi64(zmm_raw1, zmm_q2, zmm_raw2); + __m512i zmm3 = PermutexvarEpi64(zmm_q3, zmm_raw2); + + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + __m512i dst0 = _mm512_permutex2var_epi32(zmm0, zmm_d0, zmm1); + __m512i dst1 = _mm512_permutex2var_epi32(zmm1, zmm_d1, zmm2); + __m512i dst2 = _mm512_permutex2var_epi32(zmm2, zmm_d2, zmm3); + + _mm512_storeu_si512((__m512i*)dst_rgb24, dst0); + _mm512_storeu_si512((__m512i*)(dst_rgb24 + 64), dst1); + _mm512_storeu_si512((__m512i*)(dst_rgb24 + 128), dst2); + + src_raw += 192; + dst_rgb24 += 192; + width -= 64; + } + if (width > 0) { + int nbytes = width * 3; + __mmask64 k0 = + (nbytes >= 64) ? ~(__mmask64)0 : (__mmask64)((1ULL << nbytes) - 1ULL); + __mmask64 k1 = (nbytes <= 64) ? 0 + : (nbytes >= 128) + ? ~(__mmask64)0 + : (__mmask64)((1ULL << (nbytes - 64)) - 1ULL); + __mmask64 k2 = + (nbytes <= 128) ? 0 : (__mmask64)((1ULL << (nbytes - 128)) - 1ULL); + __m512i zmm_raw0 = _mm512_maskz_loadu_epi8(k0, src_raw); + __m512i zmm_raw1 = + k1 ? _mm512_maskz_loadu_epi8(k1, src_raw + 64) : _mm512_setzero_si512(); + __m512i zmm_raw2 = k2 ? _mm512_maskz_loadu_epi8(k2, src_raw + 128) + : _mm512_setzero_si512(); + + __m512i zmm0 = PermutexvarEpi64(zmm_q0, zmm_raw0); + __m512i zmm1 = _mm512_permutex2var_epi64(zmm_raw0, zmm_q1, zmm_raw1); + __m512i zmm2 = _mm512_permutex2var_epi64(zmm_raw1, zmm_q2, zmm_raw2); + __m512i zmm3 = PermutexvarEpi64(zmm_q3, zmm_raw2); + + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + __m512i dst0 = _mm512_permutex2var_epi32(zmm0, zmm_d0, zmm1); + __m512i dst1 = _mm512_permutex2var_epi32(zmm1, zmm_d1, zmm2); + __m512i dst2 = _mm512_permutex2var_epi32(zmm2, zmm_d2, zmm3); + + _mm512_mask_storeu_epi8(dst_rgb24, k0, dst0); + if (k1) { + _mm512_mask_storeu_epi8(dst_rgb24 + 64, k1, dst1); + } + if (k2) { + _mm512_mask_storeu_epi8(dst_rgb24 + 128, k2, dst2); + } + } + _mm256_zeroupper(); +} +#endif // HAS_RAWTORGB24ROW_AVX512BW + +#ifdef HAS_RAWTORGB24ROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void RAWToRGB24Row_AVX512VBMI(const uint8_t* src_raw, + uint8_t* dst_rgb24, + int width) { + __m512i zmm_p0 = _mm512_loadu_si512((const __m512i*)kPermRAWToRGB24_0); + __m512i zmm_p1 = _mm512_loadu_si512((const __m512i*)kPermRAWToRGB24_1); + __m512i zmm_p2 = _mm512_loadu_si512((const __m512i*)kPermRAWToRGB24_2); + __m512i zmm_p3 = _mm512_loadu_si512((const __m512i*)kPermRAWToRGB24_3); + + while (width >= 64) { + __m512i zmm_raw0 = _mm512_loadu_si512((const __m512i*)src_raw); + __m512i zmm_raw1 = _mm512_loadu_si512((const __m512i*)(src_raw + 64)); + __m512i zmm_raw2 = _mm512_loadu_si512((const __m512i*)(src_raw + 128)); + + __m512i tmp1 = _mm512_permutex2var_epi8(zmm_raw1, zmm_p1, zmm_raw0); + __m512i dst0 = _mm512_permutex2var_epi8(zmm_raw0, zmm_p0, zmm_raw1); + __m512i dst2 = _mm512_permutex2var_epi8(zmm_raw1, zmm_p3, zmm_raw2); + __m512i dst1 = _mm512_permutex2var_epi8(tmp1, zmm_p2, zmm_raw2); + + _mm512_storeu_si512((__m512i*)dst_rgb24, dst0); + _mm512_storeu_si512((__m512i*)(dst_rgb24 + 64), dst1); + _mm512_storeu_si512((__m512i*)(dst_rgb24 + 128), dst2); + + src_raw += 192; + dst_rgb24 += 192; + width -= 64; + } + if (width > 0) { + int nbytes = width * 3; + __mmask64 k0 = + (nbytes >= 64) ? ~(__mmask64)0 : (__mmask64)((1ULL << nbytes) - 1ULL); + __mmask64 k1 = (nbytes <= 64) ? 0 + : (nbytes >= 128) + ? ~(__mmask64)0 + : (__mmask64)((1ULL << (nbytes - 64)) - 1ULL); + __mmask64 k2 = + (nbytes <= 128) ? 0 : (__mmask64)((1ULL << (nbytes - 128)) - 1ULL); + __m512i zmm_raw0 = _mm512_maskz_loadu_epi8(k0, src_raw); + __m512i zmm_raw1 = + k1 ? _mm512_maskz_loadu_epi8(k1, src_raw + 64) : _mm512_setzero_si512(); + __m512i zmm_raw2 = k2 ? _mm512_maskz_loadu_epi8(k2, src_raw + 128) + : _mm512_setzero_si512(); + + __m512i tmp1 = _mm512_permutex2var_epi8(zmm_raw1, zmm_p1, zmm_raw0); + __m512i dst0 = _mm512_permutex2var_epi8(zmm_raw0, zmm_p0, zmm_raw1); + __m512i dst2 = _mm512_permutex2var_epi8(zmm_raw1, zmm_p3, zmm_raw2); + __m512i dst1 = _mm512_permutex2var_epi8(tmp1, zmm_p2, zmm_raw2); + + _mm512_mask_storeu_epi8(dst_rgb24, k0, dst0); + if (k1) { + _mm512_mask_storeu_epi8(dst_rgb24 + 64, k1, dst1); + } + if (k2) { + _mm512_mask_storeu_epi8(dst_rgb24 + 128, k2, dst2); + } + } + _mm256_zeroupper(); +} +#endif // HAS_RAWTORGB24ROW_AVX512VBMI + +#if defined(HAS_RGBTOYMATRIXROW_AVX512BW) || \ + defined(HAS_ARGBTOYMATRIXROW_AVX512BW) || \ + defined(HAS_ARGBTOUV444MATRIXROW_AVX512BW) || \ + defined(HAS_ARGBTOUVMATRIXROW_AVX512BW) || \ + defined(HAS_ARGBTOYMATRIXROW_AVX512VNNI) || \ + defined(HAS_ARGBTOUV444MATRIXROW_AVX512VNNI) || \ + defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNI) +static const uint32_t kPermdARGBToY_AVX512BW[16] = {0, 4, 8, 12, 1, 5, 9, 13, + 2, 6, 10, 14, 3, 7, 11, 15}; +#endif + +#ifdef HAS_RGBTOYMATRIXROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void RGBToYMatrixRow_AVX512BW(const uint8_t* src_rgb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + __m512i zmm_q0 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB0_AVX512BW); + __m512i zmm_q1 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB1_AVX512BW); + __m512i zmm_q2 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB2_AVX512BW); + __m512i zmm_q3 = + _mm512_loadu_si512((const __m512i*)kPermqRGB24ToARGB3_AVX512BW); + __m512i zmm_shuf = _mm512_broadcast_i64x4( + _mm256_loadu_si256((const __m256i*)kShuffleMaskRGB24ToARGB_AVX512BW)); + __m512i zmm_perm_y = + _mm512_loadu_si512((const __m512i*)kPermdARGBToY_AVX512BW); + + __m512i zmm_80 = _mm512_set1_epi8((char)0x80); + __m512i zmm_one = _mm512_set1_epi16(1); + __m512i zmm_coeff = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToY)); + __m512i zmm_add = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kAddY)); + + // Compute bias adjusted for 0x80 subtraction: + // bias = kAddY - pmaddwd(pmaddubsw(kRGBToY, 0x80), 1) + __m512i zmm_bias = _mm512_maddubs_epi16(zmm_coeff, zmm_80); + zmm_bias = _mm512_madd_epi16(zmm_bias, zmm_one); + zmm_bias = _mm512_packs_epi32(zmm_bias, zmm_bias); + zmm_add = _mm512_sub_epi16(zmm_add, zmm_bias); + + while (width >= 64) { + __m512i zmm_raw0 = _mm512_loadu_si512((const __m512i*)src_rgb); + __m512i zmm_raw1 = _mm512_loadu_si512((const __m512i*)(src_rgb + 64)); + __m512i zmm_raw2 = _mm512_loadu_si512((const __m512i*)(src_rgb + 128)); + + __m512i zmm0 = PermutexvarEpi64(zmm_q0, zmm_raw0); + __m512i zmm1 = _mm512_permutex2var_epi64(zmm_raw0, zmm_q1, zmm_raw1); + __m512i zmm2 = _mm512_permutex2var_epi64(zmm_raw1, zmm_q2, zmm_raw2); + __m512i zmm3 = PermutexvarEpi64(zmm_q3, zmm_raw2); + + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + zmm0 = _mm512_xor_si512(zmm0, zmm_80); + zmm1 = _mm512_xor_si512(zmm1, zmm_80); + zmm2 = _mm512_xor_si512(zmm2, zmm_80); + zmm3 = _mm512_xor_si512(zmm3, zmm_80); + + zmm0 = _mm512_maddubs_epi16(zmm_coeff, zmm0); + zmm1 = _mm512_maddubs_epi16(zmm_coeff, zmm1); + zmm2 = _mm512_maddubs_epi16(zmm_coeff, zmm2); + zmm3 = _mm512_maddubs_epi16(zmm_coeff, zmm3); + + zmm0 = _mm512_madd_epi16(zmm0, zmm_one); + zmm1 = _mm512_madd_epi16(zmm1, zmm_one); + zmm0 = _mm512_packs_epi32(zmm0, zmm1); + + zmm2 = _mm512_madd_epi16(zmm2, zmm_one); + zmm3 = _mm512_madd_epi16(zmm3, zmm_one); + zmm2 = _mm512_packs_epi32(zmm2, zmm3); + + zmm0 = _mm512_add_epi16(zmm0, zmm_add); + zmm2 = _mm512_add_epi16(zmm2, zmm_add); + + zmm0 = _mm512_srli_epi16(zmm0, 8); + zmm2 = _mm512_srli_epi16(zmm2, 8); + + zmm0 = _mm512_packus_epi16(zmm0, zmm2); + zmm0 = PermutexvarEpi32(zmm_perm_y, zmm0); + + _mm512_storeu_si512((__m512i*)dst_y, zmm0); + + src_rgb += 192; + dst_y += 64; + width -= 64; + } + if (width > 0) { + __mmask64 ky = (__mmask64)((1ULL << width) - 1ULL); + int nbytes = width * 3; + __mmask64 k0 = + (nbytes >= 64) ? ~(__mmask64)0 : (__mmask64)((1ULL << nbytes) - 1ULL); + __mmask64 k1 = (nbytes <= 64) ? 0 + : (nbytes >= 128) + ? ~(__mmask64)0 + : (__mmask64)((1ULL << (nbytes - 64)) - 1ULL); + __mmask64 k2 = + (nbytes <= 128) ? 0 : (__mmask64)((1ULL << (nbytes - 128)) - 1ULL); + __m512i zmm_raw0 = _mm512_maskz_loadu_epi8(k0, src_rgb); + __m512i zmm_raw1 = + k1 ? _mm512_maskz_loadu_epi8(k1, src_rgb + 64) : _mm512_setzero_si512(); + __m512i zmm_raw2 = k2 ? _mm512_maskz_loadu_epi8(k2, src_rgb + 128) + : _mm512_setzero_si512(); + + __m512i zmm0 = PermutexvarEpi64(zmm_q0, zmm_raw0); + __m512i zmm1 = _mm512_permutex2var_epi64(zmm_raw0, zmm_q1, zmm_raw1); + __m512i zmm2 = _mm512_permutex2var_epi64(zmm_raw1, zmm_q2, zmm_raw2); + __m512i zmm3 = PermutexvarEpi64(zmm_q3, zmm_raw2); + + zmm0 = _mm512_xor_si512(_mm512_shuffle_epi8(zmm0, zmm_shuf), zmm_80); + zmm1 = _mm512_xor_si512(_mm512_shuffle_epi8(zmm1, zmm_shuf), zmm_80); + zmm2 = _mm512_xor_si512(_mm512_shuffle_epi8(zmm2, zmm_shuf), zmm_80); + zmm3 = _mm512_xor_si512(_mm512_shuffle_epi8(zmm3, zmm_shuf), zmm_80); + + zmm0 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm0), zmm_one); + zmm1 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm1), zmm_one); + zmm0 = _mm512_packs_epi32(zmm0, zmm1); + + zmm2 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm2), zmm_one); + zmm3 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm3), zmm_one); + zmm2 = _mm512_packs_epi32(zmm2, zmm3); + + zmm0 = _mm512_srli_epi16(_mm512_add_epi16(zmm0, zmm_add), 8); + zmm2 = _mm512_srli_epi16(_mm512_add_epi16(zmm2, zmm_add), 8); + + zmm0 = PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(zmm0, zmm2)); + _mm512_mask_storeu_epi8(dst_y, ky, zmm0); + } + _mm256_zeroupper(); +} +#endif // HAS_RGBTOYMATRIXROW_AVX512BW + +#ifdef HAS_ARGBTOYMATRIXROW_AVX512VNNI +LIBYUV_TARGET_AVX512VNNI +void ARGBToYMatrixRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + __m512i zmm_perm_y = + _mm512_loadu_si512((const __m512i*)kPermdARGBToY_AVX512BW); + __m512i zmm_80 = _mm512_set1_epi8((char)0x80); + __m512i zmm_coeff = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToY)); + __m512i zmm_add = + _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i*)c->kAddY)); + + __m512i zmm_bias = + _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_coeff, zmm_80); + zmm_add = _mm512_sub_epi32(zmm_add, zmm_bias); + + while (width >= 64) { + __m512i zmm0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i zmm1 = _mm512_loadu_si512((const __m512i*)(src_argb + 64)); + __m512i zmm2 = _mm512_loadu_si512((const __m512i*)(src_argb + 128)); + __m512i zmm3 = _mm512_loadu_si512((const __m512i*)(src_argb + 192)); + + zmm0 = _mm512_xor_si512(zmm0, zmm_80); + zmm1 = _mm512_xor_si512(zmm1, zmm_80); + zmm2 = _mm512_xor_si512(zmm2, zmm_80); + zmm3 = _mm512_xor_si512(zmm3, zmm_80); + + zmm0 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm0); + zmm1 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm1); + zmm2 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm2); + zmm3 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm3); + + zmm0 = _mm512_packus_epi32(zmm0, zmm1); + zmm2 = _mm512_packus_epi32(zmm2, zmm3); + + zmm0 = _mm512_srli_epi16(zmm0, 8); + zmm2 = _mm512_srli_epi16(zmm2, 8); + + zmm0 = _mm512_packus_epi16(zmm0, zmm2); + zmm0 = PermutexvarEpi32(zmm_perm_y, zmm0); + + _mm512_storeu_si512((__m512i*)dst_y, zmm0); + + src_argb += 256; + dst_y += 64; + width -= 64; + } + if (width > 0) { + uint64_t mask = (1ULL << width) - 1ULL; + __mmask16 k0 = (__mmask16)mask; + __mmask16 k1 = (__mmask16)(mask >> 16); + __mmask16 k2 = (__mmask16)(mask >> 32); + __mmask16 k3 = (__mmask16)(mask >> 48); + __m512i zmm0 = + _mm512_xor_si512(_mm512_maskz_loadu_epi32(k0, src_argb), zmm_80); + __m512i zmm1 = + _mm512_xor_si512(k1 ? _mm512_maskz_loadu_epi32(k1, src_argb + 64) + : _mm512_setzero_si512(), + zmm_80); + __m512i zmm2 = + _mm512_xor_si512(k2 ? _mm512_maskz_loadu_epi32(k2, src_argb + 128) + : _mm512_setzero_si512(), + zmm_80); + __m512i zmm3 = + _mm512_xor_si512(k3 ? _mm512_maskz_loadu_epi32(k3, src_argb + 192) + : _mm512_setzero_si512(), + zmm_80); + + zmm0 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm0); + zmm1 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm1); + zmm2 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm2); + zmm3 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm3); + + zmm0 = _mm512_srli_epi16(_mm512_packus_epi32(zmm0, zmm1), 8); + zmm2 = _mm512_srli_epi16(_mm512_packus_epi32(zmm2, zmm3), 8); + + zmm0 = PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(zmm0, zmm2)); + _mm512_mask_storeu_epi8(dst_y, (__mmask64)mask, zmm0); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOYMATRIXROW_AVX512VNNI + +#if defined(HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI) || \ + defined(HAS_ARGBTOUV444MATRIXROW_AVX512VNNIVBMI) || \ + defined(HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI) +// AVX512VNNIVBMI kernels use both AVX512VNNI (vpdpbusd) and AVX512VBMI +// (vpermt2b) and require both CPU features. There are no AVX512VBMI +// versions without AVX512VNNI. + +// vpermt2b indices selecting byte 1 of each int32 from 2 vectors. The 32 +// byte pattern is broadcast so each 256 bit half holds the same 32 results. +// Clang constant folds the indices and lowers _mm512_permutex2var_epi8 to a +// longer vpshufb + vpor + vpermd sequence, so hide the indices from it. +#if defined(__clang__) +#define LIBYUV_HIDE_CONSTANT(v) __asm__("" : "+v"(v)) +#else +#define LIBYUV_HIDE_CONSTANT(v) +#endif +static const uint8_t kPermbDWordByte1_AVX512VNNIVBMI[32] = { + 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, + 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125}; +#endif + +#ifdef HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI +// Requires AVX512VNNI and AVX512VBMI. +// The 32 bit sums are kAddY + dot(kRGBToY, argb) which is always in +// [0, 65535], so Y is byte 1 of each int32 and no saturation is needed. +LIBYUV_TARGET_AVX512VNNIVBMI +void ARGBToYMatrixRow_AVX512VNNIVBMI(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + __m512i zmm_perm = _mm512_broadcast_i64x4( + _mm256_loadu_si256((const __m256i*)kPermbDWordByte1_AVX512VNNIVBMI)); + LIBYUV_HIDE_CONSTANT(zmm_perm); + __m512i zmm_80 = _mm512_set1_epi8((char)0x80); + __m512i zmm_coeff = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToY)); + __m512i zmm_add = + _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i*)c->kAddY)); + + __m512i zmm_bias = + _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_coeff, zmm_80); + zmm_add = _mm512_sub_epi32(zmm_add, zmm_bias); + + while (width >= 64) { + __m512i zmm0 = + _mm512_xor_si512(_mm512_loadu_si512((const __m512i*)src_argb), zmm_80); + __m512i zmm1 = _mm512_xor_si512( + _mm512_loadu_si512((const __m512i*)(src_argb + 64)), zmm_80); + __m512i zmm2 = _mm512_xor_si512( + _mm512_loadu_si512((const __m512i*)(src_argb + 128)), zmm_80); + __m512i zmm3 = _mm512_xor_si512( + _mm512_loadu_si512((const __m512i*)(src_argb + 192)), zmm_80); + + zmm0 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm0); + zmm1 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm1); + zmm2 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm2); + zmm3 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm3); + + zmm0 = _mm512_permutex2var_epi8(zmm0, zmm_perm, zmm1); // Y 0..31 + zmm2 = _mm512_permutex2var_epi8(zmm2, zmm_perm, zmm3); // Y 32..63 + + _mm256_storeu_si256((__m256i*)dst_y, _mm512_castsi512_si256(zmm0)); + _mm256_storeu_si256((__m256i*)(dst_y + 32), _mm512_castsi512_si256(zmm2)); + + src_argb += 256; + dst_y += 64; + width -= 64; + } + if (width > 0) { + uint64_t mask = (1ULL << width) - 1ULL; + __mmask16 k0 = (__mmask16)mask; + __mmask16 k1 = (__mmask16)(mask >> 16); + __mmask16 k2 = (__mmask16)(mask >> 32); + __mmask16 k3 = (__mmask16)(mask >> 48); + __m512i zmm0 = + _mm512_xor_si512(_mm512_maskz_loadu_epi32(k0, src_argb), zmm_80); + __m512i zmm1 = + _mm512_xor_si512(k1 ? _mm512_maskz_loadu_epi32(k1, src_argb + 64) + : _mm512_setzero_si512(), + zmm_80); + __m512i zmm2 = + _mm512_xor_si512(k2 ? _mm512_maskz_loadu_epi32(k2, src_argb + 128) + : _mm512_setzero_si512(), + zmm_80); + __m512i zmm3 = + _mm512_xor_si512(k3 ? _mm512_maskz_loadu_epi32(k3, src_argb + 192) + : _mm512_setzero_si512(), + zmm_80); + + zmm0 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm0); + zmm1 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm1); + zmm2 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm2); + zmm3 = _mm512_dpbusd_epi32(zmm_add, zmm_coeff, zmm3); + + zmm0 = _mm512_permutex2var_epi8(zmm0, zmm_perm, zmm1); + zmm2 = _mm512_permutex2var_epi8(zmm2, zmm_perm, zmm3); + + _mm256_mask_storeu_epi8(dst_y, (__mmask32)mask, + _mm512_castsi512_si256(zmm0)); + if (mask >> 32) { + _mm256_mask_storeu_epi8(dst_y + 32, (__mmask32)(mask >> 32), + _mm512_castsi512_si256(zmm2)); + } + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOYMATRIXROW_AVX512VNNIVBMI + +#ifdef HAS_ARGBTOUV444MATRIXROW_AVX512VNNI +LIBYUV_TARGET_AVX512VNNI +void ARGBToUV444MatrixRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + __m512i zmm_u = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToU)); + __m512i zmm_v = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToV)); + __m512i zmm_8000 = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kAddUV)); + __m512i zmm_perm_y = + _mm512_loadu_si512((const __m512i*)kPermdARGBToY_AVX512BW); + + while (width >= 64) { + __m512i zmm_s0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i zmm_s1 = _mm512_loadu_si512((const __m512i*)(src_argb + 64)); + __m512i zmm_s2 = _mm512_loadu_si512((const __m512i*)(src_argb + 128)); + __m512i zmm_s3 = _mm512_loadu_si512((const __m512i*)(src_argb + 192)); + + __m512i zmm0 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s0, zmm_u); + __m512i zmm1 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s1, zmm_u); + __m512i zmm2 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s2, zmm_u); + __m512i zmm3 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s3, zmm_u); + + zmm0 = _mm512_packs_epi32(zmm0, zmm1); + zmm2 = _mm512_packs_epi32(zmm2, zmm3); + zmm0 = _mm512_sub_epi16(zmm_8000, zmm0); + zmm2 = _mm512_sub_epi16(zmm_8000, zmm2); + zmm0 = _mm512_srli_epi16(zmm0, 8); + zmm2 = _mm512_srli_epi16(zmm2, 8); + zmm0 = _mm512_packus_epi16(zmm0, zmm2); + zmm0 = PermutexvarEpi32(zmm_perm_y, zmm0); + _mm512_storeu_si512((__m512i*)dst_u, zmm0); + + zmm0 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s0, zmm_v); + zmm1 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s1, zmm_v); + zmm2 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s2, zmm_v); + zmm3 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s3, zmm_v); + + zmm0 = _mm512_packs_epi32(zmm0, zmm1); + zmm2 = _mm512_packs_epi32(zmm2, zmm3); + zmm0 = _mm512_sub_epi16(zmm_8000, zmm0); + zmm2 = _mm512_sub_epi16(zmm_8000, zmm2); + zmm0 = _mm512_srli_epi16(zmm0, 8); + zmm2 = _mm512_srli_epi16(zmm2, 8); + zmm0 = _mm512_packus_epi16(zmm0, zmm2); + zmm0 = PermutexvarEpi32(zmm_perm_y, zmm0); + _mm512_storeu_si512((__m512i*)dst_v, zmm0); + + src_argb += 256; + dst_u += 64; + dst_v += 64; + width -= 64; + } + if (width > 0) { + uint64_t mask = (1ULL << width) - 1ULL; + __mmask16 k0 = (__mmask16)mask; + __mmask16 k1 = (__mmask16)(mask >> 16); + __mmask16 k2 = (__mmask16)(mask >> 32); + __mmask16 k3 = (__mmask16)(mask >> 48); + __m512i zmm_s0 = _mm512_maskz_loadu_epi32(k0, src_argb); + __m512i zmm_s1 = k1 ? _mm512_maskz_loadu_epi32(k1, src_argb + 64) + : _mm512_setzero_si512(); + __m512i zmm_s2 = k2 ? _mm512_maskz_loadu_epi32(k2, src_argb + 128) + : _mm512_setzero_si512(); + __m512i zmm_s3 = k3 ? _mm512_maskz_loadu_epi32(k3, src_argb + 192) + : _mm512_setzero_si512(); + + __m512i zmm0 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s0, zmm_u); + __m512i zmm1 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s1, zmm_u); + __m512i zmm2 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s2, zmm_u); + __m512i zmm3 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s3, zmm_u); + + zmm0 = _mm512_srli_epi16( + _mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(zmm0, zmm1)), 8); + zmm2 = _mm512_srli_epi16( + _mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(zmm2, zmm3)), 8); + zmm0 = PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(zmm0, zmm2)); + _mm512_mask_storeu_epi8(dst_u, (__mmask64)mask, zmm0); + + zmm0 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s0, zmm_v); + zmm1 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s1, zmm_v); + zmm2 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s2, zmm_v); + zmm3 = _mm512_dpbusd_epi32(_mm512_setzero_si512(), zmm_s3, zmm_v); + + zmm0 = _mm512_srli_epi16( + _mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(zmm0, zmm1)), 8); + zmm2 = _mm512_srli_epi16( + _mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(zmm2, zmm3)), 8); + zmm0 = PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(zmm0, zmm2)); + _mm512_mask_storeu_epi8(dst_v, (__mmask64)mask, zmm0); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOUV444MATRIXROW_AVX512VNNI + +#ifdef HAS_ARGBTOUV444MATRIXROW_AVX512VNNIVBMI +// Requires AVX512VNNI and AVX512VBMI. +// U = (kAddUV - dot(kRGBToU, argb)) >> 8. The accumulators start at +// ~kAddUV so they hold ~(kAddUV - dot) and U is the inverse of byte 1 of each +// int32. +LIBYUV_TARGET_AVX512VNNIVBMI +void ARGBToUV444MatrixRow_AVX512VNNIVBMI(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + __m512i zmm_perm = _mm512_broadcast_i64x4( + _mm256_loadu_si256((const __m256i*)kPermbDWordByte1_AVX512VNNIVBMI)); + LIBYUV_HIDE_CONSTANT(zmm_perm); + __m512i zmm_u = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToU)); + __m512i zmm_v = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToV)); + const __m512i zmm_neg1 = _mm512_set1_epi32(-1); + __m512i zmm_add = _mm512_xor_si512( + _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i*)c->kAddUV)), + zmm_neg1); // ~kAddUV + + while (width >= 64) { + __m512i zmm_s0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i zmm_s1 = _mm512_loadu_si512((const __m512i*)(src_argb + 64)); + __m512i zmm_s2 = _mm512_loadu_si512((const __m512i*)(src_argb + 128)); + __m512i zmm_s3 = _mm512_loadu_si512((const __m512i*)(src_argb + 192)); + + __m512i zmm0 = _mm512_dpbusd_epi32(zmm_add, zmm_s0, zmm_u); + __m512i zmm1 = _mm512_dpbusd_epi32(zmm_add, zmm_s1, zmm_u); + __m512i zmm2 = _mm512_dpbusd_epi32(zmm_add, zmm_s2, zmm_u); + __m512i zmm3 = _mm512_dpbusd_epi32(zmm_add, zmm_s3, zmm_u); + __m512i zmm4 = _mm512_dpbusd_epi32(zmm_add, zmm_s0, zmm_v); + __m512i zmm5 = _mm512_dpbusd_epi32(zmm_add, zmm_s1, zmm_v); + __m512i zmm6 = _mm512_dpbusd_epi32(zmm_add, zmm_s2, zmm_v); + __m512i zmm7 = _mm512_dpbusd_epi32(zmm_add, zmm_s3, zmm_v); + + zmm0 = _mm512_permutex2var_epi8(zmm0, zmm_perm, zmm1); // ~U 0..31 + zmm2 = _mm512_permutex2var_epi8(zmm2, zmm_perm, zmm3); // ~U 32..63 + zmm4 = _mm512_permutex2var_epi8(zmm4, zmm_perm, zmm5); // ~V 0..31 + zmm6 = _mm512_permutex2var_epi8(zmm6, zmm_perm, zmm7); // ~V 32..63 + // Avoid _mm512_ternarylogic_epi32 (unmodeled by LLVM MSan; see GEMINI.md). + zmm0 = _mm512_xor_si512(_mm512_shuffle_i64x2(zmm0, zmm2, 0x44), + zmm_neg1); // U + zmm4 = _mm512_xor_si512(_mm512_shuffle_i64x2(zmm4, zmm6, 0x44), + zmm_neg1); // V + + _mm512_storeu_si512((__m512i*)dst_u, zmm0); + _mm512_storeu_si512((__m512i*)dst_v, zmm4); + + src_argb += 256; + dst_u += 64; + dst_v += 64; + width -= 64; + } + if (width > 0) { + uint64_t mask = (1ULL << width) - 1ULL; + __mmask16 k0 = (__mmask16)mask; + __mmask16 k1 = (__mmask16)(mask >> 16); + __mmask16 k2 = (__mmask16)(mask >> 32); + __mmask16 k3 = (__mmask16)(mask >> 48); + __m512i zmm_s0 = _mm512_maskz_loadu_epi32(k0, src_argb); + __m512i zmm_s1 = k1 ? _mm512_maskz_loadu_epi32(k1, src_argb + 64) + : _mm512_setzero_si512(); + __m512i zmm_s2 = k2 ? _mm512_maskz_loadu_epi32(k2, src_argb + 128) + : _mm512_setzero_si512(); + __m512i zmm_s3 = k3 ? _mm512_maskz_loadu_epi32(k3, src_argb + 192) + : _mm512_setzero_si512(); + + __m512i zmm0 = _mm512_dpbusd_epi32(zmm_add, zmm_s0, zmm_u); + __m512i zmm1 = _mm512_dpbusd_epi32(zmm_add, zmm_s1, zmm_u); + __m512i zmm2 = _mm512_dpbusd_epi32(zmm_add, zmm_s2, zmm_u); + __m512i zmm3 = _mm512_dpbusd_epi32(zmm_add, zmm_s3, zmm_u); + __m512i zmm4 = _mm512_dpbusd_epi32(zmm_add, zmm_s0, zmm_v); + __m512i zmm5 = _mm512_dpbusd_epi32(zmm_add, zmm_s1, zmm_v); + __m512i zmm6 = _mm512_dpbusd_epi32(zmm_add, zmm_s2, zmm_v); + __m512i zmm7 = _mm512_dpbusd_epi32(zmm_add, zmm_s3, zmm_v); + + zmm0 = _mm512_permutex2var_epi8(zmm0, zmm_perm, zmm1); + zmm2 = _mm512_permutex2var_epi8(zmm2, zmm_perm, zmm3); + zmm4 = _mm512_permutex2var_epi8(zmm4, zmm_perm, zmm5); + zmm6 = _mm512_permutex2var_epi8(zmm6, zmm_perm, zmm7); + zmm0 = _mm512_xor_si512( + _mm512_inserti64x4(zmm0, _mm512_castsi512_si256(zmm2), 1), zmm_neg1); + zmm4 = _mm512_xor_si512( + _mm512_inserti64x4(zmm4, _mm512_castsi512_si256(zmm6), 1), zmm_neg1); + + _mm512_mask_storeu_epi8(dst_u, (__mmask64)mask, zmm0); + _mm512_mask_storeu_epi8(dst_v, (__mmask64)mask, zmm4); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOUV444MATRIXROW_AVX512VNNIVBMI + +#ifdef HAS_ARGBTOUVMATRIXROW_AVX512VNNI +LIBYUV_TARGET_AVX512VNNI +void ARGBToUVMatrixRow_AVX512VNNI(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + static const uint32_t kPermdARGBToUV_AVX512BW[16] = { + 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15}; + static const uint8_t kShuffleAARRGGBB_AVX512[16] = { + 0, 4, 1, 5, 2, 6, 3, 7, 8, 12, 9, 13, 10, 14, 11, 15}; + __m512i zmm_u = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToU)); + __m512i zmm_v = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToV)); + __m512i zmm_0101 = _mm512_set1_epi16(0x0101); + __m512i zmm_8000 = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kAddUV)); + __m512i zmm_zero = _mm512_setzero_si512(); + __m512i zmm_shuf = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)kShuffleAARRGGBB_AVX512)); + __m512i zmm_perm_y = + _mm512_loadu_si512((const __m512i*)kPermdARGBToY_AVX512BW); + __m512i zmm_perm_uv = + _mm512_loadu_si512((const __m512i*)kPermdARGBToUV_AVX512BW); + + while (width >= 32) { + __m512i zmm0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i zmm1 = _mm512_loadu_si512((const __m512i*)(src_argb + 64)); + __m512i zmm2 = + _mm512_loadu_si512((const __m512i*)(src_argb + src_stride_argb)); + __m512i zmm3 = + _mm512_loadu_si512((const __m512i*)(src_argb + src_stride_argb + 64)); + + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + zmm0 = _mm512_maddubs_epi16(zmm0, zmm_0101); + zmm1 = _mm512_maddubs_epi16(zmm1, zmm_0101); + zmm2 = _mm512_maddubs_epi16(zmm2, zmm_0101); + zmm3 = _mm512_maddubs_epi16(zmm3, zmm_0101); + + zmm0 = _mm512_add_epi16(zmm0, zmm2); + zmm1 = _mm512_add_epi16(zmm1, zmm3); + + zmm0 = _mm512_srli_epi16(zmm0, 1); + zmm1 = _mm512_srli_epi16(zmm1, 1); + zmm0 = _mm512_avg_epu16(zmm0, zmm_zero); + zmm1 = _mm512_avg_epu16(zmm1, zmm_zero); + + zmm0 = _mm512_packus_epi16(zmm0, zmm1); + zmm0 = PermutexvarEpi32(zmm_perm_uv, zmm0); + + zmm1 = _mm512_dpbusd_epi32(zmm_zero, zmm0, zmm_u); + zmm2 = _mm512_dpbusd_epi32(zmm_zero, zmm0, zmm_v); + zmm0 = _mm512_packs_epi32(zmm1, zmm2); + zmm0 = _mm512_sub_epi16(zmm_8000, zmm0); + zmm0 = _mm512_srli_epi16(zmm0, 8); + zmm0 = _mm512_packus_epi16(zmm0, zmm0); + zmm0 = PermutexvarEpi32(zmm_perm_y, zmm0); + + _mm_storeu_si128((__m128i*)dst_u, _mm512_castsi512_si128(zmm0)); + _mm_storeu_si128((__m128i*)dst_v, _mm512_extracti32x4_epi32(zmm0, 1)); + + src_argb += 128; + dst_u += 16; + dst_v += 16; + width -= 32; + } + if (width > 0) { + uint32_t mask = (1u << width) - 1u; + __mmask16 k1 = (__mmask16)mask; + __mmask16 k2 = (__mmask16)(mask >> 16); + __mmask16 k3 = ~k1; + __mmask16 k4 = ~k2; + __m512i zmm0 = _mm512_maskz_loadu_epi32(k1, src_argb); + __m512i zmm1 = _mm512_maskz_loadu_epi32(k2, src_argb + 64); + __m512i zmm2 = _mm512_maskz_loadu_epi32(k1, src_argb + src_stride_argb); + __m512i zmm3 = + _mm512_maskz_loadu_epi32(k2, src_argb + src_stride_argb + 64); + + zmm0 = _mm512_mask_shuffle_epi32(zmm0, k3, zmm0, (_MM_PERM_ENUM)0xa0); + zmm1 = _mm512_mask_shuffle_epi32(zmm1, k4, zmm1, (_MM_PERM_ENUM)0xa0); + zmm2 = _mm512_mask_shuffle_epi32(zmm2, k3, zmm2, (_MM_PERM_ENUM)0xa0); + zmm3 = _mm512_mask_shuffle_epi32(zmm3, k4, zmm3, (_MM_PERM_ENUM)0xa0); + + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + zmm0 = _mm512_maddubs_epi16(zmm0, zmm_0101); + zmm1 = _mm512_maddubs_epi16(zmm1, zmm_0101); + zmm2 = _mm512_maddubs_epi16(zmm2, zmm_0101); + zmm3 = _mm512_maddubs_epi16(zmm3, zmm_0101); + + zmm0 = _mm512_add_epi16(zmm0, zmm2); + zmm1 = _mm512_add_epi16(zmm1, zmm3); + + zmm0 = _mm512_srli_epi16(zmm0, 1); + zmm1 = _mm512_srli_epi16(zmm1, 1); + zmm0 = _mm512_avg_epu16(zmm0, zmm_zero); + zmm1 = _mm512_avg_epu16(zmm1, zmm_zero); + + zmm0 = _mm512_packus_epi16(zmm0, zmm1); + zmm0 = PermutexvarEpi32(zmm_perm_uv, zmm0); + + zmm1 = _mm512_dpbusd_epi32(zmm_zero, zmm0, zmm_u); + zmm2 = _mm512_dpbusd_epi32(zmm_zero, zmm0, zmm_v); + zmm0 = _mm512_packs_epi32(zmm1, zmm2); + zmm0 = _mm512_sub_epi16(zmm_8000, zmm0); + zmm0 = _mm512_srli_epi16(zmm0, 8); + zmm0 = _mm512_packus_epi16(zmm0, zmm0); + zmm0 = PermutexvarEpi32(zmm_perm_y, zmm0); + + int halfwidth = (width + 1) >> 1; + __mmask16 k_out = (__mmask16)((1u << halfwidth) - 1u); + _mm_mask_storeu_epi8(dst_u, k_out, _mm512_castsi512_si128(zmm0)); + _mm_mask_storeu_epi8(dst_v, k_out, _mm512_extracti32x4_epi32(zmm0, 1)); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOUVMATRIXROW_AVX512VNNI + +#ifdef HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI +// Requires AVX512VNNI and AVX512VBMI. +LIBYUV_TARGET_AVX512VNNIVBMI +void ARGBToUVMatrixRow_AVX512VNNIVBMI(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + static const uint32_t kPermdARGBToUV_AVX512BW[16] = { + 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15}; + static const uint8_t kShuffleAARRGGBB_AVX512[16] = { + 0, 4, 1, 5, 2, 6, 3, 7, 8, 12, 9, 13, 10, 14, 11, 15}; + __m512i zmm_u = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToU)); + __m512i zmm_v = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToV)); + __m512i zmm_0101 = _mm512_set1_epi16(0x0101); + __m512i zmm_add = _mm512_xor_si512( + _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i*)c->kAddUV)), + _mm512_set1_epi32(-1)); // ~kAddUV + __m512i zmm_zero = _mm512_setzero_si512(); + __m512i zmm_shuf = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)kShuffleAARRGGBB_AVX512)); + __m512i zmm_perm = _mm512_broadcast_i64x4( + _mm256_loadu_si256((const __m256i*)kPermbDWordByte1_AVX512VNNIVBMI)); + LIBYUV_HIDE_CONSTANT(zmm_perm); + __m512i zmm_perm_uv = + _mm512_loadu_si512((const __m512i*)kPermdARGBToUV_AVX512BW); + + while (width >= 32) { + __m512i zmm0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i zmm1 = _mm512_loadu_si512((const __m512i*)(src_argb + 64)); + __m512i zmm2 = + _mm512_loadu_si512((const __m512i*)(src_argb + src_stride_argb)); + __m512i zmm3 = + _mm512_loadu_si512((const __m512i*)(src_argb + src_stride_argb + 64)); + + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + zmm0 = _mm512_maddubs_epi16(zmm0, zmm_0101); + zmm1 = _mm512_maddubs_epi16(zmm1, zmm_0101); + zmm2 = _mm512_maddubs_epi16(zmm2, zmm_0101); + zmm3 = _mm512_maddubs_epi16(zmm3, zmm_0101); + + zmm0 = _mm512_add_epi16(zmm0, zmm2); + zmm1 = _mm512_add_epi16(zmm1, zmm3); + + zmm0 = _mm512_srli_epi16(zmm0, 1); + zmm1 = _mm512_srli_epi16(zmm1, 1); + zmm0 = _mm512_avg_epu16(zmm0, zmm_zero); + zmm1 = _mm512_avg_epu16(zmm1, zmm_zero); + + zmm0 = _mm512_packus_epi16(zmm0, zmm1); + zmm0 = PermutexvarEpi32(zmm_perm_uv, zmm0); + + zmm1 = _mm512_dpbusd_epi32(zmm_add, zmm0, zmm_u); // ~U + zmm2 = _mm512_dpbusd_epi32(zmm_add, zmm0, zmm_v); // ~V + zmm0 = _mm512_permutex2var_epi8(zmm1, zmm_perm, zmm2); + __m256i ymm_uv = + _mm256_xor_si256(_mm512_castsi512_si256(zmm0), _mm256_set1_epi32(-1)); + + _mm_storeu_si128((__m128i*)dst_u, _mm256_castsi256_si128(ymm_uv)); + _mm_storeu_si128((__m128i*)dst_v, _mm256_extracti128_si256(ymm_uv, 1)); + + src_argb += 128; + dst_u += 16; + dst_v += 16; + width -= 32; + } + if (width > 0) { + uint32_t mask = (1u << width) - 1u; + __mmask16 k1 = (__mmask16)mask; + __mmask16 k2 = (__mmask16)(mask >> 16); + __mmask16 k3 = ~k1; + __mmask16 k4 = ~k2; + __m512i zmm0 = _mm512_maskz_loadu_epi32(k1, src_argb); + __m512i zmm1 = _mm512_maskz_loadu_epi32(k2, src_argb + 64); + __m512i zmm2 = _mm512_maskz_loadu_epi32(k1, src_argb + src_stride_argb); + __m512i zmm3 = + _mm512_maskz_loadu_epi32(k2, src_argb + src_stride_argb + 64); + + zmm0 = _mm512_mask_shuffle_epi32(zmm0, k3, zmm0, (_MM_PERM_ENUM)0xa0); + zmm1 = _mm512_mask_shuffle_epi32(zmm1, k4, zmm1, (_MM_PERM_ENUM)0xa0); + zmm2 = _mm512_mask_shuffle_epi32(zmm2, k3, zmm2, (_MM_PERM_ENUM)0xa0); + zmm3 = _mm512_mask_shuffle_epi32(zmm3, k4, zmm3, (_MM_PERM_ENUM)0xa0); + + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + zmm0 = _mm512_maddubs_epi16(zmm0, zmm_0101); + zmm1 = _mm512_maddubs_epi16(zmm1, zmm_0101); + zmm2 = _mm512_maddubs_epi16(zmm2, zmm_0101); + zmm3 = _mm512_maddubs_epi16(zmm3, zmm_0101); + + zmm0 = _mm512_add_epi16(zmm0, zmm2); + zmm1 = _mm512_add_epi16(zmm1, zmm3); + + zmm0 = _mm512_srli_epi16(zmm0, 1); + zmm1 = _mm512_srli_epi16(zmm1, 1); + zmm0 = _mm512_avg_epu16(zmm0, zmm_zero); + zmm1 = _mm512_avg_epu16(zmm1, zmm_zero); + + zmm0 = _mm512_packus_epi16(zmm0, zmm1); + zmm0 = PermutexvarEpi32(zmm_perm_uv, zmm0); + + zmm1 = _mm512_dpbusd_epi32(zmm_add, zmm0, zmm_u); // ~U + zmm2 = _mm512_dpbusd_epi32(zmm_add, zmm0, zmm_v); // ~V + zmm0 = _mm512_permutex2var_epi8(zmm1, zmm_perm, zmm2); + __m256i ymm_uv = + _mm256_xor_si256(_mm512_castsi512_si256(zmm0), _mm256_set1_epi32(-1)); + + int halfwidth = (width + 1) >> 1; + __mmask16 k_out = (__mmask16)((1u << halfwidth) - 1u); + _mm_mask_storeu_epi8(dst_u, k_out, _mm256_castsi256_si128(ymm_uv)); + _mm_mask_storeu_epi8(dst_v, k_out, _mm256_extracti128_si256(ymm_uv, 1)); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOUVMATRIXROW_AVX512VNNIVBMI + +#ifdef HAS_ARGBTOUVMATRIXROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBToUVMatrixRow_AVX2(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + __m256i ymm_u = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)c->kRGBToU)); + __m256i ymm_v = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)c->kRGBToV)); + __m256i ymm_0101 = _mm256_set1_epi16(0x0101); + __m256i ymm_shuf = + _mm256_setr_epi8(0, 4, 1, 5, 2, 6, 3, 7, 8, 12, 9, 13, 10, 14, 11, 15, 0, + 4, 1, 5, 2, 6, 3, 7, 8, 12, 9, 13, 10, 14, 11, 15); + __m256i ymm_8000 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)c->kAddUV)); + __m256i ymm_zero = _mm256_setzero_si256(); + + while (width > 0) { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_argb); + __m256i ymm1 = _mm256_loadu_si256((const __m256i*)(src_argb + 32)); + __m256i ymm2 = + _mm256_loadu_si256((const __m256i*)(src_argb + src_stride_argb)); + __m256i ymm3 = + _mm256_loadu_si256((const __m256i*)(src_argb + src_stride_argb + 32)); + + ymm0 = _mm256_shuffle_epi8(ymm0, ymm_shuf); + ymm1 = _mm256_shuffle_epi8(ymm1, ymm_shuf); + ymm2 = _mm256_shuffle_epi8(ymm2, ymm_shuf); + ymm3 = _mm256_shuffle_epi8(ymm3, ymm_shuf); + + ymm0 = _mm256_maddubs_epi16(ymm0, ymm_0101); + ymm1 = _mm256_maddubs_epi16(ymm1, ymm_0101); + ymm2 = _mm256_maddubs_epi16(ymm2, ymm_0101); + ymm3 = _mm256_maddubs_epi16(ymm3, ymm_0101); + + ymm0 = _mm256_add_epi16(ymm0, ymm2); + ymm1 = _mm256_add_epi16(ymm1, ymm3); + + ymm0 = _mm256_srli_epi16(ymm0, 1); + ymm1 = _mm256_srli_epi16(ymm1, 1); + ymm0 = _mm256_avg_epu16(ymm0, ymm_zero); + ymm1 = _mm256_avg_epu16(ymm1, ymm_zero); + + ymm0 = _mm256_packus_epi16(ymm0, ymm1); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0xd8); + + ymm1 = _mm256_maddubs_epi16(ymm0, ymm_v); + ymm0 = _mm256_maddubs_epi16(ymm0, ymm_u); + + ymm0 = _mm256_hadd_epi16(ymm0, ymm1); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0xd8); + ymm0 = _mm256_sub_epi16(ymm_8000, ymm0); + ymm0 = _mm256_srli_epi16(ymm0, 8); + ymm0 = _mm256_packus_epi16(ymm0, ymm0); + + __m128i xmm_u = _mm256_castsi256_si128(ymm0); + __m128i xmm_v = _mm256_extracti128_si256(ymm0, 1); + + _mm_storel_epi64((__m128i*)dst_u, xmm_u); + _mm_storel_epi64((__m128i*)dst_v, xmm_v); + + src_argb += 64; + dst_u += 8; + dst_v += 8; + width -= 16; + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOUVMATRIXROW_AVX2 + +#ifdef HAS_CONVERT8TO16ROW_AVX2 +LIBYUV_TARGET_AVX2 +void Convert8To16Row_AVX2(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width) { + const int shift = 16 - bits; + __m128i shift128 = _mm_cvtsi32_si128(shift); + do { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_y); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0xd8); + __m256i row0 = _mm256_unpacklo_epi8(ymm0, ymm0); + __m256i row1 = _mm256_unpackhi_epi8(ymm0, ymm0); + row0 = _mm256_srl_epi16(row0, shift128); + row1 = _mm256_srl_epi16(row1, shift128); + _mm256_storeu_si256((__m256i*)dst_y, row0); + _mm256_storeu_si256((__m256i*)(dst_y + 16), row1); + src_y += 32; + dst_y += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_CONVERT8TO16ROW_AVX2 + +#ifdef HAS_MULTIPLYROW_16_AVX2 +LIBYUV_TARGET_AVX2 +void MultiplyRow_16_AVX2(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + __m256i scale256 = _mm256_set1_epi16((short)scale); + do { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_y); + __m256i ymm1 = _mm256_loadu_si256((const __m256i*)(src_y + 16)); + ymm0 = _mm256_mullo_epi16(ymm0, scale256); + ymm1 = _mm256_mullo_epi16(ymm1, scale256); + _mm256_storeu_si256((__m256i*)dst_y, ymm0); + _mm256_storeu_si256((__m256i*)(dst_y + 16), ymm1); + src_y += 32; + dst_y += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_MULTIPLYROW_16_AVX2 + +#ifdef HAS_MERGEUVROW_AVX2 +LIBYUV_TARGET_AVX2 +void MergeUVRow_AVX2(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width) { + while (width > 0) { + __m256i ymm0 = _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)src_u)); + __m256i ymm1 = _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)src_v)); + + ymm1 = _mm256_slli_epi16(ymm1, 8); + ymm0 = _mm256_or_si256(ymm0, ymm1); + + _mm256_storeu_si256((__m256i*)dst_uv, ymm0); + + src_u += 16; + src_v += 16; + dst_uv += 32; + width -= 16; + } + _mm256_zeroupper(); +} +#endif // HAS_MERGEUVROW_AVX2 + +#ifdef HAS_MIRRORROW_AVX2 +LIBYUV_TARGET_AVX2 +void MirrorRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { + __m256i ymm_shuf = _mm256_broadcastsi128_si256( + _mm_setr_epi8(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)); + src += width; + while (width > 0) { + src -= 32; + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src); + ymm0 = _mm256_shuffle_epi8(ymm0, ymm_shuf); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0x4e); + _mm256_storeu_si256((__m256i*)dst, ymm0); + dst += 32; + width -= 32; + } + _mm256_zeroupper(); +} +#endif // HAS_MIRRORROW_AVX2 + +#ifdef HAS_MIRRORUVROW_AVX2 +LIBYUV_TARGET_AVX2 +void MirrorUVRow_AVX2(const uint8_t* src_uv, uint8_t* dst_uv, int width) { + __m256i ymm_shuf = _mm256_broadcastsi128_si256( + _mm_setr_epi8(14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1)); + src_uv += width * 2; + while (width > 0) { + src_uv -= 32; + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_uv); + ymm0 = _mm256_shuffle_epi8(ymm0, ymm_shuf); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0x4e); + _mm256_storeu_si256((__m256i*)dst_uv, ymm0); + dst_uv += 32; + width -= 16; + } + _mm256_zeroupper(); +} +#endif // HAS_MIRRORUVROW_AVX2 + +#ifdef HAS_MIRRORROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void MirrorRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + const __m512i zmm_shuf = _mm512_broadcast_i32x4( + _mm_setr_epi8(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)); + const __m512i zmm_rev = _mm512_set_epi16( + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31); + const uint8_t* s = src + width; + while (width >= 64) { + s -= 64; + __m512i v = _mm512_loadu_si512((const __m512i*)s); + v = _mm512_shuffle_epi8(v, zmm_shuf); + v = _mm512_shuffle_i64x2(v, v, 0x1b); + _mm512_storeu_si512((__m512i*)dst, v); + dst += 64; + width -= 64; + } + if (width > 0) { + __mmask64 k = (1ULL << width) - 1ULL; + __m512i v = _mm512_maskz_loadu_epi8(k, src); + v = _mm512_or_si512(_mm512_srli_epi16(v, 8), _mm512_slli_epi16(v, 8)); + __m512i idx = + _mm512_sub_epi16(zmm_rev, _mm512_set1_epi16((short)((64 - width) >> 1))); + v = PermutexvarEpi16(idx, v); + if (width & 1) { + __m512i v_hi = _mm512_alignr_epi64(v, v, 2); + v = _mm512_alignr_epi8(v_hi, v, 1); + } + _mm512_mask_storeu_epi8(dst, k, v); + } + _mm256_zeroupper(); +} +#endif // HAS_MIRRORROW_AVX512BW + +#ifdef HAS_MIRRORSPLITUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void MirrorSplitUVRow_AVX512BW(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const __m512i zmm_shuf = _mm512_broadcast_i32x4( + _mm_setr_epi8(14, 12, 10, 8, 6, 4, 2, 0, 15, 13, 11, 9, 7, 5, 3, 1)); + const __m512i zmm_perm = _mm512_setr_epi64(6, 4, 2, 0, 7, 5, 3, 1); + const __m512i zmm_rev = _mm512_set_epi16( + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31); + const uint8_t* s = src_uv + (ptrdiff_t)width * 2; + while (width >= 32) { + s -= 64; + __m512i v = _mm512_loadu_si512((const __m512i*)s); + v = _mm512_shuffle_epi8(v, zmm_shuf); + v = PermutexvarEpi64(zmm_perm, v); + _mm256_storeu_si256((__m256i*)dst_u, _mm512_castsi512_si256(v)); + _mm256_storeu_si256((__m256i*)dst_v, _mm512_extracti64x4_epi64(v, 1)); + dst_u += 32; + dst_v += 32; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i idx = + _mm512_sub_epi16(zmm_rev, _mm512_set1_epi16((short)(32 - width))); + __m512i v = _mm512_maskz_loadu_epi16(k, src_uv); + v = PermutexvarEpi16(idx, v); + _mm256_mask_storeu_epi8(dst_u, k, _mm512_cvtepi16_epi8(v)); + _mm256_mask_storeu_epi8(dst_v, k, + _mm512_cvtepi16_epi8(_mm512_srli_epi16(v, 8))); + } + _mm256_zeroupper(); +} +#endif // HAS_MIRRORSPLITUVROW_AVX512BW + +#ifdef HAS_MIRRORUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void MirrorUVRow_AVX512BW(const uint8_t* src_uv, uint8_t* dst_uv, int width) { + const __m512i zmm_idx = _mm512_set_epi16( + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31); + const uint8_t* s = src_uv + (ptrdiff_t)width * 2; + while (width >= 32) { + s -= 64; + __m512i zmm0 = _mm512_loadu_si512((const __m512i*)s); + zmm0 = PermutexvarEpi16(zmm_idx, zmm0); + _mm512_storeu_si512((__m512i*)dst_uv, zmm0); + dst_uv += 64; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i idx = + _mm512_sub_epi16(zmm_idx, _mm512_set1_epi16((short)(32 - width))); + __m512i zmm0 = _mm512_maskz_loadu_epi16(k, src_uv); + _mm512_mask_storeu_epi16(dst_uv, k, PermutexvarEpi16(idx, zmm0)); + } + _mm256_zeroupper(); +} +#endif // HAS_MIRRORUVROW_AVX512BW + +#ifdef HAS_SWAPUVROW_AVX2 +LIBYUV_TARGET_AVX2 +void SwapUVRow_AVX2(const uint8_t* src_uv, uint8_t* dst_vu, int width) { + __m256i ymm_shuf = _mm256_broadcastsi128_si256( + _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14)); + while (width > 0) { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_uv); + __m256i ymm1 = _mm256_loadu_si256((const __m256i*)(src_uv + 32)); + ymm0 = _mm256_shuffle_epi8(ymm0, ymm_shuf); + ymm1 = _mm256_shuffle_epi8(ymm1, ymm_shuf); + _mm256_storeu_si256((__m256i*)dst_vu, ymm0); + _mm256_storeu_si256((__m256i*)(dst_vu + 32), ymm1); + src_uv += 64; + dst_vu += 64; + width -= 32; + } + _mm256_zeroupper(); +} +#endif // HAS_SWAPUVROW_AVX2 + +#ifdef HAS_MIRRORSPLITUVROW_SSSE3 +LIBYUV_TARGET_SSSE3 +void MirrorSplitUVRow_SSSE3(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const __m128i xmm_shuf = + _mm_setr_epi8(14, 12, 10, 8, 6, 4, 2, 0, 15, 13, 11, 9, 7, 5, 3, 1); + src_uv += (ptrdiff_t)width * 2; + while (width > 0) { + src_uv -= 16; + __m128i xmm0 = + _mm_shuffle_epi8(_mm_loadu_si128((const __m128i*)src_uv), xmm_shuf); + _mm_storel_epi64((__m128i*)dst_u, xmm0); + _mm_storel_epi64((__m128i*)dst_v, _mm_unpackhi_epi64(xmm0, xmm0)); + dst_u += 8; + dst_v += 8; + width -= 8; + } +} +#endif // HAS_MIRRORSPLITUVROW_SSSE3 + +#ifdef HAS_MIRRORSPLITUVROW_AVX2 +LIBYUV_TARGET_AVX2 +void MirrorSplitUVRow_AVX2(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + __m256i ymm_shuf = _mm256_broadcastsi128_si256( + _mm_setr_epi8(14, 12, 10, 8, 6, 4, 2, 0, 15, 13, 11, 9, 7, 5, 3, 1)); + src_uv += (ptrdiff_t)width * 2; + while (width > 0) { + src_uv -= 32; + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_uv); + ymm0 = _mm256_shuffle_epi8(ymm0, ymm_shuf); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0x72); + _mm_storeu_si128((__m128i*)dst_u, _mm256_castsi256_si128(ymm0)); + _mm_storeu_si128((__m128i*)dst_v, _mm256_extracti128_si256(ymm0, 1)); + dst_u += 16; + dst_v += 16; + width -= 16; + } + _mm256_zeroupper(); +} +#endif // HAS_MIRRORSPLITUVROW_AVX2 + +#ifdef HAS_RGB24MIRRORROW_AVX2 +LIBYUV_TARGET_AVX2 +void RGB24MirrorRow_AVX2(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width) { + __m256i shuf0 = + _mm256_setr_epi8(-1, 12, 13, 14, 9, 10, 11, 6, 7, 8, 3, 4, 5, 0, 1, 2, -1, + 12, 13, 14, 9, 10, 11, 6, 7, 8, 3, 4, 5, 0, 1, 2); + __m128i shuf1 = + _mm_setr_epi8(13, 14, 15, 10, 11, 12, 7, 8, 9, 4, 5, 6, 1, 2, 3, -1); + + src_rgb24 += (ptrdiff_t)width * 3 - 96; + while (width > 0) { + __m128i v0_lo = _mm_loadu_si128((const __m128i*)(src_rgb24 + 0)); + __m128i v0_hi = _mm_loadu_si128((const __m128i*)(src_rgb24 + 15)); + __m256i v0 = + _mm256_inserti128_si256(_mm256_castsi128_si256(v0_lo), v0_hi, 1); + + __m128i v1_lo = _mm_loadu_si128((const __m128i*)(src_rgb24 + 30)); + __m128i v1_hi = _mm_loadu_si128((const __m128i*)(src_rgb24 + 45)); + __m256i v1 = + _mm256_inserti128_si256(_mm256_castsi128_si256(v1_lo), v1_hi, 1); + + __m128i v2_lo = _mm_loadu_si128((const __m128i*)(src_rgb24 + 60)); + __m128i v2_hi = _mm_loadu_si128((const __m128i*)(src_rgb24 + 75)); + __m256i v2 = + _mm256_inserti128_si256(_mm256_castsi128_si256(v2_lo), v2_hi, 1); + + __m128i v3 = _mm_loadu_si128((const __m128i*)(src_rgb24 + 80)); + + v0 = _mm256_shuffle_epi8(v0, shuf0); + v1 = _mm256_shuffle_epi8(v1, shuf0); + v2 = _mm256_shuffle_epi8(v2, shuf0); + v3 = _mm_shuffle_epi8(v3, shuf1); + + _mm_storeu_si128((__m128i*)(dst_rgb24 + 80), _mm256_castsi256_si128(v0)); + _mm_storeu_si128((__m128i*)(dst_rgb24 + 65), + _mm256_extracti128_si256(v0, 1)); + _mm_storeu_si128((__m128i*)(dst_rgb24 + 50), _mm256_castsi256_si128(v1)); + _mm_storeu_si128((__m128i*)(dst_rgb24 + 35), + _mm256_extracti128_si256(v1, 1)); + _mm_storeu_si128((__m128i*)(dst_rgb24 + 20), _mm256_castsi256_si128(v2)); + _mm_storeu_si128((__m128i*)(dst_rgb24 + 5), + _mm256_extracti128_si256(v2, 1)); + _mm_storel_epi64((__m128i*)(dst_rgb24 + 0), v3); + + src_rgb24 -= 96; + dst_rgb24 += 96; + width -= 32; + } + _mm256_zeroupper(); +} +#endif // HAS_RGB24MIRRORROW_AVX2 + +#ifdef HAS_INTERPOLATEROW_AVX2 +LIBYUV_TARGET_AVX2 +void InterpolateRow_AVX2(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + int y1 = source_y_fraction; + int y0 = 256 - y1; + const uint8_t* src_ptr1 = src_ptr + src_stride; + __m256i ymm_y = _mm256_set1_epi16((y1 << 8) | y0); + __m256i ymm_8080 = _mm256_set1_epi16(0x8080); + int i; + + if (y1 == 0) { + for (i = 0; i < width; i += 32) { + _mm256_storeu_si256((__m256i*)(dst_ptr + i), + _mm256_loadu_si256((const __m256i*)(src_ptr + i))); + } + } else if (y1 == 128) { + for (i = 0; i < width; i += 32) { + __m256i row0 = _mm256_loadu_si256((const __m256i*)(src_ptr + i)); + __m256i row1 = _mm256_loadu_si256((const __m256i*)(src_ptr1 + i)); + _mm256_storeu_si256((__m256i*)(dst_ptr + i), _mm256_avg_epu8(row0, row1)); + } + } else { + for (i = 0; i < width; i += 32) { + __m256i row0 = _mm256_loadu_si256((const __m256i*)(src_ptr + i)); + __m256i row1 = _mm256_loadu_si256((const __m256i*)(src_ptr1 + i)); + __m256i low = _mm256_unpacklo_epi8(row0, row1); + __m256i high = _mm256_unpackhi_epi8(row0, row1); + low = _mm256_sub_epi8(low, ymm_8080); + high = _mm256_sub_epi8(high, ymm_8080); + low = _mm256_maddubs_epi16(ymm_y, low); + high = _mm256_maddubs_epi16(ymm_y, high); + low = _mm256_add_epi16(low, ymm_8080); + high = _mm256_add_epi16(high, ymm_8080); + low = _mm256_srli_epi16(low, 8); + high = _mm256_srli_epi16(high, 8); + _mm256_storeu_si256((__m256i*)(dst_ptr + i), + _mm256_packus_epi16(low, high)); + } + } + _mm256_zeroupper(); +} +#endif // HAS_INTERPOLATEROW_AVX2 + +#ifdef HAS_INTERPOLATEROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void InterpolateRow_AVX512BW(uint8_t* dst_ptr, + const uint8_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + int y1 = source_y_fraction; + int y0 = 256 - y1; + const uint8_t* src_ptr1 = src_ptr + src_stride; + __m512i zmm_y = _mm512_set1_epi16((short)((y1 << 8) | y0)); + __m512i zmm_8080 = _mm512_set1_epi16((short)0x8080); + int i; + + if (y1 == 0) { + for (i = 0; i <= width - 64; i += 64) { + _mm512_storeu_si512((__m512i*)(dst_ptr + i), + _mm512_loadu_si512((const __m512i*)(src_ptr + i))); + } + if (i < width) { + __mmask64 mask = (__mmask64)((1ull << (width - i)) - 1ull); + _mm512_mask_storeu_epi8(dst_ptr + i, mask, + _mm512_maskz_loadu_epi8(mask, src_ptr + i)); + } + } else if (y1 == 128) { + for (i = 0; i <= width - 64; i += 64) { + __m512i row0 = _mm512_loadu_si512((const __m512i*)(src_ptr + i)); + __m512i row1 = _mm512_loadu_si512((const __m512i*)(src_ptr1 + i)); + _mm512_storeu_si512((__m512i*)(dst_ptr + i), _mm512_avg_epu8(row0, row1)); + } + if (i < width) { + __mmask64 mask = (__mmask64)((1ull << (width - i)) - 1ull); + __m512i row0 = _mm512_maskz_loadu_epi8(mask, src_ptr + i); + __m512i row1 = _mm512_maskz_loadu_epi8(mask, src_ptr1 + i); + _mm512_mask_storeu_epi8(dst_ptr + i, mask, _mm512_avg_epu8(row0, row1)); + } + } else { + for (i = 0; i <= width - 64; i += 64) { + __m512i row0 = _mm512_loadu_si512((const __m512i*)(src_ptr + i)); + __m512i row1 = _mm512_loadu_si512((const __m512i*)(src_ptr1 + i)); + __m512i low = _mm512_unpacklo_epi8(row0, row1); + __m512i high = _mm512_unpackhi_epi8(row0, row1); + low = _mm512_sub_epi8(low, zmm_8080); + high = _mm512_sub_epi8(high, zmm_8080); + low = _mm512_maddubs_epi16(zmm_y, low); + high = _mm512_maddubs_epi16(zmm_y, high); + low = _mm512_add_epi16(low, zmm_8080); + high = _mm512_add_epi16(high, zmm_8080); + low = _mm512_srli_epi16(low, 8); + high = _mm512_srli_epi16(high, 8); + _mm512_storeu_si512((__m512i*)(dst_ptr + i), + _mm512_packus_epi16(low, high)); + } + if (i < width) { + __mmask64 mask = (__mmask64)((1ull << (width - i)) - 1ull); + __m512i row0 = _mm512_maskz_loadu_epi8(mask, src_ptr + i); + __m512i row1 = _mm512_maskz_loadu_epi8(mask, src_ptr1 + i); + __m512i low = _mm512_unpacklo_epi8(row0, row1); + __m512i high = _mm512_unpackhi_epi8(row0, row1); + low = _mm512_sub_epi8(low, zmm_8080); + high = _mm512_sub_epi8(high, zmm_8080); + low = _mm512_maddubs_epi16(zmm_y, low); + high = _mm512_maddubs_epi16(zmm_y, high); + low = _mm512_add_epi16(low, zmm_8080); + high = _mm512_add_epi16(high, zmm_8080); + low = _mm512_srli_epi16(low, 8); + high = _mm512_srli_epi16(high, 8); + _mm512_mask_storeu_epi8(dst_ptr + i, mask, + _mm512_packus_epi16(low, high)); + } + } + _mm256_zeroupper(); +} +#endif // HAS_INTERPOLATEROW_AVX512BW + +#ifdef HAS_INTERPOLATEROW_16_AVX2 +LIBYUV_TARGET_AVX2 +void InterpolateRow_16_AVX2(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + int y1 = source_y_fraction; + int y0 = 256 - y1; + const uint16_t* src_ptr1 = src_ptr + src_stride; + __m256i ymm_y = _mm256_set1_epi32((y1 << 16) | y0); + __m256i ymm_8000 = _mm256_set1_epi16((short)0x8000); + __m256i ymm_round = _mm256_set1_epi32(8388736); // 0x800000 + 128 + int i; + + if (y1 == 0) { + for (i = 0; i < width; i += 16) { + _mm256_storeu_si256((__m256i*)(dst_ptr + i), + _mm256_loadu_si256((const __m256i*)(src_ptr + i))); + } + } else if (y1 == 128) { + for (i = 0; i < width; i += 16) { + __m256i row0 = _mm256_loadu_si256((const __m256i*)(src_ptr + i)); + __m256i row1 = _mm256_loadu_si256((const __m256i*)(src_ptr1 + i)); + _mm256_storeu_si256((__m256i*)(dst_ptr + i), + _mm256_avg_epu16(row0, row1)); + } + } else { + for (i = 0; i < width; i += 16) { + __m256i row0 = _mm256_loadu_si256((const __m256i*)(src_ptr + i)); + __m256i row1 = _mm256_loadu_si256((const __m256i*)(src_ptr1 + i)); + __m256i row0l = _mm256_unpacklo_epi16(row0, row1); + __m256i row0h = _mm256_unpackhi_epi16(row0, row1); + row0l = _mm256_sub_epi16(row0l, ymm_8000); + row0h = _mm256_sub_epi16(row0h, ymm_8000); + __m256i resl = _mm256_madd_epi16(row0l, ymm_y); + __m256i resh = _mm256_madd_epi16(row0h, ymm_y); + resl = _mm256_add_epi32(resl, ymm_round); + resh = _mm256_add_epi32(resh, ymm_round); + resl = _mm256_srai_epi32(resl, 8); + resh = _mm256_srai_epi32(resh, 8); + _mm256_storeu_si256((__m256i*)(dst_ptr + i), + _mm256_packus_epi32(resl, resh)); + } + } + _mm256_zeroupper(); +} +#endif // HAS_INTERPOLATEROW_16_AVX2 + +#ifdef HAS_ARGBMIRRORROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBMirrorRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { + __m256i ymm_shuf = _mm256_setr_epi32(7, 6, 5, 4, 3, 2, 1, 0); + src += width * 4; + while (width > 0) { + src -= 32; + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src); + ymm0 = _mm256_permutevar8x32_epi32(ymm0, ymm_shuf); + _mm256_storeu_si256((__m256i*)dst, ymm0); + dst += 32; + width -= 8; + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBMIRRORROW_AVX2 #ifdef HAS_J400TOARGBROW_AVX2 -// Duplicates gray value 3 times and fills in alpha opaque. -__declspec(naked) void J400ToARGBRow_AVX2(const uint8_t* src_y, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, [esp + 4] // src_y - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - vpcmpeqb ymm5, ymm5, ymm5 // generate mask 0xff000000 - vpslld ymm5, ymm5, 24 +static const uint8_t kShuffleMaskJ400ToARGB_0[32] = { + 0u, 0u, 0u, 128u, 1u, 1u, 1u, 128u, 2u, 2u, 2u, 128u, 3u, 3u, 3u, 128u, + 4u, 4u, 4u, 128u, 5u, 5u, 5u, 128u, 6u, 6u, 6u, 128u, 7u, 7u, 7u, 128u}; +static const uint8_t kShuffleMaskJ400ToARGB_1[32] = { + 8u, 8u, 8u, 128u, 9u, 9u, 9u, 128u, 10u, 10u, 10u, + 128u, 11u, 11u, 11u, 128u, 12u, 12u, 12u, 128u, 13u, 13u, + 13u, 128u, 14u, 14u, 14u, 128u, 15u, 15u, 15u, 128u}; - convertloop: - vmovdqu xmm0, [eax] - lea eax, [eax + 16] - vpermq ymm0, ymm0, 0xd8 - vpunpcklbw ymm0, ymm0, ymm0 - vpermq ymm0, ymm0, 0xd8 - vpunpckhwd ymm1, ymm0, ymm0 - vpunpcklwd ymm0, ymm0, ymm0 - vpor ymm0, ymm0, ymm5 - vpor ymm1, ymm1, ymm5 - vmovdqu [edx], ymm0 - vmovdqu [edx + 32], ymm1 - lea edx, [edx + 64] - sub ecx, 16 - jg convertloop - vzeroupper - ret +LIBYUV_TARGET_AVX2 +void J400ToARGBRow_AVX2(const uint8_t* src_y, uint8_t* dst_argb, int width) { + __m256i ymm_mask0 = + _mm256_loadu_si256((const __m256i*)kShuffleMaskJ400ToARGB_0); + __m256i ymm_mask1 = + _mm256_loadu_si256((const __m256i*)kShuffleMaskJ400ToARGB_1); + __m256i ymm_alpha = _mm256_set1_epi32((int)0xff000000u); + + while (width > 0) { + __m256i ymm0 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)src_y)); + + __m256i ymm1 = _mm256_shuffle_epi8(ymm0, ymm_mask0); + __m256i ymm2 = _mm256_shuffle_epi8(ymm0, ymm_mask1); + + ymm1 = _mm256_or_si256(ymm1, ymm_alpha); + ymm2 = _mm256_or_si256(ymm2, ymm_alpha); + + _mm256_storeu_si256((__m256i*)dst_argb, ymm1); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), ymm2); + + src_y += 16; + dst_argb += 64; + width -= 16; } + _mm256_zeroupper(); } #endif // HAS_J400TOARGBROW_AVX2 -__declspec(naked) void RGB24ToARGBRow_SSSE3(const uint8_t* src_rgb24, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, [esp + 4] // src_rgb24 - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - pcmpeqb xmm5, xmm5 // generate mask 0xff000000 - pslld xmm5, 24 - movdqa xmm4, xmmword ptr kShuffleMaskRGB24ToARGB - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm3, [eax + 32] - lea eax, [eax + 48] - movdqa xmm2, xmm3 - palignr xmm2, xmm1, 8 // xmm2 = { xmm3[0:3] xmm1[8:15]} - pshufb xmm2, xmm4 - por xmm2, xmm5 - palignr xmm1, xmm0, 12 // xmm1 = { xmm3[0:7] xmm0[12:15]} - pshufb xmm0, xmm4 - movdqu [edx + 32], xmm2 - por xmm0, xmm5 - pshufb xmm1, xmm4 - movdqu [edx], xmm0 - por xmm1, xmm5 - palignr xmm3, xmm3, 4 // xmm3 = { xmm3[4:15]} - pshufb xmm3, xmm4 - movdqu [edx + 16], xmm1 - por xmm3, xmm5 - movdqu [edx + 48], xmm3 - lea edx, [edx + 64] - sub ecx, 16 - jg convertloop - ret - } -} - -__declspec(naked) void RAWToARGBRow_SSSE3(const uint8_t* src_raw, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, [esp + 4] // src_raw - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - pcmpeqb xmm5, xmm5 // generate mask 0xff000000 - pslld xmm5, 24 - movdqa xmm4, xmmword ptr kShuffleMaskRAWToARGB - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm3, [eax + 32] - lea eax, [eax + 48] - movdqa xmm2, xmm3 - palignr xmm2, xmm1, 8 // xmm2 = { xmm3[0:3] xmm1[8:15]} - pshufb xmm2, xmm4 - por xmm2, xmm5 - palignr xmm1, xmm0, 12 // xmm1 = { xmm3[0:7] xmm0[12:15]} - pshufb xmm0, xmm4 - movdqu [edx + 32], xmm2 - por xmm0, xmm5 - pshufb xmm1, xmm4 - movdqu [edx], xmm0 - por xmm1, xmm5 - palignr xmm3, xmm3, 4 // xmm3 = { xmm3[4:15]} - pshufb xmm3, xmm4 - movdqu [edx + 16], xmm1 - por xmm3, xmm5 - movdqu [edx + 48], xmm3 - lea edx, [edx + 64] - sub ecx, 16 - jg convertloop - ret - } -} - -__declspec(naked) void RAWToRGB24Row_SSSE3(const uint8_t* src_raw, - uint8_t* dst_rgb24, - int width) { - __asm { - mov eax, [esp + 4] // src_raw - mov edx, [esp + 8] // dst_rgb24 - mov ecx, [esp + 12] // width - movdqa xmm3, xmmword ptr kShuffleMaskRAWToRGB24_0 - movdqa xmm4, xmmword ptr kShuffleMaskRAWToRGB24_1 - movdqa xmm5, xmmword ptr kShuffleMaskRAWToRGB24_2 - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 4] - movdqu xmm2, [eax + 8] - lea eax, [eax + 24] - pshufb xmm0, xmm3 - pshufb xmm1, xmm4 - pshufb xmm2, xmm5 - movq qword ptr [edx], xmm0 - movq qword ptr [edx + 8], xmm1 - movq qword ptr [edx + 16], xmm2 - lea edx, [edx + 24] - sub ecx, 8 - jg convertloop - ret - } -} - -// pmul method to replicate bits. -// Math to replicate bits: -// (v << 8) | (v << 3) -// v * 256 + v * 8 -// v * (256 + 8) -// G shift of 5 is incorporated, so shift is 5 + 8 and 5 + 3 -// 20 instructions. -__declspec(naked) void RGB565ToARGBRow_SSE2(const uint8_t* src_rgb565, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, 0x01080108 // generate multiplier to repeat 5 bits - movd xmm5, eax - pshufd xmm5, xmm5, 0 - mov eax, 0x20802080 // multiplier shift by 5 and then repeat 6 bits - movd xmm6, eax - pshufd xmm6, xmm6, 0 - pcmpeqb xmm3, xmm3 // generate mask 0xf800f800 for Red - psllw xmm3, 11 - pcmpeqb xmm4, xmm4 // generate mask 0x07e007e0 for Green - psllw xmm4, 10 - psrlw xmm4, 5 - pcmpeqb xmm7, xmm7 // generate mask 0xff00ff00 for Alpha - psllw xmm7, 8 - - mov eax, [esp + 4] // src_rgb565 - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - sub edx, eax - sub edx, eax - - convertloop: - movdqu xmm0, [eax] // fetch 8 pixels of bgr565 - movdqa xmm1, xmm0 - movdqa xmm2, xmm0 - pand xmm1, xmm3 // R in upper 5 bits - psllw xmm2, 11 // B in upper 5 bits - pmulhuw xmm1, xmm5 // * (256 + 8) - pmulhuw xmm2, xmm5 // * (256 + 8) - psllw xmm1, 8 - por xmm1, xmm2 // RB - pand xmm0, xmm4 // G in middle 6 bits - pmulhuw xmm0, xmm6 // << 5 * (256 + 4) - por xmm0, xmm7 // AG - movdqa xmm2, xmm1 - punpcklbw xmm1, xmm0 - punpckhbw xmm2, xmm0 - movdqu [eax * 2 + edx], xmm1 // store 4 pixels of ARGB - movdqu [eax * 2 + edx + 16], xmm2 // store next 4 pixels of ARGB - lea eax, [eax + 16] - sub ecx, 8 - jg convertloop - ret - } -} +#ifdef HAS_RGB24TOARGBROW_AVX2 +static const uint8_t kShuffleMaskRGB24ToARGB[2][16] = { + {0u, 1u, 2u, 128u, 3u, 4u, 5u, 128u, 6u, 7u, 8u, 128u, 9u, 10u, 11u, 128u}, + {4u, 5u, 6u, 128u, 7u, 8u, 9u, 128u, 10u, 11u, 12u, 128u, 13u, 14u, 15u, + 128u}}; +#endif // HAS_RGB24TOARGBROW_AVX2 #ifdef HAS_RGB565TOARGBROW_AVX2 -// pmul method to replicate bits. -// Math to replicate bits: -// (v << 8) | (v << 3) -// v * 256 + v * 8 -// v * (256 + 8) -// G shift of 5 is incorporated, so shift is 5 + 8 and 5 + 3 -__declspec(naked) void RGB565ToARGBRow_AVX2(const uint8_t* src_rgb565, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, 0x01080108 // generate multiplier to repeat 5 bits - vmovd xmm5, eax - vbroadcastss ymm5, xmm5 - mov eax, 0x20802080 // multiplier shift by 5 and then repeat 6 bits - vmovd xmm6, eax - vbroadcastss ymm6, xmm6 - vpcmpeqb ymm3, ymm3, ymm3 // generate mask 0xf800f800 for Red - vpsllw ymm3, ymm3, 11 - vpcmpeqb ymm4, ymm4, ymm4 // generate mask 0x07e007e0 for Green - vpsllw ymm4, ymm4, 10 - vpsrlw ymm4, ymm4, 5 - vpcmpeqb ymm7, ymm7, ymm7 // generate mask 0xff00ff00 for Alpha - vpsllw ymm7, ymm7, 8 +LIBYUV_TARGET_AVX2 +void RGB565ToARGBRow_AVX2(const uint8_t* src_rgb565, + uint8_t* dst_argb, + int width) { + __m256i ymm_scale_rb = _mm256_set1_epi32(0x01080108); + __m256i ymm_scale_g = _mm256_set1_epi32(0x20802080); + __m256i ymm_mask_b = _mm256_set1_epi16((short)0xf800); + __m256i ymm_mask_g = _mm256_set1_epi16(0x07e0); + __m256i ymm_mask_a = _mm256_set1_epi16((short)0xff00); - mov eax, [esp + 4] // src_rgb565 - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - sub edx, eax - sub edx, eax + while (width > 0) { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_rgb565); + __m256i ymm1 = ymm0; + __m256i ymm2 = ymm0; - convertloop: - vmovdqu ymm0, [eax] // fetch 16 pixels of bgr565 - vpand ymm1, ymm0, ymm3 // R in upper 5 bits - vpsllw ymm2, ymm0, 11 // B in upper 5 bits - vpmulhuw ymm1, ymm1, ymm5 // * (256 + 8) - vpmulhuw ymm2, ymm2, ymm5 // * (256 + 8) - vpsllw ymm1, ymm1, 8 - vpor ymm1, ymm1, ymm2 // RB - vpand ymm0, ymm0, ymm4 // G in middle 6 bits - vpmulhuw ymm0, ymm0, ymm6 // << 5 * (256 + 4) - vpor ymm0, ymm0, ymm7 // AG - vpermq ymm0, ymm0, 0xd8 // mutate for unpack - vpermq ymm1, ymm1, 0xd8 - vpunpckhbw ymm2, ymm1, ymm0 - vpunpcklbw ymm1, ymm1, ymm0 - vmovdqu [eax * 2 + edx], ymm1 // store 4 pixels of ARGB - vmovdqu [eax * 2 + edx + 32], ymm2 // store next 4 pixels of ARGB - lea eax, [eax + 32] - sub ecx, 16 - jg convertloop - vzeroupper - ret + ymm1 = _mm256_and_si256(ymm1, ymm_mask_b); + ymm2 = _mm256_slli_epi16(ymm2, 11); + ymm1 = _mm256_mulhi_epu16(ymm1, ymm_scale_rb); + ymm2 = _mm256_mulhi_epu16(ymm2, ymm_scale_rb); + ymm1 = _mm256_slli_epi16(ymm1, 8); + ymm1 = _mm256_or_si256(ymm1, ymm2); // RB + + ymm0 = _mm256_and_si256(ymm0, ymm_mask_g); + ymm0 = _mm256_mulhi_epu16(ymm0, ymm_scale_g); + ymm0 = _mm256_or_si256(ymm0, ymm_mask_a); // GA + + ymm2 = _mm256_unpacklo_epi8(ymm1, ymm0); + ymm1 = _mm256_unpackhi_epi8(ymm1, ymm0); + + ymm0 = _mm256_permute2x128_si256(ymm2, ymm1, 0x20); + ymm1 = _mm256_permute2x128_si256(ymm2, ymm1, 0x31); + + _mm256_storeu_si256((__m256i*)dst_argb, ymm0); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), ymm1); + + src_rgb565 += 32; + dst_argb += 64; + width -= 16; } + _mm256_zeroupper(); } #endif // HAS_RGB565TOARGBROW_AVX2 #ifdef HAS_ARGB1555TOARGBROW_AVX2 -__declspec(naked) void ARGB1555ToARGBRow_AVX2(const uint8_t* src_argb1555, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, 0x01080108 // generate multiplier to repeat 5 bits - vmovd xmm5, eax - vbroadcastss ymm5, xmm5 - mov eax, 0x42004200 // multiplier shift by 6 and then repeat 5 bits - vmovd xmm6, eax - vbroadcastss ymm6, xmm6 - vpcmpeqb ymm3, ymm3, ymm3 // generate mask 0xf800f800 for Red - vpsllw ymm3, ymm3, 11 - vpsrlw ymm4, ymm3, 6 // generate mask 0x03e003e0 for Green - vpcmpeqb ymm7, ymm7, ymm7 // generate mask 0xff00ff00 for Alpha - vpsllw ymm7, ymm7, 8 +LIBYUV_TARGET_AVX2 +void ARGB1555ToARGBRow_AVX2(const uint8_t* src_argb1555, + uint8_t* dst_argb, + int width) { + __m256i ymm_scale_rb = _mm256_set1_epi32(0x01080108); + __m256i ymm_scale_g = _mm256_set1_epi32(0x42004200); + __m256i ymm_mask_b = _mm256_set1_epi16((short)0xf800); + __m256i ymm_mask_g = _mm256_set1_epi16(0x03e0); + __m256i ymm_mask_a = _mm256_set1_epi16((short)0xff00); - mov eax, [esp + 4] // src_argb1555 - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - sub edx, eax - sub edx, eax + while (width > 0) { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_argb1555); + __m256i ymm1 = ymm0; + __m256i ymm2 = ymm0; - convertloop: - vmovdqu ymm0, [eax] // fetch 16 pixels of 1555 - vpsllw ymm1, ymm0, 1 // R in upper 5 bits - vpsllw ymm2, ymm0, 11 // B in upper 5 bits - vpand ymm1, ymm1, ymm3 - vpmulhuw ymm2, ymm2, ymm5 // * (256 + 8) - vpmulhuw ymm1, ymm1, ymm5 // * (256 + 8) - vpsllw ymm1, ymm1, 8 - vpor ymm1, ymm1, ymm2 // RB - vpsraw ymm2, ymm0, 8 // A - vpand ymm0, ymm0, ymm4 // G in middle 5 bits - vpmulhuw ymm0, ymm0, ymm6 // << 6 * (256 + 8) - vpand ymm2, ymm2, ymm7 - vpor ymm0, ymm0, ymm2 // AG - vpermq ymm0, ymm0, 0xd8 // mutate for unpack - vpermq ymm1, ymm1, 0xd8 - vpunpckhbw ymm2, ymm1, ymm0 - vpunpcklbw ymm1, ymm1, ymm0 - vmovdqu [eax * 2 + edx], ymm1 // store 8 pixels of ARGB - vmovdqu [eax * 2 + edx + 32], ymm2 // store next 8 pixels of ARGB - lea eax, [eax + 32] - sub ecx, 16 - jg convertloop - vzeroupper - ret + ymm1 = _mm256_slli_epi16(ymm1, 1); + ymm2 = _mm256_slli_epi16(ymm2, 11); + ymm1 = _mm256_and_si256(ymm1, ymm_mask_b); + ymm2 = _mm256_mulhi_epu16(ymm2, ymm_scale_rb); + ymm1 = _mm256_mulhi_epu16(ymm1, ymm_scale_rb); + ymm1 = _mm256_slli_epi16(ymm1, 8); + ymm1 = _mm256_or_si256(ymm1, ymm2); // RB + + ymm2 = ymm0; + ymm0 = _mm256_and_si256(ymm0, ymm_mask_g); + ymm2 = _mm256_srai_epi16(ymm2, 8); + ymm0 = _mm256_mulhi_epu16(ymm0, ymm_scale_g); + ymm2 = _mm256_and_si256(ymm2, ymm_mask_a); + ymm0 = _mm256_or_si256(ymm0, ymm2); // GA + + ymm2 = _mm256_unpacklo_epi8(ymm1, ymm0); + ymm1 = _mm256_unpackhi_epi8(ymm1, ymm0); + + ymm0 = _mm256_permute2x128_si256(ymm2, ymm1, 0x20); + ymm1 = _mm256_permute2x128_si256(ymm2, ymm1, 0x31); + + _mm256_storeu_si256((__m256i*)dst_argb, ymm0); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), ymm1); + + src_argb1555 += 32; + dst_argb += 64; + width -= 16; } + _mm256_zeroupper(); } #endif // HAS_ARGB1555TOARGBROW_AVX2 #ifdef HAS_ARGB4444TOARGBROW_AVX2 -__declspec(naked) void ARGB4444ToARGBRow_AVX2(const uint8_t* src_argb4444, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, 0x0f0f0f0f // generate mask 0x0f0f0f0f - vmovd xmm4, eax - vbroadcastss ymm4, xmm4 - vpslld ymm5, ymm4, 4 // 0xf0f0f0f0 for high nibbles - mov eax, [esp + 4] // src_argb4444 - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - sub edx, eax - sub edx, eax +LIBYUV_TARGET_AVX2 +void ARGB4444ToARGBRow_AVX2(const uint8_t* src_argb4444, + uint8_t* dst_argb, + int width) { + __m256i ymm_mask = _mm256_set1_epi32(0x0f0f0f0f); + __m256i ymm_mask2 = _mm256_slli_epi32(ymm_mask, 4); - convertloop: - vmovdqu ymm0, [eax] // fetch 16 pixels of bgra4444 - vpand ymm2, ymm0, ymm5 // mask high nibbles - vpand ymm0, ymm0, ymm4 // mask low nibbles - vpsrlw ymm3, ymm2, 4 - vpsllw ymm1, ymm0, 4 - vpor ymm2, ymm2, ymm3 - vpor ymm0, ymm0, ymm1 - vpermq ymm0, ymm0, 0xd8 // mutate for unpack - vpermq ymm2, ymm2, 0xd8 - vpunpckhbw ymm1, ymm0, ymm2 - vpunpcklbw ymm0, ymm0, ymm2 - vmovdqu [eax * 2 + edx], ymm0 // store 8 pixels of ARGB - vmovdqu [eax * 2 + edx + 32], ymm1 // store next 8 pixels of ARGB - lea eax, [eax + 32] - sub ecx, 16 - jg convertloop - vzeroupper - ret + while (width > 0) { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_argb4444); + __m256i ymm2 = ymm0; + + ymm0 = _mm256_and_si256(ymm0, ymm_mask); + ymm2 = _mm256_and_si256(ymm2, ymm_mask2); + + __m256i ymm1 = ymm0; + __m256i ymm3 = ymm2; + + ymm1 = _mm256_slli_epi16(ymm1, 4); + ymm3 = _mm256_srli_epi16(ymm3, 4); + + ymm0 = _mm256_or_si256(ymm0, ymm1); + ymm2 = _mm256_or_si256(ymm2, ymm3); + + ymm1 = ymm0; + ymm0 = _mm256_unpacklo_epi8(ymm0, ymm2); + ymm1 = _mm256_unpackhi_epi8(ymm1, ymm2); + + ymm2 = _mm256_permute2x128_si256(ymm0, ymm1, 0x20); + ymm1 = _mm256_permute2x128_si256(ymm0, ymm1, 0x31); + + _mm256_storeu_si256((__m256i*)dst_argb, ymm2); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), ymm1); + + src_argb4444 += 32; + dst_argb += 64; + width -= 16; } + _mm256_zeroupper(); } #endif // HAS_ARGB4444TOARGBROW_AVX2 -// 24 instructions -__declspec(naked) void ARGB1555ToARGBRow_SSE2(const uint8_t* src_argb1555, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, 0x01080108 // generate multiplier to repeat 5 bits - movd xmm5, eax - pshufd xmm5, xmm5, 0 - mov eax, 0x42004200 // multiplier shift by 6 and then repeat 5 bits - movd xmm6, eax - pshufd xmm6, xmm6, 0 - pcmpeqb xmm3, xmm3 // generate mask 0xf800f800 for Red - psllw xmm3, 11 - movdqa xmm4, xmm3 // generate mask 0x03e003e0 for Green - psrlw xmm4, 6 - pcmpeqb xmm7, xmm7 // generate mask 0xff00ff00 for Alpha - psllw xmm7, 8 - - mov eax, [esp + 4] // src_argb1555 - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - sub edx, eax - sub edx, eax - - convertloop: - movdqu xmm0, [eax] // fetch 8 pixels of 1555 - movdqa xmm1, xmm0 - movdqa xmm2, xmm0 - psllw xmm1, 1 // R in upper 5 bits - psllw xmm2, 11 // B in upper 5 bits - pand xmm1, xmm3 - pmulhuw xmm2, xmm5 // * (256 + 8) - pmulhuw xmm1, xmm5 // * (256 + 8) - psllw xmm1, 8 - por xmm1, xmm2 // RB - movdqa xmm2, xmm0 - pand xmm0, xmm4 // G in middle 5 bits - psraw xmm2, 8 // A - pmulhuw xmm0, xmm6 // << 6 * (256 + 8) - pand xmm2, xmm7 - por xmm0, xmm2 // AG - movdqa xmm2, xmm1 - punpcklbw xmm1, xmm0 - punpckhbw xmm2, xmm0 - movdqu [eax * 2 + edx], xmm1 // store 4 pixels of ARGB - movdqu [eax * 2 + edx + 16], xmm2 // store next 4 pixels of ARGB - lea eax, [eax + 16] - sub ecx, 8 - jg convertloop - ret - } -} - -// 18 instructions. -__declspec(naked) void ARGB4444ToARGBRow_SSE2(const uint8_t* src_argb4444, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, 0x0f0f0f0f // generate mask 0x0f0f0f0f - movd xmm4, eax - pshufd xmm4, xmm4, 0 - movdqa xmm5, xmm4 // 0xf0f0f0f0 for high nibbles - pslld xmm5, 4 - mov eax, [esp + 4] // src_argb4444 - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - sub edx, eax - sub edx, eax - - convertloop: - movdqu xmm0, [eax] // fetch 8 pixels of bgra4444 - movdqa xmm2, xmm0 - pand xmm0, xmm4 // mask low nibbles - pand xmm2, xmm5 // mask high nibbles - movdqa xmm1, xmm0 - movdqa xmm3, xmm2 - psllw xmm1, 4 - psrlw xmm3, 4 - por xmm0, xmm1 - por xmm2, xmm3 - movdqa xmm1, xmm0 - punpcklbw xmm0, xmm2 - punpckhbw xmm1, xmm2 - movdqu [eax * 2 + edx], xmm0 // store 4 pixels of ARGB - movdqu [eax * 2 + edx + 16], xmm1 // store next 4 pixels of ARGB - lea eax, [eax + 16] - sub ecx, 8 - jg convertloop - ret - } -} - -__declspec(naked) void ARGBToRGB24Row_SSSE3(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_rgb - mov ecx, [esp + 12] // width - movdqa xmm6, xmmword ptr kShuffleMaskARGBToRGB24 - - convertloop: - movdqu xmm0, [eax] // fetch 16 pixels of argb - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + 32] - movdqu xmm3, [eax + 48] - lea eax, [eax + 64] - pshufb xmm0, xmm6 // pack 16 bytes of ARGB to 12 bytes of RGB - pshufb xmm1, xmm6 - pshufb xmm2, xmm6 - pshufb xmm3, xmm6 - movdqa xmm4, xmm1 // 4 bytes from 1 for 0 - psrldq xmm1, 4 // 8 bytes from 1 - pslldq xmm4, 12 // 4 bytes from 1 for 0 - movdqa xmm5, xmm2 // 8 bytes from 2 for 1 - por xmm0, xmm4 // 4 bytes from 1 for 0 - pslldq xmm5, 8 // 8 bytes from 2 for 1 - movdqu [edx], xmm0 // store 0 - por xmm1, xmm5 // 8 bytes from 2 for 1 - psrldq xmm2, 8 // 4 bytes from 2 - pslldq xmm3, 4 // 12 bytes from 3 for 2 - por xmm2, xmm3 // 12 bytes from 3 for 2 - movdqu [edx + 16], xmm1 // store 1 - movdqu [edx + 32], xmm2 // store 2 - lea edx, [edx + 48] - sub ecx, 16 - jg convertloop - ret - } -} - -__declspec(naked) void ARGBToRAWRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_rgb - mov ecx, [esp + 12] // width - movdqa xmm6, xmmword ptr kShuffleMaskARGBToRAW - - convertloop: - movdqu xmm0, [eax] // fetch 16 pixels of argb - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + 32] - movdqu xmm3, [eax + 48] - lea eax, [eax + 64] - pshufb xmm0, xmm6 // pack 16 bytes of ARGB to 12 bytes of RGB - pshufb xmm1, xmm6 - pshufb xmm2, xmm6 - pshufb xmm3, xmm6 - movdqa xmm4, xmm1 // 4 bytes from 1 for 0 - psrldq xmm1, 4 // 8 bytes from 1 - pslldq xmm4, 12 // 4 bytes from 1 for 0 - movdqa xmm5, xmm2 // 8 bytes from 2 for 1 - por xmm0, xmm4 // 4 bytes from 1 for 0 - pslldq xmm5, 8 // 8 bytes from 2 for 1 - movdqu [edx], xmm0 // store 0 - por xmm1, xmm5 // 8 bytes from 2 for 1 - psrldq xmm2, 8 // 4 bytes from 2 - pslldq xmm3, 4 // 12 bytes from 3 for 2 - por xmm2, xmm3 // 12 bytes from 3 for 2 - movdqu [edx + 16], xmm1 // store 1 - movdqu [edx + 32], xmm2 // store 2 - lea edx, [edx + 48] - sub ecx, 16 - jg convertloop - ret - } -} - -__declspec(naked) void ARGBToRGB565Row_SSE2(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_rgb - mov ecx, [esp + 12] // width - pcmpeqb xmm3, xmm3 // generate mask 0x0000001f - psrld xmm3, 27 - pcmpeqb xmm4, xmm4 // generate mask 0x000007e0 - psrld xmm4, 26 - pslld xmm4, 5 - pcmpeqb xmm5, xmm5 // generate mask 0xfffff800 - pslld xmm5, 11 - - convertloop: - movdqu xmm0, [eax] // fetch 4 pixels of argb - movdqa xmm1, xmm0 // B - movdqa xmm2, xmm0 // G - pslld xmm0, 8 // R - psrld xmm1, 3 // B - psrld xmm2, 5 // G - psrad xmm0, 16 // R - pand xmm1, xmm3 // B - pand xmm2, xmm4 // G - pand xmm0, xmm5 // R - por xmm1, xmm2 // BG - por xmm0, xmm1 // BGR - packssdw xmm0, xmm0 - lea eax, [eax + 16] - movq qword ptr [edx], xmm0 // store 4 pixels of RGB565 - lea edx, [edx + 8] - sub ecx, 4 - jg convertloop - ret - } -} - -__declspec(naked) void ARGBToRGB565DitherRow_SSE2(const uint8_t* src_argb, - uint8_t* dst_rgb, - const uint32_t dither4, - int width) { - __asm { - - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_rgb - movd xmm6, [esp + 12] // dither4 - mov ecx, [esp + 16] // width - punpcklbw xmm6, xmm6 // make dither 16 bytes - movdqa xmm7, xmm6 - punpcklwd xmm6, xmm6 - punpckhwd xmm7, xmm7 - pcmpeqb xmm3, xmm3 // generate mask 0x0000001f - psrld xmm3, 27 - pcmpeqb xmm4, xmm4 // generate mask 0x000007e0 - psrld xmm4, 26 - pslld xmm4, 5 - pcmpeqb xmm5, xmm5 // generate mask 0xfffff800 - pslld xmm5, 11 - - convertloop: - movdqu xmm0, [eax] // fetch 4 pixels of argb - paddusb xmm0, xmm6 // add dither - movdqa xmm1, xmm0 // B - movdqa xmm2, xmm0 // G - pslld xmm0, 8 // R - psrld xmm1, 3 // B - psrld xmm2, 5 // G - psrad xmm0, 16 // R - pand xmm1, xmm3 // B - pand xmm2, xmm4 // G - pand xmm0, xmm5 // R - por xmm1, xmm2 // BG - por xmm0, xmm1 // BGR - packssdw xmm0, xmm0 - lea eax, [eax + 16] - movq qword ptr [edx], xmm0 // store 4 pixels of RGB565 - lea edx, [edx + 8] - sub ecx, 4 - jg convertloop - ret - } -} - #ifdef HAS_ARGBTORGB565DITHERROW_AVX2 -__declspec(naked) void ARGBToRGB565DitherRow_AVX2(const uint8_t* src_argb, - uint8_t* dst_rgb, - const uint32_t dither4, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_rgb - vbroadcastss xmm6, [esp + 12] // dither4 - mov ecx, [esp + 16] // width - vpunpcklbw xmm6, xmm6, xmm6 // make dither 32 bytes - vpermq ymm6, ymm6, 0xd8 - vpunpcklwd ymm6, ymm6, ymm6 - vpcmpeqb ymm3, ymm3, ymm3 // generate mask 0x0000001f - vpsrld ymm3, ymm3, 27 - vpcmpeqb ymm4, ymm4, ymm4 // generate mask 0x000007e0 - vpsrld ymm4, ymm4, 26 - vpslld ymm4, ymm4, 5 - vpslld ymm5, ymm3, 11 // generate mask 0x0000f800 +LIBYUV_TARGET_AVX2 +void ARGBToRGB565DitherRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_rgb, + uint32_t dither4, + int width) { + __m128i dither_shuf = + _mm_setr_epi8(0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3); + __m128i d128 = _mm_shuffle_epi8(_mm_cvtsi32_si128((int)dither4), dither_shuf); + __m256i ymm_dither = _mm256_broadcastsi128_si256(d128); + __m256i mask_b = _mm256_set1_epi32(0x0000001f); + __m256i mask_g = _mm256_set1_epi32(0x000007e0); + __m256i mask_r = _mm256_set1_epi32(0x0000f800); - convertloop: - vmovdqu ymm0, [eax] // fetch 8 pixels of argb - vpaddusb ymm0, ymm0, ymm6 // add dither - vpsrld ymm2, ymm0, 5 // G - vpsrld ymm1, ymm0, 3 // B - vpsrld ymm0, ymm0, 8 // R - vpand ymm2, ymm2, ymm4 // G - vpand ymm1, ymm1, ymm3 // B - vpand ymm0, ymm0, ymm5 // R - vpor ymm1, ymm1, ymm2 // BG - vpor ymm0, ymm0, ymm1 // BGR - vpackusdw ymm0, ymm0, ymm0 - vpermq ymm0, ymm0, 0xd8 - lea eax, [eax + 32] - vmovdqu [edx], xmm0 // store 8 pixels of RGB565 - lea edx, [edx + 16] - sub ecx, 8 - jg convertloop - vzeroupper - ret + while (width > 0) { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_argb); + ymm0 = _mm256_adds_epu8(ymm0, ymm_dither); + __m256i ymm2 = _mm256_srli_epi32(ymm0, 5); + __m256i ymm1 = _mm256_srli_epi32(ymm0, 3); + ymm0 = _mm256_srli_epi32(ymm0, 8); + ymm2 = _mm256_and_si256(ymm2, mask_g); + ymm1 = _mm256_and_si256(ymm1, mask_b); + ymm0 = _mm256_and_si256(ymm0, mask_r); + ymm1 = _mm256_or_si256(ymm2, ymm1); + ymm0 = _mm256_or_si256(ymm1, ymm0); + ymm0 = _mm256_packus_epi32(ymm0, ymm0); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0xd8); + _mm_storeu_si128((__m128i*)dst_rgb, _mm256_castsi256_si128(ymm0)); + src_argb += 32; + dst_rgb += 16; + width -= 8; } + _mm256_zeroupper(); } #endif // HAS_ARGBTORGB565DITHERROW_AVX2 -// TODO(fbarchard): Improve sign extension/packing. -__declspec(naked) void ARGBToARGB1555Row_SSE2(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_rgb - mov ecx, [esp + 12] // width - pcmpeqb xmm4, xmm4 // generate mask 0x0000001f - psrld xmm4, 27 - movdqa xmm5, xmm4 // generate mask 0x000003e0 - pslld xmm5, 5 - movdqa xmm6, xmm4 // generate mask 0x00007c00 - pslld xmm6, 10 - pcmpeqb xmm7, xmm7 // generate mask 0xffff8000 - pslld xmm7, 15 - - convertloop: - movdqu xmm0, [eax] // fetch 4 pixels of argb - movdqa xmm1, xmm0 // B - movdqa xmm2, xmm0 // G - movdqa xmm3, xmm0 // R - psrad xmm0, 16 // A - psrld xmm1, 3 // B - psrld xmm2, 6 // G - psrld xmm3, 9 // R - pand xmm0, xmm7 // A - pand xmm1, xmm4 // B - pand xmm2, xmm5 // G - pand xmm3, xmm6 // R - por xmm0, xmm1 // BA - por xmm2, xmm3 // GR - por xmm0, xmm2 // BGRA - packssdw xmm0, xmm0 - lea eax, [eax + 16] - movq qword ptr [edx], xmm0 // store 4 pixels of ARGB1555 - lea edx, [edx + 8] - sub ecx, 4 - jg convertloop - ret - } -} - -__declspec(naked) void ARGBToARGB4444Row_SSE2(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_rgb - mov ecx, [esp + 12] // width - pcmpeqb xmm4, xmm4 // generate mask 0xf000f000 - psllw xmm4, 12 - movdqa xmm3, xmm4 // generate mask 0x00f000f0 - psrlw xmm3, 8 - - convertloop: - movdqu xmm0, [eax] // fetch 4 pixels of argb - movdqa xmm1, xmm0 - pand xmm0, xmm3 // low nibble - pand xmm1, xmm4 // high nibble - psrld xmm0, 4 - psrld xmm1, 8 - por xmm0, xmm1 - packuswb xmm0, xmm0 - lea eax, [eax + 16] - movq qword ptr [edx], xmm0 // store 4 pixels of ARGB4444 - lea edx, [edx + 8] - sub ecx, 4 - jg convertloop - ret - } -} - #ifdef HAS_ARGBTORGB565ROW_AVX2 -__declspec(naked) void ARGBToRGB565Row_AVX2(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_rgb - mov ecx, [esp + 12] // width - vpcmpeqb ymm3, ymm3, ymm3 // generate mask 0x0000001f - vpsrld ymm3, ymm3, 27 - vpcmpeqb ymm4, ymm4, ymm4 // generate mask 0x000007e0 - vpsrld ymm4, ymm4, 26 - vpslld ymm4, ymm4, 5 - vpslld ymm5, ymm3, 11 // generate mask 0x0000f800 +LIBYUV_TARGET_AVX2 +void ARGBToRGB565Row_AVX2(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width) { + __m256i mask_b = _mm256_set1_epi32(0x0000001f); + __m256i mask_g = _mm256_set1_epi32(0x000007e0); + __m256i mask_r = _mm256_set1_epi32(0x0000f800); - convertloop: - vmovdqu ymm0, [eax] // fetch 8 pixels of argb - vpsrld ymm2, ymm0, 5 // G - vpsrld ymm1, ymm0, 3 // B - vpsrld ymm0, ymm0, 8 // R - vpand ymm2, ymm2, ymm4 // G - vpand ymm1, ymm1, ymm3 // B - vpand ymm0, ymm0, ymm5 // R - vpor ymm1, ymm1, ymm2 // BG - vpor ymm0, ymm0, ymm1 // BGR - vpackusdw ymm0, ymm0, ymm0 - vpermq ymm0, ymm0, 0xd8 - lea eax, [eax + 32] - vmovdqu [edx], xmm0 // store 8 pixels of RGB565 - lea edx, [edx + 16] - sub ecx, 8 - jg convertloop - vzeroupper - ret + while (width > 0) { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_argb); + __m256i ymm2 = _mm256_srli_epi32(ymm0, 5); + __m256i ymm1 = _mm256_srli_epi32(ymm0, 3); + ymm0 = _mm256_srli_epi32(ymm0, 8); + ymm2 = _mm256_and_si256(ymm2, mask_g); + ymm1 = _mm256_and_si256(ymm1, mask_b); + ymm0 = _mm256_and_si256(ymm0, mask_r); + ymm1 = _mm256_or_si256(ymm2, ymm1); + ymm0 = _mm256_or_si256(ymm1, ymm0); + ymm0 = _mm256_packus_epi32(ymm0, ymm0); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0xd8); + _mm_storeu_si128((__m128i*)dst_rgb, _mm256_castsi256_si128(ymm0)); + src_argb += 32; + dst_rgb += 16; + width -= 8; } + _mm256_zeroupper(); } #endif // HAS_ARGBTORGB565ROW_AVX2 #ifdef HAS_ARGBTOARGB1555ROW_AVX2 -__declspec(naked) void ARGBToARGB1555Row_AVX2(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_rgb - mov ecx, [esp + 12] // width - vpcmpeqb ymm4, ymm4, ymm4 - vpsrld ymm4, ymm4, 27 // generate mask 0x0000001f - vpslld ymm5, ymm4, 5 // generate mask 0x000003e0 - vpslld ymm6, ymm4, 10 // generate mask 0x00007c00 - vpcmpeqb ymm7, ymm7, ymm7 // generate mask 0xffff8000 - vpslld ymm7, ymm7, 15 +LIBYUV_TARGET_AVX2 +void ARGBToARGB1555Row_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb1555, + int width) { + __m256i mask_b = _mm256_set1_epi32(0x0000001f); + __m256i mask_g = _mm256_set1_epi32(0x000003e0); + __m256i mask_r = _mm256_set1_epi32(0x00007c00); + __m256i mask_a = _mm256_set1_epi32(0x00008000); - convertloop: - vmovdqu ymm0, [eax] // fetch 8 pixels of argb - vpsrld ymm3, ymm0, 9 // R - vpsrld ymm2, ymm0, 6 // G - vpsrld ymm1, ymm0, 3 // B - vpsrad ymm0, ymm0, 16 // A - vpand ymm3, ymm3, ymm6 // R - vpand ymm2, ymm2, ymm5 // G - vpand ymm1, ymm1, ymm4 // B - vpand ymm0, ymm0, ymm7 // A - vpor ymm0, ymm0, ymm1 // BA - vpor ymm2, ymm2, ymm3 // GR - vpor ymm0, ymm0, ymm2 // BGRA - vpackssdw ymm0, ymm0, ymm0 - vpermq ymm0, ymm0, 0xd8 - lea eax, [eax + 32] - vmovdqu [edx], xmm0 // store 8 pixels of ARGB1555 - lea edx, [edx + 16] - sub ecx, 8 - jg convertloop - vzeroupper - ret + while (width > 0) { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_argb); + __m256i ymm2 = _mm256_srli_epi32(ymm0, 6); + __m256i ymm1 = _mm256_srli_epi32(ymm0, 3); + __m256i ymm7 = _mm256_srli_epi32(ymm0, 16); + ymm0 = _mm256_srli_epi32(ymm0, 9); + ymm2 = _mm256_and_si256(ymm2, mask_g); + ymm1 = _mm256_and_si256(ymm1, mask_b); + ymm7 = _mm256_and_si256(ymm7, mask_a); + ymm0 = _mm256_and_si256(ymm0, mask_r); + ymm1 = _mm256_or_si256(ymm2, ymm1); + ymm0 = _mm256_or_si256(ymm7, ymm0); + ymm0 = _mm256_or_si256(ymm1, ymm0); + ymm0 = _mm256_packus_epi32(ymm0, ymm0); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0xd8); + _mm_storeu_si128((__m128i*)dst_argb1555, _mm256_castsi256_si128(ymm0)); + src_argb += 32; + dst_argb1555 += 16; + width -= 8; } + _mm256_zeroupper(); } #endif // HAS_ARGBTOARGB1555ROW_AVX2 #ifdef HAS_ARGBTOARGB4444ROW_AVX2 -__declspec(naked) void ARGBToARGB4444Row_AVX2(const uint8_t* src_argb, - uint8_t* dst_rgb, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_rgb - mov ecx, [esp + 12] // width - vpcmpeqb ymm4, ymm4, ymm4 // generate mask 0xf000f000 - vpsllw ymm4, ymm4, 12 - vpsrlw ymm3, ymm4, 8 // generate mask 0x00f000f0 +LIBYUV_TARGET_AVX2 +void ARGBToARGB4444Row_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb4444, + int width) { + __m256i mask_b = _mm256_set1_epi32(0x0000000f); + __m256i mask_g = _mm256_set1_epi32(0x000000f0); + __m256i mask_r = _mm256_set1_epi32(0x00000f00); + __m256i mask_a = _mm256_set1_epi32(0x0000f000); - convertloop: - vmovdqu ymm0, [eax] // fetch 8 pixels of argb - vpand ymm1, ymm0, ymm4 // high nibble - vpand ymm0, ymm0, ymm3 // low nibble - vpsrld ymm1, ymm1, 8 - vpsrld ymm0, ymm0, 4 - vpor ymm0, ymm0, ymm1 - vpackuswb ymm0, ymm0, ymm0 - vpermq ymm0, ymm0, 0xd8 - lea eax, [eax + 32] - vmovdqu [edx], xmm0 // store 8 pixels of ARGB4444 - lea edx, [edx + 16] - sub ecx, 8 - jg convertloop - vzeroupper - ret + while (width > 0) { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src_argb); + __m256i ymm2 = _mm256_srli_epi32(ymm0, 8); + __m256i ymm1 = _mm256_srli_epi32(ymm0, 4); + __m256i ymm7 = _mm256_srli_epi32(ymm0, 16); + ymm0 = _mm256_srli_epi32(ymm0, 12); + ymm2 = _mm256_and_si256(ymm2, mask_g); + ymm1 = _mm256_and_si256(ymm1, mask_b); + ymm7 = _mm256_and_si256(ymm7, mask_a); + ymm0 = _mm256_and_si256(ymm0, mask_r); + ymm1 = _mm256_or_si256(ymm2, ymm1); + ymm0 = _mm256_or_si256(ymm7, ymm0); + ymm0 = _mm256_or_si256(ymm1, ymm0); + ymm0 = _mm256_packus_epi32(ymm0, ymm0); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0xd8); + _mm_storeu_si128((__m128i*)dst_argb4444, _mm256_castsi256_si128(ymm0)); + src_argb += 32; + dst_argb4444 += 16; + width -= 8; } + _mm256_zeroupper(); } #endif // HAS_ARGBTOARGB4444ROW_AVX2 -// Convert 16 ARGB pixels (64 bytes) to 16 Y values. -__declspec(naked) void ARGBToYRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_y, - int width) { - __asm { - mov eax, [esp + 4] /* src_argb */ - mov edx, [esp + 8] /* dst_y */ - mov ecx, [esp + 12] /* width */ - movdqa xmm4, xmmword ptr kARGBToY - movdqa xmm5, xmmword ptr kAddY16 +#ifdef HAS_RGB24TOARGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void RGB24ToARGBRow_AVX2(const uint8_t* src_rgb24, + uint8_t* dst_argb, + int width) { + __m256i ymm_alpha = _mm256_set1_epi32(0xff000000); + __m256i ymm_shuf = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShuffleMaskRGB24ToARGB[0])); + __m256i ymm_shuf2 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShuffleMaskRGB24ToARGB[1])); - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + 32] - movdqu xmm3, [eax + 48] - pmaddubsw xmm0, xmm4 - pmaddubsw xmm1, xmm4 - pmaddubsw xmm2, xmm4 - pmaddubsw xmm3, xmm4 - lea eax, [eax + 64] - phaddw xmm0, xmm1 - phaddw xmm2, xmm3 - psrlw xmm0, 7 - psrlw xmm2, 7 - packuswb xmm0, xmm2 - paddb xmm0, xmm5 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg convertloop - ret + while (width > 0) { + __m128i xmm0 = _mm_loadu_si128((const __m128i*)src_rgb24); + __m256i ymm0 = _mm256_castsi128_si256(xmm0); + ymm0 = _mm256_inserti128_si256( + ymm0, _mm_loadu_si128((const __m128i*)(src_rgb24 + 12)), 1); + + __m128i xmm1 = _mm_loadu_si128((const __m128i*)(src_rgb24 + 24)); + __m256i ymm1 = _mm256_castsi128_si256(xmm1); + ymm1 = _mm256_inserti128_si256( + ymm1, _mm_loadu_si128((const __m128i*)(src_rgb24 + 36)), 1); + + __m128i xmm2 = _mm_loadu_si128((const __m128i*)(src_rgb24 + 48)); + __m256i ymm2 = _mm256_castsi128_si256(xmm2); + ymm2 = _mm256_inserti128_si256( + ymm2, _mm_loadu_si128((const __m128i*)(src_rgb24 + 60)), 1); + + __m128i xmm3 = _mm_loadu_si128((const __m128i*)(src_rgb24 + 68)); + __m256i ymm3 = _mm256_castsi128_si256(xmm3); + ymm3 = _mm256_inserti128_si256( + ymm3, _mm_loadu_si128((const __m128i*)(src_rgb24 + 80)), 1); + + ymm0 = _mm256_shuffle_epi8(ymm0, ymm_shuf); + ymm1 = _mm256_shuffle_epi8(ymm1, ymm_shuf); + ymm2 = _mm256_shuffle_epi8(ymm2, ymm_shuf); + ymm3 = _mm256_shuffle_epi8(ymm3, ymm_shuf2); + + ymm0 = _mm256_or_si256(ymm0, ymm_alpha); + ymm1 = _mm256_or_si256(ymm1, ymm_alpha); + ymm2 = _mm256_or_si256(ymm2, ymm_alpha); + ymm3 = _mm256_or_si256(ymm3, ymm_alpha); + + _mm256_storeu_si256((__m256i*)dst_argb, ymm0); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), ymm1); + _mm256_storeu_si256((__m256i*)(dst_argb + 64), ymm2); + _mm256_storeu_si256((__m256i*)(dst_argb + 96), ymm3); + + src_rgb24 += 96; + dst_argb += 128; + width -= 32; } + _mm256_zeroupper(); } +#endif // HAS_RGB24TOARGBROW_AVX2 -// Convert 16 ARGB pixels (64 bytes) to 16 YJ values. -// Same as ARGBToYRow but different coefficients, no add 16, but do rounding. -__declspec(naked) void ARGBToYJRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_y, - int width) { - __asm { - mov eax, [esp + 4] /* src_argb */ - mov edx, [esp + 8] /* dst_y */ - mov ecx, [esp + 12] /* width */ - movdqa xmm4, xmmword ptr kARGBToYJ - movdqa xmm5, xmmword ptr kAddYJ64 - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + 32] - movdqu xmm3, [eax + 48] - pmaddubsw xmm0, xmm4 - pmaddubsw xmm1, xmm4 - pmaddubsw xmm2, xmm4 - pmaddubsw xmm3, xmm4 - lea eax, [eax + 64] - phaddw xmm0, xmm1 - phaddw xmm2, xmm3 - paddw xmm0, xmm5 // Add .5 for rounding. - paddw xmm2, xmm5 - psrlw xmm0, 7 - psrlw xmm2, 7 - packuswb xmm0, xmm2 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg convertloop - ret +#ifdef HAS_ARGBSHUFFLEROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBShuffleRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + const uint8_t* shuffler, + int width) { + __m256i control = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)shuffler)); + while (width >= 16) { + __m256i row = _mm256_loadu_si256((const __m256i*)src_argb); + __m256i row1 = _mm256_loadu_si256((const __m256i*)(src_argb + 32)); + row = _mm256_shuffle_epi8(row, control); + row1 = _mm256_shuffle_epi8(row1, control); + _mm256_storeu_si256((__m256i*)dst_argb, row); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), row1); + src_argb += 64; + dst_argb += 64; + width -= 16; } + _mm256_zeroupper(); } +#endif // HAS_ARGBSHUFFLEROW_AVX2 -#ifdef HAS_ARGBTOYROW_AVX2 -// vpermd for vphaddw + vpackuswb vpermd. -static const lvec32 kPermdARGBToY_AVX = {0, 4, 1, 5, 2, 6, 3, 7}; - -// Convert 32 ARGB pixels (128 bytes) to 32 Y values. -__declspec(naked) void ARGBToYRow_AVX2(const uint8_t* src_argb, - uint8_t* dst_y, - int width) { - __asm { - mov eax, [esp + 4] /* src_argb */ - mov edx, [esp + 8] /* dst_y */ - mov ecx, [esp + 12] /* width */ - vbroadcastf128 ymm4, xmmword ptr kARGBToY - vbroadcastf128 ymm5, xmmword ptr kAddY16 - vmovdqu ymm6, ymmword ptr kPermdARGBToY_AVX - - convertloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - vmovdqu ymm2, [eax + 64] - vmovdqu ymm3, [eax + 96] - vpmaddubsw ymm0, ymm0, ymm4 - vpmaddubsw ymm1, ymm1, ymm4 - vpmaddubsw ymm2, ymm2, ymm4 - vpmaddubsw ymm3, ymm3, ymm4 - lea eax, [eax + 128] - vphaddw ymm0, ymm0, ymm1 // mutates. - vphaddw ymm2, ymm2, ymm3 - vpsrlw ymm0, ymm0, 7 - vpsrlw ymm2, ymm2, 7 - vpackuswb ymm0, ymm0, ymm2 // mutates. - vpermd ymm0, ymm6, ymm0 // For vphaddw + vpackuswb mutation. - vpaddb ymm0, ymm0, ymm5 // add 16 for Y - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 32 - jg convertloop - vzeroupper - ret +#ifdef HAS_ARGBSHUFFLEROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBShuffleRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + const uint8_t* shuffler, + int width) { + __m512i control = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)shuffler)); + while (width >= 32) { + __m512i row = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i row1 = _mm512_loadu_si512((const __m512i*)(src_argb + 64)); + row = _mm512_shuffle_epi8(row, control); + row1 = _mm512_shuffle_epi8(row1, control); + _mm512_storeu_si512((__m512i*)dst_argb, row); + _mm512_storeu_si512((__m512i*)(dst_argb + 64), row1); + src_argb += 128; + dst_argb += 128; + width -= 32; } + if (width > 0) { + uint32_t mask = (1u << width) - 1u; + __mmask16 mask0 = (__mmask16)mask; + __mmask16 mask1 = (__mmask16)(mask >> 16); + __m512i row = _mm512_maskz_loadu_epi32(mask0, src_argb); + __m512i row1 = _mm512_maskz_loadu_epi32(mask1, src_argb + 64); + row = _mm512_shuffle_epi8(row, control); + row1 = _mm512_shuffle_epi8(row1, control); + _mm512_mask_storeu_epi32(dst_argb, mask0, row); + _mm512_mask_storeu_epi32(dst_argb + 64, mask1, row1); + } + _mm256_zeroupper(); } -#endif // HAS_ARGBTOYROW_AVX2 - -#ifdef HAS_ARGBTOYJROW_AVX2 -// Convert 32 ARGB pixels (128 bytes) to 32 Y values. -__declspec(naked) void ARGBToYJRow_AVX2(const uint8_t* src_argb, - uint8_t* dst_y, - int width) { - __asm { - mov eax, [esp + 4] /* src_argb */ - mov edx, [esp + 8] /* dst_y */ - mov ecx, [esp + 12] /* width */ - vbroadcastf128 ymm4, xmmword ptr kARGBToYJ - vbroadcastf128 ymm5, xmmword ptr kAddYJ64 - vmovdqu ymm6, ymmword ptr kPermdARGBToY_AVX - - convertloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - vmovdqu ymm2, [eax + 64] - vmovdqu ymm3, [eax + 96] - vpmaddubsw ymm0, ymm0, ymm4 - vpmaddubsw ymm1, ymm1, ymm4 - vpmaddubsw ymm2, ymm2, ymm4 - vpmaddubsw ymm3, ymm3, ymm4 - lea eax, [eax + 128] - vphaddw ymm0, ymm0, ymm1 // mutates. - vphaddw ymm2, ymm2, ymm3 - vpaddw ymm0, ymm0, ymm5 // Add .5 for rounding. - vpaddw ymm2, ymm2, ymm5 - vpsrlw ymm0, ymm0, 7 - vpsrlw ymm2, ymm2, 7 - vpackuswb ymm0, ymm0, ymm2 // mutates. - vpermd ymm0, ymm6, ymm0 // For vphaddw + vpackuswb mutation. - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 32 - jg convertloop - - vzeroupper - ret - } -} -#endif // HAS_ARGBTOYJROW_AVX2 - -__declspec(naked) void BGRAToYRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_y, - int width) { - __asm { - mov eax, [esp + 4] /* src_argb */ - mov edx, [esp + 8] /* dst_y */ - mov ecx, [esp + 12] /* width */ - movdqa xmm4, xmmword ptr kBGRAToY - movdqa xmm5, xmmword ptr kAddY16 - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + 32] - movdqu xmm3, [eax + 48] - pmaddubsw xmm0, xmm4 - pmaddubsw xmm1, xmm4 - pmaddubsw xmm2, xmm4 - pmaddubsw xmm3, xmm4 - lea eax, [eax + 64] - phaddw xmm0, xmm1 - phaddw xmm2, xmm3 - psrlw xmm0, 7 - psrlw xmm2, 7 - packuswb xmm0, xmm2 - paddb xmm0, xmm5 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg convertloop - ret - } -} - -__declspec(naked) void ABGRToYRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_y, - int width) { - __asm { - mov eax, [esp + 4] /* src_argb */ - mov edx, [esp + 8] /* dst_y */ - mov ecx, [esp + 12] /* width */ - movdqa xmm4, xmmword ptr kABGRToY - movdqa xmm5, xmmword ptr kAddY16 - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + 32] - movdqu xmm3, [eax + 48] - pmaddubsw xmm0, xmm4 - pmaddubsw xmm1, xmm4 - pmaddubsw xmm2, xmm4 - pmaddubsw xmm3, xmm4 - lea eax, [eax + 64] - phaddw xmm0, xmm1 - phaddw xmm2, xmm3 - psrlw xmm0, 7 - psrlw xmm2, 7 - packuswb xmm0, xmm2 - paddb xmm0, xmm5 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg convertloop - ret - } -} - -__declspec(naked) void RGBAToYRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_y, - int width) { - __asm { - mov eax, [esp + 4] /* src_argb */ - mov edx, [esp + 8] /* dst_y */ - mov ecx, [esp + 12] /* width */ - movdqa xmm4, xmmword ptr kRGBAToY - movdqa xmm5, xmmword ptr kAddY16 - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + 32] - movdqu xmm3, [eax + 48] - pmaddubsw xmm0, xmm4 - pmaddubsw xmm1, xmm4 - pmaddubsw xmm2, xmm4 - pmaddubsw xmm3, xmm4 - lea eax, [eax + 64] - phaddw xmm0, xmm1 - phaddw xmm2, xmm3 - psrlw xmm0, 7 - psrlw xmm2, 7 - packuswb xmm0, xmm2 - paddb xmm0, xmm5 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg convertloop - ret - } -} - -__declspec(naked) void ARGBToUVRow_SSSE3(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_argb - mov esi, [esp + 8 + 8] // src_stride_argb - mov edx, [esp + 8 + 12] // dst_u - mov edi, [esp + 8 + 16] // dst_v - mov ecx, [esp + 8 + 20] // width - movdqa xmm5, xmmword ptr kAddUV128 - movdqa xmm6, xmmword ptr kARGBToV - movdqa xmm7, xmmword ptr kARGBToU - sub edi, edx // stride from u to v - - convertloop: - /* step 1 - subsample 16x2 argb pixels to 8x1 */ - movdqu xmm0, [eax] - movdqu xmm4, [eax + esi] - pavgb xmm0, xmm4 - movdqu xmm1, [eax + 16] - movdqu xmm4, [eax + esi + 16] - pavgb xmm1, xmm4 - movdqu xmm2, [eax + 32] - movdqu xmm4, [eax + esi + 32] - pavgb xmm2, xmm4 - movdqu xmm3, [eax + 48] - movdqu xmm4, [eax + esi + 48] - pavgb xmm3, xmm4 - - lea eax, [eax + 64] - movdqa xmm4, xmm0 - shufps xmm0, xmm1, 0x88 - shufps xmm4, xmm1, 0xdd - pavgb xmm0, xmm4 - movdqa xmm4, xmm2 - shufps xmm2, xmm3, 0x88 - shufps xmm4, xmm3, 0xdd - pavgb xmm2, xmm4 - - // step 2 - convert to U and V - // from here down is very similar to Y code except - // instead of 16 different pixels, its 8 pixels of U and 8 of V - movdqa xmm1, xmm0 - movdqa xmm3, xmm2 - pmaddubsw xmm0, xmm7 // U - pmaddubsw xmm2, xmm7 - pmaddubsw xmm1, xmm6 // V - pmaddubsw xmm3, xmm6 - phaddw xmm0, xmm2 - phaddw xmm1, xmm3 - psraw xmm0, 8 - psraw xmm1, 8 - packsswb xmm0, xmm1 - paddb xmm0, xmm5 // -> unsigned - - // step 3 - store 8 U and 8 V values - movlps qword ptr [edx], xmm0 // U - movhps qword ptr [edx + edi], xmm0 // V - lea edx, [edx + 8] - sub ecx, 16 - jg convertloop - - pop edi - pop esi - ret - } -} - -__declspec(naked) void ARGBToUVJRow_SSSE3(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_argb - mov esi, [esp + 8 + 8] // src_stride_argb - mov edx, [esp + 8 + 12] // dst_u - mov edi, [esp + 8 + 16] // dst_v - mov ecx, [esp + 8 + 20] // width - movdqa xmm5, xmmword ptr kAddUVJ128 - movdqa xmm6, xmmword ptr kARGBToVJ - movdqa xmm7, xmmword ptr kARGBToUJ - sub edi, edx // stride from u to v - - convertloop: - /* step 1 - subsample 16x2 argb pixels to 8x1 */ - movdqu xmm0, [eax] - movdqu xmm4, [eax + esi] - pavgb xmm0, xmm4 - movdqu xmm1, [eax + 16] - movdqu xmm4, [eax + esi + 16] - pavgb xmm1, xmm4 - movdqu xmm2, [eax + 32] - movdqu xmm4, [eax + esi + 32] - pavgb xmm2, xmm4 - movdqu xmm3, [eax + 48] - movdqu xmm4, [eax + esi + 48] - pavgb xmm3, xmm4 - - lea eax, [eax + 64] - movdqa xmm4, xmm0 - shufps xmm0, xmm1, 0x88 - shufps xmm4, xmm1, 0xdd - pavgb xmm0, xmm4 - movdqa xmm4, xmm2 - shufps xmm2, xmm3, 0x88 - shufps xmm4, xmm3, 0xdd - pavgb xmm2, xmm4 - - // step 2 - convert to U and V - // from here down is very similar to Y code except - // instead of 16 different pixels, its 8 pixels of U and 8 of V - movdqa xmm1, xmm0 - movdqa xmm3, xmm2 - pmaddubsw xmm0, xmm7 // U - pmaddubsw xmm2, xmm7 - pmaddubsw xmm1, xmm6 // V - pmaddubsw xmm3, xmm6 - phaddw xmm0, xmm2 - phaddw xmm1, xmm3 - paddw xmm0, xmm5 // +.5 rounding -> unsigned - paddw xmm1, xmm5 - psraw xmm0, 8 - psraw xmm1, 8 - packsswb xmm0, xmm1 - - // step 3 - store 8 U and 8 V values - movlps qword ptr [edx], xmm0 // U - movhps qword ptr [edx + edi], xmm0 // V - lea edx, [edx + 8] - sub ecx, 16 - jg convertloop - - pop edi - pop esi - ret - } -} - -#ifdef HAS_ARGBTOUVROW_AVX2 -__declspec(naked) void ARGBToUVRow_AVX2(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_argb - mov esi, [esp + 8 + 8] // src_stride_argb - mov edx, [esp + 8 + 12] // dst_u - mov edi, [esp + 8 + 16] // dst_v - mov ecx, [esp + 8 + 20] // width - vbroadcastf128 ymm5, xmmword ptr kAddUV128 - vbroadcastf128 ymm6, xmmword ptr kARGBToV - vbroadcastf128 ymm7, xmmword ptr kARGBToU - sub edi, edx // stride from u to v - - convertloop: - /* step 1 - subsample 32x2 argb pixels to 16x1 */ - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - vmovdqu ymm2, [eax + 64] - vmovdqu ymm3, [eax + 96] - vpavgb ymm0, ymm0, [eax + esi] - vpavgb ymm1, ymm1, [eax + esi + 32] - vpavgb ymm2, ymm2, [eax + esi + 64] - vpavgb ymm3, ymm3, [eax + esi + 96] - lea eax, [eax + 128] - vshufps ymm4, ymm0, ymm1, 0x88 - vshufps ymm0, ymm0, ymm1, 0xdd - vpavgb ymm0, ymm0, ymm4 // mutated by vshufps - vshufps ymm4, ymm2, ymm3, 0x88 - vshufps ymm2, ymm2, ymm3, 0xdd - vpavgb ymm2, ymm2, ymm4 // mutated by vshufps - - // step 2 - convert to U and V - // from here down is very similar to Y code except - // instead of 32 different pixels, its 16 pixels of U and 16 of V - vpmaddubsw ymm1, ymm0, ymm7 // U - vpmaddubsw ymm3, ymm2, ymm7 - vpmaddubsw ymm0, ymm0, ymm6 // V - vpmaddubsw ymm2, ymm2, ymm6 - vphaddw ymm1, ymm1, ymm3 // mutates - vphaddw ymm0, ymm0, ymm2 - vpsraw ymm1, ymm1, 8 - vpsraw ymm0, ymm0, 8 - vpacksswb ymm0, ymm1, ymm0 // mutates - vpermq ymm0, ymm0, 0xd8 // For vpacksswb - vpshufb ymm0, ymm0, ymmword ptr kShufARGBToUV_AVX // for vshufps/vphaddw - vpaddb ymm0, ymm0, ymm5 // -> unsigned - - // step 3 - store 16 U and 16 V values - vextractf128 [edx], ymm0, 0 // U - vextractf128 [edx + edi], ymm0, 1 // V - lea edx, [edx + 16] - sub ecx, 32 - jg convertloop - - pop edi - pop esi - vzeroupper - ret - } -} -#endif // HAS_ARGBTOUVROW_AVX2 - -#ifdef HAS_ARGBTOUVJROW_AVX2 -__declspec(naked) void ARGBToUVJRow_AVX2(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_argb - mov esi, [esp + 8 + 8] // src_stride_argb - mov edx, [esp + 8 + 12] // dst_u - mov edi, [esp + 8 + 16] // dst_v - mov ecx, [esp + 8 + 20] // width - vbroadcastf128 ymm5, xmmword ptr kAddUVJ128 - vbroadcastf128 ymm6, xmmword ptr kARGBToVJ - vbroadcastf128 ymm7, xmmword ptr kARGBToUJ - sub edi, edx // stride from u to v - - convertloop: - /* step 1 - subsample 32x2 argb pixels to 16x1 */ - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - vmovdqu ymm2, [eax + 64] - vmovdqu ymm3, [eax + 96] - vpavgb ymm0, ymm0, [eax + esi] - vpavgb ymm1, ymm1, [eax + esi + 32] - vpavgb ymm2, ymm2, [eax + esi + 64] - vpavgb ymm3, ymm3, [eax + esi + 96] - lea eax, [eax + 128] - vshufps ymm4, ymm0, ymm1, 0x88 - vshufps ymm0, ymm0, ymm1, 0xdd - vpavgb ymm0, ymm0, ymm4 // mutated by vshufps - vshufps ymm4, ymm2, ymm3, 0x88 - vshufps ymm2, ymm2, ymm3, 0xdd - vpavgb ymm2, ymm2, ymm4 // mutated by vshufps - - // step 2 - convert to U and V - // from here down is very similar to Y code except - // instead of 32 different pixels, its 16 pixels of U and 16 of V - vpmaddubsw ymm1, ymm0, ymm7 // U - vpmaddubsw ymm3, ymm2, ymm7 - vpmaddubsw ymm0, ymm0, ymm6 // V - vpmaddubsw ymm2, ymm2, ymm6 - vphaddw ymm1, ymm1, ymm3 // mutates - vphaddw ymm0, ymm0, ymm2 - vpaddw ymm1, ymm1, ymm5 // +.5 rounding -> unsigned - vpaddw ymm0, ymm0, ymm5 - vpsraw ymm1, ymm1, 8 - vpsraw ymm0, ymm0, 8 - vpacksswb ymm0, ymm1, ymm0 // mutates - vpermq ymm0, ymm0, 0xd8 // For vpacksswb - vpshufb ymm0, ymm0, ymmword ptr kShufARGBToUV_AVX // for vshufps/vphaddw - - // step 3 - store 16 U and 16 V values - vextractf128 [edx], ymm0, 0 // U - vextractf128 [edx + edi], ymm0, 1 // V - lea edx, [edx + 16] - sub ecx, 32 - jg convertloop - - pop edi - pop esi - vzeroupper - ret - } -} -#endif // HAS_ARGBTOUVJROW_AVX2 - -__declspec(naked) void ARGBToUV444Row_SSSE3(const uint8_t* src_argb0, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push edi - mov eax, [esp + 4 + 4] // src_argb - mov edx, [esp + 4 + 8] // dst_u - mov edi, [esp + 4 + 12] // dst_v - mov ecx, [esp + 4 + 16] // width - movdqa xmm5, xmmword ptr kAddUV128 - movdqa xmm6, xmmword ptr kARGBToV - movdqa xmm7, xmmword ptr kARGBToU - sub edi, edx // stride from u to v - - convertloop: - /* convert to U and V */ - movdqu xmm0, [eax] // U - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + 32] - movdqu xmm3, [eax + 48] - pmaddubsw xmm0, xmm7 - pmaddubsw xmm1, xmm7 - pmaddubsw xmm2, xmm7 - pmaddubsw xmm3, xmm7 - phaddw xmm0, xmm1 - phaddw xmm2, xmm3 - psraw xmm0, 8 - psraw xmm2, 8 - packsswb xmm0, xmm2 - paddb xmm0, xmm5 - movdqu [edx], xmm0 - - movdqu xmm0, [eax] // V - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + 32] - movdqu xmm3, [eax + 48] - pmaddubsw xmm0, xmm6 - pmaddubsw xmm1, xmm6 - pmaddubsw xmm2, xmm6 - pmaddubsw xmm3, xmm6 - phaddw xmm0, xmm1 - phaddw xmm2, xmm3 - psraw xmm0, 8 - psraw xmm2, 8 - packsswb xmm0, xmm2 - paddb xmm0, xmm5 - lea eax, [eax + 64] - movdqu [edx + edi], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg convertloop - - pop edi - ret - } -} - -__declspec(naked) void BGRAToUVRow_SSSE3(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_argb - mov esi, [esp + 8 + 8] // src_stride_argb - mov edx, [esp + 8 + 12] // dst_u - mov edi, [esp + 8 + 16] // dst_v - mov ecx, [esp + 8 + 20] // width - movdqa xmm5, xmmword ptr kAddUV128 - movdqa xmm6, xmmword ptr kBGRAToV - movdqa xmm7, xmmword ptr kBGRAToU - sub edi, edx // stride from u to v - - convertloop: - /* step 1 - subsample 16x2 argb pixels to 8x1 */ - movdqu xmm0, [eax] - movdqu xmm4, [eax + esi] - pavgb xmm0, xmm4 - movdqu xmm1, [eax + 16] - movdqu xmm4, [eax + esi + 16] - pavgb xmm1, xmm4 - movdqu xmm2, [eax + 32] - movdqu xmm4, [eax + esi + 32] - pavgb xmm2, xmm4 - movdqu xmm3, [eax + 48] - movdqu xmm4, [eax + esi + 48] - pavgb xmm3, xmm4 - - lea eax, [eax + 64] - movdqa xmm4, xmm0 - shufps xmm0, xmm1, 0x88 - shufps xmm4, xmm1, 0xdd - pavgb xmm0, xmm4 - movdqa xmm4, xmm2 - shufps xmm2, xmm3, 0x88 - shufps xmm4, xmm3, 0xdd - pavgb xmm2, xmm4 - - // step 2 - convert to U and V - // from here down is very similar to Y code except - // instead of 16 different pixels, its 8 pixels of U and 8 of V - movdqa xmm1, xmm0 - movdqa xmm3, xmm2 - pmaddubsw xmm0, xmm7 // U - pmaddubsw xmm2, xmm7 - pmaddubsw xmm1, xmm6 // V - pmaddubsw xmm3, xmm6 - phaddw xmm0, xmm2 - phaddw xmm1, xmm3 - psraw xmm0, 8 - psraw xmm1, 8 - packsswb xmm0, xmm1 - paddb xmm0, xmm5 // -> unsigned - - // step 3 - store 8 U and 8 V values - movlps qword ptr [edx], xmm0 // U - movhps qword ptr [edx + edi], xmm0 // V - lea edx, [edx + 8] - sub ecx, 16 - jg convertloop - - pop edi - pop esi - ret - } -} - -__declspec(naked) void ABGRToUVRow_SSSE3(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_argb - mov esi, [esp + 8 + 8] // src_stride_argb - mov edx, [esp + 8 + 12] // dst_u - mov edi, [esp + 8 + 16] // dst_v - mov ecx, [esp + 8 + 20] // width - movdqa xmm5, xmmword ptr kAddUV128 - movdqa xmm6, xmmword ptr kABGRToV - movdqa xmm7, xmmword ptr kABGRToU - sub edi, edx // stride from u to v - - convertloop: - /* step 1 - subsample 16x2 argb pixels to 8x1 */ - movdqu xmm0, [eax] - movdqu xmm4, [eax + esi] - pavgb xmm0, xmm4 - movdqu xmm1, [eax + 16] - movdqu xmm4, [eax + esi + 16] - pavgb xmm1, xmm4 - movdqu xmm2, [eax + 32] - movdqu xmm4, [eax + esi + 32] - pavgb xmm2, xmm4 - movdqu xmm3, [eax + 48] - movdqu xmm4, [eax + esi + 48] - pavgb xmm3, xmm4 - - lea eax, [eax + 64] - movdqa xmm4, xmm0 - shufps xmm0, xmm1, 0x88 - shufps xmm4, xmm1, 0xdd - pavgb xmm0, xmm4 - movdqa xmm4, xmm2 - shufps xmm2, xmm3, 0x88 - shufps xmm4, xmm3, 0xdd - pavgb xmm2, xmm4 - - // step 2 - convert to U and V - // from here down is very similar to Y code except - // instead of 16 different pixels, its 8 pixels of U and 8 of V - movdqa xmm1, xmm0 - movdqa xmm3, xmm2 - pmaddubsw xmm0, xmm7 // U - pmaddubsw xmm2, xmm7 - pmaddubsw xmm1, xmm6 // V - pmaddubsw xmm3, xmm6 - phaddw xmm0, xmm2 - phaddw xmm1, xmm3 - psraw xmm0, 8 - psraw xmm1, 8 - packsswb xmm0, xmm1 - paddb xmm0, xmm5 // -> unsigned - - // step 3 - store 8 U and 8 V values - movlps qword ptr [edx], xmm0 // U - movhps qword ptr [edx + edi], xmm0 // V - lea edx, [edx + 8] - sub ecx, 16 - jg convertloop - - pop edi - pop esi - ret - } -} - -__declspec(naked) void RGBAToUVRow_SSSE3(const uint8_t* src_argb0, - int src_stride_argb, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_argb - mov esi, [esp + 8 + 8] // src_stride_argb - mov edx, [esp + 8 + 12] // dst_u - mov edi, [esp + 8 + 16] // dst_v - mov ecx, [esp + 8 + 20] // width - movdqa xmm5, xmmword ptr kAddUV128 - movdqa xmm6, xmmword ptr kRGBAToV - movdqa xmm7, xmmword ptr kRGBAToU - sub edi, edx // stride from u to v - - convertloop: - /* step 1 - subsample 16x2 argb pixels to 8x1 */ - movdqu xmm0, [eax] - movdqu xmm4, [eax + esi] - pavgb xmm0, xmm4 - movdqu xmm1, [eax + 16] - movdqu xmm4, [eax + esi + 16] - pavgb xmm1, xmm4 - movdqu xmm2, [eax + 32] - movdqu xmm4, [eax + esi + 32] - pavgb xmm2, xmm4 - movdqu xmm3, [eax + 48] - movdqu xmm4, [eax + esi + 48] - pavgb xmm3, xmm4 - - lea eax, [eax + 64] - movdqa xmm4, xmm0 - shufps xmm0, xmm1, 0x88 - shufps xmm4, xmm1, 0xdd - pavgb xmm0, xmm4 - movdqa xmm4, xmm2 - shufps xmm2, xmm3, 0x88 - shufps xmm4, xmm3, 0xdd - pavgb xmm2, xmm4 - - // step 2 - convert to U and V - // from here down is very similar to Y code except - // instead of 16 different pixels, its 8 pixels of U and 8 of V - movdqa xmm1, xmm0 - movdqa xmm3, xmm2 - pmaddubsw xmm0, xmm7 // U - pmaddubsw xmm2, xmm7 - pmaddubsw xmm1, xmm6 // V - pmaddubsw xmm3, xmm6 - phaddw xmm0, xmm2 - phaddw xmm1, xmm3 - psraw xmm0, 8 - psraw xmm1, 8 - packsswb xmm0, xmm1 - paddb xmm0, xmm5 // -> unsigned - - // step 3 - store 8 U and 8 V values - movlps qword ptr [edx], xmm0 // U - movhps qword ptr [edx + edi], xmm0 // V - lea edx, [edx + 8] - sub ecx, 16 - jg convertloop - - pop edi - pop esi - ret - } -} -#endif // HAS_ARGBTOYROW_SSSE3 - -// Read 16 UV from 444 -#define READYUV444_AVX2 \ - __asm { \ - __asm vmovdqu xmm0, [esi] /* U */ \ - __asm vmovdqu xmm1, [esi + edi] /* V */ \ - __asm lea esi, [esi + 16] \ - __asm vpermq ymm0, ymm0, 0xd8 \ - __asm vpermq ymm1, ymm1, 0xd8 \ - __asm vpunpcklbw ymm0, ymm0, ymm1 /* UV */ \ - __asm vmovdqu xmm4, [eax] /* Y */ \ - __asm vpermq ymm4, ymm4, 0xd8 \ - __asm vpunpcklbw ymm4, ymm4, ymm4 \ - __asm lea eax, [eax + 16]} - -// Read 8 UV from 422, upsample to 16 UV. -#define READYUV422_AVX2 \ - __asm { \ - __asm vmovq xmm0, qword ptr [esi] /* U */ \ - __asm vmovq xmm1, qword ptr [esi + edi] /* V */ \ - __asm lea esi, [esi + 8] \ - __asm vpunpcklbw ymm0, ymm0, ymm1 /* UV */ \ - __asm vpermq ymm0, ymm0, 0xd8 \ - __asm vpunpcklwd ymm0, ymm0, ymm0 /* UVUV (upsample) */ \ - __asm vmovdqu xmm4, [eax] /* Y */ \ - __asm vpermq ymm4, ymm4, 0xd8 \ - __asm vpunpcklbw ymm4, ymm4, ymm4 \ - __asm lea eax, [eax + 16]} - -// Read 8 UV from 422, upsample to 16 UV. With 16 Alpha. -#define READYUVA422_AVX2 \ - __asm { \ - __asm vmovq xmm0, qword ptr [esi] /* U */ \ - __asm vmovq xmm1, qword ptr [esi + edi] /* V */ \ - __asm lea esi, [esi + 8] \ - __asm vpunpcklbw ymm0, ymm0, ymm1 /* UV */ \ - __asm vpermq ymm0, ymm0, 0xd8 \ - __asm vpunpcklwd ymm0, ymm0, ymm0 /* UVUV (upsample) */ \ - __asm vmovdqu xmm4, [eax] /* Y */ \ - __asm vpermq ymm4, ymm4, 0xd8 \ - __asm vpunpcklbw ymm4, ymm4, ymm4 \ - __asm lea eax, [eax + 16] \ - __asm vmovdqu xmm5, [ebp] /* A */ \ - __asm vpermq ymm5, ymm5, 0xd8 \ - __asm lea ebp, [ebp + 16]} - -// Read 8 UV from NV12, upsample to 16 UV. -#define READNV12_AVX2 \ - __asm { \ - __asm vmovdqu xmm0, [esi] /* UV */ \ - __asm lea esi, [esi + 16] \ - __asm vpermq ymm0, ymm0, 0xd8 \ - __asm vpunpcklwd ymm0, ymm0, ymm0 /* UVUV (upsample) */ \ - __asm vmovdqu xmm4, [eax] /* Y */ \ - __asm vpermq ymm4, ymm4, 0xd8 \ - __asm vpunpcklbw ymm4, ymm4, ymm4 \ - __asm lea eax, [eax + 16]} - -// Read 8 UV from NV21, upsample to 16 UV. -#define READNV21_AVX2 \ - __asm { \ - __asm vmovdqu xmm0, [esi] /* UV */ \ - __asm lea esi, [esi + 16] \ - __asm vpermq ymm0, ymm0, 0xd8 \ - __asm vpshufb ymm0, ymm0, ymmword ptr kShuffleNV21 \ - __asm vmovdqu xmm4, [eax] /* Y */ \ - __asm vpermq ymm4, ymm4, 0xd8 \ - __asm vpunpcklbw ymm4, ymm4, ymm4 \ - __asm lea eax, [eax + 16]} - -// Read 8 YUY2 with 16 Y and upsample 8 UV to 16 UV. -#define READYUY2_AVX2 \ - __asm { \ - __asm vmovdqu ymm4, [eax] /* YUY2 */ \ - __asm vpshufb ymm4, ymm4, ymmword ptr kShuffleYUY2Y \ - __asm vmovdqu ymm0, [eax] /* UV */ \ - __asm vpshufb ymm0, ymm0, ymmword ptr kShuffleYUY2UV \ - __asm lea eax, [eax + 32]} - -// Read 8 UYVY with 16 Y and upsample 8 UV to 16 UV. -#define READUYVY_AVX2 \ - __asm { \ - __asm vmovdqu ymm4, [eax] /* UYVY */ \ - __asm vpshufb ymm4, ymm4, ymmword ptr kShuffleUYVYY \ - __asm vmovdqu ymm0, [eax] /* UV */ \ - __asm vpshufb ymm0, ymm0, ymmword ptr kShuffleUYVYUV \ - __asm lea eax, [eax + 32]} - -// Convert 16 pixels: 16 UV and 16 Y. -#define YUVTORGB_AVX2(YuvConstants) \ - __asm { \ - __asm vpmaddubsw ymm2, ymm0, ymmword ptr [YuvConstants + KUVTOR] /* R UV */\ - __asm vpmaddubsw ymm1, ymm0, ymmword ptr [YuvConstants + KUVTOG] /* G UV */\ - __asm vpmaddubsw ymm0, ymm0, ymmword ptr [YuvConstants + KUVTOB] /* B UV */\ - __asm vmovdqu ymm3, ymmword ptr [YuvConstants + KUVBIASR] \ - __asm vpsubw ymm2, ymm3, ymm2 \ - __asm vmovdqu ymm3, ymmword ptr [YuvConstants + KUVBIASG] \ - __asm vpsubw ymm1, ymm3, ymm1 \ - __asm vmovdqu ymm3, ymmword ptr [YuvConstants + KUVBIASB] \ - __asm vpsubw ymm0, ymm3, ymm0 /* Step 2: Find Y contribution to 16 R,G,B values */ \ - __asm vpmulhuw ymm4, ymm4, ymmword ptr [YuvConstants + KYTORGB] \ - __asm vpaddsw ymm0, ymm0, ymm4 /* B += Y */ \ - __asm vpaddsw ymm1, ymm1, ymm4 /* G += Y */ \ - __asm vpaddsw ymm2, ymm2, ymm4 /* R += Y */ \ - __asm vpsraw ymm0, ymm0, 6 \ - __asm vpsraw ymm1, ymm1, 6 \ - __asm vpsraw ymm2, ymm2, 6 \ - __asm vpackuswb ymm0, ymm0, ymm0 /* B */ \ - __asm vpackuswb ymm1, ymm1, ymm1 /* G */ \ - __asm vpackuswb ymm2, ymm2, ymm2 /* R */ \ - } - -// Store 16 ARGB values. -#define STOREARGB_AVX2 \ - __asm { \ - __asm vpunpcklbw ymm0, ymm0, ymm1 /* BG */ \ - __asm vpermq ymm0, ymm0, 0xd8 \ - __asm vpunpcklbw ymm2, ymm2, ymm5 /* RA */ \ - __asm vpermq ymm2, ymm2, 0xd8 \ - __asm vpunpcklwd ymm1, ymm0, ymm2 /* BGRA first 8 pixels */ \ - __asm vpunpckhwd ymm0, ymm0, ymm2 /* BGRA next 8 pixels */ \ - __asm vmovdqu 0[edx], ymm1 \ - __asm vmovdqu 32[edx], ymm0 \ - __asm lea edx, [edx + 64]} - -// Store 16 RGBA values. -#define STORERGBA_AVX2 \ - __asm { \ - __asm vpunpcklbw ymm1, ymm1, ymm2 /* GR */ \ - __asm vpermq ymm1, ymm1, 0xd8 \ - __asm vpunpcklbw ymm2, ymm5, ymm0 /* AB */ \ - __asm vpermq ymm2, ymm2, 0xd8 \ - __asm vpunpcklwd ymm0, ymm2, ymm1 /* ABGR first 8 pixels */ \ - __asm vpunpckhwd ymm1, ymm2, ymm1 /* ABGR next 8 pixels */ \ - __asm vmovdqu [edx], ymm0 \ - __asm vmovdqu [edx + 32], ymm1 \ - __asm lea edx, [edx + 64]} +#endif // HAS_ARGBSHUFFLEROW_AVX512BW #ifdef HAS_I422TOARGBROW_AVX2 -// 16 pixels -// 8 UV values upsampled to 16 UV, mixed with 16 Y producing 16 ARGB (64 bytes). -__declspec(naked) void I422ToARGBRow_AVX2( - const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push edi - push ebx - mov eax, [esp + 12 + 4] // Y - mov esi, [esp + 12 + 8] // U - mov edi, [esp + 12 + 12] // V - mov edx, [esp + 12 + 16] // argb - mov ebx, [esp + 12 + 20] // yuvconstants - mov ecx, [esp + 12 + 24] // width - sub edi, esi - vpcmpeqb ymm5, ymm5, ymm5 // generate 0xffffffffffffffff for alpha +LIBYUV_TARGET_AVX2 +void I422ToARGBRow_AVX2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + __m256i ymm_kUVToB = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToB); + __m256i ymm_kUVToG = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToG); + __m256i ymm_kUVToR = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToR); + __m256i ymm_kYToRgb = + _mm256_loadu_si256((const __m256i*)yuvconstants->kYToRgb); + __m256i ymm_kYBiasToRgb = + _mm256_loadu_si256((const __m256i*)yuvconstants->kYBiasToRgb); + __m256i ymm_128 = _mm256_set1_epi8((char)0x80); + __m256i ymm_alpha = _mm256_set1_epi8((char)0xff); + __m256i ymm_u_zero = _mm256_setzero_si256(); - convertloop: - READYUV422_AVX2 - YUVTORGB_AVX2(ebx) - STOREARGB_AVX2 + ptrdiff_t offset = src_v - src_u; - sub ecx, 16 - jg convertloop + while (width >= 16) { + __m128i xmm_u = _mm_loadl_epi64((const __m128i*)src_u); + __m128i xmm_v = _mm_loadl_epi64((const __m128i*)(src_u + offset)); + src_u += 8; - pop ebx - pop edi - pop esi - vzeroupper - ret + __m256i ymm3 = _mm256_insertf128_si256(ymm_u_zero, xmm_u, 0); + __m256i ymm1 = _mm256_insertf128_si256(ymm_u_zero, xmm_v, 0); + + ymm3 = _mm256_unpacklo_epi8(ymm3, ymm1); + ymm3 = _mm256_permute4x64_epi64(ymm3, 0xd8); + ymm3 = _mm256_unpacklo_epi16(ymm3, ymm3); + + __m128i xmm_y = _mm_loadu_si128((const __m128i*)src_y); + src_y += 16; + __m256i ymm4 = _mm256_insertf128_si256(ymm_u_zero, xmm_y, 0); + ymm4 = _mm256_permute4x64_epi64(ymm4, 0xd8); + ymm4 = _mm256_unpacklo_epi8(ymm4, ymm4); + + ymm3 = _mm256_sub_epi8(ymm3, ymm_128); + ymm4 = _mm256_mulhi_epu16(ymm4, ymm_kYToRgb); + + __m256i ymm0 = _mm256_maddubs_epi16(ymm_kUVToB, ymm3); + ymm1 = _mm256_maddubs_epi16(ymm_kUVToG, ymm3); + __m256i ymm2 = _mm256_maddubs_epi16(ymm_kUVToR, ymm3); + + ymm4 = _mm256_add_epi16(ymm4, ymm_kYBiasToRgb); + + ymm0 = _mm256_adds_epi16(ymm0, ymm4); + ymm1 = _mm256_subs_epi16(ymm4, ymm1); + ymm2 = _mm256_adds_epi16(ymm2, ymm4); + + ymm0 = _mm256_srai_epi16(ymm0, 6); + ymm1 = _mm256_srai_epi16(ymm1, 6); + ymm2 = _mm256_srai_epi16(ymm2, 6); + + ymm0 = _mm256_packus_epi16(ymm0, ymm0); + ymm1 = _mm256_packus_epi16(ymm1, ymm1); + ymm2 = _mm256_packus_epi16(ymm2, ymm2); + + ymm0 = _mm256_unpacklo_epi8(ymm0, ymm1); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0xd8); + ymm2 = _mm256_unpacklo_epi8(ymm2, ymm_alpha); + ymm2 = _mm256_permute4x64_epi64(ymm2, 0xd8); + + __m256i argb0 = _mm256_unpacklo_epi16(ymm0, ymm2); + __m256i argb1 = _mm256_unpackhi_epi16(ymm0, ymm2); + + _mm256_storeu_si256((__m256i*)dst_argb, argb0); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), argb1); + + dst_argb += 64; + width -= 16; } + _mm256_zeroupper(); } #endif // HAS_I422TOARGBROW_AVX2 -#ifdef HAS_I422ALPHATOARGBROW_AVX2 -// 16 pixels -// 8 UV values upsampled to 16 UV, mixed with 16 Y and 16 A producing 16 ARGB. -__declspec(naked) void I422AlphaToARGBRow_AVX2( - const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - const uint8_t* a_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push edi - push ebx - push ebp - mov eax, [esp + 16 + 4] // Y - mov esi, [esp + 16 + 8] // U - mov edi, [esp + 16 + 12] // V - mov ebp, [esp + 16 + 16] // A - mov edx, [esp + 16 + 20] // argb - mov ebx, [esp + 16 + 24] // yuvconstants - mov ecx, [esp + 16 + 28] // width - sub edi, esi +#ifdef HAS_I422TOAR30ROW_AVX2 +LIBYUV_TARGET_AVX2 +void I422ToAR30Row_AVX2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + __m256i ymm_kUVToB = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToB); + __m256i ymm_kUVToG = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToG); + __m256i ymm_kUVToR = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToR); + __m256i ymm_kYToRgb = + _mm256_loadu_si256((const __m256i*)yuvconstants->kYToRgb); + __m256i ymm_kYBiasToRgb = _mm256_sub_epi16( + _mm256_loadu_si256((const __m256i*)yuvconstants->kYBiasToRgb), + _mm256_set1_epi16(24)); + __m256i ymm_128 = _mm256_set1_epi8((char)0x80); + __m256i ymm_3ff0 = _mm256_set1_epi16((short)0x3ff0); + __m256i ymm_c000 = _mm256_set1_epi16((short)0xc000); + __m256i ymm_u_zero = _mm256_setzero_si256(); - convertloop: - READYUVA422_AVX2 - YUVTORGB_AVX2(ebx) - STOREARGB_AVX2 + ptrdiff_t offset = src_v - src_u; - sub ecx, 16 - jg convertloop + while (width >= 16) { + __m128i xmm_u = _mm_loadl_epi64((const __m128i*)src_u); + __m128i xmm_v = _mm_loadl_epi64((const __m128i*)(src_u + offset)); + src_u += 8; - pop ebp - pop ebx - pop edi - pop esi - vzeroupper - ret + __m256i ymm3 = _mm256_insertf128_si256(ymm_u_zero, xmm_u, 0); + __m256i ymm1 = _mm256_insertf128_si256(ymm_u_zero, xmm_v, 0); + + ymm3 = _mm256_unpacklo_epi8(ymm3, ymm1); + ymm3 = _mm256_permute4x64_epi64(ymm3, 0xd8); + ymm3 = _mm256_unpacklo_epi16(ymm3, ymm3); + + __m128i xmm_y = _mm_loadu_si128((const __m128i*)src_y); + src_y += 16; + __m256i ymm4 = _mm256_insertf128_si256(ymm_u_zero, xmm_y, 0); + ymm4 = _mm256_permute4x64_epi64(ymm4, 0xd8); + ymm4 = _mm256_unpacklo_epi8(ymm4, ymm4); + + ymm3 = _mm256_sub_epi8(ymm3, ymm_128); + ymm4 = _mm256_mulhi_epu16(ymm4, ymm_kYToRgb); + + __m256i ymm0 = _mm256_maddubs_epi16(ymm_kUVToB, ymm3); + ymm1 = _mm256_maddubs_epi16(ymm_kUVToG, ymm3); + __m256i ymm2 = _mm256_maddubs_epi16(ymm_kUVToR, ymm3); + + ymm4 = _mm256_add_epi16(ymm4, ymm_kYBiasToRgb); + + ymm0 = _mm256_adds_epi16(ymm0, ymm4); + ymm1 = _mm256_subs_epi16(ymm4, ymm1); + ymm2 = _mm256_adds_epi16(ymm2, ymm4); + + ymm0 = _mm256_min_epi16(ymm0, ymm_3ff0); + ymm1 = _mm256_min_epi16(ymm1, ymm_3ff0); + ymm2 = _mm256_min_epi16(ymm2, ymm_3ff0); + ymm0 = _mm256_max_epi16(ymm0, ymm_u_zero); + ymm1 = _mm256_max_epi16(ymm1, ymm_u_zero); + ymm2 = _mm256_max_epi16(ymm2, ymm_u_zero); + + __m256i ymm_g_masked = _mm256_and_si256(ymm1, ymm_3ff0); + __m256i ymm_r_masked = _mm256_and_si256(ymm2, ymm_3ff0); + ymm0 = _mm256_srli_epi16(ymm0, 4); + ymm3 = _mm256_slli_epi16(ymm_g_masked, 6); + ymm0 = _mm256_or_si256(ymm0, ymm3); + ymm1 = _mm256_srli_epi16(ymm1, 10); + ymm2 = _mm256_or_si256(ymm_r_masked, ymm_c000); + ymm2 = _mm256_or_si256(ymm2, ymm1); + + ymm0 = _mm256_permute4x64_epi64(ymm0, 0xd8); + ymm2 = _mm256_permute4x64_epi64(ymm2, 0xd8); + + __m256i ar30_lo = _mm256_unpacklo_epi16(ymm0, ymm2); + __m256i ar30_hi = _mm256_unpackhi_epi16(ymm0, ymm2); + + _mm256_storeu_si256((__m256i*)dst_ar30, ar30_lo); + _mm256_storeu_si256((__m256i*)(dst_ar30 + 32), ar30_hi); + + dst_ar30 += 64; + width -= 16; } + _mm256_zeroupper(); } -#endif // HAS_I422ALPHATOARGBROW_AVX2 - -#ifdef HAS_I444TOARGBROW_AVX2 -// 16 pixels -// 16 UV values with 16 Y producing 16 ARGB (64 bytes). -__declspec(naked) void I444ToARGBRow_AVX2( - const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push edi - push ebx - mov eax, [esp + 12 + 4] // Y - mov esi, [esp + 12 + 8] // U - mov edi, [esp + 12 + 12] // V - mov edx, [esp + 12 + 16] // argb - mov ebx, [esp + 12 + 20] // yuvconstants - mov ecx, [esp + 12 + 24] // width - sub edi, esi - vpcmpeqb ymm5, ymm5, ymm5 // generate 0xffffffffffffffff for alpha - convertloop: - READYUV444_AVX2 - YUVTORGB_AVX2(ebx) - STOREARGB_AVX2 - - sub ecx, 16 - jg convertloop - - pop ebx - pop edi - pop esi - vzeroupper - ret - } -} -#endif // HAS_I444TOARGBROW_AVX2 +#endif // HAS_I422TOAR30ROW_AVX2 #ifdef HAS_NV12TOARGBROW_AVX2 -// 16 pixels. -// 8 UV values upsampled to 16 UV, mixed with 16 Y producing 16 ARGB (64 bytes). -__declspec(naked) void NV12ToARGBRow_AVX2( - const uint8_t* y_buf, - const uint8_t* uv_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push ebx - mov eax, [esp + 8 + 4] // Y - mov esi, [esp + 8 + 8] // UV - mov edx, [esp + 8 + 12] // argb - mov ebx, [esp + 8 + 16] // yuvconstants - mov ecx, [esp + 8 + 20] // width - vpcmpeqb ymm5, ymm5, ymm5 // generate 0xffffffffffffffff for alpha +LIBYUV_TARGET_AVX2 +void NV12ToARGBRow_AVX2(const uint8_t* src_y, + const uint8_t* src_uv, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + __m256i ymm_kUVToB = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToB); + __m256i ymm_kUVToG = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToG); + __m256i ymm_kUVToR = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToR); + __m256i ymm_kYToRgb = + _mm256_loadu_si256((const __m256i*)yuvconstants->kYToRgb); + __m256i ymm_kYBiasToRgb = + _mm256_loadu_si256((const __m256i*)yuvconstants->kYBiasToRgb); + __m256i ymm_128 = _mm256_set1_epi8((char)0x80); + __m256i ymm_alpha = _mm256_set1_epi8((char)0xff); + __m256i ymm_u_zero = _mm256_setzero_si256(); - convertloop: - READNV12_AVX2 - YUVTORGB_AVX2(ebx) - STOREARGB_AVX2 + while (width >= 16) { + __m128i xmm_uv = _mm_loadu_si128((const __m128i*)src_uv); + src_uv += 16; - sub ecx, 16 - jg convertloop + __m256i ymm3 = _mm256_insertf128_si256(ymm_u_zero, xmm_uv, 0); + ymm3 = _mm256_permute4x64_epi64(ymm3, 0xd8); + ymm3 = _mm256_unpacklo_epi16(ymm3, ymm3); - pop ebx - pop esi - vzeroupper - ret + __m128i xmm_y = _mm_loadu_si128((const __m128i*)src_y); + src_y += 16; + __m256i ymm4 = _mm256_insertf128_si256(ymm_u_zero, xmm_y, 0); + ymm4 = _mm256_permute4x64_epi64(ymm4, 0xd8); + ymm4 = _mm256_unpacklo_epi8(ymm4, ymm4); + + ymm3 = _mm256_sub_epi8(ymm3, ymm_128); + ymm4 = _mm256_mulhi_epu16(ymm4, ymm_kYToRgb); + + __m256i ymm0 = _mm256_maddubs_epi16(ymm_kUVToB, ymm3); + __m256i ymm1 = _mm256_maddubs_epi16(ymm_kUVToG, ymm3); + __m256i ymm2 = _mm256_maddubs_epi16(ymm_kUVToR, ymm3); + + ymm4 = _mm256_add_epi16(ymm4, ymm_kYBiasToRgb); + + ymm0 = _mm256_adds_epi16(ymm0, ymm4); + ymm1 = _mm256_subs_epi16(ymm4, ymm1); + ymm2 = _mm256_adds_epi16(ymm2, ymm4); + + ymm0 = _mm256_srai_epi16(ymm0, 6); + ymm1 = _mm256_srai_epi16(ymm1, 6); + ymm2 = _mm256_srai_epi16(ymm2, 6); + + ymm0 = _mm256_packus_epi16(ymm0, ymm0); + ymm1 = _mm256_packus_epi16(ymm1, ymm1); + ymm2 = _mm256_packus_epi16(ymm2, ymm2); + + ymm0 = _mm256_unpacklo_epi8(ymm0, ymm1); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0xd8); + ymm2 = _mm256_unpacklo_epi8(ymm2, ymm_alpha); + ymm2 = _mm256_permute4x64_epi64(ymm2, 0xd8); + + __m256i argb0 = _mm256_unpacklo_epi16(ymm0, ymm2); + __m256i argb1 = _mm256_unpackhi_epi16(ymm0, ymm2); + + _mm256_storeu_si256((__m256i*)dst_argb, argb0); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), argb1); + + dst_argb += 64; + width -= 16; } + _mm256_zeroupper(); } #endif // HAS_NV12TOARGBROW_AVX2 #ifdef HAS_NV21TOARGBROW_AVX2 -// 16 pixels. -// 8 VU values upsampled to 16 UV, mixed with 16 Y producing 16 ARGB (64 bytes). -__declspec(naked) void NV21ToARGBRow_AVX2( - const uint8_t* y_buf, - const uint8_t* vu_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push ebx - mov eax, [esp + 8 + 4] // Y - mov esi, [esp + 8 + 8] // VU - mov edx, [esp + 8 + 12] // argb - mov ebx, [esp + 8 + 16] // yuvconstants - mov ecx, [esp + 8 + 20] // width - vpcmpeqb ymm5, ymm5, ymm5 // generate 0xffffffffffffffff for alpha +static const uint8_t kShuffleNV21_AVX2[32] = { + 1u, 0u, 3u, 2u, 5u, 4u, 7u, 6u, 9u, 8u, 11u, 10u, 13u, 12u, 15u, 14u, + 1u, 0u, 3u, 2u, 5u, 4u, 7u, 6u, 9u, 8u, 11u, 10u, 13u, 12u, 15u, 14u}; - convertloop: - READNV21_AVX2 - YUVTORGB_AVX2(ebx) - STOREARGB_AVX2 +LIBYUV_TARGET_AVX2 +void NV21ToARGBRow_AVX2(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + __m256i ymm_kUVToB = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToB); + __m256i ymm_kUVToG = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToG); + __m256i ymm_kUVToR = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToR); + __m256i ymm_kYToRgb = + _mm256_loadu_si256((const __m256i*)yuvconstants->kYToRgb); + __m256i ymm_kYBiasToRgb = + _mm256_loadu_si256((const __m256i*)yuvconstants->kYBiasToRgb); + __m256i ymm_128 = _mm256_set1_epi8((char)0x80); + __m256i ymm_alpha = _mm256_set1_epi8((char)0xff); + __m256i ymm_shuf_nv21 = _mm256_loadu_si256((const __m256i*)kShuffleNV21_AVX2); + __m256i ymm_u_zero = _mm256_setzero_si256(); - sub ecx, 16 - jg convertloop + while (width >= 16) { + __m128i xmm_vu = _mm_loadu_si128((const __m128i*)src_vu); + src_vu += 16; - pop ebx - pop esi - vzeroupper - ret + __m256i ymm3 = _mm256_insertf128_si256(ymm_u_zero, xmm_vu, 0); + ymm3 = _mm256_permute4x64_epi64(ymm3, 0xd8); + ymm3 = _mm256_shuffle_epi8(ymm3, ymm_shuf_nv21); + ymm3 = _mm256_unpacklo_epi16(ymm3, ymm3); + + __m128i xmm_y = _mm_loadu_si128((const __m128i*)src_y); + src_y += 16; + __m256i ymm4 = _mm256_insertf128_si256(ymm_u_zero, xmm_y, 0); + ymm4 = _mm256_permute4x64_epi64(ymm4, 0xd8); + ymm4 = _mm256_unpacklo_epi8(ymm4, ymm4); + + ymm3 = _mm256_sub_epi8(ymm3, ymm_128); + ymm4 = _mm256_mulhi_epu16(ymm4, ymm_kYToRgb); + + __m256i ymm0 = _mm256_maddubs_epi16(ymm_kUVToB, ymm3); + __m256i ymm1 = _mm256_maddubs_epi16(ymm_kUVToG, ymm3); + __m256i ymm2 = _mm256_maddubs_epi16(ymm_kUVToR, ymm3); + + ymm4 = _mm256_add_epi16(ymm4, ymm_kYBiasToRgb); + + ymm0 = _mm256_adds_epi16(ymm0, ymm4); + ymm1 = _mm256_subs_epi16(ymm4, ymm1); + ymm2 = _mm256_adds_epi16(ymm2, ymm4); + + ymm0 = _mm256_srai_epi16(ymm0, 6); + ymm1 = _mm256_srai_epi16(ymm1, 6); + ymm2 = _mm256_srai_epi16(ymm2, 6); + + ymm0 = _mm256_packus_epi16(ymm0, ymm0); + ymm1 = _mm256_packus_epi16(ymm1, ymm1); + ymm2 = _mm256_packus_epi16(ymm2, ymm2); + + ymm0 = _mm256_unpacklo_epi8(ymm0, ymm1); + ymm0 = _mm256_permute4x64_epi64(ymm0, 0xd8); + ymm2 = _mm256_unpacklo_epi8(ymm2, ymm_alpha); + ymm2 = _mm256_permute4x64_epi64(ymm2, 0xd8); + + __m256i argb0 = _mm256_unpacklo_epi16(ymm0, ymm2); + __m256i argb1 = _mm256_unpackhi_epi16(ymm0, ymm2); + + _mm256_storeu_si256((__m256i*)dst_argb, argb0); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), argb1); + + dst_argb += 64; + width -= 16; } + _mm256_zeroupper(); } #endif // HAS_NV21TOARGBROW_AVX2 -#ifdef HAS_YUY2TOARGBROW_AVX2 -// 16 pixels. -// 8 YUY2 values with 16 Y and 8 UV producing 16 ARGB (64 bytes). -__declspec(naked) void YUY2ToARGBRow_AVX2( - const uint8_t* src_yuy2, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push ebx - mov eax, [esp + 4 + 4] // yuy2 - mov edx, [esp + 4 + 8] // argb - mov ebx, [esp + 4 + 12] // yuvconstants - mov ecx, [esp + 4 + 16] // width - vpcmpeqb ymm5, ymm5, ymm5 // generate 0xffffffffffffffff for alpha +#if defined(HAS_I422TORGB24ROW_AVX2) || \ + defined(HAS_I422TORGB24ROW_AVX512BW) || \ + defined(HAS_ARGBTORGB24ROW_AVX2) || \ + defined(HAS_ARGBTORGB24ROW_AVX512BW) +static const uint8_t kShuffleMaskARGBToRGB24[2][16] = { + {0u, 1u, 2u, 4u, 5u, 6u, 8u, 9u, 10u, 12u, 13u, 14u, 128u, 128u, 128u, + 128u}, + {0u, 1u, 2u, 4u, 5u, 6u, 8u, 9u, 128u, 128u, 128u, 128u, 10u, 12u, 13u, + 14u}}; +#endif - convertloop: - READYUY2_AVX2 - YUVTORGB_AVX2(ebx) - STOREARGB_AVX2 +#if defined(HAS_I422TORGB24ROW_AVX2) +LIBYUV_TARGET_AVX2 +void I422ToRGB24Row_AVX2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + // Constants + __m256i ymm_kUVToB = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToB); + __m256i ymm_kUVToG = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToG); + __m256i ymm_kUVToR = _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToR); + __m256i ymm_kYToRgb = + _mm256_loadu_si256((const __m256i*)yuvconstants->kYToRgb); + __m256i ymm_kYBiasToRgb = + _mm256_loadu_si256((const __m256i*)yuvconstants->kYBiasToRgb); + __m256i ymm_128 = _mm256_set1_epi8((char)0x80); - sub ecx, 16 - jg convertloop + __m256i ymm_shuf0 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShuffleMaskARGBToRGB24[1])); + __m256i ymm_shuf1 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShuffleMaskARGBToRGB24[0])); + __m256i ymm_u_zero = _mm256_setzero_si256(); - pop ebx - vzeroupper - ret + ptrdiff_t offset = src_v - src_u; + + while (width >= 16) { + // READYUV422_AVX2 + __m128i xmm_u = _mm_loadl_epi64((const __m128i*)src_u); + __m128i xmm_v = _mm_loadl_epi64((const __m128i*)(src_u + offset)); + src_u += 8; + + __m256i ymm3 = _mm256_insertf128_si256(ymm_u_zero, xmm_u, 0); + __m256i ymm1 = _mm256_insertf128_si256(ymm_u_zero, xmm_v, 0); + + ymm3 = _mm256_unpacklo_epi8(ymm3, ymm1); + ymm3 = _mm256_permute4x64_epi64(ymm3, 0xd8); + ymm3 = _mm256_unpacklo_epi16(ymm3, ymm3); + + __m128i xmm_y = _mm_loadu_si128((const __m128i*)src_y); + src_y += 16; + __m256i ymm4 = _mm256_insertf128_si256(ymm_u_zero, xmm_y, 0); + ymm4 = _mm256_permute4x64_epi64(ymm4, 0xd8); + ymm4 = _mm256_unpacklo_epi8(ymm4, ymm4); + + // YUVTORGB_AVX2 + ymm3 = _mm256_sub_epi8(ymm3, ymm_128); + ymm4 = _mm256_mulhi_epu16(ymm4, ymm_kYToRgb); + + __m256i ymm0 = _mm256_maddubs_epi16(ymm_kUVToB, ymm3); + ymm1 = _mm256_maddubs_epi16(ymm_kUVToG, ymm3); + __m256i ymm2 = _mm256_maddubs_epi16(ymm_kUVToR, ymm3); + + ymm4 = _mm256_add_epi16(ymm4, ymm_kYBiasToRgb); + + ymm0 = _mm256_adds_epi16(ymm0, ymm4); + ymm1 = _mm256_subs_epi16(ymm4, ymm1); + ymm2 = _mm256_adds_epi16(ymm2, ymm4); + + ymm0 = _mm256_srai_epi16(ymm0, 6); + ymm1 = _mm256_srai_epi16(ymm1, 6); + ymm2 = _mm256_srai_epi16(ymm2, 6); + + ymm0 = _mm256_packus_epi16(ymm0, ymm0); + ymm1 = _mm256_packus_epi16(ymm1, ymm1); + ymm2 = _mm256_packus_epi16(ymm2, ymm2); + + // STORERGB24_AVX2 + __m256i ymm0_packed = _mm256_unpacklo_epi8(ymm0, ymm1); + __m256i ymm2_packed = _mm256_unpacklo_epi8(ymm2, ymm2); + __m256i ymm1_packed = ymm0_packed; + + ymm0_packed = _mm256_unpacklo_epi16(ymm0_packed, ymm2_packed); + ymm1_packed = _mm256_unpackhi_epi16(ymm1_packed, ymm2_packed); + + ymm0_packed = _mm256_shuffle_epi8(ymm0_packed, ymm_shuf0); + ymm1_packed = _mm256_shuffle_epi8(ymm1_packed, ymm_shuf1); + + ymm1_packed = _mm256_alignr_epi8(ymm1_packed, ymm0_packed, 0xc); + + __m128i xmm0_store = _mm256_castsi256_si128(ymm0_packed); + __m128i xmm1_store = _mm256_castsi256_si128(ymm1_packed); + __m128i xmm2_store = _mm256_extractf128_si256(ymm0_packed, 1); + __m128i xmm3_store = _mm256_extractf128_si256(ymm1_packed, 1); + + xmm0_store = _mm_unpacklo_epi64(xmm0_store, xmm1_store); + xmm2_store = _mm_alignr_epi8(xmm2_store, xmm1_store, 8); + + _mm_storeu_si128((__m128i*)dst_rgb24, xmm0_store); + _mm_storeu_si128((__m128i*)(dst_rgb24 + 16), xmm2_store); + _mm_storeu_si128((__m128i*)(dst_rgb24 + 32), xmm3_store); + + dst_rgb24 += 48; + width -= 16; + } + _mm256_zeroupper(); +} +#endif // defined(HAS_I422TORGB24ROW_AVX2) || + // defined(HAS_I422TORGB24ROW_AVX512BW) + +#if defined(HAS_I422TORGB24ROW_AVX512VBMI) || \ + defined(HAS_I422TORGB24ROW_AVX512BW) +#define READYUV422_AVX512BW \ + __m128i xmm_u = _mm_loadu_si128((const __m128i*)src_u); \ + __m128i xmm_v = _mm_loadu_si128((const __m128i*)(src_u + offset)); \ + src_u += 16; \ + __m512i zmm_u_val = _mm512_castsi128_si512(xmm_u); \ + __m512i zmm_v_val = _mm512_castsi128_si512(xmm_v); \ + zmm_u_val = PermutexvarEpi64(zmm_split, zmm_u_val); \ + zmm_v_val = PermutexvarEpi64(zmm_split, zmm_v_val); \ + __m512i zmm3 = _mm512_unpacklo_epi8(zmm_u_val, zmm_v_val); \ + zmm3 = _mm512_permutex_epi64(zmm3, 0xd8); \ + zmm3 = _mm512_unpacklo_epi16(zmm3, zmm3); \ + __m256i ymm_y = _mm256_loadu_si256((const __m256i*)src_y); \ + src_y += 32; \ + __m512i zmm4 = _mm512_castsi256_si512(ymm_y); \ + zmm4 = PermutexvarEpi64(zmm_split_y, zmm4); \ + zmm4 = _mm512_permutex_epi64(zmm4, 0xd8); \ + zmm4 = _mm512_unpacklo_epi8(zmm4, zmm4); + +#define READYUV422_MASK_AVX512BW \ + __mmask16 mask_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); \ + __mmask32 mask_y = (__mmask32)((1u << width) - 1u); \ + __m128i xmm_u = _mm_maskz_loadu_epi8(mask_uv, src_u); \ + __m128i xmm_v = _mm_maskz_loadu_epi8(mask_uv, src_u + offset); \ + __m512i zmm_u_val = _mm512_castsi128_si512(xmm_u); \ + __m512i zmm_v_val = _mm512_castsi128_si512(xmm_v); \ + zmm_u_val = PermutexvarEpi64(zmm_split, zmm_u_val); \ + zmm_v_val = PermutexvarEpi64(zmm_split, zmm_v_val); \ + __m512i zmm3 = _mm512_unpacklo_epi8(zmm_u_val, zmm_v_val); \ + zmm3 = _mm512_permutex_epi64(zmm3, 0xd8); \ + zmm3 = _mm512_unpacklo_epi16(zmm3, zmm3); \ + __m256i ymm_y = _mm256_maskz_loadu_epi8(mask_y, src_y); \ + __m512i zmm4 = _mm512_castsi256_si512(ymm_y); \ + zmm4 = PermutexvarEpi64(zmm_split_y, zmm4); \ + zmm4 = _mm512_permutex_epi64(zmm4, 0xd8); \ + zmm4 = _mm512_unpacklo_epi8(zmm4, zmm4); + +#define YUVTORGB_AVX512BW \ + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); \ + zmm4 = _mm512_mulhi_epu16(zmm4, zmm_kYToRgb); \ + __m512i zmm0 = _mm512_maddubs_epi16(zmm_kUVToB, zmm3); \ + __m512i zmm1 = _mm512_maddubs_epi16(zmm_kUVToG, zmm3); \ + __m512i zmm2 = _mm512_maddubs_epi16(zmm_kUVToR, zmm3); \ + zmm4 = _mm512_add_epi16(zmm4, zmm_kYBiasToRgb); \ + zmm0 = _mm512_adds_epi16(zmm0, zmm4); \ + zmm1 = _mm512_subs_epi16(zmm4, zmm1); \ + zmm2 = _mm512_adds_epi16(zmm2, zmm4); \ + zmm0 = _mm512_srai_epi16(zmm0, 6); \ + zmm1 = _mm512_srai_epi16(zmm1, 6); \ + zmm2 = _mm512_srai_epi16(zmm2, 6); \ + zmm0 = _mm512_packus_epi16(zmm0, zmm0); \ + zmm1 = _mm512_packus_epi16(zmm1, zmm1); \ + zmm2 = _mm512_packus_epi16(zmm2, zmm2); + +#define STORERGB24_AVX512VBMI \ + __m512i zmm_BG = _mm512_permutex2var_epi8(zmm0, zmm_mask_BG, zmm1); \ + __m512i zmm_dst0 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST0, zmm2); \ + __m512i zmm_dst1 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST1, zmm2); \ + _mm512_storeu_si512((__m512i*)dst_rgb24, zmm_dst0); \ + _mm256_storeu_si256((__m256i*)(dst_rgb24 + 64), \ + _mm512_castsi512_si256(zmm_dst1)); \ + dst_rgb24 += 96; + +#define STORERGB24_MASK_AVX512VBMI \ + int dst_bytes = width * 3; \ + __mmask64 mask_dst0 = dst_bytes >= 64 ? ~0ull : (1ull << dst_bytes) - 1ull; \ + __mmask32 mask_dst1 = dst_bytes > 64 ? (1u << (dst_bytes - 64)) - 1u : 0u; \ + __m512i zmm_BG = _mm512_permutex2var_epi8(zmm0, zmm_mask_BG, zmm1); \ + __m512i zmm_dst0 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST0, zmm2); \ + __m512i zmm_dst1 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST1, zmm2); \ + _mm512_mask_storeu_epi8(dst_rgb24, mask_dst0, zmm_dst0); \ + _mm256_mask_storeu_epi8(dst_rgb24 + 64, mask_dst1, \ + _mm512_castsi512_si256(zmm_dst1)); + +#define STORERGB24_AVX512BW \ + __m512i zmm_bg = _mm512_unpacklo_epi8(zmm0, zmm1); \ + __m512i zmm_rr = _mm512_unpacklo_epi8(zmm2, zmm2); \ + __m512i zmm_lo = _mm512_unpacklo_epi16(zmm_bg, zmm_rr); \ + __m512i zmm_hi = _mm512_unpackhi_epi16(zmm_bg, zmm_rr); \ + zmm_lo = _mm512_shuffle_epi8(zmm_lo, zmm_shuf0); \ + zmm_hi = _mm512_shuffle_epi8(zmm_hi, zmm_shuf1); \ + zmm_hi = _mm512_alignr_epi8(zmm_hi, zmm_lo, 12); \ + __m512i zmm_dst0 = _mm512_permutex2var_epi64(zmm_lo, zmm_stitch0, zmm_hi); \ + __m512i zmm_dst1 = _mm512_permutex2var_epi64(zmm_lo, zmm_stitch1, zmm_hi); \ + _mm512_storeu_si512((__m512i*)dst_rgb24, zmm_dst0); \ + _mm256_storeu_si256((__m256i*)(dst_rgb24 + 64), \ + _mm512_castsi512_si256(zmm_dst1)); \ + dst_rgb24 += 96; + +#define STORERGB24_MASK_AVX512BW \ + int dst_bytes = width * 3; \ + __mmask64 mask_dst0 = dst_bytes >= 64 ? ~0ull : (1ull << dst_bytes) - 1ull; \ + __mmask32 mask_dst1 = dst_bytes > 64 ? (1u << (dst_bytes - 64)) - 1u : 0u; \ + __m512i zmm_bg = _mm512_unpacklo_epi8(zmm0, zmm1); \ + __m512i zmm_rr = _mm512_unpacklo_epi8(zmm2, zmm2); \ + __m512i zmm_lo = _mm512_unpacklo_epi16(zmm_bg, zmm_rr); \ + __m512i zmm_hi = _mm512_unpackhi_epi16(zmm_bg, zmm_rr); \ + zmm_lo = _mm512_shuffle_epi8(zmm_lo, zmm_shuf0); \ + zmm_hi = _mm512_shuffle_epi8(zmm_hi, zmm_shuf1); \ + zmm_hi = _mm512_alignr_epi8(zmm_hi, zmm_lo, 12); \ + __m512i zmm_dst0 = _mm512_permutex2var_epi64(zmm_lo, zmm_stitch0, zmm_hi); \ + __m512i zmm_dst1 = _mm512_permutex2var_epi64(zmm_lo, zmm_stitch1, zmm_hi); \ + _mm512_mask_storeu_epi8(dst_rgb24, mask_dst0, zmm_dst0); \ + _mm256_mask_storeu_epi8(dst_rgb24 + 64, mask_dst1, \ + _mm512_castsi512_si256(zmm_dst1)); +#endif // defined(HAS_I422TORGB24ROW_AVX512VBMI) || + // defined(HAS_I422TORGB24ROW_AVX512BW) + +#ifdef HAS_I422TORGB24ROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void I422ToRGB24Row_AVX512VBMI(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + // Masks + static const uint8_t kMaskBG[64] = { + 0x00, 0x40, 0x01, 0x41, 0x02, 0x42, 0x03, 0x43, 0x04, 0x44, 0x05, + 0x45, 0x06, 0x46, 0x07, 0x47, 0x10, 0x50, 0x11, 0x51, 0x12, 0x52, + 0x13, 0x53, 0x14, 0x54, 0x15, 0x55, 0x16, 0x56, 0x17, 0x57, 0x20, + 0x60, 0x21, 0x61, 0x22, 0x62, 0x23, 0x63, 0x24, 0x64, 0x25, 0x65, + 0x26, 0x66, 0x27, 0x67, 0x30, 0x70, 0x31, 0x71, 0x32, 0x72, 0x33, + 0x73, 0x34, 0x74, 0x35, 0x75, 0x36, 0x76, 0x37, 0x77}; + static const uint8_t kMaskDST0[64] = { + 0x00, 0x01, 0x40, 0x02, 0x03, 0x41, 0x04, 0x05, 0x42, 0x06, 0x07, + 0x43, 0x08, 0x09, 0x44, 0x0a, 0x0b, 0x45, 0x0c, 0x0d, 0x46, 0x0e, + 0x0f, 0x47, 0x10, 0x11, 0x50, 0x12, 0x13, 0x51, 0x14, 0x15, 0x52, + 0x16, 0x17, 0x53, 0x18, 0x19, 0x54, 0x1a, 0x1b, 0x55, 0x1c, 0x1d, + 0x56, 0x1e, 0x1f, 0x57, 0x20, 0x21, 0x60, 0x22, 0x23, 0x61, 0x24, + 0x25, 0x62, 0x26, 0x27, 0x63, 0x28, 0x29, 0x64, 0x2a}; + static const uint8_t kMaskDST1[64] = { + 0x2b, 0x65, 0x2c, 0x2d, 0x66, 0x2e, 0x2f, 0x67, 0x30, 0x31, 0x70, + 0x32, 0x33, 0x71, 0x34, 0x35, 0x72, 0x36, 0x37, 0x73, 0x38, 0x39, + 0x74, 0x3a, 0x3b, 0x75, 0x3c, 0x3d, 0x76, 0x3e, 0x3f, 0x77, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + static const uint64_t kSplitQuadWords[8] = {0, 2, 2, 2, 1, 2, 2, 2}; + static const uint64_t kSplitDoubleQuadWords[8] = {0, 1, 4, 4, 2, 3, 4, 4}; + + // Constants + __m512i zmm_kUVToB = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToB)); + __m512i zmm_kUVToG = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToG)); + __m512i zmm_kUVToR = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToR)); + __m512i zmm_kYToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYToRgb)); + __m512i zmm_kYBiasToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYBiasToRgb)); + __m512i zmm_128 = _mm512_set1_epi8((char)0x80); + + __m512i zmm_mask_BG = _mm512_loadu_si512((const __m512i*)kMaskBG); + __m512i zmm_mask_DST0 = _mm512_loadu_si512((const __m512i*)kMaskDST0); + __m512i zmm_mask_DST1 = _mm512_loadu_si512((const __m512i*)kMaskDST1); + __m512i zmm_split = _mm512_loadu_si512((const __m512i*)kSplitQuadWords); + __m512i zmm_split_y = + _mm512_loadu_si512((const __m512i*)kSplitDoubleQuadWords); + + ptrdiff_t offset = src_v - src_u; + + while (width >= 32) { + READYUV422_AVX512BW + YUVTORGB_AVX512BW + STORERGB24_AVX512VBMI + width -= 32; + } + if (width > 0) { + READYUV422_MASK_AVX512BW + YUVTORGB_AVX512BW + STORERGB24_MASK_AVX512VBMI + } + _mm256_zeroupper(); +} +#endif // HAS_I422TORGB24ROW_AVX512VBMI + +#ifdef HAS_I422TORGB24ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I422ToRGB24Row_AVX512BW(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + static const uint64_t kStitchRGB24_0[8] = {0, 8, 9, 2, 10, 11, 4, 12}; + static const uint64_t kStitchRGB24_1[8] = {13, 6, 14, 15, 0, 0, 0, 0}; + static const uint64_t kSplitQuadWords[8] = {0, 2, 2, 2, 1, 2, 2, 2}; + static const uint64_t kSplitDoubleQuadWords[8] = {0, 1, 4, 4, 2, 3, 4, 4}; + + // Constants + __m512i zmm_kUVToB = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToB)); + __m512i zmm_kUVToG = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToG)); + __m512i zmm_kUVToR = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToR)); + __m512i zmm_kYToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYToRgb)); + __m512i zmm_kYBiasToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYBiasToRgb)); + __m512i zmm_128 = _mm512_set1_epi8((char)0x80); + + __m512i zmm_shuf0 = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)kShuffleMaskARGBToRGB24[1])); + __m512i zmm_shuf1 = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)kShuffleMaskARGBToRGB24[0])); + __m512i zmm_stitch0 = _mm512_loadu_si512((const __m512i*)kStitchRGB24_0); + __m512i zmm_stitch1 = _mm512_loadu_si512((const __m512i*)kStitchRGB24_1); + __m512i zmm_split = _mm512_loadu_si512((const __m512i*)kSplitQuadWords); + __m512i zmm_split_y = + _mm512_loadu_si512((const __m512i*)kSplitDoubleQuadWords); + + ptrdiff_t offset = src_v - src_u; + + while (width >= 32) { + READYUV422_AVX512BW + YUVTORGB_AVX512BW + STORERGB24_AVX512BW + width -= 32; + } + if (width > 0) { + READYUV422_MASK_AVX512BW + YUVTORGB_AVX512BW + STORERGB24_MASK_AVX512BW + } + _mm256_zeroupper(); +} +#endif // HAS_I422TORGB24ROW_AVX512BW + +#if defined(HAS_I422TORGB24ROW_AVX512VBMI) || \ + defined(HAS_I422TORGB24ROW_AVX512BW) +#undef READYUV422_AVX512BW +#undef READYUV422_MASK_AVX512BW +#undef YUVTORGB_AVX512BW +#undef STORERGB24_AVX512VBMI +#undef STORERGB24_MASK_AVX512VBMI +#undef STORERGB24_AVX512BW +#undef STORERGB24_MASK_AVX512BW +#endif + +#ifdef HAS_I422TOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I422ToAR30Row_AVX512BW(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + static const uint64_t kSplitQuadWords[8] = {0, 2, 2, 2, 1, 2, 2, 2}; + static const uint64_t kSplitDoubleQuadWords[8] = {0, 1, 4, 4, 2, 3, 4, 4}; + static const uint16_t kPermAR30_0[32] = { + 0, 32, 1, 33, 2, 34, 3, 35, 4, 36, 5, 37, 6, 38, 7, 39, + 8, 40, 9, 41, 10, 42, 11, 43, 12, 44, 13, 45, 14, 46, 15, 47}; + static const uint16_t kPermAR30_1[32] = { + 16, 48, 17, 49, 18, 50, 19, 51, 20, 52, 21, 53, 22, 54, 23, 55, + 24, 56, 25, 57, 26, 58, 27, 59, 28, 60, 29, 61, 30, 62, 31, 63}; + + // Constants + __m512i zmm_kUVToB = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToB)); + __m512i zmm_kUVToG = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToG)); + __m512i zmm_kUVToR = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToR)); + __m512i zmm_kYToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYToRgb)); + __m512i zmm_kYBiasToRgb = _mm512_sub_epi16( + _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYBiasToRgb)), + _mm512_set1_epi16(24)); + __m512i zmm_128 = _mm512_set1_epi8((char)0x80); + __m512i zmm_3ff0 = _mm512_set1_epi16((short)0x3ff0); + __m512i zmm_fc00 = _mm512_set1_epi16((short)0xfc00); + __m512i zmm_c000 = _mm512_set1_epi16((short)0xc000); + __m512i zmm_zero = _mm512_setzero_si512(); + + __m512i zmm_perm0 = _mm512_loadu_si512((const __m512i*)kPermAR30_0); + __m512i zmm_perm1 = _mm512_loadu_si512((const __m512i*)kPermAR30_1); + __m512i zmm_split = _mm512_loadu_si512((const __m512i*)kSplitQuadWords); + __m512i zmm_split_y = + _mm512_loadu_si512((const __m512i*)kSplitDoubleQuadWords); + + ptrdiff_t offset = src_v - src_u; + + while (width >= 32) { + // READYUV422_AVX512BW + __m128i xmm_u = _mm_loadu_si128((const __m128i*)src_u); + __m128i xmm_v = _mm_loadu_si128((const __m128i*)(src_u + offset)); + src_u += 16; + + __m512i zmm_u_val = _mm512_castsi128_si512(xmm_u); + __m512i zmm_v_val = _mm512_castsi128_si512(xmm_v); + + zmm_u_val = PermutexvarEpi64(zmm_split, zmm_u_val); + zmm_v_val = PermutexvarEpi64(zmm_split, zmm_v_val); + + __m512i zmm3 = _mm512_unpacklo_epi8(zmm_u_val, zmm_v_val); + zmm3 = _mm512_permutex_epi64(zmm3, 0xd8); + zmm3 = _mm512_unpacklo_epi16(zmm3, zmm3); + + __m256i ymm_y = _mm256_loadu_si256((const __m256i*)src_y); + src_y += 32; + __m512i zmm4 = _mm512_castsi256_si512(ymm_y); + zmm4 = PermutexvarEpi64(zmm_split_y, zmm4); + zmm4 = _mm512_permutex_epi64(zmm4, 0xd8); + zmm4 = _mm512_unpacklo_epi8(zmm4, zmm4); + + // YUVTORGB_AVX512BW + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_mulhi_epu16(zmm4, zmm_kYToRgb); + + __m512i zmm0 = _mm512_maddubs_epi16(zmm_kUVToB, zmm3); + __m512i zmm1 = _mm512_maddubs_epi16(zmm_kUVToG, zmm3); + __m512i zmm2 = _mm512_maddubs_epi16(zmm_kUVToR, zmm3); + + zmm4 = _mm512_add_epi16(zmm4, zmm_kYBiasToRgb); + + zmm0 = _mm512_adds_epi16(zmm0, zmm4); + zmm1 = _mm512_subs_epi16(zmm4, zmm1); + zmm2 = _mm512_adds_epi16(zmm2, zmm4); + + // Clamp to [0, 0x3ff0] (1023 * 16) + zmm0 = _mm512_min_epi16(zmm0, zmm_3ff0); + zmm1 = _mm512_min_epi16(zmm1, zmm_3ff0); + zmm2 = _mm512_min_epi16(zmm2, zmm_3ff0); + zmm0 = _mm512_max_epi16(zmm0, zmm_zero); + zmm1 = _mm512_max_epi16(zmm1, zmm_zero); + zmm2 = _mm512_max_epi16(zmm2, zmm_zero); + + // STOREAR30_AVX512BW: + zmm0 = _mm512_srli_epi16(zmm0, 4); + zmm3 = _mm512_srli_epi16(zmm1, 10); + zmm1 = _mm512_slli_epi16(zmm1, 6); + zmm0 = _mm512_or_si512(zmm0, _mm512_and_si512(zmm1, zmm_fc00)); + zmm2 = _mm512_or_si512(_mm512_and_si512(zmm2, zmm_3ff0), + _mm512_andnot_si512(zmm_3ff0, zmm3)); + zmm2 = _mm512_or_si512(zmm2, zmm_c000); + + __m512i zmm_dst0 = _mm512_permutex2var_epi16(zmm0, zmm_perm0, zmm2); + __m512i zmm_dst1 = _mm512_permutex2var_epi16(zmm0, zmm_perm1, zmm2); + + _mm512_storeu_si512((__m512i*)dst_ar30, zmm_dst0); + _mm512_storeu_si512((__m512i*)(dst_ar30 + 64), zmm_dst1); + + dst_ar30 += 128; + width -= 32; + } + if (width > 0) { + __mmask16 mask_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __mmask32 mask_y = (__mmask32)((1u << width) - 1u); + __m128i xmm_u = _mm_maskz_loadu_epi8(mask_uv, src_u); + __m128i xmm_v = _mm_maskz_loadu_epi8(mask_uv, src_u + offset); + + __m512i zmm_u_val = _mm512_castsi128_si512(xmm_u); + __m512i zmm_v_val = _mm512_castsi128_si512(xmm_v); + + zmm_u_val = PermutexvarEpi64(zmm_split, zmm_u_val); + zmm_v_val = PermutexvarEpi64(zmm_split, zmm_v_val); + + __m512i zmm3 = _mm512_unpacklo_epi8(zmm_u_val, zmm_v_val); + zmm3 = _mm512_permutex_epi64(zmm3, 0xd8); + zmm3 = _mm512_unpacklo_epi16(zmm3, zmm3); + + __m256i ymm_y = _mm256_maskz_loadu_epi8(mask_y, src_y); + __m512i zmm4 = _mm512_castsi256_si512(ymm_y); + zmm4 = PermutexvarEpi64(zmm_split_y, zmm4); + zmm4 = _mm512_permutex_epi64(zmm4, 0xd8); + zmm4 = _mm512_unpacklo_epi8(zmm4, zmm4); + + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_mulhi_epu16(zmm4, zmm_kYToRgb); + + __m512i zmm0 = _mm512_maddubs_epi16(zmm_kUVToB, zmm3); + __m512i zmm1 = _mm512_maddubs_epi16(zmm_kUVToG, zmm3); + __m512i zmm2 = _mm512_maddubs_epi16(zmm_kUVToR, zmm3); + + zmm4 = _mm512_add_epi16(zmm4, zmm_kYBiasToRgb); + + zmm0 = _mm512_adds_epi16(zmm0, zmm4); + zmm1 = _mm512_subs_epi16(zmm4, zmm1); + zmm2 = _mm512_adds_epi16(zmm2, zmm4); + + zmm0 = _mm512_min_epi16(zmm0, zmm_3ff0); + zmm1 = _mm512_min_epi16(zmm1, zmm_3ff0); + zmm2 = _mm512_min_epi16(zmm2, zmm_3ff0); + zmm0 = _mm512_max_epi16(zmm0, zmm_zero); + zmm1 = _mm512_max_epi16(zmm1, zmm_zero); + zmm2 = _mm512_max_epi16(zmm2, zmm_zero); + + zmm0 = _mm512_srli_epi16(zmm0, 4); + zmm3 = _mm512_srli_epi16(zmm1, 10); + zmm1 = _mm512_slli_epi16(zmm1, 6); + zmm0 = _mm512_or_si512(zmm0, _mm512_and_si512(zmm1, zmm_fc00)); + zmm2 = _mm512_or_si512(_mm512_and_si512(zmm2, zmm_3ff0), + _mm512_andnot_si512(zmm_3ff0, zmm3)); + zmm2 = _mm512_or_si512(zmm2, zmm_c000); + + __m512i zmm_dst0 = _mm512_permutex2var_epi16(zmm0, zmm_perm0, zmm2); + __m512i zmm_dst1 = _mm512_permutex2var_epi16(zmm0, zmm_perm1, zmm2); + + _mm512_mask_storeu_epi32(dst_ar30, (__mmask16)mask_y, zmm_dst0); + _mm512_mask_storeu_epi32(dst_ar30 + 64, (__mmask16)(mask_y >> 16), + zmm_dst1); + } + _mm256_zeroupper(); +} +#endif // HAS_I422TOAR30ROW_AVX512BW + +#ifdef HAS_ARGBBLENDROW_AVX2 +static const uint8_t kShuffleAlpha[16] = {3u, 0x80, 3u, 0x80, 7u, 0x80, + 7u, 0x80, 11u, 0x80, 11u, 0x80, + 15u, 0x80, 15u, 0x80}; + +LIBYUV_TARGET_AVX2 +void ARGBBlendRow_AVX2(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + __m256i shuff = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)kShuffleAlpha)); + __m256i ymm_1 = _mm256_set1_epi16(1); + __m256i mask_lo = _mm256_set1_epi16(0x00ff); + __m256i mask_hi = _mm256_set1_epi16((short)0xff00); + __m256i mask_alpha = _mm256_set1_epi32((int)0xff000000); + + while (width >= 8) { + __m256i ymm_s0 = _mm256_loadu_si256((const __m256i*)src_argb0); + __m256i ymm_s1 = _mm256_loadu_si256((const __m256i*)src_argb1); + src_argb0 += 32; + src_argb1 += 32; + + __m256i ymm_a = _mm256_xor_si256(ymm_s0, mask_alpha); + ymm_a = _mm256_shuffle_epi8(ymm_a, shuff); + ymm_a = _mm256_add_epi16(ymm_a, ymm_1); + + __m256i ymm_s1_lo = _mm256_and_si256(ymm_s1, mask_lo); + __m256i ymm_s1_hi = _mm256_srli_epi16(ymm_s1, 8); + + ymm_s1_lo = _mm256_mullo_epi16(ymm_s1_lo, ymm_a); + ymm_s1_hi = _mm256_mullo_epi16(ymm_s1_hi, ymm_a); + + ymm_s1_lo = _mm256_srli_epi16(ymm_s1_lo, 8); + ymm_s1_hi = _mm256_and_si256(ymm_s1_hi, mask_hi); + + __m256i res = _mm256_or_si256(ymm_s0, mask_alpha); + res = _mm256_adds_epu8(res, ymm_s1_lo); + res = _mm256_adds_epu8(res, ymm_s1_hi); + + _mm256_storeu_si256((__m256i*)dst_argb, res); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); + + while (width > 0) { + uint32_t s0 = *(const uint32_t*)src_argb0; + uint32_t s1 = *(const uint32_t*)src_argb1; + src_argb0 += 4; + src_argb1 += 4; + + uint32_t a = 256 - (s0 >> 24); + uint32_t b = (((s1 & 0x000000ff) * a) >> 8) + (s0 & 0x000000ff); + uint32_t g = (((s1 & 0x0000ff00) * a) >> 8) + (s0 & 0x0000ff00); + uint32_t r = (((s1 & 0x00ff0000) >> 8) * a) + (s0 & 0x00ff0000); + + b = (b > 255) ? 255 : b; + g = (g > 0xff00) ? 0xff00 : (g & 0xff00); + r = (r > 0x00ff0000) ? 0x00ff0000 : (r & 0x00ff0000); + + *(uint32_t*)dst_argb = 0xff000000 | r | g | b; + dst_argb += 4; + --width; } } -#endif // HAS_YUY2TOARGBROW_AVX2 - -#ifdef HAS_UYVYTOARGBROW_AVX2 -// 16 pixels. -// 8 UYVY values with 16 Y and 8 UV producing 16 ARGB (64 bytes). -__declspec(naked) void UYVYToARGBRow_AVX2( - const uint8_t* src_uyvy, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push ebx - mov eax, [esp + 4 + 4] // uyvy - mov edx, [esp + 4 + 8] // argb - mov ebx, [esp + 4 + 12] // yuvconstants - mov ecx, [esp + 4 + 16] // width - vpcmpeqb ymm5, ymm5, ymm5 // generate 0xffffffffffffffff for alpha - - convertloop: - READUYVY_AVX2 - YUVTORGB_AVX2(ebx) - STOREARGB_AVX2 - - sub ecx, 16 - jg convertloop - - pop ebx - vzeroupper - ret - } -} -#endif // HAS_UYVYTOARGBROW_AVX2 - -#ifdef HAS_I422TORGBAROW_AVX2 -// 16 pixels -// 8 UV values upsampled to 16 UV, mixed with 16 Y producing 16 RGBA (64 bytes). -__declspec(naked) void I422ToRGBARow_AVX2( - const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push edi - push ebx - mov eax, [esp + 12 + 4] // Y - mov esi, [esp + 12 + 8] // U - mov edi, [esp + 12 + 12] // V - mov edx, [esp + 12 + 16] // abgr - mov ebx, [esp + 12 + 20] // yuvconstants - mov ecx, [esp + 12 + 24] // width - sub edi, esi - vpcmpeqb ymm5, ymm5, ymm5 // generate 0xffffffffffffffff for alpha - - convertloop: - READYUV422_AVX2 - YUVTORGB_AVX2(ebx) - STORERGBA_AVX2 - - sub ecx, 16 - jg convertloop - - pop ebx - pop edi - pop esi - vzeroupper - ret - } -} -#endif // HAS_I422TORGBAROW_AVX2 - -#if defined(HAS_I422TOARGBROW_SSSE3) -// TODO(fbarchard): Read that does half size on Y and treats 420 as 444. -// Allows a conversion with half size scaling. - -// Read 8 UV from 444. -#define READYUV444 \ - __asm { \ - __asm movq xmm0, qword ptr [esi] /* U */ \ - __asm movq xmm1, qword ptr [esi + edi] /* V */ \ - __asm lea esi, [esi + 8] \ - __asm punpcklbw xmm0, xmm1 /* UV */ \ - __asm movq xmm4, qword ptr [eax] \ - __asm punpcklbw xmm4, xmm4 \ - __asm lea eax, [eax + 8]} - -// Read 4 UV from 422, upsample to 8 UV. -#define READYUV422 \ - __asm { \ - __asm movd xmm0, [esi] /* U */ \ - __asm movd xmm1, [esi + edi] /* V */ \ - __asm lea esi, [esi + 4] \ - __asm punpcklbw xmm0, xmm1 /* UV */ \ - __asm punpcklwd xmm0, xmm0 /* UVUV (upsample) */ \ - __asm movq xmm4, qword ptr [eax] \ - __asm punpcklbw xmm4, xmm4 \ - __asm lea eax, [eax + 8]} - -// Read 4 UV from 422, upsample to 8 UV. With 8 Alpha. -#define READYUVA422 \ - __asm { \ - __asm movd xmm0, [esi] /* U */ \ - __asm movd xmm1, [esi + edi] /* V */ \ - __asm lea esi, [esi + 4] \ - __asm punpcklbw xmm0, xmm1 /* UV */ \ - __asm punpcklwd xmm0, xmm0 /* UVUV (upsample) */ \ - __asm movq xmm4, qword ptr [eax] /* Y */ \ - __asm punpcklbw xmm4, xmm4 \ - __asm lea eax, [eax + 8] \ - __asm movq xmm5, qword ptr [ebp] /* A */ \ - __asm lea ebp, [ebp + 8]} - -// Read 4 UV from NV12, upsample to 8 UV. -#define READNV12 \ - __asm { \ - __asm movq xmm0, qword ptr [esi] /* UV */ \ - __asm lea esi, [esi + 8] \ - __asm punpcklwd xmm0, xmm0 /* UVUV (upsample) */ \ - __asm movq xmm4, qword ptr [eax] \ - __asm punpcklbw xmm4, xmm4 \ - __asm lea eax, [eax + 8]} - -// Read 4 VU from NV21, upsample to 8 UV. -#define READNV21 \ - __asm { \ - __asm movq xmm0, qword ptr [esi] /* UV */ \ - __asm lea esi, [esi + 8] \ - __asm pshufb xmm0, xmmword ptr kShuffleNV21 \ - __asm movq xmm4, qword ptr [eax] \ - __asm punpcklbw xmm4, xmm4 \ - __asm lea eax, [eax + 8]} - -// Read 4 YUY2 with 8 Y and upsample 4 UV to 8 UV. -#define READYUY2 \ - __asm { \ - __asm movdqu xmm4, [eax] /* YUY2 */ \ - __asm pshufb xmm4, xmmword ptr kShuffleYUY2Y \ - __asm movdqu xmm0, [eax] /* UV */ \ - __asm pshufb xmm0, xmmword ptr kShuffleYUY2UV \ - __asm lea eax, [eax + 16]} - -// Read 4 UYVY with 8 Y and upsample 4 UV to 8 UV. -#define READUYVY \ - __asm { \ - __asm movdqu xmm4, [eax] /* UYVY */ \ - __asm pshufb xmm4, xmmword ptr kShuffleUYVYY \ - __asm movdqu xmm0, [eax] /* UV */ \ - __asm pshufb xmm0, xmmword ptr kShuffleUYVYUV \ - __asm lea eax, [eax + 16]} - -// Convert 8 pixels: 8 UV and 8 Y. -#define YUVTORGB(YuvConstants) \ - __asm { \ - __asm movdqa xmm1, xmm0 \ - __asm movdqa xmm2, xmm0 \ - __asm movdqa xmm3, xmm0 \ - __asm movdqa xmm0, xmmword ptr [YuvConstants + KUVBIASB] \ - __asm pmaddubsw xmm1, xmmword ptr [YuvConstants + KUVTOB] \ - __asm psubw xmm0, xmm1 \ - __asm movdqa xmm1, xmmword ptr [YuvConstants + KUVBIASG] \ - __asm pmaddubsw xmm2, xmmword ptr [YuvConstants + KUVTOG] \ - __asm psubw xmm1, xmm2 \ - __asm movdqa xmm2, xmmword ptr [YuvConstants + KUVBIASR] \ - __asm pmaddubsw xmm3, xmmword ptr [YuvConstants + KUVTOR] \ - __asm psubw xmm2, xmm3 \ - __asm pmulhuw xmm4, xmmword ptr [YuvConstants + KYTORGB] \ - __asm paddsw xmm0, xmm4 /* B += Y */ \ - __asm paddsw xmm1, xmm4 /* G += Y */ \ - __asm paddsw xmm2, xmm4 /* R += Y */ \ - __asm psraw xmm0, 6 \ - __asm psraw xmm1, 6 \ - __asm psraw xmm2, 6 \ - __asm packuswb xmm0, xmm0 /* B */ \ - __asm packuswb xmm1, xmm1 /* G */ \ - __asm packuswb xmm2, xmm2 /* R */ \ - } - -// Store 8 ARGB values. -#define STOREARGB \ - __asm { \ - __asm punpcklbw xmm0, xmm1 /* BG */ \ - __asm punpcklbw xmm2, xmm5 /* RA */ \ - __asm movdqa xmm1, xmm0 \ - __asm punpcklwd xmm0, xmm2 /* BGRA first 4 pixels */ \ - __asm punpckhwd xmm1, xmm2 /* BGRA next 4 pixels */ \ - __asm movdqu 0[edx], xmm0 \ - __asm movdqu 16[edx], xmm1 \ - __asm lea edx, [edx + 32]} - -// Store 8 BGRA values. -#define STOREBGRA \ - __asm { \ - __asm pcmpeqb xmm5, xmm5 /* generate 0xffffffff for alpha */ \ - __asm punpcklbw xmm1, xmm0 /* GB */ \ - __asm punpcklbw xmm5, xmm2 /* AR */ \ - __asm movdqa xmm0, xmm5 \ - __asm punpcklwd xmm5, xmm1 /* BGRA first 4 pixels */ \ - __asm punpckhwd xmm0, xmm1 /* BGRA next 4 pixels */ \ - __asm movdqu 0[edx], xmm5 \ - __asm movdqu 16[edx], xmm0 \ - __asm lea edx, [edx + 32]} - -// Store 8 RGBA values. -#define STORERGBA \ - __asm { \ - __asm pcmpeqb xmm5, xmm5 /* generate 0xffffffff for alpha */ \ - __asm punpcklbw xmm1, xmm2 /* GR */ \ - __asm punpcklbw xmm5, xmm0 /* AB */ \ - __asm movdqa xmm0, xmm5 \ - __asm punpcklwd xmm5, xmm1 /* RGBA first 4 pixels */ \ - __asm punpckhwd xmm0, xmm1 /* RGBA next 4 pixels */ \ - __asm movdqu 0[edx], xmm5 \ - __asm movdqu 16[edx], xmm0 \ - __asm lea edx, [edx + 32]} - -// Store 8 RGB24 values. -#define STORERGB24 \ - __asm {/* Weave into RRGB */ \ - __asm punpcklbw xmm0, xmm1 /* BG */ \ - __asm punpcklbw xmm2, xmm2 /* RR */ \ - __asm movdqa xmm1, xmm0 \ - __asm punpcklwd xmm0, xmm2 /* BGRR first 4 pixels */ \ - __asm punpckhwd xmm1, xmm2 /* BGRR next 4 pixels */ /* RRGB -> RGB24 */ \ - __asm pshufb xmm0, xmm5 /* Pack first 8 and last 4 bytes. */ \ - __asm pshufb xmm1, xmm6 /* Pack first 12 bytes. */ \ - __asm palignr xmm1, xmm0, 12 /* last 4 bytes of xmm0 + 12 xmm1 */ \ - __asm movq qword ptr 0[edx], xmm0 /* First 8 bytes */ \ - __asm movdqu 8[edx], xmm1 /* Last 16 bytes */ \ - __asm lea edx, [edx + 24]} - -// Store 8 RGB565 values. -#define STORERGB565 \ - __asm {/* Weave into RRGB */ \ - __asm punpcklbw xmm0, xmm1 /* BG */ \ - __asm punpcklbw xmm2, xmm2 /* RR */ \ - __asm movdqa xmm1, xmm0 \ - __asm punpcklwd xmm0, xmm2 /* BGRR first 4 pixels */ \ - __asm punpckhwd xmm1, xmm2 /* BGRR next 4 pixels */ /* RRGB -> RGB565 */ \ - __asm movdqa xmm3, xmm0 /* B first 4 pixels of argb */ \ - __asm movdqa xmm2, xmm0 /* G */ \ - __asm pslld xmm0, 8 /* R */ \ - __asm psrld xmm3, 3 /* B */ \ - __asm psrld xmm2, 5 /* G */ \ - __asm psrad xmm0, 16 /* R */ \ - __asm pand xmm3, xmm5 /* B */ \ - __asm pand xmm2, xmm6 /* G */ \ - __asm pand xmm0, xmm7 /* R */ \ - __asm por xmm3, xmm2 /* BG */ \ - __asm por xmm0, xmm3 /* BGR */ \ - __asm movdqa xmm3, xmm1 /* B next 4 pixels of argb */ \ - __asm movdqa xmm2, xmm1 /* G */ \ - __asm pslld xmm1, 8 /* R */ \ - __asm psrld xmm3, 3 /* B */ \ - __asm psrld xmm2, 5 /* G */ \ - __asm psrad xmm1, 16 /* R */ \ - __asm pand xmm3, xmm5 /* B */ \ - __asm pand xmm2, xmm6 /* G */ \ - __asm pand xmm1, xmm7 /* R */ \ - __asm por xmm3, xmm2 /* BG */ \ - __asm por xmm1, xmm3 /* BGR */ \ - __asm packssdw xmm0, xmm1 \ - __asm movdqu 0[edx], xmm0 /* store 8 pixels of RGB565 */ \ - __asm lea edx, [edx + 16]} - -// 8 pixels. -// 8 UV values, mixed with 8 Y producing 8 ARGB (32 bytes). -__declspec(naked) void I444ToARGBRow_SSSE3( - const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push edi - push ebx - mov eax, [esp + 12 + 4] // Y - mov esi, [esp + 12 + 8] // U - mov edi, [esp + 12 + 12] // V - mov edx, [esp + 12 + 16] // argb - mov ebx, [esp + 12 + 20] // yuvconstants - mov ecx, [esp + 12 + 24] // width - sub edi, esi - pcmpeqb xmm5, xmm5 // generate 0xffffffff for alpha - - convertloop: - READYUV444 - YUVTORGB(ebx) - STOREARGB - - sub ecx, 8 - jg convertloop - - pop ebx - pop edi - pop esi - ret - } -} - -// 8 pixels. -// 4 UV values upsampled to 8 UV, mixed with 8 Y producing 8 RGB24 (24 bytes). -__declspec(naked) void I422ToRGB24Row_SSSE3( - const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_rgb24, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push edi - push ebx - mov eax, [esp + 12 + 4] // Y - mov esi, [esp + 12 + 8] // U - mov edi, [esp + 12 + 12] // V - mov edx, [esp + 12 + 16] // argb - mov ebx, [esp + 12 + 20] // yuvconstants - mov ecx, [esp + 12 + 24] // width - sub edi, esi - movdqa xmm5, xmmword ptr kShuffleMaskARGBToRGB24_0 - movdqa xmm6, xmmword ptr kShuffleMaskARGBToRGB24 - - convertloop: - READYUV422 - YUVTORGB(ebx) - STORERGB24 - - sub ecx, 8 - jg convertloop - - pop ebx - pop edi - pop esi - ret - } -} - -// 8 pixels -// 4 UV values upsampled to 8 UV, mixed with 8 Y producing 8 RGB565 (16 bytes). -__declspec(naked) void I422ToRGB565Row_SSSE3( - const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* rgb565_buf, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push edi - push ebx - mov eax, [esp + 12 + 4] // Y - mov esi, [esp + 12 + 8] // U - mov edi, [esp + 12 + 12] // V - mov edx, [esp + 12 + 16] // argb - mov ebx, [esp + 12 + 20] // yuvconstants - mov ecx, [esp + 12 + 24] // width - sub edi, esi - pcmpeqb xmm5, xmm5 // generate mask 0x0000001f - psrld xmm5, 27 - pcmpeqb xmm6, xmm6 // generate mask 0x000007e0 - psrld xmm6, 26 - pslld xmm6, 5 - pcmpeqb xmm7, xmm7 // generate mask 0xfffff800 - pslld xmm7, 11 - - convertloop: - READYUV422 - YUVTORGB(ebx) - STORERGB565 - - sub ecx, 8 - jg convertloop - - pop ebx - pop edi - pop esi - ret - } -} - -// 8 pixels. -// 4 UV values upsampled to 8 UV, mixed with 8 Y producing 8 ARGB (32 bytes). -__declspec(naked) void I422ToARGBRow_SSSE3( - const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push edi - push ebx - mov eax, [esp + 12 + 4] // Y - mov esi, [esp + 12 + 8] // U - mov edi, [esp + 12 + 12] // V - mov edx, [esp + 12 + 16] // argb - mov ebx, [esp + 12 + 20] // yuvconstants - mov ecx, [esp + 12 + 24] // width - sub edi, esi - pcmpeqb xmm5, xmm5 // generate 0xffffffff for alpha - - convertloop: - READYUV422 - YUVTORGB(ebx) - STOREARGB - - sub ecx, 8 - jg convertloop - - pop ebx - pop edi - pop esi - ret - } -} - -// 8 pixels. -// 4 UV values upsampled to 8 UV, mixed with 8 Y and 8 A producing 8 ARGB. -__declspec(naked) void I422AlphaToARGBRow_SSSE3( - const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - const uint8_t* a_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push edi - push ebx - push ebp - mov eax, [esp + 16 + 4] // Y - mov esi, [esp + 16 + 8] // U - mov edi, [esp + 16 + 12] // V - mov ebp, [esp + 16 + 16] // A - mov edx, [esp + 16 + 20] // argb - mov ebx, [esp + 16 + 24] // yuvconstants - mov ecx, [esp + 16 + 28] // width - sub edi, esi - - convertloop: - READYUVA422 - YUVTORGB(ebx) - STOREARGB - - sub ecx, 8 - jg convertloop - - pop ebp - pop ebx - pop edi - pop esi - ret - } -} - -// 8 pixels. -// 4 UV values upsampled to 8 UV, mixed with 8 Y producing 8 ARGB (32 bytes). -__declspec(naked) void NV12ToARGBRow_SSSE3( - const uint8_t* y_buf, - const uint8_t* uv_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push ebx - mov eax, [esp + 8 + 4] // Y - mov esi, [esp + 8 + 8] // UV - mov edx, [esp + 8 + 12] // argb - mov ebx, [esp + 8 + 16] // yuvconstants - mov ecx, [esp + 8 + 20] // width - pcmpeqb xmm5, xmm5 // generate 0xffffffff for alpha - - convertloop: - READNV12 - YUVTORGB(ebx) - STOREARGB - - sub ecx, 8 - jg convertloop - - pop ebx - pop esi - ret - } -} - -// 8 pixels. -// 4 UV values upsampled to 8 UV, mixed with 8 Y producing 8 ARGB (32 bytes). -__declspec(naked) void NV21ToARGBRow_SSSE3( - const uint8_t* y_buf, - const uint8_t* vu_buf, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push ebx - mov eax, [esp + 8 + 4] // Y - mov esi, [esp + 8 + 8] // VU - mov edx, [esp + 8 + 12] // argb - mov ebx, [esp + 8 + 16] // yuvconstants - mov ecx, [esp + 8 + 20] // width - pcmpeqb xmm5, xmm5 // generate 0xffffffff for alpha - - convertloop: - READNV21 - YUVTORGB(ebx) - STOREARGB - - sub ecx, 8 - jg convertloop - - pop ebx - pop esi - ret - } -} - -// 8 pixels. -// 4 YUY2 values with 8 Y and 4 UV producing 8 ARGB (32 bytes). -__declspec(naked) void YUY2ToARGBRow_SSSE3( - const uint8_t* src_yuy2, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push ebx - mov eax, [esp + 4 + 4] // yuy2 - mov edx, [esp + 4 + 8] // argb - mov ebx, [esp + 4 + 12] // yuvconstants - mov ecx, [esp + 4 + 16] // width - pcmpeqb xmm5, xmm5 // generate 0xffffffff for alpha - - convertloop: - READYUY2 - YUVTORGB(ebx) - STOREARGB - - sub ecx, 8 - jg convertloop - - pop ebx - ret - } -} - -// 8 pixels. -// 4 UYVY values with 8 Y and 4 UV producing 8 ARGB (32 bytes). -__declspec(naked) void UYVYToARGBRow_SSSE3( - const uint8_t* src_uyvy, - uint8_t* dst_argb, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push ebx - mov eax, [esp + 4 + 4] // uyvy - mov edx, [esp + 4 + 8] // argb - mov ebx, [esp + 4 + 12] // yuvconstants - mov ecx, [esp + 4 + 16] // width - pcmpeqb xmm5, xmm5 // generate 0xffffffff for alpha - - convertloop: - READUYVY - YUVTORGB(ebx) - STOREARGB - - sub ecx, 8 - jg convertloop - - pop ebx - ret - } -} - -__declspec(naked) void I422ToRGBARow_SSSE3( - const uint8_t* y_buf, - const uint8_t* u_buf, - const uint8_t* v_buf, - uint8_t* dst_rgba, - const struct YuvConstants* yuvconstants, - int width) { - __asm { - push esi - push edi - push ebx - mov eax, [esp + 12 + 4] // Y - mov esi, [esp + 12 + 8] // U - mov edi, [esp + 12 + 12] // V - mov edx, [esp + 12 + 16] // argb - mov ebx, [esp + 12 + 20] // yuvconstants - mov ecx, [esp + 12 + 24] // width - sub edi, esi - - convertloop: - READYUV422 - YUVTORGB(ebx) - STORERGBA - - sub ecx, 8 - jg convertloop - - pop ebx - pop edi - pop esi - ret - } -} -#endif // HAS_I422TOARGBROW_SSSE3 - -#ifdef HAS_I400TOARGBROW_SSE2 -// 8 pixels of Y converted to 8 pixels of ARGB (32 bytes). -__declspec(naked) void I400ToARGBRow_SSE2(const uint8_t* y_buf, - uint8_t* rgb_buf, - int width) { - __asm { - mov eax, 0x4a354a35 // 4a35 = 18997 = round(1.164 * 64 * 256) - movd xmm2, eax - pshufd xmm2, xmm2,0 - mov eax, 0x04880488 // 0488 = 1160 = round(1.164 * 64 * 16) - movd xmm3, eax - pshufd xmm3, xmm3, 0 - pcmpeqb xmm4, xmm4 // generate mask 0xff000000 - pslld xmm4, 24 - - mov eax, [esp + 4] // Y - mov edx, [esp + 8] // rgb - mov ecx, [esp + 12] // width - - convertloop: - // Step 1: Scale Y contribution to 8 G values. G = (y - 16) * 1.164 - movq xmm0, qword ptr [eax] - lea eax, [eax + 8] - punpcklbw xmm0, xmm0 // Y.Y - pmulhuw xmm0, xmm2 - psubusw xmm0, xmm3 - psrlw xmm0, 6 - packuswb xmm0, xmm0 // G - - // Step 2: Weave into ARGB - punpcklbw xmm0, xmm0 // GG - movdqa xmm1, xmm0 - punpcklwd xmm0, xmm0 // BGRA first 4 pixels - punpckhwd xmm1, xmm1 // BGRA next 4 pixels - por xmm0, xmm4 - por xmm1, xmm4 - movdqu [edx], xmm0 - movdqu [edx + 16], xmm1 - lea edx, [edx + 32] - sub ecx, 8 - jg convertloop - ret - } -} -#endif // HAS_I400TOARGBROW_SSE2 - -#ifdef HAS_I400TOARGBROW_AVX2 -// 16 pixels of Y converted to 16 pixels of ARGB (64 bytes). -// note: vpunpcklbw mutates and vpackuswb unmutates. -__declspec(naked) void I400ToARGBRow_AVX2(const uint8_t* y_buf, - uint8_t* rgb_buf, - int width) { - __asm { - mov eax, 0x4a354a35 // 4a35 = 18997 = round(1.164 * 64 * 256) - vmovd xmm2, eax - vbroadcastss ymm2, xmm2 - mov eax, 0x04880488 // 0488 = 1160 = round(1.164 * 64 * 16) - vmovd xmm3, eax - vbroadcastss ymm3, xmm3 - vpcmpeqb ymm4, ymm4, ymm4 // generate mask 0xff000000 - vpslld ymm4, ymm4, 24 - - mov eax, [esp + 4] // Y - mov edx, [esp + 8] // rgb - mov ecx, [esp + 12] // width - - convertloop: - // Step 1: Scale Y contriportbution to 16 G values. G = (y - 16) * 1.164 - vmovdqu xmm0, [eax] - lea eax, [eax + 16] - vpermq ymm0, ymm0, 0xd8 // vpunpcklbw mutates - vpunpcklbw ymm0, ymm0, ymm0 // Y.Y - vpmulhuw ymm0, ymm0, ymm2 - vpsubusw ymm0, ymm0, ymm3 - vpsrlw ymm0, ymm0, 6 - vpackuswb ymm0, ymm0, ymm0 // G. still mutated: 3120 - - // TODO(fbarchard): Weave alpha with unpack. - // Step 2: Weave into ARGB - vpunpcklbw ymm1, ymm0, ymm0 // GG - mutates - vpermq ymm1, ymm1, 0xd8 - vpunpcklwd ymm0, ymm1, ymm1 // GGGG first 8 pixels - vpunpckhwd ymm1, ymm1, ymm1 // GGGG next 8 pixels - vpor ymm0, ymm0, ymm4 - vpor ymm1, ymm1, ymm4 - vmovdqu [edx], ymm0 - vmovdqu [edx + 32], ymm1 - lea edx, [edx + 64] - sub ecx, 16 - jg convertloop - vzeroupper - ret - } -} -#endif // HAS_I400TOARGBROW_AVX2 - -#ifdef HAS_MIRRORROW_SSSE3 -// Shuffle table for reversing the bytes. -static const uvec8 kShuffleMirror = {15u, 14u, 13u, 12u, 11u, 10u, 9u, 8u, - 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u}; - -// TODO(fbarchard): Replace lea with -16 offset. -__declspec(naked) void MirrorRow_SSSE3(const uint8_t* src, - uint8_t* dst, - int width) { - __asm { - mov eax, [esp + 4] // src - mov edx, [esp + 8] // dst - mov ecx, [esp + 12] // width - movdqa xmm5, xmmword ptr kShuffleMirror - - convertloop: - movdqu xmm0, [eax - 16 + ecx] - pshufb xmm0, xmm5 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg convertloop - ret - } -} -#endif // HAS_MIRRORROW_SSSE3 - -#ifdef HAS_MIRRORROW_AVX2 -__declspec(naked) void MirrorRow_AVX2(const uint8_t* src, - uint8_t* dst, - int width) { - __asm { - mov eax, [esp + 4] // src - mov edx, [esp + 8] // dst - mov ecx, [esp + 12] // width - vbroadcastf128 ymm5, xmmword ptr kShuffleMirror - - convertloop: - vmovdqu ymm0, [eax - 32 + ecx] - vpshufb ymm0, ymm0, ymm5 - vpermq ymm0, ymm0, 0x4e // swap high and low halfs - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 32 - jg convertloop - vzeroupper - ret - } -} -#endif // HAS_MIRRORROW_AVX2 - -#ifdef HAS_MIRRORUVROW_SSSE3 -// Shuffle table for reversing the bytes of UV channels. -static const uvec8 kShuffleMirrorUV = {14u, 12u, 10u, 8u, 6u, 4u, 2u, 0u, - 15u, 13u, 11u, 9u, 7u, 5u, 3u, 1u}; - -__declspec(naked) void MirrorUVRow_SSSE3(const uint8_t* src, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push edi - mov eax, [esp + 4 + 4] // src - mov edx, [esp + 4 + 8] // dst_u - mov edi, [esp + 4 + 12] // dst_v - mov ecx, [esp + 4 + 16] // width - movdqa xmm1, xmmword ptr kShuffleMirrorUV - lea eax, [eax + ecx * 2 - 16] - sub edi, edx - - convertloop: - movdqu xmm0, [eax] - lea eax, [eax - 16] - pshufb xmm0, xmm1 - movlpd qword ptr [edx], xmm0 - movhpd qword ptr [edx + edi], xmm0 - lea edx, [edx + 8] - sub ecx, 8 - jg convertloop - - pop edi - ret - } -} -#endif // HAS_MIRRORUVROW_SSSE3 - -#ifdef HAS_ARGBMIRRORROW_SSE2 -__declspec(naked) void ARGBMirrorRow_SSE2(const uint8_t* src, - uint8_t* dst, - int width) { - __asm { - mov eax, [esp + 4] // src - mov edx, [esp + 8] // dst - mov ecx, [esp + 12] // width - lea eax, [eax - 16 + ecx * 4] // last 4 pixels. - - convertloop: - movdqu xmm0, [eax] - lea eax, [eax - 16] - pshufd xmm0, xmm0, 0x1b - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jg convertloop - ret - } -} -#endif // HAS_ARGBMIRRORROW_SSE2 - -#ifdef HAS_ARGBMIRRORROW_AVX2 -// Shuffle table for reversing the bytes. -static const ulvec32 kARGBShuffleMirror_AVX2 = {7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u}; - -__declspec(naked) void ARGBMirrorRow_AVX2(const uint8_t* src, - uint8_t* dst, - int width) { - __asm { - mov eax, [esp + 4] // src - mov edx, [esp + 8] // dst - mov ecx, [esp + 12] // width - vmovdqu ymm5, ymmword ptr kARGBShuffleMirror_AVX2 - - convertloop: - vpermd ymm0, ymm5, [eax - 32 + ecx * 4] // permute dword order - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 8 - jg convertloop - vzeroupper - ret - } -} -#endif // HAS_ARGBMIRRORROW_AVX2 - -#ifdef HAS_SPLITUVROW_SSE2 -__declspec(naked) void SplitUVRow_SSE2(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push edi - mov eax, [esp + 4 + 4] // src_uv - mov edx, [esp + 4 + 8] // dst_u - mov edi, [esp + 4 + 12] // dst_v - mov ecx, [esp + 4 + 16] // width - pcmpeqb xmm5, xmm5 // generate mask 0x00ff00ff - psrlw xmm5, 8 - sub edi, edx - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - lea eax, [eax + 32] - movdqa xmm2, xmm0 - movdqa xmm3, xmm1 - pand xmm0, xmm5 // even bytes - pand xmm1, xmm5 - packuswb xmm0, xmm1 - psrlw xmm2, 8 // odd bytes - psrlw xmm3, 8 - packuswb xmm2, xmm3 - movdqu [edx], xmm0 - movdqu [edx + edi], xmm2 - lea edx, [edx + 16] - sub ecx, 16 - jg convertloop - - pop edi - ret - } -} - -#endif // HAS_SPLITUVROW_SSE2 - -#ifdef HAS_SPLITUVROW_AVX2 -__declspec(naked) void SplitUVRow_AVX2(const uint8_t* src_uv, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push edi - mov eax, [esp + 4 + 4] // src_uv - mov edx, [esp + 4 + 8] // dst_u - mov edi, [esp + 4 + 12] // dst_v - mov ecx, [esp + 4 + 16] // width - vpcmpeqb ymm5, ymm5, ymm5 // generate mask 0x00ff00ff - vpsrlw ymm5, ymm5, 8 - sub edi, edx - - convertloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - lea eax, [eax + 64] - vpsrlw ymm2, ymm0, 8 // odd bytes - vpsrlw ymm3, ymm1, 8 - vpand ymm0, ymm0, ymm5 // even bytes - vpand ymm1, ymm1, ymm5 - vpackuswb ymm0, ymm0, ymm1 - vpackuswb ymm2, ymm2, ymm3 - vpermq ymm0, ymm0, 0xd8 - vpermq ymm2, ymm2, 0xd8 - vmovdqu [edx], ymm0 - vmovdqu [edx + edi], ymm2 - lea edx, [edx + 32] - sub ecx, 32 - jg convertloop - - pop edi - vzeroupper - ret - } -} -#endif // HAS_SPLITUVROW_AVX2 - -#ifdef HAS_MERGEUVROW_SSE2 -__declspec(naked) void MergeUVRow_SSE2(const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_uv, - int width) { - __asm { - push edi - mov eax, [esp + 4 + 4] // src_u - mov edx, [esp + 4 + 8] // src_v - mov edi, [esp + 4 + 12] // dst_uv - mov ecx, [esp + 4 + 16] // width - sub edx, eax - - convertloop: - movdqu xmm0, [eax] // read 16 U's - movdqu xmm1, [eax + edx] // and 16 V's - lea eax, [eax + 16] - movdqa xmm2, xmm0 - punpcklbw xmm0, xmm1 // first 8 UV pairs - punpckhbw xmm2, xmm1 // next 8 UV pairs - movdqu [edi], xmm0 - movdqu [edi + 16], xmm2 - lea edi, [edi + 32] - sub ecx, 16 - jg convertloop - - pop edi - ret - } -} -#endif // HAS_MERGEUVROW_SSE2 - -#ifdef HAS_MERGEUVROW_AVX2 -__declspec(naked) void MergeUVRow_AVX2(const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_uv, - int width) { - __asm { - push edi - mov eax, [esp + 4 + 4] // src_u - mov edx, [esp + 4 + 8] // src_v - mov edi, [esp + 4 + 12] // dst_uv - mov ecx, [esp + 4 + 16] // width - sub edx, eax - - convertloop: - vmovdqu ymm0, [eax] // read 32 U's - vmovdqu ymm1, [eax + edx] // and 32 V's - lea eax, [eax + 32] - vpunpcklbw ymm2, ymm0, ymm1 // low 16 UV pairs. mutated qqword 0,2 - vpunpckhbw ymm0, ymm0, ymm1 // high 16 UV pairs. mutated qqword 1,3 - vextractf128 [edi], ymm2, 0 // bytes 0..15 - vextractf128 [edi + 16], ymm0, 0 // bytes 16..31 - vextractf128 [edi + 32], ymm2, 1 // bytes 32..47 - vextractf128 [edi + 48], ymm0, 1 // bytes 47..63 - lea edi, [edi + 64] - sub ecx, 32 - jg convertloop - - pop edi - vzeroupper - ret - } -} -#endif // HAS_MERGEUVROW_AVX2 - -#ifdef HAS_COPYROW_SSE2 -// CopyRow copys 'width' bytes using a 16 byte load/store, 32 bytes at time. -__declspec(naked) void CopyRow_SSE2(const uint8_t* src, - uint8_t* dst, - int width) { - __asm { - mov eax, [esp + 4] // src - mov edx, [esp + 8] // dst - mov ecx, [esp + 12] // width - test eax, 15 - jne convertloopu - test edx, 15 - jne convertloopu - - convertloopa: - movdqa xmm0, [eax] - movdqa xmm1, [eax + 16] - lea eax, [eax + 32] - movdqa [edx], xmm0 - movdqa [edx + 16], xmm1 - lea edx, [edx + 32] - sub ecx, 32 - jg convertloopa - ret - - convertloopu: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - lea eax, [eax + 32] - movdqu [edx], xmm0 - movdqu [edx + 16], xmm1 - lea edx, [edx + 32] - sub ecx, 32 - jg convertloopu - ret - } -} -#endif // HAS_COPYROW_SSE2 - -#ifdef HAS_COPYROW_AVX -// CopyRow copys 'width' bytes using a 32 byte load/store, 64 bytes at time. -__declspec(naked) void CopyRow_AVX(const uint8_t* src, - uint8_t* dst, - int width) { - __asm { - mov eax, [esp + 4] // src - mov edx, [esp + 8] // dst - mov ecx, [esp + 12] // width - - convertloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - lea eax, [eax + 64] - vmovdqu [edx], ymm0 - vmovdqu [edx + 32], ymm1 - lea edx, [edx + 64] - sub ecx, 64 - jg convertloop - - vzeroupper - ret - } -} -#endif // HAS_COPYROW_AVX - -// Multiple of 1. -__declspec(naked) void CopyRow_ERMS(const uint8_t* src, - uint8_t* dst, - int width) { - __asm { - mov eax, esi - mov edx, edi - mov esi, [esp + 4] // src - mov edi, [esp + 8] // dst - mov ecx, [esp + 12] // width - rep movsb - mov edi, edx - mov esi, eax - ret - } -} - -#ifdef HAS_ARGBCOPYALPHAROW_SSE2 -// width in pixels -__declspec(naked) void ARGBCopyAlphaRow_SSE2(const uint8_t* src, - uint8_t* dst, - int width) { - __asm { - mov eax, [esp + 4] // src - mov edx, [esp + 8] // dst - mov ecx, [esp + 12] // width - pcmpeqb xmm0, xmm0 // generate mask 0xff000000 - pslld xmm0, 24 - pcmpeqb xmm1, xmm1 // generate mask 0x00ffffff - psrld xmm1, 8 - - convertloop: - movdqu xmm2, [eax] - movdqu xmm3, [eax + 16] - lea eax, [eax + 32] - movdqu xmm4, [edx] - movdqu xmm5, [edx + 16] - pand xmm2, xmm0 - pand xmm3, xmm0 - pand xmm4, xmm1 - pand xmm5, xmm1 - por xmm2, xmm4 - por xmm3, xmm5 - movdqu [edx], xmm2 - movdqu [edx + 16], xmm3 - lea edx, [edx + 32] - sub ecx, 8 - jg convertloop - - ret - } -} -#endif // HAS_ARGBCOPYALPHAROW_SSE2 - -#ifdef HAS_ARGBCOPYALPHAROW_AVX2 -// width in pixels -__declspec(naked) void ARGBCopyAlphaRow_AVX2(const uint8_t* src, - uint8_t* dst, - int width) { - __asm { - mov eax, [esp + 4] // src - mov edx, [esp + 8] // dst - mov ecx, [esp + 12] // width - vpcmpeqb ymm0, ymm0, ymm0 - vpsrld ymm0, ymm0, 8 // generate mask 0x00ffffff - - convertloop: - vmovdqu ymm1, [eax] - vmovdqu ymm2, [eax + 32] - lea eax, [eax + 64] - vpblendvb ymm1, ymm1, [edx], ymm0 - vpblendvb ymm2, ymm2, [edx + 32], ymm0 - vmovdqu [edx], ymm1 - vmovdqu [edx + 32], ymm2 - lea edx, [edx + 64] - sub ecx, 16 - jg convertloop - - vzeroupper - ret - } -} -#endif // HAS_ARGBCOPYALPHAROW_AVX2 - -#ifdef HAS_ARGBEXTRACTALPHAROW_SSE2 -// width in pixels -__declspec(naked) void ARGBExtractAlphaRow_SSE2(const uint8_t* src_argb, - uint8_t* dst_a, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_a - mov ecx, [esp + 12] // width - - extractloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - lea eax, [eax + 32] - psrld xmm0, 24 - psrld xmm1, 24 - packssdw xmm0, xmm1 - packuswb xmm0, xmm0 - movq qword ptr [edx], xmm0 - lea edx, [edx + 8] - sub ecx, 8 - jg extractloop - - ret - } -} -#endif // HAS_ARGBEXTRACTALPHAROW_SSE2 - -#ifdef HAS_ARGBEXTRACTALPHAROW_AVX2 -// width in pixels -__declspec(naked) void ARGBExtractAlphaRow_AVX2(const uint8_t* src_argb, - uint8_t* dst_a, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_a - mov ecx, [esp + 12] // width - vmovdqa ymm4, ymmword ptr kPermdARGBToY_AVX - - extractloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - vpsrld ymm0, ymm0, 24 - vpsrld ymm1, ymm1, 24 - vmovdqu ymm2, [eax + 64] - vmovdqu ymm3, [eax + 96] - lea eax, [eax + 128] - vpackssdw ymm0, ymm0, ymm1 // mutates - vpsrld ymm2, ymm2, 24 - vpsrld ymm3, ymm3, 24 - vpackssdw ymm2, ymm2, ymm3 // mutates - vpackuswb ymm0, ymm0, ymm2 // mutates - vpermd ymm0, ymm4, ymm0 // unmutate - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 32 - jg extractloop - - vzeroupper - ret - } -} -#endif // HAS_ARGBEXTRACTALPHAROW_AVX2 - -#ifdef HAS_ARGBCOPYYTOALPHAROW_SSE2 -// width in pixels -__declspec(naked) void ARGBCopyYToAlphaRow_SSE2(const uint8_t* src, - uint8_t* dst, - int width) { - __asm { - mov eax, [esp + 4] // src - mov edx, [esp + 8] // dst - mov ecx, [esp + 12] // width - pcmpeqb xmm0, xmm0 // generate mask 0xff000000 - pslld xmm0, 24 - pcmpeqb xmm1, xmm1 // generate mask 0x00ffffff - psrld xmm1, 8 - - convertloop: - movq xmm2, qword ptr [eax] // 8 Y's - lea eax, [eax + 8] - punpcklbw xmm2, xmm2 - punpckhwd xmm3, xmm2 - punpcklwd xmm2, xmm2 - movdqu xmm4, [edx] - movdqu xmm5, [edx + 16] - pand xmm2, xmm0 - pand xmm3, xmm0 - pand xmm4, xmm1 - pand xmm5, xmm1 - por xmm2, xmm4 - por xmm3, xmm5 - movdqu [edx], xmm2 - movdqu [edx + 16], xmm3 - lea edx, [edx + 32] - sub ecx, 8 - jg convertloop - - ret - } -} -#endif // HAS_ARGBCOPYYTOALPHAROW_SSE2 - -#ifdef HAS_ARGBCOPYYTOALPHAROW_AVX2 -// width in pixels -__declspec(naked) void ARGBCopyYToAlphaRow_AVX2(const uint8_t* src, - uint8_t* dst, - int width) { - __asm { - mov eax, [esp + 4] // src - mov edx, [esp + 8] // dst - mov ecx, [esp + 12] // width - vpcmpeqb ymm0, ymm0, ymm0 - vpsrld ymm0, ymm0, 8 // generate mask 0x00ffffff - - convertloop: - vpmovzxbd ymm1, qword ptr [eax] - vpmovzxbd ymm2, qword ptr [eax + 8] - lea eax, [eax + 16] - vpslld ymm1, ymm1, 24 - vpslld ymm2, ymm2, 24 - vpblendvb ymm1, ymm1, [edx], ymm0 - vpblendvb ymm2, ymm2, [edx + 32], ymm0 - vmovdqu [edx], ymm1 - vmovdqu [edx + 32], ymm2 - lea edx, [edx + 64] - sub ecx, 16 - jg convertloop - - vzeroupper - ret - } -} -#endif // HAS_ARGBCOPYYTOALPHAROW_AVX2 - -#ifdef HAS_SETROW_X86 -// Write 'width' bytes using an 8 bit value repeated. -// width should be multiple of 4. -__declspec(naked) void SetRow_X86(uint8_t* dst, uint8_t v8, int width) { - __asm { - movzx eax, byte ptr [esp + 8] // v8 - mov edx, 0x01010101 // Duplicate byte to all bytes. - mul edx // overwrites edx with upper part of result. - mov edx, edi - mov edi, [esp + 4] // dst - mov ecx, [esp + 12] // width - shr ecx, 2 - rep stosd - mov edi, edx - ret - } -} - -// Write 'width' bytes using an 8 bit value repeated. -__declspec(naked) void SetRow_ERMS(uint8_t* dst, uint8_t v8, int width) { - __asm { - mov edx, edi - mov edi, [esp + 4] // dst - mov eax, [esp + 8] // v8 - mov ecx, [esp + 12] // width - rep stosb - mov edi, edx - ret - } -} - -// Write 'width' 32 bit values. -__declspec(naked) void ARGBSetRow_X86(uint8_t* dst_argb, - uint32_t v32, - int width) { - __asm { - mov edx, edi - mov edi, [esp + 4] // dst - mov eax, [esp + 8] // v32 - mov ecx, [esp + 12] // width - rep stosd - mov edi, edx - ret - } -} -#endif // HAS_SETROW_X86 - -#ifdef HAS_YUY2TOYROW_AVX2 -__declspec(naked) void YUY2ToYRow_AVX2(const uint8_t* src_yuy2, - uint8_t* dst_y, - int width) { - __asm { - mov eax, [esp + 4] // src_yuy2 - mov edx, [esp + 8] // dst_y - mov ecx, [esp + 12] // width - vpcmpeqb ymm5, ymm5, ymm5 // generate mask 0x00ff00ff - vpsrlw ymm5, ymm5, 8 - - convertloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - lea eax, [eax + 64] - vpand ymm0, ymm0, ymm5 // even bytes are Y - vpand ymm1, ymm1, ymm5 - vpackuswb ymm0, ymm0, ymm1 // mutates. - vpermq ymm0, ymm0, 0xd8 - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 32 - jg convertloop - vzeroupper - ret - } -} - -__declspec(naked) void YUY2ToUVRow_AVX2(const uint8_t* src_yuy2, - int stride_yuy2, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_yuy2 - mov esi, [esp + 8 + 8] // stride_yuy2 - mov edx, [esp + 8 + 12] // dst_u - mov edi, [esp + 8 + 16] // dst_v - mov ecx, [esp + 8 + 20] // width - vpcmpeqb ymm5, ymm5, ymm5 // generate mask 0x00ff00ff - vpsrlw ymm5, ymm5, 8 - sub edi, edx - - convertloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - vpavgb ymm0, ymm0, [eax + esi] - vpavgb ymm1, ymm1, [eax + esi + 32] - lea eax, [eax + 64] - vpsrlw ymm0, ymm0, 8 // YUYV -> UVUV - vpsrlw ymm1, ymm1, 8 - vpackuswb ymm0, ymm0, ymm1 // mutates. - vpermq ymm0, ymm0, 0xd8 - vpand ymm1, ymm0, ymm5 // U - vpsrlw ymm0, ymm0, 8 // V - vpackuswb ymm1, ymm1, ymm1 // mutates. - vpackuswb ymm0, ymm0, ymm0 // mutates. - vpermq ymm1, ymm1, 0xd8 - vpermq ymm0, ymm0, 0xd8 - vextractf128 [edx], ymm1, 0 // U - vextractf128 [edx + edi], ymm0, 0 // V - lea edx, [edx + 16] - sub ecx, 32 - jg convertloop - - pop edi - pop esi - vzeroupper - ret - } -} - -__declspec(naked) void YUY2ToUV422Row_AVX2(const uint8_t* src_yuy2, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push edi - mov eax, [esp + 4 + 4] // src_yuy2 - mov edx, [esp + 4 + 8] // dst_u - mov edi, [esp + 4 + 12] // dst_v - mov ecx, [esp + 4 + 16] // width - vpcmpeqb ymm5, ymm5, ymm5 // generate mask 0x00ff00ff - vpsrlw ymm5, ymm5, 8 - sub edi, edx - - convertloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - lea eax, [eax + 64] - vpsrlw ymm0, ymm0, 8 // YUYV -> UVUV - vpsrlw ymm1, ymm1, 8 - vpackuswb ymm0, ymm0, ymm1 // mutates. - vpermq ymm0, ymm0, 0xd8 - vpand ymm1, ymm0, ymm5 // U - vpsrlw ymm0, ymm0, 8 // V - vpackuswb ymm1, ymm1, ymm1 // mutates. - vpackuswb ymm0, ymm0, ymm0 // mutates. - vpermq ymm1, ymm1, 0xd8 - vpermq ymm0, ymm0, 0xd8 - vextractf128 [edx], ymm1, 0 // U - vextractf128 [edx + edi], ymm0, 0 // V - lea edx, [edx + 16] - sub ecx, 32 - jg convertloop - - pop edi - vzeroupper - ret - } -} - -__declspec(naked) void UYVYToYRow_AVX2(const uint8_t* src_uyvy, - uint8_t* dst_y, - int width) { - __asm { - mov eax, [esp + 4] // src_uyvy - mov edx, [esp + 8] // dst_y - mov ecx, [esp + 12] // width - - convertloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - lea eax, [eax + 64] - vpsrlw ymm0, ymm0, 8 // odd bytes are Y - vpsrlw ymm1, ymm1, 8 - vpackuswb ymm0, ymm0, ymm1 // mutates. - vpermq ymm0, ymm0, 0xd8 - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 32 - jg convertloop - vzeroupper - ret - } -} - -__declspec(naked) void UYVYToUVRow_AVX2(const uint8_t* src_uyvy, - int stride_uyvy, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_yuy2 - mov esi, [esp + 8 + 8] // stride_yuy2 - mov edx, [esp + 8 + 12] // dst_u - mov edi, [esp + 8 + 16] // dst_v - mov ecx, [esp + 8 + 20] // width - vpcmpeqb ymm5, ymm5, ymm5 // generate mask 0x00ff00ff - vpsrlw ymm5, ymm5, 8 - sub edi, edx - - convertloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - vpavgb ymm0, ymm0, [eax + esi] - vpavgb ymm1, ymm1, [eax + esi + 32] - lea eax, [eax + 64] - vpand ymm0, ymm0, ymm5 // UYVY -> UVUV - vpand ymm1, ymm1, ymm5 - vpackuswb ymm0, ymm0, ymm1 // mutates. - vpermq ymm0, ymm0, 0xd8 - vpand ymm1, ymm0, ymm5 // U - vpsrlw ymm0, ymm0, 8 // V - vpackuswb ymm1, ymm1, ymm1 // mutates. - vpackuswb ymm0, ymm0, ymm0 // mutates. - vpermq ymm1, ymm1, 0xd8 - vpermq ymm0, ymm0, 0xd8 - vextractf128 [edx], ymm1, 0 // U - vextractf128 [edx + edi], ymm0, 0 // V - lea edx, [edx + 16] - sub ecx, 32 - jg convertloop - - pop edi - pop esi - vzeroupper - ret - } -} - -__declspec(naked) void UYVYToUV422Row_AVX2(const uint8_t* src_uyvy, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push edi - mov eax, [esp + 4 + 4] // src_yuy2 - mov edx, [esp + 4 + 8] // dst_u - mov edi, [esp + 4 + 12] // dst_v - mov ecx, [esp + 4 + 16] // width - vpcmpeqb ymm5, ymm5, ymm5 // generate mask 0x00ff00ff - vpsrlw ymm5, ymm5, 8 - sub edi, edx - - convertloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - lea eax, [eax + 64] - vpand ymm0, ymm0, ymm5 // UYVY -> UVUV - vpand ymm1, ymm1, ymm5 - vpackuswb ymm0, ymm0, ymm1 // mutates. - vpermq ymm0, ymm0, 0xd8 - vpand ymm1, ymm0, ymm5 // U - vpsrlw ymm0, ymm0, 8 // V - vpackuswb ymm1, ymm1, ymm1 // mutates. - vpackuswb ymm0, ymm0, ymm0 // mutates. - vpermq ymm1, ymm1, 0xd8 - vpermq ymm0, ymm0, 0xd8 - vextractf128 [edx], ymm1, 0 // U - vextractf128 [edx + edi], ymm0, 0 // V - lea edx, [edx + 16] - sub ecx, 32 - jg convertloop - - pop edi - vzeroupper - ret - } -} -#endif // HAS_YUY2TOYROW_AVX2 - -#ifdef HAS_YUY2TOYROW_SSE2 -__declspec(naked) void YUY2ToYRow_SSE2(const uint8_t* src_yuy2, - uint8_t* dst_y, - int width) { - __asm { - mov eax, [esp + 4] // src_yuy2 - mov edx, [esp + 8] // dst_y - mov ecx, [esp + 12] // width - pcmpeqb xmm5, xmm5 // generate mask 0x00ff00ff - psrlw xmm5, 8 - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - lea eax, [eax + 32] - pand xmm0, xmm5 // even bytes are Y - pand xmm1, xmm5 - packuswb xmm0, xmm1 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg convertloop - ret - } -} - -__declspec(naked) void YUY2ToUVRow_SSE2(const uint8_t* src_yuy2, - int stride_yuy2, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_yuy2 - mov esi, [esp + 8 + 8] // stride_yuy2 - mov edx, [esp + 8 + 12] // dst_u - mov edi, [esp + 8 + 16] // dst_v - mov ecx, [esp + 8 + 20] // width - pcmpeqb xmm5, xmm5 // generate mask 0x00ff00ff - psrlw xmm5, 8 - sub edi, edx - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + esi] - movdqu xmm3, [eax + esi + 16] - lea eax, [eax + 32] - pavgb xmm0, xmm2 - pavgb xmm1, xmm3 - psrlw xmm0, 8 // YUYV -> UVUV - psrlw xmm1, 8 - packuswb xmm0, xmm1 - movdqa xmm1, xmm0 - pand xmm0, xmm5 // U - packuswb xmm0, xmm0 - psrlw xmm1, 8 // V - packuswb xmm1, xmm1 - movq qword ptr [edx], xmm0 - movq qword ptr [edx + edi], xmm1 - lea edx, [edx + 8] - sub ecx, 16 - jg convertloop - - pop edi - pop esi - ret - } -} - -__declspec(naked) void YUY2ToUV422Row_SSE2(const uint8_t* src_yuy2, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push edi - mov eax, [esp + 4 + 4] // src_yuy2 - mov edx, [esp + 4 + 8] // dst_u - mov edi, [esp + 4 + 12] // dst_v - mov ecx, [esp + 4 + 16] // width - pcmpeqb xmm5, xmm5 // generate mask 0x00ff00ff - psrlw xmm5, 8 - sub edi, edx - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - lea eax, [eax + 32] - psrlw xmm0, 8 // YUYV -> UVUV - psrlw xmm1, 8 - packuswb xmm0, xmm1 - movdqa xmm1, xmm0 - pand xmm0, xmm5 // U - packuswb xmm0, xmm0 - psrlw xmm1, 8 // V - packuswb xmm1, xmm1 - movq qword ptr [edx], xmm0 - movq qword ptr [edx + edi], xmm1 - lea edx, [edx + 8] - sub ecx, 16 - jg convertloop - - pop edi - ret - } -} - -__declspec(naked) void UYVYToYRow_SSE2(const uint8_t* src_uyvy, - uint8_t* dst_y, - int width) { - __asm { - mov eax, [esp + 4] // src_uyvy - mov edx, [esp + 8] // dst_y - mov ecx, [esp + 12] // width - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - lea eax, [eax + 32] - psrlw xmm0, 8 // odd bytes are Y - psrlw xmm1, 8 - packuswb xmm0, xmm1 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg convertloop - ret - } -} - -__declspec(naked) void UYVYToUVRow_SSE2(const uint8_t* src_uyvy, - int stride_uyvy, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_yuy2 - mov esi, [esp + 8 + 8] // stride_yuy2 - mov edx, [esp + 8 + 12] // dst_u - mov edi, [esp + 8 + 16] // dst_v - mov ecx, [esp + 8 + 20] // width - pcmpeqb xmm5, xmm5 // generate mask 0x00ff00ff - psrlw xmm5, 8 - sub edi, edx - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + esi] - movdqu xmm3, [eax + esi + 16] - lea eax, [eax + 32] - pavgb xmm0, xmm2 - pavgb xmm1, xmm3 - pand xmm0, xmm5 // UYVY -> UVUV - pand xmm1, xmm5 - packuswb xmm0, xmm1 - movdqa xmm1, xmm0 - pand xmm0, xmm5 // U - packuswb xmm0, xmm0 - psrlw xmm1, 8 // V - packuswb xmm1, xmm1 - movq qword ptr [edx], xmm0 - movq qword ptr [edx + edi], xmm1 - lea edx, [edx + 8] - sub ecx, 16 - jg convertloop - - pop edi - pop esi - ret - } -} - -__declspec(naked) void UYVYToUV422Row_SSE2(const uint8_t* src_uyvy, - uint8_t* dst_u, - uint8_t* dst_v, - int width) { - __asm { - push edi - mov eax, [esp + 4 + 4] // src_yuy2 - mov edx, [esp + 4 + 8] // dst_u - mov edi, [esp + 4 + 12] // dst_v - mov ecx, [esp + 4 + 16] // width - pcmpeqb xmm5, xmm5 // generate mask 0x00ff00ff - psrlw xmm5, 8 - sub edi, edx - - convertloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - lea eax, [eax + 32] - pand xmm0, xmm5 // UYVY -> UVUV - pand xmm1, xmm5 - packuswb xmm0, xmm1 - movdqa xmm1, xmm0 - pand xmm0, xmm5 // U - packuswb xmm0, xmm0 - psrlw xmm1, 8 // V - packuswb xmm1, xmm1 - movq qword ptr [edx], xmm0 - movq qword ptr [edx + edi], xmm1 - lea edx, [edx + 8] - sub ecx, 16 - jg convertloop - - pop edi - ret - } -} -#endif // HAS_YUY2TOYROW_SSE2 +#endif // HAS_ARGBBLENDROW_AVX2 #ifdef HAS_BLENDPLANEROW_SSSE3 -// Blend 8 pixels at a time. -// unsigned version of math -// =((A2*C2)+(B2*(255-C2))+255)/256 -// signed version of math -// =(((A2-128)*C2)+((B2-128)*(255-C2))+32768+127)/256 -__declspec(naked) void BlendPlaneRow_SSSE3(const uint8_t* src0, - const uint8_t* src1, - const uint8_t* alpha, - uint8_t* dst, - int width) { - __asm { - push esi - push edi - pcmpeqb xmm5, xmm5 // generate mask 0xff00ff00 - psllw xmm5, 8 - mov eax, 0x80808080 // 128 for biasing image to signed. - movd xmm6, eax - pshufd xmm6, xmm6, 0x00 +void BlendPlaneRow_SSSE3(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width) { + __m128i xmm_ff00 = _mm_set1_epi16((short)0xff00); + __m128i xmm_80 = _mm_set1_epi8((char)0x80); + __m128i xmm_round = _mm_set1_epi16((short)0x807f); - mov eax, 0x807f807f // 32768 + 127 for unbias and round. - movd xmm7, eax - pshufd xmm7, xmm7, 0x00 - mov eax, [esp + 8 + 4] // src0 - mov edx, [esp + 8 + 8] // src1 - mov esi, [esp + 8 + 12] // alpha - mov edi, [esp + 8 + 16] // dst - mov ecx, [esp + 8 + 20] // width - sub eax, esi - sub edx, esi - sub edi, esi + while (width > 0) { + __m128i xmm_a = _mm_loadl_epi64((const __m128i*)alpha); + __m128i xmm_s0 = _mm_loadl_epi64((const __m128i*)src0); + __m128i xmm_s1 = _mm_loadl_epi64((const __m128i*)src1); + alpha += 8; + src0 += 8; + src1 += 8; - // 8 pixel loop. - convertloop8: - movq xmm0, qword ptr [esi] // alpha - punpcklbw xmm0, xmm0 - pxor xmm0, xmm5 // a, 255-a - movq xmm1, qword ptr [eax + esi] // src0 - movq xmm2, qword ptr [edx + esi] // src1 - punpcklbw xmm1, xmm2 - psubb xmm1, xmm6 // bias src0/1 - 128 - pmaddubsw xmm0, xmm1 - paddw xmm0, xmm7 // unbias result - 32768 and round. - psrlw xmm0, 8 - packuswb xmm0, xmm0 - movq qword ptr [edi + esi], xmm0 - lea esi, [esi + 8] - sub ecx, 8 - jg convertloop8 + xmm_a = _mm_unpacklo_epi8(xmm_a, xmm_a); + xmm_a = _mm_xor_si128(xmm_a, xmm_ff00); - pop edi - pop esi - ret + __m128i xmm_s = _mm_unpacklo_epi8(xmm_s0, xmm_s1); + xmm_s = _mm_sub_epi8(xmm_s, xmm_80); + + __m128i xmm_p = _mm_maddubs_epi16(xmm_a, xmm_s); + xmm_p = _mm_add_epi16(xmm_p, xmm_round); + xmm_p = _mm_srli_epi16(xmm_p, 8); + + __m128i xmm_d = _mm_packus_epi16(xmm_p, xmm_p); + _mm_storel_epi64((__m128i*)dst, xmm_d); + dst += 8; + width -= 8; } } #endif // HAS_BLENDPLANEROW_SSSE3 #ifdef HAS_BLENDPLANEROW_AVX2 -// Blend 32 pixels at a time. -// unsigned version of math -// =((A2*C2)+(B2*(255-C2))+255)/256 -// signed version of math -// =(((A2-128)*C2)+((B2-128)*(255-C2))+32768+127)/256 -__declspec(naked) void BlendPlaneRow_AVX2(const uint8_t* src0, - const uint8_t* src1, - const uint8_t* alpha, - uint8_t* dst, - int width) { - __asm { - push esi - push edi - vpcmpeqb ymm5, ymm5, ymm5 // generate mask 0xff00ff00 - vpsllw ymm5, ymm5, 8 - mov eax, 0x80808080 // 128 for biasing image to signed. - vmovd xmm6, eax - vbroadcastss ymm6, xmm6 - mov eax, 0x807f807f // 32768 + 127 for unbias and round. - vmovd xmm7, eax - vbroadcastss ymm7, xmm7 - mov eax, [esp + 8 + 4] // src0 - mov edx, [esp + 8 + 8] // src1 - mov esi, [esp + 8 + 12] // alpha - mov edi, [esp + 8 + 16] // dst - mov ecx, [esp + 8 + 20] // width - sub eax, esi - sub edx, esi - sub edi, esi +LIBYUV_TARGET_AVX2 +void BlendPlaneRow_AVX2(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width) { + __m256i ymm_ff00 = _mm256_set1_epi16((short)0xff00); + __m256i ymm_80 = _mm256_set1_epi8((char)0x80); + __m256i ymm_round = _mm256_set1_epi16((short)0x807f); - // 32 pixel loop. - convertloop32: - vmovdqu ymm0, [esi] // alpha - vpunpckhbw ymm3, ymm0, ymm0 // 8..15, 24..31 - vpunpcklbw ymm0, ymm0, ymm0 // 0..7, 16..23 - vpxor ymm3, ymm3, ymm5 // a, 255-a - vpxor ymm0, ymm0, ymm5 // a, 255-a - vmovdqu ymm1, [eax + esi] // src0 - vmovdqu ymm2, [edx + esi] // src1 - vpunpckhbw ymm4, ymm1, ymm2 - vpunpcklbw ymm1, ymm1, ymm2 - vpsubb ymm4, ymm4, ymm6 // bias src0/1 - 128 - vpsubb ymm1, ymm1, ymm6 // bias src0/1 - 128 - vpmaddubsw ymm3, ymm3, ymm4 - vpmaddubsw ymm0, ymm0, ymm1 - vpaddw ymm3, ymm3, ymm7 // unbias result - 32768 and round. - vpaddw ymm0, ymm0, ymm7 // unbias result - 32768 and round. - vpsrlw ymm3, ymm3, 8 - vpsrlw ymm0, ymm0, 8 - vpackuswb ymm0, ymm0, ymm3 - vmovdqu [edi + esi], ymm0 - lea esi, [esi + 32] - sub ecx, 32 - jg convertloop32 + while (width > 0) { + __m256i ymm_a = _mm256_loadu_si256((const __m256i*)alpha); + __m256i ymm_s0 = _mm256_loadu_si256((const __m256i*)src0); + __m256i ymm_s1 = _mm256_loadu_si256((const __m256i*)src1); + alpha += 32; + src0 += 32; + src1 += 32; - pop edi - pop esi - vzeroupper - ret + __m256i ymm_a_lo = _mm256_unpacklo_epi8(ymm_a, ymm_a); + __m256i ymm_a_hi = _mm256_unpackhi_epi8(ymm_a, ymm_a); + ymm_a_lo = _mm256_xor_si256(ymm_a_lo, ymm_ff00); + ymm_a_hi = _mm256_xor_si256(ymm_a_hi, ymm_ff00); + + __m256i ymm_s_lo = _mm256_unpacklo_epi8(ymm_s0, ymm_s1); + __m256i ymm_s_hi = _mm256_unpackhi_epi8(ymm_s0, ymm_s1); + ymm_s_lo = _mm256_sub_epi8(ymm_s_lo, ymm_80); + ymm_s_hi = _mm256_sub_epi8(ymm_s_hi, ymm_80); + + __m256i ymm_p_lo = _mm256_maddubs_epi16(ymm_a_lo, ymm_s_lo); + __m256i ymm_p_hi = _mm256_maddubs_epi16(ymm_a_hi, ymm_s_hi); + + ymm_p_lo = _mm256_add_epi16(ymm_p_lo, ymm_round); + ymm_p_hi = _mm256_add_epi16(ymm_p_hi, ymm_round); + + ymm_p_lo = _mm256_srli_epi16(ymm_p_lo, 8); + ymm_p_hi = _mm256_srli_epi16(ymm_p_hi, 8); + + __m256i ymm_d = _mm256_packus_epi16(ymm_p_lo, ymm_p_hi); + _mm256_storeu_si256((__m256i*)dst, ymm_d); + dst += 32; + width -= 32; } + _mm256_zeroupper(); } #endif // HAS_BLENDPLANEROW_AVX2 -#ifdef HAS_ARGBBLENDROW_SSSE3 -// Shuffle table for isolating alpha. -static const uvec8 kShuffleAlpha = {3u, 0x80, 3u, 0x80, 7u, 0x80, 7u, 0x80, - 11u, 0x80, 11u, 0x80, 15u, 0x80, 15u, 0x80}; +#ifdef HAS_BLENDPLANEROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void BlendPlaneRow_AVX512BW(const uint8_t* src0, + const uint8_t* src1, + const uint8_t* alpha, + uint8_t* dst, + int width) { + __m512i zmm_ff00 = _mm512_set1_epi16((short)0xff00); + __m512i zmm_80 = _mm512_set1_epi8((char)0x80); + __m512i zmm_round = _mm512_set1_epi16((short)0x807f); -// Blend 8 pixels at a time. -__declspec(naked) void ARGBBlendRow_SSSE3(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_argb0 - mov esi, [esp + 4 + 8] // src_argb1 - mov edx, [esp + 4 + 12] // dst_argb - mov ecx, [esp + 4 + 16] // width - pcmpeqb xmm7, xmm7 // generate constant 0x0001 - psrlw xmm7, 15 - pcmpeqb xmm6, xmm6 // generate mask 0x00ff00ff - psrlw xmm6, 8 - pcmpeqb xmm5, xmm5 // generate mask 0xff00ff00 - psllw xmm5, 8 - pcmpeqb xmm4, xmm4 // generate mask 0xff000000 - pslld xmm4, 24 - sub ecx, 4 - jl convertloop4b // less than 4 pixels? + while (width >= 64) { + __m512i zmm_a = _mm512_loadu_si512((const __m512i*)alpha); + __m512i zmm_s0 = _mm512_loadu_si512((const __m512i*)src0); + __m512i zmm_s1 = _mm512_loadu_si512((const __m512i*)src1); + alpha += 64; + src0 += 64; + src1 += 64; - // 4 pixel loop. - convertloop4: - movdqu xmm3, [eax] // src argb - lea eax, [eax + 16] - movdqa xmm0, xmm3 // src argb - pxor xmm3, xmm4 // ~alpha - movdqu xmm2, [esi] // _r_b - pshufb xmm3, xmmword ptr kShuffleAlpha // alpha - pand xmm2, xmm6 // _r_b - paddw xmm3, xmm7 // 256 - alpha - pmullw xmm2, xmm3 // _r_b * alpha - movdqu xmm1, [esi] // _a_g - lea esi, [esi + 16] - psrlw xmm1, 8 // _a_g - por xmm0, xmm4 // set alpha to 255 - pmullw xmm1, xmm3 // _a_g * alpha - psrlw xmm2, 8 // _r_b convert to 8 bits again - paddusb xmm0, xmm2 // + src argb - pand xmm1, xmm5 // a_g_ convert to 8 bits again - paddusb xmm0, xmm1 // + src argb - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jge convertloop4 + __m512i zmm_a_lo = _mm512_unpacklo_epi8(zmm_a, zmm_a); + __m512i zmm_a_hi = _mm512_unpackhi_epi8(zmm_a, zmm_a); + zmm_a_lo = _mm512_xor_si512(zmm_a_lo, zmm_ff00); + zmm_a_hi = _mm512_xor_si512(zmm_a_hi, zmm_ff00); - convertloop4b: - add ecx, 4 - 1 - jl convertloop1b + __m512i zmm_s_lo = _mm512_unpacklo_epi8(zmm_s0, zmm_s1); + __m512i zmm_s_hi = _mm512_unpackhi_epi8(zmm_s0, zmm_s1); + zmm_s_lo = _mm512_sub_epi8(zmm_s_lo, zmm_80); + zmm_s_hi = _mm512_sub_epi8(zmm_s_hi, zmm_80); - // 1 pixel loop. - convertloop1: - movd xmm3, [eax] // src argb - lea eax, [eax + 4] - movdqa xmm0, xmm3 // src argb - pxor xmm3, xmm4 // ~alpha - movd xmm2, [esi] // _r_b - pshufb xmm3, xmmword ptr kShuffleAlpha // alpha - pand xmm2, xmm6 // _r_b - paddw xmm3, xmm7 // 256 - alpha - pmullw xmm2, xmm3 // _r_b * alpha - movd xmm1, [esi] // _a_g - lea esi, [esi + 4] - psrlw xmm1, 8 // _a_g - por xmm0, xmm4 // set alpha to 255 - pmullw xmm1, xmm3 // _a_g * alpha - psrlw xmm2, 8 // _r_b convert to 8 bits again - paddusb xmm0, xmm2 // + src argb - pand xmm1, xmm5 // a_g_ convert to 8 bits again - paddusb xmm0, xmm1 // + src argb - movd [edx], xmm0 - lea edx, [edx + 4] - sub ecx, 1 - jge convertloop1 + __m512i zmm_p_lo = _mm512_maddubs_epi16(zmm_a_lo, zmm_s_lo); + __m512i zmm_p_hi = _mm512_maddubs_epi16(zmm_a_hi, zmm_s_hi); - convertloop1b: - pop esi - ret + zmm_p_lo = _mm512_add_epi16(zmm_p_lo, zmm_round); + zmm_p_hi = _mm512_add_epi16(zmm_p_hi, zmm_round); + + zmm_p_lo = _mm512_srli_epi16(zmm_p_lo, 8); + zmm_p_hi = _mm512_srli_epi16(zmm_p_hi, 8); + + __m512i zmm_d = _mm512_packus_epi16(zmm_p_lo, zmm_p_hi); + _mm512_storeu_si512((__m512i*)dst, zmm_d); + dst += 64; + width -= 64; } -} -#endif // HAS_ARGBBLENDROW_SSSE3 + if (width > 0) { + __mmask64 mask = (1ULL << width) - 1ULL; + __m512i zmm_a = _mm512_maskz_loadu_epi8(mask, alpha); + __m512i zmm_s0 = _mm512_maskz_loadu_epi8(mask, src0); + __m512i zmm_s1 = _mm512_maskz_loadu_epi8(mask, src1); -#ifdef HAS_ARGBATTENUATEROW_SSSE3 -// Shuffle table duplicating alpha. -static const uvec8 kShuffleAlpha0 = { - 3u, 3u, 3u, 3u, 3u, 3u, 128u, 128u, 7u, 7u, 7u, 7u, 7u, 7u, 128u, 128u, -}; -static const uvec8 kShuffleAlpha1 = { - 11u, 11u, 11u, 11u, 11u, 11u, 128u, 128u, - 15u, 15u, 15u, 15u, 15u, 15u, 128u, 128u, -}; -__declspec(naked) void ARGBAttenuateRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, [esp + 4] // src_argb0 - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - pcmpeqb xmm3, xmm3 // generate mask 0xff000000 - pslld xmm3, 24 - movdqa xmm4, xmmword ptr kShuffleAlpha0 - movdqa xmm5, xmmword ptr kShuffleAlpha1 + __m512i zmm_a_lo = _mm512_unpacklo_epi8(zmm_a, zmm_a); + __m512i zmm_a_hi = _mm512_unpackhi_epi8(zmm_a, zmm_a); + zmm_a_lo = _mm512_xor_si512(zmm_a_lo, zmm_ff00); + zmm_a_hi = _mm512_xor_si512(zmm_a_hi, zmm_ff00); - convertloop: - movdqu xmm0, [eax] // read 4 pixels - pshufb xmm0, xmm4 // isolate first 2 alphas - movdqu xmm1, [eax] // read 4 pixels - punpcklbw xmm1, xmm1 // first 2 pixel rgbs - pmulhuw xmm0, xmm1 // rgb * a - movdqu xmm1, [eax] // read 4 pixels - pshufb xmm1, xmm5 // isolate next 2 alphas - movdqu xmm2, [eax] // read 4 pixels - punpckhbw xmm2, xmm2 // next 2 pixel rgbs - pmulhuw xmm1, xmm2 // rgb * a - movdqu xmm2, [eax] // mask original alpha - lea eax, [eax + 16] - pand xmm2, xmm3 - psrlw xmm0, 8 - psrlw xmm1, 8 - packuswb xmm0, xmm1 - por xmm0, xmm2 // copy original alpha - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jg convertloop + __m512i zmm_s_lo = _mm512_unpacklo_epi8(zmm_s0, zmm_s1); + __m512i zmm_s_hi = _mm512_unpackhi_epi8(zmm_s0, zmm_s1); + zmm_s_lo = _mm512_sub_epi8(zmm_s_lo, zmm_80); + zmm_s_hi = _mm512_sub_epi8(zmm_s_hi, zmm_80); - ret + __m512i zmm_p_lo = _mm512_maddubs_epi16(zmm_a_lo, zmm_s_lo); + __m512i zmm_p_hi = _mm512_maddubs_epi16(zmm_a_hi, zmm_s_hi); + + zmm_p_lo = _mm512_add_epi16(zmm_p_lo, zmm_round); + zmm_p_hi = _mm512_add_epi16(zmm_p_hi, zmm_round); + + zmm_p_lo = _mm512_srli_epi16(zmm_p_lo, 8); + zmm_p_hi = _mm512_srli_epi16(zmm_p_hi, 8); + + __m512i zmm_d = _mm512_packus_epi16(zmm_p_lo, zmm_p_hi); + _mm512_mask_storeu_epi8(dst, mask, zmm_d); } + _mm256_zeroupper(); } -#endif // HAS_ARGBATTENUATEROW_SSSE3 +#endif // HAS_BLENDPLANEROW_AVX512BW -#ifdef HAS_ARGBATTENUATEROW_AVX2 -// Shuffle table duplicating alpha. -static const uvec8 kShuffleAlpha_AVX2 = {6u, 7u, 6u, 7u, 6u, 7u, - 128u, 128u, 14u, 15u, 14u, 15u, - 14u, 15u, 128u, 128u}; -__declspec(naked) void ARGBAttenuateRow_AVX2(const uint8_t* src_argb, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, [esp + 4] // src_argb0 - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - sub edx, eax - vbroadcastf128 ymm4, xmmword ptr kShuffleAlpha_AVX2 - vpcmpeqb ymm5, ymm5, ymm5 // generate mask 0xff000000 - vpslld ymm5, ymm5, 24 - - convertloop: - vmovdqu ymm6, [eax] // read 8 pixels. - vpunpcklbw ymm0, ymm6, ymm6 // low 4 pixels. mutated. - vpunpckhbw ymm1, ymm6, ymm6 // high 4 pixels. mutated. - vpshufb ymm2, ymm0, ymm4 // low 4 alphas - vpshufb ymm3, ymm1, ymm4 // high 4 alphas - vpmulhuw ymm0, ymm0, ymm2 // rgb * a - vpmulhuw ymm1, ymm1, ymm3 // rgb * a - vpand ymm6, ymm6, ymm5 // isolate alpha - vpsrlw ymm0, ymm0, 8 - vpsrlw ymm1, ymm1, 8 - vpackuswb ymm0, ymm0, ymm1 // unmutated. - vpor ymm0, ymm0, ymm6 // copy original alpha - vmovdqu [eax + edx], ymm0 - lea eax, [eax + 32] - sub ecx, 8 - jg convertloop - - vzeroupper - ret +#ifdef HAS_ARGBEXTRACTALPHAROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBExtractAlphaRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_a, + int width) { + while (width >= 32) { + __m512i z0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i z1 = _mm512_loadu_si512((const __m512i*)(src_argb + 64)); + __m128i a0 = _mm512_cvtepi32_epi8(_mm512_srli_epi32(z0, 24)); + __m128i a1 = _mm512_cvtepi32_epi8(_mm512_srli_epi32(z1, 24)); + _mm_storeu_si128((__m128i*)dst_a, a0); + _mm_storeu_si128((__m128i*)(dst_a + 16), a1); + src_argb += 128; + dst_a += 32; + width -= 32; } -} -#endif // HAS_ARGBATTENUATEROW_AVX2 - -#ifdef HAS_ARGBUNATTENUATEROW_SSE2 -// Unattenuate 4 pixels at a time. -__declspec(naked) void ARGBUnattenuateRow_SSE2(const uint8_t* src_argb, - uint8_t* dst_argb, - int width) { - __asm { - push ebx - push esi - push edi - mov eax, [esp + 12 + 4] // src_argb - mov edx, [esp + 12 + 8] // dst_argb - mov ecx, [esp + 12 + 12] // width - lea ebx, fixed_invtbl8 - - convertloop: - movdqu xmm0, [eax] // read 4 pixels - movzx esi, byte ptr [eax + 3] // first alpha - movzx edi, byte ptr [eax + 7] // second alpha - punpcklbw xmm0, xmm0 // first 2 - movd xmm2, dword ptr [ebx + esi * 4] - movd xmm3, dword ptr [ebx + edi * 4] - pshuflw xmm2, xmm2, 040h // first 4 inv_alpha words. 1, a, a, a - pshuflw xmm3, xmm3, 040h // next 4 inv_alpha words - movlhps xmm2, xmm3 - pmulhuw xmm0, xmm2 // rgb * a - - movdqu xmm1, [eax] // read 4 pixels - movzx esi, byte ptr [eax + 11] // third alpha - movzx edi, byte ptr [eax + 15] // forth alpha - punpckhbw xmm1, xmm1 // next 2 - movd xmm2, dword ptr [ebx + esi * 4] - movd xmm3, dword ptr [ebx + edi * 4] - pshuflw xmm2, xmm2, 040h // first 4 inv_alpha words - pshuflw xmm3, xmm3, 040h // next 4 inv_alpha words - movlhps xmm2, xmm3 - pmulhuw xmm1, xmm2 // rgb * a - lea eax, [eax + 16] - packuswb xmm0, xmm1 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jg convertloop - - pop edi - pop esi - pop ebx - ret + if (width >= 16) { + __m512i z0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m128i a0 = _mm512_cvtepi32_epi8(_mm512_srli_epi32(z0, 24)); + _mm_storeu_si128((__m128i*)dst_a, a0); + src_argb += 64; + dst_a += 16; + width -= 16; } -} -#endif // HAS_ARGBUNATTENUATEROW_SSE2 - -#ifdef HAS_ARGBUNATTENUATEROW_AVX2 -// Shuffle table duplicating alpha. -static const uvec8 kUnattenShuffleAlpha_AVX2 = { - 0u, 1u, 0u, 1u, 0u, 1u, 6u, 7u, 8u, 9u, 8u, 9u, 8u, 9u, 14u, 15u}; -// TODO(fbarchard): Enable USE_GATHER for future hardware if faster. -// USE_GATHER is not on by default, due to being a slow instruction. -#ifdef USE_GATHER -__declspec(naked) void ARGBUnattenuateRow_AVX2(const uint8_t* src_argb, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, [esp + 4] // src_argb0 - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - sub edx, eax - vbroadcastf128 ymm4, xmmword ptr kUnattenShuffleAlpha_AVX2 - - convertloop: - vmovdqu ymm6, [eax] // read 8 pixels. - vpcmpeqb ymm5, ymm5, ymm5 // generate mask 0xffffffff for gather. - vpsrld ymm2, ymm6, 24 // alpha in low 8 bits. - vpunpcklbw ymm0, ymm6, ymm6 // low 4 pixels. mutated. - vpunpckhbw ymm1, ymm6, ymm6 // high 4 pixels. mutated. - vpgatherdd ymm3, [ymm2 * 4 + fixed_invtbl8], ymm5 // ymm5 cleared. 1, a - vpunpcklwd ymm2, ymm3, ymm3 // low 4 inverted alphas. mutated. 1, 1, a, a - vpunpckhwd ymm3, ymm3, ymm3 // high 4 inverted alphas. mutated. - vpshufb ymm2, ymm2, ymm4 // replicate low 4 alphas. 1, a, a, a - vpshufb ymm3, ymm3, ymm4 // replicate high 4 alphas - vpmulhuw ymm0, ymm0, ymm2 // rgb * ia - vpmulhuw ymm1, ymm1, ymm3 // rgb * ia - vpackuswb ymm0, ymm0, ymm1 // unmutated. - vmovdqu [eax + edx], ymm0 - lea eax, [eax + 32] - sub ecx, 8 - jg convertloop - - vzeroupper - ret + if (width > 0) { + __mmask16 mask = (__mmask16)((1u << width) - 1u); + __m512i z0 = _mm512_maskz_loadu_epi32(mask, src_argb); + __m128i a0 = _mm512_cvtepi32_epi8(_mm512_srli_epi32(z0, 24)); + // Use _mm_mask_storeu_epi8 instead of _mm512_mask_cvtepi32_storeu_epi8 + // because LLVM MSan does not instrument @llvm.x86.avx512.mask.pmov.db.mem + // to unpoison destination shadow memory. + _mm_mask_storeu_epi8(dst_a, mask, a0); } + _mm256_zeroupper(); } -#else // USE_GATHER -__declspec(naked) void ARGBUnattenuateRow_AVX2(const uint8_t* src_argb, - uint8_t* dst_argb, - int width) { - __asm { +#endif // HAS_ARGBEXTRACTALPHAROW_AVX512BW - push ebx - push esi - push edi - mov eax, [esp + 12 + 4] // src_argb - mov edx, [esp + 12 + 8] // dst_argb - mov ecx, [esp + 12 + 12] // width - sub edx, eax - lea ebx, fixed_invtbl8 - vbroadcastf128 ymm5, xmmword ptr kUnattenShuffleAlpha_AVX2 - - convertloop: - // replace VPGATHER - movzx esi, byte ptr [eax + 3] // alpha0 - movzx edi, byte ptr [eax + 7] // alpha1 - vmovd xmm0, dword ptr [ebx + esi * 4] // [1,a0] - vmovd xmm1, dword ptr [ebx + edi * 4] // [1,a1] - movzx esi, byte ptr [eax + 11] // alpha2 - movzx edi, byte ptr [eax + 15] // alpha3 - vpunpckldq xmm6, xmm0, xmm1 // [1,a1,1,a0] - vmovd xmm2, dword ptr [ebx + esi * 4] // [1,a2] - vmovd xmm3, dword ptr [ebx + edi * 4] // [1,a3] - movzx esi, byte ptr [eax + 19] // alpha4 - movzx edi, byte ptr [eax + 23] // alpha5 - vpunpckldq xmm7, xmm2, xmm3 // [1,a3,1,a2] - vmovd xmm0, dword ptr [ebx + esi * 4] // [1,a4] - vmovd xmm1, dword ptr [ebx + edi * 4] // [1,a5] - movzx esi, byte ptr [eax + 27] // alpha6 - movzx edi, byte ptr [eax + 31] // alpha7 - vpunpckldq xmm0, xmm0, xmm1 // [1,a5,1,a4] - vmovd xmm2, dword ptr [ebx + esi * 4] // [1,a6] - vmovd xmm3, dword ptr [ebx + edi * 4] // [1,a7] - vpunpckldq xmm2, xmm2, xmm3 // [1,a7,1,a6] - vpunpcklqdq xmm3, xmm6, xmm7 // [1,a3,1,a2,1,a1,1,a0] - vpunpcklqdq xmm0, xmm0, xmm2 // [1,a7,1,a6,1,a5,1,a4] - vinserti128 ymm3, ymm3, xmm0, 1 // [1,a7,1,a6,1,a5,1,a4,1,a3,1,a2,1,a1,1,a0] - // end of VPGATHER - - vmovdqu ymm6, [eax] // read 8 pixels. - vpunpcklbw ymm0, ymm6, ymm6 // low 4 pixels. mutated. - vpunpckhbw ymm1, ymm6, ymm6 // high 4 pixels. mutated. - vpunpcklwd ymm2, ymm3, ymm3 // low 4 inverted alphas. mutated. 1, 1, a, a - vpunpckhwd ymm3, ymm3, ymm3 // high 4 inverted alphas. mutated. - vpshufb ymm2, ymm2, ymm5 // replicate low 4 alphas. 1, a, a, a - vpshufb ymm3, ymm3, ymm5 // replicate high 4 alphas - vpmulhuw ymm0, ymm0, ymm2 // rgb * ia - vpmulhuw ymm1, ymm1, ymm3 // rgb * ia - vpackuswb ymm0, ymm0, ymm1 // unmutated. - vmovdqu [eax + edx], ymm0 - lea eax, [eax + 32] - sub ecx, 8 - jg convertloop - - pop edi - pop esi - pop ebx - vzeroupper - ret +#ifdef HAS_ARGBCOPYYTOALPHAROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBCopyYToAlphaRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + // Store only the alpha byte (every 4th byte) using a byte mask instead of + // loading dst and blending with _mm512_ternarylogic_epi32. This avoids + // reading uninitialized destination bytes and avoids + // @llvm.x86.avx512.pternlog which LLVM MSan does not model bitwise. + const __mmask64 alpha_mask = 0x8888888888888888ull; + while (width >= 32) { + __m512i a0 = _mm512_slli_epi32( + _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*)src)), 24); + __m512i a1 = _mm512_slli_epi32( + _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*)(src + 16))), 24); + _mm512_mask_storeu_epi8(dst, alpha_mask, a0); + _mm512_mask_storeu_epi8(dst + 64, alpha_mask, a1); + src += 32; + dst += 128; + width -= 32; } -} -#endif // USE_GATHER -#endif // HAS_ARGBATTENUATEROW_AVX2 - -#ifdef HAS_ARGBGRAYROW_SSSE3 -// Convert 8 ARGB pixels (64 bytes) to 8 Gray ARGB pixels. -__declspec(naked) void ARGBGrayRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_argb, - int width) { - __asm { - mov eax, [esp + 4] /* src_argb */ - mov edx, [esp + 8] /* dst_argb */ - mov ecx, [esp + 12] /* width */ - movdqa xmm4, xmmword ptr kARGBToYJ - movdqa xmm5, xmmword ptr kAddYJ64 - - convertloop: - movdqu xmm0, [eax] // G - movdqu xmm1, [eax + 16] - pmaddubsw xmm0, xmm4 - pmaddubsw xmm1, xmm4 - phaddw xmm0, xmm1 - paddw xmm0, xmm5 // Add .5 for rounding. - psrlw xmm0, 7 - packuswb xmm0, xmm0 // 8 G bytes - movdqu xmm2, [eax] // A - movdqu xmm3, [eax + 16] - lea eax, [eax + 32] - psrld xmm2, 24 - psrld xmm3, 24 - packuswb xmm2, xmm3 - packuswb xmm2, xmm2 // 8 A bytes - movdqa xmm3, xmm0 // Weave into GG, GA, then GGGA - punpcklbw xmm0, xmm0 // 8 GG words - punpcklbw xmm3, xmm2 // 8 GA words - movdqa xmm1, xmm0 - punpcklwd xmm0, xmm3 // GGGA first 4 - punpckhwd xmm1, xmm3 // GGGA next 4 - movdqu [edx], xmm0 - movdqu [edx + 16], xmm1 - lea edx, [edx + 32] - sub ecx, 8 - jg convertloop - ret + if (width >= 16) { + __m512i a0 = _mm512_slli_epi32( + _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*)src)), 24); + _mm512_mask_storeu_epi8(dst, alpha_mask, a0); + src += 16; + dst += 64; + width -= 16; } -} -#endif // HAS_ARGBGRAYROW_SSSE3 - -#ifdef HAS_ARGBSEPIAROW_SSSE3 -// b = (r * 35 + g * 68 + b * 17) >> 7 -// g = (r * 45 + g * 88 + b * 22) >> 7 -// r = (r * 50 + g * 98 + b * 24) >> 7 -// Constant for ARGB color to sepia tone. -static const vec8 kARGBToSepiaB = {17, 68, 35, 0, 17, 68, 35, 0, - 17, 68, 35, 0, 17, 68, 35, 0}; - -static const vec8 kARGBToSepiaG = {22, 88, 45, 0, 22, 88, 45, 0, - 22, 88, 45, 0, 22, 88, 45, 0}; - -static const vec8 kARGBToSepiaR = {24, 98, 50, 0, 24, 98, 50, 0, - 24, 98, 50, 0, 24, 98, 50, 0}; - -// Convert 8 ARGB pixels (32 bytes) to 8 Sepia ARGB pixels. -__declspec(naked) void ARGBSepiaRow_SSSE3(uint8_t* dst_argb, int width) { - __asm { - mov eax, [esp + 4] /* dst_argb */ - mov ecx, [esp + 8] /* width */ - movdqa xmm2, xmmword ptr kARGBToSepiaB - movdqa xmm3, xmmword ptr kARGBToSepiaG - movdqa xmm4, xmmword ptr kARGBToSepiaR - - convertloop: - movdqu xmm0, [eax] // B - movdqu xmm6, [eax + 16] - pmaddubsw xmm0, xmm2 - pmaddubsw xmm6, xmm2 - phaddw xmm0, xmm6 - psrlw xmm0, 7 - packuswb xmm0, xmm0 // 8 B values - movdqu xmm5, [eax] // G - movdqu xmm1, [eax + 16] - pmaddubsw xmm5, xmm3 - pmaddubsw xmm1, xmm3 - phaddw xmm5, xmm1 - psrlw xmm5, 7 - packuswb xmm5, xmm5 // 8 G values - punpcklbw xmm0, xmm5 // 8 BG values - movdqu xmm5, [eax] // R - movdqu xmm1, [eax + 16] - pmaddubsw xmm5, xmm4 - pmaddubsw xmm1, xmm4 - phaddw xmm5, xmm1 - psrlw xmm5, 7 - packuswb xmm5, xmm5 // 8 R values - movdqu xmm6, [eax] // A - movdqu xmm1, [eax + 16] - psrld xmm6, 24 - psrld xmm1, 24 - packuswb xmm6, xmm1 - packuswb xmm6, xmm6 // 8 A values - punpcklbw xmm5, xmm6 // 8 RA values - movdqa xmm1, xmm0 // Weave BG, RA together - punpcklwd xmm0, xmm5 // BGRA first 4 - punpckhwd xmm1, xmm5 // BGRA next 4 - movdqu [eax], xmm0 - movdqu [eax + 16], xmm1 - lea eax, [eax + 32] - sub ecx, 8 - jg convertloop - ret + if (width > 0) { + __mmask16 mask = (__mmask16)((1u << width) - 1u); + __mmask64 tail_alpha_mask = alpha_mask >> (64 - width * 4); + __m512i a0 = _mm512_slli_epi32( + _mm512_maskz_cvtepu8_epi32(mask, _mm_maskz_loadu_epi8(mask, src)), 24); + _mm512_mask_storeu_epi8(dst, tail_alpha_mask, a0); } + _mm256_zeroupper(); } -#endif // HAS_ARGBSEPIAROW_SSSE3 +#endif // HAS_ARGBCOPYYTOALPHAROW_AVX512BW -#ifdef HAS_ARGBCOLORMATRIXROW_SSSE3 -// Tranform 8 ARGB pixels (32 bytes) with color matrix. -// Same as Sepia except matrix is provided. -// TODO(fbarchard): packuswbs only use half of the reg. To make RGBA, combine R -// and B into a high and low, then G/A, unpackl/hbw and then unpckl/hwd. -__declspec(naked) void ARGBColorMatrixRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_argb, - const int8_t* matrix_argb, - int width) { - __asm { - mov eax, [esp + 4] /* src_argb */ - mov edx, [esp + 8] /* dst_argb */ - mov ecx, [esp + 12] /* matrix_argb */ - movdqu xmm5, [ecx] - pshufd xmm2, xmm5, 0x00 - pshufd xmm3, xmm5, 0x55 - pshufd xmm4, xmm5, 0xaa - pshufd xmm5, xmm5, 0xff - mov ecx, [esp + 16] /* width */ - - convertloop: - movdqu xmm0, [eax] // B - movdqu xmm7, [eax + 16] - pmaddubsw xmm0, xmm2 - pmaddubsw xmm7, xmm2 - movdqu xmm6, [eax] // G - movdqu xmm1, [eax + 16] - pmaddubsw xmm6, xmm3 - pmaddubsw xmm1, xmm3 - phaddsw xmm0, xmm7 // B - phaddsw xmm6, xmm1 // G - psraw xmm0, 6 // B - psraw xmm6, 6 // G - packuswb xmm0, xmm0 // 8 B values - packuswb xmm6, xmm6 // 8 G values - punpcklbw xmm0, xmm6 // 8 BG values - movdqu xmm1, [eax] // R - movdqu xmm7, [eax + 16] - pmaddubsw xmm1, xmm4 - pmaddubsw xmm7, xmm4 - phaddsw xmm1, xmm7 // R - movdqu xmm6, [eax] // A - movdqu xmm7, [eax + 16] - pmaddubsw xmm6, xmm5 - pmaddubsw xmm7, xmm5 - phaddsw xmm6, xmm7 // A - psraw xmm1, 6 // R - psraw xmm6, 6 // A - packuswb xmm1, xmm1 // 8 R values - packuswb xmm6, xmm6 // 8 A values - punpcklbw xmm1, xmm6 // 8 RA values - movdqa xmm6, xmm0 // Weave BG, RA together - punpcklwd xmm0, xmm1 // BGRA first 4 - punpckhwd xmm6, xmm1 // BGRA next 4 - movdqu [edx], xmm0 - movdqu [edx + 16], xmm6 - lea eax, [eax + 32] - lea edx, [edx + 32] - sub ecx, 8 - jg convertloop - ret +#ifdef HAS_ARGBMIRRORROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBMirrorRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + const __m512i rev = + _mm512_set_epi32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + const uint8_t* s = src + (ptrdiff_t)width * 4; + while (width >= 16) { + s -= 64; + _mm512_storeu_si512( + (__m512i*)dst, + PermutexvarEpi32(rev, _mm512_loadu_si512((const __m512i*)s))); + dst += 64; + width -= 16; } + if (width > 0) { + // Remaining 1 to 15 pixels are at the start of src. + __mmask16 mask = (__mmask16)((1u << width) - 1u); + __m512i idx = _mm512_sub_epi32(rev, _mm512_set1_epi32(16 - width)); + __m512i v = _mm512_maskz_loadu_epi32(mask, src); + _mm512_mask_storeu_epi32(dst, mask, PermutexvarEpi32(idx, v)); + } + _mm256_zeroupper(); } -#endif // HAS_ARGBCOLORMATRIXROW_SSSE3 +#endif // HAS_ARGBMIRRORROW_AVX512BW -#ifdef HAS_ARGBQUANTIZEROW_SSE2 -// Quantize 4 ARGB pixels (16 bytes). -__declspec(naked) void ARGBQuantizeRow_SSE2(uint8_t* dst_argb, - int scale, - int interval_size, - int interval_offset, +#ifdef HAS_RGB24MIRRORROW_AVX512VBMI +static const uint8_t kPermMirrorRGB24_0[64] = { + 125u, 126u, 127u, 122u, 123u, 124u, 119u, 120u, 121u, 116u, 117u, + 118u, 113u, 114u, 115u, 110u, 111u, 112u, 107u, 108u, 109u, 104u, + 105u, 106u, 101u, 102u, 103u, 98u, 99u, 100u, 95u, 96u, 97u, + 92u, 93u, 94u, 89u, 90u, 91u, 86u, 87u, 88u, 83u, 84u, + 85u, 80u, 81u, 82u, 77u, 78u, 79u, 74u, 75u, 76u, 71u, + 72u, 73u, 68u, 69u, 70u, 65u, 66u, 67u, 62u}; +static const uint8_t kPermMirrorRGB24_1[64] = { + 127u, 128u, 123u, 124u, 125u, 120u, 121u, 122u, 117u, 118u, 119u, + 114u, 115u, 116u, 111u, 112u, 113u, 108u, 109u, 110u, 105u, 106u, + 107u, 102u, 103u, 104u, 99u, 100u, 101u, 96u, 97u, 98u, 93u, + 94u, 95u, 90u, 91u, 92u, 87u, 88u, 89u, 84u, 85u, 86u, + 81u, 82u, 83u, 78u, 79u, 80u, 75u, 76u, 77u, 72u, 73u, + 74u, 69u, 70u, 71u, 66u, 67u, 68u, 63u, 64u}; +static const uint8_t kPermMirrorRGB24_2[64] = { + 65u, 60u, 61u, 62u, 57u, 58u, 59u, 54u, 55u, 56u, 51u, 52u, 53u, + 48u, 49u, 50u, 45u, 46u, 47u, 42u, 43u, 44u, 39u, 40u, 41u, 36u, + 37u, 38u, 33u, 34u, 35u, 30u, 31u, 32u, 27u, 28u, 29u, 24u, 25u, + 26u, 21u, 22u, 23u, 18u, 19u, 20u, 15u, 16u, 17u, 12u, 13u, 14u, + 9u, 10u, 11u, 6u, 7u, 8u, 3u, 4u, 5u, 0u, 1u, 2u}; + +// Byte mask with the low n bits set, clamped to [0, 64]. +static inline __mmask64 RGB24MirrorMask(int n) { + return n <= 0 ? 0ull : n >= 64 ? ~0ull : (1ull << n) - 1ull; +} + +// Mirror 64 RGB24 pixels (3 full zmm vectors) per loop. The remaining 1 to +// 63 pixels use masked loads and stores that access only valid bytes. +LIBYUV_TARGET_AVX512VBMI +void RGB24MirrorRow_AVX512VBMI(const uint8_t* src_rgb24, + uint8_t* dst_rgb24, + int width) { + const __m512i idx0 = _mm512_loadu_si512((const __m512i*)kPermMirrorRGB24_0); + const __m512i idx1 = _mm512_loadu_si512((const __m512i*)kPermMirrorRGB24_1); + const __m512i idx2 = _mm512_loadu_si512((const __m512i*)kPermMirrorRGB24_2); + int r = width & 63; + int w = width - r; + if (w > 0) { + const uint8_t* src = src_rgb24 + (ptrdiff_t)width * 3 - 192; + do { + __m512i a = _mm512_loadu_si512((const __m512i*)src); + __m512i b = _mm512_loadu_si512((const __m512i*)(src + 64)); + __m512i c = _mm512_loadu_si512((const __m512i*)(src + 128)); + __m512i d0 = _mm512_permutex2var_epi8(b, idx0, c); + __m512i d1 = _mm512_permutex2var_epi8(a, idx1, b); + __m512i d2 = _mm512_permutex2var_epi8(a, idx2, b); + d1 = _mm512_mask_broadcastb_epi8(d1, (__mmask64)2, + _mm512_castsi512_si128(c)); + _mm512_storeu_si512((__m512i*)dst_rgb24, d0); + _mm512_storeu_si512((__m512i*)(dst_rgb24 + 64), d1); + _mm512_storeu_si512((__m512i*)(dst_rgb24 + 128), d2); + src -= 192; + dst_rgb24 += 192; + w -= 64; + } while (w > 0); + } + if (r) { + int nb = r * 3; + int off = 192 - nb; + __mmask64 m0 = RGB24MirrorMask(nb); + __mmask64 m1 = RGB24MirrorMask(nb - 64); + __mmask64 m2 = RGB24MirrorMask(nb - 128); + __m512i a = _mm512_maskz_loadu_epi8(m0, src_rgb24); + __m512i b = _mm512_maskz_loadu_epi8(m1, src_rgb24 + 64); + __m512i c = _mm512_maskz_loadu_epi8(m2, src_rgb24 + 128); + __m512i t0 = _mm512_sub_epi8(idx0, _mm512_set1_epi8((char)(off - 64))); + __m512i t1 = _mm512_sub_epi8(idx1, _mm512_set1_epi8((char)off)); + __m512i t2 = _mm512_sub_epi8(idx2, _mm512_set1_epi8((char)off)); + __m512i d0 = MaskPermutexvarEpi8(_mm512_permutex2var_epi8(a, t0, b), + _mm512_movepi8_mask(t0), t0, c); + __m512i d1 = MaskPermutexvarEpi8(_mm512_permutex2var_epi8(a, t1, b), + _mm512_movepi8_mask(t1), t1, c); + __m512i d2 = MaskPermutexvarEpi8(_mm512_permutex2var_epi8(a, t2, b), + _mm512_movepi8_mask(t2), t2, c); + _mm512_mask_storeu_epi8(dst_rgb24, m0, d0); + _mm512_mask_storeu_epi8(dst_rgb24 + 64, m1, d1); + _mm512_mask_storeu_epi8(dst_rgb24 + 128, m2, d2); + } + _mm256_zeroupper(); +} +#endif // HAS_RGB24MIRRORROW_AVX512VBMI + +// =========================================================================== +// Module 1: AYUV to Planar Y / UV / VU (AVX2 / AVX512VBMI) +// =========================================================================== + +#ifdef HAS_AYUVTOYROW_AVX2 +LIBYUV_TARGET_AVX2 +void AYUVToYRow_AVX2(const uint8_t* src_ayuv, uint8_t* dst_y, int width) { + const __m256i ymm_mask = _mm256_set1_epi32(0x000000ff); + while (width >= 16) { + __m256i ymm0 = _mm256_and_si256( + _mm256_srli_epi32(_mm256_loadu_si256((const __m256i*)src_ayuv), 16), + ymm_mask); + __m256i ymm1 = _mm256_and_si256( + _mm256_srli_epi32(_mm256_loadu_si256((const __m256i*)(src_ayuv + 32)), + 16), + ymm_mask); + src_ayuv += 64; + ymm0 = _mm256_permute4x64_epi64(_mm256_packus_epi32(ymm0, ymm1), 0xd8); + __m128i out = _mm_packus_epi16(_mm256_castsi256_si128(ymm0), + _mm256_extracti128_si256(ymm0, 1)); + _mm_storeu_si128((__m128i*)dst_y, out); + dst_y += 16; + width -= 16; + } + _mm256_zeroupper(); +} +#endif // HAS_AYUVTOYROW_AVX2 + +#if defined(HAS_AYUVTOUVROW_AVX2) || defined(HAS_AYUVTOVUROW_AVX2) +static const uint8_t kShufAYUVToUV16_Win[16] = { + 1, 5, 0, 4, 9, 13, 8, 12, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}; + +static const uint8_t kShufAYUVToVU16_Win[16] = { + 0, 4, 1, 5, 8, 12, 9, 13, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}; + +LIBYUV_TARGET_AVX2 +static inline void AYUVToUVOrVURow_Win_AVX2(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + const uint8_t* shuf_table, int width) { - __asm { - mov eax, [esp + 4] /* dst_argb */ - movd xmm2, [esp + 8] /* scale */ - movd xmm3, [esp + 12] /* interval_size */ - movd xmm4, [esp + 16] /* interval_offset */ - mov ecx, [esp + 20] /* width */ - pshuflw xmm2, xmm2, 040h - pshufd xmm2, xmm2, 044h - pshuflw xmm3, xmm3, 040h - pshufd xmm3, xmm3, 044h - pshuflw xmm4, xmm4, 040h - pshufd xmm4, xmm4, 044h - pxor xmm5, xmm5 // constant 0 - pcmpeqb xmm6, xmm6 // generate mask 0xff000000 - pslld xmm6, 24 + const __m256i ymm_shuf = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)shuf_table)); + const __m256i ymm_0101 = _mm256_set1_epi16(0x0101); + const __m256i ymm_zero = _mm256_setzero_si256(); + while (width >= 16) { + __m256i s00 = _mm256_shuffle_epi8( + _mm256_loadu_si256((const __m256i*)src_ayuv), ymm_shuf); + __m256i s01 = _mm256_shuffle_epi8( + _mm256_loadu_si256((const __m256i*)(src_ayuv + 32)), ymm_shuf); + __m256i s10 = _mm256_shuffle_epi8( + _mm256_loadu_si256((const __m256i*)(src_ayuv + src_stride_ayuv)), + ymm_shuf); + __m256i s11 = _mm256_shuffle_epi8( + _mm256_loadu_si256((const __m256i*)(src_ayuv + src_stride_ayuv + 32)), + ymm_shuf); + src_ayuv += 64; + __m256i p0 = + _mm256_maddubs_epi16(_mm256_unpacklo_epi64(s00, s01), ymm_0101); + __m256i p1 = + _mm256_maddubs_epi16(_mm256_unpacklo_epi64(s10, s11), ymm_0101); + p0 = _mm256_avg_epu16(_mm256_srli_epi16(_mm256_add_epi16(p0, p1), 1), + ymm_zero); + p0 = _mm256_permute4x64_epi64(p0, 0xd8); + __m128i out = _mm_packus_epi16(_mm256_castsi256_si128(p0), + _mm256_extracti128_si256(p0, 1)); + _mm_storeu_si128((__m128i*)dst_uv, out); + dst_uv += 16; + width -= 16; + } + _mm256_zeroupper(); +} +#endif - convertloop: - movdqu xmm0, [eax] // read 4 pixels - punpcklbw xmm0, xmm5 // first 2 pixels - pmulhuw xmm0, xmm2 // pixel * scale >> 16 - movdqu xmm1, [eax] // read 4 pixels - punpckhbw xmm1, xmm5 // next 2 pixels - pmulhuw xmm1, xmm2 - pmullw xmm0, xmm3 // * interval_size - movdqu xmm7, [eax] // read 4 pixels - pmullw xmm1, xmm3 - pand xmm7, xmm6 // mask alpha - paddw xmm0, xmm4 // + interval_size / 2 - paddw xmm1, xmm4 - packuswb xmm0, xmm1 - por xmm0, xmm7 - movdqu [eax], xmm0 - lea eax, [eax + 16] - sub ecx, 4 - jg convertloop - ret +#ifdef HAS_AYUVTOUVROW_AVX2 +LIBYUV_TARGET_AVX2 +void AYUVToUVRow_AVX2(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + int width) { + AYUVToUVOrVURow_Win_AVX2(src_ayuv, src_stride_ayuv, dst_uv, + kShufAYUVToUV16_Win, width); +} +#endif // HAS_AYUVTOUVROW_AVX2 + +#ifdef HAS_AYUVTOVUROW_AVX2 +LIBYUV_TARGET_AVX2 +void AYUVToVURow_AVX2(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_vu, + int width) { + AYUVToUVOrVURow_Win_AVX2(src_ayuv, src_stride_ayuv, dst_vu, + kShufAYUVToVU16_Win, width); +} +#endif // HAS_AYUVTOVUROW_AVX2 + +#ifdef HAS_AYUVTOYROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void AYUVToYRow_AVX512VBMI(const uint8_t* src_ayuv, uint8_t* dst_y, int width) { + static const uint8_t kPermAYUVToY32[64] = { + 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, + 66, 70, 74, 78, 82, 86, 90, 94, 98, 102, 106, 110, 114, 118, 122, 126, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const __m512i zmm_perm = _mm512_loadu_si512((const __m512i*)kPermAYUVToY32); + while (width >= 32) { + __m512i zmm0 = _mm512_loadu_si512((const __m512i*)src_ayuv); + __m512i zmm1 = _mm512_loadu_si512((const __m512i*)(src_ayuv + 64)); + src_ayuv += 128; + __m512i out = _mm512_permutex2var_epi8(zmm0, zmm_perm, zmm1); + _mm256_storeu_si256((__m256i*)dst_y, _mm512_castsi512_si256(out)); + dst_y += 32; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k1 = (__mmask16)m32; + __mmask16 k2 = (__mmask16)(m32 >> 16); + __m512i zmm0 = _mm512_maskz_loadu_epi32(k1, src_ayuv); + __m512i zmm1 = _mm512_maskz_loadu_epi32(k2, src_ayuv + 64); + __m512i out = _mm512_permutex2var_epi8(zmm0, zmm_perm, zmm1); + _mm256_mask_storeu_epi8(dst_y, (__mmask32)m32, _mm512_castsi512_si256(out)); + } + _mm256_zeroupper(); +} +#endif // HAS_AYUVTOYROW_AVX512VBMI + +#if defined(HAS_AYUVTOUVROW_AVX512VBMI) || defined(HAS_AYUVTOVUROW_AVX512VBMI) +static const uint8_t kPermAYUVToUV_Win[64] = { + 1, 5, 0, 4, 9, 13, 8, 12, 17, 21, 16, 20, 25, + 29, 24, 28, 33, 37, 32, 36, 41, 45, 40, 44, 49, 53, + 48, 52, 57, 61, 56, 60, 65, 69, 64, 68, 73, 77, 72, + 76, 81, 85, 80, 84, 89, 93, 88, 92, 97, 101, 96, 100, + 105, 109, 104, 108, 113, 117, 112, 116, 121, 125, 120, 124}; + +static const uint8_t kPermAYUVToVU_Win[64] = { + 0, 4, 1, 5, 8, 12, 9, 13, 16, 20, 17, 21, 24, + 28, 25, 29, 32, 36, 33, 37, 40, 44, 41, 45, 48, 52, + 49, 53, 56, 60, 57, 61, 64, 68, 65, 69, 72, 76, 73, + 77, 80, 84, 81, 85, 88, 92, 89, 93, 96, 100, 97, 101, + 104, 108, 105, 109, 112, 116, 113, 117, 120, 124, 121, 125}; + +LIBYUV_TARGET_AVX512VBMI +static inline void AYUVToUVOrVURow_Win_AVX512VBMI(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + const uint8_t* perm_table, + int width) { + const __m512i zmm_perm = _mm512_loadu_si512((const __m512i*)perm_table); + const __m512i zmm_0101 = _mm512_set1_epi16(0x0101); + const __m512i zmm_zero = _mm512_setzero_si512(); + while (width >= 32) { + __m512i s00 = _mm512_loadu_si512((const __m512i*)src_ayuv); + __m512i s01 = _mm512_loadu_si512((const __m512i*)(src_ayuv + 64)); + __m512i s10 = + _mm512_loadu_si512((const __m512i*)(src_ayuv + src_stride_ayuv)); + __m512i s11 = + _mm512_loadu_si512((const __m512i*)(src_ayuv + src_stride_ayuv + 64)); + src_ayuv += 128; + __m512i p0 = _mm512_permutex2var_epi8(s00, zmm_perm, s01); + __m512i p1 = _mm512_permutex2var_epi8(s10, zmm_perm, s11); + p0 = _mm512_maddubs_epi16(p0, zmm_0101); + p1 = _mm512_maddubs_epi16(p1, zmm_0101); + p0 = _mm512_avg_epu16(_mm512_srli_epi16(_mm512_add_epi16(p0, p1), 1), + zmm_zero); + _mm256_storeu_si256((__m256i*)dst_uv, _mm512_cvtepi16_epi8(p0)); + dst_uv += 32; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k1 = (__mmask16)m32; + __mmask16 k2 = (__mmask16)(m32 >> 16); + __m512i s00 = _mm512_maskz_loadu_epi32(k1, src_ayuv); + __m512i s01 = _mm512_maskz_loadu_epi32(k2, src_ayuv + 64); + __m512i s10 = _mm512_maskz_loadu_epi32(k1, src_ayuv + src_stride_ayuv); + __m512i s11 = _mm512_maskz_loadu_epi32(k2, src_ayuv + src_stride_ayuv + 64); + __m512i p0 = _mm512_permutex2var_epi8(s00, zmm_perm, s01); + __m512i p1 = _mm512_permutex2var_epi8(s10, zmm_perm, s11); + __mmask16 k_odd = (__mmask16)((width & 1) << (width >> 1)); + p0 = _mm512_mask_or_epi32(p0, k_odd, p0, _mm512_slli_epi32(p0, 8)); + p1 = _mm512_mask_or_epi32(p1, k_odd, p1, _mm512_slli_epi32(p1, 8)); + p0 = _mm512_maddubs_epi16(p0, zmm_0101); + p1 = _mm512_maddubs_epi16(p1, zmm_0101); + p0 = _mm512_avg_epu16(_mm512_srli_epi16(_mm512_add_epi16(p0, p1), 1), + zmm_zero); + uint32_t out_bytes = (uint32_t)((width + 1) & ~1); + __mmask32 k_out = + out_bytes >= 32 ? ~0u : (__mmask32)((1u << out_bytes) - 1u); + _mm256_mask_storeu_epi8(dst_uv, k_out, _mm512_cvtepi16_epi8(p0)); + } + _mm256_zeroupper(); +} +#endif + +#ifdef HAS_AYUVTOUVROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void AYUVToUVRow_AVX512VBMI(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_uv, + int width) { + AYUVToUVOrVURow_Win_AVX512VBMI(src_ayuv, src_stride_ayuv, dst_uv, + kPermAYUVToUV_Win, width); +} +#endif // HAS_AYUVTOUVROW_AVX512VBMI + +#ifdef HAS_AYUVTOVUROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void AYUVToVURow_AVX512VBMI(const uint8_t* src_ayuv, + int src_stride_ayuv, + uint8_t* dst_vu, + int width) { + AYUVToUVOrVURow_Win_AVX512VBMI(src_ayuv, src_stride_ayuv, dst_vu, + kPermAYUVToVU_Win, width); +} +#endif // HAS_AYUVTOVUROW_AVX512VBMI + +// =========================================================================== +// Module 2: 10-bit / 30-bit AR30 & XR30 Pack / Unpack (AVX2 / AVX512BW) +// =========================================================================== + +#ifdef HAS_AR30TOARGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void AR30ToARGBRow_AVX2(const uint8_t* src_ar30, + uint8_t* dst_argb, + int width) { + const __m256i m0 = _mm256_set1_epi32((int)0xc0000000u); + const __m256i m1 = _mm256_set1_epi32(0x300000ff); + const __m256i m2 = _mm256_set1_epi32(0x0c00ff00); + const __m256i m3 = _mm256_set1_epi32(0x03ff0000); + while (width >= 8) { + __m256i v = _mm256_loadu_si256((const __m256i*)src_ar30); + src_ar30 += 32; + __m256i out = _mm256_or_si256( + _mm256_or_si256(_mm256_and_si256(v, m0), + _mm256_and_si256(_mm256_srli_epi32(v, 2), m1)), + _mm256_or_si256(_mm256_and_si256(_mm256_srli_epi32(v, 4), m2), + _mm256_and_si256(_mm256_srli_epi32(v, 6), m3))); + _mm256_storeu_si256((__m256i*)dst_argb, out); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); +} +#endif // HAS_AR30TOARGBROW_AVX2 + +#ifdef HAS_AR30TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void AR30ToARGBRow_AVX512BW(const uint8_t* src_ar30, + uint8_t* dst_argb, + int width) { + const __m512i m0 = _mm512_set1_epi32((int)0xc0000000u); + const __m512i m1 = _mm512_set1_epi32(0x300000ff); + const __m512i m2 = _mm512_set1_epi32(0x0c00ff00); + const __m512i m3 = _mm512_set1_epi32(0x03ff0000); + while (width >= 16) { + __m512i v = _mm512_loadu_si512((const __m512i*)src_ar30); + src_ar30 += 64; + __m512i out = _mm512_or_si512( + _mm512_or_si512(_mm512_and_si512(v, m0), + _mm512_and_si512(_mm512_srli_epi32(v, 2), m1)), + _mm512_or_si512(_mm512_and_si512(_mm512_srli_epi32(v, 4), m2), + _mm512_and_si512(_mm512_srli_epi32(v, 6), m3))); + _mm512_storeu_si512((__m512i*)dst_argb, out); + dst_argb += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i v = _mm512_maskz_loadu_epi32(k, src_ar30); + __m512i out = _mm512_or_si512( + _mm512_or_si512(_mm512_and_si512(v, m0), + _mm512_and_si512(_mm512_srli_epi32(v, 2), m1)), + _mm512_or_si512(_mm512_and_si512(_mm512_srli_epi32(v, 4), m2), + _mm512_and_si512(_mm512_srli_epi32(v, 6), m3))); + _mm512_mask_storeu_epi32(dst_argb, k, out); + } + _mm256_zeroupper(); +} +#endif // HAS_AR30TOARGBROW_AVX512BW + +#ifdef HAS_AR30TOABGRROW_AVX2 +LIBYUV_TARGET_AVX2 +void AR30ToABGRRow_AVX2(const uint8_t* src_ar30, + uint8_t* dst_abgr, + int width) { + static const uint8_t kShufSwapRB16[16] = {2, 1, 0, 3, 6, 5, 4, 7, + 10, 9, 8, 11, 14, 13, 12, 15}; + const __m256i m0 = _mm256_set1_epi32((int)0xc0000000u); + const __m256i m1 = _mm256_set1_epi32(0x300000ff); + const __m256i m2 = _mm256_set1_epi32(0x0c00ff00); + const __m256i m3 = _mm256_set1_epi32(0x03ff0000); + const __m256i shuf = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)kShufSwapRB16)); + while (width >= 8) { + __m256i v = _mm256_loadu_si256((const __m256i*)src_ar30); + src_ar30 += 32; + __m256i out = _mm256_or_si256( + _mm256_or_si256(_mm256_and_si256(v, m0), + _mm256_and_si256(_mm256_srli_epi32(v, 2), m1)), + _mm256_or_si256(_mm256_and_si256(_mm256_srli_epi32(v, 4), m2), + _mm256_and_si256(_mm256_srli_epi32(v, 6), m3))); + out = _mm256_shuffle_epi8(out, shuf); + _mm256_storeu_si256((__m256i*)dst_abgr, out); + dst_abgr += 32; + width -= 8; + } + _mm256_zeroupper(); +} +#endif // HAS_AR30TOABGRROW_AVX2 + +#ifdef HAS_AR30TOABGRROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void AR30ToABGRRow_AVX512BW(const uint8_t* src_ar30, + uint8_t* dst_abgr, + int width) { + static const uint8_t kShufSwapRB16[16] = {2, 1, 0, 3, 6, 5, 4, 7, + 10, 9, 8, 11, 14, 13, 12, 15}; + const __m512i m0 = _mm512_set1_epi32((int)0xc0000000u); + const __m512i m1 = _mm512_set1_epi32(0x300000ff); + const __m512i m2 = _mm512_set1_epi32(0x0c00ff00); + const __m512i m3 = _mm512_set1_epi32(0x03ff0000); + const __m512i shuf = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)kShufSwapRB16)); + while (width >= 16) { + __m512i v = _mm512_loadu_si512((const __m512i*)src_ar30); + src_ar30 += 64; + __m512i out = _mm512_or_si512( + _mm512_or_si512(_mm512_and_si512(v, m0), + _mm512_and_si512(_mm512_srli_epi32(v, 2), m1)), + _mm512_or_si512(_mm512_and_si512(_mm512_srli_epi32(v, 4), m2), + _mm512_and_si512(_mm512_srli_epi32(v, 6), m3))); + out = _mm512_shuffle_epi8(out, shuf); + _mm512_storeu_si512((__m512i*)dst_abgr, out); + dst_abgr += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i v = _mm512_maskz_loadu_epi32(k, src_ar30); + __m512i out = _mm512_or_si512( + _mm512_or_si512(_mm512_and_si512(v, m0), + _mm512_and_si512(_mm512_srli_epi32(v, 2), m1)), + _mm512_or_si512(_mm512_and_si512(_mm512_srli_epi32(v, 4), m2), + _mm512_and_si512(_mm512_srli_epi32(v, 6), m3))); + out = _mm512_shuffle_epi8(out, shuf); + _mm512_mask_storeu_epi32(dst_abgr, k, out); + } + _mm256_zeroupper(); +} +#endif // HAS_AR30TOABGRROW_AVX512BW + +#ifdef HAS_AR30TOAB30ROW_AVX2 +LIBYUV_TARGET_AVX2 +void AR30ToAB30Row_AVX2(const uint8_t* src_ar30, + uint8_t* dst_ab30, + int width) { + const __m256i m0 = _mm256_set1_epi32((int)0xc00ffc00u); + const __m256i m1 = _mm256_set1_epi32(0x3ff00000); + const __m256i m2 = _mm256_set1_epi32(0x000003ff); + while (width >= 8) { + __m256i v = _mm256_loadu_si256((const __m256i*)src_ar30); + src_ar30 += 32; + __m256i out = _mm256_or_si256( + _mm256_and_si256(v, m0), + _mm256_or_si256(_mm256_and_si256(_mm256_slli_epi32(v, 20), m1), + _mm256_and_si256(_mm256_srli_epi32(v, 20), m2))); + _mm256_storeu_si256((__m256i*)dst_ab30, out); + dst_ab30 += 32; + width -= 8; + } + _mm256_zeroupper(); +} +#endif // HAS_AR30TOAB30ROW_AVX2 + +#ifdef HAS_AR30TOAB30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void AR30ToAB30Row_AVX512BW(const uint8_t* src_ar30, + uint8_t* dst_ab30, + int width) { + const __m512i m0 = _mm512_set1_epi32((int)0xc00ffc00u); + const __m512i m1 = _mm512_set1_epi32(0x3ff00000); + const __m512i m2 = _mm512_set1_epi32(0x000003ff); + while (width >= 16) { + __m512i v = _mm512_loadu_si512((const __m512i*)src_ar30); + src_ar30 += 64; + __m512i out = _mm512_or_si512( + _mm512_and_si512(v, m0), + _mm512_or_si512(_mm512_and_si512(_mm512_slli_epi32(v, 20), m1), + _mm512_and_si512(_mm512_srli_epi32(v, 20), m2))); + _mm512_storeu_si512((__m512i*)dst_ab30, out); + dst_ab30 += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i v = _mm512_maskz_loadu_epi32(k, src_ar30); + __m512i out = _mm512_or_si512( + _mm512_and_si512(v, m0), + _mm512_or_si512(_mm512_and_si512(_mm512_slli_epi32(v, 20), m1), + _mm512_and_si512(_mm512_srli_epi32(v, 20), m2))); + _mm512_mask_storeu_epi32(dst_ab30, k, out); + } + _mm256_zeroupper(); +} +#endif // HAS_AR30TOAB30ROW_AVX512BW + +#ifdef HAS_MERGEXR30ROW_10_AVX512BW +LIBYUV_TARGET_AVX512BW +void MergeXR30Row_10_AVX512BW(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int depth, + int width) { + (void)depth; + const __m512i max10 = _mm512_set1_epi32(1023); + const __m512i alpha = _mm512_set1_epi32((int)0xc0000000u); + while (width >= 16) { + __m512i r = _mm512_min_epu32( + _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i*)src_r)), + max10); + __m512i g = _mm512_min_epu32( + _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i*)src_g)), + max10); + __m512i b = _mm512_min_epu32( + _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i*)src_b)), + max10); + src_r += 16; + src_g += 16; + src_b += 16; + __m512i out = _mm512_or_si512( + _mm512_or_si512(_mm512_slli_epi32(r, 20), _mm512_slli_epi32(g, 10)), + _mm512_or_si512(b, alpha)); + _mm512_storeu_si512((__m512i*)dst_ar30, out); + dst_ar30 += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i r = _mm512_min_epu32( + _mm512_cvtepu16_epi32(_mm256_maskz_loadu_epi16(k, src_r)), max10); + __m512i g = _mm512_min_epu32( + _mm512_cvtepu16_epi32(_mm256_maskz_loadu_epi16(k, src_g)), max10); + __m512i b = _mm512_min_epu32( + _mm512_cvtepu16_epi32(_mm256_maskz_loadu_epi16(k, src_b)), max10); + __m512i out = _mm512_or_si512( + _mm512_or_si512(_mm512_slli_epi32(r, 20), _mm512_slli_epi32(g, 10)), + _mm512_or_si512(b, alpha)); + _mm512_mask_storeu_epi32(dst_ar30, k, out); + } + _mm256_zeroupper(); +} +#endif // HAS_MERGEXR30ROW_10_AVX512BW + +#if defined(HAS_ARGBTOAR30ROW_AVX512BW) || defined(HAS_ABGRTOAR30ROW_AVX512BW) +static const uint8_t kShuffleRB30_Win[16] = {128u, 0u, 128u, 2u, 128u, 4u, + 128u, 6u, 128u, 8u, 128u, 10u, + 128u, 12u, 128u, 14u}; + +static const uint8_t kShuffleBR30_Win[16] = {128u, 2u, 128u, 0u, 128u, 6u, + 128u, 4u, 128u, 10u, 128u, 8u, + 128u, 14u, 128u, 12u}; + +LIBYUV_TARGET_AVX512BW +static inline void ARGBOrABGRToAR30Row_Win_AVX512BW(const uint8_t* src, + uint8_t* dst, + const uint8_t* shuf_rb, + int width) { + const __m512i zmm_shuf = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)shuf_rb)); + const __m512i zmm_mul_rb = _mm512_set1_epi32(1028 * 16 * 65536 + 1028); + const __m512i zmm_mask_rb = _mm512_set1_epi32(0x3ff003ff); + const __m512i zmm_mask_ag = _mm512_set1_epi32((int)0xc000ff00u); + const __m512i zmm_mul_ag = _mm512_set1_epi32(64 * 65536 + 1028); + while (width >= 16) { + __m512i v = _mm512_loadu_si512((const __m512i*)src); + src += 64; + __m512i rb = _mm512_and_si512( + _mm512_mulhi_epu16(_mm512_shuffle_epi8(v, zmm_shuf), zmm_mul_rb), + zmm_mask_rb); + __m512i ag = _mm512_slli_epi32( + _mm512_mulhi_epu16(_mm512_and_si512(v, zmm_mask_ag), zmm_mul_ag), 10); + _mm512_storeu_si512((__m512i*)dst, _mm512_or_si512(ag, rb)); + dst += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i v = _mm512_maskz_loadu_epi32(k, src); + __m512i rb = _mm512_and_si512( + _mm512_mulhi_epu16(_mm512_shuffle_epi8(v, zmm_shuf), zmm_mul_rb), + zmm_mask_rb); + __m512i ag = _mm512_slli_epi32( + _mm512_mulhi_epu16(_mm512_and_si512(v, zmm_mask_ag), zmm_mul_ag), 10); + _mm512_mask_storeu_epi32(dst, k, _mm512_or_si512(ag, rb)); + } + _mm256_zeroupper(); +} +#endif + +#ifdef HAS_ARGBTOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToAR30Row_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + ARGBOrABGRToAR30Row_Win_AVX512BW(src, dst, kShuffleRB30_Win, width); +} +#endif // HAS_ARGBTOAR30ROW_AVX512BW + +#ifdef HAS_ABGRTOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ABGRToAR30Row_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + ARGBOrABGRToAR30Row_Win_AVX512BW(src, dst, kShuffleBR30_Win, width); +} +#endif // HAS_ABGRTOAR30ROW_AVX512BW + +// =========================================================================== +// Module 3: Planar / Channel Pack & Mirror / Interpolate_16 (AVX512VBMI / BW) +// =========================================================================== + +#ifdef HAS_MERGERGBROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void MergeRGBRow_AVX512VBMI(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_rgb, + int width) { + static const uint8_t kPermMergeRGB64_0[64] = { + 0x00, 0x20, 0x40, 0x01, 0x21, 0x41, 0x02, 0x22, 0x42, 0x03, 0x23, + 0x43, 0x04, 0x24, 0x44, 0x05, 0x25, 0x45, 0x06, 0x26, 0x46, 0x07, + 0x27, 0x47, 0x08, 0x28, 0x48, 0x09, 0x29, 0x49, 0x0a, 0x2a, 0x4a, + 0x0b, 0x2b, 0x4b, 0x0c, 0x2c, 0x4c, 0x0d, 0x2d, 0x4d, 0x0e, 0x2e, + 0x4e, 0x0f, 0x2f, 0x4f, 0x10, 0x30, 0x50, 0x11, 0x31, 0x51, 0x12, + 0x32, 0x52, 0x13, 0x33, 0x53, 0x14, 0x34, 0x54, 0x15}; + static const uint8_t kPermMergeRGB64_1[64] = { + 0x35, 0x55, 0x16, 0x36, 0x56, 0x17, 0x37, 0x57, 0x18, 0x38, 0x58, + 0x19, 0x39, 0x59, 0x1a, 0x3a, 0x5a, 0x1b, 0x3b, 0x5b, 0x1c, 0x3c, + 0x5c, 0x1d, 0x3d, 0x5d, 0x1e, 0x3e, 0x5e, 0x1f, 0x3f, 0x5f, 0x60, + 0x00, 0x20, 0x61, 0x01, 0x21, 0x62, 0x02, 0x22, 0x63, 0x03, 0x23, + 0x64, 0x04, 0x24, 0x65, 0x05, 0x25, 0x66, 0x06, 0x26, 0x67, 0x07, + 0x27, 0x68, 0x08, 0x28, 0x69, 0x09, 0x29, 0x6a, 0x0a}; + static const uint8_t kPermMergeRGB64_2[64] = { + 0x6a, 0x2b, 0x4b, 0x6b, 0x2c, 0x4c, 0x6c, 0x2d, 0x4d, 0x6d, 0x2e, + 0x4e, 0x6e, 0x2f, 0x4f, 0x6f, 0x30, 0x50, 0x70, 0x31, 0x51, 0x71, + 0x32, 0x52, 0x72, 0x33, 0x53, 0x73, 0x34, 0x54, 0x74, 0x35, 0x55, + 0x75, 0x36, 0x56, 0x76, 0x37, 0x57, 0x77, 0x38, 0x58, 0x78, 0x39, + 0x59, 0x79, 0x3a, 0x5a, 0x7a, 0x3b, 0x5b, 0x7b, 0x3c, 0x5c, 0x7c, + 0x3d, 0x5d, 0x7d, 0x3e, 0x5e, 0x7e, 0x3f, 0x5f, 0x7f}; + const __m512i m_rgb0 = _mm512_loadu_si512((const __m512i*)kPermMergeRGB64_0); + const __m512i m_rgb1 = _mm512_loadu_si512((const __m512i*)kPermMergeRGB64_1); + const __m512i m_rgb2 = _mm512_loadu_si512((const __m512i*)kPermMergeRGB64_2); + while (width >= 64) { + __m512i rg0 = _mm512_inserti64x4( + _mm512_castsi256_si512(_mm256_loadu_si256((const __m256i*)src_r)), + _mm256_loadu_si256((const __m256i*)src_g), 1); + __m512i br = _mm512_inserti64x4( + _mm512_castsi256_si512(_mm256_loadu_si256((const __m256i*)src_b)), + _mm256_loadu_si256((const __m256i*)(src_r + 32)), 1); + __m512i gb1 = _mm512_inserti64x4( + _mm512_castsi256_si512( + _mm256_loadu_si256((const __m256i*)(src_g + 32))), + _mm256_loadu_si256((const __m256i*)(src_b + 32)), 1); + src_r += 64; + src_g += 64; + src_b += 64; + __m512i d0 = _mm512_permutex2var_epi8(rg0, m_rgb0, br); + __m512i d1 = MaskPermutexvarEpi8(_mm512_permutex2var_epi8(rg0, m_rgb1, br), + 0xb6db6db600000000ull, m_rgb1, gb1); + __m512i d2 = _mm512_permutex2var_epi8(br, m_rgb2, gb1); + _mm512_storeu_si512((__m512i*)dst_rgb, d0); + _mm512_storeu_si512((__m512i*)(dst_rgb + 64), d1); + _mm512_storeu_si512((__m512i*)(dst_rgb + 128), d2); + dst_rgb += 192; + width -= 64; + } + if (width >= 32) { + __m512i rg = _mm512_inserti64x4( + _mm512_castsi256_si512(_mm256_loadu_si256((const __m256i*)src_r)), + _mm256_loadu_si256((const __m256i*)src_g), 1); + __m512i b = + _mm512_castsi256_si512(_mm256_loadu_si256((const __m256i*)src_b)); + src_r += 32; + src_g += 32; + src_b += 32; + __m512i d0 = _mm512_permutex2var_epi8(rg, m_rgb0, b); + __m512i d1 = _mm512_permutex2var_epi8(rg, m_rgb1, b); + _mm512_storeu_si512((__m512i*)dst_rgb, d0); + _mm256_storeu_si256((__m256i*)(dst_rgb + 64), _mm512_castsi512_si256(d1)); + dst_rgb += 96; + width -= 32; + } + if (width > 0) { + __mmask32 k_in = (__mmask32)((1u << width) - 1u); + __m512i rg = _mm512_inserti64x4( + _mm512_castsi256_si512(_mm256_maskz_loadu_epi8(k_in, src_r)), + _mm256_maskz_loadu_epi8(k_in, src_g), 1); + __m512i b = _mm512_castsi256_si512(_mm256_maskz_loadu_epi8(k_in, src_b)); + __m512i d0 = _mm512_permutex2var_epi8(rg, m_rgb0, b); + __m512i d1 = _mm512_permutex2var_epi8(rg, m_rgb1, b); + int dst_bytes = width * 3; + __mmask64 k0 = dst_bytes >= 64 ? ~0ull : (1ull << dst_bytes) - 1ull; + __mmask32 k1 = dst_bytes > 64 ? (1u << (dst_bytes - 64)) - 1u : 0u; + _mm512_mask_storeu_epi8(dst_rgb, k0, d0); + _mm256_mask_storeu_epi8(dst_rgb + 64, k1, _mm512_castsi512_si256(d1)); + } + _mm256_zeroupper(); +} +#endif // HAS_MERGERGBROW_AVX512VBMI + +#ifdef HAS_RAWTORGBAROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void RAWToRGBARow_AVX512VBMI(const uint8_t* src_raw, + uint8_t* dst_rgba, + int width) { + static const uint8_t kPermRAWToRGBA0[64] = { + 0, 2, 1, 0, 0, 5, 4, 3, 0, 8, 7, 6, 0, 11, 10, 9, + 0, 14, 13, 12, 0, 17, 16, 15, 0, 20, 19, 18, 0, 23, 22, 21, + 0, 26, 25, 24, 0, 29, 28, 27, 0, 32, 31, 30, 0, 35, 34, 33, + 0, 38, 37, 36, 0, 41, 40, 39, 0, 44, 43, 42, 0, 47, 46, 45}; + static const uint8_t kPermRAWToRGBA1[64] = { + 0, 50, 49, 48, 0, 53, 52, 51, 0, 56, 55, 54, 0, 59, 58, 57, + 0, 62, 61, 60, 0, 65, 64, 63, 0, 68, 67, 66, 0, 71, 70, 69, + 0, 74, 73, 72, 0, 77, 76, 75, 0, 80, 79, 78, 0, 83, 82, 81, + 0, 86, 85, 84, 0, 89, 88, 87, 0, 92, 91, 90, 0, 95, 94, 93}; + const __m512i p0 = _mm512_loadu_si512((const __m512i*)kPermRAWToRGBA0); + const __m512i p1 = _mm512_loadu_si512((const __m512i*)kPermRAWToRGBA1); + const __m512i alpha = _mm512_set1_epi32(0x000000ff); + while (width >= 32) { + __m512i s0 = _mm512_loadu_si512((const __m512i*)src_raw); + __m512i s1 = _mm512_castsi256_si512( + _mm256_loadu_si256((const __m256i*)(src_raw + 64))); + src_raw += 96; + __m512i d0 = _mm512_or_si512(PermutexvarEpi8(p0, s0), alpha); + __m512i d1 = _mm512_or_si512(_mm512_permutex2var_epi8(s0, p1, s1), alpha); + _mm512_storeu_si512((__m512i*)dst_rgba, d0); + _mm512_storeu_si512((__m512i*)(dst_rgba + 64), d1); + dst_rgba += 128; + width -= 32; + } + if (width > 0) { + int src_bytes = width * 3; + __mmask64 ks0 = src_bytes >= 64 ? ~0ull : (1ull << src_bytes) - 1ull; + __mmask32 ks1 = src_bytes > 64 ? (1u << (src_bytes - 64)) - 1u : 0u; + __m512i s0 = _mm512_maskz_loadu_epi8(ks0, src_raw); + __m512i s1 = + _mm512_castsi256_si512(_mm256_maskz_loadu_epi8(ks1, src_raw + 64)); + __m512i d0 = _mm512_or_si512(PermutexvarEpi8(p0, s0), alpha); + __m512i d1 = _mm512_or_si512(_mm512_permutex2var_epi8(s0, p1, s1), alpha); + uint32_t m32 = (1u << width) - 1u; + _mm512_mask_storeu_epi32(dst_rgba, (__mmask16)m32, d0); + _mm512_mask_storeu_epi32(dst_rgba + 64, (__mmask16)(m32 >> 16), d1); + } + _mm256_zeroupper(); +} +#endif // HAS_RAWTORGBAROW_AVX512VBMI + +#ifdef HAS_SWAPUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void SwapUVRow_AVX512BW(const uint8_t* src_uv, uint8_t* dst_vu, int width) { + static const uint8_t kSwapUV16[16] = {1, 0, 3, 2, 5, 4, 7, 6, + 9, 8, 11, 10, 13, 12, 15, 14}; + const __m512i swap = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)kSwapUV16)); + while (width >= 32) { + __m512i v = _mm512_loadu_si512((const __m512i*)src_uv); + src_uv += 64; + _mm512_storeu_si512((__m512i*)dst_vu, _mm512_shuffle_epi8(v, swap)); + dst_vu += 64; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i v = _mm512_maskz_loadu_epi16(k, src_uv); + _mm512_mask_storeu_epi16(dst_vu, k, _mm512_shuffle_epi8(v, swap)); + } + _mm256_zeroupper(); +} +#endif // HAS_SWAPUVROW_AVX512BW + +#ifdef HAS_MIRRORROW_16_AVX512BW +LIBYUV_TARGET_AVX512BW +void MirrorRow_16_AVX512BW(const uint16_t* src, uint16_t* dst, int width) { + static const uint16_t kMirror16Idx[32] = { + 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, + 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + const __m512i rev = _mm512_loadu_si512((const __m512i*)kMirror16Idx); + src += width; + while (width >= 32) { + src -= 32; + __m512i v = _mm512_loadu_si512((const __m512i*)src); + _mm512_storeu_si512((__m512i*)dst, PermutexvarEpi16(rev, v)); + dst += 32; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i idx = _mm512_sub_epi16(rev, _mm512_set1_epi16((short)(32 - width))); + __m512i v = _mm512_maskz_loadu_epi16(k, src - width); + _mm512_mask_storeu_epi16(dst, k, PermutexvarEpi16(idx, v)); + } + _mm256_zeroupper(); +} +#endif // HAS_MIRRORROW_16_AVX512BW + +#ifdef HAS_HALFMERGEUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void HalfMergeUVRow_AVX512BW(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width) { + const __m512i c0101 = _mm512_set1_epi16(0x0101); + const __m512i czero = _mm512_setzero_si512(); + const __m512i c00ff = _mm512_set1_epi16(0x00ff); + while (width >= 64) { + __m512i u0 = _mm512_loadu_si512((const __m512i*)src_u); + __m512i u1 = _mm512_loadu_si512((const __m512i*)(src_u + src_stride_u)); + __m512i v0 = _mm512_loadu_si512((const __m512i*)src_v); + __m512i v1 = _mm512_loadu_si512((const __m512i*)(src_v + src_stride_v)); + src_u += 64; + src_v += 64; + u0 = _mm512_avg_epu16( + _mm512_srli_epi16(_mm512_add_epi16(_mm512_maddubs_epi16(u0, c0101), + _mm512_maddubs_epi16(u1, c0101)), + 1), + czero); + v0 = _mm512_avg_epu16( + _mm512_srli_epi16(_mm512_add_epi16(_mm512_maddubs_epi16(v0, c0101), + _mm512_maddubs_epi16(v1, c0101)), + 1), + czero); + _mm512_storeu_si512((__m512i*)dst_uv, + _mm512_or_si512(u0, _mm512_slli_epi16(v0, 8))); + dst_uv += 64; + width -= 64; + } + if (width > 0) { + __mmask64 k = width >= 64 ? ~0ull : (1ull << width) - 1ull; + __m512i u0 = _mm512_maskz_loadu_epi8(k, src_u); + __m512i u1 = _mm512_maskz_loadu_epi8(k, src_u + src_stride_u); + __m512i v0 = _mm512_maskz_loadu_epi8(k, src_v); + __m512i v1 = _mm512_maskz_loadu_epi8(k, src_v + src_stride_v); + __mmask32 k_odd = (__mmask32)((uint32_t)(width & 1) << (width >> 1)); + u0 = _mm512_mask_mullo_epi16(u0, k_odd, _mm512_and_si512(u0, c00ff), c0101); + u1 = _mm512_mask_mullo_epi16(u1, k_odd, _mm512_and_si512(u1, c00ff), c0101); + v0 = _mm512_mask_mullo_epi16(v0, k_odd, _mm512_and_si512(v0, c00ff), c0101); + v1 = _mm512_mask_mullo_epi16(v1, k_odd, _mm512_and_si512(v1, c00ff), c0101); + u0 = _mm512_avg_epu16( + _mm512_srli_epi16(_mm512_add_epi16(_mm512_maddubs_epi16(u0, c0101), + _mm512_maddubs_epi16(u1, c0101)), + 1), + czero); + v0 = _mm512_avg_epu16( + _mm512_srli_epi16(_mm512_add_epi16(_mm512_maddubs_epi16(v0, c0101), + _mm512_maddubs_epi16(v1, c0101)), + 1), + czero); + int out_words = (width + 1) >> 1; + __mmask32 k_out = + out_words >= 32 ? ~0u : (__mmask32)((1u << out_words) - 1u); + _mm512_mask_storeu_epi16(dst_uv, k_out, + _mm512_or_si512(u0, _mm512_slli_epi16(v0, 8))); + } + _mm256_zeroupper(); +} +#endif // HAS_HALFMERGEUVROW_AVX512BW + +#ifdef HAS_INTERPOLATEROW_16_AVX512BW +LIBYUV_TARGET_AVX512BW +void InterpolateRow_16_AVX512BW(uint16_t* dst_ptr, + const uint16_t* src_ptr, + ptrdiff_t src_stride, + int width, + int source_y_fraction) { + int y1 = source_y_fraction; + int y0 = 256 - y1; + const uint16_t* src_ptr1 = src_ptr + src_stride; + __m512i zmm_y = _mm512_set1_epi32((y1 << 16) | y0); + __m512i zmm_8000 = _mm512_set1_epi16((short)0x8000); + __m512i zmm_round = _mm512_set1_epi32(8388736); // 0x800000 + 128 + int i; + + if (y1 == 0) { + for (i = 0; i <= width - 32; i += 32) { + _mm512_storeu_si512((__m512i*)(dst_ptr + i), + _mm512_loadu_si512((const __m512i*)(src_ptr + i))); + } + if (i < width) { + __mmask32 mask = (__mmask32)((1u << (width - i)) - 1u); + _mm512_mask_storeu_epi16(dst_ptr + i, mask, + _mm512_maskz_loadu_epi16(mask, src_ptr + i)); + } + } else if (y1 == 128) { + for (i = 0; i <= width - 32; i += 32) { + __m512i row0 = _mm512_loadu_si512((const __m512i*)(src_ptr + i)); + __m512i row1 = _mm512_loadu_si512((const __m512i*)(src_ptr1 + i)); + _mm512_storeu_si512((__m512i*)(dst_ptr + i), + _mm512_avg_epu16(row0, row1)); + } + if (i < width) { + __mmask32 mask = (__mmask32)((1u << (width - i)) - 1u); + __m512i row0 = _mm512_maskz_loadu_epi16(mask, src_ptr + i); + __m512i row1 = _mm512_maskz_loadu_epi16(mask, src_ptr1 + i); + _mm512_mask_storeu_epi16(dst_ptr + i, mask, _mm512_avg_epu16(row0, row1)); + } + } else { + for (i = 0; i <= width - 32; i += 32) { + __m512i row0 = _mm512_loadu_si512((const __m512i*)(src_ptr + i)); + __m512i row1 = _mm512_loadu_si512((const __m512i*)(src_ptr1 + i)); + __m512i row0l = _mm512_unpacklo_epi16(row0, row1); + __m512i row0h = _mm512_unpackhi_epi16(row0, row1); + row0l = _mm512_sub_epi16(row0l, zmm_8000); + row0h = _mm512_sub_epi16(row0h, zmm_8000); + __m512i resl = _mm512_madd_epi16(row0l, zmm_y); + __m512i resh = _mm512_madd_epi16(row0h, zmm_y); + resl = _mm512_add_epi32(resl, zmm_round); + resh = _mm512_add_epi32(resh, zmm_round); + resl = _mm512_srai_epi32(resl, 8); + resh = _mm512_srai_epi32(resh, 8); + _mm512_storeu_si512((__m512i*)(dst_ptr + i), + _mm512_packus_epi32(resl, resh)); + } + if (i < width) { + __mmask32 mask = (__mmask32)((1u << (width - i)) - 1u); + __m512i row0 = _mm512_maskz_loadu_epi16(mask, src_ptr + i); + __m512i row1 = _mm512_maskz_loadu_epi16(mask, src_ptr1 + i); + __m512i row0l = _mm512_unpacklo_epi16(row0, row1); + __m512i row0h = _mm512_unpackhi_epi16(row0, row1); + row0l = _mm512_sub_epi16(row0l, zmm_8000); + row0h = _mm512_sub_epi16(row0h, zmm_8000); + __m512i resl = _mm512_madd_epi16(row0l, zmm_y); + __m512i resh = _mm512_madd_epi16(row0h, zmm_y); + resl = _mm512_add_epi32(resl, zmm_round); + resh = _mm512_add_epi32(resh, zmm_round); + resl = _mm512_srai_epi32(resl, 8); + resh = _mm512_srai_epi32(resh, 8); + _mm512_mask_storeu_epi16(dst_ptr + i, mask, + _mm512_packus_epi32(resl, resh)); + } + } + _mm256_zeroupper(); +} +#endif // HAS_INTERPOLATEROW_16_AVX512BW + +// =========================================================================== +// Module 4: NV12 / NV21 & I422Alpha to ARGB / RGB24 (AVX512BW / AVX512VBMI) +// =========================================================================== + +#if defined(HAS_NV12TOARGBROW_AVX512BW) || \ + defined(HAS_NV21TOARGBROW_AVX512BW) || \ + defined(HAS_NV12TORGB24ROW_AVX512VBMI) || \ + defined(HAS_NV21TORGB24ROW_AVX512VBMI) || \ + defined(HAS_I422ALPHATOARGBROW_AVX512BW) +static const uint16_t kSplitQuadWords_Win[32] = { + 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, + 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15}; +static const uint64_t kUnpermuteAVX512_Win[8] = {0, 4, 1, 5, 2, 6, 3, 7}; +#endif + +#ifdef HAS_NV12TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void NV12ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + const __m512i zmm_kUVToB = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToB)); + const __m512i zmm_kUVToG = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToG)); + const __m512i zmm_kUVToR = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToR)); + const __m512i zmm_kYToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYToRgb)); + const __m512i zmm_kYBiasToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYBiasToRgb)); + const __m512i zmm_128 = _mm512_set1_epi8((char)0x80); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_Win); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_Win); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m512i zmm3 = PermutexvarEpi16( + zmm_quad, + _mm512_castsi256_si512(_mm256_loadu_si256((const __m256i*)uv_buf))); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)y_buf)); + uv_buf += 32; + y_buf += 32; + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_add_epi16(_mm512_mulhi_epu16(zmm4, zmm_kYToRgb), + zmm_kYBiasToRgb); + __m512i zmm0 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToB, zmm3), zmm4), 6), + zmm5); + __m512i zmm1 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_subs_epi16(zmm4, _mm512_maddubs_epi16(zmm_kUVToG, zmm3)), 6), + zmm5); + __m512i zmm2 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToR, zmm3), zmm4), 6), + zmm5); + __m512i bg = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm0, zmm1)); + __m512i ra = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm2, zmm5)); + _mm512_storeu_si512((__m512i*)dst_argb, _mm512_unpacklo_epi16(bg, ra)); + _mm512_storeu_si512((__m512i*)(dst_argb + 64), + _mm512_unpackhi_epi16(bg, ra)); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m512i zmm3 = PermutexvarEpi16( + zmm_quad, + _mm512_castsi256_si512(_mm256_maskz_loadu_epi16(k_uv, uv_buf))); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8((__mmask32)m32, y_buf)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_add_epi16(_mm512_mulhi_epu16(zmm4, zmm_kYToRgb), + zmm_kYBiasToRgb); + __m512i zmm0 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToB, zmm3), zmm4), 6), + zmm5); + __m512i zmm1 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_subs_epi16(zmm4, _mm512_maddubs_epi16(zmm_kUVToG, zmm3)), 6), + zmm5); + __m512i zmm2 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToR, zmm3), zmm4), 6), + zmm5); + __m512i bg = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm0, zmm1)); + __m512i ra = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm2, zmm5)); + _mm512_mask_storeu_epi32(dst_argb, (__mmask16)m32, + _mm512_unpacklo_epi16(bg, ra)); + _mm512_mask_storeu_epi32(dst_argb + 64, (__mmask16)(m32 >> 16), + _mm512_unpackhi_epi16(bg, ra)); + } + _mm256_zeroupper(); +} +#endif // HAS_NV12TOARGBROW_AVX512BW + +#ifdef HAS_NV21TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void NV21ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* vu_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + const __m512i zmm_kUVToB = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToB)); + const __m512i zmm_kUVToG = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToG)); + const __m512i zmm_kUVToR = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToR)); + const __m512i zmm_kYToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYToRgb)); + const __m512i zmm_kYBiasToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYBiasToRgb)); + const __m512i zmm_128 = _mm512_set1_epi8((char)0x80); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_Win); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_Win); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m512i zmm3 = PermutexvarEpi16( + zmm_quad, + _mm512_castsi256_si512(_mm256_or_si256( + _mm256_slli_epi16(_mm256_loadu_si256((const __m256i*)vu_buf), 8), + _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)vu_buf), 8)))); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)y_buf)); + vu_buf += 32; + y_buf += 32; + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_add_epi16(_mm512_mulhi_epu16(zmm4, zmm_kYToRgb), + zmm_kYBiasToRgb); + __m512i zmm0 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToB, zmm3), zmm4), 6), + zmm5); + __m512i zmm1 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_subs_epi16(zmm4, _mm512_maddubs_epi16(zmm_kUVToG, zmm3)), 6), + zmm5); + __m512i zmm2 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToR, zmm3), zmm4), 6), + zmm5); + __m512i bg = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm0, zmm1)); + __m512i ra = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm2, zmm5)); + _mm512_storeu_si512((__m512i*)dst_argb, _mm512_unpacklo_epi16(bg, ra)); + _mm512_storeu_si512((__m512i*)(dst_argb + 64), + _mm512_unpackhi_epi16(bg, ra)); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m512i zmm3 = PermutexvarEpi16( + zmm_quad, + _mm512_castsi256_si512(_mm256_or_si256( + _mm256_slli_epi16(_mm256_maskz_loadu_epi16(k_uv, vu_buf), 8), + _mm256_srli_epi16(_mm256_maskz_loadu_epi16(k_uv, vu_buf), 8)))); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8((__mmask32)m32, y_buf)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_add_epi16(_mm512_mulhi_epu16(zmm4, zmm_kYToRgb), + zmm_kYBiasToRgb); + __m512i zmm0 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToB, zmm3), zmm4), 6), + zmm5); + __m512i zmm1 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_subs_epi16(zmm4, _mm512_maddubs_epi16(zmm_kUVToG, zmm3)), 6), + zmm5); + __m512i zmm2 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToR, zmm3), zmm4), 6), + zmm5); + __m512i bg = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm0, zmm1)); + __m512i ra = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm2, zmm5)); + _mm512_mask_storeu_epi32(dst_argb, (__mmask16)m32, + _mm512_unpacklo_epi16(bg, ra)); + _mm512_mask_storeu_epi32(dst_argb + 64, (__mmask16)(m32 >> 16), + _mm512_unpackhi_epi16(bg, ra)); + } + _mm256_zeroupper(); +} +#endif // HAS_NV21TOARGBROW_AVX512BW + +#if defined(HAS_NV12TORGB24ROW_AVX512VBMI) || \ + defined(HAS_NV21TORGB24ROW_AVX512VBMI) +static const uint8_t kMaskBG_NV[64] = { + 0x00, 0x40, 0x01, 0x41, 0x02, 0x42, 0x03, 0x43, 0x04, 0x44, 0x05, + 0x45, 0x06, 0x46, 0x07, 0x47, 0x10, 0x50, 0x11, 0x51, 0x12, 0x52, + 0x13, 0x53, 0x14, 0x54, 0x15, 0x55, 0x16, 0x56, 0x17, 0x57, 0x20, + 0x60, 0x21, 0x61, 0x22, 0x62, 0x23, 0x63, 0x24, 0x64, 0x25, 0x65, + 0x26, 0x66, 0x27, 0x67, 0x30, 0x70, 0x31, 0x71, 0x32, 0x72, 0x33, + 0x73, 0x34, 0x74, 0x35, 0x75, 0x36, 0x76, 0x37, 0x77}; +static const uint8_t kMaskDST0_NV[64] = { + 0x00, 0x01, 0x40, 0x02, 0x03, 0x41, 0x04, 0x05, 0x42, 0x06, 0x07, + 0x43, 0x08, 0x09, 0x44, 0x0a, 0x0b, 0x45, 0x0c, 0x0d, 0x46, 0x0e, + 0x0f, 0x47, 0x10, 0x11, 0x50, 0x12, 0x13, 0x51, 0x14, 0x15, 0x52, + 0x16, 0x17, 0x53, 0x18, 0x19, 0x54, 0x1a, 0x1b, 0x55, 0x1c, 0x1d, + 0x56, 0x1e, 0x1f, 0x57, 0x20, 0x21, 0x60, 0x22, 0x23, 0x61, 0x24, + 0x25, 0x62, 0x26, 0x27, 0x63, 0x28, 0x29, 0x64, 0x2a}; +static const uint8_t kMaskDST1_NV[64] = { + 0x2b, 0x65, 0x2c, 0x2d, 0x66, 0x2e, 0x2f, 0x67, 0x30, 0x31, 0x70, + 0x32, 0x33, 0x71, 0x34, 0x35, 0x72, 0x36, 0x37, 0x73, 0x38, 0x39, + 0x74, 0x3a, 0x3b, 0x75, 0x3c, 0x3d, 0x76, 0x3e, 0x3f, 0x77, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +#endif + +#ifdef HAS_NV12TORGB24ROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void NV12ToRGB24Row_AVX512VBMI(const uint8_t* y_buf, + const uint8_t* uv_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + const __m512i zmm_kUVToB = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToB)); + const __m512i zmm_kUVToG = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToG)); + const __m512i zmm_kUVToR = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToR)); + const __m512i zmm_kYToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYToRgb)); + const __m512i zmm_kYBiasToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYBiasToRgb)); + const __m512i zmm_128 = _mm512_set1_epi8((char)0x80); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_Win); + const __m512i zmm_mask_BG = _mm512_loadu_si512((const __m512i*)kMaskBG_NV); + const __m512i zmm_mask_DST0 = + _mm512_loadu_si512((const __m512i*)kMaskDST0_NV); + const __m512i zmm_mask_DST1 = + _mm512_loadu_si512((const __m512i*)kMaskDST1_NV); + while (width >= 32) { + __m512i zmm3 = PermutexvarEpi16( + zmm_quad, + _mm512_castsi256_si512(_mm256_loadu_si256((const __m256i*)uv_buf))); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)y_buf)); + uv_buf += 32; + y_buf += 32; + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_add_epi16(_mm512_mulhi_epu16(zmm4, zmm_kYToRgb), + zmm_kYBiasToRgb); + __m512i zmm0 = _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToB, zmm3), zmm4), 6); + __m512i zmm1 = _mm512_srai_epi16( + _mm512_subs_epi16(zmm4, _mm512_maddubs_epi16(zmm_kUVToG, zmm3)), 6); + __m512i zmm2 = _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToR, zmm3), zmm4), 6); + zmm0 = _mm512_packus_epi16(zmm0, zmm0); + zmm1 = _mm512_packus_epi16(zmm1, zmm1); + zmm2 = _mm512_packus_epi16(zmm2, zmm2); + __m512i zmm_BG = _mm512_permutex2var_epi8(zmm0, zmm_mask_BG, zmm1); + __m512i zmm_dst0 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST0, zmm2); + __m512i zmm_dst1 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST1, zmm2); + _mm512_storeu_si512((__m512i*)dst_rgb24, zmm_dst0); + _mm256_storeu_si256((__m256i*)(dst_rgb24 + 64), + _mm512_castsi512_si256(zmm_dst1)); + dst_rgb24 += 96; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m512i zmm3 = PermutexvarEpi16( + zmm_quad, + _mm512_castsi256_si512(_mm256_maskz_loadu_epi16(k_uv, uv_buf))); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8((__mmask32)m32, y_buf)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_add_epi16(_mm512_mulhi_epu16(zmm4, zmm_kYToRgb), + zmm_kYBiasToRgb); + __m512i zmm0 = _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToB, zmm3), zmm4), 6); + __m512i zmm1 = _mm512_srai_epi16( + _mm512_subs_epi16(zmm4, _mm512_maddubs_epi16(zmm_kUVToG, zmm3)), 6); + __m512i zmm2 = _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToR, zmm3), zmm4), 6); + zmm0 = _mm512_packus_epi16(zmm0, zmm0); + zmm1 = _mm512_packus_epi16(zmm1, zmm1); + zmm2 = _mm512_packus_epi16(zmm2, zmm2); + __m512i zmm_BG = _mm512_permutex2var_epi8(zmm0, zmm_mask_BG, zmm1); + __m512i zmm_dst0 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST0, zmm2); + __m512i zmm_dst1 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST1, zmm2); + int dst_bytes = width * 3; + __mmask64 k0 = dst_bytes >= 64 ? ~0ull : (1ull << dst_bytes) - 1ull; + __mmask32 k1 = dst_bytes > 64 ? (1u << (dst_bytes - 64)) - 1u : 0u; + _mm512_mask_storeu_epi8(dst_rgb24, k0, zmm_dst0); + _mm256_mask_storeu_epi8(dst_rgb24 + 64, k1, + _mm512_castsi512_si256(zmm_dst1)); + } + _mm256_zeroupper(); +} +#endif // HAS_NV12TORGB24ROW_AVX512VBMI + +#ifdef HAS_NV21TORGB24ROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void NV21ToRGB24Row_AVX512VBMI(const uint8_t* y_buf, + const uint8_t* vu_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + const __m512i zmm_kUVToB = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToB)); + const __m512i zmm_kUVToG = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToG)); + const __m512i zmm_kUVToR = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToR)); + const __m512i zmm_kYToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYToRgb)); + const __m512i zmm_kYBiasToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYBiasToRgb)); + const __m512i zmm_128 = _mm512_set1_epi8((char)0x80); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_Win); + const __m512i zmm_mask_BG = _mm512_loadu_si512((const __m512i*)kMaskBG_NV); + const __m512i zmm_mask_DST0 = + _mm512_loadu_si512((const __m512i*)kMaskDST0_NV); + const __m512i zmm_mask_DST1 = + _mm512_loadu_si512((const __m512i*)kMaskDST1_NV); + while (width >= 32) { + __m512i zmm3 = PermutexvarEpi16( + zmm_quad, + _mm512_castsi256_si512(_mm256_or_si256( + _mm256_slli_epi16(_mm256_loadu_si256((const __m256i*)vu_buf), 8), + _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)vu_buf), 8)))); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)y_buf)); + vu_buf += 32; + y_buf += 32; + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_add_epi16(_mm512_mulhi_epu16(zmm4, zmm_kYToRgb), + zmm_kYBiasToRgb); + __m512i zmm0 = _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToB, zmm3), zmm4), 6); + __m512i zmm1 = _mm512_srai_epi16( + _mm512_subs_epi16(zmm4, _mm512_maddubs_epi16(zmm_kUVToG, zmm3)), 6); + __m512i zmm2 = _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToR, zmm3), zmm4), 6); + zmm0 = _mm512_packus_epi16(zmm0, zmm0); + zmm1 = _mm512_packus_epi16(zmm1, zmm1); + zmm2 = _mm512_packus_epi16(zmm2, zmm2); + __m512i zmm_BG = _mm512_permutex2var_epi8(zmm0, zmm_mask_BG, zmm1); + __m512i zmm_dst0 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST0, zmm2); + __m512i zmm_dst1 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST1, zmm2); + _mm512_storeu_si512((__m512i*)dst_rgb24, zmm_dst0); + _mm256_storeu_si256((__m256i*)(dst_rgb24 + 64), + _mm512_castsi512_si256(zmm_dst1)); + dst_rgb24 += 96; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m512i zmm3 = PermutexvarEpi16( + zmm_quad, + _mm512_castsi256_si512(_mm256_or_si256( + _mm256_slli_epi16(_mm256_maskz_loadu_epi16(k_uv, vu_buf), 8), + _mm256_srli_epi16(_mm256_maskz_loadu_epi16(k_uv, vu_buf), 8)))); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8((__mmask32)m32, y_buf)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_add_epi16(_mm512_mulhi_epu16(zmm4, zmm_kYToRgb), + zmm_kYBiasToRgb); + __m512i zmm0 = _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToB, zmm3), zmm4), 6); + __m512i zmm1 = _mm512_srai_epi16( + _mm512_subs_epi16(zmm4, _mm512_maddubs_epi16(zmm_kUVToG, zmm3)), 6); + __m512i zmm2 = _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToR, zmm3), zmm4), 6); + zmm0 = _mm512_packus_epi16(zmm0, zmm0); + zmm1 = _mm512_packus_epi16(zmm1, zmm1); + zmm2 = _mm512_packus_epi16(zmm2, zmm2); + __m512i zmm_BG = _mm512_permutex2var_epi8(zmm0, zmm_mask_BG, zmm1); + __m512i zmm_dst0 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST0, zmm2); + __m512i zmm_dst1 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST1, zmm2); + int dst_bytes = width * 3; + __mmask64 k0 = dst_bytes >= 64 ? ~0ull : (1ull << dst_bytes) - 1ull; + __mmask32 k1 = dst_bytes > 64 ? (1u << (dst_bytes - 64)) - 1u : 0u; + _mm512_mask_storeu_epi8(dst_rgb24, k0, zmm_dst0); + _mm256_mask_storeu_epi8(dst_rgb24 + 64, k1, + _mm512_castsi512_si256(zmm_dst1)); + } + _mm256_zeroupper(); +} +#endif // HAS_NV21TORGB24ROW_AVX512VBMI + +#ifdef HAS_I422ALPHATOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I422AlphaToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + const __m512i zmm_kUVToB = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToB)); + const __m512i zmm_kUVToG = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToG)); + const __m512i zmm_kUVToR = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kUVToR)); + const __m512i zmm_kYToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYToRgb)); + const __m512i zmm_kYBiasToRgb = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)yuvconstants->kYBiasToRgb)); + const __m512i zmm_128 = _mm512_set1_epi8((char)0x80); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_Win); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_Win); + ptrdiff_t offset = v_buf - u_buf; + while (width >= 32) { + __m128i xu = _mm_loadu_si128((const __m128i*)u_buf); + __m128i xv = _mm_loadu_si128((const __m128i*)(u_buf + offset)); + u_buf += 16; + __m256i yuv = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(xu, xv)), + _mm_unpackhi_epi8(xu, xv), 1); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_castsi256_si512(yuv)); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)y_buf)); + __m512i zmm5 = _mm512_packus_epi16( + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)a_buf)), + _mm512_setzero_si512()); + y_buf += 32; + a_buf += 32; + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_add_epi16(_mm512_mulhi_epu16(zmm4, zmm_kYToRgb), + zmm_kYBiasToRgb); + __m512i zmm0 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToB, zmm3), zmm4), 6), + zmm5); + __m512i zmm1 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_subs_epi16(zmm4, _mm512_maddubs_epi16(zmm_kUVToG, zmm3)), 6), + zmm5); + __m512i zmm2 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToR, zmm3), zmm4), 6), + zmm5); + __m512i bg = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm0, zmm1)); + __m512i ra = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm2, zmm5)); + _mm512_storeu_si512((__m512i*)dst_argb, _mm512_unpacklo_epi16(bg, ra)); + _mm512_storeu_si512((__m512i*)(dst_argb + 64), + _mm512_unpackhi_epi16(bg, ra)); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m128i xu = _mm_maskz_loadu_epi8(k_uv, u_buf); + __m128i xv = _mm_maskz_loadu_epi8(k_uv, u_buf + offset); + __m256i yuv = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(xu, xv)), + _mm_unpackhi_epi8(xu, xv), 1); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_castsi256_si512(yuv)); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8((__mmask32)m32, y_buf)); + __m512i zmm5 = _mm512_packus_epi16( + _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8((__mmask32)m32, a_buf)), + _mm512_setzero_si512()); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); + zmm4 = _mm512_add_epi16(_mm512_mulhi_epu16(zmm4, zmm_kYToRgb), + zmm_kYBiasToRgb); + __m512i zmm0 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToB, zmm3), zmm4), 6), + zmm5); + __m512i zmm1 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_subs_epi16(zmm4, _mm512_maddubs_epi16(zmm_kUVToG, zmm3)), 6), + zmm5); + __m512i zmm2 = _mm512_packus_epi16( + _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToR, zmm3), zmm4), 6), + zmm5); + __m512i bg = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm0, zmm1)); + __m512i ra = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm2, zmm5)); + _mm512_mask_storeu_epi32(dst_argb, (__mmask16)m32, + _mm512_unpacklo_epi16(bg, ra)); + _mm512_mask_storeu_epi32(dst_argb + 64, (__mmask16)(m32 >> 16), + _mm512_unpackhi_epi16(bg, ra)); + } + _mm256_zeroupper(); +} +#endif // HAS_I422ALPHATOARGBROW_AVX512BW + +// =========================================================================== +// Module 5: I400ToARGB & ARGB Shaders (Attenuate, Multiply, Gray, Blend) +// =========================================================================== + +#ifdef HAS_I400TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I400ToARGBRow_AVX512BW(const uint8_t* y_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + static const uint64_t kLinearizePackQ[8] = {0, 2, 4, 6, 1, 3, 5, 7}; + static const uint8_t kBcastGrayByte[16] = {0, 0, 0, 0x80, 4, 4, 4, 0x80, + 8, 8, 8, 0x80, 12, 12, 12, 0x80}; + const __m512i zmm_yg = + _mm512_set1_epi16(*(const int16_t*)yuvconstants->kYToRgb); + const __m512i zmm_ygb = + _mm512_set1_epi16(*(const int16_t*)yuvconstants->kYBiasToRgb); + const __m512i zmm_lin = _mm512_loadu_si512((const __m512i*)kLinearizePackQ); + const __m512i zmm_bcast = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)kBcastGrayByte)); + const __m512i zmm_alpha = _mm512_set1_epi32((int)0xff000000u); + while (width >= 32) { + __m512i y16 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)y_buf)); + y_buf += 32; + y16 = _mm512_or_si512(y16, _mm512_slli_epi16(y16, 8)); + y16 = _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_mulhi_epu16(y16, zmm_yg), zmm_ygb), 6); + __m512i g = PermutexvarEpi64(zmm_lin, _mm512_packus_epi16(y16, y16)); + __m256i g256 = _mm512_castsi512_si256(g); + __m512i d0 = _mm512_or_si512( + _mm512_shuffle_epi8(_mm512_cvtepu8_epi32(_mm256_castsi256_si128(g256)), + zmm_bcast), + zmm_alpha); + __m512i d1 = _mm512_or_si512( + _mm512_shuffle_epi8( + _mm512_cvtepu8_epi32(_mm256_extracti128_si256(g256, 1)), zmm_bcast), + zmm_alpha); + _mm512_storeu_si512((__m512i*)dst_argb, d0); + _mm512_storeu_si512((__m512i*)(dst_argb + 64), d1); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __m512i y16 = + _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8((__mmask32)m32, y_buf)); + y16 = _mm512_or_si512(y16, _mm512_slli_epi16(y16, 8)); + y16 = _mm512_srai_epi16( + _mm512_adds_epi16(_mm512_mulhi_epu16(y16, zmm_yg), zmm_ygb), 6); + __m512i g = PermutexvarEpi64(zmm_lin, _mm512_packus_epi16(y16, y16)); + __m256i g256 = _mm512_castsi512_si256(g); + __m512i d0 = _mm512_or_si512( + _mm512_shuffle_epi8(_mm512_cvtepu8_epi32(_mm256_castsi256_si128(g256)), + zmm_bcast), + zmm_alpha); + __m512i d1 = _mm512_or_si512( + _mm512_shuffle_epi8( + _mm512_cvtepu8_epi32(_mm256_extracti128_si256(g256, 1)), zmm_bcast), + zmm_alpha); + _mm512_mask_storeu_epi32(dst_argb, (__mmask16)m32, d0); + _mm512_mask_storeu_epi32(dst_argb + 64, (__mmask16)(m32 >> 16), d1); + } + _mm256_zeroupper(); +} +#endif // HAS_I400TOARGBROW_AVX512BW + +#ifdef HAS_ARGBATTENUATEROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBAttenuateRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + static const int8_t kAttenShuf16[16] = {6, -128, 6, -128, 6, -128, + -128, -128, 14, -128, 14, -128, + 14, -128, -128, -128}; + const __m512i zmm_shuf = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)kAttenShuf16)); + const __m512i zmm_alpha = _mm512_set1_epi32((int)0xff000000u); + const __m512i zmm_bias = _mm512_set1_epi16(0x00ff); + while (width >= 16) { + __m512i s = _mm512_loadu_si512((const __m512i*)src_argb); + src_argb += 64; + __m512i lo = _mm512_unpacklo_epi8(s, zmm_alpha); + __m512i hi = _mm512_unpackhi_epi8(s, zmm_alpha); + lo = _mm512_srli_epi16( + _mm512_add_epi16( + _mm512_mullo_epi16(lo, _mm512_shuffle_epi8(lo, zmm_shuf)), + zmm_bias), + 8); + hi = _mm512_srli_epi16( + _mm512_add_epi16( + _mm512_mullo_epi16(hi, _mm512_shuffle_epi8(hi, zmm_shuf)), + zmm_bias), + 8); + __m512i out = _mm512_or_si512(_mm512_packus_epi16(lo, hi), + _mm512_and_si512(s, zmm_alpha)); + _mm512_storeu_si512((__m512i*)dst_argb, out); + dst_argb += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i s = _mm512_maskz_loadu_epi32(k, src_argb); + __m512i lo = _mm512_unpacklo_epi8(s, zmm_alpha); + __m512i hi = _mm512_unpackhi_epi8(s, zmm_alpha); + lo = _mm512_srli_epi16( + _mm512_add_epi16( + _mm512_mullo_epi16(lo, _mm512_shuffle_epi8(lo, zmm_shuf)), + zmm_bias), + 8); + hi = _mm512_srli_epi16( + _mm512_add_epi16( + _mm512_mullo_epi16(hi, _mm512_shuffle_epi8(hi, zmm_shuf)), + zmm_bias), + 8); + __m512i out = _mm512_or_si512(_mm512_packus_epi16(lo, hi), + _mm512_and_si512(s, zmm_alpha)); + _mm512_mask_storeu_epi32(dst_argb, k, out); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBATTENUATEROW_AVX512BW + +#ifdef HAS_ARGBMULTIPLYROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBMultiplyRow_AVX512BW(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + const __m512i zero = _mm512_setzero_si512(); + while (width >= 16) { + __m512i s0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i s1 = _mm512_loadu_si512((const __m512i*)src_argb1); + src_argb += 64; + src_argb1 += 64; + __m512i lo = _mm512_mulhrs_epi16( + _mm512_srli_epi16(_mm512_unpacklo_epi8(zero, s0), 1), + _mm512_unpacklo_epi8(s1, zero)); + __m512i hi = _mm512_mulhrs_epi16( + _mm512_srli_epi16(_mm512_unpackhi_epi8(zero, s0), 1), + _mm512_unpackhi_epi8(s1, zero)); + _mm512_storeu_si512((__m512i*)dst_argb, _mm512_packus_epi16(lo, hi)); + dst_argb += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i s0 = _mm512_maskz_loadu_epi32(k, src_argb); + __m512i s1 = _mm512_maskz_loadu_epi32(k, src_argb1); + __m512i lo = _mm512_mulhrs_epi16( + _mm512_srli_epi16(_mm512_unpacklo_epi8(zero, s0), 1), + _mm512_unpacklo_epi8(s1, zero)); + __m512i hi = _mm512_mulhrs_epi16( + _mm512_srli_epi16(_mm512_unpackhi_epi8(zero, s0), 1), + _mm512_unpackhi_epi8(s1, zero)); + _mm512_mask_storeu_epi32(dst_argb, k, _mm512_packus_epi16(lo, hi)); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBMULTIPLYROW_AVX512BW + +#ifdef HAS_ARGBGRAYROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBGrayRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + static const uint8_t kShufGrayDword[16] = {0, 0, 0, 0x80, 4, 4, 4, 0x80, + 8, 8, 8, 0x80, 12, 12, 12, 0x80}; + const __m512i c_coeff = _mm512_set1_epi32(0x004d961d); + const __m512i c_sub128 = _mm512_set1_epi8((char)0x80); + const __m512i c_one16 = _mm512_set1_epi16(1); + const __m512i c_bias = _mm512_set1_epi32(32896); + const __m512i c_shuf = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)kShufGrayDword)); + const __m512i c_alpha = _mm512_set1_epi32((int)0xff000000u); + while (width >= 16) { + __m512i s = _mm512_loadu_si512((const __m512i*)src_argb); + src_argb += 64; + __m512i y16 = _mm512_maddubs_epi16(c_coeff, _mm512_sub_epi8(s, c_sub128)); + __m512i y32 = _mm512_srli_epi32( + _mm512_add_epi32(_mm512_madd_epi16(y16, c_one16), c_bias), 8); + __m512i out = _mm512_or_si512(_mm512_and_si512(s, c_alpha), + _mm512_shuffle_epi8(y32, c_shuf)); + _mm512_storeu_si512((__m512i*)dst_argb, out); + dst_argb += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i s = _mm512_maskz_loadu_epi32(k, src_argb); + __m512i y16 = _mm512_maddubs_epi16(c_coeff, _mm512_sub_epi8(s, c_sub128)); + __m512i y32 = _mm512_srli_epi32( + _mm512_add_epi32(_mm512_madd_epi16(y16, c_one16), c_bias), 8); + __m512i out = _mm512_or_si512(_mm512_and_si512(s, c_alpha), + _mm512_shuffle_epi8(y32, c_shuf)); + _mm512_mask_storeu_epi32(dst_argb, k, out); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBGRAYROW_AVX512BW + +#ifdef HAS_ARGBGRAYROW_AVX512VNNI +LIBYUV_TARGET_AVX512VNNI +void ARGBGrayRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + static const uint8_t kShufGrayDword[16] = {0, 0, 0, 0x80, 4, 4, 4, 0x80, + 8, 8, 8, 0x80, 12, 12, 12, 0x80}; + const __m512i c_coeff = _mm512_set1_epi32(0x004d961d); + const __m512i c_sub128 = _mm512_set1_epi8((char)0x80); + const __m512i c_bias = _mm512_set1_epi32(32896); + const __m512i c_shuf = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)kShufGrayDword)); + const __m512i c_alpha = _mm512_set1_epi32((int)0xff000000u); + // Avoid _mm512_ternarylogic_epi32 (unmodeled by LLVM MSan on RGBX inputs; + // see GEMINI.md). + while (width >= 16) { + __m512i s = _mm512_loadu_si512((const __m512i*)src_argb); + src_argb += 64; + __m512i y32 = _mm512_srli_epi32( + _mm512_dpbusd_epi32(c_bias, c_coeff, _mm512_xor_si512(s, c_sub128)), 8); + __m512i out = _mm512_or_si512(_mm512_shuffle_epi8(y32, c_shuf), + _mm512_and_si512(s, c_alpha)); + _mm512_storeu_si512((__m512i*)dst_argb, out); + dst_argb += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i s = _mm512_maskz_loadu_epi32(k, src_argb); + __m512i y32 = _mm512_srli_epi32( + _mm512_dpbusd_epi32(c_bias, c_coeff, _mm512_xor_si512(s, c_sub128)), 8); + __m512i out = _mm512_or_si512(_mm512_shuffle_epi8(y32, c_shuf), + _mm512_and_si512(s, c_alpha)); + _mm512_mask_storeu_epi32(dst_argb, k, out); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBGRAYROW_AVX512VNNI + +#ifdef HAS_ARGBBLENDROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBBlendRow_AVX512BW(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + static const uint8_t kShuffleAlpha16[16] = {3u, 0x80, 3u, 0x80, 7u, 0x80, + 7u, 0x80, 11u, 0x80, 11u, 0x80, + 15u, 0x80, 15u, 0x80}; + const __m512i zmm_shuf = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)kShuffleAlpha16)); + const __m512i zmm_alpha = _mm512_set1_epi32((int)0xff000000u); + const __m512i zmm_ff00 = _mm512_set1_epi16((short)0xff00u); + const __m512i zmm_00ff = _mm512_set1_epi16(0x00ff); + const __m512i zmm_0001 = _mm512_set1_epi16(0x0001); + while (width >= 16) { + __m512i s0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i s1 = _mm512_loadu_si512((const __m512i*)src_argb1); + src_argb += 64; + src_argb1 += 64; + __m512i inv_a = _mm512_add_epi16( + _mm512_shuffle_epi8(_mm512_xor_si512(s0, zmm_alpha), zmm_shuf), + zmm_0001); + __m512i even = _mm512_srli_epi16( + _mm512_mullo_epi16(_mm512_and_si512(s1, zmm_00ff), inv_a), 8); + __m512i odd = _mm512_and_si512( + _mm512_mullo_epi16(_mm512_srli_epi16(s1, 8), inv_a), zmm_ff00); + __m512i out = _mm512_adds_epu8( + _mm512_adds_epu8(_mm512_or_si512(s0, zmm_alpha), even), odd); + _mm512_storeu_si512((__m512i*)dst_argb, out); + dst_argb += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i s0 = _mm512_maskz_loadu_epi32(k, src_argb); + __m512i s1 = _mm512_maskz_loadu_epi32(k, src_argb1); + __m512i inv_a = _mm512_add_epi16( + _mm512_shuffle_epi8(_mm512_xor_si512(s0, zmm_alpha), zmm_shuf), + zmm_0001); + __m512i even = _mm512_srli_epi16( + _mm512_mullo_epi16(_mm512_and_si512(s1, zmm_00ff), inv_a), 8); + __m512i odd = _mm512_and_si512( + _mm512_mullo_epi16(_mm512_srli_epi16(s1, 8), inv_a), zmm_ff00); + __m512i out = _mm512_adds_epu8( + _mm512_adds_epu8(_mm512_or_si512(s0, zmm_alpha), even), odd); + _mm512_mask_storeu_epi32(dst_argb, k, out); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBBLENDROW_AVX512BW + +#ifdef HAS_ARGBORROW_SSE2 +void ARGBOrRow_SSE2(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + const __m128i val = _mm_set1_epi32((int)value); + while (width >= 4) { + __m128i s = _mm_loadu_si128((const __m128i*)src_argb); + src_argb += 16; + _mm_storeu_si128((__m128i*)dst_argb, _mm_or_si128(s, val)); + dst_argb += 16; + width -= 4; } } -#endif // HAS_ARGBQUANTIZEROW_SSE2 +#endif // HAS_ARGBORROW_SSE2 -#ifdef HAS_ARGBSHADEROW_SSE2 -// Shade 4 pixels at a time by specified value. -__declspec(naked) void ARGBShadeRow_SSE2(const uint8_t* src_argb, - uint8_t* dst_argb, +#ifdef HAS_ARGBORROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBOrRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + const __m256i val = _mm256_set1_epi32((int)value); + while (width >= 8) { + __m256i s = _mm256_loadu_si256((const __m256i*)src_argb); + src_argb += 32; + _mm256_storeu_si256((__m256i*)dst_argb, _mm256_or_si256(s, val)); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBORROW_AVX2 + +#ifdef HAS_ARGBORROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBOrRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_argb, + uint32_t value, + int width) { + const __m512i val = _mm512_set1_epi32((int)value); + while (width >= 16) { + __m512i s = _mm512_loadu_si512((const __m512i*)src_argb); + src_argb += 64; + _mm512_storeu_si512((__m512i*)dst_argb, _mm512_or_si512(s, val)); + dst_argb += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i s = _mm512_maskz_loadu_epi32(k, src_argb); + _mm512_mask_storeu_epi32(dst_argb, k, _mm512_or_si512(s, val)); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBORROW_AVX512BW + +#ifdef HAS_ARGBALPHABLENDROW_SSSE3 +LIBYUV_TARGET_SSSE3 +void ARGBAlphaBlendRow_SSSE3(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + const __m128i zero = _mm_setzero_si128(); + const __m128i k0001 = _mm_set1_epi16(0x0001); + const __m128i k0101 = _mm_set1_epi16(0x0101); + const __m128i k00ff = _mm_set1_epi16(0x00ff); + const __m128i k8080 = _mm_set1_epi8((char)0x80); + const __m128i k7f81 = _mm_set1_epi16(0x7f81); + const __m128i k00ffffff = _mm_set1_epi32(0x00ffffff); + while (width >= 4) { + __m128i s = _mm_loadu_si128((const __m128i*)src_argb0); + __m128i d = _mm_loadu_si128((const __m128i*)src_argb1); + src_argb0 += 16; + src_argb1 += 16; + __m128i sa = _mm_srli_epi32(s, 24); + __m128i da = _mm_srli_epi32(d, 24); + __m128i da_sa = _mm_mulhi_epu16( + _mm_add_epi16(_mm_mullo_epi16(da, sa), k0001), k0101); + __m128i da2 = _mm_add_epi32(da, _mm_sub_epi32(sa, da_sa)); + __m128i t = _mm_srli_epi32(_mm_cmpeq_epi32(da, zero), 24); + __m128i sa_eff = _mm_or_si128(sa, t); + __m128i den_eff = _mm_or_si128(da2, t); + __m128i num = _mm_sub_epi32(_mm_slli_epi32(sa_eff, 8), sa_eff); + __m128i ratio = _mm_cvttps_epi32( + _mm_div_ps(_mm_cvtepi32_ps(num), _mm_cvtepi32_ps(den_eff))); + __m128i r_rep = _mm_shufflelo_epi16(_mm_shufflehi_epi16(ratio, 0xa0), 0xa0); + __m128i w = + _mm_or_si128(r_rep, _mm_slli_epi16(_mm_sub_epi16(k00ff, r_rep), 8)); + __m128i w_lo = _mm_unpacklo_epi16(w, w); + __m128i w_hi = _mm_unpackhi_epi16(w, w); + __m128i sb = _mm_sub_epi8(s, k8080); + __m128i db = _mm_sub_epi8(d, k8080); + __m128i lo = _mm_mulhi_epu16( + _mm_add_epi16(_mm_maddubs_epi16(w_lo, _mm_unpacklo_epi8(sb, db)), + k7f81), + k0101); + __m128i hi = _mm_mulhi_epu16( + _mm_add_epi16(_mm_maddubs_epi16(w_hi, _mm_unpackhi_epi8(sb, db)), + k7f81), + k0101); + __m128i rgb = _mm_packus_epi16(lo, hi); + __m128i out = + _mm_or_si128(_mm_and_si128(rgb, k00ffffff), _mm_slli_epi32(da2, 24)); + _mm_storeu_si128((__m128i*)dst_argb, out); + dst_argb += 16; + width -= 4; + } +} +#endif // HAS_ARGBALPHABLENDROW_SSSE3 + +#ifdef HAS_ARGBALPHABLENDROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBAlphaBlendRow_AVX2(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + const __m256i zero = _mm256_setzero_si256(); + const __m256i k0001 = _mm256_set1_epi16(0x0001); + const __m256i k0101 = _mm256_set1_epi16(0x0101); + const __m256i k00ff = _mm256_set1_epi16(0x00ff); + const __m256i k8080 = _mm256_set1_epi8((char)0x80); + const __m256i k7f81 = _mm256_set1_epi16(0x7f81); + const __m256i k00ffffff = _mm256_set1_epi32(0x00ffffff); + while (width >= 8) { + __m256i s = _mm256_loadu_si256((const __m256i*)src_argb0); + __m256i d = _mm256_loadu_si256((const __m256i*)src_argb1); + src_argb0 += 32; + src_argb1 += 32; + __m256i sa = _mm256_srli_epi32(s, 24); + __m256i da = _mm256_srli_epi32(d, 24); + __m256i da_sa = _mm256_mulhi_epu16( + _mm256_add_epi16(_mm256_mullo_epi16(da, sa), k0001), k0101); + __m256i da2 = _mm256_add_epi32(da, _mm256_sub_epi32(sa, da_sa)); + __m256i t = _mm256_srli_epi32(_mm256_cmpeq_epi32(da, zero), 24); + __m256i sa_eff = _mm256_or_si256(sa, t); + __m256i den_eff = _mm256_or_si256(da2, t); + __m256i num = _mm256_sub_epi32(_mm256_slli_epi32(sa_eff, 8), sa_eff); + __m256i ratio = _mm256_cvttps_epi32( + _mm256_div_ps(_mm256_cvtepi32_ps(num), _mm256_cvtepi32_ps(den_eff))); + __m256i r_rep = + _mm256_shufflelo_epi16(_mm256_shufflehi_epi16(ratio, 0xa0), 0xa0); + __m256i w = _mm256_or_si256( + r_rep, _mm256_slli_epi16(_mm256_sub_epi16(k00ff, r_rep), 8)); + __m256i w_lo = _mm256_unpacklo_epi16(w, w); + __m256i w_hi = _mm256_unpackhi_epi16(w, w); + __m256i sb = _mm256_sub_epi8(s, k8080); + __m256i db = _mm256_sub_epi8(d, k8080); + __m256i lo = _mm256_mulhi_epu16( + _mm256_add_epi16( + _mm256_maddubs_epi16(w_lo, _mm256_unpacklo_epi8(sb, db)), k7f81), + k0101); + __m256i hi = _mm256_mulhi_epu16( + _mm256_add_epi16( + _mm256_maddubs_epi16(w_hi, _mm256_unpackhi_epi8(sb, db)), k7f81), + k0101); + __m256i rgb = _mm256_packus_epi16(lo, hi); + __m256i out = _mm256_or_si256(_mm256_and_si256(rgb, k00ffffff), + _mm256_slli_epi32(da2, 24)); + _mm256_storeu_si256((__m256i*)dst_argb, out); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBALPHABLENDROW_AVX2 + +#ifdef HAS_ARGBALPHABLENDROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBAlphaBlendRow_AVX512BW(const uint8_t* src_argb0, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + const __m512i zero = _mm512_setzero_si512(); + const __m512i k0001 = _mm512_set1_epi16(0x0001); + const __m512i k0101 = _mm512_set1_epi16(0x0101); + const __m512i k00ff = _mm512_set1_epi16(0x00ff); + const __m512i k8080 = _mm512_set1_epi8((char)0x80); + const __m512i k7f81 = _mm512_set1_epi16(0x7f81); + const __m512i k00ffffff = _mm512_set1_epi32(0x00ffffff); + while (width >= 16) { + __m512i s = _mm512_loadu_si512((const __m512i*)src_argb0); + __m512i d = _mm512_loadu_si512((const __m512i*)src_argb1); + src_argb0 += 64; + src_argb1 += 64; + __m512i sa = _mm512_srli_epi32(s, 24); + __m512i da = _mm512_srli_epi32(d, 24); + __m512i da_sa = _mm512_mulhi_epu16( + _mm512_add_epi16(_mm512_mullo_epi16(da, sa), k0001), k0101); + __m512i da2 = _mm512_add_epi32(da, _mm512_sub_epi32(sa, da_sa)); + __mmask16 k_da0 = _mm512_cmpeq_epi32_mask(da, zero); + __m512i t = _mm512_maskz_set1_epi32(k_da0, 255); + __m512i sa_eff = _mm512_or_si512(sa, t); + __m512i den_eff = _mm512_or_si512(da2, t); + __m512i num = _mm512_sub_epi32(_mm512_slli_epi32(sa_eff, 8), sa_eff); + __m512i ratio = CvttpsEpi32( + _mm512_div_ps(_mm512_cvtepi32_ps(num), _mm512_cvtepi32_ps(den_eff))); + __m512i r_rep = + _mm512_shufflelo_epi16(_mm512_shufflehi_epi16(ratio, 0xa0), 0xa0); + __m512i w = _mm512_or_si512( + r_rep, _mm512_slli_epi16(_mm512_sub_epi16(k00ff, r_rep), 8)); + __m512i w_lo = _mm512_unpacklo_epi16(w, w); + __m512i w_hi = _mm512_unpackhi_epi16(w, w); + __m512i sb = _mm512_sub_epi8(s, k8080); + __m512i db = _mm512_sub_epi8(d, k8080); + __m512i lo = _mm512_mulhi_epu16( + _mm512_add_epi16( + _mm512_maddubs_epi16(w_lo, _mm512_unpacklo_epi8(sb, db)), k7f81), + k0101); + __m512i hi = _mm512_mulhi_epu16( + _mm512_add_epi16( + _mm512_maddubs_epi16(w_hi, _mm512_unpackhi_epi8(sb, db)), k7f81), + k0101); + __m512i rgb = _mm512_packus_epi16(lo, hi); + __m512i out = _mm512_or_si512(_mm512_and_si512(rgb, k00ffffff), + _mm512_slli_epi32(da2, 24)); + _mm512_storeu_si512((__m512i*)dst_argb, out); + dst_argb += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i s = _mm512_maskz_loadu_epi32(k, src_argb0); + __m512i d = _mm512_maskz_loadu_epi32(k, src_argb1); + __m512i sa = _mm512_srli_epi32(s, 24); + __m512i da = _mm512_srli_epi32(d, 24); + __m512i da_sa = _mm512_mulhi_epu16( + _mm512_add_epi16(_mm512_mullo_epi16(da, sa), k0001), k0101); + __m512i da2 = _mm512_add_epi32(da, _mm512_sub_epi32(sa, da_sa)); + __mmask16 k_da0 = _mm512_cmpeq_epi32_mask(da, zero); + __m512i t = _mm512_maskz_set1_epi32(k_da0, 255); + __m512i sa_eff = _mm512_or_si512(sa, t); + __m512i den_eff = _mm512_or_si512(da2, t); + __m512i num = _mm512_sub_epi32(_mm512_slli_epi32(sa_eff, 8), sa_eff); + __m512i ratio = CvttpsEpi32( + _mm512_div_ps(_mm512_cvtepi32_ps(num), _mm512_cvtepi32_ps(den_eff))); + __m512i r_rep = + _mm512_shufflelo_epi16(_mm512_shufflehi_epi16(ratio, 0xa0), 0xa0); + __m512i w = _mm512_or_si512( + r_rep, _mm512_slli_epi16(_mm512_sub_epi16(k00ff, r_rep), 8)); + __m512i w_lo = _mm512_unpacklo_epi16(w, w); + __m512i w_hi = _mm512_unpackhi_epi16(w, w); + __m512i sb = _mm512_sub_epi8(s, k8080); + __m512i db = _mm512_sub_epi8(d, k8080); + __m512i lo = _mm512_mulhi_epu16( + _mm512_add_epi16( + _mm512_maddubs_epi16(w_lo, _mm512_unpacklo_epi8(sb, db)), k7f81), + k0101); + __m512i hi = _mm512_mulhi_epu16( + _mm512_add_epi16( + _mm512_maddubs_epi16(w_hi, _mm512_unpackhi_epi8(sb, db)), k7f81), + k0101); + __m512i rgb = _mm512_packus_epi16(lo, hi); + __m512i out = _mm512_or_si512(_mm512_and_si512(rgb, k00ffffff), + _mm512_slli_epi32(da2, 24)); + _mm512_mask_storeu_epi32(dst_argb, k, out); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBALPHABLENDROW_AVX512BW + +// =========================================================================== +// Module 6: AVX2 Row Functions (Minimum AVX2 Coverage) +// =========================================================================== + +#ifdef HAS_ARGBSEPIAROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBSepiaRow_AVX2(uint8_t* dst_argb, int width) { + static const int8_t kSepiaB[16] = {17, 68, 35, 0, 17, 68, 35, 0, + 17, 68, 35, 0, 17, 68, 35, 0}; + static const int8_t kSepiaG[16] = {22, 88, 45, 0, 22, 88, 45, 0, + 22, 88, 45, 0, 22, 88, 45, 0}; + static const int8_t kSepiaR[16] = {24, 98, 50, 0, 24, 98, 50, 0, + 24, 98, 50, 0, 24, 98, 50, 0}; + if (width >= 8) { + const __m256i vb = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)kSepiaB)); + const __m256i vg = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)kSepiaG)); + const __m256i vr = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)kSepiaR)); + while (width >= 8) { + __m256i v0 = _mm256_loadu_si256((const __m256i*)dst_argb); + __m256i b = _mm256_maddubs_epi16(v0, vb); + __m256i g = _mm256_maddubs_epi16(v0, vg); + __m256i r = _mm256_maddubs_epi16(v0, vr); + __m256i bg = _mm256_srli_epi16(_mm256_hadd_epi16(b, g), 7); + __m256i rr = _mm256_srli_epi16(_mm256_hadd_epi16(r, r), 7); + bg = _mm256_packus_epi16(bg, bg); + rr = _mm256_packus_epi16(rr, rr); + bg = _mm256_unpacklo_epi8(bg, _mm256_shuffle_epi32(bg, 0x01)); + __m256i a = _mm256_srli_epi32(v0, 24); + a = _mm256_packus_epi16(a, a); + a = _mm256_packus_epi16(a, a); + __m256i ra = _mm256_unpacklo_epi8(rr, a); + __m256i out = _mm256_unpacklo_epi16(bg, ra); + _mm256_storeu_si256((__m256i*)dst_argb, out); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); + } + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + ARGBSepiaRow_C(dst_argb, width); + } +} +#endif // HAS_ARGBSEPIAROW_AVX2 + +#ifdef HAS_ARGBCOLORMATRIXROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBColorMatrixRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + const int8_t* matrix_argb, + int width) { + static const int8_t kShufTranspose4x4[16] = {0, 4, 8, 12, 1, 5, 9, 13, + 2, 6, 10, 14, 3, 7, 11, 15}; + if (width >= 8) { + const __m256i m = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)matrix_argb)); + const __m256i shuf = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShufTranspose4x4)); + const __m256i m0 = _mm256_shuffle_epi32(m, 0x00); + const __m256i m1 = _mm256_shuffle_epi32(m, 0x55); + const __m256i m2 = _mm256_shuffle_epi32(m, 0xaa); + const __m256i m3 = _mm256_shuffle_epi32(m, 0xff); + while (width >= 8) { + __m256i v0 = _mm256_loadu_si256((const __m256i*)src_argb); + src_argb += 32; + __m256i p01 = _mm256_hadds_epi16(_mm256_maddubs_epi16(v0, m0), + _mm256_maddubs_epi16(v0, m1)); + __m256i p23 = _mm256_hadds_epi16(_mm256_maddubs_epi16(v0, m2), + _mm256_maddubs_epi16(v0, m3)); + p01 = _mm256_srai_epi16(p01, 6); + p23 = _mm256_srai_epi16(p23, 6); + __m256i out = _mm256_shuffle_epi8(_mm256_packus_epi16(p01, p23), shuf); + _mm256_storeu_si256((__m256i*)dst_argb, out); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); + } + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + ARGBColorMatrixRow_C(src_argb, dst_argb, matrix_argb, width); + } +} +#endif // HAS_ARGBCOLORMATRIXROW_AVX2 + +#ifdef HAS_ARGBQUANTIZEROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBQuantizeRow_AVX2(uint8_t* dst_argb, + int scale, + int interval_size, + int interval_offset, + int width) { + if (width >= 8) { + const __m256i v_scale = _mm256_set1_epi16((short)scale); + const __m256i v_size = _mm256_set1_epi16((short)interval_size); + const __m256i v_off = _mm256_set1_epi16((short)interval_offset); + const __m256i zero = _mm256_setzero_si256(); + const __m256i alpha_mask = _mm256_set1_epi32((int)0xff000000u); + while (width >= 8) { + __m256i v0 = _mm256_loadu_si256((const __m256i*)dst_argb); + __m256i a = _mm256_and_si256(v0, alpha_mask); + __m256i lo = _mm256_unpacklo_epi8(v0, zero); + __m256i hi = _mm256_unpackhi_epi8(v0, zero); + lo = _mm256_add_epi16( + _mm256_mullo_epi16(_mm256_mulhi_epu16(lo, v_scale), v_size), v_off); + hi = _mm256_add_epi16( + _mm256_mullo_epi16(_mm256_mulhi_epu16(hi, v_scale), v_size), v_off); + __m256i out = _mm256_or_si256( + _mm256_andnot_si256(alpha_mask, _mm256_packus_epi16(lo, hi)), a); + _mm256_storeu_si256((__m256i*)dst_argb, out); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); + } + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + ARGBQuantizeRow_C(dst_argb, scale, interval_size, interval_offset, width); + } +} +#endif // HAS_ARGBQUANTIZEROW_AVX2 + +#ifdef HAS_ARGBSHADEROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBShadeRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + int width, + uint32_t value) { + if (width >= 8) { + __m256i v_val = _mm256_set1_epi32((int)value); + v_val = _mm256_unpacklo_epi8(v_val, v_val); + while (width >= 8) { + __m256i v0 = _mm256_loadu_si256((const __m256i*)src_argb); + src_argb += 32; + __m256i lo = _mm256_unpacklo_epi8(v0, v0); + __m256i hi = _mm256_unpackhi_epi8(v0, v0); + lo = _mm256_srli_epi16(_mm256_mulhi_epu16(lo, v_val), 8); + hi = _mm256_srli_epi16(_mm256_mulhi_epu16(hi, v_val), 8); + _mm256_storeu_si256((__m256i*)dst_argb, _mm256_packus_epi16(lo, hi)); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); + } + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + ARGBShadeRow_C(src_argb, dst_argb, width, value); + } +} +#endif // HAS_ARGBSHADEROW_AVX2 + +#ifdef HAS_SOBELXROW_AVX2 +LIBYUV_TARGET_AVX2 +void SobelXRow_AVX2(const uint8_t* src_y0, + const uint8_t* src_y1, + const uint8_t* src_y2, + uint8_t* dst_sobelx, + int width) { + while (width > 0) { + __m256i a0 = _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)src_y0)); + __m256i b0 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src_y0 + 2))); + __m256i a1 = _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)src_y1)); + __m256i b1 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src_y1 + 2))); + __m256i a2 = _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)src_y2)); + __m256i b2 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src_y2 + 2))); + __m256i d0 = _mm256_sub_epi16(a0, b0); + __m256i d1 = _mm256_sub_epi16(a1, b1); + __m256i d2 = _mm256_sub_epi16(a2, b2); + __m256i sum = + _mm256_add_epi16(_mm256_add_epi16(d0, d2), _mm256_add_epi16(d1, d1)); + sum = _mm256_abs_epi16(sum); + sum = _mm256_permute4x64_epi64(_mm256_packus_epi16(sum, sum), 0xd8); + _mm_storeu_si128((__m128i*)dst_sobelx, _mm256_castsi256_si128(sum)); + src_y0 += 16; + src_y1 += 16; + src_y2 += 16; + dst_sobelx += 16; + width -= 16; + } + _mm256_zeroupper(); +} +#endif // HAS_SOBELXROW_AVX2 + +#ifdef HAS_SOBELYROW_AVX2 +LIBYUV_TARGET_AVX2 +void SobelYRow_AVX2(const uint8_t* src_y0, + const uint8_t* src_y1, + uint8_t* dst_sobely, + int width) { + while (width > 0) { + __m256i a0 = _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)src_y0)); + __m256i b0 = _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)src_y1)); + __m256i a1 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src_y0 + 1))); + __m256i b1 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src_y1 + 1))); + __m256i a2 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src_y0 + 2))); + __m256i b2 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src_y1 + 2))); + __m256i d0 = _mm256_sub_epi16(a0, b0); + __m256i d1 = _mm256_sub_epi16(a1, b1); + __m256i d2 = _mm256_sub_epi16(a2, b2); + __m256i sum = + _mm256_add_epi16(_mm256_add_epi16(d0, d2), _mm256_add_epi16(d1, d1)); + sum = _mm256_abs_epi16(sum); + sum = _mm256_permute4x64_epi64(_mm256_packus_epi16(sum, sum), 0xd8); + _mm_storeu_si128((__m128i*)dst_sobely, _mm256_castsi256_si128(sum)); + src_y0 += 16; + src_y1 += 16; + dst_sobely += 16; + width -= 16; + } + _mm256_zeroupper(); +} +#endif // HAS_SOBELYROW_AVX2 + +#ifdef HAS_SOBELROW_AVX2 +LIBYUV_TARGET_AVX2 +void SobelRow_AVX2(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_argb, + int width) { + const __m256i v_alpha = _mm256_set1_epi32((int)0xff000000u); + while (width > 0) { + __m128i vx = _mm_loadu_si128((const __m128i*)src_sobelx); + __m128i vy = _mm_loadu_si128((const __m128i*)src_sobely); + __m256i s16 = _mm256_cvtepu8_epi16(_mm_adds_epu8(vx, vy)); + s16 = _mm256_or_si256(s16, _mm256_slli_epi16(s16, 8)); + s16 = _mm256_permute4x64_epi64(s16, 0xd8); + __m256i p0 = _mm256_or_si256(_mm256_unpacklo_epi16(s16, s16), v_alpha); + __m256i p1 = _mm256_or_si256(_mm256_unpackhi_epi16(s16, s16), v_alpha); + _mm256_storeu_si256((__m256i*)dst_argb, p0); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), p1); + src_sobelx += 16; + src_sobely += 16; + dst_argb += 64; + width -= 16; + } + _mm256_zeroupper(); +} +#endif // HAS_SOBELROW_AVX2 + +#ifdef HAS_SOBELTOPLANEROW_AVX2 +LIBYUV_TARGET_AVX2 +void SobelToPlaneRow_AVX2(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_y, + int width) { + while (width > 0) { + __m256i vx = _mm256_loadu_si256((const __m256i*)src_sobelx); + __m256i vy = _mm256_loadu_si256((const __m256i*)src_sobely); + _mm256_storeu_si256((__m256i*)dst_y, _mm256_adds_epu8(vx, vy)); + src_sobelx += 32; + src_sobely += 32; + dst_y += 32; + width -= 32; + } + _mm256_zeroupper(); +} +#endif // HAS_SOBELTOPLANEROW_AVX2 + +#ifdef HAS_SOBELXYROW_AVX2 +LIBYUV_TARGET_AVX2 +void SobelXYRow_AVX2(const uint8_t* src_sobelx, + const uint8_t* src_sobely, + uint8_t* dst_argb, + int width) { + const __m256i v_ff00 = _mm256_set1_epi16((short)0xff00u); + while (width > 0) { + __m128i vx = _mm_loadu_si128((const __m128i*)src_sobelx); + __m128i vy = _mm_loadu_si128((const __m128i*)src_sobely); + __m128i vs = _mm_adds_epu8(vx, vy); + __m256i bg = + _mm256_or_si256(_mm256_cvtepu8_epi16(vy), + _mm256_slli_epi16(_mm256_cvtepu8_epi16(vs), 8)); + __m256i ra = _mm256_or_si256(_mm256_cvtepu8_epi16(vx), v_ff00); + bg = _mm256_permute4x64_epi64(bg, 0xd8); + ra = _mm256_permute4x64_epi64(ra, 0xd8); + _mm256_storeu_si256((__m256i*)dst_argb, _mm256_unpacklo_epi16(bg, ra)); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), + _mm256_unpackhi_epi16(bg, ra)); + src_sobelx += 16; + src_sobely += 16; + dst_argb += 64; + width -= 16; + } + _mm256_zeroupper(); +} +#endif // HAS_SOBELXYROW_AVX2 + +#ifdef HAS_ARGBAFFINEROW_AVX2 +LIBYUV_API +LIBYUV_TARGET_AVX2 +void ARGBAffineRow_AVX2(const uint8_t* src_argb, + int src_argb_stride, + uint8_t* dst_argb, + const float* src_dudv, + int width) { + static const float kRamp[8] = {0.0f, 1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, 7.0f}; + float uv_tail[4] = {src_dudv[0], src_dudv[1], src_dudv[2], src_dudv[3]}; + if (width >= 8) { + const __m256 ramp = _mm256_loadu_ps(kRamp); + const __m256 step8 = _mm256_set1_ps(8.0f); + __m256 du = _mm256_set1_ps(uv_tail[2]); + __m256 dv = _mm256_set1_ps(uv_tail[3]); + __m256 u = + _mm256_add_ps(_mm256_set1_ps(uv_tail[0]), _mm256_mul_ps(ramp, du)); + __m256 v = + _mm256_add_ps(_mm256_set1_ps(uv_tail[1]), _mm256_mul_ps(ramp, dv)); + du = _mm256_mul_ps(du, step8); + dv = _mm256_mul_ps(dv, step8); + const __m256i v_stride = _mm256_set1_epi32(src_argb_stride); + while (width >= 8) { + __m256i iu = _mm256_cvttps_epi32(u); + __m256i iv = _mm256_cvttps_epi32(v); + __m256i idx = _mm256_add_epi32(_mm256_slli_epi32(iu, 2), + _mm256_mullo_epi32(iv, v_stride)); + __m256i pix = _mm256_i32gather_epi32((const int*)src_argb, idx, 1); + _mm256_storeu_si256((__m256i*)dst_argb, pix); + u = _mm256_add_ps(u, du); + v = _mm256_add_ps(v, dv); + dst_argb += 32; + width -= 8; + } + uv_tail[0] = _mm256_cvtss_f32(u); + uv_tail[1] = _mm256_cvtss_f32(v); + _mm256_zeroupper(); + } + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + ARGBAffineRow_C(src_argb, src_argb_stride, dst_argb, uv_tail, width); + } +} +#endif // HAS_ARGBAFFINEROW_AVX2 + +#ifdef HAS_ARGBCOLORTABLEROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBColorTableRow_AVX2(uint8_t* dst_argb, + const uint8_t* table_argb, + int width) { + if (width >= 8) { + const __m256i m0 = _mm256_set1_epi32(0x000000ff); + const __m256i m1 = _mm256_set1_epi32(0x0000ff00); + const __m256i m2 = _mm256_set1_epi32(0x00ff0000); + const __m256i m3 = _mm256_set1_epi32((int)0xff000000u); + while (width >= 8) { + __m256i v0 = _mm256_loadu_si256((const __m256i*)dst_argb); + __m256i c0 = + _mm256_and_si256(_mm256_i32gather_epi32((const int*)table_argb, + _mm256_and_si256(v0, m0), 4), + m0); + __m256i c1 = _mm256_and_si256( + _mm256_i32gather_epi32((const int*)table_argb, + _mm256_and_si256(_mm256_srli_epi32(v0, 8), m0), + 4), + m1); + __m256i c2 = _mm256_and_si256( + _mm256_i32gather_epi32( + (const int*)table_argb, + _mm256_and_si256(_mm256_srli_epi32(v0, 16), m0), 4), + m2); + __m256i c3 = + _mm256_and_si256(_mm256_i32gather_epi32((const int*)table_argb, + _mm256_srli_epi32(v0, 24), 4), + m3); + __m256i out = + _mm256_or_si256(_mm256_or_si256(c0, c1), _mm256_or_si256(c2, c3)); + _mm256_storeu_si256((__m256i*)dst_argb, out); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); + } + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + ARGBColorTableRow_C(dst_argb, table_argb, width); + } +} +#endif // HAS_ARGBCOLORTABLEROW_AVX2 + +#ifdef HAS_RGBCOLORTABLEROW_AVX2 +LIBYUV_TARGET_AVX2 +void RGBColorTableRow_AVX2(uint8_t* dst_argb, + const uint8_t* table_argb, + int width) { + if (width >= 8) { + const __m256i m0 = _mm256_set1_epi32(0x000000ff); + const __m256i m1 = _mm256_set1_epi32(0x0000ff00); + const __m256i m2 = _mm256_set1_epi32(0x00ff0000); + const __m256i m3 = _mm256_set1_epi32((int)0xff000000u); + while (width >= 8) { + __m256i v0 = _mm256_loadu_si256((const __m256i*)dst_argb); + __m256i c0 = + _mm256_and_si256(_mm256_i32gather_epi32((const int*)table_argb, + _mm256_and_si256(v0, m0), 4), + m0); + __m256i c1 = _mm256_and_si256( + _mm256_i32gather_epi32((const int*)table_argb, + _mm256_and_si256(_mm256_srli_epi32(v0, 8), m0), + 4), + m1); + __m256i c2 = _mm256_and_si256( + _mm256_i32gather_epi32( + (const int*)table_argb, + _mm256_and_si256(_mm256_srli_epi32(v0, 16), m0), 4), + m2); + __m256i c3 = _mm256_and_si256(v0, m3); + __m256i out = + _mm256_or_si256(_mm256_or_si256(c0, c1), _mm256_or_si256(c2, c3)); + _mm256_storeu_si256((__m256i*)dst_argb, out); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); + } + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + RGBColorTableRow_C(dst_argb, table_argb, width); + } +} +#endif // HAS_RGBCOLORTABLEROW_AVX2 + +#ifdef HAS_ARGBLUMACOLORTABLEROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBLumaColorTableRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + int width, + const uint8_t* luma, + uint32_t lumacoeff) { + if (width >= 8) { + const __m256i c_br = _mm256_set1_epi32((int)(lumacoeff & 0x00ff00ffu)); + const __m256i c_ga = + _mm256_set1_epi32((int)((lumacoeff >> 8) & 0x000000ffu)); + const __m256i m_00ff = _mm256_set1_epi16(0x00ff); + const __m256i m_ff = _mm256_set1_epi32(0x000000ff); + const __m256i m_7f00 = _mm256_set1_epi32(0x00007f00); + const __m256i m_18 = _mm256_set1_epi32(0x00000018); + const __m256i m_alpha = _mm256_set1_epi32((int)0xff000000u); + while (width >= 8) { + __m256i v0 = _mm256_loadu_si256((const __m256i*)src_argb); + src_argb += 32; + __m256i y = _mm256_add_epi32( + _mm256_madd_epi16(_mm256_and_si256(v0, m_00ff), c_br), + _mm256_madd_epi16(_mm256_srli_epi16(v0, 8), c_ga)); + y = _mm256_and_si256(y, m_7f00); + + __m256i b_idx = + _mm256_srli_epi32(_mm256_or_si256(_mm256_and_si256(v0, m_ff), y), 2); + __m256i b_val = _mm256_i32gather_epi32((const int*)luma, b_idx, 4); + __m256i b_sh = _mm256_and_si256(_mm256_slli_epi32(v0, 3), m_18); + b_val = _mm256_and_si256(_mm256_srlv_epi32(b_val, b_sh), m_ff); + + __m256i g_idx = _mm256_srli_epi32( + _mm256_or_si256(_mm256_and_si256(_mm256_srli_epi32(v0, 8), m_ff), y), + 2); + __m256i g_val = _mm256_i32gather_epi32((const int*)luma, g_idx, 4); + __m256i g_sh = _mm256_and_si256(_mm256_srli_epi32(v0, 5), m_18); + g_val = _mm256_slli_epi32( + _mm256_and_si256(_mm256_srlv_epi32(g_val, g_sh), m_ff), 8); + + __m256i r_idx = _mm256_srli_epi32( + _mm256_or_si256(_mm256_and_si256(_mm256_srli_epi32(v0, 16), m_ff), y), + 2); + __m256i r_val = _mm256_i32gather_epi32((const int*)luma, r_idx, 4); + __m256i r_sh = _mm256_and_si256(_mm256_srli_epi32(v0, 13), m_18); + r_val = _mm256_slli_epi32( + _mm256_and_si256(_mm256_srlv_epi32(r_val, r_sh), m_ff), 16); + + __m256i a_val = _mm256_and_si256(v0, m_alpha); + __m256i out = _mm256_or_si256(_mm256_or_si256(b_val, g_val), + _mm256_or_si256(r_val, a_val)); + _mm256_storeu_si256((__m256i*)dst_argb, out); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); + } + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + ARGBLumaColorTableRow_C(src_argb, dst_argb, width, luma, lumacoeff); + } +} +#endif // HAS_ARGBLUMACOLORTABLEROW_AVX2 + +#ifdef HAS_BYTETOFLOATROW_AVX2 +LIBYUV_TARGET_AVX2 +void ByteToFloatRow_AVX2(const uint8_t* src, + float* dst, + float scale, + int width) { + const __m256 v_scale = _mm256_set1_ps(scale); + while (width > 0) { + __m256i i0 = _mm256_cvtepu8_epi32(_mm_loadl_epi64((const __m128i*)src)); + __m256i i1 = + _mm256_cvtepu8_epi32(_mm_loadl_epi64((const __m128i*)(src + 8))); + _mm256_storeu_ps(dst, _mm256_mul_ps(_mm256_cvtepi32_ps(i0), v_scale)); + _mm256_storeu_ps(dst + 8, _mm256_mul_ps(_mm256_cvtepi32_ps(i1), v_scale)); + src += 16; + dst += 16; + width -= 16; + } + _mm256_zeroupper(); +} +#endif // HAS_BYTETOFLOATROW_AVX2 + +#ifdef HAS_GAUSSROW_AVX2 +LIBYUV_TARGET_AVX2 +void GaussRow_AVX2(const uint32_t* src, uint16_t* dst, int width) { + static const int8_t kShuf32To16[16] = {0, 1, 4, 5, 8, 9, 12, 13, + -1, -1, -1, -1, -1, -1, -1, -1}; + if (width >= 8) { + const __m256i v_128 = _mm256_set1_epi32(128); + const __m256i v_shuf = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShuf32To16)); + while (width >= 8) { + __m256i s0 = _mm256_loadu_si256((const __m256i*)src); + __m256i s1 = _mm256_loadu_si256((const __m256i*)(src + 1)); + __m256i s2 = _mm256_loadu_si256((const __m256i*)(src + 2)); + __m256i s3 = _mm256_loadu_si256((const __m256i*)(src + 3)); + __m256i s4 = _mm256_loadu_si256((const __m256i*)(src + 4)); + src += 8; + __m256i sum04 = _mm256_add_epi32(s0, s4); + __m256i sum13 = _mm256_slli_epi32(_mm256_add_epi32(s1, s3), 2); + __m256i sum2 = + _mm256_add_epi32(_mm256_slli_epi32(s2, 2), _mm256_slli_epi32(s2, 1)); + __m256i acc = + _mm256_srli_epi32(_mm256_add_epi32(_mm256_add_epi32(sum04, sum13), + _mm256_add_epi32(sum2, v_128)), + 8); + acc = _mm256_permute4x64_epi64(_mm256_shuffle_epi8(acc, v_shuf), 0xd8); + _mm_storeu_si128((__m128i*)dst, _mm256_castsi256_si128(acc)); + dst += 8; + width -= 8; + } + _mm256_zeroupper(); + } + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + GaussRow_C(src, dst, width); + } +} +#endif // HAS_GAUSSROW_AVX2 + +#ifdef HAS_GAUSSROW_F32_AVX2 +LIBYUV_TARGET_AVX2 +void GaussRow_F32_AVX2(const float* src, float* dst, int width) { + if (width >= 8) { + const __m256 v4 = _mm256_set1_ps(4.0f); + const __m256 v6 = _mm256_set1_ps(6.0f); + const __m256 v_scale = _mm256_set1_ps(1.0f / 256.0f); + while (width >= 8) { + __m256 acc = _mm256_loadu_ps(src); + acc = _mm256_add_ps(acc, _mm256_mul_ps(_mm256_loadu_ps(src + 1), v4)); + acc = _mm256_add_ps(acc, _mm256_mul_ps(_mm256_loadu_ps(src + 2), v6)); + acc = _mm256_add_ps(acc, _mm256_mul_ps(_mm256_loadu_ps(src + 3), v4)); + acc = _mm256_add_ps(acc, _mm256_loadu_ps(src + 4)); + acc = _mm256_mul_ps(acc, v_scale); + _mm256_storeu_ps(dst, acc); + src += 8; + dst += 8; + width -= 8; + } + _mm256_zeroupper(); + } + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + GaussRow_F32_C(src, dst, width); + } +} +#endif // HAS_GAUSSROW_F32_AVX2 + +#ifdef HAS_SETROW_AVX2 +LIBYUV_TARGET_AVX2 +void SetRow_AVX2(uint8_t* dst, uint8_t v8, int width) { + const __m256i v = _mm256_set1_epi8((char)v8); + while (width >= 64) { + _mm256_storeu_si256((__m256i*)dst, v); + _mm256_storeu_si256((__m256i*)(dst + 32), v); + dst += 64; + width -= 64; + } + if (width > 0) { + _mm256_storeu_si256((__m256i*)dst, v); + } + _mm256_zeroupper(); +} +#endif // HAS_SETROW_AVX2 + +#ifdef HAS_ARGBSETROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBSetRow_AVX2(uint8_t* dst_argb, uint32_t v32, int width) { + const __m256i v = _mm256_set1_epi32((int)v32); + while (width >= 16) { + _mm256_storeu_si256((__m256i*)dst_argb, v); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), v); + dst_argb += 64; + width -= 16; + } + if (width > 0) { + _mm256_storeu_si256((__m256i*)dst_argb, v); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBSETROW_AVX2 + +#ifdef HAS_COPYROW_16_AVX2 +LIBYUV_TARGET_AVX2 +void CopyRow_16_AVX2(const uint16_t* src, uint16_t* dst, int width) { + while (width > 0) { + __m256i v0 = _mm256_loadu_si256((const __m256i*)src); + __m256i v1 = _mm256_loadu_si256((const __m256i*)(src + 16)); + _mm256_storeu_si256((__m256i*)dst, v0); + _mm256_storeu_si256((__m256i*)(dst + 16), v1); + src += 32; + dst += 32; + width -= 32; + } + _mm256_zeroupper(); +} +#endif // HAS_COPYROW_16_AVX2 + +#ifdef HAS_DETILEROW_AVX2 +LIBYUV_TARGET_AVX2 +void DetileRow_AVX2(const uint8_t* src, + ptrdiff_t src_tile_stride, + uint8_t* dst, + int width) { + while (width >= 32) { + __m128i t0 = _mm_loadu_si128((const __m128i*)src); + __m128i t1 = _mm_loadu_si128((const __m128i*)(src + src_tile_stride)); + src += 2 * src_tile_stride; + _mm256_storeu_si256((__m256i*)dst, _mm256_set_m128i(t1, t0)); + dst += 32; + width -= 32; + } + if (width > 0) { + _mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src)); + } + _mm256_zeroupper(); +} +#endif // HAS_DETILEROW_AVX2 + +#ifdef HAS_DETILEROW_16_AVX2 +LIBYUV_TARGET_AVX2 +void DetileRow_16_AVX2(const uint16_t* src, + ptrdiff_t src_tile_stride, + uint16_t* dst, + int width) { + while (width >= 32) { + __m256i t0 = _mm256_loadu_si256((const __m256i*)src); + __m256i t1 = _mm256_loadu_si256((const __m256i*)(src + src_tile_stride)); + src += 2 * src_tile_stride; + _mm256_storeu_si256((__m256i*)dst, t0); + _mm256_storeu_si256((__m256i*)(dst + 16), t1); + dst += 32; + width -= 32; + } + if (width > 0) { + _mm256_storeu_si256((__m256i*)dst, _mm256_loadu_si256((const __m256i*)src)); + } + _mm256_zeroupper(); +} +#endif // HAS_DETILEROW_16_AVX2 + +#ifdef HAS_DETILESPLITUVROW_AVX2 +LIBYUV_TARGET_AVX2 +void DetileSplitUVRow_AVX2(const uint8_t* src_uv, + ptrdiff_t src_tile_stride, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + static const uint8_t kDeinterlaceUV_Win[16] = {0, 2, 4, 6, 8, 10, 12, 14, + 1, 3, 5, 7, 9, 11, 13, 15}; + const __m128i shuf128 = _mm_loadu_si128((const __m128i*)kDeinterlaceUV_Win); + const __m256i shuf256 = _mm256_broadcastsi128_si256(shuf128); + while (width >= 32) { + __m128i t0 = _mm_loadu_si128((const __m128i*)src_uv); + __m128i t1 = _mm_loadu_si128((const __m128i*)(src_uv + src_tile_stride)); + src_uv += 2 * src_tile_stride; + __m256i v = _mm256_permute4x64_epi64( + _mm256_shuffle_epi8(_mm256_set_m128i(t1, t0), shuf256), 0xd8); + _mm_storeu_si128((__m128i*)dst_u, _mm256_castsi256_si128(v)); + _mm_storeu_si128((__m128i*)dst_v, _mm256_extracti128_si256(v, 1)); + dst_u += 16; + dst_v += 16; + width -= 32; + } + if (width > 0) { + __m128i v = + _mm_shuffle_epi8(_mm_loadu_si128((const __m128i*)src_uv), shuf128); + _mm_storel_epi64((__m128i*)dst_u, v); + _mm_storel_epi64((__m128i*)dst_v, _mm_unpackhi_epi64(v, v)); + } + _mm256_zeroupper(); +} +#endif // HAS_DETILESPLITUVROW_AVX2 + +#if defined(__x86_64__) || defined(_M_X64) + +#ifdef HAS_ARGB1555TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGB1555ToARGBRow_AVX512BW(const uint8_t* src_argb1555, + uint8_t* dst_argb, + int width) { + const __m512i zmm_f800 = _mm512_set1_epi16((short)0xf800); + const __m512i zmm_03e0 = _mm512_set1_epi16(0x03e0); + const __m512i zmm_ff00 = _mm512_set1_epi16((short)0xff00); + const __m512i zmm_0108 = _mm512_set1_epi16(0x0108); + const __m512i zmm_4200 = _mm512_set1_epi16(0x4200); + while (width >= 32) { + __m512i v0 = _mm512_loadu_si512((const __m512i*)src_argb1555); + src_argb1555 += 64; + __m512i r = _mm512_mulhi_epu16( + _mm512_and_si512(_mm512_slli_epi16(v0, 1), zmm_f800), zmm_0108); + __m512i b = _mm512_mulhi_epu16(_mm512_slli_epi16(v0, 11), zmm_0108); + __m512i rb = _mm512_or_si512(_mm512_slli_epi16(r, 8), b); + __m512i g = _mm512_mulhi_epu16(_mm512_and_si512(v0, zmm_03e0), zmm_4200); + __m512i a = _mm512_and_si512(_mm512_srai_epi16(v0, 8), zmm_ff00); + __m512i ga = _mm512_or_si512(g, a); + __m512i lo = _mm512_unpacklo_epi8(rb, ga); + __m512i hi = _mm512_unpackhi_epi8(rb, ga); + __m512i out0 = _mm512_shuffle_i64x2(lo, hi, 0x44); + __m512i out1 = _mm512_shuffle_i64x2(lo, hi, 0xee); + out0 = _mm512_shuffle_i64x2(out0, out0, 0xd8); + out1 = _mm512_shuffle_i64x2(out1, out1, 0xd8); + _mm512_storeu_si512((__m512i*)dst_argb, out0); + _mm512_storeu_si512((__m512i*)(dst_argb + 64), out1); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1ULL << width) - 1ULL); + __m512i v0 = _mm512_maskz_loadu_epi16(k, src_argb1555); + __m512i r = _mm512_mulhi_epu16( + _mm512_and_si512(_mm512_slli_epi16(v0, 1), zmm_f800), zmm_0108); + __m512i b = _mm512_mulhi_epu16(_mm512_slli_epi16(v0, 11), zmm_0108); + __m512i rb = _mm512_or_si512(_mm512_slli_epi16(r, 8), b); + __m512i g = _mm512_mulhi_epu16(_mm512_and_si512(v0, zmm_03e0), zmm_4200); + __m512i a = _mm512_and_si512(_mm512_srai_epi16(v0, 8), zmm_ff00); + __m512i ga = _mm512_or_si512(g, a); + __m512i lo = _mm512_unpacklo_epi8(rb, ga); + __m512i hi = _mm512_unpackhi_epi8(rb, ga); + __m512i out0 = _mm512_shuffle_i64x2(lo, hi, 0x44); + __m512i out1 = _mm512_shuffle_i64x2(lo, hi, 0xee); + out0 = _mm512_shuffle_i64x2(out0, out0, 0xd8); + out1 = _mm512_shuffle_i64x2(out1, out1, 0xd8); + if (width > 16) { + _mm512_storeu_si512((__m512i*)dst_argb, out0); + _mm512_mask_storeu_epi32(dst_argb + 64, (__mmask16)(k >> 16), out1); + } else { + _mm512_mask_storeu_epi32(dst_argb, (__mmask16)k, out0); + } + } + _mm256_zeroupper(); +} +#endif // HAS_ARGB1555TOARGBROW_AVX512BW + +#ifdef HAS_ARGBTORGB565DITHERROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToRGB565DitherRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_rgb, + uint32_t dither4, + int width) { + __m128i d128 = _mm_cvtsi32_si128((int)dither4); + d128 = _mm_unpacklo_epi8(d128, d128); + d128 = _mm_unpacklo_epi16(d128, d128); + const __m512i zmm_dither = _mm512_broadcast_i32x4(d128); + const __m512i zmm_001f = _mm512_set1_epi32(0x0000001f); + const __m512i zmm_07e0 = _mm512_set1_epi32(0x000007e0); + const __m512i zmm_f800 = _mm512_set1_epi32(0x0000f800); + while (width >= 16) { + __m512i v0 = _mm512_adds_epu8(_mm512_loadu_si512((const __m512i*)src_argb), + zmm_dither); + src_argb += 64; + __m512i b = _mm512_and_si512(_mm512_srli_epi32(v0, 3), zmm_001f); + __m512i g = _mm512_and_si512(_mm512_srli_epi32(v0, 5), zmm_07e0); + __m512i r = _mm512_and_si512(_mm512_srli_epi32(v0, 8), zmm_f800); + __m256i rgb16 = + _mm512_cvtepi32_epi16(_mm512_or_si512(_mm512_or_si512(b, g), r)); + _mm256_storeu_si256((__m256i*)dst_rgb, rgb16); + dst_rgb += 32; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i v0 = + _mm512_adds_epu8(_mm512_maskz_loadu_epi32(k, src_argb), zmm_dither); + __m512i b = _mm512_and_si512(_mm512_srli_epi32(v0, 3), zmm_001f); + __m512i g = _mm512_and_si512(_mm512_srli_epi32(v0, 5), zmm_07e0); + __m512i r = _mm512_and_si512(_mm512_srli_epi32(v0, 8), zmm_f800); + __m256i rgb16 = + _mm512_cvtepi32_epi16(_mm512_or_si512(_mm512_or_si512(b, g), r)); + _mm256_mask_storeu_epi16(dst_rgb, k, rgb16); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTORGB565DITHERROW_AVX512BW + +#ifdef HAS_ARGBTORGB565ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToRGB565Row_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_rgb, + int width) { + const __m512i zmm_001f = _mm512_set1_epi32(0x0000001f); + const __m512i zmm_07e0 = _mm512_set1_epi32(0x000007e0); + const __m512i zmm_f800 = _mm512_set1_epi32(0x0000f800); + while (width >= 16) { + __m512i v0 = _mm512_loadu_si512((const __m512i*)src_argb); + src_argb += 64; + __m512i b = _mm512_and_si512(_mm512_srli_epi32(v0, 3), zmm_001f); + __m512i g = _mm512_and_si512(_mm512_srli_epi32(v0, 5), zmm_07e0); + __m512i r = _mm512_and_si512(_mm512_srli_epi32(v0, 8), zmm_f800); + __m256i rgb16 = + _mm512_cvtepi32_epi16(_mm512_or_si512(_mm512_or_si512(b, g), r)); + _mm256_storeu_si256((__m256i*)dst_rgb, rgb16); + dst_rgb += 32; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i v0 = _mm512_maskz_loadu_epi32(k, src_argb); + __m512i b = _mm512_and_si512(_mm512_srli_epi32(v0, 3), zmm_001f); + __m512i g = _mm512_and_si512(_mm512_srli_epi32(v0, 5), zmm_07e0); + __m512i r = _mm512_and_si512(_mm512_srli_epi32(v0, 8), zmm_f800); + __m256i rgb16 = + _mm512_cvtepi32_epi16(_mm512_or_si512(_mm512_or_si512(b, g), r)); + _mm256_mask_storeu_epi16(dst_rgb, k, rgb16); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTORGB565ROW_AVX512BW + +#ifdef HAS_MERGEUVROW_16_AVX512BW +LIBYUV_TARGET_AVX512BW +void MergeUVRow_16_AVX512BW(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width) { + const __m128i sh_u = _mm_cvtsi32_si128(16 - depth); + const __m128i sh_v = _mm_cvtsi32_si128(32 - depth); + while (width >= 16) { + __m512i u32 = + _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i*)src_u)); + __m512i v32 = + _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i*)src_v)); + src_u += 16; + src_v += 16; + u32 = _mm512_sll_epi16(u32, sh_u); + v32 = _mm512_sll_epi32(v32, sh_v); + _mm512_storeu_si512((__m512i*)dst_uv, _mm512_or_si512(u32, v32)); + dst_uv += 32; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i u32 = _mm512_cvtepu16_epi32(_mm256_maskz_loadu_epi16(k, src_u)); + __m512i v32 = _mm512_cvtepu16_epi32(_mm256_maskz_loadu_epi16(k, src_v)); + u32 = _mm512_sll_epi16(u32, sh_u); + v32 = _mm512_sll_epi32(v32, sh_v); + _mm512_mask_storeu_epi32(dst_uv, k, _mm512_or_si512(u32, v32)); + } + _mm256_zeroupper(); +} +#endif // HAS_MERGEUVROW_16_AVX512BW + +#ifdef HAS_DIVIDEROW_16_AVX512BW +LIBYUV_TARGET_AVX512BW +void DivideRow_16_AVX512BW(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + if (scale == 65536) { // Divide by 1, so do memcpy. + if (src_y != dst_y) { + memcpy(dst_y, src_y, (size_t)width * 2); + } + return; + } + const __m512i zmm_scale = _mm512_set1_epi16((short)scale); + while (width >= 32) { + __m512i v = _mm512_loadu_si512((const __m512i*)src_y); + src_y += 32; + _mm512_storeu_si512((__m512i*)dst_y, _mm512_mulhi_epu16(v, zmm_scale)); + dst_y += 32; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i v = _mm512_maskz_loadu_epi16(k, src_y); + _mm512_mask_storeu_epi16(dst_y, k, _mm512_mulhi_epu16(v, zmm_scale)); + } + _mm256_zeroupper(); +} +#endif // HAS_DIVIDEROW_16_AVX512BW + +#ifdef HAS_YUY2TOYROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void YUY2ToYRow_AVX512BW(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { + while (width >= 32) { + __m512i v = _mm512_loadu_si512((const __m512i*)src_yuy2); + src_yuy2 += 64; + _mm256_storeu_si256((__m256i*)dst_y, _mm512_cvtepi16_epi8(v)); + dst_y += 32; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i v = _mm512_maskz_loadu_epi16(k, src_yuy2); + _mm256_mask_storeu_epi8(dst_y, k, _mm512_cvtepi16_epi8(v)); + } + _mm256_zeroupper(); +} +#endif // HAS_YUY2TOYROW_AVX512BW + +#ifdef HAS_YUY2TOUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void YUY2ToUVRow_AVX512BW(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const ptrdiff_t stride = (ptrdiff_t)stride_yuy2; + while (width >= 32) { + __m512i r0 = _mm512_loadu_si512((const __m512i*)src_yuy2); + __m512i r1 = _mm512_loadu_si512((const __m512i*)(src_yuy2 + stride)); + src_yuy2 += 64; + __m512i avg = _mm512_avg_epu8(r0, r1); + _mm_storeu_si128((__m128i*)dst_u, + _mm512_cvtepi32_epi8(_mm512_srli_epi32(avg, 8))); + _mm_storeu_si128((__m128i*)dst_v, + _mm512_cvtepi32_epi8(_mm512_srli_epi32(avg, 24))); + dst_u += 16; + dst_v += 16; + width -= 32; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m512i r0 = _mm512_maskz_loadu_epi32(k, src_yuy2); + __m512i r1 = _mm512_maskz_loadu_epi32(k, src_yuy2 + stride); + __m512i avg = _mm512_avg_epu8(r0, r1); + _mm_mask_storeu_epi8(dst_u, k, + _mm512_cvtepi32_epi8(_mm512_srli_epi32(avg, 8))); + _mm_mask_storeu_epi8(dst_v, k, + _mm512_cvtepi32_epi8(_mm512_srli_epi32(avg, 24))); + } + _mm256_zeroupper(); +} +#endif // HAS_YUY2TOUVROW_AVX512BW + +#ifdef HAS_UYVYTOYROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void UYVYToYRow_AVX512BW(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { + while (width >= 32) { + __m512i v = _mm512_loadu_si512((const __m512i*)src_uyvy); + src_uyvy += 64; + _mm256_storeu_si256((__m256i*)dst_y, + _mm512_cvtepi16_epi8(_mm512_srli_epi16(v, 8))); + dst_y += 32; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i v = _mm512_maskz_loadu_epi16(k, src_uyvy); + _mm256_mask_storeu_epi8(dst_y, k, + _mm512_cvtepi16_epi8(_mm512_srli_epi16(v, 8))); + } + _mm256_zeroupper(); +} +#endif // HAS_UYVYTOYROW_AVX512BW + +#ifdef HAS_UYVYTOUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void UYVYToUVRow_AVX512BW(const uint8_t* src_uyvy, + int stride_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const ptrdiff_t stride = (ptrdiff_t)stride_uyvy; + while (width >= 32) { + __m512i r0 = _mm512_loadu_si512((const __m512i*)src_uyvy); + __m512i r1 = _mm512_loadu_si512((const __m512i*)(src_uyvy + stride)); + src_uyvy += 64; + __m512i avg = _mm512_avg_epu8(r0, r1); + _mm_storeu_si128((__m128i*)dst_u, _mm512_cvtepi32_epi8(avg)); + _mm_storeu_si128((__m128i*)dst_v, + _mm512_cvtepi32_epi8(_mm512_srli_epi32(avg, 16))); + dst_u += 16; + dst_v += 16; + width -= 32; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m512i r0 = _mm512_maskz_loadu_epi32(k, src_uyvy); + __m512i r1 = _mm512_maskz_loadu_epi32(k, src_uyvy + stride); + __m512i avg = _mm512_avg_epu8(r0, r1); + _mm_mask_storeu_epi8(dst_u, k, _mm512_cvtepi32_epi8(avg)); + _mm_mask_storeu_epi8(dst_v, k, + _mm512_cvtepi32_epi8(_mm512_srli_epi32(avg, 16))); + } + _mm256_zeroupper(); +} +#endif // HAS_UYVYTOUVROW_AVX512BW + +#ifdef HAS_ARGBSEPIAROW_AVX512VNNI +LIBYUV_TARGET_AVX512VNNI +void ARGBSepiaRow_AVX512VNNI(uint8_t* dst_argb, int width) { + const __m512i zero = _mm512_setzero_si512(); + const __m512i c_b = _mm512_set1_epi32(0x00234411); + const __m512i c_g = _mm512_set1_epi32(0x002d5816); + const __m512i c_r = _mm512_set1_epi32(0x00326218); + const __m512i max255 = _mm512_set1_epi32(255); + const __m512i a_mask = _mm512_set1_epi32((int)0xff000000u); + while (width >= 16) { + __m512i v0 = _mm512_loadu_si512((const __m512i*)dst_argb); + __m512i b = _mm512_srli_epi32(_mm512_dpbusd_epi32(zero, v0, c_b), 7); + __m512i g = _mm512_min_epu32( + _mm512_srli_epi32(_mm512_dpbusd_epi32(zero, v0, c_g), 7), max255); + __m512i r = _mm512_min_epu32( + _mm512_srli_epi32(_mm512_dpbusd_epi32(zero, v0, c_r), 7), max255); + __m512i a = _mm512_and_si512(v0, a_mask); + __m512i out = _mm512_or_si512(_mm512_or_si512(b, _mm512_slli_epi32(g, 8)), + _mm512_or_si512(_mm512_slli_epi32(r, 16), a)); + _mm512_storeu_si512((__m512i*)dst_argb, out); + dst_argb += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i v0 = _mm512_maskz_loadu_epi32(k, dst_argb); + __m512i b = _mm512_srli_epi32(_mm512_dpbusd_epi32(zero, v0, c_b), 7); + __m512i g = _mm512_min_epu32( + _mm512_srli_epi32(_mm512_dpbusd_epi32(zero, v0, c_g), 7), max255); + __m512i r = _mm512_min_epu32( + _mm512_srli_epi32(_mm512_dpbusd_epi32(zero, v0, c_r), 7), max255); + __m512i a = _mm512_and_si512(v0, a_mask); + __m512i out = _mm512_or_si512(_mm512_or_si512(b, _mm512_slli_epi32(g, 8)), + _mm512_or_si512(_mm512_slli_epi32(r, 16), a)); + _mm512_mask_storeu_epi32(dst_argb, k, out); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBSEPIAROW_AVX512VNNI + +#ifdef HAS_ARGBCOLORMATRIXROW_AVX512VNNI +LIBYUV_TARGET_AVX512VNNI +void ARGBColorMatrixRow_AVX512VNNI(const uint8_t* src_argb, + uint8_t* dst_argb, + const int8_t* matrix_argb, + int width) { + const __m512i zero = _mm512_setzero_si512(); + const __m512i max255 = _mm512_set1_epi32(255); + const __m128i m128 = _mm_loadu_si128((const __m128i*)matrix_argb); + const __m512i m0 = _mm512_set1_epi32(_mm_cvtsi128_si32(m128)); + const __m512i m1 = + _mm512_set1_epi32(_mm_cvtsi128_si32(_mm_srli_si128(m128, 4))); + const __m512i m2 = + _mm512_set1_epi32(_mm_cvtsi128_si32(_mm_srli_si128(m128, 8))); + const __m512i m3 = + _mm512_set1_epi32(_mm_cvtsi128_si32(_mm_srli_si128(m128, 12))); + while (width >= 16) { + __m512i v0 = _mm512_loadu_si512((const __m512i*)src_argb); + src_argb += 64; + __m512i b = _mm512_min_epu32( + _mm512_max_epi32( + _mm512_srai_epi32(_mm512_dpbusd_epi32(zero, v0, m0), 6), zero), + max255); + __m512i g = _mm512_min_epu32( + _mm512_max_epi32( + _mm512_srai_epi32(_mm512_dpbusd_epi32(zero, v0, m1), 6), zero), + max255); + __m512i r = _mm512_min_epu32( + _mm512_max_epi32( + _mm512_srai_epi32(_mm512_dpbusd_epi32(zero, v0, m2), 6), zero), + max255); + __m512i a = _mm512_min_epu32( + _mm512_max_epi32( + _mm512_srai_epi32(_mm512_dpbusd_epi32(zero, v0, m3), 6), zero), + max255); + __m512i out = _mm512_or_si512( + _mm512_or_si512(b, _mm512_slli_epi32(g, 8)), + _mm512_or_si512(_mm512_slli_epi32(r, 16), _mm512_slli_epi32(a, 24))); + _mm512_storeu_si512((__m512i*)dst_argb, out); + dst_argb += 64; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i v0 = _mm512_maskz_loadu_epi32(k, src_argb); + __m512i b = _mm512_min_epu32( + _mm512_max_epi32( + _mm512_srai_epi32(_mm512_dpbusd_epi32(zero, v0, m0), 6), zero), + max255); + __m512i g = _mm512_min_epu32( + _mm512_max_epi32( + _mm512_srai_epi32(_mm512_dpbusd_epi32(zero, v0, m1), 6), zero), + max255); + __m512i r = _mm512_min_epu32( + _mm512_max_epi32( + _mm512_srai_epi32(_mm512_dpbusd_epi32(zero, v0, m2), 6), zero), + max255); + __m512i a = _mm512_min_epu32( + _mm512_max_epi32( + _mm512_srai_epi32(_mm512_dpbusd_epi32(zero, v0, m3), 6), zero), + max255); + __m512i out = _mm512_or_si512( + _mm512_or_si512(b, _mm512_slli_epi32(g, 8)), + _mm512_or_si512(_mm512_slli_epi32(r, 16), _mm512_slli_epi32(a, 24))); + _mm512_mask_storeu_epi32(dst_argb, k, out); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBCOLORMATRIXROW_AVX512VNNI + +#ifdef HAS_HALFFLOATROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void HalfFloatRow_AVX512BW(const uint16_t* src, + uint16_t* dst, + float scale, + int width) { + const __m512 vscale = _mm512_set1_ps(scale); + while (width >= 16) { + __m512i s32 = + _mm512_cvtepu16_epi32(_mm256_loadu_si256((const __m256i*)src)); + src += 16; + __m512 f = _mm512_mul_ps(_mm512_cvtepi32_ps(s32), vscale); + __m256i h16 = _mm512_cvtps_ph(f, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC); + _mm256_storeu_si256((__m256i*)dst, h16); + dst += 16; + width -= 16; + } + if (width > 0) { + __mmask16 k = (__mmask16)((1u << width) - 1u); + __m512i s32 = _mm512_cvtepu16_epi32(_mm256_maskz_loadu_epi16(k, src)); + __m512 f = _mm512_mul_ps(_mm512_cvtepi32_ps(s32), vscale); + __m256i h16 = _mm512_cvtps_ph(f, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC); + _mm256_mask_storeu_epi16(dst, k, h16); + } + _mm256_zeroupper(); +} +#endif // HAS_HALFFLOATROW_AVX512BW + +#ifdef HAS_CONVERT8TO8ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void Convert8To8Row_AVX512BW(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width) { + const __m512i zmm_scale = + _mm512_slli_epi16(_mm512_set1_epi16((short)scale), 8); + const __m512i zmm_bias = _mm512_set1_epi8((char)bias); + const __m512i zmm_zero = _mm512_setzero_si512(); + while (width >= 64) { + __m512i y8 = _mm512_loadu_si512((const __m512i*)src_y); + src_y += 64; + __m512i y_lo = + _mm512_mulhi_epu16(_mm512_unpacklo_epi8(y8, zmm_zero), zmm_scale); + __m512i y_hi = + _mm512_mulhi_epu16(_mm512_unpackhi_epi8(y8, zmm_zero), zmm_scale); + __m512i out8 = _mm512_add_epi8(_mm512_packus_epi16(y_lo, y_hi), zmm_bias); + _mm512_storeu_si512((__m512i*)dst_y, out8); + dst_y += 64; + width -= 64; + } + if (width > 0) { + __mmask64 k = (__mmask64)((1ULL << width) - 1ULL); + __m512i y8 = _mm512_maskz_loadu_epi8(k, src_y); + __m512i y_lo = + _mm512_mulhi_epu16(_mm512_unpacklo_epi8(y8, zmm_zero), zmm_scale); + __m512i y_hi = + _mm512_mulhi_epu16(_mm512_unpackhi_epi8(y8, zmm_zero), zmm_scale); + __m512i out8 = _mm512_add_epi8(_mm512_packus_epi16(y_lo, y_hi), zmm_bias); + _mm512_mask_storeu_epi8(dst_y, k, out8); + } + _mm256_zeroupper(); +} +#endif // HAS_CONVERT8TO8ROW_AVX512BW + +// =========================================================================== +// Extended YUV (I422, I444, YUY2, UYVY, I210, I212, I410, P210, P410) +// to ARGB / RGBA / RGB24 / AR30 (AVX512BW / AVX512VBMI) +// =========================================================================== + +static const uint16_t kSplitQuadWords_ExtWin[32] = { + 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, + 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15}; +static const uint64_t kUnpermuteAVX512_ExtWin[8] = {0, 4, 1, 5, 2, 6, 3, 7}; +static const uint16_t kPermAR30_0_Win[32] = { + 0, 32, 1, 33, 2, 34, 3, 35, 4, 36, 5, 37, 6, 38, 7, 39, + 8, 40, 9, 41, 10, 42, 11, 43, 12, 44, 13, 45, 14, 46, 15, 47}; +static const uint16_t kPermAR30_1_Win[32] = { + 16, 48, 17, 49, 18, 50, 19, 51, 20, 52, 21, 53, 22, 54, 23, 55, + 24, 56, 25, 57, 26, 58, 27, 59, 28, 60, 29, 61, 30, 62, 31, 63}; +static const uint8_t kShuffleYUY2Y_Win[16] = {0, 0, 2, 2, 4, 4, 6, 6, + 8, 8, 10, 10, 12, 12, 14, 14}; +static const uint8_t kShuffleYUY2UV_Win[16] = {1, 3, 1, 3, 5, 7, 5, 7, + 9, 11, 9, 11, 13, 15, 13, 15}; +static const uint8_t kShuffleUYVYY_Win[16] = {1, 1, 3, 3, 5, 5, 7, 7, + 9, 9, 11, 11, 13, 13, 15, 15}; +static const uint8_t kShuffleUYVYUV_Win[16] = {0, 2, 0, 2, 4, 6, 4, 6, + 8, 10, 8, 10, 12, 14, 12, 14}; + +#define YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants) \ + const __m512i zmm_kUVToB = _mm512_broadcast_i32x4( \ + _mm_loadu_si128((const __m128i*)(yuvconstants)->kUVToB)); \ + const __m512i zmm_kUVToG = _mm512_broadcast_i32x4( \ + _mm_loadu_si128((const __m128i*)(yuvconstants)->kUVToG)); \ + const __m512i zmm_kUVToR = _mm512_broadcast_i32x4( \ + _mm_loadu_si128((const __m128i*)(yuvconstants)->kUVToR)); \ + const __m512i zmm_kYToRgb = _mm512_broadcast_i32x4( \ + _mm_loadu_si128((const __m128i*)(yuvconstants)->kYToRgb)); \ + const __m512i zmm_kYBiasToRgb = _mm512_broadcast_i32x4( \ + _mm_loadu_si128((const __m128i*)(yuvconstants)->kYBiasToRgb)); \ + const __m512i zmm_128 = _mm512_set1_epi8((char)0x80) + +#define YUVTORGB16_WIN_AVX512BW \ + zmm3 = _mm512_sub_epi8(zmm3, zmm_128); \ + zmm4 = _mm512_add_epi16(_mm512_mulhi_epu16(zmm4, zmm_kYToRgb), \ + zmm_kYBiasToRgb); \ + __m512i b16 = \ + _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToB, zmm3), zmm4); \ + __m512i g16 = \ + _mm512_subs_epi16(zmm4, _mm512_maddubs_epi16(zmm_kUVToG, zmm3)); \ + __m512i r16 = _mm512_adds_epi16(_mm512_maddubs_epi16(zmm_kUVToR, zmm3), zmm4) + +#define YUVTORGB8_WIN_AVX512BW \ + YUVTORGB16_WIN_AVX512BW; \ + __m512i zmm0 = _mm512_packus_epi16(_mm512_srai_epi16(b16, 6), zmm5); \ + __m512i zmm1 = _mm512_packus_epi16(_mm512_srai_epi16(g16, 6), zmm5); \ + __m512i zmm2 = _mm512_packus_epi16(_mm512_srai_epi16(r16, 6), zmm5) + +#define STOREARGB_WIN_AVX512BW(dst_ptr) \ + do { \ + __m512i bg = \ + PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm0, zmm1)); \ + __m512i ra = \ + PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm2, zmm5)); \ + _mm512_storeu_si512((__m512i*)(dst_ptr), _mm512_unpacklo_epi16(bg, ra)); \ + _mm512_storeu_si512((__m512i*)((dst_ptr) + 64), \ + _mm512_unpackhi_epi16(bg, ra)); \ + } while (0) + +#define STOREARGB_MASK_WIN_AVX512BW(dst_ptr, m32) \ + do { \ + __m512i bg = \ + PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm0, zmm1)); \ + __m512i ra = \ + PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm2, zmm5)); \ + _mm512_mask_storeu_epi32((dst_ptr), (__mmask16)(m32), \ + _mm512_unpacklo_epi16(bg, ra)); \ + _mm512_mask_storeu_epi32((dst_ptr) + 64, (__mmask16)((m32) >> 16), \ + _mm512_unpackhi_epi16(bg, ra)); \ + } while (0) + +#define PACKAR30_WIN_AVX512BW(dst0, dst1) \ + b16 = _mm512_max_epi16(_mm512_min_epi16(b16, zmm_3ff0), zmm_zero); \ + g16 = _mm512_max_epi16(_mm512_min_epi16(g16, zmm_3ff0), zmm_zero); \ + r16 = _mm512_max_epi16(_mm512_min_epi16(r16, zmm_3ff0), zmm_zero); \ + __m512i lo16 = \ + _mm512_or_si512(_mm512_srli_epi16(b16, 4), \ + _mm512_and_si512(_mm512_slli_epi16(g16, 6), zmm_fc00)); \ + __m512i hi16 = \ + _mm512_or_si512(_mm512_or_si512(_mm512_and_si512(r16, zmm_3ff0), \ + _mm512_srli_epi16(g16, 10)), \ + zmm_c000); \ + __m512i dst0 = _mm512_permutex2var_epi16(lo16, zmm_perm0, hi16); \ + __m512i dst1 = _mm512_permutex2var_epi16(lo16, zmm_perm1, hi16) + +#ifdef HAS_I422TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I422ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_ExtWin); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m128i xu = _mm_loadu_si128((const __m128i*)u_buf); + __m128i xv = _mm_loadu_si128((const __m128i*)v_buf); + u_buf += 16; + v_buf += 16; + __m256i uv256 = _mm256_inserti128_si256( + _mm256_zextsi128_si256(_mm_unpacklo_epi8(xu, xv)), + _mm_unpackhi_epi8(xu, xv), 1); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)y_buf)); + y_buf += 32; + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m128i xu = _mm_maskz_loadu_epi8(k_uv, u_buf); + __m128i xv = _mm_maskz_loadu_epi8(k_uv, v_buf); + __m256i uv256 = _mm256_inserti128_si256( + _mm256_zextsi128_si256(_mm_unpacklo_epi8(xu, xv)), + _mm_unpackhi_epi8(xu, xv), 1); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8((__mmask32)m32, y_buf)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_I422TOARGBROW_AVX512BW + +#ifdef HAS_I422TORGBAROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I422ToRGBARow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_rgba, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_ExtWin); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m128i xu = _mm_loadu_si128((const __m128i*)u_buf); + __m128i xv = _mm_loadu_si128((const __m128i*)v_buf); + u_buf += 16; + v_buf += 16; + __m256i uv256 = _mm256_inserti128_si256( + _mm256_zextsi128_si256(_mm_unpacklo_epi8(xu, xv)), + _mm_unpackhi_epi8(xu, xv), 1); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)y_buf)); + y_buf += 32; + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + YUVTORGB8_WIN_AVX512BW; + __m512i ab = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm5, zmm0)); + __m512i gr = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm1, zmm2)); + _mm512_storeu_si512((__m512i*)dst_rgba, _mm512_unpacklo_epi16(ab, gr)); + _mm512_storeu_si512((__m512i*)(dst_rgba + 64), + _mm512_unpackhi_epi16(ab, gr)); + dst_rgba += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m128i xu = _mm_maskz_loadu_epi8(k_uv, u_buf); + __m128i xv = _mm_maskz_loadu_epi8(k_uv, v_buf); + __m256i uv256 = _mm256_inserti128_si256( + _mm256_zextsi128_si256(_mm_unpacklo_epi8(xu, xv)), + _mm_unpackhi_epi8(xu, xv), 1); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8((__mmask32)m32, y_buf)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + YUVTORGB8_WIN_AVX512BW; + __m512i ab = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm5, zmm0)); + __m512i gr = PermutexvarEpi64(zmm_unperm, _mm512_unpacklo_epi8(zmm1, zmm2)); + _mm512_mask_storeu_epi32(dst_rgba, (__mmask16)m32, + _mm512_unpacklo_epi16(ab, gr)); + _mm512_mask_storeu_epi32(dst_rgba + 64, (__mmask16)(m32 >> 16), + _mm512_unpackhi_epi16(ab, gr)); + } + _mm256_zeroupper(); +} +#endif // HAS_I422TORGBAROW_AVX512BW + +#ifdef HAS_I444TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I444ToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m512i u16 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)u_buf)); + __m512i v16 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)v_buf)); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)y_buf)); + u_buf += 32; + v_buf += 32; + y_buf += 32; + __m512i zmm3 = _mm512_or_si512(u16, _mm512_slli_epi16(v16, 8)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask32 k = (__mmask32)m32; + __m512i u16 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, u_buf)); + __m512i v16 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, v_buf)); + __m512i zmm4 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, y_buf)); + __m512i zmm3 = _mm512_or_si512(u16, _mm512_slli_epi16(v16, 8)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_I444TOARGBROW_AVX512BW + +#ifdef HAS_I444ALPHATOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I444AlphaToARGBRow_AVX512BW(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + const uint8_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + while (width >= 32) { + __m512i u16 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)u_buf)); + __m512i v16 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)v_buf)); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)y_buf)); + __m512i a16 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)a_buf)); + u_buf += 32; + v_buf += 32; + y_buf += 32; + a_buf += 32; + __m512i zmm3 = _mm512_or_si512(u16, _mm512_slli_epi16(v16, 8)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + __m512i zmm5 = _mm512_packus_epi16(a16, a16); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask32 k = (__mmask32)m32; + __m512i u16 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, u_buf)); + __m512i v16 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, v_buf)); + __m512i zmm4 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, y_buf)); + __m512i a16 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, a_buf)); + __m512i zmm3 = _mm512_or_si512(u16, _mm512_slli_epi16(v16, 8)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + __m512i zmm5 = _mm512_packus_epi16(a16, a16); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_I444ALPHATOARGBROW_AVX512BW + +#ifdef HAS_I444TORGB24ROW_AVX512VBMI +static const uint8_t kMaskBG_I444[64] = { + 0x00, 0x40, 0x01, 0x41, 0x02, 0x42, 0x03, 0x43, 0x04, 0x44, 0x05, + 0x45, 0x06, 0x46, 0x07, 0x47, 0x10, 0x50, 0x11, 0x51, 0x12, 0x52, + 0x13, 0x53, 0x14, 0x54, 0x15, 0x55, 0x16, 0x56, 0x17, 0x57, 0x20, + 0x60, 0x21, 0x61, 0x22, 0x62, 0x23, 0x63, 0x24, 0x64, 0x25, 0x65, + 0x26, 0x66, 0x27, 0x67, 0x30, 0x70, 0x31, 0x71, 0x32, 0x72, 0x33, + 0x73, 0x34, 0x74, 0x35, 0x75, 0x36, 0x76, 0x37, 0x77}; +static const uint8_t kMaskDST0_I444[64] = { + 0x00, 0x01, 0x40, 0x02, 0x03, 0x41, 0x04, 0x05, 0x42, 0x06, 0x07, + 0x43, 0x08, 0x09, 0x44, 0x0a, 0x0b, 0x45, 0x0c, 0x0d, 0x46, 0x0e, + 0x0f, 0x47, 0x10, 0x11, 0x50, 0x12, 0x13, 0x51, 0x14, 0x15, 0x52, + 0x16, 0x17, 0x53, 0x18, 0x19, 0x54, 0x1a, 0x1b, 0x55, 0x1c, 0x1d, + 0x56, 0x1e, 0x1f, 0x57, 0x20, 0x21, 0x60, 0x22, 0x23, 0x61, 0x24, + 0x25, 0x62, 0x26, 0x27, 0x63, 0x28, 0x29, 0x64, 0x2a}; +static const uint8_t kMaskDST1_I444[64] = { + 0x2b, 0x65, 0x2c, 0x2d, 0x66, 0x2e, 0x2f, 0x67, 0x30, 0x31, 0x70, + 0x32, 0x33, 0x71, 0x34, 0x35, 0x72, 0x36, 0x37, 0x73, 0x38, 0x39, + 0x74, 0x3a, 0x3b, 0x75, 0x3c, 0x3d, 0x76, 0x3e, 0x3f, 0x77, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +LIBYUV_TARGET_AVX512VBMI +void I444ToRGB24Row_AVX512VBMI(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_rgb24, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_mask_BG = _mm512_loadu_si512((const __m512i*)kMaskBG_I444); + const __m512i zmm_mask_DST0 = + _mm512_loadu_si512((const __m512i*)kMaskDST0_I444); + const __m512i zmm_mask_DST1 = + _mm512_loadu_si512((const __m512i*)kMaskDST1_I444); + while (width >= 32) { + __m512i u16 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)u_buf)); + __m512i v16 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)v_buf)); + __m512i zmm4 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)y_buf)); + u_buf += 32; + v_buf += 32; + y_buf += 32; + __m512i zmm3 = _mm512_or_si512(u16, _mm512_slli_epi16(v16, 8)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + YUVTORGB16_WIN_AVX512BW; + __m512i zmm0 = _mm512_srai_epi16(b16, 6); + __m512i zmm1 = _mm512_srai_epi16(g16, 6); + __m512i zmm2 = _mm512_srai_epi16(r16, 6); + zmm0 = _mm512_packus_epi16(zmm0, zmm0); + zmm1 = _mm512_packus_epi16(zmm1, zmm1); + zmm2 = _mm512_packus_epi16(zmm2, zmm2); + __m512i zmm_BG = _mm512_permutex2var_epi8(zmm0, zmm_mask_BG, zmm1); + __m512i zmm_dst0 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST0, zmm2); + __m512i zmm_dst1 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST1, zmm2); + _mm512_storeu_si512((__m512i*)dst_rgb24, zmm_dst0); + _mm256_storeu_si256((__m256i*)(dst_rgb24 + 64), + _mm512_castsi512_si256(zmm_dst1)); + dst_rgb24 += 96; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i u16 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, u_buf)); + __m512i v16 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, v_buf)); + __m512i zmm4 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, y_buf)); + __m512i zmm3 = _mm512_or_si512(u16, _mm512_slli_epi16(v16, 8)); + zmm4 = _mm512_or_si512(zmm4, _mm512_slli_epi16(zmm4, 8)); + YUVTORGB16_WIN_AVX512BW; + __m512i zmm0 = _mm512_srai_epi16(b16, 6); + __m512i zmm1 = _mm512_srai_epi16(g16, 6); + __m512i zmm2 = _mm512_srai_epi16(r16, 6); + zmm0 = _mm512_packus_epi16(zmm0, zmm0); + zmm1 = _mm512_packus_epi16(zmm1, zmm1); + zmm2 = _mm512_packus_epi16(zmm2, zmm2); + __m512i zmm_BG = _mm512_permutex2var_epi8(zmm0, zmm_mask_BG, zmm1); + __m512i zmm_dst0 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST0, zmm2); + __m512i zmm_dst1 = _mm512_permutex2var_epi8(zmm_BG, zmm_mask_DST1, zmm2); + int dst_bytes = width * 3; + __mmask64 k0 = dst_bytes >= 64 ? ~0ull : (1ull << dst_bytes) - 1ull; + __mmask32 k1 = dst_bytes > 64 ? (1u << (dst_bytes - 64)) - 1u : 0u; + _mm512_mask_storeu_epi8(dst_rgb24, k0, zmm_dst0); + _mm256_mask_storeu_epi8(dst_rgb24 + 64, k1, + _mm512_castsi512_si256(zmm_dst1)); + } + _mm256_zeroupper(); +} +#endif // HAS_I444TORGB24ROW_AVX512VBMI + +#ifdef HAS_YUY2TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void YUY2ToARGBRow_AVX512BW(const uint8_t* yuy2_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + const __m512i zmm_shuf_y = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)kShuffleYUY2Y_Win)); + const __m512i zmm_shuf_uv = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)kShuffleYUY2UV_Win)); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m512i in = _mm512_loadu_si512((const __m512i*)yuy2_buf); + yuy2_buf += 64; + __m512i zmm4 = _mm512_shuffle_epi8(in, zmm_shuf_y); + __m512i zmm3 = _mm512_shuffle_epi8(in, zmm_shuf_uv); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k2 = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m512i in = _mm512_maskz_loadu_epi32(k2, yuy2_buf); + __m512i zmm4 = _mm512_shuffle_epi8(in, zmm_shuf_y); + __m512i zmm3 = _mm512_shuffle_epi8(in, zmm_shuf_uv); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_YUY2TOARGBROW_AVX512BW + +#ifdef HAS_UYVYTOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void UYVYToARGBRow_AVX512BW(const uint8_t* uyvy_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + const __m512i zmm_shuf_y = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)kShuffleUYVYY_Win)); + const __m512i zmm_shuf_uv = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)kShuffleUYVYUV_Win)); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m512i in = _mm512_loadu_si512((const __m512i*)uyvy_buf); + uyvy_buf += 64; + __m512i zmm4 = _mm512_shuffle_epi8(in, zmm_shuf_y); + __m512i zmm3 = _mm512_shuffle_epi8(in, zmm_shuf_uv); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k2 = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m512i in = _mm512_maskz_loadu_epi32(k2, uyvy_buf); + __m512i zmm4 = _mm512_shuffle_epi8(in, zmm_shuf_y); + __m512i zmm3 = _mm512_shuffle_epi8(in, zmm_shuf_uv); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_UYVYTOARGBROW_AVX512BW + +#ifdef HAS_I210TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I210ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_ExtWin); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m256i u_s = + _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)u_buf), 2); + __m256i v_s = + _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)v_buf), 2); + __m512i y16 = _mm512_loadu_si512((const __m512i*)y_buf); + u_buf += 16; + v_buf += 16; + y_buf += 32; + __m256i uv256 = _mm256_unpacklo_epi8(_mm256_packus_epi16(u_s, u_s), + _mm256_packus_epi16(v_s, v_s)); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m256i u_s = _mm256_srli_epi16(_mm256_maskz_loadu_epi16(k_uv, u_buf), 2); + __m256i v_s = _mm256_srli_epi16(_mm256_maskz_loadu_epi16(k_uv, v_buf), 2); + __m512i y16 = _mm512_maskz_loadu_epi16((__mmask32)m32, y_buf); + __m256i uv256 = _mm256_unpacklo_epi8(_mm256_packus_epi16(u_s, u_s), + _mm256_packus_epi16(v_s, v_s)); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_I210TOARGBROW_AVX512BW + +#ifdef HAS_I210TOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I210ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_ExtWin); + const __m512i zmm_perm0 = _mm512_loadu_si512((const __m512i*)kPermAR30_0_Win); + const __m512i zmm_perm1 = _mm512_loadu_si512((const __m512i*)kPermAR30_1_Win); + const __m512i zmm_zero = _mm512_setzero_si512(); + const __m512i zmm_3ff0 = _mm512_set1_epi16(0x3ff0); + const __m512i zmm_fc00 = _mm512_set1_epi16((short)0xfc00); + const __m512i zmm_c000 = _mm512_set1_epi16((short)0xc000); + while (width >= 32) { + __m256i u_s = + _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)u_buf), 2); + __m256i v_s = + _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)v_buf), 2); + __m512i y16 = _mm512_loadu_si512((const __m512i*)y_buf); + u_buf += 16; + v_buf += 16; + y_buf += 32; + __m256i uv256 = _mm256_unpacklo_epi8(_mm256_packus_epi16(u_s, u_s), + _mm256_packus_epi16(v_s, v_s)); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + YUVTORGB16_WIN_AVX512BW; + PACKAR30_WIN_AVX512BW(dst0, dst1); + _mm512_storeu_si512((__m512i*)dst_ar30, dst0); + _mm512_storeu_si512((__m512i*)(dst_ar30 + 64), dst1); + dst_ar30 += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m256i u_s = _mm256_srli_epi16(_mm256_maskz_loadu_epi16(k_uv, u_buf), 2); + __m256i v_s = _mm256_srli_epi16(_mm256_maskz_loadu_epi16(k_uv, v_buf), 2); + __m512i y16 = _mm512_maskz_loadu_epi16((__mmask32)m32, y_buf); + __m256i uv256 = _mm256_unpacklo_epi8(_mm256_packus_epi16(u_s, u_s), + _mm256_packus_epi16(v_s, v_s)); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + YUVTORGB16_WIN_AVX512BW; + PACKAR30_WIN_AVX512BW(dst0, dst1); + _mm512_mask_storeu_epi32(dst_ar30, (__mmask16)m32, dst0); + _mm512_mask_storeu_epi32(dst_ar30 + 64, (__mmask16)(m32 >> 16), dst1); + } + _mm256_zeroupper(); +} +#endif // HAS_I210TOAR30ROW_AVX512BW + +#ifdef HAS_I210ALPHATOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I210AlphaToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_ExtWin); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + while (width >= 32) { + __m256i u_s = + _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)u_buf), 2); + __m256i v_s = + _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)v_buf), 2); + __m512i y16 = _mm512_loadu_si512((const __m512i*)y_buf); + __m512i a16 = + _mm512_srli_epi16(_mm512_loadu_si512((const __m512i*)a_buf), 2); + u_buf += 16; + v_buf += 16; + y_buf += 32; + a_buf += 32; + __m256i uv256 = _mm256_unpacklo_epi8(_mm256_packus_epi16(u_s, u_s), + _mm256_packus_epi16(v_s, v_s)); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + __m512i zmm5 = _mm512_packus_epi16(a16, a16); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m256i u_s = _mm256_srli_epi16(_mm256_maskz_loadu_epi16(k_uv, u_buf), 2); + __m256i v_s = _mm256_srli_epi16(_mm256_maskz_loadu_epi16(k_uv, v_buf), 2); + __m512i y16 = _mm512_maskz_loadu_epi16((__mmask32)m32, y_buf); + __m512i a16 = + _mm512_srli_epi16(_mm512_maskz_loadu_epi16((__mmask32)m32, a_buf), 2); + __m256i uv256 = _mm256_unpacklo_epi8(_mm256_packus_epi16(u_s, u_s), + _mm256_packus_epi16(v_s, v_s)); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + __m512i zmm5 = _mm512_packus_epi16(a16, a16); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_I210ALPHATOARGBROW_AVX512BW + +#ifdef HAS_I212TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I212ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_ExtWin); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m256i u_s = + _mm256_srai_epi16(_mm256_loadu_si256((const __m256i*)u_buf), 4); + __m256i v_s = + _mm256_srai_epi16(_mm256_loadu_si256((const __m256i*)v_buf), 4); + __m512i y16 = _mm512_loadu_si512((const __m512i*)y_buf); + u_buf += 16; + v_buf += 16; + y_buf += 32; + __m256i uv256 = _mm256_unpacklo_epi8(_mm256_packus_epi16(u_s, u_s), + _mm256_packus_epi16(v_s, v_s)); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 4), _mm512_srli_epi16(y16, 8)); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m256i u_s = _mm256_srai_epi16(_mm256_maskz_loadu_epi16(k_uv, u_buf), 4); + __m256i v_s = _mm256_srai_epi16(_mm256_maskz_loadu_epi16(k_uv, v_buf), 4); + __m512i y16 = _mm512_maskz_loadu_epi16((__mmask32)m32, y_buf); + __m256i uv256 = _mm256_unpacklo_epi8(_mm256_packus_epi16(u_s, u_s), + _mm256_packus_epi16(v_s, v_s)); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 4), _mm512_srli_epi16(y16, 8)); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_I212TOARGBROW_AVX512BW + +#ifdef HAS_I212TOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I212ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_quad = + _mm512_loadu_si512((const __m512i*)kSplitQuadWords_ExtWin); + const __m512i zmm_perm0 = _mm512_loadu_si512((const __m512i*)kPermAR30_0_Win); + const __m512i zmm_perm1 = _mm512_loadu_si512((const __m512i*)kPermAR30_1_Win); + const __m512i zmm_zero = _mm512_setzero_si512(); + const __m512i zmm_3ff0 = _mm512_set1_epi16(0x3ff0); + const __m512i zmm_fc00 = _mm512_set1_epi16((short)0xfc00); + const __m512i zmm_c000 = _mm512_set1_epi16((short)0xc000); + while (width >= 32) { + __m256i u_s = + _mm256_srai_epi16(_mm256_loadu_si256((const __m256i*)u_buf), 4); + __m256i v_s = + _mm256_srai_epi16(_mm256_loadu_si256((const __m256i*)v_buf), 4); + __m512i y16 = _mm512_loadu_si512((const __m512i*)y_buf); + u_buf += 16; + v_buf += 16; + y_buf += 32; + __m256i uv256 = _mm256_unpacklo_epi8(_mm256_packus_epi16(u_s, u_s), + _mm256_packus_epi16(v_s, v_s)); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 4), _mm512_srli_epi16(y16, 8)); + YUVTORGB16_WIN_AVX512BW; + PACKAR30_WIN_AVX512BW(dst0, dst1); + _mm512_storeu_si512((__m512i*)dst_ar30, dst0); + _mm512_storeu_si512((__m512i*)(dst_ar30 + 64), dst1); + dst_ar30 += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m256i u_s = _mm256_srai_epi16(_mm256_maskz_loadu_epi16(k_uv, u_buf), 4); + __m256i v_s = _mm256_srai_epi16(_mm256_maskz_loadu_epi16(k_uv, v_buf), 4); + __m512i y16 = _mm512_maskz_loadu_epi16((__mmask32)m32, y_buf); + __m256i uv256 = _mm256_unpacklo_epi8(_mm256_packus_epi16(u_s, u_s), + _mm256_packus_epi16(v_s, v_s)); + __m512i zmm3 = PermutexvarEpi16(zmm_quad, _mm512_zextsi256_si512(uv256)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 4), _mm512_srli_epi16(y16, 8)); + YUVTORGB16_WIN_AVX512BW; + PACKAR30_WIN_AVX512BW(dst0, dst1); + _mm512_mask_storeu_epi32(dst_ar30, (__mmask16)m32, dst0); + _mm512_mask_storeu_epi32(dst_ar30 + 64, (__mmask16)(m32 >> 16), dst1); + } + _mm256_zeroupper(); +} +#endif // HAS_I212TOAR30ROW_AVX512BW + +#ifdef HAS_I410TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I410ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m512i u_s = + _mm512_srli_epi16(_mm512_loadu_si512((const __m512i*)u_buf), 2); + __m512i v_s = + _mm512_srli_epi16(_mm512_loadu_si512((const __m512i*)v_buf), 2); + __m512i y16 = _mm512_loadu_si512((const __m512i*)y_buf); + u_buf += 32; + v_buf += 32; + y_buf += 32; + __m512i zmm3 = _mm512_unpacklo_epi8(_mm512_packus_epi16(u_s, u_s), + _mm512_packus_epi16(v_s, v_s)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask32 k = (__mmask32)m32; + __m512i u_s = _mm512_srli_epi16(_mm512_maskz_loadu_epi16(k, u_buf), 2); + __m512i v_s = _mm512_srli_epi16(_mm512_maskz_loadu_epi16(k, v_buf), 2); + __m512i y16 = _mm512_maskz_loadu_epi16(k, y_buf); + __m512i zmm3 = _mm512_unpacklo_epi8(_mm512_packus_epi16(u_s, u_s), + _mm512_packus_epi16(v_s, v_s)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_I410TOARGBROW_AVX512BW + +#ifdef HAS_I410TOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I410ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_perm0 = _mm512_loadu_si512((const __m512i*)kPermAR30_0_Win); + const __m512i zmm_perm1 = _mm512_loadu_si512((const __m512i*)kPermAR30_1_Win); + const __m512i zmm_zero = _mm512_setzero_si512(); + const __m512i zmm_3ff0 = _mm512_set1_epi16(0x3ff0); + const __m512i zmm_fc00 = _mm512_set1_epi16((short)0xfc00); + const __m512i zmm_c000 = _mm512_set1_epi16((short)0xc000); + while (width >= 32) { + __m512i u_s = + _mm512_srli_epi16(_mm512_loadu_si512((const __m512i*)u_buf), 2); + __m512i v_s = + _mm512_srli_epi16(_mm512_loadu_si512((const __m512i*)v_buf), 2); + __m512i y16 = _mm512_loadu_si512((const __m512i*)y_buf); + u_buf += 32; + v_buf += 32; + y_buf += 32; + __m512i zmm3 = _mm512_unpacklo_epi8(_mm512_packus_epi16(u_s, u_s), + _mm512_packus_epi16(v_s, v_s)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + YUVTORGB16_WIN_AVX512BW; + PACKAR30_WIN_AVX512BW(dst0, dst1); + _mm512_storeu_si512((__m512i*)dst_ar30, dst0); + _mm512_storeu_si512((__m512i*)(dst_ar30 + 64), dst1); + dst_ar30 += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask32 k = (__mmask32)m32; + __m512i u_s = _mm512_srli_epi16(_mm512_maskz_loadu_epi16(k, u_buf), 2); + __m512i v_s = _mm512_srli_epi16(_mm512_maskz_loadu_epi16(k, v_buf), 2); + __m512i y16 = _mm512_maskz_loadu_epi16(k, y_buf); + __m512i zmm3 = _mm512_unpacklo_epi8(_mm512_packus_epi16(u_s, u_s), + _mm512_packus_epi16(v_s, v_s)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + YUVTORGB16_WIN_AVX512BW; + PACKAR30_WIN_AVX512BW(dst0, dst1); + _mm512_mask_storeu_epi32(dst_ar30, (__mmask16)m32, dst0); + _mm512_mask_storeu_epi32(dst_ar30 + 64, (__mmask16)(m32 >> 16), dst1); + } + _mm256_zeroupper(); +} +#endif // HAS_I410TOAR30ROW_AVX512BW + +#ifdef HAS_I410ALPHATOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void I410AlphaToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* u_buf, + const uint16_t* v_buf, + const uint16_t* a_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + while (width >= 32) { + __m512i u_s = + _mm512_srli_epi16(_mm512_loadu_si512((const __m512i*)u_buf), 2); + __m512i v_s = + _mm512_srli_epi16(_mm512_loadu_si512((const __m512i*)v_buf), 2); + __m512i y16 = _mm512_loadu_si512((const __m512i*)y_buf); + __m512i a16 = + _mm512_srli_epi16(_mm512_loadu_si512((const __m512i*)a_buf), 2); + u_buf += 32; + v_buf += 32; + y_buf += 32; + a_buf += 32; + __m512i zmm3 = _mm512_unpacklo_epi8(_mm512_packus_epi16(u_s, u_s), + _mm512_packus_epi16(v_s, v_s)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + __m512i zmm5 = _mm512_packus_epi16(a16, a16); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask32 k = (__mmask32)m32; + __m512i u_s = _mm512_srli_epi16(_mm512_maskz_loadu_epi16(k, u_buf), 2); + __m512i v_s = _mm512_srli_epi16(_mm512_maskz_loadu_epi16(k, v_buf), 2); + __m512i y16 = _mm512_maskz_loadu_epi16(k, y_buf); + __m512i a16 = _mm512_srli_epi16(_mm512_maskz_loadu_epi16(k, a_buf), 2); + __m512i zmm3 = _mm512_unpacklo_epi8(_mm512_packus_epi16(u_s, u_s), + _mm512_packus_epi16(v_s, v_s)); + __m512i zmm4 = + _mm512_or_si512(_mm512_slli_epi16(y16, 6), _mm512_srli_epi16(y16, 4)); + __m512i zmm5 = _mm512_packus_epi16(a16, a16); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_I410ALPHATOARGBROW_AVX512BW + +#ifdef HAS_P210TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void P210ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + const __m512i zmm_shuf_uv = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)kShuffleYUY2UV_Win)); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m512i zmm4 = _mm512_loadu_si512((const __m512i*)y_buf); + __m512i zmm3 = _mm512_shuffle_epi8( + _mm512_loadu_si512((const __m512i*)uv_buf), zmm_shuf_uv); + y_buf += 32; + uv_buf += 32; + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m512i zmm4 = _mm512_maskz_loadu_epi16((__mmask32)m32, y_buf); + __m512i zmm3 = _mm512_shuffle_epi8(_mm512_maskz_loadu_epi32(k_uv, uv_buf), + zmm_shuf_uv); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_P210TOARGBROW_AVX512BW + +#ifdef HAS_P210TOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void P210ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_perm0 = _mm512_loadu_si512((const __m512i*)kPermAR30_0_Win); + const __m512i zmm_perm1 = _mm512_loadu_si512((const __m512i*)kPermAR30_1_Win); + const __m512i zmm_shuf_uv = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)kShuffleYUY2UV_Win)); + const __m512i zmm_zero = _mm512_setzero_si512(); + const __m512i zmm_3ff0 = _mm512_set1_epi16(0x3ff0); + const __m512i zmm_fc00 = _mm512_set1_epi16((short)0xfc00); + const __m512i zmm_c000 = _mm512_set1_epi16((short)0xc000); + while (width >= 32) { + __m512i zmm4 = _mm512_loadu_si512((const __m512i*)y_buf); + __m512i zmm3 = _mm512_shuffle_epi8( + _mm512_loadu_si512((const __m512i*)uv_buf), zmm_shuf_uv); + y_buf += 32; + uv_buf += 32; + YUVTORGB16_WIN_AVX512BW; + PACKAR30_WIN_AVX512BW(dst0, dst1); + _mm512_storeu_si512((__m512i*)dst_ar30, dst0); + _mm512_storeu_si512((__m512i*)(dst_ar30 + 64), dst1); + dst_ar30 += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __mmask16 k_uv = (__mmask16)((1u << ((width + 1) >> 1)) - 1u); + __m512i zmm4 = _mm512_maskz_loadu_epi16((__mmask32)m32, y_buf); + __m512i zmm3 = _mm512_shuffle_epi8(_mm512_maskz_loadu_epi32(k_uv, uv_buf), + zmm_shuf_uv); + YUVTORGB16_WIN_AVX512BW; + PACKAR30_WIN_AVX512BW(dst0, dst1); + _mm512_mask_storeu_epi32(dst_ar30, (__mmask16)m32, dst0); + _mm512_mask_storeu_epi32(dst_ar30 + 64, (__mmask16)(m32 >> 16), dst1); + } + _mm256_zeroupper(); +} +#endif // HAS_P210TOAR30ROW_AVX512BW + +#ifdef HAS_P410TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void P410ToARGBRow_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_unperm = + _mm512_loadu_si512((const __m512i*)kUnpermuteAVX512_ExtWin); + const __m512i zmm5 = _mm512_set1_epi32(-1); + while (width >= 32) { + __m512i zmm4 = _mm512_loadu_si512((const __m512i*)y_buf); + __m512i uv0 = _mm512_loadu_si512((const __m512i*)uv_buf); + __m512i uv1 = _mm512_loadu_si512((const __m512i*)(uv_buf + 32)); + y_buf += 32; + uv_buf += 64; + __m256i lo = _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv0, 8)); + __m256i hi = _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv1, 8)); + __m512i zmm3 = _mm512_inserti64x4(_mm512_zextsi256_si512(lo), hi, 1); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_WIN_AVX512BW(dst_argb); + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __m512i zmm4 = _mm512_maskz_loadu_epi16((__mmask32)m32, y_buf); + __m512i uv0 = _mm512_maskz_loadu_epi32((__mmask16)m32, uv_buf); + __m512i uv1 = _mm512_maskz_loadu_epi32((__mmask16)(m32 >> 16), uv_buf + 32); + __m256i lo = _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv0, 8)); + __m256i hi = _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv1, 8)); + __m512i zmm3 = _mm512_inserti64x4(_mm512_zextsi256_si512(lo), hi, 1); + YUVTORGB8_WIN_AVX512BW; + STOREARGB_MASK_WIN_AVX512BW(dst_argb, m32); + } + _mm256_zeroupper(); +} +#endif // HAS_P410TOARGBROW_AVX512BW + +#ifdef HAS_P410TOAR30ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void P410ToAR30Row_AVX512BW(const uint16_t* y_buf, + const uint16_t* uv_buf, + uint8_t* dst_ar30, + const struct YuvConstants* yuvconstants, + int width) { + YUVTORGB_SETUP_WIN_AVX512BW(yuvconstants); + const __m512i zmm_perm0 = _mm512_loadu_si512((const __m512i*)kPermAR30_0_Win); + const __m512i zmm_perm1 = _mm512_loadu_si512((const __m512i*)kPermAR30_1_Win); + const __m512i zmm_zero = _mm512_setzero_si512(); + const __m512i zmm_3ff0 = _mm512_set1_epi16(0x3ff0); + const __m512i zmm_fc00 = _mm512_set1_epi16((short)0xfc00); + const __m512i zmm_c000 = _mm512_set1_epi16((short)0xc000); + while (width >= 32) { + __m512i zmm4 = _mm512_loadu_si512((const __m512i*)y_buf); + __m512i uv0 = _mm512_loadu_si512((const __m512i*)uv_buf); + __m512i uv1 = _mm512_loadu_si512((const __m512i*)(uv_buf + 32)); + y_buf += 32; + uv_buf += 64; + __m256i lo = _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv0, 8)); + __m256i hi = _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv1, 8)); + __m512i zmm3 = _mm512_inserti64x4(_mm512_zextsi256_si512(lo), hi, 1); + YUVTORGB16_WIN_AVX512BW; + PACKAR30_WIN_AVX512BW(dst0, dst1); + _mm512_storeu_si512((__m512i*)dst_ar30, dst0); + _mm512_storeu_si512((__m512i*)(dst_ar30 + 64), dst1); + dst_ar30 += 128; + width -= 32; + } + if (width > 0) { + uint32_t m32 = (1u << width) - 1u; + __m512i zmm4 = _mm512_maskz_loadu_epi16((__mmask32)m32, y_buf); + __m512i uv0 = _mm512_maskz_loadu_epi32((__mmask16)m32, uv_buf); + __m512i uv1 = _mm512_maskz_loadu_epi32((__mmask16)(m32 >> 16), uv_buf + 32); + __m256i lo = _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv0, 8)); + __m256i hi = _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv1, 8)); + __m512i zmm3 = _mm512_inserti64x4(_mm512_zextsi256_si512(lo), hi, 1); + YUVTORGB16_WIN_AVX512BW; + PACKAR30_WIN_AVX512BW(dst0, dst1); + _mm512_mask_storeu_epi32(dst_ar30, (__mmask16)m32, dst0); + _mm512_mask_storeu_epi32(dst_ar30 + 64, (__mmask16)(m32 >> 16), dst1); + } + _mm256_zeroupper(); +} +#endif // HAS_P410TOAR30ROW_AVX512BW + +#if defined(HAS_ARGBTORGB24ROW_AVX512BW) || defined(HAS_ARGBTORAWROW_AVX512BW) +LIBYUV_TARGET_AVX512BW +static inline void ARGBToRGBRow_AVX512BW(const uint8_t* src, + uint8_t* dst, int width, - uint32_t value) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // width - movd xmm2, [esp + 16] // value - punpcklbw xmm2, xmm2 - punpcklqdq xmm2, xmm2 + const uint8_t* shuffler) { + const __m512i zmm_shuf = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)shuffler)); + const __m512i zmm_p0 = + _mm512_loadu_si512((const __m512i*)kPermdRGB24_0_AVX512BW); + const __m512i zmm_p1 = + _mm512_loadu_si512((const __m512i*)kPermdRGB24_1_AVX512BW); + const __m512i zmm_p2 = + _mm512_loadu_si512((const __m512i*)kPermdRGB24_2_AVX512BW); - convertloop: - movdqu xmm0, [eax] // read 4 pixels - lea eax, [eax + 16] - movdqa xmm1, xmm0 - punpcklbw xmm0, xmm0 // first 2 - punpckhbw xmm1, xmm1 // next 2 - pmulhuw xmm0, xmm2 // argb * value - pmulhuw xmm1, xmm2 // argb * value - psrlw xmm0, 8 - psrlw xmm1, 8 - packuswb xmm0, xmm1 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jg convertloop + while (width >= 64) { + __m512i zmm0 = _mm512_loadu_si512((const __m512i*)src); + __m512i zmm1 = _mm512_loadu_si512((const __m512i*)(src + 64)); + __m512i zmm2 = _mm512_loadu_si512((const __m512i*)(src + 128)); + __m512i zmm3 = _mm512_loadu_si512((const __m512i*)(src + 192)); + src += 256; - ret + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + __m512i out0 = _mm512_permutex2var_epi32(zmm0, zmm_p0, zmm1); + __m512i out1 = _mm512_permutex2var_epi32(zmm1, zmm_p1, zmm2); + __m512i out2 = _mm512_permutex2var_epi32(zmm2, zmm_p2, zmm3); + + _mm512_storeu_si512((__m512i*)dst, out0); + _mm512_storeu_si512((__m512i*)(dst + 64), out1); + _mm512_storeu_si512((__m512i*)(dst + 128), out2); + dst += 192; + width -= 64; + } + + if (width > 0) { + uint64_t m_in = (1ULL << width) - 1ULL; + __m512i zmm0 = _mm512_maskz_loadu_epi32((__mmask16)m_in, src); + __m512i zmm1 = _mm512_maskz_loadu_epi32((__mmask16)(m_in >> 16), src + 64); + __m512i zmm2 = _mm512_maskz_loadu_epi32((__mmask16)(m_in >> 32), src + 128); + __m512i zmm3 = _mm512_maskz_loadu_epi32((__mmask16)(m_in >> 48), src + 192); + + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + __m512i out0 = _mm512_permutex2var_epi32(zmm0, zmm_p0, zmm1); + __m512i out1 = _mm512_permutex2var_epi32(zmm1, zmm_p1, zmm2); + __m512i out2 = _mm512_permutex2var_epi32(zmm2, zmm_p2, zmm3); + + int bytes = width * 3; + __mmask64 k_out0 = + (bytes >= 64) ? ~(__mmask64)0 : (__mmask64)((1ULL << bytes) - 1ULL); + __mmask64 k_out1 = + (bytes <= 64) + ? 0 + : ((bytes >= 128) ? ~(__mmask64)0 + : (__mmask64)((1ULL << (bytes - 64)) - 1ULL)); + __mmask64 k_out2 = + (bytes <= 128) ? 0 : (__mmask64)((1ULL << (bytes - 128)) - 1ULL); + + _mm512_mask_storeu_epi8(dst, k_out0, out0); + _mm512_mask_storeu_epi8(dst + 64, k_out1, out1); + _mm512_mask_storeu_epi8(dst + 128, k_out2, out2); + } + _mm256_zeroupper(); +} +#endif // defined(HAS_ARGBTORGB24ROW_AVX512BW) || + // defined(HAS_ARGBTORAWROW_AVX512BW) + +#ifdef HAS_ARGBTORGB24ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToRGB24Row_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + ARGBToRGBRow_AVX512BW(src, dst, width, kShuffleMaskARGBToRGB24[0]); +} +#endif // HAS_ARGBTORGB24ROW_AVX512BW + +#ifdef HAS_ARGBTORAWROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToRAWRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + static const uint8_t kShuffleMaskARGBToRAW_AVX512[16] = { + 2u, 1u, 0u, 6u, 5u, 4u, 10u, 9u, 8u, 14u, 13u, 12u, 128u, 128u, 128u, + 128u}; + ARGBToRGBRow_AVX512BW(src, dst, width, kShuffleMaskARGBToRAW_AVX512); +} +#endif // HAS_ARGBTORAWROW_AVX512BW + +#ifdef HAS_CONVERT16TO8ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void Convert16To8Row_AVX512BW(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width) { + const __m512i zmm_scale = _mm512_set1_epi16((short)scale); + const __m512i zmm_255 = _mm512_set1_epi16(255); + while (width >= 64) { + __m512i y0 = _mm512_loadu_si512((const __m512i*)src_y); + __m512i y1 = _mm512_loadu_si512((const __m512i*)(src_y + 32)); + y0 = _mm512_min_epu16(_mm512_mulhi_epu16(y0, zmm_scale), zmm_255); + y1 = _mm512_min_epu16(_mm512_mulhi_epu16(y1, zmm_scale), zmm_255); + _mm256_storeu_si256((__m256i*)dst_y, _mm512_cvtepi16_epi8(y0)); + _mm256_storeu_si256((__m256i*)(dst_y + 32), _mm512_cvtepi16_epi8(y1)); + src_y += 64; + dst_y += 64; + width -= 64; + } + if (width >= 32) { + __m512i y0 = _mm512_loadu_si512((const __m512i*)src_y); + y0 = _mm512_min_epu16(_mm512_mulhi_epu16(y0, zmm_scale), zmm_255); + _mm256_storeu_si256((__m256i*)dst_y, _mm512_cvtepi16_epi8(y0)); + src_y += 32; + dst_y += 32; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i y0 = _mm512_maskz_loadu_epi16(k, src_y); + y0 = _mm512_min_epu16(_mm512_mulhi_epu16(y0, zmm_scale), zmm_255); + _mm256_mask_storeu_epi8(dst_y, k, _mm512_cvtepi16_epi8(y0)); + } + _mm256_zeroupper(); +} +#endif // HAS_CONVERT16TO8ROW_AVX512BW + +#ifdef HAS_COPYROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void CopyRow_AVX512BW(const uint8_t* src, uint8_t* dst, int width) { + while (width >= 128) { + __m512i z0 = _mm512_loadu_si512((const __m512i*)src); + __m512i z1 = _mm512_loadu_si512((const __m512i*)(src + 64)); + _mm512_storeu_si512((__m512i*)dst, z0); + _mm512_storeu_si512((__m512i*)(dst + 64), z1); + src += 128; + dst += 128; + width -= 128; + } + if (width >= 64) { + __m512i z0 = _mm512_loadu_si512((const __m512i*)src); + _mm512_storeu_si512((__m512i*)dst, z0); + src += 64; + dst += 64; + width -= 64; + } + if (width > 0) { + __mmask64 k = (__mmask64)((1ULL << width) - 1ULL); + __m512i z0 = _mm512_maskz_loadu_epi8(k, src); + _mm512_mask_storeu_epi8(dst, k, z0); + } + _mm256_zeroupper(); +} +#endif // HAS_COPYROW_AVX512BW + +#ifdef HAS_HALFROW_16TO8_AVX512BW +LIBYUV_TARGET_AVX512BW +void HalfRow_16To8_AVX512BW(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const __m512i zmm_scale = _mm512_set1_epi16((short)scale); + const __m512i zmm_255 = _mm512_set1_epi16(255); + while (width >= 64) { + __m512i r0 = _mm512_loadu_si512((const __m512i*)src_uv); + __m512i r1 = _mm512_loadu_si512((const __m512i*)(src_uv + 32)); + __m512i s0 = _mm512_loadu_si512((const __m512i*)(src_uv + src_uv_stride)); + __m512i s1 = + _mm512_loadu_si512((const __m512i*)(src_uv + src_uv_stride + 32)); + r0 = _mm512_avg_epu16(r0, s0); + r1 = _mm512_avg_epu16(r1, s1); + r0 = _mm512_min_epu16(_mm512_mulhi_epu16(r0, zmm_scale), zmm_255); + r1 = _mm512_min_epu16(_mm512_mulhi_epu16(r1, zmm_scale), zmm_255); + _mm256_storeu_si256((__m256i*)dst_uv, _mm512_cvtepi16_epi8(r0)); + _mm256_storeu_si256((__m256i*)(dst_uv + 32), _mm512_cvtepi16_epi8(r1)); + src_uv += 64; + dst_uv += 64; + width -= 64; + } + if (width > 0) { + uint64_t mask = (1ULL << width) - 1ULL; + __mmask32 k1 = (__mmask32)mask; + __mmask32 k2 = (__mmask32)(mask >> 32); + __m512i r0 = _mm512_maskz_loadu_epi16(k1, src_uv); + __m512i r1 = _mm512_maskz_loadu_epi16(k2, src_uv + 32); + __m512i s0 = _mm512_maskz_loadu_epi16(k1, src_uv + src_uv_stride); + __m512i s1 = _mm512_maskz_loadu_epi16(k2, src_uv + src_uv_stride + 32); + r0 = _mm512_avg_epu16(r0, s0); + r1 = _mm512_avg_epu16(r1, s1); + r0 = _mm512_min_epu16(_mm512_mulhi_epu16(r0, zmm_scale), zmm_255); + r1 = _mm512_min_epu16(_mm512_mulhi_epu16(r1, zmm_scale), zmm_255); + _mm256_mask_storeu_epi8(dst_uv, k1, _mm512_cvtepi16_epi8(r0)); + _mm256_mask_storeu_epi8(dst_uv + 32, k2, _mm512_cvtepi16_epi8(r1)); + } + _mm256_zeroupper(); +} +#endif // HAS_HALFROW_16TO8_AVX512BW + +#ifdef HAS_HALFWIDTHROW_16TO8_AVX512BW +LIBYUV_TARGET_AVX512BW +void HalfWidthRow_16To8_AVX512BW(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const __m512i zmm_mask16 = _mm512_set1_epi32(0x0000ffff); + const __m512i zmm_2 = _mm512_set1_epi32(2); + const __m512i zmm_scale = _mm512_set1_epi16((short)scale); + const __m512i zmm_255 = _mm512_set1_epi16(255); + while (width >= 32) { + __m512i s0 = _mm512_loadu_si512((const __m512i*)src_uv); + __m512i s1 = _mm512_loadu_si512((const __m512i*)(src_uv + 32)); + __m512i t0 = _mm512_loadu_si512((const __m512i*)(src_uv + src_uv_stride)); + __m512i t1 = + _mm512_loadu_si512((const __m512i*)(src_uv + src_uv_stride + 32)); + __m512i sum0 = _mm512_add_epi32(_mm512_and_si512(s0, zmm_mask16), + _mm512_srli_epi32(s0, 16)); + sum0 = _mm512_add_epi32(sum0, _mm512_and_si512(t0, zmm_mask16)); + sum0 = _mm512_add_epi32(sum0, _mm512_srli_epi32(t0, 16)); + sum0 = _mm512_srli_epi32(_mm512_add_epi32(sum0, zmm_2), 2); + + __m512i sum1 = _mm512_add_epi32(_mm512_and_si512(s1, zmm_mask16), + _mm512_srli_epi32(s1, 16)); + sum1 = _mm512_add_epi32(sum1, _mm512_and_si512(t1, zmm_mask16)); + sum1 = _mm512_add_epi32(sum1, _mm512_srli_epi32(t1, 16)); + sum1 = _mm512_srli_epi32(_mm512_add_epi32(sum1, zmm_2), 2); + + __m512i avg16 = + _mm512_inserti64x4(_mm512_zextsi256_si512(_mm512_cvtepi32_epi16(sum0)), + _mm512_cvtepi32_epi16(sum1), 1); + avg16 = _mm512_min_epu16(_mm512_mulhi_epu16(avg16, zmm_scale), zmm_255); + _mm256_storeu_si256((__m256i*)dst_uv, _mm512_cvtepi16_epi8(avg16)); + src_uv += 64; + dst_uv += 32; + width -= 32; + } + if (width > 0) { + uint32_t mask = (1u << width) - 1u; + __mmask16 k1 = (__mmask16)mask; + __mmask16 k2 = (__mmask16)(mask >> 16); + __mmask32 k3 = (__mmask32)mask; + __m512i s0 = _mm512_maskz_loadu_epi32(k1, src_uv); + __m512i s1 = _mm512_maskz_loadu_epi32(k2, src_uv + 32); + __m512i t0 = _mm512_maskz_loadu_epi32(k1, src_uv + src_uv_stride); + __m512i t1 = _mm512_maskz_loadu_epi32(k2, src_uv + src_uv_stride + 32); + __m512i sum0 = _mm512_add_epi32(_mm512_and_si512(s0, zmm_mask16), + _mm512_srli_epi32(s0, 16)); + sum0 = _mm512_add_epi32(sum0, _mm512_and_si512(t0, zmm_mask16)); + sum0 = _mm512_add_epi32(sum0, _mm512_srli_epi32(t0, 16)); + sum0 = _mm512_srli_epi32(_mm512_add_epi32(sum0, zmm_2), 2); + + __m512i sum1 = _mm512_add_epi32(_mm512_and_si512(s1, zmm_mask16), + _mm512_srli_epi32(s1, 16)); + sum1 = _mm512_add_epi32(sum1, _mm512_and_si512(t1, zmm_mask16)); + sum1 = _mm512_add_epi32(sum1, _mm512_srli_epi32(t1, 16)); + sum1 = _mm512_srli_epi32(_mm512_add_epi32(sum1, zmm_2), 2); + + __m512i avg16 = + _mm512_inserti64x4(_mm512_zextsi256_si512(_mm512_cvtepi32_epi16(sum0)), + _mm512_cvtepi32_epi16(sum1), 1); + avg16 = _mm512_min_epu16(_mm512_mulhi_epu16(avg16, zmm_scale), zmm_255); + _mm256_mask_storeu_epi8(dst_uv, k3, _mm512_cvtepi16_epi8(avg16)); + } + _mm256_zeroupper(); +} +#endif // HAS_HALFWIDTHROW_16TO8_AVX512BW + +#ifdef HAS_SPLITUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void SplitUVRow_AVX512BW(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + while (width >= 64) { + __m512i uv0 = _mm512_loadu_si512((const __m512i*)src_uv); + __m512i uv1 = _mm512_loadu_si512((const __m512i*)(src_uv + 64)); + _mm256_storeu_si256((__m256i*)dst_u, _mm512_cvtepi16_epi8(uv0)); + _mm256_storeu_si256((__m256i*)(dst_u + 32), _mm512_cvtepi16_epi8(uv1)); + _mm256_storeu_si256((__m256i*)dst_v, + _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv0, 8))); + _mm256_storeu_si256((__m256i*)(dst_v + 32), + _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv1, 8))); + src_uv += 128; + dst_u += 64; + dst_v += 64; + width -= 64; + } + if (width > 0) { + uint64_t mask = (1ULL << width) - 1ULL; + __mmask32 k0 = (__mmask32)mask; + __mmask32 k1 = (__mmask32)(mask >> 32); + __m512i uv0 = _mm512_maskz_loadu_epi16(k0, src_uv); + _mm256_mask_storeu_epi8(dst_u, k0, _mm512_cvtepi16_epi8(uv0)); + _mm256_mask_storeu_epi8(dst_v, k0, + _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv0, 8))); + if (k1) { + __m512i uv1 = _mm512_maskz_loadu_epi16(k1, src_uv + 64); + _mm256_mask_storeu_epi8(dst_u + 32, k1, _mm512_cvtepi16_epi8(uv1)); + _mm256_mask_storeu_epi8(dst_v + 32, k1, + _mm512_cvtepi16_epi8(_mm512_srli_epi16(uv1, 8))); + } + } + _mm256_zeroupper(); +} +#endif // HAS_SPLITUVROW_AVX512BW + +#ifdef HAS_CONVERT8TO16ROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void Convert8To16Row_AVX512BW(const uint8_t* src_y, + uint16_t* dst_y, + int bits, + int width) { + const __m128i shift128 = _mm_cvtsi32_si128(16 - bits); + while (width >= 64) { + __m256i y0_8 = _mm256_loadu_si256((const __m256i*)src_y); + __m256i y1_8 = _mm256_loadu_si256((const __m256i*)(src_y + 32)); + __m512i y0 = _mm512_cvtepu8_epi16(y0_8); + __m512i y1 = _mm512_cvtepu8_epi16(y1_8); + y0 = _mm512_srl_epi16(_mm512_or_si512(y0, _mm512_slli_epi16(y0, 8)), + shift128); + y1 = _mm512_srl_epi16(_mm512_or_si512(y1, _mm512_slli_epi16(y1, 8)), + shift128); + _mm512_storeu_si512((__m512i*)dst_y, y0); + _mm512_storeu_si512((__m512i*)(dst_y + 32), y1); + src_y += 64; + dst_y += 64; + width -= 64; + } + if (width >= 32) { + __m256i y0_8 = _mm256_loadu_si256((const __m256i*)src_y); + __m512i y0 = _mm512_cvtepu8_epi16(y0_8); + y0 = _mm512_srl_epi16(_mm512_or_si512(y0, _mm512_slli_epi16(y0, 8)), + shift128); + _mm512_storeu_si512((__m512i*)dst_y, y0); + src_y += 32; + dst_y += 32; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i y0 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, src_y)); + y0 = _mm512_srl_epi16(_mm512_or_si512(y0, _mm512_slli_epi16(y0, 8)), + shift128); + _mm512_mask_storeu_epi16(dst_y, k, y0); + } + _mm256_zeroupper(); +} +#endif // HAS_CONVERT8TO16ROW_AVX512BW + +#ifdef HAS_J400TOARGBROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void J400ToARGBRow_AVX512BW(const uint8_t* src_y, + uint8_t* dst_argb, + int width) { + static const uint8_t kShuffleMaskJ400ToARGB_AVX512[64] = { + 0u, 0u, 0u, 128u, 1u, 1u, 1u, 128u, 2u, 2u, 2u, 128u, 3u, + 3u, 3u, 128u, 4u, 4u, 4u, 128u, 5u, 5u, 5u, 128u, 6u, 6u, + 6u, 128u, 7u, 7u, 7u, 128u, 8u, 8u, 8u, 128u, 9u, 9u, 9u, + 128u, 10u, 10u, 10u, 128u, 11u, 11u, 11u, 128u, 12u, 12u, 12u, 128u, + 13u, 13u, 13u, 128u, 14u, 14u, 14u, 128u, 15u, 15u, 15u, 128u}; + const __m512i zmm_mask = + _mm512_loadu_si512((const __m512i*)kShuffleMaskJ400ToARGB_AVX512); + const __m512i zmm_alpha = _mm512_set1_epi32((int)0xff000000u); + while (width >= 32) { + __m512i z0 = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)src_y)); + __m512i z1 = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)(src_y + 16))); + z0 = _mm512_or_si512(_mm512_shuffle_epi8(z0, zmm_mask), zmm_alpha); + z1 = _mm512_or_si512(_mm512_shuffle_epi8(z1, zmm_mask), zmm_alpha); + _mm512_storeu_si512((__m512i*)dst_argb, z0); + _mm512_storeu_si512((__m512i*)(dst_argb + 64), z1); + src_y += 32; + dst_argb += 128; + width -= 32; + } + if (width > 0) { + uint32_t mask = (1u << width) - 1u; + __mmask16 k0 = (__mmask16)mask; + __mmask16 k1 = (__mmask16)(mask >> 16); + __m512i z0 = _mm512_broadcast_i32x4(_mm_maskz_loadu_epi8(k0, src_y)); + z0 = _mm512_or_si512(_mm512_shuffle_epi8(z0, zmm_mask), zmm_alpha); + _mm512_mask_storeu_epi32(dst_argb, k0, z0); + if (k1) { + __m512i z1 = _mm512_broadcast_i32x4(_mm_maskz_loadu_epi8(k1, src_y + 16)); + z1 = _mm512_or_si512(_mm512_shuffle_epi8(z1, zmm_mask), zmm_alpha); + _mm512_mask_storeu_epi32(dst_argb + 64, k1, z1); + } + } + _mm256_zeroupper(); +} +#endif // HAS_J400TOARGBROW_AVX512BW + +#ifdef HAS_MERGEUVROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void MergeUVRow_AVX512BW(const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uv, + int width) { + while (width >= 32) { + __m512i u16 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)src_u)); + __m512i v16 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)src_v)); + __m512i uv = _mm512_or_si512(u16, _mm512_slli_epi16(v16, 8)); + _mm512_storeu_si512((__m512i*)dst_uv, uv); + src_u += 32; + src_v += 32; + dst_uv += 64; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i u16 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, src_u)); + __m512i v16 = _mm512_cvtepu8_epi16(_mm256_maskz_loadu_epi8(k, src_v)); + __m512i uv = _mm512_or_si512(u16, _mm512_slli_epi16(v16, 8)); + _mm512_mask_storeu_epi16(dst_uv, k, uv); + } + _mm256_zeroupper(); +} +#endif // HAS_MERGEUVROW_AVX512BW + +#ifdef HAS_MULTIPLYROW_16_AVX512BW +LIBYUV_TARGET_AVX512BW +void MultiplyRow_16_AVX512BW(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + const __m512i zmm_scale = _mm512_set1_epi16((short)scale); + while (width >= 64) { + __m512i z0 = _mm512_loadu_si512((const __m512i*)src_y); + __m512i z1 = _mm512_loadu_si512((const __m512i*)(src_y + 32)); + z0 = _mm512_mullo_epi16(z0, zmm_scale); + z1 = _mm512_mullo_epi16(z1, zmm_scale); + _mm512_storeu_si512((__m512i*)dst_y, z0); + _mm512_storeu_si512((__m512i*)(dst_y + 32), z1); + src_y += 64; + dst_y += 64; + width -= 64; + } + if (width >= 32) { + __m512i z0 = _mm512_loadu_si512((const __m512i*)src_y); + z0 = _mm512_mullo_epi16(z0, zmm_scale); + _mm512_storeu_si512((__m512i*)dst_y, z0); + src_y += 32; + dst_y += 32; + width -= 32; + } + if (width > 0) { + __mmask32 k = (__mmask32)((1u << width) - 1u); + __m512i z0 = _mm512_maskz_loadu_epi16(k, src_y); + z0 = _mm512_mullo_epi16(z0, zmm_scale); + _mm512_mask_storeu_epi16(dst_y, k, z0); + } + _mm256_zeroupper(); +} +#endif // HAS_MULTIPLYROW_16_AVX512BW + +#ifdef HAS_ARGBTOYMATRIXROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToYMatrixRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_y, + int width, + const struct ArgbConstants* c) { + const __m512i zmm_perm_y = + _mm512_loadu_si512((const __m512i*)kPermdARGBToY_AVX512BW); + const __m512i zmm_80 = _mm512_set1_epi8((char)0x80); + const __m512i zmm_one = _mm512_set1_epi16(1); + const __m512i zmm_coeff = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToY)); + __m512i zmm_add = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kAddY)); + + __m512i zmm_bias = _mm512_maddubs_epi16(zmm_coeff, zmm_80); + zmm_bias = _mm512_madd_epi16(zmm_bias, zmm_one); + zmm_bias = _mm512_packs_epi32(zmm_bias, zmm_bias); + zmm_add = _mm512_sub_epi16(zmm_add, zmm_bias); + + while (width >= 64) { + __m512i zmm0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i zmm1 = _mm512_loadu_si512((const __m512i*)(src_argb + 64)); + __m512i zmm2 = _mm512_loadu_si512((const __m512i*)(src_argb + 128)); + __m512i zmm3 = _mm512_loadu_si512((const __m512i*)(src_argb + 192)); + + zmm0 = _mm512_xor_si512(zmm0, zmm_80); + zmm1 = _mm512_xor_si512(zmm1, zmm_80); + zmm2 = _mm512_xor_si512(zmm2, zmm_80); + zmm3 = _mm512_xor_si512(zmm3, zmm_80); + + zmm0 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm0), zmm_one); + zmm1 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm1), zmm_one); + zmm0 = _mm512_packs_epi32(zmm0, zmm1); + + zmm2 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm2), zmm_one); + zmm3 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm3), zmm_one); + zmm2 = _mm512_packs_epi32(zmm2, zmm3); + + zmm0 = _mm512_srli_epi16(_mm512_add_epi16(zmm0, zmm_add), 8); + zmm2 = _mm512_srli_epi16(_mm512_add_epi16(zmm2, zmm_add), 8); + + zmm0 = PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(zmm0, zmm2)); + _mm512_storeu_si512((__m512i*)dst_y, zmm0); + + src_argb += 256; + dst_y += 64; + width -= 64; + } + if (width > 0) { + uint64_t mask = (1ULL << width) - 1ULL; + __mmask16 k0 = (__mmask16)mask; + __mmask16 k1 = (__mmask16)(mask >> 16); + __mmask16 k2 = (__mmask16)(mask >> 32); + __mmask16 k3 = (__mmask16)(mask >> 48); + __m512i zmm0 = + _mm512_xor_si512(_mm512_maskz_loadu_epi32(k0, src_argb), zmm_80); + __m512i zmm1 = + _mm512_xor_si512(k1 ? _mm512_maskz_loadu_epi32(k1, src_argb + 64) + : _mm512_setzero_si512(), + zmm_80); + __m512i zmm2 = + _mm512_xor_si512(k2 ? _mm512_maskz_loadu_epi32(k2, src_argb + 128) + : _mm512_setzero_si512(), + zmm_80); + __m512i zmm3 = + _mm512_xor_si512(k3 ? _mm512_maskz_loadu_epi32(k3, src_argb + 192) + : _mm512_setzero_si512(), + zmm_80); + + zmm0 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm0), zmm_one); + zmm1 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm1), zmm_one); + zmm0 = _mm512_packs_epi32(zmm0, zmm1); + + zmm2 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm2), zmm_one); + zmm3 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm_coeff, zmm3), zmm_one); + zmm2 = _mm512_packs_epi32(zmm2, zmm3); + + zmm0 = _mm512_srli_epi16(_mm512_add_epi16(zmm0, zmm_add), 8); + zmm2 = _mm512_srli_epi16(_mm512_add_epi16(zmm2, zmm_add), 8); + + zmm0 = PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(zmm0, zmm2)); + _mm512_mask_storeu_epi8(dst_y, (__mmask64)mask, zmm0); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOYMATRIXROW_AVX512BW + +#ifdef HAS_ARGBTOUV444MATRIXROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToUV444MatrixRow_AVX512BW(const uint8_t* src_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + const __m512i zmm_u = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToU)); + const __m512i zmm_v = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToV)); + const __m512i zmm_one = _mm512_set1_epi16(1); + const __m512i zmm_8000 = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kAddUV)); + const __m512i zmm_perm_y = + _mm512_loadu_si512((const __m512i*)kPermdARGBToY_AVX512BW); + + while (width >= 64) { + __m512i s0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i s1 = _mm512_loadu_si512((const __m512i*)(src_argb + 64)); + __m512i s2 = _mm512_loadu_si512((const __m512i*)(src_argb + 128)); + __m512i s3 = _mm512_loadu_si512((const __m512i*)(src_argb + 192)); + + __m512i u0 = _mm512_madd_epi16(_mm512_maddubs_epi16(s0, zmm_u), zmm_one); + __m512i u1 = _mm512_madd_epi16(_mm512_maddubs_epi16(s1, zmm_u), zmm_one); + __m512i u2 = _mm512_madd_epi16(_mm512_maddubs_epi16(s2, zmm_u), zmm_one); + __m512i u3 = _mm512_madd_epi16(_mm512_maddubs_epi16(s3, zmm_u), zmm_one); + __m512i u01 = + _mm512_srli_epi16(_mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(u0, u1)), + 8); + __m512i u23 = + _mm512_srli_epi16(_mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(u2, u3)), + 8); + _mm512_storeu_si512( + (__m512i*)dst_u, + PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(u01, u23))); + + __m512i v0 = _mm512_madd_epi16(_mm512_maddubs_epi16(s0, zmm_v), zmm_one); + __m512i v1 = _mm512_madd_epi16(_mm512_maddubs_epi16(s1, zmm_v), zmm_one); + __m512i v2 = _mm512_madd_epi16(_mm512_maddubs_epi16(s2, zmm_v), zmm_one); + __m512i v3 = _mm512_madd_epi16(_mm512_maddubs_epi16(s3, zmm_v), zmm_one); + __m512i v01 = + _mm512_srli_epi16(_mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(v0, v1)), + 8); + __m512i v23 = + _mm512_srli_epi16(_mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(v2, v3)), + 8); + _mm512_storeu_si512( + (__m512i*)dst_v, + PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(v01, v23))); + + src_argb += 256; + dst_u += 64; + dst_v += 64; + width -= 64; + } + if (width > 0) { + uint64_t mask = (1ULL << width) - 1ULL; + __mmask16 k0 = (__mmask16)mask; + __mmask16 k1 = (__mmask16)(mask >> 16); + __mmask16 k2 = (__mmask16)(mask >> 32); + __mmask16 k3 = (__mmask16)(mask >> 48); + __m512i s0 = _mm512_maskz_loadu_epi32(k0, src_argb); + __m512i s1 = k1 ? _mm512_maskz_loadu_epi32(k1, src_argb + 64) + : _mm512_setzero_si512(); + __m512i s2 = k2 ? _mm512_maskz_loadu_epi32(k2, src_argb + 128) + : _mm512_setzero_si512(); + __m512i s3 = k3 ? _mm512_maskz_loadu_epi32(k3, src_argb + 192) + : _mm512_setzero_si512(); + + __m512i u0 = _mm512_madd_epi16(_mm512_maddubs_epi16(s0, zmm_u), zmm_one); + __m512i u1 = _mm512_madd_epi16(_mm512_maddubs_epi16(s1, zmm_u), zmm_one); + __m512i u2 = _mm512_madd_epi16(_mm512_maddubs_epi16(s2, zmm_u), zmm_one); + __m512i u3 = _mm512_madd_epi16(_mm512_maddubs_epi16(s3, zmm_u), zmm_one); + __m512i u01 = _mm512_srli_epi16( + _mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(u0, u1)), 8); + __m512i u23 = _mm512_srli_epi16( + _mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(u2, u3)), 8); + _mm512_mask_storeu_epi8( + dst_u, (__mmask64)mask, + PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(u01, u23))); + + __m512i v0 = _mm512_madd_epi16(_mm512_maddubs_epi16(s0, zmm_v), zmm_one); + __m512i v1 = _mm512_madd_epi16(_mm512_maddubs_epi16(s1, zmm_v), zmm_one); + __m512i v2 = _mm512_madd_epi16(_mm512_maddubs_epi16(s2, zmm_v), zmm_one); + __m512i v3 = _mm512_madd_epi16(_mm512_maddubs_epi16(s3, zmm_v), zmm_one); + __m512i v01 = _mm512_srli_epi16( + _mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(v0, v1)), 8); + __m512i v23 = _mm512_srli_epi16( + _mm512_sub_epi16(zmm_8000, _mm512_packs_epi32(v2, v3)), 8); + _mm512_mask_storeu_epi8( + dst_v, (__mmask64)mask, + PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(v01, v23))); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOUV444MATRIXROW_AVX512BW + +#ifdef HAS_ARGBTOUVMATRIXROW_AVX512BW +LIBYUV_TARGET_AVX512BW +void ARGBToUVMatrixRow_AVX512BW(const uint8_t* src_argb, + int src_stride_argb, + uint8_t* dst_u, + uint8_t* dst_v, + int width, + const struct ArgbConstants* c) { + static const uint32_t kPermdARGBToUV_AVX512BW[16] = { + 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15}; + static const uint8_t kShuffleAARRGGBB_AVX512BW[16] = { + 0, 4, 1, 5, 2, 6, 3, 7, 8, 12, 9, 13, 10, 14, 11, 15}; + const __m512i zmm_u = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToU)); + const __m512i zmm_v = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kRGBToV)); + const __m512i zmm_0101 = _mm512_set1_epi16(0x0101); + const __m512i zmm_one = _mm512_set1_epi16(1); + const __m512i zmm_8000 = + _mm512_broadcast_i32x4(_mm_loadu_si128((const __m128i*)c->kAddUV)); + const __m512i zmm_zero = _mm512_setzero_si512(); + const __m512i zmm_shuf = _mm512_broadcast_i32x4( + _mm_loadu_si128((const __m128i*)kShuffleAARRGGBB_AVX512BW)); + const __m512i zmm_perm_y = + _mm512_loadu_si512((const __m512i*)kPermdARGBToY_AVX512BW); + const __m512i zmm_perm_uv = + _mm512_loadu_si512((const __m512i*)kPermdARGBToUV_AVX512BW); + + while (width >= 32) { + __m512i zmm0 = _mm512_loadu_si512((const __m512i*)src_argb); + __m512i zmm1 = _mm512_loadu_si512((const __m512i*)(src_argb + 64)); + __m512i zmm2 = + _mm512_loadu_si512((const __m512i*)(src_argb + src_stride_argb)); + __m512i zmm3 = + _mm512_loadu_si512((const __m512i*)(src_argb + src_stride_argb + 64)); + + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + zmm0 = _mm512_maddubs_epi16(zmm0, zmm_0101); + zmm1 = _mm512_maddubs_epi16(zmm1, zmm_0101); + zmm2 = _mm512_maddubs_epi16(zmm2, zmm_0101); + zmm3 = _mm512_maddubs_epi16(zmm3, zmm_0101); + + zmm0 = _mm512_add_epi16(zmm0, zmm2); + zmm1 = _mm512_add_epi16(zmm1, zmm3); + + zmm0 = _mm512_avg_epu16(_mm512_srli_epi16(zmm0, 1), zmm_zero); + zmm1 = _mm512_avg_epu16(_mm512_srli_epi16(zmm1, 1), zmm_zero); + + zmm0 = PermutexvarEpi32(zmm_perm_uv, _mm512_packus_epi16(zmm0, zmm1)); + + zmm1 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm0, zmm_u), zmm_one); + zmm2 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm0, zmm_v), zmm_one); + zmm0 = _mm512_packs_epi32(zmm1, zmm2); + zmm0 = _mm512_srli_epi16(_mm512_sub_epi16(zmm_8000, zmm0), 8); + zmm0 = PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(zmm0, zmm0)); + + _mm_storeu_si128((__m128i*)dst_u, _mm512_castsi512_si128(zmm0)); + _mm_storeu_si128((__m128i*)dst_v, _mm512_extracti32x4_epi32(zmm0, 1)); + + src_argb += 128; + dst_u += 16; + dst_v += 16; + width -= 32; + } + if (width > 0) { + uint32_t mask = (1u << width) - 1u; + __mmask16 k1 = (__mmask16)mask; + __mmask16 k2 = (__mmask16)(mask >> 16); + __mmask16 k3 = ~k1; + __mmask16 k4 = ~k2; + __m512i zmm0 = _mm512_maskz_loadu_epi32(k1, src_argb); + __m512i zmm1 = _mm512_maskz_loadu_epi32(k2, src_argb + 64); + __m512i zmm2 = _mm512_maskz_loadu_epi32(k1, src_argb + src_stride_argb); + __m512i zmm3 = + _mm512_maskz_loadu_epi32(k2, src_argb + src_stride_argb + 64); + + zmm0 = _mm512_mask_shuffle_epi32(zmm0, k3, zmm0, (_MM_PERM_ENUM)0xa0); + zmm1 = _mm512_mask_shuffle_epi32(zmm1, k4, zmm1, (_MM_PERM_ENUM)0xa0); + zmm2 = _mm512_mask_shuffle_epi32(zmm2, k3, zmm2, (_MM_PERM_ENUM)0xa0); + zmm3 = _mm512_mask_shuffle_epi32(zmm3, k4, zmm3, (_MM_PERM_ENUM)0xa0); + + zmm0 = _mm512_shuffle_epi8(zmm0, zmm_shuf); + zmm1 = _mm512_shuffle_epi8(zmm1, zmm_shuf); + zmm2 = _mm512_shuffle_epi8(zmm2, zmm_shuf); + zmm3 = _mm512_shuffle_epi8(zmm3, zmm_shuf); + + zmm0 = _mm512_maddubs_epi16(zmm0, zmm_0101); + zmm1 = _mm512_maddubs_epi16(zmm1, zmm_0101); + zmm2 = _mm512_maddubs_epi16(zmm2, zmm_0101); + zmm3 = _mm512_maddubs_epi16(zmm3, zmm_0101); + + zmm0 = _mm512_add_epi16(zmm0, zmm2); + zmm1 = _mm512_add_epi16(zmm1, zmm3); + + zmm0 = _mm512_avg_epu16(_mm512_srli_epi16(zmm0, 1), zmm_zero); + zmm1 = _mm512_avg_epu16(_mm512_srli_epi16(zmm1, 1), zmm_zero); + + zmm0 = PermutexvarEpi32(zmm_perm_uv, _mm512_packus_epi16(zmm0, zmm1)); + + zmm1 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm0, zmm_u), zmm_one); + zmm2 = _mm512_madd_epi16(_mm512_maddubs_epi16(zmm0, zmm_v), zmm_one); + zmm0 = _mm512_packs_epi32(zmm1, zmm2); + zmm0 = _mm512_srli_epi16(_mm512_sub_epi16(zmm_8000, zmm0), 8); + zmm0 = PermutexvarEpi32(zmm_perm_y, _mm512_packus_epi16(zmm0, zmm0)); + + int halfwidth = (width + 1) >> 1; + __mmask16 k_out = (__mmask16)((1u << halfwidth) - 1u); + _mm_mask_storeu_epi8(dst_u, k_out, _mm512_castsi512_si128(zmm0)); + _mm_mask_storeu_epi8(dst_v, k_out, _mm512_extracti32x4_epi32(zmm0, 1)); + } + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOUVMATRIXROW_AVX512BW + +#endif // defined(__x86_64__) || defined(_M_X64) + +#ifdef HAS_COPYROW_AVX +LIBYUV_TARGET_AVX +void CopyRow_AVX(const uint8_t* src, uint8_t* dst, int width) { + do { + __m256i y0 = _mm256_loadu_si256((const __m256i*)src); + __m256i y1 = _mm256_loadu_si256((const __m256i*)(src + 32)); + _mm256_storeu_si256((__m256i*)dst, y0); + _mm256_storeu_si256((__m256i*)(dst + 32), y1); + src += 64; + dst += 64; + width -= 64; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_COPYROW_AVX + +#ifdef HAS_DETILETOYUY2_AVX2 +LIBYUV_TARGET_AVX2 +void DetileToYUY2_AVX2(const uint8_t* src_y, + ptrdiff_t src_y_tile_stride, + const uint8_t* src_uv, + ptrdiff_t src_uv_tile_stride, + uint8_t* dst_yuy2, + int width) { + do { + __m128i y0 = _mm_loadu_si128((const __m128i*)src_y); + __m128i y1 = _mm_loadu_si128((const __m128i*)(src_y + src_y_tile_stride)); + __m128i uv0 = _mm_loadu_si128((const __m128i*)src_uv); + __m128i uv1 = + _mm_loadu_si128((const __m128i*)(src_uv + src_uv_tile_stride)); + __m256i y = _mm256_inserti128_si256(_mm256_castsi128_si256(y0), y1, 1); + __m256i uv = _mm256_inserti128_si256(_mm256_castsi128_si256(uv0), uv1, 1); + __m256i lo = _mm256_unpacklo_epi8(y, uv); + __m256i hi = _mm256_unpackhi_epi8(y, uv); + _mm256_storeu_si256((__m256i*)dst_yuy2, + _mm256_permute2x128_si256(lo, hi, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_yuy2 + 32), + _mm256_permute2x128_si256(lo, hi, 0x31)); + src_y += 2 * src_y_tile_stride; + src_uv += 2 * src_uv_tile_stride; + dst_yuy2 += 64; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_DETILETOYUY2_AVX2 + +#ifdef HAS_UNPACKMT2T_AVX2 +LIBYUV_TARGET_AVX2 +void UnpackMT2T_AVX2(const uint8_t* src, uint16_t* dst, size_t size) { + const __m256i mask_00c0 = _mm256_set1_epi16(0x00c0); + while (size >= 80) { + __m256i low16 = _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)src)); + __m256i l0 = _mm256_and_si256(_mm256_slli_epi16(low16, 6), mask_00c0); + __m256i l1 = _mm256_and_si256(_mm256_slli_epi16(low16, 4), mask_00c0); + __m256i l2 = _mm256_and_si256(_mm256_slli_epi16(low16, 2), mask_00c0); + __m256i l3 = _mm256_and_si256(low16, mask_00c0); + + __m256i u0 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src + 16))); + __m256i u1 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src + 32))); + __m256i u2 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src + 48))); + __m256i u3 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src + 64))); + + u0 = _mm256_or_si256( + _mm256_or_si256(_mm256_slli_epi16(u0, 8), _mm256_srli_epi16(u0, 2)), + l0); + u1 = _mm256_or_si256( + _mm256_or_si256(_mm256_slli_epi16(u1, 8), _mm256_srli_epi16(u1, 2)), + l1); + u2 = _mm256_or_si256( + _mm256_or_si256(_mm256_slli_epi16(u2, 8), _mm256_srli_epi16(u2, 2)), + l2); + u3 = _mm256_or_si256( + _mm256_or_si256(_mm256_slli_epi16(u3, 8), _mm256_srli_epi16(u3, 2)), + l3); + + _mm256_storeu_si256((__m256i*)dst, u0); + _mm256_storeu_si256((__m256i*)(dst + 16), u1); + _mm256_storeu_si256((__m256i*)(dst + 32), u2); + _mm256_storeu_si256((__m256i*)(dst + 48), u3); + + src += 80; + dst += 64; + size -= 80; + } + _mm256_zeroupper(); +} +#endif // HAS_UNPACKMT2T_AVX2 + +#ifdef HAS_ARGBGRAYROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBGrayRow_AVX2(const uint8_t* src_argb, uint8_t* dst_argb, int width) { + static const uint8_t kShufGrayDword[16] = {0, 0, 0, 0x80, 4, 4, 4, 0x80, + 8, 8, 8, 0x80, 12, 12, 12, 0x80}; + const __m256i c_coeff = _mm256_set1_epi32(0x004d961d); + const __m256i c_sub128 = _mm256_set1_epi8((char)0x80); + const __m256i c_one16 = _mm256_set1_epi16(1); + const __m256i c_bias = _mm256_set1_epi32(32896); + const __m256i c_shuf = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShufGrayDword)); + const __m256i c_alpha = _mm256_set1_epi32((int)0xff000000u); + + while (width >= 8) { + __m256i s = _mm256_loadu_si256((const __m256i*)src_argb); + src_argb += 32; + __m256i y16 = _mm256_maddubs_epi16(c_coeff, _mm256_sub_epi8(s, c_sub128)); + __m256i y32 = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_madd_epi16(y16, c_one16), c_bias), 8); + __m256i out = _mm256_or_si256(_mm256_and_si256(s, c_alpha), + _mm256_shuffle_epi8(y32, c_shuf)); + _mm256_storeu_si256((__m256i*)dst_argb, out); + dst_argb += 32; + width -= 8; + } + _mm256_zeroupper(); + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + ARGBGrayRow_C(src_argb, dst_argb, width); } } -#endif // HAS_ARGBSHADEROW_SSE2 +#endif // HAS_ARGBGRAYROW_AVX2 -#ifdef HAS_ARGBMULTIPLYROW_SSE2 -// Multiply 2 rows of ARGB pixels together, 4 pixels at a time. -__declspec(naked) void ARGBMultiplyRow_SSE2(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_argb0 - mov esi, [esp + 4 + 8] // src_argb1 - mov edx, [esp + 4 + 12] // dst_argb - mov ecx, [esp + 4 + 16] // width - pxor xmm5, xmm5 // constant 0 +#ifdef HAS_MERGERGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void MergeRGBRow_AVX2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_rgb, + int width) { + static const uint8_t kMergeRGBShuf[5][16] = { + {0u, 11u, 6u, 1u, 12u, 7u, 2u, 13u, 8u, 3u, 14u, 9u, 4u, 15u, 10u, 5u}, + {5u, 0u, 11u, 6u, 1u, 12u, 7u, 2u, 13u, 8u, 3u, 14u, 9u, 4u, 15u, 10u}, + {10u, 5u, 0u, 11u, 6u, 1u, 12u, 7u, 2u, 13u, 8u, 3u, 14u, 9u, 4u, 15u}, + {0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, + 0u}, + {0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, + 0u}}; + const __m256i shuf_r = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kMergeRGBShuf[0])); + const __m256i shuf_g = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kMergeRGBShuf[1])); + const __m256i shuf_b = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kMergeRGBShuf[2])); + const __m256i m1 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kMergeRGBShuf[3])); + const __m256i m2 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kMergeRGBShuf[4])); - convertloop: - movdqu xmm0, [eax] // read 4 pixels from src_argb0 - movdqu xmm2, [esi] // read 4 pixels from src_argb1 - movdqu xmm1, xmm0 - movdqu xmm3, xmm2 - punpcklbw xmm0, xmm0 // first 2 - punpckhbw xmm1, xmm1 // next 2 - punpcklbw xmm2, xmm5 // first 2 - punpckhbw xmm3, xmm5 // next 2 - pmulhuw xmm0, xmm2 // src_argb0 * src_argb1 first 2 - pmulhuw xmm1, xmm3 // src_argb0 * src_argb1 next 2 - lea eax, [eax + 16] - lea esi, [esi + 16] - packuswb xmm0, xmm1 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jg convertloop + do { + __m256i r = + _mm256_shuffle_epi8(_mm256_loadu_si256((const __m256i*)src_r), shuf_r); + __m256i g = + _mm256_shuffle_epi8(_mm256_loadu_si256((const __m256i*)src_g), shuf_g); + __m256i b = + _mm256_shuffle_epi8(_mm256_loadu_si256((const __m256i*)src_b), shuf_b); - pop esi - ret + __m256i c0 = _mm256_blendv_epi8(_mm256_blendv_epi8(r, g, m1), b, m2); + __m256i c1 = _mm256_blendv_epi8(_mm256_blendv_epi8(g, b, m1), r, m2); + __m256i c2 = _mm256_blendv_epi8(_mm256_blendv_epi8(b, r, m1), g, m2); + + _mm256_storeu_si256((__m256i*)dst_rgb, + _mm256_permute2x128_si256(c0, c1, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_rgb + 32), + _mm256_permute2x128_si256(c2, c0, 0x30)); + _mm256_storeu_si256((__m256i*)(dst_rgb + 64), + _mm256_permute2x128_si256(c1, c2, 0x31)); + + src_r += 32; + src_g += 32; + src_b += 32; + dst_rgb += 96; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_MERGERGBROW_AVX2 + +#ifdef HAS_RAWTORGBAROW_AVX2 +LIBYUV_TARGET_AVX2 +void RAWToRGBARow_AVX2(const uint8_t* src_raw, uint8_t* dst_rgba, int width) { + static const uint8_t kShufRAWToRGBA_Lo[16] = {0x80, 2u, 1u, 0u, 0x80, 5u, + 4u, 3u, 0x80, 8u, 7u, 6u, + 0x80, 11u, 10u, 9u}; + static const uint8_t kShufRAWToRGBA_Hi[16] = {0x80, 6u, 5u, 4u, 0x80, 9u, + 8u, 7u, 0x80, 12u, 11u, 10u, + 0x80, 15u, 14u, 13u}; + const __m256i shuf_lo = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShufRAWToRGBA_Lo)); + const __m256i shuf_hi = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShufRAWToRGBA_Hi)); + const __m256i alpha = _mm256_set1_epi32(0x000000ff); + + do { + __m128i s0 = _mm_loadu_si128((const __m128i*)src_raw); + __m128i s1 = _mm_loadu_si128((const __m128i*)(src_raw + 12)); + __m128i s2 = _mm_loadu_si128((const __m128i*)(src_raw + 20)); + __m128i s3 = _mm_loadu_si128((const __m128i*)(src_raw + 32)); + __m256i y0 = _mm256_inserti128_si256(_mm256_castsi128_si256(s0), s1, 1); + __m256i y1 = _mm256_inserti128_si256(_mm256_castsi128_si256(s2), s3, 1); + y0 = _mm256_or_si256(_mm256_shuffle_epi8(y0, shuf_lo), alpha); + y1 = _mm256_or_si256(_mm256_shuffle_epi8(y1, shuf_hi), alpha); + _mm256_storeu_si256((__m256i*)dst_rgba, y0); + _mm256_storeu_si256((__m256i*)(dst_rgba + 32), y1); + src_raw += 48; + dst_rgba += 64; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_RAWTORGBAROW_AVX2 + +#ifdef HAS_HALFROW_AVX2 +LIBYUV_TARGET_AVX2 +void HalfRow_AVX2(const uint8_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int width) { + do { + __m256i r0 = _mm256_loadu_si256((const __m256i*)src_uv); + __m256i r1 = _mm256_loadu_si256((const __m256i*)(src_uv + src_uv_stride)); + _mm256_storeu_si256((__m256i*)dst_uv, _mm256_avg_epu8(r0, r1)); + src_uv += 32; + dst_uv += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_HALFROW_AVX2 + +#ifdef HAS_HALFROW_16_AVX2 +LIBYUV_TARGET_AVX2 +void HalfRow_16_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint16_t* dst_uv, + int width) { + do { + __m256i r0 = _mm256_loadu_si256((const __m256i*)src_uv); + __m256i r1 = _mm256_loadu_si256((const __m256i*)(src_uv + src_uv_stride)); + _mm256_storeu_si256((__m256i*)dst_uv, _mm256_avg_epu16(r0, r1)); + src_uv += 16; + dst_uv += 16; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_HALFROW_16_AVX2 + +#ifdef HAS_HALFMERGEUVROW_AVX2 +LIBYUV_TARGET_AVX2 +void HalfMergeUVRow_AVX2(const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint8_t* dst_uv, + int width) { + const __m256i ymm_0101 = _mm256_set1_epi16(0x0101); + const __m256i ymm_zero = _mm256_setzero_si256(); + do { + __m256i u0 = _mm256_loadu_si256((const __m256i*)src_u); + __m256i v0 = _mm256_loadu_si256((const __m256i*)src_v); + __m256i u1 = _mm256_loadu_si256((const __m256i*)(src_u + src_stride_u)); + __m256i v1 = _mm256_loadu_si256((const __m256i*)(src_v + src_stride_v)); + u0 = _mm256_add_epi16(_mm256_maddubs_epi16(u0, ymm_0101), + _mm256_maddubs_epi16(u1, ymm_0101)); + v0 = _mm256_add_epi16(_mm256_maddubs_epi16(v0, ymm_0101), + _mm256_maddubs_epi16(v1, ymm_0101)); + u0 = _mm256_avg_epu16(_mm256_srli_epi16(u0, 1), ymm_zero); + v0 = _mm256_avg_epu16(_mm256_srli_epi16(v0, 1), ymm_zero); + u0 = _mm256_packus_epi16(u0, u0); + v0 = _mm256_packus_epi16(v0, v0); + _mm256_storeu_si256((__m256i*)dst_uv, _mm256_unpacklo_epi8(u0, v0)); + src_u += 32; + src_v += 32; + dst_uv += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_HALFMERGEUVROW_AVX2 + +#ifdef HAS_CONVERT8TO8ROW_AVX2 +LIBYUV_TARGET_AVX2 +void Convert8To8Row_AVX2(const uint8_t* src_y, + uint8_t* dst_y, + int scale, + int bias, + int width) { + const __m256i ymm_scale = + _mm256_slli_epi16(_mm256_set1_epi16((short)scale), 8); + const __m256i ymm_bias = _mm256_set1_epi8((char)bias); + const __m256i ymm_zero = _mm256_setzero_si256(); + do { + __m256i y = _mm256_loadu_si256((const __m256i*)src_y); + __m256i lo = + _mm256_mulhi_epu16(_mm256_unpacklo_epi8(y, ymm_zero), ymm_scale); + __m256i hi = + _mm256_mulhi_epu16(_mm256_unpackhi_epi8(y, ymm_zero), ymm_scale); + __m256i out = _mm256_add_epi8(_mm256_packus_epi16(lo, hi), ymm_bias); + _mm256_storeu_si256((__m256i*)dst_y, out); + src_y += 32; + dst_y += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_CONVERT8TO8ROW_AVX2 + +#ifdef HAS_DIVIDEROW_16_AVX2 +LIBYUV_TARGET_AVX2 +void DivideRow_16_AVX2(const uint16_t* src_y, + uint16_t* dst_y, + int scale, + int width) { + if (scale == 65536) { // Divide by 1, so do memcpy. + if (src_y != dst_y) { + memcpy(dst_y, src_y, (size_t)width * 2); + } + return; + } + const __m256i ymm_scale = _mm256_set1_epi16((short)scale); + while (width > 0) { + __m256i v0 = _mm256_mulhi_epu16(_mm256_loadu_si256((const __m256i*)src_y), + ymm_scale); + __m256i v1 = _mm256_mulhi_epu16( + _mm256_loadu_si256((const __m256i*)(src_y + 16)), ymm_scale); + _mm256_storeu_si256((__m256i*)dst_y, v0); + _mm256_storeu_si256((__m256i*)(dst_y + 16), v1); + src_y += 32; + dst_y += 32; + width -= 32; + } + _mm256_zeroupper(); +} +#endif // HAS_DIVIDEROW_16_AVX2 + +#ifdef HAS_CONVERT16TO8ROW_AVX2 +LIBYUV_TARGET_AVX2 +void Convert16To8Row_AVX2(const uint16_t* src_y, + uint8_t* dst_y, + int scale, + int width) { + const __m256i ymm_scale = _mm256_set1_epi16((short)scale); + const __m256i ymm_255 = _mm256_set1_epi16(255); + do { + __m256i y0 = _mm256_loadu_si256((const __m256i*)src_y); + __m256i y1 = _mm256_loadu_si256((const __m256i*)(src_y + 16)); + y0 = _mm256_min_epu16(_mm256_mulhi_epu16(y0, ymm_scale), ymm_255); + y1 = _mm256_min_epu16(_mm256_mulhi_epu16(y1, ymm_scale), ymm_255); + __m256i out = _mm256_permute4x64_epi64(_mm256_packus_epi16(y0, y1), 0xd8); + _mm256_storeu_si256((__m256i*)dst_y, out); + src_y += 32; + dst_y += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_CONVERT16TO8ROW_AVX2 + +#ifdef HAS_HALFROW_16TO8_AVX2 +LIBYUV_TARGET_AVX2 +void HalfRow_16To8_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const __m256i ymm_scale = _mm256_set1_epi16((short)scale); + const __m256i ymm_255 = _mm256_set1_epi16(255); + do { + __m256i r0 = _mm256_loadu_si256((const __m256i*)src_uv); + __m256i r1 = _mm256_loadu_si256((const __m256i*)(src_uv + 16)); + __m256i s0 = _mm256_loadu_si256((const __m256i*)(src_uv + src_uv_stride)); + __m256i s1 = + _mm256_loadu_si256((const __m256i*)(src_uv + src_uv_stride + 16)); + r0 = _mm256_min_epu16(_mm256_mulhi_epu16(_mm256_avg_epu16(r0, s0), ymm_scale), + ymm_255); + r1 = _mm256_min_epu16(_mm256_mulhi_epu16(_mm256_avg_epu16(r1, s1), ymm_scale), + ymm_255); + __m256i out = _mm256_permute4x64_epi64(_mm256_packus_epi16(r0, r1), 0xd8); + _mm256_storeu_si256((__m256i*)dst_uv, out); + src_uv += 32; + dst_uv += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_HALFROW_16TO8_AVX2 + +#ifdef HAS_HALFWIDTHROW_16TO8_AVX2 +LIBYUV_TARGET_AVX2 +void HalfWidthRow_16To8_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + const __m256i ymm_mask16 = _mm256_set1_epi32(0x0000ffff); + const __m256i ymm_2 = _mm256_set1_epi32(2); + const __m256i ymm_scale = _mm256_set1_epi16((short)scale); + const __m256i ymm_255 = _mm256_set1_epi16(255); + do { + __m256i s0 = _mm256_loadu_si256((const __m256i*)src_uv); + __m256i s1 = _mm256_loadu_si256((const __m256i*)(src_uv + 16)); + __m256i t0 = _mm256_loadu_si256((const __m256i*)(src_uv + src_uv_stride)); + __m256i t1 = + _mm256_loadu_si256((const __m256i*)(src_uv + src_uv_stride + 16)); + + __m256i sum0 = _mm256_add_epi32(_mm256_and_si256(s0, ymm_mask16), + _mm256_srli_epi32(s0, 16)); + sum0 = _mm256_add_epi32(sum0, _mm256_and_si256(t0, ymm_mask16)); + sum0 = _mm256_add_epi32(sum0, _mm256_srli_epi32(t0, 16)); + sum0 = _mm256_srli_epi32(_mm256_add_epi32(sum0, ymm_2), 2); + + __m256i sum1 = _mm256_add_epi32(_mm256_and_si256(s1, ymm_mask16), + _mm256_srli_epi32(s1, 16)); + sum1 = _mm256_add_epi32(sum1, _mm256_and_si256(t1, ymm_mask16)); + sum1 = _mm256_add_epi32(sum1, _mm256_srli_epi32(t1, 16)); + sum1 = _mm256_srli_epi32(_mm256_add_epi32(sum1, ymm_2), 2); + + __m256i avg16 = + _mm256_permute4x64_epi64(_mm256_packus_epi32(sum0, sum1), 0xd8); + avg16 = _mm256_min_epu16(_mm256_mulhi_epu16(avg16, ymm_scale), ymm_255); + __m256i out = + _mm256_permute4x64_epi64(_mm256_packus_epi16(avg16, avg16), 0xd8); + _mm_storeu_si128((__m128i*)dst_uv, _mm256_castsi256_si128(out)); + src_uv += 32; + dst_uv += 16; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_HALFWIDTHROW_16TO8_AVX2 + +#ifdef HAS_HALFWIDTHROW_16TO8_ODD_AVX2 +LIBYUV_TARGET_AVX2 +void HalfWidthRow_16To8_Odd_AVX2(const uint16_t* src_uv, + ptrdiff_t src_uv_stride, + uint8_t* dst_uv, + int scale, + int width) { + int n = (width - 1) & ~15; + int r = (width - 1) & 15; + SIMD_ALIGNED(uint16_t pair[64]); + SIMD_ALIGNED(uint8_t out[16]); + if (n > 0) { + HalfWidthRow_16To8_AVX2(src_uv, src_uv_stride, dst_uv, scale, n); + src_uv += n * 2; + dst_uv += n; + } + if (r > 0) { + HalfWidthRow_16To8_Any_AVX2(src_uv, src_uv_stride, dst_uv, scale, r); + src_uv += r * 2; + dst_uv += r; + } + memset(pair, 0, sizeof(pair)); + pair[0] = src_uv[0]; + pair[1] = src_uv[0]; + pair[32] = src_uv[src_uv_stride]; + pair[33] = src_uv[src_uv_stride]; + HalfWidthRow_16To8_AVX2(pair, 32, out, scale, 16); + dst_uv[0] = out[0]; +} +#endif // HAS_HALFWIDTHROW_16TO8_ODD_AVX2 + +#ifdef HAS_GAUSSCOL_AVX2 +LIBYUV_TARGET_AVX2 +void GaussCol_AVX2(const uint16_t* src0, + const uint16_t* src1, + const uint16_t* src2, + const uint16_t* src3, + const uint16_t* src4, + uint32_t* dst, + int width) { + while (width >= 8) { + __m256i v0 = _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)src0)); + __m256i v1 = _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)src1)); + __m256i v2 = _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)src2)); + __m256i v3 = _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)src3)); + __m256i v4 = _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)src4)); + __m256i v04 = _mm256_add_epi32(v0, v4); + __m256i v13 = _mm256_slli_epi32(_mm256_add_epi32(v1, v3), 2); + __m256i v2_6 = + _mm256_add_epi32(_mm256_slli_epi32(v2, 2), _mm256_slli_epi32(v2, 1)); + _mm256_storeu_si256((__m256i*)dst, + _mm256_add_epi32(_mm256_add_epi32(v04, v13), v2_6)); + src0 += 8; + src1 += 8; + src2 += 8; + src3 += 8; + src4 += 8; + dst += 8; + width -= 8; + } + _mm256_zeroupper(); + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + GaussCol_C(src0, src1, src2, src3, src4, dst, width); } } -#endif // HAS_ARGBMULTIPLYROW_SSE2 +#endif // HAS_GAUSSCOL_AVX2 -#ifdef HAS_ARGBADDROW_SSE2 -// Add 2 rows of ARGB pixels together, 4 pixels at a time. -// TODO(fbarchard): Port this to posix, neon and other math functions. -__declspec(naked) void ARGBAddRow_SSE2(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_argb0 - mov esi, [esp + 4 + 8] // src_argb1 - mov edx, [esp + 4 + 12] // dst_argb - mov ecx, [esp + 4 + 16] // width - - sub ecx, 4 - jl convertloop49 - - convertloop4: - movdqu xmm0, [eax] // read 4 pixels from src_argb0 - lea eax, [eax + 16] - movdqu xmm1, [esi] // read 4 pixels from src_argb1 - lea esi, [esi + 16] - paddusb xmm0, xmm1 // src_argb0 + src_argb1 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jge convertloop4 - - convertloop49: - add ecx, 4 - 1 - jl convertloop19 - - convertloop1: - movd xmm0, [eax] // read 1 pixels from src_argb0 - lea eax, [eax + 4] - movd xmm1, [esi] // read 1 pixels from src_argb1 - lea esi, [esi + 4] - paddusb xmm0, xmm1 // src_argb0 + src_argb1 - movd [edx], xmm0 - lea edx, [edx + 4] - sub ecx, 1 - jge convertloop1 - - convertloop19: - pop esi - ret +#ifdef HAS_GAUSSCOL_F32_AVX2 +LIBYUV_TARGET_AVX2 +void GaussCol_F32_AVX2(const float* src0, + const float* src1, + const float* src2, + const float* src3, + const float* src4, + float* dst, + int width) { + const __m256 c4 = _mm256_set1_ps(4.0f); + const __m256 c6 = _mm256_set1_ps(6.0f); + while (width >= 8) { + __m256 s0 = _mm256_loadu_ps(src0); + __m256 s1 = _mm256_loadu_ps(src1); + __m256 s2 = _mm256_loadu_ps(src2); + __m256 s3 = _mm256_loadu_ps(src3); + __m256 s4 = _mm256_loadu_ps(src4); + __m256 sum = _mm256_add_ps(s0, _mm256_mul_ps(s1, c4)); + sum = _mm256_add_ps(sum, _mm256_mul_ps(s2, c6)); + sum = _mm256_add_ps(sum, _mm256_mul_ps(s3, c4)); + sum = _mm256_add_ps(sum, s4); + _mm256_storeu_ps(dst, sum); + src0 += 8; + src1 += 8; + src2 += 8; + src3 += 8; + src4 += 8; + dst += 8; + width -= 8; + } + _mm256_zeroupper(); + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + GaussCol_F32_C(src0, src1, src2, src3, src4, dst, width); } } -#endif // HAS_ARGBADDROW_SSE2 +#endif // HAS_GAUSSCOL_F32_AVX2 -#ifdef HAS_ARGBSUBTRACTROW_SSE2 -// Subtract 2 rows of ARGB pixels together, 4 pixels at a time. -__declspec(naked) void ARGBSubtractRow_SSE2(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_argb0 - mov esi, [esp + 4 + 8] // src_argb1 - mov edx, [esp + 4 + 12] // dst_argb - mov ecx, [esp + 4 + 16] // width +#ifdef HAS_SCALEMAXSAMPLES_AVX2 +LIBYUV_TARGET_AVX2 +float ScaleMaxSamples_AVX2(const float* src, + float* dst, + float scale, + int width) { + __m256 vmax = _mm256_setzero_ps(); + const __m256 vscale = _mm256_set1_ps(scale); + while (width >= 8) { + __m256 v = _mm256_loadu_ps(src); + src += 8; + vmax = _mm256_max_ps(v, vmax); + _mm256_storeu_ps(dst, _mm256_mul_ps(v, vscale)); + dst += 8; + width -= 8; + } + __m128 m128 = + _mm_max_ps(_mm256_extractf128_ps(vmax, 1), _mm256_castps256_ps128(vmax)); + m128 = _mm_max_ps(_mm_movehl_ps(m128, m128), m128); + m128 = _mm_max_ss(_mm_shuffle_ps(m128, m128, 1), m128); + float fmax = _mm_cvtss_f32(m128); + _mm256_zeroupper(); + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + for (; width > 0; --width) { + float v = *src++; + float vs = v * scale; + fmax = (v > fmax) ? v : fmax; + *dst++ = vs; + } + return fmax; +} +#endif // HAS_SCALEMAXSAMPLES_AVX2 - convertloop: - movdqu xmm0, [eax] // read 4 pixels from src_argb0 - lea eax, [eax + 16] - movdqu xmm1, [esi] // read 4 pixels from src_argb1 - lea esi, [esi + 16] - psubusb xmm0, xmm1 // src_argb0 - src_argb1 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jg convertloop +#ifdef HAS_SCALESUMSAMPLES_AVX2 +LIBYUV_TARGET_AVX2 +float ScaleSumSamples_AVX2(const float* src, + float* dst, + float scale, + int width) { + __m256 vsum = _mm256_setzero_ps(); + const __m256 vscale = _mm256_set1_ps(scale); + while (width >= 8) { + __m256 v = _mm256_loadu_ps(src); + src += 8; + vsum = _mm256_add_ps(vsum, _mm256_mul_ps(v, v)); + _mm256_storeu_ps(dst, _mm256_mul_ps(v, vscale)); + dst += 8; + width -= 8; + } + __m128 s128 = + _mm_add_ps(_mm256_castps256_ps128(vsum), _mm256_extractf128_ps(vsum, 1)); + s128 = _mm_add_ps(s128, _mm_movehl_ps(s128, s128)); + s128 = _mm_add_ss(s128, _mm_shuffle_ps(s128, s128, 1)); + float fsum = _mm_cvtss_f32(s128); + _mm256_zeroupper(); + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + for (; width > 0; --width) { + float v = *src++; + fsum += v * v; + *dst++ = v * scale; + } + return fsum; +} +#endif // HAS_SCALESUMSAMPLES_AVX2 - pop esi - ret +#ifdef HAS_SCALESAMPLES_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleSamples_AVX2(const float* src, float* dst, float scale, int width) { + const __m256 vscale = _mm256_set1_ps(scale); + while (width >= 8) { + __m256 v = _mm256_loadu_ps(src); + src += 8; + _mm256_storeu_ps(dst, _mm256_mul_ps(v, vscale)); + dst += 8; + width -= 8; + } + _mm256_zeroupper(); + if (width > 0) { + // TODO(fbarchard): Handle remainder with masking or SIMD Any function. + ScaleSamples_C(src, dst, scale, width); } } -#endif // HAS_ARGBSUBTRACTROW_SSE2 +#endif // HAS_SCALESAMPLES_AVX2 -#ifdef HAS_ARGBMULTIPLYROW_AVX2 -// Multiply 2 rows of ARGB pixels together, 8 pixels at a time. -__declspec(naked) void ARGBMultiplyRow_AVX2(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_argb0 - mov esi, [esp + 4 + 8] // src_argb1 - mov edx, [esp + 4 + 12] // dst_argb - mov ecx, [esp + 4 + 16] // width - vpxor ymm5, ymm5, ymm5 // constant 0 +#if defined(HAS_ARGBTORGB24ROW_AVX2) || defined(HAS_ARGBTORAWROW_AVX2) +LIBYUV_TARGET_AVX2 +static inline void ARGBToRGBRow_AVX2(const uint8_t* src, + uint8_t* dst, + int width, + const uint8_t* shuffler) { + static const uint32_t kPermdRGB24_AVX[8] = {0, 1, 2, 4, 5, 6, 3, 7}; + const __m256i ymm_shuf = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)shuffler)); + const __m256i ymm_perm = + _mm256_loadu_si256((const __m256i*)kPermdRGB24_AVX); + do { + __m256i ymm0 = _mm256_loadu_si256((const __m256i*)src); + __m256i ymm1 = _mm256_loadu_si256((const __m256i*)(src + 32)); + __m256i ymm2 = _mm256_loadu_si256((const __m256i*)(src + 64)); + __m256i ymm3 = _mm256_loadu_si256((const __m256i*)(src + 96)); + src += 128; - convertloop: - vmovdqu ymm1, [eax] // read 8 pixels from src_argb0 - lea eax, [eax + 32] - vmovdqu ymm3, [esi] // read 8 pixels from src_argb1 - lea esi, [esi + 32] - vpunpcklbw ymm0, ymm1, ymm1 // low 4 - vpunpckhbw ymm1, ymm1, ymm1 // high 4 - vpunpcklbw ymm2, ymm3, ymm5 // low 4 - vpunpckhbw ymm3, ymm3, ymm5 // high 4 - vpmulhuw ymm0, ymm0, ymm2 // src_argb0 * src_argb1 low 4 - vpmulhuw ymm1, ymm1, ymm3 // src_argb0 * src_argb1 high 4 - vpackuswb ymm0, ymm0, ymm1 - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 8 - jg convertloop + ymm0 = _mm256_permutevar8x32_epi32(_mm256_shuffle_epi8(ymm0, ymm_shuf), + ymm_perm); + ymm1 = _mm256_permutevar8x32_epi32(_mm256_shuffle_epi8(ymm1, ymm_shuf), + ymm_perm); + ymm2 = _mm256_permutevar8x32_epi32(_mm256_shuffle_epi8(ymm2, ymm_shuf), + ymm_perm); + ymm3 = _mm256_permutevar8x32_epi32(_mm256_shuffle_epi8(ymm3, ymm_shuf), + ymm_perm); - pop esi - vzeroupper - ret - } + _mm256_storeu_si256( + (__m256i*)dst, + _mm256_or_si256(ymm0, _mm256_permute4x64_epi64(ymm1, 0x3f))); + _mm256_storeu_si256( + (__m256i*)(dst + 32), + _mm256_or_si256(_mm256_permute4x64_epi64(ymm1, 0xf9), + _mm256_permute4x64_epi64(ymm2, 0x4f))); + _mm256_storeu_si256( + (__m256i*)(dst + 64), + _mm256_or_si256(_mm256_permute4x64_epi64(ymm2, 0xfe), + _mm256_permute4x64_epi64(ymm3, 0x93))); + dst += 96; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); } -#endif // HAS_ARGBMULTIPLYROW_AVX2 +#endif // defined(HAS_ARGBTORGB24ROW_AVX2) || defined(HAS_ARGBTORAWROW_AVX2) + +#ifdef HAS_ARGBTORGB24ROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBToRGB24Row_AVX2(const uint8_t* src, uint8_t* dst, int width) { + ARGBToRGBRow_AVX2(src, dst, width, kShuffleMaskARGBToRGB24[0]); +} +#endif // HAS_ARGBTORGB24ROW_AVX2 + +#ifdef HAS_ARGBTORAWROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBToRAWRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { + static const uint8_t kShuffleMaskARGBToRAW_AVX2[16] = { + 2u, 1u, 0u, 6u, 5u, 4u, 10u, 9u, 8u, 14u, 13u, 12u, 128u, 128u, 128u, + 128u}; + ARGBToRGBRow_AVX2(src, dst, width, kShuffleMaskARGBToRAW_AVX2); +} +#endif // HAS_ARGBTORAWROW_AVX2 + +#ifdef HAS_SPLITUVROW_AVX2 +LIBYUV_TARGET_AVX2 +void SplitUVRow_AVX2(const uint8_t* src_uv, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const __m256i mask_00ff = _mm256_set1_epi16(0x00ff); + do { + __m256i uv0 = _mm256_loadu_si256((const __m256i*)src_uv); + __m256i uv1 = _mm256_loadu_si256((const __m256i*)(src_uv + 32)); + __m256i u = _mm256_permute4x64_epi64( + _mm256_packus_epi16(_mm256_and_si256(uv0, mask_00ff), + _mm256_and_si256(uv1, mask_00ff)), + 0xd8); + __m256i v = _mm256_permute4x64_epi64( + _mm256_packus_epi16(_mm256_srli_epi16(uv0, 8), + _mm256_srli_epi16(uv1, 8)), + 0xd8); + _mm256_storeu_si256((__m256i*)dst_u, u); + _mm256_storeu_si256((__m256i*)dst_v, v); + src_uv += 64; + dst_u += 32; + dst_v += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_SPLITUVROW_AVX2 + +#ifdef HAS_AR64TOARGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void AR64ToARGBRow_AVX2(const uint16_t* src_ar64, + uint8_t* dst_argb, + int width) { + do { + __m256i s0 = _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)src_ar64), + 8); + __m256i s1 = _mm256_srli_epi16( + _mm256_loadu_si256((const __m256i*)(src_ar64 + 16)), 8); + __m256i out = _mm256_permute4x64_epi64(_mm256_packus_epi16(s0, s1), 0xd8); + _mm256_storeu_si256((__m256i*)dst_argb, out); + src_ar64 += 32; + dst_argb += 32; + width -= 8; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_AR64TOARGBROW_AVX2 + +#ifdef HAS_AB64TOARGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void AB64ToARGBRow_AVX2(const uint16_t* src_ab64, + uint8_t* dst_argb, + int width) { + static const uint8_t kShufSwapRB[16] = {2u, 1u, 0u, 3u, 6u, 5u, 4u, 7u, + 10u, 9u, 8u, 11u, 14u, 13u, 12u, 15u}; + const __m256i shuf = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShufSwapRB)); + do { + __m256i s0 = _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)src_ab64), + 8); + __m256i s1 = _mm256_srli_epi16( + _mm256_loadu_si256((const __m256i*)(src_ab64 + 16)), 8); + __m256i out = _mm256_permute4x64_epi64(_mm256_packus_epi16(s0, s1), 0xd8); + out = _mm256_shuffle_epi8(out, shuf); + _mm256_storeu_si256((__m256i*)dst_argb, out); + src_ab64 += 32; + dst_argb += 32; + width -= 8; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_AB64TOARGBROW_AVX2 + +#ifdef HAS_ARGBTOAR64ROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBToAR64Row_AVX2(const uint8_t* src_argb, + uint16_t* dst_ar64, + int width) { + do { + __m256i s = _mm256_permute4x64_epi64( + _mm256_loadu_si256((const __m256i*)src_argb), 0xd8); + _mm256_storeu_si256((__m256i*)dst_ar64, _mm256_unpacklo_epi8(s, s)); + _mm256_storeu_si256((__m256i*)(dst_ar64 + 16), _mm256_unpackhi_epi8(s, s)); + src_argb += 32; + dst_ar64 += 32; + width -= 8; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOAR64ROW_AVX2 + +#ifdef HAS_ARGBTOAB64ROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBToAB64Row_AVX2(const uint8_t* src_argb, + uint16_t* dst_ab64, + int width) { + static const uint8_t kShufSwapRB[16] = {2u, 1u, 0u, 3u, 6u, 5u, 4u, 7u, + 10u, 9u, 8u, 11u, 14u, 13u, 12u, 15u}; + const __m256i shuf = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShufSwapRB)); + do { + __m256i s = _mm256_shuffle_epi8( + _mm256_loadu_si256((const __m256i*)src_argb), shuf); + s = _mm256_permute4x64_epi64(s, 0xd8); + _mm256_storeu_si256((__m256i*)dst_ab64, _mm256_unpacklo_epi8(s, s)); + _mm256_storeu_si256((__m256i*)(dst_ab64 + 16), _mm256_unpackhi_epi8(s, s)); + src_argb += 32; + dst_ab64 += 32; + width -= 8; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_ARGBTOAB64ROW_AVX2 #ifdef HAS_ARGBADDROW_AVX2 -// Add 2 rows of ARGB pixels together, 8 pixels at a time. -__declspec(naked) void ARGBAddRow_AVX2(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_argb0 - mov esi, [esp + 4 + 8] // src_argb1 - mov edx, [esp + 4 + 12] // dst_argb - mov ecx, [esp + 4 + 16] // width - - convertloop: - vmovdqu ymm0, [eax] // read 8 pixels from src_argb0 - lea eax, [eax + 32] - vpaddusb ymm0, ymm0, [esi] // add 8 pixels from src_argb1 - lea esi, [esi + 32] - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 8 - jg convertloop - - pop esi - vzeroupper - ret - } +LIBYUV_TARGET_AVX2 +void ARGBAddRow_AVX2(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + do { + __m256i s0 = _mm256_loadu_si256((const __m256i*)src_argb); + __m256i s1 = _mm256_loadu_si256((const __m256i*)src_argb1); + _mm256_storeu_si256((__m256i*)dst_argb, _mm256_adds_epu8(s0, s1)); + src_argb += 32; + src_argb1 += 32; + dst_argb += 32; + width -= 8; + } while (width > 0); + _mm256_zeroupper(); } #endif // HAS_ARGBADDROW_AVX2 #ifdef HAS_ARGBSUBTRACTROW_AVX2 -// Subtract 2 rows of ARGB pixels together, 8 pixels at a time. -__declspec(naked) void ARGBSubtractRow_AVX2(const uint8_t* src_argb0, - const uint8_t* src_argb1, - uint8_t* dst_argb, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_argb0 - mov esi, [esp + 4 + 8] // src_argb1 - mov edx, [esp + 4 + 12] // dst_argb - mov ecx, [esp + 4 + 16] // width - - convertloop: - vmovdqu ymm0, [eax] // read 8 pixels from src_argb0 - lea eax, [eax + 32] - vpsubusb ymm0, ymm0, [esi] // src_argb0 - src_argb1 - lea esi, [esi + 32] - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 8 - jg convertloop - - pop esi - vzeroupper - ret - } +LIBYUV_TARGET_AVX2 +void ARGBSubtractRow_AVX2(const uint8_t* src_argb, + const uint8_t* src_argb1, + uint8_t* dst_argb, + int width) { + do { + __m256i s0 = _mm256_loadu_si256((const __m256i*)src_argb); + __m256i s1 = _mm256_loadu_si256((const __m256i*)src_argb1); + _mm256_storeu_si256((__m256i*)dst_argb, _mm256_subs_epu8(s0, s1)); + src_argb += 32; + src_argb1 += 32; + dst_argb += 32; + width -= 8; + } while (width > 0); + _mm256_zeroupper(); } #endif // HAS_ARGBSUBTRACTROW_AVX2 -#ifdef HAS_SOBELXROW_SSE2 -// SobelX as a matrix is -// -1 0 1 -// -2 0 2 -// -1 0 1 -__declspec(naked) void SobelXRow_SSE2(const uint8_t* src_y0, - const uint8_t* src_y1, - const uint8_t* src_y2, - uint8_t* dst_sobelx, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_y0 - mov esi, [esp + 8 + 8] // src_y1 - mov edi, [esp + 8 + 12] // src_y2 - mov edx, [esp + 8 + 16] // dst_sobelx - mov ecx, [esp + 8 + 20] // width - sub esi, eax - sub edi, eax - sub edx, eax - pxor xmm5, xmm5 // constant 0 - - convertloop: - movq xmm0, qword ptr [eax] // read 8 pixels from src_y0[0] - movq xmm1, qword ptr [eax + 2] // read 8 pixels from src_y0[2] - punpcklbw xmm0, xmm5 - punpcklbw xmm1, xmm5 - psubw xmm0, xmm1 - movq xmm1, qword ptr [eax + esi] // read 8 pixels from src_y1[0] - movq xmm2, qword ptr [eax + esi + 2] // read 8 pixels from src_y1[2] - punpcklbw xmm1, xmm5 - punpcklbw xmm2, xmm5 - psubw xmm1, xmm2 - movq xmm2, qword ptr [eax + edi] // read 8 pixels from src_y2[0] - movq xmm3, qword ptr [eax + edi + 2] // read 8 pixels from src_y2[2] - punpcklbw xmm2, xmm5 - punpcklbw xmm3, xmm5 - psubw xmm2, xmm3 - paddw xmm0, xmm2 - paddw xmm0, xmm1 - paddw xmm0, xmm1 - pxor xmm1, xmm1 // abs = max(xmm0, -xmm0). SSSE3 could use pabsw - psubw xmm1, xmm0 - pmaxsw xmm0, xmm1 - packuswb xmm0, xmm0 - movq qword ptr [eax + edx], xmm0 - lea eax, [eax + 8] - sub ecx, 8 - jg convertloop - - pop edi - pop esi - ret - } +#ifdef HAS_ARGBCOPYALPHAROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBCopyAlphaRow_AVX2(const uint8_t* src, uint8_t* dst, int width) { + const __m256i mask_alpha = _mm256_set1_epi32((int)0xff000000u); + do { + __m256i s0 = _mm256_loadu_si256((const __m256i*)src); + __m256i s1 = _mm256_loadu_si256((const __m256i*)(src + 32)); + __m256i d0 = _mm256_loadu_si256((const __m256i*)dst); + __m256i d1 = _mm256_loadu_si256((const __m256i*)(dst + 32)); + _mm256_storeu_si256((__m256i*)dst, _mm256_blendv_epi8(d0, s0, mask_alpha)); + _mm256_storeu_si256((__m256i*)(dst + 32), + _mm256_blendv_epi8(d1, s1, mask_alpha)); + src += 64; + dst += 64; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); } -#endif // HAS_SOBELXROW_SSE2 +#endif // HAS_ARGBCOPYALPHAROW_AVX2 -#ifdef HAS_SOBELYROW_SSE2 -// SobelY as a matrix is -// -1 -2 -1 -// 0 0 0 -// 1 2 1 -__declspec(naked) void SobelYRow_SSE2(const uint8_t* src_y0, - const uint8_t* src_y1, - uint8_t* dst_sobely, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_y0 - mov esi, [esp + 4 + 8] // src_y1 - mov edx, [esp + 4 + 12] // dst_sobely - mov ecx, [esp + 4 + 16] // width - sub esi, eax - sub edx, eax - pxor xmm5, xmm5 // constant 0 - - convertloop: - movq xmm0, qword ptr [eax] // read 8 pixels from src_y0[0] - movq xmm1, qword ptr [eax + esi] // read 8 pixels from src_y1[0] - punpcklbw xmm0, xmm5 - punpcklbw xmm1, xmm5 - psubw xmm0, xmm1 - movq xmm1, qword ptr [eax + 1] // read 8 pixels from src_y0[1] - movq xmm2, qword ptr [eax + esi + 1] // read 8 pixels from src_y1[1] - punpcklbw xmm1, xmm5 - punpcklbw xmm2, xmm5 - psubw xmm1, xmm2 - movq xmm2, qword ptr [eax + 2] // read 8 pixels from src_y0[2] - movq xmm3, qword ptr [eax + esi + 2] // read 8 pixels from src_y1[2] - punpcklbw xmm2, xmm5 - punpcklbw xmm3, xmm5 - psubw xmm2, xmm3 - paddw xmm0, xmm2 - paddw xmm0, xmm1 - paddw xmm0, xmm1 - pxor xmm1, xmm1 // abs = max(xmm0, -xmm0). SSSE3 could use pabsw - psubw xmm1, xmm0 - pmaxsw xmm0, xmm1 - packuswb xmm0, xmm0 - movq qword ptr [eax + edx], xmm0 - lea eax, [eax + 8] - sub ecx, 8 - jg convertloop - - pop esi - ret - } +#ifdef HAS_ARGBPOLYNOMIALROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBPolynomialRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + const float* poly, + int width) { + const __m256 c0 = _mm256_broadcast_ps((const __m128*)(poly + 0)); + const __m256 c1 = _mm256_broadcast_ps((const __m128*)(poly + 4)); + const __m256 c2 = _mm256_broadcast_ps((const __m128*)(poly + 8)); + const __m256 c3 = _mm256_broadcast_ps((const __m128*)(poly + 12)); + do { + __m128i s8 = _mm_loadl_epi64((const __m128i*)src_argb); + src_argb += 8; + __m256 x = _mm256_cvtepi32_ps(_mm256_cvtepu8_epi32(s8)); + __m256 x2 = _mm256_mul_ps(x, x); + __m256 res = _mm256_add_ps(c0, _mm256_mul_ps(c1, x)); + res = _mm256_add_ps(res, _mm256_mul_ps(c2, x2)); + res = _mm256_add_ps(res, _mm256_mul_ps(_mm256_mul_ps(c3, x), x2)); + __m256i i32 = _mm256_cvttps_epi32(res); + __m256i u16 = _mm256_permute4x64_epi64(_mm256_packs_epi32(i32, i32), 0xd8); + __m128i u8 = _mm_packus_epi16(_mm256_castsi256_si128(u16), + _mm256_castsi256_si128(u16)); + _mm_storel_epi64((__m128i*)dst_argb, u8); + dst_argb += 8; + width -= 2; + } while (width > 0); + _mm256_zeroupper(); } -#endif // HAS_SOBELYROW_SSE2 +#endif // HAS_ARGBPOLYNOMIALROW_AVX2 -#ifdef HAS_SOBELROW_SSE2 -// Adds Sobel X and Sobel Y and stores Sobel into ARGB. -// A = 255 -// R = Sobel -// G = Sobel -// B = Sobel -__declspec(naked) void SobelRow_SSE2(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_argb, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_sobelx - mov esi, [esp + 4 + 8] // src_sobely - mov edx, [esp + 4 + 12] // dst_argb - mov ecx, [esp + 4 + 16] // width - sub esi, eax - pcmpeqb xmm5, xmm5 // alpha 255 - pslld xmm5, 24 // 0xff000000 - - convertloop: - movdqu xmm0, [eax] // read 16 pixels src_sobelx - movdqu xmm1, [eax + esi] // read 16 pixels src_sobely - lea eax, [eax + 16] - paddusb xmm0, xmm1 // sobel = sobelx + sobely - movdqa xmm2, xmm0 // GG - punpcklbw xmm2, xmm0 // First 8 - punpckhbw xmm0, xmm0 // Next 8 - movdqa xmm1, xmm2 // GGGG - punpcklwd xmm1, xmm2 // First 4 - punpckhwd xmm2, xmm2 // Next 4 - por xmm1, xmm5 // GGGA - por xmm2, xmm5 - movdqa xmm3, xmm0 // GGGG - punpcklwd xmm3, xmm0 // Next 4 - punpckhwd xmm0, xmm0 // Last 4 - por xmm3, xmm5 // GGGA - por xmm0, xmm5 - movdqu [edx], xmm1 - movdqu [edx + 16], xmm2 - movdqu [edx + 32], xmm3 - movdqu [edx + 48], xmm0 - lea edx, [edx + 64] - sub ecx, 16 - jg convertloop - - pop esi - ret - } +#ifdef HAS_ARGBUNATTENUATEROW_AVX2 +LIBYUV_TARGET_AVX2 +void ARGBUnattenuateRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_argb, + int width) { + static const uint8_t kUnattenShuffleAlpha[16] = { + 0u, 1u, 0u, 1u, 0u, 1u, 6u, 7u, 8u, 9u, 8u, 9u, 8u, 9u, 14u, 15u}; + const __m256i ymm_shuf = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kUnattenShuffleAlpha)); + do { + __m256i ymm3 = _mm256_setr_epi32( + (int)fixed_invtbl8[src_argb[3]], (int)fixed_invtbl8[src_argb[7]], + (int)fixed_invtbl8[src_argb[11]], (int)fixed_invtbl8[src_argb[15]], + (int)fixed_invtbl8[src_argb[19]], (int)fixed_invtbl8[src_argb[23]], + (int)fixed_invtbl8[src_argb[27]], (int)fixed_invtbl8[src_argb[31]]); + __m256i ymm6 = _mm256_loadu_si256((const __m256i*)src_argb); + __m256i ymm0 = _mm256_unpacklo_epi8(ymm6, ymm6); + __m256i ymm1 = _mm256_unpackhi_epi8(ymm6, ymm6); + __m256i ymm2 = + _mm256_shuffle_epi8(_mm256_unpacklo_epi16(ymm3, ymm3), ymm_shuf); + ymm3 = _mm256_shuffle_epi8(_mm256_unpackhi_epi16(ymm3, ymm3), ymm_shuf); + ymm0 = _mm256_mulhi_epu16(ymm0, ymm2); + ymm1 = _mm256_mulhi_epu16(ymm1, ymm3); + _mm256_storeu_si256((__m256i*)dst_argb, _mm256_packus_epi16(ymm0, ymm1)); + src_argb += 32; + dst_argb += 32; + width -= 8; + } while (width > 0); + _mm256_zeroupper(); } -#endif // HAS_SOBELROW_SSE2 +#endif // HAS_ARGBUNATTENUATEROW_AVX2 -#ifdef HAS_SOBELTOPLANEROW_SSE2 -// Adds Sobel X and Sobel Y and stores Sobel into a plane. -__declspec(naked) void SobelToPlaneRow_SSE2(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_y, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_sobelx - mov esi, [esp + 4 + 8] // src_sobely - mov edx, [esp + 4 + 12] // dst_argb - mov ecx, [esp + 4 + 16] // width - sub esi, eax +#ifdef HAS_COMPUTECUMULATIVESUMROW_AVX2 +LIBYUV_TARGET_AVX2 +void ComputeCumulativeSumRow_AVX2(const uint8_t* row, + int32_t* cumsum, + const int32_t* previous_cumsum, + int width) { + static const uint8_t kCumSumTranspose[16] = {0, 4, 8, 12, 1, 5, 9, 13, + 2, 6, 10, 14, 3, 7, 11, 15}; + static const int8_t kCumSumMaddLo[32] = { + 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, + 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0}; + static const int8_t kCumSumMaddHi[32] = { + 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + __m256i ymm0 = _mm256_setzero_si256(); + const __m256i ymm5 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kCumSumTranspose)); + const __m256i ymm6 = _mm256_loadu_si256((const __m256i*)kCumSumMaddLo); + const __m256i ymm7 = _mm256_loadu_si256((const __m256i*)kCumSumMaddHi); + const __m256i ymm8 = _mm256_set1_epi16(1); - convertloop: - movdqu xmm0, [eax] // read 16 pixels src_sobelx - movdqu xmm1, [eax + esi] // read 16 pixels src_sobely - lea eax, [eax + 16] - paddusb xmm0, xmm1 // sobel = sobelx + sobely - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg convertloop - - pop esi - ret + while (width >= 4) { + __m256i ymm2 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)row)); + row += 16; + ymm2 = _mm256_shuffle_epi8(ymm2, ymm5); + __m256i ymm3 = _mm256_madd_epi16(_mm256_maddubs_epi16(ymm2, ymm6), ymm8); + __m256i ymm4 = _mm256_madd_epi16(_mm256_maddubs_epi16(ymm2, ymm7), ymm8); + __m256i sum4 = _mm256_permute2x128_si256(ymm4, ymm4, 0x11); + ymm3 = _mm256_add_epi32( + _mm256_add_epi32(ymm3, + _mm256_loadu_si256((const __m256i*)previous_cumsum)), + ymm0); + ymm4 = _mm256_add_epi32( + _mm256_add_epi32( + ymm4, _mm256_loadu_si256((const __m256i*)(previous_cumsum + 8))), + ymm0); + previous_cumsum += 16; + ymm0 = _mm256_add_epi32(ymm0, sum4); + _mm256_storeu_si256((__m256i*)cumsum, ymm3); + _mm256_storeu_si256((__m256i*)(cumsum + 8), ymm4); + cumsum += 16; + width -= 4; } -} -#endif // HAS_SOBELTOPLANEROW_SSE2 -#ifdef HAS_SOBELXYROW_SSE2 -// Mixes Sobel X, Sobel Y and Sobel into ARGB. -// A = 255 -// R = Sobel X -// G = Sobel -// B = Sobel Y -__declspec(naked) void SobelXYRow_SSE2(const uint8_t* src_sobelx, - const uint8_t* src_sobely, - uint8_t* dst_argb, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_sobelx - mov esi, [esp + 4 + 8] // src_sobely - mov edx, [esp + 4 + 12] // dst_argb - mov ecx, [esp + 4 + 16] // width - sub esi, eax - pcmpeqb xmm5, xmm5 // alpha 255 - - convertloop: - movdqu xmm0, [eax] // read 16 pixels src_sobelx - movdqu xmm1, [eax + esi] // read 16 pixels src_sobely - lea eax, [eax + 16] - movdqa xmm2, xmm0 - paddusb xmm2, xmm1 // sobel = sobelx + sobely - movdqa xmm3, xmm0 // XA - punpcklbw xmm3, xmm5 - punpckhbw xmm0, xmm5 - movdqa xmm4, xmm1 // YS - punpcklbw xmm4, xmm2 - punpckhbw xmm1, xmm2 - movdqa xmm6, xmm4 // YSXA - punpcklwd xmm6, xmm3 // First 4 - punpckhwd xmm4, xmm3 // Next 4 - movdqa xmm7, xmm1 // YSXA - punpcklwd xmm7, xmm0 // Next 4 - punpckhwd xmm1, xmm0 // Last 4 - movdqu [edx], xmm6 - movdqu [edx + 16], xmm4 - movdqu [edx + 32], xmm7 - movdqu [edx + 48], xmm1 - lea edx, [edx + 64] - sub ecx, 16 - jg convertloop - - pop esi - ret + __m128i xmm0 = _mm256_castsi256_si128(ymm0); + while (width > 0) { + int32_t px; + memcpy(&px, row, sizeof(px)); + row += 4; + __m128i xmm2 = _mm_cvtepu8_epi32(_mm_cvtsi32_si128(px)); + xmm0 = _mm_add_epi32(xmm0, xmm2); + xmm2 = _mm_add_epi32(xmm0, + _mm_loadu_si128((const __m128i*)previous_cumsum)); + previous_cumsum += 4; + _mm_storeu_si128((__m128i*)cumsum, xmm2); + cumsum += 4; + --width; } + _mm256_zeroupper(); } -#endif // HAS_SOBELXYROW_SSE2 +#endif // HAS_COMPUTECUMULATIVESUMROW_AVX2 -#ifdef HAS_CUMULATIVESUMTOAVERAGEROW_SSE2 -// Consider float CumulativeSum. -// Consider calling CumulativeSum one row at time as needed. -// Consider circular CumulativeSum buffer of radius * 2 + 1 height. -// Convert cumulative sum for an area to an average for 1 pixel. -// topleft is pointer to top left of CumulativeSum buffer for area. -// botleft is pointer to bottom left of CumulativeSum buffer. -// width is offset from left to right of area in CumulativeSum buffer measured -// in number of ints. -// area is the number of pixels in the area being averaged. -// dst points to pixel to store result to. -// count is number of averaged pixels to produce. -// Does 4 pixels at a time. -// This function requires alignment on accumulation buffer pointers. -void CumulativeSumToAverageRow_SSE2(const int32_t* topleft, +#ifdef HAS_CUMULATIVESUMTOAVERAGEROW_AVX2 +LIBYUV_TARGET_AVX2 +void CumulativeSumToAverageRow_AVX2(const int32_t* topleft, const int32_t* botleft, int width, int area, uint8_t* dst, int count) { - __asm { - mov eax, topleft // eax topleft - mov esi, botleft // esi botleft - mov edx, width - movd xmm5, area - mov edi, dst - mov ecx, count - cvtdq2ps xmm5, xmm5 - rcpss xmm4, xmm5 // 1.0f / area - pshufd xmm4, xmm4, 0 - sub ecx, 4 - jl l4b + __m128 xmm5 = _mm_cvtsi32_ss(_mm_setzero_ps(), area); + __m128 xmm4 = _mm_div_ss(_mm_set_ss(1.0f), xmm5); + xmm4 = _mm_shuffle_ps(xmm4, xmm4, 0); - cmp area, 128 // 128 pixels will not overflow 15 bits. - ja l4 + if (count >= 4) { + __m256 ymm4 = _mm256_insertf128_ps(_mm256_castps128_ps256(xmm4), xmm4, 1); + if (area > 1 && area <= 0x80) { + __m128 xmm6 = _mm_cvtepi32_ps(_mm_set1_epi32(0x0000ffff)); + xmm6 = _mm_mul_ss(_mm_add_ss(xmm5, xmm6), xmm4); + __m128i i6 = _mm_cvtps_epi32(xmm6); + i6 = _mm_packus_epi32(i6, i6); + __m256i ymm6 = _mm256_broadcastw_epi16(i6); + while (count >= 4) { + __m256i ymm0 = _mm256_sub_epi32( + _mm256_loadu_si256((const __m256i*)topleft), + _mm256_loadu_si256((const __m256i*)(topleft + width))); + __m256i ymm1 = _mm256_sub_epi32( + _mm256_loadu_si256((const __m256i*)(topleft + 8)), + _mm256_loadu_si256((const __m256i*)(topleft + width + 8))); + topleft += 16; + ymm0 = _mm256_sub_epi32(ymm0, + _mm256_loadu_si256((const __m256i*)botleft)); + ymm1 = _mm256_sub_epi32( + ymm1, _mm256_loadu_si256((const __m256i*)(botleft + 8))); + ymm0 = _mm256_add_epi32( + ymm0, _mm256_loadu_si256((const __m256i*)(botleft + width))); + ymm1 = _mm256_add_epi32( + ymm1, _mm256_loadu_si256((const __m256i*)(botleft + width + 8))); + botleft += 16; + ymm0 = _mm256_mulhi_epu16(_mm256_packus_epi32(ymm0, ymm1), ymm6); + __m128i out = _mm_packus_epi16(_mm256_castsi256_si128(ymm0), + _mm256_extracti128_si256(ymm0, 1)); + _mm_storeu_si128((__m128i*)dst, _mm_shuffle_epi32(out, 0xd8)); + dst += 16; + count -= 4; + } + } else { + while (count >= 4) { + __m256i ymm0 = _mm256_sub_epi32( + _mm256_loadu_si256((const __m256i*)topleft), + _mm256_loadu_si256((const __m256i*)(topleft + width))); + __m256i ymm1 = _mm256_sub_epi32( + _mm256_loadu_si256((const __m256i*)(topleft + 8)), + _mm256_loadu_si256((const __m256i*)(topleft + width + 8))); + topleft += 16; + ymm0 = _mm256_sub_epi32(ymm0, + _mm256_loadu_si256((const __m256i*)botleft)); + ymm1 = _mm256_sub_epi32( + ymm1, _mm256_loadu_si256((const __m256i*)(botleft + 8))); + ymm0 = _mm256_add_epi32( + ymm0, _mm256_loadu_si256((const __m256i*)(botleft + width))); + ymm1 = _mm256_add_epi32( + ymm1, _mm256_loadu_si256((const __m256i*)(botleft + width + 8))); + botleft += 16; + ymm0 = + _mm256_cvttps_epi32(_mm256_mul_ps(_mm256_cvtepi32_ps(ymm0), ymm4)); + ymm1 = + _mm256_cvttps_epi32(_mm256_mul_ps(_mm256_cvtepi32_ps(ymm1), ymm4)); + ymm0 = _mm256_packus_epi32(ymm0, ymm1); + __m128i out = _mm_packus_epi16(_mm256_castsi256_si128(ymm0), + _mm256_extracti128_si256(ymm0, 1)); + _mm_storeu_si128((__m128i*)dst, _mm_shuffle_epi32(out, 0xd8)); + dst += 16; + count -= 4; + } + } + _mm256_zeroupper(); + } - pshufd xmm5, xmm5, 0 // area - pcmpeqb xmm6, xmm6 // constant of 65536.0 - 1 = 65535.0 - psrld xmm6, 16 - cvtdq2ps xmm6, xmm6 - addps xmm5, xmm6 // (65536.0 + area - 1) - mulps xmm5, xmm4 // (65536.0 + area - 1) * 1 / area - cvtps2dq xmm5, xmm5 // 0.16 fixed point - packssdw xmm5, xmm5 // 16 bit shorts - - // 4 pixel loop small blocks. - s4: - // top left - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + 32] - movdqu xmm3, [eax + 48] - - // - top right - psubd xmm0, [eax + edx * 4] - psubd xmm1, [eax + edx * 4 + 16] - psubd xmm2, [eax + edx * 4 + 32] - psubd xmm3, [eax + edx * 4 + 48] - lea eax, [eax + 64] - - // - bottom left - psubd xmm0, [esi] - psubd xmm1, [esi + 16] - psubd xmm2, [esi + 32] - psubd xmm3, [esi + 48] - - // + bottom right - paddd xmm0, [esi + edx * 4] - paddd xmm1, [esi + edx * 4 + 16] - paddd xmm2, [esi + edx * 4 + 32] - paddd xmm3, [esi + edx * 4 + 48] - lea esi, [esi + 64] - - packssdw xmm0, xmm1 // pack 4 pixels into 2 registers - packssdw xmm2, xmm3 - - pmulhuw xmm0, xmm5 - pmulhuw xmm2, xmm5 - - packuswb xmm0, xmm2 - movdqu [edi], xmm0 - lea edi, [edi + 16] - sub ecx, 4 - jge s4 - - jmp l4b - - // 4 pixel loop - l4: - // top left - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + 32] - movdqu xmm3, [eax + 48] - - // - top right - psubd xmm0, [eax + edx * 4] - psubd xmm1, [eax + edx * 4 + 16] - psubd xmm2, [eax + edx * 4 + 32] - psubd xmm3, [eax + edx * 4 + 48] - lea eax, [eax + 64] - - // - bottom left - psubd xmm0, [esi] - psubd xmm1, [esi + 16] - psubd xmm2, [esi + 32] - psubd xmm3, [esi + 48] - - // + bottom right - paddd xmm0, [esi + edx * 4] - paddd xmm1, [esi + edx * 4 + 16] - paddd xmm2, [esi + edx * 4 + 32] - paddd xmm3, [esi + edx * 4 + 48] - lea esi, [esi + 64] - - cvtdq2ps xmm0, xmm0 // Average = Sum * 1 / Area - cvtdq2ps xmm1, xmm1 - mulps xmm0, xmm4 - mulps xmm1, xmm4 - cvtdq2ps xmm2, xmm2 - cvtdq2ps xmm3, xmm3 - mulps xmm2, xmm4 - mulps xmm3, xmm4 - cvtps2dq xmm0, xmm0 - cvtps2dq xmm1, xmm1 - cvtps2dq xmm2, xmm2 - cvtps2dq xmm3, xmm3 - packssdw xmm0, xmm1 - packssdw xmm2, xmm3 - packuswb xmm0, xmm2 - movdqu [edi], xmm0 - lea edi, [edi + 16] - sub ecx, 4 - jge l4 - - l4b: - add ecx, 4 - 1 - jl l1b - - // 1 pixel loop - l1: - movdqu xmm0, [eax] - psubd xmm0, [eax + edx * 4] - lea eax, [eax + 16] - psubd xmm0, [esi] - paddd xmm0, [esi + edx * 4] - lea esi, [esi + 16] - cvtdq2ps xmm0, xmm0 - mulps xmm0, xmm4 - cvtps2dq xmm0, xmm0 - packssdw xmm0, xmm0 - packuswb xmm0, xmm0 - movd dword ptr [edi], xmm0 - lea edi, [edi + 4] - sub ecx, 1 - jge l1 - l1b: + while (count > 0) { + __m128i d0 = _mm_sub_epi32( + _mm_loadu_si128((const __m128i*)topleft), + _mm_loadu_si128((const __m128i*)(topleft + width))); + topleft += 4; + __m128i d1 = _mm_sub_epi32( + _mm_loadu_si128((const __m128i*)(botleft + width)), + _mm_loadu_si128((const __m128i*)botleft)); + botleft += 4; + d0 = _mm_add_epi32(d0, d1); + d0 = _mm_cvttps_epi32(_mm_mul_ps(_mm_cvtepi32_ps(d0), xmm4)); + d0 = _mm_packus_epi32(d0, d0); + d0 = _mm_packus_epi16(d0, d0); + int32_t out32 = _mm_cvtsi128_si32(d0); + memcpy(dst, &out32, sizeof(out32)); + dst += 4; + --count; } } -#endif // HAS_CUMULATIVESUMTOAVERAGEROW_SSE2 +#endif // HAS_CUMULATIVESUMTOAVERAGEROW_AVX2 -#ifdef HAS_COMPUTECUMULATIVESUMROW_SSE2 -// Creates a table of cumulative sums where each value is a sum of all values -// above and to the left of the value. -void ComputeCumulativeSumRow_SSE2(const uint8_t* row, - int32_t* cumsum, - const int32_t* previous_cumsum, - int width) { - __asm { - mov eax, row - mov edx, cumsum - mov esi, previous_cumsum - mov ecx, width - pxor xmm0, xmm0 - pxor xmm1, xmm1 - - sub ecx, 4 - jl l4b - test edx, 15 - jne l4b - - // 4 pixel loop - l4: - movdqu xmm2, [eax] // 4 argb pixels 16 bytes. - lea eax, [eax + 16] - movdqa xmm4, xmm2 - - punpcklbw xmm2, xmm1 - movdqa xmm3, xmm2 - punpcklwd xmm2, xmm1 - punpckhwd xmm3, xmm1 - - punpckhbw xmm4, xmm1 - movdqa xmm5, xmm4 - punpcklwd xmm4, xmm1 - punpckhwd xmm5, xmm1 - - paddd xmm0, xmm2 - movdqu xmm2, [esi] // previous row above. - paddd xmm2, xmm0 - - paddd xmm0, xmm3 - movdqu xmm3, [esi + 16] - paddd xmm3, xmm0 - - paddd xmm0, xmm4 - movdqu xmm4, [esi + 32] - paddd xmm4, xmm0 - - paddd xmm0, xmm5 - movdqu xmm5, [esi + 48] - lea esi, [esi + 64] - paddd xmm5, xmm0 - - movdqu [edx], xmm2 - movdqu [edx + 16], xmm3 - movdqu [edx + 32], xmm4 - movdqu [edx + 48], xmm5 - - lea edx, [edx + 64] - sub ecx, 4 - jge l4 - - l4b: - add ecx, 4 - 1 - jl l1b - - // 1 pixel loop - l1: - movd xmm2, dword ptr [eax] // 1 argb pixel - lea eax, [eax + 4] - punpcklbw xmm2, xmm1 - punpcklwd xmm2, xmm1 - paddd xmm0, xmm2 - movdqu xmm2, [esi] - lea esi, [esi + 16] - paddd xmm2, xmm0 - movdqu [edx], xmm2 - lea edx, [edx + 16] - sub ecx, 1 - jge l1 - - l1b: - } +#ifdef HAS_I422TOYUY2ROW_AVX2 +LIBYUV_TARGET_AVX2 +void I422ToYUY2Row_AVX2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_yuy2, + int width) { + do { + __m128i u = _mm_loadu_si128((const __m128i*)src_u); + __m128i v = _mm_loadu_si128((const __m128i*)src_v); + __m256i uv = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(u, v)), + _mm_unpackhi_epi8(u, v), 1); + __m256i y = _mm256_loadu_si256((const __m256i*)src_y); + __m256i lo = _mm256_unpacklo_epi8(y, uv); + __m256i hi = _mm256_unpackhi_epi8(y, uv); + _mm256_storeu_si256((__m256i*)dst_yuy2, + _mm256_permute2x128_si256(lo, hi, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_yuy2 + 32), + _mm256_permute2x128_si256(lo, hi, 0x31)); + src_y += 32; + src_u += 16; + src_v += 16; + dst_yuy2 += 64; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); } -#endif // HAS_COMPUTECUMULATIVESUMROW_SSE2 +#endif // HAS_I422TOYUY2ROW_AVX2 -#ifdef HAS_ARGBAFFINEROW_SSE2 -// Copy ARGB pixels from source image with slope to a row of destination. -__declspec(naked) LIBYUV_API void ARGBAffineRow_SSE2(const uint8_t* src_argb, - int src_argb_stride, - uint8_t* dst_argb, - const float* uv_dudv, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 12] // src_argb - mov esi, [esp + 16] // stride - mov edx, [esp + 20] // dst_argb - mov ecx, [esp + 24] // pointer to uv_dudv - movq xmm2, qword ptr [ecx] // uv - movq xmm7, qword ptr [ecx + 8] // dudv - mov ecx, [esp + 28] // width - shl esi, 16 // 4, stride - add esi, 4 - movd xmm5, esi - sub ecx, 4 - jl l4b - - // setup for 4 pixel loop - pshufd xmm7, xmm7, 0x44 // dup dudv - pshufd xmm5, xmm5, 0 // dup 4, stride - movdqa xmm0, xmm2 // x0, y0, x1, y1 - addps xmm0, xmm7 - movlhps xmm2, xmm0 - movdqa xmm4, xmm7 - addps xmm4, xmm4 // dudv *= 2 - movdqa xmm3, xmm2 // x2, y2, x3, y3 - addps xmm3, xmm4 - addps xmm4, xmm4 // dudv *= 4 - - // 4 pixel loop - l4: - cvttps2dq xmm0, xmm2 // x, y float to int first 2 - cvttps2dq xmm1, xmm3 // x, y float to int next 2 - packssdw xmm0, xmm1 // x, y as 8 shorts - pmaddwd xmm0, xmm5 // offsets = x * 4 + y * stride. - movd esi, xmm0 - pshufd xmm0, xmm0, 0x39 // shift right - movd edi, xmm0 - pshufd xmm0, xmm0, 0x39 // shift right - movd xmm1, [eax + esi] // read pixel 0 - movd xmm6, [eax + edi] // read pixel 1 - punpckldq xmm1, xmm6 // combine pixel 0 and 1 - addps xmm2, xmm4 // x, y += dx, dy first 2 - movq qword ptr [edx], xmm1 - movd esi, xmm0 - pshufd xmm0, xmm0, 0x39 // shift right - movd edi, xmm0 - movd xmm6, [eax + esi] // read pixel 2 - movd xmm0, [eax + edi] // read pixel 3 - punpckldq xmm6, xmm0 // combine pixel 2 and 3 - addps xmm3, xmm4 // x, y += dx, dy next 2 - movq qword ptr 8[edx], xmm6 - lea edx, [edx + 16] - sub ecx, 4 - jge l4 - - l4b: - add ecx, 4 - 1 - jl l1b - - // 1 pixel loop - l1: - cvttps2dq xmm0, xmm2 // x, y float to int - packssdw xmm0, xmm0 // x, y as shorts - pmaddwd xmm0, xmm5 // offset = x * 4 + y * stride - addps xmm2, xmm7 // x, y += dx, dy - movd esi, xmm0 - movd xmm0, [eax + esi] // copy a pixel - movd [edx], xmm0 - lea edx, [edx + 4] - sub ecx, 1 - jge l1 - l1b: - pop edi - pop esi - ret - } +#ifdef HAS_I422TOUYVYROW_AVX2 +LIBYUV_TARGET_AVX2 +void I422ToUYVYRow_AVX2(const uint8_t* src_y, + const uint8_t* src_u, + const uint8_t* src_v, + uint8_t* dst_uyvy, + int width) { + do { + __m128i u = _mm_loadu_si128((const __m128i*)src_u); + __m128i v = _mm_loadu_si128((const __m128i*)src_v); + __m256i uv = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(u, v)), + _mm_unpackhi_epi8(u, v), 1); + __m256i y = _mm256_loadu_si256((const __m256i*)src_y); + __m256i lo = _mm256_unpacklo_epi8(uv, y); + __m256i hi = _mm256_unpackhi_epi8(uv, y); + _mm256_storeu_si256((__m256i*)dst_uyvy, + _mm256_permute2x128_si256(lo, hi, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_uyvy + 32), + _mm256_permute2x128_si256(lo, hi, 0x31)); + src_y += 32; + src_u += 16; + src_v += 16; + dst_uyvy += 64; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); } -#endif // HAS_ARGBAFFINEROW_SSE2 +#endif // HAS_I422TOUYVYROW_AVX2 -#ifdef HAS_INTERPOLATEROW_AVX2 -// Bilinear filter 32x2 -> 32x1 -__declspec(naked) void InterpolateRow_AVX2(uint8_t* dst_ptr, - const uint8_t* src_ptr, - ptrdiff_t src_stride, - int dst_width, - int source_y_fraction) { - __asm { - push esi - push edi - mov edi, [esp + 8 + 4] // dst_ptr - mov esi, [esp + 8 + 8] // src_ptr - mov edx, [esp + 8 + 12] // src_stride - mov ecx, [esp + 8 + 16] // dst_width - mov eax, [esp + 8 + 20] // source_y_fraction (0..255) - // Dispatch to specialized filters if applicable. - cmp eax, 0 - je xloop100 // 0 / 256. Blend 100 / 0. - sub edi, esi - cmp eax, 128 - je xloop50 // 128 /256 is 0.50. Blend 50 / 50. - - vmovd xmm0, eax // high fraction 0..255 - neg eax - add eax, 256 - vmovd xmm5, eax // low fraction 256..1 - vpunpcklbw xmm5, xmm5, xmm0 - vpunpcklwd xmm5, xmm5, xmm5 - vbroadcastss ymm5, xmm5 - - mov eax, 0x80808080 // 128b for bias and rounding. - vmovd xmm4, eax - vbroadcastss ymm4, xmm4 - - xloop: - vmovdqu ymm0, [esi] - vmovdqu ymm2, [esi + edx] - vpunpckhbw ymm1, ymm0, ymm2 // mutates - vpunpcklbw ymm0, ymm0, ymm2 - vpsubb ymm1, ymm1, ymm4 // bias to signed image - vpsubb ymm0, ymm0, ymm4 - vpmaddubsw ymm1, ymm5, ymm1 - vpmaddubsw ymm0, ymm5, ymm0 - vpaddw ymm1, ymm1, ymm4 // unbias and round - vpaddw ymm0, ymm0, ymm4 - vpsrlw ymm1, ymm1, 8 - vpsrlw ymm0, ymm0, 8 - vpackuswb ymm0, ymm0, ymm1 // unmutates - vmovdqu [esi + edi], ymm0 - lea esi, [esi + 32] - sub ecx, 32 - jg xloop - jmp xloop99 - - // Blend 50 / 50. - xloop50: - vmovdqu ymm0, [esi] - vpavgb ymm0, ymm0, [esi + edx] - vmovdqu [esi + edi], ymm0 - lea esi, [esi + 32] - sub ecx, 32 - jg xloop50 - jmp xloop99 - - // Blend 100 / 0 - Copy row unchanged. - xloop100: - rep movsb - - xloop99: - pop edi - pop esi - vzeroupper - ret - } +#ifdef HAS_MERGEARGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void MergeARGBRow_AVX2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + const uint8_t* src_a, + uint8_t* dst_argb, + int width) { + do { + __m128i r = _mm_loadu_si128((const __m128i*)src_r); + __m128i g = _mm_loadu_si128((const __m128i*)src_g); + __m128i b = _mm_loadu_si128((const __m128i*)src_b); + __m128i a = _mm_loadu_si128((const __m128i*)src_a); + __m256i bg = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(b, g)), + _mm_unpackhi_epi8(b, g), 1); + __m256i ra = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(r, a)), + _mm_unpackhi_epi8(r, a), 1); + __m256i lo = _mm256_unpacklo_epi16(bg, ra); + __m256i hi = _mm256_unpackhi_epi16(bg, ra); + _mm256_storeu_si256((__m256i*)dst_argb, + _mm256_permute2x128_si256(lo, hi, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), + _mm256_permute2x128_si256(lo, hi, 0x31)); + src_r += 16; + src_g += 16; + src_b += 16; + src_a += 16; + dst_argb += 64; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); } -#endif // HAS_INTERPOLATEROW_AVX2 +#endif // HAS_MERGEARGBROW_AVX2 -// Bilinear filter 16x2 -> 16x1 -// TODO(fbarchard): Consider allowing 256 using memcpy. -__declspec(naked) void InterpolateRow_SSSE3(uint8_t* dst_ptr, - const uint8_t* src_ptr, - ptrdiff_t src_stride, - int dst_width, - int source_y_fraction) { - __asm { - push esi - push edi - - mov edi, [esp + 8 + 4] // dst_ptr - mov esi, [esp + 8 + 8] // src_ptr - mov edx, [esp + 8 + 12] // src_stride - mov ecx, [esp + 8 + 16] // dst_width - mov eax, [esp + 8 + 20] // source_y_fraction (0..255) - sub edi, esi - // Dispatch to specialized filters if applicable. - cmp eax, 0 - je xloop100 // 0 /256. Blend 100 / 0. - cmp eax, 128 - je xloop50 // 128 / 256 is 0.50. Blend 50 / 50. - - movd xmm0, eax // high fraction 0..255 - neg eax - add eax, 256 - movd xmm5, eax // low fraction 255..1 - punpcklbw xmm5, xmm0 - punpcklwd xmm5, xmm5 - pshufd xmm5, xmm5, 0 - mov eax, 0x80808080 // 128 for biasing image to signed. - movd xmm4, eax - pshufd xmm4, xmm4, 0x00 - - xloop: - movdqu xmm0, [esi] - movdqu xmm2, [esi + edx] - movdqu xmm1, xmm0 - punpcklbw xmm0, xmm2 - punpckhbw xmm1, xmm2 - psubb xmm0, xmm4 // bias image by -128 - psubb xmm1, xmm4 - movdqa xmm2, xmm5 - movdqa xmm3, xmm5 - pmaddubsw xmm2, xmm0 - pmaddubsw xmm3, xmm1 - paddw xmm2, xmm4 - paddw xmm3, xmm4 - psrlw xmm2, 8 - psrlw xmm3, 8 - packuswb xmm2, xmm3 - movdqu [esi + edi], xmm2 - lea esi, [esi + 16] - sub ecx, 16 - jg xloop - jmp xloop99 - - // Blend 50 / 50. - xloop50: - movdqu xmm0, [esi] - movdqu xmm1, [esi + edx] - pavgb xmm0, xmm1 - movdqu [esi + edi], xmm0 - lea esi, [esi + 16] - sub ecx, 16 - jg xloop50 - jmp xloop99 - - // Blend 100 / 0 - Copy row unchanged. - xloop100: - movdqu xmm0, [esi] - movdqu [esi + edi], xmm0 - lea esi, [esi + 16] - sub ecx, 16 - jg xloop100 - - xloop99: - pop edi - pop esi - ret - } +#ifdef HAS_MERGEXRGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void MergeXRGBRow_AVX2(const uint8_t* src_r, + const uint8_t* src_g, + const uint8_t* src_b, + uint8_t* dst_argb, + int width) { + const __m128i a = _mm_set1_epi8((char)0xff); + do { + __m128i r = _mm_loadu_si128((const __m128i*)src_r); + __m128i g = _mm_loadu_si128((const __m128i*)src_g); + __m128i b = _mm_loadu_si128((const __m128i*)src_b); + __m256i bg = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(b, g)), + _mm_unpackhi_epi8(b, g), 1); + __m256i ra = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(r, a)), + _mm_unpackhi_epi8(r, a), 1); + __m256i lo = _mm256_unpacklo_epi16(bg, ra); + __m256i hi = _mm256_unpackhi_epi16(bg, ra); + _mm256_storeu_si256((__m256i*)dst_argb, + _mm256_permute2x128_si256(lo, hi, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), + _mm256_permute2x128_si256(lo, hi, 0x31)); + src_r += 16; + src_g += 16; + src_b += 16; + dst_argb += 64; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); } +#endif // HAS_MERGEXRGBROW_AVX2 -// For BGRAToARGB, ABGRToARGB, RGBAToARGB, and ARGBToRGBA. -__declspec(naked) void ARGBShuffleRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_argb, - const uint8_t* shuffler, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // shuffler - movdqu xmm5, [ecx] - mov ecx, [esp + 16] // width - - wloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - lea eax, [eax + 32] - pshufb xmm0, xmm5 - pshufb xmm1, xmm5 - movdqu [edx], xmm0 - movdqu [edx + 16], xmm1 - lea edx, [edx + 32] - sub ecx, 8 - jg wloop - ret - } +#ifdef HAS_MERGEARGB16TO8ROW_AVX2 +LIBYUV_TARGET_AVX2 +void MergeARGB16To8Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint8_t* dst_argb, + int depth, + int width) { + const __m128i shift128 = _mm_cvtsi32_si128(depth - 8); + const __m256i ymm_255 = _mm256_set1_epi16(255); + do { + __m256i r16 = _mm256_min_epu16( + _mm256_srl_epi16(_mm256_loadu_si256((const __m256i*)src_r), shift128), + ymm_255); + __m256i g16 = _mm256_min_epu16( + _mm256_srl_epi16(_mm256_loadu_si256((const __m256i*)src_g), shift128), + ymm_255); + __m256i b16 = _mm256_min_epu16( + _mm256_srl_epi16(_mm256_loadu_si256((const __m256i*)src_b), shift128), + ymm_255); + __m256i a16 = _mm256_min_epu16( + _mm256_srl_epi16(_mm256_loadu_si256((const __m256i*)src_a), shift128), + ymm_255); + __m256i br8 = + _mm256_permute4x64_epi64(_mm256_packus_epi16(b16, r16), 0xd8); + __m256i ga8 = + _mm256_permute4x64_epi64(_mm256_packus_epi16(g16, a16), 0xd8); + __m128i b = _mm256_castsi256_si128(br8); + __m128i r = _mm256_extracti128_si256(br8, 1); + __m128i g = _mm256_castsi256_si128(ga8); + __m128i a = _mm256_extracti128_si256(ga8, 1); + __m256i bg = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(b, g)), + _mm_unpackhi_epi8(b, g), 1); + __m256i ra = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(r, a)), + _mm_unpackhi_epi8(r, a), 1); + __m256i lo = _mm256_unpacklo_epi16(bg, ra); + __m256i hi = _mm256_unpackhi_epi16(bg, ra); + _mm256_storeu_si256((__m256i*)dst_argb, + _mm256_permute2x128_si256(lo, hi, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), + _mm256_permute2x128_si256(lo, hi, 0x31)); + src_r += 16; + src_g += 16; + src_b += 16; + src_a += 16; + dst_argb += 64; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); } +#endif // HAS_MERGEARGB16TO8ROW_AVX2 -#ifdef HAS_ARGBSHUFFLEROW_AVX2 -__declspec(naked) void ARGBShuffleRow_AVX2(const uint8_t* src_argb, - uint8_t* dst_argb, - const uint8_t* shuffler, - int width) { - __asm { - mov eax, [esp + 4] // src_argb - mov edx, [esp + 8] // dst_argb - mov ecx, [esp + 12] // shuffler - vbroadcastf128 ymm5, [ecx] // same shuffle in high as low. - mov ecx, [esp + 16] // width - - wloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - lea eax, [eax + 64] - vpshufb ymm0, ymm0, ymm5 - vpshufb ymm1, ymm1, ymm5 - vmovdqu [edx], ymm0 - vmovdqu [edx + 32], ymm1 - lea edx, [edx + 64] - sub ecx, 16 - jg wloop - - vzeroupper - ret - } +#ifdef HAS_MERGEXRGB16TO8ROW_AVX2 +LIBYUV_TARGET_AVX2 +void MergeXRGB16To8Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_argb, + int depth, + int width) { + const __m128i shift128 = _mm_cvtsi32_si128(depth - 8); + const __m256i ymm_255 = _mm256_set1_epi16(255); + const __m128i a = _mm_set1_epi8((char)0xff); + do { + __m256i r16 = _mm256_min_epu16( + _mm256_srl_epi16(_mm256_loadu_si256((const __m256i*)src_r), shift128), + ymm_255); + __m256i g16 = _mm256_min_epu16( + _mm256_srl_epi16(_mm256_loadu_si256((const __m256i*)src_g), shift128), + ymm_255); + __m256i b16 = _mm256_min_epu16( + _mm256_srl_epi16(_mm256_loadu_si256((const __m256i*)src_b), shift128), + ymm_255); + __m256i br8 = + _mm256_permute4x64_epi64(_mm256_packus_epi16(b16, r16), 0xd8); + __m256i g8 = + _mm256_permute4x64_epi64(_mm256_packus_epi16(g16, g16), 0xd8); + __m128i b = _mm256_castsi256_si128(br8); + __m128i r = _mm256_extracti128_si256(br8, 1); + __m128i g = _mm256_castsi256_si128(g8); + __m256i bg = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(b, g)), + _mm_unpackhi_epi8(b, g), 1); + __m256i ra = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(r, a)), + _mm_unpackhi_epi8(r, a), 1); + __m256i lo = _mm256_unpacklo_epi16(bg, ra); + __m256i hi = _mm256_unpackhi_epi16(bg, ra); + _mm256_storeu_si256((__m256i*)dst_argb, + _mm256_permute2x128_si256(lo, hi, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), + _mm256_permute2x128_si256(lo, hi, 0x31)); + src_r += 16; + src_g += 16; + src_b += 16; + dst_argb += 64; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); } -#endif // HAS_ARGBSHUFFLEROW_AVX2 +#endif // HAS_MERGEXRGB16TO8ROW_AVX2 -// YUY2 - Macro-pixel = 2 image pixels -// Y0U0Y1V0....Y2U2Y3V2...Y4U4Y5V4.... - -// UYVY - Macro-pixel = 2 image pixels -// U0Y0V0Y1 - -__declspec(naked) void I422ToYUY2Row_SSE2(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_frame, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_y - mov esi, [esp + 8 + 8] // src_u - mov edx, [esp + 8 + 12] // src_v - mov edi, [esp + 8 + 16] // dst_frame - mov ecx, [esp + 8 + 20] // width - sub edx, esi - - convertloop: - movq xmm2, qword ptr [esi] // U - movq xmm3, qword ptr [esi + edx] // V - lea esi, [esi + 8] - punpcklbw xmm2, xmm3 // UV - movdqu xmm0, [eax] // Y - lea eax, [eax + 16] - movdqa xmm1, xmm0 - punpcklbw xmm0, xmm2 // YUYV - punpckhbw xmm1, xmm2 - movdqu [edi], xmm0 - movdqu [edi + 16], xmm1 - lea edi, [edi + 32] - sub ecx, 16 - jg convertloop - - pop edi - pop esi - ret - } +#ifdef HAS_MERGEAR64ROW_AVX2 +LIBYUV_TARGET_AVX2 +void MergeAR64Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + const uint16_t* src_a, + uint16_t* dst_ar64, + int depth, + int width) { + const __m128i shift128 = _mm_cvtsi32_si128(16 - depth); + const uint32_t max_val = (depth >= 16) ? 0xffffu : ((1u << depth) - 1u); + const __m256i ymm_max = _mm256_set1_epi16((short)max_val); + do { + __m256i r = _mm256_sll_epi16( + _mm256_min_epu16(_mm256_loadu_si256((const __m256i*)src_r), ymm_max), + shift128); + __m256i g = _mm256_sll_epi16( + _mm256_min_epu16(_mm256_loadu_si256((const __m256i*)src_g), ymm_max), + shift128); + __m256i b = _mm256_sll_epi16( + _mm256_min_epu16(_mm256_loadu_si256((const __m256i*)src_b), ymm_max), + shift128); + __m256i a = _mm256_sll_epi16( + _mm256_min_epu16(_mm256_loadu_si256((const __m256i*)src_a), ymm_max), + shift128); + __m256i bg_lo = _mm256_unpacklo_epi16(b, g); + __m256i bg_hi = _mm256_unpackhi_epi16(b, g); + __m256i ra_lo = _mm256_unpacklo_epi16(r, a); + __m256i ra_hi = _mm256_unpackhi_epi16(r, a); + __m256i p0_8 = _mm256_unpacklo_epi32(bg_lo, ra_lo); + __m256i p2_10 = _mm256_unpackhi_epi32(bg_lo, ra_lo); + __m256i p4_12 = _mm256_unpacklo_epi32(bg_hi, ra_hi); + __m256i p6_14 = _mm256_unpackhi_epi32(bg_hi, ra_hi); + _mm256_storeu_si256((__m256i*)dst_ar64, + _mm256_permute2x128_si256(p0_8, p2_10, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_ar64 + 16), + _mm256_permute2x128_si256(p4_12, p6_14, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_ar64 + 32), + _mm256_permute2x128_si256(p0_8, p2_10, 0x31)); + _mm256_storeu_si256((__m256i*)(dst_ar64 + 48), + _mm256_permute2x128_si256(p4_12, p6_14, 0x31)); + src_r += 16; + src_g += 16; + src_b += 16; + src_a += 16; + dst_ar64 += 64; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); } +#endif // HAS_MERGEAR64ROW_AVX2 -__declspec(naked) void I422ToUYVYRow_SSE2(const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_frame, - int width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_y - mov esi, [esp + 8 + 8] // src_u - mov edx, [esp + 8 + 12] // src_v - mov edi, [esp + 8 + 16] // dst_frame - mov ecx, [esp + 8 + 20] // width - sub edx, esi - - convertloop: - movq xmm2, qword ptr [esi] // U - movq xmm3, qword ptr [esi + edx] // V - lea esi, [esi + 8] - punpcklbw xmm2, xmm3 // UV - movdqu xmm0, [eax] // Y - movdqa xmm1, xmm2 - lea eax, [eax + 16] - punpcklbw xmm1, xmm0 // UYVY - punpckhbw xmm2, xmm0 - movdqu [edi], xmm1 - movdqu [edi + 16], xmm2 - lea edi, [edi + 32] - sub ecx, 16 - jg convertloop - - pop edi - pop esi - ret - } +#ifdef HAS_MERGEXR64ROW_AVX2 +LIBYUV_TARGET_AVX2 +void MergeXR64Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint16_t* dst_ar64, + int depth, + int width) { + const __m128i shift128 = _mm_cvtsi32_si128(16 - depth); + const uint32_t max_val = (depth >= 16) ? 0xffffu : ((1u << depth) - 1u); + const __m256i ymm_max = _mm256_set1_epi16((short)max_val); + const __m256i a = _mm256_set1_epi16((short)0xffff); + do { + __m256i r = _mm256_sll_epi16( + _mm256_min_epu16(_mm256_loadu_si256((const __m256i*)src_r), ymm_max), + shift128); + __m256i g = _mm256_sll_epi16( + _mm256_min_epu16(_mm256_loadu_si256((const __m256i*)src_g), ymm_max), + shift128); + __m256i b = _mm256_sll_epi16( + _mm256_min_epu16(_mm256_loadu_si256((const __m256i*)src_b), ymm_max), + shift128); + __m256i bg_lo = _mm256_unpacklo_epi16(b, g); + __m256i bg_hi = _mm256_unpackhi_epi16(b, g); + __m256i ra_lo = _mm256_unpacklo_epi16(r, a); + __m256i ra_hi = _mm256_unpackhi_epi16(r, a); + __m256i p0_8 = _mm256_unpacklo_epi32(bg_lo, ra_lo); + __m256i p2_10 = _mm256_unpackhi_epi32(bg_lo, ra_lo); + __m256i p4_12 = _mm256_unpacklo_epi32(bg_hi, ra_hi); + __m256i p6_14 = _mm256_unpackhi_epi32(bg_hi, ra_hi); + _mm256_storeu_si256((__m256i*)dst_ar64, + _mm256_permute2x128_si256(p0_8, p2_10, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_ar64 + 16), + _mm256_permute2x128_si256(p4_12, p6_14, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_ar64 + 32), + _mm256_permute2x128_si256(p0_8, p2_10, 0x31)); + _mm256_storeu_si256((__m256i*)(dst_ar64 + 48), + _mm256_permute2x128_si256(p4_12, p6_14, 0x31)); + src_r += 16; + src_g += 16; + src_b += 16; + dst_ar64 += 64; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); } +#endif // HAS_MERGEXR64ROW_AVX2 -#ifdef HAS_ARGBPOLYNOMIALROW_SSE2 -__declspec(naked) void ARGBPolynomialRow_SSE2(const uint8_t* src_argb, - uint8_t* dst_argb, - const float* poly, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] /* src_argb */ - mov edx, [esp + 4 + 8] /* dst_argb */ - mov esi, [esp + 4 + 12] /* poly */ - mov ecx, [esp + 4 + 16] /* width */ - pxor xmm3, xmm3 // 0 constant for zero extending bytes to ints. +#ifdef HAS_NV21TOYUV24ROW_AVX2 +LIBYUV_TARGET_AVX2 +void NV21ToYUV24Row_AVX2(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_yuv24, + int width) { + static const uint8_t kYUV24Shuffle[3][16] = { + {8, 9, 0, 8, 9, 1, 10, 11, 2, 10, 11, 3, 12, 13, 4, 12}, + {9, 1, 10, 11, 2, 10, 11, 3, 12, 13, 4, 12, 13, 5, 14, 15}, + {2, 10, 11, 3, 12, 13, 4, 12, 13, 5, 14, 15, 6, 14, 15, 7}}; + const __m256i ymm4 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kYUV24Shuffle[0])); + const __m256i ymm5 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kYUV24Shuffle[1])); + const __m256i ymm6 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kYUV24Shuffle[2])); - // 2 pixel loop. - convertloop: - // pmovzxbd xmm0, dword ptr [eax] // BGRA pixel - // pmovzxbd xmm4, dword ptr [eax + 4] // BGRA pixel - movq xmm0, qword ptr [eax] // BGRABGRA - lea eax, [eax + 8] - punpcklbw xmm0, xmm3 - movdqa xmm4, xmm0 - punpcklwd xmm0, xmm3 // pixel 0 - punpckhwd xmm4, xmm3 // pixel 1 - cvtdq2ps xmm0, xmm0 // 4 floats - cvtdq2ps xmm4, xmm4 - movdqa xmm1, xmm0 // X - movdqa xmm5, xmm4 - mulps xmm0, [esi + 16] // C1 * X - mulps xmm4, [esi + 16] - addps xmm0, [esi] // result = C0 + C1 * X - addps xmm4, [esi] - movdqa xmm2, xmm1 - movdqa xmm6, xmm5 - mulps xmm2, xmm1 // X * X - mulps xmm6, xmm5 - mulps xmm1, xmm2 // X * X * X - mulps xmm5, xmm6 - mulps xmm2, [esi + 32] // C2 * X * X - mulps xmm6, [esi + 32] - mulps xmm1, [esi + 48] // C3 * X * X * X - mulps xmm5, [esi + 48] - addps xmm0, xmm2 // result += C2 * X * X - addps xmm4, xmm6 - addps xmm0, xmm1 // result += C3 * X * X * X - addps xmm4, xmm5 - cvttps2dq xmm0, xmm0 - cvttps2dq xmm4, xmm4 - packuswb xmm0, xmm4 - packuswb xmm0, xmm0 - movq qword ptr [edx], xmm0 - lea edx, [edx + 8] - sub ecx, 2 - jg convertloop - pop esi - ret - } + do { + __m256 ymm2 = _mm256_castsi256_ps(_mm256_loadu_si256((const __m256i*)src_y)); + __m256 ymm3 = + _mm256_castsi256_ps(_mm256_loadu_si256((const __m256i*)src_vu)); + __m256i c0 = _mm256_shuffle_epi8( + _mm256_castps_si256(_mm256_shuffle_ps(ymm2, ymm3, 0x44)), ymm4); + __m256i c1 = _mm256_shuffle_epi8( + _mm256_castps_si256(_mm256_shuffle_ps(ymm2, ymm3, 0x99)), ymm5); + __m256i c2 = _mm256_shuffle_epi8( + _mm256_castps_si256(_mm256_shuffle_ps(ymm2, ymm3, 0xee)), ymm6); + _mm256_storeu_si256((__m256i*)dst_yuv24, + _mm256_permute2x128_si256(c0, c1, 0x20)); + _mm256_storeu_si256((__m256i*)(dst_yuv24 + 32), + _mm256_permute2x128_si256(c2, c0, 0x30)); + _mm256_storeu_si256((__m256i*)(dst_yuv24 + 64), + _mm256_permute2x128_si256(c1, c2, 0x31)); + src_y += 32; + src_vu += 32; + dst_yuv24 += 96; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); } -#endif // HAS_ARGBPOLYNOMIALROW_SSE2 +#endif // HAS_NV21TOYUV24ROW_AVX2 -#ifdef HAS_ARGBPOLYNOMIALROW_AVX2 -__declspec(naked) void ARGBPolynomialRow_AVX2(const uint8_t* src_argb, - uint8_t* dst_argb, - const float* poly, - int width) { - __asm { - mov eax, [esp + 4] /* src_argb */ - mov edx, [esp + 8] /* dst_argb */ - mov ecx, [esp + 12] /* poly */ - vbroadcastf128 ymm4, [ecx] // C0 - vbroadcastf128 ymm5, [ecx + 16] // C1 - vbroadcastf128 ymm6, [ecx + 32] // C2 - vbroadcastf128 ymm7, [ecx + 48] // C3 - mov ecx, [esp + 16] /* width */ +#ifdef HAS_NV21TOYUV24ROW_AVX512VBMI +LIBYUV_TARGET_AVX512VBMI +void NV21ToYUV24Row_AVX512VBMI(const uint8_t* src_y, + const uint8_t* src_vu, + uint8_t* dst_yuv24, + int width) { + static const uint8_t kNV21ToYUV24Perm_AVX512VBMI[3][64] = { + {64, 65, 0, 64, 65, 1, 66, 67, 2, 66, 67, 3, 68, 69, 4, 68, + 69, 5, 70, 71, 6, 70, 71, 7, 72, 73, 8, 72, 73, 9, 74, 75, + 10, 74, 75, 11, 76, 77, 12, 76, 77, 13, 78, 79, 14, 78, 79, 15, + 80, 81, 16, 80, 81, 17, 82, 83, 18, 82, 83, 19, 84, 85, 20, 84}, + {85, 21, 86, 87, 22, 86, 87, 23, 88, 89, 24, 88, 89, + 25, 90, 91, 26, 90, 91, 27, 92, 93, 28, 92, 93, 29, + 94, 95, 30, 94, 95, 31, 96, 97, 32, 96, 97, 33, 98, + 99, 34, 98, 99, 35, 100, 101, 36, 100, 101, 37, 102, 103, + 38, 102, 103, 39, 104, 105, 40, 104, 105, 41, 106, 107}, + {42, 106, 107, 43, 108, 109, 44, 108, 109, 45, 110, 111, 46, + 110, 111, 47, 112, 113, 48, 112, 113, 49, 114, 115, 50, 114, + 115, 51, 116, 117, 52, 116, 117, 53, 118, 119, 54, 118, 119, + 55, 120, 121, 56, 120, 121, 57, 122, 123, 58, 122, 123, 59, + 124, 125, 60, 124, 125, 61, 126, 127, 62, 126, 127, 63}}; + __m512i zmm_p0 = + _mm512_loadu_si512((const __m512i*)kNV21ToYUV24Perm_AVX512VBMI[0]); + __m512i zmm_p1 = + _mm512_loadu_si512((const __m512i*)kNV21ToYUV24Perm_AVX512VBMI[1]); + __m512i zmm_p2 = + _mm512_loadu_si512((const __m512i*)kNV21ToYUV24Perm_AVX512VBMI[2]); + LIBYUV_HIDE_CONSTANT(zmm_p0); + LIBYUV_HIDE_CONSTANT(zmm_p1); + LIBYUV_HIDE_CONSTANT(zmm_p2); - // 2 pixel loop. - convertloop: - vpmovzxbd ymm0, qword ptr [eax] // 2 BGRA pixels - lea eax, [eax + 8] - vcvtdq2ps ymm0, ymm0 // X 8 floats - vmulps ymm2, ymm0, ymm0 // X * X - vmulps ymm3, ymm0, ymm7 // C3 * X - vfmadd132ps ymm0, ymm4, ymm5 // result = C0 + C1 * X - vfmadd231ps ymm0, ymm2, ymm6 // result += C2 * X * X - vfmadd231ps ymm0, ymm2, ymm3 // result += C3 * X * X * X - vcvttps2dq ymm0, ymm0 - vpackusdw ymm0, ymm0, ymm0 // b0g0r0a0_00000000_b0g0r0a0_00000000 - vpermq ymm0, ymm0, 0xd8 // b0g0r0a0_b0g0r0a0_00000000_00000000 - vpackuswb xmm0, xmm0, xmm0 // bgrabgra_00000000_00000000_00000000 - vmovq qword ptr [edx], xmm0 - lea edx, [edx + 8] - sub ecx, 2 - jg convertloop - vzeroupper - ret + while (width >= 64) { + __m512i zy = _mm512_loadu_si512((const __m512i*)src_y); + __m512i zvu = _mm512_loadu_si512((const __m512i*)src_vu); + __m512i dst0 = _mm512_permutex2var_epi8(zy, zmm_p0, zvu); + __m512i dst1 = _mm512_permutex2var_epi8(zy, zmm_p1, zvu); + __m512i dst2 = _mm512_permutex2var_epi8(zy, zmm_p2, zvu); + _mm512_storeu_si512((__m512i*)dst_yuv24, dst0); + _mm512_storeu_si512((__m512i*)(dst_yuv24 + 64), dst1); + _mm512_storeu_si512((__m512i*)(dst_yuv24 + 128), dst2); + src_y += 64; + src_vu += 64; + dst_yuv24 += 192; + width -= 64; } -} -#endif // HAS_ARGBPOLYNOMIALROW_AVX2 - -#ifdef HAS_HALFFLOATROW_SSE2 -static float kExpBias = 1.9259299444e-34f; -__declspec(naked) void HalfFloatRow_SSE2(const uint16_t* src, - uint16_t* dst, - float scale, - int width) { - __asm { - mov eax, [esp + 4] /* src */ - mov edx, [esp + 8] /* dst */ - movd xmm4, dword ptr [esp + 12] /* scale */ - mov ecx, [esp + 16] /* width */ - mulss xmm4, kExpBias - pshufd xmm4, xmm4, 0 - pxor xmm5, xmm5 - sub edx, eax - - // 8 pixel loop. - convertloop: - movdqu xmm2, xmmword ptr [eax] // 8 shorts - add eax, 16 - movdqa xmm3, xmm2 - punpcklwd xmm2, xmm5 - cvtdq2ps xmm2, xmm2 // convert 8 ints to floats - punpckhwd xmm3, xmm5 - cvtdq2ps xmm3, xmm3 - mulps xmm2, xmm4 - mulps xmm3, xmm4 - psrld xmm2, 13 - psrld xmm3, 13 - packssdw xmm2, xmm3 - movdqu [eax + edx - 16], xmm2 - sub ecx, 8 - jg convertloop - ret + if (width > 0) { + __mmask64 ky = (__mmask64)((1ULL << width) - 1ULL); + int vu_bytes = (width + 1) & ~1; + __mmask64 kvu = (vu_bytes >= 64) ? ~(__mmask64)0 + : (__mmask64)((1ULL << vu_bytes) - 1ULL); + __m512i zy = _mm512_maskz_loadu_epi8(ky, src_y); + __m512i zvu = _mm512_maskz_loadu_epi8(kvu, src_vu); + __m512i dst0 = _mm512_permutex2var_epi8(zy, zmm_p0, zvu); + __m512i dst1 = _mm512_permutex2var_epi8(zy, zmm_p1, zvu); + __m512i dst2 = _mm512_permutex2var_epi8(zy, zmm_p2, zvu); + int nbytes = width * 3; + __mmask64 k0 = + (nbytes >= 64) ? ~(__mmask64)0 : (__mmask64)((1ULL << nbytes) - 1ULL); + __mmask64 k1 = (nbytes <= 64) ? 0 + : (nbytes >= 128) + ? ~(__mmask64)0 + : (__mmask64)((1ULL << (nbytes - 64)) - 1ULL); + __mmask64 k2 = + (nbytes <= 128) ? 0 : (__mmask64)((1ULL << (nbytes - 128)) - 1ULL); + _mm512_mask_storeu_epi8(dst_yuv24, k0, dst0); + if (k1) { + _mm512_mask_storeu_epi8(dst_yuv24 + 64, k1, dst1); + } + if (k2) { + _mm512_mask_storeu_epi8(dst_yuv24 + 128, k2, dst2); + } } + _mm256_zeroupper(); } -#endif // HAS_HALFFLOATROW_SSE2 +#endif // HAS_NV21TOYUV24ROW_AVX512VBMI -#ifdef HAS_HALFFLOATROW_AVX2 -__declspec(naked) void HalfFloatRow_AVX2(const uint16_t* src, - uint16_t* dst, - float scale, - int width) { - __asm { - mov eax, [esp + 4] /* src */ - mov edx, [esp + 8] /* dst */ - movd xmm4, dword ptr [esp + 12] /* scale */ - mov ecx, [esp + 16] /* width */ +#ifdef HAS_SPLITARGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void SplitARGBRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + uint8_t* dst_a, + int width) { + static const uint8_t kShufSplitARGB[16] = {0, 4, 8, 12, 1, 5, 9, 13, + 2, 6, 10, 14, 3, 7, 11, 15}; + const __m256i shuf = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShufSplitARGB)); + do { + __m256i t0 = _mm256_shuffle_epi8( + _mm256_loadu_si256((const __m256i*)src_argb), shuf); + __m256i t1 = _mm256_shuffle_epi8( + _mm256_loadu_si256((const __m256i*)(src_argb + 32)), shuf); + __m256i p0 = _mm256_permute2x128_si256(t0, t1, 0x20); + __m256i p1 = _mm256_permute2x128_si256(t0, t1, 0x31); + __m256i bg = _mm256_permute4x64_epi64(_mm256_unpacklo_epi32(p0, p1), 0xd8); + __m256i ra = _mm256_permute4x64_epi64(_mm256_unpackhi_epi32(p0, p1), 0xd8); + _mm_storeu_si128((__m128i*)dst_b, _mm256_castsi256_si128(bg)); + _mm_storeu_si128((__m128i*)dst_g, _mm256_extracti128_si256(bg, 1)); + _mm_storeu_si128((__m128i*)dst_r, _mm256_castsi256_si128(ra)); + _mm_storeu_si128((__m128i*)dst_a, _mm256_extracti128_si256(ra, 1)); + src_argb += 64; + dst_r += 16; + dst_g += 16; + dst_b += 16; + dst_a += 16; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_SPLITARGBROW_AVX2 - vmulss xmm4, xmm4, kExpBias - vbroadcastss ymm4, xmm4 - vpxor ymm5, ymm5, ymm5 - sub edx, eax +#ifdef HAS_SPLITXRGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void SplitXRGBRow_AVX2(const uint8_t* src_argb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + static const uint8_t kShufSplitARGB[16] = {0, 4, 8, 12, 1, 5, 9, 13, + 2, 6, 10, 14, 3, 7, 11, 15}; + const __m256i shuf = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kShufSplitARGB)); + do { + __m256i t0 = _mm256_shuffle_epi8( + _mm256_loadu_si256((const __m256i*)src_argb), shuf); + __m256i t1 = _mm256_shuffle_epi8( + _mm256_loadu_si256((const __m256i*)(src_argb + 32)), shuf); + __m256i p0 = _mm256_permute2x128_si256(t0, t1, 0x20); + __m256i p1 = _mm256_permute2x128_si256(t0, t1, 0x31); + __m256i bg = _mm256_permute4x64_epi64(_mm256_unpacklo_epi32(p0, p1), 0xd8); + __m256i ra = _mm256_permute4x64_epi64(_mm256_unpackhi_epi32(p0, p1), 0xd8); + _mm_storeu_si128((__m128i*)dst_b, _mm256_castsi256_si128(bg)); + _mm_storeu_si128((__m128i*)dst_g, _mm256_extracti128_si256(bg, 1)); + _mm_storeu_si128((__m128i*)dst_r, _mm256_castsi256_si128(ra)); + src_argb += 64; + dst_r += 16; + dst_g += 16; + dst_b += 16; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_SPLITXRGBROW_AVX2 - // 16 pixel loop. - convertloop: - vmovdqu ymm2, [eax] // 16 shorts - add eax, 32 - vpunpckhwd ymm3, ymm2, ymm5 // convert 16 shorts to 16 ints - vpunpcklwd ymm2, ymm2, ymm5 - vcvtdq2ps ymm3, ymm3 // convert 16 ints to floats - vcvtdq2ps ymm2, ymm2 - vmulps ymm3, ymm3, ymm4 // scale to adjust exponent for 5 bit range. - vmulps ymm2, ymm2, ymm4 - vpsrld ymm3, ymm3, 13 // float convert to 8 half floats truncate - vpsrld ymm2, ymm2, 13 - vpackssdw ymm2, ymm2, ymm3 - vmovdqu [eax + edx - 32], ymm2 - sub ecx, 16 - jg convertloop - vzeroupper - ret +#ifdef HAS_SPLITRGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void SplitRGBRow_AVX2(const uint8_t* src_rgb, + uint8_t* dst_r, + uint8_t* dst_g, + uint8_t* dst_b, + int width) { + static const uint8_t kSplitRGBShuffle[5][16] = { + {0u, 3u, 6u, 9u, 12u, 15u, 2u, 5u, 8u, 11u, 14u, 1u, 4u, 7u, 10u, 13u}, + {1u, 4u, 7u, 10u, 13u, 0u, 3u, 6u, 9u, 12u, 15u, 2u, 5u, 8u, 11u, 14u}, + {2u, 5u, 8u, 11u, 14u, 1u, 4u, 7u, 10u, 13u, 0u, 3u, 6u, 9u, 12u, 15u}, + {0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, + 0u}, + {0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, 0u, 0u, 128u, + 0u}}; + const __m256i s0 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kSplitRGBShuffle[0])); + const __m256i s1 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kSplitRGBShuffle[1])); + const __m256i s2 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kSplitRGBShuffle[2])); + const __m256i m0 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kSplitRGBShuffle[3])); + const __m256i m1 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)kSplitRGBShuffle[4])); + + do { + __m256i ymm4 = _mm256_loadu_si256((const __m256i*)src_rgb); + __m256i ymm5 = _mm256_loadu_si256((const __m256i*)(src_rgb + 32)); + __m256i ymm6 = _mm256_loadu_si256((const __m256i*)(src_rgb + 64)); + src_rgb += 96; + __m256i ymm1 = _mm256_blend_epi32(ymm4, ymm5, 0xf0); + __m256i ymm2 = _mm256_permute2x128_si256(ymm4, ymm6, 0x21); + __m256i ymm3 = _mm256_blend_epi32(ymm5, ymm6, 0xf0); + ymm4 = _mm256_blendv_epi8(ymm1, ymm3, m0); + ymm5 = _mm256_blendv_epi8(ymm2, ymm1, m0); + ymm6 = _mm256_blendv_epi8(ymm3, ymm2, m0); + ymm1 = _mm256_shuffle_epi8(_mm256_blendv_epi8(ymm4, ymm5, m1), s0); + ymm2 = _mm256_shuffle_epi8(_mm256_blendv_epi8(ymm5, ymm6, m1), s1); + ymm3 = _mm256_shuffle_epi8(_mm256_blendv_epi8(ymm6, ymm4, m1), s2); + _mm256_storeu_si256((__m256i*)dst_r, ymm1); + _mm256_storeu_si256((__m256i*)dst_g, ymm2); + _mm256_storeu_si256((__m256i*)dst_b, ymm3); + dst_r += 32; + dst_g += 32; + dst_b += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_SPLITRGBROW_AVX2 + +#ifdef HAS_SPLITUVROW_16_AVX2 +LIBYUV_TARGET_AVX2 +void SplitUVRow_16_AVX2(const uint16_t* src_uv, + uint16_t* dst_u, + uint16_t* dst_v, + int depth, + int width) { + const __m128i shift128 = _mm_cvtsi32_si128(16 - depth); + const __m256i mask16 = _mm256_set1_epi32(0x0000ffff); + do { + __m256i uv0 = _mm256_loadu_si256((const __m256i*)src_uv); + __m256i uv1 = _mm256_loadu_si256((const __m256i*)(src_uv + 16)); + __m256i u = _mm256_permute4x64_epi64( + _mm256_packus_epi32(_mm256_and_si256(uv0, mask16), + _mm256_and_si256(uv1, mask16)), + 0xd8); + __m256i v = _mm256_permute4x64_epi64( + _mm256_packus_epi32(_mm256_srli_epi32(uv0, 16), + _mm256_srli_epi32(uv1, 16)), + 0xd8); + _mm256_storeu_si256((__m256i*)dst_u, _mm256_srl_epi16(u, shift128)); + _mm256_storeu_si256((__m256i*)dst_v, _mm256_srl_epi16(v, shift128)); + src_uv += 32; + dst_u += 16; + dst_v += 16; + width -= 16; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_SPLITUVROW_16_AVX2 + +#ifdef HAS_YUY2TOYROW_AVX2 +LIBYUV_TARGET_AVX2 +void YUY2ToYRow_AVX2(const uint8_t* src_yuy2, uint8_t* dst_y, int width) { + const __m256i mask_00ff = _mm256_set1_epi16(0x00ff); + do { + __m256i s0 = + _mm256_and_si256(_mm256_loadu_si256((const __m256i*)src_yuy2), + mask_00ff); + __m256i s1 = + _mm256_and_si256(_mm256_loadu_si256((const __m256i*)(src_yuy2 + 32)), + mask_00ff); + _mm256_storeu_si256( + (__m256i*)dst_y, + _mm256_permute4x64_epi64(_mm256_packus_epi16(s0, s1), 0xd8)); + src_yuy2 += 64; + dst_y += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_YUY2TOYROW_AVX2 + +#ifdef HAS_UYVYTOYROW_AVX2 +LIBYUV_TARGET_AVX2 +void UYVYToYRow_AVX2(const uint8_t* src_uyvy, uint8_t* dst_y, int width) { + do { + __m256i s0 = + _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)src_uyvy), 8); + __m256i s1 = + _mm256_srli_epi16(_mm256_loadu_si256((const __m256i*)(src_uyvy + 32)), + 8); + _mm256_storeu_si256( + (__m256i*)dst_y, + _mm256_permute4x64_epi64(_mm256_packus_epi16(s0, s1), 0xd8)); + src_uyvy += 64; + dst_y += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_UYVYTOYROW_AVX2 + +#ifdef HAS_YUY2TOUVROW_AVX2 +LIBYUV_TARGET_AVX2 +void YUY2ToUVRow_AVX2(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const __m256i mask_00ff = _mm256_set1_epi16(0x00ff); + do { + __m256i y0 = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)src_yuy2), + _mm256_loadu_si256((const __m256i*)(src_yuy2 + stride_yuy2))); + __m256i y1 = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)(src_yuy2 + 32)), + _mm256_loadu_si256((const __m256i*)(src_yuy2 + stride_yuy2 + 32))); + __m256i uv = _mm256_permute4x64_epi64( + _mm256_packus_epi16(_mm256_srli_epi16(y0, 8), _mm256_srli_epi16(y1, 8)), + 0xd8); + __m256i u = _mm256_and_si256(uv, mask_00ff); + __m256i v = _mm256_srli_epi16(uv, 8); + u = _mm256_permute4x64_epi64(_mm256_packus_epi16(u, u), 0xd8); + v = _mm256_permute4x64_epi64(_mm256_packus_epi16(v, v), 0xd8); + _mm_storeu_si128((__m128i*)dst_u, _mm256_castsi256_si128(u)); + _mm_storeu_si128((__m128i*)dst_v, _mm256_castsi256_si128(v)); + src_yuy2 += 64; + dst_u += 16; + dst_v += 16; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_YUY2TOUVROW_AVX2 + +#ifdef HAS_YUY2TOUV422ROW_AVX2 +LIBYUV_TARGET_AVX2 +void YUY2ToUV422Row_AVX2(const uint8_t* src_yuy2, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const __m256i mask_00ff = _mm256_set1_epi16(0x00ff); + do { + __m256i y0 = _mm256_loadu_si256((const __m256i*)src_yuy2); + __m256i y1 = _mm256_loadu_si256((const __m256i*)(src_yuy2 + 32)); + __m256i uv = _mm256_permute4x64_epi64( + _mm256_packus_epi16(_mm256_srli_epi16(y0, 8), _mm256_srli_epi16(y1, 8)), + 0xd8); + __m256i u = _mm256_and_si256(uv, mask_00ff); + __m256i v = _mm256_srli_epi16(uv, 8); + u = _mm256_permute4x64_epi64(_mm256_packus_epi16(u, u), 0xd8); + v = _mm256_permute4x64_epi64(_mm256_packus_epi16(v, v), 0xd8); + _mm_storeu_si128((__m128i*)dst_u, _mm256_castsi256_si128(u)); + _mm_storeu_si128((__m128i*)dst_v, _mm256_castsi256_si128(v)); + src_yuy2 += 64; + dst_u += 16; + dst_v += 16; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_YUY2TOUV422ROW_AVX2 + +#ifdef HAS_YUY2TONVUVROW_AVX2 +LIBYUV_TARGET_AVX2 +void YUY2ToNVUVRow_AVX2(const uint8_t* src_yuy2, + int stride_yuy2, + uint8_t* dst_uv, + int width) { + do { + __m256i y0 = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)src_yuy2), + _mm256_loadu_si256((const __m256i*)(src_yuy2 + stride_yuy2))); + __m256i y1 = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)(src_yuy2 + 32)), + _mm256_loadu_si256((const __m256i*)(src_yuy2 + stride_yuy2 + 32))); + __m256i uv = _mm256_permute4x64_epi64( + _mm256_packus_epi16(_mm256_srli_epi16(y0, 8), _mm256_srli_epi16(y1, 8)), + 0xd8); + _mm256_storeu_si256((__m256i*)dst_uv, uv); + src_yuy2 += 64; + dst_uv += 32; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // HAS_YUY2TONVUVROW_AVX2 + +#if defined(HAS_UYVYTOUVROW_AVX2) || defined(HAS_UYVYTOYROW_AVX2) +LIBYUV_TARGET_AVX2 +void UYVYToUVRow_AVX2(const uint8_t* src_uyvy, + int stride_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const __m256i mask_00ff = _mm256_set1_epi16(0x00ff); + do { + __m256i y0 = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)src_uyvy), + _mm256_loadu_si256((const __m256i*)(src_uyvy + stride_uyvy))); + __m256i y1 = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)(src_uyvy + 32)), + _mm256_loadu_si256((const __m256i*)(src_uyvy + stride_uyvy + 32))); + __m256i uv = _mm256_permute4x64_epi64( + _mm256_packus_epi16(_mm256_and_si256(y0, mask_00ff), + _mm256_and_si256(y1, mask_00ff)), + 0xd8); + __m256i u = _mm256_and_si256(uv, mask_00ff); + __m256i v = _mm256_srli_epi16(uv, 8); + u = _mm256_permute4x64_epi64(_mm256_packus_epi16(u, u), 0xd8); + v = _mm256_permute4x64_epi64(_mm256_packus_epi16(v, v), 0xd8); + _mm_storeu_si128((__m128i*)dst_u, _mm256_castsi256_si128(u)); + _mm_storeu_si128((__m128i*)dst_v, _mm256_castsi256_si128(v)); + src_uyvy += 64; + dst_u += 16; + dst_v += 16; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // defined(HAS_UYVYTOUVROW_AVX2) || defined(HAS_UYVYTOYROW_AVX2) + +#if defined(HAS_UYVYTOUV422ROW_AVX2) || defined(HAS_UYVYTOYROW_AVX2) +LIBYUV_TARGET_AVX2 +void UYVYToUV422Row_AVX2(const uint8_t* src_uyvy, + uint8_t* dst_u, + uint8_t* dst_v, + int width) { + const __m256i mask_00ff = _mm256_set1_epi16(0x00ff); + do { + __m256i y0 = _mm256_loadu_si256((const __m256i*)src_uyvy); + __m256i y1 = _mm256_loadu_si256((const __m256i*)(src_uyvy + 32)); + __m256i uv = _mm256_permute4x64_epi64( + _mm256_packus_epi16(_mm256_and_si256(y0, mask_00ff), + _mm256_and_si256(y1, mask_00ff)), + 0xd8); + __m256i u = _mm256_and_si256(uv, mask_00ff); + __m256i v = _mm256_srli_epi16(uv, 8); + u = _mm256_permute4x64_epi64(_mm256_packus_epi16(u, u), 0xd8); + v = _mm256_permute4x64_epi64(_mm256_packus_epi16(v, v), 0xd8); + _mm_storeu_si128((__m128i*)dst_u, _mm256_castsi256_si128(u)); + _mm_storeu_si128((__m128i*)dst_v, _mm256_castsi256_si128(v)); + src_uyvy += 64; + dst_u += 16; + dst_v += 16; + width -= 32; + } while (width > 0); + _mm256_zeroupper(); +} +#endif // defined(HAS_UYVYTOUV422ROW_AVX2) || defined(HAS_UYVYTOYROW_AVX2) + +#ifdef HAS_I444TOARGBROW_AVX2 +LIBYUV_TARGET_AVX2 +void I444ToARGBRow_AVX2(const uint8_t* y_buf, + const uint8_t* u_buf, + const uint8_t* v_buf, + uint8_t* dst_argb, + const struct YuvConstants* yuvconstants, + int width) { + const __m256i ymm_kUVToB = + _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToB); + const __m256i ymm_kUVToG = + _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToG); + const __m256i ymm_kUVToR = + _mm256_loadu_si256((const __m256i*)yuvconstants->kUVToR); + const __m256i ymm_kYToRgb = + _mm256_loadu_si256((const __m256i*)yuvconstants->kYToRgb); + const __m256i ymm_kYBiasToRgb = + _mm256_loadu_si256((const __m256i*)yuvconstants->kYBiasToRgb); + const __m256i ymm_128 = _mm256_set1_epi8((char)0x80); + const __m256i ymm_alpha = _mm256_set1_epi8((char)0xff); + + while (width >= 16) { + __m128i xmm_u = _mm_loadu_si128((const __m128i*)u_buf); + __m128i xmm_v = _mm_loadu_si128((const __m128i*)v_buf); + __m128i xmm_y = _mm_loadu_si128((const __m128i*)y_buf); + u_buf += 16; + v_buf += 16; + y_buf += 16; + + __m256i ymm3 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(xmm_u, xmm_v)), + _mm_unpackhi_epi8(xmm_u, xmm_v), 1); + __m256i ymm4 = _mm256_inserti128_si256( + _mm256_castsi128_si256(_mm_unpacklo_epi8(xmm_y, xmm_y)), + _mm_unpackhi_epi8(xmm_y, xmm_y), 1); + + ymm3 = _mm256_sub_epi8(ymm3, ymm_128); + ymm4 = _mm256_mulhi_epu16(ymm4, ymm_kYToRgb); + + __m256i ymm0 = _mm256_maddubs_epi16(ymm_kUVToB, ymm3); + __m256i ymm1 = _mm256_maddubs_epi16(ymm_kUVToG, ymm3); + __m256i ymm2 = _mm256_maddubs_epi16(ymm_kUVToR, ymm3); + + ymm4 = _mm256_add_epi16(ymm4, ymm_kYBiasToRgb); + + ymm0 = _mm256_srai_epi16(_mm256_adds_epi16(ymm0, ymm4), 6); + ymm1 = _mm256_srai_epi16(_mm256_subs_epi16(ymm4, ymm1), 6); + ymm2 = _mm256_srai_epi16(_mm256_adds_epi16(ymm2, ymm4), 6); + + ymm0 = _mm256_packus_epi16(ymm0, ymm0); + ymm1 = _mm256_packus_epi16(ymm1, ymm1); + ymm2 = _mm256_packus_epi16(ymm2, ymm2); + + ymm0 = _mm256_permute4x64_epi64(_mm256_unpacklo_epi8(ymm0, ymm1), 0xd8); + ymm2 = + _mm256_permute4x64_epi64(_mm256_unpacklo_epi8(ymm2, ymm_alpha), 0xd8); + + _mm256_storeu_si256((__m256i*)dst_argb, _mm256_unpacklo_epi16(ymm0, ymm2)); + _mm256_storeu_si256((__m256i*)(dst_argb + 32), + _mm256_unpackhi_epi16(ymm0, ymm2)); + + dst_argb += 64; + width -= 16; } + _mm256_zeroupper(); } -#endif // HAS_HALFFLOATROW_AVX2 +#endif // HAS_I444TOARGBROW_AVX2 -#ifdef HAS_HALFFLOATROW_F16C -__declspec(naked) void HalfFloatRow_F16C(const uint16_t* src, - uint16_t* dst, - float scale, - int width) { - __asm { - mov eax, [esp + 4] /* src */ - mov edx, [esp + 8] /* dst */ - vbroadcastss ymm4, [esp + 12] /* scale */ - mov ecx, [esp + 16] /* width */ - sub edx, eax - - // 16 pixel loop. - convertloop: - vpmovzxwd ymm2, xmmword ptr [eax] // 8 shorts -> 8 ints - vpmovzxwd ymm3, xmmword ptr [eax + 16] // 8 more shorts - add eax, 32 - vcvtdq2ps ymm2, ymm2 // convert 8 ints to floats - vcvtdq2ps ymm3, ymm3 - vmulps ymm2, ymm2, ymm4 // scale to normalized range 0 to 1 - vmulps ymm3, ymm3, ymm4 - vcvtps2ph xmm2, ymm2, 3 // float convert to 8 half floats truncate - vcvtps2ph xmm3, ymm3, 3 - vmovdqu [eax + edx + 32], xmm2 - vmovdqu [eax + edx + 32 + 16], xmm3 - sub ecx, 16 - jg convertloop - vzeroupper - ret +#ifdef HAS_MERGEXR30ROW_AVX2 +LIBYUV_TARGET_AVX2 +void MergeXR30Row_AVX2(const uint16_t* src_r, + const uint16_t* src_g, + const uint16_t* src_b, + uint8_t* dst_ar30, + int depth, + int width) { + int shift = depth - 10; + __m128i v_shift = _mm_cvtsi32_si128(shift); + __m256i v_alpha = _mm256_set1_epi16(0x0030); + __m256i v_max = _mm256_set1_epi16(1023); + while (width > 0) { + __m256i r = _mm256_min_epu16( + _mm256_srl_epi16(_mm256_loadu_si256((const __m256i*)src_r), v_shift), + v_max); + __m256i g = _mm256_min_epu16( + _mm256_srl_epi16(_mm256_loadu_si256((const __m256i*)src_g), v_shift), + v_max); + __m256i b = _mm256_min_epu16( + _mm256_srl_epi16(_mm256_loadu_si256((const __m256i*)src_b), v_shift), + v_max); + r = _mm256_slli_epi16(_mm256_permute4x64_epi64(r, 0xd8), 4); + g = _mm256_permute4x64_epi64(g, 0xd8); + b = _mm256_permute4x64_epi64(b, 0xd8); + __m256i rb_lo = _mm256_unpacklo_epi16(b, r); + __m256i rb_hi = _mm256_unpackhi_epi16(b, r); + __m256i ag_lo = _mm256_slli_epi32(_mm256_unpacklo_epi16(g, v_alpha), 10); + __m256i ag_hi = _mm256_slli_epi32(_mm256_unpackhi_epi16(g, v_alpha), 10); + _mm256_storeu_si256((__m256i*)dst_ar30, _mm256_or_si256(rb_lo, ag_lo)); + _mm256_storeu_si256((__m256i*)(dst_ar30 + 32), + _mm256_or_si256(rb_hi, ag_hi)); + src_r += 16; + src_g += 16; + src_b += 16; + dst_ar30 += 64; + width -= 16; } + _mm256_zeroupper(); } -#endif // HAS_HALFFLOATROW_F16C +#endif // HAS_MERGEXR30ROW_AVX2 -#ifdef HAS_ARGBCOLORTABLEROW_X86 -// Tranform ARGB pixels with color table. -__declspec(naked) void ARGBColorTableRow_X86(uint8_t* dst_argb, - const uint8_t* table_argb, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] /* dst_argb */ - mov esi, [esp + 4 + 8] /* table_argb */ - mov ecx, [esp + 4 + 12] /* width */ - - // 1 pixel loop. - convertloop: - movzx edx, byte ptr [eax] - lea eax, [eax + 4] - movzx edx, byte ptr [esi + edx * 4] - mov byte ptr [eax - 4], dl - movzx edx, byte ptr [eax - 4 + 1] - movzx edx, byte ptr [esi + edx * 4 + 1] - mov byte ptr [eax - 4 + 1], dl - movzx edx, byte ptr [eax - 4 + 2] - movzx edx, byte ptr [esi + edx * 4 + 2] - mov byte ptr [eax - 4 + 2], dl - movzx edx, byte ptr [eax - 4 + 3] - movzx edx, byte ptr [esi + edx * 4 + 3] - mov byte ptr [eax - 4 + 3], dl - dec ecx - jg convertloop - pop esi - ret +#ifdef HAS_MERGEUVROW_16_AVX2 +LIBYUV_TARGET_AVX2 +void MergeUVRow_16_AVX2(const uint16_t* src_u, + const uint16_t* src_v, + uint16_t* dst_uv, + int depth, + int width) { + const __m128i sh_u = _mm_cvtsi32_si128(16 - depth); + const __m128i sh_v = _mm_cvtsi32_si128(32 - depth); + while (width > 0) { + __m256i u32 = + _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)src_u)); + __m256i v32 = + _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)src_v)); + src_u += 8; + src_v += 8; + u32 = _mm256_sll_epi16(u32, sh_u); + v32 = _mm256_sll_epi32(v32, sh_v); + _mm256_storeu_si256((__m256i*)dst_uv, _mm256_or_si256(u32, v32)); + dst_uv += 16; + width -= 8; } + _mm256_zeroupper(); } -#endif // HAS_ARGBCOLORTABLEROW_X86 - -#ifdef HAS_RGBCOLORTABLEROW_X86 -// Tranform RGB pixels with color table. -__declspec(naked) void RGBColorTableRow_X86(uint8_t* dst_argb, - const uint8_t* table_argb, - int width) { - __asm { - push esi - mov eax, [esp + 4 + 4] /* dst_argb */ - mov esi, [esp + 4 + 8] /* table_argb */ - mov ecx, [esp + 4 + 12] /* width */ - - // 1 pixel loop. - convertloop: - movzx edx, byte ptr [eax] - lea eax, [eax + 4] - movzx edx, byte ptr [esi + edx * 4] - mov byte ptr [eax - 4], dl - movzx edx, byte ptr [eax - 4 + 1] - movzx edx, byte ptr [esi + edx * 4 + 1] - mov byte ptr [eax - 4 + 1], dl - movzx edx, byte ptr [eax - 4 + 2] - movzx edx, byte ptr [esi + edx * 4 + 2] - mov byte ptr [eax - 4 + 2], dl - dec ecx - jg convertloop - - pop esi - ret - } -} -#endif // HAS_RGBCOLORTABLEROW_X86 - -#ifdef HAS_ARGBLUMACOLORTABLEROW_SSSE3 -// Tranform RGB pixels with luma table. -__declspec(naked) void ARGBLumaColorTableRow_SSSE3(const uint8_t* src_argb, - uint8_t* dst_argb, - int width, - const uint8_t* luma, - uint32_t lumacoeff) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] /* src_argb */ - mov edi, [esp + 8 + 8] /* dst_argb */ - mov ecx, [esp + 8 + 12] /* width */ - movd xmm2, dword ptr [esp + 8 + 16] // luma table - movd xmm3, dword ptr [esp + 8 + 20] // lumacoeff - pshufd xmm2, xmm2, 0 - pshufd xmm3, xmm3, 0 - pcmpeqb xmm4, xmm4 // generate mask 0xff00ff00 - psllw xmm4, 8 - pxor xmm5, xmm5 - - // 4 pixel loop. - convertloop: - movdqu xmm0, xmmword ptr [eax] // generate luma ptr - pmaddubsw xmm0, xmm3 - phaddw xmm0, xmm0 - pand xmm0, xmm4 // mask out low bits - punpcklwd xmm0, xmm5 - paddd xmm0, xmm2 // add table base - movd esi, xmm0 - pshufd xmm0, xmm0, 0x39 // 00111001 to rotate right 32 - - movzx edx, byte ptr [eax] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi], dl - movzx edx, byte ptr [eax + 1] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi + 1], dl - movzx edx, byte ptr [eax + 2] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi + 2], dl - movzx edx, byte ptr [eax + 3] // copy alpha. - mov byte ptr [edi + 3], dl - - movd esi, xmm0 - pshufd xmm0, xmm0, 0x39 // 00111001 to rotate right 32 - - movzx edx, byte ptr [eax + 4] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi + 4], dl - movzx edx, byte ptr [eax + 5] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi + 5], dl - movzx edx, byte ptr [eax + 6] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi + 6], dl - movzx edx, byte ptr [eax + 7] // copy alpha. - mov byte ptr [edi + 7], dl - - movd esi, xmm0 - pshufd xmm0, xmm0, 0x39 // 00111001 to rotate right 32 - - movzx edx, byte ptr [eax + 8] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi + 8], dl - movzx edx, byte ptr [eax + 9] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi + 9], dl - movzx edx, byte ptr [eax + 10] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi + 10], dl - movzx edx, byte ptr [eax + 11] // copy alpha. - mov byte ptr [edi + 11], dl - - movd esi, xmm0 - - movzx edx, byte ptr [eax + 12] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi + 12], dl - movzx edx, byte ptr [eax + 13] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi + 13], dl - movzx edx, byte ptr [eax + 14] - movzx edx, byte ptr [esi + edx] - mov byte ptr [edi + 14], dl - movzx edx, byte ptr [eax + 15] // copy alpha. - mov byte ptr [edi + 15], dl - - lea eax, [eax + 16] - lea edi, [edi + 16] - sub ecx, 4 - jg convertloop - - pop edi - pop esi - ret - } -} -#endif // HAS_ARGBLUMACOLORTABLEROW_SSSE3 - -#endif // defined(_M_X64) +#endif // HAS_MERGEUVROW_16_AVX2 #ifdef __cplusplus } // extern "C" } // namespace libyuv #endif -#endif // !defined(LIBYUV_DISABLE_X86) && (defined(_M_IX86) || defined(_M_X64)) +#endif // !defined(LIBYUV_DISABLE_X86) && (defined(__x86_64__) || + // defined(__i386__) || defined(_M_X64) || defined(_M_IX86)) && + // ((defined(_MSC_VER) && !defined(__clang__)) || + // defined(LIBYUV_ENABLE_ROWWIN)) diff --git a/libs/libyuv/source/scale.cc b/libs/libyuv/source/scale.cc index 30066d5b34..f2157409cb 100644 --- a/libs/libyuv/source/scale.cc +++ b/libs/libyuv/source/scale.cc @@ -11,12 +11,15 @@ #include "libyuv/scale.h" #include +#include +#include #include #include "libyuv/cpu_id.h" #include "libyuv/planar_functions.h" // For CopyPlane #include "libyuv/row.h" #include "libyuv/scale_row.h" +#include "libyuv/scale_uv.h" // For UVScale #ifdef __cplusplus namespace libyuv { @@ -28,6 +31,7 @@ static __inline int Abs(int v) { } #define SUBSAMPLE(v, a, s) (v < 0) ? (-((-v + a) >> s)) : ((v + a) >> s) +#define CENTERSTART(dx, s) (dx < 0) ? -((-dx >> 1) + s) : ((dx >> 1) + s) // Scale plane, 1/2 // This is an optimized version for scaling down a plane to 1/2 of @@ -37,8 +41,8 @@ static void ScalePlaneDown2(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint8_t* src_ptr, uint8_t* dst_ptr, enum FilterMode filtering) { @@ -49,7 +53,7 @@ static void ScalePlaneDown2(int src_width, ? ScaleRowDown2_C : (filtering == kFilterLinear ? ScaleRowDown2Linear_C : ScaleRowDown2Box_C); - int row_stride = src_stride << 1; + ptrdiff_t row_stride = src_stride * 2; (void)src_width; (void)src_height; if (!filtering) { @@ -72,6 +76,13 @@ static void ScalePlaneDown2(int src_width, } } #endif +#if defined(HAS_SCALEROWDOWN2_SME) + if (TestCpuFlag(kCpuHasSME)) { + ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_SME + : filtering == kFilterLinear ? ScaleRowDown2Linear_SME + : ScaleRowDown2Box_SME; + } +#endif #if defined(HAS_SCALEROWDOWN2_SSSE3) if (TestCpuFlag(kCpuHasSSSE3)) { ScaleRowDown2 = @@ -103,36 +114,62 @@ static void ScalePlaneDown2(int src_width, } } #endif -#if defined(HAS_SCALEROWDOWN2_MSA) - if (TestCpuFlag(kCpuHasMSA)) { +#if defined(HAS_SCALEROWDOWN2_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { ScaleRowDown2 = filtering == kFilterNone - ? ScaleRowDown2_Any_MSA - : (filtering == kFilterLinear ? ScaleRowDown2Linear_Any_MSA - : ScaleRowDown2Box_Any_MSA); - if (IS_ALIGNED(dst_width, 32)) { - ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_MSA + ? ScaleRowDown2_AVX512BW + : (filtering == kFilterLinear ? ScaleRowDown2Linear_AVX512BW + : ScaleRowDown2Box_AVX512BW); + } +#endif +#if defined(HAS_SCALEROWDOWN2_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ScaleRowDown2 = + filtering == kFilterNone + ? ScaleRowDown2_Any_LSX + : (filtering == kFilterLinear ? ScaleRowDown2Linear_Any_LSX + : ScaleRowDown2Box_Any_LSX); + if (IS_ALIGNED(dst_width, 16)) { + ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_LSX : (filtering == kFilterLinear - ? ScaleRowDown2Linear_MSA - : ScaleRowDown2Box_MSA); + ? ScaleRowDown2Linear_LSX + : ScaleRowDown2Box_LSX); } } #endif -#if defined(HAS_SCALEROWDOWN2_MMI) - if (TestCpuFlag(kCpuHasMMI)) { +#if defined(HAS_SCALEROWDOWN2_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleRowDown2 = filtering == kFilterNone + ? ScaleRowDown2_RVV + : (filtering == kFilterLinear ? ScaleRowDown2Linear_RVV + : ScaleRowDown2Box_RVV); + } +#endif +#if defined(HAS_SCALEROWDOWN2_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { ScaleRowDown2 = filtering == kFilterNone - ? ScaleRowDown2_Any_MMI - : (filtering == kFilterLinear ? ScaleRowDown2Linear_Any_MMI - : ScaleRowDown2Box_Any_MMI); - if (IS_ALIGNED(dst_width, 8)) { - ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_MMI - : (filtering == kFilterLinear - ? ScaleRowDown2Linear_MMI - : ScaleRowDown2Box_MMI); + ? ScaleRowDown2_Any_WASMSIMD + : (filtering == kFilterLinear ? ScaleRowDown2Linear_Any_WASMSIMD + : ScaleRowDown2Box_Any_WASMSIMD); + if (IS_ALIGNED(dst_width, 16)) { + ScaleRowDown2 = + filtering == kFilterNone + ? ScaleRowDown2_WASMSIMD + : (filtering == kFilterLinear ? ScaleRowDown2Linear_WASMSIMD + : ScaleRowDown2Box_WASMSIMD); } } #endif +#if defined(HAS_SCALEROWDOWN2_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ScaleRowDown2 = filtering == kFilterNone + ? ScaleRowDown2_HVX + : (filtering == kFilterLinear ? ScaleRowDown2Linear_HVX + : ScaleRowDown2Box_HVX); + } +#endif if (filtering == kFilterLinear) { src_stride = 0; @@ -149,8 +186,8 @@ static void ScalePlaneDown2_16(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint16_t* src_ptr, uint16_t* dst_ptr, enum FilterMode filtering) { @@ -161,7 +198,7 @@ static void ScalePlaneDown2_16(int src_width, ? ScaleRowDown2_16_C : (filtering == kFilterLinear ? ScaleRowDown2Linear_16_C : ScaleRowDown2Box_16_C); - int row_stride = src_stride << 1; + ptrdiff_t row_stride = src_stride * 2; (void)src_width; (void)src_height; if (!filtering) { @@ -169,27 +206,40 @@ static void ScalePlaneDown2_16(int src_width, src_stride = 0; } -#if defined(HAS_SCALEROWDOWN2_16_NEON) - if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(dst_width, 16)) { - ScaleRowDown2 = - filtering ? ScaleRowDown2Box_16_NEON : ScaleRowDown2_16_NEON; - } -#endif -#if defined(HAS_SCALEROWDOWN2_16_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 16)) { +#if defined(HAS_SCALEROWDOWN2_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { ScaleRowDown2 = filtering == kFilterNone - ? ScaleRowDown2_16_SSE2 - : (filtering == kFilterLinear ? ScaleRowDown2Linear_16_SSE2 - : ScaleRowDown2Box_16_SSE2); + ? ScaleRowDown2_16_Any_AVX2 + : (filtering == kFilterLinear ? ScaleRowDown2Linear_16_Any_AVX2 + : ScaleRowDown2Box_16_Any_AVX2); + if (IS_ALIGNED(dst_width, 16)) { + ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_16_AVX2 + : filtering == kFilterLinear ? ScaleRowDown2Linear_16_AVX2 + : ScaleRowDown2Box_16_AVX2; + } } #endif -#if defined(HAS_SCALEROWDOWN2_16_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 4)) { - ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_16_MMI +#if defined(HAS_SCALEROWDOWN2_16_NEON) + if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(dst_width, 16)) { + ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_16_NEON + : filtering == kFilterLinear ? ScaleRowDown2Linear_16_NEON + : ScaleRowDown2Box_16_NEON; + } +#endif +#if defined(HAS_SCALEROWDOWN2_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_16_SME + : filtering == kFilterLinear ? ScaleRowDown2Linear_16_SME + : ScaleRowDown2Box_16_SME; + } +#endif +#if defined(HAS_SCALEROWDOWN2_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ScaleRowDown2 = filtering == kFilterNone ? ScaleRowDown2_16_HVX : (filtering == kFilterLinear - ? ScaleRowDown2Linear_16_MMI - : ScaleRowDown2Box_16_MMI); + ? ScaleRowDown2Linear_16_HVX + : ScaleRowDown2Box_16_HVX); } #endif @@ -212,8 +262,8 @@ static void ScalePlaneDown4(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint8_t* src_ptr, uint8_t* dst_ptr, enum FilterMode filtering) { @@ -221,7 +271,7 @@ static void ScalePlaneDown4(int src_width, void (*ScaleRowDown4)(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width) = filtering ? ScaleRowDown4Box_C : ScaleRowDown4_C; - int row_stride = src_stride << 2; + ptrdiff_t row_stride = src_stride * 4; (void)src_width; (void)src_height; if (!filtering) { @@ -232,7 +282,7 @@ static void ScalePlaneDown4(int src_width, if (TestCpuFlag(kCpuHasNEON)) { ScaleRowDown4 = filtering ? ScaleRowDown4Box_Any_NEON : ScaleRowDown4_Any_NEON; - if (IS_ALIGNED(dst_width, 8)) { + if (IS_ALIGNED(dst_width, 16)) { ScaleRowDown4 = filtering ? ScaleRowDown4Box_NEON : ScaleRowDown4_NEON; } } @@ -255,24 +305,35 @@ static void ScalePlaneDown4(int src_width, } } #endif -#if defined(HAS_SCALEROWDOWN4_MSA) - if (TestCpuFlag(kCpuHasMSA)) { +#if defined(HAS_SCALEROWDOWN4_LSX) + if (TestCpuFlag(kCpuHasLSX)) { ScaleRowDown4 = - filtering ? ScaleRowDown4Box_Any_MSA : ScaleRowDown4_Any_MSA; - if (IS_ALIGNED(dst_width, 16)) { - ScaleRowDown4 = filtering ? ScaleRowDown4Box_MSA : ScaleRowDown4_MSA; + filtering ? ScaleRowDown4Box_Any_LSX : ScaleRowDown4_Any_LSX; + if (IS_ALIGNED(dst_width, 8)) { + ScaleRowDown4 = filtering ? ScaleRowDown4Box_LSX : ScaleRowDown4_LSX; } } #endif -#if defined(HAS_SCALEROWDOWN4_MMI) - if (TestCpuFlag(kCpuHasMMI)) { +#if defined(HAS_SCALEROWDOWN4_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleRowDown4 = filtering ? ScaleRowDown4Box_RVV : ScaleRowDown4_RVV; + } +#endif +#if defined(HAS_SCALEROWDOWN4_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { ScaleRowDown4 = - filtering ? ScaleRowDown4Box_Any_MMI : ScaleRowDown4_Any_MMI; - if (IS_ALIGNED(dst_width, 8)) { - ScaleRowDown4 = filtering ? ScaleRowDown4Box_MMI : ScaleRowDown4_MMI; + filtering ? ScaleRowDown4Box_Any_WASMSIMD : ScaleRowDown4_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 16)) { + ScaleRowDown4 = + filtering ? ScaleRowDown4Box_WASMSIMD : ScaleRowDown4_WASMSIMD; } } #endif +#if defined(HAS_SCALEROWDOWN4_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ScaleRowDown4 = filtering ? ScaleRowDown4Box_HVX : ScaleRowDown4_HVX; + } +#endif if (filtering == kFilterLinear) { src_stride = 0; @@ -288,8 +349,8 @@ static void ScalePlaneDown4_16(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint16_t* src_ptr, uint16_t* dst_ptr, enum FilterMode filtering) { @@ -297,30 +358,13 @@ static void ScalePlaneDown4_16(int src_width, void (*ScaleRowDown4)(const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, int dst_width) = filtering ? ScaleRowDown4Box_16_C : ScaleRowDown4_16_C; - int row_stride = src_stride << 2; + ptrdiff_t row_stride = src_stride * 4; (void)src_width; (void)src_height; if (!filtering) { src_ptr += src_stride * 2; // Point to row 2. src_stride = 0; } -#if defined(HAS_SCALEROWDOWN4_16_NEON) - if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(dst_width, 8)) { - ScaleRowDown4 = - filtering ? ScaleRowDown4Box_16_NEON : ScaleRowDown4_16_NEON; - } -#endif -#if defined(HAS_SCALEROWDOWN4_16_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) { - ScaleRowDown4 = - filtering ? ScaleRowDown4Box_16_SSE2 : ScaleRowDown4_16_SSE2; - } -#endif -#if defined(HAS_SCALEROWDOWN4_16_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 8)) { - ScaleRowDown4 = filtering ? ScaleRowDown4Box_16_MMI : ScaleRowDown4_16_MMI; - } -#endif if (filtering == kFilterLinear) { src_stride = 0; @@ -337,8 +381,8 @@ static void ScalePlaneDown34(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint8_t* src_ptr, uint8_t* dst_ptr, enum FilterMode filtering) { @@ -347,7 +391,7 @@ static void ScalePlaneDown34(int src_width, uint8_t* dst_ptr, int dst_width); void (*ScaleRowDown34_1)(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); - const int filter_stride = (filtering == kFilterLinear) ? 0 : src_stride; + const ptrdiff_t filter_stride = (filtering == kFilterLinear) ? 0 : src_stride; (void)src_width; (void)src_height; assert(dst_width % 3 == 0); @@ -360,14 +404,11 @@ static void ScalePlaneDown34(int src_width, } #if defined(HAS_SCALEROWDOWN34_NEON) if (TestCpuFlag(kCpuHasNEON)) { - if (!filtering) { - ScaleRowDown34_0 = ScaleRowDown34_Any_NEON; - ScaleRowDown34_1 = ScaleRowDown34_Any_NEON; - } else { - ScaleRowDown34_0 = ScaleRowDown34_0_Box_Any_NEON; - ScaleRowDown34_1 = ScaleRowDown34_1_Box_Any_NEON; - } +#if defined(__aarch64__) + if (dst_width % 48 == 0) { +#else if (dst_width % 24 == 0) { +#endif if (!filtering) { ScaleRowDown34_0 = ScaleRowDown34_NEON; ScaleRowDown34_1 = ScaleRowDown34_NEON; @@ -375,45 +416,87 @@ static void ScalePlaneDown34(int src_width, ScaleRowDown34_0 = ScaleRowDown34_0_Box_NEON; ScaleRowDown34_1 = ScaleRowDown34_1_Box_NEON; } - } - } -#endif -#if defined(HAS_SCALEROWDOWN34_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - if (!filtering) { - ScaleRowDown34_0 = ScaleRowDown34_Any_MSA; - ScaleRowDown34_1 = ScaleRowDown34_Any_MSA; } else { - ScaleRowDown34_0 = ScaleRowDown34_0_Box_Any_MSA; - ScaleRowDown34_1 = ScaleRowDown34_1_Box_Any_MSA; - } - if (dst_width % 48 == 0) { if (!filtering) { - ScaleRowDown34_0 = ScaleRowDown34_MSA; - ScaleRowDown34_1 = ScaleRowDown34_MSA; + ScaleRowDown34_0 = ScaleRowDown34_Any_NEON; + ScaleRowDown34_1 = ScaleRowDown34_Any_NEON; } else { - ScaleRowDown34_0 = ScaleRowDown34_0_Box_MSA; - ScaleRowDown34_1 = ScaleRowDown34_1_Box_MSA; + ScaleRowDown34_0 = ScaleRowDown34_0_Box_Any_NEON; + ScaleRowDown34_1 = ScaleRowDown34_1_Box_Any_NEON; } } } #endif -#if defined(HAS_SCALEROWDOWN34_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - if (!filtering) { - ScaleRowDown34_0 = ScaleRowDown34_Any_SSSE3; - ScaleRowDown34_1 = ScaleRowDown34_Any_SSSE3; +#if defined(HAS_SCALEROWDOWN34_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + if (dst_width % 12 == 0) { + if (!filtering) { + ScaleRowDown34_0 = ScaleRowDown34_LSX; + ScaleRowDown34_1 = ScaleRowDown34_LSX; + } else { + ScaleRowDown34_0 = ScaleRowDown34_0_Box_LSX; + ScaleRowDown34_1 = ScaleRowDown34_1_Box_LSX; + } } else { - ScaleRowDown34_0 = ScaleRowDown34_0_Box_Any_SSSE3; - ScaleRowDown34_1 = ScaleRowDown34_1_Box_Any_SSSE3; + if (!filtering) { + ScaleRowDown34_0 = ScaleRowDown34_Any_LSX; + ScaleRowDown34_1 = ScaleRowDown34_Any_LSX; + } else { + ScaleRowDown34_0 = ScaleRowDown34_0_Box_Any_LSX; + ScaleRowDown34_1 = ScaleRowDown34_1_Box_Any_LSX; + } } + } +#endif +#if defined(HAS_SCALEROWDOWN34_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { if (dst_width % 24 == 0) { if (!filtering) { - ScaleRowDown34_0 = ScaleRowDown34_SSSE3; - ScaleRowDown34_1 = ScaleRowDown34_SSSE3; + ScaleRowDown34_0 = ScaleRowDown34_AVX2; + ScaleRowDown34_1 = ScaleRowDown34_AVX2; } else { - ScaleRowDown34_0 = ScaleRowDown34_0_Box_SSSE3; - ScaleRowDown34_1 = ScaleRowDown34_1_Box_SSSE3; + ScaleRowDown34_0 = ScaleRowDown34_0_Box_AVX2; + ScaleRowDown34_1 = ScaleRowDown34_1_Box_AVX2; + } + } else { + if (!filtering) { + ScaleRowDown34_0 = ScaleRowDown34_Any_AVX2; + ScaleRowDown34_1 = ScaleRowDown34_Any_AVX2; + } else { + ScaleRowDown34_0 = ScaleRowDown34_0_Box_Any_AVX2; + ScaleRowDown34_1 = ScaleRowDown34_1_Box_Any_AVX2; + } + } + } +#endif +#if defined(HAS_SCALEROWDOWN34_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + if (!filtering) { + ScaleRowDown34_0 = ScaleRowDown34_RVV; + ScaleRowDown34_1 = ScaleRowDown34_RVV; + } else { + ScaleRowDown34_0 = ScaleRowDown34_0_Box_RVV; + ScaleRowDown34_1 = ScaleRowDown34_1_Box_RVV; + } + } +#endif +#if defined(HAS_SCALEROWDOWN34_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + if (dst_width % 24 == 0) { + if (!filtering) { + ScaleRowDown34_0 = ScaleRowDown34_WASMSIMD; + ScaleRowDown34_1 = ScaleRowDown34_WASMSIMD; + } else { + ScaleRowDown34_0 = ScaleRowDown34_0_Box_WASMSIMD; + ScaleRowDown34_1 = ScaleRowDown34_1_Box_WASMSIMD; + } + } else { + if (!filtering) { + ScaleRowDown34_0 = ScaleRowDown34_Any_WASMSIMD; + ScaleRowDown34_1 = ScaleRowDown34_Any_WASMSIMD; + } else { + ScaleRowDown34_0 = ScaleRowDown34_0_Box_Any_WASMSIMD; + ScaleRowDown34_1 = ScaleRowDown34_1_Box_Any_WASMSIMD; } } } @@ -446,8 +529,8 @@ static void ScalePlaneDown34_16(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint16_t* src_ptr, uint16_t* dst_ptr, enum FilterMode filtering) { @@ -456,7 +539,7 @@ static void ScalePlaneDown34_16(int src_width, uint16_t* dst_ptr, int dst_width); void (*ScaleRowDown34_1)(const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, int dst_width); - const int filter_stride = (filtering == kFilterLinear) ? 0 : src_stride; + const ptrdiff_t filter_stride = (filtering == kFilterLinear) ? 0 : src_stride; (void)src_width; (void)src_height; assert(dst_width % 3 == 0); @@ -467,28 +550,6 @@ static void ScalePlaneDown34_16(int src_width, ScaleRowDown34_0 = ScaleRowDown34_0_Box_16_C; ScaleRowDown34_1 = ScaleRowDown34_1_Box_16_C; } -#if defined(HAS_SCALEROWDOWN34_16_NEON) - if (TestCpuFlag(kCpuHasNEON) && (dst_width % 24 == 0)) { - if (!filtering) { - ScaleRowDown34_0 = ScaleRowDown34_16_NEON; - ScaleRowDown34_1 = ScaleRowDown34_16_NEON; - } else { - ScaleRowDown34_0 = ScaleRowDown34_0_Box_16_NEON; - ScaleRowDown34_1 = ScaleRowDown34_1_Box_16_NEON; - } - } -#endif -#if defined(HAS_SCALEROWDOWN34_16_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3) && (dst_width % 24 == 0)) { - if (!filtering) { - ScaleRowDown34_0 = ScaleRowDown34_16_SSSE3; - ScaleRowDown34_1 = ScaleRowDown34_16_SSSE3; - } else { - ScaleRowDown34_0 = ScaleRowDown34_0_Box_16_SSSE3; - ScaleRowDown34_1 = ScaleRowDown34_1_Box_16_SSSE3; - } - } -#endif for (y = 0; y < dst_height - 2; y += 3) { ScaleRowDown34_0(src_ptr, filter_stride, dst_ptr, dst_width); @@ -532,8 +593,8 @@ static void ScalePlaneDown38(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint8_t* src_ptr, uint8_t* dst_ptr, enum FilterMode filtering) { @@ -542,7 +603,7 @@ static void ScalePlaneDown38(int src_width, uint8_t* dst_ptr, int dst_width); void (*ScaleRowDown38_2)(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width); - const int filter_stride = (filtering == kFilterLinear) ? 0 : src_stride; + const ptrdiff_t filter_stride = (filtering == kFilterLinear) ? 0 : src_stride; assert(dst_width % 3 == 0); (void)src_width; (void)src_height; @@ -574,41 +635,73 @@ static void ScalePlaneDown38(int src_width, } } #endif -#if defined(HAS_SCALEROWDOWN38_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { +#if defined(HAS_SCALEROWDOWN38_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { if (!filtering) { - ScaleRowDown38_3 = ScaleRowDown38_Any_SSSE3; - ScaleRowDown38_2 = ScaleRowDown38_Any_SSSE3; + ScaleRowDown38_3 = ScaleRowDown38_Any_AVX2; + ScaleRowDown38_2 = ScaleRowDown38_Any_AVX2; } else { - ScaleRowDown38_3 = ScaleRowDown38_3_Box_Any_SSSE3; - ScaleRowDown38_2 = ScaleRowDown38_2_Box_Any_SSSE3; - } - if (dst_width % 12 == 0 && !filtering) { - ScaleRowDown38_3 = ScaleRowDown38_SSSE3; - ScaleRowDown38_2 = ScaleRowDown38_SSSE3; - } - if (dst_width % 6 == 0 && filtering) { - ScaleRowDown38_3 = ScaleRowDown38_3_Box_SSSE3; - ScaleRowDown38_2 = ScaleRowDown38_2_Box_SSSE3; - } - } -#endif -#if defined(HAS_SCALEROWDOWN38_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - if (!filtering) { - ScaleRowDown38_3 = ScaleRowDown38_Any_MSA; - ScaleRowDown38_2 = ScaleRowDown38_Any_MSA; - } else { - ScaleRowDown38_3 = ScaleRowDown38_3_Box_Any_MSA; - ScaleRowDown38_2 = ScaleRowDown38_2_Box_Any_MSA; + ScaleRowDown38_3 = ScaleRowDown38_3_Box_Any_AVX2; + ScaleRowDown38_2 = ScaleRowDown38_2_Box_Any_AVX2; } if (dst_width % 12 == 0) { if (!filtering) { - ScaleRowDown38_3 = ScaleRowDown38_MSA; - ScaleRowDown38_2 = ScaleRowDown38_MSA; + ScaleRowDown38_3 = ScaleRowDown38_AVX2; + ScaleRowDown38_2 = ScaleRowDown38_AVX2; } else { - ScaleRowDown38_3 = ScaleRowDown38_3_Box_MSA; - ScaleRowDown38_2 = ScaleRowDown38_2_Box_MSA; + ScaleRowDown38_3 = ScaleRowDown38_3_Box_AVX2; + ScaleRowDown38_2 = ScaleRowDown38_2_Box_AVX2; + } + } + } +#endif +#if defined(HAS_SCALEROWDOWN38_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + if (!filtering) { + ScaleRowDown38_3 = ScaleRowDown38_Any_LSX; + ScaleRowDown38_2 = ScaleRowDown38_Any_LSX; + } else { + ScaleRowDown38_3 = ScaleRowDown38_3_Box_Any_LSX; + ScaleRowDown38_2 = ScaleRowDown38_2_Box_Any_LSX; + } + if (dst_width % 12 == 0) { + if (!filtering) { + ScaleRowDown38_3 = ScaleRowDown38_LSX; + ScaleRowDown38_2 = ScaleRowDown38_LSX; + } else { + ScaleRowDown38_3 = ScaleRowDown38_3_Box_LSX; + ScaleRowDown38_2 = ScaleRowDown38_2_Box_LSX; + } + } + } +#endif +#if defined(HAS_SCALEROWDOWN38_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + if (!filtering) { + ScaleRowDown38_3 = ScaleRowDown38_RVV; + ScaleRowDown38_2 = ScaleRowDown38_RVV; + } else { + ScaleRowDown38_3 = ScaleRowDown38_3_Box_RVV; + ScaleRowDown38_2 = ScaleRowDown38_2_Box_RVV; + } + } +#endif +#if defined(HAS_SCALEROWDOWN38_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + if (!filtering) { + ScaleRowDown38_3 = ScaleRowDown38_Any_WASMSIMD; + ScaleRowDown38_2 = ScaleRowDown38_Any_WASMSIMD; + } else { + ScaleRowDown38_3 = ScaleRowDown38_3_Box_Any_WASMSIMD; + ScaleRowDown38_2 = ScaleRowDown38_2_Box_Any_WASMSIMD; + } + if (dst_width % 12 == 0) { + if (!filtering) { + ScaleRowDown38_3 = ScaleRowDown38_WASMSIMD; + ScaleRowDown38_2 = ScaleRowDown38_WASMSIMD; + } else { + ScaleRowDown38_3 = ScaleRowDown38_3_Box_WASMSIMD; + ScaleRowDown38_2 = ScaleRowDown38_2_Box_WASMSIMD; } } } @@ -641,8 +734,8 @@ static void ScalePlaneDown38_16(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint16_t* src_ptr, uint16_t* dst_ptr, enum FilterMode filtering) { @@ -651,7 +744,7 @@ static void ScalePlaneDown38_16(int src_width, uint16_t* dst_ptr, int dst_width); void (*ScaleRowDown38_2)(const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, int dst_width); - const int filter_stride = (filtering == kFilterLinear) ? 0 : src_stride; + const ptrdiff_t filter_stride = (filtering == kFilterLinear) ? 0 : src_stride; (void)src_width; (void)src_height; assert(dst_width % 3 == 0); @@ -662,28 +755,6 @@ static void ScalePlaneDown38_16(int src_width, ScaleRowDown38_3 = ScaleRowDown38_3_Box_16_C; ScaleRowDown38_2 = ScaleRowDown38_2_Box_16_C; } -#if defined(HAS_SCALEROWDOWN38_16_NEON) - if (TestCpuFlag(kCpuHasNEON) && (dst_width % 12 == 0)) { - if (!filtering) { - ScaleRowDown38_3 = ScaleRowDown38_16_NEON; - ScaleRowDown38_2 = ScaleRowDown38_16_NEON; - } else { - ScaleRowDown38_3 = ScaleRowDown38_3_Box_16_NEON; - ScaleRowDown38_2 = ScaleRowDown38_2_Box_16_NEON; - } - } -#endif -#if defined(HAS_SCALEROWDOWN38_16_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3) && (dst_width % 24 == 0)) { - if (!filtering) { - ScaleRowDown38_3 = ScaleRowDown38_16_SSSE3; - ScaleRowDown38_2 = ScaleRowDown38_16_SSSE3; - } else { - ScaleRowDown38_3 = ScaleRowDown38_3_Box_16_SSSE3; - ScaleRowDown38_2 = ScaleRowDown38_2_Box_16_SSSE3; - } - } -#endif for (y = 0; y < dst_height - 2; y += 3) { ScaleRowDown38_3(src_ptr, filter_stride, dst_ptr, dst_width); @@ -736,9 +807,6 @@ static void ScaleAddCols2_C(int dst_width, int dx, const uint16_t* src_ptr, uint8_t* dst_ptr) { -#ifdef __clang_analyzer__ - *dst_ptr = 0; -#else int i; int scaletbl[2]; int minboxwidth = dx >> 16; @@ -749,11 +817,12 @@ static void ScaleAddCols2_C(int dst_width, int ix = x >> 16; x += dx; boxwidth = MIN1((x >> 16) - ix); - *dst_ptr++ = - SumPixels(boxwidth, src_ptr + ix) * scaletbl[boxwidth - minboxwidth] >> - 16; + int scaletbl_index = boxwidth - minboxwidth; + assert((scaletbl_index == 0) || (scaletbl_index == 1)); + *dst_ptr++ = (uint8_t)(SumPixels(boxwidth, src_ptr + ix) * + scaletbl[scaletbl_index] >> + 16); } -#endif } static void ScaleAddCols2_16_C(int dst_width, @@ -762,9 +831,6 @@ static void ScaleAddCols2_16_C(int dst_width, int dx, const uint32_t* src_ptr, uint16_t* dst_ptr) { -#ifdef __clang_analyzer__ - * dst_ptr = 0; -#else int i; int scaletbl[2]; int minboxwidth = dx >> 16; @@ -775,11 +841,11 @@ static void ScaleAddCols2_16_C(int dst_width, int ix = x >> 16; x += dx; boxwidth = MIN1((x >> 16) - ix); - *dst_ptr++ = SumPixels_16(boxwidth, src_ptr + ix) * - scaletbl[boxwidth - minboxwidth] >> - 16; + int scaletbl_index = boxwidth - minboxwidth; + assert((scaletbl_index == 0) || (scaletbl_index == 1)); + *dst_ptr++ = + SumPixels_16(boxwidth, src_ptr + ix) * scaletbl[scaletbl_index] >> 16; } -#endif } static void ScaleAddCols0_C(int dst_width, @@ -793,7 +859,7 @@ static void ScaleAddCols0_C(int dst_width, (void)dx; src_ptr += (x >> 16); for (i = 0; i < dst_width; ++i) { - *dst_ptr++ = src_ptr[i] * scaleval >> 16; + *dst_ptr++ = (uint8_t)(src_ptr[i] * scaleval >> 16); } } @@ -808,7 +874,7 @@ static void ScaleAddCols1_C(int dst_width, int i; x >>= 16; for (i = 0; i < dst_width; ++i) { - *dst_ptr++ = SumPixels(boxwidth, src_ptr + x) * scaleval >> 16; + *dst_ptr++ = (uint8_t)(SumPixels(boxwidth, src_ptr + x) * scaleval >> 16); x += boxwidth; } } @@ -822,6 +888,7 @@ static void ScaleAddCols1_16_C(int dst_width, int boxwidth = MIN1(dx >> 16); int scaleval = 65536 / (boxwidth * boxheight); int i; + x >>= 16; for (i = 0; i < dst_width; ++i) { *dst_ptr++ = SumPixels_16(boxwidth, src_ptr + x) * scaleval >> 16; x += boxwidth; @@ -835,27 +902,29 @@ static void ScaleAddCols1_16_C(int dst_width, // one pixel of destination using fixed point (16.16) to step // through source, sampling a box of pixel with simple // averaging. -static void ScalePlaneBox(int src_width, - int src_height, - int dst_width, - int dst_height, - int src_stride, - int dst_stride, - const uint8_t* src_ptr, - uint8_t* dst_ptr) { +static int ScalePlaneBox(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_ptr, + uint8_t* dst_ptr) { int j, k; // Initial source x/y coordinate and step values as 16.16 fixed point. int x = 0; int y = 0; int dx = 0; int dy = 0; - const int max_y = (src_height << 16); + const uint32_t max_y = (uint32_t)src_height << 16; ScaleSlope(src_width, src_height, dst_width, dst_height, kFilterBox, &x, &y, &dx, &dy); src_width = Abs(src_width); { // Allocate a row buffer of uint16_t. align_buffer_64(row16, src_width * 2); + if (!row16) + return 1; void (*ScaleAddCols)(int dst_width, int boxheight, int x, int dx, const uint16_t* src_ptr, uint8_t* dst_ptr) = (dx & 0xffff) ? ScaleAddCols2_C @@ -878,6 +947,22 @@ static void ScalePlaneBox(int src_width, } } #endif +#if defined(HAS_SCALEADDROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ScaleAddRow = ScaleAddRow_AVX512BW; + } +#endif +#if defined(HAS_SCALEADDCOLS1_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW) && dx > 0 && !(dx & 0xffff) && + dx != 0x10000) { + ScaleAddCols = ScaleAddCols1_AVX512BW; + } +#endif +#if defined(HAS_SCALEADDCOLS2_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW) && dx > 0 && (dx & 0xffff)) { + ScaleAddCols = ScaleAddCols2_AVX512BW; + } +#endif #if defined(HAS_SCALEADDROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { ScaleAddRow = ScaleAddRow_Any_NEON; @@ -886,32 +971,43 @@ static void ScalePlaneBox(int src_width, } } #endif -#if defined(HAS_SCALEADDROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ScaleAddRow = ScaleAddRow_Any_MSA; +#if defined(HAS_SCALEADDROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ScaleAddRow = ScaleAddRow_Any_LSX; if (IS_ALIGNED(src_width, 16)) { - ScaleAddRow = ScaleAddRow_MSA; + ScaleAddRow = ScaleAddRow_LSX; } } #endif -#if defined(HAS_SCALEADDROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ScaleAddRow = ScaleAddRow_Any_MMI; - if (IS_ALIGNED(src_width, 8)) { - ScaleAddRow = ScaleAddRow_MMI; +#if defined(HAS_SCALEADDROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleAddRow = ScaleAddRow_RVV; + } +#endif +#if defined(HAS_SCALEADDROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ScaleAddRow = ScaleAddRow_HVX; + } +#endif +#if defined(HAS_SCALEADDROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASM)) { + ScaleAddRow = ScaleAddRow_Any_WASMSIMD; + if (IS_ALIGNED(src_width, 16)) { + ScaleAddRow = ScaleAddRow_WASMSIMD; } } #endif + uint32_t uy = y; for (j = 0; j < dst_height; ++j) { int boxheight; - int iy = y >> 16; + int iy = uy >> 16; const uint8_t* src = src_ptr + iy * src_stride; - y += dy; - if (y > max_y) { - y = max_y; + uy += dy; + if (uy > max_y) { + uy = max_y; } - boxheight = MIN1((y >> 16) - iy); + boxheight = MIN1((int)(uy >> 16) - iy); memset(row16, 0, src_width * 2); for (k = 0; k < boxheight; ++k) { ScaleAddRow(src, (uint16_t*)(row16), src_width); @@ -922,55 +1018,48 @@ static void ScalePlaneBox(int src_width, } free_aligned_buffer_64(row16); } + return 0; } -static void ScalePlaneBox_16(int src_width, - int src_height, - int dst_width, - int dst_height, - int src_stride, - int dst_stride, - const uint16_t* src_ptr, - uint16_t* dst_ptr) { +static int ScalePlaneBox_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_ptr, + uint16_t* dst_ptr) { int j, k; // Initial source x/y coordinate and step values as 16.16 fixed point. int x = 0; int y = 0; int dx = 0; int dy = 0; - const int max_y = (src_height << 16); + const uint32_t max_y = (uint32_t)src_height << 16; ScaleSlope(src_width, src_height, dst_width, dst_height, kFilterBox, &x, &y, &dx, &dy); src_width = Abs(src_width); { // Allocate a row buffer of uint32_t. align_buffer_64(row32, src_width * 4); + if (!row32) + return 1; void (*ScaleAddCols)(int dst_width, int boxheight, int x, int dx, const uint32_t* src_ptr, uint16_t* dst_ptr) = (dx & 0xffff) ? ScaleAddCols2_16_C : ScaleAddCols1_16_C; void (*ScaleAddRow)(const uint16_t* src_ptr, uint32_t* dst_ptr, int src_width) = ScaleAddRow_16_C; -#if defined(HAS_SCALEADDROW_16_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(src_width, 16)) { - ScaleAddRow = ScaleAddRow_16_SSE2; - } -#endif - -#if defined(HAS_SCALEADDROW_16_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(src_width, 4)) { - ScaleAddRow = ScaleAddRow_16_MMI; - } -#endif + uint32_t uy = y; for (j = 0; j < dst_height; ++j) { int boxheight; - int iy = y >> 16; + int iy = uy >> 16; const uint16_t* src = src_ptr + iy * src_stride; - y += dy; - if (y > max_y) { - y = max_y; + uy += dy; + if (uy > max_y) { + uy = max_y; } - boxheight = MIN1((y >> 16) - iy); + boxheight = MIN1((int)(uy >> 16) - iy); memset(row32, 0, src_width * 4); for (k = 0; k < boxheight; ++k) { ScaleAddRow(src, (uint32_t*)(row32), src_width); @@ -981,18 +1070,19 @@ static void ScalePlaneBox_16(int src_width, } free_aligned_buffer_64(row32); } + return 0; } // Scale plane down with bilinear interpolation. -void ScalePlaneBilinearDown(int src_width, - int src_height, - int dst_width, - int dst_height, - int src_stride, - int dst_stride, - const uint8_t* src_ptr, - uint8_t* dst_ptr, - enum FilterMode filtering) { +static int ScalePlaneBilinearDown(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_ptr, + uint8_t* dst_ptr, + enum FilterMode filtering) { // Initial source x/y coordinate and step values as 16.16 fixed point. int x = 0; int y = 0; @@ -1001,27 +1091,21 @@ void ScalePlaneBilinearDown(int src_width, // TODO(fbarchard): Consider not allocating row buffer for kFilterLinear. // Allocate a row buffer. align_buffer_64(row, src_width); + if (!row) + return 1; - const int max_y = (src_height - 1) << 16; + const uint32_t max_y = (uint32_t)(src_height - 1) << 16; int j; - void (*ScaleFilterCols)(uint8_t * dst_ptr, const uint8_t* src_ptr, + void (*ScaleFilterCols)(uint8_t* dst_ptr, const uint8_t* src_ptr, int dst_width, int x, int dx) = (src_width >= 32768) ? ScaleFilterCols64_C : ScaleFilterCols_C; - void (*InterpolateRow)(uint8_t * dst_ptr, const uint8_t* src_ptr, + void (*InterpolateRow)(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_C; ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y, &dx, &dy); src_width = Abs(src_width); -#if defined(HAS_INTERPOLATEROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_SSSE3; - if (IS_ALIGNED(src_width, 16)) { - InterpolateRow = InterpolateRow_SSSE3; - } - } -#endif #if defined(HAS_INTERPOLATEROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { InterpolateRow = InterpolateRow_Any_AVX2; @@ -1030,6 +1114,11 @@ void ScalePlaneBilinearDown(int src_width, } } #endif +#if defined(HAS_INTERPOLATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_AVX512BW; + } +#endif #if defined(HAS_INTERPOLATEROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { InterpolateRow = InterpolateRow_Any_NEON; @@ -1038,26 +1127,54 @@ void ScalePlaneBilinearDown(int src_width, } } #endif -#if defined(HAS_INTERPOLATEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - InterpolateRow = InterpolateRow_Any_MSA; - if (IS_ALIGNED(src_width, 32)) { - InterpolateRow = InterpolateRow_MSA; +#if defined(HAS_INTERPOLATEROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + InterpolateRow = InterpolateRow_SVE2; + } +#endif +#if defined(HAS_INTERPOLATEROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + InterpolateRow = InterpolateRow_Any_LSX; + if (IS_ALIGNED(src_width, 16)) { + InterpolateRow = InterpolateRow_LSX; } } #endif -#if defined(HAS_INTERPOLATEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - InterpolateRow = InterpolateRow_Any_MMI; +#if defined(HAS_INTERPOLATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + InterpolateRow = InterpolateRow_Any_LASX; + if (IS_ALIGNED(src_width, 32)) { + InterpolateRow = InterpolateRow_LASX; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + InterpolateRow = InterpolateRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_HVX; + } +#endif +#if defined(HAS_INTERPOLATEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_Any_WASMSIMD; if (IS_ALIGNED(src_width, 16)) { - InterpolateRow = InterpolateRow_MMI; + InterpolateRow = InterpolateRow_WASMSIMD; } } #endif -#if defined(HAS_SCALEFILTERCOLS_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) { - ScaleFilterCols = ScaleFilterCols_SSSE3; +#if defined(HAS_SCALEFILTERCOLS_AVX2) + if (TestCpuFlag(kCpuHasAVX2) && src_width < 32768) { + ScaleFilterCols = ScaleFilterCols_AVX2; } #endif #if defined(HAS_SCALEFILTERCOLS_NEON) @@ -1068,46 +1185,53 @@ void ScalePlaneBilinearDown(int src_width, } } #endif -#if defined(HAS_SCALEFILTERCOLS_MSA) - if (TestCpuFlag(kCpuHasMSA) && src_width < 32768) { - ScaleFilterCols = ScaleFilterCols_Any_MSA; - if (IS_ALIGNED(dst_width, 16)) { - ScaleFilterCols = ScaleFilterCols_MSA; +#if defined(HAS_SCALEFILTERCOLS_LSX) + if (TestCpuFlag(kCpuHasLSX) && src_width < 32768) { + ScaleFilterCols = ScaleFilterCols_Any_LSX; + if (IS_ALIGNED(dst_width, 4)) { + ScaleFilterCols = ScaleFilterCols_LSX; } } #endif - if (y > max_y) { - y = max_y; +#if defined(HAS_SCALEFILTERCOLS_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD) && src_width < 32768) { + ScaleFilterCols = ScaleFilterCols_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 8)) { + ScaleFilterCols = ScaleFilterCols_WASMSIMD; + } } +#endif + uint32_t uy = y; for (j = 0; j < dst_height; ++j) { - int yi = y >> 16; + if (uy > max_y) { + uy = max_y; + } + int yi = uy >> 16; const uint8_t* src = src_ptr + yi * src_stride; if (filtering == kFilterLinear) { ScaleFilterCols(dst_ptr, src, dst_width, x, dx); } else { - int yf = (y >> 8) & 255; + int yf = (uy >> 8) & 255; InterpolateRow(row, src, src_stride, src_width, yf); ScaleFilterCols(dst_ptr, row, dst_width, x, dx); } dst_ptr += dst_stride; - y += dy; - if (y > max_y) { - y = max_y; - } + uy += dy; } free_aligned_buffer_64(row); + return 0; } -void ScalePlaneBilinearDown_16(int src_width, - int src_height, - int dst_width, - int dst_height, - int src_stride, - int dst_stride, - const uint16_t* src_ptr, - uint16_t* dst_ptr, - enum FilterMode filtering) { +static int ScalePlaneBilinearDown_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_ptr, + uint16_t* dst_ptr, + enum FilterMode filtering) { // Initial source x/y coordinate and step values as 16.16 fixed point. int x = 0; int y = 0; @@ -1116,115 +1240,115 @@ void ScalePlaneBilinearDown_16(int src_width, // TODO(fbarchard): Consider not allocating row buffer for kFilterLinear. // Allocate a row buffer. align_buffer_64(row, src_width * 2); + if (!row) + return 1; - const int max_y = (src_height - 1) << 16; + const uint32_t max_y = (uint32_t)(src_height - 1) << 16; int j; - void (*ScaleFilterCols)(uint16_t * dst_ptr, const uint16_t* src_ptr, + void (*ScaleFilterCols)(uint16_t* dst_ptr, const uint16_t* src_ptr, int dst_width, int x, int dx) = (src_width >= 32768) ? ScaleFilterCols64_16_C : ScaleFilterCols_16_C; - void (*InterpolateRow)(uint16_t * dst_ptr, const uint16_t* src_ptr, + void (*InterpolateRow)(uint16_t* dst_ptr, const uint16_t* src_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_16_C; ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y, &dx, &dy); src_width = Abs(src_width); -#if defined(HAS_INTERPOLATEROW_16_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - InterpolateRow = InterpolateRow_Any_16_SSE2; - if (IS_ALIGNED(src_width, 16)) { - InterpolateRow = InterpolateRow_16_SSE2; - } - } -#endif -#if defined(HAS_INTERPOLATEROW_16_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_16_SSSE3; - if (IS_ALIGNED(src_width, 16)) { - InterpolateRow = InterpolateRow_16_SSSE3; - } - } -#endif #if defined(HAS_INTERPOLATEROW_16_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - InterpolateRow = InterpolateRow_Any_16_AVX2; + InterpolateRow = InterpolateRow_16_Any_AVX2; if (IS_ALIGNED(src_width, 32)) { InterpolateRow = InterpolateRow_16_AVX2; } } #endif +#if defined(HAS_INTERPOLATEROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_16_AVX512BW; + } +#endif #if defined(HAS_INTERPOLATEROW_16_NEON) if (TestCpuFlag(kCpuHasNEON)) { - InterpolateRow = InterpolateRow_Any_16_NEON; + InterpolateRow = InterpolateRow_16_Any_NEON; if (IS_ALIGNED(src_width, 16)) { InterpolateRow = InterpolateRow_16_NEON; } } #endif - -#if defined(HAS_SCALEFILTERCOLS_16_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) { - ScaleFilterCols = ScaleFilterCols_16_SSSE3; +#if defined(HAS_INTERPOLATEROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_16_SME; } #endif - if (y > max_y) { - y = max_y; +#if defined(HAS_INTERPOLATEROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_16_HVX; } +#endif +#if defined(HAS_INTERPOLATEROW_16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_16_Any_WASMSIMD; + if (IS_ALIGNED(src_width, 8)) { + InterpolateRow = InterpolateRow_16_WASMSIMD; + } + } +#endif + uint32_t uy = y; for (j = 0; j < dst_height; ++j) { - int yi = y >> 16; + if (uy > max_y) { + uy = max_y; + } + int yi = uy >> 16; const uint16_t* src = src_ptr + yi * src_stride; if (filtering == kFilterLinear) { ScaleFilterCols(dst_ptr, src, dst_width, x, dx); } else { - int yf = (y >> 8) & 255; + int yf = (uy >> 8) & 255; InterpolateRow((uint16_t*)row, src, src_stride, src_width, yf); ScaleFilterCols(dst_ptr, (uint16_t*)row, dst_width, x, dx); } dst_ptr += dst_stride; - y += dy; - if (y > max_y) { - y = max_y; - } + uy += dy; } free_aligned_buffer_64(row); + return 0; } // Scale up down with bilinear interpolation. -void ScalePlaneBilinearUp(int src_width, - int src_height, - int dst_width, - int dst_height, - int src_stride, - int dst_stride, - const uint8_t* src_ptr, - uint8_t* dst_ptr, - enum FilterMode filtering) { +static int ScalePlaneBilinearUp(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_ptr, + uint8_t* dst_ptr, + enum FilterMode filtering) { + assert(src_width > 0); + assert(src_height > 0); + assert(dst_width > 0); + assert(dst_height > 0); + int j; // Initial source x/y coordinate and step values as 16.16 fixed point. int x = 0; int y = 0; int dx = 0; int dy = 0; - const int max_y = (src_height - 1) << 16; - void (*InterpolateRow)(uint8_t * dst_ptr, const uint8_t* src_ptr, + const uint32_t max_y = (uint32_t)(src_height - 1) << 16; + void (*InterpolateRow)(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_C; - void (*ScaleFilterCols)(uint8_t * dst_ptr, const uint8_t* src_ptr, + void (*ScaleFilterCols)(uint8_t* dst_ptr, const uint8_t* src_ptr, int dst_width, int x, int dx) = filtering ? ScaleFilterCols_C : ScaleCols_C; ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y, &dx, &dy); + assert(dy <= 65536); src_width = Abs(src_width); -#if defined(HAS_INTERPOLATEROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_SSSE3; - if (IS_ALIGNED(dst_width, 16)) { - InterpolateRow = InterpolateRow_SSSE3; - } - } -#endif #if defined(HAS_INTERPOLATEROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { InterpolateRow = InterpolateRow_Any_AVX2; @@ -1233,6 +1357,11 @@ void ScalePlaneBilinearUp(int src_width, } } #endif +#if defined(HAS_INTERPOLATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_AVX512BW; + } +#endif #if defined(HAS_INTERPOLATEROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { InterpolateRow = InterpolateRow_Any_NEON; @@ -1241,13 +1370,41 @@ void ScalePlaneBilinearUp(int src_width, } } #endif +#if defined(HAS_INTERPOLATEROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + InterpolateRow = InterpolateRow_SVE2; + } +#endif +#if defined(HAS_INTERPOLATEROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + InterpolateRow = InterpolateRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_HVX; + } +#endif +#if defined(HAS_INTERPOLATEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 16)) { + InterpolateRow = InterpolateRow_WASMSIMD; + } + } +#endif if (filtering && src_width >= 32768) { ScaleFilterCols = ScaleFilterCols64_C; } -#if defined(HAS_SCALEFILTERCOLS_SSSE3) - if (filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) { - ScaleFilterCols = ScaleFilterCols_SSSE3; +#if defined(HAS_SCALEFILTERCOLS_AVX2) + if (filtering && TestCpuFlag(kCpuHasAVX2) && src_width < 32768) { + ScaleFilterCols = ScaleFilterCols_AVX2; } #endif #if defined(HAS_SCALEFILTERCOLS_NEON) @@ -1258,41 +1415,47 @@ void ScalePlaneBilinearUp(int src_width, } } #endif -#if defined(HAS_SCALEFILTERCOLS_MSA) - if (filtering && TestCpuFlag(kCpuHasMSA) && src_width < 32768) { - ScaleFilterCols = ScaleFilterCols_Any_MSA; - if (IS_ALIGNED(dst_width, 16)) { - ScaleFilterCols = ScaleFilterCols_MSA; +#if defined(HAS_SCALEFILTERCOLS_LSX) + if (filtering && TestCpuFlag(kCpuHasLSX) && src_width < 32768) { + ScaleFilterCols = ScaleFilterCols_Any_LSX; + if (IS_ALIGNED(dst_width, 4)) { + ScaleFilterCols = ScaleFilterCols_LSX; + } + } +#endif +#if defined(HAS_SCALEFILTERCOLS_WASMSIMD) + if (filtering && TestCpuFlag(kCpuHasWASMSIMD) && src_width < 32768) { + ScaleFilterCols = ScaleFilterCols_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 8)) { + ScaleFilterCols = ScaleFilterCols_WASMSIMD; } } #endif if (!filtering && src_width * 2 == dst_width && x < 0x8000) { ScaleFilterCols = ScaleColsUp2_C; -#if defined(HAS_SCALECOLS_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) { - ScaleFilterCols = ScaleColsUp2_SSE2; - } -#endif -#if defined(HAS_SCALECOLS_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 8)) { - ScaleFilterCols = ScaleColsUp2_MMI; +#if defined(HAS_SCALECOLSUP2_AVX2) + if (TestCpuFlag(kCpuHasAVX2) && IS_ALIGNED(dst_width, 8)) { + ScaleFilterCols = ScaleColsUp2_AVX2; } #endif } - if (y > max_y) { - y = max_y; + uint32_t uy = y; + if (uy > max_y) { + uy = max_y; } { - int yi = y >> 16; + int yi = uy >> 16; const uint8_t* src = src_ptr + yi * src_stride; // Allocate 2 row buffers. - const int kRowSize = (dst_width + 31) & ~31; - align_buffer_64(row, kRowSize * 2); + const int row_size = (dst_width + 31) & ~31; + align_buffer_64(row, row_size * 2); + if (!row) + return 1; uint8_t* rowptr = row; - int rowstride = kRowSize; + ptrdiff_t rowstride = row_size; int lasty = yi; ScaleFilterCols(rowptr, src, dst_width, x, dx); @@ -1300,167 +1463,523 @@ void ScalePlaneBilinearUp(int src_width, src += src_stride; } ScaleFilterCols(rowptr + rowstride, src, dst_width, x, dx); - src += src_stride; + if (src_height > 2) { + src += src_stride; + } + // 2-row rolling buffer: + // rowptr and (rowptr + rowstride) hold the scaled rows for yi and yi + 1. + // Because dy <= 65536 (dy <= 1.0 in 16.16), yi advances in unit steps. + // When yi != lasty: + // 1. Scale the next source row into the older buffer (rowptr). + // 2. Swap buffer pointers (rowptr += rowstride; rowstride = -rowstride;) + // so rowptr points to yi and (rowptr + rowstride) points to yi + 1. + // 3. Advance src by 1 row if row yi + 2 exists ((uy + 65536) < max_y), + // otherwise clamp src at (src_height - 1) to avoid reading out of + // bounds. for (j = 0; j < dst_height; ++j) { - yi = y >> 16; + if (uy > max_y) { + uy = max_y; + } + yi = uy >> 16; if (yi != lasty) { - if (y > max_y) { - y = max_y; - yi = y >> 16; - src = src_ptr + yi * src_stride; - } - if (yi != lasty) { - ScaleFilterCols(rowptr, src, dst_width, x, dx); - rowptr += rowstride; - rowstride = -rowstride; - lasty = yi; + ScaleFilterCols(rowptr, src, dst_width, x, dx); + rowptr += rowstride; + rowstride = -rowstride; + lasty = yi; + if ((uy + 65536) < max_y) { src += src_stride; } } if (filtering == kFilterLinear) { InterpolateRow(dst_ptr, rowptr, 0, dst_width, 0); } else { - int yf = (y >> 8) & 255; + int yf = (uy >> 8) & 255; InterpolateRow(dst_ptr, rowptr, rowstride, dst_width, yf); } dst_ptr += dst_stride; - y += dy; + uy += dy; } free_aligned_buffer_64(row); } + return 0; } -void ScalePlaneBilinearUp_16(int src_width, - int src_height, - int dst_width, - int dst_height, - int src_stride, - int dst_stride, - const uint16_t* src_ptr, - uint16_t* dst_ptr, - enum FilterMode filtering) { +// Scale plane, horizontally up by 2 times. +// Uses linear filter horizontally, nearest vertically. +// This is an optimized version for scaling up a plane to 2 times of +// its original width, using linear interpolation. +// This is used to scale U and V planes of I422 to I444. +static void ScalePlaneUp2_Linear(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_ptr, + uint8_t* dst_ptr) { + void (*ScaleRowUp)(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) = + ScaleRowUp2_Linear_Any_C; + int i; + + (void)src_width; + // This function can only scale up by 2 times horizontally. + assert(src_width == ((dst_width + 1) / 2)); + +#ifdef HAS_SCALEROWUP2_LINEAR_SSE2 + if (TestCpuFlag(kCpuHasSSE2)) { + ScaleRowUp = ScaleRowUp2_Linear_Any_SSE2; + } +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_SSSE3 + if (TestCpuFlag(kCpuHasSSSE3)) { + ScaleRowUp = ScaleRowUp2_Linear_Any_SSSE3; + } +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp = ScaleRowUp2_Linear_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_NEON + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp = ScaleRowUp2_Linear_Any_NEON; + } +#endif +#ifdef HAS_SCALEROWUP2_LINEAR_RVV + if (TestCpuFlag(kCpuHasRVV)) { + ScaleRowUp = ScaleRowUp2_Linear_RVV; + } +#endif + + if (dst_height == 1) { + ScaleRowUp(src_ptr + ((src_height - 1) / 2) * src_stride, dst_ptr, + dst_width); + } else { + uint32_t uy = (1 << 15) - 1; + int dy = FixedDiv(src_height - 1, dst_height - 1); + for (i = 0; i < dst_height; ++i) { + int yi = uy >> 16; + ScaleRowUp(src_ptr + yi * src_stride, dst_ptr, dst_width); + dst_ptr += dst_stride; + uy += dy; + } + } +} + +// Scale plane, up by 2 times. +// This is an optimized version for scaling up a plane to 2 times of +// its original size, using bilinear interpolation. +// This is used to scale U and V planes of I420 to I444. +static void ScalePlaneUp2_Bilinear(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_ptr, + uint8_t* dst_ptr) { + void (*Scale2RowUp)(const uint8_t* src_ptr, ptrdiff_t src_stride, + uint8_t* dst_ptr, ptrdiff_t dst_stride, int dst_width) = + ScaleRowUp2_Bilinear_Any_C; + int x; + + (void)src_width; + // This function can only scale up by 2 times. + assert(src_width == ((dst_width + 1) / 2)); + assert(src_height == ((dst_height + 1) / 2)); + +#ifdef HAS_SCALEROWUP2_BILINEAR_SSE2 + if (TestCpuFlag(kCpuHasSSE2)) { + Scale2RowUp = ScaleRowUp2_Bilinear_Any_SSE2; + } +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_SSSE3 + if (TestCpuFlag(kCpuHasSSSE3)) { + Scale2RowUp = ScaleRowUp2_Bilinear_Any_SSSE3; + } +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp = ScaleRowUp2_Bilinear_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_NEON + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp = ScaleRowUp2_Bilinear_Any_NEON; + } +#endif +#ifdef HAS_SCALEROWUP2_BILINEAR_RVV + if (TestCpuFlag(kCpuHasRVV)) { + Scale2RowUp = ScaleRowUp2_Bilinear_RVV; + } +#endif + + Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width); + dst_ptr += dst_stride; + for (x = 0; x < src_height - 1; ++x) { + Scale2RowUp(src_ptr, src_stride, dst_ptr, dst_stride, dst_width); + src_ptr += src_stride; + // TODO(fbarchard): Test performance of writing one row of destination at a + // time. + dst_ptr += 2 * dst_stride; + } + if (!(dst_height & 1)) { + Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width); + } +} + +// Scale at most 14 bit plane, horizontally up by 2 times. +// This is an optimized version for scaling up a plane to 2 times of +// its original width, using linear interpolation. +// stride is in count of uint16_t. +// This is used to scale U and V planes of I210 to I410 and I212 to I412. +static void ScalePlaneUp2_12_Linear(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_ptr, + uint16_t* dst_ptr) { + void (*ScaleRowUp)(const uint16_t* src_ptr, uint16_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_16_Any_C; + int i; + + (void)src_width; + // This function can only scale up by 2 times horizontally. + assert(src_width == ((dst_width + 1) / 2)); + +#ifdef HAS_SCALEROWUP2_LINEAR_12_SSSE3 + if (TestCpuFlag(kCpuHasSSSE3)) { + ScaleRowUp = ScaleRowUp2_Linear_12_Any_SSSE3; + } +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_12_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp = ScaleRowUp2_Linear_12_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_12_NEON + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp = ScaleRowUp2_Linear_12_Any_NEON; + } +#endif + + if (dst_height == 1) { + ScaleRowUp(src_ptr + ((src_height - 1) / 2) * src_stride, dst_ptr, + dst_width); + } else { + uint32_t uy = (1 << 15) - 1; + int dy = FixedDiv(src_height - 1, dst_height - 1); + for (i = 0; i < dst_height; ++i) { + int yi = uy >> 16; + ScaleRowUp(src_ptr + yi * src_stride, dst_ptr, dst_width); + dst_ptr += dst_stride; + uy += dy; + } + } +} + +// Scale at most 12 bit plane, up by 2 times. +// This is an optimized version for scaling up a plane to 2 times of +// its original size, using bilinear interpolation. +// stride is in count of uint16_t. +// This is used to scale U and V planes of I010 to I410 and I012 to I412. +static void ScalePlaneUp2_12_Bilinear(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_ptr, + uint16_t* dst_ptr) { + void (*Scale2RowUp)(const uint16_t* src_ptr, ptrdiff_t src_stride, + uint16_t* dst_ptr, ptrdiff_t dst_stride, int dst_width) = + ScaleRowUp2_Bilinear_16_Any_C; + int x; + + (void)src_width; + // This function can only scale up by 2 times. + assert(src_width == ((dst_width + 1) / 2)); + assert(src_height == ((dst_height + 1) / 2)); + +#ifdef HAS_SCALEROWUP2_BILINEAR_12_SSSE3 + if (TestCpuFlag(kCpuHasSSSE3)) { + Scale2RowUp = ScaleRowUp2_Bilinear_12_Any_SSSE3; + } +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_12_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp = ScaleRowUp2_Bilinear_12_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_12_NEON + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp = ScaleRowUp2_Bilinear_12_Any_NEON; + } +#endif + + Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width); + dst_ptr += dst_stride; + for (x = 0; x < src_height - 1; ++x) { + Scale2RowUp(src_ptr, src_stride, dst_ptr, dst_stride, dst_width); + src_ptr += src_stride; + dst_ptr += 2 * dst_stride; + } + if (!(dst_height & 1)) { + Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width); + } +} + +static void ScalePlaneUp2_16_Linear(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_ptr, + uint16_t* dst_ptr) { + void (*ScaleRowUp)(const uint16_t* src_ptr, uint16_t* dst_ptr, + int dst_width) = ScaleRowUp2_Linear_16_Any_C; + int i; + + (void)src_width; + // This function can only scale up by 2 times horizontally. + assert(src_width == ((dst_width + 1) / 2)); + +#ifdef HAS_SCALEROWUP2_LINEAR_16_SSE2 + if (TestCpuFlag(kCpuHasSSE2)) { + ScaleRowUp = ScaleRowUp2_Linear_16_Any_SSE2; + } +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_16_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp = ScaleRowUp2_Linear_16_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_16_NEON + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp = ScaleRowUp2_Linear_16_Any_NEON; + } +#endif + + if (dst_height == 1) { + ScaleRowUp(src_ptr + ((src_height - 1) / 2) * src_stride, dst_ptr, + dst_width); + } else { + uint32_t uy = (1 << 15) - 1; + int dy = FixedDiv(src_height - 1, dst_height - 1); + for (i = 0; i < dst_height; ++i) { + int yi = uy >> 16; + ScaleRowUp(src_ptr + yi * src_stride, dst_ptr, dst_width); + dst_ptr += dst_stride; + uy += dy; + } + } +} + +static void ScalePlaneUp2_16_Bilinear(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_ptr, + uint16_t* dst_ptr) { + void (*Scale2RowUp)(const uint16_t* src_ptr, ptrdiff_t src_stride, + uint16_t* dst_ptr, ptrdiff_t dst_stride, int dst_width) = + ScaleRowUp2_Bilinear_16_Any_C; + int x; + + (void)src_width; + // This function can only scale up by 2 times. + assert(src_width == ((dst_width + 1) / 2)); + assert(src_height == ((dst_height + 1) / 2)); + +#ifdef HAS_SCALEROWUP2_BILINEAR_16_SSE2 + if (TestCpuFlag(kCpuHasSSE2)) { + Scale2RowUp = ScaleRowUp2_Bilinear_16_Any_SSE2; + } +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_16_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp = ScaleRowUp2_Bilinear_16_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_16_NEON + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp = ScaleRowUp2_Bilinear_16_Any_NEON; + } +#endif + + Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width); + dst_ptr += dst_stride; + for (x = 0; x < src_height - 1; ++x) { + Scale2RowUp(src_ptr, src_stride, dst_ptr, dst_stride, dst_width); + src_ptr += src_stride; + dst_ptr += 2 * dst_stride; + } + if (!(dst_height & 1)) { + Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width); + } +} + +static int ScalePlaneBilinearUp_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_ptr, + uint16_t* dst_ptr, + enum FilterMode filtering) { + assert(src_width > 0); + assert(src_height > 0); + assert(dst_width > 0); + assert(dst_height > 0); + int j; // Initial source x/y coordinate and step values as 16.16 fixed point. int x = 0; int y = 0; int dx = 0; int dy = 0; - const int max_y = (src_height - 1) << 16; - void (*InterpolateRow)(uint16_t * dst_ptr, const uint16_t* src_ptr, + const uint32_t max_y = (uint32_t)(src_height - 1) << 16; + void (*InterpolateRow)(uint16_t* dst_ptr, const uint16_t* src_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_16_C; - void (*ScaleFilterCols)(uint16_t * dst_ptr, const uint16_t* src_ptr, + void (*ScaleFilterCols)(uint16_t* dst_ptr, const uint16_t* src_ptr, int dst_width, int x, int dx) = filtering ? ScaleFilterCols_16_C : ScaleCols_16_C; ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y, &dx, &dy); + assert(dy <= 65536); src_width = Abs(src_width); -#if defined(HAS_INTERPOLATEROW_16_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - InterpolateRow = InterpolateRow_Any_16_SSE2; - if (IS_ALIGNED(dst_width, 16)) { - InterpolateRow = InterpolateRow_16_SSE2; - } - } -#endif -#if defined(HAS_INTERPOLATEROW_16_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_16_SSSE3; - if (IS_ALIGNED(dst_width, 16)) { - InterpolateRow = InterpolateRow_16_SSSE3; - } - } -#endif #if defined(HAS_INTERPOLATEROW_16_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - InterpolateRow = InterpolateRow_Any_16_AVX2; + InterpolateRow = InterpolateRow_16_Any_AVX2; if (IS_ALIGNED(dst_width, 32)) { InterpolateRow = InterpolateRow_16_AVX2; } } #endif +#if defined(HAS_INTERPOLATEROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_16_AVX512BW; + } +#endif #if defined(HAS_INTERPOLATEROW_16_NEON) if (TestCpuFlag(kCpuHasNEON)) { - InterpolateRow = InterpolateRow_Any_16_NEON; + InterpolateRow = InterpolateRow_16_Any_NEON; if (IS_ALIGNED(dst_width, 16)) { InterpolateRow = InterpolateRow_16_NEON; } } #endif +#if defined(HAS_INTERPOLATEROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_16_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_16_HVX; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_16_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 8)) { + InterpolateRow = InterpolateRow_16_WASMSIMD; + } + } +#endif if (filtering && src_width >= 32768) { ScaleFilterCols = ScaleFilterCols64_16_C; } -#if defined(HAS_SCALEFILTERCOLS_16_SSSE3) - if (filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) { - ScaleFilterCols = ScaleFilterCols_16_SSSE3; - } -#endif if (!filtering && src_width * 2 == dst_width && x < 0x8000) { ScaleFilterCols = ScaleColsUp2_16_C; -#if defined(HAS_SCALECOLS_16_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) { - ScaleFilterCols = ScaleColsUp2_16_SSE2; - } -#endif -#if defined(HAS_SCALECOLS_16_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 8)) { - ScaleFilterCols = ScaleColsUp2_16_MMI; - } -#endif } - if (y > max_y) { - y = max_y; + uint32_t uy = y; + if (uy > max_y) { + uy = max_y; } { - int yi = y >> 16; + int yi = uy >> 16; const uint16_t* src = src_ptr + yi * src_stride; // Allocate 2 row buffers. - const int kRowSize = (dst_width + 31) & ~31; - align_buffer_64(row, kRowSize * 4); - - uint16_t* rowptr = (uint16_t*)row; - int rowstride = kRowSize; + const int row_size = (dst_width + 31) & ~31; + align_buffer_64(row, row_size * 4); + ptrdiff_t rowstride = row_size; int lasty = yi; + uint16_t* rowptr = (uint16_t*)row; + if (!row) + return 1; ScaleFilterCols(rowptr, src, dst_width, x, dx); if (src_height > 1) { src += src_stride; } ScaleFilterCols(rowptr + rowstride, src, dst_width, x, dx); - src += src_stride; + if (src_height > 2) { + src += src_stride; + } + // 2-row rolling buffer: + // rowptr and (rowptr + rowstride) hold the scaled rows for yi and yi + 1. + // Because dy <= 65536 (dy <= 1.0 in 16.16), yi advances in unit steps. + // When yi != lasty: + // 1. Scale the next source row into the older buffer (rowptr). + // 2. Swap buffer pointers (rowptr += rowstride; rowstride = -rowstride;) + // so rowptr points to yi and (rowptr + rowstride) points to yi + 1. + // 3. Advance src by 1 row if row yi + 2 exists ((uy + 65536) < max_y), + // otherwise clamp src at (src_height - 1) to avoid reading out of + // bounds. for (j = 0; j < dst_height; ++j) { - yi = y >> 16; + if (uy > max_y) { + uy = max_y; + } + yi = uy >> 16; if (yi != lasty) { - if (y > max_y) { - y = max_y; - yi = y >> 16; - src = src_ptr + yi * src_stride; - } - if (yi != lasty) { - ScaleFilterCols(rowptr, src, dst_width, x, dx); - rowptr += rowstride; - rowstride = -rowstride; - lasty = yi; + ScaleFilterCols(rowptr, src, dst_width, x, dx); + rowptr += rowstride; + rowstride = -rowstride; + lasty = yi; + if ((uy + 65536) < max_y) { src += src_stride; } } if (filtering == kFilterLinear) { InterpolateRow(dst_ptr, rowptr, 0, dst_width, 0); } else { - int yf = (y >> 8) & 255; + int yf = (uy >> 8) & 255; InterpolateRow(dst_ptr, rowptr, rowstride, dst_width, yf); } dst_ptr += dst_stride; - y += dy; + uy += dy; } free_aligned_buffer_64(row); } + return 0; } // Scale Plane to/from any dimensions, without interpolation. @@ -1472,12 +1991,12 @@ static void ScalePlaneSimple(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint8_t* src_ptr, uint8_t* dst_ptr) { int i; - void (*ScaleCols)(uint8_t * dst_ptr, const uint8_t* src_ptr, int dst_width, + void (*ScaleCols)(uint8_t* dst_ptr, const uint8_t* src_ptr, int dst_width, int x, int dx) = ScaleCols_C; // Initial source x/y coordinate and step values as 16.16 fixed point. int x = 0; @@ -1490,22 +2009,19 @@ static void ScalePlaneSimple(int src_width, if (src_width * 2 == dst_width && x < 0x8000) { ScaleCols = ScaleColsUp2_C; -#if defined(HAS_SCALECOLS_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) { - ScaleCols = ScaleColsUp2_SSE2; - } -#endif -#if defined(HAS_SCALECOLS_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 8)) { - ScaleCols = ScaleColsUp2_MMI; +#if defined(HAS_SCALECOLSUP2_AVX2) + if (TestCpuFlag(kCpuHasAVX2) && IS_ALIGNED(dst_width, 8)) { + ScaleCols = ScaleColsUp2_AVX2; } #endif } + uint32_t uy = y; for (i = 0; i < dst_height; ++i) { - ScaleCols(dst_ptr, src_ptr + (y >> 16) * src_stride, dst_width, x, dx); + int yi = uy >> 16; + ScaleCols(dst_ptr, src_ptr + yi * src_stride, dst_width, x, dx); dst_ptr += dst_stride; - y += dy; + uy += dy; } } @@ -1513,12 +2029,12 @@ static void ScalePlaneSimple_16(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint16_t* src_ptr, uint16_t* dst_ptr) { int i; - void (*ScaleCols)(uint16_t * dst_ptr, const uint16_t* src_ptr, int dst_width, + void (*ScaleCols)(uint16_t* dst_ptr, const uint16_t* src_ptr, int dst_width, int x, int dx) = ScaleCols_16_C; // Initial source x/y coordinate and step values as 16.16 fixed point. int x = 0; @@ -1531,38 +2047,37 @@ static void ScalePlaneSimple_16(int src_width, if (src_width * 2 == dst_width && x < 0x8000) { ScaleCols = ScaleColsUp2_16_C; -#if defined(HAS_SCALECOLS_16_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) { - ScaleCols = ScaleColsUp2_16_SSE2; - } -#endif -#if defined(HAS_SCALECOLS_16_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 8)) { - ScaleCols = ScaleColsUp2_16_MMI; - } -#endif } + uint32_t uy = y; for (i = 0; i < dst_height; ++i) { - ScaleCols(dst_ptr, src_ptr + (y >> 16) * src_stride, dst_width, x, dx); + int yi = uy >> 16; + ScaleCols(dst_ptr, src_ptr + yi * src_stride, dst_width, x, dx); dst_ptr += dst_stride; - y += dy; + uy += dy; } } // Scale a plane. // This function dispatches to a specialized scaler based on scale factor. - LIBYUV_API -void ScalePlane(const uint8_t* src, - int src_stride, - int src_width, - int src_height, - uint8_t* dst, - int dst_stride, - int dst_width, - int dst_height, - enum FilterMode filtering) { +int ScalePlane(const uint8_t* src, + int src_stride, + int src_width, + int src_height, + uint8_t* dst, + int dst_stride, + int dst_width, + int dst_height, + enum FilterMode filtering) { + // Reject dimensions larger than 32768 (or smaller than -32768 for height). + // This prevents FixedDiv signed integer overflows that can lead to division + // by zero/overflow crashes (SIGFPE on x86) or incorrect step calculations. + if (!src || src_width <= 0 || src_height == 0 || src_width > 32768 || + src_height < -32768 || src_height > 32768 || !dst || dst_width <= 0 || + dst_height <= 0) { + return -1; + } // Simplify filtering when possible. filtering = ScaleFilterReduce(src_width, src_height, dst_width, dst_height, filtering); @@ -1570,23 +2085,44 @@ void ScalePlane(const uint8_t* src, // Negative height means invert the image. if (src_height < 0) { src_height = -src_height; - src = src + (src_height - 1) * src_stride; + src = src + (src_height - 1) * (ptrdiff_t)src_stride; src_stride = -src_stride; } - // Use specialized scales to improve performance for common resolutions. // For example, all the 1/2 scalings will use ScalePlaneDown2() if (dst_width == src_width && dst_height == src_height) { // Straight copy. CopyPlane(src, src_stride, dst, dst_stride, dst_width, dst_height); - return; + return 0; } if (dst_width == src_width && filtering != kFilterBox) { - int dy = FixedDiv(src_height, dst_height); + int dy = 0; + int y = 0; + // Check for 1 pixel and avoid FixedDiv overflow. + // TODO(b/573815252): Fix center row calculation when dst_height == 1 and + // src_height == 32768. + if (dst_height == 1 && src_height >= 32768) { + dy = FixedDiv(src_height, src_height); + y = CENTERSTART(dy, -32768); + } else if (dst_height <= src_height) { + // When scaling down, use the center 2 rows to filter. + dy = FixedDiv(src_height, dst_height); + y = CENTERSTART(dy, -32768); // Subtract 0.5 (32768) to center filter. + } else if (src_height > 1 && dst_height > 1) { + // Point sampling uses centered source/destination stepping, matching + // ScaleSlope. Bilinear scaling maps the source endpoints. + if (filtering == kFilterNone) { + dy = FixedDiv(src_height, dst_height); + y = CENTERSTART(dy, 0); + } else { + // When scaling up, last row of destination uses the last 2 source rows. + dy = FixedDiv1(src_height, dst_height); + } + } // Arbitrary scale vertically, but unscaled horizontally. ScalePlaneVertical(src_height, dst_width, dst_height, src_stride, - dst_stride, src, dst, 0, 0, dy, 1, filtering); - return; + dst_stride, src, dst, 0, y, dy, /*bpp=*/1, filtering); + return 0; } if (dst_width <= Abs(src_width) && dst_height <= src_height) { // Scale down. @@ -1594,58 +2130,75 @@ void ScalePlane(const uint8_t* src, // optimized, 3/4 ScalePlaneDown34(src_width, src_height, dst_width, dst_height, src_stride, dst_stride, src, dst, filtering); - return; + return 0; } if (2 * dst_width == src_width && 2 * dst_height == src_height) { // optimized, 1/2 ScalePlaneDown2(src_width, src_height, dst_width, dst_height, src_stride, dst_stride, src, dst, filtering); - return; + return 0; } // 3/8 rounded up for odd sized chroma height. if (8 * dst_width == 3 * src_width && 8 * dst_height == 3 * src_height) { // optimized, 3/8 ScalePlaneDown38(src_width, src_height, dst_width, dst_height, src_stride, dst_stride, src, dst, filtering); - return; + return 0; } if (4 * dst_width == src_width && 4 * dst_height == src_height && (filtering == kFilterBox || filtering == kFilterNone)) { // optimized, 1/4 ScalePlaneDown4(src_width, src_height, dst_width, dst_height, src_stride, dst_stride, src, dst, filtering); - return; + return 0; } } if (filtering == kFilterBox && dst_height * 2 < src_height) { - ScalePlaneBox(src_width, src_height, dst_width, dst_height, src_stride, - dst_stride, src, dst); - return; + return ScalePlaneBox(src_width, src_height, dst_width, dst_height, + src_stride, dst_stride, src, dst); + } + if ((dst_width + 1) / 2 == src_width && filtering == kFilterLinear) { + ScalePlaneUp2_Linear(src_width, src_height, dst_width, dst_height, + src_stride, dst_stride, src, dst); + return 0; + } + if ((dst_height + 1) / 2 == src_height && (dst_width + 1) / 2 == src_width && + (filtering == kFilterBilinear || filtering == kFilterBox)) { + ScalePlaneUp2_Bilinear(src_width, src_height, dst_width, dst_height, + src_stride, dst_stride, src, dst); + return 0; } if (filtering && dst_height > src_height) { - ScalePlaneBilinearUp(src_width, src_height, dst_width, dst_height, - src_stride, dst_stride, src, dst, filtering); - return; + return ScalePlaneBilinearUp(src_width, src_height, dst_width, dst_height, + src_stride, dst_stride, src, dst, filtering); } if (filtering) { - ScalePlaneBilinearDown(src_width, src_height, dst_width, dst_height, - src_stride, dst_stride, src, dst, filtering); - return; + return ScalePlaneBilinearDown(src_width, src_height, dst_width, dst_height, + src_stride, dst_stride, src, dst, filtering); } ScalePlaneSimple(src_width, src_height, dst_width, dst_height, src_stride, dst_stride, src, dst); + return 0; } LIBYUV_API -void ScalePlane_16(const uint16_t* src, - int src_stride, - int src_width, - int src_height, - uint16_t* dst, - int dst_stride, - int dst_width, - int dst_height, - enum FilterMode filtering) { +int ScalePlane_16(const uint16_t* src, + int src_stride, + int src_width, + int src_height, + uint16_t* dst, + int dst_stride, + int dst_width, + int dst_height, + enum FilterMode filtering) { + // Reject dimensions larger than 32768 (or smaller than -32768 for height). + // This prevents FixedDiv signed integer overflows that can lead to division + // by zero/overflow crashes (SIGFPE on x86) or incorrect step calculations. + if (!src || src_width <= 0 || src_height == 0 || src_width > 32768 || + src_height < -32768 || src_height > 32768 || !dst || dst_width <= 0 || + dst_height <= 0) { + return -1; + } // Simplify filtering when possible. filtering = ScaleFilterReduce(src_width, src_height, dst_width, dst_height, filtering); @@ -1653,23 +2206,44 @@ void ScalePlane_16(const uint16_t* src, // Negative height means invert the image. if (src_height < 0) { src_height = -src_height; - src = src + (src_height - 1) * src_stride; + src = src + (src_height - 1) * (ptrdiff_t)src_stride; src_stride = -src_stride; } - // Use specialized scales to improve performance for common resolutions. // For example, all the 1/2 scalings will use ScalePlaneDown2() if (dst_width == src_width && dst_height == src_height) { // Straight copy. CopyPlane_16(src, src_stride, dst, dst_stride, dst_width, dst_height); - return; + return 0; } if (dst_width == src_width && filtering != kFilterBox) { - int dy = FixedDiv(src_height, dst_height); - // Arbitrary scale vertically, but unscaled vertically. + int dy = 0; + int y = 0; + // Check for 1 pixel and avoid FixedDiv overflow. + // TODO(b/573815252): Fix center row calculation when dst_height == 1 and + // src_height == 32768. + if (dst_height == 1 && src_height >= 32768) { + dy = FixedDiv(src_height, src_height); + y = CENTERSTART(dy, -32768); + } else if (dst_height <= src_height) { + // When scaling down, use the center 2 rows to filter. + dy = FixedDiv(src_height, dst_height); + y = CENTERSTART(dy, -32768); // Subtract 0.5 (32768) to center filter. + } else if (src_height > 1 && dst_height > 1) { + // Point sampling uses centered source/destination stepping, matching + // ScaleSlope. Bilinear scaling maps the source endpoints. + if (filtering == kFilterNone) { + dy = FixedDiv(src_height, dst_height); + y = CENTERSTART(dy, 0); + } else { + // When scaling up, last row of destination uses the last 2 source rows. + dy = FixedDiv1(src_height, dst_height); + } + } + // Arbitrary scale vertically, but unscaled horizontally. ScalePlaneVertical_16(src_height, dst_width, dst_height, src_stride, - dst_stride, src, dst, 0, 0, dy, 1, filtering); - return; + dst_stride, src, dst, 0, y, dy, /*bpp=*/1, filtering); + return 0; } if (dst_width <= Abs(src_width) && dst_height <= src_height) { // Scale down. @@ -1677,46 +2251,101 @@ void ScalePlane_16(const uint16_t* src, // optimized, 3/4 ScalePlaneDown34_16(src_width, src_height, dst_width, dst_height, src_stride, dst_stride, src, dst, filtering); - return; + return 0; } if (2 * dst_width == src_width && 2 * dst_height == src_height) { // optimized, 1/2 ScalePlaneDown2_16(src_width, src_height, dst_width, dst_height, src_stride, dst_stride, src, dst, filtering); - return; + return 0; } // 3/8 rounded up for odd sized chroma height. if (8 * dst_width == 3 * src_width && 8 * dst_height == 3 * src_height) { // optimized, 3/8 ScalePlaneDown38_16(src_width, src_height, dst_width, dst_height, src_stride, dst_stride, src, dst, filtering); - return; + return 0; } if (4 * dst_width == src_width && 4 * dst_height == src_height && (filtering == kFilterBox || filtering == kFilterNone)) { // optimized, 1/4 ScalePlaneDown4_16(src_width, src_height, dst_width, dst_height, src_stride, dst_stride, src, dst, filtering); - return; + return 0; } } if (filtering == kFilterBox && dst_height * 2 < src_height) { - ScalePlaneBox_16(src_width, src_height, dst_width, dst_height, src_stride, - dst_stride, src, dst); - return; + return ScalePlaneBox_16(src_width, src_height, dst_width, dst_height, + src_stride, dst_stride, src, dst); + } + if ((dst_width + 1) / 2 == src_width && filtering == kFilterLinear) { + ScalePlaneUp2_16_Linear(src_width, src_height, dst_width, dst_height, + src_stride, dst_stride, src, dst); + return 0; + } + if ((dst_height + 1) / 2 == src_height && (dst_width + 1) / 2 == src_width && + (filtering == kFilterBilinear || filtering == kFilterBox)) { + ScalePlaneUp2_16_Bilinear(src_width, src_height, dst_width, dst_height, + src_stride, dst_stride, src, dst); + return 0; } if (filtering && dst_height > src_height) { - ScalePlaneBilinearUp_16(src_width, src_height, dst_width, dst_height, - src_stride, dst_stride, src, dst, filtering); - return; + return ScalePlaneBilinearUp_16(src_width, src_height, dst_width, dst_height, + src_stride, dst_stride, src, dst, filtering); } if (filtering) { - ScalePlaneBilinearDown_16(src_width, src_height, dst_width, dst_height, - src_stride, dst_stride, src, dst, filtering); - return; + return ScalePlaneBilinearDown_16(src_width, src_height, dst_width, + dst_height, src_stride, dst_stride, src, + dst, filtering); } ScalePlaneSimple_16(src_width, src_height, dst_width, dst_height, src_stride, dst_stride, src, dst); + return 0; +} + +LIBYUV_API +int ScalePlane_12(const uint16_t* src, + int src_stride, + int src_width, + int src_height, + uint16_t* dst, + int dst_stride, + int dst_width, + int dst_height, + enum FilterMode filtering) { + // Reject dimensions larger than 32768 (or smaller than -32768 for height). + // This prevents FixedDiv signed integer overflows that can lead to division + // by zero/overflow crashes (SIGFPE on x86) or incorrect step calculations. + if (!src || src_width <= 0 || src_height == 0 || src_width > 32768 || + src_height < -32768 || src_height > 32768 || !dst || dst_width <= 0 || + dst_height <= 0) { + return -1; + } + // Simplify filtering when possible. + filtering = ScaleFilterReduce(src_width, src_height, dst_width, dst_height, + filtering); + + // Negative height means invert the image. + if (src_height < 0) { + src_height = -src_height; + src = src + (src_height - 1) * (ptrdiff_t)src_stride; + src_stride = -src_stride; + } + + if ((dst_width + 1) / 2 == src_width && filtering == kFilterLinear) { + ScalePlaneUp2_12_Linear(src_width, src_height, dst_width, dst_height, + src_stride, dst_stride, src, dst); + return 0; + } + if ((dst_height + 1) / 2 == src_height && (dst_width + 1) / 2 == src_width && + (filtering == kFilterBilinear || filtering == kFilterBox)) { + ScalePlaneUp2_12_Bilinear(src_width, src_height, dst_width, dst_height, + src_stride, dst_stride, src, dst); + return 0; + } + + return ScalePlane_16(src, src_stride, src_width, src_height, dst, dst_stride, + dst_width, dst_height, filtering); } // Scale an I420 image. @@ -1740,23 +2369,31 @@ int I420Scale(const uint8_t* src_y, int dst_width, int dst_height, enum FilterMode filtering) { + int r; + + if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || + src_height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_width <= 0 || + dst_height <= 0) { + return -1; + } int src_halfwidth = SUBSAMPLE(src_width, 1, 1); int src_halfheight = SUBSAMPLE(src_height, 1, 1); int dst_halfwidth = SUBSAMPLE(dst_width, 1, 1); int dst_halfheight = SUBSAMPLE(dst_height, 1, 1); - if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { - return -1; - } - ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y, dst_stride_y, - dst_width, dst_height, filtering); - ScalePlane(src_u, src_stride_u, src_halfwidth, src_halfheight, dst_u, - dst_stride_u, dst_halfwidth, dst_halfheight, filtering); - ScalePlane(src_v, src_stride_v, src_halfwidth, src_halfheight, dst_v, - dst_stride_v, dst_halfwidth, dst_halfheight, filtering); - return 0; + r = ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y, + dst_stride_y, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane(src_u, src_stride_u, src_halfwidth, src_halfheight, dst_u, + dst_stride_u, dst_halfwidth, dst_halfheight, filtering); + if (r != 0) { + return r; + } + r = ScalePlane(src_v, src_stride_v, src_halfwidth, src_halfheight, dst_v, + dst_stride_v, dst_halfwidth, dst_halfheight, filtering); + return r; } LIBYUV_API @@ -1777,23 +2414,76 @@ int I420Scale_16(const uint16_t* src_y, int dst_width, int dst_height, enum FilterMode filtering) { + int r; + + if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || + src_height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_width <= 0 || + dst_height <= 0) { + return -1; + } int src_halfwidth = SUBSAMPLE(src_width, 1, 1); int src_halfheight = SUBSAMPLE(src_height, 1, 1); int dst_halfwidth = SUBSAMPLE(dst_width, 1, 1); int dst_halfheight = SUBSAMPLE(dst_height, 1, 1); - if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + + r = ScalePlane_16(src_y, src_stride_y, src_width, src_height, dst_y, + dst_stride_y, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_16(src_u, src_stride_u, src_halfwidth, src_halfheight, dst_u, + dst_stride_u, dst_halfwidth, dst_halfheight, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_16(src_v, src_stride_v, src_halfwidth, src_halfheight, dst_v, + dst_stride_v, dst_halfwidth, dst_halfheight, filtering); + return r; +} + +LIBYUV_API +int I420Scale_12(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int dst_width, + int dst_height, + enum FilterMode filtering) { + int r; + + if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || + src_height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_width <= 0 || + dst_height <= 0) { return -1; } + int src_halfwidth = SUBSAMPLE(src_width, 1, 1); + int src_halfheight = SUBSAMPLE(src_height, 1, 1); + int dst_halfwidth = SUBSAMPLE(dst_width, 1, 1); + int dst_halfheight = SUBSAMPLE(dst_height, 1, 1); - ScalePlane_16(src_y, src_stride_y, src_width, src_height, dst_y, dst_stride_y, - dst_width, dst_height, filtering); - ScalePlane_16(src_u, src_stride_u, src_halfwidth, src_halfheight, dst_u, - dst_stride_u, dst_halfwidth, dst_halfheight, filtering); - ScalePlane_16(src_v, src_stride_v, src_halfwidth, src_halfheight, dst_v, - dst_stride_v, dst_halfwidth, dst_halfheight, filtering); - return 0; + r = ScalePlane_12(src_y, src_stride_y, src_width, src_height, dst_y, + dst_stride_y, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_12(src_u, src_stride_u, src_halfwidth, src_halfheight, dst_u, + dst_stride_u, dst_halfwidth, dst_halfheight, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_12(src_v, src_stride_v, src_halfwidth, src_halfheight, dst_v, + dst_stride_v, dst_halfwidth, dst_halfheight, filtering); + return r; } // Scale an I444 image. @@ -1817,19 +2507,27 @@ int I444Scale(const uint8_t* src_y, int dst_width, int dst_height, enum FilterMode filtering) { - if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + int r; + + if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || + src_height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_width <= 0 || + dst_height <= 0) { return -1; } - ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y, dst_stride_y, - dst_width, dst_height, filtering); - ScalePlane(src_u, src_stride_u, src_width, src_height, dst_u, dst_stride_u, - dst_width, dst_height, filtering); - ScalePlane(src_v, src_stride_v, src_width, src_height, dst_v, dst_stride_v, - dst_width, dst_height, filtering); - return 0; + r = ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y, + dst_stride_y, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane(src_u, src_stride_u, src_width, src_height, dst_u, + dst_stride_u, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane(src_v, src_stride_v, src_width, src_height, dst_v, + dst_stride_v, dst_width, dst_height, filtering); + return r; } LIBYUV_API @@ -1850,19 +2548,496 @@ int I444Scale_16(const uint16_t* src_y, int dst_width, int dst_height, enum FilterMode filtering) { - if (!src_y || !src_u || !src_v || src_width == 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + int r; + + if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || + src_height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_width <= 0 || + dst_height <= 0) { return -1; } - ScalePlane_16(src_y, src_stride_y, src_width, src_height, dst_y, dst_stride_y, - dst_width, dst_height, filtering); - ScalePlane_16(src_u, src_stride_u, src_width, src_height, dst_u, dst_stride_u, - dst_width, dst_height, filtering); - ScalePlane_16(src_v, src_stride_v, src_width, src_height, dst_v, dst_stride_v, - dst_width, dst_height, filtering); - return 0; + r = ScalePlane_16(src_y, src_stride_y, src_width, src_height, dst_y, + dst_stride_y, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_16(src_u, src_stride_u, src_width, src_height, dst_u, + dst_stride_u, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_16(src_v, src_stride_v, src_width, src_height, dst_v, + dst_stride_v, dst_width, dst_height, filtering); + return r; +} + +LIBYUV_API +int I444Scale_12(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int dst_width, + int dst_height, + enum FilterMode filtering) { + int r; + + if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || + src_height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_width <= 0 || + dst_height <= 0) { + return -1; + } + + r = ScalePlane_12(src_y, src_stride_y, src_width, src_height, dst_y, + dst_stride_y, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_12(src_u, src_stride_u, src_width, src_height, dst_u, + dst_stride_u, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_12(src_v, src_stride_v, src_width, src_height, dst_v, + dst_stride_v, dst_width, dst_height, filtering); + return r; +} + +// Scale an I422 image. +// This function in turn calls a scaling function for each plane. + +LIBYUV_API +int I422Scale(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + int src_width, + int src_height, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_u, + int dst_stride_u, + uint8_t* dst_v, + int dst_stride_v, + int dst_width, + int dst_height, + enum FilterMode filtering) { + int r; + + if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || + src_height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_width <= 0 || + dst_height <= 0) { + return -1; + } + int src_halfwidth = SUBSAMPLE(src_width, 1, 1); + int dst_halfwidth = SUBSAMPLE(dst_width, 1, 1); + + r = ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y, + dst_stride_y, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane(src_u, src_stride_u, src_halfwidth, src_height, dst_u, + dst_stride_u, dst_halfwidth, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane(src_v, src_stride_v, src_halfwidth, src_height, dst_v, + dst_stride_v, dst_halfwidth, dst_height, filtering); + return r; +} + +LIBYUV_API +int I422Scale_16(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int dst_width, + int dst_height, + enum FilterMode filtering) { + int r; + + if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || + src_height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_width <= 0 || + dst_height <= 0) { + return -1; + } + int src_halfwidth = SUBSAMPLE(src_width, 1, 1); + int dst_halfwidth = SUBSAMPLE(dst_width, 1, 1); + + r = ScalePlane_16(src_y, src_stride_y, src_width, src_height, dst_y, + dst_stride_y, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_16(src_u, src_stride_u, src_halfwidth, src_height, dst_u, + dst_stride_u, dst_halfwidth, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_16(src_v, src_stride_v, src_halfwidth, src_height, dst_v, + dst_stride_v, dst_halfwidth, dst_height, filtering); + return r; +} + +LIBYUV_API +int I422Scale_12(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_u, + int src_stride_u, + const uint16_t* src_v, + int src_stride_v, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_u, + int dst_stride_u, + uint16_t* dst_v, + int dst_stride_v, + int dst_width, + int dst_height, + enum FilterMode filtering) { + int r; + + if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || + src_height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_width <= 0 || + dst_height <= 0) { + return -1; + } + int src_halfwidth = SUBSAMPLE(src_width, 1, 1); + int dst_halfwidth = SUBSAMPLE(dst_width, 1, 1); + + r = ScalePlane_12(src_y, src_stride_y, src_width, src_height, dst_y, + dst_stride_y, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_12(src_u, src_stride_u, src_halfwidth, src_height, dst_u, + dst_stride_u, dst_halfwidth, dst_height, filtering); + if (r != 0) { + return r; + } + r = ScalePlane_12(src_v, src_stride_v, src_halfwidth, src_height, dst_v, + dst_stride_v, dst_halfwidth, dst_height, filtering); + return r; +} + +// Scale NV12 / NV16 / NV24. subsample_x/y are 1 to half that axis, else 0. + +static int NVScale(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering, + int subsample_x, + int subsample_y) { + int r; + int src_uv_width; + int src_uv_height; + int dst_uv_width; + int dst_uv_height; + + if (!src_y || !src_uv || src_width <= 0 || src_height == 0 || + src_height == INT_MIN || !dst_y || !dst_uv || dst_width <= 0 || + dst_height <= 0) { + return -1; + } + src_uv_width = SUBSAMPLE(src_width, subsample_x, subsample_x); + src_uv_height = SUBSAMPLE(src_height, subsample_y, subsample_y); + dst_uv_width = SUBSAMPLE(dst_width, subsample_x, subsample_x); + dst_uv_height = SUBSAMPLE(dst_height, subsample_y, subsample_y); + + r = ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y, + dst_stride_y, dst_width, dst_height, filtering); + if (r != 0) { + return r; + } + r = UVScale(src_uv, src_stride_uv, src_uv_width, src_uv_height, dst_uv, + dst_stride_uv, dst_uv_width, dst_uv_height, filtering); + return r; +} + +// Scale P010 / P210 / P410. subsample_x/y are 1 to half that axis, else 0. +// Samples are 10-bit in the MSBs. Convert to 10-bit LSB, ScalePlane_16, then +// back to MSB. UVScale_16 cannot general-scale, so UV is split then merged. + +static int PxxxScale(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering, + int subsample_x, + int subsample_y) { + int r; + int src_uv_width; + int src_uv_height; + int dst_uv_width; + int dst_uv_height; + size_t src_uv_plane; + size_t dst_uv_plane; + size_t src_uv_bytes; + size_t dst_uv_bytes; + + if (!src_y || !src_uv || src_width <= 0 || src_height == 0 || + src_height == INT_MIN || !dst_y || !dst_uv || dst_width <= 0 || + dst_height <= 0) { + return -1; + } + // ConvertToLSBPlane_16 / SplitUVPlane_16 invert dst, not src. Point both + // planes at the last row so ScalePlane_16 and the UV split see a top-down + // image. + if (src_height < 0) { + const int abs_height = -src_height; + const int src_uv_h = SUBSAMPLE(abs_height, subsample_y, subsample_y); + src_y = src_y + (ptrdiff_t)(abs_height - 1) * src_stride_y; + src_stride_y = -src_stride_y; + src_uv = src_uv + (ptrdiff_t)(src_uv_h - 1) * src_stride_uv; + src_stride_uv = -src_stride_uv; + src_height = abs_height; + } + + src_uv_width = SUBSAMPLE(src_width, subsample_x, subsample_x); + src_uv_height = SUBSAMPLE(src_height, subsample_y, subsample_y); + dst_uv_width = SUBSAMPLE(dst_width, subsample_x, subsample_x); + dst_uv_height = SUBSAMPLE(dst_height, subsample_y, subsample_y); + + if (src_width == dst_width && src_height == dst_height) { + r = ScalePlane_16(src_y, src_stride_y, src_width, src_height, dst_y, + dst_stride_y, dst_width, dst_height, filtering); + } else { + size_t src_y_plane; + size_t src_y_bytes; + if ((size_t)src_width > SIZE_MAX / (size_t)src_height) { + return -1; + } + src_y_plane = (size_t)src_width * (size_t)src_height; + if (src_y_plane > SIZE_MAX / sizeof(uint16_t)) { + return 1; + } + src_y_bytes = src_y_plane * sizeof(uint16_t); + align_buffer_64(src_y_lsb, src_y_bytes); + if (!src_y_lsb) { + return 1; + } + ConvertToLSBPlane_16(src_y, src_stride_y, (uint16_t*)src_y_lsb, src_width, + src_width, src_height, 10); + r = ScalePlane_16((uint16_t*)src_y_lsb, src_width, src_width, src_height, + dst_y, dst_stride_y, dst_width, dst_height, filtering); + if (r == 0) { + ConvertToMSBPlane_16(dst_y, dst_stride_y, dst_y, dst_stride_y, dst_width, + dst_height, 10); + } + free_aligned_buffer_64(src_y_lsb); + } + if (r != 0) { + return r; + } + + if (src_uv_width == dst_uv_width && src_uv_height == dst_uv_height && + src_uv_width <= INT_MAX / 2) { + CopyPlane_16(src_uv, src_stride_uv, dst_uv, dst_stride_uv, src_uv_width * 2, + src_uv_height); + return 0; + } + + if (src_uv_width <= 0 || src_uv_height <= 0 || dst_uv_width <= 0 || + dst_uv_height <= 0 || + (size_t)src_uv_width > SIZE_MAX / (size_t)src_uv_height || + (size_t)dst_uv_width > SIZE_MAX / (size_t)dst_uv_height) { + return -1; + } + src_uv_plane = (size_t)src_uv_width * (size_t)src_uv_height; + dst_uv_plane = (size_t)dst_uv_width * (size_t)dst_uv_height; + if (src_uv_plane > SIZE_MAX / (2u * sizeof(uint16_t)) || + dst_uv_plane > SIZE_MAX / (2u * sizeof(uint16_t))) { + return 1; + } + src_uv_bytes = src_uv_plane * sizeof(uint16_t) * 2u; + dst_uv_bytes = dst_uv_plane * sizeof(uint16_t) * 2u; + + align_buffer_64(src_uv_planes, src_uv_bytes); + align_buffer_64(dst_uv_planes, dst_uv_bytes); + if (!src_uv_planes || !dst_uv_planes) { + free_aligned_buffer_64(src_uv_planes); + free_aligned_buffer_64(dst_uv_planes); + return 1; + } + + { + uint16_t* src_u = (uint16_t*)src_uv_planes; + uint16_t* src_v = src_u + src_uv_plane; + uint16_t* dst_u = (uint16_t*)dst_uv_planes; + uint16_t* dst_v = dst_u + dst_uv_plane; + + SplitUVPlane_16(src_uv, src_stride_uv, src_u, src_uv_width, src_v, + src_uv_width, src_uv_width, src_uv_height, 10); + r = ScalePlane_16(src_u, src_uv_width, src_uv_width, src_uv_height, dst_u, + dst_uv_width, dst_uv_width, dst_uv_height, filtering); + if (r == 0) { + r = ScalePlane_16(src_v, src_uv_width, src_uv_width, src_uv_height, dst_v, + dst_uv_width, dst_uv_width, dst_uv_height, filtering); + } + if (r == 0) { + MergeUVPlane_16(dst_u, dst_uv_width, dst_v, dst_uv_width, dst_uv, + dst_stride_uv, dst_uv_width, dst_uv_height, 10); + } + } + + free_aligned_buffer_64(src_uv_planes); + free_aligned_buffer_64(dst_uv_planes); + return r; +} + +LIBYUV_API +int NV12Scale(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering) { + return NVScale(src_y, src_stride_y, src_uv, src_stride_uv, src_width, + src_height, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + dst_width, dst_height, filtering, 1, 1); +} + +LIBYUV_API +int NV16Scale(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering) { + return NVScale(src_y, src_stride_y, src_uv, src_stride_uv, src_width, + src_height, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + dst_width, dst_height, filtering, 1, 0); +} + +LIBYUV_API +int NV24Scale(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering) { + return NVScale(src_y, src_stride_y, src_uv, src_stride_uv, src_width, + src_height, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + dst_width, dst_height, filtering, 0, 0); +} + +LIBYUV_API +int P010Scale(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering) { + return PxxxScale(src_y, src_stride_y, src_uv, src_stride_uv, src_width, + src_height, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + dst_width, dst_height, filtering, 1, 1); +} + +LIBYUV_API +int P210Scale(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering) { + return PxxxScale(src_y, src_stride_y, src_uv, src_stride_uv, src_width, + src_height, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + dst_width, dst_height, filtering, 1, 0); +} + +LIBYUV_API +int P410Scale(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering) { + return PxxxScale(src_y, src_stride_y, src_uv, src_stride_uv, src_width, + src_height, dst_y, dst_stride_y, dst_uv, dst_stride_uv, + dst_width, dst_height, filtering, 0, 0); } // Deprecated api @@ -1883,7 +3058,7 @@ int Scale(const uint8_t* src_y, int dst_stride_v, int dst_width, int dst_height, - LIBYUV_BOOL interpolate) { + int interpolate) { return I420Scale(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, src_width, src_height, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v, dst_width, diff --git a/libs/libyuv/source/scale_any.cc b/libs/libyuv/source/scale_any.cc index 17831372cf..ec903768e1 100644 --- a/libs/libyuv/source/scale_any.cc +++ b/libs/libyuv/source/scale_any.cc @@ -8,61 +8,17 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include #include // For memset/memcpy #include "libyuv/scale.h" #include "libyuv/scale_row.h" -#include "libyuv/basic_types.h" - #ifdef __cplusplus namespace libyuv { extern "C" { #endif -// Definition for ScaleFilterCols, ScaleARGBCols and ScaleARGBFilterCols -#define CANY(NAMEANY, TERP_SIMD, TERP_C, BPP, MASK) \ - void NAMEANY(uint8_t* dst_ptr, const uint8_t* src_ptr, int dst_width, int x, \ - int dx) { \ - int r = dst_width & MASK; \ - int n = dst_width & ~MASK; \ - if (n > 0) { \ - TERP_SIMD(dst_ptr, src_ptr, n, x, dx); \ - } \ - TERP_C(dst_ptr + n * BPP, src_ptr, r, x + n * dx, dx); \ - } - -#ifdef HAS_SCALEFILTERCOLS_NEON -CANY(ScaleFilterCols_Any_NEON, ScaleFilterCols_NEON, ScaleFilterCols_C, 1, 7) -#endif -#ifdef HAS_SCALEFILTERCOLS_MSA -CANY(ScaleFilterCols_Any_MSA, ScaleFilterCols_MSA, ScaleFilterCols_C, 1, 15) -#endif -#ifdef HAS_SCALEARGBCOLS_NEON -CANY(ScaleARGBCols_Any_NEON, ScaleARGBCols_NEON, ScaleARGBCols_C, 4, 7) -#endif -#ifdef HAS_SCALEARGBCOLS_MSA -CANY(ScaleARGBCols_Any_MSA, ScaleARGBCols_MSA, ScaleARGBCols_C, 4, 3) -#endif -#ifdef HAS_SCALEARGBCOLS_MMI -CANY(ScaleARGBCols_Any_MMI, ScaleARGBCols_MMI, ScaleARGBCols_C, 4, 0) -#endif -#ifdef HAS_SCALEARGBFILTERCOLS_NEON -CANY(ScaleARGBFilterCols_Any_NEON, - ScaleARGBFilterCols_NEON, - ScaleARGBFilterCols_C, - 4, - 3) -#endif -#ifdef HAS_SCALEARGBFILTERCOLS_MSA -CANY(ScaleARGBFilterCols_Any_MSA, - ScaleARGBFilterCols_MSA, - ScaleARGBFilterCols_C, - 4, - 7) -#endif -#undef CANY - // Fixed scale down. // Mask may be non-power of 2, so use MOD #define SDANY(NAMEANY, SCALEROWDOWN_SIMD, SCALEROWDOWN_C, FACTOR, BPP, MASK) \ @@ -73,8 +29,9 @@ CANY(ScaleARGBFilterCols_Any_MSA, if (n > 0) { \ SCALEROWDOWN_SIMD(src_ptr, src_stride, dst_ptr, n); \ } \ - SCALEROWDOWN_C(src_ptr + (n * FACTOR) * BPP, src_stride, \ - dst_ptr + n * BPP, r); \ + ptrdiff_t np = n; \ + SCALEROWDOWN_C(src_ptr + (np * FACTOR) * BPP, src_stride, \ + dst_ptr + np * BPP, r); \ } // Fixed scale down for odd source width. Used by I420Blend subsampling. @@ -88,8 +45,22 @@ CANY(ScaleARGBFilterCols_Any_MSA, if (n > 0) { \ SCALEROWDOWN_SIMD(src_ptr, src_stride, dst_ptr, n); \ } \ - SCALEROWDOWN_C(src_ptr + (n * FACTOR) * BPP, src_stride, \ - dst_ptr + n * BPP, r + 1); \ + ptrdiff_t np = n; \ + SCALEROWDOWN_C(src_ptr + (np * FACTOR) * BPP, src_stride, \ + dst_ptr + np * BPP, r + 1); \ + } + +// Fixed scale down for 16-bit planar. +#define SDANY16(NAMEANY, SCALEROWDOWN_SIMD, SCALEROWDOWN_C, FACTOR, MASK) \ + void NAMEANY(const uint16_t* src_ptr, ptrdiff_t src_stride, \ + uint16_t* dst_ptr, int dst_width) { \ + int r = (int)((unsigned int)dst_width % (MASK + 1)); /* NOLINT */ \ + int n = dst_width - r; \ + if (n > 0) { \ + SCALEROWDOWN_SIMD(src_ptr, src_stride, dst_ptr, n); \ + } \ + ptrdiff_t np = n; \ + SCALEROWDOWN_C(src_ptr + (np * FACTOR), src_stride, dst_ptr + np, r); \ } #ifdef HAS_SCALEROWDOWN2_SSSE3 @@ -113,6 +84,30 @@ SDODD(ScaleRowDown2Box_Odd_SSSE3, 1, 15) #endif +#ifdef HAS_SCALEUVROWDOWN2_AVX2 +SDANY(ScaleUVRowDown2_Any_AVX2, + ScaleUVRowDown2_AVX2, + ScaleUVRowDown2_C, + 2, + 2, + 7) +#endif +#ifdef HAS_SCALEUVROWDOWN2LINEAR_AVX2 +SDANY(ScaleUVRowDown2Linear_Any_AVX2, + ScaleUVRowDown2Linear_AVX2, + ScaleUVRowDown2Linear_C, + 2, + 2, + 7) +#endif +#ifdef HAS_SCALEUVROWDOWN2BOX_AVX2 +SDANY(ScaleUVRowDown2Box_Any_AVX2, + ScaleUVRowDown2Box_AVX2, + ScaleUVRowDown2Box_C, + 2, + 2, + 7) +#endif #ifdef HAS_SCALEROWDOWN2_AVX2 SDANY(ScaleRowDown2_Any_AVX2, ScaleRowDown2_AVX2, ScaleRowDown2_C, 2, 1, 31) SDANY(ScaleRowDown2Linear_Any_AVX2, @@ -134,6 +129,23 @@ SDODD(ScaleRowDown2Box_Odd_AVX2, 1, 31) #endif +#ifdef HAS_SCALEROWDOWN2_16_AVX2 +SDANY16(ScaleRowDown2_16_Any_AVX2, + ScaleRowDown2_16_AVX2, + ScaleRowDown2_16_C, + 2, + 15) +SDANY16(ScaleRowDown2Linear_16_Any_AVX2, + ScaleRowDown2Linear_16_AVX2, + ScaleRowDown2Linear_16_C, + 2, + 15) +SDANY16(ScaleRowDown2Box_16_Any_AVX2, + ScaleRowDown2Box_16_AVX2, + ScaleRowDown2Box_16_C, + 2, + 15) +#endif #ifdef HAS_SCALEROWDOWN2_NEON SDANY(ScaleRowDown2_Any_NEON, ScaleRowDown2_NEON, ScaleRowDown2_C, 2, 1, 15) SDANY(ScaleRowDown2Linear_Any_NEON, @@ -155,41 +167,44 @@ SDODD(ScaleRowDown2Box_Odd_NEON, 1, 15) #endif -#ifdef HAS_SCALEROWDOWN2_MSA -SDANY(ScaleRowDown2_Any_MSA, ScaleRowDown2_MSA, ScaleRowDown2_C, 2, 1, 31) -SDANY(ScaleRowDown2Linear_Any_MSA, - ScaleRowDown2Linear_MSA, - ScaleRowDown2Linear_C, +#ifdef HAS_SCALEUVROWDOWN2_NEON +SDANY(ScaleUVRowDown2_Any_NEON, + ScaleUVRowDown2_NEON, + ScaleUVRowDown2_C, 2, - 1, - 31) -SDANY(ScaleRowDown2Box_Any_MSA, - ScaleRowDown2Box_MSA, - ScaleRowDown2Box_C, 2, - 1, - 31) + 7) #endif -#ifdef HAS_SCALEROWDOWN2_MMI -SDANY(ScaleRowDown2_Any_MMI, ScaleRowDown2_MMI, ScaleRowDown2_C, 2, 1, 7) -SDANY(ScaleRowDown2Linear_Any_MMI, - ScaleRowDown2Linear_MMI, +#ifdef HAS_SCALEUVROWDOWN2LINEAR_NEON +SDANY(ScaleUVRowDown2Linear_Any_NEON, + ScaleUVRowDown2Linear_NEON, + ScaleUVRowDown2Linear_C, + 2, + 2, + 7) +#endif +#ifdef HAS_SCALEUVROWDOWN2BOX_NEON +SDANY(ScaleUVRowDown2Box_Any_NEON, + ScaleUVRowDown2Box_NEON, + ScaleUVRowDown2Box_C, + 2, + 2, + 7) +#endif +#ifdef HAS_SCALEROWDOWN2_LSX +SDANY(ScaleRowDown2_Any_LSX, ScaleRowDown2_LSX, ScaleRowDown2_C, 2, 1, 15) +SDANY(ScaleRowDown2Linear_Any_LSX, + ScaleRowDown2Linear_LSX, ScaleRowDown2Linear_C, 2, 1, - 7) -SDANY(ScaleRowDown2Box_Any_MMI, - ScaleRowDown2Box_MMI, + 15) +SDANY(ScaleRowDown2Box_Any_LSX, + ScaleRowDown2Box_LSX, ScaleRowDown2Box_C, 2, 1, - 7) -SDODD(ScaleRowDown2Box_Odd_MMI, - ScaleRowDown2Box_MMI, - ScaleRowDown2Box_Odd_C, - 2, - 1, - 7) + 15) #endif #ifdef HAS_SCALEROWDOWN4_SSSE3 SDANY(ScaleRowDown4_Any_SSSE3, ScaleRowDown4_SSSE3, ScaleRowDown4_C, 4, 1, 7) @@ -210,7 +225,7 @@ SDANY(ScaleRowDown4Box_Any_AVX2, 15) #endif #ifdef HAS_SCALEROWDOWN4_NEON -SDANY(ScaleRowDown4_Any_NEON, ScaleRowDown4_NEON, ScaleRowDown4_C, 4, 1, 7) +SDANY(ScaleRowDown4_Any_NEON, ScaleRowDown4_NEON, ScaleRowDown4_C, 4, 1, 15) SDANY(ScaleRowDown4Box_Any_NEON, ScaleRowDown4Box_NEON, ScaleRowDown4Box_C, @@ -218,45 +233,56 @@ SDANY(ScaleRowDown4Box_Any_NEON, 1, 7) #endif -#ifdef HAS_SCALEROWDOWN4_MSA -SDANY(ScaleRowDown4_Any_MSA, ScaleRowDown4_MSA, ScaleRowDown4_C, 4, 1, 15) -SDANY(ScaleRowDown4Box_Any_MSA, - ScaleRowDown4Box_MSA, - ScaleRowDown4Box_C, - 4, - 1, - 15) -#endif -#ifdef HAS_SCALEROWDOWN4_MMI -SDANY(ScaleRowDown4_Any_MMI, ScaleRowDown4_MMI, ScaleRowDown4_C, 4, 1, 7) -SDANY(ScaleRowDown4Box_Any_MMI, - ScaleRowDown4Box_MMI, +#ifdef HAS_SCALEROWDOWN4_LSX +SDANY(ScaleRowDown4_Any_LSX, ScaleRowDown4_LSX, ScaleRowDown4_C, 4, 1, 7) +SDANY(ScaleRowDown4Box_Any_LSX, + ScaleRowDown4Box_LSX, ScaleRowDown4Box_C, 4, 1, 7) #endif -#ifdef HAS_SCALEROWDOWN34_SSSE3 -SDANY(ScaleRowDown34_Any_SSSE3, - ScaleRowDown34_SSSE3, +#ifdef HAS_SCALEROWDOWN34_AVX2 +SDANY(ScaleRowDown34_Any_AVX2, + ScaleRowDown34_AVX2, ScaleRowDown34_C, 4 / 3, 1, 23) -SDANY(ScaleRowDown34_0_Box_Any_SSSE3, - ScaleRowDown34_0_Box_SSSE3, +SDANY(ScaleRowDown34_0_Box_Any_AVX2, + ScaleRowDown34_0_Box_AVX2, ScaleRowDown34_0_Box_C, 4 / 3, 1, 23) -SDANY(ScaleRowDown34_1_Box_Any_SSSE3, - ScaleRowDown34_1_Box_SSSE3, +SDANY(ScaleRowDown34_1_Box_Any_AVX2, + ScaleRowDown34_1_Box_AVX2, ScaleRowDown34_1_Box_C, 4 / 3, 1, 23) #endif #ifdef HAS_SCALEROWDOWN34_NEON +#ifdef __aarch64__ +SDANY(ScaleRowDown34_Any_NEON, + ScaleRowDown34_NEON, + ScaleRowDown34_C, + 4 / 3, + 1, + 47) +SDANY(ScaleRowDown34_0_Box_Any_NEON, + ScaleRowDown34_0_Box_NEON, + ScaleRowDown34_0_Box_C, + 4 / 3, + 1, + 47) +SDANY(ScaleRowDown34_1_Box_Any_NEON, + ScaleRowDown34_1_Box_NEON, + ScaleRowDown34_1_Box_C, + 4 / 3, + 1, + 47) +#else SDANY(ScaleRowDown34_Any_NEON, ScaleRowDown34_NEON, ScaleRowDown34_C, @@ -276,45 +302,46 @@ SDANY(ScaleRowDown34_1_Box_Any_NEON, 1, 23) #endif -#ifdef HAS_SCALEROWDOWN34_MSA -SDANY(ScaleRowDown34_Any_MSA, - ScaleRowDown34_MSA, +#endif +#ifdef HAS_SCALEROWDOWN34_LSX +SDANY(ScaleRowDown34_Any_LSX, + ScaleRowDown34_LSX, ScaleRowDown34_C, 4 / 3, 1, - 47) -SDANY(ScaleRowDown34_0_Box_Any_MSA, - ScaleRowDown34_0_Box_MSA, + 11) +SDANY(ScaleRowDown34_0_Box_Any_LSX, + ScaleRowDown34_0_Box_LSX, ScaleRowDown34_0_Box_C, 4 / 3, 1, - 47) -SDANY(ScaleRowDown34_1_Box_Any_MSA, - ScaleRowDown34_1_Box_MSA, + 11) +SDANY(ScaleRowDown34_1_Box_Any_LSX, + ScaleRowDown34_1_Box_LSX, ScaleRowDown34_1_Box_C, 4 / 3, 1, - 47) + 11) #endif -#ifdef HAS_SCALEROWDOWN38_SSSE3 -SDANY(ScaleRowDown38_Any_SSSE3, - ScaleRowDown38_SSSE3, +#ifdef HAS_SCALEROWDOWN38_AVX2 +SDANY(ScaleRowDown38_Any_AVX2, + ScaleRowDown38_AVX2, ScaleRowDown38_C, 8 / 3, 1, 11) -SDANY(ScaleRowDown38_3_Box_Any_SSSE3, - ScaleRowDown38_3_Box_SSSE3, +SDANY(ScaleRowDown38_3_Box_Any_AVX2, + ScaleRowDown38_3_Box_AVX2, ScaleRowDown38_3_Box_C, 8 / 3, 1, - 5) -SDANY(ScaleRowDown38_2_Box_Any_SSSE3, - ScaleRowDown38_2_Box_SSSE3, + 11) +SDANY(ScaleRowDown38_2_Box_Any_AVX2, + ScaleRowDown38_2_Box_AVX2, ScaleRowDown38_2_Box_C, 8 / 3, 1, - 5) + 11) #endif #ifdef HAS_SCALEROWDOWN38_NEON SDANY(ScaleRowDown38_Any_NEON, @@ -336,46 +363,46 @@ SDANY(ScaleRowDown38_2_Box_Any_NEON, 1, 11) #endif -#ifdef HAS_SCALEROWDOWN38_MSA -SDANY(ScaleRowDown38_Any_MSA, - ScaleRowDown38_MSA, +#ifdef HAS_SCALEROWDOWN38_LSX +SDANY(ScaleRowDown38_Any_LSX, + ScaleRowDown38_LSX, ScaleRowDown38_C, 8 / 3, 1, 11) -SDANY(ScaleRowDown38_3_Box_Any_MSA, - ScaleRowDown38_3_Box_MSA, +SDANY(ScaleRowDown38_3_Box_Any_LSX, + ScaleRowDown38_3_Box_LSX, ScaleRowDown38_3_Box_C, 8 / 3, 1, 11) -SDANY(ScaleRowDown38_2_Box_Any_MSA, - ScaleRowDown38_2_Box_MSA, +SDANY(ScaleRowDown38_2_Box_Any_LSX, + ScaleRowDown38_2_Box_LSX, ScaleRowDown38_2_Box_C, 8 / 3, 1, 11) #endif -#ifdef HAS_SCALEARGBROWDOWN2_SSE2 -SDANY(ScaleARGBRowDown2_Any_SSE2, - ScaleARGBRowDown2_SSE2, +#ifdef HAS_SCALEARGBROWDOWN2_AVX2 +SDANY(ScaleARGBRowDown2_Any_AVX2, + ScaleARGBRowDown2_AVX2, ScaleARGBRowDown2_C, 2, 4, - 3) -SDANY(ScaleARGBRowDown2Linear_Any_SSE2, - ScaleARGBRowDown2Linear_SSE2, + 7) +SDANY(ScaleARGBRowDown2Linear_Any_AVX2, + ScaleARGBRowDown2Linear_AVX2, ScaleARGBRowDown2Linear_C, 2, 4, - 3) -SDANY(ScaleARGBRowDown2Box_Any_SSE2, - ScaleARGBRowDown2Box_SSE2, + 7) +SDANY(ScaleARGBRowDown2Box_Any_AVX2, + ScaleARGBRowDown2Box_AVX2, ScaleARGBRowDown2Box_C, 2, 4, - 3) + 7) #endif #ifdef HAS_SCALEARGBROWDOWN2_NEON SDANY(ScaleARGBRowDown2_Any_NEON, @@ -397,46 +424,128 @@ SDANY(ScaleARGBRowDown2Box_Any_NEON, 4, 7) #endif -#ifdef HAS_SCALEARGBROWDOWN2_MSA -SDANY(ScaleARGBRowDown2_Any_MSA, - ScaleARGBRowDown2_MSA, +#ifdef HAS_SCALEARGBROWDOWN2_LSX +SDANY(ScaleARGBRowDown2_Any_LSX, + ScaleARGBRowDown2_LSX, ScaleARGBRowDown2_C, 2, 4, 3) -SDANY(ScaleARGBRowDown2Linear_Any_MSA, - ScaleARGBRowDown2Linear_MSA, +SDANY(ScaleARGBRowDown2Linear_Any_LSX, + ScaleARGBRowDown2Linear_LSX, ScaleARGBRowDown2Linear_C, 2, 4, 3) -SDANY(ScaleARGBRowDown2Box_Any_MSA, - ScaleARGBRowDown2Box_MSA, +SDANY(ScaleARGBRowDown2Box_Any_LSX, + ScaleARGBRowDown2Box_LSX, ScaleARGBRowDown2Box_C, 2, 4, 3) #endif -#ifdef HAS_SCALEARGBROWDOWN2_MMI -SDANY(ScaleARGBRowDown2_Any_MMI, - ScaleARGBRowDown2_MMI, +#ifdef HAS_SCALEROWDOWN2_WASMSIMD +SDANY(ScaleRowDown2_Any_WASMSIMD, + ScaleRowDown2_WASMSIMD, + ScaleRowDown2_C, + 2, + 1, + 15) +SDANY(ScaleRowDown2Linear_Any_WASMSIMD, + ScaleRowDown2Linear_WASMSIMD, + ScaleRowDown2Linear_C, + 2, + 1, + 15) +SDANY(ScaleRowDown2Box_Any_WASMSIMD, + ScaleRowDown2Box_WASMSIMD, + ScaleRowDown2Box_C, + 2, + 1, + 15) +SDODD(ScaleRowDown2Box_Odd_WASMSIMD, + ScaleRowDown2Box_WASMSIMD, + ScaleRowDown2Box_Odd_C, + 2, + 1, + 15) +#endif +#ifdef HAS_SCALEROWDOWN4_WASMSIMD +SDANY(ScaleRowDown4_Any_WASMSIMD, + ScaleRowDown4_WASMSIMD, + ScaleRowDown4_C, + 4, + 1, + 15) +SDANY(ScaleRowDown4Box_Any_WASMSIMD, + ScaleRowDown4Box_WASMSIMD, + ScaleRowDown4Box_C, + 4, + 1, + 7) +#endif +#ifdef HAS_SCALEROWDOWN34_WASMSIMD +SDANY(ScaleRowDown34_Any_WASMSIMD, + ScaleRowDown34_WASMSIMD, + ScaleRowDown34_C, + 4 / 3, + 1, + 23) +SDANY(ScaleRowDown34_0_Box_Any_WASMSIMD, + ScaleRowDown34_0_Box_WASMSIMD, + ScaleRowDown34_0_Box_C, + 4 / 3, + 1, + 23) +SDANY(ScaleRowDown34_1_Box_Any_WASMSIMD, + ScaleRowDown34_1_Box_WASMSIMD, + ScaleRowDown34_1_Box_C, + 4 / 3, + 1, + 23) +#endif +#ifdef HAS_SCALEROWDOWN38_WASMSIMD +SDANY(ScaleRowDown38_Any_WASMSIMD, + ScaleRowDown38_WASMSIMD, + ScaleRowDown38_C, + 8 / 3, + 1, + 11) +SDANY(ScaleRowDown38_3_Box_Any_WASMSIMD, + ScaleRowDown38_3_Box_WASMSIMD, + ScaleRowDown38_3_Box_C, + 8 / 3, + 1, + 11) +SDANY(ScaleRowDown38_2_Box_Any_WASMSIMD, + ScaleRowDown38_2_Box_WASMSIMD, + ScaleRowDown38_2_Box_C, + 8 / 3, + 1, + 11) +#endif +#ifdef HAS_SCALEARGBROWDOWN2_WASMSIMD +SDANY(ScaleARGBRowDown2_Any_WASMSIMD, + ScaleARGBRowDown2_WASMSIMD, ScaleARGBRowDown2_C, 2, 4, - 1) -SDANY(ScaleARGBRowDown2Linear_Any_MMI, - ScaleARGBRowDown2Linear_MMI, + 3) +SDANY(ScaleARGBRowDown2Linear_Any_WASMSIMD, + ScaleARGBRowDown2Linear_WASMSIMD, ScaleARGBRowDown2Linear_C, 2, 4, - 1) -SDANY(ScaleARGBRowDown2Box_Any_MMI, - ScaleARGBRowDown2Box_MMI, + 3) +SDANY(ScaleARGBRowDown2Box_Any_WASMSIMD, + ScaleARGBRowDown2Box_WASMSIMD, ScaleARGBRowDown2Box_C, 2, 4, - 1) + 3) #endif +#undef SDANY16 +#undef SDODD #undef SDANY // Scale down by even scale factor. @@ -448,21 +557,22 @@ SDANY(ScaleARGBRowDown2Box_Any_MMI, if (n > 0) { \ SCALEROWDOWN_SIMD(src_ptr, src_stride, src_stepx, dst_ptr, n); \ } \ - SCALEROWDOWN_C(src_ptr + (n * src_stepx) * BPP, src_stride, src_stepx, \ - dst_ptr + n * BPP, r); \ + ptrdiff_t np = n; \ + SCALEROWDOWN_C(src_ptr + (np * src_stepx) * BPP, src_stride, src_stepx, \ + dst_ptr + np * BPP, r); \ } -#ifdef HAS_SCALEARGBROWDOWNEVEN_SSE2 -SDAANY(ScaleARGBRowDownEven_Any_SSE2, - ScaleARGBRowDownEven_SSE2, +#ifdef HAS_SCALEARGBROWDOWNEVEN_AVX2 +SDAANY(ScaleARGBRowDownEven_Any_AVX2, + ScaleARGBRowDownEven_AVX2, ScaleARGBRowDownEven_C, 4, - 3) -SDAANY(ScaleARGBRowDownEvenBox_Any_SSE2, - ScaleARGBRowDownEvenBox_SSE2, + 7) +SDAANY(ScaleARGBRowDownEvenBox_Any_AVX2, + ScaleARGBRowDownEvenBox_AVX2, ScaleARGBRowDownEvenBox_C, 4, - 3) + 7) #endif #ifdef HAS_SCALEARGBROWDOWNEVEN_NEON SDAANY(ScaleARGBRowDownEven_Any_NEON, @@ -476,49 +586,75 @@ SDAANY(ScaleARGBRowDownEvenBox_Any_NEON, 4, 3) #endif -#ifdef HAS_SCALEARGBROWDOWNEVEN_MSA -SDAANY(ScaleARGBRowDownEven_Any_MSA, - ScaleARGBRowDownEven_MSA, +#ifdef HAS_SCALEARGBROWDOWNEVEN_LSX +SDAANY(ScaleARGBRowDownEven_Any_LSX, + ScaleARGBRowDownEven_LSX, ScaleARGBRowDownEven_C, 4, 3) -SDAANY(ScaleARGBRowDownEvenBox_Any_MSA, - ScaleARGBRowDownEvenBox_MSA, +SDAANY(ScaleARGBRowDownEvenBox_Any_LSX, + ScaleARGBRowDownEvenBox_LSX, ScaleARGBRowDownEvenBox_C, 4, 3) #endif -#ifdef HAS_SCALEARGBROWDOWNEVEN_MMI -SDAANY(ScaleARGBRowDownEven_Any_MMI, - ScaleARGBRowDownEven_MMI, +#ifdef HAS_SCALEUVROWDOWNEVEN_AVX2 +SDAANY(ScaleUVRowDownEven_Any_AVX2, + ScaleUVRowDownEven_AVX2, + ScaleUVRowDownEven_C, + 2, + 7) +#endif +#ifdef HAS_SCALEUVROWDOWNEVEN_NEON +SDAANY(ScaleUVRowDownEven_Any_NEON, + ScaleUVRowDownEven_NEON, + ScaleUVRowDownEven_C, + 2, + 3) +#endif +#ifdef HAS_SCALEARGBROWDOWNEVEN_WASMSIMD +SDAANY(ScaleARGBRowDownEven_Any_WASMSIMD, + ScaleARGBRowDownEven_WASMSIMD, ScaleARGBRowDownEven_C, 4, - 1) -SDAANY(ScaleARGBRowDownEvenBox_Any_MMI, - ScaleARGBRowDownEvenBox_MMI, + 3) +SDAANY(ScaleARGBRowDownEvenBox_Any_WASMSIMD, + ScaleARGBRowDownEvenBox_WASMSIMD, ScaleARGBRowDownEvenBox_C, 4, - 1) + 3) #endif #ifdef SASIMDONLY // This also works and uses memcpy and SIMD instead of C, but is slower on ARM +#ifdef LIBYUV_MSAN +#define MSAN_MEMSET(a, b, c) memset(a, b, c) +#else +#define MSAN_MEMSET(a, b, c) +#endif + // Add rows box filter scale down. Using macro from row_any #define SAROW(NAMEANY, ANY_SIMD, SBPP, BPP, MASK) \ void NAMEANY(const uint8_t* src_ptr, uint16_t* dst_ptr, int width) { \ - SIMD_ALIGNED(uint16_t dst_temp[32]); \ SIMD_ALIGNED(uint8_t src_temp[32]); \ - memset(dst_temp, 0, 32 * 2); /* for msan */ \ + static_assert((MASK + 1) * SBPP <= sizeof(src_temp), \ + "src_temp buffer too small"); \ + SIMD_ALIGNED(uint16_t dst_temp[32]); \ + static_assert((MASK + 1) * BPP <= sizeof(dst_temp), \ + "dst_temp buffer too small"); \ + MSAN_MEMSET(src_temp, 0, sizeof(src_temp)); /* for msan */ \ + MSAN_MEMSET(dst_temp, 0, sizeof(dst_temp)); /* for msan */ \ int r = width & MASK; \ int n = width & ~MASK; \ if (n > 0) { \ ANY_SIMD(src_ptr, dst_ptr, n); \ } \ - memcpy(src_temp, src_ptr + n * SBPP, r * SBPP); \ - memcpy(dst_temp, dst_ptr + n * BPP, r * BPP); \ + ptrdiff_t np = n; \ + memcpy(src_temp, src_ptr + np * SBPP, r * SBPP); \ + memcpy(dst_temp, dst_ptr + np * BPP, r * BPP); \ ANY_SIMD(src_temp, dst_temp, MASK + 1); \ - memcpy(dst_ptr + n * BPP, dst_temp, r * BPP); \ + memcpy(dst_ptr + np * BPP, dst_temp, r * BPP); \ } #ifdef HAS_SCALEADDROW_SSE2 @@ -530,11 +666,11 @@ SAROW(ScaleAddRow_Any_AVX2, ScaleAddRow_AVX2, 1, 2, 31) #ifdef HAS_SCALEADDROW_NEON SAROW(ScaleAddRow_Any_NEON, ScaleAddRow_NEON, 1, 2, 15) #endif -#ifdef HAS_SCALEADDROW_MSA -SAROW(ScaleAddRow_Any_MSA, ScaleAddRow_MSA, 1, 2, 15) +#ifdef HAS_SCALEADDROW_LSX +SAROW(ScaleAddRow_Any_LSX, ScaleAddRow_LSX, 1, 2, 15) #endif -#ifdef HAS_SCALEADDROW_MMI -SAROW(ScaleAddRow_Any_MMI, ScaleAddRow_MMI, 1, 2, 7) +#ifdef HAS_SCALEADDROW_WASMSIMD +SAROW(ScaleAddRow_Any_WASMSIMD, ScaleAddRow_WASMSIMD, 1, 2, 15) #endif #undef SAANY @@ -559,16 +695,523 @@ SAANY(ScaleAddRow_Any_AVX2, ScaleAddRow_AVX2, ScaleAddRow_C, 31) #ifdef HAS_SCALEADDROW_NEON SAANY(ScaleAddRow_Any_NEON, ScaleAddRow_NEON, ScaleAddRow_C, 15) #endif -#ifdef HAS_SCALEADDROW_MSA -SAANY(ScaleAddRow_Any_MSA, ScaleAddRow_MSA, ScaleAddRow_C, 15) +#ifdef HAS_SCALEADDROW_LSX +SAANY(ScaleAddRow_Any_LSX, ScaleAddRow_LSX, ScaleAddRow_C, 15) #endif -#ifdef HAS_SCALEADDROW_MMI -SAANY(ScaleAddRow_Any_MMI, ScaleAddRow_MMI, ScaleAddRow_C, 7) +#ifdef HAS_SCALEADDROW_WASMSIMD +SAANY(ScaleAddRow_Any_WASMSIMD, ScaleAddRow_WASMSIMD, ScaleAddRow_C, 15) #endif #undef SAANY #endif // SASIMDONLY +// Definition for ScaleFilterCols, ScaleARGBCols and ScaleARGBFilterCols +#define CANY(NAMEANY, TERP_SIMD, TERP_C, BPP, MASK) \ + void NAMEANY(uint8_t* dst_ptr, const uint8_t* src_ptr, int dst_width, int x, \ + int dx) { \ + int r = dst_width & MASK; \ + int n = dst_width & ~MASK; \ + if (n > 0) { \ + TERP_SIMD(dst_ptr, src_ptr, n, x, dx); \ + } \ + ptrdiff_t np = n; \ + TERP_C(dst_ptr + np * BPP, src_ptr, r, x + np * dx, dx); \ + } + +#ifdef HAS_SCALEFILTERCOLS_NEON +CANY(ScaleFilterCols_Any_NEON, ScaleFilterCols_NEON, ScaleFilterCols_C, 1, 7) +#endif +#ifdef HAS_SCALEFILTERCOLS_LSX +CANY(ScaleFilterCols_Any_LSX, ScaleFilterCols_LSX, ScaleFilterCols_C, 1, 3) +#endif +#ifdef HAS_SCALEARGBCOLS_NEON +CANY(ScaleARGBCols_Any_NEON, ScaleARGBCols_NEON, ScaleARGBCols_C, 4, 7) +#endif +#ifdef HAS_SCALEARGBCOLS_LSX +CANY(ScaleARGBCols_Any_LSX, ScaleARGBCols_LSX, ScaleARGBCols_C, 4, 3) +#endif +#ifdef HAS_SCALEARGBFILTERCOLS_NEON +CANY(ScaleARGBFilterCols_Any_NEON, + ScaleARGBFilterCols_NEON, + ScaleARGBFilterCols_C, + 4, + 3) +#endif +#ifdef HAS_SCALEARGBFILTERCOLS_LSX +CANY(ScaleARGBFilterCols_Any_LSX, + ScaleARGBFilterCols_LSX, + ScaleARGBFilterCols_C, + 4, + 3) +#endif +#ifdef HAS_SCALEFILTERCOLS_WASMSIMD +CANY(ScaleFilterCols_Any_WASMSIMD, + ScaleFilterCols_WASMSIMD, + ScaleFilterCols_C, + 1, + 7) +#endif +#ifdef HAS_SCALEARGBCOLS_WASMSIMD +CANY(ScaleARGBCols_Any_WASMSIMD, ScaleARGBCols_WASMSIMD, ScaleARGBCols_C, 4, 3) +#endif +#ifdef HAS_SCALEARGBFILTERCOLS_WASMSIMD +CANY(ScaleARGBFilterCols_Any_WASMSIMD, + ScaleARGBFilterCols_WASMSIMD, + ScaleARGBFilterCols_C, + 4, + 3) +#endif +#undef CANY + +// Scale up horizontally 2 times using linear filter. +#define SUH2LANY(NAME, SIMD, C, MASK, PTYPE) \ + void NAME(const PTYPE* src_ptr, PTYPE* dst_ptr, int dst_width) { \ + int work_width = (dst_width - 1) & ~1; \ + int r = work_width & MASK; \ + int n = work_width & ~MASK; \ + dst_ptr[0] = src_ptr[0]; \ + if (work_width > 0) { \ + if (n != 0) { \ + SIMD(src_ptr, dst_ptr + 1, n); \ + } \ + C(src_ptr + (n / 2), dst_ptr + n + 1, r); \ + } \ + dst_ptr[dst_width - 1] = src_ptr[(dst_width - 1) / 2]; \ + } + +// Even the C versions need to be wrapped, because boundary pixels have to +// be handled differently + +SUH2LANY(ScaleRowUp2_Linear_Any_C, + ScaleRowUp2_Linear_C, + ScaleRowUp2_Linear_C, + 0, + uint8_t) + +SUH2LANY(ScaleRowUp2_Linear_16_Any_C, + ScaleRowUp2_Linear_16_C, + ScaleRowUp2_Linear_16_C, + 0, + uint16_t) + +#ifdef HAS_SCALEROWUP2_LINEAR_SSE2 +SUH2LANY(ScaleRowUp2_Linear_Any_SSE2, + ScaleRowUp2_Linear_SSE2, + ScaleRowUp2_Linear_C, + 15, + uint8_t) +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_SSSE3 +SUH2LANY(ScaleRowUp2_Linear_Any_SSSE3, + ScaleRowUp2_Linear_SSSE3, + ScaleRowUp2_Linear_C, + 15, + uint8_t) +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_12_SSSE3 +SUH2LANY(ScaleRowUp2_Linear_12_Any_SSSE3, + ScaleRowUp2_Linear_12_SSSE3, + ScaleRowUp2_Linear_16_C, + 15, + uint16_t) +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_16_SSE2 +SUH2LANY(ScaleRowUp2_Linear_16_Any_SSE2, + ScaleRowUp2_Linear_16_SSE2, + ScaleRowUp2_Linear_16_C, + 7, + uint16_t) +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_AVX2 +SUH2LANY(ScaleRowUp2_Linear_Any_AVX2, + ScaleRowUp2_Linear_AVX2, + ScaleRowUp2_Linear_C, + 31, + uint8_t) +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_12_AVX2 +SUH2LANY(ScaleRowUp2_Linear_12_Any_AVX2, + ScaleRowUp2_Linear_12_AVX2, + ScaleRowUp2_Linear_16_C, + 31, + uint16_t) +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_16_AVX2 +SUH2LANY(ScaleRowUp2_Linear_16_Any_AVX2, + ScaleRowUp2_Linear_16_AVX2, + ScaleRowUp2_Linear_16_C, + 15, + uint16_t) +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_NEON +#ifdef __aarch64__ +SUH2LANY(ScaleRowUp2_Linear_Any_NEON, + ScaleRowUp2_Linear_NEON, + ScaleRowUp2_Linear_C, + 31, + uint8_t) +#else +SUH2LANY(ScaleRowUp2_Linear_Any_NEON, + ScaleRowUp2_Linear_NEON, + ScaleRowUp2_Linear_C, + 15, + uint8_t) +#endif +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_12_NEON +SUH2LANY(ScaleRowUp2_Linear_12_Any_NEON, + ScaleRowUp2_Linear_12_NEON, + ScaleRowUp2_Linear_16_C, + 15, + uint16_t) +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_16_NEON +SUH2LANY(ScaleRowUp2_Linear_16_Any_NEON, + ScaleRowUp2_Linear_16_NEON, + ScaleRowUp2_Linear_16_C, + 15, + uint16_t) +#endif + +#undef SUH2LANY + +// Scale up 2 times using bilinear filter. +// This function produces 2 rows at a time. +#define SU2BLANY(NAME, SIMD, C, MASK, PTYPE) \ + void NAME(const PTYPE* src_ptr, ptrdiff_t src_stride, PTYPE* dst_ptr, \ + ptrdiff_t dst_stride, int dst_width) { \ + int work_width = (dst_width - 1) & ~1; \ + int r = work_width & MASK; \ + int n = work_width & ~MASK; \ + const PTYPE* sa = src_ptr; \ + const PTYPE* sb = src_ptr + src_stride; \ + PTYPE* da = dst_ptr; \ + PTYPE* db = dst_ptr + dst_stride; \ + da[0] = (3 * sa[0] + sb[0] + 2) >> 2; \ + db[0] = (sa[0] + 3 * sb[0] + 2) >> 2; \ + if (work_width > 0) { \ + if (n != 0) { \ + SIMD(sa, sb - sa, da + 1, db - da, n); \ + } \ + C(sa + (n / 2), sb - sa, da + n + 1, db - da, r); \ + } \ + da[dst_width - 1] = \ + (3 * sa[(dst_width - 1) / 2] + sb[(dst_width - 1) / 2] + 2) >> 2; \ + db[dst_width - 1] = \ + (sa[(dst_width - 1) / 2] + 3 * sb[(dst_width - 1) / 2] + 2) >> 2; \ + } + +SU2BLANY(ScaleRowUp2_Bilinear_Any_C, + ScaleRowUp2_Bilinear_C, + ScaleRowUp2_Bilinear_C, + 0, + uint8_t) + +SU2BLANY(ScaleRowUp2_Bilinear_16_Any_C, + ScaleRowUp2_Bilinear_16_C, + ScaleRowUp2_Bilinear_16_C, + 0, + uint16_t) + +#ifdef HAS_SCALEROWUP2_BILINEAR_SSE2 +SU2BLANY(ScaleRowUp2_Bilinear_Any_SSE2, + ScaleRowUp2_Bilinear_SSE2, + ScaleRowUp2_Bilinear_C, + 15, + uint8_t) +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_12_SSSE3 +SU2BLANY(ScaleRowUp2_Bilinear_12_Any_SSSE3, + ScaleRowUp2_Bilinear_12_SSSE3, + ScaleRowUp2_Bilinear_16_C, + 15, + uint16_t) +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_16_SSE2 +SU2BLANY(ScaleRowUp2_Bilinear_16_Any_SSE2, + ScaleRowUp2_Bilinear_16_SSE2, + ScaleRowUp2_Bilinear_16_C, + 7, + uint16_t) +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_SSSE3 +SU2BLANY(ScaleRowUp2_Bilinear_Any_SSSE3, + ScaleRowUp2_Bilinear_SSSE3, + ScaleRowUp2_Bilinear_C, + 15, + uint8_t) +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_AVX2 +SU2BLANY(ScaleRowUp2_Bilinear_Any_AVX2, + ScaleRowUp2_Bilinear_AVX2, + ScaleRowUp2_Bilinear_C, + 31, + uint8_t) +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_12_AVX2 +SU2BLANY(ScaleRowUp2_Bilinear_12_Any_AVX2, + ScaleRowUp2_Bilinear_12_AVX2, + ScaleRowUp2_Bilinear_16_C, + 15, + uint16_t) +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_16_AVX2 +SU2BLANY(ScaleRowUp2_Bilinear_16_Any_AVX2, + ScaleRowUp2_Bilinear_16_AVX2, + ScaleRowUp2_Bilinear_16_C, + 15, + uint16_t) +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_NEON +SU2BLANY(ScaleRowUp2_Bilinear_Any_NEON, + ScaleRowUp2_Bilinear_NEON, + ScaleRowUp2_Bilinear_C, + 15, + uint8_t) +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_12_NEON +SU2BLANY(ScaleRowUp2_Bilinear_12_Any_NEON, + ScaleRowUp2_Bilinear_12_NEON, + ScaleRowUp2_Bilinear_16_C, + 15, + uint16_t) +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_16_NEON +SU2BLANY(ScaleRowUp2_Bilinear_16_Any_NEON, + ScaleRowUp2_Bilinear_16_NEON, + ScaleRowUp2_Bilinear_16_C, + 7, + uint16_t) +#endif + +#undef SU2BLANY + +// Scale bi-planar plane up horizontally 2 times using linear filter. +#define SBUH2LANY(NAME, SIMD, C, MASK, PTYPE) \ + void NAME(const PTYPE* src_ptr, PTYPE* dst_ptr, int dst_width) { \ + int work_width = (dst_width - 1) & ~1; \ + int r = work_width & MASK; \ + int n = work_width & ~MASK; \ + dst_ptr[0] = src_ptr[0]; \ + dst_ptr[1] = src_ptr[1]; \ + if (work_width > 0) { \ + if (n != 0) { \ + SIMD(src_ptr, dst_ptr + 2, n); \ + } \ + ptrdiff_t np = n; \ + C(src_ptr + np, dst_ptr + 2 * np + 2, r); \ + } \ + dst_ptr[2 * dst_width - 2] = src_ptr[((dst_width + 1) & ~1) - 2]; \ + dst_ptr[2 * dst_width - 1] = src_ptr[((dst_width + 1) & ~1) - 1]; \ + } + +SBUH2LANY(ScaleUVRowUp2_Linear_Any_C, + ScaleUVRowUp2_Linear_C, + ScaleUVRowUp2_Linear_C, + 0, + uint8_t) + +SBUH2LANY(ScaleUVRowUp2_Linear_16_Any_C, + ScaleUVRowUp2_Linear_16_C, + ScaleUVRowUp2_Linear_16_C, + 0, + uint16_t) + +#ifdef HAS_SCALEUVROWUP2_LINEAR_SSSE3 +SBUH2LANY(ScaleUVRowUp2_Linear_Any_SSSE3, + ScaleUVRowUp2_Linear_SSSE3, + ScaleUVRowUp2_Linear_C, + 7, + uint8_t) +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_AVX2 +SBUH2LANY(ScaleUVRowUp2_Linear_Any_AVX2, + ScaleUVRowUp2_Linear_AVX2, + ScaleUVRowUp2_Linear_C, + 15, + uint8_t) +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_SSE41 +SBUH2LANY(ScaleUVRowUp2_Linear_16_Any_SSE41, + ScaleUVRowUp2_Linear_16_SSE41, + ScaleUVRowUp2_Linear_16_C, + 3, + uint16_t) +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_AVX2 +SBUH2LANY(ScaleUVRowUp2_Linear_16_Any_AVX2, + ScaleUVRowUp2_Linear_16_AVX2, + ScaleUVRowUp2_Linear_16_C, + 7, + uint16_t) +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_NEON +SBUH2LANY(ScaleUVRowUp2_Linear_Any_NEON, + ScaleUVRowUp2_Linear_NEON, + ScaleUVRowUp2_Linear_C, + 7, + uint8_t) +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_NEON +SBUH2LANY(ScaleUVRowUp2_Linear_16_Any_NEON, + ScaleUVRowUp2_Linear_16_NEON, + ScaleUVRowUp2_Linear_16_C, + 7, + uint16_t) +#endif + +#undef SBUH2LANY + +// Scale bi-planar plane up 2 times using bilinear filter. +// This function produces 2 rows at a time. +#define SBU2BLANY(NAME, SIMD, C, MASK, PTYPE) \ + void NAME(const PTYPE* src_ptr, ptrdiff_t src_stride, PTYPE* dst_ptr, \ + ptrdiff_t dst_stride, int dst_width) { \ + int work_width = (dst_width - 1) & ~1; \ + int r = work_width & MASK; \ + int n = work_width & ~MASK; \ + const PTYPE* sa = src_ptr; \ + const PTYPE* sb = src_ptr + src_stride; \ + PTYPE* da = dst_ptr; \ + PTYPE* db = dst_ptr + dst_stride; \ + da[0] = (3 * sa[0] + sb[0] + 2) >> 2; \ + db[0] = (sa[0] + 3 * sb[0] + 2) >> 2; \ + da[1] = (3 * sa[1] + sb[1] + 2) >> 2; \ + db[1] = (sa[1] + 3 * sb[1] + 2) >> 2; \ + if (work_width > 0) { \ + if (n != 0) { \ + SIMD(sa, sb - sa, da + 2, db - da, n); \ + } \ + ptrdiff_t np = n; \ + C(sa + np, sb - sa, da + 2 * np + 2, db - da, r); \ + } \ + da[2 * dst_width - 2] = (3 * sa[((dst_width + 1) & ~1) - 2] + \ + sb[((dst_width + 1) & ~1) - 2] + 2) >> \ + 2; \ + db[2 * dst_width - 2] = (sa[((dst_width + 1) & ~1) - 2] + \ + 3 * sb[((dst_width + 1) & ~1) - 2] + 2) >> \ + 2; \ + da[2 * dst_width - 1] = (3 * sa[((dst_width + 1) & ~1) - 1] + \ + sb[((dst_width + 1) & ~1) - 1] + 2) >> \ + 2; \ + db[2 * dst_width - 1] = (sa[((dst_width + 1) & ~1) - 1] + \ + 3 * sb[((dst_width + 1) & ~1) - 1] + 2) >> \ + 2; \ + } + +SBU2BLANY(ScaleUVRowUp2_Bilinear_Any_C, + ScaleUVRowUp2_Bilinear_C, + ScaleUVRowUp2_Bilinear_C, + 0, + uint8_t) + +SBU2BLANY(ScaleUVRowUp2_Bilinear_16_Any_C, + ScaleUVRowUp2_Bilinear_16_C, + ScaleUVRowUp2_Bilinear_16_C, + 0, + uint16_t) + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_SSSE3 +SBU2BLANY(ScaleUVRowUp2_Bilinear_Any_SSSE3, + ScaleUVRowUp2_Bilinear_SSSE3, + ScaleUVRowUp2_Bilinear_C, + 7, + uint8_t) +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_AVX2 +SBU2BLANY(ScaleUVRowUp2_Bilinear_Any_AVX2, + ScaleUVRowUp2_Bilinear_AVX2, + ScaleUVRowUp2_Bilinear_C, + 15, + uint8_t) +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_SSE41 +SBU2BLANY(ScaleUVRowUp2_Bilinear_16_Any_SSE41, + ScaleUVRowUp2_Bilinear_16_SSE41, + ScaleUVRowUp2_Bilinear_16_C, + 3, + uint16_t) +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_AVX2 +SBU2BLANY(ScaleUVRowUp2_Bilinear_16_Any_AVX2, + ScaleUVRowUp2_Bilinear_16_AVX2, + ScaleUVRowUp2_Bilinear_16_C, + 7, + uint16_t) +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_NEON +SBU2BLANY(ScaleUVRowUp2_Bilinear_Any_NEON, + ScaleUVRowUp2_Bilinear_NEON, + ScaleUVRowUp2_Bilinear_C, + 7, + uint8_t) +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_NEON +SBU2BLANY(ScaleUVRowUp2_Bilinear_16_Any_NEON, + ScaleUVRowUp2_Bilinear_16_NEON, + ScaleUVRowUp2_Bilinear_16_C, + 7, + uint16_t) +#endif + +#undef SBU2BLANY + +// Scale UV columns by 3 box filter. +#define SUVAC3ANY(NAMEANY, SIMD, C, MASK) \ + void NAMEANY(int dst_width, int scaleval, const uint16_t* src_uv, \ + uint8_t* dst_uv) { \ + int r = dst_width & MASK; \ + int n = dst_width & ~MASK; \ + if (n > 0) { \ + SIMD(n, scaleval, src_uv, dst_uv); \ + } \ + C(r, scaleval, src_uv + (ptrdiff_t)n * 6, dst_uv + (ptrdiff_t)n * 2); \ + } +#ifdef HAS_SCALEUVADDCOLS3_AVX2 +SUVAC3ANY(ScaleUVAddCols3_Any_AVX2, ScaleUVAddCols3_AVX2, ScaleUVAddCols3_C, 7) +#endif +#ifdef HAS_SCALEUVADDCOLS3_NEON +SUVAC3ANY(ScaleUVAddCols3_Any_NEON, ScaleUVAddCols3_NEON, ScaleUVAddCols3_C, 7) +#endif +#ifdef HAS_SCALEUVADDCOLS3_LSX +SUVAC3ANY(ScaleUVAddCols3_Any_LSX, ScaleUVAddCols3_LSX, ScaleUVAddCols3_C, 7) +#endif +#ifdef HAS_SCALEUVADDCOLS3_WASMSIMD +SUVAC3ANY(ScaleUVAddCols3_Any_WASMSIMD, + ScaleUVAddCols3_WASMSIMD, + ScaleUVAddCols3_C, + 7) +#endif +#undef SUVAC3ANY + #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/source/scale_argb.cc b/libs/libyuv/source/scale_argb.cc index beef380a8e..53280ea166 100644 --- a/libs/libyuv/source/scale_argb.cc +++ b/libs/libyuv/source/scale_argb.cc @@ -11,11 +11,15 @@ #include "libyuv/scale.h" #include +#include +#include +#include #include #include "libyuv/cpu_id.h" #include "libyuv/planar_functions.h" // For CopyARGB #include "libyuv/row.h" +#include "libyuv/scale_argb.h" #include "libyuv/scale_row.h" #ifdef __cplusplus @@ -34,8 +38,8 @@ static void ScaleARGBDown2(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint8_t* src_argb, uint8_t* dst_argb, int x, @@ -44,7 +48,7 @@ static void ScaleARGBDown2(int src_width, int dy, enum FilterMode filtering) { int j; - int row_stride = src_stride * (dy >> 16); + ptrdiff_t row_stride = src_stride * (dy >> 16); void (*ScaleARGBRowDown2)(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width) = filtering == kFilterNone @@ -63,19 +67,19 @@ static void ScaleARGBDown2(int src_width, src_argb += (y >> 16) * src_stride + ((x >> 16) - 1) * 4; } -#if defined(HAS_SCALEARGBROWDOWN2_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { +#if defined(HAS_SCALEARGBROWDOWN2_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { ScaleARGBRowDown2 = filtering == kFilterNone - ? ScaleARGBRowDown2_Any_SSE2 - : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_SSE2 - : ScaleARGBRowDown2Box_Any_SSE2); - if (IS_ALIGNED(dst_width, 4)) { + ? ScaleARGBRowDown2_Any_AVX2 + : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_AVX2 + : ScaleARGBRowDown2Box_Any_AVX2); + if (IS_ALIGNED(dst_width, 8)) { ScaleARGBRowDown2 = filtering == kFilterNone - ? ScaleARGBRowDown2_SSE2 - : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_SSE2 - : ScaleARGBRowDown2Box_SSE2); + ? ScaleARGBRowDown2_AVX2 + : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_AVX2 + : ScaleARGBRowDown2Box_AVX2); } } #endif @@ -95,38 +99,66 @@ static void ScaleARGBDown2(int src_width, } } #endif -#if defined(HAS_SCALEARGBROWDOWN2_MSA) - if (TestCpuFlag(kCpuHasMSA)) { +#if defined(HAS_SCALEARGBROWDOWN2_SME) + if (TestCpuFlag(kCpuHasSME)) { + ScaleARGBRowDown2 = filtering == kFilterNone ? ScaleARGBRowDown2_SME + : filtering == kFilterLinear + ? ScaleARGBRowDown2Linear_SME + : ScaleARGBRowDown2Box_SME; + } +#endif +#if defined(HAS_SCALEARGBROWDOWN2_LSX) + if (TestCpuFlag(kCpuHasLSX)) { ScaleARGBRowDown2 = filtering == kFilterNone - ? ScaleARGBRowDown2_Any_MSA - : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_MSA - : ScaleARGBRowDown2Box_Any_MSA); + ? ScaleARGBRowDown2_Any_LSX + : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_LSX + : ScaleARGBRowDown2Box_Any_LSX); if (IS_ALIGNED(dst_width, 4)) { ScaleARGBRowDown2 = filtering == kFilterNone - ? ScaleARGBRowDown2_MSA - : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_MSA - : ScaleARGBRowDown2Box_MSA); + ? ScaleARGBRowDown2_LSX + : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_LSX + : ScaleARGBRowDown2Box_LSX); } } #endif -#if defined(HAS_SCALEARGBROWDOWN2_MMI) - if (TestCpuFlag(kCpuHasMMI)) { +#if defined(HAS_SCALEARGBROWDOWN2_RVV) && \ + defined(HAS_SCALEARGBROWDOWN2LINEAR_RVV) && \ + defined(HAS_SCALEARGBROWDOWN2BOX_RVV) + if (TestCpuFlag(kCpuHasRVV)) { ScaleARGBRowDown2 = filtering == kFilterNone - ? ScaleARGBRowDown2_Any_MMI - : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_MMI - : ScaleARGBRowDown2Box_Any_MMI); - if (IS_ALIGNED(dst_width, 2)) { + ? ScaleARGBRowDown2_RVV + : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_RVV + : ScaleARGBRowDown2Box_RVV); + } +#endif +#if defined(HAS_SCALEARGBROWDOWN2_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ScaleARGBRowDown2 = + filtering == kFilterNone + ? ScaleARGBRowDown2_Any_WASMSIMD + : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_WASMSIMD + : ScaleARGBRowDown2Box_Any_WASMSIMD); + if (IS_ALIGNED(dst_width, 4)) { ScaleARGBRowDown2 = filtering == kFilterNone - ? ScaleARGBRowDown2_MMI - : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_MMI - : ScaleARGBRowDown2Box_MMI); + ? ScaleARGBRowDown2_WASMSIMD + : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_WASMSIMD + : ScaleARGBRowDown2Box_WASMSIMD); } } #endif +#if defined(HAS_SCALEARGBROWDOWN2_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ScaleARGBRowDown2 = + filtering == kFilterNone + ? ScaleARGBRowDown2_HVX + : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_HVX + : ScaleARGBRowDown2Box_HVX); + } +#endif if (filtering == kFilterLinear) { src_stride = 0; @@ -141,23 +173,28 @@ static void ScaleARGBDown2(int src_width, // ScaleARGB ARGB, 1/4 // This is an optimized version for scaling down a ARGB to 1/4 of // its original size. -static void ScaleARGBDown4Box(int src_width, - int src_height, - int dst_width, - int dst_height, - int src_stride, - int dst_stride, - const uint8_t* src_argb, - uint8_t* dst_argb, - int x, - int dx, - int y, - int dy) { +static int ScaleARGBDown4Box(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_argb, + uint8_t* dst_argb, + int x, + int dx, + int y, + int dy) { int j; // Allocate 2 rows of ARGB. - const int kRowSize = (dst_width * 2 * 4 + 31) & ~31; - align_buffer_64(row, kRowSize * 2); - int row_stride = src_stride * (dy >> 16); + const int row_size = (dst_width * 2 * 4 + 31) & ~31; + // TODO(fbarchard): Remove this row buffer and implement a ScaleARGBRowDown4 + // but implemented via a 2 pass wrapper that uses a very small array on the + // stack with a horizontal loop. + align_buffer_64(row, row_size * 2); + if (!row) + return 1; + ptrdiff_t row_stride = src_stride * (dy >> 16); void (*ScaleARGBRowDown2)(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width) = ScaleARGBRowDown2Box_C; @@ -168,11 +205,11 @@ static void ScaleARGBDown4Box(int src_width, (void)dx; assert(dx == 65536 * 4); // Test scale factor of 4. assert((dy & 0x3ffff) == 0); // Test vertical scale is multiple of 4. -#if defined(HAS_SCALEARGBROWDOWN2_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ScaleARGBRowDown2 = ScaleARGBRowDown2Box_Any_SSE2; - if (IS_ALIGNED(dst_width, 4)) { - ScaleARGBRowDown2 = ScaleARGBRowDown2Box_SSE2; +#if defined(HAS_SCALEARGBROWDOWN2_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleARGBRowDown2 = ScaleARGBRowDown2Box_Any_AVX2; + if (IS_ALIGNED(dst_width, 8)) { + ScaleARGBRowDown2 = ScaleARGBRowDown2Box_AVX2; } } #endif @@ -184,16 +221,40 @@ static void ScaleARGBDown4Box(int src_width, } } #endif +#if defined(HAS_SCALEARGBROWDOWN2_SME) + if (TestCpuFlag(kCpuHasSME)) { + ScaleARGBRowDown2 = ScaleARGBRowDown2Box_SME; + } +#endif +#if defined(HAS_SCALEARGBROWDOWN2BOX_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleARGBRowDown2 = ScaleARGBRowDown2Box_RVV; + } +#endif +#if defined(HAS_SCALEARGBROWDOWN2_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ScaleARGBRowDown2 = ScaleARGBRowDown2Box_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 4)) { + ScaleARGBRowDown2 = ScaleARGBRowDown2Box_WASMSIMD; + } + } +#endif +#if defined(HAS_SCALEARGBROWDOWN2_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ScaleARGBRowDown2 = ScaleARGBRowDown2Box_HVX; + } +#endif for (j = 0; j < dst_height; ++j) { ScaleARGBRowDown2(src_argb, src_stride, row, dst_width * 2); - ScaleARGBRowDown2(src_argb + src_stride * 2, src_stride, row + kRowSize, + ScaleARGBRowDown2(src_argb + src_stride * 2, src_stride, row + row_size, dst_width * 2); - ScaleARGBRowDown2(row, kRowSize, dst_argb, dst_width); + ScaleARGBRowDown2(row, row_size, dst_argb, dst_width); src_argb += row_stride; dst_argb += dst_stride; } free_aligned_buffer_64(row); + return 0; } // ScaleARGB ARGB Even @@ -203,8 +264,8 @@ static void ScaleARGBDownEven(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint8_t* src_argb, uint8_t* dst_argb, int x, @@ -214,7 +275,7 @@ static void ScaleARGBDownEven(int src_width, enum FilterMode filtering) { int j; int col_step = dx >> 16; - int row_stride = (dy >> 16) * src_stride; + ptrdiff_t row_stride = (dy >> 16) * src_stride; void (*ScaleARGBRowDownEven)(const uint8_t* src_argb, ptrdiff_t src_stride, int src_step, uint8_t* dst_argb, int dst_width) = filtering ? ScaleARGBRowDownEvenBox_C : ScaleARGBRowDownEven_C; @@ -223,13 +284,13 @@ static void ScaleARGBDownEven(int src_width, assert(IS_ALIGNED(src_width, 2)); assert(IS_ALIGNED(src_height, 2)); src_argb += (y >> 16) * src_stride + (x >> 16) * 4; -#if defined(HAS_SCALEARGBROWDOWNEVEN_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_SSE2 - : ScaleARGBRowDownEven_Any_SSE2; - if (IS_ALIGNED(dst_width, 4)) { +#if defined(HAS_SCALEARGBROWDOWNEVEN_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_AVX2 + : ScaleARGBRowDownEven_Any_AVX2; + if (IS_ALIGNED(dst_width, 8)) { ScaleARGBRowDownEven = - filtering ? ScaleARGBRowDownEvenBox_SSE2 : ScaleARGBRowDownEven_SSE2; + filtering ? ScaleARGBRowDownEvenBox_AVX2 : ScaleARGBRowDownEven_AVX2; } } #endif @@ -243,23 +304,33 @@ static void ScaleARGBDownEven(int src_width, } } #endif -#if defined(HAS_SCALEARGBROWDOWNEVEN_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_MSA - : ScaleARGBRowDownEven_Any_MSA; +#if defined(HAS_SCALEARGBROWDOWNEVEN_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_LSX + : ScaleARGBRowDownEven_Any_LSX; if (IS_ALIGNED(dst_width, 4)) { ScaleARGBRowDownEven = - filtering ? ScaleARGBRowDownEvenBox_MSA : ScaleARGBRowDownEven_MSA; + filtering ? ScaleARGBRowDownEvenBox_LSX : ScaleARGBRowDownEven_LSX; } } #endif -#if defined(HAS_SCALEARGBROWDOWNEVEN_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_MMI - : ScaleARGBRowDownEven_Any_MMI; - if (IS_ALIGNED(dst_width, 2)) { - ScaleARGBRowDownEven = - filtering ? ScaleARGBRowDownEvenBox_MMI : ScaleARGBRowDownEven_MMI; +#if defined(HAS_SCALEARGBROWDOWNEVENBOX_RVV) + if (filtering && TestCpuFlag(kCpuHasRVV)) { + ScaleARGBRowDownEven = ScaleARGBRowDownEvenBox_RVV; + } +#endif +#if defined(HAS_SCALEARGBROWDOWNEVEN_RVV) + if (!filtering && TestCpuFlag(kCpuHasRVV)) { + ScaleARGBRowDownEven = ScaleARGBRowDownEven_RVV; + } +#endif +#if defined(HAS_SCALEARGBROWDOWNEVEN_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_WASMSIMD + : ScaleARGBRowDownEven_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 4)) { + ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_WASMSIMD + : ScaleARGBRowDownEven_WASMSIMD; } } #endif @@ -275,24 +346,24 @@ static void ScaleARGBDownEven(int src_width, } // Scale ARGB down with bilinear interpolation. -static void ScaleARGBBilinearDown(int src_width, - int src_height, - int dst_width, - int dst_height, - int src_stride, - int dst_stride, - const uint8_t* src_argb, - uint8_t* dst_argb, - int x, - int dx, - int y, - int dy, - enum FilterMode filtering) { +static int ScaleARGBBilinearDown(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_argb, + uint8_t* dst_argb, + int x, + int dx, + int y, + int dy, + enum FilterMode filtering) { int j; - void (*InterpolateRow)(uint8_t * dst_argb, const uint8_t* src_argb, + void (*InterpolateRow)(uint8_t* dst_argb, const uint8_t* src_argb, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_C; - void (*ScaleARGBFilterCols)(uint8_t * dst_argb, const uint8_t* src_argb, + void (*ScaleARGBFilterCols)(uint8_t* dst_argb, const uint8_t* src_argb, int dst_width, int x, int dx) = (src_width >= 32768) ? ScaleARGBFilterCols64_C : ScaleARGBFilterCols_C; int64_t xlast = x + (int64_t)(dst_width - 1) * dx; @@ -308,14 +379,6 @@ static void ScaleARGBBilinearDown(int src_width, clip_src_width = (int)(xr - xl) * 4; // Width aligned to 4. src_argb += xl * 4; x -= (int)(xl << 16); -#if defined(HAS_INTERPOLATEROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_SSSE3; - if (IS_ALIGNED(clip_src_width, 16)) { - InterpolateRow = InterpolateRow_SSSE3; - } - } -#endif #if defined(HAS_INTERPOLATEROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { InterpolateRow = InterpolateRow_Any_AVX2; @@ -324,6 +387,11 @@ static void ScaleARGBBilinearDown(int src_width, } } #endif +#if defined(HAS_INTERPOLATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_AVX512BW; + } +#endif #if defined(HAS_INTERPOLATEROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { InterpolateRow = InterpolateRow_Any_NEON; @@ -332,17 +400,53 @@ static void ScaleARGBBilinearDown(int src_width, } } #endif -#if defined(HAS_INTERPOLATEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - InterpolateRow = InterpolateRow_Any_MSA; - if (IS_ALIGNED(clip_src_width, 32)) { - InterpolateRow = InterpolateRow_MSA; +#if defined(HAS_INTERPOLATEROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + InterpolateRow = InterpolateRow_SVE2; + } +#endif +#if defined(HAS_INTERPOLATEROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + InterpolateRow = InterpolateRow_Any_LSX; + if (IS_ALIGNED(clip_src_width, 16)) { + InterpolateRow = InterpolateRow_LSX; } } #endif -#if defined(HAS_SCALEARGBFILTERCOLS_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) { - ScaleARGBFilterCols = ScaleARGBFilterCols_SSSE3; +#if defined(HAS_INTERPOLATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + InterpolateRow = InterpolateRow_Any_LASX; + if (IS_ALIGNED(clip_src_width, 32)) { + InterpolateRow = InterpolateRow_LASX; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + InterpolateRow = InterpolateRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_HVX; + } +#endif +#if defined(HAS_INTERPOLATEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_Any_WASMSIMD; + if (IS_ALIGNED(clip_src_width, 16)) { + InterpolateRow = InterpolateRow_WASMSIMD; + } + } +#endif +#if defined(HAS_SCALEARGBFILTERCOLS_AVX2) + if (TestCpuFlag(kCpuHasAVX2) && src_width < 32768) { + ScaleARGBFilterCols = ScaleARGBFilterCols_AVX2; } #endif #if defined(HAS_SCALEARGBFILTERCOLS_NEON) @@ -353,73 +457,87 @@ static void ScaleARGBBilinearDown(int src_width, } } #endif -#if defined(HAS_SCALEARGBFILTERCOLS_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ScaleARGBFilterCols = ScaleARGBFilterCols_Any_MSA; - if (IS_ALIGNED(dst_width, 8)) { - ScaleARGBFilterCols = ScaleARGBFilterCols_MSA; +#if defined(HAS_SCALEARGBFILTERCOLS_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ScaleARGBFilterCols = ScaleARGBFilterCols_Any_LSX; + if (IS_ALIGNED(dst_width, 4)) { + ScaleARGBFilterCols = ScaleARGBFilterCols_LSX; } } #endif +#if defined(HAS_SCALEARGBFILTERCOLS_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleARGBFilterCols = ScaleARGBFilterCols_RVV; + } +#endif +#if defined(HAS_SCALEARGBFILTERCOLS_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD) && src_width < 32768) { + ScaleARGBFilterCols = ScaleARGBFilterCols_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 4)) { + ScaleARGBFilterCols = ScaleARGBFilterCols_WASMSIMD; + } + } +#endif + // TODO(fbarchard): Consider not allocating row buffer for kFilterLinear. // Allocate a row of ARGB. { - align_buffer_64(row, clip_src_width * 4); + // clip_src_width is already in bytes (4 per ARGB pixel). + align_buffer_64(row, clip_src_width); + if (!row) + return 1; - const int max_y = (src_height - 1) << 16; - if (y > max_y) { - y = max_y; - } + const int64_t max_y = (int64_t)(src_height - 1) << 16; + int64_t y64 = y; for (j = 0; j < dst_height; ++j) { - int yi = y >> 16; + if (y64 > max_y) { + y64 = max_y; + } + int yi = (int)(y64 >> 16); const uint8_t* src = src_argb + yi * src_stride; if (filtering == kFilterLinear) { ScaleARGBFilterCols(dst_argb, src, dst_width, x, dx); } else { - int yf = (y >> 8) & 255; + int yf = (int)((y64 >> 8) & 255); InterpolateRow(row, src, src_stride, clip_src_width, yf); ScaleARGBFilterCols(dst_argb, row, dst_width, x, dx); } dst_argb += dst_stride; - y += dy; - if (y > max_y) { - y = max_y; - } + y64 += dy; } free_aligned_buffer_64(row); } + return 0; } // Scale ARGB up with bilinear interpolation. -static void ScaleARGBBilinearUp(int src_width, - int src_height, - int dst_width, - int dst_height, - int src_stride, - int dst_stride, - const uint8_t* src_argb, - uint8_t* dst_argb, - int x, - int dx, - int y, - int dy, - enum FilterMode filtering) { +static int ScaleARGBBilinearUp(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_argb, + uint8_t* dst_argb, + int x, + int dx, + int y, + int dy, + enum FilterMode filtering) { + assert(src_width > 0); + assert(src_height > 0); + assert(dst_width > 0); + assert(dst_height > 0); + assert(dy <= 65536); + int j; - void (*InterpolateRow)(uint8_t * dst_argb, const uint8_t* src_argb, + void (*InterpolateRow)(uint8_t* dst_argb, const uint8_t* src_argb, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_C; - void (*ScaleARGBFilterCols)(uint8_t * dst_argb, const uint8_t* src_argb, + void (*ScaleARGBFilterCols)(uint8_t* dst_argb, const uint8_t* src_argb, int dst_width, int x, int dx) = filtering ? ScaleARGBFilterCols_C : ScaleARGBCols_C; - const int max_y = (src_height - 1) << 16; -#if defined(HAS_INTERPOLATEROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_SSSE3; - if (IS_ALIGNED(dst_width, 4)) { - InterpolateRow = InterpolateRow_SSSE3; - } - } -#endif + const int64_t max_y = (int64_t)(src_height - 1) << 16; #if defined(HAS_INTERPOLATEROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { InterpolateRow = InterpolateRow_Any_AVX2; @@ -428,6 +546,11 @@ static void ScaleARGBBilinearUp(int src_width, } } #endif +#if defined(HAS_INTERPOLATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_AVX512BW; + } +#endif #if defined(HAS_INTERPOLATEROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { InterpolateRow = InterpolateRow_Any_NEON; @@ -436,19 +559,47 @@ static void ScaleARGBBilinearUp(int src_width, } } #endif -#if defined(HAS_INTERPOLATEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - InterpolateRow = InterpolateRow_Any_MSA; - if (IS_ALIGNED(dst_width, 8)) { - InterpolateRow = InterpolateRow_MSA; +#if defined(HAS_INTERPOLATEROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + InterpolateRow = InterpolateRow_SVE2; + } +#endif +#if defined(HAS_INTERPOLATEROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + InterpolateRow = InterpolateRow_Any_LSX; + if (IS_ALIGNED(dst_width, 16)) { + InterpolateRow = InterpolateRow_LSX; } } #endif -#if defined(HAS_INTERPOLATEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - InterpolateRow = InterpolateRow_Any_MMI; - if (IS_ALIGNED(dst_width, 2)) { - InterpolateRow = InterpolateRow_MMI; +#if defined(HAS_INTERPOLATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + InterpolateRow = InterpolateRow_Any_LASX; + if (IS_ALIGNED(dst_width, 32)) { + InterpolateRow = InterpolateRow_LASX; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + InterpolateRow = InterpolateRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_HVX; + } +#endif +#if defined(HAS_INTERPOLATEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 4)) { + InterpolateRow = InterpolateRow_WASMSIMD; } } #endif @@ -456,9 +607,9 @@ static void ScaleARGBBilinearUp(int src_width, ScaleARGBFilterCols = filtering ? ScaleARGBFilterCols64_C : ScaleARGBCols64_C; } -#if defined(HAS_SCALEARGBFILTERCOLS_SSSE3) - if (filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) { - ScaleARGBFilterCols = ScaleARGBFilterCols_SSSE3; +#if defined(HAS_SCALEARGBFILTERCOLS_AVX2) + if (filtering && TestCpuFlag(kCpuHasAVX2) && src_width < 32768) { + ScaleARGBFilterCols = ScaleARGBFilterCols_AVX2; } #endif #if defined(HAS_SCALEARGBFILTERCOLS_NEON) @@ -469,17 +620,22 @@ static void ScaleARGBBilinearUp(int src_width, } } #endif -#if defined(HAS_SCALEARGBFILTERCOLS_MSA) - if (filtering && TestCpuFlag(kCpuHasMSA)) { - ScaleARGBFilterCols = ScaleARGBFilterCols_Any_MSA; - if (IS_ALIGNED(dst_width, 8)) { - ScaleARGBFilterCols = ScaleARGBFilterCols_MSA; +#if defined(HAS_SCALEARGBFILTERCOLS_LSX) + if (filtering && TestCpuFlag(kCpuHasLSX)) { + ScaleARGBFilterCols = ScaleARGBFilterCols_Any_LSX; + if (IS_ALIGNED(dst_width, 4)) { + ScaleARGBFilterCols = ScaleARGBFilterCols_LSX; } } #endif -#if defined(HAS_SCALEARGBCOLS_SSE2) - if (!filtering && TestCpuFlag(kCpuHasSSE2) && src_width < 32768) { - ScaleARGBFilterCols = ScaleARGBCols_SSE2; +#if defined(HAS_SCALEARGBFILTERCOLS_RVV) + if (filtering && TestCpuFlag(kCpuHasRVV)) { + ScaleARGBFilterCols = ScaleARGBFilterCols_RVV; + } +#endif +#if defined(HAS_SCALEARGBCOLS_AVX2) + if (!filtering && TestCpuFlag(kCpuHasAVX2) && src_width < 32768) { + ScaleARGBFilterCols = ScaleARGBCols_AVX2; } #endif #if defined(HAS_SCALEARGBCOLS_NEON) @@ -490,50 +646,61 @@ static void ScaleARGBBilinearUp(int src_width, } } #endif -#if defined(HAS_SCALEARGBCOLS_MSA) - if (!filtering && TestCpuFlag(kCpuHasMSA)) { - ScaleARGBFilterCols = ScaleARGBCols_Any_MSA; +#if defined(HAS_SCALEARGBCOLS_LSX) + if (!filtering && TestCpuFlag(kCpuHasLSX)) { + ScaleARGBFilterCols = ScaleARGBCols_Any_LSX; if (IS_ALIGNED(dst_width, 4)) { - ScaleARGBFilterCols = ScaleARGBCols_MSA; + ScaleARGBFilterCols = ScaleARGBCols_LSX; } } #endif -#if defined(HAS_SCALEARGBCOLS_MMI) - if (!filtering && TestCpuFlag(kCpuHasMMI)) { - ScaleARGBFilterCols = ScaleARGBCols_Any_MMI; - if (IS_ALIGNED(dst_width, 1)) { - ScaleARGBFilterCols = ScaleARGBCols_MMI; +#if defined(HAS_SCALEARGBFILTERCOLS_WASMSIMD) + if (filtering && TestCpuFlag(kCpuHasWASMSIMD) && src_width < 32768) { + ScaleARGBFilterCols = ScaleARGBFilterCols_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 4)) { + ScaleARGBFilterCols = ScaleARGBFilterCols_WASMSIMD; + } + } +#endif +#if defined(HAS_SCALEARGBCOLS_WASMSIMD) + if (!filtering && TestCpuFlag(kCpuHasWASMSIMD) && src_width < 32768) { + ScaleARGBFilterCols = ScaleARGBCols_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 4)) { + ScaleARGBFilterCols = ScaleARGBCols_WASMSIMD; } } #endif if (!filtering && src_width * 2 == dst_width && x < 0x8000) { ScaleARGBFilterCols = ScaleARGBColsUp2_C; -#if defined(HAS_SCALEARGBCOLSUP2_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) { - ScaleARGBFilterCols = ScaleARGBColsUp2_SSE2; +#if defined(HAS_SCALEARGBCOLSUP2_AVX2) + if (TestCpuFlag(kCpuHasAVX2) && IS_ALIGNED(dst_width, 8)) { + ScaleARGBFilterCols = ScaleARGBColsUp2_AVX2; } #endif -#if defined(HAS_SCALEARGBCOLSUP2_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 4)) { - ScaleARGBFilterCols = ScaleARGBColsUp2_MMI; +#if defined(HAS_SCALEARGBCOLSUP2_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD) && IS_ALIGNED(dst_width, 8)) { + ScaleARGBFilterCols = ScaleARGBColsUp2_WASMSIMD; } #endif } - if (y > max_y) { - y = max_y; + int64_t y64 = y; + if (y64 > max_y) { + y64 = max_y; } { - int yi = y >> 16; + int yi = (int)(y64 >> 16); const uint8_t* src = src_argb + yi * src_stride; // Allocate 2 rows of ARGB. - const int kRowSize = (dst_width * 4 + 31) & ~31; - align_buffer_64(row, kRowSize * 2); + const int row_size = (dst_width * 4 + 31) & ~31; + align_buffer_64(row, row_size * 2); + if (!row) + return 1; uint8_t* rowptr = row; - int rowstride = kRowSize; + ptrdiff_t rowstride = row_size; int lasty = yi; ScaleARGBFilterCols(rowptr, src, dst_width, x, dx); @@ -541,279 +708,48 @@ static void ScaleARGBBilinearUp(int src_width, src += src_stride; } ScaleARGBFilterCols(rowptr + rowstride, src, dst_width, x, dx); - src += src_stride; + if (src_height > 2) { + src += src_stride; + } + // 2-row rolling buffer: + // rowptr and (rowptr + rowstride) hold the scaled rows for yi and yi + 1. + // Because dy <= 65536 (dy <= 1.0 in 16.16), yi advances in unit steps. + // When yi != lasty: + // 1. Scale the next source row into the older buffer (rowptr). + // 2. Swap buffer pointers (rowptr += rowstride; rowstride = -rowstride;) + // so rowptr points to yi and (rowptr + rowstride) points to yi + 1. + // 3. Advance src by 1 row if row yi + 2 exists ((y64 + 65536) < max_y), + // otherwise clamp src at (src_height - 1) to avoid reading out of + // bounds. for (j = 0; j < dst_height; ++j) { - yi = y >> 16; + if (y64 > max_y) { + y64 = max_y; + } + yi = (int)(y64 >> 16); if (yi != lasty) { - if (y > max_y) { - y = max_y; - yi = y >> 16; - src = src_argb + yi * src_stride; - } - if (yi != lasty) { - ScaleARGBFilterCols(rowptr, src, dst_width, x, dx); - rowptr += rowstride; - rowstride = -rowstride; - lasty = yi; + ScaleARGBFilterCols(rowptr, src, dst_width, x, dx); + rowptr += rowstride; + rowstride = -rowstride; + lasty = yi; + if ((y64 + 65536) < max_y) { src += src_stride; } } if (filtering == kFilterLinear) { InterpolateRow(dst_argb, rowptr, 0, dst_width * 4, 0); } else { - int yf = (y >> 8) & 255; + int yf = (int)((y64 >> 8) & 255); InterpolateRow(dst_argb, rowptr, rowstride, dst_width * 4, yf); } dst_argb += dst_stride; - y += dy; + y64 += dy; } free_aligned_buffer_64(row); } + return 0; } -#ifdef YUVSCALEUP -// Scale YUV to ARGB up with bilinear interpolation. -static void ScaleYUVToARGBBilinearUp(int src_width, - int src_height, - int dst_width, - int dst_height, - int src_stride_y, - int src_stride_u, - int src_stride_v, - int dst_stride_argb, - const uint8_t* src_y, - const uint8_t* src_u, - const uint8_t* src_v, - uint8_t* dst_argb, - int x, - int dx, - int y, - int dy, - enum FilterMode filtering) { - int j; - void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf, - const uint8_t* v_buf, uint8_t* rgb_buf, int width) = - I422ToARGBRow_C; -#if defined(HAS_I422TOARGBROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - I422ToARGBRow = I422ToARGBRow_Any_SSSE3; - if (IS_ALIGNED(src_width, 8)) { - I422ToARGBRow = I422ToARGBRow_SSSE3; - } - } -#endif -#if defined(HAS_I422TOARGBROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - I422ToARGBRow = I422ToARGBRow_Any_AVX2; - if (IS_ALIGNED(src_width, 16)) { - I422ToARGBRow = I422ToARGBRow_AVX2; - } - } -#endif -#if defined(HAS_I422TOARGBROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - I422ToARGBRow = I422ToARGBRow_Any_NEON; - if (IS_ALIGNED(src_width, 8)) { - I422ToARGBRow = I422ToARGBRow_NEON; - } - } -#endif -#if defined(HAS_I422TOARGBROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - I422ToARGBRow = I422ToARGBRow_Any_MSA; - if (IS_ALIGNED(src_width, 8)) { - I422ToARGBRow = I422ToARGBRow_MSA; - } - } -#endif - - void (*InterpolateRow)(uint8_t * dst_argb, const uint8_t* src_argb, - ptrdiff_t src_stride, int dst_width, - int source_y_fraction) = InterpolateRow_C; -#if defined(HAS_INTERPOLATEROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_SSSE3; - if (IS_ALIGNED(dst_width, 4)) { - InterpolateRow = InterpolateRow_SSSE3; - } - } -#endif -#if defined(HAS_INTERPOLATEROW_AVX2) - if (TestCpuFlag(kCpuHasAVX2)) { - InterpolateRow = InterpolateRow_Any_AVX2; - if (IS_ALIGNED(dst_width, 8)) { - InterpolateRow = InterpolateRow_AVX2; - } - } -#endif -#if defined(HAS_INTERPOLATEROW_NEON) - if (TestCpuFlag(kCpuHasNEON)) { - InterpolateRow = InterpolateRow_Any_NEON; - if (IS_ALIGNED(dst_width, 4)) { - InterpolateRow = InterpolateRow_NEON; - } - } -#endif -#if defined(HAS_INTERPOLATEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - InterpolateRow = InterpolateRow_Any_MSA; - if (IS_ALIGNED(dst_width, 8)) { - InterpolateRow = InterpolateRow_MSA; - } - } -#endif - - void (*ScaleARGBFilterCols)(uint8_t * dst_argb, const uint8_t* src_argb, - int dst_width, int x, int dx) = - filtering ? ScaleARGBFilterCols_C : ScaleARGBCols_C; - if (src_width >= 32768) { - ScaleARGBFilterCols = - filtering ? ScaleARGBFilterCols64_C : ScaleARGBCols64_C; - } -#if defined(HAS_SCALEARGBFILTERCOLS_SSSE3) - if (filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) { - ScaleARGBFilterCols = ScaleARGBFilterCols_SSSE3; - } -#endif -#if defined(HAS_SCALEARGBFILTERCOLS_NEON) - if (filtering && TestCpuFlag(kCpuHasNEON)) { - ScaleARGBFilterCols = ScaleARGBFilterCols_Any_NEON; - if (IS_ALIGNED(dst_width, 4)) { - ScaleARGBFilterCols = ScaleARGBFilterCols_NEON; - } - } -#endif -#if defined(HAS_SCALEARGBFILTERCOLS_MSA) - if (filtering && TestCpuFlag(kCpuHasMSA)) { - ScaleARGBFilterCols = ScaleARGBFilterCols_Any_MSA; - if (IS_ALIGNED(dst_width, 8)) { - ScaleARGBFilterCols = ScaleARGBFilterCols_MSA; - } - } -#endif -#if defined(HAS_SCALEARGBCOLS_SSE2) - if (!filtering && TestCpuFlag(kCpuHasSSE2) && src_width < 32768) { - ScaleARGBFilterCols = ScaleARGBCols_SSE2; - } -#endif -#if defined(HAS_SCALEARGBCOLS_NEON) - if (!filtering && TestCpuFlag(kCpuHasNEON)) { - ScaleARGBFilterCols = ScaleARGBCols_Any_NEON; - if (IS_ALIGNED(dst_width, 8)) { - ScaleARGBFilterCols = ScaleARGBCols_NEON; - } - } -#endif -#if defined(HAS_SCALEARGBCOLS_MSA) - if (!filtering && TestCpuFlag(kCpuHasMSA)) { - ScaleARGBFilterCols = ScaleARGBCols_Any_MSA; - if (IS_ALIGNED(dst_width, 4)) { - ScaleARGBFilterCols = ScaleARGBCols_MSA; - } - } -#endif -#if defined(HAS_SCALEARGBCOLS_MMI) - if (!filtering && TestCpuFlag(kCpuHasMMI)) { - ScaleARGBFilterCols = ScaleARGBCols_Any_MMI; - if (IS_ALIGNED(dst_width, 1)) { - ScaleARGBFilterCols = ScaleARGBCols_MMI; - } - } -#endif - if (!filtering && src_width * 2 == dst_width && x < 0x8000) { - ScaleARGBFilterCols = ScaleARGBColsUp2_C; -#if defined(HAS_SCALEARGBCOLSUP2_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) { - ScaleARGBFilterCols = ScaleARGBColsUp2_SSE2; - } -#endif -#if defined(HAS_SCALEARGBCOLSUP2_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 4)) { - ScaleARGBFilterCols = ScaleARGBColsUp2_MMI; - } -#endif - } - - const int max_y = (src_height - 1) << 16; - if (y > max_y) { - y = max_y; - } - const int kYShift = 1; // Shift Y by 1 to convert Y plane to UV coordinate. - int yi = y >> 16; - int uv_yi = yi >> kYShift; - const uint8_t* src_row_y = src_y + yi * src_stride_y; - const uint8_t* src_row_u = src_u + uv_yi * src_stride_u; - const uint8_t* src_row_v = src_v + uv_yi * src_stride_v; - - // Allocate 2 rows of ARGB. - const int kRowSize = (dst_width * 4 + 31) & ~31; - align_buffer_64(row, kRowSize * 2); - - // Allocate 1 row of ARGB for source conversion. - align_buffer_64(argb_row, src_width * 4); - - uint8_t* rowptr = row; - int rowstride = kRowSize; - int lasty = yi; - - // TODO(fbarchard): Convert first 2 rows of YUV to ARGB. - ScaleARGBFilterCols(rowptr, src_row_y, dst_width, x, dx); - if (src_height > 1) { - src_row_y += src_stride_y; - if (yi & 1) { - src_row_u += src_stride_u; - src_row_v += src_stride_v; - } - } - ScaleARGBFilterCols(rowptr + rowstride, src_row_y, dst_width, x, dx); - if (src_height > 2) { - src_row_y += src_stride_y; - if (!(yi & 1)) { - src_row_u += src_stride_u; - src_row_v += src_stride_v; - } - } - - for (j = 0; j < dst_height; ++j) { - yi = y >> 16; - if (yi != lasty) { - if (y > max_y) { - y = max_y; - yi = y >> 16; - uv_yi = yi >> kYShift; - src_row_y = src_y + yi * src_stride_y; - src_row_u = src_u + uv_yi * src_stride_u; - src_row_v = src_v + uv_yi * src_stride_v; - } - if (yi != lasty) { - // TODO(fbarchard): Convert the clipped region of row. - I422ToARGBRow(src_row_y, src_row_u, src_row_v, argb_row, src_width); - ScaleARGBFilterCols(rowptr, argb_row, dst_width, x, dx); - rowptr += rowstride; - rowstride = -rowstride; - lasty = yi; - src_row_y += src_stride_y; - if (yi & 1) { - src_row_u += src_stride_u; - src_row_v += src_stride_v; - } - } - } - if (filtering == kFilterLinear) { - InterpolateRow(dst_argb, rowptr, 0, dst_width * 4, 0); - } else { - int yf = (y >> 8) & 255; - InterpolateRow(dst_argb, rowptr, rowstride, dst_width * 4, yf); - } - dst_argb += dst_stride_argb; - y += dy; - } - free_aligned_buffer_64(row); - free_aligned_buffer_64(row_argb); -} -#endif - // Scale ARGB to/from any dimensions, without interpolation. // Fixed point math is used for performance: The upper 16 bits // of x and dx is the integer part of the source position and @@ -823,8 +759,8 @@ static void ScaleARGBSimple(int src_width, int src_height, int dst_width, int dst_height, - int src_stride, - int dst_stride, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, const uint8_t* src_argb, uint8_t* dst_argb, int x, @@ -832,13 +768,13 @@ static void ScaleARGBSimple(int src_width, int y, int dy) { int j; - void (*ScaleARGBCols)(uint8_t * dst_argb, const uint8_t* src_argb, + void (*ScaleARGBCols)(uint8_t* dst_argb, const uint8_t* src_argb, int dst_width, int x, int dx) = (src_width >= 32768) ? ScaleARGBCols64_C : ScaleARGBCols_C; - (void)src_height; -#if defined(HAS_SCALEARGBCOLS_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && src_width < 32768) { - ScaleARGBCols = ScaleARGBCols_SSE2; + const int64_t max_y = (int64_t)(src_height - 1) << 16; +#if defined(HAS_SCALEARGBCOLS_AVX2) + if (TestCpuFlag(kCpuHasAVX2) && src_width < 32768) { + ScaleARGBCols = ScaleARGBCols_AVX2; } #endif #if defined(HAS_SCALEARGBCOLS_NEON) @@ -849,60 +785,64 @@ static void ScaleARGBSimple(int src_width, } } #endif -#if defined(HAS_SCALEARGBCOLS_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - ScaleARGBCols = ScaleARGBCols_Any_MSA; +#if defined(HAS_SCALEARGBCOLS_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ScaleARGBCols = ScaleARGBCols_Any_LSX; if (IS_ALIGNED(dst_width, 4)) { - ScaleARGBCols = ScaleARGBCols_MSA; + ScaleARGBCols = ScaleARGBCols_LSX; } } #endif -#if defined(HAS_SCALEARGBCOLS_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - ScaleARGBCols = ScaleARGBCols_Any_MMI; - if (IS_ALIGNED(dst_width, 1)) { - ScaleARGBCols = ScaleARGBCols_MMI; +#if defined(HAS_SCALEARGBCOLS_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD) && src_width < 32768) { + ScaleARGBCols = ScaleARGBCols_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 4)) { + ScaleARGBCols = ScaleARGBCols_WASMSIMD; } } #endif if (src_width * 2 == dst_width && x < 0x8000) { ScaleARGBCols = ScaleARGBColsUp2_C; -#if defined(HAS_SCALEARGBCOLSUP2_SSE2) - if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) { - ScaleARGBCols = ScaleARGBColsUp2_SSE2; +#if defined(HAS_SCALEARGBCOLSUP2_AVX2) + if (TestCpuFlag(kCpuHasAVX2) && IS_ALIGNED(dst_width, 8)) { + ScaleARGBCols = ScaleARGBColsUp2_AVX2; } #endif -#if defined(HAS_SCALEARGBCOLSUP2_MMI) - if (TestCpuFlag(kCpuHasMMI) && IS_ALIGNED(dst_width, 4)) { - ScaleARGBCols = ScaleARGBColsUp2_MMI; +#if defined(HAS_SCALEARGBCOLSUP2_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD) && IS_ALIGNED(dst_width, 8)) { + ScaleARGBCols = ScaleARGBColsUp2_WASMSIMD; } #endif } + int64_t y64 = y; for (j = 0; j < dst_height; ++j) { - ScaleARGBCols(dst_argb, src_argb + (y >> 16) * src_stride, dst_width, x, + if (y64 > max_y) { + y64 = max_y; + } + ScaleARGBCols(dst_argb, src_argb + (y64 >> 16) * src_stride, dst_width, x, dx); dst_argb += dst_stride; - y += dy; + y64 += dy; } } // ScaleARGB a ARGB. // This function in turn calls a scaling function // suitable for handling the desired resolutions. -static void ScaleARGB(const uint8_t* src, - int src_stride, - int src_width, - int src_height, - uint8_t* dst, - int dst_stride, - int dst_width, - int dst_height, - int clip_x, - int clip_y, - int clip_width, - int clip_height, - enum FilterMode filtering) { +static int ScaleARGB(const uint8_t* src, + int src_stride, + int src_width, + int src_height, + uint8_t* dst, + int dst_stride, + int dst_width, + int dst_height, + int clip_x, + int clip_y, + int clip_width, + int clip_height, + enum FilterMode filtering) { // Initial source x/y coordinate and step values as 16.16 fixed point. int x = 0; int y = 0; @@ -916,7 +856,7 @@ static void ScaleARGB(const uint8_t* src, // Negative src_height means invert the image. if (src_height < 0) { src_height = -src_height; - src = src + (src_height - 1) * src_stride; + src = src + (src_height - 1) * (ptrdiff_t)src_stride; src_stride = -src_stride; } ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y, @@ -931,8 +871,8 @@ static void ScaleARGB(const uint8_t* src, if (clip_y) { int64_t clipf = (int64_t)(clip_y)*dy; y += (clipf & 0xffff); - src += (clipf >> 16) * src_stride; - dst += clip_y * dst_stride; + src += (clipf >> 16) * (ptrdiff_t)src_stride; + dst += clip_y * (ptrdiff_t)dst_stride; } // Special case for integer step values. @@ -942,56 +882,55 @@ static void ScaleARGB(const uint8_t* src, } else { // Optimized even scale down. ie 2, 4, 6, 8, 10x. if (!(dx & 0x10000) && !(dy & 0x10000)) { - if (dx == 0x20000) { + if (dx == 0x20000 && dy == 0x20000) { // Optimized 1/2 downsample. ScaleARGBDown2(src_width, src_height, clip_width, clip_height, src_stride, dst_stride, src, dst, x, dx, y, dy, filtering); - return; + return 0; } - if (dx == 0x40000 && filtering == kFilterBox) { + if (dx == 0x40000 && dy == 0x40000 && filtering == kFilterBox) { // Optimized 1/4 box downsample. - ScaleARGBDown4Box(src_width, src_height, clip_width, clip_height, - src_stride, dst_stride, src, dst, x, dx, y, dy); - return; + return ScaleARGBDown4Box(src_width, src_height, clip_width, + clip_height, src_stride, dst_stride, src, + dst, x, dx, y, dy); } ScaleARGBDownEven(src_width, src_height, clip_width, clip_height, src_stride, dst_stride, src, dst, x, dx, y, dy, filtering); - return; + return 0; } // Optimized odd scale down. ie 3, 5, 7, 9x. if ((dx & 0x10000) && (dy & 0x10000)) { filtering = kFilterNone; if (dx == 0x10000 && dy == 0x10000) { // Straight copy. - ARGBCopy(src + (y >> 16) * src_stride + (x >> 16) * 4, src_stride, - dst, dst_stride, clip_width, clip_height); - return; + ARGBCopy(src + (y >> 16) * (ptrdiff_t)src_stride + (x >> 16) * 4, + src_stride, dst, dst_stride, clip_width, clip_height); + return 0; } } } } if (dx == 0x10000 && (x & 0xffff) == 0) { - // Arbitrary scale vertically, but unscaled vertically. + // Arbitrary scale vertically, but unscaled horizontally. ScalePlaneVertical(src_height, clip_width, clip_height, src_stride, - dst_stride, src, dst, x, y, dy, 4, filtering); - return; + dst_stride, src, dst, x, y, dy, /*bpp=*/4, filtering); + return 0; } if (filtering && dy < 65536) { - ScaleARGBBilinearUp(src_width, src_height, clip_width, clip_height, - src_stride, dst_stride, src, dst, x, dx, y, dy, - filtering); - return; + return ScaleARGBBilinearUp(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, dy, + filtering); } if (filtering) { - ScaleARGBBilinearDown(src_width, src_height, clip_width, clip_height, - src_stride, dst_stride, src, dst, x, dx, y, dy, - filtering); - return; + return ScaleARGBBilinearDown(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, dy, + filtering); } ScaleARGBSimple(src_width, src_height, clip_width, clip_height, src_stride, dst_stride, src, dst, x, dx, y, dy); + return 0; } LIBYUV_API @@ -1008,17 +947,17 @@ int ARGBScaleClip(const uint8_t* src_argb, int clip_width, int clip_height, enum FilterMode filtering) { - if (!src_argb || src_width == 0 || src_height == 0 || !dst_argb || - dst_width <= 0 || dst_height <= 0 || clip_x < 0 || clip_y < 0 || - clip_width > 32768 || clip_height > 32768 || + if (!src_argb || src_width == 0 || src_width > 32768 || src_width < -32768 || + src_height == 0 || src_height > 32768 || src_height < -32768 || + !dst_argb || dst_width <= 0 || dst_height <= 0 || clip_x < 0 || + clip_y < 0 || clip_width > 32768 || clip_height > 32768 || (clip_x + clip_width) > dst_width || (clip_y + clip_height) > dst_height) { return -1; } - ScaleARGB(src_argb, src_stride_argb, src_width, src_height, dst_argb, - dst_stride_argb, dst_width, dst_height, clip_x, clip_y, clip_width, - clip_height, filtering); - return 0; + return ScaleARGB(src_argb, src_stride_argb, src_width, src_height, dst_argb, + dst_stride_argb, dst_width, dst_height, clip_x, clip_y, + clip_width, clip_height, filtering); } // Scale an ARGB image. @@ -1032,14 +971,14 @@ int ARGBScale(const uint8_t* src_argb, int dst_width, int dst_height, enum FilterMode filtering) { - if (!src_argb || src_width == 0 || src_height == 0 || src_width > 32768 || - src_height > 32768 || !dst_argb || dst_width <= 0 || dst_height <= 0) { + if (!src_argb || src_width == 0 || src_width > 32768 || src_width < -32768 || + src_height == 0 || src_height > 32768 || src_height < -32768 || + !dst_argb || dst_width <= 0 || dst_height <= 0) { return -1; } - ScaleARGB(src_argb, src_stride_argb, src_width, src_height, dst_argb, - dst_stride_argb, dst_width, dst_height, 0, 0, dst_width, dst_height, - filtering); - return 0; + return ScaleARGB(src_argb, src_stride_argb, src_width, src_height, dst_argb, + dst_stride_argb, dst_width, dst_height, 0, 0, dst_width, + dst_height, filtering); } // Scale with YUV conversion to ARGB and clipping. @@ -1063,16 +1002,32 @@ int YUVToARGBScaleClip(const uint8_t* src_y, int clip_width, int clip_height, enum FilterMode filtering) { - uint8_t* argb_buffer = (uint8_t*)malloc(src_width * src_height * 4); int r; (void)src_fourcc; // TODO(fbarchard): implement and/or assert. (void)dst_fourcc; + if (!src_y || !src_u || !src_v || !dst_argb || src_width <= 0 || + src_width > INT_MAX / 4 || src_height == 0 || src_height == INT_MIN || + dst_width <= 0 || dst_height <= 0 || clip_width <= 0 || + clip_height <= 0) { + return -1; + } + const int abs_src_height = (src_height < 0) ? -src_height : src_height; + const uint64_t argb_buffer_size = (uint64_t)src_width * abs_src_height * 4; +#if UINT64_MAX > SIZE_MAX + if (argb_buffer_size > SIZE_MAX) { + return -1; // Invalid size. + } +#endif + uint8_t* argb_buffer = (uint8_t*)malloc((size_t)argb_buffer_size); + if (!argb_buffer) { + return 1; // Out of memory runtime error. + } I420ToARGB(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, argb_buffer, src_width * 4, src_width, src_height); - r = ARGBScaleClip(argb_buffer, src_width * 4, src_width, src_height, dst_argb, - dst_stride_argb, dst_width, dst_height, clip_x, clip_y, - clip_width, clip_height, filtering); + r = ARGBScaleClip(argb_buffer, src_width * 4, src_width, abs_src_height, + dst_argb, dst_stride_argb, dst_width, dst_height, clip_x, + clip_y, clip_width, clip_height, filtering); free(argb_buffer); return r; } diff --git a/libs/libyuv/source/scale_common.cc b/libs/libyuv/source/scale_common.cc index 6369027175..a07a2183eb 100644 --- a/libs/libyuv/source/scale_common.cc +++ b/libs/libyuv/source/scale_common.cc @@ -23,6 +23,12 @@ namespace libyuv { extern "C" { #endif +#ifdef __cplusplus +#define STATIC_CAST(type, expr) static_cast(expr) +#else +#define STATIC_CAST(type, expr) (type)(expr) +#endif + static __inline int Abs(int v) { return v >= 0 ? v : -v; } @@ -198,36 +204,35 @@ void ScaleRowDown4Box_C(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width) { - intptr_t stride = src_stride; int x; for (x = 0; x < dst_width - 1; x += 2) { dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] + - src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] + - src_ptr[stride + 3] + src_ptr[stride * 2 + 0] + - src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] + - src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] + - src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] + - src_ptr[stride * 3 + 3] + 8) >> + src_ptr[src_stride + 0] + src_ptr[src_stride + 1] + + src_ptr[src_stride + 2] + src_ptr[src_stride + 3] + + src_ptr[src_stride * 2 + 0] + src_ptr[src_stride * 2 + 1] + + src_ptr[src_stride * 2 + 2] + src_ptr[src_stride * 2 + 3] + + src_ptr[src_stride * 3 + 0] + src_ptr[src_stride * 3 + 1] + + src_ptr[src_stride * 3 + 2] + src_ptr[src_stride * 3 + 3] + 8) >> 4; dst[1] = (src_ptr[4] + src_ptr[5] + src_ptr[6] + src_ptr[7] + - src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride + 6] + - src_ptr[stride + 7] + src_ptr[stride * 2 + 4] + - src_ptr[stride * 2 + 5] + src_ptr[stride * 2 + 6] + - src_ptr[stride * 2 + 7] + src_ptr[stride * 3 + 4] + - src_ptr[stride * 3 + 5] + src_ptr[stride * 3 + 6] + - src_ptr[stride * 3 + 7] + 8) >> + src_ptr[src_stride + 4] + src_ptr[src_stride + 5] + + src_ptr[src_stride + 6] + src_ptr[src_stride + 7] + + src_ptr[src_stride * 2 + 4] + src_ptr[src_stride * 2 + 5] + + src_ptr[src_stride * 2 + 6] + src_ptr[src_stride * 2 + 7] + + src_ptr[src_stride * 3 + 4] + src_ptr[src_stride * 3 + 5] + + src_ptr[src_stride * 3 + 6] + src_ptr[src_stride * 3 + 7] + 8) >> 4; dst += 2; src_ptr += 8; } if (dst_width & 1) { dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] + - src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] + - src_ptr[stride + 3] + src_ptr[stride * 2 + 0] + - src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] + - src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] + - src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] + - src_ptr[stride * 3 + 3] + 8) >> + src_ptr[src_stride + 0] + src_ptr[src_stride + 1] + + src_ptr[src_stride + 2] + src_ptr[src_stride + 3] + + src_ptr[src_stride * 2 + 0] + src_ptr[src_stride * 2 + 1] + + src_ptr[src_stride * 2 + 2] + src_ptr[src_stride * 2 + 3] + + src_ptr[src_stride * 3 + 0] + src_ptr[src_stride * 3 + 1] + + src_ptr[src_stride * 3 + 2] + src_ptr[src_stride * 3 + 3] + 8) >> 4; } } @@ -236,36 +241,35 @@ void ScaleRowDown4Box_16_C(const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst, int dst_width) { - intptr_t stride = src_stride; int x; for (x = 0; x < dst_width - 1; x += 2) { dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] + - src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] + - src_ptr[stride + 3] + src_ptr[stride * 2 + 0] + - src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] + - src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] + - src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] + - src_ptr[stride * 3 + 3] + 8) >> + src_ptr[src_stride + 0] + src_ptr[src_stride + 1] + + src_ptr[src_stride + 2] + src_ptr[src_stride + 3] + + src_ptr[src_stride * 2 + 0] + src_ptr[src_stride * 2 + 1] + + src_ptr[src_stride * 2 + 2] + src_ptr[src_stride * 2 + 3] + + src_ptr[src_stride * 3 + 0] + src_ptr[src_stride * 3 + 1] + + src_ptr[src_stride * 3 + 2] + src_ptr[src_stride * 3 + 3] + 8) >> 4; dst[1] = (src_ptr[4] + src_ptr[5] + src_ptr[6] + src_ptr[7] + - src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride + 6] + - src_ptr[stride + 7] + src_ptr[stride * 2 + 4] + - src_ptr[stride * 2 + 5] + src_ptr[stride * 2 + 6] + - src_ptr[stride * 2 + 7] + src_ptr[stride * 3 + 4] + - src_ptr[stride * 3 + 5] + src_ptr[stride * 3 + 6] + - src_ptr[stride * 3 + 7] + 8) >> + src_ptr[src_stride + 4] + src_ptr[src_stride + 5] + + src_ptr[src_stride + 6] + src_ptr[src_stride + 7] + + src_ptr[src_stride * 2 + 4] + src_ptr[src_stride * 2 + 5] + + src_ptr[src_stride * 2 + 6] + src_ptr[src_stride * 2 + 7] + + src_ptr[src_stride * 3 + 4] + src_ptr[src_stride * 3 + 5] + + src_ptr[src_stride * 3 + 6] + src_ptr[src_stride * 3 + 7] + 8) >> 4; dst += 2; src_ptr += 8; } if (dst_width & 1) { dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] + - src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] + - src_ptr[stride + 3] + src_ptr[stride * 2 + 0] + - src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] + - src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] + - src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] + - src_ptr[stride * 3 + 3] + 8) >> + src_ptr[src_stride + 0] + src_ptr[src_stride + 1] + + src_ptr[src_stride + 2] + src_ptr[src_stride + 3] + + src_ptr[src_stride * 2 + 0] + src_ptr[src_stride * 2 + 1] + + src_ptr[src_stride * 2 + 2] + src_ptr[src_stride * 2 + 3] + + src_ptr[src_stride * 3 + 0] + src_ptr[src_stride * 3 + 1] + + src_ptr[src_stride * 3 + 2] + src_ptr[src_stride * 3 + 3] + 8) >> 4; } } @@ -400,6 +404,95 @@ void ScaleRowDown34_1_Box_16_C(const uint16_t* src_ptr, } } +// Sample position: (O is src sample position, X is dst sample position) +// +// v dst_ptr at here v stop at here +// X O X X O X X O X X O X X O X +// ^ src_ptr at here +void ScaleRowUp2_Linear_C(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + int src_width = dst_width >> 1; + int x; + assert((dst_width % 2 == 0) && (dst_width >= 0)); + for (x = 0; x < src_width; ++x) { + dst_ptr[2 * x + 0] = (src_ptr[x + 0] * 3 + src_ptr[x + 1] * 1 + 2) >> 2; + dst_ptr[2 * x + 1] = (src_ptr[x + 0] * 1 + src_ptr[x + 1] * 3 + 2) >> 2; + } +} + +// Sample position: (O is src sample position, X is dst sample position) +// +// src_ptr at here +// X v X X X X X X X X X +// O O O O O +// X X X X X X X X X X +// ^ dst_ptr at here ^ stop at here +// X X X X X X X X X X +// O O O O O +// X X X X X X X X X X +void ScaleRowUp2_Bilinear_C(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint8_t* s = src_ptr; + const uint8_t* t = src_ptr + src_stride; + uint8_t* d = dst_ptr; + uint8_t* e = dst_ptr + dst_stride; + int src_width = dst_width >> 1; + int x; + assert((dst_width % 2 == 0) && (dst_width >= 0)); + for (x = 0; x < src_width; ++x) { + d[2 * x + 0] = + (s[x + 0] * 9 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 1 + 8) >> 4; + d[2 * x + 1] = + (s[x + 0] * 3 + s[x + 1] * 9 + t[x + 0] * 1 + t[x + 1] * 3 + 8) >> 4; + e[2 * x + 0] = + (s[x + 0] * 3 + s[x + 1] * 1 + t[x + 0] * 9 + t[x + 1] * 3 + 8) >> 4; + e[2 * x + 1] = + (s[x + 0] * 1 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 9 + 8) >> 4; + } +} + +// Only suitable for at most 14 bit range. +void ScaleRowUp2_Linear_16_C(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + int src_width = dst_width >> 1; + int x; + assert((dst_width % 2 == 0) && (dst_width >= 0)); + for (x = 0; x < src_width; ++x) { + dst_ptr[2 * x + 0] = (src_ptr[x + 0] * 3 + src_ptr[x + 1] * 1 + 2) >> 2; + dst_ptr[2 * x + 1] = (src_ptr[x + 0] * 1 + src_ptr[x + 1] * 3 + 2) >> 2; + } +} + +// Only suitable for at most 12bit range. +void ScaleRowUp2_Bilinear_16_C(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint16_t* s = src_ptr; + const uint16_t* t = src_ptr + src_stride; + uint16_t* d = dst_ptr; + uint16_t* e = dst_ptr + dst_stride; + int src_width = dst_width >> 1; + int x; + assert((dst_width % 2 == 0) && (dst_width >= 0)); + for (x = 0; x < src_width; ++x) { + d[2 * x + 0] = + (s[x + 0] * 9 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 1 + 8) >> 4; + d[2 * x + 1] = + (s[x + 0] * 3 + s[x + 1] * 9 + t[x + 0] * 1 + t[x + 1] * 3 + 8) >> 4; + e[2 * x + 0] = + (s[x + 0] * 3 + s[x + 1] * 1 + t[x + 0] * 9 + t[x + 1] * 3 + 8) >> 4; + e[2 * x + 1] = + (s[x + 0] * 1 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 9 + 8) >> 4; + } +} + // Scales a single row of pixels using point sampling. void ScaleCols_C(uint8_t* dst_ptr, const uint8_t* src_ptr, @@ -541,10 +634,10 @@ void ScaleFilterCols64_C(uint8_t* dst_ptr, #undef BLENDER // Same as 8 bit arm blender but return is cast to uint16_t -#define BLENDER(a, b, f) \ - (uint16_t)( \ - (int)(a) + \ - (int)((((int64_t)((f)) * ((int64_t)(b) - (int)(a))) + 0x8000) >> 16)) +#define BLENDER(a, b, f) \ + (uint16_t)((int)(a) + \ + (int)((((int64_t)((f)) * ((int64_t)(b) - (int)(a))) + 0x8000) >> \ + 16)) void ScaleFilterCols_16_C(uint16_t* dst_ptr, const uint16_t* src_ptr, @@ -639,27 +732,26 @@ void ScaleRowDown38_3_Box_C(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width) { - intptr_t stride = src_stride; int i; assert((dst_width % 3 == 0) && (dst_width > 0)); for (i = 0; i < dst_width; i += 3) { - dst_ptr[0] = - (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] + - src_ptr[stride + 1] + src_ptr[stride + 2] + src_ptr[stride * 2 + 0] + - src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2]) * - (65536 / 9) >> - 16; - dst_ptr[1] = - (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] + - src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride * 2 + 3] + - src_ptr[stride * 2 + 4] + src_ptr[stride * 2 + 5]) * - (65536 / 9) >> - 16; - dst_ptr[2] = - (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7] + - src_ptr[stride * 2 + 6] + src_ptr[stride * 2 + 7]) * - (65536 / 6) >> - 16; + dst_ptr[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + + src_ptr[src_stride + 0] + src_ptr[src_stride + 1] + + src_ptr[src_stride + 2] + src_ptr[src_stride * 2 + 0] + + src_ptr[src_stride * 2 + 1] + src_ptr[src_stride * 2 + 2]) * + (65536 / 9) >> + 16; + dst_ptr[1] = (src_ptr[3] + src_ptr[4] + src_ptr[5] + + src_ptr[src_stride + 3] + src_ptr[src_stride + 4] + + src_ptr[src_stride + 5] + src_ptr[src_stride * 2 + 3] + + src_ptr[src_stride * 2 + 4] + src_ptr[src_stride * 2 + 5]) * + (65536 / 9) >> + 16; + dst_ptr[2] = (src_ptr[6] + src_ptr[7] + src_ptr[src_stride + 6] + + src_ptr[src_stride + 7] + src_ptr[src_stride * 2 + 6] + + src_ptr[src_stride * 2 + 7]) * + (65536 / 6) >> + 16; src_ptr += 8; dst_ptr += 3; } @@ -669,27 +761,26 @@ void ScaleRowDown38_3_Box_16_C(const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, int dst_width) { - intptr_t stride = src_stride; int i; assert((dst_width % 3 == 0) && (dst_width > 0)); for (i = 0; i < dst_width; i += 3) { - dst_ptr[0] = - (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] + - src_ptr[stride + 1] + src_ptr[stride + 2] + src_ptr[stride * 2 + 0] + - src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2]) * - (65536 / 9) >> - 16; - dst_ptr[1] = - (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] + - src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride * 2 + 3] + - src_ptr[stride * 2 + 4] + src_ptr[stride * 2 + 5]) * - (65536 / 9) >> - 16; - dst_ptr[2] = - (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7] + - src_ptr[stride * 2 + 6] + src_ptr[stride * 2 + 7]) * - (65536 / 6) >> - 16; + dst_ptr[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + + src_ptr[src_stride + 0] + src_ptr[src_stride + 1] + + src_ptr[src_stride + 2] + src_ptr[src_stride * 2 + 0] + + src_ptr[src_stride * 2 + 1] + src_ptr[src_stride * 2 + 2]) * + (65536u / 9u) >> + 16; + dst_ptr[1] = (src_ptr[3] + src_ptr[4] + src_ptr[5] + + src_ptr[src_stride + 3] + src_ptr[src_stride + 4] + + src_ptr[src_stride + 5] + src_ptr[src_stride * 2 + 3] + + src_ptr[src_stride * 2 + 4] + src_ptr[src_stride * 2 + 5]) * + (65536u / 9u) >> + 16; + dst_ptr[2] = (src_ptr[6] + src_ptr[7] + src_ptr[src_stride + 6] + + src_ptr[src_stride + 7] + src_ptr[src_stride * 2 + 6] + + src_ptr[src_stride * 2 + 7]) * + (65536u / 6u) >> + 16; src_ptr += 8; dst_ptr += 3; } @@ -700,22 +791,23 @@ void ScaleRowDown38_2_Box_C(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width) { - intptr_t stride = src_stride; int i; assert((dst_width % 3 == 0) && (dst_width > 0)); for (i = 0; i < dst_width; i += 3) { - dst_ptr[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] + - src_ptr[stride + 1] + src_ptr[stride + 2]) * - (65536 / 6) >> - 16; - dst_ptr[1] = (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] + - src_ptr[stride + 4] + src_ptr[stride + 5]) * - (65536 / 6) >> - 16; - dst_ptr[2] = - (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7]) * - (65536 / 4) >> + dst_ptr[0] = + (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[src_stride + 0] + + src_ptr[src_stride + 1] + src_ptr[src_stride + 2]) * + (65536 / 6) >> 16; + dst_ptr[1] = + (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[src_stride + 3] + + src_ptr[src_stride + 4] + src_ptr[src_stride + 5]) * + (65536 / 6) >> + 16; + dst_ptr[2] = (src_ptr[6] + src_ptr[7] + src_ptr[src_stride + 6] + + src_ptr[src_stride + 7]) * + (65536 / 4) >> + 16; src_ptr += 8; dst_ptr += 3; } @@ -725,22 +817,23 @@ void ScaleRowDown38_2_Box_16_C(const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, int dst_width) { - intptr_t stride = src_stride; int i; assert((dst_width % 3 == 0) && (dst_width > 0)); for (i = 0; i < dst_width; i += 3) { - dst_ptr[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] + - src_ptr[stride + 1] + src_ptr[stride + 2]) * - (65536 / 6) >> - 16; - dst_ptr[1] = (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] + - src_ptr[stride + 4] + src_ptr[stride + 5]) * - (65536 / 6) >> - 16; - dst_ptr[2] = - (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7]) * - (65536 / 4) >> + dst_ptr[0] = + (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[src_stride + 0] + + src_ptr[src_stride + 1] + src_ptr[src_stride + 2]) * + (65536u / 6u) >> 16; + dst_ptr[1] = + (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[src_stride + 3] + + src_ptr[src_stride + 4] + src_ptr[src_stride + 5]) * + (65536u / 6u) >> + 16; + dst_ptr[2] = (src_ptr[6] + src_ptr[7] + src_ptr[src_stride + 6] + + src_ptr[src_stride + 7]) * + (65536u / 4u) >> + 16; src_ptr += 8; dst_ptr += 3; } @@ -776,22 +869,21 @@ void ScaleAddRow_16_C(const uint16_t* src_ptr, } } +// ARGB scale row functions + void ScaleARGBRowDown2_C(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width) { - const uint32_t* src = (const uint32_t*)(src_argb); - uint32_t* dst = (uint32_t*)(dst_argb); int x; (void)src_stride; - for (x = 0; x < dst_width - 1; x += 2) { - dst[0] = src[1]; - dst[1] = src[3]; - src += 4; - dst += 2; - } - if (dst_width & 1) { - dst[0] = src[1]; + for (x = 0; x < dst_width; ++x) { + dst_argb[0] = src_argb[4]; + dst_argb[1] = src_argb[5]; + dst_argb[2] = src_argb[6]; + dst_argb[3] = src_argb[7]; + src_argb += 8; + dst_argb += 4; } } @@ -839,18 +931,15 @@ void ScaleARGBRowDownEven_C(const uint8_t* src_argb, int src_stepx, uint8_t* dst_argb, int dst_width) { - const uint32_t* src = (const uint32_t*)(src_argb); - uint32_t* dst = (uint32_t*)(dst_argb); - (void)src_stride; int x; - for (x = 0; x < dst_width - 1; x += 2) { - dst[0] = src[0]; - dst[1] = src[src_stepx]; - src += src_stepx * 2; - dst += 2; - } - if (dst_width & 1) { - dst[0] = src[0]; + (void)src_stride; + for (x = 0; x < dst_width; ++x) { + dst_argb[0] = src_argb[0]; + dst_argb[1] = src_argb[1]; + dst_argb[2] = src_argb[2]; + dst_argb[3] = src_argb[3]; + src_argb += src_stepx * 4; + dst_argb += 4; } } @@ -884,18 +973,15 @@ void ScaleARGBCols_C(uint8_t* dst_argb, int dst_width, int x, int dx) { - const uint32_t* src = (const uint32_t*)(src_argb); - uint32_t* dst = (uint32_t*)(dst_argb); int j; - for (j = 0; j < dst_width - 1; j += 2) { - dst[0] = src[x >> 16]; + for (j = 0; j < dst_width; ++j) { + const uint8_t* src = src_argb + (x >> 16) * 4; + dst_argb[0] = src[0]; + dst_argb[1] = src[1]; + dst_argb[2] = src[2]; + dst_argb[3] = src[3]; + dst_argb += 4; x += dx; - dst[1] = src[x >> 16]; - x += dx; - dst += 2; - } - if (dst_width & 1) { - dst[0] = src[x >> 16]; } } @@ -905,18 +991,15 @@ void ScaleARGBCols64_C(uint8_t* dst_argb, int x32, int dx) { int64_t x = (int64_t)(x32); - const uint32_t* src = (const uint32_t*)(src_argb); - uint32_t* dst = (uint32_t*)(dst_argb); int j; - for (j = 0; j < dst_width - 1; j += 2) { - dst[0] = src[x >> 16]; + for (j = 0; j < dst_width; ++j) { + const uint8_t* src = src_argb + (x >> 16) * 4; + dst_argb[0] = src[0]; + dst_argb[1] = src[1]; + dst_argb[2] = src[2]; + dst_argb[3] = src[3]; + dst_argb += 4; x += dx; - dst[1] = src[x >> 16]; - x += dx; - dst += 2; - } - if (dst_width & 1) { - dst[0] = src[x >> 16]; } } @@ -926,59 +1009,46 @@ void ScaleARGBColsUp2_C(uint8_t* dst_argb, int dst_width, int x, int dx) { - const uint32_t* src = (const uint32_t*)(src_argb); - uint32_t* dst = (uint32_t*)(dst_argb); int j; (void)x; (void)dx; for (j = 0; j < dst_width - 1; j += 2) { - dst[1] = dst[0] = src[0]; - src += 1; - dst += 2; + dst_argb[0] = dst_argb[4] = src_argb[0]; + dst_argb[1] = dst_argb[5] = src_argb[1]; + dst_argb[2] = dst_argb[6] = src_argb[2]; + dst_argb[3] = dst_argb[7] = src_argb[3]; + src_argb += 4; + dst_argb += 8; } if (dst_width & 1) { - dst[0] = src[0]; + dst_argb[0] = src_argb[0]; + dst_argb[1] = src_argb[1]; + dst_argb[2] = src_argb[2]; + dst_argb[3] = src_argb[3]; } } // TODO(fbarchard): Replace 0x7f ^ f with 128-f. bug=607. // Mimics SSSE3 blender -#define BLENDER1(a, b, f) ((a) * (0x7f ^ f) + (b)*f) >> 7 -#define BLENDERC(a, b, f, s) \ - (uint32_t)(BLENDER1(((a) >> s) & 255, ((b) >> s) & 255, f) << s) -#define BLENDER(a, b, f) \ - BLENDERC(a, b, f, 24) | BLENDERC(a, b, f, 16) | BLENDERC(a, b, f, 8) | \ - BLENDERC(a, b, f, 0) +#define BLENDER1(a, b, f) (((a) * (0x7f ^ (f)) + (b) * (f)) >> 7) void ScaleARGBFilterCols_C(uint8_t* dst_argb, const uint8_t* src_argb, int dst_width, int x, int dx) { - const uint32_t* src = (const uint32_t*)(src_argb); - uint32_t* dst = (uint32_t*)(dst_argb); int j; - for (j = 0; j < dst_width - 1; j += 2) { - int xi = x >> 16; + for (j = 0; j < dst_width; ++j) { + int xi = (x >> 16) * 4; int xf = (x >> 9) & 0x7f; - uint32_t a = src[xi]; - uint32_t b = src[xi + 1]; - dst[0] = BLENDER(a, b, xf); + const uint8_t* a = src_argb + xi; + const uint8_t* b = a + 4; + dst_argb[0] = (uint8_t)BLENDER1(a[0], b[0], xf); + dst_argb[1] = (uint8_t)BLENDER1(a[1], b[1], xf); + dst_argb[2] = (uint8_t)BLENDER1(a[2], b[2], xf); + dst_argb[3] = (uint8_t)BLENDER1(a[3], b[3], xf); + dst_argb += 4; x += dx; - xi = x >> 16; - xf = (x >> 9) & 0x7f; - a = src[xi]; - b = src[xi + 1]; - dst[1] = BLENDER(a, b, xf); - x += dx; - dst += 2; - } - if (dst_width & 1) { - int xi = x >> 16; - int xf = (x >> 9) & 0x7f; - uint32_t a = src[xi]; - uint32_t b = src[xi + 1]; - dst[0] = BLENDER(a, b, xf); } } @@ -988,35 +1058,521 @@ void ScaleARGBFilterCols64_C(uint8_t* dst_argb, int x32, int dx) { int64_t x = (int64_t)(x32); - const uint32_t* src = (const uint32_t*)(src_argb); - uint32_t* dst = (uint32_t*)(dst_argb); int j; - for (j = 0; j < dst_width - 1; j += 2) { - int64_t xi = x >> 16; + for (j = 0; j < dst_width; ++j) { + int64_t xi = (x >> 16) * 4; int xf = (x >> 9) & 0x7f; - uint32_t a = src[xi]; - uint32_t b = src[xi + 1]; - dst[0] = BLENDER(a, b, xf); + const uint8_t* a = src_argb + xi; + const uint8_t* b = a + 4; + dst_argb[0] = (uint8_t)BLENDER1(a[0], b[0], xf); + dst_argb[1] = (uint8_t)BLENDER1(a[1], b[1], xf); + dst_argb[2] = (uint8_t)BLENDER1(a[2], b[2], xf); + dst_argb[3] = (uint8_t)BLENDER1(a[3], b[3], xf); + dst_argb += 4; x += dx; - xi = x >> 16; - xf = (x >> 9) & 0x7f; - a = src[xi]; - b = src[xi + 1]; - dst[1] = BLENDER(a, b, xf); - x += dx; - dst += 2; - } - if (dst_width & 1) { - int64_t xi = x >> 16; - int xf = (x >> 9) & 0x7f; - uint32_t a = src[xi]; - uint32_t b = src[xi + 1]; - dst[0] = BLENDER(a, b, xf); } } #undef BLENDER1 -#undef BLENDERC -#undef BLENDER + +// UV scale row functions +// same as ARGB but 2 channels + +void ScaleUVRowDown2_C(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + int x; + (void)src_stride; + for (x = 0; x < dst_width; ++x) { + dst_uv[0] = src_uv[2]; // Store the 2nd UV + dst_uv[1] = src_uv[3]; + src_uv += 4; + dst_uv += 2; + } +} + +void ScaleUVRowDown2Linear_C(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + int x; + (void)src_stride; + for (x = 0; x < dst_width; ++x) { + dst_uv[0] = (src_uv[0] + src_uv[2] + 1) >> 1; + dst_uv[1] = (src_uv[1] + src_uv[3] + 1) >> 1; + src_uv += 4; + dst_uv += 2; + } +} + +void ScaleUVRowDown2Box_C(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + int x; + for (x = 0; x < dst_width; ++x) { + dst_uv[0] = (src_uv[0] + src_uv[2] + src_uv[src_stride] + + src_uv[src_stride + 2] + 2) >> + 2; + dst_uv[1] = (src_uv[1] + src_uv[3] + src_uv[src_stride + 1] + + src_uv[src_stride + 3] + 2) >> + 2; + src_uv += 4; + dst_uv += 2; + } +} + +void ScaleUVRowDownEven_C(const uint8_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_uv, + int dst_width) { + int x; + (void)src_stride; + for (x = 0; x < dst_width; ++x) { + dst_uv[0] = src_uv[0]; + dst_uv[1] = src_uv[1]; + src_uv += src_stepx * 2; + dst_uv += 2; + } +} + +void ScaleUVRowDownEvenBox_C(const uint8_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_uv, + int dst_width) { + int x; + for (x = 0; x < dst_width; ++x) { + dst_uv[0] = (src_uv[0] + src_uv[2] + src_uv[src_stride] + + src_uv[src_stride + 2] + 2) >> + 2; + dst_uv[1] = (src_uv[1] + src_uv[3] + src_uv[src_stride + 1] + + src_uv[src_stride + 3] + 2) >> + 2; + src_uv += src_stepx * 2; + dst_uv += 2; + } +} + +void ScaleUVRowDown2_16_C(const uint16_t* src_uv, + ptrdiff_t src_stride, + uint16_t* dst_uv, + int dst_width) { + int x; + (void)src_stride; + for (x = 0; x < dst_width; ++x) { + dst_uv[0] = src_uv[2]; // Store the 2nd UV + dst_uv[1] = src_uv[3]; + src_uv += 4; + dst_uv += 2; + } +} + +void ScaleUVRowDown2Linear_16_C(const uint16_t* src_uv, + ptrdiff_t src_stride, + uint16_t* dst_uv, + int dst_width) { + int x; + (void)src_stride; + for (x = 0; x < dst_width; ++x) { + dst_uv[0] = (uint16_t)(((uint32_t)src_uv[0] + src_uv[2] + 1) >> 1); + dst_uv[1] = (uint16_t)(((uint32_t)src_uv[1] + src_uv[3] + 1) >> 1); + src_uv += 4; + dst_uv += 2; + } +} + +void ScaleUVRowDown2Box_16_C(const uint16_t* src_uv, + ptrdiff_t src_stride, + uint16_t* dst_uv, + int dst_width) { + int x; + for (x = 0; x < dst_width; ++x) { + dst_uv[0] = (uint16_t)(((uint32_t)src_uv[0] + src_uv[2] + + src_uv[src_stride] + src_uv[src_stride + 2] + 2) >> + 2); + dst_uv[1] = + (uint16_t)(((uint32_t)src_uv[1] + src_uv[3] + src_uv[src_stride + 1] + + src_uv[src_stride + 3] + 2) >> + 2); + src_uv += 4; + dst_uv += 2; + } +} + +void ScaleUVRowDownEven_16_C(const uint16_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint16_t* dst_uv, + int dst_width) { + int x; + (void)src_stride; + for (x = 0; x < dst_width; ++x) { + dst_uv[0] = src_uv[0]; + dst_uv[1] = src_uv[1]; + src_uv += src_stepx * 2; + dst_uv += 2; + } +} + +void ScaleUVRowDownEvenBox_16_C(const uint16_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint16_t* dst_uv, + int dst_width) { + int x; + for (x = 0; x < dst_width; ++x) { + dst_uv[0] = (uint16_t)(((uint32_t)src_uv[0] + src_uv[2] + + src_uv[src_stride] + src_uv[src_stride + 2] + 2) >> + 2); + dst_uv[1] = + (uint16_t)(((uint32_t)src_uv[1] + src_uv[3] + src_uv[src_stride + 1] + + src_uv[src_stride + 3] + 2) >> + 2); + src_uv += src_stepx * 2; + dst_uv += 2; + } +} + +void ScaleUVRowUp2_Linear_C(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + int src_width = dst_width >> 1; + int x; + assert((dst_width % 2 == 0) && (dst_width >= 0)); + for (x = 0; x < src_width; ++x) { + dst_ptr[4 * x + 0] = + (src_ptr[2 * x + 0] * 3 + src_ptr[2 * x + 2] * 1 + 2) >> 2; + dst_ptr[4 * x + 1] = + (src_ptr[2 * x + 1] * 3 + src_ptr[2 * x + 3] * 1 + 2) >> 2; + dst_ptr[4 * x + 2] = + (src_ptr[2 * x + 0] * 1 + src_ptr[2 * x + 2] * 3 + 2) >> 2; + dst_ptr[4 * x + 3] = + (src_ptr[2 * x + 1] * 1 + src_ptr[2 * x + 3] * 3 + 2) >> 2; + } +} + +void ScaleUVRowUp2_Bilinear_C(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint8_t* s = src_ptr; + const uint8_t* t = src_ptr + src_stride; + uint8_t* d = dst_ptr; + uint8_t* e = dst_ptr + dst_stride; + int src_width = dst_width >> 1; + int x; + assert((dst_width % 2 == 0) && (dst_width >= 0)); + for (x = 0; x < src_width; ++x) { + d[4 * x + 0] = (s[2 * x + 0] * 9 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 + + t[2 * x + 2] * 1 + 8) >> + 4; + d[4 * x + 1] = (s[2 * x + 1] * 9 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 + + t[2 * x + 3] * 1 + 8) >> + 4; + d[4 * x + 2] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 9 + t[2 * x + 0] * 1 + + t[2 * x + 2] * 3 + 8) >> + 4; + d[4 * x + 3] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 9 + t[2 * x + 1] * 1 + + t[2 * x + 3] * 3 + 8) >> + 4; + e[4 * x + 0] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 1 + t[2 * x + 0] * 9 + + t[2 * x + 2] * 3 + 8) >> + 4; + e[4 * x + 1] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 1 + t[2 * x + 1] * 9 + + t[2 * x + 3] * 3 + 8) >> + 4; + e[4 * x + 2] = (s[2 * x + 0] * 1 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 + + t[2 * x + 2] * 9 + 8) >> + 4; + e[4 * x + 3] = (s[2 * x + 1] * 1 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 + + t[2 * x + 3] * 9 + 8) >> + 4; + } +} + +void ScaleUVRowUp2_Linear_16_C(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + int src_width = dst_width >> 1; + int x; + assert((dst_width % 2 == 0) && (dst_width >= 0)); + for (x = 0; x < src_width; ++x) { + dst_ptr[4 * x + 0] = + (src_ptr[2 * x + 0] * 3 + src_ptr[2 * x + 2] * 1 + 2) >> 2; + dst_ptr[4 * x + 1] = + (src_ptr[2 * x + 1] * 3 + src_ptr[2 * x + 3] * 1 + 2) >> 2; + dst_ptr[4 * x + 2] = + (src_ptr[2 * x + 0] * 1 + src_ptr[2 * x + 2] * 3 + 2) >> 2; + dst_ptr[4 * x + 3] = + (src_ptr[2 * x + 1] * 1 + src_ptr[2 * x + 3] * 3 + 2) >> 2; + } +} + +void ScaleUVRowUp2_Bilinear_16_C(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint16_t* s = src_ptr; + const uint16_t* t = src_ptr + src_stride; + uint16_t* d = dst_ptr; + uint16_t* e = dst_ptr + dst_stride; + int src_width = dst_width >> 1; + int x; + assert((dst_width % 2 == 0) && (dst_width >= 0)); + for (x = 0; x < src_width; ++x) { + d[4 * x + 0] = (s[2 * x + 0] * 9 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 + + t[2 * x + 2] * 1 + 8) >> + 4; + d[4 * x + 1] = (s[2 * x + 1] * 9 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 + + t[2 * x + 3] * 1 + 8) >> + 4; + d[4 * x + 2] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 9 + t[2 * x + 0] * 1 + + t[2 * x + 2] * 3 + 8) >> + 4; + d[4 * x + 3] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 9 + t[2 * x + 1] * 1 + + t[2 * x + 3] * 3 + 8) >> + 4; + e[4 * x + 0] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 1 + t[2 * x + 0] * 9 + + t[2 * x + 2] * 3 + 8) >> + 4; + e[4 * x + 1] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 1 + t[2 * x + 1] * 9 + + t[2 * x + 3] * 3 + 8) >> + 4; + e[4 * x + 2] = (s[2 * x + 0] * 1 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 + + t[2 * x + 2] * 9 + 8) >> + 4; + e[4 * x + 3] = (s[2 * x + 1] * 1 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 + + t[2 * x + 3] * 9 + 8) >> + 4; + } +} + +// Scales a single row of pixels using point sampling. +void ScaleUVCols_C(uint8_t* dst_uv, + const uint8_t* src_uv, + int dst_width, + int x, + int dx) { + int j; + for (j = 0; j < dst_width; ++j) { + const uint8_t* src = src_uv + (x >> 16) * 2; + dst_uv[0] = src[0]; + dst_uv[1] = src[1]; + dst_uv += 2; + x += dx; + } +} + +void ScaleUVCols64_C(uint8_t* dst_uv, + const uint8_t* src_uv, + int dst_width, + int x32, + int dx) { + int64_t x = (int64_t)(x32); + int j; + for (j = 0; j < dst_width; ++j) { + const uint8_t* src = src_uv + (x >> 16) * 2; + dst_uv[0] = src[0]; + dst_uv[1] = src[1]; + dst_uv += 2; + x += dx; + } +} + +// Scales a single row of pixels up by 2x using point sampling. +void ScaleUVColsUp2_C(uint8_t* dst_uv, + const uint8_t* src_uv, + int dst_width, + int x, + int dx) { + int j; + (void)x; + (void)dx; + for (j = 0; j < dst_width - 1; j += 2) { + dst_uv[0] = dst_uv[2] = src_uv[0]; + dst_uv[1] = dst_uv[3] = src_uv[1]; + src_uv += 2; + dst_uv += 4; + } + if (dst_width & 1) { + dst_uv[0] = src_uv[0]; + dst_uv[1] = src_uv[1]; + } +} + +// Performs (a + ((f * (b - a) + 64) >> 7)) which is equivalent of +// ((a * (128 - f) + b * f + 64) >> 7). +#define BLENDER1(a, b, f) ((a) + (((f) * ((b) - (a)) + 64) >> 7)) + +void ScaleUVFilterCols_C(uint8_t* dst_uv, + const uint8_t* src_uv, + int dst_width, + int x, + int dx) { + int j; + for (j = 0; j < dst_width; ++j) { + int xi = (x >> 16) * 2; + int xf = (x >> 9) & 0x7f; + const uint8_t* a = src_uv + xi; + const uint8_t* b = a + 2; + dst_uv[0] = (uint8_t)BLENDER1(a[0], b[0], xf); + dst_uv[1] = (uint8_t)BLENDER1(a[1], b[1], xf); + dst_uv += 2; + x += dx; + } +} + +void ScaleUVFilterCols64_C(uint8_t* dst_uv, + const uint8_t* src_uv, + int dst_width, + int x32, + int dx) { + int64_t x = (int64_t)(x32); + int j; + for (j = 0; j < dst_width; ++j) { + int64_t xi = (x >> 16) * 2; + int xf = (x >> 9) & 0x7f; + const uint8_t* a = src_uv + xi; + const uint8_t* b = a + 2; + dst_uv[0] = (uint8_t)BLENDER1(a[0], b[0], xf); + dst_uv[1] = (uint8_t)BLENDER1(a[1], b[1], xf); + dst_uv += 2; + x += dx; + } +} +#undef BLENDER1 + +// Scale UV columns by 3 box filter. +void ScaleUVAddCols3_C(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { + int i; + for (i = 0; i < dst_width; ++i) { + uint32_t u = src_uv[0] + src_uv[2] + src_uv[4]; + uint32_t v = src_uv[1] + src_uv[3] + src_uv[5]; + src_uv += 6; + dst_uv[0] = (uint8_t)((u * scaleval) >> 16); + dst_uv[1] = (uint8_t)((v * scaleval) >> 16); + dst_uv += 2; + } +} + +// Scales a single row of 16-bit UV pixels using point sampling. +void ScaleUVCols_16_C(uint16_t* dst_uv, + const uint16_t* src_uv, + int dst_width, + int x, + int dx) { + int j; + for (j = 0; j < dst_width; ++j) { + const uint16_t* src = src_uv + (x >> 16) * 2; + dst_uv[0] = src[0]; + dst_uv[1] = src[1]; + dst_uv += 2; + x += dx; + } +} + +void ScaleUVCols64_16_C(uint16_t* dst_uv, + const uint16_t* src_uv, + int dst_width, + int x32, + int dx) { + int64_t x = (int64_t)(x32); + int j; + for (j = 0; j < dst_width; ++j) { + const uint16_t* src = src_uv + (x >> 16) * 2; + dst_uv[0] = src[0]; + dst_uv[1] = src[1]; + dst_uv += 2; + x += dx; + } +} + +// Scales a single row of 16-bit UV pixels up by 2x using point sampling. +void ScaleUVColsUp2_16_C(uint16_t* dst_uv, + const uint16_t* src_uv, + int dst_width, + int x, + int dx) { + int j; + (void)x; + (void)dx; + for (j = 0; j < dst_width - 1; j += 2) { + dst_uv[0] = dst_uv[2] = src_uv[0]; + dst_uv[1] = dst_uv[3] = src_uv[1]; + src_uv += 2; + dst_uv += 4; + } + if (dst_width & 1) { + dst_uv[0] = src_uv[0]; + dst_uv[1] = src_uv[1]; + } +} + +#define BLENDER_16(a, b, f) \ + (uint16_t)((int)(a) + \ + (int)((((int64_t)((f)) * ((int64_t)(b) - (int)(a))) + 0x8000) >> \ + 16)) + +void ScaleUVFilterCols_16_C(uint16_t* dst_uv, + const uint16_t* src_uv, + int dst_width, + int x, + int dx) { + int j; + for (j = 0; j < dst_width; ++j) { + int xi = (x >> 16) * 2; + int xf = x & 0xffff; + const uint16_t* a = src_uv + xi; + const uint16_t* b = a + 2; + dst_uv[0] = BLENDER_16(a[0], b[0], xf); + dst_uv[1] = BLENDER_16(a[1], b[1], xf); + dst_uv += 2; + x += dx; + } +} + +void ScaleUVFilterCols64_16_C(uint16_t* dst_uv, + const uint16_t* src_uv, + int dst_width, + int x32, + int dx) { + int64_t x = (int64_t)(x32); + int j; + for (j = 0; j < dst_width; ++j) { + int64_t xi = (x >> 16) * 2; + int xf = x & 0xffff; + const uint16_t* a = src_uv + xi; + const uint16_t* b = a + 2; + dst_uv[0] = BLENDER_16(a[0], b[0], xf); + dst_uv[1] = BLENDER_16(a[1], b[1], xf); + dst_uv += 2; + x += dx; + } +} +#undef BLENDER_16 + +// Scale 16-bit UV columns by 3 box filter. +void ScaleUVAddCols3_16_C(int dst_width, + int scaleval, + const uint32_t* src_uv, + uint16_t* dst_uv) { + int i; + for (i = 0; i < dst_width; ++i) { + uint32_t u = src_uv[0] + src_uv[2] + src_uv[4]; + uint32_t v = src_uv[1] + src_uv[3] + src_uv[5]; + src_uv += 6; + dst_uv[0] = (uint16_t)((u * (uint32_t)scaleval) >> 16); + dst_uv[1] = (uint16_t)((v * (uint32_t)scaleval) >> 16); + dst_uv += 2; + } +} // Scale plane vertically with bilinear interpolation. void ScalePlaneVertical(int src_height, @@ -1029,28 +1585,32 @@ void ScalePlaneVertical(int src_height, int x, int y, int dy, - int bpp, + int bpp, // bytes per pixel. 4 for ARGB. enum FilterMode filtering) { // TODO(fbarchard): Allow higher bpp. int dst_width_bytes = dst_width * bpp; - void (*InterpolateRow)(uint8_t * dst_argb, const uint8_t* src_argb, + void (*InterpolateRow)(uint8_t* dst_argb, const uint8_t* src_argb, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_C; - const int max_y = (src_height > 1) ? ((src_height - 1) << 16) - 1 : 0; + const bool interpolate = filtering == kFilterBilinear; + int64_t max_y = 0; + if (src_height > 1) { + max_y = ((int64_t)src_height - 1) << 16; + if (interpolate) { + --max_y; + } + } + // Without vertical interpolation, InterpolateRow() copies one row. A zero + // stride keeps it from forming a second source row pointer past the end when + // y is clamped to the last row. + const ptrdiff_t interpolate_stride = interpolate ? src_stride : 0; + int64_t y64 = y; int j; assert(bpp >= 1 && bpp <= 4); assert(src_height != 0); assert(dst_width > 0); assert(dst_height > 0); src_argb += (x >> 16) * bpp; -#if defined(HAS_INTERPOLATEROW_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_SSSE3; - if (IS_ALIGNED(dst_width_bytes, 16)) { - InterpolateRow = InterpolateRow_SSSE3; - } - } -#endif #if defined(HAS_INTERPOLATEROW_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { InterpolateRow = InterpolateRow_Any_AVX2; @@ -1059,6 +1619,11 @@ void ScalePlaneVertical(int src_height, } } #endif +#if defined(HAS_INTERPOLATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_AVX512BW; + } +#endif #if defined(HAS_INTERPOLATEROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { InterpolateRow = InterpolateRow_Any_NEON; @@ -1067,36 +1632,66 @@ void ScalePlaneVertical(int src_height, } } #endif -#if defined(HAS_INTERPOLATEROW_MSA) - if (TestCpuFlag(kCpuHasMSA)) { - InterpolateRow = InterpolateRow_Any_MSA; +#if defined(HAS_INTERPOLATEROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + InterpolateRow = InterpolateRow_SVE2; + } +#endif +#if defined(HAS_INTERPOLATEROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + InterpolateRow = InterpolateRow_Any_LSX; + if (IS_ALIGNED(dst_width_bytes, 16)) { + InterpolateRow = InterpolateRow_LSX; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + InterpolateRow = InterpolateRow_Any_LASX; if (IS_ALIGNED(dst_width_bytes, 32)) { - InterpolateRow = InterpolateRow_MSA; + InterpolateRow = InterpolateRow_LASX; } } #endif -#if defined(HAS_INTERPOLATEROW_MMI) - if (TestCpuFlag(kCpuHasMMI)) { - InterpolateRow = InterpolateRow_Any_MMI; - if (IS_ALIGNED(dst_width_bytes, 8)) { - InterpolateRow = InterpolateRow_MMI; +#if defined(HAS_INTERPOLATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + InterpolateRow = InterpolateRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_HVX; + } +#endif +#if defined(HAS_INTERPOLATEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_Any_WASMSIMD; + if (IS_ALIGNED(dst_width_bytes, 16)) { + InterpolateRow = InterpolateRow_WASMSIMD; } } #endif + for (j = 0; j < dst_height; ++j) { int yi; int yf; - if (y > max_y) { - y = max_y; + if (y64 > max_y) { + y64 = max_y; } - yi = y >> 16; - yf = filtering ? ((y >> 8) & 255) : 0; - InterpolateRow(dst_argb, src_argb + yi * src_stride, src_stride, - dst_width_bytes, yf); + yi = (int)(y64 >> 16); + yf = interpolate ? (int)((y64 >> 8) & 255) : 0; + InterpolateRow(dst_argb, src_argb + yi * (ptrdiff_t)src_stride, + interpolate_stride, dst_width_bytes, yf); dst_argb += dst_stride; - y += dy; + y64 += dy; } } + void ScalePlaneVertical_16(int src_height, int dst_width, int dst_height, @@ -1107,64 +1702,83 @@ void ScalePlaneVertical_16(int src_height, int x, int y, int dy, - int wpp, + int wpp, /* words per pixel. normally 1 */ enum FilterMode filtering) { // TODO(fbarchard): Allow higher wpp. int dst_width_words = dst_width * wpp; - void (*InterpolateRow)(uint16_t * dst_argb, const uint16_t* src_argb, + void (*InterpolateRow)(uint16_t* dst_argb, const uint16_t* src_argb, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_16_C; - const int max_y = (src_height > 1) ? ((src_height - 1) << 16) - 1 : 0; + const bool interpolate = filtering == kFilterBilinear; + int64_t max_y = 0; + if (src_height > 1) { + max_y = ((int64_t)src_height - 1) << 16; + if (interpolate) { + --max_y; + } + } + // Without vertical interpolation, InterpolateRow() copies one row. A zero + // stride keeps it from forming a second source row pointer past the end when + // y is clamped to the last row. + const ptrdiff_t interpolate_stride = interpolate ? src_stride : 0; + int64_t y64 = y; int j; assert(wpp >= 1 && wpp <= 2); assert(src_height != 0); assert(dst_width > 0); assert(dst_height > 0); src_argb += (x >> 16) * wpp; -#if defined(HAS_INTERPOLATEROW_16_SSE2) - if (TestCpuFlag(kCpuHasSSE2)) { - InterpolateRow = InterpolateRow_Any_16_SSE2; - if (IS_ALIGNED(dst_width_bytes, 16)) { - InterpolateRow = InterpolateRow_16_SSE2; - } - } -#endif -#if defined(HAS_INTERPOLATEROW_16_SSSE3) - if (TestCpuFlag(kCpuHasSSSE3)) { - InterpolateRow = InterpolateRow_Any_16_SSSE3; - if (IS_ALIGNED(dst_width_bytes, 16)) { - InterpolateRow = InterpolateRow_16_SSSE3; - } - } -#endif #if defined(HAS_INTERPOLATEROW_16_AVX2) if (TestCpuFlag(kCpuHasAVX2)) { - InterpolateRow = InterpolateRow_Any_16_AVX2; - if (IS_ALIGNED(dst_width_bytes, 32)) { + InterpolateRow = InterpolateRow_16_Any_AVX2; + if (IS_ALIGNED(dst_width_words, 32)) { InterpolateRow = InterpolateRow_16_AVX2; } } #endif +#if defined(HAS_INTERPOLATEROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_16_AVX512BW; + } +#endif #if defined(HAS_INTERPOLATEROW_16_NEON) if (TestCpuFlag(kCpuHasNEON)) { - InterpolateRow = InterpolateRow_Any_16_NEON; - if (IS_ALIGNED(dst_width_bytes, 16)) { + InterpolateRow = InterpolateRow_16_Any_NEON; + if (IS_ALIGNED(dst_width_words, 8)) { InterpolateRow = InterpolateRow_16_NEON; } } +#endif +#if defined(HAS_INTERPOLATEROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_16_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_16_HVX; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_16_Any_WASMSIMD; + if (IS_ALIGNED(dst_width_words, 8)) { + InterpolateRow = InterpolateRow_16_WASMSIMD; + } + } #endif for (j = 0; j < dst_height; ++j) { int yi; int yf; - if (y > max_y) { - y = max_y; + if (y64 > max_y) { + y64 = max_y; } - yi = y >> 16; - yf = filtering ? ((y >> 8) & 255) : 0; - InterpolateRow(dst_argb, src_argb + yi * src_stride, src_stride, - dst_width_words, yf); + yi = (int)(y64 >> 16); + yf = interpolate ? (int)((y64 >> 8) & 255) : 0; + InterpolateRow(dst_argb, src_argb + yi * (ptrdiff_t)src_stride, + interpolate_stride, dst_width_words, yf); dst_argb += dst_stride; - y += dy; + y64 += dy; } } @@ -1181,8 +1795,9 @@ enum FilterMode ScaleFilterReduce(int src_width, src_height = -src_height; } if (filtering == kFilterBox) { - // If scaling both axis to 0.5 or larger, switch from Box to Bilinear. - if (dst_width * 2 >= src_width && dst_height * 2 >= src_height) { + // If scaling either axis to 0.5 or larger, switch from Box to Bilinear. + if ((int64_t)dst_width * 2 >= src_width || + (int64_t)dst_height * 2 >= src_height) { filtering = kFilterBilinear; } } @@ -1191,7 +1806,7 @@ enum FilterMode ScaleFilterReduce(int src_width, filtering = kFilterLinear; } // TODO(fbarchard): Detect any odd scale factor and reduce to Linear. - if (dst_height == src_height || dst_height * 3 == src_height) { + if (dst_height == src_height || (int64_t)dst_height * 3 == src_height) { filtering = kFilterLinear; } // TODO(fbarchard): Remove 1 pixel wide filter restriction, which is to @@ -1205,7 +1820,7 @@ enum FilterMode ScaleFilterReduce(int src_width, filtering = kFilterNone; } // TODO(fbarchard): Detect any odd scale factor and reduce to None. - if (dst_width == src_width || dst_width * 3 == src_width) { + if (dst_width == src_width || (int64_t)dst_width * 3 == src_width) { filtering = kFilterNone; } } @@ -1217,7 +1832,7 @@ int FixedDiv_C(int num, int div) { return (int)(((int64_t)(num) << 16) / div); } -// Divide num by div and return as 16.16 fixed point result. +// Divide num - 1 by div - 1 and return as 16.16 fixed point result. int FixedDiv1_C(int num, int div) { return (int)((((int64_t)(num) << 16) - 0x00010001) / (div - 1)); } @@ -1243,8 +1858,10 @@ void ScaleSlope(int src_width, assert(dst_width > 0); assert(dst_height > 0); // Check for 1 pixel and avoid FixedDiv overflow. - if (dst_width == 1 && src_width >= 32768) { - dst_width = src_width; + // TODO(b/573815252): Fix center coordinate calculation when dst == 1 and + // src == 32768. + if (dst_width == 1 && Abs(src_width) >= 32768) { + dst_width = Abs(src_width); } if (dst_height == 1 && src_height >= 32768) { dst_height = src_height; @@ -1260,14 +1877,14 @@ void ScaleSlope(int src_width, if (dst_width <= Abs(src_width)) { *dx = FixedDiv(Abs(src_width), dst_width); *x = CENTERSTART(*dx, -32768); // Subtract 0.5 (32768) to center filter. - } else if (dst_width > 1) { + } else if (src_width > 1 && dst_width > 1) { *dx = FixedDiv1(Abs(src_width), dst_width); *x = 0; } if (dst_height <= src_height) { *dy = FixedDiv(src_height, dst_height); *y = CENTERSTART(*dy, -32768); // Subtract 0.5 (32768) to center filter. - } else if (dst_height > 1) { + } else if (src_height > 1 && dst_height > 1) { *dy = FixedDiv1(src_height, dst_height); *y = 0; } @@ -1276,7 +1893,7 @@ void ScaleSlope(int src_width, if (dst_width <= Abs(src_width)) { *dx = FixedDiv(Abs(src_width), dst_width); *x = CENTERSTART(*dx, -32768); // Subtract 0.5 (32768) to center filter. - } else if (dst_width > 1) { + } else if (src_width > 1 && dst_width > 1) { *dx = FixedDiv1(Abs(src_width), dst_width); *x = 0; } @@ -1298,35 +1915,6 @@ void ScaleSlope(int src_width, } #undef CENTERSTART -// Read 8x2 upsample with filtering and write 16x1. -// actually reads an extra pixel, so 9x2. -void ScaleRowUp2_16_C(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width) { - const uint16_t* src2 = src_ptr + src_stride; - - int x; - for (x = 0; x < dst_width - 1; x += 2) { - uint16_t p0 = src_ptr[0]; - uint16_t p1 = src_ptr[1]; - uint16_t p2 = src2[0]; - uint16_t p3 = src2[1]; - dst[0] = (p0 * 9 + p1 * 3 + p2 * 3 + p3 + 8) >> 4; - dst[1] = (p0 * 3 + p1 * 9 + p2 + p3 * 3 + 8) >> 4; - ++src_ptr; - ++src2; - dst += 2; - } - if (dst_width & 1) { - uint16_t p0 = src_ptr[0]; - uint16_t p1 = src_ptr[1]; - uint16_t p2 = src2[0]; - uint16_t p3 = src2[1]; - dst[0] = (p0 * 9 + p1 * 3 + p2 * 3 + p3 + 8) >> 4; - } -} - #ifdef __cplusplus } // extern "C" } // namespace libyuv diff --git a/libs/libyuv/source/scale_gcc.cc b/libs/libyuv/source/scale_gcc.cc index 90a49f30d7..4c239b7d92 100644 --- a/libs/libyuv/source/scale_gcc.cc +++ b/libs/libyuv/source/scale_gcc.cc @@ -16,10 +16,19 @@ namespace libyuv { extern "C" { #endif -// This module is for GCC x86 and x64. -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. +// This module is for GCC x86 and x64. +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__)) && \ + !defined(LIBYUV_ENABLE_ROWWIN) + +#ifdef HAS_SCALEROWDOWN34_AVX2 // Offsets for source bytes 0 to 9 static const uvec8 kShuf0 = {0, 1, 3, 4, 5, 7, 8, 9, 128, 128, 128, 128, 128, 128, 128, 128}; @@ -54,7 +63,9 @@ static const uvec8 kMadd21 = {2, 2, 1, 3, 3, 1, 2, 2, 1, 3, 3, 1, 2, 2, 1, 3}; // Coefficients for source bytes 21 to 31 static const vec16 kRound34 = {2, 2, 2, 2, 2, 2, 2, 2}; +#endif // HAS_SCALEROWDOWN34_AVX2 +#ifdef HAS_SCALEROWDOWN38_AVX2 static const uvec8 kShuf38a = {0, 3, 6, 8, 11, 14, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}; @@ -88,6 +99,7 @@ static const uvec8 kShufAb2 = {2, 128, 5, 128, 128, 128, 10, 128, // Scaling values for boxes of 3x2 and 2x2 static const uvec16 kScaleAb2 = {65536 / 3, 65536 / 3, 65536 / 2, 65536 / 3, 65536 / 3, 65536 / 2, 0, 0}; +#endif // HAS_SCALEROWDOWN38_AVX2 // GCC versions of row functions are verbatim conversions from Visual C. // Generated using gcc disassembly on Visual C object file: @@ -101,22 +113,22 @@ void ScaleRowDown2_SSSE3(const uint8_t* src_ptr, asm volatile( // 16 pixel loop. LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "psrlw $0x8,%%xmm0 \n" - "psrlw $0x8,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "psrlw $0x8,%%xmm0 \n" + "psrlw $0x8,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width) // %2 - ::"memory", - "cc", "xmm0", "xmm1"); + : + : "memory", "cc", "xmm0", "xmm1"); } void ScaleRowDown2Linear_SSSE3(const uint8_t* src_ptr, @@ -125,30 +137,30 @@ void ScaleRowDown2Linear_SSSE3(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "pcmpeqb %%xmm4,%%xmm4 \n" - "psrlw $0xf,%%xmm4 \n" - "packuswb %%xmm4,%%xmm4 \n" - "pxor %%xmm5,%%xmm5 \n" + "pcmpeqb %%xmm4,%%xmm4 \n" // 0x0101 + "pabsb %%xmm4,%%xmm4 \n" + + "pxor %%xmm5,%%xmm5 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "pavgw %%xmm5,%%xmm0 \n" - "pavgw %%xmm5,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "pmaddubsw %%xmm4,%%xmm0 \n" + "pmaddubsw %%xmm4,%%xmm1 \n" + "pavgw %%xmm5,%%xmm0 \n" + "pavgw %%xmm5,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width) // %2 - ::"memory", - "cc", "xmm0", "xmm1", "xmm4", "xmm5"); + : + : "memory", "cc", "xmm0", "xmm1", "xmm4", "xmm5"); } void ScaleRowDown2Box_SSSE3(const uint8_t* src_ptr, @@ -156,38 +168,37 @@ void ScaleRowDown2Box_SSSE3(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) { asm volatile( - "pcmpeqb %%xmm4,%%xmm4 \n" - "psrlw $0xf,%%xmm4 \n" - "packuswb %%xmm4,%%xmm4 \n" - "pxor %%xmm5,%%xmm5 \n" + "pcmpeqb %%xmm4,%%xmm4 \n" // 0x0101 + "pabsb %%xmm4,%%xmm4 \n" + "pxor %%xmm5,%%xmm5 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x00(%0,%3,1),%%xmm2 \n" - "movdqu 0x10(%0,%3,1),%%xmm3 \n" - "lea 0x20(%0),%0 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm4,%%xmm3 \n" - "paddw %%xmm2,%%xmm0 \n" - "paddw %%xmm3,%%xmm1 \n" - "psrlw $0x1,%%xmm0 \n" - "psrlw $0x1,%%xmm1 \n" - "pavgw %%xmm5,%%xmm0 \n" - "pavgw %%xmm5,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(dst_width) // %2 - : "r"((intptr_t)(src_stride)) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x00(%0,%3,1),%%xmm2 \n" + "movdqu 0x10(%0,%3,1),%%xmm3 \n" + "lea 0x20(%0),%0 \n" + "pmaddubsw %%xmm4,%%xmm0 \n" + "pmaddubsw %%xmm4,%%xmm1 \n" + "pmaddubsw %%xmm4,%%xmm2 \n" + "pmaddubsw %%xmm4,%%xmm3 \n" + "paddw %%xmm2,%%xmm0 \n" + "paddw %%xmm3,%%xmm1 \n" + "psrlw $0x1,%%xmm0 \n" + "psrlw $0x1,%%xmm1 \n" + "pavgw %%xmm5,%%xmm0 \n" + "pavgw %%xmm5,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); } #ifdef HAS_SCALEROWDOWN2_AVX2 @@ -197,26 +208,24 @@ void ScaleRowDown2_AVX2(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpsrlw $0x8,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width) // %2 - ::"memory", - "cc", "xmm0", "xmm1"); + : + : "memory", "cc", "xmm0", "xmm1"); } void ScaleRowDown2Linear_AVX2(const uint8_t* src_ptr, @@ -225,32 +234,31 @@ void ScaleRowDown2Linear_AVX2(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" - "vpsrlw $0xf,%%ymm4,%%ymm4 \n" - "vpackuswb %%ymm4,%%ymm4,%%ymm4 \n" - "vpxor %%ymm5,%%ymm5,%%ymm5 \n" + "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" + "vpabsb %%ymm4,%%ymm4 \n" + "vpxor %%ymm5,%%ymm5,%%ymm5 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" - "vpmaddubsw %%ymm4,%%ymm1,%%ymm1 \n" - "vpavgw %%ymm5,%%ymm0,%%ymm0 \n" - "vpavgw %%ymm5,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" + "vpmaddubsw %%ymm4,%%ymm1,%%ymm1 \n" + "vpavgw %%ymm5,%%ymm0,%%ymm0 \n" + "vpavgw %%ymm5,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width) // %2 - ::"memory", - "cc", "xmm0", "xmm1", "xmm4", "xmm5"); + : + : "memory", "cc", "xmm0", "xmm1", "xmm4", "xmm5"); } void ScaleRowDown2Box_AVX2(const uint8_t* src_ptr, @@ -258,125 +266,390 @@ void ScaleRowDown2Box_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) { asm volatile( - "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" - "vpsrlw $0xf,%%ymm4,%%ymm4 \n" - "vpackuswb %%ymm4,%%ymm4,%%ymm4 \n" - "vpxor %%ymm5,%%ymm5,%%ymm5 \n" + "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" + "vpabsb %%ymm4,%%ymm4 \n" + "vpxor %%ymm5,%%ymm5,%%ymm5 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vmovdqu 0x00(%0,%3,1),%%ymm2 \n" - "vmovdqu 0x20(%0,%3,1),%%ymm3 \n" - "lea 0x40(%0),%0 \n" - "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" - "vpmaddubsw %%ymm4,%%ymm1,%%ymm1 \n" - "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" - "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" - "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" - "vpaddw %%ymm3,%%ymm1,%%ymm1 \n" - "vpsrlw $0x1,%%ymm0,%%ymm0 \n" - "vpsrlw $0x1,%%ymm1,%%ymm1 \n" - "vpavgw %%ymm5,%%ymm0,%%ymm0 \n" - "vpavgw %%ymm5,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vmovdqu %%ymm0,(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(dst_width) // %2 - : "r"((intptr_t)(src_stride)) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu 0x00(%0,%3,1),%%ymm2 \n" + "vmovdqu 0x20(%0,%3,1),%%ymm3 \n" + "lea 0x40(%0),%0 \n" + "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" + "vpmaddubsw %%ymm4,%%ymm1,%%ymm1 \n" + "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" + "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm3,%%ymm1,%%ymm1 \n" + "vpsrlw $0x1,%%ymm0,%%ymm0 \n" + "vpsrlw $0x1,%%ymm1,%%ymm1 \n" + "vpavgw %%ymm5,%%ymm0,%%ymm0 \n" + "vpavgw %%ymm5,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); } #endif // HAS_SCALEROWDOWN2_AVX2 +#ifdef HAS_SCALEROWDOWN2_16_AVX2 +void ScaleRowDown2_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width) { + (void)src_stride; + asm volatile( + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpsrld $0x10,%%ymm0,%%ymm0 \n" + "vpsrld $0x10,%%ymm1,%%ymm1 \n" + "vpackusdw %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "xmm0", "xmm1"); +} + +void ScaleRowDown2Linear_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width) { + (void)src_stride; + asm volatile( + "vpcmpeqd %%ymm4,%%ymm4,%%ymm4 \n" + "vpsrld $0x10,%%ymm4,%%ymm4 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpsrld $0x10,%%ymm0,%%ymm2 \n" + "vpsrld $0x10,%%ymm1,%%ymm3 \n" + "vpand %%ymm4,%%ymm0,%%ymm0 \n" + "vpand %%ymm4,%%ymm1,%%ymm1 \n" + "vpackusdw %%ymm1,%%ymm0,%%ymm0 \n" + "vpackusdw %%ymm3,%%ymm2,%%ymm2 \n" + "vpavgw %%ymm2,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} + +void ScaleRowDown2Box_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width) { + asm volatile( + "vpcmpeqd %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrld $0x1f,%%ymm6,%%ymm7 \n" + "vpslld $0x1,%%ymm7,%%ymm7 \n" + "vpsrld $0x10,%%ymm6,%%ymm6 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu 0x00(%0,%3,2),%%ymm2 \n" + "vmovdqu 0x20(%0,%3,2),%%ymm3 \n" + "lea 0x40(%0),%0 \n" + "vpsrld $0x10,%%ymm0,%%ymm4 \n" + "vpand %%ymm6,%%ymm0,%%ymm0 \n" + "vpaddd %%ymm4,%%ymm0,%%ymm0 \n" + "vpsrld $0x10,%%ymm2,%%ymm4 \n" + "vpand %%ymm6,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm4,%%ymm2,%%ymm2 \n" + "vpaddd %%ymm2,%%ymm0,%%ymm0 \n" + "vpsrld $0x10,%%ymm1,%%ymm4 \n" + "vpand %%ymm6,%%ymm1,%%ymm1 \n" + "vpaddd %%ymm4,%%ymm1,%%ymm1 \n" + "vpsrld $0x10,%%ymm3,%%ymm4 \n" + "vpand %%ymm6,%%ymm3,%%ymm3 \n" + "vpaddd %%ymm4,%%ymm3,%%ymm3 \n" + "vpaddd %%ymm3,%%ymm1,%%ymm1 \n" + "vpaddd %%ymm7,%%ymm0,%%ymm0 \n" + "vpaddd %%ymm7,%%ymm1,%%ymm1 \n" + "vpsrld $0x2,%%ymm0,%%ymm0 \n" + "vpsrld $0x2,%%ymm1,%%ymm1 \n" + "vpackusdw %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm6", "xmm7"); +} +#endif // HAS_SCALEROWDOWN2_16_AVX2 + +#ifdef HAS_SCALEROWDOWN2_AVX512BW +LIBYUV_TARGET_AVX512BW +void ScaleRowDown2_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + uintptr_t temp; + asm volatile( + "sub $0x20,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%0),%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpmovwb %%zmm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "mov $-1,%k3 \n" + "bzhi %k2,%k3,%k3 \n" + "kmovd %k3,%%k1 \n" + "vmovdqu16 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpsrlw $0x8,%%zmm0,%%zmm0 \n" + "vpmovwb %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width), // %2 + "=&r"(temp) // %3 + : + : "memory", "cc", "xmm0", "k1"); +} + +LIBYUV_TARGET_AVX512BW +void ScaleRowDown2Linear_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + uintptr_t temp; + asm volatile( + "vpternlogd $0xff,%%zmm4,%%zmm4,%%zmm4 \n" + "vpabsb %%zmm4,%%zmm4 \n" + "vpxord %%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%0),%%zmm0 \n" + "lea 0x40(%0),%0 \n" + "vpmaddubsw %%zmm4,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm5,%%zmm0,%%zmm0 \n" + "vpmovwb %%zmm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "mov $-1,%k3 \n" + "bzhi %k2,%k3,%k3 \n" + "kmovd %k3,%%k1 \n" + "vmovdqu16 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpmaddubsw %%zmm4,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm5,%%zmm0,%%zmm0 \n" + "vpmovwb %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width), // %2 + "=&r"(temp) // %3 + : + : "memory", "cc", "xmm0", "xmm4", "xmm5", "k1"); +} + +LIBYUV_TARGET_AVX512BW +void ScaleRowDown2Box_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + uintptr_t temp; + asm volatile( + "vpternlogd $0xff,%%zmm4,%%zmm4,%%zmm4 \n" + "vpabsb %%zmm4,%%zmm4 \n" + "vpxord %%zmm5,%%zmm5,%%zmm5 \n" + "sub $0x20,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu8 (%0),%%zmm0 \n" + "vmovdqu8 0x00(%0,%4,1),%%zmm2 \n" + "lea 0x40(%0),%0 \n" + "vpmaddubsw %%zmm4,%%zmm0,%%zmm0 \n" + "vpmaddubsw %%zmm4,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm2,%%zmm0,%%zmm0 \n" + "vpsrlw $0x1,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm5,%%zmm0,%%zmm0 \n" + "vpmovwb %%zmm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x20,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "mov $-1,%k3 \n" + "bzhi %k2,%k3,%k3 \n" + "kmovd %k3,%%k1 \n" + "vmovdqu16 (%0),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 0x00(%0,%4,1),%%zmm2%{%%k1%}%{z%}\n" + "vpmaddubsw %%zmm4,%%zmm0,%%zmm0 \n" + "vpmaddubsw %%zmm4,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm2,%%zmm0,%%zmm0 \n" + "vpsrlw $0x1,%%zmm0,%%zmm0 \n" + "vpavgw %%zmm5,%%zmm0,%%zmm0 \n" + "vpmovwb %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width), // %2 + "=&r"(temp) // %3 + : "r"(src_stride) // %4 + : "memory", "cc", "xmm0", "xmm2", "xmm4", "xmm5", "k1"); +} + +void ScaleRowDown2Box_Odd_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + dst_width -= 1; + if (dst_width > 0) { + ScaleRowDown2Box_AVX512BW(src_ptr, src_stride, dst_ptr, dst_width); + src_ptr += dst_width * 2; + dst_ptr += dst_width; + } + dst_ptr[0] = (src_ptr[0] + src_ptr[src_stride] + 1) >> 1; +} +#endif // HAS_SCALEROWDOWN2_AVX512BW + void ScaleRowDown4_SSSE3(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width) { (void)src_stride; asm volatile( - "pcmpeqb %%xmm5,%%xmm5 \n" - "psrld $0x18,%%xmm5 \n" - "pslld $0x10,%%xmm5 \n" + "pcmpeqb %%xmm5,%%xmm5 \n" + "psrld $0x18,%%xmm5 \n" + "pslld $0x10,%%xmm5 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "pand %%xmm5,%%xmm0 \n" - "pand %%xmm5,%%xmm1 \n" - "packuswb %%xmm1,%%xmm0 \n" - "psrlw $0x8,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "movq %%xmm0,(%1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x8,%2 \n" - "jg 1b \n" + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "lea 0x20(%0),%0 \n" + "pand %%xmm5,%%xmm0 \n" + "pand %%xmm5,%%xmm1 \n" + "packuswb %%xmm1,%%xmm0 \n" + "psrlw $0x8,%%xmm0 \n" + "packuswb %%xmm0,%%xmm0 \n" + "movq %%xmm0,(%1) \n" + "lea 0x8(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width) // %2 - ::"memory", - "cc", "xmm0", "xmm1", "xmm5"); + : + : "memory", "cc", "xmm0", "xmm1", "xmm5"); } void ScaleRowDown4Box_SSSE3(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width) { - intptr_t stridex3; + ptrdiff_t stridex3; asm volatile( - "pcmpeqb %%xmm4,%%xmm4 \n" - "psrlw $0xf,%%xmm4 \n" - "movdqa %%xmm4,%%xmm5 \n" - "packuswb %%xmm4,%%xmm4 \n" - "psllw $0x3,%%xmm5 \n" - "lea 0x00(%4,%4,2),%3 \n" + "pcmpeqb %%xmm4,%%xmm4 \n" + "pabsw %%xmm4,%%xmm5 \n" + "pabsb %%xmm4,%%xmm4 \n" // 0x0101 + "psllw $0x3,%%xmm5 \n" // 0x0008 + "lea 0x00(%4,%4,2),%3 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x00(%0,%4,1),%%xmm2 \n" - "movdqu 0x10(%0,%4,1),%%xmm3 \n" - "pmaddubsw %%xmm4,%%xmm0 \n" - "pmaddubsw %%xmm4,%%xmm1 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm4,%%xmm3 \n" - "paddw %%xmm2,%%xmm0 \n" - "paddw %%xmm3,%%xmm1 \n" - "movdqu 0x00(%0,%4,2),%%xmm2 \n" - "movdqu 0x10(%0,%4,2),%%xmm3 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm4,%%xmm3 \n" - "paddw %%xmm2,%%xmm0 \n" - "paddw %%xmm3,%%xmm1 \n" - "movdqu 0x00(%0,%3,1),%%xmm2 \n" - "movdqu 0x10(%0,%3,1),%%xmm3 \n" - "lea 0x20(%0),%0 \n" - "pmaddubsw %%xmm4,%%xmm2 \n" - "pmaddubsw %%xmm4,%%xmm3 \n" - "paddw %%xmm2,%%xmm0 \n" - "paddw %%xmm3,%%xmm1 \n" - "phaddw %%xmm1,%%xmm0 \n" - "paddw %%xmm5,%%xmm0 \n" - "psrlw $0x4,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "movq %%xmm0,(%1) \n" - "lea 0x8(%1),%1 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(dst_width), // %2 - "=&r"(stridex3) // %3 - : "r"((intptr_t)(src_stride)) // %4 + "1: \n" + "movdqu (%0),%%xmm0 \n" + "movdqu 0x10(%0),%%xmm1 \n" + "movdqu 0x00(%0,%4,1),%%xmm2 \n" + "movdqu 0x10(%0,%4,1),%%xmm3 \n" + "pmaddubsw %%xmm4,%%xmm0 \n" + "pmaddubsw %%xmm4,%%xmm1 \n" + "pmaddubsw %%xmm4,%%xmm2 \n" + "pmaddubsw %%xmm4,%%xmm3 \n" + "paddw %%xmm2,%%xmm0 \n" + "paddw %%xmm3,%%xmm1 \n" + "movdqu 0x00(%0,%4,2),%%xmm2 \n" + "movdqu 0x10(%0,%4,2),%%xmm3 \n" + "pmaddubsw %%xmm4,%%xmm2 \n" + "pmaddubsw %%xmm4,%%xmm3 \n" + "paddw %%xmm2,%%xmm0 \n" + "paddw %%xmm3,%%xmm1 \n" + "movdqu 0x00(%0,%3,1),%%xmm2 \n" + "movdqu 0x10(%0,%3,1),%%xmm3 \n" + "lea 0x20(%0),%0 \n" + "pmaddubsw %%xmm4,%%xmm2 \n" + "pmaddubsw %%xmm4,%%xmm3 \n" + "paddw %%xmm2,%%xmm0 \n" + "paddw %%xmm3,%%xmm1 \n" + "phaddw %%xmm1,%%xmm0 \n" + "paddw %%xmm5,%%xmm0 \n" + "psrlw $0x4,%%xmm0 \n" + "packuswb %%xmm0,%%xmm0 \n" + "movq %%xmm0,(%1) \n" + "lea 0x8(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width), // %2 + "=&r"(stridex3) // %3 + : "r"(src_stride) // %4 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); } @@ -387,32 +660,32 @@ void ScaleRowDown4_AVX2(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" - "vpsrld $0x18,%%ymm5,%%ymm5 \n" - "vpslld $0x10,%%ymm5,%%ymm5 \n" + "vpcmpeqb %%ymm5,%%ymm5,%%ymm5 \n" + "vpsrld $0x18,%%ymm5,%%ymm5 \n" + "vpslld $0x10,%%ymm5,%%ymm5 \n" LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "lea 0x40(%0),%0 \n" - "vpand %%ymm5,%%ymm0,%%ymm0 \n" - "vpand %%ymm5,%%ymm1,%%ymm1 \n" - "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vpsrlw $0x8,%%ymm0,%%ymm0 \n" - "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vmovdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - "vzeroupper \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpand %%ymm5,%%ymm0,%%ymm0 \n" + "vpand %%ymm5,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpsrlw $0x8,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width) // %2 - ::"memory", - "cc", "xmm0", "xmm1", "xmm5"); + : + : "memory", "cc", "xmm0", "xmm1", "xmm5"); } void ScaleRowDown4Box_AVX2(const uint8_t* src_ptr, @@ -420,401 +693,1482 @@ void ScaleRowDown4Box_AVX2(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) { asm volatile( - "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" - "vpsrlw $0xf,%%ymm4,%%ymm4 \n" - "vpsllw $0x3,%%ymm4,%%ymm5 \n" - "vpackuswb %%ymm4,%%ymm4,%%ymm4 \n" + "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" + "vpabsw %%ymm4,%%ymm5 \n" + "vpabsb %%ymm4,%%ymm4 \n" // 0x0101 + "vpsllw $0x3,%%ymm5,%%ymm5 \n" // 0x0008 LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm0 \n" - "vmovdqu 0x20(%0),%%ymm1 \n" - "vmovdqu 0x00(%0,%3,1),%%ymm2 \n" - "vmovdqu 0x20(%0,%3,1),%%ymm3 \n" - "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" - "vpmaddubsw %%ymm4,%%ymm1,%%ymm1 \n" - "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" - "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" - "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" - "vpaddw %%ymm3,%%ymm1,%%ymm1 \n" - "vmovdqu 0x00(%0,%3,2),%%ymm2 \n" - "vmovdqu 0x20(%0,%3,2),%%ymm3 \n" - "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" - "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" - "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" - "vpaddw %%ymm3,%%ymm1,%%ymm1 \n" - "vmovdqu 0x00(%0,%4,1),%%ymm2 \n" - "vmovdqu 0x20(%0,%4,1),%%ymm3 \n" - "lea 0x40(%0),%0 \n" - "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" - "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" - "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" - "vpaddw %%ymm3,%%ymm1,%%ymm1 \n" - "vphaddw %%ymm1,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vpaddw %%ymm5,%%ymm0,%%ymm0 \n" - "vpsrlw $0x4,%%ymm0,%%ymm0 \n" - "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" - "vpermq $0xd8,%%ymm0,%%ymm0 \n" - "vmovdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(dst_width) // %2 - : "r"((intptr_t)(src_stride)), // %3 - "r"((intptr_t)(src_stride * 3)) // %4 + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu 0x00(%0,%3,1),%%ymm2 \n" + "vmovdqu 0x20(%0,%3,1),%%ymm3 \n" + "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" + "vpmaddubsw %%ymm4,%%ymm1,%%ymm1 \n" + "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" + "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm3,%%ymm1,%%ymm1 \n" + "vmovdqu 0x00(%0,%3,2),%%ymm2 \n" + "vmovdqu 0x20(%0,%3,2),%%ymm3 \n" + "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" + "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm3,%%ymm1,%%ymm1 \n" + "vmovdqu 0x00(%0,%4,1),%%ymm2 \n" + "vmovdqu 0x20(%0,%4,1),%%ymm3 \n" + "lea 0x40(%0),%0 \n" + "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm4,%%ymm3,%%ymm3 \n" + "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm3,%%ymm1,%%ymm1 \n" + "vphaddw %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpaddw %%ymm5,%%ymm0,%%ymm0 \n" + "vpsrlw $0x4,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(src_stride * 3) // %4 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); } #endif // HAS_SCALEROWDOWN4_AVX2 -void ScaleRowDown34_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { +#ifdef HAS_SCALEROWDOWN34_AVX2 +void ScaleRowDown34_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { (void)src_stride; asm volatile( - "movdqa %0,%%xmm3 \n" - "movdqa %1,%%xmm4 \n" - "movdqa %2,%%xmm5 \n" - : - : "m"(kShuf0), // %0 - "m"(kShuf1), // %1 - "m"(kShuf2) // %2 - ); - asm volatile( + "vbroadcasti128 %[kShuf0],%%ymm3 \n" + "vbroadcasti128 %[kShuf1],%%ymm4 \n" + "vbroadcasti128 %[kShuf2],%%ymm5 \n" + "sub $0x30,%[dst_width] \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm2 \n" - "lea 0x20(%0),%0 \n" - "movdqa %%xmm2,%%xmm1 \n" - "palignr $0x8,%%xmm0,%%xmm1 \n" - "pshufb %%xmm3,%%xmm0 \n" - "pshufb %%xmm4,%%xmm1 \n" - "pshufb %%xmm5,%%xmm2 \n" - "movq %%xmm0,(%1) \n" - "movq %%xmm1,0x8(%1) \n" - "movq %%xmm2,0x10(%1) \n" - "lea 0x18(%1),%1 \n" - "sub $0x18,%2 \n" - "jg 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(dst_width) // %2 - ::"memory", - "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); + "1: \n" + "vmovdqu (%[src_ptr]),%%ymm0 \n" + "vmovdqu 0x20(%[src_ptr]),%%ymm1 \n" + "lea 0x40(%[src_ptr]),%[src_ptr] \n" + "vperm2i128 $0x20,%%ymm1,%%ymm0,%%ymm2 \n" + "vperm2i128 $0x31,%%ymm1,%%ymm0,%%ymm6 \n" + "vpalignr $0x8,%%ymm2,%%ymm6,%%ymm1 \n" + "vpshufb %%ymm3,%%ymm2,%%ymm0 \n" + "vpshufb %%ymm4,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm5,%%ymm6,%%ymm2 \n" + "vpunpcklqdq %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%xmm0,(%[dst_ptr]) \n" + "vmovq %%xmm2,0x10(%[dst_ptr]) \n" + "vextracti128 $0x1,%%ymm0,%%xmm0 \n" + "vextracti128 $0x1,%%ymm2,%%xmm2 \n" + "vmovdqu %%xmm0,0x18(%[dst_ptr]) \n" + "vmovq %%xmm2,0x28(%[dst_ptr]) \n" + "lea 0x30(%[dst_ptr]),%[dst_ptr] \n" + "sub $0x30,%[dst_width] \n" + "jge 1b \n" + + "2: \n" + "add $0x30,%[dst_width] \n" + "jle 99f \n" + "vmovdqu (%[src_ptr]),%%ymm0 \n" + "vextracti128 $0x1,%%ymm0,%%xmm2 \n" + "vpalignr $0x8,%%xmm0,%%xmm2,%%xmm1 \n" + "vpshufb %%xmm3,%%xmm0,%%xmm0 \n" + "vpshufb %%xmm4,%%xmm1,%%xmm1 \n" + "vpshufb %%xmm5,%%xmm2,%%xmm2 \n" + "vpunpcklqdq %%xmm1,%%xmm0,%%xmm0 \n" + "vmovdqu %%xmm0,(%[dst_ptr]) \n" + "vmovq %%xmm2,0x10(%[dst_ptr]) \n" + + "99: \n" + "vzeroupper \n" + : [src_ptr] "+r"(src_ptr), [dst_ptr] "+r"(dst_ptr), + [dst_width] "+r"(dst_width) + : [kShuf0] "m"(kShuf0), [kShuf1] "m"(kShuf1), [kShuf2] "m"(kShuf2) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); } -void ScaleRowDown34_1_Box_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - asm volatile( - "movdqa %0,%%xmm2 \n" // kShuf01 - "movdqa %1,%%xmm3 \n" // kShuf11 - "movdqa %2,%%xmm4 \n" // kShuf21 - : - : "m"(kShuf01), // %0 - "m"(kShuf11), // %1 - "m"(kShuf21) // %2 - ); - asm volatile( - "movdqa %0,%%xmm5 \n" // kMadd01 - "movdqa %1,%%xmm0 \n" // kMadd11 - "movdqa %2,%%xmm1 \n" // kRound34 - : - : "m"(kMadd01), // %0 - "m"(kMadd11), // %1 - "m"(kRound34) // %2 - ); +void ScaleRowDown34_1_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { asm volatile( + "vbroadcasti128 %[kRound34],%%ymm5 \n" + "sub $0x30,%[dst_width] \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm6 \n" - "movdqu 0x00(%0,%3,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm6 \n" - "pshufb %%xmm2,%%xmm6 \n" - "pmaddubsw %%xmm5,%%xmm6 \n" - "paddsw %%xmm1,%%xmm6 \n" - "psrlw $0x2,%%xmm6 \n" - "packuswb %%xmm6,%%xmm6 \n" - "movq %%xmm6,(%1) \n" - "movdqu 0x8(%0),%%xmm6 \n" - "movdqu 0x8(%0,%3,1),%%xmm7 \n" - "pavgb %%xmm7,%%xmm6 \n" - "pshufb %%xmm3,%%xmm6 \n" - "pmaddubsw %%xmm0,%%xmm6 \n" - "paddsw %%xmm1,%%xmm6 \n" - "psrlw $0x2,%%xmm6 \n" - "packuswb %%xmm6,%%xmm6 \n" - "movq %%xmm6,0x8(%1) \n" - "movdqu 0x10(%0),%%xmm6 \n" - "movdqu 0x10(%0,%3,1),%%xmm7 \n" - "lea 0x20(%0),%0 \n" - "pavgb %%xmm7,%%xmm6 \n" - "pshufb %%xmm4,%%xmm6 \n" - "pmaddubsw %4,%%xmm6 \n" - "paddsw %%xmm1,%%xmm6 \n" - "psrlw $0x2,%%xmm6 \n" - "packuswb %%xmm6,%%xmm6 \n" - "movq %%xmm6,0x10(%1) \n" - "lea 0x18(%1),%1 \n" - "sub $0x18,%2 \n" - "jg 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(dst_width) // %2 - : "r"((intptr_t)(src_stride)), // %3 - "m"(kMadd21) // %4 + "1: \n" + "vmovdqu (%[src_ptr]),%%ymm0 \n" + "vmovdqu 0x00(%[src_ptr],%[src_stride],1),%%ymm2 \n" + "vpavgb %%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu 0x20(%[src_ptr]),%%ymm1 \n" + "vmovdqu 0x20(%[src_ptr],%[src_stride],1),%%ymm3 \n" + "lea 0x40(%[src_ptr]),%[src_ptr] \n" + "vpavgb %%ymm3,%%ymm1,%%ymm1 \n" + "vperm2i128 $0x20,%%ymm1,%%ymm0,%%ymm2 \n" + "vperm2i128 $0x31,%%ymm1,%%ymm0,%%ymm3 \n" + "vpalignr $0x8,%%ymm2,%%ymm3,%%ymm4 \n" + + "vbroadcasti128 %[kShuf01],%%ymm6 \n" + "vbroadcasti128 %[kMadd01],%%ymm7 \n" + "vpshufb %%ymm6,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm7,%%ymm2,%%ymm2 \n" + "vpaddsw %%ymm5,%%ymm2,%%ymm2 \n" + "vpsrlw $0x2,%%ymm2,%%ymm2 \n" + "vpackuswb %%ymm2,%%ymm2,%%ymm2 \n" + + "vbroadcasti128 %[kShuf11],%%ymm6 \n" + "vbroadcasti128 %[kMadd11],%%ymm7 \n" + "vpshufb %%ymm6,%%ymm4,%%ymm4 \n" + "vpmaddubsw %%ymm7,%%ymm4,%%ymm4 \n" + "vpaddsw %%ymm5,%%ymm4,%%ymm4 \n" + "vpsrlw $0x2,%%ymm4,%%ymm4 \n" + "vpackuswb %%ymm4,%%ymm4,%%ymm4 \n" + + "vbroadcasti128 %[kShuf21],%%ymm6 \n" + "vbroadcasti128 %[kMadd21],%%ymm7 \n" + "vpshufb %%ymm6,%%ymm3,%%ymm3 \n" + "vpmaddubsw %%ymm7,%%ymm3,%%ymm3 \n" + "vpaddsw %%ymm5,%%ymm3,%%ymm3 \n" + "vpsrlw $0x2,%%ymm3,%%ymm3 \n" + "vpackuswb %%ymm3,%%ymm3,%%ymm3 \n" + + "vpunpcklqdq %%ymm4,%%ymm2,%%ymm2 \n" + "vmovdqu %%xmm2,(%[dst_ptr]) \n" + "vmovq %%xmm3,0x10(%[dst_ptr]) \n" + "vextracti128 $0x1,%%ymm2,%%xmm0 \n" + "vextracti128 $0x1,%%ymm3,%%xmm1 \n" + "vmovdqu %%xmm0,0x18(%[dst_ptr]) \n" + "vmovq %%xmm1,0x28(%[dst_ptr]) \n" + "lea 0x30(%[dst_ptr]),%[dst_ptr] \n" + "sub $0x30,%[dst_width] \n" + "jge 1b \n" + + "2: \n" + "add $0x30,%[dst_width] \n" + "jle 99f \n" + "vmovdqu (%[src_ptr]),%%ymm0 \n" + "vmovdqu 0x00(%[src_ptr],%[src_stride],1),%%ymm1 \n" + "vpavgb %%ymm1,%%ymm0,%%ymm0 \n" + "vextracti128 $0x1,%%ymm0,%%xmm3 \n" + "vpalignr $0x8,%%xmm0,%%xmm3,%%xmm4 \n" + + "vpshufb %[kShuf01],%%xmm0,%%xmm0 \n" + "vpmaddubsw %[kMadd01],%%xmm0,%%xmm0 \n" + "vpaddsw %%xmm5,%%xmm0,%%xmm0 \n" + "vpsrlw $0x2,%%xmm0,%%xmm0 \n" + "vpackuswb %%xmm0,%%xmm0,%%xmm0 \n" + + "vpshufb %[kShuf11],%%xmm4,%%xmm4 \n" + "vpmaddubsw %[kMadd11],%%xmm4,%%xmm4 \n" + "vpaddsw %%xmm5,%%xmm4,%%xmm4 \n" + "vpsrlw $0x2,%%xmm4,%%xmm4 \n" + "vpackuswb %%xmm4,%%xmm4,%%xmm4 \n" + + "vpshufb %[kShuf21],%%xmm3,%%xmm3 \n" + "vpmaddubsw %[kMadd21],%%xmm3,%%xmm3 \n" + "vpaddsw %%xmm5,%%xmm3,%%xmm3 \n" + "vpsrlw $0x2,%%xmm3,%%xmm3 \n" + "vpackuswb %%xmm3,%%xmm3,%%xmm3 \n" + + "vpunpcklqdq %%xmm4,%%xmm0,%%xmm0 \n" + "vmovdqu %%xmm0,(%[dst_ptr]) \n" + "vmovq %%xmm3,0x10(%[dst_ptr]) \n" + + "99: \n" + "vzeroupper \n" + : [src_ptr] "+r"(src_ptr), [dst_ptr] "+r"(dst_ptr), + [dst_width] "+rm"(dst_width) + : [src_stride] "r"(src_stride), [kShuf01] "m"(kShuf01), + [kShuf11] "m"(kShuf11), [kShuf21] "m"(kShuf21), [kMadd01] "m"(kMadd01), + [kMadd11] "m"(kMadd11), [kRound34] "m"(kRound34), [kMadd21] "m"(kMadd21) : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); } -void ScaleRowDown34_0_Box_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - asm volatile( - "movdqa %0,%%xmm2 \n" // kShuf01 - "movdqa %1,%%xmm3 \n" // kShuf11 - "movdqa %2,%%xmm4 \n" // kShuf21 - : - : "m"(kShuf01), // %0 - "m"(kShuf11), // %1 - "m"(kShuf21) // %2 - ); - asm volatile( - "movdqa %0,%%xmm5 \n" // kMadd01 - "movdqa %1,%%xmm0 \n" // kMadd11 - "movdqa %2,%%xmm1 \n" // kRound34 - : - : "m"(kMadd01), // %0 - "m"(kMadd11), // %1 - "m"(kRound34) // %2 - ); - +void ScaleRowDown34_0_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { asm volatile( + "vbroadcasti128 %[kRound34],%%ymm5 \n" + "sub $0x30,%[dst_width] \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm6 \n" - "movdqu 0x00(%0,%3,1),%%xmm7 \n" - "pavgb %%xmm6,%%xmm7 \n" - "pavgb %%xmm7,%%xmm6 \n" - "pshufb %%xmm2,%%xmm6 \n" - "pmaddubsw %%xmm5,%%xmm6 \n" - "paddsw %%xmm1,%%xmm6 \n" - "psrlw $0x2,%%xmm6 \n" - "packuswb %%xmm6,%%xmm6 \n" - "movq %%xmm6,(%1) \n" - "movdqu 0x8(%0),%%xmm6 \n" - "movdqu 0x8(%0,%3,1),%%xmm7 \n" - "pavgb %%xmm6,%%xmm7 \n" - "pavgb %%xmm7,%%xmm6 \n" - "pshufb %%xmm3,%%xmm6 \n" - "pmaddubsw %%xmm0,%%xmm6 \n" - "paddsw %%xmm1,%%xmm6 \n" - "psrlw $0x2,%%xmm6 \n" - "packuswb %%xmm6,%%xmm6 \n" - "movq %%xmm6,0x8(%1) \n" - "movdqu 0x10(%0),%%xmm6 \n" - "movdqu 0x10(%0,%3,1),%%xmm7 \n" - "lea 0x20(%0),%0 \n" - "pavgb %%xmm6,%%xmm7 \n" - "pavgb %%xmm7,%%xmm6 \n" - "pshufb %%xmm4,%%xmm6 \n" - "pmaddubsw %4,%%xmm6 \n" - "paddsw %%xmm1,%%xmm6 \n" - "psrlw $0x2,%%xmm6 \n" - "packuswb %%xmm6,%%xmm6 \n" - "movq %%xmm6,0x10(%1) \n" - "lea 0x18(%1),%1 \n" - "sub $0x18,%2 \n" - "jg 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(dst_width) // %2 - : "r"((intptr_t)(src_stride)), // %3 - "m"(kMadd21) // %4 + "1: \n" + "vmovdqu (%[src_ptr]),%%ymm0 \n" + "vmovdqu 0x00(%[src_ptr],%[src_stride],1),%%ymm2 \n" + "vpavgb %%ymm0,%%ymm2,%%ymm2 \n" + "vpavgb %%ymm2,%%ymm0,%%ymm0 \n" + "vmovdqu 0x20(%[src_ptr]),%%ymm1 \n" + "vmovdqu 0x20(%[src_ptr],%[src_stride],1),%%ymm3 \n" + "lea 0x40(%[src_ptr]),%[src_ptr] \n" + "vpavgb %%ymm1,%%ymm3,%%ymm3 \n" + "vpavgb %%ymm3,%%ymm1,%%ymm1 \n" + "vperm2i128 $0x20,%%ymm1,%%ymm0,%%ymm2 \n" + "vperm2i128 $0x31,%%ymm1,%%ymm0,%%ymm3 \n" + "vpalignr $0x8,%%ymm2,%%ymm3,%%ymm4 \n" + + "vbroadcasti128 %[kShuf01],%%ymm6 \n" + "vbroadcasti128 %[kMadd01],%%ymm7 \n" + "vpshufb %%ymm6,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm7,%%ymm2,%%ymm2 \n" + "vpaddsw %%ymm5,%%ymm2,%%ymm2 \n" + "vpsrlw $0x2,%%ymm2,%%ymm2 \n" + "vpackuswb %%ymm2,%%ymm2,%%ymm2 \n" + + "vbroadcasti128 %[kShuf11],%%ymm6 \n" + "vbroadcasti128 %[kMadd11],%%ymm7 \n" + "vpshufb %%ymm6,%%ymm4,%%ymm4 \n" + "vpmaddubsw %%ymm7,%%ymm4,%%ymm4 \n" + "vpaddsw %%ymm5,%%ymm4,%%ymm4 \n" + "vpsrlw $0x2,%%ymm4,%%ymm4 \n" + "vpackuswb %%ymm4,%%ymm4,%%ymm4 \n" + + "vbroadcasti128 %[kShuf21],%%ymm6 \n" + "vbroadcasti128 %[kMadd21],%%ymm7 \n" + "vpshufb %%ymm6,%%ymm3,%%ymm3 \n" + "vpmaddubsw %%ymm7,%%ymm3,%%ymm3 \n" + "vpaddsw %%ymm5,%%ymm3,%%ymm3 \n" + "vpsrlw $0x2,%%ymm3,%%ymm3 \n" + "vpackuswb %%ymm3,%%ymm3,%%ymm3 \n" + + "vpunpcklqdq %%ymm4,%%ymm2,%%ymm2 \n" + "vmovdqu %%xmm2,(%[dst_ptr]) \n" + "vmovq %%xmm3,0x10(%[dst_ptr]) \n" + "vextracti128 $0x1,%%ymm2,%%xmm0 \n" + "vextracti128 $0x1,%%ymm3,%%xmm1 \n" + "vmovdqu %%xmm0,0x18(%[dst_ptr]) \n" + "vmovq %%xmm1,0x28(%[dst_ptr]) \n" + "lea 0x30(%[dst_ptr]),%[dst_ptr] \n" + "sub $0x30,%[dst_width] \n" + "jge 1b \n" + + "2: \n" + "add $0x30,%[dst_width] \n" + "jle 99f \n" + "vmovdqu (%[src_ptr]),%%ymm0 \n" + "vmovdqu 0x00(%[src_ptr],%[src_stride],1),%%ymm1 \n" + "vpavgb %%ymm0,%%ymm1,%%ymm1 \n" + "vpavgb %%ymm1,%%ymm0,%%ymm0 \n" + "vextracti128 $0x1,%%ymm0,%%xmm3 \n" + "vpalignr $0x8,%%xmm0,%%xmm3,%%xmm4 \n" + + "vpshufb %[kShuf01],%%xmm0,%%xmm0 \n" + "vpmaddubsw %[kMadd01],%%xmm0,%%xmm0 \n" + "vpaddsw %%xmm5,%%xmm0,%%xmm0 \n" + "vpsrlw $0x2,%%xmm0,%%xmm0 \n" + "vpackuswb %%xmm0,%%xmm0,%%xmm0 \n" + + "vpshufb %[kShuf11],%%xmm4,%%xmm4 \n" + "vpmaddubsw %[kMadd11],%%xmm4,%%xmm4 \n" + "vpaddsw %%xmm5,%%xmm4,%%xmm4 \n" + "vpsrlw $0x2,%%xmm4,%%xmm4 \n" + "vpackuswb %%xmm4,%%xmm4,%%xmm4 \n" + + "vpshufb %[kShuf21],%%xmm3,%%xmm3 \n" + "vpmaddubsw %[kMadd21],%%xmm3,%%xmm3 \n" + "vpaddsw %%xmm5,%%xmm3,%%xmm3 \n" + "vpsrlw $0x2,%%xmm3,%%xmm3 \n" + "vpackuswb %%xmm3,%%xmm3,%%xmm3 \n" + + "vpunpcklqdq %%xmm4,%%xmm0,%%xmm0 \n" + "vmovdqu %%xmm0,(%[dst_ptr]) \n" + "vmovq %%xmm3,0x10(%[dst_ptr]) \n" + + "99: \n" + "vzeroupper \n" + : [src_ptr] "+r"(src_ptr), [dst_ptr] "+r"(dst_ptr), + [dst_width] "+rm"(dst_width) + : [src_stride] "r"(src_stride), [kShuf01] "m"(kShuf01), + [kShuf11] "m"(kShuf11), [kShuf21] "m"(kShuf21), [kMadd01] "m"(kMadd01), + [kMadd11] "m"(kMadd11), [kRound34] "m"(kRound34), [kMadd21] "m"(kMadd21) : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); } +#endif // HAS_SCALEROWDOWN34_AVX2 -void ScaleRowDown38_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { +#ifdef HAS_SCALEROWDOWN38_AVX2 +void ScaleRowDown38_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { (void)src_stride; asm volatile( - "movdqa %3,%%xmm4 \n" - "movdqa %4,%%xmm5 \n" + "vmovdqu %3,%%xmm4 \n" + "vinserti128 $0x1,%4,%%ymm4,%%ymm4 \n" + "sub $0x18,%2 \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "pshufb %%xmm4,%%xmm0 \n" - "pshufb %%xmm5,%%xmm1 \n" - "paddusb %%xmm1,%%xmm0 \n" - "movq %%xmm0,(%1) \n" - "movhlps %%xmm0,%%xmm1 \n" - "movd %%xmm1,0x8(%1) \n" - "lea 0xc(%1),%1 \n" - "sub $0xc,%2 \n" - "jg 1b \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm4,%%ymm1,%%ymm1 \n" + "vextracti128 $0x1,%%ymm0,%%xmm2 \n" + "vextracti128 $0x1,%%ymm1,%%xmm3 \n" + "vpor %%xmm2,%%xmm0,%%xmm0 \n" + "vpor %%xmm3,%%xmm1,%%xmm1 \n" + "vmovq %%xmm0,(%1) \n" + "vpsrldq $0x8,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,0x8(%1) \n" + "vmovq %%xmm1,0xc(%1) \n" + "vpsrldq $0x8,%%xmm1,%%xmm1 \n" + "vmovd %%xmm1,0x14(%1) \n" + "lea 0x18(%1),%1 \n" + "sub $0x18,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x18,%2 \n" + "jle 99f \n" + "vmovdqu (%0),%%ymm0 \n" + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" + "vextracti128 $0x1,%%ymm0,%%xmm2 \n" + "vpor %%xmm2,%%xmm0,%%xmm0 \n" + "vmovq %%xmm0,(%1) \n" + "vpsrldq $0x8,%%xmm0,%%xmm0 \n" + "vmovd %%xmm0,0x8(%1) \n" + + "99: \n" + "vzeroupper \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width) // %2 : "m"(kShuf38a), // %3 "m"(kShuf38b) // %4 - : "memory", "cc", "xmm0", "xmm1", "xmm4", "xmm5"); + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); } -void ScaleRowDown38_2_Box_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - asm volatile( - "movdqa %0,%%xmm2 \n" - "movdqa %1,%%xmm3 \n" - "movdqa %2,%%xmm4 \n" - "movdqa %3,%%xmm5 \n" - : - : "m"(kShufAb0), // %0 - "m"(kShufAb1), // %1 - "m"(kShufAb2), // %2 - "m"(kScaleAb2) // %3 - ); +void ScaleRowDown38_2_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { asm volatile( + "vbroadcasti128 %[kShufAb0],%%ymm2 \n" + "vbroadcasti128 %[kShufAb1],%%ymm3 \n" + "vbroadcasti128 %[kShufAb2],%%ymm4 \n" + "vbroadcasti128 %[kScaleAb2],%%ymm5 \n" + "vpxor %%ymm7,%%ymm7,%%ymm7 \n" LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x00(%0,%3,1),%%xmm1 \n" - "lea 0x10(%0),%0 \n" - "pavgb %%xmm1,%%xmm0 \n" - "movdqa %%xmm0,%%xmm1 \n" - "pshufb %%xmm2,%%xmm1 \n" - "movdqa %%xmm0,%%xmm6 \n" - "pshufb %%xmm3,%%xmm6 \n" - "paddusw %%xmm6,%%xmm1 \n" - "pshufb %%xmm4,%%xmm0 \n" - "paddusw %%xmm0,%%xmm1 \n" - "pmulhuw %%xmm5,%%xmm1 \n" - "packuswb %%xmm1,%%xmm1 \n" - "movd %%xmm1,(%1) \n" - "psrlq $0x10,%%xmm1 \n" - "movd %%xmm1,0x2(%1) \n" - "lea 0x6(%1),%1 \n" - "sub $0x6,%2 \n" - "jg 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(dst_width) // %2 - : "r"((intptr_t)(src_stride)) // %3 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); -} - -void ScaleRowDown38_3_Box_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - asm volatile( - "movdqa %0,%%xmm2 \n" - "movdqa %1,%%xmm3 \n" - "movdqa %2,%%xmm4 \n" - "pxor %%xmm5,%%xmm5 \n" - : - : "m"(kShufAc), // %0 - "m"(kShufAc3), // %1 - "m"(kScaleAc33) // %2 - ); - asm volatile( - - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x00(%0,%3,1),%%xmm6 \n" - "movhlps %%xmm0,%%xmm1 \n" - "movhlps %%xmm6,%%xmm7 \n" - "punpcklbw %%xmm5,%%xmm0 \n" - "punpcklbw %%xmm5,%%xmm1 \n" - "punpcklbw %%xmm5,%%xmm6 \n" - "punpcklbw %%xmm5,%%xmm7 \n" - "paddusw %%xmm6,%%xmm0 \n" - "paddusw %%xmm7,%%xmm1 \n" - "movdqu 0x00(%0,%3,2),%%xmm6 \n" - "lea 0x10(%0),%0 \n" - "movhlps %%xmm6,%%xmm7 \n" - "punpcklbw %%xmm5,%%xmm6 \n" - "punpcklbw %%xmm5,%%xmm7 \n" - "paddusw %%xmm6,%%xmm0 \n" - "paddusw %%xmm7,%%xmm1 \n" - "movdqa %%xmm0,%%xmm6 \n" - "psrldq $0x2,%%xmm0 \n" - "paddusw %%xmm0,%%xmm6 \n" - "psrldq $0x2,%%xmm0 \n" - "paddusw %%xmm0,%%xmm6 \n" - "pshufb %%xmm2,%%xmm6 \n" - "movdqa %%xmm1,%%xmm7 \n" - "psrldq $0x2,%%xmm1 \n" - "paddusw %%xmm1,%%xmm7 \n" - "psrldq $0x2,%%xmm1 \n" - "paddusw %%xmm1,%%xmm7 \n" - "pshufb %%xmm3,%%xmm7 \n" - "paddusw %%xmm7,%%xmm6 \n" - "pmulhuw %%xmm4,%%xmm6 \n" - "packuswb %%xmm6,%%xmm6 \n" - "movd %%xmm6,(%1) \n" - "psrlq $0x10,%%xmm6 \n" - "movd %%xmm6,0x2(%1) \n" - "lea 0x6(%1),%1 \n" - "sub $0x6,%2 \n" - "jg 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(dst_width) // %2 - : "r"((intptr_t)(src_stride)) // %3 + "1: \n" + "vmovdqu (%[src_ptr]),%%ymm0 \n" + "vmovdqu 0x00(%[src_ptr],%[src_stride],1),%%ymm1 \n" + "lea 0x20(%[src_ptr]),%[src_ptr] \n" + "vpavgb %%ymm1,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm2,%%ymm0,%%ymm1 \n" + "vpshufb %%ymm3,%%ymm0,%%ymm6 \n" + "vpaddusw %%ymm6,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" + "vpaddusw %%ymm0,%%ymm1,%%ymm1 \n" + "vpmulhuw %%ymm5,%%ymm1,%%ymm1 \n" + "vpackuswb %%ymm7,%%ymm1,%%ymm1 \n" + "vextracti128 $0x1,%%ymm1,%%xmm0 \n" + "vpslldq $0x6,%%xmm0,%%xmm0 \n" + "vpor %%xmm0,%%xmm1,%%xmm1 \n" + "vmovq %%xmm1,(%[dst_ptr]) \n" + "vpsrldq $0x8,%%xmm1,%%xmm1 \n" + "vmovd %%xmm1,0x8(%[dst_ptr]) \n" + "lea 0xc(%[dst_ptr]),%[dst_ptr] \n" + "sub $0xc,%[dst_width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src_ptr] "+r"(src_ptr), [dst_ptr] "+r"(dst_ptr), + [dst_width] "+rm"(dst_width) + : [src_stride] "r"(src_stride), [kShufAb0] "m"(kShufAb0), + [kShufAb1] "m"(kShufAb1), [kShufAb2] "m"(kShufAb2), + [kScaleAb2] "m"(kScaleAb2) : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); } +void ScaleRowDown38_3_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + asm volatile( + "vbroadcasti128 %[kShufAc],%%ymm2 \n" + "vbroadcasti128 %[kShufAc3],%%ymm3 \n" + "vbroadcasti128 %[kScaleAc33],%%ymm4 \n" + "vpxor %%ymm5,%%ymm5,%%ymm5 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[src_ptr]),%%ymm0 \n" + "vmovdqu 0x00(%[src_ptr],%[src_stride],1),%%ymm6 \n" + "vpunpckhbw %%ymm5,%%ymm0,%%ymm1 \n" + "vpunpcklbw %%ymm5,%%ymm0,%%ymm0 \n" + "vpunpckhbw %%ymm5,%%ymm6,%%ymm7 \n" + "vpunpcklbw %%ymm5,%%ymm6,%%ymm6 \n" + "vpaddusw %%ymm6,%%ymm0,%%ymm0 \n" + "vpaddusw %%ymm7,%%ymm1,%%ymm1 \n" + "vmovdqu 0x00(%[src_ptr],%[src_stride],2),%%ymm6 \n" + "lea 0x20(%[src_ptr]),%[src_ptr] \n" + "vpunpckhbw %%ymm5,%%ymm6,%%ymm7 \n" + "vpunpcklbw %%ymm5,%%ymm6,%%ymm6 \n" + "vpaddusw %%ymm6,%%ymm0,%%ymm0 \n" + "vpaddusw %%ymm7,%%ymm1,%%ymm1 \n" + "vpsrldq $0x2,%%ymm0,%%ymm6 \n" + "vpaddusw %%ymm0,%%ymm6,%%ymm6 \n" + "vpsrldq $0x4,%%ymm0,%%ymm0 \n" + "vpaddusw %%ymm0,%%ymm6,%%ymm6 \n" + "vpshufb %%ymm2,%%ymm6,%%ymm6 \n" + "vpsrldq $0x2,%%ymm1,%%ymm7 \n" + "vpaddusw %%ymm1,%%ymm7,%%ymm7 \n" + "vpsrldq $0x4,%%ymm1,%%ymm1 \n" + "vpaddusw %%ymm1,%%ymm7,%%ymm7 \n" + "vpshufb %%ymm3,%%ymm7,%%ymm7 \n" + "vpaddusw %%ymm7,%%ymm6,%%ymm6 \n" + "vpmulhuw %%ymm4,%%ymm6,%%ymm6 \n" + "vpackuswb %%ymm5,%%ymm6,%%ymm6 \n" + "vextracti128 $0x1,%%ymm6,%%xmm0 \n" + "vpslldq $0x6,%%xmm0,%%xmm0 \n" + "vpor %%xmm0,%%xmm6,%%xmm6 \n" + "vmovq %%xmm6,(%[dst_ptr]) \n" + "vpsrldq $0x8,%%xmm6,%%xmm6 \n" + "vmovd %%xmm6,0x8(%[dst_ptr]) \n" + "lea 0xc(%[dst_ptr]),%[dst_ptr] \n" + "sub $0xc,%[dst_width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src_ptr] "+r"(src_ptr), [dst_ptr] "+r"(dst_ptr), + [dst_width] "+rm"(dst_width) + : [src_stride] "r"(src_stride), [kShufAc] "m"(kShufAc), + [kShufAc3] "m"(kShufAc3), [kScaleAc33] "m"(kScaleAc33) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif // HAS_SCALEROWDOWN38_AVX2 + +static const uvec8 kLinearShuffleFar = {2, 3, 0, 1, 6, 7, 4, 5, + 10, 11, 8, 9, 14, 15, 12, 13}; + +static const uvec8 kLinearMadd31 = {3, 1, 1, 3, 3, 1, 1, 3, + 3, 1, 1, 3, 3, 1, 1, 3}; + +#ifdef HAS_SCALEROWUP2_LINEAR_SSE2 +void ScaleRowUp2_Linear_SSE2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + asm volatile( + "pxor %%xmm0,%%xmm0 \n" // 0 + "pcmpeqw %%xmm6,%%xmm6 \n" + "psrlw $15,%%xmm6 \n" + "psllw $1,%%xmm6 \n" // all 2 + + LABELALIGN + "1: \n" + "movq (%0),%%xmm1 \n" // 01234567 + "movq 1(%0),%%xmm2 \n" // 12345678 + "movdqa %%xmm1,%%xmm3 \n" + "punpcklbw %%xmm2,%%xmm3 \n" // 0112233445566778 + "punpcklbw %%xmm1,%%xmm1 \n" // 0011223344556677 + "punpcklbw %%xmm2,%%xmm2 \n" // 1122334455667788 + "movdqa %%xmm1,%%xmm4 \n" + "punpcklbw %%xmm0,%%xmm4 \n" // 00112233 (16) + "movdqa %%xmm2,%%xmm5 \n" + "punpcklbw %%xmm0,%%xmm5 \n" // 11223344 (16) + "paddw %%xmm5,%%xmm4 \n" + "movdqa %%xmm3,%%xmm5 \n" + "paddw %%xmm6,%%xmm4 \n" + "punpcklbw %%xmm0,%%xmm5 \n" // 01122334 (16) + "paddw %%xmm5,%%xmm5 \n" + "paddw %%xmm4,%%xmm5 \n" // 3*near+far+2 (lo) + "psrlw $2,%%xmm5 \n" // 3/4*near+1/4*far (lo) + + "punpckhbw %%xmm0,%%xmm1 \n" // 44556677 (16) + "punpckhbw %%xmm0,%%xmm2 \n" // 55667788 (16) + "paddw %%xmm2,%%xmm1 \n" + "punpckhbw %%xmm0,%%xmm3 \n" // 45566778 (16) + "paddw %%xmm6,%%xmm1 \n" + "paddw %%xmm3,%%xmm3 \n" + "paddw %%xmm3,%%xmm1 \n" // 3*near+far+2 (hi) + "psrlw $2,%%xmm1 \n" // 3/4*near+1/4*far (hi) + + "packuswb %%xmm1,%%xmm5 \n" + "movdqu %%xmm5,(%1) \n" + + "lea 0x8(%0),%0 \n" + "lea 0x10(%1),%1 \n" // 8 sample to 16 sample + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); +} +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_SSE2 +void ScaleRowUp2_Bilinear_SSE2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + asm volatile( + "1: \n" + "pxor %%xmm0,%%xmm0 \n" // 0 + // above line + "movq (%0),%%xmm1 \n" // 01234567 + "movq 1(%0),%%xmm2 \n" // 12345678 + "movdqa %%xmm1,%%xmm3 \n" + "punpcklbw %%xmm2,%%xmm3 \n" // 0112233445566778 + "punpcklbw %%xmm1,%%xmm1 \n" // 0011223344556677 + "punpcklbw %%xmm2,%%xmm2 \n" // 1122334455667788 + + "movdqa %%xmm1,%%xmm4 \n" + "punpcklbw %%xmm0,%%xmm4 \n" // 00112233 (16) + "movdqa %%xmm2,%%xmm5 \n" + "punpcklbw %%xmm0,%%xmm5 \n" // 11223344 (16) + "paddw %%xmm5,%%xmm4 \n" // near+far + "movdqa %%xmm3,%%xmm5 \n" + "punpcklbw %%xmm0,%%xmm5 \n" // 01122334 (16) + "paddw %%xmm5,%%xmm5 \n" // 2*near + "paddw %%xmm5,%%xmm4 \n" // 3*near+far (1, lo) + + "punpckhbw %%xmm0,%%xmm1 \n" // 44556677 (16) + "punpckhbw %%xmm0,%%xmm2 \n" // 55667788 (16) + "paddw %%xmm2,%%xmm1 \n" + "punpckhbw %%xmm0,%%xmm3 \n" // 45566778 (16) + "paddw %%xmm3,%%xmm3 \n" // 2*near + "paddw %%xmm3,%%xmm1 \n" // 3*near+far (1, hi) + + // below line + "movq (%0,%3),%%xmm6 \n" // 01234567 + "movq 1(%0,%3),%%xmm2 \n" // 12345678 + "movdqa %%xmm6,%%xmm3 \n" + "punpcklbw %%xmm2,%%xmm3 \n" // 0112233445566778 + "punpcklbw %%xmm6,%%xmm6 \n" // 0011223344556677 + "punpcklbw %%xmm2,%%xmm2 \n" // 1122334455667788 + + "movdqa %%xmm6,%%xmm5 \n" + "punpcklbw %%xmm0,%%xmm5 \n" // 00112233 (16) + "movdqa %%xmm2,%%xmm7 \n" + "punpcklbw %%xmm0,%%xmm7 \n" // 11223344 (16) + "paddw %%xmm7,%%xmm5 \n" // near+far + "movdqa %%xmm3,%%xmm7 \n" + "punpcklbw %%xmm0,%%xmm7 \n" // 01122334 (16) + "paddw %%xmm7,%%xmm7 \n" // 2*near + "paddw %%xmm7,%%xmm5 \n" // 3*near+far (2, lo) + + "punpckhbw %%xmm0,%%xmm6 \n" // 44556677 (16) + "punpckhbw %%xmm0,%%xmm2 \n" // 55667788 (16) + "paddw %%xmm6,%%xmm2 \n" // near+far + "punpckhbw %%xmm0,%%xmm3 \n" // 45566778 (16) + "paddw %%xmm3,%%xmm3 \n" // 2*near + "paddw %%xmm3,%%xmm2 \n" // 3*near+far (2, hi) + + // xmm4 xmm1 + // xmm5 xmm2 + "pcmpeqw %%xmm0,%%xmm0 \n" + "psrlw $15,%%xmm0 \n" + "psllw $3,%%xmm0 \n" // all 8 + + "movdqa %%xmm4,%%xmm3 \n" + "movdqa %%xmm5,%%xmm6 \n" + "paddw %%xmm3,%%xmm3 \n" // 6*near+2*far (1, lo) + "paddw %%xmm0,%%xmm6 \n" // 3*near+far+8 (2, lo) + "paddw %%xmm4,%%xmm3 \n" // 9*near+3*far (1, lo) + "paddw %%xmm6,%%xmm3 \n" // 9 3 3 1 + 8 (1, lo) + "psrlw $4,%%xmm3 \n" // ^ div by 16 + + "movdqa %%xmm1,%%xmm7 \n" + "movdqa %%xmm2,%%xmm6 \n" + "paddw %%xmm7,%%xmm7 \n" // 6*near+2*far (1, hi) + "paddw %%xmm0,%%xmm6 \n" // 3*near+far+8 (2, hi) + "paddw %%xmm1,%%xmm7 \n" // 9*near+3*far (1, hi) + "paddw %%xmm6,%%xmm7 \n" // 9 3 3 1 + 8 (1, hi) + "psrlw $4,%%xmm7 \n" // ^ div by 16 + + "packuswb %%xmm7,%%xmm3 \n" + "movdqu %%xmm3,(%1) \n" // save above line + + "movdqa %%xmm5,%%xmm3 \n" + "paddw %%xmm0,%%xmm4 \n" // 3*near+far+8 (1, lo) + "paddw %%xmm3,%%xmm3 \n" // 6*near+2*far (2, lo) + "paddw %%xmm3,%%xmm5 \n" // 9*near+3*far (2, lo) + "paddw %%xmm4,%%xmm5 \n" // 9 3 3 1 + 8 (lo) + "psrlw $4,%%xmm5 \n" // ^ div by 16 + + "movdqa %%xmm2,%%xmm3 \n" + "paddw %%xmm0,%%xmm1 \n" // 3*near+far+8 (1, hi) + "paddw %%xmm3,%%xmm3 \n" // 6*near+2*far (2, hi) + "paddw %%xmm3,%%xmm2 \n" // 9*near+3*far (2, hi) + "paddw %%xmm1,%%xmm2 \n" // 9 3 3 1 + 8 (hi) + "psrlw $4,%%xmm2 \n" // ^ div by 16 + + "packuswb %%xmm2,%%xmm5 \n" + "movdqu %%xmm5,(%1,%4) \n" // save below line + + "lea 0x8(%0),%0 \n" + "lea 0x10(%1),%1 \n" // 8 sample to 16 sample + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(dst_stride) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_12_SSSE3 +void ScaleRowUp2_Linear_12_SSSE3(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + asm volatile( + "movdqa %3,%%xmm5 \n" + "pcmpeqw %%xmm4,%%xmm4 \n" + "psrlw $15,%%xmm4 \n" + "psllw $1,%%xmm4 \n" // all 2 + + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm0 \n" // 01234567 (16) + "movdqu 2(%0),%%xmm1 \n" // 12345678 (16) + + "movdqa %%xmm0,%%xmm2 \n" + "punpckhwd %%xmm1,%%xmm2 \n" // 45566778 (16) + "punpcklwd %%xmm1,%%xmm0 \n" // 01122334 (16) + + "movdqa %%xmm2,%%xmm3 \n" + "movdqa %%xmm0,%%xmm1 \n" + "pshufb %%xmm5,%%xmm3 \n" // 54657687 (far) + "pshufb %%xmm5,%%xmm1 \n" // 10213243 (far) + + "paddw %%xmm4,%%xmm1 \n" // far+2 + "paddw %%xmm4,%%xmm3 \n" // far+2 + "paddw %%xmm0,%%xmm1 \n" // near+far+2 + "paddw %%xmm2,%%xmm3 \n" // near+far+2 + "paddw %%xmm0,%%xmm0 \n" // 2*near + "paddw %%xmm2,%%xmm2 \n" // 2*near + "paddw %%xmm1,%%xmm0 \n" // 3*near+far+2 (lo) + "paddw %%xmm3,%%xmm2 \n" // 3*near+far+2 (hi) + + "psrlw $2,%%xmm0 \n" // 3/4*near+1/4*far + "psrlw $2,%%xmm2 \n" // 3/4*near+1/4*far + "movdqu %%xmm0,(%1) \n" + "movdqu %%xmm2,16(%1) \n" + + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" // 8 sample to 16 sample + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "m"(kLinearShuffleFar) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_12_SSSE3 +void ScaleRowUp2_Bilinear_12_SSSE3(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + asm volatile( + "pcmpeqw %%xmm7,%%xmm7 \n" + "psrlw $15,%%xmm7 \n" + "psllw $3,%%xmm7 \n" // all 8 + "movdqa %5,%%xmm6 \n" + + LABELALIGN + "1: \n" + // above line + "movdqu (%0),%%xmm0 \n" // 01234567 (16) + "movdqu 2(%0),%%xmm1 \n" // 12345678 (16) + "movdqa %%xmm0,%%xmm2 \n" + "punpckhwd %%xmm1,%%xmm2 \n" // 45566778 (16) + "punpcklwd %%xmm1,%%xmm0 \n" // 01122334 (16) + "movdqa %%xmm2,%%xmm3 \n" + "movdqa %%xmm0,%%xmm1 \n" + "pshufb %%xmm6,%%xmm3 \n" // 54657687 (far) + "pshufb %%xmm6,%%xmm1 \n" // 10213243 (far) + "paddw %%xmm0,%%xmm1 \n" // near+far + "paddw %%xmm2,%%xmm3 \n" // near+far + "paddw %%xmm0,%%xmm0 \n" // 2*near + "paddw %%xmm2,%%xmm2 \n" // 2*near + "paddw %%xmm1,%%xmm0 \n" // 3*near+far (1, lo) + "paddw %%xmm3,%%xmm2 \n" // 3*near+far (1, hi) + + // below line + "movdqu (%0,%3,2),%%xmm1 \n" // 01234567 (16) + "movdqu 2(%0,%3,2),%%xmm4 \n" // 12345678 (16) + "movdqa %%xmm1,%%xmm3 \n" + "punpckhwd %%xmm4,%%xmm3 \n" // 45566778 (16) + "punpcklwd %%xmm4,%%xmm1 \n" // 01122334 (16) + "movdqa %%xmm3,%%xmm5 \n" + "movdqa %%xmm1,%%xmm4 \n" + "pshufb %%xmm6,%%xmm5 \n" // 54657687 (far) + "pshufb %%xmm6,%%xmm4 \n" // 10213243 (far) + "paddw %%xmm1,%%xmm4 \n" // near+far + "paddw %%xmm3,%%xmm5 \n" // near+far + "paddw %%xmm1,%%xmm1 \n" // 2*near + "paddw %%xmm3,%%xmm3 \n" // 2*near + "paddw %%xmm4,%%xmm1 \n" // 3*near+far (2, lo) + "paddw %%xmm5,%%xmm3 \n" // 3*near+far (2, hi) + + // xmm0 xmm2 + // xmm1 xmm3 + + "movdqa %%xmm0,%%xmm4 \n" + "movdqa %%xmm1,%%xmm5 \n" + "paddw %%xmm4,%%xmm4 \n" // 6*near+2*far (1, lo) + "paddw %%xmm7,%%xmm5 \n" // 3*near+far+8 (2, lo) + "paddw %%xmm0,%%xmm4 \n" // 9*near+3*far (1, lo) + "paddw %%xmm5,%%xmm4 \n" // 9 3 3 1 + 8 (1, lo) + "psrlw $4,%%xmm4 \n" // ^ div by 16 + "movdqu %%xmm4,(%1) \n" + + "movdqa %%xmm2,%%xmm4 \n" + "movdqa %%xmm3,%%xmm5 \n" + "paddw %%xmm4,%%xmm4 \n" // 6*near+2*far (1, hi) + "paddw %%xmm7,%%xmm5 \n" // 3*near+far+8 (2, hi) + "paddw %%xmm2,%%xmm4 \n" // 9*near+3*far (1, hi) + "paddw %%xmm5,%%xmm4 \n" // 9 3 3 1 + 8 (1, hi) + "psrlw $4,%%xmm4 \n" // ^ div by 16 + "movdqu %%xmm4,0x10(%1) \n" + + "movdqa %%xmm1,%%xmm4 \n" + "paddw %%xmm7,%%xmm0 \n" // 3*near+far+8 (1, lo) + "paddw %%xmm4,%%xmm4 \n" // 6*near+2*far (2, lo) + "paddw %%xmm4,%%xmm1 \n" // 9*near+3*far (2, lo) + "paddw %%xmm0,%%xmm1 \n" // 9 3 3 1 + 8 (2, lo) + "psrlw $4,%%xmm1 \n" // ^ div by 16 + "movdqu %%xmm1,(%1,%4,2) \n" + + "movdqa %%xmm3,%%xmm4 \n" + "paddw %%xmm7,%%xmm2 \n" // 3*near+far+8 (1, hi) + "paddw %%xmm4,%%xmm4 \n" // 6*near+2*far (2, hi) + "paddw %%xmm4,%%xmm3 \n" // 9*near+3*far (2, hi) + "paddw %%xmm2,%%xmm3 \n" // 9 3 3 1 + 8 (2, hi) + "psrlw $4,%%xmm3 \n" // ^ div by 16 + "movdqu %%xmm3,0x10(%1,%4,2) \n" + + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" // 8 sample to 16 sample + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(dst_stride), // %4 + "m"(kLinearShuffleFar) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_16_SSE2 +void ScaleRowUp2_Linear_16_SSE2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + asm volatile( + "pxor %%xmm5,%%xmm5 \n" + "pcmpeqd %%xmm4,%%xmm4 \n" + "psrld $31,%%xmm4 \n" + "pslld $1,%%xmm4 \n" // all 2 + + LABELALIGN + "1: \n" + "movq (%0),%%xmm0 \n" // 0123 (16b) + "movq 2(%0),%%xmm1 \n" // 1234 (16b) + + "punpcklwd %%xmm5,%%xmm0 \n" // 0123 (32b) + "punpcklwd %%xmm5,%%xmm1 \n" // 1234 (32b) + + "movdqa %%xmm0,%%xmm2 \n" + "movdqa %%xmm1,%%xmm3 \n" + + "pshufd $0b10110001,%%xmm2,%%xmm2 \n" // 1032 (even, far) + "pshufd $0b10110001,%%xmm3,%%xmm3 \n" // 2143 (odd, far) + + "paddd %%xmm4,%%xmm2 \n" // far+2 (lo) + "paddd %%xmm4,%%xmm3 \n" // far+2 (hi) + "paddd %%xmm0,%%xmm2 \n" // near+far+2 (lo) + "paddd %%xmm1,%%xmm3 \n" // near+far+2 (hi) + "paddd %%xmm0,%%xmm0 \n" // 2*near (lo) + "paddd %%xmm1,%%xmm1 \n" // 2*near (hi) + "paddd %%xmm2,%%xmm0 \n" // 3*near+far+2 (lo) + "paddd %%xmm3,%%xmm1 \n" // 3*near+far+2 (hi) + + "psrld $2,%%xmm0 \n" // 3/4*near+1/4*far (lo) + "psrld $2,%%xmm1 \n" // 3/4*near+1/4*far (hi) + "pshuflw $0x88,%%xmm0,%%xmm0 \n" + "pshufhw $0x88,%%xmm0,%%xmm0 \n" + "pshufd $0x88,%%xmm0,%%xmm0 \n" + "pshuflw $0x88,%%xmm1,%%xmm1 \n" + "pshufhw $0x88,%%xmm1,%%xmm1 \n" + "pshufd $0x88,%%xmm1,%%xmm1 \n" + "punpckldq %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + + "lea 0x8(%0),%0 \n" + "lea 0x10(%1),%1 \n" // 4 pixel to 8 pixel + "sub $0x8,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_16_SSE2 +void ScaleRowUp2_Bilinear_16_SSE2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + asm volatile( + "pxor %%xmm7,%%xmm7 \n" + "pcmpeqd %%xmm6,%%xmm6 \n" + "psrld $31,%%xmm6 \n" + "pslld $3,%%xmm6 \n" // all 8 + + LABELALIGN + "1: \n" + "movq (%0),%%xmm0 \n" // 0123 (16b) + "movq 2(%0),%%xmm1 \n" // 1234 (16b) + "punpcklwd %%xmm7,%%xmm0 \n" // 0123 (32b) + "punpcklwd %%xmm7,%%xmm1 \n" // 1234 (32b) + "movdqa %%xmm0,%%xmm2 \n" + "movdqa %%xmm1,%%xmm3 \n" + "pshufd $0b10110001,%%xmm2,%%xmm2 \n" // 1032 (even, far) + "pshufd $0b10110001,%%xmm3,%%xmm3 \n" // 2143 (odd, far) + "paddd %%xmm0,%%xmm2 \n" // near+far (lo) + "paddd %%xmm1,%%xmm3 \n" // near+far (hi) + "paddd %%xmm0,%%xmm0 \n" // 2*near (lo) + "paddd %%xmm1,%%xmm1 \n" // 2*near (hi) + "paddd %%xmm2,%%xmm0 \n" // 3*near+far (1, lo) + "paddd %%xmm3,%%xmm1 \n" // 3*near+far (1, hi) + + "movq (%0,%3,2),%%xmm2 \n" + "movq 2(%0,%3,2),%%xmm3 \n" + "punpcklwd %%xmm7,%%xmm2 \n" // 0123 (32b) + "punpcklwd %%xmm7,%%xmm3 \n" // 1234 (32b) + "movdqa %%xmm2,%%xmm4 \n" + "movdqa %%xmm3,%%xmm5 \n" + "pshufd $0b10110001,%%xmm4,%%xmm4 \n" // 1032 (even, far) + "pshufd $0b10110001,%%xmm5,%%xmm5 \n" // 2143 (odd, far) + "paddd %%xmm2,%%xmm4 \n" // near+far (lo) + "paddd %%xmm3,%%xmm5 \n" // near+far (hi) + "paddd %%xmm2,%%xmm2 \n" // 2*near (lo) + "paddd %%xmm3,%%xmm3 \n" // 2*near (hi) + "paddd %%xmm4,%%xmm2 \n" // 3*near+far (2, lo) + "paddd %%xmm5,%%xmm3 \n" // 3*near+far (2, hi) + + "movdqa %%xmm0,%%xmm4 \n" + "movdqa %%xmm2,%%xmm5 \n" + "paddd %%xmm0,%%xmm4 \n" // 6*near+2*far (1, lo) + "paddd %%xmm6,%%xmm5 \n" // 3*near+far+8 (2, lo) + "paddd %%xmm0,%%xmm4 \n" // 9*near+3*far (1, lo) + "paddd %%xmm5,%%xmm4 \n" // 9 3 3 1 + 8 (1, lo) + "psrld $4,%%xmm4 \n" // ^ div by 16 (1, lo) + + "movdqa %%xmm2,%%xmm5 \n" + "paddd %%xmm2,%%xmm5 \n" // 6*near+2*far (2, lo) + "paddd %%xmm6,%%xmm0 \n" // 3*near+far+8 (1, lo) + "paddd %%xmm2,%%xmm5 \n" // 9*near+3*far (2, lo) + "paddd %%xmm0,%%xmm5 \n" // 9 3 3 1 + 8 (2, lo) + "psrld $4,%%xmm5 \n" // ^ div by 16 (2, lo) + + "movdqa %%xmm1,%%xmm0 \n" + "movdqa %%xmm3,%%xmm2 \n" + "paddd %%xmm1,%%xmm0 \n" // 6*near+2*far (1, hi) + "paddd %%xmm6,%%xmm2 \n" // 3*near+far+8 (2, hi) + "paddd %%xmm1,%%xmm0 \n" // 9*near+3*far (1, hi) + "paddd %%xmm2,%%xmm0 \n" // 9 3 3 1 + 8 (1, hi) + "psrld $4,%%xmm0 \n" // ^ div by 16 (1, hi) + + "movdqa %%xmm3,%%xmm2 \n" + "paddd %%xmm3,%%xmm2 \n" // 6*near+2*far (2, hi) + "paddd %%xmm6,%%xmm1 \n" // 3*near+far+8 (1, hi) + "paddd %%xmm3,%%xmm2 \n" // 9*near+3*far (2, hi) + "paddd %%xmm1,%%xmm2 \n" // 9 3 3 1 + 8 (2, hi) + "psrld $4,%%xmm2 \n" // ^ div by 16 (2, hi) + + "pshuflw $0x88,%%xmm4,%%xmm4 \n" + "pshufhw $0x88,%%xmm4,%%xmm4 \n" + "pshufd $0x88,%%xmm4,%%xmm4 \n" + "pshuflw $0x88,%%xmm0,%%xmm0 \n" + "pshufhw $0x88,%%xmm0,%%xmm0 \n" + "pshufd $0x88,%%xmm0,%%xmm0 \n" + "punpckldq %%xmm0,%%xmm4 \n" + "movdqu %%xmm4,(%1) \n" // store above + "pshuflw $0x88,%%xmm5,%%xmm5 \n" + "pshufhw $0x88,%%xmm5,%%xmm5 \n" + "pshufd $0x88,%%xmm5,%%xmm5 \n" + "pshuflw $0x88,%%xmm2,%%xmm2 \n" + "pshufhw $0x88,%%xmm2,%%xmm2 \n" + "pshufd $0x88,%%xmm2,%%xmm2 \n" + "punpckldq %%xmm2,%%xmm5 \n" + "movdqu %%xmm5,(%1,%4,2) \n" // store below + + "lea 0x8(%0),%0 \n" + "lea 0x10(%1),%1 \n" // 4 pixel to 8 pixel + "sub $0x8,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(dst_stride) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_SSSE3 +void ScaleRowUp2_Linear_SSSE3(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + asm volatile( + "pcmpeqw %%xmm4,%%xmm4 \n" + "psrlw $15,%%xmm4 \n" + "psllw $1,%%xmm4 \n" // all 2 + "movdqa %3,%%xmm3 \n" + + LABELALIGN + "1: \n" + "movq (%0),%%xmm0 \n" // 01234567 + "movq 1(%0),%%xmm1 \n" // 12345678 + "punpcklwd %%xmm0,%%xmm0 \n" // 0101232345456767 + "punpcklwd %%xmm1,%%xmm1 \n" // 1212343456567878 + "movdqa %%xmm0,%%xmm2 \n" + "punpckhdq %%xmm1,%%xmm2 \n" // 4545565667677878 + "punpckldq %%xmm1,%%xmm0 \n" // 0101121223233434 + "pmaddubsw %%xmm3,%%xmm2 \n" // 3*near+far (hi) + "pmaddubsw %%xmm3,%%xmm0 \n" // 3*near+far (lo) + "paddw %%xmm4,%%xmm0 \n" // 3*near+far+2 (lo) + "paddw %%xmm4,%%xmm2 \n" // 3*near+far+2 (hi) + "psrlw $2,%%xmm0 \n" // 3/4*near+1/4*far (lo) + "psrlw $2,%%xmm2 \n" // 3/4*near+1/4*far (hi) + "packuswb %%xmm2,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + "lea 0x8(%0),%0 \n" + "lea 0x10(%1),%1 \n" // 8 sample to 16 sample + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "m"(kLinearMadd31) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_SSSE3 +void ScaleRowUp2_Bilinear_SSSE3(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + asm volatile( + "pcmpeqw %%xmm6,%%xmm6 \n" + "psrlw $15,%%xmm6 \n" + "psllw $3,%%xmm6 \n" // all 8 + "movdqa %5,%%xmm7 \n" + + LABELALIGN + "1: \n" + "movq (%0),%%xmm0 \n" // 01234567 + "movq 1(%0),%%xmm1 \n" // 12345678 + "punpcklwd %%xmm0,%%xmm0 \n" // 0101232345456767 + "punpcklwd %%xmm1,%%xmm1 \n" // 1212343456567878 + "movdqa %%xmm0,%%xmm2 \n" + "punpckhdq %%xmm1,%%xmm2 \n" // 4545565667677878 + "punpckldq %%xmm1,%%xmm0 \n" // 0101121223233434 + "pmaddubsw %%xmm7,%%xmm2 \n" // 3*near+far (1, hi) + "pmaddubsw %%xmm7,%%xmm0 \n" // 3*near+far (1, lo) + + "movq (%0,%3),%%xmm1 \n" + "movq 1(%0,%3),%%xmm4 \n" + "punpcklwd %%xmm1,%%xmm1 \n" + "punpcklwd %%xmm4,%%xmm4 \n" + "movdqa %%xmm1,%%xmm3 \n" + "punpckhdq %%xmm4,%%xmm3 \n" + "punpckldq %%xmm4,%%xmm1 \n" + "pmaddubsw %%xmm7,%%xmm3 \n" // 3*near+far (2, hi) + "pmaddubsw %%xmm7,%%xmm1 \n" // 3*near+far (2, lo) + + // xmm0 xmm2 + // xmm1 xmm3 + + "movdqa %%xmm0,%%xmm4 \n" + "movdqa %%xmm1,%%xmm5 \n" + "paddw %%xmm0,%%xmm4 \n" // 6*near+2*far (1, lo) + "paddw %%xmm6,%%xmm5 \n" // 3*near+far+8 (2, lo) + "paddw %%xmm0,%%xmm4 \n" // 9*near+3*far (1, lo) + "paddw %%xmm5,%%xmm4 \n" // 9 3 3 1 + 8 (1, lo) + "psrlw $4,%%xmm4 \n" // ^ div by 16 (1, lo) + + "movdqa %%xmm1,%%xmm5 \n" + "paddw %%xmm1,%%xmm5 \n" // 6*near+2*far (2, lo) + "paddw %%xmm6,%%xmm0 \n" // 3*near+far+8 (1, lo) + "paddw %%xmm1,%%xmm5 \n" // 9*near+3*far (2, lo) + "paddw %%xmm0,%%xmm5 \n" // 9 3 3 1 + 8 (2, lo) + "psrlw $4,%%xmm5 \n" // ^ div by 16 (2, lo) + + "movdqa %%xmm2,%%xmm0 \n" + "movdqa %%xmm3,%%xmm1 \n" + "paddw %%xmm2,%%xmm0 \n" // 6*near+2*far (1, hi) + "paddw %%xmm6,%%xmm1 \n" // 3*near+far+8 (2, hi) + "paddw %%xmm2,%%xmm0 \n" // 9*near+3*far (1, hi) + "paddw %%xmm1,%%xmm0 \n" // 9 3 3 1 + 8 (1, hi) + "psrlw $4,%%xmm0 \n" // ^ div by 16 (1, hi) + + "movdqa %%xmm3,%%xmm1 \n" + "paddw %%xmm3,%%xmm1 \n" // 6*near+2*far (2, hi) + "paddw %%xmm6,%%xmm2 \n" // 3*near+far+8 (1, hi) + "paddw %%xmm3,%%xmm1 \n" // 9*near+3*far (2, hi) + "paddw %%xmm2,%%xmm1 \n" // 9 3 3 1 + 8 (2, hi) + "psrlw $4,%%xmm1 \n" // ^ div by 16 (2, hi) + + "packuswb %%xmm0,%%xmm4 \n" + "movdqu %%xmm4,(%1) \n" // store above + "packuswb %%xmm1,%%xmm5 \n" + "movdqu %%xmm5,(%1,%4) \n" // store below + + "lea 0x8(%0),%0 \n" + "lea 0x10(%1),%1 \n" // 8 sample to 16 sample + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(dst_stride), // %4 + "m"(kLinearMadd31) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_AVX2 +void ScaleRowUp2_Linear_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + asm volatile( + "vpcmpeqw %%ymm4,%%ymm4,%%ymm4 \n" + "vpsrlw $15,%%ymm4,%%ymm4 \n" + "vpsllw $1,%%ymm4,%%ymm4 \n" // all 2 + "vbroadcastf128 %3,%%ymm3 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" // 0123456789ABCDEF + "vmovdqu 1(%0),%%xmm1 \n" // 123456789ABCDEF0 + "vpermq $0b11011000,%%ymm0,%%ymm0 \n" + "vpermq $0b11011000,%%ymm1,%%ymm1 \n" + "vpunpcklwd %%ymm0,%%ymm0,%%ymm0 \n" + "vpunpcklwd %%ymm1,%%ymm1,%%ymm1 \n" + "vpunpckhdq %%ymm1,%%ymm0,%%ymm2 \n" + "vpunpckldq %%ymm1,%%ymm0,%%ymm0 \n" + "vpmaddubsw %%ymm3,%%ymm2,%%ymm1 \n" // 3*near+far (hi) + "vpmaddubsw %%ymm3,%%ymm0,%%ymm0 \n" // 3*near+far (lo) + "vpaddw %%ymm4,%%ymm0,%%ymm0 \n" // 3*near+far+2 (lo) + "vpaddw %%ymm4,%%ymm1,%%ymm1 \n" // 3*near+far+2 (hi) + "vpsrlw $2,%%ymm0,%%ymm0 \n" // 3/4*near+1/4*far (lo) + "vpsrlw $2,%%ymm1,%%ymm1 \n" // 3/4*near+1/4*far (hi) + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" // 16 sample to 32 sample + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "m"(kLinearMadd31) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_AVX2 +void ScaleRowUp2_Bilinear_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + asm volatile( + "vpcmpeqw %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrlw $15,%%ymm6,%%ymm6 \n" + "vpsllw $3,%%ymm6,%%ymm6 \n" // all 8 + "vbroadcastf128 %5,%%ymm7 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" // 0123456789ABCDEF + "vmovdqu 1(%0),%%xmm1 \n" // 123456789ABCDEF0 + "vpermq $0b11011000,%%ymm0,%%ymm0 \n" + "vpermq $0b11011000,%%ymm1,%%ymm1 \n" + "vpunpcklwd %%ymm0,%%ymm0,%%ymm0 \n" + "vpunpcklwd %%ymm1,%%ymm1,%%ymm1 \n" + "vpunpckhdq %%ymm1,%%ymm0,%%ymm2 \n" + "vpunpckldq %%ymm1,%%ymm0,%%ymm0 \n" + "vpmaddubsw %%ymm7,%%ymm2,%%ymm1 \n" // 3*near+far (1, hi) + "vpmaddubsw %%ymm7,%%ymm0,%%ymm0 \n" // 3*near+far (1, lo) + + "vmovdqu (%0,%3),%%xmm2 \n" // 0123456789ABCDEF + "vmovdqu 1(%0,%3),%%xmm3 \n" // 123456789ABCDEF0 + "vpermq $0b11011000,%%ymm2,%%ymm2 \n" + "vpermq $0b11011000,%%ymm3,%%ymm3 \n" + "vpunpcklwd %%ymm2,%%ymm2,%%ymm2 \n" + "vpunpcklwd %%ymm3,%%ymm3,%%ymm3 \n" + "vpunpckhdq %%ymm3,%%ymm2,%%ymm4 \n" + "vpunpckldq %%ymm3,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm7,%%ymm4,%%ymm3 \n" // 3*near+far (2, hi) + "vpmaddubsw %%ymm7,%%ymm2,%%ymm2 \n" // 3*near+far (2, lo) + + // ymm0 ymm1 + // ymm2 ymm3 + + "vpaddw %%ymm0,%%ymm0,%%ymm4 \n" // 6*near+2*far (1, lo) + "vpaddw %%ymm6,%%ymm2,%%ymm5 \n" // 3*near+far+8 (2, lo) + "vpaddw %%ymm4,%%ymm0,%%ymm4 \n" // 9*near+3*far (1, lo) + "vpaddw %%ymm4,%%ymm5,%%ymm4 \n" // 9 3 3 1 + 8 (1, lo) + "vpsrlw $4,%%ymm4,%%ymm4 \n" // ^ div by 16 (1, lo) + + "vpaddw %%ymm2,%%ymm2,%%ymm5 \n" // 6*near+2*far (2, lo) + "vpaddw %%ymm6,%%ymm0,%%ymm0 \n" // 3*near+far+8 (1, lo) + "vpaddw %%ymm5,%%ymm2,%%ymm5 \n" // 9*near+3*far (2, lo) + "vpaddw %%ymm5,%%ymm0,%%ymm5 \n" // 9 3 3 1 + 8 (2, lo) + "vpsrlw $4,%%ymm5,%%ymm5 \n" // ^ div by 16 (2, lo) + + "vpaddw %%ymm1,%%ymm1,%%ymm0 \n" // 6*near+2*far (1, hi) + "vpaddw %%ymm6,%%ymm3,%%ymm2 \n" // 3*near+far+8 (2, hi) + "vpaddw %%ymm0,%%ymm1,%%ymm0 \n" // 9*near+3*far (1, hi) + "vpaddw %%ymm0,%%ymm2,%%ymm0 \n" // 9 3 3 1 + 8 (1, hi) + "vpsrlw $4,%%ymm0,%%ymm0 \n" // ^ div by 16 (1, hi) + + "vpaddw %%ymm3,%%ymm3,%%ymm2 \n" // 6*near+2*far (2, hi) + "vpaddw %%ymm6,%%ymm1,%%ymm1 \n" // 3*near+far+8 (1, hi) + "vpaddw %%ymm2,%%ymm3,%%ymm2 \n" // 9*near+3*far (2, hi) + "vpaddw %%ymm2,%%ymm1,%%ymm2 \n" // 9 3 3 1 + 8 (2, hi) + "vpsrlw $4,%%ymm2,%%ymm2 \n" // ^ div by 16 (2, hi) + + "vpackuswb %%ymm0,%%ymm4,%%ymm4 \n" + "vmovdqu %%ymm4,(%1) \n" // store above + "vpackuswb %%ymm2,%%ymm5,%%ymm5 \n" + "vmovdqu %%ymm5,(%1,%4) \n" // store below + + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" // 16 sample to 32 sample + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(dst_stride), // %4 + "m"(kLinearMadd31) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_12_AVX2 +void ScaleRowUp2_Linear_12_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + asm volatile( + "vbroadcastf128 %3,%%ymm5 \n" + "vpcmpeqw %%ymm4,%%ymm4,%%ymm4 \n" + "vpsrlw $15,%%ymm4,%%ymm4 \n" + "vpsllw $1,%%ymm4,%%ymm4 \n" // all 2 + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" // 0123456789ABCDEF (16b) + "vmovdqu 2(%0),%%ymm1 \n" // 123456789ABCDEF0 (16b) + + "vpermq $0b11011000,%%ymm0,%%ymm0 \n" // 012389AB4567CDEF + "vpermq $0b11011000,%%ymm1,%%ymm1 \n" // 12349ABC5678DEF0 + + "vpunpckhwd %%ymm1,%%ymm0,%%ymm2 \n" // 899AABBCCDDEEFF0 (near) + "vpunpcklwd %%ymm1,%%ymm0,%%ymm0 \n" // 0112233445566778 (near) + "vpshufb %%ymm5,%%ymm2,%%ymm3 \n" // 98A9BACBDCEDFE0F (far) + "vpshufb %%ymm5,%%ymm0,%%ymm1 \n" // 1021324354657687 (far) + + "vpaddw %%ymm4,%%ymm1,%%ymm1 \n" // far+2 + "vpaddw %%ymm4,%%ymm3,%%ymm3 \n" // far+2 + "vpaddw %%ymm0,%%ymm1,%%ymm1 \n" // near+far+2 + "vpaddw %%ymm2,%%ymm3,%%ymm3 \n" // near+far+2 + "vpaddw %%ymm0,%%ymm0,%%ymm0 \n" // 2*near + "vpaddw %%ymm2,%%ymm2,%%ymm2 \n" // 2*near + "vpaddw %%ymm0,%%ymm1,%%ymm0 \n" // 3*near+far+2 + "vpaddw %%ymm2,%%ymm3,%%ymm2 \n" // 3*near+far+2 + + "vpsrlw $2,%%ymm0,%%ymm0 \n" // 3/4*near+1/4*far + "vpsrlw $2,%%ymm2,%%ymm2 \n" // 3/4*near+1/4*far + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm2,32(%1) \n" + + "lea 0x20(%0),%0 \n" + "lea 0x40(%1),%1 \n" // 16 sample to 32 sample + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "m"(kLinearShuffleFar) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_12_AVX2 +void ScaleRowUp2_Bilinear_12_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + asm volatile( + "vbroadcastf128 %5,%%ymm5 \n" + "vpcmpeqw %%ymm4,%%ymm4,%%ymm4 \n" + "vpsrlw $15,%%ymm4,%%ymm4 \n" + "vpsllw $3,%%ymm4,%%ymm4 \n" // all 8 + + LABELALIGN + "1: \n" + + "vmovdqu (%0),%%xmm0 \n" // 01234567 (16b) + "vmovdqu 2(%0),%%xmm1 \n" // 12345678 (16b) + "vpermq $0b11011000,%%ymm0,%%ymm0 \n" // 0123000045670000 + "vpermq $0b11011000,%%ymm1,%%ymm1 \n" // 1234000056780000 + "vpunpcklwd %%ymm1,%%ymm0,%%ymm0 \n" // 0112233445566778 (near) + "vpshufb %%ymm5,%%ymm0,%%ymm1 \n" // 1021324354657687 (far) + "vpaddw %%ymm0,%%ymm1,%%ymm1 \n" // near+far + "vpaddw %%ymm0,%%ymm0,%%ymm0 \n" // 2*near + "vpaddw %%ymm0,%%ymm1,%%ymm2 \n" // 3*near+far (1) + + "vmovdqu (%0,%3,2),%%xmm0 \n" // 01234567 (16b) + "vmovdqu 2(%0,%3,2),%%xmm1 \n" // 12345678 (16b) + "vpermq $0b11011000,%%ymm0,%%ymm0 \n" // 0123000045670000 + "vpermq $0b11011000,%%ymm1,%%ymm1 \n" // 1234000056780000 + "vpunpcklwd %%ymm1,%%ymm0,%%ymm0 \n" // 0112233445566778 (near) + "vpshufb %%ymm5,%%ymm0,%%ymm1 \n" // 1021324354657687 (far) + "vpaddw %%ymm0,%%ymm1,%%ymm1 \n" // near+far + "vpaddw %%ymm0,%%ymm0,%%ymm0 \n" // 2*near + "vpaddw %%ymm0,%%ymm1,%%ymm3 \n" // 3*near+far (2) + + "vpaddw %%ymm2,%%ymm2,%%ymm0 \n" // 6*near+2*far (1) + "vpaddw %%ymm4,%%ymm3,%%ymm1 \n" // 3*near+far+8 (2) + "vpaddw %%ymm0,%%ymm2,%%ymm0 \n" // 9*near+3*far (1) + "vpaddw %%ymm0,%%ymm1,%%ymm0 \n" // 9 3 3 1 + 8 (1) + "vpsrlw $4,%%ymm0,%%ymm0 \n" // ^ div by 16 + "vmovdqu %%ymm0,(%1) \n" // store above + + "vpaddw %%ymm3,%%ymm3,%%ymm0 \n" // 6*near+2*far (2) + "vpaddw %%ymm4,%%ymm2,%%ymm1 \n" // 3*near+far+8 (1) + "vpaddw %%ymm0,%%ymm3,%%ymm0 \n" // 9*near+3*far (2) + "vpaddw %%ymm0,%%ymm1,%%ymm0 \n" // 9 3 3 1 + 8 (2) + "vpsrlw $4,%%ymm0,%%ymm0 \n" // ^ div by 16 + "vmovdqu %%ymm0,(%1,%4,2) \n" // store below + + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" // 8 sample to 16 sample + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(dst_stride), // %4 + "m"(kLinearShuffleFar) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_16_AVX2 +void ScaleRowUp2_Linear_16_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + asm volatile( + "vpcmpeqd %%ymm4,%%ymm4,%%ymm4 \n" + "vpsrld $31,%%ymm4,%%ymm4 \n" + "vpslld $1,%%ymm4,%%ymm4 \n" // all 2 + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" // 01234567 (16b, 1u1v) + "vmovdqu 2(%0),%%xmm1 \n" // 12345678 (16b, 1u1v) + + "vpmovzxwd %%xmm0,%%ymm0 \n" // 01234567 (32b, 1u1v) + "vpmovzxwd %%xmm1,%%ymm1 \n" // 12345678 (32b, 1u1v) + + "vpshufd $0b10110001,%%ymm0,%%ymm2 \n" // 10325476 (lo, far) + "vpshufd $0b10110001,%%ymm1,%%ymm3 \n" // 21436587 (hi, far) + + "vpaddd %%ymm4,%%ymm2,%%ymm2 \n" // far+2 (lo) + "vpaddd %%ymm4,%%ymm3,%%ymm3 \n" // far+2 (hi) + "vpaddd %%ymm0,%%ymm2,%%ymm2 \n" // near+far+2 (lo) + "vpaddd %%ymm1,%%ymm3,%%ymm3 \n" // near+far+2 (hi) + "vpaddd %%ymm0,%%ymm0,%%ymm0 \n" // 2*near (lo) + "vpaddd %%ymm1,%%ymm1,%%ymm1 \n" // 2*near (hi) + "vpaddd %%ymm0,%%ymm2,%%ymm0 \n" // 3*near+far+2 (lo) + "vpaddd %%ymm1,%%ymm3,%%ymm1 \n" // 3*near+far+2 (hi) + + "vpsrld $2,%%ymm0,%%ymm0 \n" // 3/4*near+1/4*far (lo) + "vpsrld $2,%%ymm1,%%ymm1 \n" // 3/4*near+1/4*far (hi) + "vpackusdw %%ymm1,%%ymm0,%%ymm0 \n" + "vpshufd $0b11011000,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" // 8 pixel to 16 pixel + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_16_AVX2 +void ScaleRowUp2_Bilinear_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + asm volatile( + "vpcmpeqd %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrld $31,%%ymm6,%%ymm6 \n" + "vpslld $3,%%ymm6,%%ymm6 \n" // all 8 + + LABELALIGN + "1: \n" + + "vmovdqu (%0),%%xmm0 \n" // 01234567 (16b, 1u1v) + "vmovdqu 2(%0),%%xmm1 \n" // 12345678 (16b, 1u1v) + "vpmovzxwd %%xmm0,%%ymm0 \n" // 01234567 (32b, 1u1v) + "vpmovzxwd %%xmm1,%%ymm1 \n" // 12345678 (32b, 1u1v) + "vpshufd $0b10110001,%%ymm0,%%ymm2 \n" // 10325476 (lo, far) + "vpshufd $0b10110001,%%ymm1,%%ymm3 \n" // 21436587 (hi, far) + "vpaddd %%ymm0,%%ymm2,%%ymm2 \n" // near+far (lo) + "vpaddd %%ymm1,%%ymm3,%%ymm3 \n" // near+far (hi) + "vpaddd %%ymm0,%%ymm0,%%ymm0 \n" // 2*near (lo) + "vpaddd %%ymm1,%%ymm1,%%ymm1 \n" // 2*near (hi) + "vpaddd %%ymm0,%%ymm2,%%ymm0 \n" // 3*near+far (1, lo) + "vpaddd %%ymm1,%%ymm3,%%ymm1 \n" // 3*near+far (1, hi) + + "vmovdqu (%0,%3,2),%%xmm2 \n" // 01234567 (16b, 1u1v) + "vmovdqu 2(%0,%3,2),%%xmm3 \n" // 12345678 (16b, 1u1v) + "vpmovzxwd %%xmm2,%%ymm2 \n" // 01234567 (32b, 1u1v) + "vpmovzxwd %%xmm3,%%ymm3 \n" // 12345678 (32b, 1u1v) + "vpshufd $0b10110001,%%ymm2,%%ymm4 \n" // 10325476 (lo, far) + "vpshufd $0b10110001,%%ymm3,%%ymm5 \n" // 21436587 (hi, far) + "vpaddd %%ymm2,%%ymm4,%%ymm4 \n" // near+far (lo) + "vpaddd %%ymm3,%%ymm5,%%ymm5 \n" // near+far (hi) + "vpaddd %%ymm2,%%ymm2,%%ymm2 \n" // 2*near (lo) + "vpaddd %%ymm3,%%ymm3,%%ymm3 \n" // 2*near (hi) + "vpaddd %%ymm2,%%ymm4,%%ymm2 \n" // 3*near+far (2, lo) + "vpaddd %%ymm3,%%ymm5,%%ymm3 \n" // 3*near+far (2, hi) + + "vpaddd %%ymm0,%%ymm0,%%ymm4 \n" // 6*near+2*far (1, lo) + "vpaddd %%ymm6,%%ymm2,%%ymm5 \n" // 3*near+far+8 (2, lo) + "vpaddd %%ymm4,%%ymm0,%%ymm4 \n" // 9*near+3*far (1, lo) + "vpaddd %%ymm4,%%ymm5,%%ymm4 \n" // 9 3 3 1 + 8 (1, lo) + "vpsrld $4,%%ymm4,%%ymm4 \n" // ^ div by 16 (1, lo) + + "vpaddd %%ymm2,%%ymm2,%%ymm5 \n" // 6*near+2*far (2, lo) + "vpaddd %%ymm6,%%ymm0,%%ymm0 \n" // 3*near+far+8 (1, lo) + "vpaddd %%ymm5,%%ymm2,%%ymm5 \n" // 9*near+3*far (2, lo) + "vpaddd %%ymm5,%%ymm0,%%ymm5 \n" // 9 3 3 1 + 8 (2, lo) + "vpsrld $4,%%ymm5,%%ymm5 \n" // ^ div by 16 (2, lo) + + "vpaddd %%ymm1,%%ymm1,%%ymm0 \n" // 6*near+2*far (1, hi) + "vpaddd %%ymm6,%%ymm3,%%ymm2 \n" // 3*near+far+8 (2, hi) + "vpaddd %%ymm0,%%ymm1,%%ymm0 \n" // 9*near+3*far (1, hi) + "vpaddd %%ymm0,%%ymm2,%%ymm0 \n" // 9 3 3 1 + 8 (1, hi) + "vpsrld $4,%%ymm0,%%ymm0 \n" // ^ div by 16 (1, hi) + + "vpaddd %%ymm3,%%ymm3,%%ymm2 \n" // 6*near+2*far (2, hi) + "vpaddd %%ymm6,%%ymm1,%%ymm1 \n" // 3*near+far+8 (1, hi) + "vpaddd %%ymm2,%%ymm3,%%ymm2 \n" // 9*near+3*far (2, hi) + "vpaddd %%ymm2,%%ymm1,%%ymm2 \n" // 9 3 3 1 + 8 (2, hi) + "vpsrld $4,%%ymm2,%%ymm2 \n" // ^ div by 16 (2, hi) + + "vpackusdw %%ymm0,%%ymm4,%%ymm4 \n" + "vpshufd $0b11011000,%%ymm4,%%ymm4 \n" + "vmovdqu %%ymm4,(%1) \n" // store above + "vpackusdw %%ymm2,%%ymm5,%%ymm5 \n" + "vpshufd $0b11011000,%%ymm5,%%ymm5 \n" + "vmovdqu %%ymm5,(%1,%4,2) \n" // store below + + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" // 8 pixel to 16 pixel + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(dst_stride) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); +} +#endif + // Reads 16xN bytes and produces 16 shorts at a time. void ScaleAddRow_SSE2(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width) { - asm volatile( + asm volatile("pxor %%xmm5,%%xmm5 \n" - "pxor %%xmm5,%%xmm5 \n" - - // 16 pixel loop. - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm3 \n" - "lea 0x10(%0),%0 \n" // src_ptr += 16 - "movdqu (%1),%%xmm0 \n" - "movdqu 0x10(%1),%%xmm1 \n" - "movdqa %%xmm3,%%xmm2 \n" - "punpcklbw %%xmm5,%%xmm2 \n" - "punpckhbw %%xmm5,%%xmm3 \n" - "paddusw %%xmm2,%%xmm0 \n" - "paddusw %%xmm3,%%xmm1 \n" - "movdqu %%xmm0,(%1) \n" - "movdqu %%xmm1,0x10(%1) \n" - "lea 0x20(%1),%1 \n" - "sub $0x10,%2 \n" - "jg 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(src_width) // %2 - : - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); + // 16 pixel loop. + LABELALIGN + "1: \n" + "movdqu (%0),%%xmm3 \n" + "lea 0x10(%0),%0 \n" // src_ptr += 16 + "movdqu (%1),%%xmm0 \n" + "movdqu 0x10(%1),%%xmm1 \n" + "movdqa %%xmm3,%%xmm2 \n" + "punpcklbw %%xmm5,%%xmm2 \n" + "punpckhbw %%xmm5,%%xmm3 \n" + "paddusw %%xmm2,%%xmm0 \n" + "paddusw %%xmm3,%%xmm1 \n" + "movdqu %%xmm0,(%1) \n" + "movdqu %%xmm1,0x10(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(src_width) // %2 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); } #ifdef HAS_SCALEADDROW_AVX2 @@ -822,140 +2176,812 @@ void ScaleAddRow_SSE2(const uint8_t* src_ptr, void ScaleAddRow_AVX2(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width) { - asm volatile( + asm volatile("vpxor %%ymm5,%%ymm5,%%ymm5 \n" - "vpxor %%ymm5,%%ymm5,%%ymm5 \n" - - LABELALIGN - "1: \n" - "vmovdqu (%0),%%ymm3 \n" - "lea 0x20(%0),%0 \n" // src_ptr += 32 - "vpermq $0xd8,%%ymm3,%%ymm3 \n" - "vpunpcklbw %%ymm5,%%ymm3,%%ymm2 \n" - "vpunpckhbw %%ymm5,%%ymm3,%%ymm3 \n" - "vpaddusw (%1),%%ymm2,%%ymm0 \n" - "vpaddusw 0x20(%1),%%ymm3,%%ymm1 \n" - "vmovdqu %%ymm0,(%1) \n" - "vmovdqu %%ymm1,0x20(%1) \n" - "lea 0x40(%1),%1 \n" - "sub $0x20,%2 \n" - "jg 1b \n" - "vzeroupper \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(src_width) // %2 - : - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm3 \n" + "lea 0x20(%0),%0 \n" // src_ptr += 32 + "vpermq $0xd8,%%ymm3,%%ymm3 \n" + "vpunpcklbw %%ymm5,%%ymm3,%%ymm2 \n" + "vpunpckhbw %%ymm5,%%ymm3,%%ymm3 \n" + "vpaddusw (%1),%%ymm2,%%ymm0 \n" + "vpaddusw 0x20(%1),%%ymm3,%%ymm1 \n" + "vmovdqu %%ymm0,(%1) \n" + "vmovdqu %%ymm1,0x20(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x20,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(src_width) // %2 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"); } #endif // HAS_SCALEADDROW_AVX2 -// Constant for making pixels signed to avoid pmaddubsw -// saturation. -static const uvec8 kFsub80 = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}; - -// Constant for making pixels unsigned and adding .5 for rounding. -static const uvec16 kFadd40 = {0x4040, 0x4040, 0x4040, 0x4040, - 0x4040, 0x4040, 0x4040, 0x4040}; - -// Bilinear column filtering. SSSE3 version. -void ScaleFilterCols_SSSE3(uint8_t* dst_ptr, - const uint8_t* src_ptr, - int dst_width, - int x, - int dx) { - intptr_t x0, x1, temp_pixel; +#ifdef HAS_SCALEADDROW_AVX512BW +// Reads 32xN bytes and accumulates to 32xN shorts at a time, with masked tail. +LIBYUV_TARGET_AVX512BW +void ScaleAddRow_AVX512BW(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int src_width) { + uintptr_t temp; asm volatile( - "movd %6,%%xmm2 \n" - "movd %7,%%xmm3 \n" - "movl $0x04040000,%k2 \n" - "movd %k2,%%xmm5 \n" - "pcmpeqb %%xmm6,%%xmm6 \n" - "psrlw $0x9,%%xmm6 \n" // 0x007f007f - "pcmpeqb %%xmm7,%%xmm7 \n" - "psrlw $15,%%xmm7 \n" // 0x00010001 - - "pextrw $0x1,%%xmm2,%k3 \n" - "subl $0x2,%5 \n" - "jl 29f \n" - "movdqa %%xmm2,%%xmm0 \n" - "paddd %%xmm3,%%xmm0 \n" - "punpckldq %%xmm0,%%xmm2 \n" - "punpckldq %%xmm3,%%xmm3 \n" - "paddd %%xmm3,%%xmm3 \n" - "pextrw $0x3,%%xmm2,%k4 \n" + "sub $0x40,%2 \n" + "jl 2f \n" + // 64 pixel loop. LABELALIGN - "2: \n" - "movdqa %%xmm2,%%xmm1 \n" - "paddd %%xmm3,%%xmm2 \n" - "movzwl 0x00(%1,%3,1),%k2 \n" - "movd %k2,%%xmm0 \n" - "psrlw $0x9,%%xmm1 \n" - "movzwl 0x00(%1,%4,1),%k2 \n" - "movd %k2,%%xmm4 \n" - "pshufb %%xmm5,%%xmm1 \n" - "punpcklwd %%xmm4,%%xmm0 \n" - "psubb %8,%%xmm0 \n" // make pixels signed. - "pxor %%xmm6,%%xmm1 \n" // 128 - f = (f ^ 127 ) + - // 1 - "paddusb %%xmm7,%%xmm1 \n" - "pmaddubsw %%xmm0,%%xmm1 \n" - "pextrw $0x1,%%xmm2,%k3 \n" - "pextrw $0x3,%%xmm2,%k4 \n" - "paddw %9,%%xmm1 \n" // make pixels unsigned. - "psrlw $0x7,%%xmm1 \n" - "packuswb %%xmm1,%%xmm1 \n" - "movd %%xmm1,%k2 \n" - "mov %w2,(%0) \n" - "lea 0x2(%0),%0 \n" - "subl $0x2,%5 \n" - "jge 2b \n" + "1: \n" + "vpmovzxbw (%0),%%zmm0 \n" + "vpmovzxbw 0x20(%0),%%zmm1 \n" + "lea 0x40(%0),%0 \n" + "vpaddusw (%1),%%zmm0,%%zmm0 \n" + "vpaddusw 0x40(%1),%%zmm1,%%zmm1 \n" + "vmovdqu16 %%zmm0,(%1) \n" + "vmovdqu16 %%zmm1,0x40(%1) \n" + "lea 0x80(%1),%1 \n" + "sub $0x40,%2 \n" + "jge 1b \n" - LABELALIGN - "29: \n" - "addl $0x1,%5 \n" - "jl 99f \n" - "movzwl 0x00(%1,%3,1),%k2 \n" - "movd %k2,%%xmm0 \n" - "psrlw $0x9,%%xmm2 \n" - "pshufb %%xmm5,%%xmm2 \n" - "psubb %8,%%xmm0 \n" // make pixels signed. - "pxor %%xmm6,%%xmm2 \n" - "paddusb %%xmm7,%%xmm2 \n" - "pmaddubsw %%xmm0,%%xmm2 \n" - "paddw %9,%%xmm2 \n" // make pixels unsigned. - "psrlw $0x7,%%xmm2 \n" - "packuswb %%xmm2,%%xmm2 \n" - "movd %%xmm2,%k2 \n" - "mov %b2,(%0) \n" - "99: \n" - : "+r"(dst_ptr), // %0 - "+r"(src_ptr), // %1 - "=&a"(temp_pixel), // %2 - "=&r"(x0), // %3 - "=&r"(x1), // %4 -#if defined(__x86_64__) - "+rm"(dst_width) // %5 -#else - "+m"(dst_width) // %5 -#endif - : "rm"(x), // %6 - "rm"(dx), // %7 -#if defined(__x86_64__) - "x"(kFsub80), // %8 - "x"(kFadd40) // %9 -#else - "m"(kFsub80), // %8 - "m"(kFadd40) // %9 -#endif - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", - "xmm7"); + "2: \n" + "add $0x20,%2 \n" + "jl 3f \n" + "vpmovzxbw (%0),%%zmm0 \n" + "lea 0x20(%0),%0 \n" + "vpaddusw (%1),%%zmm0,%%zmm0 \n" + "vmovdqu16 %%zmm0,(%1) \n" + "lea 0x40(%1),%1 \n" + "sub $0x20,%2 \n" + + "3: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "mov $-1,%k3 \n" + "bzhi %k2,%k3,%k3 \n" + "kmovd %k3,%%k1 \n" + "vpmovzxbw (%0),%%zmm0%{%%k1%}%{z%} \n" + "vpaddusw (%1),%%zmm0,%%zmm0%{%%k1%}%{z%}\n" + "vmovdqu16 %%zmm0,(%1)%{%%k1%} \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(src_width), // %2 + "=&r"(temp) // %3 + : + : "memory", "cc", "xmm0", "xmm1", "k1"); } +#endif // HAS_SCALEADDROW_AVX512BW -// Reads 4 pixels, duplicates them and writes 8 pixels. -// Alignment requirement: src_argb 16 byte aligned, dst_argb 16 byte aligned. -void ScaleColsUp2_SSE2(uint8_t* dst_ptr, +#if defined(HAS_SCALEADDCOLS1_AVX512BW) || defined(HAS_SCALEADDCOLS2_AVX512BW) +static const uint8_t kSequence0_15[16] = {0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15}; +#endif + +#ifdef HAS_SCALEADDCOLS1_AVX512BW +LIBYUV_TARGET_AVX512BW +void ScaleAddCols1_AVX512BW(int dst_width, + int boxheight, + int x, + int dx, + const uint16_t* src_ptr, + uint8_t* dst_ptr) { + int boxwidth = dx >> 16; + if (boxwidth < 1) { + boxwidth = 1; + } + int scaleval = 65536 / (boxwidth * boxheight); + src_ptr += (x >> 16); + intptr_t temp, mask; + asm volatile( + "mov $0x0000ffff,%k[temp] \n" + "vpbroadcastd %k[temp],%%zmm6 \n" + "vpbroadcastd %k[scaleval],%%zmm7 \n" + "cmp $4,%k[bw] \n" + "jg 20f \n" + + // Path 1: 1 <= boxwidth <= 4 (16 output pixels per loop). + "vpmovzxbd %[kSeq],%%zmm3 \n" + "vpslld $16,%%zmm3,%%zmm4 \n" + "vpord %%zmm4,%%zmm3,%%zmm3 \n" + "vpbroadcastw %k[bw],%%zmm2 \n" + "vpmullw %%zmm2,%%zmm3,%%zmm3 \n" + "mov $0x00010000,%k[temp] \n" + "vpbroadcastd %k[temp],%%zmm0 \n" + "mov $0x00030002,%k[temp] \n" + "vpbroadcastd %k[temp],%%zmm1 \n" + "vpaddw %%zmm0,%%zmm3,%%zmm4 \n" + "vpaddw %%zmm1,%%zmm3,%%zmm5 \n" + "vpcmpuw $6,%%zmm0,%%zmm2,%%k2 \n" + "vpcmpuw $6,%%zmm1,%%zmm2,%%k3 \n" + "mov %k[bw],%k[temp] \n" + "shl $4,%k[temp] \n" + "mov $-1,%q[mask] \n" + "bzhi %q[temp],%q[mask],%q[mask] \n" + "kmovd %k[mask],%%k1 \n" + "shr $32,%q[mask] \n" + "kmovd %k[mask],%%k4 \n" + "shl $1,%q[temp] \n" + "sub $0x10,%[dst_width] \n" + "jl 12f \n" + + LABELALIGN + "11: \n" + "vmovdqu16 (%[src_ptr]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 0x40(%[src_ptr]),%%zmm1%{%%k4%}%{z%} \n" + "add %q[temp],%[src_ptr] \n" + "vmovdqa64 %%zmm4,%%zmm2 \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm2%{%%k2%}%{z%} \n" + "vmovdqa64 %%zmm5,%%zmm3 \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm3%{%%k3%}%{z%} \n" + "vpsrld $16,%%zmm2,%%zmm0 \n" + "vpandd %%zmm6,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm3,%%zmm1 \n" + "vpandd %%zmm6,%%zmm3,%%zmm3 \n" + "vpaddd %%zmm0,%%zmm2,%%zmm2 \n" + "vpaddd %%zmm1,%%zmm3,%%zmm3 \n" + "vpaddd %%zmm3,%%zmm2,%%zmm2 \n" + "vpmulld %%zmm7,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm2,%%zmm2 \n" + "vpmovdb %%zmm2,(%[dst_ptr]) \n" + "lea 0x10(%[dst_ptr]),%[dst_ptr] \n" + "sub $0x10,%[dst_width] \n" + "jge 11b \n" + + "12: \n" + "add $0x10,%[dst_width] \n" + "jle 99f \n" + "mov %k[dst_width],%k[temp] \n" + "imul %k[bw],%k[temp] \n" + "mov $-1,%q[mask] \n" + "bzhi %q[temp],%q[mask],%q[mask] \n" + "kmovd %k[mask],%%k1 \n" + "shr $32,%q[mask] \n" + "kmovd %k[mask],%%k4 \n" + "vmovdqu16 (%[src_ptr]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 0x40(%[src_ptr]),%%zmm1%{%%k4%}%{z%} \n" + "vmovdqa64 %%zmm4,%%zmm2 \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm2%{%%k2%}%{z%} \n" + "vmovdqa64 %%zmm5,%%zmm3 \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm3%{%%k3%}%{z%} \n" + "vpsrld $16,%%zmm2,%%zmm0 \n" + "vpandd %%zmm6,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm3,%%zmm1 \n" + "vpandd %%zmm6,%%zmm3,%%zmm3 \n" + "vpaddd %%zmm0,%%zmm2,%%zmm2 \n" + "vpaddd %%zmm1,%%zmm3,%%zmm3 \n" + "vpaddd %%zmm3,%%zmm2,%%zmm2 \n" + "vpmulld %%zmm7,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm2,%%zmm2 \n" + "mov $-1,%q[mask] \n" + "bzhi %q[dst_width],%q[mask],%q[mask]\n" + "kmovw %k[mask],%%k1 \n" + "vpmovdb %%zmm2,(%[dst_ptr])%{%%k1%} \n" + "jmp 99f \n" + + // Path 2: 5 <= boxwidth <= 8 (8 output pixels per loop). + "20: \n" + "cmp $8,%k[bw] \n" + "jg 30f \n" + "vpmovzxbq %[kSeq],%%zmm3 \n" + "vpsllq $16,%%zmm3,%%zmm4 \n" + "vpord %%zmm4,%%zmm3,%%zmm3 \n" + "vpsllq $32,%%zmm3,%%zmm4 \n" + "vpord %%zmm4,%%zmm3,%%zmm3 \n" + "vpbroadcastw %k[bw],%%zmm2 \n" + "vpmullw %%zmm2,%%zmm3,%%zmm3 \n" + "movabs $0x0003000200010000,%q[temp] \n" + "vpbroadcastq %q[temp],%%zmm0 \n" + "movabs $0x0007000600050004,%q[temp] \n" + "vpbroadcastq %q[temp],%%zmm1 \n" + "vpaddw %%zmm0,%%zmm3,%%zmm4 \n" + "vpaddw %%zmm1,%%zmm3,%%zmm5 \n" + "vpcmpuw $6,%%zmm1,%%zmm2,%%k3 \n" + "mov %k[bw],%k[temp] \n" + "shl $3,%k[temp] \n" + "mov $-1,%q[mask] \n" + "bzhi %q[temp],%q[mask],%q[mask] \n" + "kmovd %k[mask],%%k1 \n" + "shr $32,%q[mask] \n" + "kmovd %k[mask],%%k4 \n" + "shl $1,%q[temp] \n" + "sub $0x8,%[dst_width] \n" + "jl 22f \n" + + LABELALIGN + "21: \n" + "vmovdqu16 (%[src_ptr]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 0x40(%[src_ptr]),%%zmm1%{%%k4%}%{z%} \n" + "add %q[temp],%[src_ptr] \n" + "vmovdqa64 %%zmm4,%%zmm2 \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm2 \n" + "vmovdqa64 %%zmm5,%%zmm3 \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm3%{%%k3%}%{z%} \n" + "vpsrld $16,%%zmm2,%%zmm0 \n" + "vpandd %%zmm6,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm3,%%zmm1 \n" + "vpandd %%zmm6,%%zmm3,%%zmm3 \n" + "vpaddd %%zmm0,%%zmm2,%%zmm2 \n" + "vpaddd %%zmm1,%%zmm3,%%zmm3 \n" + "vpaddd %%zmm3,%%zmm2,%%zmm2 \n" + "vpsrlq $32,%%zmm2,%%zmm0 \n" + "vpaddd %%zmm0,%%zmm2,%%zmm2 \n" + "vpmulld %%zmm7,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm2,%%zmm2 \n" + "vpmovqb %%zmm2,(%[dst_ptr]) \n" + "lea 0x8(%[dst_ptr]),%[dst_ptr] \n" + "sub $0x8,%[dst_width] \n" + "jge 21b \n" + + "22: \n" + "add $0x8,%[dst_width] \n" + "jle 99f \n" + "mov %k[dst_width],%k[temp] \n" + "imul %k[bw],%k[temp] \n" + "mov $-1,%q[mask] \n" + "bzhi %q[temp],%q[mask],%q[mask] \n" + "kmovd %k[mask],%%k1 \n" + "shr $32,%q[mask] \n" + "kmovd %k[mask],%%k4 \n" + "vmovdqu16 (%[src_ptr]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 0x40(%[src_ptr]),%%zmm1%{%%k4%}%{z%} \n" + "vmovdqa64 %%zmm4,%%zmm2 \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm2 \n" + "vmovdqa64 %%zmm5,%%zmm3 \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm3%{%%k3%}%{z%} \n" + "vpsrld $16,%%zmm2,%%zmm0 \n" + "vpandd %%zmm6,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm3,%%zmm1 \n" + "vpandd %%zmm6,%%zmm3,%%zmm3 \n" + "vpaddd %%zmm0,%%zmm2,%%zmm2 \n" + "vpaddd %%zmm1,%%zmm3,%%zmm3 \n" + "vpaddd %%zmm3,%%zmm2,%%zmm2 \n" + "vpsrlq $32,%%zmm2,%%zmm0 \n" + "vpaddd %%zmm0,%%zmm2,%%zmm2 \n" + "vpmulld %%zmm7,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm2,%%zmm2 \n" + "mov $-1,%q[mask] \n" + "bzhi %q[dst_width],%q[mask],%q[mask]\n" + "kmovw %k[mask],%%k1 \n" + "vpmovqb %%zmm2,(%[dst_ptr])%{%%k1%} \n" + "jmp 99f \n" + + // Path 3: boxwidth >= 9 (ZMM 32-word reduction per output pixel). + "30: \n" + "mov %k[bw],%k[temp] \n" + "and $0x1f,%k[temp] \n" + "mov $-1,%k[mask] \n" + "bzhi %k[temp],%k[mask],%k[mask] \n" + "kmovd %k[mask],%%k1 \n" + + LABELALIGN + "31: \n" + "vpxord %%zmm2,%%zmm2,%%zmm2 \n" + "mov %[src_ptr],%q[mask] \n" + "lea (%[src_ptr],%q[bw],2),%[src_ptr] \n" + "mov %q[bw],%q[temp] \n" + "sub $0x20,%q[temp] \n" + "jl 33f \n" + "32: \n" + "vmovdqu16 (%q[mask]),%%zmm0 \n" + "lea 0x40(%q[mask]),%q[mask] \n" + "vpsrld $16,%%zmm0,%%zmm1 \n" + "vpandd %%zmm6,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm1,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm0,%%zmm2,%%zmm2 \n" + "sub $0x20,%q[temp] \n" + "jge 32b \n" + "33: \n" + "add $0x20,%q[temp] \n" + "jle 34f \n" + "vmovdqu16 (%q[mask]),%%zmm0%{%%k1%}%{z%}\n" + "vpsrld $16,%%zmm0,%%zmm1 \n" + "vpandd %%zmm6,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm1,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm0,%%zmm2,%%zmm2 \n" + "34: \n" + "vextracti32x8 $1,%%zmm2,%%ymm0 \n" + "vpaddd %%ymm0,%%ymm2,%%ymm2 \n" + "vextracti128 $1,%%ymm2,%%xmm0 \n" + "vpaddd %%xmm0,%%xmm2,%%xmm2 \n" + "vpshufd $0xee,%%xmm2,%%xmm0 \n" + "vpaddd %%xmm0,%%xmm2,%%xmm2 \n" + "vpshufd $0x55,%%xmm2,%%xmm0 \n" + "vpaddd %%xmm0,%%xmm2,%%xmm2 \n" + "vpmulld %%xmm7,%%xmm2,%%xmm2 \n" + "vpsrld $16,%%xmm2,%%xmm2 \n" + "vmovd %%xmm2,%k[temp] \n" + "mov %b[temp],(%[dst_ptr]) \n" + "inc %[dst_ptr] \n" + "dec %[dst_width] \n" + "jg 31b \n" + + "99: \n" + "vzeroupper \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [dst_width] "+r"(dst_width), // %[dst_width] + [temp] "=&r"(temp), // %[temp] + [mask] "=&r"(mask) // %[mask] + : [bw] "r"((intptr_t)boxwidth), // %[bw] + [scaleval] "r"(scaleval), // %[scaleval] + [kSeq] "m"(kSequence0_15) // %[kSeq] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7", "k1", "k2", "k3", "k4"); +} +#endif // HAS_SCALEADDCOLS1_AVX512BW + +#ifdef HAS_SCALEADDCOLS2_AVX512BW +LIBYUV_TARGET_AVX512BW +void ScaleAddCols2_AVX512BW(int dst_width, + int boxheight, + int x, + int dx, + const uint16_t* src_ptr, + uint8_t* dst_ptr) { + int minboxwidth = dx >> 16; + int scaletbl[2]; + scaletbl[0] = 65536 / ((minboxwidth < 1 ? 1 : minboxwidth) * boxheight); + scaletbl[1] = + 65536 / (((minboxwidth + 1) < 1 ? 1 : (minboxwidth + 1)) * boxheight); + intptr_t base_ix, temp, mask; + asm volatile( + "mov $0x0000ffff,%k[temp] \n" + "vpbroadcastd %k[temp],%%zmm20 \n" + "vpbroadcastd %[scale0],%%zmm22 \n" + "vpbroadcastd %[scale1],%%zmm23 \n" + "cmpl $1,%[minbw] \n" + "jl 30f \n" + "cmpl $3,%[minbw] \n" + "jg 20f \n" + + // Path 1: 1 <= minboxwidth <= 3 (16 output pixels per loop). + "vpmovzxbd %[kSeq],%%zmm16 \n" + "vpbroadcastd %k[dx],%%zmm17 \n" + "vpmulld %%zmm17,%%zmm16,%%zmm16 \n" + "vpaddd %%zmm17,%%zmm16,%%zmm17 \n" + "mov $0x00010000,%k[temp] \n" + "vpbroadcastd %k[temp],%%zmm18 \n" + "mov $0x00030002,%k[temp] \n" + "vpbroadcastd %k[temp],%%zmm19 \n" + "vpbroadcastd %[minbw],%%zmm21 \n" + "sub $0x10,%[dst_width] \n" + "jl 12f \n" + + LABELALIGN + "11: \n" + "movslq %k[x],%q[base_ix] \n" + "movzwl %w[x],%k[temp] \n" + "vpbroadcastd %k[temp],%%zmm2 \n" + "sar $16,%q[base_ix] \n" + "lea (%k[x],%k[dx],8),%k[temp] \n" + "lea (%k[temp],%k[dx],8),%k[x] \n" + "movslq %k[x],%q[temp] \n" + "sar $16,%q[temp] \n" + "sub %q[base_ix],%q[temp] \n" + "mov $-1,%q[mask] \n" + "bzhi %q[temp],%q[mask],%q[mask] \n" + "kmovd %k[mask],%%k1 \n" + "shr $32,%q[mask] \n" + "kmovd %k[mask],%%k2 \n" + "vmovdqu16 (%[src_ptr],%q[base_ix],2),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 0x40(%[src_ptr],%q[base_ix],2),%%zmm1%{%%k2%}%{z%} \n" + + "vpaddd %%zmm16,%%zmm2,%%zmm3 \n" + "vpaddd %%zmm17,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm3,%%zmm3 \n" + "vpsrld $16,%%zmm2,%%zmm2 \n" + "vpsubd %%zmm3,%%zmm2,%%zmm2 \n" + "vpcmpd $6,%%zmm21,%%zmm2,%%k4 \n" + + "vpslld $16,%%zmm3,%%zmm4 \n" + "vpord %%zmm4,%%zmm3,%%zmm3 \n" + "vpslld $16,%%zmm2,%%zmm4 \n" + "vpord %%zmm4,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm18,%%zmm3,%%zmm4 \n" + "vpaddw %%zmm19,%%zmm3,%%zmm5 \n" + "vpcmpuw $6,%%zmm18,%%zmm2,%%k2 \n" + "vpcmpuw $6,%%zmm19,%%zmm2,%%k3 \n" + + "vpermi2w %%zmm1,%%zmm0,%%zmm4%{%%k2%}%{z%} \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm5%{%%k3%}%{z%} \n" + "vpsrld $16,%%zmm4,%%zmm0 \n" + "vpandd %%zmm20,%%zmm4,%%zmm4 \n" + "vpsrld $16,%%zmm5,%%zmm1 \n" + "vpandd %%zmm20,%%zmm5,%%zmm5 \n" + "vpaddd %%zmm0,%%zmm4,%%zmm4 \n" + "vpaddd %%zmm1,%%zmm5,%%zmm5 \n" + "vpaddd %%zmm5,%%zmm4,%%zmm4 \n" + + "vpblendmd %%zmm23,%%zmm22,%%zmm2%{%%k4%}\n" + "vpmulld %%zmm2,%%zmm4,%%zmm4 \n" + "vpsrld $16,%%zmm4,%%zmm4 \n" + "vpmovdb %%zmm4,(%[dst_ptr]) \n" + "lea 0x10(%[dst_ptr]),%[dst_ptr] \n" + "sub $0x10,%[dst_width] \n" + "jge 11b \n" + + "12: \n" + "add $0x10,%[dst_width] \n" + "jle 99f \n" + "movslq %k[x],%q[base_ix] \n" + "movzwl %w[x],%k[temp] \n" + "vpbroadcastd %k[temp],%%zmm2 \n" + "sar $16,%q[base_ix] \n" + "mov %k[dst_width],%k[temp] \n" + "imul %k[dx],%k[temp] \n" + "add %k[x],%k[temp] \n" + "sar $16,%k[temp] \n" + "movslq %k[temp],%q[temp] \n" + "sub %q[base_ix],%q[temp] \n" + "mov $-1,%q[mask] \n" + "bzhi %q[temp],%q[mask],%q[mask] \n" + "kmovd %k[mask],%%k1 \n" + "shr $32,%q[mask] \n" + "kmovd %k[mask],%%k2 \n" + "vmovdqu16 (%[src_ptr],%q[base_ix],2),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 0x40(%[src_ptr],%q[base_ix],2),%%zmm1%{%%k2%}%{z%} \n" + + "vpaddd %%zmm16,%%zmm2,%%zmm3 \n" + "vpaddd %%zmm17,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm3,%%zmm3 \n" + "vpsrld $16,%%zmm2,%%zmm2 \n" + "vpsubd %%zmm3,%%zmm2,%%zmm2 \n" + "vpcmpd $6,%%zmm21,%%zmm2,%%k4 \n" + + "vpslld $16,%%zmm3,%%zmm4 \n" + "vpord %%zmm4,%%zmm3,%%zmm3 \n" + "vpslld $16,%%zmm2,%%zmm4 \n" + "vpord %%zmm4,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm18,%%zmm3,%%zmm4 \n" + "vpaddw %%zmm19,%%zmm3,%%zmm5 \n" + "vpcmpuw $6,%%zmm18,%%zmm2,%%k2 \n" + "vpcmpuw $6,%%zmm19,%%zmm2,%%k3 \n" + + "vpermi2w %%zmm1,%%zmm0,%%zmm4%{%%k2%}%{z%} \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm5%{%%k3%}%{z%} \n" + "vpsrld $16,%%zmm4,%%zmm0 \n" + "vpandd %%zmm20,%%zmm4,%%zmm4 \n" + "vpsrld $16,%%zmm5,%%zmm1 \n" + "vpandd %%zmm20,%%zmm5,%%zmm5 \n" + "vpaddd %%zmm0,%%zmm4,%%zmm4 \n" + "vpaddd %%zmm1,%%zmm5,%%zmm5 \n" + "vpaddd %%zmm5,%%zmm4,%%zmm4 \n" + + "vpblendmd %%zmm23,%%zmm22,%%zmm2%{%%k4%}\n" + "vpmulld %%zmm2,%%zmm4,%%zmm4 \n" + "vpsrld $16,%%zmm4,%%zmm4 \n" + "mov $-1,%q[mask] \n" + "bzhi %q[dst_width],%q[mask],%q[mask]\n" + "kmovw %k[mask],%%k1 \n" + "vpmovdb %%zmm4,(%[dst_ptr])%{%%k1%} \n" + "jmp 99f \n" + + // Path 2: 4 <= minboxwidth <= 7 (8 output pixels per loop). + "20: \n" + "cmpl $7,%[minbw] \n" + "jg 30f \n" + "vpmovzxbq %[kSeq],%%zmm16 \n" + "movslq %k[dx],%q[temp] \n" + "vpbroadcastq %q[temp],%%zmm17 \n" + "vpmulld %%zmm17,%%zmm16,%%zmm16 \n" + "vpaddq %%zmm17,%%zmm16,%%zmm17 \n" + "movabs $0x0003000200010000,%q[temp] \n" + "vpbroadcastq %q[temp],%%zmm18 \n" + "movabs $0x0007000600050004,%q[temp] \n" + "vpbroadcastq %q[temp],%%zmm19 \n" + "movslq %[minbw],%q[temp] \n" + "vpbroadcastq %q[temp],%%zmm21 \n" + "sub $0x8,%[dst_width] \n" + "jl 22f \n" + + LABELALIGN + "21: \n" + "movslq %k[x],%q[base_ix] \n" + "movzwl %w[x],%k[temp] \n" + "vpbroadcastq %q[temp],%%zmm2 \n" + "sar $16,%q[base_ix] \n" + "lea (%k[x],%k[dx],8),%k[x] \n" + "movslq %k[x],%q[temp] \n" + "sar $16,%q[temp] \n" + "sub %q[base_ix],%q[temp] \n" + "mov $-1,%q[mask] \n" + "bzhi %q[temp],%q[mask],%q[mask] \n" + "kmovd %k[mask],%%k1 \n" + "shr $32,%q[mask] \n" + "kmovd %k[mask],%%k2 \n" + "vmovdqu16 (%[src_ptr],%q[base_ix],2),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 0x40(%[src_ptr],%q[base_ix],2),%%zmm1%{%%k2%}%{z%} \n" + + "vpaddd %%zmm16,%%zmm2,%%zmm3 \n" + "vpaddd %%zmm17,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm3,%%zmm3 \n" + "vpsrld $16,%%zmm2,%%zmm2 \n" + "vpsubd %%zmm3,%%zmm2,%%zmm2 \n" + "vpcmpq $6,%%zmm21,%%zmm2,%%k4 \n" + + "vpsllq $16,%%zmm3,%%zmm4 \n" + "vpord %%zmm4,%%zmm3,%%zmm3 \n" + "vpsllq $32,%%zmm3,%%zmm4 \n" + "vpord %%zmm4,%%zmm3,%%zmm3 \n" + "vpsllq $16,%%zmm2,%%zmm4 \n" + "vpord %%zmm4,%%zmm2,%%zmm2 \n" + "vpsllq $32,%%zmm2,%%zmm4 \n" + "vpord %%zmm4,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm18,%%zmm3,%%zmm4 \n" + "vpaddw %%zmm19,%%zmm3,%%zmm5 \n" + "vpcmpuw $6,%%zmm19,%%zmm2,%%k3 \n" + + "vpermi2w %%zmm1,%%zmm0,%%zmm4 \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm5%{%%k3%}%{z%} \n" + "vpsrld $16,%%zmm4,%%zmm0 \n" + "vpandd %%zmm20,%%zmm4,%%zmm4 \n" + "vpsrld $16,%%zmm5,%%zmm1 \n" + "vpandd %%zmm20,%%zmm5,%%zmm5 \n" + "vpaddd %%zmm0,%%zmm4,%%zmm4 \n" + "vpaddd %%zmm1,%%zmm5,%%zmm5 \n" + "vpaddd %%zmm5,%%zmm4,%%zmm4 \n" + "vpsrlq $32,%%zmm4,%%zmm0 \n" + "vpaddd %%zmm0,%%zmm4,%%zmm4 \n" + + "vpblendmq %%zmm23,%%zmm22,%%zmm2%{%%k4%}\n" + "vpmulld %%zmm2,%%zmm4,%%zmm4 \n" + "vpsrld $16,%%zmm4,%%zmm4 \n" + "vpmovqb %%zmm4,(%[dst_ptr]) \n" + "lea 0x8(%[dst_ptr]),%[dst_ptr] \n" + "sub $0x8,%[dst_width] \n" + "jge 21b \n" + + "22: \n" + "add $0x8,%[dst_width] \n" + "jle 99f \n" + "movslq %k[x],%q[base_ix] \n" + "movzwl %w[x],%k[temp] \n" + "vpbroadcastq %q[temp],%%zmm2 \n" + "sar $16,%q[base_ix] \n" + "mov %k[dst_width],%k[temp] \n" + "imul %k[dx],%k[temp] \n" + "add %k[x],%k[temp] \n" + "sar $16,%k[temp] \n" + "movslq %k[temp],%q[temp] \n" + "sub %q[base_ix],%q[temp] \n" + "mov $-1,%q[mask] \n" + "bzhi %q[temp],%q[mask],%q[mask] \n" + "kmovd %k[mask],%%k1 \n" + "shr $32,%q[mask] \n" + "kmovd %k[mask],%%k2 \n" + "vmovdqu16 (%[src_ptr],%q[base_ix],2),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu16 0x40(%[src_ptr],%q[base_ix],2),%%zmm1%{%%k2%}%{z%} \n" + + "vpaddd %%zmm16,%%zmm2,%%zmm3 \n" + "vpaddd %%zmm17,%%zmm2,%%zmm2 \n" + "vpsrld $16,%%zmm3,%%zmm3 \n" + "vpsrld $16,%%zmm2,%%zmm2 \n" + "vpsubd %%zmm3,%%zmm2,%%zmm2 \n" + "vpcmpq $6,%%zmm21,%%zmm2,%%k4 \n" + + "vpsllq $16,%%zmm3,%%zmm4 \n" + "vpord %%zmm4,%%zmm3,%%zmm3 \n" + "vpsllq $32,%%zmm3,%%zmm4 \n" + "vpord %%zmm4,%%zmm3,%%zmm3 \n" + "vpsllq $16,%%zmm2,%%zmm4 \n" + "vpord %%zmm4,%%zmm2,%%zmm2 \n" + "vpsllq $32,%%zmm2,%%zmm4 \n" + "vpord %%zmm4,%%zmm2,%%zmm2 \n" + "vpaddw %%zmm18,%%zmm3,%%zmm4 \n" + "vpaddw %%zmm19,%%zmm3,%%zmm5 \n" + "vpcmpuw $6,%%zmm19,%%zmm2,%%k3 \n" + + "vpermi2w %%zmm1,%%zmm0,%%zmm4 \n" + "vpermi2w %%zmm1,%%zmm0,%%zmm5%{%%k3%}%{z%} \n" + "vpsrld $16,%%zmm4,%%zmm0 \n" + "vpandd %%zmm20,%%zmm4,%%zmm4 \n" + "vpsrld $16,%%zmm5,%%zmm1 \n" + "vpandd %%zmm20,%%zmm5,%%zmm5 \n" + "vpaddd %%zmm0,%%zmm4,%%zmm4 \n" + "vpaddd %%zmm1,%%zmm5,%%zmm5 \n" + "vpaddd %%zmm5,%%zmm4,%%zmm4 \n" + "vpsrlq $32,%%zmm4,%%zmm0 \n" + "vpaddd %%zmm0,%%zmm4,%%zmm4 \n" + + "vpblendmq %%zmm23,%%zmm22,%%zmm2%{%%k4%}\n" + "vpmulld %%zmm2,%%zmm4,%%zmm4 \n" + "vpsrld $16,%%zmm4,%%zmm4 \n" + "mov $-1,%q[mask] \n" + "bzhi %q[dst_width],%q[mask],%q[mask]\n" + "kmovw %k[mask],%%k1 \n" + "vpmovqb %%zmm4,(%[dst_ptr])%{%%k1%} \n" + "jmp 99f \n" + + // Path 3: minboxwidth >= 8 or minboxwidth < 1. + LABELALIGN + "30: \n" + "movslq %k[x],%q[base_ix] \n" + "sar $16,%q[base_ix] \n" + "add %k[dx],%k[x] \n" + "movslq %k[x],%q[temp] \n" + "sar $16,%q[temp] \n" + "sub %q[base_ix],%q[temp] \n" + "cmp $1,%q[temp] \n" + "jge 31f \n" + "mov $1,%q[temp] \n" + "31: \n" + "vmovdqa32 %%xmm22,%%xmm3 \n" + "cmp %k[temp],%[minbw] \n" + "jge 32f \n" + "vmovdqa32 %%xmm23,%%xmm3 \n" + "32: \n" + "vpxord %%zmm2,%%zmm2,%%zmm2 \n" + "lea (%[src_ptr],%q[base_ix],2),%q[base_ix] \n" + "sub $0x20,%q[temp] \n" + "jl 34f \n" + "33: \n" + "vmovdqu16 (%q[base_ix]),%%zmm0 \n" + "lea 0x40(%q[base_ix]),%q[base_ix] \n" + "vpsrld $16,%%zmm0,%%zmm1 \n" + "vpandd %%zmm20,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm1,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm0,%%zmm2,%%zmm2 \n" + "sub $0x20,%q[temp] \n" + "jge 33b \n" + "34: \n" + "add $0x20,%q[temp] \n" + "jle 35f \n" + "mov $-1,%q[mask] \n" + "bzhi %q[temp],%q[mask],%q[mask] \n" + "kmovd %k[mask],%%k1 \n" + "vmovdqu16 (%q[base_ix]),%%zmm0%{%%k1%}%{z%} \n" + "vpsrld $16,%%zmm0,%%zmm1 \n" + "vpandd %%zmm20,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm1,%%zmm0,%%zmm0 \n" + "vpaddd %%zmm0,%%zmm2,%%zmm2 \n" + "35: \n" + "vextracti32x8 $1,%%zmm2,%%ymm0 \n" + "vpaddd %%ymm0,%%ymm2,%%ymm2 \n" + "vextracti128 $1,%%ymm2,%%xmm0 \n" + "vpaddd %%xmm0,%%xmm2,%%xmm2 \n" + "vpshufd $0xee,%%xmm2,%%xmm0 \n" + "vpaddd %%xmm0,%%xmm2,%%xmm2 \n" + "vpshufd $0x55,%%xmm2,%%xmm0 \n" + "vpaddd %%xmm0,%%xmm2,%%xmm2 \n" + "vpmulld %%xmm3,%%xmm2,%%xmm2 \n" + "vpsrld $16,%%xmm2,%%xmm2 \n" + "vmovd %%xmm2,%k[temp] \n" + "mov %b[temp],(%[dst_ptr]) \n" + "inc %[dst_ptr] \n" + "dec %[dst_width] \n" + "jg 30b \n" + + "99: \n" + "vzeroupper \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [dst_width] "+r"(dst_width), // %[dst_width] + [x] "+r"(x), // %[x] + [base_ix] "=&r"(base_ix), // %[base_ix] + [temp] "=&r"(temp), // %[temp] + [mask] "=&r"(mask) // %[mask] + : [dx] "r"(dx), // %[dx] + [minbw] "m"(minboxwidth), // %[minbw] + [scale0] "m"(scaletbl[0]), // %[scale0] + [scale1] "m"(scaletbl[1]), // %[scale1] + [kSeq] "m"(kSequence0_15) // %[kSeq] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm16", + "xmm17", "xmm18", "xmm19", "xmm20", "xmm21", "xmm22", "xmm23", "k1", + "k2", "k3", "k4"); +} +#endif // HAS_SCALEADDCOLS2_AVX512BW + +#ifdef HAS_SCALEFILTERCOLS_AVX2 +static const int32_t kStep0_7_Filter[8] = {0, 1, 2, 3, 4, 5, 6, 7}; +static const uvec8 kShufFracCols = {0, 0, 4, 4, 8, 8, 12, 12, + 128, 128, 128, 128, 128, 128, 128, 128}; + +// Bilinear column filtering. AVX2 version. +void ScaleFilterCols_AVX2(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx) { + int n = dst_width & ~7; + int r = dst_width & 7; + if (n > 0) { + SIMD_ALIGNED(int32_t xi_buf[8]); + int32_t* xi_ptr = xi_buf; + uintptr_t tmp; + int loop_n = n; + asm volatile( + "vpbroadcastd %[x],%%ymm2 \n" + "vpbroadcastd %[dx],%%ymm3 \n" + "vpmulld %[kStep],%%ymm3,%%ymm0 \n" + "vpaddd %%ymm0,%%ymm2,%%ymm2 \n" + "vpslld $0x3,%%ymm3,%%ymm3 \n" + "vbroadcasti128 %[kShufFrac],%%ymm5 \n" + "vpcmpeqb %%xmm6,%%xmm6,%%xmm6 \n" + "vpsrlw $0x8,%%xmm6,%%xmm7 \n" // 0x00ff + "vpsrlw $0x9,%%xmm6,%%xmm6 \n" // 0x007f + + LABELALIGN + "1: \n" + "vpsrad $0x10,%%ymm2,%%ymm0 \n" + "vmovdqu %%ymm0,(%[xi]) \n" + "vpsrlw $0x9,%%ymm2,%%ymm1 \n" + "vpaddd %%ymm3,%%ymm2,%%ymm2 \n" + "vpshufb %%ymm5,%%ymm1,%%ymm1 \n" + "vpermq $0xd8,%%ymm1,%%ymm1 \n" + "vpxor %%xmm6,%%xmm1,%%xmm1 \n" +#if defined(__x86_64__) + "movslq 0x00(%[xi]),%q[tmp] \n" + "vpinsrw $0x0,0x00(%[src],%q[tmp],1),%%xmm0,%%xmm0 \n" + "movslq 0x04(%[xi]),%q[tmp] \n" + "vpinsrw $0x1,0x00(%[src],%q[tmp],1),%%xmm0,%%xmm0 \n" + "movslq 0x08(%[xi]),%q[tmp] \n" + "vpinsrw $0x2,0x00(%[src],%q[tmp],1),%%xmm0,%%xmm0 \n" + "movslq 0x0c(%[xi]),%q[tmp] \n" + "vpinsrw $0x3,0x00(%[src],%q[tmp],1),%%xmm0,%%xmm0 \n" + "movslq 0x10(%[xi]),%q[tmp] \n" + "vpinsrw $0x4,0x00(%[src],%q[tmp],1),%%xmm0,%%xmm0 \n" + "movslq 0x14(%[xi]),%q[tmp] \n" + "vpinsrw $0x5,0x00(%[src],%q[tmp],1),%%xmm0,%%xmm0 \n" + "movslq 0x18(%[xi]),%q[tmp] \n" + "vpinsrw $0x6,0x00(%[src],%q[tmp],1),%%xmm0,%%xmm0 \n" + "movslq 0x1c(%[xi]),%q[tmp] \n" + "vpinsrw $0x7,0x00(%[src],%q[tmp],1),%%xmm0,%%xmm0 \n" +#else + "mov 0x00(%[xi]),%[tmp] \n" + "vpinsrw $0x0,0x00(%[src],%[tmp],1),%%xmm0,%%xmm0 \n" + "mov 0x04(%[xi]),%[tmp] \n" + "vpinsrw $0x1,0x00(%[src],%[tmp],1),%%xmm0,%%xmm0 \n" + "mov 0x08(%[xi]),%[tmp] \n" + "vpinsrw $0x2,0x00(%[src],%[tmp],1),%%xmm0,%%xmm0 \n" + "mov 0x0c(%[xi]),%[tmp] \n" + "vpinsrw $0x3,0x00(%[src],%[tmp],1),%%xmm0,%%xmm0 \n" + "mov 0x10(%[xi]),%[tmp] \n" + "vpinsrw $0x4,0x00(%[src],%[tmp],1),%%xmm0,%%xmm0 \n" + "mov 0x14(%[xi]),%[tmp] \n" + "vpinsrw $0x5,0x00(%[src],%[tmp],1),%%xmm0,%%xmm0 \n" + "mov 0x18(%[xi]),%[tmp] \n" + "vpinsrw $0x6,0x00(%[src],%[tmp],1),%%xmm0,%%xmm0 \n" + "mov 0x1c(%[xi]),%[tmp] \n" + "vpinsrw $0x7,0x00(%[src],%[tmp],1),%%xmm0,%%xmm0 \n" +#endif + "vpand %%xmm7,%%xmm0,%%xmm4 \n" + "vpmaddubsw %%xmm1,%%xmm0,%%xmm0 \n" + "vpaddw %%xmm4,%%xmm0,%%xmm0 \n" + "vpsubw %%xmm6,%%xmm7,%%xmm4 \n" + "vpsrlw $0x1,%%xmm4,%%xmm4 \n" // 0x0040 + "vpaddw %%xmm4,%%xmm0,%%xmm0 \n" + "vpsrlw $0x7,%%xmm0,%%xmm0 \n" + "vpackuswb %%xmm0,%%xmm0,%%xmm0 \n" + "vmovq %%xmm0,(%[dst]) \n" + "lea 0x8(%[dst]),%[dst] \n" + "subl $0x8,%[n] \n" + "jg 1b \n" + "vzeroupper \n" + : [dst] "+r"(dst_ptr), [n] "+rm"(loop_n), [tmp] "=&r"(tmp) + : [src] "r"(src_ptr), [xi] "r"(xi_ptr), [x] "m"(x), [dx] "m"(dx), + [kStep] "m"(kStep0_7_Filter), [kShufFrac] "m"(kShufFracCols) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); + x = (int)((uint32_t)x + (uint32_t)n * (uint32_t)dx); + } + for (int j = 0; j < r; ++j) { + int xi = x >> 16; + int a = src_ptr[xi]; + int b = src_ptr[xi + 1]; + dst_ptr[j] = (uint8_t)(a + ((((x & 0xffff) >> 9) * (b - a) + 0x40) >> 7)); + x = (int)((uint32_t)x + (uint32_t)dx); + } +} +#endif // HAS_SCALEFILTERCOLS_AVX2 + +#ifdef HAS_SCALECOLSUP2_AVX2 +// Reads 16 pixels, duplicates them and writes 32 pixels (plus 16/8 tails). +void ScaleColsUp2_AVX2(uint8_t* dst_ptr, const uint8_t* src_ptr, int dst_width, int x, @@ -963,263 +2989,260 @@ void ScaleColsUp2_SSE2(uint8_t* dst_ptr, (void)x; (void)dx; asm volatile( + "sub $0x20,%2 \n" + "jl 2f \n" LABELALIGN - "1: \n" - "movdqu (%1),%%xmm0 \n" - "lea 0x10(%1),%1 \n" - "movdqa %%xmm0,%%xmm1 \n" - "punpcklbw %%xmm0,%%xmm0 \n" - "punpckhbw %%xmm1,%%xmm1 \n" - "movdqu %%xmm0,(%0) \n" - "movdqu %%xmm1,0x10(%0) \n" - "lea 0x20(%0),%0 \n" - "sub $0x20,%2 \n" - "jg 1b \n" + "1: \n" + "vmovdqu (%1),%%xmm0 \n" + "lea 0x10(%1),%1 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpunpcklbw %%ymm0,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%0) \n" + "lea 0x20(%0),%0 \n" + "sub $0x20,%2 \n" + "jge 1b \n" + "2: \n" + "add $0x20,%2 \n" + "jle 99f \n" + "test $0x10,%2 \n" + "je 3f \n" + "vmovq (%1),%%xmm0 \n" + "lea 0x8(%1),%1 \n" + "vpunpcklbw %%xmm0,%%xmm0,%%xmm0 \n" + "vmovdqu %%xmm0,(%0) \n" + "lea 0x10(%0),%0 \n" + + "3: \n" + "test $0x8,%2 \n" + "je 99f \n" + "vmovd (%1),%%xmm0 \n" + "vpunpcklbw %%xmm0,%%xmm0,%%xmm0 \n" + "vmovq %%xmm0,(%0) \n" + + "99: \n" + "vzeroupper \n" : "+r"(dst_ptr), // %0 "+r"(src_ptr), // %1 "+r"(dst_width) // %2 - ::"memory", - "cc", "xmm0", "xmm1"); + : + : "memory", "cc", "xmm0"); } +#endif // HAS_SCALECOLSUP2_AVX2 -void ScaleARGBRowDown2_SSE2(const uint8_t* src_argb, +#ifdef HAS_SCALEARGBROWDOWN2_AVX2 +void ScaleARGBRowDown2_AVX2(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width) { (void)src_stride; asm volatile( - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "shufps $0xdd,%%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x4,%2 \n" - "jg 1b \n" + "1: \n" + "vmovups (%0),%%ymm0 \n" + "vmovups 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vshufps $0xdd,%%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovups %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(dst_width) // %2 - ::"memory", - "cc", "xmm0", "xmm1"); + : + : "memory", "cc", "xmm0", "xmm1"); } -void ScaleARGBRowDown2Linear_SSE2(const uint8_t* src_argb, +void ScaleARGBRowDown2Linear_AVX2(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width) { (void)src_stride; asm volatile( - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "lea 0x20(%0),%0 \n" - "movdqa %%xmm0,%%xmm2 \n" - "shufps $0x88,%%xmm1,%%xmm0 \n" - "shufps $0xdd,%%xmm1,%%xmm2 \n" - "pavgb %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x4,%2 \n" - "jg 1b \n" + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vshufps $0x88,%%ymm1,%%ymm0,%%ymm2 \n" + "vshufps $0xdd,%%ymm1,%%ymm0,%%ymm0 \n" + "vpavgb %%ymm0,%%ymm2,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(dst_width) // %2 - ::"memory", - "cc", "xmm0", "xmm1"); + : + : "memory", "cc", "xmm0", "xmm1", "xmm2"); } -void ScaleARGBRowDown2Box_SSE2(const uint8_t* src_argb, +void ScaleARGBRowDown2Box_AVX2(const uint8_t* src_argb, ptrdiff_t src_stride, uint8_t* dst_argb, int dst_width) { asm volatile( - LABELALIGN - "1: \n" - "movdqu (%0),%%xmm0 \n" - "movdqu 0x10(%0),%%xmm1 \n" - "movdqu 0x00(%0,%3,1),%%xmm2 \n" - "movdqu 0x10(%0,%3,1),%%xmm3 \n" - "lea 0x20(%0),%0 \n" - "pavgb %%xmm2,%%xmm0 \n" - "pavgb %%xmm3,%%xmm1 \n" - "movdqa %%xmm0,%%xmm2 \n" - "shufps $0x88,%%xmm1,%%xmm0 \n" - "shufps $0xdd,%%xmm1,%%xmm2 \n" - "pavgb %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%1) \n" - "lea 0x10(%1),%1 \n" - "sub $0x4,%2 \n" - "jg 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_argb), // %1 - "+r"(dst_width) // %2 - : "r"((intptr_t)(src_stride)) // %3 + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "vmovdqu 0x00(%0,%3,1),%%ymm2 \n" + "vmovdqu 0x20(%0,%3,1),%%ymm3 \n" + "lea 0x40(%0),%0 \n" + "vpavgb %%ymm2,%%ymm0,%%ymm0 \n" + "vpavgb %%ymm3,%%ymm1,%%ymm1 \n" + "vshufps $0x88,%%ymm1,%%ymm0,%%ymm2 \n" + "vshufps $0xdd,%%ymm1,%%ymm0,%%ymm0 \n" + "vpavgb %%ymm0,%%ymm2,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_argb), // %0 + "+r"(dst_argb), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride) // %3 : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3"); } +#endif // HAS_SCALEARGBROWDOWN2_AVX2 -// Reads 4 pixels at a time. -// Alignment requirement: dst_argb 16 byte aligned. -void ScaleARGBRowDownEven_SSE2(const uint8_t* src_argb, +#ifdef HAS_SCALEARGBROWDOWNEVEN_AVX2 +static const int32_t kStep0_7_Even[8] = {0, 1, 2, 3, 4, 5, 6, 7}; + +// Reads 8 pixels at a time. +void ScaleARGBRowDownEven_AVX2(const uint8_t* src_argb, ptrdiff_t src_stride, int src_stepx, uint8_t* dst_argb, int dst_width) { - intptr_t src_stepx_x4 = (intptr_t)(src_stepx); - intptr_t src_stepx_x12; + ptrdiff_t src_stepx_x32 = (ptrdiff_t)src_stepx * 32; (void)src_stride; asm volatile( - "lea 0x00(,%1,4),%1 \n" - "lea 0x00(%1,%1,2),%4 \n" + "vpbroadcastd %[stepx],%%ymm2 \n" + "vpmulld %[kStep],%%ymm2,%%ymm2 \n" LABELALIGN - "1: \n" - "movd (%0),%%xmm0 \n" - "movd 0x00(%0,%1,1),%%xmm1 \n" - "punpckldq %%xmm1,%%xmm0 \n" - "movd 0x00(%0,%1,2),%%xmm2 \n" - "movd 0x00(%0,%4,1),%%xmm3 \n" - "lea 0x00(%0,%1,4),%0 \n" - "punpckldq %%xmm3,%%xmm2 \n" - "punpcklqdq %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%2) \n" - "lea 0x10(%2),%2 \n" - "sub $0x4,%3 \n" - "jg 1b \n" - : "+r"(src_argb), // %0 - "+r"(src_stepx_x4), // %1 - "+r"(dst_argb), // %2 - "+r"(dst_width), // %3 - "=&r"(src_stepx_x12) // %4 - ::"memory", - "cc", "xmm0", "xmm1", "xmm2", "xmm3"); + "1: \n" + "vpcmpeqd %%ymm3,%%ymm3,%%ymm3 \n" + "vpgatherdd %%ymm3,(%[src],%%ymm2,4),%%ymm0 \n" + "add %[step32],%[src] \n" + "vmovdqu %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "sub $0x8,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src] "+r"(src_argb), [dst] "+r"(dst_argb), [width] "+rm"(dst_width) + : [step32] "r"(src_stepx_x32), [stepx] "m"(src_stepx), + [kStep] "m"(kStep0_7_Even) + : "memory", "cc", "xmm0", "xmm2", "xmm3"); } -// Blends four 2x2 to 4x1. -// Alignment requirement: dst_argb 16 byte aligned. -void ScaleARGBRowDownEvenBox_SSE2(const uint8_t* src_argb, +// Blends eight 2x2 to 8x1. +void ScaleARGBRowDownEvenBox_AVX2(const uint8_t* src_argb, ptrdiff_t src_stride, int src_stepx, uint8_t* dst_argb, int dst_width) { - intptr_t src_stepx_x4 = (intptr_t)(src_stepx); - intptr_t src_stepx_x12; - intptr_t row1 = (intptr_t)(src_stride); + const uint8_t* row1 = src_argb + src_stride; + ptrdiff_t step4_bytes = (ptrdiff_t)src_stepx * 16; asm volatile( - "lea 0x00(,%1,4),%1 \n" - "lea 0x00(%1,%1,2),%4 \n" - "lea 0x00(%0,%5,1),%5 \n" + "vmovd %[stepx],%%xmm4 \n" + "vpshufd $0x0,%%xmm4,%%xmm4 \n" + "vpmulld %[kStep],%%xmm4,%%xmm4 \n" LABELALIGN - "1: \n" - "movq (%0),%%xmm0 \n" - "movhps 0x00(%0,%1,1),%%xmm0 \n" - "movq 0x00(%0,%1,2),%%xmm1 \n" - "movhps 0x00(%0,%4,1),%%xmm1 \n" - "lea 0x00(%0,%1,4),%0 \n" - "movq (%5),%%xmm2 \n" - "movhps 0x00(%5,%1,1),%%xmm2 \n" - "movq 0x00(%5,%1,2),%%xmm3 \n" - "movhps 0x00(%5,%4,1),%%xmm3 \n" - "lea 0x00(%5,%1,4),%5 \n" - "pavgb %%xmm2,%%xmm0 \n" - "pavgb %%xmm3,%%xmm1 \n" - "movdqa %%xmm0,%%xmm2 \n" - "shufps $0x88,%%xmm1,%%xmm0 \n" - "shufps $0xdd,%%xmm1,%%xmm2 \n" - "pavgb %%xmm2,%%xmm0 \n" - "movdqu %%xmm0,(%2) \n" - "lea 0x10(%2),%2 \n" - "sub $0x4,%3 \n" - "jg 1b \n" - : "+r"(src_argb), // %0 - "+r"(src_stepx_x4), // %1 - "+r"(dst_argb), // %2 - "+rm"(dst_width), // %3 - "=&r"(src_stepx_x12), // %4 - "+r"(row1) // %5 - ::"memory", - "cc", "xmm0", "xmm1", "xmm2", "xmm3"); + "1: \n" + "vpcmpeqd %%ymm5,%%ymm5,%%ymm5 \n" + "vpgatherdq %%ymm5,(%[row0],%%xmm4,4),%%ymm0 \n" + "vpcmpeqd %%ymm5,%%ymm5,%%ymm5 \n" + "vpgatherdq %%ymm5,(%[row1],%%xmm4,4),%%ymm2 \n" + "add %[step4],%[row0] \n" + "add %[step4],%[row1] \n" + "vpcmpeqd %%ymm5,%%ymm5,%%ymm5 \n" + "vpgatherdq %%ymm5,(%[row0],%%xmm4,4),%%ymm1 \n" + "vpcmpeqd %%ymm5,%%ymm5,%%ymm5 \n" + "vpgatherdq %%ymm5,(%[row1],%%xmm4,4),%%ymm3 \n" + "add %[step4],%[row0] \n" + "add %[step4],%[row1] \n" + "vpavgb %%ymm2,%%ymm0,%%ymm0 \n" + "vpavgb %%ymm3,%%ymm1,%%ymm1 \n" + "vshufps $0x88,%%ymm1,%%ymm0,%%ymm2 \n" + "vshufps $0xdd,%%ymm1,%%ymm0,%%ymm0 \n" + "vpavgb %%ymm0,%%ymm2,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "subl $0x8,%[width] \n" + "jg 1b \n" + "vzeroupper \n" + : [row0] "+r"(src_argb), [row1] "+r"(row1), [dst] "+r"(dst_argb), + [width] "+rm"(dst_width) + : [step4] "r"(step4_bytes), [stepx] "m"(src_stepx), + [kStep] "m"(kStep0_7_Even) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); } +#endif // HAS_SCALEARGBROWDOWNEVEN_AVX2 -void ScaleARGBCols_SSE2(uint8_t* dst_argb, +#ifdef HAS_SCALEARGBCOLS_AVX2 +static const int32_t kStep0_7_Cols[8] = {0, 1, 2, 3, 4, 5, 6, 7}; + +void ScaleARGBCols_AVX2(uint8_t* dst_argb, const uint8_t* src_argb, int dst_width, int x, int dx) { - intptr_t x0, x1; - asm volatile( - "movd %5,%%xmm2 \n" - "movd %6,%%xmm3 \n" - "pshufd $0x0,%%xmm2,%%xmm2 \n" - "pshufd $0x11,%%xmm3,%%xmm0 \n" - "paddd %%xmm0,%%xmm2 \n" - "paddd %%xmm3,%%xmm3 \n" - "pshufd $0x5,%%xmm3,%%xmm0 \n" - "paddd %%xmm0,%%xmm2 \n" - "paddd %%xmm3,%%xmm3 \n" - "pshufd $0x0,%%xmm3,%%xmm3 \n" - "pextrw $0x1,%%xmm2,%k0 \n" - "pextrw $0x3,%%xmm2,%k1 \n" - "cmp $0x0,%4 \n" - "jl 99f \n" - "sub $0x4,%4 \n" - "jl 49f \n" + int n = dst_width & ~7; + int r = dst_width & 7; + if (n > 0) { + int loop_n = n; + asm volatile( + "vpbroadcastd %[x],%%ymm2 \n" + "vpbroadcastd %[dx],%%ymm3 \n" + "vpmulld %[kStep],%%ymm3,%%ymm0 \n" + "vpaddd %%ymm0,%%ymm2,%%ymm2 \n" + "vpslld $0x3,%%ymm3,%%ymm3 \n" - LABELALIGN - "40: \n" - "movd 0x00(%3,%0,4),%%xmm0 \n" - "movd 0x00(%3,%1,4),%%xmm1 \n" - "pextrw $0x5,%%xmm2,%k0 \n" - "pextrw $0x7,%%xmm2,%k1 \n" - "paddd %%xmm3,%%xmm2 \n" - "punpckldq %%xmm1,%%xmm0 \n" - "movd 0x00(%3,%0,4),%%xmm1 \n" - "movd 0x00(%3,%1,4),%%xmm4 \n" - "pextrw $0x1,%%xmm2,%k0 \n" - "pextrw $0x3,%%xmm2,%k1 \n" - "punpckldq %%xmm4,%%xmm1 \n" - "punpcklqdq %%xmm1,%%xmm0 \n" - "movdqu %%xmm0,(%2) \n" - "lea 0x10(%2),%2 \n" - "sub $0x4,%4 \n" - "jge 40b \n" - - "49: \n" - "test $0x2,%4 \n" - "je 29f \n" - "movd 0x00(%3,%0,4),%%xmm0 \n" - "movd 0x00(%3,%1,4),%%xmm1 \n" - "pextrw $0x5,%%xmm2,%k0 \n" - "punpckldq %%xmm1,%%xmm0 \n" - "movq %%xmm0,(%2) \n" - "lea 0x8(%2),%2 \n" - "29: \n" - "test $0x1,%4 \n" - "je 99f \n" - "movd 0x00(%3,%0,4),%%xmm0 \n" - "movd %%xmm0,(%2) \n" - "99: \n" - : "=&a"(x0), // %0 - "=&d"(x1), // %1 - "+r"(dst_argb), // %2 - "+r"(src_argb), // %3 - "+r"(dst_width) // %4 - : "rm"(x), // %5 - "rm"(dx) // %6 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); + LABELALIGN + "1: \n" + "vpsrad $0x10,%%ymm2,%%ymm0 \n" + "vpaddd %%ymm3,%%ymm2,%%ymm2 \n" + "vpcmpeqd %%ymm4,%%ymm4,%%ymm4 \n" + "vpgatherdd %%ymm4,(%[src],%%ymm0,4),%%ymm1 \n" + "vmovdqu %%ymm1,(%[dst]) \n" + "lea 0x20(%[dst]),%[dst] \n" + "subl $0x8,%[n] \n" + "jg 1b \n" + "vzeroupper \n" + : [dst] "+r"(dst_argb), [n] "+rm"(loop_n) + : [src] "r"(src_argb), [x] "m"(x), [dx] "m"(dx), + [kStep] "m"(kStep0_7_Cols) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); + x = (int)((uint32_t)x + (uint32_t)n * (uint32_t)dx); + } + for (int j = 0; j < r; ++j) { + const uint8_t* src = src_argb + (ptrdiff_t)(x >> 16) * 4; + dst_argb[0] = src[0]; + dst_argb[1] = src[1]; + dst_argb[2] = src[2]; + dst_argb[3] = src[3]; + dst_argb += 4; + x = (int)((uint32_t)x + (uint32_t)dx); + } } +#endif // HAS_SCALEARGBCOLS_AVX2 +#ifdef HAS_SCALEARGBCOLSUP2_AVX2 // Reads 4 pixels, duplicates them and writes 8 pixels. -// Alignment requirement: src_argb 16 byte aligned, dst_argb 16 byte aligned. -void ScaleARGBColsUp2_SSE2(uint8_t* dst_argb, +void ScaleARGBColsUp2_AVX2(uint8_t* dst_argb, const uint8_t* src_argb, int dst_width, int x, @@ -1227,26 +3250,27 @@ void ScaleARGBColsUp2_SSE2(uint8_t* dst_argb, (void)x; (void)dx; asm volatile( - LABELALIGN - "1: \n" - "movdqu (%1),%%xmm0 \n" - "lea 0x10(%1),%1 \n" - "movdqa %%xmm0,%%xmm1 \n" - "punpckldq %%xmm0,%%xmm0 \n" - "punpckhdq %%xmm1,%%xmm1 \n" - "movdqu %%xmm0,(%0) \n" - "movdqu %%xmm1,0x10(%0) \n" - "lea 0x20(%0),%0 \n" - "sub $0x8,%2 \n" - "jg 1b \n" - + "1: \n" + "vmovdqu (%1),%%xmm0 \n" + "lea 0x10(%1),%1 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vpunpckldq %%ymm0,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%0) \n" + "lea 0x20(%0),%0 \n" + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" : "+r"(dst_argb), // %0 "+r"(src_argb), // %1 "+r"(dst_width) // %2 - ::"memory", - "cc", "xmm0", "xmm1"); + : + : "memory", "cc", "xmm0"); } +#endif // HAS_SCALEARGBCOLSUP2_AVX2 + +#ifdef HAS_SCALEARGBFILTERCOLS_AVX2 +static const int32_t kStep0_3_ARGB[4] = {0, 1, 2, 3}; // Shuffle table for arranging 2 pixels into pairs for pmaddubsw static const uvec8 kShuffleColARGB = { @@ -1254,95 +3278,86 @@ static const uvec8 kShuffleColARGB = { 8u, 12u, 9u, 13u, 10u, 14u, 11u, 15u // bbggrraa 2nd pixel }; -// Shuffle table for duplicating 2 fractions into 8 bytes each -static const uvec8 kShuffleFractions = { - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, +// Shuffle table for duplicating 4 fractions across 2x128-bit lanes +static const uint8_t kShuffleFractionsAVX2[32] = { + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, + 8u, 8u, 8u, 8u, 8u, 8u, 8u, 8u, 12u, 12u, 12u, 12u, 12u, 12u, 12u, 12u, }; -// Bilinear row filtering combines 4x2 -> 4x1. SSSE3 version -void ScaleARGBFilterCols_SSSE3(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx) { - intptr_t x0, x1; - asm volatile( - "movdqa %0,%%xmm4 \n" - "movdqa %1,%%xmm5 \n" - : - : "m"(kShuffleColARGB), // %0 - "m"(kShuffleFractions) // %1 - ); +// Bilinear row filtering combines 4x2 -> 4x1. AVX2 version. +void ScaleARGBFilterCols_AVX2(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx) { + int n = dst_width & ~3; + int r = dst_width & 3; + if (n > 0) { + int loop_n = n; + asm volatile( + "vbroadcasti128 %[kShufARGB],%%ymm4 \n" + "vmovdqu %[kShufFrac],%%ymm5 \n" + "vmovd %[x],%%xmm2 \n" + "vpshufd $0x0,%%xmm2,%%xmm2 \n" + "vmovd %[dx],%%xmm3 \n" + "vpshufd $0x0,%%xmm3,%%xmm3 \n" + "vpmulld %[kStep],%%xmm3,%%xmm0 \n" + "vpaddd %%xmm0,%%xmm2,%%xmm2 \n" + "vpslld $0x2,%%xmm3,%%xmm3 \n" + "vpcmpeqb %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrlw $0x9,%%ymm6,%%ymm6 \n" - asm volatile( - "movd %5,%%xmm2 \n" - "movd %6,%%xmm3 \n" - "pcmpeqb %%xmm6,%%xmm6 \n" - "psrlw $0x9,%%xmm6 \n" - "pextrw $0x1,%%xmm2,%k3 \n" - "sub $0x2,%2 \n" - "jl 29f \n" - "movdqa %%xmm2,%%xmm0 \n" - "paddd %%xmm3,%%xmm0 \n" - "punpckldq %%xmm0,%%xmm2 \n" - "punpckldq %%xmm3,%%xmm3 \n" - "paddd %%xmm3,%%xmm3 \n" - "pextrw $0x3,%%xmm2,%k4 \n" - - LABELALIGN - "2: \n" - "movdqa %%xmm2,%%xmm1 \n" - "paddd %%xmm3,%%xmm2 \n" - "movq 0x00(%1,%3,4),%%xmm0 \n" - "psrlw $0x9,%%xmm1 \n" - "movhps 0x00(%1,%4,4),%%xmm0 \n" - "pshufb %%xmm5,%%xmm1 \n" - "pshufb %%xmm4,%%xmm0 \n" - "pxor %%xmm6,%%xmm1 \n" - "pmaddubsw %%xmm1,%%xmm0 \n" - "psrlw $0x7,%%xmm0 \n" - "pextrw $0x1,%%xmm2,%k3 \n" - "pextrw $0x3,%%xmm2,%k4 \n" - "packuswb %%xmm0,%%xmm0 \n" - "movq %%xmm0,(%0) \n" - "lea 0x8(%0),%0 \n" - "sub $0x2,%2 \n" - "jge 2b \n" - - LABELALIGN - "29: \n" - "add $0x1,%2 \n" - "jl 99f \n" - "psrlw $0x9,%%xmm2 \n" - "movq 0x00(%1,%3,4),%%xmm0 \n" - "pshufb %%xmm5,%%xmm2 \n" - "pshufb %%xmm4,%%xmm0 \n" - "pxor %%xmm6,%%xmm2 \n" - "pmaddubsw %%xmm2,%%xmm0 \n" - "psrlw $0x7,%%xmm0 \n" - "packuswb %%xmm0,%%xmm0 \n" - "movd %%xmm0,(%0) \n" - - LABELALIGN "99: \n" // clang-format error. - - : "+r"(dst_argb), // %0 - "+r"(src_argb), // %1 - "+rm"(dst_width), // %2 - "=&r"(x0), // %3 - "=&r"(x1) // %4 - : "rm"(x), // %5 - "rm"(dx) // %6 - : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); + LABELALIGN + "1: \n" + "vpsrad $0x10,%%xmm2,%%xmm1 \n" + "vpcmpeqd %%ymm7,%%ymm7,%%ymm7 \n" + "vpgatherdq %%ymm7,(%[src],%%xmm1,4),%%ymm0 \n" + "vpsrlw $0x9,%%xmm2,%%xmm1 \n" + "vpaddd %%xmm3,%%xmm2,%%xmm2 \n" + "vinserti128 $0x1,%%xmm1,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm5,%%ymm1,%%ymm1 \n" + "vpshufb %%ymm4,%%ymm0,%%ymm0 \n" + "vpxor %%ymm6,%%ymm1,%%ymm1 \n" + "vpmaddubsw %%ymm1,%%ymm0,%%ymm0 \n" + "vpsrlw $0x7,%%ymm0,%%ymm0 \n" + "vpackuswb %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%xmm0,(%[dst]) \n" + "lea 0x10(%[dst]),%[dst] \n" + "subl $0x4,%[n] \n" + "jg 1b \n" + "vzeroupper \n" + : [dst] "+r"(dst_argb), [n] "+rm"(loop_n) + : [src] "r"(src_argb), [x] "m"(x), [dx] "m"(dx), + [kStep] "m"(kStep0_3_ARGB), [kShufARGB] "m"(kShuffleColARGB), + [kShufFrac] "m"(kShuffleFractionsAVX2) + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", + "xmm6", "xmm7"); + x = (int)((uint32_t)x + (uint32_t)n * (uint32_t)dx); + } + for (int j = 0; j < r; ++j) { + ptrdiff_t xi = (ptrdiff_t)(x >> 16) * 4; + int xf = (x >> 9) & 0x7f; + const uint8_t* a = src_argb + xi; + const uint8_t* b = a + 4; + dst_argb[0] = (uint8_t)((a[0] * (0x7f ^ xf) + b[0] * xf) >> 7); + dst_argb[1] = (uint8_t)((a[1] * (0x7f ^ xf) + b[1] * xf) >> 7); + dst_argb[2] = (uint8_t)((a[2] * (0x7f ^ xf) + b[2] * xf) >> 7); + dst_argb[3] = (uint8_t)((a[3] * (0x7f ^ xf) + b[3] * xf) >> 7); + dst_argb += 4; + x = (int)((uint32_t)x + (uint32_t)dx); + } } +#endif // HAS_SCALEARGBFILTERCOLS_AVX2 // Divide num by div and return as 16.16 fixed point result. int FixedDiv_X86(int num, int div) { asm volatile( - "cdq \n" - "shld $0x10,%%eax,%%edx \n" - "shl $0x10,%%eax \n" - "idiv %1 \n" - "mov %0, %%eax \n" + "cdq \n" + "shld $0x10,%%eax,%%edx \n" + "shl $0x10,%%eax \n" + "idiv %1 \n" + "mov %0, %%eax \n" : "+a"(num) // %0 : "c"(div) // %1 : "memory", "cc", "edx"); @@ -1352,20 +3367,1032 @@ int FixedDiv_X86(int num, int div) { // Divide num - 1 by div - 1 and return as 16.16 fixed point result. int FixedDiv1_X86(int num, int div) { asm volatile( - "cdq \n" - "shld $0x10,%%eax,%%edx \n" - "shl $0x10,%%eax \n" - "sub $0x10001,%%eax \n" - "sbb $0x0,%%edx \n" - "sub $0x1,%1 \n" - "idiv %1 \n" - "mov %0, %%eax \n" - : "+a"(num) // %0 - : "c"(div) // %1 + "cdq \n" + "shld $0x10,%%eax,%%edx \n" + "shl $0x10,%%eax \n" + "sub $0x10001,%%eax \n" + "sbb $0x0,%%edx \n" + "sub $0x1,%1 \n" + "idiv %1 \n" + "mov %0, %%eax \n" + : "+a"(num), // %0 + "+c"(div) // %1 + : : "memory", "cc", "edx"); return num; } +#ifdef HAS_SCALEUVROWDOWN2_AVX2 +void ScaleUVRowDown2_AVX2(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + (void)src_stride; + asm volatile( + "sub $0x10,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpsrld $0x10,%%ymm0,%%ymm0 \n" + "vpsrld $0x10,%%ymm1,%%ymm1 \n" + "vpackusdw %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%2 \n" + "jle 99f \n" + "vmovdqu (%0),%%ymm0 \n" + "vpsrld $0x10,%%ymm0,%%ymm0 \n" + "vpackusdw %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%xmm0,(%1) \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "xmm0", "xmm1"); +} +#endif // HAS_SCALEUVROWDOWN2_AVX2 + +#ifdef HAS_SCALEUVROWDOWN2LINEAR_AVX2 +void ScaleUVRowDown2Linear_AVX2(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + (void)src_stride; + asm volatile( + "vpcmpeqd %%ymm4,%%ymm4,%%ymm4 \n" + "vpsrld $0x10,%%ymm4,%%ymm4 \n" + "sub $0x10,%2 \n" + "jl 2f \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" + "vmovdqu 0x20(%0),%%ymm1 \n" + "lea 0x40(%0),%0 \n" + "vpsrld $0x10,%%ymm0,%%ymm2 \n" + "vpsrld $0x10,%%ymm1,%%ymm3 \n" + "vpavgb %%ymm2,%%ymm0,%%ymm0 \n" + "vpavgb %%ymm3,%%ymm1,%%ymm1 \n" + "vpand %%ymm4,%%ymm0,%%ymm0 \n" + "vpand %%ymm4,%%ymm1,%%ymm1 \n" + "vpackusdw %%ymm1,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + "lea 0x20(%1),%1 \n" + "sub $0x10,%2 \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%2 \n" + "jle 99f \n" + "vmovdqu (%0),%%ymm0 \n" + "vpsrld $0x10,%%ymm0,%%ymm2 \n" + "vpavgb %%ymm2,%%ymm0,%%ymm0 \n" + "vpand %%ymm4,%%ymm0,%%ymm0 \n" + "vpackusdw %%ymm0,%%ymm0,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%xmm0,(%1) \n" + + "99: \n" + "vzeroupper \n" + : "+r"(src_uv), // %0 + "+r"(dst_uv), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif // HAS_SCALEUVROWDOWN2LINEAR_AVX2 + +#ifdef HAS_SCALEUVROWDOWN2BOX_AVX2 +// Shuffle table for splitting UV into upper and lower part of register. +static const uvec8 kShuffleSplitUV = {0u, 2u, 4u, 6u, 8u, 10u, 12u, 14u, + 1u, 3u, 5u, 7u, 9u, 11u, 13u, 15u}; +static const uvec8 kShuffleMergeUV = {0u, 8u, 2u, 10u, 4u, 12u, + 6u, 14u, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80}; + +void ScaleUVRowDown2Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + asm volatile( + "vpcmpeqb %%ymm4,%%ymm4,%%ymm4 \n" // 01010101 + "vpabsb %%ymm4,%%ymm4 \n" + "vpxor %%ymm5,%%ymm5,%%ymm5 \n" // zero + "vbroadcastf128 %4,%%ymm1 \n" // split shuffler + "vbroadcastf128 %5,%%ymm3 \n" // merge shuffler + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%ymm0 \n" // 16 UV row 0 + "vmovdqu 0x00(%0,%3,1),%%ymm2 \n" // 16 UV row 1 + "lea 0x20(%0),%0 \n" + "vpshufb %%ymm1,%%ymm0,%%ymm0 \n" // uuuuvvvv + "vpshufb %%ymm1,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm4,%%ymm0,%%ymm0 \n" // horizontal add + "vpmaddubsw %%ymm4,%%ymm2,%%ymm2 \n" + "vpaddw %%ymm2,%%ymm0,%%ymm0 \n" // vertical add + "vpsrlw $0x1,%%ymm0,%%ymm0 \n" // round + "vpavgw %%ymm5,%%ymm0,%%ymm0 \n" + "vpshufb %%ymm3,%%ymm0,%%ymm0 \n" // merge uv + "vpermq $0xd8,%%ymm0,%%ymm0 \n" // combine qwords + "vmovdqu %%xmm0,(%1) \n" + "lea 0x10(%1),%1 \n" // 8 UV + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "m"(kShuffleSplitUV), // %4 + "m"(kShuffleMergeUV) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif // HAS_SCALEUVROWDOWN2BOX_AVX2 + +#ifdef HAS_SCALEUVROWDOWNEVEN_AVX2 +void ScaleUVRowDownEven_AVX2(const uint8_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_uv, + int dst_width) { + ptrdiff_t step = (ptrdiff_t)src_stepx * 2; + ptrdiff_t step3 = step * 3; + (void)src_stride; + asm volatile( + "vpxor %%xmm0,%%xmm0,%%xmm0 \n" + + LABELALIGN + "1: \n" + "vpinsrw $0x0,(%[src]),%%xmm0,%%xmm0 \n" + "vpinsrw $0x1,0x00(%[src],%[step],1),%%xmm0,%%xmm0 \n" + "vpinsrw $0x2,0x00(%[src],%[step],2),%%xmm0,%%xmm0 \n" + "vpinsrw $0x3,0x00(%[src],%[step3],1),%%xmm0,%%xmm0 \n" + "lea 0x00(%[src],%[step],4),%[src] \n" + "vpinsrw $0x4,(%[src]),%%xmm0,%%xmm0 \n" + "vpinsrw $0x5,0x00(%[src],%[step],1),%%xmm0,%%xmm0 \n" + "vpinsrw $0x6,0x00(%[src],%[step],2),%%xmm0,%%xmm0 \n" + "vpinsrw $0x7,0x00(%[src],%[step3],1),%%xmm0,%%xmm0 \n" + "lea 0x00(%[src],%[step],4),%[src] \n" + "vmovdqu %%xmm0,(%[dst]) \n" + "lea 0x10(%[dst]),%[dst] \n" + "subl $0x8,%[width] \n" + "jg 1b \n" + : [src] "+r"(src_uv), [dst] "+r"(dst_uv), [width] "+rm"(dst_width) + : [step] "r"(step), [step3] "r"(step3) + : "memory", "cc", "xmm0"); +} +#endif // HAS_SCALEUVROWDOWNEVEN_AVX2 + +static const uvec8 kUVLinearMadd31 = {3, 1, 3, 1, 1, 3, 1, 3, + 3, 1, 3, 1, 1, 3, 1, 3}; + +#ifdef HAS_SCALEUVROWUP2_LINEAR_SSSE3 +void ScaleUVRowUp2_Linear_SSSE3(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + asm volatile( + "pcmpeqw %%xmm4,%%xmm4 \n" + "psrlw $15,%%xmm4 \n" + "psllw $1,%%xmm4 \n" // all 2 + "movdqa %3,%%xmm3 \n" + + LABELALIGN + "1: \n" + "movq (%0),%%xmm0 \n" // 00112233 (1u1v) + "movq 2(%0),%%xmm1 \n" // 11223344 (1u1v) + "punpcklbw %%xmm1,%%xmm0 \n" // 0101121223233434 (2u2v) + "movdqa %%xmm0,%%xmm2 \n" + "punpckhdq %%xmm0,%%xmm2 \n" // 2323232334343434 (2u2v) + "punpckldq %%xmm0,%%xmm0 \n" // 0101010112121212 (2u2v) + "pmaddubsw %%xmm3,%%xmm2 \n" // 3*near+far (1u1v16, hi) + "pmaddubsw %%xmm3,%%xmm0 \n" // 3*near+far (1u1v16, lo) + "paddw %%xmm4,%%xmm0 \n" // 3*near+far+2 (lo) + "paddw %%xmm4,%%xmm2 \n" // 3*near+far+2 (hi) + "psrlw $2,%%xmm0 \n" // 3/4*near+1/4*far (lo) + "psrlw $2,%%xmm2 \n" // 3/4*near+1/4*far (hi) + "packuswb %%xmm2,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + + "lea 0x8(%0),%0 \n" + "lea 0x10(%1),%1 \n" // 4 uv to 8 uv + "sub $0x8,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "m"(kUVLinearMadd31) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); +} +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_SSSE3 +void ScaleUVRowUp2_Bilinear_SSSE3(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + asm volatile( + "pcmpeqw %%xmm6,%%xmm6 \n" + "psrlw $15,%%xmm6 \n" + "psllw $3,%%xmm6 \n" // all 8 + "movdqa %5,%%xmm7 \n" + + LABELALIGN + "1: \n" + "movq (%0),%%xmm0 \n" // 00112233 (1u1v) + "movq 2(%0),%%xmm1 \n" // 11223344 (1u1v) + "punpcklbw %%xmm1,%%xmm0 \n" // 0101121223233434 (2u2v) + "movdqa %%xmm0,%%xmm2 \n" + "punpckhdq %%xmm0,%%xmm2 \n" // 2323232334343434 (2u2v) + "punpckldq %%xmm0,%%xmm0 \n" // 0101010112121212 (2u2v) + "pmaddubsw %%xmm7,%%xmm2 \n" // 3*near+far (1u1v16, hi) + "pmaddubsw %%xmm7,%%xmm0 \n" // 3*near+far (1u1v16, lo) + + "movq (%0,%3),%%xmm1 \n" + "movq 2(%0,%3),%%xmm4 \n" + "punpcklbw %%xmm4,%%xmm1 \n" + "movdqa %%xmm1,%%xmm3 \n" + "punpckhdq %%xmm1,%%xmm3 \n" + "punpckldq %%xmm1,%%xmm1 \n" + "pmaddubsw %%xmm7,%%xmm3 \n" // 3*near+far (2, hi) + "pmaddubsw %%xmm7,%%xmm1 \n" // 3*near+far (2, lo) + + // xmm0 xmm2 + // xmm1 xmm3 + + "movdqa %%xmm0,%%xmm4 \n" + "movdqa %%xmm1,%%xmm5 \n" + "paddw %%xmm0,%%xmm4 \n" // 6*near+2*far (1, lo) + "paddw %%xmm6,%%xmm5 \n" // 3*near+far+8 (2, lo) + "paddw %%xmm0,%%xmm4 \n" // 9*near+3*far (1, lo) + "paddw %%xmm5,%%xmm4 \n" // 9 3 3 1 + 8 (1, lo) + "psrlw $4,%%xmm4 \n" // ^ div by 16 (1, lo) + + "movdqa %%xmm1,%%xmm5 \n" + "paddw %%xmm1,%%xmm5 \n" // 6*near+2*far (2, lo) + "paddw %%xmm6,%%xmm0 \n" // 3*near+far+8 (1, lo) + "paddw %%xmm1,%%xmm5 \n" // 9*near+3*far (2, lo) + "paddw %%xmm0,%%xmm5 \n" // 9 3 3 1 + 8 (2, lo) + "psrlw $4,%%xmm5 \n" // ^ div by 16 (2, lo) + + "movdqa %%xmm2,%%xmm0 \n" + "movdqa %%xmm3,%%xmm1 \n" + "paddw %%xmm2,%%xmm0 \n" // 6*near+2*far (1, hi) + "paddw %%xmm6,%%xmm1 \n" // 3*near+far+8 (2, hi) + "paddw %%xmm2,%%xmm0 \n" // 9*near+3*far (1, hi) + "paddw %%xmm1,%%xmm0 \n" // 9 3 3 1 + 8 (1, hi) + "psrlw $4,%%xmm0 \n" // ^ div by 16 (1, hi) + + "movdqa %%xmm3,%%xmm1 \n" + "paddw %%xmm3,%%xmm1 \n" // 6*near+2*far (2, hi) + "paddw %%xmm6,%%xmm2 \n" // 3*near+far+8 (1, hi) + "paddw %%xmm3,%%xmm1 \n" // 9*near+3*far (2, hi) + "paddw %%xmm2,%%xmm1 \n" // 9 3 3 1 + 8 (2, hi) + "psrlw $4,%%xmm1 \n" // ^ div by 16 (2, hi) + + "packuswb %%xmm0,%%xmm4 \n" + "movdqu %%xmm4,(%1) \n" // store above + "packuswb %%xmm1,%%xmm5 \n" + "movdqu %%xmm5,(%1,%4) \n" // store below + + "lea 0x8(%0),%0 \n" + "lea 0x10(%1),%1 \n" // 4 uv to 8 uv + "sub $0x8,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(dst_stride), // %4 + "m"(kUVLinearMadd31) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_AVX2 + +void ScaleUVRowUp2_Linear_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + asm volatile( + "vpcmpeqw %%ymm4,%%ymm4,%%ymm4 \n" + "vpsrlw $15,%%ymm4,%%ymm4 \n" + "vpsllw $1,%%ymm4,%%ymm4 \n" // all 2 + "vbroadcastf128 %3,%%ymm3 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" + "vmovdqu 2(%0),%%xmm1 \n" + "vpermq $0b11011000,%%ymm0,%%ymm0 \n" + "vpermq $0b11011000,%%ymm1,%%ymm1 \n" + "vpunpcklbw %%ymm1,%%ymm0,%%ymm0 \n" + "vpunpckhdq %%ymm0,%%ymm0,%%ymm2 \n" + "vpunpckldq %%ymm0,%%ymm0,%%ymm0 \n" + "vpmaddubsw %%ymm3,%%ymm2,%%ymm1 \n" // 3*near+far (hi) + "vpmaddubsw %%ymm3,%%ymm0,%%ymm0 \n" // 3*near+far (lo) + "vpaddw %%ymm4,%%ymm0,%%ymm0 \n" // 3*near+far+2 (lo) + "vpaddw %%ymm4,%%ymm1,%%ymm1 \n" // 3*near+far+2 (hi) + "vpsrlw $2,%%ymm0,%%ymm0 \n" // 3/4*near+1/4*far (lo) + "vpsrlw $2,%%ymm1,%%ymm1 \n" // 3/4*near+1/4*far (hi) + "vpackuswb %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" // 8 uv to 16 uv + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "m"(kUVLinearMadd31) // %3 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_AVX2 +void ScaleUVRowUp2_Bilinear_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + asm volatile( + "vpcmpeqw %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrlw $15,%%ymm6,%%ymm6 \n" + "vpsllw $3,%%ymm6,%%ymm6 \n" // all 8 + "vbroadcastf128 %5,%%ymm7 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" + "vmovdqu 2(%0),%%xmm1 \n" + "vpermq $0b11011000,%%ymm0,%%ymm0 \n" + "vpermq $0b11011000,%%ymm1,%%ymm1 \n" + "vpunpcklbw %%ymm1,%%ymm0,%%ymm0 \n" + "vpunpckhdq %%ymm0,%%ymm0,%%ymm2 \n" + "vpunpckldq %%ymm0,%%ymm0,%%ymm0 \n" + "vpmaddubsw %%ymm7,%%ymm2,%%ymm1 \n" // 3*near+far (1, hi) + "vpmaddubsw %%ymm7,%%ymm0,%%ymm0 \n" // 3*near+far (1, lo) + + "vmovdqu (%0,%3),%%xmm2 \n" // 0123456789ABCDEF + "vmovdqu 2(%0,%3),%%xmm3 \n" // 123456789ABCDEF0 + "vpermq $0b11011000,%%ymm2,%%ymm2 \n" + "vpermq $0b11011000,%%ymm3,%%ymm3 \n" + "vpunpcklbw %%ymm3,%%ymm2,%%ymm2 \n" + "vpunpckhdq %%ymm2,%%ymm2,%%ymm4 \n" + "vpunpckldq %%ymm2,%%ymm2,%%ymm2 \n" + "vpmaddubsw %%ymm7,%%ymm4,%%ymm3 \n" // 3*near+far (2, hi) + "vpmaddubsw %%ymm7,%%ymm2,%%ymm2 \n" // 3*near+far (2, lo) + + // ymm0 ymm1 + // ymm2 ymm3 + + "vpaddw %%ymm0,%%ymm0,%%ymm4 \n" // 6*near+2*far (1, lo) + "vpaddw %%ymm6,%%ymm2,%%ymm5 \n" // 3*near+far+8 (2, lo) + "vpaddw %%ymm4,%%ymm0,%%ymm4 \n" // 9*near+3*far (1, lo) + "vpaddw %%ymm4,%%ymm5,%%ymm4 \n" // 9 3 3 1 + 8 (1, lo) + "vpsrlw $4,%%ymm4,%%ymm4 \n" // ^ div by 16 (1, lo) + + "vpaddw %%ymm2,%%ymm2,%%ymm5 \n" // 6*near+2*far (2, lo) + "vpaddw %%ymm6,%%ymm0,%%ymm0 \n" // 3*near+far+8 (1, lo) + "vpaddw %%ymm5,%%ymm2,%%ymm5 \n" // 9*near+3*far (2, lo) + "vpaddw %%ymm5,%%ymm0,%%ymm5 \n" // 9 3 3 1 + 8 (2, lo) + "vpsrlw $4,%%ymm5,%%ymm5 \n" // ^ div by 16 (2, lo) + + "vpaddw %%ymm1,%%ymm1,%%ymm0 \n" // 6*near+2*far (1, hi) + "vpaddw %%ymm6,%%ymm3,%%ymm2 \n" // 3*near+far+8 (2, hi) + "vpaddw %%ymm0,%%ymm1,%%ymm0 \n" // 9*near+3*far (1, hi) + "vpaddw %%ymm0,%%ymm2,%%ymm0 \n" // 9 3 3 1 + 8 (1, hi) + "vpsrlw $4,%%ymm0,%%ymm0 \n" // ^ div by 16 (1, hi) + + "vpaddw %%ymm3,%%ymm3,%%ymm2 \n" // 6*near+2*far (2, hi) + "vpaddw %%ymm6,%%ymm1,%%ymm1 \n" // 3*near+far+8 (1, hi) + "vpaddw %%ymm2,%%ymm3,%%ymm2 \n" // 9*near+3*far (2, hi) + "vpaddw %%ymm2,%%ymm1,%%ymm2 \n" // 9 3 3 1 + 8 (2, hi) + "vpsrlw $4,%%ymm2,%%ymm2 \n" // ^ div by 16 (2, hi) + + "vpackuswb %%ymm0,%%ymm4,%%ymm4 \n" + "vmovdqu %%ymm4,(%1) \n" // store above + "vpackuswb %%ymm2,%%ymm5,%%ymm5 \n" + "vmovdqu %%ymm5,(%1,%4) \n" // store below + + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" // 8 uv to 16 uv + "sub $0x10,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(dst_stride), // %4 + "m"(kUVLinearMadd31) // %5 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_SSE41 +void ScaleUVRowUp2_Linear_16_SSE41(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + asm volatile( + "pxor %%xmm5,%%xmm5 \n" + "pcmpeqd %%xmm4,%%xmm4 \n" + "psrld $31,%%xmm4 \n" + "pslld $1,%%xmm4 \n" // all 2 + + LABELALIGN + "1: \n" + "movq (%0),%%xmm0 \n" // 0011 (16b, 1u1v) + "movq 4(%0),%%xmm1 \n" // 1122 (16b, 1u1v) + + "punpcklwd %%xmm5,%%xmm0 \n" // 0011 (32b, 1u1v) + "punpcklwd %%xmm5,%%xmm1 \n" // 1122 (32b, 1u1v) + + "movdqa %%xmm0,%%xmm2 \n" + "movdqa %%xmm1,%%xmm3 \n" + + "pshufd $0b01001110,%%xmm2,%%xmm2 \n" // 1100 (lo, far) + "pshufd $0b01001110,%%xmm3,%%xmm3 \n" // 2211 (hi, far) + + "paddd %%xmm4,%%xmm2 \n" // far+2 (lo) + "paddd %%xmm4,%%xmm3 \n" // far+2 (hi) + "paddd %%xmm0,%%xmm2 \n" // near+far+2 (lo) + "paddd %%xmm1,%%xmm3 \n" // near+far+2 (hi) + "paddd %%xmm0,%%xmm0 \n" // 2*near (lo) + "paddd %%xmm1,%%xmm1 \n" // 2*near (hi) + "paddd %%xmm2,%%xmm0 \n" // 3*near+far+2 (lo) + "paddd %%xmm3,%%xmm1 \n" // 3*near+far+2 (hi) + + "psrld $2,%%xmm0 \n" // 3/4*near+1/4*far (lo) + "psrld $2,%%xmm1 \n" // 3/4*near+1/4*far (hi) + "packusdw %%xmm1,%%xmm0 \n" + "movdqu %%xmm0,(%1) \n" + + "lea 0x8(%0),%0 \n" + "lea 0x10(%1),%1 \n" // 2 uv to 4 uv + "sub $0x4,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"); +} +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_SSE41 +void ScaleUVRowUp2_Bilinear_16_SSE41(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + asm volatile( + "pxor %%xmm7,%%xmm7 \n" + "pcmpeqd %%xmm6,%%xmm6 \n" + "psrld $31,%%xmm6 \n" + "pslld $3,%%xmm6 \n" // all 8 + + LABELALIGN + "1: \n" + "movq (%0),%%xmm0 \n" // 0011 (16b, 1u1v) + "movq 4(%0),%%xmm1 \n" // 1122 (16b, 1u1v) + "punpcklwd %%xmm7,%%xmm0 \n" // 0011 (near) (32b, 1u1v) + "punpcklwd %%xmm7,%%xmm1 \n" // 1122 (near) (32b, 1u1v) + "movdqa %%xmm0,%%xmm2 \n" + "movdqa %%xmm1,%%xmm3 \n" + "pshufd $0b01001110,%%xmm2,%%xmm2 \n" // 1100 (far) (1, lo) + "pshufd $0b01001110,%%xmm3,%%xmm3 \n" // 2211 (far) (1, hi) + "paddd %%xmm0,%%xmm2 \n" // near+far (1, lo) + "paddd %%xmm1,%%xmm3 \n" // near+far (1, hi) + "paddd %%xmm0,%%xmm0 \n" // 2*near (1, lo) + "paddd %%xmm1,%%xmm1 \n" // 2*near (1, hi) + "paddd %%xmm2,%%xmm0 \n" // 3*near+far (1, lo) + "paddd %%xmm3,%%xmm1 \n" // 3*near+far (1, hi) + + "movq (%0,%3,2),%%xmm2 \n" + "movq 4(%0,%3,2),%%xmm3 \n" + "punpcklwd %%xmm7,%%xmm2 \n" + "punpcklwd %%xmm7,%%xmm3 \n" + "movdqa %%xmm2,%%xmm4 \n" + "movdqa %%xmm3,%%xmm5 \n" + "pshufd $0b01001110,%%xmm4,%%xmm4 \n" // 1100 (far) (2, lo) + "pshufd $0b01001110,%%xmm5,%%xmm5 \n" // 2211 (far) (2, hi) + "paddd %%xmm2,%%xmm4 \n" // near+far (2, lo) + "paddd %%xmm3,%%xmm5 \n" // near+far (2, hi) + "paddd %%xmm2,%%xmm2 \n" // 2*near (2, lo) + "paddd %%xmm3,%%xmm3 \n" // 2*near (2, hi) + "paddd %%xmm4,%%xmm2 \n" // 3*near+far (2, lo) + "paddd %%xmm5,%%xmm3 \n" // 3*near+far (2, hi) + + "movdqa %%xmm0,%%xmm4 \n" + "movdqa %%xmm2,%%xmm5 \n" + "paddd %%xmm0,%%xmm4 \n" // 6*near+2*far (1, lo) + "paddd %%xmm6,%%xmm5 \n" // 3*near+far+8 (2, lo) + "paddd %%xmm0,%%xmm4 \n" // 9*near+3*far (1, lo) + "paddd %%xmm5,%%xmm4 \n" // 9 3 3 1 + 8 (1, lo) + "psrld $4,%%xmm4 \n" // ^ div by 16 (1, lo) + + "movdqa %%xmm2,%%xmm5 \n" + "paddd %%xmm2,%%xmm5 \n" // 6*near+2*far (2, lo) + "paddd %%xmm6,%%xmm0 \n" // 3*near+far+8 (1, lo) + "paddd %%xmm2,%%xmm5 \n" // 9*near+3*far (2, lo) + "paddd %%xmm0,%%xmm5 \n" // 9 3 3 1 + 8 (2, lo) + "psrld $4,%%xmm5 \n" // ^ div by 16 (2, lo) + + "movdqa %%xmm1,%%xmm0 \n" + "movdqa %%xmm3,%%xmm2 \n" + "paddd %%xmm1,%%xmm0 \n" // 6*near+2*far (1, hi) + "paddd %%xmm6,%%xmm2 \n" // 3*near+far+8 (2, hi) + "paddd %%xmm1,%%xmm0 \n" // 9*near+3*far (1, hi) + "paddd %%xmm2,%%xmm0 \n" // 9 3 3 1 + 8 (1, hi) + "psrld $4,%%xmm0 \n" // ^ div by 16 (1, hi) + + "movdqa %%xmm3,%%xmm2 \n" + "paddd %%xmm3,%%xmm2 \n" // 6*near+2*far (2, hi) + "paddd %%xmm6,%%xmm1 \n" // 3*near+far+8 (1, hi) + "paddd %%xmm3,%%xmm2 \n" // 9*near+3*far (2, hi) + "paddd %%xmm1,%%xmm2 \n" // 9 3 3 1 + 8 (2, hi) + "psrld $4,%%xmm2 \n" // ^ div by 16 (2, hi) + + "packusdw %%xmm0,%%xmm4 \n" + "movdqu %%xmm4,(%1) \n" // store above + "packusdw %%xmm2,%%xmm5 \n" + "movdqu %%xmm5,(%1,%4,2) \n" // store below + + "lea 0x8(%0),%0 \n" + "lea 0x10(%1),%1 \n" // 2 uv to 4 uv + "sub $0x4,%2 \n" + "jg 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(dst_stride) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +} +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_AVX2 +void ScaleUVRowUp2_Linear_16_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + asm volatile( + "vpcmpeqd %%ymm4,%%ymm4,%%ymm4 \n" + "vpsrld $31,%%ymm4,%%ymm4 \n" + "vpslld $1,%%ymm4,%%ymm4 \n" // all 2 + + LABELALIGN + "1: \n" + "vmovdqu (%0),%%xmm0 \n" // 00112233 (16b, 1u1v) + "vmovdqu 4(%0),%%xmm1 \n" // 11223344 (16b, 1u1v) + + "vpmovzxwd %%xmm0,%%ymm0 \n" // 01234567 (32b, 1u1v) + "vpmovzxwd %%xmm1,%%ymm1 \n" // 12345678 (32b, 1u1v) + + "vpshufd $0b01001110,%%ymm0,%%ymm2 \n" // 11003322 (lo, far) + "vpshufd $0b01001110,%%ymm1,%%ymm3 \n" // 22114433 (hi, far) + + "vpaddd %%ymm4,%%ymm2,%%ymm2 \n" // far+2 (lo) + "vpaddd %%ymm4,%%ymm3,%%ymm3 \n" // far+2 (hi) + "vpaddd %%ymm0,%%ymm2,%%ymm2 \n" // near+far+2 (lo) + "vpaddd %%ymm1,%%ymm3,%%ymm3 \n" // near+far+2 (hi) + "vpaddd %%ymm0,%%ymm0,%%ymm0 \n" // 2*near (lo) + "vpaddd %%ymm1,%%ymm1,%%ymm1 \n" // 2*near (hi) + "vpaddd %%ymm0,%%ymm2,%%ymm0 \n" // 3*near+far+2 (lo) + "vpaddd %%ymm1,%%ymm3,%%ymm1 \n" // 3*near+far+2 (hi) + + "vpsrld $2,%%ymm0,%%ymm0 \n" // 3/4*near+1/4*far (lo) + "vpsrld $2,%%ymm1,%%ymm1 \n" // 3/4*near+1/4*far (hi) + "vpackusdw %%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%1) \n" + + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" // 4 uv to 8 uv + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"); +} +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_AVX2 +void ScaleUVRowUp2_Bilinear_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + asm volatile( + "vpcmpeqd %%ymm6,%%ymm6,%%ymm6 \n" + "vpsrld $31,%%ymm6,%%ymm6 \n" + "vpslld $3,%%ymm6,%%ymm6 \n" // all 8 + + LABELALIGN + "1: \n" + + "vmovdqu (%0),%%xmm0 \n" // 00112233 (16b, 1u1v) + "vmovdqu 4(%0),%%xmm1 \n" // 11223344 (16b, 1u1v) + "vpmovzxwd %%xmm0,%%ymm0 \n" // 01234567 (32b, 1u1v) + "vpmovzxwd %%xmm1,%%ymm1 \n" // 12345678 (32b, 1u1v) + "vpshufd $0b01001110,%%ymm0,%%ymm2 \n" // 11003322 (lo, far) + "vpshufd $0b01001110,%%ymm1,%%ymm3 \n" // 22114433 (hi, far) + "vpaddd %%ymm0,%%ymm2,%%ymm2 \n" // near+far (lo) + "vpaddd %%ymm1,%%ymm3,%%ymm3 \n" // near+far (hi) + "vpaddd %%ymm0,%%ymm0,%%ymm0 \n" // 2*near (lo) + "vpaddd %%ymm1,%%ymm1,%%ymm1 \n" // 2*near (hi) + "vpaddd %%ymm0,%%ymm2,%%ymm0 \n" // 3*near+far (lo) + "vpaddd %%ymm1,%%ymm3,%%ymm1 \n" // 3*near+far (hi) + + "vmovdqu (%0,%3,2),%%xmm2 \n" // 00112233 (16b, 1u1v) + "vmovdqu 4(%0,%3,2),%%xmm3 \n" // 11223344 (16b, 1u1v) + "vpmovzxwd %%xmm2,%%ymm2 \n" // 01234567 (32b, 1u1v) + "vpmovzxwd %%xmm3,%%ymm3 \n" // 12345678 (32b, 1u1v) + "vpshufd $0b01001110,%%ymm2,%%ymm4 \n" // 11003322 (lo, far) + "vpshufd $0b01001110,%%ymm3,%%ymm5 \n" // 22114433 (hi, far) + "vpaddd %%ymm2,%%ymm4,%%ymm4 \n" // near+far (lo) + "vpaddd %%ymm3,%%ymm5,%%ymm5 \n" // near+far (hi) + "vpaddd %%ymm2,%%ymm2,%%ymm2 \n" // 2*near (lo) + "vpaddd %%ymm3,%%ymm3,%%ymm3 \n" // 2*near (hi) + "vpaddd %%ymm2,%%ymm4,%%ymm2 \n" // 3*near+far (lo) + "vpaddd %%ymm3,%%ymm5,%%ymm3 \n" // 3*near+far (hi) + + "vpaddd %%ymm0,%%ymm0,%%ymm4 \n" // 6*near+2*far (1, lo) + "vpaddd %%ymm6,%%ymm2,%%ymm5 \n" // 3*near+far+8 (2, lo) + "vpaddd %%ymm4,%%ymm0,%%ymm4 \n" // 9*near+3*far (1, lo) + "vpaddd %%ymm4,%%ymm5,%%ymm4 \n" // 9 3 3 1 + 8 (1, lo) + "vpsrld $4,%%ymm4,%%ymm4 \n" // ^ div by 16 (1, lo) + + "vpaddd %%ymm2,%%ymm2,%%ymm5 \n" // 6*near+2*far (2, lo) + "vpaddd %%ymm6,%%ymm0,%%ymm0 \n" // 3*near+far+8 (1, lo) + "vpaddd %%ymm5,%%ymm2,%%ymm5 \n" // 9*near+3*far (2, lo) + "vpaddd %%ymm5,%%ymm0,%%ymm5 \n" // 9 3 3 1 + 8 (2, lo) + "vpsrld $4,%%ymm5,%%ymm5 \n" // ^ div by 16 (2, lo) + + "vpaddd %%ymm1,%%ymm1,%%ymm0 \n" // 6*near+2*far (1, hi) + "vpaddd %%ymm6,%%ymm3,%%ymm2 \n" // 3*near+far+8 (2, hi) + "vpaddd %%ymm0,%%ymm1,%%ymm0 \n" // 9*near+3*far (1, hi) + "vpaddd %%ymm0,%%ymm2,%%ymm0 \n" // 9 3 3 1 + 8 (1, hi) + "vpsrld $4,%%ymm0,%%ymm0 \n" // ^ div by 16 (1, hi) + + "vpaddd %%ymm3,%%ymm3,%%ymm2 \n" // 6*near+2*far (2, hi) + "vpaddd %%ymm6,%%ymm1,%%ymm1 \n" // 3*near+far+8 (1, hi) + "vpaddd %%ymm2,%%ymm3,%%ymm2 \n" // 9*near+3*far (2, hi) + "vpaddd %%ymm2,%%ymm1,%%ymm2 \n" // 9 3 3 1 + 8 (2, hi) + "vpsrld $4,%%ymm2,%%ymm2 \n" // ^ div by 16 (2, hi) + + "vpackusdw %%ymm0,%%ymm4,%%ymm4 \n" + "vmovdqu %%ymm4,(%1) \n" // store above + "vpackusdw %%ymm2,%%ymm5,%%ymm5 \n" + "vmovdqu %%ymm5,(%1,%4,2) \n" // store below + + "lea 0x10(%0),%0 \n" + "lea 0x20(%1),%1 \n" // 4 uv to 8 uv + "sub $0x8,%2 \n" + "jg 1b \n" + "vzeroupper \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width) // %2 + : "r"(src_stride), // %3 + "r"(dst_stride) // %4 + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"); +} +#endif + +#ifdef HAS_SCALEUVADDCOLS3_AVX2 +static const ulvec32 kPermUV3_0 = {0, 3, 6, 1, 4, 7, 2, 5}; +static const ulvec32 kPermUV3_1 = {3, 4, 5, 6, 7, 0, 1, 2}; +static const ulvec32 kPermUV3_2 = {6, 7, 0, 1, 2, 3, 4, 5}; + +// Scale UV columns by 3 box filter. +// Reads 96 bytes (24 UV pixels) and writes 16 bytes (8 UV pixels) per block. +void ScaleUVAddCols3_AVX2(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { +#if defined(__x86_64__) + asm volatile( + "vmovd %k[scaleval],%%xmm7 \n" + "vpbroadcastw %%xmm7,%%ymm7 \n" + "vmovdqa %[kPerm0],%%ymm4 \n" + "vmovdqa %[kPerm1],%%ymm5 \n" + "vmovdqa %[kPerm2],%%ymm6 \n" + "sub $0x10,%[dst_width] \n" + "jl 2f \n" + + // Process 16 output UV pixels (192 input bytes -> 32 output bytes). + LABELALIGN + "1: \n" + "vmovdqu (%[src_uv]),%%ymm0 \n" + "vmovdqu 0x20(%[src_uv]),%%ymm1 \n" + "vpermd %%ymm0,%%ymm4,%%ymm0 \n" + "vpermd %%ymm1,%%ymm4,%%ymm1 \n" + "vpblendd $0x38,%%ymm1,%%ymm0,%%ymm3 \n" + "vpblendd $0xc0,%%ymm1,%%ymm0,%%ymm2 \n" + "vpblendd $0x07,%%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu 0x40(%[src_uv]),%%ymm1 \n" + "vpermd %%ymm1,%%ymm4,%%ymm1 \n" + "vpblendd $0xc0,%%ymm1,%%ymm3,%%ymm3 \n" + "vpblendd $0x07,%%ymm1,%%ymm2,%%ymm2 \n" + "vpblendd $0x38,%%ymm1,%%ymm0,%%ymm0 \n" + "vpermd %%ymm2,%%ymm5,%%ymm2 \n" + "vpermd %%ymm0,%%ymm6,%%ymm0 \n" + "vpaddw %%ymm2,%%ymm3,%%ymm3 \n" + "vpaddw %%ymm0,%%ymm3,%%ymm8 \n" + "vpmulhuw %%ymm7,%%ymm8,%%ymm8 \n" + + "vmovdqu 0x60(%[src_uv]),%%ymm0 \n" + "vmovdqu 0x80(%[src_uv]),%%ymm1 \n" + "lea 0xc0(%[src_uv]),%[src_uv] \n" + "vpermd %%ymm0,%%ymm4,%%ymm0 \n" + "vpermd %%ymm1,%%ymm4,%%ymm1 \n" + "vpblendd $0x38,%%ymm1,%%ymm0,%%ymm3 \n" + "vpblendd $0xc0,%%ymm1,%%ymm0,%%ymm2 \n" + "vpblendd $0x07,%%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu -0x20(%[src_uv]),%%ymm1 \n" + "vpermd %%ymm1,%%ymm4,%%ymm1 \n" + "vpblendd $0xc0,%%ymm1,%%ymm3,%%ymm3 \n" + "vpblendd $0x07,%%ymm1,%%ymm2,%%ymm2 \n" + "vpblendd $0x38,%%ymm1,%%ymm0,%%ymm0 \n" + "vpermd %%ymm2,%%ymm5,%%ymm2 \n" + "vpermd %%ymm0,%%ymm6,%%ymm0 \n" + "vpaddw %%ymm2,%%ymm3,%%ymm3 \n" + "vpaddw %%ymm0,%%ymm3,%%ymm3 \n" + "vpmulhuw %%ymm7,%%ymm3,%%ymm3 \n" + + "vpackuswb %%ymm3,%%ymm8,%%ymm0 \n" + "vpermq $0xd8,%%ymm0,%%ymm0 \n" + "vmovdqu %%ymm0,(%[dst_uv]) \n" + "lea 0x20(%[dst_uv]),%[dst_uv] \n" + "sub $0x10,%[dst_width] \n" + "jge 1b \n" + + "2: \n" + "add $0x10,%[dst_width] \n" + "jle 99f \n" + + // 8-pixel remainder. + "vmovdqu (%[src_uv]),%%ymm0 \n" + "vmovdqu 0x20(%[src_uv]),%%ymm1 \n" + "vpermd %%ymm0,%%ymm4,%%ymm0 \n" + "vpermd %%ymm1,%%ymm4,%%ymm1 \n" + "vpblendd $0x38,%%ymm1,%%ymm0,%%ymm3 \n" + "vpblendd $0xc0,%%ymm1,%%ymm0,%%ymm2 \n" + "vpblendd $0x07,%%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu 0x40(%[src_uv]),%%ymm1 \n" + "vpermd %%ymm1,%%ymm4,%%ymm1 \n" + "vpblendd $0xc0,%%ymm1,%%ymm3,%%ymm3 \n" + "vpblendd $0x07,%%ymm1,%%ymm2,%%ymm2 \n" + "vpblendd $0x38,%%ymm1,%%ymm0,%%ymm0 \n" + "vpermd %%ymm2,%%ymm5,%%ymm2 \n" + "vpermd %%ymm0,%%ymm6,%%ymm0 \n" + "vpaddw %%ymm2,%%ymm3,%%ymm3 \n" + "vpaddw %%ymm0,%%ymm3,%%ymm3 \n" + "vpmulhuw %%ymm7,%%ymm3,%%ymm3 \n" + "vextracti128 $1,%%ymm3,%%xmm2 \n" + "vpackuswb %%xmm2,%%xmm3,%%xmm3 \n" + "vmovdqu %%xmm3,(%[dst_uv]) \n" + + "99: \n" + "vzeroupper \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [dst_width] "+r"(dst_width) // %[dst_width] + : [scaleval] "r"(scaleval), // %[scaleval] + [kPerm0] "m"(kPermUV3_0), // %[kPerm0] + [kPerm1] "m"(kPermUV3_1), // %[kPerm1] + [kPerm2] "m"(kPermUV3_2) // %[kPerm2] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7", "xmm8"); +#else // defined(__x86_64__) + asm volatile( + "vmovd %[scaleval],%%xmm7 \n" + "vpbroadcastw %%xmm7,%%ymm7 \n" + "vmovdqa %[kPerm0],%%ymm4 \n" + "vmovdqa %[kPerm1],%%ymm5 \n" + "vmovdqa %[kPerm2],%%ymm6 \n" + + LABELALIGN + "1: \n" + "vmovdqu (%[src_uv]),%%ymm0 \n" + "vmovdqu 0x20(%[src_uv]),%%ymm1 \n" + "vpermd %%ymm0,%%ymm4,%%ymm0 \n" + "vpermd %%ymm1,%%ymm4,%%ymm1 \n" + "vpblendd $0x38,%%ymm1,%%ymm0,%%ymm3 \n" + "vpblendd $0xc0,%%ymm1,%%ymm0,%%ymm2 \n" + "vpblendd $0x07,%%ymm1,%%ymm0,%%ymm0 \n" + "vmovdqu 0x40(%[src_uv]),%%ymm1 \n" + "lea 0x60(%[src_uv]),%[src_uv] \n" + "vpermd %%ymm1,%%ymm4,%%ymm1 \n" + "vpblendd $0xc0,%%ymm1,%%ymm3,%%ymm3 \n" + "vpblendd $0x07,%%ymm1,%%ymm2,%%ymm2 \n" + "vpblendd $0x38,%%ymm1,%%ymm0,%%ymm0 \n" + "vpermd %%ymm2,%%ymm5,%%ymm2 \n" + "vpermd %%ymm0,%%ymm6,%%ymm0 \n" + "vpaddw %%ymm2,%%ymm3,%%ymm3 \n" + "vpaddw %%ymm0,%%ymm3,%%ymm3 \n" + "vpmulhuw %%ymm7,%%ymm3,%%ymm3 \n" + "vextracti128 $1,%%ymm3,%%xmm2 \n" + "vpackuswb %%xmm2,%%xmm3,%%xmm3 \n" + "vmovdqu %%xmm3,(%[dst_uv]) \n" + "lea 0x10(%[dst_uv]),%[dst_uv] \n" + "sub $0x8,%[dst_width] \n" + "jg 1b \n" + "vzeroupper \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [dst_width] "+r"(dst_width) // %[dst_width] + : [scaleval] "rm"(scaleval), // %[scaleval] + [kPerm0] "m"(kPermUV3_0), // %[kPerm0] + [kPerm1] "m"(kPermUV3_1), // %[kPerm1] + [kPerm2] "m"(kPermUV3_2) // %[kPerm2] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm7"); +#endif // defined(__x86_64__) +} +#endif // HAS_SCALEUVADDCOLS3_AVX2 + +#ifdef HAS_SCALEUVADDCOLS3_AVX512VBMI +static const uint8_t kPerm512_Col0[16] = {0, 3, 6, 9, 12, 15, 18, 21, + 24, 27, 30, 1, 4, 7, 10, 13}; +static const uint8_t kPerm512_Col1[16] = {1, 4, 7, 10, 13, 16, 19, 22, + 25, 28, 31, 2, 5, 8, 11, 14}; +static const uint8_t kPerm512_Col2[16] = {2, 5, 8, 11, 14, 17, 20, 23, + 26, 29, 0, 3, 6, 9, 12, 15}; +static const uint8_t kPackEvenBytes[64] = { + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, + 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, + 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, + 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, + 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126}; + +// Scale UV columns by 3 box filter using AVX512VBMI. +// Processes 32 UV pixels (384 input bytes -> 64 output bytes) per main loop +// iteration, followed by a 16-pixel block and a k-masked tail (1..15 pixels). +LIBYUV_TARGET_AVX512VBMI +void ScaleUVAddCols3_AVX512VBMI(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { + intptr_t temp, mask; + asm volatile( + "vpbroadcastw %k[scaleval],%%zmm20 \n" + "vpmovzxbd %[kCol0],%%zmm16 \n" + "vpmovzxbd %[kCol1],%%zmm17 \n" + "vpmovzxbd %[kCol2],%%zmm18 \n" + "vmovdqu8 %[kPack],%%zmm19 \n" + "mov $0xf800,%k[temp] \n" + "kmovw %k[temp],%%k5 \n" + "mov $0xfc00,%k[temp] \n" + "kmovw %k[temp],%%k6 \n" + + "sub $0x20,%[dst_width] \n" + "jl 2f \n" + + // Main loop: 32 output UV pixels (64 output bytes) per iteration. + LABELALIGN + "1: \n" + "vmovdqu32 (%[src_uv]),%%zmm0 \n" + "vmovdqu32 0x40(%[src_uv]),%%zmm1 \n" + "vmovdqu32 0x80(%[src_uv]),%%zmm2 \n" + "vmovdqa32 %%zmm16,%%zmm3 \n" + "vpermi2d %%zmm1,%%zmm0,%%zmm3 \n" + "vmovdqa32 %%zmm17,%%zmm4 \n" + "vpermi2d %%zmm1,%%zmm0,%%zmm4 \n" + "vmovdqa32 %%zmm18,%%zmm5 \n" + "vpermi2d %%zmm1,%%zmm0,%%zmm5 \n" + "vpermd %%zmm2,%%zmm16,%%zmm3%{%%k5%} \n" + "vpermd %%zmm2,%%zmm17,%%zmm4%{%%k5%} \n" + "vpermd %%zmm2,%%zmm18,%%zmm5%{%%k6%} \n" + "vpaddw %%zmm4,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm5,%%zmm3,%%zmm3 \n" + "vpmulhuw %%zmm20,%%zmm3,%%zmm0 \n" + + "vmovdqu32 0xc0(%[src_uv]),%%zmm6 \n" + "vmovdqu32 0x100(%[src_uv]),%%zmm1 \n" + "vmovdqu32 0x140(%[src_uv]),%%zmm2 \n" + "lea 0x180(%[src_uv]),%[src_uv] \n" + "vmovdqa32 %%zmm16,%%zmm3 \n" + "vpermi2d %%zmm1,%%zmm6,%%zmm3 \n" + "vmovdqa32 %%zmm17,%%zmm4 \n" + "vpermi2d %%zmm1,%%zmm6,%%zmm4 \n" + "vmovdqa32 %%zmm18,%%zmm5 \n" + "vpermi2d %%zmm1,%%zmm6,%%zmm5 \n" + "vpermd %%zmm2,%%zmm16,%%zmm3%{%%k5%} \n" + "vpermd %%zmm2,%%zmm17,%%zmm4%{%%k5%} \n" + "vpermd %%zmm2,%%zmm18,%%zmm5%{%%k6%} \n" + "vpaddw %%zmm4,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm5,%%zmm3,%%zmm3 \n" + "vpmulhuw %%zmm20,%%zmm3,%%zmm3 \n" + + "vmovdqa64 %%zmm19,%%zmm2 \n" + "vpermi2b %%zmm3,%%zmm0,%%zmm2 \n" + "vmovdqu8 %%zmm2,(%[dst_uv]) \n" + "lea 0x40(%[dst_uv]),%[dst_uv] \n" + "sub $0x20,%[dst_width] \n" + "jge 1b \n" + + "2: \n" + "add $0x20,%[dst_width] \n" + "jle 99f \n" + "cmp $0x10,%[dst_width] \n" + "jl 3f \n" + + // 16-pixel half-block (32 output bytes). + "vmovdqu32 (%[src_uv]),%%zmm0 \n" + "vmovdqu32 0x40(%[src_uv]),%%zmm1 \n" + "vmovdqu32 0x80(%[src_uv]),%%zmm2 \n" + "lea 0xc0(%[src_uv]),%[src_uv] \n" + "vmovdqa32 %%zmm16,%%zmm3 \n" + "vpermi2d %%zmm1,%%zmm0,%%zmm3 \n" + "vmovdqa32 %%zmm17,%%zmm4 \n" + "vpermi2d %%zmm1,%%zmm0,%%zmm4 \n" + "vmovdqa32 %%zmm18,%%zmm5 \n" + "vpermi2d %%zmm1,%%zmm0,%%zmm5 \n" + "vpermd %%zmm2,%%zmm16,%%zmm3%{%%k5%} \n" + "vpermd %%zmm2,%%zmm17,%%zmm4%{%%k5%} \n" + "vpermd %%zmm2,%%zmm18,%%zmm5%{%%k6%} \n" + "vpaddw %%zmm4,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm5,%%zmm3,%%zmm3 \n" + "vpmulhuw %%zmm20,%%zmm3,%%zmm0 \n" + "vpmovwb %%zmm0,(%[dst_uv]) \n" + "lea 0x20(%[dst_uv]),%[dst_uv] \n" + "sub $0x10,%[dst_width] \n" + "jle 99f \n" + + // Tail: 1..15 output UV pixels (3..45 input dwords, 2..30 output bytes). + "3: \n" + "lea (%q[dst_width],%q[dst_width],2),%q[temp] \n" + "mov $-1,%q[mask] \n" + "bzhi %q[temp],%q[mask],%q[mask] \n" + "kmovw %k[mask],%%k1 \n" + "shr $16,%q[mask] \n" + "kmovw %k[mask],%%k2 \n" + "shr $16,%q[mask] \n" + "kmovw %k[mask],%%k3 \n" + "mov $-1,%q[mask] \n" + "bzhi %q[dst_width],%q[mask],%q[mask] \n" + "kmovw %k[mask],%%k4 \n" + + "vmovdqu32 (%[src_uv]),%%zmm0%{%%k1%}%{z%} \n" + "vmovdqu32 0x40(%[src_uv]),%%zmm1%{%%k2%}%{z%} \n" + "vmovdqu32 0x80(%[src_uv]),%%zmm2%{%%k3%}%{z%} \n" + "vmovdqa32 %%zmm16,%%zmm3 \n" + "vpermi2d %%zmm1,%%zmm0,%%zmm3 \n" + "vmovdqa32 %%zmm17,%%zmm4 \n" + "vpermi2d %%zmm1,%%zmm0,%%zmm4 \n" + "vmovdqa32 %%zmm18,%%zmm5 \n" + "vpermi2d %%zmm1,%%zmm0,%%zmm5 \n" + "vpermd %%zmm2,%%zmm16,%%zmm3%{%%k5%} \n" + "vpermd %%zmm2,%%zmm17,%%zmm4%{%%k5%} \n" + "vpermd %%zmm2,%%zmm18,%%zmm5%{%%k6%} \n" + "vpaddw %%zmm4,%%zmm3,%%zmm3 \n" + "vpaddw %%zmm5,%%zmm3,%%zmm3 \n" + "vpmulhuw %%zmm20,%%zmm3,%%zmm0 \n" + "vpmovwb %%zmm0,%%ymm0 \n" + "vmovdqu16 %%ymm0,(%[dst_uv])%{%%k4%} \n" + + "99: \n" + "vzeroupper \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [dst_width] "+r"(dst_width), // %[dst_width] + [temp] "=&r"(temp), // %[temp] + [mask] "=&r"(mask) // %[mask] + : [scaleval] "r"(scaleval), // %[scaleval] + [kCol0] "m"(kPerm512_Col0), // %[kCol0] + [kCol1] "m"(kPerm512_Col1), // %[kCol1] + [kCol2] "m"(kPerm512_Col2), // %[kCol2] + [kPack] "m"(kPackEvenBytes) // %[kPack] + : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", + "xmm16", "xmm17", "xmm18", "xmm19", "xmm20", "k1", "k2", "k3", "k4", + "k5", "k6"); +} +#endif // HAS_SCALEUVADDCOLS3_AVX512VBMI + #endif // defined(__x86_64__) || defined(__i386__) #ifdef __cplusplus diff --git a/libs/libyuv/source/scale_hvx.cc b/libs/libyuv/source/scale_hvx.cc new file mode 100644 index 0000000000..0aab64a6a8 --- /dev/null +++ b/libs/libyuv/source/scale_hvx.cc @@ -0,0 +1,625 @@ +/* + * Copyright 2026 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/scale_row.h" + +#if !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) +#include +#include +#include +#include + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +static __inline HVX_Vector vloada(const void* ptr) { + HVX_Vector v; + memcpy(&v, (const HVX_Vector*)ptr, sizeof(v)); + return v; +} + +static __inline HVX_UVector vloadu(const void* ptr) { + HVX_UVector v; + memcpy(&v, ptr, sizeof(v)); + return v; +} + +static __inline void vstoreu(void* ptr, HVX_UVector v) { + memcpy(ptr, &v, sizeof(v)); +} + +static __inline void vstoreu_partial(void* dst, HVX_Vector v, int n) { + if (n >= 128) { + vstoreu(dst, v); + } else if (n > 0) { + const uintptr_t addr = (uintptr_t)dst; + const uintptr_t offset = addr & 127; + HVX_Vector value = Q6_V_vlalign_VVR(v, v, addr); + HVX_VectorPred ql_not = Q6_Q_vsetq_R(addr); + HVX_VectorPred qr = Q6_Q_vsetq2_R(offset + (uintptr_t)n); + if (offset + (uintptr_t)n > 128) { + Q6_vmem_QRIV(qr, (uint8_t*)dst + 128, value); + qr = Q6_Q_vcmp_eq_VbVb(value, value); + } + ql_not = Q6_Q_or_QQn(ql_not, qr); + Q6_vmem_QnRIV(ql_not, dst, value); + } +} + +static __inline HVX_Vector vloadu_partial_zero(const void* src, int n) { + if (n >= 128) { + return vloadu(src); + } + if (n <= 0) { + return Q6_V_vzero(); + } + const uintptr_t addr = (uintptr_t)src; + const uintptr_t offset = addr & 127; + HVX_Vector v0 = vloada(src); + HVX_Vector v1 = + (offset + (uintptr_t)n > 128) ? vloada((const uint8_t*)src + 128) : v0; + HVX_Vector v = Q6_V_valign_VVR(v1, v0, addr); + return Q6_V_vmux_QVV(Q6_Q_vsetq_R(n), v, Q6_V_vzero()); +} + +void ScaleAddRow_HVX(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width) { + while (src_width > 0) { + int w = src_width >= 128 ? 128 : src_width; + HVX_Vector s = vloadu_partial_zero(src_ptr, w); + HVX_VectorPair s16 = Q6_Wuh_vunpack_Vub(s); + int b0 = w > 64 ? 128 : w * 2; + HVX_Vector d0 = vloadu_partial_zero(dst_ptr, b0); + d0 = Q6_Vh_vadd_VhVh(d0, Q6_V_lo_W(s16)); + vstoreu_partial(dst_ptr, d0, b0); + if (w > 64) { + int b1 = (w - 64) * 2; + HVX_Vector d1 = vloadu_partial_zero(dst_ptr + 64, b1); + d1 = Q6_Vh_vadd_VhVh(d1, Q6_V_hi_W(s16)); + vstoreu_partial(dst_ptr + 64, d1, b1); + } + src_ptr += 128; + dst_ptr += 128; + src_width -= 128; + } +} + +// vrdelta control vectors to compact 3 vectors of 3-column UV sums into 1 +// vector of 32 UV pairs (64 uint16_t): +// kUVAddCols3P0 routes dwords 0, 3, ..., 30 -> dwords 0..10 (bytes 0..43) +static const uint8_t kUVAddCols3P0[128] __attribute__((aligned(128))) = { + 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x08, 0x08, 0x08, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +// kUVAddCols3P1 routes dwords 1, 4, ..., 31 -> dwords 11..21 (bytes 44..87) +static const uint8_t kUVAddCols3P1[128] __attribute__((aligned(128))) = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x10, 0x10, 0x10, + 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, + 0x10, 0x10, 0x10, 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +// kUVAddCols3P2 routes dwords 2, 5, ..., 29 -> dwords 22..31 (bytes 88..127) +static const uint8_t kUVAddCols3P2[128] __attribute__((aligned(128))) = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x08, 0x08, 0x08, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, +}; + +void ScaleUVAddCols3_HVX(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { + const HVX_Vector p0 = vloada(kUVAddCols3P0); + const HVX_Vector p1 = vloada(kUVAddCols3P1); + const HVX_Vector p2 = vloada(kUVAddCols3P2); + const HVX_VectorPred q44 = Q6_Q_vsetq_R(44); + const HVX_VectorPred q88 = Q6_Q_vsetq_R(88); + const uint32_t scale_splat = + ((uint32_t)(uint16_t)scaleval << 16) | (uint16_t)scaleval; + while (dst_width > 0) { + int w = dst_width >= 32 ? 32 : dst_width; + int src_bytes = w * 12; + HVX_Vector v0 = + vloadu_partial_zero(src_uv, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector v1 = + src_bytes > 128 + ? vloadu_partial_zero((const uint8_t*)src_uv + 128, + src_bytes > 256 ? 128 : src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector v2 = + src_bytes > 256 + ? vloadu_partial_zero((const uint8_t*)src_uv + 256, src_bytes - 256) + : Q6_V_vzero(); + + HVX_Vector s0 = + Q6_Vh_vadd_VhVh(Q6_Vh_vadd_VhVh(v0, Q6_V_valign_VVR(v1, v0, 4)), + Q6_V_valign_VVR(v1, v0, 8)); + HVX_Vector s1 = + Q6_Vh_vadd_VhVh(Q6_Vh_vadd_VhVh(v1, Q6_V_valign_VVR(v2, v1, 4)), + Q6_V_valign_VVR(v2, v1, 8)); + HVX_Vector s2 = + Q6_Vh_vadd_VhVh(Q6_Vh_vadd_VhVh(v2, Q6_V_valign_VVR(v2, v2, 4)), + Q6_V_valign_VVR(v2, v2, 8)); + + HVX_Vector sum = Q6_V_vmux_QVV( + q44, Q6_V_vrdelta_VV(s0, p0), + Q6_V_vmux_QVV(q88, Q6_V_vrdelta_VV(s1, p1), Q6_V_vrdelta_VV(s2, p2))); + + HVX_VectorPair prod = Q6_Wuw_vmpy_VuhRuh(sum, scale_splat); + HVX_Vector scaled = Q6_Vh_vshuffo_VhVh(Q6_V_hi_W(prod), Q6_V_lo_W(prod)); + HVX_Vector out = Q6_Vub_vpack_VhVh_sat(scaled, scaled); + vstoreu_partial(dst_uv, out, w * 2); + src_uv += 192; + dst_uv += 64; + dst_width -= 32; + } +} + +void ScaleRowDown2_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + int w = dst_width >= 128 ? 128 : dst_width; + int src_bytes = w * 2; + HVX_Vector s0 = + vloadu_partial_zero(src_ptr, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_ptr + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair d = Q6_W_vdeal_VVR(s1, s0, -1); + vstoreu_partial(dst, Q6_V_hi_W(d), w); + src_ptr += 256; + dst += 128; + dst_width -= 128; + } +} + +void ScaleRowDown2Linear_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + int w = dst_width >= 128 ? 128 : dst_width; + int src_bytes = w * 2; + HVX_Vector s0 = + vloadu_partial_zero(src_ptr, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_ptr + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair d = Q6_W_vdeal_VVR(s1, s0, -1); + HVX_Vector avg = Q6_Vub_vavg_VubVub_rnd(Q6_V_lo_W(d), Q6_V_hi_W(d)); + vstoreu_partial(dst, avg, w); + src_ptr += 256; + dst += 128; + dst_width -= 128; + } +} + +void ScaleRowDown2Box_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + const uint8_t* s = src_ptr; + const uint8_t* t = src_ptr + src_stride; + const int32_t kOnes = 0x01010101; + HVX_Vector vtwo = Q6_Vh_vsplat_R(2); + while (dst_width > 0) { + int w = dst_width >= 128 ? 128 : dst_width; + int src_bytes = w * 2; + HVX_Vector s0 = vloadu_partial_zero(s, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector t0 = vloadu_partial_zero(t, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector sum0 = Q6_Vh_vdmpy_VubRb(s0, kOnes); + sum0 = Q6_Vh_vdmpyacc_VhVubRb(sum0, t0, kOnes); + sum0 = Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh(sum0, vtwo), 2); + + HVX_Vector sum1 = Q6_V_vzero(); + if (src_bytes > 128) { + HVX_Vector s1 = vloadu_partial_zero(s + 128, src_bytes - 128); + HVX_Vector t1 = vloadu_partial_zero(t + 128, src_bytes - 128); + sum1 = Q6_Vh_vdmpy_VubRb(s1, kOnes); + sum1 = Q6_Vh_vdmpyacc_VhVubRb(sum1, t1, kOnes); + sum1 = Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh(sum1, vtwo), 2); + } + HVX_Vector out = Q6_Vub_vpack_VhVh_sat(sum1, sum0); + vstoreu_partial(dst, out, w); + s += 256; + t += 256; + dst += 128; + dst_width -= 128; + } +} + +void ScaleRowDown2Box_Odd_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + dst_width -= 1; + if (dst_width > 0) { + ScaleRowDown2Box_HVX(src_ptr, src_stride, dst, dst_width); + } + const uint8_t* s = src_ptr + dst_width * 2; + const uint8_t* t = s + src_stride; + dst[dst_width] = (s[0] + t[0] + 1) >> 1; +} + +void ScaleRowDown2_16_HVX(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + int w = dst_width >= 64 ? 64 : dst_width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_ptr, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_ptr + 64, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair d = Q6_W_vdeal_VVR(s1, s0, -2); + vstoreu_partial(dst, Q6_V_hi_W(d), w * 2); + src_ptr += 128; + dst += 64; + dst_width -= 64; + } +} + +void ScaleRowDown2Linear_16_HVX(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + int w = dst_width >= 64 ? 64 : dst_width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_ptr, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_ptr + 64, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair d = Q6_W_vdeal_VVR(s1, s0, -2); + HVX_Vector avg = Q6_Vuh_vavg_VuhVuh_rnd(Q6_V_lo_W(d), Q6_V_hi_W(d)); + vstoreu_partial(dst, avg, w * 2); + src_ptr += 128; + dst += 64; + dst_width -= 64; + } +} + +void ScaleRowDown2Box_16_HVX(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width) { + const uint16_t* s = src_ptr; + const uint16_t* t = src_ptr + src_stride; + HVX_Vector vtwo = Q6_V_vsplat_R(2); + while (dst_width > 0) { + int w = dst_width >= 64 ? 64 : dst_width; + int src_bytes = w * 4; + HVX_Vector s0 = vloadu_partial_zero(s, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector t0 = vloadu_partial_zero(t, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(s + 64, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector t1 = src_bytes > 128 + ? vloadu_partial_zero(t + 64, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair ds = Q6_W_vdeal_VVR(s1, s0, -2); + HVX_VectorPair dt = Q6_W_vdeal_VVR(t1, t0, -2); + HVX_VectorPair s_even = Q6_Wuw_vunpack_Vuh(Q6_V_lo_W(ds)); + HVX_VectorPair s_odd = Q6_Wuw_vunpack_Vuh(Q6_V_hi_W(ds)); + HVX_VectorPair t_even = Q6_Wuw_vunpack_Vuh(Q6_V_lo_W(dt)); + HVX_VectorPair t_odd = Q6_Wuw_vunpack_Vuh(Q6_V_hi_W(dt)); + + HVX_Vector sum_lo = Q6_Vw_vadd_VwVw(Q6_V_lo_W(s_even), Q6_V_lo_W(s_odd)); + sum_lo = Q6_Vw_vadd_VwVw(sum_lo, Q6_V_lo_W(t_even)); + sum_lo = Q6_Vw_vadd_VwVw(sum_lo, Q6_V_lo_W(t_odd)); + sum_lo = Q6_Vw_vasr_VwR(Q6_Vw_vadd_VwVw(sum_lo, vtwo), 2); + + HVX_Vector sum_hi = Q6_Vw_vadd_VwVw(Q6_V_hi_W(s_even), Q6_V_hi_W(s_odd)); + sum_hi = Q6_Vw_vadd_VwVw(sum_hi, Q6_V_hi_W(t_even)); + sum_hi = Q6_Vw_vadd_VwVw(sum_hi, Q6_V_hi_W(t_odd)); + sum_hi = Q6_Vw_vasr_VwR(Q6_Vw_vadd_VwVw(sum_hi, vtwo), 2); + + HVX_Vector out = Q6_Vuh_vpack_VwVw_sat(sum_hi, sum_lo); + vstoreu_partial(dst, out, w * 2); + s += 128; + t += 128; + dst += 64; + dst_width -= 64; + } +} + +void ScaleRowDown4_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + int w = dst_width >= 128 ? 128 : dst_width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_ptr, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = + src_bytes > 128 + ? vloadu_partial_zero(src_ptr + 128, + src_bytes > 256 ? 128 : src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector s2 = + src_bytes > 256 + ? vloadu_partial_zero(src_ptr + 256, + src_bytes > 384 ? 128 : src_bytes - 256) + : Q6_V_vzero(); + HVX_Vector s3 = src_bytes > 384 + ? vloadu_partial_zero(src_ptr + 384, src_bytes - 384) + : Q6_V_vzero(); + HVX_VectorPair d01 = Q6_W_vdeal_VVR(s1, s0, -1); + HVX_VectorPair d23 = Q6_W_vdeal_VVR(s3, s2, -1); + HVX_VectorPair d_even = Q6_W_vdeal_VVR(Q6_V_lo_W(d23), Q6_V_lo_W(d01), -1); + vstoreu_partial(dst_ptr, Q6_V_hi_W(d_even), w); + src_ptr += 512; + dst_ptr += 128; + dst_width -= 128; + } +} + +void ScaleRowDown4Box_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* r0 = src_ptr; + const uint8_t* r1 = r0 + src_stride; + const uint8_t* r2 = r1 + src_stride; + const uint8_t* r3 = r2 + src_stride; + const int32_t kOnes = 0x01010101; + HVX_Vector veight = Q6_Vh_vsplat_R(8); + while (dst_width > 0) { + int w = dst_width >= 128 ? 128 : dst_width; + int src_bytes = w * 4; + HVX_Vector sum[4]; + for (int c = 0; c < 4; ++c) { + int rem = src_bytes - c * 128; + if (rem > 0) { + int b = rem > 128 ? 128 : rem; + HVX_Vector v0 = vloadu_partial_zero(r0 + c * 128, b); + HVX_Vector v1 = vloadu_partial_zero(r1 + c * 128, b); + HVX_Vector v2 = vloadu_partial_zero(r2 + c * 128, b); + HVX_Vector v3 = vloadu_partial_zero(r3 + c * 128, b); + HVX_Vector s = Q6_Vw_vrmpy_VubRb(v0, kOnes); + s = Q6_Vw_vrmpyacc_VwVubRb(s, v1, kOnes); + s = Q6_Vw_vrmpyacc_VwVubRb(s, v2, kOnes); + s = Q6_Vw_vrmpyacc_VwVubRb(s, v3, kOnes); + sum[c] = s; + } else { + sum[c] = Q6_V_vzero(); + } + } + HVX_Vector s01 = Q6_Vh_vpack_VwVw_sat(sum[1], sum[0]); + HVX_Vector s23 = Q6_Vh_vpack_VwVw_sat(sum[3], sum[2]); + s01 = Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh(s01, veight), 4); + s23 = Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh(s23, veight), 4); + HVX_Vector out = Q6_Vub_vpack_VhVh_sat(s23, s01); + vstoreu_partial(dst_ptr, out, w); + r0 += 512; + r1 += 512; + r2 += 512; + r3 += 512; + dst_ptr += 128; + dst_width -= 128; + } +} + +void ScaleARGBRowDown2_HVX(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + int w = dst_width >= 32 ? 32 : dst_width; + int src_bytes = w * 8; + HVX_Vector s0 = + vloadu_partial_zero(src_argb, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_argb + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair d = Q6_W_vdeal_VVR(s1, s0, -4); + vstoreu_partial(dst_argb, Q6_V_hi_W(d), w * 4); + src_argb += 256; + dst_argb += 128; + dst_width -= 32; + } +} + +void ScaleARGBRowDown2Linear_HVX(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + int w = dst_width >= 32 ? 32 : dst_width; + int src_bytes = w * 8; + HVX_Vector s0 = + vloadu_partial_zero(src_argb, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_argb + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair d = Q6_W_vdeal_VVR(s1, s0, -4); + HVX_Vector avg = Q6_Vub_vavg_VubVub_rnd(Q6_V_lo_W(d), Q6_V_hi_W(d)); + vstoreu_partial(dst_argb, avg, w * 4); + src_argb += 256; + dst_argb += 128; + dst_width -= 32; + } +} + +void ScaleARGBRowDown2Box_HVX(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + const uint8_t* s = src_argb; + const uint8_t* t = src_argb + src_stride; + HVX_Vector vtwo = Q6_Vh_vsplat_R(2); + while (dst_width > 0) { + int w = dst_width >= 32 ? 32 : dst_width; + int src_bytes = w * 8; + HVX_Vector s0 = vloadu_partial_zero(s, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector t0 = vloadu_partial_zero(t, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(s + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector t1 = src_bytes > 128 + ? vloadu_partial_zero(t + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair ds = Q6_W_vdeal_VVR(s1, s0, -4); + HVX_VectorPair dt = Q6_W_vdeal_VVR(t1, t0, -4); + HVX_VectorPair s_even = Q6_Wuh_vunpack_Vub(Q6_V_lo_W(ds)); + HVX_VectorPair s_odd = Q6_Wuh_vunpack_Vub(Q6_V_hi_W(ds)); + HVX_VectorPair t_even = Q6_Wuh_vunpack_Vub(Q6_V_lo_W(dt)); + HVX_VectorPair t_odd = Q6_Wuh_vunpack_Vub(Q6_V_hi_W(dt)); + + HVX_Vector sum_lo = Q6_Vh_vadd_VhVh(Q6_V_lo_W(s_even), Q6_V_lo_W(s_odd)); + sum_lo = Q6_Vh_vadd_VhVh(sum_lo, Q6_V_lo_W(t_even)); + sum_lo = Q6_Vh_vadd_VhVh(sum_lo, Q6_V_lo_W(t_odd)); + sum_lo = Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh(sum_lo, vtwo), 2); + + HVX_Vector sum_hi = Q6_Vh_vadd_VhVh(Q6_V_hi_W(s_even), Q6_V_hi_W(s_odd)); + sum_hi = Q6_Vh_vadd_VhVh(sum_hi, Q6_V_hi_W(t_even)); + sum_hi = Q6_Vh_vadd_VhVh(sum_hi, Q6_V_hi_W(t_odd)); + sum_hi = Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh(sum_hi, vtwo), 2); + + HVX_Vector out = Q6_Vub_vpack_VhVh_sat(sum_hi, sum_lo); + vstoreu_partial(dst_argb, out, w * 4); + s += 256; + t += 256; + dst_argb += 128; + dst_width -= 32; + } +} + +void ScaleUVRowDown2_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + int w = dst_width >= 64 ? 64 : dst_width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_ptr, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_ptr + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair d = Q6_W_vdeal_VVR(s1, s0, -2); + vstoreu_partial(dst_uv, Q6_V_hi_W(d), w * 2); + src_ptr += 256; + dst_uv += 128; + dst_width -= 64; + } +} + +void ScaleUVRowDown2Linear_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + int w = dst_width >= 64 ? 64 : dst_width; + int src_bytes = w * 4; + HVX_Vector s0 = + vloadu_partial_zero(src_ptr, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(src_ptr + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair d = Q6_W_vdeal_VVR(s1, s0, -2); + HVX_Vector avg = Q6_Vub_vavg_VubVub_rnd(Q6_V_lo_W(d), Q6_V_hi_W(d)); + vstoreu_partial(dst_uv, avg, w * 2); + src_ptr += 256; + dst_uv += 128; + dst_width -= 64; + } +} + +void ScaleUVRowDown2Box_HVX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + const uint8_t* s = src_ptr; + const uint8_t* t = src_ptr + src_stride; + HVX_Vector vtwo = Q6_Vh_vsplat_R(2); + while (dst_width > 0) { + int w = dst_width >= 64 ? 64 : dst_width; + int src_bytes = w * 4; + HVX_Vector s0 = vloadu_partial_zero(s, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector t0 = vloadu_partial_zero(t, src_bytes > 128 ? 128 : src_bytes); + HVX_Vector s1 = src_bytes > 128 + ? vloadu_partial_zero(s + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_Vector t1 = src_bytes > 128 + ? vloadu_partial_zero(t + 128, src_bytes - 128) + : Q6_V_vzero(); + HVX_VectorPair ds = Q6_W_vdeal_VVR(s1, s0, -2); + HVX_VectorPair dt = Q6_W_vdeal_VVR(t1, t0, -2); + HVX_VectorPair s_even = Q6_Wuh_vunpack_Vub(Q6_V_lo_W(ds)); + HVX_VectorPair s_odd = Q6_Wuh_vunpack_Vub(Q6_V_hi_W(ds)); + HVX_VectorPair t_even = Q6_Wuh_vunpack_Vub(Q6_V_lo_W(dt)); + HVX_VectorPair t_odd = Q6_Wuh_vunpack_Vub(Q6_V_hi_W(dt)); + + HVX_Vector sum_lo = Q6_Vh_vadd_VhVh(Q6_V_lo_W(s_even), Q6_V_lo_W(s_odd)); + sum_lo = Q6_Vh_vadd_VhVh(sum_lo, Q6_V_lo_W(t_even)); + sum_lo = Q6_Vh_vadd_VhVh(sum_lo, Q6_V_lo_W(t_odd)); + sum_lo = Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh(sum_lo, vtwo), 2); + + HVX_Vector sum_hi = Q6_Vh_vadd_VhVh(Q6_V_hi_W(s_even), Q6_V_hi_W(s_odd)); + sum_hi = Q6_Vh_vadd_VhVh(sum_hi, Q6_V_hi_W(t_even)); + sum_hi = Q6_Vh_vadd_VhVh(sum_hi, Q6_V_hi_W(t_odd)); + sum_hi = Q6_Vh_vasr_VhR(Q6_Vh_vadd_VhVh(sum_hi, vtwo), 2); + + HVX_Vector out = Q6_Vub_vpack_VhVh_sat(sum_hi, sum_lo); + vstoreu_partial(dst_uv, out, w * 2); + s += 256; + t += 256; + dst_uv += 128; + dst_width -= 64; + } +} + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_HVX) && defined(__HVX__) diff --git a/libs/libyuv/source/scale_lsx.cc b/libs/libyuv/source/scale_lsx.cc new file mode 100644 index 0000000000..cdb333ee42 --- /dev/null +++ b/libs/libyuv/source/scale_lsx.cc @@ -0,0 +1,975 @@ +/* + * Copyright 2022 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "libyuv/scale_row.h" + +#if !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx) + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +static const uint64_t kScale38Shuf[2] = {0x13100e0b08060300ULL, + 0x000000001e1b1816ULL}; +static const uint64_t kScale38BoxShuf[2] = {0x0a08160604120200ULL, + 0x000000001e0e0c1aULL}; +static const uint64_t kScale34Shuf[2] = {0x0908070504030100ULL, + 0x000000000f0d0c0bULL}; +static const uint64_t kScale34BoxLo[2] = {0x0504030202010100ULL, + 0x0000000007060605ULL}; +static const uint64_t kScale34BoxHi[2] = {0x0d0c0b0a0a090908ULL, + 0x000000000f0e0e0dULL}; +static const uint64_t kScale34BoxWt[2] = {0x0103030102020103ULL, + 0x0000000003010202ULL}; +static const uint64_t kScale34Pack12[2] = {0x0908050403020100ULL, + 0x000000000d0c0b0aULL}; +static const uint64_t kRamp0123[2] = {0x0000000100000000ULL, + 0x0000000300000002ULL}; + +void ScaleARGBRowDown2_LSX(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + asm volatile( + "srli.w %[w], %[w], 2 \n" + "beqz %[w], 2f \n" + "1: \n" + "vld $vr0, %[src], 0 \n" + "vld $vr1, %[src], 16 \n" + "vpickod.w $vr0, $vr1, $vr0 \n" + "vst $vr0, %[dst], 0 \n" + "addi.d %[src], %[src], 32 \n" + "addi.d %[dst], %[dst], 16 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_argb), // %[dst] + [w] "+r"(dst_width) // %[w] + : + : "memory", "$vr0", "$vr1"); +} + +void ScaleARGBRowDown2Linear_LSX(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + asm volatile( + "srli.w %[w], %[w], 2 \n" + "beqz %[w], 2f \n" + "1: \n" + "vld $vr0, %[src], 0 \n" + "vld $vr1, %[src], 16 \n" + "vpickev.w $vr2, $vr1, $vr0 \n" + "vpickod.w $vr3, $vr1, $vr0 \n" + "vavgr.bu $vr0, $vr3, $vr2 \n" + "vst $vr0, %[dst], 0 \n" + "addi.d %[src], %[src], 32 \n" + "addi.d %[dst], %[dst], 16 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_argb), // %[dst] + [w] "+r"(dst_width) // %[w] + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3"); +} + +void ScaleARGBRowDown2Box_LSX(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + const uint8_t* t = src_argb + src_stride; + asm volatile( + "srli.w %[w], %[w], 2 \n" + "beqz %[w], 2f \n" + "1: \n" + "vld $vr0, %[s], 0 \n" + "vld $vr1, %[s], 16 \n" + "vld $vr2, %[t], 0 \n" + "vld $vr3, %[t], 16 \n" + "vpickev.w $vr4, $vr1, $vr0 \n" + "vpickod.w $vr5, $vr1, $vr0 \n" + "vpickev.w $vr6, $vr3, $vr2 \n" + "vpickod.w $vr7, $vr3, $vr2 \n" + "vaddwev.h.bu $vr0, $vr4, $vr5 \n" + "vaddwod.h.bu $vr1, $vr4, $vr5 \n" + "vaddwev.h.bu $vr2, $vr6, $vr7 \n" + "vaddwod.h.bu $vr3, $vr6, $vr7 \n" + "vadd.h $vr0, $vr0, $vr2 \n" + "vadd.h $vr1, $vr1, $vr3 \n" + "vsrari.h $vr0, $vr0, 2 \n" + "vsrari.h $vr1, $vr1, 2 \n" + "vpackev.b $vr0, $vr1, $vr0 \n" + "vst $vr0, %[dst], 0 \n" + "addi.d %[s], %[s], 32 \n" + "addi.d %[t], %[t], 32 \n" + "addi.d %[dst], %[dst], 16 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [s] "+r"(src_argb), // %[s] + [t] "+r"(t), // %[t] + [dst] "+r"(dst_argb), // %[dst] + [w] "+r"(dst_width) // %[w] + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7"); +} + +void ScaleARGBRowDownEven_LSX(const uint8_t* src_argb, + ptrdiff_t src_stride, + int32_t src_stepx, + uint8_t* dst_argb, + int dst_width) { + const ptrdiff_t step = (ptrdiff_t)src_stepx * 4; + uint32_t r0, r1, r2, r3; + (void)src_stride; + asm volatile( + "srli.w %[w], %[w], 2 \n" + "beqz %[w], 2f \n" + "1: \n" + "ld.w %[r0], %[src], 0 \n" + "add.d %[src], %[src], %[step] \n" + "ld.w %[r1], %[src], 0 \n" + "add.d %[src], %[src], %[step] \n" + "ld.w %[r2], %[src], 0 \n" + "add.d %[src], %[src], %[step] \n" + "ld.w %[r3], %[src], 0 \n" + "add.d %[src], %[src], %[step] \n" + "st.w %[r0], %[dst], 0 \n" + "st.w %[r1], %[dst], 4 \n" + "st.w %[r2], %[dst], 8 \n" + "st.w %[r3], %[dst], 12 \n" + "addi.d %[dst], %[dst], 16 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_argb), // %[dst] + [w] "+r"(dst_width), // %[w] + [r0] "=&r"(r0), // %[r0] + [r1] "=&r"(r1), // %[r1] + [r2] "=&r"(r2), // %[r2] + [r3] "=&r"(r3) // %[r3] + : [step] "r"(step) // %[step] + : "memory"); +} + +void ScaleARGBRowDownEvenBox_LSX(const uint8_t* src_argb, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_argb, + int dst_width) { + const ptrdiff_t step = (ptrdiff_t)src_stepx * 4; + const uint8_t* next_argb = src_argb + src_stride; + uint64_t r0, r1; + asm volatile( + "srli.w %[w], %[w], 2 \n" + "beqz %[w], 2f \n" + "1: \n" + "ld.d %[r0], %[s], 0 \n" + "add.d %[s], %[s], %[step] \n" + "ld.d %[r1], %[s], 0 \n" + "add.d %[s], %[s], %[step] \n" + "vinsgr2vr.d $vr0, %[r0], 0 \n" + "vinsgr2vr.d $vr0, %[r1], 1 \n" + "ld.d %[r0], %[s], 0 \n" + "add.d %[s], %[s], %[step] \n" + "ld.d %[r1], %[s], 0 \n" + "add.d %[s], %[s], %[step] \n" + "vinsgr2vr.d $vr1, %[r0], 0 \n" + "vinsgr2vr.d $vr1, %[r1], 1 \n" + + "ld.d %[r0], %[t], 0 \n" + "add.d %[t], %[t], %[step] \n" + "ld.d %[r1], %[t], 0 \n" + "add.d %[t], %[t], %[step] \n" + "vinsgr2vr.d $vr2, %[r0], 0 \n" + "vinsgr2vr.d $vr2, %[r1], 1 \n" + "ld.d %[r0], %[t], 0 \n" + "add.d %[t], %[t], %[step] \n" + "ld.d %[r1], %[t], 0 \n" + "add.d %[t], %[t], %[step] \n" + "vinsgr2vr.d $vr3, %[r0], 0 \n" + "vinsgr2vr.d $vr3, %[r1], 1 \n" + + "vpickev.w $vr4, $vr1, $vr0 \n" + "vpickod.w $vr5, $vr1, $vr0 \n" + "vpickev.w $vr6, $vr3, $vr2 \n" + "vpickod.w $vr7, $vr3, $vr2 \n" + "vaddwev.h.bu $vr0, $vr4, $vr5 \n" + "vaddwod.h.bu $vr1, $vr4, $vr5 \n" + "vaddwev.h.bu $vr2, $vr6, $vr7 \n" + "vaddwod.h.bu $vr3, $vr6, $vr7 \n" + "vadd.h $vr0, $vr0, $vr2 \n" + "vadd.h $vr1, $vr1, $vr3 \n" + "vsrari.h $vr0, $vr0, 2 \n" + "vsrari.h $vr1, $vr1, 2 \n" + "vpackev.b $vr0, $vr1, $vr0 \n" + "vst $vr0, %[dst], 0 \n" + "addi.d %[dst], %[dst], 16 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [s] "+r"(src_argb), // %[s] + [t] "+r"(next_argb), // %[t] + [dst] "+r"(dst_argb), // %[dst] + [w] "+r"(dst_width), // %[w] + [r0] "=&r"(r0), // %[r0] + [r1] "=&r"(r1) // %[r1] + : [step] "r"(step) // %[step] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7"); +} + +void ScaleRowDown2_LSX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + (void)src_stride; + asm volatile( + "srli.w %[w], %[w], 4 \n" + "beqz %[w], 2f \n" + "1: \n" + "vld $vr0, %[src], 0 \n" + "vld $vr1, %[src], 16 \n" + "vpickod.b $vr0, $vr1, $vr0 \n" + "vst $vr0, %[dst], 0 \n" + "addi.d %[src], %[src], 32 \n" + "addi.d %[dst], %[dst], 16 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src_ptr), // %[src] + [dst] "+r"(dst), // %[dst] + [w] "+r"(dst_width) // %[w] + : + : "memory", "$vr0", "$vr1"); +} + +void ScaleRowDown2Linear_LSX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + (void)src_stride; + asm volatile( + "srli.w %[w], %[w], 4 \n" + "beqz %[w], 2f \n" + "1: \n" + "vld $vr0, %[src], 0 \n" + "vld $vr1, %[src], 16 \n" + "vpickev.b $vr2, $vr1, $vr0 \n" + "vpickod.b $vr3, $vr1, $vr0 \n" + "vavgr.bu $vr0, $vr3, $vr2 \n" + "vst $vr0, %[dst], 0 \n" + "addi.d %[src], %[src], 32 \n" + "addi.d %[dst], %[dst], 16 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src_ptr), // %[src] + [dst] "+r"(dst), // %[dst] + [w] "+r"(dst_width) // %[w] + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3"); +} + +void ScaleRowDown2Box_LSX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + const uint8_t* src_nex = src_ptr + src_stride; + asm volatile( + "srli.w %[w], %[w], 4 \n" + "beqz %[w], 2f \n" + "1: \n" + "vld $vr0, %[src], 0 \n" + "vld $vr1, %[src], 16 \n" + "vld $vr2, %[nex], 0 \n" + "vld $vr3, %[nex], 16 \n" + "vaddwev.h.bu $vr4, $vr0, $vr2 \n" + "vaddwod.h.bu $vr5, $vr0, $vr2 \n" + "vaddwev.h.bu $vr6, $vr1, $vr3 \n" + "vaddwod.h.bu $vr7, $vr1, $vr3 \n" + "vadd.h $vr4, $vr4, $vr5 \n" + "vadd.h $vr6, $vr6, $vr7 \n" + "vsrarni.b.h $vr6, $vr4, 2 \n" + "vst $vr6, %[dst], 0 \n" + "addi.d %[src], %[src], 32 \n" + "addi.d %[nex], %[nex], 32 \n" + "addi.d %[dst], %[dst], 16 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src_ptr), // %[src] + [nex] "+r"(src_nex), // %[nex] + [dst] "+r"(dst), // %[dst] + [w] "+r"(dst_width) // %[w] + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7"); +} + +void ScaleRowDown4_LSX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + (void)src_stride; + asm volatile( + "srli.w %[w], %[w], 3 \n" + "beqz %[w], 2f \n" + "1: \n" + "vld $vr0, %[src], 0 \n" + "vld $vr1, %[src], 16 \n" + "vpickev.b $vr0, $vr1, $vr0 \n" + "vpickod.b $vr0, $vr0, $vr0 \n" + "vstelm.d $vr0, %[dst], 0, 0 \n" + "addi.d %[src], %[src], 32 \n" + "addi.d %[dst], %[dst], 8 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src_ptr), // %[src] + [dst] "+r"(dst), // %[dst] + [w] "+r"(dst_width) // %[w] + : + : "memory", "$vr0", "$vr1"); +} + +void ScaleRowDown4Box_LSX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + const uint8_t* ptr1 = src_ptr + src_stride; + const uint8_t* ptr2 = ptr1 + src_stride; + const uint8_t* ptr3 = ptr2 + src_stride; + asm volatile( + "srli.w %[w], %[w], 3 \n" + "beqz %[w], 2f \n" + "1: \n" + "vld $vr0, %[p0], 0 \n" + "vld $vr1, %[p0], 16 \n" + "vld $vr2, %[p1], 0 \n" + "vld $vr3, %[p1], 16 \n" + "vld $vr4, %[p2], 0 \n" + "vld $vr5, %[p2], 16 \n" + "vld $vr6, %[p3], 0 \n" + "vld $vr7, %[p3], 16 \n" + "vhaddw.hu.bu $vr0, $vr0, $vr0 \n" + "vhaddw.hu.bu $vr1, $vr1, $vr1 \n" + "vhaddw.hu.bu $vr2, $vr2, $vr2 \n" + "vhaddw.hu.bu $vr3, $vr3, $vr3 \n" + "vhaddw.hu.bu $vr4, $vr4, $vr4 \n" + "vhaddw.hu.bu $vr5, $vr5, $vr5 \n" + "vhaddw.hu.bu $vr6, $vr6, $vr6 \n" + "vhaddw.hu.bu $vr7, $vr7, $vr7 \n" + "vadd.h $vr0, $vr0, $vr2 \n" + "vadd.h $vr1, $vr1, $vr3 \n" + "vadd.h $vr4, $vr4, $vr6 \n" + "vadd.h $vr5, $vr5, $vr7 \n" + "vadd.h $vr0, $vr0, $vr4 \n" + "vadd.h $vr1, $vr1, $vr5 \n" + "vhaddw.wu.hu $vr0, $vr0, $vr0 \n" + "vhaddw.wu.hu $vr1, $vr1, $vr1 \n" + "vsrarni.h.w $vr1, $vr0, 4 \n" + "vsrlni.b.h $vr1, $vr1, 0 \n" + "vstelm.d $vr1, %[dst], 0, 0 \n" + "addi.d %[p0], %[p0], 32 \n" + "addi.d %[p1], %[p1], 32 \n" + "addi.d %[p2], %[p2], 32 \n" + "addi.d %[p3], %[p3], 32 \n" + "addi.d %[dst], %[dst], 8 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [p0] "+r"(src_ptr), // %[p0] + [p1] "+r"(ptr1), // %[p1] + [p2] "+r"(ptr2), // %[p2] + [p3] "+r"(ptr3), // %[p3] + [dst] "+r"(dst), // %[dst] + [w] "+r"(dst_width) // %[w] + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7"); +} + +void ScaleRowDown38_LSX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + int count = dst_width / 12; + (void)src_stride; + asm volatile( + "beqz %[cnt], 2f \n" + "vld $vr2, %[shuf], 0 \n" + "1: \n" + "vld $vr0, %[src], 0 \n" + "vld $vr1, %[src], 16 \n" + "vshuf.b $vr0, $vr1, $vr0, $vr2 \n" + "vstelm.d $vr0, %[dst], 0, 0 \n" + "vstelm.w $vr0, %[dst], 8, 2 \n" + "addi.d %[src], %[src], 32 \n" + "addi.d %[dst], %[dst], 12 \n" + "addi.w %[cnt], %[cnt], -1 \n" + "bnez %[cnt], 1b \n" + "2: \n" + : [src] "+r"(src_ptr), // %[src] + [dst] "+r"(dst), // %[dst] + [cnt] "+r"(count) // %[cnt] + : [shuf] "r"(kScale38Shuf) // %[shuf] + : "memory", "$vr0", "$vr1", "$vr2"); +} + +void ScaleRowDown38_2_Box_LSX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* src_nex = src_ptr + src_stride; + int count = dst_width / 12; + int c2aaa = 0x2aaa; + int c4000 = 0x4000; + asm volatile( + "beqz %[cnt], 2f \n" + "vld $vr8, %[shuf], 0 \n" + "vreplgr2vr.h $vr9, %[c2aaa] \n" + "vreplgr2vr.w $vr10, %[c4000] \n" + "1: \n" + "vld $vr0, %[src], 0 \n" + "vld $vr1, %[src], 16 \n" + "vld $vr2, %[nex], 0 \n" + "vld $vr3, %[nex], 16 \n" + "vaddwev.h.bu $vr4, $vr0, $vr2 \n" + "vaddwod.h.bu $vr5, $vr0, $vr2 \n" + "vaddwev.h.bu $vr6, $vr1, $vr3 \n" + "vaddwod.h.bu $vr7, $vr1, $vr3 \n" + "vpickev.h $vr0, $vr6, $vr4 \n" + "vpickev.h $vr1, $vr7, $vr5 \n" + "vpackod.h $vr2, $vr5, $vr4 \n" + "vpackod.h $vr3, $vr7, $vr6 \n" + "vpickev.w $vr4, $vr3, $vr2 \n" + "vadd.h $vr0, $vr0, $vr1 \n" + "vadd.h $vr0, $vr0, $vr4 \n" + "vmuh.h $vr0, $vr0, $vr9 \n" + "vpickod.w $vr2, $vr3, $vr2 \n" + "vhaddw.wu.hu $vr2, $vr2, $vr2 \n" + "vmul.w $vr2, $vr2, $vr10 \n" + "vshuf.b $vr0, $vr2, $vr0, $vr8 \n" + "vstelm.d $vr0, %[dst], 0, 0 \n" + "vstelm.w $vr0, %[dst], 8, 2 \n" + "addi.d %[src], %[src], 32 \n" + "addi.d %[nex], %[nex], 32 \n" + "addi.d %[dst], %[dst], 12 \n" + "addi.w %[cnt], %[cnt], -1 \n" + "bnez %[cnt], 1b \n" + "2: \n" + : [src] "+r"(src_ptr), // %[src] + [nex] "+r"(src_nex), // %[nex] + [dst] "+r"(dst_ptr), // %[dst] + [cnt] "+r"(count) // %[cnt] + : [shuf] "r"(kScale38BoxShuf), // %[shuf] + [c2aaa] "r"(c2aaa), // %[c2aaa] + [c4000] "r"(c4000) // %[c4000] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10"); +} + +void ScaleRowDown38_3_Box_LSX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* ptr1 = src_ptr + src_stride; + const uint8_t* ptr2 = ptr1 + src_stride; + int count = dst_width / 12; + int c1c71 = 0x1c71; + int c2aaa = 0x2aaa; + asm volatile( + "beqz %[cnt], 2f \n" + "vldi $vr11, 0 \n" + "vld $vr8, %[shuf], 0 \n" + "vreplgr2vr.h $vr9, %[c1c71] \n" + "vreplgr2vr.w $vr10, %[c2aaa] \n" + "1: \n" + "vld $vr0, %[p0], 0 \n" + "vld $vr1, %[p0], 16 \n" + "vld $vr2, %[p1], 0 \n" + "vld $vr3, %[p1], 16 \n" + "vaddwev.h.bu $vr4, $vr0, $vr2 \n" + "vaddwod.h.bu $vr5, $vr0, $vr2 \n" + "vaddwev.h.bu $vr6, $vr1, $vr3 \n" + "vaddwod.h.bu $vr7, $vr1, $vr3 \n" + "vld $vr0, %[p2], 0 \n" + "vld $vr1, %[p2], 16 \n" + "vpackev.b $vr2, $vr11, $vr0 \n" + "vpackod.b $vr3, $vr11, $vr0 \n" + "vadd.h $vr4, $vr4, $vr2 \n" + "vadd.h $vr5, $vr5, $vr3 \n" + "vpackev.b $vr2, $vr11, $vr1 \n" + "vpackod.b $vr3, $vr11, $vr1 \n" + "vadd.h $vr6, $vr6, $vr2 \n" + "vadd.h $vr7, $vr7, $vr3 \n" + "vpickev.h $vr0, $vr6, $vr4 \n" + "vpickev.h $vr1, $vr7, $vr5 \n" + "vpackod.h $vr2, $vr5, $vr4 \n" + "vpackod.h $vr3, $vr7, $vr6 \n" + "vpickev.w $vr4, $vr3, $vr2 \n" + "vadd.h $vr0, $vr0, $vr1 \n" + "vadd.h $vr0, $vr0, $vr4 \n" + "vmuh.h $vr0, $vr0, $vr9 \n" + "vpickod.w $vr2, $vr3, $vr2 \n" + "vhaddw.wu.hu $vr2, $vr2, $vr2 \n" + "vmul.w $vr2, $vr2, $vr10 \n" + "vshuf.b $vr0, $vr2, $vr0, $vr8 \n" + "vstelm.d $vr0, %[dst], 0, 0 \n" + "vstelm.w $vr0, %[dst], 8, 2 \n" + "addi.d %[p0], %[p0], 32 \n" + "addi.d %[p1], %[p1], 32 \n" + "addi.d %[p2], %[p2], 32 \n" + "addi.d %[dst], %[dst], 12 \n" + "addi.w %[cnt], %[cnt], -1 \n" + "bnez %[cnt], 1b \n" + "2: \n" + : [p0] "+r"(src_ptr), // %[p0] + [p1] "+r"(ptr1), // %[p1] + [p2] "+r"(ptr2), // %[p2] + [dst] "+r"(dst_ptr), // %[dst] + [cnt] "+r"(count) // %[cnt] + : [shuf] "r"(kScale38BoxShuf), // %[shuf] + [c1c71] "r"(c1c71), // %[c1c71] + [c2aaa] "r"(c2aaa) // %[c2aaa] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11"); +} + +void ScaleAddRow_LSX(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width) { + asm volatile( + "srli.w %[w], %[w], 4 \n" + "beqz %[w], 2f \n" + "vldi $vr0, 0 \n" + "1: \n" + "vld $vr1, %[src], 0 \n" + "vld $vr2, %[dst], 0 \n" + "vld $vr3, %[dst], 16 \n" + "vilvl.b $vr4, $vr0, $vr1 \n" + "vilvh.b $vr5, $vr0, $vr1 \n" + "vadd.h $vr2, $vr2, $vr4 \n" + "vadd.h $vr3, $vr3, $vr5 \n" + "vst $vr2, %[dst], 0 \n" + "vst $vr3, %[dst], 16 \n" + "addi.d %[src], %[src], 16 \n" + "addi.d %[dst], %[dst], 32 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [src] "+r"(src_ptr), // %[src] + [dst] "+r"(dst_ptr), // %[dst] + [w] "+r"(src_width) // %[w] + : + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5"); +} + +static const uint8_t kScaleUVAddCols3Shuf[] = { + 0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 4, 5, 6, 7, + 4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 8, 9, 10, 11, + 8, 9, 10, 11, 20, 21, 22, 23, 0, 1, 2, 3, 12, 13, 14, 15, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 20, 21, 22, 23, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 24, 25, 26, 27, + 0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, +}; + +void ScaleUVAddCols3_LSX(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { + asm volatile( + "vld $vr6, %[shuf], 0 \n" + "vld $vr7, %[shuf], 16 \n" + "vld $vr8, %[shuf], 32 \n" + "vld $vr9, %[shuf], 48 \n" + "vld $vr10, %[shuf], 64 \n" + "vld $vr11, %[shuf], 80 \n" + "vreplgr2vr.h $vr12, %[scaleval] \n" + "1: \n" + "vld $vr0, %[src_uv], 0 \n" + "vld $vr1, %[src_uv], 16 \n" + "vld $vr2, %[src_uv], 32 \n" + "vshuf.b $vr3, $vr1, $vr0, $vr6 \n" + "vshuf.b $vr4, $vr1, $vr0, $vr7 \n" + "vshuf.b $vr5, $vr1, $vr0, $vr8 \n" + "vshuf.b $vr3, $vr2, $vr3, $vr9 \n" + "vshuf.b $vr4, $vr2, $vr4, $vr10 \n" + "vshuf.b $vr5, $vr2, $vr5, $vr11 \n" + "vadd.h $vr3, $vr3, $vr4 \n" + "vadd.h $vr3, $vr3, $vr5 \n" + "vmuh.hu $vr3, $vr3, $vr12 \n" + "vld $vr0, %[src_uv], 48 \n" + "vld $vr1, %[src_uv], 64 \n" + "vld $vr2, %[src_uv], 80 \n" + "addi.d %[src_uv], %[src_uv], 96 \n" + "vshuf.b $vr13, $vr1, $vr0, $vr6 \n" + "vshuf.b $vr4, $vr1, $vr0, $vr7 \n" + "vshuf.b $vr5, $vr1, $vr0, $vr8 \n" + "vshuf.b $vr13, $vr2, $vr13, $vr9 \n" + "vshuf.b $vr4, $vr2, $vr4, $vr10 \n" + "vshuf.b $vr5, $vr2, $vr5, $vr11 \n" + "vadd.h $vr13, $vr13, $vr4 \n" + "vadd.h $vr13, $vr13, $vr5 \n" + "vmuh.hu $vr13, $vr13, $vr12 \n" + "vpickev.b $vr0, $vr13, $vr3 \n" + "vst $vr0, %[dst_uv], 0 \n" + "addi.d %[dst_uv], %[dst_uv], 16 \n" + "addi.w %[dst_width], %[dst_width], -8 \n" + "bgtz %[dst_width], 1b \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [dst_width] "+r"(dst_width) // %[dst_width] + : [scaleval] "r"(scaleval), // %[scaleval] + [shuf] "r"(kScaleUVAddCols3Shuf) + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9", "$vr10", "$vr11", "$vr12", "$vr13"); +} + +void ScaleFilterCols_LSX(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx) { + ptrdiff_t i0, i1, i2, i3; + uint32_t p0, p1; + asm volatile( + "srli.w %[w], %[w], 2 \n" + "beqz %[w], 2f \n" + "vld $vr0, %[ramp], 0 \n" + "vreplgr2vr.w $vr1, %[dx] \n" + "vreplgr2vr.w $vr2, %[x] \n" + "vmul.w $vr0, $vr1, $vr0 \n" + "vslli.w $vr1, $vr1, 2 \n" + "vadd.w $vr2, $vr2, $vr0 \n" + "vldi $vr3, 0x7f \n" + "vsrli.w $vr3, $vr3, 24 \n" + "vaddi.wu $vr4, $vr3, 1 \n" + "1: \n" + "vsrai.w $vr5, $vr2, 16 \n" + "vsrai.w $vr6, $vr2, 9 \n" + "vand.v $vr6, $vr6, $vr3 \n" + "vsub.w $vr7, $vr4, $vr6 \n" + "vslli.w $vr6, $vr6, 8 \n" + "vor.v $vr6, $vr6, $vr7 \n" + "vadd.w $vr2, $vr2, $vr1 \n" + "vpickve2gr.w %[i0], $vr5, 0 \n" + "vpickve2gr.w %[i1], $vr5, 1 \n" + "vpickve2gr.w %[i2], $vr5, 2 \n" + "vpickve2gr.w %[i3], $vr5, 3 \n" + "ldx.h %[p0], %[src], %[i0] \n" + "ldx.h %[p1], %[src], %[i1] \n" + "vinsgr2vr.h $vr5, %[p0], 0 \n" + "vinsgr2vr.h $vr5, %[p1], 2 \n" + "ldx.h %[p0], %[src], %[i2] \n" + "ldx.h %[p1], %[src], %[i3] \n" + "vinsgr2vr.h $vr5, %[p0], 4 \n" + "vinsgr2vr.h $vr5, %[p1], 6 \n" + "vmulwev.h.bu $vr7, $vr5, $vr6 \n" + "vmaddwod.h.bu $vr7, $vr5, $vr6 \n" + "vsrari.h $vr5, $vr7, 7 \n" + "vpickev.b $vr5, $vr5, $vr5 \n" + "vpickev.b $vr5, $vr5, $vr5 \n" + "vstelm.w $vr5, %[dst], 0, 0 \n" + "addi.d %[dst], %[dst], 4 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [dst] "+r"(dst_ptr), // %[dst] + [w] "+r"(dst_width), // %[w] + [i0] "=&r"(i0), // %[i0] + [i1] "=&r"(i1), // %[i1] + [i2] "=&r"(i2), // %[i2] + [i3] "=&r"(i3), // %[i3] + [p0] "=&r"(p0), // %[p0] + [p1] "=&r"(p1) // %[p1] + : [src] "r"(src_ptr), // %[src] + [x] "r"(x), // %[x] + [dx] "r"(dx), // %[dx] + [ramp] "r"(kRamp0123) // %[ramp] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7"); +} + +void ScaleARGBCols_LSX(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx) { + ptrdiff_t i0, i1, i2, i3; + uint32_t p0, p1; + asm volatile( + "srli.w %[w], %[w], 2 \n" + "beqz %[w], 2f \n" + "vld $vr0, %[ramp], 0 \n" + "vreplgr2vr.w $vr1, %[dx] \n" + "vreplgr2vr.w $vr2, %[x] \n" + "vmul.w $vr0, $vr1, $vr0 \n" + "vslli.w $vr1, $vr1, 2 \n" + "vadd.w $vr2, $vr2, $vr0 \n" + "1: \n" + "vsrai.w $vr3, $vr2, 16 \n" + "vslli.w $vr3, $vr3, 2 \n" + "vadd.w $vr2, $vr2, $vr1 \n" + "vpickve2gr.w %[i0], $vr3, 0 \n" + "vpickve2gr.w %[i1], $vr3, 1 \n" + "vpickve2gr.w %[i2], $vr3, 2 \n" + "vpickve2gr.w %[i3], $vr3, 3 \n" + "ldx.w %[p0], %[src], %[i0] \n" + "ldx.w %[p1], %[src], %[i1] \n" + "st.w %[p0], %[dst], 0 \n" + "st.w %[p1], %[dst], 4 \n" + "ldx.w %[p0], %[src], %[i2] \n" + "ldx.w %[p1], %[src], %[i3] \n" + "st.w %[p0], %[dst], 8 \n" + "st.w %[p1], %[dst], 12 \n" + "addi.d %[dst], %[dst], 16 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [dst] "+r"(dst_argb), // %[dst] + [w] "+r"(dst_width), // %[w] + [i0] "=&r"(i0), // %[i0] + [i1] "=&r"(i1), // %[i1] + [i2] "=&r"(i2), // %[i2] + [i3] "=&r"(i3), // %[i3] + [p0] "=&r"(p0), // %[p0] + [p1] "=&r"(p1) // %[p1] + : [src] "r"(src_argb), // %[src] + [x] "r"(x), // %[x] + [dx] "r"(dx), // %[dx] + [ramp] "r"(kRamp0123) // %[ramp] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3"); +} + +void ScaleARGBFilterCols_LSX(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx) { + ptrdiff_t i0, i1, i2, i3; + uint64_t p0, p1; + asm volatile( + "srli.w %[w], %[w], 2 \n" + "beqz %[w], 2f \n" + "vld $vr0, %[ramp], 0 \n" + "vreplgr2vr.w $vr1, %[dx] \n" + "vreplgr2vr.w $vr2, %[x] \n" + "vmul.w $vr0, $vr1, $vr0 \n" + "vslli.w $vr1, $vr1, 2 \n" + "vadd.w $vr2, $vr2, $vr0 \n" + "vldi $vr3, 0x7f \n" + "1: \n" + "vsrai.w $vr4, $vr2, 16 \n" + "vslli.w $vr4, $vr4, 2 \n" + "vsrai.w $vr5, $vr2, 9 \n" + "vadd.w $vr2, $vr2, $vr1 \n" + "vand.v $vr5, $vr5, $vr3 \n" + "vshuf4i.b $vr5, $vr5, 0x00 \n" + "vxor.v $vr6, $vr5, $vr3 \n" + "vilvl.b $vr7, $vr5, $vr6 \n" + "vilvh.b $vr8, $vr5, $vr6 \n" + "vpickve2gr.w %[i0], $vr4, 0 \n" + "vpickve2gr.w %[i1], $vr4, 1 \n" + "vpickve2gr.w %[i2], $vr4, 2 \n" + "vpickve2gr.w %[i3], $vr4, 3 \n" + "ldx.d %[p0], %[src], %[i0] \n" + "ldx.d %[p1], %[src], %[i1] \n" + "vinsgr2vr.d $vr4, %[p0], 0 \n" + "vinsgr2vr.d $vr4, %[p1], 1 \n" + "ldx.d %[p0], %[src], %[i2] \n" + "ldx.d %[p1], %[src], %[i3] \n" + "vinsgr2vr.d $vr5, %[p0], 0 \n" + "vinsgr2vr.d $vr5, %[p1], 1 \n" + "vpickev.w $vr6, $vr5, $vr4 \n" + "vpickod.w $vr4, $vr5, $vr4 \n" + "vilvl.b $vr5, $vr4, $vr6 \n" + "vilvh.b $vr4, $vr4, $vr6 \n" + "vmulwev.h.bu $vr6, $vr5, $vr7 \n" + "vmaddwod.h.bu $vr6, $vr5, $vr7 \n" + "vmulwev.h.bu $vr7, $vr4, $vr8 \n" + "vmaddwod.h.bu $vr7, $vr4, $vr8 \n" + "vsrani.b.h $vr7, $vr6, 7 \n" + "vst $vr7, %[dst], 0 \n" + "addi.d %[dst], %[dst], 16 \n" + "addi.w %[w], %[w], -1 \n" + "bnez %[w], 1b \n" + "2: \n" + : [dst] "+r"(dst_argb), // %[dst] + [w] "+r"(dst_width), // %[w] + [i0] "=&r"(i0), // %[i0] + [i1] "=&r"(i1), // %[i1] + [i2] "=&r"(i2), // %[i2] + [i3] "=&r"(i3), // %[i3] + [p0] "=&r"(p0), // %[p0] + [p1] "=&r"(p1) // %[p1] + : [src] "r"(src_argb), // %[src] + [x] "r"(x), // %[x] + [dx] "r"(dx), // %[dx] + [ramp] "r"(kRamp0123) // %[ramp] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8"); +} + +void ScaleRowDown34_LSX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + int count = dst_width / 12; + (void)src_stride; + asm volatile( + "beqz %[cnt], 2f \n" + "vld $vr1, %[shuf], 0 \n" + "1: \n" + "vld $vr0, %[src], 0 \n" + "vshuf.b $vr0, $vr0, $vr0, $vr1 \n" + "vstelm.d $vr0, %[dst], 0, 0 \n" + "vstelm.w $vr0, %[dst], 8, 2 \n" + "addi.d %[src], %[src], 16 \n" + "addi.d %[dst], %[dst], 12 \n" + "addi.w %[cnt], %[cnt], -1 \n" + "bnez %[cnt], 1b \n" + "2: \n" + : [src] "+r"(src_ptr), // %[src] + [dst] "+r"(dst), // %[dst] + [cnt] "+r"(count) // %[cnt] + : [shuf] "r"(kScale34Shuf) // %[shuf] + : "memory", "$vr0", "$vr1"); +} + +void ScaleRowDown34_0_Box_LSX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* d, + int dst_width) { + const uint8_t* src_nex = src_ptr + src_stride; + int count = dst_width / 12; + asm volatile( + "beqz %[cnt], 2f \n" + "vld $vr0, %[lo], 0 \n" + "vld $vr1, %[hi], 0 \n" + "vld $vr2, %[wt], 0 \n" + "vld $vr3, %[pack], 0 \n" + "1: \n" + "vld $vr4, %[src], 0 \n" + "vld $vr5, %[nex], 0 \n" + "vshuf.b $vr6, $vr4, $vr4, $vr0 \n" + "vshuf.b $vr7, $vr4, $vr4, $vr1 \n" + "vshuf.b $vr8, $vr5, $vr5, $vr0 \n" + "vshuf.b $vr9, $vr5, $vr5, $vr1 \n" + "vmulwev.h.bu $vr4, $vr6, $vr2 \n" + "vmaddwod.h.bu $vr4, $vr6, $vr2 \n" + "vmulwev.h.bu $vr5, $vr7, $vr2 \n" + "vmaddwod.h.bu $vr5, $vr7, $vr2 \n" + "vmulwev.h.bu $vr6, $vr8, $vr2 \n" + "vmaddwod.h.bu $vr6, $vr8, $vr2 \n" + "vmulwev.h.bu $vr7, $vr9, $vr2 \n" + "vmaddwod.h.bu $vr7, $vr9, $vr2 \n" + "vsrari.h $vr4, $vr4, 2 \n" + "vsrari.h $vr5, $vr5, 2 \n" + "vsrari.h $vr6, $vr6, 2 \n" + "vsrari.h $vr7, $vr7, 2 \n" + "vslli.h $vr8, $vr4, 1 \n" + "vslli.h $vr9, $vr5, 1 \n" + "vadd.h $vr4, $vr4, $vr8 \n" + "vadd.h $vr5, $vr5, $vr9 \n" + "vadd.h $vr4, $vr4, $vr6 \n" + "vadd.h $vr5, $vr5, $vr7 \n" + "vsrarni.b.h $vr5, $vr4, 2 \n" + "vshuf.b $vr5, $vr5, $vr5, $vr3 \n" + "vstelm.d $vr5, %[dst], 0, 0 \n" + "vstelm.w $vr5, %[dst], 8, 2 \n" + "addi.d %[src], %[src], 16 \n" + "addi.d %[nex], %[nex], 16 \n" + "addi.d %[dst], %[dst], 12 \n" + "addi.w %[cnt], %[cnt], -1 \n" + "bnez %[cnt], 1b \n" + "2: \n" + : [src] "+r"(src_ptr), // %[src] + [nex] "+r"(src_nex), // %[nex] + [dst] "+r"(d), // %[dst] + [cnt] "+r"(count) // %[cnt] + : [lo] "r"(kScale34BoxLo), // %[lo] + [hi] "r"(kScale34BoxHi), // %[hi] + [wt] "r"(kScale34BoxWt), // %[wt] + [pack] "r"(kScale34Pack12) // %[pack] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9"); +} + +void ScaleRowDown34_1_Box_LSX(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* d, + int dst_width) { + const uint8_t* src_nex = src_ptr + src_stride; + int count = dst_width / 12; + asm volatile( + "beqz %[cnt], 2f \n" + "vld $vr0, %[lo], 0 \n" + "vld $vr1, %[hi], 0 \n" + "vld $vr2, %[wt], 0 \n" + "vld $vr3, %[pack], 0 \n" + "1: \n" + "vld $vr4, %[src], 0 \n" + "vld $vr5, %[nex], 0 \n" + "vshuf.b $vr6, $vr4, $vr4, $vr0 \n" + "vshuf.b $vr7, $vr4, $vr4, $vr1 \n" + "vshuf.b $vr8, $vr5, $vr5, $vr0 \n" + "vshuf.b $vr9, $vr5, $vr5, $vr1 \n" + "vmulwev.h.bu $vr4, $vr6, $vr2 \n" + "vmaddwod.h.bu $vr4, $vr6, $vr2 \n" + "vmulwev.h.bu $vr5, $vr7, $vr2 \n" + "vmaddwod.h.bu $vr5, $vr7, $vr2 \n" + "vmulwev.h.bu $vr6, $vr8, $vr2 \n" + "vmaddwod.h.bu $vr6, $vr8, $vr2 \n" + "vmulwev.h.bu $vr7, $vr9, $vr2 \n" + "vmaddwod.h.bu $vr7, $vr9, $vr2 \n" + "vsrari.h $vr4, $vr4, 2 \n" + "vsrari.h $vr5, $vr5, 2 \n" + "vsrari.h $vr6, $vr6, 2 \n" + "vsrari.h $vr7, $vr7, 2 \n" + "vadd.h $vr4, $vr4, $vr6 \n" + "vadd.h $vr5, $vr5, $vr7 \n" + "vsrarni.b.h $vr5, $vr4, 1 \n" + "vshuf.b $vr5, $vr5, $vr5, $vr3 \n" + "vstelm.d $vr5, %[dst], 0, 0 \n" + "vstelm.w $vr5, %[dst], 8, 2 \n" + "addi.d %[src], %[src], 16 \n" + "addi.d %[nex], %[nex], 16 \n" + "addi.d %[dst], %[dst], 12 \n" + "addi.w %[cnt], %[cnt], -1 \n" + "bnez %[cnt], 1b \n" + "2: \n" + : [src] "+r"(src_ptr), // %[src] + [nex] "+r"(src_nex), // %[nex] + [dst] "+r"(d), // %[dst] + [cnt] "+r"(count) // %[cnt] + : [lo] "r"(kScale34BoxLo), // %[lo] + [hi] "r"(kScale34BoxHi), // %[hi] + [wt] "r"(kScale34BoxWt), // %[wt] + [pack] "r"(kScale34Pack12) // %[pack] + : "memory", "$vr0", "$vr1", "$vr2", "$vr3", "$vr4", "$vr5", "$vr6", + "$vr7", "$vr8", "$vr9"); +} + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx) diff --git a/libs/libyuv/source/scale_mmi.cc b/libs/libyuv/source/scale_mmi.cc deleted file mode 100644 index 990463c2a6..0000000000 --- a/libs/libyuv/source/scale_mmi.cc +++ /dev/null @@ -1,1113 +0,0 @@ -/* - * Copyright 2013 The LibYuv Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "libyuv/scale.h" - -#include -#include - -#include "libyuv/cpu_id.h" -#include "libyuv/planar_functions.h" // For CopyARGB -#include "libyuv/row.h" -#include "libyuv/scale_row.h" - -#ifdef __cplusplus -namespace libyuv { -extern "C" { -#endif - -// This module is for Mips MMI. -#if !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) - -// clang-format off - -// CPU agnostic row functions -void ScaleRowDown2_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - (void)src_stride; - - uint64_t src0, src1, dest; - const uint64_t shift = 0x8ULL; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_ptr]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_ptr]) \n\t" - "psrlh %[src0], %[src0], %[shift] \n\t" - - "gsldrc1 %[src1], 0x08(%[src_ptr]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_ptr]) \n\t" - "psrlh %[src1], %[src1], %[shift] \n\t" - - "packushb %[dest], %[src0], %[src1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x10 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest] "=&f"(dest) - : [src_ptr] "r"(src_ptr), [dst_ptr] "r"(dst), [width] "r"(dst_width), - [shift] "f"(shift) - : "memory"); -} - -void ScaleRowDown2Linear_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - (void)src_stride; - - uint64_t src0, src1; - uint64_t dest, dest0, dest1; - - const uint64_t mask = 0x00ff00ff00ff00ffULL; - const uint64_t shift = 0x8ULL; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_ptr]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_ptr]) \n\t" - "and %[dest0], %[src0], %[mask] \n\t" - "gsldrc1 %[src1], 0x08(%[src_ptr]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_ptr]) \n\t" - "and %[dest1], %[src1], %[mask] \n\t" - "packushb %[dest0], %[dest0], %[dest1] \n\t" - - "psrlh %[src0], %[src0], %[shift] \n\t" - "psrlh %[src1], %[src1], %[shift] \n\t" - "packushb %[dest1], %[src0], %[src1] \n\t" - - "pavgb %[dest], %[dest0], %[dest1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x10 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest0] "=&f"(dest0), - [dest1] "=&f"(dest1), [dest] "=&f"(dest) - : [src_ptr] "r"(src_ptr), [dst_ptr] "r"(dst), [mask] "f"(mask), - [shift] "f"(shift), [width] "r"(dst_width) - : "memory"); -} - -void ScaleRowDown2Box_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - const uint8_t* s = src_ptr; - const uint8_t* t = src_ptr + src_stride; - - uint64_t s0, s1, t0, t1; - uint64_t dest, dest0, dest1; - - const uint64_t ph = 0x0002000200020002ULL; - const uint64_t mask = 0x00ff00ff00ff00ffULL; - const uint64_t shift0 = 0x2ULL; - const uint64_t shift1 = 0x8ULL; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[s0], 0x00(%[s]) \n\t" - "gsldlc1 %[s0], 0x07(%[s]) \n\t" - "psrlh %[s1], %[s0], %[shift1] \n\t" - "and %[s0], %[s0], %[mask] \n\t" - - "gsldrc1 %[t0], 0x00(%[t]) \n\t" - "gsldlc1 %[t0], 0x07(%[t]) \n\t" - "psrlh %[t1], %[t0], %[shift1] \n\t" - "and %[t0], %[t0], %[mask] \n\t" - - "paddh %[dest0], %[s0], %[s1] \n\t" - "paddh %[dest0], %[dest0], %[t0] \n\t" - "paddh %[dest0], %[dest0], %[t1] \n\t" - "paddh %[dest0], %[dest0], %[ph] \n\t" - "psrlh %[dest0], %[dest0], %[shift0] \n\t" - - "gsldrc1 %[s0], 0x08(%[s]) \n\t" - "gsldlc1 %[s0], 0x0f(%[s]) \n\t" - "psrlh %[s1], %[s0], %[shift1] \n\t" - "and %[s0], %[s0], %[mask] \n\t" - - "gsldrc1 %[t0], 0x08(%[t]) \n\t" - "gsldlc1 %[t0], 0x0f(%[t]) \n\t" - "psrlh %[t1], %[t0], %[shift1] \n\t" - "and %[t0], %[t0], %[mask] \n\t" - - "paddh %[dest1], %[s0], %[s1] \n\t" - "paddh %[dest1], %[dest1], %[t0] \n\t" - "paddh %[dest1], %[dest1], %[t1] \n\t" - "paddh %[dest1], %[dest1], %[ph] \n\t" - "psrlh %[dest1], %[dest1], %[shift0] \n\t" - - "packushb %[dest], %[dest0], %[dest1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[s], %[s], 0x10 \n\t" - "daddiu %[t], %[t], 0x10 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [s0] "=&f"(s0), [s1] "=&f"(s1), [t0] "=&f"(t0), [t1] "=&f"(t1), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [dest] "=&f"(dest) - : [s] "r"(s), [t] "r"(t), [dst_ptr] "r"(dst), [width] "r"(dst_width), - [shift0] "f"(shift0), [shift1] "f"(shift1), [ph] "f"(ph), - [mask] "f"(mask) - : "memory"); -} - -void ScaleARGBRowDown2_MMI(const uint8_t* src_argb, - ptrdiff_t src_stride, - uint8_t* dst_argb, - int dst_width) { - (void)src_stride; - - const uint32_t* src = (const uint32_t*)(src_argb); - uint32_t* dst = (uint32_t*)(dst_argb); - - uint64_t src0, src1, dest; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_ptr]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_ptr]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_ptr]) \n\t" - "punpckhwd %[dest], %[src0], %[src1] \n\t" - - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x10 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest] "=&f"(dest) - : [src_ptr] "r"(src), [dst_ptr] "r"(dst), [width] "r"(dst_width) - : "memory"); -} - -void ScaleARGBRowDown2Linear_MMI(const uint8_t* src_argb, - ptrdiff_t src_stride, - uint8_t* dst_argb, - int dst_width) { - (void)src_stride; - - uint64_t src0, src1; - uint64_t dest, dest_hi, dest_lo; - - __asm__ volatile( - "1: \n\t" - "lwc1 %[src0], 0x00(%[src_ptr]) \n\t" - "lwc1 %[src1], 0x08(%[src_ptr]) \n\t" - "punpcklwd %[dest_lo], %[src0], %[src1] \n\t" - "lwc1 %[src0], 0x04(%[src_ptr]) \n\t" - "lwc1 %[src1], 0x0c(%[src_ptr]) \n\t" - "punpcklwd %[dest_hi], %[src0], %[src1] \n\t" - - "pavgb %[dest], %[dest_lo], %[dest_hi] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x10 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest_hi] "=&f"(dest_hi), - [dest_lo] "=&f"(dest_lo), [dest] "=&f"(dest) - : [src_ptr] "r"(src_argb), [dst_ptr] "r"(dst_argb), [width] "r"(dst_width) - : "memory"); -} - -void ScaleARGBRowDown2Box_MMI(const uint8_t* src_argb, - ptrdiff_t src_stride, - uint8_t* dst_argb, - int dst_width) { - const uint8_t* s = src_argb; - const uint8_t* t = src_argb + src_stride; - - uint64_t s0, s_hi, s_lo; - uint64_t t0, t_hi, t_lo; - uint64_t dest, dest_hi, dest_lo; - - const uint64_t mask = 0x0ULL; - const uint64_t ph = 0x0002000200020002ULL; - const uint64_t shfit = 0x2ULL; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[s0], 0x00(%[s]) \n\t" - "gsldlc1 %[s0], 0x07(%[s]) \n\t" - "punpcklbh %[s_lo], %[s0], %[mask] \n\t" - "punpckhbh %[s_hi], %[s0], %[mask] \n\t" - "paddh %[dest_lo], %[s_lo], %[s_hi] \n\t" - - "gsldrc1 %[t0], 0x00(%[t]) \n\t" - "gsldlc1 %[t0], 0x07(%[t]) \n\t" - "punpcklbh %[t_lo], %[t0], %[mask] \n\t" - "punpckhbh %[t_hi], %[t0], %[mask] \n\t" - "paddh %[dest_lo], %[dest_lo], %[t_lo] \n\t" - "paddh %[dest_lo], %[dest_lo], %[t_hi] \n\t" - - "paddh %[dest_lo], %[dest_lo], %[ph] \n\t" - "psrlh %[dest_lo], %[dest_lo], %[shfit] \n\t" - - "gsldrc1 %[s0], 0x08(%[s]) \n\t" - "gsldlc1 %[s0], 0x0f(%[s]) \n\t" - "punpcklbh %[s_lo], %[s0], %[mask] \n\t" - "punpckhbh %[s_hi], %[s0], %[mask] \n\t" - "paddh %[dest_hi], %[s_lo], %[s_hi] \n\t" - - "gsldrc1 %[t0], 0x08(%[t]) \n\t" - "gsldlc1 %[t0], 0x0f(%[t]) \n\t" - "punpcklbh %[t_lo], %[t0], %[mask] \n\t" - "punpckhbh %[t_hi], %[t0], %[mask] \n\t" - "paddh %[dest_hi], %[dest_hi], %[t_lo] \n\t" - "paddh %[dest_hi], %[dest_hi], %[t_hi] \n\t" - - "paddh %[dest_hi], %[dest_hi], %[ph] \n\t" - "psrlh %[dest_hi], %[dest_hi], %[shfit] \n\t" - - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[s], %[s], 0x10 \n\t" - "daddiu %[t], %[t], 0x10 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [s0] "=&f"(s0), [t0] "=&f"(t0), [dest_hi] "=&f"(dest_hi), - [dest_lo] "=&f"(dest_lo), [s_hi] "=&f"(s_hi), [s_lo] "=&f"(s_lo), - [t_hi] "=&f"(t_hi), [t_lo] "=&f"(t_lo), [dest] "=&f"(dest) - : [s] "r"(s), [t] "r"(t), [dst_ptr] "r"(dst_argb), [width] "r"(dst_width), - [mask] "f"(mask), [ph] "f"(ph), [shfit] "f"(shfit) - : "memory"); -} - -void ScaleRowDown2_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width) { - (void)src_stride; - - uint64_t src0, src1, dest; - const uint64_t shift = 0x10ULL; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_ptr]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_ptr]) \n\t" - "psrlw %[src0], %[src0], %[shift] \n\t" - - "gsldrc1 %[src1], 0x08(%[src_ptr]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_ptr]) \n\t" - "psrlw %[src1], %[src1], %[shift] \n\t" - - "packsswh %[dest], %[src0], %[src1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x10 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest] "=&f"(dest) - : [src_ptr] "r"(src_ptr), [dst_ptr] "r"(dst), [width] "r"(dst_width), - [shift] "f"(shift) - : "memory"); -} - -void ScaleRowDown2Linear_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width) { - (void)src_stride; - - uint64_t src0, src1; - uint64_t dest, dest_hi, dest_lo; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_ptr]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_ptr]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_ptr]) \n\t" - "punpcklhw %[dest_lo], %[src0], %[src1] \n\t" - "punpckhhw %[dest_hi], %[src0], %[src1] \n\t" - - "punpcklhw %[src0], %[dest_lo], %[dest_hi] \n\t" - "punpckhhw %[src1], %[dest_lo], %[dest_hi] \n\t" - - "pavgh %[dest], %[src0], %[src1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x10 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest_hi] "=&f"(dest_hi), - [dest_lo] "=&f"(dest_lo), [dest] "=&f"(dest) - : [src_ptr] "r"(src_ptr), [dst_ptr] "r"(dst), [width] "r"(dst_width) - : "memory"); -} - -void ScaleRowDown2Box_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width) { - const uint16_t* s = src_ptr; - const uint16_t* t = src_ptr + src_stride; - - uint64_t s0, s1, s_hi, s_lo; - uint64_t t0, t1, t_hi, t_lo; - uint64_t dest, dest0, dest1; - - const uint64_t ph = 0x0000000200000002ULL; - const uint64_t mask = 0x0000ffff0000ffffULL; - const uint64_t shift0 = 0x10ULL; - const uint64_t shift1 = 0x2ULL; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[s0], 0x00(%[s]) \n\t" - "gsldlc1 %[s0], 0x07(%[s]) \n\t" - "psrlw %[s1], %[s0], %[shift0] \n\t" - "and %[s0], %[s0], %[mask] \n\t" - - "gsldrc1 %[t0], 0x00(%[t]) \n\t" - "gsldlc1 %[t0], 0x07(%[t]) \n\t" - "psrlw %[t1], %[t0], %[shift0] \n\t" - "and %[t0], %[t0], %[mask] \n\t" - - "paddw %[dest0], %[s0], %[s1] \n\t" - "paddw %[dest0], %[dest0], %[t0] \n\t" - "paddw %[dest0], %[dest0], %[t1] \n\t" - "paddw %[dest0], %[dest0], %[ph] \n\t" - "psrlw %[dest0], %[dest0], %[shift1] \n\t" - - "gsldrc1 %[s0], 0x08(%[s]) \n\t" - "gsldlc1 %[s0], 0x0f(%[s]) \n\t" - "psrlw %[s1], %[s0], %[shift0] \n\t" - "and %[s0], %[s0], %[mask] \n\t" - - "gsldrc1 %[t0], 0x08(%[t]) \n\t" - "gsldlc1 %[t0], 0x0f(%[t]) \n\t" - "psrlw %[t1], %[t0], %[shift0] \n\t" - "and %[t0], %[t0], %[mask] \n\t" - - "paddw %[dest1], %[s0], %[s1] \n\t" - "paddw %[dest1], %[dest1], %[t0] \n\t" - "paddw %[dest1], %[dest1], %[t1] \n\t" - "paddw %[dest1], %[dest1], %[ph] \n\t" - "psrlw %[dest1], %[dest1], %[shift1] \n\t" - - "packsswh %[dest], %[dest0], %[dest1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[s], %[s], 0x10 \n\t" - "daddiu %[t], %[t], 0x10 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [s0] "=&f"(s0), [s1] "=&f"(s1), [t0] "=&f"(t0), [t1] "=&f"(t1), - [s_hi] "=&f"(s_hi), [s_lo] "=&f"(s_lo), [t_hi] "=&f"(t_hi), - [t_lo] "=&f"(t_lo), [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), - [dest] "=&f"(dest) - : [s] "r"(s), [t] "r"(t), [dst_ptr] "r"(dst), [width] "r"(dst_width), - [shift0] "f"(shift0), [shift1] "f"(shift1), [ph] "f"(ph), - [mask] "f"(mask) - : "memory"); -} - -void ScaleRowDown4_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - (void)src_stride; - - uint64_t src0, src1; - uint64_t dest, dest_hi, dest_lo; - - const uint64_t shift = 0x10ULL; - const uint64_t mask = 0x000000ff000000ffULL; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_ptr]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_ptr]) \n\t" - "psrlw %[src0], %[src0], %[shift] \n\t" - "and %[src0], %[src0], %[mask] \n\t" - "gsldrc1 %[src1], 0x08(%[src_ptr]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_ptr]) \n\t" - "psrlw %[src1], %[src1], %[shift] \n\t" - "and %[src1], %[src1], %[mask] \n\t" - "packsswh %[dest_lo], %[src0], %[src1] \n\t" - - "gsldrc1 %[src0], 0x10(%[src_ptr]) \n\t" - "gsldlc1 %[src0], 0x17(%[src_ptr]) \n\t" - "psrlw %[src0], %[src0], %[shift] \n\t" - "and %[src0], %[src0], %[mask] \n\t" - "gsldrc1 %[src1], 0x18(%[src_ptr]) \n\t" - "gsldlc1 %[src1], 0x1f(%[src_ptr]) \n\t" - "psrlw %[src1], %[src1], %[shift] \n\t" - "and %[src1], %[src1], %[mask] \n\t" - "packsswh %[dest_hi], %[src0], %[src1] \n\t" - - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x20 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest_hi] "=&f"(dest_hi), - [dest_lo] "=&f"(dest_lo), [dest] "=&f"(dest) - : [src_ptr] "r"(src_ptr), [dst_ptr] "r"(dst), [width] "r"(dst_width), - [shift] "f"(shift), [mask] "f"(mask) - : "memory"); -} - -void ScaleRowDown4_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width) { - (void)src_stride; - - uint64_t src0, src1; - uint64_t dest, dest_hi, dest_lo; - - const uint64_t mask = 0x0ULL; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src_ptr]) \n\t" - "gsldlc1 %[src0], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src1], 0x08(%[src_ptr]) \n\t" - "gsldlc1 %[src1], 0x0f(%[src_ptr]) \n\t" - "punpckhhw %[dest_lo], %[src0], %[src1] \n\t" - "punpcklhw %[dest_lo], %[dest_lo], %[mask] \n\t" - - "gsldrc1 %[src0], 0x10(%[src_ptr]) \n\t" - "gsldlc1 %[src0], 0x17(%[src_ptr]) \n\t" - "gsldrc1 %[src1], 0x18(%[src_ptr]) \n\t" - "gsldlc1 %[src1], 0x1f(%[src_ptr]) \n\t" - "punpckhhw %[dest_hi], %[src0], %[src1] \n\t" - "punpcklhw %[dest_hi], %[dest_hi], %[mask] \n\t" - - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x20 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest_hi] "=&f"(dest_hi), - [dest_lo] "=&f"(dest_lo), [dest] "=&f"(dest) - : [src_ptr] "r"(src_ptr), [dst_ptr] "r"(dst), [width] "r"(dst_width), - [mask] "f"(mask) - : "memory"); -} - -#define DO_SCALEROWDOWN4BOX_PUNPCKADD() \ - "punpcklbh %[src_lo], %[src], %[mask0] \n\t" \ - "punpckhbh %[src_hi], %[src], %[mask0] \n\t" \ - "paddh %[dest_lo], %[dest_lo], %[src_lo] \n\t" \ - "paddh %[dest_hi], %[dest_hi], %[src_hi] \n\t" - -#define DO_SCALEROWDOWN4BOX_LOOP(reg) \ - "ldc1 %[src], 0x00(%[src0_ptr]) \n\t" \ - "punpcklbh %[dest_lo], %[src], %[mask0] \n\t" \ - "punpckhbh %[dest_hi], %[src], %[mask0] \n\t" \ - \ - "ldc1 %[src], 0x00(%[src1_ptr]) \n\t" \ - DO_SCALEROWDOWN4BOX_PUNPCKADD() \ - \ - "ldc1 %[src], 0x00(%[src2_ptr]) \n\t" \ - DO_SCALEROWDOWN4BOX_PUNPCKADD() \ - \ - "ldc1 %[src], 0x00(%[src3_ptr]) \n\t" \ - DO_SCALEROWDOWN4BOX_PUNPCKADD() \ - \ - "pmaddhw %[dest_lo], %[dest_lo], %[mask1] \n\t" \ - "pmaddhw %[dest_hi], %[dest_hi], %[mask1] \n\t" \ - "packsswh " #reg ", %[dest_lo], %[dest_hi] \n\t" \ - "pmaddhw " #reg ", " #reg ", %[mask1] \n\t" \ - "paddh " #reg ", " #reg ", %[ph] \n\t" \ - "psrlh " #reg ", " #reg ", %[shift] \n\t" \ - \ - "daddiu %[src0_ptr], %[src0_ptr], 0x08 \n\t" \ - "daddiu %[src1_ptr], %[src1_ptr], 0x08 \n\t" \ - "daddiu %[src2_ptr], %[src2_ptr], 0x08 \n\t" \ - "daddiu %[src3_ptr], %[src3_ptr], 0x08 \n\t" - -/* LibYUVScaleTest.ScaleDownBy4_Box */ -void ScaleRowDown4Box_MMI(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - const uint8_t* src0_ptr = src_ptr; - const uint8_t* src1_ptr = src_ptr + src_stride; - const uint8_t* src2_ptr = src_ptr + src_stride * 2; - const uint8_t* src3_ptr = src_ptr + src_stride * 3; - - uint64_t src, src_hi, src_lo; - uint64_t dest, dest_hi, dest_lo, dest0, dest1, dest2, dest3; - - const uint64_t mask0 = 0x0ULL; - const uint64_t mask1 = 0x0001000100010001ULL; - const uint64_t ph = 0x0008000800080008ULL; - const uint64_t shift = 0x4ULL; - - __asm__ volatile( - "1: \n\t" - - DO_SCALEROWDOWN4BOX_LOOP(%[dest0]) - DO_SCALEROWDOWN4BOX_LOOP(%[dest1]) - DO_SCALEROWDOWN4BOX_LOOP(%[dest2]) - DO_SCALEROWDOWN4BOX_LOOP(%[dest3]) - - "packsswh %[dest_lo], %[dest0], %[dest1] \n\t" - "packsswh %[dest_hi], %[dest2], %[dest3] \n\t" - - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), - [dest_hi] "=&f"(dest_hi), [dest_lo] "=&f"(dest_lo), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [dest2] "=&f"(dest2), - [dest3] "=&f"(dest3), [src] "=&f"(src), [dest] "=&f"(dest) - : [src0_ptr] "r"(src0_ptr), [src1_ptr] "r"(src1_ptr), - [src2_ptr] "r"(src2_ptr), [src3_ptr] "r"(src3_ptr), [dst_ptr] "r"(dst), - [width] "r"(dst_width), [shift] "f"(shift), [mask0] "f"(mask0), - [ph] "f"(ph), [mask1] "f"(mask1) - : "memory"); -} - -#define DO_SCALEROWDOWN4BOX_16_PUNPCKADD() \ - "punpcklbh %[src_lo], %[src], %[mask0] \n\t" \ - "punpckhbh %[src_hi], %[src], %[mask0] \n\t" \ - "paddh %[dest_lo], %[dest_lo], %[src_lo] \n\t" \ - "paddh %[dest_hi], %[dest_hi], %[src_hi] \n\t" - -#define DO_SCALEROWDOWN4BOX_16_LOOP(reg) \ - "ldc1 %[src], 0x00(%[src0_ptr]) \n\t" \ - "punpcklbh %[dest_lo], %[src], %[mask0] \n\t" \ - "punpckhbh %[dest_hi], %[src], %[mask0] \n\t" \ - \ - "ldc1 %[src], 0x00(%[src1_ptr]) \n\t" \ - DO_SCALEROWDOWN4BOX_16_PUNPCKADD() \ - \ - "ldc1 %[src], 0x00(%[src2_ptr]) \n\t" \ - DO_SCALEROWDOWN4BOX_16_PUNPCKADD() \ - \ - "ldc1 %[src], 0x00(%[src3_ptr]) \n\t" \ - DO_SCALEROWDOWN4BOX_16_PUNPCKADD() \ - \ - "paddw %[dest], %[dest_lo], %[dest_hi] \n\t" \ - "punpckhwd %[dest_hi], %[dest], %[dest] \n\t" \ - "paddw %[dest], %[dest_hi], %[dest] \n\t" \ - "paddw %[dest], %[dest], %[ph] \n\t" \ - "psraw %[dest], %[dest], %[shift] \n\t" \ - "and " #reg ", %[dest], %[mask1] \n\t" \ - \ - "daddiu %[src0_ptr], %[src0_ptr], 0x08 \n\t" \ - "daddiu %[src1_ptr], %[src1_ptr], 0x08 \n\t" \ - "daddiu %[src2_ptr], %[src2_ptr], 0x08 \n\t" \ - "daddiu %[src3_ptr], %[src3_ptr], 0x08 \n\t" - -/* LibYUVScaleTest.ScaleDownBy4_Box_16 */ -void ScaleRowDown4Box_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width) { - const uint16_t* src0_ptr = src_ptr; - const uint16_t* src1_ptr = src_ptr + src_stride; - const uint16_t* src2_ptr = src_ptr + src_stride * 2; - const uint16_t* src3_ptr = src_ptr + src_stride * 3; - - uint64_t src, src_hi, src_lo; - uint64_t dest, dest_hi, dest_lo, dest0, dest1, dest2, dest3; - - const uint64_t mask0 = 0x0ULL; - const uint64_t mask1 = 0x00000000ffffffffULL; - const uint64_t ph = 0x0000000800000008ULL; - const uint64_t shift = 0x04ULL; - - __asm__ volatile( - "1: \n\t" - - DO_SCALEROWDOWN4BOX_16_LOOP(%[dest0]) - DO_SCALEROWDOWN4BOX_16_LOOP(%[dest1]) - DO_SCALEROWDOWN4BOX_16_LOOP(%[dest2]) - DO_SCALEROWDOWN4BOX_16_LOOP(%[dest3]) - "punpcklwd %[dest_lo], %[dest0], %[dest1] \n\t" - "punpcklwd %[dest_hi], %[dest2], %[dest3] \n\t" - - "packushb %[dest], %[dest_lo], %[dest_hi] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), - [dest_hi] "=&f"(dest_hi), [dest_lo] "=&f"(dest_lo), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [dest2] "=&f"(dest2), - [dest3] "=&f"(dest3), [src] "=&f"(src), [dest] "=&f"(dest) - : [src0_ptr] "r"(src0_ptr), [src1_ptr] "r"(src1_ptr), - [src2_ptr] "r"(src2_ptr), [src3_ptr] "r"(src3_ptr), [dst_ptr] "r"(dst), - [width] "r"(dst_width), [shift] "f"(shift), [mask0] "f"(mask0), - [ph] "f"(ph), [mask1] "f"(mask1) - : "memory"); -} - -// Scales a single row of pixels up by 2x using point sampling. -void ScaleColsUp2_MMI(uint8_t* dst_ptr, - const uint8_t* src_ptr, - int dst_width, - int x, - int dx) { - uint64_t src, dest; - - (void)x; - (void)dx; - - __asm__ volatile( - "1: \n\t" - "lwc1 %[src], 0x00(%[src_ptr]) \n\t" - - "punpcklbh %[dest], %[src], %[src] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x04 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [dest] "=&f"(dest) - : [src_ptr] "r"(src_ptr), [dst_ptr] "r"(dst_ptr), [width] "r"(dst_width) - : "memory"); -} - -void ScaleColsUp2_16_MMI(uint16_t* dst_ptr, - const uint16_t* src_ptr, - int dst_width, - int x, - int dx) { - uint64_t src, dest; - - (void)x; - (void)dx; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - - "punpcklhw %[dest], %[src], %[src] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "punpckhhw %[dest], %[src], %[src] \n\t" - "gssdlc1 %[dest], 0x0f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x08(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x10 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src] "=&f"(src), [dest] "=&f"(dest) - : [src_ptr] "r"(src_ptr), [dst_ptr] "r"(dst_ptr), [width] "r"(dst_width) - : "memory"); -} - -void ScaleAddRow_MMI(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width) { - uint64_t src, src_hi, src_lo, dest0, dest1; - const uint64_t mask = 0x0ULL; - - __asm__ volatile( - "1: \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - "punpcklbh %[src_lo], %[src], %[mask] \n\t" - "punpckhbh %[src_hi], %[src], %[mask] \n\t" - - "gsldrc1 %[dest0], 0x00(%[dst_ptr]) \n\t" - "gsldlc1 %[dest0], 0x07(%[dst_ptr]) \n\t" - "paddush %[dest0], %[dest0], %[src_lo] \n\t" - "gsldrc1 %[dest1], 0x08(%[dst_ptr]) \n\t" - "gsldlc1 %[dest1], 0x0f(%[dst_ptr]) \n\t" - "paddush %[dest1], %[dest1], %[src_hi] \n\t" - - "gssdlc1 %[dest0], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_ptr]) \n\t" - "gssdlc1 %[dest1], 0x0f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest1], 0x08(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x10 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [src_hi] "=&f"(src_hi), - [src_lo] "=&f"(src_lo), [src] "=&f"(src) - : [src_ptr] "r"(src_ptr), [dst_ptr] "r"(dst_ptr), [width] "r"(src_width), - [mask] "f"(mask) - : "memory"); -} - -void ScaleAddRow_16_MMI(const uint16_t* src_ptr, - uint32_t* dst_ptr, - int src_width) { - uint64_t src, src_hi, src_lo, dest0, dest1; - const uint64_t mask = 0x0ULL; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "punpcklhw %[src_lo], %[src], %[mask] \n\t" - "punpckhhw %[src_hi], %[src], %[mask] \n\t" - - "gsldrc1 %[dest0], 0x00(%[dst_ptr]) \n\t" - "gsldlc1 %[dest0], 0x07(%[dst_ptr]) \n\t" - "paddw %[dest0], %[dest0], %[src_lo] \n\t" - "gssdlc1 %[dest0], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_ptr]) \n\t" - - "gsldrc1 %[dest1], 0x08(%[dst_ptr]) \n\t" - "gsldlc1 %[dest1], 0x0f(%[dst_ptr]) \n\t" - "paddw %[dest1], %[dest1], %[src_hi] \n\t" - "gssdlc1 %[dest1], 0x0f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest1], 0x08(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x10 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [src_hi] "=&f"(src_hi), - [src_lo] "=&f"(src_lo), [src] "=&f"(src) - : [src_ptr] "r"(src_ptr), [dst_ptr] "r"(dst_ptr), [width] "r"(src_width), - [mask] "f"(mask) - : "memory"); -} - -void ScaleARGBRowDownEven_MMI(const uint8_t* src_argb, - ptrdiff_t src_stride, - int src_stepx, - uint8_t* dst_argb, - int dst_width) { - (void)src_stride; - - uint64_t src0, src1, dest; - - __asm__ volatile( - "1: \n\t" - "lwc1 %[src0], 0x00(%[src_ptr]) \n\t" - "dadd %[src_ptr], %[src_ptr], %[src_stepx_4]\n\t" - "lwc1 %[src1], 0x00(%[src_ptr]) \n\t" - "punpcklwd %[dest], %[src0], %[src1] \n\t" - - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "dadd %[src_ptr], %[src_ptr], %[src_stepx_4]\n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest] "=&f"(dest) - : [src_ptr] "r"(src_argb), [dst_ptr] "r"(dst_argb), - [src_stepx_4] "r"(src_stepx << 2), [width] "r"(dst_width) - : "memory"); -} - -void ScaleARGBRowDownEvenBox_MMI(const uint8_t* src_argb, - ptrdiff_t src_stride, - int src_stepx, - uint8_t* dst_argb, - int dst_width) { - const uint8_t* src0_ptr = src_argb; - const uint8_t* src1_ptr = src_argb + src_stride; - - uint64_t src0, src1, src_hi, src_lo; - uint64_t dest, dest_hi, dest_lo, dest0, dest1; - - const uint64_t mask = 0x0ULL; - const uint64_t ph = 0x0002000200020002ULL; - const uint64_t shift = 0x2ULL; - - __asm__ volatile( - "1: \n\t" - - "lwc1 %[src0], 0x00(%[src0_ptr]) \n\t" - "punpcklbh %[dest_lo], %[src0], %[mask] \n\t" - "lwc1 %[src0], 0x04(%[src0_ptr]) \n\t" - "punpcklbh %[dest_hi], %[src0], %[mask] \n\t" - - "lwc1 %[src1], 0x00(%[src1_ptr]) \n\t" - "punpcklbh %[src_lo], %[src1], %[mask] \n\t" - "lwc1 %[src1], 0x04(%[src1_ptr]) \n\t" - "punpcklbh %[src_hi], %[src1], %[mask] \n\t" - "paddh %[dest_lo], %[dest_lo], %[src_lo] \n\t" - "paddh %[dest_hi], %[dest_hi], %[src_hi] \n\t" - "paddh %[dest0], %[dest_hi], %[dest_lo] \n\t" - "paddh %[dest0], %[dest0], %[ph] \n\t" - "psrlh %[dest0], %[dest0], %[shift] \n\t" - - "dadd %[src0_ptr], %[src0_ptr], %[src_stepx_4] \n\t" - "dadd %[src1_ptr], %[src1_ptr], %[src_stepx_4] \n\t" - - "lwc1 %[src0], 0x00(%[src0_ptr]) \n\t" - "punpcklbh %[dest_lo], %[src0], %[mask] \n\t" - "lwc1 %[src0], 0x04(%[src0_ptr]) \n\t" - "punpcklbh %[dest_hi], %[src0], %[mask] \n\t" - - "lwc1 %[src1], 0x00(%[src1_ptr]) \n\t" - "punpcklbh %[src_lo], %[src1], %[mask] \n\t" - "lwc1 %[src1], 0x04(%[src1_ptr]) \n\t" - "punpcklbh %[src_hi], %[src1], %[mask] \n\t" - "paddh %[dest_lo], %[dest_lo], %[src_lo] \n\t" - "paddh %[dest_hi], %[dest_hi], %[src_hi] \n\t" - "paddh %[dest1], %[dest_hi], %[dest_lo] \n\t" - "paddh %[dest1], %[dest1], %[ph] \n\t" - "psrlh %[dest1], %[dest1], %[shift] \n\t" - - "packushb %[dest], %[dest0], %[dest1] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "dadd %[src0_ptr], %[src0_ptr], %[src_stepx_4] \n\t" - "dadd %[src1_ptr], %[src1_ptr], %[src_stepx_4] \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x08 \n\t" - "daddi %[width], %[width], -0x02 \n\t" - "bnez %[width], 1b \n\t" - : [src_hi] "=&f"(src_hi), [src_lo] "=&f"(src_lo), - [dest_hi] "=&f"(dest_hi), [dest_lo] "=&f"(dest_lo), - [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [src0] "=&f"(src0), - [src1] "=&f"(src1), [dest] "=&f"(dest) - : [src0_ptr] "r"(src0_ptr), [src1_ptr] "r"(src1_ptr), - [dst_ptr] "r"(dst_argb), [width] "r"(dst_width), - [src_stepx_4] "r"(src_stepx << 2), [shift] "f"(shift), [mask] "f"(mask), - [ph] "f"(ph) - : "memory"); -} - -// Scales a single row of pixels using point sampling. -void ScaleARGBCols_MMI(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx) { - const uint32_t* src = (const uint32_t*)(src_argb); - uint32_t* dst = (uint32_t*)(dst_argb); - - const uint32_t* src_tmp; - - uint64_t dest, offset; - - const uint64_t shift0 = 16; - const uint64_t shift1 = 2; - - __asm__ volatile( - "1: \n\t" - "srav %[offset], %[x], %[shift0] \n\t" - "sllv %[offset], %[offset], %[shift1] \n\t" - "dadd %[src_tmp], %[src_ptr], %[offset] \n\t" - "lwc1 %[dest], 0x00(%[src_tmp]) \n\t" - "swc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - "dadd %[x], %[x], %[dx] \n\t" - - "daddiu %[dst_ptr], %[dst_ptr], 0x04 \n\t" - "daddi %[width], %[width], -0x01 \n\t" - "bnez %[width], 1b \n\t" - : [dest] "=&f"(dest), [offset] "=&r"(offset), [src_tmp] "=&r"(src_tmp) - : [src_ptr] "r"(src), [dst_ptr] "r"(dst), [width] "r"(dst_width), - [dx] "r"(dx), [x] "r"(x), [shift0] "r"(shift0), [shift1] "r"(shift1) - : "memory"); -} - -// Scales a single row of pixels up by 2x using point sampling. -void ScaleARGBColsUp2_MMI(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx) { - uint64_t src, dest0, dest1; - (void)x; - (void)dx; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src], 0x00(%[src_ptr]) \n\t" - "gsldlc1 %[src], 0x07(%[src_ptr]) \n\t" - "punpcklwd %[dest0], %[src], %[src] \n\t" - "gssdlc1 %[dest0], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest0], 0x00(%[dst_ptr]) \n\t" - "punpckhwd %[dest1], %[src], %[src] \n\t" - "gssdlc1 %[dest1], 0x0f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest1], 0x08(%[dst_ptr]) \n\t" - - "daddiu %[src_ptr], %[src_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x10 \n\t" - "daddi %[width], %[width], -0x04 \n\t" - "bnez %[width], 1b \n\t" - : [dest0] "=&f"(dest0), [dest1] "=&f"(dest1), [src] "=&f"(src) - : [src_ptr] "r"(src_argb), [dst_ptr] "r"(dst_argb), [width] "r"(dst_width) - : "memory"); -} - -// Divide num by div and return as 16.16 fixed point result. -/* LibYUVBaseTest.TestFixedDiv */ -int FixedDiv_MIPS(int num, int div) { - int quotient = 0; - const int shift = 16; - - asm( - "dsll %[num], %[num], %[shift] \n\t" - "ddiv %[num], %[div] \t\n" - "mflo %[quo] \t\n" - : [quo] "+&r"(quotient) - : [num] "r"(num), [div] "r"(div), [shift] "r"(shift)); - - return quotient; -} - -// Divide num by div and return as 16.16 fixed point result. -/* LibYUVScaleTest.ARGBScaleTo320x240_Linear */ -int FixedDiv1_MIPS(int num, int div) { - int quotient = 0; - const int shift = 16; - const int val1 = 1; - const int64_t val11 = 0x00010001ULL; - - asm( - "dsll %[num], %[num], %[shift] \n\t" - "dsub %[num], %[num], %[val11] \n\t" - "dsub %[div], %[div], %[val1] \n\t" - "ddiv %[num], %[div] \t\n" - "mflo %[quo] \t\n" - : [quo] "+&r"(quotient) - : [num] "r"(num), [div] "r"(div), [val1] "r"(val1), [val11] "r"(val11), - [shift] "r"(shift)); - - return quotient; -} - -// Read 8x2 upsample with filtering and write 16x1. -// actually reads an extra pixel, so 9x2. -void ScaleRowUp2_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width) { - const uint16_t* src2_ptr = src_ptr + src_stride; - - uint64_t src0, src1; - uint64_t dest, dest04, dest15, dest26, dest37; - uint64_t tmp0, tmp1, tmp2, tmp3; - - const uint64_t mask0 = 0x0003000900030009ULL; - const uint64_t mask1 = 0x0001000300010003ULL; - const uint64_t mask2 = 0x0009000300090003ULL; - const uint64_t mask3 = 0x0003000100030001ULL; - const uint64_t ph = 0x0000000800000008ULL; - const uint64_t shift = 4; - - __asm__ volatile( - "1: \n\t" - "gsldrc1 %[src0], 0x00(%[src1_ptr]) \n\t" - "gsldlc1 %[src0], 0x07(%[src1_ptr]) \n\t" - "pmaddhw %[dest04], %[src0], %[mask0] \n\t" - "gsldrc1 %[src1], 0x00(%[src2_ptr]) \n\t" - "gsldlc1 %[src1], 0x07(%[src2_ptr]) \n\t" - "pmaddhw %[dest], %[src1], %[mask1] \n\t" - "paddw %[dest04], %[dest04], %[dest] \n\t" - "paddw %[dest04], %[dest04], %[ph] \n\t" - "psrlw %[dest04], %[dest04], %[shift] \n\t" - - "pmaddhw %[dest15], %[src0], %[mask2] \n\t" - "pmaddhw %[dest], %[src1], %[mask3] \n\t" - "paddw %[dest15], %[dest15], %[dest] \n\t" - "paddw %[dest15], %[dest15], %[ph] \n\t" - "psrlw %[dest15], %[dest15], %[shift] \n\t" - - "gsldrc1 %[src0], 0x02(%[src1_ptr]) \n\t" - "gsldlc1 %[src0], 0x09(%[src1_ptr]) \n\t" - "pmaddhw %[dest26], %[src0], %[mask0] \n\t" - "gsldrc1 %[src1], 0x02(%[src2_ptr]) \n\t" - "gsldlc1 %[src1], 0x09(%[src2_ptr]) \n\t" - "pmaddhw %[dest], %[src1], %[mask1] \n\t" - "paddw %[dest26], %[dest26], %[dest] \n\t" - "paddw %[dest26], %[dest26], %[ph] \n\t" - "psrlw %[dest26], %[dest26], %[shift] \n\t" - - "pmaddhw %[dest37], %[src0], %[mask2] \n\t" - "pmaddhw %[dest], %[src1], %[mask3] \n\t" - "paddw %[dest37], %[dest37], %[dest] \n\t" - "paddw %[dest37], %[dest37], %[ph] \n\t" - "psrlw %[dest37], %[dest37], %[shift] \n\t" - - /* tmp0 = ( 00 04 02 06 ) */ - "packsswh %[tmp0], %[dest04], %[dest26] \n\t" - /* tmp1 = ( 01 05 03 07 ) */ - "packsswh %[tmp1], %[dest15], %[dest37] \n\t" - - /* tmp2 = ( 00 01 04 05 )*/ - "punpcklhw %[tmp2], %[tmp0], %[tmp1] \n\t" - /* tmp3 = ( 02 03 06 07 )*/ - "punpckhhw %[tmp3], %[tmp0], %[tmp1] \n\t" - - /* ( 00 01 02 03 ) */ - "punpcklwd %[dest], %[tmp2], %[tmp3] \n\t" - "gssdlc1 %[dest], 0x07(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x00(%[dst_ptr]) \n\t" - - /* ( 04 05 06 07 ) */ - "punpckhwd %[dest], %[tmp2], %[tmp3] \n\t" - "gssdlc1 %[dest], 0x0f(%[dst_ptr]) \n\t" - "gssdrc1 %[dest], 0x08(%[dst_ptr]) \n\t" - - "daddiu %[src1_ptr], %[src1_ptr], 0x08 \n\t" - "daddiu %[src2_ptr], %[src2_ptr], 0x08 \n\t" - "daddiu %[dst_ptr], %[dst_ptr], 0x10 \n\t" - "daddi %[width], %[width], -0x08 \n\t" - "bnez %[width], 1b \n\t" - : [src0] "=&f"(src0), [src1] "=&f"(src1), [dest04] "=&f"(dest04), - [dest15] "=&f"(dest15), [dest26] "=&f"(dest26), [dest37] "=&f"(dest37), - [tmp0] "=&f"(tmp0), [tmp1] "=&f"(tmp1), [tmp2] "=&f"(tmp2), - [tmp3] "=&f"(tmp3), [dest] "=&f"(dest) - : [src1_ptr] "r"(src_ptr), [src2_ptr] "r"(src2_ptr), [dst_ptr] "r"(dst), - [width] "r"(dst_width), [mask0] "f"(mask0), [mask1] "f"(mask1), - [mask2] "f"(mask2), [mask3] "f"(mask3), [shift] "f"(shift), [ph] "f"(ph) - : "memory"); -} - -// clang-format on - -#endif // !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) - -#ifdef __cplusplus -} // extern "C" -} // namespace libyuv -#endif diff --git a/libs/libyuv/source/scale_msa.cc b/libs/libyuv/source/scale_msa.cc deleted file mode 100644 index 482a521f0d..0000000000 --- a/libs/libyuv/source/scale_msa.cc +++ /dev/null @@ -1,949 +0,0 @@ -/* - * Copyright 2016 The LibYuv Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include - -#include "libyuv/scale_row.h" - -// This module is for GCC MSA -#if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) -#include "libyuv/macros_msa.h" - -#ifdef __cplusplus -namespace libyuv { -extern "C" { -#endif - -#define LOAD_INDEXED_DATA(srcp, indx0, out0) \ - { \ - out0[0] = srcp[indx0[0]]; \ - out0[1] = srcp[indx0[1]]; \ - out0[2] = srcp[indx0[2]]; \ - out0[3] = srcp[indx0[3]]; \ - } - -void ScaleARGBRowDown2_MSA(const uint8_t* src_argb, - ptrdiff_t src_stride, - uint8_t* dst_argb, - int dst_width) { - int x; - v16u8 src0, src1, dst0; - (void)src_stride; - - for (x = 0; x < dst_width; x += 4) { - src0 = (v16u8)__msa_ld_b((v16i8*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)src_argb, 16); - dst0 = (v16u8)__msa_pckod_w((v4i32)src1, (v4i32)src0); - ST_UB(dst0, dst_argb); - src_argb += 32; - dst_argb += 16; - } -} - -void ScaleARGBRowDown2Linear_MSA(const uint8_t* src_argb, - ptrdiff_t src_stride, - uint8_t* dst_argb, - int dst_width) { - int x; - v16u8 src0, src1, vec0, vec1, dst0; - (void)src_stride; - - for (x = 0; x < dst_width; x += 4) { - src0 = (v16u8)__msa_ld_b((v16i8*)src_argb, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)src_argb, 16); - vec0 = (v16u8)__msa_pckev_w((v4i32)src1, (v4i32)src0); - vec1 = (v16u8)__msa_pckod_w((v4i32)src1, (v4i32)src0); - dst0 = (v16u8)__msa_aver_u_b((v16u8)vec0, (v16u8)vec1); - ST_UB(dst0, dst_argb); - src_argb += 32; - dst_argb += 16; - } -} - -void ScaleARGBRowDown2Box_MSA(const uint8_t* src_argb, - ptrdiff_t src_stride, - uint8_t* dst_argb, - int dst_width) { - int x; - const uint8_t* s = src_argb; - const uint8_t* t = src_argb + src_stride; - v16u8 src0, src1, src2, src3, vec0, vec1, vec2, vec3, dst0; - v8u16 reg0, reg1, reg2, reg3; - v16i8 shuffler = {0, 4, 1, 5, 2, 6, 3, 7, 8, 12, 9, 13, 10, 14, 11, 15}; - - for (x = 0; x < dst_width; x += 4) { - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)s, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)t, 0); - src3 = (v16u8)__msa_ld_b((v16i8*)t, 16); - vec0 = (v16u8)__msa_vshf_b(shuffler, (v16i8)src0, (v16i8)src0); - vec1 = (v16u8)__msa_vshf_b(shuffler, (v16i8)src1, (v16i8)src1); - vec2 = (v16u8)__msa_vshf_b(shuffler, (v16i8)src2, (v16i8)src2); - vec3 = (v16u8)__msa_vshf_b(shuffler, (v16i8)src3, (v16i8)src3); - reg0 = __msa_hadd_u_h(vec0, vec0); - reg1 = __msa_hadd_u_h(vec1, vec1); - reg2 = __msa_hadd_u_h(vec2, vec2); - reg3 = __msa_hadd_u_h(vec3, vec3); - reg0 += reg2; - reg1 += reg3; - reg0 = (v8u16)__msa_srari_h((v8i16)reg0, 2); - reg1 = (v8u16)__msa_srari_h((v8i16)reg1, 2); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg1, (v16i8)reg0); - ST_UB(dst0, dst_argb); - s += 32; - t += 32; - dst_argb += 16; - } -} - -void ScaleARGBRowDownEven_MSA(const uint8_t* src_argb, - ptrdiff_t src_stride, - int32_t src_stepx, - uint8_t* dst_argb, - int dst_width) { - int x; - int32_t stepx = src_stepx * 4; - int32_t data0, data1, data2, data3; - (void)src_stride; - - for (x = 0; x < dst_width; x += 4) { - data0 = LW(src_argb); - data1 = LW(src_argb + stepx); - data2 = LW(src_argb + stepx * 2); - data3 = LW(src_argb + stepx * 3); - SW(data0, dst_argb); - SW(data1, dst_argb + 4); - SW(data2, dst_argb + 8); - SW(data3, dst_argb + 12); - src_argb += stepx * 4; - dst_argb += 16; - } -} - -void ScaleARGBRowDownEvenBox_MSA(const uint8_t* src_argb, - ptrdiff_t src_stride, - int src_stepx, - uint8_t* dst_argb, - int dst_width) { - int x; - const uint8_t* nxt_argb = src_argb + src_stride; - int32_t stepx = src_stepx * 4; - int64_t data0, data1, data2, data3; - v16u8 src0 = {0}, src1 = {0}, src2 = {0}, src3 = {0}; - v16u8 vec0, vec1, vec2, vec3; - v8u16 reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7; - v16u8 dst0; - - for (x = 0; x < dst_width; x += 4) { - data0 = LD(src_argb); - data1 = LD(src_argb + stepx); - data2 = LD(src_argb + stepx * 2); - data3 = LD(src_argb + stepx * 3); - src0 = (v16u8)__msa_insert_d((v2i64)src0, 0, data0); - src0 = (v16u8)__msa_insert_d((v2i64)src0, 1, data1); - src1 = (v16u8)__msa_insert_d((v2i64)src1, 0, data2); - src1 = (v16u8)__msa_insert_d((v2i64)src1, 1, data3); - data0 = LD(nxt_argb); - data1 = LD(nxt_argb + stepx); - data2 = LD(nxt_argb + stepx * 2); - data3 = LD(nxt_argb + stepx * 3); - src2 = (v16u8)__msa_insert_d((v2i64)src2, 0, data0); - src2 = (v16u8)__msa_insert_d((v2i64)src2, 1, data1); - src3 = (v16u8)__msa_insert_d((v2i64)src3, 0, data2); - src3 = (v16u8)__msa_insert_d((v2i64)src3, 1, data3); - vec0 = (v16u8)__msa_ilvr_b((v16i8)src2, (v16i8)src0); - vec1 = (v16u8)__msa_ilvr_b((v16i8)src3, (v16i8)src1); - vec2 = (v16u8)__msa_ilvl_b((v16i8)src2, (v16i8)src0); - vec3 = (v16u8)__msa_ilvl_b((v16i8)src3, (v16i8)src1); - reg0 = __msa_hadd_u_h(vec0, vec0); - reg1 = __msa_hadd_u_h(vec1, vec1); - reg2 = __msa_hadd_u_h(vec2, vec2); - reg3 = __msa_hadd_u_h(vec3, vec3); - reg4 = (v8u16)__msa_pckev_d((v2i64)reg2, (v2i64)reg0); - reg5 = (v8u16)__msa_pckev_d((v2i64)reg3, (v2i64)reg1); - reg6 = (v8u16)__msa_pckod_d((v2i64)reg2, (v2i64)reg0); - reg7 = (v8u16)__msa_pckod_d((v2i64)reg3, (v2i64)reg1); - reg4 += reg6; - reg5 += reg7; - reg4 = (v8u16)__msa_srari_h((v8i16)reg4, 2); - reg5 = (v8u16)__msa_srari_h((v8i16)reg5, 2); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg5, (v16i8)reg4); - ST_UB(dst0, dst_argb); - src_argb += stepx * 4; - nxt_argb += stepx * 4; - dst_argb += 16; - } -} - -void ScaleRowDown2_MSA(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - int x; - v16u8 src0, src1, src2, src3, dst0, dst1; - (void)src_stride; - - for (x = 0; x < dst_width; x += 32) { - src0 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 32); - src3 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 48); - dst0 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - dst1 = (v16u8)__msa_pckod_b((v16i8)src3, (v16i8)src2); - ST_UB2(dst0, dst1, dst, 16); - src_ptr += 64; - dst += 32; - } -} - -void ScaleRowDown2Linear_MSA(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - int x; - v16u8 src0, src1, src2, src3, vec0, vec1, vec2, vec3, dst0, dst1; - (void)src_stride; - - for (x = 0; x < dst_width; x += 32) { - src0 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 32); - src3 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 48); - vec0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - vec2 = (v16u8)__msa_pckev_b((v16i8)src3, (v16i8)src2); - vec1 = (v16u8)__msa_pckod_b((v16i8)src1, (v16i8)src0); - vec3 = (v16u8)__msa_pckod_b((v16i8)src3, (v16i8)src2); - dst0 = __msa_aver_u_b(vec1, vec0); - dst1 = __msa_aver_u_b(vec3, vec2); - ST_UB2(dst0, dst1, dst, 16); - src_ptr += 64; - dst += 32; - } -} - -void ScaleRowDown2Box_MSA(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - int x; - const uint8_t* s = src_ptr; - const uint8_t* t = src_ptr + src_stride; - v16u8 src0, src1, src2, src3, src4, src5, src6, src7, dst0, dst1; - v8u16 vec0, vec1, vec2, vec3; - - for (x = 0; x < dst_width; x += 32) { - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)s, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)s, 32); - src3 = (v16u8)__msa_ld_b((v16i8*)s, 48); - src4 = (v16u8)__msa_ld_b((v16i8*)t, 0); - src5 = (v16u8)__msa_ld_b((v16i8*)t, 16); - src6 = (v16u8)__msa_ld_b((v16i8*)t, 32); - src7 = (v16u8)__msa_ld_b((v16i8*)t, 48); - vec0 = __msa_hadd_u_h(src0, src0); - vec1 = __msa_hadd_u_h(src1, src1); - vec2 = __msa_hadd_u_h(src2, src2); - vec3 = __msa_hadd_u_h(src3, src3); - vec0 += __msa_hadd_u_h(src4, src4); - vec1 += __msa_hadd_u_h(src5, src5); - vec2 += __msa_hadd_u_h(src6, src6); - vec3 += __msa_hadd_u_h(src7, src7); - vec0 = (v8u16)__msa_srari_h((v8i16)vec0, 2); - vec1 = (v8u16)__msa_srari_h((v8i16)vec1, 2); - vec2 = (v8u16)__msa_srari_h((v8i16)vec2, 2); - vec3 = (v8u16)__msa_srari_h((v8i16)vec3, 2); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - dst1 = (v16u8)__msa_pckev_b((v16i8)vec3, (v16i8)vec2); - ST_UB2(dst0, dst1, dst, 16); - s += 64; - t += 64; - dst += 32; - } -} - -void ScaleRowDown4_MSA(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - int x; - v16u8 src0, src1, src2, src3, vec0, vec1, dst0; - (void)src_stride; - - for (x = 0; x < dst_width; x += 16) { - src0 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 32); - src3 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 48); - vec0 = (v16u8)__msa_pckev_b((v16i8)src1, (v16i8)src0); - vec1 = (v16u8)__msa_pckev_b((v16i8)src3, (v16i8)src2); - dst0 = (v16u8)__msa_pckod_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst); - src_ptr += 64; - dst += 16; - } -} - -void ScaleRowDown4Box_MSA(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - int x; - const uint8_t* s = src_ptr; - const uint8_t* t0 = s + src_stride; - const uint8_t* t1 = s + src_stride * 2; - const uint8_t* t2 = s + src_stride * 3; - v16u8 src0, src1, src2, src3, src4, src5, src6, src7, dst0; - v8u16 vec0, vec1, vec2, vec3; - v4u32 reg0, reg1, reg2, reg3; - - for (x = 0; x < dst_width; x += 16) { - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)s, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)s, 32); - src3 = (v16u8)__msa_ld_b((v16i8*)s, 48); - src4 = (v16u8)__msa_ld_b((v16i8*)t0, 0); - src5 = (v16u8)__msa_ld_b((v16i8*)t0, 16); - src6 = (v16u8)__msa_ld_b((v16i8*)t0, 32); - src7 = (v16u8)__msa_ld_b((v16i8*)t0, 48); - vec0 = __msa_hadd_u_h(src0, src0); - vec1 = __msa_hadd_u_h(src1, src1); - vec2 = __msa_hadd_u_h(src2, src2); - vec3 = __msa_hadd_u_h(src3, src3); - vec0 += __msa_hadd_u_h(src4, src4); - vec1 += __msa_hadd_u_h(src5, src5); - vec2 += __msa_hadd_u_h(src6, src6); - vec3 += __msa_hadd_u_h(src7, src7); - src0 = (v16u8)__msa_ld_b((v16i8*)t1, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)t1, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)t1, 32); - src3 = (v16u8)__msa_ld_b((v16i8*)t1, 48); - src4 = (v16u8)__msa_ld_b((v16i8*)t2, 0); - src5 = (v16u8)__msa_ld_b((v16i8*)t2, 16); - src6 = (v16u8)__msa_ld_b((v16i8*)t2, 32); - src7 = (v16u8)__msa_ld_b((v16i8*)t2, 48); - vec0 += __msa_hadd_u_h(src0, src0); - vec1 += __msa_hadd_u_h(src1, src1); - vec2 += __msa_hadd_u_h(src2, src2); - vec3 += __msa_hadd_u_h(src3, src3); - vec0 += __msa_hadd_u_h(src4, src4); - vec1 += __msa_hadd_u_h(src5, src5); - vec2 += __msa_hadd_u_h(src6, src6); - vec3 += __msa_hadd_u_h(src7, src7); - reg0 = __msa_hadd_u_w(vec0, vec0); - reg1 = __msa_hadd_u_w(vec1, vec1); - reg2 = __msa_hadd_u_w(vec2, vec2); - reg3 = __msa_hadd_u_w(vec3, vec3); - reg0 = (v4u32)__msa_srari_w((v4i32)reg0, 4); - reg1 = (v4u32)__msa_srari_w((v4i32)reg1, 4); - reg2 = (v4u32)__msa_srari_w((v4i32)reg2, 4); - reg3 = (v4u32)__msa_srari_w((v4i32)reg3, 4); - vec0 = (v8u16)__msa_pckev_h((v8i16)reg1, (v8i16)reg0); - vec1 = (v8u16)__msa_pckev_h((v8i16)reg3, (v8i16)reg2); - dst0 = (v16u8)__msa_pckev_b((v16i8)vec1, (v16i8)vec0); - ST_UB(dst0, dst); - s += 64; - t0 += 64; - t1 += 64; - t2 += 64; - dst += 16; - } -} - -void ScaleRowDown38_MSA(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - int x, width; - uint64_t dst0; - uint32_t dst1; - v16u8 src0, src1, vec0; - v16i8 mask = {0, 3, 6, 8, 11, 14, 16, 19, 22, 24, 27, 30, 0, 0, 0, 0}; - (void)src_stride; - - assert(dst_width % 3 == 0); - width = dst_width / 3; - - for (x = 0; x < width; x += 4) { - src0 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 16); - vec0 = (v16u8)__msa_vshf_b(mask, (v16i8)src1, (v16i8)src0); - dst0 = __msa_copy_u_d((v2i64)vec0, 0); - dst1 = __msa_copy_u_w((v4i32)vec0, 2); - SD(dst0, dst); - SW(dst1, dst + 8); - src_ptr += 32; - dst += 12; - } -} - -void ScaleRowDown38_2_Box_MSA(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - int x, width; - const uint8_t* s = src_ptr; - const uint8_t* t = src_ptr + src_stride; - uint64_t dst0; - uint32_t dst1; - v16u8 src0, src1, src2, src3, out; - v8u16 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7; - v4u32 tmp0, tmp1, tmp2, tmp3, tmp4; - v8i16 zero = {0}; - v8i16 mask = {0, 1, 2, 8, 3, 4, 5, 9}; - v16i8 dst_mask = {0, 2, 16, 4, 6, 18, 8, 10, 20, 12, 14, 22, 0, 0, 0, 0}; - v4u32 const_0x2AAA = (v4u32)__msa_fill_w(0x2AAA); - v4u32 const_0x4000 = (v4u32)__msa_fill_w(0x4000); - - assert((dst_width % 3 == 0) && (dst_width > 0)); - width = dst_width / 3; - - for (x = 0; x < width; x += 4) { - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)s, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)t, 0); - src3 = (v16u8)__msa_ld_b((v16i8*)t, 16); - vec0 = (v8u16)__msa_ilvr_b((v16i8)src2, (v16i8)src0); - vec1 = (v8u16)__msa_ilvl_b((v16i8)src2, (v16i8)src0); - vec2 = (v8u16)__msa_ilvr_b((v16i8)src3, (v16i8)src1); - vec3 = (v8u16)__msa_ilvl_b((v16i8)src3, (v16i8)src1); - vec0 = __msa_hadd_u_h((v16u8)vec0, (v16u8)vec0); - vec1 = __msa_hadd_u_h((v16u8)vec1, (v16u8)vec1); - vec2 = __msa_hadd_u_h((v16u8)vec2, (v16u8)vec2); - vec3 = __msa_hadd_u_h((v16u8)vec3, (v16u8)vec3); - vec4 = (v8u16)__msa_vshf_h(mask, zero, (v8i16)vec0); - vec5 = (v8u16)__msa_vshf_h(mask, zero, (v8i16)vec1); - vec6 = (v8u16)__msa_vshf_h(mask, zero, (v8i16)vec2); - vec7 = (v8u16)__msa_vshf_h(mask, zero, (v8i16)vec3); - vec0 = (v8u16)__msa_pckod_w((v4i32)vec1, (v4i32)vec0); - vec1 = (v8u16)__msa_pckod_w((v4i32)vec3, (v4i32)vec2); - vec0 = (v8u16)__msa_pckod_w((v4i32)vec1, (v4i32)vec0); - tmp0 = __msa_hadd_u_w(vec4, vec4); - tmp1 = __msa_hadd_u_w(vec5, vec5); - tmp2 = __msa_hadd_u_w(vec6, vec6); - tmp3 = __msa_hadd_u_w(vec7, vec7); - tmp4 = __msa_hadd_u_w(vec0, vec0); - vec0 = (v8u16)__msa_pckev_h((v8i16)tmp1, (v8i16)tmp0); - vec1 = (v8u16)__msa_pckev_h((v8i16)tmp3, (v8i16)tmp2); - tmp0 = __msa_hadd_u_w(vec0, vec0); - tmp1 = __msa_hadd_u_w(vec1, vec1); - tmp0 *= const_0x2AAA; - tmp1 *= const_0x2AAA; - tmp4 *= const_0x4000; - tmp0 = (v4u32)__msa_srai_w((v4i32)tmp0, 16); - tmp1 = (v4u32)__msa_srai_w((v4i32)tmp1, 16); - tmp4 = (v4u32)__msa_srai_w((v4i32)tmp4, 16); - vec0 = (v8u16)__msa_pckev_h((v8i16)tmp1, (v8i16)tmp0); - vec1 = (v8u16)__msa_pckev_h((v8i16)tmp4, (v8i16)tmp4); - out = (v16u8)__msa_vshf_b(dst_mask, (v16i8)vec1, (v16i8)vec0); - dst0 = __msa_copy_u_d((v2i64)out, 0); - dst1 = __msa_copy_u_w((v4i32)out, 2); - SD(dst0, dst_ptr); - SW(dst1, dst_ptr + 8); - s += 32; - t += 32; - dst_ptr += 12; - } -} - -void ScaleRowDown38_3_Box_MSA(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - int x, width; - const uint8_t* s = src_ptr; - const uint8_t* t0 = s + src_stride; - const uint8_t* t1 = s + src_stride * 2; - uint64_t dst0; - uint32_t dst1; - v16u8 src0, src1, src2, src3, src4, src5, out; - v8u16 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7; - v4u32 tmp0, tmp1, tmp2, tmp3, tmp4; - v8u16 zero = {0}; - v8i16 mask = {0, 1, 2, 8, 3, 4, 5, 9}; - v16i8 dst_mask = {0, 2, 16, 4, 6, 18, 8, 10, 20, 12, 14, 22, 0, 0, 0, 0}; - v4u32 const_0x1C71 = (v4u32)__msa_fill_w(0x1C71); - v4u32 const_0x2AAA = (v4u32)__msa_fill_w(0x2AAA); - - assert((dst_width % 3 == 0) && (dst_width > 0)); - width = dst_width / 3; - - for (x = 0; x < width; x += 4) { - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)s, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)t0, 0); - src3 = (v16u8)__msa_ld_b((v16i8*)t0, 16); - src4 = (v16u8)__msa_ld_b((v16i8*)t1, 0); - src5 = (v16u8)__msa_ld_b((v16i8*)t1, 16); - vec0 = (v8u16)__msa_ilvr_b((v16i8)src2, (v16i8)src0); - vec1 = (v8u16)__msa_ilvl_b((v16i8)src2, (v16i8)src0); - vec2 = (v8u16)__msa_ilvr_b((v16i8)src3, (v16i8)src1); - vec3 = (v8u16)__msa_ilvl_b((v16i8)src3, (v16i8)src1); - vec4 = (v8u16)__msa_ilvr_b((v16i8)zero, (v16i8)src4); - vec5 = (v8u16)__msa_ilvl_b((v16i8)zero, (v16i8)src4); - vec6 = (v8u16)__msa_ilvr_b((v16i8)zero, (v16i8)src5); - vec7 = (v8u16)__msa_ilvl_b((v16i8)zero, (v16i8)src5); - vec0 = __msa_hadd_u_h((v16u8)vec0, (v16u8)vec0); - vec1 = __msa_hadd_u_h((v16u8)vec1, (v16u8)vec1); - vec2 = __msa_hadd_u_h((v16u8)vec2, (v16u8)vec2); - vec3 = __msa_hadd_u_h((v16u8)vec3, (v16u8)vec3); - vec0 += __msa_hadd_u_h((v16u8)vec4, (v16u8)vec4); - vec1 += __msa_hadd_u_h((v16u8)vec5, (v16u8)vec5); - vec2 += __msa_hadd_u_h((v16u8)vec6, (v16u8)vec6); - vec3 += __msa_hadd_u_h((v16u8)vec7, (v16u8)vec7); - vec4 = (v8u16)__msa_vshf_h(mask, (v8i16)zero, (v8i16)vec0); - vec5 = (v8u16)__msa_vshf_h(mask, (v8i16)zero, (v8i16)vec1); - vec6 = (v8u16)__msa_vshf_h(mask, (v8i16)zero, (v8i16)vec2); - vec7 = (v8u16)__msa_vshf_h(mask, (v8i16)zero, (v8i16)vec3); - vec0 = (v8u16)__msa_pckod_w((v4i32)vec1, (v4i32)vec0); - vec1 = (v8u16)__msa_pckod_w((v4i32)vec3, (v4i32)vec2); - vec0 = (v8u16)__msa_pckod_w((v4i32)vec1, (v4i32)vec0); - tmp0 = __msa_hadd_u_w(vec4, vec4); - tmp1 = __msa_hadd_u_w(vec5, vec5); - tmp2 = __msa_hadd_u_w(vec6, vec6); - tmp3 = __msa_hadd_u_w(vec7, vec7); - tmp4 = __msa_hadd_u_w(vec0, vec0); - vec0 = (v8u16)__msa_pckev_h((v8i16)tmp1, (v8i16)tmp0); - vec1 = (v8u16)__msa_pckev_h((v8i16)tmp3, (v8i16)tmp2); - tmp0 = __msa_hadd_u_w(vec0, vec0); - tmp1 = __msa_hadd_u_w(vec1, vec1); - tmp0 *= const_0x1C71; - tmp1 *= const_0x1C71; - tmp4 *= const_0x2AAA; - tmp0 = (v4u32)__msa_srai_w((v4i32)tmp0, 16); - tmp1 = (v4u32)__msa_srai_w((v4i32)tmp1, 16); - tmp4 = (v4u32)__msa_srai_w((v4i32)tmp4, 16); - vec0 = (v8u16)__msa_pckev_h((v8i16)tmp1, (v8i16)tmp0); - vec1 = (v8u16)__msa_pckev_h((v8i16)tmp4, (v8i16)tmp4); - out = (v16u8)__msa_vshf_b(dst_mask, (v16i8)vec1, (v16i8)vec0); - dst0 = __msa_copy_u_d((v2i64)out, 0); - dst1 = __msa_copy_u_w((v4i32)out, 2); - SD(dst0, dst_ptr); - SW(dst1, dst_ptr + 8); - s += 32; - t0 += 32; - t1 += 32; - dst_ptr += 12; - } -} - -void ScaleAddRow_MSA(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width) { - int x; - v16u8 src0; - v8u16 dst0, dst1; - v16i8 zero = {0}; - - assert(src_width > 0); - - for (x = 0; x < src_width; x += 16) { - src0 = LD_UB(src_ptr); - dst0 = (v8u16)__msa_ld_h((v8i16*)dst_ptr, 0); - dst1 = (v8u16)__msa_ld_h((v8i16*)dst_ptr, 16); - dst0 += (v8u16)__msa_ilvr_b(zero, (v16i8)src0); - dst1 += (v8u16)__msa_ilvl_b(zero, (v16i8)src0); - ST_UH2(dst0, dst1, dst_ptr, 8); - src_ptr += 16; - dst_ptr += 16; - } -} - -void ScaleFilterCols_MSA(uint8_t* dst_ptr, - const uint8_t* src_ptr, - int dst_width, - int x, - int dx) { - int j; - v4i32 vec_x = __msa_fill_w(x); - v4i32 vec_dx = __msa_fill_w(dx); - v4i32 vec_const = {0, 1, 2, 3}; - v4i32 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9; - v4i32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; - v8u16 reg0, reg1; - v16u8 dst0; - v4i32 const_0xFFFF = __msa_fill_w(0xFFFF); - v4i32 const_0x40 = __msa_fill_w(0x40); - - vec0 = vec_dx * vec_const; - vec1 = vec_dx * 4; - vec_x += vec0; - - for (j = 0; j < dst_width - 1; j += 16) { - vec2 = vec_x >> 16; - vec6 = vec_x & const_0xFFFF; - vec_x += vec1; - vec3 = vec_x >> 16; - vec7 = vec_x & const_0xFFFF; - vec_x += vec1; - vec4 = vec_x >> 16; - vec8 = vec_x & const_0xFFFF; - vec_x += vec1; - vec5 = vec_x >> 16; - vec9 = vec_x & const_0xFFFF; - vec_x += vec1; - vec6 >>= 9; - vec7 >>= 9; - vec8 >>= 9; - vec9 >>= 9; - LOAD_INDEXED_DATA(src_ptr, vec2, tmp0); - LOAD_INDEXED_DATA(src_ptr, vec3, tmp1); - LOAD_INDEXED_DATA(src_ptr, vec4, tmp2); - LOAD_INDEXED_DATA(src_ptr, vec5, tmp3); - vec2 += 1; - vec3 += 1; - vec4 += 1; - vec5 += 1; - LOAD_INDEXED_DATA(src_ptr, vec2, tmp4); - LOAD_INDEXED_DATA(src_ptr, vec3, tmp5); - LOAD_INDEXED_DATA(src_ptr, vec4, tmp6); - LOAD_INDEXED_DATA(src_ptr, vec5, tmp7); - tmp4 -= tmp0; - tmp5 -= tmp1; - tmp6 -= tmp2; - tmp7 -= tmp3; - tmp4 *= vec6; - tmp5 *= vec7; - tmp6 *= vec8; - tmp7 *= vec9; - tmp4 += const_0x40; - tmp5 += const_0x40; - tmp6 += const_0x40; - tmp7 += const_0x40; - tmp4 >>= 7; - tmp5 >>= 7; - tmp6 >>= 7; - tmp7 >>= 7; - tmp0 += tmp4; - tmp1 += tmp5; - tmp2 += tmp6; - tmp3 += tmp7; - reg0 = (v8u16)__msa_pckev_h((v8i16)tmp1, (v8i16)tmp0); - reg1 = (v8u16)__msa_pckev_h((v8i16)tmp3, (v8i16)tmp2); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg1, (v16i8)reg0); - __msa_st_b(dst0, dst_ptr, 0); - dst_ptr += 16; - } -} - -void ScaleARGBCols_MSA(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx) { - const uint32_t* src = (const uint32_t*)(src_argb); - uint32_t* dst = (uint32_t*)(dst_argb); - int j; - v4i32 x_vec = __msa_fill_w(x); - v4i32 dx_vec = __msa_fill_w(dx); - v4i32 const_vec = {0, 1, 2, 3}; - v4i32 vec0, vec1, vec2; - v4i32 dst0; - - vec0 = dx_vec * const_vec; - vec1 = dx_vec * 4; - x_vec += vec0; - - for (j = 0; j < dst_width; j += 4) { - vec2 = x_vec >> 16; - x_vec += vec1; - LOAD_INDEXED_DATA(src, vec2, dst0); - __msa_st_w(dst0, dst, 0); - dst += 4; - } -} - -void ScaleARGBFilterCols_MSA(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx) { - const uint32_t* src = (const uint32_t*)(src_argb); - int j; - v4u32 src0, src1, src2, src3; - v4u32 vec0, vec1, vec2, vec3; - v16u8 reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7; - v16u8 mult0, mult1, mult2, mult3; - v8u16 tmp0, tmp1, tmp2, tmp3; - v16u8 dst0, dst1; - v4u32 vec_x = (v4u32)__msa_fill_w(x); - v4u32 vec_dx = (v4u32)__msa_fill_w(dx); - v4u32 vec_const = {0, 1, 2, 3}; - v16u8 const_0x7f = (v16u8)__msa_fill_b(0x7f); - - vec0 = vec_dx * vec_const; - vec1 = vec_dx * 4; - vec_x += vec0; - - for (j = 0; j < dst_width - 1; j += 8) { - vec2 = vec_x >> 16; - reg0 = (v16u8)(vec_x >> 9); - vec_x += vec1; - vec3 = vec_x >> 16; - reg1 = (v16u8)(vec_x >> 9); - vec_x += vec1; - reg0 = reg0 & const_0x7f; - reg1 = reg1 & const_0x7f; - reg0 = (v16u8)__msa_shf_b((v16i8)reg0, 0); - reg1 = (v16u8)__msa_shf_b((v16i8)reg1, 0); - reg2 = reg0 ^ const_0x7f; - reg3 = reg1 ^ const_0x7f; - mult0 = (v16u8)__msa_ilvr_b((v16i8)reg0, (v16i8)reg2); - mult1 = (v16u8)__msa_ilvl_b((v16i8)reg0, (v16i8)reg2); - mult2 = (v16u8)__msa_ilvr_b((v16i8)reg1, (v16i8)reg3); - mult3 = (v16u8)__msa_ilvl_b((v16i8)reg1, (v16i8)reg3); - LOAD_INDEXED_DATA(src, vec2, src0); - LOAD_INDEXED_DATA(src, vec3, src1); - vec2 += 1; - vec3 += 1; - LOAD_INDEXED_DATA(src, vec2, src2); - LOAD_INDEXED_DATA(src, vec3, src3); - reg4 = (v16u8)__msa_ilvr_b((v16i8)src2, (v16i8)src0); - reg5 = (v16u8)__msa_ilvl_b((v16i8)src2, (v16i8)src0); - reg6 = (v16u8)__msa_ilvr_b((v16i8)src3, (v16i8)src1); - reg7 = (v16u8)__msa_ilvl_b((v16i8)src3, (v16i8)src1); - tmp0 = __msa_dotp_u_h(reg4, mult0); - tmp1 = __msa_dotp_u_h(reg5, mult1); - tmp2 = __msa_dotp_u_h(reg6, mult2); - tmp3 = __msa_dotp_u_h(reg7, mult3); - tmp0 >>= 7; - tmp1 >>= 7; - tmp2 >>= 7; - tmp3 >>= 7; - dst0 = (v16u8)__msa_pckev_b((v16i8)tmp1, (v16i8)tmp0); - dst1 = (v16u8)__msa_pckev_b((v16i8)tmp3, (v16i8)tmp2); - __msa_st_b(dst0, dst_argb, 0); - __msa_st_b(dst1, dst_argb, 16); - dst_argb += 32; - } -} - -void ScaleRowDown34_MSA(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst, - int dst_width) { - int x; - (void)src_stride; - v16u8 src0, src1, src2, src3; - v16u8 vec0, vec1, vec2; - v16i8 mask0 = {0, 1, 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, 19, 20}; - v16i8 mask1 = {5, 7, 8, 9, 11, 12, 13, 15, 16, 17, 19, 20, 21, 23, 24, 25}; - v16i8 mask2 = {11, 12, 13, 15, 16, 17, 19, 20, - 21, 23, 24, 25, 27, 28, 29, 31}; - - assert((dst_width % 3 == 0) && (dst_width > 0)); - - for (x = 0; x < dst_width; x += 48) { - src0 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 32); - src3 = (v16u8)__msa_ld_b((v16i8*)src_ptr, 48); - vec0 = (v16u8)__msa_vshf_b(mask0, (v16i8)src1, (v16i8)src0); - vec1 = (v16u8)__msa_vshf_b(mask1, (v16i8)src2, (v16i8)src1); - vec2 = (v16u8)__msa_vshf_b(mask2, (v16i8)src3, (v16i8)src2); - __msa_st_b((v16i8)vec0, dst, 0); - __msa_st_b((v16i8)vec1, dst, 16); - __msa_st_b((v16i8)vec2, dst, 32); - src_ptr += 64; - dst += 48; - } -} - -void ScaleRowDown34_0_Box_MSA(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* d, - int dst_width) { - const uint8_t* s = src_ptr; - const uint8_t* t = src_ptr + src_stride; - int x; - v16u8 src0, src1, src2, src3, src4, src5, src6, src7, dst0, dst1, dst2; - v16u8 vec0, vec1, vec2, vec3, vec4, vec5; - v16u8 vec6, vec7, vec8, vec9, vec10, vec11; - v8i16 reg0, reg1, reg2, reg3, reg4, reg5; - v8i16 reg6, reg7, reg8, reg9, reg10, reg11; - v16u8 const0 = {3, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 3, 3, 1, 1, 1}; - v16u8 const1 = {1, 3, 3, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 3, 3, 1}; - v16u8 const2 = {1, 1, 1, 3, 3, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 3}; - v16i8 mask0 = {0, 1, 1, 2, 2, 3, 4, 5, 5, 6, 6, 7, 8, 9, 9, 10}; - v16i8 mask1 = {10, 11, 12, 13, 13, 14, 14, 15, - 16, 17, 17, 18, 18, 19, 20, 21}; - v16i8 mask2 = {5, 6, 6, 7, 8, 9, 9, 10, 10, 11, 12, 13, 13, 14, 14, 15}; - v8i16 shft0 = {2, 1, 2, 2, 1, 2, 2, 1}; - v8i16 shft1 = {2, 2, 1, 2, 2, 1, 2, 2}; - v8i16 shft2 = {1, 2, 2, 1, 2, 2, 1, 2}; - - assert((dst_width % 3 == 0) && (dst_width > 0)); - - for (x = 0; x < dst_width; x += 48) { - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)s, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)s, 32); - src3 = (v16u8)__msa_ld_b((v16i8*)s, 48); - src4 = (v16u8)__msa_ld_b((v16i8*)t, 0); - src5 = (v16u8)__msa_ld_b((v16i8*)t, 16); - src6 = (v16u8)__msa_ld_b((v16i8*)t, 32); - src7 = (v16u8)__msa_ld_b((v16i8*)t, 48); - vec0 = (v16u8)__msa_vshf_b(mask0, (v16i8)src0, (v16i8)src0); - vec1 = (v16u8)__msa_vshf_b(mask1, (v16i8)src1, (v16i8)src0); - vec2 = (v16u8)__msa_vshf_b(mask2, (v16i8)src1, (v16i8)src1); - vec3 = (v16u8)__msa_vshf_b(mask0, (v16i8)src2, (v16i8)src2); - vec4 = (v16u8)__msa_vshf_b(mask1, (v16i8)src3, (v16i8)src2); - vec5 = (v16u8)__msa_vshf_b(mask2, (v16i8)src3, (v16i8)src3); - vec6 = (v16u8)__msa_vshf_b(mask0, (v16i8)src4, (v16i8)src4); - vec7 = (v16u8)__msa_vshf_b(mask1, (v16i8)src5, (v16i8)src4); - vec8 = (v16u8)__msa_vshf_b(mask2, (v16i8)src5, (v16i8)src5); - vec9 = (v16u8)__msa_vshf_b(mask0, (v16i8)src6, (v16i8)src6); - vec10 = (v16u8)__msa_vshf_b(mask1, (v16i8)src7, (v16i8)src6); - vec11 = (v16u8)__msa_vshf_b(mask2, (v16i8)src7, (v16i8)src7); - reg0 = (v8i16)__msa_dotp_u_h(vec0, const0); - reg1 = (v8i16)__msa_dotp_u_h(vec1, const1); - reg2 = (v8i16)__msa_dotp_u_h(vec2, const2); - reg3 = (v8i16)__msa_dotp_u_h(vec3, const0); - reg4 = (v8i16)__msa_dotp_u_h(vec4, const1); - reg5 = (v8i16)__msa_dotp_u_h(vec5, const2); - reg6 = (v8i16)__msa_dotp_u_h(vec6, const0); - reg7 = (v8i16)__msa_dotp_u_h(vec7, const1); - reg8 = (v8i16)__msa_dotp_u_h(vec8, const2); - reg9 = (v8i16)__msa_dotp_u_h(vec9, const0); - reg10 = (v8i16)__msa_dotp_u_h(vec10, const1); - reg11 = (v8i16)__msa_dotp_u_h(vec11, const2); - reg0 = __msa_srar_h(reg0, shft0); - reg1 = __msa_srar_h(reg1, shft1); - reg2 = __msa_srar_h(reg2, shft2); - reg3 = __msa_srar_h(reg3, shft0); - reg4 = __msa_srar_h(reg4, shft1); - reg5 = __msa_srar_h(reg5, shft2); - reg6 = __msa_srar_h(reg6, shft0); - reg7 = __msa_srar_h(reg7, shft1); - reg8 = __msa_srar_h(reg8, shft2); - reg9 = __msa_srar_h(reg9, shft0); - reg10 = __msa_srar_h(reg10, shft1); - reg11 = __msa_srar_h(reg11, shft2); - reg0 = reg0 * 3 + reg6; - reg1 = reg1 * 3 + reg7; - reg2 = reg2 * 3 + reg8; - reg3 = reg3 * 3 + reg9; - reg4 = reg4 * 3 + reg10; - reg5 = reg5 * 3 + reg11; - reg0 = __msa_srari_h(reg0, 2); - reg1 = __msa_srari_h(reg1, 2); - reg2 = __msa_srari_h(reg2, 2); - reg3 = __msa_srari_h(reg3, 2); - reg4 = __msa_srari_h(reg4, 2); - reg5 = __msa_srari_h(reg5, 2); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg1, (v16i8)reg0); - dst1 = (v16u8)__msa_pckev_b((v16i8)reg3, (v16i8)reg2); - dst2 = (v16u8)__msa_pckev_b((v16i8)reg5, (v16i8)reg4); - __msa_st_b((v16i8)dst0, d, 0); - __msa_st_b((v16i8)dst1, d, 16); - __msa_st_b((v16i8)dst2, d, 32); - s += 64; - t += 64; - d += 48; - } -} - -void ScaleRowDown34_1_Box_MSA(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* d, - int dst_width) { - const uint8_t* s = src_ptr; - const uint8_t* t = src_ptr + src_stride; - int x; - v16u8 src0, src1, src2, src3, src4, src5, src6, src7, dst0, dst1, dst2; - v16u8 vec0, vec1, vec2, vec3, vec4, vec5; - v16u8 vec6, vec7, vec8, vec9, vec10, vec11; - v8i16 reg0, reg1, reg2, reg3, reg4, reg5; - v8i16 reg6, reg7, reg8, reg9, reg10, reg11; - v16u8 const0 = {3, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 3, 3, 1, 1, 1}; - v16u8 const1 = {1, 3, 3, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 3, 3, 1}; - v16u8 const2 = {1, 1, 1, 3, 3, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 3}; - v16i8 mask0 = {0, 1, 1, 2, 2, 3, 4, 5, 5, 6, 6, 7, 8, 9, 9, 10}; - v16i8 mask1 = {10, 11, 12, 13, 13, 14, 14, 15, - 16, 17, 17, 18, 18, 19, 20, 21}; - v16i8 mask2 = {5, 6, 6, 7, 8, 9, 9, 10, 10, 11, 12, 13, 13, 14, 14, 15}; - v8i16 shft0 = {2, 1, 2, 2, 1, 2, 2, 1}; - v8i16 shft1 = {2, 2, 1, 2, 2, 1, 2, 2}; - v8i16 shft2 = {1, 2, 2, 1, 2, 2, 1, 2}; - - assert((dst_width % 3 == 0) && (dst_width > 0)); - - for (x = 0; x < dst_width; x += 48) { - src0 = (v16u8)__msa_ld_b((v16i8*)s, 0); - src1 = (v16u8)__msa_ld_b((v16i8*)s, 16); - src2 = (v16u8)__msa_ld_b((v16i8*)s, 32); - src3 = (v16u8)__msa_ld_b((v16i8*)s, 48); - src4 = (v16u8)__msa_ld_b((v16i8*)t, 0); - src5 = (v16u8)__msa_ld_b((v16i8*)t, 16); - src6 = (v16u8)__msa_ld_b((v16i8*)t, 32); - src7 = (v16u8)__msa_ld_b((v16i8*)t, 48); - vec0 = (v16u8)__msa_vshf_b(mask0, (v16i8)src0, (v16i8)src0); - vec1 = (v16u8)__msa_vshf_b(mask1, (v16i8)src1, (v16i8)src0); - vec2 = (v16u8)__msa_vshf_b(mask2, (v16i8)src1, (v16i8)src1); - vec3 = (v16u8)__msa_vshf_b(mask0, (v16i8)src2, (v16i8)src2); - vec4 = (v16u8)__msa_vshf_b(mask1, (v16i8)src3, (v16i8)src2); - vec5 = (v16u8)__msa_vshf_b(mask2, (v16i8)src3, (v16i8)src3); - vec6 = (v16u8)__msa_vshf_b(mask0, (v16i8)src4, (v16i8)src4); - vec7 = (v16u8)__msa_vshf_b(mask1, (v16i8)src5, (v16i8)src4); - vec8 = (v16u8)__msa_vshf_b(mask2, (v16i8)src5, (v16i8)src5); - vec9 = (v16u8)__msa_vshf_b(mask0, (v16i8)src6, (v16i8)src6); - vec10 = (v16u8)__msa_vshf_b(mask1, (v16i8)src7, (v16i8)src6); - vec11 = (v16u8)__msa_vshf_b(mask2, (v16i8)src7, (v16i8)src7); - reg0 = (v8i16)__msa_dotp_u_h(vec0, const0); - reg1 = (v8i16)__msa_dotp_u_h(vec1, const1); - reg2 = (v8i16)__msa_dotp_u_h(vec2, const2); - reg3 = (v8i16)__msa_dotp_u_h(vec3, const0); - reg4 = (v8i16)__msa_dotp_u_h(vec4, const1); - reg5 = (v8i16)__msa_dotp_u_h(vec5, const2); - reg6 = (v8i16)__msa_dotp_u_h(vec6, const0); - reg7 = (v8i16)__msa_dotp_u_h(vec7, const1); - reg8 = (v8i16)__msa_dotp_u_h(vec8, const2); - reg9 = (v8i16)__msa_dotp_u_h(vec9, const0); - reg10 = (v8i16)__msa_dotp_u_h(vec10, const1); - reg11 = (v8i16)__msa_dotp_u_h(vec11, const2); - reg0 = __msa_srar_h(reg0, shft0); - reg1 = __msa_srar_h(reg1, shft1); - reg2 = __msa_srar_h(reg2, shft2); - reg3 = __msa_srar_h(reg3, shft0); - reg4 = __msa_srar_h(reg4, shft1); - reg5 = __msa_srar_h(reg5, shft2); - reg6 = __msa_srar_h(reg6, shft0); - reg7 = __msa_srar_h(reg7, shft1); - reg8 = __msa_srar_h(reg8, shft2); - reg9 = __msa_srar_h(reg9, shft0); - reg10 = __msa_srar_h(reg10, shft1); - reg11 = __msa_srar_h(reg11, shft2); - reg0 += reg6; - reg1 += reg7; - reg2 += reg8; - reg3 += reg9; - reg4 += reg10; - reg5 += reg11; - reg0 = __msa_srari_h(reg0, 1); - reg1 = __msa_srari_h(reg1, 1); - reg2 = __msa_srari_h(reg2, 1); - reg3 = __msa_srari_h(reg3, 1); - reg4 = __msa_srari_h(reg4, 1); - reg5 = __msa_srari_h(reg5, 1); - dst0 = (v16u8)__msa_pckev_b((v16i8)reg1, (v16i8)reg0); - dst1 = (v16u8)__msa_pckev_b((v16i8)reg3, (v16i8)reg2); - dst2 = (v16u8)__msa_pckev_b((v16i8)reg5, (v16i8)reg4); - __msa_st_b((v16i8)dst0, d, 0); - __msa_st_b((v16i8)dst1, d, 16); - __msa_st_b((v16i8)dst2, d, 32); - s += 64; - t += 64; - d += 48; - } -} - -#ifdef __cplusplus -} // extern "C" -} // namespace libyuv -#endif - -#endif // !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) diff --git a/libs/libyuv/source/scale_neon.cc b/libs/libyuv/source/scale_neon.cc index 366b155ba4..2d5be0af37 100644 --- a/libs/libyuv/source/scale_neon.cc +++ b/libs/libyuv/source/scale_neon.cc @@ -9,12 +9,20 @@ */ #include "libyuv/row.h" +#include "libyuv/scale_row.h" #ifdef __cplusplus namespace libyuv { extern "C" { #endif +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + // This module is for GCC Neon. #if !defined(LIBYUV_DISABLE_NEON) && defined(__ARM_NEON__) && \ !defined(__aarch64__) @@ -29,17 +37,17 @@ void ScaleRowDown2_NEON(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "1: \n" + "1: \n" // load even pixels into q0, odd into q1 - "vld2.8 {q0, q1}, [%0]! \n" - "subs %2, %2, #16 \n" // 16 processed per loop - "vst1.8 {q1}, [%1]! \n" // store odd pixels - "bgt 1b \n" + "vld2.8 {q0, q1}, [%0]! \n" + "subs %2, %2, #16 \n" // 16 processed per loop + "vst1.8 {q1}, [%1]! \n" // store odd pixels + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst), // %1 "+r"(dst_width) // %2 : - : "q0", "q1" // Clobber List + : "memory", "cc", "q0", "q1" // Clobber List ); } @@ -50,17 +58,17 @@ void ScaleRowDown2Linear_NEON(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "1: \n" - "vld2.8 {q0, q1}, [%0]! \n" // load 32 pixels - "subs %2, %2, #16 \n" // 16 processed per loop - "vrhadd.u8 q0, q0, q1 \n" // rounding half add - "vst1.8 {q0}, [%1]! \n" - "bgt 1b \n" + "1: \n" + "vld2.8 {q0, q1}, [%0]! \n" // load 32 pixels + "subs %2, %2, #16 \n" // 16 processed per loop + "vrhadd.u8 q0, q0, q1 \n" // rounding half add + "vst1.8 {q0}, [%1]! \n" + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst), // %1 "+r"(dst_width) // %2 : - : "q0", "q1" // Clobber List + : "memory", "cc", "q0", "q1" // Clobber List ); } @@ -71,27 +79,27 @@ void ScaleRowDown2Box_NEON(const uint8_t* src_ptr, int dst_width) { asm volatile( // change the stride to row 2 pointer - "add %1, %0 \n" - "1: \n" - "vld1.8 {q0, q1}, [%0]! \n" // load row 1 and post inc - "vld1.8 {q2, q3}, [%1]! \n" // load row 2 and post inc - "subs %3, %3, #16 \n" // 16 processed per loop - "vpaddl.u8 q0, q0 \n" // row 1 add adjacent - "vpaddl.u8 q1, q1 \n" - "vpadal.u8 q0, q2 \n" // row 2 add adjacent + + "add %1, %0 \n" + "1: \n" + "vld1.8 {q0, q1}, [%0]! \n" // load row 1 and post inc + "vld1.8 {q2, q3}, [%1]! \n" // load row 2 and post inc + "subs %3, %3, #16 \n" // 16 processed per loop + "vpaddl.u8 q0, q0 \n" // row 1 add adjacent + "vpaddl.u8 q1, q1 \n" + "vpadal.u8 q0, q2 \n" // row 2 add adjacent + // row1 - "vpadal.u8 q1, q3 \n" - "vrshrn.u16 d0, q0, #2 \n" // downshift, round and + "vpadal.u8 q1, q3 \n" + "vrshrn.u16 d0, q0, #2 \n" // downshift, round and // pack - "vrshrn.u16 d1, q1, #2 \n" - "vst1.8 {q0}, [%2]! \n" - "bgt 1b \n" + "vrshrn.u16 d1, q1, #2 \n" + "vst1.8 {q0}, [%2]! \n" + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(src_stride), // %1 "+r"(dst), // %2 "+r"(dst_width) // %3 : - : "q0", "q1", "q2", "q3" // Clobber List + : "memory", "cc", "q0", "q1", "q2", "q3" // Clobber List ); } @@ -101,11 +109,11 @@ void ScaleRowDown4_NEON(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // src line 0 - "subs %2, %2, #8 \n" // 8 processed per loop - "vst1.8 {d2}, [%1]! \n" - "bgt 1b \n" + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // src line 0 + "subs %2, %2, #8 \n" // 8 processed per loop + "vst1.8 {d2}, [%1]! \n" + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width) // %2 @@ -121,21 +129,21 @@ void ScaleRowDown4Box_NEON(const uint8_t* src_ptr, const uint8_t* src_ptr2 = src_ptr + src_stride * 2; const uint8_t* src_ptr3 = src_ptr + src_stride * 3; asm volatile( - "1: \n" - "vld1.8 {q0}, [%0]! \n" // load up 16x4 - "vld1.8 {q1}, [%3]! \n" - "vld1.8 {q2}, [%4]! \n" - "vld1.8 {q3}, [%5]! \n" - "subs %2, %2, #4 \n" - "vpaddl.u8 q0, q0 \n" - "vpadal.u8 q0, q1 \n" - "vpadal.u8 q0, q2 \n" - "vpadal.u8 q0, q3 \n" - "vpaddl.u16 q0, q0 \n" - "vrshrn.u32 d0, q0, #4 \n" // divide by 16 w/rounding - "vmovn.u16 d0, q0 \n" - "vst1.32 {d0[0]}, [%1]! \n" - "bgt 1b \n" + "1: \n" + "vld1.8 {q0}, [%0]! \n" // load up 16x4 + "vld1.8 {q1}, [%3]! \n" + "vld1.8 {q2}, [%4]! \n" + "vld1.8 {q3}, [%5]! \n" + "subs %2, %2, #4 \n" + "vpaddl.u8 q0, q0 \n" + "vpadal.u8 q0, q1 \n" + "vpadal.u8 q0, q2 \n" + "vpadal.u8 q0, q3 \n" + "vpaddl.u16 q0, q0 \n" + "vrshrn.u32 d0, q0, #4 \n" // divide by 16 w/rounding + "vmovn.u16 d0, q0 \n" + "vst1.32 {d0[0]}, [%1]! \n" + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width), // %2 @@ -155,12 +163,12 @@ void ScaleRowDown34_NEON(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // src line 0 - "subs %2, %2, #24 \n" - "vmov d2, d3 \n" // order d0, d1, d2 - "vst3.8 {d0, d1, d2}, [%1]! \n" - "bgt 1b \n" + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // src line 0 + "subs %2, %2, #24 \n" + "vmov d2, d3 \n" // order d0, d1, d2 + "vst3.8 {d0, d1, d2}, [%1]! \n" + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width) // %2 @@ -173,49 +181,49 @@ void ScaleRowDown34_0_Box_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) { asm volatile( - "vmov.u8 d24, #3 \n" - "add %3, %0 \n" - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // src line 0 - "vld4.8 {d4, d5, d6, d7}, [%3]! \n" // src line 1 - "subs %2, %2, #24 \n" + "vmov.u8 d24, #3 \n" + "add %3, %0 \n" + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // src line 0 + "vld4.8 {d4, d5, d6, d7}, [%3]! \n" // src line 1 + "subs %2, %2, #24 \n" // filter src line 0 with src line 1 // expand chars to shorts to allow for room // when adding lines together - "vmovl.u8 q8, d4 \n" - "vmovl.u8 q9, d5 \n" - "vmovl.u8 q10, d6 \n" - "vmovl.u8 q11, d7 \n" + "vmovl.u8 q8, d4 \n" + "vmovl.u8 q9, d5 \n" + "vmovl.u8 q10, d6 \n" + "vmovl.u8 q11, d7 \n" // 3 * line_0 + line_1 - "vmlal.u8 q8, d0, d24 \n" - "vmlal.u8 q9, d1, d24 \n" - "vmlal.u8 q10, d2, d24 \n" - "vmlal.u8 q11, d3, d24 \n" + "vmlal.u8 q8, d0, d24 \n" + "vmlal.u8 q9, d1, d24 \n" + "vmlal.u8 q10, d2, d24 \n" + "vmlal.u8 q11, d3, d24 \n" - // (3 * line_0 + line_1) >> 2 - "vqrshrn.u16 d0, q8, #2 \n" - "vqrshrn.u16 d1, q9, #2 \n" - "vqrshrn.u16 d2, q10, #2 \n" - "vqrshrn.u16 d3, q11, #2 \n" + // (3 * line_0 + line_1 + 2) >> 2 + "vqrshrn.u16 d0, q8, #2 \n" + "vqrshrn.u16 d1, q9, #2 \n" + "vqrshrn.u16 d2, q10, #2 \n" + "vqrshrn.u16 d3, q11, #2 \n" - // a0 = (src[0] * 3 + s[1] * 1) >> 2 - "vmovl.u8 q8, d1 \n" - "vmlal.u8 q8, d0, d24 \n" - "vqrshrn.u16 d0, q8, #2 \n" + // a0 = (src[0] * 3 + s[1] * 1 + 2) >> 2 + "vmovl.u8 q8, d1 \n" + "vmlal.u8 q8, d0, d24 \n" + "vqrshrn.u16 d0, q8, #2 \n" - // a1 = (src[1] * 1 + s[2] * 1) >> 1 - "vrhadd.u8 d1, d1, d2 \n" + // a1 = (src[1] * 1 + s[2] * 1 + 1) >> 1 + "vrhadd.u8 d1, d1, d2 \n" - // a2 = (src[2] * 1 + s[3] * 3) >> 2 - "vmovl.u8 q8, d2 \n" - "vmlal.u8 q8, d3, d24 \n" - "vqrshrn.u16 d2, q8, #2 \n" + // a2 = (src[2] * 1 + s[3] * 3 + 2) >> 2 + "vmovl.u8 q8, d2 \n" + "vmlal.u8 q8, d3, d24 \n" + "vqrshrn.u16 d2, q8, #2 \n" - "vst3.8 {d0, d1, d2}, [%1]! \n" + "vst3.8 {d0, d1, d2}, [%1]! \n" - "bgt 1b \n" + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width), // %2 @@ -230,31 +238,31 @@ void ScaleRowDown34_1_Box_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) { asm volatile( - "vmov.u8 d24, #3 \n" - "add %3, %0 \n" - "1: \n" - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // src line 0 - "vld4.8 {d4, d5, d6, d7}, [%3]! \n" // src line 1 - "subs %2, %2, #24 \n" + "vmov.u8 d24, #3 \n" + "add %3, %0 \n" + "1: \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" // src line 0 + "vld4.8 {d4, d5, d6, d7}, [%3]! \n" // src line 1 + "subs %2, %2, #24 \n" // average src line 0 with src line 1 - "vrhadd.u8 q0, q0, q2 \n" - "vrhadd.u8 q1, q1, q3 \n" + "vrhadd.u8 q0, q0, q2 \n" + "vrhadd.u8 q1, q1, q3 \n" - // a0 = (src[0] * 3 + s[1] * 1) >> 2 - "vmovl.u8 q3, d1 \n" - "vmlal.u8 q3, d0, d24 \n" - "vqrshrn.u16 d0, q3, #2 \n" + // a0 = (src[0] * 3 + s[1] * 1 + 2) >> 2 + "vmovl.u8 q3, d1 \n" + "vmlal.u8 q3, d0, d24 \n" + "vqrshrn.u16 d0, q3, #2 \n" - // a1 = (src[1] * 1 + s[2] * 1) >> 1 - "vrhadd.u8 d1, d1, d2 \n" + // a1 = (src[1] * 1 + s[2] * 1 + 1) >> 1 + "vrhadd.u8 d1, d1, d2 \n" - // a2 = (src[2] * 1 + s[3] * 3) >> 2 - "vmovl.u8 q3, d2 \n" - "vmlal.u8 q3, d3, d24 \n" - "vqrshrn.u16 d2, q3, #2 \n" + // a2 = (src[2] * 1 + s[3] * 3 + 2) >> 2 + "vmovl.u8 q3, d2 \n" + "vmlal.u8 q3, d3, d24 \n" + "vqrshrn.u16 d2, q3, #2 \n" - "vst3.8 {d0, d1, d2}, [%1]! \n" - "bgt 1b \n" + "vst3.8 {d0, d1, d2}, [%1]! \n" + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width), // %2 @@ -282,20 +290,20 @@ void ScaleRowDown38_NEON(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "vld1.8 {q3}, [%3] \n" - "1: \n" - "vld1.8 {d0, d1, d2, d3}, [%0]! \n" - "subs %2, %2, #12 \n" - "vtbl.u8 d4, {d0, d1, d2, d3}, d6 \n" - "vtbl.u8 d5, {d0, d1, d2, d3}, d7 \n" - "vst1.8 {d4}, [%1]! \n" - "vst1.32 {d5[0]}, [%1]! \n" - "bgt 1b \n" + "vld1.8 {q3}, [%3] \n" + "1: \n" + "vld1.8 {d0, d1, d2, d3}, [%0]! \n" + "subs %2, %2, #12 \n" + "vtbl.u8 d4, {d0, d1, d2, d3}, d6 \n" + "vtbl.u8 d5, {d0, d1, d2, d3}, d7 \n" + "vst1.8 {d4}, [%1]! \n" + "vst1.32 {d5[0]}, [%1]! \n" + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width) // %2 : "r"(&kShuf38) // %3 - : "d0", "d1", "d2", "d3", "d4", "d5", "memory", "cc"); + : "memory", "cc", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7"); } // 32x3 -> 12x1 @@ -306,57 +314,57 @@ void OMITFP ScaleRowDown38_3_Box_NEON(const uint8_t* src_ptr, const uint8_t* src_ptr1 = src_ptr + src_stride * 2; asm volatile( - "vld1.16 {q13}, [%5] \n" - "vld1.8 {q14}, [%6] \n" - "vld1.8 {q15}, [%7] \n" - "add %3, %0 \n" - "1: \n" + "vld1.16 {q13}, [%5] \n" + "vld1.8 {q14}, [%6] \n" + "vld1.8 {q15}, [%7] \n" + "add %3, %0 \n" + "1: \n" // d0 = 00 40 01 41 02 42 03 43 // d1 = 10 50 11 51 12 52 13 53 // d2 = 20 60 21 61 22 62 23 63 // d3 = 30 70 31 71 32 72 33 73 - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" - "vld4.8 {d4, d5, d6, d7}, [%3]! \n" - "vld4.8 {d16, d17, d18, d19}, [%4]! \n" - "subs %2, %2, #12 \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" + "vld4.8 {d4, d5, d6, d7}, [%3]! \n" + "vld4.8 {d16, d17, d18, d19}, [%4]! \n" + "subs %2, %2, #12 \n" // Shuffle the input data around to get align the data // so adjacent data can be added. 0,1 - 2,3 - 4,5 - 6,7 // d0 = 00 10 01 11 02 12 03 13 // d1 = 40 50 41 51 42 52 43 53 - "vtrn.u8 d0, d1 \n" - "vtrn.u8 d4, d5 \n" - "vtrn.u8 d16, d17 \n" + "vtrn.u8 d0, d1 \n" + "vtrn.u8 d4, d5 \n" + "vtrn.u8 d16, d17 \n" // d2 = 20 30 21 31 22 32 23 33 // d3 = 60 70 61 71 62 72 63 73 - "vtrn.u8 d2, d3 \n" - "vtrn.u8 d6, d7 \n" - "vtrn.u8 d18, d19 \n" + "vtrn.u8 d2, d3 \n" + "vtrn.u8 d6, d7 \n" + "vtrn.u8 d18, d19 \n" // d0 = 00+10 01+11 02+12 03+13 // d2 = 40+50 41+51 42+52 43+53 - "vpaddl.u8 q0, q0 \n" - "vpaddl.u8 q2, q2 \n" - "vpaddl.u8 q8, q8 \n" + "vpaddl.u8 q0, q0 \n" + "vpaddl.u8 q2, q2 \n" + "vpaddl.u8 q8, q8 \n" // d3 = 60+70 61+71 62+72 63+73 - "vpaddl.u8 d3, d3 \n" - "vpaddl.u8 d7, d7 \n" - "vpaddl.u8 d19, d19 \n" + "vpaddl.u8 d3, d3 \n" + "vpaddl.u8 d7, d7 \n" + "vpaddl.u8 d19, d19 \n" // combine source lines - "vadd.u16 q0, q2 \n" - "vadd.u16 q0, q8 \n" - "vadd.u16 d4, d3, d7 \n" - "vadd.u16 d4, d19 \n" + "vadd.u16 q0, q2 \n" + "vadd.u16 q0, q8 \n" + "vadd.u16 d4, d3, d7 \n" + "vadd.u16 d4, d19 \n" // dst_ptr[3] = (s[6 + st * 0] + s[7 + st * 0] // + s[6 + st * 1] + s[7 + st * 1] // + s[6 + st * 2] + s[7 + st * 2]) / 6 "vqrdmulh.s16 q2, q2, q13 \n" - "vmovn.u16 d4, q2 \n" + "vmovn.u16 d4, q2 \n" // Shuffle 2,3 reg around so that 2 can be added to the // 0,1 reg and 3 can be added to the 4,5 reg. This @@ -364,24 +372,24 @@ void OMITFP ScaleRowDown38_3_Box_NEON(const uint8_t* src_ptr, // registers are already expanded. Then do transposes // to get aligned. // q2 = xx 20 xx 30 xx 21 xx 31 xx 22 xx 32 xx 23 xx 33 - "vmovl.u8 q1, d2 \n" - "vmovl.u8 q3, d6 \n" - "vmovl.u8 q9, d18 \n" + "vmovl.u8 q1, d2 \n" + "vmovl.u8 q3, d6 \n" + "vmovl.u8 q9, d18 \n" // combine source lines - "vadd.u16 q1, q3 \n" - "vadd.u16 q1, q9 \n" + "vadd.u16 q1, q3 \n" + "vadd.u16 q1, q9 \n" // d4 = xx 20 xx 30 xx 22 xx 32 // d5 = xx 21 xx 31 xx 23 xx 33 - "vtrn.u32 d2, d3 \n" + "vtrn.u32 d2, d3 \n" // d4 = xx 20 xx 21 xx 22 xx 23 // d5 = xx 30 xx 31 xx 32 xx 33 - "vtrn.u16 d2, d3 \n" + "vtrn.u16 d2, d3 \n" // 0+1+2, 3+4+5 - "vadd.u16 q0, q1 \n" + "vadd.u16 q0, q1 \n" // Need to divide, but can't downshift as the the value // isn't a power of 2. So multiply by 65536 / n @@ -390,14 +398,14 @@ void OMITFP ScaleRowDown38_3_Box_NEON(const uint8_t* src_ptr, // Align for table lookup, vtbl requires registers to // be adjacent - "vmov.u8 d2, d4 \n" + "vmov.u8 d2, d4 \n" - "vtbl.u8 d3, {d0, d1, d2}, d28 \n" - "vtbl.u8 d4, {d0, d1, d2}, d29 \n" + "vtbl.u8 d3, {d0, d1, d2}, d28 \n" + "vtbl.u8 d4, {d0, d1, d2}, d29 \n" - "vst1.8 {d3}, [%1]! \n" - "vst1.32 {d4[0]}, [%1]! \n" - "bgt 1b \n" + "vst1.8 {d3}, [%1]! \n" + "vst1.32 {d4[0]}, [%1]! \n" + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width), // %2 @@ -416,46 +424,46 @@ void ScaleRowDown38_2_Box_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) { asm volatile( - "vld1.16 {q13}, [%4] \n" - "vld1.8 {q14}, [%5] \n" - "add %3, %0 \n" - "1: \n" + "vld1.16 {q13}, [%4] \n" + "vld1.8 {q14}, [%5] \n" + "add %3, %0 \n" + "1: \n" // d0 = 00 40 01 41 02 42 03 43 // d1 = 10 50 11 51 12 52 13 53 // d2 = 20 60 21 61 22 62 23 63 // d3 = 30 70 31 71 32 72 33 73 - "vld4.8 {d0, d1, d2, d3}, [%0]! \n" - "vld4.8 {d4, d5, d6, d7}, [%3]! \n" - "subs %2, %2, #12 \n" + "vld4.8 {d0, d1, d2, d3}, [%0]! \n" + "vld4.8 {d4, d5, d6, d7}, [%3]! \n" + "subs %2, %2, #12 \n" // Shuffle the input data around to get align the data // so adjacent data can be added. 0,1 - 2,3 - 4,5 - 6,7 // d0 = 00 10 01 11 02 12 03 13 // d1 = 40 50 41 51 42 52 43 53 - "vtrn.u8 d0, d1 \n" - "vtrn.u8 d4, d5 \n" + "vtrn.u8 d0, d1 \n" + "vtrn.u8 d4, d5 \n" // d2 = 20 30 21 31 22 32 23 33 // d3 = 60 70 61 71 62 72 63 73 - "vtrn.u8 d2, d3 \n" - "vtrn.u8 d6, d7 \n" + "vtrn.u8 d2, d3 \n" + "vtrn.u8 d6, d7 \n" // d0 = 00+10 01+11 02+12 03+13 // d2 = 40+50 41+51 42+52 43+53 - "vpaddl.u8 q0, q0 \n" - "vpaddl.u8 q2, q2 \n" + "vpaddl.u8 q0, q0 \n" + "vpaddl.u8 q2, q2 \n" // d3 = 60+70 61+71 62+72 63+73 - "vpaddl.u8 d3, d3 \n" - "vpaddl.u8 d7, d7 \n" + "vpaddl.u8 d3, d3 \n" + "vpaddl.u8 d7, d7 \n" // combine source lines - "vadd.u16 q0, q2 \n" - "vadd.u16 d4, d3, d7 \n" + "vadd.u16 q0, q2 \n" + "vadd.u16 d4, d3, d7 \n" // dst_ptr[3] = (s[6] + s[7] + s[6+st] + s[7+st]) / 4 - "vqrshrn.u16 d4, q2, #2 \n" + "vqrshrn.u16 d4, q2, #2 \n" // Shuffle 2,3 reg around so that 2 can be added to the // 0,1 reg and 3 can be added to the 4,5 reg. This @@ -463,22 +471,22 @@ void ScaleRowDown38_2_Box_NEON(const uint8_t* src_ptr, // registers are already expanded. Then do transposes // to get aligned. // q2 = xx 20 xx 30 xx 21 xx 31 xx 22 xx 32 xx 23 xx 33 - "vmovl.u8 q1, d2 \n" - "vmovl.u8 q3, d6 \n" + "vmovl.u8 q1, d2 \n" + "vmovl.u8 q3, d6 \n" // combine source lines - "vadd.u16 q1, q3 \n" + "vadd.u16 q1, q3 \n" // d4 = xx 20 xx 30 xx 22 xx 32 // d5 = xx 21 xx 31 xx 23 xx 33 - "vtrn.u32 d2, d3 \n" + "vtrn.u32 d2, d3 \n" // d4 = xx 20 xx 21 xx 22 xx 23 // d5 = xx 30 xx 31 xx 32 xx 33 - "vtrn.u16 d2, d3 \n" + "vtrn.u16 d2, d3 \n" // 0+1+2, 3+4+5 - "vadd.u16 q0, q1 \n" + "vadd.u16 q0, q1 \n" // Need to divide, but can't downshift as the the value // isn't a power of 2. So multiply by 65536 / n @@ -487,14 +495,14 @@ void ScaleRowDown38_2_Box_NEON(const uint8_t* src_ptr, // Align for table lookup, vtbl requires registers to // be adjacent - "vmov.u8 d2, d4 \n" + "vmov.u8 d2, d4 \n" - "vtbl.u8 d3, {d0, d1, d2}, d28 \n" - "vtbl.u8 d4, {d0, d1, d2}, d29 \n" + "vtbl.u8 d3, {d0, d1, d2}, d28 \n" + "vtbl.u8 d4, {d0, d1, d2}, d29 \n" - "vst1.8 {d3}, [%1]! \n" - "vst1.32 {d4[0]}, [%1]! \n" - "bgt 1b \n" + "vst1.8 {d3}, [%1]! \n" + "vst1.32 {d4[0]}, [%1]! \n" + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width), // %2 @@ -504,20 +512,498 @@ void ScaleRowDown38_2_Box_NEON(const uint8_t* src_ptr, : "q0", "q1", "q2", "q3", "q13", "q14", "memory", "cc"); } +void ScaleRowUp2_Linear_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* src_temp = src_ptr + 1; + asm volatile( + "vmov.u8 d30, #3 \n" + + "1: \n" + "vld1.8 {d4}, [%0]! \n" // 01234567 + "vld1.8 {d5}, [%3]! \n" // 12345678 + + "vmovl.u8 q0, d4 \n" // 01234567 (16b) + "vmovl.u8 q1, d5 \n" // 12345678 (16b) + "vmlal.u8 q0, d5, d30 \n" // 3*near+far (odd) + "vmlal.u8 q1, d4, d30 \n" // 3*near+far (even) + + "vrshrn.u16 d1, q0, #2 \n" // 3/4*near+1/4*far (odd) + "vrshrn.u16 d0, q1, #2 \n" // 3/4*near+1/4*far (even) + + "vst2.8 {d0, d1}, [%1]! \n" // store + "subs %2, %2, #16 \n" // 8 sample -> 16 sample + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width), // %2 + "+r"(src_temp) // %3 + : + : "memory", "cc", "q0", "q1", "q2", "q15" // Clobber List + ); +} + +void ScaleRowUp2_Bilinear_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint8_t* src_ptr1 = src_ptr + src_stride; + uint8_t* dst_ptr1 = dst_ptr + dst_stride; + const uint8_t* src_temp = src_ptr + 1; + const uint8_t* src_temp1 = src_ptr1 + 1; + + asm volatile( + "vmov.u16 q15, #3 \n" + "vmov.u8 d28, #3 \n" + + "1: \n" + "vld1.8 {d4}, [%0]! \n" // 01234567 + "vld1.8 {d5}, [%5]! \n" // 12345678 + + "vmovl.u8 q0, d4 \n" // 01234567 (16b) + "vmovl.u8 q1, d5 \n" // 12345678 (16b) + "vmlal.u8 q0, d5, d28 \n" // 3*near+far (1, odd) + "vmlal.u8 q1, d4, d28 \n" // 3*near+far (1, even) + + "vld1.8 {d8}, [%1]! \n" + "vld1.8 {d9}, [%6]! \n" + + "vmovl.u8 q2, d8 \n" + "vmovl.u8 q3, d9 \n" + "vmlal.u8 q2, d9, d28 \n" // 3*near+far (2, odd) + "vmlal.u8 q3, d8, d28 \n" // 3*near+far (2, even) + + // e o + // q1 q0 + // q3 q2 + + "vmovq q4, q2 \n" + "vmovq q5, q3 \n" + "vmla.u16 q4, q0, q15 \n" // 9 3 3 1 (1, odd) + "vmla.u16 q5, q1, q15 \n" // 9 3 3 1 (1, even) + "vmla.u16 q0, q2, q15 \n" // 9 3 3 1 (2, odd) + "vmla.u16 q1, q3, q15 \n" // 9 3 3 1 (2, even) + + // e o + // q5 q4 + // q1 q0 + + "vrshrn.u16 d2, q1, #4 \n" // 2, even + "vrshrn.u16 d3, q0, #4 \n" // 2, odd + "vrshrn.u16 d0, q5, #4 \n" // 1, even + "vrshrn.u16 d1, q4, #4 \n" // 1, odd + + "vst2.8 {d0, d1}, [%2]! \n" // store + "vst2.8 {d2, d3}, [%3]! \n" // store + "subs %4, %4, #16 \n" // 8 sample -> 16 sample + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_ptr1), // %1 + "+r"(dst_ptr), // %2 + "+r"(dst_ptr1), // %3 + "+r"(dst_width), // %4 + "+r"(src_temp), // %5 + "+r"(src_temp1) // %6 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "d28", + "q15" // Clobber List + ); +} + +void ScaleRowUp2_Linear_12_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + const uint16_t* src_temp = src_ptr + 1; + asm volatile( + "vmov.u16 q15, #3 \n" + + "1: \n" + "vld1.16 {q1}, [%0]! \n" // 01234567 (16b) + "vld1.16 {q0}, [%3]! \n" // 12345678 (16b) + + "vmovq q2, q0 \n" + "vmla.u16 q0, q1, q15 \n" // 3*near+far (odd) + "vmla.u16 q1, q2, q15 \n" // 3*near+far (even) + + "vrshr.u16 q0, q0, #2 \n" // 3/4*near+1/4*far (odd) + "vrshr.u16 q1, q1, #2 \n" // 3/4*near+1/4*far (even) + + "vst2.16 {d0, d1, d2, d3}, [%1]! \n" // store + "subs %2, %2, #16 \n" // 8 sample -> 16 sample + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width), // %2 + "+r"(src_temp) // %3 + : + : "memory", "cc", "q0", "q1", "q2", "q15" // Clobber List + ); +} + +void ScaleRowUp2_Bilinear_12_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint16_t* src_ptr1 = src_ptr + src_stride; + uint16_t* dst_ptr1 = dst_ptr + dst_stride; + const uint16_t* src_temp = src_ptr + 1; + const uint16_t* src_temp1 = src_ptr1 + 1; + + asm volatile( + "vmov.u16 q15, #3 \n" + + "1: \n" + "vld1.16 {q0}, [%0]! \n" // 01234567 (16b) + "vld1.16 {q1}, [%5]! \n" // 12345678 (16b) + + "vmovq q2, q0 \n" + "vmla.u16 q0, q1, q15 \n" // 3*near+far (odd) + "vmla.u16 q1, q2, q15 \n" // 3*near+far (even) + + "vld1.16 {q2}, [%1]! \n" // 01234567 (16b) + "vld1.16 {q3}, [%6]! \n" // 12345678 (16b) + + "vmovq q4, q2 \n" + "vmla.u16 q2, q3, q15 \n" // 3*near+far (odd) + "vmla.u16 q3, q4, q15 \n" // 3*near+far (even) + + "vmovq q4, q2 \n" + "vmovq q5, q3 \n" + "vmla.u16 q4, q0, q15 \n" // 9 3 3 1 (1, odd) + "vmla.u16 q5, q1, q15 \n" // 9 3 3 1 (1, even) + "vmla.u16 q0, q2, q15 \n" // 9 3 3 1 (2, odd) + "vmla.u16 q1, q3, q15 \n" // 9 3 3 1 (2, even) + + "vrshr.u16 q2, q1, #4 \n" // 2, even + "vrshr.u16 q3, q0, #4 \n" // 2, odd + "vrshr.u16 q0, q5, #4 \n" // 1, even + "vrshr.u16 q1, q4, #4 \n" // 1, odd + + "vst2.16 {d0, d1, d2, d3}, [%2]! \n" // store + "vst2.16 {d4, d5, d6, d7}, [%3]! \n" // store + "subs %4, %4, #16 \n" // 8 sample -> 16 sample + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_ptr1), // %1 + "+r"(dst_ptr), // %2 + "+r"(dst_ptr1), // %3 + "+r"(dst_width), // %4 + "+r"(src_temp), // %5 + "+r"(src_temp1) // %6 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", + "q15" // Clobber List + ); +} + +void ScaleRowUp2_Linear_16_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + const uint16_t* src_temp = src_ptr + 1; + asm volatile( + "vmov.u16 d31, #3 \n" + + "1: \n" + "vld1.16 {q0}, [%0]! \n" // 01234567 (16b) + "vld1.16 {q1}, [%3]! \n" // 12345678 (16b) + + "vmovl.u16 q2, d0 \n" // 0123 (32b) + "vmovl.u16 q3, d1 \n" // 4567 (32b) + "vmovl.u16 q4, d2 \n" // 1234 (32b) + "vmovl.u16 q5, d3 \n" // 5678 (32b) + + "vmlal.u16 q2, d2, d31 \n" + "vmlal.u16 q3, d3, d31 \n" + "vmlal.u16 q4, d0, d31 \n" + "vmlal.u16 q5, d1, d31 \n" + + "vrshrn.u32 d0, q4, #2 \n" + "vrshrn.u32 d1, q5, #2 \n" + "vrshrn.u32 d2, q2, #2 \n" + "vrshrn.u32 d3, q3, #2 \n" + + "vst2.16 {q0, q1}, [%1]! \n" // store + "subs %2, %2, #16 \n" // 8 sample -> 16 sample + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width), // %2 + "+r"(src_temp) // %3 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q15" // Clobber List + ); +} + +void ScaleRowUp2_Bilinear_16_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint16_t* src_ptr1 = src_ptr + src_stride; + uint16_t* dst_ptr1 = dst_ptr + dst_stride; + const uint16_t* src_temp = src_ptr + 1; + const uint16_t* src_temp1 = src_ptr1 + 1; + + asm volatile( + "vmov.u16 d31, #3 \n" + "vmov.u32 q14, #3 \n" + + "1: \n" + "vld1.16 {d0}, [%0]! \n" // 0123 (16b) + "vld1.16 {d1}, [%5]! \n" // 1234 (16b) + "vmovl.u16 q2, d0 \n" // 0123 (32b) + "vmovl.u16 q3, d1 \n" // 1234 (32b) + "vmlal.u16 q2, d1, d31 \n" + "vmlal.u16 q3, d0, d31 \n" + + "vld1.16 {d0}, [%1]! \n" // 0123 (16b) + "vld1.16 {d1}, [%6]! \n" // 1234 (16b) + "vmovl.u16 q4, d0 \n" // 0123 (32b) + "vmovl.u16 q5, d1 \n" // 1234 (32b) + "vmlal.u16 q4, d1, d31 \n" + "vmlal.u16 q5, d0, d31 \n" + + "vmovq q0, q4 \n" + "vmovq q1, q5 \n" + "vmla.u32 q4, q2, q14 \n" + "vmla.u32 q5, q3, q14 \n" + "vmla.u32 q2, q0, q14 \n" + "vmla.u32 q3, q1, q14 \n" + + "vrshrn.u32 d1, q4, #4 \n" + "vrshrn.u32 d0, q5, #4 \n" + "vrshrn.u32 d3, q2, #4 \n" + "vrshrn.u32 d2, q3, #4 \n" + + "vst2.16 {d0, d1}, [%2]! \n" // store + "vst2.16 {d2, d3}, [%3]! \n" // store + "subs %4, %4, #8 \n" // 4 sample -> 8 sample + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_ptr1), // %1 + "+r"(dst_ptr), // %2 + "+r"(dst_ptr1), // %3 + "+r"(dst_width), // %4 + "+r"(src_temp), // %5 + "+r"(src_temp1) // %6 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q14", + "d31" // Clobber List + ); +} + +void ScaleUVRowUp2_Linear_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* src_temp = src_ptr + 2; + asm volatile( + "vmov.u8 d30, #3 \n" + + "1: \n" + "vld1.8 {d4}, [%0]! \n" // 00112233 (1u1v) + "vld1.8 {d5}, [%3]! \n" // 11223344 (1u1v) + + "vmovl.u8 q0, d4 \n" // 00112233 (1u1v, 16b) + "vmovl.u8 q1, d5 \n" // 11223344 (1u1v, 16b) + "vmlal.u8 q0, d5, d30 \n" // 3*near+far (odd) + "vmlal.u8 q1, d4, d30 \n" // 3*near+far (even) + + "vrshrn.u16 d1, q0, #2 \n" // 3/4*near+1/4*far (odd) + "vrshrn.u16 d0, q1, #2 \n" // 3/4*near+1/4*far (even) + + "vst2.16 {d0, d1}, [%1]! \n" // store + "subs %2, %2, #8 \n" // 4 uv -> 8 uv + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width), // %2 + "+r"(src_temp) // %3 + : + : "memory", "cc", "q0", "q1", "q2", "d30" // Clobber List + ); +} + +void ScaleUVRowUp2_Bilinear_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint8_t* src_ptr1 = src_ptr + src_stride; + uint8_t* dst_ptr1 = dst_ptr + dst_stride; + const uint8_t* src_temp = src_ptr + 2; + const uint8_t* src_temp1 = src_ptr1 + 2; + + asm volatile( + "vmov.u16 q15, #3 \n" + "vmov.u8 d28, #3 \n" + + "1: \n" + "vld1.8 {d4}, [%0]! \n" // 00112233 (1u1v) + "vld1.8 {d5}, [%5]! \n" // 11223344 (1u1v) + + "vmovl.u8 q0, d4 \n" // 00112233 (1u1v, 16b) + "vmovl.u8 q1, d5 \n" // 11223344 (1u1v, 16b) + "vmlal.u8 q0, d5, d28 \n" // 3*near+far (1, odd) + "vmlal.u8 q1, d4, d28 \n" // 3*near+far (1, even) + + "vld1.8 {d8}, [%1]! \n" // 00112233 (1u1v) + "vld1.8 {d9}, [%6]! \n" // 11223344 (1u1v) + + "vmovl.u8 q2, d8 \n" // 00112233 (1u1v, 16b) + "vmovl.u8 q3, d9 \n" // 11223344 (1u1v, 16b) + "vmlal.u8 q2, d9, d28 \n" // 3*near+far (2, odd) + "vmlal.u8 q3, d8, d28 \n" // 3*near+far (2, even) + + // e o + // q1 q0 + // q3 q2 + + "vmovq q4, q2 \n" + "vmovq q5, q3 \n" + "vmla.u16 q4, q0, q15 \n" // 9 3 3 1 (1, odd) + "vmla.u16 q5, q1, q15 \n" // 9 3 3 1 (1, even) + "vmla.u16 q0, q2, q15 \n" // 9 3 3 1 (2, odd) + "vmla.u16 q1, q3, q15 \n" // 9 3 3 1 (2, even) + + // e o + // q5 q4 + // q1 q0 + + "vrshrn.u16 d2, q1, #4 \n" // 2, even + "vrshrn.u16 d3, q0, #4 \n" // 2, odd + "vrshrn.u16 d0, q5, #4 \n" // 1, even + "vrshrn.u16 d1, q4, #4 \n" // 1, odd + + "vst2.16 {d0, d1}, [%2]! \n" // store + "vst2.16 {d2, d3}, [%3]! \n" // store + "subs %4, %4, #8 \n" // 4 uv -> 8 uv + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_ptr1), // %1 + "+r"(dst_ptr), // %2 + "+r"(dst_ptr1), // %3 + "+r"(dst_width), // %4 + "+r"(src_temp), // %5 + "+r"(src_temp1) // %6 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "d28", + "q15" // Clobber List + ); +} + +void ScaleUVRowUp2_Linear_16_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + const uint16_t* src_temp = src_ptr + 2; + asm volatile( + "vmov.u16 d30, #3 \n" + + "1: \n" + "vld1.16 {q0}, [%0]! \n" // 00112233 (1u1v, 16) + "vld1.16 {q1}, [%3]! \n" // 11223344 (1u1v, 16) + + "vmovl.u16 q2, d0 \n" // 0011 (1u1v, 32b) + "vmovl.u16 q3, d2 \n" // 1122 (1u1v, 32b) + "vmovl.u16 q4, d1 \n" // 2233 (1u1v, 32b) + "vmovl.u16 q5, d3 \n" // 3344 (1u1v, 32b) + "vmlal.u16 q2, d2, d30 \n" // 3*near+far (odd) + "vmlal.u16 q3, d0, d30 \n" // 3*near+far (even) + "vmlal.u16 q4, d3, d30 \n" // 3*near+far (odd) + "vmlal.u16 q5, d1, d30 \n" // 3*near+far (even) + + "vrshrn.u32 d1, q2, #2 \n" // 3/4*near+1/4*far (odd) + "vrshrn.u32 d0, q3, #2 \n" // 3/4*near+1/4*far (even) + "vrshrn.u32 d3, q4, #2 \n" // 3/4*near+1/4*far (odd) + "vrshrn.u32 d2, q5, #2 \n" // 3/4*near+1/4*far (even) + + "vst2.32 {d0, d1}, [%1]! \n" // store + "vst2.32 {d2, d3}, [%1]! \n" // store + "subs %2, %2, #8 \n" // 4 uv -> 8 uv + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst_ptr), // %1 + "+r"(dst_width), // %2 + "+r"(src_temp) // %3 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", + "d30" // Clobber List + ); +} + +void ScaleUVRowUp2_Bilinear_16_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint16_t* src_ptr1 = src_ptr + src_stride; + uint16_t* dst_ptr1 = dst_ptr + dst_stride; + const uint16_t* src_temp = src_ptr + 2; + const uint16_t* src_temp1 = src_ptr1 + 2; + + asm volatile( + "vmov.u16 d30, #3 \n" + "vmov.u32 q14, #3 \n" + + "1: \n" + "vld1.8 {d0}, [%0]! \n" // 0011 (1u1v) + "vld1.8 {d1}, [%5]! \n" // 1122 (1u1v) + "vmovl.u16 q2, d0 \n" // 0011 (1u1v, 32b) + "vmovl.u16 q3, d1 \n" // 1122 (1u1v, 32b) + "vmlal.u16 q2, d1, d30 \n" // 3*near+far (1, odd) + "vmlal.u16 q3, d0, d30 \n" // 3*near+far (1, even) + + "vld1.8 {d0}, [%1]! \n" // 0011 (1u1v) + "vld1.8 {d1}, [%6]! \n" // 1122 (1u1v) + "vmovl.u16 q4, d0 \n" // 0011 (1u1v, 32b) + "vmovl.u16 q5, d1 \n" // 1122 (1u1v, 32b) + "vmlal.u16 q4, d1, d30 \n" // 3*near+far (2, odd) + "vmlal.u16 q5, d0, d30 \n" // 3*near+far (2, even) + + "vmovq q0, q4 \n" + "vmovq q1, q5 \n" + "vmla.u32 q4, q2, q14 \n" // 9 3 3 1 (1, odd) + "vmla.u32 q5, q3, q14 \n" // 9 3 3 1 (1, even) + "vmla.u32 q2, q0, q14 \n" // 9 3 3 1 (2, odd) + "vmla.u32 q3, q1, q14 \n" // 9 3 3 1 (2, even) + + "vrshrn.u32 d1, q4, #4 \n" // 1, odd + "vrshrn.u32 d0, q5, #4 \n" // 1, even + "vrshrn.u32 d3, q2, #4 \n" // 2, odd + "vrshrn.u32 d2, q3, #4 \n" // 2, even + + "vst2.32 {d0, d1}, [%2]! \n" // store + "vst2.32 {d2, d3}, [%3]! \n" // store + "subs %4, %4, #4 \n" // 2 uv -> 4 uv + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_ptr1), // %1 + "+r"(dst_ptr), // %2 + "+r"(dst_ptr1), // %3 + "+r"(dst_width), // %4 + "+r"(src_temp), // %5 + "+r"(src_temp1) // %6 + : + : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q14", + "d30" // Clobber List + ); +} + // Add a row of bytes to a row of shorts. Used for box filter. // Reads 16 bytes and accumulates to 16 shorts at a time. void ScaleAddRow_NEON(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width) { asm volatile( - "1: \n" - "vld1.16 {q1, q2}, [%1] \n" // load accumulator - "vld1.8 {q0}, [%0]! \n" // load 16 bytes - "vaddw.u8 q2, q2, d1 \n" // add - "vaddw.u8 q1, q1, d0 \n" - "vst1.16 {q1, q2}, [%1]! \n" // store accumulator - "subs %2, %2, #16 \n" // 16 processed per loop - "bgt 1b \n" + "1: \n" + "vld1.16 {q1, q2}, [%1] \n" // load accumulator + "vld1.8 {q0}, [%0]! \n" // load 16 bytes + "vaddw.u8 q2, q2, d1 \n" // add + "vaddw.u8 q1, q1, d0 \n" + "vst1.16 {q1, q2}, [%1]! \n" // store accumulator + "subs %2, %2, #16 \n" // 16 processed per loop + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(src_width) // %2 @@ -547,17 +1033,17 @@ void ScaleFilterCols_NEON(uint8_t* dst_ptr, int* tmp = dx_offset; const uint8_t* src_tmp = src_ptr; asm volatile ( - "vdup.32 q0, %3 \n" // x - "vdup.32 q1, %4 \n" // dx - "vld1.32 {q2}, [%5] \n" // 0 1 2 3 - "vshl.i32 q3, q1, #2 \n" // 4 * dx - "vmul.s32 q1, q1, q2 \n" + "vdup.32 q0, %3 \n" // x + "vdup.32 q1, %4 \n" // dx + "vld1.32 {q2}, [%5] \n" // 0 1 2 3 + "vshl.i32 q3, q1, #2 \n" // 4 * dx + "vmul.s32 q1, q1, q2 \n" // x , x + 1 * dx, x + 2 * dx, x + 3 * dx - "vadd.s32 q1, q1, q0 \n" + "vadd.s32 q1, q1, q0 \n" // x + 4 * dx, x + 5 * dx, x + 6 * dx, x + 7 * dx - "vadd.s32 q2, q1, q3 \n" - "vshl.i32 q0, q3, #1 \n" // 8 * dx - "1: \n" + "vadd.s32 q2, q1, q3 \n" + "vshl.i32 q0, q3, #1 \n" // 8 * dx + "1: \n" LOAD2_DATA8_LANE(0) LOAD2_DATA8_LANE(1) LOAD2_DATA8_LANE(2) @@ -566,27 +1052,27 @@ void ScaleFilterCols_NEON(uint8_t* dst_ptr, LOAD2_DATA8_LANE(5) LOAD2_DATA8_LANE(6) LOAD2_DATA8_LANE(7) - "vmov q10, q1 \n" - "vmov q11, q2 \n" - "vuzp.16 q10, q11 \n" - "vmovl.u8 q8, d6 \n" - "vmovl.u8 q9, d7 \n" - "vsubl.s16 q11, d18, d16 \n" - "vsubl.s16 q12, d19, d17 \n" - "vmovl.u16 q13, d20 \n" - "vmovl.u16 q10, d21 \n" - "vmul.s32 q11, q11, q13 \n" - "vmul.s32 q12, q12, q10 \n" - "vrshrn.s32 d18, q11, #16 \n" - "vrshrn.s32 d19, q12, #16 \n" - "vadd.s16 q8, q8, q9 \n" - "vmovn.s16 d6, q8 \n" + "vmov q10, q1 \n" + "vmov q11, q2 \n" + "vuzp.16 q10, q11 \n" + "vmovl.u8 q8, d6 \n" + "vmovl.u8 q9, d7 \n" + "vsubl.s16 q11, d18, d16 \n" + "vsubl.s16 q12, d19, d17 \n" + "vmovl.u16 q13, d20 \n" + "vmovl.u16 q10, d21 \n" + "vmul.s32 q11, q11, q13 \n" + "vmul.s32 q12, q12, q10 \n" + "vrshrn.s32 d18, q11, #16 \n" + "vrshrn.s32 d19, q12, #16 \n" + "vadd.s16 q8, q8, q9 \n" + "vmovn.s16 d6, q8 \n" - "vst1.8 {d6}, [%0]! \n" // store pixels - "vadd.s32 q1, q1, q0 \n" - "vadd.s32 q2, q2, q0 \n" - "subs %2, %2, #8 \n" // 8 processed per loop - "bgt 1b \n" + "vst1.8 {d6}, [%0]! \n" // store pixels + "vadd.s32 q1, q1, q0 \n" + "vadd.s32 q2, q2, q0 \n" + "subs %2, %2, #8 \n" // 8 processed per loop + "bgt 1b \n" : "+r"(dst_ptr), // %0 "+r"(src_ptr), // %1 "+r"(dst_width), // %2 @@ -602,104 +1088,19 @@ void ScaleFilterCols_NEON(uint8_t* dst_ptr, #undef LOAD2_DATA8_LANE -// 16x2 -> 16x1 -void ScaleFilterRows_NEON(uint8_t* dst_ptr, - const uint8_t* src_ptr, - ptrdiff_t src_stride, - int dst_width, - int source_y_fraction) { - asm volatile( - "cmp %4, #0 \n" - "beq 100f \n" - "add %2, %1 \n" - "cmp %4, #64 \n" - "beq 75f \n" - "cmp %4, #128 \n" - "beq 50f \n" - "cmp %4, #192 \n" - "beq 25f \n" - - "vdup.8 d5, %4 \n" - "rsb %4, #256 \n" - "vdup.8 d4, %4 \n" - // General purpose row blend. - "1: \n" - "vld1.8 {q0}, [%1]! \n" - "vld1.8 {q1}, [%2]! \n" - "subs %3, %3, #16 \n" - "vmull.u8 q13, d0, d4 \n" - "vmull.u8 q14, d1, d4 \n" - "vmlal.u8 q13, d2, d5 \n" - "vmlal.u8 q14, d3, d5 \n" - "vrshrn.u16 d0, q13, #8 \n" - "vrshrn.u16 d1, q14, #8 \n" - "vst1.8 {q0}, [%0]! \n" - "bgt 1b \n" - "b 99f \n" - - // Blend 25 / 75. - "25: \n" - "vld1.8 {q0}, [%1]! \n" - "vld1.8 {q1}, [%2]! \n" - "subs %3, %3, #16 \n" - "vrhadd.u8 q0, q1 \n" - "vrhadd.u8 q0, q1 \n" - "vst1.8 {q0}, [%0]! \n" - "bgt 25b \n" - "b 99f \n" - - // Blend 50 / 50. - "50: \n" - "vld1.8 {q0}, [%1]! \n" - "vld1.8 {q1}, [%2]! \n" - "subs %3, %3, #16 \n" - "vrhadd.u8 q0, q1 \n" - "vst1.8 {q0}, [%0]! \n" - "bgt 50b \n" - "b 99f \n" - - // Blend 75 / 25. - "75: \n" - "vld1.8 {q1}, [%1]! \n" - "vld1.8 {q0}, [%2]! \n" - "subs %3, %3, #16 \n" - "vrhadd.u8 q0, q1 \n" - "vrhadd.u8 q0, q1 \n" - "vst1.8 {q0}, [%0]! \n" - "bgt 75b \n" - "b 99f \n" - - // Blend 100 / 0 - Copy row unchanged. - "100: \n" - "vld1.8 {q0}, [%1]! \n" - "subs %3, %3, #16 \n" - "vst1.8 {q0}, [%0]! \n" - "bgt 100b \n" - - "99: \n" - "vst1.8 {d1[7]}, [%0] \n" - : "+r"(dst_ptr), // %0 - "+r"(src_ptr), // %1 - "+r"(src_stride), // %2 - "+r"(dst_width), // %3 - "+r"(source_y_fraction) // %4 - : - : "q0", "q1", "d4", "d5", "q13", "q14", "memory", "cc"); -} - void ScaleARGBRowDown2_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width) { (void)src_stride; asm volatile( - "1: \n" - "vld4.32 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels. - "vld4.32 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ARGB - "subs %2, %2, #8 \n" // 8 processed per loop - "vmov q2, q1 \n" // load next 8 ARGB - "vst2.32 {q2, q3}, [%1]! \n" // store odd pixels - "bgt 1b \n" + "1: \n" + "vld4.32 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels. + "vld4.32 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ARGB + "subs %2, %2, #8 \n" // 8 processed per loop + "vmov q2, q1 \n" // load next 8 ARGB + "vst2.32 {q2, q3}, [%1]! \n" // store odd pixels + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst), // %1 "+r"(dst_width) // %2 @@ -721,14 +1122,14 @@ void ScaleARGBRowDown2Linear_NEON(const uint8_t* src_argb, int dst_width) { (void)src_stride; asm volatile( - "1: \n" - "vld4.32 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels. - "vld4.32 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ARGB - "subs %2, %2, #8 \n" // 8 processed per loop - "vrhadd.u8 q0, q0, q1 \n" // rounding half add - "vrhadd.u8 q1, q2, q3 \n" // rounding half add - "vst2.32 {q0, q1}, [%1]! \n" - "bgt 1b \n" + "1: \n" + "vld4.32 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels. + "vld4.32 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ARGB + "subs %2, %2, #8 \n" // 8 processed per loop + "vrhadd.u8 q0, q0, q1 \n" // rounding half add + "vrhadd.u8 q1, q2, q3 \n" // rounding half add + "vst2.32 {q0, q1}, [%1]! \n" + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(dst_width) // %2 @@ -743,27 +1144,27 @@ void ScaleARGBRowDown2Box_NEON(const uint8_t* src_ptr, int dst_width) { asm volatile( // change the stride to row 2 pointer - "add %1, %1, %0 \n" - "1: \n" - "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels. - "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ARGB - "subs %3, %3, #8 \n" // 8 processed per loop. - "vpaddl.u8 q0, q0 \n" // B 16 bytes -> 8 shorts. - "vpaddl.u8 q1, q1 \n" // G 16 bytes -> 8 shorts. - "vpaddl.u8 q2, q2 \n" // R 16 bytes -> 8 shorts. - "vpaddl.u8 q3, q3 \n" // A 16 bytes -> 8 shorts. - "vld4.8 {d16, d18, d20, d22}, [%1]! \n" // load 8 more ARGB - "vld4.8 {d17, d19, d21, d23}, [%1]! \n" // load last 8 ARGB - "vpadal.u8 q0, q8 \n" // B 16 bytes -> 8 shorts. - "vpadal.u8 q1, q9 \n" // G 16 bytes -> 8 shorts. - "vpadal.u8 q2, q10 \n" // R 16 bytes -> 8 shorts. - "vpadal.u8 q3, q11 \n" // A 16 bytes -> 8 shorts. - "vrshrn.u16 d0, q0, #2 \n" // round and pack to bytes - "vrshrn.u16 d1, q1, #2 \n" - "vrshrn.u16 d2, q2, #2 \n" - "vrshrn.u16 d3, q3, #2 \n" - "vst4.8 {d0, d1, d2, d3}, [%2]! \n" - "bgt 1b \n" + "add %1, %1, %0 \n" + "1: \n" + "vld4.8 {d0, d2, d4, d6}, [%0]! \n" // load 8 ARGB pixels. + "vld4.8 {d1, d3, d5, d7}, [%0]! \n" // load next 8 ARGB + "subs %3, %3, #8 \n" // 8 processed per loop. + "vpaddl.u8 q0, q0 \n" // B 16 bytes -> 8 shorts. + "vpaddl.u8 q1, q1 \n" // G 16 bytes -> 8 shorts. + "vpaddl.u8 q2, q2 \n" // R 16 bytes -> 8 shorts. + "vpaddl.u8 q3, q3 \n" // A 16 bytes -> 8 shorts. + "vld4.8 {d16, d18, d20, d22}, [%1]! \n" // load 8 more ARGB + "vld4.8 {d17, d19, d21, d23}, [%1]! \n" // load last 8 ARGB + "vpadal.u8 q0, q8 \n" // B 16 bytes -> 8 shorts. + "vpadal.u8 q1, q9 \n" // G 16 bytes -> 8 shorts. + "vpadal.u8 q2, q10 \n" // R 16 bytes -> 8 shorts. + "vpadal.u8 q3, q11 \n" // A 16 bytes -> 8 shorts. + "vrshrn.u16 d0, q0, #2 \n" // round and pack to bytes + "vrshrn.u16 d1, q1, #2 \n" + "vrshrn.u16 d2, q2, #2 \n" + "vrshrn.u16 d3, q3, #2 \n" + "vst4.8 {d0, d1, d2, d3}, [%2]! \n" + "bgt 1b \n" : "+r"(src_ptr), // %0 "+r"(src_stride), // %1 "+r"(dst), // %2 @@ -781,15 +1182,15 @@ void ScaleARGBRowDownEven_NEON(const uint8_t* src_argb, int dst_width) { (void)src_stride; asm volatile( - "mov r12, %3, lsl #2 \n" - "1: \n" - "vld1.32 {d0[0]}, [%0], r12 \n" - "vld1.32 {d0[1]}, [%0], r12 \n" - "vld1.32 {d1[0]}, [%0], r12 \n" - "vld1.32 {d1[1]}, [%0], r12 \n" - "subs %2, %2, #4 \n" // 4 pixels per loop. - "vst1.8 {q0}, [%1]! \n" - "bgt 1b \n" + "mov r12, %3, lsl #2 \n" + "1: \n" + "vld1.32 {d0[0]}, [%0], r12 \n" + "vld1.32 {d0[1]}, [%0], r12 \n" + "vld1.32 {d1[0]}, [%0], r12 \n" + "vld1.32 {d1[1]}, [%0], r12 \n" + "subs %2, %2, #4 \n" // 4 pixels per loop. + "vst1.8 {q0}, [%1]! \n" + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(dst_argb), // %1 "+r"(dst_width) // %2 @@ -805,30 +1206,30 @@ void ScaleARGBRowDownEvenBox_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int dst_width) { asm volatile( - "mov r12, %4, lsl #2 \n" - "add %1, %1, %0 \n" - "1: \n" - "vld1.8 {d0}, [%0], r12 \n" // 4 2x2 blocks -> 2x1 - "vld1.8 {d1}, [%1], r12 \n" - "vld1.8 {d2}, [%0], r12 \n" - "vld1.8 {d3}, [%1], r12 \n" - "vld1.8 {d4}, [%0], r12 \n" - "vld1.8 {d5}, [%1], r12 \n" - "vld1.8 {d6}, [%0], r12 \n" - "vld1.8 {d7}, [%1], r12 \n" - "vaddl.u8 q0, d0, d1 \n" - "vaddl.u8 q1, d2, d3 \n" - "vaddl.u8 q2, d4, d5 \n" - "vaddl.u8 q3, d6, d7 \n" - "vswp.8 d1, d2 \n" // ab_cd -> ac_bd - "vswp.8 d5, d6 \n" // ef_gh -> eg_fh - "vadd.u16 q0, q0, q1 \n" // (a+b)_(c+d) - "vadd.u16 q2, q2, q3 \n" // (e+f)_(g+h) - "vrshrn.u16 d0, q0, #2 \n" // first 2 pixels. - "vrshrn.u16 d1, q2, #2 \n" // next 2 pixels. - "subs %3, %3, #4 \n" // 4 pixels per loop. - "vst1.8 {q0}, [%2]! \n" - "bgt 1b \n" + "mov r12, %4, lsl #2 \n" + "add %1, %1, %0 \n" + "1: \n" + "vld1.8 {d0}, [%0], r12 \n" // 4 2x2 blocks -> 2x1 + "vld1.8 {d1}, [%1], r12 \n" + "vld1.8 {d2}, [%0], r12 \n" + "vld1.8 {d3}, [%1], r12 \n" + "vld1.8 {d4}, [%0], r12 \n" + "vld1.8 {d5}, [%1], r12 \n" + "vld1.8 {d6}, [%0], r12 \n" + "vld1.8 {d7}, [%1], r12 \n" + "vaddl.u8 q0, d0, d1 \n" + "vaddl.u8 q1, d2, d3 \n" + "vaddl.u8 q2, d4, d5 \n" + "vaddl.u8 q3, d6, d7 \n" + "vswp.8 d1, d2 \n" // ab_cd -> ac_bd + "vswp.8 d5, d6 \n" // ef_gh -> eg_fh + "vadd.u16 q0, q0, q1 \n" // (a+b)_(c+d) + "vadd.u16 q2, q2, q3 \n" // (e+f)_(g+h) + "vrshrn.u16 d0, q0, #2 \n" // first 2 pixels. + "vrshrn.u16 d1, q2, #2 \n" // next 2 pixels. + "subs %3, %3, #4 \n" // 4 pixels per loop. + "vst1.8 {q0}, [%2]! \n" + "bgt 1b \n" : "+r"(src_argb), // %0 "+r"(src_stride), // %1 "+r"(dst_argb), // %2 @@ -853,7 +1254,7 @@ void ScaleARGBCols_NEON(uint8_t* dst_argb, int tmp; const uint8_t* src_tmp = src_argb; asm volatile( - "1: \n" + "1: \n" // clang-format off LOAD1_DATA32_LANE(d0, 0) LOAD1_DATA32_LANE(d0, 1) @@ -865,8 +1266,8 @@ void ScaleARGBCols_NEON(uint8_t* dst_argb, LOAD1_DATA32_LANE(d3, 1) // clang-format on "vst1.32 {q0, q1}, [%0]! \n" // store pixels - "subs %2, %2, #8 \n" // 8 processed per loop - "bgt 1b \n" + "subs %2, %2, #8 \n" // 8 processed per loop + "bgt 1b \n" : "+r"(dst_argb), // %0 "+r"(src_argb), // %1 "+r"(dst_width), // %2 @@ -897,16 +1298,16 @@ void ScaleARGBFilterCols_NEON(uint8_t* dst_argb, int* tmp = dx_offset; const uint8_t* src_tmp = src_argb; asm volatile ( - "vdup.32 q0, %3 \n" // x - "vdup.32 q1, %4 \n" // dx - "vld1.32 {q2}, [%5] \n" // 0 1 2 3 - "vshl.i32 q9, q1, #2 \n" // 4 * dx - "vmul.s32 q1, q1, q2 \n" - "vmov.i8 q3, #0x7f \n" // 0x7F - "vmov.i16 q15, #0x7f \n" // 0x7F + "vdup.32 q0, %3 \n" // x + "vdup.32 q1, %4 \n" // dx + "vld1.32 {q2}, [%5] \n" // 0 1 2 3 + "vshl.i32 q9, q1, #2 \n" // 4 * dx + "vmul.s32 q1, q1, q2 \n" + "vmov.i8 q3, #0x7f \n" // 0x7F + "vmov.i16 q15, #0x7f \n" // 0x7F // x , x + 1 * dx, x + 2 * dx, x + 3 * dx - "vadd.s32 q8, q1, q0 \n" - "1: \n" + "vadd.s32 q8, q1, q0 \n" + "1: \n" // d0, d1: a // d2, d3: b LOAD2_DATA32_LANE(d0, d2, 0) @@ -950,6 +1351,140 @@ void ScaleARGBFilterCols_NEON(uint8_t* dst_argb, #undef LOAD2_DATA32_LANE +void ScaleUVRowDown2_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + (void)src_stride; + asm volatile( + "1: \n" + "vld2.16 {d0, d2}, [%0]! \n" // load 8 UV pixels. + "vld2.16 {d1, d3}, [%0]! \n" // load next 8 UV + "subs %2, %2, #8 \n" // 8 processed per loop. + "vst1.16 {q1}, [%1]! \n" // store 8 UV + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "q0", "q1"); +} + +void ScaleUVRowDown2Linear_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + (void)src_stride; + asm volatile( + "1: \n" + "vld2.16 {d0, d2}, [%0]! \n" // load 8 UV pixels. + "vld2.16 {d1, d3}, [%0]! \n" // load next 8 UV + "subs %2, %2, #8 \n" // 8 processed per loop. + "vrhadd.u8 q0, q0, q1 \n" // rounding half add + "vst1.16 {q0}, [%1]! \n" // store 8 UV + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "q0", "q1"); +} + +void ScaleUVRowDown2Box_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + asm volatile( + // change the stride to row 2 pointer + "add %1, %1, %0 \n" + "1: \n" + "vld2.8 {d0, d2}, [%0]! \n" // load 8 UV pixels. + "vld2.8 {d1, d3}, [%0]! \n" // load next 8 UV + "subs %3, %3, #8 \n" // 8 processed per loop. + "vpaddl.u8 q0, q0 \n" // U 16 bytes -> 8 shorts. + "vpaddl.u8 q1, q1 \n" // V 16 bytes -> 8 shorts. + "vld2.8 {d16, d18}, [%1]! \n" // load 8 more UV + "vld2.8 {d17, d19}, [%1]! \n" // load last 8 UV + "vpadal.u8 q0, q8 \n" // U 16 bytes -> 8 shorts. + "vpadal.u8 q1, q9 \n" // V 16 bytes -> 8 shorts. + "vrshrn.u16 d0, q0, #2 \n" // round and pack to bytes + "vrshrn.u16 d1, q1, #2 \n" + "vst2.8 {d0, d1}, [%2]! \n" + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_stride), // %1 + "+r"(dst), // %2 + "+r"(dst_width) // %3 + : + : "memory", "cc", "q0", "q1", "q8", "q9"); +} + +// Reads 4 pixels at a time. +void ScaleUVRowDownEven_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + int src_stepx, // pixel step + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* src1_ptr = src_ptr + src_stepx * 2; + const uint8_t* src2_ptr = src_ptr + src_stepx * 4; + const uint8_t* src3_ptr = src_ptr + src_stepx * 6; + (void)src_stride; + asm volatile( + "1: \n" + "vld1.16 {d0[0]}, [%0], %6 \n" + "vld1.16 {d0[1]}, [%1], %6 \n" + "vld1.16 {d0[2]}, [%2], %6 \n" + "vld1.16 {d0[3]}, [%3], %6 \n" + "subs %5, %5, #4 \n" // 4 pixels per loop. + "vst1.8 {d0}, [%4]! \n" + "bgt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src1_ptr), // %1 + "+r"(src2_ptr), // %2 + "+r"(src3_ptr), // %3 + "+r"(dst_ptr), // %4 + "+r"(dst_width) // %5 + : "r"(src_stepx * 8) // %6 + : "memory", "cc", "d0"); +} + +// Scale UV columns by 3 box filter. +// Reads 96 bytes (24 UV pixels) and writes 16 bytes (8 UV pixels) per loop. +void ScaleUVAddCols3_NEON(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { + asm volatile( + "vdup.16 d16, %[scaleval] \n" + "1: \n" + "vld3.32 {d0, d2, d4}, [%[src_uv]]! \n" + "vld3.32 {d1, d3, d5}, [%[src_uv]]! \n" + "vadd.u16 q0, q0, q1 \n" + "vadd.u16 q0, q0, q2 \n" + "vld3.32 {d2, d4, d6}, [%[src_uv]]! \n" + "vld3.32 {d3, d5, d7}, [%[src_uv]]! \n" + "vadd.u16 q1, q1, q2 \n" + "vadd.u16 q1, q1, q3 \n" + "vmull.u16 q2, d0, d16 \n" + "vmull.u16 q3, d1, d16 \n" + "vmull.u16 q9, d2, d16 \n" + "vmull.u16 q10, d3, d16 \n" + "vshrn.i32 d0, q2, #16 \n" + "vshrn.i32 d1, q3, #16 \n" + "vshrn.i32 d2, q9, #16 \n" + "vshrn.i32 d3, q10, #16 \n" + "vmovn.i16 d0, q0 \n" + "vmovn.i16 d1, q1 \n" + "subs %[dst_width], %[dst_width], #8 \n" + "vst1.8 {q0}, [%[dst_uv]]! \n" + "bgt 1b \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [dst_width] "+r"(dst_width) // %[dst_width] + : [scaleval] "r"(scaleval) // %[scaleval] + : "memory", "cc", "q0", "q1", "q2", "q3", "q8", "q9", "q10"); +} + #endif // defined(__ARM_NEON__) && !defined(__aarch64__) #ifdef __cplusplus diff --git a/libs/libyuv/source/scale_neon64.cc b/libs/libyuv/source/scale_neon64.cc index 0a7b80ce1d..2bb04b6e9b 100644 --- a/libs/libyuv/source/scale_neon64.cc +++ b/libs/libyuv/source/scale_neon64.cc @@ -17,6 +17,13 @@ namespace libyuv { extern "C" { #endif +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + // This module is for GCC Neon armv8 64 bit. #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) @@ -27,17 +34,18 @@ void ScaleRowDown2_NEON(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "1: \n" + "1: \n" // load even pixels into v0, odd into v1 - "ld2 {v0.16b,v1.16b}, [%0], #32 \n" - "subs %w2, %w2, #16 \n" // 16 processed per loop - "st1 {v1.16b}, [%1], #16 \n" // store odd pixels - "b.gt 1b \n" + "ld2 {v0.16b,v1.16b}, [%0], #32 \n" + "subs %w2, %w2, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "st1 {v1.16b}, [%1], #16 \n" // store odd pixels + "b.gt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst), // %1 "+r"(dst_width) // %2 : - : "v0", "v1" // Clobber List + : "memory", "cc", "v0", "v1" // Clobber List ); } @@ -48,18 +56,19 @@ void ScaleRowDown2Linear_NEON(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "1: \n" + "1: \n" // load even pixels into v0, odd into v1 - "ld2 {v0.16b,v1.16b}, [%0], #32 \n" - "subs %w2, %w2, #16 \n" // 16 processed per loop - "urhadd v0.16b, v0.16b, v1.16b \n" // rounding half add - "st1 {v0.16b}, [%1], #16 \n" - "b.gt 1b \n" + "ld2 {v0.16b,v1.16b}, [%0], #32 \n" + "subs %w2, %w2, #16 \n" // 16 processed per loop + "urhadd v0.16b, v0.16b, v1.16b \n" // rounding half add + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "st1 {v0.16b}, [%1], #16 \n" + "b.gt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst), // %1 "+r"(dst_width) // %2 : - : "v0", "v1" // Clobber List + : "memory", "cc", "v0", "v1" // Clobber List ); } @@ -70,25 +79,27 @@ void ScaleRowDown2Box_NEON(const uint8_t* src_ptr, int dst_width) { asm volatile( // change the stride to row 2 pointer - "add %1, %1, %0 \n" - "1: \n" - "ld1 {v0.16b, v1.16b}, [%0], #32 \n" // load row 1 and post inc - "ld1 {v2.16b, v3.16b}, [%1], #32 \n" // load row 2 and post inc - "subs %w3, %w3, #16 \n" // 16 processed per loop - "uaddlp v0.8h, v0.16b \n" // row 1 add adjacent - "uaddlp v1.8h, v1.16b \n" - "uadalp v0.8h, v2.16b \n" // += row 2 add adjacent - "uadalp v1.8h, v3.16b \n" - "rshrn v0.8b, v0.8h, #2 \n" // round and pack - "rshrn2 v0.16b, v1.8h, #2 \n" - "st1 {v0.16b}, [%2], #16 \n" - "b.gt 1b \n" + "add %1, %1, %0 \n" + "1: \n" + "ld1 {v0.16b, v1.16b}, [%0], #32 \n" // load row 1 and post inc + "ld1 {v2.16b, v3.16b}, [%1], #32 \n" // load row 2 and post inc + "subs %w3, %w3, #16 \n" // 16 processed per loop + "uaddlp v0.8h, v0.16b \n" // row 1 add adjacent + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "uaddlp v1.8h, v1.16b \n" + "prfm pldl1keep, [%1, 448] \n" + "uadalp v0.8h, v2.16b \n" // += row 2 add adjacent + "uadalp v1.8h, v3.16b \n" + "rshrn v0.8b, v0.8h, #2 \n" // round and pack + "rshrn2 v0.16b, v1.8h, #2 \n" + "st1 {v0.16b}, [%2], #16 \n" + "b.gt 1b \n" : "+r"(src_ptr), // %0 "+r"(src_stride), // %1 "+r"(dst), // %2 "+r"(dst_width) // %3 : - : "v0", "v1", "v2", "v3" // Clobber List + : "memory", "cc", "v0", "v1", "v2", "v3" // Clobber List ); } @@ -98,16 +109,17 @@ void ScaleRowDown4_NEON(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // src line 0 - "subs %w2, %w2, #8 \n" // 8 processed per loop - "st1 {v2.8b}, [%1], #8 \n" - "b.gt 1b \n" + "1: \n" + "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // src line 0 + "subs %w2, %w2, #16 \n" // 16 processed per loop + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "st1 {v2.16b}, [%1], #16 \n" + "b.gt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width) // %2 : - : "v0", "v1", "v2", "v3", "memory", "cc"); + : "memory", "cc", "v0", "v1", "v2", "v3"); } void ScaleRowDown4Box_NEON(const uint8_t* src_ptr, @@ -118,20 +130,28 @@ void ScaleRowDown4Box_NEON(const uint8_t* src_ptr, const uint8_t* src_ptr2 = src_ptr + src_stride * 2; const uint8_t* src_ptr3 = src_ptr + src_stride * 3; asm volatile( - "1: \n" - "ld1 {v0.16b}, [%0], #16 \n" // load up 16x4 - "ld1 {v1.16b}, [%2], #16 \n" - "ld1 {v2.16b}, [%3], #16 \n" - "ld1 {v3.16b}, [%4], #16 \n" - "subs %w5, %w5, #4 \n" - "uaddlp v0.8h, v0.16b \n" - "uadalp v0.8h, v1.16b \n" - "uadalp v0.8h, v2.16b \n" - "uadalp v0.8h, v3.16b \n" - "addp v0.8h, v0.8h, v0.8h \n" - "rshrn v0.8b, v0.8h, #4 \n" // divide by 16 w/rounding - "st1 {v0.s}[0], [%1], #4 \n" - "b.gt 1b \n" + "1: \n" + "ldp q0, q4, [%0], #32 \n" // load up 16x8 + "ldp q1, q5, [%2], #32 \n" + "ldp q2, q6, [%3], #32 \n" + "ldp q3, q7, [%4], #32 \n" + "subs %w5, %w5, #8 \n" + "uaddlp v0.8h, v0.16b \n" + "uaddlp v4.8h, v4.16b \n" + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "uadalp v0.8h, v1.16b \n" + "uadalp v4.8h, v5.16b \n" + "prfm pldl1keep, [%2, 448] \n" + "uadalp v0.8h, v2.16b \n" + "uadalp v4.8h, v6.16b \n" + "prfm pldl1keep, [%3, 448] \n" + "uadalp v0.8h, v3.16b \n" + "uadalp v4.8h, v7.16b \n" + "prfm pldl1keep, [%4, 448] \n" + "addp v0.8h, v0.8h, v4.8h \n" + "rshrn v0.8b, v0.8h, #4 \n" // divide by 16 w/rounding + "str d0, [%1], #8 \n" + "b.gt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(src_ptr1), // %2 @@ -139,29 +159,45 @@ void ScaleRowDown4Box_NEON(const uint8_t* src_ptr, "+r"(src_ptr3), // %4 "+r"(dst_width) // %5 : - : "v0", "v1", "v2", "v3", "memory", "cc"); + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); } -// Down scale from 4 to 3 pixels. Use the neon multilane read/write -// to load up the every 4th pixel into a 4 different registers. -// Point samples 32 pixels to 24 pixels. +static const uvec8 kShuf34_0 = { + 0, 1, 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, 19, 20, +}; +static const uvec8 kShuf34_1 = { + 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, 19, 20, 21, 23, 24, 25, +}; +static const uvec8 kShuf34_2 = { + 11, 12, 13, 15, 16, 17, 19, 20, 21, 23, 24, 25, 27, 28, 29, 31, +}; + +// Down scale from 4 to 3 pixels. Point samples 64 pixels to 48 pixels. void ScaleRowDown34_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width) { (void)src_stride; asm volatile( - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // src line 0 - "subs %w2, %w2, #24 \n" - "orr v2.16b, v3.16b, v3.16b \n" // order v0,v1,v2 - "st3 {v0.8b,v1.8b,v2.8b}, [%1], #24 \n" - "b.gt 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(dst_width) // %2 - : - : "v0", "v1", "v2", "v3", "memory", "cc"); + "ld1 {v29.16b}, [%[kShuf34_0]] \n" + "ld1 {v30.16b}, [%[kShuf34_1]] \n" + "ld1 {v31.16b}, [%[kShuf34_2]] \n" + "1: \n" + "ld1 {v0.16b,v1.16b,v2.16b,v3.16b}, [%[src_ptr]], #64 \n" + "subs %w[width], %w[width], #48 \n" + "tbl v0.16b, {v0.16b, v1.16b}, v29.16b \n" + "prfm pldl1keep, [%[src_ptr], 448] \n" + "tbl v1.16b, {v1.16b, v2.16b}, v30.16b \n" + "tbl v2.16b, {v2.16b, v3.16b}, v31.16b \n" + "st1 {v0.16b,v1.16b,v2.16b}, [%[dst_ptr]], #48 \n" + "b.gt 1b \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [width] "+r"(dst_width) // %[width] + : [kShuf34_0] "r"(&kShuf34_0), // %[kShuf34_0] + [kShuf34_1] "r"(&kShuf34_1), // %[kShuf34_1] + [kShuf34_2] "r"(&kShuf34_2) // %[kShuf34_2] + : "memory", "cc", "v0", "v1", "v2", "v3", "v29", "v30", "v31"); } void ScaleRowDown34_0_Box_NEON(const uint8_t* src_ptr, @@ -169,56 +205,77 @@ void ScaleRowDown34_0_Box_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) { asm volatile( - "movi v20.8b, #3 \n" - "add %3, %3, %0 \n" - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // src line 0 - "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%3], #32 \n" // src line 1 - "subs %w2, %w2, #24 \n" + "movi v24.16b, #3 \n" + "add %3, %3, %0 \n" + + "1: \n" + "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // src line 0 + "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%3], #64 \n" // src line 1 + "subs %w2, %w2, #48 \n" // filter src line 0 with src line 1 // expand chars to shorts to allow for room // when adding lines together - "ushll v16.8h, v4.8b, #0 \n" - "ushll v17.8h, v5.8b, #0 \n" - "ushll v18.8h, v6.8b, #0 \n" - "ushll v19.8h, v7.8b, #0 \n" + "ushll v16.8h, v4.8b, #0 \n" + "ushll v17.8h, v5.8b, #0 \n" + "ushll v18.8h, v6.8b, #0 \n" + "ushll v19.8h, v7.8b, #0 \n" + "ushll2 v20.8h, v4.16b, #0 \n" + "ushll2 v21.8h, v5.16b, #0 \n" + "ushll2 v22.8h, v6.16b, #0 \n" + "ushll2 v23.8h, v7.16b, #0 \n" // 3 * line_0 + line_1 - "umlal v16.8h, v0.8b, v20.8b \n" - "umlal v17.8h, v1.8b, v20.8b \n" - "umlal v18.8h, v2.8b, v20.8b \n" - "umlal v19.8h, v3.8b, v20.8b \n" + "umlal v16.8h, v0.8b, v24.8b \n" + "umlal v17.8h, v1.8b, v24.8b \n" + "umlal v18.8h, v2.8b, v24.8b \n" + "umlal v19.8h, v3.8b, v24.8b \n" + "umlal2 v20.8h, v0.16b, v24.16b \n" + "umlal2 v21.8h, v1.16b, v24.16b \n" + "umlal2 v22.8h, v2.16b, v24.16b \n" + "umlal2 v23.8h, v3.16b, v24.16b \n" + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead - // (3 * line_0 + line_1) >> 2 - "uqrshrn v0.8b, v16.8h, #2 \n" - "uqrshrn v1.8b, v17.8h, #2 \n" - "uqrshrn v2.8b, v18.8h, #2 \n" - "uqrshrn v3.8b, v19.8h, #2 \n" + // (3 * line_0 + line_1 + 2) >> 2 + "uqrshrn v0.8b, v16.8h, #2 \n" + "uqrshrn v1.8b, v17.8h, #2 \n" + "uqrshrn v2.8b, v18.8h, #2 \n" + "uqrshrn v3.8b, v19.8h, #2 \n" + "uqrshrn2 v0.16b, v20.8h, #2 \n" + "uqrshrn2 v1.16b, v21.8h, #2 \n" + "uqrshrn2 v2.16b, v22.8h, #2 \n" + "uqrshrn2 v3.16b, v23.8h, #2 \n" + "prfm pldl1keep, [%3, 448] \n" - // a0 = (src[0] * 3 + s[1] * 1) >> 2 - "ushll v16.8h, v1.8b, #0 \n" - "umlal v16.8h, v0.8b, v20.8b \n" - "uqrshrn v0.8b, v16.8h, #2 \n" + // a0 = (src[0] * 3 + s[1] * 1 + 2) >> 2 + "ushll v16.8h, v1.8b, #0 \n" + "ushll2 v17.8h, v1.16b, #0 \n" + "umlal v16.8h, v0.8b, v24.8b \n" + "umlal2 v17.8h, v0.16b, v24.16b \n" + "uqrshrn v0.8b, v16.8h, #2 \n" + "uqrshrn2 v0.16b, v17.8h, #2 \n" - // a1 = (src[1] * 1 + s[2] * 1) >> 1 - "urhadd v1.8b, v1.8b, v2.8b \n" + // a1 = (src[1] * 1 + s[2] * 1 + 1) >> 1 + "urhadd v1.16b, v1.16b, v2.16b \n" - // a2 = (src[2] * 1 + s[3] * 3) >> 2 - "ushll v16.8h, v2.8b, #0 \n" - "umlal v16.8h, v3.8b, v20.8b \n" - "uqrshrn v2.8b, v16.8h, #2 \n" + // a2 = (src[2] * 1 + s[3] * 3 + 2) >> 2 + "ushll v16.8h, v2.8b, #0 \n" + "ushll2 v17.8h, v2.16b, #0 \n" + "umlal v16.8h, v3.8b, v24.8b \n" + "umlal2 v17.8h, v3.16b, v24.16b \n" + "uqrshrn v2.8b, v16.8h, #2 \n" + "uqrshrn2 v2.16b, v17.8h, #2 \n" - "st3 {v0.8b,v1.8b,v2.8b}, [%1], #24 \n" + "st3 {v0.16b,v1.16b,v2.16b}, [%1], #48 \n" - "b.gt 1b \n" + "b.gt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width), // %2 "+r"(src_stride) // %3 : - : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18", - "v19", "v20", "memory", "cc"); + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24"); } void ScaleRowDown34_1_Box_NEON(const uint8_t* src_ptr, @@ -226,51 +283,57 @@ void ScaleRowDown34_1_Box_NEON(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) { asm volatile( - "movi v20.8b, #3 \n" - "add %3, %3, %0 \n" - "1: \n" - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // src line 0 - "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%3], #32 \n" // src line 1 - "subs %w2, %w2, #24 \n" + "movi v20.16b, #3 \n" + "add %3, %3, %0 \n" + + "1: \n" + "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // src line 0 + "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%3], #64 \n" // src line 1 + "subs %w2, %w2, #48 \n" // average src line 0 with src line 1 - "urhadd v0.8b, v0.8b, v4.8b \n" - "urhadd v1.8b, v1.8b, v5.8b \n" - "urhadd v2.8b, v2.8b, v6.8b \n" - "urhadd v3.8b, v3.8b, v7.8b \n" + "urhadd v0.16b, v0.16b, v4.16b \n" + "urhadd v1.16b, v1.16b, v5.16b \n" + "urhadd v2.16b, v2.16b, v6.16b \n" + "urhadd v3.16b, v3.16b, v7.16b \n" + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead - // a0 = (src[0] * 3 + s[1] * 1) >> 2 - "ushll v4.8h, v1.8b, #0 \n" - "umlal v4.8h, v0.8b, v20.8b \n" - "uqrshrn v0.8b, v4.8h, #2 \n" + // a0 = (src[0] * 3 + s[1] * 1 + 2) >> 2 + "ushll v4.8h, v1.8b, #0 \n" + "ushll2 v5.8h, v1.16b, #0 \n" + "umlal v4.8h, v0.8b, v20.8b \n" + "umlal2 v5.8h, v0.16b, v20.16b \n" + "uqrshrn v0.8b, v4.8h, #2 \n" + "uqrshrn2 v0.16b, v5.8h, #2 \n" + "prfm pldl1keep, [%3, 448] \n" - // a1 = (src[1] * 1 + s[2] * 1) >> 1 - "urhadd v1.8b, v1.8b, v2.8b \n" + // a1 = (src[1] * 1 + s[2] * 1 + 1) >> 1 + "urhadd v1.16b, v1.16b, v2.16b \n" - // a2 = (src[2] * 1 + s[3] * 3) >> 2 - "ushll v4.8h, v2.8b, #0 \n" - "umlal v4.8h, v3.8b, v20.8b \n" - "uqrshrn v2.8b, v4.8h, #2 \n" + // a2 = (src[2] * 1 + s[3] * 3 + 2) >> 2 + "ushll v4.8h, v2.8b, #0 \n" + "ushll2 v5.8h, v2.16b, #0 \n" + "umlal v4.8h, v3.8b, v20.8b \n" + "umlal2 v5.8h, v3.16b, v20.16b \n" + "uqrshrn v2.8b, v4.8h, #2 \n" + "uqrshrn2 v2.16b, v5.8h, #2 \n" - "st3 {v0.8b,v1.8b,v2.8b}, [%1], #24 \n" - "b.gt 1b \n" + "st3 {v0.16b,v1.16b,v2.16b}, [%1], #48 \n" + "b.gt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(dst_width), // %2 "+r"(src_stride) // %3 : - : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20", "memory", "cc"); + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20"); } static const uvec8 kShuf38 = {0, 3, 6, 8, 11, 14, 16, 19, 22, 24, 27, 30, 0, 0, 0, 0}; -static const uvec8 kShuf38_2 = {0, 16, 32, 2, 18, 33, 4, 20, - 34, 6, 22, 35, 0, 0, 0, 0}; -static const vec16 kMult38_Div6 = {65536 / 12, 65536 / 12, 65536 / 12, - 65536 / 12, 65536 / 12, 65536 / 12, - 65536 / 12, 65536 / 12}; -static const vec16 kMult38_Div9 = {65536 / 18, 65536 / 18, 65536 / 18, - 65536 / 18, 65536 / 18, 65536 / 18, - 65536 / 18, 65536 / 18}; +static const vec16 kMult38_Div664 = { + 65536 / 12, 65536 / 12, 65536 / 8, 65536 / 12, 65536 / 12, 65536 / 8, 0, 0}; +static const vec16 kMult38_Div996 = {65536 / 18, 65536 / 18, 65536 / 12, + 65536 / 18, 65536 / 18, 65536 / 12, + 0, 0}; // 32 -> 12 void ScaleRowDown38_NEON(const uint8_t* src_ptr, @@ -279,240 +342,651 @@ void ScaleRowDown38_NEON(const uint8_t* src_ptr, int dst_width) { (void)src_stride; asm volatile( - "ld1 {v3.16b}, [%3] \n" - "1: \n" - "ld1 {v0.16b,v1.16b}, [%0], #32 \n" - "subs %w2, %w2, #12 \n" - "tbl v2.16b, {v0.16b,v1.16b}, v3.16b \n" - "st1 {v2.8b}, [%1], #8 \n" - "st1 {v2.s}[2], [%1], #4 \n" - "b.gt 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(dst_width) // %2 - : "r"(&kShuf38) // %3 - : "v0", "v1", "v2", "v3", "memory", "cc"); + "ld1 {v3.16b}, [%[kShuf38]] \n" + "subs %w[width], %w[width], #12 \n" + "b.eq 2f \n" + + "1: \n" + "ldp q0, q1, [%[src_ptr]], #32 \n" + "subs %w[width], %w[width], #12 \n" + "tbl v2.16b, {v0.16b, v1.16b}, v3.16b \n" + "prfm pldl1keep, [%[src_ptr], 448] \n" // prefetch 7 lines ahead + "str q2, [%[dst_ptr]] \n" + "add %[dst_ptr], %[dst_ptr], #12 \n" + "b.gt 1b \n" + + // Store exactly 12 bytes on the final iteration to avoid writing past + // the end of the array. + "2: \n" + "ldp q0, q1, [%[src_ptr]] \n" + "tbl v2.16b, {v0.16b, v1.16b}, v3.16b \n" + "st1 {v2.8b}, [%[dst_ptr]], #8 \n" + "st1 {v2.s}[2], [%[dst_ptr]] \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [width] "+r"(dst_width) // %[width] + : [kShuf38] "r"(&kShuf38) // %[kShuf38] + : "memory", "cc", "v0", "v1", "v2", "v3"); } -// 32x3 -> 12x1 -void OMITFP ScaleRowDown38_3_Box_NEON(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - const uint8_t* src_ptr1 = src_ptr + src_stride * 2; - ptrdiff_t tmp_src_stride = src_stride; +static const uvec8 kScaleRowDown38_3_BoxIndices1[] = { + 0, 1, 6, 7, 12, 13, 16, 17, 22, 23, 28, 29, 255, 255, 255, 255}; +static const uvec8 kScaleRowDown38_3_BoxIndices2[] = { + 2, 3, 8, 9, 14, 15, 18, 19, 24, 25, 30, 31, 255, 255, 255, 255}; +static const uvec8 kScaleRowDown38_3_BoxIndices3[] = { + 4, 5, 10, 11, 255, 255, 20, 21, 26, 27, 255, 255, 255, 255, 255, 255}; +static const uvec8 kScaleRowDown38_NarrowIndices[] = { + 0, 2, 4, 6, 8, 10, 16, 18, 20, 22, 24, 26, 255, 255, 255, 255}; +void ScaleRowDown38_3_Box_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* src_ptr1 = src_ptr + src_stride; + const uint8_t* src_ptr2 = src_ptr + src_stride * 2; asm volatile( - "ld1 {v29.8h}, [%5] \n" - "ld1 {v30.16b}, [%6] \n" - "ld1 {v31.8h}, [%7] \n" - "add %2, %2, %0 \n" - "1: \n" + "ld1 {v27.16b}, [%[tblArray1]] \n" + "ld1 {v28.16b}, [%[tblArray2]] \n" + "ld1 {v29.16b}, [%[tblArray3]] \n" + "ld1 {v31.16b}, [%[tblArray4]] \n" + "ld1 {v30.16b}, [%[div996]] \n" - // 00 40 01 41 02 42 03 43 - // 10 50 11 51 12 52 13 53 - // 20 60 21 61 22 62 23 63 - // 30 70 31 71 32 72 33 73 - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" - "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%2], #32 \n" - "ld4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%3], #32 \n" - "subs %w4, %w4, #12 \n" + "1: \n" + "ldp q20, q0, [%[src_ptr]], #32 \n" + "ldp q21, q1, [%[src_ptr1]], #32 \n" + "ldp q22, q2, [%[src_ptr2]], #32 \n" - // Shuffle the input data around to get align the data - // so adjacent data can be added. 0,1 - 2,3 - 4,5 - 6,7 - // 00 10 01 11 02 12 03 13 - // 40 50 41 51 42 52 43 53 - "trn1 v20.8b, v0.8b, v1.8b \n" - "trn2 v21.8b, v0.8b, v1.8b \n" - "trn1 v22.8b, v4.8b, v5.8b \n" - "trn2 v23.8b, v4.8b, v5.8b \n" - "trn1 v24.8b, v16.8b, v17.8b \n" - "trn2 v25.8b, v16.8b, v17.8b \n" + "subs %w[width], %w[width], #12 \n" - // 20 30 21 31 22 32 23 33 - // 60 70 61 71 62 72 63 73 - "trn1 v0.8b, v2.8b, v3.8b \n" - "trn2 v1.8b, v2.8b, v3.8b \n" - "trn1 v4.8b, v6.8b, v7.8b \n" - "trn2 v5.8b, v6.8b, v7.8b \n" - "trn1 v16.8b, v18.8b, v19.8b \n" - "trn2 v17.8b, v18.8b, v19.8b \n" + // Add across strided rows first. + "uaddl v23.8h, v20.8b, v21.8b \n" + "uaddl v3.8h, v0.8b, v1.8b \n" + "uaddl2 v24.8h, v20.16b, v21.16b \n" + "uaddl2 v4.8h, v0.16b, v1.16b \n" - // 00+10 01+11 02+12 03+13 - // 40+50 41+51 42+52 43+53 - "uaddlp v20.4h, v20.8b \n" - "uaddlp v21.4h, v21.8b \n" - "uaddlp v22.4h, v22.8b \n" - "uaddlp v23.4h, v23.8b \n" - "uaddlp v24.4h, v24.8b \n" - "uaddlp v25.4h, v25.8b \n" + "uaddw v23.8h, v23.8h, v22.8b \n" + "uaddw v3.8h, v3.8h, v2.8b \n" + "uaddw2 v24.8h, v24.8h, v22.16b \n" // abcdefgh ... + "uaddw2 v4.8h, v4.8h, v2.16b \n" - // 60+70 61+71 62+72 63+73 - "uaddlp v1.4h, v1.8b \n" - "uaddlp v5.4h, v5.8b \n" - "uaddlp v17.4h, v17.8b \n" + // Permute groups of {three,three,two} into separate vectors to sum. + "tbl v20.16b, {v23.16b, v24.16b}, v27.16b \n" // a d g ... + "tbl v0.16b, {v3.16b, v4.16b}, v27.16b \n" + "tbl v21.16b, {v23.16b, v24.16b}, v28.16b \n" // b e h ... + "tbl v1.16b, {v3.16b, v4.16b}, v28.16b \n" + "tbl v22.16b, {v23.16b, v24.16b}, v29.16b \n" // c f 0... + "tbl v2.16b, {v3.16b, v4.16b}, v29.16b \n" - // combine source lines - "add v20.4h, v20.4h, v22.4h \n" - "add v21.4h, v21.4h, v23.4h \n" - "add v20.4h, v20.4h, v24.4h \n" - "add v21.4h, v21.4h, v25.4h \n" - "add v2.4h, v1.4h, v5.4h \n" - "add v2.4h, v2.4h, v17.4h \n" + "add v23.8h, v20.8h, v21.8h \n" + "add v3.8h, v0.8h, v1.8h \n" + "add v24.8h, v23.8h, v22.8h \n" // a+b+c d+e+f g+h + "add v4.8h, v3.8h, v2.8h \n" - // dst_ptr[3] = (s[6 + st * 0] + s[7 + st * 0] - // + s[6 + st * 1] + s[7 + st * 1] - // + s[6 + st * 2] + s[7 + st * 2]) / 6 - "sqrdmulh v2.8h, v2.8h, v29.8h \n" - "xtn v2.8b, v2.8h \n" - - // Shuffle 2,3 reg around so that 2 can be added to the - // 0,1 reg and 3 can be added to the 4,5 reg. This - // requires expanding from u8 to u16 as the 0,1 and 4,5 - // registers are already expanded. Then do transposes - // to get aligned. - // xx 20 xx 30 xx 21 xx 31 xx 22 xx 32 xx 23 xx 33 - "ushll v16.8h, v16.8b, #0 \n" - "uaddl v0.8h, v0.8b, v4.8b \n" - - // combine source lines - "add v0.8h, v0.8h, v16.8h \n" - - // xx 20 xx 21 xx 22 xx 23 - // xx 30 xx 31 xx 32 xx 33 - "trn1 v1.8h, v0.8h, v0.8h \n" - "trn2 v4.8h, v0.8h, v0.8h \n" - "xtn v0.4h, v1.4s \n" - "xtn v4.4h, v4.4s \n" - - // 0+1+2, 3+4+5 - "add v20.8h, v20.8h, v0.8h \n" - "add v21.8h, v21.8h, v4.8h \n" - - // Need to divide, but can't downshift as the the value - // isn't a power of 2. So multiply by 65536 / n - // and take the upper 16 bits. - "sqrdmulh v0.8h, v20.8h, v31.8h \n" - "sqrdmulh v1.8h, v21.8h, v31.8h \n" - - // Align for table lookup, vtbl requires registers to be adjacent - "tbl v3.16b, {v0.16b, v1.16b, v2.16b}, v30.16b \n" - - "st1 {v3.8b}, [%1], #8 \n" - "st1 {v3.s}[2], [%1], #4 \n" - "b.gt 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(tmp_src_stride), // %2 - "+r"(src_ptr1), // %3 - "+r"(dst_width) // %4 - : "r"(&kMult38_Div6), // %5 - "r"(&kShuf38_2), // %6 - "r"(&kMult38_Div9) // %7 - : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18", - "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v29", "v30", "v31", - "memory", "cc"); + "sqrdmulh v24.8h, v24.8h, v30.8h \n" // v /= {9,9,6} + "sqrdmulh v25.8h, v4.8h, v30.8h \n" + "tbl v21.16b, {v24.16b, v25.16b}, v31.16b \n" // Narrow. + "st1 {v21.d}[0], [%[dst_ptr]], #8 \n" + "st1 {v21.s}[2], [%[dst_ptr]], #4 \n" + "b.gt 1b \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [src_ptr1] "+r"(src_ptr1), // %[src_ptr1] + [src_ptr2] "+r"(src_ptr2), // %[src_ptr2] + [width] "+r"(dst_width) // %[width] + : [div996] "r"(&kMult38_Div996), // %[div996] + [tblArray1] "r"(kScaleRowDown38_3_BoxIndices1), // %[tblArray1] + [tblArray2] "r"(kScaleRowDown38_3_BoxIndices2), // %[tblArray2] + [tblArray3] "r"(kScaleRowDown38_3_BoxIndices3), // %[tblArray3] + [tblArray4] "r"(kScaleRowDown38_NarrowIndices) // %[tblArray4] + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v20", "v21", "v22", + "v23", "v24", "v25", "v27", "v28", "v29", "v30", "v31"); } -// 32x2 -> 12x1 +static const uvec8 kScaleRowDown38_2_BoxIndices1[] = { + 0, 1, 3, 4, 6, 7, 8, 9, 11, 12, 14, 15, 255, 255, 255, 255}; +static const uvec8 kScaleRowDown38_2_BoxIndices2[] = { + 2, 18, 5, 21, 255, 255, 10, 26, 13, 29, 255, 255, 255, 255, 255, 255}; + void ScaleRowDown38_2_Box_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst_ptr, int dst_width) { - // TODO(fbarchard): use src_stride directly for clang 3.5+. - ptrdiff_t tmp_src_stride = src_stride; + const uint8_t* src_ptr1 = src_ptr + src_stride; asm volatile( - "ld1 {v30.8h}, [%4] \n" - "ld1 {v31.16b}, [%5] \n" - "add %2, %2, %0 \n" - "1: \n" + "ld1 {v28.16b}, [%[tblArray1]] \n" + "ld1 {v29.16b}, [%[tblArray2]] \n" + "ld1 {v31.16b}, [%[tblArray3]] \n" + "ld1 {v30.8h}, [%[div664]] \n" - // 00 40 01 41 02 42 03 43 - // 10 50 11 51 12 52 13 53 - // 20 60 21 61 22 62 23 63 - // 30 70 31 71 32 72 33 73 - "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" - "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%2], #32 \n" - "subs %w3, %w3, #12 \n" + "1: \n" + "ldp q20, q0, [%[src_ptr]], #32 \n" // abcdefgh ... + "ldp q21, q1, [%[src_ptr1]], #32 \n" // ijklmnop ... + "subs %w[width], %w[width], #12 \n" - // Shuffle the input data around to get align the data - // so adjacent data can be added. 0,1 - 2,3 - 4,5 - 6,7 - // 00 10 01 11 02 12 03 13 - // 40 50 41 51 42 52 43 53 - "trn1 v16.8b, v0.8b, v1.8b \n" - "trn2 v17.8b, v0.8b, v1.8b \n" - "trn1 v18.8b, v4.8b, v5.8b \n" - "trn2 v19.8b, v4.8b, v5.8b \n" + // Permute into groups of six values (three pairs) to be summed. + "tbl v22.16b, {v20.16b}, v28.16b \n" // abdegh ... + "tbl v2.16b, {v0.16b}, v28.16b \n" + "tbl v23.16b, {v21.16b}, v28.16b \n" // ijlmop ... + "tbl v3.16b, {v1.16b}, v28.16b \n" + "tbl v24.16b, {v20.16b, v21.16b}, v29.16b \n" // ckfn00 ... + "tbl v4.16b, {v0.16b, v1.16b}, v29.16b \n" - // 20 30 21 31 22 32 23 33 - // 60 70 61 71 62 72 63 73 - "trn1 v0.8b, v2.8b, v3.8b \n" - "trn2 v1.8b, v2.8b, v3.8b \n" - "trn1 v4.8b, v6.8b, v7.8b \n" - "trn2 v5.8b, v6.8b, v7.8b \n" + "uaddlp v22.8h, v22.16b \n" // a+b d+e g+h ... + "uaddlp v2.8h, v2.16b \n" + "uaddlp v23.8h, v23.16b \n" // i+j l+m o+p ... + "uaddlp v3.8h, v3.16b \n" + "uaddlp v24.8h, v24.16b \n" // c+k f+n 0 ... + "uaddlp v4.8h, v4.16b \n" + "add v20.8h, v22.8h, v23.8h \n" + "add v0.8h, v2.8h, v3.8h \n" + "add v21.8h, v20.8h, v24.8h \n" // a+b+i+j+c+k ... + "add v1.8h, v0.8h, v4.8h \n" - // 00+10 01+11 02+12 03+13 - // 40+50 41+51 42+52 43+53 - "uaddlp v16.4h, v16.8b \n" - "uaddlp v17.4h, v17.8b \n" - "uaddlp v18.4h, v18.8b \n" - "uaddlp v19.4h, v19.8b \n" + "sqrdmulh v21.8h, v21.8h, v30.8h \n" // v /= {6,6,4} + "sqrdmulh v22.8h, v1.8h, v30.8h \n" + "tbl v21.16b, {v21.16b, v22.16b}, v31.16b \n" // Narrow. + "st1 {v21.d}[0], [%[dst_ptr]], #8 \n" + "st1 {v21.s}[2], [%[dst_ptr]], #4 \n" + "b.gt 1b \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [src_ptr1] "+r"(src_ptr1), // %[src_ptr1] + [width] "+r"(dst_width) // %[width] + : [div664] "r"(&kMult38_Div664), // %[div664] + [tblArray1] "r"(kScaleRowDown38_2_BoxIndices1), // %[tblArray1] + [tblArray2] "r"(kScaleRowDown38_2_BoxIndices2), // %[tblArray2] + [tblArray3] "r"(kScaleRowDown38_NarrowIndices) // %[tblArray3] + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v20", "v21", "v22", + "v23", "v24", "v28", "v29", "v30", "v31"); +} - // 60+70 61+71 62+72 63+73 - "uaddlp v1.4h, v1.8b \n" - "uaddlp v5.4h, v5.8b \n" +void ScaleRowUp2_Linear_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* src_temp = src_ptr + 1; + asm volatile( + "movi v31.16b, #3 \n" - // combine source lines - "add v16.4h, v16.4h, v18.4h \n" - "add v17.4h, v17.4h, v19.4h \n" - "add v2.4h, v1.4h, v5.4h \n" + "1: \n" + "ldr q0, [%0], #16 \n" // 0123456789abcdef + "ldr q1, [%1], #16 \n" // 123456789abcdefg + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead - // dst_ptr[3] = (s[6] + s[7] + s[6+st] + s[7+st]) / 4 - "uqrshrn v2.8b, v2.8h, #2 \n" + "ushll v2.8h, v0.8b, #0 \n" // 01234567 (16b) + "ushll v3.8h, v1.8b, #0 \n" // 12345678 (16b) + "ushll2 v4.8h, v0.16b, #0 \n" // 89abcdef (16b) + "ushll2 v5.8h, v1.16b, #0 \n" // 9abcdefg (16b) - // Shuffle 2,3 reg around so that 2 can be added to the - // 0,1 reg and 3 can be added to the 4,5 reg. This - // requires expanding from u8 to u16 as the 0,1 and 4,5 - // registers are already expanded. Then do transposes - // to get aligned. - // xx 20 xx 30 xx 21 xx 31 xx 22 xx 32 xx 23 xx 33 + "umlal v2.8h, v1.8b, v31.8b \n" // 3*near+far (odd) + "umlal v3.8h, v0.8b, v31.8b \n" // 3*near+far (even) + "umlal2 v4.8h, v1.16b, v31.16b \n" // 3*near+far (odd) + "umlal2 v5.8h, v0.16b, v31.16b \n" // 3*near+far (even) - // combine source lines - "uaddl v0.8h, v0.8b, v4.8b \n" + "rshrn v2.8b, v2.8h, #2 \n" // 3/4*near+1/4*far (odd) + "rshrn v1.8b, v3.8h, #2 \n" // 3/4*near+1/4*far (even) + "rshrn2 v2.16b, v4.8h, #2 \n" // 3/4*near+1/4*far (odd) + "rshrn2 v1.16b, v5.8h, #2 \n" // 3/4*near+1/4*far (even) - // xx 20 xx 21 xx 22 xx 23 - // xx 30 xx 31 xx 32 xx 33 - "trn1 v1.8h, v0.8h, v0.8h \n" - "trn2 v4.8h, v0.8h, v0.8h \n" - "xtn v0.4h, v1.4s \n" - "xtn v4.4h, v4.4s \n" + "st2 {v1.16b, v2.16b}, [%2], #32 \n" + "subs %w3, %w3, #32 \n" + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_temp), // %1 + "+r"(dst_ptr), // %2 + "+r"(dst_width) // %3 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", + "v31" // Clobber List + ); +} - // 0+1+2, 3+4+5 - "add v16.8h, v16.8h, v0.8h \n" - "add v17.8h, v17.8h, v4.8h \n" +void ScaleRowUp2_Bilinear_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint8_t* src_ptr1 = src_ptr + src_stride; + uint8_t* dst_ptr1 = dst_ptr + dst_stride; + const uint8_t* src_temp = src_ptr + 1; + const uint8_t* src_temp1 = src_ptr1 + 1; - // Need to divide, but can't downshift as the the value - // isn't a power of 2. So multiply by 65536 / n - // and take the upper 16 bits. - "sqrdmulh v0.8h, v16.8h, v30.8h \n" - "sqrdmulh v1.8h, v17.8h, v30.8h \n" + asm volatile( + "movi v31.8b, #3 \n" + "movi v30.8h, #3 \n" - // Align for table lookup, vtbl requires registers to - // be adjacent + "1: \n" + "ldr d0, [%0], #8 \n" // 01234567 + "ldr d1, [%2], #8 \n" // 12345678 + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead - "tbl v3.16b, {v0.16b, v1.16b, v2.16b}, v31.16b \n" + "ushll v2.8h, v0.8b, #0 \n" // 01234567 (16b) + "ushll v3.8h, v1.8b, #0 \n" // 12345678 (16b) + "umlal v2.8h, v1.8b, v31.8b \n" // 3*near+far (1, odd) + "umlal v3.8h, v0.8b, v31.8b \n" // 3*near+far (1, even) - "st1 {v3.8b}, [%1], #8 \n" - "st1 {v3.s}[2], [%1], #4 \n" - "b.gt 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst_ptr), // %1 - "+r"(tmp_src_stride), // %2 - "+r"(dst_width) // %3 - : "r"(&kMult38_Div6), // %4 - "r"(&kShuf38_2) // %5 - : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18", - "v19", "v30", "v31", "memory", "cc"); + "ldr d0, [%1], #8 \n" + "ldr d1, [%3], #8 \n" + "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead + + "ushll v4.8h, v0.8b, #0 \n" // 01234567 (16b) + "ushll v5.8h, v1.8b, #0 \n" // 12345678 (16b) + "umlal v4.8h, v1.8b, v31.8b \n" // 3*near+far (2, odd) + "umlal v5.8h, v0.8b, v31.8b \n" // 3*near+far (2, even) + + "mov v0.16b, v4.16b \n" + "mov v1.16b, v5.16b \n" + "mla v4.8h, v2.8h, v30.8h \n" // 9 3 3 1 (1, odd) + "mla v5.8h, v3.8h, v30.8h \n" // 9 3 3 1 (1, even) + "mla v2.8h, v0.8h, v30.8h \n" // 9 3 3 1 (2, odd) + "mla v3.8h, v1.8h, v30.8h \n" // 9 3 3 1 (2, even) + + "rshrn v2.8b, v2.8h, #4 \n" // 2, odd + "rshrn v1.8b, v3.8h, #4 \n" // 2, even + "rshrn v4.8b, v4.8h, #4 \n" // 1, odd + "rshrn v3.8b, v5.8h, #4 \n" // 1, even + + "st2 {v1.8b, v2.8b}, [%5], #16 \n" // store 1 + "st2 {v3.8b, v4.8b}, [%4], #16 \n" // store 2 + "subs %w6, %w6, #16 \n" // 8 sample -> 16 sample + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_ptr1), // %1 + "+r"(src_temp), // %2 + "+r"(src_temp1), // %3 + "+r"(dst_ptr), // %4 + "+r"(dst_ptr1), // %5 + "+r"(dst_width) // %6 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v30", + "v31" // Clobber List + ); +} + +void ScaleRowUp2_Linear_12_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + const uint16_t* src_temp = src_ptr + 1; + asm volatile( + "movi v31.8h, #3 \n" + + "1: \n" + "ld1 {v0.8h}, [%0], #16 \n" // 01234567 (16b) + "ld1 {v1.8h}, [%1], #16 \n" // 12345678 (16b) + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + + "mov v2.16b, v0.16b \n" + "mla v0.8h, v1.8h, v31.8h \n" // 3*near+far (odd) + "mla v1.8h, v2.8h, v31.8h \n" // 3*near+far (even) + + "urshr v2.8h, v0.8h, #2 \n" // 3/4*near+1/4*far (odd) + "urshr v1.8h, v1.8h, #2 \n" // 3/4*near+1/4*far (even) + + "st2 {v1.8h, v2.8h}, [%2], #32 \n" // store + "subs %w3, %w3, #16 \n" // 8 sample -> 16 sample + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_temp), // %1 + "+r"(dst_ptr), // %2 + "+r"(dst_width) // %3 + : + : "memory", "cc", "v0", "v1", "v2", "v31" // Clobber List + ); +} + +void ScaleRowUp2_Bilinear_12_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint16_t* src_ptr1 = src_ptr + src_stride; + uint16_t* dst_ptr1 = dst_ptr + dst_stride; + const uint16_t* src_temp = src_ptr + 1; + const uint16_t* src_temp1 = src_ptr1 + 1; + + asm volatile( + "movi v31.8h, #3 \n" + + "1: \n" + "ld1 {v2.8h}, [%0], #16 \n" // 01234567 (16b) + "ld1 {v3.8h}, [%2], #16 \n" // 12345678 (16b) + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + + "mov v0.16b, v2.16b \n" + "mla v2.8h, v3.8h, v31.8h \n" // 3*near+far (odd) + "mla v3.8h, v0.8h, v31.8h \n" // 3*near+far (even) + + "ld1 {v4.8h}, [%1], #16 \n" // 01234567 (16b) + "ld1 {v5.8h}, [%3], #16 \n" // 12345678 (16b) + "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead + + "mov v0.16b, v4.16b \n" + "mla v4.8h, v5.8h, v31.8h \n" // 3*near+far (odd) + "mla v5.8h, v0.8h, v31.8h \n" // 3*near+far (even) + + "mov v0.16b, v4.16b \n" + "mov v1.16b, v5.16b \n" + "mla v4.8h, v2.8h, v31.8h \n" // 9 3 3 1 (1, odd) + "mla v5.8h, v3.8h, v31.8h \n" // 9 3 3 1 (1, even) + "mla v2.8h, v0.8h, v31.8h \n" // 9 3 3 1 (2, odd) + "mla v3.8h, v1.8h, v31.8h \n" // 9 3 3 1 (2, even) + + "urshr v2.8h, v2.8h, #4 \n" // 2, odd + "urshr v1.8h, v3.8h, #4 \n" // 2, even + "urshr v4.8h, v4.8h, #4 \n" // 1, odd + "urshr v3.8h, v5.8h, #4 \n" // 1, even + + "st2 {v3.8h, v4.8h}, [%4], #32 \n" // store 1 + "st2 {v1.8h, v2.8h}, [%5], #32 \n" // store 2 + + "subs %w6, %w6, #16 \n" // 8 sample -> 16 sample + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_ptr1), // %1 + "+r"(src_temp), // %2 + "+r"(src_temp1), // %3 + "+r"(dst_ptr), // %4 + "+r"(dst_ptr1), // %5 + "+r"(dst_width) // %6 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", + "v31" // Clobber List + ); +} + +void ScaleRowUp2_Linear_16_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + const uint16_t* src_temp = src_ptr + 1; + asm volatile( + "movi v31.8h, #3 \n" + + "1: \n" + "ld1 {v0.8h}, [%0], #16 \n" // 01234567 (16b) + "ld1 {v1.8h}, [%1], #16 \n" // 12345678 (16b) + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + + "ushll v2.4s, v0.4h, #0 \n" // 0123 (32b) + "ushll2 v3.4s, v0.8h, #0 \n" // 4567 (32b) + "ushll v4.4s, v1.4h, #0 \n" // 1234 (32b) + "ushll2 v5.4s, v1.8h, #0 \n" // 5678 (32b) + + "umlal v2.4s, v1.4h, v31.4h \n" // 3*near+far (1, odd) + "umlal2 v3.4s, v1.8h, v31.8h \n" // 3*near+far (2, odd) + "umlal v4.4s, v0.4h, v31.4h \n" // 3*near+far (1, even) + "umlal2 v5.4s, v0.8h, v31.8h \n" // 3*near+far (2, even) + + "rshrn v0.4h, v4.4s, #2 \n" // 3/4*near+1/4*far + "rshrn2 v0.8h, v5.4s, #2 \n" // 3/4*near+1/4*far (even) + "rshrn v1.4h, v2.4s, #2 \n" // 3/4*near+1/4*far + "rshrn2 v1.8h, v3.4s, #2 \n" // 3/4*near+1/4*far (odd) + + "st2 {v0.8h, v1.8h}, [%2], #32 \n" // store + "subs %w3, %w3, #16 \n" // 8 sample -> 16 sample + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_temp), // %1 + "+r"(dst_ptr), // %2 + "+r"(dst_width) // %3 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v31" // Clobber List + ); +} + +void ScaleRowUp2_Bilinear_16_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint16_t* src_ptr1 = src_ptr + src_stride; + uint16_t* dst_ptr1 = dst_ptr + dst_stride; + const uint16_t* src_temp = src_ptr + 1; + const uint16_t* src_temp1 = src_ptr1 + 1; + + asm volatile( + "movi v31.4h, #3 \n" + "movi v30.4s, #3 \n" + + "1: \n" + "ldr d0, [%0], #8 \n" // 0123 (16b) + "ldr d1, [%2], #8 \n" // 1234 (16b) + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "ushll v2.4s, v0.4h, #0 \n" // 0123 (32b) + "ushll v3.4s, v1.4h, #0 \n" // 1234 (32b) + "umlal v2.4s, v1.4h, v31.4h \n" // 3*near+far (1, odd) + "umlal v3.4s, v0.4h, v31.4h \n" // 3*near+far (1, even) + + "ldr d0, [%1], #8 \n" // 0123 (16b) + "ldr d1, [%3], #8 \n" // 1234 (16b) + "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead + "ushll v4.4s, v0.4h, #0 \n" // 0123 (32b) + "ushll v5.4s, v1.4h, #0 \n" // 1234 (32b) + "umlal v4.4s, v1.4h, v31.4h \n" // 3*near+far (2, odd) + "umlal v5.4s, v0.4h, v31.4h \n" // 3*near+far (2, even) + + "mov v0.16b, v4.16b \n" + "mov v1.16b, v5.16b \n" + "mla v4.4s, v2.4s, v30.4s \n" // 9 3 3 1 (1, odd) + "mla v5.4s, v3.4s, v30.4s \n" // 9 3 3 1 (1, even) + "mla v2.4s, v0.4s, v30.4s \n" // 9 3 3 1 (2, odd) + "mla v3.4s, v1.4s, v30.4s \n" // 9 3 3 1 (2, even) + + "rshrn v1.4h, v4.4s, #4 \n" // 3/4*near+1/4*far + "rshrn v0.4h, v5.4s, #4 \n" // 3/4*near+1/4*far + "rshrn v5.4h, v2.4s, #4 \n" // 3/4*near+1/4*far + "rshrn v4.4h, v3.4s, #4 \n" // 3/4*near+1/4*far + + "st2 {v0.4h, v1.4h}, [%4], #16 \n" // store 1 + "st2 {v4.4h, v5.4h}, [%5], #16 \n" // store 2 + + "subs %w6, %w6, #8 \n" // 4 sample -> 8 sample + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_ptr1), // %1 + "+r"(src_temp), // %2 + "+r"(src_temp1), // %3 + "+r"(dst_ptr), // %4 + "+r"(dst_ptr1), // %5 + "+r"(dst_width) // %6 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v30", + "v31" // Clobber List + ); +} + +void ScaleUVRowUp2_Linear_NEON(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* src_temp = src_ptr + 2; + asm volatile( + "movi v31.8b, #3 \n" + + "1: \n" + "ldr d0, [%0], #8 \n" // 00112233 (1u1v) + "ldr d1, [%1], #8 \n" // 11223344 (1u1v) + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + + "ushll v2.8h, v0.8b, #0 \n" // 00112233 (1u1v, 16b) + "ushll v3.8h, v1.8b, #0 \n" // 11223344 (1u1v, 16b) + + "umlal v2.8h, v1.8b, v31.8b \n" // 3*near+far (odd) + "umlal v3.8h, v0.8b, v31.8b \n" // 3*near+far (even) + + "rshrn v2.8b, v2.8h, #2 \n" // 3/4*near+1/4*far (odd) + "rshrn v1.8b, v3.8h, #2 \n" // 3/4*near+1/4*far (even) + + "st2 {v1.4h, v2.4h}, [%2], #16 \n" // store + "subs %w3, %w3, #8 \n" // 4 uv -> 8 uv + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_temp), // %1 + "+r"(dst_ptr), // %2 + "+r"(dst_width) // %3 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v31" // Clobber List + ); +} + +void ScaleUVRowUp2_Bilinear_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint8_t* src_ptr1 = src_ptr + src_stride; + uint8_t* dst_ptr1 = dst_ptr + dst_stride; + const uint8_t* src_temp = src_ptr + 2; + const uint8_t* src_temp1 = src_ptr1 + 2; + + asm volatile( + "movi v31.8b, #3 \n" + "movi v30.8h, #3 \n" + + "1: \n" + "ldr d0, [%0], #8 \n" + "ldr d1, [%2], #8 \n" + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + + "ushll v2.8h, v0.8b, #0 \n" + "ushll v3.8h, v1.8b, #0 \n" + "umlal v2.8h, v1.8b, v31.8b \n" // 3*near+far (1, odd) + "umlal v3.8h, v0.8b, v31.8b \n" // 3*near+far (1, even) + + "ldr d0, [%1], #8 \n" + "ldr d1, [%3], #8 \n" + "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead + + "ushll v4.8h, v0.8b, #0 \n" + "ushll v5.8h, v1.8b, #0 \n" + "umlal v4.8h, v1.8b, v31.8b \n" // 3*near+far (2, odd) + "umlal v5.8h, v0.8b, v31.8b \n" // 3*near+far (2, even) + + "mov v0.16b, v4.16b \n" + "mov v1.16b, v5.16b \n" + "mla v4.8h, v2.8h, v30.8h \n" // 9 3 3 1 (1, odd) + "mla v5.8h, v3.8h, v30.8h \n" // 9 3 3 1 (1, even) + "mla v2.8h, v0.8h, v30.8h \n" // 9 3 3 1 (2, odd) + "mla v3.8h, v1.8h, v30.8h \n" // 9 3 3 1 (2, even) + + "rshrn v2.8b, v2.8h, #4 \n" // 2, odd + "rshrn v1.8b, v3.8h, #4 \n" // 2, even + "rshrn v4.8b, v4.8h, #4 \n" // 1, odd + "rshrn v3.8b, v5.8h, #4 \n" // 1, even + + "st2 {v1.4h, v2.4h}, [%5], #16 \n" // store 2 + "st2 {v3.4h, v4.4h}, [%4], #16 \n" // store 1 + "subs %w6, %w6, #8 \n" // 4 uv -> 8 uv + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_ptr1), // %1 + "+r"(src_temp), // %2 + "+r"(src_temp1), // %3 + "+r"(dst_ptr), // %4 + "+r"(dst_ptr1), // %5 + "+r"(dst_width) // %6 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v30", + "v31" // Clobber List + ); +} + +void ScaleUVRowUp2_Linear_16_NEON(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + const uint16_t* src_temp = src_ptr + 2; + asm volatile( + "movi v31.8h, #3 \n" + + "1: \n" + "ld1 {v0.8h}, [%0], #16 \n" // 01234567 (16b) + "ld1 {v1.8h}, [%1], #16 \n" // 12345678 (16b) + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + + "ushll v2.4s, v0.4h, #0 \n" // 0011 (1u1v, 32b) + "ushll v3.4s, v1.4h, #0 \n" // 1122 (1u1v, 32b) + "ushll2 v4.4s, v0.8h, #0 \n" // 2233 (1u1v, 32b) + "ushll2 v5.4s, v1.8h, #0 \n" // 3344 (1u1v, 32b) + + "umlal v2.4s, v1.4h, v31.4h \n" // 3*near+far (odd) + "umlal v3.4s, v0.4h, v31.4h \n" // 3*near+far (even) + "umlal2 v4.4s, v1.8h, v31.8h \n" // 3*near+far (odd) + "umlal2 v5.4s, v0.8h, v31.8h \n" // 3*near+far (even) + + "rshrn v2.4h, v2.4s, #2 \n" // 3/4*near+1/4*far (odd) + "rshrn v1.4h, v3.4s, #2 \n" // 3/4*near+1/4*far (even) + "rshrn v4.4h, v4.4s, #2 \n" // 3/4*near+1/4*far (odd) + "rshrn v3.4h, v5.4s, #2 \n" // 3/4*near+1/4*far (even) + + "st2 {v1.2s, v2.2s}, [%2], #16 \n" // store + "st2 {v3.2s, v4.2s}, [%2], #16 \n" // store + "subs %w3, %w3, #8 \n" // 4 uv -> 8 uv + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_temp), // %1 + "+r"(dst_ptr), // %2 + "+r"(dst_width) // %3 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", + "v31" // Clobber List + ); +} + +void ScaleUVRowUp2_Bilinear_16_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const uint16_t* src_ptr1 = src_ptr + src_stride; + uint16_t* dst_ptr1 = dst_ptr + dst_stride; + const uint16_t* src_temp = src_ptr + 2; + const uint16_t* src_temp1 = src_ptr1 + 2; + + asm volatile( + "movi v31.4h, #3 \n" + "movi v30.4s, #3 \n" + + "1: \n" + "ldr d0, [%0], #8 \n" + "ldr d1, [%2], #8 \n" + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "ushll v2.4s, v0.4h, #0 \n" // 0011 (1u1v, 32b) + "ushll v3.4s, v1.4h, #0 \n" // 1122 (1u1v, 32b) + "umlal v2.4s, v1.4h, v31.4h \n" // 3*near+far (1, odd) + "umlal v3.4s, v0.4h, v31.4h \n" // 3*near+far (1, even) + + "ldr d0, [%1], #8 \n" + "ldr d1, [%3], #8 \n" + "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead + "ushll v4.4s, v0.4h, #0 \n" // 0011 (1u1v, 32b) + "ushll v5.4s, v1.4h, #0 \n" // 1122 (1u1v, 32b) + "umlal v4.4s, v1.4h, v31.4h \n" // 3*near+far (2, odd) + "umlal v5.4s, v0.4h, v31.4h \n" // 3*near+far (2, even) + + "mov v0.16b, v4.16b \n" + "mov v1.16b, v5.16b \n" + "mla v4.4s, v2.4s, v30.4s \n" // 9 3 3 1 (1, odd) + "mla v5.4s, v3.4s, v30.4s \n" // 9 3 3 1 (1, even) + "mla v2.4s, v0.4s, v30.4s \n" // 9 3 3 1 (2, odd) + "mla v3.4s, v1.4s, v30.4s \n" // 9 3 3 1 (2, even) + + "rshrn v1.4h, v2.4s, #4 \n" // 2, odd + "rshrn v0.4h, v3.4s, #4 \n" // 2, even + "rshrn v3.4h, v4.4s, #4 \n" // 1, odd + "rshrn v2.4h, v5.4s, #4 \n" // 1, even + + "st2 {v0.2s, v1.2s}, [%5], #16 \n" // store 2 + "st2 {v2.2s, v3.2s}, [%4], #16 \n" // store 1 + "subs %w6, %w6, #4 \n" // 2 uv -> 4 uv + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src_ptr1), // %1 + "+r"(src_temp), // %2 + "+r"(src_temp1), // %3 + "+r"(dst_ptr), // %4 + "+r"(dst_ptr1), // %5 + "+r"(dst_width) // %6 + : + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v30", + "v31" // Clobber List + ); } // Add a row of bytes to a row of shorts. Used for box filter. @@ -521,14 +995,15 @@ void ScaleAddRow_NEON(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width) { asm volatile( - "1: \n" - "ld1 {v1.8h, v2.8h}, [%1] \n" // load accumulator - "ld1 {v0.16b}, [%0], #16 \n" // load 16 bytes - "uaddw2 v2.8h, v2.8h, v0.16b \n" // add - "uaddw v1.8h, v1.8h, v0.8b \n" - "st1 {v1.8h, v2.8h}, [%1], #32 \n" // store accumulator - "subs %w2, %w2, #16 \n" // 16 processed per loop - "b.gt 1b \n" + "1: \n" + "ld1 {v1.8h, v2.8h}, [%1] \n" // load accumulator + "ld1 {v0.16b}, [%0], #16 \n" // load 16 bytes + "uaddw2 v2.8h, v2.8h, v0.16b \n" // add + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "uaddw v1.8h, v1.8h, v0.8b \n" + "st1 {v1.8h, v2.8h}, [%1], #32 \n" // store accumulator + "subs %w2, %w2, #16 \n" // 16 processed per loop + "b.gt 1b \n" : "+r"(src_ptr), // %0 "+r"(dst_ptr), // %1 "+r"(src_width) // %2 @@ -537,15 +1012,12 @@ void ScaleAddRow_NEON(const uint8_t* src_ptr, ); } -// TODO(Yang Zhang): Investigate less load instructions for -// the x/dx stepping -#define LOAD2_DATA8_LANE(n) \ - "lsr %5, %3, #16 \n" \ - "add %6, %1, %5 \n" \ - "add %3, %3, %4 \n" \ - "ld2 {v4.b, v5.b}[" #n "], [%6] \n" +#define SCALE_FILTER_COLS_STEP_ADDR \ + "sbfx %[tmp_offset], %x[x], #16, #16 \n" \ + "add %[tmp_ptr], %[src_ptr], %[tmp_offset] \n" \ + "add %w[x], %w[x], %w[dx] \n" -// The NEON version mimics this formula (from row_common.cc): +// The Neon version mimics this formula (from scale_common.cc): // #define BLENDER(a, b, f) (uint8_t)((int)(a) + // ((((int)((f)) * ((int)(b) - (int)(a))) + 0x8000) >> 16)) @@ -555,171 +1027,89 @@ void ScaleFilterCols_NEON(uint8_t* dst_ptr, int x, int dx) { int dx_offset[4] = {0, 1, 2, 3}; - int* tmp = dx_offset; - const uint8_t* src_tmp = src_ptr; - int64_t x64 = (int64_t)x; // NOLINT - int64_t dx64 = (int64_t)dx; // NOLINT - asm volatile ( - "dup v0.4s, %w3 \n" // x - "dup v1.4s, %w4 \n" // dx - "ld1 {v2.4s}, [%5] \n" // 0 1 2 3 - "shl v3.4s, v1.4s, #2 \n" // 4 * dx - "mul v1.4s, v1.4s, v2.4s \n" - // x , x + 1 * dx, x + 2 * dx, x + 3 * dx - "add v1.4s, v1.4s, v0.4s \n" - // x + 4 * dx, x + 5 * dx, x + 6 * dx, x + 7 * dx - "add v2.4s, v1.4s, v3.4s \n" - "shl v0.4s, v3.4s, #1 \n" // 8 * dx - "1: \n" - LOAD2_DATA8_LANE(0) - LOAD2_DATA8_LANE(1) - LOAD2_DATA8_LANE(2) - LOAD2_DATA8_LANE(3) - LOAD2_DATA8_LANE(4) - LOAD2_DATA8_LANE(5) - LOAD2_DATA8_LANE(6) - LOAD2_DATA8_LANE(7) - "mov v6.16b, v1.16b \n" - "mov v7.16b, v2.16b \n" - "uzp1 v6.8h, v6.8h, v7.8h \n" - "ushll v4.8h, v4.8b, #0 \n" - "ushll v5.8h, v5.8b, #0 \n" - "ssubl v16.4s, v5.4h, v4.4h \n" - "ssubl2 v17.4s, v5.8h, v4.8h \n" - "ushll v7.4s, v6.4h, #0 \n" - "ushll2 v6.4s, v6.8h, #0 \n" - "mul v16.4s, v16.4s, v7.4s \n" - "mul v17.4s, v17.4s, v6.4s \n" - "rshrn v6.4h, v16.4s, #16 \n" - "rshrn2 v6.8h, v17.4s, #16 \n" - "add v4.8h, v4.8h, v6.8h \n" - "xtn v4.8b, v4.8h \n" - - "st1 {v4.8b}, [%0], #8 \n" // store pixels - "add v1.4s, v1.4s, v0.4s \n" - "add v2.4s, v2.4s, v0.4s \n" - "subs %w2, %w2, #8 \n" // 8 processed per loop - "b.gt 1b \n" - : "+r"(dst_ptr), // %0 - "+r"(src_ptr), // %1 - "+r"(dst_width), // %2 - "+r"(x64), // %3 - "+r"(dx64), // %4 - "+r"(tmp), // %5 - "+r"(src_tmp) // %6 - : - : "memory", "cc", "v0", "v1", "v2", "v3", - "v4", "v5", "v6", "v7", "v16", "v17" - ); -} - -#undef LOAD2_DATA8_LANE - -// 16x2 -> 16x1 -void ScaleFilterRows_NEON(uint8_t* dst_ptr, - const uint8_t* src_ptr, - ptrdiff_t src_stride, - int dst_width, - int source_y_fraction) { - int y_fraction = 256 - source_y_fraction; + int64_t tmp_offset; + uint8_t* tmp_ptr; asm volatile( - "cmp %w4, #0 \n" - "b.eq 100f \n" - "add %2, %2, %1 \n" - "cmp %w4, #64 \n" - "b.eq 75f \n" - "cmp %w4, #128 \n" - "b.eq 50f \n" - "cmp %w4, #192 \n" - "b.eq 25f \n" + "dup v0.4s, %w[x] \n" + "dup v1.4s, %w[dx] \n" + "ld1 {v2.4s}, [%[dx_offset]] \n" // 0 1 2 3 + "shl v3.4s, v1.4s, #2 \n" // 4 * dx + "shl v22.4s, v1.4s, #3 \n" // 8 * dx - "dup v5.8b, %w4 \n" - "dup v4.8b, %w5 \n" - // General purpose row blend. - "1: \n" - "ld1 {v0.16b}, [%1], #16 \n" - "ld1 {v1.16b}, [%2], #16 \n" - "subs %w3, %w3, #16 \n" - "umull v6.8h, v0.8b, v4.8b \n" - "umull2 v7.8h, v0.16b, v4.16b \n" - "umlal v6.8h, v1.8b, v5.8b \n" - "umlal2 v7.8h, v1.16b, v5.16b \n" - "rshrn v0.8b, v6.8h, #8 \n" - "rshrn2 v0.16b, v7.8h, #8 \n" - "st1 {v0.16b}, [%0], #16 \n" - "b.gt 1b \n" - "b 99f \n" + "mul v1.4s, v1.4s, v2.4s \n" + // x , x + 1 * dx, x + 2 * dx, x + 3 * dx + "add v1.4s, v1.4s, v0.4s \n" + // x + 4 * dx, x + 5 * dx, x + 6 * dx, x + 7 * dx + "add v2.4s, v1.4s, v3.4s \n" - // Blend 25 / 75. - "25: \n" - "ld1 {v0.16b}, [%1], #16 \n" - "ld1 {v1.16b}, [%2], #16 \n" - "subs %w3, %w3, #16 \n" - "urhadd v0.16b, v0.16b, v1.16b \n" - "urhadd v0.16b, v0.16b, v1.16b \n" - "st1 {v0.16b}, [%0], #16 \n" - "b.gt 25b \n" - "b 99f \n" + "movi v0.8h, #0 \n" - // Blend 50 / 50. - "50: \n" - "ld1 {v0.16b}, [%1], #16 \n" - "ld1 {v1.16b}, [%2], #16 \n" - "subs %w3, %w3, #16 \n" - "urhadd v0.16b, v0.16b, v1.16b \n" - "st1 {v0.16b}, [%0], #16 \n" - "b.gt 50b \n" - "b 99f \n" + // truncate to uint16_t + "trn1 v22.8h, v22.8h, v0.8h \n" + "trn1 v20.8h, v1.8h, v0.8h \n" + "trn1 v21.8h, v2.8h, v0.8h \n" - // Blend 75 / 25. - "75: \n" - "ld1 {v1.16b}, [%1], #16 \n" - "ld1 {v0.16b}, [%2], #16 \n" - "subs %w3, %w3, #16 \n" - "urhadd v0.16b, v0.16b, v1.16b \n" - "urhadd v0.16b, v0.16b, v1.16b \n" - "st1 {v0.16b}, [%0], #16 \n" - "b.gt 75b \n" - "b 99f \n" + "1: \n" SCALE_FILTER_COLS_STEP_ADDR + "ldr h6, [%[tmp_ptr]] \n" SCALE_FILTER_COLS_STEP_ADDR + "ld1 {v6.h}[1], [%[tmp_ptr]] \n" SCALE_FILTER_COLS_STEP_ADDR + "ld1 {v6.h}[2], [%[tmp_ptr]] \n" SCALE_FILTER_COLS_STEP_ADDR + "ld1 {v6.h}[3], [%[tmp_ptr]] \n" SCALE_FILTER_COLS_STEP_ADDR + "ld1 {v6.h}[4], [%[tmp_ptr]] \n" SCALE_FILTER_COLS_STEP_ADDR + "ld1 {v6.h}[5], [%[tmp_ptr]] \n" SCALE_FILTER_COLS_STEP_ADDR + "ld1 {v6.h}[6], [%[tmp_ptr]] \n" SCALE_FILTER_COLS_STEP_ADDR + "ld1 {v6.h}[7], [%[tmp_ptr]] \n" - // Blend 100 / 0 - Copy row unchanged. - "100: \n" - "ld1 {v0.16b}, [%1], #16 \n" - "subs %w3, %w3, #16 \n" - "st1 {v0.16b}, [%0], #16 \n" - "b.gt 100b \n" + "subs %w[width], %w[width], #8 \n" // 8 processed per loop + "trn1 v4.16b, v6.16b, v0.16b \n" + "trn2 v5.16b, v6.16b, v0.16b \n" - "99: \n" - "st1 {v0.b}[15], [%0] \n" - : "+r"(dst_ptr), // %0 - "+r"(src_ptr), // %1 - "+r"(src_stride), // %2 - "+r"(dst_width), // %3 - "+r"(source_y_fraction), // %4 - "+r"(y_fraction) // %5 - : - : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "memory", "cc"); + "ssubl v16.4s, v5.4h, v4.4h \n" + "ssubl2 v17.4s, v5.8h, v4.8h \n" + "mul v16.4s, v16.4s, v20.4s \n" + "mul v17.4s, v17.4s, v21.4s \n" + "rshrn v6.4h, v16.4s, #16 \n" + "rshrn2 v6.8h, v17.4s, #16 \n" + "add v4.8h, v4.8h, v6.8h \n" + "xtn v4.8b, v4.8h \n" + + "add v20.8h, v20.8h, v22.8h \n" + "add v21.8h, v21.8h, v22.8h \n" + + "st1 {v4.8b}, [%[dst_ptr]], #8 \n" // store pixels + "b.gt 1b \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [width] "+r"(dst_width), // %[width] + [x] "+r"(x), // %[x] + [dx] "+r"(dx), // %[dx] + [tmp_offset] "=&r"(tmp_offset), // %[tmp_offset] + [tmp_ptr] "=&r"(tmp_ptr) // %[tmp_ptr] + : [dx_offset] "r"(dx_offset) // %[dx_offset] + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v16", "v17", + "v20", "v21", "v22"); } +#undef SCALE_FILTER_COLS_STEP_ADDR + void ScaleARGBRowDown2_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width) { (void)src_stride; asm volatile( - "1: \n" - // load 16 ARGB pixels with even pixels into q0/q2, odd into q1/q3 - "ld4 {v0.4s,v1.4s,v2.4s,v3.4s}, [%0], #64 \n" - "subs %w2, %w2, #8 \n" // 8 processed per loop - "mov v2.16b, v3.16b \n" - "st2 {v1.4s,v2.4s}, [%1], #32 \n" // store 8 odd pixels - "b.gt 1b \n" - : "+r"(src_ptr), // %0 - "+r"(dst), // %1 - "+r"(dst_width) // %2 + "1: \n" + "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%[src]], #64 \n" + "subs %w[width], %w[width], #8 \n" + "prfm pldl1keep, [%[src], 448] \n" + "uzp2 v0.4s, v0.4s, v1.4s \n" + "uzp2 v1.4s, v2.4s, v3.4s \n" + "st1 {v0.4s, v1.4s}, [%[dst]], #32 \n" + "b.gt 1b \n" + : [src] "+r"(src_ptr), // %[src] + [dst] "+r"(dst), // %[dst] + [width] "+r"(dst_width) // %[width] : - : "memory", "cc", "v0", "v1", "v2", "v3" // Clobber List - ); + : "memory", "cc", "v0", "v1", "v2", "v3"); } void ScaleARGBRowDown2Linear_NEON(const uint8_t* src_argb, @@ -727,79 +1117,79 @@ void ScaleARGBRowDown2Linear_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int dst_width) { (void)src_stride; + const uint8_t* src_argb1 = src_argb + 32; asm volatile( - "1: \n" - // load 16 ARGB pixels with even pixels into q0/q2, odd into q1/q3 - "ld4 {v0.4s,v1.4s,v2.4s,v3.4s}, [%0], #64 \n" - "subs %w2, %w2, #8 \n" // 8 processed per loop - - "urhadd v0.16b, v0.16b, v1.16b \n" // rounding half add - "urhadd v1.16b, v2.16b, v3.16b \n" - "st2 {v0.4s,v1.4s}, [%1], #32 \n" // store 8 pixels - "b.gt 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_argb), // %1 - "+r"(dst_width) // %2 + "1: \n" + "ld2 {v0.4s, v1.4s}, [%[src]] \n" + "add %[src], %[src], #64 \n" + "ld2 {v2.4s, v3.4s}, [%[src1]] \n" + "add %[src1], %[src1], #64 \n" + "urhadd v0.16b, v0.16b, v1.16b \n" + "urhadd v1.16b, v2.16b, v3.16b \n" + "subs %w[width], %w[width], #8 \n" + "st1 {v0.16b, v1.16b}, [%[dst]], #32 \n" + "b.gt 1b \n" + : [src] "+r"(src_argb), // %[src] + [src1] "+r"(src_argb1), // %[src1] + [dst] "+r"(dst_argb), // %[dst] + [width] "+r"(dst_width) // %[width] : - : "memory", "cc", "v0", "v1", "v2", "v3" // Clobber List - ); + : "memory", "cc", "v0", "v1", "v2", "v3"); } void ScaleARGBRowDown2Box_NEON(const uint8_t* src_ptr, ptrdiff_t src_stride, uint8_t* dst, int dst_width) { + const uint8_t* src_ptr1 = src_ptr + src_stride; asm volatile( - // change the stride to row 2 pointer - "add %1, %1, %0 \n" - "1: \n" - "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 8 ARGB - "subs %w3, %w3, #8 \n" // 8 processed per loop. - "uaddlp v0.8h, v0.16b \n" // B 16 bytes -> 8 shorts. - "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts. - "uaddlp v2.8h, v2.16b \n" // R 16 bytes -> 8 shorts. - "uaddlp v3.8h, v3.16b \n" // A 16 bytes -> 8 shorts. - "ld4 {v16.16b,v17.16b,v18.16b,v19.16b}, [%1], #64 \n" // load 8 - "uadalp v0.8h, v16.16b \n" // B 16 bytes -> 8 shorts. - "uadalp v1.8h, v17.16b \n" // G 16 bytes -> 8 shorts. - "uadalp v2.8h, v18.16b \n" // R 16 bytes -> 8 shorts. - "uadalp v3.8h, v19.16b \n" // A 16 bytes -> 8 shorts. - "rshrn v0.8b, v0.8h, #2 \n" // round and pack - "rshrn v1.8b, v1.8h, #2 \n" - "rshrn v2.8b, v2.8h, #2 \n" - "rshrn v3.8b, v3.8h, #2 \n" - "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" - "b.gt 1b \n" - : "+r"(src_ptr), // %0 - "+r"(src_stride), // %1 - "+r"(dst), // %2 - "+r"(dst_width) // %3 + "1: \n" + "ld2 {v0.4s, v1.4s}, [%[src]], #32 \n" + "ld2 {v20.4s, v21.4s}, [%[src1]], #32 \n" + "uaddl v2.8h, v0.8b, v1.8b \n" + "uaddl2 v3.8h, v0.16b, v1.16b \n" + "uaddl v22.8h, v20.8b, v21.8b \n" + "uaddl2 v23.8h, v20.16b, v21.16b \n" + "add v0.8h, v2.8h, v22.8h \n" + "add v1.8h, v3.8h, v23.8h \n" + "rshrn v0.8b, v0.8h, #2 \n" + "rshrn v1.8b, v1.8h, #2 \n" + "subs %w[width], %w[width], #4 \n" + "stp d0, d1, [%[dst]], #16 \n" + "b.gt 1b \n" + : [src] "+r"(src_ptr), [src1] "+r"(src_ptr1), [dst] "+r"(dst), + [width] "+r"(dst_width) : - : "memory", "cc", "v0", "v1", "v2", "v3", "v16", "v17", "v18", "v19"); + : "memory", "cc", "v0", "v1", "v2", "v3", "v20", "v21", "v22", "v23"); } -// Reads 4 pixels at a time. -// Alignment requirement: src_argb 4 byte aligned. void ScaleARGBRowDownEven_NEON(const uint8_t* src_argb, ptrdiff_t src_stride, int src_stepx, uint8_t* dst_argb, int dst_width) { + const uint8_t* src_argb1 = src_argb + src_stepx * 4; + const uint8_t* src_argb2 = src_argb + src_stepx * 8; + const uint8_t* src_argb3 = src_argb + src_stepx * 12; + int64_t i = 0; (void)src_stride; asm volatile( - "1: \n" - "ld1 {v0.s}[0], [%0], %3 \n" - "ld1 {v0.s}[1], [%0], %3 \n" - "ld1 {v0.s}[2], [%0], %3 \n" - "ld1 {v0.s}[3], [%0], %3 \n" - "subs %w2, %w2, #4 \n" // 4 pixels per loop. - "st1 {v0.16b}, [%1], #16 \n" - "b.gt 1b \n" - : "+r"(src_argb), // %0 - "+r"(dst_argb), // %1 - "+r"(dst_width) // %2 - : "r"((int64_t)(src_stepx * 4)) // %3 - : "memory", "cc", "v0"); + "1: \n" + "ldr w10, [%[src], %[i]] \n" + "ldr w11, [%[src1], %[i]] \n" + "ldr w12, [%[src2], %[i]] \n" + "ldr w13, [%[src3], %[i]] \n" + "add %[i], %[i], %[step] \n" + "subs %w[width], %w[width], #4 \n" + "prfm pldl1keep, [%[src], 448] \n" + "stp w10, w11, [%[dst]], #8 \n" + "stp w12, w13, [%[dst]], #8 \n" + "b.gt 1b \n" + : [src] "+r"(src_argb), [src1] "+r"(src_argb1), [src2] "+r"(src_argb2), + [src3] "+r"(src_argb3), [dst] "+r"(dst_argb), [width] "+r"(dst_width), + [i] "+r"(i) + : [step] "r"((int64_t)(src_stepx * 16)) + : "memory", "cc", "w10", "w11", "w12", "w13"); } // Reads 4 pixels at a time. @@ -812,39 +1202,39 @@ void ScaleARGBRowDownEvenBox_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int dst_width) { asm volatile( - "add %1, %1, %0 \n" - "1: \n" - "ld1 {v0.8b}, [%0], %4 \n" // Read 4 2x2 -> 2x1 - "ld1 {v1.8b}, [%1], %4 \n" - "ld1 {v2.8b}, [%0], %4 \n" - "ld1 {v3.8b}, [%1], %4 \n" - "ld1 {v4.8b}, [%0], %4 \n" - "ld1 {v5.8b}, [%1], %4 \n" - "ld1 {v6.8b}, [%0], %4 \n" - "ld1 {v7.8b}, [%1], %4 \n" - "uaddl v0.8h, v0.8b, v1.8b \n" - "uaddl v2.8h, v2.8b, v3.8b \n" - "uaddl v4.8h, v4.8b, v5.8b \n" - "uaddl v6.8h, v6.8b, v7.8b \n" - "mov v16.d[1], v0.d[1] \n" // ab_cd -> ac_bd - "mov v0.d[1], v2.d[0] \n" - "mov v2.d[0], v16.d[1] \n" - "mov v16.d[1], v4.d[1] \n" // ef_gh -> eg_fh - "mov v4.d[1], v6.d[0] \n" - "mov v6.d[0], v16.d[1] \n" - "add v0.8h, v0.8h, v2.8h \n" // (a+b)_(c+d) - "add v4.8h, v4.8h, v6.8h \n" // (e+f)_(g+h) - "rshrn v0.8b, v0.8h, #2 \n" // first 2 pixels. - "rshrn2 v0.16b, v4.8h, #2 \n" // next 2 pixels. - "subs %w3, %w3, #4 \n" // 4 pixels per loop. - "st1 {v0.16b}, [%2], #16 \n" - "b.gt 1b \n" + "add %1, %1, %0 \n" + "1: \n" + "ld1 {v0.8b}, [%0], %4 \n" // Read 4 2x2 -> 2x1 + "ld1 {v1.8b}, [%1], %4 \n" + "ld1 {v2.8b}, [%0], %4 \n" + "ld1 {v3.8b}, [%1], %4 \n" + "ld1 {v4.8b}, [%0], %4 \n" + "ld1 {v5.8b}, [%1], %4 \n" + "ld1 {v6.8b}, [%0], %4 \n" + "ld1 {v7.8b}, [%1], %4 \n" + "uaddl v0.8h, v0.8b, v1.8b \n" + "uaddl v2.8h, v2.8b, v3.8b \n" + "uaddl v4.8h, v4.8b, v5.8b \n" + "uaddl v6.8h, v6.8b, v7.8b \n" + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "zip1 v1.2d, v0.2d, v2.2d \n" + "zip2 v2.2d, v0.2d, v2.2d \n" + "zip1 v5.2d, v4.2d, v6.2d \n" + "zip2 v6.2d, v4.2d, v6.2d \n" + "prfm pldl1keep, [%1, 448] \n" + "add v0.8h, v1.8h, v2.8h \n" // (a+b)_(c+d) + "add v4.8h, v5.8h, v6.8h \n" // (e+f)_(g+h) + "rshrn v0.8b, v0.8h, #2 \n" // first 2 pixels. + "rshrn v1.8b, v4.8h, #2 \n" // next 2 pixels. + "subs %w3, %w3, #4 \n" // 4 pixels per loop. + "stp d0, d1, [%2], #16 \n" + "b.gt 1b \n" : "+r"(src_argb), // %0 "+r"(src_stride), // %1 "+r"(dst_argb), // %2 "+r"(dst_width) // %3 : "r"((int64_t)(src_stepx * 4)) // %4 - : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16"); + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); } // TODO(Yang Zhang): Investigate less load instructions for @@ -864,8 +1254,8 @@ void ScaleARGBCols_NEON(uint8_t* dst_argb, int64_t x64 = (int64_t)x; // NOLINT int64_t dx64 = (int64_t)dx; // NOLINT int64_t tmp64; - asm volatile( - "1: \n" + asm volatile ( + "1: \n" // clang-format off LOAD1_DATA32_LANE(v0, 0) LOAD1_DATA32_LANE(v0, 1) @@ -875,10 +1265,11 @@ void ScaleARGBCols_NEON(uint8_t* dst_argb, LOAD1_DATA32_LANE(v1, 1) LOAD1_DATA32_LANE(v1, 2) LOAD1_DATA32_LANE(v1, 3) + "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead // clang-format on - "st1 {v0.4s, v1.4s}, [%0], #32 \n" // store pixels - "subs %w2, %w2, #8 \n" // 8 processed per loop - "b.gt 1b \n" + "st1 {v0.4s, v1.4s}, [%0], #32 \n" // store pixels + "subs %w2, %w2, #8 \n" // 8 processed per loop + "b.gt 1b \n" : "+r"(dst_argb), // %0 "+r"(src_argb), // %1 "+r"(dst_width), // %2 @@ -892,13 +1283,14 @@ void ScaleARGBCols_NEON(uint8_t* dst_argb, #undef LOAD1_DATA32_LANE -// TODO(Yang Zhang): Investigate less load instructions for -// the x/dx stepping -#define LOAD2_DATA32_LANE(vn1, vn2, n) \ - "lsr %5, %3, #16 \n" \ - "add %6, %1, %5, lsl #2 \n" \ - "add %3, %3, %4 \n" \ - "ld2 {" #vn1 ".s, " #vn2 ".s}[" #n "], [%6] \n" +static const uvec8 kScaleARGBFilterColsShuffleIndices = { + 0, 0, 0, 0, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, +}; + +#define SCALE_ARGB_FILTER_COLS_STEP_ADDR \ + "lsr %5, %3, #16 \n" \ + "add %6, %1, %5, lsl #2 \n" \ + "add %3, %3, %4 \n" void ScaleARGBFilterCols_NEON(uint8_t* dst_argb, const uint8_t* src_argb, @@ -906,64 +1298,130 @@ void ScaleARGBFilterCols_NEON(uint8_t* dst_argb, int x, int dx) { int dx_offset[4] = {0, 1, 2, 3}; - int* tmp = dx_offset; + int64_t tmp; const uint8_t* src_tmp = src_argb; - int64_t x64 = (int64_t)x; // NOLINT - int64_t dx64 = (int64_t)dx; // NOLINT - asm volatile ( - "dup v0.4s, %w3 \n" // x - "dup v1.4s, %w4 \n" // dx - "ld1 {v2.4s}, [%5] \n" // 0 1 2 3 - "shl v6.4s, v1.4s, #2 \n" // 4 * dx - "mul v1.4s, v1.4s, v2.4s \n" - "movi v3.16b, #0x7f \n" // 0x7F - "movi v4.8h, #0x7f \n" // 0x7F - // x , x + 1 * dx, x + 2 * dx, x + 3 * dx - "add v5.4s, v1.4s, v0.4s \n" - "1: \n" - // d0, d1: a - // d2, d3: b - LOAD2_DATA32_LANE(v0, v1, 0) - LOAD2_DATA32_LANE(v0, v1, 1) - LOAD2_DATA32_LANE(v0, v1, 2) - LOAD2_DATA32_LANE(v0, v1, 3) - "shrn v2.4h, v5.4s, #9 \n" - "and v2.8b, v2.8b, v4.8b \n" - "dup v16.8b, v2.b[0] \n" - "dup v17.8b, v2.b[2] \n" - "dup v18.8b, v2.b[4] \n" - "dup v19.8b, v2.b[6] \n" - "ext v2.8b, v16.8b, v17.8b, #4 \n" - "ext v17.8b, v18.8b, v19.8b, #4 \n" - "ins v2.d[1], v17.d[0] \n" // f - "eor v7.16b, v2.16b, v3.16b \n" // 0x7f ^ f - "umull v16.8h, v0.8b, v7.8b \n" - "umull2 v17.8h, v0.16b, v7.16b \n" - "umull v18.8h, v1.8b, v2.8b \n" - "umull2 v19.8h, v1.16b, v2.16b \n" - "add v16.8h, v16.8h, v18.8h \n" - "add v17.8h, v17.8h, v19.8h \n" - "shrn v0.8b, v16.8h, #7 \n" - "shrn2 v0.16b, v17.8h, #7 \n" + int64_t x64 = (int64_t)x; + int64_t dx64 = (int64_t)dx; + asm volatile( + "dup v0.4s, %w3 \n" + "dup v1.4s, %w4 \n" + "ld1 {v2.4s}, [%[kOffsets]] \n" + "shl v6.4s, v1.4s, #2 \n" + "mul v1.4s, v1.4s, v2.4s \n" + "movi v3.16b, #0x7f \n" - "st1 {v0.4s}, [%0], #16 \n" // store pixels - "add v5.4s, v5.4s, v6.4s \n" - "subs %w2, %w2, #4 \n" // 4 processed per loop - "b.gt 1b \n" - : "+r"(dst_argb), // %0 - "+r"(src_argb), // %1 - "+r"(dst_width), // %2 - "+r"(x64), // %3 - "+r"(dx64), // %4 - "+r"(tmp), // %5 - "+r"(src_tmp) // %6 - : - : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", - "v6", "v7", "v16", "v17", "v18", "v19" - ); + "add v5.4s, v1.4s, v0.4s \n" + "ldr q18, [%[kIndices]] \n" + + "1: \n" // + SCALE_ARGB_FILTER_COLS_STEP_ADDR + "ldr d1, [%6] \n" // + SCALE_ARGB_FILTER_COLS_STEP_ADDR + "ldr d2, [%6] \n" + "shrn v4.4h, v5.4s, #9 \n" // + SCALE_ARGB_FILTER_COLS_STEP_ADDR + "ld1 {v1.d}[1], [%6] \n" // + SCALE_ARGB_FILTER_COLS_STEP_ADDR + "ld1 {v2.d}[1], [%6] \n" + + "subs %w2, %w2, #4 \n" // 4 processed per loop + "and v4.8b, v4.8b, v3.8b \n" + "trn1 v0.4s, v1.4s, v2.4s \n" + "tbl v4.16b, {v4.16b}, v18.16b \n" // f + "trn2 v1.4s, v1.4s, v2.4s \n" + "eor v7.16b, v4.16b, v3.16b \n" // 0x7f ^ f + + "umull v16.8h, v1.8b, v4.8b \n" + "umull2 v17.8h, v1.16b, v4.16b \n" + "umlal v16.8h, v0.8b, v7.8b \n" + "umlal2 v17.8h, v0.16b, v7.16b \n" + + "prfm pldl1keep, [%1, 448] \n" // prefetch 7 lines ahead + "shrn v0.8b, v16.8h, #7 \n" + "shrn v1.8b, v17.8h, #7 \n" + "add v5.4s, v5.4s, v6.4s \n" + "stp d0, d1, [%0], #16 \n" // store pixels + "b.gt 1b \n" + : "+r"(dst_argb), // %0 + "+r"(src_argb), // %1 + "+r"(dst_width), // %2 + "+r"(x64), // %3 + "+r"(dx64), // %4 + "=&r"(tmp), // %5 + "+r"(src_tmp) // %6 + : [kIndices] "r"(&kScaleARGBFilterColsShuffleIndices), // %[kIndices] + [kOffsets] "r"(dx_offset) // %[kOffsets] + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", + "v17", "v18", "v19"); } -#undef LOAD2_DATA32_LANE +#undef SCALE_ARGB_FILTER_COLS_STEP_ADDR + +void ScaleRowDown2_16_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width) { + (void)src_stride; + asm volatile( + "subs %w[dst_width], %w[dst_width], #32 \n" + "b.lt 2f \n" + + "1: \n" + "ldp q0, q1, [%[src_ptr]] \n" + "ldp q2, q3, [%[src_ptr], #32] \n" + "ldp q4, q5, [%[src_ptr], #64] \n" + "ldp q6, q7, [%[src_ptr], #96] \n" + "add %[src_ptr], %[src_ptr], #128 \n" + "uzp2 v0.8h, v0.8h, v1.8h \n" + "uzp2 v1.8h, v2.8h, v3.8h \n" + "uzp2 v2.8h, v4.8h, v5.8h \n" + "uzp2 v3.8h, v6.8h, v7.8h \n" + "subs %w[dst_width], %w[dst_width], #32 \n" // 32 elems per + // iteration. + "stp q0, q1, [%[dst_ptr]] \n" + "stp q2, q3, [%[dst_ptr], #32] \n" + "add %[dst_ptr], %[dst_ptr], #64 \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], #32 \n" + "b.eq 99f \n" + + "ldp q0, q1, [%[src_ptr]] \n" + "ldp q2, q3, [%[src_ptr], #32] \n" + "uzp2 v0.8h, v0.8h, v1.8h \n" + "uzp2 v1.8h, v2.8h, v3.8h \n" + "stp q0, q1, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst), // %[dst_ptr] + [dst_width] "+r"(dst_width) // %[dst_width] + : + : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7"); +} + +void ScaleRowDown2Linear_16_NEON(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width) { + (void)src_stride; + asm volatile( + "1: \n" + "ld2 {v0.8h, v1.8h}, [%[src_ptr]], #32 \n" + "ld2 {v2.8h, v3.8h}, [%[src_ptr]], #32 \n" + "subs %w[dst_width], %w[dst_width], #16 \n" + "urhadd v0.8h, v0.8h, v1.8h \n" + "urhadd v1.8h, v2.8h, v3.8h \n" + "prfm pldl1keep, [%[src_ptr], 448] \n" + "stp q0, q1, [%[dst_ptr]], #32 \n" + "b.gt 1b \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst), // %[dst_ptr] + [dst_width] "+r"(dst_width) // %[dst_width] + : + : "memory", "cc", "v0", "v1", "v2", "v3"); +} // Read 16x2 average down and write 8x1. void ScaleRowDown2Box_16_NEON(const uint16_t* src_ptr, @@ -972,76 +1430,157 @@ void ScaleRowDown2Box_16_NEON(const uint16_t* src_ptr, int dst_width) { asm volatile( // change the stride to row 2 pointer - "add %1, %0, %1, lsl #1 \n" // ptr + stide * 2 - "1: \n" - "ld1 {v0.8h, v1.8h}, [%0], #32 \n" // load row 1 and post inc - "ld1 {v2.8h, v3.8h}, [%1], #32 \n" // load row 2 and post inc - "subs %w3, %w3, #8 \n" // 8 processed per loop - "uaddlp v0.4s, v0.8h \n" // row 1 add adjacent - "uaddlp v1.4s, v1.8h \n" - "uadalp v0.4s, v2.8h \n" // +row 2 add adjacent - "uadalp v1.4s, v3.8h \n" - "rshrn v0.4h, v0.4s, #2 \n" // round and pack - "rshrn2 v0.8h, v1.4s, #2 \n" - "st1 {v0.8h}, [%2], #16 \n" - "b.gt 1b \n" + "add %1, %0, %1, lsl #1 \n" // ptr + stide * 2 + "1: \n" + "ld1 {v0.8h, v1.8h}, [%0], #32 \n" // load row 1 and post inc + "ld1 {v2.8h, v3.8h}, [%1], #32 \n" // load row 2 and post inc + "subs %w3, %w3, #8 \n" // 8 processed per loop + "uaddlp v0.4s, v0.8h \n" // row 1 add adjacent + "uaddlp v1.4s, v1.8h \n" + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "uadalp v0.4s, v2.8h \n" // +row 2 add adjacent + "uadalp v1.4s, v3.8h \n" + "prfm pldl1keep, [%1, 448] \n" + "rshrn v0.4h, v0.4s, #2 \n" // round and pack + "rshrn2 v0.8h, v1.4s, #2 \n" + "st1 {v0.8h}, [%2], #16 \n" + "b.gt 1b \n" : "+r"(src_ptr), // %0 "+r"(src_stride), // %1 "+r"(dst), // %2 "+r"(dst_width) // %3 : - : "v0", "v1", "v2", "v3" // Clobber List + : "memory", "cc", "v0", "v1", "v2", "v3" // Clobber List ); } -// Read 8x2 upsample with filtering and write 16x1. -// Actually reads an extra pixel, so 9x2. -void ScaleRowUp2_16_NEON(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width) { +void ScaleUVRowDown2_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + (void)src_stride; asm volatile( - "add %1, %0, %1, lsl #1 \n" // ptr + stide * 2 - "movi v0.8h, #9 \n" // constants - "movi v1.4s, #3 \n" + "1: \n" + "ld2 {v0.8h,v1.8h}, [%0], #32 \n" // load 16 UV + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "st1 {v1.8h}, [%1], #16 \n" // store 8 UV + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "v0", "v1"); +} - "1: \n" - "ld1 {v3.8h}, [%0], %4 \n" // TL read first 8 - "ld1 {v4.8h}, [%0], %5 \n" // TR read 8 offset by 1 - "ld1 {v5.8h}, [%1], %4 \n" // BL read 8 from next row - "ld1 {v6.8h}, [%1], %5 \n" // BR offset by 1 - "subs %w3, %w3, #16 \n" // 16 dst pixels per loop - "umull v16.4s, v3.4h, v0.4h \n" - "umull2 v7.4s, v3.8h, v0.8h \n" - "umull v18.4s, v4.4h, v0.4h \n" - "umull2 v17.4s, v4.8h, v0.8h \n" - "uaddw v16.4s, v16.4s, v6.4h \n" - "uaddl2 v19.4s, v6.8h, v3.8h \n" - "uaddl v3.4s, v6.4h, v3.4h \n" - "uaddw2 v6.4s, v7.4s, v6.8h \n" - "uaddl2 v7.4s, v5.8h, v4.8h \n" - "uaddl v4.4s, v5.4h, v4.4h \n" - "uaddw v18.4s, v18.4s, v5.4h \n" - "mla v16.4s, v4.4s, v1.4s \n" - "mla v18.4s, v3.4s, v1.4s \n" - "mla v6.4s, v7.4s, v1.4s \n" - "uaddw2 v4.4s, v17.4s, v5.8h \n" - "uqrshrn v16.4h, v16.4s, #4 \n" - "mla v4.4s, v19.4s, v1.4s \n" - "uqrshrn2 v16.8h, v6.4s, #4 \n" - "uqrshrn v17.4h, v18.4s, #4 \n" - "uqrshrn2 v17.8h, v4.4s, #4 \n" - "st2 {v16.8h-v17.8h}, [%2], #32 \n" - "b.gt 1b \n" +void ScaleUVRowDown2Linear_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + (void)src_stride; + asm volatile( + "1: \n" + "ld2 {v0.8h,v1.8h}, [%0], #32 \n" // load 16 UV + "subs %w2, %w2, #8 \n" // 8 processed per loop. + "urhadd v0.16b, v0.16b, v1.16b \n" // rounding half add + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "st1 {v0.8h}, [%1], #16 \n" // store 8 UV + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(dst), // %1 + "+r"(dst_width) // %2 + : + : "memory", "cc", "v0", "v1"); +} + +void ScaleUVRowDown2Box_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + asm volatile( + // change the stride to row 2 pointer + "add %1, %1, %0 \n" + "1: \n" + "ld2 {v0.16b,v1.16b}, [%0], #32 \n" // load 16 UV + "subs %w3, %w3, #8 \n" // 8 processed per loop. + "uaddlp v0.8h, v0.16b \n" // U 16 bytes -> 8 shorts. + "uaddlp v1.8h, v1.16b \n" // V 16 bytes -> 8 shorts. + "ld2 {v16.16b,v17.16b}, [%1], #32 \n" // load 16 + "uadalp v0.8h, v16.16b \n" // U 16 bytes -> 8 shorts. + "uadalp v1.8h, v17.16b \n" // V 16 bytes -> 8 shorts. + "prfm pldl1keep, [%0, 448] \n" // prefetch 7 lines ahead + "rshrn v0.8b, v0.8h, #2 \n" // round and pack + "prfm pldl1keep, [%1, 448] \n" + "rshrn v1.8b, v1.8h, #2 \n" + "st2 {v0.8b,v1.8b}, [%2], #16 \n" + "b.gt 1b \n" : "+r"(src_ptr), // %0 "+r"(src_stride), // %1 "+r"(dst), // %2 "+r"(dst_width) // %3 - : "r"(2LL), // %4 - "r"(14LL) // %5 - : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18", - "v19" // Clobber List - ); + : + : "memory", "cc", "v0", "v1", "v16", "v17"); +} + +// Reads 4 pixels at a time. +void ScaleUVRowDownEven_NEON(const uint8_t* src_ptr, + ptrdiff_t src_stride, + int src_stepx, // pixel step + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* src1_ptr = src_ptr + src_stepx * 2; + const uint8_t* src2_ptr = src_ptr + src_stepx * 4; + const uint8_t* src3_ptr = src_ptr + src_stepx * 6; + (void)src_stride; + asm volatile( + "1: \n" + "ld1 {v0.h}[0], [%0], %6 \n" + "ld1 {v1.h}[0], [%1], %6 \n" + "ld1 {v2.h}[0], [%2], %6 \n" + "ld1 {v3.h}[0], [%3], %6 \n" + "subs %w5, %w5, #4 \n" // 4 pixels per loop. + "st4 {v0.h, v1.h, v2.h, v3.h}[0], [%4], #8 \n" + "b.gt 1b \n" + : "+r"(src_ptr), // %0 + "+r"(src1_ptr), // %1 + "+r"(src2_ptr), // %2 + "+r"(src3_ptr), // %3 + "+r"(dst_ptr), // %4 + "+r"(dst_width) // %5 + : "r"((int64_t)(src_stepx * 8)) // %6 + : "memory", "cc", "v0", "v1", "v2", "v3"); +} + +// Scale UV columns by 3 box filter. +// Reads 96 bytes (24 UV pixels) and writes 16 bytes (8 UV pixels) per loop. +void ScaleUVAddCols3_NEON(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { + asm volatile( + "dup v6.8h, %w[scaleval] \n" + "1: \n" + "ld3 {v0.4s, v1.4s, v2.4s}, [%[src_uv]], #48 \n" + "ld3 {v3.4s, v4.4s, v5.4s}, [%[src_uv]], #48 \n" + "subs %w[dst_width], %w[dst_width], #8 \n" + "add v0.8h, v0.8h, v1.8h \n" + "add v3.8h, v3.8h, v4.8h \n" + "add v0.8h, v0.8h, v2.8h \n" + "add v3.8h, v3.8h, v5.8h \n" + "umull v1.4s, v0.4h, v6.4h \n" + "umull2 v2.4s, v0.8h, v6.8h \n" + "umull v4.4s, v3.4h, v6.4h \n" + "umull2 v5.4s, v3.8h, v6.8h \n" + "uzp2 v0.8h, v1.8h, v2.8h \n" + "uzp2 v3.8h, v4.8h, v5.8h \n" + "uzp1 v0.16b, v0.16b, v3.16b \n" + "st1 {v0.16b}, [%[dst_uv]], #16 \n" + "b.gt 1b \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [dst_width] "+r"(dst_width) // %[dst_width] + : [scaleval] "r"(scaleval) // %[scaleval] + : "memory", "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6"); } #endif // !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) diff --git a/libs/libyuv/source/scale_rgb.cc b/libs/libyuv/source/scale_rgb.cc new file mode 100644 index 0000000000..0a2f2f6b9a --- /dev/null +++ b/libs/libyuv/source/scale_rgb.cc @@ -0,0 +1,84 @@ +/* + * Copyright 2022 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/scale.h" /* For FilterMode */ + +#include +#include +#include +#include +#include + +#include "libyuv/convert_argb.h" +#include "libyuv/convert_from_argb.h" +#include "libyuv/row.h" +#include "libyuv/scale_argb.h" +#include "libyuv/scale_rgb.h" + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// Scale a 24 bit image. +// Converts to ARGB as intermediate step + +LIBYUV_API +int RGBScale(const uint8_t* src_rgb, + int src_stride_rgb, + int src_width, + int src_height, + uint8_t* dst_rgb, + int dst_stride_rgb, + int dst_width, + int dst_height, + enum FilterMode filtering) { + int r; + if (!src_rgb || !dst_rgb || src_width <= 0 || src_width > INT_MAX / 4 || + src_height == 0 || src_height == INT_MIN || dst_width <= 0 || + dst_width > INT_MAX / 4 || dst_height <= 0) { + return -1; + } + const int abs_src_height = (src_height < 0) ? -src_height : src_height; + const uint64_t src_argb_size = (uint64_t)src_width * abs_src_height * 4; + const uint64_t dst_argb_size = (uint64_t)dst_width * dst_height * 4; + if (src_argb_size > (UINT64_MAX - dst_argb_size)) { + return -1; // Invalid size. + } + const uint64_t argb_size = src_argb_size + dst_argb_size; +#if UINT64_MAX > SIZE_MAX + if (argb_size > SIZE_MAX) { + return -1; // Invalid size. + } +#endif + uint8_t* src_argb = (uint8_t*)malloc((size_t)argb_size); + if (!src_argb) { + return 1; // Out of memory runtime error. + } + uint8_t* dst_argb = src_argb + (size_t)src_argb_size; + + r = RGB24ToARGB(src_rgb, src_stride_rgb, src_argb, src_width * 4, src_width, + src_height); + if (!r) { + r = ARGBScale(src_argb, src_width * 4, src_width, abs_src_height, dst_argb, + dst_width * 4, dst_width, dst_height, filtering); + if (!r) { + r = ARGBToRGB24(dst_argb, dst_width * 4, dst_rgb, dst_stride_rgb, + dst_width, dst_height); + } + } + free(src_argb); + return r; +} + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif diff --git a/libs/libyuv/source/scale_rvv.cc b/libs/libyuv/source/scale_rvv.cc new file mode 100644 index 0000000000..238a9a9539 --- /dev/null +++ b/libs/libyuv/source/scale_rvv.cc @@ -0,0 +1,1348 @@ +/* + * Copyright 2023 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +/* + * Copyright (c) 2023 SiFive, Inc. All rights reserved. + * + * Contributed by Darren Hsieh + * Contributed by Bruce Lai + */ + +#include "libyuv/row.h" +#include "libyuv/scale_row.h" + +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + +// This module is for RVV (RISC-V Vector extension) +#if !defined(LIBYUV_DISABLE_RVV) && defined(__riscv_vector) +#include +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// vsetvli/vsetivli write the vl and vtype CSRs. Only "vl" is declared, and +// only for GCC; clang historically rejected it. The "vtype" register is +// intentionally not declared, and whether it should be is unresolved. +// TODO(fbarchard): consider adding "vtype" (and "vl" for clang) to the +// clobber list once confirmed with compiler maintainers. +#ifndef RVV_VL_CLOBBER +#ifdef __clang__ +#define RVV_VL_CLOBBER +#else +#define RVV_VL_CLOBBER "vl", +#endif +#endif + +#ifdef HAS_SCALEARGBFILTERCOLS_RVV +void ScaleARGBFilterCols_RVV(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx) { + assert(x >= 0); + int vl, vl_dx; + asm volatile( + "vsetvli %[vl], %[w], e32, m2, ta, ma \n" + "vmv.v.x v0, %[x] \n" + "vid.v v2 \n" + "vmacc.vx v0, %[dx], v2 \n" + + "1: \n" + // idx is x >> 16, byte index is (x >> 14) & ~3u + "vsrl.vi v2, v0, 14 \n" + "vand.vi v2, v2, -4 \n" + // Read Packed ARGB w/ byte index. + "vluxseg2ei32.v v4, (%[src_argb]), v2 \n" + // xf = (x >> 9) & 0x7f; + "vsrl.vi v8, v0, 9 \n" + "vand.vx v8, v8, %[c_7f] \n" + "mul %[vl_dx], %[vl], %[dx] \n" + "vadd.vx v0, v0, %[vl_dx] \n" + // duplicate v_xf0_u32[i] from {0,0,0,f[i]} to {f[i],f[i],f[i],f[i]} + "vmul.vx v8, v8, %[c_01010101] \n" + // TODO(fbarchard): Replace 0x7f ^ f with 128-f. bug=607. + "vxor.vx v10, v8, %[c_7f7f7f7f] \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "vsetvli zero, %[vl], e8, m2, ta, ma \n" + // ((a) * (0x7f ^ f) + (b)*f) >> 7 + "vwmulu.vv v12, v4, v10 \n" + "vwmaccu.vv v12, v6, v8 \n" + "vnsrl.wi v4, v12, 7 \n" + "vse8.v v4, (%[dst_argb]) \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "vsetvli %[vl], %[w], e32, m2, ta, ma \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [vl] "=&r"(vl), // %[vl] + [vl_dx] "=&r"(vl_dx) // %[vl_dx] + : [src_argb] "r"(src_argb), // %[src_argb] + [x] "r"(x), // %[x] + [dx] "r"(dx), // %[dx] + [c_7f] "r"(0x7f), // %[c_7f] + [c_01010101] "r"(0x01010101u), // %[c_01010101] + [c_7f7f7f7f] "r"(0x7f7f7f7fu) // %[c_7f7f7f7f] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", + "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15"); +} +#endif + +#ifdef HAS_SCALEADDROW_RVV +void ScaleAddRow_RVV(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width) { + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle16.v v8, (%[dst_ptr]) \n" + "vle8.v v16, (%[src_ptr]) \n" + // Use widening multiply-add instead of widening + add + "vwmaccu.vx v8, %[one], v16 \n" + "vse16.v v8, (%[dst_ptr]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(src_width), // %[w] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [vl] "=&r"(vl) // %[vl] + : [one] "r"(1) // %[one] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17"); +} +#endif + +#ifdef HAS_SCALEARGBROWDOWN2_RVV +void ScaleARGBRowDown2_RVV(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e32, m4, ta, ma \n" + "vlseg2e32.v v8, (%[src]) \n" + "vse32.v v12, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst], %[dst], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src], %[src], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_argb), // %[dst] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_SCALEARGBROWDOWN2LINEAR_RVV +void ScaleARGBRowDown2Linear_RVV(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + int vl; + // NOTE: To match behavior on other platforms, vxrm (fixed-point rounding mode + // register) is set to round-to-nearest-up mode(0). + asm volatile( + "csrwi vxrm, 0 \n" + + "1: \n" + "vsetvli %[vl], %[w], e32, m4, ta, ma \n" + "vlseg2e32.v v8, (%[src]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "vsetvli zero, %[vl], e8, m4, ta, ma \n" + "vaaddu.vv v8, v8, v12 \n" + "vse8.v v8, (%[dst_argb]) \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[src], %[src], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src] "+r"(src_argb), // %[src] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_SCALEARGBROWDOWN2BOX_RVV +void ScaleARGBRowDown2Box_RVV(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + int vl; + asm volatile( + "add %[src1], %[src0], %[src1] \n" + + "1: \n" + "vsetvli %[vl], %[w], e32, m2, ta, ma \n" + "vlseg2e32.v v16, (%[src0]) \n" + "vlseg2e32.v v20, (%[src1]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "vsetvli zero, %[vl], e8, m2, ta, ma \n" + "vwaddu.vx v8, v16, %[c2] \n" + "vwaddu.wv v8, v8, v18 \n" + "vwaddu.wv v8, v8, v20 \n" + "vwaddu.wv v8, v8, v22 \n" + "vnsrl.wi v16, v8, 2 \n" + "vse8.v v16, (%[dst_argb]) \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[src0], %[src0], %[vl] \n" + "add %[src1], %[src1], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src0] "+r"(src_argb), // %[src0] + [src1] "+r"(src_stride), // %[src1] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [vl] "=&r"(vl) // %[vl] + : [c2] "r"(2) // %[c2] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17", "v18", + "v19", "v20", "v21", "v22", "v23"); +} +#endif + +#ifdef HAS_SCALEARGBROWDOWNEVEN_RVV +void ScaleARGBRowDownEven_RVV(const uint8_t* src_argb, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + int vl; + ptrdiff_t src_step; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e32, m4, ta, ma \n" + "vlse32.v v8, (%[src]), %[stride_byte] \n" + "vse32.v v8, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "mul %[src_step], %[vl], %[stride_byte]\n" + "add %[src], %[src], %[src_step] \n" + "slli %[vl], %[vl], 2 \n" + "add %[dst], %[dst], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src] "+r"(src_argb), // %[src] + [dst] "+r"(dst_argb), // %[dst] + [vl] "=&r"(vl), // %[vl] + [src_step] "=&r"(src_step) // %[src_step] + : [stride_byte] "r"((ptrdiff_t)src_stepx * 4) // %[stride_byte] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11"); +} +#endif + +#ifdef HAS_SCALEARGBROWDOWNEVENBOX_RVV +void ScaleARGBRowDownEvenBox_RVV(const uint8_t* src_argb, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_argb, + int dst_width) { + int vl; + ptrdiff_t src_step; + asm volatile( + "add %[src1], %[src0], %[src1] \n" + + "1: \n" + "vsetvli %[vl], %[w], e32, m2, ta, ma \n" + "vlsseg2e32.v v16, (%[src0]), %[stride_byte] \n" + "vlsseg2e32.v v20, (%[src1]), %[stride_byte] \n" + "sub %[w], %[w], %[vl] \n" + "mul %[src_step], %[vl], %[stride_byte]\n" + "slli %[vl], %[vl], 2 \n" + "vsetvli zero, %[vl], e8, m2, ta, ma \n" + "vwaddu.vx v8, v16, %[c2] \n" + "vwaddu.wv v8, v8, v18 \n" + "vwaddu.wv v8, v8, v20 \n" + "vwaddu.wv v8, v8, v22 \n" + "vnsrl.wi v16, v8, 2 \n" + "vse8.v v16, (%[dst_argb]) \n" + "add %[src0], %[src0], %[src_step] \n" + "add %[src1], %[src1], %[src_step] \n" + "add %[dst_argb], %[dst_argb], %[vl]\n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src0] "+r"(src_argb), // %[src0] + [src1] "+r"(src_stride), // %[src1] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [vl] "=&r"(vl), // %[vl] + [src_step] "=&r"(src_step) // %[src_step] + : [stride_byte] "r"((ptrdiff_t)src_stepx * 4), // %[stride_byte] + [c2] "r"(2) // %[c2] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17", "v18", + "v19", "v20", "v21", "v22", "v23"); +} +#endif + +#ifdef HAS_SCALEROWDOWN2_RVV +void ScaleRowDown2_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + (void)src_stride; + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle16.v v8, (%[src_ptr]) \n" + "vnsrl.wi v16, v8, 8 \n" + "vse8.v v16, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst], %[dst], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst] "+r"(dst), // %[dst] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17"); +} +#endif + +#ifdef HAS_SCALEROWDOWN2LINEAR_RVV +void ScaleRowDown2Linear_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + (void)src_stride; + int vl; + // NOTE: To match behavior on other platforms, vxrm (fixed-point rounding mode + // register) is set to round-to-nearest-up mode(0). + asm volatile( + "csrwi vxrm, 0 \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vle16.v v8, (%[src_ptr]) \n" + "vnsrl.wi v16, v8, 0 \n" + "vnsrl.wi v18, v8, 8 \n" + "vaaddu.vv v16, v16, v18 \n" + "vse8.v v16, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst], %[dst], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst] "+r"(dst), // %[dst] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17", "v18", + "v19"); +} +#endif + +#ifdef HAS_SCALEROWDOWN2BOX_RVV +void ScaleRowDown2Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + int vl; + asm volatile( + "add %[t], %[s], %[t] \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg2e8.v v16, (%[s]) \n" + "vlseg2e8.v v20, (%[t]) \n" + "vwaddu.vx v8, v16, %[c2] \n" + "vwaddu.wv v8, v8, v18 \n" + "vwaddu.wv v8, v8, v20 \n" + "vwaddu.wv v8, v8, v22 \n" + "vnsrl.wi v16, v8, 2 \n" + "vse8.v v16, (%[dst]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst], %[dst], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[s], %[s], %[vl] \n" + "add %[t], %[t], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [s] "+r"(src_ptr), // %[s] + [t] "+r"(src_stride), // %[t] + [dst] "+r"(dst), // %[dst] + [vl] "=&r"(vl) // %[vl] + : [c2] "r"(2) // %[c2] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17", "v18", + "v19", "v20", "v21", "v22", "v23"); +} +#endif + +#ifdef HAS_SCALEROWDOWN4_RVV +void ScaleRowDown4_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v8, (%[src_ptr]) \n" + "vse8.v v12, (%[dst_ptr]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_SCALEROWDOWN4BOX_RVV +void ScaleRowDown4Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* src_ptr1; + const uint8_t* src_ptr2; + int vl; + asm volatile( + "add %[src_ptr1], %[src_ptr], %[src_ptr3]\n" + "add %[src_ptr2], %[src_ptr1], %[src_ptr3]\n" + "add %[src_ptr3], %[src_ptr2], %[src_ptr3]\n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v16, (%[src_ptr]) \n" + "vlseg4e8.v v24, (%[src_ptr1]) \n" + "vwaddu.vx v8, v16, %[c8] \n" + "vwaddu.wv v8, v8, v18 \n" + "vwaddu.wv v8, v8, v20 \n" + "vwaddu.wv v8, v8, v22 \n" + "vwaddu.wv v8, v8, v24 \n" + "vwaddu.wv v8, v8, v26 \n" + "vwaddu.wv v8, v8, v28 \n" + "vwaddu.wv v8, v8, v30 \n" + "vlseg4e8.v v16, (%[src_ptr2]) \n" + "vlseg4e8.v v24, (%[src_ptr3]) \n" + "vwaddu.wv v8, v8, v16 \n" + "vwaddu.wv v8, v8, v18 \n" + "vwaddu.wv v8, v8, v20 \n" + "vwaddu.wv v8, v8, v22 \n" + "vwaddu.wv v8, v8, v24 \n" + "vwaddu.wv v8, v8, v26 \n" + "vwaddu.wv v8, v8, v28 \n" + "vwaddu.wv v8, v8, v30 \n" + "vnsrl.wi v16, v8, 4 \n" + "vse8.v v16, (%[dst_ptr]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "add %[src_ptr1], %[src_ptr1], %[vl]\n" + "add %[src_ptr2], %[src_ptr2], %[vl]\n" + "add %[src_ptr3], %[src_ptr3], %[vl]\n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "=&r"(src_ptr1), // %[src_ptr1] + [src_ptr2] "=&r"(src_ptr2), // %[src_ptr2] + [src_ptr3] "+r"(src_stride), // %[src_ptr3] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [vl] "=&r"(vl) // %[vl] + : [c8] "r"(8) // %[c8] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17", "v18", + "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", + "v29", "v30", "v31"); +} +#endif + +#ifdef HAS_SCALEROWDOWN34_RVV +void ScaleRowDown34_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + dst_width /= 3; + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v8, (%[src_ptr]) \n" + "vmv2r.v v12, v14 \n" + "vsseg3e8.v v8, (%[dst_ptr]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_SCALEROWDOWN34_0_BOX_RVV +void ScaleRowDown34_0_Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + dst_width /= 3; + const uint8_t* t; + int vl; + // NOTE: To match behavior on other platforms, vxrm (fixed-point rounding mode + // register) is set to round-to-nearest-up mode(0). + asm volatile( + "add %[t], %[s], %[src_stride] \n" + "csrwi vxrm, 0 \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v24, (%[s]) \n" + "bnez %[src_stride], 2f \n" + "vwaddu.vx v20, v24, %[c2] \n" + "vwaddu.vx v16, v26, %[c2] \n" + "vwaddu.vx v12, v28, %[c2] \n" + "vwaddu.vx v8, v30, %[c2] \n" + "j 3f \n" + + "2: \n" + "vlseg4e8.v v0, (%[t]) \n" + "vwaddu.vx v20, v0, %[c2] \n" + "vwaddu.vx v16, v2, %[c2] \n" + "vwaddu.vx v12, v4, %[c2] \n" + "vwaddu.vx v8, v6, %[c2] \n" + + "3: \n" + "vwmaccu.vx v20, %[c3], v24 \n" + "vnsrl.wi v24, v20, 2 \n" + "vwmaccu.vx v16, %[c3], v26 \n" + "vnsrl.wi v20, v16, 2 \n" + "vwmaccu.vx v12, %[c3], v28 \n" + "vnsrl.wi v16, v12, 2 \n" + "vwmaccu.vx v8, %[c3], v30 \n" + "vnsrl.wi v12, v8, 2 \n" + // a0 = (src[0] * 3 + s[1] * 1 + 2) >> 2 + "vwaddu.vx v8, v20, %[c2] \n" + "vwmaccu.vx v8, %[c3], v24 \n" + "vnsrl.wi v14, v8, 2 \n" + // a2 = (src[2] * 1 + s[3] * 3 + 2) >> 2 + "vwaddu.vx v8, v16, %[c2] \n" + "vwmaccu.vx v8, %[c3], v12 \n" + // a1 = (src[1] * 1 + s[2] * 1 + 1) >> 1 + "vaaddu.vv v16, v20, v16 \n" + "vnsrl.wi v18, v8, 2 \n" + "vsseg3e8.v v14, (%[dst_ptr]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[s], %[s], %[vl] \n" + "add %[t], %[t], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [s] "+r"(src_ptr), // %[s] + [t] "=&r"(t), // %[t] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [vl] "=&r"(vl) // %[vl] + : [src_stride] "r"(src_stride), // %[src_stride] + [c2] "r"(2), // %[c2] + [c3] "r"(3) // %[c3] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", + "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", + "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", + "v28", "v29", "v30", "v31"); +} +#endif + +#ifdef HAS_SCALEROWDOWN34_1_BOX_RVV +void ScaleRowDown34_1_Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + dst_width /= 3; + const uint8_t* t; + int vl; + // NOTE: To match behavior on other platforms, vxrm (fixed-point rounding mode + // register) is set to round-to-nearest-up mode(0). + asm volatile( + "add %[t], %[s], %[src_stride] \n" + "csrwi vxrm, 0 \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v14, (%[s]) \n" + "bnez %[src_stride], 2f \n" + "vaaddu.vv v14, v14, v14 \n" + "vaaddu.vv v8, v16, v16 \n" + "vaaddu.vv v10, v18, v18 \n" + "vaaddu.vv v12, v20, v20 \n" + "j 3f \n" + + "2: \n" + "vlseg4e8.v v22, (%[t]) \n" + "vaaddu.vv v14, v14, v22 \n" + "vaaddu.vv v8, v16, v24 \n" + "vaaddu.vv v10, v18, v26 \n" + "vaaddu.vv v12, v20, v28 \n" + + "3: \n" + // a0 = (src[0] * 3 + s[1] * 1 + 2) >> 2 + "vwaddu.vx v16, v8, %[c2] \n" + "vwmaccu.vx v16, %[c3], v14 \n" + "vnsrl.wi v20, v16, 2 \n" + // a2 = (src[2] * 1 + s[3] * 3 + 2) >> 2 + "vwaddu.vx v16, v10, %[c2] \n" + "vwmaccu.vx v16, %[c3], v12 \n" + // a1 = (src[1] * 1 + s[2] * 1 + 1) >> 1 + "vaaddu.vv v22, v8, v10 \n" + "vnsrl.wi v24, v16, 2 \n" + "vsseg3e8.v v20, (%[dst_ptr]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[s], %[s], %[vl] \n" + "add %[t], %[t], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [s] "+r"(src_ptr), // %[s] + [t] "=&r"(t), // %[t] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [vl] "=&r"(vl) // %[vl] + : [src_stride] "r"(src_stride), // %[src_stride] + [c2] "r"(2), // %[c2] + [c3] "r"(3) // %[c3] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", + "v25", "v26", "v27", "v28", "v29"); +} +#endif + +#ifdef HAS_SCALEROWDOWN38_RVV +void ScaleRowDown38_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + assert(dst_width % 3 == 0); + dst_width /= 3; + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e8, m1, ta, ma \n" + "vlseg8e8.v v8, (%[src_ptr]) \n" + "vmv1r.v v9, v11 \n" + "vmv1r.v v10, v14 \n" + "vsseg3e8.v v8, (%[dst_ptr]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_SCALEROWDOWN38_2_BOX_RVV +void ScaleRowDown38_2_Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + assert((dst_width % 3 == 0) && (dst_width > 0)); + dst_width /= 3; + int vl; + asm volatile( + "add %[src_ptr1], %[src_ptr], %[src_ptr1]\n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m1, ta, ma \n" + // s: e00, e10, e20, f00, f10, f20, g00, g10 + "vlseg8e8.v v14, (%[src_ptr]) \n" + // t: e01, e11, e21, f01, f11, f21, g01, g11 + "vlseg8e8.v v22, (%[src_ptr1]) \n" + "vwaddu.vv v8, v14, v22 \n" + "vwaddu.vv v10, v15, v23 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vv v8, v8, v10 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vwaddu.vv v10, v17, v25 \n" + "vwaddu.vv v12, v18, v26 \n" + "vwaddu.vv v14, v16, v24 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vv v10, v10, v12 \n" + "vadd.vv v8, v8, v14 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vwaddu.vv v12, v19, v27 \n" + "vwaddu.vv v14, v20, v28 \n" + "vwaddu.vv v16, v21, v29 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vv v10, v10, v12 \n" + "vadd.vv v12, v14, v16 \n" + // Average in 16-bit fixed-point + "vmulhu.vx v8, v8, %[coeff_a] \n" + "vmulhu.vx v10, v10, %[coeff_a] \n" + "vmulhu.vx v12, v12, %[coeff_b] \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v14, v8, 0 \n" + "vnsrl.wi v15, v10, 0 \n" + "vnsrl.wi v16, v12, 0 \n" + "vsseg3e8.v v14, (%[dst_ptr]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "add %[src_ptr1], %[src_ptr1], %[vl]\n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "+r"(src_stride), // %[src_ptr1] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [vl] "=&r"(vl) // %[vl] + : [coeff_a] "r"(65536u / 6u), // %[coeff_a] + [coeff_b] "r"(65536u / 4u) // %[coeff_b] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", + "v25", "v26", "v27", "v28", "v29"); +} +#endif + +#ifdef HAS_SCALEROWDOWN38_3_BOX_RVV +void ScaleRowDown38_3_Box_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + assert((dst_width % 3 == 0) && (dst_width > 0)); + dst_width /= 3; + const uint8_t* src_ptr1; + int vl; + asm volatile( + "add %[src_ptr1], %[src_ptr], %[src_ptr2]\n" + "add %[src_ptr2], %[src_ptr1], %[src_ptr2]\n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m1, ta, ma \n" + // s: e00, e10, e20, f00, f10, f20, g00, g10 + "vlseg8e8.v v8, (%[src_ptr]) \n" + // t: e01, e11, e21, f01, f11, f21, g01, g11 + "vlseg8e8.v v19, (%[src_ptr1]) \n" + // u: e02, e12, e22, f02, f12, f22, g02, g12 + "vlseg8e8.v v0, (%[src_ptr2]) \n" + // Calculate sum of [e00, e22] + "vwaddu.vv v16, v8, v19 \n" + "vwaddu.vv v18, v9, v20 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vv v8, v16, v18 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vwaddu.vv v16, v10, v21 \n" + "vwaddu.vv v18, v0, v1 \n" + "vwcvtu.x.x.v v20, v2 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vv v16, v16, v18 \n" + "vadd.vv v8, v8, v20 \n" + "vadd.vv v8, v8, v16 \n" + // Calculate sum of [f00, f22] + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vwaddu.vv v16, v11, v22 \n" + "vwaddu.vv v10, v12, v23 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vv v10, v16, v10 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vwaddu.vv v16, v13, v24 \n" + "vwaddu.vv v12, v3, v4 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vv v12, v16, v12 \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vwcvtu.x.x.v v16, v5 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vv v10, v10, v16 \n" + "vadd.vv v10, v10, v12 \n" + // Calculate sum of [g00, g12] + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vwaddu.vv v12, v14, v25 \n" + "vwaddu.vv v16, v15, v26 \n" + "vwaddu.vv v14, v6, v7 \n" + "vsetvli zero, zero, e16, m2, ta, ma \n" + "vadd.vv v12, v12, v16 \n" + "vadd.vv v12, v12, v14 \n" + // Average in 16-bit fixed-point + "vmulhu.vx v8, v8, %[coeff_a] \n" + "vmulhu.vx v10, v10, %[coeff_a] \n" + "vmulhu.vx v12, v12, %[coeff_b] \n" + "vsetvli zero, zero, e8, m1, ta, ma \n" + "vnsrl.wi v14, v8, 0 \n" + "vnsrl.wi v15, v10, 0 \n" + "vnsrl.wi v16, v12, 0 \n" + "vsseg3e8.v v14, (%[dst_ptr]) \n" + "sub %[w], %[w], %[vl] \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_ptr], %[dst_ptr], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "add %[src_ptr1], %[src_ptr1], %[vl]\n" + "add %[src_ptr2], %[src_ptr2], %[vl]\n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src_ptr1] "=&r"(src_ptr1), // %[src_ptr1] + [src_ptr2] "+r"(src_stride), // %[src_ptr2] + [dst_ptr] "+r"(dst_ptr), // %[dst_ptr] + [vl] "=&r"(vl) // %[vl] + : [coeff_a] "r"(65536u / 9u), // %[coeff_a] + [coeff_b] "r"(65536u / 6u) // %[coeff_b] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", + "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", + "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26"); +} +#endif + +// ScaleUVRowUp2_(Bi)linear_RVV function is equal to other platforms' +// ScaleRowUp2_(Bi)linear_Any_XXX. We process entire row in this function. Other +// platforms only implement non-edge part of image and process edge with scalar. + +#ifdef HAS_SCALEROWUP2_LINEAR_RVV +void ScaleRowUp2_Linear_RVV(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + int src_width = (dst_width - 1) >> 1; + dst_ptr[0] = src_ptr[0]; + if (src_width > 0) { + int vl; + const uint8_t* work_src_next; + uint8_t* work_dst_ptr = dst_ptr + 1; + asm volatile( + "1: \n" + "vsetvli %[vl], %[src_width], e8, m2, ta, ma\n" + "vle8.v v12, (%[src_ptr]) \n" + "addi %[work_src_next], %[src_ptr], 1\n" + "vle8.v v24, (%[work_src_next]) \n" + "vwaddu.vx v16, v12, %[c2] \n" + "vwmaccu.vx v16, %[c3], v24 \n" + "vnsrl.wi v26, v16, 2 \n" + "vwaddu.vx v16, v24, %[c2] \n" + "vwmaccu.vx v16, %[c3], v12 \n" + "vnsrl.wi v24, v16, 2 \n" + "vsseg2e8.v v24, (%[work_dst_ptr]) \n" + "sub %[src_width], %[src_width], %[vl]\n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[work_dst_ptr], %[work_dst_ptr], %[vl]\n" + "bgtz %[src_width], 1b \n" + : [src_width] "+r"(src_width), // %[src_width] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [work_dst_ptr] "+r"(work_dst_ptr), // %[work_dst_ptr] + [vl] "=&r"(vl), // %[vl] + [work_src_next] "=&r"(work_src_next) // %[work_src_next] + : [c2] "r"(2), // %[c2] + [c3] "r"(3) // %[c3] + : RVV_VL_CLOBBER "memory", "v12", "v13", "v16", "v17", "v18", "v19", + "v24", "v25", "v26", "v27"); + } + dst_ptr[dst_width - 1] = src_ptr[0]; +} +#endif + +#ifdef HAS_SCALEROWUP2_BILINEAR_RVV +void ScaleRowUp2_Bilinear_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + int src_width = (dst_width - 1) >> 1; + const uint8_t* t = src_ptr + src_stride; + uint8_t* e = dst_ptr + dst_stride; + dst_ptr[0] = (3 * src_ptr[0] + t[0] + 2) >> 2; + e[0] = (src_ptr[0] + 3 * t[0] + 2) >> 2; + if (src_width > 0) { + int vl; + const uint8_t* tmp_ptr; + uint8_t* work_d = dst_ptr + 1; + uint8_t* work_e = e + 1; + asm volatile( + "1: \n" + "vsetvli %[vl], %[src_width], e8, m2, ta, ma\n" + "vle8.v v0, (%[work_s]) \n" + "addi %[tmp_ptr], %[work_s], 1 \n" + "vle8.v v2, (%[tmp_ptr]) \n" + "vwaddu.vx v8, v0, %[c2] \n" + "vwaddu.vx v12, v2, %[c2] \n" + "vwmaccu.vx v8, %[c3], v2 \n" + "vwmaccu.vx v12, %[c3], v0 \n" + "vle8.v v4, (%[work_t]) \n" + "addi %[tmp_ptr], %[work_t], 1 \n" + "vle8.v v6, (%[tmp_ptr]) \n" + "vwaddu.vx v16, v4, %[c2] \n" + "vwaddu.vx v20, v6, %[c2] \n" + "vwmaccu.vx v16, %[c3], v6 \n" + "vwmaccu.vx v20, %[c3], v4 \n" + "vmv4r.v v24, v16 \n" + "vmv4r.v v28, v20 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vmacc.vx v16, %[c3], v8 \n" + "vmacc.vx v20, %[c3], v12 \n" + "vmacc.vx v8, %[c3], v24 \n" + "vmacc.vx v12, %[c3], v28 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + "vnsrl.wi v0, v20, 4 \n" + "vnsrl.wi v2, v16, 4 \n" + "vsseg2e8.v v0, (%[work_d]) \n" + "vnsrl.wi v4, v12, 4 \n" + "vnsrl.wi v6, v8, 4 \n" + "vsseg2e8.v v4, (%[work_e]) \n" + "sub %[src_width], %[src_width], %[vl]\n" + "add %[work_s], %[work_s], %[vl] \n" + "add %[work_t], %[work_t], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[work_d], %[work_d], %[vl] \n" + "add %[work_e], %[work_e], %[vl] \n" + "bgtz %[src_width], 1b \n" + : [src_width] "+r"(src_width), // %[src_width] + [work_s] "+r"(src_ptr), // %[work_s] + [work_t] "+r"(t), // %[work_t] + [work_d] "+r"(work_d), // %[work_d] + [work_e] "+r"(work_e), // %[work_e] + [vl] "=&r"(vl), // %[vl] + [tmp_ptr] "=&r"(tmp_ptr) // %[tmp_ptr] + : [c2] "r"(2), // %[c2] + [c3] "r"(3) // %[c3] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", + "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", + "v27", "v28", "v29", "v30", "v31"); + } + dst_ptr[dst_width - 1] = (3 * src_ptr[0] + t[0] + 2) >> 2; + e[dst_width - 1] = (src_ptr[0] + 3 * t[0] + 2) >> 2; +} +#endif + +#ifdef HAS_SCALEUVROWDOWN2_RVV +void ScaleUVRowDown2_RVV(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + (void)src_stride; + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e16, m2, ta, ma \n" + "vle32.v v8, (%[src_uv]) \n" + "vnsrl.wi v16, v8, 16 \n" + "vse16.v v16, (%[dst_uv]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_uv], %[dst_uv], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_uv], %[src_uv], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17"); +} +#endif + +#ifdef HAS_SCALEUVROWDOWN2LINEAR_RVV +void ScaleUVRowDown2Linear_RVV(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + (void)src_stride; + int vl; + // NOTE: To match behavior on other platforms, vxrm (fixed-point rounding mode + // register) is set to round-to-nearest-up mode(0). + asm volatile( + "csrwi vxrm, 0 \n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v8, (%[src_uv]) \n" + "vaaddu.vv v8, v8, v12 \n" + "vaaddu.vv v10, v10, v14 \n" + "vsseg2e8.v v8, (%[dst_uv]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_uv], %[dst_uv], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_uv], %[src_uv], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15"); +} +#endif + +#ifdef HAS_SCALEUVROWDOWN2BOX_RVV +void ScaleUVRowDown2Box_RVV(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + int vl; + asm volatile( + "add %[src_uv_row1], %[src_uv], %[src_uv_row1]\n" + + "1: \n" + "vsetvli %[vl], %[w], e8, m2, ta, ma \n" + "vlseg4e8.v v14, (%[src_uv]) \n" + "vlseg4e8.v v22, (%[src_uv_row1]) \n" + "vwaddu.vx v8, v14, %[c2] \n" + "vwaddu.wv v8, v8, v18 \n" + "vwaddu.wv v8, v8, v22 \n" + "vwaddu.wv v8, v8, v26 \n" + "vwaddu.vx v12, v16, %[c2] \n" + "vwaddu.wv v12, v12, v20 \n" + "vwaddu.wv v12, v12, v24 \n" + "vwaddu.wv v12, v12, v28 \n" + "vnsrl.wi v16, v8, 2 \n" + "vnsrl.wi v18, v12, 2 \n" + "vsseg2e8.v v16, (%[dst_uv]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_uv], %[dst_uv], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[src_uv], %[src_uv], %[vl] \n" + "add %[src_uv_row1], %[src_uv_row1], %[vl]\n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_uv] "+r"(src_uv), // %[src_uv] + [src_uv_row1] "+r"(src_stride), // %[src_uv_row1] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [vl] "=&r"(vl) // %[vl] + : [c2] "r"(2) // %[c2] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v12", "v13", "v14", + "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", + "v25", "v26", "v27", "v28", "v29"); +} +#endif + +#ifdef HAS_SCALEUVROWDOWN4_RVV +void ScaleUVRowDown4_RVV(const uint8_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_uv, + int dst_width) { + (void)src_stride; + (void)src_stepx; + int vl; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e32, m2, ta, ma \n" + "vle64.v v8, (%[src_uv]) \n" + "vnsrl.wi v16, v8, 0 \n" + "vsetvli zero, zero, e16, m1, ta, ma \n" + "vnsrl.wi v8, v16, 0 \n" + "vse16.v v8, (%[dst_uv]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_uv], %[dst_uv], %[vl] \n" + "slli %[vl], %[vl], 2 \n" + "add %[src_uv], %[src_uv], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [vl] "=&r"(vl) // %[vl] + : + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11", "v16", "v17"); +} +#endif + +#ifdef HAS_SCALEUVROWDOWNEVEN_RVV +void ScaleUVRowDownEven_RVV(const uint8_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_uv, + int dst_width) { + (void)src_stride; + int vl; + ptrdiff_t src_step; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e16, m4, ta, ma \n" + "vlse16.v v8, (%[src_uv]), %[stride_byte]\n" + "vse16.v v8, (%[dst_uv]) \n" + "sub %[w], %[w], %[vl] \n" + "mul %[src_step], %[vl], %[stride_byte]\n" + "add %[src_uv], %[src_uv], %[src_step]\n" + "slli %[vl], %[vl], 1 \n" + "add %[dst_uv], %[dst_uv], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(dst_width), // %[w] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [vl] "=&r"(vl), // %[vl] + [src_step] "=&r"(src_step) // %[src_step] + : [stride_byte] "r"((ptrdiff_t)src_stepx * 2) // %[stride_byte] + : RVV_VL_CLOBBER "memory", "v8", "v9", "v10", "v11"); +} +#endif + +// ScaleUVRowUp2_(Bi)linear_RVV function is equal to other platforms' +// ScaleUVRowUp2_(Bi)linear_Any_XXX. We process entire row in this function. +// Other platforms only implement non-edge part of image and process edge with +// scalar. + +#ifdef HAS_SCALEUVROWUP2_LINEAR_RVV +void ScaleUVRowUp2_Linear_RVV(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + int src_pairs = (dst_width - 1) >> 1; + dst_ptr[0] = src_ptr[0]; + dst_ptr[1] = src_ptr[1]; + if (src_pairs > 0) { + int vl; + const uint8_t* work_src_next; + uint8_t* work_dst_ptr = dst_ptr + 2; + asm volatile( + "1: \n" + "vsetvli %[vl], %[src_pairs], e8, m2, ta, ma\n" + "addi %[work_src_next], %[src_ptr], 2\n" + "vlseg2e8.v v16, (%[work_src_next]) \n" + "vlseg2e8.v v20, (%[src_ptr]) \n" + "vwaddu.vx v12, v16, %[c2] \n" + "vwmaccu.vx v12, %[c3], v20 \n" + "vnsrl.wi v24, v12, 2 \n" + "vwaddu.vx v12, v20, %[c2] \n" + "vwmaccu.vx v12, %[c3], v16 \n" + "vnsrl.wi v28, v12, 2 \n" + "vwaddu.vx v12, v18, %[c2] \n" + "vwmaccu.vx v12, %[c3], v22 \n" + "vnsrl.wi v26, v12, 2 \n" + "vwaddu.vx v12, v22, %[c2] \n" + "vwmaccu.vx v12, %[c3], v18 \n" + "vnsrl.wi v30, v12, 2 \n" + "vsseg4e8.v v24, (%[work_dst_ptr]) \n" + "sub %[src_pairs], %[src_pairs], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[src_ptr], %[src_ptr], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[work_dst_ptr], %[work_dst_ptr], %[vl]\n" + "bgtz %[src_pairs], 1b \n" + : [src_pairs] "+r"(src_pairs), // %[src_pairs] + [src_ptr] "+r"(src_ptr), // %[src_ptr] + [work_dst_ptr] "+r"(work_dst_ptr), // %[work_dst_ptr] + [vl] "=&r"(vl), // %[vl] + [work_src_next] "=&r"(work_src_next) // %[work_src_next] + : [c2] "r"(2), // %[c2] + [c3] "r"(3) // %[c3] + : RVV_VL_CLOBBER "memory", "v12", "v13", "v14", "v15", "v16", "v17", + "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", + "v28", "v29", "v30", "v31"); + } + dst_ptr[2 * dst_width - 2] = src_ptr[0]; + dst_ptr[2 * dst_width - 1] = src_ptr[1]; +} +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_RVV +void ScaleUVRowUp2_Bilinear_RVV(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + int src_pairs = (dst_width - 1) >> 1; + const uint8_t* t = src_ptr + src_stride; + uint8_t* e = dst_ptr + dst_stride; + dst_ptr[0] = (3 * src_ptr[0] + t[0] + 2) >> 2; + e[0] = (src_ptr[0] + 3 * t[0] + 2) >> 2; + dst_ptr[1] = (3 * src_ptr[1] + t[1] + 2) >> 2; + e[1] = (src_ptr[1] + 3 * t[1] + 2) >> 2; + if (src_pairs > 0) { + int vl; + const uint8_t* tmp_ptr; + uint8_t* work_d = dst_ptr + 2; + uint8_t* work_e = e + 2; + asm volatile( + "1: \n" + "vsetvli %[vl], %[src_pairs], e8, m2, ta, ma\n" + // Load s_u0 (v0), s_v0 (v2) and s_u1 (v4), s_v1 (v6) + "vlseg2e8.v v0, (%[work_s]) \n" + "addi %[tmp_ptr], %[work_s], 2 \n" + "vlseg2e8.v v4, (%[tmp_ptr]) \n" + // Load t_u0 (v8), t_v0 (v10) and t_u1 (v12), t_v1 (v14) + "vlseg2e8.v v8, (%[work_t]) \n" + "addi %[tmp_ptr], %[work_t], 2 \n" + "vlseg2e8.v v12, (%[tmp_ptr]) \n" + // Compute U channel horizontal interpolation into v16..v31 + "vwaddu.vx v16, v0, %[c2] \n" + "vwaddu.vx v20, v4, %[c2] \n" + "vwmaccu.vx v16, %[c3], v4 \n" + "vwmaccu.vx v20, %[c3], v0 \n" + "vwaddu.vx v24, v8, %[c2] \n" + "vwaddu.vx v28, v12, %[c2] \n" + "vwmaccu.vx v24, %[c3], v12 \n" + "vwmaccu.vx v28, %[c3], v8 \n" + // Move t_v0 (v10) -> v0, t_v1 (v14) -> v4 so v8..v15 are free + "vmv2r.v v0, v10 \n" + "vmv2r.v v4, v14 \n" + "vmv4r.v v8, v24 \n" + "vmv4r.v v12, v28 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vmacc.vx v24, %[c3], v16 \n" + "vmacc.vx v28, %[c3], v20 \n" + "vmacc.vx v16, %[c3], v8 \n" + "vmacc.vx v20, %[c3], v12 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + // Move s_v0 (v2) -> v8, s_v1 (v6) -> v10, t_v0 (v0) -> v12, t_v1 (v4) + // -> v14 + "vmv2r.v v8, v2 \n" + "vmv2r.v v10, v6 \n" + "vmv2r.v v12, v0 \n" + "vmv2r.v v14, v4 \n" + // Narrow U results into v0 (u_d_even), v2 (u_d_odd), v4 (u_e_even), v6 + // (u_e_odd) + "vnsrl.wi v0, v28, 4 \n" + "vnsrl.wi v2, v24, 4 \n" + "vnsrl.wi v4, v20, 4 \n" + "vnsrl.wi v6, v16, 4 \n" + // Compute V channel horizontal interpolation from v8, v10, v12, v14 + // into v16..v31 + "vwaddu.vx v16, v8, %[c2] \n" + "vwaddu.vx v20, v10, %[c2] \n" + "vwmaccu.vx v16, %[c3], v10 \n" + "vwmaccu.vx v20, %[c3], v8 \n" + "vwaddu.vx v24, v12, %[c2] \n" + "vwaddu.vx v28, v14, %[c2] \n" + "vwmaccu.vx v24, %[c3], v14 \n" + "vwmaccu.vx v28, %[c3], v12 \n" + "vmv4r.v v8, v24 \n" + "vmv4r.v v12, v28 \n" + "vsetvli zero, zero, e16, m4, ta, ma \n" + "vmacc.vx v24, %[c3], v16 \n" + "vmacc.vx v28, %[c3], v20 \n" + "vmacc.vx v16, %[c3], v8 \n" + "vmacc.vx v20, %[c3], v12 \n" + "vsetvli zero, zero, e8, m2, ta, ma \n" + // Assemble and store row 0: (u_d_even, v_d_even, u_d_odd, v_d_odd) in + // v8..v15 + "vmv2r.v v8, v0 \n" + "vnsrl.wi v10, v28, 4 \n" + "vmv2r.v v12, v2 \n" + "vnsrl.wi v14, v24, 4 \n" + "vsseg4e8.v v8, (%[work_d]) \n" + // Assemble and store row 1: (u_e_even, v_e_even, u_e_odd, v_e_odd) in + // v8..v15 + "vmv2r.v v8, v4 \n" + "vnsrl.wi v10, v20, 4 \n" + "vmv2r.v v12, v6 \n" + "vnsrl.wi v14, v16, 4 \n" + "vsseg4e8.v v8, (%[work_e]) \n" + "sub %[src_pairs], %[src_pairs], %[vl]\n" + "slli %[vl], %[vl], 1 \n" + "add %[work_s], %[work_s], %[vl] \n" + "add %[work_t], %[work_t], %[vl] \n" + "slli %[vl], %[vl], 1 \n" + "add %[work_d], %[work_d], %[vl] \n" + "add %[work_e], %[work_e], %[vl] \n" + "bgtz %[src_pairs], 1b \n" + : [src_pairs] "+r"(src_pairs), // %[src_pairs] + [work_s] "+r"(src_ptr), // %[work_s] + [work_t] "+r"(t), // %[work_t] + [work_d] "+r"(work_d), // %[work_d] + [work_e] "+r"(work_e), // %[work_e] + [vl] "=&r"(vl), // %[vl] + [tmp_ptr] "=&r"(tmp_ptr) // %[tmp_ptr] + : [c2] "r"(2), // %[c2] + [c3] "r"(3) // %[c3] + : RVV_VL_CLOBBER "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", + "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", + "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", + "v27", "v28", "v29", "v30", "v31"); + } + dst_ptr[2 * dst_width - 2] = (3 * src_ptr[0] + t[0] + 2) >> 2; + e[2 * dst_width - 2] = (src_ptr[0] + 3 * t[0] + 2) >> 2; + dst_ptr[2 * dst_width - 1] = (3 * src_ptr[1] + t[1] + 2) >> 2; + e[2 * dst_width - 1] = (src_ptr[1] + 3 * t[1] + 2) >> 2; +} +#endif + +#ifdef HAS_SCALEUVADDCOLS3_RVV +void ScaleUVAddCols3_RVV(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { + size_t vl, vl2; + size_t w = (size_t)dst_width; + asm volatile( + "1: \n" + "vsetvli %[vl], %[w], e32, m2, ta, ma \n" + "vlseg3e32.v v8, (%[src_uv]) \n" + "sub %[w], %[w], %[vl] \n" + "slli %[vl2], %[vl], 2 \n" + "add %[src_uv], %[src_uv], %[vl2] \n" + "slli %[vl2], %[vl2], 1 \n" + "add %[src_uv], %[src_uv], %[vl2] \n" + "slli %[vl], %[vl], 1 \n" + "vsetvli zero, %[vl], e16, m2, ta, ma \n" + "vadd.vv v8, v8, v10 \n" + "vadd.vv v8, v8, v12 \n" + "vmulhu.vx v8, v8, %[scaleval] \n" + "vsetvli zero, %[vl], e8, m1, ta, ma \n" + "vnsrl.wi v4, v8, 0 \n" + "vse8.v v4, (%[dst_uv]) \n" + "add %[dst_uv], %[dst_uv], %[vl] \n" + "bgtz %[w], 1b \n" + : [w] "+r"(w), // %[w] + [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [vl] "=&r"(vl), // %[vl] + [vl2] "=&r"(vl2) // %[vl2] + : [scaleval] "r"(scaleval) // %[scaleval] + : RVV_VL_CLOBBER "memory", "v4", "v8", "v9", "v10", "v11", "v12", "v13"); +} +#endif + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_RVV) && defined(__riscv_vector) diff --git a/libs/libyuv/source/scale_sme.cc b/libs/libyuv/source/scale_sme.cc new file mode 100644 index 0000000000..1dc5c17bac --- /dev/null +++ b/libs/libyuv/source/scale_sme.cc @@ -0,0 +1,628 @@ +/* + * Copyright 2024 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/scale_row.h" + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// Note: every register written by an inline asm block (vector, general +// purpose, mask/predicate, "cc" for flags and "memory" for stores) must be +// listed in its clobber list, even when the ABI treats it as caller-saved. +// With LTO/LTCG the compiler may keep values live in any register across the +// asm statement, and other OS ABIs (e.g. Windows) differ in which registers +// are callee-saved. List "memory" first, then "cc", then registers. + +#if !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && \ + defined(__aarch64__) + +__arm_locally_streaming void ScaleRowDown2_SME(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + (void)src_stride; + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "1: \n" + "ptrue p0.b \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_ptr]] \n" + "incb %[src_ptr], all, mul #2 \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "st1b {z1.b}, p0, [%[dst_ptr]] \n" + "incb %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[dst_width] \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_ptr]] \n" + "st1b {z1.b}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst), // %[dst_ptr] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "p0"); +} + +__arm_locally_streaming void ScaleRowDown2_16_SME(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + (void)src_stride; + int vl; + asm volatile( + "cnth %x[vl] \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "1: \n" + "ptrue p0.h \n" + "ld2h {z0.h, z1.h}, p0/z, [%[src_ptr]] \n" + "incb %[src_ptr], all, mul #2 \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "st1h {z1.h}, p0, [%[dst_ptr]] \n" + "incb %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.h, wzr, %w[dst_width] \n" + "ld2h {z0.h, z1.h}, p0/z, [%[src_ptr]] \n" + "st1h {z1.h}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst), // %[dst_ptr] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "p0"); +} + +__arm_locally_streaming void ScaleRowDown2Linear_SME(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + (void)src_stride; + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "1: \n" + "ptrue p0.b \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_ptr]] \n" + "incb %[src_ptr], all, mul #2 \n" + "urhadd z0.b, p0/m, z0.b, z1.b \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "st1b {z0.b}, p0, [%[dst_ptr]] \n" + "incb %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[dst_width] \n" + "ld2b {z0.b, z1.b}, p0/z, [%[src_ptr]] \n" + "urhadd z0.b, p0/m, z0.b, z1.b \n" + "st1b {z0.b}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst), // %[dst_ptr] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "p0"); +} + +__arm_locally_streaming void ScaleRowDown2Linear_16_SME(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + (void)src_stride; + int vl; + asm volatile( + "cnth %x[vl] \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "1: \n" + "ptrue p0.h \n" + "ld2h {z0.h, z1.h}, p0/z, [%[src_ptr]] \n" + "incb %[src_ptr], all, mul #2 \n" + "urhadd z0.h, p0/m, z0.h, z1.h \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "st1h {z0.h}, p0, [%[dst_ptr]] \n" + "incb %[dst_ptr] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.h, wzr, %w[dst_width] \n" + "ld2h {z0.h, z1.h}, p0/z, [%[src_ptr]] \n" + "urhadd z0.h, p0/m, z0.h, z1.h \n" + "st1h {z0.h}, p0, [%[dst_ptr]] \n" + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [dst_ptr] "+r"(dst), // %[dst_ptr] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "p0"); +} + +#define SCALEROWDOWN2BOX_SVE \ + "ld2b {z0.b, z1.b}, p0/z, [%[src_ptr]] \n" \ + "ld2b {z2.b, z3.b}, p0/z, [%[src2_ptr]] \n" \ + "incb %[src_ptr], all, mul #2 \n" \ + "incb %[src2_ptr], all, mul #2 \n" \ + "uaddlb z4.h, z0.b, z1.b \n" \ + "uaddlt z5.h, z0.b, z1.b \n" \ + "uaddlb z6.h, z2.b, z3.b \n" \ + "uaddlt z7.h, z2.b, z3.b \n" \ + "add z4.h, z4.h, z6.h \n" \ + "add z5.h, z5.h, z7.h \n" \ + "rshrnb z0.b, z4.h, #2 \n" \ + "rshrnt z0.b, z5.h, #2 \n" \ + "subs %w[dst_width], %w[dst_width], %w[vl] \n" \ + "st1b {z0.b}, p0, [%[dst_ptr]] \n" \ + "incb %[dst_ptr] \n" + +__arm_locally_streaming void ScaleRowDown2Box_SME(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + const uint8_t* src2_ptr = src_ptr + src_stride; + int vl; + asm volatile( + "cntb %x[vl] \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.b \n" + "1: \n" // + SCALEROWDOWN2BOX_SVE + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.b, wzr, %w[dst_width] \n" // + SCALEROWDOWN2BOX_SVE + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src2_ptr] "+r"(src2_ptr), // %[src2_ptr] + [dst_ptr] "+r"(dst), // %[dst_ptr] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "p0"); +} + +#undef SCALEROWDOWN2BOX_SVE + +#define SCALEROWDOWN2BOX_16_SVE \ + "ld2h {z0.h, z1.h}, p0/z, [%[src_ptr]] \n" \ + "ld2h {z2.h, z3.h}, p0/z, [%[src2_ptr]] \n" \ + "incb %[src_ptr], all, mul #2 \n" \ + "incb %[src2_ptr], all, mul #2 \n" \ + "uaddlb z4.s, z0.h, z1.h \n" \ + "uaddlt z5.s, z0.h, z1.h \n" \ + "uaddlb z6.s, z2.h, z3.h \n" \ + "uaddlt z7.s, z2.h, z3.h \n" \ + "add z4.s, z4.s, z6.s \n" \ + "add z5.s, z5.s, z7.s \n" \ + "rshrnb z0.h, z4.s, #2 \n" \ + "rshrnt z0.h, z5.s, #2 \n" \ + "subs %w[dst_width], %w[dst_width], %w[vl] \n" \ + "st1h {z0.h}, p0, [%[dst_ptr]] \n" \ + "incb %[dst_ptr] \n" + +__arm_locally_streaming void ScaleRowDown2Box_16_SME(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + const uint16_t* src2_ptr = src_ptr + src_stride; + int vl; + asm volatile( + "cnth %x[vl] \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.h \n" + "1: \n" // + SCALEROWDOWN2BOX_16_SVE + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.h, wzr, %w[dst_width] \n" // + SCALEROWDOWN2BOX_16_SVE + + "99: \n" + : [src_ptr] "+r"(src_ptr), // %[src_ptr] + [src2_ptr] "+r"(src2_ptr), // %[src2_ptr] + [dst_ptr] "+r"(dst), // %[dst_ptr] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "p0"); +} + +#undef SCALEROWDOWN2BOX_16_SVE + +__arm_locally_streaming void ScaleUVRowDown2_SME(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + (void)src_stride; + int vl; + asm volatile( + "cnth %x[vl] \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "1: \n" + "ptrue p0.b \n" + "ld2h {z0.h, z1.h}, p0/z, [%[src_uv]] \n" + "incb %[src_uv], all, mul #2 \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "st1h {z1.h}, p0, [%[dst_uv]] \n" + "incb %[dst_uv] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.h, wzr, %w[dst_width] \n" + "ld2h {z0.h, z1.h}, p0/z, [%[src_uv]] \n" + "st1h {z1.h}, p0, [%[dst_uv]] \n" + + "99: \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "p0"); +} + +__arm_locally_streaming void ScaleUVRowDown2Linear_SME(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + (void)src_stride; + int vl; + asm volatile( + "cnth %x[vl] \n" + "ptrue p1.b \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.h \n" + "1: \n" + "ld2h {z0.h, z1.h}, p0/z, [%[src_uv]] \n" + "incb %[src_uv], all, mul #2 \n" + "urhadd z0.b, p1/m, z0.b, z1.b \n" + "st1h {z0.h}, p0, [%[dst_uv]] \n" + "incb %[dst_uv], all, mul #1 \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.h, wzr, %w[dst_width] \n" + "ld2h {z0.h, z1.h}, p0/z, [%[src_uv]] \n" + "urhadd z0.b, p1/m, z0.b, z1.b \n" + "st1h {z0.h}, p0, [%[dst_uv]] \n" + + "99: \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "p0", "p1"); +} + +#define SCALEUVROWDOWN2BOX_SVE \ + "ld2h {z0.h, z1.h}, p0/z, [%[src_uv]] \n" \ + "ld2h {z2.h, z3.h}, p0/z, [%[src2_uv]] \n" \ + "incb %[src_uv], all, mul #2 \n" \ + "incb %[src2_uv], all, mul #2 \n" \ + "uaddlb z4.h, z0.b, z1.b \n" \ + "uaddlt z5.h, z0.b, z1.b \n" \ + "uaddlb z6.h, z2.b, z3.b \n" \ + "uaddlt z7.h, z2.b, z3.b \n" \ + "add z4.h, z4.h, z6.h \n" \ + "add z5.h, z5.h, z7.h \n" \ + "rshrnb z0.b, z4.h, #2 \n" \ + "rshrnt z0.b, z5.h, #2 \n" \ + "st1h {z0.h}, p0, [%[dst_uv]] \n" \ + "incb %[dst_uv], all, mul #1 \n" + +__arm_locally_streaming void ScaleUVRowDown2Box_SME(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + const uint8_t* src2_uv = src_uv + src_stride; + int vl; + asm volatile( + "cnth %x[vl] \n" + "ptrue p1.b \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.h \n" + "1: \n" // + SCALEUVROWDOWN2BOX_SVE + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.h, wzr, %w[dst_width] \n" // + SCALEUVROWDOWN2BOX_SVE + + "99: \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [src2_uv] "+r"(src2_uv), // %[src2_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "p0", + "p1"); +} + +#undef SCALEUVROWDOWN2BOX_SVE + +__arm_locally_streaming void ScaleARGBRowDown2_SME(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + (void)src_stride; + int vl; + asm volatile( + "cntw %x[vl] \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "1: \n" + "ptrue p0.b \n" + "ld2w {z0.s, z1.s}, p0/z, [%[src_argb]] \n" + "incb %[src_argb], all, mul #2 \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "st1w {z1.s}, p0, [%[dst_argb]] \n" + "incb %[dst_argb] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.s, wzr, %w[dst_width] \n" + "ld2w {z0.s, z1.s}, p0/z, [%[src_argb]] \n" + "st1w {z1.s}, p0, [%[dst_argb]] \n" + + "99: \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "p0"); +} + +__arm_locally_streaming void ScaleARGBRowDown2Linear_SME( + const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + (void)src_stride; + int vl; + asm volatile( + "cntw %x[vl] \n" + "ptrue p1.b \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.s \n" + "1: \n" + "ld2w {z0.s, z1.s}, p0/z, [%[src_argb]] \n" + "incb %[src_argb], all, mul #2 \n" + "urhadd z0.b, p1/m, z0.b, z1.b \n" + "st1w {z0.s}, p0, [%[dst_argb]] \n" + "incb %[dst_argb], all, mul #1 \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.s, wzr, %w[dst_width] \n" + "ld2w {z0.s, z1.s}, p0/z, [%[src_argb]] \n" + "urhadd z0.b, p1/m, z0.b, z1.b \n" + "st1w {z0.s}, p0, [%[dst_argb]] \n" + + "99: \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "p0", "p1"); +} + +#define SCALEARGBROWDOWN2BOX_SVE \ + "ld2w {z0.s, z1.s}, p0/z, [%[src_argb]] \n" \ + "ld2w {z2.s, z3.s}, p0/z, [%[src2_argb]] \n" \ + "incb %[src_argb], all, mul #2 \n" \ + "incb %[src2_argb], all, mul #2 \n" \ + "uaddlb z4.h, z0.b, z1.b \n" \ + "uaddlt z5.h, z0.b, z1.b \n" \ + "uaddlb z6.h, z2.b, z3.b \n" \ + "uaddlt z7.h, z2.b, z3.b \n" \ + "add z4.h, z4.h, z6.h \n" \ + "add z5.h, z5.h, z7.h \n" \ + "rshrnb z0.b, z4.h, #2 \n" \ + "rshrnt z0.b, z5.h, #2 \n" \ + "st1w {z0.s}, p0, [%[dst_argb]] \n" \ + "incb %[dst_argb], all, mul #1 \n" + +__arm_locally_streaming void ScaleARGBRowDown2Box_SME(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + // Streaming-SVE only, no use of ZA tile. + const uint8_t* src2_argb = src_argb + src_stride; + int vl; + asm volatile( + "cntw %x[vl] \n" + "ptrue p1.b \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.s \n" + "1: \n" // + SCALEARGBROWDOWN2BOX_SVE + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.s, wzr, %w[dst_width] \n" // + SCALEARGBROWDOWN2BOX_SVE + + "99: \n" + : [src_argb] "+r"(src_argb), // %[src_argb] + [src2_argb] "+r"(src2_argb), // %[src2_argb] + [dst_argb] "+r"(dst_argb), // %[dst_argb] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=r"(vl) // %[vl] + : + : "memory", "cc", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "p0", + "p1"); +} + +// Scale UV columns by 3 box filter using Streaming SVE. +__arm_locally_streaming void ScaleUVAddCols3_SME(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { + // Streaming-SVE only, no use of ZA tile. + int vl; + int vl_w; + asm volatile( + "cnth %x[vl] \n" + "cntw %x[vl_w] \n" + "dup z6.h, %w[scaleval] \n" + "ptrue p3.h \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "b.lt 2f \n" + + "ptrue p0.s \n" + "ptrue p1.h \n" + "1: \n" + "ld3w {z0.s, z1.s, z2.s}, p0/z, [%[src_uv]] \n" + "incb %[src_uv], all, mul #3 \n" + "ld3w {z3.s, z4.s, z5.s}, p0/z, [%[src_uv]] \n" + "incb %[src_uv], all, mul #3 \n" + "subs %w[dst_width], %w[dst_width], %w[vl] \n" + "add z0.h, z0.h, z1.h \n" + "add z3.h, z3.h, z4.h \n" + "add z0.h, z0.h, z2.h \n" + "add z3.h, z3.h, z5.h \n" + "umulh z0.h, p3/m, z0.h, z6.h \n" + "umulh z3.h, p3/m, z3.h, z6.h \n" + "uzp1 z0.b, z0.b, z3.b \n" + "st1h {z0.h}, p1, [%[dst_uv]] \n" + "incb %[dst_uv] \n" + "b.ge 1b \n" + + "2: \n" + "adds %w[dst_width], %w[dst_width], %w[vl] \n" + "b.eq 99f \n" + + "whilelt p0.s, wzr, %w[dst_width] \n" + "whilelt p2.s, %w[vl_w], %w[dst_width] \n" + "whilelt p1.h, wzr, %w[dst_width] \n" + "ld3w {z0.s, z1.s, z2.s}, p0/z, [%[src_uv]] \n" + "incb %[src_uv], all, mul #3 \n" + "ld3w {z3.s, z4.s, z5.s}, p2/z, [%[src_uv]] \n" + "add z0.h, z0.h, z1.h \n" + "add z3.h, z3.h, z4.h \n" + "add z0.h, z0.h, z2.h \n" + "add z3.h, z3.h, z5.h \n" + "umulh z0.h, p3/m, z0.h, z6.h \n" + "umulh z3.h, p3/m, z3.h, z6.h \n" + "uzp1 z0.b, z0.b, z3.b \n" + "st1h {z0.h}, p1, [%[dst_uv]] \n" + + "99: \n" + : [src_uv] "+r"(src_uv), // %[src_uv] + [dst_uv] "+r"(dst_uv), // %[dst_uv] + [dst_width] "+r"(dst_width), // %[dst_width] + [vl] "=&r"(vl), // %[vl] + [vl_w] "=&r"(vl_w) // %[vl_w] + : [scaleval] "r"(scaleval) // %[scaleval] + : "memory", "cc", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "p0", "p1", + "p2", "p3"); +} + +#endif // !defined(LIBYUV_DISABLE_SME) && defined(CLANG_HAS_SME) && + // defined(__aarch64__) + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif diff --git a/libs/libyuv/source/scale_uv.cc b/libs/libyuv/source/scale_uv.cc new file mode 100644 index 0000000000..706f27a80a --- /dev/null +++ b/libs/libyuv/source/scale_uv.cc @@ -0,0 +1,1986 @@ +/* + * Copyright 2020 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/scale_uv.h" + +#include +#include +#include + +#include "libyuv/cpu_id.h" +#include "libyuv/planar_functions.h" // For CopyUV +#include "libyuv/row.h" +#include "libyuv/scale_row.h" + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// Macros to enable specialized scalers + +#ifndef HAS_SCALEUVDOWN2 +#define HAS_SCALEUVDOWN2 1 +#endif +#ifndef HAS_SCALEUVDOWN4BOX +#define HAS_SCALEUVDOWN4BOX 1 +#endif +#ifndef HAS_SCALEUVDOWNEVEN +#define HAS_SCALEUVDOWNEVEN 1 +#endif +#ifndef HAS_SCALEUVBOX +#define HAS_SCALEUVBOX 1 +#endif +#ifndef HAS_SCALEUVBILINEARDOWN +#define HAS_SCALEUVBILINEARDOWN 1 +#endif +#ifndef HAS_SCALEUVBILINEARUP +#define HAS_SCALEUVBILINEARUP 1 +#endif +#ifndef HAS_UVCOPY +#define HAS_UVCOPY 1 +#endif +#ifndef HAS_SCALEPLANEVERTICAL +#define HAS_SCALEPLANEVERTICAL 1 +#endif + +#define MIN1(x) ((x) < 1 ? 1 : (x)) + +// ScaleUV, 1/2 +// This is an optimized version for scaling down a UV to 1/2 of +// its original size. +#if HAS_SCALEUVDOWN2 +static void ScaleUVDown2(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_uv, + uint8_t* dst_uv, + int x, + int dx, + int y, + int dy, + enum FilterMode filtering) { + int j; + ptrdiff_t row_stride = src_stride * (dy >> 16); + void (*ScaleUVRowDown2)(const uint8_t* src_uv, ptrdiff_t src_stride, + uint8_t* dst_uv, int dst_width) = + filtering == kFilterNone + ? ScaleUVRowDown2_C + : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_C + : ScaleUVRowDown2Box_C); + (void)src_width; + (void)src_height; + (void)dx; + assert(dx == 65536 * 2); // Test scale factor of 2. + assert((dy & 0x1ffff) == 0); // Test vertical scale is multiple of 2. + // Advance to odd row, even column. + if (filtering) { + src_uv += (y >> 16) * src_stride + (x >> 16) * 2; + } else { + src_uv += (y >> 16) * src_stride + ((x >> 16) - 1) * 2; + } + +#if defined(HAS_SCALEUVROWDOWN2_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleUVRowDown2 = + filtering == kFilterNone + ? ScaleUVRowDown2_Any_AVX2 + : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_Any_AVX2 + : ScaleUVRowDown2Box_Any_AVX2); + if (IS_ALIGNED(dst_width, 8)) { + ScaleUVRowDown2 = + filtering == kFilterNone + ? ScaleUVRowDown2_AVX2 + : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_AVX2 + : ScaleUVRowDown2Box_AVX2); + } + } +#endif +#if defined(HAS_SCALEUVROWDOWN2_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ScaleUVRowDown2 = + filtering == kFilterNone + ? ScaleUVRowDown2_Any_NEON + : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_Any_NEON + : ScaleUVRowDown2Box_Any_NEON); + if (IS_ALIGNED(dst_width, 8)) { + ScaleUVRowDown2 = + filtering == kFilterNone + ? ScaleUVRowDown2_NEON + : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_NEON + : ScaleUVRowDown2Box_NEON); + } + } +#endif +#if defined(HAS_SCALEUVROWDOWN2_SME) + if (TestCpuFlag(kCpuHasSME)) { + ScaleUVRowDown2 = filtering == kFilterNone ? ScaleUVRowDown2_SME + : filtering == kFilterLinear ? ScaleUVRowDown2Linear_SME + : ScaleUVRowDown2Box_SME; + } +#endif +#if defined(HAS_SCALEUVROWDOWN2_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleUVRowDown2 = + filtering == kFilterNone + ? ScaleUVRowDown2_RVV + : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_RVV + : ScaleUVRowDown2Box_RVV); + } +#endif +#if defined(HAS_SCALEUVROWDOWN2_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ScaleUVRowDown2 = + filtering == kFilterNone + ? ScaleUVRowDown2_HVX + : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_HVX + : ScaleUVRowDown2Box_HVX); + } +#endif + + if (filtering == kFilterLinear) { + src_stride = 0; + } + for (j = 0; j < dst_height; ++j) { + ScaleUVRowDown2(src_uv, src_stride, dst_uv, dst_width); + src_uv += row_stride; + dst_uv += dst_stride; + } +} + +static void ScaleUVDown2_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_uv, + uint16_t* dst_uv, + int x, + int dx, + int y, + int dy, + enum FilterMode filtering) { + int j; + ptrdiff_t row_stride = src_stride * (dy >> 16); + void (*ScaleUVRowDown2)(const uint16_t* src_uv, ptrdiff_t src_stride, + uint16_t* dst_uv, int dst_width) = + filtering == kFilterNone + ? ScaleUVRowDown2_16_C + : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_16_C + : ScaleUVRowDown2Box_16_C); + (void)src_width; + (void)src_height; + (void)dx; + assert(dx == 65536 * 2); // Test scale factor of 2. + assert((dy & 0x1ffff) == 0); // Test vertical scale is multiple of 2. + // Advance to odd row, even column. + if (filtering) { + src_uv += (y >> 16) * src_stride + (x >> 16) * 2; + } else { + src_uv += (y >> 16) * src_stride + ((x >> 16) - 1) * 2; + } + + if (filtering == kFilterLinear) { + src_stride = 0; + } + for (j = 0; j < dst_height; ++j) { + ScaleUVRowDown2(src_uv, src_stride, dst_uv, dst_width); + src_uv += row_stride; + dst_uv += dst_stride; + } +} +#endif // HAS_SCALEUVDOWN2 + +// ScaleUV, 1/4 +// This is an optimized version for scaling down a UV to 1/4 of +// its original size. +#if HAS_SCALEUVDOWN4BOX +static int ScaleUVDown4Box(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_uv, + uint8_t* dst_uv, + int x, + int dx, + int y, + int dy) { + int j; + // Allocate 2 rows of UV. + const int row_size = (dst_width * 2 * 2 + 15) & ~15; + align_buffer_64(row, row_size * 2); + if (!row) + return 1; + ptrdiff_t row_stride = src_stride * (dy >> 16); + void (*ScaleUVRowDown2)(const uint8_t* src_uv, ptrdiff_t src_stride, + uint8_t* dst_uv, int dst_width) = + ScaleUVRowDown2Box_C; + // Advance to odd row, even column. + src_uv += (y >> 16) * src_stride + (x >> 16) * 2; + (void)src_width; + (void)src_height; + (void)dx; + assert(dx == 65536 * 4); // Test scale factor of 4. + assert((dy & 0x3ffff) == 0); // Test vertical scale is multiple of 4. + +#if defined(HAS_SCALEUVROWDOWN2BOX_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleUVRowDown2 = ScaleUVRowDown2Box_Any_AVX2; + if (IS_ALIGNED(dst_width, 8)) { + ScaleUVRowDown2 = ScaleUVRowDown2Box_AVX2; + } + } +#endif +#if defined(HAS_SCALEUVROWDOWN2BOX_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ScaleUVRowDown2 = ScaleUVRowDown2Box_Any_NEON; + if (IS_ALIGNED(dst_width, 8)) { + ScaleUVRowDown2 = ScaleUVRowDown2Box_NEON; + } + } +#endif +#if defined(HAS_SCALEUVROWDOWN2_SME) + if (TestCpuFlag(kCpuHasSME)) { + ScaleUVRowDown2 = ScaleUVRowDown2Box_SME; + } +#endif +#if defined(HAS_SCALEUVROWDOWN2BOX_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleUVRowDown2 = ScaleUVRowDown2Box_RVV; + } +#endif +#if defined(HAS_SCALEUVROWDOWN2BOX_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ScaleUVRowDown2 = ScaleUVRowDown2Box_HVX; + } +#endif + + for (j = 0; j < dst_height; ++j) { + ScaleUVRowDown2(src_uv, src_stride, row, dst_width * 2); + ScaleUVRowDown2(src_uv + src_stride * 2, src_stride, row + row_size, + dst_width * 2); + ScaleUVRowDown2(row, row_size, dst_uv, dst_width); + src_uv += row_stride; + dst_uv += dst_stride; + } + free_aligned_buffer_64(row); + return 0; +} + +static int ScaleUVDown4Box_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_uv, + uint16_t* dst_uv, + int x, + int dx, + int y, + int dy) { + int j; + // Allocate 2 rows of 16-bit UV. + const int row_stride_words = (dst_width * 2 * 2 + 15) & ~15; + align_buffer_64(row, row_stride_words * 2 * (int)sizeof(uint16_t)); + if (!row) + return 1; + uint16_t* row16 = (uint16_t*)row; + ptrdiff_t row_stride = src_stride * (dy >> 16); + void (*ScaleUVRowDown2)(const uint16_t* src_uv, ptrdiff_t src_stride, + uint16_t* dst_uv, int dst_width) = + ScaleUVRowDown2Box_16_C; + // Advance to odd row, even column. + src_uv += (y >> 16) * src_stride + (x >> 16) * 2; + (void)src_width; + (void)src_height; + (void)dx; + assert(dx == 65536 * 4); // Test scale factor of 4. + assert((dy & 0x3ffff) == 0); // Test vertical scale is multiple of 4. + + for (j = 0; j < dst_height; ++j) { + ScaleUVRowDown2(src_uv, src_stride, row16, dst_width * 2); + ScaleUVRowDown2(src_uv + src_stride * 2, src_stride, + row16 + row_stride_words, dst_width * 2); + ScaleUVRowDown2(row16, row_stride_words, dst_uv, dst_width); + src_uv += row_stride; + dst_uv += dst_stride; + } + free_aligned_buffer_64(row); + return 0; +} +#endif // HAS_SCALEUVDOWN4BOX + +// ScaleUV, any dimensions, box filter. +// The counterpart of ScalePlaneBox in scale.cc. Rows are summed into 16 bit +// accumulators, then each destination pixel averages its box of source pixels. +#if HAS_SCALEUVBOX +static void ScaleUVAddCols1_C(int dst_width, + int boxheight, + int x, + int dx, + const uint16_t* src_uv, + uint8_t* dst_uv) { + int i, j; + int boxwidth = MIN1(dx >> 16); + int scaleval = 65536 / (boxwidth * boxheight); + x >>= 16; + for (i = 0; i < dst_width; ++i) { + int u = 0; + int v = 0; + for (j = 0; j < boxwidth; ++j) { + u += src_uv[(x + j) * 2]; + v += src_uv[(x + j) * 2 + 1]; + } + x += boxwidth; + *dst_uv++ = (uint8_t)(u * scaleval >> 16); + *dst_uv++ = (uint8_t)(v * scaleval >> 16); + } +} + +static void ScaleUVAddCols2_C(int dst_width, + int boxheight, + int x, + int dx, + const uint16_t* src_uv, + uint8_t* dst_uv) { + int i, j; + int minboxwidth = dx >> 16; + int scaletbl[2]; + scaletbl[0] = 65536 / (MIN1(minboxwidth) * boxheight); + scaletbl[1] = 65536 / (MIN1(minboxwidth + 1) * boxheight); + for (i = 0; i < dst_width; ++i) { + int ix = x >> 16; + int u = 0; + int v = 0; + int boxwidth; + int scaleval; + x += dx; + boxwidth = MIN1((x >> 16) - ix); + assert((boxwidth - minboxwidth == 0) || (boxwidth - minboxwidth == 1)); + scaleval = scaletbl[boxwidth - minboxwidth]; + for (j = 0; j < boxwidth; ++j) { + u += src_uv[(ix + j) * 2]; + v += src_uv[(ix + j) * 2 + 1]; + } + *dst_uv++ = (uint8_t)(u * scaleval >> 16); + *dst_uv++ = (uint8_t)(v * scaleval >> 16); + } +} + +static int ScaleUVBox(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_uv, + uint8_t* dst_uv, + int x, + int dx, + int y, + int dy) { + int j, k; + const uint32_t max_y = (uint32_t)src_height << 16; + // Sized on src_width to keep ScaleAddRow aligned. + const int row_samples = src_width * 2; + { + // Row accumulator, two uint16_t per source pixel. + align_buffer_64(row16, row_samples * 2); + if (!row16) + return 1; + { + void (*ScaleUVAddCols)(int dst_width, int boxheight, int x, int dx, + const uint16_t* src_uv, uint8_t* dst_uv) = + (dx & 0xffff) ? ScaleUVAddCols2_C : ScaleUVAddCols1_C; + void (*ScaleUVAddCols3)(int dst_width, int scaleval, + const uint16_t* src_uv, uint8_t* dst_uv) = NULL; + // Summing a row is position wise, so an interleaved UV row can be fed to + // the plane accumulator as src_width * 2 samples. + void (*ScaleAddRow)(const uint8_t* src_ptr, uint16_t* dst_ptr, + int src_width) = ScaleAddRow_C; + if (dx == 0x30000) { + ScaleUVAddCols3 = ScaleUVAddCols3_C; +#if defined(HAS_SCALEUVADDCOLS3_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleUVAddCols3 = ScaleUVAddCols3_Any_AVX2; + if (IS_ALIGNED(dst_width, 8)) { + ScaleUVAddCols3 = ScaleUVAddCols3_AVX2; + } + } +#endif +#if defined(HAS_SCALEUVADDCOLS3_AVX512VBMI) + if (TestCpuFlag(kCpuHasAVX512VBMI)) { + ScaleUVAddCols3 = ScaleUVAddCols3_AVX512VBMI; + } +#endif +#if defined(HAS_SCALEUVADDCOLS3_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ScaleUVAddCols3 = ScaleUVAddCols3_Any_NEON; + if (IS_ALIGNED(dst_width, 8)) { + ScaleUVAddCols3 = ScaleUVAddCols3_NEON; + } + } +#endif +#if defined(HAS_SCALEUVADDCOLS3_SME) + if (TestCpuFlag(kCpuHasSME)) { + ScaleUVAddCols3 = ScaleUVAddCols3_SME; + } +#endif +#if defined(HAS_SCALEUVADDCOLS3_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleUVAddCols3 = ScaleUVAddCols3_RVV; + } +#endif +#if defined(HAS_SCALEUVADDCOLS3_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ScaleUVAddCols3 = ScaleUVAddCols3_Any_LSX; + if (IS_ALIGNED(dst_width, 8)) { + ScaleUVAddCols3 = ScaleUVAddCols3_LSX; + } + } +#endif +#if defined(HAS_SCALEUVADDCOLS3_WASMSIMD) + if (TestCpuFlag(kCpuHasWASM)) { + ScaleUVAddCols3 = ScaleUVAddCols3_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 8)) { + ScaleUVAddCols3 = ScaleUVAddCols3_WASMSIMD; + } + } +#endif +#if defined(HAS_SCALEUVADDCOLS3_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ScaleUVAddCols3 = ScaleUVAddCols3_HVX; + } +#endif + } +#if defined(HAS_SCALEADDROW_SSE2) + if (TestCpuFlag(kCpuHasSSE2)) { + ScaleAddRow = ScaleAddRow_Any_SSE2; + if (IS_ALIGNED(row_samples, 16)) { + ScaleAddRow = ScaleAddRow_SSE2; + } + } +#endif +#if defined(HAS_SCALEADDROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleAddRow = ScaleAddRow_Any_AVX2; + if (IS_ALIGNED(row_samples, 32)) { + ScaleAddRow = ScaleAddRow_AVX2; + } + } +#endif +#if defined(HAS_SCALEADDROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + ScaleAddRow = ScaleAddRow_AVX512BW; + } +#endif +#if defined(HAS_SCALEADDROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + ScaleAddRow = ScaleAddRow_Any_NEON; + if (IS_ALIGNED(row_samples, 16)) { + ScaleAddRow = ScaleAddRow_NEON; + } + } +#endif +#if defined(HAS_SCALEADDROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + ScaleAddRow = ScaleAddRow_Any_LSX; + if (IS_ALIGNED(row_samples, 16)) { + ScaleAddRow = ScaleAddRow_LSX; + } + } +#endif +#if defined(HAS_SCALEADDROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + ScaleAddRow = ScaleAddRow_RVV; + } +#endif +#if defined(HAS_SCALEADDROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + ScaleAddRow = ScaleAddRow_HVX; + } +#endif +#if defined(HAS_SCALEADDROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASM)) { + ScaleAddRow = ScaleAddRow_Any_WASMSIMD; + if (IS_ALIGNED(row_samples, 16)) { + ScaleAddRow = ScaleAddRow_WASMSIMD; + } + } +#endif + + uint32_t uy = y; + for (j = 0; j < dst_height; ++j) { + int boxheight; + int iy = uy >> 16; + const uint8_t* src = src_uv + iy * src_stride; + uy += dy; + if (uy > max_y) { + uy = max_y; + } + boxheight = MIN1((int)(uy >> 16) - iy); + memset(row16, 0, row_samples * 2); + for (k = 0; k < boxheight; ++k) { + ScaleAddRow(src, (uint16_t*)(row16), row_samples); + src += src_stride; + } + if (ScaleUVAddCols3 && boxheight <= 85) { + ScaleUVAddCols3(dst_width, 65536 / (3 * boxheight), + (const uint16_t*)row16 + (ptrdiff_t)(x >> 16) * 2, + dst_uv); + } else { + ScaleUVAddCols(dst_width, boxheight, x, dx, (uint16_t*)(row16), + dst_uv); + } + dst_uv += dst_stride; + } + } + free_aligned_buffer_64(row16); + } + return 0; +} + +static void ScaleUVAddCols1_16_C(int dst_width, + int boxheight, + int x, + int dx, + const uint32_t* src_uv, + uint16_t* dst_uv) { + int i, j; + int boxwidth = MIN1(dx >> 16); + uint32_t scaleval = 65536 / (boxwidth * boxheight); + x >>= 16; + for (i = 0; i < dst_width; ++i) { + uint32_t u = 0; + uint32_t v = 0; + for (j = 0; j < boxwidth; ++j) { + u += src_uv[(x + j) * 2]; + v += src_uv[(x + j) * 2 + 1]; + } + x += boxwidth; + *dst_uv++ = (uint16_t)((u * scaleval) >> 16); + *dst_uv++ = (uint16_t)((v * scaleval) >> 16); + } +} + +static void ScaleUVAddCols2_16_C(int dst_width, + int boxheight, + int x, + int dx, + const uint32_t* src_uv, + uint16_t* dst_uv) { + int i, j; + int minboxwidth = dx >> 16; + uint32_t scaletbl[2]; + scaletbl[0] = 65536 / (MIN1(minboxwidth) * boxheight); + scaletbl[1] = 65536 / (MIN1(minboxwidth + 1) * boxheight); + for (i = 0; i < dst_width; ++i) { + int ix = x >> 16; + uint32_t u = 0; + uint32_t v = 0; + int boxwidth; + uint32_t scaleval; + x += dx; + boxwidth = MIN1((x >> 16) - ix); + assert((boxwidth - minboxwidth == 0) || (boxwidth - minboxwidth == 1)); + scaleval = scaletbl[boxwidth - minboxwidth]; + for (j = 0; j < boxwidth; ++j) { + u += src_uv[(ix + j) * 2]; + v += src_uv[(ix + j) * 2 + 1]; + } + *dst_uv++ = (uint16_t)((u * scaleval) >> 16); + *dst_uv++ = (uint16_t)((v * scaleval) >> 16); + } +} + +static int ScaleUVBox_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_uv, + uint16_t* dst_uv, + int x, + int dx, + int y, + int dy) { + int j, k; + const uint32_t max_y = (uint32_t)src_height << 16; + const int row_samples = src_width * 2; + { + // Row accumulator, two uint32_t per source UV pixel. + align_buffer_64(row32_buf, row_samples * (int)sizeof(uint32_t)); + if (!row32_buf) + return 1; + { + uint32_t* row32 = (uint32_t*)row32_buf; + void (*ScaleUVAddCols)(int dst_width, int boxheight, int x, int dx, + const uint32_t* src_uv, uint16_t* dst_uv) = + (dx & 0xffff) ? ScaleUVAddCols2_16_C : ScaleUVAddCols1_16_C; + void (*ScaleUVAddCols3)(int dst_width, int scaleval, + const uint32_t* src_uv, uint16_t* dst_uv) = + (dx == 0x30000) ? ScaleUVAddCols3_16_C : NULL; + void (*ScaleAddRow)(const uint16_t* src_ptr, uint32_t* dst_ptr, + int src_width) = ScaleAddRow_16_C; + + uint32_t uy = y; + for (j = 0; j < dst_height; ++j) { + int boxheight; + int iy = uy >> 16; + const uint16_t* src = src_uv + iy * src_stride; + uy += dy; + if (uy > max_y) { + uy = max_y; + } + boxheight = MIN1((int)(uy >> 16) - iy); + memset(row32, 0, row_samples * sizeof(uint32_t)); + for (k = 0; k < boxheight; ++k) { + ScaleAddRow(src, row32, row_samples); + src += src_stride; + } + if (ScaleUVAddCols3 && boxheight <= 21845) { + ScaleUVAddCols3(dst_width, 65536 / (3 * boxheight), + row32 + (ptrdiff_t)(x >> 16) * 2, dst_uv); + } else { + ScaleUVAddCols(dst_width, boxheight, x, dx, row32, dst_uv); + } + dst_uv += dst_stride; + } + } + free_aligned_buffer_64(row32_buf); + } + return 0; +} +#endif // HAS_SCALEUVBOX + +// ScaleUV Even +// This is an optimized version for scaling down a UV to even +// multiple of its original size. +#if HAS_SCALEUVDOWNEVEN +static void ScaleUVDownEven(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_uv, + uint8_t* dst_uv, + int x, + int dx, + int y, + int dy, + enum FilterMode filtering) { + int j; + int col_step = dx >> 16; + ptrdiff_t row_stride = (dy >> 16) * src_stride; + void (*ScaleUVRowDownEven)(const uint8_t* src_uv, ptrdiff_t src_stride, + int src_step, uint8_t* dst_uv, int dst_width) = + filtering ? ScaleUVRowDownEvenBox_C : ScaleUVRowDownEven_C; + (void)src_width; + (void)src_height; + assert(IS_ALIGNED(src_width, 2)); + assert(IS_ALIGNED(src_height, 2)); + src_uv += (y >> 16) * src_stride + (x >> 16) * 2; +#if defined(HAS_SCALEUVROWDOWNEVEN_AVX2) + if (TestCpuFlag(kCpuHasAVX2) && !filtering) { + ScaleUVRowDownEven = ScaleUVRowDownEven_Any_AVX2; + if (IS_ALIGNED(dst_width, 8)) { + ScaleUVRowDownEven = ScaleUVRowDownEven_AVX2; + } + } +#endif +#if defined(HAS_SCALEUVROWDOWNEVEN_NEON) + if (TestCpuFlag(kCpuHasNEON) && !filtering) { + ScaleUVRowDownEven = ScaleUVRowDownEven_Any_NEON; + if (IS_ALIGNED(dst_width, 4)) { + ScaleUVRowDownEven = ScaleUVRowDownEven_NEON; + } + } +#endif // TODO(fbarchard): Enable Box filter +#if defined(HAS_SCALEUVROWDOWNEVEN_RVV) || defined(HAS_SCALEUVROWDOWN4_RVV) + if (TestCpuFlag(kCpuHasRVV) && !filtering) { +#if defined(HAS_SCALEUVROWDOWNEVEN_RVV) + ScaleUVRowDownEven = ScaleUVRowDownEven_RVV; +#endif +#if defined(HAS_SCALEUVROWDOWN4_RVV) + if (col_step == 4) { + ScaleUVRowDownEven = ScaleUVRowDown4_RVV; + } +#endif + } +#endif + + if (filtering == kFilterLinear) { + src_stride = 0; + } + for (j = 0; j < dst_height; ++j) { + ScaleUVRowDownEven(src_uv, src_stride, col_step, dst_uv, dst_width); + src_uv += row_stride; + dst_uv += dst_stride; + } +} + +static void ScaleUVDownEven_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_uv, + uint16_t* dst_uv, + int x, + int dx, + int y, + int dy, + enum FilterMode filtering) { + int j; + int col_step = dx >> 16; + ptrdiff_t row_stride = (dy >> 16) * src_stride; + void (*ScaleUVRowDownEven)(const uint16_t* src_uv, ptrdiff_t src_stride, + int src_step, uint16_t* dst_uv, int dst_width) = + filtering ? ScaleUVRowDownEvenBox_16_C : ScaleUVRowDownEven_16_C; + (void)src_width; + (void)src_height; + assert(IS_ALIGNED(src_width, 2)); + assert(IS_ALIGNED(src_height, 2)); + src_uv += (y >> 16) * src_stride + (x >> 16) * 2; + + if (filtering == kFilterLinear) { + src_stride = 0; + } + for (j = 0; j < dst_height; ++j) { + ScaleUVRowDownEven(src_uv, src_stride, col_step, dst_uv, dst_width); + src_uv += row_stride; + dst_uv += dst_stride; + } +} +#endif + +// Scale UV down with bilinear interpolation. +#if HAS_SCALEUVBILINEARDOWN +static int ScaleUVBilinearDown(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_uv, + uint8_t* dst_uv, + int x, + int dx, + int y, + int dy, + enum FilterMode filtering) { + int j; + void (*InterpolateRow)(uint8_t* dst_uv, const uint8_t* src_uv, + ptrdiff_t src_stride, int dst_width, + int source_y_fraction) = InterpolateRow_C; + void (*ScaleUVFilterCols)(uint8_t* dst_uv, const uint8_t* src_uv, + int dst_width, int x, int dx) = + (src_width >= 32768) ? ScaleUVFilterCols64_C : ScaleUVFilterCols_C; + int64_t xlast = x + (int64_t)(dst_width - 1) * dx; + int64_t xl = (dx >= 0) ? x : xlast; + int64_t xr = (dx >= 0) ? xlast : x; + int clip_src_width; + xl = (xl >> 16) & ~3; // Left edge aligned. + xr = (xr >> 16) + 1; // Right most pixel used. Bilinear uses 2 pixels. + xr = (xr + 1 + 3) & ~3; // 1 beyond 4 pixel aligned right most pixel. + if (xr > src_width) { + xr = src_width; + } + clip_src_width = (int)(xr - xl) * 2; // Width aligned to 2. + src_uv += xl * 2; + x -= (int)(xl << 16); +#if defined(HAS_INTERPOLATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + InterpolateRow = InterpolateRow_Any_AVX2; + if (IS_ALIGNED(clip_src_width, 32)) { + InterpolateRow = InterpolateRow_AVX2; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_AVX512BW; + } +#endif +#if defined(HAS_INTERPOLATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + InterpolateRow = InterpolateRow_Any_NEON; + if (IS_ALIGNED(clip_src_width, 16)) { + InterpolateRow = InterpolateRow_NEON; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + InterpolateRow = InterpolateRow_SVE2; + } +#endif +#if defined(HAS_INTERPOLATEROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + InterpolateRow = InterpolateRow_Any_LSX; + if (IS_ALIGNED(clip_src_width, 16)) { + InterpolateRow = InterpolateRow_LSX; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + InterpolateRow = InterpolateRow_Any_LASX; + if (IS_ALIGNED(clip_src_width, 32)) { + InterpolateRow = InterpolateRow_LASX; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + InterpolateRow = InterpolateRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_HVX; + } +#endif +#if defined(HAS_INTERPOLATEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_Any_WASMSIMD; + if (IS_ALIGNED(clip_src_width, 16)) { + InterpolateRow = InterpolateRow_WASMSIMD; + } + } +#endif + // TODO(fbarchard): Consider not allocating row buffer for kFilterLinear. + // Allocate a row of UV. + { + const uint32_t max_y = (uint32_t)(src_height - 1) << 16; + uint32_t uy = y; + // clip_src_width is already in bytes (2 per UV pixel). + align_buffer_64(row, clip_src_width); + if (!row) + return 1; + if (uy > max_y) { + uy = max_y; + } + for (j = 0; j < dst_height; ++j) { + int yi = uy >> 16; + const uint8_t* src = src_uv + yi * src_stride; + if (filtering == kFilterLinear) { + ScaleUVFilterCols(dst_uv, src, dst_width, x, dx); + } else { + int yf = (uy >> 8) & 255; + InterpolateRow(row, src, src_stride, clip_src_width, yf); + ScaleUVFilterCols(dst_uv, row, dst_width, x, dx); + } + dst_uv += dst_stride; + uy += dy; + if (uy > max_y) { + uy = max_y; + } + } + free_aligned_buffer_64(row); + } + return 0; +} + +static int ScaleUVBilinearDown_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_uv, + uint16_t* dst_uv, + int x, + int dx, + int y, + int dy, + enum FilterMode filtering) { + int j; + void (*InterpolateRow)(uint16_t* dst_uv, const uint16_t* src_uv, + ptrdiff_t src_stride, int dst_width, + int source_y_fraction) = InterpolateRow_16_C; + void (*ScaleUVFilterCols)(uint16_t* dst_uv, const uint16_t* src_uv, + int dst_width, int x, int dx) = + (src_width >= 32768) ? ScaleUVFilterCols64_16_C : ScaleUVFilterCols_16_C; + int64_t xlast = x + (int64_t)(dst_width - 1) * dx; + int64_t xl = (dx >= 0) ? x : xlast; + int64_t xr = (dx >= 0) ? xlast : x; + int clip_src_width; + xl = (xl >> 16) & ~3; // Left edge aligned. + xr = (xr >> 16) + 1; // Right most pixel used. Bilinear uses 2 pixels. + xr = (xr + 1 + 3) & ~3; // 1 beyond 4 pixel aligned right most pixel. + if (xr > src_width) { + xr = src_width; + } + clip_src_width = (int)(xr - xl) * 2; // Width in uint16_t words. + src_uv += xl * 2; + x -= (int)(xl << 16); +#if defined(HAS_INTERPOLATEROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + InterpolateRow = InterpolateRow_16_Any_AVX2; + if (IS_ALIGNED(clip_src_width, 16)) { + InterpolateRow = InterpolateRow_16_AVX2; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_16_AVX512BW; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + InterpolateRow = InterpolateRow_16_Any_NEON; + if (IS_ALIGNED(clip_src_width, 8)) { + InterpolateRow = InterpolateRow_16_NEON; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_16_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_16_HVX; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_16_Any_WASMSIMD; + if (IS_ALIGNED(clip_src_width, 8)) { + InterpolateRow = InterpolateRow_16_WASMSIMD; + } + } +#endif + // Allocate a row of 16-bit UV. + { + const uint32_t max_y = (uint32_t)(src_height - 1) << 16; + uint32_t uy = y; + align_buffer_64(row, clip_src_width * (int)sizeof(uint16_t)); + if (!row) + return 1; + uint16_t* row16 = (uint16_t*)row; + if (uy > max_y) { + uy = max_y; + } + for (j = 0; j < dst_height; ++j) { + int yi = uy >> 16; + const uint16_t* src = src_uv + yi * src_stride; + if (filtering == kFilterLinear) { + ScaleUVFilterCols(dst_uv, src, dst_width, x, dx); + } else { + int yf = (uy >> 8) & 255; + InterpolateRow(row16, src, src_stride, clip_src_width, yf); + ScaleUVFilterCols(dst_uv, row16, dst_width, x, dx); + } + dst_uv += dst_stride; + uy += dy; + if (uy > max_y) { + uy = max_y; + } + } + free_aligned_buffer_64(row); + } + return 0; +} +#endif + +// Scale UV up with bilinear interpolation. +#if HAS_SCALEUVBILINEARUP +static int ScaleUVBilinearUp(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_uv, + uint8_t* dst_uv, + int x, + int dx, + int y, + int dy, + enum FilterMode filtering) { + assert(src_width > 0); + assert(src_height > 0); + assert(dst_width > 0); + assert(dst_height > 0); + assert(dy <= 65536); + + int j; + void (*InterpolateRow)(uint8_t* dst_uv, const uint8_t* src_uv, + ptrdiff_t src_stride, int dst_width, + int source_y_fraction) = InterpolateRow_C; + void (*ScaleUVFilterCols)(uint8_t* dst_uv, const uint8_t* src_uv, + int dst_width, int x, int dx) = + filtering ? ScaleUVFilterCols_C : ScaleUVCols_C; + const uint32_t max_y = (uint32_t)(src_height - 1) << 16; + uint32_t uy = y; +#if defined(HAS_INTERPOLATEROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + InterpolateRow = InterpolateRow_Any_AVX2; + if (IS_ALIGNED(dst_width, 16)) { + InterpolateRow = InterpolateRow_AVX2; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_AVX512BW; + } +#endif +#if defined(HAS_INTERPOLATEROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + InterpolateRow = InterpolateRow_Any_NEON; + if (IS_ALIGNED(dst_width, 8)) { + InterpolateRow = InterpolateRow_NEON; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_SVE2) + if (TestCpuFlag(kCpuHasSVE2)) { + InterpolateRow = InterpolateRow_SVE2; + } +#endif +#if defined(HAS_INTERPOLATEROW_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_LSX) + if (TestCpuFlag(kCpuHasLSX)) { + InterpolateRow = InterpolateRow_Any_LSX; + if (IS_ALIGNED(dst_width, 16)) { + InterpolateRow = InterpolateRow_LSX; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + InterpolateRow = InterpolateRow_Any_LASX; + if (IS_ALIGNED(dst_width, 32)) { + InterpolateRow = InterpolateRow_LASX; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + InterpolateRow = InterpolateRow_RVV; + } +#endif +#if defined(HAS_INTERPOLATEROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_HVX; + } +#endif +#if defined(HAS_INTERPOLATEROW_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 8)) { + InterpolateRow = InterpolateRow_WASMSIMD; + } + } +#endif + if (src_width >= 32768) { + ScaleUVFilterCols = filtering ? ScaleUVFilterCols64_C : ScaleUVCols64_C; + } + if (!filtering && src_width * 2 == dst_width && x < 0x8000) { + ScaleUVFilterCols = ScaleUVColsUp2_C; + } + + if (uy > max_y) { + uy = max_y; + } + + { + int yi = uy >> 16; + const uint8_t* src = src_uv + yi * src_stride; + + // Allocate 2 rows of UV. + const int row_size = (dst_width * 2 + 15) & ~15; + align_buffer_64(row, row_size * 2); + if (!row) + return 1; + + uint8_t* rowptr = row; + ptrdiff_t rowstride = row_size; + int lasty = yi; + + ScaleUVFilterCols(rowptr, src, dst_width, x, dx); + if (src_height > 1) { + src += src_stride; + } + ScaleUVFilterCols(rowptr + rowstride, src, dst_width, x, dx); + if (src_height > 2) { + src += src_stride; + } + + // 2-row rolling buffer: + // rowptr and (rowptr + rowstride) hold the scaled rows for yi and yi + 1. + // Because dy <= 65536 (dy <= 1.0 in 16.16), yi advances in unit steps. + // When yi != lasty: + // 1. Scale the next source row into the older buffer (rowptr). + // 2. Swap buffer pointers (rowptr += rowstride; rowstride = -rowstride;) + // so rowptr points to yi and (rowptr + rowstride) points to yi + 1. + // 3. Advance src by 1 row if row yi + 2 exists ((uy + 65536) < max_y), + // otherwise clamp src at (src_height - 1) to avoid reading out of + // bounds. + for (j = 0; j < dst_height; ++j) { + if (uy > max_y) { + uy = max_y; + } + yi = uy >> 16; + if (yi != lasty) { + ScaleUVFilterCols(rowptr, src, dst_width, x, dx); + rowptr += rowstride; + rowstride = -rowstride; + lasty = yi; + if ((uy + 65536) < max_y) { + src += src_stride; + } + } + if (filtering == kFilterLinear) { + InterpolateRow(dst_uv, rowptr, 0, dst_width * 2, 0); + } else { + int yf = (uy >> 8) & 255; + InterpolateRow(dst_uv, rowptr, rowstride, dst_width * 2, yf); + } + dst_uv += dst_stride; + uy += dy; + } + free_aligned_buffer_64(row); + } + return 0; +} + +static int ScaleUVBilinearUp_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_uv, + uint16_t* dst_uv, + int x, + int dx, + int y, + int dy, + enum FilterMode filtering) { + assert(src_width > 0); + assert(src_height > 0); + assert(dst_width > 0); + assert(dst_height > 0); + assert(dy <= 65536); + + int j; + void (*InterpolateRow)(uint16_t* dst_uv, const uint16_t* src_uv, + ptrdiff_t src_stride, int dst_width, + int source_y_fraction) = InterpolateRow_16_C; + void (*ScaleUVFilterCols)(uint16_t* dst_uv, const uint16_t* src_uv, + int dst_width, int x, int dx) = + filtering ? ScaleUVFilterCols_16_C : ScaleUVCols_16_C; + const uint32_t max_y = (uint32_t)(src_height - 1) << 16; + uint32_t uy = y; +#if defined(HAS_INTERPOLATEROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + InterpolateRow = InterpolateRow_16_Any_AVX2; + if (IS_ALIGNED(dst_width, 8)) { + InterpolateRow = InterpolateRow_16_AVX2; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_16_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + InterpolateRow = InterpolateRow_16_AVX512BW; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + InterpolateRow = InterpolateRow_16_Any_NEON; + if (IS_ALIGNED(dst_width, 4)) { + InterpolateRow = InterpolateRow_16_NEON; + } + } +#endif +#if defined(HAS_INTERPOLATEROW_16_SME) + if (TestCpuFlag(kCpuHasSME)) { + InterpolateRow = InterpolateRow_16_SME; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + InterpolateRow = InterpolateRow_16_HVX; + } +#endif +#if defined(HAS_INTERPOLATEROW_16_WASMSIMD) + if (TestCpuFlag(kCpuHasWASMSIMD)) { + InterpolateRow = InterpolateRow_16_Any_WASMSIMD; + if (IS_ALIGNED(dst_width, 4)) { + InterpolateRow = InterpolateRow_16_WASMSIMD; + } + } +#endif + if (src_width >= 32768) { + ScaleUVFilterCols = + filtering ? ScaleUVFilterCols64_16_C : ScaleUVCols64_16_C; + } + if (!filtering && src_width * 2 == dst_width && x < 0x8000) { + ScaleUVFilterCols = ScaleUVColsUp2_16_C; + } + + if (uy > max_y) { + uy = max_y; + } + + { + int yi = uy >> 16; + const uint16_t* src = src_uv + yi * src_stride; + + // Allocate 2 rows of 16-bit UV. + const int row_stride_words = (dst_width * 2 + 15) & ~15; + align_buffer_64(row, row_stride_words * 2 * (int)sizeof(uint16_t)); + if (!row) + return 1; + + uint16_t* rowptr = (uint16_t*)row; + ptrdiff_t rowstride = row_stride_words; + int lasty = yi; + + ScaleUVFilterCols(rowptr, src, dst_width, x, dx); + if (src_height > 1) { + src += src_stride; + } + ScaleUVFilterCols(rowptr + rowstride, src, dst_width, x, dx); + if (src_height > 2) { + src += src_stride; + } + + for (j = 0; j < dst_height; ++j) { + if (uy > max_y) { + uy = max_y; + } + yi = uy >> 16; + if (yi != lasty) { + ScaleUVFilterCols(rowptr, src, dst_width, x, dx); + rowptr += rowstride; + rowstride = -rowstride; + lasty = yi; + if ((uy + 65536) < max_y) { + src += src_stride; + } + } + if (filtering == kFilterLinear) { + InterpolateRow(dst_uv, rowptr, 0, dst_width * 2, 0); + } else { + int yf = (uy >> 8) & 255; + InterpolateRow(dst_uv, rowptr, rowstride, dst_width * 2, yf); + } + dst_uv += dst_stride; + uy += dy; + } + free_aligned_buffer_64(row); + } + return 0; +} +#endif // HAS_SCALEUVBILINEARUP + +// Scale UV, horizontally up by 2 times. +// Uses linear filter horizontally, nearest vertically. +// This is an optimized version for scaling up a plane to 2 times of +// its original width, using linear interpolation. +// This is used to scale U and V planes of NV16 to NV24. +static void ScaleUVLinearUp2(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_uv, + uint8_t* dst_uv) { + void (*ScaleRowUp)(const uint8_t* src_uv, uint8_t* dst_uv, int dst_width) = + ScaleUVRowUp2_Linear_Any_C; + int i; + + // This function can only scale up by 2 times horizontally. + (void)src_width; + assert(src_width == ((dst_width + 1) / 2)); + +#ifdef HAS_SCALEUVROWUP2_LINEAR_SSSE3 + if (TestCpuFlag(kCpuHasSSSE3)) { + ScaleRowUp = ScaleUVRowUp2_Linear_Any_SSSE3; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp = ScaleUVRowUp2_Linear_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_NEON + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp = ScaleUVRowUp2_Linear_Any_NEON; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_RVV + if (TestCpuFlag(kCpuHasRVV)) { + ScaleRowUp = ScaleUVRowUp2_Linear_RVV; + } +#endif + + if (dst_height == 1) { + ScaleRowUp(src_uv + ((src_height - 1) / 2) * src_stride, dst_uv, dst_width); + } else { + uint32_t uy = (1 << 15) - 1; + int dy = FixedDiv(src_height - 1, dst_height - 1); + for (i = 0; i < dst_height; ++i) { + int yi = uy >> 16; + ScaleRowUp(src_uv + yi * src_stride, dst_uv, dst_width); + dst_uv += dst_stride; + uy += dy; + } + } +} + +// Scale plane, up by 2 times. +// This is an optimized version for scaling up a plane to 2 times of +// its original size, using bilinear interpolation. +// This is used to scale U and V planes of NV12 to NV24. +static void ScaleUVBilinearUp2(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_ptr, + uint8_t* dst_ptr) { + void (*Scale2RowUp)(const uint8_t* src_ptr, ptrdiff_t src_stride, + uint8_t* dst_ptr, ptrdiff_t dst_stride, int dst_width) = + ScaleUVRowUp2_Bilinear_Any_C; + int x; + + // This function can only scale up by 2 times. + (void)src_width; + assert(src_width == ((dst_width + 1) / 2)); + assert(src_height == ((dst_height + 1) / 2)); + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_SSSE3 + if (TestCpuFlag(kCpuHasSSSE3)) { + Scale2RowUp = ScaleUVRowUp2_Bilinear_Any_SSSE3; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp = ScaleUVRowUp2_Bilinear_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_NEON + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp = ScaleUVRowUp2_Bilinear_Any_NEON; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_RVV + if (TestCpuFlag(kCpuHasRVV)) { + Scale2RowUp = ScaleUVRowUp2_Bilinear_RVV; + } +#endif + + Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width); + dst_ptr += dst_stride; + for (x = 0; x < src_height - 1; ++x) { + Scale2RowUp(src_ptr, src_stride, dst_ptr, dst_stride, dst_width); + src_ptr += src_stride; + // TODO(fbarchard): Test performance of writing one row of destination at a + // time. + dst_ptr += 2 * dst_stride; + } + if (!(dst_height & 1)) { + Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width); + } +} + +// Scale 16 bit UV, horizontally up by 2 times. +// Uses linear filter horizontally, nearest vertically. +// This is an optimized version for scaling up a plane to 2 times of +// its original width, using linear interpolation. +// This is used to scale U and V planes of P210 to P410. +static void ScaleUVLinearUp2_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_uv, + uint16_t* dst_uv) { + void (*ScaleRowUp)(const uint16_t* src_uv, uint16_t* dst_uv, int dst_width) = + ScaleUVRowUp2_Linear_16_Any_C; + int i; + + // This function can only scale up by 2 times horizontally. + (void)src_width; + assert(src_width == ((dst_width + 1) / 2)); + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_SSE41 + if (TestCpuFlag(kCpuHasSSE41)) { + ScaleRowUp = ScaleUVRowUp2_Linear_16_Any_SSE41; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleRowUp = ScaleUVRowUp2_Linear_16_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_NEON + if (TestCpuFlag(kCpuHasNEON)) { + ScaleRowUp = ScaleUVRowUp2_Linear_16_Any_NEON; + } +#endif + + if (dst_height == 1) { + ScaleRowUp(src_uv + ((src_height - 1) / 2) * src_stride, dst_uv, dst_width); + } else { + uint32_t uy = (1 << 15) - 1; + int dy = FixedDiv(src_height - 1, dst_height - 1); + for (i = 0; i < dst_height; ++i) { + int yi = uy >> 16; + ScaleRowUp(src_uv + yi * src_stride, dst_uv, dst_width); + dst_uv += dst_stride; + uy += dy; + } + } +} + +// Scale 16 bit UV, up by 2 times. +// This is an optimized version for scaling up a plane to 2 times of +// its original size, using bilinear interpolation. +// This is used to scale U and V planes of P010 to P410. +static void ScaleUVBilinearUp2_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_ptr, + uint16_t* dst_ptr) { + void (*Scale2RowUp)(const uint16_t* src_ptr, ptrdiff_t src_stride, + uint16_t* dst_ptr, ptrdiff_t dst_stride, int dst_width) = + ScaleUVRowUp2_Bilinear_16_Any_C; + int x; + + // This function can only scale up by 2 times. + (void)src_width; + assert(src_width == ((dst_width + 1) / 2)); + assert(src_height == ((dst_height + 1) / 2)); + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_SSE41 + if (TestCpuFlag(kCpuHasSSE41)) { + Scale2RowUp = ScaleUVRowUp2_Bilinear_16_Any_SSE41; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_AVX2 + if (TestCpuFlag(kCpuHasAVX2)) { + Scale2RowUp = ScaleUVRowUp2_Bilinear_16_Any_AVX2; + } +#endif + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_NEON + if (TestCpuFlag(kCpuHasNEON)) { + Scale2RowUp = ScaleUVRowUp2_Bilinear_16_Any_NEON; + } +#endif + + Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width); + dst_ptr += dst_stride; + for (x = 0; x < src_height - 1; ++x) { + Scale2RowUp(src_ptr, src_stride, dst_ptr, dst_stride, dst_width); + src_ptr += src_stride; + // TODO(fbarchard): Test performance of writing one row of destination at a + // time. + dst_ptr += 2 * dst_stride; + } + if (!(dst_height & 1)) { + Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width); + } +} + +// Scale UV to/from any dimensions, without interpolation. +// Fixed point math is used for performance: The upper 16 bits +// of x and dx is the integer part of the source position and +// the lower 16 bits are the fixed decimal part. + +static void ScaleUVSimple(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint8_t* src_uv, + uint8_t* dst_uv, + int x, + int dx, + int y, + int dy) { + int j; + void (*ScaleUVCols)(uint8_t* dst_uv, const uint8_t* src_uv, int dst_width, + int x, int dx) = + (src_width >= 32768) ? ScaleUVCols64_C : ScaleUVCols_C; + (void)src_height; + if (src_width * 2 == dst_width && x < 0x8000) { + ScaleUVCols = ScaleUVColsUp2_C; + } + + uint32_t uy = y; + for (j = 0; j < dst_height; ++j) { + int yi = uy >> 16; + ScaleUVCols(dst_uv, src_uv + yi * src_stride, dst_width, x, dx); + dst_uv += dst_stride; + uy += dy; + } +} + +static void ScaleUVSimple_16(int src_width, + int src_height, + int dst_width, + int dst_height, + ptrdiff_t src_stride, + ptrdiff_t dst_stride, + const uint16_t* src_uv, + uint16_t* dst_uv, + int x, + int dx, + int y, + int dy) { + int j; + void (*ScaleUVCols)(uint16_t* dst_uv, const uint16_t* src_uv, int dst_width, + int x, int dx) = + (src_width >= 32768) ? ScaleUVCols64_16_C : ScaleUVCols_16_C; + (void)src_height; + if (src_width * 2 == dst_width && x < 0x8000) { + ScaleUVCols = ScaleUVColsUp2_16_C; + } + + uint32_t uy = y; + for (j = 0; j < dst_height; ++j) { + int yi = uy >> 16; + ScaleUVCols(dst_uv, src_uv + yi * src_stride, dst_width, x, dx); + dst_uv += dst_stride; + uy += dy; + } +} + +// Copy UV with optional flipping +#if HAS_UVCOPY +static int UVCopy(const uint8_t* src_uv, + int src_stride_uv, + uint8_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + if (!src_uv || !dst_uv || width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_uv = src_uv + (height - 1) * (ptrdiff_t)src_stride_uv; + src_stride_uv = -src_stride_uv; + } + + CopyPlane(src_uv, src_stride_uv, dst_uv, dst_stride_uv, width * 2, height); + return 0; +} + +static int UVCopy_16(const uint16_t* src_uv, + int src_stride_uv, + uint16_t* dst_uv, + int dst_stride_uv, + int width, + int height) { + if (!src_uv || !dst_uv || width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + src_uv = src_uv + (height - 1) * (ptrdiff_t)src_stride_uv; + src_stride_uv = -src_stride_uv; + } + + CopyPlane_16(src_uv, src_stride_uv, dst_uv, dst_stride_uv, width * 2, height); + return 0; +} +#endif // HAS_UVCOPY + +// Scale a UV plane (from NV12) +// This function in turn calls a scaling function +// suitable for handling the desired resolutions. +static int ScaleUV(const uint8_t* src, + int src_stride, + int src_width, + int src_height, + uint8_t* dst, + int dst_stride, + int dst_width, + int dst_height, + int clip_x, + int clip_y, + int clip_width, + int clip_height, + enum FilterMode filtering) { + // Initial source x/y coordinate and step values as 16.16 fixed point. + int x = 0; + int y = 0; + int dx = 0; + int dy = 0; + // Simplify filtering when possible. + filtering = ScaleFilterReduce(src_width, src_height, dst_width, dst_height, + filtering); + + // Negative src_height means invert the image. + if (src_height < 0) { + src_height = -src_height; + src = src + (src_height - 1) * (ptrdiff_t)src_stride; + src_stride = -src_stride; + } + ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y, + &dx, &dy); + if (clip_x) { + int64_t clipf = (int64_t)(clip_x)*dx; + x += (clipf & 0xffff); + src += (clipf >> 16) * 2; + dst += clip_x * 2; + } + if (clip_y) { + int64_t clipf = (int64_t)(clip_y)*dy; + y += (clipf & 0xffff); + src += (clipf >> 16) * (ptrdiff_t)src_stride; + dst += clip_y * (ptrdiff_t)dst_stride; + } + +#if HAS_SCALEUVBOX + // Exactly 4 goes to the faster ScaleUVDown4Box below. Clipping is excluded + // because whole source rows are accumulated. + if (filtering == kFilterBox && !(dx == 0x40000 && dy == 0x40000) && + clip_x == 0 && clip_y == 0) { + return ScaleUVBox(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, dy); + } +#endif + + // Special case for integer step values. + if (((dx | dy) & 0xffff) == 0) { + if (!dx || !dy) { // 1 pixel wide and/or tall. + filtering = kFilterNone; + } else { + // Optimized even scale down. ie 2, 4, 6, 8, 10x. + if (!(dx & 0x10000) && !(dy & 0x10000)) { +#if HAS_SCALEUVDOWN2 + if (dx == 0x20000 && dy == 0x20000) { + // Optimized 1/2 downsample. + ScaleUVDown2(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, dy, + filtering); + return 0; + } +#endif +#if HAS_SCALEUVDOWN4BOX + if (dx == 0x40000 && dy == 0x40000 && filtering == kFilterBox) { + // Optimized 1/4 box downsample. + return ScaleUVDown4Box(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, + dy); + } +#endif +#if HAS_SCALEUVDOWNEVEN + ScaleUVDownEven(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, dy, + filtering); + return 0; +#endif + } + // Optimized odd scale down. ie 3, 5, 7, 9x. + if ((dx & 0x10000) && (dy & 0x10000)) { + filtering = kFilterNone; +#ifdef HAS_UVCOPY + if (dx == 0x10000 && dy == 0x10000) { + // Straight copy. + return UVCopy(src + (y >> 16) * (ptrdiff_t)src_stride + (x >> 16) * 2, + src_stride, dst, dst_stride, clip_width, clip_height); + } +#endif + } + } + } + // HAS_SCALEPLANEVERTICAL + if (dx == 0x10000 && (x & 0xffff) == 0) { + // Arbitrary scale vertically, but unscaled horizontally. + ScalePlaneVertical(src_height, clip_width, clip_height, src_stride, + dst_stride, src, dst, x, y, dy, /*bpp=*/2, filtering); + return 0; + } + if ((filtering == kFilterLinear) && ((dst_width + 1) / 2 == src_width)) { + ScaleUVLinearUp2(src_width, src_height, clip_width, clip_height, src_stride, + dst_stride, src, dst); + return 0; + } + if ((clip_height + 1) / 2 == src_height && + (clip_width + 1) / 2 == src_width && + (filtering == kFilterBilinear || filtering == kFilterBox)) { + ScaleUVBilinearUp2(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst); + return 0; + } +#if HAS_SCALEUVBILINEARUP + if (filtering && dy < 65536) { + return ScaleUVBilinearUp(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, dy, + filtering); + } +#endif +#if HAS_SCALEUVBILINEARDOWN + if (filtering) { + return ScaleUVBilinearDown(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, dy, + filtering); + } +#endif + ScaleUVSimple(src_width, src_height, clip_width, clip_height, src_stride, + dst_stride, src, dst, x, dx, y, dy); + return 0; +} + +// Scale an UV image. +LIBYUV_API +int UVScale(const uint8_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint8_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering) { + if (!src_uv || src_width <= 0 || src_height == 0 || src_width > 32768 || + src_height < -32768 || src_height > 32768 || !dst_uv || dst_width <= 0 || + dst_height <= 0) { + return -1; + } + return ScaleUV(src_uv, src_stride_uv, src_width, src_height, dst_uv, + dst_stride_uv, dst_width, dst_height, 0, 0, dst_width, + dst_height, filtering); +} + +// Scale a 16-bit UV plane (from P010/P210) +static int ScaleUV_16(const uint16_t* src, + int src_stride, + int src_width, + int src_height, + uint16_t* dst, + int dst_stride, + int dst_width, + int dst_height, + int clip_x, + int clip_y, + int clip_width, + int clip_height, + enum FilterMode filtering) { + // Initial source x/y coordinate and step values as 16.16 fixed point. + int x = 0; + int y = 0; + int dx = 0; + int dy = 0; + const enum FilterMode orig_filtering = filtering; + // Simplify filtering when possible. + filtering = ScaleFilterReduce(src_width, src_height, dst_width, dst_height, + filtering); + + // Negative src_height means invert the image. + if (src_height < 0) { + src_height = -src_height; + src = src + (src_height - 1) * (ptrdiff_t)src_stride; + src_stride = -src_stride; + } + ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y, + &dx, &dy); + if (clip_x) { + int64_t clipf = (int64_t)(clip_x)*dx; + x += (clipf & 0xffff); + src += (clipf >> 16) * 2; + dst += clip_x * 2; + } + if (clip_y) { + int64_t clipf = (int64_t)(clip_y)*dy; + y += (clipf & 0xffff); + src += (clipf >> 16) * (ptrdiff_t)src_stride; + dst += clip_y * (ptrdiff_t)dst_stride; + } + +#if HAS_SCALEUVBOX + // Exactly 4 goes to the faster ScaleUVDown4Box_16 below. Clipping is excluded + // because whole source rows are accumulated. + if (filtering == kFilterBox && !(dx == 0x40000 && dy == 0x40000) && + clip_x == 0 && clip_y == 0) { + return ScaleUVBox_16(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, dy); + } +#endif + + // Special case for integer step values. + if (((dx | dy) & 0xffff) == 0) { + if (!dx || !dy) { // 1 pixel wide and/or tall. + filtering = kFilterNone; + } else { + // Optimized even scale down. ie 2, 4, 6, 8, 10x. + if (!(dx & 0x10000) && !(dy & 0x10000)) { +#if HAS_SCALEUVDOWN2 + if (dx == 0x20000 && dy == 0x20000) { + // Optimized 1/2 downsample. + ScaleUVDown2_16(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, dy, + filtering); + return 0; + } +#endif +#if HAS_SCALEUVDOWN4BOX + if (dx == 0x40000 && dy == 0x40000 && filtering == kFilterBox) { + // Optimized 1/4 box downsample. + return ScaleUVDown4Box_16(src_width, src_height, clip_width, + clip_height, src_stride, dst_stride, src, + dst, x, dx, y, dy); + } +#endif +#if HAS_SCALEUVDOWNEVEN + ScaleUVDownEven_16(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, dy, + filtering); + return 0; +#endif + } + // Optimized odd scale down. ie 3, 5, 7, 9x. + if ((dx & 0x10000) && (dy & 0x10000)) { + filtering = kFilterNone; +#ifdef HAS_UVCOPY + if (dx == 0x10000 && dy == 0x10000) { + // Straight copy. + return UVCopy_16( + src + (y >> 16) * (ptrdiff_t)src_stride + (x >> 16) * 2, + src_stride, dst, dst_stride, clip_width, clip_height); + } +#endif + } + } + } + + // ScaleFilterReduce reduces a 1 pixel wide source to kFilterNone to avoid + // reading a second source column. The Up2 kernels clamp their last pixel and + // only read the 1 source column when dst_width <= 2, so restore Linear or + // Bilinear for 2x upscales (e.g., P010ToP410 and P210ToP410 on 1-2 pixel wide + // images) when the caller requested filtering. + if (orig_filtering != kFilterNone && filtering == kFilterNone && + src_width == 1 && dst_width <= 2 && clip_x == 0 && clip_y == 0) { + if (clip_height == src_height && (dst_width + 1) / 2 == src_width) { + ScaleUVLinearUp2_16(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst); + return 0; + } + if ((clip_height + 1) / 2 == src_height && + (clip_width + 1) / 2 == src_width && orig_filtering != kFilterLinear) { + ScaleUVBilinearUp2_16(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst); + return 0; + } + } + + // HAS_SCALEPLANEVERTICAL + if (dx == 0x10000 && (x & 0xffff) == 0) { + // Arbitrary scale vertically, but unscaled horizontally. + ScalePlaneVertical_16(src_height, clip_width, clip_height, src_stride, + dst_stride, src, dst, x, y, dy, /*wpp=*/2, filtering); + return 0; + } + if ((filtering == kFilterLinear) && ((dst_width + 1) / 2 == src_width)) { + ScaleUVLinearUp2_16(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst); + return 0; + } + if ((clip_height + 1) / 2 == src_height && + (clip_width + 1) / 2 == src_width && + (filtering == kFilterBilinear || filtering == kFilterBox)) { + ScaleUVBilinearUp2_16(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst); + return 0; + } +#if HAS_SCALEUVBILINEARUP + if (filtering && dy < 65536) { + return ScaleUVBilinearUp_16(src_width, src_height, clip_width, clip_height, + src_stride, dst_stride, src, dst, x, dx, y, dy, + filtering); + } +#endif +#if HAS_SCALEUVBILINEARDOWN + if (filtering) { + return ScaleUVBilinearDown_16(src_width, src_height, clip_width, + clip_height, src_stride, dst_stride, src, dst, + x, dx, y, dy, filtering); + } +#endif + ScaleUVSimple_16(src_width, src_height, clip_width, clip_height, src_stride, + dst_stride, src, dst, x, dx, y, dy); + return 0; +} + +// Scale a 16 bit UV image. +LIBYUV_API +int UVScale_16(const uint16_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint16_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering) { + if (!src_uv || src_width <= 0 || src_height == 0 || src_width > 32768 || + src_height < -32768 || src_height > 32768 || !dst_uv || dst_width <= 0 || + dst_height <= 0) { + return -1; + } + return ScaleUV_16(src_uv, src_stride_uv, src_width, src_height, dst_uv, + dst_stride_uv, dst_width, dst_height, 0, 0, dst_width, + dst_height, filtering); +} + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif diff --git a/libs/libyuv/source/scale_wasm.cc b/libs/libyuv/source/scale_wasm.cc new file mode 100644 index 0000000000..62e613ea3b --- /dev/null +++ b/libs/libyuv/source/scale_wasm.cc @@ -0,0 +1,713 @@ +/* + * Copyright 2026 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "libyuv/row.h" +#include "libyuv/scale_row.h" + +#if !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) +#include + +#ifdef __cplusplus +namespace libyuv { +extern "C" { +#endif + +// Arbitrary i8x16.shuffle masks are rematerialized on every use by V8, so +// shuffles that do not map to a single instruction use swizzle with masks +// loaded before the loop. Mask indices of 128 produce 0. +#ifdef __wasm_relaxed_simd__ +#define LIBYUV_WASM_SWIZZLE wasm_i8x16_relaxed_swizzle +#else +#define LIBYUV_WASM_SWIZZLE wasm_i8x16_swizzle +#endif + +// Load a constant vector. The empty asm hides the address so the compiler +// keeps the vector in a local instead of sinking a v128.const into the loop. +static inline v128_t LoadConst(const uint8_t* p) { + asm("" : "+r"(p)); + return wasm_v128_load(p); +} + +#ifdef HAS_SCALEROWDOWN2_WASMSIMD +// Point sample 32 pixels to 16, keeping the odd pixels. +void ScaleRowDown2_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + v128_t a = wasm_u16x8_shr(wasm_v128_load(src_ptr), 8); + v128_t b = wasm_u16x8_shr(wasm_v128_load(src_ptr + 16), 8); + wasm_v128_store(dst_ptr, wasm_u8x16_narrow_i16x8(a, b)); + src_ptr += 32; + dst_ptr += 16; + dst_width -= 16; + } +} + +// Average pairs of pixels: (s0 + s1 + 1) >> 1. +void ScaleRowDown2Linear_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const v128_t zero = wasm_i16x8_const_splat(0); + (void)src_stride; + while (dst_width > 0) { + v128_t a = wasm_u16x8_extadd_pairwise_u8x16(wasm_v128_load(src_ptr)); + v128_t b = wasm_u16x8_extadd_pairwise_u8x16(wasm_v128_load(src_ptr + 16)); + a = wasm_u16x8_avgr(a, zero); + b = wasm_u16x8_avgr(b, zero); + wasm_v128_store(dst_ptr, wasm_u8x16_narrow_i16x8(a, b)); + src_ptr += 32; + dst_ptr += 16; + dst_width -= 16; + } +} + +// Average 2x2 boxes: (s0 + s1 + t0 + t1 + 2) >> 2. +void ScaleRowDown2Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* t = src_ptr + src_stride; + const v128_t two = wasm_i16x8_const_splat(2); + while (dst_width > 0) { + v128_t a = wasm_i16x8_add( + wasm_u16x8_extadd_pairwise_u8x16(wasm_v128_load(src_ptr)), + wasm_u16x8_extadd_pairwise_u8x16(wasm_v128_load(t))); + v128_t b = wasm_i16x8_add( + wasm_u16x8_extadd_pairwise_u8x16(wasm_v128_load(src_ptr + 16)), + wasm_u16x8_extadd_pairwise_u8x16(wasm_v128_load(t + 16))); + a = wasm_u16x8_shr(wasm_i16x8_add(a, two), 2); + b = wasm_u16x8_shr(wasm_i16x8_add(b, two), 2); + wasm_v128_store(dst_ptr, wasm_u8x16_narrow_i16x8(a, b)); + src_ptr += 32; + t += 32; + dst_ptr += 16; + dst_width -= 16; + } +} +#endif // HAS_SCALEROWDOWN2_WASMSIMD + +#ifdef HAS_SCALEROWDOWN4_WASMSIMD +// Point sample 64 pixels to 16, keeping pixel 2 of every 4. Odd 16 bit +// lanes then even bytes, which are unzips (uzp on Arm, pack on x86). +void ScaleRowDown4_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const v128_t mask = wasm_i16x8_const_splat(0xff); + (void)src_stride; + while (dst_width > 0) { + v128_t a = wasm_i16x8_shuffle(wasm_v128_load(src_ptr), + wasm_v128_load(src_ptr + 16), 1, 3, 5, 7, 9, + 11, 13, 15); + v128_t b = wasm_i16x8_shuffle(wasm_v128_load(src_ptr + 32), + wasm_v128_load(src_ptr + 48), 1, 3, 5, 7, 9, + 11, 13, 15); + wasm_v128_store(dst_ptr, wasm_u8x16_narrow_i16x8(wasm_v128_and(a, mask), + wasm_v128_and(b, mask))); + src_ptr += 64; + dst_ptr += 16; + dst_width -= 16; + } +} + +// Average 4x4 boxes: (sum + 8) >> 4. 8 pixels per loop. +void ScaleRowDown4Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const v128_t eight = wasm_i16x8_const_splat(8); + while (dst_width > 0) { + v128_t a = wasm_i16x8_const_splat(0); + v128_t b = wasm_i16x8_const_splat(0); + const uint8_t* s = src_ptr; + for (int i = 0; i < 4; ++i) { + a = wasm_i16x8_add(a, + wasm_u16x8_extadd_pairwise_u8x16(wasm_v128_load(s))); + b = wasm_i16x8_add( + b, wasm_u16x8_extadd_pairwise_u8x16(wasm_v128_load(s + 16))); + s += src_stride; + } + a = wasm_u16x8_narrow_i32x4(wasm_u32x4_extadd_pairwise_u16x8(a), + wasm_u32x4_extadd_pairwise_u16x8(b)); + a = wasm_u16x8_shr(wasm_i16x8_add(a, eight), 4); + wasm_v128_store64_lane(dst_ptr, wasm_u8x16_narrow_i16x8(a, a), 0); + src_ptr += 32; + dst_ptr += 8; + dst_width -= 8; + } +} +#endif // HAS_SCALEROWDOWN4_WASMSIMD + +#ifdef HAS_SCALEROWDOWN34_WASMSIMD +static const uint8_t kShuf34[8][16] = { + // ScaleRowDown34: 16 bytes from a, then b, then 8 bytes from b. + {0, 1, 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 128, 128, 128, 128}, + {128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 1, 3, 4}, + {5, 7, 8, 9, 11, 12, 13, 15, 128, 128, 128, 128, 128, 128, 128, 128}, + // Filter34: s0 s1 s3 and s0 s2 s2 of every 4. + {0, 1, 3, 3, 4, 5, 7, 7, 8, 9, 11, 11, 12, 13, 15, 15}, + {0, 2, 2, 3, 4, 6, 6, 7, 8, 10, 10, 11, 12, 14, 14, 15}, + // Store34: bytes 0, 1, 2 of every 4 from a, then b, then 8 from b. + {0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 128, 128, 128, 128}, + {128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 1, 2, 4}, + {5, 6, 8, 9, 10, 12, 13, 14, 128, 128, 128, 128, 128, 128, 128, 128}, +}; + +// Point sample 32 pixels to 24, keeping pixels 0, 1 and 3 of every 4. +void ScaleRowDown34_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const v128_t m0 = LoadConst(kShuf34[0]); + const v128_t m1 = LoadConst(kShuf34[1]); + const v128_t m2 = LoadConst(kShuf34[2]); + (void)src_stride; + while (dst_width > 0) { + v128_t a = wasm_v128_load(src_ptr); + v128_t b = wasm_v128_load(src_ptr + 16); + wasm_v128_store(dst_ptr, wasm_v128_or(LIBYUV_WASM_SWIZZLE(a, m0), + LIBYUV_WASM_SWIZZLE(b, m1))); + wasm_v128_store64_lane(dst_ptr + 16, LIBYUV_WASM_SWIZZLE(b, m2), 0); + src_ptr += 32; + dst_ptr += 24; + dst_width -= 24; + } +} + +// Rounding-down average: (a + b) >> 1. +static inline v128_t AvgFloor(v128_t a, v128_t b) { + return wasm_i8x16_sub( + wasm_u8x16_avgr(a, b), + wasm_v128_and(wasm_v128_xor(a, b), wasm_i8x16_const_splat(1))); +} + +// Horizontal 4 to 3 filter of 16 pixels. Result bytes 4n+0..2 are +// (3 * s0 + s1 + 2) >> 2, (s1 + s2 + 1) >> 1, (s2 + 3 * s3 + 2) >> 2 +// using (3 * a + b + 2) >> 2 == avgr(a, (a + b) >> 1). Byte 4n+3 is unused. +static inline v128_t Filter34(v128_t s, v128_t mp, v128_t ma) { + v128_t p = LIBYUV_WASM_SWIZZLE(s, mp); // s0 s1 s3 + v128_t a = LIBYUV_WASM_SWIZZLE(s, ma); // s0 s2 s2 + v128_t b = wasm_u32x4_shr(s, 8); // s1 s2 s3 + return wasm_u8x16_avgr(p, AvgFloor(a, b)); +} + +// Filter rows 1 and 2 together, 1 : 1 +void ScaleRowDown34_1_Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* t = src_ptr + src_stride; + const v128_t mp = LoadConst(kShuf34[3]); + const v128_t ma = LoadConst(kShuf34[4]); + const v128_t m0 = LoadConst(kShuf34[5]); + const v128_t m1 = LoadConst(kShuf34[6]); + const v128_t m2 = LoadConst(kShuf34[7]); + while (dst_width > 0) { + v128_t a = wasm_u8x16_avgr(Filter34(wasm_v128_load(src_ptr), mp, ma), + Filter34(wasm_v128_load(t), mp, ma)); + v128_t b = wasm_u8x16_avgr(Filter34(wasm_v128_load(src_ptr + 16), mp, ma), + Filter34(wasm_v128_load(t + 16), mp, ma)); + wasm_v128_store(dst_ptr, wasm_v128_or(LIBYUV_WASM_SWIZZLE(a, m0), + LIBYUV_WASM_SWIZZLE(b, m1))); + wasm_v128_store64_lane(dst_ptr + 16, LIBYUV_WASM_SWIZZLE(b, m2), 0); + src_ptr += 32; + t += 32; + dst_ptr += 24; + dst_width -= 24; + } +} + +// Filter rows 0 and 1 together, 3 : 1 +void ScaleRowDown34_0_Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const uint8_t* t = src_ptr + src_stride; + const v128_t mp = LoadConst(kShuf34[3]); + const v128_t ma = LoadConst(kShuf34[4]); + const v128_t m0 = LoadConst(kShuf34[5]); + const v128_t m1 = LoadConst(kShuf34[6]); + const v128_t m2 = LoadConst(kShuf34[7]); + while (dst_width > 0) { + v128_t a0 = Filter34(wasm_v128_load(src_ptr), mp, ma); + v128_t b0 = Filter34(wasm_v128_load(src_ptr + 16), mp, ma); + v128_t a1 = Filter34(wasm_v128_load(t), mp, ma); + v128_t b1 = Filter34(wasm_v128_load(t + 16), mp, ma); + v128_t a = wasm_u8x16_avgr(a0, AvgFloor(a0, a1)); + v128_t b = wasm_u8x16_avgr(b0, AvgFloor(b0, b1)); + wasm_v128_store(dst_ptr, wasm_v128_or(LIBYUV_WASM_SWIZZLE(a, m0), + LIBYUV_WASM_SWIZZLE(b, m1))); + wasm_v128_store64_lane(dst_ptr + 16, LIBYUV_WASM_SWIZZLE(b, m2), 0); + src_ptr += 32; + t += 32; + dst_ptr += 24; + dst_width -= 24; + } +} +#endif // HAS_SCALEROWDOWN34_WASMSIMD + +#ifdef HAS_SCALEROWDOWN38_WASMSIMD +static const uint8_t kShuf38[3][16] = { + // ScaleRowDown38: 6 bytes from a, then 6 bytes from b. + {0, 3, 6, 8, 11, 14, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}, + {128, 128, 128, 128, 128, 128, 0, 3, 6, 8, 11, 14, 128, 128, 128, 128}, + // Store38: bytes 0, 1, 3 of every 4. + {0, 1, 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 128, 128, 128, 128}, +}; + +// Point sample 32 pixels to 12, keeping pixels 0, 3 and 6 of every 8. +void ScaleRowDown38_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const v128_t m0 = LoadConst(kShuf38[0]); + const v128_t m1 = LoadConst(kShuf38[1]); + (void)src_stride; + while (dst_width > 0) { + v128_t d = + wasm_v128_or(LIBYUV_WASM_SWIZZLE(wasm_v128_load(src_ptr), m0), + LIBYUV_WASM_SWIZZLE(wasm_v128_load(src_ptr + 16), m1)); + wasm_v128_store64_lane(dst_ptr, d, 0); + wasm_v128_store32_lane(dst_ptr + 8, d, 2); + src_ptr += 32; + dst_ptr += 12; + dst_width -= 12; + } +} + +// Sums of columns 0-2, 3-5 and 6-7 of 8 columns of u16 are scaled by the +// i16 factors in lanes 0, 3 and 6 of k. Returns the high 16 bits of the +// products in 32 bit lanes 0, 1 and 3. +static inline v128_t Sum38(v128_t s, v128_t k) { + const v128_t zero = wasm_i16x8_const_splat(0); + v128_t s1 = wasm_i8x16_shuffle(s, zero, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17); + v128_t s2 = wasm_i8x16_shuffle(s, zero, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19); + s = wasm_i16x8_add(wasm_i16x8_add(s, s1), s2); + return wasm_u32x4_shr(wasm_i32x4_dot_i16x8(s, k), 16); +} + +// Pack 12 results from Sum38 and store them. +static inline void Store38(uint8_t* dst_ptr, + v128_t m, + v128_t a, + v128_t b, + v128_t c, + v128_t d) { + v128_t r = wasm_u8x16_narrow_i16x8(wasm_u16x8_narrow_i32x4(a, b), + wasm_u16x8_narrow_i32x4(c, d)); + r = LIBYUV_WASM_SWIZZLE(r, m); + wasm_v128_store64_lane(dst_ptr, r, 0); + wasm_v128_store32_lane(dst_ptr + 8, r, 2); +} + +// 8x3 -> 3x1 +void ScaleRowDown38_3_Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const v128_t k = + wasm_i16x8_const(65536 / 9, 0, 0, 65536 / 9, 0, 0, 65536 / 6, 0); + const v128_t m = LoadConst(kShuf38[2]); + while (dst_width > 0) { + v128_t s[4]; + for (int i = 0; i < 4; ++i) { + const uint8_t* p = src_ptr + i * 8; + s[i] = wasm_i16x8_add(wasm_i16x8_add(wasm_u16x8_load8x8(p), + wasm_u16x8_load8x8(p + src_stride)), + wasm_u16x8_load8x8(p + src_stride * 2)); + } + Store38(dst_ptr, m, Sum38(s[0], k), Sum38(s[1], k), Sum38(s[2], k), + Sum38(s[3], k)); + src_ptr += 32; + dst_ptr += 12; + dst_width -= 12; + } +} + +// 8x2 -> 3x1 +void ScaleRowDown38_2_Box_WASMSIMD(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const v128_t k = + wasm_i16x8_const(65536 / 6, 0, 0, 65536 / 6, 0, 0, 65536 / 4, 0); + const v128_t m = LoadConst(kShuf38[2]); + while (dst_width > 0) { + v128_t s[4]; + for (int i = 0; i < 4; ++i) { + const uint8_t* p = src_ptr + i * 8; + s[i] = wasm_i16x8_add(wasm_u16x8_load8x8(p), + wasm_u16x8_load8x8(p + src_stride)); + } + Store38(dst_ptr, m, Sum38(s[0], k), Sum38(s[1], k), Sum38(s[2], k), + Sum38(s[3], k)); + src_ptr += 32; + dst_ptr += 12; + dst_width -= 12; + } +} +#endif // HAS_SCALEROWDOWN38_WASMSIMD + +#ifdef HAS_SCALEFILTERCOLS_WASMSIMD +// Bilinear column filtering with 7 bit fractions, matching ScaleFilterCols_C: +// a + ((f * (b - a) + 64) >> 7). 8 pixels per loop. The fraction +// (x >> 9) & 0x7f only uses the low 16 bits of x, so x is tracked in 16 bit +// lanes. +void ScaleFilterCols_WASMSIMD(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx) { + uint32_t ux = (uint32_t)x; + const uint32_t udx = (uint32_t)dx; + v128_t xv = wasm_i16x8_make((int16_t)ux, (int16_t)(ux + udx), + (int16_t)(ux + udx * 2), (int16_t)(ux + udx * 3), + (int16_t)(ux + udx * 4), (int16_t)(ux + udx * 5), + (int16_t)(ux + udx * 6), (int16_t)(ux + udx * 7)); + const v128_t dx8 = wasm_i16x8_splat((int16_t)(udx * 8)); + const v128_t maskff = wasm_i16x8_const_splat(0xff); + const v128_t round = wasm_i16x8_const_splat(64); + while (dst_width > 0) { + v128_t p = wasm_i16x8_const_splat(0); + p = wasm_v128_load16_lane(src_ptr + ((int)ux >> 16), p, 0); + ux += udx; + p = wasm_v128_load16_lane(src_ptr + ((int)ux >> 16), p, 1); + ux += udx; + p = wasm_v128_load16_lane(src_ptr + ((int)ux >> 16), p, 2); + ux += udx; + p = wasm_v128_load16_lane(src_ptr + ((int)ux >> 16), p, 3); + ux += udx; + p = wasm_v128_load16_lane(src_ptr + ((int)ux >> 16), p, 4); + ux += udx; + p = wasm_v128_load16_lane(src_ptr + ((int)ux >> 16), p, 5); + ux += udx; + p = wasm_v128_load16_lane(src_ptr + ((int)ux >> 16), p, 6); + ux += udx; + p = wasm_v128_load16_lane(src_ptr + ((int)ux >> 16), p, 7); + ux += udx; + v128_t f = wasm_u16x8_shr(xv, 9); + xv = wasm_i16x8_add(xv, dx8); + v128_t a = wasm_v128_and(p, maskff); + v128_t d = wasm_i16x8_sub(wasm_u16x8_shr(p, 8), a); + d = wasm_i16x8_shr(wasm_i16x8_add(wasm_i16x8_mul(d, f), round), 7); + d = wasm_i16x8_add(d, a); + wasm_v128_store64_lane(dst_ptr, wasm_u8x16_narrow_i16x8(d, d), 0); + dst_ptr += 8; + dst_width -= 8; + } +} +#endif // HAS_SCALEFILTERCOLS_WASMSIMD + +#if defined(HAS_SCALEARGBROWDOWN2_WASMSIMD) || \ + defined(HAS_SCALEARGBROWDOWNEVEN_WASMSIMD) +// Average 2x2 boxes of ARGB pixels. s0 s1 hold 4 pairs of pixels from row +// 0 and t0 t1 hold the same pairs from row 1. Returns 4 pixels. +static inline v128_t BoxARGB(v128_t s0, v128_t s1, v128_t t0, v128_t t1) { + v128_t se = wasm_i32x4_shuffle(s0, s1, 0, 2, 4, 6); + v128_t so = wasm_i32x4_shuffle(s0, s1, 1, 3, 5, 7); + v128_t te = wasm_i32x4_shuffle(t0, t1, 0, 2, 4, 6); + v128_t to = wasm_i32x4_shuffle(t0, t1, 1, 3, 5, 7); + // Interleave even and odd pixels so pairwise adds sum the same channel. + v128_t a = wasm_i16x8_add( + wasm_u16x8_extadd_pairwise_u8x16(wasm_i8x16_shuffle( + se, so, 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23)), + wasm_u16x8_extadd_pairwise_u8x16(wasm_i8x16_shuffle( + te, to, 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23))); + v128_t b = wasm_i16x8_add(wasm_u16x8_extadd_pairwise_u8x16(wasm_i8x16_shuffle( + se, so, 8, 24, 9, 25, 10, 26, 11, 27, 12, 28, + 13, 29, 14, 30, 15, 31)), + wasm_u16x8_extadd_pairwise_u8x16(wasm_i8x16_shuffle( + te, to, 8, 24, 9, 25, 10, 26, 11, 27, 12, 28, + 13, 29, 14, 30, 15, 31))); + a = wasm_u16x8_shr(wasm_i16x8_add(a, wasm_i16x8_const_splat(2)), 2); + b = wasm_u16x8_shr(wasm_i16x8_add(b, wasm_i16x8_const_splat(2)), 2); + return wasm_u8x16_narrow_i16x8(a, b); +} +#endif + +#ifdef HAS_SCALEARGBROWDOWN2_WASMSIMD +// Point sample 8 ARGB pixels to 4, keeping the odd pixels. +void ScaleARGBRowDown2_WASMSIMD(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + v128_t a = wasm_v128_load(src_argb); + v128_t b = wasm_v128_load(src_argb + 16); + wasm_v128_store(dst_argb, wasm_i32x4_shuffle(a, b, 1, 3, 5, 7)); + src_argb += 32; + dst_argb += 16; + dst_width -= 4; + } +} + +// Average pairs of ARGB pixels. +void ScaleARGBRowDown2Linear_WASMSIMD(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + v128_t a = wasm_v128_load(src_argb); + v128_t b = wasm_v128_load(src_argb + 16); + wasm_v128_store(dst_argb, + wasm_u8x16_avgr(wasm_i32x4_shuffle(a, b, 0, 2, 4, 6), + wasm_i32x4_shuffle(a, b, 1, 3, 5, 7))); + src_argb += 32; + dst_argb += 16; + dst_width -= 4; + } +} + +// Average 2x2 boxes of ARGB pixels. +void ScaleARGBRowDown2Box_WASMSIMD(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + const uint8_t* t = src_argb + src_stride; + while (dst_width > 0) { + wasm_v128_store( + dst_argb, + BoxARGB(wasm_v128_load(src_argb), wasm_v128_load(src_argb + 16), + wasm_v128_load(t), wasm_v128_load(t + 16))); + src_argb += 32; + t += 32; + dst_argb += 16; + dst_width -= 4; + } +} +#endif // HAS_SCALEARGBROWDOWN2_WASMSIMD + +#ifdef HAS_SCALEARGBROWDOWNEVEN_WASMSIMD +// Point sample ARGB pixels with an even step. 4 pixels per loop. +void ScaleARGBRowDownEven_WASMSIMD(const uint8_t* src_argb, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_argb, + int dst_width) { + const ptrdiff_t step = (ptrdiff_t)src_stepx * 4; + (void)src_stride; + while (dst_width > 0) { + v128_t v = wasm_v128_load32_zero(src_argb); + v = wasm_v128_load32_lane(src_argb + step, v, 1); + v = wasm_v128_load32_lane(src_argb + step * 2, v, 2); + v = wasm_v128_load32_lane(src_argb + step * 3, v, 3); + wasm_v128_store(dst_argb, v); + src_argb += step * 4; + dst_argb += 16; + dst_width -= 4; + } +} + +// Average 2x2 boxes of ARGB pixels with an even step. 4 pixels per loop. +void ScaleARGBRowDownEvenBox_WASMSIMD(const uint8_t* src_argb, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_argb, + int dst_width) { + const ptrdiff_t step = (ptrdiff_t)src_stepx * 4; + while (dst_width > 0) { + const uint8_t* t = src_argb + src_stride; + v128_t s0 = wasm_v128_load64_zero(src_argb); + v128_t t0 = wasm_v128_load64_zero(t); + s0 = wasm_v128_load64_lane(src_argb + step, s0, 1); + t0 = wasm_v128_load64_lane(t + step, t0, 1); + v128_t s1 = wasm_v128_load64_zero(src_argb + step * 2); + v128_t t1 = wasm_v128_load64_zero(t + step * 2); + s1 = wasm_v128_load64_lane(src_argb + step * 3, s1, 1); + t1 = wasm_v128_load64_lane(t + step * 3, t1, 1); + wasm_v128_store(dst_argb, BoxARGB(s0, s1, t0, t1)); + src_argb += step * 4; + dst_argb += 16; + dst_width -= 4; + } +} +#endif // HAS_SCALEARGBROWDOWNEVEN_WASMSIMD + +#ifdef HAS_SCALEARGBCOLS_WASMSIMD +// Point sample ARGB columns. 4 pixels per loop. +void ScaleARGBCols_WASMSIMD(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx) { + uint32_t ux = (uint32_t)x; + const uint32_t udx = (uint32_t)dx; + while (dst_width > 0) { + v128_t v = wasm_v128_load32_zero(src_argb + ((int)ux >> 16) * 4); + ux += udx; + v = wasm_v128_load32_lane(src_argb + ((int)ux >> 16) * 4, v, 1); + ux += udx; + v = wasm_v128_load32_lane(src_argb + ((int)ux >> 16) * 4, v, 2); + ux += udx; + v = wasm_v128_load32_lane(src_argb + ((int)ux >> 16) * 4, v, 3); + ux += udx; + wasm_v128_store(dst_argb, v); + dst_argb += 16; + dst_width -= 4; + } +} +#endif // HAS_SCALEARGBCOLS_WASMSIMD + +#ifdef HAS_SCALEARGBFILTERCOLS_WASMSIMD +// Bilinear ARGB column filtering with 7 bit fractions, matching +// ScaleARGBFilterCols_C: (a * (127 - f) + b * f) >> 7. 4 pixels per loop. +// The fraction (x >> 9) & 0x7f only uses the low 16 bits of x, so x is +// tracked in 16 bit lanes, 4 per pixel to match the channels. +void ScaleARGBFilterCols_WASMSIMD(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx) { + uint32_t ux = (uint32_t)x; + const uint32_t udx = (uint32_t)dx; + int16_t x0 = (int16_t)ux; + int16_t x1 = (int16_t)(ux + udx); + int16_t x2 = (int16_t)(ux + udx * 2); + int16_t x3 = (int16_t)(ux + udx * 3); + v128_t x01 = wasm_i16x8_make(x0, x0, x0, x0, x1, x1, x1, x1); + v128_t x23 = wasm_i16x8_make(x2, x2, x2, x2, x3, x3, x3, x3); + const v128_t dx4 = wasm_i16x8_splat((int16_t)(udx * 4)); + const v128_t k7f = wasm_i16x8_const_splat(0x7f); + while (dst_width > 0) { + // Load pixel pairs (a, b) for 4 pixels. + v128_t p0 = wasm_v128_load64_zero(src_argb + ((int)ux >> 16) * 4); + ux += udx; + p0 = wasm_v128_load64_lane(src_argb + ((int)ux >> 16) * 4, p0, 1); + ux += udx; + v128_t p1 = wasm_v128_load64_zero(src_argb + ((int)ux >> 16) * 4); + ux += udx; + p1 = wasm_v128_load64_lane(src_argb + ((int)ux >> 16) * 4, p1, 1); + ux += udx; + v128_t a = wasm_i32x4_shuffle(p0, p1, 0, 2, 4, 6); // a0 a1 a2 a3 + v128_t b = wasm_i32x4_shuffle(p0, p1, 1, 3, 5, 7); // b0 b1 b2 b3 + v128_t f01 = wasm_u16x8_shr(x01, 9); + v128_t f23 = wasm_u16x8_shr(x23, 9); + x01 = wasm_i16x8_add(x01, dx4); + x23 = wasm_i16x8_add(x23, dx4); + v128_t r0 = wasm_i16x8_add( + wasm_i16x8_mul(wasm_u16x8_extend_low_u8x16(a), wasm_v128_xor(f01, k7f)), + wasm_i16x8_mul(wasm_u16x8_extend_low_u8x16(b), f01)); + v128_t r1 = + wasm_i16x8_add(wasm_i16x8_mul(wasm_u16x8_extend_high_u8x16(a), + wasm_v128_xor(f23, k7f)), + wasm_i16x8_mul(wasm_u16x8_extend_high_u8x16(b), f23)); + wasm_v128_store(dst_argb, wasm_u8x16_narrow_i16x8(wasm_u16x8_shr(r0, 7), + wasm_u16x8_shr(r1, 7))); + dst_argb += 16; + dst_width -= 4; + } +} +#endif // HAS_SCALEARGBFILTERCOLS_WASMSIMD + +#ifdef HAS_SCALEARGBCOLSUP2_WASMSIMD +// Point sample ARGB up by 2x. 8 pixels per loop. +void ScaleARGBColsUp2_WASMSIMD(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx) { + (void)x; + (void)dx; + while (dst_width > 0) { + // V8 lowers an Arm zip of a vector with itself to several instructions, + // so zip with copies of the pixels loaded by load64_splat instead. + v128_t s = wasm_v128_load(src_argb); + v128_t t = wasm_v128_load64_splat(src_argb); + v128_t u = wasm_v128_load64_splat(src_argb + 8); + wasm_v128_store(dst_argb, wasm_i32x4_shuffle(s, t, 0, 4, 1, 5)); + wasm_v128_store(dst_argb + 16, wasm_i32x4_shuffle(s, u, 2, 6, 3, 7)); + src_argb += 16; + dst_argb += 32; + dst_width -= 8; + } +} +#endif // HAS_SCALEARGBCOLSUP2_WASMSIMD + +#ifdef HAS_SCALEADDROW_WASMSIMD +// Reads 16 bytes and accumulates to 16 shorts at a time. +void ScaleAddRow_WASMSIMD(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int src_width) { + while (src_width > 0) { + v128_t s = wasm_v128_load(src_ptr); + v128_t d0 = wasm_v128_load(dst_ptr); + v128_t d1 = wasm_v128_load(dst_ptr + 8); + d0 = wasm_i16x8_add(d0, wasm_u16x8_extend_low_u8x16(s)); + d1 = wasm_i16x8_add(d1, wasm_u16x8_extend_high_u8x16(s)); + wasm_v128_store(dst_ptr, d0); + wasm_v128_store(dst_ptr + 8, d1); + src_ptr += 16; + dst_ptr += 16; + src_width -= 16; + } +} +#endif // HAS_SCALEADDROW_WASMSIMD + +#ifdef HAS_SCALEUVADDCOLS3_WASMSIMD +// Reads 24 UV pixels (48 uint16_t) and writes 8 UV pixels (16 bytes). +void ScaleUVAddCols3_WASMSIMD(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { + const v128_t scale = wasm_i16x8_splat((int16_t)scaleval); + while (dst_width > 0) { + v128_t s0 = wasm_v128_load(src_uv); + v128_t s1 = wasm_v128_load(src_uv + 8); + v128_t s2 = wasm_v128_load(src_uv + 16); + v128_t s3 = wasm_v128_load(src_uv + 24); + v128_t s4 = wasm_v128_load(src_uv + 32); + v128_t s5 = wasm_v128_load(src_uv + 40); + src_uv += 48; + + // Group 0..3 of 3 UV pairs from s0, s1, s2 (dwords 0..11) + v128_t a0 = wasm_i32x4_shuffle(s0, s1, 0, 3, 6, 1); + v128_t b0 = wasm_i32x4_shuffle(s0, s1, 1, 4, 7, 2); + v128_t c0 = wasm_i32x4_shuffle(s0, s1, 2, 5, 0, 3); + a0 = wasm_i32x4_shuffle(a0, s2, 0, 1, 2, 5); + b0 = wasm_i32x4_shuffle(b0, s2, 0, 1, 2, 6); + c0 = wasm_i32x4_shuffle(c0, s2, 0, 1, 4, 7); + v128_t sum0 = wasm_i16x8_add(wasm_i16x8_add(a0, b0), c0); + + // Group 4..7 of 3 UV pairs from s3, s4, s5 (dwords 0..11) + v128_t a1 = wasm_i32x4_shuffle(s3, s4, 0, 3, 6, 1); + v128_t b1 = wasm_i32x4_shuffle(s3, s4, 1, 4, 7, 2); + v128_t c1 = wasm_i32x4_shuffle(s3, s4, 2, 5, 0, 3); + a1 = wasm_i32x4_shuffle(a1, s5, 0, 1, 2, 5); + b1 = wasm_i32x4_shuffle(b1, s5, 0, 1, 2, 6); + c1 = wasm_i32x4_shuffle(c1, s5, 0, 1, 4, 7); + v128_t sum1 = wasm_i16x8_add(wasm_i16x8_add(a1, b1), c1); + + // Multiply unsigned 16-bit sums by scaleval and shift right by 16. + v128_t lo0 = wasm_u32x4_shr(wasm_u32x4_extmul_low_u16x8(sum0, scale), 16); + v128_t hi0 = wasm_u32x4_shr(wasm_u32x4_extmul_high_u16x8(sum0, scale), 16); + v128_t lo1 = wasm_u32x4_shr(wasm_u32x4_extmul_low_u16x8(sum1, scale), 16); + v128_t hi1 = wasm_u32x4_shr(wasm_u32x4_extmul_high_u16x8(sum1, scale), 16); + v128_t p0 = wasm_i16x8_narrow_i32x4(lo0, hi0); + v128_t p1 = wasm_i16x8_narrow_i32x4(lo1, hi1); + wasm_v128_store(dst_uv, wasm_u8x16_narrow_i16x8(p0, p1)); + dst_uv += 16; + dst_width -= 8; + } +} +#endif // HAS_SCALEUVADDCOLS3_WASMSIMD + +#ifdef __cplusplus +} // extern "C" +} // namespace libyuv +#endif + +#endif // !defined(LIBYUV_DISABLE_WASM) && defined(__wasm_simd128__) diff --git a/libs/libyuv/source/scale_win.cc b/libs/libyuv/source/scale_win.cc index c5fc86f3e9..93921c794a 100644 --- a/libs/libyuv/source/scale_win.cc +++ b/libs/libyuv/source/scale_win.cc @@ -11,83 +11,30 @@ #include "libyuv/row.h" #include "libyuv/scale_row.h" +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || \ + defined(_M_IX86)) && \ + ((defined(_MSC_VER) && !defined(__clang__)) || \ + defined(LIBYUV_ENABLE_ROWWIN)) +#include +#include +#include +#include +#if defined(_MSC_VER) && !defined(__clang__) +#include +#endif +#endif + #ifdef __cplusplus namespace libyuv { extern "C" { #endif -// This module is for 32 bit Visual C x86 and clangcl -#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) - -// Offsets for source bytes 0 to 9 -static const uvec8 kShuf0 = {0, 1, 3, 4, 5, 7, 8, 9, - 128, 128, 128, 128, 128, 128, 128, 128}; - -// Offsets for source bytes 11 to 20 with 8 subtracted = 3 to 12. -static const uvec8 kShuf1 = {3, 4, 5, 7, 8, 9, 11, 12, - 128, 128, 128, 128, 128, 128, 128, 128}; - -// Offsets for source bytes 21 to 31 with 16 subtracted = 5 to 31. -static const uvec8 kShuf2 = {5, 7, 8, 9, 11, 12, 13, 15, - 128, 128, 128, 128, 128, 128, 128, 128}; - -// Offsets for source bytes 0 to 10 -static const uvec8 kShuf01 = {0, 1, 1, 2, 2, 3, 4, 5, 5, 6, 6, 7, 8, 9, 9, 10}; - -// Offsets for source bytes 10 to 21 with 8 subtracted = 3 to 13. -static const uvec8 kShuf11 = {2, 3, 4, 5, 5, 6, 6, 7, - 8, 9, 9, 10, 10, 11, 12, 13}; - -// Offsets for source bytes 21 to 31 with 16 subtracted = 5 to 31. -static const uvec8 kShuf21 = {5, 6, 6, 7, 8, 9, 9, 10, - 10, 11, 12, 13, 13, 14, 14, 15}; - -// Coefficients for source bytes 0 to 10 -static const uvec8 kMadd01 = {3, 1, 2, 2, 1, 3, 3, 1, 2, 2, 1, 3, 3, 1, 2, 2}; - -// Coefficients for source bytes 10 to 21 -static const uvec8 kMadd11 = {1, 3, 3, 1, 2, 2, 1, 3, 3, 1, 2, 2, 1, 3, 3, 1}; - -// Coefficients for source bytes 21 to 31 -static const uvec8 kMadd21 = {2, 2, 1, 3, 3, 1, 2, 2, 1, 3, 3, 1, 2, 2, 1, 3}; - -// Coefficients for source bytes 21 to 31 -static const vec16 kRound34 = {2, 2, 2, 2, 2, 2, 2, 2}; - -static const uvec8 kShuf38a = {0, 3, 6, 8, 11, 14, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128}; - -static const uvec8 kShuf38b = {128, 128, 128, 128, 128, 128, 0, 3, - 6, 8, 11, 14, 128, 128, 128, 128}; - -// Arrange words 0,3,6 into 0,1,2 -static const uvec8 kShufAc = {0, 1, 6, 7, 12, 13, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128}; - -// Arrange words 0,3,6 into 3,4,5 -static const uvec8 kShufAc3 = {128, 128, 128, 128, 128, 128, 0, 1, - 6, 7, 12, 13, 128, 128, 128, 128}; - -// Scaling values for boxes of 3x3 and 2x3 -static const uvec16 kScaleAc33 = {65536 / 9, 65536 / 9, 65536 / 6, 65536 / 9, - 65536 / 9, 65536 / 6, 0, 0}; - -// Arrange first value for pixels 0,1,2,3,4,5 -static const uvec8 kShufAb0 = {0, 128, 3, 128, 6, 128, 8, 128, - 11, 128, 14, 128, 128, 128, 128, 128}; - -// Arrange second value for pixels 0,1,2,3,4,5 -static const uvec8 kShufAb1 = {1, 128, 4, 128, 7, 128, 9, 128, - 12, 128, 15, 128, 128, 128, 128, 128}; - -// Arrange third value for pixels 0,1,2,3,4,5 -static const uvec8 kShufAb2 = {2, 128, 5, 128, 128, 128, 10, 128, - 13, 128, 128, 128, 128, 128, 128, 128}; - -// Scaling values for boxes of 3x2 and 2x2 -static const uvec16 kScaleAb2 = {65536 / 3, 65536 / 3, 65536 / 2, 65536 / 3, - 65536 / 3, 65536 / 2, 0, 0}; +// This module is for 32 bit Visual C x86 +#if !defined(LIBYUV_DISABLE_X86) && defined(_MSC_VER) && defined(_M_IX86) && \ + !defined(__clang__) && !defined(LIBYUV_ENABLE_ROWWIN) +#ifdef HAS_SCALEROWDOWN2_SSSE3 // Reads 32 pixels, throws half away and writes 16 pixels. __declspec(naked) void ScaleRowDown2_SSSE3(const uint8_t* src_ptr, ptrdiff_t src_stride, @@ -103,7 +50,7 @@ __declspec(naked) void ScaleRowDown2_SSSE3(const uint8_t* src_ptr, movdqu xmm0, [eax] movdqu xmm1, [eax + 16] lea eax, [eax + 32] - psrlw xmm0, 8 // isolate odd pixels. + psrlw xmm0, 8 // isolate odd pixels. psrlw xmm1, 8 packuswb xmm0, xmm1 movdqu [edx], xmm0 @@ -137,7 +84,7 @@ __declspec(naked) void ScaleRowDown2Linear_SSSE3(const uint8_t* src_ptr, lea eax, [eax + 32] pmaddubsw xmm0, xmm4 // horizontal add pmaddubsw xmm1, xmm4 - pavgw xmm0, xmm5 // (x + 1) / 2 + pavgw xmm0, xmm5 // (x + 1) / 2 pavgw xmm1, xmm5 packuswb xmm0, xmm1 movdqu [edx], xmm0 @@ -192,122 +139,9 @@ __declspec(naked) void ScaleRowDown2Box_SSSE3(const uint8_t* src_ptr, ret } } +#endif // HAS_SCALEROWDOWN2_SSSE3 -#ifdef HAS_SCALEROWDOWN2_AVX2 -// Reads 64 pixels, throws half away and writes 32 pixels. -__declspec(naked) void ScaleRowDown2_AVX2(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - __asm { - mov eax, [esp + 4] // src_ptr - // src_stride ignored - mov edx, [esp + 12] // dst_ptr - mov ecx, [esp + 16] // dst_width - - wloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - lea eax, [eax + 64] - vpsrlw ymm0, ymm0, 8 // isolate odd pixels. - vpsrlw ymm1, ymm1, 8 - vpackuswb ymm0, ymm0, ymm1 - vpermq ymm0, ymm0, 0xd8 // unmutate vpackuswb - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 32 - jg wloop - - vzeroupper - ret - } -} - -// Blends 64x1 rectangle to 32x1. -__declspec(naked) void ScaleRowDown2Linear_AVX2(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - __asm { - mov eax, [esp + 4] // src_ptr - // src_stride - mov edx, [esp + 12] // dst_ptr - mov ecx, [esp + 16] // dst_width - - vpcmpeqb ymm4, ymm4, ymm4 // '1' constant, 8b - vpsrlw ymm4, ymm4, 15 - vpackuswb ymm4, ymm4, ymm4 - vpxor ymm5, ymm5, ymm5 // constant 0 - - wloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - lea eax, [eax + 64] - vpmaddubsw ymm0, ymm0, ymm4 // horizontal add - vpmaddubsw ymm1, ymm1, ymm4 - vpavgw ymm0, ymm0, ymm5 // (x + 1) / 2 - vpavgw ymm1, ymm1, ymm5 - vpackuswb ymm0, ymm0, ymm1 - vpermq ymm0, ymm0, 0xd8 // unmutate vpackuswb - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 32 - jg wloop - - vzeroupper - ret - } -} - -// For rounding, average = (sum + 2) / 4 -// becomes average((sum >> 1), 0) -// Blends 64x2 rectangle to 32x1. -__declspec(naked) void ScaleRowDown2Box_AVX2(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_ptr - mov esi, [esp + 4 + 8] // src_stride - mov edx, [esp + 4 + 12] // dst_ptr - mov ecx, [esp + 4 + 16] // dst_width - - vpcmpeqb ymm4, ymm4, ymm4 // '1' constant, 8b - vpsrlw ymm4, ymm4, 15 - vpackuswb ymm4, ymm4, ymm4 - vpxor ymm5, ymm5, ymm5 // constant 0 - - wloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - vmovdqu ymm2, [eax + esi] - vmovdqu ymm3, [eax + esi + 32] - lea eax, [eax + 64] - vpmaddubsw ymm0, ymm0, ymm4 // horizontal add - vpmaddubsw ymm1, ymm1, ymm4 - vpmaddubsw ymm2, ymm2, ymm4 - vpmaddubsw ymm3, ymm3, ymm4 - vpaddw ymm0, ymm0, ymm2 // vertical add - vpaddw ymm1, ymm1, ymm3 - vpsrlw ymm0, ymm0, 1 // (x + 2) / 4 = (x / 2 + 1) / 2 - vpsrlw ymm1, ymm1, 1 - vpavgw ymm0, ymm0, ymm5 // (x + 1) / 2 - vpavgw ymm1, ymm1, ymm5 - vpackuswb ymm0, ymm0, ymm1 - vpermq ymm0, ymm0, 0xd8 // unmutate vpackuswb - vmovdqu [edx], ymm0 - lea edx, [edx + 32] - sub ecx, 32 - jg wloop - - pop esi - vzeroupper - ret - } -} -#endif // HAS_SCALEROWDOWN2_AVX2 - +#ifdef HAS_SCALEROWDOWN4_SSSE3 // Point samples 32 pixels to 8 pixels. __declspec(naked) void ScaleRowDown4_SSSE3(const uint8_t* src_ptr, ptrdiff_t src_stride, @@ -318,7 +152,7 @@ __declspec(naked) void ScaleRowDown4_SSSE3(const uint8_t* src_ptr, // src_stride ignored mov edx, [esp + 12] // dst_ptr mov ecx, [esp + 16] // dst_width - pcmpeqb xmm5, xmm5 // generate mask 0x00ff0000 + pcmpeqb xmm5, xmm5 // generate mask 0x00ff0000 psrld xmm5, 24 pslld xmm5, 16 @@ -397,965 +231,9 @@ __declspec(naked) void ScaleRowDown4Box_SSSE3(const uint8_t* src_ptr, ret } } +#endif // HAS_SCALEROWDOWN4_SSSE3 -#ifdef HAS_SCALEROWDOWN4_AVX2 -// Point samples 64 pixels to 16 pixels. -__declspec(naked) void ScaleRowDown4_AVX2(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - __asm { - mov eax, [esp + 4] // src_ptr - // src_stride ignored - mov edx, [esp + 12] // dst_ptr - mov ecx, [esp + 16] // dst_width - vpcmpeqb ymm5, ymm5, ymm5 // generate mask 0x00ff0000 - vpsrld ymm5, ymm5, 24 - vpslld ymm5, ymm5, 16 - - wloop: - vmovdqu ymm0, [eax] - vmovdqu ymm1, [eax + 32] - lea eax, [eax + 64] - vpand ymm0, ymm0, ymm5 - vpand ymm1, ymm1, ymm5 - vpackuswb ymm0, ymm0, ymm1 - vpermq ymm0, ymm0, 0xd8 // unmutate vpackuswb - vpsrlw ymm0, ymm0, 8 - vpackuswb ymm0, ymm0, ymm0 - vpermq ymm0, ymm0, 0xd8 // unmutate vpackuswb - vmovdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg wloop - - vzeroupper - ret - } -} - -// Blends 64x4 rectangle to 16x1. -__declspec(naked) void ScaleRowDown4Box_AVX2(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - __asm { - push esi - push edi - mov eax, [esp + 8 + 4] // src_ptr - mov esi, [esp + 8 + 8] // src_stride - mov edx, [esp + 8 + 12] // dst_ptr - mov ecx, [esp + 8 + 16] // dst_width - lea edi, [esi + esi * 2] // src_stride * 3 - vpcmpeqb ymm4, ymm4, ymm4 // constant 0x0101 - vpsrlw ymm4, ymm4, 15 - vpsllw ymm5, ymm4, 3 // constant 0x0008 - vpackuswb ymm4, ymm4, ymm4 - - wloop: - vmovdqu ymm0, [eax] // average rows - vmovdqu ymm1, [eax + 32] - vmovdqu ymm2, [eax + esi] - vmovdqu ymm3, [eax + esi + 32] - vpmaddubsw ymm0, ymm0, ymm4 // horizontal add - vpmaddubsw ymm1, ymm1, ymm4 - vpmaddubsw ymm2, ymm2, ymm4 - vpmaddubsw ymm3, ymm3, ymm4 - vpaddw ymm0, ymm0, ymm2 // vertical add rows 0, 1 - vpaddw ymm1, ymm1, ymm3 - vmovdqu ymm2, [eax + esi * 2] - vmovdqu ymm3, [eax + esi * 2 + 32] - vpmaddubsw ymm2, ymm2, ymm4 - vpmaddubsw ymm3, ymm3, ymm4 - vpaddw ymm0, ymm0, ymm2 // add row 2 - vpaddw ymm1, ymm1, ymm3 - vmovdqu ymm2, [eax + edi] - vmovdqu ymm3, [eax + edi + 32] - lea eax, [eax + 64] - vpmaddubsw ymm2, ymm2, ymm4 - vpmaddubsw ymm3, ymm3, ymm4 - vpaddw ymm0, ymm0, ymm2 // add row 3 - vpaddw ymm1, ymm1, ymm3 - vphaddw ymm0, ymm0, ymm1 // mutates - vpermq ymm0, ymm0, 0xd8 // unmutate vphaddw - vpaddw ymm0, ymm0, ymm5 // + 8 for round - vpsrlw ymm0, ymm0, 4 // /32 for average of 4 * 4 - vpackuswb ymm0, ymm0, ymm0 - vpermq ymm0, ymm0, 0xd8 // unmutate vpackuswb - vmovdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 16 - jg wloop - - pop edi - pop esi - vzeroupper - ret - } -} -#endif // HAS_SCALEROWDOWN4_AVX2 - -// Point samples 32 pixels to 24 pixels. -// Produces three 8 byte values. For each 8 bytes, 16 bytes are read. -// Then shuffled to do the scaling. - -__declspec(naked) void ScaleRowDown34_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - __asm { - mov eax, [esp + 4] // src_ptr - // src_stride ignored - mov edx, [esp + 12] // dst_ptr - mov ecx, [esp + 16] // dst_width - movdqa xmm3, xmmword ptr kShuf0 - movdqa xmm4, xmmword ptr kShuf1 - movdqa xmm5, xmmword ptr kShuf2 - - wloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - lea eax, [eax + 32] - movdqa xmm2, xmm1 - palignr xmm1, xmm0, 8 - pshufb xmm0, xmm3 - pshufb xmm1, xmm4 - pshufb xmm2, xmm5 - movq qword ptr [edx], xmm0 - movq qword ptr [edx + 8], xmm1 - movq qword ptr [edx + 16], xmm2 - lea edx, [edx + 24] - sub ecx, 24 - jg wloop - - ret - } -} - -// Blends 32x2 rectangle to 24x1 -// Produces three 8 byte values. For each 8 bytes, 16 bytes are read. -// Then shuffled to do the scaling. - -// Register usage: -// xmm0 src_row 0 -// xmm1 src_row 1 -// xmm2 shuf 0 -// xmm3 shuf 1 -// xmm4 shuf 2 -// xmm5 madd 0 -// xmm6 madd 1 -// xmm7 kRound34 - -// Note that movdqa+palign may be better than movdqu. -__declspec(naked) void ScaleRowDown34_1_Box_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_ptr - mov esi, [esp + 4 + 8] // src_stride - mov edx, [esp + 4 + 12] // dst_ptr - mov ecx, [esp + 4 + 16] // dst_width - movdqa xmm2, xmmword ptr kShuf01 - movdqa xmm3, xmmword ptr kShuf11 - movdqa xmm4, xmmword ptr kShuf21 - movdqa xmm5, xmmword ptr kMadd01 - movdqa xmm6, xmmword ptr kMadd11 - movdqa xmm7, xmmword ptr kRound34 - - wloop: - movdqu xmm0, [eax] // pixels 0..7 - movdqu xmm1, [eax + esi] - pavgb xmm0, xmm1 - pshufb xmm0, xmm2 - pmaddubsw xmm0, xmm5 - paddsw xmm0, xmm7 - psrlw xmm0, 2 - packuswb xmm0, xmm0 - movq qword ptr [edx], xmm0 - movdqu xmm0, [eax + 8] // pixels 8..15 - movdqu xmm1, [eax + esi + 8] - pavgb xmm0, xmm1 - pshufb xmm0, xmm3 - pmaddubsw xmm0, xmm6 - paddsw xmm0, xmm7 - psrlw xmm0, 2 - packuswb xmm0, xmm0 - movq qword ptr [edx + 8], xmm0 - movdqu xmm0, [eax + 16] // pixels 16..23 - movdqu xmm1, [eax + esi + 16] - lea eax, [eax + 32] - pavgb xmm0, xmm1 - pshufb xmm0, xmm4 - movdqa xmm1, xmmword ptr kMadd21 - pmaddubsw xmm0, xmm1 - paddsw xmm0, xmm7 - psrlw xmm0, 2 - packuswb xmm0, xmm0 - movq qword ptr [edx + 16], xmm0 - lea edx, [edx + 24] - sub ecx, 24 - jg wloop - - pop esi - ret - } -} - -// Note that movdqa+palign may be better than movdqu. -__declspec(naked) void ScaleRowDown34_0_Box_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_ptr - mov esi, [esp + 4 + 8] // src_stride - mov edx, [esp + 4 + 12] // dst_ptr - mov ecx, [esp + 4 + 16] // dst_width - movdqa xmm2, xmmword ptr kShuf01 - movdqa xmm3, xmmword ptr kShuf11 - movdqa xmm4, xmmword ptr kShuf21 - movdqa xmm5, xmmword ptr kMadd01 - movdqa xmm6, xmmword ptr kMadd11 - movdqa xmm7, xmmword ptr kRound34 - - wloop: - movdqu xmm0, [eax] // pixels 0..7 - movdqu xmm1, [eax + esi] - pavgb xmm1, xmm0 - pavgb xmm0, xmm1 - pshufb xmm0, xmm2 - pmaddubsw xmm0, xmm5 - paddsw xmm0, xmm7 - psrlw xmm0, 2 - packuswb xmm0, xmm0 - movq qword ptr [edx], xmm0 - movdqu xmm0, [eax + 8] // pixels 8..15 - movdqu xmm1, [eax + esi + 8] - pavgb xmm1, xmm0 - pavgb xmm0, xmm1 - pshufb xmm0, xmm3 - pmaddubsw xmm0, xmm6 - paddsw xmm0, xmm7 - psrlw xmm0, 2 - packuswb xmm0, xmm0 - movq qword ptr [edx + 8], xmm0 - movdqu xmm0, [eax + 16] // pixels 16..23 - movdqu xmm1, [eax + esi + 16] - lea eax, [eax + 32] - pavgb xmm1, xmm0 - pavgb xmm0, xmm1 - pshufb xmm0, xmm4 - movdqa xmm1, xmmword ptr kMadd21 - pmaddubsw xmm0, xmm1 - paddsw xmm0, xmm7 - psrlw xmm0, 2 - packuswb xmm0, xmm0 - movq qword ptr [edx + 16], xmm0 - lea edx, [edx+24] - sub ecx, 24 - jg wloop - - pop esi - ret - } -} - -// 3/8 point sampler - -// Scale 32 pixels to 12 -__declspec(naked) void ScaleRowDown38_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - __asm { - mov eax, [esp + 4] // src_ptr - // src_stride ignored - mov edx, [esp + 12] // dst_ptr - mov ecx, [esp + 16] // dst_width - movdqa xmm4, xmmword ptr kShuf38a - movdqa xmm5, xmmword ptr kShuf38b - - xloop: - movdqu xmm0, [eax] // 16 pixels -> 0,1,2,3,4,5 - movdqu xmm1, [eax + 16] // 16 pixels -> 6,7,8,9,10,11 - lea eax, [eax + 32] - pshufb xmm0, xmm4 - pshufb xmm1, xmm5 - paddusb xmm0, xmm1 - - movq qword ptr [edx], xmm0 // write 12 pixels - movhlps xmm1, xmm0 - movd [edx + 8], xmm1 - lea edx, [edx + 12] - sub ecx, 12 - jg xloop - - ret - } -} - -// Scale 16x3 pixels to 6x1 with interpolation -__declspec(naked) void ScaleRowDown38_3_Box_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_ptr - mov esi, [esp + 4 + 8] // src_stride - mov edx, [esp + 4 + 12] // dst_ptr - mov ecx, [esp + 4 + 16] // dst_width - movdqa xmm2, xmmword ptr kShufAc - movdqa xmm3, xmmword ptr kShufAc3 - movdqa xmm4, xmmword ptr kScaleAc33 - pxor xmm5, xmm5 - - xloop: - movdqu xmm0, [eax] // sum up 3 rows into xmm0/1 - movdqu xmm6, [eax + esi] - movhlps xmm1, xmm0 - movhlps xmm7, xmm6 - punpcklbw xmm0, xmm5 - punpcklbw xmm1, xmm5 - punpcklbw xmm6, xmm5 - punpcklbw xmm7, xmm5 - paddusw xmm0, xmm6 - paddusw xmm1, xmm7 - movdqu xmm6, [eax + esi * 2] - lea eax, [eax + 16] - movhlps xmm7, xmm6 - punpcklbw xmm6, xmm5 - punpcklbw xmm7, xmm5 - paddusw xmm0, xmm6 - paddusw xmm1, xmm7 - - movdqa xmm6, xmm0 // 8 pixels -> 0,1,2 of xmm6 - psrldq xmm0, 2 - paddusw xmm6, xmm0 - psrldq xmm0, 2 - paddusw xmm6, xmm0 - pshufb xmm6, xmm2 - - movdqa xmm7, xmm1 // 8 pixels -> 3,4,5 of xmm6 - psrldq xmm1, 2 - paddusw xmm7, xmm1 - psrldq xmm1, 2 - paddusw xmm7, xmm1 - pshufb xmm7, xmm3 - paddusw xmm6, xmm7 - - pmulhuw xmm6, xmm4 // divide by 9,9,6, 9,9,6 - packuswb xmm6, xmm6 - - movd [edx], xmm6 // write 6 pixels - psrlq xmm6, 16 - movd [edx + 2], xmm6 - lea edx, [edx + 6] - sub ecx, 6 - jg xloop - - pop esi - ret - } -} - -// Scale 16x2 pixels to 6x1 with interpolation -__declspec(naked) void ScaleRowDown38_2_Box_SSSE3(const uint8_t* src_ptr, - ptrdiff_t src_stride, - uint8_t* dst_ptr, - int dst_width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_ptr - mov esi, [esp + 4 + 8] // src_stride - mov edx, [esp + 4 + 12] // dst_ptr - mov ecx, [esp + 4 + 16] // dst_width - movdqa xmm2, xmmword ptr kShufAb0 - movdqa xmm3, xmmword ptr kShufAb1 - movdqa xmm4, xmmword ptr kShufAb2 - movdqa xmm5, xmmword ptr kScaleAb2 - - xloop: - movdqu xmm0, [eax] // average 2 rows into xmm0 - movdqu xmm1, [eax + esi] - lea eax, [eax + 16] - pavgb xmm0, xmm1 - - movdqa xmm1, xmm0 // 16 pixels -> 0,1,2,3,4,5 of xmm1 - pshufb xmm1, xmm2 - movdqa xmm6, xmm0 - pshufb xmm6, xmm3 - paddusw xmm1, xmm6 - pshufb xmm0, xmm4 - paddusw xmm1, xmm0 - - pmulhuw xmm1, xmm5 // divide by 3,3,2, 3,3,2 - packuswb xmm1, xmm1 - - movd [edx], xmm1 // write 6 pixels - psrlq xmm1, 16 - movd [edx + 2], xmm1 - lea edx, [edx + 6] - sub ecx, 6 - jg xloop - - pop esi - ret - } -} - -// Reads 16 bytes and accumulates to 16 shorts at a time. -__declspec(naked) void ScaleAddRow_SSE2(const uint8_t* src_ptr, - uint16_t* dst_ptr, - int src_width) { - __asm { - mov eax, [esp + 4] // src_ptr - mov edx, [esp + 8] // dst_ptr - mov ecx, [esp + 12] // src_width - pxor xmm5, xmm5 - - // sum rows - xloop: - movdqu xmm3, [eax] // read 16 bytes - lea eax, [eax + 16] - movdqu xmm0, [edx] // read 16 words from destination - movdqu xmm1, [edx + 16] - movdqa xmm2, xmm3 - punpcklbw xmm2, xmm5 - punpckhbw xmm3, xmm5 - paddusw xmm0, xmm2 // sum 16 words - paddusw xmm1, xmm3 - movdqu [edx], xmm0 // write 16 words to destination - movdqu [edx + 16], xmm1 - lea edx, [edx + 32] - sub ecx, 16 - jg xloop - ret - } -} - -#ifdef HAS_SCALEADDROW_AVX2 -// Reads 32 bytes and accumulates to 32 shorts at a time. -__declspec(naked) void ScaleAddRow_AVX2(const uint8_t* src_ptr, - uint16_t* dst_ptr, - int src_width) { - __asm { - mov eax, [esp + 4] // src_ptr - mov edx, [esp + 8] // dst_ptr - mov ecx, [esp + 12] // src_width - vpxor ymm5, ymm5, ymm5 - - // sum rows - xloop: - vmovdqu ymm3, [eax] // read 32 bytes - lea eax, [eax + 32] - vpermq ymm3, ymm3, 0xd8 // unmutate for vpunpck - vpunpcklbw ymm2, ymm3, ymm5 - vpunpckhbw ymm3, ymm3, ymm5 - vpaddusw ymm0, ymm2, [edx] // sum 16 words - vpaddusw ymm1, ymm3, [edx + 32] - vmovdqu [edx], ymm0 // write 32 words to destination - vmovdqu [edx + 32], ymm1 - lea edx, [edx + 64] - sub ecx, 32 - jg xloop - - vzeroupper - ret - } -} -#endif // HAS_SCALEADDROW_AVX2 - -// Constant for making pixels signed to avoid pmaddubsw -// saturation. -static const uvec8 kFsub80 = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}; - -// Constant for making pixels unsigned and adding .5 for rounding. -static const uvec16 kFadd40 = {0x4040, 0x4040, 0x4040, 0x4040, - 0x4040, 0x4040, 0x4040, 0x4040}; - -// Bilinear column filtering. SSSE3 version. -__declspec(naked) void ScaleFilterCols_SSSE3(uint8_t* dst_ptr, - const uint8_t* src_ptr, - int dst_width, - int x, - int dx) { - __asm { - push ebx - push esi - push edi - mov edi, [esp + 12 + 4] // dst_ptr - mov esi, [esp + 12 + 8] // src_ptr - mov ecx, [esp + 12 + 12] // dst_width - movd xmm2, [esp + 12 + 16] // x - movd xmm3, [esp + 12 + 20] // dx - mov eax, 0x04040000 // shuffle to line up fractions with pixel. - movd xmm5, eax - pcmpeqb xmm6, xmm6 // generate 0x007f for inverting fraction. - psrlw xmm6, 9 - pcmpeqb xmm7, xmm7 // generate 0x0001 - psrlw xmm7, 15 - pextrw eax, xmm2, 1 // get x0 integer. preroll - sub ecx, 2 - jl xloop29 - - movdqa xmm0, xmm2 // x1 = x0 + dx - paddd xmm0, xmm3 - punpckldq xmm2, xmm0 // x0 x1 - punpckldq xmm3, xmm3 // dx dx - paddd xmm3, xmm3 // dx * 2, dx * 2 - pextrw edx, xmm2, 3 // get x1 integer. preroll - - // 2 Pixel loop. - xloop2: - movdqa xmm1, xmm2 // x0, x1 fractions. - paddd xmm2, xmm3 // x += dx - movzx ebx, word ptr [esi + eax] // 2 source x0 pixels - movd xmm0, ebx - psrlw xmm1, 9 // 7 bit fractions. - movzx ebx, word ptr [esi + edx] // 2 source x1 pixels - movd xmm4, ebx - pshufb xmm1, xmm5 // 0011 - punpcklwd xmm0, xmm4 - psubb xmm0, xmmword ptr kFsub80 // make pixels signed. - pxor xmm1, xmm6 // 0..7f and 7f..0 - paddusb xmm1, xmm7 // +1 so 0..7f and 80..1 - pmaddubsw xmm1, xmm0 // 16 bit, 2 pixels. - pextrw eax, xmm2, 1 // get x0 integer. next iteration. - pextrw edx, xmm2, 3 // get x1 integer. next iteration. - paddw xmm1, xmmword ptr kFadd40 // make pixels unsigned and round. - psrlw xmm1, 7 // 8.7 fixed point to low 8 bits. - packuswb xmm1, xmm1 // 8 bits, 2 pixels. - movd ebx, xmm1 - mov [edi], bx - lea edi, [edi + 2] - sub ecx, 2 // 2 pixels - jge xloop2 - - xloop29: - add ecx, 2 - 1 - jl xloop99 - - // 1 pixel remainder - movzx ebx, word ptr [esi + eax] // 2 source x0 pixels - movd xmm0, ebx - psrlw xmm2, 9 // 7 bit fractions. - pshufb xmm2, xmm5 // 0011 - psubb xmm0, xmmword ptr kFsub80 // make pixels signed. - pxor xmm2, xmm6 // 0..7f and 7f..0 - paddusb xmm2, xmm7 // +1 so 0..7f and 80..1 - pmaddubsw xmm2, xmm0 // 16 bit - paddw xmm2, xmmword ptr kFadd40 // make pixels unsigned and round. - psrlw xmm2, 7 // 8.7 fixed point to low 8 bits. - packuswb xmm2, xmm2 // 8 bits - movd ebx, xmm2 - mov [edi], bl - - xloop99: - - pop edi - pop esi - pop ebx - ret - } -} - -// Reads 16 pixels, duplicates them and writes 32 pixels. -__declspec(naked) void ScaleColsUp2_SSE2(uint8_t* dst_ptr, - const uint8_t* src_ptr, - int dst_width, - int x, - int dx) { - __asm { - mov edx, [esp + 4] // dst_ptr - mov eax, [esp + 8] // src_ptr - mov ecx, [esp + 12] // dst_width - - wloop: - movdqu xmm0, [eax] - lea eax, [eax + 16] - movdqa xmm1, xmm0 - punpcklbw xmm0, xmm0 - punpckhbw xmm1, xmm1 - movdqu [edx], xmm0 - movdqu [edx + 16], xmm1 - lea edx, [edx + 32] - sub ecx, 32 - jg wloop - - ret - } -} - -// Reads 8 pixels, throws half away and writes 4 even pixels (0, 2, 4, 6) -__declspec(naked) void ScaleARGBRowDown2_SSE2(const uint8_t* src_argb, - ptrdiff_t src_stride, - uint8_t* dst_argb, - int dst_width) { - __asm { - mov eax, [esp + 4] // src_argb - // src_stride ignored - mov edx, [esp + 12] // dst_argb - mov ecx, [esp + 16] // dst_width - - wloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - lea eax, [eax + 32] - shufps xmm0, xmm1, 0xdd - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jg wloop - - ret - } -} - -// Blends 8x1 rectangle to 4x1. -__declspec(naked) void ScaleARGBRowDown2Linear_SSE2(const uint8_t* src_argb, - ptrdiff_t src_stride, - uint8_t* dst_argb, - int dst_width) { - __asm { - mov eax, [esp + 4] // src_argb - // src_stride ignored - mov edx, [esp + 12] // dst_argb - mov ecx, [esp + 16] // dst_width - - wloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - lea eax, [eax + 32] - movdqa xmm2, xmm0 - shufps xmm0, xmm1, 0x88 // even pixels - shufps xmm2, xmm1, 0xdd // odd pixels - pavgb xmm0, xmm2 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jg wloop - - ret - } -} - -// Blends 8x2 rectangle to 4x1. -__declspec(naked) void ScaleARGBRowDown2Box_SSE2(const uint8_t* src_argb, - ptrdiff_t src_stride, - uint8_t* dst_argb, - int dst_width) { - __asm { - push esi - mov eax, [esp + 4 + 4] // src_argb - mov esi, [esp + 4 + 8] // src_stride - mov edx, [esp + 4 + 12] // dst_argb - mov ecx, [esp + 4 + 16] // dst_width - - wloop: - movdqu xmm0, [eax] - movdqu xmm1, [eax + 16] - movdqu xmm2, [eax + esi] - movdqu xmm3, [eax + esi + 16] - lea eax, [eax + 32] - pavgb xmm0, xmm2 // average rows - pavgb xmm1, xmm3 - movdqa xmm2, xmm0 // average columns (8 to 4 pixels) - shufps xmm0, xmm1, 0x88 // even pixels - shufps xmm2, xmm1, 0xdd // odd pixels - pavgb xmm0, xmm2 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jg wloop - - pop esi - ret - } -} - -// Reads 4 pixels at a time. -__declspec(naked) void ScaleARGBRowDownEven_SSE2(const uint8_t* src_argb, - ptrdiff_t src_stride, - int src_stepx, - uint8_t* dst_argb, - int dst_width) { - __asm { - push ebx - push edi - mov eax, [esp + 8 + 4] // src_argb - // src_stride ignored - mov ebx, [esp + 8 + 12] // src_stepx - mov edx, [esp + 8 + 16] // dst_argb - mov ecx, [esp + 8 + 20] // dst_width - lea ebx, [ebx * 4] - lea edi, [ebx + ebx * 2] - - wloop: - movd xmm0, [eax] - movd xmm1, [eax + ebx] - punpckldq xmm0, xmm1 - movd xmm2, [eax + ebx * 2] - movd xmm3, [eax + edi] - lea eax, [eax + ebx * 4] - punpckldq xmm2, xmm3 - punpcklqdq xmm0, xmm2 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jg wloop - - pop edi - pop ebx - ret - } -} - -// Blends four 2x2 to 4x1. -__declspec(naked) void ScaleARGBRowDownEvenBox_SSE2(const uint8_t* src_argb, - ptrdiff_t src_stride, - int src_stepx, - uint8_t* dst_argb, - int dst_width) { - __asm { - push ebx - push esi - push edi - mov eax, [esp + 12 + 4] // src_argb - mov esi, [esp + 12 + 8] // src_stride - mov ebx, [esp + 12 + 12] // src_stepx - mov edx, [esp + 12 + 16] // dst_argb - mov ecx, [esp + 12 + 20] // dst_width - lea esi, [eax + esi] // row1 pointer - lea ebx, [ebx * 4] - lea edi, [ebx + ebx * 2] - - wloop: - movq xmm0, qword ptr [eax] // row0 4 pairs - movhps xmm0, qword ptr [eax + ebx] - movq xmm1, qword ptr [eax + ebx * 2] - movhps xmm1, qword ptr [eax + edi] - lea eax, [eax + ebx * 4] - movq xmm2, qword ptr [esi] // row1 4 pairs - movhps xmm2, qword ptr [esi + ebx] - movq xmm3, qword ptr [esi + ebx * 2] - movhps xmm3, qword ptr [esi + edi] - lea esi, [esi + ebx * 4] - pavgb xmm0, xmm2 // average rows - pavgb xmm1, xmm3 - movdqa xmm2, xmm0 // average columns (8 to 4 pixels) - shufps xmm0, xmm1, 0x88 // even pixels - shufps xmm2, xmm1, 0xdd // odd pixels - pavgb xmm0, xmm2 - movdqu [edx], xmm0 - lea edx, [edx + 16] - sub ecx, 4 - jg wloop - - pop edi - pop esi - pop ebx - ret - } -} - -// Column scaling unfiltered. SSE2 version. -__declspec(naked) void ScaleARGBCols_SSE2(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx) { - __asm { - push edi - push esi - mov edi, [esp + 8 + 4] // dst_argb - mov esi, [esp + 8 + 8] // src_argb - mov ecx, [esp + 8 + 12] // dst_width - movd xmm2, [esp + 8 + 16] // x - movd xmm3, [esp + 8 + 20] // dx - - pshufd xmm2, xmm2, 0 // x0 x0 x0 x0 - pshufd xmm0, xmm3, 0x11 // dx 0 dx 0 - paddd xmm2, xmm0 - paddd xmm3, xmm3 // 0, 0, 0, dx * 2 - pshufd xmm0, xmm3, 0x05 // dx * 2, dx * 2, 0, 0 - paddd xmm2, xmm0 // x3 x2 x1 x0 - paddd xmm3, xmm3 // 0, 0, 0, dx * 4 - pshufd xmm3, xmm3, 0 // dx * 4, dx * 4, dx * 4, dx * 4 - - pextrw eax, xmm2, 1 // get x0 integer. - pextrw edx, xmm2, 3 // get x1 integer. - - cmp ecx, 0 - jle xloop99 - sub ecx, 4 - jl xloop49 - - // 4 Pixel loop. - xloop4: - movd xmm0, [esi + eax * 4] // 1 source x0 pixels - movd xmm1, [esi + edx * 4] // 1 source x1 pixels - pextrw eax, xmm2, 5 // get x2 integer. - pextrw edx, xmm2, 7 // get x3 integer. - paddd xmm2, xmm3 // x += dx - punpckldq xmm0, xmm1 // x0 x1 - - movd xmm1, [esi + eax * 4] // 1 source x2 pixels - movd xmm4, [esi + edx * 4] // 1 source x3 pixels - pextrw eax, xmm2, 1 // get x0 integer. next iteration. - pextrw edx, xmm2, 3 // get x1 integer. next iteration. - punpckldq xmm1, xmm4 // x2 x3 - punpcklqdq xmm0, xmm1 // x0 x1 x2 x3 - movdqu [edi], xmm0 - lea edi, [edi + 16] - sub ecx, 4 // 4 pixels - jge xloop4 - - xloop49: - test ecx, 2 - je xloop29 - - // 2 Pixels. - movd xmm0, [esi + eax * 4] // 1 source x0 pixels - movd xmm1, [esi + edx * 4] // 1 source x1 pixels - pextrw eax, xmm2, 5 // get x2 integer. - punpckldq xmm0, xmm1 // x0 x1 - - movq qword ptr [edi], xmm0 - lea edi, [edi + 8] - - xloop29: - test ecx, 1 - je xloop99 - - // 1 Pixels. - movd xmm0, [esi + eax * 4] // 1 source x2 pixels - movd dword ptr [edi], xmm0 - xloop99: - - pop esi - pop edi - ret - } -} - -// Bilinear row filtering combines 2x1 -> 1x1. SSSE3 version. -// TODO(fbarchard): Port to Neon - -// Shuffle table for arranging 2 pixels into pairs for pmaddubsw -static const uvec8 kShuffleColARGB = { - 0u, 4u, 1u, 5u, 2u, 6u, 3u, 7u, // bbggrraa 1st pixel - 8u, 12u, 9u, 13u, 10u, 14u, 11u, 15u // bbggrraa 2nd pixel -}; - -// Shuffle table for duplicating 2 fractions into 8 bytes each -static const uvec8 kShuffleFractions = { - 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, -}; - -__declspec(naked) void ScaleARGBFilterCols_SSSE3(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx) { - __asm { - push esi - push edi - mov edi, [esp + 8 + 4] // dst_argb - mov esi, [esp + 8 + 8] // src_argb - mov ecx, [esp + 8 + 12] // dst_width - movd xmm2, [esp + 8 + 16] // x - movd xmm3, [esp + 8 + 20] // dx - movdqa xmm4, xmmword ptr kShuffleColARGB - movdqa xmm5, xmmword ptr kShuffleFractions - pcmpeqb xmm6, xmm6 // generate 0x007f for inverting fraction. - psrlw xmm6, 9 - pextrw eax, xmm2, 1 // get x0 integer. preroll - sub ecx, 2 - jl xloop29 - - movdqa xmm0, xmm2 // x1 = x0 + dx - paddd xmm0, xmm3 - punpckldq xmm2, xmm0 // x0 x1 - punpckldq xmm3, xmm3 // dx dx - paddd xmm3, xmm3 // dx * 2, dx * 2 - pextrw edx, xmm2, 3 // get x1 integer. preroll - - // 2 Pixel loop. - xloop2: - movdqa xmm1, xmm2 // x0, x1 fractions. - paddd xmm2, xmm3 // x += dx - movq xmm0, qword ptr [esi + eax * 4] // 2 source x0 pixels - psrlw xmm1, 9 // 7 bit fractions. - movhps xmm0, qword ptr [esi + edx * 4] // 2 source x1 pixels - pshufb xmm1, xmm5 // 0000000011111111 - pshufb xmm0, xmm4 // arrange pixels into pairs - pxor xmm1, xmm6 // 0..7f and 7f..0 - pmaddubsw xmm0, xmm1 // argb_argb 16 bit, 2 pixels. - pextrw eax, xmm2, 1 // get x0 integer. next iteration. - pextrw edx, xmm2, 3 // get x1 integer. next iteration. - psrlw xmm0, 7 // argb 8.7 fixed point to low 8 bits. - packuswb xmm0, xmm0 // argb_argb 8 bits, 2 pixels. - movq qword ptr [edi], xmm0 - lea edi, [edi + 8] - sub ecx, 2 // 2 pixels - jge xloop2 - - xloop29: - - add ecx, 2 - 1 - jl xloop99 - - // 1 pixel remainder - psrlw xmm2, 9 // 7 bit fractions. - movq xmm0, qword ptr [esi + eax * 4] // 2 source x0 pixels - pshufb xmm2, xmm5 // 00000000 - pshufb xmm0, xmm4 // arrange pixels into pairs - pxor xmm2, xmm6 // 0..7f and 7f..0 - pmaddubsw xmm0, xmm2 // argb 16 bit, 1 pixel. - psrlw xmm0, 7 - packuswb xmm0, xmm0 // argb 8 bits, 1 pixel. - movd [edi], xmm0 - - xloop99: - - pop edi - pop esi - ret - } -} - -// Reads 4 pixels, duplicates them and writes 8 pixels. -__declspec(naked) void ScaleARGBColsUp2_SSE2(uint8_t* dst_argb, - const uint8_t* src_argb, - int dst_width, - int x, - int dx) { - __asm { - mov edx, [esp + 4] // dst_argb - mov eax, [esp + 8] // src_argb - mov ecx, [esp + 12] // dst_width - - wloop: - movdqu xmm0, [eax] - lea eax, [eax + 16] - movdqa xmm1, xmm0 - punpckldq xmm0, xmm0 - punpckhdq xmm1, xmm1 - movdqu [edx], xmm0 - movdqu [edx + 16], xmm1 - lea edx, [edx + 32] - sub ecx, 8 - jg wloop - - ret - } -} - +#ifdef HAS_FIXEDDIV_X86 // Divide num by div and return as 16.16 fixed point result. __declspec(naked) int FixedDiv_X86(int num, int div) { __asm { @@ -1383,7 +261,2359 @@ __declspec(naked) int FixedDiv1_X86(int num, int div) { ret } } -#endif // !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) +#endif // HAS_FIXEDDIV_X86 +#endif // !defined(LIBYUV_DISABLE_X86) && defined(_MSC_VER) && defined(_M_IX86) + +// The following are available for Visual C 32/64 bit, and for clang with +// LIBYUV_ENABLE_ROWWIN: +#if !defined(LIBYUV_DISABLE_X86) && \ + (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || \ + defined(_M_IX86)) && \ + ((defined(_MSC_VER) && !defined(__clang__)) || \ + defined(LIBYUV_ENABLE_ROWWIN)) + +#if defined(__clang__) || defined(__GNUC__) +#define LIBYUV_TARGET_AVX2 __attribute__((target("avx2"))) +#define LIBYUV_TARGET_AVX512BW \ + __attribute__((target("avx512bw,avx512vl,avx512f"))) +#define LIBYUV_TARGET_AVX512VBMI \ + __attribute__((target("avx512vbmi,avx512bw,avx512vl,avx512f"))) +#else +#define LIBYUV_TARGET_AVX2 +#define LIBYUV_TARGET_AVX512BW +#define LIBYUV_TARGET_AVX512VBMI +#endif // defined(__clang__) || defined(__GNUC__) + +static inline uint16_t LoadU16(const void* p) { + uint16_t v; + memcpy(&v, p, sizeof(v)); + return v; +} + +static inline uint32_t LoadU32(const void* p) { + uint32_t v; + memcpy(&v, p, sizeof(v)); + return v; +} + +static inline uint64_t LoadU64(const void* p) { + uint64_t v; + memcpy(&v, p, sizeof(v)); + return v; +} + +static inline void StoreU32(void* p, uint32_t v) { + memcpy(p, &v, sizeof(v)); +} + +#if defined(HAS_FIXEDDIV_X86) && \ + !(defined(_MSC_VER) && defined(_M_IX86) && !defined(__clang__) && \ + !defined(LIBYUV_ENABLE_ROWWIN)) +int FixedDiv_X86(int num, int div) { + return (int)(((int64_t)num * 65536) / div); +} +#endif + +#if defined(HAS_FIXEDDIV1_X86) && \ + !(defined(_MSC_VER) && defined(_M_IX86) && !defined(__clang__) && \ + !defined(LIBYUV_ENABLE_ROWWIN)) +int FixedDiv1_X86(int num, int div) { + return (int)((((int64_t)num * 65536) - 0x00010001) / (div - 1)); +} +#endif + +#ifdef HAS_SCALEROWDOWN2_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleRowDown2_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + __m256i s0 = _mm256_srli_epi16( + _mm256_loadu_si256((const __m256i*)src_ptr), 8); + __m256i s1 = _mm256_srli_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + 32)), 8); + src_ptr += 64; + __m256i d = _mm256_permute4x64_epi64(_mm256_packus_epi16(s0, s1), 0xd8); + _mm256_storeu_si256((__m256i*)dst_ptr, d); + dst_ptr += 32; + dst_width -= 32; + } +} + +LIBYUV_TARGET_AVX2 +void ScaleRowDown2Linear_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + const __m256i ones = _mm256_set1_epi8(1); + const __m256i zero = _mm256_setzero_si256(); + while (dst_width > 0) { + __m256i s0 = _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)src_ptr), ones); + __m256i s1 = _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + 32)), ones); + src_ptr += 64; + s0 = _mm256_avg_epu16(s0, zero); + s1 = _mm256_avg_epu16(s1, zero); + __m256i d = _mm256_permute4x64_epi64(_mm256_packus_epi16(s0, s1), 0xd8); + _mm256_storeu_si256((__m256i*)dst_ptr, d); + dst_ptr += 32; + dst_width -= 32; + } +} + +LIBYUV_TARGET_AVX2 +void ScaleRowDown2Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const __m256i ones = _mm256_set1_epi8(1); + const __m256i zero = _mm256_setzero_si256(); + while (dst_width > 0) { + __m256i s0 = _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)src_ptr), ones); + __m256i s1 = _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + 32)), ones); + __m256i s2 = _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride)), ones); + __m256i s3 = _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride + 32)), ones); + src_ptr += 64; + s0 = _mm256_avg_epu16(_mm256_srli_epi16(_mm256_add_epi16(s0, s2), 1), zero); + s1 = _mm256_avg_epu16(_mm256_srli_epi16(_mm256_add_epi16(s1, s3), 1), zero); + __m256i d = _mm256_permute4x64_epi64(_mm256_packus_epi16(s0, s1), 0xd8); + _mm256_storeu_si256((__m256i*)dst_ptr, d); + dst_ptr += 32; + dst_width -= 32; + } +} +#endif // HAS_SCALEROWDOWN2_AVX2 + +#ifdef HAS_SCALEROWDOWN2_16_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleRowDown2_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + __m256i s0 = _mm256_srli_epi32( + _mm256_loadu_si256((const __m256i*)src_ptr), 16); + __m256i s1 = _mm256_srli_epi32( + _mm256_loadu_si256((const __m256i*)(src_ptr + 16)), 16); + src_ptr += 32; + __m256i d = _mm256_permute4x64_epi64(_mm256_packus_epi32(s0, s1), 0xd8); + _mm256_storeu_si256((__m256i*)dst_ptr, d); + dst_ptr += 16; + dst_width -= 16; + } +} + +LIBYUV_TARGET_AVX2 +void ScaleRowDown2Linear_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width) { + (void)src_stride; + const __m256i mask = _mm256_set1_epi32(0x0000ffff); + while (dst_width > 0) { + __m256i r0 = _mm256_loadu_si256((const __m256i*)src_ptr); + __m256i r1 = _mm256_loadu_si256((const __m256i*)(src_ptr + 16)); + src_ptr += 32; + __m256i e = _mm256_packus_epi32(_mm256_and_si256(r0, mask), + _mm256_and_si256(r1, mask)); + __m256i o = _mm256_packus_epi32(_mm256_srli_epi32(r0, 16), + _mm256_srli_epi32(r1, 16)); + __m256i d = _mm256_permute4x64_epi64(_mm256_avg_epu16(e, o), 0xd8); + _mm256_storeu_si256((__m256i*)dst_ptr, d); + dst_ptr += 16; + dst_width -= 16; + } +} + +LIBYUV_TARGET_AVX2 +void ScaleRowDown2Box_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + int dst_width) { + const __m256i mask = _mm256_set1_epi32(0x0000ffff); + const __m256i round2 = _mm256_set1_epi32(2); + while (dst_width > 0) { + __m256i r0 = _mm256_loadu_si256((const __m256i*)src_ptr); + __m256i r1 = _mm256_loadu_si256((const __m256i*)(src_ptr + 16)); + __m256i r2 = _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride)); + __m256i r3 = + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride + 16)); + src_ptr += 32; + __m256i s0 = _mm256_add_epi32( + _mm256_add_epi32(_mm256_and_si256(r0, mask), _mm256_srli_epi32(r0, 16)), + _mm256_add_epi32(_mm256_and_si256(r2, mask), + _mm256_srli_epi32(r2, 16))); + __m256i s1 = _mm256_add_epi32( + _mm256_add_epi32(_mm256_and_si256(r1, mask), _mm256_srli_epi32(r1, 16)), + _mm256_add_epi32(_mm256_and_si256(r3, mask), + _mm256_srli_epi32(r3, 16))); + s0 = _mm256_srli_epi32(_mm256_add_epi32(s0, round2), 2); + s1 = _mm256_srli_epi32(_mm256_add_epi32(s1, round2), 2); + __m256i d = _mm256_permute4x64_epi64(_mm256_packus_epi32(s0, s1), 0xd8); + _mm256_storeu_si256((__m256i*)dst_ptr, d); + dst_ptr += 16; + dst_width -= 16; + } +} +#endif // HAS_SCALEROWDOWN2_16_AVX2 + +#ifdef HAS_SCALEROWDOWN2_AVX512BW +LIBYUV_TARGET_AVX512BW +void ScaleRowDown2_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + while (dst_width >= 32) { + __m512i s = + _mm512_srli_epi16(_mm512_loadu_si512((const __m512i*)src_ptr), 8); + src_ptr += 64; + _mm256_storeu_si256((__m256i*)dst_ptr, _mm512_cvtepi16_epi8(s)); + dst_ptr += 32; + dst_width -= 32; + } + if (dst_width > 0) { + __mmask32 k = (__mmask32)((1ULL << dst_width) - 1); + __m512i s = _mm512_srli_epi16(_mm512_maskz_loadu_epi16(k, src_ptr), 8); + _mm256_mask_storeu_epi8(dst_ptr, k, _mm512_cvtepi16_epi8(s)); + } +} + +LIBYUV_TARGET_AVX512BW +void ScaleRowDown2Linear_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + const __m512i ones = _mm512_set1_epi8(1); + const __m512i zero = _mm512_setzero_si512(); + while (dst_width >= 32) { + __m512i s = _mm512_avg_epu16( + _mm512_maddubs_epi16(_mm512_loadu_si512((const __m512i*)src_ptr), ones), + zero); + src_ptr += 64; + _mm256_storeu_si256((__m256i*)dst_ptr, _mm512_cvtepi16_epi8(s)); + dst_ptr += 32; + dst_width -= 32; + } + if (dst_width > 0) { + __mmask32 k = (__mmask32)((1ULL << dst_width) - 1); + __m512i s = _mm512_avg_epu16( + _mm512_maddubs_epi16(_mm512_maskz_loadu_epi16(k, src_ptr), ones), + zero); + _mm256_mask_storeu_epi8(dst_ptr, k, _mm512_cvtepi16_epi8(s)); + } +} + +LIBYUV_TARGET_AVX512BW +void ScaleRowDown2Box_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const __m512i ones = _mm512_set1_epi8(1); + const __m512i zero = _mm512_setzero_si512(); + while (dst_width >= 32) { + __m512i s0 = _mm512_maddubs_epi16( + _mm512_loadu_si512((const __m512i*)src_ptr), ones); + __m512i s1 = _mm512_maddubs_epi16( + _mm512_loadu_si512((const __m512i*)(src_ptr + src_stride)), ones); + src_ptr += 64; + __m512i s = + _mm512_avg_epu16(_mm512_srli_epi16(_mm512_add_epi16(s0, s1), 1), zero); + _mm256_storeu_si256((__m256i*)dst_ptr, _mm512_cvtepi16_epi8(s)); + dst_ptr += 32; + dst_width -= 32; + } + if (dst_width > 0) { + __mmask32 k = (__mmask32)((1ULL << dst_width) - 1); + __m512i s0 = + _mm512_maddubs_epi16(_mm512_maskz_loadu_epi16(k, src_ptr), ones); + __m512i s1 = _mm512_maddubs_epi16( + _mm512_maskz_loadu_epi16(k, src_ptr + src_stride), ones); + __m512i s = + _mm512_avg_epu16(_mm512_srli_epi16(_mm512_add_epi16(s0, s1), 1), zero); + _mm256_mask_storeu_epi8(dst_ptr, k, _mm512_cvtepi16_epi8(s)); + } +} + +LIBYUV_TARGET_AVX512BW +void ScaleRowDown2Box_Odd_AVX512BW(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + dst_width -= 1; + if (dst_width > 0) { + ScaleRowDown2Box_AVX512BW(src_ptr, src_stride, dst_ptr, dst_width); + src_ptr += dst_width * 2; + dst_ptr += dst_width; + } + dst_ptr[0] = (uint8_t)((src_ptr[0] + src_ptr[src_stride] + 1) >> 1); +} +#endif // HAS_SCALEROWDOWN2_AVX512BW + +#ifdef HAS_SCALEROWDOWN4_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleRowDown4_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + const __m256i mask = _mm256_set1_epi32(0x00ff0000); + while (dst_width > 0) { + __m256i s0 = + _mm256_and_si256(_mm256_loadu_si256((const __m256i*)src_ptr), mask); + __m256i s1 = _mm256_and_si256( + _mm256_loadu_si256((const __m256i*)(src_ptr + 32)), mask); + src_ptr += 64; + __m256i t = _mm256_srli_epi16( + _mm256_permute4x64_epi64(_mm256_packus_epi16(s0, s1), 0xd8), 8); + __m256i d = _mm256_permute4x64_epi64(_mm256_packus_epi16(t, t), 0xd8); + _mm_storeu_si128((__m128i*)dst_ptr, _mm256_castsi256_si128(d)); + dst_ptr += 16; + dst_width -= 16; + } +} + +LIBYUV_TARGET_AVX2 +void ScaleRowDown4Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const __m256i ones = _mm256_set1_epi8(1); + const __m256i round8 = _mm256_set1_epi16(8); + const ptrdiff_t stridex3 = src_stride * 3; + while (dst_width > 0) { + __m256i s0 = _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)src_ptr), ones); + __m256i s1 = _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + 32)), ones); + s0 = _mm256_add_epi16( + s0, _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride)), + ones)); + s1 = _mm256_add_epi16( + s1, _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride + 32)), + ones)); + s0 = _mm256_add_epi16( + s0, _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride * 2)), + ones)); + s1 = _mm256_add_epi16( + s1, + _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride * 2 + 32)), + ones)); + s0 = _mm256_add_epi16( + s0, + _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + stridex3)), ones)); + s1 = _mm256_add_epi16( + s1, _mm256_maddubs_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + stridex3 + 32)), + ones)); + src_ptr += 64; + __m256i t = _mm256_permute4x64_epi64(_mm256_hadd_epi16(s0, s1), 0xd8); + t = _mm256_srli_epi16(_mm256_add_epi16(t, round8), 4); + __m256i d = _mm256_permute4x64_epi64(_mm256_packus_epi16(t, t), 0xd8); + _mm_storeu_si128((__m128i*)dst_ptr, _mm256_castsi256_si128(d)); + dst_ptr += 16; + dst_width -= 16; + } +} +#endif // HAS_SCALEROWDOWN4_AVX2 + +#ifdef HAS_SCALEROWDOWN34_AVX2 +static const uvec8 kShuf0 = {0, 1, 3, 4, 5, 7, 8, 9, + 128, 128, 128, 128, 128, 128, 128, 128}; +static const uvec8 kShuf1 = {3, 4, 5, 7, 8, 9, 11, 12, + 128, 128, 128, 128, 128, 128, 128, 128}; +static const uvec8 kShuf2 = {5, 7, 8, 9, 11, 12, 13, 15, + 128, 128, 128, 128, 128, 128, 128, 128}; +static const uvec8 kShuf01 = {0, 1, 1, 2, 2, 3, 4, 5, 5, 6, 6, 7, 8, 9, 9, 10}; +static const uvec8 kShuf11 = {2, 3, 4, 5, 5, 6, 6, 7, + 8, 9, 9, 10, 10, 11, 12, 13}; +static const uvec8 kShuf21 = {5, 6, 6, 7, 8, 9, 9, 10, + 10, 11, 12, 13, 13, 14, 14, 15}; +static const uvec8 kMadd01 = {3, 1, 2, 2, 1, 3, 3, 1, 2, 2, 1, 3, 3, 1, 2, 2}; +static const uvec8 kMadd11 = {1, 3, 3, 1, 2, 2, 1, 3, 3, 1, 2, 2, 1, 3, 3, 1}; +static const uvec8 kMadd21 = {2, 2, 1, 3, 3, 1, 2, 2, 1, 3, 3, 1, 2, 2, 1, 3}; + +LIBYUV_TARGET_AVX2 +void ScaleRowDown34_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + const __m256i shuf0 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShuf0)); + const __m256i shuf1 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShuf1)); + const __m256i shuf2 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShuf2)); + while (dst_width >= 48) { + __m256i s0 = _mm256_loadu_si256((const __m256i*)src_ptr); + __m256i s1 = _mm256_loadu_si256((const __m256i*)(src_ptr + 32)); + src_ptr += 64; + __m256i lo = _mm256_permute2x128_si256(s0, s1, 0x20); + __m256i hi = _mm256_permute2x128_si256(s0, s1, 0x31); + __m256i mid = _mm256_alignr_epi8(hi, lo, 8); + __m256i d0 = _mm256_shuffle_epi8(lo, shuf0); + __m256i d1 = _mm256_shuffle_epi8(mid, shuf1); + __m256i d2 = _mm256_shuffle_epi8(hi, shuf2); + __m256i d01 = _mm256_unpacklo_epi64(d0, d1); + _mm_storeu_si128((__m128i*)dst_ptr, _mm256_castsi256_si128(d01)); + _mm_storel_epi64((__m128i*)(dst_ptr + 16), _mm256_castsi256_si128(d2)); + _mm_storeu_si128((__m128i*)(dst_ptr + 24), _mm256_extracti128_si256(d01, 1)); + _mm_storel_epi64((__m128i*)(dst_ptr + 40), _mm256_extracti128_si256(d2, 1)); + dst_ptr += 48; + dst_width -= 48; + } + if (dst_width > 0) { + __m256i s0 = _mm256_loadu_si256((const __m256i*)src_ptr); + __m128i lo = _mm256_castsi256_si128(s0); + __m128i hi = _mm256_extracti128_si256(s0, 1); + __m128i mid = _mm_alignr_epi8(hi, lo, 8); + __m128i d0 = _mm_shuffle_epi8(lo, _mm256_castsi256_si128(shuf0)); + __m128i d1 = _mm_shuffle_epi8(mid, _mm256_castsi256_si128(shuf1)); + __m128i d2 = _mm_shuffle_epi8(hi, _mm256_castsi256_si128(shuf2)); + _mm_storeu_si128((__m128i*)dst_ptr, _mm_unpacklo_epi64(d0, d1)); + _mm_storel_epi64((__m128i*)(dst_ptr + 16), d2); + } +} + +LIBYUV_TARGET_AVX2 +void ScaleRowDown34_1_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const __m256i shuf01 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShuf01)); + const __m256i shuf11 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShuf11)); + const __m256i shuf21 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShuf21)); + const __m256i madd01 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kMadd01)); + const __m256i madd11 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kMadd11)); + const __m256i madd21 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kMadd21)); + const __m256i round2 = _mm256_set1_epi16(2); + while (dst_width >= 48) { + __m256i s0 = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)src_ptr), + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride))); + __m256i s1 = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)(src_ptr + 32)), + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride + 32))); + src_ptr += 64; + __m256i lo = _mm256_permute2x128_si256(s0, s1, 0x20); + __m256i hi = _mm256_permute2x128_si256(s0, s1, 0x31); + __m256i mid = _mm256_alignr_epi8(hi, lo, 8); + __m256i p0 = _mm256_srli_epi16( + _mm256_adds_epi16( + _mm256_maddubs_epi16(_mm256_shuffle_epi8(lo, shuf01), madd01), + round2), + 2); + __m256i p1 = _mm256_srli_epi16( + _mm256_adds_epi16( + _mm256_maddubs_epi16(_mm256_shuffle_epi8(mid, shuf11), madd11), + round2), + 2); + __m256i p2 = _mm256_srli_epi16( + _mm256_adds_epi16( + _mm256_maddubs_epi16(_mm256_shuffle_epi8(hi, shuf21), madd21), + round2), + 2); + p0 = _mm256_packus_epi16(p0, p0); + p1 = _mm256_packus_epi16(p1, p1); + p2 = _mm256_packus_epi16(p2, p2); + __m256i d01 = _mm256_unpacklo_epi64(p0, p1); + _mm_storeu_si128((__m128i*)dst_ptr, _mm256_castsi256_si128(d01)); + _mm_storel_epi64((__m128i*)(dst_ptr + 16), _mm256_castsi256_si128(p2)); + _mm_storeu_si128((__m128i*)(dst_ptr + 24), _mm256_extracti128_si256(d01, 1)); + _mm_storel_epi64((__m128i*)(dst_ptr + 40), _mm256_extracti128_si256(p2, 1)); + dst_ptr += 48; + dst_width -= 48; + } + if (dst_width > 0) { + __m256i s0 = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)src_ptr), + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride))); + __m128i lo = _mm256_castsi256_si128(s0); + __m128i hi = _mm256_extracti128_si256(s0, 1); + __m128i mid = _mm_alignr_epi8(hi, lo, 8); + __m128i r2 = _mm256_castsi256_si128(round2); + __m128i p0 = _mm_srli_epi16( + _mm_adds_epi16( + _mm_maddubs_epi16(_mm_shuffle_epi8(lo, _mm256_castsi256_si128(shuf01)), + _mm256_castsi256_si128(madd01)), + r2), + 2); + __m128i p1 = _mm_srli_epi16( + _mm_adds_epi16( + _mm_maddubs_epi16( + _mm_shuffle_epi8(mid, _mm256_castsi256_si128(shuf11)), + _mm256_castsi256_si128(madd11)), + r2), + 2); + __m128i p2 = _mm_srli_epi16( + _mm_adds_epi16( + _mm_maddubs_epi16(_mm_shuffle_epi8(hi, _mm256_castsi256_si128(shuf21)), + _mm256_castsi256_si128(madd21)), + r2), + 2); + p0 = _mm_packus_epi16(p0, p0); + p1 = _mm_packus_epi16(p1, p1); + p2 = _mm_packus_epi16(p2, p2); + _mm_storeu_si128((__m128i*)dst_ptr, _mm_unpacklo_epi64(p0, p1)); + _mm_storel_epi64((__m128i*)(dst_ptr + 16), p2); + } +} + +LIBYUV_TARGET_AVX2 +void ScaleRowDown34_0_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const __m256i shuf01 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShuf01)); + const __m256i shuf11 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShuf11)); + const __m256i shuf21 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShuf21)); + const __m256i madd01 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kMadd01)); + const __m256i madd11 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kMadd11)); + const __m256i madd21 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kMadd21)); + const __m256i round2 = _mm256_set1_epi16(2); + while (dst_width >= 48) { + __m256i a0 = _mm256_loadu_si256((const __m256i*)src_ptr); + __m256i b0 = _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride)); + __m256i s0 = _mm256_avg_epu8(a0, _mm256_avg_epu8(a0, b0)); + __m256i a1 = _mm256_loadu_si256((const __m256i*)(src_ptr + 32)); + __m256i b1 = _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride + 32)); + __m256i s1 = _mm256_avg_epu8(a1, _mm256_avg_epu8(a1, b1)); + src_ptr += 64; + __m256i lo = _mm256_permute2x128_si256(s0, s1, 0x20); + __m256i hi = _mm256_permute2x128_si256(s0, s1, 0x31); + __m256i mid = _mm256_alignr_epi8(hi, lo, 8); + __m256i p0 = _mm256_srli_epi16( + _mm256_adds_epi16( + _mm256_maddubs_epi16(_mm256_shuffle_epi8(lo, shuf01), madd01), + round2), + 2); + __m256i p1 = _mm256_srli_epi16( + _mm256_adds_epi16( + _mm256_maddubs_epi16(_mm256_shuffle_epi8(mid, shuf11), madd11), + round2), + 2); + __m256i p2 = _mm256_srli_epi16( + _mm256_adds_epi16( + _mm256_maddubs_epi16(_mm256_shuffle_epi8(hi, shuf21), madd21), + round2), + 2); + p0 = _mm256_packus_epi16(p0, p0); + p1 = _mm256_packus_epi16(p1, p1); + p2 = _mm256_packus_epi16(p2, p2); + __m256i d01 = _mm256_unpacklo_epi64(p0, p1); + _mm_storeu_si128((__m128i*)dst_ptr, _mm256_castsi256_si128(d01)); + _mm_storel_epi64((__m128i*)(dst_ptr + 16), _mm256_castsi256_si128(p2)); + _mm_storeu_si128((__m128i*)(dst_ptr + 24), _mm256_extracti128_si256(d01, 1)); + _mm_storel_epi64((__m128i*)(dst_ptr + 40), _mm256_extracti128_si256(p2, 1)); + dst_ptr += 48; + dst_width -= 48; + } + if (dst_width > 0) { + __m256i a0 = _mm256_loadu_si256((const __m256i*)src_ptr); + __m256i b0 = _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride)); + __m256i s0 = _mm256_avg_epu8(a0, _mm256_avg_epu8(a0, b0)); + __m128i lo = _mm256_castsi256_si128(s0); + __m128i hi = _mm256_extracti128_si256(s0, 1); + __m128i mid = _mm_alignr_epi8(hi, lo, 8); + __m128i r2 = _mm256_castsi256_si128(round2); + __m128i p0 = _mm_srli_epi16( + _mm_adds_epi16( + _mm_maddubs_epi16(_mm_shuffle_epi8(lo, _mm256_castsi256_si128(shuf01)), + _mm256_castsi256_si128(madd01)), + r2), + 2); + __m128i p1 = _mm_srli_epi16( + _mm_adds_epi16( + _mm_maddubs_epi16( + _mm_shuffle_epi8(mid, _mm256_castsi256_si128(shuf11)), + _mm256_castsi256_si128(madd11)), + r2), + 2); + __m128i p2 = _mm_srli_epi16( + _mm_adds_epi16( + _mm_maddubs_epi16(_mm_shuffle_epi8(hi, _mm256_castsi256_si128(shuf21)), + _mm256_castsi256_si128(madd21)), + r2), + 2); + p0 = _mm_packus_epi16(p0, p0); + p1 = _mm_packus_epi16(p1, p1); + p2 = _mm_packus_epi16(p2, p2); + _mm_storeu_si128((__m128i*)dst_ptr, _mm_unpacklo_epi64(p0, p1)); + _mm_storel_epi64((__m128i*)(dst_ptr + 16), p2); + } +} +#endif // HAS_SCALEROWDOWN34_AVX2 + +#ifdef HAS_SCALEROWDOWN38_AVX2 +static const uvec8 kShuf38a = {0, 3, 6, 8, 11, 14, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128}; +static const uvec8 kShuf38b = {128, 128, 128, 128, 128, 128, 0, 3, + 6, 8, 11, 14, 128, 128, 128, 128}; +static const uvec8 kShufAc = {0, 1, 6, 7, 12, 13, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128}; +static const uvec8 kShufAc3 = {128, 128, 128, 128, 128, 128, 0, 1, + 6, 7, 12, 13, 128, 128, 128, 128}; +static const uvec16 kScaleAc33 = {65536 / 9, 65536 / 9, 65536 / 6, 65536 / 9, + 65536 / 9, 65536 / 6, 0, 0}; +static const uvec8 kShufAb0 = {0, 128, 3, 128, 6, 128, 8, 128, + 11, 128, 14, 128, 128, 128, 128, 128}; +static const uvec8 kShufAb1 = {1, 128, 4, 128, 7, 128, 9, 128, + 12, 128, 15, 128, 128, 128, 128, 128}; +static const uvec8 kShufAb2 = {2, 128, 5, 128, 128, 128, 10, 128, + 13, 128, 128, 128, 128, 128, 128, 128}; +static const uvec16 kScaleAb2 = {65536 / 3, 65536 / 3, 65536 / 2, 65536 / 3, + 65536 / 3, 65536 / 2, 0, 0}; + +LIBYUV_TARGET_AVX2 +void ScaleRowDown38_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + (void)src_stride; + const __m256i shuf38 = _mm256_inserti128_si256( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)&kShuf38a)), + _mm_loadu_si128((const __m128i*)&kShuf38b), 1); + while (dst_width >= 24) { + __m256i s0 = + _mm256_shuffle_epi8(_mm256_loadu_si256((const __m256i*)src_ptr), shuf38); + __m256i s1 = _mm256_shuffle_epi8( + _mm256_loadu_si256((const __m256i*)(src_ptr + 32)), shuf38); + src_ptr += 64; + __m128i d0 = + _mm_or_si128(_mm256_castsi256_si128(s0), _mm256_extracti128_si256(s0, 1)); + __m128i d1 = + _mm_or_si128(_mm256_castsi256_si128(s1), _mm256_extracti128_si256(s1, 1)); + _mm_storel_epi64((__m128i*)dst_ptr, d0); + StoreU32(dst_ptr + 8, (uint32_t)_mm_cvtsi128_si32(_mm_srli_si128(d0, 8))); + _mm_storel_epi64((__m128i*)(dst_ptr + 12), d1); + StoreU32(dst_ptr + 20, (uint32_t)_mm_cvtsi128_si32(_mm_srli_si128(d1, 8))); + dst_ptr += 24; + dst_width -= 24; + } + if (dst_width > 0) { + __m256i s0 = + _mm256_shuffle_epi8(_mm256_loadu_si256((const __m256i*)src_ptr), shuf38); + __m128i d0 = + _mm_or_si128(_mm256_castsi256_si128(s0), _mm256_extracti128_si256(s0, 1)); + _mm_storel_epi64((__m128i*)dst_ptr, d0); + StoreU32(dst_ptr + 8, (uint32_t)_mm_cvtsi128_si32(_mm_srli_si128(d0, 8))); + } +} + +LIBYUV_TARGET_AVX2 +void ScaleRowDown38_2_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const __m256i shuf_ab0 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShufAb0)); + const __m256i shuf_ab1 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShufAb1)); + const __m256i shuf_ab2 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShufAb2)); + const __m256i scale_ab2 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kScaleAb2)); + const __m256i zero = _mm256_setzero_si256(); + while (dst_width > 0) { + __m256i r = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)src_ptr), + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride))); + src_ptr += 32; + __m256i t = _mm256_adds_epu16( + _mm256_adds_epu16(_mm256_shuffle_epi8(r, shuf_ab0), + _mm256_shuffle_epi8(r, shuf_ab1)), + _mm256_shuffle_epi8(r, shuf_ab2)); + t = _mm256_packus_epi16(_mm256_mulhi_epu16(t, scale_ab2), zero); + __m128i d = _mm_or_si128(_mm256_castsi256_si128(t), + _mm_slli_si128(_mm256_extracti128_si256(t, 1), 6)); + _mm_storel_epi64((__m128i*)dst_ptr, d); + StoreU32(dst_ptr + 8, (uint32_t)_mm_cvtsi128_si32(_mm_srli_si128(d, 8))); + dst_ptr += 12; + dst_width -= 12; + } +} + +LIBYUV_TARGET_AVX2 +void ScaleRowDown38_3_Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const __m256i shuf_ac = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShufAc)); + const __m256i shuf_ac3 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kShufAc3)); + const __m256i scale_ac33 = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i*)&kScaleAc33)); + const __m256i zero = _mm256_setzero_si256(); + while (dst_width > 0) { + __m256i r0 = _mm256_loadu_si256((const __m256i*)src_ptr); + __m256i r1 = _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride)); + __m256i r2 = + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride * 2)); + src_ptr += 32; + __m256i s0 = + _mm256_adds_epu16(_mm256_adds_epu16(_mm256_unpacklo_epi8(r0, zero), + _mm256_unpacklo_epi8(r1, zero)), + _mm256_unpacklo_epi8(r2, zero)); + __m256i s1 = + _mm256_adds_epu16(_mm256_adds_epu16(_mm256_unpackhi_epi8(r0, zero), + _mm256_unpackhi_epi8(r1, zero)), + _mm256_unpackhi_epi8(r2, zero)); + __m256i t0 = _mm256_shuffle_epi8( + _mm256_adds_epu16(_mm256_adds_epu16(s0, _mm256_srli_si256(s0, 2)), + _mm256_srli_si256(s0, 4)), + shuf_ac); + __m256i t1 = _mm256_shuffle_epi8( + _mm256_adds_epu16(_mm256_adds_epu16(s1, _mm256_srli_si256(s1, 2)), + _mm256_srli_si256(s1, 4)), + shuf_ac3); + __m256i t = _mm256_packus_epi16( + _mm256_mulhi_epu16(_mm256_adds_epu16(t0, t1), scale_ac33), zero); + __m128i d = _mm_or_si128(_mm256_castsi256_si128(t), + _mm_slli_si128(_mm256_extracti128_si256(t, 1), 6)); + _mm_storel_epi64((__m128i*)dst_ptr, d); + StoreU32(dst_ptr + 8, (uint32_t)_mm_cvtsi128_si32(_mm_srli_si128(d, 8))); + dst_ptr += 12; + dst_width -= 12; + } +} +#endif // HAS_SCALEROWDOWN38_AVX2 + +#ifdef HAS_SCALEADDROW_SSE2 +// Reads 16 bytes and accumulates to 16 shorts at a time. +void ScaleAddRow_SSE2(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int src_width) { + const __m128i zero = _mm_setzero_si128(); + while (src_width > 0) { + __m128i s = _mm_loadu_si128((const __m128i*)src_ptr); + src_ptr += 16; + __m128i d0 = _mm_loadu_si128((const __m128i*)dst_ptr); + __m128i d1 = _mm_loadu_si128((const __m128i*)(dst_ptr + 8)); + d0 = _mm_adds_epu16(d0, _mm_unpacklo_epi8(s, zero)); + d1 = _mm_adds_epu16(d1, _mm_unpackhi_epi8(s, zero)); + _mm_storeu_si128((__m128i*)dst_ptr, d0); + _mm_storeu_si128((__m128i*)(dst_ptr + 8), d1); + dst_ptr += 16; + src_width -= 16; + } +} +#endif // HAS_SCALEADDROW_SSE2 + +#ifdef HAS_SCALEADDROW_AVX2 +// Reads 32 bytes and accumulates to 32 shorts at a time. +LIBYUV_TARGET_AVX2 +void ScaleAddRow_AVX2(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int src_width) { + while (src_width > 0) { + __m256i s0 = _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)src_ptr)); + __m256i s1 = + _mm256_cvtepu8_epi16(_mm_loadu_si128((const __m128i*)(src_ptr + 16))); + src_ptr += 32; + __m256i d0 = _mm256_loadu_si256((const __m256i*)dst_ptr); + __m256i d1 = _mm256_loadu_si256((const __m256i*)(dst_ptr + 16)); + d0 = _mm256_adds_epu16(d0, s0); + d1 = _mm256_adds_epu16(d1, s1); + _mm256_storeu_si256((__m256i*)dst_ptr, d0); + _mm256_storeu_si256((__m256i*)(dst_ptr + 16), d1); + dst_ptr += 32; + src_width -= 32; + } +} +#endif // HAS_SCALEADDROW_AVX2 + +#ifdef HAS_SCALEADDROW_AVX512BW +// Reads 64 bytes and accumulates to 64 shorts at a time, with masked tail. +LIBYUV_TARGET_AVX512BW +void ScaleAddRow_AVX512BW(const uint8_t* src_ptr, + uint16_t* dst_ptr, + int src_width) { + while (src_width >= 64) { + __m512i s0 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)src_ptr)); + __m512i s1 = _mm512_cvtepu8_epi16( + _mm256_loadu_si256((const __m256i*)(src_ptr + 32))); + src_ptr += 64; + __m512i d0 = _mm512_loadu_si512((const __m512i*)dst_ptr); + __m512i d1 = _mm512_loadu_si512((const __m512i*)(dst_ptr + 32)); + d0 = _mm512_adds_epu16(d0, s0); + d1 = _mm512_adds_epu16(d1, s1); + _mm512_storeu_si512((__m512i*)dst_ptr, d0); + _mm512_storeu_si512((__m512i*)(dst_ptr + 32), d1); + dst_ptr += 64; + src_width -= 64; + } + if (src_width >= 32) { + __m512i s0 = + _mm512_cvtepu8_epi16(_mm256_loadu_si256((const __m256i*)src_ptr)); + src_ptr += 32; + __m512i d0 = _mm512_loadu_si512((const __m512i*)dst_ptr); + d0 = _mm512_adds_epu16(d0, s0); + _mm512_storeu_si512((__m512i*)dst_ptr, d0); + dst_ptr += 32; + src_width -= 32; + } + if (src_width > 0) { + __mmask32 k = (__mmask32)((1ULL << src_width) - 1); + __m512i s0 = _mm512_maskz_cvtepu8_epi16( + k, _mm256_maskz_loadu_epi8(k, (const void*)src_ptr)); + __m512i d0 = _mm512_maskz_loadu_epi16(k, (const void*)dst_ptr); + d0 = _mm512_maskz_adds_epu16(k, d0, s0); + _mm512_mask_storeu_epi16((void*)dst_ptr, k, d0); + } +} +#endif // HAS_SCALEADDROW_AVX512BW + +#if defined(HAS_SCALEADDCOLS1_AVX512BW) || defined(HAS_SCALEADDCOLS2_AVX512BW) +static const uint8_t kSequence0_15[16] = {0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15}; +#endif + +#ifdef HAS_SCALEADDCOLS1_AVX512BW +LIBYUV_TARGET_AVX512BW +void ScaleAddCols1_AVX512BW(int dst_width, + int boxheight, + int x, + int dx, + const uint16_t* src_ptr, + uint8_t* dst_ptr) { + int boxwidth = dx >> 16; + if (boxwidth < 1) { + boxwidth = 1; + } + int scaleval = 65536 / (boxwidth * boxheight); + src_ptr += (x >> 16); + const __m512i mask_ffff = _mm512_set1_epi32(0x0000ffff); + const __m512i vscale = _mm512_set1_epi32(scaleval); + if (boxwidth <= 4) { + __m512i seq = + _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*)kSequence0_15)); + seq = _mm512_or_si512(seq, _mm512_slli_epi32(seq, 16)); + __m512i vbw = _mm512_set1_epi16((int16_t)boxwidth); + __m512i base = _mm512_mullo_epi16(seq, vbw); + __m512i c01 = _mm512_set1_epi32(0x00010000); + __m512i c23 = _mm512_set1_epi32(0x00030002); + __m512i idx01 = _mm512_add_epi16(base, c01); + __m512i idx23 = _mm512_add_epi16(base, c23); + __mmask32 k2 = _mm512_cmpgt_epu16_mask(vbw, c01); + __mmask32 k3 = _mm512_cmpgt_epu16_mask(vbw, c23); + int span = boxwidth * 16; + uint64_t m64 = (span >= 64) ? ~0ULL : ((1ULL << span) - 1); + __mmask32 k1 = (__mmask32)m64; + __mmask32 k4 = (__mmask32)(m64 >> 32); + while (dst_width >= 16) { + __m512i s0 = _mm512_maskz_loadu_epi16(k1, src_ptr); + __m512i s1 = _mm512_maskz_loadu_epi16(k4, src_ptr + 32); + src_ptr += span; + __m512i p01 = _mm512_maskz_permutex2var_epi16(k2, s0, idx01, s1); + __m512i p23 = _mm512_maskz_permutex2var_epi16(k3, s0, idx23, s1); + __m512i sum01 = _mm512_add_epi32(_mm512_and_si512(p01, mask_ffff), + _mm512_srli_epi32(p01, 16)); + __m512i sum23 = _mm512_add_epi32(_mm512_and_si512(p23, mask_ffff), + _mm512_srli_epi32(p23, 16)); + __m512i sum = _mm512_add_epi32(sum01, sum23); + sum = _mm512_srli_epi32(_mm512_mullo_epi32(sum, vscale), 16); + _mm_storeu_si128((__m128i*)dst_ptr, _mm512_cvtepi32_epi8(sum)); + dst_ptr += 16; + dst_width -= 16; + } + if (dst_width > 0) { + int rem_span = dst_width * boxwidth; + uint64_t rm64 = (rem_span >= 64) ? ~0ULL : ((1ULL << rem_span) - 1); + __m512i s0 = _mm512_maskz_loadu_epi16((__mmask32)rm64, src_ptr); + __m512i s1 = + _mm512_maskz_loadu_epi16((__mmask32)(rm64 >> 32), src_ptr + 32); + __m512i p01 = _mm512_maskz_permutex2var_epi16(k2, s0, idx01, s1); + __m512i p23 = _mm512_maskz_permutex2var_epi16(k3, s0, idx23, s1); + __m512i sum01 = _mm512_add_epi32(_mm512_and_si512(p01, mask_ffff), + _mm512_srli_epi32(p01, 16)); + __m512i sum23 = _mm512_add_epi32(_mm512_and_si512(p23, mask_ffff), + _mm512_srli_epi32(p23, 16)); + __m512i sum = _mm512_add_epi32(sum01, sum23); + sum = _mm512_srli_epi32(_mm512_mullo_epi32(sum, vscale), 16); + __mmask16 km = (__mmask16)((1U << dst_width) - 1); + // Use _mm_mask_storeu_epi8 instead of _mm512_mask_cvtepi32_storeu_epi8 + // because LLVM MSan does not instrument @llvm.x86.avx512.mask.pmov.db.mem + // to unpoison destination shadow memory. + _mm_mask_storeu_epi8(dst_ptr, km, _mm512_cvtepi32_epi8(sum)); + } + } else if (boxwidth <= 8) { + __m512i seq = + _mm512_cvtepu8_epi64(_mm_loadu_si128((const __m128i*)kSequence0_15)); + seq = _mm512_or_si512(seq, _mm512_slli_epi64(seq, 16)); + seq = _mm512_or_si512(seq, _mm512_slli_epi64(seq, 32)); + __m512i vbw = _mm512_set1_epi16((int16_t)boxwidth); + __m512i base = _mm512_mullo_epi16(seq, vbw); + __m512i c03 = _mm512_set1_epi64(0x0003000200010000ULL); + __m512i c47 = _mm512_set1_epi64(0x0007000600050004ULL); + __m512i idx03 = _mm512_add_epi16(base, c03); + __m512i idx47 = _mm512_add_epi16(base, c47); + __mmask32 k3 = _mm512_cmpgt_epu16_mask(vbw, c47); + int span = boxwidth * 8; + uint64_t m64 = (span >= 64) ? ~0ULL : ((1ULL << span) - 1); + __mmask32 k1 = (__mmask32)m64; + __mmask32 k4 = (__mmask32)(m64 >> 32); + while (dst_width >= 8) { + __m512i s0 = _mm512_maskz_loadu_epi16(k1, src_ptr); + __m512i s1 = _mm512_maskz_loadu_epi16(k4, src_ptr + 32); + src_ptr += span; + __m512i p03 = _mm512_permutex2var_epi16(s0, idx03, s1); + __m512i p47 = _mm512_maskz_permutex2var_epi16(k3, s0, idx47, s1); + __m512i sum03 = _mm512_add_epi32(_mm512_and_si512(p03, mask_ffff), + _mm512_srli_epi32(p03, 16)); + __m512i sum47 = _mm512_add_epi32(_mm512_and_si512(p47, mask_ffff), + _mm512_srli_epi32(p47, 16)); + __m512i sum = _mm512_add_epi32(sum03, sum47); + sum = _mm512_add_epi32(sum, _mm512_srli_epi64(sum, 32)); + sum = _mm512_srli_epi32(_mm512_mullo_epi32(sum, vscale), 16); + _mm_storel_epi64((__m128i*)dst_ptr, _mm512_cvtepi64_epi8(sum)); + dst_ptr += 8; + dst_width -= 8; + } + if (dst_width > 0) { + int rem_span = dst_width * boxwidth; + uint64_t rm64 = (rem_span >= 64) ? ~0ULL : ((1ULL << rem_span) - 1); + __m512i s0 = _mm512_maskz_loadu_epi16((__mmask32)rm64, src_ptr); + __m512i s1 = + _mm512_maskz_loadu_epi16((__mmask32)(rm64 >> 32), src_ptr + 32); + __m512i p03 = _mm512_permutex2var_epi16(s0, idx03, s1); + __m512i p47 = _mm512_maskz_permutex2var_epi16(k3, s0, idx47, s1); + __m512i sum03 = _mm512_add_epi32(_mm512_and_si512(p03, mask_ffff), + _mm512_srli_epi32(p03, 16)); + __m512i sum47 = _mm512_add_epi32(_mm512_and_si512(p47, mask_ffff), + _mm512_srli_epi32(p47, 16)); + __m512i sum = _mm512_add_epi32(sum03, sum47); + sum = _mm512_add_epi32(sum, _mm512_srli_epi64(sum, 32)); + sum = _mm512_srli_epi32(_mm512_mullo_epi32(sum, vscale), 16); + __mmask8 km = (__mmask8)((1U << dst_width) - 1); + // Use _mm_mask_storeu_epi8 instead of _mm512_mask_cvtepi64_storeu_epi8 + // because LLVM MSan does not instrument @llvm.x86.avx512.mask.pmov.qb.mem + // to unpoison destination shadow memory. + _mm_mask_storeu_epi8(dst_ptr, km, _mm512_cvtepi64_epi8(sum)); + } + } else { + int rem = boxwidth & 31; + __mmask32 k1 = (__mmask32)((1ULL << rem) - 1); + while (dst_width > 0) { + __m512i acc = _mm512_setzero_si512(); + const uint16_t* p = src_ptr; + src_ptr += boxwidth; + int n = boxwidth; + while (n >= 32) { + __m512i s = _mm512_loadu_si512((const __m512i*)p); + p += 32; + acc = _mm512_add_epi32(acc, + _mm512_add_epi32(_mm512_and_si512(s, mask_ffff), + _mm512_srli_epi32(s, 16))); + n -= 32; + } + if (n > 0) { + __m512i s = _mm512_maskz_loadu_epi16(k1, p); + acc = _mm512_add_epi32(acc, + _mm512_add_epi32(_mm512_and_si512(s, mask_ffff), + _mm512_srli_epi32(s, 16))); + } + uint32_t total = (uint32_t)_mm512_reduce_add_epi32(acc); + *dst_ptr++ = (uint8_t)((total * (uint32_t)scaleval) >> 16); + --dst_width; + } + } +} +#endif // HAS_SCALEADDCOLS1_AVX512BW + +#ifdef HAS_SCALEADDCOLS2_AVX512BW +LIBYUV_TARGET_AVX512BW +void ScaleAddCols2_AVX512BW(int dst_width, + int boxheight, + int x, + int dx, + const uint16_t* src_ptr, + uint8_t* dst_ptr) { + int minboxwidth = dx >> 16; + int scale0 = 65536 / ((minboxwidth < 1 ? 1 : minboxwidth) * boxheight); + int scale1 = + 65536 / (((minboxwidth + 1) < 1 ? 1 : (minboxwidth + 1)) * boxheight); + const __m512i mask_ffff = _mm512_set1_epi32(0x0000ffff); + const __m512i vscale0 = _mm512_set1_epi32(scale0); + const __m512i vscale1 = _mm512_set1_epi32(scale1); + if (minboxwidth >= 1 && minboxwidth <= 3) { + __m512i seq = + _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*)kSequence0_15)); + __m512i vdx = _mm512_set1_epi32(dx); + __m512i step0 = _mm512_mullo_epi32(seq, vdx); + __m512i step1 = _mm512_add_epi32(step0, vdx); + __m512i c01 = _mm512_set1_epi32(0x00010000); + __m512i c23 = _mm512_set1_epi32(0x00030002); + __m512i vminbw = _mm512_set1_epi32(minboxwidth); + while (dst_width >= 16) { + int base_ix = x >> 16; + __m512i xfrac = _mm512_set1_epi32(x & 0xffff); + x += dx * 16; + int span = (x >> 16) - base_ix; + uint64_t m64 = (span >= 64) ? ~0ULL : ((1ULL << span) - 1); + __m512i s0 = _mm512_maskz_loadu_epi16((__mmask32)m64, src_ptr + base_ix); + __m512i s1 = _mm512_maskz_loadu_epi16((__mmask32)(m64 >> 32), + src_ptr + base_ix + 32); + __m512i ix0 = _mm512_srli_epi32(_mm512_add_epi32(xfrac, step0), 16); + __m512i ix1 = _mm512_srli_epi32(_mm512_add_epi32(xfrac, step1), 16); + __m512i bw = _mm512_sub_epi32(ix1, ix0); + __mmask16 k4 = _mm512_cmpgt_epi32_mask(bw, vminbw); + __m512i ix0_16 = _mm512_or_si512(ix0, _mm512_slli_epi32(ix0, 16)); + __m512i bw_16 = _mm512_or_si512(bw, _mm512_slli_epi32(bw, 16)); + __m512i idx01 = _mm512_add_epi16(ix0_16, c01); + __m512i idx23 = _mm512_add_epi16(ix0_16, c23); + __mmask32 k2 = _mm512_cmpgt_epu16_mask(bw_16, c01); + __mmask32 k3 = _mm512_cmpgt_epu16_mask(bw_16, c23); + __m512i p01 = _mm512_maskz_permutex2var_epi16(k2, s0, idx01, s1); + __m512i p23 = _mm512_maskz_permutex2var_epi16(k3, s0, idx23, s1); + __m512i sum01 = _mm512_add_epi32(_mm512_and_si512(p01, mask_ffff), + _mm512_srli_epi32(p01, 16)); + __m512i sum23 = _mm512_add_epi32(_mm512_and_si512(p23, mask_ffff), + _mm512_srli_epi32(p23, 16)); + __m512i sum = _mm512_add_epi32(sum01, sum23); + __m512i vsc = _mm512_mask_blend_epi32(k4, vscale0, vscale1); + sum = _mm512_srli_epi32(_mm512_mullo_epi32(sum, vsc), 16); + _mm_storeu_si128((__m128i*)dst_ptr, _mm512_cvtepi32_epi8(sum)); + dst_ptr += 16; + dst_width -= 16; + } + if (dst_width > 0) { + int base_ix = x >> 16; + __m512i xfrac = _mm512_set1_epi32(x & 0xffff); + int end_x = x + dx * dst_width; + int span = (end_x >> 16) - base_ix; + uint64_t m64 = (span >= 64) ? ~0ULL : ((1ULL << span) - 1); + __m512i s0 = _mm512_maskz_loadu_epi16((__mmask32)m64, src_ptr + base_ix); + __m512i s1 = _mm512_maskz_loadu_epi16((__mmask32)(m64 >> 32), + src_ptr + base_ix + 32); + __m512i ix0 = _mm512_srli_epi32(_mm512_add_epi32(xfrac, step0), 16); + __m512i ix1 = _mm512_srli_epi32(_mm512_add_epi32(xfrac, step1), 16); + __m512i bw = _mm512_sub_epi32(ix1, ix0); + __mmask16 k4 = _mm512_cmpgt_epi32_mask(bw, vminbw); + __m512i ix0_16 = _mm512_or_si512(ix0, _mm512_slli_epi32(ix0, 16)); + __m512i bw_16 = _mm512_or_si512(bw, _mm512_slli_epi32(bw, 16)); + __m512i idx01 = _mm512_add_epi16(ix0_16, c01); + __m512i idx23 = _mm512_add_epi16(ix0_16, c23); + __mmask32 k2 = _mm512_cmpgt_epu16_mask(bw_16, c01); + __mmask32 k3 = _mm512_cmpgt_epu16_mask(bw_16, c23); + __m512i p01 = _mm512_maskz_permutex2var_epi16(k2, s0, idx01, s1); + __m512i p23 = _mm512_maskz_permutex2var_epi16(k3, s0, idx23, s1); + __m512i sum01 = _mm512_add_epi32(_mm512_and_si512(p01, mask_ffff), + _mm512_srli_epi32(p01, 16)); + __m512i sum23 = _mm512_add_epi32(_mm512_and_si512(p23, mask_ffff), + _mm512_srli_epi32(p23, 16)); + __m512i sum = _mm512_add_epi32(sum01, sum23); + __m512i vsc = _mm512_mask_blend_epi32(k4, vscale0, vscale1); + sum = _mm512_srli_epi32(_mm512_mullo_epi32(sum, vsc), 16); + __mmask16 km = (__mmask16)((1U << dst_width) - 1); + // Use _mm_mask_storeu_epi8 instead of _mm512_mask_cvtepi32_storeu_epi8 + // because LLVM MSan does not instrument @llvm.x86.avx512.mask.pmov.db.mem + // to unpoison destination shadow memory. + _mm_mask_storeu_epi8(dst_ptr, km, _mm512_cvtepi32_epi8(sum)); + } + } else if (minboxwidth >= 4 && minboxwidth <= 7) { + __m512i seq = + _mm512_cvtepu8_epi64(_mm_loadu_si128((const __m128i*)kSequence0_15)); + __m512i vdx = _mm512_set1_epi64(dx); + __m512i step0 = _mm512_mullo_epi32(seq, vdx); + __m512i step1 = _mm512_add_epi64(step0, vdx); + __m512i c03 = _mm512_set1_epi64(0x0003000200010000ULL); + __m512i c47 = _mm512_set1_epi64(0x0007000600050004ULL); + __m512i vminbw = _mm512_set1_epi64(minboxwidth); + while (dst_width >= 8) { + int base_ix = x >> 16; + __m512i xfrac = _mm512_set1_epi64(x & 0xffff); + x += dx * 8; + int span = (x >> 16) - base_ix; + uint64_t m64 = (span >= 64) ? ~0ULL : ((1ULL << span) - 1); + __m512i s0 = _mm512_maskz_loadu_epi16((__mmask32)m64, src_ptr + base_ix); + __m512i s1 = _mm512_maskz_loadu_epi16((__mmask32)(m64 >> 32), + src_ptr + base_ix + 32); + __m512i ix0 = _mm512_srli_epi32(_mm512_add_epi32(xfrac, step0), 16); + __m512i ix1 = _mm512_srli_epi32(_mm512_add_epi32(xfrac, step1), 16); + __m512i bw = _mm512_sub_epi32(ix1, ix0); + __mmask8 k4 = _mm512_cmpgt_epi64_mask(bw, vminbw); + __m512i ix0_16 = _mm512_or_si512(ix0, _mm512_slli_epi64(ix0, 16)); + ix0_16 = _mm512_or_si512(ix0_16, _mm512_slli_epi64(ix0_16, 32)); + __m512i bw_16 = _mm512_or_si512(bw, _mm512_slli_epi64(bw, 16)); + bw_16 = _mm512_or_si512(bw_16, _mm512_slli_epi64(bw_16, 32)); + __m512i idx03 = _mm512_add_epi16(ix0_16, c03); + __m512i idx47 = _mm512_add_epi16(ix0_16, c47); + __mmask32 k3 = _mm512_cmpgt_epu16_mask(bw_16, c47); + __m512i p03 = _mm512_permutex2var_epi16(s0, idx03, s1); + __m512i p47 = _mm512_maskz_permutex2var_epi16(k3, s0, idx47, s1); + __m512i sum03 = _mm512_add_epi32(_mm512_and_si512(p03, mask_ffff), + _mm512_srli_epi32(p03, 16)); + __m512i sum47 = _mm512_add_epi32(_mm512_and_si512(p47, mask_ffff), + _mm512_srli_epi32(p47, 16)); + __m512i sum = _mm512_add_epi32(sum03, sum47); + sum = _mm512_add_epi32(sum, _mm512_srli_epi64(sum, 32)); + __m512i vsc = _mm512_mask_blend_epi64(k4, vscale0, vscale1); + sum = _mm512_srli_epi32(_mm512_mullo_epi32(sum, vsc), 16); + _mm_storel_epi64((__m128i*)dst_ptr, _mm512_cvtepi64_epi8(sum)); + dst_ptr += 8; + dst_width -= 8; + } + if (dst_width > 0) { + int base_ix = x >> 16; + __m512i xfrac = _mm512_set1_epi64(x & 0xffff); + int end_x = x + dx * dst_width; + int span = (end_x >> 16) - base_ix; + uint64_t m64 = (span >= 64) ? ~0ULL : ((1ULL << span) - 1); + __m512i s0 = _mm512_maskz_loadu_epi16((__mmask32)m64, src_ptr + base_ix); + __m512i s1 = _mm512_maskz_loadu_epi16((__mmask32)(m64 >> 32), + src_ptr + base_ix + 32); + __m512i ix0 = _mm512_srli_epi32(_mm512_add_epi32(xfrac, step0), 16); + __m512i ix1 = _mm512_srli_epi32(_mm512_add_epi32(xfrac, step1), 16); + __m512i bw = _mm512_sub_epi32(ix1, ix0); + __mmask8 k4 = _mm512_cmpgt_epi64_mask(bw, vminbw); + __m512i ix0_16 = _mm512_or_si512(ix0, _mm512_slli_epi64(ix0, 16)); + ix0_16 = _mm512_or_si512(ix0_16, _mm512_slli_epi64(ix0_16, 32)); + __m512i bw_16 = _mm512_or_si512(bw, _mm512_slli_epi64(bw, 16)); + bw_16 = _mm512_or_si512(bw_16, _mm512_slli_epi64(bw_16, 32)); + __m512i idx03 = _mm512_add_epi16(ix0_16, c03); + __m512i idx47 = _mm512_add_epi16(ix0_16, c47); + __mmask32 k3 = _mm512_cmpgt_epu16_mask(bw_16, c47); + __m512i p03 = _mm512_permutex2var_epi16(s0, idx03, s1); + __m512i p47 = _mm512_maskz_permutex2var_epi16(k3, s0, idx47, s1); + __m512i sum03 = _mm512_add_epi32(_mm512_and_si512(p03, mask_ffff), + _mm512_srli_epi32(p03, 16)); + __m512i sum47 = _mm512_add_epi32(_mm512_and_si512(p47, mask_ffff), + _mm512_srli_epi32(p47, 16)); + __m512i sum = _mm512_add_epi32(sum03, sum47); + sum = _mm512_add_epi32(sum, _mm512_srli_epi64(sum, 32)); + __m512i vsc = _mm512_mask_blend_epi64(k4, vscale0, vscale1); + sum = _mm512_srli_epi32(_mm512_mullo_epi32(sum, vsc), 16); + __mmask8 km = (__mmask8)((1U << dst_width) - 1); + // Use _mm_mask_storeu_epi8 instead of _mm512_mask_cvtepi64_storeu_epi8 + // because LLVM MSan does not instrument @llvm.x86.avx512.mask.pmov.qb.mem + // to unpoison destination shadow memory. + _mm_mask_storeu_epi8(dst_ptr, km, _mm512_cvtepi64_epi8(sum)); + } + } else { + while (dst_width > 0) { + int ix = x >> 16; + x += dx; + int bw = (x >> 16) - ix; + if (bw < 1) { + bw = 1; + } + int sc = (bw > minboxwidth) ? scale1 : scale0; + __m512i acc = _mm512_setzero_si512(); + const uint16_t* p = src_ptr + ix; + int n = bw; + while (n >= 32) { + __m512i s = _mm512_loadu_si512((const __m512i*)p); + p += 32; + acc = _mm512_add_epi32(acc, + _mm512_add_epi32(_mm512_and_si512(s, mask_ffff), + _mm512_srli_epi32(s, 16))); + n -= 32; + } + if (n > 0) { + __mmask32 k1 = (__mmask32)((1ULL << n) - 1); + __m512i s = _mm512_maskz_loadu_epi16(k1, p); + acc = _mm512_add_epi32(acc, + _mm512_add_epi32(_mm512_and_si512(s, mask_ffff), + _mm512_srli_epi32(s, 16))); + } + uint32_t total = (uint32_t)_mm512_reduce_add_epi32(acc); + *dst_ptr++ = (uint8_t)((total * (uint32_t)sc) >> 16); + --dst_width; + } + } +} +#endif // HAS_SCALEADDCOLS2_AVX512BW + +#ifdef HAS_SCALEUVADDCOLS3_AVX2 +static const ulvec32 kPermUV3_0 = {0, 3, 6, 1, 4, 7, 2, 5}; +static const ulvec32 kPermUV3_1 = {3, 4, 5, 6, 7, 0, 1, 2}; +static const ulvec32 kPermUV3_2 = {6, 7, 0, 1, 2, 3, 4, 5}; + +// Scale UV columns by 3 box filter. +// Reads 96 bytes (24 UV pixels) and writes 16 bytes (8 UV pixels) per block. +LIBYUV_TARGET_AVX2 +void ScaleUVAddCols3_AVX2(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { + const __m256i vscale = _mm256_set1_epi16((int16_t)scaleval); + const __m256i perm0 = _mm256_loadu_si256((const __m256i*)&kPermUV3_0); + const __m256i perm1 = _mm256_loadu_si256((const __m256i*)&kPermUV3_1); + const __m256i perm2 = _mm256_loadu_si256((const __m256i*)&kPermUV3_2); + while (dst_width >= 16) { + __m256i a0 = _mm256_permutevar8x32_epi32( + _mm256_loadu_si256((const __m256i*)src_uv), perm0); + __m256i a1 = _mm256_permutevar8x32_epi32( + _mm256_loadu_si256((const __m256i*)(src_uv + 16)), perm0); + __m256i a2 = _mm256_permutevar8x32_epi32( + _mm256_loadu_si256((const __m256i*)(src_uv + 32)), perm0); + __m256i c0 = _mm256_blend_epi32(_mm256_blend_epi32(a0, a1, 0x38), a2, 0xc0); + __m256i c1 = _mm256_permutevar8x32_epi32( + _mm256_blend_epi32(_mm256_blend_epi32(a0, a1, 0xc0), a2, 0x07), perm1); + __m256i c2 = _mm256_permutevar8x32_epi32( + _mm256_blend_epi32(_mm256_blend_epi32(a0, a1, 0x07), a2, 0x38), perm2); + __m256i sum0 = _mm256_mulhi_epu16( + _mm256_add_epi16(_mm256_add_epi16(c0, c1), c2), vscale); + + __m256i b0 = _mm256_permutevar8x32_epi32( + _mm256_loadu_si256((const __m256i*)(src_uv + 48)), perm0); + __m256i b1 = _mm256_permutevar8x32_epi32( + _mm256_loadu_si256((const __m256i*)(src_uv + 64)), perm0); + __m256i b2 = _mm256_permutevar8x32_epi32( + _mm256_loadu_si256((const __m256i*)(src_uv + 80)), perm0); + src_uv += 96; + __m256i d0 = _mm256_blend_epi32(_mm256_blend_epi32(b0, b1, 0x38), b2, 0xc0); + __m256i d1 = _mm256_permutevar8x32_epi32( + _mm256_blend_epi32(_mm256_blend_epi32(b0, b1, 0xc0), b2, 0x07), perm1); + __m256i d2 = _mm256_permutevar8x32_epi32( + _mm256_blend_epi32(_mm256_blend_epi32(b0, b1, 0x07), b2, 0x38), perm2); + __m256i sum1 = _mm256_mulhi_epu16( + _mm256_add_epi16(_mm256_add_epi16(d0, d1), d2), vscale); + + __m256i packed = + _mm256_permute4x64_epi64(_mm256_packus_epi16(sum0, sum1), 0xd8); + _mm256_storeu_si256((__m256i*)dst_uv, packed); + dst_uv += 32; + dst_width -= 16; + } + while (dst_width > 0) { + __m256i a0 = _mm256_permutevar8x32_epi32( + _mm256_loadu_si256((const __m256i*)src_uv), perm0); + __m256i a1 = _mm256_permutevar8x32_epi32( + _mm256_loadu_si256((const __m256i*)(src_uv + 16)), perm0); + __m256i a2 = _mm256_permutevar8x32_epi32( + _mm256_loadu_si256((const __m256i*)(src_uv + 32)), perm0); + src_uv += 48; + __m256i c0 = _mm256_blend_epi32(_mm256_blend_epi32(a0, a1, 0x38), a2, 0xc0); + __m256i c1 = _mm256_permutevar8x32_epi32( + _mm256_blend_epi32(_mm256_blend_epi32(a0, a1, 0xc0), a2, 0x07), perm1); + __m256i c2 = _mm256_permutevar8x32_epi32( + _mm256_blend_epi32(_mm256_blend_epi32(a0, a1, 0x07), a2, 0x38), perm2); + __m256i sum = _mm256_mulhi_epu16( + _mm256_add_epi16(_mm256_add_epi16(c0, c1), c2), vscale); + __m128i lo = _mm256_castsi256_si128(sum); + __m128i hi = _mm256_extracti128_si256(sum, 1); + _mm_storeu_si128((__m128i*)dst_uv, _mm_packus_epi16(lo, hi)); + dst_uv += 16; + dst_width -= 8; + } +} +#endif // HAS_SCALEUVADDCOLS3_AVX2 + +#ifdef HAS_SCALEUVADDCOLS3_AVX512VBMI +static const uint8_t kPerm512_Col0[16] = {0, 3, 6, 9, 12, 15, 18, 21, + 24, 27, 30, 1, 4, 7, 10, 13}; +static const uint8_t kPerm512_Col1[16] = {1, 4, 7, 10, 13, 16, 19, 22, + 25, 28, 31, 2, 5, 8, 11, 14}; +static const uint8_t kPerm512_Col2[16] = {2, 5, 8, 11, 14, 17, 20, 23, + 26, 29, 0, 3, 6, 9, 12, 15}; +static const uint8_t kPackEvenBytes[64] = { + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, + 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, + 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, + 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, + 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126}; + +// Under MemorySanitizer, use a portable lane-by-lane C loop so shadow +// propagation relies only on standard C memory/array semantics rather than +// target-specific LLVM intrinsic modeling. In non-MSan builds, call the native +// AVX-512 intrinsic directly. +LIBYUV_TARGET_AVX512VBMI +static inline __m512i MaskPermutexvarEpi32(__m512i src, + __mmask16 k, + __m512i idx, + __m512i v) { +#if defined(LIBYUV_MSAN) + uint32_t src_arr[16]; + uint32_t idx_arr[16]; + uint32_t v_arr[16]; + uint32_t out_arr[16]; + _mm512_storeu_si512((__m512i*)src_arr, src); + _mm512_storeu_si512((__m512i*)idx_arr, idx); + _mm512_storeu_si512((__m512i*)v_arr, v); + for (int i = 0; i < 16; ++i) { + out_arr[i] = ((k >> i) & 1) ? v_arr[idx_arr[i] & 15] : src_arr[i]; + } + return _mm512_loadu_si512((const __m512i*)out_arr); +#else + return _mm512_mask_permutexvar_epi32(src, k, idx, v); +#endif +} + +// Scale UV columns by 3 box filter using AVX512VBMI. +// Processes 32 UV pixels (384 input bytes -> 64 output bytes) per main loop +// iteration, followed by a 16-pixel block and a k-masked tail (1..15 pixels). +LIBYUV_TARGET_AVX512VBMI +void ScaleUVAddCols3_AVX512VBMI(int dst_width, + int scaleval, + const uint16_t* src_uv, + uint8_t* dst_uv) { + const __m512i vscale = _mm512_set1_epi16((int16_t)scaleval); + const __m512i col0 = + _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*)kPerm512_Col0)); + const __m512i col1 = + _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*)kPerm512_Col1)); + const __m512i col2 = + _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*)kPerm512_Col2)); + const __m512i pack_even = _mm512_loadu_si512((const __m512i*)kPackEvenBytes); + const __mmask16 k5 = 0xf800; + const __mmask16 k6 = 0xfc00; + + while (dst_width >= 32) { + __m512i s0 = _mm512_loadu_si512((const __m512i*)src_uv); + __m512i s1 = _mm512_loadu_si512((const __m512i*)(src_uv + 32)); + __m512i s2 = _mm512_loadu_si512((const __m512i*)(src_uv + 64)); + __m512i a0 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s0, col0, s1), + k5, col0, s2); + __m512i a1 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s0, col1, s1), + k5, col1, s2); + __m512i a2 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s0, col2, s1), + k6, col2, s2); + __m512i sum0 = _mm512_mulhi_epu16( + _mm512_add_epi16(_mm512_add_epi16(a0, a1), a2), vscale); + + __m512i s3 = _mm512_loadu_si512((const __m512i*)(src_uv + 96)); + __m512i s4 = _mm512_loadu_si512((const __m512i*)(src_uv + 128)); + __m512i s5 = _mm512_loadu_si512((const __m512i*)(src_uv + 160)); + src_uv += 192; + __m512i b0 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s3, col0, s4), + k5, col0, s5); + __m512i b1 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s3, col1, s4), + k5, col1, s5); + __m512i b2 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s3, col2, s4), + k6, col2, s5); + __m512i sum1 = _mm512_mulhi_epu16( + _mm512_add_epi16(_mm512_add_epi16(b0, b1), b2), vscale); + + __m512i out = _mm512_permutex2var_epi8(sum0, pack_even, sum1); + _mm512_storeu_si512((__m512i*)dst_uv, out); + dst_uv += 64; + dst_width -= 32; + } + if (dst_width >= 16) { + __m512i s0 = _mm512_loadu_si512((const __m512i*)src_uv); + __m512i s1 = _mm512_loadu_si512((const __m512i*)(src_uv + 32)); + __m512i s2 = _mm512_loadu_si512((const __m512i*)(src_uv + 64)); + src_uv += 96; + __m512i a0 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s0, col0, s1), + k5, col0, s2); + __m512i a1 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s0, col1, s1), + k5, col1, s2); + __m512i a2 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s0, col2, s1), + k6, col2, s2); + __m512i sum0 = _mm512_mulhi_epu16( + _mm512_add_epi16(_mm512_add_epi16(a0, a1), a2), vscale); + _mm256_storeu_si256((__m256i*)dst_uv, _mm512_cvtepi16_epi8(sum0)); + dst_uv += 32; + dst_width -= 16; + } + if (dst_width > 0) { + uint64_t m64 = (1ULL << (dst_width * 3)) - 1; + __mmask16 k1 = (__mmask16)m64; + __mmask16 k2 = (__mmask16)(m64 >> 16); + __mmask16 k3 = (__mmask16)(m64 >> 32); + __mmask16 k4 = (__mmask16)((1U << dst_width) - 1); + __m512i s0 = _mm512_maskz_loadu_epi32(k1, src_uv); + __m512i s1 = _mm512_maskz_loadu_epi32(k2, src_uv + 32); + __m512i s2 = _mm512_maskz_loadu_epi32(k3, src_uv + 64); + __m512i a0 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s0, col0, s1), + k5, col0, s2); + __m512i a1 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s0, col1, s1), + k5, col1, s2); + __m512i a2 = MaskPermutexvarEpi32(_mm512_permutex2var_epi32(s0, col2, s1), + k6, col2, s2); + __m512i sum0 = _mm512_mulhi_epu16( + _mm512_add_epi16(_mm512_add_epi16(a0, a1), a2), vscale); + _mm256_mask_storeu_epi16(dst_uv, k4, _mm512_cvtepi16_epi8(sum0)); + } +} +#endif // HAS_SCALEUVADDCOLS3_AVX512VBMI + +#if defined(HAS_SCALEROWUP2_LINEAR_AVX2) || \ + defined(HAS_SCALEROWUP2_BILINEAR_AVX2) +static const uvec8 kLinearMadd31 = {3, 1, 1, 3, 3, 1, 1, 3, + 3, 1, 1, 3, 3, 1, 1, 3}; +#endif + +#if defined(HAS_SCALEROWUP2_LINEAR_12_AVX2) || \ + defined(HAS_SCALEROWUP2_BILINEAR_12_AVX2) +static const uvec8 kLinearShuffleFar = {2, 3, 0, 1, 6, 7, 4, 5, + 10, 11, 8, 9, 14, 15, 12, 13}; +#endif + +#ifdef HAS_SCALEROWUP2_LINEAR_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleRowUp2_Linear_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + const __m256i madd31 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)&kLinearMadd31)); + const __m256i round2 = _mm256_set1_epi16(2); + while (dst_width > 0) { + __m256i s0 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)src_ptr)), 0xd8); + __m256i s1 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)(src_ptr + 1))), + 0xd8); + src_ptr += 16; + s0 = _mm256_unpacklo_epi16(s0, s0); + s1 = _mm256_unpacklo_epi16(s1, s1); + __m256i lo = _mm256_maddubs_epi16(_mm256_unpacklo_epi32(s0, s1), madd31); + __m256i hi = _mm256_maddubs_epi16(_mm256_unpackhi_epi32(s0, s1), madd31); + lo = _mm256_srli_epi16(_mm256_add_epi16(lo, round2), 2); + hi = _mm256_srli_epi16(_mm256_add_epi16(hi, round2), 2); + _mm256_storeu_si256((__m256i*)dst_ptr, _mm256_packus_epi16(lo, hi)); + dst_ptr += 32; + dst_width -= 32; + } +} +#endif // HAS_SCALEROWUP2_LINEAR_AVX2 + +#ifdef HAS_SCALEROWUP2_BILINEAR_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleRowUp2_Bilinear_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const __m256i madd31 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)&kLinearMadd31)); + const __m256i round8 = _mm256_set1_epi16(8); + while (dst_width > 0) { + __m256i a0 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)src_ptr)), 0xd8); + __m256i a1 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)(src_ptr + 1))), + 0xd8); + a0 = _mm256_unpacklo_epi16(a0, a0); + a1 = _mm256_unpacklo_epi16(a1, a1); + __m256i r0_lo = _mm256_maddubs_epi16(_mm256_unpacklo_epi32(a0, a1), madd31); + __m256i r0_hi = _mm256_maddubs_epi16(_mm256_unpackhi_epi32(a0, a1), madd31); + + __m256i b0 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256( + _mm_loadu_si128((const __m128i*)(src_ptr + src_stride))), + 0xd8); + __m256i b1 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256( + _mm_loadu_si128((const __m128i*)(src_ptr + src_stride + 1))), + 0xd8); + src_ptr += 16; + b0 = _mm256_unpacklo_epi16(b0, b0); + b1 = _mm256_unpacklo_epi16(b1, b1); + __m256i r1_lo = _mm256_maddubs_epi16(_mm256_unpacklo_epi32(b0, b1), madd31); + __m256i r1_hi = _mm256_maddubs_epi16(_mm256_unpackhi_epi32(b0, b1), madd31); + + __m256i d0_lo = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(r0_lo, r0_lo), r0_lo), + _mm256_add_epi16(r1_lo, round8)), + 4); + __m256i d1_lo = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(r1_lo, r1_lo), r1_lo), + _mm256_add_epi16(r0_lo, round8)), + 4); + __m256i d0_hi = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(r0_hi, r0_hi), r0_hi), + _mm256_add_epi16(r1_hi, round8)), + 4); + __m256i d1_hi = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(r1_hi, r1_hi), r1_hi), + _mm256_add_epi16(r0_hi, round8)), + 4); + + _mm256_storeu_si256((__m256i*)dst_ptr, _mm256_packus_epi16(d0_lo, d0_hi)); + _mm256_storeu_si256((__m256i*)(dst_ptr + dst_stride), + _mm256_packus_epi16(d1_lo, d1_hi)); + dst_ptr += 32; + dst_width -= 32; + } +} +#endif // HAS_SCALEROWUP2_BILINEAR_AVX2 + +#ifdef HAS_SCALEROWUP2_LINEAR_12_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleRowUp2_Linear_12_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + const __m256i shuf_far = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)&kLinearShuffleFar)); + const __m256i round2 = _mm256_set1_epi16(2); + while (dst_width > 0) { + __m256i s0 = + _mm256_permute4x64_epi64(_mm256_loadu_si256((const __m256i*)src_ptr), + 0xd8); + __m256i s1 = _mm256_permute4x64_epi64( + _mm256_loadu_si256((const __m256i*)(src_ptr + 1)), 0xd8); + src_ptr += 16; + __m256i near_lo = _mm256_unpacklo_epi16(s0, s1); + __m256i near_hi = _mm256_unpackhi_epi16(s0, s1); + __m256i far_lo = _mm256_shuffle_epi8(near_lo, shuf_far); + __m256i far_hi = _mm256_shuffle_epi8(near_hi, shuf_far); + __m256i d_lo = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(near_lo, near_lo), + _mm256_add_epi16(near_lo, _mm256_add_epi16(far_lo, round2))), + 2); + __m256i d_hi = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(near_hi, near_hi), + _mm256_add_epi16(near_hi, _mm256_add_epi16(far_hi, round2))), + 2); + _mm256_storeu_si256((__m256i*)dst_ptr, d_lo); + _mm256_storeu_si256((__m256i*)(dst_ptr + 16), d_hi); + dst_ptr += 32; + dst_width -= 32; + } +} +#endif // HAS_SCALEROWUP2_LINEAR_12_AVX2 + +#ifdef HAS_SCALEROWUP2_BILINEAR_12_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleRowUp2_Bilinear_12_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const __m256i shuf_far = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)&kLinearShuffleFar)); + const __m256i round8 = _mm256_set1_epi16(8); + while (dst_width > 0) { + __m256i a0 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)src_ptr)), 0xd8); + __m256i a1 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)(src_ptr + 1))), + 0xd8); + __m256i near0 = _mm256_unpacklo_epi16(a0, a1); + __m256i far0 = _mm256_shuffle_epi8(near0, shuf_far); + __m256i r0 = _mm256_add_epi16(_mm256_add_epi16(near0, near0), + _mm256_add_epi16(near0, far0)); + + __m256i b0 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256( + _mm_loadu_si128((const __m128i*)(src_ptr + src_stride))), + 0xd8); + __m256i b1 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256( + _mm_loadu_si128((const __m128i*)(src_ptr + src_stride + 1))), + 0xd8); + src_ptr += 8; + __m256i near1 = _mm256_unpacklo_epi16(b0, b1); + __m256i far1 = _mm256_shuffle_epi8(near1, shuf_far); + __m256i r1 = _mm256_add_epi16(_mm256_add_epi16(near1, near1), + _mm256_add_epi16(near1, far1)); + + __m256i d0 = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(r0, r0), r0), + _mm256_add_epi16(r1, round8)), + 4); + __m256i d1 = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(r1, r1), r1), + _mm256_add_epi16(r0, round8)), + 4); + _mm256_storeu_si256((__m256i*)dst_ptr, d0); + _mm256_storeu_si256((__m256i*)(dst_ptr + dst_stride), d1); + dst_ptr += 16; + dst_width -= 16; + } +} +#endif // HAS_SCALEROWUP2_BILINEAR_12_AVX2 + +#ifdef HAS_SCALEROWUP2_LINEAR_16_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleRowUp2_Linear_16_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + const __m256i round2 = _mm256_set1_epi32(2); + while (dst_width > 0) { + __m256i near_lo = + _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)src_ptr)); + __m256i near_hi = + _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)(src_ptr + 1))); + src_ptr += 8; + __m256i far_lo = _mm256_shuffle_epi32(near_lo, 0xb1); + __m256i far_hi = _mm256_shuffle_epi32(near_hi, 0xb1); + __m256i d_lo = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(near_lo, near_lo), + _mm256_add_epi32(near_lo, _mm256_add_epi32(far_lo, round2))), + 2); + __m256i d_hi = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(near_hi, near_hi), + _mm256_add_epi32(near_hi, _mm256_add_epi32(far_hi, round2))), + 2); + __m256i d = _mm256_shuffle_epi32(_mm256_packus_epi32(d_lo, d_hi), 0xd8); + _mm256_storeu_si256((__m256i*)dst_ptr, d); + dst_ptr += 16; + dst_width -= 16; + } +} +#endif // HAS_SCALEROWUP2_LINEAR_16_AVX2 + +#ifdef HAS_SCALEROWUP2_BILINEAR_16_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleRowUp2_Bilinear_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const __m256i round8 = _mm256_set1_epi32(8); + while (dst_width > 0) { + __m256i a0 = + _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)src_ptr)); + __m256i a1 = + _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)(src_ptr + 1))); + __m256i r0_lo = _mm256_add_epi32( + _mm256_add_epi32(a0, a0), + _mm256_add_epi32(a0, _mm256_shuffle_epi32(a0, 0xb1))); + __m256i r0_hi = _mm256_add_epi32( + _mm256_add_epi32(a1, a1), + _mm256_add_epi32(a1, _mm256_shuffle_epi32(a1, 0xb1))); + + __m256i b0 = _mm256_cvtepu16_epi32( + _mm_loadu_si128((const __m128i*)(src_ptr + src_stride))); + __m256i b1 = _mm256_cvtepu16_epi32( + _mm_loadu_si128((const __m128i*)(src_ptr + src_stride + 1))); + src_ptr += 8; + __m256i r1_lo = _mm256_add_epi32( + _mm256_add_epi32(b0, b0), + _mm256_add_epi32(b0, _mm256_shuffle_epi32(b0, 0xb1))); + __m256i r1_hi = _mm256_add_epi32( + _mm256_add_epi32(b1, b1), + _mm256_add_epi32(b1, _mm256_shuffle_epi32(b1, 0xb1))); + + __m256i d0_lo = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(r0_lo, r0_lo), r0_lo), + _mm256_add_epi32(r1_lo, round8)), + 4); + __m256i d1_lo = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(r1_lo, r1_lo), r1_lo), + _mm256_add_epi32(r0_lo, round8)), + 4); + __m256i d0_hi = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(r0_hi, r0_hi), r0_hi), + _mm256_add_epi32(r1_hi, round8)), + 4); + __m256i d1_hi = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(r1_hi, r1_hi), r1_hi), + _mm256_add_epi32(r0_hi, round8)), + 4); + + _mm256_storeu_si256( + (__m256i*)dst_ptr, + _mm256_shuffle_epi32(_mm256_packus_epi32(d0_lo, d0_hi), 0xd8)); + _mm256_storeu_si256( + (__m256i*)(dst_ptr + dst_stride), + _mm256_shuffle_epi32(_mm256_packus_epi32(d1_lo, d1_hi), 0xd8)); + dst_ptr += 16; + dst_width -= 16; + } +} +#endif // HAS_SCALEROWUP2_BILINEAR_16_AVX2 + +#ifdef HAS_SCALEFILTERCOLS_AVX2 +static const int32_t kStep0_7_Filter[8] = {0, 1, 2, 3, 4, 5, 6, 7}; +static const uvec8 kShufFracCols = {0, 0, 4, 4, 8, 8, 12, 12, + 128, 128, 128, 128, 128, 128, 128, 128}; + +LIBYUV_TARGET_AVX2 +void ScaleFilterCols_AVX2(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx) { + int n = dst_width & ~7; + int r = dst_width & 7; + if (n > 0) { + SIMD_ALIGNED(int32_t xi_buf[8]); + SIMD_ALIGNED(uint16_t pix_buf[8]); + __m256i vx = _mm256_add_epi32( + _mm256_set1_epi32(x), + _mm256_mullo_epi32( + _mm256_set1_epi32(dx), + _mm256_loadu_si256((const __m256i*)kStep0_7_Filter))); + const __m256i vdx8 = _mm256_slli_epi32(_mm256_set1_epi32(dx), 3); + const __m256i shuf_frac = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)&kShufFracCols)); + const __m128i mask_7f = _mm_set1_epi16(0x007f); + const __m128i mask_ff = _mm_set1_epi16(0x00ff); + const __m128i round_40 = _mm_set1_epi16(0x0040); + for (int i = 0; i < n; i += 8) { + _mm256_store_si256((__m256i*)xi_buf, _mm256_srai_epi32(vx, 16)); + __m256i f256 = _mm256_permute4x64_epi64( + _mm256_shuffle_epi8(_mm256_srli_epi16(vx, 9), shuf_frac), 0xd8); + vx = _mm256_add_epi32(vx, vdx8); + __m128i weights = _mm_xor_si128(_mm256_castsi256_si128(f256), mask_7f); + pix_buf[0] = LoadU16(src_ptr + xi_buf[0]); + pix_buf[1] = LoadU16(src_ptr + xi_buf[1]); + pix_buf[2] = LoadU16(src_ptr + xi_buf[2]); + pix_buf[3] = LoadU16(src_ptr + xi_buf[3]); + pix_buf[4] = LoadU16(src_ptr + xi_buf[4]); + pix_buf[5] = LoadU16(src_ptr + xi_buf[5]); + pix_buf[6] = LoadU16(src_ptr + xi_buf[6]); + pix_buf[7] = LoadU16(src_ptr + xi_buf[7]); + __m128i pix = _mm_load_si128((const __m128i*)pix_buf); + __m128i a = _mm_and_si128(pix, mask_ff); + __m128i res = _mm_srli_epi16( + _mm_add_epi16(_mm_add_epi16(_mm_maddubs_epi16(pix, weights), a), + round_40), + 7); + _mm_storel_epi64((__m128i*)dst_ptr, _mm_packus_epi16(res, res)); + dst_ptr += 8; + } + x = (int)((uint32_t)x + (uint32_t)n * (uint32_t)dx); + } + for (int j = 0; j < r; ++j) { + int xi = x >> 16; + int a = src_ptr[xi]; + int b = src_ptr[xi + 1]; + dst_ptr[j] = (uint8_t)(a + ((((x & 0xffff) >> 9) * (b - a) + 0x40) >> 7)); + x = (int)((uint32_t)x + (uint32_t)dx); + } +} +#endif // HAS_SCALEFILTERCOLS_AVX2 + +#ifdef HAS_SCALECOLSUP2_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleColsUp2_AVX2(uint8_t* dst_ptr, + const uint8_t* src_ptr, + int dst_width, + int x, + int dx) { + (void)x; + (void)dx; + while (dst_width >= 32) { + __m256i s = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)src_ptr)), 0xd8); + src_ptr += 16; + _mm256_storeu_si256((__m256i*)dst_ptr, _mm256_unpacklo_epi8(s, s)); + dst_ptr += 32; + dst_width -= 32; + } + if (dst_width & 16) { + __m128i s = _mm_loadl_epi64((const __m128i*)src_ptr); + src_ptr += 8; + _mm_storeu_si128((__m128i*)dst_ptr, _mm_unpacklo_epi8(s, s)); + dst_ptr += 16; + } + if (dst_width & 8) { + __m128i s = _mm_cvtsi32_si128((int)LoadU32(src_ptr)); + _mm_storel_epi64((__m128i*)dst_ptr, _mm_unpacklo_epi8(s, s)); + } +} +#endif // HAS_SCALECOLSUP2_AVX2 + +#ifdef HAS_SCALEARGBROWDOWN2_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleARGBRowDown2_AVX2(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + __m256 s0 = _mm256_loadu_ps((const float*)src_argb); + __m256 s1 = _mm256_loadu_ps((const float*)(src_argb + 32)); + src_argb += 64; + __m256i d = _mm256_permute4x64_epi64( + _mm256_castps_si256(_mm256_shuffle_ps(s0, s1, 0xdd)), 0xd8); + _mm256_storeu_si256((__m256i*)dst_argb, d); + dst_argb += 32; + dst_width -= 8; + } +} + +LIBYUV_TARGET_AVX2 +void ScaleARGBRowDown2Linear_AVX2(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + while (dst_width > 0) { + __m256 s0 = _mm256_loadu_ps((const float*)src_argb); + __m256 s1 = _mm256_loadu_ps((const float*)(src_argb + 32)); + src_argb += 64; + __m256i e = _mm256_castps_si256(_mm256_shuffle_ps(s0, s1, 0x88)); + __m256i o = _mm256_castps_si256(_mm256_shuffle_ps(s0, s1, 0xdd)); + __m256i d = _mm256_permute4x64_epi64(_mm256_avg_epu8(e, o), 0xd8); + _mm256_storeu_si256((__m256i*)dst_argb, d); + dst_argb += 32; + dst_width -= 8; + } +} + +LIBYUV_TARGET_AVX2 +void ScaleARGBRowDown2Box_AVX2(const uint8_t* src_argb, + ptrdiff_t src_stride, + uint8_t* dst_argb, + int dst_width) { + while (dst_width > 0) { + __m256i r0 = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)src_argb), + _mm256_loadu_si256((const __m256i*)(src_argb + src_stride))); + __m256i r1 = _mm256_avg_epu8( + _mm256_loadu_si256((const __m256i*)(src_argb + 32)), + _mm256_loadu_si256((const __m256i*)(src_argb + src_stride + 32))); + src_argb += 64; + __m256i e = _mm256_castps_si256( + _mm256_shuffle_ps(_mm256_castsi256_ps(r0), _mm256_castsi256_ps(r1), + 0x88)); + __m256i o = _mm256_castps_si256( + _mm256_shuffle_ps(_mm256_castsi256_ps(r0), _mm256_castsi256_ps(r1), + 0xdd)); + __m256i d = _mm256_permute4x64_epi64(_mm256_avg_epu8(e, o), 0xd8); + _mm256_storeu_si256((__m256i*)dst_argb, d); + dst_argb += 32; + dst_width -= 8; + } +} +#endif // HAS_SCALEARGBROWDOWN2_AVX2 + +#ifdef HAS_SCALEARGBROWDOWNEVEN_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleARGBRowDownEven_AVX2(const uint8_t* src_argb, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_argb, + int dst_width) { + (void)src_stride; + const ptrdiff_t step = (ptrdiff_t)src_stepx * 4; + SIMD_ALIGNED(uint32_t pix_buf[8]); + while (dst_width > 0) { + pix_buf[0] = LoadU32(src_argb); + pix_buf[1] = LoadU32(src_argb + step); + pix_buf[2] = LoadU32(src_argb + step * 2); + pix_buf[3] = LoadU32(src_argb + step * 3); + pix_buf[4] = LoadU32(src_argb + step * 4); + pix_buf[5] = LoadU32(src_argb + step * 5); + pix_buf[6] = LoadU32(src_argb + step * 6); + pix_buf[7] = LoadU32(src_argb + step * 7); + src_argb += step * 8; + _mm256_storeu_si256((__m256i*)dst_argb, + _mm256_load_si256((const __m256i*)pix_buf)); + dst_argb += 32; + dst_width -= 8; + } +} + +LIBYUV_TARGET_AVX2 +void ScaleARGBRowDownEvenBox_AVX2(const uint8_t* src_argb, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_argb, + int dst_width) { + const uint8_t* row1 = src_argb + src_stride; + const ptrdiff_t step = (ptrdiff_t)src_stepx * 4; + SIMD_ALIGNED(uint64_t r0_lo[4]); + SIMD_ALIGNED(uint64_t r0_hi[4]); + SIMD_ALIGNED(uint64_t r1_lo[4]); + SIMD_ALIGNED(uint64_t r1_hi[4]); + while (dst_width > 0) { + r0_lo[0] = LoadU64(src_argb); + r0_lo[1] = LoadU64(src_argb + step); + r0_lo[2] = LoadU64(src_argb + step * 2); + r0_lo[3] = LoadU64(src_argb + step * 3); + r0_hi[0] = LoadU64(src_argb + step * 4); + r0_hi[1] = LoadU64(src_argb + step * 5); + r0_hi[2] = LoadU64(src_argb + step * 6); + r0_hi[3] = LoadU64(src_argb + step * 7); + r1_lo[0] = LoadU64(row1); + r1_lo[1] = LoadU64(row1 + step); + r1_lo[2] = LoadU64(row1 + step * 2); + r1_lo[3] = LoadU64(row1 + step * 3); + r1_hi[0] = LoadU64(row1 + step * 4); + r1_hi[1] = LoadU64(row1 + step * 5); + r1_hi[2] = LoadU64(row1 + step * 6); + r1_hi[3] = LoadU64(row1 + step * 7); + src_argb += step * 8; + row1 += step * 8; + __m256i a0 = _mm256_avg_epu8(_mm256_load_si256((const __m256i*)r0_lo), + _mm256_load_si256((const __m256i*)r1_lo)); + __m256i a1 = _mm256_avg_epu8(_mm256_load_si256((const __m256i*)r0_hi), + _mm256_load_si256((const __m256i*)r1_hi)); + __m256i e = _mm256_castps_si256( + _mm256_shuffle_ps(_mm256_castsi256_ps(a0), _mm256_castsi256_ps(a1), + 0x88)); + __m256i o = _mm256_castps_si256( + _mm256_shuffle_ps(_mm256_castsi256_ps(a0), _mm256_castsi256_ps(a1), + 0xdd)); + __m256i d = _mm256_permute4x64_epi64(_mm256_avg_epu8(e, o), 0xd8); + _mm256_storeu_si256((__m256i*)dst_argb, d); + dst_argb += 32; + dst_width -= 8; + } +} +#endif // HAS_SCALEARGBROWDOWNEVEN_AVX2 + +#ifdef HAS_SCALEARGBCOLS_AVX2 +static const int32_t kStep0_7_Cols[8] = {0, 1, 2, 3, 4, 5, 6, 7}; + +LIBYUV_TARGET_AVX2 +void ScaleARGBCols_AVX2(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx) { + int n = dst_width & ~7; + int r = dst_width & 7; + if (n > 0) { + SIMD_ALIGNED(int32_t xi_buf[8]); + SIMD_ALIGNED(uint32_t pix_buf[8]); + __m256i vx = _mm256_add_epi32( + _mm256_set1_epi32(x), + _mm256_mullo_epi32( + _mm256_set1_epi32(dx), + _mm256_loadu_si256((const __m256i*)kStep0_7_Cols))); + const __m256i vdx8 = _mm256_slli_epi32(_mm256_set1_epi32(dx), 3); + for (int i = 0; i < n; i += 8) { + _mm256_store_si256((__m256i*)xi_buf, _mm256_srai_epi32(vx, 16)); + vx = _mm256_add_epi32(vx, vdx8); + pix_buf[0] = LoadU32(src_argb + (ptrdiff_t)xi_buf[0] * 4); + pix_buf[1] = LoadU32(src_argb + (ptrdiff_t)xi_buf[1] * 4); + pix_buf[2] = LoadU32(src_argb + (ptrdiff_t)xi_buf[2] * 4); + pix_buf[3] = LoadU32(src_argb + (ptrdiff_t)xi_buf[3] * 4); + pix_buf[4] = LoadU32(src_argb + (ptrdiff_t)xi_buf[4] * 4); + pix_buf[5] = LoadU32(src_argb + (ptrdiff_t)xi_buf[5] * 4); + pix_buf[6] = LoadU32(src_argb + (ptrdiff_t)xi_buf[6] * 4); + pix_buf[7] = LoadU32(src_argb + (ptrdiff_t)xi_buf[7] * 4); + _mm256_storeu_si256((__m256i*)dst_argb, + _mm256_load_si256((const __m256i*)pix_buf)); + dst_argb += 32; + } + x = (int)((uint32_t)x + (uint32_t)n * (uint32_t)dx); + } + for (int j = 0; j < r; ++j) { + const uint8_t* src = src_argb + (ptrdiff_t)(x >> 16) * 4; + dst_argb[0] = src[0]; + dst_argb[1] = src[1]; + dst_argb[2] = src[2]; + dst_argb[3] = src[3]; + dst_argb += 4; + x = (int)((uint32_t)x + (uint32_t)dx); + } +} +#endif // HAS_SCALEARGBCOLS_AVX2 + +#ifdef HAS_SCALEARGBCOLSUP2_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleARGBColsUp2_AVX2(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx) { + (void)x; + (void)dx; + while (dst_width > 0) { + __m256i s = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)src_argb)), + 0xd8); + src_argb += 16; + _mm256_storeu_si256((__m256i*)dst_argb, _mm256_unpacklo_epi32(s, s)); + dst_argb += 32; + dst_width -= 8; + } +} +#endif // HAS_SCALEARGBCOLSUP2_AVX2 + +#ifdef HAS_SCALEARGBFILTERCOLS_AVX2 +static const int32_t kStep0_3_ARGB[4] = {0, 1, 2, 3}; +static const uvec8 kShuffleColARGB = { + 0u, 4u, 1u, 5u, 2u, 6u, 3u, 7u, + 8u, 12u, 9u, 13u, 10u, 14u, 11u, 15u}; +static const uint8_t kShuffleFractionsAVX2[32] = { + 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, + 8u, 8u, 8u, 8u, 8u, 8u, 8u, 8u, 12u, 12u, 12u, 12u, 12u, 12u, 12u, 12u, +}; + +LIBYUV_TARGET_AVX2 +void ScaleARGBFilterCols_AVX2(uint8_t* dst_argb, + const uint8_t* src_argb, + int dst_width, + int x, + int dx) { + int n = dst_width & ~3; + int r = dst_width & 3; + if (n > 0) { + SIMD_ALIGNED(int32_t xi_buf[4]); + SIMD_ALIGNED(uint64_t pix_buf[4]); + const __m256i shuf_argb = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)&kShuffleColARGB)); + const __m256i shuf_frac = + _mm256_loadu_si256((const __m256i*)kShuffleFractionsAVX2); + const __m256i mask_7f = _mm256_set1_epi16(0x007f); + __m128i vx = _mm_add_epi32( + _mm_set1_epi32(x), + _mm_mullo_epi32(_mm_set1_epi32(dx), + _mm_loadu_si128((const __m128i*)kStep0_3_ARGB))); + const __m128i vdx4 = _mm_slli_epi32(_mm_set1_epi32(dx), 2); + for (int i = 0; i < n; i += 4) { + _mm_store_si128((__m128i*)xi_buf, _mm_srai_epi32(vx, 16)); + __m128i f128 = _mm_srli_epi16(vx, 9); + vx = _mm_add_epi32(vx, vdx4); + pix_buf[0] = LoadU64(src_argb + (ptrdiff_t)xi_buf[0] * 4); + pix_buf[1] = LoadU64(src_argb + (ptrdiff_t)xi_buf[1] * 4); + pix_buf[2] = LoadU64(src_argb + (ptrdiff_t)xi_buf[2] * 4); + pix_buf[3] = LoadU64(src_argb + (ptrdiff_t)xi_buf[3] * 4); + __m256i pix = _mm256_shuffle_epi8( + _mm256_load_si256((const __m256i*)pix_buf), shuf_argb); + __m256i weights = _mm256_xor_si256( + _mm256_shuffle_epi8( + _mm256_inserti128_si256(_mm256_zextsi128_si256(f128), f128, 1), + shuf_frac), + mask_7f); + __m256i res = _mm256_srli_epi16(_mm256_maddubs_epi16(pix, weights), 7); + res = _mm256_permute4x64_epi64(_mm256_packus_epi16(res, res), 0xd8); + _mm_storeu_si128((__m128i*)dst_argb, _mm256_castsi256_si128(res)); + dst_argb += 16; + } + x = (int)((uint32_t)x + (uint32_t)n * (uint32_t)dx); + } + for (int j = 0; j < r; ++j) { + ptrdiff_t xi = (ptrdiff_t)(x >> 16) * 4; + int xf = (x >> 9) & 0x7f; + const uint8_t* a = src_argb + xi; + const uint8_t* b = a + 4; + dst_argb[0] = (uint8_t)((a[0] * (0x7f ^ xf) + b[0] * xf) >> 7); + dst_argb[1] = (uint8_t)((a[1] * (0x7f ^ xf) + b[1] * xf) >> 7); + dst_argb[2] = (uint8_t)((a[2] * (0x7f ^ xf) + b[2] * xf) >> 7); + dst_argb[3] = (uint8_t)((a[3] * (0x7f ^ xf) + b[3] * xf) >> 7); + dst_argb += 4; + x = (int)((uint32_t)x + (uint32_t)dx); + } +} +#endif // HAS_SCALEARGBFILTERCOLS_AVX2 + +#ifdef HAS_SCALEUVROWDOWN2_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleUVRowDown2_AVX2(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + (void)src_stride; + while (dst_width >= 16) { + __m256i s0 = + _mm256_srli_epi32(_mm256_loadu_si256((const __m256i*)src_uv), 16); + __m256i s1 = _mm256_srli_epi32( + _mm256_loadu_si256((const __m256i*)(src_uv + 32)), 16); + src_uv += 64; + __m256i d = _mm256_permute4x64_epi64(_mm256_packus_epi32(s0, s1), 0xd8); + _mm256_storeu_si256((__m256i*)dst_uv, d); + dst_uv += 32; + dst_width -= 16; + } + if (dst_width > 0) { + __m256i s0 = + _mm256_srli_epi32(_mm256_loadu_si256((const __m256i*)src_uv), 16); + __m256i d = _mm256_permute4x64_epi64(_mm256_packus_epi32(s0, s0), 0xd8); + _mm_storeu_si128((__m128i*)dst_uv, _mm256_castsi256_si128(d)); + } +} +#endif // HAS_SCALEUVROWDOWN2_AVX2 + +#ifdef HAS_SCALEUVROWDOWN2LINEAR_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleUVRowDown2Linear_AVX2(const uint8_t* src_uv, + ptrdiff_t src_stride, + uint8_t* dst_uv, + int dst_width) { + (void)src_stride; + const __m256i mask = _mm256_set1_epi32(0x0000ffff); + while (dst_width >= 16) { + __m256i r0 = _mm256_loadu_si256((const __m256i*)src_uv); + __m256i r1 = _mm256_loadu_si256((const __m256i*)(src_uv + 32)); + src_uv += 64; + __m256i s0 = + _mm256_and_si256(_mm256_avg_epu8(r0, _mm256_srli_epi32(r0, 16)), mask); + __m256i s1 = + _mm256_and_si256(_mm256_avg_epu8(r1, _mm256_srli_epi32(r1, 16)), mask); + __m256i d = _mm256_permute4x64_epi64(_mm256_packus_epi32(s0, s1), 0xd8); + _mm256_storeu_si256((__m256i*)dst_uv, d); + dst_uv += 32; + dst_width -= 16; + } + if (dst_width > 0) { + __m256i r0 = _mm256_loadu_si256((const __m256i*)src_uv); + __m256i s0 = + _mm256_and_si256(_mm256_avg_epu8(r0, _mm256_srli_epi32(r0, 16)), mask); + __m256i d = _mm256_permute4x64_epi64(_mm256_packus_epi32(s0, s0), 0xd8); + _mm_storeu_si128((__m128i*)dst_uv, _mm256_castsi256_si128(d)); + } +} +#endif // HAS_SCALEUVROWDOWN2LINEAR_AVX2 + +#ifdef HAS_SCALEUVROWDOWN2BOX_AVX2 +static const uvec8 kShuffleSplitUV = {0u, 2u, 4u, 6u, 8u, 10u, 12u, 14u, + 1u, 3u, 5u, 7u, 9u, 11u, 13u, 15u}; +static const uvec8 kShuffleMergeUV = {0u, 8u, 2u, 10u, 4u, 12u, + 6u, 14u, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80}; + +LIBYUV_TARGET_AVX2 +void ScaleUVRowDown2Box_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + int dst_width) { + const __m256i split = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)&kShuffleSplitUV)); + const __m256i merge = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)&kShuffleMergeUV)); + const __m256i ones = _mm256_set1_epi8(1); + const __m256i zero = _mm256_setzero_si256(); + while (dst_width > 0) { + __m256i r0 = _mm256_maddubs_epi16( + _mm256_shuffle_epi8(_mm256_loadu_si256((const __m256i*)src_ptr), split), + ones); + __m256i r1 = _mm256_maddubs_epi16( + _mm256_shuffle_epi8( + _mm256_loadu_si256((const __m256i*)(src_ptr + src_stride)), split), + ones); + src_ptr += 32; + __m256i s = + _mm256_avg_epu16(_mm256_srli_epi16(_mm256_add_epi16(r0, r1), 1), zero); + __m256i d = _mm256_permute4x64_epi64(_mm256_shuffle_epi8(s, merge), 0xd8); + _mm_storeu_si128((__m128i*)dst_ptr, _mm256_castsi256_si128(d)); + dst_ptr += 16; + dst_width -= 8; + } +} +#endif // HAS_SCALEUVROWDOWN2BOX_AVX2 + +#ifdef HAS_SCALEUVROWDOWNEVEN_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleUVRowDownEven_AVX2(const uint8_t* src_uv, + ptrdiff_t src_stride, + int src_stepx, + uint8_t* dst_uv, + int dst_width) { + (void)src_stride; + const ptrdiff_t step = (ptrdiff_t)src_stepx * 2; + SIMD_ALIGNED(uint16_t uv_buf[8]); + while (dst_width > 0) { + uv_buf[0] = LoadU16(src_uv); + uv_buf[1] = LoadU16(src_uv + step); + uv_buf[2] = LoadU16(src_uv + step * 2); + uv_buf[3] = LoadU16(src_uv + step * 3); + uv_buf[4] = LoadU16(src_uv + step * 4); + uv_buf[5] = LoadU16(src_uv + step * 5); + uv_buf[6] = LoadU16(src_uv + step * 6); + uv_buf[7] = LoadU16(src_uv + step * 7); + src_uv += step * 8; + _mm_storeu_si128((__m128i*)dst_uv, _mm_load_si128((const __m128i*)uv_buf)); + dst_uv += 16; + dst_width -= 8; + } +} +#endif // HAS_SCALEUVROWDOWNEVEN_AVX2 + +#if defined(HAS_SCALEUVROWUP2_LINEAR_AVX2) || \ + defined(HAS_SCALEUVROWUP2_BILINEAR_AVX2) +static const uvec8 kUVLinearMadd31 = {3, 1, 3, 1, 1, 3, 1, 3, + 3, 1, 3, 1, 1, 3, 1, 3}; +#endif + +#ifdef HAS_SCALEUVROWUP2_LINEAR_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleUVRowUp2_Linear_AVX2(const uint8_t* src_ptr, + uint8_t* dst_ptr, + int dst_width) { + const __m256i madd31 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)&kUVLinearMadd31)); + const __m256i round2 = _mm256_set1_epi16(2); + while (dst_width > 0) { + __m256i s0 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)src_ptr)), 0xd8); + __m256i s1 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)(src_ptr + 2))), + 0xd8); + src_ptr += 16; + __m256i p = _mm256_unpacklo_epi8(s0, s1); + __m256i lo = _mm256_maddubs_epi16(_mm256_unpacklo_epi32(p, p), madd31); + __m256i hi = _mm256_maddubs_epi16(_mm256_unpackhi_epi32(p, p), madd31); + lo = _mm256_srli_epi16(_mm256_add_epi16(lo, round2), 2); + hi = _mm256_srli_epi16(_mm256_add_epi16(hi, round2), 2); + _mm256_storeu_si256((__m256i*)dst_ptr, _mm256_packus_epi16(lo, hi)); + dst_ptr += 32; + dst_width -= 16; + } +} +#endif // HAS_SCALEUVROWUP2_LINEAR_AVX2 + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleUVRowUp2_Bilinear_AVX2(const uint8_t* src_ptr, + ptrdiff_t src_stride, + uint8_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const __m256i madd31 = _mm256_broadcastsi128_si256( + _mm_loadu_si128((const __m128i*)&kUVLinearMadd31)); + const __m256i round8 = _mm256_set1_epi16(8); + while (dst_width > 0) { + __m256i a0 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)src_ptr)), 0xd8); + __m256i a1 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256(_mm_loadu_si128((const __m128i*)(src_ptr + 2))), + 0xd8); + __m256i pa = _mm256_unpacklo_epi8(a0, a1); + __m256i r0_lo = _mm256_maddubs_epi16(_mm256_unpacklo_epi32(pa, pa), madd31); + __m256i r0_hi = _mm256_maddubs_epi16(_mm256_unpackhi_epi32(pa, pa), madd31); + + __m256i b0 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256( + _mm_loadu_si128((const __m128i*)(src_ptr + src_stride))), + 0xd8); + __m256i b1 = _mm256_permute4x64_epi64( + _mm256_zextsi128_si256( + _mm_loadu_si128((const __m128i*)(src_ptr + src_stride + 2))), + 0xd8); + src_ptr += 16; + __m256i pb = _mm256_unpacklo_epi8(b0, b1); + __m256i r1_lo = _mm256_maddubs_epi16(_mm256_unpacklo_epi32(pb, pb), madd31); + __m256i r1_hi = _mm256_maddubs_epi16(_mm256_unpackhi_epi32(pb, pb), madd31); + + __m256i d0_lo = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(r0_lo, r0_lo), r0_lo), + _mm256_add_epi16(r1_lo, round8)), + 4); + __m256i d1_lo = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(r1_lo, r1_lo), r1_lo), + _mm256_add_epi16(r0_lo, round8)), + 4); + __m256i d0_hi = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(r0_hi, r0_hi), r0_hi), + _mm256_add_epi16(r1_hi, round8)), + 4); + __m256i d1_hi = _mm256_srli_epi16( + _mm256_add_epi16(_mm256_add_epi16(_mm256_add_epi16(r1_hi, r1_hi), r1_hi), + _mm256_add_epi16(r0_hi, round8)), + 4); + + _mm256_storeu_si256((__m256i*)dst_ptr, _mm256_packus_epi16(d0_lo, d0_hi)); + _mm256_storeu_si256((__m256i*)(dst_ptr + dst_stride), + _mm256_packus_epi16(d1_lo, d1_hi)); + dst_ptr += 32; + dst_width -= 16; + } +} +#endif // HAS_SCALEUVROWUP2_BILINEAR_AVX2 + +#ifdef HAS_SCALEUVROWUP2_LINEAR_16_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleUVRowUp2_Linear_16_AVX2(const uint16_t* src_ptr, + uint16_t* dst_ptr, + int dst_width) { + const __m256i round2 = _mm256_set1_epi32(2); + while (dst_width > 0) { + __m256i near_lo = + _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)src_ptr)); + __m256i near_hi = + _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)(src_ptr + 2))); + src_ptr += 8; + __m256i far_lo = _mm256_shuffle_epi32(near_lo, 0x4e); + __m256i far_hi = _mm256_shuffle_epi32(near_hi, 0x4e); + __m256i d_lo = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(near_lo, near_lo), + _mm256_add_epi32(near_lo, _mm256_add_epi32(far_lo, round2))), + 2); + __m256i d_hi = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(near_hi, near_hi), + _mm256_add_epi32(near_hi, _mm256_add_epi32(far_hi, round2))), + 2); + _mm256_storeu_si256((__m256i*)dst_ptr, _mm256_packus_epi32(d_lo, d_hi)); + dst_ptr += 16; + dst_width -= 8; + } +} +#endif // HAS_SCALEUVROWUP2_LINEAR_16_AVX2 + +#ifdef HAS_SCALEUVROWUP2_BILINEAR_16_AVX2 +LIBYUV_TARGET_AVX2 +void ScaleUVRowUp2_Bilinear_16_AVX2(const uint16_t* src_ptr, + ptrdiff_t src_stride, + uint16_t* dst_ptr, + ptrdiff_t dst_stride, + int dst_width) { + const __m256i round8 = _mm256_set1_epi32(8); + while (dst_width > 0) { + __m256i a0 = + _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)src_ptr)); + __m256i a1 = + _mm256_cvtepu16_epi32(_mm_loadu_si128((const __m128i*)(src_ptr + 2))); + __m256i r0_lo = _mm256_add_epi32( + _mm256_add_epi32(a0, a0), + _mm256_add_epi32(a0, _mm256_shuffle_epi32(a0, 0x4e))); + __m256i r0_hi = _mm256_add_epi32( + _mm256_add_epi32(a1, a1), + _mm256_add_epi32(a1, _mm256_shuffle_epi32(a1, 0x4e))); + + __m256i b0 = _mm256_cvtepu16_epi32( + _mm_loadu_si128((const __m128i*)(src_ptr + src_stride))); + __m256i b1 = _mm256_cvtepu16_epi32( + _mm_loadu_si128((const __m128i*)(src_ptr + src_stride + 2))); + src_ptr += 8; + __m256i r1_lo = _mm256_add_epi32( + _mm256_add_epi32(b0, b0), + _mm256_add_epi32(b0, _mm256_shuffle_epi32(b0, 0x4e))); + __m256i r1_hi = _mm256_add_epi32( + _mm256_add_epi32(b1, b1), + _mm256_add_epi32(b1, _mm256_shuffle_epi32(b1, 0x4e))); + + __m256i d0_lo = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(r0_lo, r0_lo), r0_lo), + _mm256_add_epi32(r1_lo, round8)), + 4); + __m256i d1_lo = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(r1_lo, r1_lo), r1_lo), + _mm256_add_epi32(r0_lo, round8)), + 4); + __m256i d0_hi = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(r0_hi, r0_hi), r0_hi), + _mm256_add_epi32(r1_hi, round8)), + 4); + __m256i d1_hi = _mm256_srli_epi32( + _mm256_add_epi32(_mm256_add_epi32(_mm256_add_epi32(r1_hi, r1_hi), r1_hi), + _mm256_add_epi32(r0_hi, round8)), + 4); + + _mm256_storeu_si256((__m256i*)dst_ptr, _mm256_packus_epi32(d0_lo, d0_hi)); + _mm256_storeu_si256((__m256i*)(dst_ptr + dst_stride), + _mm256_packus_epi32(d1_lo, d1_hi)); + dst_ptr += 16; + dst_width -= 8; + } +} +#endif // HAS_SCALEUVROWUP2_BILINEAR_16_AVX2 + +#undef LIBYUV_TARGET_AVX2 +#undef LIBYUV_TARGET_AVX512BW +#undef LIBYUV_TARGET_AVX512VBMI + +#endif // !defined(LIBYUV_DISABLE_X86) && ... #ifdef __cplusplus } // extern "C" diff --git a/libs/libyuv/source/test.sh b/libs/libyuv/source/test.sh new file mode 100755 index 0000000000..7f12c3c156 --- /dev/null +++ b/libs/libyuv/source/test.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -x + +function runbenchmark1 { + perf record /google/src/cloud/fbarchard/clean/google3/blaze-bin/third_party/libyuv/libyuv_test --gunit_filter=*$1 --libyuv_width=1280 --libyuv_height=720 --libyuv_repeat=1000 --libyuv_flags=-1 --libyuv_cpu_info=-1 + perf report | grep AVX +} + +runbenchmark1 ABGRToI420 +runbenchmark1 Android420ToI420 +runbenchmark1 ARGBToI420 +runbenchmark1 Convert16To8Plane +runbenchmark1 ConvertToARGB +runbenchmark1 ConvertToI420 +runbenchmark1 CopyPlane +runbenchmark1 H010ToAB30 +runbenchmark1 H010ToAR30 +runbenchmark1 HalfFloatPlane +runbenchmark1 I010ToAB30 +runbenchmark1 I010ToAR30 +runbenchmark1 I420Copy +runbenchmark1 I420Psnr +runbenchmark1 I420Scale +runbenchmark1 I420Ssim +runbenchmark1 I420ToARGB +runbenchmark1 I420ToNV12 +runbenchmark1 I420ToUYVY +runbenchmark1 I422ToI420 +runbenchmark1 InitCpuFlags +runbenchmark1 J420ToARGB +runbenchmark1 NV12ToARGB +runbenchmark1 NV12ToI420 +runbenchmark1 NV12ToI420Rotate +runbenchmark1 SetCpuFlags +runbenchmark1 YUY2ToI420 diff --git a/libs/libyuv/tools_libyuv/OWNERS b/libs/libyuv/tools_libyuv/OWNERS index 2cb971d2b7..aae4fb6e02 100644 --- a/libs/libyuv/tools_libyuv/OWNERS +++ b/libs/libyuv/tools_libyuv/OWNERS @@ -1 +1,4 @@ -phoglund@chromium.org +mbonadei@chromium.org +fbarchard@chromium.org +pbos@chromium.org + diff --git a/libs/libyuv/tools_libyuv/autoroller/roll_deps.py b/libs/libyuv/tools_libyuv/autoroller/roll_deps.py index 2b95e302cd..472cbe6cbe 100755 --- a/libs/libyuv/tools_libyuv/autoroller/roll_deps.py +++ b/libs/libyuv/tools_libyuv/autoroller/roll_deps.py @@ -1,18 +1,14 @@ -#!/usr/bin/env python -# Copyright 2017 The LibYuv Project Authors. All rights reserved. +#!/usr/bin/env vpython3 + +# Copyright (c) 2017 The LibYUV project authors. All Rights Reserved. # # Use of this source code is governed by a BSD-style license # that can be found in the LICENSE file in the root of the source # tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may +# in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. +"""Script to automatically roll dependencies in the LibYUV DEPS file.""" -# This is a modified copy of the script in -# https://webrtc.googlesource.com/src/+/master/tools_webrtc/autoroller/roll_deps.py -# customized for libyuv. - - -"""Script to automatically roll dependencies in the libyuv DEPS file.""" import argparse import base64 @@ -22,12 +18,54 @@ import os import re import subprocess import sys -import urllib2 +import urllib.request + +def FindRootPath(): + """Returns the absolute path to the highest level repo root. + + If this repo is checked out as a submodule of the chromium/src + superproject, this returns the superproect root. Otherwise, it returns the + webrtc/src repo root. + """ + root_dir = os.path.dirname(os.path.abspath(__file__)) + while os.path.basename(root_dir) not in ('src', 'chromium'): + par_dir = os.path.normpath(os.path.join(root_dir, os.pardir)) + if par_dir == root_dir: + raise RuntimeError('Could not find the repo root.') + root_dir = par_dir + return root_dir # Skip these dependencies (list without solution name prefix). DONT_AUTOROLL_THESE = [ - 'src/third_party/gflags/src', + 'third_party/fuchsia-gn-sdk', + 'src/third_party/gflags/src', + 'src/third_party/mockito/src', +] + +# These dependencies are missing in chromium/src/DEPS, either unused or already +# in-tree. For instance, src/base is a part of the Chromium source git repo, +# but we pull it through a subtree mirror, so therefore it isn't listed in +# Chromium's deps but it is in ours. +LIBYUV_ONLY_DEPS = [ + 'src/build', + 'src/buildtools', + 'src/ios', + 'src/testing', + 'src/third_party', + 'src/third_party/android_support_test_runner', + 'src/third_party/errorprone/lib', + 'src/third_party/findbugs', + 'src/third_party/gson', + 'src/third_party/gtest-parallel', + 'src/third_party/guava', + 'src/third_party/intellij', + 'src/third_party/jsr-305/src', + 'src/third_party/ow2_asm', + 'src/third_party/proguard', + 'src/third_party/ub-uiautomator/lib', + 'src/tools', + 'src/tools/clang/dsymutil', ] LIBYUV_URL = 'https://chromium.googlesource.com/libyuv/libyuv' @@ -37,199 +75,381 @@ CHROMIUM_LOG_TEMPLATE = CHROMIUM_SRC_URL + '/+log/%s' CHROMIUM_FILE_TEMPLATE = CHROMIUM_SRC_URL + '/+/%s/%s' COMMIT_POSITION_RE = re.compile('^Cr-Commit-Position: .*#([0-9]+).*$') -CLANG_REVISION_RE = re.compile(r'^CLANG_REVISION = \'([0-9a-z]+)\'$') +CLANG_REVISION_RE = re.compile(r'^CLANG_REVISION = \'([-0-9a-z]+)\'$') ROLL_BRANCH_NAME = 'roll_chromium_revision' SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) -CHECKOUT_SRC_DIR = os.path.realpath(os.path.join(SCRIPT_DIR, os.pardir, - os.pardir)) -CHECKOUT_ROOT_DIR = os.path.realpath(os.path.join(CHECKOUT_SRC_DIR, os.pardir)) +CHECKOUT_ROOT_DIR = FindRootPath() +GCLIENT_ROOT_DIR = os.path.realpath(os.path.join(CHECKOUT_ROOT_DIR, os.pardir)) + +# Copied from tools/android/roll/android_deps/.../BuildConfigGenerator.groovy. +ANDROID_DEPS_START = r'=== ANDROID_DEPS Generated Code Start ===' +ANDROID_DEPS_END = r'=== ANDROID_DEPS Generated Code End ===' +# Location of automically gathered android deps. +ANDROID_DEPS_PATH = 'src/third_party/android_deps/' + +sys.path.append(os.path.join(CHECKOUT_ROOT_DIR, 'build')) +import find_depot_tools # pylint: disable=wrong-import-position -sys.path.append(os.path.join(CHECKOUT_SRC_DIR, 'build')) -import find_depot_tools find_depot_tools.add_depot_tools_to_path() CLANG_UPDATE_SCRIPT_URL_PATH = 'tools/clang/scripts/update.py' -CLANG_UPDATE_SCRIPT_LOCAL_PATH = os.path.join(CHECKOUT_SRC_DIR, 'tools', - 'clang', 'scripts', 'update.py') +CLANG_UPDATE_SCRIPT_LOCAL_PATH = os.path.join( + CHECKOUT_ROOT_DIR, 'tools', 'clang', 'scripts', 'update.py' +) DepsEntry = collections.namedtuple('DepsEntry', 'path url revision') -ChangedDep = collections.namedtuple('ChangedDep', - 'path url current_rev new_rev') +ChangedDep = collections.namedtuple( + 'ChangedDep', 'path url current_rev new_rev' +) +CipdDepsEntry = collections.namedtuple('CipdDepsEntry', 'path packages') +GcsDepsEntry = collections.namedtuple('GcsDepsEntry', 'path bucket objects') +VersionEntry = collections.namedtuple('VersionEntry', 'version') +ChangedCipdPackage = collections.namedtuple( + 'ChangedCipdPackage', 'path package current_version new_version' +) +ChangedVersionEntry = collections.namedtuple( + 'ChangedVersionEntry', 'path current_version new_version' +) + +ChromiumRevisionUpdate = collections.namedtuple( + 'ChromiumRevisionUpdate', 'current_chromium_rev new_chromium_rev ' +) + class RollError(Exception): - pass + pass + + +def StrExpansion(): + return lambda str_value: str_value def VarLookup(local_scope): - return lambda var_name: local_scope['vars'][var_name] + return lambda var_name: local_scope['vars'][var_name] def ParseDepsDict(deps_content): - local_scope = {} - global_scope = { - 'Var': VarLookup(local_scope), - 'deps_os': {}, - } - exec(deps_content, global_scope, local_scope) - return local_scope + local_scope = {} + global_scope = { + 'Str': StrExpansion(), + 'Var': VarLookup(local_scope), + 'deps_os': {}, + } + exec(deps_content, global_scope, local_scope) + return local_scope def ParseLocalDepsFile(filename): - with open(filename, 'rb') as f: - deps_content = f.read() - return ParseDepsDict(deps_content) - - -def ParseRemoteCrDepsFile(revision): - deps_content = ReadRemoteCrFile('DEPS', revision) - return ParseDepsDict(deps_content) + with open(filename, 'rb') as f: + deps_content = f.read().decode('utf-8') + return ParseDepsDict(deps_content) def ParseCommitPosition(commit_message): - for line in reversed(commit_message.splitlines()): - m = COMMIT_POSITION_RE.match(line.strip()) - if m: - return int(m.group(1)) - logging.error('Failed to parse commit position id from:\n%s\n', - commit_message) - sys.exit(-1) + for line in reversed(commit_message.splitlines()): + m = COMMIT_POSITION_RE.match(line.strip()) + if m: + return int(m.group(1)) + logging.error( + 'Failed to parse commit position id from:\n%s\n', commit_message + ) + sys.exit(-1) -def _RunCommand(command, working_dir=None, ignore_exit_code=False, - extra_env=None): - """Runs a command and returns the output from that command. +def _RunCommand( + command, + working_dir=None, + ignore_exit_code=False, + extra_env=None, + input_data=None, +): + """Runs a command and returns the output from that command. - If the command fails (exit code != 0), the function will exit the process. + If the command fails (exit code != 0), the function will exit the process. - Returns: - A tuple containing the stdout and stderr outputs as strings. - """ - working_dir = working_dir or CHECKOUT_SRC_DIR - logging.debug('CMD: %s CWD: %s', ' '.join(command), working_dir) - env = os.environ.copy() - if extra_env: - assert all(isinstance(value, str) for value in extra_env.values()) - logging.debug('extra env: %s', extra_env) - env.update(extra_env) - p = subprocess.Popen(command, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, env=env, - cwd=working_dir, universal_newlines=True) - std_output = p.stdout.read() - err_output = p.stderr.read() - p.wait() - p.stdout.close() - p.stderr.close() - if not ignore_exit_code and p.returncode != 0: - logging.error('Command failed: %s\n' - 'stdout:\n%s\n' - 'stderr:\n%s\n', ' '.join(command), std_output, err_output) - sys.exit(p.returncode) - return std_output, err_output + Returns: + A tuple containing the stdout and stderr outputs as strings. + """ + working_dir = working_dir or CHECKOUT_ROOT_DIR + logging.debug('CMD: %s CWD: %s', ' '.join(command), working_dir) + env = os.environ.copy() + if extra_env: + assert all(isinstance(value, str) for value in extra_env.values()) + logging.debug('extra env: %s', extra_env) + env.update(extra_env) + p = subprocess.Popen( + command, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env, + cwd=working_dir, + universal_newlines=True, + ) + std_output, err_output = p.communicate(input_data) + p.stdout.close() + p.stderr.close() + if not ignore_exit_code and p.returncode != 0: + logging.error( + 'Command failed: %s\nstdout:\n%s\nstderr:\n%s\n', + ' '.join(command), + std_output, + err_output, + ) + sys.exit(p.returncode) + return std_output, err_output def _GetBranches(): - """Returns a tuple of active,branches. + """Returns a tuple of active,branches. - The 'active' is the name of the currently active branch and 'branches' is a - list of all branches. - """ - lines = _RunCommand(['git', 'branch'])[0].split('\n') - branches = [] - active = '' - for line in lines: - if '*' in line: - # The assumption is that the first char will always be the '*'. - active = line[1:].strip() - branches.append(active) - else: - branch = line.strip() - if branch: - branches.append(branch) - return active, branches + The 'active' is the name of the currently active branch and 'branches' is a + list of all branches. + """ + lines = _RunCommand(['git', 'branch'])[0].split('\n') + branches = [] + active = '' + for line in lines: + if '*' in line: + # The assumption is that the first char will always be the '*'. + active = line[1:].strip() + branches.append(active) + else: + branch = line.strip() + if branch: + branches.append(branch) + return active, branches def _ReadGitilesContent(url): - # Download and decode BASE64 content until - # https://code.google.com/p/gitiles/issues/detail?id=7 is fixed. - base64_content = ReadUrlContent(url + '?format=TEXT') - return base64.b64decode(base64_content[0]) + # Download and decode BASE64 content until + # https://code.google.com/p/gitiles/issues/detail?id=7 is fixed. + base64_content = ReadUrlContent(url + '?format=TEXT') + return base64.b64decode(base64_content[0]).decode('utf-8') def ReadRemoteCrFile(path_below_src, revision): - """Reads a remote Chromium file of a specific revision. Returns a string.""" - return _ReadGitilesContent(CHROMIUM_FILE_TEMPLATE % (revision, - path_below_src)) + """Reads a remote Chromium file of a specific revision. + + Args: + path_below_src: A path to the target file relative to src dir. + revision: Revision to read. + + Returns: + A string with file content. + """ + return _ReadGitilesContent( + CHROMIUM_FILE_TEMPLATE % (revision, path_below_src) + ) def ReadRemoteCrCommit(revision): - """Reads a remote Chromium commit message. Returns a string.""" - return _ReadGitilesContent(CHROMIUM_COMMIT_TEMPLATE % revision) + """Reads a remote Chromium commit message. Returns a string.""" + return _ReadGitilesContent(CHROMIUM_COMMIT_TEMPLATE % revision) def ReadUrlContent(url): - """Connect to a remote host and read the contents. Returns a list of lines.""" - conn = urllib2.urlopen(url) - try: - return conn.readlines() - except IOError as e: - logging.exception('Error connecting to %s. Error: %s', url, e) - raise - finally: - conn.close() + """Connect to a remote host and read the contents. + + Args: + url: URL to connect to. + + Returns: + A list of lines. + """ + conn = urllib.request.urlopen(url) + try: + return conn.readlines() + except IOError as e: + logging.exception('Error connecting to %s. Error: %s', url, e) + raise + finally: + conn.close() def GetMatchingDepsEntries(depsentry_dict, dir_path): - """Gets all deps entries matching the provided path. + """Gets all deps entries matching the provided path. - This list may contain more than one DepsEntry object. - Example: dir_path='src/testing' would give results containing both - 'src/testing/gtest' and 'src/testing/gmock' deps entries for Chromium's DEPS. - Example 2: dir_path='src/build' should return 'src/build' but not - 'src/buildtools'. + This list may contain more than one DepsEntry object. + Example: dir_path='src/testing' would give results containing both + 'src/testing/gtest' and 'src/testing/gmock' deps entries for Chromium's + DEPS. + Example 2: dir_path='src/build' should return 'src/build' but not + 'src/buildtools'. - Returns: - A list of DepsEntry objects. - """ - result = [] - for path, depsentry in depsentry_dict.iteritems(): - if path == dir_path: - result.append(depsentry) - else: - parts = path.split('/') - if all(part == parts[i] - for i, part in enumerate(dir_path.split('/'))): - result.append(depsentry) - return result + Returns: + A list of DepsEntry objects. + """ + result = [] + for path, depsentry in depsentry_dict.items(): + if path == dir_path: + result.append(depsentry) + else: + parts = path.split('/') + if all( + part == parts[i] for i, part in enumerate(dir_path.split('/')) + ): + result.append(depsentry) + return result def BuildDepsentryDict(deps_dict): - """Builds a dict of paths to DepsEntry objects from a raw parsed deps dict.""" - result = {} - def AddDepsEntries(deps_subdict): - for path, deps_url_spec in deps_subdict.iteritems(): - # The deps url is either an URL and a condition, or just the URL. - if isinstance(deps_url_spec, dict): - if deps_url_spec.get('dep_type') == 'cipd': - continue - deps_url = deps_url_spec['url'] - else: - deps_url = deps_url_spec + """Builds a dict of paths to DepsEntry objects from a raw deps dict.""" + result = {} - if not result.has_key(path): - url, revision = deps_url.split('@') if deps_url else (None, None) - result[path] = DepsEntry(path, url, revision) + def AddDepsEntries(deps_subdict): + for path, dep in deps_subdict.items(): + if path in result: + continue + if not isinstance(dep, dict): + dep = {'url': dep} + if dep.get('dep_type') == 'cipd': + result[path] = CipdDepsEntry(path, dep['packages']) + elif dep.get('dep_type') == 'gcs': + result[path] = GcsDepsEntry(path, dep['bucket'], + dep['objects']) + else: + if '@' not in dep['url']: + url, revision = dep['url'], 'HEAD' + else: + url, revision = dep['url'].split('@') + result[path] = DepsEntry(path, url, revision) - AddDepsEntries(deps_dict['deps']) - for deps_os in ['win', 'mac', 'unix', 'android', 'ios', 'unix']: - AddDepsEntries(deps_dict.get('deps_os', {}).get(deps_os, {})) - return result + def AddVersionEntry(vars_subdict): + for key, value in vars_subdict.items(): + if key in result: + continue + if not key.endswith('_version'): + continue + key = re.sub('_version$', '', key) + result[key] = VersionEntry(value) + + AddDepsEntries(deps_dict['deps']) + for deps_os in ['win', 'mac', 'unix', 'android', 'ios', 'unix']: + AddDepsEntries(deps_dict.get('deps_os', {}).get(deps_os, {})) + AddVersionEntry(deps_dict.get('vars', {})) + return result + + +def _FindChangedCipdPackages(path, old_pkgs, new_pkgs): + old_pkgs_names = {p['package'] for p in old_pkgs} + new_pkgs_names = {p['package'] for p in new_pkgs} + pkgs_equal = old_pkgs_names == new_pkgs_names + added_pkgs = [p for p in new_pkgs_names if p not in old_pkgs_names] + removed_pkgs = [p for p in old_pkgs_names if p not in new_pkgs_names] + + assert pkgs_equal, ( + 'Old: %s\n New: %s.\nYou need to do a manual roll ' + 'and remove/add entries in DEPS so the old and new ' + 'list match.\nMost likely, you should add "%s" and ' + 'remove "%s"' % (old_pkgs, new_pkgs, added_pkgs, removed_pkgs) + ) + + for old_pkg in old_pkgs: + for new_pkg in new_pkgs: + old_version = old_pkg['version'] + new_version = new_pkg['version'] + if ( + old_pkg['package'] == new_pkg['package'] + and old_version != new_version + ): + logging.debug('Roll dependency %s to %s', path, new_version) + yield ChangedCipdPackage( + path, old_pkg['package'], old_version, new_version + ) + + +def _FindChangedVars(name, old_version, new_version): + if old_version != new_version: + logging.debug('Roll dependency %s to %s', name, new_version) + yield ChangedVersionEntry(name, old_version, new_version) + + +def _FindNewDeps(old, new): + """Gather dependencies only in `new` and return corresponding paths.""" + old_entries = set(BuildDepsentryDict(old)) + new_entries = set(BuildDepsentryDict(new)) + return [ + path + for path in new_entries - old_entries + if path not in DONT_AUTOROLL_THESE + ] + + +def FindAddedDeps(libyuv_deps, new_cr_deps): + """Calculate new deps entries of interest. + + Ideally, that would mean: only appearing in chromium DEPS + but transitively used in LibYUV. + + Since it's hard to compute, we restrict ourselves to a well defined subset: + deps sitting in `ANDROID_DEPS_PATH`. + Otherwise, assumes that's a Chromium-only dependency. + + Args: + libyuv_deps: dict of deps as defined in the LibYUV DEPS file. + new_cr_deps: dict of deps as defined in the chromium DEPS file. + + Caveat: Doesn't detect a new package in existing dep. + + Returns: + A tuple consisting of: + A list of paths added dependencies sitting in `ANDROID_DEPS_PATH`. + A list of paths for other added dependencies. + """ + all_added_deps = _FindNewDeps(libyuv_deps, new_cr_deps) + generated_android_deps = [ + path for path in all_added_deps if path.startswith(ANDROID_DEPS_PATH) + ] + other_deps = [ + path for path in all_added_deps if path not in generated_android_deps + ] + return generated_android_deps, other_deps + + +def FindRemovedDeps(libyuv_deps, new_cr_deps): + """Calculate obsolete deps entries. + + Ideally, that would mean: no more appearing in chromium DEPS + and not used in LibYUV. + + Since it's hard to compute: + 1/ We restrict ourselves to a well defined subset: + deps sitting in `ANDROID_DEPS_PATH`. + 2/ We rely on existing behavior of CalculateChangeDeps. + I.e. Assumes non-CIPD dependencies are LibYUV-only, don't remove them. + + Args: + libyuv_deps: dict of deps as defined in the LibYUV DEPS file. + new_cr_deps: dict of deps as defined in the chromium DEPS file. + + Caveat: Doesn't detect a deleted package in existing dep. + + Returns: + A tuple consisting of: + A list of paths of dependencies removed from `ANDROID_DEPS_PATH`. + A list of paths of unexpected disappearing dependencies. + """ + all_removed_deps = _FindNewDeps(new_cr_deps, libyuv_deps) + generated_android_deps = sorted([ + path for path in all_removed_deps if path.startswith(ANDROID_DEPS_PATH) + ]) + # Webrtc-only dependencies are handled in CalculateChangedDeps. + other_deps = sorted([ + path + for path in all_removed_deps + if path not in generated_android_deps and path not in LIBYUV_ONLY_DEPS + ]) + return generated_android_deps, other_deps def CalculateChangedDeps(libyuv_deps, new_cr_deps): - """ - Calculate changed deps entries based on entries defined in the libyuv DEPS - file: + """Calculate changed deps entries based on entries defined in the LibYUV + + DEPS + + file: - If a shared dependency with the Chromium DEPS file: roll it to the same revision as Chromium (i.e. entry in the new_cr_deps dict) - If it's a Chromium sub-directory, roll it to the HEAD revision (notice @@ -238,270 +458,474 @@ def CalculateChangedDeps(libyuv_deps, new_cr_deps): - If it's another DEPS entry (not shared with Chromium), roll it to HEAD unless it's configured to be skipped. - Returns: - A list of ChangedDep objects representing the changed deps. - """ - result = [] - libyuv_entries = BuildDepsentryDict(libyuv_deps) - new_cr_entries = BuildDepsentryDict(new_cr_deps) - for path, libyuv_deps_entry in libyuv_entries.iteritems(): - if path in DONT_AUTOROLL_THESE: - continue - cr_deps_entry = new_cr_entries.get(path) - if cr_deps_entry: - # Use the revision from Chromium's DEPS file. - new_rev = cr_deps_entry.revision - assert libyuv_deps_entry.url == cr_deps_entry.url, ( - 'Libyuv DEPS entry %s has a different URL (%s) than Chromium (%s).' % - (path, libyuv_deps_entry.url, cr_deps_entry.url)) - else: - # Use the HEAD of the deps repo. - stdout, _ = _RunCommand(['git', 'ls-remote', libyuv_deps_entry.url, - 'HEAD']) - new_rev = stdout.strip().split('\t')[0] + Returns: + A list of ChangedDep objects representing the changed deps. + """ + result = [] + libyuv_entries = BuildDepsentryDict(libyuv_deps) + new_cr_entries = BuildDepsentryDict(new_cr_deps) + for path, libyuv_deps_entry in libyuv_entries.items(): + if path in DONT_AUTOROLL_THESE: + continue + cr_deps_entry = new_cr_entries.get(path) + if cr_deps_entry: + assert type(cr_deps_entry) is type(libyuv_deps_entry) - # Check if an update is necessary. - if libyuv_deps_entry.revision != new_rev: - logging.debug('Roll dependency %s to %s', path, new_rev) - result.append(ChangedDep(path, libyuv_deps_entry.url, - libyuv_deps_entry.revision, new_rev)) - return sorted(result) + if isinstance(cr_deps_entry, CipdDepsEntry): + result.extend( + _FindChangedCipdPackages(path, libyuv_deps_entry.packages, + cr_deps_entry.packages)) + continue + + if isinstance(cr_deps_entry, GcsDepsEntry): + result.extend( + _FindChangedVars( + path, ','.join(x['object_name'] + for x in libyuv_deps_entry.objects), + ','.join(x['object_name'] + for x in cr_deps_entry.objects))) + continue + + if isinstance(cr_deps_entry, VersionEntry): + result.extend( + _FindChangedVars( + path, libyuv_deps_entry.version, cr_deps_entry.version + ) + ) + continue + + # Use the revision from Chromium's DEPS file. + new_rev = cr_deps_entry.revision + assert libyuv_deps_entry.url == cr_deps_entry.url, ( + 'LibYUV DEPS entry %s has a different URL %s than Chromium %s.' + % ( + path, + libyuv_deps_entry.url, + cr_deps_entry.url, + ) + ) + else: + if isinstance(libyuv_deps_entry, DepsEntry): + # Use the HEAD of the deps repo. + stdout, _ = _RunCommand( + ['git', 'ls-remote', libyuv_deps_entry.url, 'HEAD'] + ) + new_rev = stdout.strip().split('\t')[0] + else: + # The dependency has been removed from chromium. + # This is handled by FindRemovedDeps. + continue + + # Check if an update is necessary. + if libyuv_deps_entry.revision != new_rev: + logging.debug('Roll dependency %s to %s', path, new_rev) + result.append( + ChangedDep( + path, + libyuv_deps_entry.url, + libyuv_deps_entry.revision, + new_rev, + ) + ) + return sorted(result) def CalculateChangedClang(new_cr_rev): - def GetClangRev(lines): - for line in lines: - match = CLANG_REVISION_RE.match(line) - if match: - return match.group(1) - raise RollError('Could not parse Clang revision!') - with open(CLANG_UPDATE_SCRIPT_LOCAL_PATH, 'rb') as f: - current_lines = f.readlines() - current_rev = GetClangRev(current_lines) + def GetClangRev(lines): + for line in lines: + match = CLANG_REVISION_RE.match(line) + if match: + return match.group(1) + raise RollError('Could not parse Clang revision!') - new_clang_update_py = ReadRemoteCrFile(CLANG_UPDATE_SCRIPT_URL_PATH, - new_cr_rev).splitlines() - new_rev = GetClangRev(new_clang_update_py) - return ChangedDep(CLANG_UPDATE_SCRIPT_LOCAL_PATH, None, current_rev, new_rev) + with open(CLANG_UPDATE_SCRIPT_LOCAL_PATH, 'r') as f: + current_lines = f.readlines() + current_rev = GetClangRev(current_lines) + + new_clang_update_py = ReadRemoteCrFile( + CLANG_UPDATE_SCRIPT_URL_PATH, new_cr_rev + ).splitlines() + new_rev = GetClangRev(new_clang_update_py) + return ChangedDep( + CLANG_UPDATE_SCRIPT_LOCAL_PATH, None, current_rev, new_rev + ) -def GenerateCommitMessage(current_cr_rev, new_cr_rev, current_commit_pos, - new_commit_pos, changed_deps_list, clang_change): - current_cr_rev = current_cr_rev[0:10] - new_cr_rev = new_cr_rev[0:10] - rev_interval = '%s..%s' % (current_cr_rev, new_cr_rev) - git_number_interval = '%s:%s' % (current_commit_pos, new_commit_pos) +def GenerateCommitMessage( + rev_update, + current_commit_pos, + new_commit_pos, + changed_deps_list, + added_deps_paths=None, + removed_deps_paths=None, + clang_change=None, +): + current_cr_rev = rev_update.current_chromium_rev[0:10] + new_cr_rev = rev_update.new_chromium_rev[0:10] + rev_interval = '%s..%s' % (current_cr_rev, new_cr_rev) + git_number_interval = '%s:%s' % (current_commit_pos, new_commit_pos) - commit_msg = ['Roll chromium_revision %s (%s)\n' % (rev_interval, - git_number_interval)] - commit_msg.append('Change log: %s' % (CHROMIUM_LOG_TEMPLATE % rev_interval)) - commit_msg.append('Full diff: %s\n' % (CHROMIUM_COMMIT_TEMPLATE % - rev_interval)) - if changed_deps_list: - commit_msg.append('Changed dependencies:') + commit_msg = [ + 'Roll chromium_revision %s (%s)\n' + % (rev_interval, git_number_interval), + 'Change log: %s' % (CHROMIUM_LOG_TEMPLATE % rev_interval), + 'Full diff: %s\n' % (CHROMIUM_COMMIT_TEMPLATE % rev_interval), + ] - for c in changed_deps_list: - commit_msg.append('* %s: %s/+log/%s..%s' % (c.path, c.url, - c.current_rev[0:10], - c.new_rev[0:10])) - change_url = CHROMIUM_FILE_TEMPLATE % (rev_interval, 'DEPS') - commit_msg.append('DEPS diff: %s\n' % change_url) - else: - commit_msg.append('No dependencies changed.') + def Section(adjective, deps): + noun = 'dependency' if len(deps) == 1 else 'dependencies' + commit_msg.append('%s %s' % (adjective, noun)) - if clang_change.current_rev != clang_change.new_rev: - commit_msg.append('Clang version changed %s:%s' % - (clang_change.current_rev, clang_change.new_rev)) - change_url = CHROMIUM_FILE_TEMPLATE % (rev_interval, - CLANG_UPDATE_SCRIPT_URL_PATH) - commit_msg.append('Details: %s\n' % change_url) - else: - commit_msg.append('No update to Clang.\n') + if changed_deps_list: + Section('Changed', changed_deps_list) - # TBR needs to be non-empty for Gerrit to process it. - git_author = _RunCommand(['git', 'config', 'user.email'], - working_dir=CHECKOUT_SRC_DIR)[0].strip() - commit_msg.append('TBR=%s' % git_author) + for c in changed_deps_list: + if isinstance(c, ChangedCipdPackage): + commit_msg.append( + '* %s: %s..%s' % (c.path, c.current_version, c.new_version) + ) + elif isinstance(c, ChangedVersionEntry): + commit_msg.append( + '* %s_vesion: %s..%s' + % (c.path, c.current_version, c.new_version) + ) + else: + commit_msg.append( + '* %s: %s/+log/%s..%s' + % (c.path, c.url, c.current_rev[0:10], c.new_rev[0:10]) + ) - commit_msg.append('BUG=None') - return '\n'.join(commit_msg) + if added_deps_paths: + Section('Added', added_deps_paths) + commit_msg.extend('* %s' % p for p in added_deps_paths) + + if removed_deps_paths: + Section('Removed', removed_deps_paths) + commit_msg.extend('* %s' % p for p in removed_deps_paths) + + if any([changed_deps_list, added_deps_paths, removed_deps_paths]): + change_url = CHROMIUM_FILE_TEMPLATE % (rev_interval, 'DEPS') + commit_msg.append('DEPS diff: %s\n' % change_url) + else: + commit_msg.append('No dependencies changed.') + + if clang_change and clang_change.current_rev != clang_change.new_rev: + commit_msg.append( + 'Clang version changed %s:%s' + % (clang_change.current_rev, clang_change.new_rev) + ) + change_url = CHROMIUM_FILE_TEMPLATE % ( + rev_interval, + CLANG_UPDATE_SCRIPT_URL_PATH, + ) + commit_msg.append('Details: %s\n' % change_url) + else: + commit_msg.append('No update to Clang.\n') + + commit_msg.append('BUG=None') + return '\n'.join(commit_msg) -def UpdateDepsFile(deps_filename, old_cr_revision, new_cr_revision, - changed_deps): - """Update the DEPS file with the new revision.""" +def UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content): + """Update the DEPS file with the new revision.""" - # Update the chromium_revision variable. - with open(deps_filename, 'rb') as deps_file: - deps_content = deps_file.read() - deps_content = deps_content.replace(old_cr_revision, new_cr_revision) - with open(deps_filename, 'wb') as deps_file: - deps_file.write(deps_content) + with open(deps_filename, 'rb') as deps_file: + deps_content = deps_file.read().decode('utf-8') - # Update each individual DEPS entry. - for dep in changed_deps: - local_dep_dir = os.path.join(CHECKOUT_ROOT_DIR, dep.path) - if not os.path.isdir(local_dep_dir): - raise RollError( - 'Cannot find local directory %s. Make sure the .gclient file\n' - 'contains all platforms in the target_os list, i.e.\n' - 'target_os = ["android", "unix", "mac", "ios", "win"];\n' - 'Then run "gclient sync" again.' % local_dep_dir) - _RunCommand( - ['gclient', 'setdep', '--revision', '%s@%s' % (dep.path, dep.new_rev)], - working_dir=CHECKOUT_SRC_DIR) + # Update the chromium_revision variable. + deps_content = deps_content.replace( + rev_update.current_chromium_rev, rev_update.new_chromium_rev + ) + + # Add and remove dependencies. For now: only generated android deps. + # Since gclient cannot add or remove deps, we on the fact that + # these android deps are located in one place we can copy/paste. + deps_re = re.compile( + ANDROID_DEPS_START + '.*' + ANDROID_DEPS_END, re.DOTALL + ) + new_deps = deps_re.search(new_cr_content) + old_deps = deps_re.search(deps_content) + if not new_deps or not old_deps: + faulty = 'Chromium' if not new_deps else 'LibYUV' + raise RollError( + 'Was expecting to find "%s" and "%s"\nin %s DEPS' + % (ANDROID_DEPS_START, ANDROID_DEPS_END, faulty) + ) + deps_content = deps_re.sub(new_deps.group(0), deps_content) + + for dep in changed_deps: + if isinstance(dep, ChangedVersionEntry): + deps_content = deps_content.replace( + dep.current_version, dep.new_version + ) + + with open(deps_filename, 'wb') as deps_file: + deps_file.write(deps_content.encode('utf-8')) + + # Update each individual DEPS entry. + for dep in changed_deps: + # ChangedVersionEntry types are already been processed. + if isinstance(dep, ChangedVersionEntry): + continue + local_dep_dir = os.path.join(GCLIENT_ROOT_DIR, dep.path) + if not os.path.isdir(local_dep_dir): + raise RollError( + 'Cannot find local directory %s. Either run\n' + 'gclient sync --deps=all\n' + 'or make sure the .gclient file for your solution contains ' + 'all platforms in the target_os list, i.e.\n' + 'target_os = ["android", "unix", "mac", "ios", "win"];\n' + 'Then run "gclient sync" again.' % local_dep_dir + ) + if isinstance(dep, ChangedCipdPackage): + package = dep.package.format() # Eliminate double curly brackets + update = '%s:%s@%s' % (dep.path, package, dep.new_version) + else: + update = '%s@%s' % (dep.path, dep.new_rev) + _RunCommand( + ['gclient', 'setdep', '--revision', update], + working_dir=CHECKOUT_ROOT_DIR, + ) def _IsTreeClean(): - stdout, _ = _RunCommand(['git', 'status', '--porcelain']) - if len(stdout) == 0: - return True + stdout, _ = _RunCommand(['git', 'status', '--porcelain']) + if len(stdout) == 0: + return True - logging.error('Dirty/unversioned files:\n%s', stdout) - return False + logging.error('Dirty/unversioned files:\n%s', stdout) + return False -def _EnsureUpdatedMasterBranch(dry_run): - current_branch = _RunCommand( - ['git', 'rev-parse', '--abbrev-ref', 'HEAD'])[0].splitlines()[0] - if current_branch != 'master': - logging.error('Please checkout the master branch and re-run this script.') - if not dry_run: - sys.exit(-1) +def _EnsureUpdatedMainBranch(dry_run): + current_branch = _RunCommand(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])[ + 0 + ].splitlines()[0] + if current_branch != 'main': + logging.error('Please checkout the main branch and re-run this script.') # pylint: disable=line-too-long + if not dry_run: + sys.exit(-1) - logging.info('Updating master branch...') - _RunCommand(['git', 'pull']) + logging.info('Updating main branch...') + _RunCommand(['git', 'pull']) def _CreateRollBranch(dry_run): - logging.info('Creating roll branch: %s', ROLL_BRANCH_NAME) - if not dry_run: - _RunCommand(['git', 'checkout', '-b', ROLL_BRANCH_NAME]) + logging.info('Creating roll branch: %s', ROLL_BRANCH_NAME) + if not dry_run: + _RunCommand(['git', 'checkout', '-b', ROLL_BRANCH_NAME]) def _RemovePreviousRollBranch(dry_run): - active_branch, branches = _GetBranches() - if active_branch == ROLL_BRANCH_NAME: - active_branch = 'master' - if ROLL_BRANCH_NAME in branches: - logging.info('Removing previous roll branch (%s)', ROLL_BRANCH_NAME) - if not dry_run: - _RunCommand(['git', 'checkout', active_branch]) - _RunCommand(['git', 'branch', '-D', ROLL_BRANCH_NAME]) + active_branch, branches = _GetBranches() + if active_branch == ROLL_BRANCH_NAME: + active_branch = 'main' + if ROLL_BRANCH_NAME in branches: + logging.info('Removing previous roll branch (%s)', ROLL_BRANCH_NAME) + if not dry_run: + _RunCommand(['git', 'checkout', active_branch]) + _RunCommand(['git', 'branch', '-D', ROLL_BRANCH_NAME]) def _LocalCommit(commit_msg, dry_run): - logging.info('Committing changes locally.') - if not dry_run: - _RunCommand(['git', 'add', '--update', '.']) - _RunCommand(['git', 'commit', '-m', commit_msg]) + logging.info('Committing changes locally.') + if not dry_run: + _RunCommand(['git', 'add', '--update', '.']) + _RunCommand(['git', 'commit', '-m', commit_msg]) def ChooseCQMode(skip_cq, cq_over, current_commit_pos, new_commit_pos): - if skip_cq: - return 0 - if (new_commit_pos - current_commit_pos) < cq_over: - return 1 - return 2 + if skip_cq: + return 0 + if (new_commit_pos - current_commit_pos) < cq_over: + return 1 + return 2 -def _UploadCL(commit_queue_mode): - """Upload the committed changes as a changelist to Gerrit. +def _GetCcRecipients(changed_deps_list): + """Returns a list of emails to notify based on the changed deps list.""" + cc_recipients = [] + for _ in changed_deps_list: + pass + return cc_recipients - commit_queue_mode: - - 2: Submit to commit queue. - - 1: Run trybots but do not submit to CQ. - - 0: Skip CQ, upload only. - """ - cmd = ['git', 'cl', 'upload', '--force', '--bypass-hooks', '--send-mail'] - if commit_queue_mode >= 2: - logging.info('Sending the CL to the CQ...') - cmd.extend(['--use-commit-queue']) - elif commit_queue_mode >= 1: - logging.info('Starting CQ dry run...') - cmd.extend(['--cq-dry-run']) - extra_env = { - 'EDITOR': 'true', - 'SKIP_GCE_AUTH_FOR_GIT': '1', - } - stdout, stderr = _RunCommand(cmd, extra_env=extra_env) - logging.debug('Output from "git cl upload":\nstdout:\n%s\n\nstderr:\n%s', - stdout, stderr) + +def _UploadCL(commit_queue_mode, add_cc=None): + """Upload the committed changes as a changelist to Gerrit. + + commit_queue_mode: + - 2: Submit to commit queue. + - 1: Run trybots but do not submit to CQ. + - 0: Skip CQ, upload only. + + add_cc: A list of email addresses to add as CC recipients. + """ + cc_recipients = [] + if add_cc: + cc_recipients.extend(add_cc) + cmd = ['git', 'cl', 'upload', '--force', '--bypass-hooks'] + if commit_queue_mode >= 2: + logging.info('Sending the CL to the CQ...') + cmd.extend(['-o', 'label=Bot-Commit+1']) + cmd.extend(['-o', 'label=Commit-Queue+2']) + cmd.extend(['--send-mail', '--cc', ','.join(cc_recipients)]) + elif commit_queue_mode >= 1: + logging.info('Starting CQ dry run...') + cmd.extend(['-o', 'label=Commit-Queue+1']) + extra_env = { + 'EDITOR': 'true', + 'SKIP_GCE_AUTH_FOR_GIT': '1', + } + stdout, stderr = _RunCommand(cmd, extra_env=extra_env) + logging.debug( + 'Output from "git cl upload":\nstdout:\n%s\n\nstderr:\n%s', + stdout, + stderr, + ) + + +def GetRollRevisionRanges(opts, libyuv_deps): + current_cr_rev = libyuv_deps['vars']['chromium_revision'] + new_cr_rev = opts.revision + if not new_cr_rev: + stdout, _ = _RunCommand(['git', 'ls-remote', CHROMIUM_SRC_URL, 'HEAD']) + head_rev = stdout.strip().split('\t')[0] + logging.info('No revision specified. Using HEAD: %s', head_rev) + new_cr_rev = head_rev + + return ChromiumRevisionUpdate(current_cr_rev, new_cr_rev) def main(): - p = argparse.ArgumentParser() - p.add_argument('--clean', action='store_true', default=False, - help='Removes any previous local roll branch.') - p.add_argument('-r', '--revision', - help=('Chromium Git revision to roll to. Defaults to the ' - 'Chromium HEAD revision if omitted.')) - p.add_argument('--dry-run', action='store_true', default=False, - help=('Calculate changes and modify DEPS, but don\'t create ' - 'any local branch, commit, upload CL or send any ' - 'tryjobs.')) - p.add_argument('-i', '--ignore-unclean-workdir', action='store_true', - default=False, - help=('Ignore if the current branch is not master or if there ' - 'are uncommitted changes (default: %(default)s).')) - grp = p.add_mutually_exclusive_group() - grp.add_argument('--skip-cq', action='store_true', default=False, - help='Skip sending the CL to the CQ (default: %(default)s)') - grp.add_argument('--cq-over', type=int, default=1, - help=('Commit queue dry run if the revision difference ' - 'is below this number (default: %(default)s)')) - p.add_argument('-v', '--verbose', action='store_true', default=False, - help='Be extra verbose in printing of log messages.') - opts = p.parse_args() + p = argparse.ArgumentParser() + p.add_argument( + '--clean', + action='store_true', + default=False, + help='Removes any previous local roll branch.', + ) + p.add_argument( + '-r', + '--revision', + help=( + 'Chromium Git revision to roll to. Defaults to the ' + 'Chromium HEAD revision if omitted.' + ), + ) + p.add_argument( + '--dry-run', + action='store_true', + default=False, + help=( + "Calculate changes and modify DEPS, but don't create " + 'any local branch, commit, upload CL or send any ' + 'tryjobs.' + ), + ) + p.add_argument( + '-i', + '--ignore-unclean-workdir', + action='store_true', + default=False, + help=( + 'Ignore if the current branch is not main or if there ' + 'are uncommitted changes (default: %(default)s).' + ), + ) + grp = p.add_mutually_exclusive_group() + grp.add_argument( + '--skip-cq', + action='store_true', + default=False, + help='Skip sending the CL to the CQ (default: %(default)s)', + ) + grp.add_argument( + '--cq-over', + type=int, + default=1, + help=( + 'Commit queue dry run if the revision difference ' + 'is below this number (default: %(default)s)' + ), + ) + p.add_argument( + '-v', + '--verbose', + action='store_true', + default=False, + help='Be extra verbose in printing of log messages.', + ) + opts = p.parse_args() - if opts.verbose: - logging.basicConfig(level=logging.DEBUG) - else: - logging.basicConfig(level=logging.INFO) + if opts.verbose: + logging.basicConfig(level=logging.DEBUG) + else: + logging.basicConfig(level=logging.INFO) - if not opts.ignore_unclean_workdir and not _IsTreeClean(): - logging.error('Please clean your local checkout first.') - return 1 + if not opts.ignore_unclean_workdir and not _IsTreeClean(): + logging.error('Please clean your local checkout first.') + return 1 - if opts.clean: - _RemovePreviousRollBranch(opts.dry_run) + if opts.clean: + _RemovePreviousRollBranch(opts.dry_run) - if not opts.ignore_unclean_workdir: - _EnsureUpdatedMasterBranch(opts.dry_run) + if not opts.ignore_unclean_workdir: + _EnsureUpdatedMainBranch(opts.dry_run) - new_cr_rev = opts.revision - if not new_cr_rev: - stdout, _ = _RunCommand(['git', 'ls-remote', CHROMIUM_SRC_URL, 'HEAD']) - head_rev = stdout.strip().split('\t')[0] - logging.info('No revision specified. Using HEAD: %s', head_rev) - new_cr_rev = head_rev + deps_filename = os.path.join(CHECKOUT_ROOT_DIR, 'DEPS') + libyuv_deps = ParseLocalDepsFile(deps_filename) - deps_filename = os.path.join(CHECKOUT_SRC_DIR, 'DEPS') - libyuv_deps = ParseLocalDepsFile(deps_filename) - current_cr_rev = libyuv_deps['vars']['chromium_revision'] + rev_update = GetRollRevisionRanges(opts, libyuv_deps) - current_commit_pos = ParseCommitPosition(ReadRemoteCrCommit(current_cr_rev)) - new_commit_pos = ParseCommitPosition(ReadRemoteCrCommit(new_cr_rev)) + current_commit_pos = ParseCommitPosition( + ReadRemoteCrCommit(rev_update.current_chromium_rev) + ) + new_commit_pos = ParseCommitPosition( + ReadRemoteCrCommit(rev_update.new_chromium_rev) + ) - new_cr_deps = ParseRemoteCrDepsFile(new_cr_rev) - changed_deps = CalculateChangedDeps(libyuv_deps, new_cr_deps) - clang_change = CalculateChangedClang(new_cr_rev) - commit_msg = GenerateCommitMessage(current_cr_rev, new_cr_rev, - current_commit_pos, new_commit_pos, - changed_deps, clang_change) - logging.debug('Commit message:\n%s', commit_msg) + new_cr_content = ReadRemoteCrFile('DEPS', rev_update.new_chromium_rev) + new_cr_deps = ParseDepsDict(new_cr_content) + changed_deps = CalculateChangedDeps(libyuv_deps, new_cr_deps) + # Discard other deps, assumed to be chromium-only dependencies. + new_generated_android_deps, _ = FindAddedDeps(libyuv_deps, new_cr_deps) + removed_generated_android_deps, other_deps = FindRemovedDeps( + libyuv_deps, new_cr_deps + ) + if other_deps: + raise RollError( + 'LibYUV DEPS entries are missing from Chromium: %s.\n' + 'Remove them or add them to either ' + 'LIBYUV_ONLY_DEPS or DONT_AUTOROLL_THESE.' % other_deps + ) + clang_change = CalculateChangedClang(rev_update.new_chromium_rev) + commit_msg = GenerateCommitMessage( + rev_update, + current_commit_pos, + new_commit_pos, + changed_deps, + added_deps_paths=new_generated_android_deps, + removed_deps_paths=removed_generated_android_deps, + clang_change=clang_change, + ) + logging.debug('Commit message:\n%s', commit_msg) - _CreateRollBranch(opts.dry_run) - UpdateDepsFile(deps_filename, current_cr_rev, new_cr_rev, changed_deps) - _LocalCommit(commit_msg, opts.dry_run) - commit_queue_mode = ChooseCQMode(opts.skip_cq, opts.cq_over, - current_commit_pos, new_commit_pos) - logging.info('Uploading CL...') - if not opts.dry_run: - _UploadCL(commit_queue_mode) - return 0 + _CreateRollBranch(opts.dry_run) + if not opts.dry_run: + UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content) + if _IsTreeClean(): + logging.info('No DEPS changes detected, skipping CL creation.') + else: + _LocalCommit(commit_msg, opts.dry_run) + commit_queue_mode = ChooseCQMode( + opts.skip_cq, opts.cq_over, current_commit_pos, new_commit_pos + ) + logging.info('Uploading CL...') + if not opts.dry_run: + _UploadCL(commit_queue_mode, _GetCcRecipients(changed_deps)) + return 0 if __name__ == '__main__': - sys.exit(main()) + sys.exit(main()) diff --git a/libs/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py b/libs/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py index 477b6e402a..bd38c94094 100755 --- a/libs/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +++ b/libs/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py @@ -1,4 +1,5 @@ -#!/usr/bin/env python +#!/usr/bin/env vpython3 + # Copyright 2017 The LibYuv Project Authors. All rights reserved. # # Use of this source code is governed by a BSD-style license @@ -14,25 +15,23 @@ import sys import tempfile import unittest +import roll_deps +from roll_deps import CalculateChangedDeps, GetMatchingDepsEntries, ParseDepsDict, ParseLocalDepsFile, UpdateDepsFile # pylint: disable=line-too-long SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) PARENT_DIR = os.path.join(SCRIPT_DIR, os.pardir) sys.path.append(PARENT_DIR) -import roll_deps -from roll_deps import CalculateChangedDeps, GetMatchingDepsEntries, \ - ParseDepsDict, ParseLocalDepsFile, UpdateDepsFile - TEST_DATA_VARS = { - 'chromium_git': 'https://chromium.googlesource.com', - 'chromium_revision': '1b9c098a08e40114e44b6c1ec33ddf95c40b901d', + 'chromium_git': 'https://chromium.googlesource.com', + 'chromium_revision': '1b9c098a08e40114e44b6c1ec33ddf95c40b901d', } DEPS_ENTRIES = { - 'src/build': 'https://build.com', - 'src/buildtools': 'https://buildtools.com', - 'src/testing/gtest': 'https://gtest.com', - 'src/testing/gmock': 'https://gmock.com', + 'src/build': 'https://build.com', + 'src/buildtools': 'https://buildtools.com', + 'src/testing/gtest': 'https://gtest.com', + 'src/testing/gmock': 'https://gmock.com', } BUILD_OLD_REV = '52f7afeca991d96d68cf0507e20dbdd5b845691f' @@ -42,107 +41,124 @@ BUILDTOOLS_NEW_REV = '55ad626b08ef971fd82a62b7abb325359542952b' class TestError(Exception): - pass + pass -class FakeCmd(object): - def __init__(self): - self.expectations = [] +class FakeCmd: - def add_expectation(self, *args, **kwargs): - returns = kwargs.pop('_returns', None) - self.expectations.append((args, kwargs, returns)) + def __init__(self): + self.expectations = [] - def __call__(self, *args, **kwargs): - if not self.expectations: - raise TestError('Got unexpected\n%s\n%s' % (args, kwargs)) - exp_args, exp_kwargs, exp_returns = self.expectations.pop(0) - if args != exp_args or kwargs != exp_kwargs: - message = 'Expected:\n args: %s\n kwargs: %s\n' % (exp_args, exp_kwargs) - message += 'Got:\n args: %s\n kwargs: %s\n' % (args, kwargs) - raise TestError(message) - return exp_returns + def add_expectation(self, *args, **kwargs): + returns = kwargs.pop('_returns', None) + self.expectations.append((args, kwargs, returns)) + + def __call__(self, *args, **kwargs): + if not self.expectations: + raise TestError('Got unexpected\n%s\n%s' % (args, kwargs)) + exp_args, exp_kwargs, exp_returns = self.expectations.pop(0) + if args != exp_args or kwargs != exp_kwargs: + message = 'Expected:\n args: %s\n kwargs: %s\n' % ( + exp_args, + exp_kwargs, + ) + message += 'Got:\n args: %s\n kwargs: %s\n' % (args, kwargs) + raise TestError(message) + return exp_returns class TestRollChromiumRevision(unittest.TestCase): - def setUp(self): - self._output_dir = tempfile.mkdtemp() - for test_file in glob.glob(os.path.join(SCRIPT_DIR, 'testdata', '*')): - shutil.copy(test_file, self._output_dir) - self._libyuv_depsfile = os.path.join(self._output_dir, 'DEPS') - self._old_cr_depsfile = os.path.join(self._output_dir, 'DEPS.chromium.old') - self._new_cr_depsfile = os.path.join(self._output_dir, 'DEPS.chromium.new') - self.fake = FakeCmd() - self.old_RunCommand = getattr(roll_deps, '_RunCommand') - setattr(roll_deps, '_RunCommand', self.fake) + def setUp(self): + self._output_dir = tempfile.mkdtemp() + for test_file in glob.glob(os.path.join(SCRIPT_DIR, 'testdata', '*')): + shutil.copy(test_file, self._output_dir) + self._libyuv_depsfile = os.path.join(self._output_dir, 'DEPS') + self._old_cr_depsfile = os.path.join( + self._output_dir, 'DEPS.chromium.old' + ) + self._new_cr_depsfile = os.path.join( + self._output_dir, 'DEPS.chromium.new' + ) - def tearDown(self): - shutil.rmtree(self._output_dir, ignore_errors=True) - self.assertEqual(self.fake.expectations, []) - setattr(roll_deps, '_RunCommand', self.old_RunCommand) + self.fake = FakeCmd() + self.old_RunCommand = getattr(roll_deps, '_RunCommand') + setattr(roll_deps, '_RunCommand', self.fake) - def testVarLookup(self): - local_scope = {'foo': 'wrong', 'vars': {'foo': 'bar'}} - lookup = roll_deps.VarLookup(local_scope) - self.assertEquals(lookup('foo'), 'bar') + def tearDown(self): + shutil.rmtree(self._output_dir, ignore_errors=True) + self.assertEqual(self.fake.expectations, []) + setattr(roll_deps, '_RunCommand', self.old_RunCommand) - def testUpdateDepsFile(self): - new_rev = 'aaaaabbbbbcccccdddddeeeeefffff0000011111' + def testVarLookup(self): + local_scope = {'foo': 'wrong', 'vars': {'foo': 'bar'}} + lookup = roll_deps.VarLookup(local_scope) + self.assertEqual(lookup('foo'), 'bar') - current_rev = TEST_DATA_VARS['chromium_revision'] - UpdateDepsFile(self._libyuv_depsfile, current_rev, new_rev, []) - with open(self._libyuv_depsfile) as deps_file: - deps_contents = deps_file.read() - self.assertTrue(new_rev in deps_contents, - 'Failed to find %s in\n%s' % (new_rev, deps_contents)) + def testUpdateDepsFile(self): + new_rev = 'aaaaabbbbbcccccdddddeeeeefffff0000011111' - def testParseDepsDict(self): - with open(self._libyuv_depsfile) as deps_file: - deps_contents = deps_file.read() - local_scope = ParseDepsDict(deps_contents) - vars_dict = local_scope['vars'] + current_rev = TEST_DATA_VARS['chromium_revision'] + UpdateDepsFile(self._libyuv_depsfile, current_rev, new_rev, []) + with open(self._libyuv_depsfile, 'r') as deps_file: + deps_contents = deps_file.read() + self.assertTrue( + new_rev in deps_contents, + 'Failed to find %s in\n%s' % (new_rev, deps_contents), + ) - def assertVar(variable_name): - self.assertEquals(vars_dict[variable_name], TEST_DATA_VARS[variable_name]) - assertVar('chromium_git') - assertVar('chromium_revision') - self.assertEquals(len(local_scope['deps']), 3) + def testParseDepsDict(self): + with open(self._libyuv_depsfile, 'r') as deps_file: + deps_contents = deps_file.read() + local_scope = ParseDepsDict(deps_contents) + vars_dict = local_scope['vars'] - def testGetMatchingDepsEntriesReturnsPathInSimpleCase(self): - entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing/gtest') - self.assertEquals(len(entries), 1) - self.assertEquals(entries[0], DEPS_ENTRIES['src/testing/gtest']) + def assertVar(variable_name): + self.assertEqual( + vars_dict[variable_name], TEST_DATA_VARS[variable_name] + ) - def testGetMatchingDepsEntriesHandlesSimilarStartingPaths(self): - entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing') - self.assertEquals(len(entries), 2) + assertVar('chromium_git') + assertVar('chromium_revision') + self.assertEqual(len(local_scope['deps']), 3) - def testGetMatchingDepsEntriesHandlesTwoPathsWithIdenticalFirstParts(self): - entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/build') - self.assertEquals(len(entries), 1) - self.assertEquals(entries[0], DEPS_ENTRIES['src/build']) + def testGetMatchingDepsEntriesReturnsPathInSimpleCase(self): + entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing/gtest') + self.assertEqual(len(entries), 1) + self.assertEqual(entries[0], DEPS_ENTRIES['src/testing/gtest']) - def testCalculateChangedDeps(self): - _SetupGitLsRemoteCall(self.fake, - 'https://chromium.googlesource.com/chromium/src/build', BUILD_NEW_REV) - libyuv_deps = ParseLocalDepsFile(self._libyuv_depsfile) - new_cr_deps = ParseLocalDepsFile(self._new_cr_depsfile) - changed_deps = CalculateChangedDeps(libyuv_deps, new_cr_deps) - self.assertEquals(len(changed_deps), 2) - self.assertEquals(changed_deps[0].path, 'src/build') - self.assertEquals(changed_deps[0].current_rev, BUILD_OLD_REV) - self.assertEquals(changed_deps[0].new_rev, BUILD_NEW_REV) + def testGetMatchingDepsEntriesHandlesSimilarStartingPaths(self): + entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing') + self.assertEqual(len(entries), 2) - self.assertEquals(changed_deps[1].path, 'src/buildtools') - self.assertEquals(changed_deps[1].current_rev, BUILDTOOLS_OLD_REV) - self.assertEquals(changed_deps[1].new_rev, BUILDTOOLS_NEW_REV) + def testGetMatchingDepsEntriesHandlesTwoPathsWithIdenticalFirstParts(self): + entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/build') + self.assertEqual(len(entries), 1) + self.assertEqual(entries[0], DEPS_ENTRIES['src/build']) + + def testCalculateChangedDeps(self): + _SetupGitLsRemoteCall( + self.fake, + 'https://chromium.googlesource.com/chromium/src/build', + BUILD_NEW_REV, + ) + libyuv_deps = ParseLocalDepsFile(self._libyuv_depsfile) + new_cr_deps = ParseLocalDepsFile(self._new_cr_depsfile) + changed_deps = CalculateChangedDeps(libyuv_deps, new_cr_deps) + self.assertEqual(len(changed_deps), 2) + self.assertEqual(changed_deps[0].path, 'src/build') + self.assertEqual(changed_deps[0].current_rev, BUILD_OLD_REV) + self.assertEqual(changed_deps[0].new_rev, BUILD_NEW_REV) + + self.assertEqual(changed_deps[1].path, 'src/buildtools') + self.assertEqual(changed_deps[1].current_rev, BUILDTOOLS_OLD_REV) + self.assertEqual(changed_deps[1].new_rev, BUILDTOOLS_NEW_REV) def _SetupGitLsRemoteCall(cmd_fake, url, revision): - cmd = ['git', 'ls-remote', url, revision] - cmd_fake.add_expectation(cmd, _returns=(revision, None)) + cmd = ['git', 'ls-remote', url, revision] + cmd_fake.add_expectation(cmd, _returns=(revision, None)) if __name__ == '__main__': - unittest.main() + unittest.main() diff --git a/libs/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS b/libs/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS index 9fbb48a734..4f45860cda 100644 --- a/libs/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +++ b/libs/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS @@ -3,6 +3,7 @@ vars = { 'chromium_git': 'https://chromium.googlesource.com', 'chromium_revision': '1b9c098a08e40114e44b6c1ec33ddf95c40b901d', + 'ignored_str': Str(''), } deps = { diff --git a/libs/libyuv/tools_libyuv/get_landmines.py b/libs/libyuv/tools_libyuv/get_landmines.py index c554f04a39..ee0dbecd7e 100755 --- a/libs/libyuv/tools_libyuv/get_landmines.py +++ b/libs/libyuv/tools_libyuv/get_landmines.py @@ -1,4 +1,5 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 + # Copyright 2016 The LibYuv Project Authors. All rights reserved. # # Use of this source code is governed by a BSD-style license @@ -8,31 +9,30 @@ # be found in the AUTHORS file in the root of the source tree. """ -This file emits the list of reasons why a particular build needs to be clobbered -(or a list of 'landmines'). +This file emits the list of reasons why a particular build needs to be +clobbered (or a list of 'landmines'). """ import sys def print_landmines(): - """ - ALL LANDMINES ARE EMITTED FROM HERE. - """ - # DO NOT add landmines as part of a regular CL. Landmines are a last-effort - # bandaid fix if a CL that got landed has a build dependency bug and all bots - # need to be cleaned up. If you're writing a new CL that causes build - # dependency problems, fix the dependency problems instead of adding a - # landmine. - # See the Chromium version in src/build/get_landmines.py for usage examples. - print 'Clobber to remove GYP artifacts after switching bots to GN.' - print 'Another try to remove GYP artifacts after switching bots to GN.' + """ALL LANDMINES ARE EMITTED FROM HERE.""" + # DO NOT add landmines as part of a regular CL. Landmines are a last-effort + # bandaid fix if a CL that got landed has a build dependency bug and all + # bots need to be cleaned up. If you're writing a new CL that causes build + # dependency problems, fix the dependency problems instead of adding a + # landmine. + # See the Chromium version in src/build/get_landmines.py for usage + # examples. + print('Clobber to remove GYP artifacts after switching bots to GN.') + print('Another try to remove GYP artifacts after switching bots to GN.') def main(): - print_landmines() - return 0 + print_landmines() + return 0 if __name__ == '__main__': - sys.exit(main()) + sys.exit(main()) diff --git a/libs/libyuv/tools_libyuv/msan/OWNERS b/libs/libyuv/tools_libyuv/msan/OWNERS index 0a919805c2..9b67a8f678 100644 --- a/libs/libyuv/tools_libyuv/msan/OWNERS +++ b/libs/libyuv/tools_libyuv/msan/OWNERS @@ -1,3 +1,3 @@ +mbonadei@chromium.org +fbarchard@chromium.org pbos@chromium.org -phoglund@chromium.org - diff --git a/libs/libyuv/tools_libyuv/ubsan/OWNERS b/libs/libyuv/tools_libyuv/ubsan/OWNERS index da77b4ef23..9b67a8f678 100644 --- a/libs/libyuv/tools_libyuv/ubsan/OWNERS +++ b/libs/libyuv/tools_libyuv/ubsan/OWNERS @@ -1,4 +1,3 @@ -pbos@webrtc.org -phoglund@webrtc.org +mbonadei@chromium.org fbarchard@chromium.org - +pbos@chromium.org diff --git a/libs/libyuv/tools_libyuv/valgrind/chrome_tests.bat b/libs/libyuv/tools_libyuv/valgrind/chrome_tests.bat deleted file mode 100755 index 9d4c8ca8d3..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/chrome_tests.bat +++ /dev/null @@ -1,53 +0,0 @@ -@echo off -:: Copyright (c) 2011 The Chromium Authors. All rights reserved. -:: Use of this source code is governed by a BSD-style license that can be -:: found in the LICENSE file. - -setlocal - -set THISDIR=%~dp0 -set TOOL_NAME="unknown" - -:: Get the tool name and put it into TOOL_NAME {{{1 -:: NB: SHIFT command doesn't modify %* -:PARSE_ARGS_LOOP - if %1 == () GOTO:TOOLNAME_NOT_FOUND - if %1 == --tool GOTO:TOOLNAME_FOUND - SHIFT - goto :PARSE_ARGS_LOOP - -:TOOLNAME_NOT_FOUND -echo "Please specify a tool (e.g. drmemory) by using --tool flag" -exit /B 1 - -:TOOLNAME_FOUND -SHIFT -set TOOL_NAME=%1 -:: }}} -if "%TOOL_NAME%" == "drmemory" GOTO :SETUP_DRMEMORY -if "%TOOL_NAME%" == "drmemory_light" GOTO :SETUP_DRMEMORY -if "%TOOL_NAME%" == "drmemory_full" GOTO :SETUP_DRMEMORY -if "%TOOL_NAME%" == "drmemory_pattern" GOTO :SETUP_DRMEMORY -echo "Unknown tool: `%TOOL_NAME%`! Only drmemory is supported right now" -exit /B 1 - -:SETUP_DRMEMORY -:: Set up DRMEMORY_COMMAND to invoke Dr. Memory {{{1 -set DRMEMORY_PATH=%THISDIR%..\..\third_party\drmemory -set DRMEMORY_SFX=%DRMEMORY_PATH%\drmemory-windows-sfx.exe -if EXIST %DRMEMORY_SFX% GOTO DRMEMORY_BINARY_OK -echo "Can't find Dr. Memory executables." -echo "See http://www.chromium.org/developers/how-tos/using-valgrind/dr-memory" -echo "for the instructions on how to get them." -exit /B 1 - -:DRMEMORY_BINARY_OK -%DRMEMORY_SFX% -o%DRMEMORY_PATH%\unpacked -y -set DRMEMORY_COMMAND=%DRMEMORY_PATH%\unpacked\bin\drmemory.exe -:: }}} -goto :RUN_TESTS - -:RUN_TESTS -set PYTHONPATH=%THISDIR%../python/google -set RUNNING_ON_VALGRIND=yes -python %THISDIR%/chrome_tests.py %* diff --git a/libs/libyuv/tools_libyuv/valgrind/chrome_tests.py b/libs/libyuv/tools_libyuv/valgrind/chrome_tests.py deleted file mode 100755 index fe899bce14..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/chrome_tests.py +++ /dev/null @@ -1,869 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -''' Runs various chrome tests through valgrind_test.py.''' - -import glob -import logging -import multiprocessing -import optparse -import os -import stat -import subprocess -import sys - -import logging_utils -import path_utils - -import common -import valgrind_test - -class TestNotFound(Exception): pass - -class MultipleGTestFiltersSpecified(Exception): pass - -class BuildDirNotFound(Exception): pass - -class BuildDirAmbiguous(Exception): pass - -class ExecutableNotFound(Exception): pass - -class BadBinary(Exception): pass - -class ChromeTests: - SLOW_TOOLS = ["memcheck", "drmemory"] - LAYOUT_TESTS_DEFAULT_CHUNK_SIZE = 300 - - def __init__(self, options, args, test): - if ':' in test: - (self._test, self._gtest_filter) = test.split(':', 1) - else: - self._test = test - self._gtest_filter = options.gtest_filter - - if self._test not in self._test_list: - raise TestNotFound("Unknown test: %s" % test) - - if options.gtest_filter and options.gtest_filter != self._gtest_filter: - raise MultipleGTestFiltersSpecified("Can not specify both --gtest_filter " - "and --test %s" % test) - - self._options = options - self._args = args - - script_dir = path_utils.ScriptDir() - # Compute the top of the tree (the "source dir") from the script dir (where - # this script lives). We assume that the script dir is in tools/valgrind/ - # relative to the top of the tree. - self._source_dir = os.path.dirname(os.path.dirname(script_dir)) - # since this path is used for string matching, make sure it's always - # an absolute Unix-style path - self._source_dir = os.path.abspath(self._source_dir).replace('\\', '/') - valgrind_test_script = os.path.join(script_dir, "valgrind_test.py") - self._command_preamble = ["--source-dir=%s" % (self._source_dir)] - - if not self._options.build_dir: - dirs = [ - os.path.join(self._source_dir, "xcodebuild", "Debug"), - os.path.join(self._source_dir, "out", "Debug"), - os.path.join(self._source_dir, "build", "Debug"), - ] - build_dir = [d for d in dirs if os.path.isdir(d)] - if len(build_dir) > 1: - raise BuildDirAmbiguous("Found more than one suitable build dir:\n" - "%s\nPlease specify just one " - "using --build-dir" % ", ".join(build_dir)) - elif build_dir: - self._options.build_dir = build_dir[0] - else: - self._options.build_dir = None - - if self._options.build_dir: - build_dir = os.path.abspath(self._options.build_dir) - self._command_preamble += ["--build-dir=%s" % (self._options.build_dir)] - - def _EnsureBuildDirFound(self): - if not self._options.build_dir: - raise BuildDirNotFound("Oops, couldn't find a build dir, please " - "specify it manually using --build-dir") - - def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None): - '''Generates the default command array that most tests will use.''' - if exe and common.IsWindows(): - exe += '.exe' - - cmd = list(self._command_preamble) - - # Find all suppressions matching the following pattern: - # tools/valgrind/TOOL/suppressions[_PLATFORM].txt - # and list them with --suppressions= prefix. - script_dir = path_utils.ScriptDir() - tool_name = tool.ToolName(); - suppression_file = os.path.join(script_dir, tool_name, "suppressions.txt") - if os.path.exists(suppression_file): - cmd.append("--suppressions=%s" % suppression_file) - # Platform-specific suppression - for platform in common.PlatformNames(): - platform_suppression_file = \ - os.path.join(script_dir, tool_name, 'suppressions_%s.txt' % platform) - if os.path.exists(platform_suppression_file): - cmd.append("--suppressions=%s" % platform_suppression_file) - - if tool_name == "drmemory": - if self._options.drmemory_ops: - # prepending " " to avoid Dr. Memory's option confusing optparse - cmd += ["--drmemory_ops", " " + self._options.drmemory_ops] - - if self._options.valgrind_tool_flags: - cmd += self._options.valgrind_tool_flags.split(" ") - if self._options.keep_logs: - cmd += ["--keep_logs"] - if valgrind_test_args != None: - for arg in valgrind_test_args: - cmd.append(arg) - if exe: - self._EnsureBuildDirFound() - exe_path = os.path.join(self._options.build_dir, exe) - if not os.path.exists(exe_path): - raise ExecutableNotFound("Couldn't find '%s'" % exe_path) - - # Make sure we don't try to test ASan-built binaries - # with other dynamic instrumentation-based tools. - # TODO(timurrrr): also check TSan and MSan? - # `nm` might not be available, so use try-except. - try: - # Do not perform this check on OS X, as 'nm' on 10.6 can't handle - # binaries built with Clang 3.5+. - if not common.IsMac(): - nm_output = subprocess.check_output(["nm", exe_path]) - if nm_output.find("__asan_init") != -1: - raise BadBinary("You're trying to run an executable instrumented " - "with AddressSanitizer under %s. Please provide " - "an uninstrumented executable." % tool_name) - except OSError: - pass - - cmd.append(exe_path) - # Valgrind runs tests slowly, so slow tests hurt more; show elapased time - # so we can find the slowpokes. - cmd.append("--gtest_print_time") - # Built-in test launcher for gtest-based executables runs tests using - # multiple process by default. Force the single-process mode back. - cmd.append("--single-process-tests") - if self._options.gtest_repeat: - cmd.append("--gtest_repeat=%s" % self._options.gtest_repeat) - if self._options.gtest_shuffle: - cmd.append("--gtest_shuffle") - if self._options.gtest_break_on_failure: - cmd.append("--gtest_break_on_failure") - if self._options.test_launcher_bot_mode: - cmd.append("--test-launcher-bot-mode") - if self._options.test_launcher_total_shards is not None: - cmd.append("--test-launcher-total-shards=%d" - % self._options.test_launcher_total_shards) - if self._options.test_launcher_shard_index is not None: - cmd.append("--test-launcher-shard-index=%d" - % self._options.test_launcher_shard_index) - return cmd - - def Run(self): - ''' Runs the test specified by command-line argument --test ''' - logging.info("running test %s" % (self._test)) - return self._test_list[self._test](self) - - def _AppendGtestFilter(self, tool, name, cmd): - '''Append an appropriate --gtest_filter flag to the googletest binary - invocation. - If the user passed their own filter mentioning only one test, just use - it. Otherwise, filter out tests listed in the appropriate gtest_exclude - files. - ''' - if (self._gtest_filter and - ":" not in self._gtest_filter and - "?" not in self._gtest_filter and - "*" not in self._gtest_filter): - cmd.append("--gtest_filter=%s" % self._gtest_filter) - return - - filters = [] - gtest_files_dir = os.path.join(path_utils.ScriptDir(), "gtest_exclude") - - gtest_filter_files = [ - os.path.join(gtest_files_dir, name + ".gtest-%s.txt" % tool.ToolName())] - # Use ".gtest.txt" files only for slow tools, as they now contain - # Valgrind- and Dr.Memory-specific filters. - # TODO(glider): rename the files to ".gtest_slow.txt" - if tool.ToolName() in ChromeTests.SLOW_TOOLS: - gtest_filter_files += [os.path.join(gtest_files_dir, name + ".gtest.txt")] - for platform_suffix in common.PlatformNames(): - gtest_filter_files += [ - os.path.join(gtest_files_dir, name + ".gtest_%s.txt" % platform_suffix), - os.path.join(gtest_files_dir, name + ".gtest-%s_%s.txt" % \ - (tool.ToolName(), platform_suffix))] - logging.info("Reading gtest exclude filter files:") - for filename in gtest_filter_files: - # strip the leading absolute path (may be very long on the bot) - # and the following / or \. - readable_filename = filename.replace("\\", "/") # '\' on Windows - readable_filename = readable_filename.replace(self._source_dir, "")[1:] - if not os.path.exists(filename): - logging.info(" \"%s\" - not found" % readable_filename) - continue - logging.info(" \"%s\" - OK" % readable_filename) - f = open(filename, 'r') - for line in f.readlines(): - if line.startswith("#") or line.startswith("//") or line.isspace(): - continue - line = line.rstrip() - test_prefixes = ["FLAKY", "FAILS"] - for p in test_prefixes: - # Strip prefixes from the test names. - line = line.replace(".%s_" % p, ".") - # Exclude the original test name. - filters.append(line) - if line[-2:] != ".*": - # List all possible prefixes if line doesn't end with ".*". - for p in test_prefixes: - filters.append(line.replace(".", ".%s_" % p)) - # Get rid of duplicates. - filters = set(filters) - gtest_filter = self._gtest_filter - if len(filters): - if gtest_filter: - gtest_filter += ":" - if gtest_filter.find("-") < 0: - gtest_filter += "-" - else: - gtest_filter = "-" - gtest_filter += ":".join(filters) - if gtest_filter: - cmd.append("--gtest_filter=%s" % gtest_filter) - - @staticmethod - def ShowTests(): - test_to_names = {} - for name, test_function in ChromeTests._test_list.iteritems(): - test_to_names.setdefault(test_function, []).append(name) - - name_to_aliases = {} - for names in test_to_names.itervalues(): - names.sort(key=lambda name: len(name)) - name_to_aliases[names[0]] = names[1:] - - print - print "Available tests:" - print "----------------" - for name, aliases in sorted(name_to_aliases.iteritems()): - if aliases: - print " {} (aka {})".format(name, ', '.join(aliases)) - else: - print " {}".format(name) - - def SetupLdPath(self, requires_build_dir): - if requires_build_dir: - self._EnsureBuildDirFound() - elif not self._options.build_dir: - return - - # Append build_dir to LD_LIBRARY_PATH so external libraries can be loaded. - if (os.getenv("LD_LIBRARY_PATH")): - os.putenv("LD_LIBRARY_PATH", "%s:%s" % (os.getenv("LD_LIBRARY_PATH"), - self._options.build_dir)) - else: - os.putenv("LD_LIBRARY_PATH", self._options.build_dir) - - def SimpleTest(self, module, name, valgrind_test_args=None, cmd_args=None): - tool = valgrind_test.CreateTool(self._options.valgrind_tool) - cmd = self._DefaultCommand(tool, name, valgrind_test_args) - self._AppendGtestFilter(tool, name, cmd) - cmd.extend(['--test-tiny-timeout=1000']) - if cmd_args: - cmd.extend(cmd_args) - - self.SetupLdPath(True) - return tool.Run(cmd, module) - - def RunCmdLine(self): - tool = valgrind_test.CreateTool(self._options.valgrind_tool) - cmd = self._DefaultCommand(tool, None, self._args) - self.SetupLdPath(False) - return tool.Run(cmd, None) - - def TestAccessibility(self): - return self.SimpleTest("accessibility", "accessibility_unittests") - - def TestAddressInput(self): - return self.SimpleTest("addressinput", "libaddressinput_unittests") - - def TestAngle(self): - return self.SimpleTest("angle", "angle_unittests") - - def TestAppList(self): - return self.SimpleTest("app_list", "app_list_unittests") - - def TestAsh(self): - return self.SimpleTest("ash", "ash_unittests") - - def TestAura(self): - return self.SimpleTest("aura", "aura_unittests") - - def TestBase(self): - return self.SimpleTest("base", "base_unittests") - - def TestBlinkHeap(self): - return self.SimpleTest("blink_heap", "blink_heap_unittests") - - def TestBlinkPlatform(self): - return self.SimpleTest("blink_platform", "blink_platform_unittests") - - def TestCacheInvalidation(self): - return self.SimpleTest("cacheinvalidation", "cacheinvalidation_unittests") - - def TestCast(self): - return self.SimpleTest("chrome", "cast_unittests") - - def TestCC(self): - return self.SimpleTest("cc", "cc_unittests", - cmd_args=[ - "--cc-layer-tree-test-long-timeout"]) - - def TestChromeApp(self): - return self.SimpleTest("chrome_app", "chrome_app_unittests") - - def TestChromeElf(self): - return self.SimpleTest("chrome_elf", "chrome_elf_unittests") - - def TestChromeDriver(self): - return self.SimpleTest("chromedriver", "chromedriver_unittests") - - def TestChromeOS(self): - return self.SimpleTest("chromeos", "chromeos_unittests") - - def TestComponents(self): - return self.SimpleTest("components", "components_unittests") - - def TestCompositor(self): - return self.SimpleTest("compositor", "compositor_unittests") - - def TestContent(self): - return self.SimpleTest("content", "content_unittests") - - def TestCourgette(self): - return self.SimpleTest("courgette", "courgette_unittests") - - def TestCrypto(self): - return self.SimpleTest("crypto", "crypto_unittests") - - def TestDevice(self): - return self.SimpleTest("device", "device_unittests") - - def TestDisplay(self): - return self.SimpleTest("display", "display_unittests") - - def TestEvents(self): - return self.SimpleTest("events", "events_unittests") - - def TestExtensions(self): - return self.SimpleTest("extensions", "extensions_unittests") - - def TestFFmpegRegressions(self): - return self.SimpleTest("chrome", "ffmpeg_regression_tests") - - def TestGCM(self): - return self.SimpleTest("gcm", "gcm_unit_tests") - - def TestGfx(self): - return self.SimpleTest("gfx", "gfx_unittests") - - def TestGin(self): - return self.SimpleTest("gin", "gin_unittests") - - def TestGoogleApis(self): - return self.SimpleTest("google_apis", "google_apis_unittests") - - def TestGPU(self): - return self.SimpleTest("gpu", "gpu_unittests") - - def TestIpc(self): - return self.SimpleTest("ipc", "ipc_tests", - valgrind_test_args=["--trace_children"]) - - def TestInstallerUtil(self): - return self.SimpleTest("installer_util", "installer_util_unittests") - - def TestInstallStatic(self): - return self.SimpleTest("install_static", "install_static_unittests") - - def TestJingle(self): - return self.SimpleTest("chrome", "jingle_unittests") - - def TestKeyboard(self): - return self.SimpleTest("keyboard", "keyboard_unittests") - - def TestLatency(self): - return self.SimpleTest("latency", "latency_unittests") - - def TestMedia(self): - return self.SimpleTest("chrome", "media_unittests") - - def TestMessageCenter(self): - return self.SimpleTest("message_center", "message_center_unittests") - - def TestMidi(self): - return self.SimpleTest("chrome", "midi_unittests") - - def TestMojoCommon(self): - return self.SimpleTest("mojo_common", "mojo_common_unittests") - - def TestMojoPublicBindings(self): - return self.SimpleTest("mojo_public_bindings", - "mojo_public_bindings_unittests") - - def TestMojoPublicSystem(self): - return self.SimpleTest("mojo_public_system", - "mojo_public_system_unittests") - - def TestMojoPublicSysPerf(self): - return self.SimpleTest("mojo_public_sysperf", - "mojo_public_system_perftests") - - def TestMojoSystem(self): - return self.SimpleTest("mojo_system", "mojo_system_unittests") - - def TestNet(self): - return self.SimpleTest("net", "net_unittests") - - def TestNetPerf(self): - return self.SimpleTest("net", "net_perftests") - - def TestPhoneNumber(self): - return self.SimpleTest("phonenumber", "libphonenumber_unittests") - - def TestPPAPI(self): - return self.SimpleTest("chrome", "ppapi_unittests") - - def TestPrinting(self): - return self.SimpleTest("chrome", "printing_unittests") - - def TestRemoting(self): - return self.SimpleTest("chrome", "remoting_unittests", - cmd_args=[ - "--ui-test-action-timeout=60000", - "--ui-test-action-max-timeout=150000"]) - - def TestSkia(self): - return self.SimpleTest("skia", "skia_unittests") - - def TestSql(self): - return self.SimpleTest("chrome", "sql_unittests") - - def TestStorage(self): - return self.SimpleTest("storage", "storage_unittests") - - def TestLinuxSandbox(self): - return self.SimpleTest("sandbox", "sandbox_linux_unittests") - - def TestUnit(self): - # http://crbug.com/51716 - # Disabling all unit tests - # Problems reappeared after r119922 - if common.IsMac() and (self._options.valgrind_tool == "memcheck"): - logging.warning("unit_tests are disabled for memcheck on MacOS.") - return 0; - return self.SimpleTest("chrome", "unit_tests") - - def TestUIBaseUnit(self): - return self.SimpleTest("chrome", "ui_base_unittests") - - def TestUIChromeOS(self): - return self.SimpleTest("chrome", "ui_chromeos_unittests") - - def TestURL(self): - return self.SimpleTest("chrome", "url_unittests") - - def TestViews(self): - return self.SimpleTest("views", "views_unittests") - - - # Valgrind timeouts are in seconds. - UI_VALGRIND_ARGS = ["--timeout=14400", "--trace_children", "--indirect"] - # UI test timeouts are in milliseconds. - UI_TEST_ARGS = ["--ui-test-action-timeout=60000", - "--ui-test-action-max-timeout=150000", - "--no-sandbox"] - - # TODO(thestig) fine-tune these values. - # Valgrind timeouts are in seconds. - BROWSER_VALGRIND_ARGS = ["--timeout=50000", "--trace_children", "--indirect"] - # Browser test timeouts are in milliseconds. - BROWSER_TEST_ARGS = ["--ui-test-action-timeout=400000", - "--ui-test-action-max-timeout=800000", - "--no-sandbox"] - - def TestBrowser(self): - return self.SimpleTest("chrome", "browser_tests", - valgrind_test_args=self.BROWSER_VALGRIND_ARGS, - cmd_args=self.BROWSER_TEST_ARGS) - - def TestContentBrowser(self): - return self.SimpleTest("content", "content_browsertests", - valgrind_test_args=self.BROWSER_VALGRIND_ARGS, - cmd_args=self.BROWSER_TEST_ARGS) - - def TestInteractiveUI(self): - return self.SimpleTest("chrome", "interactive_ui_tests", - valgrind_test_args=self.UI_VALGRIND_ARGS, - cmd_args=self.UI_TEST_ARGS) - - def TestSyncIntegration(self): - return self.SimpleTest("chrome", "sync_integration_tests", - valgrind_test_args=self.UI_VALGRIND_ARGS, - cmd_args=(["--ui-test-action-max-timeout=450000"])) - - def TestLayoutChunk(self, chunk_num, chunk_size): - # Run tests [chunk_num*chunk_size .. (chunk_num+1)*chunk_size) from the - # list of tests. Wrap around to beginning of list at end. - # If chunk_size is zero, run all tests in the list once. - # If a text file is given as argument, it is used as the list of tests. - assert((chunk_size == 0) != (len(self._args) == 0)) - # Build the ginormous commandline in 'cmd'. - # It's going to be roughly - # python valgrind_test.py ... - # but we'll use the --indirect flag to valgrind_test.py - # to avoid valgrinding python. - # Start by building the valgrind_test.py commandline. - tool = valgrind_test.CreateTool(self._options.valgrind_tool) - cmd = self._DefaultCommand(tool) - cmd.append("--trace_children") - cmd.append("--indirect_webkit_layout") - cmd.append("--ignore_exit_code") - # Now build script_cmd, the run-webkits-tests commandline. - # Store each chunk in its own directory so that we can find the data later - chunk_dir = os.path.join("layout", "chunk_%05d" % chunk_num) - out_dir = os.path.join(path_utils.ScriptDir(), "latest") - out_dir = os.path.join(out_dir, chunk_dir) - if os.path.exists(out_dir): - old_files = glob.glob(os.path.join(out_dir, "*.txt")) - for f in old_files: - os.remove(f) - else: - os.makedirs(out_dir) - script = os.path.join(self._source_dir, "third_party", "WebKit", "Tools", - "Scripts", "run-webkit-tests") - # http://crbug.com/260627: After the switch to content_shell from DRT, each - # test now brings up 3 processes. Under Valgrind, they become memory bound - # and can eventually OOM if we don't reduce the total count. - # It'd be nice if content_shell automatically throttled the startup of new - # tests if we're low on memory. - jobs = max(1, int(multiprocessing.cpu_count() * 0.3)) - script_cmd = ["python", script, "-v", - # run a separate DumpRenderTree for each test - "--batch-size=1", - "--fully-parallel", - "--child-processes=%d" % jobs, - "--time-out-ms=800000", - "--no-retry-failures", # retrying takes too much time - # http://crbug.com/176908: Don't launch a browser when done. - "--no-show-results", - "--nocheck-sys-deps", - "--additional-driver-flag=--no-sandbox"] - # Pass build mode to run-webkit-tests. We aren't passed it directly, - # so parse it out of build_dir. run-webkit-tests can only handle - # the two values "Release" and "Debug". - # TODO(Hercules): unify how all our scripts pass around build mode - # (--mode / --target / --build-dir / --debug) - if self._options.build_dir: - build_root, mode = os.path.split(self._options.build_dir) - script_cmd.extend(["--build-directory", build_root, "--target", mode]) - if (chunk_size > 0): - script_cmd.append("--run-chunk=%d:%d" % (chunk_num, chunk_size)) - if len(self._args): - # if the arg is a txt file, then treat it as a list of tests - if os.path.isfile(self._args[0]) and self._args[0][-4:] == ".txt": - script_cmd.append("--test-list=%s" % self._args[0]) - else: - script_cmd.extend(self._args) - self._AppendGtestFilter(tool, "layout", script_cmd) - # Now run script_cmd with the wrapper in cmd - cmd.extend(["--"]) - cmd.extend(script_cmd) - - # Layout tests often times fail quickly, but the buildbot remains green. - # Detect this situation when running with the default chunk size. - if chunk_size == self.LAYOUT_TESTS_DEFAULT_CHUNK_SIZE: - min_runtime_in_seconds=120 - else: - min_runtime_in_seconds=0 - ret = tool.Run(cmd, "layout", min_runtime_in_seconds=min_runtime_in_seconds) - return ret - - - def TestLayout(self): - # A "chunk file" is maintained in the local directory so that each test - # runs a slice of the layout tests of size chunk_size that increments with - # each run. Since tests can be added and removed from the layout tests at - # any time, this is not going to give exact coverage, but it will allow us - # to continuously run small slices of the layout tests under valgrind rather - # than having to run all of them in one shot. - chunk_size = self._options.num_tests - if chunk_size == 0 or len(self._args): - return self.TestLayoutChunk(0, 0) - chunk_num = 0 - chunk_file = os.path.join("valgrind_layout_chunk.txt") - logging.info("Reading state from " + chunk_file) - try: - f = open(chunk_file) - if f: - chunk_str = f.read() - if len(chunk_str): - chunk_num = int(chunk_str) - # This should be enough so that we have a couple of complete runs - # of test data stored in the archive (although note that when we loop - # that we almost guaranteed won't be at the end of the test list) - if chunk_num > 10000: - chunk_num = 0 - f.close() - except IOError, (errno, strerror): - logging.error("error reading from file %s (%d, %s)" % (chunk_file, - errno, strerror)) - # Save the new chunk size before running the tests. Otherwise if a - # particular chunk hangs the bot, the chunk number will never get - # incremented and the bot will be wedged. - logging.info("Saving state to " + chunk_file) - try: - f = open(chunk_file, "w") - chunk_num += 1 - f.write("%d" % chunk_num) - f.close() - except IOError, (errno, strerror): - logging.error("error writing to file %s (%d, %s)" % (chunk_file, errno, - strerror)) - # Since we're running small chunks of the layout tests, it's important to - # mark the ones that have errors in them. These won't be visible in the - # summary list for long, but will be useful for someone reviewing this bot. - return self.TestLayoutChunk(chunk_num, chunk_size) - - # The known list of tests. - # Recognise the original abbreviations as well as full executable names. - _test_list = { - "cmdline" : RunCmdLine, - "addressinput": TestAddressInput, - "libaddressinput_unittests": TestAddressInput, - "accessibility": TestAccessibility, - "angle": TestAngle, "angle_unittests": TestAngle, - "app_list": TestAppList, "app_list_unittests": TestAppList, - "ash": TestAsh, "ash_unittests": TestAsh, - "aura": TestAura, "aura_unittests": TestAura, - "base": TestBase, "base_unittests": TestBase, - "blink_heap": TestBlinkHeap, - "blink_platform": TestBlinkPlatform, - "browser": TestBrowser, "browser_tests": TestBrowser, - "cacheinvalidation": TestCacheInvalidation, - "cacheinvalidation_unittests": TestCacheInvalidation, - "cast": TestCast, "cast_unittests": TestCast, - "cc": TestCC, "cc_unittests": TestCC, - "chrome_app": TestChromeApp, - "chrome_elf": TestChromeElf, - "chromedriver": TestChromeDriver, - "chromeos": TestChromeOS, "chromeos_unittests": TestChromeOS, - "components": TestComponents,"components_unittests": TestComponents, - "compositor": TestCompositor,"compositor_unittests": TestCompositor, - "content": TestContent, "content_unittests": TestContent, - "content_browsertests": TestContentBrowser, - "courgette": TestCourgette, "courgette_unittests": TestCourgette, - "crypto": TestCrypto, "crypto_unittests": TestCrypto, - "device": TestDevice, "device_unittests": TestDevice, - "display": TestDisplay, "display_unittests": TestDisplay, - "events": TestEvents, "events_unittests": TestEvents, - "extensions": TestExtensions, "extensions_unittests": TestExtensions, - "ffmpeg_regression_tests": TestFFmpegRegressions, - "gcm": TestGCM, "gcm_unit_tests": TestGCM, - "gin": TestGin, "gin_unittests": TestGin, - "gfx": TestGfx, "gfx_unittests": TestGfx, - "google_apis": TestGoogleApis, - "gpu": TestGPU, "gpu_unittests": TestGPU, - "ipc": TestIpc, "ipc_tests": TestIpc, - "installer_util": TestInstallerUtil, - "installer_util_unittests": TestInstallerUtil, - "install_static_unittests": TestInstallStatic, - "interactive_ui": TestInteractiveUI, - "jingle": TestJingle, "jingle_unittests": TestJingle, - "keyboard": TestKeyboard, "keyboard_unittests": TestKeyboard, - "latency": TestLatency, "latency_unittests": TestLatency, - "layout": TestLayout, "layout_tests": TestLayout, - "media": TestMedia, "media_unittests": TestMedia, - "message_center": TestMessageCenter, - "message_center_unittests" : TestMessageCenter, - "midi": TestMidi, "midi_unittests": TestMidi, - "mojo_common": TestMojoCommon, - "mojo_common_unittests": TestMojoCommon, - "mojo_system": TestMojoSystem, - "mojo_system_unittests": TestMojoSystem, - "mojo_public_system": TestMojoPublicSystem, - "mojo_public_system_unittests": TestMojoPublicSystem, - "mojo_public_bindings": TestMojoPublicBindings, - "mojo_public_bindings_unittests": TestMojoPublicBindings, - "mojo_public_sysperf": TestMojoPublicSysPerf, - "net": TestNet, "net_unittests": TestNet, - "net_perf": TestNetPerf, "net_perftests": TestNetPerf, - "phonenumber": TestPhoneNumber, - "libphonenumber_unittests": TestPhoneNumber, - "ppapi": TestPPAPI, "ppapi_unittests": TestPPAPI, - "printing": TestPrinting, "printing_unittests": TestPrinting, - "remoting": TestRemoting, "remoting_unittests": TestRemoting, - "sandbox": TestLinuxSandbox, "sandbox_linux_unittests": TestLinuxSandbox, - "skia": TestSkia, "skia_unittests": TestSkia, - "sql": TestSql, "sql_unittests": TestSql, - "storage": TestStorage, "storage_unittests": TestStorage, - "sync_integration_tests": TestSyncIntegration, - "sync_integration": TestSyncIntegration, - "ui_base_unit": TestUIBaseUnit, "ui_base_unittests": TestUIBaseUnit, - "ui_chromeos": TestUIChromeOS, "ui_chromeos_unittests": TestUIChromeOS, - "unit": TestUnit, "unit_tests": TestUnit, - "url": TestURL, "url_unittests": TestURL, - "views": TestViews, "views_unittests": TestViews, - "webkit": TestLayout, - } - - -def _main(): - parser = optparse.OptionParser("usage: %prog -b -t " - "[-t ...]") - - parser.add_option("--help-tests", dest="help_tests", action="store_true", - default=False, help="List all available tests") - parser.add_option("-b", "--build-dir", - help="the location of the compiler output") - parser.add_option("--target", help="Debug or Release") - parser.add_option("-t", "--test", action="append", default=[], - help="which test to run, supports test:gtest_filter format " - "as well.") - parser.add_option("--baseline", action="store_true", default=False, - help="generate baseline data instead of validating") - parser.add_option("-f", "--force", action="store_true", default=False, - help="run a broken test anyway") - parser.add_option("--gtest_filter", - help="additional arguments to --gtest_filter") - parser.add_option("--gtest_repeat", help="argument for --gtest_repeat") - parser.add_option("--gtest_shuffle", action="store_true", default=False, - help="Randomize tests' orders on every iteration.") - parser.add_option("--gtest_break_on_failure", action="store_true", - default=False, - help="Drop in to debugger on assertion failure. Also " - "useful for forcing tests to exit with a stack dump " - "on the first assertion failure when running with " - "--gtest_repeat=-1") - parser.add_option("-v", "--verbose", action="store_true", default=False, - help="verbose output - enable debug log messages") - parser.add_option("--tool", dest="valgrind_tool", default="memcheck", - help="specify a valgrind tool to run the tests under") - parser.add_option("--tool_flags", dest="valgrind_tool_flags", default="", - help="specify custom flags for the selected valgrind tool") - parser.add_option("--keep_logs", action="store_true", default=False, - help="store memory tool logs in the .logs directory " - "instead of /tmp.\nThis can be useful for tool " - "developers/maintainers.\nPlease note that the " - ".logs directory will be clobbered on tool startup.") - parser.add_option("-n", "--num_tests", type="int", - default=ChromeTests.LAYOUT_TESTS_DEFAULT_CHUNK_SIZE, - help="for layout tests: # of subtests per run. 0 for all.") - parser.add_option("--test-launcher-bot-mode", action="store_true", - help="run the tests with --test-launcher-bot-mode") - parser.add_option("--test-launcher-total-shards", type=int, - help="run the tests with --test-launcher-total-shards") - parser.add_option("--test-launcher-shard-index", type=int, - help="run the tests with --test-launcher-shard-index") - parser.add_option("--drmemory_ops", - help="extra options passed to Dr. Memory") - - options, args = parser.parse_args() - - # Bake target into build_dir. - if options.target and options.build_dir: - assert (options.target != - os.path.basename(os.path.dirname(options.build_dir))) - options.build_dir = os.path.join(os.path.abspath(options.build_dir), - options.target) - - if options.verbose: - logging_utils.config_root(logging.DEBUG) - else: - logging_utils.config_root() - - if options.help_tests: - ChromeTests.ShowTests() - return 0 - - if not options.test: - parser.error("--test not specified") - - if len(options.test) != 1 and options.gtest_filter: - parser.error("--gtest_filter and multiple tests don't make sense together") - - BROKEN_TESTS = { - 'drmemory_light': [ - 'addressinput', - 'aura', - 'base_unittests', - 'cc', - 'components', # x64 only? - 'content', - 'gfx', - 'mojo_public_bindings', - ], - 'drmemory_full': [ - 'addressinput', - 'aura', - 'base_unittests', - 'blink_heap', - 'blink_platform', - 'browser_tests', - 'cast', - 'cc', - 'chromedriver', - 'compositor', - 'content', - 'content_browsertests', - 'device', - 'events', - 'extensions', - 'gfx', - 'google_apis', - 'gpu', - 'ipc_tests', - 'jingle', - 'keyboard', - 'media', - 'midi', - 'mojo_common', - 'mojo_public_bindings', - 'mojo_public_sysperf', - 'mojo_public_system', - 'mojo_system', - 'net', - 'remoting', - 'unit', - 'url', - ], - } - - for t in options.test: - if t in BROKEN_TESTS[options.valgrind_tool] and not options.force: - logging.info("Skipping broken %s test %s -- see crbug.com/633693" % - (options.valgrind_tool, t)) - return 0 - - tests = ChromeTests(options, args, t) - ret = tests.Run() - if ret: return ret - return 0 - - -if __name__ == "__main__": - sys.exit(_main()) diff --git a/libs/libyuv/tools_libyuv/valgrind/chrome_tests.sh b/libs/libyuv/tools_libyuv/valgrind/chrome_tests.sh deleted file mode 100755 index dc17684fec..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/chrome_tests.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -# Set up some paths and re-direct the arguments to chrome_tests.py - -export THISDIR=`dirname $0` -ARGV_COPY="$@" - -# We need to set CHROME_VALGRIND iff using Memcheck: -# tools/valgrind/chrome_tests.sh --tool memcheck -# or -# tools/valgrind/chrome_tests.sh --tool=memcheck -tool="memcheck" # Default to memcheck. -while (( "$#" )) -do - if [[ "$1" == "--tool" ]] - then - tool="$2" - shift - elif [[ "$1" =~ --tool=(.*) ]] - then - tool="${BASH_REMATCH[1]}" - fi - shift -done - -NEEDS_VALGRIND=0 -NEEDS_DRMEMORY=0 - -case "$tool" in - "memcheck") - NEEDS_VALGRIND=1 - ;; - "drmemory" | "drmemory_light" | "drmemory_full" | "drmemory_pattern") - NEEDS_DRMEMORY=1 - ;; -esac - -if [ "$NEEDS_VALGRIND" == "1" ] -then - export CHROME_VALGRIND=`sh $THISDIR/locate_valgrind.sh` - if [ "$CHROME_VALGRIND" = "" ] - then - # locate_valgrind.sh failed - exit 1 - fi - echo "Using valgrind binaries from ${CHROME_VALGRIND}" - - PATH="${CHROME_VALGRIND}/bin:$PATH" - # We need to set these variables to override default lib paths hard-coded into - # Valgrind binary. - export VALGRIND_LIB="$CHROME_VALGRIND/lib/valgrind" - export VALGRIND_LIB_INNER="$CHROME_VALGRIND/lib/valgrind" - - # Clean up some /tmp directories that might be stale due to interrupted - # chrome_tests.py execution. - # FYI: - # -mtime +1 <- only print files modified more than 24h ago, - # -print0/-0 are needed to handle possible newlines in the filenames. - echo "Cleanup /tmp from Valgrind stuff" - find /tmp -maxdepth 1 \(\ - -name "vgdb-pipe-*" -or -name "vg_logs_*" -or -name "valgrind.*" \ - \) -mtime +1 -print0 | xargs -0 rm -rf -fi - -if [ "$NEEDS_DRMEMORY" == "1" ] -then - if [ -z "$DRMEMORY_COMMAND" ] - then - DRMEMORY_PATH="$THISDIR/../../third_party/drmemory" - DRMEMORY_SFX="$DRMEMORY_PATH/drmemory-windows-sfx.exe" - if [ ! -f "$DRMEMORY_SFX" ] - then - echo "Can't find Dr. Memory executables." - echo "See http://www.chromium.org/developers/how-tos/using-valgrind/dr-memory" - echo "for the instructions on how to get them." - exit 1 - fi - - chmod +x "$DRMEMORY_SFX" # Cygwin won't run it without +x. - "$DRMEMORY_SFX" -o"$DRMEMORY_PATH/unpacked" -y - export DRMEMORY_COMMAND="$DRMEMORY_PATH/unpacked/bin/drmemory.exe" - fi -fi - -PYTHONPATH=$THISDIR/../python/google python \ - "$THISDIR/chrome_tests.py" $ARGV_COPY diff --git a/libs/libyuv/tools_libyuv/valgrind/common.py b/libs/libyuv/tools_libyuv/valgrind/common.py deleted file mode 100644 index e9ee51e48e..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/common.py +++ /dev/null @@ -1,256 +0,0 @@ -# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -import logging -import platform -import os -import signal -import subprocess -import sys -import time - - -class NotImplementedError(Exception): - pass - - -class TimeoutError(Exception): - pass - - -def RunSubprocessInBackground(proc): - """Runs a subprocess in the background. Returns a handle to the process.""" - logging.info("running %s in the background" % " ".join(proc)) - return subprocess.Popen(proc) - - -def RunSubprocess(proc, timeout=0): - """ Runs a subprocess, until it finishes or |timeout| is exceeded and the - process is killed with taskkill. A |timeout| <= 0 means no timeout. - - Args: - proc: list of process components (exe + args) - timeout: how long to wait before killing, <= 0 means wait forever - """ - - logging.info("running %s, timeout %d sec" % (" ".join(proc), timeout)) - sys.stdout.flush() - sys.stderr.flush() - - # Manually read and print out stdout and stderr. - # By default, the subprocess is supposed to inherit these from its parent, - # however when run under buildbot, it seems unable to read data from a - # grandchild process, so we have to read the child and print the data as if - # it came from us for buildbot to read it. We're not sure why this is - # necessary. - # TODO(erikkay): should we buffer stderr and stdout separately? - p = subprocess.Popen(proc, universal_newlines=True, - bufsize=0, # unbuffered - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - - logging.info("started subprocess") - - did_timeout = False - if timeout > 0: - wait_until = time.time() + timeout - while p.poll() is None and not did_timeout: - # Have to use readline rather than readlines() or "for line in p.stdout:", - # otherwise we get buffered even with bufsize=0. - line = p.stdout.readline() - while line and not did_timeout: - sys.stdout.write(line) - sys.stdout.flush() - line = p.stdout.readline() - if timeout > 0: - did_timeout = time.time() > wait_until - - if did_timeout: - logging.info("process timed out") - else: - logging.info("process ended, did not time out") - - if did_timeout: - if IsWindows(): - subprocess.call(["taskkill", "/T", "/F", "/PID", str(p.pid)]) - else: - # Does this kill all children, too? - os.kill(p.pid, signal.SIGINT) - logging.error("KILLED %d" % p.pid) - # Give the process a chance to actually die before continuing - # so that cleanup can happen safely. - time.sleep(1.0) - logging.error("TIMEOUT waiting for %s" % proc[0]) - raise TimeoutError(proc[0]) - else: - for line in p.stdout: - sys.stdout.write(line) - if not IsMac(): # stdout flush fails on Mac - logging.info("flushing stdout") - sys.stdout.flush() - - logging.info("collecting result code") - result = p.poll() - if result: - logging.error("%s exited with non-zero result code %d" % (proc[0], result)) - return result - - -def IsLinux(): - return sys.platform.startswith('linux') - - -def IsMac(): - return sys.platform.startswith('darwin') - - -def IsWindows(): - return sys.platform == 'cygwin' or sys.platform.startswith('win') - - -def WindowsVersionName(): - """Returns the name of the Windows version if it is known, or None. - - Possible return values are: xp, vista, 7, 8, or None - """ - if sys.platform == 'cygwin': - # Windows version number is hiding in system name. Looks like: - # CYGWIN_NT-6.1-WOW64 - try: - version_str = platform.uname()[0].split('-')[1] - except: - return None - elif sys.platform.startswith('win'): - # Normal Windows version string. Mine: 6.1.7601 - version_str = platform.version() - else: - return None - - parts = version_str.split('.') - try: - major = int(parts[0]) - minor = int(parts[1]) - except: - return None # Can't parse, unknown version. - - if major == 5: - return 'xp' - elif major == 6 and minor == 0: - return 'vista' - elif major == 6 and minor == 1: - return '7' - elif major == 6 and minor == 2: - return '8' # Future proof. ;) - return None - - -def PlatformNames(): - """Return an array of string to be used in paths for the platform - (e.g. suppressions, gtest filters, ignore files etc.) - The first element of the array describes the 'main' platform - """ - if IsLinux(): - return ['linux'] - if IsMac(): - return ['mac'] - if IsWindows(): - names = ['win32'] - version_name = WindowsVersionName() - if version_name is not None: - names.append('win-%s' % version_name) - return names - raise NotImplementedError('Unknown platform "%s".' % sys.platform) - - -def PutEnvAndLog(env_name, env_value): - os.putenv(env_name, env_value) - logging.info('export %s=%s', env_name, env_value) - -def BoringCallers(mangled, use_re_wildcards): - """Return a list of 'boring' function names (optinally mangled) - with */? wildcards (optionally .*/.). - Boring = we drop off the bottom of stack traces below such functions. - """ - - need_mangling = [ - # Don't show our testing framework: - ("testing::Test::Run", "_ZN7testing4Test3RunEv"), - ("testing::TestInfo::Run", "_ZN7testing8TestInfo3RunEv"), - ("testing::internal::Handle*ExceptionsInMethodIfSupported*", - "_ZN7testing8internal3?Handle*ExceptionsInMethodIfSupported*"), - - # Depend on scheduling: - ("MessageLoop::Run", "_ZN11MessageLoop3RunEv"), - ("MessageLoop::RunTask", "_ZN11MessageLoop7RunTask*"), - ("RunnableMethod*", "_ZN14RunnableMethod*"), - ("DispatchToMethod*", "_Z*16DispatchToMethod*"), - ("base::internal::Invoker*::DoInvoke*", - "_ZN4base8internal8Invoker*DoInvoke*"), # Invoker{1,2,3} - ("base::internal::RunnableAdapter*::Run*", - "_ZN4base8internal15RunnableAdapter*Run*"), - ] - - ret = [] - for pair in need_mangling: - ret.append(pair[1 if mangled else 0]) - - ret += [ - # Also don't show the internals of libc/pthread. - "start_thread", - "main", - "BaseThreadInitThunk", - ] - - if use_re_wildcards: - for i in range(0, len(ret)): - ret[i] = ret[i].replace('*', '.*').replace('?', '.') - - return ret - -def NormalizeWindowsPath(path): - """If we're using Cygwin Python, turn the path into a Windows path. - - Don't turn forward slashes into backslashes for easier copy-pasting and - escaping. - - TODO(rnk): If we ever want to cut out the subprocess invocation, we can use - _winreg to get the root Cygwin directory from the registry key: - HKEY_LOCAL_MACHINE\SOFTWARE\Cygwin\setup\rootdir. - """ - if sys.platform.startswith("cygwin"): - p = subprocess.Popen(["cygpath", "-m", path], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - (out, err) = p.communicate() - if err: - logging.warning("WARNING: cygpath error: %s", err) - return out.strip() - else: - return path - -############################ -# Common output format code - -def PrintUsedSuppressionsList(suppcounts): - """ Prints out the list of used suppressions in a format common to all the - memory tools. If the list is empty, prints nothing and returns False, - otherwise True. - - suppcounts: a dictionary of used suppression counts, - Key -> name, Value -> count. - """ - if not suppcounts: - return False - - print "-----------------------------------------------------" - print "Suppressions used:" - print " count name" - for (name, count) in sorted(suppcounts.items(), key=lambda (k,v): (v,k)): - print "%7d %s" % (count, name) - print "-----------------------------------------------------" - sys.stdout.flush() - return True diff --git a/libs/libyuv/tools_libyuv/valgrind/gdb_helper.py b/libs/libyuv/tools_libyuv/valgrind/gdb_helper.py deleted file mode 100644 index d127f76008..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/gdb_helper.py +++ /dev/null @@ -1,91 +0,0 @@ -# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -''' A bunch of helper functions for querying gdb.''' - -import logging -import os -import re -import tempfile - -GDB_LINE_RE = re.compile(r'Line ([0-9]*) of "([^"]*)".*') - -def _GdbOutputToFileLine(output_line): - ''' Parse the gdb output line, return a pair (file, line num) ''' - match = GDB_LINE_RE.match(output_line) - if match: - return match.groups()[1], match.groups()[0] - else: - return None - -def ResolveAddressesWithinABinary(binary_name, load_address, address_list): - ''' For each address, return a pair (file, line num) ''' - commands = tempfile.NamedTemporaryFile() - commands.write('add-symbol-file "%s" %s\n' % (binary_name, load_address)) - for addr in address_list: - commands.write('info line *%s\n' % addr) - commands.write('quit\n') - commands.flush() - gdb_commandline = 'gdb -batch -x %s 2>/dev/null' % commands.name - gdb_pipe = os.popen(gdb_commandline) - result = gdb_pipe.readlines() - - address_count = 0 - ret = {} - for line in result: - if line.startswith('Line'): - ret[address_list[address_count]] = _GdbOutputToFileLine(line) - address_count += 1 - if line.startswith('No line'): - ret[address_list[address_count]] = (None, None) - address_count += 1 - gdb_pipe.close() - commands.close() - return ret - -class AddressTable(object): - ''' Object to do batched line number lookup. ''' - def __init__(self): - self._load_addresses = {} - self._binaries = {} - self._all_resolved = False - - def AddBinaryAt(self, binary, load_address): - ''' Register a new shared library or executable. ''' - self._load_addresses[binary] = load_address - - def Add(self, binary, address): - ''' Register a lookup request. ''' - if binary == '': - logging.warn('adding address %s in empty binary?' % address) - if binary in self._binaries: - self._binaries[binary].append(address) - else: - self._binaries[binary] = [address] - self._all_resolved = False - - def ResolveAll(self): - ''' Carry out all lookup requests. ''' - self._translation = {} - for binary in self._binaries.keys(): - if binary != '' and binary in self._load_addresses: - load_address = self._load_addresses[binary] - addr = ResolveAddressesWithinABinary( - binary, load_address, self._binaries[binary]) - self._translation[binary] = addr - self._all_resolved = True - - def GetFileLine(self, binary, addr): - ''' Get the (filename, linenum) result of a previously-registered lookup - request. - ''' - if self._all_resolved: - if binary in self._translation: - if addr in self._translation[binary]: - return self._translation[binary][addr] - return (None, None) diff --git a/libs/libyuv/tools_libyuv/valgrind/libyuv_tests.bat b/libs/libyuv/tools_libyuv/valgrind/libyuv_tests.bat deleted file mode 100644 index 5fceca6762..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/libyuv_tests.bat +++ /dev/null @@ -1,79 +0,0 @@ -@echo off -:: Copyright (c) 2012 The LibYuv Project Authors. All rights reserved. -:: -:: Use of this source code is governed by a BSD-style license -:: that can be found in the LICENSE file in the root of the source -:: tree. An additional intellectual property rights grant can be found -:: in the file PATENTS. All contributing project authors may -:: be found in the AUTHORS file in the root of the source tree. - -:: This script is a copy of chrome_tests.bat with the following changes: -:: - Invokes libyuv_tests.py instead of chrome_tests.py -:: - Chromium's Valgrind scripts directory is added to the PYTHONPATH to make -:: it possible to execute the Python scripts properly. - -:: TODO(timurrrr): batch files 'export' all the variables to the parent shell -set THISDIR=%~dp0 -set TOOL_NAME="unknown" - -:: Get the tool name and put it into TOOL_NAME {{{1 -:: NB: SHIFT command doesn't modify %* -:PARSE_ARGS_LOOP - if %1 == () GOTO:TOOLNAME_NOT_FOUND - if %1 == --tool GOTO:TOOLNAME_FOUND - SHIFT - goto :PARSE_ARGS_LOOP - -:TOOLNAME_NOT_FOUND -echo "Please specify a tool (tsan or drmemory) by using --tool flag" -exit /B 1 - -:TOOLNAME_FOUND -SHIFT -set TOOL_NAME=%1 -:: }}} -if "%TOOL_NAME%" == "drmemory" GOTO :SETUP_DRMEMORY -if "%TOOL_NAME%" == "drmemory_light" GOTO :SETUP_DRMEMORY -if "%TOOL_NAME%" == "drmemory_full" GOTO :SETUP_DRMEMORY -if "%TOOL_NAME%" == "drmemory_pattern" GOTO :SETUP_DRMEMORY -if "%TOOL_NAME%" == "tsan" GOTO :SETUP_TSAN -echo "Unknown tool: `%TOOL_NAME%`! Only tsan and drmemory are supported." -exit /B 1 - -:SETUP_DRMEMORY -if NOT "%DRMEMORY_COMMAND%"=="" GOTO :RUN_TESTS -:: Set up DRMEMORY_COMMAND to invoke Dr. Memory {{{1 -set DRMEMORY_PATH=%THISDIR%..\..\third_party\drmemory -set DRMEMORY_SFX=%DRMEMORY_PATH%\drmemory-windows-sfx.exe -if EXIST %DRMEMORY_SFX% GOTO DRMEMORY_BINARY_OK -echo "Can't find Dr. Memory executables." -echo "See http://www.chromium.org/developers/how-tos/using-valgrind/dr-memory" -echo "for the instructions on how to get them." -exit /B 1 - -:DRMEMORY_BINARY_OK -%DRMEMORY_SFX% -o%DRMEMORY_PATH%\unpacked -y -set DRMEMORY_COMMAND=%DRMEMORY_PATH%\unpacked\bin\drmemory.exe -:: }}} -goto :RUN_TESTS - -:SETUP_TSAN -:: Set up PIN_COMMAND to invoke TSan {{{1 -set TSAN_PATH=%THISDIR%..\..\third_party\tsan -set TSAN_SFX=%TSAN_PATH%\tsan-x86-windows-sfx.exe -if EXIST %TSAN_SFX% GOTO TSAN_BINARY_OK -echo "Can't find ThreadSanitizer executables." -echo "See http://www.chromium.org/developers/how-tos/using-valgrind/threadsanitizer/threadsanitizer-on-windows" -echo "for the instructions on how to get them." -exit /B 1 - -:TSAN_BINARY_OK -%TSAN_SFX% -o%TSAN_PATH%\unpacked -y -set PIN_COMMAND=%TSAN_PATH%\unpacked\tsan-x86-windows\tsan.bat -:: }}} -goto :RUN_TESTS - -:RUN_TESTS -set PYTHONPATH=%THISDIR%..\python\google;%THISDIR%..\valgrind -set RUNNING_ON_VALGRIND=yes -python %THISDIR%libyuv_tests.py %* diff --git a/libs/libyuv/tools_libyuv/valgrind/libyuv_tests.py b/libs/libyuv/tools_libyuv/valgrind/libyuv_tests.py deleted file mode 100755 index e780bd95eb..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/libyuv_tests.py +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2012 The LibYuv Project Authors. All rights reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -"""Runs various libyuv tests through valgrind_test.py. - -This script inherits the chrome_tests.py in Chrome, but allows running any test -instead of only the hard-coded ones. It uses the -t cmdline flag to do this, and -only supports specifying a single test for each run. - -Suppression files: -The Chrome valgrind directory we use as a DEPS dependency contains the following -suppression files: - valgrind/memcheck/suppressions.txt - valgrind/memcheck/suppressions_mac.txt - valgrind/tsan/suppressions.txt - valgrind/tsan/suppressions_mac.txt - valgrind/tsan/suppressions_win32.txt -Since they're referenced from the chrome_tests.py script, we have similar files -below the directory of this script. When executing, this script will setup both -Chrome's suppression files and our own, so we can easily maintain libyuv -specific suppressions in our own files. -""" - -import logging -import optparse -import os -import sys - -import logging_utils -import path_utils - -import chrome_tests - - -class LibyuvTest(chrome_tests.ChromeTests): - """Class that handles setup of suppressions for libyuv. - - Everything else is inherited from chrome_tests.ChromeTests. - """ - - def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None): - """Override command-building method so we can add more suppressions.""" - cmd = chrome_tests.ChromeTests._DefaultCommand(self, tool, exe, - valgrind_test_args) - # When ChromeTests._DefaultCommand has executed, it has setup suppression - # files based on what's found in the memcheck/ or tsan/ subdirectories of - # this script's location. If Mac or Windows is executing, additional - # platform specific files have also been added. - # Since only the ones located below this directory is added, we must also - # add the ones maintained by Chrome, located in ../../tools/valgrind. - - # The idea is to look for --suppression arguments in the cmd list and add a - # modified copy of each suppression file, for the corresponding file in - # ../../tools/valgrind. - script_dir = path_utils.ScriptDir() - old_base, _ = os.path.split(script_dir) - - checkout_src = os.path.abspath(os.path.join(script_dir, os.pardir, - os.pardir)) - new_dir = os.path.join(checkout_src, 'tools', 'valgrind') - add_suppressions = [] - for token in cmd: - if '--suppressions' in token: - add_suppressions.append(token.replace(script_dir, new_dir)) - return add_suppressions + cmd - - -def main(_): - parser = optparse.OptionParser('usage: %prog -b -t ') - parser.disable_interspersed_args() - parser.add_option('-b', '--build-dir', - help=('Location of the compiler output. Can only be used ' - 'when the test argument does not contain this path.')) - parser.add_option("--target", help="Debug or Release") - parser.add_option('-t', '--test', help='Test to run.') - parser.add_option('', '--baseline', action='store_true', default=False, - help='Generate baseline data instead of validating') - parser.add_option('', '--gtest_filter', - help='Additional arguments to --gtest_filter') - parser.add_option('', '--gtest_repeat', - help='Argument for --gtest_repeat') - parser.add_option("--gtest_shuffle", action="store_true", default=False, - help="Randomize tests' orders on every iteration.") - parser.add_option("--gtest_break_on_failure", action="store_true", - default=False, - help="Drop in to debugger on assertion failure. Also " - "useful for forcing tests to exit with a stack dump " - "on the first assertion failure when running with " - "--gtest_repeat=-1") - parser.add_option('-v', '--verbose', action='store_true', default=False, - help='Verbose output - enable debug log messages') - parser.add_option('', '--tool', dest='valgrind_tool', default='memcheck', - help='Specify a valgrind tool to run the tests under') - parser.add_option('', '--tool_flags', dest='valgrind_tool_flags', default='', - help='Specify custom flags for the selected valgrind tool') - parser.add_option('', '--keep_logs', action='store_true', default=False, - help=('Store memory tool logs in the .logs directory ' - 'instead of /tmp.\nThis can be useful for tool ' - 'developers/maintainers.\nPlease note that the ' - '.logs directory will be clobbered on tool startup.')) - parser.add_option("--test-launcher-bot-mode", action="store_true", - help="run the tests with --test-launcher-bot-mode") - parser.add_option("--test-launcher-total-shards", type=int, - help="run the tests with --test-launcher-total-shards") - parser.add_option("--test-launcher-shard-index", type=int, - help="run the tests with --test-launcher-shard-index") - options, args = parser.parse_args() - - if options.verbose: - logging_utils.config_root(logging.DEBUG) - else: - logging_utils.config_root() - - if not options.test: - parser.error('--test not specified') - - # Support build dir both with and without the target. - if (options.target and options.build_dir and - not options.build_dir.endswith(options.target)): - options.build_dir = os.path.join(options.build_dir, options.target) - - # If --build_dir is provided, prepend it to the test executable if needed. - test_executable = options.test - if options.build_dir and not test_executable.startswith(options.build_dir): - test_executable = os.path.join(options.build_dir, test_executable) - args = [test_executable] + args - - test = LibyuvTest(options, args, 'cmdline') - return test.Run() - -if __name__ == '__main__': - return_code = main(sys.argv) - sys.exit(return_code) diff --git a/libs/libyuv/tools_libyuv/valgrind/libyuv_tests.sh b/libs/libyuv/tools_libyuv/valgrind/libyuv_tests.sh deleted file mode 100755 index 249032ca96..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/libyuv_tests.sh +++ /dev/null @@ -1,101 +0,0 @@ -#!/bin/bash -# Copyright (c) 2012 The LibYuv Project Authors. All rights reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -# Set up some paths and re-direct the arguments to libyuv_tests.py - -# This script is a copy of the chrome_tests.sh wrapper script with the following -# changes: -# - The locate_valgrind.sh of Chromium's Valgrind scripts dir is used to locate -# the Valgrind framework install. If it fails a fallback path is used instead -# (../../chromium/src/third_party/valgrind/linux_x64) and a warning message -# is showed by |show_locate_valgrind_failed_warning|. -# - libyuv_tests.py is invoked instead of chrome_tests.py. -# - Chromium's Valgrind scripts directory is added to the PYTHONPATH to make it -# possible to execute the Python scripts properly. - -export THISDIR=`dirname $0` -ARGV_COPY="$@" - -# We need to set CHROME_VALGRIND iff using Memcheck: -# tools_libyuv/valgrind/libyuv_tests.sh --tool memcheck -# or -# tools_libyuv/valgrind/libyuv_tests.sh --tool=memcheck -tool="memcheck" # Default to memcheck. -while (( "$#" )) -do - if [[ "$1" == "--tool" ]] - then - tool="$2" - shift - elif [[ "$1" =~ --tool=(.*) ]] - then - tool="${BASH_REMATCH[1]}" - fi - shift -done - -NEEDS_VALGRIND=0 - -case "$tool" in - "memcheck") - NEEDS_VALGRIND=1 - ;; -esac - -# For libyuv, we'll use the locate_valgrind.sh script in Chromium's Valgrind -# scripts dir to locate the Valgrind framework install -CHROME_VALGRIND_SCRIPTS=$THISDIR/../../tools/valgrind - -if [ "$NEEDS_VALGRIND" == "1" ] -then - CHROME_VALGRIND=`sh $THISDIR/locate_valgrind.sh` - if [ "$CHROME_VALGRIND" = "" ] - then - CHROME_VALGRIND=../../src/third_party/valgrind/linux_x64 - echo - echo "-------------------- WARNING ------------------------" - echo "locate_valgrind.sh failed." - echo "Using $CHROME_VALGRIND as a fallback location." - echo "This might be because:" - echo "1) This is a swarming bot" - echo "2) You haven't set up the valgrind binaries correctly." - echo "In this case, please make sure you have followed the instructions at" - echo "http://www.chromium.org/developers/how-tos/using-valgrind/get-valgrind" - echo "Notice: In the .gclient file, you need to add this for the 'libyuv'" - echo "solution since our directory structure is different from Chromium's:" - echo "\"custom_deps\": {" - echo " \"libyuv/third_party/valgrind\":" - echo " \"https://chromium.googlesource.com/chromium/deps/valgrind/binaries\"," - echo "}," - echo "-----------------------------------------------------" - echo - fi - echo "Using valgrind binaries from ${CHROME_VALGRIND}" - - PATH="${CHROME_VALGRIND}/bin:$PATH" - # We need to set these variables to override default lib paths hard-coded into - # Valgrind binary. - export VALGRIND_LIB="$CHROME_VALGRIND/lib/valgrind" - export VALGRIND_LIB_INNER="$CHROME_VALGRIND/lib/valgrind" - - # Clean up some /tmp directories that might be stale due to interrupted - # chrome_tests.py execution. - # FYI: - # -mtime +1 <- only print files modified more than 24h ago, - # -print0/-0 are needed to handle possible newlines in the filenames. - echo "Cleanup /tmp from Valgrind stuff" - find /tmp -maxdepth 1 \(\ - -name "vgdb-pipe-*" -or -name "vg_logs_*" -or -name "valgrind.*" \ - \) -mtime +1 -print0 | xargs -0 rm -rf -fi - -# Add Chrome's Valgrind scripts dir to the PYTHON_PATH since it contains -# the scripts that are needed for this script to run -PYTHONPATH=$THISDIR/../../tools/python/google:$CHROME_VALGRIND_SCRIPTS python \ - "$THISDIR/libyuv_tests.py" $ARGV_COPY diff --git a/libs/libyuv/tools_libyuv/valgrind/locate_valgrind.sh b/libs/libyuv/tools_libyuv/valgrind/locate_valgrind.sh deleted file mode 100755 index d9594f4848..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/locate_valgrind.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -# Prints a path to Valgrind binaries to be used for Chromium. -# Select the valgrind from third_party/valgrind by default, -# but allow users to override this default without editing scripts and -# without specifying a commandline option - -export THISDIR=`dirname $0` - -# User may use their own valgrind by giving its path with CHROME_VALGRIND env. -if [ "$CHROME_VALGRIND" = "" ] -then - # Guess which binaries we should use by uname - case "$(uname -a)" in - *Linux*x86_64*) - PLATFORM="linux_x64" - ;; - *Linux*86*) - PLATFORM="linux_x86" - ;; - *Darwin*9.[678].[01]*i386*) - # Didn't test other kernels. - PLATFORM="mac" - ;; - *Darwin*10.[0-9].[0-9]*i386*) - PLATFORM="mac_10.6" - ;; - *Darwin*10.[0-9].[0-9]*x86_64*) - PLATFORM="mac_10.6" - ;; - *Darwin*11.[0-9].[0-9]*x86_64*) - PLATFORM="mac_10.7" - ;; - *) - (echo "Sorry, your platform is not supported:" && - uname -a - echo - echo "If you're on Mac OS X, please see http://crbug.com/441425") >&2 - exit 42 - esac - - # The binaries should be in third_party/valgrind - # (checked out from deps/third_party/valgrind/binaries). - CHROME_VALGRIND="$THISDIR/../../third_party/valgrind/$PLATFORM" - - # TODO(timurrrr): readlink -f is not present on Mac... - if [ "$PLATFORM" != "mac" ] && \ - [ "$PLATFORM" != "mac_10.6" ] && \ - [ "$PLATFORM" != "mac_10.7" ] - then - # Get rid of all "../" dirs - CHROME_VALGRIND=$(readlink -f $CHROME_VALGRIND) - fi -fi - -if ! test -x $CHROME_VALGRIND/bin/valgrind -then - echo "Oops, could not find Valgrind binaries in your checkout." >&2 - echo "Please see" >&2 - echo " http://dev.chromium.org/developers/how-tos/using-valgrind/get-valgrind" >&2 - echo "for the instructions on how to download pre-built binaries." >&2 - exit 1 -fi - -echo $CHROME_VALGRIND diff --git a/libs/libyuv/tools_libyuv/valgrind/memcheck/OWNERS b/libs/libyuv/tools_libyuv/valgrind/memcheck/OWNERS deleted file mode 100644 index 72e8ffc0db..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/memcheck/OWNERS +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/libs/libyuv/tools_libyuv/valgrind/memcheck/PRESUBMIT.py b/libs/libyuv/tools_libyuv/valgrind/memcheck/PRESUBMIT.py deleted file mode 100644 index 033292148d..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/memcheck/PRESUBMIT.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2012 The LibYuv Project Authors. All rights reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -""" -Copied from Chrome's src/tools/valgrind/memcheck/PRESUBMIT.py - -See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts -for more details on the presubmit API built into gcl. -""" - -import os -import re -import sys - -def CheckChange(input_api, output_api): - """Checks the memcheck suppressions files for bad data.""" - - # Add the path to the Chrome valgrind dir to the import path: - tools_vg_path = os.path.join(input_api.PresubmitLocalPath(), '..', '..', '..', - 'tools', 'valgrind') - sys.path.append(tools_vg_path) - import suppressions - - sup_regex = re.compile('suppressions.*\.txt$') - suppressions = {} - errors = [] - check_for_memcheck = False - # skip_next_line has 3 possible values: - # - False: don't skip the next line. - # - 'skip_suppression_name': the next line is a suppression name, skip. - # - 'skip_param': the next line is a system call parameter error, skip. - skip_next_line = False - for f in filter(lambda x: sup_regex.search(x.LocalPath()), - input_api.AffectedFiles()): - for line, line_num in zip(f.NewContents(), - xrange(1, len(f.NewContents()) + 1)): - line = line.lstrip() - if line.startswith('#') or not line: - continue - - if skip_next_line: - if skip_next_line == 'skip_suppression_name': - if 'insert_a_suppression_name_here' in line: - errors.append('"insert_a_suppression_name_here" is not a valid ' - 'suppression name') - if suppressions.has_key(line): - if f.LocalPath() == suppressions[line][1]: - errors.append('suppression with name "%s" at %s line %s ' - 'has already been defined at line %s' % - (line, f.LocalPath(), line_num, - suppressions[line][1])) - else: - errors.append('suppression with name "%s" at %s line %s ' - 'has already been defined at %s line %s' % - (line, f.LocalPath(), line_num, - suppressions[line][0], suppressions[line][1])) - else: - suppressions[line] = (f, line_num) - check_for_memcheck = True; - skip_next_line = False - continue - if check_for_memcheck: - if not line.startswith('Memcheck:'): - errors.append('"%s" should be "Memcheck:..." in %s line %s' % - (line, f.LocalPath(), line_num)) - check_for_memcheck = False; - if line == '{': - skip_next_line = 'skip_suppression_name' - continue - if line == "Memcheck:Param": - skip_next_line = 'skip_param' - continue - - if (line.startswith('fun:') or line.startswith('obj:') or - line.startswith('Memcheck:') or line == '}' or - line == '...'): - continue - errors.append('"%s" is probably wrong: %s line %s' % (line, f.LocalPath(), - line_num)) - if errors: - return [output_api.PresubmitError('\n'.join(errors))] - return [] - -def CheckChangeOnUpload(input_api, output_api): - return CheckChange(input_api, output_api) - -def CheckChangeOnCommit(input_api, output_api): - return CheckChange(input_api, output_api) - -def GetPreferredTrySlaves(): - # We don't have any memcheck slaves yet, so there's no use for this method. - # When we have, the slave name(s) should be put into this list. - return [] diff --git a/libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions.txt b/libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions.txt deleted file mode 100644 index 3f0f6d44f1..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions.txt +++ /dev/null @@ -1,21 +0,0 @@ -# This file is used in addition to the one already maintained in Chrome. -# It acts as a place holder for future additions for this project. -# It must exist for the Python wrapper script to work properly. - -# There are two of suppressions in this file. -# 1. third_party libraries -# 2. libyuv stuff -# 3. libjingle stuff (talk folder) -#----------------------------------------------------------------------- - -# third_party libraries -{ - bug_729 - Memcheck:Free - fun:_ZdaPv - ... - fun:_ZN7testing8internal12UnitTestImplD1Ev - ... -} - -# libyuv (empty so far) diff --git a/libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions_mac.txt b/libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions_mac.txt deleted file mode 100644 index 3ad0c8ccc5..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions_mac.txt +++ /dev/null @@ -1,5 +0,0 @@ -# This file is used in addition to the one already maintained in Chrome. -# It acts as a place holder for future additions for this project. -# It must exist for the Python wrapper script to work properly. - - diff --git a/libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions_win32.txt b/libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions_win32.txt deleted file mode 100644 index 3ad0c8ccc5..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/memcheck/suppressions_win32.txt +++ /dev/null @@ -1,5 +0,0 @@ -# This file is used in addition to the one already maintained in Chrome. -# It acts as a place holder for future additions for this project. -# It must exist for the Python wrapper script to work properly. - - diff --git a/libs/libyuv/tools_libyuv/valgrind/memcheck_analyze.py b/libs/libyuv/tools_libyuv/valgrind/memcheck_analyze.py deleted file mode 100755 index 80e85eb4ab..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/memcheck_analyze.py +++ /dev/null @@ -1,644 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -# memcheck_analyze.py - -''' Given a valgrind XML file, parses errors and uniques them.''' - -import gdb_helper - -from collections import defaultdict -import hashlib -import logging -import optparse -import os -import re -import subprocess -import sys -import time -from xml.dom.minidom import parse -from xml.parsers.expat import ExpatError - -import common - -# Global symbol table (yuck) -TheAddressTable = None - -# These are regexps that define functions (using C++ mangled names) -# we don't want to see in stack traces while pretty printing -# or generating suppressions. -# Just stop printing the stack/suppression frames when the current one -# matches any of these. -_BORING_CALLERS = common.BoringCallers(mangled=True, use_re_wildcards=True) - -def getTextOf(top_node, name): - ''' Returns all text in all DOM nodes with a certain |name| that are children - of |top_node|. - ''' - - text = "" - for nodes_named in top_node.getElementsByTagName(name): - text += "".join([node.data for node in nodes_named.childNodes - if node.nodeType == node.TEXT_NODE]) - return text - -def getCDATAOf(top_node, name): - ''' Returns all CDATA in all DOM nodes with a certain |name| that are children - of |top_node|. - ''' - - text = "" - for nodes_named in top_node.getElementsByTagName(name): - text += "".join([node.data for node in nodes_named.childNodes - if node.nodeType == node.CDATA_SECTION_NODE]) - if (text == ""): - return None - return text - -def shortenFilePath(source_dir, directory): - '''Returns a string with the string prefix |source_dir| removed from - |directory|.''' - prefixes_to_cut = ["build/src/", "valgrind/coregrind/", "out/Release/../../"] - - if source_dir: - prefixes_to_cut.append(source_dir) - - for p in prefixes_to_cut: - index = directory.rfind(p) - if index != -1: - directory = directory[index + len(p):] - - return directory - -# Constants that give real names to the abbreviations in valgrind XML output. -INSTRUCTION_POINTER = "ip" -OBJECT_FILE = "obj" -FUNCTION_NAME = "fn" -SRC_FILE_DIR = "dir" -SRC_FILE_NAME = "file" -SRC_LINE = "line" - -def gatherFrames(node, source_dir): - frames = [] - for frame in node.getElementsByTagName("frame"): - frame_dict = { - INSTRUCTION_POINTER : getTextOf(frame, INSTRUCTION_POINTER), - OBJECT_FILE : getTextOf(frame, OBJECT_FILE), - FUNCTION_NAME : getTextOf(frame, FUNCTION_NAME), - SRC_FILE_DIR : shortenFilePath( - source_dir, getTextOf(frame, SRC_FILE_DIR)), - SRC_FILE_NAME : getTextOf(frame, SRC_FILE_NAME), - SRC_LINE : getTextOf(frame, SRC_LINE) - } - - # Ignore this frame and all the following if it's a "boring" function. - enough_frames = False - for regexp in _BORING_CALLERS: - if re.match("^%s$" % regexp, frame_dict[FUNCTION_NAME]): - enough_frames = True - break - if enough_frames: - break - - frames += [frame_dict] - - global TheAddressTable - if TheAddressTable != None and frame_dict[SRC_LINE] == "": - # Try using gdb - TheAddressTable.Add(frame_dict[OBJECT_FILE], - frame_dict[INSTRUCTION_POINTER]) - return frames - -class ValgrindError: - ''' Takes a node and reads all the data from it. A - ValgrindError is immutable and is hashed on its pretty printed output. - ''' - - def __init__(self, source_dir, error_node, commandline, testcase): - ''' Copies all the relevant information out of the DOM and into object - properties. - - Args: - error_node: The DOM node we're extracting from. - source_dir: Prefix that should be stripped from the node. - commandline: The command that was run under valgrind - testcase: The test case name, if known. - ''' - - # Valgrind errors contain one pair, plus an optional - # pair, plus an optional , - # plus (since 3.5.0) a pair. - # (Origin is nicely enclosed; too bad the other two aren't.) - # The most common way to see all three in one report is - # a syscall with a parameter that points to uninitialized memory, e.g. - # Format: - # - # 0x6d - # 1 - # SyscallParam - # Syscall param write(buf) points to uninitialised byte(s) - # - # - # ... - # - # - # Address 0x5c9af4f is 7 bytes inside a block of ... - # - # - # ... - # - # - # - # Uninitialised value was created by a heap allocation - # - # - # ... - # - # - # - # - # insert_a_suppression_name_here - # Memcheck:Param - # write(buf) - # __write_nocancel - # ... - # main - # - # - # Memcheck:Param - # write(buf) - # fun:__write_nocancel - # ... - # fun:main - # } - # ]]> - # - # - # - # - # Each frame looks like this: - # - # 0x83751BC - # /data/dkegel/chrome-build/src/out/Release/base_unittests - # _ZN7testing8internal12TestInfoImpl7RunTestEPNS_8TestInfoE - # /data/dkegel/chrome-build/src/testing/gtest/src - # gtest-internal-inl.h - # 655 - # - # although the dir, file, and line elements are missing if there is - # no debug info. - - self._kind = getTextOf(error_node, "kind") - self._backtraces = [] - self._suppression = None - self._commandline = commandline - self._testcase = testcase - self._additional = [] - - # Iterate through the nodes, parsing pairs. - description = None - for node in error_node.childNodes: - if node.localName == "what" or node.localName == "auxwhat": - description = "".join([n.data for n in node.childNodes - if n.nodeType == n.TEXT_NODE]) - elif node.localName == "xwhat": - description = getTextOf(node, "text") - elif node.localName == "stack": - assert description - self._backtraces.append([description, gatherFrames(node, source_dir)]) - description = None - elif node.localName == "origin": - description = getTextOf(node, "what") - stack = node.getElementsByTagName("stack")[0] - frames = gatherFrames(stack, source_dir) - self._backtraces.append([description, frames]) - description = None - stack = None - frames = None - elif description and node.localName != None: - # The lastest description has no stack, e.g. "Address 0x28 is unknown" - self._additional.append(description) - description = None - - if node.localName == "suppression": - self._suppression = getCDATAOf(node, "rawtext"); - - def __str__(self): - ''' Pretty print the type and backtrace(s) of this specific error, - including suppression (which is just a mangled backtrace).''' - output = "" - output += "\n" # Make sure the ### is at the beginning of line. - output += "### BEGIN MEMORY TOOL REPORT (error hash=#%016X#)\n" % \ - self.ErrorHash() - if (self._commandline): - output += self._commandline + "\n" - - output += self._kind + "\n" - for backtrace in self._backtraces: - output += backtrace[0] + "\n" - filter = subprocess.Popen("c++filt -n", stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - shell=True, - close_fds=True) - buf = "" - for frame in backtrace[1]: - buf += (frame[FUNCTION_NAME] or frame[INSTRUCTION_POINTER]) + "\n" - (stdoutbuf, stderrbuf) = filter.communicate(buf.encode('latin-1')) - demangled_names = stdoutbuf.split("\n") - - i = 0 - for frame in backtrace[1]: - output += (" " + demangled_names[i]) - i = i + 1 - - global TheAddressTable - if TheAddressTable != None and frame[SRC_FILE_DIR] == "": - # Try using gdb - foo = TheAddressTable.GetFileLine(frame[OBJECT_FILE], - frame[INSTRUCTION_POINTER]) - if foo[0] != None: - output += (" (" + foo[0] + ":" + foo[1] + ")") - elif frame[SRC_FILE_DIR] != "": - output += (" (" + frame[SRC_FILE_DIR] + "/" + frame[SRC_FILE_NAME] + - ":" + frame[SRC_LINE] + ")") - else: - output += " (" + frame[OBJECT_FILE] + ")" - output += "\n" - - for additional in self._additional: - output += additional + "\n" - - assert self._suppression != None, "Your Valgrind doesn't generate " \ - "suppressions - is it too old?" - - if self._testcase: - output += "The report came from the `%s` test.\n" % self._testcase - output += "Suppression (error hash=#%016X#):\n" % self.ErrorHash() - output += (" For more info on using suppressions see " - "http://dev.chromium.org/developers/tree-sheriffs/sheriff-details-chromium/memory-sheriff#TOC-Suppressing-memory-reports") - - # Widen suppression slightly to make portable between mac and linux - # TODO(timurrrr): Oops, these transformations should happen - # BEFORE calculating the hash! - supp = self._suppression; - supp = supp.replace("fun:_Znwj", "fun:_Znw*") - supp = supp.replace("fun:_Znwm", "fun:_Znw*") - supp = supp.replace("fun:_Znaj", "fun:_Zna*") - supp = supp.replace("fun:_Znam", "fun:_Zna*") - - # Make suppressions even less platform-dependent. - for sz in [1, 2, 4, 8]: - supp = supp.replace("Memcheck:Addr%d" % sz, "Memcheck:Unaddressable") - supp = supp.replace("Memcheck:Value%d" % sz, "Memcheck:Uninitialized") - supp = supp.replace("Memcheck:Cond", "Memcheck:Uninitialized") - - # Split into lines so we can enforce length limits - supplines = supp.split("\n") - supp = None # to avoid re-use - - # Truncate at line 26 (VG_MAX_SUPP_CALLERS plus 2 for name and type) - # or at the first 'boring' caller. - # (https://bugs.kde.org/show_bug.cgi?id=199468 proposes raising - # VG_MAX_SUPP_CALLERS, but we're probably fine with it as is.) - newlen = min(26, len(supplines)); - - # Drop boring frames and all the following. - enough_frames = False - for frameno in range(newlen): - for boring_caller in _BORING_CALLERS: - if re.match("^ +fun:%s$" % boring_caller, supplines[frameno]): - newlen = frameno - enough_frames = True - break - if enough_frames: - break - if (len(supplines) > newlen): - supplines = supplines[0:newlen] - supplines.append("}") - - for frame in range(len(supplines)): - # Replace the always-changing anonymous namespace prefix with "*". - m = re.match("( +fun:)_ZN.*_GLOBAL__N_.*\.cc_" + - "[0-9a-fA-F]{8}_[0-9a-fA-F]{8}(.*)", - supplines[frame]) - if m: - supplines[frame] = "*".join(m.groups()) - - output += "\n".join(supplines) + "\n" - output += "### END MEMORY TOOL REPORT (error hash=#%016X#)\n" % \ - self.ErrorHash() - - return output - - def UniqueString(self): - ''' String to use for object identity. Don't print this, use str(obj) - instead.''' - rep = self._kind + " " - for backtrace in self._backtraces: - for frame in backtrace[1]: - rep += frame[FUNCTION_NAME] - - if frame[SRC_FILE_DIR] != "": - rep += frame[SRC_FILE_DIR] + "/" + frame[SRC_FILE_NAME] - else: - rep += frame[OBJECT_FILE] - - return rep - - # This is a device-independent hash identifying the suppression. - # By printing out this hash we can find duplicate reports between tests and - # different shards running on multiple buildbots - def ErrorHash(self): - return int(hashlib.md5(self.UniqueString()).hexdigest()[:16], 16) - - def __hash__(self): - return hash(self.UniqueString()) - def __eq__(self, rhs): - return self.UniqueString() == rhs - -def log_is_finished(f, force_finish): - f.seek(0) - prev_line = "" - while True: - line = f.readline() - if line == "": - if not force_finish: - return False - # Okay, the log is not finished but we can make it up to be parseable: - if prev_line.strip() in ["", "", ""]: - f.write("\n") - return True - return False - if '' in line: - # Valgrind often has garbage after upon crash. - f.truncate() - return True - prev_line = line - -class MemcheckAnalyzer: - ''' Given a set of Valgrind XML files, parse all the errors out of them, - unique them and output the results.''' - - SANITY_TEST_SUPPRESSIONS = { - "Memcheck sanity test 01 (memory leak).": 1, - "Memcheck sanity test 02 (malloc/read left).": 1, - "Memcheck sanity test 03 (malloc/read right).": 1, - "Memcheck sanity test 04 (malloc/write left).": 1, - "Memcheck sanity test 05 (malloc/write right).": 1, - "Memcheck sanity test 06 (new/read left).": 1, - "Memcheck sanity test 07 (new/read right).": 1, - "Memcheck sanity test 08 (new/write left).": 1, - "Memcheck sanity test 09 (new/write right).": 1, - "Memcheck sanity test 10 (write after free).": 1, - "Memcheck sanity test 11 (write after delete).": 1, - "Memcheck sanity test 12 (array deleted without []).": 1, - "Memcheck sanity test 13 (single element deleted with []).": 1, - "Memcheck sanity test 14 (malloc/read uninit).": 1, - "Memcheck sanity test 15 (new/read uninit).": 1, - } - - # Max time to wait for memcheck logs to complete. - LOG_COMPLETION_TIMEOUT = 180.0 - - def __init__(self, source_dir, show_all_leaks=False, use_gdb=False): - '''Create a parser for Memcheck logs. - - Args: - source_dir: Path to top of source tree for this build - show_all_leaks: Whether to show even less important leaks - use_gdb: Whether to use gdb to resolve source filenames and line numbers - in the report stacktraces - ''' - self._source_dir = source_dir - self._show_all_leaks = show_all_leaks - self._use_gdb = use_gdb - - # Contains the set of unique errors - self._errors = set() - - # Contains the time when the we started analyzing the first log file. - # This variable is used to skip incomplete logs after some timeout. - self._analyze_start_time = None - - - def Report(self, files, testcase, check_sanity=False): - '''Reads in a set of files and prints Memcheck report. - - Args: - files: A list of filenames. - check_sanity: if true, search for SANITY_TEST_SUPPRESSIONS - ''' - # Beyond the detailed errors parsed by ValgrindError above, - # the xml file contain records describing suppressions that were used: - # - # - # 28 - # pango_font_leak_todo - # - # - # 378 - # bug_13243 - # - # /usr/lib/libgcc_s.1.dylib0x27000 - # giving the filename and load address of each binary that was mapped - # into the process. - - global TheAddressTable - if self._use_gdb: - TheAddressTable = gdb_helper.AddressTable() - else: - TheAddressTable = None - cur_report_errors = set() - suppcounts = defaultdict(int) - badfiles = set() - - if self._analyze_start_time == None: - self._analyze_start_time = time.time() - start_time = self._analyze_start_time - - parse_failed = False - for file in files: - # Wait up to three minutes for valgrind to finish writing all files, - # but after that, just skip incomplete files and warn. - f = open(file, "r+") - pid = re.match(".*\.([0-9]+)$", file) - if pid: - pid = pid.groups()[0] - found = False - running = True - firstrun = True - skip = False - origsize = os.path.getsize(file) - while (running and not found and not skip and - (firstrun or - ((time.time() - start_time) < self.LOG_COMPLETION_TIMEOUT))): - firstrun = False - f.seek(0) - if pid: - # Make sure the process is still running so we don't wait for - # 3 minutes if it was killed. See http://crbug.com/17453 - ps_out = subprocess.Popen("ps p %s" % pid, shell=True, - stdout=subprocess.PIPE).stdout - if len(ps_out.readlines()) < 2: - running = False - else: - skip = True - running = False - found = log_is_finished(f, False) - if not running and not found: - logging.warn("Valgrind process PID = %s is not running but its " - "XML log has not been finished correctly.\n" - "Make it up by adding some closing tags manually." % pid) - found = log_is_finished(f, not running) - if running and not found: - time.sleep(1) - f.close() - if not found: - badfiles.add(file) - else: - newsize = os.path.getsize(file) - if origsize > newsize+1: - logging.warn(str(origsize - newsize) + - " bytes of junk were after in %s!" % - file) - try: - parsed_file = parse(file); - except ExpatError, e: - parse_failed = True - logging.warn("could not parse %s: %s" % (file, e)) - lineno = e.lineno - 1 - context_lines = 5 - context_start = max(0, lineno - context_lines) - context_end = lineno + context_lines + 1 - context_file = open(file, "r") - for i in range(0, context_start): - context_file.readline() - for i in range(context_start, context_end): - context_data = context_file.readline().rstrip() - if i != lineno: - logging.warn(" %s" % context_data) - else: - logging.warn("> %s" % context_data) - context_file.close() - continue - if TheAddressTable != None: - load_objs = parsed_file.getElementsByTagName("load_obj") - for load_obj in load_objs: - obj = getTextOf(load_obj, "obj") - ip = getTextOf(load_obj, "ip") - TheAddressTable.AddBinaryAt(obj, ip) - - commandline = None - preamble = parsed_file.getElementsByTagName("preamble")[0]; - for node in preamble.getElementsByTagName("line"): - if node.localName == "line": - for x in node.childNodes: - if x.nodeType == node.TEXT_NODE and "Command" in x.data: - commandline = x.data - break - - raw_errors = parsed_file.getElementsByTagName("error") - for raw_error in raw_errors: - # Ignore "possible" leaks for now by default. - if (self._show_all_leaks or - getTextOf(raw_error, "kind") != "Leak_PossiblyLost"): - error = ValgrindError(self._source_dir, - raw_error, commandline, testcase) - if error not in cur_report_errors: - # We haven't seen such errors doing this report yet... - if error in self._errors: - # ... but we saw it in earlier reports, e.g. previous UI test - cur_report_errors.add("This error was already printed in " - "some other test, see 'hash=#%016X#'" % \ - error.ErrorHash()) - else: - # ... and we haven't seen it in other tests as well - self._errors.add(error) - cur_report_errors.add(error) - - suppcountlist = parsed_file.getElementsByTagName("suppcounts") - if len(suppcountlist) > 0: - suppcountlist = suppcountlist[0] - for node in suppcountlist.getElementsByTagName("pair"): - count = getTextOf(node, "count"); - name = getTextOf(node, "name"); - suppcounts[name] += int(count) - - if len(badfiles) > 0: - logging.warn("valgrind didn't finish writing %d files?!" % len(badfiles)) - for file in badfiles: - logging.warn("Last 20 lines of %s :" % file) - os.system("tail -n 20 '%s' 1>&2" % file) - - if parse_failed: - logging.error("FAIL! Couldn't parse Valgrind output file") - return -2 - - common.PrintUsedSuppressionsList(suppcounts) - - retcode = 0 - if cur_report_errors: - logging.error("FAIL! There were %s errors: " % len(cur_report_errors)) - - if TheAddressTable != None: - TheAddressTable.ResolveAll() - - for error in cur_report_errors: - logging.error(error) - - retcode = -1 - - # Report tool's insanity even if there were errors. - if check_sanity: - remaining_sanity_supp = MemcheckAnalyzer.SANITY_TEST_SUPPRESSIONS - for (name, count) in suppcounts.iteritems(): - # Workaround for http://crbug.com/334074 - if (name in remaining_sanity_supp and - remaining_sanity_supp[name] <= count): - del remaining_sanity_supp[name] - if remaining_sanity_supp: - logging.error("FAIL! Sanity check failed!") - logging.info("The following test errors were not handled: ") - for (name, count) in remaining_sanity_supp.iteritems(): - logging.info(" * %dx %s" % (count, name)) - retcode = -3 - - if retcode != 0: - return retcode - - logging.info("PASS! No errors found!") - return 0 - - -def _main(): - '''For testing only. The MemcheckAnalyzer class should be imported instead.''' - parser = optparse.OptionParser("usage: %prog [options] ") - parser.add_option("", "--source-dir", - help="path to top of source tree for this build" - "(used to normalize source paths in baseline)") - - (options, args) = parser.parse_args() - if len(args) == 0: - parser.error("no filename specified") - filenames = args - - analyzer = MemcheckAnalyzer(options.source_dir, use_gdb=True) - return analyzer.Report(filenames, None) - - -if __name__ == "__main__": - sys.exit(_main()) diff --git a/libs/libyuv/tools_libyuv/valgrind/valgrind.sh b/libs/libyuv/tools_libyuv/valgrind/valgrind.sh deleted file mode 100755 index 7f3f792666..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/valgrind.sh +++ /dev/null @@ -1,110 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2017 The LibYuv Project Authors. All rights reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -# This is a small script for manually launching valgrind, along with passing -# it the suppression file, and some helpful arguments (automatically attaching -# the debugger on failures, etc). Run it from your repo root, something like: -# $ sh ./tools/valgrind/valgrind.sh ./out/Debug/chrome -# -# This is mostly intended for running the chrome browser interactively. -# To run unit tests, you probably want to run chrome_tests.sh instead. -# That's the script used by the valgrind buildbot. - -export THISDIR=`dirname $0` - -setup_memcheck() { - RUN_COMMAND="valgrind" - - # Prompt to attach gdb when there was an error detected. - DEFAULT_TOOL_FLAGS=("--db-command=gdb -nw %f %p" "--db-attach=yes" \ - # Keep the registers in gdb in sync with the code. - "--vex-iropt-register-updates=allregs-at-mem-access" \ - # Overwrite newly allocated or freed objects - # with 0x41 to catch inproper use. - "--malloc-fill=41" "--free-fill=41" \ - # Increase the size of stacks being tracked. - "--num-callers=30") -} - -setup_unknown() { - echo "Unknown tool \"$TOOL_NAME\" specified, the result is not guaranteed" - DEFAULT_TOOL_FLAGS=() -} - -set -e - -if [ $# -eq 0 ]; then - echo "usage: " - exit 1 -fi - -TOOL_NAME="memcheck" -declare -a DEFAULT_TOOL_FLAGS[0] - -# Select a tool different from memcheck with --tool=TOOL as a first argument -TMP_STR=`echo $1 | sed 's/^\-\-tool=//'` -if [ "$TMP_STR" != "$1" ]; then - TOOL_NAME="$TMP_STR" - shift -fi - -if echo "$@" | grep "\-\-tool" ; then - echo "--tool=TOOL must be the first argument" >&2 - exit 1 -fi - -case $TOOL_NAME in - memcheck*) setup_memcheck "$1";; - *) setup_unknown;; -esac - - -SUPPRESSIONS="$THISDIR/$TOOL_NAME/suppressions.txt" - -CHROME_VALGRIND=`sh $THISDIR/locate_valgrind.sh` -if [ "$CHROME_VALGRIND" = "" ] -then - # locate_valgrind.sh failed - exit 1 -fi -echo "Using valgrind binaries from ${CHROME_VALGRIND}" - -set -x -PATH="${CHROME_VALGRIND}/bin:$PATH" -# We need to set these variables to override default lib paths hard-coded into -# Valgrind binary. -export VALGRIND_LIB="$CHROME_VALGRIND/lib/valgrind" -export VALGRIND_LIB_INNER="$CHROME_VALGRIND/lib/valgrind" - -# G_SLICE=always-malloc: make glib use system malloc -# NSS_DISABLE_UNLOAD=1: make nss skip dlclosing dynamically loaded modules, -# which would result in "obj:*" in backtraces. -# NSS_DISABLE_ARENA_FREE_LIST=1: make nss use system malloc -# G_DEBUG=fatal_warnings: make GTK abort on any critical or warning assertions. -# If it crashes on you in the Options menu, you hit bug 19751, -# comment out the G_DEBUG=fatal_warnings line. -# -# GTEST_DEATH_TEST_USE_FORK=1: make gtest death tests valgrind-friendly -# -# When everyone has the latest valgrind, we might want to add -# --show-possibly-lost=no -# to ignore possible but not definite leaks. - -G_SLICE=always-malloc \ -NSS_DISABLE_UNLOAD=1 \ -NSS_DISABLE_ARENA_FREE_LIST=1 \ -G_DEBUG=fatal_warnings \ -GTEST_DEATH_TEST_USE_FORK=1 \ -$RUN_COMMAND \ - --trace-children=yes \ - --leak-check=yes \ - --suppressions="$SUPPRESSIONS" \ - "${DEFAULT_TOOL_FLAGS[@]}" \ - "$@" diff --git a/libs/libyuv/tools_libyuv/valgrind/valgrind_test.py b/libs/libyuv/tools_libyuv/valgrind/valgrind_test.py deleted file mode 100755 index 0fd3d97f11..0000000000 --- a/libs/libyuv/tools_libyuv/valgrind/valgrind_test.py +++ /dev/null @@ -1,517 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -"""Runs an exe through Valgrind and puts the intermediate files in a -directory. -""" - -import datetime -import glob -import logging -import optparse -import os -import re -import shutil -import stat -import subprocess -import sys -import tempfile - -import common - -import memcheck_analyze - -class BaseTool(object): - """Abstract class for running dynamic error detection tools. - - Always subclass this and implement ToolCommand with framework- and - tool-specific stuff. - """ - - def __init__(self): - temp_parent_dir = None - self.log_parent_dir = "" - if common.IsWindows(): - # gpu process on Windows Vista+ runs at Low Integrity and can only - # write to certain directories (http://crbug.com/119131) - # - # TODO(bruening): if scripts die in middle and don't clean up temp - # dir, we'll accumulate files in profile dir. should remove - # really old files automatically. - profile = os.getenv("USERPROFILE") - if profile: - self.log_parent_dir = profile + "\\AppData\\LocalLow\\" - if os.path.exists(self.log_parent_dir): - self.log_parent_dir = common.NormalizeWindowsPath(self.log_parent_dir) - temp_parent_dir = self.log_parent_dir - # Generated every time (even when overridden) - self.temp_dir = tempfile.mkdtemp(prefix="vg_logs_", dir=temp_parent_dir) - self.log_dir = self.temp_dir # overridable by --keep_logs - self.option_parser_hooks = [] - # TODO(glider): we may not need some of the env vars on some of the - # platforms. - self._env = { - "G_SLICE" : "always-malloc", - "NSS_DISABLE_UNLOAD" : "1", - "NSS_DISABLE_ARENA_FREE_LIST" : "1", - "GTEST_DEATH_TEST_USE_FORK": "1", - } - - def ToolName(self): - raise NotImplementedError, "This method should be implemented " \ - "in the tool-specific subclass" - - def Analyze(self, check_sanity=False): - raise NotImplementedError, "This method should be implemented " \ - "in the tool-specific subclass" - - def RegisterOptionParserHook(self, hook): - # Frameworks and tools can add their own flags to the parser. - self.option_parser_hooks.append(hook) - - def CreateOptionParser(self): - # Defines Chromium-specific flags. - self._parser = optparse.OptionParser("usage: %prog [options] ") - self._parser.disable_interspersed_args() - self._parser.add_option("-t", "--timeout", - dest="timeout", metavar="TIMEOUT", default=10000, - help="timeout in seconds for the run (default 10000)") - self._parser.add_option("", "--build-dir", - help="the location of the compiler output") - self._parser.add_option("", "--source-dir", - help="path to top of source tree for this build" - "(used to normalize source paths in baseline)") - self._parser.add_option("", "--gtest_filter", default="", - help="which test case to run") - self._parser.add_option("", "--gtest_repeat", - help="how many times to run each test") - self._parser.add_option("", "--gtest_print_time", action="store_true", - default=False, - help="show how long each test takes") - self._parser.add_option("", "--ignore_exit_code", action="store_true", - default=False, - help="ignore exit code of the test " - "(e.g. test failures)") - self._parser.add_option("", "--keep_logs", action="store_true", - default=False, - help="store memory tool logs in the .logs " - "directory instead of /tmp.\nThis can be " - "useful for tool developers/maintainers.\n" - "Please note that the .logs directory " - "will be clobbered on tool startup.") - - # To add framework- or tool-specific flags, please add a hook using - # RegisterOptionParserHook in the corresponding subclass. - # See ValgrindTool for an example. - for hook in self.option_parser_hooks: - hook(self, self._parser) - - def ParseArgv(self, args): - self.CreateOptionParser() - - # self._tool_flags will store those tool flags which we don't parse - # manually in this script. - self._tool_flags = [] - known_args = [] - - """ We assume that the first argument not starting with "-" is a program - name and all the following flags should be passed to the program. - TODO(timurrrr): customize optparse instead - """ - while len(args) > 0 and args[0][:1] == "-": - arg = args[0] - if (arg == "--"): - break - if self._parser.has_option(arg.split("=")[0]): - known_args += [arg] - else: - self._tool_flags += [arg] - args = args[1:] - - if len(args) > 0: - known_args += args - - self._options, self._args = self._parser.parse_args(known_args) - - self._timeout = int(self._options.timeout) - self._source_dir = self._options.source_dir - if self._options.keep_logs: - # log_parent_dir has trailing slash if non-empty - self.log_dir = self.log_parent_dir + "%s.logs" % self.ToolName() - if os.path.exists(self.log_dir): - shutil.rmtree(self.log_dir) - os.mkdir(self.log_dir) - logging.info("Logs are in " + self.log_dir) - - self._ignore_exit_code = self._options.ignore_exit_code - if self._options.gtest_filter != "": - self._args.append("--gtest_filter=%s" % self._options.gtest_filter) - if self._options.gtest_repeat: - self._args.append("--gtest_repeat=%s" % self._options.gtest_repeat) - if self._options.gtest_print_time: - self._args.append("--gtest_print_time") - - return True - - def Setup(self, args): - return self.ParseArgv(args) - - def ToolCommand(self): - raise NotImplementedError, "This method should be implemented " \ - "in the tool-specific subclass" - - def Cleanup(self): - # You may override it in the tool-specific subclass - pass - - def Execute(self): - """ Execute the app to be tested after successful instrumentation. - Full execution command-line provided by subclassers via proc.""" - logging.info("starting execution...") - proc = self.ToolCommand() - for var in self._env: - common.PutEnvAndLog(var, self._env[var]) - return common.RunSubprocess(proc, self._timeout) - - def RunTestsAndAnalyze(self, check_sanity): - exec_retcode = self.Execute() - analyze_retcode = self.Analyze(check_sanity) - - if analyze_retcode: - logging.error("Analyze failed.") - logging.info("Search the log for '[ERROR]' to see the error reports.") - return analyze_retcode - - if exec_retcode: - if self._ignore_exit_code: - logging.info("Test execution failed, but the exit code is ignored.") - else: - logging.error("Test execution failed.") - return exec_retcode - else: - logging.info("Test execution completed successfully.") - - if not analyze_retcode: - logging.info("Analysis completed successfully.") - - return 0 - - def Main(self, args, check_sanity, min_runtime_in_seconds): - """Call this to run through the whole process: Setup, Execute, Analyze""" - start_time = datetime.datetime.now() - retcode = -1 - if self.Setup(args): - retcode = self.RunTestsAndAnalyze(check_sanity) - shutil.rmtree(self.temp_dir, ignore_errors=True) - self.Cleanup() - else: - logging.error("Setup failed") - end_time = datetime.datetime.now() - runtime_in_seconds = (end_time - start_time).seconds - hours = runtime_in_seconds / 3600 - seconds = runtime_in_seconds % 3600 - minutes = seconds / 60 - seconds = seconds % 60 - logging.info("elapsed time: %02d:%02d:%02d" % (hours, minutes, seconds)) - if (min_runtime_in_seconds > 0 and - runtime_in_seconds < min_runtime_in_seconds): - logging.error("Layout tests finished too quickly. " - "It should have taken at least %d seconds. " - "Something went wrong?" % min_runtime_in_seconds) - retcode = -1 - return retcode - - def Run(self, args, module, min_runtime_in_seconds=0): - MODULES_TO_SANITY_CHECK = ["base"] - - check_sanity = module in MODULES_TO_SANITY_CHECK - return self.Main(args, check_sanity, min_runtime_in_seconds) - - -class ValgrindTool(BaseTool): - """Abstract class for running Valgrind tools. - - Always subclass this and implement ToolSpecificFlags() and - ExtendOptionParser() for tool-specific stuff. - """ - def __init__(self): - super(ValgrindTool, self).__init__() - self.RegisterOptionParserHook(ValgrindTool.ExtendOptionParser) - - def UseXML(self): - # Override if tool prefers nonxml output - return True - - def ExtendOptionParser(self, parser): - parser.add_option("", "--suppressions", default=[], - action="append", - help="path to a valgrind suppression file") - parser.add_option("", "--indirect", action="store_true", - default=False, - help="set BROWSER_WRAPPER rather than " - "running valgrind directly") - parser.add_option("", "--indirect_webkit_layout", action="store_true", - default=False, - help="set --wrapper rather than running Dr. Memory " - "directly.") - parser.add_option("", "--trace_children", action="store_true", - default=False, - help="also trace child processes") - parser.add_option("", "--num-callers", - dest="num_callers", default=30, - help="number of callers to show in stack traces") - parser.add_option("", "--generate_dsym", action="store_true", - default=False, - help="Generate .dSYM file on Mac if needed. Slow!") - - def Setup(self, args): - if not BaseTool.Setup(self, args): - return False - return True - - def ToolCommand(self): - """Get the valgrind command to run.""" - # Note that self._args begins with the exe to be run. - tool_name = self.ToolName() - - # Construct the valgrind command. - if 'CHROME_VALGRIND' in os.environ: - path = os.path.join(os.environ['CHROME_VALGRIND'], "bin", "valgrind") - else: - path = "valgrind" - proc = [path, "--tool=%s" % tool_name] - - proc += ["--num-callers=%i" % int(self._options.num_callers)] - - if self._options.trace_children: - proc += ["--trace-children=yes"] - proc += ["--trace-children-skip='*dbus-daemon*'"] - proc += ["--trace-children-skip='*dbus-launch*'"] - proc += ["--trace-children-skip='*perl*'"] - proc += ["--trace-children-skip='*python*'"] - # This is really Python, but for some reason Valgrind follows it. - proc += ["--trace-children-skip='*lsb_release*'"] - - proc += self.ToolSpecificFlags() - proc += self._tool_flags - - suppression_count = 0 - for suppression_file in self._options.suppressions: - if os.path.exists(suppression_file): - suppression_count += 1 - proc += ["--suppressions=%s" % suppression_file] - - if not suppression_count: - logging.warning("WARNING: NOT USING SUPPRESSIONS!") - - logfilename = self.log_dir + ("/%s." % tool_name) + "%p" - if self.UseXML(): - proc += ["--xml=yes", "--xml-file=" + logfilename] - else: - proc += ["--log-file=" + logfilename] - - # The Valgrind command is constructed. - - # Handle --indirect_webkit_layout separately. - if self._options.indirect_webkit_layout: - # Need to create the wrapper before modifying |proc|. - wrapper = self.CreateBrowserWrapper(proc, webkit=True) - proc = self._args - proc.append("--wrapper") - proc.append(wrapper) - return proc - - if self._options.indirect: - wrapper = self.CreateBrowserWrapper(proc) - os.environ["BROWSER_WRAPPER"] = wrapper - logging.info('export BROWSER_WRAPPER=' + wrapper) - proc = [] - proc += self._args - return proc - - def ToolSpecificFlags(self): - raise NotImplementedError, "This method should be implemented " \ - "in the tool-specific subclass" - - def CreateBrowserWrapper(self, proc, webkit=False): - """The program being run invokes Python or something else that can't stand - to be valgrinded, and also invokes the Chrome browser. In this case, use a - magic wrapper to only valgrind the Chrome browser. Build the wrapper here. - Returns the path to the wrapper. It's up to the caller to use the wrapper - appropriately. - """ - command = " ".join(proc) - # Add the PID of the browser wrapper to the logfile names so we can - # separate log files for different UI tests at the analyze stage. - command = command.replace("%p", "$$.%p") - - (fd, indirect_fname) = tempfile.mkstemp(dir=self.log_dir, - prefix="browser_wrapper.", - text=True) - f = os.fdopen(fd, "w") - f.write('#!/bin/bash\n' - 'echo "Started Valgrind wrapper for this test, PID=$$" >&2\n') - - f.write('DIR=`dirname $0`\n' - 'TESTNAME_FILE=$DIR/testcase.$$.name\n\n') - - if webkit: - # Webkit layout_tests pass the URL as the first line of stdin. - f.write('tee $TESTNAME_FILE | %s "$@"\n' % command) - else: - # Try to get the test case name by looking at the program arguments. - # i.e. Chromium ui_tests used --test-name arg. - # TODO(timurrrr): This doesn't handle "--test-name Test.Name" - # TODO(timurrrr): ui_tests are dead. Where do we use the non-webkit - # wrapper now? browser_tests? What do they do? - f.write('for arg in $@\ndo\n' - ' if [[ "$arg" =~ --test-name=(.*) ]]\n then\n' - ' echo ${BASH_REMATCH[1]} >$TESTNAME_FILE\n' - ' fi\n' - 'done\n\n' - '%s "$@"\n' % command) - - f.close() - os.chmod(indirect_fname, stat.S_IRUSR|stat.S_IXUSR) - return indirect_fname - - def CreateAnalyzer(self): - raise NotImplementedError, "This method should be implemented " \ - "in the tool-specific subclass" - - def GetAnalyzeResults(self, check_sanity=False): - # Glob all the files in the log directory - filenames = glob.glob(self.log_dir + "/" + self.ToolName() + ".*") - - # If we have browser wrapper, the logfiles are named as - # "toolname.wrapper_PID.valgrind_PID". - # Let's extract the list of wrapper_PIDs and name it ppids - ppids = set([int(f.split(".")[-2]) \ - for f in filenames if re.search("\.[0-9]+\.[0-9]+$", f)]) - - analyzer = self.CreateAnalyzer() - if len(ppids) == 0: - # Fast path - no browser wrapper was set. - return analyzer.Report(filenames, None, check_sanity) - - ret = 0 - for ppid in ppids: - testcase_name = None - try: - f = open(self.log_dir + ("/testcase.%d.name" % ppid)) - testcase_name = f.read().strip() - f.close() - wk_layout_prefix="third_party/WebKit/LayoutTests/" - wk_prefix_at = testcase_name.rfind(wk_layout_prefix) - if wk_prefix_at != -1: - testcase_name = testcase_name[wk_prefix_at + len(wk_layout_prefix):] - except IOError: - pass - print "=====================================================" - print " Below is the report for valgrind wrapper PID=%d." % ppid - if testcase_name: - print " It was used while running the `%s` test." % testcase_name - else: - print " You can find the corresponding test" - print " by searching the above log for 'PID=%d'" % ppid - sys.stdout.flush() - - ppid_filenames = [f for f in filenames \ - if re.search("\.%d\.[0-9]+$" % ppid, f)] - # check_sanity won't work with browser wrappers - assert check_sanity == False - ret |= analyzer.Report(ppid_filenames, testcase_name) - print "=====================================================" - sys.stdout.flush() - - if ret != 0: - print "" - print "The Valgrind reports are grouped by test names." - print "Each test has its PID printed in the log when the test was run" - print "and at the beginning of its Valgrind report." - print "Hint: you can search for the reports by Ctrl+F -> `=#`" - sys.stdout.flush() - - return ret - - -# TODO(timurrrr): Split into a separate file. -class Memcheck(ValgrindTool): - """Memcheck - Dynamic memory error detector for Linux & Mac - - http://valgrind.org/info/tools.html#memcheck - """ - - def __init__(self): - super(Memcheck, self).__init__() - self.RegisterOptionParserHook(Memcheck.ExtendOptionParser) - - def ToolName(self): - return "memcheck" - - def ExtendOptionParser(self, parser): - parser.add_option("--leak-check", "--leak_check", type="string", - default="yes", # --leak-check=yes is equivalent of =full - help="perform leak checking at the end of the run") - parser.add_option("", "--show_all_leaks", action="store_true", - default=False, - help="also show less blatant leaks") - parser.add_option("", "--track_origins", action="store_true", - default=False, - help="Show whence uninitialized bytes came. 30% slower.") - - def ToolSpecificFlags(self): - ret = ["--gen-suppressions=all", "--demangle=no"] - ret += ["--leak-check=%s" % self._options.leak_check] - - if self._options.show_all_leaks: - ret += ["--show-reachable=yes"] - else: - ret += ["--show-possibly-lost=no"] - - if self._options.track_origins: - ret += ["--track-origins=yes"] - - # TODO(glider): this is a temporary workaround for http://crbug.com/51716 - # Let's see whether it helps. - if common.IsMac(): - ret += ["--smc-check=all"] - - return ret - - def CreateAnalyzer(self): - use_gdb = common.IsMac() - return memcheck_analyze.MemcheckAnalyzer(self._source_dir, - self._options.show_all_leaks, - use_gdb=use_gdb) - - def Analyze(self, check_sanity=False): - ret = self.GetAnalyzeResults(check_sanity) - - if ret != 0: - logging.info("Please see http://dev.chromium.org/developers/how-tos/" - "using-valgrind for the info on Memcheck/Valgrind") - return ret - - -class ToolFactory: - def Create(self, tool_name): - if tool_name == "memcheck": - return Memcheck() - try: - platform_name = common.PlatformNames()[0] - except common.NotImplementedError: - platform_name = sys.platform + "(Unknown)" - raise RuntimeError, "Unknown tool (tool=%s, platform=%s)" % (tool_name, - platform_name) - -def CreateTool(tool): - return ToolFactory().Create(tool) diff --git a/libs/libyuv/unit_test/basictypes_test.cc b/libs/libyuv/unit_test/basictypes_test.cc index 9aaa2dcd98..3c9068c1ff 100644 --- a/libs/libyuv/unit_test/basictypes_test.cc +++ b/libs/libyuv/unit_test/basictypes_test.cc @@ -8,8 +8,9 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include + #include "../unit_test/unit_test.h" -#include "libyuv/basic_types.h" namespace libyuv { @@ -22,22 +23,22 @@ TEST_F(LibYUVBaseTest, SizeOfTypes) { uint32_t u32 = 1u; int64_t i64 = -1; uint64_t u64 = 1u; - EXPECT_EQ(1u, sizeof(i8)); - EXPECT_EQ(1u, sizeof(u8)); - EXPECT_EQ(2u, sizeof(i16)); - EXPECT_EQ(2u, sizeof(u16)); - EXPECT_EQ(4u, sizeof(i32)); - EXPECT_EQ(4u, sizeof(u32)); - EXPECT_EQ(8u, sizeof(i64)); - EXPECT_EQ(8u, sizeof(u64)); - EXPECT_GT(0, i8); - EXPECT_LT(0u, u8); - EXPECT_GT(0, i16); - EXPECT_LT(0u, u16); - EXPECT_GT(0, i32); - EXPECT_LT(0u, u32); - EXPECT_GT(0, i64); - EXPECT_LT(0u, u64); + ASSERT_EQ(1u, sizeof(i8)); + ASSERT_EQ(1u, sizeof(u8)); + ASSERT_EQ(2u, sizeof(i16)); + ASSERT_EQ(2u, sizeof(u16)); + ASSERT_EQ(4u, sizeof(i32)); + ASSERT_EQ(4u, sizeof(u32)); + ASSERT_EQ(8u, sizeof(i64)); + ASSERT_EQ(8u, sizeof(u64)); + ASSERT_GT(0, i8); + ASSERT_LT(0u, u8); + ASSERT_GT(0, i16); + ASSERT_LT(0u, u16); + ASSERT_GT(0, i32); + ASSERT_LT(0u, u32); + ASSERT_GT(0, i64); + ASSERT_LT(0u, u64); } } // namespace libyuv diff --git a/libs/libyuv/unit_test/color_test.cc b/libs/libyuv/unit_test/color_test.cc index 4bb448d56f..2f46832e3e 100644 --- a/libs/libyuv/unit_test/color_test.cc +++ b/libs/libyuv/unit_test/color_test.cc @@ -11,7 +11,6 @@ #include #include "../unit_test/unit_test.h" -#include "libyuv/basic_types.h" #include "libyuv/convert.h" #include "libyuv/convert_argb.h" #include "libyuv/convert_from.h" @@ -20,20 +19,16 @@ namespace libyuv { -// TODO(fbarchard): Port high accuracy YUV to RGB to Neon. -#if !defined(LIBYUV_DISABLE_NEON) && \ - (defined(__aarch64__) || defined(__ARM_NEON__) || defined(LIBYUV_NEON)) -#define ERROR_R 1 -#define ERROR_G 1 -#define ERROR_B 3 +// TODO(fbarchard): clang x86 has a higher accuracy YUV to RGB. +// Port to Visual C and other CPUs #define ERROR_FULL 6 -#define ERROR_J420 5 -#else +#define ERROR_J420 6 #define ERROR_R 1 #define ERROR_G 1 -#define ERROR_B 3 -#define ERROR_FULL 5 -#define ERROR_J420 3 +#ifdef LIBYUV_UNLIMITED_DATA +#define ERROR_B 1 +#else +#define ERROR_B 18 #endif #define TESTCS(TESTNAME, YUVTOARGB, ARGBTOYUV, HS1, HS, HN, DIFF) \ @@ -117,11 +112,11 @@ namespace libyuv { } \ /* Test C and SIMD match. */ \ for (int i = 0; i < kPixels * 4; ++i) { \ - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); \ + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); \ } \ /* Test SIMD is close to original. */ \ for (int i = 0; i < kPixels * 4; ++i) { \ - EXPECT_NEAR(static_cast(orig_pixels[i]), \ + ASSERT_NEAR(static_cast(orig_pixels[i]), \ static_cast(dst_pixels_opt[i]), DIFF); \ } \ \ @@ -154,6 +149,7 @@ static void YUVToRGB(int y, int u, int v, int* r, int* g, int* b) { memset(orig_y, y, kPixels); memset(orig_u, u, kHalfPixels); memset(orig_v, v, kHalfPixels); + memset(orig_pixels, 0, sizeof(orig_pixels)); /* YUV converted to ARGB. */ I422ToARGB(orig_y, kWidth, orig_u, (kWidth + 1) / 2, orig_v, (kWidth + 1) / 2, @@ -177,6 +173,7 @@ static void YUVJToRGB(int y, int u, int v, int* r, int* g, int* b) { memset(orig_y, y, kPixels); memset(orig_u, u, kHalfPixels); memset(orig_v, v, kHalfPixels); + memset(orig_pixels, 0, sizeof(orig_pixels)); /* YUV converted to ARGB. */ J422ToARGB(orig_y, kWidth, orig_u, (kWidth + 1) / 2, orig_v, (kWidth + 1) / 2, @@ -187,6 +184,104 @@ static void YUVJToRGB(int y, int u, int v, int* r, int* g, int* b) { *r = orig_pixels[2]; } +static void YUVHToRGB(int y, int u, int v, int* r, int* g, int* b) { + const int kWidth = 16; + const int kHeight = 1; + const int kPixels = kWidth * kHeight; + const int kHalfPixels = ((kWidth + 1) / 2) * ((kHeight + 1) / 2); + + SIMD_ALIGNED(uint8_t orig_y[16]); + SIMD_ALIGNED(uint8_t orig_u[8]); + SIMD_ALIGNED(uint8_t orig_v[8]); + SIMD_ALIGNED(uint8_t orig_pixels[16 * 4]); + memset(orig_y, y, kPixels); + memset(orig_u, u, kHalfPixels); + memset(orig_v, v, kHalfPixels); + + /* YUV converted to ARGB. */ + H422ToARGB(orig_y, kWidth, orig_u, (kWidth + 1) / 2, orig_v, (kWidth + 1) / 2, + orig_pixels, kWidth * 4, kWidth, kHeight); + + *b = orig_pixels[0]; + *g = orig_pixels[1]; + *r = orig_pixels[2]; +} + +#define F422ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I422ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuvF709Constants, i, j) + +static void YUVFToRGB(int y, int u, int v, int* r, int* g, int* b) { + const int kWidth = 16; + const int kHeight = 1; + const int kPixels = kWidth * kHeight; + const int kHalfPixels = ((kWidth + 1) / 2) * ((kHeight + 1) / 2); + + SIMD_ALIGNED(uint8_t orig_y[16]); + SIMD_ALIGNED(uint8_t orig_u[8]); + SIMD_ALIGNED(uint8_t orig_v[8]); + SIMD_ALIGNED(uint8_t orig_pixels[16 * 4]); + memset(orig_y, y, kPixels); + memset(orig_u, u, kHalfPixels); + memset(orig_v, v, kHalfPixels); + + /* YUV converted to ARGB. */ + F422ToARGB(orig_y, kWidth, orig_u, (kWidth + 1) / 2, orig_v, (kWidth + 1) / 2, + orig_pixels, kWidth * 4, kWidth, kHeight); + + *b = orig_pixels[0]; + *g = orig_pixels[1]; + *r = orig_pixels[2]; +} + +static void YUVUToRGB(int y, int u, int v, int* r, int* g, int* b) { + const int kWidth = 16; + const int kHeight = 1; + const int kPixels = kWidth * kHeight; + const int kHalfPixels = ((kWidth + 1) / 2) * ((kHeight + 1) / 2); + + SIMD_ALIGNED(uint8_t orig_y[16]); + SIMD_ALIGNED(uint8_t orig_u[8]); + SIMD_ALIGNED(uint8_t orig_v[8]); + SIMD_ALIGNED(uint8_t orig_pixels[16 * 4]); + memset(orig_y, y, kPixels); + memset(orig_u, u, kHalfPixels); + memset(orig_v, v, kHalfPixels); + + /* YUV converted to ARGB. */ + U422ToARGB(orig_y, kWidth, orig_u, (kWidth + 1) / 2, orig_v, (kWidth + 1) / 2, + orig_pixels, kWidth * 4, kWidth, kHeight); + + *b = orig_pixels[0]; + *g = orig_pixels[1]; + *r = orig_pixels[2]; +} + +#define V422ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I422ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuvV2020Constants, i, j) + +static void YUVVToRGB(int y, int u, int v, int* r, int* g, int* b) { + const int kWidth = 16; + const int kHeight = 1; + const int kPixels = kWidth * kHeight; + const int kHalfPixels = ((kWidth + 1) / 2) * ((kHeight + 1) / 2); + + SIMD_ALIGNED(uint8_t orig_y[16]); + SIMD_ALIGNED(uint8_t orig_u[8]); + SIMD_ALIGNED(uint8_t orig_v[8]); + SIMD_ALIGNED(uint8_t orig_pixels[16 * 4]); + memset(orig_y, y, kPixels); + memset(orig_u, u, kHalfPixels); + memset(orig_v, v, kHalfPixels); + + /* YUV converted to ARGB. */ + V422ToARGB(orig_y, kWidth, orig_u, (kWidth + 1) / 2, orig_v, (kWidth + 1) / 2, + orig_pixels, kWidth * 4, kWidth, kHeight); + + *b = orig_pixels[0]; + *g = orig_pixels[1]; + *r = orig_pixels[2]; +} + static void YToRGB(int y, int* r, int* g, int* b) { const int kWidth = 16; const int kHeight = 1; @@ -331,65 +426,103 @@ TEST_F(LibYUVColorTest, TestRoundToByte) { allb |= b; } } - EXPECT_GE(allb, 0); - EXPECT_LE(allb, 255); + ASSERT_GE(allb, 0); + ASSERT_LE(allb, 255); } +// BT.601 limited range YUV to RGB reference static void YUVToRGBReference(int y, int u, int v, int* r, int* g, int* b) { - *r = RoundToByte((y - 16) * 1.164 - (v - 128) * -1.596); - *g = RoundToByte((y - 16) * 1.164 - (u - 128) * 0.391 - (v - 128) * 0.813); - *b = RoundToByte((y - 16) * 1.164 - (u - 128) * -2.018); + double y1 = (y - 16) * 1.164; + *r = RoundToByte(y1 - (v - 128) * -1.596); + *g = RoundToByte(y1 - (u - 128) * 0.391 - (v - 128) * 0.813); + *b = RoundToByte(y1 - (u - 128) * -2.018); } +// BT.601 full range YUV to RGB reference (aka JPEG) static void YUVJToRGBReference(int y, int u, int v, int* r, int* g, int* b) { *r = RoundToByte(y - (v - 128) * -1.40200); *g = RoundToByte(y - (u - 128) * 0.34414 - (v - 128) * 0.71414); *b = RoundToByte(y - (u - 128) * -1.77200); } +// BT.709 limited range YUV to RGB reference +// See also http://www.equasys.de/colorconversion.html +static void YUVHToRGBReference(int y, int u, int v, int* r, int* g, int* b) { + double y1 = (y - 16) * 1.164; + *r = RoundToByte(y1 - (v - 128) * -1.793); + *g = RoundToByte(y1 - (u - 128) * 0.213 - (v - 128) * 0.533); + *b = RoundToByte(y1 - (u - 128) * -2.112); +} + +// BT.709 full range YUV to RGB reference +static void YUVFToRGBReference(int y, int u, int v, int* r, int* g, int* b) { + *r = RoundToByte(y - (v - 128) * -1.5748); + *g = RoundToByte(y - (u - 128) * 0.18732 - (v - 128) * 0.46812); + *b = RoundToByte(y - (u - 128) * -1.8556); +} + +// BT.2020 limited range YUV to RGB reference +static void YUVUToRGBReference(int y, int u, int v, int* r, int* g, int* b) { + double y1 = (y - 16) * 1.164384; + *r = RoundToByte(y1 - (v - 128) * -1.67867); + *g = RoundToByte(y1 - (u - 128) * 0.187326 - (v - 128) * 0.65042); + *b = RoundToByte(y1 - (u - 128) * -2.14177); +} + +// BT.2020 full range YUV to RGB reference +static void YUVVToRGBReference(int y, int u, int v, int* r, int* g, int* b) { + *r = RoundToByte(y + (v - 128) * 1.474600); + *g = RoundToByte(y - (u - 128) * 0.164553 - (v - 128) * 0.571353); + *b = RoundToByte(y + (u - 128) * 1.881400); +} + TEST_F(LibYUVColorTest, TestYUV) { int r0, g0, b0, r1, g1, b1; // cyan (less red) YUVToRGBReference(240, 255, 0, &r0, &g0, &b0); - EXPECT_EQ(56, r0); - EXPECT_EQ(255, g0); - EXPECT_EQ(255, b0); + ASSERT_EQ(56, r0); + ASSERT_EQ(255, g0); + ASSERT_EQ(255, b0); YUVToRGB(240, 255, 0, &r1, &g1, &b1); - EXPECT_EQ(57, r1); - EXPECT_EQ(255, g1); - EXPECT_EQ(255, b1); + ASSERT_EQ(57, r1); + ASSERT_EQ(255, g1); + ASSERT_EQ(255, b1); // green (less red and blue) YUVToRGBReference(240, 0, 0, &r0, &g0, &b0); - EXPECT_EQ(56, r0); - EXPECT_EQ(255, g0); - EXPECT_EQ(2, b0); + ASSERT_EQ(56, r0); + ASSERT_EQ(255, g0); + ASSERT_EQ(2, b0); YUVToRGB(240, 0, 0, &r1, &g1, &b1); - EXPECT_EQ(57, r1); - EXPECT_EQ(255, g1); - EXPECT_EQ(5, b1); + ASSERT_EQ(57, r1); + ASSERT_EQ(255, g1); +#ifdef LIBYUV_UNLIMITED_DATA + ASSERT_EQ(3, b1); +#else + ASSERT_EQ(5, b1); +#endif for (int i = 0; i < 256; ++i) { YUVToRGBReference(i, 128, 128, &r0, &g0, &b0); YUVToRGB(i, 128, 128, &r1, &g1, &b1); - EXPECT_NEAR(r0, r1, ERROR_R); - EXPECT_NEAR(g0, g1, ERROR_G); - EXPECT_NEAR(b0, b1, ERROR_B); + ASSERT_NEAR(r0, r1, ERROR_R); + ASSERT_NEAR(g0, g1, ERROR_G); + ASSERT_NEAR(b0, b1, ERROR_B); YUVToRGBReference(i, 0, 0, &r0, &g0, &b0); YUVToRGB(i, 0, 0, &r1, &g1, &b1); - EXPECT_NEAR(r0, r1, ERROR_R); - EXPECT_NEAR(g0, g1, ERROR_G); - EXPECT_NEAR(b0, b1, ERROR_B); + ASSERT_NEAR(r0, r1, ERROR_R); + ASSERT_NEAR(g0, g1, ERROR_G); + ASSERT_NEAR(b0, b1, ERROR_B); YUVToRGBReference(i, 0, 255, &r0, &g0, &b0); YUVToRGB(i, 0, 255, &r1, &g1, &b1); - EXPECT_NEAR(r0, r1, ERROR_R); - EXPECT_NEAR(g0, g1, ERROR_G); - EXPECT_NEAR(b0, b1, ERROR_B); + ASSERT_NEAR(r0, r1, ERROR_R); + ASSERT_NEAR(g0, g1, ERROR_G); + ASSERT_NEAR(b0, b1, ERROR_B); } } @@ -398,74 +531,74 @@ TEST_F(LibYUVColorTest, TestGreyYUV) { // black YUVToRGBReference(16, 128, 128, &r0, &g0, &b0); - EXPECT_EQ(0, r0); - EXPECT_EQ(0, g0); - EXPECT_EQ(0, b0); + ASSERT_EQ(0, r0); + ASSERT_EQ(0, g0); + ASSERT_EQ(0, b0); YUVToRGB(16, 128, 128, &r1, &g1, &b1); - EXPECT_EQ(0, r1); - EXPECT_EQ(0, g1); - EXPECT_EQ(0, b1); + ASSERT_EQ(0, r1); + ASSERT_EQ(0, g1); + ASSERT_EQ(0, b1); // white YUVToRGBReference(240, 128, 128, &r0, &g0, &b0); - EXPECT_EQ(255, r0); - EXPECT_EQ(255, g0); - EXPECT_EQ(255, b0); + ASSERT_EQ(255, r0); + ASSERT_EQ(255, g0); + ASSERT_EQ(255, b0); YUVToRGB(240, 128, 128, &r1, &g1, &b1); - EXPECT_EQ(255, r1); - EXPECT_EQ(255, g1); - EXPECT_EQ(255, b1); + ASSERT_EQ(255, r1); + ASSERT_EQ(255, g1); + ASSERT_EQ(255, b1); // grey YUVToRGBReference(128, 128, 128, &r0, &g0, &b0); - EXPECT_EQ(130, r0); - EXPECT_EQ(130, g0); - EXPECT_EQ(130, b0); + ASSERT_EQ(130, r0); + ASSERT_EQ(130, g0); + ASSERT_EQ(130, b0); YUVToRGB(128, 128, 128, &r1, &g1, &b1); - EXPECT_EQ(130, r1); - EXPECT_EQ(130, g1); - EXPECT_EQ(130, b1); + ASSERT_EQ(130, r1); + ASSERT_EQ(130, g1); + ASSERT_EQ(130, b1); for (int y = 0; y < 256; ++y) { YUVToRGBReference(y, 128, 128, &r0, &g0, &b0); YUVToRGB(y, 128, 128, &r1, &g1, &b1); YToRGB(y, &r2, &g2, &b2); - EXPECT_EQ(r0, r1); - EXPECT_EQ(g0, g1); - EXPECT_EQ(b0, b1); - EXPECT_EQ(r0, r2); - EXPECT_EQ(g0, g2); - EXPECT_EQ(b0, b2); + ASSERT_EQ(r0, r1); + ASSERT_EQ(g0, g1); + ASSERT_EQ(b0, b1); + ASSERT_EQ(r0, r2); + ASSERT_EQ(g0, g2); + ASSERT_EQ(b0, b2); } } static void PrintHistogram(int rh[256], int gh[256], int bh[256]) { int i; - printf("hist"); + printf("hist "); for (i = 0; i < 256; ++i) { if (rh[i] || gh[i] || bh[i]) { - printf("\t%8d", i - 128); + printf(" %8d", i - 128); } } - printf("\nred"); + printf("\nred "); for (i = 0; i < 256; ++i) { if (rh[i] || gh[i] || bh[i]) { - printf("\t%8d", rh[i]); + printf(" %8d", rh[i]); } } printf("\ngreen"); for (i = 0; i < 256; ++i) { if (rh[i] || gh[i] || bh[i]) { - printf("\t%8d", gh[i]); + printf(" %8d", gh[i]); } } - printf("\nblue"); + printf("\nblue "); for (i = 0; i < 256; ++i) { if (rh[i] || gh[i] || bh[i]) { - printf("\t%8d", bh[i]); + printf(" %8d", bh[i]); } } printf("\n"); @@ -473,7 +606,14 @@ static void PrintHistogram(int rh[256], int gh[256], int bh[256]) { // Step by 5 on inner loop goes from 0 to 255 inclusive. // Set to 1 for better converage. 3, 5 or 17 for faster testing. +#ifdef DISABLE_SLOW_TESTS #define FASTSTEP 5 +#else +#define FASTSTEP 3 +#endif + +// BT.601 limited range. +#ifndef DISABLE_SLOW_TESTS TEST_F(LibYUVColorTest, TestFullYUV) { int rh[256] = { 0, @@ -484,16 +624,16 @@ TEST_F(LibYUVColorTest, TestFullYUV) { int bh[256] = { 0, }; - for (int u = 0; u < 256; ++u) { - for (int v = 0; v < 256; ++v) { + for (int u = 0; u < 256; u += FASTSTEP) { + for (int v = 0; v < 256; v += FASTSTEP) { for (int y2 = 0; y2 < 256; y2 += FASTSTEP) { int r0, g0, b0, r1, g1, b1; int y = RANDOM256(y2); YUVToRGBReference(y, u, v, &r0, &g0, &b0); YUVToRGB(y, u, v, &r1, &g1, &b1); - EXPECT_NEAR(r0, r1, ERROR_R); - EXPECT_NEAR(g0, g1, ERROR_G); - EXPECT_NEAR(b0, b1, ERROR_B); + ASSERT_NEAR(r0, r1, ERROR_R); + ASSERT_NEAR(g0, g1, ERROR_G); + ASSERT_NEAR(b0, b1, ERROR_B); ++rh[r1 - r0 + 128]; ++gh[g1 - g0 + 128]; ++bh[b1 - b0 + 128]; @@ -503,6 +643,7 @@ TEST_F(LibYUVColorTest, TestFullYUV) { PrintHistogram(rh, gh, bh); } +// BT.601 full range. TEST_F(LibYUVColorTest, TestFullYUVJ) { int rh[256] = { 0, @@ -513,16 +654,16 @@ TEST_F(LibYUVColorTest, TestFullYUVJ) { int bh[256] = { 0, }; - for (int u = 0; u < 256; ++u) { - for (int v = 0; v < 256; ++v) { + for (int u = 0; u < 256; u += FASTSTEP) { + for (int v = 0; v < 256; v += FASTSTEP) { for (int y2 = 0; y2 < 256; y2 += FASTSTEP) { int r0, g0, b0, r1, g1, b1; int y = RANDOM256(y2); YUVJToRGBReference(y, u, v, &r0, &g0, &b0); YUVJToRGB(y, u, v, &r1, &g1, &b1); - EXPECT_NEAR(r0, r1, 1); - EXPECT_NEAR(g0, g1, 1); - EXPECT_NEAR(b0, b1, 1); + ASSERT_NEAR(r0, r1, ERROR_R); + ASSERT_NEAR(g0, g1, ERROR_G); + ASSERT_NEAR(b0, b1, ERROR_B); ++rh[r1 - r0 + 128]; ++gh[g1 - g0 + 128]; ++bh[b1 - b0 + 128]; @@ -531,6 +672,128 @@ TEST_F(LibYUVColorTest, TestFullYUVJ) { } PrintHistogram(rh, gh, bh); } + +// BT.709 limited range. +TEST_F(LibYUVColorTest, TestFullYUVH) { + int rh[256] = { + 0, + }; + int gh[256] = { + 0, + }; + int bh[256] = { + 0, + }; + for (int u = 0; u < 256; u += FASTSTEP) { + for (int v = 0; v < 256; v += FASTSTEP) { + for (int y2 = 0; y2 < 256; y2 += FASTSTEP) { + int r0, g0, b0, r1, g1, b1; + int y = RANDOM256(y2); + YUVHToRGBReference(y, u, v, &r0, &g0, &b0); + YUVHToRGB(y, u, v, &r1, &g1, &b1); + ASSERT_NEAR(r0, r1, ERROR_R); + ASSERT_NEAR(g0, g1, ERROR_G); + ASSERT_NEAR(b0, b1, ERROR_B); + ++rh[r1 - r0 + 128]; + ++gh[g1 - g0 + 128]; + ++bh[b1 - b0 + 128]; + } + } + } + PrintHistogram(rh, gh, bh); +} + +// BT.709 full range. +TEST_F(LibYUVColorTest, TestFullYUVF) { + int rh[256] = { + 0, + }; + int gh[256] = { + 0, + }; + int bh[256] = { + 0, + }; + for (int u = 0; u < 256; u += FASTSTEP) { + for (int v = 0; v < 256; v += FASTSTEP) { + for (int y2 = 0; y2 < 256; y2 += FASTSTEP) { + int r0, g0, b0, r1, g1, b1; + int y = RANDOM256(y2); + YUVFToRGBReference(y, u, v, &r0, &g0, &b0); + YUVFToRGB(y, u, v, &r1, &g1, &b1); + ASSERT_NEAR(r0, r1, ERROR_R); + ASSERT_NEAR(g0, g1, ERROR_G); + ASSERT_NEAR(b0, b1, ERROR_B); + ++rh[r1 - r0 + 128]; + ++gh[g1 - g0 + 128]; + ++bh[b1 - b0 + 128]; + } + } + } + PrintHistogram(rh, gh, bh); +} + +// BT.2020 limited range. +TEST_F(LibYUVColorTest, TestFullYUVU) { + int rh[256] = { + 0, + }; + int gh[256] = { + 0, + }; + int bh[256] = { + 0, + }; + for (int u = 0; u < 256; u += FASTSTEP) { + for (int v = 0; v < 256; v += FASTSTEP) { + for (int y2 = 0; y2 < 256; y2 += FASTSTEP) { + int r0, g0, b0, r1, g1, b1; + int y = RANDOM256(y2); + YUVUToRGBReference(y, u, v, &r0, &g0, &b0); + YUVUToRGB(y, u, v, &r1, &g1, &b1); + ASSERT_NEAR(r0, r1, ERROR_R); + ASSERT_NEAR(g0, g1, ERROR_G); + ASSERT_NEAR(b0, b1, ERROR_B); + ++rh[r1 - r0 + 128]; + ++gh[g1 - g0 + 128]; + ++bh[b1 - b0 + 128]; + } + } + } + PrintHistogram(rh, gh, bh); +} + +// BT.2020 full range. +TEST_F(LibYUVColorTest, TestFullYUVV) { + int rh[256] = { + 0, + }; + int gh[256] = { + 0, + }; + int bh[256] = { + 0, + }; + for (int u = 0; u < 256; u += FASTSTEP) { + for (int v = 0; v < 256; v += FASTSTEP) { + for (int y2 = 0; y2 < 256; y2 += FASTSTEP) { + int r0, g0, b0, r1, g1, b1; + int y = RANDOM256(y2); + YUVVToRGBReference(y, u, v, &r0, &g0, &b0); + YUVVToRGB(y, u, v, &r1, &g1, &b1); + ASSERT_NEAR(r0, r1, ERROR_R); + ASSERT_NEAR(g0, g1, 2); + ASSERT_NEAR(b0, b1, ERROR_B); + ++rh[r1 - r0 + 128]; + ++gh[g1 - g0 + 128]; + ++bh[b1 - b0 + 128]; + } + } + } + PrintHistogram(rh, gh, bh); +} +#endif // DISABLE_SLOW_TESTS + #undef FASTSTEP TEST_F(LibYUVColorTest, TestGreyYUVJ) { @@ -538,47 +801,47 @@ TEST_F(LibYUVColorTest, TestGreyYUVJ) { // black YUVJToRGBReference(0, 128, 128, &r0, &g0, &b0); - EXPECT_EQ(0, r0); - EXPECT_EQ(0, g0); - EXPECT_EQ(0, b0); + ASSERT_EQ(0, r0); + ASSERT_EQ(0, g0); + ASSERT_EQ(0, b0); YUVJToRGB(0, 128, 128, &r1, &g1, &b1); - EXPECT_EQ(0, r1); - EXPECT_EQ(0, g1); - EXPECT_EQ(0, b1); + ASSERT_EQ(0, r1); + ASSERT_EQ(0, g1); + ASSERT_EQ(0, b1); // white YUVJToRGBReference(255, 128, 128, &r0, &g0, &b0); - EXPECT_EQ(255, r0); - EXPECT_EQ(255, g0); - EXPECT_EQ(255, b0); + ASSERT_EQ(255, r0); + ASSERT_EQ(255, g0); + ASSERT_EQ(255, b0); YUVJToRGB(255, 128, 128, &r1, &g1, &b1); - EXPECT_EQ(255, r1); - EXPECT_EQ(255, g1); - EXPECT_EQ(255, b1); + ASSERT_EQ(255, r1); + ASSERT_EQ(255, g1); + ASSERT_EQ(255, b1); // grey YUVJToRGBReference(128, 128, 128, &r0, &g0, &b0); - EXPECT_EQ(128, r0); - EXPECT_EQ(128, g0); - EXPECT_EQ(128, b0); + ASSERT_EQ(128, r0); + ASSERT_EQ(128, g0); + ASSERT_EQ(128, b0); YUVJToRGB(128, 128, 128, &r1, &g1, &b1); - EXPECT_EQ(128, r1); - EXPECT_EQ(128, g1); - EXPECT_EQ(128, b1); + ASSERT_EQ(128, r1); + ASSERT_EQ(128, g1); + ASSERT_EQ(128, b1); for (int y = 0; y < 256; ++y) { YUVJToRGBReference(y, 128, 128, &r0, &g0, &b0); YUVJToRGB(y, 128, 128, &r1, &g1, &b1); YJToRGB(y, &r2, &g2, &b2); - EXPECT_EQ(r0, r1); - EXPECT_EQ(g0, g1); - EXPECT_EQ(b0, b1); - EXPECT_EQ(r0, r2); - EXPECT_EQ(g0, g2); - EXPECT_EQ(b0, b2); + ASSERT_EQ(r0, r1); + ASSERT_EQ(g0, g1); + ASSERT_EQ(b0, b1); + ASSERT_EQ(r0, r2); + ASSERT_EQ(g0, g2); + ASSERT_EQ(b0, b2); } } diff --git a/libs/libyuv/unit_test/compare_test.cc b/libs/libyuv/unit_test/compare_test.cc index bd99cdd3ac..a3a402aa15 100644 --- a/libs/libyuv/unit_test/compare_test.cc +++ b/libs/libyuv/unit_test/compare_test.cc @@ -13,7 +13,6 @@ #include #include "../unit_test/unit_test.h" -#include "libyuv/basic_types.h" #include "libyuv/compare.h" #include "libyuv/cpu_id.h" #include "libyuv/video_common.h" @@ -48,7 +47,7 @@ TEST_F(LibYUVCompareTest, Djb2_Test) { " together with Hermann Zapf"; uint32_t foxhash = HashDjb2(reinterpret_cast(fox), 131, 5381); const uint32_t kExpectedFoxHash = 2611006483u; - EXPECT_EQ(kExpectedFoxHash, foxhash); + ASSERT_EQ(kExpectedFoxHash, foxhash); for (int i = 0; i < kMaxTest; ++i) { src_a[i] = (fastrand() & 0xff); @@ -57,13 +56,13 @@ TEST_F(LibYUVCompareTest, Djb2_Test) { // Compare different buffers. Expect hash is different. uint32_t h1 = HashDjb2(src_a, kMaxTest, 5381); uint32_t h2 = HashDjb2(src_b, kMaxTest, 5381); - EXPECT_NE(h1, h2); + ASSERT_NE(h1, h2); // Make last half same. Expect hash is different. memcpy(src_a + kMaxTest / 2, src_b + kMaxTest / 2, kMaxTest / 2); h1 = HashDjb2(src_a, kMaxTest, 5381); h2 = HashDjb2(src_b, kMaxTest, 5381); - EXPECT_NE(h1, h2); + ASSERT_NE(h1, h2); // Make first half same. Expect hash is different. memcpy(src_a + kMaxTest / 2, src_a, kMaxTest / 2); @@ -71,52 +70,52 @@ TEST_F(LibYUVCompareTest, Djb2_Test) { memcpy(src_a, src_b, kMaxTest / 2); h1 = HashDjb2(src_a, kMaxTest, 5381); h2 = HashDjb2(src_b, kMaxTest, 5381); - EXPECT_NE(h1, h2); + ASSERT_NE(h1, h2); // Make same. Expect hash is same. memcpy(src_a, src_b, kMaxTest); h1 = HashDjb2(src_a, kMaxTest, 5381); h2 = HashDjb2(src_b, kMaxTest, 5381); - EXPECT_EQ(h1, h2); + ASSERT_EQ(h1, h2); // Mask seed different. Expect hash is different. memcpy(src_a, src_b, kMaxTest); h1 = HashDjb2(src_a, kMaxTest, 5381); h2 = HashDjb2(src_b, kMaxTest, 1234); - EXPECT_NE(h1, h2); + ASSERT_NE(h1, h2); // Make one byte different in middle. Expect hash is different. memcpy(src_a, src_b, kMaxTest); ++src_b[kMaxTest / 2]; h1 = HashDjb2(src_a, kMaxTest, 5381); h2 = HashDjb2(src_b, kMaxTest, 5381); - EXPECT_NE(h1, h2); + ASSERT_NE(h1, h2); // Make first byte different. Expect hash is different. memcpy(src_a, src_b, kMaxTest); ++src_b[0]; h1 = HashDjb2(src_a, kMaxTest, 5381); h2 = HashDjb2(src_b, kMaxTest, 5381); - EXPECT_NE(h1, h2); + ASSERT_NE(h1, h2); // Make last byte different. Expect hash is different. memcpy(src_a, src_b, kMaxTest); ++src_b[kMaxTest - 1]; h1 = HashDjb2(src_a, kMaxTest, 5381); h2 = HashDjb2(src_b, kMaxTest, 5381); - EXPECT_NE(h1, h2); + ASSERT_NE(h1, h2); // Make a zeros. Test different lengths. Expect hash is different. memset(src_a, 0, kMaxTest); h1 = HashDjb2(src_a, kMaxTest, 5381); h2 = HashDjb2(src_a, kMaxTest / 2, 5381); - EXPECT_NE(h1, h2); + ASSERT_NE(h1, h2); // Make a zeros and seed of zero. Test different lengths. Expect hash is same. memset(src_a, 0, kMaxTest); h1 = HashDjb2(src_a, kMaxTest, 0); h2 = HashDjb2(src_a, kMaxTest / 2, 0); - EXPECT_EQ(h1, h2); + ASSERT_EQ(h1, h2); free_aligned_buffer_page_end(src_a); free_aligned_buffer_page_end(src_b); @@ -134,7 +133,7 @@ TEST_F(LibYUVCompareTest, BenchmarkDjb2_Opt) { for (int i = 0; i < benchmark_iterations_; ++i) { h1 = HashDjb2(src_a, kMaxTest, 5381); } - EXPECT_EQ(h1, h2); + ASSERT_EQ(h1, h2); free_aligned_buffer_page_end(src_a); } @@ -149,7 +148,7 @@ TEST_F(LibYUVCompareTest, BenchmarkDjb2_Unaligned) { for (int i = 0; i < benchmark_iterations_; ++i) { h1 = HashDjb2(src_a + 1, kMaxTest, 5381); } - EXPECT_EQ(h1, h2); + ASSERT_EQ(h1, h2); free_aligned_buffer_page_end(src_a); } @@ -164,19 +163,19 @@ TEST_F(LibYUVCompareTest, BenchmarkARGBDetect_Opt) { src_a[0] = 0; fourcc = ARGBDetect(src_a, benchmark_width_ * 4, benchmark_width_, benchmark_height_); - EXPECT_EQ(static_cast(libyuv::FOURCC_BGRA), fourcc); + ASSERT_EQ(static_cast(libyuv::FOURCC_BGRA), fourcc); src_a[0] = 255; src_a[3] = 0; fourcc = ARGBDetect(src_a, benchmark_width_ * 4, benchmark_width_, benchmark_height_); - EXPECT_EQ(static_cast(libyuv::FOURCC_ARGB), fourcc); + ASSERT_EQ(static_cast(libyuv::FOURCC_ARGB), fourcc); src_a[3] = 255; for (int i = 0; i < benchmark_iterations_; ++i) { fourcc = ARGBDetect(src_a, benchmark_width_ * 4, benchmark_width_, benchmark_height_); } - EXPECT_EQ(0u, fourcc); + ASSERT_EQ(0u, fourcc); free_aligned_buffer_page_end(src_a); } @@ -192,19 +191,74 @@ TEST_F(LibYUVCompareTest, BenchmarkARGBDetect_Unaligned) { src_a[0 + 1] = 0; fourcc = ARGBDetect(src_a + 1, benchmark_width_ * 4, benchmark_width_, benchmark_height_); - EXPECT_EQ(static_cast(libyuv::FOURCC_BGRA), fourcc); + ASSERT_EQ(static_cast(libyuv::FOURCC_BGRA), fourcc); src_a[0 + 1] = 255; src_a[3 + 1] = 0; fourcc = ARGBDetect(src_a + 1, benchmark_width_ * 4, benchmark_width_, benchmark_height_); - EXPECT_EQ(static_cast(libyuv::FOURCC_ARGB), fourcc); + ASSERT_EQ(static_cast(libyuv::FOURCC_ARGB), fourcc); src_a[3 + 1] = 255; for (int i = 0; i < benchmark_iterations_; ++i) { fourcc = ARGBDetect(src_a + 1, benchmark_width_ * 4, benchmark_width_, benchmark_height_); } - EXPECT_EQ(0u, fourcc); + ASSERT_EQ(0u, fourcc); + + free_aligned_buffer_page_end(src_a); +} + +TEST_F(LibYUVCompareTest, TestARGBDetectAnyWidth) { + const int kMaxWidth = 65; + const int kBufSize = kMaxWidth * 4 + 4; + align_buffer_page_end(src_a, kBufSize); + memset(src_a, 255, kBufSize); + + for (int width = 1; width <= kMaxWidth; ++width) { + for (int offset = 0; offset < 4; ++offset) { + uint8_t* row = src_a + kBufSize - width * 4 - offset; + // All 255 -> 0 (unknown). + MaskCpuFlags(disable_cpu_flags_); + uint32_t c_fourcc = ARGBDetect(row, width * 4, width, 1); + MaskCpuFlags(benchmark_cpu_info_); + uint32_t opt_fourcc = ARGBDetect(row, width * 4, width, 1); + EXPECT_EQ(0u, c_fourcc); + EXPECT_EQ(c_fourcc, opt_fourcc) << "width " << width << " off " << offset; + + for (int x = 0; x < width; ++x) { + // Byte 0 != 255 -> FOURCC_BGRA. + row[x * 4 + 0] = 128; + MaskCpuFlags(disable_cpu_flags_); + c_fourcc = ARGBDetect(row, width * 4, width, 1); + MaskCpuFlags(benchmark_cpu_info_); + opt_fourcc = ARGBDetect(row, width * 4, width, 1); + EXPECT_EQ(static_cast(FOURCC_BGRA), c_fourcc); + EXPECT_EQ(c_fourcc, opt_fourcc) + << "width " << width << " x " << x << " byte 0"; + + // Both byte 0 and byte 3 != 255 -> FOURCC_BGRA (byte 0 checked first). + row[x * 4 + 3] = 64; + MaskCpuFlags(disable_cpu_flags_); + c_fourcc = ARGBDetect(row, width * 4, width, 1); + MaskCpuFlags(benchmark_cpu_info_); + opt_fourcc = ARGBDetect(row, width * 4, width, 1); + EXPECT_EQ(static_cast(FOURCC_BGRA), c_fourcc); + EXPECT_EQ(c_fourcc, opt_fourcc) + << "width " << width << " x " << x << " byte 0+3"; + + // Byte 3 != 255 only -> FOURCC_ARGB. + row[x * 4 + 0] = 255; + MaskCpuFlags(disable_cpu_flags_); + c_fourcc = ARGBDetect(row, width * 4, width, 1); + MaskCpuFlags(benchmark_cpu_info_); + opt_fourcc = ARGBDetect(row, width * 4, width, 1); + EXPECT_EQ(static_cast(FOURCC_ARGB), c_fourcc); + EXPECT_EQ(c_fourcc, opt_fourcc) + << "width " << width << " x " << x << " byte 3"; + row[x * 4 + 3] = 255; + } + } + } free_aligned_buffer_page_end(src_a); } @@ -221,7 +275,7 @@ TEST_F(LibYUVCompareTest, BenchmarkHammingDistance_Opt) { memcpy(src_a, "test0123test4567", 16); memcpy(src_b, "tick0123tock4567", 16); uint32_t h1 = HammingDistance_C(src_a, src_b, 16); - EXPECT_EQ(16u, h1); + ASSERT_EQ(16u, h1); // Test C vs OPT on random buffer MemRandomize(src_a, kMaxWidth); @@ -233,37 +287,71 @@ TEST_F(LibYUVCompareTest, BenchmarkHammingDistance_Opt) { benchmark_iterations_ * ((benchmark_width_ * benchmark_height_ + kMaxWidth - 1) / kMaxWidth); for (int i = 0; i < count; ++i) { -#if defined(HAS_HAMMINGDISTANCE_NEON) - h1 = HammingDistance_NEON(src_a, src_b, kMaxWidth); -#elif defined(HAS_HAMMINGDISTANCE_AVX2) - int has_avx2 = TestCpuFlag(kCpuHasAVX2); - if (has_avx2) { - h1 = HammingDistance_AVX2(src_a, src_b, kMaxWidth); +#if defined(HAS_HAMMINGDISTANCE_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + h1 = HammingDistance_NEON_DotProd(src_a, src_b, kMaxWidth); } else { - int has_sse42 = TestCpuFlag(kCpuHasSSE42); - if (has_sse42) { - h1 = HammingDistance_SSE42(src_a, src_b, kMaxWidth); - } else { - int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); - if (has_ssse3) { - h1 = HammingDistance_SSSE3(src_a, src_b, kMaxWidth); - } else { - h1 = HammingDistance_C(src_a, src_b, kMaxWidth); - } - } + h1 = HammingDistance_NEON(src_a, src_b, kMaxWidth); + } +#elif defined(HAS_HAMMINGDISTANCE_NEON) + h1 = HammingDistance_NEON(src_a, src_b, kMaxWidth); +#elif defined(HAS_HAMMINGDISTANCE_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + h1 = HammingDistance_AVX512VNNI(src_a, src_b, kMaxWidth); + } else if (TestCpuFlag(kCpuHasAVX512BW)) { + h1 = HammingDistance_AVX512BW(src_a, src_b, kMaxWidth); + } else if (TestCpuFlag(kCpuHasAVX2)) { + h1 = HammingDistance_AVX2(src_a, src_b, kMaxWidth); +#if defined(HAS_HAMMINGDISTANCE_SSE42) + } else if (TestCpuFlag(kCpuHasSSE42)) { + h1 = HammingDistance_SSE42(src_a, src_b, kMaxWidth); +#endif +#if defined(HAS_HAMMINGDISTANCE_SSSE3) + } else if (TestCpuFlag(kCpuHasSSSE3)) { + h1 = HammingDistance_SSSE3(src_a, src_b, kMaxWidth); +#endif + } else { + h1 = HammingDistance_C(src_a, src_b, kMaxWidth); + } +#elif defined(HAS_HAMMINGDISTANCE_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + h1 = HammingDistance_AVX2(src_a, src_b, kMaxWidth); +#if defined(HAS_HAMMINGDISTANCE_SSE42) + } else if (TestCpuFlag(kCpuHasSSE42)) { + h1 = HammingDistance_SSE42(src_a, src_b, kMaxWidth); +#endif +#if defined(HAS_HAMMINGDISTANCE_SSSE3) + } else if (TestCpuFlag(kCpuHasSSSE3)) { + h1 = HammingDistance_SSSE3(src_a, src_b, kMaxWidth); +#endif + } else { + h1 = HammingDistance_C(src_a, src_b, kMaxWidth); } #elif defined(HAS_HAMMINGDISTANCE_SSE42) - int has_sse42 = TestCpuFlag(kCpuHasSSE42); - if (has_sse42) { + if (TestCpuFlag(kCpuHasSSE42)) { h1 = HammingDistance_SSE42(src_a, src_b, kMaxWidth); } else { h1 = HammingDistance_C(src_a, src_b, kMaxWidth); } +#elif defined(HAS_HAMMINGDISTANCE_RVV) + h1 = HammingDistance_RVV(src_a, src_b, kMaxWidth); +#elif defined(HAS_HAMMINGDISTANCE_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + h1 = HammingDistance_LASX(src_a, src_b, kMaxWidth); + } else { + h1 = HammingDistance_LSX(src_a, src_b, kMaxWidth); + } +#elif defined(HAS_HAMMINGDISTANCE_LSX) + h1 = HammingDistance_LSX(src_a, src_b, kMaxWidth); +#elif defined(HAS_HAMMINGDISTANCE_WASMSIMD) + h1 = HammingDistance_WASMSIMD(src_a, src_b, kMaxWidth); +#elif defined(HAS_HAMMINGDISTANCE_HVX) + h1 = HammingDistance_HVX(src_a, src_b, kMaxWidth); #else h1 = HammingDistance_C(src_a, src_b, kMaxWidth); #endif } - EXPECT_EQ(h0, h1); + ASSERT_EQ(h0, h1); free_aligned_buffer_page_end(src_a); free_aligned_buffer_page_end(src_b); @@ -280,7 +368,7 @@ TEST_F(LibYUVCompareTest, BenchmarkHammingDistance_C) { memcpy(src_a, "test0123test4567", 16); memcpy(src_b, "tick0123tock4567", 16); uint32_t h1 = HammingDistance_C(src_a, src_b, 16); - EXPECT_EQ(16u, h1); + ASSERT_EQ(16u, h1); // Test C vs OPT on random buffer MemRandomize(src_a, kMaxWidth); @@ -295,7 +383,7 @@ TEST_F(LibYUVCompareTest, BenchmarkHammingDistance_C) { h1 = HammingDistance_C(src_a, src_b, kMaxWidth); } - EXPECT_EQ(h0, h1); + ASSERT_EQ(h0, h1); free_aligned_buffer_page_end(src_a); free_aligned_buffer_page_end(src_b); @@ -311,7 +399,7 @@ TEST_F(LibYUVCompareTest, BenchmarkHammingDistance) { memcpy(src_a, "test0123test4567", 16); memcpy(src_b, "tick0123tock4567", 16); uint64_t h1 = ComputeHammingDistance(src_a, src_b, 16); - EXPECT_EQ(16u, h1); + ASSERT_EQ(16u, h1); // Test C vs OPT on random buffer MemRandomize(src_a, kMaxWidth); @@ -326,7 +414,7 @@ TEST_F(LibYUVCompareTest, BenchmarkHammingDistance) { h1 = ComputeHammingDistance(src_a, src_b, kMaxWidth); } - EXPECT_EQ(h0, h1); + ASSERT_EQ(h0, h1); free_aligned_buffer_page_end(src_a); free_aligned_buffer_page_end(src_b); @@ -344,42 +432,76 @@ static const int kMaxOptCount = (1 << (32 - 3)) - 64; // 536870848 TEST_F(LibYUVCompareTest, TestHammingDistance_Opt) { uint32_t h1 = 0; - const int kMaxWidth = (benchmark_width_ * benchmark_height_ + 31) & ~31; + const int kMaxWidth = (benchmark_width_ * benchmark_height_ + 63) & ~63; align_buffer_page_end(src_a, kMaxWidth); align_buffer_page_end(src_b, kMaxWidth); memset(src_a, 255u, kMaxWidth); memset(src_b, 0u, kMaxWidth); uint64_t h0 = ComputeHammingDistance(src_a, src_b, kMaxWidth); - EXPECT_EQ(kMaxWidth * 8ULL, h0); + ASSERT_EQ(kMaxWidth * 8ULL, h0); for (int i = 0; i < benchmark_iterations_; ++i) { -#if defined(HAS_HAMMINGDISTANCE_NEON) - h1 = HammingDistance_NEON(src_a, src_b, kMaxWidth); -#elif defined(HAS_HAMMINGDISTANCE_AVX2) - int has_avx2 = TestCpuFlag(kCpuHasAVX2); - if (has_avx2) { - h1 = HammingDistance_AVX2(src_a, src_b, kMaxWidth); +#if defined(HAS_HAMMINGDISTANCE_NEON_DOTPROD) + if (TestCpuFlag(kCpuHasNeonDotProd)) { + h1 = HammingDistance_NEON_DotProd(src_a, src_b, kMaxWidth); } else { - int has_sse42 = TestCpuFlag(kCpuHasSSE42); - if (has_sse42) { - h1 = HammingDistance_SSE42(src_a, src_b, kMaxWidth); - } else { - int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); - if (has_ssse3) { - h1 = HammingDistance_SSSE3(src_a, src_b, kMaxWidth); - } else { - h1 = HammingDistance_C(src_a, src_b, kMaxWidth); - } - } + h1 = HammingDistance_NEON(src_a, src_b, kMaxWidth); + } +#elif defined(HAS_HAMMINGDISTANCE_NEON) + h1 = HammingDistance_NEON(src_a, src_b, kMaxWidth); +#elif defined(HAS_HAMMINGDISTANCE_AVX512VNNI) + if (TestCpuFlag(kCpuHasAVX512VNNI)) { + h1 = HammingDistance_AVX512VNNI(src_a, src_b, kMaxWidth); + } else if (TestCpuFlag(kCpuHasAVX512BW)) { + h1 = HammingDistance_AVX512BW(src_a, src_b, kMaxWidth); + } else if (TestCpuFlag(kCpuHasAVX2)) { + h1 = HammingDistance_AVX2(src_a, src_b, kMaxWidth); +#if defined(HAS_HAMMINGDISTANCE_SSE42) + } else if (TestCpuFlag(kCpuHasSSE42)) { + h1 = HammingDistance_SSE42(src_a, src_b, kMaxWidth); +#endif +#if defined(HAS_HAMMINGDISTANCE_SSSE3) + } else if (TestCpuFlag(kCpuHasSSSE3)) { + h1 = HammingDistance_SSSE3(src_a, src_b, kMaxWidth); +#endif + } else { + h1 = HammingDistance_C(src_a, src_b, kMaxWidth); + } +#elif defined(HAS_HAMMINGDISTANCE_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + h1 = HammingDistance_AVX2(src_a, src_b, kMaxWidth); +#if defined(HAS_HAMMINGDISTANCE_SSE42) + } else if (TestCpuFlag(kCpuHasSSE42)) { + h1 = HammingDistance_SSE42(src_a, src_b, kMaxWidth); +#endif +#if defined(HAS_HAMMINGDISTANCE_SSSE3) + } else if (TestCpuFlag(kCpuHasSSSE3)) { + h1 = HammingDistance_SSSE3(src_a, src_b, kMaxWidth); +#endif + } else { + h1 = HammingDistance_C(src_a, src_b, kMaxWidth); } #elif defined(HAS_HAMMINGDISTANCE_SSE42) - int has_sse42 = TestCpuFlag(kCpuHasSSE42); - if (has_sse42) { + if (TestCpuFlag(kCpuHasSSE42)) { h1 = HammingDistance_SSE42(src_a, src_b, kMaxWidth); } else { h1 = HammingDistance_C(src_a, src_b, kMaxWidth); } +#elif defined(HAS_HAMMINGDISTANCE_RVV) + h1 = HammingDistance_RVV(src_a, src_b, kMaxWidth); +#elif defined(HAS_HAMMINGDISTANCE_LASX) + if (TestCpuFlag(kCpuHasLASX)) { + h1 = HammingDistance_LASX(src_a, src_b, kMaxWidth); + } else { + h1 = HammingDistance_LSX(src_a, src_b, kMaxWidth); + } +#elif defined(HAS_HAMMINGDISTANCE_LSX) + h1 = HammingDistance_LSX(src_a, src_b, kMaxWidth); +#elif defined(HAS_HAMMINGDISTANCE_WASMSIMD) + h1 = HammingDistance_WASMSIMD(src_a, src_b, kMaxWidth); +#elif defined(HAS_HAMMINGDISTANCE_HVX) + h1 = HammingDistance_HVX(src_a, src_b, kMaxWidth); #else h1 = HammingDistance_C(src_a, src_b, kMaxWidth); #endif @@ -389,7 +511,7 @@ TEST_F(LibYUVCompareTest, TestHammingDistance_Opt) { // result can not be expected to be correct. // TODO(fbarchard): Consider expecting the low 16 bits to match. if (kMaxWidth <= kMaxOptCount) { - EXPECT_EQ(kMaxWidth * 8U, h1); + ASSERT_EQ(kMaxWidth * 8U, h1); } else { if (kMaxWidth * 8ULL != static_cast(h1)) { printf( @@ -420,7 +542,7 @@ TEST_F(LibYUVCompareTest, TestHammingDistance) { h1 = ComputeHammingDistance(src_a, src_b, benchmark_width_ * benchmark_height_); } - EXPECT_EQ(benchmark_width_ * benchmark_height_ * 8ULL, h1); + ASSERT_EQ(benchmark_width_ * benchmark_height_ * 8ULL, h1); free_aligned_buffer_page_end(src_a); free_aligned_buffer_page_end(src_b); @@ -436,7 +558,7 @@ TEST_F(LibYUVCompareTest, BenchmarkSumSquareError_Opt) { memcpy(src_a, "test0123test4567", 16); memcpy(src_b, "tick0123tock4567", 16); uint64_t h1 = ComputeSumSquareError(src_a, src_b, 16); - EXPECT_EQ(790u, h1); + ASSERT_EQ(790u, h1); for (int i = 0; i < kMaxWidth; ++i) { src_a[i] = i; @@ -452,7 +574,7 @@ TEST_F(LibYUVCompareTest, BenchmarkSumSquareError_Opt) { h1 = ComputeSumSquareError(src_a, src_b, kMaxWidth); } - EXPECT_EQ(0u, h1); + ASSERT_EQ(0u, h1); free_aligned_buffer_page_end(src_a); free_aligned_buffer_page_end(src_b); @@ -468,18 +590,18 @@ TEST_F(LibYUVCompareTest, SumSquareError) { uint64_t err; err = ComputeSumSquareError(src_a, src_b, kMaxWidth); - EXPECT_EQ(0u, err); + ASSERT_EQ(0u, err); memset(src_a, 1, kMaxWidth); err = ComputeSumSquareError(src_a, src_b, kMaxWidth); - EXPECT_EQ(static_cast(err), kMaxWidth); + ASSERT_EQ(static_cast(err), kMaxWidth); memset(src_a, 190, kMaxWidth); memset(src_b, 193, kMaxWidth); err = ComputeSumSquareError(src_a, src_b, kMaxWidth); - EXPECT_EQ(static_cast(err), kMaxWidth * 3 * 3); + ASSERT_EQ(static_cast(err), kMaxWidth * 3 * 3); for (int i = 0; i < kMaxWidth; ++i) { src_a[i] = (fastrand() & 0xff); @@ -492,7 +614,51 @@ TEST_F(LibYUVCompareTest, SumSquareError) { MaskCpuFlags(benchmark_cpu_info_); uint64_t opt_err = ComputeSumSquareError(src_a, src_b, kMaxWidth); - EXPECT_EQ(c_err, opt_err); + ASSERT_EQ(c_err, opt_err); + + free_aligned_buffer_page_end(src_a); + free_aligned_buffer_page_end(src_b); +} + +// Test every count, aligned and unaligned, ending at the end of a page. +TEST_F(LibYUVCompareTest, TestCompareAnyCount) { + const int kMaxCount = 64 * 5 + 1; + align_buffer_page_end(src_a, kMaxCount + 1); + align_buffer_page_end(src_b, kMaxCount + 1); + MemRandomize(src_a, kMaxCount + 1); + MemRandomize(src_b, kMaxCount + 1); + + const int kCpuMasks[] = { + benchmark_cpu_info_, + benchmark_cpu_info_ & ~kCpuHasAVX512VNNI, + benchmark_cpu_info_ & ~(kCpuHasAVX512BW | kCpuHasAVX512VNNI), + benchmark_cpu_info_ & + ~(kCpuHasAVX2 | kCpuHasAVX512BW | kCpuHasAVX512VNNI), + }; + + for (int count = 0; count <= kMaxCount; ++count) { + for (int offset = 0; offset < 2; ++offset) { + const uint8_t* a = src_a + kMaxCount + 1 - count - offset; + const uint8_t* b = src_b + kMaxCount + 1 - count - offset; + MaskCpuFlags(disable_cpu_flags_); + uint32_t c_hash = HashDjb2(a, count, 5381); + uint64_t c_diff = ComputeHammingDistance(a, b, count); + uint64_t c_err = ComputeSumSquareError(a, b, count); + for (size_t m = 0; m < sizeof(kCpuMasks) / sizeof(kCpuMasks[0]); ++m) { + MaskCpuFlags(kCpuMasks[m]); + uint32_t opt_hash = HashDjb2(a, count, 5381); + uint64_t opt_diff = ComputeHammingDistance(a, b, count); + uint64_t opt_err = ComputeSumSquareError(a, b, count); + EXPECT_EQ(c_hash, opt_hash) + << "count " << count << " offset " << offset << " mask " << m; + EXPECT_EQ(c_diff, opt_diff) + << "count " << count << " offset " << offset << " mask " << m; + EXPECT_EQ(c_err, opt_err) + << "count " << count << " offset " << offset << " mask " << m; + } + MaskCpuFlags(benchmark_cpu_info_); + } + } free_aligned_buffer_page_end(src_a); free_aligned_buffer_page_end(src_b); @@ -517,7 +683,7 @@ TEST_F(LibYUVCompareTest, BenchmarkPsnr_Opt) { opt_time = (get_time() - opt_time) / benchmark_iterations_; printf("BenchmarkPsnr_Opt - %8.2f us opt\n", opt_time * 1e6); - EXPECT_EQ(0, 0); + ASSERT_EQ(0, 0); free_aligned_buffer_page_end(src_a); free_aligned_buffer_page_end(src_b); @@ -542,7 +708,7 @@ TEST_F(LibYUVCompareTest, BenchmarkPsnr_Unaligned) { opt_time = (get_time() - opt_time) / benchmark_iterations_; printf("BenchmarkPsnr_Opt - %8.2f us opt\n", opt_time * 1e6); - EXPECT_EQ(0, 0); + ASSERT_EQ(0, 0); free_aligned_buffer_page_end(src_a); free_aligned_buffer_page_end(src_b); @@ -564,7 +730,7 @@ TEST_F(LibYUVCompareTest, Psnr) { src_b + kSrcStride * b + b, kSrcStride, kSrcWidth, kSrcHeight); - EXPECT_EQ(err, kMaxPsnr); + ASSERT_EQ(err, kMaxPsnr); memset(src_a, 255, kSrcPlaneSize); @@ -572,7 +738,7 @@ TEST_F(LibYUVCompareTest, Psnr) { src_b + kSrcStride * b + b, kSrcStride, kSrcWidth, kSrcHeight); - EXPECT_EQ(err, 0.0); + ASSERT_EQ(err, 0.0); memset(src_a, 1, kSrcPlaneSize); @@ -580,8 +746,8 @@ TEST_F(LibYUVCompareTest, Psnr) { src_b + kSrcStride * b + b, kSrcStride, kSrcWidth, kSrcHeight); - EXPECT_GT(err, 48.0); - EXPECT_LT(err, 49.0); + ASSERT_GT(err, 48.0); + ASSERT_LT(err, 49.0); for (int i = 0; i < kSrcPlaneSize; ++i) { src_a[i] = i; @@ -591,9 +757,9 @@ TEST_F(LibYUVCompareTest, Psnr) { src_b + kSrcStride * b + b, kSrcStride, kSrcWidth, kSrcHeight); - EXPECT_GT(err, 2.0); + ASSERT_GT(err, 2.0); if (kSrcWidth * kSrcHeight >= 256) { - EXPECT_LT(err, 6.0); + ASSERT_LT(err, 6.0); } memset(src_a, 0, kSrcPlaneSize); @@ -619,13 +785,13 @@ TEST_F(LibYUVCompareTest, Psnr) { src_b + kSrcStride * b + b, kSrcStride, kSrcWidth, kSrcHeight); - EXPECT_EQ(opt_err, c_err); + ASSERT_EQ(opt_err, c_err); free_aligned_buffer_page_end(src_a); free_aligned_buffer_page_end(src_b); } -TEST_F(LibYUVCompareTest, DISABLED_BenchmarkSsim_Opt) { +TEST_F(LibYUVCompareTest, BenchmarkSsim_Opt) { align_buffer_page_end(src_a, benchmark_width_ * benchmark_height_); align_buffer_page_end(src_b, benchmark_width_ * benchmark_height_); for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { @@ -635,16 +801,82 @@ TEST_F(LibYUVCompareTest, DISABLED_BenchmarkSsim_Opt) { MaskCpuFlags(benchmark_cpu_info_); - double opt_time = get_time(); + double ssim = 0.0; for (int i = 0; i < benchmark_iterations_; ++i) { - CalcFrameSsim(src_a, benchmark_width_, src_b, benchmark_width_, - benchmark_width_, benchmark_height_); + ssim = CalcFrameSsim(src_a, benchmark_width_, src_b, benchmark_width_, + benchmark_width_, benchmark_height_); } - opt_time = (get_time() - opt_time) / benchmark_iterations_; - printf("BenchmarkSsim_Opt - %8.2f us opt\n", opt_time * 1e6); + if (benchmark_width_ > 8 && benchmark_height_ > 8) { + EXPECT_EQ(1.0, ssim); + } else { + EXPECT_EQ(0.0, ssim); + } - EXPECT_EQ(0, 0); // Pass if we get this far. + free_aligned_buffer_page_end(src_a); + free_aligned_buffer_page_end(src_b); +} + +TEST_F(LibYUVCompareTest, BenchmarkSsim_Unaligned) { + align_buffer_page_end(src_a, benchmark_width_ * benchmark_height_ + 1); + align_buffer_page_end(src_b, benchmark_width_ * benchmark_height_); + for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { + src_a[i + 1] = i; + src_b[i] = i; + } + + MaskCpuFlags(benchmark_cpu_info_); + + double ssim = 0.0; + for (int i = 0; i < benchmark_iterations_; ++i) { + ssim = CalcFrameSsim(src_a + 1, benchmark_width_, src_b, benchmark_width_, + benchmark_width_, benchmark_height_); + } + + if (benchmark_width_ > 8 && benchmark_height_ > 8) { + EXPECT_EQ(1.0, ssim); + } else { + EXPECT_EQ(0.0, ssim); + } + + free_aligned_buffer_page_end(src_a); + free_aligned_buffer_page_end(src_b); +} + +TEST_F(LibYUVCompareTest, TestSsimAnyWidth) { + const int kMaxWidth = 140; + const int kHeight = 16; + const int kPlaneSize = kMaxWidth * kHeight + 1; + align_buffer_page_end(src_a, kPlaneSize); + align_buffer_page_end(src_b, kPlaneSize); + for (int i = 0; i < kPlaneSize; ++i) { + src_a[i] = (i * 73 + 19) & 0xff; + src_b[i] = (i * 151 + 43) & 0xff; + } + + const int kCpuMasks[] = { + benchmark_cpu_info_, + benchmark_cpu_info_ & ~(kCpuHasAVX512BW | kCpuHasAVX512VNNI), + benchmark_cpu_info_ & + ~(kCpuHasAVX2 | kCpuHasAVX512BW | kCpuHasAVX512VNNI), + }; + + for (int width = 9; width <= kMaxWidth; ++width) { + for (int offset = 0; offset < 2; ++offset) { + const int size = width * kHeight; + const uint8_t* a = src_a + kPlaneSize - size - offset; + const uint8_t* b = src_b + kPlaneSize - size - offset; + MaskCpuFlags(disable_cpu_flags_); + double c_ssim = CalcFrameSsim(a, width, b, width, width, kHeight); + for (size_t m = 0; m < sizeof(kCpuMasks) / sizeof(kCpuMasks[0]); ++m) { + MaskCpuFlags(kCpuMasks[m]); + double opt_ssim = CalcFrameSsim(a, width, b, width, width, kHeight); + EXPECT_NEAR(c_ssim, opt_ssim, 1e-5) + << "width " << width << " offset " << offset << " mask " << m; + } + MaskCpuFlags(benchmark_cpu_info_); + } + } free_aligned_buffer_page_end(src_a); free_aligned_buffer_page_end(src_b); @@ -665,6 +897,7 @@ TEST_F(LibYUVCompareTest, Ssim) { printf("warning - Ssim size too small. Testing function executes.\n"); } + // Identical images: SSIM == 1.0. double err; err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, src_b + kSrcStride * b + b, kSrcStride, kSrcWidth, @@ -674,6 +907,7 @@ TEST_F(LibYUVCompareTest, Ssim) { EXPECT_EQ(err, 1.0); } + // Completely different constant images (255 vs 0): SSIM near 0. memset(src_a, 255, kSrcPlaneSize); err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, @@ -684,6 +918,7 @@ TEST_F(LibYUVCompareTest, Ssim) { EXPECT_LT(err, 0.0001); } + // Slightly different constant images (1 vs 0): SSIM ~ 0.84. memset(src_a, 1, kSrcPlaneSize); err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, @@ -691,10 +926,11 @@ TEST_F(LibYUVCompareTest, Ssim) { kSrcHeight); if (kSrcWidth > 8 && kSrcHeight > 8) { - EXPECT_GT(err, 0.0001); + EXPECT_GT(err, 0.8); EXPECT_LT(err, 0.9); } + // Gradient vs constant 0: SSIM near 0. for (int i = 0; i < kSrcPlaneSize; ++i) { src_a[i] = i; } @@ -708,28 +944,30 @@ TEST_F(LibYUVCompareTest, Ssim) { EXPECT_LT(err, 0.01); } + // Similar images (deterministic gradient + small perturbation): SSIM ~ 0.99. for (int i = b; i < (kSrcHeight + b); ++i) { for (int j = b; j < (kSrcWidth + b); ++j) { - src_a[(i * kSrcStride) + j] = (fastrand() & 0xff); - src_b[(i * kSrcStride) + j] = (fastrand() & 0xff); + uint8_t val = static_cast((i * 3 + j * 5) & 0xff); + src_a[(i * kSrcStride) + j] = val; + src_b[(i * kSrcStride) + j] = + static_cast((val + ((i ^ j) & 3)) & 0xff); } } MaskCpuFlags(disable_cpu_flags_); - double c_err, opt_err; - - c_err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, - src_b + kSrcStride * b + b, kSrcStride, kSrcWidth, - kSrcHeight); + double c_err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); MaskCpuFlags(benchmark_cpu_info_); - - opt_err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, - src_b + kSrcStride * b + b, kSrcStride, kSrcWidth, - kSrcHeight); + double opt_err = CalcFrameSsim(src_a + kSrcStride * b + b, kSrcStride, + src_b + kSrcStride * b + b, kSrcStride, + kSrcWidth, kSrcHeight); if (kSrcWidth > 8 && kSrcHeight > 8) { - EXPECT_EQ(opt_err, c_err); + EXPECT_GT(opt_err, 0.9); + EXPECT_LT(opt_err, 1.0); + EXPECT_NEAR(c_err, opt_err, 1e-5); } free_aligned_buffer_page_end(src_a); diff --git a/libs/libyuv/unit_test/convert_argb_test.cc b/libs/libyuv/unit_test/convert_argb_test.cc new file mode 100644 index 0000000000..a2e1ad547b --- /dev/null +++ b/libs/libyuv/unit_test/convert_argb_test.cc @@ -0,0 +1,3165 @@ +/* + * Copyright 2023 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include +#include + +#include "../unit_test/unit_test.h" +#include "libyuv/compare.h" +#include "libyuv/convert.h" +#include "libyuv/convert_argb.h" +#include "libyuv/convert_from.h" +#include "libyuv/convert_from_argb.h" +#include "libyuv/cpu_id.h" +#include "libyuv/planar_functions.h" +#include "libyuv/rotate.h" +#include "libyuv/video_common.h" + +#ifdef ENABLE_ROW_TESTS +#include "libyuv/row.h" /* For ARGBToAR30Row_AVX2 */ +#endif + +#if (defined(__riscv) && !defined(__clang__)) || defined(__hexagon__) +#define DISABLE_SLOW_TESTS +#undef ENABLE_FULL_TESTS +#undef ENABLE_ROW_TESTS +#define LEAN_TESTS +#endif + +// Some functions fail on big endian. Enable these tests on all cpus except +// PowerPC, but they are not optimized so disabled by default. +#if !defined(DISABLE_SLOW_TESTS) && !defined(__powerpc__) +#define LITTLE_ENDIAN_ONLY_TEST 1 +#endif +#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) +// SLOW TESTS are those that are unoptimized C code. +// FULL TESTS are optimized but test many variations of the same code. +#define ENABLE_FULL_TESTS +#endif + +namespace libyuv { + +// Alias to copy pixels as is +#define AR30ToAR30 ARGBCopy +#define ABGRToABGR ARGBCopy + +// subsample amount uses a divide. +#define SUBSAMPLE(v, a) ((((v) + (a) - 1)) / (a)) + +#define ALIGNINT(V, ALIGN) (((V) + (ALIGN) - 1) / (ALIGN) * (ALIGN)) + +#define TESTBPTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, \ + DST_SUBSAMP_Y, W1280, N, NEG, OFF, SRC_DEPTH, TILE_WIDTH, \ + TILE_HEIGHT) \ + TEST_F(LibYUVConvertTest, SRC_FMT_PLANAR##To##FMT_PLANAR##N) { \ + static_assert(SRC_BPC == 1 || SRC_BPC == 2, "SRC BPC unsupported"); \ + static_assert(DST_BPC == 1 || DST_BPC == 2, "DST BPC unsupported"); \ + static_assert(SRC_SUBSAMP_X == 1 || SRC_SUBSAMP_X == 2, \ + "SRC_SUBSAMP_X unsupported"); \ + static_assert(SRC_SUBSAMP_Y == 1 || SRC_SUBSAMP_Y == 2, \ + "SRC_SUBSAMP_Y unsupported"); \ + static_assert(DST_SUBSAMP_X == 1 || DST_SUBSAMP_X == 2, \ + "DST_SUBSAMP_X unsupported"); \ + static_assert(DST_SUBSAMP_Y == 1 || DST_SUBSAMP_Y == 2, \ + "DST_SUBSAMP_Y unsupported"); \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kSrcHalfWidth = SUBSAMPLE(kWidth, SRC_SUBSAMP_X); \ + const int kDstHalfWidth = SUBSAMPLE(kWidth, DST_SUBSAMP_X); \ + const int kDstHalfHeight = SUBSAMPLE(kHeight, DST_SUBSAMP_Y); \ + const int kPaddedWidth = (kWidth + (TILE_WIDTH - 1)) & ~(TILE_WIDTH - 1); \ + const int kPaddedHeight = \ + (kHeight + (TILE_HEIGHT - 1)) & ~(TILE_HEIGHT - 1); \ + const int kSrcHalfPaddedWidth = SUBSAMPLE(kPaddedWidth, SRC_SUBSAMP_X); \ + const int kSrcHalfPaddedHeight = SUBSAMPLE(kPaddedHeight, SRC_SUBSAMP_Y); \ + align_buffer_page_end(src_y, \ + kPaddedWidth * kPaddedHeight * SRC_BPC + OFF); \ + align_buffer_page_end( \ + src_uv, \ + kSrcHalfPaddedWidth * kSrcHalfPaddedHeight * SRC_BPC * 2 + OFF); \ + align_buffer_page_end(dst_y_c, kWidth * kHeight * DST_BPC); \ + align_buffer_page_end(dst_u_c, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + align_buffer_page_end(dst_v_c, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + align_buffer_page_end(dst_y_opt, kWidth * kHeight * DST_BPC); \ + align_buffer_page_end(dst_u_opt, \ + kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + align_buffer_page_end(dst_v_opt, \ + kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + SRC_T* src_y_p = reinterpret_cast(src_y + OFF); \ + SRC_T* src_uv_p = reinterpret_cast(src_uv + OFF); \ + for (int i = 0; i < kPaddedWidth * kPaddedHeight; ++i) { \ + src_y_p[i] = \ + (fastrand() & (((SRC_T)(-1)) << ((8 * SRC_BPC) - SRC_DEPTH))); \ + } \ + for (int i = 0; i < kSrcHalfPaddedWidth * kSrcHalfPaddedHeight * 2; ++i) { \ + src_uv_p[i] = \ + (fastrand() & (((SRC_T)(-1)) << ((8 * SRC_BPC) - SRC_DEPTH))); \ + } \ + memset(dst_y_c, 1, kWidth * kHeight * DST_BPC); \ + memset(dst_u_c, 2, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + memset(dst_v_c, 3, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + memset(dst_y_opt, 101, kWidth * kHeight * DST_BPC); \ + memset(dst_u_opt, 102, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + memset(dst_v_opt, 103, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + MaskCpuFlags(disable_cpu_flags_); \ + SRC_FMT_PLANAR##To##FMT_PLANAR( \ + src_y_p, kWidth, src_uv_p, kSrcHalfWidth * 2, \ + reinterpret_cast(dst_y_c), kWidth, \ + reinterpret_cast(dst_u_c), kDstHalfWidth, \ + reinterpret_cast(dst_v_c), kDstHalfWidth, kWidth, \ + NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + SRC_FMT_PLANAR##To##FMT_PLANAR( \ + src_y_p, kWidth, src_uv_p, kSrcHalfWidth * 2, \ + reinterpret_cast(dst_y_opt), kWidth, \ + reinterpret_cast(dst_u_opt), kDstHalfWidth, \ + reinterpret_cast(dst_v_opt), kDstHalfWidth, kWidth, \ + NEG kHeight); \ + } \ + for (int i = 0; i < kHeight * kWidth * DST_BPC; ++i) { \ + ASSERT_EQ(dst_y_c[i], dst_y_opt[i]); \ + } \ + for (int i = 0; i < kDstHalfWidth * kDstHalfHeight * DST_BPC; ++i) { \ + ASSERT_EQ(dst_u_c[i], dst_u_opt[i]); \ + ASSERT_EQ(dst_v_c[i], dst_v_opt[i]); \ + } \ + free_aligned_buffer_page_end(dst_y_c); \ + free_aligned_buffer_page_end(dst_u_c); \ + free_aligned_buffer_page_end(dst_v_c); \ + free_aligned_buffer_page_end(dst_y_opt); \ + free_aligned_buffer_page_end(dst_u_opt); \ + free_aligned_buffer_page_end(dst_v_opt); \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_uv); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTBPTOP(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, \ + DST_SUBSAMP_Y, SRC_DEPTH, TILE_WIDTH, TILE_HEIGHT) \ + TESTBPTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_ + 1, _Any, +, 0, SRC_DEPTH, TILE_WIDTH, \ + TILE_HEIGHT) \ + TESTBPTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _Unaligned, +, 2, SRC_DEPTH, TILE_WIDTH, \ + TILE_HEIGHT) \ + TESTBPTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _Invert, -, 0, SRC_DEPTH, TILE_WIDTH, \ + TILE_HEIGHT) \ + TESTBPTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0, SRC_DEPTH, TILE_WIDTH, TILE_HEIGHT) +#else +#define TESTBPTOP(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, \ + DST_SUBSAMP_Y, SRC_DEPTH, TILE_WIDTH, TILE_HEIGHT) \ + TESTBPTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0, SRC_DEPTH, TILE_WIDTH, TILE_HEIGHT) +#endif + +TESTBPTOP(NV12, uint8_t, 1, 2, 2, I420, uint8_t, 1, 2, 2, 8, 1, 1) +TESTBPTOP(NV21, uint8_t, 1, 2, 2, I420, uint8_t, 1, 2, 2, 8, 1, 1) +TESTBPTOP(MM21, uint8_t, 1, 2, 2, I420, uint8_t, 1, 2, 2, 8, 16, 32) +TESTBPTOP(P010, uint16_t, 2, 2, 2, I010, uint16_t, 2, 2, 2, 10, 1, 1) +TESTBPTOP(P012, uint16_t, 2, 2, 2, I012, uint16_t, 2, 2, 2, 12, 1, 1) +TESTBPTOP(P210, uint16_t, 2, 2, 1, I210, uint16_t, 2, 2, 1, 10, 1, 1) +TESTBPTOP(P410, uint16_t, 2, 1, 1, I410, uint16_t, 2, 1, 1, 10, 1, 1) +TESTBPTOP(P010, uint16_t, 2, 2, 2, I420, uint8_t, 1, 2, 2, 10, 1, 1) +TESTBPTOP(P210, uint16_t, 2, 2, 1, I420, uint8_t, 1, 2, 2, 10, 1, 1) +TESTBPTOP(P410, uint16_t, 2, 1, 1, I420, uint8_t, 1, 2, 2, 10, 1, 1) + +// Provide matrix wrappers for full range bt.709 +#define F420ToABGR(a, b, c, d, e, f, g, h, i, j) \ + I420ToARGBMatrix(a, b, e, f, c, d, g, h, &kYvuF709Constants, i, j) +#define F420ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I420ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuvF709Constants, i, j) +#define F422ToABGR(a, b, c, d, e, f, g, h, i, j) \ + I422ToARGBMatrix(a, b, e, f, c, d, g, h, &kYvuF709Constants, i, j) +#define F422ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I422ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuvF709Constants, i, j) +#define F444ToABGR(a, b, c, d, e, f, g, h, i, j) \ + I444ToARGBMatrix(a, b, e, f, c, d, g, h, &kYvuF709Constants, i, j) +#define F444ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I444ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuvF709Constants, i, j) + +// Provide matrix wrappers for full range bt.2020 +#define V420ToABGR(a, b, c, d, e, f, g, h, i, j) \ + I420ToARGBMatrix(a, b, e, f, c, d, g, h, &kYvuV2020Constants, i, j) +#define V420ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I420ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuvV2020Constants, i, j) +#define V422ToABGR(a, b, c, d, e, f, g, h, i, j) \ + I422ToARGBMatrix(a, b, e, f, c, d, g, h, &kYvuV2020Constants, i, j) +#define V422ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I422ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuvV2020Constants, i, j) +#define V444ToABGR(a, b, c, d, e, f, g, h, i, j) \ + I444ToARGBMatrix(a, b, e, f, c, d, g, h, &kYvuV2020Constants, i, j) +#define V444ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I444ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuvV2020Constants, i, j) + +#define I420ToARGBFilter(a, b, c, d, e, f, g, h, i, j) \ + I420ToARGBMatrixFilter(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j, \ + kFilterBilinear) +#define I422ToARGBFilter(a, b, c, d, e, f, g, h, i, j) \ + I422ToARGBMatrixFilter(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j, \ + kFilterBilinear) +#define I420ToRGB24Filter(a, b, c, d, e, f, g, h, i, j) \ + I420ToRGB24MatrixFilter(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j, \ + kFilterBilinear) +#define I422ToRGB24Filter(a, b, c, d, e, f, g, h, i, j) \ + I420ToRGB24MatrixFilter(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j, \ + kFilterBilinear) + +#define TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, W1280, N, NEG, OFF) \ + TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##N) { \ + const int kWidth = W1280; \ + const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ + const int kStrideB = ALIGNINT(kWidth * BPP_B, ALIGN); \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ + align_buffer_page_end(src_y, kWidth * kHeight + OFF); \ + align_buffer_page_end(src_u, kSizeUV + OFF); \ + align_buffer_page_end(src_v, kSizeUV + OFF); \ + align_buffer_page_end(dst_argb_c, kStrideB * kHeight + OFF); \ + align_buffer_page_end(dst_argb_opt, kStrideB * kHeight + OFF); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + src_y[i + OFF] = (fastrand() & 0xff); \ + } \ + for (int i = 0; i < kSizeUV; ++i) { \ + src_u[i + OFF] = (fastrand() & 0xff); \ + src_v[i + OFF] = (fastrand() & 0xff); \ + } \ + memset(dst_argb_c + OFF, 1, kStrideB * kHeight); \ + memset(dst_argb_opt + OFF, 101, kStrideB * kHeight); \ + MaskCpuFlags(disable_cpu_flags_); \ + double time0 = get_time(); \ + FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ + src_v + OFF, kStrideUV, dst_argb_c + OFF, kStrideB, \ + kWidth, NEG kHeight); \ + double time1 = get_time(); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ + src_v + OFF, kStrideUV, dst_argb_opt + OFF, \ + kStrideB, kWidth, NEG kHeight); \ + } \ + double time2 = get_time(); \ + printf(" %8d us C - %8d us OPT\n", \ + static_cast((time1 - time0) * 1e6), \ + static_cast((time2 - time1) * 1e6 / benchmark_iterations_)); \ + for (int i = 0; i < kWidth * BPP_B * kHeight; ++i) { \ + ASSERT_EQ(dst_argb_c[i + OFF], dst_argb_opt[i + OFF]); \ + } \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_u); \ + free_aligned_buffer_page_end(src_v); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTPLANARTOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN) \ + TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_ + 1, _Any, +, 0) \ + TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Unaligned, +, 4) \ + TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Invert, -, 0) \ + TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Opt, +, 0) +#else +#define TESTPLANARTOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN) \ + TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Opt, +, 0) +#endif + +#if defined(ENABLE_FULL_TESTS) +TESTPLANARTOB(I420, 2, 2, ARGB, 4, 4, 1) +TESTPLANARTOB(I420, 2, 2, ABGR, 4, 4, 1) +TESTPLANARTOB(J420, 2, 2, ARGB, 4, 4, 1) +TESTPLANARTOB(J420, 2, 2, ABGR, 4, 4, 1) +TESTPLANARTOB(F420, 2, 2, ARGB, 4, 4, 1) +TESTPLANARTOB(F420, 2, 2, ABGR, 4, 4, 1) +TESTPLANARTOB(H420, 2, 2, ARGB, 4, 4, 1) +TESTPLANARTOB(H420, 2, 2, ABGR, 4, 4, 1) +TESTPLANARTOB(U420, 2, 2, ARGB, 4, 4, 1) +TESTPLANARTOB(U420, 2, 2, ABGR, 4, 4, 1) +TESTPLANARTOB(V420, 2, 2, ARGB, 4, 4, 1) +TESTPLANARTOB(V420, 2, 2, ABGR, 4, 4, 1) +TESTPLANARTOB(I420, 2, 2, BGRA, 4, 4, 1) +TESTPLANARTOB(I420, 2, 2, RGBA, 4, 4, 1) +TESTPLANARTOB(I420, 2, 2, RAW, 3, 3, 1) +TESTPLANARTOB(I420, 2, 2, RGB24, 3, 3, 1) +TESTPLANARTOB(J420, 2, 2, RAW, 3, 3, 1) +TESTPLANARTOB(J420, 2, 2, RGB24, 3, 3, 1) +TESTPLANARTOB(H420, 2, 2, RAW, 3, 3, 1) +TESTPLANARTOB(H420, 2, 2, RGB24, 3, 3, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTPLANARTOB(I420, 2, 2, RGB565, 2, 2, 1) +TESTPLANARTOB(J420, 2, 2, RGB565, 2, 2, 1) +TESTPLANARTOB(H420, 2, 2, RGB565, 2, 2, 1) +TESTPLANARTOB(I420, 2, 2, ARGB1555, 2, 2, 1) +TESTPLANARTOB(I420, 2, 2, ARGB4444, 2, 2, 1) +TESTPLANARTOB(I422, 2, 1, RGB565, 2, 2, 1) +#endif +TESTPLANARTOB(I422, 2, 1, ARGB, 4, 4, 1) +TESTPLANARTOB(I422, 2, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(J422, 2, 1, ARGB, 4, 4, 1) +TESTPLANARTOB(J422, 2, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(H422, 2, 1, ARGB, 4, 4, 1) +TESTPLANARTOB(H422, 2, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(U422, 2, 1, ARGB, 4, 4, 1) +TESTPLANARTOB(U422, 2, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(V422, 2, 1, ARGB, 4, 4, 1) +TESTPLANARTOB(V422, 2, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(I422, 2, 1, BGRA, 4, 4, 1) +TESTPLANARTOB(I422, 2, 1, RGBA, 4, 4, 1) +TESTPLANARTOB(I422, 2, 1, RGB24, 3, 3, 1) +TESTPLANARTOB(I422, 2, 1, RAW, 3, 3, 1) +TESTPLANARTOB(I444, 1, 1, ARGB, 4, 4, 1) +TESTPLANARTOB(I444, 1, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(I444, 1, 1, RGB24, 3, 3, 1) +TESTPLANARTOB(I444, 1, 1, RAW, 3, 3, 1) +TESTPLANARTOB(J444, 1, 1, ARGB, 4, 4, 1) +TESTPLANARTOB(J444, 1, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(H444, 1, 1, ARGB, 4, 4, 1) +TESTPLANARTOB(H444, 1, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(U444, 1, 1, ARGB, 4, 4, 1) +TESTPLANARTOB(U444, 1, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(V444, 1, 1, ARGB, 4, 4, 1) +TESTPLANARTOB(V444, 1, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(I420, 2, 2, YUY2, 2, 4, 1) +TESTPLANARTOB(I420, 2, 2, UYVY, 2, 4, 1) +TESTPLANARTOB(I422, 2, 1, YUY2, 2, 4, 1) +TESTPLANARTOB(I422, 2, 1, UYVY, 2, 4, 1) +TESTPLANARTOB(I420, 2, 2, I400, 1, 1, 1) +TESTPLANARTOB(J420, 2, 2, J400, 1, 1, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTPLANARTOB(I420, 2, 2, AR30, 4, 4, 1) +TESTPLANARTOB(H420, 2, 2, AR30, 4, 4, 1) +TESTPLANARTOB(I420, 2, 2, AB30, 4, 4, 1) +TESTPLANARTOB(H420, 2, 2, AB30, 4, 4, 1) +#endif +TESTPLANARTOB(I420, 2, 2, ARGBFilter, 4, 4, 1) +TESTPLANARTOB(I422, 2, 1, ARGBFilter, 4, 4, 1) +TESTPLANARTOB(I420, 2, 2, RGB24Filter, 3, 3, 1) +TESTPLANARTOB(I422, 2, 2, RGB24Filter, 3, 3, 1) +#else // FULL_TESTS +TESTPLANARTOB(I420, 2, 2, ABGR, 4, 4, 1) +TESTPLANARTOB(I420, 2, 2, ARGB, 4, 4, 1) +TESTPLANARTOB(I420, 2, 2, BGRA, 4, 4, 1) +TESTPLANARTOB(I420, 2, 2, RAW, 3, 3, 1) +TESTPLANARTOB(I420, 2, 2, RGB24, 3, 3, 1) +TESTPLANARTOB(I420, 2, 2, RGBA, 4, 4, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTPLANARTOB(I420, 2, 2, RGB565, 2, 2, 1) +TESTPLANARTOB(I420, 2, 2, ARGB1555, 2, 2, 1) +TESTPLANARTOB(I420, 2, 2, ARGB4444, 2, 2, 1) +TESTPLANARTOB(I422, 2, 1, RGB565, 2, 2, 1) +#endif +TESTPLANARTOB(I420, 2, 2, I400, 1, 1, 1) +TESTPLANARTOB(I420, 2, 2, UYVY, 2, 4, 1) +TESTPLANARTOB(I420, 2, 2, YUY2, 2, 4, 1) +TESTPLANARTOB(I422, 2, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(I422, 2, 1, ARGB, 4, 4, 1) +TESTPLANARTOB(I422, 2, 1, BGRA, 4, 4, 1) +TESTPLANARTOB(I422, 2, 1, RGBA, 4, 4, 1) +TESTPLANARTOB(I422, 2, 1, UYVY, 2, 4, 1) +TESTPLANARTOB(I422, 2, 1, YUY2, 2, 4, 1) +TESTPLANARTOB(I420, 2, 2, ARGBFilter, 4, 4, 1) +TESTPLANARTOB(I422, 2, 1, ARGBFilter, 4, 4, 1) +TESTPLANARTOB(I420, 2, 2, RGB24Filter, 3, 3, 1) +TESTPLANARTOB(I444, 1, 1, ABGR, 4, 4, 1) +TESTPLANARTOB(I444, 1, 1, ARGB, 4, 4, 1) +#endif + +#define TESTBPTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B, \ + W1280, N, NEG, OFF) \ + TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kStrideB = kWidth * BPP_B; \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + align_buffer_page_end(src_y, kWidth * kHeight + OFF); \ + align_buffer_page_end( \ + src_uv, kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y) * 2 + OFF); \ + align_buffer_page_end(dst_argb_c, kStrideB * kHeight); \ + align_buffer_page_end(dst_argb_opt, kStrideB * kHeight); \ + for (int i = 0; i < kHeight; ++i) \ + for (int j = 0; j < kWidth; ++j) \ + src_y[i * kWidth + j + OFF] = (fastrand() & 0xff); \ + for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ + for (int j = 0; j < kStrideUV * 2; ++j) { \ + src_uv[i * kStrideUV * 2 + j + OFF] = (fastrand() & 0xff); \ + } \ + } \ + memset(dst_argb_c, 1, kStrideB * kHeight); \ + memset(dst_argb_opt, 101, kStrideB * kHeight); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_uv + OFF, kStrideUV * 2, \ + dst_argb_c, kWidth * BPP_B, kWidth, NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_uv + OFF, kStrideUV * 2, \ + dst_argb_opt, kWidth * BPP_B, kWidth, \ + NEG kHeight); \ + } \ + /* Convert to ARGB so 565 is expanded to bytes that can be compared. */ \ + align_buffer_page_end(dst_argb32_c, kWidth * 4 * kHeight); \ + align_buffer_page_end(dst_argb32_opt, kWidth * 4 * kHeight); \ + memset(dst_argb32_c, 2, kWidth * 4 * kHeight); \ + memset(dst_argb32_opt, 102, kWidth * 4 * kHeight); \ + FMT_C##ToARGB(dst_argb_c, kStrideB, dst_argb32_c, kWidth * 4, kWidth, \ + kHeight); \ + FMT_C##ToARGB(dst_argb_opt, kStrideB, dst_argb32_opt, kWidth * 4, kWidth, \ + kHeight); \ + for (int i = 0; i < kHeight; ++i) { \ + for (int j = 0; j < kWidth * 4; ++j) { \ + ASSERT_EQ(dst_argb32_c[i * kWidth * 4 + j], \ + dst_argb32_opt[i * kWidth * 4 + j]); \ + } \ + } \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_uv); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + free_aligned_buffer_page_end(dst_argb32_c); \ + free_aligned_buffer_page_end(dst_argb32_opt); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTBPTOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B) \ + TESTBPTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B, \ + benchmark_width_ + 1, _Any, +, 0) \ + TESTBPTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B, \ + benchmark_width_, _Unaligned, +, 2) \ + TESTBPTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B, \ + benchmark_width_, _Invert, -, 0) \ + TESTBPTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B, \ + benchmark_width_, _Opt, +, 0) +#else +#define TESTBPTOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B) \ + TESTBPTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B, \ + benchmark_width_, _Opt, +, 0) +#endif + +#define JNV12ToARGB(a, b, c, d, e, f, g, h) \ + NV12ToARGBMatrix(a, b, c, d, e, f, &kYuvJPEGConstants, g, h) +#define JNV21ToARGB(a, b, c, d, e, f, g, h) \ + NV21ToARGBMatrix(a, b, c, d, e, f, &kYuvJPEGConstants, g, h) +#define JNV12ToABGR(a, b, c, d, e, f, g, h) \ + NV12ToABGRMatrix(a, b, c, d, e, f, &kYuvJPEGConstants, g, h) +#define JNV21ToABGR(a, b, c, d, e, f, g, h) \ + NV21ToABGRMatrix(a, b, c, d, e, f, &kYuvJPEGConstants, g, h) +#define JNV12ToRGB24(a, b, c, d, e, f, g, h) \ + NV12ToRGB24Matrix(a, b, c, d, e, f, &kYuvJPEGConstants, g, h) +#define JNV21ToRGB24(a, b, c, d, e, f, g, h) \ + NV21ToRGB24Matrix(a, b, c, d, e, f, &kYuvJPEGConstants, g, h) +#define JNV12ToRAW(a, b, c, d, e, f, g, h) \ + NV12ToRAWMatrix(a, b, c, d, e, f, &kYuvJPEGConstants, g, h) +#define JNV21ToRAW(a, b, c, d, e, f, g, h) \ + NV21ToRAWMatrix(a, b, c, d, e, f, &kYuvJPEGConstants, g, h) +#define JNV12ToRGB565(a, b, c, d, e, f, g, h) \ + NV12ToRGB565Matrix(a, b, c, d, e, f, &kYuvJPEGConstants, g, h) + +TESTBPTOB(JNV12, 2, 2, ARGB, ARGB, 4) +TESTBPTOB(JNV21, 2, 2, ARGB, ARGB, 4) +TESTBPTOB(JNV12, 2, 2, ABGR, ABGR, 4) +TESTBPTOB(JNV21, 2, 2, ABGR, ABGR, 4) +TESTBPTOB(JNV12, 2, 2, RGB24, RGB24, 3) +TESTBPTOB(JNV21, 2, 2, RGB24, RGB24, 3) +TESTBPTOB(JNV12, 2, 2, RAW, RAW, 3) +TESTBPTOB(JNV21, 2, 2, RAW, RAW, 3) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTBPTOB(JNV12, 2, 2, RGB565, RGB565, 2) +#endif + +TESTBPTOB(NV12, 2, 2, ARGB, ARGB, 4) +TESTBPTOB(NV21, 2, 2, ARGB, ARGB, 4) +TESTBPTOB(NV12, 2, 2, ABGR, ABGR, 4) +TESTBPTOB(NV21, 2, 2, ABGR, ABGR, 4) +TESTBPTOB(NV12, 2, 2, RGB24, RGB24, 3) +TESTBPTOB(NV21, 2, 2, RGB24, RGB24, 3) +TESTBPTOB(NV12, 2, 2, RAW, RAW, 3) +TESTBPTOB(NV21, 2, 2, RAW, RAW, 3) +TESTBPTOB(NV21, 2, 2, YUV24, RAW, 3) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTBPTOB(NV12, 2, 2, RGB565, RGB565, 2) +#endif + +#define TESTBP16TOBTRANSITIVE(FMT_BP, FMT_PLANAR) \ + TEST_F(LibYUVConvertTest, FMT_BP##ToARGB_Matches##FMT_PLANAR) { \ + const int kWidth = benchmark_width_ | 1; \ + const int kHeight = benchmark_height_; \ + const int kPixels = kWidth * kHeight; \ + align_buffer_page_end(src_y, kPixels * 2); \ + align_buffer_page_end(src_uv, kPixels * 4); \ + align_buffer_page_end(plane_y, kPixels * 2); \ + align_buffer_page_end(plane_u, kPixels * 2); \ + align_buffer_page_end(plane_v, kPixels * 2); \ + align_buffer_page_end(dst_bp, kPixels * 4); \ + align_buffer_page_end(dst_planar, kPixels * 4); \ + uint16_t* src_y16 = reinterpret_cast(src_y); \ + uint16_t* src_uv16 = reinterpret_cast(src_uv); \ + uint16_t* plane_y16 = reinterpret_cast(plane_y); \ + uint16_t* plane_u16 = reinterpret_cast(plane_u); \ + uint16_t* plane_v16 = reinterpret_cast(plane_v); \ + for (int i = 0; i < kPixels; ++i) { \ + src_y16[i] = static_cast((fastrand() & 0x3ff) << 6); \ + } \ + for (int i = 0; i < kPixels * 2; ++i) { \ + src_uv16[i] = static_cast((fastrand() & 0x3ff) << 6); \ + } \ + EXPECT_EQ(0, FMT_BP##To##FMT_PLANAR(src_y16, kWidth, src_uv16, kWidth * 2, \ + plane_y16, kWidth, plane_u16, kWidth, \ + plane_v16, kWidth, kWidth, kHeight)); \ + EXPECT_EQ(0, FMT_BP##ToARGBMatrix(src_y16, kWidth, src_uv16, kWidth * 2, \ + dst_bp, kWidth * 4, &kYuvI601Constants, \ + kWidth, kHeight)); \ + EXPECT_EQ( \ + 0, FMT_PLANAR##ToARGBMatrix(plane_y16, kWidth, plane_u16, kWidth, \ + plane_v16, kWidth, dst_planar, kWidth * 4, \ + &kYuvI601Constants, kWidth, kHeight)); \ + int max_diff = 0; \ + for (int i = 0; i < kPixels * 4; ++i) { \ + const int diff = Abs(dst_bp[i] - dst_planar[i]); \ + if (diff > max_diff) { \ + max_diff = diff; \ + } \ + } \ + EXPECT_LE(max_diff, 1); \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_uv); \ + free_aligned_buffer_page_end(plane_y); \ + free_aligned_buffer_page_end(plane_u); \ + free_aligned_buffer_page_end(plane_v); \ + free_aligned_buffer_page_end(dst_bp); \ + free_aligned_buffer_page_end(dst_planar); \ + } + +TESTBP16TOBTRANSITIVE(P010, I010) +TESTBP16TOBTRANSITIVE(P210, I210) +TESTBP16TOBTRANSITIVE(P410, I410) + +#define TESTATOBI(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, \ + EPP_B, STRIDE_B, HEIGHT_B, W1280, N, NEG, OFF) \ + TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ + const int kHeightB = (kHeight + HEIGHT_B - 1) / HEIGHT_B * HEIGHT_B; \ + const int kStrideA = \ + (kWidth * EPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ + const int kStrideB = \ + (kWidth * EPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ + align_buffer_page_end(src_argb, \ + (size_t)kStrideA * kHeightA * sizeof(TYPE_A) + OFF); \ + align_buffer_page_end(dst_argb_c, \ + (size_t)kStrideB * kHeightB * sizeof(TYPE_B)); \ + align_buffer_page_end(dst_argb_opt, \ + (size_t)kStrideB * kHeightB * sizeof(TYPE_B)); \ + for (size_t i = 0; i < (size_t)kStrideA * kHeightA * sizeof(TYPE_A); \ + ++i) { \ + src_argb[i + OFF] = (fastrand() & 0xff); \ + } \ + memset(dst_argb_c, 1, (size_t)kStrideB * kHeightB * sizeof(TYPE_B)); \ + memset(dst_argb_opt, 101, (size_t)kStrideB * kHeightB * sizeof(TYPE_B)); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_A##To##FMT_B((TYPE_A*)(src_argb + OFF), kStrideA, (TYPE_B*)dst_argb_c, \ + kStrideB, kWidth, NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_A##To##FMT_B((TYPE_A*)(src_argb + OFF), kStrideA, \ + (TYPE_B*)dst_argb_opt, kStrideB, kWidth, NEG kHeight); \ + } \ + for (size_t i = 0; i < (size_t)kStrideB * kHeightB * sizeof(TYPE_B); \ + ++i) { \ + ASSERT_EQ(dst_argb_c[i], dst_argb_opt[i]); \ + } \ + free_aligned_buffer_page_end(src_argb); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + } + +#define TESTATOBRANDOM(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, \ + TYPE_B, EPP_B, STRIDE_B, HEIGHT_B) \ + TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##_Random) { \ + for (int times = 0; times < benchmark_iterations_; ++times) { \ + const int kWidth = (fastrand() & 63) + 1; \ + const int kHeight = (fastrand() & 31) + 1; \ + const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ + const int kHeightB = (kHeight + HEIGHT_B - 1) / HEIGHT_B * HEIGHT_B; \ + const int kStrideA = \ + (kWidth * EPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ + const int kStrideB = \ + (kWidth * EPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ + align_buffer_page_end(src_argb, \ + (size_t)kStrideA * kHeightA * sizeof(TYPE_A)); \ + align_buffer_page_end(dst_argb_c, \ + (size_t)kStrideB * kHeightB * sizeof(TYPE_B)); \ + align_buffer_page_end(dst_argb_opt, \ + (size_t)kStrideB * kHeightB * sizeof(TYPE_B)); \ + for (size_t i = 0; i < (size_t)kStrideA * kHeightA * sizeof(TYPE_A); \ + ++i) { \ + src_argb[i] = 0xfe; \ + } \ + memset(dst_argb_c, 123, (size_t)kStrideB * kHeightB * sizeof(TYPE_B)); \ + memset(dst_argb_opt, 123, (size_t)kStrideB * kHeightB * sizeof(TYPE_B)); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_A##To##FMT_B((TYPE_A*)src_argb, kStrideA, (TYPE_B*)dst_argb_c, \ + kStrideB, kWidth, kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + FMT_A##To##FMT_B((TYPE_A*)src_argb, kStrideA, (TYPE_B*)dst_argb_opt, \ + kStrideB, kWidth, kHeight); \ + for (size_t i = 0; i < (size_t)kStrideB * kHeightB * sizeof(TYPE_B); \ + ++i) { \ + ASSERT_EQ(dst_argb_c[i], dst_argb_opt[i]); \ + } \ + free_aligned_buffer_page_end(src_argb); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + } \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTATOB(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, \ + EPP_B, STRIDE_B, HEIGHT_B) \ + TESTATOBI(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, EPP_B, \ + STRIDE_B, HEIGHT_B, benchmark_width_ + 1, _Any, +, 0) \ + TESTATOBI(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, EPP_B, \ + STRIDE_B, HEIGHT_B, benchmark_width_, _Unaligned, +, 4) \ + TESTATOBI(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, EPP_B, \ + STRIDE_B, HEIGHT_B, benchmark_width_, _Invert, -, 0) \ + TESTATOBI(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, EPP_B, \ + STRIDE_B, HEIGHT_B, benchmark_width_, _Opt, +, 0) \ + TESTATOBRANDOM(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, \ + EPP_B, STRIDE_B, HEIGHT_B) +#else +#define TESTATOB(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, \ + EPP_B, STRIDE_B, HEIGHT_B) \ + TESTATOBI(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, EPP_B, \ + STRIDE_B, HEIGHT_B, benchmark_width_, _Opt, +, 0) +#endif + +TESTATOB(AB30, uint8_t, 4, 4, 1, ABGR, uint8_t, 4, 4, 1) +TESTATOB(AB30, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOB(ABGR, uint8_t, 4, 4, 1, AR30, uint8_t, 4, 4, 1) +#endif +TESTATOB(ABGR, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOB(AR30, uint8_t, 4, 4, 1, AB30, uint8_t, 4, 4, 1) +#endif +TESTATOB(AR30, uint8_t, 4, 4, 1, ABGR, uint8_t, 4, 4, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOB(AR30, uint8_t, 4, 4, 1, AR30, uint8_t, 4, 4, 1) +TESTATOB(AR30, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +#endif +TESTATOB(ARGB, uint8_t, 4, 4, 1, ABGR, uint8_t, 4, 4, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOB(ARGB, uint8_t, 4, 4, 1, AR30, uint8_t, 4, 4, 1) +#endif +TESTATOB(ARGB, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, ARGB1555, uint8_t, 2, 2, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, ARGB4444, uint8_t, 2, 2, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, ARGBMirror, uint8_t, 4, 4, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, BGRA, uint8_t, 4, 4, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, I400, uint8_t, 1, 1, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, J400, uint8_t, 1, 1, 1) +TESTATOB(ABGR, uint8_t, 4, 4, 1, J400, uint8_t, 1, 1, 1) +TESTATOB(RGBA, uint8_t, 4, 4, 1, J400, uint8_t, 1, 1, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, RAW, uint8_t, 3, 3, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, RGB24, uint8_t, 3, 3, 1) +TESTATOB(ABGR, uint8_t, 4, 4, 1, RAW, uint8_t, 3, 3, 1) +TESTATOB(ABGR, uint8_t, 4, 4, 1, RGB24, uint8_t, 3, 3, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOB(ARGB, uint8_t, 4, 4, 1, RGB565, uint8_t, 2, 2, 1) +#endif +TESTATOB(ARGB, uint8_t, 4, 4, 1, RGBA, uint8_t, 4, 4, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, UYVY, uint8_t, 2, 4, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, YUY2, uint8_t, 2, 4, 1) +TESTATOB(ARGB1555, uint8_t, 2, 2, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(ARGB4444, uint8_t, 2, 2, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(BGRA, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(I400, uint8_t, 1, 1, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(I400, uint8_t, 1, 1, 1, I400, uint8_t, 1, 1, 1) +TESTATOB(I400, uint8_t, 1, 1, 1, I400Mirror, uint8_t, 1, 1, 1) +TESTATOB(J400, uint8_t, 1, 1, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(J400, uint8_t, 1, 1, 1, J400, uint8_t, 1, 1, 1) +TESTATOB(RAW, uint8_t, 3, 3, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(RAW, uint8_t, 3, 3, 1, RGBA, uint8_t, 4, 4, 1) +TESTATOB(RAW, uint8_t, 3, 3, 1, RGB24, uint8_t, 3, 3, 1) +TESTATOB(RGB24, uint8_t, 3, 3, 1, RAW, uint8_t, 3, 3, 1) +TESTATOB(RGB24, uint8_t, 3, 3, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(RGB24, uint8_t, 3, 3, 1, J400, uint8_t, 1, 1, 1) +TESTATOB(RGB24, uint8_t, 3, 3, 1, RGB24Mirror, uint8_t, 3, 3, 1) +TESTATOB(RAW, uint8_t, 3, 3, 1, J400, uint8_t, 1, 1, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOB(RGB565, uint8_t, 2, 2, 1, ARGB, uint8_t, 4, 4, 1) +#endif +TESTATOB(RGBA, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(UYVY, uint8_t, 2, 4, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(YUY2, uint8_t, 2, 4, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(YUY2, uint8_t, 2, 4, 1, Y, uint8_t, 1, 1, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, AR64, uint16_t, 4, 4, 1) +TESTATOB(ARGB, uint8_t, 4, 4, 1, AB64, uint16_t, 4, 4, 1) +TESTATOB(ABGR, uint8_t, 4, 4, 1, AR64, uint16_t, 4, 4, 1) +TESTATOB(ABGR, uint8_t, 4, 4, 1, AB64, uint16_t, 4, 4, 1) +TESTATOB(AR64, uint16_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(AB64, uint16_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOB(AR64, uint16_t, 4, 4, 1, ABGR, uint8_t, 4, 4, 1) +TESTATOB(AB64, uint16_t, 4, 4, 1, ABGR, uint8_t, 4, 4, 1) +TESTATOB(AR64, uint16_t, 4, 4, 1, AB64, uint16_t, 4, 4, 1) +TESTATOB(AB64, uint16_t, 4, 4, 1, AR64, uint16_t, 4, 4, 1) + +// in place test +#define TESTATOAI(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, \ + EPP_B, STRIDE_B, HEIGHT_B, W1280, N, NEG, OFF) \ + TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ + const int kHeightB = (kHeight + HEIGHT_B - 1) / HEIGHT_B * HEIGHT_B; \ + const int kStrideA = \ + (kWidth * EPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ + const int kStrideB = \ + (kWidth * EPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ + align_buffer_page_end(src_argb, \ + kStrideA * kHeightA * (int)sizeof(TYPE_A) + OFF); \ + align_buffer_page_end(dst_argb_c, \ + kStrideA * kHeightA * (int)sizeof(TYPE_A) + OFF); \ + align_buffer_page_end(dst_argb_opt, \ + kStrideA * kHeightA * (int)sizeof(TYPE_A) + OFF); \ + for (int i = 0; i < kStrideA * kHeightA * (int)sizeof(TYPE_A); ++i) { \ + src_argb[i + OFF] = (fastrand() & 0xff); \ + } \ + memcpy(dst_argb_c + OFF, src_argb, \ + kStrideA * kHeightA * (int)sizeof(TYPE_A)); \ + memcpy(dst_argb_opt + OFF, src_argb, \ + kStrideA * kHeightA * (int)sizeof(TYPE_A)); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_A##To##FMT_B((TYPE_A*)(dst_argb_c /* src */ + OFF), kStrideA, \ + (TYPE_B*)dst_argb_c, kStrideB, kWidth, NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_A##To##FMT_B((TYPE_A*)(dst_argb_opt /* src */ + OFF), kStrideA, \ + (TYPE_B*)dst_argb_opt, kStrideB, kWidth, NEG kHeight); \ + } \ + memcpy(dst_argb_opt + OFF, src_argb, \ + kStrideA * kHeightA * (int)sizeof(TYPE_A)); \ + FMT_A##To##FMT_B((TYPE_A*)(dst_argb_opt /* src */ + OFF), kStrideA, \ + (TYPE_B*)dst_argb_opt, kStrideB, kWidth, NEG kHeight); \ + for (int i = 0; i < kStrideB * kHeightB * (int)sizeof(TYPE_B); ++i) { \ + ASSERT_EQ(dst_argb_c[i], dst_argb_opt[i]); \ + } \ + free_aligned_buffer_page_end(src_argb); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + } + +#define TESTATOA(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, \ + EPP_B, STRIDE_B, HEIGHT_B) \ + TESTATOAI(FMT_A, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, FMT_B, TYPE_B, EPP_B, \ + STRIDE_B, HEIGHT_B, benchmark_width_, _Inplace, +, 0) + +TESTATOA(AB30, uint8_t, 4, 4, 1, ABGR, uint8_t, 4, 4, 1) +TESTATOA(AB30, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOA(ABGR, uint8_t, 4, 4, 1, AR30, uint8_t, 4, 4, 1) +#endif +TESTATOA(ABGR, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOA(AR30, uint8_t, 4, 4, 1, AB30, uint8_t, 4, 4, 1) +#endif +TESTATOA(AR30, uint8_t, 4, 4, 1, ABGR, uint8_t, 4, 4, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOA(AR30, uint8_t, 4, 4, 1, AR30, uint8_t, 4, 4, 1) +TESTATOA(AR30, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +#endif +TESTATOA(ARGB, uint8_t, 4, 4, 1, ABGR, uint8_t, 4, 4, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOA(ARGB, uint8_t, 4, 4, 1, AR30, uint8_t, 4, 4, 1) +#endif +TESTATOA(ARGB, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOA(ARGB, uint8_t, 4, 4, 1, ARGB1555, uint8_t, 2, 2, 1) +TESTATOA(ARGB, uint8_t, 4, 4, 1, ARGB4444, uint8_t, 2, 2, 1) +// TODO(fbarchard): Support in place for mirror. +// TESTATOA(ARGB, uint8_t, 4, 4, 1, ARGBMirror, uint8_t, 4, 4, 1) +TESTATOA(ARGB, uint8_t, 4, 4, 1, BGRA, uint8_t, 4, 4, 1) +TESTATOA(ARGB, uint8_t, 4, 4, 1, I400, uint8_t, 1, 1, 1) +TESTATOA(ARGB, uint8_t, 4, 4, 1, J400, uint8_t, 1, 1, 1) +TESTATOA(RGBA, uint8_t, 4, 4, 1, J400, uint8_t, 1, 1, 1) +TESTATOA(ARGB, uint8_t, 4, 4, 1, RAW, uint8_t, 3, 3, 1) +TESTATOA(ARGB, uint8_t, 4, 4, 1, RGB24, uint8_t, 3, 3, 1) +TESTATOA(ABGR, uint8_t, 4, 4, 1, RAW, uint8_t, 3, 3, 1) +TESTATOA(ABGR, uint8_t, 4, 4, 1, RGB24, uint8_t, 3, 3, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOA(ARGB, uint8_t, 4, 4, 1, RGB565, uint8_t, 2, 2, 1) +#endif +TESTATOA(ARGB, uint8_t, 4, 4, 1, RGBA, uint8_t, 4, 4, 1) +TESTATOA(ARGB, uint8_t, 4, 4, 1, UYVY, uint8_t, 2, 4, 1) +TESTATOA(ARGB, uint8_t, 4, 4, 1, YUY2, uint8_t, 2, 4, 1) +// TODO(fbarchard): Support in place for conversions that increase bpp. +// TESTATOA(ARGB1555, uint8_t, 2, 2, 1, ARGB, uint8_t, 4, 4, 1) +// TESTATOA(ARGB4444, uint8_t, 2, 2, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOA(BGRA, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +// TESTATOA(I400, uint8_t, 1, 1, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOA(I400, uint8_t, 1, 1, 1, I400, uint8_t, 1, 1, 1) +// TESTATOA(I400, uint8_t, 1, 1, 1, I400Mirror, uint8_t, 1, 1, 1) +// TESTATOA(J400, uint8_t, 1, 1, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOA(J400, uint8_t, 1, 1, 1, J400, uint8_t, 1, 1, 1) +// TESTATOA(RAW, uint8_t, 3, 3, 1, ARGB, uint8_t, 4, 4, 1) +// TESTATOA(RAW, uint8_t, 3, 3, 1, RGBA, uint8_t, 4, 4, 1) +TESTATOA(RAW, uint8_t, 3, 3, 1, RGB24, uint8_t, 3, 3, 1) +// TESTATOA(RGB24, uint8_t, 3, 3, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOA(RGB24, uint8_t, 3, 3, 1, J400, uint8_t, 1, 1, 1) +// TESTATOA(RGB24, uint8_t, 3, 3, 1, RGB24Mirror, uint8_t, 3, 3, 1) +TESTATOA(RAW, uint8_t, 3, 3, 1, J400, uint8_t, 1, 1, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +// TESTATOA(RGB565, uint8_t, 2, 2, 1, ARGB, uint8_t, 4, 4, 1) +#endif +TESTATOA(RGBA, uint8_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +// TESTATOA(UYVY, uint8_t, 2, 4, 1, ARGB, uint8_t, 4, 4, 1) +// TESTATOA(YUY2, uint8_t, 2, 4, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOA(YUY2, uint8_t, 2, 4, 1, Y, uint8_t, 1, 1, 1) +// TESTATOA(ARGB, uint8_t, 4, 4, 1, AR64, uint16_t, 4, 4, 1) +// TESTATOA(ARGB, uint8_t, 4, 4, 1, AB64, uint16_t, 4, 4, 1) +// TESTATOA(ABGR, uint8_t, 4, 4, 1, AR64, uint16_t, 4, 4, 1) +// TESTATOA(ABGR, uint8_t, 4, 4, 1, AB64, uint16_t, 4, 4, 1) +TESTATOA(AR64, uint16_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOA(AB64, uint16_t, 4, 4, 1, ARGB, uint8_t, 4, 4, 1) +TESTATOA(AR64, uint16_t, 4, 4, 1, ABGR, uint8_t, 4, 4, 1) +TESTATOA(AB64, uint16_t, 4, 4, 1, ABGR, uint8_t, 4, 4, 1) +TESTATOA(AR64, uint16_t, 4, 4, 1, AB64, uint16_t, 4, 4, 1) +TESTATOA(AB64, uint16_t, 4, 4, 1, AR64, uint16_t, 4, 4, 1) + +#define TESTATOBDI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ + HEIGHT_B, W1280, N, NEG, OFF) \ + TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##Dither##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ + const int kHeightB = (kHeight + HEIGHT_B - 1) / HEIGHT_B * HEIGHT_B; \ + const int kStrideA = \ + (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ + const int kStrideB = \ + (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ + align_buffer_page_end(src_argb, (size_t)kStrideA * kHeightA + OFF); \ + align_buffer_page_end(dst_argb_c, (size_t)kStrideB * kHeightB); \ + align_buffer_page_end(dst_argb_opt, (size_t)kStrideB * kHeightB); \ + for (size_t i = 0; i < (size_t)kStrideA * kHeightA; ++i) { \ + src_argb[i + OFF] = (fastrand() & 0xff); \ + } \ + memset(dst_argb_c, 1, (size_t)kStrideB * kHeightB); \ + memset(dst_argb_opt, 101, (size_t)kStrideB * kHeightB); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_A##To##FMT_B##Dither(src_argb + OFF, kStrideA, dst_argb_c, kStrideB, \ + NULL, kWidth, NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_A##To##FMT_B##Dither(src_argb + OFF, kStrideA, dst_argb_opt, \ + kStrideB, NULL, kWidth, NEG kHeight); \ + } \ + for (size_t i = 0; i < (size_t)kStrideB * kHeightB; ++i) { \ + ASSERT_EQ(dst_argb_c[i], dst_argb_opt[i]); \ + } \ + free_aligned_buffer_page_end(src_argb); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + } + +#define TESTATOBDRANDOM(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, \ + STRIDE_B, HEIGHT_B) \ + TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##Dither_Random) { \ + for (int times = 0; times < benchmark_iterations_; ++times) { \ + const int kWidth = (fastrand() & 63) + 1; \ + const int kHeight = (fastrand() & 31) + 1; \ + const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ + const int kHeightB = (kHeight + HEIGHT_B - 1) / HEIGHT_B * HEIGHT_B; \ + const int kStrideA = \ + (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ + const int kStrideB = \ + (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ + align_buffer_page_end(src_argb, (size_t)kStrideA * kHeightA); \ + align_buffer_page_end(dst_argb_c, (size_t)kStrideB * kHeightB); \ + align_buffer_page_end(dst_argb_opt, (size_t)kStrideB * kHeightB); \ + for (size_t i = 0; i < (size_t)kStrideA * kHeightA; ++i) { \ + src_argb[i] = (fastrand() & 0xff); \ + } \ + memset(dst_argb_c, 123, (size_t)kStrideB * kHeightB); \ + memset(dst_argb_opt, 123, (size_t)kStrideB * kHeightB); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_A##To##FMT_B##Dither(src_argb, kStrideA, dst_argb_c, kStrideB, NULL, \ + kWidth, kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + FMT_A##To##FMT_B##Dither(src_argb, kStrideA, dst_argb_opt, kStrideB, \ + NULL, kWidth, kHeight); \ + for (size_t i = 0; i < (size_t)kStrideB * kHeightB; ++i) { \ + ASSERT_EQ(dst_argb_c[i], dst_argb_opt[i]); \ + } \ + free_aligned_buffer_page_end(src_argb); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + } \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTATOBD(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ + HEIGHT_B) \ + TESTATOBDI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ + HEIGHT_B, benchmark_width_ + 1, _Any, +, 0) \ + TESTATOBDI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ + HEIGHT_B, benchmark_width_, _Unaligned, +, 2) \ + TESTATOBDI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ + HEIGHT_B, benchmark_width_, _Invert, -, 0) \ + TESTATOBDI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ + HEIGHT_B, benchmark_width_, _Opt, +, 0) \ + TESTATOBDRANDOM(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ + HEIGHT_B) +#else +#define TESTATOBD(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ + HEIGHT_B) \ + TESTATOBDRANDOM(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ + HEIGHT_B) +#endif + +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOBD(ARGB, 4, 4, 1, RGB565, 2, 2, 1) +#endif + +// These conversions called twice, produce the original result. +// e.g. endian swap twice. +#define TESTENDI(FMT_ATOB, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, W1280, N, NEG, \ + OFF) \ + TEST_F(LibYUVConvertTest, FMT_ATOB##_Endswap##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ + const int kStrideA = \ + (kWidth * EPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ + align_buffer_page_end(src_argb, \ + (size_t)kStrideA * kHeightA * sizeof(TYPE_A) + OFF); \ + align_buffer_page_end(dst_argb_c, \ + (size_t)kStrideA * kHeightA * sizeof(TYPE_A)); \ + align_buffer_page_end(dst_argb_opt, \ + (size_t)kStrideA * kHeightA * sizeof(TYPE_A)); \ + for (size_t i = 0; i < (size_t)kStrideA * kHeightA * sizeof(TYPE_A); \ + ++i) { \ + src_argb[i + OFF] = (fastrand() & 0xff); \ + } \ + memset(dst_argb_c, 1, (size_t)kStrideA * kHeightA * sizeof(TYPE_A)); \ + memset(dst_argb_opt, 101, (size_t)kStrideA * kHeightA * sizeof(TYPE_A)); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_ATOB((TYPE_A*)(src_argb + OFF), kStrideA, (TYPE_A*)dst_argb_c, \ + kStrideA, kWidth, NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_ATOB((TYPE_A*)(src_argb + OFF), kStrideA, (TYPE_A*)dst_argb_opt, \ + kStrideA, kWidth, NEG kHeight); \ + } \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_ATOB((TYPE_A*)dst_argb_c, kStrideA, (TYPE_A*)dst_argb_c, kStrideA, \ + kWidth, NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + FMT_ATOB((TYPE_A*)dst_argb_opt, kStrideA, (TYPE_A*)dst_argb_opt, kStrideA, \ + kWidth, NEG kHeight); \ + for (size_t i = 0; i < (size_t)kStrideA * kHeightA * sizeof(TYPE_A); \ + ++i) { \ + ASSERT_EQ(src_argb[i + OFF], dst_argb_opt[i]); \ + ASSERT_EQ(dst_argb_c[i], dst_argb_opt[i]); \ + } \ + free_aligned_buffer_page_end(src_argb); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTEND(FMT_ATOB, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A) \ + TESTENDI(FMT_ATOB, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, benchmark_width_ + 1, \ + _Any, +, 0) \ + TESTENDI(FMT_ATOB, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, benchmark_width_, \ + _Unaligned, +, 2) \ + TESTENDI(FMT_ATOB, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, benchmark_width_, \ + _Opt, +, 0) +#else +#define TESTEND(FMT_ATOB, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A) \ + TESTENDI(FMT_ATOB, TYPE_A, EPP_A, STRIDE_A, HEIGHT_A, benchmark_width_, \ + _Opt, +, 0) +#endif + +TESTEND(ARGBToBGRA, uint8_t, 4, 4, 1) +TESTEND(ARGBToABGR, uint8_t, 4, 4, 1) +TESTEND(BGRAToARGB, uint8_t, 4, 4, 1) +TESTEND(ABGRToARGB, uint8_t, 4, 4, 1) +TESTEND(AB64ToAR64, uint16_t, 4, 4, 1) + +#define TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, W1280, N, NEG, OFF, ATTEN) \ + TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##N) { \ + const int kWidth = W1280; \ + const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ + const int kStrideB = ALIGNINT(kWidth * BPP_B, ALIGN); \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ + align_buffer_page_end(src_y, kWidth * kHeight + OFF); \ + align_buffer_page_end(src_u, kSizeUV + OFF); \ + align_buffer_page_end(src_v, kSizeUV + OFF); \ + align_buffer_page_end(src_a, kWidth * kHeight + OFF); \ + align_buffer_page_end(dst_argb_c, kStrideB * kHeight + OFF); \ + align_buffer_page_end(dst_argb_opt, kStrideB * kHeight + OFF); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + src_y[i + OFF] = (fastrand() & 0xff); \ + src_a[i + OFF] = (fastrand() & 0xff); \ + } \ + for (int i = 0; i < kSizeUV; ++i) { \ + src_u[i + OFF] = (fastrand() & 0xff); \ + src_v[i + OFF] = (fastrand() & 0xff); \ + } \ + memset(dst_argb_c + OFF, 1, kStrideB * kHeight); \ + memset(dst_argb_opt + OFF, 101, kStrideB * kHeight); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ + src_v + OFF, kStrideUV, src_a + OFF, kWidth, \ + dst_argb_c + OFF, kStrideB, kWidth, NEG kHeight, \ + ATTEN); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ + src_v + OFF, kStrideUV, src_a + OFF, kWidth, \ + dst_argb_opt + OFF, kStrideB, kWidth, NEG kHeight, \ + ATTEN); \ + } \ + for (int i = 0; i < kWidth * BPP_B * kHeight; ++i) { \ + ASSERT_EQ(dst_argb_c[i + OFF], dst_argb_opt[i + OFF]); \ + } \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_u); \ + free_aligned_buffer_page_end(src_v); \ + free_aligned_buffer_page_end(src_a); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTQPLANARTOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN) \ + TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_ + 1, _Any, +, 0, 0) \ + TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Unaligned, +, 2, 0) \ + TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Invert, -, 0, 0) \ + TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Opt, +, 0, 0) \ + TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Premult, +, 0, 1) +#else +#define TESTQPLANARTOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN) \ + TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Opt, +, 0, 0) +#endif + +#define J420AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I420AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define J420AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I420AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define F420AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I420AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define F420AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I420AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define H420AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I420AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define H420AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I420AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define U420AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I420AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define U420AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I420AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define V420AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I420AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) +#define V420AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I420AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) +#define J422AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I422AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define J422AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I422AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define F422AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I422AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define F422AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I422AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define H422AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I422AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define H422AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I422AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define U422AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I422AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define U422AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I422AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define V422AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I422AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) +#define V422AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I422AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) +#define J444AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I444AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define J444AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I444AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define F444AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I444AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define F444AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I444AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define H444AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I444AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define H444AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I444AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define U444AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I444AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define U444AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I444AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define V444AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I444AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) +#define V444AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I444AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) + +#define I420AlphaToARGBFilter(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I420AlphaToARGBMatrixFilter(a, b, c, d, e, f, g, h, i, j, \ + &kYuvI601Constants, k, l, m, kFilterBilinear) +#define I422AlphaToARGBFilter(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I422AlphaToARGBMatrixFilter(a, b, c, d, e, f, g, h, i, j, \ + &kYuvI601Constants, k, l, m, kFilterBilinear) + +#if defined(ENABLE_FULL_TESTS) +TESTQPLANARTOB(I420Alpha, 2, 2, ARGB, 4, 4, 1) +TESTQPLANARTOB(I420Alpha, 2, 2, ABGR, 4, 4, 1) +TESTQPLANARTOB(J420Alpha, 2, 2, ARGB, 4, 4, 1) +TESTQPLANARTOB(J420Alpha, 2, 2, ABGR, 4, 4, 1) +TESTQPLANARTOB(H420Alpha, 2, 2, ARGB, 4, 4, 1) +TESTQPLANARTOB(H420Alpha, 2, 2, ABGR, 4, 4, 1) +TESTQPLANARTOB(F420Alpha, 2, 2, ARGB, 4, 4, 1) +TESTQPLANARTOB(F420Alpha, 2, 2, ABGR, 4, 4, 1) +TESTQPLANARTOB(U420Alpha, 2, 2, ARGB, 4, 4, 1) +TESTQPLANARTOB(U420Alpha, 2, 2, ABGR, 4, 4, 1) +TESTQPLANARTOB(V420Alpha, 2, 2, ARGB, 4, 4, 1) +TESTQPLANARTOB(V420Alpha, 2, 2, ABGR, 4, 4, 1) +TESTQPLANARTOB(I422Alpha, 2, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(I422Alpha, 2, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(J422Alpha, 2, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(J422Alpha, 2, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(H422Alpha, 2, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(H422Alpha, 2, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(F422Alpha, 2, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(F422Alpha, 2, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(U422Alpha, 2, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(U422Alpha, 2, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(V422Alpha, 2, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(V422Alpha, 2, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(I444Alpha, 1, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(I444Alpha, 1, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(J444Alpha, 1, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(J444Alpha, 1, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(H444Alpha, 1, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(H444Alpha, 1, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(F444Alpha, 1, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(F444Alpha, 1, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(U444Alpha, 1, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(U444Alpha, 1, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(V444Alpha, 1, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(V444Alpha, 1, 1, ABGR, 4, 4, 1) +TESTQPLANARTOB(I420Alpha, 2, 2, ARGBFilter, 4, 4, 1) +TESTQPLANARTOB(I422Alpha, 2, 1, ARGBFilter, 4, 4, 1) +#else +TESTQPLANARTOB(I420Alpha, 2, 2, ARGB, 4, 4, 1) +TESTQPLANARTOB(I422Alpha, 2, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(I444Alpha, 1, 1, ARGB, 4, 4, 1) +TESTQPLANARTOB(I420Alpha, 2, 2, ARGBFilter, 4, 4, 1) +TESTQPLANARTOB(I422Alpha, 2, 1, ARGBFilter, 4, 4, 1) +#endif + +TEST_F(LibYUVConvertTest, TestYToARGB) { + uint8_t y[32]; + uint8_t expectedg[32]; + for (int i = 0; i < 32; ++i) { + y[i] = i * 5 + 17; + expectedg[i] = static_cast((y[i] - 16) * 1.164f + 0.5f); + } + uint8_t argb[32 * 4]; + YToARGB(y, 0, argb, 0, 32, 1); + + for (int i = 0; i < 32; ++i) { + printf("%2d %d: %d <-> %d,%d,%d,%d\n", i, y[i], expectedg[i], + argb[i * 4 + 0], argb[i * 4 + 1], argb[i * 4 + 2], argb[i * 4 + 3]); + } + for (int i = 0; i < 32; ++i) { + ASSERT_EQ(expectedg[i], argb[i * 4 + 0]); + } +} + +static const uint8_t kNoDither4x4[16] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + +TEST_F(LibYUVConvertTest, TestNoDither) { + align_buffer_page_end(src_argb, benchmark_width_ * benchmark_height_ * 4); + align_buffer_page_end(dst_rgb565, benchmark_width_ * benchmark_height_ * 2); + align_buffer_page_end(dst_rgb565dither, + benchmark_width_ * benchmark_height_ * 2); + MemRandomize(src_argb, benchmark_width_ * benchmark_height_ * 4); + MemRandomize(dst_rgb565, benchmark_width_ * benchmark_height_ * 2); + MemRandomize(dst_rgb565dither, benchmark_width_ * benchmark_height_ * 2); + ARGBToRGB565(src_argb, benchmark_width_ * 4, dst_rgb565, benchmark_width_ * 2, + benchmark_width_, benchmark_height_); + ARGBToRGB565Dither(src_argb, benchmark_width_ * 4, dst_rgb565dither, + benchmark_width_ * 2, kNoDither4x4, benchmark_width_, + benchmark_height_); + for (int i = 0; i < benchmark_width_ * benchmark_height_ * 2; ++i) { + ASSERT_EQ(dst_rgb565[i], dst_rgb565dither[i]); + } + + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(dst_rgb565); + free_aligned_buffer_page_end(dst_rgb565dither); +} + +// Ordered 4x4 dither for 888 to 565. Values from 0 to 7. +static const uint8_t kDither565_4x4[16] = { + 0, 4, 1, 5, 6, 2, 7, 3, 1, 5, 0, 4, 7, 3, 6, 2, +}; + +TEST_F(LibYUVConvertTest, TestDither) { + align_buffer_page_end(src_argb, benchmark_width_ * benchmark_height_ * 4); + align_buffer_page_end(dst_rgb565, benchmark_width_ * benchmark_height_ * 2); + align_buffer_page_end(dst_rgb565dither, + benchmark_width_ * benchmark_height_ * 2); + align_buffer_page_end(dst_argb, benchmark_width_ * benchmark_height_ * 4); + align_buffer_page_end(dst_argbdither, + benchmark_width_ * benchmark_height_ * 4); + MemRandomize(src_argb, benchmark_width_ * benchmark_height_ * 4); + MemRandomize(dst_rgb565, benchmark_width_ * benchmark_height_ * 2); + MemRandomize(dst_rgb565dither, benchmark_width_ * benchmark_height_ * 2); + MemRandomize(dst_argb, benchmark_width_ * benchmark_height_ * 4); + MemRandomize(dst_argbdither, benchmark_width_ * benchmark_height_ * 4); + ARGBToRGB565(src_argb, benchmark_width_ * 4, dst_rgb565, benchmark_width_ * 2, + benchmark_width_, benchmark_height_); + ARGBToRGB565Dither(src_argb, benchmark_width_ * 4, dst_rgb565dither, + benchmark_width_ * 2, kDither565_4x4, benchmark_width_, + benchmark_height_); + RGB565ToARGB(dst_rgb565, benchmark_width_ * 2, dst_argb, benchmark_width_ * 4, + benchmark_width_, benchmark_height_); + RGB565ToARGB(dst_rgb565dither, benchmark_width_ * 2, dst_argbdither, + benchmark_width_ * 4, benchmark_width_, benchmark_height_); + + for (int i = 0; i < benchmark_width_ * benchmark_height_ * 4; ++i) { + ASSERT_NEAR(dst_argb[i], dst_argbdither[i], 9); + } + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(dst_rgb565); + free_aligned_buffer_page_end(dst_rgb565dither); + free_aligned_buffer_page_end(dst_argb); + free_aligned_buffer_page_end(dst_argbdither); +} + +#define TESTPLANARTOBID(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, W1280, N, NEG, OFF, FMT_C, BPP_C) \ + TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##Dither##N) { \ + const int kWidth = W1280; \ + const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ + const int kStrideB = ALIGNINT(kWidth * BPP_B, ALIGN); \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ + align_buffer_page_end(src_y, kWidth * kHeight + OFF); \ + align_buffer_page_end(src_u, kSizeUV + OFF); \ + align_buffer_page_end(src_v, kSizeUV + OFF); \ + align_buffer_page_end(dst_argb_c, kStrideB * kHeight + OFF); \ + align_buffer_page_end(dst_argb_opt, kStrideB * kHeight + OFF); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + src_y[i + OFF] = (fastrand() & 0xff); \ + } \ + for (int i = 0; i < kSizeUV; ++i) { \ + src_u[i + OFF] = (fastrand() & 0xff); \ + src_v[i + OFF] = (fastrand() & 0xff); \ + } \ + memset(dst_argb_c + OFF, 1, kStrideB * kHeight); \ + memset(dst_argb_opt + OFF, 101, kStrideB * kHeight); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_PLANAR##To##FMT_B##Dither(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ + src_v + OFF, kStrideUV, dst_argb_c + OFF, \ + kStrideB, NULL, kWidth, NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_PLANAR##To##FMT_B##Dither( \ + src_y + OFF, kWidth, src_u + OFF, kStrideUV, src_v + OFF, kStrideUV, \ + dst_argb_opt + OFF, kStrideB, NULL, kWidth, NEG kHeight); \ + } \ + /* Convert to ARGB so 565 is expanded to bytes that can be compared. */ \ + align_buffer_page_end(dst_argb32_c, kWidth * BPP_C * kHeight); \ + align_buffer_page_end(dst_argb32_opt, kWidth * BPP_C * kHeight); \ + memset(dst_argb32_c, 2, kWidth * BPP_C * kHeight); \ + memset(dst_argb32_opt, 102, kWidth * BPP_C * kHeight); \ + FMT_B##To##FMT_C(dst_argb_c + OFF, kStrideB, dst_argb32_c, kWidth * BPP_C, \ + kWidth, kHeight); \ + FMT_B##To##FMT_C(dst_argb_opt + OFF, kStrideB, dst_argb32_opt, \ + kWidth * BPP_C, kWidth, kHeight); \ + for (int i = 0; i < kWidth * BPP_C * kHeight; ++i) { \ + ASSERT_EQ(dst_argb32_c[i], dst_argb32_opt[i]); \ + } \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_u); \ + free_aligned_buffer_page_end(src_v); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + free_aligned_buffer_page_end(dst_argb32_c); \ + free_aligned_buffer_page_end(dst_argb32_opt); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTPLANARTOBD(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, FMT_C, BPP_C) \ + TESTPLANARTOBID(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_ + 1, _Any, +, 0, FMT_C, BPP_C) \ + TESTPLANARTOBID(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Unaligned, +, 2, FMT_C, BPP_C) \ + TESTPLANARTOBID(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Invert, -, 0, FMT_C, BPP_C) \ + TESTPLANARTOBID(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Opt, +, 0, FMT_C, BPP_C) +#else +#define TESTPLANARTOBD(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, FMT_C, BPP_C) \ + TESTPLANARTOBID(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Opt, +, 0, FMT_C, BPP_C) +#endif + +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTPLANARTOBD(I420, 2, 2, RGB565, 2, 2, 1, ARGB, 4) +#endif + +// Transitive test. A to B to C is same as A to C. +// Benchmarks A To B to C for comparison to 1 step, benchmarked elsewhere. +#define TESTPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + W1280, N, NEG, OFF, FMT_C, BPP_C) \ + TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##To##FMT_C##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kStrideB = SUBSAMPLE(kWidth, SUB_B) * BPP_B; \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ + align_buffer_page_end(src_y, kWidth * kHeight + OFF); \ + align_buffer_page_end(src_u, kSizeUV + OFF); \ + align_buffer_page_end(src_v, kSizeUV + OFF); \ + align_buffer_page_end(dst_argb_b, kStrideB * kHeight + OFF); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + src_y[i + OFF] = (fastrand() & 0xff); \ + } \ + for (int i = 0; i < kSizeUV; ++i) { \ + src_u[i + OFF] = (fastrand() & 0xff); \ + src_v[i + OFF] = (fastrand() & 0xff); \ + } \ + memset(dst_argb_b + OFF, 1, kStrideB * kHeight); \ + FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ + src_v + OFF, kStrideUV, dst_argb_b + OFF, kStrideB, \ + kWidth, NEG kHeight); \ + /* Convert to a 3rd format in 1 step and 2 steps and compare */ \ + const int kStrideC = kWidth * BPP_C; \ + align_buffer_page_end(dst_argb_c, kStrideC * kHeight + OFF); \ + align_buffer_page_end(dst_argb_bc, kStrideC * kHeight + OFF); \ + memset(dst_argb_c + OFF, 2, kStrideC * kHeight); \ + memset(dst_argb_bc + OFF, 3, kStrideC * kHeight); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_PLANAR##To##FMT_C(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ + src_v + OFF, kStrideUV, dst_argb_c + OFF, \ + kStrideC, kWidth, NEG kHeight); \ + /* Convert B to C */ \ + FMT_B##To##FMT_C(dst_argb_b + OFF, kStrideB, dst_argb_bc + OFF, \ + kStrideC, kWidth, kHeight); \ + } \ + for (int i = 0; i < kStrideC * kHeight; ++i) { \ + ASSERT_EQ(dst_argb_c[i + OFF], dst_argb_bc[i + OFF]); \ + } \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_u); \ + free_aligned_buffer_page_end(src_v); \ + free_aligned_buffer_page_end(dst_argb_b); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_bc); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTPLANARTOE(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + FMT_C, BPP_C) \ + TESTPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + benchmark_width_ + 1, _Any, +, 0, FMT_C, BPP_C) \ + TESTPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + benchmark_width_, _Unaligned, +, 2, FMT_C, BPP_C) \ + TESTPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + benchmark_width_, _Invert, -, 0, FMT_C, BPP_C) \ + TESTPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + benchmark_width_, _Opt, +, 0, FMT_C, BPP_C) +#else +#define TESTPLANARTOE(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + FMT_C, BPP_C) \ + TESTPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + benchmark_width_, _Opt, +, 0, FMT_C, BPP_C) +#endif + +#if defined(ENABLE_FULL_TESTS) +TESTPLANARTOE(I420, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, ABGR, 4) +TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, RAW, 3) +TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, RGB24, 3) +TESTPLANARTOE(I420, 2, 2, BGRA, 1, 4, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, RAW, 1, 3, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, RAW, 1, 3, RGB24, 3) +TESTPLANARTOE(I420, 2, 2, RGB24, 1, 3, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, RGB24, 1, 3, RAW, 3) +TESTPLANARTOE(I420, 2, 2, RGBA, 1, 4, ARGB, 4) +TESTPLANARTOE(H420, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(H420, 2, 2, ARGB, 1, 4, ABGR, 4) +TESTPLANARTOE(H420, 2, 2, ARGB, 1, 4, RAW, 3) +TESTPLANARTOE(H420, 2, 2, ARGB, 1, 4, RGB24, 3) +TESTPLANARTOE(H420, 2, 2, RAW, 1, 3, ARGB, 4) +TESTPLANARTOE(H420, 2, 2, RAW, 1, 3, RGB24, 3) +TESTPLANARTOE(H420, 2, 2, RGB24, 1, 3, ARGB, 4) +TESTPLANARTOE(H420, 2, 2, RGB24, 1, 3, RAW, 3) +TESTPLANARTOE(J420, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(J420, 2, 2, ARGB, 1, 4, ARGB, 4) +TESTPLANARTOE(U420, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(U420, 2, 2, ARGB, 1, 4, ARGB, 4) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, RGB565, 2) +TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, ARGB1555, 2) +TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, ARGB4444, 2) +TESTPLANARTOE(I422, 2, 1, ARGB, 1, 4, RGB565, 2) +#endif +TESTPLANARTOE(I422, 2, 1, ARGB, 1, 4, ABGR, 4) +TESTPLANARTOE(I422, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(J422, 2, 1, ARGB, 1, 4, ARGB, 4) +TESTPLANARTOE(J422, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(H422, 2, 1, ARGB, 1, 4, ARGB, 4) +TESTPLANARTOE(H422, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(U422, 2, 1, ARGB, 1, 4, ARGB, 4) +TESTPLANARTOE(U422, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(V422, 2, 1, ARGB, 1, 4, ARGB, 4) +TESTPLANARTOE(V422, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(I422, 2, 1, BGRA, 1, 4, ARGB, 4) +TESTPLANARTOE(I422, 2, 1, RGBA, 1, 4, ARGB, 4) +TESTPLANARTOE(I444, 1, 1, ARGB, 1, 4, ABGR, 4) +TESTPLANARTOE(I444, 1, 1, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(J444, 1, 1, ARGB, 1, 4, ARGB, 4) +TESTPLANARTOE(J444, 1, 1, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(H444, 1, 1, ARGB, 1, 4, ARGB, 4) +TESTPLANARTOE(H444, 1, 1, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(U444, 1, 1, ARGB, 1, 4, ARGB, 4) +TESTPLANARTOE(U444, 1, 1, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(V444, 1, 1, ARGB, 1, 4, ARGB, 4) +TESTPLANARTOE(V444, 1, 1, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, YUY2, 2, 4, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, UYVY, 2, 4, ARGB, 4) +TESTPLANARTOE(I422, 2, 1, YUY2, 2, 4, ARGB, 4) +TESTPLANARTOE(I422, 2, 1, UYVY, 2, 4, ARGB, 4) +#else +TESTPLANARTOE(I420, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, ARGB1555, 2) +TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, ARGB4444, 2) +TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, RAW, 3) +TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, RGB24, 3) +TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, RGB565, 2) +TESTPLANARTOE(I420, 2, 2, BGRA, 1, 4, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, RAW, 1, 3, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, RAW, 1, 3, RGB24, 3) +TESTPLANARTOE(I420, 2, 2, RGB24, 1, 3, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, RGB24, 1, 3, RAW, 3) +TESTPLANARTOE(I420, 2, 2, RGBA, 1, 4, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, UYVY, 2, 4, ARGB, 4) +TESTPLANARTOE(I420, 2, 2, YUY2, 2, 4, ARGB, 4) +TESTPLANARTOE(I422, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTPLANARTOE(I422, 2, 1, ARGB, 1, 4, RGB565, 2) +TESTPLANARTOE(I422, 2, 1, BGRA, 1, 4, ARGB, 4) +TESTPLANARTOE(I422, 2, 1, RGBA, 1, 4, ARGB, 4) +TESTPLANARTOE(I422, 2, 1, UYVY, 2, 4, ARGB, 4) +TESTPLANARTOE(I422, 2, 1, YUY2, 2, 4, ARGB, 4) +TESTPLANARTOE(I444, 1, 1, ABGR, 1, 4, ARGB, 4) +#endif + +// Transitive test: Compare 1 step vs 2 step conversion for YUVA to ARGB. +// Benchmark 2 step conversion for comparison to 1 step conversion. +#define TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + W1280, N, NEG, OFF, FMT_C, BPP_C, ATTEN) \ + TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##To##FMT_C##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kStrideB = SUBSAMPLE(kWidth, SUB_B) * BPP_B; \ + const int kSizeUV = \ + SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y); \ + align_buffer_page_end(src_y, kWidth * kHeight + OFF); \ + align_buffer_page_end(src_u, kSizeUV + OFF); \ + align_buffer_page_end(src_v, kSizeUV + OFF); \ + align_buffer_page_end(src_a, kWidth * kHeight + OFF); \ + align_buffer_page_end(dst_argb_b, kStrideB * kHeight + OFF); \ + const int kStrideC = kWidth * BPP_C; \ + align_buffer_page_end(dst_argb_c, kStrideC * kHeight + OFF); \ + align_buffer_page_end(dst_argb_bc, kStrideC * kHeight + OFF); \ + memset(dst_argb_c + OFF, 2, kStrideC * kHeight); \ + memset(dst_argb_b + OFF, 1, kStrideB * kHeight); \ + memset(dst_argb_bc + OFF, 3, kStrideC * kHeight); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + src_y[i + OFF] = (fastrand() & 0xff); \ + src_a[i + OFF] = (fastrand() & 0xff); \ + } \ + for (int i = 0; i < kSizeUV; ++i) { \ + src_u[i + OFF] = (fastrand() & 0xff); \ + src_v[i + OFF] = (fastrand() & 0xff); \ + } \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + /* Convert A to B */ \ + FMT_PLANAR##To##FMT_B( \ + src_y + OFF, kWidth, src_u + OFF, SUBSAMPLE(kWidth, SUBSAMP_X), \ + src_v + OFF, SUBSAMPLE(kWidth, SUBSAMP_X), src_a + OFF, kWidth, \ + dst_argb_b + OFF, kStrideB, kWidth, NEG kHeight, ATTEN); \ + /* Convert B to C */ \ + FMT_B##To##FMT_C(dst_argb_b + OFF, kStrideB, dst_argb_bc + OFF, \ + kStrideC, kWidth, kHeight); \ + } \ + /* Convert A to C */ \ + FMT_PLANAR##To##FMT_C( \ + src_y + OFF, kWidth, src_u + OFF, SUBSAMPLE(kWidth, SUBSAMP_X), \ + src_v + OFF, SUBSAMPLE(kWidth, SUBSAMP_X), src_a + OFF, kWidth, \ + dst_argb_c + OFF, kStrideC, kWidth, NEG kHeight, ATTEN); \ + for (int i = 0; i < kStrideC * kHeight; ++i) { \ + ASSERT_EQ(dst_argb_c[i + OFF], dst_argb_bc[i + OFF]); \ + } \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_u); \ + free_aligned_buffer_page_end(src_v); \ + free_aligned_buffer_page_end(src_a); \ + free_aligned_buffer_page_end(dst_argb_b); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_bc); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTQPLANARTOE(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + FMT_C, BPP_C) \ + TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + benchmark_width_ + 1, _Any, +, 0, FMT_C, BPP_C, 0) \ + TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + benchmark_width_, _Unaligned, +, 2, FMT_C, BPP_C, 0) \ + TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + benchmark_width_, _Invert, -, 0, FMT_C, BPP_C, 0) \ + TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + benchmark_width_, _Opt, +, 0, FMT_C, BPP_C, 0) \ + TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + benchmark_width_, _Premult, +, 0, FMT_C, BPP_C, 1) +#else +#define TESTQPLANARTOE(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + FMT_C, BPP_C) \ + TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ + benchmark_width_, _Opt, +, 0, FMT_C, BPP_C, 0) +#endif + +#if defined(ENABLE_FULL_TESTS) +TESTQPLANARTOE(I420Alpha, 2, 2, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(I420Alpha, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(J420Alpha, 2, 2, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(J420Alpha, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(H420Alpha, 2, 2, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(H420Alpha, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(F420Alpha, 2, 2, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(F420Alpha, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(U420Alpha, 2, 2, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(U420Alpha, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(V420Alpha, 2, 2, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(V420Alpha, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(I422Alpha, 2, 1, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(I422Alpha, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(J422Alpha, 2, 1, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(J422Alpha, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(F422Alpha, 2, 1, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(F422Alpha, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(H422Alpha, 2, 1, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(H422Alpha, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(U422Alpha, 2, 1, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(U422Alpha, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(V422Alpha, 2, 1, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(V422Alpha, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(I444Alpha, 1, 1, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(I444Alpha, 1, 1, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(J444Alpha, 1, 1, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(J444Alpha, 1, 1, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(H444Alpha, 1, 1, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(H444Alpha, 1, 1, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(U444Alpha, 1, 1, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(U444Alpha, 1, 1, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(V444Alpha, 1, 1, ARGB, 1, 4, ABGR, 4) +TESTQPLANARTOE(V444Alpha, 1, 1, ABGR, 1, 4, ARGB, 4) +#else +TESTQPLANARTOE(I420Alpha, 2, 2, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(I422Alpha, 2, 1, ABGR, 1, 4, ARGB, 4) +TESTQPLANARTOE(I444Alpha, 1, 1, ABGR, 1, 4, ARGB, 4) +#endif + +#define TESTPLANETOEI(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, W1280, N, NEG, \ + OFF, FMT_C, BPP_C) \ + TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##To##FMT_C##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kStrideA = SUBSAMPLE(kWidth, SUB_A) * BPP_A; \ + const int kStrideB = SUBSAMPLE(kWidth, SUB_B) * BPP_B; \ + align_buffer_page_end(src_argb_a, kStrideA * kHeight + OFF); \ + align_buffer_page_end(dst_argb_b, kStrideB * kHeight + OFF); \ + MemRandomize(src_argb_a + OFF, kStrideA * kHeight); \ + memset(dst_argb_b + OFF, 1, kStrideB * kHeight); \ + FMT_A##To##FMT_B(src_argb_a + OFF, kStrideA, dst_argb_b + OFF, kStrideB, \ + kWidth, NEG kHeight); \ + /* Convert to a 3rd format in 1 step and 2 steps and compare */ \ + const int kStrideC = kWidth * BPP_C; \ + align_buffer_page_end(dst_argb_c, kStrideC * kHeight + OFF); \ + align_buffer_page_end(dst_argb_bc, kStrideC * kHeight + OFF); \ + memset(dst_argb_c + OFF, 2, kStrideC * kHeight); \ + memset(dst_argb_bc + OFF, 3, kStrideC * kHeight); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_A##To##FMT_C(src_argb_a + OFF, kStrideA, dst_argb_c + OFF, kStrideC, \ + kWidth, NEG kHeight); \ + /* Convert B to C */ \ + FMT_B##To##FMT_C(dst_argb_b + OFF, kStrideB, dst_argb_bc + OFF, \ + kStrideC, kWidth, kHeight); \ + } \ + for (int i = 0; i < kStrideC * kHeight; i += 4) { \ + ASSERT_EQ(dst_argb_c[i + OFF + 0], dst_argb_bc[i + OFF + 0]); \ + ASSERT_EQ(dst_argb_c[i + OFF + 1], dst_argb_bc[i + OFF + 1]); \ + ASSERT_EQ(dst_argb_c[i + OFF + 2], dst_argb_bc[i + OFF + 2]); \ + ASSERT_NEAR(dst_argb_c[i + OFF + 3], dst_argb_bc[i + OFF + 3], 64); \ + } \ + free_aligned_buffer_page_end(src_argb_a); \ + free_aligned_buffer_page_end(dst_argb_b); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_bc); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTPLANETOE(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, FMT_C, BPP_C) \ + TESTPLANETOEI(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, \ + benchmark_width_ + 1, _Any, +, 0, FMT_C, BPP_C) \ + TESTPLANETOEI(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, benchmark_width_, \ + _Unaligned, +, 4, FMT_C, BPP_C) \ + TESTPLANETOEI(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, benchmark_width_, \ + _Invert, -, 0, FMT_C, BPP_C) \ + TESTPLANETOEI(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, benchmark_width_, \ + _Opt, +, 0, FMT_C, BPP_C) +#else +#define TESTPLANETOE(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, FMT_C, BPP_C) \ + TESTPLANETOEI(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, benchmark_width_, \ + _Opt, +, 0, FMT_C, BPP_C) +#endif + +// Caveat: Destination needs to be 4 bytes +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTPLANETOE(ARGB, 1, 4, AR30, 1, 4, ARGB, 4) +TESTPLANETOE(ABGR, 1, 4, AR30, 1, 4, ABGR, 4) +TESTPLANETOE(AR30, 1, 4, ARGB, 1, 4, ABGR, 4) +TESTPLANETOE(AR30, 1, 4, ABGR, 1, 4, ARGB, 4) +TESTPLANETOE(ARGB, 1, 4, AB30, 1, 4, ARGB, 4) +TESTPLANETOE(ABGR, 1, 4, AB30, 1, 4, ABGR, 4) +TESTPLANETOE(AB30, 1, 4, ARGB, 1, 4, ABGR, 4) +TESTPLANETOE(AB30, 1, 4, ABGR, 1, 4, ARGB, 4) +#endif + +TEST_F(LibYUVConvertTest, RotateWithARGBSource) { + // 2x2 frames + uint32_t src[4]; + uint32_t dst[4]; + // some random input + src[0] = 0x11000000; + src[1] = 0x00450000; + src[2] = 0x00009f00; + src[3] = 0x000000ff; + // zeros on destination + dst[0] = 0x00000000; + dst[1] = 0x00000000; + dst[2] = 0x00000000; + dst[3] = 0x00000000; + + int r = ConvertToARGB(reinterpret_cast(src), + 16, // input size + reinterpret_cast(dst), + 8, // destination stride + 0, // crop_x + 0, // crop_y + 2, // width + 2, // height + 2, // crop width + 2, // crop height + kRotate90, FOURCC_ARGB); + + ASSERT_EQ(r, 0); + // 90 degrees rotation, no conversion + ASSERT_EQ(dst[0], src[2]); + ASSERT_EQ(dst[1], src[0]); + ASSERT_EQ(dst[2], src[3]); + ASSERT_EQ(dst[3], src[1]); +} + +#define TESTCONVERTTOARGBSMOKE(FMT, BPC, SUBSAMP_X, SUBSAMP_Y) \ + TEST_F(LibYUVConvertTest, ConvertToARGB_##FMT) { \ + const int kWidth = 64; \ + const int kHeight = 48; \ + const int kUvStride = (SUBSAMP_X == 1) ? kWidth * 2 : ((kWidth + 1) & ~1); \ + const int kUvHeight = SUBSAMPLE(kHeight, SUBSAMP_Y); \ + const int kSampleSize = (kWidth * kHeight + kUvStride * kUvHeight) * BPC; \ + align_buffer_page_end(src, kSampleSize); \ + align_buffer_page_end(dst, kWidth * kHeight * 4); \ + MemRandomize(src, kSampleSize); \ + memset(dst, 0, kWidth * kHeight * 4); \ + EXPECT_EQ( \ + 0, ConvertToARGB(src, kSampleSize, dst, kWidth * 4, 0, 0, kWidth, \ + kHeight, kWidth, kHeight, kRotate0, FOURCC_##FMT)); \ + free_aligned_buffer_page_end(src); \ + free_aligned_buffer_page_end(dst); \ + } + +TESTCONVERTTOARGBSMOKE(NV16, 1, 2, 1) +TESTCONVERTTOARGBSMOKE(NV24, 1, 1, 1) + +#define TESTCONVERTTOARGBI(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, W1280, N, \ + NEG) \ + TEST_F(LibYUVConvertTest, ConvertToARGB_##FMT##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kUvStride = (SUBSAMP_X == 1) ? kWidth * 2 : ((kWidth + 1) & ~1); \ + const int kUvHeight = SUBSAMPLE(kHeight, SUBSAMP_Y); \ + const int kYPixels = kWidth * kHeight; \ + const int kUvPixels = kUvStride * kUvHeight; \ + align_buffer_page_end(src, (kYPixels + kUvPixels) * BPC); \ + align_buffer_page_end(dst, kWidth * kHeight * 4); \ + align_buffer_page_end(ref, kWidth * kHeight * 4); \ + TYPE* src_p = reinterpret_cast(src); \ + MemRandomize(src, (kYPixels + kUvPixels) * BPC); \ + if (BPC == 2) { \ + for (int i = 0; i < kYPixels + kUvPixels; ++i) { \ + src_p[i] = static_cast(src_p[i] & 0xffc0); \ + } \ + } \ + memset(dst, 1, kWidth * kHeight * 4); \ + memset(ref, 2, kWidth * kHeight * 4); \ + EXPECT_EQ(0, FMT##ToARGBMatrix(src_p, kWidth, src_p + kYPixels, kUvStride, \ + ref, kWidth * 4, &kYuvI601Constants, \ + kWidth, NEG kHeight)); \ + EXPECT_EQ( \ + 0, ConvertToARGB(src, 0, dst, kWidth * 4, 0, 0, kWidth, NEG kHeight, \ + kWidth, kHeight, kRotate0, FOURCC_##FMT)); \ + for (int i = 0; i < kWidth * kHeight * 4; ++i) { \ + ASSERT_EQ(dst[i], ref[i]); \ + } \ + free_aligned_buffer_page_end(src); \ + free_aligned_buffer_page_end(dst); \ + free_aligned_buffer_page_end(ref); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTCONVERTTOARGB(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y) \ + TESTCONVERTTOARGBI(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_ + 1, _Any, +) \ + TESTCONVERTTOARGBI(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, \ + _Invert, -) \ + TESTCONVERTTOARGBI(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, \ + _Opt, +) +#else +#define TESTCONVERTTOARGB(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y) \ + TESTCONVERTTOARGBI(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, \ + _Opt, +) +#endif + +TESTCONVERTTOARGB(P010, uint16_t, 2, 2, 2) +TESTCONVERTTOARGB(P210, uint16_t, 2, 2, 1) +TESTCONVERTTOARGB(P410, uint16_t, 2, 1, 1) + +#ifdef HAS_ARGBTOAR30ROW_AVX2 +TEST_F(LibYUVConvertTest, ARGBToAR30Row_Opt) { + // ARGBToAR30Row_AVX2 expects a multiple of 8 pixels. + const int kPixels = (benchmark_width_ * benchmark_height_ + 7) & ~7; + align_buffer_page_end(src, kPixels * 4); + align_buffer_page_end(dst_opt, kPixels * 4); + align_buffer_page_end(dst_c, kPixels * 4); + MemRandomize(src, kPixels * 4); + memset(dst_opt, 0, kPixels * 4); + memset(dst_c, 1, kPixels * 4); + + ARGBToAR30Row_C(src, dst_c, kPixels); + + int has_avx2 = TestCpuFlag(kCpuHasAVX2); + int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); + for (int i = 0; i < benchmark_iterations_; ++i) { + if (has_avx2) { + ARGBToAR30Row_AVX2(src, dst_opt, kPixels); + } else if (has_ssse3) { + ARGBToAR30Row_SSSE3(src, dst_opt, kPixels); + } else { + ARGBToAR30Row_C(src, dst_opt, kPixels); + } + } + for (int i = 0; i < kPixels * 4; ++i) { + ASSERT_EQ(dst_opt[i], dst_c[i]); + } + + free_aligned_buffer_page_end(src); + free_aligned_buffer_page_end(dst_opt); + free_aligned_buffer_page_end(dst_c); +} +#endif // HAS_ARGBTOAR30ROW_AVX2 + +#ifdef HAS_ABGRTOAR30ROW_AVX2 +TEST_F(LibYUVConvertTest, ABGRToAR30Row_Opt) { + // ABGRToAR30Row_AVX2 expects a multiple of 8 pixels. + const int kPixels = (benchmark_width_ * benchmark_height_ + 7) & ~7; + align_buffer_page_end(src, kPixels * 4); + align_buffer_page_end(dst_opt, kPixels * 4); + align_buffer_page_end(dst_c, kPixels * 4); + MemRandomize(src, kPixels * 4); + memset(dst_opt, 0, kPixels * 4); + memset(dst_c, 1, kPixels * 4); + + ABGRToAR30Row_C(src, dst_c, kPixels); + + int has_avx2 = TestCpuFlag(kCpuHasAVX2); + int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); + for (int i = 0; i < benchmark_iterations_; ++i) { + if (has_avx2) { + ABGRToAR30Row_AVX2(src, dst_opt, kPixels); + } else if (has_ssse3) { + ABGRToAR30Row_SSSE3(src, dst_opt, kPixels); + } else { + ABGRToAR30Row_C(src, dst_opt, kPixels); + } + } + for (int i = 0; i < kPixels * 4; ++i) { + ASSERT_EQ(dst_opt[i], dst_c[i]); + } + + free_aligned_buffer_page_end(src); + free_aligned_buffer_page_end(dst_opt); + free_aligned_buffer_page_end(dst_c); +} +#endif // HAS_ABGRTOAR30ROW_AVX2 + +#if !defined(LEAN_TESTS) + +// Provide matrix wrappers for 12 bit YUV +#define I012ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I012ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j) +#define I012ToAR30(a, b, c, d, e, f, g, h, i, j) \ + I012ToAR30Matrix(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j) +#define I012ToAB30(a, b, c, d, e, f, g, h, i, j) \ + I012ToAB30Matrix(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j) + +#define I410ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I410ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j) +#define I410ToABGR(a, b, c, d, e, f, g, h, i, j) \ + I410ToABGRMatrix(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j) +#define H410ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I410ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuvH709Constants, i, j) +#define H410ToABGR(a, b, c, d, e, f, g, h, i, j) \ + I410ToABGRMatrix(a, b, c, d, e, f, g, h, &kYuvH709Constants, i, j) +#define U410ToARGB(a, b, c, d, e, f, g, h, i, j) \ + I410ToARGBMatrix(a, b, c, d, e, f, g, h, &kYuv2020Constants, i, j) +#define U410ToABGR(a, b, c, d, e, f, g, h, i, j) \ + I410ToABGRMatrix(a, b, c, d, e, f, g, h, &kYuv2020Constants, i, j) +#define I410ToAR30(a, b, c, d, e, f, g, h, i, j) \ + I410ToAR30Matrix(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j) +#define I410ToAB30(a, b, c, d, e, f, g, h, i, j) \ + I410ToAB30Matrix(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j) +#define H410ToAR30(a, b, c, d, e, f, g, h, i, j) \ + I410ToAR30Matrix(a, b, c, d, e, f, g, h, &kYuvH709Constants, i, j) +#define H410ToAB30(a, b, c, d, e, f, g, h, i, j) \ + I410ToAB30Matrix(a, b, c, d, e, f, g, h, &kYuvH709Constants, i, j) +#define U410ToAR30(a, b, c, d, e, f, g, h, i, j) \ + I410ToAR30Matrix(a, b, c, d, e, f, g, h, &kYuv2020Constants, i, j) +#define U410ToAB30(a, b, c, d, e, f, g, h, i, j) \ + I410ToAB30Matrix(a, b, c, d, e, f, g, h, &kYuv2020Constants, i, j) + +#define I010ToARGBFilter(a, b, c, d, e, f, g, h, i, j) \ + I010ToARGBMatrixFilter(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j, \ + kFilterBilinear) +#define I010ToAR30Filter(a, b, c, d, e, f, g, h, i, j) \ + I010ToAR30MatrixFilter(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j, \ + kFilterBilinear) +#define I210ToARGBFilter(a, b, c, d, e, f, g, h, i, j) \ + I210ToARGBMatrixFilter(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j, \ + kFilterBilinear) +#define I210ToAR30Filter(a, b, c, d, e, f, g, h, i, j) \ + I210ToAR30MatrixFilter(a, b, c, d, e, f, g, h, &kYuvI601Constants, i, j, \ + kFilterBilinear) + +// TODO(fbarchard): Fix clamping issue affected by U channel. +#define TESTPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_MASK, FMT_B, \ + BPP_B, ALIGN, YALIGN, W1280, N, NEG, SOFF, DOFF) \ + TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##N) { \ + const int kWidth = W1280; \ + const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ + const int kStrideB = ALIGNINT(kWidth * BPP_B, ALIGN); \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ + const int kBpc = 2; \ + align_buffer_page_end(src_y, kWidth * kHeight * kBpc + SOFF); \ + align_buffer_page_end(src_u, kSizeUV * kBpc + SOFF); \ + align_buffer_page_end(src_v, kSizeUV * kBpc + SOFF); \ + align_buffer_page_end(dst_argb_c, kStrideB * kHeight + DOFF); \ + align_buffer_page_end(dst_argb_opt, kStrideB * kHeight + DOFF); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + reinterpret_cast(src_y + SOFF)[i] = (fastrand() & FMT_MASK); \ + } \ + for (int i = 0; i < kSizeUV; ++i) { \ + reinterpret_cast(src_u + SOFF)[i] = (fastrand() & FMT_MASK); \ + reinterpret_cast(src_v + SOFF)[i] = (fastrand() & FMT_MASK); \ + } \ + memset(dst_argb_c + DOFF, 1, kStrideB * kHeight); \ + memset(dst_argb_opt + DOFF, 101, kStrideB * kHeight); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_PLANAR##To##FMT_B( \ + reinterpret_cast(src_y + SOFF), kWidth, \ + reinterpret_cast(src_u + SOFF), kStrideUV, \ + reinterpret_cast(src_v + SOFF), kStrideUV, \ + dst_argb_c + DOFF, kStrideB, kWidth, NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_PLANAR##To##FMT_B( \ + reinterpret_cast(src_y + SOFF), kWidth, \ + reinterpret_cast(src_u + SOFF), kStrideUV, \ + reinterpret_cast(src_v + SOFF), kStrideUV, \ + dst_argb_opt + DOFF, kStrideB, kWidth, NEG kHeight); \ + } \ + for (int i = 0; i < kWidth * BPP_B * kHeight; ++i) { \ + ASSERT_EQ(dst_argb_c[i + DOFF], dst_argb_opt[i + DOFF]); \ + } \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_u); \ + free_aligned_buffer_page_end(src_v); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTPLANAR16TOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_MASK, FMT_B, \ + BPP_B, ALIGN, YALIGN) \ + TESTPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_MASK, FMT_B, BPP_B, \ + ALIGN, YALIGN, benchmark_width_ + 1, _Any, +, 0, 0) \ + TESTPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_MASK, FMT_B, BPP_B, \ + ALIGN, YALIGN, benchmark_width_, _Unaligned, +, 4, 4) \ + TESTPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_MASK, FMT_B, BPP_B, \ + ALIGN, YALIGN, benchmark_width_, _Invert, -, 0, 0) \ + TESTPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_MASK, FMT_B, BPP_B, \ + ALIGN, YALIGN, benchmark_width_, _Opt, +, 0, 0) +#else +#define TESTPLANAR16TOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_MASK, FMT_B, \ + BPP_B, ALIGN, YALIGN) \ + TESTPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_MASK, FMT_B, BPP_B, \ + ALIGN, YALIGN, benchmark_width_, _Opt, +, 0, 0) +#endif + +// These conversions are only optimized for x86 +#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) +TESTPLANAR16TOB(I010, 2, 2, 0x3ff, ARGB, 4, 4, 1) +TESTPLANAR16TOB(I010, 2, 2, 0x3ff, ABGR, 4, 4, 1) +TESTPLANAR16TOB(H010, 2, 2, 0x3ff, ARGB, 4, 4, 1) +TESTPLANAR16TOB(H010, 2, 2, 0x3ff, ABGR, 4, 4, 1) +TESTPLANAR16TOB(U010, 2, 2, 0x3ff, ARGB, 4, 4, 1) +TESTPLANAR16TOB(U010, 2, 2, 0x3ff, ABGR, 4, 4, 1) +TESTPLANAR16TOB(I210, 2, 1, 0x3ff, ARGB, 4, 4, 1) +TESTPLANAR16TOB(I210, 2, 1, 0x3ff, ABGR, 4, 4, 1) +TESTPLANAR16TOB(H210, 2, 1, 0x3ff, ARGB, 4, 4, 1) +TESTPLANAR16TOB(H210, 2, 1, 0x3ff, ABGR, 4, 4, 1) +TESTPLANAR16TOB(U210, 2, 1, 0x3ff, ARGB, 4, 4, 1) +TESTPLANAR16TOB(U210, 2, 1, 0x3ff, ABGR, 4, 4, 1) +TESTPLANAR16TOB(I410, 1, 1, 0x3ff, ARGB, 4, 4, 1) +TESTPLANAR16TOB(I410, 1, 1, 0x3ff, ABGR, 4, 4, 1) +TESTPLANAR16TOB(H410, 1, 1, 0x3ff, ARGB, 4, 4, 1) +TESTPLANAR16TOB(H410, 1, 1, 0x3ff, ABGR, 4, 4, 1) +TESTPLANAR16TOB(U410, 1, 1, 0x3ff, ARGB, 4, 4, 1) +TESTPLANAR16TOB(U410, 1, 1, 0x3ff, ABGR, 4, 4, 1) +TESTPLANAR16TOB(I012, 2, 2, 0xfff, ARGB, 4, 4, 1) +TESTPLANAR16TOB(I010, 2, 2, 0x3ff, ARGBFilter, 4, 4, 1) +TESTPLANAR16TOB(I210, 2, 1, 0x3ff, ARGBFilter, 4, 4, 1) + +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTPLANAR16TOB(I010, 2, 2, 0x3ff, AR30, 4, 4, 1) +TESTPLANAR16TOB(I010, 2, 2, 0x3ff, AB30, 4, 4, 1) +TESTPLANAR16TOB(H010, 2, 2, 0x3ff, AR30, 4, 4, 1) +TESTPLANAR16TOB(H010, 2, 2, 0x3ff, AB30, 4, 4, 1) +TESTPLANAR16TOB(U010, 2, 2, 0x3ff, AR30, 4, 4, 1) +TESTPLANAR16TOB(U010, 2, 2, 0x3ff, AB30, 4, 4, 1) +TESTPLANAR16TOB(I210, 2, 1, 0x3ff, AR30, 4, 4, 1) +TESTPLANAR16TOB(I210, 2, 1, 0x3ff, AB30, 4, 4, 1) +TESTPLANAR16TOB(H210, 2, 1, 0x3ff, AR30, 4, 4, 1) +TESTPLANAR16TOB(H210, 2, 1, 0x3ff, AB30, 4, 4, 1) +TESTPLANAR16TOB(U210, 2, 1, 0x3ff, AR30, 4, 4, 1) +TESTPLANAR16TOB(U210, 2, 1, 0x3ff, AB30, 4, 4, 1) +TESTPLANAR16TOB(I410, 1, 1, 0x3ff, AR30, 4, 4, 1) +TESTPLANAR16TOB(I410, 1, 1, 0x3ff, AB30, 4, 4, 1) +TESTPLANAR16TOB(H410, 1, 1, 0x3ff, AR30, 4, 4, 1) +TESTPLANAR16TOB(H410, 1, 1, 0x3ff, AB30, 4, 4, 1) +TESTPLANAR16TOB(U410, 1, 1, 0x3ff, AR30, 4, 4, 1) +TESTPLANAR16TOB(U410, 1, 1, 0x3ff, AB30, 4, 4, 1) +TESTPLANAR16TOB(I012, 2, 2, 0xfff, AR30, 4, 4, 1) +TESTPLANAR16TOB(I012, 2, 2, 0xfff, AB30, 4, 4, 1) +TESTPLANAR16TOB(I010, 2, 2, 0x3ff, AR30Filter, 4, 4, 1) +TESTPLANAR16TOB(I210, 2, 1, 0x3ff, AR30Filter, 4, 4, 1) +#endif // LITTLE_ENDIAN_ONLY_TEST +#endif // DISABLE_SLOW_TESTS + +#define TESTQPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, \ + ALIGN, YALIGN, W1280, N, NEG, OFF, ATTEN, S_DEPTH) \ + TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##N) { \ + const int kWidth = W1280; \ + const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ + const int kStrideB = ALIGNINT(kWidth * BPP_B, ALIGN); \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ + const int kBpc = 2; \ + align_buffer_page_end(src_y, kWidth * kHeight * kBpc + OFF); \ + align_buffer_page_end(src_u, kSizeUV * kBpc + OFF); \ + align_buffer_page_end(src_v, kSizeUV * kBpc + OFF); \ + align_buffer_page_end(src_a, kWidth * kHeight * kBpc + OFF); \ + align_buffer_page_end(dst_argb_c, kStrideB * kHeight + OFF); \ + align_buffer_page_end(dst_argb_opt, kStrideB * kHeight + OFF); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + reinterpret_cast(src_y + OFF)[i] = \ + (fastrand() & ((1 << S_DEPTH) - 1)); \ + reinterpret_cast(src_a + OFF)[i] = \ + (fastrand() & ((1 << S_DEPTH) - 1)); \ + } \ + for (int i = 0; i < kSizeUV; ++i) { \ + reinterpret_cast(src_u + OFF)[i] = \ + (fastrand() & ((1 << S_DEPTH) - 1)); \ + reinterpret_cast(src_v + OFF)[i] = \ + (fastrand() & ((1 << S_DEPTH) - 1)); \ + } \ + memset(dst_argb_c + OFF, 1, kStrideB * kHeight); \ + memset(dst_argb_opt + OFF, 101, kStrideB * kHeight); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_PLANAR##To##FMT_B(reinterpret_cast(src_y + OFF), kWidth, \ + reinterpret_cast(src_u + OFF), kStrideUV, \ + reinterpret_cast(src_v + OFF), kStrideUV, \ + reinterpret_cast(src_a + OFF), kWidth, \ + dst_argb_c + OFF, kStrideB, kWidth, NEG kHeight, \ + ATTEN); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_PLANAR##To##FMT_B( \ + reinterpret_cast(src_y + OFF), kWidth, \ + reinterpret_cast(src_u + OFF), kStrideUV, \ + reinterpret_cast(src_v + OFF), kStrideUV, \ + reinterpret_cast(src_a + OFF), kWidth, \ + dst_argb_opt + OFF, kStrideB, kWidth, NEG kHeight, ATTEN); \ + } \ + for (int i = 0; i < kWidth * BPP_B * kHeight; ++i) { \ + ASSERT_EQ(dst_argb_c[i + OFF], dst_argb_opt[i + OFF]); \ + } \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_u); \ + free_aligned_buffer_page_end(src_v); \ + free_aligned_buffer_page_end(src_a); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTQPLANAR16TOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, \ + ALIGN, YALIGN, S_DEPTH) \ + TESTQPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_ + 1, _Any, +, 0, 0, S_DEPTH) \ + TESTQPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Unaligned, +, 2, 0, S_DEPTH) \ + TESTQPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Invert, -, 0, 0, S_DEPTH) \ + TESTQPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Opt, +, 0, 0, S_DEPTH) \ + TESTQPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Premult, +, 0, 1, S_DEPTH) +#else +#define TESTQPLANAR16TOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, \ + ALIGN, YALIGN, S_DEPTH) \ + TESTQPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, benchmark_width_, _Opt, +, 0, 0, S_DEPTH) +#endif + +#define I010AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvI601Constants, k, \ + l, m) +#define I010AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvI601Constants, k, \ + l, m) +#define J010AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define J010AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define F010AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define F010AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define H010AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define H010AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define U010AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define U010AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define V010AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) +#define V010AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) +#define I210AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvI601Constants, k, \ + l, m) +#define I210AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvI601Constants, k, \ + l, m) +#define J210AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define J210AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define F210AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define F210AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define H210AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define H210AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define U210AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define U210AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define V210AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) +#define V210AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I210AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) +#define I410AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvI601Constants, k, \ + l, m) +#define I410AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvI601Constants, k, \ + l, m) +#define J410AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define J410AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvJPEGConstants, k, \ + l, m) +#define F410AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define F410AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvF709Constants, k, \ + l, m) +#define H410AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define H410AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvH709Constants, k, \ + l, m) +#define U410AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define U410AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuv2020Constants, k, \ + l, m) +#define V410AlphaToARGB(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToARGBMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) +#define V410AlphaToABGR(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I410AlphaToABGRMatrix(a, b, c, d, e, f, g, h, i, j, &kYuvV2020Constants, k, \ + l, m) +#define I010AlphaToARGBFilter(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToARGBMatrixFilter(a, b, c, d, e, f, g, h, i, j, \ + &kYuvI601Constants, k, l, m, kFilterBilinear) +#define I210AlphaToARGBFilter(a, b, c, d, e, f, g, h, i, j, k, l, m) \ + I010AlphaToARGBMatrixFilter(a, b, c, d, e, f, g, h, i, j, \ + &kYuvI601Constants, k, l, m, kFilterBilinear) + +// These conversions are only optimized for x86 +#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) +TESTQPLANAR16TOB(I010Alpha, 2, 2, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(I010Alpha, 2, 2, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(J010Alpha, 2, 2, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(J010Alpha, 2, 2, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(H010Alpha, 2, 2, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(H010Alpha, 2, 2, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(F010Alpha, 2, 2, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(F010Alpha, 2, 2, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(U010Alpha, 2, 2, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(U010Alpha, 2, 2, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(V010Alpha, 2, 2, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(V010Alpha, 2, 2, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(I210Alpha, 2, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(I210Alpha, 2, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(J210Alpha, 2, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(J210Alpha, 2, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(H210Alpha, 2, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(H210Alpha, 2, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(F210Alpha, 2, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(F210Alpha, 2, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(U210Alpha, 2, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(U210Alpha, 2, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(V210Alpha, 2, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(V210Alpha, 2, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(I410Alpha, 1, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(I410Alpha, 1, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(J410Alpha, 1, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(J410Alpha, 1, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(H410Alpha, 1, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(H410Alpha, 1, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(F410Alpha, 1, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(F410Alpha, 1, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(U410Alpha, 1, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(U410Alpha, 1, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(V410Alpha, 1, 1, ARGB, 4, 4, 1, 10) +TESTQPLANAR16TOB(V410Alpha, 1, 1, ABGR, 4, 4, 1, 10) +TESTQPLANAR16TOB(I010Alpha, 2, 2, ARGBFilter, 4, 4, 1, 10) +TESTQPLANAR16TOB(I210Alpha, 2, 1, ARGBFilter, 4, 4, 1, 10) +#endif // DISABLE_SLOW_TESTS + +#define TESTBP16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, W1280, N, NEG, SOFF, DOFF, S_DEPTH) \ + TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##N) { \ + const int kWidth = W1280; \ + const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ + const int kStrideB = ALIGNINT(kWidth * BPP_B, ALIGN); \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X) * 2; \ + const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y) * 2; \ + const int kBpc = 2; \ + align_buffer_page_end(src_y, kWidth * kHeight * kBpc + SOFF); \ + align_buffer_page_end(src_uv, kSizeUV * kBpc + SOFF); \ + align_buffer_page_end(dst_argb_c, kStrideB * kHeight + DOFF); \ + align_buffer_page_end(dst_argb_opt, kStrideB * kHeight + DOFF); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + reinterpret_cast(src_y + SOFF)[i] = \ + (fastrand() & (((uint16_t)(-1)) << (16 - S_DEPTH))); \ + } \ + for (int i = 0; i < kSizeUV; ++i) { \ + reinterpret_cast(src_uv + SOFF)[i] = \ + (fastrand() & (((uint16_t)(-1)) << (16 - S_DEPTH))); \ + } \ + memset(dst_argb_c + DOFF, 1, kStrideB * kHeight); \ + memset(dst_argb_opt + DOFF, 101, kStrideB * kHeight); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_PLANAR##To##FMT_B(reinterpret_cast(src_y + SOFF), kWidth, \ + reinterpret_cast(src_uv + SOFF), \ + kStrideUV, dst_argb_c + DOFF, kStrideB, kWidth, \ + NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_PLANAR##To##FMT_B(reinterpret_cast(src_y + SOFF), kWidth, \ + reinterpret_cast(src_uv + SOFF), \ + kStrideUV, dst_argb_opt + DOFF, kStrideB, kWidth, \ + NEG kHeight); \ + } \ + for (int i = 0; i < kWidth * BPP_B * kHeight; ++i) { \ + ASSERT_EQ(dst_argb_c[i + DOFF], dst_argb_opt[i + DOFF]); \ + } \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_uv); \ + free_aligned_buffer_page_end(dst_argb_c); \ + free_aligned_buffer_page_end(dst_argb_opt); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTBP16TOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, S_DEPTH) \ + TESTBP16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, YALIGN, \ + benchmark_width_ + 1, _Any, +, 0, 0, S_DEPTH) \ + TESTBP16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, YALIGN, \ + benchmark_width_, _Unaligned, +, 4, 4, S_DEPTH) \ + TESTBP16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, YALIGN, \ + benchmark_width_, _Invert, -, 0, 0, S_DEPTH) \ + TESTBP16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, YALIGN, \ + benchmark_width_, _Opt, +, 0, 0, S_DEPTH) +#else +#define TESTBP16TOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ + YALIGN, S_DEPTH) \ + TESTBP16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, YALIGN, \ + benchmark_width_, _Opt, +, 0, 0, S_DEPTH) +#endif + +#define P010ToARGB(a, b, c, d, e, f, g, h) \ + P010ToARGBMatrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P210ToARGB(a, b, c, d, e, f, g, h) \ + P210ToARGBMatrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P410ToARGB(a, b, c, d, e, f, g, h) \ + P410ToARGBMatrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P010ToAR30(a, b, c, d, e, f, g, h) \ + P010ToAR30Matrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P210ToAR30(a, b, c, d, e, f, g, h) \ + P210ToAR30Matrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P410ToAR30(a, b, c, d, e, f, g, h) \ + P410ToAR30Matrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) + +#define P012ToARGB(a, b, c, d, e, f, g, h) \ + P012ToARGBMatrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P212ToARGB(a, b, c, d, e, f, g, h) \ + P212ToARGBMatrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P412ToARGB(a, b, c, d, e, f, g, h) \ + P412ToARGBMatrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P012ToAR30(a, b, c, d, e, f, g, h) \ + P012ToAR30Matrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P212ToAR30(a, b, c, d, e, f, g, h) \ + P212ToAR30Matrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P412ToAR30(a, b, c, d, e, f, g, h) \ + P412ToAR30Matrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) + +#define P016ToARGB(a, b, c, d, e, f, g, h) \ + P016ToARGBMatrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P216ToARGB(a, b, c, d, e, f, g, h) \ + P216ToARGBMatrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P416ToARGB(a, b, c, d, e, f, g, h) \ + P416ToARGBMatrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P016ToAR30(a, b, c, d, e, f, g, h) \ + P016ToAR30Matrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P216ToAR30(a, b, c, d, e, f, g, h) \ + P216ToAR30Matrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) +#define P416ToAR30(a, b, c, d, e, f, g, h) \ + P416ToAR30Matrix(a, b, c, d, e, f, &kYuvH709Constants, g, h) + +#define P010ToARGBFilter(a, b, c, d, e, f, g, h) \ + P010ToARGBMatrixFilter(a, b, c, d, e, f, &kYuvH709Constants, g, h, \ + kFilterBilinear) +#define P210ToARGBFilter(a, b, c, d, e, f, g, h) \ + P210ToARGBMatrixFilter(a, b, c, d, e, f, &kYuvH709Constants, g, h, \ + kFilterBilinear) +#define P010ToAR30Filter(a, b, c, d, e, f, g, h) \ + P010ToAR30MatrixFilter(a, b, c, d, e, f, &kYuvH709Constants, g, h, \ + kFilterBilinear) +#define P210ToAR30Filter(a, b, c, d, e, f, g, h) \ + P210ToAR30MatrixFilter(a, b, c, d, e, f, &kYuvH709Constants, g, h, \ + kFilterBilinear) + +#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) +TESTBP16TOB(P010, 2, 2, ARGB, 4, 4, 1, 10) +TESTBP16TOB(P210, 2, 1, ARGB, 4, 4, 1, 10) +TESTBP16TOB(P410, 1, 1, ARGB, 4, 4, 1, 10) +TESTBP16TOB(P012, 2, 2, ARGB, 4, 4, 1, 12) +TESTBP16TOB(P212, 2, 1, ARGB, 4, 4, 1, 12) +TESTBP16TOB(P412, 1, 1, ARGB, 4, 4, 1, 12) +TESTBP16TOB(P016, 2, 2, ARGB, 4, 4, 1, 16) +TESTBP16TOB(P216, 2, 1, ARGB, 4, 4, 1, 16) +TESTBP16TOB(P416, 1, 1, ARGB, 4, 4, 1, 16) +TESTBP16TOB(P010, 2, 2, ARGBFilter, 4, 4, 1, 10) +TESTBP16TOB(P210, 2, 1, ARGBFilter, 4, 4, 1, 10) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTBP16TOB(P010, 2, 2, AR30, 4, 4, 1, 10) +TESTBP16TOB(P210, 2, 1, AR30, 4, 4, 1, 10) +TESTBP16TOB(P410, 1, 1, AR30, 4, 4, 1, 10) +TESTBP16TOB(P012, 2, 2, AR30, 4, 4, 1, 12) +TESTBP16TOB(P212, 2, 1, AR30, 4, 4, 1, 12) +TESTBP16TOB(P412, 1, 1, AR30, 4, 4, 1, 12) +TESTBP16TOB(P016, 2, 2, AR30, 4, 4, 1, 16) +TESTBP16TOB(P216, 2, 1, AR30, 4, 4, 1, 16) +TESTBP16TOB(P416, 1, 1, AR30, 4, 4, 1, 16) +TESTBP16TOB(P010, 2, 2, AR30Filter, 4, 4, 1, 10) +TESTBP16TOB(P210, 2, 1, AR30Filter, 4, 4, 1, 10) +#endif // LITTLE_ENDIAN_ONLY_TEST +#endif // DISABLE_SLOW_TESTS + +static int Clamp(int y) { + if (y < 0) { + y = 0; + } + if (y > 255) { + y = 255; + } + return y; +} + +static int Clamp10(int y) { + if (y < 0) { + y = 0; + } + if (y > 1023) { + y = 1023; + } + return y; +} + +// Test 8 bit YUV to 8 bit RGB +TEST_F(LibYUVConvertTest, TestH420ToARGB) { + const int kSize = 256; + int histogram_b[256]; + int histogram_g[256]; + int histogram_r[256]; + memset(histogram_b, 0, sizeof(histogram_b)); + memset(histogram_g, 0, sizeof(histogram_g)); + memset(histogram_r, 0, sizeof(histogram_r)); + align_buffer_page_end(orig_yuv, kSize + kSize / 2 * 2); + align_buffer_page_end(argb_pixels, kSize * 4); + uint8_t* orig_y = orig_yuv; + uint8_t* orig_u = orig_y + kSize; + uint8_t* orig_v = orig_u + kSize / 2; + + // Test grey scale + for (int i = 0; i < kSize; ++i) { + orig_y[i] = i; + } + for (int i = 0; i < kSize / 2; ++i) { + orig_u[i] = 128; // 128 is 0. + orig_v[i] = 128; + } + + H420ToARGB(orig_y, 0, orig_u, 0, orig_v, 0, argb_pixels, 0, kSize, 1); + + for (int i = 0; i < kSize; ++i) { + int b = argb_pixels[i * 4 + 0]; + int g = argb_pixels[i * 4 + 1]; + int r = argb_pixels[i * 4 + 2]; + int a = argb_pixels[i * 4 + 3]; + ++histogram_b[b]; + ++histogram_g[g]; + ++histogram_r[r]; + // Reference formula for Y channel contribution in YUV to RGB conversions: + int expected_y = Clamp(static_cast((i - 16) * 1.164f + 0.5f)); + ASSERT_EQ(b, expected_y); + ASSERT_EQ(g, expected_y); + ASSERT_EQ(r, expected_y); + ASSERT_EQ(a, 255); + } + + int count_b = 0; + int count_g = 0; + int count_r = 0; + for (int i = 0; i < kSize; ++i) { + if (histogram_b[i]) { + ++count_b; + } + if (histogram_g[i]) { + ++count_g; + } + if (histogram_r[i]) { + ++count_r; + } + } + printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); + + free_aligned_buffer_page_end(orig_yuv); + free_aligned_buffer_page_end(argb_pixels); +} + +// Test 10 bit YUV to 8 bit RGB +TEST_F(LibYUVConvertTest, TestH010ToARGB) { + const int kSize = 1024; + int histogram_b[1024]; + int histogram_g[1024]; + int histogram_r[1024]; + memset(histogram_b, 0, sizeof(histogram_b)); + memset(histogram_g, 0, sizeof(histogram_g)); + memset(histogram_r, 0, sizeof(histogram_r)); + align_buffer_page_end(orig_yuv, kSize * 2 + kSize / 2 * 2 * 2); + align_buffer_page_end(argb_pixels, kSize * 4); + uint16_t* orig_y = reinterpret_cast(orig_yuv); + uint16_t* orig_u = orig_y + kSize; + uint16_t* orig_v = orig_u + kSize / 2; + + // Test grey scale + for (int i = 0; i < kSize; ++i) { + orig_y[i] = i; + } + for (int i = 0; i < kSize / 2; ++i) { + orig_u[i] = 512; // 512 is 0. + orig_v[i] = 512; + } + + H010ToARGB(orig_y, 0, orig_u, 0, orig_v, 0, argb_pixels, 0, kSize, 1); + + for (int i = 0; i < kSize; ++i) { + int b = argb_pixels[i * 4 + 0]; + int g = argb_pixels[i * 4 + 1]; + int r = argb_pixels[i * 4 + 2]; + int a = argb_pixels[i * 4 + 3]; + ++histogram_b[b]; + ++histogram_g[g]; + ++histogram_r[r]; + int expected_y = Clamp(static_cast((i - 64) * 1.164f / 4)); + ASSERT_NEAR(b, expected_y, 1); + ASSERT_NEAR(g, expected_y, 1); + ASSERT_NEAR(r, expected_y, 1); + ASSERT_EQ(a, 255); + } + + int count_b = 0; + int count_g = 0; + int count_r = 0; + for (int i = 0; i < kSize; ++i) { + if (histogram_b[i]) { + ++count_b; + } + if (histogram_g[i]) { + ++count_g; + } + if (histogram_r[i]) { + ++count_r; + } + } + printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); + + free_aligned_buffer_page_end(orig_yuv); + free_aligned_buffer_page_end(argb_pixels); +} + +// Test 10 bit YUV to 10 bit RGB +// Caveat: Result is near due to float rounding in expected +// result. +TEST_F(LibYUVConvertTest, TestH010ToAR30) { + const int kSize = 1024; + int histogram_b[1024]; + int histogram_g[1024]; + int histogram_r[1024]; + memset(histogram_b, 0, sizeof(histogram_b)); + memset(histogram_g, 0, sizeof(histogram_g)); + memset(histogram_r, 0, sizeof(histogram_r)); + + align_buffer_page_end(orig_yuv, kSize * 2 + kSize / 2 * 2 * 2); + align_buffer_page_end(ar30_pixels, kSize * 4); + uint16_t* orig_y = reinterpret_cast(orig_yuv); + uint16_t* orig_u = orig_y + kSize; + uint16_t* orig_v = orig_u + kSize / 2; + + // Test grey scale + for (int i = 0; i < kSize; ++i) { + orig_y[i] = i; + } + for (int i = 0; i < kSize / 2; ++i) { + orig_u[i] = 512; // 512 is 0. + orig_v[i] = 512; + } + + H010ToAR30(orig_y, 0, orig_u, 0, orig_v, 0, ar30_pixels, 0, kSize, 1); + + for (int i = 0; i < kSize; ++i) { + int b10 = reinterpret_cast(ar30_pixels)[i] & 1023; + int g10 = (reinterpret_cast(ar30_pixels)[i] >> 10) & 1023; + int r10 = (reinterpret_cast(ar30_pixels)[i] >> 20) & 1023; + int a2 = (reinterpret_cast(ar30_pixels)[i] >> 30) & 3; + ++histogram_b[b10]; + ++histogram_g[g10]; + ++histogram_r[r10]; + int expected_y = Clamp10(static_cast((i - 64) * 1.164f + 0.5)); + ASSERT_NEAR(b10, expected_y, 4); + ASSERT_NEAR(g10, expected_y, 4); + ASSERT_NEAR(r10, expected_y, 4); + ASSERT_EQ(a2, 3); + } + + int count_b = 0; + int count_g = 0; + int count_r = 0; + for (int i = 0; i < kSize; ++i) { + if (histogram_b[i]) { + ++count_b; + } + if (histogram_g[i]) { + ++count_g; + } + if (histogram_r[i]) { + ++count_r; + } + } + printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); + + free_aligned_buffer_page_end(orig_yuv); + free_aligned_buffer_page_end(ar30_pixels); +} + +// Test 10 bit YUV to 10 bit RGB +// Caveat: Result is near due to float rounding in expected +// result. +TEST_F(LibYUVConvertTest, TestH010ToAB30) { + const int kSize = 1024; + int histogram_b[1024]; + int histogram_g[1024]; + int histogram_r[1024]; + memset(histogram_b, 0, sizeof(histogram_b)); + memset(histogram_g, 0, sizeof(histogram_g)); + memset(histogram_r, 0, sizeof(histogram_r)); + + align_buffer_page_end(orig_yuv, kSize * 2 + kSize / 2 * 2 * 2); + align_buffer_page_end(ab30_pixels, kSize * 4); + uint16_t* orig_y = reinterpret_cast(orig_yuv); + uint16_t* orig_u = orig_y + kSize; + uint16_t* orig_v = orig_u + kSize / 2; + + // Test grey scale + for (int i = 0; i < kSize; ++i) { + orig_y[i] = i; + } + for (int i = 0; i < kSize / 2; ++i) { + orig_u[i] = 512; // 512 is 0. + orig_v[i] = 512; + } + + H010ToAB30(orig_y, 0, orig_u, 0, orig_v, 0, ab30_pixels, 0, kSize, 1); + + for (int i = 0; i < kSize; ++i) { + int r10 = reinterpret_cast(ab30_pixels)[i] & 1023; + int g10 = (reinterpret_cast(ab30_pixels)[i] >> 10) & 1023; + int b10 = (reinterpret_cast(ab30_pixels)[i] >> 20) & 1023; + int a2 = (reinterpret_cast(ab30_pixels)[i] >> 30) & 3; + ++histogram_b[b10]; + ++histogram_g[g10]; + ++histogram_r[r10]; + int expected_y = Clamp10(static_cast((i - 64) * 1.164f + 0.5)); + ASSERT_NEAR(r10, expected_y, 4); + ASSERT_NEAR(g10, expected_y, 4); + ASSERT_NEAR(b10, expected_y, 4); + ASSERT_EQ(a2, 3); + } + + int count_b = 0; + int count_g = 0; + int count_r = 0; + for (int i = 0; i < kSize; ++i) { + if (histogram_b[i]) { + ++count_b; + } + if (histogram_g[i]) { + ++count_g; + } + if (histogram_r[i]) { + ++count_r; + } + } + printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); + + free_aligned_buffer_page_end(orig_yuv); + free_aligned_buffer_page_end(ab30_pixels); +} + +// Test 8 bit YUV to 10 bit RGB +TEST_F(LibYUVConvertTest, TestH420ToAR30) { + const int kSize = 256; + const int kHistSize = 1024; + int histogram_b[kHistSize]; + int histogram_g[kHistSize]; + int histogram_r[kHistSize]; + memset(histogram_b, 0, sizeof(histogram_b)); + memset(histogram_g, 0, sizeof(histogram_g)); + memset(histogram_r, 0, sizeof(histogram_r)); + align_buffer_page_end(orig_yuv, kSize + kSize / 2 * 2); + align_buffer_page_end(ar30_pixels, kSize * 4); + uint8_t* orig_y = orig_yuv; + uint8_t* orig_u = orig_y + kSize; + uint8_t* orig_v = orig_u + kSize / 2; + + // Test grey scale + for (int i = 0; i < kSize; ++i) { + orig_y[i] = i; + } + for (int i = 0; i < kSize / 2; ++i) { + orig_u[i] = 128; // 128 is 0. + orig_v[i] = 128; + } + + H420ToAR30(orig_y, 0, orig_u, 0, orig_v, 0, ar30_pixels, 0, kSize, 1); + + for (int i = 0; i < kSize; ++i) { + int b10 = reinterpret_cast(ar30_pixels)[i] & 1023; + int g10 = (reinterpret_cast(ar30_pixels)[i] >> 10) & 1023; + int r10 = (reinterpret_cast(ar30_pixels)[i] >> 20) & 1023; + int a2 = (reinterpret_cast(ar30_pixels)[i] >> 30) & 3; + ++histogram_b[b10]; + ++histogram_g[g10]; + ++histogram_r[r10]; + int expected_y = Clamp10(static_cast((i - 16) * 1.164f * 4.f + 0.5)); + ASSERT_NEAR(b10, expected_y, 4); + ASSERT_NEAR(g10, expected_y, 4); + ASSERT_NEAR(r10, expected_y, 4); + ASSERT_EQ(a2, 3); + } + + int count_b = 0; + int count_g = 0; + int count_r = 0; + for (int i = 0; i < kHistSize; ++i) { + if (histogram_b[i]) { + ++count_b; + } + if (histogram_g[i]) { + ++count_g; + } + if (histogram_r[i]) { + ++count_r; + } + } + printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); + + free_aligned_buffer_page_end(orig_yuv); + free_aligned_buffer_page_end(ar30_pixels); +} + +// Test I400 with jpeg matrix is same as J400 +TEST_F(LibYUVConvertTest, TestI400) { + const int kSize = 256; + align_buffer_page_end(orig_i400, kSize); + align_buffer_page_end(argb_pixels_i400, kSize * 4); + align_buffer_page_end(argb_pixels_j400, kSize * 4); + align_buffer_page_end(argb_pixels_jpeg_i400, kSize * 4); + align_buffer_page_end(argb_pixels_h709_i400, kSize * 4); + align_buffer_page_end(argb_pixels_2020_i400, kSize * 4); + + // Test grey scale + for (int i = 0; i < kSize; ++i) { + orig_i400[i] = i; + } + + J400ToARGB(orig_i400, 0, argb_pixels_j400, 0, kSize, 1); + I400ToARGB(orig_i400, 0, argb_pixels_i400, 0, kSize, 1); + I400ToARGBMatrix(orig_i400, 0, argb_pixels_jpeg_i400, 0, &kYuvJPEGConstants, + kSize, 1); + I400ToARGBMatrix(orig_i400, 0, argb_pixels_h709_i400, 0, &kYuvH709Constants, + kSize, 1); + I400ToARGBMatrix(orig_i400, 0, argb_pixels_2020_i400, 0, &kYuv2020Constants, + kSize, 1); + + ASSERT_EQ(0, argb_pixels_i400[0]); + ASSERT_EQ(0, argb_pixels_j400[0]); + ASSERT_EQ(0, argb_pixels_jpeg_i400[0]); + ASSERT_EQ(0, argb_pixels_h709_i400[0]); + ASSERT_EQ(0, argb_pixels_2020_i400[0]); + ASSERT_EQ(0, argb_pixels_i400[16 * 4]); + ASSERT_EQ(16, argb_pixels_j400[16 * 4]); + ASSERT_EQ(16, argb_pixels_jpeg_i400[16 * 4]); + ASSERT_EQ(0, argb_pixels_h709_i400[16 * 4]); + ASSERT_EQ(0, argb_pixels_2020_i400[16 * 4]); + ASSERT_EQ(130, argb_pixels_i400[128 * 4]); + ASSERT_EQ(128, argb_pixels_j400[128 * 4]); + ASSERT_EQ(128, argb_pixels_jpeg_i400[128 * 4]); + ASSERT_EQ(130, argb_pixels_h709_i400[128 * 4]); + ASSERT_EQ(130, argb_pixels_2020_i400[128 * 4]); + ASSERT_EQ(255, argb_pixels_i400[255 * 4]); + ASSERT_EQ(255, argb_pixels_j400[255 * 4]); + ASSERT_EQ(255, argb_pixels_jpeg_i400[255 * 4]); + ASSERT_EQ(255, argb_pixels_h709_i400[255 * 4]); + ASSERT_EQ(255, argb_pixels_2020_i400[255 * 4]); + + for (int i = 0; i < kSize * 4; ++i) { + if ((i & 3) == 3) { + ASSERT_EQ(255, argb_pixels_j400[i]); + } else { + ASSERT_EQ(i / 4, argb_pixels_j400[i]); + } + ASSERT_EQ(argb_pixels_jpeg_i400[i], argb_pixels_j400[i]); + } + + free_aligned_buffer_page_end(orig_i400); + free_aligned_buffer_page_end(argb_pixels_i400); + free_aligned_buffer_page_end(argb_pixels_j400); + free_aligned_buffer_page_end(argb_pixels_jpeg_i400); + free_aligned_buffer_page_end(argb_pixels_h709_i400); + free_aligned_buffer_page_end(argb_pixels_2020_i400); +} + +// Test RGB24 to ARGB and back to RGB24 +TEST_F(LibYUVConvertTest, TestARGBToRGB24) { + const int kSize = 256; + align_buffer_page_end(orig_rgb24, kSize * 3); + align_buffer_page_end(argb_pixels, kSize * 4); + align_buffer_page_end(dest_rgb24, kSize * 3); + + // Test grey scale + for (int i = 0; i < kSize * 3; ++i) { + orig_rgb24[i] = i; + } + + RGB24ToARGB(orig_rgb24, 0, argb_pixels, 0, kSize, 1); + ARGBToRGB24(argb_pixels, 0, dest_rgb24, 0, kSize, 1); + + for (int i = 0; i < kSize * 3; ++i) { + ASSERT_EQ(orig_rgb24[i], dest_rgb24[i]); + } + + free_aligned_buffer_page_end(orig_rgb24); + free_aligned_buffer_page_end(argb_pixels); + free_aligned_buffer_page_end(dest_rgb24); +} + +TEST_F(LibYUVConvertTest, TestARGBToRGB565) { + SIMD_ALIGNED(uint8_t orig_pixels[256][4]); + SIMD_ALIGNED(uint8_t dest_rgb565[256][2]); + + for (int i = 0; i < 256; ++i) { + for (int j = 0; j < 4; ++j) { + orig_pixels[i][j] = i; + } + } + ARGBToRGB565(&orig_pixels[0][0], 0, &dest_rgb565[0][0], 0, 256, 1); + uint32_t checksum = HashDjb2(&dest_rgb565[0][0], sizeof(dest_rgb565), 5381); + ASSERT_EQ(610919429u, checksum); +} + +TEST_F(LibYUVConvertTest, TestYUY2ToARGB) { + SIMD_ALIGNED(uint8_t orig_pixels[256][2]); + SIMD_ALIGNED(uint8_t dest_argb[256][4]); + + for (int i = 0; i < 256; ++i) { + for (int j = 0; j < 2; ++j) { + orig_pixels[i][j] = i; + } + } + YUY2ToARGB(&orig_pixels[0][0], 0, &dest_argb[0][0], 0, 256, 1); + uint32_t checksum = HashDjb2(&dest_argb[0][0], sizeof(dest_argb), 5381); +#if defined(LIBYUV_UNLIMITED_DATA) + ASSERT_EQ(10343289u, checksum); +#else + ASSERT_EQ(3486643515u, checksum); +#endif +} + +TEST_F(LibYUVConvertTest, TestUYVYToARGB) { + SIMD_ALIGNED(uint8_t orig_pixels[256][2]); + SIMD_ALIGNED(uint8_t dest_argb[256][4]); + + for (int i = 0; i < 256; ++i) { + for (int j = 0; j < 2; ++j) { + orig_pixels[i][j] = i; + } + } + UYVYToARGB(&orig_pixels[0][0], 0, &dest_argb[0][0], 0, 256, 1); + uint32_t checksum = HashDjb2(&dest_argb[0][0], sizeof(dest_argb), 5381); +#if defined(LIBYUV_UNLIMITED_DATA) + ASSERT_EQ(10343289u, checksum); +#else + ASSERT_EQ(3486643515u, checksum); +#endif +} + +// Call P010ToARGBMatrixFilter() with a width that is not a multiple of 16. +// Verify there is no stack buffer overflow in P410ToARGBRow_Any_AVX2(). +TEST_F(LibYUVConvertTest, P010ToARGBMatrixFilterOverflow) { + int width = 1024 + 15; // 1039 + int height = 4; + int dst_stride_argb = width * 4; + int src_stride_uv = (width + 1) & ~1; + int src_uv_height = (height + 1) / 2; + align_buffer_page_end_16(src_y, width * height); + align_buffer_page_end_16(src_uv, src_stride_uv * src_uv_height); + align_buffer_page_end(dst_argb, dst_stride_argb * height); + memset(src_y, 0x02, width * height * sizeof(uint16_t)); + memset(src_uv, 0x02, src_stride_uv * src_uv_height * sizeof(uint16_t)); + EXPECT_EQ( + 0, P010ToARGBMatrixFilter(src_y, width, src_uv, src_stride_uv, dst_argb, + dst_stride_argb, &kYuvI601Constants, width, + height, kFilterBilinear)); + free_aligned_buffer_page_end_16(src_y); + free_aligned_buffer_page_end_16(src_uv); + free_aligned_buffer_page_end(dst_argb); +} + +// Call P210ToARGBMatrixFilter() with a width that is not a multiple of 16. +// Verify there is no stack buffer overflow in P410ToARGBRow_Any_AVX2(). +TEST_F(LibYUVConvertTest, P210ToARGBMatrixFilterOverflow) { + int width = 1024 + 15; // 1039 + int height = 4; + int dst_stride_argb = width * 4; + int src_stride_uv = (width + 1) & ~1; + align_buffer_page_end_16(src_y, width * height); + align_buffer_page_end_16(src_uv, src_stride_uv * height); + align_buffer_page_end(dst_argb, dst_stride_argb * height); + memset(src_y, 0x02, width * height * sizeof(uint16_t)); + memset(src_uv, 0x02, src_stride_uv * height * sizeof(uint16_t)); + EXPECT_EQ( + 0, P210ToARGBMatrixFilter(src_y, width, src_uv, src_stride_uv, dst_argb, + dst_stride_argb, &kYuvI601Constants, width, + height, kFilterBilinear)); + free_aligned_buffer_page_end_16(src_y); + free_aligned_buffer_page_end_16(src_uv); + free_aligned_buffer_page_end(dst_argb); +} + +// Call P010ToAR30MatrixFilter() with a width that is not a multiple of 16. +// Verify there is no stack buffer overflow in P410ToAR30Row_Any_AVX2(). +TEST_F(LibYUVConvertTest, P010ToAR30MatrixFilterOverflow) { + int width = 1024 + 15; // 1039 + int height = 4; + int dst_stride_argb = width * 4; + int src_stride_uv = (width + 1) & ~1; + int src_uv_height = (height + 1) / 2; + align_buffer_page_end_16(src_y, width * height); + align_buffer_page_end_16(src_uv, src_stride_uv * src_uv_height); + align_buffer_page_end(dst_argb, dst_stride_argb * height); + memset(src_y, 0x02, width * height * sizeof(uint16_t)); + memset(src_uv, 0x02, src_stride_uv * src_uv_height * sizeof(uint16_t)); + EXPECT_EQ( + 0, P010ToAR30MatrixFilter(src_y, width, src_uv, src_stride_uv, dst_argb, + dst_stride_argb, &kYuvI601Constants, width, + height, kFilterBilinear)); + free_aligned_buffer_page_end_16(src_y); + free_aligned_buffer_page_end_16(src_uv); + free_aligned_buffer_page_end(dst_argb); +} + +// Call P210ToAR30MatrixFilter(() with a width that is not a multiple of 16. +// Verify there is no stack buffer overflow in P410ToAR30Row_Any_AVX2(). +TEST_F(LibYUVConvertTest, P210ToAR30MatrixFilterOverflow) { + int width = 1024 + 15; // 1039 + int height = 4; + int dst_stride_ar30 = width * 4; + int src_stride_uv = (width + 1) & ~1; + align_buffer_page_end_16(src_y, width * height); + align_buffer_page_end_16(src_uv, src_stride_uv * height); + align_buffer_page_end(dst_ar30, dst_stride_ar30 * height); + memset(src_y, 0x02, width * height * sizeof(uint16_t)); + memset(src_uv, 0x02, src_stride_uv * height * sizeof(uint16_t)); + EXPECT_EQ( + 0, P210ToAR30MatrixFilter(src_y, width, src_uv, src_stride_uv, dst_ar30, + dst_stride_ar30, &kYuvI601Constants, width, + height, kFilterBilinear)); + free_aligned_buffer_page_end_16(src_y); + free_aligned_buffer_page_end_16(src_uv); + free_aligned_buffer_page_end(dst_ar30); +} + +#ifdef ENABLE_ROW_TESTS +TEST_F(LibYUVConvertTest, TestARGBToUVMatrixRow_Opt) { + const int kMaxWidth = 128; + SIMD_ALIGNED(uint8_t orig_argb_pixels[kMaxWidth * 4 * 2]); + SIMD_ALIGNED(uint8_t dest_u_c[kMaxWidth]); + SIMD_ALIGNED(uint8_t dest_v_c[kMaxWidth]); + SIMD_ALIGNED(uint8_t dest_u_opt[kMaxWidth]); + SIMD_ALIGNED(uint8_t dest_v_opt[kMaxWidth]); + + for (int i = 0; i < kMaxWidth * 4 * 2; ++i) { + orig_argb_pixels[i] = i * 43; + } + +#if defined(HAS_ARGBTOUVMATRIXROW_NEON) + int has_neon = TestCpuFlag(kCpuHasNEON); + if (has_neon) { + for (int width = 1; width <= kMaxWidth; ++width) { + for (int height = 1; height <= 2; ++height) { + memset(dest_u_c, 0, sizeof(dest_u_c)); + memset(dest_v_c, 0, sizeof(dest_v_c)); + memset(dest_u_opt, 0, sizeof(dest_u_opt)); + memset(dest_v_opt, 0, sizeof(dest_v_opt)); + + int src_stride = (height == 1) ? 0 : kMaxWidth * 4; + + ARGBToUVMatrixRow_C(&orig_argb_pixels[0], src_stride, &dest_u_c[0], + &dest_v_c[0], width, &kArgbI601Constants); + ARGBToUVMatrixRow_Any_NEON(&orig_argb_pixels[0], src_stride, + &dest_u_opt[0], &dest_v_opt[0], width, + &kArgbI601Constants); + + int half_width = (width + 1) / 2; + for (int i = 0; i < half_width; ++i) { + ASSERT_EQ(dest_u_c[i], dest_u_opt[i]) + << "u mismatch at " << i << " width " << width << " height " + << height; + ASSERT_EQ(dest_v_c[i], dest_v_opt[i]) + << "v mismatch at " << i << " width " << width << " height " + << height; + } + } + } + } +#endif +} +#endif + +#if !defined(DISABLE_SLOW_TESTS) && \ + (defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__)) +// TODO(fbarchard): Consider _set_new_mode(0) to make malloc return NULL + +#ifndef DISABLE_SLOW_TESTS +TEST_F(LibYUVConvertTest, TestI400LargeSize) { + // The width and height are chosen as follows: + // - kWidth * kHeight is not a multiple of 8: This lets us to use the Any + // variant of the conversion function. + const int kWidth = 1073741823; + const int kHeight = 2; + +#if defined(__aarch64__) + // Infer malloc can accept a large size for cpu with dot product (a76/a55) + int has_large_malloc = TestCpuFlag(kCpuHasNeonDotProd); +#elif defined(__SANITIZE_MEMORY__) + int has_large_malloc = 0; +#elif defined(__has_feature) +#if __has_feature(memory_sanitizer) + int has_large_malloc = 0; +#else + int has_large_malloc = 1; +#endif +#else + int has_large_malloc = 1; +#endif + if (!has_large_malloc) { + GTEST_SKIP() << "WARNING: Large allocation may assert for " + << (size_t)kWidth * kHeight << " bytes"; + } + + // Allocate one extra column so that the coalesce optimizations do not trigger + // in convert_argb.cc (they are triggered only when stride is equal to width). + const size_t kStride = kWidth + 1; + + printf("WARNING: attempting to allocate I400 image of %zd bytes\n", + (size_t)kWidth * kHeight); + fflush(stdout); + align_buffer_page_end(orig_i400, (size_t)kWidth * kHeight); + if (!orig_i400) { + GTEST_SKIP() << "WARNING: unable to allocate I400 image of " + << (size_t)kWidth * kHeight << " bytes"; + } + printf("INFO: allocate I400 image returned %p\n", orig_i400); + fflush(stdout); + align_buffer_page_end(dest_argb, (size_t)kWidth * kHeight * 4); + if (!dest_argb) { + free_aligned_buffer_page_end(orig_i400); + GTEST_SKIP() << "WARNING: unable to allocate ARGB image of " + << (size_t)kWidth * kHeight * 4 << " bytes"; + } + printf("INFO: allocate ARGB image returned %p\n", dest_argb); + fflush(stdout); + for (int i = 0; i < kWidth * kHeight; ++i) { + orig_i400[i] = i % 256; + } + ASSERT_EQ(I400ToARGBMatrix(orig_i400, kStride, dest_argb, kWidth, + &kYuvJPEGConstants, kWidth, kHeight), + 0); + free_aligned_buffer_page_end(dest_argb); + free_aligned_buffer_page_end(orig_i400); +} +#endif // DISABLE_SLOW_TESTS +#endif // !defined(DISABLE_SLOW_TESTS) && \ + // (defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__)) + +#endif // !defined(LEAN_TESTS) + +#define TESTATOBPI(FMT_A, TYPE_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, SUBSAMP_X, \ + SUBSAMP_Y, W1280, N, NEG, OFF) \ + TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ + const int kStrideA = \ + (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ + const int kStrideY = kWidth; \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X) * 2; \ + const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ + align_buffer_page_end(src_argb, \ + kStrideA * kHeightA * (int)sizeof(TYPE_A) + OFF); \ + align_buffer_page_end(dst_y_c, kStrideY * kHeight); \ + align_buffer_page_end(dst_uv_c, kSizeUV); \ + align_buffer_page_end(dst_y_opt, kStrideY * kHeight); \ + align_buffer_page_end(dst_uv_opt, kSizeUV); \ + for (int i = 0; i < kStrideA * kHeightA * (int)sizeof(TYPE_A); ++i) { \ + src_argb[i + OFF] = (fastrand() & 0xff); \ + } \ + memset(dst_y_c, 1, kStrideY * kHeight); \ + memset(dst_uv_c, 2, kSizeUV); \ + memset(dst_y_opt, 101, kStrideY * kHeight); \ + memset(dst_uv_opt, 102, kSizeUV); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_A##To##FMT_B((TYPE_A*)(src_argb + OFF), kStrideA, dst_y_c, kStrideY, \ + dst_uv_c, kStrideUV, kWidth, NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_A##To##FMT_B((TYPE_A*)(src_argb + OFF), kStrideA, dst_y_opt, \ + kStrideY, dst_uv_opt, kStrideUV, kWidth, NEG kHeight); \ + } \ + for (int i = 0; i < kStrideY * kHeight; ++i) { \ + ASSERT_EQ(dst_y_c[i], dst_y_opt[i]); \ + } \ + for (int i = 0; i < kSizeUV; ++i) { \ + ASSERT_EQ(dst_uv_c[i], dst_uv_opt[i]); \ + } \ + free_aligned_buffer_page_end(src_argb); \ + free_aligned_buffer_page_end(dst_y_c); \ + free_aligned_buffer_page_end(dst_uv_c); \ + free_aligned_buffer_page_end(dst_y_opt); \ + free_aligned_buffer_page_end(dst_uv_opt); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTATOBP(FMT_A, TYPE_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, SUBSAMP_X, \ + SUBSAMP_Y) \ + TESTATOBPI(FMT_A, TYPE_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, SUBSAMP_X, \ + SUBSAMP_Y, benchmark_width_ + 1, _Any, +, 0) \ + TESTATOBPI(FMT_A, TYPE_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, SUBSAMP_X, \ + SUBSAMP_Y, benchmark_width_, _Unaligned, +, 4) \ + TESTATOBPI(FMT_A, TYPE_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, SUBSAMP_X, \ + SUBSAMP_Y, benchmark_width_, _Invert, -, 0) \ + TESTATOBPI(FMT_A, TYPE_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, SUBSAMP_X, \ + SUBSAMP_Y, benchmark_width_, _Opt, +, 0) +#else +#define TESTATOBP(FMT_A, TYPE_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, SUBSAMP_X, \ + SUBSAMP_Y) \ + TESTATOBPI(FMT_A, TYPE_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, SUBSAMP_X, \ + SUBSAMP_Y, benchmark_width_, _Opt, +, 0) +#endif + +TESTATOBP(RAW, uint8_t, 3, 3, 1, NV21, 2, 2) +TESTATOBP(RGB24, uint8_t, 3, 3, 1, NV12, 2, 2) +TESTATOBP(RAW, uint8_t, 3, 3, 1, JNV21, 2, 2) + +} // namespace libyuv diff --git a/libs/libyuv/unit_test/convert_test.cc b/libs/libyuv/unit_test/convert_test.cc index b676954b21..aaba43f29d 100644 --- a/libs/libyuv/unit_test/convert_test.cc +++ b/libs/libyuv/unit_test/convert_test.cc @@ -10,9 +10,9 @@ #include #include +#include #include -#include "libyuv/basic_types.h" #include "libyuv/compare.h" #include "libyuv/convert.h" #include "libyuv/convert_argb.h" @@ -27,21 +27,21 @@ #include "libyuv/rotate.h" #include "libyuv/video_common.h" -#ifdef ENABLE_ROW_TESTS -#include "libyuv/row.h" /* For ARGBToAR30Row_AVX2 */ +#if (defined(__riscv) && !defined(__clang__)) || defined(__hexagon__) +#define DISABLE_SLOW_TESTS +#undef ENABLE_FULL_TESTS +#define LEAN_TESTS #endif -#if defined(__arm__) || defined(__aarch64__) -// arm version subsamples by summing 4 pixels then multiplying by matrix with -// 4x smaller coefficients which are rounded to nearest integer. -#define ARM_YUV_ERROR 4 -#else -#define ARM_YUV_ERROR 0 +// Some functions fail on big endian. Enable these tests on all cpus except +// PowerPC, but they are not optimized so disabled by default. +#if !defined(DISABLE_SLOW_TESTS) && !defined(__powerpc__) +#define LITTLE_ENDIAN_ONLY_TEST 1 #endif - -// Some functions fail on big endian. Enable these tests on all cpus except PowerPC -#if !defined(__powerpc__) -#define LITTLE_ENDIAN_TEST 1 +#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) +// SLOW TESTS are those that are unoptimized C code. +// FULL TESTS are optimized but test many variations of the same code. +#define ENABLE_FULL_TESTS #endif namespace libyuv { @@ -50,76 +50,90 @@ namespace libyuv { #define AR30ToAR30 ARGBCopy #define ABGRToABGR ARGBCopy -#define SUBSAMPLE(v, a) ((((v) + (a)-1)) / (a)) +// subsample amount uses a divide. +#define SUBSAMPLE(v, a) ((((v) + (a) - 1)) / (a)) + +#define ALIGNINT(V, ALIGN) (((V) + (ALIGN) - 1) / (ALIGN) * (ALIGN)) // Planar test #define TESTPLANARTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, \ - DST_SUBSAMP_X, DST_SUBSAMP_Y, W1280, N, NEG, OFF) \ + DST_SUBSAMP_X, DST_SUBSAMP_Y, W1280, N, NEG, OFF, DOY, \ + SRC_DEPTH) \ TEST_F(LibYUVConvertTest, SRC_FMT_PLANAR##To##FMT_PLANAR##N) { \ static_assert(SRC_BPC == 1 || SRC_BPC == 2, "SRC BPC unsupported"); \ static_assert(DST_BPC == 1 || DST_BPC == 2, "DST BPC unsupported"); \ static_assert(SRC_SUBSAMP_X == 1 || SRC_SUBSAMP_X == 2, \ - "DST SRC_SUBSAMP_X unsupported"); \ + "SRC_SUBSAMP_X unsupported"); \ static_assert(SRC_SUBSAMP_Y == 1 || SRC_SUBSAMP_Y == 2, \ - "DST SRC_SUBSAMP_Y unsupported"); \ + "SRC_SUBSAMP_Y unsupported"); \ static_assert(DST_SUBSAMP_X == 1 || DST_SUBSAMP_X == 2, \ - "DST DST_SUBSAMP_X unsupported"); \ + "DST_SUBSAMP_X unsupported"); \ static_assert(DST_SUBSAMP_Y == 1 || DST_SUBSAMP_Y == 2, \ - "DST DST_SUBSAMP_Y unsupported"); \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ + "DST_SUBSAMP_Y unsupported"); \ + const int kWidth = W1280; \ const int kHeight = benchmark_height_; \ const int kSrcHalfWidth = SUBSAMPLE(kWidth, SRC_SUBSAMP_X); \ const int kSrcHalfHeight = SUBSAMPLE(kHeight, SRC_SUBSAMP_Y); \ const int kDstHalfWidth = SUBSAMPLE(kWidth, DST_SUBSAMP_X); \ const int kDstHalfHeight = SUBSAMPLE(kHeight, DST_SUBSAMP_Y); \ - align_buffer_page_end(src_y, kWidth* kHeight* SRC_BPC + OFF); \ + align_buffer_page_end(src_y, kWidth * kHeight * SRC_BPC + OFF); \ align_buffer_page_end(src_u, \ - kSrcHalfWidth* kSrcHalfHeight* SRC_BPC + OFF); \ + kSrcHalfWidth * kSrcHalfHeight * SRC_BPC + OFF); \ align_buffer_page_end(src_v, \ - kSrcHalfWidth* kSrcHalfHeight* SRC_BPC + OFF); \ - align_buffer_page_end(dst_y_c, kWidth* kHeight* DST_BPC); \ - align_buffer_page_end(dst_u_c, kDstHalfWidth* kDstHalfHeight* DST_BPC); \ - align_buffer_page_end(dst_v_c, kDstHalfWidth* kDstHalfHeight* DST_BPC); \ - align_buffer_page_end(dst_y_opt, kWidth* kHeight* DST_BPC); \ - align_buffer_page_end(dst_u_opt, kDstHalfWidth* kDstHalfHeight* DST_BPC); \ - align_buffer_page_end(dst_v_opt, kDstHalfWidth* kDstHalfHeight* DST_BPC); \ + kSrcHalfWidth * kSrcHalfHeight * SRC_BPC + OFF); \ + align_buffer_page_end(dst_y_c, kWidth * kHeight * DST_BPC); \ + align_buffer_page_end(dst_u_c, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + align_buffer_page_end(dst_v_c, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + align_buffer_page_end(dst_y_opt, kWidth * kHeight * DST_BPC); \ + align_buffer_page_end(dst_u_opt, \ + kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + align_buffer_page_end(dst_v_opt, \ + kDstHalfWidth * kDstHalfHeight * DST_BPC); \ MemRandomize(src_y + OFF, kWidth * kHeight * SRC_BPC); \ MemRandomize(src_u + OFF, kSrcHalfWidth * kSrcHalfHeight * SRC_BPC); \ MemRandomize(src_v + OFF, kSrcHalfWidth * kSrcHalfHeight * SRC_BPC); \ - memset(dst_y_c, 1, kWidth* kHeight* DST_BPC); \ - memset(dst_u_c, 2, kDstHalfWidth* kDstHalfHeight* DST_BPC); \ - memset(dst_v_c, 3, kDstHalfWidth* kDstHalfHeight* DST_BPC); \ - memset(dst_y_opt, 101, kWidth* kHeight* DST_BPC); \ - memset(dst_u_opt, 102, kDstHalfWidth* kDstHalfHeight* DST_BPC); \ - memset(dst_v_opt, 103, kDstHalfWidth* kDstHalfHeight* DST_BPC); \ + SRC_T* src_y_p = reinterpret_cast(src_y + OFF); \ + SRC_T* src_u_p = reinterpret_cast(src_u + OFF); \ + SRC_T* src_v_p = reinterpret_cast(src_v + OFF); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + src_y_p[i] = src_y_p[i] & ((1 << SRC_DEPTH) - 1); \ + } \ + for (int i = 0; i < kSrcHalfWidth * kSrcHalfHeight; ++i) { \ + src_u_p[i] = src_u_p[i] & ((1 << SRC_DEPTH) - 1); \ + src_v_p[i] = src_v_p[i] & ((1 << SRC_DEPTH) - 1); \ + } \ + memset(dst_y_c, 1, kWidth * kHeight * DST_BPC); \ + memset(dst_u_c, 2, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + memset(dst_v_c, 3, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + memset(dst_y_opt, 101, kWidth * kHeight * DST_BPC); \ + memset(dst_u_opt, 102, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + memset(dst_v_opt, 103, kDstHalfWidth * kDstHalfHeight * DST_BPC); \ MaskCpuFlags(disable_cpu_flags_); \ SRC_FMT_PLANAR##To##FMT_PLANAR( \ - reinterpret_cast(src_y + OFF), kWidth, \ - reinterpret_cast(src_u + OFF), kSrcHalfWidth, \ - reinterpret_cast(src_v + OFF), kSrcHalfWidth, \ - reinterpret_cast(dst_y_c), kWidth, \ + src_y_p, kWidth, src_u_p, kSrcHalfWidth, src_v_p, kSrcHalfWidth, \ + DOY ? reinterpret_cast(dst_y_c) : NULL, kWidth, \ reinterpret_cast(dst_u_c), kDstHalfWidth, \ reinterpret_cast(dst_v_c), kDstHalfWidth, kWidth, \ NEG kHeight); \ MaskCpuFlags(benchmark_cpu_info_); \ for (int i = 0; i < benchmark_iterations_; ++i) { \ SRC_FMT_PLANAR##To##FMT_PLANAR( \ - reinterpret_cast(src_y + OFF), kWidth, \ - reinterpret_cast(src_u + OFF), kSrcHalfWidth, \ - reinterpret_cast(src_v + OFF), kSrcHalfWidth, \ - reinterpret_cast(dst_y_opt), kWidth, \ + src_y_p, kWidth, src_u_p, kSrcHalfWidth, src_v_p, kSrcHalfWidth, \ + DOY ? reinterpret_cast(dst_y_opt) : NULL, kWidth, \ reinterpret_cast(dst_u_opt), kDstHalfWidth, \ reinterpret_cast(dst_v_opt), kDstHalfWidth, kWidth, \ NEG kHeight); \ } \ - for (int i = 0; i < kHeight * kWidth * DST_BPC; ++i) { \ - EXPECT_EQ(dst_y_c[i], dst_y_opt[i]); \ + if (DOY) { \ + for (int i = 0; i < kHeight * kWidth * DST_BPC; ++i) { \ + ASSERT_EQ(dst_y_c[i], dst_y_opt[i]); \ + } \ } \ for (int i = 0; i < kDstHalfWidth * kDstHalfHeight * DST_BPC; ++i) { \ - EXPECT_EQ(dst_u_c[i], dst_u_opt[i]); \ - EXPECT_EQ(dst_v_c[i], dst_v_opt[i]); \ + ASSERT_EQ(dst_u_c[i], dst_u_opt[i]); \ + ASSERT_EQ(dst_v_c[i], dst_v_opt[i]); \ } \ free_aligned_buffer_page_end(dst_y_c); \ free_aligned_buffer_page_end(dst_u_c); \ @@ -132,55 +146,91 @@ namespace libyuv { free_aligned_buffer_page_end(src_v); \ } +#if defined(ENABLE_FULL_TESTS) #define TESTPLANARTOP(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, \ - DST_SUBSAMP_X, DST_SUBSAMP_Y) \ + DST_SUBSAMP_X, DST_SUBSAMP_Y, SRC_DEPTH) \ TESTPLANARTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ - benchmark_width_ - 4, _Any, +, 0) \ + benchmark_width_ + 1, _Any, +, 0, 1, SRC_DEPTH) \ TESTPLANARTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ - benchmark_width_, _Unaligned, +, 1) \ + benchmark_width_, _Unaligned, +, 2, 1, SRC_DEPTH) \ TESTPLANARTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ - benchmark_width_, _Invert, -, 0) \ + benchmark_width_, _Invert, -, 0, 1, SRC_DEPTH) \ TESTPLANARTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ - benchmark_width_, _Opt, +, 0) + benchmark_width_, _Opt, +, 0, 1, SRC_DEPTH) \ + TESTPLANARTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _NullY, +, 0, 0, SRC_DEPTH) +#else +#define TESTPLANARTOP(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, \ + DST_SUBSAMP_X, DST_SUBSAMP_Y, SRC_DEPTH) \ + TESTPLANARTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _NullY, +, 0, 0, SRC_DEPTH) \ + TESTPLANARTOPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0, 1, SRC_DEPTH) +#endif -TESTPLANARTOP(I420, uint8_t, 1, 2, 2, I420, uint8_t, 1, 2, 2) -TESTPLANARTOP(I422, uint8_t, 1, 2, 1, I420, uint8_t, 1, 2, 2) -TESTPLANARTOP(I444, uint8_t, 1, 1, 1, I420, uint8_t, 1, 2, 2) -TESTPLANARTOP(I420, uint8_t, 1, 2, 2, I422, uint8_t, 1, 2, 1) -TESTPLANARTOP(I420, uint8_t, 1, 2, 2, I444, uint8_t, 1, 1, 1) -TESTPLANARTOP(I420, uint8_t, 1, 2, 2, I420Mirror, uint8_t, 1, 2, 2) -TESTPLANARTOP(I422, uint8_t, 1, 2, 1, I422, uint8_t, 1, 2, 1) -TESTPLANARTOP(I444, uint8_t, 1, 1, 1, I444, uint8_t, 1, 1, 1) -TESTPLANARTOP(I010, uint16_t, 2, 2, 2, I010, uint16_t, 2, 2, 2) -TESTPLANARTOP(I010, uint16_t, 2, 2, 2, I420, uint8_t, 1, 2, 2) -TESTPLANARTOP(I420, uint8_t, 1, 2, 2, I010, uint16_t, 2, 2, 2) -TESTPLANARTOP(H010, uint16_t, 2, 2, 2, H010, uint16_t, 2, 2, 2) -TESTPLANARTOP(H010, uint16_t, 2, 2, 2, H420, uint8_t, 1, 2, 2) -TESTPLANARTOP(H420, uint8_t, 1, 2, 2, H010, uint16_t, 2, 2, 2) +TESTPLANARTOP(I420, uint8_t, 1, 2, 2, I420, uint8_t, 1, 2, 2, 8) +TESTPLANARTOP(I422, uint8_t, 1, 2, 1, I420, uint8_t, 1, 2, 2, 8) +TESTPLANARTOP(I444, uint8_t, 1, 1, 1, I420, uint8_t, 1, 2, 2, 8) +TESTPLANARTOP(I420, uint8_t, 1, 2, 2, I422, uint8_t, 1, 2, 1, 8) +TESTPLANARTOP(I420, uint8_t, 1, 2, 2, I444, uint8_t, 1, 1, 1, 8) +TESTPLANARTOP(I420, uint8_t, 1, 2, 2, I420Mirror, uint8_t, 1, 2, 2, 8) +TESTPLANARTOP(I422, uint8_t, 1, 2, 1, I422, uint8_t, 1, 2, 1, 8) +TESTPLANARTOP(I422, uint8_t, 1, 2, 1, I444, uint8_t, 1, 1, 1, 8) +TESTPLANARTOP(I444, uint8_t, 1, 1, 1, I444, uint8_t, 1, 1, 1, 8) +TESTPLANARTOP(I010, uint16_t, 2, 2, 2, I010, uint16_t, 2, 2, 2, 10) +TESTPLANARTOP(I420, uint8_t, 1, 2, 2, I010, uint16_t, 2, 2, 2, 8) +TESTPLANARTOP(I420, uint8_t, 1, 2, 2, I012, uint16_t, 2, 2, 2, 8) +TESTPLANARTOP(H010, uint16_t, 2, 2, 2, H010, uint16_t, 2, 2, 2, 10) +TESTPLANARTOP(H010, uint16_t, 2, 2, 2, H420, uint8_t, 1, 2, 2, 10) +TESTPLANARTOP(H420, uint8_t, 1, 2, 2, H010, uint16_t, 2, 2, 2, 8) +TESTPLANARTOP(H420, uint8_t, 1, 2, 2, H012, uint16_t, 2, 2, 2, 8) +TESTPLANARTOP(J420, uint8_t, 1, 2, 2, I420, uint8_t, 1, 2, 2, 8) +TESTPLANARTOP(I010, uint16_t, 2, 2, 2, I410, uint16_t, 2, 1, 1, 10) +TESTPLANARTOP(I210, uint16_t, 2, 2, 1, I410, uint16_t, 2, 1, 1, 10) +TESTPLANARTOP(I012, uint16_t, 2, 2, 2, I412, uint16_t, 2, 1, 1, 12) +TESTPLANARTOP(I212, uint16_t, 2, 2, 1, I412, uint16_t, 2, 1, 1, 12) +TESTPLANARTOP(I410, uint16_t, 2, 1, 1, I010, uint16_t, 2, 2, 2, 10) +TESTPLANARTOP(I210, uint16_t, 2, 2, 1, I010, uint16_t, 2, 2, 2, 10) +TESTPLANARTOP(I412, uint16_t, 2, 1, 1, I012, uint16_t, 2, 2, 2, 12) +TESTPLANARTOP(I212, uint16_t, 2, 2, 1, I012, uint16_t, 2, 2, 2, 12) +TESTPLANARTOP(I010, uint16_t, 2, 2, 2, I420, uint8_t, 1, 2, 2, 10) +TESTPLANARTOP(I210, uint16_t, 2, 2, 1, I420, uint8_t, 1, 2, 2, 10) +TESTPLANARTOP(I210, uint16_t, 2, 2, 1, I422, uint8_t, 1, 2, 1, 10) +TESTPLANARTOP(I410, uint16_t, 2, 1, 1, I420, uint8_t, 1, 2, 2, 10) +TESTPLANARTOP(I410, uint16_t, 2, 1, 1, I444, uint8_t, 1, 1, 1, 10) +TESTPLANARTOP(I012, uint16_t, 2, 2, 2, I420, uint8_t, 1, 2, 2, 12) +TESTPLANARTOP(I212, uint16_t, 2, 2, 1, I420, uint8_t, 1, 2, 2, 12) +TESTPLANARTOP(I212, uint16_t, 2, 2, 1, I422, uint8_t, 1, 2, 1, 12) +TESTPLANARTOP(I412, uint16_t, 2, 1, 1, I420, uint8_t, 1, 2, 2, 12) +TESTPLANARTOP(I412, uint16_t, 2, 1, 1, I444, uint8_t, 1, 1, 1, 12) // Test Android 420 to I420 #define TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, \ SRC_SUBSAMP_Y, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ W1280, N, NEG, OFF, PN, OFF_U, OFF_V) \ - TEST_F(LibYUVConvertTest, SRC_FMT_PLANAR##To##FMT_PLANAR##_##PN##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ + TEST_F(LibYUVConvertTest, SRC_FMT_PLANAR##To##FMT_PLANAR##To##PN##N) { \ + const int kWidth = W1280; \ const int kHeight = benchmark_height_; \ const int kSizeUV = \ SUBSAMPLE(kWidth, SRC_SUBSAMP_X) * SUBSAMPLE(kHeight, SRC_SUBSAMP_Y); \ - align_buffer_page_end(src_y, kWidth* kHeight + OFF); \ + align_buffer_page_end(src_y, kWidth * kHeight + OFF); \ align_buffer_page_end(src_uv, \ - kSizeUV*((PIXEL_STRIDE == 3) ? 3 : 2) + OFF); \ - align_buffer_page_end(dst_y_c, kWidth* kHeight); \ + kSizeUV * ((PIXEL_STRIDE == 3) ? 3 : 2) + OFF); \ + align_buffer_page_end(dst_y_c, kWidth * kHeight); \ align_buffer_page_end(dst_u_c, SUBSAMPLE(kWidth, SUBSAMP_X) * \ SUBSAMPLE(kHeight, SUBSAMP_Y)); \ align_buffer_page_end(dst_v_c, SUBSAMPLE(kWidth, SUBSAMP_X) * \ SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - align_buffer_page_end(dst_y_opt, kWidth* kHeight); \ + align_buffer_page_end(dst_y_opt, kWidth * kHeight); \ align_buffer_page_end(dst_u_opt, SUBSAMPLE(kWidth, SUBSAMP_X) * \ SUBSAMPLE(kHeight, SUBSAMP_Y)); \ align_buffer_page_end(dst_v_opt, SUBSAMPLE(kWidth, SUBSAMP_X) * \ @@ -199,12 +249,12 @@ TESTPLANARTOP(H420, uint8_t, 1, 2, 2, H010, uint16_t, 2, 2, 2) (fastrand() & 0xff); \ } \ } \ - memset(dst_y_c, 1, kWidth* kHeight); \ + memset(dst_y_c, 1, kWidth * kHeight); \ memset(dst_u_c, 2, \ SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ memset(dst_v_c, 3, \ SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_y_opt, 101, kWidth* kHeight); \ + memset(dst_y_opt, 101, kWidth * kHeight); \ memset(dst_u_opt, 102, \ SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ memset(dst_v_opt, 103, \ @@ -223,41 +273,23 @@ TESTPLANARTOP(H420, uint8_t, 1, 2, 2, H010, uint16_t, 2, 2, 2) dst_y_opt, kWidth, dst_u_opt, SUBSAMPLE(kWidth, SUBSAMP_X), \ dst_v_opt, SUBSAMPLE(kWidth, SUBSAMP_X), kWidth, NEG kHeight); \ } \ - int max_diff = 0; \ for (int i = 0; i < kHeight; ++i) { \ for (int j = 0; j < kWidth; ++j) { \ - int abs_diff = abs(static_cast(dst_y_c[i * kWidth + j]) - \ - static_cast(dst_y_opt[i * kWidth + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ + ASSERT_EQ(dst_y_c[i * kWidth + j], dst_y_opt[i * kWidth + j]); \ } \ } \ - EXPECT_EQ(0, max_diff); \ for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ for (int j = 0; j < SUBSAMPLE(kWidth, SUBSAMP_X); ++j) { \ - int abs_diff = abs( \ - static_cast(dst_u_c[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j]) - \ - static_cast( \ - dst_u_opt[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ + ASSERT_EQ(dst_u_c[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j], \ + dst_u_opt[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j]); \ } \ } \ - EXPECT_LE(max_diff, 3); \ for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ for (int j = 0; j < SUBSAMPLE(kWidth, SUBSAMP_X); ++j) { \ - int abs_diff = abs( \ - static_cast(dst_v_c[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j]) - \ - static_cast( \ - dst_v_opt[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ + ASSERT_EQ(dst_v_c[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j], \ + dst_v_opt[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j]); \ } \ } \ - EXPECT_LE(max_diff, 3); \ free_aligned_buffer_page_end(dst_y_c); \ free_aligned_buffer_page_end(dst_u_c); \ free_aligned_buffer_page_end(dst_v_c); \ @@ -268,114 +300,123 @@ TESTPLANARTOP(H420, uint8_t, 1, 2, 2, H010, uint16_t, 2, 2, 2) free_aligned_buffer_page_end(src_uv); \ } +#if defined(ENABLE_FULL_TESTS) #define TESTAPLANARTOP(SRC_FMT_PLANAR, PN, PIXEL_STRIDE, OFF_U, OFF_V, \ SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, SUBSAMP_X, \ SUBSAMP_Y) \ TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ - FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, benchmark_width_ - 4, \ + FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, benchmark_width_ + 1, \ _Any, +, 0, PN, OFF_U, OFF_V) \ TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, \ - _Unaligned, +, 1, PN, OFF_U, OFF_V) \ + _Unaligned, +, 2, PN, OFF_U, OFF_V) \ TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Invert, \ -, 0, PN, OFF_U, OFF_V) \ TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Opt, +, \ 0, PN, OFF_U, OFF_V) +#else +#define TESTAPLANARTOP(SRC_FMT_PLANAR, PN, PIXEL_STRIDE, OFF_U, OFF_V, \ + SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, SUBSAMP_X, \ + SUBSAMP_Y) \ + TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Opt, +, \ + 0, PN, OFF_U, OFF_V) +#endif TESTAPLANARTOP(Android420, I420, 1, 0, 0, 2, 2, I420, 2, 2) TESTAPLANARTOP(Android420, NV12, 2, 0, 1, 2, 2, I420, 2, 2) TESTAPLANARTOP(Android420, NV21, 2, 1, 0, 2, 2, I420, 2, 2) +#undef TESTAPLANARTOP +#undef TESTAPLANARTOPI // wrapper to keep API the same -int I400ToNV21(const uint8_t* src_y, - int src_stride_y, - const uint8_t* /* src_u */, - int /* src_stride_u */, - const uint8_t* /* src_v */, - int /* src_stride_v */, - uint8_t* dst_y, - int dst_stride_y, - uint8_t* dst_vu, - int dst_stride_vu, - int width, - int height) { +static int I400ToNV21(const uint8_t* src_y, + int src_stride_y, + const uint8_t* /* src_u */, + int /* src_stride_u */, + const uint8_t* /* src_v */, + int /* src_stride_v */, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_vu, + int dst_stride_vu, + int width, + int height) { return I400ToNV21(src_y, src_stride_y, dst_y, dst_stride_y, dst_vu, dst_stride_vu, width, height); } -#define TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ - FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, W1280, N, NEG, OFF) \ +#define TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, \ + DST_SUBSAMP_X, DST_SUBSAMP_Y, W1280, N, NEG, OFF, \ + SRC_DEPTH) \ TEST_F(LibYUVConvertTest, SRC_FMT_PLANAR##To##FMT_PLANAR##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ + static_assert(SRC_BPC == 1 || SRC_BPC == 2, "SRC BPC unsupported"); \ + static_assert(DST_BPC == 1 || DST_BPC == 2, "DST BPC unsupported"); \ + static_assert(SRC_SUBSAMP_X == 1 || SRC_SUBSAMP_X == 2, \ + "SRC_SUBSAMP_X unsupported"); \ + static_assert(SRC_SUBSAMP_Y == 1 || SRC_SUBSAMP_Y == 2, \ + "SRC_SUBSAMP_Y unsupported"); \ + static_assert(DST_SUBSAMP_X == 1 || DST_SUBSAMP_X == 2, \ + "DST_SUBSAMP_X unsupported"); \ + static_assert(DST_SUBSAMP_Y == 1 || DST_SUBSAMP_Y == 2, \ + "DST_SUBSAMP_Y unsupported"); \ + const int kWidth = W1280; \ const int kHeight = benchmark_height_; \ - align_buffer_page_end(src_y, kWidth* kHeight + OFF); \ - align_buffer_page_end(src_u, SUBSAMPLE(kWidth, SRC_SUBSAMP_X) * \ - SUBSAMPLE(kHeight, SRC_SUBSAMP_Y) + \ - OFF); \ - align_buffer_page_end(src_v, SUBSAMPLE(kWidth, SRC_SUBSAMP_X) * \ - SUBSAMPLE(kHeight, SRC_SUBSAMP_Y) + \ - OFF); \ - align_buffer_page_end(dst_y_c, kWidth* kHeight); \ - align_buffer_page_end(dst_uv_c, SUBSAMPLE(kWidth, SUBSAMP_X) * 2 * \ - SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - align_buffer_page_end(dst_y_opt, kWidth* kHeight); \ - align_buffer_page_end(dst_uv_opt, SUBSAMPLE(kWidth, SUBSAMP_X) * 2 * \ - SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - for (int i = 0; i < kHeight; ++i) \ - for (int j = 0; j < kWidth; ++j) \ - src_y[i * kWidth + j + OFF] = (fastrand() & 0xff); \ - for (int i = 0; i < SUBSAMPLE(kHeight, SRC_SUBSAMP_Y); ++i) { \ - for (int j = 0; j < SUBSAMPLE(kWidth, SRC_SUBSAMP_X); ++j) { \ - src_u[(i * SUBSAMPLE(kWidth, SRC_SUBSAMP_X)) + j + OFF] = \ - (fastrand() & 0xff); \ - src_v[(i * SUBSAMPLE(kWidth, SRC_SUBSAMP_X)) + j + OFF] = \ - (fastrand() & 0xff); \ - } \ + const int kSrcHalfWidth = SUBSAMPLE(kWidth, SRC_SUBSAMP_X); \ + const int kSrcHalfHeight = SUBSAMPLE(kHeight, SRC_SUBSAMP_Y); \ + const int kDstHalfWidth = SUBSAMPLE(kWidth, DST_SUBSAMP_X); \ + const int kDstHalfHeight = SUBSAMPLE(kHeight, DST_SUBSAMP_Y); \ + align_buffer_page_end(src_y, kWidth * kHeight * SRC_BPC + OFF); \ + align_buffer_page_end(src_u, \ + kSrcHalfWidth * kSrcHalfHeight * SRC_BPC + OFF); \ + align_buffer_page_end(src_v, \ + kSrcHalfWidth * kSrcHalfHeight * SRC_BPC + OFF); \ + align_buffer_page_end(dst_y_c, kWidth * kHeight * DST_BPC); \ + align_buffer_page_end(dst_uv_c, \ + kDstHalfWidth * kDstHalfHeight * DST_BPC * 2); \ + align_buffer_page_end(dst_y_opt, kWidth * kHeight * DST_BPC); \ + align_buffer_page_end(dst_uv_opt, \ + kDstHalfWidth * kDstHalfHeight * DST_BPC * 2); \ + MemRandomize(src_y + OFF, kWidth * kHeight * SRC_BPC); \ + MemRandomize(src_u + OFF, kSrcHalfWidth * kSrcHalfHeight * SRC_BPC); \ + MemRandomize(src_v + OFF, kSrcHalfWidth * kSrcHalfHeight * SRC_BPC); \ + SRC_T* src_y_p = reinterpret_cast(src_y + OFF); \ + SRC_T* src_u_p = reinterpret_cast(src_u + OFF); \ + SRC_T* src_v_p = reinterpret_cast(src_v + OFF); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + src_y_p[i] = src_y_p[i] & ((1 << SRC_DEPTH) - 1); \ } \ - memset(dst_y_c, 1, kWidth* kHeight); \ - memset(dst_uv_c, 2, \ - SUBSAMPLE(kWidth, SUBSAMP_X) * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_y_opt, 101, kWidth* kHeight); \ - memset(dst_uv_opt, 102, \ - SUBSAMPLE(kWidth, SUBSAMP_X) * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + for (int i = 0; i < kSrcHalfWidth * kSrcHalfHeight; ++i) { \ + src_u_p[i] = src_u_p[i] & ((1 << SRC_DEPTH) - 1); \ + src_v_p[i] = src_v_p[i] & ((1 << SRC_DEPTH) - 1); \ + } \ + memset(dst_y_c, 1, kWidth * kHeight * DST_BPC); \ + memset(dst_uv_c, 2, kDstHalfWidth * kDstHalfHeight * DST_BPC * 2); \ + memset(dst_y_opt, 101, kWidth * kHeight * DST_BPC); \ + memset(dst_uv_opt, 102, kDstHalfWidth * kDstHalfHeight * DST_BPC * 2); \ MaskCpuFlags(disable_cpu_flags_); \ - SRC_FMT_PLANAR##To##FMT_PLANAR( \ - src_y + OFF, kWidth, src_u + OFF, SUBSAMPLE(kWidth, SRC_SUBSAMP_X), \ - src_v + OFF, SUBSAMPLE(kWidth, SRC_SUBSAMP_X), dst_y_c, kWidth, \ - dst_uv_c, SUBSAMPLE(kWidth, SUBSAMP_X) * 2, kWidth, NEG kHeight); \ + SRC_FMT_PLANAR##To##FMT_PLANAR(src_y_p, kWidth, src_u_p, kSrcHalfWidth, \ + src_v_p, kSrcHalfWidth, \ + reinterpret_cast(dst_y_c), kWidth, \ + reinterpret_cast(dst_uv_c), \ + kDstHalfWidth * 2, kWidth, NEG kHeight); \ MaskCpuFlags(benchmark_cpu_info_); \ for (int i = 0; i < benchmark_iterations_; ++i) { \ SRC_FMT_PLANAR##To##FMT_PLANAR( \ - src_y + OFF, kWidth, src_u + OFF, SUBSAMPLE(kWidth, SRC_SUBSAMP_X), \ - src_v + OFF, SUBSAMPLE(kWidth, SRC_SUBSAMP_X), dst_y_opt, kWidth, \ - dst_uv_opt, SUBSAMPLE(kWidth, SUBSAMP_X) * 2, kWidth, NEG kHeight); \ + src_y_p, kWidth, src_u_p, kSrcHalfWidth, src_v_p, kSrcHalfWidth, \ + reinterpret_cast(dst_y_opt), kWidth, \ + reinterpret_cast(dst_uv_opt), kDstHalfWidth * 2, kWidth, \ + NEG kHeight); \ } \ - int max_diff = 0; \ - for (int i = 0; i < kHeight; ++i) { \ - for (int j = 0; j < kWidth; ++j) { \ - int abs_diff = abs(static_cast(dst_y_c[i * kWidth + j]) - \ - static_cast(dst_y_opt[i * kWidth + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ + for (int i = 0; i < kHeight * kWidth * DST_BPC; ++i) { \ + ASSERT_EQ(dst_y_c[i], dst_y_opt[i]); \ } \ - EXPECT_LE(max_diff, 1); \ - for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ - for (int j = 0; j < SUBSAMPLE(kWidth, SUBSAMP_X) * 2; ++j) { \ - int abs_diff = \ - abs(static_cast( \ - dst_uv_c[i * SUBSAMPLE(kWidth, SUBSAMP_X) * 2 + j]) - \ - static_cast( \ - dst_uv_opt[i * SUBSAMPLE(kWidth, SUBSAMP_X) * 2 + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ + for (int i = 0; i < kDstHalfWidth * kDstHalfHeight * DST_BPC * 2; ++i) { \ + ASSERT_EQ(dst_uv_c[i], dst_uv_opt[i]); \ } \ - EXPECT_LE(max_diff, 1); \ free_aligned_buffer_page_end(dst_y_c); \ free_aligned_buffer_page_end(dst_uv_c); \ free_aligned_buffer_page_end(dst_y_opt); \ @@ -385,93 +426,315 @@ int I400ToNV21(const uint8_t* src_y, free_aligned_buffer_page_end(src_v); \ } -#define TESTPLANARTOBP(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ - FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ - TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_ - 4, _Any, +, 0) \ - TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Unaligned, +, 1) \ - TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Invert, -, 0) \ - TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Opt, +, 0) +#if defined(ENABLE_FULL_TESTS) +#define TESTPLANARTOBP(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, \ + DST_SUBSAMP_X, DST_SUBSAMP_Y, SRC_DEPTH) \ + TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, \ + DST_SUBSAMP_Y, benchmark_width_ + 1, _Any, +, 0, SRC_DEPTH) \ + TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, \ + DST_SUBSAMP_Y, benchmark_width_, _Unaligned, +, 2, \ + SRC_DEPTH) \ + TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, \ + DST_SUBSAMP_Y, benchmark_width_, _Invert, -, 0, SRC_DEPTH) \ + TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, \ + DST_SUBSAMP_Y, benchmark_width_, _Opt, +, 0, SRC_DEPTH) +#else +#define TESTPLANARTOBP(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, \ + DST_SUBSAMP_X, DST_SUBSAMP_Y, SRC_DEPTH) \ + TESTPLANARTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, \ + DST_SUBSAMP_Y, benchmark_width_, _Opt, +, 0, SRC_DEPTH) +#endif -TESTPLANARTOBP(I420, 2, 2, NV12, 2, 2) -TESTPLANARTOBP(I420, 2, 2, NV21, 2, 2) -TESTPLANARTOBP(I422, 2, 1, NV21, 2, 2) -TESTPLANARTOBP(I444, 1, 1, NV21, 2, 2) -TESTPLANARTOBP(I400, 2, 2, NV21, 2, 2) +TESTPLANARTOBP(I420, uint8_t, 1, 2, 2, NV12, uint8_t, 1, 2, 2, 8) +TESTPLANARTOBP(I420, uint8_t, 1, 2, 2, NV21, uint8_t, 1, 2, 2, 8) +TESTPLANARTOBP(I422, uint8_t, 1, 2, 1, NV21, uint8_t, 1, 2, 2, 8) +TESTPLANARTOBP(I444, uint8_t, 1, 1, 1, NV12, uint8_t, 1, 2, 2, 8) +TESTPLANARTOBP(I444, uint8_t, 1, 1, 1, NV21, uint8_t, 1, 2, 2, 8) +TESTPLANARTOBP(I400, uint8_t, 1, 2, 2, NV21, uint8_t, 1, 2, 2, 8) +TESTPLANARTOBP(I010, uint16_t, 2, 2, 2, NV12, uint8_t, 1, 2, 2, 8) +TESTPLANARTOBP(I010, uint16_t, 2, 2, 2, P010, uint16_t, 2, 2, 2, 10) +TESTPLANARTOBP(I210, uint16_t, 2, 2, 1, P210, uint16_t, 2, 2, 1, 10) +TESTPLANARTOBP(I012, uint16_t, 2, 2, 2, P012, uint16_t, 2, 2, 2, 12) +TESTPLANARTOBP(I212, uint16_t, 2, 2, 1, P212, uint16_t, 2, 2, 1, 12) +TESTPLANARTOBP(I420, uint8_t, 1, 2, 2, P010, uint16_t, 2, 2, 2, 8) +TESTPLANARTOBP(I422, uint8_t, 1, 2, 1, P210, uint16_t, 2, 2, 1, 8) +TESTPLANARTOBP(I444, uint8_t, 1, 1, 1, P410, uint16_t, 2, 1, 1, 8) +TESTPLANARTOBP(I420, uint8_t, 1, 2, 2, P210, uint16_t, 2, 2, 1, 8) +TESTPLANARTOBP(I420, uint8_t, 1, 2, 2, P410, uint16_t, 2, 1, 1, 8) +TESTPLANARTOBP(I410, uint16_t, 2, 1, 1, P410, uint16_t, 2, 1, 1, 10) +TESTPLANARTOBP(I412, uint16_t, 2, 1, 1, P412, uint16_t, 2, 1, 1, 12) -#define TESTBIPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ - FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, W1280, N, NEG, \ - OFF, DOY) \ +#define TESTCONVERTFROMI420I(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, W1280, N, \ + NEG) \ + TEST_F(LibYUVConvertTest, ConvertFromI420_##FMT##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kHalfWidth = SUBSAMPLE(kWidth, 2); \ + const int kHalfHeight = SUBSAMPLE(kHeight, 2); \ + const int kUvStride = (SUBSAMP_X == 1) ? kWidth * 2 : ((kWidth + 1) & ~1); \ + const int kUvHeight = SUBSAMPLE(kHeight, SUBSAMP_Y); \ + const int kSamplePixels = kWidth * kHeight + kUvStride * kUvHeight; \ + align_buffer_page_end(src_y, kWidth * kHeight); \ + align_buffer_page_end(src_u, kHalfWidth * kHalfHeight); \ + align_buffer_page_end(src_v, kHalfWidth * kHalfHeight); \ + align_buffer_page_end(dst, kSamplePixels * BPC); \ + align_buffer_page_end(ref, kSamplePixels * BPC); \ + MemRandomize(src_y, kWidth * kHeight); \ + MemRandomize(src_u, kHalfWidth * kHalfHeight); \ + MemRandomize(src_v, kHalfWidth * kHalfHeight); \ + memset(dst, 0, kSamplePixels * BPC); \ + memset(ref, 1, kSamplePixels * BPC); \ + TYPE* dst_p = reinterpret_cast(dst); \ + TYPE* ref_p = reinterpret_cast(ref); \ + EXPECT_EQ(0, \ + I420To##FMT(src_y, kWidth, src_u, kHalfWidth, src_v, kHalfWidth, \ + ref_p, kWidth, ref_p + kWidth * kHeight, kUvStride, \ + kWidth, NEG kHeight)); \ + EXPECT_EQ(0, ConvertFromI420(src_y, kWidth, src_u, kHalfWidth, src_v, \ + kHalfWidth, dst, 0, kWidth, NEG kHeight, \ + FOURCC_##FMT)); \ + for (int i = 0; i < kSamplePixels; ++i) { \ + ASSERT_EQ(dst_p[i], ref_p[i]); \ + } \ + if (BPC == 2) { \ + EXPECT_EQ(-1, ConvertFromI420(src_y, kWidth, src_u, kHalfWidth, src_v, \ + kHalfWidth, dst, 1, kWidth, kHeight, \ + FOURCC_##FMT)); \ + } \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_u); \ + free_aligned_buffer_page_end(src_v); \ + free_aligned_buffer_page_end(dst); \ + free_aligned_buffer_page_end(ref); \ + } + +#define TESTCONVERTTOI420I(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, W1280, N, \ + NEG) \ + TEST_F(LibYUVConvertTest, ConvertToI420_##FMT##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kHalfWidth = SUBSAMPLE(kWidth, 2); \ + const int kHalfHeight = SUBSAMPLE(kHeight, 2); \ + const int kUvStride = (SUBSAMP_X == 1) ? kWidth * 2 : ((kWidth + 1) & ~1); \ + const int kUvHeight = SUBSAMPLE(kHeight, SUBSAMP_Y); \ + const int kYPixels = kWidth * kHeight; \ + const int kUvPixels = kUvStride * kUvHeight; \ + align_buffer_page_end(src, (kYPixels + kUvPixels) * BPC); \ + align_buffer_page_end(dst_y, kWidth * kHeight); \ + align_buffer_page_end(dst_u, kHalfWidth * kHalfHeight); \ + align_buffer_page_end(dst_v, kHalfWidth * kHalfHeight); \ + align_buffer_page_end(ref_y, kWidth * kHeight); \ + align_buffer_page_end(ref_u, kHalfWidth * kHalfHeight); \ + align_buffer_page_end(ref_v, kHalfWidth * kHalfHeight); \ + TYPE* src_p = reinterpret_cast(src); \ + MemRandomize(src, (kYPixels + kUvPixels) * BPC); \ + if (BPC == 2) { \ + for (int i = 0; i < kYPixels + kUvPixels; ++i) { \ + src_p[i] = static_cast(src_p[i] & 0xffc0); \ + } \ + } \ + memset(dst_y, 1, kWidth * kHeight); \ + memset(dst_u, 2, kHalfWidth * kHalfHeight); \ + memset(dst_v, 3, kHalfWidth * kHalfHeight); \ + memset(ref_y, 4, kWidth * kHeight); \ + memset(ref_u, 5, kHalfWidth * kHalfHeight); \ + memset(ref_v, 6, kHalfWidth * kHalfHeight); \ + EXPECT_EQ(0, FMT##ToI420(src_p, kWidth, src_p + kYPixels, kUvStride, \ + ref_y, kWidth, ref_u, kHalfWidth, ref_v, \ + kHalfWidth, kWidth, NEG kHeight)); \ + EXPECT_EQ(0, ConvertToI420(src, 0, dst_y, kWidth, dst_u, kHalfWidth, \ + dst_v, kHalfWidth, 0, 0, kWidth, NEG kHeight, \ + kWidth, kHeight, kRotate0, FOURCC_##FMT)); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + ASSERT_EQ(dst_y[i], ref_y[i]); \ + } \ + for (int i = 0; i < kHalfWidth * kHalfHeight; ++i) { \ + ASSERT_EQ(dst_u[i], ref_u[i]); \ + ASSERT_EQ(dst_v[i], ref_v[i]); \ + } \ + free_aligned_buffer_page_end(src); \ + free_aligned_buffer_page_end(dst_y); \ + free_aligned_buffer_page_end(dst_u); \ + free_aligned_buffer_page_end(dst_v); \ + free_aligned_buffer_page_end(ref_y); \ + free_aligned_buffer_page_end(ref_u); \ + free_aligned_buffer_page_end(ref_v); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTCONVERTFROMI420(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y) \ + TESTCONVERTFROMI420I(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_ + 1, _Any, +) \ + TESTCONVERTFROMI420I(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, \ + _Invert, -) \ + TESTCONVERTFROMI420I(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, \ + _Opt, +) +#define TESTCONVERTTOI420(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y) \ + TESTCONVERTTOI420I(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_ + 1, _Any, +) \ + TESTCONVERTTOI420I(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, \ + _Invert, -) \ + TESTCONVERTTOI420I(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, \ + _Opt, +) +#else +#define TESTCONVERTFROMI420(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y) \ + TESTCONVERTFROMI420I(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, \ + _Opt, +) +#define TESTCONVERTTOI420(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y) \ + TESTCONVERTTOI420I(FMT, TYPE, BPC, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, \ + _Opt, +) +#endif + +TESTCONVERTFROMI420(P010, uint16_t, 2, 2, 2) +TESTCONVERTFROMI420(P210, uint16_t, 2, 2, 1) +TESTCONVERTFROMI420(P410, uint16_t, 2, 1, 1) +TESTCONVERTTOI420(P010, uint16_t, 2, 2, 2) +TESTCONVERTTOI420(P210, uint16_t, 2, 2, 1) +TESTCONVERTTOI420(P410, uint16_t, 2, 1, 1) + +#define TESTCONVERTTOI420SMOKE(FMT, BPC, SUBSAMP_X, SUBSAMP_Y) \ + TEST_F(LibYUVConvertTest, ConvertToI420_##FMT) { \ + const int kWidth = 64; \ + const int kHeight = 48; \ + const int kUvStride = (SUBSAMP_X == 1) ? kWidth * 2 : ((kWidth + 1) & ~1); \ + const int kUvHeight = SUBSAMPLE(kHeight, SUBSAMP_Y); \ + const int kSampleSize = (kWidth * kHeight + kUvStride * kUvHeight) * BPC; \ + align_buffer_page_end(src, kSampleSize); \ + align_buffer_page_end(dst_y, kWidth * kHeight); \ + align_buffer_page_end(dst_u, (kWidth / 2) * (kHeight / 2)); \ + align_buffer_page_end(dst_v, (kWidth / 2) * (kHeight / 2)); \ + MemRandomize(src, kSampleSize); \ + memset(dst_y, 0, kWidth * kHeight); \ + memset(dst_u, 0, (kWidth / 2) * (kHeight / 2)); \ + memset(dst_v, 0, (kWidth / 2) * (kHeight / 2)); \ + EXPECT_EQ( \ + 0, ConvertToI420(src, kSampleSize, dst_y, kWidth, dst_u, kWidth / 2, \ + dst_v, kWidth / 2, 0, 0, kWidth, kHeight, kWidth, \ + kHeight, kRotate0, FOURCC_##FMT)); \ + free_aligned_buffer_page_end(src); \ + free_aligned_buffer_page_end(dst_y); \ + free_aligned_buffer_page_end(dst_u); \ + free_aligned_buffer_page_end(dst_v); \ + } + +#define TESTCONVERTFROMI420SMOKE(FMT, BPC, SUBSAMP_X, SUBSAMP_Y) \ + TEST_F(LibYUVConvertTest, ConvertFromI420_##FMT) { \ + const int kWidth = 64; \ + const int kHeight = 48; \ + const int kUvStride = (SUBSAMP_X == 1) ? kWidth * 2 : ((kWidth + 1) & ~1); \ + const int kUvHeight = SUBSAMPLE(kHeight, SUBSAMP_Y); \ + const int kDstSize = (kWidth * kHeight + kUvStride * kUvHeight) * BPC; \ + align_buffer_page_end(src_y, kWidth * kHeight); \ + align_buffer_page_end(src_u, (kWidth / 2) * (kHeight / 2)); \ + align_buffer_page_end(src_v, (kWidth / 2) * (kHeight / 2)); \ + align_buffer_page_end(dst, kDstSize); \ + MemRandomize(src_y, kWidth * kHeight); \ + MemRandomize(src_u, (kWidth / 2) * (kHeight / 2)); \ + MemRandomize(src_v, (kWidth / 2) * (kHeight / 2)); \ + memset(dst, 0, kDstSize); \ + EXPECT_EQ(0, ConvertFromI420(src_y, kWidth, src_u, kWidth / 2, src_v, \ + kWidth / 2, dst, kWidth * BPC, kWidth, \ + kHeight, FOURCC_##FMT)); \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_u); \ + free_aligned_buffer_page_end(src_v); \ + free_aligned_buffer_page_end(dst); \ + } + +TESTCONVERTTOI420SMOKE(NV16, 1, 2, 1) +TESTCONVERTTOI420SMOKE(NV24, 1, 1, 1) +TESTCONVERTFROMI420SMOKE(NV16, 1, 2, 1) +TESTCONVERTFROMI420SMOKE(NV24, 1, 1, 1) + +#define TESTBPTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, \ + DST_SUBSAMP_Y, W1280, N, NEG, OFF, DOY, SRC_DEPTH, \ + TILE_WIDTH, TILE_HEIGHT) \ TEST_F(LibYUVConvertTest, SRC_FMT_PLANAR##To##FMT_PLANAR##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ + static_assert(DST_BPC == 1 || DST_BPC == 2, "DST BPC unsupported"); \ + static_assert(SRC_SUBSAMP_X == 1 || SRC_SUBSAMP_X == 2, \ + "SRC_SUBSAMP_X unsupported"); \ + static_assert(SRC_SUBSAMP_Y == 1 || SRC_SUBSAMP_Y == 2, \ + "SRC_SUBSAMP_Y unsupported"); \ + static_assert(DST_SUBSAMP_X == 1 || DST_SUBSAMP_X == 2, \ + "DST_SUBSAMP_X unsupported"); \ + static_assert(DST_SUBSAMP_Y == 1 || DST_SUBSAMP_Y == 2, \ + "DST_SUBSAMP_Y unsupported"); \ + const int kWidth = W1280; \ const int kHeight = benchmark_height_; \ - align_buffer_page_end(src_y, kWidth* kHeight + OFF); \ - align_buffer_page_end(src_uv, 2 * SUBSAMPLE(kWidth, SRC_SUBSAMP_X) * \ - SUBSAMPLE(kHeight, SRC_SUBSAMP_Y) + \ - OFF); \ - align_buffer_page_end(dst_y_c, kWidth* kHeight); \ - align_buffer_page_end(dst_uv_c, 2 * SUBSAMPLE(kWidth, SUBSAMP_X) * \ - SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - align_buffer_page_end(dst_y_opt, kWidth* kHeight); \ - align_buffer_page_end(dst_uv_opt, 2 * SUBSAMPLE(kWidth, SUBSAMP_X) * \ - SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - for (int i = 0; i < kHeight; ++i) \ - for (int j = 0; j < kWidth; ++j) \ - src_y[i * kWidth + j + OFF] = (fastrand() & 0xff); \ - for (int i = 0; i < SUBSAMPLE(kHeight, SRC_SUBSAMP_Y); ++i) { \ - for (int j = 0; j < 2 * SUBSAMPLE(kWidth, SRC_SUBSAMP_X); ++j) { \ - src_uv[(i * 2 * SUBSAMPLE(kWidth, SRC_SUBSAMP_X)) + j + OFF] = \ - (fastrand() & 0xff); \ - } \ + const int kSrcHalfWidth = SUBSAMPLE(kWidth, SRC_SUBSAMP_X); \ + const int kDstHalfWidth = SUBSAMPLE(kWidth, DST_SUBSAMP_X); \ + const int kDstHalfHeight = SUBSAMPLE(kHeight, DST_SUBSAMP_Y); \ + const int kPaddedWidth = (kWidth + (TILE_WIDTH - 1)) & ~(TILE_WIDTH - 1); \ + const int kPaddedHeight = \ + (kHeight + (TILE_HEIGHT - 1)) & ~(TILE_HEIGHT - 1); \ + const int kSrcHalfPaddedWidth = SUBSAMPLE(kPaddedWidth, SRC_SUBSAMP_X); \ + const int kSrcHalfPaddedHeight = SUBSAMPLE(kPaddedHeight, SRC_SUBSAMP_Y); \ + align_buffer_page_end(src_y, \ + kPaddedWidth * kPaddedHeight * SRC_BPC + OFF); \ + align_buffer_page_end( \ + src_uv, \ + 2 * kSrcHalfPaddedWidth * kSrcHalfPaddedHeight * SRC_BPC + OFF); \ + align_buffer_page_end(dst_y_c, kWidth * kHeight * DST_BPC); \ + align_buffer_page_end(dst_uv_c, \ + 2 * kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + align_buffer_page_end(dst_y_opt, kWidth * kHeight * DST_BPC); \ + align_buffer_page_end(dst_uv_opt, \ + 2 * kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + SRC_T* src_y_p = reinterpret_cast(src_y + OFF); \ + SRC_T* src_uv_p = reinterpret_cast(src_uv + OFF); \ + for (int i = 0; \ + i < kPaddedWidth * kPaddedHeight * SRC_BPC / (int)sizeof(SRC_T); \ + ++i) { \ + src_y_p[i] = \ + (fastrand() & (((SRC_T)(-1)) << ((8 * SRC_BPC) - SRC_DEPTH))); \ } \ - memset(dst_y_c, 1, kWidth* kHeight); \ - memset(dst_uv_c, 2, \ - 2 * SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_y_opt, 101, kWidth* kHeight); \ - memset(dst_uv_opt, 102, \ - 2 * SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + for (int i = 0; i < kSrcHalfPaddedWidth * kSrcHalfPaddedHeight * 2 * \ + SRC_BPC / (int)sizeof(SRC_T); \ + ++i) { \ + src_uv_p[i] = \ + (fastrand() & (((SRC_T)(-1)) << ((8 * SRC_BPC) - SRC_DEPTH))); \ + } \ + memset(dst_y_c, 1, kWidth * kHeight * DST_BPC); \ + memset(dst_uv_c, 2, 2 * kDstHalfWidth * kDstHalfHeight * DST_BPC); \ + memset(dst_y_opt, 101, kWidth * kHeight * DST_BPC); \ + memset(dst_uv_opt, 102, 2 * kDstHalfWidth * kDstHalfHeight * DST_BPC); \ MaskCpuFlags(disable_cpu_flags_); \ SRC_FMT_PLANAR##To##FMT_PLANAR( \ - src_y + OFF, kWidth, src_uv + OFF, \ - 2 * SUBSAMPLE(kWidth, SRC_SUBSAMP_X), DOY ? dst_y_c : NULL, kWidth, \ - dst_uv_c, 2 * SUBSAMPLE(kWidth, SUBSAMP_X), kWidth, NEG kHeight); \ + src_y_p, kWidth * SRC_BPC / (int)sizeof(SRC_T), src_uv_p, \ + 2 * kSrcHalfWidth * SRC_BPC / (int)sizeof(SRC_T), \ + DOY ? reinterpret_cast(dst_y_c) : NULL, kWidth, \ + reinterpret_cast(dst_uv_c), 2 * kDstHalfWidth, kWidth, \ + NEG kHeight); \ MaskCpuFlags(benchmark_cpu_info_); \ for (int i = 0; i < benchmark_iterations_; ++i) { \ SRC_FMT_PLANAR##To##FMT_PLANAR( \ - src_y + OFF, kWidth, src_uv + OFF, \ - 2 * SUBSAMPLE(kWidth, SRC_SUBSAMP_X), DOY ? dst_y_opt : NULL, \ - kWidth, dst_uv_opt, 2 * SUBSAMPLE(kWidth, SUBSAMP_X), kWidth, \ + src_y_p, kWidth * SRC_BPC / (int)sizeof(SRC_T), src_uv_p, \ + 2 * kSrcHalfWidth * SRC_BPC / (int)sizeof(SRC_T), \ + DOY ? reinterpret_cast(dst_y_opt) : NULL, kWidth, \ + reinterpret_cast(dst_uv_opt), 2 * kDstHalfWidth, kWidth, \ NEG kHeight); \ } \ - int max_diff = 0; \ if (DOY) { \ for (int i = 0; i < kHeight; ++i) { \ for (int j = 0; j < kWidth; ++j) { \ - int abs_diff = abs(static_cast(dst_y_c[i * kWidth + j]) - \ - static_cast(dst_y_opt[i * kWidth + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ - } \ - EXPECT_LE(max_diff, 1); \ - } \ - for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ - for (int j = 0; j < 2 * SUBSAMPLE(kWidth, SUBSAMP_X); ++j) { \ - int abs_diff = \ - abs(static_cast( \ - dst_uv_c[i * 2 * SUBSAMPLE(kWidth, SUBSAMP_X) + j]) - \ - static_cast( \ - dst_uv_opt[i * 2 * SUBSAMPLE(kWidth, SUBSAMP_X) + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ + ASSERT_EQ(dst_y_c[i * kWidth + j], dst_y_opt[i * kWidth + j]); \ } \ } \ } \ - EXPECT_LE(max_diff, 1); \ + for (int i = 0; i < kDstHalfHeight; ++i) { \ + for (int j = 0; j < 2 * kDstHalfWidth; ++j) { \ + ASSERT_EQ(dst_uv_c[i * 2 * kDstHalfWidth + j], \ + dst_uv_opt[i * 2 * kDstHalfWidth + j]); \ + } \ + } \ free_aligned_buffer_page_end(dst_y_c); \ free_aligned_buffer_page_end(dst_uv_c); \ free_aligned_buffer_page_end(dst_y_opt); \ @@ -480,475 +743,72 @@ TESTPLANARTOBP(I400, 2, 2, NV21, 2, 2) free_aligned_buffer_page_end(src_uv); \ } -#define TESTBIPLANARTOBP(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ - FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ - TESTBIPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_ - 4, _Any, +, 0, 1) \ - TESTBIPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Unaligned, +, 1, \ - 1) \ - TESTBIPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Invert, -, 0, 1) \ - TESTBIPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Opt, +, 0, 1) \ - TESTBIPLANARTOBPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _NullY, +, 0, 0) - -TESTBIPLANARTOBP(NV21, 2, 2, NV12, 2, 2) - -#define TESTBIPLANARTOPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ - FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, W1280, N, NEG, OFF, \ - DOY) \ - TEST_F(LibYUVConvertTest, SRC_FMT_PLANAR##To##FMT_PLANAR##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = benchmark_height_; \ - align_buffer_page_end(src_y, kWidth* kHeight + OFF); \ - align_buffer_page_end(src_uv, 2 * SUBSAMPLE(kWidth, SRC_SUBSAMP_X) * \ - SUBSAMPLE(kHeight, SRC_SUBSAMP_Y) + \ - OFF); \ - align_buffer_page_end(dst_y_c, kWidth* kHeight); \ - align_buffer_page_end(dst_u_c, SUBSAMPLE(kWidth, SUBSAMP_X) * \ - SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - align_buffer_page_end(dst_v_c, SUBSAMPLE(kWidth, SUBSAMP_X) * \ - SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - align_buffer_page_end(dst_y_opt, kWidth* kHeight); \ - align_buffer_page_end(dst_u_opt, SUBSAMPLE(kWidth, SUBSAMP_X) * \ - SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - align_buffer_page_end(dst_v_opt, SUBSAMPLE(kWidth, SUBSAMP_X) * \ - SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - for (int i = 0; i < kHeight; ++i) \ - for (int j = 0; j < kWidth; ++j) \ - src_y[i * kWidth + j + OFF] = (fastrand() & 0xff); \ - for (int i = 0; i < SUBSAMPLE(kHeight, SRC_SUBSAMP_Y); ++i) { \ - for (int j = 0; j < 2 * SUBSAMPLE(kWidth, SRC_SUBSAMP_X); ++j) { \ - src_uv[(i * 2 * SUBSAMPLE(kWidth, SRC_SUBSAMP_X)) + j + OFF] = \ - (fastrand() & 0xff); \ - } \ - } \ - memset(dst_y_c, 1, kWidth* kHeight); \ - memset(dst_u_c, 2, \ - SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_v_c, 3, \ - SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_y_opt, 101, kWidth* kHeight); \ - memset(dst_u_opt, 102, \ - SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_v_opt, 103, \ - SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - MaskCpuFlags(disable_cpu_flags_); \ - SRC_FMT_PLANAR##To##FMT_PLANAR( \ - src_y + OFF, kWidth, src_uv + OFF, \ - 2 * SUBSAMPLE(kWidth, SRC_SUBSAMP_X), DOY ? dst_y_c : NULL, kWidth, \ - dst_u_c, SUBSAMPLE(kWidth, SUBSAMP_X), dst_v_c, \ - SUBSAMPLE(kWidth, SUBSAMP_X), kWidth, NEG kHeight); \ - MaskCpuFlags(benchmark_cpu_info_); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - SRC_FMT_PLANAR##To##FMT_PLANAR( \ - src_y + OFF, kWidth, src_uv + OFF, \ - 2 * SUBSAMPLE(kWidth, SRC_SUBSAMP_X), DOY ? dst_y_opt : NULL, \ - kWidth, dst_u_opt, SUBSAMPLE(kWidth, SUBSAMP_X), dst_v_opt, \ - SUBSAMPLE(kWidth, SUBSAMP_X), kWidth, NEG kHeight); \ - } \ - int max_diff = 0; \ - if (DOY) { \ - for (int i = 0; i < kHeight; ++i) { \ - for (int j = 0; j < kWidth; ++j) { \ - int abs_diff = abs(static_cast(dst_y_c[i * kWidth + j]) - \ - static_cast(dst_y_opt[i * kWidth + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ - } \ - EXPECT_LE(max_diff, 1); \ - } \ - for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ - for (int j = 0; j < SUBSAMPLE(kWidth, SUBSAMP_X); ++j) { \ - int abs_diff = abs( \ - static_cast(dst_u_c[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j]) - \ - static_cast( \ - dst_u_opt[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ - } \ - EXPECT_LE(max_diff, 1); \ - for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ - for (int j = 0; j < SUBSAMPLE(kWidth, SUBSAMP_X); ++j) { \ - int abs_diff = abs( \ - static_cast(dst_v_c[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j]) - \ - static_cast( \ - dst_v_opt[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ - } \ - EXPECT_LE(max_diff, 1); \ - free_aligned_buffer_page_end(dst_y_c); \ - free_aligned_buffer_page_end(dst_u_c); \ - free_aligned_buffer_page_end(dst_v_c); \ - free_aligned_buffer_page_end(dst_y_opt); \ - free_aligned_buffer_page_end(dst_u_opt); \ - free_aligned_buffer_page_end(dst_v_opt); \ - free_aligned_buffer_page_end(src_y); \ - free_aligned_buffer_page_end(src_uv); \ - } - -#define TESTBIPLANARTOP(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ - FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ - TESTBIPLANARTOPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_ - 4, _Any, +, 0, 1) \ - TESTBIPLANARTOPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Unaligned, +, 1, \ - 1) \ - TESTBIPLANARTOPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Invert, -, 0, 1) \ - TESTBIPLANARTOPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Opt, +, 0, 1) \ - TESTBIPLANARTOPI(SRC_FMT_PLANAR, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, \ - SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _NullY, +, 0, 0) - -TESTBIPLANARTOP(NV12, 2, 2, I420, 2, 2) -TESTBIPLANARTOP(NV21, 2, 2, I420, 2, 2) - -#define ALIGNINT(V, ALIGN) (((V) + (ALIGN)-1) / (ALIGN) * (ALIGN)) - -#define TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, W1280, N, NEG, OFF) \ - TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ - const int kStrideB = ALIGNINT(kWidth * BPP_B, ALIGN); \ - const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ - const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ - align_buffer_page_end(src_y, kWidth* kHeight + OFF); \ - align_buffer_page_end(src_u, kSizeUV + OFF); \ - align_buffer_page_end(src_v, kSizeUV + OFF); \ - align_buffer_page_end(dst_argb_c, kStrideB* kHeight + OFF); \ - align_buffer_page_end(dst_argb_opt, kStrideB* kHeight + OFF); \ - for (int i = 0; i < kWidth * kHeight; ++i) { \ - src_y[i + OFF] = (fastrand() & 0xff); \ - } \ - for (int i = 0; i < kSizeUV; ++i) { \ - src_u[i + OFF] = (fastrand() & 0xff); \ - src_v[i + OFF] = (fastrand() & 0xff); \ - } \ - memset(dst_argb_c + OFF, 1, kStrideB * kHeight); \ - memset(dst_argb_opt + OFF, 101, kStrideB * kHeight); \ - MaskCpuFlags(disable_cpu_flags_); \ - double time0 = get_time(); \ - FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ - src_v + OFF, kStrideUV, dst_argb_c + OFF, kStrideB, \ - kWidth, NEG kHeight); \ - double time1 = get_time(); \ - MaskCpuFlags(benchmark_cpu_info_); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ - src_v + OFF, kStrideUV, dst_argb_opt + OFF, \ - kStrideB, kWidth, NEG kHeight); \ - } \ - double time2 = get_time(); \ - printf(" %8d us C - %8d us OPT\n", \ - static_cast((time1 - time0) * 1e6), \ - static_cast((time2 - time1) * 1e6 / benchmark_iterations_)); \ - for (int i = 0; i < kWidth * BPP_B * kHeight; ++i) { \ - EXPECT_EQ(dst_argb_c[i + OFF], dst_argb_opt[i + OFF]); \ - } \ - free_aligned_buffer_page_end(src_y); \ - free_aligned_buffer_page_end(src_u); \ - free_aligned_buffer_page_end(src_v); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_opt); \ - } - -#define TESTPLANARTOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN) \ - TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_ - 4, _Any, +, 0) \ - TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, _Unaligned, +, 1) \ - TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, _Invert, -, 0) \ - TESTPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, _Opt, +, 0) - -TESTPLANARTOB(I420, 2, 2, ARGB, 4, 4, 1) -TESTPLANARTOB(J420, 2, 2, ARGB, 4, 4, 1) -TESTPLANARTOB(J420, 2, 2, ABGR, 4, 4, 1) -TESTPLANARTOB(H420, 2, 2, ARGB, 4, 4, 1) -TESTPLANARTOB(H420, 2, 2, ABGR, 4, 4, 1) -TESTPLANARTOB(I420, 2, 2, BGRA, 4, 4, 1) -TESTPLANARTOB(I420, 2, 2, ABGR, 4, 4, 1) -TESTPLANARTOB(I420, 2, 2, RGBA, 4, 4, 1) -TESTPLANARTOB(I420, 2, 2, RAW, 3, 3, 1) -TESTPLANARTOB(I420, 2, 2, RGB24, 3, 3, 1) -TESTPLANARTOB(H420, 2, 2, RAW, 3, 3, 1) -TESTPLANARTOB(H420, 2, 2, RGB24, 3, 3, 1) -#ifdef LITTLE_ENDIAN_TEST -TESTPLANARTOB(I420, 2, 2, RGB565, 2, 2, 1) -TESTPLANARTOB(J420, 2, 2, RGB565, 2, 2, 1) -TESTPLANARTOB(H420, 2, 2, RGB565, 2, 2, 1) -TESTPLANARTOB(I420, 2, 2, ARGB1555, 2, 2, 1) -TESTPLANARTOB(I420, 2, 2, ARGB4444, 2, 2, 1) -TESTPLANARTOB(I422, 2, 1, RGB565, 2, 2, 1) -#endif -TESTPLANARTOB(I422, 2, 1, ARGB, 4, 4, 1) -TESTPLANARTOB(J422, 2, 1, ARGB, 4, 4, 1) -TESTPLANARTOB(J422, 2, 1, ABGR, 4, 4, 1) -TESTPLANARTOB(H422, 2, 1, ARGB, 4, 4, 1) -TESTPLANARTOB(H422, 2, 1, ABGR, 4, 4, 1) -TESTPLANARTOB(I422, 2, 1, BGRA, 4, 4, 1) -TESTPLANARTOB(I422, 2, 1, ABGR, 4, 4, 1) -TESTPLANARTOB(I422, 2, 1, RGBA, 4, 4, 1) -TESTPLANARTOB(I444, 1, 1, ARGB, 4, 4, 1) -TESTPLANARTOB(J444, 1, 1, ARGB, 4, 4, 1) -TESTPLANARTOB(I444, 1, 1, ABGR, 4, 4, 1) -TESTPLANARTOB(I420, 2, 2, YUY2, 2, 4, 1) -TESTPLANARTOB(I420, 2, 2, UYVY, 2, 4, 1) -TESTPLANARTOB(I422, 2, 1, YUY2, 2, 4, 1) -TESTPLANARTOB(I422, 2, 1, UYVY, 2, 4, 1) -TESTPLANARTOB(I420, 2, 2, I400, 1, 1, 1) -TESTPLANARTOB(J420, 2, 2, J400, 1, 1, 1) -#ifdef LITTLE_ENDIAN_TEST -TESTPLANARTOB(I420, 2, 2, AR30, 4, 4, 1) -TESTPLANARTOB(H420, 2, 2, AR30, 4, 4, 1) -#endif - -#define TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, W1280, DIFF, N, NEG, OFF, ATTEN) \ - TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ - const int kStrideB = ALIGNINT(kWidth * BPP_B, ALIGN); \ - const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ - const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ - align_buffer_page_end(src_y, kWidth* kHeight + OFF); \ - align_buffer_page_end(src_u, kSizeUV + OFF); \ - align_buffer_page_end(src_v, kSizeUV + OFF); \ - align_buffer_page_end(src_a, kWidth* kHeight + OFF); \ - align_buffer_page_end(dst_argb_c, kStrideB* kHeight + OFF); \ - align_buffer_page_end(dst_argb_opt, kStrideB* kHeight + OFF); \ - for (int i = 0; i < kWidth * kHeight; ++i) { \ - src_y[i + OFF] = (fastrand() & 0xff); \ - src_a[i + OFF] = (fastrand() & 0xff); \ - } \ - for (int i = 0; i < kSizeUV; ++i) { \ - src_u[i + OFF] = (fastrand() & 0xff); \ - src_v[i + OFF] = (fastrand() & 0xff); \ - } \ - memset(dst_argb_c + OFF, 1, kStrideB * kHeight); \ - memset(dst_argb_opt + OFF, 101, kStrideB * kHeight); \ - MaskCpuFlags(disable_cpu_flags_); \ - FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ - src_v + OFF, kStrideUV, src_a + OFF, kWidth, \ - dst_argb_c + OFF, kStrideB, kWidth, NEG kHeight, \ - ATTEN); \ - MaskCpuFlags(benchmark_cpu_info_); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ - src_v + OFF, kStrideUV, src_a + OFF, kWidth, \ - dst_argb_opt + OFF, kStrideB, kWidth, NEG kHeight, \ - ATTEN); \ - } \ - int max_diff = 0; \ - for (int i = 0; i < kWidth * BPP_B * kHeight; ++i) { \ - int abs_diff = abs(static_cast(dst_argb_c[i + OFF]) - \ - static_cast(dst_argb_opt[i + OFF])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ - EXPECT_LE(max_diff, DIFF); \ - free_aligned_buffer_page_end(src_y); \ - free_aligned_buffer_page_end(src_u); \ - free_aligned_buffer_page_end(src_v); \ - free_aligned_buffer_page_end(src_a); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_opt); \ - } - -#define TESTQPLANARTOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, DIFF) \ - TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_ - 4, DIFF, _Any, +, 0, 0) \ - TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, DIFF, _Unaligned, +, 1, 0) \ - TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, DIFF, _Invert, -, 0, 0) \ - TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, DIFF, _Opt, +, 0, 0) \ - TESTQPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, DIFF, _Premult, +, 0, 1) - -TESTQPLANARTOB(I420Alpha, 2, 2, ARGB, 4, 4, 1, 2) -TESTQPLANARTOB(I420Alpha, 2, 2, ABGR, 4, 4, 1, 2) - -#define TESTBIPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, \ - BPP_B, W1280, DIFF, N, NEG, OFF) \ - TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = benchmark_height_; \ - const int kStrideB = kWidth * BPP_B; \ - const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ - align_buffer_page_end(src_y, kWidth* kHeight + OFF); \ - align_buffer_page_end(src_uv, \ - kStrideUV* SUBSAMPLE(kHeight, SUBSAMP_Y) * 2 + OFF); \ - align_buffer_page_end(dst_argb_c, kStrideB* kHeight); \ - align_buffer_page_end(dst_argb_opt, kStrideB* kHeight); \ - for (int i = 0; i < kHeight; ++i) \ - for (int j = 0; j < kWidth; ++j) \ - src_y[i * kWidth + j + OFF] = (fastrand() & 0xff); \ - for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ - for (int j = 0; j < kStrideUV * 2; ++j) { \ - src_uv[i * kStrideUV * 2 + j + OFF] = (fastrand() & 0xff); \ - } \ - } \ - memset(dst_argb_c, 1, kStrideB* kHeight); \ - memset(dst_argb_opt, 101, kStrideB* kHeight); \ - MaskCpuFlags(disable_cpu_flags_); \ - FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_uv + OFF, kStrideUV * 2, \ - dst_argb_c, kWidth * BPP_B, kWidth, NEG kHeight); \ - MaskCpuFlags(benchmark_cpu_info_); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_uv + OFF, kStrideUV * 2, \ - dst_argb_opt, kWidth * BPP_B, kWidth, \ - NEG kHeight); \ - } \ - /* Convert to ARGB so 565 is expanded to bytes that can be compared. */ \ - align_buffer_page_end(dst_argb32_c, kWidth * 4 * kHeight); \ - align_buffer_page_end(dst_argb32_opt, kWidth * 4 * kHeight); \ - memset(dst_argb32_c, 2, kWidth * 4 * kHeight); \ - memset(dst_argb32_opt, 102, kWidth * 4 * kHeight); \ - FMT_C##ToARGB(dst_argb_c, kStrideB, dst_argb32_c, kWidth * 4, kWidth, \ - kHeight); \ - FMT_C##ToARGB(dst_argb_opt, kStrideB, dst_argb32_opt, kWidth * 4, kWidth, \ - kHeight); \ - int max_diff = 0; \ - for (int i = 0; i < kHeight; ++i) { \ - for (int j = 0; j < kWidth * 4; ++j) { \ - int abs_diff = \ - abs(static_cast(dst_argb32_c[i * kWidth * 4 + j]) - \ - static_cast(dst_argb32_opt[i * kWidth * 4 + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ - } \ - EXPECT_LE(max_diff, DIFF); \ - free_aligned_buffer_page_end(src_y); \ - free_aligned_buffer_page_end(src_uv); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_opt); \ - free_aligned_buffer_page_end(dst_argb32_c); \ - free_aligned_buffer_page_end(dst_argb32_opt); \ - } - -#define TESTBIPLANARTOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B, \ - DIFF) \ - TESTBIPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B, \ - benchmark_width_ - 4, DIFF, _Any, +, 0) \ - TESTBIPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B, \ - benchmark_width_, DIFF, _Unaligned, +, 1) \ - TESTBIPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B, \ - benchmark_width_, DIFF, _Invert, -, 0) \ - TESTBIPLANARTOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, FMT_C, BPP_B, \ - benchmark_width_, DIFF, _Opt, +, 0) - -TESTBIPLANARTOB(NV12, 2, 2, ARGB, ARGB, 4, 2) -TESTBIPLANARTOB(NV21, 2, 2, ARGB, ARGB, 4, 2) -TESTBIPLANARTOB(NV12, 2, 2, ABGR, ABGR, 4, 2) -TESTBIPLANARTOB(NV21, 2, 2, ABGR, ABGR, 4, 2) -TESTBIPLANARTOB(NV12, 2, 2, RGB24, RGB24, 3, 2) -TESTBIPLANARTOB(NV21, 2, 2, RGB24, RGB24, 3, 2) -TESTBIPLANARTOB(NV12, 2, 2, RAW, RAW, 3, 2) -TESTBIPLANARTOB(NV21, 2, 2, RAW, RAW, 3, 2) -#ifdef LITTLE_ENDIAN_TEST -TESTBIPLANARTOB(NV12, 2, 2, RGB565, RGB565, 2, 9) -#endif -TESTBIPLANARTOB(NV21, 2, 2, YUV24, RAW, 3, 2) - -#ifdef DO_THREE_PLANES -// Do 3 allocations for yuv. conventional but slower. -#define TESTATOPLANARI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ - W1280, DIFF, N, NEG, OFF) \ - TEST_F(LibYUVConvertTest, FMT_A##To##FMT_PLANAR##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ - const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ - const int kStride = (kStrideUV * SUBSAMP_X * 8 * BPP_A + 7) / 8; \ - align_buffer_page_end(src_argb, kStride* kHeight + OFF); \ - align_buffer_page_end(dst_y_c, kWidth* kHeight); \ - align_buffer_page_end(dst_u_c, kStrideUV* SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - align_buffer_page_end(dst_v_c, kStrideUV* SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - align_buffer_page_end(dst_y_opt, kWidth* kHeight); \ - align_buffer_page_end(dst_u_opt, \ - kStrideUV* SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - align_buffer_page_end(dst_v_opt, \ - kStrideUV* SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_y_c, 1, kWidth* kHeight); \ - memset(dst_u_c, 2, kStrideUV* SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_v_c, 3, kStrideUV* SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_y_opt, 101, kWidth* kHeight); \ - memset(dst_u_opt, 102, kStrideUV* SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_v_opt, 103, kStrideUV* SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - for (int i = 0; i < kHeight; ++i) \ - for (int j = 0; j < kStride; ++j) \ - src_argb[(i * kStride) + j + OFF] = (fastrand() & 0xff); \ - MaskCpuFlags(disable_cpu_flags_); \ - FMT_A##To##FMT_PLANAR(src_argb + OFF, kStride, dst_y_c, kWidth, dst_u_c, \ - kStrideUV, dst_v_c, kStrideUV, kWidth, NEG kHeight); \ - MaskCpuFlags(benchmark_cpu_info_); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_A##To##FMT_PLANAR(src_argb + OFF, kStride, dst_y_opt, kWidth, \ - dst_u_opt, kStrideUV, dst_v_opt, kStrideUV, \ - kWidth, NEG kHeight); \ - } \ - for (int i = 0; i < kHeight; ++i) { \ - for (int j = 0; j < kWidth; ++j) { \ - EXPECT_NEAR(static_cast(dst_y_c[i * kWidth + j]), \ - static_cast(dst_y_opt[i * kWidth + j]), DIFF); \ - } \ - } \ - for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ - for (int j = 0; j < kStrideUV; ++j) { \ - EXPECT_NEAR(static_cast(dst_u_c[i * kStrideUV + j]), \ - static_cast(dst_u_opt[i * kStrideUV + j]), DIFF); \ - } \ - } \ - for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ - for (int j = 0; j < kStrideUV; ++j) { \ - EXPECT_NEAR(static_cast(dst_v_c[i * kStrideUV + j]), \ - static_cast(dst_v_opt[i * kStrideUV + j]), DIFF); \ - } \ - } \ - free_aligned_buffer_page_end(dst_y_c); \ - free_aligned_buffer_page_end(dst_u_c); \ - free_aligned_buffer_page_end(dst_v_c); \ - free_aligned_buffer_page_end(dst_y_opt); \ - free_aligned_buffer_page_end(dst_u_opt); \ - free_aligned_buffer_page_end(dst_v_opt); \ - free_aligned_buffer_page_end(src_argb); \ - } +#if defined(ENABLE_FULL_TESTS) +#define TESTBPTOBP(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, \ + DST_SUBSAMP_Y, SRC_DEPTH, TILE_WIDTH, TILE_HEIGHT) \ + TESTBPTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_ + 1, _Any, +, 0, 1, SRC_DEPTH, TILE_WIDTH, \ + TILE_HEIGHT) \ + TESTBPTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _Unaligned, +, 2, 1, SRC_DEPTH, TILE_WIDTH, \ + TILE_HEIGHT) \ + TESTBPTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _Invert, -, 0, 1, SRC_DEPTH, TILE_WIDTH, \ + TILE_HEIGHT) \ + TESTBPTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0, 1, SRC_DEPTH, TILE_WIDTH, \ + TILE_HEIGHT) \ + TESTBPTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _NullY, +, 0, 0, SRC_DEPTH, TILE_WIDTH, \ + TILE_HEIGHT) #else +#define TESTBPTOBP(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, \ + DST_SUBSAMP_Y, SRC_DEPTH, TILE_WIDTH, TILE_HEIGHT) \ + TESTBPTOBPI(SRC_FMT_PLANAR, SRC_T, SRC_BPC, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, DST_T, DST_BPC, DST_SUBSAMP_X, DST_SUBSAMP_Y, \ + benchmark_width_, _NullY, +, 0, 0, SRC_DEPTH, TILE_WIDTH, \ + TILE_HEIGHT) +#endif + +TESTBPTOBP(NV12, uint8_t, 1, 2, 2, NV21, uint8_t, 1, 2, 2, 8, 1, 1) +TESTBPTOBP(NV21, uint8_t, 1, 2, 2, NV12, uint8_t, 1, 2, 2, 8, 1, 1) +TESTBPTOBP(NV12, uint8_t, 1, 2, 2, NV12Mirror, uint8_t, 1, 2, 2, 8, 1, 1) +TESTBPTOBP(NV12, uint8_t, 1, 2, 2, NV24, uint8_t, 1, 1, 1, 8, 1, 1) +TESTBPTOBP(NV16, uint8_t, 1, 2, 1, NV24, uint8_t, 1, 1, 1, 8, 1, 1) +TESTBPTOBP(P010, uint16_t, 2, 2, 2, P410, uint16_t, 2, 1, 1, 10, 1, 1) +TESTBPTOBP(P210, uint16_t, 2, 2, 1, P410, uint16_t, 2, 1, 1, 10, 1, 1) +TESTBPTOBP(P012, uint16_t, 2, 2, 2, P412, uint16_t, 2, 1, 1, 10, 1, 1) +TESTBPTOBP(P212, uint16_t, 2, 2, 1, P412, uint16_t, 2, 1, 1, 12, 1, 1) +TESTBPTOBP(P016, uint16_t, 2, 2, 2, P416, uint16_t, 2, 1, 1, 12, 1, 1) +TESTBPTOBP(P216, uint16_t, 2, 2, 1, P416, uint16_t, 2, 1, 1, 12, 1, 1) +TESTBPTOBP(MM21, uint8_t, 1, 2, 2, NV12, uint8_t, 1, 2, 2, 8, 16, 32) +TESTBPTOBP(MT2T, uint8_t, 10 / 8, 2, 2, P010, uint16_t, 2, 2, 2, 10, 16, 32) +TESTBPTOBP(P010, uint16_t, 2, 2, 2, NV12, uint8_t, 1, 2, 2, 8, 1, 1) + #define TESTATOPLANARI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ - W1280, DIFF, N, NEG, OFF) \ + W1280, N, NEG, OFF) \ TEST_F(LibYUVConvertTest, FMT_A##To##FMT_PLANAR##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ + const int kWidth = W1280; \ const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ const int kStride = (kStrideUV * SUBSAMP_X * 8 * BPP_A + 7) / 8; \ - align_buffer_page_end(src_argb, kStride* kHeight + OFF); \ - align_buffer_page_end(dst_y_c, kWidth* kHeight); \ + align_buffer_page_end(src_argb, kStride * kHeight + OFF); \ + align_buffer_page_end(dst_y_c, kWidth * kHeight); \ align_buffer_page_end(dst_uv_c, \ kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - align_buffer_page_end(dst_y_opt, kWidth* kHeight); \ + align_buffer_page_end(dst_y_opt, kWidth * kHeight); \ align_buffer_page_end(dst_uv_opt, \ kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_y_c, 1, kWidth* kHeight); \ + memset(dst_y_c, 1, kWidth * kHeight); \ memset(dst_uv_c, 2, kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_y_opt, 101, kWidth* kHeight); \ + memset(dst_y_opt, 101, kWidth * kHeight); \ memset(dst_uv_opt, 102, kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ for (int i = 0; i < kHeight; ++i) \ for (int j = 0; j < kStride; ++j) \ @@ -965,14 +825,12 @@ TESTBIPLANARTOB(NV21, 2, 2, YUV24, RAW, 3, 2) } \ for (int i = 0; i < kHeight; ++i) { \ for (int j = 0; j < kWidth; ++j) { \ - EXPECT_NEAR(static_cast(dst_y_c[i * kWidth + j]), \ - static_cast(dst_y_opt[i * kWidth + j]), DIFF); \ + ASSERT_EQ(dst_y_c[i * kWidth + j], dst_y_opt[i * kWidth + j]); \ } \ } \ for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y) * 2; ++i) { \ for (int j = 0; j < kStrideUV; ++j) { \ - EXPECT_NEAR(static_cast(dst_uv_c[i * kStrideUV + j]), \ - static_cast(dst_uv_opt[i * kStrideUV + j]), DIFF); \ + ASSERT_EQ(dst_uv_c[i * kStrideUV + j], dst_uv_opt[i * kStrideUV + j]); \ } \ } \ free_aligned_buffer_page_end(dst_y_c); \ @@ -981,64 +839,148 @@ TESTBIPLANARTOB(NV21, 2, 2, YUV24, RAW, 3, 2) free_aligned_buffer_page_end(dst_uv_opt); \ free_aligned_buffer_page_end(src_argb); \ } + +#if defined(ENABLE_FULL_TESTS) +#define TESTATOPLANAR(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ + TESTATOPLANARI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_ + 1, _Any, +, 0) \ + TESTATOPLANARI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Unaligned, +, 2) \ + TESTATOPLANARI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Invert, -, 0) \ + TESTATOPLANARI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0) +#else +#define TESTATOPLANAR(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ + TESTATOPLANARI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0) #endif -#define TESTATOPLANAR(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ - DIFF) \ - TESTATOPLANARI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ - benchmark_width_ - 4, DIFF, _Any, +, 0) \ - TESTATOPLANARI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ - benchmark_width_, DIFF, _Unaligned, +, 1) \ - TESTATOPLANARI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ - benchmark_width_, DIFF, _Invert, -, 0) \ - TESTATOPLANARI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ - benchmark_width_, DIFF, _Opt, +, 0) - -TESTATOPLANAR(ABGR, 4, 1, I420, 2, 2, 4) -TESTATOPLANAR(ARGB, 4, 1, I420, 2, 2, 4) -TESTATOPLANAR(ARGB, 4, 1, I422, 2, 1, 2) -TESTATOPLANAR(ARGB, 4, 1, I444, 1, 1, 2) -TESTATOPLANAR(ARGB, 4, 1, J420, 2, 2, ARM_YUV_ERROR) -TESTATOPLANAR(ARGB, 4, 1, J422, 2, 1, ARM_YUV_ERROR) -#ifdef LITTLE_ENDIAN_TEST -TESTATOPLANAR(ARGB1555, 2, 1, I420, 2, 2, 15) -TESTATOPLANAR(ARGB4444, 2, 1, I420, 2, 2, 17) +TESTATOPLANAR(ABGR, 4, 1, I420, 2, 2) +TESTATOPLANAR(ARGB, 4, 1, I420, 2, 2) +TESTATOPLANAR(ARGB, 4, 1, I422, 2, 1) +TESTATOPLANAR(ARGB, 4, 1, I444, 1, 1) +TESTATOPLANAR(ARGB, 4, 1, J420, 2, 2) +TESTATOPLANAR(ARGB, 4, 1, J422, 2, 1) +TESTATOPLANAR(ARGB, 4, 1, J444, 1, 1) +TESTATOPLANAR(ABGR, 4, 1, J420, 2, 2) +TESTATOPLANAR(ABGR, 4, 1, J422, 2, 1) +#ifdef LITTLE_ENDIAN_ONLY_TEST +TESTATOPLANAR(ARGB4444, 2, 1, I420, 2, 2) +TESTATOPLANAR(RGB565, 2, 1, I420, 2, 2) +TESTATOPLANAR(ARGB1555, 2, 1, I420, 2, 2) #endif -TESTATOPLANAR(BGRA, 4, 1, I420, 2, 2, 4) -TESTATOPLANAR(I400, 1, 1, I420, 2, 2, 2) -TESTATOPLANAR(J400, 1, 1, J420, 2, 2, 2) -TESTATOPLANAR(RAW, 3, 1, I420, 2, 2, 4) -TESTATOPLANAR(RGB24, 3, 1, I420, 2, 2, 4) -TESTATOPLANAR(RGB24, 3, 1, J420, 2, 2, ARM_YUV_ERROR) -#ifdef LITTLE_ENDIAN_TEST -TESTATOPLANAR(RGB565, 2, 1, I420, 2, 2, 5) -#endif -TESTATOPLANAR(RGBA, 4, 1, I420, 2, 2, 4) -TESTATOPLANAR(UYVY, 2, 1, I420, 2, 2, 2) -TESTATOPLANAR(UYVY, 2, 1, I422, 2, 1, 2) -TESTATOPLANAR(YUY2, 2, 1, I420, 2, 2, 2) -TESTATOPLANAR(YUY2, 2, 1, I422, 2, 1, 2) +TESTATOPLANAR(BGRA, 4, 1, I420, 2, 2) +TESTATOPLANAR(I400, 1, 1, I420, 2, 2) +TESTATOPLANAR(J400, 1, 1, J420, 2, 2) +TESTATOPLANAR(RAW, 3, 1, I420, 2, 2) +TESTATOPLANAR(RAW, 3, 1, I444, 1, 1) +TESTATOPLANAR(RAW, 3, 1, J420, 2, 2) +TESTATOPLANAR(RAW, 3, 1, J444, 1, 1) +TESTATOPLANAR(RGB24, 3, 1, I420, 2, 2) +TESTATOPLANAR(RGB24, 3, 1, J420, 2, 2) +TESTATOPLANAR(RGBA, 4, 1, I420, 2, 2) +TESTATOPLANAR(AR30, 4, 1, I420, 2, 2) +TESTATOPLANAR(AB30, 4, 1, I420, 2, 2) +TESTATOPLANAR(UYVY, 2, 1, I420, 2, 2) +TESTATOPLANAR(UYVY, 2, 1, I422, 2, 1) +TESTATOPLANAR(YUY2, 2, 1, I420, 2, 2) +TESTATOPLANAR(YUY2, 2, 1, I422, 2, 1) -#define TESTATOBIPLANARI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, \ - SUBSAMP_Y, W1280, N, NEG, OFF) \ +#define TESTATOPLANARAI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, \ + SUBSAMP_Y, W1280, N, NEG, OFF) \ + TEST_F(LibYUVConvertTest, FMT_A##To##FMT_PLANAR##N) { \ + const int kWidth = W1280; \ + const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kStride = (kStrideUV * SUBSAMP_X * 8 * BPP_A + 7) / 8; \ + align_buffer_page_end(src_argb, kStride * kHeight + OFF); \ + align_buffer_page_end(dst_a_c, kWidth * kHeight); \ + align_buffer_page_end(dst_y_c, kWidth * kHeight); \ + align_buffer_page_end(dst_uv_c, \ + kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + align_buffer_page_end(dst_a_opt, kWidth * kHeight); \ + align_buffer_page_end(dst_y_opt, kWidth * kHeight); \ + align_buffer_page_end(dst_uv_opt, \ + kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + memset(dst_a_c, 1, kWidth * kHeight); \ + memset(dst_y_c, 2, kWidth * kHeight); \ + memset(dst_uv_c, 3, kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + memset(dst_a_opt, 101, kWidth * kHeight); \ + memset(dst_y_opt, 102, kWidth * kHeight); \ + memset(dst_uv_opt, 103, kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + for (int i = 0; i < kHeight; ++i) \ + for (int j = 0; j < kStride; ++j) \ + src_argb[(i * kStride) + j + OFF] = (fastrand() & 0xff); \ + MaskCpuFlags(disable_cpu_flags_); \ + FMT_A##To##FMT_PLANAR(src_argb + OFF, kStride, dst_y_c, kWidth, dst_uv_c, \ + kStrideUV * 2, dst_uv_c + kStrideUV, kStrideUV * 2, \ + dst_a_c, kWidth, kWidth, NEG kHeight); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FMT_A##To##FMT_PLANAR(src_argb + OFF, kStride, dst_y_opt, kWidth, \ + dst_uv_opt, kStrideUV * 2, dst_uv_opt + kStrideUV, \ + kStrideUV * 2, dst_a_opt, kWidth, kWidth, \ + NEG kHeight); \ + } \ + for (int i = 0; i < kHeight; ++i) { \ + for (int j = 0; j < kWidth; ++j) { \ + ASSERT_EQ(dst_y_c[i * kWidth + j], dst_y_opt[i * kWidth + j]); \ + ASSERT_EQ(dst_a_c[i * kWidth + j], dst_a_opt[i * kWidth + j]); \ + } \ + } \ + for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y) * 2; ++i) { \ + for (int j = 0; j < kStrideUV; ++j) { \ + ASSERT_EQ(dst_uv_c[i * kStrideUV + j], dst_uv_opt[i * kStrideUV + j]); \ + } \ + } \ + free_aligned_buffer_page_end(dst_a_c); \ + free_aligned_buffer_page_end(dst_y_c); \ + free_aligned_buffer_page_end(dst_uv_c); \ + free_aligned_buffer_page_end(dst_a_opt); \ + free_aligned_buffer_page_end(dst_y_opt); \ + free_aligned_buffer_page_end(dst_uv_opt); \ + free_aligned_buffer_page_end(src_argb); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTATOPLANARA(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ + TESTATOPLANARAI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_ + 1, _Any, +, 0) \ + TESTATOPLANARAI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Unaligned, +, 2) \ + TESTATOPLANARAI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Invert, -, 0) \ + TESTATOPLANARAI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0) +#else +#define TESTATOPLANARA(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ + TESTATOPLANARAI(FMT_A, BPP_A, YALIGN, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0) +#endif + +TESTATOPLANARA(ARGB, 4, 1, I420Alpha, 2, 2) + +#define TESTATOBPI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + W1280, N, NEG, OFF) \ TEST_F(LibYUVConvertTest, FMT_A##To##FMT_PLANAR##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ + const int kWidth = W1280; \ const int kHeight = benchmark_height_; \ const int kStride = SUBSAMPLE(kWidth, SUB_A) * BPP_A; \ const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ - align_buffer_page_end(src_argb, kStride* kHeight + OFF); \ - align_buffer_page_end(dst_y_c, kWidth* kHeight); \ + align_buffer_page_end(src_argb, kStride * kHeight + OFF); \ + align_buffer_page_end(dst_y_c, kWidth * kHeight); \ align_buffer_page_end(dst_uv_c, \ kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - align_buffer_page_end(dst_y_opt, kWidth* kHeight); \ + align_buffer_page_end(dst_y_opt, kWidth * kHeight); \ align_buffer_page_end(dst_uv_opt, \ kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ for (int i = 0; i < kHeight; ++i) \ for (int j = 0; j < kStride; ++j) \ src_argb[(i * kStride) + j + OFF] = (fastrand() & 0xff); \ - memset(dst_y_c, 1, kWidth* kHeight); \ + memset(dst_y_c, 1, kWidth * kHeight); \ memset(dst_uv_c, 2, kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ - memset(dst_y_opt, 101, kWidth* kHeight); \ + memset(dst_y_opt, 101, kWidth * kHeight); \ memset(dst_uv_opt, 102, kStrideUV * 2 * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ MaskCpuFlags(disable_cpu_flags_); \ FMT_A##To##FMT_PLANAR(src_argb + OFF, kStride, dst_y_c, kWidth, dst_uv_c, \ @@ -1048,28 +990,17 @@ TESTATOPLANAR(YUY2, 2, 1, I422, 2, 1, 2) FMT_A##To##FMT_PLANAR(src_argb + OFF, kStride, dst_y_opt, kWidth, \ dst_uv_opt, kStrideUV * 2, kWidth, NEG kHeight); \ } \ - int max_diff = 0; \ for (int i = 0; i < kHeight; ++i) { \ for (int j = 0; j < kWidth; ++j) { \ - int abs_diff = abs(static_cast(dst_y_c[i * kWidth + j]) - \ - static_cast(dst_y_opt[i * kWidth + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ + ASSERT_EQ(dst_y_c[i * kWidth + j], dst_y_opt[i * kWidth + j]); \ } \ } \ - EXPECT_LE(max_diff, 4); \ for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ for (int j = 0; j < kStrideUV * 2; ++j) { \ - int abs_diff = \ - abs(static_cast(dst_uv_c[i * kStrideUV * 2 + j]) - \ - static_cast(dst_uv_opt[i * kStrideUV * 2 + j])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ + ASSERT_EQ(dst_uv_c[i * kStrideUV * 2 + j], \ + dst_uv_opt[i * kStrideUV * 2 + j]); \ } \ } \ - EXPECT_LE(max_diff, 4); \ free_aligned_buffer_page_end(dst_y_c); \ free_aligned_buffer_page_end(dst_uv_c); \ free_aligned_buffer_page_end(dst_y_opt); \ @@ -1077,330 +1008,283 @@ TESTATOPLANAR(YUY2, 2, 1, I422, 2, 1, 2) free_aligned_buffer_page_end(src_argb); \ } -#define TESTATOBIPLANAR(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ - TESTATOBIPLANARI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ - benchmark_width_ - 4, _Any, +, 0) \ - TESTATOBIPLANARI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ - benchmark_width_, _Unaligned, +, 1) \ - TESTATOBIPLANARI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ - benchmark_width_, _Invert, -, 0) \ - TESTATOBIPLANARI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ - benchmark_width_, _Opt, +, 0) +#if defined(ENABLE_FULL_TESTS) +#define TESTATOBP(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ + TESTATOBPI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_ + 1, _Any, +, 0) \ + TESTATOBPI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Unaligned, +, 2) \ + TESTATOBPI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Invert, -, 0) \ + TESTATOBPI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0) +#else +#define TESTATOBP(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ + TESTATOBPI(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0) +#endif -TESTATOBIPLANAR(ARGB, 1, 4, NV12, 2, 2) -TESTATOBIPLANAR(ARGB, 1, 4, NV21, 2, 2) -TESTATOBIPLANAR(ABGR, 1, 4, NV12, 2, 2) -TESTATOBIPLANAR(ABGR, 1, 4, NV21, 2, 2) -TESTATOBIPLANAR(YUY2, 2, 4, NV12, 2, 2) -TESTATOBIPLANAR(UYVY, 2, 4, NV12, 2, 2) -TESTATOBIPLANAR(AYUV, 1, 4, NV12, 2, 2) -TESTATOBIPLANAR(AYUV, 1, 4, NV21, 2, 2) +TESTATOBP(ARGB, 1, 4, NV12, 2, 2) +TESTATOBP(ARGB, 1, 4, NV21, 2, 2) +TESTATOBP(ARGB, 1, 4, NV16, 2, 1) +TESTATOBP(ARGB, 1, 4, NV24, 1, 1) +TESTATOBP(ABGR, 1, 4, NV12, 2, 2) +TESTATOBP(ABGR, 1, 4, NV21, 2, 2) +TESTATOBP(YUY2, 2, 4, NV12, 2, 2) +TESTATOBP(UYVY, 2, 4, NV12, 2, 2) +TESTATOBP(AYUV, 1, 4, NV12, 2, 2) +TESTATOBP(AYUV, 1, 4, NV21, 2, 2) -#define TESTATOBI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, W1280, DIFF, N, NEG, OFF) \ - TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = benchmark_height_; \ - const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ - const int kHeightB = (kHeight + HEIGHT_B - 1) / HEIGHT_B * HEIGHT_B; \ - const int kStrideA = \ - (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ - const int kStrideB = \ - (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ - align_buffer_page_end(src_argb, kStrideA* kHeightA + OFF); \ - align_buffer_page_end(dst_argb_c, kStrideB* kHeightB); \ - align_buffer_page_end(dst_argb_opt, kStrideB* kHeightB); \ - for (int i = 0; i < kStrideA * kHeightA; ++i) { \ - src_argb[i + OFF] = (fastrand() & 0xff); \ - } \ - memset(dst_argb_c, 1, kStrideB* kHeightB); \ - memset(dst_argb_opt, 101, kStrideB* kHeightB); \ - MaskCpuFlags(disable_cpu_flags_); \ - FMT_A##To##FMT_B(src_argb + OFF, kStrideA, dst_argb_c, kStrideB, kWidth, \ - NEG kHeight); \ - MaskCpuFlags(benchmark_cpu_info_); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_A##To##FMT_B(src_argb + OFF, kStrideA, dst_argb_opt, kStrideB, \ - kWidth, NEG kHeight); \ - } \ - int max_diff = 0; \ - for (int i = 0; i < kStrideB * kHeightB; ++i) { \ - int abs_diff = abs(static_cast(dst_argb_c[i]) - \ - static_cast(dst_argb_opt[i])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ - EXPECT_LE(max_diff, DIFF); \ - free_aligned_buffer_page_end(src_argb); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_opt); \ +// Matrix API with I601 constants matches the non-matrix wrapper. +#define TESTATOBPMATRIX(FMT_A, BPP_A, FMT_B, SUBSAMP_X, SUBSAMP_Y) \ + TEST_F(LibYUVConvertTest, Test##FMT_A##To##FMT_B##Matrix) { \ + const int kWidth = 16; \ + const int kHeight = 16; \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kHeightUV = SUBSAMPLE(kHeight, SUBSAMP_Y); \ + align_buffer_page_end(src_argb, kWidth * kHeight * BPP_A); \ + align_buffer_page_end(dst_y, kWidth * kHeight); \ + align_buffer_page_end(dst_uv, kStrideUV * 2 * kHeightUV); \ + align_buffer_page_end(ref_y, kWidth * kHeight); \ + align_buffer_page_end(ref_uv, kStrideUV * 2 * kHeightUV); \ + \ + MemRandomize(src_argb, kWidth * kHeight * BPP_A); \ + \ + FMT_A##To##FMT_B##Matrix(src_argb, kWidth * BPP_A, dst_y, kWidth, dst_uv, \ + kStrideUV * 2, &kArgbI601Constants, kWidth, \ + kHeight); \ + FMT_A##To##FMT_B(src_argb, kWidth * BPP_A, ref_y, kWidth, ref_uv, \ + kStrideUV * 2, kWidth, kHeight); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + ASSERT_EQ(dst_y[i], ref_y[i]); \ + } \ + for (int i = 0; i < kStrideUV * 2 * kHeightUV; ++i) { \ + ASSERT_EQ(dst_uv[i], ref_uv[i]); \ + } \ + \ + free_aligned_buffer_page_end(src_argb); \ + free_aligned_buffer_page_end(dst_y); \ + free_aligned_buffer_page_end(dst_uv); \ + free_aligned_buffer_page_end(ref_y); \ + free_aligned_buffer_page_end(ref_uv); \ } -#define TESTATOBRANDOM(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, \ - STRIDE_B, HEIGHT_B, DIFF) \ - TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##_Random) { \ - for (int times = 0; times < benchmark_iterations_; ++times) { \ - const int kWidth = (fastrand() & 63) + 1; \ - const int kHeight = (fastrand() & 31) + 1; \ - const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ - const int kHeightB = (kHeight + HEIGHT_B - 1) / HEIGHT_B * HEIGHT_B; \ - const int kStrideA = \ - (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ - const int kStrideB = \ - (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ - align_buffer_page_end(src_argb, kStrideA* kHeightA); \ - align_buffer_page_end(dst_argb_c, kStrideB* kHeightB); \ - align_buffer_page_end(dst_argb_opt, kStrideB* kHeightB); \ - for (int i = 0; i < kStrideA * kHeightA; ++i) { \ - src_argb[i] = (fastrand() & 0xff); \ - } \ - memset(dst_argb_c, 123, kStrideB* kHeightB); \ - memset(dst_argb_opt, 123, kStrideB* kHeightB); \ - MaskCpuFlags(disable_cpu_flags_); \ - FMT_A##To##FMT_B(src_argb, kStrideA, dst_argb_c, kStrideB, kWidth, \ - kHeight); \ - MaskCpuFlags(benchmark_cpu_info_); \ - FMT_A##To##FMT_B(src_argb, kStrideA, dst_argb_opt, kStrideB, kWidth, \ - kHeight); \ - for (int i = 0; i < kStrideB * kHeightB; ++i) { \ - EXPECT_NEAR(dst_argb_c[i], dst_argb_opt[i], DIFF); \ - } \ - free_aligned_buffer_page_end(src_argb); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_opt); \ - } \ - } +TESTATOBPMATRIX(ARGB, 4, NV12, 2, 2) +TESTATOBPMATRIX(ARGB, 4, NV16, 2, 1) +TESTATOBPMATRIX(ARGB, 4, NV24, 1, 1) -#define TESTATOB(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, DIFF) \ - TESTATOBI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, benchmark_width_ - 4, DIFF, _Any, +, 0) \ - TESTATOBI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, benchmark_width_, DIFF, _Unaligned, +, 1) \ - TESTATOBI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, benchmark_width_, DIFF, _Invert, -, 0) \ - TESTATOBI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, benchmark_width_, DIFF, _Opt, +, 0) \ - TESTATOBRANDOM(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, DIFF) - -// TODO(fbarchard): make ARM version of C code that matches NEON. -TESTATOB(AB30, 4, 4, 1, ABGR, 4, 4, 1, 0) -TESTATOB(AB30, 4, 4, 1, ARGB, 4, 4, 1, 0) -#ifdef LITTLE_ENDIAN_TEST -TESTATOB(ABGR, 4, 4, 1, AR30, 4, 4, 1, 0) -#endif -TESTATOB(ABGR, 4, 4, 1, ARGB, 4, 4, 1, 0) -#ifdef LITTLE_ENDIAN_TEST -TESTATOB(AR30, 4, 4, 1, AB30, 4, 4, 1, 0) -#endif -TESTATOB(AR30, 4, 4, 1, ABGR, 4, 4, 1, 0) -#ifdef LITTLE_ENDIAN_TEST -TESTATOB(AR30, 4, 4, 1, AR30, 4, 4, 1, 0) -TESTATOB(AR30, 4, 4, 1, ARGB, 4, 4, 1, 0) -#endif -TESTATOB(ARGB, 4, 4, 1, ABGR, 4, 4, 1, 0) -#ifdef LITTLE_ENDIAN_TEST -TESTATOB(ARGB, 4, 4, 1, AR30, 4, 4, 1, 0) -#endif -TESTATOB(ARGB, 4, 4, 1, ARGB, 4, 4, 1, 0) -TESTATOB(ARGB, 4, 4, 1, ARGB1555, 2, 2, 1, 0) -TESTATOB(ARGB, 4, 4, 1, ARGB4444, 2, 2, 1, 0) -TESTATOB(ARGB, 4, 4, 1, ARGBMirror, 4, 4, 1, 0) -TESTATOB(ARGB, 4, 4, 1, BGRA, 4, 4, 1, 0) -TESTATOB(ARGB, 4, 4, 1, I400, 1, 1, 1, 2) -TESTATOB(ARGB, 4, 4, 1, J400, 1, 1, 1, 2) -TESTATOB(ARGB, 4, 4, 1, RAW, 3, 3, 1, 0) -TESTATOB(ARGB, 4, 4, 1, RGB24, 3, 3, 1, 0) -#ifdef LITTLE_ENDIAN_TEST -TESTATOB(ARGB, 4, 4, 1, RGB565, 2, 2, 1, 0) -#endif -TESTATOB(ARGB, 4, 4, 1, RGBA, 4, 4, 1, 0) -TESTATOB(ARGB, 4, 4, 1, UYVY, 2, 4, 1, 4) -TESTATOB(ARGB, 4, 4, 1, YUY2, 2, 4, 1, 4) -TESTATOB(ARGB1555, 2, 2, 1, ARGB, 4, 4, 1, 0) -TESTATOB(ARGB4444, 2, 2, 1, ARGB, 4, 4, 1, 0) -TESTATOB(BGRA, 4, 4, 1, ARGB, 4, 4, 1, 0) -TESTATOB(I400, 1, 1, 1, ARGB, 4, 4, 1, 0) -TESTATOB(I400, 1, 1, 1, I400, 1, 1, 1, 0) -TESTATOB(I400, 1, 1, 1, I400Mirror, 1, 1, 1, 0) -TESTATOB(J400, 1, 1, 1, ARGB, 4, 4, 1, 0) -TESTATOB(J400, 1, 1, 1, J400, 1, 1, 1, 0) -TESTATOB(RAW, 3, 3, 1, ARGB, 4, 4, 1, 0) -TESTATOB(RAW, 3, 3, 1, RGB24, 3, 3, 1, 0) -TESTATOB(RGB24, 3, 3, 1, ARGB, 4, 4, 1, 0) -TESTATOB(RGB24, 3, 3, 1, J400, 1, 1, 1, 0) -#ifdef LITTLE_ENDIAN_TEST -TESTATOB(RGB565, 2, 2, 1, ARGB, 4, 4, 1, 0) -#endif -TESTATOB(RGBA, 4, 4, 1, ARGB, 4, 4, 1, 0) -TESTATOB(UYVY, 2, 4, 1, ARGB, 4, 4, 1, ARM_YUV_ERROR) -TESTATOB(YUY2, 2, 4, 1, ARGB, 4, 4, 1, ARM_YUV_ERROR) -TESTATOB(YUY2, 2, 4, 1, Y, 1, 1, 1, 0) - -#define TESTATOBDI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, W1280, DIFF, N, NEG, OFF) \ - TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##Dither##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = benchmark_height_; \ - const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ - const int kHeightB = (kHeight + HEIGHT_B - 1) / HEIGHT_B * HEIGHT_B; \ - const int kStrideA = \ - (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ - const int kStrideB = \ - (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ - align_buffer_page_end(src_argb, kStrideA* kHeightA + OFF); \ - align_buffer_page_end(dst_argb_c, kStrideB* kHeightB); \ - align_buffer_page_end(dst_argb_opt, kStrideB* kHeightB); \ - for (int i = 0; i < kStrideA * kHeightA; ++i) { \ - src_argb[i + OFF] = (fastrand() & 0xff); \ - } \ - memset(dst_argb_c, 1, kStrideB* kHeightB); \ - memset(dst_argb_opt, 101, kStrideB* kHeightB); \ - MaskCpuFlags(disable_cpu_flags_); \ - FMT_A##To##FMT_B##Dither(src_argb + OFF, kStrideA, dst_argb_c, kStrideB, \ - NULL, kWidth, NEG kHeight); \ - MaskCpuFlags(benchmark_cpu_info_); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_A##To##FMT_B##Dither(src_argb + OFF, kStrideA, dst_argb_opt, \ - kStrideB, NULL, kWidth, NEG kHeight); \ - } \ - int max_diff = 0; \ - for (int i = 0; i < kStrideB * kHeightB; ++i) { \ - int abs_diff = abs(static_cast(dst_argb_c[i]) - \ - static_cast(dst_argb_opt[i])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ - EXPECT_LE(max_diff, DIFF); \ - free_aligned_buffer_page_end(src_argb); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_opt); \ - } - -#define TESTATOBDRANDOM(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, \ - STRIDE_B, HEIGHT_B, DIFF) \ - TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##Dither_Random) { \ - for (int times = 0; times < benchmark_iterations_; ++times) { \ - const int kWidth = (fastrand() & 63) + 1; \ - const int kHeight = (fastrand() & 31) + 1; \ - const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ - const int kHeightB = (kHeight + HEIGHT_B - 1) / HEIGHT_B * HEIGHT_B; \ - const int kStrideA = \ - (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ - const int kStrideB = \ - (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ - align_buffer_page_end(src_argb, kStrideA* kHeightA); \ - align_buffer_page_end(dst_argb_c, kStrideB* kHeightB); \ - align_buffer_page_end(dst_argb_opt, kStrideB* kHeightB); \ - for (int i = 0; i < kStrideA * kHeightA; ++i) { \ - src_argb[i] = (fastrand() & 0xff); \ - } \ - memset(dst_argb_c, 123, kStrideB* kHeightB); \ - memset(dst_argb_opt, 123, kStrideB* kHeightB); \ - MaskCpuFlags(disable_cpu_flags_); \ - FMT_A##To##FMT_B##Dither(src_argb, kStrideA, dst_argb_c, kStrideB, NULL, \ - kWidth, kHeight); \ - MaskCpuFlags(benchmark_cpu_info_); \ - FMT_A##To##FMT_B##Dither(src_argb, kStrideA, dst_argb_opt, kStrideB, \ - NULL, kWidth, kHeight); \ - int max_diff = 0; \ - for (int i = 0; i < kStrideB * kHeightB; ++i) { \ - int abs_diff = abs(static_cast(dst_argb_c[i]) - \ - static_cast(dst_argb_opt[i])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ - EXPECT_LE(max_diff, DIFF); \ - free_aligned_buffer_page_end(src_argb); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_opt); \ - } \ - } - -#define TESTATOBD(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, DIFF) \ - TESTATOBDI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, benchmark_width_ - 4, DIFF, _Any, +, 0) \ - TESTATOBDI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, benchmark_width_, DIFF, _Unaligned, +, 1) \ - TESTATOBDI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, benchmark_width_, DIFF, _Invert, -, 0) \ - TESTATOBDI(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, benchmark_width_, DIFF, _Opt, +, 0) \ - TESTATOBDRANDOM(FMT_A, BPP_A, STRIDE_A, HEIGHT_A, FMT_B, BPP_B, STRIDE_B, \ - HEIGHT_B, DIFF) - -#ifdef LITTLE_ENDIAN_TEST -TESTATOBD(ARGB, 4, 4, 1, RGB565, 2, 2, 1, 0) -#endif - -#define TESTSYMI(FMT_ATOB, BPP_A, STRIDE_A, HEIGHT_A, W1280, N, NEG, OFF) \ - TEST_F(LibYUVConvertTest, FMT_ATOB##_Symetric##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ +#define TESTATOBPI16(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + W1280, N, NEG, OFF) \ + TEST_F(LibYUVConvertTest, FMT_A##To##FMT_PLANAR##N) { \ + const int kWidth = W1280; \ const int kHeight = benchmark_height_; \ - const int kHeightA = (kHeight + HEIGHT_A - 1) / HEIGHT_A * HEIGHT_A; \ - const int kStrideA = \ - (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ - align_buffer_page_end(src_argb, kStrideA* kHeightA + OFF); \ - align_buffer_page_end(dst_argb_c, kStrideA* kHeightA); \ - align_buffer_page_end(dst_argb_opt, kStrideA* kHeightA); \ - for (int i = 0; i < kStrideA * kHeightA; ++i) { \ - src_argb[i + OFF] = (fastrand() & 0xff); \ - } \ - memset(dst_argb_c, 1, kStrideA* kHeightA); \ - memset(dst_argb_opt, 101, kStrideA* kHeightA); \ + const int kStride = SUBSAMPLE(kWidth, SUB_A) * BPP_A; \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kHeightUV = SUBSAMPLE(kHeight, SUBSAMP_Y); \ + align_buffer_page_end(src_argb, kStride * kHeight + OFF); \ + align_buffer_page_end(dst_y_c, kWidth * kHeight * 2); \ + align_buffer_page_end(dst_uv_c, kStrideUV * 2 * kHeightUV * 2); \ + align_buffer_page_end(dst_y_opt, kWidth * kHeight * 2); \ + align_buffer_page_end(dst_uv_opt, kStrideUV * 2 * kHeightUV * 2); \ + for (int i = 0; i < kHeight; ++i) \ + for (int j = 0; j < kStride; ++j) \ + src_argb[(i * kStride) + j + OFF] = (fastrand() & 0xff); \ + memset(dst_y_c, 1, kWidth * kHeight * 2); \ + memset(dst_uv_c, 2, kStrideUV * 2 * kHeightUV * 2); \ + memset(dst_y_opt, 101, kWidth * kHeight * 2); \ + memset(dst_uv_opt, 102, kStrideUV * 2 * kHeightUV * 2); \ MaskCpuFlags(disable_cpu_flags_); \ - FMT_ATOB(src_argb + OFF, kStrideA, dst_argb_c, kStrideA, kWidth, \ - NEG kHeight); \ + FMT_A##To##FMT_PLANAR(src_argb + OFF, kStride, \ + reinterpret_cast(dst_y_c), kWidth, \ + reinterpret_cast(dst_uv_c), \ + kStrideUV * 2, kWidth, NEG kHeight); \ MaskCpuFlags(benchmark_cpu_info_); \ for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_ATOB(src_argb + OFF, kStrideA, dst_argb_opt, kStrideA, kWidth, \ - NEG kHeight); \ + FMT_A##To##FMT_PLANAR(src_argb + OFF, kStride, \ + reinterpret_cast(dst_y_opt), kWidth, \ + reinterpret_cast(dst_uv_opt), \ + kStrideUV * 2, kWidth, NEG kHeight); \ } \ - MaskCpuFlags(disable_cpu_flags_); \ - FMT_ATOB(dst_argb_c, kStrideA, dst_argb_c, kStrideA, kWidth, NEG kHeight); \ - MaskCpuFlags(benchmark_cpu_info_); \ - FMT_ATOB(dst_argb_opt, kStrideA, dst_argb_opt, kStrideA, kWidth, \ - NEG kHeight); \ - for (int i = 0; i < kStrideA * kHeightA; ++i) { \ - EXPECT_EQ(src_argb[i + OFF], dst_argb_opt[i]); \ - EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]); \ + const uint16_t* y_c = reinterpret_cast(dst_y_c); \ + const uint16_t* y_opt = reinterpret_cast(dst_y_opt); \ + const uint16_t* uv_c = reinterpret_cast(dst_uv_c); \ + const uint16_t* uv_opt = reinterpret_cast(dst_uv_opt); \ + for (int i = 0; i < kHeight; ++i) { \ + for (int j = 0; j < kWidth; ++j) { \ + ASSERT_EQ(y_c[i * kWidth + j], y_opt[i * kWidth + j]); \ + } \ + } \ + for (int i = 0; i < kHeightUV; ++i) { \ + for (int j = 0; j < kStrideUV * 2; ++j) { \ + ASSERT_EQ(uv_c[i * kStrideUV * 2 + j], uv_opt[i * kStrideUV * 2 + j]); \ + } \ + } \ + free_aligned_buffer_page_end(dst_y_c); \ + free_aligned_buffer_page_end(dst_uv_c); \ + free_aligned_buffer_page_end(dst_y_opt); \ + free_aligned_buffer_page_end(dst_uv_opt); \ + free_aligned_buffer_page_end(src_argb); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TESTATOBP16(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ + TESTATOBPI16(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_ + 1, _Any, +, 0) \ + TESTATOBPI16(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Unaligned, +, 2) \ + TESTATOBPI16(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Invert, -, 0) \ + TESTATOBPI16(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0) +#else +#define TESTATOBP16(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y) \ + TESTATOBPI16(FMT_A, SUB_A, BPP_A, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + benchmark_width_, _Opt, +, 0) +#endif + +TESTATOBP16(ARGB, 1, 4, P010, 2, 2) +TESTATOBP16(ARGB, 1, 4, P210, 2, 1) +TESTATOBP16(ARGB, 1, 4, P410, 1, 1) + +#define TESTATOBPMATRIX16(FMT_A, BPP_A, FMT_B, SUBSAMP_X, SUBSAMP_Y) \ + TEST_F(LibYUVConvertTest, Test##FMT_A##To##FMT_B##Matrix) { \ + const int kWidth = 16; \ + const int kHeight = 16; \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kHeightUV = SUBSAMPLE(kHeight, SUBSAMP_Y); \ + align_buffer_page_end(src_argb, kWidth * kHeight * BPP_A); \ + align_buffer_page_end(dst_y, kWidth * kHeight * 2); \ + align_buffer_page_end(dst_uv, kStrideUV * 2 * kHeightUV * 2); \ + align_buffer_page_end(ref_y, kWidth * kHeight * 2); \ + align_buffer_page_end(ref_uv, kStrideUV * 2 * kHeightUV * 2); \ + \ + MemRandomize(src_argb, kWidth * kHeight * BPP_A); \ + \ + FMT_A##To##FMT_B##Matrix( \ + src_argb, kWidth * BPP_A, reinterpret_cast(dst_y), kWidth, \ + reinterpret_cast(dst_uv), kStrideUV * 2, \ + &kArgbI601Constants, kWidth, kHeight); \ + FMT_A##To##FMT_B( \ + src_argb, kWidth * BPP_A, reinterpret_cast(ref_y), kWidth, \ + reinterpret_cast(ref_uv), kStrideUV * 2, kWidth, kHeight); \ + const uint16_t* y = reinterpret_cast(dst_y); \ + const uint16_t* y_ref = reinterpret_cast(ref_y); \ + const uint16_t* uv = reinterpret_cast(dst_uv); \ + const uint16_t* uv_ref = reinterpret_cast(ref_uv); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + ASSERT_EQ(y[i], y_ref[i]); \ + } \ + for (int i = 0; i < kStrideUV * 2 * kHeightUV; ++i) { \ + ASSERT_EQ(uv[i], uv_ref[i]); \ + } \ + \ + free_aligned_buffer_page_end(src_argb); \ + free_aligned_buffer_page_end(dst_y); \ + free_aligned_buffer_page_end(dst_uv); \ + free_aligned_buffer_page_end(ref_y); \ + free_aligned_buffer_page_end(ref_uv); \ + } + +TESTATOBPMATRIX16(ARGB, 4, P010, 2, 2) +TESTATOBPMATRIX16(ARGB, 4, P210, 2, 1) +TESTATOBPMATRIX16(ARGB, 4, P410, 1, 1) + +#define TESTATOBP16FROM8(FMT_A, FMT_16, FMT_8, SUBSAMP_X, SUBSAMP_Y) \ + TEST_F(LibYUVConvertTest, Test##FMT_A##To##FMT_16##From##FMT_8) { \ + const int kWidth = 16; \ + const int kHeight = 16; \ + const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kHeightUV = SUBSAMPLE(kHeight, SUBSAMP_Y); \ + align_buffer_page_end(src_argb, kWidth * kHeight * 4); \ + align_buffer_page_end(dst8_y, kWidth * kHeight); \ + align_buffer_page_end(dst8_uv, kStrideUV * 2 * kHeightUV); \ + align_buffer_page_end(dst16_y, kWidth * kHeight * 2); \ + align_buffer_page_end(dst16_uv, kStrideUV * 2 * kHeightUV * 2); \ + MemRandomize(src_argb, kWidth * kHeight * 4); \ + FMT_A##To##FMT_8(src_argb, kWidth * 4, dst8_y, kWidth, dst8_uv, \ + kStrideUV * 2, kWidth, kHeight); \ + FMT_A##To##FMT_16(src_argb, kWidth * 4, \ + reinterpret_cast(dst16_y), kWidth, \ + reinterpret_cast(dst16_uv), kStrideUV * 2, \ + kWidth, kHeight); \ + const uint16_t* y16 = reinterpret_cast(dst16_y); \ + const uint16_t* uv16 = reinterpret_cast(dst16_uv); \ + for (int i = 0; i < kWidth * kHeight; ++i) { \ + ASSERT_EQ(y16[i], static_cast( \ + ((dst8_y[i] * 1024u * 0x0101u) >> 16) << 6)); \ + } \ + for (int i = 0; i < kStrideUV * 2 * kHeightUV; ++i) { \ + ASSERT_EQ(uv16[i], static_cast( \ + ((dst8_uv[i] * 1024u * 0x0101u) >> 16) << 6)); \ + } \ + free_aligned_buffer_page_end(src_argb); \ + free_aligned_buffer_page_end(dst8_y); \ + free_aligned_buffer_page_end(dst8_uv); \ + free_aligned_buffer_page_end(dst16_y); \ + free_aligned_buffer_page_end(dst16_uv); \ + } + +TESTATOBP16FROM8(ARGB, P010, NV12, 2, 2) +TESTATOBP16FROM8(ARGB, P210, NV16, 2, 1) +TESTATOBP16FROM8(ARGB, P410, NV24, 1, 1) + +#define TESTATOBP16TRANSITIVE(FMT_A, FMT_I, FMT_P, SUBSAMP_X, SUBSAMP_Y) \ + TEST_F(LibYUVConvertTest, Test##FMT_A##To##FMT_P##Transitive) { \ + const int kWidth = benchmark_width_ | 1; \ + const int kHeight = benchmark_height_; \ + const int kWidthUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ + const int kHeightUV = SUBSAMPLE(kHeight, SUBSAMP_Y); \ + const int kYSize = kWidth * kHeight; \ + const int kUVSize = kWidthUV * kHeightUV; \ + align_buffer_page_end(src_argb, kYSize * 4); \ + align_buffer_page_end(dst_p_y, kYSize * 2); \ + align_buffer_page_end(dst_p_uv, kUVSize * 2 * 2); \ + align_buffer_page_end(ref_y, kYSize); \ + align_buffer_page_end(ref_u, kUVSize); \ + align_buffer_page_end(ref_v, kUVSize); \ + align_buffer_page_end(ref_p_y, kYSize * 2); \ + align_buffer_page_end(ref_p_uv, kUVSize * 2 * 2); \ + uint16_t* dst_p_y16 = reinterpret_cast(dst_p_y); \ + uint16_t* dst_p_uv16 = reinterpret_cast(dst_p_uv); \ + uint16_t* ref_p_y16 = reinterpret_cast(ref_p_y); \ + uint16_t* ref_p_uv16 = reinterpret_cast(ref_p_uv); \ + MemRandomize(src_argb, kYSize * 4); \ + memset(dst_p_y, 1, kYSize * 2); \ + memset(dst_p_uv, 2, kUVSize * 2 * 2); \ + memset(ref_y, 3, kYSize); \ + memset(ref_u, 4, kUVSize); \ + memset(ref_v, 5, kUVSize); \ + memset(ref_p_y, 6, kYSize * 2); \ + memset(ref_p_uv, 7, kUVSize * 2 * 2); \ + EXPECT_EQ(0, FMT_A##To##FMT_P(src_argb, kWidth * 4, dst_p_y16, kWidth, \ + dst_p_uv16, kWidthUV * 2, kWidth, kHeight)); \ + EXPECT_EQ(0, \ + FMT_A##To##FMT_I(src_argb, kWidth * 4, ref_y, kWidth, ref_u, \ + kWidthUV, ref_v, kWidthUV, kWidth, kHeight)); \ + EXPECT_EQ(0, FMT_I##To##FMT_P(ref_y, kWidth, ref_u, kWidthUV, ref_v, \ + kWidthUV, ref_p_y16, kWidth, ref_p_uv16, \ + kWidthUV * 2, kWidth, kHeight)); \ + for (int i = 0; i < kYSize; ++i) { \ + ASSERT_EQ(dst_p_y16[i], ref_p_y16[i]); \ + } \ + for (int i = 0; i < kUVSize * 2; ++i) { \ + ASSERT_EQ(dst_p_uv16[i], ref_p_uv16[i]); \ } \ free_aligned_buffer_page_end(src_argb); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_opt); \ + free_aligned_buffer_page_end(dst_p_y); \ + free_aligned_buffer_page_end(dst_p_uv); \ + free_aligned_buffer_page_end(ref_y); \ + free_aligned_buffer_page_end(ref_u); \ + free_aligned_buffer_page_end(ref_v); \ + free_aligned_buffer_page_end(ref_p_y); \ + free_aligned_buffer_page_end(ref_p_uv); \ } -#define TESTSYM(FMT_ATOB, BPP_A, STRIDE_A, HEIGHT_A) \ - TESTSYMI(FMT_ATOB, BPP_A, STRIDE_A, HEIGHT_A, benchmark_width_ - 4, _Any, +, \ - 0) \ - TESTSYMI(FMT_ATOB, BPP_A, STRIDE_A, HEIGHT_A, benchmark_width_, _Unaligned, \ - +, 1) \ - TESTSYMI(FMT_ATOB, BPP_A, STRIDE_A, HEIGHT_A, benchmark_width_, _Opt, +, 0) +TESTATOBP16TRANSITIVE(ARGB, I420, P010, 2, 2) +TESTATOBP16TRANSITIVE(ARGB, I422, P210, 2, 1) +TESTATOBP16TRANSITIVE(ARGB, I444, P410, 1, 1) -TESTSYM(ARGBToARGB, 4, 4, 1) -TESTSYM(ARGBToBGRA, 4, 4, 1) -TESTSYM(ARGBToABGR, 4, 4, 1) -TESTSYM(BGRAToARGB, 4, 4, 1) -TESTSYM(ABGRToARGB, 4, 4, 1) - -TEST_F(LibYUVConvertTest, Test565) { - SIMD_ALIGNED(uint8_t orig_pixels[256][4]); - SIMD_ALIGNED(uint8_t pixels565[256][2]); - - for (int i = 0; i < 256; ++i) { - for (int j = 0; j < 4; ++j) { - orig_pixels[i][j] = i; - } - } - ARGBToRGB565(&orig_pixels[0][0], 0, &pixels565[0][0], 0, 256, 1); - uint32_t checksum = HashDjb2(&pixels565[0][0], sizeof(pixels565), 5381); - EXPECT_EQ(610919429u, checksum); -} +#if !defined(LEAN_TESTS) #ifdef HAVE_JPEG TEST_F(LibYUVConvertTest, ValidateJpeg) { @@ -1414,11 +1298,11 @@ TEST_F(LibYUVConvertTest, ValidateJpeg) { // No SOI or EOI. Expect fail. memset(orig_pixels, 0, kSize); - EXPECT_FALSE(ValidateJpeg(orig_pixels, kSize)); + ASSERT_FALSE(ValidateJpeg(orig_pixels, kSize)); // Test special value that matches marker start. memset(orig_pixels, 0xff, kSize); - EXPECT_FALSE(ValidateJpeg(orig_pixels, kSize)); + ASSERT_FALSE(ValidateJpeg(orig_pixels, kSize)); // EOI, SOI. Expect pass. orig_pixels[0] = 0xff; @@ -1427,7 +1311,7 @@ TEST_F(LibYUVConvertTest, ValidateJpeg) { orig_pixels[kSize - kOff + 0] = 0xff; orig_pixels[kSize - kOff + 1] = 0xd9; // EOI. for (int times = 0; times < benchmark_iterations_; ++times) { - EXPECT_TRUE(ValidateJpeg(orig_pixels, kSize)); + ASSERT_TRUE(ValidateJpeg(orig_pixels, kSize)); } free_aligned_buffer_page_end(orig_pixels); } @@ -1445,7 +1329,7 @@ TEST_F(LibYUVConvertTest, ValidateJpegLarge) { // No SOI or EOI. Expect fail. memset(orig_pixels, 0, kBufSize); - EXPECT_FALSE(ValidateJpeg(orig_pixels, kBufSize)); + ASSERT_FALSE(ValidateJpeg(orig_pixels, kBufSize)); // EOI, SOI. Expect pass. orig_pixels[0] = 0xff; @@ -1454,7 +1338,7 @@ TEST_F(LibYUVConvertTest, ValidateJpegLarge) { orig_pixels[kSize - kOff + 0] = 0xff; orig_pixels[kSize - kOff + 1] = 0xd9; // EOI. for (int times = 0; times < benchmark_iterations_; ++times) { - EXPECT_TRUE(ValidateJpeg(orig_pixels, kBufSize)); + ASSERT_TRUE(ValidateJpeg(orig_pixels, kBufSize)); } free_aligned_buffer_page_end(orig_pixels); } @@ -1469,24 +1353,24 @@ TEST_F(LibYUVConvertTest, InvalidateJpeg) { align_buffer_page_end(orig_pixels, kSize); // NULL pointer. Expect fail. - EXPECT_FALSE(ValidateJpeg(NULL, kSize)); + ASSERT_FALSE(ValidateJpeg(NULL, kSize)); // Negative size. Expect fail. - EXPECT_FALSE(ValidateJpeg(orig_pixels, -1)); + ASSERT_FALSE(ValidateJpeg(orig_pixels, -1)); // Too large size. Expect fail. - EXPECT_FALSE(ValidateJpeg(orig_pixels, 0xfb000000ull)); + ASSERT_FALSE(ValidateJpeg(orig_pixels, 0xfb000000ull)); // No SOI or EOI. Expect fail. memset(orig_pixels, 0, kSize); - EXPECT_FALSE(ValidateJpeg(orig_pixels, kSize)); + ASSERT_FALSE(ValidateJpeg(orig_pixels, kSize)); // SOI but no EOI. Expect fail. orig_pixels[0] = 0xff; orig_pixels[1] = 0xd8; // SOI. orig_pixels[2] = 0xff; for (int times = 0; times < benchmark_iterations_; ++times) { - EXPECT_FALSE(ValidateJpeg(orig_pixels, kSize)); + ASSERT_FALSE(ValidateJpeg(orig_pixels, kSize)); } // EOI but no SOI. Expect fail. @@ -1494,7 +1378,7 @@ TEST_F(LibYUVConvertTest, InvalidateJpeg) { orig_pixels[1] = 0; orig_pixels[kSize - kOff + 0] = 0xff; orig_pixels[kSize - kOff + 1] = 0xd9; // EOI. - EXPECT_FALSE(ValidateJpeg(orig_pixels, kSize)); + ASSERT_FALSE(ValidateJpeg(orig_pixels, kSize)); free_aligned_buffer_page_end(orig_pixels); } @@ -1818,7 +1702,7 @@ TEST_F(LibYUVConvertTest, TestMJPGSize) { int width = 0; int height = 0; int ret = MJPGSize(kTest2Jpg, kTest2JpgLen, &width, &height); - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); printf("test jpeg size %d x %d\n", width, height); } @@ -1827,12 +1711,15 @@ TEST_F(LibYUVConvertTest, TestMJPGToI420) { int width = 0; int height = 0; int ret = MJPGSize(kTest2Jpg, kTest2JpgLen, &width, &height); - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); int half_width = (width + 1) / 2; int half_height = (height + 1) / 2; int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } align_buffer_page_end(dst_y, width * height); align_buffer_page_end(dst_u, half_width * half_height); @@ -1842,15 +1729,15 @@ TEST_F(LibYUVConvertTest, TestMJPGToI420) { dst_v, half_width, width, height, width, height); } // Expect sucesss - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); // Test result matches known hash value. uint32_t dst_y_hash = HashDjb2(dst_y, width * height, 5381); uint32_t dst_u_hash = HashDjb2(dst_u, half_width * half_height, 5381); uint32_t dst_v_hash = HashDjb2(dst_v, half_width * half_height, 5381); - EXPECT_EQ(dst_y_hash, 2682851208u); - EXPECT_EQ(dst_u_hash, 2501859930u); - EXPECT_EQ(dst_v_hash, 2126459123u); + ASSERT_EQ(dst_y_hash, 2682851208u); + ASSERT_EQ(dst_u_hash, 2501859930u); + ASSERT_EQ(dst_v_hash, 2126459123u); free_aligned_buffer_page_end(dst_y); free_aligned_buffer_page_end(dst_u); @@ -1861,12 +1748,15 @@ TEST_F(LibYUVConvertTest, TestMJPGToI420_NV21) { int width = 0; int height = 0; int ret = MJPGSize(kTest2Jpg, kTest2JpgLen, &width, &height); - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); int half_width = (width + 1) / 2; int half_height = (height + 1) / 2; int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } // Convert to NV21 align_buffer_page_end(dst_y, width * height); @@ -1877,7 +1767,7 @@ TEST_F(LibYUVConvertTest, TestMJPGToI420_NV21) { half_width * 2, width, height, width, height); } // Expect sucesss - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); // Convert to I420 align_buffer_page_end(dst2_y, width * height); @@ -1888,7 +1778,7 @@ TEST_F(LibYUVConvertTest, TestMJPGToI420_NV21) { dst2_v, half_width, width, height, width, height); } // Expect sucesss - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); // Convert I420 to NV21 align_buffer_page_end(dst3_y, width * height); @@ -1898,11 +1788,11 @@ TEST_F(LibYUVConvertTest, TestMJPGToI420_NV21) { width, dst3_vu, half_width * 2, width, height); for (int i = 0; i < width * height; ++i) { - EXPECT_EQ(dst_y[i], dst3_y[i]); + ASSERT_EQ(dst_y[i], dst3_y[i]); } for (int i = 0; i < half_width * half_height * 2; ++i) { - EXPECT_EQ(dst_vu[i], dst3_vu[i]); - EXPECT_EQ(dst_vu[i], dst3_vu[i]); + ASSERT_EQ(dst_vu[i], dst3_vu[i]); + ASSERT_EQ(dst_vu[i], dst3_vu[i]); } free_aligned_buffer_page_end(dst3_y); @@ -1916,16 +1806,81 @@ TEST_F(LibYUVConvertTest, TestMJPGToI420_NV21) { free_aligned_buffer_page_end(dst_vu); } -TEST_F(LibYUVConvertTest, TestMJPGToNV21_420) { +TEST_F(LibYUVConvertTest, TestMJPGToI420_NV12) { int width = 0; int height = 0; int ret = MJPGSize(kTest2Jpg, kTest2JpgLen, &width, &height); - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); int half_width = (width + 1) / 2; int half_height = (height + 1) / 2; int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } + + // Convert to NV12 + align_buffer_page_end(dst_y, width * height); + align_buffer_page_end(dst_uv, half_width * half_height * 2); + + for (int times = 0; times < benchmark_iterations; ++times) { + ret = MJPGToNV12(kTest2Jpg, kTest2JpgLen, dst_y, width, dst_uv, + half_width * 2, width, height, width, height); + } + // Expect sucesss + ASSERT_EQ(0, ret); + + // Convert to I420 + align_buffer_page_end(dst2_y, width * height); + align_buffer_page_end(dst2_u, half_width * half_height); + align_buffer_page_end(dst2_v, half_width * half_height); + for (int times = 0; times < benchmark_iterations; ++times) { + ret = MJPGToI420(kTest2Jpg, kTest2JpgLen, dst2_y, width, dst2_u, half_width, + dst2_v, half_width, width, height, width, height); + } + // Expect sucesss + ASSERT_EQ(0, ret); + + // Convert I420 to NV12 + align_buffer_page_end(dst3_y, width * height); + align_buffer_page_end(dst3_uv, half_width * half_height * 2); + + I420ToNV12(dst2_y, width, dst2_u, half_width, dst2_v, half_width, dst3_y, + width, dst3_uv, half_width * 2, width, height); + + for (int i = 0; i < width * height; ++i) { + ASSERT_EQ(dst_y[i], dst3_y[i]); + } + for (int i = 0; i < half_width * half_height * 2; ++i) { + ASSERT_EQ(dst_uv[i], dst3_uv[i]); + ASSERT_EQ(dst_uv[i], dst3_uv[i]); + } + + free_aligned_buffer_page_end(dst3_y); + free_aligned_buffer_page_end(dst3_uv); + + free_aligned_buffer_page_end(dst2_y); + free_aligned_buffer_page_end(dst2_u); + free_aligned_buffer_page_end(dst2_v); + + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_uv); +} + +TEST_F(LibYUVConvertTest, TestMJPGToNV21_420) { + int width = 0; + int height = 0; + int ret = MJPGSize(kTest2Jpg, kTest2JpgLen, &width, &height); + ASSERT_EQ(0, ret); + + int half_width = (width + 1) / 2; + int half_height = (height + 1) / 2; + int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * + benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } align_buffer_page_end(dst_y, width * height); align_buffer_page_end(dst_uv, half_width * half_height * 2); @@ -1934,28 +1889,69 @@ TEST_F(LibYUVConvertTest, TestMJPGToNV21_420) { half_width * 2, width, height, width, height); } // Expect sucesss - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); // Test result matches known hash value. uint32_t dst_y_hash = HashDjb2(dst_y, width * height, 5381); uint32_t dst_uv_hash = HashDjb2(dst_uv, half_width * half_height * 2, 5381); - EXPECT_EQ(dst_y_hash, 2682851208u); - EXPECT_EQ(dst_uv_hash, 1069662856u); + ASSERT_EQ(dst_y_hash, 2682851208u); + ASSERT_EQ(dst_uv_hash, 1069662856u); free_aligned_buffer_page_end(dst_y); free_aligned_buffer_page_end(dst_uv); } -TEST_F(LibYUVConvertTest, TestMJPGToNV21_422) { +TEST_F(LibYUVConvertTest, TestMJPGToNV12_420) { int width = 0; int height = 0; - int ret = MJPGSize(kTest3Jpg, kTest3JpgLen, &width, &height); - EXPECT_EQ(0, ret); + int ret = MJPGSize(kTest2Jpg, kTest2JpgLen, &width, &height); + ASSERT_EQ(0, ret); int half_width = (width + 1) / 2; int half_height = (height + 1) / 2; int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } + + align_buffer_page_end(dst_y, width * height); + align_buffer_page_end(dst_uv, half_width * half_height * 2); + for (int times = 0; times < benchmark_iterations; ++times) { + ret = MJPGToNV12(kTest2Jpg, kTest2JpgLen, dst_y, width, dst_uv, + half_width * 2, width, height, width, height); + } + // Expect sucesss + ASSERT_EQ(0, ret); + + // Test result matches known hash value. Hashes are for VU so flip the plane. + uint32_t dst_y_hash = HashDjb2(dst_y, width * height, 5381); + align_buffer_page_end(dst_vu, half_width * half_height * 2); + SwapUVPlane(dst_uv, half_width * 2, dst_vu, half_width * 2, half_width, + half_height); + uint32_t dst_vu_hash = HashDjb2(dst_vu, half_width * half_height * 2, 5381); + ASSERT_EQ(dst_y_hash, 2682851208u); + ASSERT_EQ(dst_vu_hash, 1069662856u); + + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_uv); + free_aligned_buffer_page_end(dst_vu); +} + +// TODO(fbarchard): Improve test to compare against I422, not checksum +TEST_F(LibYUVConvertTest, DISABLED_TestMJPGToNV21_422) { + int width = 0; + int height = 0; + int ret = MJPGSize(kTest3Jpg, kTest3JpgLen, &width, &height); + ASSERT_EQ(0, ret); + + int half_width = (width + 1) / 2; + int half_height = (height + 1) / 2; + int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * + benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } align_buffer_page_end(dst_y, width * height); align_buffer_page_end(dst_uv, half_width * half_height * 2); @@ -1964,28 +1960,68 @@ TEST_F(LibYUVConvertTest, TestMJPGToNV21_422) { half_width * 2, width, height, width, height); } // Expect sucesss - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); // Test result matches known hash value. uint32_t dst_y_hash = HashDjb2(dst_y, width * height, 5381); uint32_t dst_uv_hash = HashDjb2(dst_uv, half_width * half_height * 2, 5381); - EXPECT_EQ(dst_y_hash, 2682851208u); - EXPECT_EQ(dst_uv_hash, 3543430771u); + ASSERT_EQ(dst_y_hash, 2682851208u); + ASSERT_EQ(dst_uv_hash, 493520167u); free_aligned_buffer_page_end(dst_y); free_aligned_buffer_page_end(dst_uv); } +TEST_F(LibYUVConvertTest, DISABLED_TestMJPGToNV12_422) { + int width = 0; + int height = 0; + int ret = MJPGSize(kTest3Jpg, kTest3JpgLen, &width, &height); + ASSERT_EQ(0, ret); + + int half_width = (width + 1) / 2; + int half_height = (height + 1) / 2; + int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * + benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } + + align_buffer_page_end(dst_y, width * height); + align_buffer_page_end(dst_uv, half_width * half_height * 2); + for (int times = 0; times < benchmark_iterations; ++times) { + ret = MJPGToNV12(kTest3Jpg, kTest3JpgLen, dst_y, width, dst_uv, + half_width * 2, width, height, width, height); + } + // Expect sucesss + ASSERT_EQ(0, ret); + + // Test result matches known hash value. Hashes are for VU so flip the plane. + uint32_t dst_y_hash = HashDjb2(dst_y, width * height, 5381); + align_buffer_page_end(dst_vu, half_width * half_height * 2); + SwapUVPlane(dst_uv, half_width * 2, dst_vu, half_width * 2, half_width, + half_height); + uint32_t dst_vu_hash = HashDjb2(dst_vu, half_width * half_height * 2, 5381); + ASSERT_EQ(dst_y_hash, 2682851208u); + ASSERT_EQ(dst_vu_hash, 493520167u); + + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_uv); + free_aligned_buffer_page_end(dst_vu); +} + TEST_F(LibYUVConvertTest, TestMJPGToNV21_400) { int width = 0; int height = 0; int ret = MJPGSize(kTest0Jpg, kTest0JpgLen, &width, &height); - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); int half_width = (width + 1) / 2; int half_height = (height + 1) / 2; int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } align_buffer_page_end(dst_y, width * height); align_buffer_page_end(dst_uv, half_width * half_height * 2); @@ -1994,28 +2030,68 @@ TEST_F(LibYUVConvertTest, TestMJPGToNV21_400) { half_width * 2, width, height, width, height); } // Expect sucesss - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); // Test result matches known hash value. uint32_t dst_y_hash = HashDjb2(dst_y, width * height, 5381); uint32_t dst_uv_hash = HashDjb2(dst_uv, half_width * half_height * 2, 5381); - EXPECT_EQ(dst_y_hash, 330644005u); - EXPECT_EQ(dst_uv_hash, 135214341u); + ASSERT_EQ(dst_y_hash, 330644005u); + ASSERT_EQ(dst_uv_hash, 135214341u); free_aligned_buffer_page_end(dst_y); free_aligned_buffer_page_end(dst_uv); } +TEST_F(LibYUVConvertTest, TestMJPGToNV12_400) { + int width = 0; + int height = 0; + int ret = MJPGSize(kTest0Jpg, kTest0JpgLen, &width, &height); + ASSERT_EQ(0, ret); + + int half_width = (width + 1) / 2; + int half_height = (height + 1) / 2; + int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * + benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } + + align_buffer_page_end(dst_y, width * height); + align_buffer_page_end(dst_uv, half_width * half_height * 2); + for (int times = 0; times < benchmark_iterations; ++times) { + ret = MJPGToNV12(kTest0Jpg, kTest0JpgLen, dst_y, width, dst_uv, + half_width * 2, width, height, width, height); + } + // Expect sucesss + ASSERT_EQ(0, ret); + + // Test result matches known hash value. Hashes are for VU so flip the plane. + uint32_t dst_y_hash = HashDjb2(dst_y, width * height, 5381); + align_buffer_page_end(dst_vu, half_width * half_height * 2); + SwapUVPlane(dst_uv, half_width * 2, dst_vu, half_width * 2, half_width, + half_height); + uint32_t dst_vu_hash = HashDjb2(dst_vu, half_width * half_height * 2, 5381); + ASSERT_EQ(dst_y_hash, 330644005u); + ASSERT_EQ(dst_vu_hash, 135214341u); + + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_uv); + free_aligned_buffer_page_end(dst_vu); +} + TEST_F(LibYUVConvertTest, TestMJPGToNV21_444) { int width = 0; int height = 0; int ret = MJPGSize(kTest1Jpg, kTest1JpgLen, &width, &height); - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); int half_width = (width + 1) / 2; int half_height = (height + 1) / 2; int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } align_buffer_page_end(dst_y, width * height); align_buffer_page_end(dst_uv, half_width * half_height * 2); @@ -2024,26 +2100,66 @@ TEST_F(LibYUVConvertTest, TestMJPGToNV21_444) { half_width * 2, width, height, width, height); } // Expect sucesss - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); // Test result matches known hash value. uint32_t dst_y_hash = HashDjb2(dst_y, width * height, 5381); uint32_t dst_uv_hash = HashDjb2(dst_uv, half_width * half_height * 2, 5381); - EXPECT_EQ(dst_y_hash, 2682851208u); - EXPECT_EQ(dst_uv_hash, 506143297u); + ASSERT_EQ(dst_y_hash, 2682851208u); + ASSERT_EQ(dst_uv_hash, 506143297u); free_aligned_buffer_page_end(dst_y); free_aligned_buffer_page_end(dst_uv); } +TEST_F(LibYUVConvertTest, TestMJPGToNV12_444) { + int width = 0; + int height = 0; + int ret = MJPGSize(kTest1Jpg, kTest1JpgLen, &width, &height); + ASSERT_EQ(0, ret); + + int half_width = (width + 1) / 2; + int half_height = (height + 1) / 2; + int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * + benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } + + align_buffer_page_end(dst_y, width * height); + align_buffer_page_end(dst_uv, half_width * half_height * 2); + for (int times = 0; times < benchmark_iterations; ++times) { + ret = MJPGToNV12(kTest1Jpg, kTest1JpgLen, dst_y, width, dst_uv, + half_width * 2, width, height, width, height); + } + // Expect sucesss + ASSERT_EQ(0, ret); + + // Test result matches known hash value. Hashes are for VU so flip the plane. + uint32_t dst_y_hash = HashDjb2(dst_y, width * height, 5381); + align_buffer_page_end(dst_vu, half_width * half_height * 2); + SwapUVPlane(dst_uv, half_width * 2, dst_vu, half_width * 2, half_width, + half_height); + uint32_t dst_vu_hash = HashDjb2(dst_vu, half_width * half_height * 2, 5381); + ASSERT_EQ(dst_y_hash, 2682851208u); + ASSERT_EQ(dst_vu_hash, 506143297u); + + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_uv); + free_aligned_buffer_page_end(dst_vu); +} + TEST_F(LibYUVConvertTest, TestMJPGToARGB) { int width = 0; int height = 0; int ret = MJPGSize(kTest3Jpg, kTest3JpgLen, &width, &height); - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); int benchmark_iterations = benchmark_iterations_ * benchmark_width_ * benchmark_height_ / (width * height); + if (benchmark_iterations < 1) { + benchmark_iterations = 1; + } align_buffer_page_end(dst_argb, width * height * 4); for (int times = 0; times < benchmark_iterations; ++times) { @@ -2051,18 +2167,22 @@ TEST_F(LibYUVConvertTest, TestMJPGToARGB) { height, width, height); } // Expect sucesss - EXPECT_EQ(0, ret); + ASSERT_EQ(0, ret); // Test result matches known hash value. uint32_t dst_argb_hash = HashDjb2(dst_argb, width * height, 5381); - EXPECT_EQ(dst_argb_hash, 2355976473u); +#ifdef LIBYUV_UNLIMITED_DATA + ASSERT_EQ(dst_argb_hash, 3900633302u); +#else + ASSERT_EQ(dst_argb_hash, 2355976473u); +#endif free_aligned_buffer_page_end(dst_argb); } -static int ShowJPegInfo(const uint8_t* sample, size_t sample_size) { +static bool ShowJPegInfo(const uint8_t* sample, size_t sample_size) { MJpegDecoder mjpeg_decoder; - LIBYUV_BOOL ret = mjpeg_decoder.LoadFrame(sample, sample_size); + bool ret = mjpeg_decoder.LoadFrame(sample, sample_size); int width = mjpeg_decoder.GetWidth(); int height = mjpeg_decoder.GetHeight(); @@ -2117,12 +2237,12 @@ static int ShowJPegInfo(const uint8_t* sample, size_t sample_size) { } TEST_F(LibYUVConvertTest, TestMJPGInfo) { - EXPECT_EQ(1, ShowJPegInfo(kTest0Jpg, kTest0JpgLen)); - EXPECT_EQ(1, ShowJPegInfo(kTest1Jpg, kTest1JpgLen)); - EXPECT_EQ(1, ShowJPegInfo(kTest2Jpg, kTest2JpgLen)); - EXPECT_EQ(1, ShowJPegInfo(kTest3Jpg, kTest3JpgLen)); - EXPECT_EQ(1, ShowJPegInfo(kTest4Jpg, - kTest4JpgLen)); // Valid but unsupported. + ASSERT_TRUE(ShowJPegInfo(kTest0Jpg, kTest0JpgLen)); + ASSERT_TRUE(ShowJPegInfo(kTest1Jpg, kTest1JpgLen)); + ASSERT_TRUE(ShowJPegInfo(kTest2Jpg, kTest2JpgLen)); + ASSERT_TRUE(ShowJPegInfo(kTest3Jpg, kTest3JpgLen)); + ASSERT_TRUE(ShowJPegInfo(kTest4Jpg, + kTest4JpgLen)); // Valid but unsupported. } #endif // HAVE_JPEG @@ -2182,18 +2302,18 @@ TEST_F(LibYUVConvertTest, NV12Crop) { for (int i = 0; i < kDestHeight; ++i) { for (int j = 0; j < kDestWidth; ++j) { - EXPECT_EQ(dst_y[i * kWidth + j], dst_y_2[i * kWidth + j]); + ASSERT_EQ(dst_y[i * kWidth + j], dst_y_2[i * kWidth + j]); } } for (int i = 0; i < SUBSAMPLE(kDestHeight, SUBSAMP_Y); ++i) { for (int j = 0; j < SUBSAMPLE(kDestWidth, SUBSAMP_X); ++j) { - EXPECT_EQ(dst_u[i * SUBSAMPLE(kDestWidth, SUBSAMP_X) + j], + ASSERT_EQ(dst_u[i * SUBSAMPLE(kDestWidth, SUBSAMP_X) + j], dst_u_2[i * SUBSAMPLE(kDestWidth, SUBSAMP_X) + j]); } } for (int i = 0; i < SUBSAMPLE(kDestHeight, SUBSAMP_Y); ++i) { for (int j = 0; j < SUBSAMPLE(kDestWidth, SUBSAMP_X); ++j) { - EXPECT_EQ(dst_v[i * SUBSAMPLE(kDestWidth, SUBSAMP_X) + j], + ASSERT_EQ(dst_v[i * SUBSAMPLE(kDestWidth, SUBSAMP_X) + j], dst_v_2[i * SUBSAMPLE(kDestWidth, SUBSAMP_X) + j]); } } @@ -2211,7 +2331,7 @@ TEST_F(LibYUVConvertTest, I420CropOddY) { const int SUBSAMP_Y = 2; const int kWidth = benchmark_width_; const int kHeight = benchmark_height_; - const int crop_y = 1; + const int crop_y = benchmark_height_ > 1 ? 1 : 0; const int kDestWidth = benchmark_width_; const int kDestHeight = benchmark_height_ - crop_y * 2; const int kStrideU = SUBSAMPLE(kWidth, SUBSAMP_X); @@ -2255,19 +2375,19 @@ TEST_F(LibYUVConvertTest, I420CropOddY) { for (int i = 0; i < kDestHeight; ++i) { for (int j = 0; j < kDestWidth; ++j) { - EXPECT_EQ(src_y[crop_y * kWidth + i * kWidth + j], + ASSERT_EQ(src_y[crop_y * kWidth + i * kWidth + j], dst_y[i * kDestWidth + j]); } } for (int i = 0; i < SUBSAMPLE(kDestHeight, SUBSAMP_Y); ++i) { for (int j = 0; j < SUBSAMPLE(kDestWidth, SUBSAMP_X); ++j) { - EXPECT_EQ(src_u[(crop_y / 2 + i) * kStrideU + j], + ASSERT_EQ(src_u[(crop_y / 2 + i) * kStrideU + j], dst_u[i * SUBSAMPLE(kDestWidth, SUBSAMP_X) + j]); } } for (int i = 0; i < SUBSAMPLE(kDestHeight, SUBSAMP_Y); ++i) { for (int j = 0; j < SUBSAMPLE(kDestWidth, SUBSAMP_X); ++j) { - EXPECT_EQ(src_v[(crop_y / 2 + i) * kStrideV + j], + ASSERT_EQ(src_v[(crop_y / 2 + i) * kStrideV + j], dst_v[i * SUBSAMPLE(kDestWidth, SUBSAMP_X) + j]); } } @@ -2278,181 +2398,23 @@ TEST_F(LibYUVConvertTest, I420CropOddY) { free_aligned_buffer_page_end(src_y); } -TEST_F(LibYUVConvertTest, TestYToARGB) { - uint8_t y[32]; - uint8_t expectedg[32]; - for (int i = 0; i < 32; ++i) { - y[i] = i * 5 + 17; - expectedg[i] = static_cast((y[i] - 16) * 1.164f + 0.5f); - } - uint8_t argb[32 * 4]; - YToARGB(y, 0, argb, 0, 32, 1); - - for (int i = 0; i < 32; ++i) { - printf("%2d %d: %d <-> %d,%d,%d,%d\n", i, y[i], expectedg[i], - argb[i * 4 + 0], argb[i * 4 + 1], argb[i * 4 + 2], argb[i * 4 + 3]); - } - for (int i = 0; i < 32; ++i) { - EXPECT_EQ(expectedg[i], argb[i * 4 + 0]); - } -} - -static const uint8_t kNoDither4x4[16] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - -TEST_F(LibYUVConvertTest, TestNoDither) { - align_buffer_page_end(src_argb, benchmark_width_ * benchmark_height_ * 4); - align_buffer_page_end(dst_rgb565, benchmark_width_ * benchmark_height_ * 2); - align_buffer_page_end(dst_rgb565dither, - benchmark_width_ * benchmark_height_ * 2); - MemRandomize(src_argb, benchmark_width_ * benchmark_height_ * 4); - MemRandomize(dst_rgb565, benchmark_width_ * benchmark_height_ * 2); - MemRandomize(dst_rgb565dither, benchmark_width_ * benchmark_height_ * 2); - ARGBToRGB565(src_argb, benchmark_width_ * 4, dst_rgb565, benchmark_width_ * 2, - benchmark_width_, benchmark_height_); - ARGBToRGB565Dither(src_argb, benchmark_width_ * 4, dst_rgb565dither, - benchmark_width_ * 2, kNoDither4x4, benchmark_width_, - benchmark_height_); - for (int i = 0; i < benchmark_width_ * benchmark_height_ * 2; ++i) { - EXPECT_EQ(dst_rgb565[i], dst_rgb565dither[i]); - } - - free_aligned_buffer_page_end(src_argb); - free_aligned_buffer_page_end(dst_rgb565); - free_aligned_buffer_page_end(dst_rgb565dither); -} - -// Ordered 4x4 dither for 888 to 565. Values from 0 to 7. -static const uint8_t kDither565_4x4[16] = { - 0, 4, 1, 5, 6, 2, 7, 3, 1, 5, 0, 4, 7, 3, 6, 2, -}; - -TEST_F(LibYUVConvertTest, TestDither) { - align_buffer_page_end(src_argb, benchmark_width_ * benchmark_height_ * 4); - align_buffer_page_end(dst_rgb565, benchmark_width_ * benchmark_height_ * 2); - align_buffer_page_end(dst_rgb565dither, - benchmark_width_ * benchmark_height_ * 2); - align_buffer_page_end(dst_argb, benchmark_width_ * benchmark_height_ * 4); - align_buffer_page_end(dst_argbdither, - benchmark_width_ * benchmark_height_ * 4); - MemRandomize(src_argb, benchmark_width_ * benchmark_height_ * 4); - MemRandomize(dst_rgb565, benchmark_width_ * benchmark_height_ * 2); - MemRandomize(dst_rgb565dither, benchmark_width_ * benchmark_height_ * 2); - MemRandomize(dst_argb, benchmark_width_ * benchmark_height_ * 4); - MemRandomize(dst_argbdither, benchmark_width_ * benchmark_height_ * 4); - ARGBToRGB565(src_argb, benchmark_width_ * 4, dst_rgb565, benchmark_width_ * 2, - benchmark_width_, benchmark_height_); - ARGBToRGB565Dither(src_argb, benchmark_width_ * 4, dst_rgb565dither, - benchmark_width_ * 2, kDither565_4x4, benchmark_width_, - benchmark_height_); - RGB565ToARGB(dst_rgb565, benchmark_width_ * 2, dst_argb, benchmark_width_ * 4, - benchmark_width_, benchmark_height_); - RGB565ToARGB(dst_rgb565dither, benchmark_width_ * 2, dst_argbdither, - benchmark_width_ * 4, benchmark_width_, benchmark_height_); - - for (int i = 0; i < benchmark_width_ * benchmark_height_ * 4; ++i) { - EXPECT_NEAR(dst_argb[i], dst_argbdither[i], 9); - } - free_aligned_buffer_page_end(src_argb); - free_aligned_buffer_page_end(dst_rgb565); - free_aligned_buffer_page_end(dst_rgb565dither); - free_aligned_buffer_page_end(dst_argb); - free_aligned_buffer_page_end(dst_argbdither); -} - -#define TESTPLANARTOBID(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, W1280, DIFF, N, NEG, OFF, FMT_C, BPP_C) \ - TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##Dither##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ - const int kStrideB = ALIGNINT(kWidth * BPP_B, ALIGN); \ - const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ - const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ - align_buffer_page_end(src_y, kWidth* kHeight + OFF); \ - align_buffer_page_end(src_u, kSizeUV + OFF); \ - align_buffer_page_end(src_v, kSizeUV + OFF); \ - align_buffer_page_end(dst_argb_c, kStrideB* kHeight + OFF); \ - align_buffer_page_end(dst_argb_opt, kStrideB* kHeight + OFF); \ - for (int i = 0; i < kWidth * kHeight; ++i) { \ - src_y[i + OFF] = (fastrand() & 0xff); \ - } \ - for (int i = 0; i < kSizeUV; ++i) { \ - src_u[i + OFF] = (fastrand() & 0xff); \ - src_v[i + OFF] = (fastrand() & 0xff); \ - } \ - memset(dst_argb_c + OFF, 1, kStrideB * kHeight); \ - memset(dst_argb_opt + OFF, 101, kStrideB * kHeight); \ - MaskCpuFlags(disable_cpu_flags_); \ - FMT_PLANAR##To##FMT_B##Dither(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ - src_v + OFF, kStrideUV, dst_argb_c + OFF, \ - kStrideB, NULL, kWidth, NEG kHeight); \ - MaskCpuFlags(benchmark_cpu_info_); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_PLANAR##To##FMT_B##Dither( \ - src_y + OFF, kWidth, src_u + OFF, kStrideUV, src_v + OFF, kStrideUV, \ - dst_argb_opt + OFF, kStrideB, NULL, kWidth, NEG kHeight); \ - } \ - int max_diff = 0; \ - /* Convert to ARGB so 565 is expanded to bytes that can be compared. */ \ - align_buffer_page_end(dst_argb32_c, kWidth* BPP_C* kHeight); \ - align_buffer_page_end(dst_argb32_opt, kWidth* BPP_C* kHeight); \ - memset(dst_argb32_c, 2, kWidth* BPP_C* kHeight); \ - memset(dst_argb32_opt, 102, kWidth* BPP_C* kHeight); \ - FMT_B##To##FMT_C(dst_argb_c + OFF, kStrideB, dst_argb32_c, kWidth * BPP_C, \ - kWidth, kHeight); \ - FMT_B##To##FMT_C(dst_argb_opt + OFF, kStrideB, dst_argb32_opt, \ - kWidth * BPP_C, kWidth, kHeight); \ - for (int i = 0; i < kWidth * BPP_C * kHeight; ++i) { \ - int abs_diff = abs(static_cast(dst_argb32_c[i]) - \ - static_cast(dst_argb32_opt[i])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ - EXPECT_LE(max_diff, DIFF); \ - free_aligned_buffer_page_end(src_y); \ - free_aligned_buffer_page_end(src_u); \ - free_aligned_buffer_page_end(src_v); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_opt); \ - free_aligned_buffer_page_end(dst_argb32_c); \ - free_aligned_buffer_page_end(dst_argb32_opt); \ - } - -#define TESTPLANARTOBD(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, DIFF, FMT_C, BPP_C) \ - TESTPLANARTOBID(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_ - 4, DIFF, _Any, +, 0, FMT_C, \ - BPP_C) \ - TESTPLANARTOBID(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, DIFF, _Unaligned, +, 1, FMT_C, \ - BPP_C) \ - TESTPLANARTOBID(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, DIFF, _Invert, -, 0, FMT_C, BPP_C) \ - TESTPLANARTOBID(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, DIFF, _Opt, +, 0, FMT_C, BPP_C) - -#ifdef LITTLE_ENDIAN_TEST -TESTPLANARTOBD(I420, 2, 2, RGB565, 2, 2, 1, 9, ARGB, 4) -#endif #define TESTPTOB(NAME, UYVYTOI420, UYVYTONV12) \ TEST_F(LibYUVConvertTest, NAME) { \ const int kWidth = benchmark_width_; \ const int kHeight = benchmark_height_; \ \ align_buffer_page_end(orig_uyvy, 4 * SUBSAMPLE(kWidth, 2) * kHeight); \ - align_buffer_page_end(orig_y, kWidth* kHeight); \ + align_buffer_page_end(orig_y, kWidth * kHeight); \ align_buffer_page_end(orig_u, \ SUBSAMPLE(kWidth, 2) * SUBSAMPLE(kHeight, 2)); \ align_buffer_page_end(orig_v, \ SUBSAMPLE(kWidth, 2) * SUBSAMPLE(kHeight, 2)); \ \ - align_buffer_page_end(dst_y_orig, kWidth* kHeight); \ + align_buffer_page_end(dst_y_orig, kWidth * kHeight); \ align_buffer_page_end(dst_uv_orig, \ 2 * SUBSAMPLE(kWidth, 2) * SUBSAMPLE(kHeight, 2)); \ \ - align_buffer_page_end(dst_y, kWidth* kHeight); \ + align_buffer_page_end(dst_y, kWidth * kHeight); \ align_buffer_page_end(dst_uv, \ 2 * SUBSAMPLE(kWidth, 2) * SUBSAMPLE(kHeight, 2)); \ \ @@ -2473,14 +2435,14 @@ TESTPLANARTOBD(I420, 2, 2, RGB565, 2, 2, 1, 9, ARGB, 4) } \ \ for (int i = 0; i < kWidth * kHeight; ++i) { \ - EXPECT_EQ(orig_y[i], dst_y[i]); \ + ASSERT_EQ(orig_y[i], dst_y[i]); \ } \ for (int i = 0; i < kWidth * kHeight; ++i) { \ - EXPECT_EQ(dst_y_orig[i], dst_y[i]); \ + ASSERT_EQ(dst_y_orig[i], dst_y[i]); \ } \ for (int i = 0; i < 2 * SUBSAMPLE(kWidth, 2) * SUBSAMPLE(kHeight, 2); \ ++i) { \ - EXPECT_EQ(dst_uv_orig[i], dst_uv[i]); \ + ASSERT_EQ(dst_uv_orig[i], dst_uv[i]); \ } \ \ free_aligned_buffer_page_end(orig_uyvy); \ @@ -2496,770 +2458,827 @@ TESTPLANARTOBD(I420, 2, 2, RGB565, 2, 2, 1, 9, ARGB, 4) TESTPTOB(TestYUY2ToNV12, YUY2ToI420, YUY2ToNV12) TESTPTOB(TestUYVYToNV12, UYVYToI420, UYVYToNV12) -// Transitive tests. A to B to C is same as A to C. +TEST_F(LibYUVConvertTest, MM21ToYUY2) { + const int kWidth = (benchmark_width_ + 15) & (~15); + const int kHeight = (benchmark_height_ + 31) & (~31); -#define TESTPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - W1280, N, NEG, OFF, FMT_C, BPP_C) \ - TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##_##FMT_C##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = benchmark_height_; \ - const int kStrideB = SUBSAMPLE(kWidth, SUB_B) * BPP_B; \ - const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ - const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ - align_buffer_page_end(src_y, kWidth* kHeight + OFF); \ - align_buffer_page_end(src_u, kSizeUV + OFF); \ - align_buffer_page_end(src_v, kSizeUV + OFF); \ - align_buffer_page_end(dst_argb_b, kStrideB* kHeight + OFF); \ - for (int i = 0; i < kWidth * kHeight; ++i) { \ - src_y[i + OFF] = (fastrand() & 0xff); \ - } \ - for (int i = 0; i < kSizeUV; ++i) { \ - src_u[i + OFF] = (fastrand() & 0xff); \ - src_v[i + OFF] = (fastrand() & 0xff); \ - } \ - memset(dst_argb_b + OFF, 1, kStrideB * kHeight); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_PLANAR##To##FMT_B(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ - src_v + OFF, kStrideUV, dst_argb_b + OFF, \ - kStrideB, kWidth, NEG kHeight); \ - } \ - /* Convert to a 3rd format in 1 step and 2 steps and compare */ \ - const int kStrideC = kWidth * BPP_C; \ - align_buffer_page_end(dst_argb_c, kStrideC* kHeight + OFF); \ - align_buffer_page_end(dst_argb_bc, kStrideC* kHeight + OFF); \ - memset(dst_argb_c + OFF, 2, kStrideC * kHeight); \ - memset(dst_argb_bc + OFF, 3, kStrideC * kHeight); \ - FMT_PLANAR##To##FMT_C(src_y + OFF, kWidth, src_u + OFF, kStrideUV, \ - src_v + OFF, kStrideUV, dst_argb_c + OFF, kStrideC, \ - kWidth, NEG kHeight); \ - /* Convert B to C */ \ - FMT_B##To##FMT_C(dst_argb_b + OFF, kStrideB, dst_argb_bc + OFF, kStrideC, \ - kWidth, kHeight); \ - for (int i = 0; i < kStrideC * kHeight; ++i) { \ - EXPECT_EQ(dst_argb_c[i + OFF], dst_argb_bc[i + OFF]); \ - } \ - free_aligned_buffer_page_end(src_y); \ - free_aligned_buffer_page_end(src_u); \ - free_aligned_buffer_page_end(src_v); \ - free_aligned_buffer_page_end(dst_argb_b); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_bc); \ - } + align_buffer_page_end(orig_y, kWidth * kHeight); + align_buffer_page_end(orig_uv, + 2 * SUBSAMPLE(kWidth, 2) * SUBSAMPLE(kHeight, 2)); -#define TESTPLANARTOE(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - FMT_C, BPP_C) \ - TESTPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - benchmark_width_ - 4, _Any, +, 0, FMT_C, BPP_C) \ - TESTPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - benchmark_width_, _Unaligned, +, 1, FMT_C, BPP_C) \ - TESTPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - benchmark_width_, _Invert, -, 0, FMT_C, BPP_C) \ - TESTPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - benchmark_width_, _Opt, +, 0, FMT_C, BPP_C) + align_buffer_page_end(tmp_y, kWidth * kHeight); + align_buffer_page_end(tmp_u, SUBSAMPLE(kWidth, 2) * SUBSAMPLE(kHeight, 2)); + align_buffer_page_end(tmp_v, SUBSAMPLE(kWidth, 2) * SUBSAMPLE(kHeight, 2)); -TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, ABGR, 4) -TESTPLANARTOE(J420, 2, 2, ARGB, 1, 4, ARGB, 4) -TESTPLANARTOE(J420, 2, 2, ABGR, 1, 4, ARGB, 4) -TESTPLANARTOE(H420, 2, 2, ARGB, 1, 4, ARGB, 4) -TESTPLANARTOE(H420, 2, 2, ABGR, 1, 4, ARGB, 4) -TESTPLANARTOE(I420, 2, 2, BGRA, 1, 4, ARGB, 4) -TESTPLANARTOE(I420, 2, 2, ABGR, 1, 4, ARGB, 4) -TESTPLANARTOE(I420, 2, 2, RGBA, 1, 4, ARGB, 4) -TESTPLANARTOE(I420, 2, 2, RGB24, 1, 3, ARGB, 4) -TESTPLANARTOE(I420, 2, 2, RAW, 1, 3, RGB24, 3) -TESTPLANARTOE(I420, 2, 2, RGB24, 1, 3, RAW, 3) -TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, RAW, 3) -TESTPLANARTOE(I420, 2, 2, RAW, 1, 3, ARGB, 4) -TESTPLANARTOE(H420, 2, 2, RGB24, 1, 3, ARGB, 4) -TESTPLANARTOE(H420, 2, 2, RAW, 1, 3, RGB24, 3) -TESTPLANARTOE(H420, 2, 2, RGB24, 1, 3, RAW, 3) -TESTPLANARTOE(H420, 2, 2, ARGB, 1, 4, RAW, 3) -TESTPLANARTOE(H420, 2, 2, RAW, 1, 3, ARGB, 4) -#ifdef LITTLE_ENDIAN_TEST -TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, RGB565, 2) -TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, ARGB1555, 2) -TESTPLANARTOE(I420, 2, 2, ARGB, 1, 4, ARGB4444, 2) -TESTPLANARTOE(I422, 2, 1, ARGB, 1, 4, RGB565, 2) -#endif -TESTPLANARTOE(J422, 2, 1, ARGB, 1, 4, ARGB, 4) -TESTPLANARTOE(J422, 2, 1, ABGR, 1, 4, ARGB, 4) -TESTPLANARTOE(H422, 2, 1, ARGB, 1, 4, ARGB, 4) -TESTPLANARTOE(H422, 2, 1, ABGR, 1, 4, ARGB, 4) -TESTPLANARTOE(I422, 2, 1, BGRA, 1, 4, ARGB, 4) -TESTPLANARTOE(I422, 2, 1, ABGR, 1, 4, ARGB, 4) -TESTPLANARTOE(I422, 2, 1, RGBA, 1, 4, ARGB, 4) -TESTPLANARTOE(I444, 1, 1, ARGB, 1, 4, ARGB, 4) -TESTPLANARTOE(J444, 1, 1, ARGB, 1, 4, ARGB, 4) -TESTPLANARTOE(I444, 1, 1, ABGR, 1, 4, ARGB, 4) -TESTPLANARTOE(I420, 2, 2, YUY2, 2, 4, ARGB, 4) -TESTPLANARTOE(I420, 2, 2, UYVY, 2, 4, ARGB, 4) -TESTPLANARTOE(I422, 2, 1, YUY2, 2, 4, ARGB, 4) -TESTPLANARTOE(I422, 2, 1, UYVY, 2, 4, ARGB, 4) + align_buffer_page_end(dst_yuyv, 4 * SUBSAMPLE(kWidth, 2) * kHeight); + align_buffer_page_end(golden_yuyv, 4 * SUBSAMPLE(kWidth, 2) * kHeight); -#define TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - W1280, N, NEG, OFF, FMT_C, BPP_C, ATTEN) \ - TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##_##FMT_C##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = benchmark_height_; \ - const int kStrideB = SUBSAMPLE(kWidth, SUB_B) * BPP_B; \ - const int kSizeUV = \ - SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y); \ - align_buffer_page_end(src_y, kWidth* kHeight + OFF); \ - align_buffer_page_end(src_u, kSizeUV + OFF); \ - align_buffer_page_end(src_v, kSizeUV + OFF); \ - align_buffer_page_end(src_a, kWidth* kHeight + OFF); \ - align_buffer_page_end(dst_argb_b, kStrideB* kHeight + OFF); \ - for (int i = 0; i < kWidth * kHeight; ++i) { \ - src_y[i + OFF] = (fastrand() & 0xff); \ - src_a[i + OFF] = (fastrand() & 0xff); \ - } \ - for (int i = 0; i < kSizeUV; ++i) { \ - src_u[i + OFF] = (fastrand() & 0xff); \ - src_v[i + OFF] = (fastrand() & 0xff); \ - } \ - memset(dst_argb_b + OFF, 1, kStrideB * kHeight); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_PLANAR##To##FMT_B( \ - src_y + OFF, kWidth, src_u + OFF, SUBSAMPLE(kWidth, SUBSAMP_X), \ - src_v + OFF, SUBSAMPLE(kWidth, SUBSAMP_X), src_a + OFF, kWidth, \ - dst_argb_b + OFF, kStrideB, kWidth, NEG kHeight, ATTEN); \ - } \ - /* Convert to a 3rd format in 1 step and 2 steps and compare */ \ - const int kStrideC = kWidth * BPP_C; \ - align_buffer_page_end(dst_argb_c, kStrideC* kHeight + OFF); \ - align_buffer_page_end(dst_argb_bc, kStrideC* kHeight + OFF); \ - memset(dst_argb_c + OFF, 2, kStrideC * kHeight); \ - memset(dst_argb_bc + OFF, 3, kStrideC * kHeight); \ - FMT_PLANAR##To##FMT_C( \ - src_y + OFF, kWidth, src_u + OFF, SUBSAMPLE(kWidth, SUBSAMP_X), \ - src_v + OFF, SUBSAMPLE(kWidth, SUBSAMP_X), src_a + OFF, kWidth, \ - dst_argb_c + OFF, kStrideC, kWidth, NEG kHeight, ATTEN); \ - /* Convert B to C */ \ - FMT_B##To##FMT_C(dst_argb_b + OFF, kStrideB, dst_argb_bc + OFF, kStrideC, \ - kWidth, kHeight); \ - for (int i = 0; i < kStrideC * kHeight; ++i) { \ - EXPECT_EQ(dst_argb_c[i + OFF], dst_argb_bc[i + OFF]); \ - } \ - free_aligned_buffer_page_end(src_y); \ - free_aligned_buffer_page_end(src_u); \ - free_aligned_buffer_page_end(src_v); \ - free_aligned_buffer_page_end(src_a); \ - free_aligned_buffer_page_end(dst_argb_b); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_bc); \ - } + MemRandomize(orig_y, kWidth * kHeight); + MemRandomize(orig_uv, 2 * SUBSAMPLE(kWidth, 2) * SUBSAMPLE(kHeight, 2)); -#define TESTQPLANARTOE(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - FMT_C, BPP_C) \ - TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - benchmark_width_ - 4, _Any, +, 0, FMT_C, BPP_C, 0) \ - TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - benchmark_width_, _Unaligned, +, 1, FMT_C, BPP_C, 0) \ - TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - benchmark_width_, _Invert, -, 0, FMT_C, BPP_C, 0) \ - TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - benchmark_width_, _Opt, +, 0, FMT_C, BPP_C, 0) \ - TESTQPLANARTOEI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, SUB_B, BPP_B, \ - benchmark_width_, _Premult, +, 0, FMT_C, BPP_C, 1) + /* Convert MM21 to YUY2 in 2 steps for reference */ + libyuv::MM21ToI420(orig_y, kWidth, orig_uv, 2 * SUBSAMPLE(kWidth, 2), tmp_y, + kWidth, tmp_u, SUBSAMPLE(kWidth, 2), tmp_v, + SUBSAMPLE(kWidth, 2), kWidth, kHeight); + libyuv::I420ToYUY2(tmp_y, kWidth, tmp_u, SUBSAMPLE(kWidth, 2), tmp_v, + SUBSAMPLE(kWidth, 2), golden_yuyv, + 4 * SUBSAMPLE(kWidth, 2), kWidth, kHeight); -TESTQPLANARTOE(I420Alpha, 2, 2, ARGB, 1, 4, ABGR, 4) -TESTQPLANARTOE(I420Alpha, 2, 2, ABGR, 1, 4, ARGB, 4) - -#define TESTPLANETOEI(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, W1280, N, NEG, \ - OFF, FMT_C, BPP_C) \ - TEST_F(LibYUVConvertTest, FMT_A##To##FMT_B##_##FMT_C##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = benchmark_height_; \ - const int kStrideA = SUBSAMPLE(kWidth, SUB_A) * BPP_A; \ - const int kStrideB = SUBSAMPLE(kWidth, SUB_B) * BPP_B; \ - align_buffer_page_end(src_argb_a, kStrideA* kHeight + OFF); \ - align_buffer_page_end(dst_argb_b, kStrideB* kHeight + OFF); \ - MemRandomize(src_argb_a + OFF, kStrideA * kHeight); \ - memset(dst_argb_b + OFF, 1, kStrideB * kHeight); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_A##To##FMT_B(src_argb_a + OFF, kStrideA, dst_argb_b + OFF, kStrideB, \ - kWidth, NEG kHeight); \ - } \ - /* Convert to a 3rd format in 1 step and 2 steps and compare */ \ - const int kStrideC = kWidth * BPP_C; \ - align_buffer_page_end(dst_argb_c, kStrideC* kHeight + OFF); \ - align_buffer_page_end(dst_argb_bc, kStrideC* kHeight + OFF); \ - memset(dst_argb_c + OFF, 2, kStrideC * kHeight); \ - memset(dst_argb_bc + OFF, 3, kStrideC * kHeight); \ - FMT_A##To##FMT_C(src_argb_a + OFF, kStrideA, dst_argb_c + OFF, kStrideC, \ - kWidth, NEG kHeight); \ - /* Convert B to C */ \ - FMT_B##To##FMT_C(dst_argb_b + OFF, kStrideB, dst_argb_bc + OFF, kStrideC, \ - kWidth, kHeight); \ - for (int i = 0; i < kStrideC * kHeight; i += 4) { \ - EXPECT_EQ(dst_argb_c[i + OFF + 0], dst_argb_bc[i + OFF + 0]); \ - EXPECT_EQ(dst_argb_c[i + OFF + 1], dst_argb_bc[i + OFF + 1]); \ - EXPECT_EQ(dst_argb_c[i + OFF + 2], dst_argb_bc[i + OFF + 2]); \ - EXPECT_NEAR(dst_argb_c[i + OFF + 3], dst_argb_bc[i + OFF + 3], 64); \ - } \ - free_aligned_buffer_page_end(src_argb_a); \ - free_aligned_buffer_page_end(dst_argb_b); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_bc); \ - } - -#define TESTPLANETOE(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, FMT_C, BPP_C) \ - TESTPLANETOEI(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, \ - benchmark_width_ - 4, _Any, +, 0, FMT_C, BPP_C) \ - TESTPLANETOEI(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, benchmark_width_, \ - _Unaligned, +, 1, FMT_C, BPP_C) \ - TESTPLANETOEI(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, benchmark_width_, \ - _Invert, -, 0, FMT_C, BPP_C) \ - TESTPLANETOEI(FMT_A, SUB_A, BPP_A, FMT_B, SUB_B, BPP_B, benchmark_width_, \ - _Opt, +, 0, FMT_C, BPP_C) - -// Caveat: Destination needs to be 4 bytes -#ifdef LITTLE_ENDIAN_TEST -TESTPLANETOE(ARGB, 1, 4, AR30, 1, 4, ARGB, 4) -TESTPLANETOE(ABGR, 1, 4, AR30, 1, 4, ABGR, 4) -TESTPLANETOE(AR30, 1, 4, ARGB, 1, 4, ABGR, 4) -TESTPLANETOE(AR30, 1, 4, ABGR, 1, 4, ARGB, 4) -TESTPLANETOE(ARGB, 1, 4, AB30, 1, 4, ARGB, 4) -TESTPLANETOE(ABGR, 1, 4, AB30, 1, 4, ABGR, 4) -TESTPLANETOE(AB30, 1, 4, ARGB, 1, 4, ABGR, 4) -TESTPLANETOE(AB30, 1, 4, ABGR, 1, 4, ARGB, 4) -#endif - -TEST_F(LibYUVConvertTest, RotateWithARGBSource) { - // 2x2 frames - uint32_t src[4]; - uint32_t dst[4]; - // some random input - src[0] = 0x11000000; - src[1] = 0x00450000; - src[2] = 0x00009f00; - src[3] = 0x000000ff; - // zeros on destination - dst[0] = 0x00000000; - dst[1] = 0x00000000; - dst[2] = 0x00000000; - dst[3] = 0x00000000; - - int r = ConvertToARGB(reinterpret_cast(src), - 16, // input size - reinterpret_cast(dst), - 8, // destination stride - 0, // crop_x - 0, // crop_y - 2, // width - 2, // height - 2, // crop width - 2, // crop height - kRotate90, FOURCC_ARGB); - - EXPECT_EQ(r, 0); - // 90 degrees rotation, no conversion - EXPECT_EQ(dst[0], src[2]); - EXPECT_EQ(dst[1], src[0]); - EXPECT_EQ(dst[2], src[3]); - EXPECT_EQ(dst[3], src[1]); -} - -#ifdef HAS_ARGBTOAR30ROW_AVX2 -TEST_F(LibYUVConvertTest, ARGBToAR30Row_Opt) { - // ARGBToAR30Row_AVX2 expects a multiple of 8 pixels. - const int kPixels = (benchmark_width_ * benchmark_height_ + 7) & ~7; - align_buffer_page_end(src, kPixels * 4); - align_buffer_page_end(dst_opt, kPixels * 4); - align_buffer_page_end(dst_c, kPixels * 4); - MemRandomize(src, kPixels * 4); - memset(dst_opt, 0, kPixels * 4); - memset(dst_c, 1, kPixels * 4); - - ARGBToAR30Row_C(src, dst_c, kPixels); - - int has_avx2 = TestCpuFlag(kCpuHasAVX2); - int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); + /* Convert to NV12 */ for (int i = 0; i < benchmark_iterations_; ++i) { - if (has_avx2) { - ARGBToAR30Row_AVX2(src, dst_opt, kPixels); - } else if (has_ssse3) { - ARGBToAR30Row_SSSE3(src, dst_opt, kPixels); - } else { - ARGBToAR30Row_C(src, dst_opt, kPixels); - } - } - for (int i = 0; i < kPixels * 4; ++i) { - EXPECT_EQ(dst_opt[i], dst_c[i]); + libyuv::MM21ToYUY2(orig_y, kWidth, orig_uv, 2 * SUBSAMPLE(kWidth, 2), + dst_yuyv, 4 * SUBSAMPLE(kWidth, 2), kWidth, kHeight); } - free_aligned_buffer_page_end(src); - free_aligned_buffer_page_end(dst_opt); - free_aligned_buffer_page_end(dst_c); -} -#endif // HAS_ARGBTOAR30ROW_AVX2 - -#ifdef HAS_ABGRTOAR30ROW_AVX2 -TEST_F(LibYUVConvertTest, ABGRToAR30Row_Opt) { - // ABGRToAR30Row_AVX2 expects a multiple of 8 pixels. - const int kPixels = (benchmark_width_ * benchmark_height_ + 7) & ~7; - align_buffer_page_end(src, kPixels * 4); - align_buffer_page_end(dst_opt, kPixels * 4); - align_buffer_page_end(dst_c, kPixels * 4); - MemRandomize(src, kPixels * 4); - memset(dst_opt, 0, kPixels * 4); - memset(dst_c, 1, kPixels * 4); - - ABGRToAR30Row_C(src, dst_c, kPixels); - - int has_avx2 = TestCpuFlag(kCpuHasAVX2); - int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); - for (int i = 0; i < benchmark_iterations_; ++i) { - if (has_avx2) { - ABGRToAR30Row_AVX2(src, dst_opt, kPixels); - } else if (has_ssse3) { - ABGRToAR30Row_SSSE3(src, dst_opt, kPixels); - } else { - ABGRToAR30Row_C(src, dst_opt, kPixels); - } - } - for (int i = 0; i < kPixels * 4; ++i) { - EXPECT_EQ(dst_opt[i], dst_c[i]); + for (int i = 0; i < 4 * SUBSAMPLE(kWidth, 2) * kHeight; ++i) { + ASSERT_EQ(dst_yuyv[i], golden_yuyv[i]); } - free_aligned_buffer_page_end(src); - free_aligned_buffer_page_end(dst_opt); - free_aligned_buffer_page_end(dst_c); -} -#endif // HAS_ABGRTOAR30ROW_AVX2 - -// TODO(fbarchard): Fix clamping issue affected by U channel. -#define TESTPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, \ - ALIGN, YALIGN, W1280, DIFF, N, NEG, SOFF, DOFF) \ - TEST_F(LibYUVConvertTest, FMT_PLANAR##To##FMT_B##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ - const int kHeight = ALIGNINT(benchmark_height_, YALIGN); \ - const int kStrideB = ALIGNINT(kWidth * BPP_B, ALIGN); \ - const int kStrideUV = SUBSAMPLE(kWidth, SUBSAMP_X); \ - const int kSizeUV = kStrideUV * SUBSAMPLE(kHeight, SUBSAMP_Y); \ - const int kBpc = 2; \ - align_buffer_page_end(src_y, kWidth* kHeight* kBpc + SOFF); \ - align_buffer_page_end(src_u, kSizeUV* kBpc + SOFF); \ - align_buffer_page_end(src_v, kSizeUV* kBpc + SOFF); \ - align_buffer_page_end(dst_argb_c, kStrideB* kHeight + DOFF); \ - align_buffer_page_end(dst_argb_opt, kStrideB* kHeight + DOFF); \ - for (int i = 0; i < kWidth * kHeight; ++i) { \ - reinterpret_cast(src_y + SOFF)[i] = (fastrand() & 0x3ff); \ - } \ - for (int i = 0; i < kSizeUV; ++i) { \ - reinterpret_cast(src_u + SOFF)[i] = (fastrand() & 0x3ff); \ - reinterpret_cast(src_v + SOFF)[i] = (fastrand() & 0x3ff); \ - } \ - memset(dst_argb_c + DOFF, 1, kStrideB * kHeight); \ - memset(dst_argb_opt + DOFF, 101, kStrideB * kHeight); \ - MaskCpuFlags(disable_cpu_flags_); \ - FMT_PLANAR##To##FMT_B( \ - reinterpret_cast(src_y + SOFF), kWidth, \ - reinterpret_cast(src_u + SOFF), kStrideUV, \ - reinterpret_cast(src_v + SOFF), kStrideUV, \ - dst_argb_c + DOFF, kStrideB, kWidth, NEG kHeight); \ - MaskCpuFlags(benchmark_cpu_info_); \ - for (int i = 0; i < benchmark_iterations_; ++i) { \ - FMT_PLANAR##To##FMT_B( \ - reinterpret_cast(src_y + SOFF), kWidth, \ - reinterpret_cast(src_u + SOFF), kStrideUV, \ - reinterpret_cast(src_v + SOFF), kStrideUV, \ - dst_argb_opt + DOFF, kStrideB, kWidth, NEG kHeight); \ - } \ - int max_diff = 0; \ - for (int i = 0; i < kWidth * BPP_B * kHeight; ++i) { \ - int abs_diff = abs(static_cast(dst_argb_c[i + DOFF]) - \ - static_cast(dst_argb_opt[i + DOFF])); \ - if (abs_diff > max_diff) { \ - max_diff = abs_diff; \ - } \ - } \ - EXPECT_LE(max_diff, DIFF); \ - free_aligned_buffer_page_end(src_y); \ - free_aligned_buffer_page_end(src_u); \ - free_aligned_buffer_page_end(src_v); \ - free_aligned_buffer_page_end(dst_argb_c); \ - free_aligned_buffer_page_end(dst_argb_opt); \ - } - -#define TESTPLANAR16TOB(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, DIFF) \ - TESTPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_ - 4, DIFF, _Any, +, 0, 0) \ - TESTPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, DIFF, _Unaligned, +, 1, 1) \ - TESTPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, DIFF, _Invert, -, 0, 0) \ - TESTPLANAR16TOBI(FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, FMT_B, BPP_B, ALIGN, \ - YALIGN, benchmark_width_, DIFF, _Opt, +, 0, 0) - -TESTPLANAR16TOB(I010, 2, 2, ARGB, 4, 4, 1, 2) -TESTPLANAR16TOB(I010, 2, 2, ABGR, 4, 4, 1, 2) -#ifdef LITTLE_ENDIAN_TEST -TESTPLANAR16TOB(I010, 2, 2, AR30, 4, 4, 1, 2) -TESTPLANAR16TOB(I010, 2, 2, AB30, 4, 4, 1, 2) -#endif -TESTPLANAR16TOB(H010, 2, 2, ARGB, 4, 4, 1, 2) -TESTPLANAR16TOB(H010, 2, 2, ABGR, 4, 4, 1, 2) -#ifdef LITTLE_ENDIAN_TEST -TESTPLANAR16TOB(H010, 2, 2, AR30, 4, 4, 1, 2) -TESTPLANAR16TOB(H010, 2, 2, AB30, 4, 4, 1, 2) -#endif - -static int Clamp(int y) { - if (y < 0) { - y = 0; - } - if (y > 255) { - y = 255; - } - return y; + free_aligned_buffer_page_end(orig_y); + free_aligned_buffer_page_end(orig_uv); + free_aligned_buffer_page_end(tmp_y); + free_aligned_buffer_page_end(tmp_u); + free_aligned_buffer_page_end(tmp_v); + free_aligned_buffer_page_end(dst_yuyv); + free_aligned_buffer_page_end(golden_yuyv); } -static int Clamp10(int y) { - if (y < 0) { - y = 0; - } - if (y > 1023) { - y = 1023; - } - return y; -} - -// Test 8 bit YUV to 8 bit RGB -TEST_F(LibYUVConvertTest, TestH420ToARGB) { +// Test RGB24 to J420 is exact +TEST_F(LibYUVConvertTest, TestRGB24ToJ420) { const int kSize = 256; - int histogram_b[256]; - int histogram_g[256]; - int histogram_r[256]; - memset(histogram_b, 0, sizeof(histogram_b)); - memset(histogram_g, 0, sizeof(histogram_g)); - memset(histogram_r, 0, sizeof(histogram_r)); - align_buffer_page_end(orig_yuv, kSize + kSize / 2 * 2); - align_buffer_page_end(argb_pixels, kSize * 4); - uint8_t* orig_y = orig_yuv; - uint8_t* orig_u = orig_y + kSize; - uint8_t* orig_v = orig_u + kSize / 2; + align_buffer_page_end(orig_rgb24, kSize * 3 * 2); // 2 rows of RGB24 + align_buffer_page_end(dest_j420, kSize * 3 / 2 * 2); + int iterations256 = (benchmark_width_ * benchmark_height_ + (kSize * 2 - 1)) / + (kSize * 2) * benchmark_iterations_; - // Test grey scale - for (int i = 0; i < kSize; ++i) { - orig_y[i] = i; - } - for (int i = 0; i < kSize / 2; ++i) { - orig_u[i] = 128; // 128 is 0. - orig_v[i] = 128; - } - - H420ToARGB(orig_y, 0, orig_u, 0, orig_v, 0, argb_pixels, 0, kSize, 1); - - for (int i = 0; i < kSize; ++i) { - int b = argb_pixels[i * 4 + 0]; - int g = argb_pixels[i * 4 + 1]; - int r = argb_pixels[i * 4 + 2]; - int a = argb_pixels[i * 4 + 3]; - ++histogram_b[b]; - ++histogram_g[g]; - ++histogram_r[r]; - int expected_y = Clamp(static_cast((i - 16) * 1.164f)); - EXPECT_NEAR(b, expected_y, 1); - EXPECT_NEAR(g, expected_y, 1); - EXPECT_NEAR(r, expected_y, 1); - EXPECT_EQ(a, 255); - } - - int count_b = 0; - int count_g = 0; - int count_r = 0; - for (int i = 0; i < kSize; ++i) { - if (histogram_b[i]) { - ++count_b; - } - if (histogram_g[i]) { - ++count_g; - } - if (histogram_r[i]) { - ++count_r; - } - } - printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); - - free_aligned_buffer_page_end(orig_yuv); - free_aligned_buffer_page_end(argb_pixels); -} - -// Test 10 bit YUV to 8 bit RGB -TEST_F(LibYUVConvertTest, TestH010ToARGB) { - const int kSize = 1024; - int histogram_b[1024]; - int histogram_g[1024]; - int histogram_r[1024]; - memset(histogram_b, 0, sizeof(histogram_b)); - memset(histogram_g, 0, sizeof(histogram_g)); - memset(histogram_r, 0, sizeof(histogram_r)); - align_buffer_page_end(orig_yuv, kSize * 2 + kSize / 2 * 2 * 2); - align_buffer_page_end(argb_pixels, kSize * 4); - uint16_t* orig_y = reinterpret_cast(orig_yuv); - uint16_t* orig_u = orig_y + kSize; - uint16_t* orig_v = orig_u + kSize / 2; - - // Test grey scale - for (int i = 0; i < kSize; ++i) { - orig_y[i] = i; - } - for (int i = 0; i < kSize / 2; ++i) { - orig_u[i] = 512; // 512 is 0. - orig_v[i] = 512; - } - - H010ToARGB(orig_y, 0, orig_u, 0, orig_v, 0, argb_pixels, 0, kSize, 1); - - for (int i = 0; i < kSize; ++i) { - int b = argb_pixels[i * 4 + 0]; - int g = argb_pixels[i * 4 + 1]; - int r = argb_pixels[i * 4 + 2]; - int a = argb_pixels[i * 4 + 3]; - ++histogram_b[b]; - ++histogram_g[g]; - ++histogram_r[r]; - int expected_y = Clamp(static_cast((i - 64) * 1.164f / 4)); - EXPECT_NEAR(b, expected_y, 1); - EXPECT_NEAR(g, expected_y, 1); - EXPECT_NEAR(r, expected_y, 1); - EXPECT_EQ(a, 255); - } - - int count_b = 0; - int count_g = 0; - int count_r = 0; - for (int i = 0; i < kSize; ++i) { - if (histogram_b[i]) { - ++count_b; - } - if (histogram_g[i]) { - ++count_g; - } - if (histogram_r[i]) { - ++count_r; - } - } - printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); - - free_aligned_buffer_page_end(orig_yuv); - free_aligned_buffer_page_end(argb_pixels); -} - -// Test 10 bit YUV to 10 bit RGB -// Caveat: Result is near due to float rounding in expected -// result. -TEST_F(LibYUVConvertTest, TestH010ToAR30) { - const int kSize = 1024; - int histogram_b[1024]; - int histogram_g[1024]; - int histogram_r[1024]; - memset(histogram_b, 0, sizeof(histogram_b)); - memset(histogram_g, 0, sizeof(histogram_g)); - memset(histogram_r, 0, sizeof(histogram_r)); - - align_buffer_page_end(orig_yuv, kSize * 2 + kSize / 2 * 2 * 2); - align_buffer_page_end(ar30_pixels, kSize * 4); - uint16_t* orig_y = reinterpret_cast(orig_yuv); - uint16_t* orig_u = orig_y + kSize; - uint16_t* orig_v = orig_u + kSize / 2; - - // Test grey scale - for (int i = 0; i < kSize; ++i) { - orig_y[i] = i; - } - for (int i = 0; i < kSize / 2; ++i) { - orig_u[i] = 512; // 512 is 0. - orig_v[i] = 512; - } - - H010ToAR30(orig_y, 0, orig_u, 0, orig_v, 0, ar30_pixels, 0, kSize, 1); - - for (int i = 0; i < kSize; ++i) { - int b10 = reinterpret_cast(ar30_pixels)[i] & 1023; - int g10 = (reinterpret_cast(ar30_pixels)[i] >> 10) & 1023; - int r10 = (reinterpret_cast(ar30_pixels)[i] >> 20) & 1023; - int a2 = (reinterpret_cast(ar30_pixels)[i] >> 30) & 3; - ++histogram_b[b10]; - ++histogram_g[g10]; - ++histogram_r[r10]; - int expected_y = Clamp10(static_cast((i - 64) * 1.164f)); - EXPECT_NEAR(b10, expected_y, 4); - EXPECT_NEAR(g10, expected_y, 4); - EXPECT_NEAR(r10, expected_y, 4); - EXPECT_EQ(a2, 3); - } - - int count_b = 0; - int count_g = 0; - int count_r = 0; - for (int i = 0; i < kSize; ++i) { - if (histogram_b[i]) { - ++count_b; - } - if (histogram_g[i]) { - ++count_g; - } - if (histogram_r[i]) { - ++count_r; - } - } - printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); - - free_aligned_buffer_page_end(orig_yuv); - free_aligned_buffer_page_end(ar30_pixels); -} - -// Test 10 bit YUV to 10 bit RGB -// Caveat: Result is near due to float rounding in expected -// result. -TEST_F(LibYUVConvertTest, TestH010ToAB30) { - const int kSize = 1024; - int histogram_b[1024]; - int histogram_g[1024]; - int histogram_r[1024]; - memset(histogram_b, 0, sizeof(histogram_b)); - memset(histogram_g, 0, sizeof(histogram_g)); - memset(histogram_r, 0, sizeof(histogram_r)); - - align_buffer_page_end(orig_yuv, kSize * 2 + kSize / 2 * 2 * 2); - align_buffer_page_end(ab30_pixels, kSize * 4); - uint16_t* orig_y = reinterpret_cast(orig_yuv); - uint16_t* orig_u = orig_y + kSize; - uint16_t* orig_v = orig_u + kSize / 2; - - // Test grey scale - for (int i = 0; i < kSize; ++i) { - orig_y[i] = i; - } - for (int i = 0; i < kSize / 2; ++i) { - orig_u[i] = 512; // 512 is 0. - orig_v[i] = 512; - } - - H010ToAB30(orig_y, 0, orig_u, 0, orig_v, 0, ab30_pixels, 0, kSize, 1); - - for (int i = 0; i < kSize; ++i) { - int r10 = reinterpret_cast(ab30_pixels)[i] & 1023; - int g10 = (reinterpret_cast(ab30_pixels)[i] >> 10) & 1023; - int b10 = (reinterpret_cast(ab30_pixels)[i] >> 20) & 1023; - int a2 = (reinterpret_cast(ab30_pixels)[i] >> 30) & 3; - ++histogram_b[b10]; - ++histogram_g[g10]; - ++histogram_r[r10]; - int expected_y = Clamp10(static_cast((i - 64) * 1.164f)); - EXPECT_NEAR(b10, expected_y, 4); - EXPECT_NEAR(g10, expected_y, 4); - EXPECT_NEAR(r10, expected_y, 4); - EXPECT_EQ(a2, 3); - } - - int count_b = 0; - int count_g = 0; - int count_r = 0; - for (int i = 0; i < kSize; ++i) { - if (histogram_b[i]) { - ++count_b; - } - if (histogram_g[i]) { - ++count_g; - } - if (histogram_r[i]) { - ++count_r; - } - } - printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); - - free_aligned_buffer_page_end(orig_yuv); - free_aligned_buffer_page_end(ab30_pixels); -} - -// Test 8 bit YUV to 10 bit RGB -TEST_F(LibYUVConvertTest, TestH420ToAR30) { - const int kSize = 256; - const int kHistSize = 1024; - int histogram_b[kHistSize]; - int histogram_g[kHistSize]; - int histogram_r[kHistSize]; - memset(histogram_b, 0, sizeof(histogram_b)); - memset(histogram_g, 0, sizeof(histogram_g)); - memset(histogram_r, 0, sizeof(histogram_r)); - align_buffer_page_end(orig_yuv, kSize + kSize / 2 * 2); - align_buffer_page_end(ar30_pixels, kSize * 4); - uint8_t* orig_y = orig_yuv; - uint8_t* orig_u = orig_y + kSize; - uint8_t* orig_v = orig_u + kSize / 2; - - // Test grey scale - for (int i = 0; i < kSize; ++i) { - orig_y[i] = i; - } - for (int i = 0; i < kSize / 2; ++i) { - orig_u[i] = 128; // 128 is 0. - orig_v[i] = 128; - } - - H420ToAR30(orig_y, 0, orig_u, 0, orig_v, 0, ar30_pixels, 0, kSize, 1); - - for (int i = 0; i < kSize; ++i) { - int b10 = reinterpret_cast(ar30_pixels)[i] & 1023; - int g10 = (reinterpret_cast(ar30_pixels)[i] >> 10) & 1023; - int r10 = (reinterpret_cast(ar30_pixels)[i] >> 20) & 1023; - int a2 = (reinterpret_cast(ar30_pixels)[i] >> 30) & 3; - ++histogram_b[b10]; - ++histogram_g[g10]; - ++histogram_r[r10]; - int expected_y = Clamp10(static_cast((i - 16) * 1.164f * 4.f)); - EXPECT_NEAR(b10, expected_y, 4); - EXPECT_NEAR(g10, expected_y, 4); - EXPECT_NEAR(r10, expected_y, 4); - EXPECT_EQ(a2, 3); - } - - int count_b = 0; - int count_g = 0; - int count_r = 0; - for (int i = 0; i < kHistSize; ++i) { - if (histogram_b[i]) { - ++count_b; - } - if (histogram_g[i]) { - ++count_g; - } - if (histogram_r[i]) { - ++count_r; - } - } - printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); - - free_aligned_buffer_page_end(orig_yuv); - free_aligned_buffer_page_end(ar30_pixels); -} - -// Test RGB24 to ARGB and back to RGB24 -TEST_F(LibYUVConvertTest, TestARGBToRGB24) { - const int kSize = 256; - align_buffer_page_end(orig_rgb24, kSize * 3); - align_buffer_page_end(argb_pixels, kSize * 4); - align_buffer_page_end(dest_rgb24, kSize * 3); - - // Test grey scale - for (int i = 0; i < kSize * 3; ++i) { + for (int i = 0; i < kSize * 3 * 2; ++i) { orig_rgb24[i] = i; } - RGB24ToARGB(orig_rgb24, 0, argb_pixels, 0, kSize, 1); - ARGBToRGB24(argb_pixels, 0, dest_rgb24, 0, kSize, 1); - - for (int i = 0; i < kSize * 3; ++i) { - EXPECT_EQ(orig_rgb24[i], dest_rgb24[i]); + for (int i = 0; i < iterations256; ++i) { + RGB24ToJ420(orig_rgb24, kSize * 3, dest_j420, kSize, // Y plane + dest_j420 + kSize * 2, kSize / 2, // U plane + dest_j420 + kSize * 5 / 2, kSize / 2, // V plane + kSize, 2); } + uint32_t checksum = HashDjb2(dest_j420, kSize * 3 / 2 * 2, 5381); + ASSERT_EQ(223551344u, checksum); + free_aligned_buffer_page_end(orig_rgb24); - free_aligned_buffer_page_end(argb_pixels); - free_aligned_buffer_page_end(dest_rgb24); + free_aligned_buffer_page_end(dest_j420); } +// Test RGB24 to I420 is exact +TEST_F(LibYUVConvertTest, TestRGB24ToI420) { + const int kSize = 256; + align_buffer_page_end(orig_rgb24, kSize * 3 * 2); // 2 rows of RGB24 + align_buffer_page_end(dest_i420, kSize * 3 / 2 * 2); + int iterations256 = (benchmark_width_ * benchmark_height_ + (kSize * 2 - 1)) / + (kSize * 2) * benchmark_iterations_; + + for (int i = 0; i < kSize * 3 * 2; ++i) { + orig_rgb24[i] = i; + } + + for (int i = 0; i < iterations256; ++i) { + RGB24ToI420(orig_rgb24, kSize * 3, dest_i420, kSize, // Y plane + dest_i420 + kSize * 2, kSize / 2, // U plane + dest_i420 + kSize * 5 / 2, kSize / 2, // V plane + kSize, 2); + } + + uint32_t checksum = HashDjb2(dest_i420, kSize * 3 / 2 * 2, 5381); + ASSERT_EQ(4197774805u, checksum); + + free_aligned_buffer_page_end(orig_rgb24); + free_aligned_buffer_page_end(dest_i420); +} + +TEST_F(LibYUVConvertTest, TestJ420ToI420) { + const uint8_t src_y[12] = {0, 0, 128, 128, 255, 255, + 0, 0, 128, 128, 255, 255}; + const uint8_t src_u[3] = {0, 128, 255}; + const uint8_t src_v[3] = {0, 128, 255}; + uint8_t dst_y[12]; + uint8_t dst_u[3]; + uint8_t dst_v[3]; + ASSERT_EQ(J420ToI420(src_y, 6, src_u, 3, src_v, 3, dst_y, 6, dst_u, 3, dst_v, + 3, 6, 2), + 0); + ASSERT_EQ(dst_y[0], 16); + ASSERT_EQ(dst_y[2], 126); + ASSERT_EQ(dst_y[4], 235); + ASSERT_EQ(dst_u[0], 16); + ASSERT_EQ(dst_u[1], 128); + ASSERT_EQ(dst_u[2], 240); + ASSERT_EQ(dst_v[0], 16); + ASSERT_EQ(dst_v[1], 128); + ASSERT_EQ(dst_v[2], 240); +} + +TEST_F(LibYUVConvertTest, TestABGRToI420Matrix) { + const int kWidth = 16; + const int kHeight = 16; + align_buffer_page_end(src_abgr, kWidth * kHeight * 4); + align_buffer_page_end(dst_y, kWidth * kHeight); + align_buffer_page_end(dst_u, kWidth / 2 * kHeight / 2); + align_buffer_page_end(dst_v, kWidth / 2 * kHeight / 2); + + MemRandomize(src_abgr, kWidth * kHeight * 4); + + // BT.601 + ARGBToI420Matrix(src_abgr, kWidth * 4, dst_y, kWidth, dst_u, kWidth / 2, + dst_v, kWidth / 2, &kAbgrI601Constants, kWidth, kHeight); + // Verify against non-matrix version + align_buffer_page_end(ref_y, kWidth * kHeight); + align_buffer_page_end(ref_u, kWidth / 2 * kHeight / 2); + align_buffer_page_end(ref_v, kWidth / 2 * kHeight / 2); + ABGRToI420(src_abgr, kWidth * 4, ref_y, kWidth, ref_u, kWidth / 2, ref_v, + kWidth / 2, kWidth, kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth / 2 * kHeight / 2; ++i) { + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + + // JPEG + ARGBToI420Matrix(src_abgr, kWidth * 4, dst_y, kWidth, dst_u, kWidth / 2, + dst_v, kWidth / 2, &kAbgrJPEGConstants, kWidth, kHeight); + // Verify against non-matrix version + ABGRToJ420(src_abgr, kWidth * 4, ref_y, kWidth, ref_u, kWidth / 2, ref_v, + kWidth / 2, kWidth, kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth / 2 * kHeight / 2; ++i) { + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + + free_aligned_buffer_page_end(src_abgr); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_u); + free_aligned_buffer_page_end(dst_v); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_u); + free_aligned_buffer_page_end(ref_v); +} + +TEST_F(LibYUVConvertTest, TestRAWToI420) { + const int kWidth = 16; + const int kHeight = 16; + align_buffer_page_end(src_raw, kWidth * kHeight * 3); + align_buffer_page_end(dst_y, kWidth * kHeight); + align_buffer_page_end(dst_u, kWidth / 2 * kHeight / 2); + align_buffer_page_end(dst_v, kWidth / 2 * kHeight / 2); + align_buffer_page_end(src_argb, kWidth * kHeight * 4); + align_buffer_page_end(ref_y, kWidth * kHeight); + align_buffer_page_end(ref_u, kWidth / 2 * kHeight / 2); + align_buffer_page_end(ref_v, kWidth / 2 * kHeight / 2); + + MemRandomize(src_raw, kWidth * kHeight * 3); + + RAWToI420(src_raw, kWidth * 3, dst_y, kWidth, dst_u, kWidth / 2, dst_v, + kWidth / 2, kWidth, kHeight); + + // Verify against RAWToARGB + ARGBToI420 + RAWToARGB(src_raw, kWidth * 3, src_argb, kWidth * 4, kWidth, kHeight); + ARGBToI420(src_argb, kWidth * 4, ref_y, kWidth, ref_u, kWidth / 2, ref_v, + kWidth / 2, kWidth, kHeight); + + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth / 2 * kHeight / 2; ++i) { + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + + free_aligned_buffer_page_end(src_raw); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_u); + free_aligned_buffer_page_end(dst_v); + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_u); + free_aligned_buffer_page_end(ref_v); +} + +TEST_F(LibYUVConvertTest, TestRAWToI444) { + const int kWidth = 16; + const int kHeight = 16; + align_buffer_page_end(src_raw, kWidth * kHeight * 3); + align_buffer_page_end(dst_y, kWidth * kHeight); + align_buffer_page_end(dst_u, kWidth * kHeight); + align_buffer_page_end(dst_v, kWidth * kHeight); + align_buffer_page_end(src_argb, kWidth * kHeight * 4); + align_buffer_page_end(ref_y, kWidth * kHeight); + align_buffer_page_end(ref_u, kWidth * kHeight); + align_buffer_page_end(ref_v, kWidth * kHeight); + + MemRandomize(src_raw, kWidth * kHeight * 3); + + RAWToI444(src_raw, kWidth * 3, dst_y, kWidth, dst_u, kWidth, dst_v, kWidth, + kWidth, kHeight); + + // Verify against RAWToARGB + ARGBToI444 + RAWToARGB(src_raw, kWidth * 3, src_argb, kWidth * 4, kWidth, kHeight); + ARGBToI444(src_argb, kWidth * 4, ref_y, kWidth, ref_u, kWidth, ref_v, kWidth, + kWidth, kHeight); + + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + + free_aligned_buffer_page_end(src_raw); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_u); + free_aligned_buffer_page_end(dst_v); + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_u); + free_aligned_buffer_page_end(ref_v); +} + +TEST_F(LibYUVConvertTest, TestRAWToJ444) { + const int kWidth = 16; + const int kHeight = 16; + align_buffer_page_end(src_raw, kWidth * kHeight * 3); + align_buffer_page_end(dst_y, kWidth * kHeight); + align_buffer_page_end(dst_u, kWidth * kHeight); + align_buffer_page_end(dst_v, kWidth * kHeight); + align_buffer_page_end(src_argb, kWidth * kHeight * 4); + align_buffer_page_end(ref_y, kWidth * kHeight); + align_buffer_page_end(ref_u, kWidth * kHeight); + align_buffer_page_end(ref_v, kWidth * kHeight); + + MemRandomize(src_raw, kWidth * kHeight * 3); + + RAWToJ444(src_raw, kWidth * 3, dst_y, kWidth, dst_u, kWidth, dst_v, kWidth, + kWidth, kHeight); + + // Verify against RAWToARGB + ARGBToJ444 + RAWToARGB(src_raw, kWidth * 3, src_argb, kWidth * 4, kWidth, kHeight); + ARGBToJ444(src_argb, kWidth * 4, ref_y, kWidth, ref_u, kWidth, ref_v, kWidth, + kWidth, kHeight); + + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + + free_aligned_buffer_page_end(src_raw); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_u); + free_aligned_buffer_page_end(dst_v); + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_u); + free_aligned_buffer_page_end(ref_v); +} + +TEST_F(LibYUVConvertTest, TestRAWToNV21) { + const int kWidth = 16; + const int kHeight = 16; + align_buffer_page_end(src_raw, kWidth * kHeight * 3); + align_buffer_page_end(dst_y, kWidth * kHeight); + align_buffer_page_end(dst_vu, kWidth * kHeight / 2); + align_buffer_page_end(ref_y, kWidth * kHeight); + align_buffer_page_end(ref_u, kWidth / 2 * kHeight / 2); + align_buffer_page_end(ref_v, kWidth / 2 * kHeight / 2); + align_buffer_page_end(ref_vu, kWidth * kHeight / 2); + + MemRandomize(src_raw, kWidth * kHeight * 3); + + RAWToNV21(src_raw, kWidth * 3, dst_y, kWidth, dst_vu, kWidth, kWidth, + kHeight); + + // Verify against RAWToI420 + interleaving V and U + RAWToI420(src_raw, kWidth * 3, ref_y, kWidth, ref_u, kWidth / 2, ref_v, + kWidth / 2, kWidth, kHeight); + for (int i = 0; i < kWidth / 2 * kHeight / 2; ++i) { + ref_vu[i * 2] = ref_v[i]; + ref_vu[i * 2 + 1] = ref_u[i]; + } + + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth * kHeight / 2; ++i) { + ASSERT_EQ(dst_vu[i], ref_vu[i]); + } + + free_aligned_buffer_page_end(src_raw); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_vu); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_u); + free_aligned_buffer_page_end(ref_v); + free_aligned_buffer_page_end(ref_vu); +} + +TEST_F(LibYUVConvertTest, TestRAWToJNV21) { + const int kWidth = 16; + const int kHeight = 16; + align_buffer_page_end(src_raw, kWidth * kHeight * 3); + align_buffer_page_end(dst_y, kWidth * kHeight); + align_buffer_page_end(dst_vu, kWidth * kHeight / 2); + align_buffer_page_end(ref_y, kWidth * kHeight); + align_buffer_page_end(ref_u, kWidth / 2 * kHeight / 2); + align_buffer_page_end(ref_v, kWidth / 2 * kHeight / 2); + align_buffer_page_end(ref_vu, kWidth * kHeight / 2); + + MemRandomize(src_raw, kWidth * kHeight * 3); + + RAWToJNV21(src_raw, kWidth * 3, dst_y, kWidth, dst_vu, kWidth, kWidth, + kHeight); + + // Verify against RAWToJ420 + interleaving V and U + RAWToJ420(src_raw, kWidth * 3, ref_y, kWidth, ref_u, kWidth / 2, ref_v, + kWidth / 2, kWidth, kHeight); + for (int i = 0; i < kWidth / 2 * kHeight / 2; ++i) { + ref_vu[i * 2] = ref_v[i]; + ref_vu[i * 2 + 1] = ref_u[i]; + } + + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth * kHeight / 2; ++i) { + ASSERT_EQ(dst_vu[i], ref_vu[i]); + } + + free_aligned_buffer_page_end(src_raw); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_vu); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_u); + free_aligned_buffer_page_end(ref_v); + free_aligned_buffer_page_end(ref_vu); +} + +TEST_F(LibYUVConvertTest, TestRGB24ToNV12) { + const int kWidth = 16; + const int kHeight = 16; + align_buffer_page_end(src_rgb24, kWidth * kHeight * 3); + align_buffer_page_end(dst_y, kWidth * kHeight); + align_buffer_page_end(dst_uv, kWidth * kHeight / 2); + align_buffer_page_end(ref_y, kWidth * kHeight); + align_buffer_page_end(ref_u, kWidth / 2 * kHeight / 2); + align_buffer_page_end(ref_v, kWidth / 2 * kHeight / 2); + align_buffer_page_end(ref_uv, kWidth * kHeight / 2); + + MemRandomize(src_rgb24, kWidth * kHeight * 3); + + RGB24ToNV12(src_rgb24, kWidth * 3, dst_y, kWidth, dst_uv, kWidth, kWidth, + kHeight); + + // Verify against RGB24ToI420 + interleaving U and V + RGB24ToI420(src_rgb24, kWidth * 3, ref_y, kWidth, ref_u, kWidth / 2, ref_v, + kWidth / 2, kWidth, kHeight); + for (int i = 0; i < kWidth / 2 * kHeight / 2; ++i) { + ref_uv[i * 2] = ref_u[i]; + ref_uv[i * 2 + 1] = ref_v[i]; + } + + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth * kHeight / 2; ++i) { + ASSERT_EQ(dst_uv[i], ref_uv[i]); + } + + free_aligned_buffer_page_end(src_rgb24); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_uv); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_u); + free_aligned_buffer_page_end(ref_v); + free_aligned_buffer_page_end(ref_uv); +} + +TEST_F(LibYUVConvertTest, TestABGRToNV12Matrix) { + const int kWidth = 16; + const int kHeight = 16; + align_buffer_page_end(src_abgr, kWidth * kHeight * 4); + align_buffer_page_end(dst_y, kWidth * kHeight); + align_buffer_page_end(dst_uv, kWidth * kHeight / 2); + + MemRandomize(src_abgr, kWidth * kHeight * 4); + + // BT.601 + ARGBToNV12Matrix(src_abgr, kWidth * 4, dst_y, kWidth, dst_uv, kWidth, + &kAbgrI601Constants, kWidth, kHeight); + // Verify against non-matrix version + align_buffer_page_end(ref_y, kWidth * kHeight); + align_buffer_page_end(ref_uv, kWidth * kHeight / 2); + ABGRToNV12(src_abgr, kWidth * 4, ref_y, kWidth, ref_uv, kWidth, kWidth, + kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth * kHeight / 2; ++i) { + ASSERT_EQ(dst_uv[i], ref_uv[i]); + } + + free_aligned_buffer_page_end(src_abgr); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_uv); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_uv); +} + +TEST_F(LibYUVConvertTest, TestARGBToI420Matrix) { + const int kWidth = 16; + const int kHeight = 16; + align_buffer_page_end(src_argb, kWidth * kHeight * 4); + align_buffer_page_end(dst_y, kWidth * kHeight); + align_buffer_page_end(dst_u, kWidth / 2 * kHeight / 2); + align_buffer_page_end(dst_v, kWidth / 2 * kHeight / 2); + + MemRandomize(src_argb, kWidth * kHeight * 4); + + // BT.601 + ARGBToI420Matrix(src_argb, kWidth * 4, dst_y, kWidth, dst_u, kWidth / 2, + dst_v, kWidth / 2, &kArgbI601Constants, kWidth, kHeight); + // Verify against non-matrix version + align_buffer_page_end(ref_y, kWidth * kHeight); + align_buffer_page_end(ref_u, kWidth / 2 * kHeight / 2); + align_buffer_page_end(ref_v, kWidth / 2 * kHeight / 2); + ARGBToI420(src_argb, kWidth * 4, ref_y, kWidth, ref_u, kWidth / 2, ref_v, + kWidth / 2, kWidth, kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth / 2 * kHeight / 2; ++i) { + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + + // JPEG + ARGBToI420Matrix(src_argb, kWidth * 4, dst_y, kWidth, dst_u, kWidth / 2, + dst_v, kWidth / 2, &kArgbJPEGConstants, kWidth, kHeight); + // Verify against non-matrix version + ARGBToJ420(src_argb, kWidth * 4, ref_y, kWidth, ref_u, kWidth / 2, ref_v, + kWidth / 2, kWidth, kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth / 2 * kHeight / 2; ++i) { + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + + // BT.709 + ARGBToI420Matrix(src_argb, kWidth * 4, dst_y, kWidth, dst_u, kWidth / 2, + dst_v, kWidth / 2, &kArgbH709Constants, kWidth, kHeight); + // Just check if it returns 0 for now. + // In a real test we'd have reference values. + + // BT.2020 + ARGBToI420Matrix(src_argb, kWidth * 4, dst_y, kWidth, dst_u, kWidth / 2, + dst_v, kWidth / 2, &kArgbU2020Constants, kWidth, kHeight); + + // Reference BT.709 (limited range) + // Y = round(0.2126 * 219 / 255 * R + 0.7152 * 219 / 255 * G + 0.0722 * 219 / + // 255 * B + 16) Y = round(0.1826 * R + 0.6142 * G + 0.0620 * B + 16) 47 * 255 + // + 157 * 255 + 16 * 255 + 4224 = 11985 + 40035 + 4080 + 4224 = 60324 60324 / + // 256 = 235.64 -> 235. Correct. + + for (int i = 0; i < kWidth * kHeight * 4; ++i) + src_argb[i] = 255; + ARGBToI420Matrix(src_argb, kWidth * 4, dst_y, kWidth, dst_u, kWidth / 2, + dst_v, kWidth / 2, &kArgbH709Constants, kWidth, kHeight); + ASSERT_EQ(dst_y[0], 235); + ASSERT_EQ(dst_u[0], 128); + ASSERT_EQ(dst_v[0], 128); + + for (int i = 0; i < kWidth * kHeight * 4; i += 4) { + src_argb[i + 0] = 0; // B + src_argb[i + 1] = 0; // G + src_argb[i + 2] = 255; // R + src_argb[i + 3] = 255; // A + } + ARGBToI420Matrix(src_argb, kWidth * 4, dst_y, kWidth, dst_u, kWidth / 2, + dst_v, kWidth / 2, &kArgbH709Constants, kWidth, kHeight); + // Y = 47 * 255 + 4224 = 11985 + 4224 = 16209. 16209 / 256 = 63.3 -> 63. + ASSERT_EQ(dst_y[0], 63); + // U = -26 * 255 + 32768 = -6630 + 32768 = 26138. 26138 / 256 = 102.1 -> 102. + ASSERT_EQ(dst_u[0], 102); + // V = 112 * 255 + 32768 = 28560 + 32768 = 61328. 61328 / 256 = 239.5 -> 239. + ASSERT_EQ(dst_v[0], 239); + + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_u); + free_aligned_buffer_page_end(dst_v); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_u); + free_aligned_buffer_page_end(ref_v); +} + +TEST_F(LibYUVConvertTest, TestARGBToI422Matrix) { + const int kWidth = 16; + const int kHeight = 16; + align_buffer_page_end(src_argb, kWidth * kHeight * 4); + align_buffer_page_end(dst_y, kWidth * kHeight); + align_buffer_page_end(dst_u, kWidth / 2 * kHeight); + align_buffer_page_end(dst_v, kWidth / 2 * kHeight); + + MemRandomize(src_argb, kWidth * kHeight * 4); + + // BT.601 + ARGBToI422Matrix(src_argb, kWidth * 4, dst_y, kWidth, dst_u, kWidth / 2, + dst_v, kWidth / 2, &kArgbI601Constants, kWidth, kHeight); + // Verify against non-matrix version + align_buffer_page_end(ref_y, kWidth * kHeight); + align_buffer_page_end(ref_u, kWidth / 2 * kHeight); + align_buffer_page_end(ref_v, kWidth / 2 * kHeight); + ARGBToI422(src_argb, kWidth * 4, ref_y, kWidth, ref_u, kWidth / 2, ref_v, + kWidth / 2, kWidth, kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth / 2 * kHeight; ++i) { + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + + // JPEG + ARGBToI422Matrix(src_argb, kWidth * 4, dst_y, kWidth, dst_u, kWidth / 2, + dst_v, kWidth / 2, &kArgbJPEGConstants, kWidth, kHeight); + // Verify against non-matrix version + ARGBToJ422(src_argb, kWidth * 4, ref_y, kWidth, ref_u, kWidth / 2, ref_v, + kWidth / 2, kWidth, kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth / 2 * kHeight / 2; ++i) { + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_u); + free_aligned_buffer_page_end(dst_v); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_u); + free_aligned_buffer_page_end(ref_v); +} + +TEST_F(LibYUVConvertTest, TestARGBToI444Matrix) { + const int kWidth = 16; + const int kHeight = 16; + align_buffer_page_end(src_argb, kWidth * kHeight * 4); + align_buffer_page_end(dst_y, kWidth * kHeight); + align_buffer_page_end(dst_u, kWidth * kHeight); + align_buffer_page_end(dst_v, kWidth * kHeight); + + MemRandomize(src_argb, kWidth * kHeight * 4); + + // BT.601 + ARGBToI444Matrix(src_argb, kWidth * 4, dst_y, kWidth, dst_u, kWidth, dst_v, + kWidth, &kArgbI601Constants, kWidth, kHeight); + // Verify against non-matrix version + align_buffer_page_end(ref_y, kWidth * kHeight); + align_buffer_page_end(ref_u, kWidth * kHeight); + align_buffer_page_end(ref_v, kWidth * kHeight); + ARGBToI444(src_argb, kWidth * 4, ref_y, kWidth, ref_u, kWidth, ref_v, kWidth, + kWidth, kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + + // JPEG + ARGBToI444Matrix(src_argb, kWidth * 4, dst_y, kWidth, dst_u, kWidth / 2, + dst_v, kWidth / 2, &kArgbJPEGConstants, kWidth, kHeight); + // Verify against non-matrix version + ARGBToJ444(src_argb, kWidth * 4, ref_y, kWidth, ref_u, kWidth / 2, ref_v, + kWidth / 2, kWidth, kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < kWidth / 2 * kHeight / 2; ++i) { + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_u); + free_aligned_buffer_page_end(dst_v); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_u); + free_aligned_buffer_page_end(ref_v); +} + +template +static void TestRGBToI420(ConvertToYUV convert_to_yuv, + ConvertToARGB convert_to_argb, + int width, + int height, + int disable_cpu_flags, + int benchmark_cpu_info) { + align_buffer_page_end(src_rgb, width * height * 4); + align_buffer_page_end(dst_y, width * height); + align_buffer_page_end(dst_u, (width + 1) / 2 * (height + 1) / 2); + align_buffer_page_end(dst_v, (width + 1) / 2 * (height + 1) / 2); + + align_buffer_page_end(tmp_argb, width * height * 4); + align_buffer_page_end(ref_y, width * height); + align_buffer_page_end(ref_u, (width + 1) / 2 * (height + 1) / 2); + align_buffer_page_end(ref_v, (width + 1) / 2 * (height + 1) / 2); + + MemRandomize(src_rgb, width * height * 4); + + { + SCOPED_TRACE("C_Version"); + MaskCpuFlags(disable_cpu_flags); + + // Clear buffers + memset(dst_y, 0, width * height); + memset(dst_u, 0, (width + 1) / 2 * (height + 1) / 2); + memset(dst_v, 0, (width + 1) / 2 * (height + 1) / 2); + memset(ref_y, 0, width * height); + memset(ref_u, 0, (width + 1) / 2 * (height + 1) / 2); + memset(ref_v, 0, (width + 1) / 2 * (height + 1) / 2); + memset(tmp_argb, 0, width * height * 4); + + int r1 = + convert_to_yuv(src_rgb, width * 4, dst_y, width, dst_u, (width + 1) / 2, + dst_v, (width + 1) / 2, width, height); + ASSERT_EQ(r1, 0); + + int r2 = + convert_to_argb(src_rgb, width * 4, tmp_argb, width * 4, width, height); + ASSERT_EQ(r2, 0); + + int r3 = ARGBToI420(tmp_argb, width * 4, ref_y, width, ref_u, + (width + 1) / 2, ref_v, (width + 1) / 2, width, height); + ASSERT_EQ(r3, 0); + + for (int i = 0; i < width * height; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < (width + 1) / 2 * (height + 1) / 2; ++i) { + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + } + + { + SCOPED_TRACE("SIMD_Version"); + MaskCpuFlags(benchmark_cpu_info); + + // Clear buffers + memset(dst_y, 0, width * height); + memset(dst_u, 0, (width + 1) / 2 * (height + 1) / 2); + memset(dst_v, 0, (width + 1) / 2 * (height + 1) / 2); + memset(ref_y, 0, width * height); + memset(ref_u, 0, (width + 1) / 2 * (height + 1) / 2); + memset(ref_v, 0, (width + 1) / 2 * (height + 1) / 2); + memset(tmp_argb, 0, width * height * 4); + + int r1 = + convert_to_yuv(src_rgb, width * 4, dst_y, width, dst_u, (width + 1) / 2, + dst_v, (width + 1) / 2, width, height); + ASSERT_EQ(r1, 0); + + int r2 = + convert_to_argb(src_rgb, width * 4, tmp_argb, width * 4, width, height); + ASSERT_EQ(r2, 0); + + int r3 = ARGBToI420(tmp_argb, width * 4, ref_y, width, ref_u, + (width + 1) / 2, ref_v, (width + 1) / 2, width, height); + ASSERT_EQ(r3, 0); + + for (int i = 0; i < width * height; ++i) { + ASSERT_EQ(dst_y[i], ref_y[i]); + } + for (int i = 0; i < (width + 1) / 2 * (height + 1) / 2; ++i) { + ASSERT_EQ(dst_u[i], ref_u[i]); + ASSERT_EQ(dst_v[i], ref_v[i]); + } + } + + free_aligned_buffer_page_end(src_rgb); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_u); + free_aligned_buffer_page_end(dst_v); + free_aligned_buffer_page_end(tmp_argb); + free_aligned_buffer_page_end(ref_y); + free_aligned_buffer_page_end(ref_u); + free_aligned_buffer_page_end(ref_v); +} + +TEST_F(LibYUVConvertTest, BGRAToI420_Check) { + TestRGBToI420(BGRAToI420, BGRAToARGB, 16, 16, disable_cpu_flags_, + benchmark_cpu_info_); + TestRGBToI420(BGRAToI420, BGRAToARGB, 17, 17, disable_cpu_flags_, + benchmark_cpu_info_); + TestRGBToI420(BGRAToI420, BGRAToARGB, 1280, 720, disable_cpu_flags_, + benchmark_cpu_info_); +} + +TEST_F(LibYUVConvertTest, RGBAToI420_Check) { + TestRGBToI420(RGBAToI420, RGBAToARGB, 16, 16, disable_cpu_flags_, + benchmark_cpu_info_); + TestRGBToI420(RGBAToI420, RGBAToARGB, 17, 17, disable_cpu_flags_, + benchmark_cpu_info_); + TestRGBToI420(RGBAToI420, RGBAToARGB, 1280, 720, disable_cpu_flags_, + benchmark_cpu_info_); +} + +TEST_F(LibYUVConvertTest, ABGRToI420_Check) { + TestRGBToI420(ABGRToI420, ABGRToARGB, 16, 16, disable_cpu_flags_, + benchmark_cpu_info_); + TestRGBToI420(ABGRToI420, ABGRToARGB, 17, 17, disable_cpu_flags_, + benchmark_cpu_info_); + TestRGBToI420(ABGRToI420, ABGRToARGB, 1280, 720, disable_cpu_flags_, + benchmark_cpu_info_); +} + +// I210ToI420/I212ToI420 funnel through I21xToI420, which scales chroma +// vertically. Verify oversize heights do not overflow a signed int. +TEST_F(LibYUVConvertTest, I21xToI420NoHeightOverflow) { + int width = 4; + int height = 40000; + int half_width = (width + 1) / 2; + int half_height = (height + 1) / 2; + // I21x: 16-bit 4:2:2 + align_buffer_page_end_16(src_y, width * height); + align_buffer_page_end_16(src_u, half_width * height); + align_buffer_page_end_16(src_v, half_width * height); + // I420: 8-bit 4:2:0 + align_buffer_page_end(dst_y, width * height); + align_buffer_page_end(dst_u, half_width * half_height); + align_buffer_page_end(dst_v, half_width * half_height); + + memset(src_y, 0, width * height * sizeof(uint16_t)); + memset(src_u, 0, half_width * height * sizeof(uint16_t)); + memset(src_v, 0, half_width * height * sizeof(uint16_t)); + + EXPECT_EQ(0, I210ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, 32767)); + EXPECT_EQ(0, I210ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, 32768)); + EXPECT_EQ(0, I210ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, 32769)); + EXPECT_EQ(0, I210ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, -32767)); + EXPECT_EQ(0, I210ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, -32768)); + EXPECT_EQ(0, I210ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, -32769)); + EXPECT_EQ(0, I212ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, 32767)); + EXPECT_EQ(0, I212ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, 32768)); + EXPECT_EQ(0, I212ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, 32769)); + EXPECT_EQ(0, I212ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, -32767)); + EXPECT_EQ(0, I212ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, -32768)); + EXPECT_EQ(0, I212ToI420(src_y, 4, src_u, 2, src_v, 2, dst_y, 4, dst_u, 2, + dst_v, 2, 4, -32769)); + + free_aligned_buffer_page_end_16(src_y); + free_aligned_buffer_page_end_16(src_u); + free_aligned_buffer_page_end_16(src_v); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_u); + free_aligned_buffer_page_end(dst_v); +} + +// Call YUY2ToNV12() with a width that is not a multiple of 32. Verify there is +// no stack buffer overflow in YUY2ToNVUVRow_Any_AVX2(). +TEST_F(LibYUVConvertTest, YUY2ToNV12Overflow) { + int width = 40 * 32 + 30; // 1310 + int height = 4; + int src_stride_yuy2 = width * 2; + align_buffer_page_end(src_yuy2, src_stride_yuy2 * height); + align_buffer_page_end(dst_y, width * height); + align_buffer_page_end(dst_uv, width * ((height + 1) / 2)); + memset(src_yuy2, 0xA5, src_stride_yuy2 * height); + EXPECT_EQ(0, YUY2ToNV12(src_yuy2, src_stride_yuy2, dst_y, width, dst_uv, + width, width, height)); + free_aligned_buffer_page_end(src_yuy2); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_uv); +} + +#endif // !defined(LEAN_TESTS) + } // namespace libyuv diff --git a/libs/libyuv/unit_test/cpu_test.cc b/libs/libyuv/unit_test/cpu_test.cc index a7991d2bab..3829f8dd23 100644 --- a/libs/libyuv/unit_test/cpu_test.cc +++ b/libs/libyuv/unit_test/cpu_test.cc @@ -8,93 +8,21 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include #include #include +#ifdef __linux__ +#include +#include +#endif + #include "../unit_test/unit_test.h" -#include "libyuv/basic_types.h" #include "libyuv/cpu_id.h" #include "libyuv/version.h" namespace libyuv { -TEST_F(LibYUVBaseTest, TestCpuHas) { - int cpu_flags = TestCpuFlag(-1); - printf("Cpu Flags %d\n", cpu_flags); -#if defined(__arm__) || defined(__aarch64__) - int has_arm = TestCpuFlag(kCpuHasARM); - printf("Has ARM %d\n", has_arm); - int has_neon = TestCpuFlag(kCpuHasNEON); - printf("Has NEON %d\n", has_neon); -#endif - int has_x86 = TestCpuFlag(kCpuHasX86); - int has_sse2 = TestCpuFlag(kCpuHasSSE2); - int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); - int has_sse41 = TestCpuFlag(kCpuHasSSE41); - int has_sse42 = TestCpuFlag(kCpuHasSSE42); - int has_avx = TestCpuFlag(kCpuHasAVX); - int has_avx2 = TestCpuFlag(kCpuHasAVX2); - int has_erms = TestCpuFlag(kCpuHasERMS); - int has_fma3 = TestCpuFlag(kCpuHasFMA3); - int has_f16c = TestCpuFlag(kCpuHasF16C); - int has_gfni = TestCpuFlag(kCpuHasGFNI); - int has_avx512bw = TestCpuFlag(kCpuHasAVX512BW); - int has_avx512vl = TestCpuFlag(kCpuHasAVX512VL); - int has_avx512vbmi = TestCpuFlag(kCpuHasAVX512VBMI); - int has_avx512vbmi2 = TestCpuFlag(kCpuHasAVX512VBMI2); - int has_avx512vbitalg = TestCpuFlag(kCpuHasAVX512VBITALG); - int has_avx512vpopcntdq = TestCpuFlag(kCpuHasAVX512VPOPCNTDQ); - printf("Has X86 %d\n", has_x86); - printf("Has SSE2 %d\n", has_sse2); - printf("Has SSSE3 %d\n", has_ssse3); - printf("Has SSE41 %d\n", has_sse41); - printf("Has SSE42 %d\n", has_sse42); - printf("Has AVX %d\n", has_avx); - printf("Has AVX2 %d\n", has_avx2); - printf("Has ERMS %d\n", has_erms); - printf("Has FMA3 %d\n", has_fma3); - printf("Has F16C %d\n", has_f16c); - printf("Has GFNI %d\n", has_gfni); - printf("Has AVX512BW %d\n", has_avx512bw); - printf("Has AVX512VL %d\n", has_avx512vl); - printf("Has AVX512VBMI %d\n", has_avx512vbmi); - printf("Has AVX512VBMI2 %d\n", has_avx512vbmi2); - printf("Has AVX512VBITALG %d\n", has_avx512vbitalg); - printf("Has AVX512VPOPCNTDQ %d\n", has_avx512vpopcntdq); - -#if defined(__mips__) - int has_mips = TestCpuFlag(kCpuHasMIPS); - printf("Has MIPS %d\n", has_mips); - int has_msa = TestCpuFlag(kCpuHasMSA); - printf("Has MSA %d\n", has_msa); - int has_mmi = TestCpuFlag(kCpuHasMMI); - printf("Has MMI %d\n", has_mmi); -#endif -} - -TEST_F(LibYUVBaseTest, TestCpuCompilerEnabled) { -#if defined(__aarch64__) - printf("Arm64 build\n"); -#endif -#if defined(__aarch64__) || defined(__ARM_NEON__) || defined(LIBYUV_NEON) - printf("Neon build enabled\n"); -#endif -#if defined(__x86_64__) || defined(_M_X64) - printf("x64 build\n"); -#endif -#ifdef _MSC_VER - printf("_MSC_VER %d\n", _MSC_VER); -#endif -#if !defined(LIBYUV_DISABLE_X86) && \ - (defined(GCC_HAS_AVX2) || defined(CLANG_HAS_AVX2) || \ - defined(VISUALC_HAS_AVX2)) - printf("Has AVX2 1\n"); -#else - printf("Has AVX2 0\n"); -// If compiler does not support AVX2, the following function not expected: -#endif -} - #if defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || \ defined(_M_X64) TEST_F(LibYUVBaseTest, TestCpuId) { @@ -116,9 +44,10 @@ TEST_F(LibYUVBaseTest, TestCpuId) { cpu_info[0] = cpu_info[1]; // Reorder output cpu_info[1] = cpu_info[3]; cpu_info[3] = 0; - printf("Cpu Vendor: %s %x %x %x\n", reinterpret_cast(&cpu_info[0]), - cpu_info[0], cpu_info[1], cpu_info[2]); - EXPECT_EQ(12u, strlen(reinterpret_cast(&cpu_info[0]))); + printf("Cpu Vendor: %s 0x%x 0x%x 0x%x\n", + reinterpret_cast(&cpu_info[0]), cpu_info[0], cpu_info[1], + cpu_info[2]); + ASSERT_EQ(12u, strlen(reinterpret_cast(&cpu_info[0]))); // CPU Family and Model // 3:0 - Stepping @@ -136,6 +65,294 @@ TEST_F(LibYUVBaseTest, TestCpuId) { } #endif +#ifdef __linux__ +static void KernelVersion(int* version) { + struct utsname buffer; + int i = 0; + + version[0] = version[1] = 0; + if (uname(&buffer) == 0) { + char* v = buffer.release; + for (i = 0; *v && i < 2; ++v) { + if (isdigit(*v)) { + version[i++] = (int)strtol(v, &v, 10); + } + } + } +} +#endif + +TEST_F(LibYUVBaseTest, TestCpuHas) { +#if defined(__linux__) + { + int kernelversion[2]; + KernelVersion(kernelversion); + printf("Kernel Version %d.%d\n", kernelversion[0], kernelversion[1]); + } +#endif // defined(__linux__) + +#if defined(__arm__) || defined(__aarch64__) + int has_arm = TestCpuFlag(kCpuHasARM); + if (has_arm) { + int has_neon = TestCpuFlag(kCpuHasNEON); + int has_neon_dotprod = TestCpuFlag(kCpuHasNeonDotProd); + int has_neon_i8mm = TestCpuFlag(kCpuHasNeonI8MM); + int has_sve = TestCpuFlag(kCpuHasSVE); + int has_sve2 = TestCpuFlag(kCpuHasSVE2); + int has_sve_f32mm = TestCpuFlag(kCpuHasSVEF32MM); + int has_sme = TestCpuFlag(kCpuHasSME); + int has_sme2 = TestCpuFlag(kCpuHasSME2); + printf("Has Arm 0x%x\n", has_arm); + printf("Has Neon 0x%x\n", has_neon); + printf("Has Neon DotProd 0x%x\n", has_neon_dotprod); + printf("Has Neon I8MM 0x%x\n", has_neon_i8mm); + printf("Has SVE 0x%x\n", has_sve); + printf("Has SVE2 0x%x\n", has_sve2); + printf("Has SVE F32MM 0x%x\n", has_sve_f32mm); + printf("Has SME 0x%x\n", has_sme); + printf("Has SME2 0x%x\n", has_sme2); + +#if defined(__aarch64__) + // Read and print the SVE and SME vector lengths. + if (has_sve) { + int sve_vl; + asm(".inst 0x04bf5020 \n" // rdvl x0, #1 + "mov %w[sve_vl], w0 \n" + : [sve_vl] "=r"(sve_vl) // %[sve_vl] + : + : "x0"); + printf("SVE vector length: %d bytes\n", sve_vl); + } + if (has_sme) { + int sme_vl; + asm(".inst 0x04bf5820 \n" // rdsvl x0, #1 + "mov %w[sme_vl], w0 \n" + : [sme_vl] "=r"(sme_vl) // %[sme_vl] + : + : "x0"); + printf("SME vector length: %d bytes\n", sme_vl); + } +#endif // defined(__aarch64__) + } +#endif // if defined(__arm__) || defined(__aarch64__) + +#if defined(__riscv) + int has_riscv = TestCpuFlag(kCpuHasRISCV); + if (has_riscv) { + int has_rvv = TestCpuFlag(kCpuHasRVV); + printf("Has RISCV 0x%x\n", has_riscv); + printf("Has RVV 0x%x\n", has_rvv); + + // Read and print the RVV vector length. + if (has_rvv) { + register uint32_t vlenb __asm__("t0"); + __asm__(".word 0xC22022F3" /* CSRR t0, vlenb */ : "=r"(vlenb)); + printf("RVV vector length: %d bytes\n", vlenb); + } + } +#endif // defined(__riscv) + +#if defined(__loongarch__) + int has_loongarch = TestCpuFlag(kCpuHasLOONGARCH); + if (has_loongarch) { + int has_lsx = TestCpuFlag(kCpuHasLSX); + int has_lasx = TestCpuFlag(kCpuHasLASX); + printf("Has LOONGARCH 0x%x\n", has_loongarch); + printf("Has LSX 0x%x\n", has_lsx); + printf("Has LASX 0x%x\n", has_lasx); + } +#endif // defined(__loongarch__) + +#if defined(__wasm__) + int has_wasm = TestCpuFlag(kCpuHasWASM); + if (has_wasm) { + int has_wasm_simd = TestCpuFlag(kCpuHasWASMSIMD); + printf("Has WASM 0x%x\n", has_wasm); + printf("Has WASM SIMD 0x%x\n", has_wasm_simd); + } +#endif // defined(__wasm__) + +#if defined(__hexagon__) + int has_hexagon = TestCpuFlag(kCpuHasHexagon); + if (has_hexagon) { + int has_hvx = TestCpuFlag(kCpuHasHVX); + printf("Has Hexagon 0x%x\n", has_hexagon); + printf("Has HVX 0x%x\n", has_hvx); + } +#endif // defined(__hexagon__) + +#if defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || \ + defined(_M_X64) + int has_x86 = TestCpuFlag(kCpuHasX86); + if (has_x86) { + int has_sse2 = TestCpuFlag(kCpuHasSSE2); + int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); + int has_sse41 = TestCpuFlag(kCpuHasSSE41); + int has_sse42 = TestCpuFlag(kCpuHasSSE42); + int has_avx = TestCpuFlag(kCpuHasAVX); + int has_avx2 = TestCpuFlag(kCpuHasAVX2); + int has_erms = TestCpuFlag(kCpuHasERMS); + int has_fsmr = TestCpuFlag(kCpuHasFSMR); + int has_fma3 = TestCpuFlag(kCpuHasFMA3); + int has_f16c = TestCpuFlag(kCpuHasF16C); + int has_avx512bw = TestCpuFlag(kCpuHasAVX512BW); + int has_avx512vl = TestCpuFlag(kCpuHasAVX512VL); + int has_avx512vnni = TestCpuFlag(kCpuHasAVX512VNNI); + int has_avx512vbmi = TestCpuFlag(kCpuHasAVX512VBMI); + int has_avx512vbmi2 = TestCpuFlag(kCpuHasAVX512VBMI2); + int has_avx512vbitalg = TestCpuFlag(kCpuHasAVX512VBITALG); + int has_avx10 = TestCpuFlag(kCpuHasAVX10); + int has_avx10_2 = TestCpuFlag(kCpuHasAVX10_2); + int has_avxvnni = TestCpuFlag(kCpuHasAVXVNNI); + int has_avxvnniint8 = TestCpuFlag(kCpuHasAVXVNNIINT8); + int has_amxint8 = TestCpuFlag(kCpuHasAMXINT8); + int has_avx512bmm = TestCpuFlag(kCpuHasAVX512BMM); + int has_amxtf32 = TestCpuFlag(kCpuHasAMXTF32); + printf("Has X86 0x%x\n", has_x86); + printf("Has SSE2 0x%x\n", has_sse2); + printf("Has SSSE3 0x%x\n", has_ssse3); + printf("Has SSE4.1 0x%x\n", has_sse41); + printf("Has SSE4.2 0x%x\n", has_sse42); + printf("Has AVX 0x%x\n", has_avx); + printf("Has AVX2 0x%x\n", has_avx2); + printf("Has ERMS 0x%x\n", has_erms); + printf("Has FSMR 0x%x\n", has_fsmr); + printf("Has FMA3 0x%x\n", has_fma3); + printf("Has F16C 0x%x\n", has_f16c); + printf("Has AVX512BW 0x%x\n", has_avx512bw); + printf("Has AVX512VL 0x%x\n", has_avx512vl); + printf("Has AVX512VNNI 0x%x\n", has_avx512vnni); + printf("Has AVX512VBMI 0x%x\n", has_avx512vbmi); + printf("Has AVX512VBMI2 0x%x\n", has_avx512vbmi2); + printf("Has AVX512VBITALG 0x%x\n", has_avx512vbitalg); + printf("Has AVX10 0x%x\n", has_avx10); + printf("Has AVX10_2 0x%x\n", has_avx10_2); + printf("HAS AVXVNNI 0x%x\n", has_avxvnni); + printf("Has AVXVNNIINT8 0x%x\n", has_avxvnniint8); + printf("Has AMXINT8 0x%x\n", has_amxint8); + printf("Has AVX512BMM 0x%x\n", has_avx512bmm); + printf("Has AMXTF32 0x%x\n", has_amxtf32); + } +#endif // defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || + // defined(_M_X64) +} + +TEST_F(LibYUVBaseTest, TestCompilerMacros) { + // Tests all macros used in public headers. +#ifdef __ATOMIC_RELAXED + printf("__ATOMIC_RELAXED %d\n", __ATOMIC_RELAXED); +#endif +#ifdef __cplusplus + printf("__cplusplus %ld\n", __cplusplus); +#endif +#ifdef __clang_major__ + printf("__clang_major__ %d\n", __clang_major__); +#endif +#ifdef __clang_minor__ + printf("__clang_minor__ %d\n", __clang_minor__); +#endif +#ifdef __GNUC__ + printf("__GNUC__ %d\n", __GNUC__); +#endif +#ifdef __GNUC_MINOR__ + printf("__GNUC_MINOR__ %d\n", __GNUC_MINOR__); +#endif +#ifdef __i386__ + printf("__i386__ %d\n", __i386__); +#endif +#ifdef __x86_64__ + printf("__x86_64__ %d\n", __x86_64__); +#endif +#ifdef _M_IX86 + printf("_M_IX86 %d\n", _M_IX86); +#endif +#ifdef _M_X64 + printf("_M_X64 %d\n", _M_X64); +#endif +#ifdef _MSC_VER + printf("_MSC_VER %d\n", _MSC_VER); +#endif +#ifdef __aarch64__ + printf("__aarch64__ %d\n", __aarch64__); +#endif +#ifdef __arm__ + printf("__arm__ %d\n", __arm__); +#endif +#ifdef __riscv + printf("__riscv %d\n", __riscv); +#endif +#ifdef __riscv_vector + printf("__riscv_vector %d\n", __riscv_vector); +#endif +#ifdef __riscv_v_intrinsic + printf("__riscv_v_intrinsic %d\n", __riscv_v_intrinsic); +#endif +#ifdef __riscv_zve64x + printf("__riscv_zve64x %d\n", __riscv_zve64x); +#endif +#ifdef __APPLE__ + printf("__APPLE__ %d\n", __APPLE__); +#endif +#ifdef __clang__ + printf("__clang__ %d\n", __clang__); +#endif +#ifdef __CLR_VER + printf("__CLR_VER %d\n", __CLR_VER); +#endif +#ifdef __CYGWIN__ + printf("__CYGWIN__ %d\n", __CYGWIN__); +#endif +#ifdef __llvm__ + printf("__llvm__ %d\n", __llvm__); +#endif +#ifdef __loongarch__ + printf("__loongarch__ %d\n", __loongarch__); +#endif +#ifdef __wasm__ + printf("__wasm__ %d\n", __wasm__); +#endif +#ifdef __wasm_simd128__ + printf("__wasm_simd128__ %d\n", __wasm_simd128__); +#endif +#ifdef __hexagon__ + printf("__hexagon__ %d\n", __hexagon__); +#endif +#ifdef __HVX__ + printf("__HVX__ %d\n", __HVX__); +#endif +#ifdef __HVX_ARCH__ + printf("__HVX_ARCH__ %d\n", __HVX_ARCH__); +#endif +#ifdef __HVX_LENGTH__ + printf("__HVX_LENGTH__ %d\n", __HVX_LENGTH__); +#endif +#ifdef _WIN32 + printf("_WIN32 %d\n", _WIN32); +#endif +#ifdef __native_client__ + printf("__native_client__ %d\n", __native_client__); +#endif +#ifdef __pic__ + printf("__pic__ %d\n", __pic__); +#endif +#ifdef __pnacl__ + printf("__pnacl__ %d\n", __pnacl__); +#endif +#ifdef GG_LONGLONG + printf("GG_LONGLONG %lld\n", GG_LONGLONG(1)); +#endif +#ifdef INT_TYPES_DEFINED + printf("INT_TYPES_DEFINED\n"); +#endif +#ifdef __has_feature + printf("__has_feature\n"); +#if __has_feature(memory_sanitizer) + printf("__has_feature(memory_sanitizer) %d\n", + __has_feature(memory_sanitizer)); +#endif +#endif +} + static int FileExists(const char* file_name) { FILE* f = fopen(file_name, "r"); if (!f) { @@ -145,22 +362,87 @@ static int FileExists(const char* file_name) { return 1; } -TEST_F(LibYUVBaseTest, TestLinuxNeon) { +TEST_F(LibYUVBaseTest, DISABLED_TestLinuxArm) { if (FileExists("../../unit_test/testdata/arm_v7.txt")) { printf("Note: testing to load \"../../unit_test/testdata/arm_v7.txt\"\n"); - EXPECT_EQ(0, ArmCpuCaps("../../unit_test/testdata/arm_v7.txt")); - EXPECT_EQ(kCpuHasNEON, ArmCpuCaps("../../unit_test/testdata/tegra3.txt")); - EXPECT_EQ(kCpuHasNEON, ArmCpuCaps("../../unit_test/testdata/juno.txt")); + ASSERT_EQ(0, ArmCpuCaps("../../unit_test/testdata/arm_v7.txt")); + ASSERT_EQ(kCpuHasNEON, ArmCpuCaps("../../unit_test/testdata/tegra3.txt")); } else { printf("WARNING: unable to load \"../../unit_test/testdata/arm_v7.txt\"\n"); } -#if defined(__linux__) && defined(__ARM_NEON__) - EXPECT_EQ(kCpuHasNEON, ArmCpuCaps("/proc/cpuinfo")); +#if defined(__linux__) && defined(__ARM_NEON__) && !defined(__aarch64__) + if (FileExists("/proc/cpuinfo")) { + if (kCpuHasNEON != ArmCpuCaps("/proc/cpuinfo")) { + // This can happen on Arm emulator but /proc/cpuinfo is from host. + printf("WARNING: Neon build enabled but CPU does not have Neon\n"); + } + } else { + printf("WARNING: unable to load \"/proc/cpuinfo\"\n"); + } #endif } -TEST_F(LibYUVBaseTest, TestSetCpuFlags) { +#if defined(__linux__) && defined(__aarch64__) +TEST_F(LibYUVBaseTest, TestLinuxAArch64) { + // Values taken from a Cortex-A57 machine, only Neon available. + ASSERT_EQ(kCpuHasNEON, AArch64CpuCaps(0xffU, 0x0U)); + + // Values taken from a Google Pixel 7. + int expected = kCpuHasNEON | kCpuHasNeonDotProd; + ASSERT_EQ(expected, AArch64CpuCaps(0x119fffU, 0x0U)); + + // Values taken from a Google Pixel 8. + expected = kCpuHasNEON | kCpuHasNeonDotProd | kCpuHasNeonI8MM | kCpuHasSVE | + kCpuHasSVE2; + ASSERT_EQ(expected, AArch64CpuCaps(0x3fffffffU, 0x2f33fU)); + + // Values taken from a Neoverse N2 machine. + ASSERT_EQ(expected, AArch64CpuCaps(0x3fffffffU, 0x2f3ffU)); + + // Check for SME feature detection. + expected |= kCpuHasSME; + ASSERT_EQ(expected, AArch64CpuCaps(0x3fffffffU, 0x82f3ffU)); + + // Check for SME2 feature detection. + expected |= kCpuHasSME2; + ASSERT_EQ(expected, AArch64CpuCaps(0x3fffffffU, 0x200082f3ffULL)); +} +#endif + +TEST_F(LibYUVBaseTest, DISABLED_TestLinuxRVV) { + if (FileExists("../../unit_test/testdata/riscv64.txt")) { + printf("Note: testing to load \"../../unit_test/testdata/riscv64.txt\"\n"); + + ASSERT_EQ(0, RiscvCpuCaps("../../unit_test/testdata/riscv64.txt")); + ASSERT_EQ(kCpuHasRVV, + RiscvCpuCaps("../../unit_test/testdata/riscv64_rvv.txt")); + ASSERT_EQ(kCpuHasRVV | kCpuHasRVVZVFH, + RiscvCpuCaps("../../unit_test/testdata/riscv64_rvv_zvfh.txt")); + } else { + printf( + "WARNING: unable to load " + "\"../../unit_test/testdata/riscv64.txt\"\n"); + } +#if defined(__linux__) && defined(__riscv) + if (FileExists("/proc/cpuinfo")) { + if (!(kCpuHasRVV & RiscvCpuCaps("/proc/cpuinfo"))) { + // This can happen on RVV emulator but /proc/cpuinfo is from host. + printf("WARNING: RVV build enabled but CPU does not have RVV\n"); + } + } else { + printf("WARNING: unable to load \"/proc/cpuinfo\"\n"); + } +#endif +} + +#ifdef _WIN32 +// This doesn't pass on Windows CQ. +#define MAYBE_TestSetCpuFlags DISABLED_TestSetCpuFlags +#else +#define MAYBE_TestSetCpuFlags TestSetCpuFlags +#endif +TEST_F(LibYUVBaseTest, MAYBE_TestSetCpuFlags) { // Reset any masked flags that may have been set so auto init is enabled. MaskCpuFlags(0); @@ -169,15 +451,15 @@ TEST_F(LibYUVBaseTest, TestSetCpuFlags) { // Test setting different CPU configurations. int cpu_flags = kCpuHasARM | kCpuHasNEON | kCpuInitialized; SetCpuFlags(cpu_flags); - EXPECT_EQ(cpu_flags, TestCpuFlag(-1)); + ASSERT_EQ(cpu_flags, TestCpuFlag(-1)); cpu_flags = kCpuHasX86 | kCpuInitialized; SetCpuFlags(cpu_flags); - EXPECT_EQ(cpu_flags, TestCpuFlag(-1)); + ASSERT_EQ(cpu_flags, TestCpuFlag(-1)); // Test that setting 0 turns auto-init back on. SetCpuFlags(0); - EXPECT_EQ(original_cpu_flags, TestCpuFlag(-1)); + ASSERT_EQ(original_cpu_flags, TestCpuFlag(-1)); // Restore the CPU flag mask. MaskCpuFlags(benchmark_cpu_info_); diff --git a/libs/libyuv/unit_test/cpu_thread_test.cc b/libs/libyuv/unit_test/cpu_thread_test.cc index 59061b98e0..572074d73f 100644 --- a/libs/libyuv/unit_test/cpu_thread_test.cc +++ b/libs/libyuv/unit_test/cpu_thread_test.cc @@ -12,7 +12,7 @@ #include "libyuv/cpu_id.h" -#if defined(__clang__) +#if defined(__clang__) && !defined(__wasm__) #if __has_include() #define LIBYUV_HAVE_PTHREAD 1 #endif @@ -27,10 +27,10 @@ namespace libyuv { #ifdef LIBYUV_HAVE_PTHREAD -void* ThreadMain(void* arg) { +static void* ThreadMain(void* arg) { int* flags = static_cast(arg); - *flags = TestCpuFlag(kCpuHasSSSE3); + *flags = TestCpuFlag(kCpuInitialized); return nullptr; } #endif // LIBYUV_HAVE_PTHREAD @@ -51,10 +51,10 @@ TEST(LibYUVCpuThreadTest, TestCpuFlagMultipleThreads) { ret = pthread_create(&thread2, nullptr, ThreadMain, &cpu_flags2); ASSERT_EQ(ret, 0); ret = pthread_join(thread1, nullptr); - EXPECT_EQ(ret, 0); + ASSERT_EQ(ret, 0); ret = pthread_join(thread2, nullptr); - EXPECT_EQ(ret, 0); - EXPECT_EQ(cpu_flags1, cpu_flags2); + ASSERT_EQ(ret, 0); + ASSERT_EQ(cpu_flags1, cpu_flags2); #else printf("pthread unavailable; Test skipped."); #endif // LIBYUV_HAVE_PTHREAD diff --git a/libs/libyuv/unit_test/math_test.cc b/libs/libyuv/unit_test/math_test.cc index a1544c122b..1f1a6d8443 100644 --- a/libs/libyuv/unit_test/math_test.cc +++ b/libs/libyuv/unit_test/math_test.cc @@ -13,7 +13,6 @@ #include #include "../unit_test/unit_test.h" -#include "libyuv/basic_types.h" #include "libyuv/cpu_id.h" #include "libyuv/scale.h" @@ -30,44 +29,44 @@ TEST_F(LibYUVBaseTest, TestFixedDiv) { int result_opt[1280]; int result_c[1280]; - EXPECT_EQ(0x10000, libyuv::FixedDiv(1, 1)); - EXPECT_EQ(0x7fff0000, libyuv::FixedDiv(0x7fff, 1)); + ASSERT_EQ(0x10000, libyuv::FixedDiv(1, 1)); + ASSERT_EQ(0x7fff0000, libyuv::FixedDiv(0x7fff, 1)); // TODO(fbarchard): Avoid the following that throw exceptions. - // EXPECT_EQ(0x100000000, libyuv::FixedDiv(0x10000, 1)); - // EXPECT_EQ(0x80000000, libyuv::FixedDiv(0x8000, 1)); + // ASSERT_EQ(0x100000000, libyuv::FixedDiv(0x10000, 1)); + // ASSERT_EQ(0x80000000, libyuv::FixedDiv(0x8000, 1)); - EXPECT_EQ(0x20000, libyuv::FixedDiv(640 * 2, 640)); - EXPECT_EQ(0x30000, libyuv::FixedDiv(640 * 3, 640)); - EXPECT_EQ(0x40000, libyuv::FixedDiv(640 * 4, 640)); - EXPECT_EQ(0x50000, libyuv::FixedDiv(640 * 5, 640)); - EXPECT_EQ(0x60000, libyuv::FixedDiv(640 * 6, 640)); - EXPECT_EQ(0x70000, libyuv::FixedDiv(640 * 7, 640)); - EXPECT_EQ(0x80000, libyuv::FixedDiv(640 * 8, 640)); - EXPECT_EQ(0xa0000, libyuv::FixedDiv(640 * 10, 640)); - EXPECT_EQ(0x20000, libyuv::FixedDiv(960 * 2, 960)); - EXPECT_EQ(0x08000, libyuv::FixedDiv(640 / 2, 640)); - EXPECT_EQ(0x04000, libyuv::FixedDiv(640 / 4, 640)); - EXPECT_EQ(0x20000, libyuv::FixedDiv(1080 * 2, 1080)); - EXPECT_EQ(0x20000, libyuv::FixedDiv(200000, 100000)); - EXPECT_EQ(0x18000, libyuv::FixedDiv(150000, 100000)); - EXPECT_EQ(0x20000, libyuv::FixedDiv(40000, 20000)); - EXPECT_EQ(0x20000, libyuv::FixedDiv(-40000, -20000)); - EXPECT_EQ(-0x20000, libyuv::FixedDiv(40000, -20000)); - EXPECT_EQ(-0x20000, libyuv::FixedDiv(-40000, 20000)); - EXPECT_EQ(0x10000, libyuv::FixedDiv(4095, 4095)); - EXPECT_EQ(0x10000, libyuv::FixedDiv(4096, 4096)); - EXPECT_EQ(0x10000, libyuv::FixedDiv(4097, 4097)); - EXPECT_EQ(123 * 65536, libyuv::FixedDiv(123, 1)); + ASSERT_EQ(0x20000, libyuv::FixedDiv(640 * 2, 640)); + ASSERT_EQ(0x30000, libyuv::FixedDiv(640 * 3, 640)); + ASSERT_EQ(0x40000, libyuv::FixedDiv(640 * 4, 640)); + ASSERT_EQ(0x50000, libyuv::FixedDiv(640 * 5, 640)); + ASSERT_EQ(0x60000, libyuv::FixedDiv(640 * 6, 640)); + ASSERT_EQ(0x70000, libyuv::FixedDiv(640 * 7, 640)); + ASSERT_EQ(0x80000, libyuv::FixedDiv(640 * 8, 640)); + ASSERT_EQ(0xa0000, libyuv::FixedDiv(640 * 10, 640)); + ASSERT_EQ(0x20000, libyuv::FixedDiv(960 * 2, 960)); + ASSERT_EQ(0x08000, libyuv::FixedDiv(640 / 2, 640)); + ASSERT_EQ(0x04000, libyuv::FixedDiv(640 / 4, 640)); + ASSERT_EQ(0x20000, libyuv::FixedDiv(1080 * 2, 1080)); + ASSERT_EQ(0x20000, libyuv::FixedDiv(200000, 100000)); + ASSERT_EQ(0x18000, libyuv::FixedDiv(150000, 100000)); + ASSERT_EQ(0x20000, libyuv::FixedDiv(40000, 20000)); + ASSERT_EQ(0x20000, libyuv::FixedDiv(-40000, -20000)); + ASSERT_EQ(-0x20000, libyuv::FixedDiv(40000, -20000)); + ASSERT_EQ(-0x20000, libyuv::FixedDiv(-40000, 20000)); + ASSERT_EQ(0x10000, libyuv::FixedDiv(4095, 4095)); + ASSERT_EQ(0x10000, libyuv::FixedDiv(4096, 4096)); + ASSERT_EQ(0x10000, libyuv::FixedDiv(4097, 4097)); + ASSERT_EQ(123 * 65536, libyuv::FixedDiv(123, 1)); for (int i = 1; i < 4100; ++i) { - EXPECT_EQ(0x10000, libyuv::FixedDiv(i, i)); - EXPECT_EQ(0x20000, libyuv::FixedDiv(i * 2, i)); - EXPECT_EQ(0x30000, libyuv::FixedDiv(i * 3, i)); - EXPECT_EQ(0x40000, libyuv::FixedDiv(i * 4, i)); - EXPECT_EQ(0x08000, libyuv::FixedDiv(i, i * 2)); - EXPECT_NEAR(16384 * 65536 / i, libyuv::FixedDiv(16384, i), 1); + ASSERT_EQ(0x10000, libyuv::FixedDiv(i, i)); + ASSERT_EQ(0x20000, libyuv::FixedDiv(i * 2, i)); + ASSERT_EQ(0x30000, libyuv::FixedDiv(i * 3, i)); + ASSERT_EQ(0x40000, libyuv::FixedDiv(i * 4, i)); + ASSERT_EQ(0x08000, libyuv::FixedDiv(i, i * 2)); + ASSERT_NEAR(16384 * 65536 / i, libyuv::FixedDiv(16384, i), 1); } - EXPECT_EQ(123 * 65536, libyuv::FixedDiv(123, 1)); + ASSERT_EQ(123 * 65536, libyuv::FixedDiv(123, 1)); MemRandomize(reinterpret_cast(&num[0]), sizeof(num)); MemRandomize(reinterpret_cast(&div[0]), sizeof(div)); @@ -84,7 +83,7 @@ TEST_F(LibYUVBaseTest, TestFixedDiv) { } for (int j = 0; j < 1280; ++j) { result_c[j] = libyuv::FixedDiv_C(num[j], div[j]); - EXPECT_NEAR(result_c[j], result_opt[j], 1); + ASSERT_NEAR(result_c[j], result_opt[j], 1); } } @@ -118,7 +117,7 @@ TEST_F(LibYUVBaseTest, TestFixedDiv_Opt) { } for (int j = 0; j < 1280; ++j) { result_c[j] = libyuv::FixedDiv_C(num[j], div[j]); - EXPECT_NEAR(result_c[j], result_opt[j], 1); + ASSERT_NEAR(result_c[j], result_opt[j], 1); } } @@ -152,7 +151,7 @@ TEST_F(LibYUVBaseTest, TestFixedDiv1_Opt) { } for (int j = 0; j < 1280; ++j) { result_c[j] = libyuv::FixedDiv1_C(num[j], div[j]); - EXPECT_NEAR(result_c[j], result_opt[j], 1); + ASSERT_NEAR(result_c[j], result_opt[j], 1); } } #endif // ENABLE_ROW_TESTS diff --git a/libs/libyuv/unit_test/planar_test.cc b/libs/libyuv/unit_test/planar_test.cc index 19232b6fed..5854b8903d 100644 --- a/libs/libyuv/unit_test/planar_test.cc +++ b/libs/libyuv/unit_test/planar_test.cc @@ -12,7 +12,6 @@ #include #include - #include "../unit_test/unit_test.h" #include "libyuv/compare.h" #include "libyuv/convert.h" @@ -22,6 +21,13 @@ #include "libyuv/cpu_id.h" #include "libyuv/planar_functions.h" #include "libyuv/rotate.h" +#include "libyuv/scale.h" +#include "libyuv/scale_uv.h" + +#if !defined(LIBYUV_USING_SHARED_LIBRARY) && !defined(COMPONENT_BUILD) && \ + !defined(ENABLE_ROW_TESTS) +#define ENABLE_ROW_TESTS +#endif #ifdef ENABLE_ROW_TESTS // row.h defines SIMD_ALIGNED, overriding unit_test.h @@ -29,6 +35,23 @@ #include "libyuv/row.h" /* For ScaleSumSamples_Neon */ #endif +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) +#include +#define MSAN_POISON(ptr, size) __msan_allocated_memory(ptr, size) +#define MSAN_CHECK_INITIALIZED(ptr, size) \ + __msan_check_mem_is_initialized(ptr, size) +#endif +#endif +#ifndef MSAN_POISON +#define MSAN_POISON(ptr, size) +#endif +#ifndef MSAN_CHECK_INITIALIZED +#define MSAN_CHECK_INITIALIZED(ptr, size) +#endif + +#define EXPECTED_UNATTENUATE_DIFF 0 + namespace libyuv { TEST_F(LibYUVPlanarTest, TestAttenuate) { @@ -51,28 +74,74 @@ TEST_F(LibYUVPlanarTest, TestAttenuate) { orig_pixels[2 * 4 + 0] = 16u; orig_pixels[2 * 4 + 1] = 64u; orig_pixels[2 * 4 + 2] = 192u; - orig_pixels[2 * 4 + 3] = 255u; + orig_pixels[2 * 4 + 3] = 128u; orig_pixels[3 * 4 + 0] = 16u; orig_pixels[3 * 4 + 1] = 64u; orig_pixels[3 * 4 + 2] = 192u; - orig_pixels[3 * 4 + 3] = 128u; - ARGBUnattenuate(orig_pixels, 0, unatten_pixels, 0, 4, 1); - EXPECT_EQ(255u, unatten_pixels[0 * 4 + 0]); - EXPECT_EQ(255u, unatten_pixels[0 * 4 + 1]); - EXPECT_EQ(254u, unatten_pixels[0 * 4 + 2]); - EXPECT_EQ(128u, unatten_pixels[0 * 4 + 3]); - EXPECT_EQ(0u, unatten_pixels[1 * 4 + 0]); - EXPECT_EQ(0u, unatten_pixels[1 * 4 + 1]); - EXPECT_EQ(0u, unatten_pixels[1 * 4 + 2]); - EXPECT_EQ(0u, unatten_pixels[1 * 4 + 3]); - EXPECT_EQ(16u, unatten_pixels[2 * 4 + 0]); - EXPECT_EQ(64u, unatten_pixels[2 * 4 + 1]); - EXPECT_EQ(192u, unatten_pixels[2 * 4 + 2]); - EXPECT_EQ(255u, unatten_pixels[2 * 4 + 3]); - EXPECT_EQ(32u, unatten_pixels[3 * 4 + 0]); - EXPECT_EQ(128u, unatten_pixels[3 * 4 + 1]); - EXPECT_EQ(255u, unatten_pixels[3 * 4 + 2]); - EXPECT_EQ(128u, unatten_pixels[3 * 4 + 3]); + orig_pixels[3 * 4 + 3] = 255u; + orig_pixels[4 * 4 + 0] = 255u; + orig_pixels[4 * 4 + 1] = 255u; + orig_pixels[4 * 4 + 2] = 255u; + orig_pixels[4 * 4 + 3] = 255u; + + ARGBUnattenuate(orig_pixels, 0, unatten_pixels, 0, 5, 1); + ASSERT_EQ(255u, unatten_pixels[0 * 4 + 0]); + ASSERT_EQ(255u, unatten_pixels[0 * 4 + 1]); + ASSERT_EQ(254u, unatten_pixels[0 * 4 + 2]); + ASSERT_EQ(128u, unatten_pixels[0 * 4 + 3]); + ASSERT_EQ(0u, unatten_pixels[1 * 4 + 0]); + ASSERT_EQ(0u, unatten_pixels[1 * 4 + 1]); + ASSERT_EQ(0u, unatten_pixels[1 * 4 + 2]); + ASSERT_EQ(0u, unatten_pixels[1 * 4 + 3]); + ASSERT_EQ(32u, unatten_pixels[2 * 4 + 0]); + ASSERT_EQ(128u, unatten_pixels[2 * 4 + 1]); + ASSERT_EQ(255u, unatten_pixels[2 * 4 + 2]); + ASSERT_EQ(128u, unatten_pixels[2 * 4 + 3]); + ASSERT_EQ(16u, unatten_pixels[3 * 4 + 0]); + ASSERT_EQ(64u, unatten_pixels[3 * 4 + 1]); + ASSERT_EQ(192u, unatten_pixels[3 * 4 + 2]); + ASSERT_EQ(255u, unatten_pixels[3 * 4 + 3]); + ASSERT_EQ(255u, unatten_pixels[4 * 4 + 0]); + ASSERT_EQ(255u, unatten_pixels[4 * 4 + 1]); + ASSERT_EQ(255u, unatten_pixels[4 * 4 + 2]); + ASSERT_EQ(255u, unatten_pixels[4 * 4 + 3]); + + ARGBAttenuate(orig_pixels, 0, atten_pixels, 0, 5, 1); + ASSERT_EQ(100u, atten_pixels[0 * 4 + 0]); + ASSERT_EQ(65u, atten_pixels[0 * 4 + 1]); + ASSERT_EQ(64u, atten_pixels[0 * 4 + 2]); + ASSERT_EQ(128u, atten_pixels[0 * 4 + 3]); + ASSERT_EQ(0u, atten_pixels[1 * 4 + 0]); + ASSERT_EQ(0u, atten_pixels[1 * 4 + 1]); + ASSERT_EQ(0u, atten_pixels[1 * 4 + 2]); + ASSERT_EQ(0u, atten_pixels[1 * 4 + 3]); + ASSERT_EQ(8u, atten_pixels[2 * 4 + 0]); + ASSERT_EQ(32u, atten_pixels[2 * 4 + 1]); + ASSERT_EQ(96u, atten_pixels[2 * 4 + 2]); + ASSERT_EQ(128u, atten_pixels[2 * 4 + 3]); + ASSERT_EQ(16u, atten_pixels[3 * 4 + 0]); + ASSERT_EQ(64u, atten_pixels[3 * 4 + 1]); + ASSERT_EQ(192u, atten_pixels[3 * 4 + 2]); + ASSERT_EQ(255u, atten_pixels[3 * 4 + 3]); + ASSERT_EQ(255u, atten_pixels[4 * 4 + 0]); + ASSERT_EQ(255u, atten_pixels[4 * 4 + 1]); + ASSERT_EQ(255u, atten_pixels[4 * 4 + 2]); + ASSERT_EQ(255u, atten_pixels[4 * 4 + 3]); + + // test 255 + for (int i = 0; i < 256; ++i) { + orig_pixels[i * 4 + 0] = i; + orig_pixels[i * 4 + 1] = 0; + orig_pixels[i * 4 + 2] = 0; + orig_pixels[i * 4 + 3] = 255; + } + ARGBAttenuate(orig_pixels, 0, atten_pixels, 0, 256, 1); + for (int i = 0; i < 256; ++i) { + ASSERT_EQ(orig_pixels[i * 4 + 0], atten_pixels[i * 4 + 0]); + ASSERT_EQ(0, atten_pixels[i * 4 + 1]); + ASSERT_EQ(0, atten_pixels[i * 4 + 2]); + ASSERT_EQ(255, atten_pixels[i * 4 + 3]); + } for (int i = 0; i < 1280; ++i) { orig_pixels[i * 4 + 0] = i; @@ -86,24 +155,24 @@ TEST_F(LibYUVPlanarTest, TestAttenuate) { ARGBAttenuate(unatten_pixels, 0, atten2_pixels, 0, 1280, 1); } for (int i = 0; i < 1280; ++i) { - EXPECT_NEAR(atten_pixels[i * 4 + 0], atten2_pixels[i * 4 + 0], 2); - EXPECT_NEAR(atten_pixels[i * 4 + 1], atten2_pixels[i * 4 + 1], 2); - EXPECT_NEAR(atten_pixels[i * 4 + 2], atten2_pixels[i * 4 + 2], 2); - EXPECT_NEAR(atten_pixels[i * 4 + 3], atten2_pixels[i * 4 + 3], 2); + ASSERT_NEAR(atten_pixels[i * 4 + 0], atten2_pixels[i * 4 + 0], 1); + ASSERT_NEAR(atten_pixels[i * 4 + 1], atten2_pixels[i * 4 + 1], 1); + ASSERT_NEAR(atten_pixels[i * 4 + 2], atten2_pixels[i * 4 + 2], 1); + ASSERT_NEAR(atten_pixels[i * 4 + 3], atten2_pixels[i * 4 + 3], 1); } // Make sure transparent, 50% and opaque are fully accurate. - EXPECT_EQ(0, atten_pixels[0 * 4 + 0]); - EXPECT_EQ(0, atten_pixels[0 * 4 + 1]); - EXPECT_EQ(0, atten_pixels[0 * 4 + 2]); - EXPECT_EQ(0, atten_pixels[0 * 4 + 3]); - EXPECT_EQ(64, atten_pixels[128 * 4 + 0]); - EXPECT_EQ(32, atten_pixels[128 * 4 + 1]); - EXPECT_EQ(21, atten_pixels[128 * 4 + 2]); - EXPECT_EQ(128, atten_pixels[128 * 4 + 3]); - EXPECT_NEAR(255, atten_pixels[255 * 4 + 0], 1); - EXPECT_NEAR(127, atten_pixels[255 * 4 + 1], 1); - EXPECT_NEAR(85, atten_pixels[255 * 4 + 2], 1); - EXPECT_EQ(255, atten_pixels[255 * 4 + 3]); + ASSERT_EQ(0, atten_pixels[0 * 4 + 0]); + ASSERT_EQ(0, atten_pixels[0 * 4 + 1]); + ASSERT_EQ(0, atten_pixels[0 * 4 + 2]); + ASSERT_EQ(0, atten_pixels[0 * 4 + 3]); + ASSERT_EQ(64, atten_pixels[128 * 4 + 0]); + ASSERT_EQ(32, atten_pixels[128 * 4 + 1]); + ASSERT_EQ(21, atten_pixels[128 * 4 + 2]); + ASSERT_EQ(128, atten_pixels[128 * 4 + 3]); + ASSERT_EQ(255, atten_pixels[255 * 4 + 0]); + ASSERT_EQ(127, atten_pixels[255 * 4 + 1]); + ASSERT_EQ(85, atten_pixels[255 * 4 + 2]); + ASSERT_EQ(255, atten_pixels[255 * 4 + 3]); free_aligned_buffer_page_end(atten2_pixels); free_aligned_buffer_page_end(unatten_pixels); @@ -123,14 +192,14 @@ static int TestAttenuateI(int width, } const int kBpp = 4; const int kStride = width * kBpp; - align_buffer_page_end(src_argb, kStride * height + off); - align_buffer_page_end(dst_argb_c, kStride * height); - align_buffer_page_end(dst_argb_opt, kStride * height); - for (int i = 0; i < kStride * height; ++i) { + align_buffer_page_end(src_argb, (size_t)kStride * height + off); + align_buffer_page_end(dst_argb_c, (size_t)kStride * height); + align_buffer_page_end(dst_argb_opt, (size_t)kStride * height); + for (size_t i = 0; i < (size_t)kStride * height; ++i) { src_argb[i + off] = (fastrand() & 0xff); } - memset(dst_argb_c, 0, kStride * height); - memset(dst_argb_opt, 0, kStride * height); + memset(dst_argb_c, 0, (size_t)kStride * height); + memset(dst_argb_opt, 0, (size_t)kStride * height); MaskCpuFlags(disable_cpu_flags); ARGBAttenuate(src_argb + off, kStride, dst_argb_c, kStride, width, @@ -141,7 +210,7 @@ static int TestAttenuateI(int width, invert * height); } int max_diff = 0; - for (int i = 0; i < kStride * height; ++i) { + for (size_t i = 0; i < (size_t)kStride * height; ++i) { int abs_diff = abs(static_cast(dst_argb_c[i]) - static_cast(dst_argb_opt[i])); if (abs_diff > max_diff) { @@ -155,31 +224,32 @@ static int TestAttenuateI(int width, } TEST_F(LibYUVPlanarTest, ARGBAttenuate_Any) { - int max_diff = TestAttenuateI(benchmark_width_ - 1, benchmark_height_, + int max_diff = TestAttenuateI(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 2); + + ASSERT_EQ(max_diff, 0); } TEST_F(LibYUVPlanarTest, ARGBAttenuate_Unaligned) { int max_diff = TestAttenuateI(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1); - EXPECT_LE(max_diff, 2); + ASSERT_EQ(max_diff, 0); } TEST_F(LibYUVPlanarTest, ARGBAttenuate_Invert) { int max_diff = TestAttenuateI(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, -1, 0); - EXPECT_LE(max_diff, 2); + ASSERT_EQ(max_diff, 0); } TEST_F(LibYUVPlanarTest, ARGBAttenuate_Opt) { int max_diff = TestAttenuateI(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 2); + ASSERT_EQ(max_diff, 0); } static int TestUnattenuateI(int width, @@ -194,16 +264,16 @@ static int TestUnattenuateI(int width, } const int kBpp = 4; const int kStride = width * kBpp; - align_buffer_page_end(src_argb, kStride * height + off); - align_buffer_page_end(dst_argb_c, kStride * height); - align_buffer_page_end(dst_argb_opt, kStride * height); - for (int i = 0; i < kStride * height; ++i) { + align_buffer_page_end(src_argb, (size_t)kStride * height + off); + align_buffer_page_end(dst_argb_c, (size_t)kStride * height); + align_buffer_page_end(dst_argb_opt, (size_t)kStride * height); + for (size_t i = 0; i < (size_t)kStride * height; ++i) { src_argb[i + off] = (fastrand() & 0xff); } ARGBAttenuate(src_argb + off, kStride, src_argb + off, kStride, width, height); - memset(dst_argb_c, 0, kStride * height); - memset(dst_argb_opt, 0, kStride * height); + memset(dst_argb_c, 0, (size_t)kStride * height); + memset(dst_argb_opt, 0, (size_t)kStride * height); MaskCpuFlags(disable_cpu_flags); ARGBUnattenuate(src_argb + off, kStride, dst_argb_c, kStride, width, @@ -214,7 +284,7 @@ static int TestUnattenuateI(int width, invert * height); } int max_diff = 0; - for (int i = 0; i < kStride * height; ++i) { + for (size_t i = 0; i < (size_t)kStride * height; ++i) { int abs_diff = abs(static_cast(dst_argb_c[i]) - static_cast(dst_argb_opt[i])); if (abs_diff > max_diff) { @@ -228,31 +298,31 @@ static int TestUnattenuateI(int width, } TEST_F(LibYUVPlanarTest, ARGBUnattenuate_Any) { - int max_diff = TestUnattenuateI(benchmark_width_ - 1, benchmark_height_, + int max_diff = TestUnattenuateI(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 2); + ASSERT_EQ(max_diff, 0); } TEST_F(LibYUVPlanarTest, ARGBUnattenuate_Unaligned) { int max_diff = TestUnattenuateI(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1); - EXPECT_LE(max_diff, 2); + ASSERT_EQ(max_diff, 0); } TEST_F(LibYUVPlanarTest, ARGBUnattenuate_Invert) { int max_diff = TestUnattenuateI(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, -1, 0); - EXPECT_LE(max_diff, 2); + ASSERT_EQ(max_diff, 0); } TEST_F(LibYUVPlanarTest, ARGBUnattenuate_Opt) { int max_diff = TestUnattenuateI(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 2); + ASSERT_EQ(max_diff, 0); } TEST_F(LibYUVPlanarTest, TestARGBComputeCumulativeSum) { @@ -273,14 +343,15 @@ TEST_F(LibYUVPlanarTest, TestARGBComputeCumulativeSum) { for (int y = 0; y < 16; ++y) { for (int x = 0; x < 16; ++x) { - EXPECT_EQ((x + 1) * (y + 1), added_pixels[y][x][0]); - EXPECT_EQ((x + 1) * (y + 1) * 2, added_pixels[y][x][1]); - EXPECT_EQ((x + 1) * (y + 1) * 3, added_pixels[y][x][2]); - EXPECT_EQ((x + 1) * (y + 1) * 255, added_pixels[y][x][3]); + ASSERT_EQ((x + 1) * (y + 1), added_pixels[y][x][0]); + ASSERT_EQ((x + 1) * (y + 1) * 2, added_pixels[y][x][1]); + ASSERT_EQ((x + 1) * (y + 1) * 3, added_pixels[y][x][2]); + ASSERT_EQ((x + 1) * (y + 1) * 255, added_pixels[y][x][3]); } } } +// near is for legacy platforms. TEST_F(LibYUVPlanarTest, TestARGBGray) { SIMD_ALIGNED(uint8_t orig_pixels[1280][4]); memset(orig_pixels, 0, sizeof(orig_pixels)); @@ -317,30 +388,30 @@ TEST_F(LibYUVPlanarTest, TestARGBGray) { orig_pixels[5][3] = 224u; // Do 16 to test asm version. ARGBGray(&orig_pixels[0][0], 0, 0, 0, 16, 1); - EXPECT_EQ(30u, orig_pixels[0][0]); - EXPECT_EQ(30u, orig_pixels[0][1]); - EXPECT_EQ(30u, orig_pixels[0][2]); - EXPECT_EQ(128u, orig_pixels[0][3]); - EXPECT_EQ(149u, orig_pixels[1][0]); - EXPECT_EQ(149u, orig_pixels[1][1]); - EXPECT_EQ(149u, orig_pixels[1][2]); - EXPECT_EQ(0u, orig_pixels[1][3]); - EXPECT_EQ(76u, orig_pixels[2][0]); - EXPECT_EQ(76u, orig_pixels[2][1]); - EXPECT_EQ(76u, orig_pixels[2][2]); - EXPECT_EQ(255u, orig_pixels[2][3]); - EXPECT_EQ(0u, orig_pixels[3][0]); - EXPECT_EQ(0u, orig_pixels[3][1]); - EXPECT_EQ(0u, orig_pixels[3][2]); - EXPECT_EQ(255u, orig_pixels[3][3]); - EXPECT_EQ(255u, orig_pixels[4][0]); - EXPECT_EQ(255u, orig_pixels[4][1]); - EXPECT_EQ(255u, orig_pixels[4][2]); - EXPECT_EQ(255u, orig_pixels[4][3]); - EXPECT_EQ(96u, orig_pixels[5][0]); - EXPECT_EQ(96u, orig_pixels[5][1]); - EXPECT_EQ(96u, orig_pixels[5][2]); - EXPECT_EQ(224u, orig_pixels[5][3]); + ASSERT_NEAR(29u, orig_pixels[0][0], 1); + ASSERT_NEAR(29u, orig_pixels[0][1], 1); + ASSERT_NEAR(29u, orig_pixels[0][2], 1); + ASSERT_EQ(128u, orig_pixels[0][3]); + ASSERT_EQ(149u, orig_pixels[1][0]); + ASSERT_EQ(149u, orig_pixels[1][1]); + ASSERT_EQ(149u, orig_pixels[1][2]); + ASSERT_EQ(0u, orig_pixels[1][3]); + ASSERT_NEAR(77u, orig_pixels[2][0], 1); + ASSERT_NEAR(77u, orig_pixels[2][1], 1); + ASSERT_NEAR(77u, orig_pixels[2][2], 1); + ASSERT_EQ(255u, orig_pixels[2][3]); + ASSERT_EQ(0u, orig_pixels[3][0]); + ASSERT_EQ(0u, orig_pixels[3][1]); + ASSERT_EQ(0u, orig_pixels[3][2]); + ASSERT_EQ(255u, orig_pixels[3][3]); + ASSERT_EQ(255u, orig_pixels[4][0]); + ASSERT_EQ(255u, orig_pixels[4][1]); + ASSERT_EQ(255u, orig_pixels[4][2]); + ASSERT_EQ(255u, orig_pixels[4][3]); + ASSERT_NEAR(97u, orig_pixels[5][0], 1); + ASSERT_NEAR(97u, orig_pixels[5][1], 1); + ASSERT_NEAR(97u, orig_pixels[5][2], 1); + ASSERT_EQ(224u, orig_pixels[5][3]); for (int i = 0; i < 1280; ++i) { orig_pixels[i][0] = i; orig_pixels[i][1] = i / 2; @@ -389,30 +460,30 @@ TEST_F(LibYUVPlanarTest, TestARGBGrayTo) { orig_pixels[5][3] = 224u; // Do 16 to test asm version. ARGBGrayTo(&orig_pixels[0][0], 0, &gray_pixels[0][0], 0, 16, 1); - EXPECT_EQ(30u, gray_pixels[0][0]); - EXPECT_EQ(30u, gray_pixels[0][1]); - EXPECT_EQ(30u, gray_pixels[0][2]); - EXPECT_EQ(128u, gray_pixels[0][3]); - EXPECT_EQ(149u, gray_pixels[1][0]); - EXPECT_EQ(149u, gray_pixels[1][1]); - EXPECT_EQ(149u, gray_pixels[1][2]); - EXPECT_EQ(0u, gray_pixels[1][3]); - EXPECT_EQ(76u, gray_pixels[2][0]); - EXPECT_EQ(76u, gray_pixels[2][1]); - EXPECT_EQ(76u, gray_pixels[2][2]); - EXPECT_EQ(255u, gray_pixels[2][3]); - EXPECT_EQ(0u, gray_pixels[3][0]); - EXPECT_EQ(0u, gray_pixels[3][1]); - EXPECT_EQ(0u, gray_pixels[3][2]); - EXPECT_EQ(255u, gray_pixels[3][3]); - EXPECT_EQ(255u, gray_pixels[4][0]); - EXPECT_EQ(255u, gray_pixels[4][1]); - EXPECT_EQ(255u, gray_pixels[4][2]); - EXPECT_EQ(255u, gray_pixels[4][3]); - EXPECT_EQ(96u, gray_pixels[5][0]); - EXPECT_EQ(96u, gray_pixels[5][1]); - EXPECT_EQ(96u, gray_pixels[5][2]); - EXPECT_EQ(224u, gray_pixels[5][3]); + ASSERT_NEAR(30u, gray_pixels[0][0], 1); + ASSERT_NEAR(30u, gray_pixels[0][1], 1); + ASSERT_NEAR(30u, gray_pixels[0][2], 1); + ASSERT_NEAR(128u, gray_pixels[0][3], 1); + ASSERT_NEAR(149u, gray_pixels[1][0], 1); + ASSERT_NEAR(149u, gray_pixels[1][1], 1); + ASSERT_NEAR(149u, gray_pixels[1][2], 1); + ASSERT_NEAR(0u, gray_pixels[1][3], 1); + ASSERT_NEAR(76u, gray_pixels[2][0], 1); + ASSERT_NEAR(76u, gray_pixels[2][1], 1); + ASSERT_NEAR(76u, gray_pixels[2][2], 1); + ASSERT_NEAR(255u, gray_pixels[2][3], 1); + ASSERT_NEAR(0u, gray_pixels[3][0], 1); + ASSERT_NEAR(0u, gray_pixels[3][1], 1); + ASSERT_NEAR(0u, gray_pixels[3][2], 1); + ASSERT_NEAR(255u, gray_pixels[3][3], 1); + ASSERT_NEAR(255u, gray_pixels[4][0], 1); + ASSERT_NEAR(255u, gray_pixels[4][1], 1); + ASSERT_NEAR(255u, gray_pixels[4][2], 1); + ASSERT_NEAR(255u, gray_pixels[4][3], 1); + ASSERT_NEAR(96u, gray_pixels[5][0], 1); + ASSERT_NEAR(96u, gray_pixels[5][1], 1); + ASSERT_NEAR(96u, gray_pixels[5][2], 1); + ASSERT_NEAR(224u, gray_pixels[5][3], 1); for (int i = 0; i < 1280; ++i) { orig_pixels[i][0] = i; orig_pixels[i][1] = i / 2; @@ -422,6 +493,50 @@ TEST_F(LibYUVPlanarTest, TestARGBGrayTo) { for (int i = 0; i < benchmark_pixels_div1280_; ++i) { ARGBGrayTo(&orig_pixels[0][0], 0, &gray_pixels[0][0], 0, 1280, 1); } + + for (int i = 0; i < 256; ++i) { + orig_pixels[i][0] = i; + orig_pixels[i][1] = i; + orig_pixels[i][2] = i; + orig_pixels[i][3] = i; + } + ARGBGray(&orig_pixels[0][0], 0, 0, 0, 256, 1); + for (int i = 0; i < 256; ++i) { + ASSERT_EQ(i, orig_pixels[i][0]); + ASSERT_EQ(i, orig_pixels[i][1]); + ASSERT_EQ(i, orig_pixels[i][2]); + ASSERT_EQ(i, orig_pixels[i][3]); + } + + // Test RGBX input with uninitialized alpha channel under MSan. + SIMD_ALIGNED(uint8_t gray_pixels_c[37][4]); + for (int i = 0; i < 37; ++i) { + orig_pixels[i][0] = static_cast(i * 7); + orig_pixels[i][1] = static_cast(i * 13); + orig_pixels[i][2] = static_cast(i * 23); + orig_pixels[i][3] = 0u; + } + MaskCpuFlags(disable_cpu_flags_); + ARGBGrayTo(&orig_pixels[0][0], 0, &gray_pixels_c[0][0], 0, 37, 1); + MaskCpuFlags(benchmark_cpu_info_); + for (int i = 0; i < 37; ++i) { + MSAN_POISON(&orig_pixels[i][3], 1); + } + MSAN_POISON(gray_pixels, sizeof(gray_pixels)); + ARGBGrayTo(&orig_pixels[0][0], 0, &gray_pixels[0][0], 0, 37, 1); + for (int i = 0; i < 37; ++i) { + MSAN_CHECK_INITIALIZED(&gray_pixels[i][0], 3); + ASSERT_EQ(gray_pixels_c[i][0], gray_pixels[i][0]); + ASSERT_EQ(gray_pixels_c[i][1], gray_pixels[i][1]); + ASSERT_EQ(gray_pixels_c[i][2], gray_pixels[i][2]); + } + ARGBGray(&orig_pixels[0][0], 0, 0, 0, 37, 1); + for (int i = 0; i < 37; ++i) { + MSAN_CHECK_INITIALIZED(&orig_pixels[i][0], 3); + ASSERT_EQ(gray_pixels_c[i][0], orig_pixels[i][0]); + ASSERT_EQ(gray_pixels_c[i][1], orig_pixels[i][1]); + ASSERT_EQ(gray_pixels_c[i][2], orig_pixels[i][2]); + } } TEST_F(LibYUVPlanarTest, TestARGBSepia) { @@ -460,30 +575,30 @@ TEST_F(LibYUVPlanarTest, TestARGBSepia) { orig_pixels[5][3] = 224u; // Do 16 to test asm version. ARGBSepia(&orig_pixels[0][0], 0, 0, 0, 16, 1); - EXPECT_EQ(33u, orig_pixels[0][0]); - EXPECT_EQ(43u, orig_pixels[0][1]); - EXPECT_EQ(47u, orig_pixels[0][2]); - EXPECT_EQ(128u, orig_pixels[0][3]); - EXPECT_EQ(135u, orig_pixels[1][0]); - EXPECT_EQ(175u, orig_pixels[1][1]); - EXPECT_EQ(195u, orig_pixels[1][2]); - EXPECT_EQ(0u, orig_pixels[1][3]); - EXPECT_EQ(69u, orig_pixels[2][0]); - EXPECT_EQ(89u, orig_pixels[2][1]); - EXPECT_EQ(99u, orig_pixels[2][2]); - EXPECT_EQ(255u, orig_pixels[2][3]); - EXPECT_EQ(0u, orig_pixels[3][0]); - EXPECT_EQ(0u, orig_pixels[3][1]); - EXPECT_EQ(0u, orig_pixels[3][2]); - EXPECT_EQ(255u, orig_pixels[3][3]); - EXPECT_EQ(239u, orig_pixels[4][0]); - EXPECT_EQ(255u, orig_pixels[4][1]); - EXPECT_EQ(255u, orig_pixels[4][2]); - EXPECT_EQ(255u, orig_pixels[4][3]); - EXPECT_EQ(88u, orig_pixels[5][0]); - EXPECT_EQ(114u, orig_pixels[5][1]); - EXPECT_EQ(127u, orig_pixels[5][2]); - EXPECT_EQ(224u, orig_pixels[5][3]); + ASSERT_EQ(33u, orig_pixels[0][0]); + ASSERT_EQ(43u, orig_pixels[0][1]); + ASSERT_EQ(47u, orig_pixels[0][2]); + ASSERT_EQ(128u, orig_pixels[0][3]); + ASSERT_EQ(135u, orig_pixels[1][0]); + ASSERT_EQ(175u, orig_pixels[1][1]); + ASSERT_EQ(195u, orig_pixels[1][2]); + ASSERT_EQ(0u, orig_pixels[1][3]); + ASSERT_EQ(69u, orig_pixels[2][0]); + ASSERT_EQ(89u, orig_pixels[2][1]); + ASSERT_EQ(99u, orig_pixels[2][2]); + ASSERT_EQ(255u, orig_pixels[2][3]); + ASSERT_EQ(0u, orig_pixels[3][0]); + ASSERT_EQ(0u, orig_pixels[3][1]); + ASSERT_EQ(0u, orig_pixels[3][2]); + ASSERT_EQ(255u, orig_pixels[3][3]); + ASSERT_EQ(239u, orig_pixels[4][0]); + ASSERT_EQ(255u, orig_pixels[4][1]); + ASSERT_EQ(255u, orig_pixels[4][2]); + ASSERT_EQ(255u, orig_pixels[4][3]); + ASSERT_EQ(88u, orig_pixels[5][0]); + ASSERT_EQ(114u, orig_pixels[5][1]); + ASSERT_EQ(127u, orig_pixels[5][2]); + ASSERT_EQ(224u, orig_pixels[5][3]); for (int i = 0; i < 1280; ++i) { orig_pixels[i][0] = i; @@ -531,22 +646,22 @@ TEST_F(LibYUVPlanarTest, TestARGBColorMatrix) { // Do 16 to test asm version. ARGBColorMatrix(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0, &kRGBToSepia[0], 16, 1); - EXPECT_EQ(31u, dst_pixels_opt[0][0]); - EXPECT_EQ(43u, dst_pixels_opt[0][1]); - EXPECT_EQ(47u, dst_pixels_opt[0][2]); - EXPECT_EQ(128u, dst_pixels_opt[0][3]); - EXPECT_EQ(135u, dst_pixels_opt[1][0]); - EXPECT_EQ(175u, dst_pixels_opt[1][1]); - EXPECT_EQ(195u, dst_pixels_opt[1][2]); - EXPECT_EQ(0u, dst_pixels_opt[1][3]); - EXPECT_EQ(67u, dst_pixels_opt[2][0]); - EXPECT_EQ(87u, dst_pixels_opt[2][1]); - EXPECT_EQ(99u, dst_pixels_opt[2][2]); - EXPECT_EQ(255u, dst_pixels_opt[2][3]); - EXPECT_EQ(87u, dst_pixels_opt[3][0]); - EXPECT_EQ(112u, dst_pixels_opt[3][1]); - EXPECT_EQ(127u, dst_pixels_opt[3][2]); - EXPECT_EQ(224u, dst_pixels_opt[3][3]); + ASSERT_EQ(31u, dst_pixels_opt[0][0]); + ASSERT_EQ(43u, dst_pixels_opt[0][1]); + ASSERT_EQ(47u, dst_pixels_opt[0][2]); + ASSERT_EQ(128u, dst_pixels_opt[0][3]); + ASSERT_EQ(135u, dst_pixels_opt[1][0]); + ASSERT_EQ(175u, dst_pixels_opt[1][1]); + ASSERT_EQ(195u, dst_pixels_opt[1][2]); + ASSERT_EQ(0u, dst_pixels_opt[1][3]); + ASSERT_EQ(67u, dst_pixels_opt[2][0]); + ASSERT_EQ(87u, dst_pixels_opt[2][1]); + ASSERT_EQ(99u, dst_pixels_opt[2][2]); + ASSERT_EQ(255u, dst_pixels_opt[2][3]); + ASSERT_EQ(87u, dst_pixels_opt[3][0]); + ASSERT_EQ(112u, dst_pixels_opt[3][1]); + ASSERT_EQ(127u, dst_pixels_opt[3][2]); + ASSERT_EQ(224u, dst_pixels_opt[3][3]); for (int i = 0; i < 1280; ++i) { orig_pixels[i][0] = i; @@ -565,10 +680,10 @@ TEST_F(LibYUVPlanarTest, TestARGBColorMatrix) { } for (int i = 0; i < 1280; ++i) { - EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); - EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); - EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); - EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); + ASSERT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); + ASSERT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); + ASSERT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); + ASSERT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); } } @@ -604,22 +719,22 @@ TEST_F(LibYUVPlanarTest, TestRGBColorMatrix) { orig_pixels[3][3] = 224u; // Do 16 to test asm version. RGBColorMatrix(&orig_pixels[0][0], 0, &kRGBToSepia[0], 0, 0, 16, 1); - EXPECT_EQ(31u, orig_pixels[0][0]); - EXPECT_EQ(43u, orig_pixels[0][1]); - EXPECT_EQ(47u, orig_pixels[0][2]); - EXPECT_EQ(128u, orig_pixels[0][3]); - EXPECT_EQ(135u, orig_pixels[1][0]); - EXPECT_EQ(175u, orig_pixels[1][1]); - EXPECT_EQ(195u, orig_pixels[1][2]); - EXPECT_EQ(0u, orig_pixels[1][3]); - EXPECT_EQ(67u, orig_pixels[2][0]); - EXPECT_EQ(87u, orig_pixels[2][1]); - EXPECT_EQ(99u, orig_pixels[2][2]); - EXPECT_EQ(255u, orig_pixels[2][3]); - EXPECT_EQ(87u, orig_pixels[3][0]); - EXPECT_EQ(112u, orig_pixels[3][1]); - EXPECT_EQ(127u, orig_pixels[3][2]); - EXPECT_EQ(224u, orig_pixels[3][3]); + ASSERT_EQ(31u, orig_pixels[0][0]); + ASSERT_EQ(43u, orig_pixels[0][1]); + ASSERT_EQ(47u, orig_pixels[0][2]); + ASSERT_EQ(128u, orig_pixels[0][3]); + ASSERT_EQ(135u, orig_pixels[1][0]); + ASSERT_EQ(175u, orig_pixels[1][1]); + ASSERT_EQ(195u, orig_pixels[1][2]); + ASSERT_EQ(0u, orig_pixels[1][3]); + ASSERT_EQ(67u, orig_pixels[2][0]); + ASSERT_EQ(87u, orig_pixels[2][1]); + ASSERT_EQ(99u, orig_pixels[2][2]); + ASSERT_EQ(255u, orig_pixels[2][3]); + ASSERT_EQ(87u, orig_pixels[3][0]); + ASSERT_EQ(112u, orig_pixels[3][1]); + ASSERT_EQ(127u, orig_pixels[3][2]); + ASSERT_EQ(224u, orig_pixels[3][3]); for (int i = 0; i < 1280; ++i) { orig_pixels[i][0] = i; @@ -659,22 +774,22 @@ TEST_F(LibYUVPlanarTest, TestARGBColorTable) { orig_pixels[3][3] = 3u; // Do 16 to test asm version. ARGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 16, 1); - EXPECT_EQ(1u, orig_pixels[0][0]); - EXPECT_EQ(2u, orig_pixels[0][1]); - EXPECT_EQ(3u, orig_pixels[0][2]); - EXPECT_EQ(4u, orig_pixels[0][3]); - EXPECT_EQ(5u, orig_pixels[1][0]); - EXPECT_EQ(6u, orig_pixels[1][1]); - EXPECT_EQ(7u, orig_pixels[1][2]); - EXPECT_EQ(8u, orig_pixels[1][3]); - EXPECT_EQ(9u, orig_pixels[2][0]); - EXPECT_EQ(10u, orig_pixels[2][1]); - EXPECT_EQ(11u, orig_pixels[2][2]); - EXPECT_EQ(12u, orig_pixels[2][3]); - EXPECT_EQ(1u, orig_pixels[3][0]); - EXPECT_EQ(6u, orig_pixels[3][1]); - EXPECT_EQ(11u, orig_pixels[3][2]); - EXPECT_EQ(16u, orig_pixels[3][3]); + ASSERT_EQ(1u, orig_pixels[0][0]); + ASSERT_EQ(2u, orig_pixels[0][1]); + ASSERT_EQ(3u, orig_pixels[0][2]); + ASSERT_EQ(4u, orig_pixels[0][3]); + ASSERT_EQ(5u, orig_pixels[1][0]); + ASSERT_EQ(6u, orig_pixels[1][1]); + ASSERT_EQ(7u, orig_pixels[1][2]); + ASSERT_EQ(8u, orig_pixels[1][3]); + ASSERT_EQ(9u, orig_pixels[2][0]); + ASSERT_EQ(10u, orig_pixels[2][1]); + ASSERT_EQ(11u, orig_pixels[2][2]); + ASSERT_EQ(12u, orig_pixels[2][3]); + ASSERT_EQ(1u, orig_pixels[3][0]); + ASSERT_EQ(6u, orig_pixels[3][1]); + ASSERT_EQ(11u, orig_pixels[3][2]); + ASSERT_EQ(16u, orig_pixels[3][3]); for (int i = 0; i < 1280; ++i) { orig_pixels[i][0] = i; @@ -715,22 +830,22 @@ TEST_F(LibYUVPlanarTest, TestRGBColorTable) { orig_pixels[3][3] = 3u; // Do 16 to test asm version. RGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 16, 1); - EXPECT_EQ(1u, orig_pixels[0][0]); - EXPECT_EQ(2u, orig_pixels[0][1]); - EXPECT_EQ(3u, orig_pixels[0][2]); - EXPECT_EQ(0u, orig_pixels[0][3]); // Alpha unchanged. - EXPECT_EQ(5u, orig_pixels[1][0]); - EXPECT_EQ(6u, orig_pixels[1][1]); - EXPECT_EQ(7u, orig_pixels[1][2]); - EXPECT_EQ(1u, orig_pixels[1][3]); // Alpha unchanged. - EXPECT_EQ(9u, orig_pixels[2][0]); - EXPECT_EQ(10u, orig_pixels[2][1]); - EXPECT_EQ(11u, orig_pixels[2][2]); - EXPECT_EQ(2u, orig_pixels[2][3]); // Alpha unchanged. - EXPECT_EQ(1u, orig_pixels[3][0]); - EXPECT_EQ(6u, orig_pixels[3][1]); - EXPECT_EQ(11u, orig_pixels[3][2]); - EXPECT_EQ(3u, orig_pixels[3][3]); // Alpha unchanged. + ASSERT_EQ(1u, orig_pixels[0][0]); + ASSERT_EQ(2u, orig_pixels[0][1]); + ASSERT_EQ(3u, orig_pixels[0][2]); + ASSERT_EQ(0u, orig_pixels[0][3]); // Alpha unchanged. + ASSERT_EQ(5u, orig_pixels[1][0]); + ASSERT_EQ(6u, orig_pixels[1][1]); + ASSERT_EQ(7u, orig_pixels[1][2]); + ASSERT_EQ(1u, orig_pixels[1][3]); // Alpha unchanged. + ASSERT_EQ(9u, orig_pixels[2][0]); + ASSERT_EQ(10u, orig_pixels[2][1]); + ASSERT_EQ(11u, orig_pixels[2][2]); + ASSERT_EQ(2u, orig_pixels[2][3]); // Alpha unchanged. + ASSERT_EQ(1u, orig_pixels[3][0]); + ASSERT_EQ(6u, orig_pixels[3][1]); + ASSERT_EQ(11u, orig_pixels[3][2]); + ASSERT_EQ(3u, orig_pixels[3][3]); // Alpha unchanged. for (int i = 0; i < 1280; ++i) { orig_pixels[i][0] = i; @@ -756,10 +871,10 @@ TEST_F(LibYUVPlanarTest, TestARGBQuantize) { 1280, 1); for (int i = 0; i < 1280; ++i) { - EXPECT_EQ((i / 8 * 8 + 8 / 2) & 255, orig_pixels[i][0]); - EXPECT_EQ((i / 2 / 8 * 8 + 8 / 2) & 255, orig_pixels[i][1]); - EXPECT_EQ((i / 3 / 8 * 8 + 8 / 2) & 255, orig_pixels[i][2]); - EXPECT_EQ(i & 255, orig_pixels[i][3]); + ASSERT_EQ((i / 8 * 8 + 8 / 2) & 255, orig_pixels[i][0]); + ASSERT_EQ((i / 2 / 8 * 8 + 8 / 2) & 255, orig_pixels[i][1]); + ASSERT_EQ((i / 3 / 8 * 8 + 8 / 2) & 255, orig_pixels[i][2]); + ASSERT_EQ(i & 255, orig_pixels[i][3]); } for (int i = 0; i < benchmark_pixels_div1280_; ++i) { ARGBQuantize(&orig_pixels[0][0], 0, (65536 + (8 / 2)) / 8, 8, 8 / 2, 0, 0, @@ -767,27 +882,103 @@ TEST_F(LibYUVPlanarTest, TestARGBQuantize) { } } -TEST_F(LibYUVPlanarTest, TestARGBMirror) { - SIMD_ALIGNED(uint8_t orig_pixels[1280][4]); - SIMD_ALIGNED(uint8_t dst_pixels[1280][4]); +TEST_F(LibYUVPlanarTest, ARGBMirror_Opt) { + align_buffer_page_end(src_pixels, benchmark_width_ * benchmark_height_ * 4); + align_buffer_page_end(dst_pixels_opt, + benchmark_width_ * benchmark_height_ * 4); + align_buffer_page_end(dst_pixels_c, benchmark_width_ * benchmark_height_ * 4); - for (int i = 0; i < 1280; ++i) { - orig_pixels[i][0] = i; - orig_pixels[i][1] = i / 2; - orig_pixels[i][2] = i / 3; - orig_pixels[i][3] = i / 4; - } - ARGBMirror(&orig_pixels[0][0], 0, &dst_pixels[0][0], 0, 1280, 1); + MemRandomize(src_pixels, benchmark_width_ * benchmark_height_ * 4); + MaskCpuFlags(disable_cpu_flags_); + ARGBMirror(src_pixels, benchmark_width_ * 4, dst_pixels_c, + benchmark_width_ * 4, benchmark_width_, benchmark_height_); + MaskCpuFlags(benchmark_cpu_info_); - for (int i = 0; i < 1280; ++i) { - EXPECT_EQ(i & 255, dst_pixels[1280 - 1 - i][0]); - EXPECT_EQ((i / 2) & 255, dst_pixels[1280 - 1 - i][1]); - EXPECT_EQ((i / 3) & 255, dst_pixels[1280 - 1 - i][2]); - EXPECT_EQ((i / 4) & 255, dst_pixels[1280 - 1 - i][3]); + for (int i = 0; i < benchmark_iterations_; ++i) { + ARGBMirror(src_pixels, benchmark_width_ * 4, dst_pixels_opt, + benchmark_width_ * 4, benchmark_width_, benchmark_height_); } - for (int i = 0; i < benchmark_pixels_div1280_; ++i) { - ARGBMirror(&orig_pixels[0][0], 0, &dst_pixels[0][0], 0, 1280, 1); + for (int i = 0; i < benchmark_width_ * benchmark_height_ * 4; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); } + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(dst_pixels_c); +} + +TEST_F(LibYUVPlanarTest, MirrorPlane_16_Opt) { + align_buffer_page_end(src_pixels_8, benchmark_width_ * benchmark_height_ * 2); + align_buffer_page_end(dst_pixels_opt_8, + benchmark_width_ * benchmark_height_ * 2); + align_buffer_page_end(dst_pixels_c_8, + benchmark_width_ * benchmark_height_ * 2); + uint16_t* src_pixels = reinterpret_cast(src_pixels_8); + uint16_t* dst_pixels_opt = reinterpret_cast(dst_pixels_opt_8); + uint16_t* dst_pixels_c = reinterpret_cast(dst_pixels_c_8); + + MemRandomize(src_pixels_8, benchmark_width_ * benchmark_height_ * 2); + MaskCpuFlags(disable_cpu_flags_); + MirrorPlane_16(src_pixels, benchmark_width_, dst_pixels_c, benchmark_width_, + benchmark_width_, benchmark_height_); + MaskCpuFlags(benchmark_cpu_info_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + MirrorPlane_16(src_pixels, benchmark_width_, dst_pixels_opt, + benchmark_width_, benchmark_width_, benchmark_height_); + } + for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { + EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + free_aligned_buffer_page_end(src_pixels_8); + free_aligned_buffer_page_end(dst_pixels_opt_8); + free_aligned_buffer_page_end(dst_pixels_c_8); +} + +TEST_F(LibYUVPlanarTest, MirrorPlane_Opt) { + align_buffer_page_end(src_pixels, benchmark_width_ * benchmark_height_); + align_buffer_page_end(dst_pixels_opt, benchmark_width_ * benchmark_height_); + align_buffer_page_end(dst_pixels_c, benchmark_width_ * benchmark_height_); + + MemRandomize(src_pixels, benchmark_width_ * benchmark_height_); + MaskCpuFlags(disable_cpu_flags_); + MirrorPlane(src_pixels, benchmark_width_, dst_pixels_c, benchmark_width_, + benchmark_width_, benchmark_height_); + MaskCpuFlags(benchmark_cpu_info_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + MirrorPlane(src_pixels, benchmark_width_, dst_pixels_opt, benchmark_width_, + benchmark_width_, benchmark_height_); + } + for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(dst_pixels_c); +} + +TEST_F(LibYUVPlanarTest, MirrorUVPlane_Opt) { + align_buffer_page_end(src_pixels, benchmark_width_ * benchmark_height_ * 2); + align_buffer_page_end(dst_pixels_opt, + benchmark_width_ * benchmark_height_ * 2); + align_buffer_page_end(dst_pixels_c, benchmark_width_ * benchmark_height_ * 2); + + MemRandomize(src_pixels, benchmark_width_ * benchmark_height_ * 2); + MaskCpuFlags(disable_cpu_flags_); + MirrorUVPlane(src_pixels, benchmark_width_ * 2, dst_pixels_c, + benchmark_width_ * 2, benchmark_width_, benchmark_height_); + MaskCpuFlags(benchmark_cpu_info_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + MirrorUVPlane(src_pixels, benchmark_width_ * 2, dst_pixels_opt, + benchmark_width_ * 2, benchmark_width_, benchmark_height_); + } + for (int i = 0; i < benchmark_width_ * benchmark_height_ * 2; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(dst_pixels_c); } TEST_F(LibYUVPlanarTest, TestShade) { @@ -813,34 +1004,34 @@ TEST_F(LibYUVPlanarTest, TestShade) { orig_pixels[3][3] = 0u; // Do 8 pixels to allow opt version to be used. ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 8, 1, 0x80ffffff); - EXPECT_EQ(10u, shade_pixels[0][0]); - EXPECT_EQ(20u, shade_pixels[0][1]); - EXPECT_EQ(40u, shade_pixels[0][2]); - EXPECT_EQ(40u, shade_pixels[0][3]); - EXPECT_EQ(0u, shade_pixels[1][0]); - EXPECT_EQ(0u, shade_pixels[1][1]); - EXPECT_EQ(0u, shade_pixels[1][2]); - EXPECT_EQ(128u, shade_pixels[1][3]); - EXPECT_EQ(0u, shade_pixels[2][0]); - EXPECT_EQ(0u, shade_pixels[2][1]); - EXPECT_EQ(0u, shade_pixels[2][2]); - EXPECT_EQ(0u, shade_pixels[2][3]); - EXPECT_EQ(0u, shade_pixels[3][0]); - EXPECT_EQ(0u, shade_pixels[3][1]); - EXPECT_EQ(0u, shade_pixels[3][2]); - EXPECT_EQ(0u, shade_pixels[3][3]); + ASSERT_EQ(10u, shade_pixels[0][0]); + ASSERT_EQ(20u, shade_pixels[0][1]); + ASSERT_EQ(40u, shade_pixels[0][2]); + ASSERT_EQ(40u, shade_pixels[0][3]); + ASSERT_EQ(0u, shade_pixels[1][0]); + ASSERT_EQ(0u, shade_pixels[1][1]); + ASSERT_EQ(0u, shade_pixels[1][2]); + ASSERT_EQ(128u, shade_pixels[1][3]); + ASSERT_EQ(0u, shade_pixels[2][0]); + ASSERT_EQ(0u, shade_pixels[2][1]); + ASSERT_EQ(0u, shade_pixels[2][2]); + ASSERT_EQ(0u, shade_pixels[2][3]); + ASSERT_EQ(0u, shade_pixels[3][0]); + ASSERT_EQ(0u, shade_pixels[3][1]); + ASSERT_EQ(0u, shade_pixels[3][2]); + ASSERT_EQ(0u, shade_pixels[3][3]); ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 8, 1, 0x80808080); - EXPECT_EQ(5u, shade_pixels[0][0]); - EXPECT_EQ(10u, shade_pixels[0][1]); - EXPECT_EQ(20u, shade_pixels[0][2]); - EXPECT_EQ(40u, shade_pixels[0][3]); + ASSERT_EQ(5u, shade_pixels[0][0]); + ASSERT_EQ(10u, shade_pixels[0][1]); + ASSERT_EQ(20u, shade_pixels[0][2]); + ASSERT_EQ(40u, shade_pixels[0][3]); ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 8, 1, 0x10204080); - EXPECT_EQ(5u, shade_pixels[0][0]); - EXPECT_EQ(5u, shade_pixels[0][1]); - EXPECT_EQ(5u, shade_pixels[0][2]); - EXPECT_EQ(5u, shade_pixels[0][3]); + ASSERT_EQ(5u, shade_pixels[0][0]); + ASSERT_EQ(5u, shade_pixels[0][1]); + ASSERT_EQ(5u, shade_pixels[0][2]); + ASSERT_EQ(5u, shade_pixels[0][3]); for (int i = 0; i < benchmark_pixels_div1280_; ++i) { ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 1280, 1, @@ -891,37 +1082,37 @@ TEST_F(LibYUVPlanarTest, TestARGBInterpolate) { ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, &interpolate_pixels[0][0], 0, 4, 1, 128); - EXPECT_EQ(8u, interpolate_pixels[0][0]); - EXPECT_EQ(16u, interpolate_pixels[0][1]); - EXPECT_EQ(32u, interpolate_pixels[0][2]); - EXPECT_EQ(64u, interpolate_pixels[0][3]); - EXPECT_EQ(0u, interpolate_pixels[1][0]); - EXPECT_EQ(0u, interpolate_pixels[1][1]); - EXPECT_EQ(0u, interpolate_pixels[1][2]); - EXPECT_EQ(128u, interpolate_pixels[1][3]); - EXPECT_EQ(0u, interpolate_pixels[2][0]); - EXPECT_EQ(0u, interpolate_pixels[2][1]); - EXPECT_EQ(0u, interpolate_pixels[2][2]); - EXPECT_EQ(0u, interpolate_pixels[2][3]); - EXPECT_EQ(128u, interpolate_pixels[3][0]); - EXPECT_EQ(128u, interpolate_pixels[3][1]); - EXPECT_EQ(128u, interpolate_pixels[3][2]); - EXPECT_EQ(128u, interpolate_pixels[3][3]); + ASSERT_EQ(8u, interpolate_pixels[0][0]); + ASSERT_EQ(16u, interpolate_pixels[0][1]); + ASSERT_EQ(32u, interpolate_pixels[0][2]); + ASSERT_EQ(64u, interpolate_pixels[0][3]); + ASSERT_EQ(0u, interpolate_pixels[1][0]); + ASSERT_EQ(0u, interpolate_pixels[1][1]); + ASSERT_EQ(0u, interpolate_pixels[1][2]); + ASSERT_EQ(128u, interpolate_pixels[1][3]); + ASSERT_EQ(0u, interpolate_pixels[2][0]); + ASSERT_EQ(0u, interpolate_pixels[2][1]); + ASSERT_EQ(0u, interpolate_pixels[2][2]); + ASSERT_EQ(0u, interpolate_pixels[2][3]); + ASSERT_EQ(128u, interpolate_pixels[3][0]); + ASSERT_EQ(128u, interpolate_pixels[3][1]); + ASSERT_EQ(128u, interpolate_pixels[3][2]); + ASSERT_EQ(128u, interpolate_pixels[3][3]); ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, &interpolate_pixels[0][0], 0, 4, 1, 0); - EXPECT_EQ(16u, interpolate_pixels[0][0]); - EXPECT_EQ(32u, interpolate_pixels[0][1]); - EXPECT_EQ(64u, interpolate_pixels[0][2]); - EXPECT_EQ(128u, interpolate_pixels[0][3]); + ASSERT_EQ(16u, interpolate_pixels[0][0]); + ASSERT_EQ(32u, interpolate_pixels[0][1]); + ASSERT_EQ(64u, interpolate_pixels[0][2]); + ASSERT_EQ(128u, interpolate_pixels[0][3]); ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, &interpolate_pixels[0][0], 0, 4, 1, 192); - EXPECT_EQ(4u, interpolate_pixels[0][0]); - EXPECT_EQ(8u, interpolate_pixels[0][1]); - EXPECT_EQ(16u, interpolate_pixels[0][2]); - EXPECT_EQ(32u, interpolate_pixels[0][3]); + ASSERT_EQ(4u, interpolate_pixels[0][0]); + ASSERT_EQ(8u, interpolate_pixels[0][1]); + ASSERT_EQ(16u, interpolate_pixels[0][2]); + ASSERT_EQ(32u, interpolate_pixels[0][3]); for (int i = 0; i < benchmark_pixels_div1280_; ++i) { ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, @@ -972,37 +1163,37 @@ TEST_F(LibYUVPlanarTest, TestInterpolatePlane) { InterpolatePlane(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0, &interpolate_pixels[0], 0, 16, 1, 128); - EXPECT_EQ(8u, interpolate_pixels[0]); - EXPECT_EQ(16u, interpolate_pixels[1]); - EXPECT_EQ(32u, interpolate_pixels[2]); - EXPECT_EQ(64u, interpolate_pixels[3]); - EXPECT_EQ(0u, interpolate_pixels[4]); - EXPECT_EQ(0u, interpolate_pixels[5]); - EXPECT_EQ(0u, interpolate_pixels[6]); - EXPECT_EQ(128u, interpolate_pixels[7]); - EXPECT_EQ(0u, interpolate_pixels[8]); - EXPECT_EQ(0u, interpolate_pixels[9]); - EXPECT_EQ(0u, interpolate_pixels[10]); - EXPECT_EQ(0u, interpolate_pixels[11]); - EXPECT_EQ(128u, interpolate_pixels[12]); - EXPECT_EQ(128u, interpolate_pixels[13]); - EXPECT_EQ(128u, interpolate_pixels[14]); - EXPECT_EQ(128u, interpolate_pixels[15]); + ASSERT_EQ(8u, interpolate_pixels[0]); + ASSERT_EQ(16u, interpolate_pixels[1]); + ASSERT_EQ(32u, interpolate_pixels[2]); + ASSERT_EQ(64u, interpolate_pixels[3]); + ASSERT_EQ(0u, interpolate_pixels[4]); + ASSERT_EQ(0u, interpolate_pixels[5]); + ASSERT_EQ(0u, interpolate_pixels[6]); + ASSERT_EQ(128u, interpolate_pixels[7]); + ASSERT_EQ(0u, interpolate_pixels[8]); + ASSERT_EQ(0u, interpolate_pixels[9]); + ASSERT_EQ(0u, interpolate_pixels[10]); + ASSERT_EQ(0u, interpolate_pixels[11]); + ASSERT_EQ(128u, interpolate_pixels[12]); + ASSERT_EQ(128u, interpolate_pixels[13]); + ASSERT_EQ(128u, interpolate_pixels[14]); + ASSERT_EQ(128u, interpolate_pixels[15]); InterpolatePlane(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0, &interpolate_pixels[0], 0, 16, 1, 0); - EXPECT_EQ(16u, interpolate_pixels[0]); - EXPECT_EQ(32u, interpolate_pixels[1]); - EXPECT_EQ(64u, interpolate_pixels[2]); - EXPECT_EQ(128u, interpolate_pixels[3]); + ASSERT_EQ(16u, interpolate_pixels[0]); + ASSERT_EQ(32u, interpolate_pixels[1]); + ASSERT_EQ(64u, interpolate_pixels[2]); + ASSERT_EQ(128u, interpolate_pixels[3]); InterpolatePlane(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0, &interpolate_pixels[0], 0, 16, 1, 192); - EXPECT_EQ(4u, interpolate_pixels[0]); - EXPECT_EQ(8u, interpolate_pixels[1]); - EXPECT_EQ(16u, interpolate_pixels[2]); - EXPECT_EQ(32u, interpolate_pixels[3]); + ASSERT_EQ(4u, interpolate_pixels[0]); + ASSERT_EQ(8u, interpolate_pixels[1]); + ASSERT_EQ(16u, interpolate_pixels[2]); + ASSERT_EQ(32u, interpolate_pixels[3]); for (int i = 0; i < benchmark_pixels_div1280_; ++i) { InterpolatePlane(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0, @@ -1010,19 +1201,100 @@ TEST_F(LibYUVPlanarTest, TestInterpolatePlane) { } } +TEST_F(LibYUVPlanarTest, TestInterpolatePlane_16) { + SIMD_ALIGNED(uint16_t orig_pixels_0[1280]); + SIMD_ALIGNED(uint16_t orig_pixels_1[1280]); + SIMD_ALIGNED(uint16_t interpolate_pixels[1280]); + memset(orig_pixels_0, 0, sizeof(orig_pixels_0)); + memset(orig_pixels_1, 0, sizeof(orig_pixels_1)); + + orig_pixels_0[0] = 16u; + orig_pixels_0[1] = 32u; + orig_pixels_0[2] = 64u; + orig_pixels_0[3] = 128u; + orig_pixels_0[4] = 0u; + orig_pixels_0[5] = 0u; + orig_pixels_0[6] = 0u; + orig_pixels_0[7] = 255u; + orig_pixels_0[8] = 0u; + orig_pixels_0[9] = 0u; + orig_pixels_0[10] = 0u; + orig_pixels_0[11] = 0u; + orig_pixels_0[12] = 0u; + orig_pixels_0[13] = 0u; + orig_pixels_0[14] = 0u; + orig_pixels_0[15] = 0u; + + orig_pixels_1[0] = 0u; + orig_pixels_1[1] = 0u; + orig_pixels_1[2] = 0u; + orig_pixels_1[3] = 0u; + orig_pixels_1[4] = 0u; + orig_pixels_1[5] = 0u; + orig_pixels_1[6] = 0u; + orig_pixels_1[7] = 0u; + orig_pixels_1[8] = 0u; + orig_pixels_1[9] = 0u; + orig_pixels_1[10] = 0u; + orig_pixels_1[11] = 0u; + orig_pixels_1[12] = 255u; + orig_pixels_1[13] = 255u; + orig_pixels_1[14] = 255u; + orig_pixels_1[15] = 255u; + + InterpolatePlane_16(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0, + &interpolate_pixels[0], 0, 16, 1, 128); + ASSERT_EQ(8u, interpolate_pixels[0]); + ASSERT_EQ(16u, interpolate_pixels[1]); + ASSERT_EQ(32u, interpolate_pixels[2]); + ASSERT_EQ(64u, interpolate_pixels[3]); + ASSERT_EQ(0u, interpolate_pixels[4]); + ASSERT_EQ(0u, interpolate_pixels[5]); + ASSERT_EQ(0u, interpolate_pixels[6]); + ASSERT_EQ(128u, interpolate_pixels[7]); + ASSERT_EQ(0u, interpolate_pixels[8]); + ASSERT_EQ(0u, interpolate_pixels[9]); + ASSERT_EQ(0u, interpolate_pixels[10]); + ASSERT_EQ(0u, interpolate_pixels[11]); + ASSERT_EQ(128u, interpolate_pixels[12]); + ASSERT_EQ(128u, interpolate_pixels[13]); + ASSERT_EQ(128u, interpolate_pixels[14]); + ASSERT_EQ(128u, interpolate_pixels[15]); + + InterpolatePlane_16(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0, + &interpolate_pixels[0], 0, 16, 1, 0); + ASSERT_EQ(16u, interpolate_pixels[0]); + ASSERT_EQ(32u, interpolate_pixels[1]); + ASSERT_EQ(64u, interpolate_pixels[2]); + ASSERT_EQ(128u, interpolate_pixels[3]); + + InterpolatePlane_16(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0, + &interpolate_pixels[0], 0, 16, 1, 192); + + ASSERT_EQ(4u, interpolate_pixels[0]); + ASSERT_EQ(8u, interpolate_pixels[1]); + ASSERT_EQ(16u, interpolate_pixels[2]); + ASSERT_EQ(32u, interpolate_pixels[3]); + + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { + InterpolatePlane_16(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0, + &interpolate_pixels[0], 0, 1280, 1, 123); + } +} + #define TESTTERP(FMT_A, BPP_A, STRIDE_A, FMT_B, BPP_B, STRIDE_B, W1280, TERP, \ N, NEG, OFF) \ TEST_F(LibYUVPlanarTest, ARGBInterpolate##TERP##N) { \ - const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ + const int kWidth = W1280; \ const int kHeight = benchmark_height_; \ const int kStrideA = \ (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ const int kStrideB = \ (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ - align_buffer_page_end(src_argb_a, kStrideA* kHeight + OFF); \ - align_buffer_page_end(src_argb_b, kStrideA* kHeight + OFF); \ - align_buffer_page_end(dst_argb_c, kStrideB* kHeight); \ - align_buffer_page_end(dst_argb_opt, kStrideB* kHeight); \ + align_buffer_page_end(src_argb_a, kStrideA * kHeight + OFF); \ + align_buffer_page_end(src_argb_b, kStrideA * kHeight + OFF); \ + align_buffer_page_end(dst_argb_c, kStrideB * kHeight); \ + align_buffer_page_end(dst_argb_opt, kStrideB * kHeight); \ for (int i = 0; i < kStrideA * kHeight; ++i) { \ src_argb_a[i + OFF] = (fastrand() & 0xff); \ src_argb_b[i + OFF] = (fastrand() & 0xff); \ @@ -1036,7 +1308,7 @@ TEST_F(LibYUVPlanarTest, TestInterpolatePlane) { dst_argb_opt, kStrideB, kWidth, NEG kHeight, TERP); \ } \ for (int i = 0; i < kStrideB * kHeight; ++i) { \ - EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]); \ + ASSERT_EQ(dst_argb_c[i], dst_argb_opt[i]); \ } \ free_aligned_buffer_page_end(src_argb_a); \ free_aligned_buffer_page_end(src_argb_b); \ @@ -1045,7 +1317,7 @@ TEST_F(LibYUVPlanarTest, TestInterpolatePlane) { } #define TESTINTERPOLATE(TERP) \ - TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_ - 1, TERP, _Any, +, 0) \ + TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_ + 1, TERP, _Any, +, 0) \ TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Unaligned, +, 1) \ TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Invert, -, 0) \ TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Opt, +, 0) @@ -1062,7 +1334,8 @@ static int TestBlend(int width, int disable_cpu_flags, int benchmark_cpu_info, int invert, - int off) { + int off, + int attenuate) { if (width < 1) { width = 1; } @@ -1076,10 +1349,12 @@ static int TestBlend(int width, src_argb_a[i + off] = (fastrand() & 0xff); src_argb_b[i + off] = (fastrand() & 0xff); } - ARGBAttenuate(src_argb_a + off, kStride, src_argb_a + off, kStride, width, - height); - ARGBAttenuate(src_argb_b + off, kStride, src_argb_b + off, kStride, width, - height); + MemRandomize(src_argb_a, kStride * height + off); + MemRandomize(src_argb_b, kStride * height + off); + if (attenuate) { + ARGBAttenuate(src_argb_a + off, kStride, src_argb_a + off, kStride, width, + height); + } memset(dst_argb_c, 255, kStride * height); memset(dst_argb_opt, 255, kStride * height); @@ -1108,30 +1383,37 @@ static int TestBlend(int width, TEST_F(LibYUVPlanarTest, ARGBBlend_Any) { int max_diff = - TestBlend(benchmark_width_ - 4, benchmark_height_, benchmark_iterations_, - disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 1); + TestBlend(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_, +1, 0, 1); + ASSERT_LE(max_diff, 1); } TEST_F(LibYUVPlanarTest, ARGBBlend_Unaligned) { int max_diff = TestBlend(benchmark_width_, benchmark_height_, benchmark_iterations_, - disable_cpu_flags_, benchmark_cpu_info_, +1, 1); - EXPECT_LE(max_diff, 1); + disable_cpu_flags_, benchmark_cpu_info_, +1, 1, 1); + ASSERT_LE(max_diff, 1); } TEST_F(LibYUVPlanarTest, ARGBBlend_Invert) { int max_diff = TestBlend(benchmark_width_, benchmark_height_, benchmark_iterations_, - disable_cpu_flags_, benchmark_cpu_info_, -1, 0); - EXPECT_LE(max_diff, 1); + disable_cpu_flags_, benchmark_cpu_info_, -1, 0, 1); + ASSERT_LE(max_diff, 1); +} + +TEST_F(LibYUVPlanarTest, ARGBBlend_Unattenuated) { + int max_diff = + TestBlend(benchmark_width_, benchmark_height_, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_, +1, 0, 0); + ASSERT_LE(max_diff, 1); } TEST_F(LibYUVPlanarTest, ARGBBlend_Opt) { int max_diff = TestBlend(benchmark_width_, benchmark_height_, benchmark_iterations_, - disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 1); + disable_cpu_flags_, benchmark_cpu_info_, +1, 0, 1); + ASSERT_LE(max_diff, 1); } static void TestBlendPlane(int width, @@ -1163,14 +1445,14 @@ static void TestBlendPlane(int width, BlendPlane(src_argb_a + off, width, src_argb_b + off, width, src_argb_alpha + off, width, dst_argb_opt + off, width, width, 1); for (int i = 0; i < width; ++i) { - EXPECT_EQ(src_argb_a[i + off], dst_argb_opt[i + off]); + ASSERT_EQ(src_argb_a[i + off], dst_argb_opt[i + off]); } // Test destination is maintained exactly if alpha is 0. memset(src_argb_alpha + off, 0, width); BlendPlane(src_argb_a + off, width, src_argb_b + off, width, src_argb_alpha + off, width, dst_argb_opt + off, width, width, 1); for (int i = 0; i < width; ++i) { - EXPECT_EQ(src_argb_b[i + off], dst_argb_opt[i + off]); + ASSERT_EQ(src_argb_b[i + off], dst_argb_opt[i + off]); } for (int i = 0; i < kStride * height; ++i) { src_argb_a[i + off] = (fastrand() & 0xff); @@ -1189,7 +1471,7 @@ static void TestBlendPlane(int width, invert * height); } for (int i = 0; i < kStride * height; ++i) { - EXPECT_EQ(dst_argb_c[i + off], dst_argb_opt[i + off]); + ASSERT_EQ(dst_argb_c[i + off], dst_argb_opt[i + off]); } free_aligned_buffer_page_end(src_argb_a); free_aligned_buffer_page_end(src_argb_b); @@ -1207,7 +1489,7 @@ TEST_F(LibYUVPlanarTest, BlendPlane_Unaligned) { disable_cpu_flags_, benchmark_cpu_info_, +1, 1); } TEST_F(LibYUVPlanarTest, BlendPlane_Any) { - TestBlendPlane(benchmark_width_ - 4, benchmark_height_, benchmark_iterations_, + TestBlendPlane(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1); } TEST_F(LibYUVPlanarTest, BlendPlane_Invert) { @@ -1215,7 +1497,7 @@ TEST_F(LibYUVPlanarTest, BlendPlane_Invert) { disable_cpu_flags_, benchmark_cpu_info_, -1, 1); } -#define SUBSAMPLE(v, a) ((((v) + (a)-1)) / (a)) +#define SUBSAMPLE(v, a) ((((v) + (a) - 1)) / (a)) static void TestI420Blend(int width, int height, @@ -1270,11 +1552,11 @@ static void TestI420Blend(int width, width, invert * height); } for (int i = 0; i < width * height; ++i) { - EXPECT_EQ(dst_y_c[i + off], dst_y_opt[i + off]); + ASSERT_EQ(dst_y_c[i + off], dst_y_opt[i + off]); } for (int i = 0; i < kSizeUV; ++i) { - EXPECT_EQ(dst_u_c[i + off], dst_u_opt[i + off]); - EXPECT_EQ(dst_v_c[i + off], dst_v_opt[i + off]); + ASSERT_EQ(dst_u_c[i + off], dst_u_opt[i + off]); + ASSERT_EQ(dst_v_c[i + off], dst_v_opt[i + off]); } free_aligned_buffer_page_end(src_y0); free_aligned_buffer_page_end(src_u0); @@ -1302,7 +1584,7 @@ TEST_F(LibYUVPlanarTest, I420Blend_Unaligned) { // TODO(fbarchard): DISABLED because _Any uses C. Avoid C and re-enable. TEST_F(LibYUVPlanarTest, DISABLED_I420Blend_Any) { - TestI420Blend(benchmark_width_ - 4, benchmark_height_, benchmark_iterations_, + TestI420Blend(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); } TEST_F(LibYUVPlanarTest, I420Blend_Invert) { @@ -1310,90 +1592,105 @@ TEST_F(LibYUVPlanarTest, I420Blend_Invert) { disable_cpu_flags_, benchmark_cpu_info_, -1, 0); } +#ifdef ENABLE_ROW_TESTS TEST_F(LibYUVPlanarTest, TestAffine) { - SIMD_ALIGNED(uint8_t orig_pixels_0[1280][4]); + SIMD_ALIGNED(uint8_t orig_pixels_0[2][1280][4]); SIMD_ALIGNED(uint8_t interpolate_pixels_C[1280][4]); - for (int i = 0; i < 1280; ++i) { - for (int j = 0; j < 4; ++j) { - orig_pixels_0[i][j] = i; + for (int r = 0; r < 2; ++r) { + for (int i = 0; i < 1280; ++i) { + for (int j = 0; j < 4; ++j) { + orig_pixels_0[r][i][j] = i + r * 17; + } } } - float uv_step[4] = {0.f, 0.f, 0.75f, 0.f}; + float uv_step[4] = {0.f, 0.f, 0.75f, 1.f / 1280.f}; + const int stride = 1280 * 4; - ARGBAffineRow_C(&orig_pixels_0[0][0], 0, &interpolate_pixels_C[0][0], uv_step, - 1280); - EXPECT_EQ(0u, interpolate_pixels_C[0][0]); - EXPECT_EQ(96u, interpolate_pixels_C[128][0]); - EXPECT_EQ(191u, interpolate_pixels_C[255][3]); + ARGBAffineRow_C(&orig_pixels_0[0][0][0], stride, &interpolate_pixels_C[0][0], + uv_step, 1280); + ASSERT_EQ(0u, interpolate_pixels_C[0][0]); + ASSERT_EQ(96u, interpolate_pixels_C[128][0]); + ASSERT_EQ(191u, interpolate_pixels_C[255][3]); -#if defined(HAS_ARGBAFFINEROW_SSE2) - SIMD_ALIGNED(uint8_t interpolate_pixels_Opt[1280][4]); - ARGBAffineRow_SSE2(&orig_pixels_0[0][0], 0, &interpolate_pixels_Opt[0][0], - uv_step, 1280); - EXPECT_EQ(0, memcmp(interpolate_pixels_Opt, interpolate_pixels_C, 1280 * 4)); +#if defined(HAS_ARGBAFFINEROW_AVX2) + int has_avx2 = TestCpuFlag(kCpuHasAVX2); + if (has_avx2) { + SIMD_ALIGNED(uint8_t interpolate_pixels_Opt[1280][4]); + ARGBAffineRow_AVX2(&orig_pixels_0[0][0][0], stride, + &interpolate_pixels_Opt[0][0], uv_step, 1280); + ASSERT_EQ(0, + memcmp(interpolate_pixels_Opt, interpolate_pixels_C, 1280 * 4)); + ARGBAffineRow_AVX2(&orig_pixels_0[0][0][0], stride, + &interpolate_pixels_Opt[0][0], uv_step, 1279); + ASSERT_EQ(0, + memcmp(interpolate_pixels_Opt, interpolate_pixels_C, 1279 * 4)); - int has_sse2 = TestCpuFlag(kCpuHasSSE2); - if (has_sse2) { for (int i = 0; i < benchmark_pixels_div1280_; ++i) { - ARGBAffineRow_SSE2(&orig_pixels_0[0][0], 0, &interpolate_pixels_Opt[0][0], - uv_step, 1280); + ARGBAffineRow_AVX2(&orig_pixels_0[0][0][0], stride, + &interpolate_pixels_Opt[0][0], uv_step, 1280); + } + } +#endif +#if defined(HAS_ARGBAFFINEROW_NEON) + int has_neon = TestCpuFlag(kCpuHasNEON); + if (has_neon) { + SIMD_ALIGNED(uint8_t interpolate_pixels_Opt[1280][4]); + ARGBAffineRow_NEON(&orig_pixels_0[0][0][0], stride, + &interpolate_pixels_Opt[0][0], uv_step, 1280); + ASSERT_EQ(0, + memcmp(interpolate_pixels_Opt, interpolate_pixels_C, 1280 * 4)); + ARGBAffineRow_NEON(&orig_pixels_0[0][0][0], stride, + &interpolate_pixels_Opt[0][0], uv_step, 1279); + ASSERT_EQ(0, + memcmp(interpolate_pixels_Opt, interpolate_pixels_C, 1279 * 4)); + + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { + ARGBAffineRow_NEON(&orig_pixels_0[0][0][0], stride, + &interpolate_pixels_Opt[0][0], uv_step, 1280); } } #endif } +#endif // ENABLE_ROW_TESTS -TEST_F(LibYUVPlanarTest, TestCopyPlane) { - int err = 0; - int yw = benchmark_width_; - int yh = benchmark_height_; - int b = 12; - int i, j; - - int y_plane_size = (yw + b * 2) * (yh + b * 2); - align_buffer_page_end(orig_y, y_plane_size); +static int TestCopyPlane(int benchmark_width, + int benchmark_height, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info, + int invert, + int off) { + const int y_plane_size = benchmark_width * benchmark_height; + align_buffer_page_end(orig_y, y_plane_size + off); align_buffer_page_end(dst_c, y_plane_size); align_buffer_page_end(dst_opt, y_plane_size); - memset(orig_y, 0, y_plane_size); - memset(dst_c, 0, y_plane_size); - memset(dst_opt, 0, y_plane_size); - - // Fill image buffers with random data. - for (i = b; i < (yh + b); ++i) { - for (j = b; j < (yw + b); ++j) { - orig_y[i * (yw + b * 2) + j] = fastrand() & 0xff; - } - } - - // Fill destination buffers with random data. - for (i = 0; i < y_plane_size; ++i) { - uint8_t random_number = fastrand() & 0x7f; - dst_c[i] = random_number; - dst_opt[i] = dst_c[i]; - } - - int y_off = b * (yw + b * 2) + b; - - int y_st = yw + b * 2; - int stride = 8; + MemRandomize(orig_y + off, y_plane_size); + memset(dst_c, 1, y_plane_size); + memset(dst_opt, 2, y_plane_size); // Disable all optimizations. - MaskCpuFlags(disable_cpu_flags_); - for (j = 0; j < benchmark_iterations_; j++) { - CopyPlane(orig_y + y_off, y_st, dst_c + y_off, stride, yw, yh); + MaskCpuFlags(disable_cpu_flags); + for (int i = 0; i < benchmark_iterations; i++) { + CopyPlane(orig_y + off, benchmark_width, dst_c, benchmark_width, + benchmark_width, benchmark_height * invert); } // Enable optimizations. - MaskCpuFlags(benchmark_cpu_info_); - for (j = 0; j < benchmark_iterations_; j++) { - CopyPlane(orig_y + y_off, y_st, dst_opt + y_off, stride, yw, yh); + MaskCpuFlags(benchmark_cpu_info); + for (int i = 0; i < benchmark_iterations; i++) { + CopyPlane(orig_y + off, benchmark_width, dst_opt, benchmark_width, + benchmark_width, benchmark_height * invert); } - for (i = 0; i < y_plane_size; ++i) { - if (dst_c[i] != dst_opt[i]) { - ++err; + int max_diff = 0; + for (int i = 0; i < y_plane_size; ++i) { + int abs_diff = + abs(static_cast(dst_c[i]) - static_cast(dst_opt[i])); + if (abs_diff > max_diff) { + max_diff = abs_diff; } } @@ -1401,7 +1698,321 @@ TEST_F(LibYUVPlanarTest, TestCopyPlane) { free_aligned_buffer_page_end(dst_c); free_aligned_buffer_page_end(dst_opt); - EXPECT_EQ(0, err); + return max_diff; +} + +TEST_F(LibYUVPlanarTest, CopyPlane_Any) { + int max_diff = TestCopyPlane(benchmark_width_ + 1, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0); + ASSERT_LE(max_diff, 0); +} + +TEST_F(LibYUVPlanarTest, CopyPlane_Unaligned) { + int max_diff = + TestCopyPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_, +1, 1); + ASSERT_LE(max_diff, 0); +} + +TEST_F(LibYUVPlanarTest, CopyPlane_Invert) { + int max_diff = + TestCopyPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_, -1, 0); + ASSERT_LE(max_diff, 0); +} + +TEST_F(LibYUVPlanarTest, CopyPlane_Opt) { + int max_diff = + TestCopyPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_, +1, 0); + ASSERT_LE(max_diff, 0); +} + +TEST_F(LibYUVPlanarTest, TestCopyPlaneZero) { + // Test to verify copying a rect with a zero height or width does + // not touch destination memory. + uint8_t src = 42; + uint8_t dst = 0; + + // Disable all optimizations. + MaskCpuFlags(disable_cpu_flags_); + CopyPlane(&src, 0, &dst, 0, 0, 0); + ASSERT_EQ(src, 42); + ASSERT_EQ(dst, 0); + + CopyPlane(&src, 1, &dst, 1, 1, 0); + ASSERT_EQ(src, 42); + ASSERT_EQ(dst, 0); + + CopyPlane(&src, 1, &dst, 1, 0, 1); + ASSERT_EQ(src, 42); + ASSERT_EQ(dst, 0); + + // Enable optimizations. + MaskCpuFlags(benchmark_cpu_info_); + CopyPlane(&src, 0, &dst, 0, 0, 0); + ASSERT_EQ(src, 42); + ASSERT_EQ(dst, 0); + + CopyPlane(&src, 1, &dst, 1, 1, 0); + ASSERT_EQ(src, 42); + ASSERT_EQ(dst, 0); + + CopyPlane(&src, 1, &dst, 1, 0, 1); + ASSERT_EQ(src, 42); + ASSERT_EQ(dst, 0); +} + +static int TestCopyPlane_16(int benchmark_width, + int benchmark_height, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info, + int invert, + int off) { + const int y_plane_size = benchmark_width * benchmark_height; + align_buffer_page_end(orig_y, (y_plane_size + off) * 2); + align_buffer_page_end(dst_c, y_plane_size * 2); + align_buffer_page_end(dst_opt, y_plane_size * 2); + uint16_t* orig_y_16 = reinterpret_cast(orig_y) + off; + uint16_t* dst_c_16 = reinterpret_cast(dst_c); + uint16_t* dst_opt_16 = reinterpret_cast(dst_opt); + + MemRandomize(orig_y, (y_plane_size + off) * 2); + memset(dst_c, 1, y_plane_size * 2); + memset(dst_opt, 2, y_plane_size * 2); + + // Disable all optimizations. + MaskCpuFlags(disable_cpu_flags); + for (int i = 0; i < benchmark_iterations; i++) { + CopyPlane_16(orig_y_16, benchmark_width, dst_c_16, benchmark_width, + benchmark_width, benchmark_height * invert); + } + + // Enable optimizations. + MaskCpuFlags(benchmark_cpu_info); + for (int i = 0; i < benchmark_iterations; i++) { + CopyPlane_16(orig_y_16, benchmark_width, dst_opt_16, benchmark_width, + benchmark_width, benchmark_height * invert); + } + + int max_diff = 0; + for (int i = 0; i < y_plane_size; ++i) { + int abs_diff = + abs(static_cast(dst_c_16[i]) - static_cast(dst_opt_16[i])); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + + free_aligned_buffer_page_end(orig_y); + free_aligned_buffer_page_end(dst_c); + free_aligned_buffer_page_end(dst_opt); + + return max_diff; +} + +TEST_F(LibYUVPlanarTest, CopyPlane_16_Any) { + int max_diff = TestCopyPlane_16(benchmark_width_ + 1, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0); + ASSERT_LE(max_diff, 0); +} + +TEST_F(LibYUVPlanarTest, CopyPlane_16_Unaligned) { + int max_diff = TestCopyPlane_16(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 1); + ASSERT_LE(max_diff, 0); +} + +TEST_F(LibYUVPlanarTest, CopyPlane_16_Invert) { + int max_diff = TestCopyPlane_16(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, -1, 0); + ASSERT_LE(max_diff, 0); +} + +TEST_F(LibYUVPlanarTest, CopyPlane_16_Opt) { + int max_diff = TestCopyPlane_16(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0); + ASSERT_LE(max_diff, 0); +} + +TEST_F(LibYUVPlanarTest, TestDetilePlane) { + int i, j; + + // orig is tiled. Allocate enough memory for tiles. + int tile_width = (benchmark_width_ + 15) & ~15; + int tile_height = (benchmark_height_ + 15) & ~15; + int tile_plane_size = tile_width * tile_height; + int y_plane_size = benchmark_width_ * benchmark_height_; + align_buffer_page_end(tile_y, tile_plane_size); + align_buffer_page_end(dst_c, y_plane_size); + align_buffer_page_end(dst_opt, y_plane_size); + + MemRandomize(tile_y, tile_plane_size); + memset(dst_c, 0, y_plane_size); + memset(dst_opt, 0, y_plane_size); + + // Disable all optimizations. + MaskCpuFlags(disable_cpu_flags_); + for (j = 0; j < benchmark_iterations_; j++) { + DetilePlane(tile_y, tile_width, dst_c, benchmark_width_, benchmark_width_, + benchmark_height_, 16); + } + + // Enable optimizations. + MaskCpuFlags(benchmark_cpu_info_); + for (j = 0; j < benchmark_iterations_; j++) { + DetilePlane(tile_y, tile_width, dst_opt, benchmark_width_, benchmark_width_, + benchmark_height_, 16); + } + + for (i = 0; i < y_plane_size; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]); + } + + free_aligned_buffer_page_end(tile_y); + free_aligned_buffer_page_end(dst_c); + free_aligned_buffer_page_end(dst_opt); +} + +TEST_F(LibYUVPlanarTest, TestDetilePlane_16) { + int i, j; + + // orig is tiled. Allocate enough memory for tiles. + int tile_width = (benchmark_width_ + 15) & ~15; + int tile_height = (benchmark_height_ + 15) & ~15; + int tile_plane_size = tile_width * tile_height * 2; + int y_plane_size = benchmark_width_ * benchmark_height_ * 2; + align_buffer_page_end(tile_y, tile_plane_size); + align_buffer_page_end(dst_c, y_plane_size); + align_buffer_page_end(dst_opt, y_plane_size); + + MemRandomize(tile_y, tile_plane_size); + memset(dst_c, 0, y_plane_size); + memset(dst_opt, 0, y_plane_size); + + // Disable all optimizations. + MaskCpuFlags(disable_cpu_flags_); + for (j = 0; j < benchmark_iterations_; j++) { + DetilePlane_16((const uint16_t*)tile_y, tile_width, (uint16_t*)dst_c, + benchmark_width_, benchmark_width_, benchmark_height_, 16); + } + + // Enable optimizations. + MaskCpuFlags(benchmark_cpu_info_); + for (j = 0; j < benchmark_iterations_; j++) { + DetilePlane_16((const uint16_t*)tile_y, tile_width, (uint16_t*)dst_opt, + benchmark_width_, benchmark_width_, benchmark_height_, 16); + } + + for (i = 0; i < y_plane_size; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]); + } + + free_aligned_buffer_page_end(tile_y); + free_aligned_buffer_page_end(dst_c); + free_aligned_buffer_page_end(dst_opt); +} + +// Compares DetileSplitUV to 2 step Detile + SplitUV +TEST_F(LibYUVPlanarTest, TestDetileSplitUVPlane_Correctness) { + int i, j; + + // orig is tiled. Allocate enough memory for tiles. + int uv_width = (benchmark_width_ + 1) & ~1; + int tile_width = (uv_width + 15) & ~15; + int tile_height = (benchmark_height_ + 15) & ~15; + int tile_plane_size = tile_width * tile_height; + int uv_plane_size = (uv_width / 2) * benchmark_height_; + align_buffer_page_end(tile_uv, tile_plane_size); + align_buffer_page_end(detiled_uv, tile_plane_size); + align_buffer_page_end(dst_u_two_stage, uv_plane_size); + align_buffer_page_end(dst_u_opt, uv_plane_size); + align_buffer_page_end(dst_v_two_stage, uv_plane_size); + align_buffer_page_end(dst_v_opt, uv_plane_size); + + MemRandomize(tile_uv, tile_plane_size); + memset(detiled_uv, 0, tile_plane_size); + memset(dst_u_two_stage, 0, uv_plane_size); + memset(dst_u_opt, 0, uv_plane_size); + memset(dst_v_two_stage, 0, uv_plane_size); + memset(dst_v_opt, 0, uv_plane_size); + + DetileSplitUVPlane(tile_uv, tile_width, dst_u_opt, uv_width / 2, dst_v_opt, + uv_width / 2, uv_width, benchmark_height_, 16); + + // Benchmark 2 step conversion for comparison. + for (j = 0; j < benchmark_iterations_; j++) { + DetilePlane(tile_uv, tile_width, detiled_uv, uv_width, uv_width, + benchmark_height_, 16); + SplitUVPlane(detiled_uv, uv_width, dst_u_two_stage, uv_width / 2, + dst_v_two_stage, uv_width / 2, uv_width / 2, + benchmark_height_); + } + + for (i = 0; i < uv_plane_size; ++i) { + ASSERT_EQ(dst_u_two_stage[i], dst_u_opt[i]); + ASSERT_EQ(dst_v_two_stage[i], dst_v_opt[i]); + } + + free_aligned_buffer_page_end(tile_uv); + free_aligned_buffer_page_end(detiled_uv); + free_aligned_buffer_page_end(dst_u_two_stage); + free_aligned_buffer_page_end(dst_u_opt); + free_aligned_buffer_page_end(dst_v_two_stage); + free_aligned_buffer_page_end(dst_v_opt); +} + +TEST_F(LibYUVPlanarTest, TestDetileSplitUVPlane_Benchmark) { + int i, j; + + // orig is tiled. Allocate enough memory for tiles. + int uv_width = (benchmark_width_ + 1) & ~1; + int tile_width = (uv_width + 15) & ~15; + int tile_height = (benchmark_height_ + 15) & ~15; + int tile_plane_size = tile_width * tile_height; + int uv_plane_size = (uv_width / 2) * benchmark_height_; + align_buffer_page_end(tile_uv, tile_plane_size); + align_buffer_page_end(dst_u_c, uv_plane_size); + align_buffer_page_end(dst_u_opt, uv_plane_size); + align_buffer_page_end(dst_v_c, uv_plane_size); + align_buffer_page_end(dst_v_opt, uv_plane_size); + + MemRandomize(tile_uv, tile_plane_size); + memset(dst_u_c, 0, uv_plane_size); + memset(dst_u_opt, 0, uv_plane_size); + memset(dst_v_c, 0, uv_plane_size); + memset(dst_v_opt, 0, uv_plane_size); + + // Disable all optimizations. + MaskCpuFlags(disable_cpu_flags_); + + DetileSplitUVPlane(tile_uv, tile_width, dst_u_c, uv_width / 2, dst_v_c, + uv_width / 2, uv_width, benchmark_height_, 16); + + // Enable optimizations. + MaskCpuFlags(benchmark_cpu_info_); + + for (j = 0; j < benchmark_iterations_; j++) { + DetileSplitUVPlane(tile_uv, tile_width, dst_u_opt, uv_width / 2, dst_v_opt, + uv_width / 2, uv_width, benchmark_height_, 16); + } + + for (i = 0; i < uv_plane_size; ++i) { + ASSERT_EQ(dst_u_c[i], dst_u_opt[i]); + ASSERT_EQ(dst_v_c[i], dst_v_opt[i]); + } + + free_aligned_buffer_page_end(tile_uv); + free_aligned_buffer_page_end(dst_u_c); + free_aligned_buffer_page_end(dst_u_opt); + free_aligned_buffer_page_end(dst_v_c); + free_aligned_buffer_page_end(dst_v_opt); } static int TestMultiply(int width, @@ -1416,16 +2027,16 @@ static int TestMultiply(int width, } const int kBpp = 4; const int kStride = width * kBpp; - align_buffer_page_end(src_argb_a, kStride * height + off); - align_buffer_page_end(src_argb_b, kStride * height + off); - align_buffer_page_end(dst_argb_c, kStride * height); - align_buffer_page_end(dst_argb_opt, kStride * height); - for (int i = 0; i < kStride * height; ++i) { + align_buffer_page_end(src_argb_a, (size_t)kStride * height + off); + align_buffer_page_end(src_argb_b, (size_t)kStride * height + off); + align_buffer_page_end(dst_argb_c, (size_t)kStride * height); + align_buffer_page_end(dst_argb_opt, (size_t)kStride * height); + for (size_t i = 0; i < (size_t)kStride * height; ++i) { src_argb_a[i + off] = (fastrand() & 0xff); src_argb_b[i + off] = (fastrand() & 0xff); } - memset(dst_argb_c, 0, kStride * height); - memset(dst_argb_opt, 0, kStride * height); + memset(dst_argb_c, 0, (size_t)kStride * height); + memset(dst_argb_opt, 0, (size_t)kStride * height); MaskCpuFlags(disable_cpu_flags); ARGBMultiply(src_argb_a + off, kStride, src_argb_b + off, kStride, dst_argb_c, @@ -1436,7 +2047,7 @@ static int TestMultiply(int width, dst_argb_opt, kStride, width, invert * height); } int max_diff = 0; - for (int i = 0; i < kStride * height; ++i) { + for (size_t i = 0; i < (size_t)kStride * height; ++i) { int abs_diff = abs(static_cast(dst_argb_c[i]) - static_cast(dst_argb_opt[i])); if (abs_diff > max_diff) { @@ -1451,31 +2062,31 @@ static int TestMultiply(int width, } TEST_F(LibYUVPlanarTest, ARGBMultiply_Any) { - int max_diff = TestMultiply(benchmark_width_ - 1, benchmark_height_, + int max_diff = TestMultiply(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 0); } TEST_F(LibYUVPlanarTest, ARGBMultiply_Unaligned) { int max_diff = TestMultiply(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 0); } TEST_F(LibYUVPlanarTest, ARGBMultiply_Invert) { int max_diff = TestMultiply(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, -1, 0); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 0); } TEST_F(LibYUVPlanarTest, ARGBMultiply_Opt) { int max_diff = TestMultiply(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 0); } static int TestAdd(int width, @@ -1490,16 +2101,16 @@ static int TestAdd(int width, } const int kBpp = 4; const int kStride = width * kBpp; - align_buffer_page_end(src_argb_a, kStride * height + off); - align_buffer_page_end(src_argb_b, kStride * height + off); - align_buffer_page_end(dst_argb_c, kStride * height); - align_buffer_page_end(dst_argb_opt, kStride * height); - for (int i = 0; i < kStride * height; ++i) { + align_buffer_page_end(src_argb_a, (size_t)kStride * height + off); + align_buffer_page_end(src_argb_b, (size_t)kStride * height + off); + align_buffer_page_end(dst_argb_c, (size_t)kStride * height); + align_buffer_page_end(dst_argb_opt, (size_t)kStride * height); + for (size_t i = 0; i < (size_t)kStride * height; ++i) { src_argb_a[i + off] = (fastrand() & 0xff); src_argb_b[i + off] = (fastrand() & 0xff); } - memset(dst_argb_c, 0, kStride * height); - memset(dst_argb_opt, 0, kStride * height); + memset(dst_argb_c, 0, (size_t)kStride * height); + memset(dst_argb_opt, 0, (size_t)kStride * height); MaskCpuFlags(disable_cpu_flags); ARGBAdd(src_argb_a + off, kStride, src_argb_b + off, kStride, dst_argb_c, @@ -1510,7 +2121,7 @@ static int TestAdd(int width, kStride, width, invert * height); } int max_diff = 0; - for (int i = 0; i < kStride * height; ++i) { + for (size_t i = 0; i < (size_t)kStride * height; ++i) { int abs_diff = abs(static_cast(dst_argb_c[i]) - static_cast(dst_argb_opt[i])); if (abs_diff > max_diff) { @@ -1526,30 +2137,30 @@ static int TestAdd(int width, TEST_F(LibYUVPlanarTest, ARGBAdd_Any) { int max_diff = - TestAdd(benchmark_width_ - 1, benchmark_height_, benchmark_iterations_, + TestAdd(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } TEST_F(LibYUVPlanarTest, ARGBAdd_Unaligned) { int max_diff = TestAdd(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } TEST_F(LibYUVPlanarTest, ARGBAdd_Invert) { int max_diff = TestAdd(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, -1, 0); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } TEST_F(LibYUVPlanarTest, ARGBAdd_Opt) { int max_diff = TestAdd(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } static int TestSubtract(int width, @@ -1564,16 +2175,16 @@ static int TestSubtract(int width, } const int kBpp = 4; const int kStride = width * kBpp; - align_buffer_page_end(src_argb_a, kStride * height + off); - align_buffer_page_end(src_argb_b, kStride * height + off); - align_buffer_page_end(dst_argb_c, kStride * height); - align_buffer_page_end(dst_argb_opt, kStride * height); - for (int i = 0; i < kStride * height; ++i) { + align_buffer_page_end(src_argb_a, (size_t)kStride * height + off); + align_buffer_page_end(src_argb_b, (size_t)kStride * height + off); + align_buffer_page_end(dst_argb_c, (size_t)kStride * height); + align_buffer_page_end(dst_argb_opt, (size_t)kStride * height); + for (size_t i = 0; i < (size_t)kStride * height; ++i) { src_argb_a[i + off] = (fastrand() & 0xff); src_argb_b[i + off] = (fastrand() & 0xff); } - memset(dst_argb_c, 0, kStride * height); - memset(dst_argb_opt, 0, kStride * height); + memset(dst_argb_c, 0, (size_t)kStride * height); + memset(dst_argb_opt, 0, (size_t)kStride * height); MaskCpuFlags(disable_cpu_flags); ARGBSubtract(src_argb_a + off, kStride, src_argb_b + off, kStride, dst_argb_c, @@ -1584,7 +2195,7 @@ static int TestSubtract(int width, dst_argb_opt, kStride, width, invert * height); } int max_diff = 0; - for (int i = 0; i < kStride * height; ++i) { + for (size_t i = 0; i < (size_t)kStride * height; ++i) { int abs_diff = abs(static_cast(dst_argb_c[i]) - static_cast(dst_argb_opt[i])); if (abs_diff > max_diff) { @@ -1599,31 +2210,31 @@ static int TestSubtract(int width, } TEST_F(LibYUVPlanarTest, ARGBSubtract_Any) { - int max_diff = TestSubtract(benchmark_width_ - 1, benchmark_height_, + int max_diff = TestSubtract(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } TEST_F(LibYUVPlanarTest, ARGBSubtract_Unaligned) { int max_diff = TestSubtract(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } TEST_F(LibYUVPlanarTest, ARGBSubtract_Invert) { int max_diff = TestSubtract(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, -1, 0); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } TEST_F(LibYUVPlanarTest, ARGBSubtract_Opt) { int max_diff = TestSubtract(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } static int TestSobel(int width, @@ -1638,15 +2249,15 @@ static int TestSobel(int width, } const int kBpp = 4; const int kStride = width * kBpp; - align_buffer_page_end(src_argb_a, kStride * height + off); - align_buffer_page_end(dst_argb_c, kStride * height); - align_buffer_page_end(dst_argb_opt, kStride * height); - memset(src_argb_a, 0, kStride * height + off); - for (int i = 0; i < kStride * height; ++i) { + align_buffer_page_end(src_argb_a, (size_t)kStride * height + off); + align_buffer_page_end(dst_argb_c, (size_t)kStride * height); + align_buffer_page_end(dst_argb_opt, (size_t)kStride * height); + memset(src_argb_a, 0, (size_t)kStride * height + off); + for (size_t i = 0; i < (size_t)kStride * height; ++i) { src_argb_a[i + off] = (fastrand() & 0xff); } - memset(dst_argb_c, 0, kStride * height); - memset(dst_argb_opt, 0, kStride * height); + memset(dst_argb_c, 0, (size_t)kStride * height); + memset(dst_argb_opt, 0, (size_t)kStride * height); MaskCpuFlags(disable_cpu_flags); ARGBSobel(src_argb_a + off, kStride, dst_argb_c, kStride, width, @@ -1657,7 +2268,7 @@ static int TestSobel(int width, invert * height); } int max_diff = 0; - for (int i = 0; i < kStride * height; ++i) { + for (size_t i = 0; i < (size_t)kStride * height; ++i) { int abs_diff = abs(static_cast(dst_argb_c[i]) - static_cast(dst_argb_opt[i])); if (abs_diff > max_diff) { @@ -1672,30 +2283,30 @@ static int TestSobel(int width, TEST_F(LibYUVPlanarTest, ARGBSobel_Any) { int max_diff = - TestSobel(benchmark_width_ - 1, benchmark_height_, benchmark_iterations_, + TestSobel(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBSobel_Unaligned) { int max_diff = TestSobel(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBSobel_Invert) { int max_diff = TestSobel(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, -1, 0); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBSobel_Opt) { int max_diff = TestSobel(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } static int TestSobelToPlane(int width, @@ -1745,31 +2356,31 @@ static int TestSobelToPlane(int width, } TEST_F(LibYUVPlanarTest, ARGBSobelToPlane_Any) { - int max_diff = TestSobelToPlane(benchmark_width_ - 1, benchmark_height_, + int max_diff = TestSobelToPlane(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBSobelToPlane_Unaligned) { int max_diff = TestSobelToPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBSobelToPlane_Invert) { int max_diff = TestSobelToPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, -1, 0); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBSobelToPlane_Opt) { int max_diff = TestSobelToPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } static int TestSobelXY(int width, @@ -1784,15 +2395,15 @@ static int TestSobelXY(int width, } const int kBpp = 4; const int kStride = width * kBpp; - align_buffer_page_end(src_argb_a, kStride * height + off); - align_buffer_page_end(dst_argb_c, kStride * height); - align_buffer_page_end(dst_argb_opt, kStride * height); - memset(src_argb_a, 0, kStride * height + off); - for (int i = 0; i < kStride * height; ++i) { + align_buffer_page_end(src_argb_a, (size_t)kStride * height + off); + align_buffer_page_end(dst_argb_c, (size_t)kStride * height); + align_buffer_page_end(dst_argb_opt, (size_t)kStride * height); + memset(src_argb_a, 0, (size_t)kStride * height + off); + for (size_t i = 0; i < (size_t)kStride * height; ++i) { src_argb_a[i + off] = (fastrand() & 0xff); } - memset(dst_argb_c, 0, kStride * height); - memset(dst_argb_opt, 0, kStride * height); + memset(dst_argb_c, 0, (size_t)kStride * height); + memset(dst_argb_opt, 0, (size_t)kStride * height); MaskCpuFlags(disable_cpu_flags); ARGBSobelXY(src_argb_a + off, kStride, dst_argb_c, kStride, width, @@ -1803,7 +2414,7 @@ static int TestSobelXY(int width, invert * height); } int max_diff = 0; - for (int i = 0; i < kStride * height; ++i) { + for (size_t i = 0; i < (size_t)kStride * height; ++i) { int abs_diff = abs(static_cast(dst_argb_c[i]) - static_cast(dst_argb_opt[i])); if (abs_diff > max_diff) { @@ -1817,31 +2428,31 @@ static int TestSobelXY(int width, } TEST_F(LibYUVPlanarTest, ARGBSobelXY_Any) { - int max_diff = TestSobelXY(benchmark_width_ - 1, benchmark_height_, + int max_diff = TestSobelXY(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBSobelXY_Unaligned) { int max_diff = TestSobelXY(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBSobelXY_Invert) { int max_diff = TestSobelXY(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, -1, 0); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBSobelXY_Opt) { int max_diff = TestSobelXY(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } static int TestBlur(int width, @@ -1857,16 +2468,16 @@ static int TestBlur(int width, } const int kBpp = 4; const int kStride = width * kBpp; - align_buffer_page_end(src_argb_a, kStride * height + off); - align_buffer_page_end(dst_cumsum, width * height * 16); - align_buffer_page_end(dst_argb_c, kStride * height); - align_buffer_page_end(dst_argb_opt, kStride * height); - for (int i = 0; i < kStride * height; ++i) { + const int kCumsumHeight = radius * 2 + 2; + align_buffer_page_end(src_argb_a, (size_t)kStride * height + off); + align_buffer_page_end(dst_cumsum, (size_t)width * kCumsumHeight * 16); + align_buffer_page_end(dst_argb_c, (size_t)kStride * height); + align_buffer_page_end(dst_argb_opt, (size_t)kStride * height); + for (size_t i = 0; i < (size_t)kStride * height; ++i) { src_argb_a[i + off] = (fastrand() & 0xff); } - memset(dst_cumsum, 0, width * height * 16); - memset(dst_argb_c, 0, kStride * height); - memset(dst_argb_opt, 0, kStride * height); + memset(dst_argb_c, 0, (size_t)kStride * height); + memset(dst_argb_opt, 0, (size_t)kStride * height); MaskCpuFlags(disable_cpu_flags); ARGBBlur(src_argb_a + off, kStride, dst_argb_c, kStride, @@ -1879,7 +2490,7 @@ static int TestBlur(int width, invert * height, radius); } int max_diff = 0; - for (int i = 0; i < kStride * height; ++i) { + for (size_t i = 0; i < (size_t)kStride * height; ++i) { int abs_diff = abs(static_cast(dst_argb_c[i]) - static_cast(dst_argb_opt[i])); if (abs_diff > max_diff) { @@ -1893,62 +2504,72 @@ static int TestBlur(int width, return max_diff; } +#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) +#define DISABLED_ARM(name) name +#else +#define DISABLED_ARM(name) DISABLED_##name +#endif + static const int kBlurSize = 55; -TEST_F(LibYUVPlanarTest, ARGBBlur_Any) { +TEST_F(LibYUVPlanarTest, DISABLED_ARM(ARGBBlur_Any)) { int max_diff = - TestBlur(benchmark_width_ - 1, benchmark_height_, benchmark_iterations_, + TestBlur(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0, kBlurSize); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } -TEST_F(LibYUVPlanarTest, ARGBBlur_Unaligned) { +TEST_F(LibYUVPlanarTest, DISABLED_ARM(ARGBBlur_Unaligned)) { int max_diff = TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1, kBlurSize); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } -TEST_F(LibYUVPlanarTest, ARGBBlur_Invert) { +TEST_F(LibYUVPlanarTest, DISABLED_ARM(ARGBBlur_Invert)) { int max_diff = TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, -1, 0, kBlurSize); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } -TEST_F(LibYUVPlanarTest, ARGBBlur_Opt) { +TEST_F(LibYUVPlanarTest, DISABLED_ARM(ARGBBlur_Opt)) { int max_diff = TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0, kBlurSize); - EXPECT_LE(max_diff, 1); + ASSERT_LE(max_diff, 1); } -static const int kBlurSmallSize = 5; -TEST_F(LibYUVPlanarTest, ARGBBlurSmall_Any) { +static const int kBlurSmallSize = 1; +TEST_F(LibYUVPlanarTest, DISABLED_ARM(ARGBBlurSmall_Any)) { int max_diff = - TestBlur(benchmark_width_ - 1, benchmark_height_, benchmark_iterations_, - disable_cpu_flags_, benchmark_cpu_info_, +1, 0, kBlurSmallSize); - EXPECT_LE(max_diff, 1); + TestBlur((benchmark_width_ + 3) / 4 + 1, (benchmark_height_ + 3) / 4, + benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, + +1, 0, kBlurSmallSize); + ASSERT_LE(max_diff, 1); } -TEST_F(LibYUVPlanarTest, ARGBBlurSmall_Unaligned) { +TEST_F(LibYUVPlanarTest, DISABLED_ARM(ARGBBlurSmall_Unaligned)) { int max_diff = - TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_, - disable_cpu_flags_, benchmark_cpu_info_, +1, 1, kBlurSmallSize); - EXPECT_LE(max_diff, 1); + TestBlur((benchmark_width_ + 3) / 4, (benchmark_height_ + 3) / 4, + benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, + +1, 1, kBlurSmallSize); + ASSERT_LE(max_diff, 1); } -TEST_F(LibYUVPlanarTest, ARGBBlurSmall_Invert) { +TEST_F(LibYUVPlanarTest, DISABLED_ARM(ARGBBlurSmall_Invert)) { int max_diff = - TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_, - disable_cpu_flags_, benchmark_cpu_info_, -1, 0, kBlurSmallSize); - EXPECT_LE(max_diff, 1); + TestBlur((benchmark_width_ + 3) / 4, (benchmark_height_ + 3) / 4, + benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, + -1, 0, kBlurSmallSize); + ASSERT_LE(max_diff, 1); } -TEST_F(LibYUVPlanarTest, ARGBBlurSmall_Opt) { +TEST_F(LibYUVPlanarTest, DISABLED_ARM(ARGBBlurSmall_Opt)) { int max_diff = - TestBlur(benchmark_width_, benchmark_height_, benchmark_iterations_, - disable_cpu_flags_, benchmark_cpu_info_, +1, 0, kBlurSmallSize); - EXPECT_LE(max_diff, 1); + TestBlur((benchmark_width_ + 3) / 4, (benchmark_height_ + 3) / 4, + benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, + +1, 0, kBlurSmallSize); + ASSERT_LE(max_diff, 1); } TEST_F(LibYUVPlanarTest, TestARGBPolynomial) { @@ -1992,26 +2613,26 @@ TEST_F(LibYUVPlanarTest, TestARGBPolynomial) { // Do 16 to test asm version. ARGBPolynomial(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0, &kWarmifyPolynomial[0], 16, 1); - EXPECT_EQ(235u, dst_pixels_opt[0][0]); - EXPECT_EQ(0u, dst_pixels_opt[0][1]); - EXPECT_EQ(0u, dst_pixels_opt[0][2]); - EXPECT_EQ(128u, dst_pixels_opt[0][3]); - EXPECT_EQ(0u, dst_pixels_opt[1][0]); - EXPECT_EQ(233u, dst_pixels_opt[1][1]); - EXPECT_EQ(0u, dst_pixels_opt[1][2]); - EXPECT_EQ(0u, dst_pixels_opt[1][3]); - EXPECT_EQ(0u, dst_pixels_opt[2][0]); - EXPECT_EQ(0u, dst_pixels_opt[2][1]); - EXPECT_EQ(241u, dst_pixels_opt[2][2]); - EXPECT_EQ(255u, dst_pixels_opt[2][3]); - EXPECT_EQ(235u, dst_pixels_opt[3][0]); - EXPECT_EQ(233u, dst_pixels_opt[3][1]); - EXPECT_EQ(241u, dst_pixels_opt[3][2]); - EXPECT_EQ(255u, dst_pixels_opt[3][3]); - EXPECT_EQ(10u, dst_pixels_opt[4][0]); - EXPECT_EQ(59u, dst_pixels_opt[4][1]); - EXPECT_EQ(188u, dst_pixels_opt[4][2]); - EXPECT_EQ(224u, dst_pixels_opt[4][3]); + ASSERT_EQ(235u, dst_pixels_opt[0][0]); + ASSERT_EQ(0u, dst_pixels_opt[0][1]); + ASSERT_EQ(0u, dst_pixels_opt[0][2]); + ASSERT_EQ(128u, dst_pixels_opt[0][3]); + ASSERT_EQ(0u, dst_pixels_opt[1][0]); + ASSERT_EQ(233u, dst_pixels_opt[1][1]); + ASSERT_EQ(0u, dst_pixels_opt[1][2]); + ASSERT_EQ(0u, dst_pixels_opt[1][3]); + ASSERT_EQ(0u, dst_pixels_opt[2][0]); + ASSERT_EQ(0u, dst_pixels_opt[2][1]); + ASSERT_EQ(241u, dst_pixels_opt[2][2]); + ASSERT_EQ(255u, dst_pixels_opt[2][3]); + ASSERT_EQ(235u, dst_pixels_opt[3][0]); + ASSERT_EQ(233u, dst_pixels_opt[3][1]); + ASSERT_EQ(241u, dst_pixels_opt[3][2]); + ASSERT_EQ(255u, dst_pixels_opt[3][3]); + ASSERT_EQ(10u, dst_pixels_opt[4][0]); + ASSERT_EQ(59u, dst_pixels_opt[4][1]); + ASSERT_EQ(188u, dst_pixels_opt[4][2]); + ASSERT_EQ(224u, dst_pixels_opt[4][3]); for (int i = 0; i < 1280; ++i) { orig_pixels[i][0] = i; @@ -2031,53 +2652,59 @@ TEST_F(LibYUVPlanarTest, TestARGBPolynomial) { } for (int i = 0; i < 1280; ++i) { - EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); - EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); - EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); - EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); + ASSERT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); + ASSERT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); + ASSERT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); + ASSERT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); } } -int TestHalfFloatPlane(int benchmark_width, - int benchmark_height, - int benchmark_iterations, - int disable_cpu_flags, - int benchmark_cpu_info, - float scale, - int mask) { - int i, j; - const int y_plane_size = benchmark_width * benchmark_height * 2; +static int TestHalfFloatPlane(int benchmark_width, + int benchmark_height, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info, + float scale, + int mask, + int invert, + int off) { + if (benchmark_width <= 0 || benchmark_height <= 0) { + return 0; + } + const size_t y_plane_size = static_cast(benchmark_width) * + static_cast(benchmark_height) * 2; + align_buffer_page_end(orig_y, y_plane_size + off); + align_buffer_page_end(dst_c, y_plane_size); + align_buffer_page_end(dst_opt, y_plane_size); - align_buffer_page_end(orig_y, y_plane_size * 3); - uint8_t* dst_opt = orig_y + y_plane_size; - uint8_t* dst_c = orig_y + y_plane_size * 2; + MemRandomize(orig_y + off, y_plane_size); + memset(dst_c, 1, y_plane_size); + memset(dst_opt, 2, y_plane_size); - MemRandomize(orig_y, y_plane_size); - memset(dst_c, 0, y_plane_size); - memset(dst_opt, 1, y_plane_size); - - for (i = 0; i < y_plane_size / 2; ++i) { - reinterpret_cast(orig_y)[i] &= mask; + for (size_t i = 0; i < y_plane_size / 2; ++i) { + reinterpret_cast(orig_y + off)[i] &= mask; } // Disable all optimizations. MaskCpuFlags(disable_cpu_flags); - for (j = 0; j < benchmark_iterations; j++) { - HalfFloatPlane(reinterpret_cast(orig_y), benchmark_width * 2, - reinterpret_cast(dst_c), benchmark_width * 2, - scale, benchmark_width, benchmark_height); + for (int j = 0; j < benchmark_iterations; j++) { + HalfFloatPlane(reinterpret_cast(orig_y + off), + benchmark_width * 2, reinterpret_cast(dst_c), + benchmark_width * 2, scale, benchmark_width, + benchmark_height * invert); } // Enable optimizations. MaskCpuFlags(benchmark_cpu_info); - for (j = 0; j < benchmark_iterations; j++) { - HalfFloatPlane(reinterpret_cast(orig_y), benchmark_width * 2, - reinterpret_cast(dst_opt), benchmark_width * 2, - scale, benchmark_width, benchmark_height); + for (int j = 0; j < benchmark_iterations; j++) { + HalfFloatPlane(reinterpret_cast(orig_y + off), + benchmark_width * 2, reinterpret_cast(dst_opt), + benchmark_width * 2, scale, benchmark_width, + benchmark_height * invert); } int max_diff = 0; - for (i = 0; i < y_plane_size / 2; ++i) { + for (size_t i = 0; i < y_plane_size / 2; ++i) { int abs_diff = abs(static_cast(reinterpret_cast(dst_c)[i]) - static_cast(reinterpret_cast(dst_opt)[i])); @@ -2087,103 +2714,138 @@ int TestHalfFloatPlane(int benchmark_width, } free_aligned_buffer_page_end(orig_y); + free_aligned_buffer_page_end(dst_c); + free_aligned_buffer_page_end(dst_opt); return max_diff; } -#if defined(__arm__) -static void EnableFlushDenormalToZero(void) { - uint32_t cw; - __asm__ __volatile__( - "vmrs %0, fpscr \n" - "orr %0, %0, #0x1000000 \n" - "vmsr fpscr, %0 \n" - : "=r"(cw)::"memory"); -} -#endif - -// 5 bit exponent with bias of 15 will underflow to a denormal if scale causes -// exponent to be less than 0. 15 - log2(65536) = -1/ This shouldnt normally -// happen since scale is 1/(1<(orig_y + y_plane_size); - float* dst_c = reinterpret_cast(orig_y + y_plane_size * 5); + align_buffer_page_end(orig_y, y_plane_size); + align_buffer_page_end(dst_opt_mem, y_plane_size * 4); + align_buffer_page_end(dst_c_mem, y_plane_size * 4); + float* dst_opt = reinterpret_cast(dst_opt_mem); + float* dst_c = reinterpret_cast(dst_c_mem); MemRandomize(orig_y, y_plane_size); memset(dst_c, 0, y_plane_size * 4); @@ -2208,6 +2870,8 @@ float TestByteToFloat(int benchmark_width, } free_aligned_buffer_page_end(orig_y); + free_aligned_buffer_page_end(dst_opt_mem); + free_aligned_buffer_page_end(dst_c_mem); return max_diff; } @@ -2215,7 +2879,7 @@ TEST_F(LibYUVPlanarTest, TestByteToFloat) { float diff = TestByteToFloat(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, 1.0f); - EXPECT_EQ(0.f, diff); + ASSERT_EQ(0.f, diff); } TEST_F(LibYUVPlanarTest, TestARGBLumaColorTable) { @@ -2253,22 +2917,22 @@ TEST_F(LibYUVPlanarTest, TestARGBLumaColorTable) { // Do 16 to test asm version. ARGBLumaColorTable(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0, &lumacolortable[0], 16, 1); - EXPECT_EQ(253u, dst_pixels_opt[0][0]); - EXPECT_EQ(0u, dst_pixels_opt[0][1]); - EXPECT_EQ(0u, dst_pixels_opt[0][2]); - EXPECT_EQ(128u, dst_pixels_opt[0][3]); - EXPECT_EQ(0u, dst_pixels_opt[1][0]); - EXPECT_EQ(253u, dst_pixels_opt[1][1]); - EXPECT_EQ(0u, dst_pixels_opt[1][2]); - EXPECT_EQ(0u, dst_pixels_opt[1][3]); - EXPECT_EQ(0u, dst_pixels_opt[2][0]); - EXPECT_EQ(0u, dst_pixels_opt[2][1]); - EXPECT_EQ(253u, dst_pixels_opt[2][2]); - EXPECT_EQ(255u, dst_pixels_opt[2][3]); - EXPECT_EQ(48u, dst_pixels_opt[3][0]); - EXPECT_EQ(192u, dst_pixels_opt[3][1]); - EXPECT_EQ(64u, dst_pixels_opt[3][2]); - EXPECT_EQ(224u, dst_pixels_opt[3][3]); + ASSERT_EQ(253u, dst_pixels_opt[0][0]); + ASSERT_EQ(0u, dst_pixels_opt[0][1]); + ASSERT_EQ(0u, dst_pixels_opt[0][2]); + ASSERT_EQ(128u, dst_pixels_opt[0][3]); + ASSERT_EQ(0u, dst_pixels_opt[1][0]); + ASSERT_EQ(253u, dst_pixels_opt[1][1]); + ASSERT_EQ(0u, dst_pixels_opt[1][2]); + ASSERT_EQ(0u, dst_pixels_opt[1][3]); + ASSERT_EQ(0u, dst_pixels_opt[2][0]); + ASSERT_EQ(0u, dst_pixels_opt[2][1]); + ASSERT_EQ(253u, dst_pixels_opt[2][2]); + ASSERT_EQ(255u, dst_pixels_opt[2][3]); + ASSERT_EQ(48u, dst_pixels_opt[3][0]); + ASSERT_EQ(192u, dst_pixels_opt[3][1]); + ASSERT_EQ(64u, dst_pixels_opt[3][2]); + ASSERT_EQ(224u, dst_pixels_opt[3][3]); for (int i = 0; i < 1280; ++i) { orig_pixels[i][0] = i; @@ -2287,99 +2951,253 @@ TEST_F(LibYUVPlanarTest, TestARGBLumaColorTable) { lumacolortable, 1280, 1); } for (int i = 0; i < 1280; ++i) { - EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); - EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); - EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); - EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); + ASSERT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); + ASSERT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); + ASSERT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); + ASSERT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); } free_aligned_buffer_page_end(lumacolortable); } -TEST_F(LibYUVPlanarTest, TestARGBCopyAlpha) { - const int kSize = benchmark_width_ * benchmark_height_ * 4; - align_buffer_page_end(orig_pixels, kSize); +static int TestARGBCopyAlpha(int width, + int height, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info, + int invert, + int off) { + if (width < 1) { + width = 1; + } + const int kStride = width * 4; + const int kSize = kStride * height; + align_buffer_page_end(orig_pixels, kSize + off); align_buffer_page_end(dst_pixels_opt, kSize); align_buffer_page_end(dst_pixels_c, kSize); - MemRandomize(orig_pixels, kSize); - MemRandomize(dst_pixels_opt, kSize); - memcpy(dst_pixels_c, dst_pixels_opt, kSize); - - MaskCpuFlags(disable_cpu_flags_); - ARGBCopyAlpha(orig_pixels, benchmark_width_ * 4, dst_pixels_c, - benchmark_width_ * 4, benchmark_width_, benchmark_height_); - MaskCpuFlags(benchmark_cpu_info_); - - for (int i = 0; i < benchmark_iterations_; ++i) { - ARGBCopyAlpha(orig_pixels, benchmark_width_ * 4, dst_pixels_opt, - benchmark_width_ * 4, benchmark_width_, benchmark_height_); + MemRandomize(orig_pixels + off, kSize); + MemRandomize(dst_pixels_c, kSize); + // Copy RGB bytes only, leaving alpha bytes in dst_pixels_opt uninitialized. + MSAN_POISON(dst_pixels_opt, kSize); + for (int i = 0; i < width * height; ++i) { + dst_pixels_opt[i * 4 + 0] = dst_pixels_c[i * 4 + 0]; + dst_pixels_opt[i * 4 + 1] = dst_pixels_c[i * 4 + 1]; + dst_pixels_opt[i * 4 + 2] = dst_pixels_c[i * 4 + 2]; } + + MaskCpuFlags(disable_cpu_flags); + ARGBCopyAlpha(orig_pixels + off, kStride, dst_pixels_c, kStride, width, + invert * height); + MaskCpuFlags(benchmark_cpu_info); + + for (int i = 0; i < benchmark_iterations; ++i) { + ARGBCopyAlpha(orig_pixels + off, kStride, dst_pixels_opt, kStride, width, + invert * height); + } + int max_diff = 0; for (int i = 0; i < kSize; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + int abs_diff = abs(static_cast(dst_pixels_c[i]) - + static_cast(dst_pixels_opt[i])); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } } free_aligned_buffer_page_end(dst_pixels_c); free_aligned_buffer_page_end(dst_pixels_opt); free_aligned_buffer_page_end(orig_pixels); + return max_diff; } -TEST_F(LibYUVPlanarTest, TestARGBExtractAlpha) { - // Round count up to multiple of 16 - const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; - align_buffer_page_end(src_pixels, kPixels * 4); +TEST_F(LibYUVPlanarTest, ARGBCopyAlpha_Any) { + int max_diff = TestARGBCopyAlpha(benchmark_width_ - 1, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0); + ASSERT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBCopyAlpha_Unaligned) { + int max_diff = TestARGBCopyAlpha(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 1); + ASSERT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBCopyAlpha_Invert) { + int max_diff = TestARGBCopyAlpha(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, -1, 0); + ASSERT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBCopyAlpha_Opt) { + int max_diff = TestARGBCopyAlpha(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0); + ASSERT_EQ(0, max_diff); +} + +static int TestARGBExtractAlpha(int width, + int height, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info, + int invert, + int off) { + if (width < 1) { + width = 1; + } + const int kPixels = width * height; + align_buffer_page_end(src_pixels, kPixels * 4 + off); align_buffer_page_end(dst_pixels_opt, kPixels); align_buffer_page_end(dst_pixels_c, kPixels); - MemRandomize(src_pixels, kPixels * 4); - MemRandomize(dst_pixels_opt, kPixels); - memcpy(dst_pixels_c, dst_pixels_opt, kPixels); + MemRandomize(src_pixels + off, kPixels * 4); + // Leave dst_pixels_opt uninitialized to verify MSan unpoisons all written + // alpha bytes (including masked tail stores). + MSAN_POISON(dst_pixels_opt, kPixels); - MaskCpuFlags(disable_cpu_flags_); - ARGBExtractAlpha(src_pixels, benchmark_width_ * 4, dst_pixels_c, - benchmark_width_, benchmark_width_, benchmark_height_); - MaskCpuFlags(benchmark_cpu_info_); + MaskCpuFlags(disable_cpu_flags); + ARGBExtractAlpha(src_pixels + off, width * 4, dst_pixels_c, width, width, + invert * height); - for (int i = 0; i < benchmark_iterations_; ++i) { - ARGBExtractAlpha(src_pixels, benchmark_width_ * 4, dst_pixels_opt, - benchmark_width_, benchmark_width_, benchmark_height_); + MaskCpuFlags(benchmark_cpu_info); + for (int i = 0; i < benchmark_iterations; ++i) { + ARGBExtractAlpha(src_pixels + off, width * 4, dst_pixels_opt, width, width, + invert * height); } + int max_diff = 0; for (int i = 0; i < kPixels; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + int abs_diff = abs(static_cast(dst_pixels_c[i]) - + static_cast(dst_pixels_opt[i])); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } } free_aligned_buffer_page_end(dst_pixels_c); free_aligned_buffer_page_end(dst_pixels_opt); free_aligned_buffer_page_end(src_pixels); + return max_diff; } -TEST_F(LibYUVPlanarTest, TestARGBCopyYToAlpha) { - // Round count up to multiple of 16 - const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; - align_buffer_page_end(orig_pixels, kPixels); +TEST_F(LibYUVPlanarTest, ARGBExtractAlpha_Any) { + int max_diff = TestARGBExtractAlpha(benchmark_width_ - 1, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0); + ASSERT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBExtractAlpha_Unaligned) { + int max_diff = TestARGBExtractAlpha(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 1); + ASSERT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBExtractAlpha_Invert) { + int max_diff = TestARGBExtractAlpha(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, -1, 0); + ASSERT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBExtractAlpha_Opt) { + int max_diff = TestARGBExtractAlpha(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0); + ASSERT_EQ(0, max_diff); +} + +static int TestARGBCopyYToAlpha(int width, + int height, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info, + int invert, + int off) { + if (width < 1) { + width = 1; + } + const int kPixels = width * height; + align_buffer_page_end(orig_pixels, kPixels + off); align_buffer_page_end(dst_pixels_opt, kPixels * 4); align_buffer_page_end(dst_pixels_c, kPixels * 4); + align_buffer_page_end(dst_uninit_opt, kPixels * 4); - MemRandomize(orig_pixels, kPixels); - MemRandomize(dst_pixels_opt, kPixels * 4); - memcpy(dst_pixels_c, dst_pixels_opt, kPixels * 4); - - MaskCpuFlags(disable_cpu_flags_); - ARGBCopyYToAlpha(orig_pixels, benchmark_width_, dst_pixels_c, - benchmark_width_ * 4, benchmark_width_, benchmark_height_); - MaskCpuFlags(benchmark_cpu_info_); - - for (int i = 0; i < benchmark_iterations_; ++i) { - ARGBCopyYToAlpha(orig_pixels, benchmark_width_, dst_pixels_opt, - benchmark_width_ * 4, benchmark_width_, benchmark_height_); + MemRandomize(orig_pixels + off, kPixels); + MemRandomize(dst_pixels_c, kPixels * 4); + // Copy RGB bytes only, leaving alpha bytes in dst_pixels_opt uninitialized. + MSAN_POISON(dst_pixels_opt, kPixels * 4); + for (int i = 0; i < kPixels; ++i) { + dst_pixels_opt[i * 4 + 0] = dst_pixels_c[i * 4 + 0]; + dst_pixels_opt[i * 4 + 1] = dst_pixels_c[i * 4 + 1]; + dst_pixels_opt[i * 4 + 2] = dst_pixels_c[i * 4 + 2]; } + // Also test with completely uninitialized destination buffer for MSan. + MSAN_POISON(dst_uninit_opt, kPixels * 4); + + MaskCpuFlags(disable_cpu_flags); + ARGBCopyYToAlpha(orig_pixels + off, width, dst_pixels_c, width * 4, width, + invert * height); + + MaskCpuFlags(benchmark_cpu_info); + ARGBCopyYToAlpha(orig_pixels + off, width, dst_uninit_opt, width * 4, width, + invert * height); + for (int i = 0; i < benchmark_iterations; ++i) { + ARGBCopyYToAlpha(orig_pixels + off, width, dst_pixels_opt, width * 4, width, + invert * height); + } + int max_diff = 0; for (int i = 0; i < kPixels * 4; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + int abs_diff = abs(static_cast(dst_pixels_c[i]) - + static_cast(dst_pixels_opt[i])); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + for (int i = 0; i < kPixels; ++i) { + int abs_diff = abs(static_cast(dst_pixels_c[i * 4 + 3]) - + static_cast(dst_uninit_opt[i * 4 + 3])); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } } + free_aligned_buffer_page_end(dst_uninit_opt); free_aligned_buffer_page_end(dst_pixels_c); free_aligned_buffer_page_end(dst_pixels_opt); free_aligned_buffer_page_end(orig_pixels); + return max_diff; +} + +TEST_F(LibYUVPlanarTest, ARGBCopyYToAlpha_Any) { + int max_diff = TestARGBCopyYToAlpha(benchmark_width_ - 1, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0); + ASSERT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBCopyYToAlpha_Unaligned) { + int max_diff = TestARGBCopyYToAlpha(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 1); + ASSERT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBCopyYToAlpha_Invert) { + int max_diff = TestARGBCopyYToAlpha(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, -1, 0); + ASSERT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBCopyYToAlpha_Opt) { + int max_diff = TestARGBCopyYToAlpha(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0); + ASSERT_EQ(0, max_diff); } static int TestARGBRect(int width, @@ -2432,153 +3250,210 @@ static int TestARGBRect(int width, } TEST_F(LibYUVPlanarTest, ARGBRect_Any) { - int max_diff = TestARGBRect(benchmark_width_ - 1, benchmark_height_, + int max_diff = TestARGBRect(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0, 4); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBRect_Unaligned) { int max_diff = TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1, 4); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBRect_Invert) { int max_diff = TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, -1, 0, 4); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, ARGBRect_Opt) { int max_diff = TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0, 4); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, SetPlane_Any) { - int max_diff = TestARGBRect(benchmark_width_ - 1, benchmark_height_, + int max_diff = TestARGBRect(benchmark_width_ + 1, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0, 1); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, SetPlane_Unaligned) { int max_diff = TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 1, 1); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, SetPlane_Invert) { int max_diff = TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, -1, 0, 1); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, SetPlane_Opt) { int max_diff = TestARGBRect(benchmark_width_, benchmark_height_, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_, +1, 0, 1); - EXPECT_EQ(0, max_diff); + ASSERT_EQ(0, max_diff); } TEST_F(LibYUVPlanarTest, MergeUVPlane_Opt) { - // Round count up to multiple of 16 - const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; - align_buffer_page_end(src_pixels, kPixels * 2); - align_buffer_page_end(tmp_pixels_u, kPixels); - align_buffer_page_end(tmp_pixels_v, kPixels); + const int kPixels = benchmark_width_ * benchmark_height_; + align_buffer_page_end(src_pixels_u, kPixels); + align_buffer_page_end(src_pixels_v, kPixels); align_buffer_page_end(dst_pixels_opt, kPixels * 2); align_buffer_page_end(dst_pixels_c, kPixels * 2); - MemRandomize(src_pixels, kPixels * 2); - MemRandomize(tmp_pixels_u, kPixels); - MemRandomize(tmp_pixels_v, kPixels); + MemRandomize(src_pixels_u, kPixels); + MemRandomize(src_pixels_v, kPixels); MemRandomize(dst_pixels_opt, kPixels * 2); MemRandomize(dst_pixels_c, kPixels * 2); MaskCpuFlags(disable_cpu_flags_); - SplitUVPlane(src_pixels, benchmark_width_ * 2, tmp_pixels_u, benchmark_width_, - tmp_pixels_v, benchmark_width_, benchmark_width_, - benchmark_height_); - MergeUVPlane(tmp_pixels_u, benchmark_width_, tmp_pixels_v, benchmark_width_, + MergeUVPlane(src_pixels_u, benchmark_width_, src_pixels_v, benchmark_width_, dst_pixels_c, benchmark_width_ * 2, benchmark_width_, benchmark_height_); MaskCpuFlags(benchmark_cpu_info_); - SplitUVPlane(src_pixels, benchmark_width_ * 2, tmp_pixels_u, benchmark_width_, - tmp_pixels_v, benchmark_width_, benchmark_width_, - benchmark_height_); - for (int i = 0; i < benchmark_iterations_; ++i) { - MergeUVPlane(tmp_pixels_u, benchmark_width_, tmp_pixels_v, benchmark_width_, + MergeUVPlane(src_pixels_u, benchmark_width_, src_pixels_v, benchmark_width_, dst_pixels_opt, benchmark_width_ * 2, benchmark_width_, benchmark_height_); } for (int i = 0; i < kPixels * 2; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); } - free_aligned_buffer_page_end(src_pixels); - free_aligned_buffer_page_end(tmp_pixels_u); - free_aligned_buffer_page_end(tmp_pixels_v); + free_aligned_buffer_page_end(src_pixels_u); + free_aligned_buffer_page_end(src_pixels_v); + free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(dst_pixels_c); +} + +// 16 bit channel split and merge +TEST_F(LibYUVPlanarTest, MergeUVPlane_16_Opt) { + const int kPixels = benchmark_width_ * benchmark_height_; + align_buffer_page_end(src_pixels_u, kPixels * 2); + align_buffer_page_end(src_pixels_v, kPixels * 2); + align_buffer_page_end(dst_pixels_opt, kPixels * 2 * 2); + align_buffer_page_end(dst_pixels_c, kPixels * 2 * 2); + MemRandomize(src_pixels_u, kPixels * 2); + MemRandomize(src_pixels_v, kPixels * 2); + MemRandomize(dst_pixels_opt, kPixels * 2 * 2); + MemRandomize(dst_pixels_c, kPixels * 2 * 2); + + MaskCpuFlags(disable_cpu_flags_); + MergeUVPlane_16((const uint16_t*)src_pixels_u, benchmark_width_, + (const uint16_t*)src_pixels_v, benchmark_width_, + (uint16_t*)dst_pixels_c, benchmark_width_ * 2, + benchmark_width_, benchmark_height_, 12); + MaskCpuFlags(benchmark_cpu_info_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + MergeUVPlane_16((const uint16_t*)src_pixels_u, benchmark_width_, + (const uint16_t*)src_pixels_v, benchmark_width_, + (uint16_t*)dst_pixels_opt, benchmark_width_ * 2, + benchmark_width_, benchmark_height_, 12); + } + + for (int i = 0; i < kPixels * 2 * 2; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + free_aligned_buffer_page_end(src_pixels_u); + free_aligned_buffer_page_end(src_pixels_v); free_aligned_buffer_page_end(dst_pixels_opt); free_aligned_buffer_page_end(dst_pixels_c); } TEST_F(LibYUVPlanarTest, SplitUVPlane_Opt) { - // Round count up to multiple of 16 - const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + const int kPixels = benchmark_width_ * benchmark_height_; align_buffer_page_end(src_pixels, kPixels * 2); - align_buffer_page_end(tmp_pixels_u, kPixels); - align_buffer_page_end(tmp_pixels_v, kPixels); - align_buffer_page_end(dst_pixels_opt, kPixels * 2); - align_buffer_page_end(dst_pixels_c, kPixels * 2); + align_buffer_page_end(dst_pixels_u_c, kPixels); + align_buffer_page_end(dst_pixels_v_c, kPixels); + align_buffer_page_end(dst_pixels_u_opt, kPixels); + align_buffer_page_end(dst_pixels_v_opt, kPixels); MemRandomize(src_pixels, kPixels * 2); - MemRandomize(tmp_pixels_u, kPixels); - MemRandomize(tmp_pixels_v, kPixels); - MemRandomize(dst_pixels_opt, kPixels * 2); - MemRandomize(dst_pixels_c, kPixels * 2); + MemRandomize(dst_pixels_u_c, kPixels); + MemRandomize(dst_pixels_v_c, kPixels); + MemRandomize(dst_pixels_u_opt, kPixels); + MemRandomize(dst_pixels_v_opt, kPixels); MaskCpuFlags(disable_cpu_flags_); - SplitUVPlane(src_pixels, benchmark_width_ * 2, tmp_pixels_u, benchmark_width_, - tmp_pixels_v, benchmark_width_, benchmark_width_, - benchmark_height_); - MergeUVPlane(tmp_pixels_u, benchmark_width_, tmp_pixels_v, benchmark_width_, - dst_pixels_c, benchmark_width_ * 2, benchmark_width_, - benchmark_height_); + SplitUVPlane(src_pixels, benchmark_width_ * 2, dst_pixels_u_c, + benchmark_width_, dst_pixels_v_c, benchmark_width_, + benchmark_width_, benchmark_height_); MaskCpuFlags(benchmark_cpu_info_); for (int i = 0; i < benchmark_iterations_; ++i) { - SplitUVPlane(src_pixels, benchmark_width_ * 2, tmp_pixels_u, - benchmark_width_, tmp_pixels_v, benchmark_width_, + SplitUVPlane(src_pixels, benchmark_width_ * 2, dst_pixels_u_opt, + benchmark_width_, dst_pixels_v_opt, benchmark_width_, benchmark_width_, benchmark_height_); } - MergeUVPlane(tmp_pixels_u, benchmark_width_, tmp_pixels_v, benchmark_width_, - dst_pixels_opt, benchmark_width_ * 2, benchmark_width_, - benchmark_height_); - for (int i = 0; i < kPixels * 2; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + for (int i = 0; i < kPixels; ++i) { + ASSERT_EQ(dst_pixels_u_c[i], dst_pixels_u_opt[i]); + ASSERT_EQ(dst_pixels_v_c[i], dst_pixels_v_opt[i]); } free_aligned_buffer_page_end(src_pixels); - free_aligned_buffer_page_end(tmp_pixels_u); - free_aligned_buffer_page_end(tmp_pixels_v); - free_aligned_buffer_page_end(dst_pixels_opt); - free_aligned_buffer_page_end(dst_pixels_c); + free_aligned_buffer_page_end(dst_pixels_u_c); + free_aligned_buffer_page_end(dst_pixels_v_c); + free_aligned_buffer_page_end(dst_pixels_u_opt); + free_aligned_buffer_page_end(dst_pixels_v_opt); +} + +// 16 bit channel split +TEST_F(LibYUVPlanarTest, SplitUVPlane_16_Opt) { + const int kPixels = benchmark_width_ * benchmark_height_; + align_buffer_page_end(src_pixels, kPixels * 2 * 2); + align_buffer_page_end(dst_pixels_u_c, kPixels * 2); + align_buffer_page_end(dst_pixels_v_c, kPixels * 2); + align_buffer_page_end(dst_pixels_u_opt, kPixels * 2); + align_buffer_page_end(dst_pixels_v_opt, kPixels * 2); + MemRandomize(src_pixels, kPixels * 2 * 2); + MemRandomize(dst_pixels_u_c, kPixels * 2); + MemRandomize(dst_pixels_v_c, kPixels * 2); + MemRandomize(dst_pixels_u_opt, kPixels * 2); + MemRandomize(dst_pixels_v_opt, kPixels * 2); + + MaskCpuFlags(disable_cpu_flags_); + SplitUVPlane_16((const uint16_t*)src_pixels, benchmark_width_ * 2, + (uint16_t*)dst_pixels_u_c, benchmark_width_, + (uint16_t*)dst_pixels_v_c, benchmark_width_, benchmark_width_, + benchmark_height_, 10); + MaskCpuFlags(benchmark_cpu_info_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + SplitUVPlane_16((const uint16_t*)src_pixels, benchmark_width_ * 2, + (uint16_t*)dst_pixels_u_opt, benchmark_width_, + (uint16_t*)dst_pixels_v_opt, benchmark_width_, + benchmark_width_, benchmark_height_, 10); + } + + for (int i = 0; i < kPixels * 2; ++i) { + ASSERT_EQ(dst_pixels_u_c[i], dst_pixels_u_opt[i]); + ASSERT_EQ(dst_pixels_v_c[i], dst_pixels_v_opt[i]); + } + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(dst_pixels_u_c); + free_aligned_buffer_page_end(dst_pixels_v_c); + free_aligned_buffer_page_end(dst_pixels_u_opt); + free_aligned_buffer_page_end(dst_pixels_v_opt); } TEST_F(LibYUVPlanarTest, SwapUVPlane_Opt) { // Round count up to multiple of 16 - const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + const int kPixels = benchmark_width_ * benchmark_height_; align_buffer_page_end(src_pixels, kPixels * 2); align_buffer_page_end(dst_pixels_opt, kPixels * 2); align_buffer_page_end(dst_pixels_c, kPixels * 2); @@ -2598,7 +3473,7 @@ TEST_F(LibYUVPlanarTest, SwapUVPlane_Opt) { } for (int i = 0; i < kPixels * 2; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); } free_aligned_buffer_page_end(src_pixels); @@ -2608,106 +3483,574 @@ TEST_F(LibYUVPlanarTest, SwapUVPlane_Opt) { TEST_F(LibYUVPlanarTest, MergeRGBPlane_Opt) { // Round count up to multiple of 16 - const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + const int kPixels = benchmark_width_ * benchmark_height_; align_buffer_page_end(src_pixels, kPixels * 3); - align_buffer_page_end(tmp_pixels_r, kPixels); - align_buffer_page_end(tmp_pixels_g, kPixels); - align_buffer_page_end(tmp_pixels_b, kPixels); - align_buffer_page_end(dst_pixels_opt, kPixels * 3); + align_buffer_page_end(tmp_pixels_c_r, kPixels); + align_buffer_page_end(tmp_pixels_opt_r, kPixels); + align_buffer_page_end(tmp_pixels_c_g, kPixels); + align_buffer_page_end(tmp_pixels_opt_g, kPixels); + align_buffer_page_end(tmp_pixels_c_b, kPixels); + align_buffer_page_end(tmp_pixels_opt_b, kPixels); align_buffer_page_end(dst_pixels_c, kPixels * 3); + align_buffer_page_end(dst_pixels_opt, kPixels * 3); MemRandomize(src_pixels, kPixels * 3); - MemRandomize(tmp_pixels_r, kPixels); - MemRandomize(tmp_pixels_g, kPixels); - MemRandomize(tmp_pixels_b, kPixels); - MemRandomize(dst_pixels_opt, kPixels * 3); + MemRandomize(tmp_pixels_c_r, kPixels); + MemRandomize(tmp_pixels_opt_r, kPixels); + MemRandomize(tmp_pixels_c_g, kPixels); + MemRandomize(tmp_pixels_opt_g, kPixels); + MemRandomize(tmp_pixels_c_b, kPixels); + MemRandomize(tmp_pixels_opt_b, kPixels); MemRandomize(dst_pixels_c, kPixels * 3); + MemRandomize(dst_pixels_opt, kPixels * 3); MaskCpuFlags(disable_cpu_flags_); - SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_r, - benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b, - benchmark_width_, benchmark_width_, benchmark_height_); - MergeRGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_, - tmp_pixels_b, benchmark_width_, dst_pixels_c, - benchmark_width_ * 3, benchmark_width_, benchmark_height_); + SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_c_r, + benchmark_width_, tmp_pixels_c_g, benchmark_width_, + tmp_pixels_c_b, benchmark_width_, benchmark_width_, + benchmark_height_); + MergeRGBPlane(tmp_pixels_c_r, benchmark_width_, tmp_pixels_c_g, + benchmark_width_, tmp_pixels_c_b, benchmark_width_, + dst_pixels_c, benchmark_width_ * 3, benchmark_width_, + benchmark_height_); MaskCpuFlags(benchmark_cpu_info_); - SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_r, - benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b, - benchmark_width_, benchmark_width_, benchmark_height_); + SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_opt_r, + benchmark_width_, tmp_pixels_opt_g, benchmark_width_, + tmp_pixels_opt_b, benchmark_width_, benchmark_width_, + benchmark_height_); for (int i = 0; i < benchmark_iterations_; ++i) { - MergeRGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, - benchmark_width_, tmp_pixels_b, benchmark_width_, + MergeRGBPlane(tmp_pixels_opt_r, benchmark_width_, tmp_pixels_opt_g, + benchmark_width_, tmp_pixels_opt_b, benchmark_width_, dst_pixels_opt, benchmark_width_ * 3, benchmark_width_, benchmark_height_); } for (int i = 0; i < kPixels * 3; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); } free_aligned_buffer_page_end(src_pixels); - free_aligned_buffer_page_end(tmp_pixels_r); - free_aligned_buffer_page_end(tmp_pixels_g); - free_aligned_buffer_page_end(tmp_pixels_b); - free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(tmp_pixels_c_r); + free_aligned_buffer_page_end(tmp_pixels_opt_r); + free_aligned_buffer_page_end(tmp_pixels_c_g); + free_aligned_buffer_page_end(tmp_pixels_opt_g); + free_aligned_buffer_page_end(tmp_pixels_c_b); + free_aligned_buffer_page_end(tmp_pixels_opt_b); free_aligned_buffer_page_end(dst_pixels_c); + free_aligned_buffer_page_end(dst_pixels_opt); } TEST_F(LibYUVPlanarTest, SplitRGBPlane_Opt) { // Round count up to multiple of 16 - const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + const int kPixels = benchmark_width_ * benchmark_height_; align_buffer_page_end(src_pixels, kPixels * 3); - align_buffer_page_end(tmp_pixels_r, kPixels); - align_buffer_page_end(tmp_pixels_g, kPixels); - align_buffer_page_end(tmp_pixels_b, kPixels); - align_buffer_page_end(dst_pixels_opt, kPixels * 3); + align_buffer_page_end(tmp_pixels_c_r, kPixels); + align_buffer_page_end(tmp_pixels_opt_r, kPixels); + align_buffer_page_end(tmp_pixels_c_g, kPixels); + align_buffer_page_end(tmp_pixels_opt_g, kPixels); + align_buffer_page_end(tmp_pixels_c_b, kPixels); + align_buffer_page_end(tmp_pixels_opt_b, kPixels); align_buffer_page_end(dst_pixels_c, kPixels * 3); + align_buffer_page_end(dst_pixels_opt, kPixels * 3); MemRandomize(src_pixels, kPixels * 3); - MemRandomize(tmp_pixels_r, kPixels); - MemRandomize(tmp_pixels_g, kPixels); - MemRandomize(tmp_pixels_b, kPixels); - MemRandomize(dst_pixels_opt, kPixels * 3); + MemRandomize(tmp_pixels_c_r, kPixels); + MemRandomize(tmp_pixels_opt_r, kPixels); + MemRandomize(tmp_pixels_c_g, kPixels); + MemRandomize(tmp_pixels_opt_g, kPixels); + MemRandomize(tmp_pixels_c_b, kPixels); + MemRandomize(tmp_pixels_opt_b, kPixels); MemRandomize(dst_pixels_c, kPixels * 3); + MemRandomize(dst_pixels_opt, kPixels * 3); MaskCpuFlags(disable_cpu_flags_); - SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_r, - benchmark_width_, tmp_pixels_g, benchmark_width_, tmp_pixels_b, - benchmark_width_, benchmark_width_, benchmark_height_); - MergeRGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_, - tmp_pixels_b, benchmark_width_, dst_pixels_c, - benchmark_width_ * 3, benchmark_width_, benchmark_height_); + SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_c_r, + benchmark_width_, tmp_pixels_c_g, benchmark_width_, + tmp_pixels_c_b, benchmark_width_, benchmark_width_, + benchmark_height_); + MergeRGBPlane(tmp_pixels_c_r, benchmark_width_, tmp_pixels_c_g, + benchmark_width_, tmp_pixels_c_b, benchmark_width_, + dst_pixels_c, benchmark_width_ * 3, benchmark_width_, + benchmark_height_); MaskCpuFlags(benchmark_cpu_info_); for (int i = 0; i < benchmark_iterations_; ++i) { - SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_r, - benchmark_width_, tmp_pixels_g, benchmark_width_, - tmp_pixels_b, benchmark_width_, benchmark_width_, + SplitRGBPlane(src_pixels, benchmark_width_ * 3, tmp_pixels_opt_r, + benchmark_width_, tmp_pixels_opt_g, benchmark_width_, + tmp_pixels_opt_b, benchmark_width_, benchmark_width_, benchmark_height_); } - MergeRGBPlane(tmp_pixels_r, benchmark_width_, tmp_pixels_g, benchmark_width_, - tmp_pixels_b, benchmark_width_, dst_pixels_opt, - benchmark_width_ * 3, benchmark_width_, benchmark_height_); + MergeRGBPlane(tmp_pixels_opt_r, benchmark_width_, tmp_pixels_opt_g, + benchmark_width_, tmp_pixels_opt_b, benchmark_width_, + dst_pixels_opt, benchmark_width_ * 3, benchmark_width_, + benchmark_height_); for (int i = 0; i < kPixels * 3; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); } free_aligned_buffer_page_end(src_pixels); - free_aligned_buffer_page_end(tmp_pixels_r); - free_aligned_buffer_page_end(tmp_pixels_g); - free_aligned_buffer_page_end(tmp_pixels_b); + free_aligned_buffer_page_end(tmp_pixels_c_r); + free_aligned_buffer_page_end(tmp_pixels_opt_r); + free_aligned_buffer_page_end(tmp_pixels_c_g); + free_aligned_buffer_page_end(tmp_pixels_opt_g); + free_aligned_buffer_page_end(tmp_pixels_c_b); + free_aligned_buffer_page_end(tmp_pixels_opt_b); + free_aligned_buffer_page_end(dst_pixels_c); + free_aligned_buffer_page_end(dst_pixels_opt); +} + +// Call SplitRGBPlane() with a width that is not a multiple of 32. Verify there +// is no stack buffer overflow in SplitRGBRow_Any_AVX2(). +TEST_F(LibYUVPlanarTest, SplitRGBPlaneOverflow) { + int width = 1024 + 31; // 1055 + const int height = 2; + align_buffer_page_end(src_rgb, width * 3 * height); + align_buffer_page_end(dst_r, width * height); + align_buffer_page_end(dst_g, width * height); + align_buffer_page_end(dst_b, width * height); + memset(src_rgb, 0x5A, width * 3 * height); + SplitRGBPlane(src_rgb, width * 3, dst_r, width, dst_g, width, dst_b, width, + width, height); + free_aligned_buffer_page_end(src_rgb); + free_aligned_buffer_page_end(dst_r); + free_aligned_buffer_page_end(dst_g); + free_aligned_buffer_page_end(dst_b); +} + +TEST_F(LibYUVPlanarTest, MergeARGBPlane_Opt) { + const int kPixels = benchmark_width_ * benchmark_height_; + align_buffer_page_end(src_pixels, kPixels * 4); + align_buffer_page_end(tmp_pixels_c_r, kPixels); + align_buffer_page_end(tmp_pixels_opt_r, kPixels); + align_buffer_page_end(tmp_pixels_c_g, kPixels); + align_buffer_page_end(tmp_pixels_opt_g, kPixels); + align_buffer_page_end(tmp_pixels_c_b, kPixels); + align_buffer_page_end(tmp_pixels_opt_b, kPixels); + align_buffer_page_end(tmp_pixels_c_a, kPixels); + align_buffer_page_end(tmp_pixels_opt_a, kPixels); + align_buffer_page_end(dst_pixels_c, kPixels * 4); + align_buffer_page_end(dst_pixels_opt, kPixels * 4); + + MemRandomize(src_pixels, kPixels * 4); + MemRandomize(tmp_pixels_c_r, kPixels); + MemRandomize(tmp_pixels_opt_r, kPixels); + MemRandomize(tmp_pixels_c_g, kPixels); + MemRandomize(tmp_pixels_opt_g, kPixels); + MemRandomize(tmp_pixels_c_b, kPixels); + MemRandomize(tmp_pixels_opt_b, kPixels); + MemRandomize(tmp_pixels_c_a, kPixels); + MemRandomize(tmp_pixels_opt_a, kPixels); + MemRandomize(dst_pixels_opt, kPixels * 4); + MemRandomize(dst_pixels_c, kPixels * 4); + + MaskCpuFlags(disable_cpu_flags_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_c_r, + benchmark_width_, tmp_pixels_c_g, benchmark_width_, + tmp_pixels_c_b, benchmark_width_, tmp_pixels_c_a, + benchmark_width_, benchmark_width_, benchmark_height_); + MergeARGBPlane(tmp_pixels_c_r, benchmark_width_, tmp_pixels_c_g, + benchmark_width_, tmp_pixels_c_b, benchmark_width_, + tmp_pixels_c_a, benchmark_width_, dst_pixels_c, + benchmark_width_ * 4, benchmark_width_, benchmark_height_); + + MaskCpuFlags(benchmark_cpu_info_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_opt_r, + benchmark_width_, tmp_pixels_opt_g, benchmark_width_, + tmp_pixels_opt_b, benchmark_width_, tmp_pixels_opt_a, + benchmark_width_, benchmark_width_, benchmark_height_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + MergeARGBPlane(tmp_pixels_opt_r, benchmark_width_, tmp_pixels_opt_g, + benchmark_width_, tmp_pixels_opt_b, benchmark_width_, + tmp_pixels_opt_a, benchmark_width_, dst_pixels_opt, + benchmark_width_ * 4, benchmark_width_, benchmark_height_); + } + + for (int i = 0; i < kPixels * 4; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(tmp_pixels_c_r); + free_aligned_buffer_page_end(tmp_pixels_opt_r); + free_aligned_buffer_page_end(tmp_pixels_c_g); + free_aligned_buffer_page_end(tmp_pixels_opt_g); + free_aligned_buffer_page_end(tmp_pixels_c_b); + free_aligned_buffer_page_end(tmp_pixels_opt_b); + free_aligned_buffer_page_end(tmp_pixels_c_a); + free_aligned_buffer_page_end(tmp_pixels_opt_a); free_aligned_buffer_page_end(dst_pixels_opt); free_aligned_buffer_page_end(dst_pixels_c); } +TEST_F(LibYUVPlanarTest, SplitARGBPlane_Opt) { + const int kPixels = benchmark_width_ * benchmark_height_; + align_buffer_page_end(src_pixels, kPixels * 4); + align_buffer_page_end(tmp_pixels_c_r, kPixels); + align_buffer_page_end(tmp_pixels_opt_r, kPixels); + align_buffer_page_end(tmp_pixels_c_g, kPixels); + align_buffer_page_end(tmp_pixels_opt_g, kPixels); + align_buffer_page_end(tmp_pixels_c_b, kPixels); + align_buffer_page_end(tmp_pixels_opt_b, kPixels); + align_buffer_page_end(tmp_pixels_c_a, kPixels); + align_buffer_page_end(tmp_pixels_opt_a, kPixels); + align_buffer_page_end(dst_pixels_opt, kPixels * 4); + align_buffer_page_end(dst_pixels_c, kPixels * 4); + + MemRandomize(src_pixels, kPixels * 4); + MemRandomize(tmp_pixels_c_r, kPixels); + MemRandomize(tmp_pixels_opt_r, kPixels); + MemRandomize(tmp_pixels_c_g, kPixels); + MemRandomize(tmp_pixels_opt_g, kPixels); + MemRandomize(tmp_pixels_c_b, kPixels); + MemRandomize(tmp_pixels_opt_b, kPixels); + MemRandomize(tmp_pixels_c_a, kPixels); + MemRandomize(tmp_pixels_opt_a, kPixels); + MemRandomize(dst_pixels_opt, kPixels * 4); + MemRandomize(dst_pixels_c, kPixels * 4); + + MaskCpuFlags(disable_cpu_flags_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_c_r, + benchmark_width_, tmp_pixels_c_g, benchmark_width_, + tmp_pixels_c_b, benchmark_width_, tmp_pixels_c_a, + benchmark_width_, benchmark_width_, benchmark_height_); + MergeARGBPlane(tmp_pixels_c_r, benchmark_width_, tmp_pixels_c_g, + benchmark_width_, tmp_pixels_c_b, benchmark_width_, + tmp_pixels_c_a, benchmark_width_, dst_pixels_c, + benchmark_width_ * 4, benchmark_width_, benchmark_height_); + + MaskCpuFlags(benchmark_cpu_info_); + for (int i = 0; i < benchmark_iterations_; ++i) { + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_opt_r, + benchmark_width_, tmp_pixels_opt_g, benchmark_width_, + tmp_pixels_opt_b, benchmark_width_, tmp_pixels_opt_a, + benchmark_width_, benchmark_width_, benchmark_height_); + } + + MergeARGBPlane(tmp_pixels_opt_r, benchmark_width_, tmp_pixels_opt_g, + benchmark_width_, tmp_pixels_opt_b, benchmark_width_, + tmp_pixels_opt_a, benchmark_width_, dst_pixels_opt, + benchmark_width_ * 4, benchmark_width_, benchmark_height_); + + for (int i = 0; i < kPixels * 4; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(tmp_pixels_c_r); + free_aligned_buffer_page_end(tmp_pixels_opt_r); + free_aligned_buffer_page_end(tmp_pixels_c_g); + free_aligned_buffer_page_end(tmp_pixels_opt_g); + free_aligned_buffer_page_end(tmp_pixels_c_b); + free_aligned_buffer_page_end(tmp_pixels_opt_b); + free_aligned_buffer_page_end(tmp_pixels_c_a); + free_aligned_buffer_page_end(tmp_pixels_opt_a); + free_aligned_buffer_page_end(dst_pixels_c); + free_aligned_buffer_page_end(dst_pixels_opt); +} + +// Call SplitARGBPlane() with a width that is not a multiple of 16. Verify there +// is no stack buffer overflow in SplitXRGBRow_Any_AVX2(). +TEST_F(LibYUVPlanarTest, SplitARGBPlaneOverflow) { + int width = 1024 + 15; // 1039 + int height = 2; + align_buffer_page_end(src_argb, width * 4 * height); + align_buffer_page_end(dst_r, width * height); + align_buffer_page_end(dst_g, width * height); + align_buffer_page_end(dst_b, width * height); + memset(src_argb, 0x5A, width * 4 * height); + // dst_a == NULL selects SplitXRGBRow + SplitARGBPlane(src_argb, width * 4, dst_r, width, dst_g, width, dst_b, width, + NULL, 0, width, height); + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(dst_r); + free_aligned_buffer_page_end(dst_g); + free_aligned_buffer_page_end(dst_b); +} + +TEST_F(LibYUVPlanarTest, MergeXRGBPlane_Opt) { + const int kPixels = benchmark_width_ * benchmark_height_; + align_buffer_page_end(src_pixels, kPixels * 4); + align_buffer_page_end(tmp_pixels_c_r, kPixels); + align_buffer_page_end(tmp_pixels_opt_r, kPixels); + align_buffer_page_end(tmp_pixels_c_g, kPixels); + align_buffer_page_end(tmp_pixels_opt_g, kPixels); + align_buffer_page_end(tmp_pixels_c_b, kPixels); + align_buffer_page_end(tmp_pixels_opt_b, kPixels); + align_buffer_page_end(dst_pixels_c, kPixels * 4); + align_buffer_page_end(dst_pixels_opt, kPixels * 4); + + MemRandomize(src_pixels, kPixels * 4); + MemRandomize(tmp_pixels_c_r, kPixels); + MemRandomize(tmp_pixels_opt_r, kPixels); + MemRandomize(tmp_pixels_c_g, kPixels); + MemRandomize(tmp_pixels_opt_g, kPixels); + MemRandomize(tmp_pixels_c_b, kPixels); + MemRandomize(tmp_pixels_opt_b, kPixels); + MemRandomize(dst_pixels_c, kPixels * 4); + MemRandomize(dst_pixels_opt, kPixels * 4); + + MaskCpuFlags(disable_cpu_flags_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_c_r, + benchmark_width_, tmp_pixels_c_g, benchmark_width_, + tmp_pixels_c_b, benchmark_width_, NULL, 0, benchmark_width_, + benchmark_height_); + MergeARGBPlane(tmp_pixels_c_r, benchmark_width_, tmp_pixels_c_g, + benchmark_width_, tmp_pixels_c_b, benchmark_width_, NULL, 0, + dst_pixels_c, benchmark_width_ * 4, benchmark_width_, + benchmark_height_); + + MaskCpuFlags(benchmark_cpu_info_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_opt_r, + benchmark_width_, tmp_pixels_opt_g, benchmark_width_, + tmp_pixels_opt_b, benchmark_width_, NULL, 0, benchmark_width_, + benchmark_height_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + MergeARGBPlane(tmp_pixels_opt_r, benchmark_width_, tmp_pixels_opt_g, + benchmark_width_, tmp_pixels_opt_b, benchmark_width_, NULL, + 0, dst_pixels_opt, benchmark_width_ * 4, benchmark_width_, + benchmark_height_); + } + + for (int i = 0; i < kPixels * 4; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(tmp_pixels_c_r); + free_aligned_buffer_page_end(tmp_pixels_opt_r); + free_aligned_buffer_page_end(tmp_pixels_c_g); + free_aligned_buffer_page_end(tmp_pixels_opt_g); + free_aligned_buffer_page_end(tmp_pixels_c_b); + free_aligned_buffer_page_end(tmp_pixels_opt_b); + free_aligned_buffer_page_end(dst_pixels_c); + free_aligned_buffer_page_end(dst_pixels_opt); +} + +TEST_F(LibYUVPlanarTest, SplitXRGBPlane_Opt) { + const int kPixels = benchmark_width_ * benchmark_height_; + align_buffer_page_end(src_pixels, kPixels * 4); + align_buffer_page_end(tmp_pixels_c_r, kPixels); + align_buffer_page_end(tmp_pixels_opt_r, kPixels); + align_buffer_page_end(tmp_pixels_c_g, kPixels); + align_buffer_page_end(tmp_pixels_opt_g, kPixels); + align_buffer_page_end(tmp_pixels_c_b, kPixels); + align_buffer_page_end(tmp_pixels_opt_b, kPixels); + align_buffer_page_end(dst_pixels_c, kPixels * 4); + align_buffer_page_end(dst_pixels_opt, kPixels * 4); + + MemRandomize(src_pixels, kPixels * 4); + MemRandomize(tmp_pixels_c_r, kPixels); + MemRandomize(tmp_pixels_opt_r, kPixels); + MemRandomize(tmp_pixels_c_g, kPixels); + MemRandomize(tmp_pixels_opt_g, kPixels); + MemRandomize(tmp_pixels_c_b, kPixels); + MemRandomize(tmp_pixels_opt_b, kPixels); + MemRandomize(dst_pixels_c, kPixels * 4); + MemRandomize(dst_pixels_opt, kPixels * 4); + + MaskCpuFlags(disable_cpu_flags_); + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_c_r, + benchmark_width_, tmp_pixels_c_g, benchmark_width_, + tmp_pixels_c_b, benchmark_width_, NULL, 0, benchmark_width_, + benchmark_height_); + MergeARGBPlane(tmp_pixels_c_r, benchmark_width_, tmp_pixels_c_g, + benchmark_width_, tmp_pixels_c_b, benchmark_width_, NULL, 0, + dst_pixels_c, benchmark_width_ * 4, benchmark_width_, + benchmark_height_); + + MaskCpuFlags(benchmark_cpu_info_); + for (int i = 0; i < benchmark_iterations_; ++i) { + SplitARGBPlane(src_pixels, benchmark_width_ * 4, tmp_pixels_opt_r, + benchmark_width_, tmp_pixels_opt_g, benchmark_width_, + tmp_pixels_opt_b, benchmark_width_, NULL, 0, + benchmark_width_, benchmark_height_); + } + + MergeARGBPlane(tmp_pixels_opt_r, benchmark_width_, tmp_pixels_opt_g, + benchmark_width_, tmp_pixels_opt_b, benchmark_width_, NULL, 0, + dst_pixels_opt, benchmark_width_ * 4, benchmark_width_, + benchmark_height_); + + for (int i = 0; i < kPixels * 4; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(tmp_pixels_c_r); + free_aligned_buffer_page_end(tmp_pixels_opt_r); + free_aligned_buffer_page_end(tmp_pixels_c_g); + free_aligned_buffer_page_end(tmp_pixels_opt_g); + free_aligned_buffer_page_end(tmp_pixels_c_b); + free_aligned_buffer_page_end(tmp_pixels_opt_b); + free_aligned_buffer_page_end(dst_pixels_c); + free_aligned_buffer_page_end(dst_pixels_opt); +} + +// Merge 4 channels +#define TESTQPLANARTOPI(FUNC, STYPE, DTYPE, DEPTH, W1280, N, NEG, OFF) \ + TEST_F(LibYUVPlanarTest, FUNC##Plane_##DEPTH##N) { \ + const int kWidth = W1280; \ + const int kPixels = kWidth * benchmark_height_; \ + align_buffer_page_end(src_memory_r, kPixels * sizeof(STYPE) + OFF); \ + align_buffer_page_end(src_memory_g, kPixels * sizeof(STYPE) + OFF); \ + align_buffer_page_end(src_memory_b, kPixels * sizeof(STYPE) + OFF); \ + align_buffer_page_end(src_memory_a, kPixels * sizeof(STYPE) + OFF); \ + align_buffer_page_end(dst_memory_c, kPixels * 4 * sizeof(DTYPE)); \ + align_buffer_page_end(dst_memory_opt, kPixels * 4 * sizeof(DTYPE)); \ + MemRandomize(src_memory_r, kPixels * sizeof(STYPE) + OFF); \ + MemRandomize(src_memory_g, kPixels * sizeof(STYPE) + OFF); \ + MemRandomize(src_memory_b, kPixels * sizeof(STYPE) + OFF); \ + MemRandomize(src_memory_a, kPixels * sizeof(STYPE) + OFF); \ + memset(dst_memory_c, 0, kPixels * 4 * sizeof(DTYPE)); \ + memset(dst_memory_opt, 0, kPixels * 4 * sizeof(DTYPE)); \ + STYPE* src_pixels_r = reinterpret_cast(src_memory_r + OFF); \ + STYPE* src_pixels_g = reinterpret_cast(src_memory_g + OFF); \ + STYPE* src_pixels_b = reinterpret_cast(src_memory_b + OFF); \ + STYPE* src_pixels_a = reinterpret_cast(src_memory_a + OFF); \ + DTYPE* dst_pixels_c = reinterpret_cast(dst_memory_c); \ + DTYPE* dst_pixels_opt = reinterpret_cast(dst_memory_opt); \ + MaskCpuFlags(disable_cpu_flags_); \ + FUNC##Plane(src_pixels_r, kWidth, src_pixels_g, kWidth, src_pixels_b, \ + kWidth, src_pixels_a, kWidth, dst_pixels_c, kWidth * 4, \ + kWidth, NEG benchmark_height_, DEPTH); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FUNC##Plane(src_pixels_r, kWidth, src_pixels_g, kWidth, src_pixels_b, \ + kWidth, src_pixels_a, kWidth, dst_pixels_opt, kWidth * 4, \ + kWidth, NEG benchmark_height_, DEPTH); \ + } \ + for (int i = 0; i < kPixels * 4; ++i) { \ + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); \ + } \ + free_aligned_buffer_page_end(src_memory_r); \ + free_aligned_buffer_page_end(src_memory_g); \ + free_aligned_buffer_page_end(src_memory_b); \ + free_aligned_buffer_page_end(src_memory_a); \ + free_aligned_buffer_page_end(dst_memory_c); \ + free_aligned_buffer_page_end(dst_memory_opt); \ + } + +// Merge 3 channel RGB into 4 channel XRGB with opaque alpha +#define TESTQPLANAROTOPI(FUNC, STYPE, DTYPE, DEPTH, W1280, N, NEG, OFF) \ + TEST_F(LibYUVPlanarTest, FUNC##Plane_Opaque_##DEPTH##N) { \ + const int kWidth = W1280; \ + const int kPixels = kWidth * benchmark_height_; \ + align_buffer_page_end(src_memory_r, kPixels * sizeof(STYPE) + OFF); \ + align_buffer_page_end(src_memory_g, kPixels * sizeof(STYPE) + OFF); \ + align_buffer_page_end(src_memory_b, kPixels * sizeof(STYPE) + OFF); \ + align_buffer_page_end(dst_memory_c, kPixels * 4 * sizeof(DTYPE)); \ + align_buffer_page_end(dst_memory_opt, kPixels * 4 * sizeof(DTYPE)); \ + MemRandomize(src_memory_r, kPixels * sizeof(STYPE) + OFF); \ + MemRandomize(src_memory_g, kPixels * sizeof(STYPE) + OFF); \ + MemRandomize(src_memory_b, kPixels * sizeof(STYPE) + OFF); \ + memset(dst_memory_c, 0, kPixels * 4 * sizeof(DTYPE)); \ + memset(dst_memory_opt, 0, kPixels * 4 * sizeof(DTYPE)); \ + STYPE* src_pixels_r = reinterpret_cast(src_memory_r + OFF); \ + STYPE* src_pixels_g = reinterpret_cast(src_memory_g + OFF); \ + STYPE* src_pixels_b = reinterpret_cast(src_memory_b + OFF); \ + DTYPE* dst_pixels_c = reinterpret_cast(dst_memory_c); \ + DTYPE* dst_pixels_opt = reinterpret_cast(dst_memory_opt); \ + MaskCpuFlags(disable_cpu_flags_); \ + FUNC##Plane(src_pixels_r, kWidth, src_pixels_g, kWidth, src_pixels_b, \ + kWidth, NULL, 0, dst_pixels_c, kWidth * 4, kWidth, \ + NEG benchmark_height_, DEPTH); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FUNC##Plane(src_pixels_r, kWidth, src_pixels_g, kWidth, src_pixels_b, \ + kWidth, NULL, 0, dst_pixels_opt, kWidth * 4, kWidth, \ + NEG benchmark_height_, DEPTH); \ + } \ + for (int i = 0; i < kPixels * 4; ++i) { \ + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); \ + } \ + free_aligned_buffer_page_end(src_memory_r); \ + free_aligned_buffer_page_end(src_memory_g); \ + free_aligned_buffer_page_end(src_memory_b); \ + free_aligned_buffer_page_end(dst_memory_c); \ + free_aligned_buffer_page_end(dst_memory_opt); \ + } + +#define TESTQPLANARTOP(FUNC, STYPE, DTYPE, DEPTH) \ + TESTQPLANARTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_ + 1, _Any, +, 0) \ + TESTQPLANARTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_, _Unaligned, +, \ + 2) \ + TESTQPLANARTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_, _Invert, -, 0) \ + TESTQPLANARTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_, _Opt, +, 0) \ + TESTQPLANAROTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_ + 1, _Any, +, \ + 0) \ + TESTQPLANAROTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_, _Unaligned, +, \ + 2) \ + TESTQPLANAROTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_, _Invert, -, 0) \ + TESTQPLANAROTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_, _Opt, +, 0) + +TESTQPLANARTOP(MergeAR64, uint16_t, uint16_t, 10) +TESTQPLANARTOP(MergeAR64, uint16_t, uint16_t, 12) +TESTQPLANARTOP(MergeAR64, uint16_t, uint16_t, 16) +TESTQPLANARTOP(MergeARGB16To8, uint16_t, uint8_t, 10) +TESTQPLANARTOP(MergeARGB16To8, uint16_t, uint8_t, 12) +TESTQPLANARTOP(MergeARGB16To8, uint16_t, uint8_t, 16) + +#define TESTTPLANARTOPI(FUNC, STYPE, DTYPE, DEPTH, W1280, N, NEG, OFF) \ + TEST_F(LibYUVPlanarTest, FUNC##Plane_##DEPTH##N) { \ + const int kWidth = W1280; \ + const int kPixels = kWidth * benchmark_height_; \ + align_buffer_page_end(src_memory_r, kPixels * sizeof(STYPE) + OFF); \ + align_buffer_page_end(src_memory_g, kPixels * sizeof(STYPE) + OFF); \ + align_buffer_page_end(src_memory_b, kPixels * sizeof(STYPE) + OFF); \ + align_buffer_page_end(dst_memory_c, kPixels * 4 * sizeof(DTYPE)); \ + align_buffer_page_end(dst_memory_opt, kPixels * 4 * sizeof(DTYPE)); \ + MemRandomize(src_memory_r, kPixels * sizeof(STYPE) + OFF); \ + MemRandomize(src_memory_g, kPixels * sizeof(STYPE) + OFF); \ + MemRandomize(src_memory_b, kPixels * sizeof(STYPE) + OFF); \ + STYPE* src_pixels_r = reinterpret_cast(src_memory_r + OFF); \ + STYPE* src_pixels_g = reinterpret_cast(src_memory_g + OFF); \ + STYPE* src_pixels_b = reinterpret_cast(src_memory_b + OFF); \ + DTYPE* dst_pixels_c = reinterpret_cast(dst_memory_c); \ + DTYPE* dst_pixels_opt = reinterpret_cast(dst_memory_opt); \ + memset(dst_pixels_c, 1, kPixels * 4 * sizeof(DTYPE)); \ + memset(dst_pixels_opt, 2, kPixels * 4 * sizeof(DTYPE)); \ + MaskCpuFlags(disable_cpu_flags_); \ + FUNC##Plane(src_pixels_r, kWidth, src_pixels_g, kWidth, src_pixels_b, \ + kWidth, dst_pixels_c, kWidth * 4, kWidth, \ + NEG benchmark_height_, DEPTH); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + FUNC##Plane(src_pixels_r, kWidth, src_pixels_g, kWidth, src_pixels_b, \ + kWidth, dst_pixels_opt, kWidth * 4, kWidth, \ + NEG benchmark_height_, DEPTH); \ + } \ + for (int i = 0; i < kPixels * 4; ++i) { \ + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); \ + } \ + free_aligned_buffer_page_end(src_memory_r); \ + free_aligned_buffer_page_end(src_memory_g); \ + free_aligned_buffer_page_end(src_memory_b); \ + free_aligned_buffer_page_end(dst_memory_c); \ + free_aligned_buffer_page_end(dst_memory_opt); \ + } + +#define TESTTPLANARTOP(FUNC, STYPE, DTYPE, DEPTH) \ + TESTTPLANARTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_ + 1, _Any, +, 0) \ + TESTTPLANARTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_, _Unaligned, +, \ + 2) \ + TESTTPLANARTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_, _Invert, -, 0) \ + TESTTPLANARTOPI(FUNC, STYPE, DTYPE, DEPTH, benchmark_width_, _Opt, +, 0) + +TESTTPLANARTOP(MergeXR30, uint16_t, uint8_t, 10) +TESTTPLANARTOP(MergeXR30, uint16_t, uint8_t, 12) +TESTTPLANARTOP(MergeXR30, uint16_t, uint8_t, 16) + // TODO(fbarchard): improve test for platforms and cpu detect -#ifdef HAS_MERGEUVROW_16_AVX2 +#if defined(HAS_MERGEUVROW_16_AVX512BW) || defined(HAS_MERGEUVROW_16_AVX2) TEST_F(LibYUVPlanarTest, MergeUVRow_16_Opt) { // Round count up to multiple of 16 const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + align_buffer_page_end(src_pixels_u, kPixels * 2); align_buffer_page_end(src_pixels_v, kPixels * 2); align_buffer_page_end(dst_pixels_uv_opt, kPixels * 2 * 2); @@ -2720,25 +4063,41 @@ TEST_F(LibYUVPlanarTest, MergeUVRow_16_Opt) { MergeUVRow_16_C(reinterpret_cast(src_pixels_u), reinterpret_cast(src_pixels_v), - reinterpret_cast(dst_pixels_uv_c), 64, kPixels); + reinterpret_cast(dst_pixels_uv_c), 16, kPixels); +#if defined(HAS_MERGEUVROW_16_AVX512BW) + int has_avx512 = TestCpuFlag(kCpuHasAVX512BW); +#endif +#if defined(HAS_MERGEUVROW_16_AVX2) int has_avx2 = TestCpuFlag(kCpuHasAVX2); +#endif for (int i = 0; i < benchmark_iterations_; ++i) { - if (has_avx2) { +#if defined(HAS_MERGEUVROW_16_AVX512BW) + if (has_avx512) { + MergeUVRow_16_AVX512BW(reinterpret_cast(src_pixels_u), + reinterpret_cast(src_pixels_v), + reinterpret_cast(dst_pixels_uv_opt), 16, + kPixels); + } else +#endif +#if defined(HAS_MERGEUVROW_16_AVX2) + if (has_avx2) { MergeUVRow_16_AVX2(reinterpret_cast(src_pixels_u), reinterpret_cast(src_pixels_v), - reinterpret_cast(dst_pixels_uv_opt), 64, + reinterpret_cast(dst_pixels_uv_opt), 16, kPixels); - } else { + } else +#endif + { MergeUVRow_16_C(reinterpret_cast(src_pixels_u), reinterpret_cast(src_pixels_v), - reinterpret_cast(dst_pixels_uv_opt), 64, + reinterpret_cast(dst_pixels_uv_opt), 16, kPixels); } } for (int i = 0; i < kPixels * 2 * 2; ++i) { - EXPECT_EQ(dst_pixels_uv_opt[i], dst_pixels_uv_c[i]); + ASSERT_EQ(dst_pixels_uv_opt[i], dst_pixels_uv_c[i]); } free_aligned_buffer_page_end(src_pixels_u); @@ -2748,11 +4107,14 @@ TEST_F(LibYUVPlanarTest, MergeUVRow_16_Opt) { } #endif -// TODO(fbarchard): Improve test for more platforms. -#ifdef HAS_MULTIPLYROW_16_AVX2 +#if defined(HAS_MULTIPLYROW_16_AVX512BW) || \ + defined(HAS_MULTIPLYROW_16_AVX2) || defined(HAS_MULTIPLYROW_16_NEON) || \ + defined(HAS_MULTIPLYROW_16_SME) || defined(HAS_MULTIPLYROW_16_RVV) || \ + defined(HAS_MULTIPLYROW_16_HVX) TEST_F(LibYUVPlanarTest, MultiplyRow_16_Opt) { - // Round count up to multiple of 16 - const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + // Round count up to multiple of 64 + const int kPixels = (benchmark_width_ * benchmark_height_ + 63) & ~63; + align_buffer_page_end(src_pixels_y, kPixels * 2); align_buffer_page_end(dst_pixels_y_opt, kPixels * 2); align_buffer_page_end(dst_pixels_y_c, kPixels * 2); @@ -2764,13 +4126,69 @@ TEST_F(LibYUVPlanarTest, MultiplyRow_16_Opt) { MultiplyRow_16_C(reinterpret_cast(src_pixels_y), reinterpret_cast(dst_pixels_y_c), 64, kPixels); +#if defined(HAS_MULTIPLYROW_16_AVX512BW) + int has_avx512 = TestCpuFlag(kCpuHasAVX512BW); +#endif +#if defined(HAS_MULTIPLYROW_16_AVX2) int has_avx2 = TestCpuFlag(kCpuHasAVX2); +#endif +#if defined(HAS_MULTIPLYROW_16_NEON) + int has_neon = TestCpuFlag(kCpuHasNEON); +#endif +#if defined(HAS_MULTIPLYROW_16_SME) + int has_sme = TestCpuFlag(kCpuHasSME); +#endif +#if defined(HAS_MULTIPLYROW_16_RVV) + int has_rvv = TestCpuFlag(kCpuHasRVV); +#endif +#if defined(HAS_MULTIPLYROW_16_HVX) + int has_hvx = TestCpuFlag(kCpuHasHVX); +#endif + for (int i = 0; i < benchmark_iterations_; ++i) { - if (has_avx2) { +#if defined(HAS_MULTIPLYROW_16_AVX512BW) + if (has_avx512) { + MultiplyRow_16_AVX512BW(reinterpret_cast(src_pixels_y), + reinterpret_cast(dst_pixels_y_opt), 64, + kPixels); + } else +#endif +#if defined(HAS_MULTIPLYROW_16_AVX2) + if (has_avx2) { MultiplyRow_16_AVX2(reinterpret_cast(src_pixels_y), reinterpret_cast(dst_pixels_y_opt), 64, kPixels); - } else { + } else +#endif +#if defined(HAS_MULTIPLYROW_16_SME) + if (has_sme) { + MultiplyRow_16_SME(reinterpret_cast(src_pixels_y), + reinterpret_cast(dst_pixels_y_opt), 64, + kPixels); + } else +#endif +#if defined(HAS_MULTIPLYROW_16_NEON) + if (has_neon) { + MultiplyRow_16_NEON(reinterpret_cast(src_pixels_y), + reinterpret_cast(dst_pixels_y_opt), 64, + kPixels); + } else +#endif +#if defined(HAS_MULTIPLYROW_16_RVV) + if (has_rvv) { + MultiplyRow_16_RVV(reinterpret_cast(src_pixels_y), + reinterpret_cast(dst_pixels_y_opt), 64, + kPixels); + } else +#endif +#if defined(HAS_MULTIPLYROW_16_HVX) + if (has_hvx) { + MultiplyRow_16_HVX(reinterpret_cast(src_pixels_y), + reinterpret_cast(dst_pixels_y_opt), 64, + kPixels); + } else +#endif + { MultiplyRow_16_C(reinterpret_cast(src_pixels_y), reinterpret_cast(dst_pixels_y_opt), 64, kPixels); @@ -2778,18 +4196,85 @@ TEST_F(LibYUVPlanarTest, MultiplyRow_16_Opt) { } for (int i = 0; i < kPixels * 2; ++i) { - EXPECT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); + ASSERT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); } free_aligned_buffer_page_end(src_pixels_y); free_aligned_buffer_page_end(dst_pixels_y_opt); free_aligned_buffer_page_end(dst_pixels_y_c); } -#endif // HAS_MULTIPLYROW_16_AVX2 + +#if defined(HAS_MULTIPLYROW_16_AVX512BW) || \ + defined(HAS_MULTIPLYROW_16_AVX2) || defined(HAS_MULTIPLYROW_16_NEON) +TEST_F(LibYUVPlanarTest, MultiplyRow_16_Any) { + const int kMaxPixels = 256; + align_buffer_page_end(src_pixels_y, kMaxPixels * 2); + align_buffer_page_end(dst_pixels_y_opt, kMaxPixels * 2); + align_buffer_page_end(dst_pixels_y_c, kMaxPixels * 2); + + for (int i = 0; i < kMaxPixels; ++i) { + reinterpret_cast(src_pixels_y)[i] = fastrand() & 1023; + } + +#if defined(HAS_MULTIPLYROW_16_AVX512BW) + int has_avx512 = TestCpuFlag(kCpuHasAVX512BW); +#endif +#if defined(HAS_MULTIPLYROW_16_AVX2) + int has_avx2 = TestCpuFlag(kCpuHasAVX2); +#endif +#if defined(HAS_MULTIPLYROW_16_NEON) + int has_neon = TestCpuFlag(kCpuHasNEON); +#endif + + for (int width = 1; width <= 129; ++width) { + memset(dst_pixels_y_opt, 0, kMaxPixels * 2); + memset(dst_pixels_y_c, 1, kMaxPixels * 2); + + MultiplyRow_16_C(reinterpret_cast(src_pixels_y), + reinterpret_cast(dst_pixels_y_c), 64, width); + +#if defined(HAS_MULTIPLYROW_16_AVX512BW) + if (has_avx512) { + MultiplyRow_16_AVX512BW(reinterpret_cast(src_pixels_y), + reinterpret_cast(dst_pixels_y_opt), 64, + width); + } else +#endif +#if defined(HAS_MULTIPLYROW_16_AVX2) + if (has_avx2) { + MultiplyRow_16_Any_AVX2(reinterpret_cast(src_pixels_y), + reinterpret_cast(dst_pixels_y_opt), 64, + width); + } else +#endif +#if defined(HAS_MULTIPLYROW_16_NEON) + if (has_neon) { + MultiplyRow_16_Any_NEON(reinterpret_cast(src_pixels_y), + reinterpret_cast(dst_pixels_y_opt), 64, + width); + } else +#endif + { + MultiplyRow_16_C(reinterpret_cast(src_pixels_y), + reinterpret_cast(dst_pixels_y_opt), 64, + width); + } + + for (int i = 0; i < width * 2; ++i) { + ASSERT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); + } + } + + free_aligned_buffer_page_end(src_pixels_y); + free_aligned_buffer_page_end(dst_pixels_y_opt); + free_aligned_buffer_page_end(dst_pixels_y_c); +} +#endif // HAS_MULTIPLYROW_16_AVX512BW || HAS_MULTIPLYROW_16_AVX2 || + // HAS_MULTIPLYROW_16_NEON +#endif // HAS_MULTIPLYROW_16_... TEST_F(LibYUVPlanarTest, Convert16To8Plane) { - // Round count up to multiple of 16 - const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + const int kPixels = benchmark_width_ * benchmark_height_; align_buffer_page_end(src_pixels_y, kPixels * 2); align_buffer_page_end(dst_pixels_y_opt, kPixels); align_buffer_page_end(dst_pixels_y_c, kPixels); @@ -2811,7 +4296,96 @@ TEST_F(LibYUVPlanarTest, Convert16To8Plane) { } for (int i = 0; i < kPixels; ++i) { - EXPECT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); + ASSERT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); + } + + free_aligned_buffer_page_end(src_pixels_y); + free_aligned_buffer_page_end(dst_pixels_y_opt); + free_aligned_buffer_page_end(dst_pixels_y_c); +} + +TEST_F(LibYUVPlanarTest, Convert8To8Plane) { + const int kPixels = benchmark_width_ * benchmark_height_; + align_buffer_page_end(src_pixels_y, kPixels); + align_buffer_page_end(dst_pixels_y_opt, kPixels); + align_buffer_page_end(dst_pixels_y_c, kPixels); + + MemRandomize(src_pixels_y, kPixels); + memset(dst_pixels_y_opt, 0, kPixels); + memset(dst_pixels_y_c, 1, kPixels); + + MaskCpuFlags(disable_cpu_flags_); + Convert8To8Plane(src_pixels_y, benchmark_width_, dst_pixels_y_c, + benchmark_width_, 220, 16, benchmark_width_, + benchmark_height_); + MaskCpuFlags(benchmark_cpu_info_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + Convert8To8Plane(src_pixels_y, benchmark_width_, dst_pixels_y_opt, + benchmark_width_, 220, 16, benchmark_width_, + benchmark_height_); + } + + for (int i = 0; i < kPixels; ++i) { + ASSERT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); + } + + free_aligned_buffer_page_end(src_pixels_y); + free_aligned_buffer_page_end(dst_pixels_y_opt); + free_aligned_buffer_page_end(dst_pixels_y_c); +} + +TEST_F(LibYUVPlanarTest, YUY2ToY) { + const int kPixels = benchmark_width_ * benchmark_height_; + align_buffer_page_end(src_pixels_y, kPixels * 2); + align_buffer_page_end(dst_pixels_y_opt, kPixels); + align_buffer_page_end(dst_pixels_y_c, kPixels); + + MemRandomize(src_pixels_y, kPixels * 2); + memset(dst_pixels_y_opt, 0, kPixels); + memset(dst_pixels_y_c, 1, kPixels); + + MaskCpuFlags(disable_cpu_flags_); + YUY2ToY(src_pixels_y, benchmark_width_ * 2, dst_pixels_y_c, benchmark_width_, + benchmark_width_, benchmark_height_); + MaskCpuFlags(benchmark_cpu_info_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + YUY2ToY(src_pixels_y, benchmark_width_ * 2, dst_pixels_y_opt, + benchmark_width_, benchmark_width_, benchmark_height_); + } + + for (int i = 0; i < kPixels; ++i) { + ASSERT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); + } + + free_aligned_buffer_page_end(src_pixels_y); + free_aligned_buffer_page_end(dst_pixels_y_opt); + free_aligned_buffer_page_end(dst_pixels_y_c); +} + +TEST_F(LibYUVPlanarTest, UYVYToY) { + const int kPixels = benchmark_width_ * benchmark_height_; + align_buffer_page_end(src_pixels_y, kPixels * 2); + align_buffer_page_end(dst_pixels_y_opt, kPixels); + align_buffer_page_end(dst_pixels_y_c, kPixels); + + MemRandomize(src_pixels_y, kPixels * 2); + memset(dst_pixels_y_opt, 0, kPixels); + memset(dst_pixels_y_c, 1, kPixels); + + MaskCpuFlags(disable_cpu_flags_); + UYVYToY(src_pixels_y, benchmark_width_ * 2, dst_pixels_y_c, benchmark_width_, + benchmark_width_, benchmark_height_); + MaskCpuFlags(benchmark_cpu_info_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + UYVYToY(src_pixels_y, benchmark_width_ * 2, dst_pixels_y_opt, + benchmark_width_, benchmark_width_, benchmark_height_); + } + + for (int i = 0; i < kPixels; ++i) { + ASSERT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); } free_aligned_buffer_page_end(src_pixels_y); @@ -2821,10 +4395,10 @@ TEST_F(LibYUVPlanarTest, Convert16To8Plane) { #ifdef ENABLE_ROW_TESTS // TODO(fbarchard): Improve test for more platforms. -#ifdef HAS_CONVERT16TO8ROW_AVX2 +#if defined(HAS_CONVERT16TO8ROW_AVX512BW) || defined(HAS_CONVERT16TO8ROW_AVX2) TEST_F(LibYUVPlanarTest, Convert16To8Row_Opt) { - // AVX2 does multiple of 32, so round count up - const int kPixels = (benchmark_width_ * benchmark_height_ + 31) & ~31; + // AVX512 does multiple of 64, so round count up + const int kPixels = (benchmark_width_ * benchmark_height_ + 63) & ~63; align_buffer_page_end(src_pixels_y, kPixels * 2); align_buffer_page_end(dst_pixels_y_opt, kPixels); align_buffer_page_end(dst_pixels_y_c, kPixels); @@ -2841,35 +4415,335 @@ TEST_F(LibYUVPlanarTest, Convert16To8Row_Opt) { Convert16To8Row_C(reinterpret_cast(src_pixels_y), dst_pixels_y_c, 16384, kPixels); +#if defined(HAS_CONVERT16TO8ROW_AVX512BW) + int has_avx512 = TestCpuFlag(kCpuHasAVX512BW); +#endif +#if defined(HAS_CONVERT16TO8ROW_AVX2) int has_avx2 = TestCpuFlag(kCpuHasAVX2); - int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); +#endif for (int i = 0; i < benchmark_iterations_; ++i) { - if (has_avx2) { +#if defined(HAS_CONVERT16TO8ROW_AVX512BW) + if (has_avx512) { + Convert16To8Row_AVX512BW(reinterpret_cast(src_pixels_y), + dst_pixels_y_opt, 16384, kPixels); + } else +#endif +#if defined(HAS_CONVERT16TO8ROW_AVX2) + if (has_avx2) { Convert16To8Row_AVX2(reinterpret_cast(src_pixels_y), dst_pixels_y_opt, 16384, kPixels); - } else if (has_ssse3) { - Convert16To8Row_SSSE3(reinterpret_cast(src_pixels_y), - dst_pixels_y_opt, 16384, kPixels); - } else { + } else +#endif + { Convert16To8Row_C(reinterpret_cast(src_pixels_y), dst_pixels_y_opt, 16384, kPixels); } } for (int i = 0; i < kPixels; ++i) { - EXPECT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); + ASSERT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); } free_aligned_buffer_page_end(src_pixels_y); free_aligned_buffer_page_end(dst_pixels_y_opt); free_aligned_buffer_page_end(dst_pixels_y_c); } -#endif // HAS_CONVERT16TO8ROW_AVX2 +#endif // HAS_CONVERT16TO8ROW_AVX512BW || HAS_CONVERT16TO8ROW_AVX2 + +#if defined(HAS_HALFWIDTHROW_16TO8_AVX2) || \ + defined(HAS_HALFWIDTHROW_16TO8_SSSE3) || \ + defined(HAS_HALFWIDTHROW_16TO8_AVX512BW) || \ + defined(HAS_HALFWIDTHROW_16TO8_NEON) +TEST_F(LibYUVPlanarTest, HalfWidthRow_16To8_Opt) { + const int kPixels = (benchmark_width_ * benchmark_height_ + 63) & ~63; + align_buffer_page_end_16(src_pixels_uv, kPixels * 4); + align_buffer_page_end(dst_pixels_uv_opt, kPixels); + align_buffer_page_end(dst_pixels_uv_c, kPixels); + + for (int i = 0; i < kPixels * 4; ++i) { + src_pixels_uv[i] = fastrand() & 1023; + } + + memset(dst_pixels_uv_opt, 0, kPixels); + memset(dst_pixels_uv_c, 1, kPixels); + + HalfWidthRow_16To8_C(src_pixels_uv, kPixels * 2, dst_pixels_uv_c, 16384, + kPixels); + +#if defined(HAS_HALFWIDTHROW_16TO8_AVX512BW) + int has_avx512 = TestCpuFlag(kCpuHasAVX512BW); +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_AVX2) + int has_avx2 = TestCpuFlag(kCpuHasAVX2); +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_SSSE3) + int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_NEON) + int has_neon = TestCpuFlag(kCpuHasNEON); +#endif + + for (int i = 0; i < benchmark_iterations_; ++i) { +#if defined(HAS_HALFWIDTHROW_16TO8_AVX512BW) + if (has_avx512) { + HalfWidthRow_16To8_AVX512BW(src_pixels_uv, kPixels * 2, dst_pixels_uv_opt, + 16384, kPixels); + } else +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_AVX2) + if (has_avx2) { + HalfWidthRow_16To8_AVX2(src_pixels_uv, kPixels * 2, dst_pixels_uv_opt, + 16384, kPixels); + } else +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_SSSE3) + if (has_ssse3) { + HalfWidthRow_16To8_SSSE3(src_pixels_uv, kPixels * 2, dst_pixels_uv_opt, + 16384, kPixels); + } else +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_NEON) + if (has_neon) { + HalfWidthRow_16To8_NEON(src_pixels_uv, kPixels * 2, dst_pixels_uv_opt, + 16384, kPixels); + } else +#endif + { + HalfWidthRow_16To8_C(src_pixels_uv, kPixels * 2, dst_pixels_uv_opt, 16384, + kPixels); + } + } + + for (int i = 0; i < kPixels; ++i) { + ASSERT_EQ(dst_pixels_uv_opt[i], dst_pixels_uv_c[i]); + } + + free_aligned_buffer_page_end_16(src_pixels_uv); + free_aligned_buffer_page_end(dst_pixels_uv_opt); + free_aligned_buffer_page_end(dst_pixels_uv_c); +} + +TEST_F(LibYUVPlanarTest, HalfWidthRow_16To8_Any) { + const int kMaxPixels = 256; + align_buffer_page_end_16(src_pixels_uv, kMaxPixels * 4); + align_buffer_page_end(dst_pixels_uv_opt, kMaxPixels); + align_buffer_page_end(dst_pixels_uv_c, kMaxPixels); + + for (int i = 0; i < kMaxPixels * 4; ++i) { + src_pixels_uv[i] = fastrand() & 1023; + } + +#if defined(HAS_HALFWIDTHROW_16TO8_AVX512BW) + int has_avx512 = TestCpuFlag(kCpuHasAVX512BW); +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_AVX2) + int has_avx2 = TestCpuFlag(kCpuHasAVX2); +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_SSSE3) + int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_NEON) + int has_neon = TestCpuFlag(kCpuHasNEON); +#endif + + for (int width = 1; width <= 129; ++width) { + memset(dst_pixels_uv_opt, 0, kMaxPixels); + memset(dst_pixels_uv_c, 1, kMaxPixels); + + HalfWidthRow_16To8_C(src_pixels_uv, kMaxPixels * 2, dst_pixels_uv_c, 16384, + width); + +#if defined(HAS_HALFWIDTHROW_16TO8_AVX512BW) + if (has_avx512) { + HalfWidthRow_16To8_AVX512BW(src_pixels_uv, kMaxPixels * 2, + dst_pixels_uv_opt, 16384, width); + } else +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_AVX2) + if (has_avx2) { + HalfWidthRow_16To8_Any_AVX2(src_pixels_uv, kMaxPixels * 2, + dst_pixels_uv_opt, 16384, width); + } else +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_SSSE3) + if (has_ssse3) { + HalfWidthRow_16To8_Any_SSSE3(src_pixels_uv, kMaxPixels * 2, + dst_pixels_uv_opt, 16384, width); + } else +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_NEON) + if (has_neon) { + HalfWidthRow_16To8_Any_NEON(src_pixels_uv, kMaxPixels * 2, + dst_pixels_uv_opt, 16384, width); + } else +#endif + { + HalfWidthRow_16To8_C(src_pixels_uv, kMaxPixels * 2, dst_pixels_uv_opt, + 16384, width); + } + + for (int i = 0; i < width; ++i) { + ASSERT_EQ(dst_pixels_uv_opt[i], dst_pixels_uv_c[i]); + } + } + + free_aligned_buffer_page_end_16(src_pixels_uv); + free_aligned_buffer_page_end(dst_pixels_uv_opt); + free_aligned_buffer_page_end(dst_pixels_uv_c); +} +#endif + +#if defined(HAS_UYVYTOYROW_AVX512BW) || defined(HAS_UYVYTOYROW_AVX2) || \ + defined(HAS_UYVYTOYROW_NEON) +TEST_F(LibYUVPlanarTest, UYVYToYRow_Opt) { + // AVX2/AVX512 does multiple of 32, so round count up + const int kPixels = (benchmark_width_ * benchmark_height_ + 31) & ~31; + align_buffer_page_end(src_pixels_y, kPixels * 2); + align_buffer_page_end(dst_pixels_y_opt, kPixels); + align_buffer_page_end(dst_pixels_y_c, kPixels); + + MemRandomize(src_pixels_y, kPixels * 2); + memset(dst_pixels_y_opt, 0, kPixels); + memset(dst_pixels_y_c, 1, kPixels); + + UYVYToYRow_C(src_pixels_y, dst_pixels_y_c, kPixels); + +#if defined(HAS_UYVYTOYROW_AVX512BW) + int has_avx512 = TestCpuFlag(kCpuHasAVX512BW); +#endif +#if defined(HAS_UYVYTOYROW_AVX2) + int has_avx2 = TestCpuFlag(kCpuHasAVX2); +#endif +#if defined(HAS_UYVYTOYROW_NEON) + int has_neon = TestCpuFlag(kCpuHasNEON); +#endif + for (int i = 0; i < benchmark_iterations_; ++i) { +#if defined(HAS_UYVYTOYROW_AVX512BW) + if (has_avx512) { + UYVYToYRow_AVX512BW(src_pixels_y, dst_pixels_y_opt, kPixels); + } else +#endif +#if defined(HAS_UYVYTOYROW_AVX2) + if (has_avx2) { + UYVYToYRow_AVX2(src_pixels_y, dst_pixels_y_opt, kPixels); + } else +#endif +#if defined(HAS_UYVYTOYROW_NEON) + if (has_neon) { + UYVYToYRow_NEON(src_pixels_y, dst_pixels_y_opt, kPixels); + } else +#endif + { + UYVYToYRow_C(src_pixels_y, dst_pixels_y_opt, kPixels); + } + } + + for (int i = 0; i < kPixels; ++i) { + ASSERT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); + } + + free_aligned_buffer_page_end(src_pixels_y); + free_aligned_buffer_page_end(dst_pixels_y_opt); + free_aligned_buffer_page_end(dst_pixels_y_c); +} +#endif // HAS_UYVYTOYROW_... + +#if defined(HAS_RGB565TOYROW_AVX2) && defined(HAS_ARGB1555TOYROW_AVX2) && \ + defined(HAS_ARGB4444TOYROW_AVX2) +TEST_F(LibYUVPlanarTest, RGB16ToYUVRow_Opt) { + if (!TestCpuFlag(kCpuHasAVX2)) { + return; + } + const int kMaxWidth = 128; + SIMD_ALIGNED(uint8_t src0[kMaxWidth * 2]); + SIMD_ALIGNED(uint8_t src1[kMaxWidth * 2]); + SIMD_ALIGNED(uint8_t dst_y_c[kMaxWidth]); + SIMD_ALIGNED(uint8_t dst_y_opt[kMaxWidth]); + SIMD_ALIGNED(uint8_t dst_u_c[kMaxWidth]); + SIMD_ALIGNED(uint8_t dst_v_c[kMaxWidth]); + SIMD_ALIGNED(uint8_t dst_u_opt[kMaxWidth]); + SIMD_ALIGNED(uint8_t dst_v_opt[kMaxWidth]); + MemRandomize(src0, sizeof(src0)); + MemRandomize(src1, sizeof(src1)); + + for (int width : {1, 2, 7, 15, 16, 17, 31, 32, 33, 64, 127, 128}) { + const int halfwidth = (width + 1) / 2; + const int stride = kMaxWidth * 2; + + RGB565ToYRow_C(src0, dst_y_c, width); + if (IS_ALIGNED(width, 32)) { + RGB565ToYRow_AVX2(src0, dst_y_opt, width); + } else { + RGB565ToYRow_Any_AVX2(src0, dst_y_opt, width); + } + for (int i = 0; i < width; ++i) { + ASSERT_NEAR(dst_y_c[i], dst_y_opt[i], 1); + } + + ARGB1555ToYRow_C(src0, dst_y_c, width); + if (IS_ALIGNED(width, 32)) { + ARGB1555ToYRow_AVX2(src0, dst_y_opt, width); + } else { + ARGB1555ToYRow_Any_AVX2(src0, dst_y_opt, width); + } + for (int i = 0; i < width; ++i) { + ASSERT_NEAR(dst_y_c[i], dst_y_opt[i], 1); + } + + ARGB4444ToYRow_C(src0, dst_y_c, width); + if (IS_ALIGNED(width, 32)) { + ARGB4444ToYRow_AVX2(src0, dst_y_opt, width); + } else { + ARGB4444ToYRow_Any_AVX2(src0, dst_y_opt, width); + } + for (int i = 0; i < width; ++i) { + ASSERT_NEAR(dst_y_c[i], dst_y_opt[i], 1); + } + + SIMD_ALIGNED(uint8_t src2rows[kMaxWidth * 2 * 2]); + memcpy(src2rows, src0, stride); + memcpy(src2rows + stride, src1, stride); + + RGB565ToUVRow_C(src2rows, stride, dst_u_c, dst_v_c, width); + if (IS_ALIGNED(width, 32)) { + RGB565ToUVRow_AVX2(src2rows, stride, dst_u_opt, dst_v_opt, width); + } else { + RGB565ToUVRow_Any_AVX2(src2rows, stride, dst_u_opt, dst_v_opt, width); + } + for (int i = 0; i < halfwidth; ++i) { + ASSERT_NEAR(dst_u_c[i], dst_u_opt[i], 2); + ASSERT_NEAR(dst_v_c[i], dst_v_opt[i], 2); + } + + ARGB1555ToUVRow_C(src2rows, stride, dst_u_c, dst_v_c, width); + if (IS_ALIGNED(width, 32)) { + ARGB1555ToUVRow_AVX2(src2rows, stride, dst_u_opt, dst_v_opt, width); + } else { + ARGB1555ToUVRow_Any_AVX2(src2rows, stride, dst_u_opt, dst_v_opt, width); + } + for (int i = 0; i < halfwidth; ++i) { + ASSERT_NEAR(dst_u_c[i], dst_u_opt[i], 2); + ASSERT_NEAR(dst_v_c[i], dst_v_opt[i], 2); + } + + ARGB4444ToUVRow_C(src2rows, stride, dst_u_c, dst_v_c, width); + if (IS_ALIGNED(width, 32)) { + ARGB4444ToUVRow_AVX2(src2rows, stride, dst_u_opt, dst_v_opt, width); + } else { + ARGB4444ToUVRow_Any_AVX2(src2rows, stride, dst_u_opt, dst_v_opt, width); + } + for (int i = 0; i < halfwidth; ++i) { + ASSERT_NEAR(dst_u_c[i], dst_u_opt[i], 2); + ASSERT_NEAR(dst_v_c[i], dst_v_opt[i], 2); + } + } +} +#endif + #endif // ENABLE_ROW_TESTS TEST_F(LibYUVPlanarTest, Convert8To16Plane) { - // Round count up to multiple of 16 - const int kPixels = (benchmark_width_ * benchmark_height_ + 15) & ~15; + const int kPixels = benchmark_width_ * benchmark_height_; align_buffer_page_end(src_pixels_y, kPixels); align_buffer_page_end(dst_pixels_y_opt, kPixels * 2); align_buffer_page_end(dst_pixels_y_c, kPixels * 2); @@ -2881,8 +4755,7 @@ TEST_F(LibYUVPlanarTest, Convert8To16Plane) { MaskCpuFlags(disable_cpu_flags_); Convert8To16Plane(src_pixels_y, benchmark_width_, reinterpret_cast(dst_pixels_y_c), - benchmark_width_, 1024, benchmark_width_, - benchmark_height_); + benchmark_width_, 10, benchmark_width_, benchmark_height_); MaskCpuFlags(benchmark_cpu_info_); for (int i = 0; i < benchmark_iterations_; ++i) { @@ -2893,7 +4766,7 @@ TEST_F(LibYUVPlanarTest, Convert8To16Plane) { } for (int i = 0; i < kPixels * 2; ++i) { - EXPECT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); + ASSERT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); } free_aligned_buffer_page_end(src_pixels_y); @@ -2903,9 +4776,9 @@ TEST_F(LibYUVPlanarTest, Convert8To16Plane) { #ifdef ENABLE_ROW_TESTS // TODO(fbarchard): Improve test for more platforms. -#ifdef HAS_CONVERT8TO16ROW_AVX2 +#if defined(HAS_CONVERT8TO16ROW_AVX512BW) || defined(HAS_CONVERT8TO16ROW_AVX2) TEST_F(LibYUVPlanarTest, Convert8To16Row_Opt) { - const int kPixels = (benchmark_width_ * benchmark_height_ + 31) & ~31; + const int kPixels = (benchmark_width_ * benchmark_height_ + 63) & ~63; align_buffer_page_end(src_pixels_y, kPixels); align_buffer_page_end(dst_pixels_y_opt, kPixels * 2); align_buffer_page_end(dst_pixels_y_c, kPixels * 2); @@ -2915,35 +4788,40 @@ TEST_F(LibYUVPlanarTest, Convert8To16Row_Opt) { memset(dst_pixels_y_c, 1, kPixels * 2); Convert8To16Row_C(src_pixels_y, reinterpret_cast(dst_pixels_y_c), - 1024, kPixels); + 10, kPixels); +#if defined(HAS_CONVERT8TO16ROW_AVX512BW) + int has_avx512 = TestCpuFlag(kCpuHasAVX512BW); +#endif int has_avx2 = TestCpuFlag(kCpuHasAVX2); - int has_sse2 = TestCpuFlag(kCpuHasSSE2); for (int i = 0; i < benchmark_iterations_; ++i) { - if (has_avx2) { +#if defined(HAS_CONVERT8TO16ROW_AVX512BW) + if (has_avx512) { + Convert8To16Row_AVX512BW(src_pixels_y, + reinterpret_cast(dst_pixels_y_opt), + 10, kPixels); + } else +#endif + if (has_avx2) { Convert8To16Row_AVX2(src_pixels_y, - reinterpret_cast(dst_pixels_y_opt), 1024, - kPixels); - } else if (has_sse2) { - Convert8To16Row_SSE2(src_pixels_y, - reinterpret_cast(dst_pixels_y_opt), 1024, + reinterpret_cast(dst_pixels_y_opt), 10, kPixels); } else { Convert8To16Row_C(src_pixels_y, - reinterpret_cast(dst_pixels_y_opt), 1024, + reinterpret_cast(dst_pixels_y_opt), 10, kPixels); } } for (int i = 0; i < kPixels * 2; ++i) { - EXPECT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); + ASSERT_EQ(dst_pixels_y_opt[i], dst_pixels_y_c[i]); } free_aligned_buffer_page_end(src_pixels_y); free_aligned_buffer_page_end(dst_pixels_y_opt); free_aligned_buffer_page_end(dst_pixels_y_c); } -#endif // HAS_CONVERT8TO16ROW_AVX2 +#endif // HAS_CONVERT8TO16ROW_AVX512BW || HAS_CONVERT8TO16ROW_AVX2 float TestScaleMaxSamples(int benchmark_width, int benchmark_height, @@ -2976,6 +4854,16 @@ float TestScaleMaxSamples(int benchmark_width, max_opt = ScaleMaxSamples_NEON(reinterpret_cast(orig_y), reinterpret_cast(dst_opt), scale, kPixels); +#elif defined(HAS_SCALEMAXSAMPLES_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + max_opt = ScaleMaxSamples_AVX2(reinterpret_cast(orig_y), + reinterpret_cast(dst_opt), scale, + kPixels); + } else { + max_opt = ScaleMaxSamples_C(reinterpret_cast(orig_y), + reinterpret_cast(dst_opt), scale, + kPixels); + } #else max_opt = ScaleMaxSamples_C(reinterpret_cast(orig_y), @@ -3004,13 +4892,13 @@ float TestScaleMaxSamples(int benchmark_width, TEST_F(LibYUVPlanarTest, TestScaleMaxSamples_C) { float diff = TestScaleMaxSamples(benchmark_width_, benchmark_height_, benchmark_iterations_, 1.2f, false); - EXPECT_EQ(0, diff); + ASSERT_EQ(0, diff); } TEST_F(LibYUVPlanarTest, TestScaleMaxSamples_Opt) { float diff = TestScaleMaxSamples(benchmark_width_, benchmark_height_, benchmark_iterations_, 1.2f, true); - EXPECT_EQ(0, diff); + ASSERT_EQ(0, diff); } float TestScaleSumSamples(int benchmark_width, @@ -3044,6 +4932,16 @@ float TestScaleSumSamples(int benchmark_width, sum_opt = ScaleSumSamples_NEON(reinterpret_cast(orig_y), reinterpret_cast(dst_opt), scale, kPixels); +#elif defined(HAS_SCALESUMSAMPLES_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + sum_opt = ScaleSumSamples_AVX2(reinterpret_cast(orig_y), + reinterpret_cast(dst_opt), scale, + kPixels); + } else { + sum_opt = ScaleSumSamples_C(reinterpret_cast(orig_y), + reinterpret_cast(dst_opt), scale, + kPixels); + } #else sum_opt = ScaleSumSamples_C(reinterpret_cast(orig_y), @@ -3083,13 +4981,13 @@ float TestScaleSumSamples(int benchmark_width, TEST_F(LibYUVPlanarTest, TestScaleSumSamples_C) { float diff = TestScaleSumSamples(benchmark_width_, benchmark_height_, benchmark_iterations_, 1.2f, false); - EXPECT_EQ(0, diff); + ASSERT_EQ(0, diff); } TEST_F(LibYUVPlanarTest, TestScaleSumSamples_Opt) { float diff = TestScaleSumSamples(benchmark_width_, benchmark_height_, benchmark_iterations_, 1.2f, true); - EXPECT_EQ(0, diff); + ASSERT_EQ(0, diff); } float TestScaleSamples(int benchmark_width, @@ -3121,6 +5019,14 @@ float TestScaleSamples(int benchmark_width, #ifdef HAS_SCALESUMSAMPLES_NEON ScaleSamples_NEON(reinterpret_cast(orig_y), reinterpret_cast(dst_opt), scale, kPixels); +#elif defined(HAS_SCALESAMPLES_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + ScaleSamples_AVX2(reinterpret_cast(orig_y), + reinterpret_cast(dst_opt), scale, kPixels); + } else { + ScaleSamples_C(reinterpret_cast(orig_y), + reinterpret_cast(dst_opt), scale, kPixels); + } #else ScaleSamples_C(reinterpret_cast(orig_y), reinterpret_cast(dst_opt), scale, kPixels); @@ -3147,13 +5053,13 @@ float TestScaleSamples(int benchmark_width, TEST_F(LibYUVPlanarTest, TestScaleSamples_C) { float diff = TestScaleSamples(benchmark_width_, benchmark_height_, benchmark_iterations_, 1.2f, false); - EXPECT_EQ(0, diff); + ASSERT_EQ(0, diff); } TEST_F(LibYUVPlanarTest, TestScaleSamples_Opt) { float diff = TestScaleSamples(benchmark_width_, benchmark_height_, benchmark_iterations_, 1.2f, true); - EXPECT_EQ(0, diff); + ASSERT_EQ(0, diff); } float TestCopySamples(int benchmark_width, @@ -3207,52 +5113,59 @@ float TestCopySamples(int benchmark_width, TEST_F(LibYUVPlanarTest, TestCopySamples_C) { float diff = TestCopySamples(benchmark_width_, benchmark_height_, benchmark_iterations_, false); - EXPECT_EQ(0, diff); + ASSERT_EQ(0, diff); } TEST_F(LibYUVPlanarTest, TestCopySamples_Opt) { float diff = TestCopySamples(benchmark_width_, benchmark_height_, benchmark_iterations_, true); - EXPECT_EQ(0, diff); + ASSERT_EQ(0, diff); } extern "C" void GaussRow_NEON(const uint32_t* src, uint16_t* dst, int width); extern "C" void GaussRow_C(const uint32_t* src, uint16_t* dst, int width); TEST_F(LibYUVPlanarTest, TestGaussRow_Opt) { - SIMD_ALIGNED(uint32_t orig_pixels[640 + 4]); - SIMD_ALIGNED(uint16_t dst_pixels_c[640]); - SIMD_ALIGNED(uint16_t dst_pixels_opt[640]); + SIMD_ALIGNED(uint32_t orig_pixels[1280 + 8]); + SIMD_ALIGNED(uint16_t dst_pixels_c[1280]); + SIMD_ALIGNED(uint16_t dst_pixels_opt[1280]); memset(orig_pixels, 0, sizeof(orig_pixels)); memset(dst_pixels_c, 1, sizeof(dst_pixels_c)); memset(dst_pixels_opt, 2, sizeof(dst_pixels_opt)); - for (int i = 0; i < 640 + 4; ++i) { + for (int i = 0; i < 1280 + 8; ++i) { orig_pixels[i] = i * 256; } - GaussRow_C(&orig_pixels[0], &dst_pixels_c[0], 640); - for (int i = 0; i < benchmark_pixels_div1280_ * 2; ++i) { -#if !defined(LIBYUV_DISABLE_NEON) && \ + GaussRow_C(&orig_pixels[0], &dst_pixels_c[0], 1280); + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { +#if defined(HAS_GAUSSROW_AVX2) + int has_avx2 = TestCpuFlag(kCpuHasAVX2); + if (has_avx2) { + GaussRow_AVX2(&orig_pixels[0], &dst_pixels_opt[0], 1280); + } else { + GaussRow_C(&orig_pixels[0], &dst_pixels_opt[0], 1280); + } +#elif !defined(LIBYUV_DISABLE_NEON) && \ (defined(__aarch64__) || defined(__ARM_NEON__) || defined(LIBYUV_NEON)) int has_neon = TestCpuFlag(kCpuHasNEON); if (has_neon) { - GaussRow_NEON(&orig_pixels[0], &dst_pixels_opt[0], 640); + GaussRow_NEON(&orig_pixels[0], &dst_pixels_opt[0], 1280); } else { - GaussRow_C(&orig_pixels[0], &dst_pixels_opt[0], 640); + GaussRow_C(&orig_pixels[0], &dst_pixels_opt[0], 1280); } #else - GaussRow_C(&orig_pixels[0], &dst_pixels_opt[0], 640); + GaussRow_C(&orig_pixels[0], &dst_pixels_opt[0], 1280); #endif } - for (int i = 0; i < 640; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + for (int i = 0; i < 1280; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); } - EXPECT_EQ(dst_pixels_c[0], + ASSERT_EQ(dst_pixels_c[0], static_cast(0 * 1 + 1 * 4 + 2 * 6 + 3 * 4 + 4 * 1)); - EXPECT_EQ(dst_pixels_c[639], static_cast(10256)); + ASSERT_EQ(dst_pixels_c[639], static_cast(10256)); } extern "C" void GaussCol_NEON(const uint16_t* src0, @@ -3272,48 +5185,144 @@ extern "C" void GaussCol_C(const uint16_t* src0, int width); TEST_F(LibYUVPlanarTest, TestGaussCol_Opt) { - SIMD_ALIGNED(uint16_t orig_pixels[640 * 5]); - SIMD_ALIGNED(uint32_t dst_pixels_c[640]); - SIMD_ALIGNED(uint32_t dst_pixels_opt[640]); + SIMD_ALIGNED(uint16_t orig_pixels[1280 * 5]); + SIMD_ALIGNED(uint32_t dst_pixels_c[1280]); + SIMD_ALIGNED(uint32_t dst_pixels_opt[1280]); memset(orig_pixels, 0, sizeof(orig_pixels)); memset(dst_pixels_c, 1, sizeof(dst_pixels_c)); memset(dst_pixels_opt, 2, sizeof(dst_pixels_opt)); - for (int i = 0; i < 640 * 5; ++i) { - orig_pixels[i] = i; + for (int i = 0; i < 1280 * 5; ++i) { + orig_pixels[i] = static_cast(i); } - GaussCol_C(&orig_pixels[0], &orig_pixels[640], &orig_pixels[640 * 2], - &orig_pixels[640 * 3], &orig_pixels[640 * 4], &dst_pixels_c[0], - 640); - for (int i = 0; i < benchmark_pixels_div1280_ * 2; ++i) { -#if !defined(LIBYUV_DISABLE_NEON) && \ + GaussCol_C(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2], + &orig_pixels[1280 * 3], &orig_pixels[1280 * 4], &dst_pixels_c[0], + 1280); + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { +#if defined(HAS_GAUSSCOL_AVX2) + int has_avx2 = TestCpuFlag(kCpuHasAVX2); + if (has_avx2) { + GaussCol_AVX2(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2], + &orig_pixels[1280 * 3], &orig_pixels[1280 * 4], + &dst_pixels_opt[0], 1280); + } else { + GaussCol_C(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2], + &orig_pixels[1280 * 3], &orig_pixels[1280 * 4], + &dst_pixels_opt[0], 1280); + } +#elif !defined(LIBYUV_DISABLE_NEON) && \ (defined(__aarch64__) || defined(__ARM_NEON__) || defined(LIBYUV_NEON)) int has_neon = TestCpuFlag(kCpuHasNEON); if (has_neon) { - GaussCol_NEON(&orig_pixels[0], &orig_pixels[640], &orig_pixels[640 * 2], - &orig_pixels[640 * 3], &orig_pixels[640 * 4], - &dst_pixels_opt[0], 640); + GaussCol_NEON(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2], + &orig_pixels[1280 * 3], &orig_pixels[1280 * 4], + &dst_pixels_opt[0], 1280); } else { - GaussCol_C(&orig_pixels[0], &orig_pixels[640], &orig_pixels[640 * 2], - &orig_pixels[640 * 3], &orig_pixels[640 * 4], - &dst_pixels_opt[0], 640); + GaussCol_C(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2], + &orig_pixels[1280 * 3], &orig_pixels[1280 * 4], + &dst_pixels_opt[0], 1280); } #else - GaussCol_C(&orig_pixels[0], &orig_pixels[640], &orig_pixels[640 * 2], - &orig_pixels[640 * 3], &orig_pixels[640 * 4], &dst_pixels_opt[0], - 640); + GaussCol_C(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2], + &orig_pixels[1280 * 3], &orig_pixels[1280 * 4], + &dst_pixels_opt[0], 1280); #endif } - for (int i = 0; i < 640; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + for (int i = 0; i < 1280; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } +} + +TEST_F(LibYUVPlanarTest, TestGaussRow_F32_Opt) { + SIMD_ALIGNED(float orig_pixels[1280 + 4]); + SIMD_ALIGNED(float dst_pixels_c[1280]); + SIMD_ALIGNED(float dst_pixels_opt[1280]); + + memset(orig_pixels, 0, sizeof(orig_pixels)); + memset(dst_pixels_c, 1, sizeof(dst_pixels_c)); + memset(dst_pixels_opt, 2, sizeof(dst_pixels_opt)); + + for (int i = 0; i < 1280 + 4; ++i) { + orig_pixels[i] = static_cast(i); + } + GaussRow_F32_C(&orig_pixels[0], &dst_pixels_c[0], 1280); + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { +#if defined(HAS_GAUSSROW_F32_AVX2) + int has_avx2 = TestCpuFlag(kCpuHasAVX2); + if (has_avx2) { + GaussRow_F32_AVX2(&orig_pixels[0], &dst_pixels_opt[0], 1280); + } else { + GaussRow_F32_C(&orig_pixels[0], &dst_pixels_opt[0], 1280); + } +#elif !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) + int has_neon = TestCpuFlag(kCpuHasNEON); + if (has_neon) { + GaussRow_F32_NEON(&orig_pixels[0], &dst_pixels_opt[0], 1280); + } else { + GaussRow_F32_C(&orig_pixels[0], &dst_pixels_opt[0], 1280); + } +#else + GaussRow_F32_C(&orig_pixels[0], &dst_pixels_opt[0], 1280); +#endif } - EXPECT_EQ(dst_pixels_c[0], - static_cast(0 * 1 + 640 * 4 + 640 * 2 * 6 + 640 * 3 * 4 + - 640 * 4 * 1)); - EXPECT_EQ(dst_pixels_c[639], static_cast(30704)); + for (int i = 0; i < 1280; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } +} + +TEST_F(LibYUVPlanarTest, TestGaussCol_F32_Opt) { + SIMD_ALIGNED(float dst_pixels_c[1280]); + SIMD_ALIGNED(float dst_pixels_opt[1280]); + align_buffer_page_end(orig_pixels_buf, 1280 * 5 * 4); // 5 rows + float* orig_pixels = reinterpret_cast(orig_pixels_buf); + + memset(orig_pixels, 0, 1280 * 5 * 4); + memset(dst_pixels_c, 1, sizeof(dst_pixels_c)); + memset(dst_pixels_opt, 2, sizeof(dst_pixels_opt)); + + for (int i = 0; i < 1280 * 5; ++i) { + orig_pixels[i] = static_cast(i); + } + GaussCol_F32_C(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2], + &orig_pixels[1280 * 3], &orig_pixels[1280 * 4], + &dst_pixels_c[0], 1280); + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { +#if defined(HAS_GAUSSCOL_F32_AVX2) + int has_avx2 = TestCpuFlag(kCpuHasAVX2); + if (has_avx2) { + GaussCol_F32_AVX2(&orig_pixels[0], &orig_pixels[1280], + &orig_pixels[1280 * 2], &orig_pixels[1280 * 3], + &orig_pixels[1280 * 4], &dst_pixels_opt[0], 1280); + } else { + GaussCol_F32_C(&orig_pixels[0], &orig_pixels[1280], + &orig_pixels[1280 * 2], &orig_pixels[1280 * 3], + &orig_pixels[1280 * 4], &dst_pixels_opt[0], 1280); + } +#elif !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) + int has_neon = TestCpuFlag(kCpuHasNEON); + if (has_neon) { + GaussCol_F32_NEON(&orig_pixels[0], &orig_pixels[1280], + &orig_pixels[1280 * 2], &orig_pixels[1280 * 3], + &orig_pixels[1280 * 4], &dst_pixels_opt[0], 1280); + } else { + GaussCol_F32_C(&orig_pixels[0], &orig_pixels[1280], + &orig_pixels[1280 * 2], &orig_pixels[1280 * 3], + &orig_pixels[1280 * 4], &dst_pixels_opt[0], 1280); + } +#else + GaussCol_F32_C(&orig_pixels[0], &orig_pixels[1280], &orig_pixels[1280 * 2], + &orig_pixels[1280 * 3], &orig_pixels[1280 * 4], + &dst_pixels_opt[0], 1280); +#endif + } + + for (int i = 0; i < 1280; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + free_aligned_buffer_page_end(orig_pixels_buf); } TEST_F(LibYUVPlanarTest, SwapUVRow) { @@ -3326,6 +5335,22 @@ TEST_F(LibYUVPlanarTest, SwapUVRow) { MemRandomize(src_pixels_vu, kPixels * 2); memset(dst_pixels_uv, 1, kPixels * 2); +#if defined(HAS_SWAPUVROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + SwapUVRow = SwapUVRow_Any_SSSE3; + if (IS_ALIGNED(kPixels, 16)) { + SwapUVRow = SwapUVRow_SSSE3; + } + } +#endif +#if defined(HAS_SWAPUVROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + SwapUVRow = SwapUVRow_Any_AVX2; + if (IS_ALIGNED(kPixels, 32)) { + SwapUVRow = SwapUVRow_AVX2; + } + } +#endif #if defined(HAS_SWAPUVROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { SwapUVRow = SwapUVRow_Any_NEON; @@ -3334,18 +5359,1274 @@ TEST_F(LibYUVPlanarTest, SwapUVRow) { } } #endif +#if defined(HAS_SWAPUVROW_RVV) + if (TestCpuFlag(kCpuHasRVV)) { + SwapUVRow = SwapUVRow_RVV; + } +#endif +#if defined(HAS_SWAPUVROW_HVX) + if (TestCpuFlag(kCpuHasHVX)) { + SwapUVRow = SwapUVRow_HVX; + } +#endif for (int j = 0; j < benchmark_iterations_; j++) { SwapUVRow(src_pixels_vu, dst_pixels_uv, kPixels); } for (int i = 0; i < kPixels; ++i) { - EXPECT_EQ(dst_pixels_uv[i * 2 + 0], src_pixels_vu[i * 2 + 1]); - EXPECT_EQ(dst_pixels_uv[i * 2 + 1], src_pixels_vu[i * 2 + 0]); + ASSERT_EQ(dst_pixels_uv[i * 2 + 0], src_pixels_vu[i * 2 + 1]); + ASSERT_EQ(dst_pixels_uv[i * 2 + 1], src_pixels_vu[i * 2 + 0]); } free_aligned_buffer_page_end(src_pixels_vu); free_aligned_buffer_page_end(dst_pixels_uv); } + +TEST_F(LibYUVPlanarTest, HalfRow_Opt) { + const int kMaxPixels = 160; + align_buffer_page_end(src_pixels, kMaxPixels * 2); + align_buffer_page_end(dst_pixels_opt, kMaxPixels); + align_buffer_page_end(dst_pixels_c, kMaxPixels); + MemRandomize(src_pixels, kMaxPixels * 2); + + for (ptrdiff_t stride : {ptrdiff_t{0}, ptrdiff_t{kMaxPixels}}) { + for (int width = 1; width <= 129; ++width) { + memset(dst_pixels_opt, 0, kMaxPixels); + memset(dst_pixels_c, 1, kMaxPixels); + HalfRow_C(src_pixels, stride, dst_pixels_c, width); +#if defined(HAS_HALFROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + if (IS_ALIGNED(width, 32)) { + HalfRow_AVX2(src_pixels, stride, dst_pixels_opt, width); + } else { + HalfRow_Any_AVX2(src_pixels, stride, dst_pixels_opt, width); + } + } else +#endif + { + HalfRow_C(src_pixels, stride, dst_pixels_opt, width); + } + ASSERT_EQ(0, memcmp(dst_pixels_c, dst_pixels_opt, width)) + << "stride=" << stride << " width=" << width; + } + } + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(dst_pixels_c); +} + +TEST_F(LibYUVPlanarTest, HalfRow_16_Opt) { + const int kMaxPixels = 160; + align_buffer_page_end_16(src_pixels, kMaxPixels * 2); + align_buffer_page_end_16(dst_pixels_opt, kMaxPixels); + align_buffer_page_end_16(dst_pixels_c, kMaxPixels); + for (int i = 0; i < kMaxPixels * 2; ++i) { + src_pixels[i] = static_cast(fastrand()); + } + + for (ptrdiff_t stride : {ptrdiff_t{0}, ptrdiff_t{kMaxPixels}}) { + for (int width = 1; width <= 129; ++width) { + memset(dst_pixels_opt, 0, kMaxPixels * 2); + memset(dst_pixels_c, 1, kMaxPixels * 2); + HalfRow_16_C(src_pixels, stride, dst_pixels_c, width); +#if defined(HAS_HALFROW_16_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + if (IS_ALIGNED(width, 16)) { + HalfRow_16_AVX2(src_pixels, stride, dst_pixels_opt, width); + } else { + HalfRow_16_Any_AVX2(src_pixels, stride, dst_pixels_opt, width); + } + } else +#endif + { + HalfRow_16_C(src_pixels, stride, dst_pixels_opt, width); + } + ASSERT_EQ(0, memcmp(dst_pixels_c, dst_pixels_opt, width * 2)) + << "stride=" << stride << " width=" << width; + } + } + + free_aligned_buffer_page_end_16(src_pixels); + free_aligned_buffer_page_end_16(dst_pixels_opt); + free_aligned_buffer_page_end_16(dst_pixels_c); +} + +TEST_F(LibYUVPlanarTest, HalfWidthRow_16To8_Odd_Opt) { + const int kMaxPixels = 160; + align_buffer_page_end_16(src_pixels, kMaxPixels * 4); + align_buffer_page_end(dst_pixels_opt, kMaxPixels); + align_buffer_page_end(dst_pixels_c, kMaxPixels); + for (int i = 0; i < kMaxPixels * 4; ++i) { + src_pixels[i] = fastrand() & 1023; + } + + for (ptrdiff_t stride : {ptrdiff_t{0}, ptrdiff_t{kMaxPixels * 2}}) { + for (int width = 1; width <= 129; ++width) { + memset(dst_pixels_opt, 0, kMaxPixels); + memset(dst_pixels_c, 1, kMaxPixels); + HalfWidthRow_16To8_Odd_C(src_pixels, stride, dst_pixels_c, 16384, width); +#if defined(HAS_HALFWIDTHROW_16TO8_ODD_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + HalfWidthRow_16To8_Odd_AVX2(src_pixels, stride, dst_pixels_opt, 16384, + width); + } else +#endif + { + HalfWidthRow_16To8_Odd_C(src_pixels, stride, dst_pixels_opt, 16384, + width); + } + ASSERT_EQ(0, memcmp(dst_pixels_c, dst_pixels_opt, width)) + << "stride=" << stride << " width=" << width; + } + } + + free_aligned_buffer_page_end_16(src_pixels); + free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(dst_pixels_c); +} + +TEST_F(LibYUVPlanarTest, ARGBChannelReorderRow_C_Test) { + const int kPixels = 65; + align_buffer_page_end(src_argb, kPixels * 4); + align_buffer_page_end(dst_row, kPixels * 4); + align_buffer_page_end(dst_api, kPixels * 4); + MemRandomize(src_argb, kPixels * 4); + + ARGBToABGRRow_C(src_argb, dst_row, kPixels); + ARGBToABGR(src_argb, kPixels * 4, dst_api, kPixels * 4, kPixels, 1); + ASSERT_EQ(0, memcmp(dst_row, dst_api, kPixels * 4)); + + ARGBToBGRARow_C(src_argb, dst_row, kPixels); + ARGBToBGRA(src_argb, kPixels * 4, dst_api, kPixels * 4, kPixels, 1); + ASSERT_EQ(0, memcmp(dst_row, dst_api, kPixels * 4)); + + ARGBToRGBARow_C(src_argb, dst_row, kPixels); + ARGBToRGBA(src_argb, kPixels * 4, dst_api, kPixels * 4, kPixels, 1); + ASSERT_EQ(0, memcmp(dst_row, dst_api, kPixels * 4)); + + RGBAToARGBRow_C(src_argb, dst_row, kPixels); + RGBAToARGB(src_argb, kPixels * 4, dst_api, kPixels * 4, kPixels, 1); + ASSERT_EQ(0, memcmp(dst_row, dst_api, kPixels * 4)); + + align_buffer_page_end_16(src_ar64, kPixels * 4); + align_buffer_page_end_16(dst_ab64_row, kPixels * 4); + align_buffer_page_end_16(dst_ab64_api, kPixels * 4); + for (int i = 0; i < kPixels * 4; ++i) { + src_ar64[i] = static_cast(fastrand()); + } + AR64ToAB64Row_C(src_ar64, dst_ab64_row, kPixels); + AR64ToAB64(src_ar64, kPixels * 4, dst_ab64_api, kPixels * 4, kPixels, 1); + ASSERT_EQ(0, memcmp(dst_ab64_row, dst_ab64_api, kPixels * 8)); + + free_aligned_buffer_page_end_16(src_ar64); + free_aligned_buffer_page_end_16(dst_ab64_row); + free_aligned_buffer_page_end_16(dst_ab64_api); + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(dst_row); + free_aligned_buffer_page_end(dst_api); +} +#endif // ENABLE_ROW_TESTS + +TEST_F(LibYUVPlanarTest, TestGaussPlane_F32) { + const int kSize = benchmark_width_ * benchmark_height_ * 4; + align_buffer_page_end(orig_pixels, kSize); + align_buffer_page_end(dst_pixels_opt, kSize); + align_buffer_page_end(dst_pixels_c, kSize); + + for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { + ((float*)(orig_pixels))[i] = (i & 1023) * 3.14f; + } + memset(dst_pixels_opt, 1, kSize); + memset(dst_pixels_c, 2, kSize); + + MaskCpuFlags(disable_cpu_flags_); + GaussPlane_F32((const float*)(orig_pixels), benchmark_width_, + (float*)(dst_pixels_c), benchmark_width_, benchmark_width_, + benchmark_height_); + MaskCpuFlags(benchmark_cpu_info_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + GaussPlane_F32((const float*)(orig_pixels), benchmark_width_, + (float*)(dst_pixels_opt), benchmark_width_, benchmark_width_, + benchmark_height_); + } + for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { + ASSERT_NEAR(((float*)(dst_pixels_c))[i], ((float*)(dst_pixels_opt))[i], 1.f) + << i; + } + + free_aligned_buffer_page_end(dst_pixels_c); + free_aligned_buffer_page_end(dst_pixels_opt); + free_aligned_buffer_page_end(orig_pixels); +} + +TEST_F(LibYUVPlanarTest, HalfMergeUVPlane_Opt) { + int dst_width = (benchmark_width_ + 1) / 2; + int dst_height = (benchmark_height_ + 1) / 2; + align_buffer_page_end(src_pixels_u, benchmark_width_ * benchmark_height_); + align_buffer_page_end(src_pixels_v, benchmark_width_ * benchmark_height_); + align_buffer_page_end(dst_pixels_uv_opt, dst_width * 2 * dst_height); + align_buffer_page_end(dst_pixels_uv_c, dst_width * 2 * dst_height); + + MemRandomize(src_pixels_u, benchmark_width_ * benchmark_height_); + MemRandomize(src_pixels_v, benchmark_width_ * benchmark_height_); + MemRandomize(dst_pixels_uv_opt, dst_width * 2 * dst_height); + MemRandomize(dst_pixels_uv_c, dst_width * 2 * dst_height); + + MaskCpuFlags(disable_cpu_flags_); + HalfMergeUVPlane(src_pixels_u, benchmark_width_, src_pixels_v, + benchmark_width_, dst_pixels_uv_c, dst_width * 2, + benchmark_width_, benchmark_height_); + MaskCpuFlags(benchmark_cpu_info_); + + for (int i = 0; i < benchmark_iterations_; ++i) { + HalfMergeUVPlane(src_pixels_u, benchmark_width_, src_pixels_v, + benchmark_width_, dst_pixels_uv_opt, dst_width * 2, + benchmark_width_, benchmark_height_); + } + + for (int i = 0; i < dst_width * 2 * dst_height; ++i) { + ASSERT_EQ(dst_pixels_uv_c[i], dst_pixels_uv_opt[i]); + } + + free_aligned_buffer_page_end(src_pixels_u); + free_aligned_buffer_page_end(src_pixels_v); + free_aligned_buffer_page_end(dst_pixels_uv_opt); + free_aligned_buffer_page_end(dst_pixels_uv_c); +} + +TEST_F(LibYUVPlanarTest, NV12Copy) { + const int halfwidth = (benchmark_width_ + 1) >> 1; + const int halfheight = (benchmark_height_ + 1) >> 1; + align_buffer_page_end(src_y, benchmark_width_ * benchmark_height_); + align_buffer_page_end(src_uv, halfwidth * 2 * halfheight); + align_buffer_page_end(dst_y, benchmark_width_ * benchmark_height_); + align_buffer_page_end(dst_uv, halfwidth * 2 * halfheight); + + MemRandomize(src_y, benchmark_width_ * benchmark_height_); + MemRandomize(src_uv, halfwidth * 2 * halfheight); + MemRandomize(dst_y, benchmark_width_ * benchmark_height_); + MemRandomize(dst_uv, halfwidth * 2 * halfheight); + + for (int i = 0; i < benchmark_iterations_; ++i) { + NV12Copy(src_y, benchmark_width_, src_uv, halfwidth * 2, dst_y, + benchmark_width_, dst_uv, halfwidth * 2, benchmark_width_, + benchmark_height_); + } + + for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { + ASSERT_EQ(src_y[i], dst_y[i]); + } + for (int i = 0; i < halfwidth * 2 * halfheight; ++i) { + ASSERT_EQ(src_uv[i], dst_uv[i]); + } + + free_aligned_buffer_page_end(src_y); + free_aligned_buffer_page_end(src_uv); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_uv); +} + +TEST_F(LibYUVPlanarTest, NV21Copy) { + const int halfwidth = (benchmark_width_ + 1) >> 1; + const int halfheight = (benchmark_height_ + 1) >> 1; + align_buffer_page_end(src_y, benchmark_width_ * benchmark_height_); + align_buffer_page_end(src_vu, halfwidth * 2 * halfheight); + align_buffer_page_end(dst_y, benchmark_width_ * benchmark_height_); + align_buffer_page_end(dst_vu, halfwidth * 2 * halfheight); + + MemRandomize(src_y, benchmark_width_ * benchmark_height_); + MemRandomize(src_vu, halfwidth * 2 * halfheight); + MemRandomize(dst_y, benchmark_width_ * benchmark_height_); + MemRandomize(dst_vu, halfwidth * 2 * halfheight); + + for (int i = 0; i < benchmark_iterations_; ++i) { + NV21Copy(src_y, benchmark_width_, src_vu, halfwidth * 2, dst_y, + benchmark_width_, dst_vu, halfwidth * 2, benchmark_width_, + benchmark_height_); + } + + for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) { + ASSERT_EQ(src_y[i], dst_y[i]); + } + for (int i = 0; i < halfwidth * 2 * halfheight; ++i) { + ASSERT_EQ(src_vu[i], dst_vu[i]); + } + + free_aligned_buffer_page_end(src_y); + free_aligned_buffer_page_end(src_vu); + free_aligned_buffer_page_end(dst_y); + free_aligned_buffer_page_end(dst_vu); +} + +#if defined(ENABLE_ROW_TESTS) && !defined(LIBYUV_DISABLE_NEON) && \ + defined(__aarch64__) + +TEST_F(LibYUVPlanarTest, TestConvertFP16ToFP32) { + int i, j; + const int y_plane_size = benchmark_width_ * benchmark_height_; + + align_buffer_page_end(orig_f, y_plane_size * 4); + align_buffer_page_end(orig_y, y_plane_size * 2); + align_buffer_page_end(dst_opt, y_plane_size * 4); + align_buffer_page_end(rec_opt, y_plane_size * 2); + + for (i = 0; i < y_plane_size; ++i) { + ((float*)orig_f)[i] = (float)(i % 10000) * 3.14f; + } + memset(orig_y, 1, y_plane_size * 2); + memset(dst_opt, 2, y_plane_size * 4); + memset(rec_opt, 3, y_plane_size * 2); + + ConvertFP32ToFP16Row_NEON((const float*)orig_f, (uint16_t*)orig_y, + y_plane_size); + + for (j = 0; j < benchmark_iterations_; j++) { + ConvertFP16ToFP32Row_NEON((const uint16_t*)orig_y, (float*)dst_opt, + y_plane_size); + } + + ConvertFP32ToFP16Row_NEON((const float*)dst_opt, (uint16_t*)rec_opt, + y_plane_size); + + for (i = 0; i < y_plane_size; ++i) { + ASSERT_EQ(((const uint16_t*)orig_y)[i], ((const uint16_t*)rec_opt)[i]); + } + + free_aligned_buffer_page_end(orig_f); + free_aligned_buffer_page_end(orig_y); + free_aligned_buffer_page_end(dst_opt); + free_aligned_buffer_page_end(rec_opt); +} + +TEST_F(LibYUVPlanarTest, TestConvertFP16ToFP32Column) { + int i, j; + const int y_plane_size = benchmark_width_ * benchmark_height_; + + align_buffer_page_end(orig_f, y_plane_size * 4); + align_buffer_page_end(orig_y, y_plane_size * 2); + align_buffer_page_end(dst_opt, y_plane_size * 4); + align_buffer_page_end(rec_opt, y_plane_size * 2); + + for (i = 0; i < y_plane_size; ++i) { + ((float*)orig_f)[i] = (float)(i % 10000) * 3.14f; + } + memset(orig_y, 1, y_plane_size * 2); + memset(dst_opt, 2, y_plane_size * 4); + memset(rec_opt, 3, y_plane_size * 2); + + ConvertFP32ToFP16Row_NEON((const float*)orig_f, (uint16_t*)orig_y, + y_plane_size); + + for (j = 0; j < benchmark_iterations_; j++) { + ConvertFP16ToFP32Column_NEON((const uint16_t*)orig_y, 1, (float*)dst_opt, + y_plane_size); + } + + ConvertFP32ToFP16Row_NEON((const float*)dst_opt, (uint16_t*)rec_opt, + y_plane_size); + + for (i = 0; i < y_plane_size; ++i) { + ASSERT_EQ(((const uint16_t*)orig_y)[i], ((const uint16_t*)rec_opt)[i]); + } + + free_aligned_buffer_page_end(orig_f); + free_aligned_buffer_page_end(orig_y); + free_aligned_buffer_page_end(dst_opt); + free_aligned_buffer_page_end(rec_opt); +} + +#endif // defined(ENABLE_ROW_TESTS) && defined(__aarch64__) + +static int TestARGBOr(int width, + int height, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info, + int invert, + int off, + uint32_t value) { + if (width < 1) { + width = 1; + } + const int kBpp = 4; + const int kStride = width * kBpp; + align_buffer_page_end(src_argb, kStride * abs(height) + off); + align_buffer_page_end(dst_argb_c, kStride * abs(height)); + align_buffer_page_end(dst_argb_opt, kStride * abs(height)); + MemRandomize(src_argb, kStride * abs(height) + off); + memset(dst_argb_c, 0, kStride * abs(height)); + memset(dst_argb_opt, 1, kStride * abs(height)); + + MaskCpuFlags(disable_cpu_flags); + ARGBOr(src_argb + off, kStride, dst_argb_c, kStride, width, invert * height, + value); + MaskCpuFlags(benchmark_cpu_info); + for (int i = 0; i < benchmark_iterations; ++i) { + ARGBOr(src_argb + off, kStride, dst_argb_opt, kStride, width, + invert * height, value); + } + int max_diff = 0; + for (int i = 0; i < kStride * abs(height); ++i) { + int abs_diff = abs(static_cast(dst_argb_c[i]) - + static_cast(dst_argb_opt[i])); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(dst_argb_c); + free_aligned_buffer_page_end(dst_argb_opt); + return max_diff; +} + +TEST_F(LibYUVPlanarTest, ARGBOr_Any) { + int max_diff = TestARGBOr(benchmark_width_ + 1, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0, 0xff000000u); + EXPECT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBOr_Unaligned) { + int max_diff = TestARGBOr(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 1, 0xff000000u); + EXPECT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBOr_Invert) { + int max_diff = TestARGBOr(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, -1, 0, 0xff000000u); + EXPECT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBOr_Opt) { + int max_diff = TestARGBOr(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0, 0xff000000u); + EXPECT_EQ(0, max_diff); +} + +static int TestARGBAlphaBlend(int width, + int height, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info, + int invert, + int off) { + if (width < 1) { + width = 1; + } + const int kBpp = 4; + const int kStride = width * kBpp; + align_buffer_page_end(src_argb0, kStride * abs(height) + off); + align_buffer_page_end(src_argb1, kStride * abs(height) + off); + align_buffer_page_end(dst_argb_c, kStride * abs(height)); + align_buffer_page_end(dst_argb_opt, kStride * abs(height)); + MemRandomize(src_argb0, kStride * abs(height) + off); + MemRandomize(src_argb1, kStride * abs(height) + off); + memset(dst_argb_c, 0, kStride * abs(height)); + memset(dst_argb_opt, 1, kStride * abs(height)); + + MaskCpuFlags(disable_cpu_flags); + ARGBAlphaBlend(src_argb0 + off, kStride, src_argb1 + off, kStride, dst_argb_c, + kStride, width, invert * height); + MaskCpuFlags(benchmark_cpu_info); + for (int i = 0; i < benchmark_iterations; ++i) { + ARGBAlphaBlend(src_argb0 + off, kStride, src_argb1 + off, kStride, + dst_argb_opt, kStride, width, invert * height); + } + int max_diff = 0; + for (int i = 0; i < kStride * abs(height); ++i) { + int abs_diff = abs(static_cast(dst_argb_c[i]) - + static_cast(dst_argb_opt[i])); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + free_aligned_buffer_page_end(src_argb0); + free_aligned_buffer_page_end(src_argb1); + free_aligned_buffer_page_end(dst_argb_c); + free_aligned_buffer_page_end(dst_argb_opt); + return max_diff; +} + +TEST_F(LibYUVPlanarTest, ARGBAlphaBlend_Any) { + int max_diff = TestARGBAlphaBlend(benchmark_width_ + 1, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0); + EXPECT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBAlphaBlend_Unaligned) { + int max_diff = TestARGBAlphaBlend(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 1); + EXPECT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBAlphaBlend_Invert) { + int max_diff = TestARGBAlphaBlend(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, -1, 0); + EXPECT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBAlphaBlend_Opt) { + int max_diff = TestARGBAlphaBlend(benchmark_width_, benchmark_height_, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_, +1, 0); + EXPECT_EQ(0, max_diff); +} + +TEST_F(LibYUVPlanarTest, ARGBAlphaBlend_AllAlphas) { + const int kWidth = 256; + const int kHeight = 256; + const int kStride = kWidth * 4; + align_buffer_page_end(src_argb0, kStride * kHeight); + align_buffer_page_end(src_argb1, kStride * kHeight); + align_buffer_page_end(dst_argb_c, kStride * kHeight); + align_buffer_page_end(dst_argb_opt, kStride * kHeight); + for (int da = 0; da < 256; ++da) { + for (int sa = 0; sa < 256; ++sa) { + int idx = (da * 256 + sa) * 4; + src_argb0[idx + 0] = (sa * 7 + da * 3 + 13) & 255; + src_argb0[idx + 1] = (sa * 13 + da * 5 + 29) & 255; + src_argb0[idx + 2] = (sa * 29 + da * 11 + 47) & 255; + src_argb0[idx + 3] = sa; + src_argb1[idx + 0] = (da * 17 + sa * 19 + 53) & 255; + src_argb1[idx + 1] = (da * 23 + sa * 31 + 71) & 255; + src_argb1[idx + 2] = (da * 37 + sa * 41 + 89) & 255; + src_argb1[idx + 3] = da; + } + } + MaskCpuFlags(disable_cpu_flags_); + ARGBAlphaBlend(src_argb0, kStride, src_argb1, kStride, dst_argb_c, kStride, + kWidth, kHeight); + MaskCpuFlags(benchmark_cpu_info_); + ARGBAlphaBlend(src_argb0, kStride, src_argb1, kStride, dst_argb_opt, kStride, + kWidth, kHeight); + for (int i = 0; i < kStride * kHeight; ++i) { + ASSERT_EQ(dst_argb_c[i], dst_argb_opt[i]) << "Mismatch at byte " << i; + } + free_aligned_buffer_page_end(src_argb0); + free_aligned_buffer_page_end(src_argb1); + free_aligned_buffer_page_end(dst_argb_c); + free_aligned_buffer_page_end(dst_argb_opt); +} + +TEST_F(LibYUVPlanarTest, MSanUninitializedInputsAndTails) { + static const int kWidths[] = {1, 7, 15, 16, 17, 31, 32, 33, 63, 64, 65, 99}; + const int kMaxW = 128; + const int kMaxSrcUV = kMaxW * 3 * 2 + 128; + align_buffer_page_end(src0, kMaxW * 4 + 128); + align_buffer_page_end(src1, kMaxW * 4 + 128); + align_buffer_page_end(src2, kMaxW * 4 + 128); + align_buffer_page_end(dst_c0, kMaxW * 4 + 128); + align_buffer_page_end(dst_c1, kMaxW * 4 + 128); + align_buffer_page_end(dst_c2, kMaxW * 4 + 128); + align_buffer_page_end(dst_opt0, kMaxW * 4 + 128); + align_buffer_page_end(dst_opt1, kMaxW * 4 + 128); + align_buffer_page_end(dst_opt2, kMaxW * 4 + 128); + align_buffer_page_end(uv_src, kMaxSrcUV * 3); + + for (size_t wi = 0; wi < sizeof(kWidths) / sizeof(kWidths[0]); ++wi) { + const int w = kWidths[wi]; + const int uv_w = (w + 1) / 2; + + // 1. ARGBToI444 and ARGBToI420 with poisoned RGBX alpha and poisoned tail. + for (int i = 0; i < w; ++i) { + src0[i * 4 + 0] = static_cast((i * 11 + 3) & 255); + src0[i * 4 + 1] = static_cast((i * 17 + 7) & 255); + src0[i * 4 + 2] = static_cast((i * 29 + 13) & 255); + src0[i * 4 + 3] = 0u; + } + MaskCpuFlags(disable_cpu_flags_); + ARGBToI444(src0, w * 4, dst_c0, w, dst_c1, w, dst_c2, w, w, 1); + MaskCpuFlags(benchmark_cpu_info_); + for (int i = 0; i < w; ++i) { + MSAN_POISON(&src0[i * 4 + 3], 1); + } + MSAN_POISON(src0 + w * 4, 128); + MSAN_POISON(dst_opt0, kMaxW * 4); + MSAN_POISON(dst_opt1, kMaxW * 4); + MSAN_POISON(dst_opt2, kMaxW * 4); + ARGBToI444(src0, w * 4, dst_opt0, w, dst_opt1, w, dst_opt2, w, w, 1); + MSAN_CHECK_INITIALIZED(dst_opt0, w); + MSAN_CHECK_INITIALIZED(dst_opt1, w); + MSAN_CHECK_INITIALIZED(dst_opt2, w); + for (int i = 0; i < w; ++i) { + EXPECT_EQ(dst_c0[i], dst_opt0[i]) << "ARGBToI444 Y w=" << w; + EXPECT_EQ(dst_c1[i], dst_opt1[i]) << "ARGBToI444 U w=" << w; + EXPECT_EQ(dst_c2[i], dst_opt2[i]) << "ARGBToI444 V w=" << w; + } + + for (int i = 0; i < w; ++i) { + src0[i * 4 + 3] = 0u; + } + MaskCpuFlags(disable_cpu_flags_); + ARGBToI420(src0, w * 4, dst_c0, w, dst_c1, uv_w, dst_c2, uv_w, w, 1); + MaskCpuFlags(benchmark_cpu_info_); + for (int i = 0; i < w; ++i) { + MSAN_POISON(&src0[i * 4 + 3], 1); + } + MSAN_POISON(src0 + w * 4, 128); + MSAN_POISON(dst_opt0, kMaxW * 4); + MSAN_POISON(dst_opt1, kMaxW * 4); + MSAN_POISON(dst_opt2, kMaxW * 4); + ARGBToI420(src0, w * 4, dst_opt0, w, dst_opt1, uv_w, dst_opt2, uv_w, w, 1); + MSAN_CHECK_INITIALIZED(dst_opt0, w); + MSAN_CHECK_INITIALIZED(dst_opt1, uv_w); + MSAN_CHECK_INITIALIZED(dst_opt2, uv_w); + for (int i = 0; i < w; ++i) { + EXPECT_EQ(dst_c0[i], dst_opt0[i]) << "ARGBToI420 Y w=" << w; + } + for (int i = 0; i < uv_w; ++i) { + EXPECT_EQ(dst_c1[i], dst_opt1[i]) << "ARGBToI420 U w=" << w; + EXPECT_EQ(dst_c2[i], dst_opt2[i]) << "ARGBToI420 V w=" << w; + } + + // 2. ARGBMirror with poisoned alpha on even pixels (verifying per-lane + // shadow permutation) and poisoned tail. + for (int i = 0; i < w; ++i) { + src0[i * 4 + 0] = static_cast((i * 5 + 1) & 255); + src0[i * 4 + 1] = static_cast((i * 9 + 2) & 255); + src0[i * 4 + 2] = static_cast((i * 15 + 3) & 255); + src0[i * 4 + 3] = static_cast((i * 21 + 4) & 255); + } + MaskCpuFlags(disable_cpu_flags_); + ARGBMirror(src0, w * 4, dst_c0, w * 4, w, 1); + MaskCpuFlags(benchmark_cpu_info_); + for (int i = 0; i < w; i += 2) { + MSAN_POISON(&src0[i * 4 + 3], 1); + } + MSAN_POISON(src0 + w * 4, 128); + MSAN_POISON(dst_opt0, kMaxW * 4); + ARGBMirror(src0, w * 4, dst_opt0, w * 4, w, 1); + for (int i = 0; i < w; ++i) { + const int src_i = w - 1 - i; + MSAN_CHECK_INITIALIZED(&dst_opt0[i * 4], 3); + EXPECT_EQ(dst_c0[i * 4 + 0], dst_opt0[i * 4 + 0]); + EXPECT_EQ(dst_c0[i * 4 + 1], dst_opt0[i * 4 + 1]); + EXPECT_EQ(dst_c0[i * 4 + 2], dst_opt0[i * 4 + 2]); + if (src_i & 1) { + MSAN_CHECK_INITIALIZED(&dst_opt0[i * 4 + 3], 1); + EXPECT_EQ(dst_c0[i * 4 + 3], dst_opt0[i * 4 + 3]); + } + } + + // 3. RGB24Mirror, RAWToRGBA, RAWToRGB24, MergeRGBPlane with poisoned tails. + for (int i = 0; i < w * 3; ++i) { + src0[i] = static_cast((i * 19 + 5) & 255); + } + MSAN_POISON(src0 + w * 3, 128); + + MaskCpuFlags(disable_cpu_flags_); + RGB24Mirror(src0, w * 3, dst_c0, w * 3, w, 1); + RAWToRGBA(src0, w * 3, dst_c1, w * 4, w, 1); + RAWToRGB24(src0, w * 3, dst_c2, w * 3, w, 1); + MaskCpuFlags(benchmark_cpu_info_); + MSAN_POISON(dst_opt0, kMaxW * 4); + MSAN_POISON(dst_opt1, kMaxW * 4); + MSAN_POISON(dst_opt2, kMaxW * 4); + RGB24Mirror(src0, w * 3, dst_opt0, w * 3, w, 1); + RAWToRGBA(src0, w * 3, dst_opt1, w * 4, w, 1); + RAWToRGB24(src0, w * 3, dst_opt2, w * 3, w, 1); + MSAN_CHECK_INITIALIZED(dst_opt0, w * 3); + MSAN_CHECK_INITIALIZED(dst_opt1, w * 4); + MSAN_CHECK_INITIALIZED(dst_opt2, w * 3); + EXPECT_EQ(0, memcmp(dst_c0, dst_opt0, w * 3)); + EXPECT_EQ(0, memcmp(dst_c1, dst_opt1, w * 4)); + EXPECT_EQ(0, memcmp(dst_c2, dst_opt2, w * 3)); + + for (int i = 0; i < w; ++i) { + src0[i] = static_cast((i * 3 + 11) & 255); + src1[i] = static_cast((i * 7 + 23) & 255); + src2[i] = static_cast((i * 13 + 37) & 255); + } + MSAN_POISON(src0 + w, 128); + MSAN_POISON(src1 + w, 128); + MSAN_POISON(src2 + w, 128); + MaskCpuFlags(disable_cpu_flags_); + MergeRGBPlane(src0, w, src1, w, src2, w, dst_c0, w * 3, w, 1); + MirrorPlane(src0, w, dst_c1, w, w, 1); + MaskCpuFlags(benchmark_cpu_info_); + MSAN_POISON(dst_opt0, kMaxW * 4); + MSAN_POISON(dst_opt1, kMaxW * 4); + MergeRGBPlane(src0, w, src1, w, src2, w, dst_opt0, w * 3, w, 1); + MirrorPlane(src0, w, dst_opt1, w, w, 1); + MSAN_CHECK_INITIALIZED(dst_opt0, w * 3); + MSAN_CHECK_INITIALIZED(dst_opt1, w); + EXPECT_EQ(0, memcmp(dst_c0, dst_opt0, w * 3)); + EXPECT_EQ(0, memcmp(dst_c1, dst_opt1, w)); + + // 4. MirrorUVPlane and MirrorPlane_16 with poisoned tails. + for (int i = 0; i < w * 2; ++i) { + src0[i] = static_cast((i * 23 + 9) & 255); + } + MSAN_POISON(src0 + w * 2, 128); + MaskCpuFlags(disable_cpu_flags_); + MirrorUVPlane(src0, w * 2, dst_c0, w * 2, w, 1); + MirrorPlane_16(reinterpret_cast(src0), w, + reinterpret_cast(dst_c1), w, w, 1); + MaskCpuFlags(benchmark_cpu_info_); + MSAN_POISON(dst_opt0, kMaxW * 4); + MSAN_POISON(dst_opt1, kMaxW * 4); + MirrorUVPlane(src0, w * 2, dst_opt0, w * 2, w, 1); + MirrorPlane_16(reinterpret_cast(src0), w, + reinterpret_cast(dst_opt1), w, w, 1); + MSAN_CHECK_INITIALIZED(dst_opt0, w * 2); + MSAN_CHECK_INITIALIZED(dst_opt1, w * 2); + EXPECT_EQ(0, memcmp(dst_c0, dst_opt0, w * 2)); + EXPECT_EQ(0, memcmp(dst_c1, dst_opt1, w * 2)); + + // 5. I420ToAR30, NV12ToARGB, NV12ToRGB24, I444ToARGB, I210ToARGB. + for (int i = 0; i < w; ++i) { + src0[i] = static_cast((i * 5 + 16) & 255); + src1[i] = static_cast((i * 9 + 64) & 255); + src2[i] = static_cast((i * 11 + 128) & 255); + } + MSAN_POISON(src0 + w, 128); + MSAN_POISON(src1 + uv_w, 128); + MSAN_POISON(src2 + uv_w, 128); + MaskCpuFlags(disable_cpu_flags_); + I420ToAR30(src0, w, src1, uv_w, src2, uv_w, dst_c0, w * 4, w, 1); + MaskCpuFlags(benchmark_cpu_info_); + MSAN_POISON(dst_opt0, kMaxW * 4); + I420ToAR30(src0, w, src1, uv_w, src2, uv_w, dst_opt0, w * 4, w, 1); + MSAN_CHECK_INITIALIZED(dst_opt0, w * 4); + EXPECT_EQ(0, memcmp(dst_c0, dst_opt0, w * 4)); + + for (int i = 0; i < uv_w * 2; ++i) { + src1[i] = static_cast((i * 13 + 80) & 255); + } + MSAN_POISON(src1 + uv_w * 2, 128); + MaskCpuFlags(disable_cpu_flags_); + NV12ToARGB(src0, w, src1, uv_w * 2, dst_c0, w * 4, w, 1); + NV12ToRGB24(src0, w, src1, uv_w * 2, dst_c1, w * 3, w, 1); + MaskCpuFlags(benchmark_cpu_info_); + MSAN_POISON(dst_opt0, kMaxW * 4); + MSAN_POISON(dst_opt1, kMaxW * 4); + NV12ToARGB(src0, w, src1, uv_w * 2, dst_opt0, w * 4, w, 1); + NV12ToRGB24(src0, w, src1, uv_w * 2, dst_opt1, w * 3, w, 1); + MSAN_CHECK_INITIALIZED(dst_opt0, w * 4); + MSAN_CHECK_INITIALIZED(dst_opt1, w * 3); + EXPECT_EQ(0, memcmp(dst_c0, dst_opt0, w * 4)); + EXPECT_EQ(0, memcmp(dst_c1, dst_opt1, w * 3)); + + for (int i = 0; i < w; ++i) { + reinterpret_cast(src0)[i] = + static_cast((i * 17 + 64) & 1023); + } + for (int i = 0; i < uv_w; ++i) { + reinterpret_cast(src1)[i] = + static_cast((i * 23 + 256) & 1023); + reinterpret_cast(src2)[i] = + static_cast((i * 31 + 512) & 1023); + } + MSAN_POISON(src0 + w * 2, 128); + MSAN_POISON(src1 + uv_w * 2, 128); + MSAN_POISON(src2 + uv_w * 2, 128); + MaskCpuFlags(disable_cpu_flags_); + I210ToARGB(reinterpret_cast(src0), w, + reinterpret_cast(src1), uv_w, + reinterpret_cast(src2), uv_w, dst_c0, w * 4, w, + 1); + MaskCpuFlags(benchmark_cpu_info_); + MSAN_POISON(dst_opt0, kMaxW * 4); + I210ToARGB(reinterpret_cast(src0), w, + reinterpret_cast(src1), uv_w, + reinterpret_cast(src2), uv_w, dst_opt0, w * 4, + w, 1); + MSAN_CHECK_INITIALIZED(dst_opt0, w * 4); + EXPECT_EQ(0, memcmp(dst_c0, dst_opt0, w * 4)); + + // 6. ARGBAlphaBlend with poisoned tails and poisoned destination. + for (int i = 0; i < w * 4; ++i) { + src0[i] = static_cast((i * 29 + 3) & 255); + src1[i] = static_cast((i * 37 + 11) & 255); + } + MSAN_POISON(src0 + w * 4, 128); + MSAN_POISON(src1 + w * 4, 128); + MaskCpuFlags(disable_cpu_flags_); + ARGBAlphaBlend(src0, w * 4, src1, w * 4, dst_c0, w * 4, w, 1); + MaskCpuFlags(benchmark_cpu_info_); + MSAN_POISON(dst_opt0, kMaxW * 4); + ARGBAlphaBlend(src0, w * 4, src1, w * 4, dst_opt0, w * 4, w, 1); + MSAN_CHECK_INITIALIZED(dst_opt0, w * 4); + EXPECT_EQ(0, memcmp(dst_c0, dst_opt0, w * 4)); + + // 7. UVScale 3x box downscale (hits ScaleUVAddCols3_AVX512VBMI). + const int src_uv_w = w * 3; + const int src_uv_stride = src_uv_w * 2 + 64; + MSAN_POISON(uv_src, kMaxSrcUV * 3); + for (int row = 0; row < 3; ++row) { + for (int i = 0; i < src_uv_w * 2; ++i) { + uv_src[row * src_uv_stride + i] = + static_cast((row * 53 + i * 17 + 7) & 255); + } + } + MaskCpuFlags(disable_cpu_flags_); + UVScale(uv_src, src_uv_stride, src_uv_w, 3, dst_c0, w * 2, w, 1, + kFilterBox); + MaskCpuFlags(benchmark_cpu_info_); + MSAN_POISON(dst_opt0, kMaxW * 4); + UVScale(uv_src, src_uv_stride, src_uv_w, 3, dst_opt0, w * 2, w, 1, + kFilterBox); + MSAN_CHECK_INITIALIZED(dst_opt0, w * 2); + EXPECT_EQ(0, memcmp(dst_c0, dst_opt0, w * 2)); + } + + free_aligned_buffer_page_end(src0); + free_aligned_buffer_page_end(src1); + free_aligned_buffer_page_end(src2); + free_aligned_buffer_page_end(dst_c0); + free_aligned_buffer_page_end(dst_c1); + free_aligned_buffer_page_end(dst_c2); + free_aligned_buffer_page_end(dst_opt0); + free_aligned_buffer_page_end(dst_opt1); + free_aligned_buffer_page_end(dst_opt2); + free_aligned_buffer_page_end(uv_src); +} + +// Regression test for RGBToUVMatrixRow_Any_SSSE3 MASK=15 (previously MASK=7 +// overread 24 bytes past src_rgb24 at width=24). +TEST_F(LibYUVPlanarTest, RGB24ToI420_Width24_OOB) { + const int kWidth = 24; + const int kHeight = 2; + align_buffer_page_end(src_rgb24, kWidth * 3 * kHeight); + align_buffer_page_end(dst_y_c, kWidth * kHeight); + align_buffer_page_end(dst_u_c, (kWidth / 2) * (kHeight / 2)); + align_buffer_page_end(dst_v_c, (kWidth / 2) * (kHeight / 2)); + align_buffer_page_end(dst_y_opt, kWidth * kHeight); + align_buffer_page_end(dst_u_opt, (kWidth / 2) * (kHeight / 2)); + align_buffer_page_end(dst_v_opt, (kWidth / 2) * (kHeight / 2)); + MemRandomize(src_rgb24, kWidth * 3 * kHeight); + + MaskCpuFlags(disable_cpu_flags_); + RGB24ToI420(src_rgb24, kWidth * 3, dst_y_c, kWidth, dst_u_c, kWidth / 2, + dst_v_c, kWidth / 2, kWidth, kHeight); + + const int kNoAvx512 = + benchmark_cpu_info_ & ~(kCpuHasAVX512BW | kCpuHasAVX512VL | + kCpuHasAVX512VBMI | kCpuHasAVX512VNNI); + const int kSsse3Only = kNoAvx512 & ~kCpuHasAVX2; + const int kModes[3] = {benchmark_cpu_info_, kNoAvx512, kSsse3Only}; + for (int m = 0; m < 3; ++m) { + MaskCpuFlags(kModes[m]); + memset(dst_y_opt, 0, kWidth * kHeight); + memset(dst_u_opt, 0, (kWidth / 2) * (kHeight / 2)); + memset(dst_v_opt, 0, (kWidth / 2) * (kHeight / 2)); + RGB24ToI420(src_rgb24, kWidth * 3, dst_y_opt, kWidth, dst_u_opt, kWidth / 2, + dst_v_opt, kWidth / 2, kWidth, kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_y_c[i], dst_y_opt[i]); + } + for (int i = 0; i < (kWidth / 2) * (kHeight / 2); ++i) { + ASSERT_EQ(dst_u_c[i], dst_u_opt[i]); + ASSERT_EQ(dst_v_c[i], dst_v_opt[i]); + } + } + MaskCpuFlags(benchmark_cpu_info_); + + free_aligned_buffer_page_end(src_rgb24); + free_aligned_buffer_page_end(dst_y_c); + free_aligned_buffer_page_end(dst_u_c); + free_aligned_buffer_page_end(dst_v_c); + free_aligned_buffer_page_end(dst_y_opt); + free_aligned_buffer_page_end(dst_u_opt); + free_aligned_buffer_page_end(dst_v_opt); +} + +#ifdef ENABLE_ROW_TESTS +#if defined(HAS_HALFWIDTHROW_16TO8_SSSE3) || \ + defined(HAS_HALFWIDTHROW_16TO8_AVX2) || \ + defined(HAS_HALFWIDTHROW_16TO8_AVX512BW) || \ + defined(HAS_HALFROW_16TO8_AVX512BW) +// Regression test for HalfWidthRow_16To8 (>= 0x8000 unsigned MSB samples and +// exact page-end tail bounds) and HalfRow_16To8 (non-power-of-two scale). +TEST_F(LibYUVPlanarTest, Half16To8_HighBitAndNonPow2Scale) { + const int kWidths[] = {1, 7, 15, 24, 31, 33, 63, 65}; + for (size_t w_idx = 0; w_idx < sizeof(kWidths) / sizeof(kWidths[0]); + ++w_idx) { + const int w = kWidths[w_idx]; + align_buffer_page_end_16(src_uv_hw, w * 4); + align_buffer_page_end(dst_c, w); + align_buffer_page_end(dst_opt, w); + for (int i = 0; i < w * 4; ++i) { + src_uv_hw[i] = static_cast(0x8000u + ((i * 257u) & 0x7fffu)); + } + HalfWidthRow_16To8_C(src_uv_hw, w * 2, dst_c, 256, w); +#if defined(HAS_HALFWIDTHROW_16TO8_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + memset(dst_opt, 0x5a, w); + HalfWidthRow_16To8_AVX512BW(src_uv_hw, w * 2, dst_opt, 256, w); + for (int i = 0; i < w; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]) << "AVX512BW w=" << w << " i=" << i; + } + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + memset(dst_opt, 0x5a, w); + HalfWidthRow_16To8_Any_AVX2(src_uv_hw, w * 2, dst_opt, 256, w); + for (int i = 0; i < w; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]) << "AVX2 w=" << w << " i=" << i; + } + } +#endif +#if defined(HAS_HALFWIDTHROW_16TO8_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + memset(dst_opt, 0x5a, w); + HalfWidthRow_16To8_Any_SSSE3(src_uv_hw, w * 2, dst_opt, 256, w); + for (int i = 0; i < w; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]) << "SSSE3 w=" << w << " i=" << i; + } + } #endif + // HalfRow_16To8 with non-power-of-two scale (e.g. 16320). + align_buffer_page_end_16(src_uv_hr, w * 2); + for (int i = 0; i < w * 2; ++i) { + src_uv_hr[i] = static_cast((i * 73u) & 1023u); + } + HalfRow_16To8_C(src_uv_hr, w, dst_c, 16320, w); +#if defined(HAS_HALFROW_16TO8_AVX512BW) + if (TestCpuFlag(kCpuHasAVX512BW)) { + memset(dst_opt, 0x5a, w); + HalfRow_16To8_AVX512BW(src_uv_hr, w, dst_opt, 16320, w); + for (int i = 0; i < w; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]) + << "HalfRow_16To8_AVX512BW w=" << w << " i=" << i; + } + } +#endif + free_aligned_buffer_page_end_16(src_uv_hr); + free_aligned_buffer_page_end_16(src_uv_hw); + free_aligned_buffer_page_end(dst_c); + free_aligned_buffer_page_end(dst_opt); + } +} +#endif // HAS_HALFWIDTHROW_16TO8_* || HAS_HALFROW_16TO8_AVX512BW + +#if defined(HAS_UNPACKMT2T_AVX2) +// Regression test for UnpackMT2T_C and UnpackMT2T_AVX2 when size is not a +// multiple of the 80-byte (64-pixel) MT2T block size. +TEST_F(LibYUVPlanarTest, UnpackMT2T_PartialTail) { + if (!TestCpuFlag(kCpuHasAVX2)) { + return; + } + const size_t kSrcSize = 120; // 1 full 80-byte block + 40 trailing bytes + const size_t kDstCount = (kSrcSize / 80) * 64; + align_buffer_page_end(src, kSrcSize); + align_buffer_page_end_16(dst_c, kDstCount); + align_buffer_page_end_16(dst_opt, kDstCount); + MemRandomize(src, kSrcSize); + UnpackMT2T_C(src, dst_c, kSrcSize); + UnpackMT2T_AVX2(src, dst_opt, kSrcSize); + for (size_t i = 0; i < kDstCount; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]) << "i=" << i; + } + // Verify size < 80 performs zero out-of-bounds reads or writes. + UnpackMT2T_C(src + 80, dst_c, 40); + UnpackMT2T_AVX2(src + 80, dst_opt, 40); + for (size_t i = 0; i < kDstCount; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]) << "i=" << i; + } + free_aligned_buffer_page_end(src); + free_aligned_buffer_page_end_16(dst_c); + free_aligned_buffer_page_end_16(dst_opt); +} +#endif // HAS_UNPACKMT2T_AVX2 +#endif // ENABLE_ROW_TESTS + +// Regression test for ConvertToLSBPlane_16 with depth=16 (scale=65536). +TEST_F(LibYUVPlanarTest, ConvertToLSBPlane_16_Depth16) { + const int kWidth = 37; + const int kHeight = 4; + align_buffer_page_end_16(src_y, kWidth * kHeight); + align_buffer_page_end_16(dst_c, kWidth * kHeight); + align_buffer_page_end_16(dst_opt, kWidth * kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + src_y[i] = static_cast(0x1234u + i * 251u); + } + MaskCpuFlags(disable_cpu_flags_); + ConvertToLSBPlane_16(src_y, kWidth, dst_c, kWidth, kWidth, kHeight, 16); + + const int kNoAvx512 = + benchmark_cpu_info_ & ~(kCpuHasAVX512BW | kCpuHasAVX512VL); + MaskCpuFlags(benchmark_cpu_info_); + memset(dst_opt, 0, kWidth * kHeight * 2); + ConvertToLSBPlane_16(src_y, kWidth, dst_opt, kWidth, kWidth, kHeight, 16); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]); + } + + MaskCpuFlags(kNoAvx512); + memset(dst_opt, 0, kWidth * kHeight * 2); + ConvertToLSBPlane_16(src_y, kWidth, dst_opt, kWidth, kWidth, kHeight, 16); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]); + } + MaskCpuFlags(benchmark_cpu_info_); + + free_aligned_buffer_page_end_16(src_y); + free_aligned_buffer_page_end_16(dst_c); + free_aligned_buffer_page_end_16(dst_opt); +} + +// Regression test for ARGBPolynomial saturation on outputs >= 32768 / 65536, +// odd widths, and 4-byte-aligned (non-16-byte-aligned) polynomial arrays. +TEST_F(LibYUVPlanarTest, ARGBPolynomial_LargeOutputAndUnalignedPoly) { + const int kWidth = 37; + const int kHeight = 3; + align_buffer_page_end(src_argb, kWidth * 4 * kHeight); + align_buffer_page_end(dst_c, kWidth * 4 * kHeight); + align_buffer_page_end(dst_opt, kWidth * 4 * kHeight); + align_buffer_page_end(poly_buf, 17 * sizeof(float)); + // Offset by +1 float so poly is 4-byte aligned, not 16-byte aligned. + float* poly = reinterpret_cast(poly_buf) + 1; + for (int c = 0; c < 4; ++c) { + poly[0 + c] = 0.0f; + poly[4 + c] = 300.0f; // 255 * 300 = 76500 >= 65536 -> must clamp to 255 + poly[8 + c] = 1.0f; // 200^2 = 40000 in [32768, 65535] -> clamp to 255 + poly[12 + c] = 0.0f; + } + for (int i = 0; i < kWidth * 4 * kHeight; ++i) { + src_argb[i] = static_cast(i & 255); + } + + MaskCpuFlags(disable_cpu_flags_); + ARGBPolynomial(src_argb, kWidth * 4, dst_c, kWidth * 4, poly, kWidth, + kHeight); + + const int kSse2Only = + benchmark_cpu_info_ & ~(kCpuHasAVX2 | kCpuHasFMA3 | kCpuHasAVX512BW); + const int kModes[2] = {benchmark_cpu_info_, kSse2Only}; + for (int m = 0; m < 2; ++m) { + MaskCpuFlags(kModes[m]); + memset(dst_opt, 0, kWidth * 4 * kHeight); + ARGBPolynomial(src_argb, kWidth * 4, dst_opt, kWidth * 4, poly, kWidth, + kHeight); + for (int i = 0; i < kWidth * 4 * kHeight; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]) << "mode=" << m << " i=" << i; + } + } + MaskCpuFlags(benchmark_cpu_info_); + + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(dst_c); + free_aligned_buffer_page_end(dst_opt); + free_aligned_buffer_page_end(poly_buf); +} + +// Regression test for ARGBBlur / CumulativeSumToAverageRow_AVX2 when radius=0 +// or radius=1 produces small window areas (area == 1 or area == 2) on 0xff. +TEST_F(LibYUVPlanarTest, ARGBBlur_SmallRadiusWhite) { + const int kWidth = 37; + const int kHeight = 4; + const int kCumSumStride32 = (kWidth + 16) * 4; + align_buffer_page_end(src_argb, kWidth * 4 * kHeight); + align_buffer_page_end(dst_c, kWidth * 4 * kHeight); + align_buffer_page_end(dst_opt, kWidth * 4 * kHeight); + align_buffer_page_end(cumsum, kCumSumStride32 * (kHeight + 2) * 4); + memset(src_argb, 0xff, kWidth * 4 * kHeight); + + for (int radius = 1; radius <= 2; ++radius) { + MaskCpuFlags(disable_cpu_flags_); + ARGBBlur(src_argb, kWidth * 4, dst_c, kWidth * 4, + reinterpret_cast(cumsum), kCumSumStride32, kWidth, + kHeight, radius); + MaskCpuFlags(benchmark_cpu_info_); + memset(dst_opt, 0, kWidth * 4 * kHeight); + ARGBBlur(src_argb, kWidth * 4, dst_opt, kWidth * 4, + reinterpret_cast(cumsum), kCumSumStride32, kWidth, + kHeight, radius); + for (int i = 0; i < kWidth * 4 * kHeight; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]) << "radius=" << radius << " i=" << i; + } + } + + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(dst_c); + free_aligned_buffer_page_end(dst_opt); + free_aligned_buffer_page_end(cumsum); +} + +// Regression test for ARGBLumaColorTable with standard BT.601 green weight +// 150 (> 127) and bright pixels where R*77 + G*150 + B*29 > 32767. +TEST_F(LibYUVPlanarTest, ARGBLumaColorTable_BrightPixels) { + const int kWidth = 37; + const int kHeight = 3; + align_buffer_page_end(src_argb, kWidth * 4 * kHeight); + align_buffer_page_end(dst_c, kWidth * 4 * kHeight); + align_buffer_page_end(dst_opt, kWidth * 4 * kHeight); + align_buffer_page_end(luma, 32768); + for (int i = 0; i < 32768; ++i) { + luma[i] = static_cast(((i >> 8) * 3 + (i & 255)) & 255); + } + for (int i = 0; i < kWidth * kHeight; ++i) { + src_argb[i * 4 + 0] = static_cast(200 + (i % 56)); + src_argb[i * 4 + 1] = static_cast(200 + ((i * 3) % 56)); + src_argb[i * 4 + 2] = static_cast(200 + ((i * 7) % 56)); + src_argb[i * 4 + 3] = static_cast(i & 255); + } + + MaskCpuFlags(disable_cpu_flags_); + ARGBLumaColorTable(src_argb, kWidth * 4, dst_c, kWidth * 4, luma, kWidth, + kHeight); + MaskCpuFlags(benchmark_cpu_info_); + ARGBLumaColorTable(src_argb, kWidth * 4, dst_opt, kWidth * 4, luma, kWidth, + kHeight); + for (int i = 0; i < kWidth * 4 * kHeight; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]) << "i=" << i; + } + + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(dst_c); + free_aligned_buffer_page_end(dst_opt); + free_aligned_buffer_page_end(luma); +} + +#if defined(ENABLE_ROW_TESTS) && !defined(LIBYUV_DISABLE_X86) && \ + (defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) || \ + defined(__i386__)) +// Regression test for 2-byte-aligned (non-16/32-byte-aligned) Intel +// YuvConstants and ArgbConstants structs and custom non-0x8000 kAddUV offsets. +TEST_F(LibYUVPlanarTest, UnalignedMatrixConstantsAndCustomKAddUV) { + const int kWidth = 38; + const int kHeight = 4; + align_buffer_page_end(yuvc_buf, sizeof(YuvConstants) + 16); + align_buffer_page_end(argbc_buf, sizeof(ArgbConstants) + 16); + // Offset by +2 bytes (matches alignof == 2, misaligned for movdqa/vmovdqa). + YuvConstants* yuvc = reinterpret_cast(yuvc_buf + 2); + ArgbConstants* argbc = reinterpret_cast(argbc_buf + 2); + memcpy(yuvc, &kYuvI601Constants, sizeof(YuvConstants)); + memcpy(argbc, &kArgbI601Constants, sizeof(ArgbConstants)); + for (int i = 0; i < 16; ++i) { + argbc->kAddUV[i] = 0x7200u; // Non-default UV bias (!= 0x8000) + } + + align_buffer_page_end(src_argb, kWidth * 4 * kHeight); + align_buffer_page_end(y_c, kWidth * kHeight); + align_buffer_page_end(u_c, kWidth * kHeight); + align_buffer_page_end(v_c, kWidth * kHeight); + align_buffer_page_end(y_opt, kWidth * kHeight); + align_buffer_page_end(u_opt, kWidth * kHeight); + align_buffer_page_end(v_opt, kWidth * kHeight); + align_buffer_page_end(rgb_c, kWidth * 4 * kHeight); + align_buffer_page_end(rgb_opt, kWidth * 4 * kHeight); + MemRandomize(src_argb, kWidth * 4 * kHeight); + + MaskCpuFlags(disable_cpu_flags_); + ARGBToI444Matrix(src_argb, kWidth * 4, y_c, kWidth, u_c, kWidth, v_c, kWidth, + argbc, kWidth, kHeight); + I420ToARGBMatrix(y_c, kWidth, u_c, kWidth / 2, v_c, kWidth / 2, rgb_c, + kWidth * 4, yuvc, kWidth, kHeight); + + const int kNoAvx512 = + benchmark_cpu_info_ & ~(kCpuHasAVX512BW | kCpuHasAVX512VL | + kCpuHasAVX512VBMI | kCpuHasAVX512VNNI); + const int kSsse3Only = kNoAvx512 & ~kCpuHasAVX2; + const int kModes[3] = {benchmark_cpu_info_, kNoAvx512, kSsse3Only}; + for (int m = 0; m < 3; ++m) { + MaskCpuFlags(kModes[m]); + ARGBToI444Matrix(src_argb, kWidth * 4, y_opt, kWidth, u_opt, kWidth, v_opt, + kWidth, argbc, kWidth, kHeight); + I420ToARGBMatrix(y_c, kWidth, u_c, kWidth / 2, v_c, kWidth / 2, rgb_opt, + kWidth * 4, yuvc, kWidth, kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + ASSERT_EQ(y_c[i], y_opt[i]); + ASSERT_EQ(u_c[i], u_opt[i]) << "mode=" << m << " i=" << i; + ASSERT_EQ(v_c[i], v_opt[i]) << "mode=" << m << " i=" << i; + } + for (int i = 0; i < kWidth * 4 * kHeight; ++i) { + ASSERT_EQ(rgb_c[i], rgb_opt[i]) << "mode=" << m << " i=" << i; + } + } + + // Also test ARGBToI420Matrix with custom kAddUV and I400ToARGBMatrix with + // unaligned YuvConstants. + MaskCpuFlags(disable_cpu_flags_); + ARGBToI420Matrix(src_argb, kWidth * 4, y_c, kWidth, u_c, kWidth / 2, v_c, + kWidth / 2, argbc, kWidth, kHeight); + I400ToARGBMatrix(y_c, kWidth, rgb_c, kWidth * 4, yuvc, kWidth, kHeight); + for (int m = 0; m < 3; ++m) { + MaskCpuFlags(kModes[m]); + ARGBToI420Matrix(src_argb, kWidth * 4, y_opt, kWidth, u_opt, kWidth / 2, + v_opt, kWidth / 2, argbc, kWidth, kHeight); + I400ToARGBMatrix(y_c, kWidth, rgb_opt, kWidth * 4, yuvc, kWidth, kHeight); + for (int i = 0; i < (kWidth / 2) * (kHeight / 2); ++i) { + ASSERT_NEAR(u_c[i], u_opt[i], 1) << "mode=" << m << " i=" << i; + ASSERT_NEAR(v_c[i], v_opt[i], 1) << "mode=" << m << " i=" << i; + } + for (int i = 0; i < kWidth * 4 * kHeight; ++i) { + ASSERT_EQ(rgb_c[i], rgb_opt[i]) << "mode=" << m << " i=" << i; + } + } + MaskCpuFlags(benchmark_cpu_info_); + + free_aligned_buffer_page_end(yuvc_buf); + free_aligned_buffer_page_end(argbc_buf); + free_aligned_buffer_page_end(src_argb); + free_aligned_buffer_page_end(y_c); + free_aligned_buffer_page_end(u_c); + free_aligned_buffer_page_end(v_c); + free_aligned_buffer_page_end(y_opt); + free_aligned_buffer_page_end(u_opt); + free_aligned_buffer_page_end(v_opt); + free_aligned_buffer_page_end(rgb_c); + free_aligned_buffer_page_end(rgb_opt); +} +#endif // ENABLE_ROW_TESTS + +// Regression test for MergeAR64Plane depth=16 (UBSan shift) and +// MergeARGB16To8Plane depth=8 saturation on out-of-range >255 samples. +TEST_F(LibYUVPlanarTest, MergeAR64Depth16AndMergeARGB16To8Depth8Clamp) { + const int kWidth = 37; + const int kHeight = 2; + align_buffer_page_end_16(src_r, kWidth * kHeight); + align_buffer_page_end_16(src_g, kWidth * kHeight); + align_buffer_page_end_16(src_b, kWidth * kHeight); + align_buffer_page_end_16(src_a, kWidth * kHeight); + align_buffer_page_end_16(ar64_c, kWidth * 4 * kHeight); + align_buffer_page_end_16(ar64_opt, kWidth * 4 * kHeight); + align_buffer_page_end(argb_c, kWidth * 4 * kHeight); + align_buffer_page_end(argb_opt, kWidth * 4 * kHeight); + for (int i = 0; i < kWidth * kHeight; ++i) { + src_r[i] = static_cast(200u + (i * 19u)); + src_g[i] = static_cast(100u + (i * 37u)); + src_b[i] = static_cast(50u + (i * 53u)); + src_a[i] = static_cast(0x8000u + (i * 101u)); + } + + MaskCpuFlags(disable_cpu_flags_); + MergeAR64Plane(src_r, kWidth, src_g, kWidth, src_b, kWidth, src_a, kWidth, + ar64_c, kWidth * 4, kWidth, kHeight, 16); + MergeARGB16To8Plane(src_r, kWidth, src_g, kWidth, src_b, kWidth, src_a, + kWidth, argb_c, kWidth * 4, kWidth, kHeight, 8); + + MaskCpuFlags(benchmark_cpu_info_); + MergeAR64Plane(src_r, kWidth, src_g, kWidth, src_b, kWidth, src_a, kWidth, + ar64_opt, kWidth * 4, kWidth, kHeight, 16); + MergeARGB16To8Plane(src_r, kWidth, src_g, kWidth, src_b, kWidth, src_a, + kWidth, argb_opt, kWidth * 4, kWidth, kHeight, 8); + + for (int i = 0; i < kWidth * 4 * kHeight; ++i) { + ASSERT_EQ(ar64_c[i], ar64_opt[i]); + ASSERT_EQ(argb_c[i], argb_opt[i]); + } + + free_aligned_buffer_page_end_16(src_r); + free_aligned_buffer_page_end_16(src_g); + free_aligned_buffer_page_end_16(src_b); + free_aligned_buffer_page_end_16(src_a); + free_aligned_buffer_page_end_16(ar64_c); + free_aligned_buffer_page_end_16(ar64_opt); + free_aligned_buffer_page_end(argb_c); + free_aligned_buffer_page_end(argb_opt); +} + } // namespace libyuv diff --git a/libs/libyuv/unit_test/rotate_argb_test.cc b/libs/libyuv/unit_test/rotate_argb_test.cc index d200389596..902aa81294 100644 --- a/libs/libyuv/unit_test/rotate_argb_test.cc +++ b/libs/libyuv/unit_test/rotate_argb_test.cc @@ -12,19 +12,20 @@ #include "../unit_test/unit_test.h" #include "libyuv/cpu_id.h" +#include "libyuv/planar_functions.h" #include "libyuv/rotate_argb.h" namespace libyuv { -void TestRotateBpp(int src_width, - int src_height, - int dst_width, - int dst_height, - libyuv::RotationMode mode, - int benchmark_iterations, - int disable_cpu_flags, - int benchmark_cpu_info, - const int kBpp) { +static void TestRotateBpp(int src_width, + int src_height, + int dst_width, + int dst_height, + libyuv::RotationMode mode, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info, + const int kBpp) { if (src_width < 1) { src_width = 1; } @@ -75,7 +76,7 @@ void TestRotateBpp(int src_width, // Rotation should be exact. for (int i = 0; i < dst_argb_plane_size; ++i) { - EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]); + ASSERT_EQ(dst_argb_c[i], dst_argb_opt[i]); } free_aligned_buffer_page_end(dst_argb_c); @@ -119,6 +120,20 @@ TEST_F(LibYUVRotateTest, ARGBRotate270_Opt) { disable_cpu_flags_, benchmark_cpu_info_); } +TEST_F(LibYUVRotateTest, ARGBRotate90_Odd) { + ARGBTestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate90, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, ARGBRotate270_Odd) { + ARGBTestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate270, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_); +} + static void TestRotatePlane(int src_width, int src_height, int dst_width, @@ -156,31 +171,271 @@ TEST_F(LibYUVRotateTest, RotatePlane270_Opt) { } TEST_F(LibYUVRotateTest, DISABLED_RotatePlane0_Odd) { - TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_width_ - 3, benchmark_height_ - 1, kRotate0, + TestRotatePlane(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_width_ + 1, benchmark_height_ + 1, kRotate0, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_RotatePlane90_Odd) { - TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_height_ - 1, benchmark_width_ - 3, kRotate90, + TestRotatePlane(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate90, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_RotatePlane180_Odd) { - TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_width_ - 3, benchmark_height_ - 1, kRotate180, + TestRotatePlane(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_width_ + 1, benchmark_height_ + 1, kRotate180, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_RotatePlane270_Odd) { - TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_height_ - 1, benchmark_width_ - 3, kRotate270, + TestRotatePlane(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate270, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } +TEST_F(LibYUVRotateTest, RotatePlane90_TestStride) { + int argb_plane_size = benchmark_width_ * 4 * abs(benchmark_height_); + + align_buffer_page_end(src_argb, argb_plane_size); + align_buffer_page_end(dst_argb, argb_plane_size); + + ASSERT_EQ(0, ARGBRotate(src_argb, benchmark_width_ * 4, dst_argb, + benchmark_width_ * 4, benchmark_width_, + benchmark_height_, kRotate0)); + + ASSERT_EQ(0, ARGBRotate(src_argb, benchmark_width_ * 4 - 1, dst_argb, + benchmark_width_ * 4 - 1, benchmark_width_ - 1, + benchmark_height_, kRotate0)); + + ASSERT_EQ(0, ARGBRotate(src_argb, benchmark_width_ * 4, dst_argb, + benchmark_width_ * 4, benchmark_width_, + benchmark_height_, kRotate180)); + + ASSERT_EQ(0, ARGBRotate(src_argb, benchmark_width_ * 4 - 1, dst_argb, + benchmark_width_ * 4 - 1, benchmark_width_ - 1, + benchmark_height_, kRotate180)); + + ASSERT_EQ(0, ARGBRotate(src_argb, benchmark_width_ * 4, dst_argb, + abs(benchmark_height_) * 4, benchmark_width_, + benchmark_height_, kRotate90)); + + ASSERT_EQ(-1, ARGBRotate(src_argb, benchmark_width_ * 4 - 1, dst_argb, + abs(benchmark_height_) * 4, benchmark_width_ - 1, + benchmark_height_, kRotate90)); + + ASSERT_EQ(0, ARGBRotate(src_argb, benchmark_width_ * 4, dst_argb, + abs(benchmark_height_) * 4, benchmark_width_, + benchmark_height_, kRotate270)); + + ASSERT_EQ(-1, ARGBRotate(src_argb, benchmark_width_ * 4 - 1, dst_argb, + abs(benchmark_height_) * 4, benchmark_width_ - 1, + benchmark_height_, kRotate270)); + + free_aligned_buffer_page_end(dst_argb); + free_aligned_buffer_page_end(src_argb); +} + +static void TestRotatePlane_16(int src_width, + int src_height, + int dst_width, + int dst_height, + libyuv::RotationMode mode, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (src_width < 1) { + src_width = 1; + } + if (src_height < 1) { + src_height = 1; + } + if (dst_width < 1) { + dst_width = 1; + } + if (dst_height < 1) { + dst_height = 1; + } + int src_stride = src_width; + int src_plane_size = src_stride * abs(src_height); + align_buffer_page_end_16(src, src_plane_size); + for (int i = 0; i < src_plane_size; ++i) { + src[i] = fastrand() & 0xffff; + } + + int dst_stride = dst_width; + int dst_plane_size = dst_stride * dst_height; + align_buffer_page_end_16(dst_c, dst_plane_size); + align_buffer_page_end_16(dst_opt, dst_plane_size); + memset(dst_c, 2, dst_plane_size * 2); + memset(dst_opt, 3, dst_plane_size * 2); + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + RotatePlane_16(src, src_stride, dst_c, dst_stride, src_width, src_height, + mode); + + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + for (int i = 0; i < benchmark_iterations; ++i) { + RotatePlane_16(src, src_stride, dst_opt, dst_stride, src_width, src_height, + mode); + } + + // Rotation should be exact. + for (int i = 0; i < dst_plane_size; ++i) { + ASSERT_EQ(dst_c[i], dst_opt[i]); + } + + free_aligned_buffer_page_end_16(dst_c); + free_aligned_buffer_page_end_16(dst_opt); + free_aligned_buffer_page_end_16(src); +} + +TEST_F(LibYUVRotateTest, RotatePlane0_16_Opt) { + TestRotatePlane_16(benchmark_width_, benchmark_height_, benchmark_width_, + benchmark_height_, kRotate0, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, RotatePlane90_16_Opt) { + TestRotatePlane_16(benchmark_width_, benchmark_height_, benchmark_height_, + benchmark_width_, kRotate90, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, RotatePlane180_16_Opt) { + TestRotatePlane_16(benchmark_width_, benchmark_height_, benchmark_width_, + benchmark_height_, kRotate180, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, RotatePlane270_16_Opt) { + TestRotatePlane_16(benchmark_width_, benchmark_height_, benchmark_height_, + benchmark_width_, kRotate270, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, RotatePlane0_16_Odd) { + TestRotatePlane_16(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_width_ + 1, benchmark_height_ + 1, kRotate0, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, RotatePlane90_16_Odd) { + TestRotatePlane_16(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate90, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, RotatePlane180_16_Odd) { + TestRotatePlane_16(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_width_ + 1, benchmark_height_ + 1, kRotate180, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, RotatePlane270_16_Odd) { + TestRotatePlane_16(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate270, + benchmark_iterations_, disable_cpu_flags_, + benchmark_cpu_info_); +} + +static void TestRotatePlane16_SplitMergeUV(int src_width, + int src_height, + int dst_width, + int dst_height, + libyuv::RotationMode mode, + int benchmark_cpu_info) { + if (src_width < 1) { + src_width = 1; + } + if (src_height < 1) { + src_height = 1; + } + if (dst_width < 1) { + dst_width = 1; + } + if (dst_height < 1) { + dst_height = 1; + } + const int src_pixels = src_width * src_height; + const int dst_pixels = dst_width * dst_height; + align_buffer_page_end(src_16, src_pixels * 2); + align_buffer_page_end(dst_16, dst_pixels * 2); + align_buffer_page_end(ref_16, dst_pixels * 2); + align_buffer_page_end(src_lo, src_pixels); + align_buffer_page_end(src_hi, src_pixels); + align_buffer_page_end(dst_lo, dst_pixels); + align_buffer_page_end(dst_hi, dst_pixels); + for (int i = 0; i < src_pixels * 2; ++i) { + src_16[i] = fastrand() & 0xff; + } + memset(dst_16, 2, dst_pixels * 2); + memset(ref_16, 3, dst_pixels * 2); + + MaskCpuFlags(benchmark_cpu_info); + SplitUVPlane(src_16, src_width * 2, src_lo, src_width, src_hi, src_width, + src_width, src_height); + RotatePlane(src_lo, src_width, dst_lo, dst_width, src_width, src_height, + mode); + RotatePlane(src_hi, src_width, dst_hi, dst_width, src_width, src_height, + mode); + MergeUVPlane(dst_lo, dst_width, dst_hi, dst_width, ref_16, dst_width * 2, + dst_width, dst_height); + + I410Rotate(reinterpret_cast(src_16), src_width, + reinterpret_cast(src_16), src_width, + reinterpret_cast(src_16), src_width, + reinterpret_cast(dst_16), dst_width, + reinterpret_cast(dst_16), dst_width, + reinterpret_cast(dst_16), dst_width, src_width, + src_height, mode); + + EXPECT_EQ(0, memcmp(ref_16, dst_16, dst_pixels * 2)); + + free_aligned_buffer_page_end(dst_hi); + free_aligned_buffer_page_end(dst_lo); + free_aligned_buffer_page_end(src_hi); + free_aligned_buffer_page_end(src_lo); + free_aligned_buffer_page_end(ref_16); + free_aligned_buffer_page_end(dst_16); + free_aligned_buffer_page_end(src_16); +} + +TEST_F(LibYUVRotateTest, RotatePlane16_SplitMergeUV_Opt) { + TestRotatePlane16_SplitMergeUV(benchmark_width_, benchmark_height_, + benchmark_width_, benchmark_height_, kRotate0, + benchmark_cpu_info_); + TestRotatePlane16_SplitMergeUV(benchmark_width_, benchmark_height_, + benchmark_height_, benchmark_width_, kRotate90, + benchmark_cpu_info_); + TestRotatePlane16_SplitMergeUV(benchmark_width_, benchmark_height_, + benchmark_width_, benchmark_height_, + kRotate180, benchmark_cpu_info_); + TestRotatePlane16_SplitMergeUV(benchmark_width_, benchmark_height_, + benchmark_height_, benchmark_width_, + kRotate270, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, RotatePlane16_SplitMergeUV_Odd) { + TestRotatePlane16_SplitMergeUV(benchmark_width_ + 3, benchmark_height_ + 5, + benchmark_width_ + 3, benchmark_height_ + 5, + kRotate0, benchmark_cpu_info_); + TestRotatePlane16_SplitMergeUV(benchmark_width_ + 3, benchmark_height_ + 5, + benchmark_height_ + 5, benchmark_width_ + 3, + kRotate90, benchmark_cpu_info_); + TestRotatePlane16_SplitMergeUV(benchmark_width_ + 3, benchmark_height_ + 5, + benchmark_width_ + 3, benchmark_height_ + 5, + kRotate180, benchmark_cpu_info_); + TestRotatePlane16_SplitMergeUV(benchmark_width_ + 3, benchmark_height_ + 5, + benchmark_height_ + 5, benchmark_width_ + 3, + kRotate270, benchmark_cpu_info_); +} + } // namespace libyuv diff --git a/libs/libyuv/unit_test/rotate_test.cc b/libs/libyuv/unit_test/rotate_test.cc index 61941e63e0..5ddf899cbe 100644 --- a/libs/libyuv/unit_test/rotate_test.cc +++ b/libs/libyuv/unit_test/rotate_test.cc @@ -14,8 +14,19 @@ #include "libyuv/cpu_id.h" #include "libyuv/rotate.h" +#if !defined(LIBYUV_USING_SHARED_LIBRARY) && !defined(COMPONENT_BUILD) && \ + !defined(ENABLE_ROW_TESTS) +#define ENABLE_ROW_TESTS +#endif + +#ifdef ENABLE_ROW_TESTS +#include "libyuv/rotate_row.h" +#endif + namespace libyuv { +#define SUBSAMPLE(v, a) ((((v) + (a) - 1)) / (a)) + static void I420TestRotate(int src_width, int src_height, int dst_width, @@ -72,7 +83,7 @@ static void I420TestRotate(int src_width, // Rotation should be exact. for (int i = 0; i < dst_i420_size; ++i) { - EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); + ASSERT_EQ(dst_i420_c[i], dst_i420_opt[i]); } free_aligned_buffer_page_end(dst_i420_c); @@ -108,33 +119,121 @@ TEST_F(LibYUVRotateTest, I420Rotate270_Opt) { // Odd width tests work but disabled because they use C code and can be // tested by passing an odd width command line or environment variable. TEST_F(LibYUVRotateTest, DISABLED_I420Rotate0_Odd) { - I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_width_ - 3, benchmark_height_ - 1, kRotate0, + I420TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_width_ + 1, benchmark_height_ + 1, kRotate0, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_I420Rotate90_Odd) { - I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_height_ - 1, benchmark_width_ - 3, kRotate90, + I420TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate90, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_I420Rotate180_Odd) { - I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_width_ - 3, benchmark_height_ - 1, kRotate180, + I420TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_width_ + 1, benchmark_height_ + 1, kRotate180, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_I420Rotate270_Odd) { - I420TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_height_ - 1, benchmark_width_ - 3, kRotate270, + I420TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate270, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } +static void I422TestRotate(int src_width, + int src_height, + int dst_width, + int dst_height, + libyuv::RotationMode mode, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (src_width < 1) { + src_width = 1; + } + if (src_height == 0) { + src_height = 1; + } + if (dst_width < 1) { + dst_width = 1; + } + if (dst_height < 1) { + dst_height = 1; + } + int src_i422_y_size = src_width * Abs(src_height); + int src_i422_uv_size = ((src_width + 1) / 2) * Abs(src_height); + int src_i422_size = src_i422_y_size + src_i422_uv_size * 2; + align_buffer_page_end(src_i422, src_i422_size); + for (int i = 0; i < src_i422_size; ++i) { + src_i422[i] = fastrand() & 0xff; + } + + int dst_i422_y_size = dst_width * dst_height; + int dst_i422_uv_size = ((dst_width + 1) / 2) * dst_height; + int dst_i422_size = dst_i422_y_size + dst_i422_uv_size * 2; + align_buffer_page_end(dst_i422_c, dst_i422_size); + align_buffer_page_end(dst_i422_opt, dst_i422_size); + memset(dst_i422_c, 2, dst_i422_size); + memset(dst_i422_opt, 3, dst_i422_size); + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + I422Rotate(src_i422, src_width, src_i422 + src_i422_y_size, + (src_width + 1) / 2, src_i422 + src_i422_y_size + src_i422_uv_size, + (src_width + 1) / 2, dst_i422_c, dst_width, + dst_i422_c + dst_i422_y_size, (dst_width + 1) / 2, + dst_i422_c + dst_i422_y_size + dst_i422_uv_size, + (dst_width + 1) / 2, src_width, src_height, mode); + + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + for (int i = 0; i < benchmark_iterations; ++i) { + I422Rotate( + src_i422, src_width, src_i422 + src_i422_y_size, (src_width + 1) / 2, + src_i422 + src_i422_y_size + src_i422_uv_size, (src_width + 1) / 2, + dst_i422_opt, dst_width, dst_i422_opt + dst_i422_y_size, + (dst_width + 1) / 2, dst_i422_opt + dst_i422_y_size + dst_i422_uv_size, + (dst_width + 1) / 2, src_width, src_height, mode); + } + + // Rotation should be exact. + for (int i = 0; i < dst_i422_size; ++i) { + ASSERT_EQ(dst_i422_c[i], dst_i422_opt[i]); + } + + free_aligned_buffer_page_end(dst_i422_c); + free_aligned_buffer_page_end(dst_i422_opt); + free_aligned_buffer_page_end(src_i422); +} + +TEST_F(LibYUVRotateTest, I422Rotate0_Opt) { + I422TestRotate(benchmark_width_, benchmark_height_, benchmark_width_, + benchmark_height_, kRotate0, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I422Rotate90_Opt) { + I422TestRotate(benchmark_width_, benchmark_height_, benchmark_height_, + benchmark_width_, kRotate90, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I422Rotate180_Opt) { + I422TestRotate(benchmark_width_, benchmark_height_, benchmark_width_, + benchmark_height_, kRotate180, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I422Rotate270_Opt) { + I422TestRotate(benchmark_width_, benchmark_height_, benchmark_height_, + benchmark_width_, kRotate270, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + static void I444TestRotate(int src_width, int src_height, int dst_width, @@ -189,7 +288,7 @@ static void I444TestRotate(int src_width, // Rotation should be exact. for (int i = 0; i < dst_i444_size; ++i) { - EXPECT_EQ(dst_i444_c[i], dst_i444_opt[i]); + ASSERT_EQ(dst_i444_c[i], dst_i444_opt[i]); } free_aligned_buffer_page_end(dst_i444_c); @@ -225,29 +324,29 @@ TEST_F(LibYUVRotateTest, I444Rotate270_Opt) { // Odd width tests work but disabled because they use C code and can be // tested by passing an odd width command line or environment variable. TEST_F(LibYUVRotateTest, DISABLED_I444Rotate0_Odd) { - I444TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_width_ - 3, benchmark_height_ - 1, kRotate0, + I444TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_width_ + 1, benchmark_height_ + 1, kRotate0, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_I444Rotate90_Odd) { - I444TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_height_ - 1, benchmark_width_ - 3, kRotate90, + I444TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate90, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_I444Rotate180_Odd) { - I444TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_width_ - 3, benchmark_height_ - 1, kRotate180, + I444TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_width_ + 1, benchmark_height_ + 1, kRotate180, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_I444Rotate270_Odd) { - I444TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_height_ - 1, benchmark_width_ - 3, kRotate270, + I444TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate270, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } @@ -307,7 +406,7 @@ static void NV12TestRotate(int src_width, // Rotation should be exact. for (int i = 0; i < dst_i420_size; ++i) { - EXPECT_EQ(dst_i420_c[i], dst_i420_opt[i]); + ASSERT_EQ(dst_i420_c[i], dst_i420_opt[i]); } free_aligned_buffer_page_end(dst_i420_c); @@ -340,29 +439,29 @@ TEST_F(LibYUVRotateTest, NV12Rotate270_Opt) { } TEST_F(LibYUVRotateTest, DISABLED_NV12Rotate0_Odd) { - NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_width_ - 3, benchmark_height_ - 1, kRotate0, + NV12TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_width_ + 1, benchmark_height_ + 1, kRotate0, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_NV12Rotate90_Odd) { - NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_height_ - 1, benchmark_width_ - 3, kRotate90, + NV12TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate90, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_NV12Rotate180_Odd) { - NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_width_ - 3, benchmark_height_ - 1, kRotate180, + NV12TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_width_ + 1, benchmark_height_ + 1, kRotate180, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } TEST_F(LibYUVRotateTest, DISABLED_NV12Rotate270_Odd) { - NV12TestRotate(benchmark_width_ - 3, benchmark_height_ - 1, - benchmark_height_ - 1, benchmark_width_ - 3, kRotate270, + NV12TestRotate(benchmark_width_ + 1, benchmark_height_ + 1, + benchmark_height_ + 1, benchmark_width_ + 1, kRotate270, benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); } @@ -391,4 +490,566 @@ TEST_F(LibYUVRotateTest, NV12Rotate270_Invert) { disable_cpu_flags_, benchmark_cpu_info_); } +// Test Android 420 to I420 Rotate +#define TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, \ + SRC_SUBSAMP_Y, FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, \ + W1280, N, NEG, OFF, PN, OFF_U, OFF_V, ROT) \ + TEST_F(LibYUVRotateTest, \ + SRC_FMT_PLANAR##To##FMT_PLANAR##Rotate##ROT##To##PN##N) { \ + const int kWidth = W1280; \ + const int kHeight = benchmark_height_; \ + const int kSizeUV = \ + SUBSAMPLE(kWidth, SRC_SUBSAMP_X) * SUBSAMPLE(kHeight, SRC_SUBSAMP_Y); \ + align_buffer_page_end(src_y, kWidth * kHeight + OFF); \ + align_buffer_page_end(src_uv, \ + kSizeUV * ((PIXEL_STRIDE == 3) ? 3 : 2) + OFF); \ + align_buffer_page_end(dst_y_c, kWidth * kHeight); \ + align_buffer_page_end(dst_u_c, SUBSAMPLE(kWidth, SUBSAMP_X) * \ + SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + align_buffer_page_end(dst_v_c, SUBSAMPLE(kWidth, SUBSAMP_X) * \ + SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + align_buffer_page_end(dst_y_opt, kWidth * kHeight); \ + align_buffer_page_end(dst_u_opt, SUBSAMPLE(kWidth, SUBSAMP_X) * \ + SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + align_buffer_page_end(dst_v_opt, SUBSAMPLE(kWidth, SUBSAMP_X) * \ + SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + uint8_t* src_u = src_uv + OFF_U; \ + uint8_t* src_v = src_uv + (PIXEL_STRIDE == 1 ? kSizeUV : OFF_V); \ + int src_stride_uv = SUBSAMPLE(kWidth, SUBSAMP_X) * PIXEL_STRIDE; \ + for (int i = 0; i < kHeight; ++i) \ + for (int j = 0; j < kWidth; ++j) \ + src_y[i * kWidth + j + OFF] = (fastrand() & 0xff); \ + for (int i = 0; i < SUBSAMPLE(kHeight, SRC_SUBSAMP_Y); ++i) { \ + for (int j = 0; j < SUBSAMPLE(kWidth, SRC_SUBSAMP_X); ++j) { \ + src_u[(i * src_stride_uv) + j * PIXEL_STRIDE + OFF] = \ + (fastrand() & 0xff); \ + src_v[(i * src_stride_uv) + j * PIXEL_STRIDE + OFF] = \ + (fastrand() & 0xff); \ + } \ + } \ + memset(dst_y_c, 1, kWidth * kHeight); \ + memset(dst_u_c, 2, \ + SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + memset(dst_v_c, 3, \ + SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + memset(dst_y_opt, 101, kWidth * kHeight); \ + memset(dst_u_opt, 102, \ + SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + memset(dst_v_opt, 103, \ + SUBSAMPLE(kWidth, SUBSAMP_X) * SUBSAMPLE(kHeight, SUBSAMP_Y)); \ + MaskCpuFlags(disable_cpu_flags_); \ + SRC_FMT_PLANAR##To##FMT_PLANAR##Rotate( \ + src_y + OFF, kWidth, src_u + OFF, SUBSAMPLE(kWidth, SRC_SUBSAMP_X), \ + src_v + OFF, SUBSAMPLE(kWidth, SRC_SUBSAMP_X), PIXEL_STRIDE, dst_y_c, \ + kWidth, dst_u_c, SUBSAMPLE(kWidth, SUBSAMP_X), dst_v_c, \ + SUBSAMPLE(kWidth, SUBSAMP_X), kWidth, NEG kHeight, \ + (libyuv::RotationMode)ROT); \ + MaskCpuFlags(benchmark_cpu_info_); \ + for (int i = 0; i < benchmark_iterations_; ++i) { \ + SRC_FMT_PLANAR##To##FMT_PLANAR##Rotate( \ + src_y + OFF, kWidth, src_u + OFF, SUBSAMPLE(kWidth, SRC_SUBSAMP_X), \ + src_v + OFF, SUBSAMPLE(kWidth, SRC_SUBSAMP_X), PIXEL_STRIDE, \ + dst_y_opt, kWidth, dst_u_opt, SUBSAMPLE(kWidth, SUBSAMP_X), \ + dst_v_opt, SUBSAMPLE(kWidth, SUBSAMP_X), kWidth, NEG kHeight, \ + (libyuv::RotationMode)ROT); \ + } \ + for (int i = 0; i < kHeight; ++i) { \ + for (int j = 0; j < kWidth; ++j) { \ + ASSERT_EQ(dst_y_c[i * kWidth + j], dst_y_opt[i * kWidth + j]); \ + } \ + } \ + for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ + for (int j = 0; j < SUBSAMPLE(kWidth, SUBSAMP_X); ++j) { \ + ASSERT_EQ(dst_u_c[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j], \ + dst_u_opt[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j]); \ + } \ + } \ + for (int i = 0; i < SUBSAMPLE(kHeight, SUBSAMP_Y); ++i) { \ + for (int j = 0; j < SUBSAMPLE(kWidth, SUBSAMP_X); ++j) { \ + ASSERT_EQ(dst_v_c[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j], \ + dst_v_opt[i * SUBSAMPLE(kWidth, SUBSAMP_X) + j]); \ + } \ + } \ + free_aligned_buffer_page_end(dst_y_c); \ + free_aligned_buffer_page_end(dst_u_c); \ + free_aligned_buffer_page_end(dst_v_c); \ + free_aligned_buffer_page_end(dst_y_opt); \ + free_aligned_buffer_page_end(dst_u_opt); \ + free_aligned_buffer_page_end(dst_v_opt); \ + free_aligned_buffer_page_end(src_y); \ + free_aligned_buffer_page_end(src_uv); \ + } + +#define TESTAPLANARTOP(SRC_FMT_PLANAR, PN, PIXEL_STRIDE, OFF_U, OFF_V, \ + SRC_SUBSAMP_X, SRC_SUBSAMP_Y, FMT_PLANAR, SUBSAMP_X, \ + SUBSAMP_Y) \ + TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, benchmark_width_ + 1, \ + _Any, +, 0, PN, OFF_U, OFF_V, 0) \ + TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, \ + _Unaligned, +, 2, PN, OFF_U, OFF_V, 0) \ + TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Invert, \ + -, 0, PN, OFF_U, OFF_V, 0) \ + TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Opt, +, \ + 0, PN, OFF_U, OFF_V, 0) \ + TESTAPLANARTOPI(SRC_FMT_PLANAR, PIXEL_STRIDE, SRC_SUBSAMP_X, SRC_SUBSAMP_Y, \ + FMT_PLANAR, SUBSAMP_X, SUBSAMP_Y, benchmark_width_, _Opt, +, \ + 0, PN, OFF_U, OFF_V, 180) + +TESTAPLANARTOP(Android420, I420, 1, 0, 0, 2, 2, I420, 2, 2) +TESTAPLANARTOP(Android420, NV12, 2, 0, 1, 2, 2, I420, 2, 2) +TESTAPLANARTOP(Android420, NV21, 2, 1, 0, 2, 2, I420, 2, 2) +#undef TESTAPLANARTOP +#undef TESTAPLANARTOPI + +static void I010TestRotate(int src_width, + int src_height, + int dst_width, + int dst_height, + libyuv::RotationMode mode, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (src_width < 1) { + src_width = 1; + } + if (src_height == 0) { + src_height = 1; + } + if (dst_width < 1) { + dst_width = 1; + } + if (dst_height < 1) { + dst_height = 1; + } + int src_i010_y_size = src_width * Abs(src_height); + int src_i010_uv_size = ((src_width + 1) / 2) * ((Abs(src_height) + 1) / 2); + int src_i010_size = src_i010_y_size + src_i010_uv_size * 2; + align_buffer_page_end_16(src_i010, src_i010_size); + for (int i = 0; i < src_i010_size; ++i) { + src_i010[i] = fastrand() & 0x3ff; + } + + int dst_i010_y_size = dst_width * dst_height; + int dst_i010_uv_size = ((dst_width + 1) / 2) * ((dst_height + 1) / 2); + int dst_i010_size = dst_i010_y_size + dst_i010_uv_size * 2; + align_buffer_page_end_16(dst_i010_c, dst_i010_size); + align_buffer_page_end_16(dst_i010_opt, dst_i010_size); + memset(dst_i010_c, 2, dst_i010_size * 2); + memset(dst_i010_opt, 3, dst_i010_size * 2); + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + I010Rotate(src_i010, src_width, src_i010 + src_i010_y_size, + (src_width + 1) / 2, src_i010 + src_i010_y_size + src_i010_uv_size, + (src_width + 1) / 2, dst_i010_c, dst_width, + dst_i010_c + dst_i010_y_size, (dst_width + 1) / 2, + dst_i010_c + dst_i010_y_size + dst_i010_uv_size, + (dst_width + 1) / 2, src_width, src_height, mode); + + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + for (int i = 0; i < benchmark_iterations; ++i) { + I010Rotate( + src_i010, src_width, src_i010 + src_i010_y_size, (src_width + 1) / 2, + src_i010 + src_i010_y_size + src_i010_uv_size, (src_width + 1) / 2, + dst_i010_opt, dst_width, dst_i010_opt + dst_i010_y_size, + (dst_width + 1) / 2, dst_i010_opt + dst_i010_y_size + dst_i010_uv_size, + (dst_width + 1) / 2, src_width, src_height, mode); + } + + // Rotation should be exact. + for (int i = 0; i < dst_i010_size; ++i) { + ASSERT_EQ(dst_i010_c[i], dst_i010_opt[i]); + } + + free_aligned_buffer_page_end_16(dst_i010_c); + free_aligned_buffer_page_end_16(dst_i010_opt); + free_aligned_buffer_page_end_16(src_i010); +} + +TEST_F(LibYUVRotateTest, I010Rotate0_Opt) { + I010TestRotate(benchmark_width_, benchmark_height_, benchmark_width_, + benchmark_height_, kRotate0, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I010Rotate90_Opt) { + I010TestRotate(benchmark_width_, benchmark_height_, benchmark_height_, + benchmark_width_, kRotate90, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I010Rotate180_Opt) { + I010TestRotate(benchmark_width_, benchmark_height_, benchmark_width_, + benchmark_height_, kRotate180, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I010Rotate270_Opt) { + I010TestRotate(benchmark_width_, benchmark_height_, benchmark_height_, + benchmark_width_, kRotate270, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +static void I210TestRotate(int src_width, + int src_height, + int dst_width, + int dst_height, + libyuv::RotationMode mode, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (src_width < 1) { + src_width = 1; + } + if (src_height == 0) { + src_height = 1; + } + if (dst_width < 1) { + dst_width = 1; + } + if (dst_height < 1) { + dst_height = 1; + } + int src_i210_y_size = src_width * Abs(src_height); + int src_i210_uv_size = ((src_width + 1) / 2) * Abs(src_height); + int src_i210_size = src_i210_y_size + src_i210_uv_size * 2; + align_buffer_page_end_16(src_i210, src_i210_size); + for (int i = 0; i < src_i210_size; ++i) { + src_i210[i] = fastrand() & 0x3ff; + } + + int dst_i210_y_size = dst_width * dst_height; + int dst_i210_uv_size = ((dst_width + 1) / 2) * dst_height; + int dst_i210_size = dst_i210_y_size + dst_i210_uv_size * 2; + align_buffer_page_end_16(dst_i210_c, dst_i210_size); + align_buffer_page_end_16(dst_i210_opt, dst_i210_size); + memset(dst_i210_c, 2, dst_i210_size * 2); + memset(dst_i210_opt, 3, dst_i210_size * 2); + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + I210Rotate(src_i210, src_width, src_i210 + src_i210_y_size, + (src_width + 1) / 2, src_i210 + src_i210_y_size + src_i210_uv_size, + (src_width + 1) / 2, dst_i210_c, dst_width, + dst_i210_c + dst_i210_y_size, (dst_width + 1) / 2, + dst_i210_c + dst_i210_y_size + dst_i210_uv_size, + (dst_width + 1) / 2, src_width, src_height, mode); + + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + for (int i = 0; i < benchmark_iterations; ++i) { + I210Rotate( + src_i210, src_width, src_i210 + src_i210_y_size, (src_width + 1) / 2, + src_i210 + src_i210_y_size + src_i210_uv_size, (src_width + 1) / 2, + dst_i210_opt, dst_width, dst_i210_opt + dst_i210_y_size, + (dst_width + 1) / 2, dst_i210_opt + dst_i210_y_size + dst_i210_uv_size, + (dst_width + 1) / 2, src_width, src_height, mode); + } + + // Rotation should be exact. + for (int i = 0; i < dst_i210_size; ++i) { + ASSERT_EQ(dst_i210_c[i], dst_i210_opt[i]); + } + + free_aligned_buffer_page_end_16(dst_i210_c); + free_aligned_buffer_page_end_16(dst_i210_opt); + free_aligned_buffer_page_end_16(src_i210); +} + +TEST_F(LibYUVRotateTest, I210Rotate0_Opt) { + I210TestRotate(benchmark_width_, benchmark_height_, benchmark_width_, + benchmark_height_, kRotate0, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I210Rotate90_Opt) { + I210TestRotate(benchmark_width_, benchmark_height_, benchmark_height_, + benchmark_width_, kRotate90, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I210Rotate180_Opt) { + I210TestRotate(benchmark_width_, benchmark_height_, benchmark_width_, + benchmark_height_, kRotate180, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I210Rotate270_Opt) { + I210TestRotate(benchmark_width_, benchmark_height_, benchmark_height_, + benchmark_width_, kRotate270, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +static void I410TestRotate(int src_width, + int src_height, + int dst_width, + int dst_height, + libyuv::RotationMode mode, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (src_width < 1) { + src_width = 1; + } + if (src_height == 0) { + src_height = 1; + } + if (dst_width < 1) { + dst_width = 1; + } + if (dst_height < 1) { + dst_height = 1; + } + int src_i410_y_size = src_width * Abs(src_height); + int src_i410_uv_size = src_width * Abs(src_height); + int src_i410_size = src_i410_y_size + src_i410_uv_size * 2; + align_buffer_page_end_16(src_i410, src_i410_size); + for (int i = 0; i < src_i410_size; ++i) { + src_i410[i] = fastrand() & 0x3ff; + } + + int dst_i410_y_size = dst_width * dst_height; + int dst_i410_uv_size = dst_width * dst_height; + int dst_i410_size = dst_i410_y_size + dst_i410_uv_size * 2; + align_buffer_page_end_16(dst_i410_c, dst_i410_size); + align_buffer_page_end_16(dst_i410_opt, dst_i410_size); + memset(dst_i410_c, 2, dst_i410_size * 2); + memset(dst_i410_opt, 3, dst_i410_size * 2); + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + I410Rotate(src_i410, src_width, src_i410 + src_i410_y_size, src_width, + src_i410 + src_i410_y_size + src_i410_uv_size, src_width, + dst_i410_c, dst_width, dst_i410_c + dst_i410_y_size, dst_width, + dst_i410_c + dst_i410_y_size + dst_i410_uv_size, dst_width, + src_width, src_height, mode); + + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + for (int i = 0; i < benchmark_iterations; ++i) { + I410Rotate(src_i410, src_width, src_i410 + src_i410_y_size, src_width, + src_i410 + src_i410_y_size + src_i410_uv_size, src_width, + dst_i410_opt, dst_width, dst_i410_opt + dst_i410_y_size, + dst_width, dst_i410_opt + dst_i410_y_size + dst_i410_uv_size, + dst_width, src_width, src_height, mode); + } + + // Rotation should be exact. + for (int i = 0; i < dst_i410_size; ++i) { + ASSERT_EQ(dst_i410_c[i], dst_i410_opt[i]); + } + + free_aligned_buffer_page_end_16(dst_i410_c); + free_aligned_buffer_page_end_16(dst_i410_opt); + free_aligned_buffer_page_end_16(src_i410); +} + +TEST_F(LibYUVRotateTest, I410Rotate0_Opt) { + I410TestRotate(benchmark_width_, benchmark_height_, benchmark_width_, + benchmark_height_, kRotate0, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I410Rotate90_Opt) { + I410TestRotate(benchmark_width_, benchmark_height_, benchmark_height_, + benchmark_width_, kRotate90, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I410Rotate180_Opt) { + I410TestRotate(benchmark_width_, benchmark_height_, benchmark_width_, + benchmark_height_, kRotate180, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +TEST_F(LibYUVRotateTest, I410Rotate270_Opt) { + I410TestRotate(benchmark_width_, benchmark_height_, benchmark_height_, + benchmark_width_, kRotate270, benchmark_iterations_, + disable_cpu_flags_, benchmark_cpu_info_); +} + +#if defined(ENABLE_ROW_TESTS) + +TEST_F(LibYUVRotateTest, TransposeWx4_32_Test) { + // dst width and height + const int width = 4; + const int height = 4; + int src_pixels[4][4]; + int dst_pixels_c[4][4]; + int dst_pixels_opt[4][4]; + + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + src_pixels[i][j] = i * 10 + j; + } + } + memset(dst_pixels_c, 1, width * height * 4); + memset(dst_pixels_opt, 2, width * height * 4); + + TransposeWx4_32_C((const uint8_t*)src_pixels, height * 4, + (uint8_t*)dst_pixels_c, width * 4, width); + + const int benchmark_iterations = + (benchmark_iterations_ * benchmark_width_ * benchmark_height_ + 15) / + (4 * 4); + for (int i = 0; i < benchmark_iterations; ++i) { +#if defined(HAS_TRANSPOSEWX4_32_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + TransposeWx4_32_NEON((const uint8_t*)src_pixels, height * 4, + (uint8_t*)dst_pixels_opt, width * 4, width); + } else +#elif defined(HAS_TRANSPOSEWX4_32_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + TransposeWx4_32_AVX2((const uint8_t*)src_pixels, height * 4, + (uint8_t*)dst_pixels_opt, width * 4, width); + } else +#endif + { + TransposeWx4_32_C((const uint8_t*)src_pixels, height * 4, + (uint8_t*)dst_pixels_opt, width * 4, width); + } + } + + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + ASSERT_EQ(dst_pixels_c[i][j], src_pixels[j][i]); + ASSERT_EQ(dst_pixels_c[i][j], dst_pixels_opt[i][j]); + } + } +} + +TEST_F(LibYUVRotateTest, TransposeWx4_32_Opt) { + // dst width and height + const int width = ((benchmark_width_ * benchmark_height_ + 3) / 4 + 3) & ~3; + const int height = 4; + align_buffer_page_end(src_pixels, height * width * 4); + align_buffer_page_end(dst_pixels_c, width * height * 4); + align_buffer_page_end(dst_pixels_opt, width * height * 4); + + MemRandomize(src_pixels, height * width * 4); + memset(dst_pixels_c, 1, width * height * 4); + memset(dst_pixels_opt, 2, width * height * 4); + + TransposeWx4_32_C((const uint8_t*)src_pixels, height * 4, + (uint8_t*)dst_pixels_c, width * 4, width); + + for (int i = 0; i < benchmark_iterations_; ++i) { +#if defined(HAS_TRANSPOSEWX4_32_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + TransposeWx4_32_NEON((const uint8_t*)src_pixels, height * 4, + (uint8_t*)dst_pixels_opt, width * 4, width); + } else +#elif defined(HAS_TRANSPOSEWX4_32_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + TransposeWx4_32_AVX2((const uint8_t*)src_pixels, height * 4, + (uint8_t*)dst_pixels_opt, width * 4, width); + } else +#endif + { + TransposeWx4_32_C((const uint8_t*)src_pixels, height * 4, + (uint8_t*)dst_pixels_opt, width * 4, width); + } + } + + for (int i = 0; i < width * height; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(dst_pixels_c); + free_aligned_buffer_page_end(dst_pixels_opt); +} + +TEST_F(LibYUVRotateTest, TransposeWx4_32_Any) { + for (int width : {4, 8, 12, 16, 20, 28, 36}) { + const int height = 4; + align_buffer_page_end(src_pixels, height * width * 4); + align_buffer_page_end(dst_pixels_c, width * height * 4); + align_buffer_page_end(dst_pixels_opt, width * height * 4); + + MemRandomize(src_pixels, height * width * 4); + memset(dst_pixels_c, 1, width * height * 4); + memset(dst_pixels_opt, 2, width * height * 4); + + TransposeWx4_32_C(src_pixels, height * 4, dst_pixels_c, width * 4, width); +#if defined(HAS_TRANSPOSEWX4_32_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + if ((width & 7) == 0) { + TransposeWx4_32_AVX2(src_pixels, height * 4, dst_pixels_opt, width * 4, + width); + } else { + TransposeWx4_32_Any_AVX2(src_pixels, height * 4, dst_pixels_opt, + width * 4, width); + } + } else +#endif +#if defined(HAS_TRANSPOSEWX4_32_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + TransposeWx4_32_NEON(src_pixels, height * 4, dst_pixels_opt, width * 4, + width); + } else +#endif + { + TransposeWx4_32_C(src_pixels, height * 4, dst_pixels_opt, width * 4, + width); + } + + ASSERT_EQ(0, memcmp(dst_pixels_c, dst_pixels_opt, width * height * 4)) + << "width=" << width; + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(dst_pixels_c); + free_aligned_buffer_page_end(dst_pixels_opt); + } +} + +#if defined(HAS_TRANSPOSEWXH_32_AVX2) +TEST_F(LibYUVRotateTest, TransposeWxH_32_Test) { + if (!TestCpuFlag(kCpuHasAVX2)) { + return; + } + const int kMaxW = 35; + const int kMaxH = 25; + align_buffer_page_end(src_pixels, kMaxW * kMaxH * 4); + align_buffer_page_end(dst_pixels_c, kMaxW * kMaxH * 4); + align_buffer_page_end(dst_pixels_opt, kMaxW * kMaxH * 4); + MemRandomize(src_pixels, kMaxW * kMaxH * 4); + + for (int h = 1; h <= kMaxH; ++h) { + for (int w = 1; w <= kMaxW; ++w) { + const int src_stride = w * 4; + const int dst_stride = h * 4; + const int src_bytes = src_stride * h; + const int dst_bytes = dst_stride * w; + const uint8_t* src = src_pixels + kMaxW * kMaxH * 4 - src_bytes; + uint8_t* dst_c = dst_pixels_c + kMaxW * kMaxH * 4 - dst_bytes; + uint8_t* dst_opt = dst_pixels_opt + kMaxW * kMaxH * 4 - dst_bytes; + + memset(dst_c, 1, dst_bytes); + memset(dst_opt, 2, dst_bytes); + TransposeWxH_32_C(src, src_stride, dst_c, dst_stride, w, h); + TransposeWxH_32_AVX2(src, src_stride, dst_opt, dst_stride, w, h); + ASSERT_EQ(0, memcmp(dst_c, dst_opt, dst_bytes)) << w << "x" << h; + + // Also test negative src_stride (90-degree) and negative dst_stride + // (270-degree). + memset(dst_c, 3, dst_bytes); + memset(dst_opt, 4, dst_bytes); + TransposeWxH_32_C(src + (ptrdiff_t)(h - 1) * src_stride, -src_stride, + dst_c + (ptrdiff_t)(w - 1) * dst_stride, -dst_stride, w, + h); + TransposeWxH_32_AVX2(src + (ptrdiff_t)(h - 1) * src_stride, -src_stride, + dst_opt + (ptrdiff_t)(w - 1) * dst_stride, + -dst_stride, w, h); + ASSERT_EQ(0, memcmp(dst_c, dst_opt, dst_bytes)) << "neg " << w << "x" << h; + } + } + + free_aligned_buffer_page_end(src_pixels); + free_aligned_buffer_page_end(dst_pixels_c); + free_aligned_buffer_page_end(dst_pixels_opt); +} +#endif // defined(HAS_TRANSPOSEWXH_32_AVX2) + +#endif // ENABLE_ROW_TESTS + } // namespace libyuv diff --git a/libs/libyuv/unit_test/scale_argb_test.cc b/libs/libyuv/unit_test/scale_argb_test.cc index 93b77f56a9..532bcb5097 100644 --- a/libs/libyuv/unit_test/scale_argb_test.cc +++ b/libs/libyuv/unit_test/scale_argb_test.cc @@ -22,6 +22,12 @@ namespace libyuv { #define STRINGIZE(line) #line #define FILELINESTR(file, line) file ":" STRINGIZE(line) +#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) +// SLOW TESTS are those that are unoptimized C code. +// FULL TESTS are optimized but test many variations of the same code. +#define ENABLE_FULL_TESTS +#endif + // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. static int ARGBTestFilter(int src_width, int src_height, @@ -114,8 +120,8 @@ static int ARGBTestFilter(int src_width, return max_diff; } -static const int kTileX = 8; -static const int kTileY = 8; +static const int kTileX = 64; +static const int kTileY = 64; static int TileARGBScale(const uint8_t* src_argb, int src_stride_argb, @@ -232,34 +238,49 @@ static int ARGBClipTestFilter(int src_width, #define DX(x, nom, denom) static_cast((Abs(x) / nom) * nom) #define SX(x, nom, denom) static_cast((x / nom) * denom) -#define TEST_FACTOR1(name, filter, nom, denom, max_diff) \ +#define TEST_FACTOR1(DISABLED_, name, filter, nom, denom, max_diff) \ TEST_F(LibYUVScaleTest, ARGBScaleDownBy##name##_##filter) { \ int diff = ARGBTestFilter( \ SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } \ - TEST_F(LibYUVScaleTest, ARGBScaleDownClipBy##name##_##filter) { \ + TEST_F(LibYUVScaleTest, DISABLED_##ARGBScaleDownClipBy##name##_##filter) { \ int diff = ARGBClipTestFilter( \ SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ kFilter##filter, benchmark_iterations_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } // Test a scale factor with all 4 filters. Expect unfiltered to be exact, but // filtering is different fixed point implementations for SSSE3, Neon and C. -#define TEST_FACTOR(name, nom, denom) \ - TEST_FACTOR1(name, None, nom, denom, 0) \ - TEST_FACTOR1(name, Linear, nom, denom, 3) \ - TEST_FACTOR1(name, Bilinear, nom, denom, 3) \ - TEST_FACTOR1(name, Box, nom, denom, 3) +#ifndef DISABLE_SLOW_TESTS +#define TEST_FACTOR(name, nom, denom) \ + TEST_FACTOR1(, name, None, nom, denom, 0) \ + TEST_FACTOR1(, name, Linear, nom, denom, 3) \ + TEST_FACTOR1(, name, Bilinear, nom, denom, 3) \ + TEST_FACTOR1(, name, Box, nom, denom, 3) +#else +#if defined(ENABLE_FULL_TESTS) +#define TEST_FACTOR(name, nom, denom) \ + TEST_FACTOR1(DISABLED_, name, None, nom, denom, 0) \ + TEST_FACTOR1(DISABLED_, name, Linear, nom, denom, 3) \ + TEST_FACTOR1(DISABLED_, name, Bilinear, nom, denom, 3) \ + TEST_FACTOR1(DISABLED_, name, Box, nom, denom, 3) +#else +#define TEST_FACTOR(name, nom, denom) \ + TEST_FACTOR1(DISABLED_, name, Bilinear, nom, denom, 3) +#endif +#endif TEST_FACTOR(2, 1, 2) TEST_FACTOR(4, 1, 4) -// TEST_FACTOR(8, 1, 8) Disable for benchmark performance. +#ifndef DISABLE_SLOW_TESTS +TEST_FACTOR(8, 1, 8) +#endif TEST_FACTOR(3by4, 3, 4) TEST_FACTOR(3by8, 3, 8) TEST_FACTOR(3, 1, 3) @@ -268,70 +289,108 @@ TEST_FACTOR(3, 1, 3) #undef SX #undef DX -#define TEST_SCALETO1(name, width, height, filter, max_diff) \ +#define TEST_SCALETO1(DISABLED_, name, width, height, filter, max_diff) \ TEST_F(LibYUVScaleTest, name##To##width##x##height##_##filter) { \ int diff = ARGBTestFilter(benchmark_width_, benchmark_height_, width, \ height, kFilter##filter, benchmark_iterations_, \ disable_cpu_flags_, benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } \ TEST_F(LibYUVScaleTest, name##From##width##x##height##_##filter) { \ int diff = ARGBTestFilter(width, height, Abs(benchmark_width_), \ Abs(benchmark_height_), kFilter##filter, \ benchmark_iterations_, disable_cpu_flags_, \ benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } \ - TEST_F(LibYUVScaleTest, name##ClipTo##width##x##height##_##filter) { \ + TEST_F(LibYUVScaleTest, \ + DISABLED_##name##ClipTo##width##x##height##_##filter) { \ int diff = \ ARGBClipTestFilter(benchmark_width_, benchmark_height_, width, height, \ kFilter##filter, benchmark_iterations_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } \ - TEST_F(LibYUVScaleTest, name##ClipFrom##width##x##height##_##filter) { \ + TEST_F(LibYUVScaleTest, \ + DISABLED_##name##ClipFrom##width##x##height##_##filter) { \ int diff = ARGBClipTestFilter(width, height, Abs(benchmark_width_), \ Abs(benchmark_height_), kFilter##filter, \ benchmark_iterations_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } -/// Test scale to a specified size with all 4 filters. -#define TEST_SCALETO(name, width, height) \ - TEST_SCALETO1(name, width, height, None, 0) \ - TEST_SCALETO1(name, width, height, Linear, 3) \ - TEST_SCALETO1(name, width, height, Bilinear, 3) +#ifndef DISABLE_SLOW_TESTS +// Test scale to a specified size with all 4 filters. +#define TEST_SCALETO(name, width, height) \ + TEST_SCALETO1(, name, width, height, None, 0) \ + TEST_SCALETO1(, name, width, height, Linear, 3) \ + TEST_SCALETO1(, name, width, height, Bilinear, 3) \ + TEST_SCALETO1(, name, width, height, Box, 3) +#else +#if defined(ENABLE_FULL_TESTS) +#define TEST_SCALETO(name, width, height) \ + TEST_SCALETO1(DISABLED_, name, width, height, None, 0) \ + TEST_SCALETO1(DISABLED_, name, width, height, Linear, 3) \ + TEST_SCALETO1(DISABLED_, name, width, height, Bilinear, 3) \ + TEST_SCALETO1(DISABLED_, name, width, height, Box, 3) +#else +#define TEST_SCALETO(name, width, height) \ + TEST_SCALETO1(DISABLED_, name, width, height, Bilinear, 3) +#endif +#endif TEST_SCALETO(ARGBScale, 1, 1) -TEST_SCALETO(ARGBScale, 320, 240) TEST_SCALETO(ARGBScale, 569, 480) TEST_SCALETO(ARGBScale, 640, 360) +#ifndef DISABLE_SLOW_TESTS +TEST_SCALETO(ARGBScale, 50, 1) +TEST_SCALETO(ARGBScale, 256, 144) /* 128x72 * 2 */ +TEST_SCALETO(ARGBScale, 320, 240) TEST_SCALETO(ARGBScale, 1280, 720) TEST_SCALETO(ARGBScale, 1920, 1080) +#endif // DISABLE_SLOW_TESTS #undef TEST_SCALETO1 #undef TEST_SCALETO +#define TEST_SCALESWAPXY1(name, filter, max_diff) \ + TEST_F(LibYUVScaleTest, name##SwapXY_##filter) { \ + int diff = ARGBTestFilter(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } + +#if defined(ENABLE_FULL_TESTS) +// Test scale with swapped width and height with all 3 filters. +TEST_SCALESWAPXY1(ARGBScale, None, 0) +TEST_SCALESWAPXY1(ARGBScale, Linear, 0) +TEST_SCALESWAPXY1(ARGBScale, Bilinear, 0) +#else +TEST_SCALESWAPXY1(ARGBScale, Bilinear, 0) +#endif +#undef TEST_SCALESWAPXY1 + // Scale with YUV conversion to ARGB and clipping. // TODO(fbarchard): Add fourcc support. All 4 ARGB formats is easy to support. -LIBYUV_API -int YUVToARGBScaleReference2(const uint8_t* src_y, - int src_stride_y, - const uint8_t* src_u, - int src_stride_u, - const uint8_t* src_v, - int src_stride_v, - uint32_t /* src_fourcc */, - int src_width, - int src_height, - uint8_t* dst_argb, - int dst_stride_argb, - uint32_t /* dst_fourcc */, - int dst_width, - int dst_height, - int clip_x, - int clip_y, - int clip_width, - int clip_height, - enum FilterMode filtering) { +static int YUVToARGBScaleReference2(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_u, + int src_stride_u, + const uint8_t* src_v, + int src_stride_v, + uint32_t /* src_fourcc */, + int src_width, + int src_height, + uint8_t* dst_argb, + int dst_stride_argb, + uint32_t /* dst_fourcc */, + int dst_width, + int dst_height, + int clip_x, + int clip_y, + int clip_width, + int clip_height, + enum FilterMode filtering) { uint8_t* argb_buffer = static_cast(malloc(src_width * src_height * 4)); int r; @@ -371,12 +430,14 @@ static void FillRamp(uint8_t* buf, } // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. -static int YUVToARGBTestFilter(int src_width, - int src_height, - int dst_width, - int dst_height, - FilterMode f, - int benchmark_iterations) { +static void YUVToARGBTestFilter(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int error_threshold, + int* max_diff_out) { int64_t src_y_plane_size = Abs(src_width) * Abs(src_height); int64_t src_uv_plane_size = ((Abs(src_width) + 1) / 2) * ((Abs(src_height) + 1) / 2); @@ -387,13 +448,13 @@ static int YUVToARGBTestFilter(int src_width, align_buffer_page_end(src_u, src_uv_plane_size); align_buffer_page_end(src_v, src_uv_plane_size); - int64_t dst_argb_plane_size = (dst_width) * (dst_height)*4LL; - int dst_stride_argb = (dst_width)*4; + int64_t dst_argb_plane_size = (dst_width) * (dst_height) * 4LL; + int dst_stride_argb = (dst_width) * 4; align_buffer_page_end(dst_argb_c, dst_argb_plane_size); align_buffer_page_end(dst_argb_opt, dst_argb_plane_size); if (!dst_argb_c || !dst_argb_opt || !src_y || !src_u || !src_v) { printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); - return 0; + return; } // Fill YUV image with continuous ramp, which is less sensitive to // subsampling and filtering differences for test purposes. @@ -422,36 +483,199 @@ static int YUVToARGBTestFilter(int src_width, int abs_diff = Abs(dst_argb_c[(i * dst_stride_argb) + j] - dst_argb_opt[(i * dst_stride_argb) + j]); if (abs_diff > max_diff) { - printf("error %d at %d,%d c %d opt %d", abs_diff, j, i, + max_diff = abs_diff; + } + if (abs_diff > error_threshold) { + printf("error %d at %d,%d c %d opt %d\n", abs_diff, j, i, dst_argb_c[(i * dst_stride_argb) + j], dst_argb_opt[(i * dst_stride_argb) + j]); - EXPECT_LE(abs_diff, 40); - max_diff = abs_diff; + goto cleanup; } } } +cleanup: + if (max_diff_out) { + *max_diff_out = max_diff; + } free_aligned_buffer_page_end(dst_argb_c); free_aligned_buffer_page_end(dst_argb_opt); free_aligned_buffer_page_end(src_y); free_aligned_buffer_page_end(src_u); free_aligned_buffer_page_end(src_v); - return max_diff; } TEST_F(LibYUVScaleTest, YUVToRGBScaleUp) { - int diff = - YUVToARGBTestFilter(benchmark_width_, benchmark_height_, - benchmark_width_ * 3 / 2, benchmark_height_ * 3 / 2, - libyuv::kFilterBilinear, benchmark_iterations_); - EXPECT_LE(diff, 10); + int diff = 0; + YUVToARGBTestFilter(benchmark_width_, benchmark_height_, + benchmark_width_ * 3 / 2, benchmark_height_ * 3 / 2, + libyuv::kFilterBilinear, benchmark_iterations_, 10, + &diff); + ASSERT_LE(diff, 10); } TEST_F(LibYUVScaleTest, YUVToRGBScaleDown) { - int diff = YUVToARGBTestFilter( - benchmark_width_ * 3 / 2, benchmark_height_ * 3 / 2, benchmark_width_, - benchmark_height_, libyuv::kFilterBilinear, benchmark_iterations_); - EXPECT_LE(diff, 10); + int diff = 0; + YUVToARGBTestFilter(benchmark_width_ * 3 / 2, benchmark_height_ * 3 / 2, + benchmark_width_, benchmark_height_, + libyuv::kFilterBilinear, benchmark_iterations_, 10, + &diff); + ASSERT_LE(diff, 10); } +TEST_F(LibYUVScaleTest, ARGBTest3x) { + const int kSrcStride = 480 * 4; + const int kDstStride = 160 * 4; + const int kSize = kSrcStride * 3; + align_buffer_page_end(orig_pixels, kSize); + for (int i = 0; i < 480 * 3; ++i) { + orig_pixels[i * 4 + 0] = i; + orig_pixels[i * 4 + 1] = 255 - i; + orig_pixels[i * 4 + 2] = i + 1; + orig_pixels[i * 4 + 3] = i + 10; + } + align_buffer_page_end(dest_pixels, kDstStride); + + int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 * + benchmark_iterations_; + for (int i = 0; i < iterations160; ++i) { + ARGBScale(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1, + kFilterBilinear); + } + + ASSERT_EQ(225, dest_pixels[0]); + ASSERT_EQ(255 - 225, dest_pixels[1]); + ASSERT_EQ(226, dest_pixels[2]); + ASSERT_EQ(235, dest_pixels[3]); + + ARGBScale(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1, + kFilterNone); + + ASSERT_EQ(225, dest_pixels[0]); + ASSERT_EQ(255 - 225, dest_pixels[1]); + ASSERT_EQ(226, dest_pixels[2]); + ASSERT_EQ(235, dest_pixels[3]); + + free_aligned_buffer_page_end(dest_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +TEST_F(LibYUVScaleTest, ARGBTest4x) { + const int kSrcStride = 640 * 4; + const int kDstStride = 160 * 4; + const int kSize = kSrcStride * 4; + align_buffer_page_end(orig_pixels, kSize); + for (int i = 0; i < 640 * 4; ++i) { + orig_pixels[i * 4 + 0] = i; + orig_pixels[i * 4 + 1] = 255 - i; + orig_pixels[i * 4 + 2] = i + 1; + orig_pixels[i * 4 + 3] = i + 10; + } + align_buffer_page_end(dest_pixels, kDstStride); + + int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 * + benchmark_iterations_; + for (int i = 0; i < iterations160; ++i) { + ARGBScale(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1, + kFilterBilinear); + } + + ASSERT_NEAR(66, dest_pixels[0], 4); + ASSERT_NEAR(255 - 66, dest_pixels[1], 4); + ASSERT_NEAR(67, dest_pixels[2], 4); + ASSERT_NEAR(76, dest_pixels[3], 4); + + ARGBScale(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1, + kFilterNone); + + ASSERT_EQ(2, dest_pixels[0]); + ASSERT_EQ(255 - 2, dest_pixels[1]); + ASSERT_EQ(3, dest_pixels[2]); + ASSERT_EQ(12, dest_pixels[3]); + + free_aligned_buffer_page_end(dest_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +TEST_F(LibYUVScaleTest, ARGBScale_LargeHeightOverflow) { + const int src_w = 4; + const int src_h = 32767; + align_buffer_page_end(orig_pixels, src_w * src_h * 4); + align_buffer_page_end(dest_pixels, src_w * 2 * 4); + memset(orig_pixels, 128, src_w * src_h * 4); + + // Test both vertical-only scaling (dst_w == src_w) and 2D scaling (dst_w != + // src_w). + for (int dst_w : {4, 2}) { + int res = ARGBScale(orig_pixels, src_w * 4, src_w, src_h, dest_pixels, + dst_w * 4, dst_w, 2, kFilterBilinear); + EXPECT_EQ(0, res); + + res = ARGBScale(orig_pixels, src_w * 4, src_w, -src_h, dest_pixels, + dst_w * 4, dst_w, 2, kFilterBilinear); + EXPECT_EQ(0, res); + + res = ARGBScale(orig_pixels, src_w * 4, src_w, src_h, dest_pixels, + dst_w * 4, dst_w, 2, kFilterLinear); + EXPECT_EQ(0, res); + + res = ARGBScale(orig_pixels, src_w * 4, src_w, -src_h, dest_pixels, + dst_w * 4, dst_w, 2, kFilterLinear); + EXPECT_EQ(0, res); + + res = ARGBScale(orig_pixels, src_w * 4, src_w, src_h, dest_pixels, + dst_w * 4, dst_w, 2, kFilterNone); + EXPECT_EQ(0, res); + + res = ARGBScale(orig_pixels, src_w * 4, src_w, -src_h, dest_pixels, + dst_w * 4, dst_w, 2, kFilterNone); + EXPECT_EQ(0, res); + } + + free_aligned_buffer_page_end(dest_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +TEST_F(LibYUVScaleTest, ARGBScaleDimensionOverflow) { + uint8_t src[16] = {}; + uint8_t dst[4] = {}; + EXPECT_EQ(-1, ARGBScale(src, 4, 32769, 1, dst, 4, 1, 1, kFilterNone)); + EXPECT_EQ(-1, ARGBScale(src, 4, -32769, 1, dst, 4, 1, 1, kFilterNone)); + EXPECT_EQ(-1, ARGBScale(src, 4, 1, 32769, dst, 4, 1, 1, kFilterNone)); + EXPECT_EQ(-1, ARGBScale(src, 4, 1, -32769, dst, 4, 1, 1, kFilterNone)); + EXPECT_EQ(-1, ARGBScaleClip(src, 4, 32769, 1, dst, 4, 1, 1, 0, 0, 1, 1, + kFilterNone)); + EXPECT_EQ(-1, ARGBScaleClip(src, 4, -32769, 1, dst, 4, 1, 1, 0, 0, 1, 1, + kFilterNone)); + EXPECT_EQ(-1, ARGBScaleClip(src, 4, 1, 32769, dst, 4, 1, 1, 0, 0, 1, 1, + kFilterNone)); + EXPECT_EQ(-1, ARGBScaleClip(src, 4, 1, -32769, dst, 4, 1, 1, 0, 0, 1, 1, + kFilterNone)); +} + +#if defined(__LP64__) || defined(_WIN64) +TEST_F(LibYUVScaleTest, ARGBScaleLargeImageOver2GB) { + const int kSrcWidth = 4; + const int kSrcHeight = 32768; + const int kSrcStride = 131072; // 32768 * 131072 = 4 GB (> INT_MAX) + const size_t kSrcSize = (size_t)kSrcStride * kSrcHeight; + uint8_t* src = static_cast(calloc(1, kSrcSize)); + if (!src) { + GTEST_SKIP() << "could not allocate " << kSrcSize << " bytes"; + } + uint8_t dst[8 * 4 * 4] = {}; + + for (int dst_w : {4, 2}) { + for (FilterMode f : + {kFilterNone, kFilterLinear, kFilterBilinear, kFilterBox}) { + EXPECT_EQ(0, ARGBScale(src, kSrcStride, kSrcWidth, kSrcHeight, dst, + dst_w * 4, dst_w, 2, f)); + EXPECT_EQ(0, ARGBScale(src, kSrcStride, kSrcWidth, -kSrcHeight, dst, + dst_w * 4, dst_w, 2, f)); + } + } + free(src); +} +#endif + } // namespace libyuv diff --git a/libs/libyuv/unit_test/scale_plane_test.cc b/libs/libyuv/unit_test/scale_plane_test.cc new file mode 100644 index 0000000000..012377d5cd --- /dev/null +++ b/libs/libyuv/unit_test/scale_plane_test.cc @@ -0,0 +1,919 @@ +/* + * Copyright 2023 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include +#include +#include + +#include + +#include "../unit_test/unit_test.h" +#include "libyuv/cpu_id.h" +#include "libyuv/scale.h" +#include "libyuv/scale_uv.h" + +#ifdef ENABLE_ROW_TESTS +#include "libyuv/scale_row.h" // For ScaleRowDown2Box_Odd_C +#endif + +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) +#include +#define MSAN_POISON(ptr, size) __msan_allocated_memory(ptr, size) +#endif +#endif +#ifndef MSAN_POISON +#define MSAN_POISON(ptr, size) +#endif + +#define STRINGIZE(line) #line +#define FILELINESTR(file, line) file ":" STRINGIZE(line) + +#if (defined(__riscv) && !defined(__clang__)) || defined(__hexagon__) +#define DISABLE_SLOW_TESTS +#undef ENABLE_FULL_TESTS +#undef ENABLE_ROW_TESTS +#define LEAN_TESTS +#endif + +#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) +// SLOW TESTS are those that are unoptimized C code. +// FULL TESTS are optimized but test many variations of the same code. +#define ENABLE_FULL_TESTS +#endif + +namespace libyuv { + +// POC: int row_stride = src_stride * 2 overflows to a small negative value +// when src_stride is close to INT_MAX, causing src_ptr to walk backward +// past the start of the source allocation on the second loop iteration. +// With src_stride = 0x7FFFFFFE, row_stride = (int)0xFFFFFFFC = -4, so on +// y=1 ScaleRowDown2Box reads 4 bytes before the heap allocation. +TEST_F(LibYUVScaleTest, ScalePlaneDown2_RowStrideOverflow) { + constexpr int kSrcStride = 0x7FFFFFFE; // INT_MAX - 1 + constexpr int kSrcW = 64; + constexpr int kSrcH = 4; + constexpr int kDstW = 32; + constexpr int kDstH = 2; + // src_size = (kSrcH - 1) * stride + width. + size_t src_size = kSrcH - 1; + if (src_size > SIZE_MAX / kSrcStride) { + GTEST_SKIP() << "could not represent allocation size in size_t"; + } + src_size *= kSrcStride; + if (src_size > SIZE_MAX - kSrcW) { + GTEST_SKIP() << "could not represent allocation size in size_t"; + } + src_size += kSrcW; + +#if defined(__aarch64__) + // Infer malloc can accept a large size for cpu with dot product (a76/a55) + int has_large_malloc = TestCpuFlag(kCpuHasNeonDotProd); +#else + int has_large_malloc = 1; +#endif + if (!has_large_malloc) { + GTEST_SKIP() << "large allocation may assert for " << src_size << " bytes"; + } + + uint8_t* src = new (std::nothrow) uint8_t[src_size]; + if (!src) { + GTEST_SKIP() << "could not allocate " << src_size << " bytes"; + } + uint8_t dst[kDstW * kDstH]; + uint8_t* src_row = src; + for (int i = 0; i < kSrcH; i++) { + memset(src_row, 0x41, kSrcW); + src_row += kSrcStride; + } + // Force the C row kernel: the SIMD kernels are inline asm that ASAN does not + // instrument, so they silently read OOB without a report. + MaskCpuFlags(1); + // 2*dst == src on both axes -> ScalePlane dispatches to ScalePlaneDown2. + // int row_stride = kSrcStride * 2 wraps to -4; on y=1 src_ptr underflows. + ScalePlane(src, kSrcStride, kSrcW, kSrcH, dst, kDstW, kDstW, kDstH, + kFilterBox); + MaskCpuFlags(0); + delete[] src; +} + +// POC: same defect in the 1/4 fast path. src_stride = 0x3FFFFFFF gives +// int row_stride = src_stride * 4 = (int)0xFFFFFFFC = -4. +TEST_F(LibYUVScaleTest, ScalePlaneDown4_RowStrideOverflow) { + constexpr int kSrcStride = 0x3FFFFFFF; // INT_MAX / 4 (rounded down) + constexpr int kSrcW = 64; + constexpr int kSrcH = 8; + constexpr int kDstW = 16; + constexpr int kDstH = 2; + // src_size = (kSrcH - 1) * stride + width. + size_t src_size = kSrcH - 1; + if (src_size > SIZE_MAX / kSrcStride) { + GTEST_SKIP() << "could not represent allocation size in size_t"; + } + src_size *= kSrcStride; + if (src_size > SIZE_MAX - kSrcW) { + GTEST_SKIP() << "could not represent allocation size in size_t"; + } + src_size += kSrcW; + +#if defined(__aarch64__) + // Infer malloc can accept a large size for cpu with dot product (a76/a55) + int has_large_malloc = TestCpuFlag(kCpuHasNeonDotProd); +#else + int has_large_malloc = 1; +#endif + if (!has_large_malloc) { + GTEST_SKIP() << "large allocation may assert for " << src_size << " bytes"; + } + + uint8_t* src = new (std::nothrow) uint8_t[src_size]; + if (!src) { + GTEST_SKIP() << "could not allocate " << src_size << " bytes"; + } + uint8_t dst[kDstW * kDstH]; + uint8_t* src_row = src; + for (int i = 0; i < kSrcH; i++) { + memset(src_row, 0x41, kSrcW); + src_row += kSrcStride; + } + // Force the C row kernel: the SIMD kernels are inline asm that ASAN does not + // instrument, so they silently read OOB without a report. + MaskCpuFlags(1); + // 4*dst == src on both axes with kFilterBox -> ScalePlaneDown4. + ScalePlane(src, kSrcStride, kSrcW, kSrcH, dst, kDstW, kDstW, kDstH, + kFilterBox); + MaskCpuFlags(0); + delete[] src; +} + +#ifdef ENABLE_ROW_TESTS +#ifdef HAS_SCALEROWDOWN2_SSSE3 +TEST_F(LibYUVScaleTest, TestScaleRowDown2Box_Odd_SSSE3) { + SIMD_ALIGNED(uint8_t orig_pixels[128 * 2]); + SIMD_ALIGNED(uint8_t dst_pixels_opt[64]); + SIMD_ALIGNED(uint8_t dst_pixels_c[64]); + memset(orig_pixels, 0, sizeof(orig_pixels)); + memset(dst_pixels_opt, 0, sizeof(dst_pixels_opt)); + memset(dst_pixels_c, 0, sizeof(dst_pixels_c)); + + int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); + if (!has_ssse3) { + printf("Warning SSSE3 not detected; Skipping test.\n"); + } else { + // TL. + orig_pixels[0] = 255u; + orig_pixels[1] = 0u; + orig_pixels[128 + 0] = 0u; + orig_pixels[128 + 1] = 0u; + // TR. + orig_pixels[2] = 0u; + orig_pixels[3] = 100u; + orig_pixels[128 + 2] = 0u; + orig_pixels[128 + 3] = 0u; + // BL. + orig_pixels[4] = 0u; + orig_pixels[5] = 0u; + orig_pixels[128 + 4] = 50u; + orig_pixels[128 + 5] = 0u; + // BR. + orig_pixels[6] = 0u; + orig_pixels[7] = 0u; + orig_pixels[128 + 6] = 0u; + orig_pixels[128 + 7] = 20u; + // Odd. + orig_pixels[126] = 4u; + orig_pixels[127] = 255u; + orig_pixels[128 + 126] = 16u; + orig_pixels[128 + 127] = 255u; + + // Test regular half size. + ScaleRowDown2Box_C(orig_pixels, 128, dst_pixels_c, 64); + + ASSERT_EQ(64u, dst_pixels_c[0]); + ASSERT_EQ(25u, dst_pixels_c[1]); + ASSERT_EQ(13u, dst_pixels_c[2]); + ASSERT_EQ(5u, dst_pixels_c[3]); + ASSERT_EQ(0u, dst_pixels_c[4]); + ASSERT_EQ(133u, dst_pixels_c[63]); + + // Test Odd width version - Last pixel is just 1 horizontal pixel. + ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 64); + + ASSERT_EQ(64u, dst_pixels_c[0]); + ASSERT_EQ(25u, dst_pixels_c[1]); + ASSERT_EQ(13u, dst_pixels_c[2]); + ASSERT_EQ(5u, dst_pixels_c[3]); + ASSERT_EQ(0u, dst_pixels_c[4]); + ASSERT_EQ(10u, dst_pixels_c[63]); + + // Test one pixel less, should skip the last pixel. + memset(dst_pixels_c, 0, sizeof(dst_pixels_c)); + ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 63); + + ASSERT_EQ(64u, dst_pixels_c[0]); + ASSERT_EQ(25u, dst_pixels_c[1]); + ASSERT_EQ(13u, dst_pixels_c[2]); + ASSERT_EQ(5u, dst_pixels_c[3]); + ASSERT_EQ(0u, dst_pixels_c[4]); + ASSERT_EQ(0u, dst_pixels_c[63]); + + // Test regular half size SSSE3. + ScaleRowDown2Box_SSSE3(orig_pixels, 128, dst_pixels_opt, 64); + + ASSERT_EQ(64u, dst_pixels_opt[0]); + ASSERT_EQ(25u, dst_pixels_opt[1]); + ASSERT_EQ(13u, dst_pixels_opt[2]); + ASSERT_EQ(5u, dst_pixels_opt[3]); + ASSERT_EQ(0u, dst_pixels_opt[4]); + ASSERT_EQ(133u, dst_pixels_opt[63]); + + // Compare C and SSSE3 match. + ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 64); + ScaleRowDown2Box_Odd_SSSE3(orig_pixels, 128, dst_pixels_opt, 64); + for (int i = 0; i < 64; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + } +} +#endif // HAS_SCALEROWDOWN2_SSSE3 + +TEST_F(LibYUVScaleTest, TestScaleRowDown2Box_16) { + SIMD_ALIGNED(uint16_t orig_pixels[2560 * 2]); + SIMD_ALIGNED(uint16_t dst_pixels_c[1280]); + SIMD_ALIGNED(uint16_t dst_pixels_opt[1280]); + + memset(orig_pixels, 0, sizeof(orig_pixels)); + memset(dst_pixels_c, 1, sizeof(dst_pixels_c)); + memset(dst_pixels_opt, 2, sizeof(dst_pixels_opt)); + + for (int i = 0; i < 2560 * 2; ++i) { + orig_pixels[i] = i; + } + ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_c[0], 1280); + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { +#if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) + int has_neon = TestCpuFlag(kCpuHasNEON); + if (has_neon) { + ScaleRowDown2Box_16_NEON(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280); + } else { + ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280); + } +#elif defined(HAS_SCALEROWDOWN2_16_AVX2) + int has_avx2 = TestCpuFlag(kCpuHasAVX2); + if (has_avx2) { + ScaleRowDown2Box_16_AVX2(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280); + } else { + ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280); + } +#else + ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280); +#endif + } + + for (int i = 0; i < 1280; ++i) { + ASSERT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); + } + + ASSERT_EQ(dst_pixels_c[0], (0 + 1 + 2560 + 2561 + 2) / 4); + ASSERT_EQ(dst_pixels_c[1279], 3839); +} +#endif // ENABLE_ROW_TESTS + +// Test scaling plane with 8 bit C vs 12 bit C and return maximum pixel +// difference. +// 0 = exact. +static int TestPlaneFilter_16(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (!SizeValid(src_width, src_height, dst_width, dst_height)) { + return 0; + } + + int i; + int64_t src_y_plane_size = (Abs(src_width)) * (Abs(src_height)); + int src_stride_y = Abs(src_width); + int dst_y_plane_size = dst_width * dst_height; + int dst_stride_y = dst_width; + + align_buffer_page_end(src_y, src_y_plane_size); + align_buffer_page_end(src_y_16, src_y_plane_size * 2); + align_buffer_page_end(dst_y_8, dst_y_plane_size); + align_buffer_page_end(dst_y_16, dst_y_plane_size * 2); + uint16_t* p_src_y_16 = reinterpret_cast(src_y_16); + uint16_t* p_dst_y_16 = reinterpret_cast(dst_y_16); + + MemRandomize(src_y, src_y_plane_size); + memset(dst_y_8, 0, dst_y_plane_size); + memset(dst_y_16, 1, dst_y_plane_size * 2); + + for (i = 0; i < src_y_plane_size; ++i) { + p_src_y_16[i] = src_y[i] & 255; + } + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y_8, dst_stride_y, + dst_width, dst_height, f); + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + + for (i = 0; i < benchmark_iterations; ++i) { + ScalePlane_16(p_src_y_16, src_stride_y, src_width, src_height, p_dst_y_16, + dst_stride_y, dst_width, dst_height, f); + } + + // Expect an exact match. + int max_diff = 0; + for (i = 0; i < dst_y_plane_size; ++i) { + int abs_diff = Abs(dst_y_8[i] - p_dst_y_16[i]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + + free_aligned_buffer_page_end(dst_y_8); + free_aligned_buffer_page_end(dst_y_16); + free_aligned_buffer_page_end(src_y); + free_aligned_buffer_page_end(src_y_16); + + return max_diff; +} + +// The following adjustments in dimensions ensure the scale factor will be +// exactly achieved. +// 2 is chroma subsample. +#define DX(x, nom, denom) static_cast(((Abs(x) / nom + 1) / 2) * nom * 2) +#define SX(x, nom, denom) static_cast(((x / nom + 1) / 2) * denom * 2) + +#define TEST_FACTOR1(name, filter, nom, denom, max_diff) \ + TEST_F(LibYUVScaleTest, DISABLED_##ScalePlaneDownBy##name##_##filter##_16) { \ + int diff = TestPlaneFilter_16( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } + +// Test a scale factor with all 4 filters. Expect unfiltered to be exact, but +// filtering is different fixed point implementations for SSSE3, Neon and C. +#define TEST_FACTOR(name, nom, denom, boxdiff) \ + TEST_FACTOR1(name, None, nom, denom, 0) \ + TEST_FACTOR1(name, Linear, nom, denom, boxdiff) \ + TEST_FACTOR1(name, Bilinear, nom, denom, boxdiff) \ + TEST_FACTOR1(name, Box, nom, denom, boxdiff) + +TEST_FACTOR(2, 1, 2, 0) +TEST_FACTOR(4, 1, 4, 0) +// TEST_FACTOR(8, 1, 8, 0) Disable for benchmark performance. Takes 90 seconds. +TEST_FACTOR(3by4, 3, 4, 1) +TEST_FACTOR(3by8, 3, 8, 1) +TEST_FACTOR(3, 1, 3, 0) +#undef TEST_FACTOR1 +#undef TEST_FACTOR +#undef SX +#undef DX + +TEST_F(LibYUVScaleTest, PlaneTest3x) { + const int kSrcStride = 480; + const int kDstStride = 160; + const int kSize = kSrcStride * 3; + align_buffer_page_end(orig_pixels, kSize); + for (int i = 0; i < 480 * 3; ++i) { + orig_pixels[i] = i; + } + align_buffer_page_end(dest_pixels, kDstStride); + + int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 * + benchmark_iterations_; + for (int i = 0; i < iterations160; ++i) { + ScalePlane(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1, + kFilterBilinear); + } + + ASSERT_EQ(225, dest_pixels[0]); + + ScalePlane(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1, + kFilterNone); + + ASSERT_EQ(225, dest_pixels[0]); + + free_aligned_buffer_page_end(dest_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +TEST_F(LibYUVScaleTest, PlaneTest4x) { + const int kSrcStride = 640; + const int kDstStride = 160; + const int kSize = kSrcStride * 4; + align_buffer_page_end(orig_pixels, kSize); + for (int i = 0; i < 640 * 4; ++i) { + orig_pixels[i] = i; + } + align_buffer_page_end(dest_pixels, kDstStride); + + int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 * + benchmark_iterations_; + for (int i = 0; i < iterations160; ++i) { + ScalePlane(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1, + kFilterBilinear); + } + + ASSERT_EQ(66, dest_pixels[0]); + + ScalePlane(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1, + kFilterNone); + + ASSERT_EQ(2, dest_pixels[0]); // expect the 3rd pixel of the 3rd row + + free_aligned_buffer_page_end(dest_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +// Intent is to test 200x50 to 50x200 but width and height can be parameters. +TEST_F(LibYUVScaleTest, PlaneTestRotate_None) { + const int kSize = benchmark_width_ * benchmark_height_; + align_buffer_page_end(orig_pixels, kSize); + for (int i = 0; i < kSize; ++i) { + orig_pixels[i] = i; + } + align_buffer_page_end(dest_opt_pixels, kSize); + align_buffer_page_end(dest_c_pixels, kSize); + + MaskCpuFlags(disable_cpu_flags_); // Disable all CPU optimization. + ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, benchmark_height_, + dest_c_pixels, benchmark_height_, benchmark_height_, + benchmark_width_, kFilterNone); + MaskCpuFlags(benchmark_cpu_info_); // Enable all CPU optimization. + + for (int i = 0; i < benchmark_iterations_; ++i) { + ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, + benchmark_height_, dest_opt_pixels, benchmark_height_, + benchmark_height_, benchmark_width_, kFilterNone); + } + + for (int i = 0; i < kSize; ++i) { + ASSERT_EQ(dest_c_pixels[i], dest_opt_pixels[i]); + } + + free_aligned_buffer_page_end(dest_c_pixels); + free_aligned_buffer_page_end(dest_opt_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +TEST_F(LibYUVScaleTest, PlaneTestRotate_Bilinear) { + const int kSize = benchmark_width_ * benchmark_height_; + align_buffer_page_end(orig_pixels, kSize); + for (int i = 0; i < kSize; ++i) { + orig_pixels[i] = i; + } + align_buffer_page_end(dest_opt_pixels, kSize); + align_buffer_page_end(dest_c_pixels, kSize); + + MaskCpuFlags(disable_cpu_flags_); // Disable all CPU optimization. + ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, benchmark_height_, + dest_c_pixels, benchmark_height_, benchmark_height_, + benchmark_width_, kFilterBilinear); + MaskCpuFlags(benchmark_cpu_info_); // Enable all CPU optimization. + + for (int i = 0; i < benchmark_iterations_; ++i) { + ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, + benchmark_height_, dest_opt_pixels, benchmark_height_, + benchmark_height_, benchmark_width_, kFilterBilinear); + } + + for (int i = 0; i < kSize; ++i) { + ASSERT_EQ(dest_c_pixels[i], dest_opt_pixels[i]); + } + + free_aligned_buffer_page_end(dest_c_pixels); + free_aligned_buffer_page_end(dest_opt_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +// Intent is to test 200x50 to 50x200 but width and height can be parameters. +TEST_F(LibYUVScaleTest, PlaneTestRotate_Box) { + const int kSize = benchmark_width_ * benchmark_height_; + align_buffer_page_end(orig_pixels, kSize); + for (int i = 0; i < kSize; ++i) { + orig_pixels[i] = i; + } + align_buffer_page_end(dest_opt_pixels, kSize); + align_buffer_page_end(dest_c_pixels, kSize); + + MaskCpuFlags(disable_cpu_flags_); // Disable all CPU optimization. + ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, benchmark_height_, + dest_c_pixels, benchmark_height_, benchmark_height_, + benchmark_width_, kFilterBox); + MaskCpuFlags(benchmark_cpu_info_); // Enable all CPU optimization. + + for (int i = 0; i < benchmark_iterations_; ++i) { + ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, + benchmark_height_, dest_opt_pixels, benchmark_height_, + benchmark_height_, benchmark_width_, kFilterBox); + } + + for (int i = 0; i < kSize; ++i) { + ASSERT_EQ(dest_c_pixels[i], dest_opt_pixels[i]); + } + + free_aligned_buffer_page_end(dest_c_pixels); + free_aligned_buffer_page_end(dest_opt_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +TEST_F(LibYUVScaleTest, ScalePlaneBox_Any) { + const int kDstW = 29; + const int kDstH = 3; + const int kSrcH = 9; + for (int src_w : {87, 174, 73, 155}) { + const int kSrcSize = src_w * kSrcH; + const int kDstSize = kDstW * kDstH; + align_buffer_page_end(src_pixels, kSrcSize); + align_buffer_page_end(dst_c_pixels, kDstSize); + align_buffer_page_end(dst_opt_pixels, kDstSize); + MemRandomize(src_pixels, kSrcSize); + MSAN_POISON(dst_opt_pixels, kDstSize); + + MaskCpuFlags(disable_cpu_flags_); + ScalePlane(src_pixels, src_w, src_w, kSrcH, dst_c_pixels, kDstW, kDstW, + kDstH, kFilterBox); + MaskCpuFlags(benchmark_cpu_info_); + ScalePlane(src_pixels, src_w, src_w, kSrcH, dst_opt_pixels, kDstW, kDstW, + kDstH, kFilterBox); + + for (int i = 0; i < kDstSize; ++i) { + ASSERT_EQ(dst_c_pixels[i], dst_opt_pixels[i]); + } + free_aligned_buffer_page_end(dst_opt_pixels); + free_aligned_buffer_page_end(dst_c_pixels); + free_aligned_buffer_page_end(src_pixels); + } +} + +TEST_F(LibYUVScaleTest, PlaneTest1_Box) { + align_buffer_page_end(orig_pixels, 3); + align_buffer_page_end(dst_pixels, 3); + + // Pad the 1x1 byte image with invalid values before and after in case libyuv + // reads outside the memory boundaries. + orig_pixels[0] = 0; + orig_pixels[1] = 1; // scale this pixel + orig_pixels[2] = 2; + dst_pixels[0] = 3; + dst_pixels[1] = 3; + dst_pixels[2] = 3; + + libyuv::ScalePlane(orig_pixels + 1, /* src_stride= */ 1, /* src_width= */ 1, + /* src_height= */ 1, dst_pixels, /* dst_stride= */ 1, + /* dst_width= */ 1, /* dst_height= */ 2, + libyuv::kFilterBox); + + ASSERT_EQ(dst_pixels[0], 1); + ASSERT_EQ(dst_pixels[1], 1); + ASSERT_EQ(dst_pixels[2], 3); + + free_aligned_buffer_page_end(dst_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +TEST_F(LibYUVScaleTest, PlaneTest1_16_Box) { + align_buffer_page_end(orig_pixels_alloc, 3 * 2); + align_buffer_page_end(dst_pixels_alloc, 3 * 2); + uint16_t* orig_pixels = (uint16_t*)orig_pixels_alloc; + uint16_t* dst_pixels = (uint16_t*)dst_pixels_alloc; + + // Pad the 1x1 byte image with invalid values before and after in case libyuv + // reads outside the memory boundaries. + orig_pixels[0] = 0; + orig_pixels[1] = 1; // scale this pixel + orig_pixels[2] = 2; + dst_pixels[0] = 3; + dst_pixels[1] = 3; + dst_pixels[2] = 3; + + libyuv::ScalePlane_16( + orig_pixels + 1, /* src_stride= */ 1, /* src_width= */ 1, + /* src_height= */ 1, dst_pixels, /* dst_stride= */ 1, + /* dst_width= */ 1, /* dst_height= */ 2, libyuv::kFilterNone); + + ASSERT_EQ(dst_pixels[0], 1); + ASSERT_EQ(dst_pixels[1], 1); + ASSERT_EQ(dst_pixels[2], 3); + + free_aligned_buffer_page_end(dst_pixels_alloc); + free_aligned_buffer_page_end(orig_pixels_alloc); +} + +TEST_F(LibYUVScaleTest, ScalePlaneVerticalPointUp) { + const int kWidth = 32; + const uint8_t kSentinel = 0xFF; + const uint8_t expected[] = {10, 10, 20, 30, 30}; + + // An extra sentinel row exposes accidental interpolation past the last valid + // row. 3->5 is the uneven ratio that used to drop the last source row. + align_buffer_page_end(src, kWidth * 4); + align_buffer_page_end(dst, kWidth * 5); + memset(src, kSentinel, kWidth * 4); + memset(dst, kSentinel, kWidth * 5); + memset(src, 10, kWidth); + memset(src + kWidth, 20, kWidth); + memset(src + 2 * kWidth, 30, kWidth); + + ASSERT_EQ(0, ScalePlane(src, kWidth, kWidth, 3, dst, kWidth, kWidth, 5, + kFilterNone)); + for (int y = 0; y < 5; ++y) { + for (int x = 0; x < kWidth; ++x) { + EXPECT_EQ(expected[y], dst[y * kWidth + x]); + } + } + + free_aligned_buffer_page_end(dst); + free_aligned_buffer_page_end(src); +} + +TEST_F(LibYUVScaleTest, ScalePlaneVerticalPointUp_16) { + const int kWidth = 32; + const uint16_t kSentinel = 0xFFFF; + const uint16_t expected[] = {10, 10, 20, 30, 30}; + + align_buffer_page_end(src_alloc, kWidth * 4 * 2); + align_buffer_page_end(dst_alloc, kWidth * 5 * 2); + uint16_t* src = reinterpret_cast(src_alloc); + uint16_t* dst = reinterpret_cast(dst_alloc); + for (int i = 0; i < kWidth * 4; ++i) { + src[i] = kSentinel; + } + for (int i = 0; i < kWidth * 5; ++i) { + dst[i] = kSentinel; + } + for (int x = 0; x < kWidth; ++x) { + src[x] = 10; + src[kWidth + x] = 20; + src[2 * kWidth + x] = 30; + } + + ASSERT_EQ(0, ScalePlane_16(src, kWidth, kWidth, 3, dst, kWidth, kWidth, 5, + kFilterNone)); + for (int y = 0; y < 5; ++y) { + for (int x = 0; x < kWidth; ++x) { + EXPECT_EQ(expected[y], dst[y * kWidth + x]); + } + } + + free_aligned_buffer_page_end(dst_alloc); + free_aligned_buffer_page_end(src_alloc); +} + +TEST_F(LibYUVScaleTest, ScalePlaneVerticalBilinearUp) { + const int kWidth = 32; + const uint8_t kSentinel = 0xFF; + // Same-width 2x upsampling still uses FixedDiv1. With y = 0 the 8.8 + // fractions are 0, 85, 170, 255. InterpolateRow_C: + // (a * (256 - yf) + b * yf + 128) >> 8. + // Nearest 2x would duplicate rows as {10, 10, 200, 200}. + const uint8_t expected[] = {10, 73, 136, 199}; + + align_buffer_page_end(src, kWidth * 3); + align_buffer_page_end(dst, kWidth * 4); + memset(src, kSentinel, kWidth * 3); + memset(dst, kSentinel, kWidth * 4); + memset(src, 10, kWidth); + memset(src + kWidth, 200, kWidth); + + ASSERT_EQ(0, ScalePlane(src, kWidth, kWidth, 2, dst, kWidth, kWidth, 4, + kFilterBilinear)); + for (int y = 0; y < 4; ++y) { + for (int x = 0; x < kWidth; ++x) { + EXPECT_EQ(expected[y], dst[y * kWidth + x]); + } + } + + free_aligned_buffer_page_end(dst); + free_aligned_buffer_page_end(src); +} + +TEST_F(LibYUVScaleTest, ScalePlaneVerticalBilinearUp_16) { + const int kWidth = 32; + const uint16_t kSentinel = 0xFFFF; + const uint16_t expected[] = {10, 73, 136, 199}; + + align_buffer_page_end(src_alloc, kWidth * 3 * 2); + align_buffer_page_end(dst_alloc, kWidth * 4 * 2); + uint16_t* src = reinterpret_cast(src_alloc); + uint16_t* dst = reinterpret_cast(dst_alloc); + for (int i = 0; i < kWidth * 3; ++i) { + src[i] = kSentinel; + } + for (int i = 0; i < kWidth * 4; ++i) { + dst[i] = kSentinel; + } + for (int x = 0; x < kWidth; ++x) { + src[x] = 10; + src[kWidth + x] = 200; + } + + ASSERT_EQ(0, ScalePlane_16(src, kWidth, kWidth, 2, dst, kWidth, kWidth, 4, + kFilterBilinear)); + for (int y = 0; y < 4; ++y) { + for (int x = 0; x < kWidth; ++x) { + EXPECT_EQ(expected[y], dst[y * kWidth + x]); + } + } + + free_aligned_buffer_page_end(dst_alloc); + free_aligned_buffer_page_end(src_alloc); +} + +// POC: int * int overflow in ScalePlaneVertical (scale_common.cc). +// +// `yi * src_stride` is evaluated as int * int. When the product exceeds +// INT_MAX it wraps negative and InterpolateRow reads from BEFORE the +// source allocation. +// +// Parameters: +// - dst_width == src_width +// -> ScalePlane dispatches to ScalePlaneVertical +// - src_height == 5, dst_height == 1 +// -> single iteration with yi == 2 +// - src_stride == 0x7FFFFFF8 +// -> 2 * 0x7FFFFFF8 == 0xFFFFFFF0 == -16 (int) +// +// The source buffer is sized so that the *correct* 64-bit offset +// (2 * 0x7FFFFFF8 == 4294967280) plus kWidth bytes is in-bounds. With the +// bug, the 32-bit product is -16 and ASAN reports a heap-buffer-overflow +// READ "16 bytes before" the allocation. +TEST_F(LibYUVScaleTest, ScalePlaneVertical_IntStrideOverflow) { + const int kWidth = 16; + const int kSrcHeight = 5; + const int kDstHeight = 1; + const int kStride = 0x7FFFFFF8; // 2147483640 + + // src_size is big enough for the only row this call legitimately touches + // (yi == 2) when computed in 64-bit: 2 * stride + width = 4 GiB. + size_t src_size = kStride; + if (src_size > SIZE_MAX / 2) { + GTEST_SKIP() << "could not represent allocation size in size_t"; + } + src_size *= 2; + if (src_size > SIZE_MAX - kWidth) { + GTEST_SKIP() << "could not represent allocation size in size_t"; + } + src_size += kWidth; + +#if defined(__aarch64__) + // Infer malloc can accept a large size for cpu with dot product (a76/a55) + int has_large_malloc = TestCpuFlag(kCpuHasNeonDotProd); +#else + int has_large_malloc = 1; +#endif + if (!has_large_malloc) { + GTEST_SKIP() << "large allocation may assert for " << src_size << " bytes"; + } + + uint8_t* src = new (std::nothrow) uint8_t[src_size]; + if (!src) { + GTEST_SKIP() << "could not allocate " << src_size << " bytes"; + } + uint8_t* dst = new uint8_t[kWidth]; + memset(dst, 0, kWidth); + + // Force the scalar path so the crash site is deterministic + // (InterpolateRow_C -> memcpy when yf == 0). + MaskCpuFlags(disable_cpu_flags_); + + int r = ScalePlane(src, kStride, kWidth, kSrcHeight, dst, kWidth, kWidth, + kDstHeight, kFilterNone); + + // Not reached under ASAN. + ASSERT_EQ(0, r); + delete[] src; + delete[] dst; +} + +TEST_F(LibYUVScaleTest, ScalePlane_InvalidInputs) { + uint8_t src[16] = {0}; + uint8_t dst[16] = {0}; + + // NULL src/dst + EXPECT_EQ(-1, ScalePlane(nullptr, 4, 4, 4, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane(src, 4, 4, 4, nullptr, 4, 4, 4, kFilterNone)); + + // Width/height <= 0 (except src_height which can be negative but not 0) + EXPECT_EQ(-1, ScalePlane(src, 4, 0, 4, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane(src, 4, -1, 4, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane(src, 4, 4, 0, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane(src, 4, 4, 4, dst, 4, 0, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane(src, 4, 4, 4, dst, 4, -1, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane(src, 4, 4, 4, dst, 4, 4, 0, kFilterNone)); + EXPECT_EQ(-1, ScalePlane(src, 4, 4, 4, dst, 4, 4, -1, kFilterNone)); + + // Width/height too large (> 32768) + EXPECT_EQ(-1, ScalePlane(src, 4, 32769, 4, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane(src, 4, 4, 32769, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane(src, 4, 4, -32769, dst, 4, 4, 4, kFilterNone)); + + // Valid edge cases + EXPECT_EQ(0, ScalePlane(src, 4, 1, 1, dst, 4, 1, 1, kFilterNone)); + EXPECT_EQ(0, ScalePlane(src, 4, 1, -1, dst, 4, 1, 1, kFilterNone)); +} + +TEST_F(LibYUVScaleTest, ScalePlane_16_InvalidInputs) { + uint16_t src[16] = {0}; + uint16_t dst[16] = {0}; + + EXPECT_EQ(-1, ScalePlane_16(nullptr, 4, 4, 4, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane_16(src, 4, 4, 4, nullptr, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane_16(src, 4, 0, 4, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane_16(src, 4, 32769, 4, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane_16(src, 4, 4, -32769, dst, 4, 4, 4, kFilterNone)); +} + +TEST_F(LibYUVScaleTest, ScalePlane_12_InvalidInputs) { + uint16_t src[16] = {0}; + uint16_t dst[16] = {0}; + + EXPECT_EQ(-1, ScalePlane_12(nullptr, 4, 4, 4, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane_12(src, 4, 4, 4, nullptr, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane_12(src, 4, 0, 4, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane_12(src, 4, 32769, 4, dst, 4, 4, 4, kFilterNone)); + EXPECT_EQ(-1, ScalePlane_12(src, 4, 4, -32769, dst, 4, 4, 4, kFilterNone)); +} + +TEST_F(LibYUVScaleTest, ScalePlaneOversizeHeight) { + const int kSrcWidth = 4; + const int kSrcHeight = 32768; + uint8_t* src = new uint8_t[kSrcWidth * kSrcHeight]; + memset(src, 0, kSrcWidth * kSrcHeight); + uint8_t dst[4 * 2] = {}; + + for (int dst_w : {4, 2}) { + for (int dst_h : {1, 2}) { + for (FilterMode f : + {kFilterNone, kFilterLinear, kFilterBilinear, kFilterBox}) { + EXPECT_EQ(0, ScalePlane(src, kSrcWidth, kSrcWidth, kSrcHeight, dst, + dst_w, dst_w, dst_h, f)); + EXPECT_EQ(0, ScalePlane(src, kSrcWidth, kSrcWidth, -kSrcHeight, dst, + dst_w, dst_w, dst_h, f)); + } + } + } + delete[] src; +} + +TEST_F(LibYUVScaleTest, ScalePlaneBoxMaxSrcHeight) { + const int kSrcWidth = 4; + const int kSrcHeight = 32768; + uint8_t* src = new uint8_t[kSrcWidth * kSrcHeight]; + memset(src, 0, kSrcWidth * kSrcHeight); + uint8_t dst[2 * 4] = {}; + + EXPECT_EQ(0, ScalePlane(src, kSrcWidth, kSrcWidth, kSrcHeight, dst, 2, 2, 4, + kFilterBox)); + delete[] src; +} + +#if defined(__LP64__) || defined(_WIN64) +TEST_F(LibYUVScaleTest, ScaleLargeImageOver2GB) { + const int kSrcWidth = 4; + const int kSrcHeight = 32768; + const int kSrcStride = 131072; // 32768 * 131072 = 4 GB (> INT_MAX) + const size_t kSrcSize = (size_t)kSrcStride * kSrcHeight; + uint8_t* src = static_cast(calloc(1, kSrcSize)); + if (!src) { + GTEST_SKIP() << "could not allocate " << kSrcSize << " bytes"; + } + uint8_t dst[8 * 4 * 4] = {}; + + for (FilterMode f : + {kFilterNone, kFilterLinear, kFilterBilinear, kFilterBox}) { + EXPECT_EQ( + 0, ScalePlane(src, kSrcStride, kSrcWidth, kSrcHeight, dst, 4, 4, 2, f)); + EXPECT_EQ(0, ScalePlane(src, kSrcStride, kSrcWidth, -kSrcHeight, dst, 4, 4, + 2, f)); + EXPECT_EQ( + 0, ScalePlane(src, kSrcStride, kSrcWidth, kSrcHeight, dst, 8, 8, 2, f)); + EXPECT_EQ(0, UVScale(src, kSrcStride, kSrcWidth, kSrcHeight, dst, 4 * 2, 4, + 2, f)); + EXPECT_EQ(0, UVScale(src, kSrcStride, kSrcWidth, -kSrcHeight, dst, 4 * 2, 4, + 2, f)); + EXPECT_EQ(0, UVScale(src, kSrcStride, kSrcWidth, kSrcHeight, dst, 8 * 2, 8, + 2, f)); + } + free(src); +} +#endif + +} // namespace libyuv diff --git a/libs/libyuv/unit_test/scale_rgb_test.cc b/libs/libyuv/unit_test/scale_rgb_test.cc new file mode 100644 index 0000000000..f6fa1e8caa --- /dev/null +++ b/libs/libyuv/unit_test/scale_rgb_test.cc @@ -0,0 +1,280 @@ +/* + * Copyright 2022 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "../unit_test/unit_test.h" +#include "libyuv/cpu_id.h" +#include "libyuv/scale_rgb.h" + +namespace libyuv { + +#define STRINGIZE(line) #line +#define FILELINESTR(file, line) file ":" STRINGIZE(line) + +#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) +// SLOW TESTS are those that are unoptimized C code. +// FULL TESTS are optimized but test many variations of the same code. +#define ENABLE_FULL_TESTS +#endif + +// Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. +static int RGBTestFilter(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (!SizeValid(src_width, src_height, dst_width, dst_height)) { + return 0; + } + + int i, j; + const int b = 0; // 128 to test for padding/stride. + int64_t src_rgb_plane_size = + (Abs(src_width) + b * 3) * (Abs(src_height) + b * 3) * 3LL; + int src_stride_rgb = (b * 3 + Abs(src_width)) * 3; + + align_buffer_page_end(src_rgb, src_rgb_plane_size); + if (!src_rgb) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + MemRandomize(src_rgb, src_rgb_plane_size); + + int64_t dst_rgb_plane_size = (dst_width + b * 3) * (dst_height + b * 3) * 3LL; + int dst_stride_rgb = (b * 3 + dst_width) * 3; + + align_buffer_page_end(dst_rgb_c, dst_rgb_plane_size); + align_buffer_page_end(dst_rgb_opt, dst_rgb_plane_size); + if (!dst_rgb_c || !dst_rgb_opt) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + memset(dst_rgb_c, 2, dst_rgb_plane_size); + memset(dst_rgb_opt, 3, dst_rgb_plane_size); + + // Warm up both versions for consistent benchmarks. + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + RGBScale(src_rgb + (src_stride_rgb * b) + b * 3, src_stride_rgb, src_width, + src_height, dst_rgb_c + (dst_stride_rgb * b) + b * 3, dst_stride_rgb, + dst_width, dst_height, f); + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + RGBScale(src_rgb + (src_stride_rgb * b) + b * 3, src_stride_rgb, src_width, + src_height, dst_rgb_opt + (dst_stride_rgb * b) + b * 3, + dst_stride_rgb, dst_width, dst_height, f); + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + double c_time = get_time(); + RGBScale(src_rgb + (src_stride_rgb * b) + b * 3, src_stride_rgb, src_width, + src_height, dst_rgb_c + (dst_stride_rgb * b) + b * 3, dst_stride_rgb, + dst_width, dst_height, f); + + c_time = (get_time() - c_time); + + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + double opt_time = get_time(); + for (i = 0; i < benchmark_iterations; ++i) { + RGBScale(src_rgb + (src_stride_rgb * b) + b * 3, src_stride_rgb, src_width, + src_height, dst_rgb_opt + (dst_stride_rgb * b) + b * 3, + dst_stride_rgb, dst_width, dst_height, f); + } + opt_time = (get_time() - opt_time) / benchmark_iterations; + + // Report performance of C vs OPT + printf("filter %d - %8d us C - %8d us OPT\n", f, + static_cast(c_time * 1e6), static_cast(opt_time * 1e6)); + + // C version may be a little off from the optimized. Order of + // operations may introduce rounding somewhere. So do a difference + // of the buffers and look to see that the max difference isn't + // over 2. + int max_diff = 0; + for (i = b; i < (dst_height + b); ++i) { + for (j = b * 3; j < (dst_width + b) * 3; ++j) { + int abs_diff = Abs(dst_rgb_c[(i * dst_stride_rgb) + j] - + dst_rgb_opt[(i * dst_stride_rgb) + j]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + } + + free_aligned_buffer_page_end(dst_rgb_c); + free_aligned_buffer_page_end(dst_rgb_opt); + free_aligned_buffer_page_end(src_rgb); + return max_diff; +} + +// The following adjustments in dimensions ensure the scale factor will be +// exactly achieved. +#define DX(x, nom, denom) static_cast((Abs(x) / nom) * nom) +#define SX(x, nom, denom) static_cast((x / nom) * denom) + +#define TEST_FACTOR1(name, filter, nom, denom, max_diff) \ + TEST_F(LibYUVScaleTest, RGBScaleDownBy##name##_##filter) { \ + int diff = RGBTestFilter( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } + +#if defined(ENABLE_FULL_TESTS) +// Test a scale factor with all 4 filters. Expect unfiltered to be exact, but +// filtering is different fixed point implementations for SSSE3, Neon and C. +#define TEST_FACTOR(name, nom, denom) \ + TEST_FACTOR1(name, None, nom, denom, 0) \ + TEST_FACTOR1(name, Linear, nom, denom, 3) \ + TEST_FACTOR1(name, Bilinear, nom, denom, 3) \ + TEST_FACTOR1(name, Box, nom, denom, 3) +#else +// Test a scale factor with Bilinear. +#define TEST_FACTOR(name, nom, denom) \ + TEST_FACTOR1(name, Bilinear, nom, denom, 3) +#endif + +TEST_FACTOR(2, 1, 2) +#ifndef DISABLE_SLOW_TESTS +TEST_FACTOR(4, 1, 4) +// TEST_FACTOR(8, 1, 8) Disable for benchmark performance. +TEST_FACTOR(3by4, 3, 4) +TEST_FACTOR(3by8, 3, 8) +TEST_FACTOR(3, 1, 3) +#endif +#undef TEST_FACTOR1 +#undef TEST_FACTOR +#undef SX +#undef DX + +#define TEST_SCALETO1(name, width, height, filter, max_diff) \ + TEST_F(LibYUVScaleTest, name##To##width##x##height##_##filter) { \ + int diff = RGBTestFilter(benchmark_width_, benchmark_height_, width, \ + height, kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, name##From##width##x##height##_##filter) { \ + int diff = RGBTestFilter(width, height, Abs(benchmark_width_), \ + Abs(benchmark_height_), kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } + +#if defined(ENABLE_FULL_TESTS) +/// Test scale to a specified size with all 4 filters. +#define TEST_SCALETO(name, width, height) \ + TEST_SCALETO1(name, width, height, None, 0) \ + TEST_SCALETO1(name, width, height, Linear, 3) \ + TEST_SCALETO1(name, width, height, Bilinear, 3) +#else +#define TEST_SCALETO(name, width, height) \ + TEST_SCALETO1(name, width, height, Bilinear, 3) +#endif + +TEST_SCALETO(RGBScale, 640, 360) +#ifndef DISABLE_SLOW_TESTS +TEST_SCALETO(RGBScale, 1, 1) +TEST_SCALETO(RGBScale, 256, 144) /* 128x72 * 3 */ +TEST_SCALETO(RGBScale, 320, 240) +TEST_SCALETO(RGBScale, 569, 480) +TEST_SCALETO(RGBScale, 1280, 720) +TEST_SCALETO(RGBScale, 1920, 1080) +#endif // DISABLE_SLOW_TESTS +#undef TEST_SCALETO1 +#undef TEST_SCALETO + +#define TEST_SCALESWAPXY1(name, filter, max_diff) \ + TEST_F(LibYUVScaleTest, name##SwapXY_##filter) { \ + int diff = RGBTestFilter(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } + +#if defined(ENABLE_FULL_TESTS) +// Test scale with swapped width and height with all 3 filters. +TEST_SCALESWAPXY1(RGBScale, None, 0) +TEST_SCALESWAPXY1(RGBScale, Linear, 0) +TEST_SCALESWAPXY1(RGBScale, Bilinear, 0) +#else +TEST_SCALESWAPXY1(RGBScale, Bilinear, 0) +#endif +#undef TEST_SCALESWAPXY1 + +TEST_F(LibYUVScaleTest, RGBTest3x) { + const int kSrcStride = 480 * 3; + const int kDstStride = 160 * 3; + const int kSize = kSrcStride * 3; + align_buffer_page_end(orig_pixels, kSize); + for (int i = 0; i < 480 * 3; ++i) { + orig_pixels[i * 3 + 0] = i; + orig_pixels[i * 3 + 1] = 255 - i; + } + align_buffer_page_end(dest_pixels, kDstStride); + + int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 * + benchmark_iterations_; + for (int i = 0; i < iterations160; ++i) { + RGBScale(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1, + kFilterBilinear); + } + + ASSERT_EQ(225, dest_pixels[0]); + ASSERT_EQ(255 - 225, dest_pixels[1]); + + RGBScale(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1, + kFilterNone); + + ASSERT_EQ(225, dest_pixels[0]); + ASSERT_EQ(255 - 225, dest_pixels[1]); + + free_aligned_buffer_page_end(dest_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +TEST_F(LibYUVScaleTest, RGBTest4x) { + const int kSrcStride = 640 * 3; + const int kDstStride = 160 * 3; + const int kSize = kSrcStride * 4; + align_buffer_page_end(orig_pixels, kSize); + for (int i = 0; i < 640 * 4; ++i) { + orig_pixels[i * 3 + 0] = i; + orig_pixels[i * 3 + 1] = 255 - i; + } + align_buffer_page_end(dest_pixels, kDstStride); + + int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 * + benchmark_iterations_; + for (int i = 0; i < iterations160; ++i) { + RGBScale(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1, + kFilterBilinear); + } + + ASSERT_EQ(66, dest_pixels[0]); + ASSERT_EQ(190, dest_pixels[1]); + + RGBScale(orig_pixels, kSrcStride, 64, 4, dest_pixels, kDstStride, 16, 1, + kFilterNone); + + ASSERT_EQ(2, dest_pixels[0]); // expect the 3rd pixel of the 3rd row + ASSERT_EQ(255 - 2, dest_pixels[1]); + + free_aligned_buffer_page_end(dest_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +} // namespace libyuv diff --git a/libs/libyuv/unit_test/scale_test.cc b/libs/libyuv/unit_test/scale_test.cc index 94a7859006..e634b6c0f8 100644 --- a/libs/libyuv/unit_test/scale_test.cc +++ b/libs/libyuv/unit_test/scale_test.cc @@ -22,6 +22,17 @@ #define STRINGIZE(line) #line #define FILELINESTR(file, line) file ":" STRINGIZE(line) +#if (defined(__riscv) && !defined(__clang__)) || defined(__hexagon__) +#define DISABLE_SLOW_TESTS +#undef ENABLE_FULL_TESTS +#endif + +#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) +// SLOW TESTS are those that are unoptimized C code. +// FULL TESTS are optimized but test many variations of the same code. +#define ENABLE_FULL_TESTS +#endif + namespace libyuv { // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. @@ -142,6 +153,123 @@ static int I420TestFilter(int src_width, return max_diff; } +// Test scaling with 8 bit C vs 12 bit C and return maximum pixel difference. +// 0 = exact. +static int I420TestFilter_12(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (!SizeValid(src_width, src_height, dst_width, dst_height)) { + return 0; + } + + int i; + int src_width_uv = (Abs(src_width) + 1) >> 1; + int src_height_uv = (Abs(src_height) + 1) >> 1; + + int64_t src_y_plane_size = (Abs(src_width)) * (Abs(src_height)); + int64_t src_uv_plane_size = (src_width_uv) * (src_height_uv); + + int src_stride_y = Abs(src_width); + int src_stride_uv = src_width_uv; + + align_buffer_page_end(src_y, src_y_plane_size); + align_buffer_page_end(src_u, src_uv_plane_size); + align_buffer_page_end(src_v, src_uv_plane_size); + align_buffer_page_end(src_y_12, src_y_plane_size * 2); + align_buffer_page_end(src_u_12, src_uv_plane_size * 2); + align_buffer_page_end(src_v_12, src_uv_plane_size * 2); + if (!src_y || !src_u || !src_v || !src_y_12 || !src_u_12 || !src_v_12) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + uint16_t* p_src_y_12 = reinterpret_cast(src_y_12); + uint16_t* p_src_u_12 = reinterpret_cast(src_u_12); + uint16_t* p_src_v_12 = reinterpret_cast(src_v_12); + + MemRandomize(src_y, src_y_plane_size); + MemRandomize(src_u, src_uv_plane_size); + MemRandomize(src_v, src_uv_plane_size); + + for (i = 0; i < src_y_plane_size; ++i) { + p_src_y_12[i] = src_y[i]; + } + for (i = 0; i < src_uv_plane_size; ++i) { + p_src_u_12[i] = src_u[i]; + p_src_v_12[i] = src_v[i]; + } + + int dst_width_uv = (dst_width + 1) >> 1; + int dst_height_uv = (dst_height + 1) >> 1; + + int dst_y_plane_size = (dst_width) * (dst_height); + int dst_uv_plane_size = (dst_width_uv) * (dst_height_uv); + + int dst_stride_y = dst_width; + int dst_stride_uv = dst_width_uv; + + align_buffer_page_end(dst_y_8, dst_y_plane_size); + align_buffer_page_end(dst_u_8, dst_uv_plane_size); + align_buffer_page_end(dst_v_8, dst_uv_plane_size); + align_buffer_page_end(dst_y_12, dst_y_plane_size * 2); + align_buffer_page_end(dst_u_12, dst_uv_plane_size * 2); + align_buffer_page_end(dst_v_12, dst_uv_plane_size * 2); + + uint16_t* p_dst_y_12 = reinterpret_cast(dst_y_12); + uint16_t* p_dst_u_12 = reinterpret_cast(dst_u_12); + uint16_t* p_dst_v_12 = reinterpret_cast(dst_v_12); + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + I420Scale(src_y, src_stride_y, src_u, src_stride_uv, src_v, src_stride_uv, + src_width, src_height, dst_y_8, dst_stride_y, dst_u_8, + dst_stride_uv, dst_v_8, dst_stride_uv, dst_width, dst_height, f); + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + for (i = 0; i < benchmark_iterations; ++i) { + I420Scale_12(p_src_y_12, src_stride_y, p_src_u_12, src_stride_uv, + p_src_v_12, src_stride_uv, src_width, src_height, p_dst_y_12, + dst_stride_y, p_dst_u_12, dst_stride_uv, p_dst_v_12, + dst_stride_uv, dst_width, dst_height, f); + } + + // Expect an exact match. + int max_diff = 0; + for (i = 0; i < dst_y_plane_size; ++i) { + int abs_diff = Abs(dst_y_8[i] - p_dst_y_12[i]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + for (i = 0; i < dst_uv_plane_size; ++i) { + int abs_diff = Abs(dst_u_8[i] - p_dst_u_12[i]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + abs_diff = Abs(dst_v_8[i] - p_dst_v_12[i]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + + free_aligned_buffer_page_end(dst_y_8); + free_aligned_buffer_page_end(dst_u_8); + free_aligned_buffer_page_end(dst_v_8); + free_aligned_buffer_page_end(dst_y_12); + free_aligned_buffer_page_end(dst_u_12); + free_aligned_buffer_page_end(dst_v_12); + free_aligned_buffer_page_end(src_y); + free_aligned_buffer_page_end(src_u); + free_aligned_buffer_page_end(src_v); + free_aligned_buffer_page_end(src_y_12); + free_aligned_buffer_page_end(src_u_12); + free_aligned_buffer_page_end(src_v_12); + + return max_diff; +} + // Test scaling with 8 bit C vs 16 bit C and return maximum pixel difference. // 0 = exact. static int I420TestFilter_16(int src_width, @@ -377,6 +505,123 @@ static int I444TestFilter(int src_width, return max_diff; } +// Test scaling with 8 bit C vs 12 bit C and return maximum pixel difference. +// 0 = exact. +static int I444TestFilter_12(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (!SizeValid(src_width, src_height, dst_width, dst_height)) { + return 0; + } + + int i; + int src_width_uv = Abs(src_width); + int src_height_uv = Abs(src_height); + + int64_t src_y_plane_size = (Abs(src_width)) * (Abs(src_height)); + int64_t src_uv_plane_size = (src_width_uv) * (src_height_uv); + + int src_stride_y = Abs(src_width); + int src_stride_uv = src_width_uv; + + align_buffer_page_end(src_y, src_y_plane_size); + align_buffer_page_end(src_u, src_uv_plane_size); + align_buffer_page_end(src_v, src_uv_plane_size); + align_buffer_page_end(src_y_12, src_y_plane_size * 2); + align_buffer_page_end(src_u_12, src_uv_plane_size * 2); + align_buffer_page_end(src_v_12, src_uv_plane_size * 2); + if (!src_y || !src_u || !src_v || !src_y_12 || !src_u_12 || !src_v_12) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + uint16_t* p_src_y_12 = reinterpret_cast(src_y_12); + uint16_t* p_src_u_12 = reinterpret_cast(src_u_12); + uint16_t* p_src_v_12 = reinterpret_cast(src_v_12); + + MemRandomize(src_y, src_y_plane_size); + MemRandomize(src_u, src_uv_plane_size); + MemRandomize(src_v, src_uv_plane_size); + + for (i = 0; i < src_y_plane_size; ++i) { + p_src_y_12[i] = src_y[i]; + } + for (i = 0; i < src_uv_plane_size; ++i) { + p_src_u_12[i] = src_u[i]; + p_src_v_12[i] = src_v[i]; + } + + int dst_width_uv = dst_width; + int dst_height_uv = dst_height; + + int dst_y_plane_size = (dst_width) * (dst_height); + int dst_uv_plane_size = (dst_width_uv) * (dst_height_uv); + + int dst_stride_y = dst_width; + int dst_stride_uv = dst_width_uv; + + align_buffer_page_end(dst_y_8, dst_y_plane_size); + align_buffer_page_end(dst_u_8, dst_uv_plane_size); + align_buffer_page_end(dst_v_8, dst_uv_plane_size); + align_buffer_page_end(dst_y_12, dst_y_plane_size * 2); + align_buffer_page_end(dst_u_12, dst_uv_plane_size * 2); + align_buffer_page_end(dst_v_12, dst_uv_plane_size * 2); + + uint16_t* p_dst_y_12 = reinterpret_cast(dst_y_12); + uint16_t* p_dst_u_12 = reinterpret_cast(dst_u_12); + uint16_t* p_dst_v_12 = reinterpret_cast(dst_v_12); + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + I444Scale(src_y, src_stride_y, src_u, src_stride_uv, src_v, src_stride_uv, + src_width, src_height, dst_y_8, dst_stride_y, dst_u_8, + dst_stride_uv, dst_v_8, dst_stride_uv, dst_width, dst_height, f); + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + for (i = 0; i < benchmark_iterations; ++i) { + I444Scale_12(p_src_y_12, src_stride_y, p_src_u_12, src_stride_uv, + p_src_v_12, src_stride_uv, src_width, src_height, p_dst_y_12, + dst_stride_y, p_dst_u_12, dst_stride_uv, p_dst_v_12, + dst_stride_uv, dst_width, dst_height, f); + } + + // Expect an exact match. + int max_diff = 0; + for (i = 0; i < dst_y_plane_size; ++i) { + int abs_diff = Abs(dst_y_8[i] - p_dst_y_12[i]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + for (i = 0; i < dst_uv_plane_size; ++i) { + int abs_diff = Abs(dst_u_8[i] - p_dst_u_12[i]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + abs_diff = Abs(dst_v_8[i] - p_dst_v_12[i]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + + free_aligned_buffer_page_end(dst_y_8); + free_aligned_buffer_page_end(dst_u_8); + free_aligned_buffer_page_end(dst_v_8); + free_aligned_buffer_page_end(dst_y_12); + free_aligned_buffer_page_end(dst_u_12); + free_aligned_buffer_page_end(dst_v_12); + free_aligned_buffer_page_end(src_y); + free_aligned_buffer_page_end(src_u); + free_aligned_buffer_page_end(src_v); + free_aligned_buffer_page_end(src_y_12); + free_aligned_buffer_page_end(src_u_12); + free_aligned_buffer_page_end(src_v_12); + + return max_diff; +} + // Test scaling with 8 bit C vs 16 bit C and return maximum pixel difference. // 0 = exact. static int I444TestFilter_16(int src_width, @@ -494,57 +739,454 @@ static int I444TestFilter_16(int src_width, return max_diff; } +// Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. +static int NVTestFilter(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int subsample_x, + int subsample_y, + int (*NVScale)(const uint8_t* src_y, + int src_stride_y, + const uint8_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint8_t* dst_y, + int dst_stride_y, + uint8_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering), + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (!SizeValid(src_width, src_height, dst_width, dst_height)) { + return 0; + } + + int i, j; + int src_width_uv = subsample_x ? ((Abs(src_width) + 1) >> 1) : Abs(src_width); + int src_height_uv = + subsample_y ? ((Abs(src_height) + 1) >> 1) : Abs(src_height); + + int64_t src_y_plane_size = (Abs(src_width)) * (Abs(src_height)); + int64_t src_uv_plane_size = (src_width_uv) * (src_height_uv) * 2; + + int src_stride_y = Abs(src_width); + int src_stride_uv = src_width_uv * 2; + + align_buffer_page_end(src_y, src_y_plane_size); + align_buffer_page_end(src_uv, src_uv_plane_size); + if (!src_y || !src_uv) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + MemRandomize(src_y, src_y_plane_size); + MemRandomize(src_uv, src_uv_plane_size); + + int dst_width_uv = subsample_x ? ((dst_width + 1) >> 1) : dst_width; + int dst_height_uv = subsample_y ? ((dst_height + 1) >> 1) : dst_height; + + int64_t dst_y_plane_size = (dst_width) * (dst_height); + int64_t dst_uv_plane_size = (dst_width_uv) * (dst_height_uv) * 2; + + int dst_stride_y = dst_width; + int dst_stride_uv = dst_width_uv * 2; + + align_buffer_page_end(dst_y_c, dst_y_plane_size); + align_buffer_page_end(dst_uv_c, dst_uv_plane_size); + align_buffer_page_end(dst_y_opt, dst_y_plane_size); + align_buffer_page_end(dst_uv_opt, dst_uv_plane_size); + if (!dst_y_c || !dst_uv_c || !dst_y_opt || !dst_uv_opt) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + double c_time = get_time(); + NVScale(src_y, src_stride_y, src_uv, src_stride_uv, src_width, src_height, + dst_y_c, dst_stride_y, dst_uv_c, dst_stride_uv, dst_width, dst_height, + f); + c_time = (get_time() - c_time); + + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + double opt_time = get_time(); + for (i = 0; i < benchmark_iterations; ++i) { + NVScale(src_y, src_stride_y, src_uv, src_stride_uv, src_width, src_height, + dst_y_opt, dst_stride_y, dst_uv_opt, dst_stride_uv, dst_width, + dst_height, f); + } + opt_time = (get_time() - opt_time) / benchmark_iterations; + // Report performance of C vs OPT. + printf("filter %d - %8d us C - %8d us OPT\n", f, + static_cast(c_time * 1e6), static_cast(opt_time * 1e6)); + + // C version may be a little off from the optimized. Order of + // operations may introduce rounding somewhere. So do a difference + // of the buffers and look to see that the max difference is not + // over 3. + int max_diff = 0; + for (i = 0; i < (dst_height); ++i) { + for (j = 0; j < (dst_width); ++j) { + int abs_diff = Abs(dst_y_c[(i * dst_stride_y) + j] - + dst_y_opt[(i * dst_stride_y) + j]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + } + + for (i = 0; i < (dst_height_uv); ++i) { + for (j = 0; j < (dst_width_uv * 2); ++j) { + int abs_diff = Abs(dst_uv_c[(i * dst_stride_uv) + j] - + dst_uv_opt[(i * dst_stride_uv) + j]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + } + + free_aligned_buffer_page_end(dst_y_c); + free_aligned_buffer_page_end(dst_uv_c); + free_aligned_buffer_page_end(dst_y_opt); + free_aligned_buffer_page_end(dst_uv_opt); + free_aligned_buffer_page_end(src_y); + free_aligned_buffer_page_end(src_uv); + + return max_diff; +} + +static int NV12TestFilter(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + return NVTestFilter(src_width, src_height, dst_width, dst_height, f, 1, 1, + NV12Scale, benchmark_iterations, disable_cpu_flags, + benchmark_cpu_info); +} + +static int NV16TestFilter(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + return NVTestFilter(src_width, src_height, dst_width, dst_height, f, 1, 0, + NV16Scale, benchmark_iterations, disable_cpu_flags, + benchmark_cpu_info); +} + +static int NV24TestFilter(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + return NVTestFilter(src_width, src_height, dst_width, dst_height, f, 0, 0, + NV24Scale, benchmark_iterations, disable_cpu_flags, + benchmark_cpu_info); +} + +static int PxxxTestFilter(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int subsample_x, + int subsample_y, + int (*PxxxScale)(const uint16_t* src_y, + int src_stride_y, + const uint16_t* src_uv, + int src_stride_uv, + int src_width, + int src_height, + uint16_t* dst_y, + int dst_stride_y, + uint16_t* dst_uv, + int dst_stride_uv, + int dst_width, + int dst_height, + enum FilterMode filtering), + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (!SizeValid(src_width, src_height, dst_width, dst_height)) { + return 0; + } + + int i, j; + int src_width_uv = subsample_x ? ((Abs(src_width) + 1) >> 1) : Abs(src_width); + int src_height_uv = + subsample_y ? ((Abs(src_height) + 1) >> 1) : Abs(src_height); + + int64_t src_y_plane_size = (Abs(src_width)) * (Abs(src_height)); + int64_t src_uv_plane_size = (src_width_uv) * (src_height_uv) * 2; + + int src_stride_y = Abs(src_width); + int src_stride_uv = src_width_uv * 2; + + align_buffer_page_end(src_y, src_y_plane_size * 2); + align_buffer_page_end(src_uv, src_uv_plane_size * 2); + if (!src_y || !src_uv) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + uint16_t* p_src_y = reinterpret_cast(src_y); + uint16_t* p_src_uv = reinterpret_cast(src_uv); + MemRandomize(src_y, src_y_plane_size * 2); + MemRandomize(src_uv, src_uv_plane_size * 2); + for (i = 0; i < src_y_plane_size; ++i) { + p_src_y[i] = static_cast(p_src_y[i] & 0xffc0); + } + for (i = 0; i < src_uv_plane_size; ++i) { + p_src_uv[i] = static_cast(p_src_uv[i] & 0xffc0); + } + + int dst_width_uv = subsample_x ? ((dst_width + 1) >> 1) : dst_width; + int dst_height_uv = subsample_y ? ((dst_height + 1) >> 1) : dst_height; + + int64_t dst_y_plane_size = (dst_width) * (dst_height); + int64_t dst_uv_plane_size = (dst_width_uv) * (dst_height_uv) * 2; + + int dst_stride_y = dst_width; + int dst_stride_uv = dst_width_uv * 2; + + align_buffer_page_end(dst_y_c, dst_y_plane_size * 2); + align_buffer_page_end(dst_uv_c, dst_uv_plane_size * 2); + align_buffer_page_end(dst_y_opt, dst_y_plane_size * 2); + align_buffer_page_end(dst_uv_opt, dst_uv_plane_size * 2); + if (!dst_y_c || !dst_uv_c || !dst_y_opt || !dst_uv_opt) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + uint16_t* p_dst_y_c = reinterpret_cast(dst_y_c); + uint16_t* p_dst_uv_c = reinterpret_cast(dst_uv_c); + uint16_t* p_dst_y_opt = reinterpret_cast(dst_y_opt); + uint16_t* p_dst_uv_opt = reinterpret_cast(dst_uv_opt); + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + double c_time = get_time(); + PxxxScale(p_src_y, src_stride_y, p_src_uv, src_stride_uv, src_width, + src_height, p_dst_y_c, dst_stride_y, p_dst_uv_c, dst_stride_uv, + dst_width, dst_height, f); + c_time = (get_time() - c_time); + + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + double opt_time = get_time(); + for (i = 0; i < benchmark_iterations; ++i) { + PxxxScale(p_src_y, src_stride_y, p_src_uv, src_stride_uv, src_width, + src_height, p_dst_y_opt, dst_stride_y, p_dst_uv_opt, + dst_stride_uv, dst_width, dst_height, f); + } + opt_time = (get_time() - opt_time) / benchmark_iterations; + printf("filter %d - %8d us C - %8d us OPT\n", f, + static_cast(c_time * 1e6), static_cast(opt_time * 1e6)); + + int max_diff = 0; + for (i = 0; i < dst_height; ++i) { + for (j = 0; j < dst_width; ++j) { + uint16_t c = p_dst_y_c[(i * dst_stride_y) + j]; + uint16_t opt = p_dst_y_opt[(i * dst_stride_y) + j]; + // Scaled output is converted back to canonical 10-bit MSB. + if ((c & 0x3f) || (opt & 0x3f)) { + max_diff = 999; + } + int abs_diff = Abs((c >> 6) - (opt >> 6)); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + } + for (i = 0; i < dst_height_uv; ++i) { + for (j = 0; j < (dst_width_uv * 2); ++j) { + uint16_t c = p_dst_uv_c[(i * dst_stride_uv) + j]; + uint16_t opt = p_dst_uv_opt[(i * dst_stride_uv) + j]; + // MergeUVPlane_16 depth=10 must produce canonical 10-bit MSB samples. + if ((c & 0x3f) || (opt & 0x3f)) { + max_diff = 999; + } + int abs_diff = Abs((c >> 6) - (opt >> 6)); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + } + + free_aligned_buffer_page_end(dst_y_c); + free_aligned_buffer_page_end(dst_uv_c); + free_aligned_buffer_page_end(dst_y_opt); + free_aligned_buffer_page_end(dst_uv_opt); + free_aligned_buffer_page_end(src_y); + free_aligned_buffer_page_end(src_uv); + + return max_diff; +} + +static int P010TestFilter(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + return PxxxTestFilter(src_width, src_height, dst_width, dst_height, f, 1, 1, + P010Scale, benchmark_iterations, disable_cpu_flags, + benchmark_cpu_info); +} + +static int P210TestFilter(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + return PxxxTestFilter(src_width, src_height, dst_width, dst_height, f, 1, 0, + P210Scale, benchmark_iterations, disable_cpu_flags, + benchmark_cpu_info); +} + +static int P410TestFilter(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + return PxxxTestFilter(src_width, src_height, dst_width, dst_height, f, 0, 0, + P410Scale, benchmark_iterations, disable_cpu_flags, + benchmark_cpu_info); +} + // The following adjustments in dimensions ensure the scale factor will be // exactly achieved. // 2 is chroma subsample. #define DX(x, nom, denom) static_cast(((Abs(x) / nom + 1) / 2) * nom * 2) #define SX(x, nom, denom) static_cast(((x / nom + 1) / 2) * denom * 2) -#define TEST_FACTOR1(name, filter, nom, denom, max_diff) \ - TEST_F(LibYUVScaleTest, I420ScaleDownBy##name##_##filter) { \ - int diff = I420TestFilter( \ - SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ - DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ - kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ - benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ - } \ - TEST_F(LibYUVScaleTest, I444ScaleDownBy##name##_##filter) { \ - int diff = I444TestFilter( \ - SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ - DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ - kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ - benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ - } \ - TEST_F(LibYUVScaleTest, I420ScaleDownBy##name##_##filter##_16) { \ - int diff = I420TestFilter_16( \ - SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ - DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ - kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ - benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ - } \ - TEST_F(LibYUVScaleTest, I444ScaleDownBy##name##_##filter##_16) { \ - int diff = I444TestFilter_16( \ - SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ - DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ - kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ - benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ +#define TEST_FACTOR1(DISABLED_, name, filter, nom, denom, max_diff) \ + TEST_F(LibYUVScaleTest, I420ScaleDownBy##name##_##filter) { \ + int diff = I420TestFilter( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, I444ScaleDownBy##name##_##filter) { \ + int diff = I444TestFilter( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, DISABLED_##I420ScaleDownBy##name##_##filter##_12) { \ + int diff = I420TestFilter_12( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, DISABLED_##I444ScaleDownBy##name##_##filter##_12) { \ + int diff = I444TestFilter_12( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV12ScaleDownBy##name##_##filter) { \ + int diff = NV12TestFilter( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV16ScaleDownBy##name##_##filter) { \ + int diff = NV16TestFilter( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV24ScaleDownBy##name##_##filter) { \ + int diff = NV24TestFilter( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P010ScaleDownBy##name##_##filter) { \ + int diff = P010TestFilter( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P210ScaleDownBy##name##_##filter) { \ + int diff = P210TestFilter( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P410ScaleDownBy##name##_##filter) { \ + int diff = P410TestFilter( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ } // Test a scale factor with all 4 filters. Expect unfiltered to be exact, but // filtering is different fixed point implementations for SSSE3, Neon and C. -#define TEST_FACTOR(name, nom, denom, boxdiff) \ - TEST_FACTOR1(name, None, nom, denom, 0) \ - TEST_FACTOR1(name, Linear, nom, denom, 3) \ - TEST_FACTOR1(name, Bilinear, nom, denom, 3) \ - TEST_FACTOR1(name, Box, nom, denom, boxdiff) +#ifndef DISABLE_SLOW_TESTS +#define TEST_FACTOR(name, nom, denom, boxdiff) \ + TEST_FACTOR1(, name, None, nom, denom, 0) \ + TEST_FACTOR1(, name, Linear, nom, denom, 3) \ + TEST_FACTOR1(, name, Bilinear, nom, denom, 3) \ + TEST_FACTOR1(, name, Box, nom, denom, boxdiff) +#else +#if defined(ENABLE_FULL_TESTS) +#define TEST_FACTOR(name, nom, denom, boxdiff) \ + TEST_FACTOR1(DISABLED_, name, None, nom, denom, 0) \ + TEST_FACTOR1(DISABLED_, name, Linear, nom, denom, 3) \ + TEST_FACTOR1(DISABLED_, name, Bilinear, nom, denom, 3) \ + TEST_FACTOR1(DISABLED_, name, Box, nom, denom, boxdiff) +#else +#define TEST_FACTOR(name, nom, denom, boxdiff) \ + TEST_FACTOR1(DISABLED_, name, Bilinear, nom, denom, 3) \ + TEST_FACTOR1(DISABLED_, name, Box, nom, denom, boxdiff) +#endif +#endif TEST_FACTOR(2, 1, 2, 0) TEST_FACTOR(4, 1, 4, 0) -// TEST_FACTOR(8, 1, 8, 0) Disable for benchmark performance. Takes 90 seconds. +#ifndef DISABLE_SLOW_TESTS +TEST_FACTOR(8, 1, 8, 0) +#endif TEST_FACTOR(3by4, 3, 4, 1) TEST_FACTOR(3by8, 3, 8, 1) TEST_FACTOR(3, 1, 3, 0) @@ -553,357 +1195,310 @@ TEST_FACTOR(3, 1, 3, 0) #undef SX #undef DX -#define TEST_SCALETO1(name, width, height, filter, max_diff) \ +#define TEST_SCALETO1(DISABLED_, name, width, height, filter, max_diff) \ TEST_F(LibYUVScaleTest, I420##name##To##width##x##height##_##filter) { \ int diff = I420TestFilter(benchmark_width_, benchmark_height_, width, \ height, kFilter##filter, benchmark_iterations_, \ disable_cpu_flags_, benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } \ TEST_F(LibYUVScaleTest, I444##name##To##width##x##height##_##filter) { \ int diff = I444TestFilter(benchmark_width_, benchmark_height_, width, \ height, kFilter##filter, benchmark_iterations_, \ disable_cpu_flags_, benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } \ - TEST_F(LibYUVScaleTest, I420##name##To##width##x##height##_##filter##_16) { \ + TEST_F(LibYUVScaleTest, \ + DISABLED_##I420##name##To##width##x##height##_##filter##_12) { \ + int diff = I420TestFilter_12( \ + benchmark_width_, benchmark_height_, width, height, kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, \ + DISABLED_##I444##name##To##width##x##height##_##filter##_12) { \ + int diff = I444TestFilter_12( \ + benchmark_width_, benchmark_height_, width, height, kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, \ + DISABLED_##I420##name##To##width##x##height##_##filter##_16) { \ int diff = I420TestFilter_16( \ benchmark_width_, benchmark_height_, width, height, kFilter##filter, \ benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } \ - TEST_F(LibYUVScaleTest, I444##name##To##width##x##height##_##filter##_16) { \ + TEST_F(LibYUVScaleTest, \ + DISABLED_##I444##name##To##width##x##height##_##filter##_16) { \ int diff = I444TestFilter_16( \ benchmark_width_, benchmark_height_, width, height, kFilter##filter, \ benchmark_iterations_, disable_cpu_flags_, benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV12##name##To##width##x##height##_##filter) { \ + int diff = NV12TestFilter(benchmark_width_, benchmark_height_, width, \ + height, kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV16##name##To##width##x##height##_##filter) { \ + int diff = NV16TestFilter(benchmark_width_, benchmark_height_, width, \ + height, kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV24##name##To##width##x##height##_##filter) { \ + int diff = NV24TestFilter(benchmark_width_, benchmark_height_, width, \ + height, kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P010##name##To##width##x##height##_##filter) { \ + int diff = P010TestFilter(benchmark_width_, benchmark_height_, width, \ + height, kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P210##name##To##width##x##height##_##filter) { \ + int diff = P210TestFilter(benchmark_width_, benchmark_height_, width, \ + height, kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P410##name##To##width##x##height##_##filter) { \ + int diff = P410TestFilter(benchmark_width_, benchmark_height_, width, \ + height, kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ } \ TEST_F(LibYUVScaleTest, I420##name##From##width##x##height##_##filter) { \ int diff = I420TestFilter(width, height, Abs(benchmark_width_), \ Abs(benchmark_height_), kFilter##filter, \ benchmark_iterations_, disable_cpu_flags_, \ benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } \ TEST_F(LibYUVScaleTest, I444##name##From##width##x##height##_##filter) { \ int diff = I444TestFilter(width, height, Abs(benchmark_width_), \ Abs(benchmark_height_), kFilter##filter, \ benchmark_iterations_, disable_cpu_flags_, \ benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } \ TEST_F(LibYUVScaleTest, \ - I420##name##From##width##x##height##_##filter##_16) { \ + DISABLED_##I420##name##From##width##x##height##_##filter##_12) { \ + int diff = I420TestFilter_12(width, height, Abs(benchmark_width_), \ + Abs(benchmark_height_), kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, \ + DISABLED_##I444##name##From##width##x##height##_##filter##_12) { \ + int diff = I444TestFilter_12(width, height, Abs(benchmark_width_), \ + Abs(benchmark_height_), kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, \ + DISABLED_##I420##name##From##width##x##height##_##filter##_16) { \ int diff = I420TestFilter_16(width, height, Abs(benchmark_width_), \ Abs(benchmark_height_), kFilter##filter, \ benchmark_iterations_, disable_cpu_flags_, \ benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ } \ TEST_F(LibYUVScaleTest, \ - I444##name##From##width##x##height##_##filter##_16) { \ + DISABLED_##I444##name##From##width##x##height##_##filter##_16) { \ int diff = I444TestFilter_16(width, height, Abs(benchmark_width_), \ Abs(benchmark_height_), kFilter##filter, \ benchmark_iterations_, disable_cpu_flags_, \ benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV12##name##From##width##x##height##_##filter) { \ + int diff = NV12TestFilter(width, height, Abs(benchmark_width_), \ + Abs(benchmark_height_), kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV16##name##From##width##x##height##_##filter) { \ + int diff = NV16TestFilter(width, height, Abs(benchmark_width_), \ + Abs(benchmark_height_), kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV24##name##From##width##x##height##_##filter) { \ + int diff = NV24TestFilter(width, height, Abs(benchmark_width_), \ + Abs(benchmark_height_), kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P010##name##From##width##x##height##_##filter) { \ + int diff = P010TestFilter(width, height, Abs(benchmark_width_), \ + Abs(benchmark_height_), kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P210##name##From##width##x##height##_##filter) { \ + int diff = P210TestFilter(width, height, Abs(benchmark_width_), \ + Abs(benchmark_height_), kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P410##name##From##width##x##height##_##filter) { \ + int diff = P410TestFilter(width, height, Abs(benchmark_width_), \ + Abs(benchmark_height_), kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ } +#ifndef DISABLE_SLOW_TESTS // Test scale to a specified size with all 4 filters. -#define TEST_SCALETO(name, width, height) \ - TEST_SCALETO1(name, width, height, None, 0) \ - TEST_SCALETO1(name, width, height, Linear, 3) \ - TEST_SCALETO1(name, width, height, Bilinear, 3) \ - TEST_SCALETO1(name, width, height, Box, 3) +#define TEST_SCALETO(name, width, height) \ + TEST_SCALETO1(, name, width, height, None, 0) \ + TEST_SCALETO1(, name, width, height, Linear, 3) \ + TEST_SCALETO1(, name, width, height, Bilinear, 3) \ + TEST_SCALETO1(, name, width, height, Box, 3) +#else +#if defined(ENABLE_FULL_TESTS) +#define TEST_SCALETO(name, width, height) \ + TEST_SCALETO1(DISABLED_, name, width, height, None, 0) \ + TEST_SCALETO1(DISABLED_, name, width, height, Linear, 3) \ + TEST_SCALETO1(DISABLED_, name, width, height, Bilinear, 3) \ + TEST_SCALETO1(DISABLED_, name, width, height, Box, 3) +#else +#define TEST_SCALETO(name, width, height) \ + TEST_SCALETO1(DISABLED_, name, width, height, Bilinear, 3) \ + TEST_SCALETO1(DISABLED_, name, width, height, Box, 3) +#endif +#endif TEST_SCALETO(Scale, 1, 1) -TEST_SCALETO(Scale, 320, 240) TEST_SCALETO(Scale, 569, 480) TEST_SCALETO(Scale, 640, 360) +#ifndef DISABLE_SLOW_TESTS +TEST_SCALETO(Scale, 256, 144) /* 128x72 * 2 */ +TEST_SCALETO(Scale, 264, 216) +TEST_SCALETO(Scale, 320, 240) TEST_SCALETO(Scale, 1280, 720) TEST_SCALETO(Scale, 1920, 1080) +TEST_SCALETO(Scale, 1080, 1920) // for rotated phones +#endif // DISABLE_SLOW_TESTS #undef TEST_SCALETO1 #undef TEST_SCALETO -#ifdef ENABLE_ROW_TESTS -#ifdef HAS_SCALEROWDOWN2_SSSE3 -TEST_F(LibYUVScaleTest, TestScaleRowDown2Box_Odd_SSSE3) { - SIMD_ALIGNED(uint8_t orig_pixels[128 * 2]); - SIMD_ALIGNED(uint8_t dst_pixels_opt[64]); - SIMD_ALIGNED(uint8_t dst_pixels_c[64]); - memset(orig_pixels, 0, sizeof(orig_pixels)); - memset(dst_pixels_opt, 0, sizeof(dst_pixels_opt)); - memset(dst_pixels_c, 0, sizeof(dst_pixels_c)); - - int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); - if (!has_ssse3) { - printf("Warning SSSE3 not detected; Skipping test.\n"); - } else { - // TL. - orig_pixels[0] = 255u; - orig_pixels[1] = 0u; - orig_pixels[128 + 0] = 0u; - orig_pixels[128 + 1] = 0u; - // TR. - orig_pixels[2] = 0u; - orig_pixels[3] = 100u; - orig_pixels[128 + 2] = 0u; - orig_pixels[128 + 3] = 0u; - // BL. - orig_pixels[4] = 0u; - orig_pixels[5] = 0u; - orig_pixels[128 + 4] = 50u; - orig_pixels[128 + 5] = 0u; - // BR. - orig_pixels[6] = 0u; - orig_pixels[7] = 0u; - orig_pixels[128 + 6] = 0u; - orig_pixels[128 + 7] = 20u; - // Odd. - orig_pixels[126] = 4u; - orig_pixels[127] = 255u; - orig_pixels[128 + 126] = 16u; - orig_pixels[128 + 127] = 255u; - - // Test regular half size. - ScaleRowDown2Box_C(orig_pixels, 128, dst_pixels_c, 64); - - EXPECT_EQ(64u, dst_pixels_c[0]); - EXPECT_EQ(25u, dst_pixels_c[1]); - EXPECT_EQ(13u, dst_pixels_c[2]); - EXPECT_EQ(5u, dst_pixels_c[3]); - EXPECT_EQ(0u, dst_pixels_c[4]); - EXPECT_EQ(133u, dst_pixels_c[63]); - - // Test Odd width version - Last pixel is just 1 horizontal pixel. - ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 64); - - EXPECT_EQ(64u, dst_pixels_c[0]); - EXPECT_EQ(25u, dst_pixels_c[1]); - EXPECT_EQ(13u, dst_pixels_c[2]); - EXPECT_EQ(5u, dst_pixels_c[3]); - EXPECT_EQ(0u, dst_pixels_c[4]); - EXPECT_EQ(10u, dst_pixels_c[63]); - - // Test one pixel less, should skip the last pixel. - memset(dst_pixels_c, 0, sizeof(dst_pixels_c)); - ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 63); - - EXPECT_EQ(64u, dst_pixels_c[0]); - EXPECT_EQ(25u, dst_pixels_c[1]); - EXPECT_EQ(13u, dst_pixels_c[2]); - EXPECT_EQ(5u, dst_pixels_c[3]); - EXPECT_EQ(0u, dst_pixels_c[4]); - EXPECT_EQ(0u, dst_pixels_c[63]); - - // Test regular half size SSSE3. - ScaleRowDown2Box_SSSE3(orig_pixels, 128, dst_pixels_opt, 64); - - EXPECT_EQ(64u, dst_pixels_opt[0]); - EXPECT_EQ(25u, dst_pixels_opt[1]); - EXPECT_EQ(13u, dst_pixels_opt[2]); - EXPECT_EQ(5u, dst_pixels_opt[3]); - EXPECT_EQ(0u, dst_pixels_opt[4]); - EXPECT_EQ(133u, dst_pixels_opt[63]); - - // Compare C and SSSE3 match. - ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 64); - ScaleRowDown2Box_Odd_SSSE3(orig_pixels, 128, dst_pixels_opt, 64); - for (int i = 0; i < 64; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); - } +#define TEST_SCALESWAPXY1(DISABLED_, name, filter, max_diff) \ + TEST_F(LibYUVScaleTest, I420##name##SwapXY_##filter) { \ + int diff = I420TestFilter(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, I444##name##SwapXY_##filter) { \ + int diff = I444TestFilter(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, DISABLED_##I420##name##SwapXY_##filter##_12) { \ + int diff = I420TestFilter_12(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, DISABLED_##I444##name##SwapXY_##filter##_12) { \ + int diff = I444TestFilter_12(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, DISABLED_##I420##name##SwapXY_##filter##_16) { \ + int diff = I420TestFilter_16(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, DISABLED_##I444##name##SwapXY_##filter##_16) { \ + int diff = I444TestFilter_16(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV12##name##SwapXY_##filter) { \ + int diff = NV12TestFilter(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV16##name##SwapXY_##filter) { \ + int diff = NV16TestFilter(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, NV24##name##SwapXY_##filter) { \ + int diff = NV24TestFilter(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P010##name##SwapXY_##filter) { \ + int diff = P010TestFilter(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P210##name##SwapXY_##filter) { \ + int diff = P210TestFilter(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, P410##name##SwapXY_##filter) { \ + int diff = P410TestFilter(benchmark_width_, benchmark_height_, \ + benchmark_height_, benchmark_width_, \ + kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ } -} -#endif // HAS_SCALEROWDOWN2_SSSE3 -extern "C" void ScaleRowUp2_16_NEON(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width); -extern "C" void ScaleRowUp2_16_MMI(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width); -extern "C" void ScaleRowUp2_16_C(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width); - -TEST_F(LibYUVScaleTest, TestScaleRowUp2_16) { - SIMD_ALIGNED(uint16_t orig_pixels[640 * 2 + 1]); // 2 rows + 1 pixel overrun. - SIMD_ALIGNED(uint16_t dst_pixels_opt[1280]); - SIMD_ALIGNED(uint16_t dst_pixels_c[1280]); - - memset(orig_pixels, 0, sizeof(orig_pixels)); - memset(dst_pixels_opt, 1, sizeof(dst_pixels_opt)); - memset(dst_pixels_c, 2, sizeof(dst_pixels_c)); - - for (int i = 0; i < 640 * 2 + 1; ++i) { - orig_pixels[i] = i; - } - ScaleRowUp2_16_C(&orig_pixels[0], 640, &dst_pixels_c[0], 1280); - for (int i = 0; i < benchmark_pixels_div1280_; ++i) { -#if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) - int has_neon = TestCpuFlag(kCpuHasNEON); - if (has_neon) { - ScaleRowUp2_16_NEON(&orig_pixels[0], 640, &dst_pixels_opt[0], 1280); - } else { - ScaleRowUp2_16_C(&orig_pixels[0], 640, &dst_pixels_opt[0], 1280); - } -#elif !defined(LIBYUV_DISABLE_MMI) && defined(_MIPS_ARCH_LOONGSON3A) - int has_mmi = TestCpuFlag(kCpuHasMMI); - if (has_mmi) { - ScaleRowUp2_16_MMI(&orig_pixels[0], 640, &dst_pixels_opt[0], 1280); - } else { - ScaleRowUp2_16_C(&orig_pixels[0], 640, &dst_pixels_opt[0], 1280); - } +// Test scale to a specified size with all 4 filters. +#ifndef DISABLE_SLOW_TESTS +TEST_SCALESWAPXY1(, Scale, None, 0) +TEST_SCALESWAPXY1(, Scale, Linear, 3) +TEST_SCALESWAPXY1(, Scale, Bilinear, 3) +TEST_SCALESWAPXY1(, Scale, Box, 3) #else - ScaleRowUp2_16_C(&orig_pixels[0], 640, &dst_pixels_opt[0], 1280); -#endif - } - - for (int i = 0; i < 1280; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); - } - EXPECT_EQ(dst_pixels_c[0], (0 * 9 + 1 * 3 + 640 * 3 + 641 * 1 + 8) / 16); - EXPECT_EQ(dst_pixels_c[1279], 800); -} - -extern "C" void ScaleRowDown2Box_16_NEON(const uint16_t* src_ptr, - ptrdiff_t src_stride, - uint16_t* dst, - int dst_width); - -TEST_F(LibYUVScaleTest, TestScaleRowDown2Box_16) { - SIMD_ALIGNED(uint16_t orig_pixels[2560 * 2]); - SIMD_ALIGNED(uint16_t dst_pixels_c[1280]); - SIMD_ALIGNED(uint16_t dst_pixels_opt[1280]); - - memset(orig_pixels, 0, sizeof(orig_pixels)); - memset(dst_pixels_c, 1, sizeof(dst_pixels_c)); - memset(dst_pixels_opt, 2, sizeof(dst_pixels_opt)); - - for (int i = 0; i < 2560 * 2; ++i) { - orig_pixels[i] = i; - } - ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_c[0], 1280); - for (int i = 0; i < benchmark_pixels_div1280_; ++i) { -#if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) - int has_neon = TestCpuFlag(kCpuHasNEON); - if (has_neon) { - ScaleRowDown2Box_16_NEON(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280); - } else { - ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280); - } +#if defined(ENABLE_FULL_TESTS) +TEST_SCALESWAPXY1(DISABLED_, Scale, None, 0) +TEST_SCALESWAPXY1(DISABLED_, Scale, Linear, 3) +TEST_SCALESWAPXY1(DISABLED_, Scale, Bilinear, 3) +TEST_SCALESWAPXY1(DISABLED_, Scale, Box, 3) #else - ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280); +TEST_SCALESWAPXY1(DISABLED_, Scale, Bilinear, 3) +TEST_SCALESWAPXY1(DISABLED_, Scale, Box, 3) #endif - } +#endif +#undef TEST_SCALESWAPXY1 - for (int i = 0; i < 1280; ++i) { - EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); - } - - EXPECT_EQ(dst_pixels_c[0], (0 + 1 + 2560 + 2561 + 2) / 4); - EXPECT_EQ(dst_pixels_c[1279], 3839); -} -#endif // ENABLE_ROW_TESTS - -// Test scaling plane with 8 bit C vs 16 bit C and return maximum pixel -// difference. -// 0 = exact. -static int TestPlaneFilter_16(int src_width, - int src_height, - int dst_width, - int dst_height, - FilterMode f, - int benchmark_iterations, - int disable_cpu_flags, - int benchmark_cpu_info) { - if (!SizeValid(src_width, src_height, dst_width, dst_height)) { - return 0; - } - - int i; - int64_t src_y_plane_size = (Abs(src_width)) * (Abs(src_height)); - int src_stride_y = Abs(src_width); - int dst_y_plane_size = dst_width * dst_height; - int dst_stride_y = dst_width; - - align_buffer_page_end(src_y, src_y_plane_size); - align_buffer_page_end(src_y_16, src_y_plane_size * 2); - align_buffer_page_end(dst_y_8, dst_y_plane_size); - align_buffer_page_end(dst_y_16, dst_y_plane_size * 2); - uint16_t* p_src_y_16 = reinterpret_cast(src_y_16); - uint16_t* p_dst_y_16 = reinterpret_cast(dst_y_16); - - MemRandomize(src_y, src_y_plane_size); - memset(dst_y_8, 0, dst_y_plane_size); - memset(dst_y_16, 1, dst_y_plane_size * 2); - - for (i = 0; i < src_y_plane_size; ++i) { - p_src_y_16[i] = src_y[i] & 255; - } - - MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. - ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y_8, dst_stride_y, - dst_width, dst_height, f); - MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. - - for (i = 0; i < benchmark_iterations; ++i) { - ScalePlane_16(p_src_y_16, src_stride_y, src_width, src_height, p_dst_y_16, - dst_stride_y, dst_width, dst_height, f); - } - - // Expect an exact match. - int max_diff = 0; - for (i = 0; i < dst_y_plane_size; ++i) { - int abs_diff = Abs(dst_y_8[i] - p_dst_y_16[i]); - if (abs_diff > max_diff) { - max_diff = abs_diff; - } - } - - free_aligned_buffer_page_end(dst_y_8); - free_aligned_buffer_page_end(dst_y_16); - free_aligned_buffer_page_end(src_y); - free_aligned_buffer_page_end(src_y_16); - - return max_diff; -} - -// The following adjustments in dimensions ensure the scale factor will be -// exactly achieved. -// 2 is chroma subsample. -#define DX(x, nom, denom) static_cast(((Abs(x) / nom + 1) / 2) * nom * 2) -#define SX(x, nom, denom) static_cast(((x / nom + 1) / 2) * denom * 2) - -#define TEST_FACTOR1(name, filter, nom, denom, max_diff) \ - TEST_F(LibYUVScaleTest, ScalePlaneDownBy##name##_##filter##_16) { \ - int diff = TestPlaneFilter_16( \ - SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ - DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ - kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ - benchmark_cpu_info_); \ - EXPECT_LE(diff, max_diff); \ - } - -// Test a scale factor with all 4 filters. Expect unfiltered to be exact, but -// filtering is different fixed point implementations for SSSE3, Neon and C. -#define TEST_FACTOR(name, nom, denom, boxdiff) \ - TEST_FACTOR1(name, None, nom, denom, 0) \ - TEST_FACTOR1(name, Linear, nom, denom, boxdiff) \ - TEST_FACTOR1(name, Bilinear, nom, denom, boxdiff) \ - TEST_FACTOR1(name, Box, nom, denom, boxdiff) - -TEST_FACTOR(2, 1, 2, 0) -TEST_FACTOR(4, 1, 4, 0) -// TEST_FACTOR(8, 1, 8, 0) Disable for benchmark performance. Takes 90 seconds. -TEST_FACTOR(3by4, 3, 4, 1) -TEST_FACTOR(3by8, 3, 8, 1) -TEST_FACTOR(3, 1, 3, 0) -#undef TEST_FACTOR1 -#undef TEST_FACTOR -#undef SX -#undef DX } // namespace libyuv diff --git a/libs/libyuv/unit_test/scale_uv_test.cc b/libs/libyuv/unit_test/scale_uv_test.cc new file mode 100644 index 0000000000..bbb6bbc680 --- /dev/null +++ b/libs/libyuv/unit_test/scale_uv_test.cc @@ -0,0 +1,657 @@ +/* + * Copyright 2011 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "../unit_test/unit_test.h" +#include "libyuv/cpu_id.h" +#include "libyuv/scale.h" +#include "libyuv/scale_uv.h" + +namespace libyuv { + +#define STRINGIZE(line) #line +#define FILELINESTR(file, line) file ":" STRINGIZE(line) + +#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) +// SLOW TESTS are those that are unoptimized C code. +// FULL TESTS are optimized but test many variations of the same code. +#define ENABLE_FULL_TESTS +#endif + +// Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. +static int UVTestFilter(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (!SizeValid(src_width, src_height, dst_width, dst_height)) { + return 0; + } + if (src_width <= 0 || src_height == 0 || dst_width <= 0 || dst_height <= 0) { + return 0; + } + + int i; + int64_t src_uv_plane_size = Abs(src_width) * Abs(src_height) * 2LL; + int src_stride_uv = Abs(src_width) * 2; + int64_t dst_uv_plane_size = dst_width * dst_height * 2LL; + int dst_stride_uv = dst_width * 2; + + align_buffer_page_end(src_uv, src_uv_plane_size); + align_buffer_page_end(dst_uv_c, dst_uv_plane_size); + align_buffer_page_end(dst_uv_opt, dst_uv_plane_size); + + if (!src_uv || !dst_uv_c || !dst_uv_opt) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + MemRandomize(src_uv, src_uv_plane_size); + memset(dst_uv_c, 2, dst_uv_plane_size); + memset(dst_uv_opt, 123, dst_uv_plane_size); + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + double c_time = get_time(); + UVScale(src_uv, src_stride_uv, src_width, src_height, dst_uv_c, dst_stride_uv, + dst_width, dst_height, f); + c_time = (get_time() - c_time); + + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + double opt_time = get_time(); + for (i = 0; i < benchmark_iterations; ++i) { + UVScale(src_uv, src_stride_uv, src_width, src_height, dst_uv_opt, + dst_stride_uv, dst_width, dst_height, f); + } + opt_time = (get_time() - opt_time) / benchmark_iterations; + + // Report performance of C vs OPT + printf("filter %d - %8d us C - %8d us OPT\n", f, + static_cast(c_time * 1e6), static_cast(opt_time * 1e6)); + + int max_diff = 0; + for (i = 0; i < dst_uv_plane_size; ++i) { + int abs_diff = Abs(dst_uv_c[i] - dst_uv_opt[i]); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + + free_aligned_buffer_page_end(dst_uv_c); + free_aligned_buffer_page_end(dst_uv_opt); + free_aligned_buffer_page_end(src_uv); + return max_diff; +} + +// The following adjustments in dimensions ensure the scale factor will be +// exactly achieved. +#define DX(x, nom, denom) static_cast((Abs(x) / nom) * nom) +#define SX(x, nom, denom) static_cast((x / nom) * denom) + +#define TEST_FACTOR1(name, filter, nom, denom) \ + TEST_F(LibYUVScaleTest, UVScaleDownBy##name##_##filter) { \ + int diff = UVTestFilter( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_EQ(0, diff); \ + } + +#if defined(ENABLE_FULL_TESTS) +// Test a scale factor with all 4 filters. Expect exact for SIMD vs C. +#define TEST_FACTOR(name, nom, denom) \ + TEST_FACTOR1(name, None, nom, denom) \ + TEST_FACTOR1(name, Linear, nom, denom) \ + TEST_FACTOR1(name, Bilinear, nom, denom) \ + TEST_FACTOR1(name, Box, nom, denom) +#else +// Test a scale factor with Bilinear. +#define TEST_FACTOR(name, nom, denom) TEST_FACTOR1(name, Bilinear, nom, denom) +#endif + +TEST_FACTOR(2, 1, 2) +TEST_FACTOR(4, 1, 4) +// TEST_FACTOR(8, 1, 8) Disable for benchmark performance. +TEST_FACTOR(3by4, 3, 4) +TEST_FACTOR(3by8, 3, 8) +TEST_FACTOR(3, 1, 3) +#undef TEST_FACTOR1 +#undef TEST_FACTOR +#undef SX +#undef DX + +#define TEST_SCALETO1(name, width, height, filter, max_diff) \ + TEST_F(LibYUVScaleTest, name##To##width##x##height##_##filter) { \ + int diff = UVTestFilter(benchmark_width_, benchmark_height_, width, \ + height, kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, name##From##width##x##height##_##filter) { \ + int diff = UVTestFilter(width, height, Abs(benchmark_width_), \ + Abs(benchmark_height_), kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } + +#if defined(ENABLE_FULL_TESTS) +/// Test scale to a specified size with all 4 filters. +#define TEST_SCALETO(name, width, height) \ + TEST_SCALETO1(name, width, height, None, 0) \ + TEST_SCALETO1(name, width, height, Linear, 3) \ + TEST_SCALETO1(name, width, height, Bilinear, 3) +#else +#define TEST_SCALETO(name, width, height) \ + TEST_SCALETO1(name, width, height, Bilinear, 3) +#endif + +TEST_SCALETO(UVScale, 1, 1) +TEST_SCALETO(UVScale, 569, 480) +TEST_SCALETO(UVScale, 640, 360) +#ifndef DISABLE_SLOW_TESTS +TEST_SCALETO(UVScale, 256, 144) /* 128x72 * 2 */ +TEST_SCALETO(UVScale, 320, 240) +TEST_SCALETO(UVScale, 1280, 720) +TEST_SCALETO(UVScale, 1920, 1080) +#endif // DISABLE_SLOW_TESTS +#undef TEST_SCALETO1 +#undef TEST_SCALETO + +#define TEST_SCALESWAPXY1(name, filter, max_diff) \ + TEST_F(LibYUVScaleTest, name##SwapXY_##filter) { \ + int diff = \ + UVTestFilter(benchmark_width_, benchmark_height_, benchmark_height_, \ + benchmark_width_, kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } + +#if defined(ENABLE_FULL_TESTS) +// Test scale with swapped width and height with all 3 filters. +TEST_SCALESWAPXY1(UVScale, None, 0) +TEST_SCALESWAPXY1(UVScale, Linear, 0) +TEST_SCALESWAPXY1(UVScale, Bilinear, 0) +#else +TEST_SCALESWAPXY1(UVScale, Bilinear, 0) +#endif +#undef TEST_SCALESWAPXY1 + +TEST_F(LibYUVScaleTest, UVTest3x) { + const int kSrcStride = 480 * 2; + const int kDstStride = 160 * 2; + const int kSize = kSrcStride * 3; + align_buffer_page_end(orig_pixels, kSize); + for (int i = 0; i < 480 * 3; ++i) { + orig_pixels[i * 2 + 0] = i; + orig_pixels[i * 2 + 1] = 255 - i; + } + align_buffer_page_end(dest_pixels, kDstStride); + + int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 * + benchmark_iterations_; + for (int i = 0; i < iterations160; ++i) { + UVScale(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1, + kFilterBilinear); + } + + ASSERT_EQ(225, dest_pixels[0]); + ASSERT_EQ(255 - 225, dest_pixels[1]); + + UVScale(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1, + kFilterNone); + + ASSERT_EQ(225, dest_pixels[0]); + ASSERT_EQ(255 - 225, dest_pixels[1]); + + free_aligned_buffer_page_end(dest_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +TEST_F(LibYUVScaleTest, UVTest4x) { + const int kSrcStride = 640 * 2; + const int kDstStride = 160 * 2; + const int kSize = kSrcStride * 4; + align_buffer_page_end(orig_pixels, kSize); + for (int i = 0; i < 640 * 4; ++i) { + orig_pixels[i * 2 + 0] = i; + orig_pixels[i * 2 + 1] = 255 - i; + } + align_buffer_page_end(dest_pixels, kDstStride); + + int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 * + benchmark_iterations_; + for (int i = 0; i < iterations160; ++i) { + UVScale(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1, + kFilterBilinear); + } + + ASSERT_EQ(66, dest_pixels[0]); + ASSERT_EQ(190, dest_pixels[1]); + + UVScale(orig_pixels, kSrcStride, 64, 4, dest_pixels, kDstStride, 16, 1, + kFilterNone); + + ASSERT_EQ(2, dest_pixels[0]); // expect the 3rd pixel of the 3rd row + ASSERT_EQ(255 - 2, dest_pixels[1]); + + free_aligned_buffer_page_end(dest_pixels); + free_aligned_buffer_page_end(orig_pixels); +} + +// Box filtering an interleaved UV plane has to produce the same bytes as box +// filtering the U and V planes separately, which is the path I420 takes. +// C and SIMD agreeing is not enough here: before ScaleUVBox existed both +// point sampled, so this compares against an independent implementation. +static int UVTestBoxAgainstPlanes(int src_width, + int src_height, + int dst_width, + int dst_height, + int cpu_info) { + if (!SizeValid(src_width, src_height, dst_width, dst_height)) { + return 0; + } + if (src_width <= 0 || src_height == 0 || dst_width <= 0 || dst_height <= 0) { + return 0; + } + int64_t src_uv_plane_size = src_width * src_height * 2LL; + int64_t src_plane_size = src_width * src_height * 1LL; + int64_t dst_uv_plane_size = dst_width * dst_height * 2LL; + int64_t dst_plane_size = dst_width * dst_height * 1LL; + + align_buffer_page_end(src_uv, src_uv_plane_size); + align_buffer_page_end(src_u, src_plane_size); + align_buffer_page_end(src_v, src_plane_size); + align_buffer_page_end(dst_uv, dst_uv_plane_size); + align_buffer_page_end(dst_u, dst_plane_size); + align_buffer_page_end(dst_v, dst_plane_size); + if (!src_uv || !src_u || !src_v || !dst_uv || !dst_u || !dst_v) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + MemRandomize(src_uv, src_uv_plane_size); + memset(dst_uv, 123, dst_uv_plane_size); + for (int i = 0; i < src_width * src_height; ++i) { + src_u[i] = src_uv[i * 2 + 0]; + src_v[i] = src_uv[i * 2 + 1]; + } + + MaskCpuFlags(cpu_info); + UVScale(src_uv, src_width * 2, src_width, src_height, dst_uv, dst_width * 2, + dst_width, dst_height, kFilterBox); + ScalePlane(src_u, src_width, src_width, src_height, dst_u, dst_width, + dst_width, dst_height, kFilterBox); + ScalePlane(src_v, src_width, src_width, src_height, dst_v, dst_width, + dst_width, dst_height, kFilterBox); + + int max_diff = 0; + for (int i = 0; i < dst_width * dst_height; ++i) { + int du = Abs(dst_uv[i * 2 + 0] - dst_u[i]); + int dv = Abs(dst_uv[i * 2 + 1] - dst_v[i]); + if (du > max_diff) { + max_diff = du; + } + if (dv > max_diff) { + max_diff = dv; + } + } + + free_aligned_buffer_page_end(dst_v); + free_aligned_buffer_page_end(dst_u); + free_aligned_buffer_page_end(dst_uv); + free_aligned_buffer_page_end(src_v); + free_aligned_buffer_page_end(src_u); + free_aligned_buffer_page_end(src_uv); + return max_diff; +} + +// Chroma dimensions, ie half the frame sizes named in the comments. +// max_diff is 0 for everything ScaleUVBox handles. The 1/2 and 1/4 fast paths +// predate it and keep their own rounding, so 1/4 is allowed to drift by one. +#define TEST_BOXPLANE(name, swidth, sheight, dwidth, dheight, max_diff) \ + TEST_F(LibYUVScaleTest, UVScaleBoxMatchesPlane##name) { \ + int diff_c = UVTestBoxAgainstPlanes(swidth, sheight, dwidth, dheight, \ + disable_cpu_flags_); \ + ASSERT_LE(diff_c, max_diff); \ + int diff_opt = UVTestBoxAgainstPlanes(swidth, sheight, dwidth, dheight, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff_opt, max_diff); \ + } + +TEST_BOXPLANE(By2, 960, 540, 480, 270, 0) /* 1080p to 960x540 */ +TEST_BOXPLANE(By3, 960, 540, 320, 180, 0) /* 1080p to 640x360 */ +TEST_BOXPLANE(By3Rounded, 640, 360, 214, 120, 0) /* 720p to 427x240 */ +TEST_BOXPLANE(By4, 960, 540, 240, 135, 1) /* ScaleUVDown4Box */ +TEST_BOXPLANE(By3_75, 960, 540, 256, 144, 0) /* 1080p to 512x288 */ +TEST_BOXPLANE(By6, 640, 360, 106, 60, 0) /* 720p to 213x120 */ +TEST_BOXPLANE(By8, 640, 360, 80, 45, 0) /* 720p to 160x90 */ +TEST_BOXPLANE(OddTail, 33, 17, 7, 5, 0) /* not a multiple of 8 wide */ +TEST_BOXPLANE(By3OddTail7, 21, 15, 7, 5, 0) /* 3x, dst_width = 7 */ +TEST_BOXPLANE(By3OddTail23, 69, 15, 23, 5, 0) /* 3x, dst_width = 23 */ +TEST_BOXPLANE(By3OddTail47, 141, 15, 47, 5, 0) /* 3x, dst_width = 47 */ +TEST_BOXPLANE(By3OddTail79, 237, 15, 79, 5, 0) /* 3x, dst_width = 79 */ +TEST_BOXPLANE(Tiny, 80, 60, 3, 2, 0) /* dst below one SIMD group */ +#undef TEST_BOXPLANE + +// A box filter has to read the whole box. Every 3x3 block here is 255 except +// for its top left pixel, so point sampling the block origin yields 0 while +// the box average is 8 * 255 * (65536 / 9) >> 16 = 226. +TEST_F(LibYUVScaleTest, UVScaleBoxAverages) { + const int kSrcWidth = 48; + const int kSrcHeight = 24; + const int kDstWidth = kSrcWidth / 3; + const int kDstHeight = kSrcHeight / 3; + align_buffer_page_end(src_uv, kSrcWidth * kSrcHeight * 2); + align_buffer_page_end(dst_uv, kDstWidth * kDstHeight * 2); + + memset(src_uv, 255, kSrcWidth * kSrcHeight * 2); + for (int y = 0; y < kSrcHeight; y += 3) { + for (int x = 0; x < kSrcWidth; x += 3) { + src_uv[(y * kSrcWidth + x) * 2 + 0] = 0; + src_uv[(y * kSrcWidth + x) * 2 + 1] = 0; + } + } + memset(dst_uv, 123, kDstWidth * kDstHeight * 2); + + UVScale(src_uv, kSrcWidth * 2, kSrcWidth, kSrcHeight, dst_uv, kDstWidth * 2, + kDstWidth, kDstHeight, kFilterBox); + + for (int i = 0; i < kDstWidth * kDstHeight * 2; ++i) { + ASSERT_EQ(226, dst_uv[i]) << "at " << i; + } + + free_aligned_buffer_page_end(dst_uv); + free_aligned_buffer_page_end(src_uv); +} + +// Test 16-bit UVScale_16 with C vs Opt and return maximum pixel difference. +static int UVTestFilter_16(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode f, + int benchmark_iterations, + int disable_cpu_flags, + int benchmark_cpu_info) { + if (!SizeValid(src_width, src_height, dst_width, dst_height)) { + return 0; + } + if (src_width <= 0 || src_height == 0 || dst_width <= 0 || dst_height <= 0) { + return 0; + } + + int i; + int64_t src_uv_samples = Abs(src_width) * Abs(src_height) * 2LL; + int src_stride_uv = Abs(src_width) * 2; + int64_t dst_uv_samples = dst_width * dst_height * 2LL; + int dst_stride_uv = dst_width * 2; + + align_buffer_page_end(src_uv_buf, src_uv_samples * 2); + align_buffer_page_end(dst_uv_c_buf, dst_uv_samples * 2); + align_buffer_page_end(dst_uv_opt_buf, dst_uv_samples * 2); + + if (!src_uv_buf || !dst_uv_c_buf || !dst_uv_opt_buf) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + uint16_t* src_uv = reinterpret_cast(src_uv_buf); + uint16_t* dst_uv_c = reinterpret_cast(dst_uv_c_buf); + uint16_t* dst_uv_opt = reinterpret_cast(dst_uv_opt_buf); + + MemRandomize(src_uv_buf, src_uv_samples * 2); + memset(dst_uv_c_buf, 2, dst_uv_samples * 2); + memset(dst_uv_opt_buf, 123, dst_uv_samples * 2); + + MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. + int rc_c = UVScale_16(src_uv, src_stride_uv, src_width, src_height, dst_uv_c, + dst_stride_uv, dst_width, dst_height, f); + if (rc_c != 0) { + free_aligned_buffer_page_end(dst_uv_c_buf); + free_aligned_buffer_page_end(dst_uv_opt_buf); + free_aligned_buffer_page_end(src_uv_buf); + return 65536; + } + + MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. + int rc_opt = 0; + for (i = 0; i < benchmark_iterations; ++i) { + rc_opt |= UVScale_16(src_uv, src_stride_uv, src_width, src_height, + dst_uv_opt, dst_stride_uv, dst_width, dst_height, f); + } + if (rc_opt != 0) { + free_aligned_buffer_page_end(dst_uv_c_buf); + free_aligned_buffer_page_end(dst_uv_opt_buf); + free_aligned_buffer_page_end(src_uv_buf); + return 65536; + } + + int max_diff = 0; + for (i = 0; i < dst_uv_samples; ++i) { + int abs_diff = Abs(static_cast(dst_uv_c[i]) - + static_cast(dst_uv_opt[i])); + if (abs_diff > max_diff) { + max_diff = abs_diff; + } + } + + free_aligned_buffer_page_end(dst_uv_c_buf); + free_aligned_buffer_page_end(dst_uv_opt_buf); + free_aligned_buffer_page_end(src_uv_buf); + return max_diff; +} + +#define DX(x, nom, denom) static_cast((Abs(x) / nom) * nom) +#define SX(x, nom, denom) static_cast((x / nom) * denom) + +#define TEST_FACTOR1_16(name, filter, nom, denom) \ + TEST_F(LibYUVScaleTest, UVScale_16_DownBy##name##_##filter) { \ + int diff = UVTestFilter_16( \ + SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \ + DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \ + kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_EQ(0, diff); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TEST_FACTOR_16(name, nom, denom) \ + TEST_FACTOR1_16(name, None, nom, denom) \ + TEST_FACTOR1_16(name, Linear, nom, denom) \ + TEST_FACTOR1_16(name, Bilinear, nom, denom) \ + TEST_FACTOR1_16(name, Box, nom, denom) +#else +#define TEST_FACTOR_16(name, nom, denom) \ + TEST_FACTOR1_16(name, Bilinear, nom, denom) +#endif + +TEST_FACTOR_16(2, 1, 2) +TEST_FACTOR_16(4, 1, 4) +TEST_FACTOR_16(3by4, 3, 4) +TEST_FACTOR_16(3by8, 3, 8) +TEST_FACTOR_16(3, 1, 3) +#undef TEST_FACTOR1_16 +#undef TEST_FACTOR_16 +#undef SX +#undef DX + +#define TEST_SCALETO1_16(name, width, height, filter, max_diff) \ + TEST_F(LibYUVScaleTest, name##To##width##x##height##_##filter) { \ + int diff = UVTestFilter_16(benchmark_width_, benchmark_height_, width, \ + height, kFilter##filter, benchmark_iterations_, \ + disable_cpu_flags_, benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } \ + TEST_F(LibYUVScaleTest, name##From##width##x##height##_##filter) { \ + int diff = UVTestFilter_16(width, height, Abs(benchmark_width_), \ + Abs(benchmark_height_), kFilter##filter, \ + benchmark_iterations_, disable_cpu_flags_, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff, max_diff); \ + } + +#if defined(ENABLE_FULL_TESTS) +#define TEST_SCALETO_16(name, width, height) \ + TEST_SCALETO1_16(name, width, height, None, 0) \ + TEST_SCALETO1_16(name, width, height, Linear, 0) \ + TEST_SCALETO1_16(name, width, height, Bilinear, 0) +#else +#define TEST_SCALETO_16(name, width, height) \ + TEST_SCALETO1_16(name, width, height, Bilinear, 0) +#endif + +TEST_SCALETO_16(UVScale_16, 1, 1) +TEST_SCALETO_16(UVScale_16, 569, 480) +TEST_SCALETO_16(UVScale_16, 640, 360) +#undef TEST_SCALETO1_16 +#undef TEST_SCALETO_16 + +// Compare UVScale_16 against scaling U and V planes separately with +// ScalePlane_16 across Box, Bilinear, Linear, and None filters. +static int UVTestAgainstPlanes_16(int src_width, + int src_height, + int dst_width, + int dst_height, + FilterMode filtering, + int cpu_info) { + if (!SizeValid(src_width, src_height, dst_width, dst_height)) { + return 0; + } + if (src_width <= 0 || src_height == 0 || dst_width <= 0 || dst_height <= 0) { + return 0; + } + const int abs_src_width = Abs(src_width); + const int abs_src_height = Abs(src_height); + int64_t src_uv_samples = abs_src_width * abs_src_height * 2LL; + int64_t src_plane_samples = abs_src_width * abs_src_height * 1LL; + int64_t dst_uv_samples = dst_width * dst_height * 2LL; + int64_t dst_plane_samples = dst_width * dst_height * 1LL; + + align_buffer_page_end(src_uv_buf, src_uv_samples * 2); + align_buffer_page_end(src_u_buf, src_plane_samples * 2); + align_buffer_page_end(src_v_buf, src_plane_samples * 2); + align_buffer_page_end(dst_uv_buf, dst_uv_samples * 2); + align_buffer_page_end(dst_u_buf, dst_plane_samples * 2); + align_buffer_page_end(dst_v_buf, dst_plane_samples * 2); + if (!src_uv_buf || !src_u_buf || !src_v_buf || !dst_uv_buf || !dst_u_buf || + !dst_v_buf) { + printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); + return 0; + } + uint16_t* src_uv = reinterpret_cast(src_uv_buf); + uint16_t* src_u = reinterpret_cast(src_u_buf); + uint16_t* src_v = reinterpret_cast(src_v_buf); + uint16_t* dst_uv = reinterpret_cast(dst_uv_buf); + uint16_t* dst_u = reinterpret_cast(dst_u_buf); + uint16_t* dst_v = reinterpret_cast(dst_v_buf); + + MemRandomize(src_uv_buf, src_uv_samples * 2); + memset(dst_uv_buf, 123, dst_uv_samples * 2); + for (int i = 0; i < abs_src_width * abs_src_height; ++i) { + src_u[i] = src_uv[i * 2 + 0]; + src_v[i] = src_uv[i * 2 + 1]; + } + + MaskCpuFlags(cpu_info); + int rc_uv = UVScale_16(src_uv, abs_src_width * 2, src_width, src_height, + dst_uv, dst_width * 2, dst_width, dst_height, + filtering); + int rc_u = ScalePlane_16(src_u, abs_src_width, src_width, src_height, dst_u, + dst_width, dst_width, dst_height, filtering); + int rc_v = ScalePlane_16(src_v, abs_src_width, src_width, src_height, dst_v, + dst_width, dst_width, dst_height, filtering); + int max_diff = (rc_uv != 0 || rc_u != 0 || rc_v != 0) ? 65536 : 0; + for (int i = 0; i < dst_width * dst_height; ++i) { + int du = Abs(static_cast(dst_uv[i * 2 + 0]) - + static_cast(dst_u[i])); + int dv = Abs(static_cast(dst_uv[i * 2 + 1]) - + static_cast(dst_v[i])); + if (du > max_diff) { + max_diff = du; + } + if (dv > max_diff) { + max_diff = dv; + } + } + + free_aligned_buffer_page_end(dst_v_buf); + free_aligned_buffer_page_end(dst_u_buf); + free_aligned_buffer_page_end(dst_uv_buf); + free_aligned_buffer_page_end(src_v_buf); + free_aligned_buffer_page_end(src_u_buf); + free_aligned_buffer_page_end(src_uv_buf); + return max_diff; +} + +#define TEST_UVPLANE16(name, swidth, sheight, dwidth, dheight, filter, \ + max_diff) \ + TEST_F(LibYUVScaleTest, UVScale_16_MatchesPlane_##name##_##filter) { \ + int diff_c = UVTestAgainstPlanes_16(swidth, sheight, dwidth, dheight, \ + kFilter##filter, disable_cpu_flags_); \ + ASSERT_LE(diff_c, max_diff); \ + int diff_opt = UVTestAgainstPlanes_16(swidth, sheight, dwidth, dheight, \ + kFilter##filter, \ + benchmark_cpu_info_); \ + ASSERT_LE(diff_opt, max_diff); \ + } + +TEST_UVPLANE16(By2, 480, 270, 240, 135, Box, 0) +TEST_UVPLANE16(By2, 480, 270, 240, 135, Bilinear, 0) +TEST_UVPLANE16(By2, 480, 270, 240, 135, None, 0) +TEST_UVPLANE16(By3, 480, 270, 160, 90, Box, 0) +TEST_UVPLANE16(By3Rounded, 320, 180, 107, 60, Box, 0) +TEST_UVPLANE16(By4, 480, 270, 120, 68, Box, 0) +TEST_UVPLANE16(By4Exact, 480, 272, 120, 68, Box, 1) +TEST_UVPLANE16(By6, 360, 180, 60, 30, Box, 0) +TEST_UVPLANE16(By6, 360, 180, 60, 30, None, 0) +TEST_UVPLANE16(OddTail, 33, 17, 7, 5, Box, 0) +TEST_UVPLANE16(By3OddTail, 69, 15, 23, 5, Box, 0) +TEST_UVPLANE16(DownArbitrary, 113, 71, 47, 29, Bilinear, 0) +TEST_UVPLANE16(DownArbitrary, 113, 71, 47, 29, Linear, 0) +TEST_UVPLANE16(DownArbitrary, 113, 71, 47, 29, None, 0) +TEST_UVPLANE16(Up2x, 37, 23, 74, 46, Bilinear, 0) +TEST_UVPLANE16(Up2x, 37, 23, 74, 46, Linear, 0) +TEST_UVPLANE16(Up2x, 37, 23, 74, 46, None, 0) +TEST_UVPLANE16(UpArbitrary, 37, 23, 91, 59, Bilinear, 0) +TEST_UVPLANE16(UpArbitrary, 37, 23, 91, 59, Linear, 0) +TEST_UVPLANE16(UpArbitrary, 37, 23, 91, 59, None, 0) +TEST_UVPLANE16(VerticalOnlyUp, 41, 19, 41, 53, Bilinear, 0) +TEST_UVPLANE16(VerticalOnlyDown, 41, 53, 41, 19, Bilinear, 0) +TEST_UVPLANE16(InvertCopy, 31, -17, 31, 17, None, 0) +TEST_UVPLANE16(InvertUp, 31, -17, 65, 39, Bilinear, 0) +#undef TEST_UVPLANE16 + +// Verify 2x kFilterLinear downscale averages pairs horizontally on odd rows +// without underflowing into the previous row. +TEST_F(LibYUVScaleTest, UVScale_16_DownBy2_LinearAveragesOddRows) { + const int kSrcWidth = 4; + const int kSrcHeight = 2; + const int kDstWidth = 2; + const int kDstHeight = 1; + uint16_t src_uv[kSrcWidth * kSrcHeight * 2] = { + // Row 0 (even row - must not be read): + 60000, 60000, 60000, 60000, 60000, 60000, 60000, 60000, + // Row 1 (odd row - horizontally averaged in pairs): + 100, 1000, 300, 3000, 500, 5000, 900, 7000, + }; + uint16_t dst_uv[kDstWidth * kDstHeight * 2] = {0}; + + ASSERT_EQ(0, UVScale_16(src_uv, kSrcWidth * 2, kSrcWidth, kSrcHeight, dst_uv, + kDstWidth * 2, kDstWidth, kDstHeight, kFilterLinear)); + EXPECT_EQ(200, dst_uv[0]); + EXPECT_EQ(2000, dst_uv[1]); + EXPECT_EQ(700, dst_uv[2]); + EXPECT_EQ(6000, dst_uv[3]); +} + +} // namespace libyuv diff --git a/libs/libyuv/unit_test/testdata/juno.txt b/libs/libyuv/unit_test/testdata/juno.txt deleted file mode 100644 index dd465272b8..0000000000 --- a/libs/libyuv/unit_test/testdata/juno.txt +++ /dev/null @@ -1,15 +0,0 @@ -Processor : AArch64 Processor rev 0 (aarch64) -processor : 0 -processor : 1 -processor : 2 -processor : 3 -processor : 4 -processor : 5 -Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 -CPU implementer : 0x41 -CPU architecture: AArch64 -CPU variant : 0x0 -CPU part : 0xd07 -CPU revision : 0 - -Hardware : Juno diff --git a/libs/libyuv/unit_test/testdata/mips.txt b/libs/libyuv/unit_test/testdata/mips.txt new file mode 100644 index 0000000000..d9f28cbfcb --- /dev/null +++ b/libs/libyuv/unit_test/testdata/mips.txt @@ -0,0 +1,7 @@ +system type : generic-loongson-machine +machine : loongson,generic +processor : 0 + +isa : mips1 mips2 mips3 mips4 mips5 mips32r1 mips32r2 mips64r1 mips64r2 +ASEs implemented : vz +shadow register sets : 1 diff --git a/libs/libyuv/unit_test/testdata/mips_loongson2k.txt b/libs/libyuv/unit_test/testdata/mips_loongson2k.txt new file mode 100644 index 0000000000..8a88d38f2b --- /dev/null +++ b/libs/libyuv/unit_test/testdata/mips_loongson2k.txt @@ -0,0 +1,5 @@ +system type : Loongson2K-SBC +machine : loongson,LS2k1000-EVP +processor : 0 +cpu model : Loongson-2K V0.3 FPU V0.1 +BogoMIPS : 1980.41 diff --git a/libs/libyuv/unit_test/testdata/mips_loongson3.txt b/libs/libyuv/unit_test/testdata/mips_loongson3.txt new file mode 100644 index 0000000000..1f540b1281 --- /dev/null +++ b/libs/libyuv/unit_test/testdata/mips_loongson3.txt @@ -0,0 +1,10 @@ +system type : generic-loongson-machine +machine : Unknown +processor : 0 +cpu model : ICT Loongson-3 V0.9 FPU V0.1 +model name : ICT Loongson-3A R3 (Loongson-3A3000) @ 1500MHz +BogoMIPS : 2990.15 + +isa : mips1 mips2 mips3 mips4 mips5 mips32r1 mips32r2 mips64r1 mips64r2 +ASEs implemented : dsp dsp2 vz +shadow register sets : 1 diff --git a/libs/libyuv/unit_test/testdata/mips_loongson_mmi.txt b/libs/libyuv/unit_test/testdata/mips_loongson_mmi.txt new file mode 100644 index 0000000000..0f10b8bb2b --- /dev/null +++ b/libs/libyuv/unit_test/testdata/mips_loongson_mmi.txt @@ -0,0 +1,7 @@ +system type : generic-loongson-machine +machine : loongson,generic +processor : 0 + +isa : mips1 mips2 mips3 mips4 mips5 mips32r1 mips32r2 mips64r1 mips64r2 +ASEs implemented : vz loongson-mmi loongson-ext +shadow register sets : 1 diff --git a/libs/libyuv/unit_test/testdata/riscv64.txt b/libs/libyuv/unit_test/testdata/riscv64.txt new file mode 100644 index 0000000000..fbb4200fc4 --- /dev/null +++ b/libs/libyuv/unit_test/testdata/riscv64.txt @@ -0,0 +1,4 @@ +processor : 0 +hart : 1 +isa : rv64imac +mmu : sv48 \ No newline at end of file diff --git a/libs/libyuv/unit_test/testdata/riscv64_rvv.txt b/libs/libyuv/unit_test/testdata/riscv64_rvv.txt new file mode 100644 index 0000000000..af1b3f3667 --- /dev/null +++ b/libs/libyuv/unit_test/testdata/riscv64_rvv.txt @@ -0,0 +1,4 @@ +processor : 0 +hart : 1 +isa : rv64imafdcv +mmu : sv48 \ No newline at end of file diff --git a/libs/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt b/libs/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt new file mode 100644 index 0000000000..c416c1aff4 --- /dev/null +++ b/libs/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt @@ -0,0 +1,4 @@ +processor : 0 +hart : 1 +isa : rv64imafdcv_zfh_zvfh +mmu : sv48 \ No newline at end of file diff --git a/libs/libyuv/unit_test/unit_test.cc b/libs/libyuv/unit_test/unit_test.cc index 2aa9cdaad6..c51b184e4e 100644 --- a/libs/libyuv/unit_test/unit_test.cc +++ b/libs/libyuv/unit_test/unit_test.cc @@ -11,29 +11,58 @@ #include "../unit_test/unit_test.h" #include // For getenv() +#if defined(__hexagon__) +#include +#endif #include -#ifdef LIBYUV_USE_GFLAGS -#include "gflags/gflags.h" +#if defined(__hexagon__) +// Hexagon QuRT sys/mman.h declares mmap/munmap without extern "C", and the +// runtime does not provide them. Emulate anonymous mappings with malloc/free. +__attribute__((nothrow)) void* mmap(void* addr, + size_t length, + int prot, + int flags, + int fd, + off_t offset) { + (void)addr; + (void)prot; + (void)flags; + (void)fd; + (void)offset; + return malloc(length); +} + +__attribute__((nothrow)) int munmap(void* addr, size_t length) { + (void)length; + free(addr); + return 0; +} #endif -#ifdef LIBYUV_USE_BASE_FLAGS -#include "base/commandlineflags.h" + +#ifdef LIBYUV_USE_ABSL_FLAGS +#include "absl/flags/flag.h" +#include "absl/flags/parse.h" #endif #include "libyuv/cpu_id.h" unsigned int fastrand_seed = 0xfb; -#ifdef LIBYUV_USE_GFLAGS -DEFINE_int32(libyuv_width, 0, "width of test image."); -DEFINE_int32(libyuv_height, 0, "height of test image."); -DEFINE_int32(libyuv_repeat, 0, "number of times to repeat test."); -DEFINE_int32(libyuv_flags, 0, "cpu flags for reference code. 1 = C, -1 = SIMD"); -DEFINE_int32(libyuv_cpu_info, - 0, - "cpu flags for benchmark code. 1 = C, -1 = SIMD"); +#ifdef LIBYUV_USE_ABSL_FLAGS +ABSL_FLAG(int32_t, libyuv_width, 0, "width of test image."); +ABSL_FLAG(int32_t, libyuv_height, 0, "height of test image."); +ABSL_FLAG(int32_t, libyuv_repeat, 0, "number of times to repeat test."); +ABSL_FLAG(int32_t, + libyuv_flags, + 0, + "cpu flags for reference code. 1 = C, -1 = SIMD"); +ABSL_FLAG(int32_t, + libyuv_cpu_info, + 0, + "cpu flags for benchmark code. 1 = C, -1 = SIMD"); #else -// Disable command line parameters if gflags disabled. +// Disable command line parameters if absl/flags disabled. static const int32_t FLAGS_libyuv_width = 0; static const int32_t FLAGS_libyuv_height = 0; static const int32_t FLAGS_libyuv_repeat = 0; @@ -41,36 +70,77 @@ static const int32_t FLAGS_libyuv_flags = 0; static const int32_t FLAGS_libyuv_cpu_info = 0; #endif +#ifdef LIBYUV_USE_ABSL_FLAGS +#define LIBYUV_GET_FLAG(f) absl::GetFlag(f) +#else +#define LIBYUV_GET_FLAG(f) f +#endif + // Test environment variable for disabling CPU features. Any non-zero value // to disable. Zero ignored to make it easy to set the variable on/off. #if !defined(__native_client__) && !defined(_M_ARM) -static LIBYUV_BOOL TestEnv(const char* name) { +static bool TestEnv(const char* name) { const char* var = getenv(name); if (var) { if (var[0] != '0') { - return LIBYUV_TRUE; + return true; } } - return LIBYUV_FALSE; + return false; } #else // nacl does not support getenv(). -static LIBYUV_BOOL TestEnv(const char*) { - return LIBYUV_FALSE; +static bool TestEnv(const char*) { + return false; } #endif -int TestCpuEnv(int cpu_info) { +static int TestCpuEnv(int cpu_info) { #if defined(__arm__) || defined(__aarch64__) if (TestEnv("LIBYUV_DISABLE_NEON")) { cpu_info &= ~libyuv::kCpuHasNEON; } #endif -#if defined(__mips__) && defined(__linux__) - if (TestEnv("LIBYUV_DISABLE_MSA")) { - cpu_info &= ~libyuv::kCpuHasMSA; +#if defined(__aarch64__) + if (TestEnv("LIBYUV_DISABLE_NEON_DOTPROD")) { + cpu_info &= ~libyuv::kCpuHasNeonDotProd; } - if (TestEnv("LIBYUV_DISABLE_MMI")) { - cpu_info &= ~libyuv::kCpuHasMMI; + if (TestEnv("LIBYUV_DISABLE_NEON_I8MM")) { + cpu_info &= ~libyuv::kCpuHasNeonI8MM; + } + if (TestEnv("LIBYUV_DISABLE_SVE")) { + cpu_info &= ~libyuv::kCpuHasSVE; + } + if (TestEnv("LIBYUV_DISABLE_SVE2")) { + cpu_info &= ~libyuv::kCpuHasSVE2; + } + if (TestEnv("LIBYUV_DISABLE_SME")) { + cpu_info &= ~libyuv::kCpuHasSME; + } + if (TestEnv("LIBYUV_DISABLE_SME2")) { + cpu_info &= ~libyuv::kCpuHasSME2; + } +#endif +#if defined(__longarch__) && defined(__linux__) + if (TestEnv("LIBYUV_DISABLE_LSX")) { + cpu_info &= ~libyuv::kCpuHasLSX; + } + if (TestEnv("LIBYUV_DISABLE_LASX")) { + cpu_info &= ~libyuv::kCpuHasLASX; + } +#endif +#if defined(__riscv) && defined(__linux__) + if (TestEnv("LIBYUV_DISABLE_RVV")) { + cpu_info &= ~libyuv::kCpuHasRVV; + } +#endif +#if defined(__wasm__) + if (TestEnv("LIBYUV_DISABLE_WASM")) { + cpu_info &= ~libyuv::kCpuHasWASMSIMD; + } +#endif +#if defined(__hexagon__) + if (TestEnv("LIBYUV_DISABLE_HVX")) { + cpu_info &= ~libyuv::kCpuHasHVX; } #endif #if !defined(__pnacl__) && !defined(__CLR_VER) && \ @@ -112,6 +182,9 @@ int TestCpuEnv(int cpu_info) { if (TestEnv("LIBYUV_DISABLE_AVX512VL")) { cpu_info &= ~libyuv::kCpuHasAVX512VL; } + if (TestEnv("LIBYUV_DISABLE_AVX512VNNI")) { + cpu_info &= ~libyuv::kCpuHasAVX512VNNI; + } if (TestEnv("LIBYUV_DISABLE_AVX512VBMI")) { cpu_info &= ~libyuv::kCpuHasAVX512VBMI; } @@ -121,11 +194,26 @@ int TestCpuEnv(int cpu_info) { if (TestEnv("LIBYUV_DISABLE_AVX512VBITALG")) { cpu_info &= ~libyuv::kCpuHasAVX512VBITALG; } - if (TestEnv("LIBYUV_DISABLE_AVX512VPOPCNTDQ")) { - cpu_info &= ~libyuv::kCpuHasAVX512VPOPCNTDQ; + if (TestEnv("LIBYUV_DISABLE_AVX10")) { + cpu_info &= ~libyuv::kCpuHasAVX10; } - if (TestEnv("LIBYUV_DISABLE_GFNI")) { - cpu_info &= ~libyuv::kCpuHasGFNI; + if (TestEnv("LIBYUV_DISABLE_AVX10_2")) { + cpu_info &= ~libyuv::kCpuHasAVX10_2; + } + if (TestEnv("LIBYUV_DISABLE_AVXVNNI")) { + cpu_info &= ~libyuv::kCpuHasAVXVNNI; + } + if (TestEnv("LIBYUV_DISABLE_AVXVNNIINT8")) { + cpu_info &= ~libyuv::kCpuHasAVXVNNIINT8; + } + if (TestEnv("LIBYUV_DISABLE_AMXINT8")) { + cpu_info &= ~libyuv::kCpuHasAMXINT8; + } + if (TestEnv("LIBYUV_DISABLE_AVX512BMM")) { + cpu_info &= ~libyuv::kCpuHasAVX512BMM; + } + if (TestEnv("LIBYUV_DISABLE_AMXTF32")) { + cpu_info &= ~libyuv::kCpuHasAMXTF32; } #endif if (TestEnv("LIBYUV_DISABLE_ASM")) { @@ -148,8 +236,8 @@ LibYUVConvertTest::LibYUVConvertTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -159,29 +247,29 @@ LibYUVConvertTest::LibYUVConvertTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { - benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT + benchmark_cpu_info_ = atoi(cpu_info); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -204,8 +292,8 @@ LibYUVColorTest::LibYUVColorTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -215,29 +303,29 @@ LibYUVColorTest::LibYUVColorTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { - benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT + benchmark_cpu_info_ = atoi(cpu_info); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -260,8 +348,8 @@ LibYUVScaleTest::LibYUVScaleTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -271,29 +359,29 @@ LibYUVScaleTest::LibYUVScaleTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { - benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT + benchmark_cpu_info_ = atoi(cpu_info); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -316,8 +404,8 @@ LibYUVRotateTest::LibYUVRotateTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -327,29 +415,29 @@ LibYUVRotateTest::LibYUVRotateTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { - benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT + benchmark_cpu_info_ = atoi(cpu_info); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -372,8 +460,8 @@ LibYUVPlanarTest::LibYUVPlanarTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -383,29 +471,29 @@ LibYUVPlanarTest::LibYUVPlanarTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { - benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT + benchmark_cpu_info_ = atoi(cpu_info); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -428,8 +516,8 @@ LibYUVBaseTest::LibYUVBaseTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -439,29 +527,29 @@ LibYUVBaseTest::LibYUVBaseTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { - benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT + benchmark_cpu_info_ = atoi(cpu_info); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -484,8 +572,8 @@ LibYUVCompareTest::LibYUVCompareTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -495,29 +583,29 @@ LibYUVCompareTest::LibYUVCompareTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { - benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT + benchmark_cpu_info_ = atoi(cpu_info); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -532,11 +620,8 @@ LibYUVCompareTest::LibYUVCompareTest() int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); -#ifdef LIBYUV_USE_GFLAGS - // AllowCommandLineParsing allows us to ignore flags passed on to us by - // Chromium build bots without having to explicitly disable them. - google::AllowCommandLineReparsing(); - google::ParseCommandLineFlags(&argc, &argv, true); +#ifdef LIBYUV_USE_ABSL_FLAGS + absl::ParseCommandLine(argc, argv); #endif return RUN_ALL_TESTS(); } diff --git a/libs/libyuv/unit_test/unit_test.h b/libs/libyuv/unit_test/unit_test.h index 87907fa160..dd4822c268 100644 --- a/libs/libyuv/unit_test/unit_test.h +++ b/libs/libyuv/unit_test/unit_test.h @@ -11,16 +11,16 @@ #ifndef UNIT_TEST_UNIT_TEST_H_ // NOLINT #define UNIT_TEST_UNIT_TEST_H_ -#ifdef WIN32 +#include // For NULL +#include +#ifdef _WIN32 #include -#else -#include +#elif !defined(__hexagon__) #include #endif -#include - -#include "libyuv/basic_types.h" +// pragma to disable warning for ASSERT_NE +#include // IWYU pragma: export #ifndef SIMD_ALIGNED #if defined(_MSC_VER) && !defined(__CLR_VER) @@ -69,15 +69,53 @@ static inline bool SizeValid(int src_width, return true; } +#ifdef LIBYUV_MSAN +#define align_buffer_page_end(var, size) \ + uint8_t* var = NULL; \ + uint8_t* var##_mem = \ + reinterpret_cast(calloc(1, ((size) + 4095 + 63) & ~4095)); \ + if (var##_mem) \ + var = reinterpret_cast( \ + (intptr_t)(var##_mem + (((size) + 4095 + 63) & ~4095) - (size)) & ~63) +#else #define align_buffer_page_end(var, size) \ + uint8_t* var = NULL; \ uint8_t* var##_mem = \ reinterpret_cast(malloc(((size) + 4095 + 63) & ~4095)); \ - uint8_t* var = reinterpret_cast( \ + if (var##_mem) \ + var = reinterpret_cast( \ (intptr_t)(var##_mem + (((size) + 4095 + 63) & ~4095) - (size)) & ~63) +#endif #define free_aligned_buffer_page_end(var) \ free(var##_mem); \ - var = 0 + var = NULL + +#ifdef LIBYUV_MSAN +#define align_buffer_page_end_16(var, size) \ + uint16_t* var = NULL; \ + uint8_t* var##_mem = \ + reinterpret_cast(calloc(1, ((size) * 2 + 4095 + 63) & ~4095)); \ + if (var##_mem) \ + var = reinterpret_cast( \ + (intptr_t)(var##_mem + (((size) * 2 + 4095 + 63) & ~4095) - \ + (size) * 2) & \ + ~63) +#else +#define align_buffer_page_end_16(var, size) \ + uint16_t* var = NULL; \ + uint8_t* var##_mem = \ + reinterpret_cast(malloc(((size) * 2 + 4095 + 63) & ~4095)); \ + if (var##_mem) \ + var = reinterpret_cast( \ + (intptr_t)(var##_mem + (((size) * 2 + 4095 + 63) & ~4095) - \ + (size) * 2) & \ + ~63) +#endif + +#define free_aligned_buffer_page_end_16(var) \ + free(var##_mem); \ + var = NULL #ifdef WIN32 static inline double get_time() { @@ -86,6 +124,10 @@ static inline double get_time() { QueryPerformanceFrequency(&f); return static_cast(t.QuadPart) / static_cast(f.QuadPart); } +#elif defined(__hexagon__) +static inline double get_time() { + return 0.; +} #else static inline double get_time() { struct timeval t; @@ -111,10 +153,13 @@ inline int fastrand() { return static_cast((fastrand_seed >> 16) & 0xffff); } +// ubsan fails if dst is unaligned unless we use uint8 static inline void MemRandomize(uint8_t* dst, int64_t len) { int64_t i; for (i = 0; i < len - 1; i += 2) { - *reinterpret_cast(dst) = fastrand(); + int r = fastrand(); + dst[0] = static_cast(r); + dst[1] = static_cast(r >> 8); dst += 2; } for (; i < len; ++i) { diff --git a/libs/libyuv/unit_test/video_common_test.cc b/libs/libyuv/unit_test/video_common_test.cc index a84206a2ad..ca91246b64 100644 --- a/libs/libyuv/unit_test/video_common_test.cc +++ b/libs/libyuv/unit_test/video_common_test.cc @@ -29,77 +29,87 @@ static bool TestValidFourCC(uint32_t fourcc, int bpp) { !TestValidChar((fourcc >> 24) & 0xff)) { return false; } - if (bpp < 0 || bpp > 32) { + if (bpp < 0 || bpp > 64) { return false; } return true; } TEST_F(LibYUVBaseTest, TestCanonicalFourCC) { - EXPECT_EQ(static_cast(FOURCC_I420), CanonicalFourCC(FOURCC_IYUV)); - EXPECT_EQ(static_cast(FOURCC_I420), CanonicalFourCC(FOURCC_YU12)); - EXPECT_EQ(static_cast(FOURCC_I422), CanonicalFourCC(FOURCC_YU16)); - EXPECT_EQ(static_cast(FOURCC_I444), CanonicalFourCC(FOURCC_YU24)); - EXPECT_EQ(static_cast(FOURCC_YUY2), CanonicalFourCC(FOURCC_YUYV)); - EXPECT_EQ(static_cast(FOURCC_YUY2), CanonicalFourCC(FOURCC_YUVS)); - EXPECT_EQ(static_cast(FOURCC_UYVY), CanonicalFourCC(FOURCC_HDYC)); - EXPECT_EQ(static_cast(FOURCC_UYVY), CanonicalFourCC(FOURCC_2VUY)); - EXPECT_EQ(static_cast(FOURCC_MJPG), CanonicalFourCC(FOURCC_JPEG)); - EXPECT_EQ(static_cast(FOURCC_MJPG), CanonicalFourCC(FOURCC_DMB1)); - EXPECT_EQ(static_cast(FOURCC_RAW), CanonicalFourCC(FOURCC_RGB3)); - EXPECT_EQ(static_cast(FOURCC_24BG), CanonicalFourCC(FOURCC_BGR3)); - EXPECT_EQ(static_cast(FOURCC_BGRA), CanonicalFourCC(FOURCC_CM32)); - EXPECT_EQ(static_cast(FOURCC_RAW), CanonicalFourCC(FOURCC_CM24)); - EXPECT_EQ(static_cast(FOURCC_RGBO), CanonicalFourCC(FOURCC_L555)); - EXPECT_EQ(static_cast(FOURCC_RGBP), CanonicalFourCC(FOURCC_L565)); - EXPECT_EQ(static_cast(FOURCC_RGBO), CanonicalFourCC(FOURCC_5551)); + ASSERT_EQ(static_cast(FOURCC_I420), CanonicalFourCC(FOURCC_IYUV)); + ASSERT_EQ(static_cast(FOURCC_I420), CanonicalFourCC(FOURCC_YU12)); + ASSERT_EQ(static_cast(FOURCC_I422), CanonicalFourCC(FOURCC_YU16)); + ASSERT_EQ(static_cast(FOURCC_I444), CanonicalFourCC(FOURCC_YU24)); + ASSERT_EQ(static_cast(FOURCC_YUY2), CanonicalFourCC(FOURCC_YUYV)); + ASSERT_EQ(static_cast(FOURCC_YUY2), CanonicalFourCC(FOURCC_YUVS)); + ASSERT_EQ(static_cast(FOURCC_UYVY), CanonicalFourCC(FOURCC_HDYC)); + ASSERT_EQ(static_cast(FOURCC_UYVY), CanonicalFourCC(FOURCC_2VUY)); + ASSERT_EQ(static_cast(FOURCC_MJPG), CanonicalFourCC(FOURCC_JPEG)); + ASSERT_EQ(static_cast(FOURCC_MJPG), CanonicalFourCC(FOURCC_DMB1)); + ASSERT_EQ(static_cast(FOURCC_RAW), CanonicalFourCC(FOURCC_RGB3)); + ASSERT_EQ(static_cast(FOURCC_24BG), CanonicalFourCC(FOURCC_BGR3)); + ASSERT_EQ(static_cast(FOURCC_BGRA), CanonicalFourCC(FOURCC_CM32)); + ASSERT_EQ(static_cast(FOURCC_RAW), CanonicalFourCC(FOURCC_CM24)); + ASSERT_EQ(static_cast(FOURCC_RGBO), CanonicalFourCC(FOURCC_L555)); + ASSERT_EQ(static_cast(FOURCC_RGBP), CanonicalFourCC(FOURCC_L565)); + ASSERT_EQ(static_cast(FOURCC_RGBO), CanonicalFourCC(FOURCC_5551)); } TEST_F(LibYUVBaseTest, TestFourCC) { - EXPECT_TRUE(TestValidFourCC(FOURCC_I420, FOURCC_BPP_I420)); - EXPECT_TRUE(TestValidFourCC(FOURCC_I420, FOURCC_BPP_I420)); - EXPECT_TRUE(TestValidFourCC(FOURCC_I422, FOURCC_BPP_I422)); - EXPECT_TRUE(TestValidFourCC(FOURCC_I444, FOURCC_BPP_I444)); - EXPECT_TRUE(TestValidFourCC(FOURCC_I400, FOURCC_BPP_I400)); - EXPECT_TRUE(TestValidFourCC(FOURCC_NV21, FOURCC_BPP_NV21)); - EXPECT_TRUE(TestValidFourCC(FOURCC_NV12, FOURCC_BPP_NV12)); - EXPECT_TRUE(TestValidFourCC(FOURCC_YUY2, FOURCC_BPP_YUY2)); - EXPECT_TRUE(TestValidFourCC(FOURCC_UYVY, FOURCC_BPP_UYVY)); - EXPECT_TRUE(TestValidFourCC(FOURCC_M420, FOURCC_BPP_M420)); - EXPECT_TRUE(TestValidFourCC(FOURCC_Q420, FOURCC_BPP_Q420)); // deprecated. - EXPECT_TRUE(TestValidFourCC(FOURCC_ARGB, FOURCC_BPP_ARGB)); - EXPECT_TRUE(TestValidFourCC(FOURCC_BGRA, FOURCC_BPP_BGRA)); - EXPECT_TRUE(TestValidFourCC(FOURCC_ABGR, FOURCC_BPP_ABGR)); - EXPECT_TRUE(TestValidFourCC(FOURCC_AR30, FOURCC_BPP_AR30)); - EXPECT_TRUE(TestValidFourCC(FOURCC_AB30, FOURCC_BPP_AB30)); - EXPECT_TRUE(TestValidFourCC(FOURCC_24BG, FOURCC_BPP_24BG)); - EXPECT_TRUE(TestValidFourCC(FOURCC_RAW, FOURCC_BPP_RAW)); - EXPECT_TRUE(TestValidFourCC(FOURCC_RGBA, FOURCC_BPP_RGBA)); - EXPECT_TRUE(TestValidFourCC(FOURCC_RGBP, FOURCC_BPP_RGBP)); - EXPECT_TRUE(TestValidFourCC(FOURCC_RGBO, FOURCC_BPP_RGBO)); - EXPECT_TRUE(TestValidFourCC(FOURCC_R444, FOURCC_BPP_R444)); - EXPECT_TRUE(TestValidFourCC(FOURCC_H420, FOURCC_BPP_H420)); - EXPECT_TRUE(TestValidFourCC(FOURCC_H422, FOURCC_BPP_H422)); - EXPECT_TRUE(TestValidFourCC(FOURCC_H010, FOURCC_BPP_H010)); - EXPECT_TRUE(TestValidFourCC(FOURCC_MJPG, FOURCC_BPP_MJPG)); - EXPECT_TRUE(TestValidFourCC(FOURCC_YV12, FOURCC_BPP_YV12)); - EXPECT_TRUE(TestValidFourCC(FOURCC_YV16, FOURCC_BPP_YV16)); - EXPECT_TRUE(TestValidFourCC(FOURCC_YV24, FOURCC_BPP_YV24)); - EXPECT_TRUE(TestValidFourCC(FOURCC_YU12, FOURCC_BPP_YU12)); - EXPECT_TRUE(TestValidFourCC(FOURCC_IYUV, FOURCC_BPP_IYUV)); - EXPECT_TRUE(TestValidFourCC(FOURCC_YU16, FOURCC_BPP_YU16)); - EXPECT_TRUE(TestValidFourCC(FOURCC_YU24, FOURCC_BPP_YU24)); - EXPECT_TRUE(TestValidFourCC(FOURCC_YUYV, FOURCC_BPP_YUYV)); - EXPECT_TRUE(TestValidFourCC(FOURCC_YUVS, FOURCC_BPP_YUVS)); - EXPECT_TRUE(TestValidFourCC(FOURCC_HDYC, FOURCC_BPP_HDYC)); - EXPECT_TRUE(TestValidFourCC(FOURCC_2VUY, FOURCC_BPP_2VUY)); - EXPECT_TRUE(TestValidFourCC(FOURCC_JPEG, FOURCC_BPP_JPEG)); - EXPECT_TRUE(TestValidFourCC(FOURCC_DMB1, FOURCC_BPP_DMB1)); - EXPECT_TRUE(TestValidFourCC(FOURCC_BA81, FOURCC_BPP_BA81)); - EXPECT_TRUE(TestValidFourCC(FOURCC_RGB3, FOURCC_BPP_RGB3)); - EXPECT_TRUE(TestValidFourCC(FOURCC_BGR3, FOURCC_BPP_BGR3)); - EXPECT_TRUE(TestValidFourCC(FOURCC_H264, FOURCC_BPP_H264)); - EXPECT_TRUE(TestValidFourCC(FOURCC_ANY, FOURCC_BPP_ANY)); + ASSERT_TRUE(TestValidFourCC(FOURCC_I420, FOURCC_BPP_I420)); + ASSERT_TRUE(TestValidFourCC(FOURCC_I420, FOURCC_BPP_I420)); + ASSERT_TRUE(TestValidFourCC(FOURCC_I422, FOURCC_BPP_I422)); + ASSERT_TRUE(TestValidFourCC(FOURCC_I444, FOURCC_BPP_I444)); + ASSERT_TRUE(TestValidFourCC(FOURCC_I400, FOURCC_BPP_I400)); + ASSERT_TRUE(TestValidFourCC(FOURCC_NV21, FOURCC_BPP_NV21)); + ASSERT_TRUE(TestValidFourCC(FOURCC_NV12, FOURCC_BPP_NV12)); + ASSERT_TRUE(TestValidFourCC(FOURCC_NV16, FOURCC_BPP_NV16)); + ASSERT_TRUE(TestValidFourCC(FOURCC_NV24, FOURCC_BPP_NV24)); + ASSERT_TRUE(TestValidFourCC(FOURCC_YUY2, FOURCC_BPP_YUY2)); + ASSERT_TRUE(TestValidFourCC(FOURCC_UYVY, FOURCC_BPP_UYVY)); + ASSERT_TRUE(TestValidFourCC(FOURCC_M420, FOURCC_BPP_M420)); // deprecated. + ASSERT_TRUE(TestValidFourCC(FOURCC_Q420, FOURCC_BPP_Q420)); // deprecated. + ASSERT_TRUE(TestValidFourCC(FOURCC_ARGB, FOURCC_BPP_ARGB)); + ASSERT_TRUE(TestValidFourCC(FOURCC_BGRA, FOURCC_BPP_BGRA)); + ASSERT_TRUE(TestValidFourCC(FOURCC_ABGR, FOURCC_BPP_ABGR)); + ASSERT_TRUE(TestValidFourCC(FOURCC_AR30, FOURCC_BPP_AR30)); + ASSERT_TRUE(TestValidFourCC(FOURCC_AB30, FOURCC_BPP_AB30)); + ASSERT_TRUE(TestValidFourCC(FOURCC_AR64, FOURCC_BPP_AR64)); + ASSERT_TRUE(TestValidFourCC(FOURCC_AB64, FOURCC_BPP_AB64)); + ASSERT_TRUE(TestValidFourCC(FOURCC_24BG, FOURCC_BPP_24BG)); + ASSERT_TRUE(TestValidFourCC(FOURCC_RAW, FOURCC_BPP_RAW)); + ASSERT_TRUE(TestValidFourCC(FOURCC_RGBA, FOURCC_BPP_RGBA)); + ASSERT_TRUE(TestValidFourCC(FOURCC_RGBP, FOURCC_BPP_RGBP)); + ASSERT_TRUE(TestValidFourCC(FOURCC_RGBO, FOURCC_BPP_RGBO)); + ASSERT_TRUE(TestValidFourCC(FOURCC_R444, FOURCC_BPP_R444)); + ASSERT_TRUE(TestValidFourCC(FOURCC_H420, FOURCC_BPP_H420)); + ASSERT_TRUE(TestValidFourCC(FOURCC_H422, FOURCC_BPP_H422)); + ASSERT_TRUE(TestValidFourCC(FOURCC_H010, FOURCC_BPP_H010)); + ASSERT_TRUE(TestValidFourCC(FOURCC_H210, FOURCC_BPP_H210)); + ASSERT_TRUE(TestValidFourCC(FOURCC_I010, FOURCC_BPP_I010)); + ASSERT_TRUE(TestValidFourCC(FOURCC_I210, FOURCC_BPP_I210)); + ASSERT_TRUE(TestValidFourCC(FOURCC_P010, FOURCC_BPP_P010)); + ASSERT_TRUE(TestValidFourCC(FOURCC_P210, FOURCC_BPP_P210)); + ASSERT_TRUE(TestValidFourCC(FOURCC_P410, FOURCC_BPP_P410)); + ASSERT_TRUE(TestValidFourCC(FOURCC_MJPG, FOURCC_BPP_MJPG)); + ASSERT_TRUE(TestValidFourCC(FOURCC_YV12, FOURCC_BPP_YV12)); + ASSERT_TRUE(TestValidFourCC(FOURCC_YV16, FOURCC_BPP_YV16)); + ASSERT_TRUE(TestValidFourCC(FOURCC_YV24, FOURCC_BPP_YV24)); + ASSERT_TRUE(TestValidFourCC(FOURCC_YU12, FOURCC_BPP_YU12)); + ASSERT_TRUE(TestValidFourCC(FOURCC_IYUV, FOURCC_BPP_IYUV)); + ASSERT_TRUE(TestValidFourCC(FOURCC_YU16, FOURCC_BPP_YU16)); + ASSERT_TRUE(TestValidFourCC(FOURCC_YU24, FOURCC_BPP_YU24)); + ASSERT_TRUE(TestValidFourCC(FOURCC_YUYV, FOURCC_BPP_YUYV)); + ASSERT_TRUE(TestValidFourCC(FOURCC_YUVS, FOURCC_BPP_YUVS)); + ASSERT_TRUE(TestValidFourCC(FOURCC_HDYC, FOURCC_BPP_HDYC)); + ASSERT_TRUE(TestValidFourCC(FOURCC_2VUY, FOURCC_BPP_2VUY)); + ASSERT_TRUE(TestValidFourCC(FOURCC_JPEG, FOURCC_BPP_JPEG)); + ASSERT_TRUE(TestValidFourCC(FOURCC_DMB1, FOURCC_BPP_DMB1)); + ASSERT_TRUE(TestValidFourCC(FOURCC_BA81, FOURCC_BPP_BA81)); + ASSERT_TRUE(TestValidFourCC(FOURCC_RGB3, FOURCC_BPP_RGB3)); + ASSERT_TRUE(TestValidFourCC(FOURCC_BGR3, FOURCC_BPP_BGR3)); + ASSERT_TRUE(TestValidFourCC(FOURCC_H264, FOURCC_BPP_H264)); + ASSERT_TRUE(TestValidFourCC(FOURCC_ANY, FOURCC_BPP_ANY)); } } // namespace libyuv diff --git a/libs/libyuv/util/color.cc b/libs/libyuv/util/color.cc new file mode 100644 index 0000000000..8c3bbefd27 --- /dev/null +++ b/libs/libyuv/util/color.cc @@ -0,0 +1,120 @@ +/* + * Copyright 2021 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include + +// This utility computes values needed to generate yuvconstants based on +// white point values. +// The yuv formulas are tuned for 8 bit YUV channels. + +// For those MCs that can be represented as kr and kb: +// Full range +// float M[3][3] +// {{1,0,2*(1-kr)},{1,-((2*kb)/((2-kb)*(1-kb-kr))),-((2*kr)/((2-kr)*(1-kb-kr)))},{1,2*(1-kb),0}}; +// float B[3] +// {1+(256*(1-kr))/255,1-(256*kb)/(255*(2-kb)*(1-kb-kr))-(256*kr)/(255*(2-kr)*(1-kb-kr)),1+(256*(1-kb))/255}; +// Limited range +// float M[3][3] +// {{85/73,0,255/112-(255*kr)/112},{85/73,-((255*kb)/(112*(2-kb)*(1-kb-kr))),-((255*kr)/(112*(2-kr)*(1-kb-kr)))},{85/73,255/112-(255*kb)/112,0}}; +// float B[3] +// {77662/43435-(1537*kr)/1785,203/219-(1537*kb)/(1785*(2-kb)*(1-kb-kr))-(1537*kr)/(1785*(2-kr)*(1-kb-kr)),77662/43435-(1537*kb)/1785}; + +// mc bt +// 1 bt.709 KR = 0.2126; KB = 0.0722 +// 4 fcc KR = 0.30; KB = 0.11 +// 6 bt.601 KR = 0.299; KB = 0.114 +// 7 SMPTE 240M KR = 0.212; KB = 0.087 +// 10 bt2020 KR = 0.2627; KB = 0.0593 + +// BT.709 full range YUV to RGB reference +// R = Y + V * 1.5748 +// G = Y - U * 0.18732 - V * 0.46812 +// B = Y + U * 1.8556 +// KR = 0.2126 +// KB = 0.0722 + +// https://mymusing.co/bt601-yuv-to-rgb-conversion-color/ + +// // Y contribution to R,G,B. Scale and bias. +// #define YG 16320 /* round(1.000 * 64 * 256 * 256 / 257) */ +// #define YB 32 /* 64 / 2 */ +// +// // U and V contributions to R,G,B. +// #define UB 113 /* round(1.77200 * 64) */ +// #define UG 22 /* round(0.34414 * 64) */ +// #define VG 46 /* round(0.71414 * 64) */ +// #define VR 90 /* round(1.40200 * 64) */ +// +// // Bias values to round, and subtract 128 from U and V. +// #define BB (-UB * 128 + YB) +// #define BG (UG * 128 + VG * 128 + YB) +// #define BR (-VR * 128 + YB) + +int round(float v) { + return (int)(v + 0.5); +} + +int main(int argc, const char* argv[]) { + if (argc < 2) { + printf("color kr kb\n"); + return -1; + } + float kr = atof(argv[1]); + float kb = atof(argv[2]); + float kg = 1 - kr - kb; + + float vr = 2 * (1 - kr); + float ug = 2 * ((1 - kb) * kb / kg); + float vg = 2 * ((1 - kr) * kr / kg); + float ub = 2 * (1 - kb); + + printf("Full range\n"); + printf("R = Y + V * %5f\n", vr); + printf("G = Y - U * %6f - V * %6f\n", ug, vg); + printf("B = Y + U * %5f\n", ub); + + printf("KR = %4f; ", kr); + printf("KB = %4f\n", kb); + // printf("KG = %4f\n", kg); + // #define YG 16320 /* round(1.000 * 64 * 256 * 256 / 257) */ + // #define YB 32 /* 64 / 2 */ + // + // // U and V contributions to R,G,B. + + printf("UB %-3d /* round(%f * 64) */\n", round(ub * 64), ub); + printf("UG %-3d /* round(%f * 64) */\n", round(ug * 64), ug); + printf("VG %-3d /* round(%f * 64) */\n", round(vg * 64), vg); + printf("VR %-3d /* round(%f * 64) */\n", round(vr * 64), vr); + + vr = 255.f / 224.f * 2 * (1 - kr); + ug = 255.f / 224.f * 2 * ((1 - kb) * kb / kg); + vg = 255.f / 224.f * 2 * ((1 - kr) * kr / kg); + ub = 255.f / 224.f * 2 * (1 - kb); + + printf("Limited range\n"); + printf("R = (Y - 16) * 1.164 + V * %5f\n", vr); + printf("G = (Y - 16) * 1.164 - U * %6f - V * %6f\n", ug, vg); + printf("B = (Y - 16) * 1.164 + U * %5f\n", ub); + + // printf("KG = %4f\n", kg); + // #define YG 16320 /* round(1.000 * 64 * 256 * 256 / 257) */ + // #define YB 32 /* 64 / 2 */ + // + // // U and V contributions to R,G,B. + + printf("UB %-3d /* round(%f * 64) */\n", round(ub * 64), ub); + printf("UG %-3d /* round(%f * 64) */\n", round(ug * 64), ug); + printf("VG %-3d /* round(%f * 64) */\n", round(vg * 64), vg); + printf("VR %-3d /* round(%f * 64) */\n", round(vr * 64), vr); + + return 0; +} diff --git a/libs/libyuv/util/compare.cc b/libs/libyuv/util/compare.cc index a16613ee2f..4ed933a1db 100644 --- a/libs/libyuv/util/compare.cc +++ b/libs/libyuv/util/compare.cc @@ -13,55 +13,129 @@ #include #include -#include "libyuv/basic_types.h" #include "libyuv/compare.h" #include "libyuv/version.h" +static bool ExtractResolutionFromFilename(const char* name, + int* width_ptr, + int* height_ptr) { + for (int i = 0; name[i]; ++i) { + if ((name[i] == '.' || name[i] == '_') && name[i + 1] >= '0' && + name[i + 1] <= '9') { + int n = sscanf(name + i + 1, "%dx%d", width_ptr, height_ptr); // NOLINT + if (2 == n) { + return true; + } + } + } + return false; +} + int main(int argc, char** argv) { - if (argc < 1) { + const char* name1 = NULL; + const char* name2 = NULL; + int width = 0; + int height = 0; + + for (int i = 1; i < argc; ++i) { + if (!strcmp(argv[i], "-s") && i + 2 < argc) { + width = atoi(argv[++i]); // NOLINT + height = atoi(argv[++i]); // NOLINT + } else if (!name1) { + name1 = argv[i]; + } else if (!name2) { + name2 = argv[i]; + } else if (width == 0 && i + 1 < argc) { + width = atoi(argv[i]); // NOLINT + height = atoi(argv[++i]); // NOLINT + } + } + + if (!name1) { printf("libyuv compare v%d\n", LIBYUV_VERSION); - printf("compare file1.yuv file2.yuv\n"); + printf("compare file1.yuv [file2.yuv [width height]]\n"); return -1; } - char* name1 = argv[1]; - char* name2 = (argc > 2) ? argv[2] : NULL; - FILE* fin1 = fopen(name1, "rb"); - FILE* fin2 = name2 ? fopen(name2, "rb") : NULL; - const int kBlockSize = 32768; - uint8_t buf1[kBlockSize]; - uint8_t buf2[kBlockSize]; + if (width <= 0 || height <= 0) { + if (!ExtractResolutionFromFilename(name1, &width, &height) && name2) { + ExtractResolutionFromFilename(name2, &width, &height); + } + } + + FILE* fin1 = fopen(name1, "rb"); + if (!fin1) { + fprintf(stderr, "Cannot open %s\n", name1); + return -1; + } + FILE* fin2 = name2 ? fopen(name2, "rb") : NULL; + if (name2 && !fin2) { + fprintf(stderr, "Cannot open %s\n", name2); + fclose(fin1); + return -1; + } + + const bool has_dims = (width >= 16 && height >= 16); + const int block_width = has_dims ? width : 256; + const int y_size = has_dims ? width * height : 32768; + const int uv_width = (width + 1) / 2; + const int uv_height = (height + 1) / 2; + const int uv_size = has_dims ? uv_width * uv_height : 0; + const int block_size = has_dims ? (y_size + 2 * uv_size) : 32768; + + uint8_t* buf1 = static_cast(malloc(block_size)); + uint8_t* buf2 = static_cast(malloc(block_size)); uint32_t hash1 = 5381; uint32_t hash2 = 5381; uint64_t sum_square_err = 0; uint64_t size_min = 0; + double ssim_sum = 0.0; + int ssim_count = 0; int amt1 = 0; int amt2 = 0; do { - amt1 = static_cast(fread(buf1, 1, kBlockSize, fin1)); + amt1 = static_cast(fread(buf1, 1, block_size, fin1)); if (amt1 > 0) { hash1 = libyuv::HashDjb2(buf1, amt1, hash1); } if (fin2) { - amt2 = static_cast(fread(buf2, 1, kBlockSize, fin2)); + amt2 = static_cast(fread(buf2, 1, block_size, fin2)); if (amt2 > 0) { hash2 = libyuv::HashDjb2(buf2, amt2, hash2); } int amt_min = (amt1 < amt2) ? amt1 : amt2; size_min += amt_min; sum_square_err += libyuv::ComputeSumSquareError(buf1, buf2, amt_min); + if (has_dims && amt_min == block_size) { + ssim_sum += libyuv::I420Ssim( + buf1, width, buf1 + y_size, uv_width, buf1 + y_size + uv_size, + uv_width, buf2, width, buf2 + y_size, uv_width, + buf2 + y_size + uv_size, uv_width, width, height); + ++ssim_count; + } else if (amt_min >= block_width * 8) { + ssim_sum += libyuv::CalcFrameSsim(buf1, block_width, buf2, block_width, + block_width, amt_min / block_width); + ++ssim_count; + } } } while (amt1 > 0 || amt2 > 0); printf("hash1 %x", hash1); if (fin2) { printf(", hash2 %x", hash2); - double mse = - static_cast(sum_square_err) / static_cast(size_min); + double mse = (size_min > 0) ? static_cast(sum_square_err) / + static_cast(size_min) + : 0.0; printf(", mse %.2f", mse); double psnr = libyuv::SumSquareErrorToPsnr(sum_square_err, size_min); - printf(", psnr %.2f\n", psnr); + printf(", psnr %.2f", psnr); + double ssim = (ssim_count > 0) ? (ssim_sum / ssim_count) : 0.0; + printf(", ssim %.6f", ssim); fclose(fin2); } + printf("\n"); fclose(fin1); + free(buf1); + free(buf2); + return 0; } diff --git a/libs/libyuv/util/cpuid.c b/libs/libyuv/util/cpuid.c index 84c0602287..d855952970 100644 --- a/libs/libyuv/util/cpuid.c +++ b/libs/libyuv/util/cpuid.c @@ -12,21 +12,157 @@ #include #include -#define INCLUDE_LIBYUV_COMPARE_H_ -#include "libyuv.h" -#include "./psnr.h" -#include "./ssim.h" +#ifdef __linux__ +#include +#include +#include +#include +#endif + +#include "libyuv/cpu_id.h" + +#ifdef __cplusplus +using namespace libyuv; +#endif + +#ifdef __linux__ +static void KernelVersion(int* version) { + struct utsname buffer; + int i = 0; + + version[0] = version[1] = 0; + if (uname(&buffer) == 0) { + char* v = buffer.release; + for (i = 0; *v && i < 2; ++v) { + if (isdigit(*v)) { + version[i++] = (int)strtol(v, &v, 10); + } + } + } +} +#endif + +#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__)) +static sigjmp_buf vdpphps_jmpbuf; +static void vdpphps_sigill_handler(int sig) { + (void)sig; + siglongjmp(vdpphps_jmpbuf, 1); +} +#endif int main(int argc, const char* argv[]) { - int cpu_flags = TestCpuFlag(-1); - int has_arm = TestCpuFlag(kCpuHasARM); - int has_mips = TestCpuFlag(kCpuHasMIPS); - int has_x86 = TestCpuFlag(kCpuHasX86); (void)argc; (void)argv; -#if defined(__i386__) || defined(__x86_64__) || \ - defined(_M_IX86) || defined(_M_X64) +#if defined(__linux__) + { + int kernelversion[2]; + KernelVersion(kernelversion); + printf("Kernel Version %d.%d\n", kernelversion[0], kernelversion[1]); + } +#endif // defined(__linux__) + +#if defined(__arm__) || defined(__aarch64__) + int has_arm = TestCpuFlag(kCpuHasARM); + if (has_arm) { + int has_neon = TestCpuFlag(kCpuHasNEON); + int has_neon_dotprod = TestCpuFlag(kCpuHasNeonDotProd); + int has_neon_i8mm = TestCpuFlag(kCpuHasNeonI8MM); + int has_sve = TestCpuFlag(kCpuHasSVE); + int has_sve2 = TestCpuFlag(kCpuHasSVE2); + int has_sve_f32mm = TestCpuFlag(kCpuHasSVEF32MM); + int has_sme = TestCpuFlag(kCpuHasSME); + int has_sme2 = TestCpuFlag(kCpuHasSME2); + printf("Has Arm 0x%x\n", has_arm); + printf("Has Neon 0x%x\n", has_neon); + printf("Has Neon DotProd 0x%x\n", has_neon_dotprod); + printf("Has Neon I8MM 0x%x\n", has_neon_i8mm); + printf("Has SVE 0x%x\n", has_sve); + printf("Has SVE2 0x%x\n", has_sve2); + printf("Has SVE F32MM 0x%x\n", has_sve_f32mm); + printf("Has SME 0x%x\n", has_sme); + printf("Has SME2 0x%x\n", has_sme2); + +#if __aarch64__ + // Read and print the SVE and SME vector lengths. + if (has_sve) { + int sve_vl; + __asm__( + ".inst 0x04bf5020 \n" // rdvl x0, #1 + "mov %w[sve_vl], w0 \n" + : [sve_vl] "=r"(sve_vl) // %[sve_vl] + : + : "x0"); + printf("SVE vector length: %d bytes\n", sve_vl); + } + if (has_sme) { + int sme_vl; + __asm__( + ".inst 0x04bf5820 \n" // rdsvl x0, #1 + "mov %w[sme_vl], w0 \n" + : [sme_vl] "=r"(sme_vl) // %[sme_vl] + : + : "x0"); + printf("SME vector length: %d bytes\n", sme_vl); + } +#endif // defined(__aarch64__) + } +#endif // if defined(__arm__) || defined(__aarch64__) + +#if defined(__riscv) + int has_riscv = TestCpuFlag(kCpuHasRISCV); + if (has_riscv) { + int has_rvv = TestCpuFlag(kCpuHasRVV); + printf("Has RISCV 0x%x\n", has_riscv); + printf("Has RVV 0x%x\n", has_rvv); + + // Read and print the RVV vector length. + if (has_rvv) { + register uint32_t vlenb __asm__("t0"); + __asm__(".word 0xC22022F3" /* CSRR t0, vlenb */ : "=r"(vlenb)); + printf("RVV vector length: %d bytes\n", vlenb); + } + } +#endif // defined(__riscv) + +#if defined(__loongarch__) + int has_loongarch = TestCpuFlag(kCpuHasLOONGARCH); + if (has_loongarch) { + int has_lsx = TestCpuFlag(kCpuHasLSX); + int has_lasx = TestCpuFlag(kCpuHasLASX); + printf("Has LOONGARCH 0x%x\n", has_loongarch); + printf("Has LSX 0x%x\n", has_lsx); + printf("Has LASX 0x%x\n", has_lasx); + } +#endif // defined(__loongarch__) + +#if defined(__wasm__) + int has_wasm = TestCpuFlag(kCpuHasWASM); + if (has_wasm) { + int has_wasm_simd = TestCpuFlag(kCpuHasWASMSIMD); + printf("Has WASM 0x%x\n", has_wasm); + printf("Has WASM SIMD 0x%x\n", has_wasm_simd); + } +#endif // defined(__wasm__) + +#if defined(__hexagon__) + int has_hexagon = TestCpuFlag(kCpuHasHexagon); + if (has_hexagon) { + int has_hvx = TestCpuFlag(kCpuHasHVX); + printf("Has Hexagon 0x%x\n", has_hexagon); + printf("Has HVX 0x%x\n", has_hvx); +#if defined(__HVX_ARCH__) + printf("HVX arch: v%d\n", __HVX_ARCH__); +#endif +#if defined(__HVX_LENGTH__) + printf("HVX vector length: %d bytes\n", __HVX_LENGTH__); +#endif + } +#endif // defined(__hexagon__) + +#if defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || \ + defined(_M_X64) + int has_x86 = TestCpuFlag(kCpuHasX86); if (has_x86) { int family, model, cpu_info[4]; // Vendor ID: @@ -56,25 +192,9 @@ int main(int argc, const char* argv[]) { CpuId(1, 0, &cpu_info[0]); family = ((cpu_info[0] >> 8) & 0x0f) | ((cpu_info[0] >> 16) & 0xff0); model = ((cpu_info[0] >> 4) & 0x0f) | ((cpu_info[0] >> 12) & 0xf0); - printf("Cpu Family %d (0x%x), Model %d (0x%x)\n", family, family, - model, model); - } -#endif - printf("Cpu Flags %x\n", cpu_flags); - printf("Has ARM %x\n", has_arm); - printf("Has MIPS %x\n", has_mips); - printf("Has X86 %x\n", has_x86); - if (has_arm) { - int has_neon = TestCpuFlag(kCpuHasNEON); - printf("Has NEON %x\n", has_neon); - } - if (has_mips) { - int has_msa = TestCpuFlag(kCpuHasMSA); - printf("Has MSA %x\n", has_msa); - int has_mmi = TestCpuFlag(kCpuHasMMI); - printf("Has MMI %x\n", has_mmi); - } - if (has_x86) { + printf("Cpu Family %d (0x%x), Model %d (0x%x)\n", family, family, model, + model); + int has_sse2 = TestCpuFlag(kCpuHasSSE2); int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); int has_sse41 = TestCpuFlag(kCpuHasSSE41); @@ -82,32 +202,74 @@ int main(int argc, const char* argv[]) { int has_avx = TestCpuFlag(kCpuHasAVX); int has_avx2 = TestCpuFlag(kCpuHasAVX2); int has_erms = TestCpuFlag(kCpuHasERMS); + int has_fsmr = TestCpuFlag(kCpuHasFSMR); int has_fma3 = TestCpuFlag(kCpuHasFMA3); - int has_f16c = TestCpuFlag(kCpuHasF16C); - int has_gfni = TestCpuFlag(kCpuHasGFNI); + int has_f16c = TestCpuFlag(kCpuHasF16C); int has_avx512bw = TestCpuFlag(kCpuHasAVX512BW); int has_avx512vl = TestCpuFlag(kCpuHasAVX512VL); + int has_avx512vnni = TestCpuFlag(kCpuHasAVX512VNNI); int has_avx512vbmi = TestCpuFlag(kCpuHasAVX512VBMI); int has_avx512vbmi2 = TestCpuFlag(kCpuHasAVX512VBMI2); int has_avx512vbitalg = TestCpuFlag(kCpuHasAVX512VBITALG); - int has_avx512vpopcntdq = TestCpuFlag(kCpuHasAVX512VPOPCNTDQ); - printf("Has SSE2 %x\n", has_sse2); - printf("Has SSSE3 %x\n", has_ssse3); - printf("Has SSE4.1 %x\n", has_sse41); - printf("Has SSE4.2 %x\n", has_sse42); - printf("Has AVX %x\n", has_avx); - printf("Has AVX2 %x\n", has_avx2); - printf("Has ERMS %x\n", has_erms); - printf("Has FMA3 %x\n", has_fma3); - printf("Has F16C %x\n", has_f16c); - printf("Has GFNI %x\n", has_gfni); - printf("Has AVX512BW %x\n", has_avx512bw); - printf("Has AVX512VL %x\n", has_avx512vl); - printf("Has AVX512VBMI %x\n", has_avx512vbmi); - printf("Has AVX512VBMI2 %x\n", has_avx512vbmi2); - printf("Has AVX512VBITALG %x\n", has_avx512vbitalg); - printf("Has AVX512VPOPCNTDQ %x\n", has_avx512vpopcntdq); + int has_avx10 = TestCpuFlag(kCpuHasAVX10); + int has_avx10_2 = TestCpuFlag(kCpuHasAVX10_2); + int has_avxvnni = TestCpuFlag(kCpuHasAVXVNNI); + int has_avxvnniint8 = TestCpuFlag(kCpuHasAVXVNNIINT8); + int has_amxint8 = TestCpuFlag(kCpuHasAMXINT8); + int has_avx512bmm = TestCpuFlag(kCpuHasAVX512BMM); + int has_amxtf32 = TestCpuFlag(kCpuHasAMXTF32); + printf("Has X86 0x%x\n", has_x86); + printf("Has SSE2 0x%x\n", has_sse2); + printf("Has SSSE3 0x%x\n", has_ssse3); + printf("Has SSE4.1 0x%x\n", has_sse41); + printf("Has SSE4.2 0x%x\n", has_sse42); + printf("Has AVX 0x%x\n", has_avx); + printf("Has AVX2 0x%x\n", has_avx2); + printf("Has ERMS 0x%x\n", has_erms); + printf("Has FSMR 0x%x\n", has_fsmr); + printf("Has FMA3 0x%x\n", has_fma3); + printf("Has F16C 0x%x\n", has_f16c); + printf("Has AVX512BW 0x%x\n", has_avx512bw); + printf("Has AVX512VL 0x%x\n", has_avx512vl); + printf("Has AVX512VNNI 0x%x\n", has_avx512vnni); + printf("Has AVX512VBMI 0x%x\n", has_avx512vbmi); + printf("Has AVX512VBMI2 0x%x\n", has_avx512vbmi2); + printf("Has AVX512VBITALG 0x%x\n", has_avx512vbitalg); + printf("Has AVX10 0x%x\n", has_avx10); + printf("Has AVX10_2 0x%x\n", has_avx10_2); + printf("HAS AVXVNNI 0x%x\n", has_avxvnni); + printf("Has AVXVNNIINT8 0x%x\n", has_avxvnniint8); + printf("Has AMXINT8 0x%x\n", has_amxint8); + printf("Has AVX512BMM 0x%x\n", has_avx512bmm); + printf("Has AMXTF32 0x%x\n", has_amxtf32); + +#ifdef __linux__ + // Test VDPPHPS instruction + { + struct sigaction act, oldact; + memset(&act, 0, sizeof(act)); + act.sa_handler = vdpphps_sigill_handler; + sigaction(SIGILL, &act, &oldact); + + printf("Testing VDPPHPS instruction... "); + fflush(stdout); + + if (sigsetjmp(vdpphps_jmpbuf, 1) == 0) { + // VDPPHPS xmm0, xmm0, xmm0 + __asm__ volatile(".byte 0x62, 0xf2, 0x7c, 0x08, 0x52, 0xc0" + : + : + : "xmm0"); + printf("Works!\n"); + } else { + printf("Crashed (SIGILL)!\n"); + } + + sigaction(SIGILL, &oldact, NULL); + } +#endif } +#endif // defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || + // defined(_M_X64) return 0; } - diff --git a/libs/libyuv/util/i444tonv12_eg.cc b/libs/libyuv/util/i444tonv12_eg.cc new file mode 100644 index 0000000000..0fcb4095a8 --- /dev/null +++ b/libs/libyuv/util/i444tonv12_eg.cc @@ -0,0 +1,28 @@ + +#include "libyuv/convert.h" + +#include // for printf +#include // for memset + +int main(int, char**) { + unsigned char src_i444[640 * 400 * 3]; + unsigned char dst_nv12[640 * 400 * 3 / 2]; + + for (size_t i = 0; i < sizeof(src_i444); ++i) { + src_i444[i] = i & 255; + } + memset(dst_nv12, 0, sizeof(dst_nv12)); + libyuv::I444ToNV12(&src_i444[0], 640, // source Y + &src_i444[640 * 400], 640, // source U + &src_i444[640 * 400 * 2], 640, // source V + &dst_nv12[0], 640, // dest Y + &dst_nv12[640 * 400], 640, // dest UV + 640, 400); // width and height + + int checksum = 0; + for (size_t i = 0; i < sizeof(dst_nv12); ++i) { + checksum += dst_nv12[i]; + } + printf("checksum %x %s\n", checksum, checksum == 0x2ec0c00 ? "PASS" : "FAIL"); + return 0; +} \ No newline at end of file diff --git a/libs/libyuv/util/psnr_main.cc b/libs/libyuv/util/psnr_main.cc index a930b202ec..45261805c9 100644 --- a/libs/libyuv/util/psnr_main.cc +++ b/libs/libyuv/util/psnr_main.cc @@ -65,9 +65,9 @@ int num_threads = 0; #endif // Parse PYUV format. ie name.1920x800_24Hz_P420.yuv -bool ExtractResolutionFromFilename(const char* name, - int* width_ptr, - int* height_ptr) { +static bool ExtractResolutionFromFilename(const char* name, + int* width_ptr, + int* height_ptr) { // Isolate the .width_height. section of the filename by searching for a // dot or underscore followed by a digit. for (int i = 0; name[i]; ++i) { @@ -105,25 +105,12 @@ bool ExtractResolutionFromFilename(const char* name, return false; } -// Scale Y channel from 16..240 to 0..255. -// This can be useful when comparing codecs that are inconsistant about Y -uint8_t ScaleY(uint8_t y) { - int ny = (y - 16) * 256 / 224; - if (ny < 0) { - ny = 0; - } - if (ny > 255) { - ny = 255; - } - return static_cast(ny); -} - // MSE = Mean Square Error -double GetMSE(double sse, double size) { +static double GetMSE(double sse, double size) { return sse / size; } -void PrintHelp(const char* program) { +static void PrintHelp(const char* program) { printf("%s [-options] org_seq rec_seq [rec_seq2.. etc]\n", program); #ifdef HAVE_JPEG printf("jpeg or raw YUV 420 supported.\n"); @@ -151,7 +138,7 @@ void PrintHelp(const char* program) { exit(0); } -void ParseOptions(int argc, const char* argv[]) { +static void ParseOptions(int argc, const char* argv[]) { if (argc <= 1) { PrintHelp(argv[0]); } @@ -240,21 +227,21 @@ void ParseOptions(int argc, const char* argv[]) { } } -bool UpdateMetrics(uint8_t* ch_org, - uint8_t* ch_rec, - const int y_size, - const int uv_size, - const size_t total_size, - int number_of_frames, - metric* cur_distortion_psnr, - metric* distorted_frame, - bool do_psnr) { +static bool UpdateMetrics(uint8_t* ch_org, + uint8_t* ch_rec, + const int y_size, + const int uv_size, + const size_t total_size, + int number_of_frames, + metric* cur_distortion_psnr, + metric* distorted_frame, + bool compute_psnr) { const int uv_offset = (do_swap_uv ? uv_size : 0); const uint8_t* const u_org = ch_org + y_size + uv_offset; const uint8_t* const u_rec = ch_rec + y_size; const uint8_t* const v_org = ch_org + y_size + (uv_size - uv_offset); const uint8_t* const v_rec = ch_rec + y_size + uv_size; - if (do_psnr) { + if (compute_psnr) { #ifdef HAVE_JPEG double y_err = static_cast( libyuv::ComputeSumSquareError(ch_org, ch_rec, y_size)); @@ -342,9 +329,12 @@ int main(int argc, const char* argv[]) { exit(1); } + if (num_rec <= 0) { + fclose(file_org); + exit(1); + } // Open all files to compare to - FILE** file_rec = new FILE*[num_rec]; - memset(file_rec, 0, num_rec * sizeof(FILE*)); // NOLINT + FILE** file_rec = new FILE*[num_rec](); for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) { file_rec[cur_rec] = fopen(argv[fileindex_rec + cur_rec], "rb"); if (file_rec[cur_rec] == NULL) { diff --git a/libs/libyuv/util/ssim.cc b/libs/libyuv/util/ssim.cc index 096fbcf061..f8b4509f87 100644 --- a/libs/libyuv/util/ssim.cc +++ b/libs/libyuv/util/ssim.cc @@ -244,23 +244,23 @@ double GetSSIMFullKernel(const uint8_t* org, // Read 8 pixels at line #L, and convert to 16bit, perform weighting // and acccumulate. -#define LOAD_LINE_PAIR(L, WEIGHT) \ - do { \ - const __m128i v0 = \ - _mm_loadl_epi64(reinterpret_cast(org + (L)*stride)); \ - const __m128i v1 = \ - _mm_loadl_epi64(reinterpret_cast(rec + (L)*stride)); \ - const __m128i w0 = _mm_unpacklo_epi8(v0, zero); \ - const __m128i w1 = _mm_unpacklo_epi8(v1, zero); \ - const __m128i ww0 = _mm_mullo_epi16(w0, (WEIGHT).values_.m_); \ - const __m128i ww1 = _mm_mullo_epi16(w1, (WEIGHT).values_.m_); \ - x = _mm_add_epi32(x, _mm_unpacklo_epi16(ww0, zero)); \ - y = _mm_add_epi32(y, _mm_unpacklo_epi16(ww1, zero)); \ - x = _mm_add_epi32(x, _mm_unpackhi_epi16(ww0, zero)); \ - y = _mm_add_epi32(y, _mm_unpackhi_epi16(ww1, zero)); \ - xx = _mm_add_epi32(xx, _mm_madd_epi16(ww0, w0)); \ - xy = _mm_add_epi32(xy, _mm_madd_epi16(ww0, w1)); \ - yy = _mm_add_epi32(yy, _mm_madd_epi16(ww1, w1)); \ +#define LOAD_LINE_PAIR(L, WEIGHT) \ + do { \ + const __m128i v0 = \ + _mm_loadl_epi64(reinterpret_cast(org + (L) * stride)); \ + const __m128i v1 = \ + _mm_loadl_epi64(reinterpret_cast(rec + (L) * stride)); \ + const __m128i w0 = _mm_unpacklo_epi8(v0, zero); \ + const __m128i w1 = _mm_unpacklo_epi8(v1, zero); \ + const __m128i ww0 = _mm_mullo_epi16(w0, (WEIGHT).values_.m_); \ + const __m128i ww1 = _mm_mullo_epi16(w1, (WEIGHT).values_.m_); \ + x = _mm_add_epi32(x, _mm_unpacklo_epi16(ww0, zero)); \ + y = _mm_add_epi32(y, _mm_unpacklo_epi16(ww1, zero)); \ + x = _mm_add_epi32(x, _mm_unpackhi_epi16(ww0, zero)); \ + y = _mm_add_epi32(y, _mm_unpackhi_epi16(ww1, zero)); \ + xx = _mm_add_epi32(xx, _mm_madd_epi16(ww0, w0)); \ + xy = _mm_add_epi32(xy, _mm_madd_epi16(ww0, w1)); \ + yy = _mm_add_epi32(yy, _mm_madd_epi16(ww1, w1)); \ } while (0) #define ADD_AND_STORE_FOUR_EPI32(M, OUT) \ diff --git a/libs/libyuv/util/yuvconstants.c b/libs/libyuv/util/yuvconstants.c new file mode 100644 index 0000000000..5f52d7553c --- /dev/null +++ b/libs/libyuv/util/yuvconstants.c @@ -0,0 +1,114 @@ +/* + * Copyright 2021 The LibYuv Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include +#include + +// This utility computes values needed to generate yuvconstants based on +// white point values. +// The yuv formulas are tuned for 8 bit YUV channels. + +// See Also +// https://mymusing.co/bt601-yuv-to-rgb-conversion-color/ + +// BT.709 full range YUV to RGB reference +// R = Y + V * 1.5748 +// G = Y - U * 0.18732 - V * 0.46812 +// B = Y + U * 1.8556 +// KR = 0.2126 +// KB = 0.0722 + +// // Y contribution to R,G,B. Scale and bias. +// #define YG 16320 /* round(1.000 * 64 * 256 * 256 / 257) */ +// #define YB 32 /* 64 / 2 */ +// +// // U and V contributions to R,G,B. +// #define UB 113 /* round(1.77200 * 64) */ +// #define UG 22 /* round(0.34414 * 64) */ +// #define VG 46 /* round(0.71414 * 64) */ +// #define VR 90 /* round(1.40200 * 64) */ +// +// // Bias values to round, and subtract 128 from U and V. +// #define BB (-UB * 128 + YB) +// #define BG (UG * 128 + VG * 128 + YB) +// #define BR (-VR * 128 + YB) + +int main(int argc, const char* argv[]) { + if (argc < 3) { + printf("yuvconstants [KR] [KB]\n"); + printf(" e.g. yuvconstants 0.2126 0.0722\n"); + printf(" MC BT KR KB\n"); + printf(" 1 BT.709 KR = 0.2126; KB = 0.0722\n"); + printf(" 4 FCC KR = 0.30; KB = 0.11\n"); + printf(" 6 BT.601 KR = 0.299; KB = 0.114\n"); + printf(" 7 SMPTE 240M KR = 0.212; KB = 0.087\n"); + printf(" 9 BT.2020 KR = 0.2627; KB = 0.0593\n"); + return -1; + } + float kr = (float)atof(argv[1]); + float kb = (float)atof(argv[2]); + float kg = 1 - kr - kb; + + float vr = 2 * (1 - kr); + float ug = 2 * ((1 - kb) * kb / kg); + float vg = 2 * ((1 - kr) * kr / kg); + float ub = 2 * (1 - kb); + + printf("Full range\n"); + printf("R = Y + V * %5f\n", vr); + printf("G = Y - U * %6f - V * %6f\n", ug, vg); + printf("B = Y + U * %5f\n", ub); + + printf("KR = %4f; ", kr); + printf("KB = %4f\n", kb); + // printf("KG = %4f\n", kg); + // #define YG 16320 /* round(1.000 * 64 * 256 * 256 / 257) */ + // #define YB 32 /* 64 / 2 */ + // + // // U and V contributions to R,G,B. + + printf("UB %-3.0f /* round(%f * 64 = %8.4f) */\n", round(ub * 64), ub, + ub * 64); + printf("UG %-3.0f /* round(%f * 64 = %8.4f) */\n", round(ug * 64), ug, + ug * 64); + printf("VG %-3.0f /* round(%f * 64 = %8.4f) */\n", round(vg * 64), vg, + vg * 64); + printf("VR %-3.0f /* round(%f * 64 = %8.4f) */\n", round(vr * 64), vr, + vr * 64); + + vr = 255.f / 224.f * 2 * (1 - kr); + ug = 255.f / 224.f * 2 * ((1 - kb) * kb / kg); + vg = 255.f / 224.f * 2 * ((1 - kr) * kr / kg); + ub = 255.f / 224.f * 2 * (1 - kb); + + printf("\nLimited range\n"); + printf("R = (Y - 16) * 1.164 + V * %5f\n", vr); + printf("G = (Y - 16) * 1.164 - U * %6f - V * %6f\n", ug, vg); + printf("B = (Y - 16) * 1.164 + U * %5f\n", ub); + + // printf("KG = %4f\n", kg); + // #define YG 16320 /* round(1.000 * 64 * 256 * 256 / 257) */ + // #define YB 32 /* 64 / 2 */ + // + // // U and V contributions to R,G,B. + + printf("UB %-3.0f /* round(%f * 64 = %8.4f) */\n", round(ub * 64), ub, + ub * 64); + printf("UG %-3.0f /* round(%f * 64 = %8.4f) */\n", round(ug * 64), ug, + ug * 64); + printf("VG %-3.0f /* round(%f * 64 = %8.4f) */\n", round(vg * 64), vg, + vg * 64); + printf("VR %-3.0f /* round(%f * 64 = %8.4f) */\n", round(vr * 64), vr, + vr * 64); + + return 0; +} diff --git a/libs/libyuv/util/yuvconvert.cc b/libs/libyuv/util/yuvconvert.cc index 27cdfe9e37..047e9235dc 100644 --- a/libs/libyuv/util/yuvconvert.cc +++ b/libs/libyuv/util/yuvconvert.cc @@ -42,9 +42,9 @@ static __inline uint32_t Abs(int32_t v) { } // Parse PYUV format. ie name.1920x800_24Hz_P420.yuv -bool ExtractResolutionFromFilename(const char* name, - int* width_ptr, - int* height_ptr) { +static bool ExtractResolutionFromFilename(const char* name, + int* width_ptr, + int* height_ptr) { // Isolate the .width_height. section of the filename by searching for a // dot or underscore followed by a digit. for (int i = 0; name[i]; ++i) { @@ -59,7 +59,7 @@ bool ExtractResolutionFromFilename(const char* name, return false; } -void PrintHelp(const char* program) { +static void PrintHelp(const char* program) { printf("%s [-options] src_argb.raw dst_yuv.raw\n", program); printf( " -s .... specify source resolution. " @@ -78,7 +78,7 @@ void PrintHelp(const char* program) { exit(0); } -void ParseOptions(int argc, const char* argv[]) { +static void ParseOptions(int argc, const char* argv[]) { if (argc <= 1) { PrintHelp(argv[0]); } @@ -165,23 +165,23 @@ static int TileARGBScale(const uint8_t* src_argb, int src_height, uint8_t* dst_argb, int dst_stride_argb, - int dst_width, - int dst_height, + int destination_width, + int destination_height, libyuv::FilterMode filtering) { - for (int y = 0; y < dst_height; y += kTileY) { - for (int x = 0; x < dst_width; x += kTileX) { + for (int y = 0; y < destination_height; y += kTileY) { + for (int x = 0; x < destination_width; x += kTileX) { int clip_width = kTileX; - if (x + clip_width > dst_width) { - clip_width = dst_width - x; + if (x + clip_width > destination_width) { + clip_width = destination_width - x; } int clip_height = kTileY; - if (y + clip_height > dst_height) { - clip_height = dst_height - y; + if (y + clip_height > destination_height) { + clip_height = destination_height - y; } int r = libyuv::ARGBScaleClip(src_argb, src_stride_argb, src_width, src_height, dst_argb, dst_stride_argb, - dst_width, dst_height, x, y, clip_width, - clip_height, filtering); + destination_width, destination_height, x, y, + clip_width, clip_height, filtering); if (r) { return r; } @@ -201,8 +201,12 @@ int main(int argc, const char* argv[]) { } // Open all files to convert to - FILE** file_rec = new FILE*[num_rec]; - memset(file_rec, 0, num_rec * sizeof(FILE*)); // NOLINT + FILE** file_rec = static_cast(calloc(num_rec, sizeof(FILE*))); + if (file_rec == NULL) { + fprintf(stderr, "No memory available\n"); + fclose(file_org); + exit(1); + } for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) { file_rec[cur_rec] = fopen(argv[fileindex_rec + cur_rec], "wb"); if (file_rec[cur_rec] == NULL) { @@ -211,7 +215,7 @@ int main(int argc, const char* argv[]) { for (int i = 0; i < cur_rec; ++i) { fclose(file_rec[i]); } - delete[] file_rec; + free(file_rec); exit(1); } } @@ -243,19 +247,19 @@ int main(int argc, const char* argv[]) { fseek(file_org, num_skip_org * total_size, SEEK_SET); #endif - uint8_t* const ch_org = new uint8_t[org_size]; - uint8_t* const ch_dst = new uint8_t[dst_size]; - uint8_t* const ch_rec = new uint8_t[total_size]; - if (ch_org == NULL || ch_rec == NULL) { + uint8_t* const ch_org = static_cast(malloc(org_size)); + uint8_t* const ch_dst = static_cast(malloc(dst_size)); + uint8_t* const ch_rec = static_cast(malloc(total_size)); + if (ch_org == NULL || ch_dst == NULL || ch_rec == NULL) { fprintf(stderr, "No memory available\n"); fclose(file_org); for (int i = 0; i < num_rec; ++i) { fclose(file_rec[i]); } - delete[] ch_org; - delete[] ch_dst; - delete[] ch_rec; - delete[] file_rec; + free(ch_org); + free(ch_dst); + free(ch_rec); + free(file_rec); exit(1); } @@ -359,9 +363,9 @@ int main(int argc, const char* argv[]) { for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) { fclose(file_rec[cur_rec]); } - delete[] ch_org; - delete[] ch_dst; - delete[] ch_rec; - delete[] file_rec; + free(ch_org); + free(ch_dst); + free(ch_rec); + free(file_rec); return 0; } diff --git a/libs/libyuv/vpython.toml b/libs/libyuv/vpython.toml new file mode 100644 index 0000000000..52d8b3adc5 --- /dev/null +++ b/libs/libyuv/vpython.toml @@ -0,0 +1,76 @@ +# Copyright 2026 The Chromium Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +requires-python = '>=3.11,<3.12' +dependencies = [ + 'protobuf==4.25.1', + 'six==1.15.0', + 'numpy==1.23.5+chromium.4', + 'psutil==5.9.8', + 'requests==2.31.0', + 'mock==2.0.0', + 'parameterized==0.7.1', + 'pbr==3.0.0', + 'setuptools==68.0.0 ; python_version < "3.14"', + 'setuptools>=75.0.0 ; python_version >= "3.14"', + 'pyfakefs==3.7.2', + 'jsonlines==1.2.0', + 'python-dateutil==2.9.0', + 'charset-normalizer==2.0.4', + 'pyasn1==0.4.5', + 'pyasn1-modules==0.2.4', + 'rsa==3.4.2', + 'cachetools==2.0.1', + 'uritemplate==3.0.0', + 'google-auth==1.25.0', + 'googleapis-common-protos==1.52.0', + 'google-api-core==1.25.1', + 'google-auth-httplib2==0.1.0', + 'google-api-python-client==2.2.0', + 'oauth2client==3.0.0', + 'html5lib==1.0.1', + 'mozdebug==0.2', + 'mozinfo==1.2.2', + 'mozlog==7.1.0', + 'mozprocess==1.2.1', + 'urllib3==1.26.6', + 'brotli==1.0.9', + 'blessings==1.7', + 'mozfile==2.0.0', + 'mozterm==1.0.0', + 'webencodings==0.5.1', + 'certifi==2020.11.8', + 'chardet==3.0.4', + 'idna==2.8', + 'distro==1.4.0', + 'pillow==10.4.0', + 'aioquic==1.2.0+chromium.1', + 'pyopenssl==24.2.1', + 'service-identity==24.1.0', + 'tzdata==2023.4', + 'pylsqpack==0.3.12', + 'cryptography==43.0.0', + 'cffi==1.15.1+chromium.2', + 'pycparser==2.19', + 'iniconfig==1.1.1', + 'packaging==16.8', + 'pyparsing==2.4.7', + 'toml==0.10.1', + 'pytest==6.2.2', + 'pytest-asyncio==0.14.0', + 'attrs==20.3.0', + 'more-itertools==4.1.0', + 'pluggy==0.13.1', + 'py==1.10.0', + 'funcsigs==1.0.2', + 'atomicwrites==1.3.0', + 'colorama==0.4.1', + 'coverage==7.3.1', + 'pathos==0.3.0+chromium.2', + 'pytz==2024.1', + "pywin32==308; sys_platform == 'win32'", + "pyobjc==10.0; sys_platform == 'darwin'", + 'httplib2==0.19.1', + "pandas==2.2.3+chromium.1; sys_platform != 'linux' or platform_machine != 'aarch64'" +] diff --git a/libs/libyuv/vpython.toml.uv.lock b/libs/libyuv/vpython.toml.uv.lock new file mode 100644 index 0000000000..c4570ede52 --- /dev/null +++ b/libs/libyuv/vpython.toml.uv.lock @@ -0,0 +1,1722 @@ +aioquic==1.2.0+chromium.1 \ + --hash=sha256:091c63339525b44f869b36c80c72715f1521e10e8d8dc66f0f1d76ed9bb186c5 \ + --hash=sha256:4c33abef5832db9b6a8473c5073b7b6d9765915025158d0d1b4f668904ae9eb2 \ + --hash=sha256:5c0f27ec0e5386743db8e3a0e17c1f118e7bb59915c4a1168c44aae8af4735e7 \ + --hash=sha256:6c118aac0b8844f133cda053d542adf4dd689cbd587d23e69314bd69cff8cec9 \ + --hash=sha256:7022d962b525fe3ae4a33278d11a9f757b88bfaab6cc74887c95c5d6226d694d \ + --hash=sha256:823e7c5addce32335f67108ea0ef0cf754cedaf2345f58ec349bb1604e7b55b2 \ + --hash=sha256:841ffbbf28eebf558b6f356215ccb34d8963351f1f5e18ee6f4265da974cc703 \ + --hash=sha256:8e2a7b8dec2cd23a19103894f24207d85094f5db18cfafe42d31a25a8e7ec4b2 \ + --hash=sha256:9e8c5c3a715e48491e83e5323a1518f079d65de90a829599cdff37c14998748e \ + --hash=sha256:aa043efcfff94803237104db48ca62a9f23c192291a10339554223af74ee6021 \ + --hash=sha256:b7a3164babb8173cba2e35d43f4bf3f6159e19b4a28601b21ee9a5163f1a2bf9 \ + --hash=sha256:e2c23c2c0b376208fe138c0bdb3ba572257d51d788837807250b0ce6444d3fa1 \ + --hash=sha256:e53155d0542f8968ea03005785cf384af1f29ae1a04864af711d6c02690b6958 \ + --hash=sha256:f99f43c4961c885581513d603af5172660314007eace52523e05464d1c03b41d +atomicwrites==1.3.0 \ + --hash=sha256:03472c30eb2c5d1ba9227e4c2ca66ab8287fbfbbda3888aa93dc2e28fc6811b4 \ + --hash=sha256:03472c30eb2c5d1ba9227e4c2ca66ab8287fbfbbda3888aa93dc2e28fc6811b4 \ + --hash=sha256:03472c30eb2c5d1ba9227e4c2ca66ab8287fbfbbda3888aa93dc2e28fc6811b4 \ + --hash=sha256:6bb9f1a7743fc65fe70e76ab1225522a3d1efc511bca66b5b89e4c41ef94ccca \ + --hash=sha256:6bb9f1a7743fc65fe70e76ab1225522a3d1efc511bca66b5b89e4c41ef94ccca \ + --hash=sha256:6bb9f1a7743fc65fe70e76ab1225522a3d1efc511bca66b5b89e4c41ef94ccca + # via pytest +attrs==20.3.0 \ + --hash=sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6 \ + --hash=sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6 \ + --hash=sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6 \ + --hash=sha256:be113fc296f1e704a1ae1a26a1f7af5082217cf0af1cdef3fa93afc543bab3f7 \ + --hash=sha256:f37869632f36155a5bea58fd2c2a4b970e51b49fc9037989640280ba6a23bc14 \ + --hash=sha256:f37869632f36155a5bea58fd2c2a4b970e51b49fc9037989640280ba6a23bc14 + # via + # pytest + # service-identity +blessings==1.7 \ + --hash=sha256:74e662a1b980c6982356b113be1160074e32f1dba038da4829f2742736a41318 \ + --hash=sha256:9d110e490ecb455308c2e4b9fabed4a2aa27fc61ae9c929e226be189a9e2d3f9 \ + --hash=sha256:9d110e490ecb455308c2e4b9fabed4a2aa27fc61ae9c929e226be189a9e2d3f9 \ + --hash=sha256:b1fdd7e7a675295630f9ae71527a8ebc10bfefa236b3d6aa4932ee4462c17ba3 \ + --hash=sha256:caad5211e7ba5afe04367cdd4cfc68fa886e2e08f6f35e76b7387d2109ccea6e \ + --hash=sha256:caad5211e7ba5afe04367cdd4cfc68fa886e2e08f6f35e76b7387d2109ccea6e + # via mozlog +brotli==1.0.9 \ + --hash=sha256:1590964412a2f2b59540b995cd89f382faf4657f5bc8d034240e9e0a10713ae5 \ + --hash=sha256:1e43abc36411833f42e12cc7ac95f9b66c8d896e636f30aefbee8997c486bca7 \ + --hash=sha256:2037368f12f750aba61f74329d9c2111a57c36e586c671686aef93f524008e97 \ + --hash=sha256:2e7c834df41cb201c35e622e08b2b1e0d9ad51a2d6f0ff8c0f42c4b110564cc7 \ + --hash=sha256:4258cc1b975b088abd0d8a6dcace6488f2b2cab658c67a6bc1ade04c76697fa6 \ + --hash=sha256:633eacc9633199b897ddbb31242aa08ed0da04b0e3a52af166988a66f9168c11 \ + --hash=sha256:672875325d005af939bb1f417dd74e4c67fe3d9eba04ece818cc0c741640f20e \ + --hash=sha256:717773b68db3ac0f26729867d5a6d9bc4b8611e75da3995fcc25e4efde859e75 \ + --hash=sha256:87a7bb50c2cce9cf9d279442ee3ee79731fc9c39421fa6c60896c7932ed5df32 \ + --hash=sha256:90fd84cd7fd28a8dccbd1253916bfd1b58ffc79a4c8f9725fcd7abd5e0922ce5 \ + --hash=sha256:99e081f61a21f13996e61b5fcb311c0ffaa47dbdf509d94576578ae784f752ca \ + --hash=sha256:a16e5e7ab858d1ecf4521b91f527a3150212d3038f41d9f878706fd9c9756727 \ + --hash=sha256:a172a8fcda96953ffb3ba0c46ac87226e2fa787a5e3314d808355acdfd9556cb \ + --hash=sha256:b47f558b2274209c59c1a24e3d350491480c0b5d871fa052cc20224e28da5fa5 \ + --hash=sha256:c02ce929bad0afa590a32d41a610c417b0c0860f7c37ec0249553f9842846ce1 \ + --hash=sha256:ed1d451150616224ce20cfc2664ed6f8716739c7b52e6814aba73d6753e62bca \ + --hash=sha256:f6430b9d07dfe90fd16d0877a3d4e2d464316b35d4b755e57e79be4bdb7869d0 +cachetools==2.0.1 \ + --hash=sha256:4319bbb78172e7bcf99423e1ecd6914b32336ccfe97d2058ffe62e641a7f3abe \ + --hash=sha256:4319bbb78172e7bcf99423e1ecd6914b32336ccfe97d2058ffe62e641a7f3abe \ + --hash=sha256:4319bbb78172e7bcf99423e1ecd6914b32336ccfe97d2058ffe62e641a7f3abe \ + --hash=sha256:452888d3eac7decf889530a271923254abb7380a0255cd65693cd29c2c66b4f8 \ + --hash=sha256:452888d3eac7decf889530a271923254abb7380a0255cd65693cd29c2c66b4f8 \ + --hash=sha256:452888d3eac7decf889530a271923254abb7380a0255cd65693cd29c2c66b4f8 + # via google-auth +certifi==2020.11.8 \ + --hash=sha256:1f422849db327d534e3d0c5f02a263458c3955ec0aae4ff09b95f195c59f4edd \ + --hash=sha256:1f422849db327d534e3d0c5f02a263458c3955ec0aae4ff09b95f195c59f4edd \ + --hash=sha256:1f422849db327d534e3d0c5f02a263458c3955ec0aae4ff09b95f195c59f4edd \ + --hash=sha256:83899d4fd2a1071acca79abb10435484cdfd9f223522fd26ac2449b2c4c52d9b \ + --hash=sha256:e538978d4526342d7b37cfcdd503eaf48f32c7f362d7ca8cb32ee5491b872841 \ + --hash=sha256:e538978d4526342d7b37cfcdd503eaf48f32c7f362d7ca8cb32ee5491b872841 + # via + # aioquic + # requests +cffi==1.15.1+chromium.2 \ + --hash=sha256:10bdaddfd9bc761f9cf6ea80a0cb3dbcf85a6034c3038879634948d75dc903e1 \ + --hash=sha256:220efee8db3410f448fc08a1337345b168853387cc0fd11c288cd4024d005308 \ + --hash=sha256:2252d280c0ab8be58f52469f4106743073ae37f956e4e483ed8d4e46efaf8566 \ + --hash=sha256:4171ff5206e90549e6f42693a69849c8fcc448936d301d3b3a4e244b221f3f83 \ + --hash=sha256:50b3834673f3ebfcdf4fdbf42a3c34c7ad05362c42a16cea26e5d193cdb9fff5 \ + --hash=sha256:51013c858d2bb7540ac5860644efe82020dc492396105887349c28908913c3b0 \ + --hash=sha256:5b54af79e781dc7fcbc17038ed339fb70bbf8e1f0dff989ef12cdebc53c820f4 \ + --hash=sha256:6291010bcc1e76ae6431cfee3b32fa526b402c3450e2cb8830e409b3e4d93028 \ + --hash=sha256:80916c530265a4935f44f13b1e3ff711b82f5e6312279be2164e958990920d58 \ + --hash=sha256:860f9af71776499a4a9684255be1af58f1ed713ddbf9eee6603023af8133d447 \ + --hash=sha256:a7f78589e2e8d1af2381a3abe778b0e10d2d5691fb14d83a3a352847747fe379 \ + --hash=sha256:aa5d44a118e77bc6e7aea22a6b7e9c9a207eee23695516865ba0b95e270ffa41 \ + --hash=sha256:b3613b9aa31c33af8c8956786697fec59296543fb4dbf3afeec80daf3b7381a2 \ + --hash=sha256:f1c983b1b1b32e87f63bc8180de89b780bb8b6a35eec36ba2ae0490ccce3e9cf \ + --hash=sha256:f9a328b8d39fa3cf6659d80e61b52560d5896a53ea6abcebcbdbce2c05496270 + # via cryptography +chardet==3.0.4 \ + --hash=sha256:a3d948e8a23a4a1072c0f972b2a7d9a04369bde7863d7ecd7b1cee31937a8f6f \ + --hash=sha256:a3d948e8a23a4a1072c0f972b2a7d9a04369bde7863d7ecd7b1cee31937a8f6f \ + --hash=sha256:a3d948e8a23a4a1072c0f972b2a7d9a04369bde7863d7ecd7b1cee31937a8f6f \ + --hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \ + --hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \ + --hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \ + --hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \ + --hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \ + --hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \ + --hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \ + --hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \ + --hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \ + --hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 +charset-normalizer==2.0.4 \ + --hash=sha256:0c8911edd15d19223366a194a513099a302055a962bca2cec0f54b8b63175d8b \ + --hash=sha256:8290b03e2f31a4b3399e1727f0323607253bb2bd38f0cb23d4e0cc6d76a5ec72 + # via requests +colorama==0.4.1 \ + --hash=sha256:758fb3cafa52391ea645703f283afd57f002011140d470793379790398876733 \ + --hash=sha256:758fb3cafa52391ea645703f283afd57f002011140d470793379790398876733 \ + --hash=sha256:758fb3cafa52391ea645703f283afd57f002011140d470793379790398876733 \ + --hash=sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48 \ + --hash=sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48 \ + --hash=sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48 \ + --hash=sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48 \ + --hash=sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48 \ + --hash=sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48 \ + --hash=sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48 \ + --hash=sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48 \ + --hash=sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48 \ + --hash=sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48 + # via pytest +coverage==7.3.1 \ + --hash=sha256:2b7f038e155de2156bd1073068b0ba39e97ed8ca340889a680ae2d7685dd60ea \ + --hash=sha256:37df007c1cb77d75ddf9e8753d2f69ba904d4beaec7d696fff0081a61ce81cd8 \ + --hash=sha256:40c0f331b8bde5128d97fa3c284078958b1aab42a86697c40f65b650417ed904 \ + --hash=sha256:412d5ef5437e9bad534e7464ea80094d195a998803146a9a856850e79083a93c \ + --hash=sha256:4c16428216025c980a8d160c885c5225d143353f609a82537e8b957a2109330e \ + --hash=sha256:4cf8ed834637fe317552ab068048c7202068b64706593159d67fa1936753a19b \ + --hash=sha256:6bc0892076728c5c5d3c92a7e968ddc1c52b49e79479e9419a50431df200566d \ + --hash=sha256:79a16c5b61a81ac581d07d74f2b257a77853d31f3e48d9f674226f4fd42a77ef \ + --hash=sha256:7f3c398881de3a558f9fb94f232757c73d3498a420462bb232590c4ecfb9a908 \ + --hash=sha256:85d78e23c50f3820666670e4689f1b30c0915e7db0020a22a41be4158d78e7f7 \ + --hash=sha256:afd828ea3ffebf4851053258a3e9d52079bfd1c60d233b0d0467bba73ebd044f \ + --hash=sha256:b81ff0d20e6da0552923e36b9b9c5c6e7dcd6192653fc9192b059137f50938c9 \ + --hash=sha256:bdaedd684fdf5c2104be67e2c1b92f73e06b83a1cb0cab19d598a4e4894ccb56 \ + --hash=sha256:ea1637565ebc68eca9ed5f6414c8231614c79b5f2f9d3409b8e8f1894902b7ee \ + --hash=sha256:ec748a35bfb05af56249a15db789773644902de436f6867129eb183479f17010 \ + --hash=sha256:fbd870567a278eddd1903e206969bb29f76288b21a5c1a61dab6e0d8260ec75f +cryptography==43.0.0 \ + --hash=sha256:0663585d02f76929792470451a5ba64424acc3cd5227b03921dab0e2f27b1709 \ + --hash=sha256:299d3da8e00b7e2b54bb02ef58d73cd5f55fb31f33ebbf33bd00d9aa6807df7e \ + --hash=sha256:31e44a986ceccec3d0498e16f3d27b2ee5fdf69ce2ab89b52eaad1d2f33d8778 \ + --hash=sha256:3d9a1eca329405219b605fac09ecfc09ac09e595d6def650a437523fcd08dd22 \ + --hash=sha256:3dcdedae5c7710b9f97ac6bba7e1052b95c7083c9d0e9df96e02a1932e777895 \ + --hash=sha256:3dcdedae5c7710b9f97ac6bba7e1052b95c7083c9d0e9df96e02a1932e777895 \ + --hash=sha256:64c3f16e2a4fc51c0d06af28441881f98c5d91009b8caaff40cf3548089e9c74 \ + --hash=sha256:64c3f16e2a4fc51c0d06af28441881f98c5d91009b8caaff40cf3548089e9c74 \ + --hash=sha256:6e2b11c55d260d03a8cf29ac9b5e0608d35f08077d8c087be96287f43af3ccdc \ + --hash=sha256:7b3f5fe74a5ca32d4d0f302ffe6680fcc5c28f8ef0dc0ae8f40c0f3a1b4fca66 \ + --hash=sha256:7b3f5fe74a5ca32d4d0f302ffe6680fcc5c28f8ef0dc0ae8f40c0f3a1b4fca66 \ + --hash=sha256:7b3f5fe74a5ca32d4d0f302ffe6680fcc5c28f8ef0dc0ae8f40c0f3a1b4fca66 \ + --hash=sha256:ac1955ce000cb29ab40def14fd1bbfa7af2017cca696ee696925615cafd0dce5 \ + --hash=sha256:ac1955ce000cb29ab40def14fd1bbfa7af2017cca696ee696925615cafd0dce5 + # via + # aioquic + # pyopenssl + # service-identity +dill==0.4.1 \ + --hash=sha256:1e1ce33e978ae97fcfcff5638477032b801c46c7c65cf717f95fbc2248f79a9d \ + --hash=sha256:6de43e59480656b19447122e9d653748231ecbd1e1e084e1bc249d4880bdfb57 + # via + # multiprocess + # pathos +distro==1.4.0 \ + --hash=sha256:b9fb5628b296e58599f257d50ad9744d154893b28a19eba10e5c17835891398e \ + --hash=sha256:eedf82a470ebe7d010f1872c17237c79ab04097948800029994fa458e52fb4b4 \ + --hash=sha256:eedf82a470ebe7d010f1872c17237c79ab04097948800029994fa458e52fb4b4 \ + --hash=sha256:eedf82a470ebe7d010f1872c17237c79ab04097948800029994fa458e52fb4b4 \ + --hash=sha256:eedf82a470ebe7d010f1872c17237c79ab04097948800029994fa458e52fb4b4 \ + --hash=sha256:eedf82a470ebe7d010f1872c17237c79ab04097948800029994fa458e52fb4b4 \ + --hash=sha256:eedf82a470ebe7d010f1872c17237c79ab04097948800029994fa458e52fb4b4 \ + --hash=sha256:eedf82a470ebe7d010f1872c17237c79ab04097948800029994fa458e52fb4b4 \ + --hash=sha256:eedf82a470ebe7d010f1872c17237c79ab04097948800029994fa458e52fb4b4 + # via mozinfo +funcsigs==1.0.2 \ + --hash=sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca \ + --hash=sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca \ + --hash=sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca \ + --hash=sha256:c75adf3fb65c5e85c480444a9182c2045f43996a805ff042207d28418e7289b8 \ + --hash=sha256:c75adf3fb65c5e85c480444a9182c2045f43996a805ff042207d28418e7289b8 \ + --hash=sha256:c75adf3fb65c5e85c480444a9182c2045f43996a805ff042207d28418e7289b8 +google-api-core==1.25.1 \ + --hash=sha256:292dd636ed381098d24b7093ccb826b2278a12d886a3fc982084069aa24a8fbb \ + --hash=sha256:292dd636ed381098d24b7093ccb826b2278a12d886a3fc982084069aa24a8fbb \ + --hash=sha256:292dd636ed381098d24b7093ccb826b2278a12d886a3fc982084069aa24a8fbb \ + --hash=sha256:340e5db8a4ae911ce74c886841bc9479572a2dbca30b922044ed24fc69f500ba \ + --hash=sha256:db582cdba02f4c7d66e9c30421e0c06cf1ae6886e66611a51c235c7210d4f2cc \ + --hash=sha256:db582cdba02f4c7d66e9c30421e0c06cf1ae6886e66611a51c235c7210d4f2cc + # via google-api-python-client +google-api-python-client==2.2.0 \ + --hash=sha256:330787e6e8ab10a1629b783a2dd98ae31196ad8f218f9fddc105dc8ac788808f \ + --hash=sha256:9edac3b071588e08e4b3d14455f2a3c2a57637cab6535f70cff0c01200e22909 +google-auth==1.25.0 \ + --hash=sha256:008e23ed080674f69f9d2d7d80db4c2591b9bb307d136cea7b3bc129771d211d \ + --hash=sha256:008e23ed080674f69f9d2d7d80db4c2591b9bb307d136cea7b3bc129771d211d \ + --hash=sha256:008e23ed080674f69f9d2d7d80db4c2591b9bb307d136cea7b3bc129771d211d \ + --hash=sha256:c4db95010a903477b81f06e5c37de92ffffd19299e04c02d0edc3c6939310844 \ + --hash=sha256:c4db95010a903477b81f06e5c37de92ffffd19299e04c02d0edc3c6939310844 \ + --hash=sha256:c4db95010a903477b81f06e5c37de92ffffd19299e04c02d0edc3c6939310844 + # via + # google-api-core + # google-api-python-client + # google-auth-httplib2 +google-auth-httplib2==0.1.0 \ + --hash=sha256:31e49c36c6b5643b57e82617cb3e021e3e1d2df9da63af67252c02fa9c1f4a10 \ + --hash=sha256:31e49c36c6b5643b57e82617cb3e021e3e1d2df9da63af67252c02fa9c1f4a10 \ + --hash=sha256:31e49c36c6b5643b57e82617cb3e021e3e1d2df9da63af67252c02fa9c1f4a10 \ + --hash=sha256:3a16b4a034b717c9fdb53723e7824bc33f56d20ff3b3673496798c99f0b7de69 \ + --hash=sha256:3a16b4a034b717c9fdb53723e7824bc33f56d20ff3b3673496798c99f0b7de69 \ + --hash=sha256:3a16b4a034b717c9fdb53723e7824bc33f56d20ff3b3673496798c99f0b7de69 + # via google-api-python-client +googleapis-common-protos==1.52.0 \ + --hash=sha256:536edff5a2d8a18613e2795577f307c656c905ee53a5e7fd64bd39e620de0557 \ + --hash=sha256:536edff5a2d8a18613e2795577f307c656c905ee53a5e7fd64bd39e620de0557 \ + --hash=sha256:536edff5a2d8a18613e2795577f307c656c905ee53a5e7fd64bd39e620de0557 \ + --hash=sha256:c8961760f5aad9a711d37b675be103e0cc4e9a39327e0d6d857872f698403e24 \ + --hash=sha256:c8961760f5aad9a711d37b675be103e0cc4e9a39327e0d6d857872f698403e24 \ + --hash=sha256:c8961760f5aad9a711d37b675be103e0cc4e9a39327e0d6d857872f698403e24 + # via google-api-core +html5lib==1.0.1 \ + --hash=sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3 \ + --hash=sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3 \ + --hash=sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3 \ + --hash=sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3 \ + --hash=sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3 \ + --hash=sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3 \ + --hash=sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3 \ + --hash=sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3 \ + --hash=sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3 \ + --hash=sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3 \ + --hash=sha256:e88d4002933d893f8b23ebb05db9f49996533d4ac6ddcbfd51b62b9b9793b397 \ + --hash=sha256:e88d4002933d893f8b23ebb05db9f49996533d4ac6ddcbfd51b62b9b9793b397 \ + --hash=sha256:e88d4002933d893f8b23ebb05db9f49996533d4ac6ddcbfd51b62b9b9793b397 +httplib2==0.19.1 \ + --hash=sha256:2ad195faf9faf079723f6714926e9a9061f694d07724b846658ce08d40f522b4 \ + --hash=sha256:2ad195faf9faf079723f6714926e9a9061f694d07724b846658ce08d40f522b4 \ + --hash=sha256:2ad195faf9faf079723f6714926e9a9061f694d07724b846658ce08d40f522b4 \ + --hash=sha256:2ad195faf9faf079723f6714926e9a9061f694d07724b846658ce08d40f522b4 \ + --hash=sha256:2ad195faf9faf079723f6714926e9a9061f694d07724b846658ce08d40f522b4 \ + --hash=sha256:2ad195faf9faf079723f6714926e9a9061f694d07724b846658ce08d40f522b4 \ + --hash=sha256:2ad195faf9faf079723f6714926e9a9061f694d07724b846658ce08d40f522b4 \ + --hash=sha256:2ad195faf9faf079723f6714926e9a9061f694d07724b846658ce08d40f522b4 \ + --hash=sha256:b7cd9ee0a01ce4e658366e13a2047b54c84fc71f1f0ff268325a1ed5b5aa119d + # via + # google-api-python-client + # google-auth-httplib2 + # oauth2client +idna==2.8 \ + --hash=sha256:6c68f10e99f5f99caff1bf6b897f7032748b7fa206d16f507c86867bc078312d \ + --hash=sha256:6c68f10e99f5f99caff1bf6b897f7032748b7fa206d16f507c86867bc078312d \ + --hash=sha256:6c68f10e99f5f99caff1bf6b897f7032748b7fa206d16f507c86867bc078312d \ + --hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c \ + --hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c \ + --hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c \ + --hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c \ + --hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c \ + --hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c \ + --hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c \ + --hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c \ + --hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c \ + --hash=sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c + # via requests +iniconfig==1.1.1 \ + --hash=sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3 \ + --hash=sha256:9d81514370059186276e9a1799e5a9752e4c060233c254d6954b53fad2ff8a5e + # via pytest +jsonlines==1.2.0 \ + --hash=sha256:0ebd5b0c3efe0d4b5018b320fb0ee1a7b680ab39f6eb853715859f818d386cc8 \ + --hash=sha256:0ebd5b0c3efe0d4b5018b320fb0ee1a7b680ab39f6eb853715859f818d386cc8 \ + --hash=sha256:0ebd5b0c3efe0d4b5018b320fb0ee1a7b680ab39f6eb853715859f818d386cc8 \ + --hash=sha256:0ebd5b0c3efe0d4b5018b320fb0ee1a7b680ab39f6eb853715859f818d386cc8 \ + --hash=sha256:0ebd5b0c3efe0d4b5018b320fb0ee1a7b680ab39f6eb853715859f818d386cc8 \ + --hash=sha256:0ebd5b0c3efe0d4b5018b320fb0ee1a7b680ab39f6eb853715859f818d386cc8 \ + --hash=sha256:0ebd5b0c3efe0d4b5018b320fb0ee1a7b680ab39f6eb853715859f818d386cc8 \ + --hash=sha256:0ebd5b0c3efe0d4b5018b320fb0ee1a7b680ab39f6eb853715859f818d386cc8 \ + --hash=sha256:0ebd5b0c3efe0d4b5018b320fb0ee1a7b680ab39f6eb853715859f818d386cc8 \ + --hash=sha256:0ebd5b0c3efe0d4b5018b320fb0ee1a7b680ab39f6eb853715859f818d386cc8 \ + --hash=sha256:73011f8c3ffffa7e2f1222168c0f6b792d609bdf3a19a4742a7ea8f046228398 \ + --hash=sha256:73011f8c3ffffa7e2f1222168c0f6b792d609bdf3a19a4742a7ea8f046228398 \ + --hash=sha256:73011f8c3ffffa7e2f1222168c0f6b792d609bdf3a19a4742a7ea8f046228398 +mock==2.0.0 \ + --hash=sha256:1005a7e0d4cc802865427a9a1928d717023653e10cc7e54451981fe08ea267a1 \ + --hash=sha256:2f61f7f5133a2fe0ba86872efbd85ff86340aa3f4b46cadf7cca961dc651b9db \ + --hash=sha256:2f61f7f5133a2fe0ba86872efbd85ff86340aa3f4b46cadf7cca961dc651b9db \ + --hash=sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1 \ + --hash=sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1 \ + --hash=sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1 \ + --hash=sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1 \ + --hash=sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1 \ + --hash=sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1 \ + --hash=sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1 \ + --hash=sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1 \ + --hash=sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1 \ + --hash=sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1 +more-itertools==4.1.0 \ + --hash=sha256:0dd8f72eeab0d2c3bd489025bb2f6a1b8342f9b198f6fc37b52d15cfa4531fea \ + --hash=sha256:11a625025954c20145b37ff6309cd54e39ca94f72f6bb9576d1195db6fa2442e \ + --hash=sha256:11a625025954c20145b37ff6309cd54e39ca94f72f6bb9576d1195db6fa2442e \ + --hash=sha256:7586f4373cc401db9ebaf156b52fe5cb3e136be27b1bb6dd6ee1e08b35b3de79 \ + --hash=sha256:f6199f71f4c81c6a6323be83693b04b6417d6c1810a2693e74863d43c30be9b7 \ + --hash=sha256:f6199f71f4c81c6a6323be83693b04b6417d6c1810a2693e74863d43c30be9b7 +mozdebug==0.2 \ + --hash=sha256:3e6fea693a7380639d7c29c2381d5bab9a7827f4ecfd819d6f1971778766f17f \ + --hash=sha256:3e6fea693a7380639d7c29c2381d5bab9a7827f4ecfd819d6f1971778766f17f \ + --hash=sha256:3e6fea693a7380639d7c29c2381d5bab9a7827f4ecfd819d6f1971778766f17f \ + --hash=sha256:bed08684bf2d415595bed781b1498084dc55d72cd51fd1d94386e136572844fb \ + --hash=sha256:bed08684bf2d415595bed781b1498084dc55d72cd51fd1d94386e136572844fb \ + --hash=sha256:bed08684bf2d415595bed781b1498084dc55d72cd51fd1d94386e136572844fb +mozfile==2.0.0 \ + --hash=sha256:7355643fca705f43d9412d444fb59588fbbd25f0d1e7592b9482f84e3d23bc8e \ + --hash=sha256:7355643fca705f43d9412d444fb59588fbbd25f0d1e7592b9482f84e3d23bc8e \ + --hash=sha256:7355643fca705f43d9412d444fb59588fbbd25f0d1e7592b9482f84e3d23bc8e \ + --hash=sha256:bb744a07c2f6b8dd2a87d3532da6d54fd454328d08a2a1a1689dc68fc420791f \ + --hash=sha256:bb744a07c2f6b8dd2a87d3532da6d54fd454328d08a2a1a1689dc68fc420791f \ + --hash=sha256:bb744a07c2f6b8dd2a87d3532da6d54fd454328d08a2a1a1689dc68fc420791f + # via + # mozinfo + # mozlog +mozinfo==1.2.2 \ + --hash=sha256:139044387a3488b531fa4520cdab251c0dec2aa2bd0e8c975c3ed35491b7228f \ + --hash=sha256:3834efcbe15fc459e7f505d7388794540ea952d4d266978be5ca024355032265 \ + --hash=sha256:7c9ce6f1e04c96cba5d2687e0115b61e922e935dfde8a3823b06fdc17ac42053 \ + --hash=sha256:9c106ffa5bdb3c1b548f4d7c8a99f492cdddf2b5964727229248273d7e1b4c65 \ + --hash=sha256:9c106ffa5bdb3c1b548f4d7c8a99f492cdddf2b5964727229248273d7e1b4c65 \ + --hash=sha256:e8a2e67b44be1db042e38fa881de10918aea4588514fbabf6423de1c6728c3f5 \ + --hash=sha256:e8a2e67b44be1db042e38fa881de10918aea4588514fbabf6423de1c6728c3f5 \ + --hash=sha256:e8a2e67b44be1db042e38fa881de10918aea4588514fbabf6423de1c6728c3f5 \ + --hash=sha256:e8a2e67b44be1db042e38fa881de10918aea4588514fbabf6423de1c6728c3f5 \ + --hash=sha256:e8a2e67b44be1db042e38fa881de10918aea4588514fbabf6423de1c6728c3f5 \ + --hash=sha256:e8a2e67b44be1db042e38fa881de10918aea4588514fbabf6423de1c6728c3f5 \ + --hash=sha256:e8a2e67b44be1db042e38fa881de10918aea4588514fbabf6423de1c6728c3f5 \ + --hash=sha256:e8a2e67b44be1db042e38fa881de10918aea4588514fbabf6423de1c6728c3f5 + # via + # mozdebug + # mozprocess +mozlog==7.1.0 \ + --hash=sha256:19952b32b781667db2b0f6b2d0aec96d4f0f8c2bfa625899758dc151730b7fb8 \ + --hash=sha256:38ce1ddaf279aa5c4284c73fdcacd428114bda5ea05a22191c60f4d6c3309b86 \ + --hash=sha256:54b9a1e781ce31fc10079dc8aec509fff7feca83714edeae6c981e279ceb796f \ + --hash=sha256:54b9a1e781ce31fc10079dc8aec509fff7feca83714edeae6c981e279ceb796f \ + --hash=sha256:54b9a1e781ce31fc10079dc8aec509fff7feca83714edeae6c981e279ceb796f \ + --hash=sha256:9155ce75cd57dc2d54aa129f28207fd7d9d7a8c777b867894be81c45bf232734 +mozprocess==1.2.1 \ + --hash=sha256:08e1036b53819fd144331f6dfbbb17fc8ca782bbed2e28b4aa771b8b91f7dffb \ + --hash=sha256:08e1036b53819fd144331f6dfbbb17fc8ca782bbed2e28b4aa771b8b91f7dffb \ + --hash=sha256:08e1036b53819fd144331f6dfbbb17fc8ca782bbed2e28b4aa771b8b91f7dffb \ + --hash=sha256:08e1036b53819fd144331f6dfbbb17fc8ca782bbed2e28b4aa771b8b91f7dffb \ + --hash=sha256:08e1036b53819fd144331f6dfbbb17fc8ca782bbed2e28b4aa771b8b91f7dffb \ + --hash=sha256:08e1036b53819fd144331f6dfbbb17fc8ca782bbed2e28b4aa771b8b91f7dffb \ + --hash=sha256:08e1036b53819fd144331f6dfbbb17fc8ca782bbed2e28b4aa771b8b91f7dffb \ + --hash=sha256:08e1036b53819fd144331f6dfbbb17fc8ca782bbed2e28b4aa771b8b91f7dffb \ + --hash=sha256:08e1036b53819fd144331f6dfbbb17fc8ca782bbed2e28b4aa771b8b91f7dffb \ + --hash=sha256:08e1036b53819fd144331f6dfbbb17fc8ca782bbed2e28b4aa771b8b91f7dffb \ + --hash=sha256:4eb345bb6990a2137ce37107dff1d5bab6395848254295a1e9c6089a79bfec54 \ + --hash=sha256:4eb345bb6990a2137ce37107dff1d5bab6395848254295a1e9c6089a79bfec54 \ + --hash=sha256:4eb345bb6990a2137ce37107dff1d5bab6395848254295a1e9c6089a79bfec54 +mozterm==1.0.0 \ + --hash=sha256:602d9d93a7b4fed803d034cf73c061c7b62496ac9698b77bce9fe1e37571ffb2 \ + --hash=sha256:602d9d93a7b4fed803d034cf73c061c7b62496ac9698b77bce9fe1e37571ffb2 \ + --hash=sha256:602d9d93a7b4fed803d034cf73c061c7b62496ac9698b77bce9fe1e37571ffb2 \ + --hash=sha256:f5eafa25c23d391e2a2bb1dd45ee928fc9e3c811977a3856b5a5a0778011053c \ + --hash=sha256:f5eafa25c23d391e2a2bb1dd45ee928fc9e3c811977a3856b5a5a0778011053c \ + --hash=sha256:f5eafa25c23d391e2a2bb1dd45ee928fc9e3c811977a3856b5a5a0778011053c + # via mozlog +multiprocess==0.70.14 \ + --hash=sha256:150f1d52633d4fc9baab1300005cfe83db6219397be4971a77d7fa77ab1ca25f \ + --hash=sha256:1f526675380b915b1e38b3c34e8194285ee854cc3eeab3c87de18adbf0761864 \ + --hash=sha256:40983e76911725cea7031791ceb707ae23039a5804649599c2fc0bd807ced40e \ + --hash=sha256:79e431dfb5f8eeee31457884ac157b8f985b4d1aad267c44f75cdffa82040870 \ + --hash=sha256:7ac72d24fc7486ed60397e9ff60dbc033def6756fecf48232addc426ad20dca4 \ + --hash=sha256:caaf3420bc77adb23217238856e6e218db5d6ea3372af9f3c9600754a1fb09eb \ + --hash=sha256:e0117c25d394a3b3a947ecb4f3ba62597848c5f82b56d6c19793ff28b6ceb4c5 + # via pathos +numpy==1.23.5+chromium.4 \ + --hash=sha256:1f09f09cd02263534f3f3376dc290bb33b2d16c10eb85fd1b0491b02028f559c \ + --hash=sha256:298e858d71fd8e2d963414be9d85288f4e04df92c1025128d7917b42a82768cd \ + --hash=sha256:3b6a0b96bcd6ce7393a92adbc00892d4af02f6c04936f671979dc285d9ed7c38 \ + --hash=sha256:3f58475348b7b887ebc9cf63ec63173b52acf988faa9d8e5b797c7befbf9a1c4 \ + --hash=sha256:44e321bb428153a6e396e7328d808def77c3cef8b3d93c5f9e4108d04c558997 \ + --hash=sha256:48f8428d17325de892ac883561d6ba485978f7b924e0b610d9f31ce968dbabe9 \ + --hash=sha256:5af4510cebaf0bb81ea9af5368fbf5a6ce21b4963dbd3e31fe0f796cffefc9ab \ + --hash=sha256:69098ac2618e6a95064a9096b8eb1e8a737b2105aeec1a21b4eac62ba8d48fa7 \ + --hash=sha256:785d2cec75a1dfb812be1a3a24da0c82ba60729c7b53e6bd132fda1479f6250f \ + --hash=sha256:9241565b3fb920fed1268068efbc0e46fbc4f2d6056495574507adaa32741f5d \ + --hash=sha256:929b83e970651c3971f1cb83ed2c3345266507487702155cb7007d2507d18771 \ + --hash=sha256:9b59a1ae3c94fd499099e304a23dacb486c030f13e826f79eb77470fa618d979 \ + --hash=sha256:a5706db7526e7edfafafe4fe620625c346a30f4b97acc8484f55ec5e83d25a74 \ + --hash=sha256:b80a749316f06b7d6a48cb1e7c5b0cf3de9a2b4ac6d001b3a6a0e5e800ea0f20 \ + --hash=sha256:eaf5507daa4d82341ad08bb2e5fd780c10e021ad48f8555ebf36027e2809787f + # via + # --override /tmp/overrides.txt + # pandas +oauth2client==3.0.0 \ + --hash=sha256:7c47d7f77c785398c13452821ea11142ebe764229333ec0cf505502f6756291c \ + --hash=sha256:800663b3d5c94dcb5fd5fdfcedf72cbc281e0e309818487d20f93385eccfb8be \ + --hash=sha256:8bccbd064280d1b2c00aa6c45f471234e75c2af75aa504a9362ddc9a88b0a937 \ + --hash=sha256:9eedc9d8e25a38492172805e6aa690f9e213bde26eadde3a26076920dee78384 \ + --hash=sha256:a6034847934e8dc6b676dc5648486e7a8bcd76a0669c3ca7140a5b86162df243 \ + --hash=sha256:d91e655716b132d06ea9bf4bf02d0a652ada98fde38c9ee0ab6a844b9aa54833 \ + --hash=sha256:f1a083936e34f1d72eb307ac9fc0ae1655200707600f8e4c600400dd08ca9575 +packaging==16.8 \ + --hash=sha256:12ab96d61fb0cf16023ec1d79d87e7372868c5a883d08378eb29741b1015d243 \ + --hash=sha256:55eaf1bd3efbcc9bbfd7562abaf4b152b9b67f06da364280d04731c18eefde6e \ + --hash=sha256:99276dc6e3a7851f32027a68f1095cd3f77c148091b092ea867a351811cfe388 \ + --hash=sha256:99276dc6e3a7851f32027a68f1095cd3f77c148091b092ea867a351811cfe388 \ + --hash=sha256:99276dc6e3a7851f32027a68f1095cd3f77c148091b092ea867a351811cfe388 \ + --hash=sha256:cfd34b5b8bab8dd8ae8563cb2871894dd24cae16c8b3cace8b0ab5768d40f1bd + # via pytest +pandas==2.2.3+chromium.1 ; platform_machine != 'aarch64' or sys_platform != 'linux' \ + --hash=sha256:21c49f76db22c6f13370b357112ac28443d0b57c8c8476613385caa5bf8d7d23 \ + --hash=sha256:3322b4dba5f4d132abb393e202f22ec7777db4b9b5e7eddba5060ead0d975169 \ + --hash=sha256:c6f279f603a83f59fbc1b61306e644ca82c48b61ada7b335aa6dbb63c1e38f12 \ + --hash=sha256:d30cace0d7fc615a216e863bbda793f9eb8ed83b561af458bcbc6d7c421ddc63 + # via --override /tmp/overrides.txt +parameterized==0.7.1 \ + --hash=sha256:aa0891c15d6899b49751bffb204a2a799f9fa71b075c312071fa59f60701e651 \ + --hash=sha256:aa0891c15d6899b49751bffb204a2a799f9fa71b075c312071fa59f60701e651 \ + --hash=sha256:aa0891c15d6899b49751bffb204a2a799f9fa71b075c312071fa59f60701e651 \ + --hash=sha256:ea0326ba5bbbe7c427329a27b75003410df07d1173ca254976f8f5a64922c322 \ + --hash=sha256:ea0326ba5bbbe7c427329a27b75003410df07d1173ca254976f8f5a64922c322 \ + --hash=sha256:ea0326ba5bbbe7c427329a27b75003410df07d1173ca254976f8f5a64922c322 +pathos==0.3.0+chromium.2 \ + --hash=sha256:063f0c266aeca5b10f74a9878531d9e34d6933403bdcb6d1ad7a4a454c8ced60 \ + --hash=sha256:063f0c266aeca5b10f74a9878531d9e34d6933403bdcb6d1ad7a4a454c8ced60 \ + --hash=sha256:12bba7d6829ea348a42065c2fd0d1398e421d1ebd37f19701e60bff22723c2b5 \ + --hash=sha256:2ec15ab1dda26b4f46a8cffbf08477412c0dd23225f0ff4de8395f440499ab15 \ + --hash=sha256:2ec15ab1dda26b4f46a8cffbf08477412c0dd23225f0ff4de8395f440499ab15 \ + --hash=sha256:4459c545a931689c34f75a45a677abb7fb08140bbfe9de5ace08d4c6a468d655 \ + --hash=sha256:4459c545a931689c34f75a45a677abb7fb08140bbfe9de5ace08d4c6a468d655 \ + --hash=sha256:5ab009f9825e372091d273b6815b791c85475db824b8dc3e62219f184672d626 \ + --hash=sha256:6507053f4e89d5ce9f5ec11f331b8d423a777dbe199c84337b9e2d172e1cc120 \ + --hash=sha256:b70f874130da27fe245b9b0fa2adbe6ac585b0bf2bdeefe2e117a646c7bd9008 \ + --hash=sha256:c389796934467ea9209d741665bd4f3a83c331810abdb33f3d483bee6988d12e \ + --hash=sha256:cb1f42b2e6ebed6a035a1a78f4eda9cf5dbfb4ec2332e52e19a28ac32c5644aa \ + --hash=sha256:fc63d03deb79a9296f6fcb875a24ac95d335ebcfa0c6e085675f46cc4eebf846 +pbr==3.0.0 \ + --hash=sha256:86f0e548dfbdc1ad12559725a66b5e1ca0b2e0744940da1ec89991fd11a2b32b \ + --hash=sha256:86f0e548dfbdc1ad12559725a66b5e1ca0b2e0744940da1ec89991fd11a2b32b \ + --hash=sha256:86f0e548dfbdc1ad12559725a66b5e1ca0b2e0744940da1ec89991fd11a2b32b \ + --hash=sha256:de776c05e4a75e4d266e03a3d82ba13894e2c51a2fa52501187361ac180d4468 \ + --hash=sha256:de776c05e4a75e4d266e03a3d82ba13894e2c51a2fa52501187361ac180d4468 \ + --hash=sha256:de776c05e4a75e4d266e03a3d82ba13894e2c51a2fa52501187361ac180d4468 + # via mock +pillow==10.4.0 \ + --hash=sha256:026dbe011f1f3c78487614add2b5987c5040139c32113e1027a8f2882d2529d3 \ + --hash=sha256:37251922614046bc350a732d801320fcab619b8235d506976c5d0601cedc7d4b \ + --hash=sha256:5dc6761a6efc781e6a1544206f22c80c3af4c8cf461206d46a1e6006e4429ff3 \ + --hash=sha256:5e84b6cc6a4a3d76c153a6b19270b3526a5a8ed6b09501d3af891daa2a9de7d6 \ + --hash=sha256:635d61f9fbd8176a8674cf78deb7ae2120efded91b7f4400e1cf688b7bfd20ff \ + --hash=sha256:6e9d3cec497f3af115e22e4cfcfb873ec34d8824948a1bf84585f282cad4ae65 \ + --hash=sha256:721f288a22b8c11dd8c1842d9dffb36dc60fc57526e50080006a4ec45e1b6b9e \ + --hash=sha256:8205c5353fbc00ececdf4fbc1eef6d93123481849ee9404fa6659a639e1520b8 \ + --hash=sha256:8d4d5063501b6dd4024b8ac2f04962d661222d120381272deea52e3fc52d3736 \ + --hash=sha256:96e334e6aefd6351a50390480d766cc4b016f54f9b1e2957dbf7b60b38f67b21 \ + --hash=sha256:b15e02e9bb4c21e39876698abf233c8c579127986f8207200bc8a8f6bb27acf2 \ + --hash=sha256:b650012afc6a3aabf574564e929aa38e1638a7b0ad66be08582d06e00861b258 \ + --hash=sha256:c711e74ff7c6ccecf38fcfa86ccd908977c25fbe670e09e14940654c8ccaa2de \ + --hash=sha256:d26a252c34d97a4c8e595182e83bd5e5561621f583a48edbe607fa90abf63042 \ + --hash=sha256:d3a08281dcc4517dc91933befea03770b1327b8aea655592ee7c6b9a84063f2d \ + --hash=sha256:e8731c73977a1bf6f3be6e499c60ea901afe914814ae9dc5dbe03b92f0e06521 +pluggy==0.13.1 \ + --hash=sha256:8421107c23be143ff540859538d9ab530b99911d3f65bf77b625dc93b03c92c3 \ + --hash=sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d + # via pytest +pox==0.3.2 \ + --hash=sha256:56fe2f099ecd8a557b8948082504492de90e8598c34733c9b1fdeca8f7b6de61 \ + --hash=sha256:56fe2f099ecd8a557b8948082504492de90e8598c34733c9b1fdeca8f7b6de61 \ + --hash=sha256:56fe2f099ecd8a557b8948082504492de90e8598c34733c9b1fdeca8f7b6de61 \ + --hash=sha256:56fe2f099ecd8a557b8948082504492de90e8598c34733c9b1fdeca8f7b6de61 \ + --hash=sha256:56fe2f099ecd8a557b8948082504492de90e8598c34733c9b1fdeca8f7b6de61 \ + --hash=sha256:56fe2f099ecd8a557b8948082504492de90e8598c34733c9b1fdeca8f7b6de61 \ + --hash=sha256:56fe2f099ecd8a557b8948082504492de90e8598c34733c9b1fdeca8f7b6de61 \ + --hash=sha256:56fe2f099ecd8a557b8948082504492de90e8598c34733c9b1fdeca8f7b6de61 + # via pathos +ppft==1.7.6.6 \ + --hash=sha256:f355d2caeed8bd7c9e4a860c471f31f7e66d1ada2791ab5458ea7dca15a51e41 + # via pathos +protobuf==4.25.1 \ + --hash=sha256:a19731d5e83ae4737bb2a089605e636077ac001d18781b3cf489b9546c7c80d6 \ + --hash=sha256:ff433d2aa814b498df6c54a8e14b716522b3ea61cb1a16950a25770374383eb1 + # via + # google-api-core + # googleapis-common-protos +psutil==5.9.8 \ + --hash=sha256:048f45fadd4abbff7b2777537149ff17954180c84b0ae8f83e1223dedfe9a9f1 \ + --hash=sha256:14b2aa38686bf66b915482c2985b69eb2d38f6027c6b4dabfbe9f2b6e57b0c09 \ + --hash=sha256:338de09c5db9257deb16d9895558863c832d4af7a809616bbc4400efc99a7bbc \ + --hash=sha256:39f8270b61fdd9647919257ebe588989b2a5e9bf31c2f1598e9aceac897f52c4 \ + --hash=sha256:47998e2bbb7c54add76df84a337bfdc1fe9c325852047da746c7b5bffef06c75 \ + --hash=sha256:52deb67064b88cdc33219b7378ba3959f0c3811b2a1bcfdc10fba05d5a8155ce \ + --hash=sha256:5ae2b403ea7c5c040070b718d1f2276822b88f5562941b51ba7fb6603409cb75 \ + --hash=sha256:84b14ade9c0df00e95bf52a6723a3876ac48ec77b58f77b5c0df11e934bc1cea \ + --hash=sha256:8b523fc1f8baba813c1f4bdb9af601616e6e061fe22229803bcef6d70c248142 \ + --hash=sha256:9230458145f4ef87ad6528bb4747d2bfe254dda325849c26577192823755c09a \ + --hash=sha256:aa4b0dffd73bf962630a7128c0a6b9831f1b750455a262f1fc37cf9930068e84 \ + --hash=sha256:b38e45716e7bb107c65875e47af505023972b3762c68bf36b221786607e301b8 \ + --hash=sha256:c2244067b9e05678afaff2812f86e6742d1467037068dc4795ed0a333f1b0a8f \ + --hash=sha256:d2ef673e3ee83d69238f55dbd6a15f20a840ea10d4e65d7facf73392666dcd66 \ + --hash=sha256:e36c1e1000e2774fafb908f69c564a0e491a448d5f5fcb28bc917586596d8f7b \ + --hash=sha256:f7eb76683ac9558cbf4cef8cc7f859a65ed6412862073862fb3e855e4796d48e +py==1.10.0 \ + --hash=sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a \ + --hash=sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a + # via pytest +pyasn1==0.4.5 \ + --hash=sha256:58bbb1feb769c42205eaf2cfc25fc2075c38f34528bddf7c14306f2f4d40145f \ + --hash=sha256:58bbb1feb769c42205eaf2cfc25fc2075c38f34528bddf7c14306f2f4d40145f \ + --hash=sha256:90aed86e2b1bb2ddf5b208f1c640578f36e8b093b6d93840f8c2fb6c2a50f68c \ + --hash=sha256:da6b43a8c9ae93bc80e2739efb38cc776ba74a886e3e9318d65fe81a8b8a2c6e \ + --hash=sha256:da6b43a8c9ae93bc80e2739efb38cc776ba74a886e3e9318d65fe81a8b8a2c6e \ + --hash=sha256:da6b43a8c9ae93bc80e2739efb38cc776ba74a886e3e9318d65fe81a8b8a2c6e + # via + # oauth2client + # pyasn1-modules + # rsa + # service-identity +pyasn1-modules==0.2.4 \ + --hash=sha256:0d0c7fe74b8a90ca500a4575dd144a901e7243c97529adeeec9f318079aae181 \ + --hash=sha256:79580acf813e3b7d6e69783884e6e83ac94bf4617b36a135b85c599d8a818a7b \ + --hash=sha256:79580acf813e3b7d6e69783884e6e83ac94bf4617b36a135b85c599d8a818a7b \ + --hash=sha256:79580acf813e3b7d6e69783884e6e83ac94bf4617b36a135b85c599d8a818a7b \ + --hash=sha256:79580acf813e3b7d6e69783884e6e83ac94bf4617b36a135b85c599d8a818a7b \ + --hash=sha256:79580acf813e3b7d6e69783884e6e83ac94bf4617b36a135b85c599d8a818a7b \ + --hash=sha256:79580acf813e3b7d6e69783884e6e83ac94bf4617b36a135b85c599d8a818a7b \ + --hash=sha256:79580acf813e3b7d6e69783884e6e83ac94bf4617b36a135b85c599d8a818a7b \ + --hash=sha256:79580acf813e3b7d6e69783884e6e83ac94bf4617b36a135b85c599d8a818a7b \ + --hash=sha256:79580acf813e3b7d6e69783884e6e83ac94bf4617b36a135b85c599d8a818a7b \ + --hash=sha256:79580acf813e3b7d6e69783884e6e83ac94bf4617b36a135b85c599d8a818a7b \ + --hash=sha256:f85c2e8bfac150869a431b58bb77596fd22c02f4206fc7bf71aacc215a2391d5 \ + --hash=sha256:f85c2e8bfac150869a431b58bb77596fd22c02f4206fc7bf71aacc215a2391d5 + # via + # google-auth + # oauth2client + # service-identity +pycparser==2.19 \ + --hash=sha256:0a95ac18b01740fdfdb6e4e9a910d68da6d4e16188908fc9f90a90c365ceebfe \ + --hash=sha256:0b124f28a2dd63b172100564eae285503e3d05e248b340a08ece41dffef30ee8 \ + --hash=sha256:631c2972be26c3c77f523e0b8681e496dbc1813b34f7aa88230a22d98d61447a \ + --hash=sha256:67015b4cf53a668f2d70c9a09a1e062afe677355ceee54cdaeac94897b37c70a \ + --hash=sha256:7353ea66ac83bd9b1d0df4551c8ec1f8fea420e9fc57fb489aff235321266a35 \ + --hash=sha256:e315b9d9958839880f12409b385d4fdc41207a0b392f56ef5ead452489fe7218 \ + --hash=sha256:e315b9d9958839880f12409b385d4fdc41207a0b392f56ef5ead452489fe7218 \ + --hash=sha256:e315b9d9958839880f12409b385d4fdc41207a0b392f56ef5ead452489fe7218 \ + --hash=sha256:e315b9d9958839880f12409b385d4fdc41207a0b392f56ef5ead452489fe7218 \ + --hash=sha256:e315b9d9958839880f12409b385d4fdc41207a0b392f56ef5ead452489fe7218 \ + --hash=sha256:e315b9d9958839880f12409b385d4fdc41207a0b392f56ef5ead452489fe7218 \ + --hash=sha256:e315b9d9958839880f12409b385d4fdc41207a0b392f56ef5ead452489fe7218 \ + --hash=sha256:e315b9d9958839880f12409b385d4fdc41207a0b392f56ef5ead452489fe7218 + # via cffi +pyfakefs==3.7.2 \ + --hash=sha256:8259042941a0690b89d92d55ed8fb1720ca4a83db87713d2fb9717cfd5e5f18e \ + --hash=sha256:9b3718c246ec98ca8269c6d19e9c33c1cc3af32e22bf189bddb921bc7fc16e39 \ + --hash=sha256:9e98f7179507c650ce17824e6493a4effef03e726ffe9f84917f5800266edcc9 \ + --hash=sha256:f415f38fe488b46974700af95f22b37e951a51159403eb9011ca37db0fde8b97 \ + --hash=sha256:f415f38fe488b46974700af95f22b37e951a51159403eb9011ca37db0fde8b97 \ + --hash=sha256:f415f38fe488b46974700af95f22b37e951a51159403eb9011ca37db0fde8b97 +pylsqpack==0.3.12 \ + --hash=sha256:0bbb56fd2d4d3a76fca985ba82db4738a96e01f4b9af8abe6979ce5265265cd7 \ + --hash=sha256:458b00d38d6cb79c9c60c04945392e1a80ff8504ea8e26a95d9d74cf5e509873 \ + --hash=sha256:5d2451d7855c41cd394a3ebc35b349e7d4086556339e8c25950f4dc8639cf9cb \ + --hash=sha256:65528edbbb2754b018a9b0c4a28fd2199c9c18cf5732b3844807db13fd8c52e5 \ + --hash=sha256:695da4bc1d597ae4c77f9468c22d56d17e6d5c6b758df20915bc083515d3de0a \ + --hash=sha256:7b14af83f1adbc2ef1da48514f309e99ba03ac9a67eada9409738ec3abfdf9bb \ + --hash=sha256:8410c3cd5ead8df2eee83df07b01ebab8be62e3c2f3d643587a0cb0a727bea4b \ + --hash=sha256:90cbbb01550fd7ddc41d89debcead03624f95b40148a195f11347e916f3a0259 \ + --hash=sha256:9423ca122fb276052490978ea60a389cad97db8be6dcd7382523d580b329edff \ + --hash=sha256:b3c8e1d15b944fc74b02ac1529bf8cf4702f50367d4015907a5575dd2710d1ba \ + --hash=sha256:b3c8e1d15b944fc74b02ac1529bf8cf4702f50367d4015907a5575dd2710d1ba \ + --hash=sha256:b9696910c4fecccffbb9d576b6a9dfb42709f69056b93c37c3d9552ea521155b \ + --hash=sha256:c1afb58dcd895c06ab4714acadaff1f239f2b6e3b6d0fe3d40d75af11bb1fc86 \ + --hash=sha256:e6f3932e4b72215e87739863b08db7da226e89d8652495f4c5d16dbccb747577 + # via aioquic +pyobjc==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1cc046cb45aaccb34d9b1c04f631102f0e012aeae36e032c4c5b26b0a2a0890b \ + --hash=sha256:3b878065a1dcea5a5bc7821a815f68fb4899684f3ff90a5c9e34d5654355d090 \ + --hash=sha256:49dd78e35d11e2abea30bf331641bb44a68bb4546c65467f23c707ee349ee6a0 \ + --hash=sha256:ea39b44bb15701bb86747f4aac6dd8c0ab0cf4bf13a9550848d9837bff8f88ac +pyobjc-core==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:02d0a674a86fc0ae19ec19592bb58bd3dc995fa45885e266b9d779d8f1fabb36 \ + --hash=sha256:0d5b711d1cc49f471e7b3ce298faec5b84f9a14955941d92af055fb21ab5bfed \ + --hash=sha256:45c6ca02801171697e7d7b1916a8a0b8c651e1ef9c3c6ac7548c89dc0c706e5e \ + --hash=sha256:f1f584a85c7d77dd815aad2e65da1d718f5211c511e59ca1cfe5c287ecb27782 + # via + # pyobjc + # pyobjc-framework-accounts + # pyobjc-framework-addressbook + # pyobjc-framework-adsupport + # pyobjc-framework-applescriptkit + # pyobjc-framework-applescriptobjc + # pyobjc-framework-applicationservices + # pyobjc-framework-audiovideobridging + # pyobjc-framework-authenticationservices + # pyobjc-framework-automaticassessmentconfiguration + # pyobjc-framework-automator + # pyobjc-framework-avfoundation + # pyobjc-framework-avkit + # pyobjc-framework-businesschat + # pyobjc-framework-calendarstore + # pyobjc-framework-cfnetwork + # pyobjc-framework-cloudkit + # pyobjc-framework-cocoa + # pyobjc-framework-collaboration + # pyobjc-framework-colorsync + # pyobjc-framework-contacts + # pyobjc-framework-contactsui + # pyobjc-framework-coreaudio + # pyobjc-framework-coreaudiokit + # pyobjc-framework-corebluetooth + # pyobjc-framework-coredata + # pyobjc-framework-corehaptics + # pyobjc-framework-corelocation + # pyobjc-framework-coremedia + # pyobjc-framework-coremediaio + # pyobjc-framework-coremidi + # pyobjc-framework-coreml + # pyobjc-framework-coremotion + # pyobjc-framework-coreservices + # pyobjc-framework-corespotlight + # pyobjc-framework-coretext + # pyobjc-framework-corewlan + # pyobjc-framework-cryptotokenkit + # pyobjc-framework-devicecheck + # pyobjc-framework-dictionaryservices + # pyobjc-framework-discrecording + # pyobjc-framework-discrecordingui + # pyobjc-framework-diskarbitration + # pyobjc-framework-dvdplayback + # pyobjc-framework-eventkit + # pyobjc-framework-exceptionhandling + # pyobjc-framework-executionpolicy + # pyobjc-framework-externalaccessory + # pyobjc-framework-fileprovider + # pyobjc-framework-fileproviderui + # pyobjc-framework-findersync + # pyobjc-framework-fsevents + # pyobjc-framework-gamecenter + # pyobjc-framework-gamecontroller + # pyobjc-framework-gamekit + # pyobjc-framework-gameplaykit + # pyobjc-framework-imagecapturecore + # pyobjc-framework-inputmethodkit + # pyobjc-framework-installerplugins + # pyobjc-framework-instantmessage + # pyobjc-framework-intents + # pyobjc-framework-iobluetooth + # pyobjc-framework-iobluetoothui + # pyobjc-framework-iosurface + # pyobjc-framework-ituneslibrary + # pyobjc-framework-latentsemanticmapping + # pyobjc-framework-launchservices + # pyobjc-framework-libdispatch + # pyobjc-framework-libxpc + # pyobjc-framework-linkpresentation + # pyobjc-framework-localauthentication + # pyobjc-framework-mapkit + # pyobjc-framework-mediaaccessibility + # pyobjc-framework-medialibrary + # pyobjc-framework-mediaplayer + # pyobjc-framework-mediatoolbox + # pyobjc-framework-metal + # pyobjc-framework-metalkit + # pyobjc-framework-metalperformanceshaders + # pyobjc-framework-modelio + # pyobjc-framework-multipeerconnectivity + # pyobjc-framework-naturallanguage + # pyobjc-framework-netfs + # pyobjc-framework-network + # pyobjc-framework-networkextension + # pyobjc-framework-notificationcenter + # pyobjc-framework-opendirectory + # pyobjc-framework-osakit + # pyobjc-framework-oslog + # pyobjc-framework-pencilkit + # pyobjc-framework-photos + # pyobjc-framework-photosui + # pyobjc-framework-preferencepanes + # pyobjc-framework-pubsub + # pyobjc-framework-pushkit + # pyobjc-framework-quartz + # pyobjc-framework-quicklookthumbnailing + # pyobjc-framework-safariservices + # pyobjc-framework-scenekit + # pyobjc-framework-screensaver + # pyobjc-framework-scriptingbridge + # pyobjc-framework-searchkit + # pyobjc-framework-security + # pyobjc-framework-securityfoundation + # pyobjc-framework-securityinterface + # pyobjc-framework-servicemanagement + # pyobjc-framework-social + # pyobjc-framework-soundanalysis + # pyobjc-framework-speech + # pyobjc-framework-spritekit + # pyobjc-framework-storekit + # pyobjc-framework-syncservices + # pyobjc-framework-systemconfiguration + # pyobjc-framework-systemextensions + # pyobjc-framework-usernotifications + # pyobjc-framework-videosubscriberaccount + # pyobjc-framework-videotoolbox + # pyobjc-framework-vision + # pyobjc-framework-webkit +pyobjc-framework-accounts==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:519e28359a3144cfec7adbbc4cf8136706b9bfc2d9f7ba34b84802297fe39499 \ + --hash=sha256:519e28359a3144cfec7adbbc4cf8136706b9bfc2d9f7ba34b84802297fe39499 \ + --hash=sha256:519e28359a3144cfec7adbbc4cf8136706b9bfc2d9f7ba34b84802297fe39499 \ + --hash=sha256:ac870dd990d5e184dfb47d314627af342f5d71935881e98cdff2bba083582fd5 + # via + # pyobjc + # pyobjc-framework-cloudkit +pyobjc-framework-addressbook==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:534412e5adab44bc799d87a7e7247d19259739cdf1cb935090e438ddc2d00882 \ + --hash=sha256:55347434ea271a89c807a89344c8f420a810a1479076294b080ed1914c8184da \ + --hash=sha256:5fe07df44850074a02f37e84c97ccd07659ec1c8c753f87d410ce1cc0bb6aa7b \ + --hash=sha256:95783846dcef30ad056746907b4b156fae6e3cf3827e222395bb2002bc1b73dd + # via pyobjc +pyobjc-framework-adsupport==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:31060beb83841f6ffd4fb6c6bfab6d537a51192720ef7b554661d5432570a052 \ + --hash=sha256:c3f0258c288313baec5db08f650d9fba6e0455a2f09b86e916e90df21efb0e78 \ + --hash=sha256:eff4562cc80c25876f1659adc4133c1b35a2799050c7fc99796a551bb2649627 \ + --hash=sha256:eff4562cc80c25876f1659adc4133c1b35a2799050c7fc99796a551bb2649627 + # via pyobjc +pyobjc-framework-applescriptkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:3a4212f6015678a37414757cc8f9bffba9080af8a7c59a996bdb5aaaa481dbe4 \ + --hash=sha256:dfa3df63532214d7dfd345776c0dd0d6ecc95ffa52950e507f56495218234b96 \ + --hash=sha256:dfa3df63532214d7dfd345776c0dd0d6ecc95ffa52950e507f56495218234b96 \ + --hash=sha256:f7020b37cbcb01ba88638f3af35b62d541b3266360cd8be1a15d5e899a701c08 + # via pyobjc +pyobjc-framework-applescriptobjc==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:24601d5773bf46be4654650cc119860e07f9e99778856b581d7db9237f32c633 \ + --hash=sha256:24601d5773bf46be4654650cc119860e07f9e99778856b581d7db9237f32c633 \ + --hash=sha256:c1109ad7fe08abc53e4d9971d77f3878e0c2422b008737a404d716e28301d7f6 \ + --hash=sha256:e305081556cf4b75adaa807b7e3e424ee949e685f47682dc6c2092e9587fe012 + # via pyobjc +pyobjc-framework-applicationservices==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:0482704c28e52d702df654e879d2a5eff073305ffe523a69eab7c94f68dff670 \ + --hash=sha256:56435724dca1779a19421a253a84a34cf398af0ac1e644b9906e8b035a8d4e9b \ + --hash=sha256:a55b35f9990488287aa4bd9f6ce6d146b192c5e665c0b22e2e6517bc470a1c1e \ + --hash=sha256:ce10afeb4a601f48f758d41b9887610947d78ff20163e5e9b383a0a5b97fabd8 + # via pyobjc +pyobjc-framework-audiovideobridging==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:4f97c1378712ce96e368cb027bffcf84dc380985da0a2df9763f95a4d00ffe24 \ + --hash=sha256:512e1d92897ce6956719661349a43905abe69fe842357d40c9af79ddf996338d \ + --hash=sha256:97954ded73eb0d465405a67176bbf12a14deec8688bf37a8979e42088d14837e \ + --hash=sha256:97954ded73eb0d465405a67176bbf12a14deec8688bf37a8979e42088d14837e + # via pyobjc +pyobjc-framework-authenticationservices==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:13680c98d5582cd02293ec18b2c03359129edf3ae54d961b80196f01a0639525 \ + --hash=sha256:52592293003563ffbf10ac226b49e8d066ff7ecb74d93bb4cfa26f40922a4980 \ + --hash=sha256:8c8dc4b20143e9501567d02e3d80f913f306035dda1d5ba641a6b74464da42f7 \ + --hash=sha256:fee53c77bb665ddfaabdfd898c3d7000efc8e94181d8f946cbca01e55720aaac + # via pyobjc +pyobjc-framework-automaticassessmentconfiguration==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1695816971e09b684206bfe5983083067b04cd8a00a1668752a0882c15a2aa9e \ + --hash=sha256:6908e94c74b6d1b0a0e8edbef57b6a4c90e2a44dcb72e299a76e6fee15524847 \ + --hash=sha256:97bea072d37ed8b5ce541bd821a78cd48de5b63d6f0d55cffcee7e5a6c756428 \ + --hash=sha256:ee0b15954ff9583cf4d5d89fcce95d2ef2e48c6bbf2f2ff23b452caa02610d49 + # via pyobjc +pyobjc-framework-automator==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:0ab20df31e526f0b049487724fb7ea27c811065bfbf5b69486685688e0f3a499 \ + --hash=sha256:160cefc779519f5b3afc2daad5c9af9f93b5827dd704377a910e98ed378ed065 \ + --hash=sha256:160cefc779519f5b3afc2daad5c9af9f93b5827dd704377a910e98ed378ed065 \ + --hash=sha256:d9f82a8d6aebfa3f46f764a67e66142c68b6214cc62579db9fd61ad95274ac5d + # via pyobjc +pyobjc-framework-avfoundation==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:027db0bb63c40e3f6b116ab20bbf51749e7d42ec17b626e3bfb2c32d6249d97e \ + --hash=sha256:304815544be66c56c367cdd815bab054f82e138284b027dc812c747a973397a6 \ + --hash=sha256:81ba59ed0de8b8c9e3230f94aae7744ecc7ad4facb66381d44e857399ce67128 \ + --hash=sha256:ab9d1b21ea2ce7b01030b549029ee2a3146cdb1734d2e4ca07fca394c8d00362 + # via + # pyobjc + # pyobjc-framework-mediaplayer +pyobjc-framework-avkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1823907932e185c6de552fa23bc0307db05fe40737e06afa4bd21f61f616867d \ + --hash=sha256:5ffda7e7595070720277f43d7c55bbc5ce1bcca757a4d6400a0b99bc0289f643 \ + --hash=sha256:6d5db4368a402c4be4c02d15b1ef6ccd921bd557d380356c940eec30df5eb8e4 \ + --hash=sha256:909b16edc8aff3763b10872afa910dc24e0aa5cd526580cef1b022b4f91775da + # via pyobjc +pyobjc-framework-businesschat==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:badcd9dfe1a97fa460e39aec5d9e1fcfbb9c5a271f8b58301dd488a4c0bc6a02 \ + --hash=sha256:badcd9dfe1a97fa460e39aec5d9e1fcfbb9c5a271f8b58301dd488a4c0bc6a02 \ + --hash=sha256:f52fdaad5af7759ee1df4a3c3db45a025b2e3989cfe6e5879d5927b60bdf9259 \ + --hash=sha256:f851eb32f3722a345267cd8accaacd3535d01a4e1750a1e5c4b989c9b4ca4948 + # via pyobjc +pyobjc-framework-calendarstore==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:26d576b80a054a502e569b977b07df5afd195b9e63c036cab018805dfbde7e0d \ + --hash=sha256:4b392d396f48b2990c4fdef4bd253a839723d02f8faa0007c63b0a11186a4ace \ + --hash=sha256:8d5a52bf2c9f42ddb1d2dd9cbb73bd10765e101e26200f9518ce6af55fdf4c12 \ + --hash=sha256:8d5a52bf2c9f42ddb1d2dd9cbb73bd10765e101e26200f9518ce6af55fdf4c12 + # via pyobjc +pyobjc-framework-cfnetwork==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:540caeafea6560335eae7cc2e2c9639c9dd6253bcf65517fb2b5c8c5e58ce820 \ + --hash=sha256:65d5bb0a146b1f4531631c1a1e8ca90fdc5fc4448331b77848c87512e1c27833 \ + --hash=sha256:729e053a58c90871d65e1b65ab5d1eeb4794aca97b03668154677390565786ed \ + --hash=sha256:ba7801708c0b38980552966daf9d26e68da6c29d8e0d0e4f2a3f259c3b54455d + # via pyobjc +pyobjc-framework-cloudkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:8b4a0cfc5614c88e0d328357a1a7bb7b2e8a2de1f68f31621c0f3ab4d226b32e \ + --hash=sha256:a76aca73ed9c961fb10cada82970d2ef6d01604bc97b4ee4e9a59bae8ce4f22c \ + --hash=sha256:a76aca73ed9c961fb10cada82970d2ef6d01604bc97b4ee4e9a59bae8ce4f22c \ + --hash=sha256:a81b5bc266fdfb26afede14d075bebf0700340f6bfdf299dcdeb0fc2f2b6ef41 + # via pyobjc +pyobjc-framework-cocoa==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:08a22ede8cba3ab93dac216a3be9a79e7546f13d578536975f94dd05b876fb77 \ + --hash=sha256:93e2b103677bb0b814e75b03e959f2cb07f2914f1ff6b4b6acd07ee1e209ea86 \ + --hash=sha256:bf21e38e3aa6e326da6668f94b24f2dbba6bdb124b5b8e6bdc60d9d238f98a14 \ + --hash=sha256:d29c9586eb647c14531904dc302189e37c95241d8b8509cbce150cadc5b8b16d + # via + # pyobjc + # pyobjc-framework-accounts + # pyobjc-framework-addressbook + # pyobjc-framework-adsupport + # pyobjc-framework-applescriptkit + # pyobjc-framework-applescriptobjc + # pyobjc-framework-applicationservices + # pyobjc-framework-audiovideobridging + # pyobjc-framework-authenticationservices + # pyobjc-framework-automaticassessmentconfiguration + # pyobjc-framework-automator + # pyobjc-framework-avfoundation + # pyobjc-framework-avkit + # pyobjc-framework-businesschat + # pyobjc-framework-calendarstore + # pyobjc-framework-cfnetwork + # pyobjc-framework-cloudkit + # pyobjc-framework-collaboration + # pyobjc-framework-colorsync + # pyobjc-framework-contacts + # pyobjc-framework-contactsui + # pyobjc-framework-coreaudio + # pyobjc-framework-coreaudiokit + # pyobjc-framework-corebluetooth + # pyobjc-framework-coredata + # pyobjc-framework-corehaptics + # pyobjc-framework-corelocation + # pyobjc-framework-coremedia + # pyobjc-framework-coremediaio + # pyobjc-framework-coremidi + # pyobjc-framework-coreml + # pyobjc-framework-coremotion + # pyobjc-framework-corespotlight + # pyobjc-framework-coretext + # pyobjc-framework-corewlan + # pyobjc-framework-cryptotokenkit + # pyobjc-framework-devicecheck + # pyobjc-framework-discrecording + # pyobjc-framework-discrecordingui + # pyobjc-framework-diskarbitration + # pyobjc-framework-dvdplayback + # pyobjc-framework-eventkit + # pyobjc-framework-exceptionhandling + # pyobjc-framework-executionpolicy + # pyobjc-framework-externalaccessory + # pyobjc-framework-fileprovider + # pyobjc-framework-findersync + # pyobjc-framework-fsevents + # pyobjc-framework-gamecenter + # pyobjc-framework-gamecontroller + # pyobjc-framework-gamekit + # pyobjc-framework-gameplaykit + # pyobjc-framework-imagecapturecore + # pyobjc-framework-inputmethodkit + # pyobjc-framework-installerplugins + # pyobjc-framework-instantmessage + # pyobjc-framework-intents + # pyobjc-framework-iobluetooth + # pyobjc-framework-iosurface + # pyobjc-framework-ituneslibrary + # pyobjc-framework-latentsemanticmapping + # pyobjc-framework-linkpresentation + # pyobjc-framework-localauthentication + # pyobjc-framework-mapkit + # pyobjc-framework-mediaaccessibility + # pyobjc-framework-medialibrary + # pyobjc-framework-mediatoolbox + # pyobjc-framework-metal + # pyobjc-framework-metalkit + # pyobjc-framework-modelio + # pyobjc-framework-multipeerconnectivity + # pyobjc-framework-naturallanguage + # pyobjc-framework-netfs + # pyobjc-framework-network + # pyobjc-framework-networkextension + # pyobjc-framework-notificationcenter + # pyobjc-framework-opendirectory + # pyobjc-framework-osakit + # pyobjc-framework-oslog + # pyobjc-framework-pencilkit + # pyobjc-framework-photos + # pyobjc-framework-photosui + # pyobjc-framework-preferencepanes + # pyobjc-framework-pubsub + # pyobjc-framework-pushkit + # pyobjc-framework-quartz + # pyobjc-framework-quicklookthumbnailing + # pyobjc-framework-safariservices + # pyobjc-framework-scenekit + # pyobjc-framework-screensaver + # pyobjc-framework-scriptingbridge + # pyobjc-framework-security + # pyobjc-framework-securityfoundation + # pyobjc-framework-securityinterface + # pyobjc-framework-servicemanagement + # pyobjc-framework-social + # pyobjc-framework-soundanalysis + # pyobjc-framework-speech + # pyobjc-framework-spritekit + # pyobjc-framework-storekit + # pyobjc-framework-syncservices + # pyobjc-framework-systemconfiguration + # pyobjc-framework-systemextensions + # pyobjc-framework-usernotifications + # pyobjc-framework-videosubscriberaccount + # pyobjc-framework-videotoolbox + # pyobjc-framework-vision + # pyobjc-framework-webkit +pyobjc-framework-collaboration==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:c8c7f65b271f37d06dfed4af7b228008b24117edbe9c2b6cb4fa739ce42a184e \ + --hash=sha256:f3cbea0595f9ec4ea8072573f75eaf8ce0740009bf81e53bebed409a774406ca \ + --hash=sha256:f3cbea0595f9ec4ea8072573f75eaf8ce0740009bf81e53bebed409a774406ca \ + --hash=sha256:f3cbea0595f9ec4ea8072573f75eaf8ce0740009bf81e53bebed409a774406ca + # via pyobjc +pyobjc-framework-colorsync==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:3f9d3c0f6c9ad96b256f4e0eccef73f7dea500f3ecc36a10a8fe16cba3d78d68 \ + --hash=sha256:3f9d3c0f6c9ad96b256f4e0eccef73f7dea500f3ecc36a10a8fe16cba3d78d68 \ + --hash=sha256:3f9d3c0f6c9ad96b256f4e0eccef73f7dea500f3ecc36a10a8fe16cba3d78d68 \ + --hash=sha256:934700933994ccf58695d49cbfa28b2138a6885462914dd93847910ac48ec912 + # via pyobjc +pyobjc-framework-contacts==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:2ebe8c9d120f46ceb923f37cc58245512b2ebdf986cb51f2bdc94092554d4f06 \ + --hash=sha256:59826b286e4be9456c0405dc872a4b8b746578cf7d03cd2695f331baf2fb55af \ + --hash=sha256:919001923baaa2903bb687c6a2365d8a7646580e573da4d6a3a83b05489c1971 \ + --hash=sha256:ab9196d0bfe38a24c4e645c466301507f322f7574348100491bc0a5106d3f4bc + # via + # pyobjc + # pyobjc-framework-contactsui +pyobjc-framework-contactsui==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:7740d9d68cc10271443b69c1f8a1cd52dc618e3b7330088582a992816671916a \ + --hash=sha256:a911ee29b0d701c9b77a7c8f655c84f565b560da623f7f654264f1c4e3f3a13c \ + --hash=sha256:df5031428fecf3055aa7986859b523a37cf80cba0aa802e4f403a283c111961d \ + --hash=sha256:f2e0a05b1b370fa55d05718cde916b3e0460eba5b848881f1e880f79cfe1ac6a + # via pyobjc +pyobjc-framework-coreaudio==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:2c86a13859740665aaa8edd6029aead3bc08adaedf86e74f49c4416d89fb77f6 \ + --hash=sha256:7e4622ff6bbbabcf596da1c5e9dff923b4aa1fac0db93dc72dfac318a72a6aa4 \ + --hash=sha256:a49426dd5eaa5991e971f67bb1a328e9a6681959be46004cbc715f7013ac45a9 \ + --hash=sha256:e2b7f55db3edf599a5bf13df0dbebb2c4281b14161ba68a7889e54f6aaa10cf4 + # via + # pyobjc + # pyobjc-framework-avfoundation + # pyobjc-framework-coreaudiokit +pyobjc-framework-coreaudiokit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:5d7979ab8f8af1b9154b682eff3f2ac58720b5782686f86683f8cecbb811db8d \ + --hash=sha256:7d188105da7acd29fe5b0e1836dbecb93350105cb51bdf7bf6fcb4a8e6f8797a \ + --hash=sha256:8155057538c15720b97afadfc7fe69846b06647e767d05d04ea1ae08ea8d9c0f \ + --hash=sha256:e1d9fe8517300472053057b6d0604f0342b052942848613eb7ffbf9be9d45937 + # via pyobjc +pyobjc-framework-corebluetooth==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:13a6338ee65dff08466851131dd7e6eb5f08acc4821ca48633f0872e0fe8b282 \ + --hash=sha256:961ac9be9f46e058c876097a9f9334111aec92ed917522ab0b9313536a3a5ff8 \ + --hash=sha256:9cbb9376f0307dfbb711328826e76b50da75bd01547a9f1f56286f1a0174ff38 \ + --hash=sha256:af540b321314227ea3b92bd3729a00280f50f7379571810419e6e542b776e1e9 \ + --hash=sha256:df4e40d17d755a887b701d7255bef89a64139ef5431f3b2781825854ed17f280 + # via pyobjc +pyobjc-framework-coredata==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:de944867061c32afc6ae82af0dbac4c756f56929a3fbca815dc1949625f17fb4 \ + --hash=sha256:df38856b6295626ffdd30944c407e0aa4d9597c6669244dd810043ab9b5e4aaf \ + --hash=sha256:e1426496c099f2e8183ce6970df800a1144cf0f6b72ff7dfca0939e205cf360b \ + --hash=sha256:f8b4c66909469b90504130b54df953a39e7e279b17161e9c91e495a02d4e6344 + # via + # pyobjc + # pyobjc-framework-cloudkit + # pyobjc-framework-syncservices +pyobjc-framework-corehaptics==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:457774c6007c78136a6c2cc7e1d8a0070ac65b9fef6d059392a8931b3e52381a \ + --hash=sha256:adb746f0aa3136b7d91c7531f7d67453203684fe7b93eb496ff9961c4377e046 \ + --hash=sha256:adb746f0aa3136b7d91c7531f7d67453203684fe7b93eb496ff9961c4377e046 \ + --hash=sha256:f28fb3cb4fe37d38e9c7b9960ddbfc872664fdbcef4e4afe8b6769fb480463ac + # via pyobjc +pyobjc-framework-corelocation==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:4a953b93788d5a31c6bdc87c41201ae55e1318407bf0cec99ac0c9217178f4dd \ + --hash=sha256:62888393ee3958eaeb18c5e96c2464726a13f50ec8000b8ab86c6dae89003566 \ + --hash=sha256:8de1ba44b98bdd12d48605694cf648671962e27a585a6ff0e162916cdc71634e \ + --hash=sha256:96317eebb54a64f3ef243502065c3e515becab5436d7e11d2ab9ff2c610f2e06 + # via + # pyobjc + # pyobjc-framework-cloudkit + # pyobjc-framework-mapkit +pyobjc-framework-coremedia==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:9bcabfbe1d700de44653b6ef56b20ee8a2666d561407d372c80ae02d97eee4a2 \ + --hash=sha256:c365aa3cb00694e62c235dbfaeee6377f87d0a0dda17bf866ac5b47969e503ca \ + --hash=sha256:e87394fdb45707e027b3b11b2a70c59fb5bdacd9341bba3490b05d9e74641925 \ + --hash=sha256:fe7f6728308a51dc45bd9d898d9b69d4a1d2c06f4a5793d6e8e74f3c5c184c35 + # via + # pyobjc + # pyobjc-framework-avfoundation + # pyobjc-framework-oslog + # pyobjc-framework-videotoolbox +pyobjc-framework-coremediaio==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:09ed675a443ce55704a3734b5aa9a34f50e855b6720d8ab35a49794243907e43 \ + --hash=sha256:0e9b3d4a3e4461114462332854b00e1af6942e25b798c81977acdc542324ccda \ + --hash=sha256:1de6e69649251772587fce29ce2f3e4f9e47bb7f2eb22e47b9cf616fde5bd3c7 \ + --hash=sha256:325223c061f9fb37886c9ff9a00e590971ded5e1844ca2da4c4f76a4d1c20d13 + # via pyobjc +pyobjc-framework-coremidi==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:47c2d23e592ae69b554a80ab99d3a668322cbf42a90e5131d4c16d8c516b48fd \ + --hash=sha256:5c128011244f333f13915f3f27a258244902bfbc676746471fd6e03108410271 \ + --hash=sha256:bfd372170ce3cb95d514afdd31c1df27e316414b37066ce8eacb999c662a48ab \ + --hash=sha256:defb9f064158c81ebe5f7882337474bd9bc91b2cb643c0db2cf3675d2bef5aae + # via pyobjc +pyobjc-framework-coreml==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:0d3b4b7aca34fe83b0b0e3c77c6b884a5172bcf6d9e87d13520568dc35df50ec \ + --hash=sha256:7fafbcd6da6a36494e974c09cf5b6b322953ed78547da43a39b2597695a95e21 \ + --hash=sha256:d29bad388f42eb0561d66d2eabdb34ba2bbca3a0b71df9de7e8de99991125dd2 \ + --hash=sha256:e78b6788f21d8883e2ef6b8b297cf45717ca3af6c1d8baaae4be79e2bd6172e6 + # via + # pyobjc + # pyobjc-framework-vision +pyobjc-framework-coremotion==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:0fbf4fe506b5dd195aaedbbd61381fbc19bd088f4115ea5d54159c86cef6f259 \ + --hash=sha256:362b2c0a5b07ed3399fc59e23cc95d54e6b53bee71395ed17f6b467c3ec3bbce \ + --hash=sha256:8dfb44b07c5ec50ffd17865f1faeab2eb36e09281aa3f59dfc199c5f431a5541 \ + --hash=sha256:a93fa4aed245aa1af19d30f9e70dbec4c75dd38609d4d9a536150a4f448db74a + # via pyobjc +pyobjc-framework-coreservices==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:715ee843718f9e7d7e4b0de2dbc49b9205032fa163b1eb015d61206d1cc07512 \ + --hash=sha256:b1f4fac38b2a9dd0a2b1146d634212a23decda3506292a1b493cbf57bfd47bcb \ + --hash=sha256:b6d55920868020ffd5f67f54b7f7b101a3d99b36d8ef634ba8797a4bbf6f9b45 \ + --hash=sha256:d60dc5f0078826176c4ecdce31ddd6c799050bef05c4261a121485b798a9ced9 + # via + # pyobjc + # pyobjc-framework-dictionaryservices + # pyobjc-framework-launchservices + # pyobjc-framework-searchkit +pyobjc-framework-corespotlight==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:2aed583a34dd835dfdd667b92f2eb6a06b048414688053fe5db7be3854a5d992 \ + --hash=sha256:39f2223e094769c9121a2b304b16a7a1d5c95c1efdb3fda2bb5987bc2e87604f \ + --hash=sha256:406532292cc64bef5ab06b74d15f3ed92754dfb14971696c5564806e47ea7b0f \ + --hash=sha256:ff0fccaac19702b5a251cbabb0785dda78fc6827a5ec99c33e3249045f6fcb6e + # via pyobjc +pyobjc-framework-coretext==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:076a963b0438c5b4fa380dd7a521028891e2f4dbe7e87daef0462cb285a66896 \ + --hash=sha256:7591ff17c6aa2641727341aacb0675105b3ff0410fae7c20e11a9ab26dc154c8 \ + --hash=sha256:de6f1d040a09c94a4c156628ae8593c2cb0ddff814603941a214b71876de4a4a \ + --hash=sha256:e6d242e7e4ed62431dff952b90c18c2deb1cb332d472f51db1e5ca66a06dedcf + # via pyobjc +pyobjc-framework-corewlan==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:0dabd26dda1c68d90cdaf996175888830ec06177c7f4513622ace6fc91ac0b6c \ + --hash=sha256:3007e20dc45cdd3d395f166063446938bb597e88e6a005e594cc76b83f991ef6 \ + --hash=sha256:38bd451577c07f7d1162dd187400773ae120c9c05fec1ff910d4a0474f84046e \ + --hash=sha256:a09f1986b92b84de09ac2d3e1136c93da4e051a89d59a639f47f4901e0317a33 + # via pyobjc +pyobjc-framework-cryptotokenkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:39e592aa144a8cfe7dadc04d1e91775f6f1a4e598630c34510fa6e8fae42d14e \ + --hash=sha256:930843a526f95eacf23b05bbc1e56bd116303ff2f0bdf4d0e210c1de7c14952d \ + --hash=sha256:abaf92e04fa73c030ea43f72d1ab13331c6ff5800b41532980ff3cbf1a733212 \ + --hash=sha256:cb1896d93aefb7acc6eec22e8a2d095e2abf43cf4ff2dcc605b72e42f6a7fedb + # via pyobjc +pyobjc-framework-devicecheck==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:581b92945ae2ab4e0e95224113f25b63774689ac8d392a234d09d5b5ff09ec41 \ + --hash=sha256:581b92945ae2ab4e0e95224113f25b63774689ac8d392a234d09d5b5ff09ec41 \ + --hash=sha256:581b92945ae2ab4e0e95224113f25b63774689ac8d392a234d09d5b5ff09ec41 \ + --hash=sha256:911f5eb7b2f4080577d4331483cb24ab36b3310e5a6ac9f5681ed9066249c535 + # via pyobjc +pyobjc-framework-dictionaryservices==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:5a0a526356826e3f855d6e551a0521a9fb1719b76ce9c33d00c6fa2f58fa49bb \ + --hash=sha256:5a0a526356826e3f855d6e551a0521a9fb1719b76ce9c33d00c6fa2f58fa49bb \ + --hash=sha256:5a0a526356826e3f855d6e551a0521a9fb1719b76ce9c33d00c6fa2f58fa49bb \ + --hash=sha256:6a398871acd1ef85855877292987384aa4ff2c9624e260853616eeb03120416c + # via pyobjc +pyobjc-framework-discrecording==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:934ac640f189797534824f3ca5ddb2c21cb8cf9b6f5864457eb399169ad485ad \ + --hash=sha256:9504d5d55194dfb7ad09c3c13609d9a7d2df0c7d3221402097cf75485f158615 \ + --hash=sha256:b1c7f85978049e5787de6881cca58dd16790e6c6856a09f2567eda52c94e99fa \ + --hash=sha256:dd728b91987a2bb5c7e80d09d62abbd2ff26a079d4b319c35fef437db3554035 + # via + # pyobjc + # pyobjc-framework-discrecordingui +pyobjc-framework-discrecordingui==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:473a634eb76069aa9a105e914dec7dbb886036b0d9e04bcee9f920c51cb0d3e7 \ + --hash=sha256:473a634eb76069aa9a105e914dec7dbb886036b0d9e04bcee9f920c51cb0d3e7 \ + --hash=sha256:473a634eb76069aa9a105e914dec7dbb886036b0d9e04bcee9f920c51cb0d3e7 \ + --hash=sha256:a274930dd19c324dc94e6e319f1623accb70f62f6d3a66b745e63420741a822c + # via pyobjc +pyobjc-framework-diskarbitration==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:17441138d7c142117efb94c856ce5a3b481ea5a7908c7593b5e2a5c135752323 \ + --hash=sha256:17441138d7c142117efb94c856ce5a3b481ea5a7908c7593b5e2a5c135752323 \ + --hash=sha256:17441138d7c142117efb94c856ce5a3b481ea5a7908c7593b5e2a5c135752323 \ + --hash=sha256:9fcc49a36daabcaf2c308c1818a550a5d34c5c83721bad3d2497cd3047b22cd5 + # via pyobjc +pyobjc-framework-dvdplayback==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:191f1b2abe33f065fbb776462f43b4cb5a8a5bfefa488b5f9332d2785e8b1062 \ + --hash=sha256:5c7eb8935a3cb70d46bb4317dadfc32b68b702d6eb9acd22dd8970c790d6b4cc \ + --hash=sha256:5c7eb8935a3cb70d46bb4317dadfc32b68b702d6eb9acd22dd8970c790d6b4cc \ + --hash=sha256:5c7eb8935a3cb70d46bb4317dadfc32b68b702d6eb9acd22dd8970c790d6b4cc + # via pyobjc +pyobjc-framework-eventkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:064f1d1bb3caee2c914018ecc9d52a4872a77946e86e6ede9bd3a577df001eb1 \ + --hash=sha256:5205fa87d02ec6e37f83a611788d57dfcb74c94ddbf484209eebc5f619852dd4 \ + --hash=sha256:c7ce0148405370ecf38878d45d95adddf74e3d7b4c58254fae0e9228c14d8c4d \ + --hash=sha256:c7ce0148405370ecf38878d45d95adddf74e3d7b4c58254fae0e9228c14d8c4d + # via pyobjc +pyobjc-framework-exceptionhandling==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:192d9869af5593cf432e19334fd12ae0e61cb709ba4ff9a3e2f8d4be3ea8a363 \ + --hash=sha256:36669ca43a4962a590cbd2f3f96b2b9fae48a4e920c0e525a07c63f11c974ffb \ + --hash=sha256:36669ca43a4962a590cbd2f3f96b2b9fae48a4e920c0e525a07c63f11c974ffb \ + --hash=sha256:46bc333ef718fca942741441932e3541d9d4c819a07a758207eb2c8e01e13d59 + # via pyobjc +pyobjc-framework-executionpolicy==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1dd12021d06c6c6dfa79f24c919e3b8e9ef970ecc5a5aafd3521214a841e381a \ + --hash=sha256:1dd12021d06c6c6dfa79f24c919e3b8e9ef970ecc5a5aafd3521214a841e381a \ + --hash=sha256:2baff57684bb5ed4fb24fb1cbdb85b63113916b8ec5a7080e6916663b1d1658a \ + --hash=sha256:f7a8fcc03758e2f0b8de759320db30ca2b486299dcac6b2e5d1012b06abeb957 + # via pyobjc +pyobjc-framework-externalaccessory==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:00c69a9b09af663618b22c4a1601b958733e266ffc38b85864a87b2c82cf403f \ + --hash=sha256:1114babdf062e9a5111a9534a9fae37135c9c4cdf09ddff35058c3314b6cc66a \ + --hash=sha256:c9582d6a1b7224ead3a5a0944df080adbdaaab0dc7b428eae82fcf7e9ef1b9f3 \ + --hash=sha256:f3b648aa4963a9db0c7057eb384245803d689492dd59cea7de822f663ec36e7d + # via pyobjc +pyobjc-framework-fileprovider==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:4b2d58f0bc91dc820e37dcf198a073d0e5f1a8bb8a51a8b293faf26532c99f64 \ + --hash=sha256:9cf8f59536b5e2db223ccb09f54889cc4589cbae46a033b659e3a532f4f18ed3 \ + --hash=sha256:bfa37d4819d355dd23b6ba8dc1741ac4a5872546946bf5a96767ea617fd37e20 \ + --hash=sha256:f498af5cdde27fe133386d43d8733ecb4cfe4190cbcf30b785adda8ee3e17ade + # via + # pyobjc + # pyobjc-framework-fileproviderui +pyobjc-framework-fileproviderui==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:53ad098926d66269254921494f7aa6425df66a8cc8d9bf6eba8a086cb77038af \ + --hash=sha256:f67a44d6ca5646f282f0fbd1cca5ad70c19e8654272fa7903da0d30c106ba617 \ + --hash=sha256:f67a44d6ca5646f282f0fbd1cca5ad70c19e8654272fa7903da0d30c106ba617 \ + --hash=sha256:f67a44d6ca5646f282f0fbd1cca5ad70c19e8654272fa7903da0d30c106ba617 + # via pyobjc +pyobjc-framework-findersync==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:2fe04f59bf5a44361da2f0968c705481da69af88c13ec92c5ba62fb70764635b \ + --hash=sha256:2fe04f59bf5a44361da2f0968c705481da69af88c13ec92c5ba62fb70764635b \ + --hash=sha256:6050c0ee480f8db1b50e9f52809792cc2322e7d30ed2915dc5db57544a34295f \ + --hash=sha256:aa78025cf3c1f7df6a68e8b2edf679314f59709cf9dd0b54b1bba691008faffe + # via pyobjc +pyobjc-framework-fsevents==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:2b293eda3731cf875a0735f1573a7ddb0b294af25e881253341e4dfe77a4f101 \ + --hash=sha256:55eed25064fb595f26439a684ea5a7e088294d0d61c11c2250825458ddca3ff7 \ + --hash=sha256:66f0ce01af35f57d28c005686684f05c896068186da12c76e3dbb77b2a7dd73e \ + --hash=sha256:ee2a03df22b33ad93d1613f707bd574a069c0dda3355a95e773d4758c7389bcf + # via + # pyobjc + # pyobjc-framework-coreservices +pyobjc-framework-gamecenter==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:28c90420ae47507271b416ac916e9dcbd7d48c648fd94578ecbd92b447463aa8 \ + --hash=sha256:52c40b01cd3b3cc0b0b95334797daa031aaa8a8216ef5be26a40ef79bc8e89d9 \ + --hash=sha256:6d25b4f14826d76340b8ff07b6e8f6e56b2c920a4d76b1d434656d0ba6e375cb \ + --hash=sha256:df43bc50275e25db78b64ef82d8e76f38486b5b4ad9ba6ccbbdc43f73519f26a + # via pyobjc +pyobjc-framework-gamecontroller==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:09a153310bc58adf005f372c5b9c1cb210374cdcd6eb45c8826d3907f9b46f8a \ + --hash=sha256:2c8f1e30b7012d5aa799949760323bfe2df569134b2a4256aa45ccbe0bcfee40 \ + --hash=sha256:8725563213e696b7e6a29587d8b9562baaff9341606fc7453b2cd928c97d877d \ + --hash=sha256:9a2fcce3c8552994b979e5dbf816c6246ba27a1b7cd6672881d19acc163144b7 + # via pyobjc +pyobjc-framework-gamekit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1223c243b3a10bccb773ac471b20baf04e007a16513f3d6a78b8921ed358e40d \ + --hash=sha256:3e3910b22638afca7c864885a914a210fdbf4f444ded9f3c8cffaa9ba708f9da \ + --hash=sha256:6634c9ac96bfe4d6e0a2c5fc1dc655397d154f75cdee226d6c02d39fa5781819 \ + --hash=sha256:93a8d53a98483ec7297a66a4769062855c21cabb8f16468356b7c72e1997f39d + # via pyobjc +pyobjc-framework-gameplaykit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:387481e798dadceffebd27d0488fc7dcb7631dc2e2c06c5e845204f9cea266c5 \ + --hash=sha256:512215ef9eb5147434d65e3378c4ae61602c875ebf3db957600c2d09df3d2a2b \ + --hash=sha256:728cf8c8c2f374398ab96ee40480bc433b18bb910117c6e28821d4c1ee206e39 \ + --hash=sha256:ed6235a84feddd8019b91d81f5bf7db1c8a17198e4242e2931cbe68ff1519794 + # via pyobjc +pyobjc-framework-imagecapturecore==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1a7b26665c6e557d8bc270a14e8ae4a2a18a8ecc02a04d321cc152739257f823 \ + --hash=sha256:2c25d6d2e3bf275de845973a43ac75d2479cd41cb6be6d73cc6fa99d4542271f \ + --hash=sha256:4b3af1bb2aeb0c3d5434f3b29d21e8a967fa640e5bd2b76395d9e5d999b5cd2c \ + --hash=sha256:a8f9dda226c954c96bf67c651ba751cf961f186901b52fb171b50eee4c199c66 + # via pyobjc +pyobjc-framework-inputmethodkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:10b4b649e51e5199a40852466d5236b62f104c61dbd74b5e0ca869e1cdc00378 \ + --hash=sha256:4f2ed5b0a85c1805e5978aee163dbd1dcdbf815b1ae32faa953eb7161fd65d65 \ + --hash=sha256:7cbb1628ae650661a00e86f4f5f660a83848b14295a62f4101ebf0248ea2c3a0 \ + --hash=sha256:8d5e6a3813920c94821caef5db1a955870d6b398c6ee999eac61f0549a1d33e3 + # via pyobjc +pyobjc-framework-installerplugins==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:7d96c00f9b1c3049be333433cdabb0dba851c525a3698a3e295c3ed1e6162a67 \ + --hash=sha256:7d96c00f9b1c3049be333433cdabb0dba851c525a3698a3e295c3ed1e6162a67 \ + --hash=sha256:7d96c00f9b1c3049be333433cdabb0dba851c525a3698a3e295c3ed1e6162a67 \ + --hash=sha256:bae9b4d81b965328b2a94bb084bba18ad6ff8d08a7f92bda2d433b07ec67cb2d + # via pyobjc +pyobjc-framework-instantmessage==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:48c5219851038cb815ee1bfa20662120285abecd793be144f9fb3cd604d4695b \ + --hash=sha256:f3ea71c542c67a3752bc185b1d4031e224054efed2398158dc0da691233ceeb0 \ + --hash=sha256:f3ea71c542c67a3752bc185b1d4031e224054efed2398158dc0da691233ceeb0 \ + --hash=sha256:f3ea71c542c67a3752bc185b1d4031e224054efed2398158dc0da691233ceeb0 + # via pyobjc +pyobjc-framework-intents==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:0c3bd2bfddc7d38be87e3d4d16bc29441450962ea32ecf68d119591ce8f5b19f \ + --hash=sha256:26200c14bbfe4c25a2c8d72b4d57d34af2a4921661a7f97802017217aa4a6b7b \ + --hash=sha256:a30279bb879c8288f655ac08a98c6bdcd295b7ab0a74ee3442a014e3e4b06b43 \ + --hash=sha256:abf36f100c38abbbd0015c8120e5f018d394896075116028df3f15c2a7a06af6 + # via pyobjc +pyobjc-framework-iobluetooth==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1f9fe213d00bbfc61367164172f8a898dc2c5a0cb7f66882ce1d74f58d098f24 \ + --hash=sha256:49cec2fe3a8d6afc5e1167c439ad840a76ea58b78e0e2a81fddc42f65f1c1e2d \ + --hash=sha256:85695b26332916700d5a0d161fda903b9dfec18137949df5f10224486489b4df \ + --hash=sha256:e6ed2991f4043134c740a9d0621617817ac57b1222e85952d6c53859436bed3d + # via + # pyobjc + # pyobjc-framework-iobluetoothui +pyobjc-framework-iobluetoothui==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:043c9307069c3f125127043155e02b135a8ad604d1b4b623175aee0183751d37 \ + --hash=sha256:043c9307069c3f125127043155e02b135a8ad604d1b4b623175aee0183751d37 \ + --hash=sha256:043c9307069c3f125127043155e02b135a8ad604d1b4b623175aee0183751d37 \ + --hash=sha256:f985031886bcf94777495774ceebd76d7f96e5bfe24456d92f2e13e2f98675e3 + # via pyobjc +pyobjc-framework-iosurface==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:002d32147d4daedeb9322321d79343bd7c0ff5dfac19d2edebeaff218d57ba64 \ + --hash=sha256:6b5dca0e5600c78cf698aef586b2ebeaa0787cf2e7d9c6a2bec44a2340f4d83d \ + --hash=sha256:bb59b5790c0a77e2dae7d20daab13dd9897451f97a7836c26de005d66a75453f \ + --hash=sha256:bb59b5790c0a77e2dae7d20daab13dd9897451f97a7836c26de005d66a75453f + # via pyobjc +pyobjc-framework-ituneslibrary==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:3212bc7acc5e19a12f609c952a389e8a52f86ba950bd4e39f458ab154913f0cc \ + --hash=sha256:51f163ac282ce38fc29d6d477515eba61233569e7629709f747319495a2035cc \ + --hash=sha256:51f163ac282ce38fc29d6d477515eba61233569e7629709f747319495a2035cc \ + --hash=sha256:cf1ebd986d27798fb687dc6f55589eb1b9229c4dc1f27922e8eaff9d7ee0acad + # via pyobjc +pyobjc-framework-latentsemanticmapping==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:2530af11a23f5bb2230920ed28d0c3766f09d2e41ebfcc21254d84077e32943c \ + --hash=sha256:a04ef00377f0ab795c9e05cb9e0f4e43db3f769dceb2f4534b692caef4de3df4 \ + --hash=sha256:a04ef00377f0ab795c9e05cb9e0f4e43db3f769dceb2f4534b692caef4de3df4 \ + --hash=sha256:a04ef00377f0ab795c9e05cb9e0f4e43db3f769dceb2f4534b692caef4de3df4 + # via pyobjc +pyobjc-framework-launchservices==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:291131cf0fcbb19e84052c4aa8a24a987f1a94fa80b973c0026dd9ad1ef82a65 \ + --hash=sha256:6c7ec57587248f193fdb317e55dd5e6903157c262d469faefb73417cc2c02a29 \ + --hash=sha256:6c7ec57587248f193fdb317e55dd5e6903157c262d469faefb73417cc2c02a29 \ + --hash=sha256:94abbdc5a3dfe364a5d97c05cb20667947cc230060fb9a348d9a79f8e7f672b9 + # via pyobjc +pyobjc-framework-libdispatch==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:31ece9451b25f70a27dfc409c3bfc855bc95def9106ff4f58cafeb2842f0bbd2 \ + --hash=sha256:3de4744a4b55bb58ad33603095722f6c3d167d22caf0ed1af5ddf43a1b081cb4 \ + --hash=sha256:6c16500e529a68330bc607019929ff7f7f99dceda569f2f2885636c140a1ff89 \ + --hash=sha256:f726d4df928a9db4c0582ef02a838284e21a7bb5b5d362b5fff0d136d27e6eaf + # via pyobjc +pyobjc-framework-libxpc==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:0406acb0206816c6b063fe88c14922ec4f47d9f9bc19af9507918ae129d54601 \ + --hash=sha256:6ea9f88ba998731a27a4946bd920767fa3087e922397f9f84a8fc7c6fed975ae \ + --hash=sha256:96926a5f7e319523297f666e62b32854e133aec65fe65f510da166bc68488093 \ + --hash=sha256:a7faa551bb2c83d173750c4bae9a26544371c79dd8ed199636637518cb391b79 + # via pyobjc +pyobjc-framework-linkpresentation==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:3333c2f863bb75388d753da2298ec0e1de51d0ec363c1a4c4d25dace1052a893 \ + --hash=sha256:e69a5a8fbe647e3c201fb89db3b94573f566c20e67b5f8e677b40152ae1bb9ea \ + --hash=sha256:e69a5a8fbe647e3c201fb89db3b94573f566c20e67b5f8e677b40152ae1bb9ea \ + --hash=sha256:e69a5a8fbe647e3c201fb89db3b94573f566c20e67b5f8e677b40152ae1bb9ea + # via pyobjc +pyobjc-framework-localauthentication==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:24aeb0edf1af6eaa17cd1eb9dbe16988e88ce62fbe31943936152a1d3f07060e \ + --hash=sha256:7a7b09a58025d71e1cc0f7df83d4f71eaf76f988917a25145f06adbc805338e5 \ + --hash=sha256:e63e242e82ac1ed17917599ac5c29577451c8881dd4aef17ae4096bd2e361b4e \ + --hash=sha256:e63e242e82ac1ed17917599ac5c29577451c8881dd4aef17ae4096bd2e361b4e + # via pyobjc +pyobjc-framework-mapkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:2265de3dfdd987f98258c100d18a37516b9da297be17ca34ef3c8595e1c48b89 \ + --hash=sha256:8999be166009807fcf2adf3c2807216acb020b4e82acf4c62d67e4d4a9b1c09e \ + --hash=sha256:bec114d216061075308baf55f19e737cc2cd5f792518e6a813d3859c335ef1da \ + --hash=sha256:c94503e72b588641afaaa9b1aaa85fcca114537ae07718f00f66b66092250bf5 + # via pyobjc +pyobjc-framework-mediaaccessibility==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:4c241ea7402c5ee52ec6af8c5b71327be69e1ab54c70e7824cf17f7d61e8372e \ + --hash=sha256:52e7322fec9f6a8c535abfd2af6ddabf017466584a63e7454f2374b79a39fd81 \ + --hash=sha256:52e7322fec9f6a8c535abfd2af6ddabf017466584a63e7454f2374b79a39fd81 \ + --hash=sha256:b1a81602f37a999b36180de08afcb5bab0e6bc12740cc5ee9710b5527596fa9c + # via pyobjc +pyobjc-framework-medialibrary==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:5556f813551be8dbd2c17d08637f6a00092b74efefe369f580df8c1469f81eb5 \ + --hash=sha256:95e6072f07796c68e566c12efaf374fd837350e776418b17c1b6215a8c176250 \ + --hash=sha256:97ee76bbb59e7185fda910d6a543108fe5e4099a2bf934365d480015816f91bd \ + --hash=sha256:97ee76bbb59e7185fda910d6a543108fe5e4099a2bf934365d480015816f91bd + # via pyobjc +pyobjc-framework-mediaplayer==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:4ec50a9839806dfc893063cc42ee738a9a9827fb73f2e5897b1e8e7d34e68f9d \ + --hash=sha256:4ec50a9839806dfc893063cc42ee738a9a9827fb73f2e5897b1e8e7d34e68f9d \ + --hash=sha256:4ec50a9839806dfc893063cc42ee738a9a9827fb73f2e5897b1e8e7d34e68f9d \ + --hash=sha256:d446bac0c05fd8700a16ebe30b7caf596f6a5b4ab86e7fe517b73673cd49ce84 + # via pyobjc +pyobjc-framework-mediatoolbox==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:550d49dea607c96e0539c33ade1ae806c58d6898f873ca6b9415d966a570432e \ + --hash=sha256:6bb53a630f1f6956a17b8300fe78d32e5c40aa369c486696d2553b1da453fca6 \ + --hash=sha256:8a648a57c486555710eac3ee01f2b9d89892cead96aa420943946c65ad0544a9 \ + --hash=sha256:aef53cff8f6e0aa5ffd930c82af68e97a401cc0ef00400ed8cd889e0744ecc3b + # via pyobjc +pyobjc-framework-metal==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:3072b03a28067e1142fa566b71654bbbbe860d9f11941b11f6ee02795a303176 \ + --hash=sha256:42810b82d7797011a29b9f10b0bdc14bfa278bcb3856a8b74adcaae88ab9cce2 \ + --hash=sha256:43f60957623e25dd5592d740edab895308d08c3a0f29c63ca8c7c594304aecdb \ + --hash=sha256:57b2df28aba9fe58a1f4d91838dba4462ef2c19ba62bb0be36d72217a1c8b6f6 + # via + # pyobjc + # pyobjc-framework-metalkit + # pyobjc-framework-metalperformanceshaders +pyobjc-framework-metalkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:3f5252f932aa10b600b9837ed21b927ad1a5b80c31ed88fb5e0e590f1ac7baad \ + --hash=sha256:587b29b2eaabc7b5689fa9239248299d6be629fb12ca4894e0539fffc1d9833a \ + --hash=sha256:e1ad86dc89b162e8d05b7f95a723d9c02b93eda2f1f226d1d04e96a615c4eff7 \ + --hash=sha256:fc760d01b78f328f12d69aadca1a3d5c66fc160be75fa32b18d7f04def5411ea + # via pyobjc +pyobjc-framework-metalperformanceshaders==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1e4734aecceb2cc948f00ce3065f48153437668f5a84e43301c319563c9f7fd0 \ + --hash=sha256:7461e6fe30b4b31dee698db1558c1a6fccf96f0cdf78fcacbc14a09c2b36121d \ + --hash=sha256:cd4d156dfbcf8f00e8dbc7048c954a6559a32d709cb36ff0d0cf5bd3dc311d76 \ + --hash=sha256:e13d9b866cf8c67ec1a0f350e5a33975b962582f549333a12ac50c81c8a4ff38 + # via pyobjc +pyobjc-framework-modelio==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:34d5a7020a7f0e2483360046d227a0709105ab0b70c72808bc564b8740b3a70c \ + --hash=sha256:4d12021dc80bec3eabd3b66cdd88836f12d304cfb26753ebf6d8a6201f9bb598 \ + --hash=sha256:8ebeccf7e637dd76900e933c040f7dd43172833915e91165da970532dc677325 \ + --hash=sha256:decf52dcf325708b1a9ff3fa584cbafb4584d5aed899732f2631aa9d7e0db783 + # via pyobjc +pyobjc-framework-multipeerconnectivity==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:2b4afa1ff6d9d203e667786e8c100f0299bcc33d7a9f8996a446e0ac0c8efb7b \ + --hash=sha256:4dfa1c88c6ca91355b06f96843f3c737c5dfb1cb74cc9cdefffaf2239b09cb1f \ + --hash=sha256:789e2e190d1c6d244487fb8e8fcd9214d5c98560d31c3714fe5e06f6d9e19960 \ + --hash=sha256:990f38b75fa3cf9ae009228626efed1ab917ff63985ac994837d48db2f95a87b + # via pyobjc +pyobjc-framework-naturallanguage==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:53c66e0cf3b5b8d22e331f8916c2a1a05f009d4c65f1f393e422dc47f027b54c \ + --hash=sha256:53c66e0cf3b5b8d22e331f8916c2a1a05f009d4c65f1f393e422dc47f027b54c \ + --hash=sha256:53c66e0cf3b5b8d22e331f8916c2a1a05f009d4c65f1f393e422dc47f027b54c \ + --hash=sha256:dbcf1469d0d6b4d0cc8172454a3bcbdeae20b04692019472199a42eb1cdcbd35 + # via pyobjc +pyobjc-framework-netfs==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:25899eeb3bbeceeae3e83afa7e8e112a7aeb2acd2141857fc4a2dbba479f7b39 \ + --hash=sha256:bc65b11917e5c4722206e829137ae8d2bf2627c061fab2886614860379e24487 \ + --hash=sha256:bc65b11917e5c4722206e829137ae8d2bf2627c061fab2886614860379e24487 \ + --hash=sha256:bc65b11917e5c4722206e829137ae8d2bf2627c061fab2886614860379e24487 + # via pyobjc +pyobjc-framework-network==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1e96f09c85a819acaaad307c2f8ced8b7758bb396c528a07b0dcc94a5c447aee \ + --hash=sha256:30966dcdbf96209113776b42edd2be4479513a83e15a88e9f88e17d9684ce811 \ + --hash=sha256:964d1a10d3de1aa282bf33bba5360e94ae6b09f1e10efdaf4357c74f3fc58ba7 \ + --hash=sha256:af717ff1ab8124246e94a0b6c4da3541c486b96fe898301e20b0b10ac2b57ab5 + # via pyobjc +pyobjc-framework-networkextension==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:386909eeacd3afb861201f9951c9c33627957d27884c31c289e134c34ec0ca07 \ + --hash=sha256:5c9d0d09d286524639cf5070bed85252b6699353b064eb6d602c332ba4610215 \ + --hash=sha256:bbf3f34265c324935c2379e2e9dc985295d966e9fbee3cd985654160f4640b49 \ + --hash=sha256:d895e04a12f933f477c0b1f77b13c07479b4ac38df2d23391ab313e54e9665e5 + # via pyobjc +pyobjc-framework-notificationcenter==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1e23dfb29af137b10f0c389505e0e77bde84ca7290e99fb39b393bcab24254eb \ + --hash=sha256:4c4644ff6a7128cd822289590697dc9ee9d28da6d640ce86de421d7722af5b35 \ + --hash=sha256:5f744fb9b2a693cd49c9931733791b5467ac65badb68c888e8fbe43ce60de8d9 \ + --hash=sha256:fd8abb44282970353875d3c012c79e7e79b82e143784b409a4265c0ec9babba8 + # via pyobjc +pyobjc-framework-opendirectory==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:bac760f838fa89557f8e8d3d5e50c948053da2fc95652158f657d5dd1c4d1629 \ + --hash=sha256:ece772476d16d1076b0b54fa7e6d26e7e5112884795c2490fe82f74cd8c03b76 \ + --hash=sha256:ece772476d16d1076b0b54fa7e6d26e7e5112884795c2490fe82f74cd8c03b76 \ + --hash=sha256:ece772476d16d1076b0b54fa7e6d26e7e5112884795c2490fe82f74cd8c03b76 + # via pyobjc +pyobjc-framework-osakit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1ce1bd389f8c55dd8cd3275db63a52143decc0cad00a5601266c65e3761cb37f \ + --hash=sha256:df5d0cd733215fb717ceffc4a8e4d6a2cabd779d4c37a9a543e83e080d889356 \ + --hash=sha256:f711267b7a01233f3eeb638ebb3aec2714151f3a5bbcf622bb3eb566385d051d \ + --hash=sha256:f711267b7a01233f3eeb638ebb3aec2714151f3a5bbcf622bb3eb566385d051d + # via pyobjc +pyobjc-framework-oslog==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:262dbabf344c94e221d5adf6f17396e68ca78e57036faaa3500842c69172ef29 \ + --hash=sha256:7d5bcfbcaff0ac7a686b6ab091f1f587af447e834ddd576e7a0333a0e994d679 \ + --hash=sha256:9097148f396bf61f74286805aa74483a553c28e8f2977169a7e8e98332463614 \ + --hash=sha256:c20cdd6576cc1465d291afec97a31257fde78ee9566aa2caf4a175b8469e5e77 + # via pyobjc +pyobjc-framework-pencilkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:5a987280e6f240ff83ef9ccceddc0527883e60df45080505481a112c7e059933 \ + --hash=sha256:d2c8aec7e6f5f8ecf544f3d7636549d45bc9a7284d7c6ddc341f672329549048 \ + --hash=sha256:fa4d6a887196f01299e60e709eb698a6ec17d45429ead1316bd3055bbd13762a \ + --hash=sha256:fa4d6a887196f01299e60e709eb698a6ec17d45429ead1316bd3055bbd13762a + # via pyobjc +pyobjc-framework-photos==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1bc42e76541196ec0b57bf335b454c8b3f00e975d0ea889e2436e5e02eecafca \ + --hash=sha256:546f864293a9c6a5c0a168e05144f6cb6786f479329fcdc4e7f32c025526cef9 \ + --hash=sha256:9aa102cb75c53972603b9a00621161ee236e28ee6d6e1e8d6547433d0055b061 \ + --hash=sha256:a6824fd47dccecbce50baa4238ba6c5b8c9aa9fcd6138a5d27b64d441dafaf12 + # via pyobjc +pyobjc-framework-photosui==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:073865bcb080ed2c8b18c09f9261b871588bc7224ac7dd11ebb8bd9982b15669 \ + --hash=sha256:1538c459d0971a8c6788efdb8cc530ad965d0e39e5a612849fca91573051a47b \ + --hash=sha256:64a4696598635e7759eea3afc218f37b66e4faac68b430e4904550679d9bb0a1 \ + --hash=sha256:c03360b0b1df2369c0a57863766cd891a0939133a09b9be80a2902e7e5ae7e9a + # via pyobjc +pyobjc-framework-preferencepanes==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:02b95ca7dfe66b0487422008bb67cb6202d27f57dbb68c3c160a2812247eaf77 \ + --hash=sha256:bf4875293f66b6176512d85c5febe2084b6dd5a500d7564c7fb47bed38468012 \ + --hash=sha256:d51cf15b50d08c9213c34ed10067532c387a9e00d035ac8e6f139eeaac4de890 \ + --hash=sha256:d51cf15b50d08c9213c34ed10067532c387a9e00d035ac8e6f139eeaac4de890 + # via pyobjc +pyobjc-framework-pubsub==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1bde2f9d7dd2baf82d8d5094d8adf7c0d4b507ec1c32106f8c89ba953bc9b287 \ + --hash=sha256:1bde2f9d7dd2baf82d8d5094d8adf7c0d4b507ec1c32106f8c89ba953bc9b287 \ + --hash=sha256:966534d65daa59d79d9662b4218e6fed2c13e4375840434e559805c933b09da3 \ + --hash=sha256:9cac04d2901108fb22bd891245dd908b0ba63bb4be697fb68717ab3407adc00a + # via pyobjc +pyobjc-framework-pushkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:93eb706b1030e059befd657bbde55179b103b705f67ce5fda7d59ef00bd52597 \ + --hash=sha256:cfb9fb736f0c42809e27ee7c1b3da43c59d67303ce752209f7a037ee66f68499 \ + --hash=sha256:d62f405feb0427036630bce41e3a6582b9ed9a636c6445572f300270e2422951 \ + --hash=sha256:f93657477660862bac633620d3d3c9515296749117abf1418d31e997e7efcea3 + # via pyobjc +pyobjc-framework-quartz==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:03f97df672c4c4d702e5fa3b16d32a4c2e9b1cbf38592917f2529bc8697e6131 \ + --hash=sha256:0b208b6e7fe22caf101ef3cbe756d156e91697a8a9b70acb0dfee238a7aaf37e \ + --hash=sha256:a543d4ab5c03719801b23cbeaca580179e23c1579fb7e1d09f2e7fb0dccd2f95 \ + --hash=sha256:eae3261ca8afc159eb14977d5d02bea6cd0906e84ba7741ab2668532320dcb5c + # via + # pyobjc + # pyobjc-framework-applicationservices + # pyobjc-framework-avfoundation + # pyobjc-framework-avkit + # pyobjc-framework-coretext + # pyobjc-framework-gamekit + # pyobjc-framework-instantmessage + # pyobjc-framework-linkpresentation + # pyobjc-framework-mapkit + # pyobjc-framework-medialibrary + # pyobjc-framework-modelio + # pyobjc-framework-oslog + # pyobjc-framework-quicklookthumbnailing + # pyobjc-framework-scenekit + # pyobjc-framework-spritekit + # pyobjc-framework-videotoolbox + # pyobjc-framework-vision +pyobjc-framework-quicklookthumbnailing==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:447a8ab915bccd99d68698f072c87051fbbb857d319d5f260d5b3f92237f0288 \ + --hash=sha256:447a8ab915bccd99d68698f072c87051fbbb857d319d5f260d5b3f92237f0288 \ + --hash=sha256:447a8ab915bccd99d68698f072c87051fbbb857d319d5f260d5b3f92237f0288 \ + --hash=sha256:cb94da8097724fc1e8dde4b3d825cf6fc78569f146ed7b195538ca028d61a9cf + # via pyobjc +pyobjc-framework-safariservices==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:65701896ee1c958d27646e39457a57a3092322651289c26baa20731370ca6f6a \ + --hash=sha256:7e6083ff340bbbbe2896d7560576e6721574d0fcdc3c4613a1ea00cb1d33df86 \ + --hash=sha256:81c91b816349a8043b187f7b67ffe46ef3c85373241eaca90ad558d3c56642ce \ + --hash=sha256:89060e2ba2a8b4ae9cda6637f0dd1d7dd2e6ba1bee3e2be35a8b3481c20de06b + # via pyobjc +pyobjc-framework-scenekit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:47ee19ac48c067a1af7186a8addae3cd1fa42fcefdeccee519bb2f5f3f7456ad \ + --hash=sha256:4cfa0dfccd821fcb3641d2e45a5ad8ade493ae691bac17728e40c8eba7ff488a \ + --hash=sha256:62c9c60a514119e295ed2467a0a0a7bc702db19efb209582cdd682bcc35ecf8c \ + --hash=sha256:a1c59d3e08e9abe06a1c0a1a93db740a4ae58a77cd87683d84354f59ccb88041 + # via pyobjc +pyobjc-framework-screensaver==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1d1fe276e06221d100bf3feccdf50466e755c6eb8d5c1efa17ef71508f4f9b24 \ + --hash=sha256:871ebe82221e4663448ddec589f660ac7538fd0ff2a24f92ab385ebc604845c2 \ + --hash=sha256:abba8626d1efb51ad9d1474937cf2328c9752671676fad3e1db7d8ce697ee6d3 \ + --hash=sha256:ed6bac6a081a811c7823e79af82fd8db25451e79bf5a270093456b83e7170207 + # via pyobjc +pyobjc-framework-scriptingbridge==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:0e9934c9d247ed3dc7ba6c2db9c9aed9ec0113b32f7b06b606c1822393322c9e \ + --hash=sha256:1e8c8ac310e1ae825830240c22a0877673a668402218eeff24bfa947142c7b83 \ + --hash=sha256:44f65133d089f5571a96ddf5c62b00f81557a2978d7da722c8288b042b15ca58 \ + --hash=sha256:f9f87616491d7317f4fd967e64b65c692744a8b215ba23debdb9b4850817cc96 + # via pyobjc +pyobjc-framework-searchkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1f6728f2b08d39b161d77bdaafca2db6f64efae33592d4b9c1c458e7800c07cc \ + --hash=sha256:1f6728f2b08d39b161d77bdaafca2db6f64efae33592d4b9c1c458e7800c07cc \ + --hash=sha256:1f6728f2b08d39b161d77bdaafca2db6f64efae33592d4b9c1c458e7800c07cc \ + --hash=sha256:5657fae70317fa96c145c6c6baa3d94e3dcd5176bd98ae5952eaa208c4cd4026 + # via pyobjc +pyobjc-framework-security==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:4743dc3f12a679ce13b75116de4cd96ec3e10fff899d7d340c41a95360f06e9d \ + --hash=sha256:5d2cf2b1e9dd06c0f41a3ecd399b5e70aae15fc013ecbc1c69c67d1d11c2126f \ + --hash=sha256:661ccabede6c4e86719a75e0f1c889ed594c059fc5ce211ea3855bf6513ac69c \ + --hash=sha256:db084ba1cedc7ff14f4d94358b3f59defc50883cffbc12810121e5252895ea15 + # via + # pyobjc + # pyobjc-framework-localauthentication + # pyobjc-framework-securityfoundation + # pyobjc-framework-securityinterface +pyobjc-framework-securityfoundation==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:6390bafd47b858e9695067884869c766d974fc7495b222ad21a2d31dc34a9180 \ + --hash=sha256:6390bafd47b858e9695067884869c766d974fc7495b222ad21a2d31dc34a9180 \ + --hash=sha256:6390bafd47b858e9695067884869c766d974fc7495b222ad21a2d31dc34a9180 \ + --hash=sha256:a3546ed431f31e74c383e4f33a671454f198ca6e2b1062aa6d7cbb61626cf0f5 + # via pyobjc +pyobjc-framework-securityinterface==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:328049de977b8e66bae412e066c04ba1b40c3a551ee429404ce32326d8a36629 \ + --hash=sha256:6d0588d92308a6bebd4cff6e232f326f255450313f5d6d6241c5bb158b20fcaf \ + --hash=sha256:c51a9020d2e2cdfc7c4e616efeb7c0c377b356d70987f4c2d4d458c1984c44a9 \ + --hash=sha256:ee56f02e9efaf5de9a82b5dc580567232dd928110cf8dbac130917c627f387f2 + # via pyobjc +pyobjc-framework-servicemanagement==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:50b96930e9ee129698384c3053d2b2f9d11f72351e8979505d4796a6675a4d42 \ + --hash=sha256:c4d5723893507cdcc764dce02a67f788ef2cbc26e2c8ac4362b1779de0ea6337 \ + --hash=sha256:c4d5723893507cdcc764dce02a67f788ef2cbc26e2c8ac4362b1779de0ea6337 \ + --hash=sha256:c4d5723893507cdcc764dce02a67f788ef2cbc26e2c8ac4362b1779de0ea6337 + # via pyobjc +pyobjc-framework-social==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:062ffea31d6543aab0f4c51332baaa4388a4ba5c826caf4092d7b068cc9ff4a2 \ + --hash=sha256:062ffea31d6543aab0f4c51332baaa4388a4ba5c826caf4092d7b068cc9ff4a2 \ + --hash=sha256:062ffea31d6543aab0f4c51332baaa4388a4ba5c826caf4092d7b068cc9ff4a2 \ + --hash=sha256:990e0c758c12708493297c391826a8c6d40a9ec6f548162a5cded571d7a5eb33 + # via pyobjc +pyobjc-framework-soundanalysis==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:00a8d9bf2fa38d0c1960edae3b5470123496e3b8599244db3f5f9946445dba28 \ + --hash=sha256:00a8d9bf2fa38d0c1960edae3b5470123496e3b8599244db3f5f9946445dba28 \ + --hash=sha256:d47f224f7c2e7935a718b1958af71af2828921cad86504a9ebf970d15247d59a \ + --hash=sha256:e448cd9b73fcae89191c98903c6754ca029af2fc8eece4a95d11d167e0dfbe86 + # via pyobjc +pyobjc-framework-speech==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:346c4df2e64b080c2ab957ca4d6578a74abaf2ed43e575cfe7cc6a36dd19d042 \ + --hash=sha256:4e327139b5d1307d00788533a7d2450f65aabff5e65d405805125c72c093fa1a \ + --hash=sha256:7e551fe41d6f459996c3d7544ce9929d0ca2ae059fedbf51cbc3a42011faf11d \ + --hash=sha256:bea5346c5f33f70f1add7430cca18d3fca484c3642f7046b63a3703fcbc2b50f + # via pyobjc +pyobjc-framework-spritekit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:54ce361a0b95cfc7e2fe08d2fb514d61ec386406b13a0c205076ff8995dcfdee \ + --hash=sha256:bf2524d2159a5378b514806a7735a4ee5f358fca5a7036c983503a9e9deb59ea \ + --hash=sha256:da874aba3d540e3808c294e877250e4cb04ee8dd68de0194d862a2d5b717ca8f \ + --hash=sha256:e23e56743abb21d1113baab879558124a10e6a57490e80a825b3c2760fcb70ba + # via + # pyobjc + # pyobjc-framework-gameplaykit +pyobjc-framework-storekit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:15466cc1b40621e0f823abd428c48d1cba0c3fa22810782d5be3c2136f533498 \ + --hash=sha256:42c1966626cd412f8d87d016088962a67dd5357386bd7a525fac117bca4de12e \ + --hash=sha256:739531d040d090c7318b2d65b600364db99147656cafb513e655742e9b2433cf \ + --hash=sha256:fa3cde89dac6cfd30b09755ea5e3dcaa8c494b2c928996aac23658434fb230e1 + # via pyobjc +pyobjc-framework-syncservices==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:1d25d30ef22e2ce6ceac01d275c9f39627c5db48a8bd232e5553b30d9a02daad \ + --hash=sha256:2432e04784bf1e68ef1951b40d8febcbddbd572a53931302fd126f7c7639b93c \ + --hash=sha256:6a97d452b933d61267d229529909df26d5b7c40ae9029c95a891585d96208cc5 \ + --hash=sha256:73d7404936938c18208ab48e50285b304bff6cc7b00649263925412231cfed18 + # via pyobjc +pyobjc-framework-systemconfiguration==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:452bd8c52aa6cea18c619786f31e6ad064dd8b0a3693e2200f425400173b9733 \ + --hash=sha256:775aae2e4f48cba3b831c080f853fe76812124b4476ac6b5e329009f0a6fa8c2 \ + --hash=sha256:a669274a35113402c461f9f788084972db1d7eb57847667268ad31b4c1323c63 \ + --hash=sha256:f697e2169b089905b5e494856b32aa8a011e9c51b94338e443833adb9a6f4512 + # via pyobjc +pyobjc-framework-systemextensions==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:39912c06675109a0d9780cb5d0accdabae5d1968e9140e26378b8f12442186cd \ + --hash=sha256:428ca84d425f25e8bcdea47df06dc9342761cc2f8550a2cb137b2a6a57fd6824 \ + --hash=sha256:6f423d1e31831bbf15f446004c1b4c51428006ff886e1461e31dcb24bb72c8e3 \ + --hash=sha256:bc37f18c98d3f52b0cd7434b81b57d22c9a6e3da568ee36af2770706419494f5 + # via pyobjc +pyobjc-framework-usernotifications==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:055379dae7caf4d9fa0a4ebba07115a8c972ca8c458266d59d610262b08f0a1f \ + --hash=sha256:08841d80265b29f7c578d634344941138cc582d42fdfb745e06d30f6cabb5789 \ + --hash=sha256:3eff0b8b5391a89e085dce964f48ef7460ace6ddcb743b01b5d567ce67bd6ea8 \ + --hash=sha256:7bd4df365174ca92011bc1926873319f9bb71d924b2e7721f23059c815f71c44 + # via pyobjc +pyobjc-framework-videosubscriberaccount==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:0b609c0b4ffac32ea6a520f373a0c980a2d6a1a2280b375dfeea15ed0c84456b \ + --hash=sha256:0b609c0b4ffac32ea6a520f373a0c980a2d6a1a2280b375dfeea15ed0c84456b \ + --hash=sha256:0b609c0b4ffac32ea6a520f373a0c980a2d6a1a2280b375dfeea15ed0c84456b \ + --hash=sha256:6d7c621fa87465d84296f8fc6f40a2f7a2a0916f49e59ccf15912cef99d7c318 + # via pyobjc +pyobjc-framework-videotoolbox==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:5bb2466e50cce92376814726d31afe7fd7cdc78d7763c9e47b29c44aa2920aa5 \ + --hash=sha256:6b1f1b3ce72a0979b1532fb53b084114a85377262e8e012fa8dbdf5c1a992015 \ + --hash=sha256:8d5e78465ab2296c929834dfbf82cf7f8e30e50d6b1506de217937ce00edf7b2 \ + --hash=sha256:933f616585620b08a0d7c1c1831e94e8cd2410ab57e8efe2e8d1c16720db8ef3 + # via pyobjc +pyobjc-framework-vision==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:133d276bf1a828739e910bd585f13417a39421ece400418057498cc303f55196 \ + --hash=sha256:38cba672cac6edf4250a956ba9ed3d2aa4fda5cd79e2d1d805586f55e1f5ea91 \ + --hash=sha256:6f5009063cf5a05a39df6a067f1165cf1e9e7415b391608fea3ec957887405e3 \ + --hash=sha256:d37d43c9593cdb6daa7b551dd889aa89b3dcef441dacf21079faed93d498dd87 + # via pyobjc +pyobjc-framework-webkit==10.0 ; sys_platform == 'darwin' \ + --hash=sha256:3df3faba2ddabfbb3a8e05a3777b75c4a48f28ee75bffbfe19227a95ce7ad743 \ + --hash=sha256:688c9af93374196d47806cc5c322f590a26d590be23ecedecdec8c8441a0cfd9 \ + --hash=sha256:9a77c7db46dc6775ba6dc12909275aa548619e88d8dc4a6a2c3438902b6d5b5b \ + --hash=sha256:df6508526bfcdfdeb24db17ff3e6bbddb65b955e529efe828e0afba86a77c49b + # via pyobjc +pyopenssl==24.2.1 \ + --hash=sha256:967d5719b12b243588573f39b0c677637145c7a1ffedcd495a487e58177fbb8d \ + --hash=sha256:967d5719b12b243588573f39b0c677637145c7a1ffedcd495a487e58177fbb8d \ + --hash=sha256:d80942d4141a8569a529d6bf3a80923ca56aabd1a565248bf2108cb3cd4ebe2f + # via aioquic +pyparsing==2.4.7 \ + --hash=sha256:e353556f0615c2246ea24b7afd6089cb096c13c2f5c26b0ad0e0a542b5db6d19 \ + --hash=sha256:e353556f0615c2246ea24b7afd6089cb096c13c2f5c26b0ad0e0a542b5db6d19 \ + --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \ + --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \ + --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \ + --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \ + --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \ + --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \ + --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \ + --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \ + --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \ + --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \ + --hash=sha256:f10f6d3fc1598d55e192fe92b58c020281a7ad211a6f8f0ca9c24b3e97ecd699 + # via + # httplib2 + # packaging +pytest==6.2.2 \ + --hash=sha256:1054ad59b89e53209f5e917515fbe5d6972ad4d63c5beda90bc97dd72701635e \ + --hash=sha256:b574b57423e818210672e07ca1fa90aaf194a4f63f3ab909a2c67ebb22913839 + # via pytest-asyncio +pytest-asyncio==0.14.0 \ + --hash=sha256:2eae1e34f6c68fc0a9dc12d4bea190483843ff4708d24277c41568d6b6044f1d \ + --hash=sha256:b01c3c3fd2f19380aff0c436e339fe3b8ae4aeed6f5c1619e671d744223a0698 +python-dateutil==2.9.0 \ + --hash=sha256:cbf2f1da5e6083ac2fbfd4da39a25f34312230110440f424a14c7558bb85d82e \ + --hash=sha256:d6e8ba261767bc6626b87eafbaff60e52b68417ae5d245ba5b703e59a384a169 + # via pandas +pytz==2024.1 \ + --hash=sha256:23d0cb73c431924d7c4e8884520c798647165ab49f34b5f3aa6d44ae702d7111 \ + --hash=sha256:328171f4e3623139da4983451950b28e95ac706e13f3f2630a879749e7a8b319 + # via + # google-api-core + # pandas +pywin32==308 ; sys_platform == 'win32' \ + --hash=sha256:48e9e39c028aae1f5dde236379070c8374393b695be23631c447b93ee9b62a5e \ + --hash=sha256:575621b90f0dc2695fec346b2d6302faebd4f0f45c05ea29404cefe35d89442b \ + --hash=sha256:c7022dd1acce30dc2c668599a2228f6b5859fc6c5323a37f2f72262bfc2e7b52 +requests==2.31.0 \ + --hash=sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f \ + --hash=sha256:7c024df3d83d462cc8127c6c9a2dae2e5d2bddb54c1039624ab3baf485d752ca + # via google-api-core +rsa==3.4.2 \ + --hash=sha256:43f682fea81c452c98d09fc316aae12de6d30c4b5c84226642cf8f8fd1c93abd \ + --hash=sha256:43f682fea81c452c98d09fc316aae12de6d30c4b5c84226642cf8f8fd1c93abd \ + --hash=sha256:43f682fea81c452c98d09fc316aae12de6d30c4b5c84226642cf8f8fd1c93abd \ + --hash=sha256:43f682fea81c452c98d09fc316aae12de6d30c4b5c84226642cf8f8fd1c93abd \ + --hash=sha256:43f682fea81c452c98d09fc316aae12de6d30c4b5c84226642cf8f8fd1c93abd \ + --hash=sha256:43f682fea81c452c98d09fc316aae12de6d30c4b5c84226642cf8f8fd1c93abd \ + --hash=sha256:43f682fea81c452c98d09fc316aae12de6d30c4b5c84226642cf8f8fd1c93abd \ + --hash=sha256:43f682fea81c452c98d09fc316aae12de6d30c4b5c84226642cf8f8fd1c93abd \ + --hash=sha256:43f682fea81c452c98d09fc316aae12de6d30c4b5c84226642cf8f8fd1c93abd \ + --hash=sha256:43f682fea81c452c98d09fc316aae12de6d30c4b5c84226642cf8f8fd1c93abd \ + --hash=sha256:b77867f9c1b9d489e4c3afbe77ce5ec47b402affb5ab4b801483b2d247d2f7d7 \ + --hash=sha256:b77867f9c1b9d489e4c3afbe77ce5ec47b402affb5ab4b801483b2d247d2f7d7 \ + --hash=sha256:b77867f9c1b9d489e4c3afbe77ce5ec47b402affb5ab4b801483b2d247d2f7d7 + # via + # google-auth + # oauth2client +service-identity==24.1.0 \ + --hash=sha256:16bd4928f1f2ea771c7c0f52eb25e42b4d4e504ea821a782bef966325bd35367 \ + --hash=sha256:a28caf8130c8a5c1c7a6f5293faaf239bbfb7751e4862436920ee6f2616f568a + # via aioquic +setuptools==68.0.0 ; python_full_version < '3.14' \ + --hash=sha256:11e52c67415a381d10d6b462ced9cfb97066179f0e871399e006c4ab101fc85f \ + --hash=sha256:25c8300cbd8c41a350e4890f8340ca0bbadff88967f7b26de4c8ccfe5d851a51 + # via + # google-api-core + # google-auth +setuptools==75.6.0 ; python_full_version >= '3.14' \ + --hash=sha256:95e7b6c4ee1eb64afe479ba9f0c89ef4fb8e0da33319d829ecb2ad1dcd131dfd \ + --hash=sha256:ce74b49e8f7110f9bf04883b730f4765b774ef3ef28f722cce7c273d253aaf7d + # via + # google-api-core + # google-auth +six==1.15.0 \ + --hash=sha256:7bb413e52c2f9981580e74743d53187be17e108df9b4f9fab1964aab2e94b9d6 \ + --hash=sha256:7bb413e52c2f9981580e74743d53187be17e108df9b4f9fab1964aab2e94b9d6 \ + --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced \ + --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced \ + --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced \ + --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced \ + --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced \ + --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced \ + --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced \ + --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced \ + --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced \ + --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced \ + --hash=sha256:c7dfbdb6d68189c1942e9405fae9eef6bdf2ddff305866df52b806c11da74323 + # via + # blessings + # google-api-core + # google-api-python-client + # google-auth + # google-auth-httplib2 + # html5lib + # jsonlines + # mock + # more-itertools + # mozfile + # mozlog + # mozterm + # oauth2client + # packaging + # python-dateutil +toml==0.10.1 \ + --hash=sha256:4099063d9b50219bf09bfa693ab8dcd96ce585cee9fdadce5a48a08ee23b0646 \ + --hash=sha256:bda89d5935c2eac546d648028b9901107a595863cb36bae0c73ac804a9b4ce88 + # via pytest +tzdata==2023.4 \ + --hash=sha256:3bfb77cffc5b0b14bdb11a65b1074fe50cccbae0f3107024e344b48912c89184 \ + --hash=sha256:aa3ace4329eeacda5b7beb7ea08ece826c28d761cda36e747cfbf97996d39bf3 + # via pandas +uritemplate==3.0.0 \ + --hash=sha256:015cd3c3e66e9d9ccd8ada54fd7167ba51c50832044d27f1439a07d4fbd76430 \ + --hash=sha256:01c69f4fe8ed503b2951bef85d996a9d22434d2431584b5b107b2981ff416fbd \ + --hash=sha256:1b9c467a940ce9fb9f50df819e8ddd14696f89b9a8cc87ac77952ba416e0a8fd \ + --hash=sha256:1b9c467a940ce9fb9f50df819e8ddd14696f89b9a8cc87ac77952ba416e0a8fd \ + --hash=sha256:7ad3e6d74caeb1d2c5f2496885e652dad1b3894abf28fdf2da9e98f4ffe8919a \ + --hash=sha256:98801f9862158b078d7252d835c7dbee5b66bf776c3226131669164ce93ae54f + # via google-api-python-client +urllib3==1.26.6 \ + --hash=sha256:39fb8672126159acb139a7718dd10806104dec1e2f0f6c88aab05d17df10c8d4 \ + --hash=sha256:fa608904f610002ec11bb0347f46ccf36c1fe0fb399c8044fce17e8fc02936db + # via requests +webencodings==0.5.1 \ + --hash=sha256:5d65b7d725951f58509b737028fb8ba2a576ee87c4d454ea0a121cda690875ed \ + --hash=sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78 \ + --hash=sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78 \ + --hash=sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78 \ + --hash=sha256:ea5ad2d6c5efc2f7de6b721fb3712f27428a9a9ad6d2a96b9abd414d84089a73 \ + --hash=sha256:ea5ad2d6c5efc2f7de6b721fb3712f27428a9a9ad6d2a96b9abd414d84089a73 + # via html5lib diff --git a/libs/libyuv/winarm.mk b/libs/libyuv/winarm.mk index c4307a431f..b0a344ae06 100644 --- a/libs/libyuv/winarm.mk +++ b/libs/libyuv/winarm.mk @@ -31,6 +31,7 @@ LOCAL_OBJ_FILES = \ source/scale_any.o\ source/scale_argb.o\ source/scale_common.o\ + source/scale_uv.o\ source/video_common.o .cc.o: diff --git a/libs/win32/libyuv/libyuv.2017.vcxproj b/libs/win32/libyuv/libyuv.2017.vcxproj index f74f7e1203..8d1dc74fba 100644 --- a/libs/win32/libyuv/libyuv.2017.vcxproj +++ b/libs/win32/libyuv/libyuv.2017.vcxproj @@ -133,10 +133,10 @@ - - + + @@ -154,27 +154,43 @@ - - + + + + + + + - - + + + + + + + - - + + + + + + + + @@ -187,16 +203,20 @@ - + + + + + From 13fd84b33c302c508297bb387e1dcea1acb48e8d Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 20 Jul 2026 23:23:38 +0300 Subject: [PATCH 51/88] [libyuv] Build AArch64 dotprod/i8mm/SVE/SME kernels with per-file -march to fix arm64/macOS build --- Makefile.am | 49 ++++++++++++++++++++++++++++++++++++++++--------- configure.ac | 22 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6d1982842d..ace180b046 100644 --- a/Makefile.am +++ b/Makefile.am @@ -180,7 +180,6 @@ libs/libyuv/source/compare.cc \ libs/libyuv/source/compare_common.cc \ libs/libyuv/source/compare_gcc.cc \ libs/libyuv/source/compare_hvx.cc \ -libs/libyuv/source/compare_neon64.cc \ libs/libyuv/source/compare_neon.cc \ libs/libyuv/source/compare_wasm.cc \ libs/libyuv/source/compare_win.cc \ @@ -203,11 +202,8 @@ libs/libyuv/source/rotate_gcc.cc \ libs/libyuv/source/rotate_hvx.cc \ libs/libyuv/source/rotate_lasx.cc \ libs/libyuv/source/rotate_lsx.cc \ -libs/libyuv/source/rotate_neon64.cc \ libs/libyuv/source/rotate_neon.cc \ libs/libyuv/source/rotate_rvv.cc \ -libs/libyuv/source/rotate_sme.cc \ -libs/libyuv/source/rotate_sve.cc \ libs/libyuv/source/rotate_wasm.cc \ libs/libyuv/source/rotate_win.cc \ libs/libyuv/source/row_any.cc \ @@ -216,11 +212,8 @@ libs/libyuv/source/row_gcc.cc \ libs/libyuv/source/row_hvx.cc \ libs/libyuv/source/row_lasx.cc \ libs/libyuv/source/row_lsx.cc \ -libs/libyuv/source/row_neon64.cc \ libs/libyuv/source/row_neon.cc \ libs/libyuv/source/row_rvv.cc \ -libs/libyuv/source/row_sme.cc \ -libs/libyuv/source/row_sve.cc \ libs/libyuv/source/row_wasm.cc \ libs/libyuv/source/row_win.cc \ libs/libyuv/source/scale_any.cc \ @@ -230,11 +223,9 @@ libs/libyuv/source/scale_common.cc \ libs/libyuv/source/scale_gcc.cc \ libs/libyuv/source/scale_hvx.cc \ libs/libyuv/source/scale_lsx.cc \ -libs/libyuv/source/scale_neon64.cc \ libs/libyuv/source/scale_neon.cc \ libs/libyuv/source/scale_rgb.cc \ libs/libyuv/source/scale_rvv.cc \ -libs/libyuv/source/scale_sme.cc \ libs/libyuv/source/scale_uv.cc \ libs/libyuv/source/scale_wasm.cc \ libs/libyuv/source/scale_win.cc \ @@ -242,6 +233,46 @@ libs/libyuv/source/video_common.cc libfreeswitch_libyuv_la_CPPFLAGS = -O2 -fomit-frame-pointer -Ilibs/libyuv/include +libfreeswitch_libyuv_la_LIBADD = + +# libyuv's AArch64 dot-product (udot), i8mm (usdot), SVE and SME kernels emit +# instructions outside the baseline armv8-a target and are selected at runtime +# by libyuv's own CPU detection. Build them as separate objects with the +# required -march flags so the rest of the library stays portable to any +# armv8-a CPU. This mirrors libs/libyuv/CMakeLists.txt. +if LIBYUV_AARCH64 +noinst_LTLIBRARIES += libfreeswitch_libyuv_neon64.la +libfreeswitch_libyuv_neon64_la_SOURCES = \ +libs/libyuv/source/compare_neon64.cc \ +libs/libyuv/source/rotate_neon64.cc \ +libs/libyuv/source/row_neon64.cc \ +libs/libyuv/source/scale_neon64.cc +libfreeswitch_libyuv_neon64_la_CPPFLAGS = $(libfreeswitch_libyuv_la_CPPFLAGS) +libfreeswitch_libyuv_neon64_la_CXXFLAGS = -march=armv8.2-a+dotprod+i8mm +libfreeswitch_libyuv_la_LIBADD += libfreeswitch_libyuv_neon64.la + +noinst_LTLIBRARIES += libfreeswitch_libyuv_sve.la +libfreeswitch_libyuv_sve_la_SOURCES = \ +libs/libyuv/source/rotate_sve.cc \ +libs/libyuv/source/row_sve.cc +libfreeswitch_libyuv_sve_la_CPPFLAGS = $(libfreeswitch_libyuv_la_CPPFLAGS) +libfreeswitch_libyuv_sve_la_CXXFLAGS = -march=armv8.5-a+i8mm+sve2 +libfreeswitch_libyuv_la_LIBADD += libfreeswitch_libyuv_sve.la + +if LIBYUV_AARCH64_SME +noinst_LTLIBRARIES += libfreeswitch_libyuv_sme.la +libfreeswitch_libyuv_sme_la_SOURCES = \ +libs/libyuv/source/rotate_sme.cc \ +libs/libyuv/source/row_sme.cc \ +libs/libyuv/source/scale_sme.cc +libfreeswitch_libyuv_sme_la_CPPFLAGS = $(libfreeswitch_libyuv_la_CPPFLAGS) +libfreeswitch_libyuv_sme_la_CXXFLAGS = -march=armv8.5-a+i8mm+sme +libfreeswitch_libyuv_la_LIBADD += libfreeswitch_libyuv_sme.la +else +libfreeswitch_libyuv_la_CPPFLAGS += -DLIBYUV_DISABLE_SME +endif +endif + CORE_LIBS+=libfreeswitch_libyuv.la endif diff --git a/configure.ac b/configure.ac index 9507ab6fe1..08be69e1ff 100644 --- a/configure.ac +++ b/configure.ac @@ -549,6 +549,28 @@ AC_ARG_ENABLE(libyuv, AM_CONDITIONAL([ENABLE_LIBYUV],[test "${enable_libyuv}" = "yes"]) +# libyuv's AArch64 SIMD kernels (dot-product, i8mm, SVE, SME) use instructions +# outside the baseline armv8-a target, so they must be compiled with per-file +# -march flags (see Makefile.am). These conditionals mirror the logic in +# libs/libyuv/CMakeLists.txt. +AM_CONDITIONAL([LIBYUV_AARCH64], + [test "x$host_cpu" = "xaarch64" || test "x$host_cpu" = "xarm64"]) + +libyuv_have_sme=no +AS_IF([test "x$host_cpu" = "xaarch64" || test "x$host_cpu" = "xarm64"], [ + AC_LANG_PUSH([C]) + libyuv_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -march=armv8.5-a+i8mm+sme" + AC_MSG_CHECKING([whether $CC supports AArch64 SME kernels]) + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[__arm_locally_streaming void func(void) { } +int main(void) { return 0; }]])], + [libyuv_have_sme=yes]) + AC_MSG_RESULT([$libyuv_have_sme]) + CFLAGS="$libyuv_save_CFLAGS" + AC_LANG_POP([C]) +]) +AM_CONDITIONAL([LIBYUV_AARCH64_SME], [test "x$libyuv_have_sme" = "xyes"]) + AC_ARG_ENABLE(libvpx, [AC_HELP_STRING([--disable-libvpx],[build without libvpx])],[enable_libvpx="$enableval"],[enable_libvpx="yes"]) From 7f73f94c15e200e8b176c8d63a164d6815ea111e Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 31 Oct 2026 13:28:55 +0300 Subject: [PATCH 52/88] [libyuv] Fix build with GCC HammingDistance_AVX512VNNI clobbers k1 but lacks the LIBYUV_TARGET_AVX512VNNI attribute that its siblings use, so GCC on x86_64 fails with "the register 'k1' cannot be clobbered in 'asm' for the current target". ARGBAlphaBlendRow_SVE_SC uses "mov z25.s, #0x01010101", which the GNU assembler rejects as an invalid replicated MOV immediate. Use the equivalent "mov z25.b, #1", which sets the same value and is accepted by both GNU as and LLVM. --- libs/libyuv/include/libyuv/row_sve.h | 2 +- libs/libyuv/source/compare_gcc.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/libyuv/include/libyuv/row_sve.h b/libs/libyuv/include/libyuv/row_sve.h index 7faf57db84..da7620d410 100644 --- a/libs/libyuv/include/libyuv/row_sve.h +++ b/libs/libyuv/include/libyuv/row_sve.h @@ -2484,7 +2484,7 @@ static inline void ARGBAlphaBlendRow_SVE_SC(const uint8_t* src_argb0, "cntw %x[vl] \n" "ptrue p0.b \n" "mov z24.h, #1 \n" - "mov z25.s, #0x01010101 \n" + "mov z25.b, #1 \n" "mov z26.s, #0x00ffffff \n" "subs %w[width], %w[width], %w[vl], lsl #1 \n" "b.lt 2f \n" diff --git a/libs/libyuv/source/compare_gcc.cc b/libs/libyuv/source/compare_gcc.cc index 5828ceaa7b..ede75ff6e0 100644 --- a/libs/libyuv/source/compare_gcc.cc +++ b/libs/libyuv/source/compare_gcc.cc @@ -458,6 +458,7 @@ uint32_t HammingDistance_AVX512BW(const uint8_t* src_a, #ifdef HAS_HAMMINGDISTANCE_AVX512VNNI // Process 64 bytes per loop and the remainder of 1 to 63 bytes with masked // loads that read zeros, accumulating byte popcounts with vpdpbusd. +LIBYUV_TARGET_AVX512VNNI uint32_t HammingDistance_AVX512VNNI(const uint8_t* src_a, const uint8_t* src_b, int count) { From b21fc93b78d41d575b0bf1a6f068c797a15dd177 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 31 Oct 2026 13:29:08 +0300 Subject: [PATCH 53/88] [libyuv] Fix function declaration without a prototype --- libs/libyuv/include/libyuv/cpu_id.h | 2 +- libs/libyuv/source/cpu_id.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/libyuv/include/libyuv/cpu_id.h b/libs/libyuv/include/libyuv/cpu_id.h index 54512b766d..67992258a3 100644 --- a/libs/libyuv/include/libyuv/cpu_id.h +++ b/libs/libyuv/include/libyuv/cpu_id.h @@ -108,7 +108,7 @@ LIBYUV_API int AArch64CpuCaps(unsigned long hwcap, unsigned long hwcap2); #else LIBYUV_API -int AArch64CpuCaps(); +int AArch64CpuCaps(void); #endif // For testing, allow CPU flags to be disabled. diff --git a/libs/libyuv/source/cpu_id.cc b/libs/libyuv/source/cpu_id.cc index f78283a972..cca1da831c 100644 --- a/libs/libyuv/source/cpu_id.cc +++ b/libs/libyuv/source/cpu_id.cc @@ -229,7 +229,7 @@ LIBYUV_API SAFEBUFFERS int AArch64CpuCaps(unsigned long hwcap, #elif defined(_WIN32) // For AArch64, but public to allow testing on any CPU. -LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() { +LIBYUV_API SAFEBUFFERS int AArch64CpuCaps(void) { // Neon is mandatory on AArch64, so enable unconditionally. int features = kCpuHasNEON; @@ -259,7 +259,7 @@ static bool have_feature(const char* feature) { } // For AArch64, but public to allow testing on any CPU. -LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() { +LIBYUV_API SAFEBUFFERS int AArch64CpuCaps(void) { // Neon is mandatory on AArch64, so enable unconditionally. int features = kCpuHasNEON; @@ -288,7 +288,7 @@ LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() { #else // !defined(__linux__) && !defined(_WIN32) && !defined(__APPLE__) // For AArch64, but public to allow testing on any CPU. -LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() { +LIBYUV_API SAFEBUFFERS int AArch64CpuCaps(void) { // Neon is mandatory on AArch64, so enable unconditionally. int features = kCpuHasNEON; From 1836c1f345cbaf56935e3ab1db67453859b99ad6 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 31 Oct 2026 14:30:03 +0300 Subject: [PATCH 54/88] [libyuv] Disable scan-build warnings. --- libs/libyuv/source/row_gcc.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/libyuv/source/row_gcc.cc b/libs/libyuv/source/row_gcc.cc index 3abe073b02..e73ee6cee6 100644 --- a/libs/libyuv/source/row_gcc.cc +++ b/libs/libyuv/source/row_gcc.cc @@ -8830,6 +8830,9 @@ void HalfWidthRow_16To8_Odd_AVX2(const uint16_t* src_uv, int r = (width - 1) & 15; SIMD_ALIGNED(uint16_t pair[64]); SIMD_ALIGNED(uint8_t out[16]); +#ifdef __clang_analyzer__ + memset(out, 0, sizeof(out)); +#endif if (n > 0) { HalfWidthRow_16To8_AVX2(src_uv, src_uv_stride, dst_uv, scale, n); src_uv += n * 2; From 7481baed1886ed6505227e23a184ec85ed55d201 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 16 Nov 2026 23:18:14 +0300 Subject: [PATCH 55/88] [Core] Remove in-tree miniupnpc: use libminiupnpc-dev on Linux and the windows-deps package on Windows (#3289) --- .github/workflows/macos.yml | 1 + .gitignore | 2 + LICENSE | 8 - Makefile.am | 13 +- build/Makefile.centos6 | 4 +- configure.ac | 1 + debian/bootstrap.sh | 1 + debian/copyright | 8 - debian/license-reconcile.yml | 8 - docs/Doxygen.conf | 2 +- freeswitch.spec | 2 + libs/miniupnpc/Changelog.txt | 250 ------ libs/miniupnpc/LICENCE | 26 - libs/miniupnpc/Makefile | 127 --- libs/miniupnpc/Makefile.mingw | 74 -- libs/miniupnpc/README | 54 -- libs/miniupnpc/bsdqueue.h | 531 ------------ libs/miniupnpc/codelength.h | 24 - libs/miniupnpc/declspec.h | 15 - libs/miniupnpc/igd_desc_parse.c | 113 --- libs/miniupnpc/igd_desc_parse.h | 47 -- libs/miniupnpc/man3/miniupnpc.3 | 52 -- libs/miniupnpc/mingw32make.bat | 7 - libs/miniupnpc/minisoap.c | 115 --- libs/miniupnpc/minisoap.h | 15 - libs/miniupnpc/minissdpc.c | 127 --- libs/miniupnpc/minissdpc.h | 15 - libs/miniupnpc/miniupnpc.c | 760 ------------------ libs/miniupnpc/miniupnpc.def | 31 - libs/miniupnpc/miniupnpc.h | 110 --- libs/miniupnpc/miniupnpcmodule.c | 460 ----------- libs/miniupnpc/miniupnpcstrings.h | 15 - libs/miniupnpc/miniwget.c | 282 ------- libs/miniupnpc/miniwget.h | 28 - libs/miniupnpc/minixml.c | 191 ----- libs/miniupnpc/minixml.h | 37 - libs/miniupnpc/minixmlvalid.c | 149 ---- libs/miniupnpc/pymoduletest.py | 52 -- libs/miniupnpc/setup.py | 15 - libs/miniupnpc/setupmingw32.py | 15 - libs/miniupnpc/testigddescparse.c | 57 -- libs/miniupnpc/testminixml.c | 88 -- libs/miniupnpc/testupnpigd.py | 84 -- libs/miniupnpc/testupnpreplyparse.c | 44 - libs/miniupnpc/updateminiupnpcstrings.sh | 36 - libs/miniupnpc/upnpc.c | 374 --------- libs/miniupnpc/upnpcommands.c | 573 ------------- libs/miniupnpc/upnpcommands.h | 193 ----- libs/miniupnpc/upnperrors.c | 66 -- libs/miniupnpc/upnperrors.h | 26 - libs/miniupnpc/upnpreplyparse.c | 127 --- libs/miniupnpc/upnpreplyparse.h | 62 -- .../FreeSWITCH-debian-raspbian-installer.sh | 2 +- scripts/debian_min_build.sh | 2 +- src/switch_nat.c | 61 +- .../FreeSwitchCore.2010.vcxproj.filters | 30 - w32/Library/FreeSwitchCore.2017.vcxproj | 236 +----- w32/miniupnpc-version.props | 21 + w32/miniupnpc.props | 60 ++ 59 files changed, 135 insertions(+), 5794 deletions(-) delete mode 100644 libs/miniupnpc/Changelog.txt delete mode 100644 libs/miniupnpc/LICENCE delete mode 100644 libs/miniupnpc/Makefile delete mode 100644 libs/miniupnpc/Makefile.mingw delete mode 100644 libs/miniupnpc/README delete mode 100644 libs/miniupnpc/bsdqueue.h delete mode 100644 libs/miniupnpc/codelength.h delete mode 100644 libs/miniupnpc/declspec.h delete mode 100644 libs/miniupnpc/igd_desc_parse.c delete mode 100644 libs/miniupnpc/igd_desc_parse.h delete mode 100644 libs/miniupnpc/man3/miniupnpc.3 delete mode 100644 libs/miniupnpc/mingw32make.bat delete mode 100644 libs/miniupnpc/minisoap.c delete mode 100644 libs/miniupnpc/minisoap.h delete mode 100644 libs/miniupnpc/minissdpc.c delete mode 100644 libs/miniupnpc/minissdpc.h delete mode 100644 libs/miniupnpc/miniupnpc.c delete mode 100644 libs/miniupnpc/miniupnpc.def delete mode 100644 libs/miniupnpc/miniupnpc.h delete mode 100644 libs/miniupnpc/miniupnpcmodule.c delete mode 100644 libs/miniupnpc/miniupnpcstrings.h delete mode 100644 libs/miniupnpc/miniwget.c delete mode 100644 libs/miniupnpc/miniwget.h delete mode 100644 libs/miniupnpc/minixml.c delete mode 100644 libs/miniupnpc/minixml.h delete mode 100644 libs/miniupnpc/minixmlvalid.c delete mode 100644 libs/miniupnpc/pymoduletest.py delete mode 100644 libs/miniupnpc/setup.py delete mode 100755 libs/miniupnpc/setupmingw32.py delete mode 100644 libs/miniupnpc/testigddescparse.c delete mode 100644 libs/miniupnpc/testminixml.c delete mode 100755 libs/miniupnpc/testupnpigd.py delete mode 100644 libs/miniupnpc/testupnpreplyparse.c delete mode 100755 libs/miniupnpc/updateminiupnpcstrings.sh delete mode 100644 libs/miniupnpc/upnpc.c delete mode 100644 libs/miniupnpc/upnpcommands.c delete mode 100644 libs/miniupnpc/upnpcommands.h delete mode 100644 libs/miniupnpc/upnperrors.c delete mode 100644 libs/miniupnpc/upnperrors.h delete mode 100644 libs/miniupnpc/upnpreplyparse.c delete mode 100644 libs/miniupnpc/upnpreplyparse.h create mode 100644 w32/miniupnpc-version.props create mode 100644 w32/miniupnpc.props diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 229566af50..ec3ad6525f 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -43,6 +43,7 @@ jobs: libsndfile \ libtool \ lua \ + miniupnpc \ opus \ ossp-uuid \ pcre2 \ diff --git a/.gitignore b/.gitignore index f4adb571b9..d7e1801528 100644 --- a/.gitignore +++ b/.gitignore @@ -295,6 +295,8 @@ libs/libjpeg-*/ libs/libjpeg-*.zip libs/freetype-*/ libs/freetype-*.zip +libs/miniupnpc-*/ +libs/miniupnpc-*.zip libs/SharpZipLib.*/ libs/SharpZipLib.*.nupkg libs/nasm-*/ diff --git a/LICENSE b/LICENSE index 7f97608acb..72dfbe3062 100644 --- a/LICENSE +++ b/LICENSE @@ -1246,14 +1246,6 @@ Copyright: 2000-2005 The Apache Software Foundation or its licensors 1992-1996 Regents of the University of Michigan License: Apache-2.0 and OpenLDAP and BSD-like -Files: libs/miniupnpc/* -Copyright: 2005-2009, Thomas Bernard -License: BSD-3-clause - -Files: libs/miniupnpc/bsdqueue.h -Copyright: 1991,1993, The Regents of the University of California -License: BSD-3-clause - Files: libs/js/* Copyright: 1998-2006 Mozilla 1996-2000 Netscape Communications Corporation diff --git a/Makefile.am b/Makefile.am index ace180b046..c6fa430dda 100644 --- a/Makefile.am +++ b/Makefile.am @@ -277,9 +277,9 @@ CORE_LIBS+=libfreeswitch_libyuv.la endif lib_LTLIBRARIES = libfreeswitch.la -libfreeswitch_la_CFLAGS = $(CORE_CFLAGS) $(SQLITE_CFLAGS) $(GUMBO_CFLAGS) $(FVAD_CFLAGS) $(FREETYPE_CFLAGS) $(CURL_CFLAGS) $(PCRE2_CFLAGS) $(SPEEX_CFLAGS) $(LIBEDIT_CFLAGS) $(openssl_CFLAGS) $(SOFIA_SIP_CFLAGS) $(AM_CFLAGS) $(TPL_CFLAGS) +libfreeswitch_la_CFLAGS = $(CORE_CFLAGS) $(SQLITE_CFLAGS) $(GUMBO_CFLAGS) $(FVAD_CFLAGS) $(FREETYPE_CFLAGS) $(CURL_CFLAGS) $(PCRE2_CFLAGS) $(SPEEX_CFLAGS) $(MINIUPNPC_CFLAGS) $(LIBEDIT_CFLAGS) $(openssl_CFLAGS) $(SOFIA_SIP_CFLAGS) $(AM_CFLAGS) $(TPL_CFLAGS) libfreeswitch_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) $(PLATFORM_CORE_LDFLAGS) -no-undefined -libfreeswitch_la_LIBADD = $(CORE_LIBS) $(APR_LIBS) $(SQLITE_LIBS) $(GUMBO_LIBS) $(FVAD_LIBS) $(FREETYPE_LIBS) $(CURL_LIBS) $(PCRE2_LIBS) $(SPEEX_LIBS) $(LIBEDIT_LIBS) $(SYSTEMD_LIBS) $(openssl_LIBS) $(PLATFORM_CORE_LIBS) $(TPL_LIBS) $(SPANDSP_LIBS) $(SOFIA_SIP_LIBS) +libfreeswitch_la_LIBADD = $(CORE_LIBS) $(APR_LIBS) $(SQLITE_LIBS) $(GUMBO_LIBS) $(FVAD_LIBS) $(FREETYPE_LIBS) $(CURL_LIBS) $(PCRE2_LIBS) $(SPEEX_LIBS) $(MINIUPNPC_LIBS) $(LIBEDIT_LIBS) $(SYSTEMD_LIBS) $(openssl_LIBS) $(PLATFORM_CORE_LIBS) $(TPL_LIBS) $(SPANDSP_LIBS) $(SOFIA_SIP_LIBS) libfreeswitch_la_DEPENDENCIES = $(BUILT_SOURCES) if HAVE_PNG @@ -430,15 +430,6 @@ libfreeswitch_la_SOURCES = \ src/switch_vpx.c \ libs/libteletone/src/libteletone_detect.c \ libs/libteletone/src/libteletone_generate.c \ - libs/miniupnpc/miniwget.c \ - libs/miniupnpc/minixml.c \ - libs/miniupnpc/igd_desc_parse.c \ - libs/miniupnpc/minisoap.c \ - libs/miniupnpc/miniupnpc.c \ - libs/miniupnpc/upnpreplyparse.c \ - libs/miniupnpc/upnpcommands.c \ - libs/miniupnpc/minissdpc.c \ - libs/miniupnpc/upnperrors.c \ libs/libnatpmp/natpmp.c \ libs/libnatpmp/getgateway.c \ src/switch_uuidv7.c diff --git a/build/Makefile.centos6 b/build/Makefile.centos6 index ff03d124ef..062384a5f5 100644 --- a/build/Makefile.centos6 +++ b/build/Makefile.centos6 @@ -6,8 +6,8 @@ # in that same directory. # # -RPMS=git gcc-c++ autoconf automake libtool wget ncurses-devel zlib-devel libjpeg-devel openssl-devel e2fsprogs-devel sqlite-devel libcurl-devel pcre2-devel speex-devel ldns-devel libedit-devel -DEBS=git build-essential automake autoconf 'libtool-bin|libtool' wget uuid-dev zlib1g-dev 'libjpeg8-dev|libjpeg62-turbo-dev' libncurses5-dev libssl-dev libpcre2-dev libcurl4-openssl-dev libldns-dev libedit-dev libspeexdsp-dev libspeexdsp-dev libsqlite3-dev perl libgdbm-dev libdb-dev bison libvlc-dev pkg-config +RPMS=git gcc-c++ autoconf automake libtool wget ncurses-devel zlib-devel libjpeg-devel openssl-devel e2fsprogs-devel sqlite-devel libcurl-devel pcre2-devel speex-devel miniupnpc-devel ldns-devel libedit-devel +DEBS=git build-essential automake autoconf 'libtool-bin|libtool' wget uuid-dev zlib1g-dev 'libjpeg8-dev|libjpeg62-turbo-dev' libncurses5-dev libssl-dev libpcre2-dev libcurl4-openssl-dev libldns-dev libedit-dev libspeexdsp-dev libspeexdsp-dev libsqlite3-dev libminiupnpc-dev perl libgdbm-dev libdb-dev bison libvlc-dev pkg-config freeswitch: deps has-git freeswitch.git/Makefile cd freeswitch.git && make diff --git a/configure.ac b/configure.ac index 08be69e1ff..92179dd23a 100644 --- a/configure.ac +++ b/configure.ac @@ -1346,6 +1346,7 @@ PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.6.20]) PKG_CHECK_MODULES([CURL], [libcurl >= 7.19]) PKG_CHECK_MODULES([PCRE2], [libpcre2-8 >= 10.00]) PKG_CHECK_MODULES([SPEEX], [speex >= 1.2rc1 speexdsp >= 1.2rc1]) +PKG_CHECK_MODULES([MINIUPNPC], [miniupnpc >= 2.1]) PKG_CHECK_MODULES([LDNS], [libldns-fs >= 1.6.6],[ AM_CONDITIONAL([HAVE_LDNS],[true])],[ PKG_CHECK_MODULES([LDNS], [libldns >= 1.6.6],[ diff --git a/debian/bootstrap.sh b/debian/bootstrap.sh index 58fdd15cc7..6d562a0652 100755 --- a/debian/bootstrap.sh +++ b/debian/bootstrap.sh @@ -303,6 +303,7 @@ Build-Depends: libedit-dev (>= 2.11), libsqlite3-dev, libtiff5-dev, + libminiupnpc-dev (>= 2.1), wget, pkg-config, yasm, # core codecs diff --git a/debian/copyright b/debian/copyright index 787e8dbd46..3a9d364f5c 100755 --- a/debian/copyright +++ b/debian/copyright @@ -1246,14 +1246,6 @@ Copyright: 2000-2005 The Apache Software Foundation or its licensors 1992-1996 Regents of the University of Michigan License: Apache-2.0 and OpenLDAP and BSD-like -Files: libs/miniupnpc/* -Copyright: 2005-2009, Thomas Bernard -License: BSD-3-clause - -Files: libs/miniupnpc/bsdqueue.h -Copyright: 1991,1993, The Regents of the University of California -License: BSD-3-clause - Files: libs/js/* Copyright: 1998-2006 Mozilla 1996-2000 Netscape Communications Corporation diff --git a/debian/license-reconcile.yml b/debian/license-reconcile.yml index d547556a3c..da22ce95ab 100644 --- a/debian/license-reconcile.yml +++ b/debian/license-reconcile.yml @@ -1,13 +1,5 @@ Rules: rules: - - - Glob: libs/miniupnpc/* - Matches: Thomas\sBERNARD - Copyright: Thomas Bernard - - - Glob: libs/miniupnpc/bsdqueue.h - Matches: The\sRegents\sof\sthe\sUniversity\sof\sCalifornia.\s+All\srights\sreserved. - Copyright: The Regents of the University of California. - Glob: libs/sofia-sip/libsofia-sip-ua/su/poll.c Matches: Free\sSoftware\sFoundation,\sInc. diff --git a/docs/Doxygen.conf b/docs/Doxygen.conf index e9394d18bb..8db1f0dbfb 100644 --- a/docs/Doxygen.conf +++ b/docs/Doxygen.conf @@ -1241,7 +1241,7 @@ SEARCH_INCLUDES = YES # the preprocessor. INCLUDE_PATH =../libs/apr ../libs/apr-util ../libs/libnatpmp \ - ../libs/miniupnpc ../libs/sofia-sip ../libs/spandsp \ + ../libs/sofia-sip ../libs/spandsp \ ../libs/srtp ../libs/win32 ../libs/xmlrpc-c # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard diff --git a/freeswitch.spec b/freeswitch.spec index d75619bbee..7a0887df79 100755 --- a/freeswitch.spec +++ b/freeswitch.spec @@ -135,6 +135,7 @@ BuildRequires: sofia-sip-devel >= 1.13.19 BuildRequires: spandsp4-devel >= 3.1.1 BuildRequires: pcre2-devel BuildRequires: speex-devel +BuildRequires: miniupnpc-devel >= 2.1 BuildRequires: sqlite-devel >= 3.6.20 BuildRequires: libtiff-devel BuildRequires: libedit-devel @@ -149,6 +150,7 @@ BuildRequires: libsndfile-devel Requires: curl >= 7.19 Requires: pcre2 Requires: speex +Requires: miniupnpc >= 2.1 Requires: sqlite >= 3.6.20 Requires: libtiff Requires: libedit diff --git a/libs/miniupnpc/Changelog.txt b/libs/miniupnpc/Changelog.txt deleted file mode 100644 index e34543fece..0000000000 --- a/libs/miniupnpc/Changelog.txt +++ /dev/null @@ -1,250 +0,0 @@ -$Id: Changelog.txt,v 1.80 2009/04/17 21:21:19 nanard Exp $ -miniUPnP client Changelog. - -2009/04/17: - updating python module - Use strtoull() when using C99 - -2009/02/28: - Fixed miniwget.c for compiling under sun - -2008/12/18: - cleanup in Makefile (thanks to Paul de Weerd) - minissdpc.c : win32 compatibility - miniupnpc.c : changed xmlns prefix from 'm' to 'u' - Removed NDEBUG (using DEBUG) - -2008/10/14: - Added the ExternalHost argument to DeletePortMapping() - -2008/10/11: - Added the ExternalHost argument to AddPortMapping() - Put a correct User-Agent: header in HTTP requests. - -VERSION 1.2 : - -2008/10/07: - Update docs - -2008/09/25: - Integrated sameport patch from Dario Meloni : Added a "sameport" - argument to upnpDiscover(). - -2008/07/18: - small modif to make Clang happy :) - -2008/07/17: - #define SOAPPREFIX "s" in miniupnpc.c in order to remove SOAP-ENV... - -2008/07/14: - include declspec.h in installation (to /usr/include/miniupnpc) - -VERSION 1.1 : - -2008/07/04: - standard options for install/ln instead of gnu-specific stuff. - -2008/07/03: - now builds a .dll and .lib with win32. (mingw32) - -2008/04/28: - make install now install the binary of the upnpc tool - -2008/04/27: - added testupnpigd.py - added error strings for miniupnpc "internal" errors - improved python module error/exception reporting. - -2008/04/23: - Completely rewrite igd_desc_parse.c in order to be compatible with - Linksys WAG200G - Added testigddescparse - updated python module - -VERSION 1.0 : - -2008/02/21: - put some #ifdef DEBUG around DisplayNameValueList() - -2008/02/18: - Improved error reporting in upnpcommands.c - UPNP_GetStatusInfo() returns LastConnectionError - -2008/02/16: - better error handling in minisoap.c - improving display of "valid IGD found" in upnpc.c - -2008/02/03: - Fixing UPNP_GetValidIGD() - improved make install :) - -2007/12/22: - Adding upnperrors.c/h to provide a strupnperror() function - used to translate UPnP error codes to string. - -2007/12/19: - Fixing getDevicesFromMiniSSDPD() - improved error reporting of UPnP functions - -2007/12/18: - It is now possible to specify a different location for MiniSSDPd socket. - working with MiniSSDPd is now more efficient. - python module improved. - -2007/12/16: - improving error reporting - -2007/12/13: - Try to improve compatibility by using HTTP/1.0 instead of 1.1 and - XML a bit different for SOAP. - -2007/11/25: - fixed select() call for linux - -2007/11/15: - Added -fPIC to CFLAG for better shared library code. - -2007/11/02: - Fixed a potential socket leak in miniwget2() - -2007/10/16: - added a parameter to upnpDiscover() in order to allow the use of another - interface than the default multicast interface. - -2007/10/12: - Fixed the creation of symbolic link in Makefile - -2007/10/08: - Added man page - -2007/10/02: - fixed memory bug in GetUPNPUrls() - -2007/10/01: - fixes in the Makefile - Added UPNP_GetIGDFromUrl() and adapted the sample program accordingly. - Added SONAME in the shared library to please debian :) - fixed MS Windows compilation (minissdpd is not available under MS Windows). - -2007/09/25: - small change to Makefile to be able to install in a different location - (default is /usr) - -2007/09/24: - now compiling both shared and static library - -2007/09/19: - Cosmetic changes on upnpc.c - -2007/09/02: - adapting to new miniSSDPd (release version ?) - -2007/08/31: - Usage of miniSSDPd to skip discovery process. - -2007/08/27: - fixed python module to allow compilation with Python older than Python 2.4 - -2007/06/12: - Added a python module. - -2007/05/19: - Fixed compilation under MinGW - -2007/05/15: - fixed a memory leak in AddPortMapping() - Added testupnpreplyparse executable to check the parsing of - upnp soap messages - minixml now ignore namespace prefixes. - -2007/04/26: - upnpc now displays external ip address with -s or -l - -2007/04/11: - changed MINIUPNPC_URL_MAXSIZE to 128 to accomodate the "BT Voyager 210" - -2007/03/19: - cleanup in miniwget.c - -2007/03/01: - Small typo fix... - -2007/01/30: - Now parsing the HTTP header from SOAP responses in order to - get content-length value. - -2007/01/29: - Fixed the Soap Query to speedup the HTTP request. - added some Win32 DLL stuff... - -2007/01/27: - Fixed some WIN32 compatibility issues - -2006/12/14: - Added UPNPIGD_IsConnected() function in miniupnp.c/.h - Added UPNP_GetValidIGD() in miniupnp.c/.h - cleaned upnpc.c main(). now using UPNP_GetValidIGD() - -2006/12/07: - Version 1.0-RC1 released - -2006/12/03: - Minor changes to compile under SunOS/Solaris - -2006/11/30: - made a minixml parser validator program - updated minixml to handle attributes correctly - -2006/11/22: - Added a -r option to the upnpc sample thanks to Alexander Hubmann. - -2006/11/19: - Cleanup code to make it more ANSI C compliant - -2006/11/10: - detect and display local lan address. - -2006/11/04: - Packets and Bytes Sent/Received are now unsigned int. - -2006/11/01: - Bug fix thanks to Giuseppe D'Angelo - -2006/10/31: - C++ compatibility for .h files. - Added a way to get ip Address on the LAN used to reach the IGD. - -2006/10/25: - Added M-SEARCH to the services in the discovery process. - -2006/10/22: - updated the Makefile to use makedepend, added a "make install" - update Makefile - -2006/10/20: - fixing the description url parsing thanks to patch sent by - Wayne Dawe. - Fixed/translated some comments. - Implemented a better discover process, first looking - for IGD then for root devices (as some devices only reply to - M-SEARCH for root devices). - -2006/09/02: - added freeUPNPDevlist() function. - -2006/08/04: - More command line arguments checking - -2006/08/01: - Added the .bat file to compile under Win32 with minGW32 - -2006/07/31: - Fixed the rootdesc parser (igd_desc_parse.c) - -2006/07/20: - parseMSEARCHReply() is now returning the ST: line as well - starting changes to detect several UPnP devices on the network - -2006/07/19: - using GetCommonLinkProperties to get down/upload bitrate - diff --git a/libs/miniupnpc/LICENCE b/libs/miniupnpc/LICENCE deleted file mode 100644 index a8cfb5ef38..0000000000 --- a/libs/miniupnpc/LICENCE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2005-2008, Thomas BERNARD -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - diff --git a/libs/miniupnpc/Makefile b/libs/miniupnpc/Makefile deleted file mode 100644 index 9cac2accca..0000000000 --- a/libs/miniupnpc/Makefile +++ /dev/null @@ -1,127 +0,0 @@ -# $Id: Makefile,v 1.48 2008/12/18 17:46:13 nanard Exp $ -# MiniUPnP Project -# http://miniupnp.free.fr/ -# (c) 2005-2007 Thomas Bernard -# to install use : -# $ PREFIX=/tmp/dummylocation make install -# or -# $ INSTALLPREFIX=/usr/local make install -# or -# make install (will go to /usr/bin, /usr/lib, etc...) -CC ?= gcc -#AR = gar -#CFLAGS = -fPIC -O -Wall -g -DDEBUG -CFLAGS ?= -fPIC -O -Wall -DNDEBUG -INSTALL = install -#following libs are needed on Solaris -#LDLIBS=-lsocket -lnsl -lresolv - -# APIVERSION is used to build SONAME -APIVERSION = 4 - -SRCS = igd_desc_parse.c miniupnpc.c minixml.c minisoap.c miniwget.c \ - upnpc.c upnpcommands.c upnpreplyparse.c testminixml.c \ - minixmlvalid.c testupnpreplyparse.c minissdpc.c \ - upnperrors.c testigddescparse.c - -LIBOBJS = miniwget.o minixml.o igd_desc_parse.o minisoap.o \ - miniupnpc.o upnpreplyparse.o upnpcommands.o minissdpc.o \ - upnperrors.o - -OBJS = $(patsubst %.c,%.o,$(SRCS)) - -# HEADERS to install -HEADERS = miniupnpc.h miniwget.h upnpcommands.h igd_desc_parse.h \ - upnpreplyparse.h upnperrors.h declspec.h -LIBRARY = libminiupnpc.a -SHAREDLIBRARY = libminiupnpc.so -SONAME = $(SHAREDLIBRARY).$(APIVERSION) -EXECUTABLES = upnpc-static upnpc-shared \ - testminixml minixmlvalid testupnpreplyparse \ - testigddescparse - -INSTALLPREFIX ?= $(PREFIX)/usr -INSTALLDIRINC = $(INSTALLPREFIX)/include/miniupnpc -INSTALLDIRLIB = $(INSTALLPREFIX)/lib -INSTALLDIRBIN = $(INSTALLPREFIX)/bin - -.PHONY: install clean depend all installpythonmodule - -all: validateminixml $(LIBRARY) $(EXECUTABLES) - -pythonmodule: $(LIBRARY) miniupnpcmodule.c setup.py - python setup.py build - touch $@ - -installpythonmodule: pythonmodule - python setup.py install - -validateminixml: minixmlvalid - @echo "minixml validation test" - ./minixmlvalid - touch $@ - -clean: - $(RM) $(LIBRARY) $(SHAREDLIBRARY) $(EXECUTABLES) $(OBJS) - # clean python stuff - $(RM) pythonmodule validateminixml - $(RM) -r build/ dist/ - #python setup.py clean - -install: $(LIBRARY) $(SHAREDLIBRARY) - $(INSTALL) -d $(INSTALLDIRINC) - $(INSTALL) -m 644 $(HEADERS) $(INSTALLDIRINC) - $(INSTALL) -d $(INSTALLDIRLIB) - $(INSTALL) -m 644 $(LIBRARY) $(INSTALLDIRLIB) - $(INSTALL) -m 644 $(SHAREDLIBRARY) $(INSTALLDIRLIB)/$(SONAME) - $(INSTALL) -d $(INSTALLDIRBIN) - $(INSTALL) -m 755 upnpc-shared $(INSTALLDIRBIN)/upnpc - ln -fs $(SONAME) $(INSTALLDIRLIB)/$(SHAREDLIBRARY) - -cleaninstall: - $(RM) -r $(INSTALLDIRINC) - $(RM) $(INSTALLDIRLIB)/$(LIBRARY) - $(RM) $(INSTALLDIRLIB)/$(SHAREDLIBRARY) - -depend: - makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null - -$(LIBRARY): $(LIBOBJS) - $(AR) crs $@ $? - -$(SHAREDLIBRARY): $(LIBOBJS) - $(CC) -shared -Wl,-soname,$(SONAME) -o $@ $^ - -upnpc-static: upnpc.o $(LIBRARY) - $(CC) -o $@ $^ - -upnpc-shared: upnpc.o $(SHAREDLIBRARY) - $(CC) -o $@ $^ - -testminixml: minixml.o igd_desc_parse.o testminixml.o - -minixmlvalid: minixml.o minixmlvalid.o - -testupnpreplyparse: testupnpreplyparse.o minixml.o upnpreplyparse.o - -testigddescparse: testigddescparse.o igd_desc_parse.o minixml.o - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -igd_desc_parse.o: igd_desc_parse.h -miniupnpc.o: miniupnpc.h declspec.h igd_desc_parse.h minissdpc.h miniwget.h -miniupnpc.o: minisoap.h minixml.h upnpcommands.h upnpreplyparse.h -minixml.o: minixml.h -minisoap.o: minisoap.h miniupnpcstrings.h -miniwget.o: miniupnpc.h declspec.h igd_desc_parse.h miniupnpcstrings.h -upnpc.o: miniwget.h declspec.h miniupnpc.h igd_desc_parse.h upnpcommands.h -upnpc.o: upnpreplyparse.h upnperrors.h -upnpcommands.o: upnpcommands.h upnpreplyparse.h declspec.h miniupnpc.h -upnpcommands.o: igd_desc_parse.h -upnpreplyparse.o: upnpreplyparse.h minixml.h -testminixml.o: minixml.h igd_desc_parse.h -minixmlvalid.o: minixml.h -testupnpreplyparse.o: upnpreplyparse.h -minissdpc.o: minissdpc.h miniupnpc.h declspec.h igd_desc_parse.h codelength.h -upnperrors.o: upnperrors.h declspec.h upnpcommands.h upnpreplyparse.h -testigddescparse.o: igd_desc_parse.h minixml.h diff --git a/libs/miniupnpc/Makefile.mingw b/libs/miniupnpc/Makefile.mingw deleted file mode 100644 index 2ca15dbc81..0000000000 --- a/libs/miniupnpc/Makefile.mingw +++ /dev/null @@ -1,74 +0,0 @@ -# $Id: Makefile.mingw,v 1.9 2008/07/02 23:31:15 nanard Exp $ -# Miniupnp project. -# http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ -# (c) 2005-2008 Thomas Bernard -CC = gcc -#CFLAGS = -Wall -g -DDEBUG -CFLAGS = -Wall -Os -DNDEBUG -LDLIBS = -lws2_32 -# -lwsock32 -PYTHON=\utils\python25\python -OBJS=miniwget.o minixml.o igd_desc_parse.o minisoap.o \ - miniupnpc.o upnpreplyparse.o upnpcommands.o upnperrors.o -OBJSDLL=$(addprefix dll/, $(OBJS)) - -all: init upnpc-static upnpc-shared testminixml libminiupnpc.a miniupnpc.dll - -init: - mkdir dll - echo "" > init - -clean: - del upnpc testminixml *.o - del dll/*.o - -libminiupnpc.a: $(OBJS) - $(AR) cr $@ $? - -pythonmodule: libminiupnpc.a - $(PYTHON) setupmingw32.py build --compiler=mingw32 - $(PYTHON) setupmingw32.py install --skip-build - -miniupnpc.dll: libminiupnpc.a $(OBJSDLL) - dllwrap -k --driver-name gcc --def miniupnpc.def \ - --output-def miniupnpc.dll.def --implib miniupnpc.lib -o $@ \ - $(OBJSDLL) $(LDLIBS) - -miniupnpc.lib: miniupnpc.dll - echo $@ generated with $< - -dll/upnpc.o: upnpc.o - echo $@ generated with $< - -.c.o: - $(CC) $(CFLAGS) -DSTATICLIB -c -o $@ $< - $(CC) $(CFLAGS) -DMINIUPNP_EXPORTS -c -o dll/$@ $< - -upnpc.o: - $(CC) $(CFLAGS) -DSTATICLIB -c -o $@ $< - $(CC) $(CFLAGS) -c -o dll/$@ $< - -upnpc-static: upnpc.o libminiupnpc.a - $(CC) -o $@ $^ $(LDLIBS) - -upnpc-shared: dll/upnpc.o miniupnpc.lib - $(CC) -o $@ $^ $(LDLIBS) - -minixml.o: minixml.c minixml.h - -upnpc.o: upnpc.c miniwget.h minisoap.h miniupnpc.h igd_desc_parse.h upnpreplyparse.h upnpcommands.h - -miniwget.o: miniwget.c miniwget.h - -minisoap.o: minisoap.c minisoap.h - -miniupnpc.o: miniupnpc.c miniupnpc.h minisoap.h miniwget.h minixml.h - -igd_desc_parse.o: igd_desc_parse.c igd_desc_parse.h - -testminixml: minixml.o igd_desc_parse.o testminixml.c - -upnpreplyparse.o: upnpreplyparse.c upnpreplyparse.h minixml.h - -upnpcommands.o: upnpcommands.c upnpcommands.h upnpreplyparse.h miniupnpc.h - diff --git a/libs/miniupnpc/README b/libs/miniupnpc/README deleted file mode 100644 index 3aa2a361b6..0000000000 --- a/libs/miniupnpc/README +++ /dev/null @@ -1,54 +0,0 @@ -Project: miniupnp -Project web page: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ -Author: Thomas Bernard -Copyright (c) 2005-2008 Thomas Bernard -This software is subject to the conditions detailed in the -LICENCE file provided within this distribution. - -For the comfort of Win32 users, bsdqueue.h is included in the distribution. -Its licence is included in the header of the file. -bsdqueue.h is a copy of the sys/queue.h of an OpenBSD system. - -* miniupnp Client * - -To compile, simply run 'gmake' (could be 'make'). -Under win32, to compile with MinGW, type "mingw32make.bat". -The compilation is known to work under linux, FreeBSD, -OpenBSD, MacOS X and cygwin. -To install the library and headers on the system use : -> su -> make install -> exit - -alternatively, to install in a specific location, use : -> INSTALLPREFIX=/usr/local make install - -upnpc.c is a sample client using the libminiupnpc. -To use the libminiupnpc in your application, link it with -libminiupnpc.a and use the following functions found in miniupnpc.h, -upnpcommands.h and miniwget.h : -- upnpDiscover() -- miniwget() -- parserootdesc() -- GetUPNPUrls() -- UPNP_* (calling UPNP methods) - -Note : use #include etc... for the includes -and -lminiupnpc for the link - -Discovery process is speeded up when MiniSSDPd is running on the machine. - -* Python module * - -you can build a python module with 'make pythonmodule' -and install it with 'make installpythonmodule'. -setup.py (and setupmingw32.py) are included in the distribution. - - -Feel free to contact me if you have any problem : -e-mail : miniupnp@free.fr - -If you are using libminiupnpc in your application, please -send me an email ! - - diff --git a/libs/miniupnpc/bsdqueue.h b/libs/miniupnpc/bsdqueue.h deleted file mode 100644 index 1fe0599f50..0000000000 --- a/libs/miniupnpc/bsdqueue.h +++ /dev/null @@ -1,531 +0,0 @@ -/* $OpenBSD: queue.h,v 1.31 2005/11/25 08:06:25 otto Exp $ */ -/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ - -/* - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)queue.h 8.5 (Berkeley) 8/20/94 - */ - -#ifndef _SYS_QUEUE_H_ -#define _SYS_QUEUE_H_ - -/* - * This file defines five types of data structures: singly-linked lists, - * lists, simple queues, tail queues, and circular queues. - * - * - * A singly-linked list is headed by a single forward pointer. The elements - * are singly linked for minimum space and pointer manipulation overhead at - * the expense of O(n) removal for arbitrary elements. New elements can be - * added to the list after an existing element or at the head of the list. - * Elements being removed from the head of the list should use the explicit - * macro for this purpose for optimum efficiency. A singly-linked list may - * only be traversed in the forward direction. Singly-linked lists are ideal - * for applications with large datasets and few or no removals or for - * implementing a LIFO queue. - * - * A list is headed by a single forward pointer (or an array of forward - * pointers for a hash table header). The elements are doubly linked - * so that an arbitrary element can be removed without a need to - * traverse the list. New elements can be added to the list before - * or after an existing element or at the head of the list. A list - * may only be traversed in the forward direction. - * - * A simple queue is headed by a pair of pointers, one the head of the - * list and the other to the tail of the list. The elements are singly - * linked to save space, so elements can only be removed from the - * head of the list. New elements can be added to the list before or after - * an existing element, at the head of the list, or at the end of the - * list. A simple queue may only be traversed in the forward direction. - * - * A tail queue is headed by a pair of pointers, one to the head of the - * list and the other to the tail of the list. The elements are doubly - * linked so that an arbitrary element can be removed without a need to - * traverse the list. New elements can be added to the list before or - * after an existing element, at the head of the list, or at the end of - * the list. A tail queue may be traversed in either direction. - * - * A circle queue is headed by a pair of pointers, one to the head of the - * list and the other to the tail of the list. The elements are doubly - * linked so that an arbitrary element can be removed without a need to - * traverse the list. New elements can be added to the list before or after - * an existing element, at the head of the list, or at the end of the list. - * A circle queue may be traversed in either direction, but has a more - * complex end of list detection. - * - * For details on the use of these macros, see the queue(3) manual page. - */ - -#ifdef QUEUE_MACRO_DEBUG -#define _Q_INVALIDATE(a) (a) = ((void *)-1) -#else -#define _Q_INVALIDATE(a) -#endif - -/* - * Singly-linked List definitions. - */ -#define SLIST_HEAD(name, type) \ -struct name { \ - struct type *slh_first; /* first element */ \ -} - -#define SLIST_HEAD_INITIALIZER(head) \ - { NULL } - -#ifdef SLIST_ENTRY -#undef SLIST_ENTRY -#endif - -#define SLIST_ENTRY(type) \ -struct { \ - struct type *sle_next; /* next element */ \ -} - -/* - * Singly-linked List access methods. - */ -#define SLIST_FIRST(head) ((head)->slh_first) -#define SLIST_END(head) NULL -#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head)) -#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) - -#define SLIST_FOREACH(var, head, field) \ - for((var) = SLIST_FIRST(head); \ - (var) != SLIST_END(head); \ - (var) = SLIST_NEXT(var, field)) - -#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ - for ((varp) = &SLIST_FIRST((head)); \ - ((var) = *(varp)) != SLIST_END(head); \ - (varp) = &SLIST_NEXT((var), field)) - -/* - * Singly-linked List functions. - */ -#define SLIST_INIT(head) { \ - SLIST_FIRST(head) = SLIST_END(head); \ -} - -#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ - (elm)->field.sle_next = (slistelm)->field.sle_next; \ - (slistelm)->field.sle_next = (elm); \ -} while (0) - -#define SLIST_INSERT_HEAD(head, elm, field) do { \ - (elm)->field.sle_next = (head)->slh_first; \ - (head)->slh_first = (elm); \ -} while (0) - -#define SLIST_REMOVE_NEXT(head, elm, field) do { \ - (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \ -} while (0) - -#define SLIST_REMOVE_HEAD(head, field) do { \ - (head)->slh_first = (head)->slh_first->field.sle_next; \ -} while (0) - -#define SLIST_REMOVE(head, elm, type, field) do { \ - if ((head)->slh_first == (elm)) { \ - SLIST_REMOVE_HEAD((head), field); \ - } else { \ - struct type *curelm = (head)->slh_first; \ - \ - while (curelm->field.sle_next != (elm)) \ - curelm = curelm->field.sle_next; \ - curelm->field.sle_next = \ - curelm->field.sle_next->field.sle_next; \ - _Q_INVALIDATE((elm)->field.sle_next); \ - } \ -} while (0) - -/* - * List definitions. - */ -#define LIST_HEAD(name, type) \ -struct name { \ - struct type *lh_first; /* first element */ \ -} - -#define LIST_HEAD_INITIALIZER(head) \ - { NULL } - -#define LIST_ENTRY(type) \ -struct { \ - struct type *le_next; /* next element */ \ - struct type **le_prev; /* address of previous next element */ \ -} - -/* - * List access methods - */ -#define LIST_FIRST(head) ((head)->lh_first) -#define LIST_END(head) NULL -#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head)) -#define LIST_NEXT(elm, field) ((elm)->field.le_next) - -#define LIST_FOREACH(var, head, field) \ - for((var) = LIST_FIRST(head); \ - (var)!= LIST_END(head); \ - (var) = LIST_NEXT(var, field)) - -/* - * List functions. - */ -#define LIST_INIT(head) do { \ - LIST_FIRST(head) = LIST_END(head); \ -} while (0) - -#define LIST_INSERT_AFTER(listelm, elm, field) do { \ - if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ - (listelm)->field.le_next->field.le_prev = \ - &(elm)->field.le_next; \ - (listelm)->field.le_next = (elm); \ - (elm)->field.le_prev = &(listelm)->field.le_next; \ -} while (0) - -#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ - (elm)->field.le_prev = (listelm)->field.le_prev; \ - (elm)->field.le_next = (listelm); \ - *(listelm)->field.le_prev = (elm); \ - (listelm)->field.le_prev = &(elm)->field.le_next; \ -} while (0) - -#define LIST_INSERT_HEAD(head, elm, field) do { \ - if (((elm)->field.le_next = (head)->lh_first) != NULL) \ - (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ - (head)->lh_first = (elm); \ - (elm)->field.le_prev = &(head)->lh_first; \ -} while (0) - -#define LIST_REMOVE(elm, field) do { \ - if ((elm)->field.le_next != NULL) \ - (elm)->field.le_next->field.le_prev = \ - (elm)->field.le_prev; \ - *(elm)->field.le_prev = (elm)->field.le_next; \ - _Q_INVALIDATE((elm)->field.le_prev); \ - _Q_INVALIDATE((elm)->field.le_next); \ -} while (0) - -#define LIST_REPLACE(elm, elm2, field) do { \ - if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \ - (elm2)->field.le_next->field.le_prev = \ - &(elm2)->field.le_next; \ - (elm2)->field.le_prev = (elm)->field.le_prev; \ - *(elm2)->field.le_prev = (elm2); \ - _Q_INVALIDATE((elm)->field.le_prev); \ - _Q_INVALIDATE((elm)->field.le_next); \ -} while (0) - -/* - * Simple queue definitions. - */ -#define SIMPLEQ_HEAD(name, type) \ -struct name { \ - struct type *sqh_first; /* first element */ \ - struct type **sqh_last; /* addr of last next element */ \ -} - -#define SIMPLEQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).sqh_first } - -#define SIMPLEQ_ENTRY(type) \ -struct { \ - struct type *sqe_next; /* next element */ \ -} - -/* - * Simple queue access methods. - */ -#define SIMPLEQ_FIRST(head) ((head)->sqh_first) -#define SIMPLEQ_END(head) NULL -#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head)) -#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) - -#define SIMPLEQ_FOREACH(var, head, field) \ - for((var) = SIMPLEQ_FIRST(head); \ - (var) != SIMPLEQ_END(head); \ - (var) = SIMPLEQ_NEXT(var, field)) - -/* - * Simple queue functions. - */ -#define SIMPLEQ_INIT(head) do { \ - (head)->sqh_first = NULL; \ - (head)->sqh_last = &(head)->sqh_first; \ -} while (0) - -#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \ - if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ - (head)->sqh_last = &(elm)->field.sqe_next; \ - (head)->sqh_first = (elm); \ -} while (0) - -#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \ - (elm)->field.sqe_next = NULL; \ - *(head)->sqh_last = (elm); \ - (head)->sqh_last = &(elm)->field.sqe_next; \ -} while (0) - -#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ - if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ - (head)->sqh_last = &(elm)->field.sqe_next; \ - (listelm)->field.sqe_next = (elm); \ -} while (0) - -#define SIMPLEQ_REMOVE_HEAD(head, field) do { \ - if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \ - (head)->sqh_last = &(head)->sqh_first; \ -} while (0) - -/* - * Tail queue definitions. - */ -#define TAILQ_HEAD(name, type) \ -struct name { \ - struct type *tqh_first; /* first element */ \ - struct type **tqh_last; /* addr of last next element */ \ -} - -#define TAILQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).tqh_first } - -#define TAILQ_ENTRY(type) \ -struct { \ - struct type *tqe_next; /* next element */ \ - struct type **tqe_prev; /* address of previous next element */ \ -} - -/* - * tail queue access methods - */ -#define TAILQ_FIRST(head) ((head)->tqh_first) -#define TAILQ_END(head) NULL -#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) -#define TAILQ_LAST(head, headname) \ - (*(((struct headname *)((head)->tqh_last))->tqh_last)) -/* XXX */ -#define TAILQ_PREV(elm, headname, field) \ - (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) -#define TAILQ_EMPTY(head) \ - (TAILQ_FIRST(head) == TAILQ_END(head)) - -#define TAILQ_FOREACH(var, head, field) \ - for((var) = TAILQ_FIRST(head); \ - (var) != TAILQ_END(head); \ - (var) = TAILQ_NEXT(var, field)) - -#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ - for((var) = TAILQ_LAST(head, headname); \ - (var) != TAILQ_END(head); \ - (var) = TAILQ_PREV(var, headname, field)) - -/* - * Tail queue functions. - */ -#define TAILQ_INIT(head) do { \ - (head)->tqh_first = NULL; \ - (head)->tqh_last = &(head)->tqh_first; \ -} while (0) - -#define TAILQ_INSERT_HEAD(head, elm, field) do { \ - if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ - (head)->tqh_first->field.tqe_prev = \ - &(elm)->field.tqe_next; \ - else \ - (head)->tqh_last = &(elm)->field.tqe_next; \ - (head)->tqh_first = (elm); \ - (elm)->field.tqe_prev = &(head)->tqh_first; \ -} while (0) - -#define TAILQ_INSERT_TAIL(head, elm, field) do { \ - (elm)->field.tqe_next = NULL; \ - (elm)->field.tqe_prev = (head)->tqh_last; \ - *(head)->tqh_last = (elm); \ - (head)->tqh_last = &(elm)->field.tqe_next; \ -} while (0) - -#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ - if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ - (elm)->field.tqe_next->field.tqe_prev = \ - &(elm)->field.tqe_next; \ - else \ - (head)->tqh_last = &(elm)->field.tqe_next; \ - (listelm)->field.tqe_next = (elm); \ - (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ -} while (0) - -#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ - (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ - (elm)->field.tqe_next = (listelm); \ - *(listelm)->field.tqe_prev = (elm); \ - (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ -} while (0) - -#define TAILQ_REMOVE(head, elm, field) do { \ - if (((elm)->field.tqe_next) != NULL) \ - (elm)->field.tqe_next->field.tqe_prev = \ - (elm)->field.tqe_prev; \ - else \ - (head)->tqh_last = (elm)->field.tqe_prev; \ - *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ - _Q_INVALIDATE((elm)->field.tqe_prev); \ - _Q_INVALIDATE((elm)->field.tqe_next); \ -} while (0) - -#define TAILQ_REPLACE(head, elm, elm2, field) do { \ - if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ - (elm2)->field.tqe_next->field.tqe_prev = \ - &(elm2)->field.tqe_next; \ - else \ - (head)->tqh_last = &(elm2)->field.tqe_next; \ - (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ - *(elm2)->field.tqe_prev = (elm2); \ - _Q_INVALIDATE((elm)->field.tqe_prev); \ - _Q_INVALIDATE((elm)->field.tqe_next); \ -} while (0) - -/* - * Circular queue definitions. - */ -#define CIRCLEQ_HEAD(name, type) \ -struct name { \ - struct type *cqh_first; /* first element */ \ - struct type *cqh_last; /* last element */ \ -} - -#define CIRCLEQ_HEAD_INITIALIZER(head) \ - { CIRCLEQ_END(&head), CIRCLEQ_END(&head) } - -#define CIRCLEQ_ENTRY(type) \ -struct { \ - struct type *cqe_next; /* next element */ \ - struct type *cqe_prev; /* previous element */ \ -} - -/* - * Circular queue access methods - */ -#define CIRCLEQ_FIRST(head) ((head)->cqh_first) -#define CIRCLEQ_LAST(head) ((head)->cqh_last) -#define CIRCLEQ_END(head) ((void *)(head)) -#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next) -#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev) -#define CIRCLEQ_EMPTY(head) \ - (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head)) - -#define CIRCLEQ_FOREACH(var, head, field) \ - for((var) = CIRCLEQ_FIRST(head); \ - (var) != CIRCLEQ_END(head); \ - (var) = CIRCLEQ_NEXT(var, field)) - -#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ - for((var) = CIRCLEQ_LAST(head); \ - (var) != CIRCLEQ_END(head); \ - (var) = CIRCLEQ_PREV(var, field)) - -/* - * Circular queue functions. - */ -#define CIRCLEQ_INIT(head) do { \ - (head)->cqh_first = CIRCLEQ_END(head); \ - (head)->cqh_last = CIRCLEQ_END(head); \ -} while (0) - -#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ - (elm)->field.cqe_next = (listelm)->field.cqe_next; \ - (elm)->field.cqe_prev = (listelm); \ - if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \ - (head)->cqh_last = (elm); \ - else \ - (listelm)->field.cqe_next->field.cqe_prev = (elm); \ - (listelm)->field.cqe_next = (elm); \ -} while (0) - -#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \ - (elm)->field.cqe_next = (listelm); \ - (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \ - if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \ - (head)->cqh_first = (elm); \ - else \ - (listelm)->field.cqe_prev->field.cqe_next = (elm); \ - (listelm)->field.cqe_prev = (elm); \ -} while (0) - -#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \ - (elm)->field.cqe_next = (head)->cqh_first; \ - (elm)->field.cqe_prev = CIRCLEQ_END(head); \ - if ((head)->cqh_last == CIRCLEQ_END(head)) \ - (head)->cqh_last = (elm); \ - else \ - (head)->cqh_first->field.cqe_prev = (elm); \ - (head)->cqh_first = (elm); \ -} while (0) - -#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \ - (elm)->field.cqe_next = CIRCLEQ_END(head); \ - (elm)->field.cqe_prev = (head)->cqh_last; \ - if ((head)->cqh_first == CIRCLEQ_END(head)) \ - (head)->cqh_first = (elm); \ - else \ - (head)->cqh_last->field.cqe_next = (elm); \ - (head)->cqh_last = (elm); \ -} while (0) - -#define CIRCLEQ_REMOVE(head, elm, field) do { \ - if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \ - (head)->cqh_last = (elm)->field.cqe_prev; \ - else \ - (elm)->field.cqe_next->field.cqe_prev = \ - (elm)->field.cqe_prev; \ - if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \ - (head)->cqh_first = (elm)->field.cqe_next; \ - else \ - (elm)->field.cqe_prev->field.cqe_next = \ - (elm)->field.cqe_next; \ - _Q_INVALIDATE((elm)->field.cqe_prev); \ - _Q_INVALIDATE((elm)->field.cqe_next); \ -} while (0) - -#define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \ - if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \ - CIRCLEQ_END(head)) \ - (head).cqh_last = (elm2); \ - else \ - (elm2)->field.cqe_next->field.cqe_prev = (elm2); \ - if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \ - CIRCLEQ_END(head)) \ - (head).cqh_first = (elm2); \ - else \ - (elm2)->field.cqe_prev->field.cqe_next = (elm2); \ - _Q_INVALIDATE((elm)->field.cqe_prev); \ - _Q_INVALIDATE((elm)->field.cqe_next); \ -} while (0) - -#endif /* !_SYS_QUEUE_H_ */ diff --git a/libs/miniupnpc/codelength.h b/libs/miniupnpc/codelength.h deleted file mode 100644 index 7280c8cb79..0000000000 --- a/libs/miniupnpc/codelength.h +++ /dev/null @@ -1,24 +0,0 @@ -/* $Id: codelength.h,v 1.1 2008/10/06 22:04:06 nanard Exp $ */ -/* Project : miniupnp - * Author : Thomas BERNARD - * copyright (c) 2005-2008 Thomas Bernard - * This software is subjet to the conditions detailed in the - * provided LICENCE file. */ -#ifndef __CODELENGTH_H__ -#define __CODELENGTH_H__ - -/* Encode length by using 7bit per Byte : - * Most significant bit of each byte specifies that the - * following byte is part of the code */ -#define DECODELENGTH(n, p) n = 0; \ - do { n = (n << 7) | (*p & 0x7f); } \ - while(*(p++)&0x80); - -#define CODELENGTH(n, p) if(n>=268435456) *(p++) = (unsigned char)((n >> 28) | 0x80); \ - if(n>=2097152) *(p++) = (unsigned char)((n >> 21) | 0x80); \ - if(n>=16384) *(p++) = (unsigned char)((n >> 14) | 0x80); \ - if(n>=128) *(p++) = (unsigned char)((n >> 7) | 0x80); \ - *(p++) = (unsigned char)(n & 0x7f); - -#endif - diff --git a/libs/miniupnpc/declspec.h b/libs/miniupnpc/declspec.h deleted file mode 100644 index b804247d25..0000000000 --- a/libs/miniupnpc/declspec.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __DECLSPEC_H__ -#define __DECLSPEC_H__ - -#if defined(WIN32) && !defined(STATICLIB) - #ifdef MINIUPNP_EXPORTS - #define LIBSPEC __declspec(dllexport) - #else - #define LIBSPEC __declspec(dllimport) - #endif -#else - #define LIBSPEC -#endif - -#endif - diff --git a/libs/miniupnpc/igd_desc_parse.c b/libs/miniupnpc/igd_desc_parse.c deleted file mode 100644 index e839ff4c13..0000000000 --- a/libs/miniupnpc/igd_desc_parse.c +++ /dev/null @@ -1,113 +0,0 @@ -/* $Id: igd_desc_parse.c,v 1.8 2008/04/23 11:51:06 nanard Exp $ */ -/* Project : miniupnp - * http://miniupnp.free.fr/ - * Author : Thomas Bernard - * Copyright (c) 2005-2008 Thomas Bernard - * This software is subject to the conditions detailed in the - * LICENCE file provided in this distribution. - * */ -#include "igd_desc_parse.h" -#include -#include - -/* TODO : rewrite this code so it correctly handle descriptions with - * both WANIPConnection and/or WANPPPConnection */ - -/* Start element handler : - * update nesting level counter and copy element name */ -void IGDstartelt(void * d, const char * name, int l) -{ - struct IGDdatas * datas = (struct IGDdatas *)d; - memcpy( datas->cureltname, name, l); - datas->cureltname[l] = '\0'; - datas->level++; - if( (l==7) && !memcmp(name, "service", l) ) { - datas->controlurl_tmp[0] = '\0'; - datas->eventsuburl_tmp[0] = '\0'; - datas->scpdurl_tmp[0] = '\0'; - datas->servicetype_tmp[0] = '\0'; - } -} - -/* End element handler : - * update nesting level counter and update parser state if - * service element is parsed */ -void IGDendelt(void * d, const char * name, int l) -{ - struct IGDdatas * datas = (struct IGDdatas *)d; - datas->level--; - /*printf("endelt %2d %.*s\n", datas->level, l, name);*/ - if( (l==7) && !memcmp(name, "service", l) ) - { - /* - if( datas->state < 1 - && !strcmp(datas->servicetype, - // "urn:schemas-upnp-org:service:WANIPConnection:1") ) - "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) - datas->state ++; - */ - if(0==strcmp(datas->servicetype_tmp, - "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) { - memcpy(datas->controlurl_CIF, datas->controlurl_tmp, MINIUPNPC_URL_MAXSIZE); - memcpy(datas->eventsuburl_CIF, datas->eventsuburl_tmp, MINIUPNPC_URL_MAXSIZE); - memcpy(datas->scpdurl_CIF, datas->scpdurl_tmp, MINIUPNPC_URL_MAXSIZE); - memcpy(datas->servicetype_CIF, datas->servicetype_tmp, MINIUPNPC_URL_MAXSIZE); - } else if(0==strcmp(datas->servicetype_tmp, - "urn:schemas-upnp-org:service:WANIPConnection:1") - || 0==strcmp(datas->servicetype_tmp, - "urn:schemas-upnp-org:service:WANPPPConnection:1") ) { - memcpy(datas->controlurl, datas->controlurl_tmp, MINIUPNPC_URL_MAXSIZE); - memcpy(datas->eventsuburl, datas->eventsuburl_tmp, MINIUPNPC_URL_MAXSIZE); - memcpy(datas->scpdurl, datas->scpdurl_tmp, MINIUPNPC_URL_MAXSIZE); - memcpy(datas->servicetype, datas->servicetype_tmp, MINIUPNPC_URL_MAXSIZE); - } - } -} - -/* Data handler : - * copy data depending on the current element name and state */ -void IGDdata(void * d, const char * data, int l) -{ - struct IGDdatas * datas = (struct IGDdatas *)d; - char * dstmember = 0; - /*printf("%2d %s : %.*s\n", - datas->level, datas->cureltname, l, data); */ - if( !strcmp(datas->cureltname, "URLBase") ) - dstmember = datas->urlbase; - else if( !strcmp(datas->cureltname, "serviceType") ) - dstmember = datas->servicetype_tmp; - else if( !strcmp(datas->cureltname, "controlURL") ) - dstmember = datas->controlurl_tmp; - else if( !strcmp(datas->cureltname, "eventSubURL") ) - dstmember = datas->eventsuburl_tmp; - else if( !strcmp(datas->cureltname, "SCPDURL") ) - dstmember = datas->scpdurl_tmp; -/* else if( !strcmp(datas->cureltname, "deviceType") ) - dstmember = datas->devicetype_tmp;*/ - if(dstmember) - { - if(l>=MINIUPNPC_URL_MAXSIZE) - l = MINIUPNPC_URL_MAXSIZE-1; - memcpy(dstmember, data, l); - dstmember[l] = '\0'; - } -} - -void printIGD(struct IGDdatas * d) -{ - printf("urlbase = %s\n", d->urlbase); - printf("WAN Device (Common interface config) :\n"); - /*printf(" deviceType = %s\n", d->devicetype_CIF);*/ - printf(" serviceType = %s\n", d->servicetype_CIF); - printf(" controlURL = %s\n", d->controlurl_CIF); - printf(" eventSubURL = %s\n", d->eventsuburl_CIF); - printf(" SCPDURL = %s\n", d->scpdurl_CIF); - printf("WAN Connection Device (IP or PPP Connection):\n"); - /*printf(" deviceType = %s\n", d->devicetype);*/ - printf(" servicetype = %s\n", d->servicetype); - printf(" controlURL = %s\n", d->controlurl); - printf(" eventSubURL = %s\n", d->eventsuburl); - printf(" SCPDURL = %s\n", d->scpdurl); -} - - diff --git a/libs/miniupnpc/igd_desc_parse.h b/libs/miniupnpc/igd_desc_parse.h deleted file mode 100644 index aabcb087d5..0000000000 --- a/libs/miniupnpc/igd_desc_parse.h +++ /dev/null @@ -1,47 +0,0 @@ -/* $Id: igd_desc_parse.h,v 1.6 2008/04/23 11:51:07 nanard Exp $ */ -/* Project : miniupnp - * http://miniupnp.free.fr/ - * Author : Thomas Bernard - * Copyright (c) 2005-2008 Thomas Bernard - * This software is subject to the conditions detailed in the - * LICENCE file provided in this distribution. - * */ -#ifndef __IGD_DESC_PARSE_H__ -#define __IGD_DESC_PARSE_H__ - -/* Structure to store the result of the parsing of UPnP - * descriptions of Internet Gateway Devices */ -#define MINIUPNPC_URL_MAXSIZE (128) -struct IGDdatas { - char cureltname[MINIUPNPC_URL_MAXSIZE]; - char urlbase[MINIUPNPC_URL_MAXSIZE]; - int level; - /*int state;*/ - /* "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" */ - char controlurl_CIF[MINIUPNPC_URL_MAXSIZE]; - char eventsuburl_CIF[MINIUPNPC_URL_MAXSIZE]; - char scpdurl_CIF[MINIUPNPC_URL_MAXSIZE]; - char servicetype_CIF[MINIUPNPC_URL_MAXSIZE]; - /*char devicetype_CIF[MINIUPNPC_URL_MAXSIZE];*/ - /* "urn:schemas-upnp-org:service:WANIPConnection:1" - * "urn:schemas-upnp-org:service:WANPPPConnection:1" */ - char controlurl[MINIUPNPC_URL_MAXSIZE]; - char eventsuburl[MINIUPNPC_URL_MAXSIZE]; - char scpdurl[MINIUPNPC_URL_MAXSIZE]; - char servicetype[MINIUPNPC_URL_MAXSIZE]; - /*char devicetype[MINIUPNPC_URL_MAXSIZE];*/ - /* tmp */ - char controlurl_tmp[MINIUPNPC_URL_MAXSIZE]; - char eventsuburl_tmp[MINIUPNPC_URL_MAXSIZE]; - char scpdurl_tmp[MINIUPNPC_URL_MAXSIZE]; - char servicetype_tmp[MINIUPNPC_URL_MAXSIZE]; - /*char devicetype_tmp[MINIUPNPC_URL_MAXSIZE];*/ -}; - -void IGDstartelt(void *, const char *, int); -void IGDendelt(void *, const char *, int); -void IGDdata(void *, const char *, int); -void printIGD(struct IGDdatas *); - -#endif - diff --git a/libs/miniupnpc/man3/miniupnpc.3 b/libs/miniupnpc/man3/miniupnpc.3 deleted file mode 100644 index 9d0e23e881..0000000000 --- a/libs/miniupnpc/man3/miniupnpc.3 +++ /dev/null @@ -1,52 +0,0 @@ -\" $Id: miniupnpc.3,v 1.2 2008/10/07 13:51:55 nanard Exp $ -.TH miniupnpc 3 -.SH NAME -miniupnpc \- UPnP client library -.SH SYNOPSIS -.SH DESCRIPTION -The miniupnpc library implement the UPnP protocol defined -to dialog with Internet Gateway Devices. It also has -the ability to use data gathered by minissdpd(1) about -UPnP devices up on the network in order to skip the -long UPnP device discovery process. -.PP -At first, upnpDiscover(3) has to be used to discover UPnP IGD present -on the network. Then UPNP_GetValidIGD(3) to select the right one. -Alternatively, UPNP_GetIGDFromUrl(3) could be used to bypass discovery -process if the root description url of the device to use is known. -Then all the UPNP_* functions can be used, such as -UPNP_GetConnectionTypeInfo(3), UPNP_AddPortMapping(3), etc... -.SH "HEADER FILES" -.IP miniupnpc.h -That's the main header file for the miniupnpc library API. -It contains all the functions and structures related to device discovery. -.IP upnpcommands.h -This header file contain the UPnP IGD methods that are accessible -through the miniupnpc API. The name of the C functions are matching -the UPnP methods names. ie: GetGenericPortMappingEntry is -UPNP_GetGenericPortMappingEntry. -.SH "API FUNCTIONS" -.IP "struct UPNPDev * upnpDiscover(int delay, const char * multicastif, const char * minissdpdsock, int sameport);" -execute the discovery process. -delay (in millisecond) is the maximum time for waiting any device response. -If available, device list will be obtained from MiniSSDPd. -Default path for minissdpd socket will be used if minissdpdsock argument is NULL. -If multicastif is not NULL, it will be used instead of the default multicast interface for sending SSDP discover packets. -If sameport is not null, SSDP packets will be sent from the source port 1900 (same as destination port) otherwise system assign a source port. -.IP "void freeUPNPDevlist(struct UPNPDev * devlist);" -free the list returned by upnpDiscover(). -.IP "int UPNP_GetValidIGD(struct UPNPDev * devlist, struct UPNPUrls * urls, struct IGDdatas * data, char * lanaddr, int lanaddrlen);" -browse the list of device returned by upnpDiscover(), find -a live UPnP internet gateway device and fill structures passed as arguments -with data used for UPNP methods invokation. -.IP "int UPNP_GetIGDFromUrl(const char * rootdescurl, struct UPNPUrls * urls, struct IGDdatas * data, char * lanaddr, int lanaddrlen);" -permit to bypass the upnpDiscover() call if the xml root description -URL of the UPnP IGD is known. -Fill structures passed as arguments -with data used for UPNP methods invokation. -.IP "void GetUPNPUrls(struct UPNPUrls *, struct IGDdatas *, const char *);" -.IP "void FreeUPNPUrls(struct UPNPUrls *);" - -.SH "SEE ALSO" -minissdpd(1) -.SH BUGS diff --git a/libs/miniupnpc/mingw32make.bat b/libs/miniupnpc/mingw32make.bat deleted file mode 100644 index 3e59be59b3..0000000000 --- a/libs/miniupnpc/mingw32make.bat +++ /dev/null @@ -1,7 +0,0 @@ -@mingw32-make -f Makefile.mingw %1 -@if errorlevel 1 goto end -@strip upnpc-static.exe -@upx --best upnpc-static.exe -@strip upnpc-shared.exe -@upx --best upnpc-shared.exe -:end diff --git a/libs/miniupnpc/minisoap.c b/libs/miniupnpc/minisoap.c deleted file mode 100644 index 36bdc77a87..0000000000 --- a/libs/miniupnpc/minisoap.c +++ /dev/null @@ -1,115 +0,0 @@ -/* $Id: minisoap.c,v 1.16 2008/10/11 16:39:29 nanard Exp $ */ -/* Project : miniupnp - * Author : Thomas Bernard - * Copyright (c) 2005 Thomas Bernard - * This software is subject to the conditions detailed in the - * LICENCE file provided in this distribution. - * - * Minimal SOAP implementation for UPnP protocol. - */ -#include -#include -#ifdef WIN32 -#include -#include -#if _MSC_VER < 1900 -#define snprintf _snprintf -#endif -#else -#include -#include -#include -#endif -#include "minisoap.h" -#include "miniupnpcstrings.h" - -/* only for malloc */ -#include - -#ifdef WIN32 -#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError()); -#else -#define PRINT_SOCKET_ERROR(x) perror(x) -#endif - -/* httpWrite sends the headers and the body to the socket - * and returns the number of bytes sent */ -static int -httpWrite(int fd, const char * body, int bodysize, - const char * headers, int headerssize) -{ - int n = 0; - /*n = write(fd, headers, headerssize);*/ - /*if(bodysize>0) - n += write(fd, body, bodysize);*/ - /* Note : my old linksys router only took into account - * soap request that are sent into only one packet */ - char * p; - /* TODO: AVOID MALLOC */ - p = malloc(headerssize+bodysize); - if(!p) - return 0; - memcpy(p, headers, headerssize); - memcpy(p+headerssize, body, bodysize); - /*n = write(fd, p, headerssize+bodysize);*/ - n = send(fd, p, headerssize+bodysize, 0); - if(n<0) { - PRINT_SOCKET_ERROR("send"); - } - /* disable send on the socket */ - /* draytek routers dont seems to like that... */ -#if 0 -#ifdef WIN32 - if(shutdown(fd, SD_SEND)<0) { -#else - if(shutdown(fd, SHUT_WR)<0) { /*SD_SEND*/ -#endif - PRINT_SOCKET_ERROR("shutdown"); - } -#endif - free(p); - return n; -} - -/* self explanatory */ -int soapPostSubmit(int fd, - const char * url, - const char * host, - unsigned short port, - const char * action, - const char * body) -{ - int bodysize; - char headerbuf[512]; - int headerssize; - char portstr[8]; - bodysize = (int)strlen(body); - /* We are not using keep-alive HTTP connections. - * HTTP/1.1 needs the header Connection: close to do that. - * This is the default with HTTP/1.0 */ - /* Connection: Close is normally there only in HTTP/1.1 but who knows */ - portstr[0] = '\0'; - if(port != 80) - snprintf(portstr, sizeof(portstr), ":%hu", port); - headerssize = snprintf(headerbuf, sizeof(headerbuf), - "POST %s HTTP/1.1\r\n" -/* "POST %s HTTP/1.0\r\n"*/ - "Host: %s%s\r\n" - "User-Agent: " OS_STRING ", UPnP/1.0, MiniUPnPc/" MINIUPNPC_VERSION_STRING "\r\n" - "Content-Length: %d\r\n" - "Content-Type: text/xml\r\n" - "SOAPAction: \"%s\"\r\n" - "Connection: Close\r\n" - "Cache-Control: no-cache\r\n" /* ??? */ - "Pragma: no-cache\r\n" - "\r\n", - url, host, portstr, bodysize, action); -#ifdef DEBUG - printf("SOAP request : headersize=%d bodysize=%d\n", - headerssize, bodysize); - /*printf("%s", headerbuf);*/ -#endif - return httpWrite(fd, body, bodysize, headerbuf, headerssize); -} - - diff --git a/libs/miniupnpc/minisoap.h b/libs/miniupnpc/minisoap.h deleted file mode 100644 index 9fa297fd33..0000000000 --- a/libs/miniupnpc/minisoap.h +++ /dev/null @@ -1,15 +0,0 @@ -/* $Id: minisoap.h,v 1.3 2006/11/19 22:32:34 nanard Exp $ */ -/* Project : miniupnp - * Author : Thomas Bernard - * Copyright (c) 2005 Thomas Bernard - * This software is subject to the conditions detailed in the - * LICENCE file provided in this distribution. */ -#ifndef __MINISOAP_H__ -#define __MINISOAP_H__ - -/*int httpWrite(int, const char *, int, const char *);*/ -int soapPostSubmit(int, const char *, const char *, unsigned short, - const char *, const char *); - -#endif - diff --git a/libs/miniupnpc/minissdpc.c b/libs/miniupnpc/minissdpc.c deleted file mode 100644 index 96133ff12f..0000000000 --- a/libs/miniupnpc/minissdpc.c +++ /dev/null @@ -1,127 +0,0 @@ -/* $Id: minissdpc.c,v 1.7 2008/12/18 17:45:48 nanard Exp $ */ -/* Project : miniupnp - * Author : Thomas BERNARD - * copyright (c) 2005-2008 Thomas Bernard - * This software is subjet to the conditions detailed in the - * provided LICENCE file. */ -/*#include */ -#include -#include -#include -#ifdef _MSC_VER -#include -typedef intptr_t ssize_t; -#define read _read -#define write _write -#define close _close -#else -#include -#endif -#include -#ifdef WIN32 -#include -#include -#include -#else -#include -#include -#endif - -#include "minissdpc.h" -#include "miniupnpc.h" - -#include "codelength.h" - -struct UPNPDev * -getDevicesFromMiniSSDPD(const char * devtype, const char * socketpath) -{ -#ifdef _MSC_VER - /* sockaddr_un not supported on msvc*/ - return NULL; -#else - struct UPNPDev * tmp; - struct UPNPDev * devlist = NULL; - unsigned char buffer[2048]; - ssize_t n; - unsigned char * p; - unsigned char * url; - unsigned int i; - unsigned int urlsize, stsize, usnsize, l, plen; - int s; - struct sockaddr_un addr; - - s = socket(AF_UNIX, SOCK_STREAM, 0); - if(s < 0) - { - /*syslog(LOG_ERR, "socket(unix): %m");*/ - perror("socket(unix)"); - return NULL; - } - addr.sun_family = AF_UNIX; - plen = strlen(socketpath); - if (plen + 1 > sizeof(addr.sun_path)) { - plen = sizeof(addr.sun_path) - 1; - } - memset(addr.sun_path, 0, sizeof(addr.sun_path)); - memcpy(addr.sun_path, socketpath, plen); - if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) - { - /*syslog(LOG_WARNING, "connect(\"%s\"): %m", socketpath);*/ - close(s); - return NULL; - } - stsize = strlen(devtype); - buffer[0] = 1; /* request type 1 : request devices/services by type */ - p = buffer + 1; - l = stsize; CODELENGTH(l, p); - memcpy(p, devtype, stsize); - p += stsize; - if(write(s, buffer, p - buffer) < 0) - { - /*syslog(LOG_ERR, "write(): %m");*/ - perror("minissdpc.c: write()"); - close(s); - return NULL; - } - n = read(s, buffer, sizeof(buffer)); - if(n<=0) - { - perror("minissdpc.c: read()"); - close(s); - return NULL; - } - p = buffer + 1; - for(i = 0; i < buffer[0]; i++) - { - if(p+2>=buffer+sizeof(buffer)) - break; - DECODELENGTH(urlsize, p); - if(p+urlsize+2>=buffer+sizeof(buffer)) - break; - url = p; - p += urlsize; - DECODELENGTH(stsize, p); - if(p+stsize+2>=buffer+sizeof(buffer)) - break; - tmp = (struct UPNPDev *)malloc(sizeof(struct UPNPDev)+urlsize+stsize); - tmp->pNext = devlist; - tmp->descURL = tmp->buffer; - tmp->st = tmp->buffer + 1 + urlsize; - memcpy(tmp->buffer, url, urlsize); - tmp->buffer[urlsize] = '\0'; - memcpy(tmp->buffer + urlsize + 1, p, stsize); - p += stsize; - tmp->buffer[urlsize+1+stsize] = '\0'; - devlist = tmp; - /* added for compatibility with recent versions of MiniSSDPd - * >= 2007/12/19 */ - DECODELENGTH(usnsize, p); - p += usnsize; - if(p>buffer + sizeof(buffer)) - break; - } - close(s); - return devlist; -#endif -} - diff --git a/libs/miniupnpc/minissdpc.h b/libs/miniupnpc/minissdpc.h deleted file mode 100644 index 25e91ce319..0000000000 --- a/libs/miniupnpc/minissdpc.h +++ /dev/null @@ -1,15 +0,0 @@ -/* $Id: minissdpc.h,v 1.1 2007/08/31 15:15:33 nanard Exp $ */ -/* Project: miniupnp - * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * Author: Thomas Bernard - * Copyright (c) 2005-2007 Thomas Bernard - * This software is subjects to the conditions detailed - * in the LICENCE file provided within this distribution */ -#ifndef __MINISSDPC_H__ -#define __MINISSDPC_H__ - -struct UPNPDev * -getDevicesFromMiniSSDPD(const char * devtype, const char * socketpath); - -#endif - diff --git a/libs/miniupnpc/miniupnpc.c b/libs/miniupnpc/miniupnpc.c deleted file mode 100644 index a72ef892b6..0000000000 --- a/libs/miniupnpc/miniupnpc.c +++ /dev/null @@ -1,760 +0,0 @@ -/* $Id: miniupnpc.c,v 1.57 2008/12/18 17:46:36 nanard Exp $ */ -/* Project : miniupnp - * Author : Thomas BERNARD - * copyright (c) 2005-2007 Thomas Bernard - * This software is subjet to the conditions detailed in the - * provided LICENCE file. */ -#define __EXTENSIONS__ 1 - -#ifndef MACOSX -#if !defined(_XOPEN_SOURCE) && !defined(__OpenBSD__) && !defined(__NetBSD__) -#ifndef __cplusplus -#define _XOPEN_SOURCE 600 -#endif -#endif -#ifndef __BSD_VISIBLE -#define __BSD_VISIBLE 1 -#endif -#endif -#include -#include -#include -#ifdef WIN32 -/* Win32 Specific includes and defines */ -#include -#include -#include -#if _MSC_VER < 1900 -#define snprintf _snprintf -#endif -#if defined(_MSC_VER) && (_MSC_VER >= 1400) -#define strncasecmp _memicmp -#else -#define strncasecmp memicmp -#endif -#define MAXHOSTNAMELEN 64 -#else -/* Standard POSIX includes */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define closesocket close -#endif -#include "miniupnpc.h" -#include "minissdpc.h" -#include "miniwget.h" -#include "minisoap.h" -#include "minixml.h" -#include "upnpcommands.h" - -#ifdef WIN32 -#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError()); -#else -#define PRINT_SOCKET_ERROR(x) perror(x) -#endif - -#define SOAPPREFIX "s" -#define SERVICEPREFIX "u" -#define SERVICEPREFIX2 'u' - -/* root description parsing */ -void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data) -{ - struct xmlparser parser; - /* xmlparser object */ - parser.xmlstart = buffer; - parser.xmlsize = bufsize; - parser.data = data; - parser.starteltfunc = IGDstartelt; - parser.endeltfunc = IGDendelt; - parser.datafunc = IGDdata; - parser.attfunc = 0; - parsexml(&parser); -#ifdef DEBUG - printIGD(data); -#endif -} - -/* Content-length: nnn */ -static int getcontentlenfromline(const char * p, int n) -{ - static const char contlenstr[] = "content-length"; - const char * p2 = contlenstr; - int a = 0; - while(*p2) - { - if(n==0) - return -1; - if(*p2 != *p && *p2 != (*p + 32)) - return -1; - p++; p2++; n--; - } - if(n==0) - return -1; - if(*p != ':') - return -1; - p++; n--; - while(*p == ' ') - { - if(n==0) - return -1; - p++; n--; - } - while(*p >= '0' && *p <= '9') - { - if(n==0) - return -1; - a = (a * 10) + (*p - '0'); - p++; n--; - } - return a; -} - -static void -getContentLengthAndHeaderLength(char * p, int n, - int * contentlen, int * headerlen) -{ - char * line; - int linelen; - int r; - line = p; - while(line < p + n) - { - linelen = 0; - while(line[linelen] != '\r' && line[linelen] != '\r') - { - if(line+linelen >= p+n) - return; - linelen++; - } - r = getcontentlenfromline(line, linelen); - if(r>0) - *contentlen = r; - line = line + linelen + 2; - if(line[0] == '\r' && line[1] == '\n') - { - *headerlen = (line - p) + 2; - return; - } - } -} - -/* simpleUPnPcommand : - * not so simple ! - * return values : - * 0 - OK - * -1 - error */ -int simpleUPnPcommand(int s, const char * url, const char * service, - const char * action, struct UPNParg * args, - char * buffer, int * bufsize) -{ - struct sockaddr_in dest; - char hostname[MAXHOSTNAMELEN+1]; - unsigned short port = 0; - char * path; - char soapact[128]; - char soapbody[2048]; - char * buf; - int buffree; - int n; - int contentlen, headerlen; /* for the response */ - snprintf(soapact, sizeof(soapact), "%s#%s", service, action); - if(args==NULL) - { - /*soapbodylen = */snprintf(soapbody, sizeof(soapbody), - "\r\n" - "<" SOAPPREFIX ":Envelope " - "xmlns:" SOAPPREFIX "=\"http://schemas.xmlsoap.org/soap/envelope/\" " - SOAPPREFIX ":encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" - "<" SOAPPREFIX ":Body>" - "<" SERVICEPREFIX ":%s xmlns:" SERVICEPREFIX "=\"%s\">" - "" - "" - "\r\n", action, service, action); - } - else - { - char * p; - const char * pe, * pv; - int soapbodylen; - soapbodylen = snprintf(soapbody, sizeof(soapbody), - "\r\n" - "<" SOAPPREFIX ":Envelope " - "xmlns:" SOAPPREFIX "=\"http://schemas.xmlsoap.org/soap/envelope/\" " - SOAPPREFIX ":encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" - "<" SOAPPREFIX ":Body>" - "<" SERVICEPREFIX ":%s xmlns:" SERVICEPREFIX "=\"%s\">", - action, service); - p = soapbody + soapbodylen; - while(args->elt) - { - /* check that we are never overflowing the string... */ - if(soapbody + sizeof(soapbody) <= p + 100) - { - /* we keep a margin of at least 100 bytes */ - *bufsize = 0; - return -1; - } - *(p++) = '<'; - pe = args->elt; - while(*pe) - *(p++) = *(pe++); - *(p++) = '>'; - if((pv = args->val)) - { - while(*pv) - *(p++) = *(pv++); - } - *(p++) = '<'; - *(p++) = '/'; - pe = args->elt; - while(*pe) - *(p++) = *(pe++); - *(p++) = '>'; - args++; - } - *(p++) = '<'; - *(p++) = '/'; - *(p++) = SERVICEPREFIX2; - *(p++) = ':'; - pe = action; - while(*pe) - *(p++) = *(pe++); - strncpy(p, ">\r\n", - soapbody + sizeof(soapbody) - p); - } - if(!parseURL(url, hostname, &port, &path)) return -1; - if(s<0) - { - s = socket(PF_INET, SOCK_STREAM, 0); - if(s<0) - { - PRINT_SOCKET_ERROR("socket"); - *bufsize = 0; - return -1; - } - dest.sin_family = AF_INET; - dest.sin_port = htons(port); - dest.sin_addr.s_addr = inet_addr(hostname); - if(connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr))<0) - { - PRINT_SOCKET_ERROR("connect"); - closesocket(s); - *bufsize = 0; - return -1; - } - } - - n = soapPostSubmit(s, path, hostname, port, soapact, soapbody); - if(n<=0) { -#ifdef DEBUG - printf("Error sending SOAP request\n"); -#endif - closesocket(s); - return -1; - } - - contentlen = -1; - headerlen = -1; - buf = buffer; - buffree = *bufsize; - *bufsize = 0; - while ((n = ReceiveData(s, buf, buffree, 5000)) > 0) { - buffree -= n; - buf += n; - *bufsize += n; - getContentLengthAndHeaderLength(buffer, *bufsize, - &contentlen, &headerlen); -#ifdef DEBUG - printf("received n=%dbytes bufsize=%d ContLen=%d HeadLen=%d\n", - n, *bufsize, contentlen, headerlen); -#endif - /* break if we received everything */ - if(contentlen > 0 && headerlen > 0 && *bufsize >= contentlen+headerlen) - break; - } - - closesocket(s); - return 0; -} - -/* parseMSEARCHReply() - * the last 4 arguments are filled during the parsing : - * - location/locationsize : "location:" field of the SSDP reply packet - * - st/stsize : "st:" field of the SSDP reply packet. - * The strings are NOT null terminated */ -static void -parseMSEARCHReply(const char * reply, int size, - const char * * location, int * locationsize, - const char * * st, int * stsize) -{ - int a, b, i; - i = 0; - a = i; /* start of the line */ - b = 0; - while(ipNext = devlist; - tmp->descURL = tmp->buffer; - tmp->st = tmp->buffer + 1 + urlsize; - memcpy(tmp->buffer, descURL, urlsize); - tmp->buffer[urlsize] = '\0'; - memcpy(tmp->buffer + urlsize + 1, st, stsize); - tmp->buffer[urlsize+1+stsize] = '\0'; - devlist = tmp; - } - } - } -} - -/* freeUPNPDevlist() should be used to - * free the chained list returned by upnpDiscover() */ -void freeUPNPDevlist(struct UPNPDev * devlist) -{ - struct UPNPDev * next; - while(devlist) - { - next = devlist->pNext; - free(devlist); - devlist = next; - } -} - -static void -url_cpy_or_cat(char * dst, const char * src, int n) -{ - if( (src[0] == 'h') - &&(src[1] == 't') - &&(src[2] == 't') - &&(src[3] == 'p') - &&(src[4] == ':') - &&(src[5] == '/') - &&(src[6] == '/')) - { - strncpy(dst, src, n); - } - else - { - int l = strlen(dst); - if(src[0] != '/') - dst[l++] = '/'; - if(l<=n) - strncpy(dst + l, src, n - l); - } -} - -/* Prepare the Urls for usage... - */ -void GetUPNPUrls(struct UPNPUrls * urls, struct IGDdatas * data, - const char * descURL) -{ - char * p; - int n1, n2, n3; - n1 = strlen(data->urlbase); - if(n1==0) - n1 = strlen(descURL); - n1 += 2; /* 1 byte more for Null terminator, 1 byte for '/' if needed */ - n2 = n1; n3 = n1; - n1 += strlen(data->scpdurl); - n2 += strlen(data->controlurl); - n3 += strlen(data->controlurl_CIF); - - urls->ipcondescURL = (char *)malloc(n1); - urls->controlURL = (char *)malloc(n2); - urls->controlURL_CIF = (char *)malloc(n3); - /* maintenant on chope la desc du WANIPConnection */ - if(data->urlbase[0] != '\0') - strncpy(urls->ipcondescURL, data->urlbase, n1); - else - strncpy(urls->ipcondescURL, descURL, n1); - p = strchr(urls->ipcondescURL+7, '/'); - if(p) p[0] = '\0'; - strncpy(urls->controlURL, urls->ipcondescURL, n2); - strncpy(urls->controlURL_CIF, urls->ipcondescURL, n3); - - url_cpy_or_cat(urls->ipcondescURL, data->scpdurl, n1); - - url_cpy_or_cat(urls->controlURL, data->controlurl, n2); - - url_cpy_or_cat(urls->controlURL_CIF, data->controlurl_CIF, n3); - -#ifdef DEBUG - printf("urls->ipcondescURL='%s' %d n1=%d\n", urls->ipcondescURL, - strlen(urls->ipcondescURL), n1); - printf("urls->controlURL='%s' %d n2=%d\n", urls->controlURL, - strlen(urls->controlURL), n2); - printf("urls->controlURL_CIF='%s' %d n3=%d\n", urls->controlURL_CIF, - strlen(urls->controlURL_CIF), n3); -#endif -} - -void -FreeUPNPUrls(struct UPNPUrls * urls) -{ - if(!urls) - return; - free(urls->controlURL); - urls->controlURL = 0; - free(urls->ipcondescURL); - urls->ipcondescURL = 0; - free(urls->controlURL_CIF); - urls->controlURL_CIF = 0; -} - - -int ReceiveData(int socket, char * data, int length, int timeout) -{ - int n; -#ifndef WIN32 - struct pollfd fds[1]; /* for the poll */ - fds[0].fd = socket; - fds[0].events = POLLIN; - n = poll(fds, 1, timeout); - if(n < 0) - { - PRINT_SOCKET_ERROR("poll"); - return -1; - } - else if(n == 0) - { - return 0; - } -#else - fd_set socketSet; - TIMEVAL timeval; - FD_ZERO(&socketSet); - FD_SET(socket, &socketSet); - timeval.tv_sec = timeout / 1000; - timeval.tv_usec = (timeout % 1000) * 1000; - /*n = select(0, &socketSet, NULL, NULL, &timeval);*/ - n = select(FD_SETSIZE, &socketSet, NULL, NULL, &timeval); - if(n < 0) - { - PRINT_SOCKET_ERROR("select"); - return -1; - } - else if(n == 0) - { - return 0; - } -#endif - n = recv(socket, data, length, 0); - if(n<0) - { - PRINT_SOCKET_ERROR("recv"); - } - return n; -} - -int -UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data) -{ - char status[64]; - unsigned int uptime; - status[0] = '\0'; - UPNP_GetStatusInfo(urls->controlURL, data->servicetype, - status, &uptime, NULL); - if(0 == strcmp("Connected", status)) - { - return 1; - } - else - return 0; -} - - -/* UPNP_GetValidIGD() : - * return values : - * 0 = NO IGD found - * 1 = A valid connected IGD has been found - * 2 = A valid IGD has been found but it reported as - * not connected - * 3 = an UPnP device has been found but was not recognized as an IGD - * - * In any non zero return case, the urls and data structures - * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to - * free allocated memory. - */ -int -UPNP_GetValidIGD(struct UPNPDev * devlist, - struct UPNPUrls * urls, - struct IGDdatas * data, - char * lanaddr, int lanaddrlen) -{ - char * descXML; - int descXMLsize = 0; - struct UPNPDev * dev; - int state; /* state 1 : IGD connected. State 2 : IGD. State 3 : anything */ - if(!devlist) - { -#ifdef DEBUG - printf("Empty devlist\n"); -#endif - return 0; - } - for(state = 1; state <= 3; state++) - { - for(dev = devlist; dev; dev = dev->pNext) - { - /* we should choose an internet gateway device. - * with st == urn:schemas-upnp-org:device:InternetGatewayDevice:1 */ - descXML = miniwget_getaddr(dev->descURL, &descXMLsize, - lanaddr, lanaddrlen); - if(descXML) - { - memset(data, 0, sizeof(struct IGDdatas)); - memset(urls, 0, sizeof(struct UPNPUrls)); - parserootdesc(descXML, descXMLsize, data); - free(descXML); - descXML = NULL; - if(0==strcmp(data->servicetype_CIF, - "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1") - || state >= 3 ) - { - GetUPNPUrls(urls, data, dev->descURL); - -#ifdef DEBUG - printf("UPNPIGD_IsConnected(%s) = %d\n", - urls->controlURL, - UPNPIGD_IsConnected(urls, data)); -#endif - if((state >= 2) || UPNPIGD_IsConnected(urls, data)) - return state; - FreeUPNPUrls(urls); - } - memset(data, 0, sizeof(struct IGDdatas)); - } -#ifdef DEBUG - else - { - printf("error getting XML description %s\n", dev->descURL); - } -#endif - } - } - return 0; -} - -/* UPNP_GetIGDFromUrl() - * Used when skipping the discovery process. - * return value : - * 0 - Not ok - * 1 - OK */ -int -UPNP_GetIGDFromUrl(const char * rootdescurl, - struct UPNPUrls * urls, - struct IGDdatas * data, - char * lanaddr, int lanaddrlen) -{ - char * descXML; - int descXMLsize = 0; - descXML = miniwget_getaddr(rootdescurl, &descXMLsize, - lanaddr, lanaddrlen); - if(descXML) { - memset(data, 0, sizeof(struct IGDdatas)); - memset(urls, 0, sizeof(struct UPNPUrls)); - parserootdesc(descXML, descXMLsize, data); - free(descXML); - descXML = NULL; - GetUPNPUrls(urls, data, rootdescurl); - return 1; - } else { - return 0; - } -} - diff --git a/libs/miniupnpc/miniupnpc.def b/libs/miniupnpc/miniupnpc.def deleted file mode 100644 index 21e66a4c36..0000000000 --- a/libs/miniupnpc/miniupnpc.def +++ /dev/null @@ -1,31 +0,0 @@ -LIBRARY -; miniupnpc library - -EXPORTS -; miniupnpc - upnpDiscover - freeUPNPDevlist - parserootdesc - UPNP_GetValidIGD - UPNP_GetIGDFromUrl - GetUPNPUrls - FreeUPNPUrls -; miniwget - miniwget - miniwget_getaddr -; upnpcommands - UPNP_GetTotalBytesSent - UPNP_GetTotalBytesReceived - UPNP_GetTotalPacketsSent - UPNP_GetTotalPacketsReceived - UPNP_GetStatusInfo - UPNP_GetConnectionTypeInfo - UPNP_GetExternalIPAddress - UPNP_GetLinkLayerMaxBitRates - UPNP_AddPortMapping - UPNP_DeletePortMapping - UPNP_GetPortMappingNumberOfEntries - UPNP_GetSpecificPortMappingEntry - UPNP_GetGenericPortMappingEntry -; upnperrors - strupnperror \ No newline at end of file diff --git a/libs/miniupnpc/miniupnpc.h b/libs/miniupnpc/miniupnpc.h deleted file mode 100644 index bce314e825..0000000000 --- a/libs/miniupnpc/miniupnpc.h +++ /dev/null @@ -1,110 +0,0 @@ -/* $Id: miniupnpc.h,v 1.18 2008/09/25 18:02:50 nanard Exp $ */ -/* Project: miniupnp - * http://miniupnp.free.fr/ - * Author: Thomas Bernard - * Copyright (c) 2005-2006 Thomas Bernard - * This software is subjects to the conditions detailed - * in the LICENCE file provided within this distribution */ -#ifndef __MINIUPNPC_H__ -#define __MINIUPNPC_H__ - -#include "declspec.h" -#include "igd_desc_parse.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Structures definitions : */ -struct UPNParg { const char * elt; const char * val; }; - -int simpleUPnPcommand(int, const char *, const char *, - const char *, struct UPNParg *, - char *, int *); - -struct UPNPDev { - struct UPNPDev * pNext; - char * descURL; - char * st; - char buffer[2]; -}; - -/* upnpDiscover() - * discover UPnP devices on the network. - * The discovered devices are returned as a chained list. - * It is up to the caller to free the list with freeUPNPDevlist(). - * delay (in millisecond) is the maximum time for waiting any device - * response. - * If available, device list will be obtained from MiniSSDPd. - * Default path for minissdpd socket will be used if minissdpdsock argument - * is NULL. - * If multicastif is not NULL, it will be used instead of the default - * multicast interface for sending SSDP discover packets. - * If sameport is not null, SSDP packets will be sent from the source port - * 1900 (same as destination port) otherwise system assign a source port. */ -LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif, - const char * minissdpdsock, int sameport); -/* freeUPNPDevlist() - * free list returned by upnpDiscover() */ -LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist); - -/* parserootdesc() : - * parse root XML description of a UPnP device and fill the IGDdatas - * structure. */ -LIBSPEC void parserootdesc(const char *, int, struct IGDdatas *); - -/* structure used to get fast access to urls - * controlURL: controlURL of the WANIPConnection - * ipcondescURL: url of the description of the WANIPConnection - * controlURL_CIF: controlURL of the WANCommonInterfaceConfig - */ -struct UPNPUrls { - char * controlURL; - char * ipcondescURL; - char * controlURL_CIF; -}; - -/* UPNP_GetValidIGD() : - * return values : - * 0 = NO IGD found - * 1 = A valid connected IGD has been found - * 2 = A valid IGD has been found but it reported as - * not connected - * 3 = an UPnP device has been found but was not recognized as an IGD - * - * In any non zero return case, the urls and data structures - * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to - * free allocated memory. - */ -LIBSPEC int -UPNP_GetValidIGD(struct UPNPDev * devlist, - struct UPNPUrls * urls, - struct IGDdatas * data, - char * lanaddr, int lanaddrlen); - -/* UPNP_GetIGDFromUrl() - * Used when skipping the discovery process. - * return value : - * 0 - Not ok - * 1 - OK */ -LIBSPEC int -UPNP_GetIGDFromUrl(const char * rootdescurl, - struct UPNPUrls * urls, - struct IGDdatas * data, - char * lanaddr, int lanaddrlen); - -LIBSPEC void GetUPNPUrls(struct UPNPUrls *, struct IGDdatas *, const char *); - -LIBSPEC void FreeUPNPUrls(struct UPNPUrls *); - -/* Reads data from the specified socket. - * Returns the number of bytes read if successful, zero if no bytes were - * read or if we timed out. Returns negative if there was an error. */ -int ReceiveData(int socket, char * data, int length, int timeout); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/libs/miniupnpc/miniupnpcmodule.c b/libs/miniupnpc/miniupnpcmodule.c deleted file mode 100644 index 121ff2052d..0000000000 --- a/libs/miniupnpc/miniupnpcmodule.c +++ /dev/null @@ -1,460 +0,0 @@ -/* $Id: miniupnpcmodule.c,v 1.13 2009/04/17 20:59:42 nanard Exp $*/ -/* Project : miniupnp - * Author : Thomas BERNARD - * website : http://miniupnp.tuxfamily.org/ - * copyright (c) 2007 Thomas Bernard - * This software is subjet to the conditions detailed in the - * provided LICENCE file. */ -#include -#define STATICLIB -#include "structmember.h" -#include "miniupnpc.h" -#include "upnpcommands.h" -#include "upnperrors.h" - -/* for compatibility with Python < 2.4 */ -#ifndef Py_RETURN_NONE -#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None -#endif - -#ifndef Py_RETURN_TRUE -#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True -#endif - -#ifndef Py_RETURN_FALSE -#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False -#endif - -typedef struct { - PyObject_HEAD - /* Type-specific fields go here. */ - struct UPNPDev * devlist; - struct UPNPUrls urls; - struct IGDdatas data; - unsigned int discoverdelay; /* value passed to upnpDiscover() */ - char lanaddr[16]; /* our ip address on the LAN */ - char * multicastif; - char * minissdpdsocket; -} UPnPObject; - -static PyMemberDef UPnP_members[] = { - {"lanaddr", T_STRING_INPLACE, offsetof(UPnPObject, lanaddr), - READONLY, "ip address on the LAN" - }, - {"discoverdelay", T_UINT, offsetof(UPnPObject, discoverdelay), - 0/*READWRITE*/, "value in ms used to wait for SSDP responses" - }, - /* T_STRING is allways readonly :( */ - {"multicastif", T_STRING, offsetof(UPnPObject, multicastif), - 0, "IP of the network interface to be used for multicast operations" - }, - {"minissdpdsocket", T_STRING, offsetof(UPnPObject, multicastif), - 0, "path of the MiniSSDPd unix socket" - }, - {NULL} -}; - -static void -UPnPObject_dealloc(UPnPObject *self) -{ - freeUPNPDevlist(self->devlist); - FreeUPNPUrls(&self->urls); - self->ob_type->tp_free((PyObject*)self); -} - -static PyObject * -UPnP_discover(UPnPObject *self) -{ - struct UPNPDev * dev; - int i; - PyObject *res = NULL; - if(self->devlist) - { - freeUPNPDevlist(self->devlist); - self->devlist = 0; - } - self->devlist = upnpDiscover((int)self->discoverdelay/*timeout in ms*/, - 0/* multicast if*/, - 0/*minissdpd socket*/, - 0/*sameport flag*/); - /* Py_RETURN_NONE ??? */ - for(dev = self->devlist, i = 0; dev; dev = dev->pNext) - i++; - res = Py_BuildValue("i", i); - return res; -} - -static PyObject * -UPnP_selectigd(UPnPObject *self) -{ - if(UPNP_GetValidIGD(self->devlist, &self->urls, &self->data, - self->lanaddr, sizeof(self->lanaddr))) - { - return Py_BuildValue("s", self->urls.controlURL); - } - else - { - /* TODO: have our own exception type ! */ - PyErr_SetString(PyExc_Exception, "No UPnP device discovered"); - return NULL; - } -} - -static PyObject * -UPnP_totalbytesent(UPnPObject *self) -{ - return Py_BuildValue("I", - UPNP_GetTotalBytesSent(self->urls.controlURL_CIF, - self->data.servicetype_CIF)); -} - -static PyObject * -UPnP_totalbytereceived(UPnPObject *self) -{ - return Py_BuildValue("I", - UPNP_GetTotalBytesReceived(self->urls.controlURL_CIF, - self->data.servicetype_CIF)); -} - -static PyObject * -UPnP_totalpacketsent(UPnPObject *self) -{ - return Py_BuildValue("I", - UPNP_GetTotalPacketsSent(self->urls.controlURL_CIF, - self->data.servicetype_CIF)); -} - -static PyObject * -UPnP_totalpacketreceived(UPnPObject *self) -{ - return Py_BuildValue("I", - UPNP_GetTotalPacketsReceived(self->urls.controlURL_CIF, - self->data.servicetype_CIF)); -} - -static PyObject * -UPnP_statusinfo(UPnPObject *self) -{ - char status[64]; - char lastconnerror[64]; - unsigned int uptime = 0; - int r; - status[0] = '\0'; - lastconnerror[0] = '\0'; - r = UPNP_GetStatusInfo(self->urls.controlURL, self->data.servicetype, - status, &uptime, lastconnerror); - if(r==UPNPCOMMAND_SUCCESS) { - return Py_BuildValue("(s,I,s)", status, uptime, lastconnerror); - } else { - /* TODO: have our own exception type ! */ - PyErr_SetString(PyExc_Exception, strupnperror(r)); - return NULL; - } -} - -static PyObject * -UPnP_connectiontype(UPnPObject *self) -{ - char connectionType[64]; - int r; - connectionType[0] = '\0'; - r = UPNP_GetConnectionTypeInfo(self->urls.controlURL, - self->data.servicetype, - connectionType); - if(r==UPNPCOMMAND_SUCCESS) { - return Py_BuildValue("s", connectionType); - } else { - /* TODO: have our own exception type ! */ - PyErr_SetString(PyExc_Exception, strupnperror(r)); - return NULL; - } -} - -static PyObject * -UPnP_externalipaddress(UPnPObject *self) -{ - char externalIPAddress[16]; - int r; - externalIPAddress[0] = '\0'; - r = UPNP_GetExternalIPAddress(self->urls.controlURL, - self->data.servicetype, - externalIPAddress); - if(r==UPNPCOMMAND_SUCCESS) { - return Py_BuildValue("s", externalIPAddress); - } else { - /* TODO: have our own exception type ! */ - PyErr_SetString(PyExc_Exception, strupnperror(r)); - return NULL; - } -} - -/* AddPortMapping(externalPort, protocol, internalHost, internalPort, desc, - * remoteHost) - * protocol is 'UDP' or 'TCP' */ -static PyObject * -UPnP_addportmapping(UPnPObject *self, PyObject *args) -{ - char extPort[6]; - unsigned short ePort; - char inPort[6]; - unsigned short iPort; - const char * proto; - const char * host; - const char * desc; - const char * remoteHost; - int r; - if (!PyArg_ParseTuple(args, "HssHss", &ePort, &proto, - &host, &iPort, &desc, &remoteHost)) - return NULL; - sprintf(extPort, "%hu", ePort); - sprintf(inPort, "%hu", iPort); - r = UPNP_AddPortMapping(self->urls.controlURL, self->data.servicetype, - extPort, inPort, host, desc, proto, remoteHost); - if(r==UPNPCOMMAND_SUCCESS) - { - Py_RETURN_TRUE; - } - else - { - // TODO: RAISE an Exception. See upnpcommands.h for errors codes. - // upnperrors.c - //Py_RETURN_FALSE; - /* TODO: have our own exception type ! */ - PyErr_SetString(PyExc_Exception, strupnperror(r)); - return NULL; - } -} - -/* DeletePortMapping(extPort, proto, removeHost='') - * proto = 'UDP', 'TCP' */ -static PyObject * -UPnP_deleteportmapping(UPnPObject *self, PyObject *args) -{ - char extPort[6]; - unsigned short ePort; - const char * proto; - const char * remoteHost = ""; - int r; - if(!PyArg_ParseTuple(args, "Hs|z", &ePort, &proto, &remoteHost)) - return NULL; - sprintf(extPort, "%hu", ePort); - r = UPNP_DeletePortMapping(self->urls.controlURL, self->data.servicetype, - extPort, proto, remoteHost); - if(r==UPNPCOMMAND_SUCCESS) { - Py_RETURN_TRUE; - } else { - /* TODO: have our own exception type ! */ - PyErr_SetString(PyExc_Exception, strupnperror(r)); - return NULL; - } -} - -static PyObject * -UPnP_getportmappingnumberofentries(UPnPObject *self) -{ - unsigned int n = 0; - int r; - r = UPNP_GetPortMappingNumberOfEntries(self->urls.controlURL, - self->data.servicetype, - &n); - if(r==UPNPCOMMAND_SUCCESS) { - return Py_BuildValue("I", n); - } else { - /* TODO: have our own exception type ! */ - PyErr_SetString(PyExc_Exception, strupnperror(r)); - return NULL; - } -} - -/* GetSpecificPortMapping(ePort, proto) - * proto = 'UDP' or 'TCP' */ -static PyObject * -UPnP_getspecificportmapping(UPnPObject *self, PyObject *args) -{ - char extPort[6]; - unsigned short ePort; - const char * proto; - char intClient[16]; - char intPort[6]; - unsigned short iPort; - if(!PyArg_ParseTuple(args, "Hs", &ePort, &proto)) - return NULL; - sprintf(extPort, "%hu", ePort); - UPNP_GetSpecificPortMappingEntry(self->urls.controlURL, - self->data.servicetype, - extPort, proto, - intClient, intPort); - if(intClient[0]) - { - iPort = (unsigned short)atoi(intPort); - return Py_BuildValue("(s,H)", intClient, iPort); - } - else - { - Py_RETURN_NONE; - } -} - -/* GetGenericPortMapping(index) */ -static PyObject * -UPnP_getgenericportmapping(UPnPObject *self, PyObject *args) -{ - int i, r; - char index[8]; - char intClient[16]; - char intPort[6]; - unsigned short iPort; - char extPort[6]; - unsigned short ePort; - char protocol[4]; - char desc[80]; - char enabled[6]; - char rHost[64]; - char duration[16]; /* lease duration */ - unsigned int dur; - if(!PyArg_ParseTuple(args, "i", &i)) - return NULL; - snprintf(index, sizeof(index), "%d", i); - rHost[0] = '\0'; enabled[0] = '\0'; - duration[0] = '\0'; desc[0] = '\0'; - extPort[0] = '\0'; intPort[0] = '\0'; intClient[0] = '\0'; - r = UPNP_GetGenericPortMappingEntry(self->urls.controlURL, - self->data.servicetype, - index, - extPort, intClient, intPort, - protocol, desc, enabled, rHost, - duration); - if(r==UPNPCOMMAND_SUCCESS) - { - ePort = (unsigned short)atoi(extPort); - iPort = (unsigned short)atoi(intPort); - dur = (unsigned int)strtoul(duration, 0, 0); - return Py_BuildValue("(H,s,(s,H),s,s,s,I)", - ePort, protocol, intClient, iPort, - desc, enabled, rHost, dur); - } - else - { - Py_RETURN_NONE; - } -} - -/* miniupnpc.UPnP object Method Table */ -static PyMethodDef UPnP_methods[] = { - {"discover", (PyCFunction)UPnP_discover, METH_NOARGS, - "discover UPnP IGD devices on the network" - }, - {"selectigd", (PyCFunction)UPnP_selectigd, METH_NOARGS, - "select a valid UPnP IGD among discovered devices" - }, - {"totalbytesent", (PyCFunction)UPnP_totalbytesent, METH_NOARGS, - "return the total number of bytes sent by UPnP IGD" - }, - {"totalbytereceived", (PyCFunction)UPnP_totalbytereceived, METH_NOARGS, - "return the total number of bytes received by UPnP IGD" - }, - {"totalpacketsent", (PyCFunction)UPnP_totalpacketsent, METH_NOARGS, - "return the total number of packets sent by UPnP IGD" - }, - {"totalpacketreceived", (PyCFunction)UPnP_totalpacketreceived, METH_NOARGS, - "return the total number of packets received by UPnP IGD" - }, - {"statusinfo", (PyCFunction)UPnP_statusinfo, METH_NOARGS, - "return status and uptime" - }, - {"connectiontype", (PyCFunction)UPnP_connectiontype, METH_NOARGS, - "return IGD WAN connection type" - }, - {"externalipaddress", (PyCFunction)UPnP_externalipaddress, METH_NOARGS, - "return external IP address" - }, - {"addportmapping", (PyCFunction)UPnP_addportmapping, METH_VARARGS, - "add a port mapping" - }, - {"deleteportmapping", (PyCFunction)UPnP_deleteportmapping, METH_VARARGS, - "delete a port mapping" - }, - {"getportmappingnumberofentries", (PyCFunction)UPnP_getportmappingnumberofentries, METH_NOARGS, - "-- non standard --" - }, - {"getspecificportmapping", (PyCFunction)UPnP_getspecificportmapping, METH_VARARGS, - "get details about a specific port mapping entry" - }, - {"getgenericportmapping", (PyCFunction)UPnP_getgenericportmapping, METH_VARARGS, - "get all details about the port mapping at index" - }, - {NULL} /* Sentinel */ -}; - -static PyTypeObject UPnPType = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ - "miniupnpc.UPnP", /*tp_name*/ - sizeof(UPnPObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)UPnPObject_dealloc,/*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /*tp_flags*/ - "UPnP objects", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - UPnP_methods, /* tp_methods */ - UPnP_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0,/*(initproc)UPnP_init,*/ /* tp_init */ - 0, /* tp_alloc */ -#ifndef WIN32 - PyType_GenericNew,/*UPnP_new,*/ /* tp_new */ -#else - 0, -#endif -}; - -/* module methods */ -static PyMethodDef miniupnpc_methods[] = { - {NULL} /* Sentinel */ -}; - -#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ -#define PyMODINIT_FUNC void -#endif -PyMODINIT_FUNC -initminiupnpc(void) -{ - PyObject* m; - -#ifdef WIN32 - UPnPType.tp_new = PyType_GenericNew; -#endif - if (PyType_Ready(&UPnPType) < 0) - return; - - m = Py_InitModule3("miniupnpc", miniupnpc_methods, - "miniupnpc module."); - - Py_INCREF(&UPnPType); - PyModule_AddObject(m, "UPnP", (PyObject *)&UPnPType); -} - diff --git a/libs/miniupnpc/miniupnpcstrings.h b/libs/miniupnpc/miniupnpcstrings.h deleted file mode 100644 index b1b38533a7..0000000000 --- a/libs/miniupnpc/miniupnpcstrings.h +++ /dev/null @@ -1,15 +0,0 @@ -/* $Id: miniupnpcstrings.h,v 1.2 2008/10/14 17:39:04 nanard Exp $ */ -/* Project: miniupnp - * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * Author: Thomas Bernard - * Copyright (c) 2005-2008 Thomas Bernard - * This software is subjects to the conditions detailed - * in the LICENCE file provided within this distribution */ -#ifndef __MINIUPNPCSTRINGS_H__ -#define __MINIUPNPCSTRINGS_H__ - -#define OS_STRING "Debian/4.0" -#define MINIUPNPC_VERSION_STRING "1.2" - -#endif - diff --git a/libs/miniupnpc/miniwget.c b/libs/miniupnpc/miniwget.c deleted file mode 100644 index 3fa930e313..0000000000 --- a/libs/miniupnpc/miniwget.c +++ /dev/null @@ -1,282 +0,0 @@ -/* $Id: miniwget.c,v 1.22 2009/02/28 10:36:35 nanard Exp $ */ -/* Project : miniupnp - * Author : Thomas Bernard - * Copyright (c) 2005 Thomas Bernard - * This software is subject to the conditions detailed in the - * LICENCE file provided in this distribution. - * */ -#include -#include -#include -#include "miniupnpc.h" -#ifdef WIN32 -#include -#include -#define MAXHOSTNAMELEN 64 -#define MIN(x,y) (((x)<(y))?(x):(y)) -#if _MSC_VER < 1900 -#define snprintf _snprintf -#endif -#define herror -#define socklen_t int -#else -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define closesocket close -#endif -#if defined(__sun) || defined(sun) -#define MIN(x,y) (((x)<(y))?(x):(y)) -#endif - -#include "miniupnpcstrings.h" - -/* miniwget2() : - * */ -static void * -miniwget2(const char * url, const char * host, - unsigned short port, const char * path, - int * size, char * addr_str, int addr_str_len) -{ - char buf[2048]; -#ifdef WIN32 - SOCKET s; -#else - int s; - int fd_flags; -#endif - struct sockaddr_in dest; - struct hostent *hp; - - *size = 0; - hp = gethostbyname(host); - if(hp==NULL) - { - herror(host); - return NULL; - } - /* memcpy((char *)&dest.sin_addr, hp->h_addr, hp->h_length); */ - memcpy(&dest.sin_addr, hp->h_addr, sizeof(dest.sin_addr)); - memset(dest.sin_zero, 0, sizeof(dest.sin_zero)); - s = socket(PF_INET, SOCK_STREAM, 0); - if(s < 0) - { - perror("socket"); - return NULL; - } - dest.sin_family = AF_INET; - dest.sin_port = htons(port); - - - - { -#ifdef WIN32 - u_long arg = 1; - if (ioctlsocket((SOCKET) s, FIONBIO, &arg) == SOCKET_ERROR) { - return NULL; - } - -#else - fd_flags = fcntl(s, F_GETFL, 0); - - if (fcntl(s, F_SETFL, fd_flags | O_NONBLOCK)) { - return NULL; - } - -#endif - - } - - connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr_in)); - - { - fd_set wfds; - struct timeval tv = { 2, 0 }; - int r; - - FD_ZERO(&wfds); - FD_SET(s, &wfds); - - r = select(s + 1, NULL, &wfds, NULL, &tv); - - if (r <= 0) { - return NULL; - } - - if (!FD_ISSET(s, &wfds)) { - return NULL; - } - - } - -#ifdef WIN32 - { - u_long arg = 0; - if (ioctlsocket((SOCKET) s, FIONBIO, &arg) == SOCKET_ERROR) { - return NULL; - } - } -#else - fcntl(s, F_SETFL, fd_flags); -#endif - - - /* get address for caller ! */ - if(addr_str) - { - struct sockaddr_in saddr; - socklen_t len; - - len = sizeof(saddr); - getsockname(s, (struct sockaddr *)&saddr, &len); -#ifndef WIN32 - inet_ntop(AF_INET, &saddr.sin_addr, addr_str, addr_str_len); -#else - /* using INT WINAPI WSAAddressToStringA(LPSOCKADDR, DWORD, LPWSAPROTOCOL_INFOA, LPSTR, LPDWORD); - * But his function make a string with the port : nn.nn.nn.nn:port */ -/* if(WSAAddressToStringA((SOCKADDR *)&saddr, sizeof(saddr), - NULL, addr_str, (DWORD *)&addr_str_len)) - { - printf("WSAAddressToStringA() failed : %d\n", WSAGetLastError()); - }*/ - strncpy(addr_str, inet_ntoa(saddr.sin_addr), addr_str_len); -#endif -#ifdef DEBUG - printf("address miniwget : %s\n", addr_str); -#endif - } - - snprintf(buf, sizeof(buf), - "GET %s HTTP/1.1\r\n" - "Host: %s:%d\r\n" - "Connection: Close\r\n" - "User-Agent: " OS_STRING ", UPnP/1.0, MiniUPnPc/" MINIUPNPC_VERSION_STRING "\r\n" - - "\r\n", - path, host, port); - /*write(s, buf, strlen(buf));*/ - send(s, buf, strlen(buf), 0); - { - int n, headers=1; - char * respbuffer = NULL; - int allreadyread = 0; - /*while((n = recv(s, buf, 2048, 0)) > 0)*/ - while((n = ReceiveData(s, buf, 2048, 5000)) > 0) - { - if(headers) - { - int i=0; - while(ip3)) - { - strncpy(hostname, p1, MIN(MAXHOSTNAMELEN, (int)(p3-p1))); - *port = 80; - } - else - { - strncpy(hostname, p1, MIN(MAXHOSTNAMELEN, (int)(p2-p1))); - *port = 0; - p2++; - while( (*p2 >= '0') && (*p2 <= '9')) - { - *port *= 10; - *port += (unsigned short)(*p2 - '0'); - p2++; - } - } - *path = p3; - return 1; -} - -void * miniwget(const char * url, int * size) -{ - unsigned short port; - char * path; - /* protocol://host:port/chemin */ - char hostname[MAXHOSTNAMELEN+1]; - *size = 0; - if(!parseURL(url, hostname, &port, &path)) { - return NULL; - } - return miniwget2(url, hostname, port, path, size, 0, 0); -} - -void * miniwget_getaddr(const char * url, int * size, char * addr, int addrlen) -{ - unsigned short port; - char * path; - /* protocol://host:port/chemin */ - char hostname[MAXHOSTNAMELEN+1]; - *size = 0; - if(addr) - addr[0] = '\0'; - if(!parseURL(url, hostname, &port, &path)) - return NULL; - return miniwget2(url, hostname, port, path, size, addr, addrlen); -} - diff --git a/libs/miniupnpc/miniwget.h b/libs/miniupnpc/miniwget.h deleted file mode 100644 index 12c062c6d6..0000000000 --- a/libs/miniupnpc/miniwget.h +++ /dev/null @@ -1,28 +0,0 @@ -/* $Id: miniwget.h,v 1.5 2007/01/29 20:27:23 nanard Exp $ */ -/* Project : miniupnp - * Author : Thomas Bernard - * Copyright (c) 2005 Thomas Bernard - * This software is subject to the conditions detailed in the - * LICENCE file provided in this distribution. - * */ -#ifndef __MINIWGET_H__ -#define __MINIWGET_H__ - -#include "declspec.h" - -#ifdef __cplusplus -extern "C" { -#endif - -LIBSPEC void * miniwget(const char *, int *); - -LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int); - -int parseURL(const char *, char *, unsigned short *, char * *); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/libs/miniupnpc/minixml.c b/libs/miniupnpc/minixml.c deleted file mode 100644 index dce690e2e4..0000000000 --- a/libs/miniupnpc/minixml.c +++ /dev/null @@ -1,191 +0,0 @@ -/* $Id: minixml.c,v 1.6 2007/05/15 18:14:08 nanard Exp $ */ -/* minixml.c : the minimum size a xml parser can be ! */ -/* Project : miniupnp - * webpage: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * Author : Thomas Bernard - -Copyright (c) 2005-2007, Thomas BERNARD -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. -*/ -#include "minixml.h" - -/* parseatt : used to parse the argument list - * return 0 (false) in case of success and -1 (true) if the end - * of the xmlbuffer is reached. */ -int parseatt(struct xmlparser * p) -{ - const char * attname; - int attnamelen; - const char * attvalue; - int attvaluelen; - while(p->xml < p->xmlend) - { - if(*p->xml=='/' || *p->xml=='>') - return 0; - if( !IS_WHITE_SPACE(*p->xml) ) - { - char sep; - attname = p->xml; - attnamelen = 0; - while(*p->xml!='=' && !IS_WHITE_SPACE(*p->xml) ) - { - attnamelen++; p->xml++; - if(p->xml >= p->xmlend) - return -1; - } - while(*(p->xml++) != '=') - { - if(p->xml >= p->xmlend) - return -1; - } - while(IS_WHITE_SPACE(*p->xml)) - { - p->xml++; - if(p->xml >= p->xmlend) - return -1; - } - sep = *p->xml; - if(sep=='\'' || sep=='\"') - { - p->xml++; - if(p->xml >= p->xmlend) - return -1; - attvalue = p->xml; - attvaluelen = 0; - while(*p->xml != sep) - { - attvaluelen++; p->xml++; - if(p->xml >= p->xmlend) - return -1; - } - } - else - { - attvalue = p->xml; - attvaluelen = 0; - while( !IS_WHITE_SPACE(*p->xml) - && *p->xml != '>' && *p->xml != '/') - { - attvaluelen++; p->xml++; - if(p->xml >= p->xmlend) - return -1; - } - } - /*printf("%.*s='%.*s'\n", - attnamelen, attname, attvaluelen, attvalue);*/ - if(p->attfunc) - p->attfunc(p->data, attname, attnamelen, attvalue, attvaluelen); - } - p->xml++; - } - return -1; -} - -/* parseelt parse the xml stream and - * call the callback functions when needed... */ -void parseelt(struct xmlparser * p) -{ - int i; - const char * elementname; - while(p->xml < (p->xmlend - 1)) - { - if((p->xml)[0]=='<' && (p->xml)[1]!='?') - { - i = 0; elementname = ++p->xml; - while( !IS_WHITE_SPACE(*p->xml) - && (*p->xml!='>') && (*p->xml!='/') - ) - { - i++; p->xml++; - if (p->xml >= p->xmlend) - return; - /* to ignore namespace : */ - if(*p->xml==':') - { - i = 0; - elementname = ++p->xml; - } - } - if(i>0) - { - if(p->starteltfunc) - p->starteltfunc(p->data, elementname, i); - if(parseatt(p)) - return; - if(*p->xml!='/') - { - const char * data; - i = 0; data = ++p->xml; - if (p->xml >= p->xmlend) - return; - while( IS_WHITE_SPACE(*p->xml) ) - { - p->xml++; - if (p->xml >= p->xmlend) - return; - } - while(*p->xml!='<') - { - i++; p->xml++; - if (p->xml >= p->xmlend) - return; - } - if(i>0 && p->datafunc) - p->datafunc(p->data, data, i); - } - } - else if(*p->xml == '/') - { - i = 0; elementname = ++p->xml; - if (p->xml >= p->xmlend) - return; - while((*p->xml != '>')) - { - i++; p->xml++; - if (p->xml >= p->xmlend) - return; - } - if(p->endeltfunc) - p->endeltfunc(p->data, elementname, i); - p->xml++; - } - } - else - { - p->xml++; - } - } -} - -/* the parser must be initialized before calling this function */ -void parsexml(struct xmlparser * parser) -{ - parser->xml = parser->xmlstart; - parser->xmlend = parser->xmlstart + parser->xmlsize; - parseelt(parser); -} - - diff --git a/libs/miniupnpc/minixml.h b/libs/miniupnpc/minixml.h deleted file mode 100644 index 857c70ee93..0000000000 --- a/libs/miniupnpc/minixml.h +++ /dev/null @@ -1,37 +0,0 @@ -/* $Id: minixml.h,v 1.6 2006/11/30 11:47:21 nanard Exp $ */ -/* minimal xml parser - * - * Project : miniupnp - * Website : http://miniupnp.free.fr/ - * Author : Thomas Bernard - * Copyright (c) 2005 Thomas Bernard - * This software is subject to the conditions detailed in the - * LICENCE file provided in this distribution. - * */ -#ifndef __MINIXML_H__ -#define __MINIXML_H__ -#define IS_WHITE_SPACE(c) ((c==' ') || (c=='\t') || (c=='\r') || (c=='\n')) - -/* if a callback function pointer is set to NULL, - * the function is not called */ -struct xmlparser { - const char *xmlstart; - const char *xmlend; - const char *xml; /* pointer to current character */ - int xmlsize; - void * data; - void (*starteltfunc) (void *, const char *, int); - void (*endeltfunc) (void *, const char *, int); - void (*datafunc) (void *, const char *, int); - void (*attfunc) (void *, const char *, int, const char *, int); -}; - -/* parsexml() - * the xmlparser structure must be initialized before the call - * the following structure members have to be initialized : - * xmlstart, xmlsize, data, *func - * xml is for internal usage, xmlend is computed automatically */ -void parsexml(struct xmlparser *); - -#endif - diff --git a/libs/miniupnpc/minixmlvalid.c b/libs/miniupnpc/minixmlvalid.c deleted file mode 100644 index e7967befad..0000000000 --- a/libs/miniupnpc/minixmlvalid.c +++ /dev/null @@ -1,149 +0,0 @@ -/* $Id: minixmlvalid.c,v 1.2 2006/11/30 11:31:55 nanard Exp $ */ -/* MiniUPnP Project - * http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/ - * minixmlvalid.c : - * validation program for the minixml parser - * - * (c) 2006 Thomas Bernard */ - -#include -#include -#include -#include "minixml.h" - -/* xml event structure */ -struct event { - enum { ELTSTART, ELTEND, ATT, CHARDATA } type; - const char * data; - int len; -}; - -struct eventlist { - int n; - struct event * events; -}; - -/* compare 2 xml event lists - * return 0 if the two lists are equals */ -int evtlistcmp(struct eventlist * a, struct eventlist * b) -{ - int i; - struct event * ae, * be; - if(a->n != b->n) - return 1; - for(i=0; in; i++) - { - ae = a->events + i; - be = b->events + i; - if( (ae->type != be->type) - ||(ae->len != be->len) - ||memcmp(ae->data, be->data, ae->len)) - { - printf("Found a difference : %d '%.*s' != %d '%.*s'\n", - ae->type, ae->len, ae->data, - be->type, be->len, be->data); - return 1; - } - } - return 0; -} - -/* Test data */ -static const char xmldata[] = -"\n" -" " -"character data" -" \n \t" -"" -" \tchardata1chardata2" -""; - -static const struct event evtref[] = -{ - {ELTSTART, "xmlroot", 7}, - {ELTSTART, "elt1", 4}, - /* attributes */ - {CHARDATA, "character data", 14}, - {ELTEND, "elt1", 4}, - {ELTSTART, "elt1b", 5}, - {ELTSTART, "elt2a", 5}, - {ELTSTART, "elt2b", 5}, - {CHARDATA, "chardata1", 9}, - {ELTEND, "elt2b", 5}, - {ELTSTART, "elt2b", 5}, - {CHARDATA, "chardata2", 9}, - {ELTEND, "elt2b", 5}, - {ELTEND, "elt2a", 5}, - {ELTEND, "xmlroot", 7} -}; - -void startelt(void * data, const char * p, int l) -{ - struct eventlist * evtlist = data; - struct event * evt; - evt = evtlist->events + evtlist->n; - /*printf("startelt : %.*s\n", l, p);*/ - evt->type = ELTSTART; - evt->data = p; - evt->len = l; - evtlist->n++; -} - -void endelt(void * data, const char * p, int l) -{ - struct eventlist * evtlist = data; - struct event * evt; - evt = evtlist->events + evtlist->n; - /*printf("endelt : %.*s\n", l, p);*/ - evt->type = ELTEND; - evt->data = p; - evt->len = l; - evtlist->n++; -} - -void chardata(void * data, const char * p, int l) -{ - struct eventlist * evtlist = data; - struct event * evt; - evt = evtlist->events + evtlist->n; - /*printf("chardata : '%.*s'\n", l, p);*/ - evt->type = CHARDATA; - evt->data = p; - evt->len = l; - evtlist->n++; -} - -int testxmlparser(const char * xml, int size) -{ - int r; - struct eventlist evtlist; - struct eventlist evtlistref; - struct xmlparser parser; - evtlist.n = 0; - evtlist.events = malloc(sizeof(struct event)*100); - memset(&parser, 0, sizeof(parser)); - parser.xmlstart = xml; - parser.xmlsize = size; - parser.data = &evtlist; - parser.starteltfunc = startelt; - parser.endeltfunc = endelt; - parser.datafunc = chardata; - parsexml(&parser); - printf("%d events\n", evtlist.n); - /* compare */ - evtlistref.n = sizeof(evtref)/sizeof(struct event); - evtlistref.events = (struct event *)evtref; - r = evtlistcmp(&evtlistref, &evtlist); - free(evtlist.events); - return r; -} - -int main(int argc, char * * argv) -{ - int r; - r = testxmlparser(xmldata, sizeof(xmldata)-1); - if(r) - printf("minixml validation test failed\n"); - return r; -} - diff --git a/libs/miniupnpc/pymoduletest.py b/libs/miniupnpc/pymoduletest.py deleted file mode 100644 index d35a3b0921..0000000000 --- a/libs/miniupnpc/pymoduletest.py +++ /dev/null @@ -1,52 +0,0 @@ -#! /usr/bin/python -# MiniUPnP project -# Author : Thomas Bernard -# This Sample code is public domain. -# website : http://miniupnp.tuxfamily.org/ - -# import the python miniupnpc module -import miniupnpc -import sys - -# create the object -u = miniupnpc.UPnP() -print 'inital(default) values :' -print ' discoverdelay', u.discoverdelay -print ' lanaddr', u.lanaddr -print ' multicastif', u.multicastif -print ' minissdpdsocket', u.minissdpdsocket -u.discoverdelay = 200; -#u.minissdpdsocket = '../minissdpd/minissdpd.sock' -# discovery process, it usualy takes several seconds (2 seconds or more) -print 'Discovering... delay=%ums' % u.discoverdelay -print u.discover(), 'device(s) detected' -# select an igd -try: - u.selectigd() -except Exception, e: - print 'Exception :', e - sys.exit(1) -# display information about the IGD and the internet connection -print 'local ip address :', u.lanaddr -print 'external ip address :', u.externalipaddress() -print u.statusinfo(), u.connectiontype() - -#print u.addportmapping(64000, 'TCP', -# '192.168.1.166', 63000, 'port mapping test', '') -#print u.deleteportmapping(64000, 'TCP') - -port = 0 -proto = 'UDP' -# list the redirections : -i = 0 -while True: - p = u.getgenericportmapping(i) - if p==None: - break - print i, p - (port, proto, (ihost,iport), desc, c, d, e) = p - #print port, desc - i = i + 1 - -print u.getspecificportmapping(port, proto) - diff --git a/libs/miniupnpc/setup.py b/libs/miniupnpc/setup.py deleted file mode 100644 index 8ecb5f392b..0000000000 --- a/libs/miniupnpc/setup.py +++ /dev/null @@ -1,15 +0,0 @@ -#! /usr/bin/python -# $Id: setup.py,v 1.3 2009/04/17 20:59:42 nanard Exp $ -# the MiniUPnP Project (c) 2007 Thomas Bernard -# http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/ -# -# python script to build the miniupnpc module under unix -# -# replace libminiupnpc.a by libminiupnpc.so for shared library usage -from distutils.core import setup, Extension -setup(name="miniupnpc", version="1.3", - ext_modules=[ - Extension(name="miniupnpc", sources=["miniupnpcmodule.c"], - extra_objects=["libminiupnpc.a"]) - ]) - diff --git a/libs/miniupnpc/setupmingw32.py b/libs/miniupnpc/setupmingw32.py deleted file mode 100755 index 62433e4ac9..0000000000 --- a/libs/miniupnpc/setupmingw32.py +++ /dev/null @@ -1,15 +0,0 @@ -#! /usr/bin/python -# $Id: setupmingw32.py,v 1.1 2007/06/12 23:04:13 nanard Exp $ -# the MiniUPnP Project (c) 2007 Thomas Bernard -# http://miniupnp.tuxfamily.org/ or http://miniupnp.free.fr/ -# -# python script to build the miniupnpc module under unix -# -from distutils.core import setup, Extension -setup(name="miniupnpc", version="1.0-RC6", - ext_modules=[ - Extension(name="miniupnpc", sources=["miniupnpcmodule.c"], - libraries=["ws2_32"], - extra_objects=["libminiupnpc.a"]) - ]) - diff --git a/libs/miniupnpc/testigddescparse.c b/libs/miniupnpc/testigddescparse.c deleted file mode 100644 index 527f5e1117..0000000000 --- a/libs/miniupnpc/testigddescparse.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $Id: testigddescparse.c,v 1.1 2008/04/23 11:53:45 nanard Exp $ */ -/* Project : miniupnp - * http://miniupnp.free.fr/ - * Author : Thomas Bernard - * Copyright (c) 2008 Thomas Bernard - * This software is subject to the conditions detailed in the - * LICENCE file provided in this distribution. - * */ -#include -#include -#include -#include "igd_desc_parse.h" -#include "minixml.h" - -int test_igd_desc_parse(char * buffer, int len) -{ - struct IGDdatas igd; - struct xmlparser parser; - memset(&igd, 0, sizeof(struct IGDdatas)); - memset(&parser, 0, sizeof(struct xmlparser)); - parser.xmlstart = buffer; - parser.xmlsize = len; - parser.data = &igd; - parser.starteltfunc = IGDstartelt; - parser.endeltfunc = IGDendelt; - parser.datafunc = IGDdata; - parsexml(&parser); - printIGD(&igd); - return 0; -} - -int main(int argc, char * * argv) -{ - FILE * f; - char * buffer; - int len; - int r = 0; - if(argc<2) { - fprintf(stderr, "Usage: %s file.xml\n", argv[0]); - return 1; - } - f = fopen(argv[1], "r"); - if(!f) { - fprintf(stderr, "Cannot open %s for reading.\n", argv[1]); - return 1; - } - fseek(f, 0, SEEK_END); - len = ftell(f); - fseek(f, 0, SEEK_SET); - buffer = malloc(len); - fread(buffer, 1, len, f); - fclose(f); - r = test_igd_desc_parse(buffer, len); - free(buffer); - return r; -} - diff --git a/libs/miniupnpc/testminixml.c b/libs/miniupnpc/testminixml.c deleted file mode 100644 index 3d82527b77..0000000000 --- a/libs/miniupnpc/testminixml.c +++ /dev/null @@ -1,88 +0,0 @@ -/* $Id: testminixml.c,v 1.6 2006/11/19 22:32:35 nanard Exp $ - * testminixml.c - * test program for the "minixml" functions. - * Author : Thomas Bernard. - */ -#include -#include -#include -#include "minixml.h" -#include "igd_desc_parse.h" - -#ifdef WIN32 -#define NO_BZERO -#endif - -#ifdef NO_BZERO -#define bzero(p, n) memset(p, 0, n) -#endif - -/* ---------------------------------------------------------------------- */ -void printeltname1(void * d, const char * name, int l) -{ - int i; - printf("element "); - for(i=0;i %s port %u TCP' % (externalipaddress, eport, u.lanaddr, httpd.server_port) - - b = u.addportmapping(eport, 'TCP', u.lanaddr, httpd.server_port, - 'UPnP IGD Tester port %u' % eport, '') - if b: - print 'Success. Now waiting for some HTTP request on http://%s:%u' % (externalipaddress ,eport) - try: - httpd.handle_request() - httpd.server_close() - except KeyboardInterrupt, details: - print "CTRL-C exception!", details - b = u.deleteportmapping(eport, 'TCP') - if b: - print 'Successfully deleted port mapping' - else: - print 'Failed to remove port mapping' - else: - print 'Failed' - - httpd.server_close() - -except Exception, e: - print 'Exception :', e diff --git a/libs/miniupnpc/testupnpreplyparse.c b/libs/miniupnpc/testupnpreplyparse.c deleted file mode 100644 index a02e8f6a62..0000000000 --- a/libs/miniupnpc/testupnpreplyparse.c +++ /dev/null @@ -1,44 +0,0 @@ -/* $Id: testupnpreplyparse.c,v 1.2 2008/02/21 13:05:27 nanard Exp $ */ -/* MiniUPnP project - * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006-2007 Thomas Bernard - * This software is subject to the conditions detailed - * in the LICENCE file provided within the distribution */ -#include -#include -#include "upnpreplyparse.h" - -void -test_parsing(const char * buf, int len) -{ - struct NameValueParserData pdata; - ParseNameValue(buf, len, &pdata); - ClearNameValueList(&pdata); -} - -int main(int argc, char * * argv) -{ - FILE * f; - char buffer[4096]; - int l; - if(argc<2) - { - fprintf(stderr, "Usage: %s file.xml\n", argv[0]); - return 1; - } - f = fopen(argv[1], "r"); - if(!f) - { - fprintf(stderr, "Error : can not open file %s\n", argv[1]); - return 2; - } - l = fread(buffer, 1, sizeof(buffer)-1, f); - fclose(f); - buffer[l] = '\0'; -#ifdef DEBUG - DisplayNameValueList(buffer, l); -#endif - test_parsing(buffer, l); - return 0; -} - diff --git a/libs/miniupnpc/updateminiupnpcstrings.sh b/libs/miniupnpc/updateminiupnpcstrings.sh deleted file mode 100755 index c120811a62..0000000000 --- a/libs/miniupnpc/updateminiupnpcstrings.sh +++ /dev/null @@ -1,36 +0,0 @@ -#! /bin/sh -# $Id: updateminiupnpcstrings.sh,v 1.1 2008/10/11 16:39:29 nanard Exp $ - -FILE=miniupnpcstrings.h - -# detecting the OS name and version -OS_NAME=`uname -s` -OS_VERSION=`uname -r` -if [ -f /etc/debian_version ]; then - OS_NAME=Debian - OS_VERSION=`cat /etc/debian_version` -fi -# use lsb_release (Linux Standard Base) when available -LSB_RELEASE=`which lsb_release` -if [ 0 -eq $? ]; then - OS_NAME=`${LSB_RELEASE} -i -s` - OS_VERSION=`${LSB_RELEASE} -r -s` - case $OS_NAME in - Debian) - #OS_VERSION=`${LSB_RELEASE} -c -s` - ;; - Ubuntu) - #OS_VERSION=`${LSB_RELEASE} -c -s` - ;; - esac -fi - -echo "Detected OS [$OS_NAME] version [$OS_VERSION]" - -EXPR="s/OS_STRING\s\".*\"/OS_STRING \"${OS_NAME}\/${OS_VERSION}\"/" -#echo $EXPR -echo "Backuping $FILE to $FILE.bak." -cp $FILE $FILE.bak -echo "setting OS_STRING macro value to ${OS_NAME}/${OS_VERSION} in $FILE." -cat $FILE.bak | sed -e "$EXPR" > $FILE - diff --git a/libs/miniupnpc/upnpc.c b/libs/miniupnpc/upnpc.c deleted file mode 100644 index 2c5debe311..0000000000 --- a/libs/miniupnpc/upnpc.c +++ /dev/null @@ -1,374 +0,0 @@ -/* $Id: upnpc.c,v 1.65 2008/10/14 18:05:27 nanard Exp $ */ -/* Project : miniupnp - * Author : Thomas Bernard - * Copyright (c) 2005-2008 Thomas Bernard - * This software is subject to the conditions detailed in the - * LICENCE file provided in this distribution. - * */ -#include -#include -#include -#ifdef WIN32 -#include -#define snprintf _snprintf -#endif -#include "miniwget.h" -#include "miniupnpc.h" -#include "upnpcommands.h" -#include "upnperrors.h" - -/* protofix() checks if protocol is "UDP" or "TCP" - * returns NULL if not */ -const char * protofix(const char * proto) -{ - static const char proto_tcp[4] = { 'T', 'C', 'P', 0}; - static const char proto_udp[4] = { 'U', 'D', 'P', 0}; - int i, b; - for(i=0, b=1; i<4; i++) - b = b && ( (proto[i] == proto_tcp[i]) - || (proto[i] == (proto_tcp[i] | 32)) ); - if(b) - return proto_tcp; - for(i=0, b=1; i<4; i++) - b = b && ( (proto[i] == proto_udp[i]) - || (proto[i] == (proto_udp[i] | 32)) ); - if(b) - return proto_udp; - return 0; -} - -static void DisplayInfos(struct UPNPUrls * urls, - struct IGDdatas * data) -{ - char externalIPAddress[16]; - char connectionType[64]; - char status[64]; - char lastconnerr[64]; - unsigned int uptime; - unsigned int brUp, brDown; - int r; - UPNP_GetConnectionTypeInfo(urls->controlURL, - data->servicetype, - connectionType); - if(connectionType[0]) - printf("Connection Type : %s\n", connectionType); - else - printf("GetConnectionTypeInfo failed.\n"); - UPNP_GetStatusInfo(urls->controlURL, data->servicetype, - status, &uptime, lastconnerr); - printf("Status : %s, uptime=%u, LastConnectionError : %s\n", - status, uptime, lastconnerr); - UPNP_GetLinkLayerMaxBitRates(urls->controlURL_CIF, data->servicetype_CIF, - &brDown, &brUp); - printf("MaxBitRateDown : %u bps MaxBitRateUp %u bps\n", brDown, brUp); - r = UPNP_GetExternalIPAddress(urls->controlURL, - data->servicetype, - externalIPAddress); - if(r != UPNPCOMMAND_SUCCESS) - printf("GetExternalIPAddress() returned %d\n", r); - if(externalIPAddress[0]) - printf("ExternalIPAddress = %s\n", externalIPAddress); - else - printf("GetExternalIPAddress failed.\n"); -} - -static void GetConnectionStatus(struct UPNPUrls * urls, - struct IGDdatas * data) -{ - unsigned int bytessent, bytesreceived, packetsreceived, packetssent; - DisplayInfos(urls, data); - bytessent = UPNP_GetTotalBytesSent(urls->controlURL_CIF, data->servicetype_CIF); - bytesreceived = UPNP_GetTotalBytesReceived(urls->controlURL_CIF, data->servicetype_CIF); - packetssent = UPNP_GetTotalPacketsSent(urls->controlURL_CIF, data->servicetype_CIF); - packetsreceived = UPNP_GetTotalPacketsReceived(urls->controlURL_CIF, data->servicetype_CIF); - printf("Bytes: Sent: %8u\tRecv: %8u\n", bytessent, bytesreceived); - printf("Packets: Sent: %8u\tRecv: %8u\n", packetssent, packetsreceived); -} - -static void ListRedirections(struct UPNPUrls * urls, - struct IGDdatas * data) -{ - int r; - int i = 0; - char index[6]; - char intClient[16]; - char intPort[6]; - char extPort[6]; - char protocol[4]; - char desc[80]; - char enabled[6]; - char rHost[64]; - char duration[16]; - /*unsigned int num=0; - UPNP_GetPortMappingNumberOfEntries(urls->controlURL, data->servicetype, &num); - printf("PortMappingNumberOfEntries : %u\n", num);*/ - do { - snprintf(index, 6, "%d", i); - rHost[0] = '\0'; enabled[0] = '\0'; - duration[0] = '\0'; desc[0] = '\0'; - extPort[0] = '\0'; intPort[0] = '\0'; intClient[0] = '\0'; - r = UPNP_GetGenericPortMappingEntry(urls->controlURL, data->servicetype, - index, - extPort, intClient, intPort, - protocol, desc, enabled, - rHost, duration); - if(r==0) - /* - printf("%02d - %s %s->%s:%s\tenabled=%s leaseDuration=%s\n" - " desc='%s' rHost='%s'\n", - i, protocol, extPort, intClient, intPort, - enabled, duration, - desc, rHost); - */ - printf("%2d %s %5s->%s:%-5s '%s' '%s'\n", - i, protocol, extPort, intClient, intPort, - desc, rHost); - else - printf("GetGenericPortMappingEntry() returned %d (%s)\n", - r, strupnperror(r)); - i++; - } while(r==0); -} - -/* Test function - * 1 - get connection type - * 2 - get extenal ip address - * 3 - Add port mapping - * 4 - get this port mapping from the IGD */ -static void SetRedirectAndTest(struct UPNPUrls * urls, - struct IGDdatas * data, - const char * iaddr, - const char * iport, - const char * eport, - const char * proto) -{ - char externalIPAddress[16]; - char intClient[16]; - char intPort[6]; - int r; - - if(!iaddr || !iport || !eport || !proto) - { - fprintf(stderr, "Wrong arguments\n"); - return; - } - proto = protofix(proto); - if(!proto) - { - fprintf(stderr, "invalid protocol\n"); - return; - } - - UPNP_GetExternalIPAddress(urls->controlURL, - data->servicetype, - externalIPAddress); - if(externalIPAddress[0]) - printf("ExternalIPAddress = %s\n", externalIPAddress); - else - printf("GetExternalIPAddress failed.\n"); - - r = UPNP_AddPortMapping(urls->controlURL, data->servicetype, - eport, iport, iaddr, 0, proto, 0); - if(r!=UPNPCOMMAND_SUCCESS) - printf("AddPortMapping(%s, %s, %s) failed with code %d\n", - eport, iport, iaddr, r); - - r = UPNP_GetSpecificPortMappingEntry(urls->controlURL, - data->servicetype, - eport, proto, - intClient, intPort); - if(r!=UPNPCOMMAND_SUCCESS) - printf("GetSpecificPortMappingEntry() failed with code %d\n", r); - - if(intClient[0]) { - printf("InternalIP:Port = %s:%s\n", intClient, intPort); - printf("external %s:%s %s is redirected to internal %s:%s\n", - externalIPAddress, eport, proto, intClient, intPort); - } -} - -static void -RemoveRedirect(struct UPNPUrls * urls, - struct IGDdatas * data, - const char * eport, - const char * proto) -{ - int r; - if(!proto || !eport) - { - fprintf(stderr, "invalid arguments\n"); - return; - } - proto = protofix(proto); - if(!proto) - { - fprintf(stderr, "protocol invalid\n"); - return; - } - r = UPNP_DeletePortMapping(urls->controlURL, data->servicetype, eport, proto, 0); - printf("UPNP_DeletePortMapping() returned : %d\n", r); -} - - -/* sample upnp client program */ -int main(int argc, char ** argv) -{ - char command = 0; - char ** commandargv = 0; - int commandargc = 0; - struct UPNPDev * devlist = 0; - char lanaddr[16]; /* my ip address on the LAN */ - int i; - const char * rootdescurl = 0; - const char * multicastif = 0; - const char * minissdpdpath = 0; - -#ifdef WIN32 - WSADATA wsaData; - int nResult = WSAStartup(MAKEWORD(2,2), &wsaData); - if(nResult != NO_ERROR) - { - fprintf(stderr, "WSAStartup() failed.\n"); - return -1; - } -#endif - printf("upnpc : miniupnpc library test client. (c) 2006-2008 Thomas Bernard\n"); - printf("Go to http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/\n" - "for more information.\n"); - /* command line processing */ - for(i=1; ipNext) - { - printf(" desc: %s\n st: %s\n\n", - device->descURL, device->st); - } - } - i = 1; - if( (rootdescurl && UPNP_GetIGDFromUrl(rootdescurl, &urls, &data, lanaddr, sizeof(lanaddr))) - || (i = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr)))) - { - switch(i) { - case 1: - printf("Found valid IGD : %s\n", urls.controlURL); - break; - case 2: - printf("Found a (not connected?) IGD : %s\n", urls.controlURL); - printf("Trying to continue anyway\n"); - break; - case 3: - printf("UPnP device found. Is it an IGD ? : %s\n", urls.controlURL); - printf("Trying to continue anyway\n"); - break; - default: - printf("Found device (igd ?) : %s\n", urls.controlURL); - printf("Trying to continue anyway\n"); - } - printf("Local LAN ip address : %s\n", lanaddr); - #if 0 - printf("getting \"%s\"\n", urls.ipcondescURL); - descXML = miniwget(urls.ipcondescURL, &descXMLsize); - if(descXML) - { - /*fwrite(descXML, 1, descXMLsize, stdout);*/ - free(descXML); descXML = NULL; - } - #endif - - switch(command) - { - case 'l': - DisplayInfos(&urls, &data); - ListRedirections(&urls, &data); - break; - case 'a': - SetRedirectAndTest(&urls, &data, - commandargv[0], commandargv[1], - commandargv[2], commandargv[3]); - break; - case 'd': - RemoveRedirect(&urls, &data, commandargv[0], commandargv[1]); - break; - case 's': - GetConnectionStatus(&urls, &data); - break; - case 'r': - for(i=0; i -#include -#include -#include "upnpcommands.h" -#include "miniupnpc.h" - -static UNSIGNED_INTEGER -my_atoui(const char * s) -{ - return s ? ((UNSIGNED_INTEGER)STRTOUI(s, NULL, 0)) : 0; -} - -/* - * */ -UNSIGNED_INTEGER -UPNP_GetTotalBytesSent(const char * controlURL, - const char * servicetype) -{ - struct NameValueParserData pdata; - char buffer[4096]; - int bufsize = 4096; - unsigned int r = 0; - char * p; - simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalBytesSent", 0, buffer, &bufsize); - ParseNameValue(buffer, bufsize, &pdata); - /*DisplayNameValueList(buffer, bufsize);*/ - p = GetValueFromNameValueList(&pdata, "NewTotalBytesSent"); - r = my_atoui(p); - ClearNameValueList(&pdata); - return r; -} - -/* - * */ -UNSIGNED_INTEGER -UPNP_GetTotalBytesReceived(const char * controlURL, - const char * servicetype) -{ - struct NameValueParserData pdata; - char buffer[4096]; - int bufsize = 4096; - unsigned int r = 0; - char * p; - simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalBytesReceived", 0, buffer, &bufsize); - ParseNameValue(buffer, bufsize, &pdata); - /*DisplayNameValueList(buffer, bufsize);*/ - p = GetValueFromNameValueList(&pdata, "NewTotalBytesReceived"); - r = my_atoui(p); - ClearNameValueList(&pdata); - return r; -} - -/* - * */ -UNSIGNED_INTEGER -UPNP_GetTotalPacketsSent(const char * controlURL, - const char * servicetype) -{ - struct NameValueParserData pdata; - char buffer[4096]; - int bufsize = 4096; - unsigned int r = 0; - char * p; - simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalPacketsSent", 0, buffer, &bufsize); - ParseNameValue(buffer, bufsize, &pdata); - /*DisplayNameValueList(buffer, bufsize);*/ - p = GetValueFromNameValueList(&pdata, "NewTotalPacketsSent"); - r = my_atoui(p); - ClearNameValueList(&pdata); - return r; -} - -/* - * */ -UNSIGNED_INTEGER -UPNP_GetTotalPacketsReceived(const char * controlURL, - const char * servicetype) -{ - struct NameValueParserData pdata; - char buffer[4096]; - int bufsize = 4096; - unsigned int r = 0; - char * p; - simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalPacketsReceived", 0, buffer, &bufsize); - ParseNameValue(buffer, bufsize, &pdata); - /*DisplayNameValueList(buffer, bufsize);*/ - p = GetValueFromNameValueList(&pdata, "NewTotalPacketsReceived"); - r = my_atoui(p); - ClearNameValueList(&pdata); - return r; -} - -/* UPNP_GetStatusInfo() call the corresponding UPNP method - * returns the current status and uptime */ -int UPNP_GetStatusInfo(const char * controlURL, - const char * servicetype, - char * status, - unsigned int * uptime, - char * lastconnerror) -{ - struct NameValueParserData pdata; - char buffer[4096]; - int bufsize = 4096; - char * p; - char * up; - char * err; - int ret = UPNPCOMMAND_UNKNOWN_ERROR; - - if(!status && !uptime) - return UPNPCOMMAND_INVALID_ARGS; - - simpleUPnPcommand(-1, controlURL, servicetype, "GetStatusInfo", 0, buffer, &bufsize); - ParseNameValue(buffer, bufsize, &pdata); - /*DisplayNameValueList(buffer, bufsize);*/ - up = GetValueFromNameValueList(&pdata, "NewUptime"); - p = GetValueFromNameValueList(&pdata, "NewConnectionStatus"); - err = GetValueFromNameValueList(&pdata, "NewLastConnectionError"); - if(p && up) - ret = UPNPCOMMAND_SUCCESS; - - if(status) { - if(p){ - strncpy(status, p, 64 ); - status[63] = '\0'; - }else - status[0]= '\0'; - } - - if(uptime) { - if(up) - sscanf(up,"%u",uptime); - else - uptime = 0; - } - - if(lastconnerror) { - if(err) { - strncpy(lastconnerror, err, 64 ); - lastconnerror[63] = '\0'; - } else - lastconnerror[0] = '\0'; - } - - p = GetValueFromNameValueList(&pdata, "errorCode"); - if(p) { - ret = UPNPCOMMAND_UNKNOWN_ERROR; - sscanf(p, "%d", &ret); - } - ClearNameValueList(&pdata); - return ret; -} - -/* UPNP_GetConnectionTypeInfo() call the corresponding UPNP method - * returns the connection type */ -int UPNP_GetConnectionTypeInfo(const char * controlURL, - const char * servicetype, - char * connectionType) -{ - struct NameValueParserData pdata; - char buffer[4096]; - int bufsize = 4096; - char * p; - int ret = UPNPCOMMAND_UNKNOWN_ERROR; - - if(!connectionType) - return UPNPCOMMAND_INVALID_ARGS; - - simpleUPnPcommand(-1, controlURL, servicetype, - "GetConnectionTypeInfo", 0, buffer, &bufsize); - ParseNameValue(buffer, bufsize, &pdata); - p = GetValueFromNameValueList(&pdata, "NewConnectionType"); - /*p = GetValueFromNameValueList(&pdata, "NewPossibleConnectionTypes");*/ - /* PossibleConnectionTypes will have several values.... */ - if(p) { - strncpy(connectionType, p, 64 ); - connectionType[63] = '\0'; - ret = UPNPCOMMAND_SUCCESS; - } else - connectionType[0] = '\0'; - p = GetValueFromNameValueList(&pdata, "errorCode"); - if(p) { - ret = UPNPCOMMAND_UNKNOWN_ERROR; - sscanf(p, "%d", &ret); - } - ClearNameValueList(&pdata); - return ret; -} - -/* UPNP_GetLinkLayerMaxBitRate() call the corresponding UPNP method. - * Returns 2 values: Downloadlink bandwidth and Uplink bandwidth. - * One of the values can be null - * Note : GetLinkLayerMaxBitRates belongs to WANPPPConnection:1 only - * We can use the GetCommonLinkProperties from WANCommonInterfaceConfig:1 */ -int UPNP_GetLinkLayerMaxBitRates(const char * controlURL, const char * servicetype, unsigned int * bitrateDown, unsigned int* bitrateUp) -{ - struct NameValueParserData pdata; - char buffer[4096]; - int bufsize = 4096; - int ret = UPNPCOMMAND_UNKNOWN_ERROR; - char * down; - char * up; - char * p; - - if(!bitrateDown && !bitrateUp) - return UPNPCOMMAND_INVALID_ARGS; - - /* shouldn't we use GetCommonLinkProperties ? */ - simpleUPnPcommand(-1, controlURL, servicetype, - "GetCommonLinkProperties", 0, buffer, &bufsize); - /*"GetLinkLayerMaxBitRates", 0, buffer, &bufsize);*/ - /*DisplayNameValueList(buffer, bufsize);*/ - ParseNameValue(buffer, bufsize, &pdata); - /*down = GetValueFromNameValueList(&pdata, "NewDownstreamMaxBitRate");*/ - /*up = GetValueFromNameValueList(&pdata, "NewUpstreamMaxBitRate");*/ - down = GetValueFromNameValueList(&pdata, "NewLayer1DownstreamMaxBitRate"); - up = GetValueFromNameValueList(&pdata, "NewLayer1UpstreamMaxBitRate"); - /*GetValueFromNameValueList(&pdata, "NewWANAccessType");*/ - /*GetValueFromNameValueList(&pdata, "NewPhysicalLinkSatus");*/ - if(down && up) - ret = UPNPCOMMAND_SUCCESS; - - if(bitrateDown) - { - if(down) - sscanf(down,"%u",bitrateDown); - else - *bitrateDown = 0; - } - - if(bitrateUp) - { - if(up) - sscanf(up,"%u",bitrateUp); - else - *bitrateUp = 0; - } - p = GetValueFromNameValueList(&pdata, "errorCode"); - if(p) { - ret = UPNPCOMMAND_UNKNOWN_ERROR; - sscanf(p, "%d", &ret); - } - ClearNameValueList(&pdata); - return ret; -} - - -/* UPNP_GetExternalIPAddress() call the corresponding UPNP method. - * if the third arg is not null the value is copied to it. - * at least 16 bytes must be available - * - * Return values : - * 0 : SUCCESS - * NON ZERO : ERROR Either an UPnP error code or an unknown error. - * - * 402 Invalid Args - See UPnP Device Architecture section on Control. - * 501 Action Failed - See UPnP Device Architecture section on Control. - */ -int UPNP_GetExternalIPAddress(const char * controlURL, - const char * servicetype, - char * extIpAdd) -{ - struct NameValueParserData pdata; - char buffer[4096]; - int bufsize = 4096; - char * p; - int ret = UPNPCOMMAND_UNKNOWN_ERROR; - - if(!extIpAdd || !controlURL || !servicetype) - return UPNPCOMMAND_INVALID_ARGS; - - simpleUPnPcommand(-1, controlURL, servicetype, "GetExternalIPAddress", 0, buffer, &bufsize); - /*DisplayNameValueList(buffer, bufsize);*/ - ParseNameValue(buffer, bufsize, &pdata); - /*printf("external ip = %s\n", GetValueFromNameValueList(&pdata, "NewExternalIPAddress") );*/ - p = GetValueFromNameValueList(&pdata, "NewExternalIPAddress"); - if(p) { - strncpy(extIpAdd, p, 16 ); - extIpAdd[15] = '\0'; - ret = UPNPCOMMAND_SUCCESS; - } else - extIpAdd[0] = '\0'; - - p = GetValueFromNameValueList(&pdata, "errorCode"); - if(p) { - ret = UPNPCOMMAND_UNKNOWN_ERROR; - sscanf(p, "%d", &ret); - } - - ClearNameValueList(&pdata); - return ret; -} - -int -UPNP_AddPortMapping(const char * controlURL, const char * servicetype, - const char * extPort, - const char * inPort, - const char * inClient, - const char * desc, - const char * proto, - const char * remoteHost) -{ - struct UPNParg * AddPortMappingArgs; - char buffer[4096]; - int bufsize = 4096; - struct NameValueParserData pdata; - const char * resVal; - int ret; - - if(!inPort || !inClient || !proto || !extPort) - return UPNPCOMMAND_INVALID_ARGS; - - AddPortMappingArgs = calloc(9, sizeof(struct UPNParg)); - AddPortMappingArgs[0].elt = "NewRemoteHost"; - AddPortMappingArgs[0].val = remoteHost; - AddPortMappingArgs[1].elt = "NewExternalPort"; - AddPortMappingArgs[1].val = extPort; - AddPortMappingArgs[2].elt = "NewProtocol"; - AddPortMappingArgs[2].val = proto; - AddPortMappingArgs[3].elt = "NewInternalPort"; - AddPortMappingArgs[3].val = inPort; - AddPortMappingArgs[4].elt = "NewInternalClient"; - AddPortMappingArgs[4].val = inClient; - AddPortMappingArgs[5].elt = "NewEnabled"; - AddPortMappingArgs[5].val = "1"; - AddPortMappingArgs[6].elt = "NewPortMappingDescription"; - AddPortMappingArgs[6].val = desc?desc:"libminiupnpc"; - AddPortMappingArgs[7].elt = "NewLeaseDuration"; - AddPortMappingArgs[7].val = "0"; - simpleUPnPcommand(-1, controlURL, servicetype, "AddPortMapping", AddPortMappingArgs, buffer, &bufsize); - /*DisplayNameValueList(buffer, bufsize);*/ - /*buffer[bufsize] = '\0';*/ - /*puts(buffer);*/ - ParseNameValue(buffer, bufsize, &pdata); - resVal = GetValueFromNameValueList(&pdata, "errorCode"); - if(resVal) { - /*printf("AddPortMapping errorCode = '%s'\n", resVal); */ - ret = UPNPCOMMAND_UNKNOWN_ERROR; - sscanf(resVal, "%d", &ret); - } else { - ret = UPNPCOMMAND_SUCCESS; - } - ClearNameValueList(&pdata); - free(AddPortMappingArgs); - return ret; -} - -int -UPNP_DeletePortMapping(const char * controlURL, const char * servicetype, - const char * extPort, const char * proto, - const char * remoteHost) -{ - /*struct NameValueParserData pdata;*/ - struct UPNParg * DeletePortMappingArgs; - char buffer[4096]; - int bufsize = 4096; - struct NameValueParserData pdata; - const char * resVal; - int ret; - - if(!extPort || !proto) - return UPNPCOMMAND_INVALID_ARGS; - - DeletePortMappingArgs = calloc(4, sizeof(struct UPNParg)); - DeletePortMappingArgs[0].elt = "NewRemoteHost"; - DeletePortMappingArgs[0].val = remoteHost; - DeletePortMappingArgs[1].elt = "NewExternalPort"; - DeletePortMappingArgs[1].val = extPort; - DeletePortMappingArgs[2].elt = "NewProtocol"; - DeletePortMappingArgs[2].val = proto; - simpleUPnPcommand(-1, controlURL, servicetype, - "DeletePortMapping", - DeletePortMappingArgs, buffer, &bufsize); - /*DisplayNameValueList(buffer, bufsize);*/ - ParseNameValue(buffer, bufsize, &pdata); - resVal = GetValueFromNameValueList(&pdata, "errorCode"); - if(resVal) { - ret = UPNPCOMMAND_UNKNOWN_ERROR; - sscanf(resVal, "%d", &ret); - } else { - ret = UPNPCOMMAND_SUCCESS; - } - ClearNameValueList(&pdata); - free(DeletePortMappingArgs); - return ret; -} - -int UPNP_GetGenericPortMappingEntry(const char * controlURL, - const char * servicetype, - const char * index, - char * extPort, - char * intClient, - char * intPort, - char * protocol, - char * desc, - char * enabled, - char * rHost, - char * duration) -{ - struct NameValueParserData pdata; - struct UPNParg * GetPortMappingArgs; - char buffer[4096]; - int bufsize = 4096; - char * p; - int r = UPNPCOMMAND_UNKNOWN_ERROR; - if(!index) - return UPNPCOMMAND_INVALID_ARGS; - intClient[0] = '\0'; - intPort[0] = '\0'; - GetPortMappingArgs = calloc(2, sizeof(struct UPNParg)); - GetPortMappingArgs[0].elt = "NewPortMappingIndex"; - GetPortMappingArgs[0].val = index; - simpleUPnPcommand(-1, controlURL, servicetype, - "GetGenericPortMappingEntry", - GetPortMappingArgs, buffer, &bufsize); - ParseNameValue(buffer, bufsize, &pdata); - p = GetValueFromNameValueList(&pdata, "NewRemoteHost"); - if(p && rHost) - { - strncpy(rHost, p, 64); - rHost[63] = '\0'; - } - p = GetValueFromNameValueList(&pdata, "NewExternalPort"); - if(p && extPort) - { - strncpy(extPort, p, 6); - extPort[5] = '\0'; - r = UPNPCOMMAND_SUCCESS; - } - p = GetValueFromNameValueList(&pdata, "NewProtocol"); - if(p && protocol) - { - strncpy(protocol, p, 4); - protocol[3] = '\0'; - } - p = GetValueFromNameValueList(&pdata, "NewInternalClient"); - if(p && intClient) - { - strncpy(intClient, p, 16); - intClient[15] = '\0'; - r = 0; - } - p = GetValueFromNameValueList(&pdata, "NewInternalPort"); - if(p && intPort) - { - strncpy(intPort, p, 6); - intPort[5] = '\0'; - } - p = GetValueFromNameValueList(&pdata, "NewEnabled"); - if(p && enabled) - { - strncpy(enabled, p, 4); - enabled[3] = '\0'; - } - p = GetValueFromNameValueList(&pdata, "NewPortMappingDescription"); - if(p && desc) - { - strncpy(desc, p, 80); - desc[79] = '\0'; - } - p = GetValueFromNameValueList(&pdata, "NewLeaseDuration"); - if(p && duration) - { - strncpy(duration, p, 16); - duration[15] = '\0'; - } - p = GetValueFromNameValueList(&pdata, "errorCode"); - if(p) { - r = UPNPCOMMAND_UNKNOWN_ERROR; - sscanf(p, "%d", &r); - } - ClearNameValueList(&pdata); - free(GetPortMappingArgs); - return r; -} - -int UPNP_GetPortMappingNumberOfEntries(const char * controlURL, const char * servicetype, unsigned int * numEntries) -{ - struct NameValueParserData pdata; - char buffer[4096]; - int bufsize = 4096; - char* p; - int ret = UPNPCOMMAND_UNKNOWN_ERROR; - simpleUPnPcommand(-1, controlURL, servicetype, "GetPortMappingNumberOfEntries", 0, buffer, &bufsize); -#ifdef DEBUG - DisplayNameValueList(buffer, bufsize); -#endif - ParseNameValue(buffer, bufsize, &pdata); - - p = GetValueFromNameValueList(&pdata, "NewPortMappingNumberOfEntries"); - if(numEntries && p) { - *numEntries = 0; - sscanf(p, "%u", numEntries); - ret = UPNPCOMMAND_SUCCESS; - } - - p = GetValueFromNameValueList(&pdata, "errorCode"); - if(p) { - ret = UPNPCOMMAND_UNKNOWN_ERROR; - sscanf(p, "%d", &ret); - } - - ClearNameValueList(&pdata); - return ret; -} - -/* UPNP_GetSpecificPortMappingEntry retrieves an existing port mapping - * the result is returned in the intClient and intPort strings - * please provide 16 and 6 bytes of data */ -int -UPNP_GetSpecificPortMappingEntry(const char * controlURL, - const char * servicetype, - const char * extPort, - const char * proto, - char * intClient, - char * intPort) -{ - struct NameValueParserData pdata; - struct UPNParg * GetPortMappingArgs; - char buffer[4096]; - int bufsize = 4096; - char * p; - int ret = UPNPCOMMAND_UNKNOWN_ERROR; - - if(!intPort || !intClient || !extPort || !proto) - return UPNPCOMMAND_INVALID_ARGS; - - GetPortMappingArgs = calloc(4, sizeof(struct UPNParg)); - GetPortMappingArgs[0].elt = "NewRemoteHost"; - GetPortMappingArgs[1].elt = "NewExternalPort"; - GetPortMappingArgs[1].val = extPort; - GetPortMappingArgs[2].elt = "NewProtocol"; - GetPortMappingArgs[2].val = proto; - simpleUPnPcommand(-1, controlURL, servicetype, - "GetSpecificPortMappingEntry", - GetPortMappingArgs, buffer, &bufsize); - /*fd = simpleUPnPcommand(fd, controlURL, data.servicetype, "GetSpecificPortMappingEntry", AddPortMappingArgs, buffer, &bufsize); */ - /*DisplayNameValueList(buffer, bufsize);*/ - ParseNameValue(buffer, bufsize, &pdata); - - p = GetValueFromNameValueList(&pdata, "NewInternalClient"); - if(p) { - strncpy(intClient, p, 16); - intClient[15] = '\0'; - ret = UPNPCOMMAND_SUCCESS; - } else - intClient[0] = '\0'; - - p = GetValueFromNameValueList(&pdata, "NewInternalPort"); - if(p) { - strncpy(intPort, p, 6); - intPort[5] = '\0'; - } else - intPort[0] = '\0'; - - p = GetValueFromNameValueList(&pdata, "errorCode"); - if(p) { - ret = UPNPCOMMAND_UNKNOWN_ERROR; - sscanf(p, "%d", &ret); - } - - ClearNameValueList(&pdata); - free(GetPortMappingArgs); - return ret; -} - - diff --git a/libs/miniupnpc/upnpcommands.h b/libs/miniupnpc/upnpcommands.h deleted file mode 100644 index 217c472be2..0000000000 --- a/libs/miniupnpc/upnpcommands.h +++ /dev/null @@ -1,193 +0,0 @@ -/* $Id: upnpcommands.h,v 1.17 2009/04/17 21:21:19 nanard Exp $ */ -/* Miniupnp project : http://miniupnp.free.fr/ - * Author : Thomas Bernard - * Copyright (c) 2005-2008 Thomas Bernard - * This software is subject to the conditions detailed in the - * LICENCE file provided within this distribution */ -#ifndef __UPNPCOMMANDS_H__ -#define __UPNPCOMMANDS_H__ - -#include "upnpreplyparse.h" -#include "declspec.h" - -/* MiniUPnPc return codes : */ -#define UPNPCOMMAND_SUCCESS (0) -#define UPNPCOMMAND_UNKNOWN_ERROR (-1) -#define UPNPCOMMAND_INVALID_ARGS (-2) - -#ifdef __cplusplus -extern "C" { -#endif - -#if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) -#define UNSIGNED_INTEGER unsigned long long -#define STRTOUI strtoull -#else -#define UNSIGNED_INTEGER unsigned int -#define STRTOUI strtoul -#endif - -LIBSPEC UNSIGNED_INTEGER -UPNP_GetTotalBytesSent(const char * controlURL, - const char * servicetype); - -LIBSPEC UNSIGNED_INTEGER -UPNP_GetTotalBytesReceived(const char * controlURL, - const char * servicetype); - -LIBSPEC UNSIGNED_INTEGER -UPNP_GetTotalPacketsSent(const char * controlURL, - const char * servicetype); - -LIBSPEC UNSIGNED_INTEGER -UPNP_GetTotalPacketsReceived(const char * controlURL, - const char * servicetype); - -/* UPNP_GetStatusInfo() - * status and lastconnerror are 64 byte buffers - * Return values : - * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR - * or a UPnP Error code */ -LIBSPEC int -UPNP_GetStatusInfo(const char * controlURL, - const char * servicetype, - char * status, - unsigned int * uptime, - char * lastconnerror); - -/* UPNP_GetConnectionTypeInfo() - * argument connectionType is a 64 character buffer - * Return Values : - * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR - * or a UPnP Error code */ -LIBSPEC int -UPNP_GetConnectionTypeInfo(const char * controlURL, - const char * servicetype, - char * connectionType); - -/* UPNP_GetExternalIPAddress() call the corresponding UPNP method. - * if the third arg is not null the value is copied to it. - * at least 16 bytes must be available - * - * Return values : - * 0 : SUCCESS - * NON ZERO : ERROR Either an UPnP error code or an unknown error. - * - * possible UPnP Errors : - * 402 Invalid Args - See UPnP Device Architecture section on Control. - * 501 Action Failed - See UPnP Device Architecture section on Control. */ -LIBSPEC int -UPNP_GetExternalIPAddress(const char * controlURL, - const char * servicetype, - char * extIpAdd); - -/* UPNP_GetLinkLayerMaxBitRates() - * call WANCommonInterfaceConfig:1#GetCommonLinkProperties - * - * return values : - * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR - * or a UPnP Error Code. */ -LIBSPEC int -UPNP_GetLinkLayerMaxBitRates(const char* controlURL, - const char* servicetype, - unsigned int * bitrateDown, - unsigned int * bitrateUp); - -/* UPNP_AddPortMapping() - * if desc is NULL, it will be defaulted to "libminiupnpc" - * remoteHost is usually NULL because IGD don't support it. - * - * Return values : - * 0 : SUCCESS - * NON ZERO : ERROR. Either an UPnP error code or an unknown error. - * - * List of possible UPnP errors for AddPortMapping : - * errorCode errorDescription (short) - Description (long) - * 402 Invalid Args - See UPnP Device Architecture section on Control. - * 501 Action Failed - See UPnP Device Architecture section on Control. - * 715 WildCardNotPermittedInSrcIP - The source IP address cannot be - * wild-carded - * 716 WildCardNotPermittedInExtPort - The external port cannot be wild-carded - * 718 ConflictInMappingEntry - The port mapping entry specified conflicts - * with a mapping assigned previously to another client - * 724 SamePortValuesRequired - Internal and External port values - * must be the same - * 725 OnlyPermanentLeasesSupported - The NAT implementation only supports - * permanent lease times on port mappings - * 726 RemoteHostOnlySupportsWildcard - RemoteHost must be a wildcard - * and cannot be a specific IP address or DNS name - * 727 ExternalPortOnlySupportsWildcard - ExternalPort must be a wildcard and - * cannot be a specific port value */ -LIBSPEC int -UPNP_AddPortMapping(const char * controlURL, const char * servicetype, - const char * extPort, - const char * inPort, - const char * inClient, - const char * desc, - const char * proto, - const char * remoteHost); - -/* UPNP_DeletePortMapping() - * Use same argument values as what was used for AddPortMapping(). - * remoteHost is usually NULL because IGD don't support it. - * Return Values : - * 0 : SUCCESS - * NON ZERO : error. Either an UPnP error code or an undefined error. - * - * List of possible UPnP errors for DeletePortMapping : - * 402 Invalid Args - See UPnP Device Architecture section on Control. - * 714 NoSuchEntryInArray - The specified value does not exist in the array */ -LIBSPEC int -UPNP_DeletePortMapping(const char * controlURL, const char * servicetype, - const char * extPort, const char * proto, - const char * remoteHost); - -/* UPNP_GetPortMappingNumberOfEntries() - * not supported by all routers */ -LIBSPEC int -UPNP_GetPortMappingNumberOfEntries(const char* controlURL, const char* servicetype, unsigned int * num); - -/* UPNP_GetSpecificPortMappingEntry retrieves an existing port mapping - * the result is returned in the intClient and intPort strings - * please provide 16 and 6 bytes of data - * - * return value : - * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR - * or a UPnP Error Code. */ -LIBSPEC int -UPNP_GetSpecificPortMappingEntry(const char * controlURL, - const char * servicetype, - const char * extPort, - const char * proto, - char * intClient, - char * intPort); - -/* UPNP_GetGenericPortMappingEntry() - * - * return value : - * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR - * or a UPnP Error Code. - * - * Possible UPNP Error codes : - * 402 Invalid Args - See UPnP Device Architecture section on Control. - * 713 SpecifiedArrayIndexInvalid - The specified array index is out of bounds - */ -LIBSPEC int -UPNP_GetGenericPortMappingEntry(const char * controlURL, - const char * servicetype, - const char * index, - char * extPort, - char * intClient, - char * intPort, - char * protocol, - char * desc, - char * enabled, - char * rHost, - char * duration); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/libs/miniupnpc/upnperrors.c b/libs/miniupnpc/upnperrors.c deleted file mode 100644 index 8a05349b15..0000000000 --- a/libs/miniupnpc/upnperrors.c +++ /dev/null @@ -1,66 +0,0 @@ -/* $Id: upnperrors.c,v 1.3 2008/04/27 17:21:51 nanard Exp $ */ -/* Project : miniupnp - * Author : Thomas BERNARD - * copyright (c) 2007 Thomas Bernard - * All Right reserved. - * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * This software is subjet to the conditions detailed in the - * provided LICENCE file. */ -#include -#include "upnperrors.h" -#include "upnpcommands.h" - -const char * strupnperror(int err) -{ - const char * s = NULL; - switch(err) { - case UPNPCOMMAND_SUCCESS: - s = "Success"; - break; - case UPNPCOMMAND_UNKNOWN_ERROR: - s = "Miniupnpc Unknown Error"; - break; - case UPNPCOMMAND_INVALID_ARGS: - s = "Miniupnpc Invalid Arguments"; - break; - case 401: - s = "Invalid Action"; - break; - case 402: - s = "Invalid Args"; - break; - case 501: - s = "Action Failed"; - break; - case 713: - s = "SpecifiedArrayIndexInvalid"; - break; - case 714: - s = "NoSuchEntryInArray"; - break; - case 715: - s = "WildCardNotPermittedInSrcIP"; - break; - case 716: - s = "WildCardNotPermittedInExtPort"; - break; - case 718: - s = "ConflictInMappingEntry"; - break; - case 724: - s = "SamePortValuesRequired"; - break; - case 725: - s = "OnlyPermanentLeasesSupported"; - break; - case 726: - s = "RemoteHostOnlySupportsWildcard"; - break; - case 727: - s = "ExternalPortOnlySupportsWildcard"; - break; - default: - s = NULL; - } - return s; -} diff --git a/libs/miniupnpc/upnperrors.h b/libs/miniupnpc/upnperrors.h deleted file mode 100644 index 2c544c97c3..0000000000 --- a/libs/miniupnpc/upnperrors.h +++ /dev/null @@ -1,26 +0,0 @@ -/* $Id: upnperrors.h,v 1.2 2008/07/02 23:31:15 nanard Exp $ */ -/* (c) 2007 Thomas Bernard - * All rights reserved. - * MiniUPnP Project. - * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * This software is subjet to the conditions detailed in the - * provided LICENCE file. */ -#ifndef __UPNPERRORS_H__ -#define __UPNPERRORS_H__ - -#include "declspec.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* strupnperror() - * Return a string description of the UPnP error code - * or NULL for undefinded errors */ -LIBSPEC const char * strupnperror(int err); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libs/miniupnpc/upnpreplyparse.c b/libs/miniupnpc/upnpreplyparse.c deleted file mode 100644 index ab2b87ecb7..0000000000 --- a/libs/miniupnpc/upnpreplyparse.c +++ /dev/null @@ -1,127 +0,0 @@ -/* $Id: upnpreplyparse.c,v 1.10 2008/02/21 13:05:27 nanard Exp $ */ -/* MiniUPnP project - * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006 Thomas Bernard - * This software is subject to the conditions detailed - * in the LICENCE file provided within the distribution */ - -#include -#include -#include - -#include "upnpreplyparse.h" -#include "minixml.h" - -static void -NameValueParserStartElt(void * d, const char * name, int l) -{ - struct NameValueParserData * data = (struct NameValueParserData *)d; - if(l>63) - l = 63; - memcpy(data->curelt, name, l); - data->curelt[l] = '\0'; -} - -static void -NameValueParserGetData(void * d, const char * datas, int l) -{ - struct NameValueParserData * data = (struct NameValueParserData *)d; - struct NameValue * nv; - nv = malloc(sizeof(struct NameValue)); - if(l>63) - l = 63; - memcpy(nv->name, data->curelt, 64); - nv->name[63] = '\0'; - memcpy(nv->value, datas, l); - nv->value[l] = '\0'; - LIST_INSERT_HEAD( &(data->head), nv, entries); -} - -void -ParseNameValue(const char * buffer, int bufsize, - struct NameValueParserData * data) -{ - struct xmlparser parser; - LIST_INIT(&(data->head)); - /* init xmlparser object */ - parser.xmlstart = buffer; - parser.xmlsize = bufsize; - parser.data = data; - parser.starteltfunc = NameValueParserStartElt; - parser.endeltfunc = 0; - parser.datafunc = NameValueParserGetData; - parser.attfunc = 0; - parsexml(&parser); -} - -void -ClearNameValueList(struct NameValueParserData * pdata) -{ - struct NameValue * nv; - while((nv = pdata->head.lh_first) != NULL) - { - LIST_REMOVE(nv, entries); - free(nv); - } -} - -char * -GetValueFromNameValueList(struct NameValueParserData * pdata, - const char * Name) -{ - struct NameValue * nv; - char * p = NULL; - for(nv = pdata->head.lh_first; - (nv != NULL) && (p == NULL); - nv = nv->entries.le_next) - { - if(strcmp(nv->name, Name) == 0) - p = nv->value; - } - return p; -} - -#if 0 -/* useless now that minixml ignores namespaces by itself */ -char * -GetValueFromNameValueListIgnoreNS(struct NameValueParserData * pdata, - const char * Name) -{ - struct NameValue * nv; - char * p = NULL; - char * pname; - for(nv = pdata->head.lh_first; - (nv != NULL) && (p == NULL); - nv = nv->entries.le_next) - { - pname = strrchr(nv->name, ':'); - if(pname) - pname++; - else - pname = nv->name; - if(strcmp(pname, Name)==0) - p = nv->value; - } - return p; -} -#endif - -/* debug all-in-one function - * do parsing then display to stdout */ -#ifdef DEBUG -void -DisplayNameValueList(char * buffer, int bufsize) -{ - struct NameValueParserData pdata; - struct NameValue * nv; - ParseNameValue(buffer, bufsize, &pdata); - for(nv = pdata.head.lh_first; - nv != NULL; - nv = nv->entries.le_next) - { - printf("%s = %s\n", nv->name, nv->value); - } - ClearNameValueList(&pdata); -} -#endif - diff --git a/libs/miniupnpc/upnpreplyparse.h b/libs/miniupnpc/upnpreplyparse.h deleted file mode 100644 index a927634310..0000000000 --- a/libs/miniupnpc/upnpreplyparse.h +++ /dev/null @@ -1,62 +0,0 @@ -/* $Id: upnpreplyparse.h,v 1.8 2008/02/21 13:05:27 nanard Exp $ */ -/* MiniUPnP project - * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006 Thomas Bernard - * This software is subject to the conditions detailed - * in the LICENCE file provided within the distribution */ - -#ifndef __UPNPREPLYPARSE_H__ -#define __UPNPREPLYPARSE_H__ - -#if defined(NO_SYS_QUEUE_H) || defined(WIN32) -#include "bsdqueue.h" -#else -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -struct NameValue { - LIST_ENTRY(NameValue) entries; - char name[64]; - char value[64]; -}; - -struct NameValueParserData { - LIST_HEAD(listhead, NameValue) head; - char curelt[64]; -}; - -/* ParseNameValue() */ -void -ParseNameValue(const char * buffer, int bufsize, - struct NameValueParserData * data); - -/* ClearNameValueList() */ -void -ClearNameValueList(struct NameValueParserData * pdata); - -/* GetValueFromNameValueList() */ -char * -GetValueFromNameValueList(struct NameValueParserData * pdata, - const char * Name); - -/* GetValueFromNameValueListIgnoreNS() */ -char * -GetValueFromNameValueListIgnoreNS(struct NameValueParserData * pdata, - const char * Name); - -/* DisplayNameValueList() */ -#ifdef DEBUG -void -DisplayNameValueList(char * buffer, int bufsize); -#endif - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/scripts/FreeSWITCH-debian-raspbian-installer.sh b/scripts/FreeSWITCH-debian-raspbian-installer.sh index ff4112681a..ac97ab44d5 100755 --- a/scripts/FreeSWITCH-debian-raspbian-installer.sh +++ b/scripts/FreeSWITCH-debian-raspbian-installer.sh @@ -249,7 +249,7 @@ freeswitch_debian_source() { freeswitch_raspbian_source() { apt-get install -o Dpkg::Progress=1 -y autoconf automake devscripts gawk libjpeg-dev libncurses5-dev libtool-bin \ libtiff5-dev libperl-dev libgdbm-dev libdb-dev gettext libssl-dev libcurl4-openssl-dev libpcre3-dev libspeex-dev \ - libspeexdsp-dev libsqlite3-dev libedit-dev libldns-dev libpq-dev libsndfile-dev libopus-dev liblua5.1-0-dev 2>&1 | \ + libspeexdsp-dev libsqlite3-dev libminiupnpc-dev libedit-dev libldns-dev libpq-dev libsndfile-dev libopus-dev liblua5.1-0-dev 2>&1 | \ awk -W interactive '/Progress/ { print }'| sed -u 's/[^0-9]//g' | dialog --gauge "Please wait.\n Installing Build Requirements..." 10 70 0 build_fs diff --git a/scripts/debian_min_build.sh b/scripts/debian_min_build.sh index a07ad7165a..ba0e92449d 100755 --- a/scripts/debian_min_build.sh +++ b/scripts/debian_min_build.sh @@ -8,7 +8,7 @@ wget -O - https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list -apt-get update && apt-get install -y libtool libjpeg62-turbo-dev ntpdate libfreetype6-dev git-buildpackage doxygen yasm gdb git build-essential automake autoconf wget uuid-dev zlib1g-dev libncurses5-dev libssl-dev libpcre3-dev libcurl4-openssl-dev libldns-dev libedit-dev libspeexdsp-dev libsqlite3-dev perl libgdbm-dev libdb-dev bison pkg-config ccache libpng16-dev libpng12-dev libopenal-dev libbroadvoice-dev libcodec2-dev libflite-dev libg7221-dev libilbc-dev libsilk-dev liblua5.2-dev libopus-dev libsndfile-dev libavformat-dev libavcodec-extra libswscale-dev libx264-dev libperl-dev unixodbc-dev libpq-dev libsctp-dev +apt-get update && apt-get install -y libtool libjpeg62-turbo-dev ntpdate libfreetype6-dev git-buildpackage doxygen yasm gdb git build-essential automake autoconf wget uuid-dev zlib1g-dev libncurses5-dev libssl-dev libpcre3-dev libcurl4-openssl-dev libldns-dev libedit-dev libspeexdsp-dev libsqlite3-dev libminiupnpc-dev perl libgdbm-dev libdb-dev bison pkg-config ccache libpng16-dev libpng12-dev libopenal-dev libbroadvoice-dev libcodec2-dev libflite-dev libg7221-dev libilbc-dev libsilk-dev liblua5.2-dev libopus-dev libsndfile-dev libavformat-dev libavcodec-extra libswscale-dev libx264-dev libperl-dev unixodbc-dev libpq-dev libsctp-dev cd /usr/src diff --git a/src/switch_nat.c b/src/switch_nat.c index a1620b4bfd..7a730a80ad 100644 --- a/src/switch_nat.c +++ b/src/switch_nat.c @@ -33,10 +33,9 @@ */ #include -#include "../libs/miniupnpc/miniwget.h" -#include "../libs/miniupnpc/miniupnpc.h" -#include "../libs/miniupnpc/upnpcommands.h" -#include "../libs/miniupnpc/upnperrors.h" +#include +#include +#include #include "../libs/libnatpmp/natpmp.h" #define MULTICAST_BUFFSIZE 65536 @@ -68,13 +67,13 @@ static nat_globals_perm_t nat_globals_perm; static switch_bool_t first_init = SWITCH_TRUE; static switch_bool_t initialized = SWITCH_FALSE; -static switch_status_t get_upnp_pubaddr(char *pub_addr) +static switch_status_t get_upnp_pubaddr(char *pub_addr, switch_bool_t have_fallback) { - if (UPNP_GetExternalIPAddress(nat_globals.urls.controlURL, nat_globals.data.servicetype, pub_addr) == UPNPCOMMAND_SUCCESS) { + if (UPNP_GetExternalIPAddress(nat_globals.urls.controlURL, nat_globals.data.first.servicetype, pub_addr) == UPNPCOMMAND_SUCCESS) { if (!strcmp(pub_addr, "0.0.0.0") || zstr_buf(pub_addr)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, - "uPNP Device (url: %s) returned an invalid external address of '%s'. Disabling uPNP\n", nat_globals.urls.controlURL, - pub_addr); + switch_log_printf(SWITCH_CHANNEL_LOG, have_fallback ? SWITCH_LOG_DEBUG : SWITCH_LOG_ERROR, + "uPNP Device (url: %s) returned an invalid external address of '%s'. %s\n", nat_globals.urls.controlURL, + pub_addr, have_fallback ? "Trying the other WAN connection service" : "Disabling uPNP"); return SWITCH_STATUS_GENERR; } } else { @@ -90,12 +89,13 @@ static int init_upnp(void) struct UPNPDev *trydev = NULL; char *descXML; int descXMLsize = 0; - const char *minissdpdpath = switch_core_get_variable("local_ip_v4"); + unsigned int scope_id = 0; + const char *multicastif = switch_core_get_variable("local_ip_v4"); memset(&nat_globals.urls, 0, sizeof(struct UPNPUrls)); memset(&nat_globals.data, 0, sizeof(struct IGDdatas)); - devlist = upnpDiscover(3000, minissdpdpath, minissdpdpath, 0); + devlist = upnpDiscover(3000, multicastif, NULL, 0, 0, 2, NULL); if (devlist) { dev = devlist; @@ -120,15 +120,16 @@ static int init_upnp(void) } if (dev) { - descXML = miniwget(dev->descURL, &descXMLsize); + descXML = miniwget(dev->descURL, &descXMLsize, dev->scope_id, NULL); nat_globals.descURL = strdup(dev->descURL); + scope_id = dev->scope_id; if (descXML) { parserootdesc(descXML, descXMLsize, &nat_globals.data); free(descXML); descXML = 0; - GetUPNPUrls(&nat_globals.urls, &nat_globals.data, dev->descURL); + GetUPNPUrls(&nat_globals.urls, &nat_globals.data, dev->descURL, dev->scope_id); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unable to retrieve device description XML (%s).\n", dev->descURL); } @@ -136,11 +137,27 @@ static int init_upnp(void) freeUPNPDevlist(devlist); } - if (get_upnp_pubaddr(nat_globals.pub_addr) == SWITCH_STATUS_SUCCESS) { + if (get_upnp_pubaddr(nat_globals.pub_addr, nat_globals.data.second.servicetype[0] ? SWITCH_TRUE : SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) { nat_globals.nat_type = SWITCH_NAT_TYPE_UPNP; return 0; } + if (nat_globals.data.second.servicetype[0]) { + /* the gateway lists two WAN connection services and the first one did not answer: try the other one */ + struct IGDdatas_service first = nat_globals.data.first; + + nat_globals.data.first = nat_globals.data.second; + nat_globals.data.second = first; + FreeUPNPUrls(&nat_globals.urls); + GetUPNPUrls(&nat_globals.urls, &nat_globals.data, nat_globals.descURL, scope_id); + + if (get_upnp_pubaddr(nat_globals.pub_addr, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) { + nat_globals.nat_type = SWITCH_NAT_TYPE_UPNP; + + return 0; + } + } + return -2; } @@ -295,7 +312,7 @@ static void *SWITCH_THREAD_FUNC switch_nat_multicast_runtime(switch_thread_t * t if (nat_globals.nat_type == SWITCH_NAT_TYPE_UPNP) { /* look for our desc URL and servicetype in the packet */ - if (strstr(buf, nat_globals.descURL) && strstr(buf, nat_globals.data.servicetype)) { + if (strstr(buf, nat_globals.descURL) && strstr(buf, nat_globals.data.first.servicetype)) { if ((pos = strstr(buf, "NTS:"))) { pos = pos + 4; while (*pos && *pos == ' ') { @@ -305,7 +322,7 @@ static void *SWITCH_THREAD_FUNC switch_nat_multicast_runtime(switch_thread_t * t /* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got UPnP keep alive packet: \n%s\n", buf); */ /* did pub ip change */ newip[0] = '\0'; - if (get_upnp_pubaddr(newip) != SWITCH_STATUS_SUCCESS) { + if (get_upnp_pubaddr(newip, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unable to get current pubaddr after receiving UPnP keep alive packet.\n"); } @@ -497,11 +514,11 @@ static switch_status_t switch_nat_add_mapping_upnp(switch_port_t port, switch_na sprintf(port_str, "%d", port); if (proto == SWITCH_NAT_TCP) { - r = UPNP_AddPortMapping(nat_globals.urls.controlURL, nat_globals.data.servicetype, port_str, port_str, - nat_globals.pvt_addr, "FreeSWITCH", "TCP", 0); + r = UPNP_AddPortMapping(nat_globals.urls.controlURL, nat_globals.data.first.servicetype, port_str, port_str, + nat_globals.pvt_addr, "FreeSWITCH", "TCP", NULL, NULL); } else if (proto == SWITCH_NAT_UDP) { - r = UPNP_AddPortMapping(nat_globals.urls.controlURL, nat_globals.data.servicetype, port_str, port_str, - nat_globals.pvt_addr, "FreeSWITCH", "UDP", 0); + r = UPNP_AddPortMapping(nat_globals.urls.controlURL, nat_globals.data.first.servicetype, port_str, port_str, + nat_globals.pvt_addr, "FreeSWITCH", "UDP", NULL, NULL); } if (r == UPNPCOMMAND_SUCCESS) { @@ -559,9 +576,9 @@ static switch_status_t switch_nat_del_mapping_upnp(switch_port_t port, switch_na sprintf(port_str, "%d", port); if (proto == SWITCH_NAT_TCP) { - r = UPNP_DeletePortMapping(nat_globals.urls.controlURL, nat_globals.data.servicetype, port_str, "TCP", 0); + r = UPNP_DeletePortMapping(nat_globals.urls.controlURL, nat_globals.data.first.servicetype, port_str, "TCP", NULL); } else if (proto == SWITCH_NAT_UDP) { - r = UPNP_DeletePortMapping(nat_globals.urls.controlURL, nat_globals.data.servicetype, port_str, "UDP", 0); + r = UPNP_DeletePortMapping(nat_globals.urls.controlURL, nat_globals.data.first.servicetype, port_str, "UDP", NULL); } if (r == UPNPCOMMAND_SUCCESS) { diff --git a/w32/Library/FreeSwitchCore.2010.vcxproj.filters b/w32/Library/FreeSwitchCore.2010.vcxproj.filters index 34c4253470..cb623ec125 100644 --- a/w32/Library/FreeSwitchCore.2010.vcxproj.filters +++ b/w32/Library/FreeSwitchCore.2010.vcxproj.filters @@ -10,27 +10,9 @@ Source Files - - Source Files - Source Files - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - Source Files @@ -202,15 +184,6 @@ Source Files - - Source Files - - - Source Files - - - Source Files - Source Files @@ -228,9 +201,6 @@ - - Header Files - Header Files diff --git a/w32/Library/FreeSwitchCore.2017.vcxproj b/w32/Library/FreeSwitchCore.2017.vcxproj index 0ca2b7eccd..7074a1b7d3 100644 --- a/w32/Library/FreeSwitchCore.2017.vcxproj +++ b/w32/Library/FreeSwitchCore.2017.vcxproj @@ -56,6 +56,7 @@ + @@ -425,240 +426,6 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" - - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - - - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - - - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - - - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;4389;4706;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;4389;4706;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;4389;4706;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;4389;4706;%(DisableSpecificWarnings) - - - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - - - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - - - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - - - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - - - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - - - - - 4100;4127;%(DisableSpecificWarnings) - _CRT_SECURE_NO_DEPRECATE;STATICLIB;%(PreprocessorDefinitions) - - - 4100;4127;%(DisableSpecificWarnings) - @@ -715,7 +482,6 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" - diff --git a/w32/miniupnpc-version.props b/w32/miniupnpc-version.props new file mode 100644 index 0000000000..04cde71443 --- /dev/null +++ b/w32/miniupnpc-version.props @@ -0,0 +1,21 @@ + + + + + 2.3.3 + 1 + + + true + + + + + + $(miniupnpcVersion) + + + $(miniupnpcBuildNumber) + + + diff --git a/w32/miniupnpc.props b/w32/miniupnpc.props new file mode 100644 index 0000000000..656ccbee0b --- /dev/null +++ b/w32/miniupnpc.props @@ -0,0 +1,60 @@ + + + + + + + + $(BaseDir)libs\miniupnpc-$(miniupnpcVersion)_$(miniupnpcBuildNumber) + + + + + + + + + + + + + + $(miniupnpcLibDir)\include;%(AdditionalIncludeDirectories) + MINIUPNP_STATICLIB;%(PreprocessorDefinitions) + + + $(miniupnpcLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + libminiupnpc.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies) + + + From a55111af587fe64e1dba1f6c41440d751f76eb5d Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 10 Nov 2026 02:38:06 +0300 Subject: [PATCH 56/88] [libvpx] Update to v1.17.0-97-gd3335af9e --- libs/libvpx/.mailmap | 7 +- libs/libvpx/.update | 2 +- libs/libvpx/AUTHORS | 41 +- libs/libvpx/CHANGELOG | 367 +- libs/libvpx/README | 76 +- libs/libvpx/args.c | 28 +- libs/libvpx/args.h | 14 +- libs/libvpx/build/make/Android.mk | 20 +- libs/libvpx/build/make/Makefile | 40 +- libs/libvpx/build/make/configure.sh | 196 +- libs/libvpx/build/make/gen_asm_deps.sh | 2 +- libs/libvpx/build/make/gen_msvs_sln.sh | 5 +- libs/libvpx/build/make/gen_msvs_vcxproj.sh | 59 +- libs/libvpx/build/make/iosbuild.sh | 10 +- libs/libvpx/build/make/rtcd.pl | 46 +- libs/libvpx/build/make/version.sh | 3 + libs/libvpx/configure | 81 +- libs/libvpx/examples.mk | 28 +- libs/libvpx/examples/resize_util.c | 123 - libs/libvpx/examples/set_maps.c | 3 +- libs/libvpx/examples/simple_decoder.c | 9 +- libs/libvpx/examples/simple_encoder.c | 3 +- libs/libvpx/examples/svc_context.h | 3 +- libs/libvpx/examples/svc_encodeframe.c | 53 +- libs/libvpx/examples/twopass_encoder.c | 4 +- .../examples/vp8_multi_resolution_encoder.c | 3 +- libs/libvpx/examples/vp8cx_set_ref.c | 3 +- libs/libvpx/examples/vp9_lossless_encoder.c | 3 +- .../libvpx/examples/vp9_spatial_svc_encoder.c | 80 +- libs/libvpx/examples/vp9cx_set_ref.c | 2 +- libs/libvpx/examples/vpx_dec_fuzzer.cc | 50 +- libs/libvpx/examples/vpx_enc_fuzzer.cc | 256 + .../examples/vpx_temporal_svc_encoder.c | 28 +- libs/libvpx/libs.doxy_template | 48 +- libs/libvpx/libs.mk | 72 +- libs/libvpx/md5_utils.c | 4 +- libs/libvpx/rate_hist.c | 8 +- libs/libvpx/test/acm_random.h | 32 +- libs/libvpx/test/active_map_refresh_test.cc | 10 +- libs/libvpx/test/active_map_test.cc | 10 +- libs/libvpx/test/add_noise_test.cc | 59 +- libs/libvpx/test/alt_ref_aq_segment_test.cc | 10 +- libs/libvpx/test/altref_test.cc | 25 +- libs/libvpx/test/android/Android.mk | 6 + libs/libvpx/test/android/get_files.py | 17 +- libs/libvpx/test/aq_segment_test.cc | 10 +- libs/libvpx/test/avg_test.cc | 82 +- libs/libvpx/test/bench.cc | 1 + libs/libvpx/test/bench.h | 2 + libs/libvpx/test/blockiness_test.cc | 8 +- libs/libvpx/test/borders_test.cc | 18 +- libs/libvpx/test/buffer.h | 2 +- libs/libvpx/test/byte_alignment_test.cc | 4 +- libs/libvpx/test/codec_factory.h | 56 +- libs/libvpx/test/comp_avg_pred_test.cc | 187 +- libs/libvpx/test/config_test.cc | 12 +- libs/libvpx/test/consistency_test.cc | 8 +- libs/libvpx/test/convolve_test.cc | 874 +++- libs/libvpx/test/cpu_speed_test.cc | 21 +- libs/libvpx/test/cq_test.cc | 24 +- libs/libvpx/test/dct16x16_test.cc | 213 +- libs/libvpx/test/dct32x32_test.cc | 216 +- libs/libvpx/test/dct_partial_test.cc | 21 +- libs/libvpx/test/dct_test.cc | 76 +- libs/libvpx/test/decode_api_test.cc | 475 +- libs/libvpx/test/decode_corrupted.cc | 27 +- libs/libvpx/test/decode_perf_test.cc | 26 +- libs/libvpx/test/decode_svc_test.cc | 11 +- libs/libvpx/test/decode_test_driver.cc | 4 +- libs/libvpx/test/decode_test_driver.h | 2 +- libs/libvpx/test/encode_api_test.cc | 4388 ++++++++++++++++- libs/libvpx/test/encode_perf_test.cc | 22 +- libs/libvpx/test/encode_test_driver.cc | 13 +- libs/libvpx/test/encode_test_driver.h | 40 +- libs/libvpx/test/error_resilience_test.cc | 38 +- .../libvpx/test/external_frame_buffer_test.cc | 17 +- libs/libvpx/test/fdct8x8_test.cc | 93 +- libs/libvpx/test/frame_size_tests.cc | 42 +- libs/libvpx/test/hadamard_test.cc | 72 +- libs/libvpx/test/idct8x8_test.cc | 3 +- libs/libvpx/test/idct_test.cc | 16 +- libs/libvpx/test/init_vpx_test.cc | 109 + libs/libvpx/test/init_vpx_test.h | 18 + libs/libvpx/test/invalid_file_test.cc | 17 +- libs/libvpx/test/ivf_video_source.h | 23 +- libs/libvpx/test/keyframe_test.cc | 119 +- libs/libvpx/test/level_test.cc | 29 +- libs/libvpx/test/lpf_test.cc | 46 +- libs/libvpx/test/md5_helper.h | 2 +- libs/libvpx/test/mfqe_test.cc | 144 + libs/libvpx/test/minmax_test.cc | 122 +- libs/libvpx/test/non_greedy_mv_test.cc | 12 +- libs/libvpx/test/partial_idct_test.cc | 30 +- libs/libvpx/test/postproc_test.cc | 238 + libs/libvpx/test/pp_filter_test.cc | 223 +- libs/libvpx/test/predict_test.cc | 142 +- libs/libvpx/test/quantize_test.cc | 19 +- libs/libvpx/test/realtime_test.cc | 11 +- libs/libvpx/test/register_state_check.h | 16 +- libs/libvpx/test/resize_test.cc | 304 +- libs/libvpx/test/resize_util.sh | 69 - libs/libvpx/test/sad_test.cc | 1006 +++- libs/libvpx/test/set_roi.cc | 4 +- libs/libvpx/test/simple_encode_test.cc | 574 --- libs/libvpx/test/sum_squares_test.cc | 265 +- libs/libvpx/test/superframe_test.cc | 18 +- libs/libvpx/test/svc_datarate_test.cc | 698 ++- libs/libvpx/test/svc_end_to_end_test.cc | 60 +- libs/libvpx/test/svc_test.h | 8 +- libs/libvpx/test/test-data.mk | 8 + libs/libvpx/test/test-data.sha1 | 7 + libs/libvpx/test/test.mk | 46 +- libs/libvpx/test/test_intra_pred_speed.cc | 160 +- libs/libvpx/test/test_libvpx.cc | 63 +- libs/libvpx/test/test_rc_interface.cc | 12 +- libs/libvpx/test/test_vector_test.cc | 26 +- libs/libvpx/test/test_vectors.cc | 1 + libs/libvpx/test/tile_independence_test.cc | 14 +- libs/libvpx/test/timestamp_test.cc | 20 +- libs/libvpx/test/tools_common.sh | 11 +- libs/libvpx/test/user_priv_test.cc | 2 +- libs/libvpx/test/util.h | 2 +- libs/libvpx/test/variance_test.cc | 726 ++- libs/libvpx/test/video_source.h | 39 +- libs/libvpx/test/vp8_boolcoder_test.cc | 2 +- libs/libvpx/test/vp8_datarate_test.cc | 108 +- libs/libvpx/test/vp8_decrypt_test.cc | 2 +- libs/libvpx/test/vp8_denoiser_sse2_test.cc | 9 +- libs/libvpx/test/vp8_fdct4x4_test.cc | 10 +- libs/libvpx/test/vp8_fragments_test.cc | 6 +- .../libvpx/test/vp8_loopfilter_simple_test.cc | 125 + libs/libvpx/test/vp8_ratectrl_rtc_test.cc | 135 +- libs/libvpx/test/vp9_arf_freq_test.cc | 28 +- libs/libvpx/test/vp9_block_error_test.cc | 57 +- libs/libvpx/test/vp9_boolcoder_test.cc | 27 +- libs/libvpx/test/vp9_c_vs_simd_encode.sh | 420 ++ libs/libvpx/test/vp9_datarate_test.cc | 238 +- libs/libvpx/test/vp9_decrypt_test.cc | 2 +- libs/libvpx/test/vp9_denoiser_test.cc | 21 +- .../test/vp9_encoder_parms_get_to_decoder.cc | 20 +- libs/libvpx/test/vp9_end_to_end_test.cc | 80 +- libs/libvpx/test/vp9_entropy_test.cc | 24 + libs/libvpx/test/vp9_ethread_test.cc | 84 +- libs/libvpx/test/vp9_ext_ratectrl_test.cc | 373 +- libs/libvpx/test/vp9_intrapred_test.cc | 675 ++- libs/libvpx/test/vp9_lossless_test.cc | 19 +- libs/libvpx/test/vp9_motion_vector_test.cc | 13 +- libs/libvpx/test/vp9_quantize_test.cc | 528 +- libs/libvpx/test/vp9_ratectrl_rtc_test.cc | 539 +- libs/libvpx/test/vp9_roi_test.cc | 10 +- libs/libvpx/test/vp9_scale_test.cc | 21 +- libs/libvpx/test/vp9_scan_test.cc | 105 + libs/libvpx/test/vp9_subtract_test.cc | 179 +- libs/libvpx/test/vp9_thread_test.cc | 8 +- libs/libvpx/test/vp9_tokenize_test.cc | 26 + libs/libvpx/test/vpx_image_test.cc | 316 ++ libs/libvpx/test/vpx_scale_test.cc | 16 +- libs/libvpx/test/vpx_scale_test.h | 2 +- libs/libvpx/test/webm_video_source.h | 14 +- libs/libvpx/test/y4m_test.cc | 8 +- libs/libvpx/test/y4m_video_source.h | 18 +- libs/libvpx/test/yuv_temporal_filter_test.cc | 25 +- libs/libvpx/test/yuv_video_source.h | 59 +- .../third_party/googletest/README.libvpx | 31 +- .../third_party/googletest/googletest.patch | 89 + .../third_party/googletest/src/.clang-format | 4 + .../third_party/googletest/src/CONTRIBUTORS | 3 + .../third_party/googletest/src/README.md | 60 +- .../include/gtest/gtest-assertion-result.h | 244 + .../src/include/gtest/gtest-death-test.h | 97 +- .../src/include/gtest/gtest-matchers.h | 111 +- .../src/include/gtest/gtest-message.h | 64 +- .../src/include/gtest/gtest-param-test.h | 145 +- .../src/include/gtest/gtest-printers.h | 287 +- .../googletest/src/include/gtest/gtest-spi.h | 134 +- .../src/include/gtest/gtest-test-part.h | 20 +- .../src/include/gtest/gtest-typed-test.h | 80 +- .../googletest/src/include/gtest/gtest.h | 671 +-- .../src/include/gtest/gtest_pred_impl.h | 200 +- .../googletest/src/include/gtest/gtest_prod.h | 9 +- .../include/gtest/internal/custom/README.md | 12 - .../internal/gtest-death-test-internal.h | 132 +- .../include/gtest/internal/gtest-filepath.h | 42 +- .../include/gtest/internal/gtest-internal.h | 503 +- .../include/gtest/internal/gtest-param-util.h | 417 +- .../include/gtest/internal/gtest-port-arch.h | 108 +- .../src/include/gtest/internal/gtest-port.h | 1500 +++--- .../src/include/gtest/internal/gtest-string.h | 21 +- .../include/gtest/internal/gtest-type-util.h | 55 +- .../googletest/src/src/gtest-all.cc | 3 +- .../src/src/gtest-assertion-result.cc | 77 + .../googletest/src/src/gtest-death-test.cc | 623 ++- .../googletest/src/src/gtest-filepath.cc | 191 +- .../googletest/src/src/gtest-internal-inl.h | 315 +- .../googletest/src/src/gtest-matchers.cc | 5 +- .../googletest/src/src/gtest-port.cc | 547 +- .../googletest/src/src/gtest-printers.cc | 136 +- .../googletest/src/src/gtest-test-part.cc | 24 +- .../googletest/src/src/gtest-typed-test.cc | 13 +- .../third_party/googletest/src/src/gtest.cc | 2343 +++++---- .../googletest/src/src/gtest_main.cc | 24 +- libs/libvpx/third_party/libwebm/AUTHORS.TXT | 1 + libs/libvpx/third_party/libwebm/Android.mk | 5 +- libs/libvpx/third_party/libwebm/README.libvpx | 11 +- .../third_party/libwebm/common/hdr_util.cc | 3 +- .../third_party/libwebm/mkvmuxer/mkvmuxer.cc | 106 +- .../third_party/libwebm/mkvmuxer/mkvmuxer.h | 10 +- .../libwebm/mkvmuxer/mkvmuxerutil.cc | 12 +- .../libwebm/mkvmuxer/mkvmuxerutil.h | 4 +- .../third_party/libwebm/mkvmuxer/mkvwriter.cc | 8 +- .../libwebm/mkvparser/mkvparser.cc | 21 +- .../libwebm/mkvparser/mkvreader.cc | 8 +- libs/libvpx/third_party/libyuv/README.libvpx | 8 +- libs/libvpx/third_party/nalloc/LICENSE | 21 + libs/libvpx/third_party/nalloc/README.libvpx | 15 + libs/libvpx/third_party/nalloc/nalloc.h | 342 ++ libs/libvpx/third_party/x86inc/README.libvpx | 7 +- libs/libvpx/tools.mk | 7 + .../3D-Reconstruction/MotionEST/Exhaust.py | 2 +- .../MotionEST/GroundTruth.py | 4 +- .../3D-Reconstruction/MotionEST/MotionEST.py | 4 +- .../tools/3D-Reconstruction/MotionEST/Util.py | 2 +- libs/libvpx/tools/README.pgo.md | 24 + libs/libvpx/tools/set_analyzer_env.sh | 20 +- libs/libvpx/tools/tiny_ssim.c | 79 +- libs/libvpx/tools_common.c | 57 +- libs/libvpx/tools_common.h | 14 +- libs/libvpx/video_reader.c | 7 +- libs/libvpx/video_writer.c | 1 + libs/libvpx/vp8/common/alloccommon.c | 14 +- .../vp8/common/arm/neon/sixtappredict_neon.c | 9 +- libs/libvpx/vp8/common/blockd.h | 2 +- libs/libvpx/vp8/common/common.h | 16 +- libs/libvpx/vp8/common/dequantize.c | 2 +- libs/libvpx/vp8/common/entropy.c | 2 +- libs/libvpx/vp8/common/findnearmv.c | 4 +- .../vp8/common/generic/systemdependent.c | 58 +- .../common/loongarch/loopfilter_filters_lsx.c | 169 + .../vp8/common/loongarch/sixtap_filter_lsx.c | 65 +- libs/libvpx/vp8/common/mfqe.c | 2 +- .../vp8/common/mips/dspr2/filter_dspr2.c | 12 +- .../vp8/common/mips/msa/sixtap_filter_msa.c | 181 +- .../vp8/common/mips/msa/vp8_macros_msa.h | 256 +- libs/libvpx/vp8/common/onyx.h | 35 +- libs/libvpx/vp8/common/onyxc_int.h | 1 - libs/libvpx/vp8/common/onyxd.h | 3 +- libs/libvpx/vp8/common/postproc.c | 31 +- libs/libvpx/vp8/common/postproc.h | 1 + libs/libvpx/vp8/common/reconinter.c | 10 +- libs/libvpx/vp8/common/rtcd.c | 2 +- libs/libvpx/vp8/common/rtcd_defs.pl | 105 +- libs/libvpx/vp8/common/threading.h | 161 +- libs/libvpx/vp8/common/vp8_loopfilter.c | 2 +- libs/libvpx/vp8/decoder/dboolhuff.h | 4 +- libs/libvpx/vp8/decoder/decodeframe.c | 50 +- libs/libvpx/vp8/decoder/decodemv.c | 4 +- libs/libvpx/vp8/decoder/onyxd_if.c | 8 +- libs/libvpx/vp8/decoder/onyxd_int.h | 27 +- libs/libvpx/vp8/decoder/threading.c | 80 +- .../vp8/encoder/arm/neon/fastquantizeb_neon.c | 8 +- libs/libvpx/vp8/encoder/bitstream.c | 19 +- libs/libvpx/vp8/encoder/denoising.c | 3 +- libs/libvpx/vp8/encoder/encodeframe.c | 88 +- libs/libvpx/vp8/encoder/encodemb.c | 12 +- libs/libvpx/vp8/encoder/encodemv.c | 10 +- libs/libvpx/vp8/encoder/ethreading.c | 112 +- libs/libvpx/vp8/encoder/firstpass.c | 195 +- .../{quantize_lsx.c => vp8_quantize_lsx.c} | 45 + libs/libvpx/vp8/encoder/mcomp.c | 76 +- libs/libvpx/vp8/encoder/mr_dissim.c | 2 +- libs/libvpx/vp8/encoder/onyx_if.c | 586 ++- libs/libvpx/vp8/encoder/onyx_int.h | 57 +- libs/libvpx/vp8/encoder/pickinter.c | 30 +- libs/libvpx/vp8/encoder/picklpf.c | 8 + libs/libvpx/vp8/encoder/ratectrl.c | 93 +- libs/libvpx/vp8/encoder/rdopt.c | 81 +- libs/libvpx/vp8/encoder/segmentation.c | 4 +- libs/libvpx/vp8/encoder/segmentation.h | 4 +- libs/libvpx/vp8/encoder/tokenize.h | 2 - libs/libvpx/vp8/encoder/vp8_quantize.c | 11 +- libs/libvpx/vp8/encoder/x86/denoising_sse2.c | 2 +- libs/libvpx/vp8/encoder/x86/quantize_sse4.c | 5 +- libs/libvpx/vp8/vp8_common.mk | 13 +- libs/libvpx/vp8/vp8_cx_iface.c | 295 +- libs/libvpx/vp8/vp8_dx_iface.c | 117 +- libs/libvpx/vp8/vp8_ratectrl_rtc.cc | 153 +- libs/libvpx/vp8/vp8_ratectrl_rtc.h | 41 +- libs/libvpx/vp8/vp8cx.mk | 14 +- .../arm/neon/vp9_highbd_iht16x16_add_neon.c | 8 +- libs/libvpx/vp9/common/vp9_alloccommon.c | 4 +- libs/libvpx/vp9/common/vp9_blockd.h | 4 +- libs/libvpx/vp9/common/vp9_common.h | 35 +- libs/libvpx/vp9/common/vp9_entropy.c | 2 +- libs/libvpx/vp9/common/vp9_entropy.h | 2 + libs/libvpx/vp9/common/vp9_entropymode.c | 1 - libs/libvpx/vp9/common/vp9_entropymode.h | 2 +- libs/libvpx/vp9/common/vp9_idct.c | 2 + libs/libvpx/vp9/common/vp9_loopfilter.c | 40 +- libs/libvpx/vp9/common/vp9_mfqe.c | 58 +- libs/libvpx/vp9/common/vp9_onyxc_int.h | 3 - libs/libvpx/vp9/common/vp9_postproc.c | 119 +- libs/libvpx/vp9/common/vp9_postproc.h | 3 + libs/libvpx/vp9/common/vp9_reconinter.c | 18 +- libs/libvpx/vp9/common/vp9_rtcd.c | 2 +- libs/libvpx/vp9/common/vp9_rtcd_defs.pl | 80 +- libs/libvpx/vp9/common/vp9_scan.c | 297 +- libs/libvpx/vp9/common/vp9_scan.h | 17 +- libs/libvpx/vp9/common/vp9_thread_common.c | 27 +- libs/libvpx/vp9/common/vp9_thread_common.h | 1 + libs/libvpx/vp9/decoder/vp9_decodeframe.c | 82 +- libs/libvpx/vp9/decoder/vp9_decodemv.c | 18 +- libs/libvpx/vp9/decoder/vp9_decoder.c | 49 +- libs/libvpx/vp9/decoder/vp9_decoder.h | 3 +- libs/libvpx/vp9/decoder/vp9_detokenize.c | 24 +- libs/libvpx/vp9/decoder/vp9_detokenize.h | 5 +- libs/libvpx/vp9/decoder/vp9_job_queue.c | 1 + libs/libvpx/vp9/decoder/vp9_job_queue.h | 2 +- .../vp9/encoder/arm/neon/vp9_dct_neon.c | 2201 ++++++--- .../vp9/encoder/arm/neon/vp9_denoiser_neon.c | 2 +- .../arm/neon/vp9_diamond_search_sad_neon.c | 296 ++ .../vp9/encoder/arm/neon/vp9_error_neon.c | 99 +- .../vp9/encoder/arm/neon/vp9_error_sve.c | 78 + .../encoder/arm/neon/vp9_frame_scale_neon.c | 5 +- .../encoder/arm/neon/vp9_highbd_error_neon.c | 49 + .../neon/vp9_highbd_temporal_filter_neon.c | 1076 ++++ .../neon/vp9_highbd_temporal_filter_sve2.c | 285 ++ .../vp9/encoder/arm/neon/vp9_quantize_neon.c | 500 +- .../arm/neon/vp9_temporal_filter_neon.c | 1103 +++++ .../neon/vp9_temporal_filter_neon_dotprod.c | 367 ++ .../arm/neon/vp9_temporal_filter_neon_i8mm.c | 351 ++ libs/libvpx/vp9/encoder/vp9_aq_complexity.c | 7 +- .../libvpx/vp9/encoder/vp9_aq_cyclicrefresh.c | 47 +- libs/libvpx/vp9/encoder/vp9_aq_variance.c | 2 +- libs/libvpx/vp9/encoder/vp9_bitstream.c | 166 +- libs/libvpx/vp9/encoder/vp9_bitstream.h | 5 +- libs/libvpx/vp9/encoder/vp9_block.h | 21 +- libs/libvpx/vp9/encoder/vp9_context_tree.c | 21 +- libs/libvpx/vp9/encoder/vp9_context_tree.h | 2 +- libs/libvpx/vp9/encoder/vp9_denoiser.c | 17 +- libs/libvpx/vp9/encoder/vp9_encodeframe.c | 998 ++-- libs/libvpx/vp9/encoder/vp9_encodeframe.h | 7 - libs/libvpx/vp9/encoder/vp9_encodemb.c | 414 +- libs/libvpx/vp9/encoder/vp9_encodemb.h | 19 +- libs/libvpx/vp9/encoder/vp9_encoder.c | 3752 +++++--------- libs/libvpx/vp9/encoder/vp9_encoder.h | 610 ++- libs/libvpx/vp9/encoder/vp9_ethread.c | 38 +- libs/libvpx/vp9/encoder/vp9_ethread.h | 4 +- libs/libvpx/vp9/encoder/vp9_ext_ratectrl.c | 137 +- libs/libvpx/vp9/encoder/vp9_ext_ratectrl.h | 31 +- libs/libvpx/vp9/encoder/vp9_extend.c | 39 - libs/libvpx/vp9/encoder/vp9_extend.h | 3 - libs/libvpx/vp9/encoder/vp9_firstpass.c | 649 +-- libs/libvpx/vp9/encoder/vp9_firstpass.h | 91 +- libs/libvpx/vp9/encoder/vp9_firstpass_stats.h | 54 + libs/libvpx/vp9/encoder/vp9_frame_scale.c | 20 + libs/libvpx/vp9/encoder/vp9_lookahead.c | 105 +- libs/libvpx/vp9/encoder/vp9_mbgraph.c | 30 +- libs/libvpx/vp9/encoder/vp9_mcomp.c | 216 +- libs/libvpx/vp9/encoder/vp9_mcomp.h | 14 +- libs/libvpx/vp9/encoder/vp9_multi_thread.c | 34 +- libs/libvpx/vp9/encoder/vp9_noise_estimate.c | 2 +- libs/libvpx/vp9/encoder/vp9_pickmode.c | 162 +- libs/libvpx/vp9/encoder/vp9_quantize.c | 93 +- libs/libvpx/vp9/encoder/vp9_quantize.h | 5 +- libs/libvpx/vp9/encoder/vp9_ratectrl.c | 366 +- libs/libvpx/vp9/encoder/vp9_ratectrl.h | 12 +- libs/libvpx/vp9/encoder/vp9_rd.c | 62 +- libs/libvpx/vp9/encoder/vp9_rd.h | 7 - libs/libvpx/vp9/encoder/vp9_rdopt.c | 743 +-- libs/libvpx/vp9/encoder/vp9_resize.c | 86 +- libs/libvpx/vp9/encoder/vp9_resize.h | 33 - libs/libvpx/vp9/encoder/vp9_segmentation.c | 2 +- libs/libvpx/vp9/encoder/vp9_speed_features.c | 124 +- libs/libvpx/vp9/encoder/vp9_speed_features.h | 72 +- libs/libvpx/vp9/encoder/vp9_subexp.c | 6 +- .../libvpx/vp9/encoder/vp9_svc_layercontext.c | 170 +- .../libvpx/vp9/encoder/vp9_svc_layercontext.h | 12 +- libs/libvpx/vp9/encoder/vp9_temporal_filter.c | 454 +- libs/libvpx/vp9/encoder/vp9_temporal_filter.h | 35 +- ...ants.h => vp9_temporal_filter_constants.h} | 32 +- libs/libvpx/vp9/encoder/vp9_tokenize.c | 6 +- libs/libvpx/vp9/encoder/vp9_tpl_model.c | 1793 +++++++ libs/libvpx/vp9/encoder/vp9_tpl_model.h | 47 + .../encoder/x86/highbd_temporal_filter_avx2.c | 263 + .../encoder/x86/highbd_temporal_filter_sse4.c | 142 +- .../x86/highbd_temporal_filter_ssse3.c | 233 + .../vp9/encoder/x86/temporal_filter_avx2.c | 441 ++ .../vp9/encoder/x86/temporal_filter_sse4.c | 2 +- .../vp9/encoder/x86/temporal_filter_ssse3.c | 279 ++ .../vp9/encoder/x86/vp9_dct_intrin_sse2.c | 6 +- .../encoder/x86/vp9_diamond_search_sad_avx.c | 317 -- .../vp9/encoder/x86/vp9_frame_scale_ssse3.c | 44 +- .../vp9/encoder/x86/vp9_quantize_avx2.c | 465 +- .../vp9/encoder/x86/vp9_quantize_sse2.c | 229 +- .../vp9/encoder/x86/vp9_quantize_ssse3.c | 252 + .../encoder/x86/vp9_quantize_ssse3_x86_64.asm | 178 - libs/libvpx/vp9/ratectrl_rtc.cc | 220 +- libs/libvpx/vp9/ratectrl_rtc.h | 106 +- libs/libvpx/vp9/simple_encode.cc | 1330 ----- libs/libvpx/vp9/simple_encode.h | 583 --- libs/libvpx/vp9/vp9_common.mk | 2 + libs/libvpx/vp9/vp9_cx_iface.c | 869 ++-- libs/libvpx/vp9/vp9_dx_iface.c | 49 +- libs/libvpx/vp9/vp9_iface_common.c | 30 +- libs/libvpx/vp9/vp9cx.mk | 39 +- libs/libvpx/vpx/internal/vpx_codec_internal.h | 32 +- libs/libvpx/vpx/internal/vpx_ratectrl_rtc.h | 20 +- libs/libvpx/vpx/src/vpx_codec.c | 7 +- libs/libvpx/vpx/src/vpx_decoder.c | 7 +- libs/libvpx/vpx/src/vpx_encoder.c | 41 +- libs/libvpx/vpx/src/vpx_image.c | 167 +- libs/libvpx/vpx/vp8cx.h | 46 +- libs/libvpx/vpx/vp8dx.h | 7 +- libs/libvpx/vpx/vpx_codec.h | 20 +- libs/libvpx/vpx/vpx_codec.mk | 4 +- libs/libvpx/vpx/vpx_decoder.h | 16 +- libs/libvpx/vpx/vpx_encoder.h | 101 +- libs/libvpx/vpx/vpx_ext_ratectrl.h | 295 +- libs/libvpx/vpx/vpx_image.h | 76 +- libs/libvpx/vpx/vpx_integer.h | 6 +- libs/libvpx/vpx/vpx_tpl.h | 69 + libs/libvpx/vpx_dsp/arm/avg_neon.c | 125 +- libs/libvpx/vpx_dsp/arm/fdct16x16_neon.c | 387 +- libs/libvpx/vpx_dsp/arm/fdct16x16_neon.h | 423 +- libs/libvpx/vpx_dsp/arm/fdct32x32_neon.c | 1663 ++----- libs/libvpx/vpx_dsp/arm/fdct32x32_neon.h | 2867 +++++++++++ .../arm/{fdct_neon.c => fdct4x4_neon.c} | 43 +- libs/libvpx/vpx_dsp/arm/fdct4x4_neon.h | 105 + libs/libvpx/vpx_dsp/arm/fdct8x8_neon.c | 143 + libs/libvpx/vpx_dsp/arm/fdct8x8_neon.h | 307 ++ libs/libvpx/vpx_dsp/arm/fdct_neon.h | 713 ++- libs/libvpx/vpx_dsp/arm/fdct_partial_neon.c | 80 + libs/libvpx/vpx_dsp/arm/fwd_txfm_neon.c | 68 - libs/libvpx/vpx_dsp/arm/hadamard_neon.c | 42 + libs/libvpx/vpx_dsp/arm/highbd_avg_neon.c | 140 + .../libvpx/vpx_dsp/arm/highbd_avg_pred_neon.c | 64 + .../vpx_dsp/arm/highbd_convolve8_neon.h | 46 + .../libvpx/vpx_dsp/arm/highbd_convolve8_sve.h | 99 + .../libvpx/vpx_dsp/arm/highbd_hadamard_neon.c | 215 + .../vpx_dsp/arm/highbd_intrapred_neon.c | 1886 ++++++- .../libvpx/vpx_dsp/arm/highbd_quantize_neon.c | 300 ++ libs/libvpx/vpx_dsp/arm/highbd_sad4d_neon.c | 238 + libs/libvpx/vpx_dsp/arm/highbd_sad_neon.c | 452 ++ libs/libvpx/vpx_dsp/arm/highbd_sse_neon.c | 238 + .../vpx_dsp/arm/highbd_subpel_variance_neon.c | 586 +++ .../libvpx/vpx_dsp/arm/highbd_variance_neon.c | 436 ++ .../arm/highbd_variance_neon_dotprod.c | 96 + libs/libvpx/vpx_dsp/arm/highbd_variance_sve.c | 344 ++ .../vpx_dsp/arm/highbd_vpx_convolve8_neon.c | 1884 ++++--- .../vpx_dsp/arm/highbd_vpx_convolve8_sve.c | 271 + .../vpx_dsp/arm/highbd_vpx_convolve8_sve2.c | 660 +++ .../arm/highbd_vpx_convolve_copy_neon.c | 104 +- .../vpx_dsp/arm/highbd_vpx_convolve_neon.c | 58 - libs/libvpx/vpx_dsp/arm/intrapred_neon.c | 1621 ++++-- libs/libvpx/vpx_dsp/arm/loopfilter_neon.c | 2 +- libs/libvpx/vpx_dsp/arm/mem_neon.h | 581 ++- libs/libvpx/vpx_dsp/arm/quantize_neon.c | 311 +- libs/libvpx/vpx_dsp/arm/sad4d_neon.c | 774 +-- libs/libvpx/vpx_dsp/arm/sad4d_neon_dotprod.c | 181 + libs/libvpx/vpx_dsp/arm/sad_neon.c | 620 +-- libs/libvpx/vpx_dsp/arm/sad_neon_dotprod.c | 255 + libs/libvpx/vpx_dsp/arm/sse_neon.c | 188 + libs/libvpx/vpx_dsp/arm/sse_neon_dotprod.c | 197 + .../libvpx/vpx_dsp/arm/subpel_variance_neon.c | 499 +- .../libvpx/vpx_dsp/arm/subpel_variance_neon.h | 138 + .../arm/subpel_variance_neon_dotprod.c | 234 + libs/libvpx/vpx_dsp/arm/subtract_neon.c | 71 +- libs/libvpx/vpx_dsp/arm/sum_neon.h | 209 +- libs/libvpx/vpx_dsp/arm/sum_squares_neon.c | 157 +- libs/libvpx/vpx_dsp/arm/sum_squares_sve.c | 73 + libs/libvpx/vpx_dsp/arm/transpose_neon.h | 523 +- libs/libvpx/vpx_dsp/arm/variance_neon.c | 683 +-- .../vpx_dsp/arm/variance_neon_dotprod.c | 343 ++ libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon.c | 1843 ++----- libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon.h | 275 +- .../vpx_dsp/arm/vpx_convolve8_neon_dotprod.c | 1024 ++++ .../vpx_dsp/arm/vpx_convolve8_neon_i8mm.c | 943 ++++ .../vpx_dsp/arm/vpx_convolve_copy_neon.c | 5 +- libs/libvpx/vpx_dsp/arm/vpx_convolve_neon.c | 61 +- .../libvpx/vpx_dsp/arm/vpx_neon_sve2_bridge.h | 46 + libs/libvpx/vpx_dsp/arm/vpx_neon_sve_bridge.h | 56 + .../vpx_dsp/arm/vpx_scaled_convolve8_neon.c | 486 +- libs/libvpx/vpx_dsp/avg.c | 14 +- libs/libvpx/vpx_dsp/bitwriter.c | 21 +- libs/libvpx/vpx_dsp/bitwriter.h | 39 +- libs/libvpx/vpx_dsp/bitwriter_buffer.c | 21 +- libs/libvpx/vpx_dsp/bitwriter_buffer.h | 16 +- libs/libvpx/vpx_dsp/deblock.c | 5 - libs/libvpx/vpx_dsp/intrapred.c | 2 +- libs/libvpx/vpx_dsp/loongarch/quantize_lsx.c | 61 +- libs/libvpx/vpx_dsp/loopfilter.c | 12 +- libs/libvpx/vpx_dsp/mips/add_noise_msa.c | 26 + libs/libvpx/vpx_dsp/mips/deblock_msa.c | 149 +- libs/libvpx/vpx_dsp/mips/macros_msa.h | 120 +- libs/libvpx/vpx_dsp/mips/sad_mmi.c | 10 +- libs/libvpx/vpx_dsp/mips/sad_msa.c | 15 + libs/libvpx/vpx_dsp/mips/variance_mmi.c | 6 +- libs/libvpx/vpx_dsp/ppc/inv_txfm_vsx.c | 26 +- libs/libvpx/vpx_dsp/ppc/quantize_vsx.c | 24 +- libs/libvpx/vpx_dsp/ppc/sad_vsx.c | 28 +- libs/libvpx/vpx_dsp/ppc/types_vsx.h | 2 +- libs/libvpx/vpx_dsp/ppc/variance_vsx.c | 2 +- libs/libvpx/vpx_dsp/prob.h | 2 +- libs/libvpx/vpx_dsp/psnr.c | 82 +- libs/libvpx/vpx_dsp/psnr.h | 7 +- libs/libvpx/vpx_dsp/quantize.c | 65 +- libs/libvpx/vpx_dsp/sad.c | 65 +- libs/libvpx/vpx_dsp/sse.c | 59 + libs/libvpx/vpx_dsp/ssim.c | 15 - libs/libvpx/vpx_dsp/ssim.h | 2 +- libs/libvpx/vpx_dsp/variance.c | 30 +- libs/libvpx/vpx_dsp/variance.h | 4 + libs/libvpx/vpx_dsp/vpx_dsp.mk | 88 +- libs/libvpx/vpx_dsp/vpx_dsp_common.h | 19 + libs/libvpx/vpx_dsp/vpx_dsp_rtcd.c | 2 +- libs/libvpx/vpx_dsp/vpx_dsp_rtcd_defs.pl | 997 ++-- libs/libvpx/vpx_dsp/vpx_filter.h | 13 +- libs/libvpx/vpx_dsp/x86/add_noise_sse2.asm | 32 +- libs/libvpx/vpx_dsp/x86/avg_intrin_avx2.c | 58 +- libs/libvpx/vpx_dsp/x86/avg_intrin_sse2.c | 58 +- libs/libvpx/vpx_dsp/x86/avg_pred_avx2.c | 111 + libs/libvpx/vpx_dsp/x86/convolve_avx2.h | 5 +- libs/libvpx/vpx_dsp/x86/deblock_sse2.asm | 432 -- libs/libvpx/vpx_dsp/x86/deblock_sse2.c | 378 ++ .../vpx_dsp/x86/fwd_dct32x32_impl_avx2.h | 2 +- .../vpx_dsp/x86/fwd_dct32x32_impl_sse2.h | 2 +- libs/libvpx/vpx_dsp/x86/fwd_txfm_avx2.c | 374 ++ .../libvpx/vpx_dsp/x86/highbd_convolve_avx2.c | 2 + .../x86/highbd_intrapred_intrin_avx2.c | 288 ++ .../x86/highbd_intrapred_intrin_avx512.c | 164 + .../vpx_dsp/x86/highbd_intrapred_sse2.asm | 4 +- .../libvpx/vpx_dsp/x86/highbd_inv_txfm_sse2.h | 2 +- .../vpx_dsp/x86/highbd_loopfilter_sse2.c | 8 +- .../vpx_dsp/x86/highbd_quantize_intrin_avx2.c | 254 + .../vpx_dsp/x86/highbd_quantize_intrin_sse2.c | 53 +- libs/libvpx/vpx_dsp/x86/highbd_sad4d_avx2.c | 462 ++ libs/libvpx/vpx_dsp/x86/highbd_sad4d_sse2.asm | 43 +- libs/libvpx/vpx_dsp/x86/highbd_sad_avx2.c | 522 ++ libs/libvpx/vpx_dsp/x86/highbd_sad_sse2.asm | 59 +- .../libvpx/vpx_dsp/x86/highbd_variance_sse2.c | 49 + libs/libvpx/vpx_dsp/x86/inv_txfm_avx2.c | 626 +++ libs/libvpx/vpx_dsp/x86/inv_txfm_sse2.c | 4 +- libs/libvpx/vpx_dsp/x86/loopfilter_avx2.c | 4 +- libs/libvpx/vpx_dsp/x86/loopfilter_sse2.c | 14 +- libs/libvpx/vpx_dsp/x86/mem_sse2.h | 4 +- libs/libvpx/vpx_dsp/x86/post_proc_sse2.c | 141 - libs/libvpx/vpx_dsp/x86/quantize_avx.c | 63 +- libs/libvpx/vpx_dsp/x86/quantize_avx2.c | 290 ++ libs/libvpx/vpx_dsp/x86/quantize_sse2.c | 22 +- libs/libvpx/vpx_dsp/x86/quantize_sse2.h | 60 +- libs/libvpx/vpx_dsp/x86/quantize_ssse3.c | 62 +- libs/libvpx/vpx_dsp/x86/sad4d_avx2.c | 66 +- libs/libvpx/vpx_dsp/x86/sad4d_avx512.c | 30 +- libs/libvpx/vpx_dsp/x86/sad4d_sse2.asm | 43 +- libs/libvpx/vpx_dsp/x86/sad_avx2.c | 164 +- libs/libvpx/vpx_dsp/x86/sad_avx512.c | 96 + libs/libvpx/vpx_dsp/x86/sad_sse2.asm | 81 +- libs/libvpx/vpx_dsp/x86/sse_avx2.c | 368 ++ libs/libvpx/vpx_dsp/x86/sse_sse4.c | 312 ++ libs/libvpx/vpx_dsp/x86/ssim_opt_x86_64.asm | 92 +- libs/libvpx/vpx_dsp/x86/subtract_avx2.c | 208 + libs/libvpx/vpx_dsp/x86/subtract_sse2.asm | 1 + libs/libvpx/vpx_dsp/x86/sum_squares_sse2.c | 2 +- libs/libvpx/vpx_dsp/x86/variance_avx2.c | 97 +- libs/libvpx/vpx_dsp/x86/variance_sse2.c | 14 +- .../vpx_dsp/x86/vpx_subpixel_4t_intrin_sse2.c | 6 +- .../vpx_dsp/x86/vpx_subpixel_8t_intrin_avx2.c | 625 ++- .../x86/vpx_subpixel_8t_intrin_ssse3.c | 6 +- libs/libvpx/vpx_mem/include/vpx_mem_intrnl.h | 2 +- libs/libvpx/vpx_ports/aarch32_cpudetect.c | 90 + libs/libvpx/vpx_ports/aarch64_cpudetect.c | 241 + libs/libvpx/vpx_ports/arm.h | 16 +- libs/libvpx/vpx_ports/arm_cpudetect.c | 154 - libs/libvpx/vpx_ports/arm_cpudetect.h | 52 + libs/libvpx/vpx_ports/bitops.h | 2 - libs/libvpx/vpx_ports/compiler_attributes.h | 12 +- libs/libvpx/vpx_ports/emms_mmx.c | 2 +- libs/libvpx/vpx_ports/mem.h | 14 +- libs/libvpx/vpx_ports/msvc.h | 32 - libs/libvpx/vpx_ports/vpx_once.h | 23 - libs/libvpx/vpx_ports/vpx_ports.mk | 8 +- libs/libvpx/vpx_ports/vpx_timer.h | 32 +- libs/libvpx/vpx_ports/x86.h | 82 +- libs/libvpx/vpx_ports/x86_abi_support.asm | 4 + libs/libvpx/vpx_scale/generic/vpx_scale.c | 5 +- libs/libvpx/vpx_scale/generic/yv12config.c | 5 +- libs/libvpx/vpx_scale/vpx_scale.h | 2 - libs/libvpx/vpx_scale/vpx_scale_rtcd.c | 2 +- libs/libvpx/vpx_util/vpx_atomics.h | 3 +- libs/libvpx/vpx_util/vpx_pthread.h | 154 + libs/libvpx/vpx_util/vpx_thread.c | 95 +- libs/libvpx/vpx_util/vpx_thread.h | 366 +- libs/libvpx/vpx_util/vpx_util.mk | 1 + libs/libvpx/vpxdec.c | 36 +- libs/libvpx/vpxenc.c | 43 +- libs/libvpx/webmdec.cc | 2 +- libs/libvpx/webmdec.h | 2 +- libs/libvpx/y4menc.c | 42 +- libs/libvpx/y4minput.c | 34 +- libs/win32/libvpx/include_x64/vp8_rtcd.h | 21 +- libs/win32/libvpx/include_x64/vp9_rtcd.h | 68 +- .../win32/libvpx/include_x64/vpx/vpx_config.h | 12 +- libs/win32/libvpx/include_x64/vpx_config.asm | 12 +- libs/win32/libvpx/include_x64/vpx_config.h | 12 +- libs/win32/libvpx/include_x64/vpx_dsp_rtcd.h | 296 +- .../win32/libvpx/include_x64/vpx_scale_rtcd.h | 12 +- libs/win32/libvpx/include_x86/vp8_rtcd.h | 21 +- libs/win32/libvpx/include_x86/vp9_rtcd.h | 69 +- .../win32/libvpx/include_x86/vpx/vpx_config.h | 12 +- libs/win32/libvpx/include_x86/vpx_config.asm | 12 +- libs/win32/libvpx/include_x86/vpx_config.h | 12 +- libs/win32/libvpx/include_x86/vpx_dsp_rtcd.h | 328 +- .../win32/libvpx/include_x86/vpx_scale_rtcd.h | 12 +- libs/win32/libvpx/libvpx.2017.vcxproj | 82 +- libs/win32/libvpx/vpx_version.h | 9 +- 615 files changed, 68654 insertions(+), 28912 deletions(-) delete mode 100644 libs/libvpx/examples/resize_util.c create mode 100644 libs/libvpx/examples/vpx_enc_fuzzer.cc create mode 100644 libs/libvpx/test/init_vpx_test.cc create mode 100644 libs/libvpx/test/init_vpx_test.h create mode 100644 libs/libvpx/test/mfqe_test.cc create mode 100644 libs/libvpx/test/postproc_test.cc delete mode 100755 libs/libvpx/test/resize_util.sh delete mode 100644 libs/libvpx/test/simple_encode_test.cc create mode 100644 libs/libvpx/test/vp8_loopfilter_simple_test.cc create mode 100755 libs/libvpx/test/vp9_c_vs_simd_encode.sh create mode 100644 libs/libvpx/test/vp9_entropy_test.cc create mode 100644 libs/libvpx/test/vp9_scan_test.cc create mode 100644 libs/libvpx/test/vp9_tokenize_test.cc create mode 100644 libs/libvpx/test/vpx_image_test.cc create mode 100644 libs/libvpx/third_party/googletest/googletest.patch create mode 100644 libs/libvpx/third_party/googletest/src/.clang-format create mode 100644 libs/libvpx/third_party/googletest/src/include/gtest/gtest-assertion-result.h create mode 100644 libs/libvpx/third_party/googletest/src/src/gtest-assertion-result.cc create mode 100644 libs/libvpx/third_party/nalloc/LICENSE create mode 100644 libs/libvpx/third_party/nalloc/README.libvpx create mode 100644 libs/libvpx/third_party/nalloc/nalloc.h create mode 100644 libs/libvpx/tools/README.pgo.md rename libs/libvpx/vp8/encoder/loongarch/{quantize_lsx.c => vp8_quantize_lsx.c} (79%) create mode 100644 libs/libvpx/vp9/encoder/arm/neon/vp9_diamond_search_sad_neon.c create mode 100644 libs/libvpx/vp9/encoder/arm/neon/vp9_error_sve.c create mode 100644 libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_error_neon.c create mode 100644 libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_temporal_filter_neon.c create mode 100644 libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_temporal_filter_sve2.c create mode 100644 libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon.c create mode 100644 libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon_dotprod.c create mode 100644 libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon_i8mm.c create mode 100644 libs/libvpx/vp9/encoder/vp9_firstpass_stats.h rename libs/libvpx/vp9/encoder/{x86/temporal_filter_constants.h => vp9_temporal_filter_constants.h} (95%) create mode 100644 libs/libvpx/vp9/encoder/vp9_tpl_model.c create mode 100644 libs/libvpx/vp9/encoder/vp9_tpl_model.h create mode 100644 libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_avx2.c create mode 100644 libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_ssse3.c create mode 100644 libs/libvpx/vp9/encoder/x86/temporal_filter_avx2.c create mode 100644 libs/libvpx/vp9/encoder/x86/temporal_filter_ssse3.c delete mode 100644 libs/libvpx/vp9/encoder/x86/vp9_diamond_search_sad_avx.c create mode 100644 libs/libvpx/vp9/encoder/x86/vp9_quantize_ssse3.c delete mode 100644 libs/libvpx/vp9/encoder/x86/vp9_quantize_ssse3_x86_64.asm delete mode 100644 libs/libvpx/vp9/simple_encode.cc delete mode 100644 libs/libvpx/vp9/simple_encode.h create mode 100644 libs/libvpx/vpx/vpx_tpl.h create mode 100644 libs/libvpx/vpx_dsp/arm/fdct32x32_neon.h rename libs/libvpx/vpx_dsp/arm/{fdct_neon.c => fdct4x4_neon.c} (56%) create mode 100644 libs/libvpx/vpx_dsp/arm/fdct4x4_neon.h create mode 100644 libs/libvpx/vpx_dsp/arm/fdct8x8_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/fdct8x8_neon.h delete mode 100644 libs/libvpx/vpx_dsp/arm/fwd_txfm_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_avg_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_avg_pred_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_convolve8_neon.h create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_convolve8_sve.h create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_hadamard_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_quantize_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_sad4d_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_sad_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_sse_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_subpel_variance_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_variance_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_variance_neon_dotprod.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_variance_sve.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_sve.c create mode 100644 libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_sve2.c delete mode 100644 libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/sad4d_neon_dotprod.c create mode 100644 libs/libvpx/vpx_dsp/arm/sad_neon_dotprod.c create mode 100644 libs/libvpx/vpx_dsp/arm/sse_neon.c create mode 100644 libs/libvpx/vpx_dsp/arm/sse_neon_dotprod.c create mode 100644 libs/libvpx/vpx_dsp/arm/subpel_variance_neon.h create mode 100644 libs/libvpx/vpx_dsp/arm/subpel_variance_neon_dotprod.c create mode 100644 libs/libvpx/vpx_dsp/arm/sum_squares_sve.c create mode 100644 libs/libvpx/vpx_dsp/arm/variance_neon_dotprod.c create mode 100644 libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon_dotprod.c create mode 100644 libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon_i8mm.c create mode 100644 libs/libvpx/vpx_dsp/arm/vpx_neon_sve2_bridge.h create mode 100644 libs/libvpx/vpx_dsp/arm/vpx_neon_sve_bridge.h create mode 100644 libs/libvpx/vpx_dsp/sse.c create mode 100644 libs/libvpx/vpx_dsp/x86/avg_pred_avx2.c delete mode 100644 libs/libvpx/vpx_dsp/x86/deblock_sse2.asm create mode 100644 libs/libvpx/vpx_dsp/x86/deblock_sse2.c create mode 100644 libs/libvpx/vpx_dsp/x86/highbd_intrapred_intrin_avx2.c create mode 100644 libs/libvpx/vpx_dsp/x86/highbd_intrapred_intrin_avx512.c create mode 100644 libs/libvpx/vpx_dsp/x86/highbd_quantize_intrin_avx2.c create mode 100644 libs/libvpx/vpx_dsp/x86/highbd_sad4d_avx2.c create mode 100644 libs/libvpx/vpx_dsp/x86/highbd_sad_avx2.c create mode 100644 libs/libvpx/vpx_dsp/x86/inv_txfm_avx2.c delete mode 100644 libs/libvpx/vpx_dsp/x86/post_proc_sse2.c create mode 100644 libs/libvpx/vpx_dsp/x86/quantize_avx2.c create mode 100644 libs/libvpx/vpx_dsp/x86/sad_avx512.c create mode 100644 libs/libvpx/vpx_dsp/x86/sse_avx2.c create mode 100644 libs/libvpx/vpx_dsp/x86/sse_sse4.c create mode 100644 libs/libvpx/vpx_dsp/x86/subtract_avx2.c create mode 100644 libs/libvpx/vpx_ports/aarch32_cpudetect.c create mode 100644 libs/libvpx/vpx_ports/aarch64_cpudetect.c delete mode 100644 libs/libvpx/vpx_ports/arm_cpudetect.c create mode 100644 libs/libvpx/vpx_ports/arm_cpudetect.h delete mode 100644 libs/libvpx/vpx_ports/msvc.h create mode 100644 libs/libvpx/vpx_util/vpx_pthread.h diff --git a/libs/libvpx/.mailmap b/libs/libvpx/.mailmap index 376ca83ae3..2fc6c7d39d 100644 --- a/libs/libvpx/.mailmap +++ b/libs/libvpx/.mailmap @@ -5,6 +5,7 @@ Aℓex Converse Alexis Ballier Alpha Lam Angie Chiang +Bohan Li Chris Cunningham Chi Yo Tsai Daniele Castagna @@ -20,11 +21,13 @@ Hui Su Jacky Chen Jim Bankoski Johann Koenig +Johann Koenig Johann Koenig -Johann Koenig Johann Koenig +Johann John Koleszar Joshua Litt +Konstantinos Margaritis Marco Paniconi Marco Paniconi Martin Storsjö @@ -52,4 +55,4 @@ Yaowu Xu Yaowu Xu Venkatarama NG. Avadhani Vitaly Buka -xiwei gu +Xiwei Gu diff --git a/libs/libvpx/.update b/libs/libvpx/.update index 630407d292..76dafdcd5f 100644 --- a/libs/libvpx/.update +++ b/libs/libvpx/.update @@ -1 +1 @@ -Mon Jul 06 01:46:10 UTC 2026 +Mon 09 Nov 2026 11:33:20 PM UTC diff --git a/libs/libvpx/AUTHORS b/libs/libvpx/AUTHORS index fffda63360..f01bca461d 100644 --- a/libs/libvpx/AUTHORS +++ b/libs/libvpx/AUTHORS @@ -12,38 +12,53 @@ Alexander Potapenko Alexander Voronov Alexandra Hájková Aℓex Converse +Alex Davicenko Alexis Ballier Alok Ahuja Alpha Lam A.Mahfoodh Ami Fischman Andoni Morales Alastruey +Andres Calderon Jaramillo Andres Mejia Andrew Lewis Andrew Russell +Andrew Salkeld +Andrey Filipenkov Angie Chen Angie Chiang +Anton Venema +Anupam Pandey Aron Rosenberg Attila Nagy Birk Magnussen Bohan Li Brian Foley Brion Vibber +Casey Smalley changjun.yang Charles 'Buck' Krasic Cheng Chen +Chen Wang +Cherma Rajan A Chi Yo Tsai chm Chris Cunningham Christian Duvivier Chunbo Hua +Chun-Min Chang Clement Courbet +CodeByMoriarty +Daniel Cheng Daniele Castagna Daniel Kang Daniel Sommermann Dan Zhu +Darryl Pogue +David Benjamin Deb Mukherjee Deepa K G +Diksha Singh Dim Temp Dmitry Kovalev Dragan Mrdjan @@ -52,12 +67,16 @@ Ehsan Akhgari Elliott Karpilovsky Erik Niemeyer Fabio Pedretti +Feng, Feifei +Florian Mayer Frank Galligan Fredrik Söderquist Fritz Koenig Fyodor Kyslov Gabriel Marin Gaute Strokkenes +George Steed +Gerda Zsejke More Geza Lore Ghislain MARY Giuseppe Scrivano @@ -65,10 +84,12 @@ Gordana Cmiljanovic Gregor Jasny Guillaume Martres Guillermo Ballester Valor +Hang Nguyen Hangyu Kuang Hanno Böck Han Shen Hao Chen +Hari Limaye Harish Mahendrakar Henrik Lundin Hien Ho @@ -84,12 +105,14 @@ James Touton James Yu James Zern Jan Gerber +Jan-Ivar Bruaroey Jan Kratochvil Janne Salonen Jean-Yves Avenard Jeff Faust Jeff Muizelaar Jeff Petkau +Jeremy Dorfman Jeremy Leconte Jerome Jiang Jia Jia @@ -101,6 +124,7 @@ Jin Bo Jingning Han Joel Fernandes Joey Parrish +Johann Johann Koenig John Koleszar Johnny Klonaris @@ -114,12 +138,16 @@ Julia Robson Justin Clift Justin Lebar Kaustubh Raste +Kexy Biscuit KO Myung-Hun Konstantinos Margaritis Kyle Siefring Lawrence Velázquez +L. E. Segovia Linfeng Zhang +Lin Zheng Liu Peng +Li Zhang Lou Quillio Luca Barbato Luc Trudeau @@ -134,6 +162,7 @@ Matthew Heaney Matthias Räncker Michael Horowitz Michael Kohler +Michał Janiszewski Mike Frysinger Mike Hommey Mikhal Shemer @@ -145,6 +174,7 @@ Mirko Bonadei Moriyoshi Koizumi Morton Jonuschat Nathan E. Egge +Neeraj Gadgil Neil Birkbeck Nico Weber Niveditha Rau @@ -160,12 +190,15 @@ Peter Collingbourne Peter de Rivaz Peter Kasting Philip Jägenstedt +Philippe Antoine +Philipp Hancke Priit Laes Rafael Ávila de Espíndola Rafaël Carré Rafael de Lucena Valle Rahul Chaudhry Ralph Giles +Ram Mohan M Ranjit Kumar Tulabandu Raphael Kubo da Costa Ravi Chaudhary @@ -174,7 +207,9 @@ Rob Bradford Ronald S. Bultje Rui Ueyama Sai Deng +Salome Thirot Sami Pietilä +Sam James Sarah Parker Sasi Inguva Scott Graham @@ -209,9 +244,11 @@ Vitaly Buka Vlad Tsyrklevich Wan-Teh Chang Wonkap Jang -xiwei gu +Xiahong Bao +Xiwei Gu Yaowu Xu Yi Luo +Yongseok Jeon Yongzhe Wang yuanhecai Yue Chen @@ -219,6 +256,8 @@ Yun Liu Yunqing Wang Yury Gitman Zoe Liu +Zoltan Kuscsik +zuxy Google Inc. The Mozilla Foundation The Xiph.Org Foundation diff --git a/libs/libvpx/CHANGELOG b/libs/libvpx/CHANGELOG index cd4e8ba43a..8abd912f21 100644 --- a/libs/libvpx/CHANGELOG +++ b/libs/libvpx/CHANGELOG @@ -1,3 +1,362 @@ +2026-08-07 v1.17.0 "Yellowbilled Duck" + This release includes a new encoder control to validate high bitdepth input, + additional Neon and AVX2/AVX512 optimizations, support for the C11 standard, + and numerous bug fixes. + + - Upgrading: + This release is ABI compatible with the previous release. + + ISO C11 standard is now enforced for C files. + + SVC is now strictly disallowed for 2-pass encoding; enabling it will return + VPX_CODEC_INVALID_PARAM. + + VP9 High Bitdepth (HBD) input validation is now enabled by default. If the + input contains values outside the valid range, the encoder will return + VPX_CODEC_INVALID_PARAM. Use the new VP9E_SET_VALIDATE_HBD_INPUT control + (or vpxenc --validate-hbd-input=0) to disable this validation. + + VP9 now sets the returned image width (w) and height (h) to the actual + width and height, rather than the stride and aligned height. This is a + behavior change that may affect applications relying on w being equal to the + stride or h being the aligned height. + + Strict validation has been added to some APIs: + - Encoders (VP8/VP9) now reject input images with unequal U and V strides. + - vpx_img_alloc() and vpx_img_wrap() now strictly validate the image format. + - External rate control (RTC) API now validates configuration inputs. + - VP9 SVC now validates spatial layer ID input. + + - Enhancement: + Added Arm Neon DotProd subpel variance paths. + Optimized Neon HBD sadx4d and sad_skipx4d functions. + Added AVX2/AVX512 implementations for various vpx_highbd predictor + functions. + Added support for MSVC v145 (Visual Studio 2026). + Added configure option --disable-x86-asm. + + - Bug fixes: + Fix to heap buffer overflow / out-of-bounds write in vp9_postproc, + vp8-multi-res-encoding, vpx_setup_noise, set_mb_ssim_rdmult_scaling, + vp9_change_config (resolution change), vp9_dec_alloc_row_mt_mem (decode + coeffs), and vp8_sixtap_predict (LoongArch). + + Fix to integer overflow in vp9-svc (layer resolution, duration), + set_mb_ssim_rdmult_scaling, vp8_encode_frame, calc_pframe_target_size, + y4minput buffer size calculations, and get_token_alloc. + + Fix to VP8 decoder crash on flush with no fragments. + Fix to VP8 decoder potential hang/slowdown with corrupt partition 0 size. + Fix to VP9 decoder crash with invalid reference frame index. + Fix to VP9 highbitdepth encoder format mismatch. + Fix to VP9 float-to-int overflow in validate_config (EOS count) and with + zero bitrate. + + Fix to VP8 decoder multithreading corruption flag reset at start of + frame. + Fix to VP8 decoder accepting inter frames on resolution change before + keyframe. + Fix to VP8 encoder reference frame dimension validation. + Fix to VP8 encoder temporal layer ID validation. + Fix to VP8 encoder missing setjmp in VP8E_SET_SCALEMODE. + + Fix to VP9 SVC encoder crash with dynamic resize and cyclic refresh + (aq_mode=3). + Fix to VP9 1-pass rate control last_boosted_qindex clamping and + VP9E_SET_QUANTIZER_ONE_PASS validation. + + Fix to NV12 x_chroma_shift calculation in vpx_image and image2yuvconfig. + Fix to AVX-512 CPU feature detection on older x86 CPUs. + Fix to x86_abi_support.asm placing read-only data tables in .rdata for + Windows. + Fix to configure disabling _FORTIFY_SOURCE on Linux. + Fix to file leaks on error paths in vpxdec and video reader/writer + utilities. + + Fix to crash/undefined behavior in vpx_img_flip with formats without alpha. + +2026-01-06 v1.16.0 "Xenonetta Duck" + This release includes Arm SVE2 and Neon optimizations for 12-tap filters, + AVX512 implementations for SAD, support for per-frame and per-spatial-layer + PSNR calculation, and numerous bug fixes. + + - Upgrading: + This release is ABI incompatible with the previous release. + + Unit tests require C++17 to build. + + Support for 32-bit iOS targets (armv7, armv7s, and i386) has been removed. + + - Enhancement: + Optimized Arm SVE2 and Neon implementations for 12-tap convolution filters. + Optimized Neon High Bitdepth (HBD) SAD and sad_avg functions. + Added Arm Neon DotProd and I8MM implementations for vpx_convolve12. + Added AVX512 implementations for SAD64 and sad_skip functions. + Added SSSE3 and AVX2 implementations for 12-tap temporal filter prediction. + Added support for per-frame and per-spatial-layer PSNR calculation. + + Adjusted temporal filter strength to improve visual quality and reduce block + artifacts. + + Added support for darwin24 (macOS 15) and darwin25 (macOS 26). + libwebm is upgraded to commit b4f01ea. + + - Bug fixes: + Fix to heap buffer overflow in vp9_deblock, vp9_post_proc_frame, and + vp9_pack_bitstream. + + Fix to integer overflow in vp9_highbd_post_proc, vp9_rc_regulate_q, + tiny_ssim, and vp9_calc_pframe_target_size_one_pass_cbr. + + Fix to use-of-uninitialized-value in vp9_highbd_post_proc, mfqe, and + vp8_datarate_test. + + Fix to out-of-bounds in log_tile_cols_from_picsize_level. + Fix to double free on initialization failure in vpx_codec_enc_init_multi. + Fix to division-by-zero crash in vpxenc with 0 FPS numerator input. + + Fix to various build failures for Arm/SVE2, macOS cross-compilation, and + Xcode 16. + +2025-05-28 v1.15.2 "Wigeon Duck" + This release fixes CVE-2025-5283 (bug webm:413411335), and is ABI compatible + with the previous release. + +2025-01-09 v1.15.1 "Wigeon Duck" + This release bumps up the SO major version and fixes the language about ABI + compatibility in the previous release changelog. + +2024-10-22 v1.15.0 "Wigeon Duck" + This release includes new codec control for key frame filtering, more Neon + optimizations, improvements to RTC encoding and bug fixes. + + - Upgrading: + This release is ABI incompatible with the previous release. + + It is strongly recommended to skip this release and upgrade to v1.15.1 since + the shared object was versioned incorrectly, as shown in + https://issues.webmproject.org/issues/384672478. + + Temporal filtering improvement that can be turned on with the new codec + control VP9E_SET_KEY_FRAME_FILTERING, which gives 1+% BD-rate saving with + minimal encoder time increase. + + libwebm is upgraded to libwebm-1.0.0.31-10-g3b63004 + + - Enhancement: + Neon optimization speed up + 1-3% speed up across speed 5 to 10 for RTC + 3% speed up for speed 0 and 1 for VoD in standard bitdepth + 3% and 7% speed up for speed 0 and 1 respectively for VoD in high bitdepth + Scene detection is allowed for all RTC speeds (>=5) + Support profile guided optimizations + + Delta quantization parameters for UV channels for vp8 is supported in RTC + rate control library + + Rate control parameters are reset and maximum QP is enforced on scene + changes in SVC when there is no inter-layer prediction + + - Bug fixes: + Fix to Uninitialized scalar variable in `vp9_rd_pick_inter_mode_sb()` + Fix to Integer-overflow in `resize_multistep` + Fix to Heap-buffer-overflow in `vpx_sad64x64_avx2` + Fix to Crash in `vpx_sad8x8_sse2` + Fix to Assertion in `write_modes` + Support profile guided optimizations + Fix to Integer-overflow in `encode_frame_to_data_rate` + Fix to Integer-overflow in `vp9_svc_check_reset_layer_rc_flag` + Fix to core dump error from /usr/bin/tools/tiny_ssim --help + Fix to use-of-uninitialized-value in `vp9_setup_tpl_stats` + Fix to Undefined-shift in `vp9_cyclic_refresh_setup` + Fix to redundant `&& __GNUC__` preproc check + Fix to valgrind warning in EncodeAPI.OssFuzz69906 + Fix to Index-out-of-bounds in `vp8_rd_pick_inter_mode` + Fix to Integer-overflow in `vp8_pick_frame_size` + Fix to Use-of-uninitialized-value in `vpx_codec_peek_stream_info` + Fix to log clutters with the message "Warning: Desired height too large" + Fix to Integer-overflow in `vp9_svc_adjust_avg_frame_qindex` + + Fix to integer overflows caused by huge target bitrate, frame rate, or + g_timebase numerator or denominator + + Fix to missing license headers + Fix to build failure for Android Armv7 + Fix to integer overflows in image helpers + Fix to Integer-overflow in `vp9_calc_iframe_target_size_one_pass_cbr` + Fix to Heap-buffer-overflow in `vp9_pick_inter_mode` + Fix to Segv in `vp9_multi_thread_tile_init` + Fix to Use-of-uninitialized-value in `vp9_row_mt_sync_mem_dealloc` + Fix to Crash in `mbloop_filter_vertical_edge_c` + Fix to Check failed in CheckUnwind + Fix to Heap-buffer-overflow in `write_modes_b` and `vpx_write` + Fix to Possible signed integer overflow found in `vpx_codec_encode` + Fix to build conflicts between Abseil and libaom/libvpx in Win ARM64 builds + Fix to build failures on aarch64 + Fix to Data race in libvpx ARM NEON + Fix to Heap-buffer-overflow in `scale_plane_1_to_2_phase_0` + Fix to integer overflow in `encode_mb_row` + Fix to Floating-point-exception in `vp8_pick_frame_size` + Fix to Heap-buffer-overflow in `vp9_enc_setup_mi` + Fix to build failure with --target=arm64-win64-vs17 + Fix to heap-buffer-overflow write in `vpx_img_read()` + Fix to C vs armv8-linux-gcc encode mismatches for `y4m_360p_10bit_input` + Fix to Null-dereference READ in `ml_predict_var_rd_partitioning` + Fix to Heap-buffer-overflow in `vpx_scaled_2d_ssse3` + Fix to Crash in `convolve_horiz` + Fix to Ill in `vpx_scaled_2d_ssse3` + Fix to Global-buffer-overflow in `cost_coeffs` + +2024-05-21 v1.14.1 "Venetian Duck" + This release includes enhancements and bug fixes. + + - Upgrading: + This release is ABI compatible with the previous release. + + - Enhancement: + Improved the detection of compiler support for AArch64 extensions, + particularly SVE. + + Added vpx_codec_get_global_headers() support for VP9. + + - Bug fixes: + Added buffer bounds checks to vpx_writer and vpx_write_bit_buffer. + Fix to GetSegmentationData() crash in aq_mode=0 for RTC rate control. + Fix to alloc for row_base_thresh_freq_fac. + Free row mt memory before freeing cpi->tile_data. + Fix to buffer alloc for vp9_bitstream_worker_data. + Fix to VP8 race issue for multi-thread with pnsr_calc. + Fix to uv width/height in vp9_scale_and_extend_frame_ssse3. + Fix to integer division by zero and overflow in calc_pframe_target_size(). + Fix to integer overflow in vpx_img_alloc() & vpx_img_wrap()(CVE-2024-5197). + Fix to UBSan error in vp9_rc_update_framerate(). + Fix to UBSan errors in vp8_new_framerate(). + Fix to integer overflow in vp8 encodeframe.c. + Handle EINTR from sem_wait(). + +2024-01-02 v1.14.0 "Venetian Duck" + This release drops support for old C compilers, such as Visual Studio 2012 + and older, that disallow mixing variable declarations and statements (a C99 + feature). It adds support for run-time CPU feature detection for Arm + platforms, as well as support for darwin23 (macOS 14). + + - Upgrading: + This release is ABI incompatible with the previous release. + + Various new features for rate control library for real-time: SVC parallel + encoding, loopfilter level, support for frame dropping, and screen content. + + New callback function send_tpl_gop_stats for vp9 external rate control + library, which can be used to transmit TPL stats for a group of pictures. A + public header vpx_tpl.h is added for the definition of TPL stats used in + this callback. + + libwebm is upgraded to libwebm-1.0.0.29-9-g1930e3c. + + - Enhancement: + Improvements on Neon optimizations: VoD: 12-35% speed up for bitdepth 8, + 68%-151% speed up for high bitdepth. + + Improvements on AVX2 and SSE optimizations. + Improvements on LSX optimizations for LoongArch. + 42-49% speedup on speed 0 VoD encoding. + Android API level predicates. + + - Bug fixes: + Fix to missing prototypes from the rtcd header. + Fix to segfault when total size is enlarged but width is smaller. + Fix to the build for arm64ec using MSVC. + Fix to copy BLOCK_8X8's mi to PICK_MODE_CONTEXT::mic. + Fix to -Wshadow warnings. + Fix to heap overflow in vpx_get4x4sse_cs_neon. + Fix to buffer overrun in highbd Neon subpel variance filters. + Added bitexact encode test script. + Fix to -Wl,-z,defs with Clang's sanitizers. + Fix to decoder stability after error & continued decoding. + Fix to mismatch of VP9 encode with NEON intrinsics with C only version. + Fix to Arm64 MSVC compile vpx_highbd_fdct4x4_neon. + Fix to fragments count before use. + Fix to a case where target bandwidth is 0 for SVC. + Fix mask in vp9_quantize_avx2,highbd_get_max_lane_eob. + Fix to int overflow in vp9_calc_pframe_target_size_one_pass_cbr. + Fix to integer overflow in vp8,ratectrl.c. + Fix to integer overflow in vp9 svc. + Fix to avg_frame_bandwidth overflow. + Fix to per frame qp for temporal layers. + Fix to unsigned integer overflow in sse computation. + Fix to uninitialized mesh feature for BEST mode. + Fix to overflow in highbd temporal_filter. + Fix to unaligned loads w/w==4 in vpx_convolve_copy_neon. + Skip arm64_neon.h workaround w/VS >= 2019. + Fix to c vs avx mismatch of diamond_search_sad(). + Fix to c vs intrinsic mismatch of vpx_hadamard_32x32() function. + Fix to a bug in vpx_hadamard_32x32_neon(). + Fix to Clang -Wunreachable-code-aggressive warnings. + Fix to a bug in vpx_highbd_hadamard_32x32_neon(). + Fix to -Wunreachable-code in mfqe_partition. + Force mode search on 64x64 if no mode is selected. + Fix to ubsan failure caused by left shift of negative. + Fix to integer overflow in calc_pframe_target_size. + Fix to float-cast-overflow in vp8_change_config(). + Fix to a null ptr before use. + Conditionally skip using inter frames in speed features. + Remove invalid reference frames. + Disable intra mode search speed features conditionally. + Set nonrd keyframe under dynamic change of deadline for rtc. + Fix to scaled reference offsets. + Set skip_recode=0 in nonrd_pick_sb_modes. + Fix to an edge case when downsizing to one. + Fix to a bug in frame scaling. + Fix to pred buffer stride. + Fix to a bug in simple motion search. + Update frame size in actual encoding. + +2023-09-29 v1.13.1 "Ugly Duckling" + This release contains two security related fixes. One each for VP8 and VP9. + + - Upgrading: + This release is ABI compatible with the previous release. + + - Bug fixes: + https://crbug.com/1486441 (CVE-2023-5217) + Fix to a crash related to VP9 encoding (#1642, CVE-2023-6349) + +2023-01-31 v1.13.0 "Ugly Duckling" + This release includes more Neon and AVX2 optimizations, adds a new codec + control to set per frame QP, upgrades GoogleTest to v1.12.1, and includes + numerous bug fixes. + + - Upgrading: + This release is ABI incompatible with the previous release. + + New codec control VP9E_SET_QUANTIZER_ONE_PASS to set per frame QP. + + GoogleTest is upgraded to v1.12.1. + + .clang-format is upgraded to clang-format-11. + + VPX_EXT_RATECTRL_ABI_VERSION was bumped due to incompatible changes to the + feature of using external rate control models for vp9. + + - Enhancement: + Numerous improvements on Neon optimizations. + Numerous improvements on AVX2 optimizations. + Additional ARM targets added for Visual Studio. + + - Bug fixes: + Fix to calculating internal stats when frame dropped. + Fix to segfault for external resize test in vp9. + Fix to build system with replacing egrep with grep -E. + Fix to a few bugs with external RTC rate control library. + Fix to make SVC work with VBR. + Fix to key frame setting in VP9 external RC. + Fix to -Wimplicit-int (Clang 16). + Fix to VP8 external RC for buffer levels. + Fix to VP8 external RC for dynamic update of layers. + Fix to VP9 auto level. + Fix to off-by-one error of max w/h in validate_config. + Fix to make SVC work for Profile 1. + 2022-06-17 v1.12.0 "Torrent Duck" This release adds optimizations for Loongarch, adds support for vp8 in the real-time rate control library, upgrades GoogleTest to v1.11.0, updates @@ -36,6 +395,7 @@ levels, and includes several improvements to NEON and numerous bug fixes. - Upgrading: + This release is ABI incompatible with the previous release. New codec control is added to get quantization parameters and loop filter levels. @@ -61,6 +421,7 @@ well as numerous bug fixes. - Upgrading: + This release is ABI incompatible with the previous release. New codec control is added to disable loopfilter for VP9. New encoder control is added to disable feature to increase Q on overshoot @@ -91,6 +452,7 @@ well as incremental improvements. - Upgrading: + This release is ABI compatible with the previous release. NV12 support is added to this release. A new interface is added for VP9 rate control. The new library libvp9rc.a must be linked by applications. @@ -114,12 +476,14 @@ This release collects incremental improvements to many aspects of the library. - Upgrading: + This release is ABI compatible with the previous release. ARCH_* defines have been removed in favor of VPX_ARCH_*. 2019-07-15 v1.8.1 "Orpington Duck" This release collects incremental improvements to many aspects of the library. - Upgrading: + This release is ABI incompatible with the previous release. VP8E_SET_CPUUSED now accepts values up to 9 for vp9. VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT had a spelling fix (was VP8E). The --sdk-path option has been removed. If you were using it to build for @@ -138,7 +502,8 @@ This release focused on encoding performance for realtime and VOD use cases. - Upgrading: - This adds and improves several vp9 controls. Most are related to SVC: + This release is ABI incompatible with the previous release. This adds and + improves several vp9 controls. Most are related to SVC: VP9E_SET_SVC_FRAME_DROP_LAYER: - Frame dropping in SVC. VP9E_SET_SVC_INTER_LAYER_PRED: diff --git a/libs/libvpx/README b/libs/libvpx/README index 477a145ba3..7bcce8f0e8 100644 --- a/libs/libvpx/README +++ b/libs/libvpx/README @@ -1,5 +1,3 @@ -v1.12.0 Torrent Duck - Welcome to the WebM VP8/VP9 Codec SDK! COMPILING THE APPLICATIONS/LIBRARIES: @@ -9,7 +7,7 @@ COMPILING THE APPLICATIONS/LIBRARIES: 1. Prerequisites - * All x86 targets require the Yasm[1] assembler be installed[2]. + * All x86 targets require the NASM[0] or Yasm[1] assembler be installed[2]. * All Windows builds require that Cygwin[3] or MSYS2[4] be installed. * Building the documentation requires Doxygen[5]. If you do not have this package, the install-docs option will be disabled. @@ -20,11 +18,15 @@ COMPILING THE APPLICATIONS/LIBRARIES: source[7]. These requirements are optional if not running the unit tests. + [0]: https://www.nasm.us/ [1]: http://www.tortall.net/projects/yasm [2]: For Visual Studio the base yasm binary (not vsyasm) should be in the PATH for Visual Studio. For VS2017 it is sufficient to rename yasm--.exe to yasm.exe and place it in: Program Files (x86)/Microsoft Visual Studio/2017//Common7/Tools/ + The MSYS2 version of the yasm binary can also be used and avoids an + issue caused by a missing Visual C++ Redistributable install (Visual + Studio 2010, MSVCR100.dll). [3]: http://www.cygwin.com [4]: http://www.msys2.org/ [5]: http://www.doxygen.org @@ -64,9 +66,20 @@ COMPILING THE APPLICATIONS/LIBRARIES: arm64-android-gcc arm64-darwin-gcc arm64-darwin20-gcc + arm64-darwin21-gcc + arm64-darwin22-gcc + arm64-darwin23-gcc + arm64-darwin24-gcc + arm64-darwin25-gcc arm64-linux-gcc arm64-win64-gcc arm64-win64-vs15 + arm64-win64-vs16 + arm64-win64-vs16-clangcl + arm64-win64-vs17 + arm64-win64-vs17-clangcl + arm64-win64-vs18 + arm64-win64-vs18-clangcl armv7-android-gcc armv7-darwin-gcc armv7-linux-rvct @@ -75,8 +88,12 @@ COMPILING THE APPLICATIONS/LIBRARIES: armv7-win32-gcc armv7-win32-vs14 armv7-win32-vs15 + armv7-win32-vs16 + armv7-win32-vs17 armv7s-darwin-gcc armv8-linux-gcc + loongarch32-linux-gcc + loongarch64-linux-gcc mips32-linux-gcc mips64-linux-gcc ppc64le-linux-gcc @@ -104,6 +121,7 @@ COMPILING THE APPLICATIONS/LIBRARIES: x86-win32-vs15 x86-win32-vs16 x86-win32-vs17 + x86-win32-vs18 x86_64-android-gcc x86_64-darwin9-gcc x86_64-darwin10-gcc @@ -117,6 +135,11 @@ COMPILING THE APPLICATIONS/LIBRARIES: x86_64-darwin18-gcc x86_64-darwin19-gcc x86_64-darwin20-gcc + x86_64-darwin21-gcc + x86_64-darwin22-gcc + x86_64-darwin23-gcc + x86_64-darwin24-gcc + x86_64-darwin25-gcc x86_64-iphonesimulator-gcc x86_64-linux-gcc x86_64-linux-icc @@ -126,6 +149,7 @@ COMPILING THE APPLICATIONS/LIBRARIES: x86_64-win64-vs15 x86_64-win64-vs16 x86_64-win64-vs17 + x86_64-win64-vs18 generic-gnu The generic-gnu target, in conjunction with the CROSS environment variable, @@ -138,8 +162,8 @@ COMPILING THE APPLICATIONS/LIBRARIES: $ CROSS=mipsel-linux-uclibc- ../libvpx/configure In addition, the executables to be invoked can be overridden by specifying the - environment variables: CC, AR, LD, AS, STRIP, NM. Additional flags can be - passed to these executables with CFLAGS, LDFLAGS, and ASFLAGS. + environment variables: AR, AS, CC, CXX, LD, STRIP. Additional flags can be + passed to these executables with ASFLAGS, CFLAGS, CXXFLAGS, and LDFLAGS. 6. Configuration errors If the configuration step fails, the first step is to look in the error log. @@ -169,7 +193,49 @@ CODE STYLE: See also: http://clang.llvm.org/docs/ClangFormat.html +PROFILE GUIDED OPTIMIZATION (PGO) + Profile Guided Optimization can be enabled for Clang builds using the + commands: + + $ export CC=clang + $ export CXX=clang++ + $ ../libvpx/configure --enable-profile + $ make + + Generate one or multiple PGO profile files by running vpxdec or vpxenc. For + example: + + $ ./vpxdec ../vpx/out_ful/vp90-2-sintel_1280x546_tile_1x4_1257kbps.webm \ + -o - > /dev/null + + To convert and merge the raw profile files, use the llvm-profdata tool: + + $ llvm-profdata merge -o perf.profdata default_8382761441159425451_0.profraw + + Then, rebuild the project with the new profile file: + + $ make clean + $ ../libvpx/configure --use-profile=perf.profdata + $ make + + Note: Always use the llvm-profdata from the toolchain that is used for + compiling the PGO-enabled binary. + + To observe the improvements from a PGO-enabled build, enable and compare the + list of failed optimizations by using the -Rpass-missed compiler flag. For + example, to list the failed loop vectorizations: + + $ ../libvpx/configure --use-profile=perf.profdata \ + --extra-cflags=-Rpass-missed=loop-vectorize + + For guidance on utilizing PGO files to identify potential optimization + opportunities, see: tools/README.pgo.md + SUPPORT This library is an open source project supported by its community. Please email webm-discuss@webmproject.org for help. +BUG REPORTS + Bug reports can be filed in the libvpx component of the issue tracker: + https://issues.webmproject.org/issues/new?component=1618984&template=2023833. + For security reports, select 'Security report' from the Template dropdown. diff --git a/libs/libvpx/args.c b/libs/libvpx/args.c index 4afb9c021a..f7dfacf8a4 100644 --- a/libs/libvpx/args.c +++ b/libs/libvpx/args.c @@ -8,13 +8,13 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include #include #include #include #include "args.h" #include "vpx/vpx_integer.h" -#include "vpx_ports/msvc.h" #if defined(__GNUC__) __attribute__((noreturn)) extern void die(const char *fmt, ...); @@ -24,7 +24,7 @@ __declspec(noreturn) extern void die(const char *fmt, ...); extern void die(const char *fmt, ...); #endif -struct arg arg_init(char **argv) { +static struct arg arg_init(char **argv) { struct arg a; a.argv = argv; @@ -91,24 +91,31 @@ char **argv_dup(int argc, const char **argv) { } void arg_show_usage(FILE *fp, const struct arg_def *const *defs) { - char option_text[40] = { 0 }; - for (; *defs; defs++) { const struct arg_def *def = *defs; char *short_val = def->has_val ? " " : ""; char *long_val = def->has_val ? "=" : ""; + int n = 0; + // Short options are indented with two spaces. Long options are indented + // with 12 spaces. if (def->short_name && def->long_name) { char *comma = def->has_val ? "," : ", "; - snprintf(option_text, 37, "-%s%s%s --%s%6s", def->short_name, short_val, - comma, def->long_name, long_val); + n = fprintf(fp, " -%s%s%s --%s%s", def->short_name, short_val, comma, + def->long_name, long_val); } else if (def->short_name) - snprintf(option_text, 37, "-%s%s", def->short_name, short_val); + n = fprintf(fp, " -%s%s", def->short_name, short_val); else if (def->long_name) - snprintf(option_text, 37, " --%s%s", def->long_name, long_val); + n = fprintf(fp, " --%s%s", def->long_name, long_val); - fprintf(fp, " %-37s\t%s\n", option_text, def->desc); + // Descriptions are indented with 40 spaces. If an option is 40 characters + // or longer, its description starts on the next line. + if (n < 40) + for (int i = 0; i < 40 - n; i++) fputc(' ', fp); + else + fputs("\n ", fp); + fprintf(fp, "%s\n", def->desc); if (def->enums) { const struct arg_enum_list *listptr; @@ -135,7 +142,6 @@ unsigned int arg_parse_uint(const struct arg *arg) { } die("Option %s: Invalid character '%c'\n", arg->name, *endptr); - return 0; } int arg_parse_int(const struct arg *arg) { @@ -152,7 +158,6 @@ int arg_parse_int(const struct arg *arg) { } die("Option %s: Invalid character '%c'\n", arg->name, *endptr); - return 0; } struct vpx_rational { @@ -209,7 +214,6 @@ int arg_parse_enum(const struct arg *arg) { if (!strcmp(arg->val, listptr->name)) return listptr->val; die("Option %s: Invalid value '%s'\n", arg->name, arg->val); - return 0; } int arg_parse_enum_or_int(const struct arg *arg) { diff --git a/libs/libvpx/args.h b/libs/libvpx/args.h index aae8ec06a5..6b3cc1c28b 100644 --- a/libs/libvpx/args.h +++ b/libs/libvpx/args.h @@ -28,8 +28,7 @@ struct arg_enum_list { const char *name; int val; }; -#define ARG_ENUM_LIST_END \ - { 0 } +#define ARG_ENUM_LIST_END { 0 } typedef struct arg_def { const char *short_name; @@ -38,19 +37,16 @@ typedef struct arg_def { const char *desc; const struct arg_enum_list *enums; } arg_def_t; -#define ARG_DEF(s, l, v, d) \ - { s, l, v, d, NULL } -#define ARG_DEF_ENUM(s, l, v, d, e) \ - { s, l, v, d, e } -#define ARG_DEF_LIST_END \ - { 0 } +#define ARG_DEF(s, l, v, d) { s, l, v, d, NULL } +#define ARG_DEF_ENUM(s, l, v, d, e) { s, l, v, d, e } +#define ARG_DEF_LIST_END { 0 } -struct arg arg_init(char **argv); int arg_match(struct arg *arg_, const struct arg_def *def, char **argv); const char *arg_next(struct arg *arg); void arg_show_usage(FILE *fp, const struct arg_def *const *defs); char **argv_dup(int argc, const char **argv); +// Note: arg_match() must be called before invoking these functions. unsigned int arg_parse_uint(const struct arg *arg); int arg_parse_int(const struct arg *arg); struct vpx_rational arg_parse_rational(const struct arg *arg); diff --git a/libs/libvpx/build/make/Android.mk b/libs/libvpx/build/make/Android.mk index b8032e67aa..a06f6f47c7 100644 --- a/libs/libvpx/build/make/Android.mk +++ b/libs/libvpx/build/make/Android.mk @@ -8,18 +8,16 @@ ## be found in the AUTHORS file in the root of the source tree. ## +# Ignore this file during non-NDK builds. +ifdef NDK_ROOT # # This file is to be used for compiling libvpx for Android using the NDK. # In an Android project place a libvpx checkout in the jni directory. # Run the configure script from the jni directory. Base libvpx # encoder/decoder configuration will look similar to: -# ./libvpx/configure --target=armv7-android-gcc --disable-examples \ +# ./libvpx/configure --target=arm64-android-gcc --disable-examples \ # --enable-external-build # -# When targeting Android, realtime-only is enabled by default. This can -# be overridden by adding the command line flag: -# --disable-realtime-only -# # This will create .mk files that contain variables that contain the # source files to compile. # @@ -27,7 +25,7 @@ # Android.mk file in the libvpx directory: # LOCAL_PATH := $(call my-dir) # include $(CLEAR_VARS) -# include jni/libvpx/build/make/Android.mk +# include libvpx/build/make/Android.mk # # By default libvpx will use the 'cpufeatures' module from the NDK. This allows # the library to be built with all available optimizations (SSE2->AVX512 for @@ -36,11 +34,14 @@ # but the resulting library *must* be run on devices supporting all of the # enabled extensions. They can be disabled individually with # --disable-{sse2, sse3, ssse3, sse4_1, avx, avx2, avx512} -# --disable-neon[-asm] +# --disable-neon{, -asm, -neon-dotprod, -neon-i8mm} +# --disable-sve # --disable-{dspr2, msa} # -# Running ndk-build will build libvpx and include it in your project. +# Running ndk-build will build libvpx and include it in your project. Set +# APP_ABI to match the --target passed to configure: +# https://developer.android.com/ndk/guides/application_mk#app_abi. # CONFIG_DIR := $(LOCAL_PATH)/ @@ -83,6 +84,8 @@ include $(LIBVPX_PATH)/libs.mk # Optimise the code. May want to revisit this setting in the future. LOCAL_CFLAGS := -O3 +LOCAL_CONLYFLAGS := -std=c11 + # For x86, include the source code in the search path so it will find files # like x86inc.asm and x86_abi_support.asm LOCAL_ASMFLAGS := -I$(LIBVPX_PATH) @@ -212,3 +215,4 @@ endif ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes) $(call import-module,android/cpufeatures) endif +endif # NDK_ROOT diff --git a/libs/libvpx/build/make/Makefile b/libs/libvpx/build/make/Makefile index b7a873cc81..39dff825b6 100644 --- a/libs/libvpx/build/make/Makefile +++ b/libs/libvpx/build/make/Makefile @@ -21,9 +21,9 @@ all: .DEFAULT clean:: .DEFAULT exampletest: .DEFAULT install:: .DEFAULT -test:: .DEFAULT -test-no-data-check:: .DEFAULT -testdata:: .DEFAULT +test: .DEFAULT +test-no-data-check: .DEFAULT +testdata: .DEFAULT utiltest: .DEFAULT exampletest-no-data-check utiltest-no-data-check: .DEFAULT test_%: .DEFAULT ; @@ -111,13 +111,13 @@ exampletest: .PHONY: install install:: .PHONY: test -test:: +test: .PHONY: testdata -testdata:: +testdata: .PHONY: utiltest utiltest: .PHONY: test-no-data-check exampletest-no-data-check utiltest-no-data-check -test-no-data-check:: +test-no-data-check: exampletest-no-data-check utiltest-no-data-check: # Force to realign stack always on OS/2 @@ -143,6 +143,16 @@ $(BUILD_PFX)%_avx2.c.o: CFLAGS += -mavx2 $(BUILD_PFX)%_avx512.c.d: CFLAGS += -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl $(BUILD_PFX)%_avx512.c.o: CFLAGS += -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl +# AARCH64 +$(BUILD_PFX)%_neon_dotprod.c.d: CFLAGS += -march=armv8.2-a+dotprod +$(BUILD_PFX)%_neon_dotprod.c.o: CFLAGS += -march=armv8.2-a+dotprod +$(BUILD_PFX)%_neon_i8mm.c.d: CFLAGS += -march=armv8.2-a+dotprod+i8mm +$(BUILD_PFX)%_neon_i8mm.c.o: CFLAGS += -march=armv8.2-a+dotprod+i8mm +$(BUILD_PFX)%_sve.c.d: CFLAGS += -march=armv8.2-a+dotprod+i8mm+sve +$(BUILD_PFX)%_sve.c.o: CFLAGS += -march=armv8.2-a+dotprod+i8mm+sve +$(BUILD_PFX)%_sve2.c.d: CFLAGS += -march=armv9-a+i8mm+sve2 +$(BUILD_PFX)%_sve2.c.o: CFLAGS += -march=armv9-a+i8mm+sve2 + # POWER $(BUILD_PFX)%_vsx.c.d: CFLAGS += -maltivec -mvsx $(BUILD_PFX)%_vsx.c.o: CFLAGS += -maltivec -mvsx @@ -304,6 +314,19 @@ $(1): $(qexec)$$(AR) $$(ARFLAGS) $$@ $$^ endef +# Don't use -Wl,-z,defs with Clang's sanitizers. +# +# Clang's AddressSanitizer documentation says "When linking shared libraries, +# the AddressSanitizer run-time is not linked, so -Wl,-z,defs may cause link +# errors (don't use it with AddressSanitizer)." See +# https://clang.llvm.org/docs/AddressSanitizer.html#usage. +NO_UNDEFINED := -Wl,-z,defs +ifeq ($(findstring clang,$(CC)),clang) + ifneq ($(filter -fsanitize=%,$(LDFLAGS)),) + NO_UNDEFINED := + endif +endif + define so_template # Not using a pattern rule here because we don't want to generate empty # archives when they are listed as a dependency in files not responsible @@ -313,7 +336,8 @@ define so_template $(1): $(if $(quiet),@echo " [LD] $$@") $(qexec)$$(LD) -shared $$(LDFLAGS) \ - -Wl,--no-undefined -Wl,-soname,$$(SONAME) \ + $(NO_UNDEFINED) \ + -Wl,-soname,$$(SONAME) \ -Wl,--version-script,$$(EXPORTS_FILE) -o $$@ \ $$(filter %.o,$$^) $$(extralibs) endef @@ -465,6 +489,6 @@ INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins all: $(BUILD_TARGETS) install:: $(INSTALL_TARGETS) dist: $(INSTALL_TARGETS) -test:: +test: .SUFFIXES: # Delete default suffix rules diff --git a/libs/libvpx/build/make/configure.sh b/libs/libvpx/build/make/configure.sh index 028edabb79..b37b9986fa 100644 --- a/libs/libvpx/build/make/configure.sh +++ b/libs/libvpx/build/make/configure.sh @@ -74,6 +74,8 @@ Build options: --cpu=CPU optimize for a specific cpu rather than a family --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS [$CFLAGS] --extra-cxxflags=ECXXFLAGS add ECXXFLAGS to CXXFLAGS [$CXXFLAGS] + --use-profile=PROFILE_FILE + Use PROFILE_FILE for PGO ${toggle_extra_warnings} emit harmless warnings (always non-fatal) ${toggle_werror} treat warnings as errors, if possible (not available with all compilers) @@ -81,6 +83,7 @@ Build options: ${toggle_pic} turn on/off Position Independent Code ${toggle_ccache} turn on/off compiler cache ${toggle_debug} enable/disable debug mode + ${toggle_profile} enable/disable profiling ${toggle_gprof} enable/disable gprof profiling instrumentation ${toggle_gcov} enable/disable gcov coverage instrumentation ${toggle_thumb} enable/disable building arm assembly in thumb mode @@ -429,6 +432,42 @@ check_gcc_machine_options() { fi } +check_neon_sve_bridge_compiles() { + if enabled sve; then + check_cc -march=armv8.2-a+dotprod+i8mm+sve < +#include +EOF + compile_result=$? + if [ ${compile_result} -eq 0 ]; then + # Check whether the compiler can compile SVE functions that require + # backup/restore of SVE registers according to AAPCS. Clang for Windows + # used to fail this, see + # https://github.com/llvm/llvm-project/issues/80009. + check_cc -march=armv8.2-a+dotprod+i8mm+sve < +void other(void); +svfloat32_t func(svfloat32_t a) { + other(); + return a; +} +EOF + compile_result=$? + fi + + if [ ${compile_result} -ne 0 ]; then + log_echo " disabling sve: arm_neon_sve_bridge.h not supported by compiler" + log_echo " disabling sve2: arm_neon_sve_bridge.h not supported by compiler" + disable_feature sve + disable_feature sve2 + RTCD_OPTIONS="${RTCD_OPTIONS}--disable-sve --disable-sve2 " + fi + fi +} + check_gcc_avx512_compiles() { if disabled gcc; then return @@ -442,13 +481,11 @@ void f(void) { } EOF compile_result=$? -# -# if [ ${compile_result} -ne 0 ]; then -# log_echo " disabling avx512: not supported by compiler" -# disable_feature avx512 -# RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx512 " -# fi -#*/ + if [ ${compile_result} -ne 0 ]; then + log_echo " disabling avx512: not supported by compiler" + disable_feature avx512 + RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx512 " + fi } check_inline_asm() { @@ -511,7 +548,6 @@ AR=${AR} LD=${LD} AS=${AS} STRIP=${STRIP} -NM=${NM} CFLAGS = ${CFLAGS} CXXFLAGS = ${CXXFLAGS} @@ -523,6 +559,7 @@ AS_SFX = ${AS_SFX:-.asm} EXE_SFX = ${EXE_SFX} VCPROJ_SFX = ${VCPROJ_SFX} RTCD_OPTIONS = ${RTCD_OPTIONS} +LIBWEBM_CXXFLAGS = ${LIBWEBM_CXXFLAGS} LIBYUV_CXXFLAGS = ${LIBYUV_CXXFLAGS} EOF @@ -612,6 +649,9 @@ process_common_cmdline() { --extra-cxxflags=*) extra_cxxflags="${optval}" ;; + --use-profile=*) + pgo_file=${optval} + ;; --enable-?*|--disable-?*) eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'` if is_in ${option} ${ARCH_EXT_LIST}; then @@ -708,7 +748,6 @@ setup_gnu_toolchain() { LD=${LD:-${CROSS}${link_with_cc:-ld}} AS=${AS:-${CROSS}as} STRIP=${STRIP:-${CROSS}strip} - NM=${NM:-${CROSS}nm} AS_SFX=.S EXE_SFX= } @@ -793,7 +832,7 @@ process_common_toolchain() { tgt_isa=x86_64 tgt_os=`echo $gcctarget | sed 's/.*\(darwin1[0-9]\).*/\1/'` ;; - *darwin2[0-1]*) + *darwin2[0-5]*) tgt_isa=`uname -m` tgt_os=`echo $gcctarget | sed 's/.*\(darwin2[0-9]\).*/\1/'` ;; @@ -844,6 +883,10 @@ process_common_toolchain() { # Enable the architecture family case ${tgt_isa} in + arm64 | armv8) + enable_feature arm + enable_feature aarch64 + ;; arm*) enable_feature arm ;; @@ -860,8 +903,14 @@ process_common_toolchain() { ;; esac - # PIC is probably what we want when building shared libs + # Position independent code (PIC) is probably what we want when building + # shared libs or position independent executable (PIE) targets. enabled shared && soft_enable pic + check_cpp << EOF || soft_enable pic +#if !(__pie__ || __PIE__) +#error Neither __pie__ or __PIE__ are set +#endif +EOF # Minimum iOS version for all target platforms (darwin and iphonesimulator). # Shared library framework builds are only possible on iOS 8 and later. @@ -942,7 +991,7 @@ process_common_toolchain() { add_cflags "-mmacosx-version-min=10.15" add_ldflags "-mmacosx-version-min=10.15" ;; - *-darwin2[0-1]-*) + *-darwin2[0-5]-*) add_cflags "-arch ${toolchain%%-*}" add_ldflags "-arch ${toolchain%%-*}" ;; @@ -967,27 +1016,30 @@ process_common_toolchain() { ;; esac - # Process ARM architecture variants + # Process architecture variants case ${toolchain} in arm*) - # on arm, isa versions are supersets - case ${tgt_isa} in - arm64|armv8) - soft_enable neon + case ${toolchain} in + armv7*-darwin*) + # Runtime cpu detection is not defined for these targets. + enabled runtime_cpu_detect && disable_feature runtime_cpu_detect ;; - armv7|armv7s) - soft_enable neon - # Only enable neon_asm when neon is also enabled. - enabled neon && soft_enable neon_asm - # If someone tries to force it through, die. - if disabled neon && enabled neon_asm; then - die "Disabling neon while keeping neon-asm is not supported" - fi + *) + soft_enable runtime_cpu_detect ;; esac - asm_conversion_cmd="cat" + if [ ${tgt_isa} = "armv7" ] || [ ${tgt_isa} = "armv7s" ]; then + soft_enable neon + # Only enable neon_asm when neon is also enabled. + enabled neon && soft_enable neon_asm + # If someone tries to force it through, die. + if disabled neon && enabled neon_asm; then + die "Disabling neon while keeping neon-asm is not supported" + fi + fi + asm_conversion_cmd="cat" case ${tgt_cc} in gcc) link_with_cc=gcc @@ -1068,8 +1120,11 @@ EOF enable_feature win_arm64_neon_h_workaround else # If a probe is not possible, assume this is the pure Windows - # SDK and so the workaround is necessary. - enable_feature win_arm64_neon_h_workaround + # SDK and so the workaround is necessary when using Visual + # Studio < 2019. + if [ ${tgt_cc##vs} -lt 16 ]; then + enable_feature win_arm64_neon_h_workaround + fi fi fi fi @@ -1080,7 +1135,6 @@ EOF AS=armasm LD="${source_path}/build/make/armlink_adapter.sh" STRIP=arm-none-linux-gnueabi-strip - NM=arm-none-linux-gnueabi-nm tune_cflags="--cpu=" tune_asflags="--cpu=" if [ -z "${tune_cpu}" ]; then @@ -1117,6 +1171,14 @@ EOF echo "See build/make/Android.mk for details." check_add_ldflags -static soft_enable unit_tests + case "$AS" in + *clang) + # The GNU Assembler was removed in the r24 version of the NDK. + # clang's internal assembler works, but `-c` is necessary to + # avoid linking. + add_asflags -c + ;; + esac ;; darwin) @@ -1127,8 +1189,6 @@ EOF AR="$(${XCRUN_FIND} ar)" AS="$(${XCRUN_FIND} as)" STRIP="$(${XCRUN_FIND} strip)" - NM="$(${XCRUN_FIND} nm)" - RANLIB="$(${XCRUN_FIND} ranlib)" AS_SFX=.S LD="${CXX:-$(${XCRUN_FIND} ld)}" @@ -1169,7 +1229,8 @@ EOF ;; esac - if [ "$(show_darwin_sdk_major_version iphoneos)" -gt 8 ]; then + if [ "$(show_darwin_sdk_major_version iphoneos)" -gt 8 ] \ + && [ "$(show_xcode_version | cut -d. -f1)" -lt 16 ]; then check_add_cflags -fembed-bitcode check_add_asflags -fembed-bitcode check_add_ldflags -fembed-bitcode @@ -1203,6 +1264,38 @@ EOF fi ;; esac + + # AArch64 ISA extensions are treated as supersets. + if [ ${tgt_isa} = "arm64" ] || [ ${tgt_isa} = "armv8" ]; then + aarch64_arch_flag_neon="arch=armv8-a" + aarch64_arch_flag_neon_dotprod="arch=armv8.2-a+dotprod" + aarch64_arch_flag_neon_i8mm="arch=armv8.2-a+dotprod+i8mm" + aarch64_arch_flag_sve="arch=armv8.2-a+dotprod+i8mm+sve" + aarch64_arch_flag_sve2="arch=armv9-a+sve2" + for ext in ${ARCH_EXT_LIST_AARCH64}; do + if [ "$disable_exts" = "yes" ]; then + RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${ext} " + soft_disable $ext + else + # Check the compiler supports the -march flag for the extension. + # This needs to happen after toolchain/OS inspection so we handle + # $CROSS etc correctly when checking for flags, else these will + # always fail. + flag="$(eval echo \$"aarch64_arch_flag_${ext}")" + check_gcc_machine_option "${flag}" "${ext}" + if ! enabled $ext; then + # Disable higher order extensions to simplify dependencies. + disable_exts="yes" + RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${ext} " + soft_disable $ext + fi + fi + done + if enabled sve; then + check_neon_sve_bridge_compiles + fi + fi + ;; mips*) link_with_cc=gcc @@ -1270,6 +1363,7 @@ EOF fi ;; x86*) + soft_enable x86_asm case ${tgt_os} in android) soft_enable realtime_only @@ -1288,6 +1382,10 @@ EOF AS=${AS:-nasm} add_ldflags -Zhigh-mem ;; + darwin*) + enabled x86 && darwin_arch="-arch i386" || darwin_arch="-arch x86_64" + add_cflags ${darwin_arch} + add_ldflags ${darwin_arch} esac AS="${alt_as:-${AS:-auto}}" @@ -1410,9 +1508,6 @@ EOF ;; darwin*) add_asflags -f macho${bits} - enabled x86 && darwin_arch="-arch i386" || darwin_arch="-arch x86_64" - add_cflags ${darwin_arch} - add_ldflags ${darwin_arch} # -mdynamic-no-pic is still a bit of voodoo -- it was required at # one time, but does not seem to be now, and it breaks some of the # code that still relies on inline assembly. @@ -1459,6 +1554,14 @@ EOF ;; esac + # Enable PGO + if [ -n "${pgo_file}" ]; then + check_add_cflags -fprofile-use=${pgo_file} || \ + die "-fprofile-use is not supported by compiler" + check_add_ldflags -fprofile-use=${pgo_file} || \ + die "-fprofile-use is not supported by linker" + fi + # Try to enable CPU specific tuning if [ -n "${tune_cpu}" ]; then if [ -n "${tune_cflags}" ]; then @@ -1479,6 +1582,9 @@ EOF else check_add_cflags -DNDEBUG fi + enabled profile && + check_add_cflags -fprofile-generate && + check_add_ldflags -fprofile-generate enabled gprof && check_add_cflags -pg && check_add_ldflags -pg enabled gcov && @@ -1497,10 +1603,6 @@ EOF # shared objects enabled gcc && enabled pic && check_add_cflags -fPIC - # Work around longjmp interception on glibc >= 2.11, to improve binary - # compatibility. See http://code.google.com/p/webm/issues/detail?id=166 - enabled linux && check_add_cflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 - # Check for strip utility variant ${STRIP} -V 2>/dev/null | grep GNU >/dev/null && enable_feature gnu_strip @@ -1513,7 +1615,7 @@ EOF # Try to find which inline keywords are supported check_cc < #include -void *thread_check (void *); -void *thread_check (void *obj){ return obj;}; -int main(void) { pthread_t thread_id; return pthread_create(&thread_id, NULL, thread_check, NULL); } +int main(void) { return pthread_create(NULL, NULL, NULL, NULL); } +EOF + + enabled pthread_h && check_lib -lpthread < +int main(void) { return &pthread_setname_np != 0; } EOF ;; esac diff --git a/libs/libvpx/build/make/gen_asm_deps.sh b/libs/libvpx/build/make/gen_asm_deps.sh index 6a7bff9ebc..3bd4d125f1 100755 --- a/libs/libvpx/build/make/gen_asm_deps.sh +++ b/libs/libvpx/build/make/gen_asm_deps.sh @@ -42,7 +42,7 @@ done [ -n "$srcfile" ] || show_help sfx=${sfx:-asm} -includes=$(LC_ALL=C egrep -i "include +\"?[a-z0-9_/]+\.${sfx}" $srcfile | +includes=$(LC_ALL=C grep -E -i "include +\"?[a-z0-9_/]+\.${sfx}" $srcfile | perl -p -e "s;.*?([a-z0-9_/]+.${sfx}).*;\1;") #" restore editor state for inc in ${includes}; do diff --git a/libs/libvpx/build/make/gen_msvs_sln.sh b/libs/libvpx/build/make/gen_msvs_sln.sh index 0b312850fe..29eab755bf 100755 --- a/libs/libvpx/build/make/gen_msvs_sln.sh +++ b/libs/libvpx/build/make/gen_msvs_sln.sh @@ -25,7 +25,7 @@ files. Options: --help Print this message --out=outfile Redirect output to a file - --ver=version Version (14-17) of visual studio to generate for + --ver=version Version (14-18) of visual studio to generate for --target=isa-os-cc Target specifier EOF exit 1 @@ -220,6 +220,7 @@ for opt in "$@"; do 15) vs_year=2017 ;; 16) vs_year=2019 ;; 17) vs_year=2022 ;; + 18) vs_year=2026 ;; *) die Unrecognized Visual Studio Version in $opt ;; esac ;; @@ -233,7 +234,7 @@ done outfile=${outfile:-/dev/stdout} mkoutfile=${mkoutfile:-/dev/stdout} case "${vs_ver}" in - 1[4-7]) + 1[4-8]) # VS has used Format Version 12.00 continuously since vs11. sln_vers="12.00" sln_vers_str="Visual Studio ${vs_year}" diff --git a/libs/libvpx/build/make/gen_msvs_vcxproj.sh b/libs/libvpx/build/make/gen_msvs_vcxproj.sh index 58bb66b9e3..2ee45e85a3 100755 --- a/libs/libvpx/build/make/gen_msvs_vcxproj.sh +++ b/libs/libvpx/build/make/gen_msvs_vcxproj.sh @@ -34,7 +34,7 @@ Options: --name=project_name Name of the project (required) --proj-guid=GUID GUID to use for the project --module-def=filename File containing export definitions (for DLLs) - --ver=version Version (14-16) of visual studio to generate for + --ver=version Version (14-18) of visual studio to generate for --src-path-bare=dir Path to root of source tree -Ipath/to/include Additional include directories -DFLAG[=value] Preprocessor macros to define @@ -106,8 +106,12 @@ generate_filter() { Include="$f" # Separate file names with Condition? tag_content ObjectFileName "\$(IntDir)$objf" - # Check for AVX and turn it on to avoid warnings. - if [[ $f =~ avx.?\.c$ ]]; then + # Set the appropriate /arch option for AVX/AVX2/AVX-512 files. + if [[ $f =~ avx512\.c$ ]]; then + tag_content AdditionalOptions "/arch:AVX512" + elif [[ $f =~ avx2\.c$ ]]; then + tag_content AdditionalOptions "/arch:AVX2" + elif [[ $f =~ avx\.c$ ]]; then tag_content AdditionalOptions "/arch:AVX" fi close_tag ClCompile @@ -141,7 +145,17 @@ for opt in "$@"; do case "$opt" in --help|-h) show_help ;; - --target=*) target="${optval}" + --target=*) + target="${optval}" + platform_toolset=$(echo ${target} | awk 'BEGIN{FS="-"}{print $4}') + case "$platform_toolset" in + clangcl) platform_toolset="ClangCl" + ;; + "") + ;; + *) die Unrecognized Visual Studio Platform Toolset in $opt + ;; + esac ;; --out=*) outfile="$optval" ;; @@ -170,7 +184,7 @@ for opt in "$@"; do --ver=*) vs_ver="$optval" case "$optval" in - 1[4-7]) + 1[4-8]) ;; *) die Unrecognized Visual Studio Version in $opt ;; @@ -259,6 +273,10 @@ case "$target" in ;; arm64*) platforms[0]="ARM64" + # As of Visual Studio 2022 17.5.5, clang-cl does not support ARM64EC. + if [ "$vs_ver" -ge 17 -a "$platform_toolset" != "ClangCl" ]; then + platforms[1]="ARM64EC" + fi asm_Debug_cmdline="armasm64 -nologo -oldit "%(FullPath)"" asm_Release_cmdline="armasm64 -nologo -oldit "%(FullPath)"" ;; @@ -335,17 +353,24 @@ generate_vcxproj() { else tag_content ConfigurationType StaticLibrary fi - if [ "$vs_ver" = "14" ]; then - tag_content PlatformToolset v140 - fi - if [ "$vs_ver" = "15" ]; then - tag_content PlatformToolset v141 - fi - if [ "$vs_ver" = "16" ]; then - tag_content PlatformToolset v142 - fi - if [ "$vs_ver" = "17" ]; then - tag_content PlatformToolset v143 + if [ -n "$platform_toolset" ]; then + tag_content PlatformToolset "$platform_toolset" + else + if [ "$vs_ver" = "14" ]; then + tag_content PlatformToolset v140 + fi + if [ "$vs_ver" = "15" ]; then + tag_content PlatformToolset v141 + fi + if [ "$vs_ver" = "16" ]; then + tag_content PlatformToolset v142 + fi + if [ "$vs_ver" = "17" ]; then + tag_content PlatformToolset v143 + fi + if [ "$vs_ver" = "18" ]; then + tag_content PlatformToolset v145 + fi fi tag_content CharacterSet Unicode if [ "$config" = "Release" ]; then @@ -415,6 +440,8 @@ generate_vcxproj() { tag_content Optimization $opt tag_content AdditionalIncludeDirectories "$incs;%(AdditionalIncludeDirectories)" tag_content PreprocessorDefinitions "WIN32;$debug;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE$extradefines;%(PreprocessorDefinitions)" + tag_content LanguageStandard_C stdc11 + tag_content LanguageStandard stdcpp17 tag_content RuntimeLibrary $runtime tag_content WarningLevel Level3 if ${werror:-false}; then diff --git a/libs/libvpx/build/make/iosbuild.sh b/libs/libvpx/build/make/iosbuild.sh index 978ffbbb98..d9594b9816 100755 --- a/libs/libvpx/build/make/iosbuild.sh +++ b/libs/libvpx/build/make/iosbuild.sh @@ -30,13 +30,9 @@ SCRIPT_DIR=$(dirname "$0") LIBVPX_SOURCE_DIR=$(cd ${SCRIPT_DIR}/../..; pwd) LIPO=$(xcrun -sdk iphoneos${SDK} -find lipo) ORIG_PWD="$(pwd)" -ARM_TARGETS="arm64-darwin-gcc - armv7-darwin-gcc - armv7s-darwin-gcc" -SIM_TARGETS="x86-iphonesimulator-gcc - x86_64-iphonesimulator-gcc" -OSX_TARGETS="x86-darwin16-gcc - x86_64-darwin16-gcc" +ARM_TARGETS="arm64-darwin-gcc" +SIM_TARGETS="x86_64-iphonesimulator-gcc" +OSX_TARGETS="x86_64-darwin16-gcc" TARGETS="${ARM_TARGETS} ${SIM_TARGETS}" # Configures for the target specified by $1, and invokes make with the dist diff --git a/libs/libvpx/build/make/rtcd.pl b/libs/libvpx/build/make/rtcd.pl index 9c97268426..7c876fc9d5 100755 --- a/libs/libvpx/build/make/rtcd.pl +++ b/libs/libvpx/build/make/rtcd.pl @@ -73,6 +73,10 @@ sub vpx_config($) { } sub specialize { + if (@_ <= 1) { + die "'specialize' must be called with a function name and at least one ", + "architecture ('C' is implied): \n@_\n"; + } my $fn=$_[0]; shift; foreach my $opt (@_) { @@ -209,6 +213,16 @@ sub filter { sub common_top() { my $include_guard = uc($opts{sym})."_H_"; print < $PRIORITY_INDEX{$b} } keys %required); if ($opts{arch} eq 'x86') { @ALL_ARCHS = filter(qw/mmx sse sse2 sse3 ssse3 sse4_1 avx avx2 avx512/); x86; } elsif ($opts{arch} eq 'x86_64') { @ALL_ARCHS = filter(qw/mmx sse sse2 sse3 ssse3 sse4_1 avx avx2 avx512/); - @REQUIRES = filter(qw/mmx sse sse2/); - &require(@REQUIRES); + if (keys %required == 0) { + @REQUIRES = filter(qw/mmx sse sse2/); + &require(@REQUIRES); + } x86; } elsif ($opts{arch} eq 'mips32' || $opts{arch} eq 'mips64') { my $have_dspr2 = 0; @@ -487,8 +518,11 @@ if ($opts{arch} eq 'x86') { @ALL_ARCHS = filter(qw/neon_asm neon/); arm; } elsif ($opts{arch} eq 'armv8' || $opts{arch} eq 'arm64' ) { - @ALL_ARCHS = filter(qw/neon/); - &require("neon"); + @ALL_ARCHS = filter(qw/neon neon_dotprod neon_i8mm sve sve2/); + if (keys %required == 0) { + @REQUIRES = filter(qw/neon/); + &require(@REQUIRES); + } arm; } elsif ($opts{arch} =~ /^ppc/ ) { @ALL_ARCHS = filter(qw/vsx/); diff --git a/libs/libvpx/build/make/version.sh b/libs/libvpx/build/make/version.sh index f36ede10f2..8f717cc96f 100755 --- a/libs/libvpx/build/make/version.sh +++ b/libs/libvpx/build/make/version.sh @@ -61,6 +61,8 @@ if [ ${bare} ]; then else cat<$$.tmp // This file is generated. Do not edit. +#ifndef VPX_VERSION_H_ +#define VPX_VERSION_H_ #define VERSION_MAJOR $major_version #define VERSION_MINOR $minor_version #define VERSION_PATCH $patch_version @@ -68,6 +70,7 @@ else #define VERSION_PACKED ((VERSION_MAJOR<<16)|(VERSION_MINOR<<8)|(VERSION_PATCH)) #define ${id}_NOSP "${version_str}" #define ${id} " ${version_str}" +#endif // VPX_VERSION_H_ EOF fi if [ -n "$out_file" ]; then diff --git a/libs/libvpx/configure b/libs/libvpx/configure index e7917c98cf..9e9d80bba5 100755 --- a/libs/libvpx/configure +++ b/libs/libvpx/configure @@ -101,9 +101,19 @@ all_platforms="${all_platforms} arm64-android-gcc" all_platforms="${all_platforms} arm64-darwin-gcc" all_platforms="${all_platforms} arm64-darwin20-gcc" all_platforms="${all_platforms} arm64-darwin21-gcc" +all_platforms="${all_platforms} arm64-darwin22-gcc" +all_platforms="${all_platforms} arm64-darwin23-gcc" +all_platforms="${all_platforms} arm64-darwin24-gcc" +all_platforms="${all_platforms} arm64-darwin25-gcc" all_platforms="${all_platforms} arm64-linux-gcc" all_platforms="${all_platforms} arm64-win64-gcc" all_platforms="${all_platforms} arm64-win64-vs15" +all_platforms="${all_platforms} arm64-win64-vs16" +all_platforms="${all_platforms} arm64-win64-vs16-clangcl" +all_platforms="${all_platforms} arm64-win64-vs17" +all_platforms="${all_platforms} arm64-win64-vs17-clangcl" +all_platforms="${all_platforms} arm64-win64-vs18" +all_platforms="${all_platforms} arm64-win64-vs18-clangcl" all_platforms="${all_platforms} armv7-android-gcc" #neon Cortex-A8 all_platforms="${all_platforms} armv7-darwin-gcc" #neon Cortex-A8 all_platforms="${all_platforms} armv7-linux-rvct" #neon Cortex-A8 @@ -112,6 +122,8 @@ all_platforms="${all_platforms} armv7-none-rvct" #neon Cortex-A8 all_platforms="${all_platforms} armv7-win32-gcc" all_platforms="${all_platforms} armv7-win32-vs14" all_platforms="${all_platforms} armv7-win32-vs15" +all_platforms="${all_platforms} armv7-win32-vs16" +all_platforms="${all_platforms} armv7-win32-vs17" all_platforms="${all_platforms} armv7s-darwin-gcc" all_platforms="${all_platforms} armv8-linux-gcc" all_platforms="${all_platforms} loongarch32-linux-gcc" @@ -143,6 +155,7 @@ all_platforms="${all_platforms} x86-win32-vs14" all_platforms="${all_platforms} x86-win32-vs15" all_platforms="${all_platforms} x86-win32-vs16" all_platforms="${all_platforms} x86-win32-vs17" +all_platforms="${all_platforms} x86-win32-vs18" all_platforms="${all_platforms} x86_64-android-gcc" all_platforms="${all_platforms} x86_64-darwin9-gcc" all_platforms="${all_platforms} x86_64-darwin10-gcc" @@ -157,6 +170,10 @@ all_platforms="${all_platforms} x86_64-darwin18-gcc" all_platforms="${all_platforms} x86_64-darwin19-gcc" all_platforms="${all_platforms} x86_64-darwin20-gcc" all_platforms="${all_platforms} x86_64-darwin21-gcc" +all_platforms="${all_platforms} x86_64-darwin22-gcc" +all_platforms="${all_platforms} x86_64-darwin23-gcc" +all_platforms="${all_platforms} x86_64-darwin24-gcc" +all_platforms="${all_platforms} x86_64-darwin25-gcc" all_platforms="${all_platforms} x86_64-iphonesimulator-gcc" all_platforms="${all_platforms} x86_64-linux-gcc" all_platforms="${all_platforms} x86_64-linux-icc" @@ -166,6 +183,7 @@ all_platforms="${all_platforms} x86_64-win64-vs14" all_platforms="${all_platforms} x86_64-win64-vs15" all_platforms="${all_platforms} x86_64-win64-vs16" all_platforms="${all_platforms} x86_64-win64-vs17" +all_platforms="${all_platforms} x86_64-win64-vs18" all_platforms="${all_platforms} generic-gnu" # all_targets is a list of all targets that can be configured @@ -237,12 +255,22 @@ CODEC_FAMILIES=" ARCH_LIST=" arm + aarch64 mips x86 x86_64 ppc loongarch " + +ARCH_EXT_LIST_AARCH64=" + neon + neon_dotprod + neon_i8mm + sve + sve2 +" + ARCH_EXT_LIST_X86=" mmx sse @@ -262,14 +290,15 @@ ARCH_EXT_LIST_LOONGSON=" " ARCH_EXT_LIST=" - neon neon_asm + ${ARCH_EXT_LIST_AARCH64} mips32 dspr2 msa mips64 + x86_asm ${ARCH_EXT_LIST_X86} vsx @@ -280,13 +309,14 @@ HAVE_LIST=" ${ARCH_EXT_LIST} vpx_ports pthread_h + pthread_setname_np unistd_h " EXPERIMENT_LIST=" fp_mb_stats emulate_hardware non_greedy_mv - rate_ctrl + collect_component_timing " CONFIG_LIST=" dependency_tracking @@ -336,7 +366,6 @@ CONFIG_LIST=" multi_res_encoding temporal_denoising vp9_temporal_denoising - consistent_recode coefficient_range_checking vp9_highbitdepth better_hw_compatibility @@ -357,6 +386,7 @@ CMDLINE_SELECT=" install_libs install_srcs debug + profile gprof gcov pic @@ -400,7 +430,6 @@ CMDLINE_SELECT=" multi_res_encoding temporal_denoising vp9_temporal_denoising - consistent_recode coefficient_range_checking better_hw_compatibility vp9_highbitdepth @@ -609,9 +638,7 @@ EOF check_header pthread.h && check_lib -lpthread < #include -void *thread_check (void *); -void *thread_check (void *obj){ return obj;}; -int main(void) { pthread_t thread_id; return pthread_create(&thread_id, NULL, thread_check, NULL); } +int main(void) { return pthread_create(NULL, NULL, NULL, NULL); } EOF check_header unistd.h # for sysconf(3) and friends. @@ -629,7 +656,6 @@ process_toolchain() { if enabled gcc; then enabled werror && check_add_cflags -Werror check_add_cflags -Wall - check_add_cflags -Wdeclaration-after-statement check_add_cflags -Wdisabled-optimization check_add_cflags -Wextra-semi check_add_cflags -Wextra-semi-stmt @@ -643,8 +669,10 @@ process_toolchain() { check_add_cflags -Wimplicit-function-declaration check_add_cflags -Wmissing-declarations check_add_cflags -Wmissing-prototypes + check_add_cflags -Wshadow + check_add_cflags -Wstrict-prototypes check_add_cflags -Wuninitialized - check_add_cflags -Wunreachable-code-loop-increment + check_add_cflags -Wunreachable-code-aggressive check_add_cflags -Wunused check_add_cflags -Wextra # check_add_cflags also adds to cxxflags. gtest does not do well with @@ -655,24 +683,39 @@ process_toolchain() { if enabled mips || [ -z "${INLINE}" ]; then enabled extra_warnings || check_add_cflags -Wno-unused-function fi - # Enforce c89 for c files. Don't be too strict about it though. Allow - # gnu extensions like "//" for comments. - check_cflags -std=gnu89 && add_cflags_only -std=gnu89 + # Enforce C11 for C files. Allow GNU extensions. + check_cflags -std=gnu11 && add_cflags_only -std=gnu11 + # Enforce C11 compatibility. + check_cflags -Wc23-extensions && add_cflags_only -Wc23-extensions # Avoid this warning for third_party C++ sources. Some reorganization # would be needed to apply this only to test/*.cc. check_cflags -Wshorten-64-to-32 && add_cflags_only -Wshorten-64-to-32 + # Do not allow implicit vector type conversions on Clang builds (this + # is already the default on GCC builds). + check_add_cflags -flax-vector-conversions=none + # Quiet gcc 6 vs 7 abi warnings: # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77728 if enabled arm; then check_add_cxxflags -Wno-psabi fi - # disable some warnings specific to libyuv. + # Enforce C++17 compatibility. + check_add_cxxflags -Wc++20-extensions + check_add_cxxflags -Wc++23-extensions + check_add_cxxflags -Wnon-virtual-dtor + + # disable some warnings specific to libyuv / libwebm. check_cxxflags -Wno-missing-declarations \ && LIBYUV_CXXFLAGS="${LIBYUV_CXXFLAGS} -Wno-missing-declarations" check_cxxflags -Wno-missing-prototypes \ && LIBYUV_CXXFLAGS="${LIBYUV_CXXFLAGS} -Wno-missing-prototypes" + check_cxxflags -Wno-pass-failed \ + && LIBYUV_CXXFLAGS="${LIBYUV_CXXFLAGS} -Wno-pass-failed" + check_cxxflags -Wno-shadow \ + && LIBWEBM_CXXFLAGS="${LIBWEBM_CXXFLAGS} -Wno-shadow" \ + && LIBYUV_CXXFLAGS="${LIBYUV_CXXFLAGS} -Wno-shadow" check_cxxflags -Wno-unused-parameter \ && LIBYUV_CXXFLAGS="${LIBYUV_CXXFLAGS} -Wno-unused-parameter" fi @@ -745,33 +788,33 @@ process_toolchain() { soft_enable libyuv ;; *-android-*) - check_add_cxxflags -std=gnu++11 && soft_enable webm_io + check_add_cxxflags -std=gnu++17 && soft_enable webm_io soft_enable libyuv # GTestLog must be modified to use Android logging utilities. ;; *-darwin-*) - check_add_cxxflags -std=gnu++11 + check_add_cxxflags -std=gnu++17 # iOS/ARM builds do not work with gtest. This does not match # x86 targets. ;; *-iphonesimulator-*) - check_add_cxxflags -std=gnu++11 && soft_enable webm_io + check_add_cxxflags -std=gnu++17 && soft_enable webm_io soft_enable libyuv ;; *-win*) # Some mingw toolchains don't have pthread available by default. # Treat these more like visual studio where threading in gtest # would be disabled for the same reason. - check_add_cxxflags -std=gnu++11 && soft_enable unit_tests \ + check_add_cxxflags -std=gnu++17 && soft_enable unit_tests \ && soft_enable webm_io check_cxx "$@" < $@ +CLEAN-OBJS += vpxdec_srcs.txt + # # Documentation Rules # diff --git a/libs/libvpx/examples/resize_util.c b/libs/libvpx/examples/resize_util.c deleted file mode 100644 index 7e529b2e20..0000000000 --- a/libs/libvpx/examples/resize_util.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2014 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include -#include -#include -#include -#include -#include - -#include "../tools_common.h" -#include "../vp9/encoder/vp9_resize.h" - -static const char *exec_name = NULL; - -static void usage() { - printf("Usage:\n"); - printf("%s x x ", - exec_name); - printf(" []\n"); -} - -void usage_exit(void) { - usage(); - exit(EXIT_FAILURE); -} - -static int parse_dim(char *v, int *width, int *height) { - char *x = strchr(v, 'x'); - if (x == NULL) x = strchr(v, 'X'); - if (x == NULL) return 0; - *width = atoi(v); - *height = atoi(&x[1]); - if (*width <= 0 || *height <= 0) - return 0; - else - return 1; -} - -int main(int argc, char *argv[]) { - char *fin, *fout; - FILE *fpin, *fpout; - uint8_t *inbuf, *outbuf; - uint8_t *inbuf_u, *outbuf_u; - uint8_t *inbuf_v, *outbuf_v; - int f, frames; - int width, height, target_width, target_height; - - exec_name = argv[0]; - - if (argc < 5) { - printf("Incorrect parameters:\n"); - usage(); - return 1; - } - - fin = argv[1]; - fout = argv[4]; - if (!parse_dim(argv[2], &width, &height)) { - printf("Incorrect parameters: %s\n", argv[2]); - usage(); - return 1; - } - if (!parse_dim(argv[3], &target_width, &target_height)) { - printf("Incorrect parameters: %s\n", argv[3]); - usage(); - return 1; - } - - fpin = fopen(fin, "rb"); - if (fpin == NULL) { - printf("Can't open file %s to read\n", fin); - usage(); - return 1; - } - fpout = fopen(fout, "wb"); - if (fpout == NULL) { - printf("Can't open file %s to write\n", fout); - usage(); - return 1; - } - if (argc >= 6) - frames = atoi(argv[5]); - else - frames = INT_MAX; - - printf("Input size: %dx%d\n", width, height); - printf("Target size: %dx%d, Frames: ", target_width, target_height); - if (frames == INT_MAX) - printf("All\n"); - else - printf("%d\n", frames); - - inbuf = (uint8_t *)malloc(width * height * 3 / 2); - outbuf = (uint8_t *)malloc(target_width * target_height * 3 / 2); - inbuf_u = inbuf + width * height; - inbuf_v = inbuf_u + width * height / 4; - outbuf_u = outbuf + target_width * target_height; - outbuf_v = outbuf_u + target_width * target_height / 4; - f = 0; - while (f < frames) { - if (fread(inbuf, width * height * 3 / 2, 1, fpin) != 1) break; - vp9_resize_frame420(inbuf, width, inbuf_u, inbuf_v, width / 2, height, - width, outbuf, target_width, outbuf_u, outbuf_v, - target_width / 2, target_height, target_width); - fwrite(outbuf, target_width * target_height * 3 / 2, 1, fpout); - f++; - } - printf("%d frames processed\n", f); - fclose(fpin); - fclose(fpout); - - free(inbuf); - free(outbuf); - return 0; -} diff --git a/libs/libvpx/examples/set_maps.c b/libs/libvpx/examples/set_maps.c index 867e473aea..05c7f54b33 100644 --- a/libs/libvpx/examples/set_maps.c +++ b/libs/libvpx/examples/set_maps.c @@ -192,7 +192,8 @@ int main(int argc, char **argv) { printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface())); res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); - if (res) die_codec(&codec, "Failed to get default codec config."); + if (res) + die("Failed to get default codec config: %s", vpx_codec_err_to_string(res)); cfg.g_w = info.frame_width; cfg.g_h = info.frame_height; diff --git a/libs/libvpx/examples/simple_decoder.c b/libs/libvpx/examples/simple_decoder.c index d089e826d5..542f07371c 100644 --- a/libs/libvpx/examples/simple_decoder.c +++ b/libs/libvpx/examples/simple_decoder.c @@ -73,12 +73,15 @@ // This example does not special case any error return codes. If there was // an error, a descriptive message is printed and the program exits. With // few exceptions, vpx_codec functions return an enumerated error status, -// with the value `0` indicating success. +// with the value `0` indicating success. VP8 may return success for a +// corrupted frame, so the VP8D_GET_FRAME_CORRUPTED control is checked after +// every decode. #include #include #include +#include "vpx/vp8dx.h" #include "vpx/vpx_decoder.h" #include "../tools_common.h" @@ -124,10 +127,14 @@ int main(int argc, char **argv) { vpx_codec_iter_t iter = NULL; vpx_image_t *img = NULL; size_t frame_size = 0; + int corrupted = 0; const unsigned char *frame = vpx_video_reader_get_frame(reader, &frame_size); if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0)) die_codec(&codec, "Failed to decode frame."); + if (vpx_codec_control(&codec, VP8D_GET_FRAME_CORRUPTED, &corrupted)) + die_codec(&codec, "Failed to get frame corrupted state."); + if (corrupted) die("Frame %d is corrupted.", frame_cnt); while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL) { vpx_img_write(img, outfile); diff --git a/libs/libvpx/examples/simple_encoder.c b/libs/libvpx/examples/simple_encoder.c index dffdd6d7da..4b09a81710 100644 --- a/libs/libvpx/examples/simple_encoder.c +++ b/libs/libvpx/examples/simple_encoder.c @@ -202,7 +202,8 @@ int main(int argc, char **argv) { printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface())); res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); - if (res) die_codec(&codec, "Failed to get default codec config."); + if (res) + die("Failed to get default codec config: %s", vpx_codec_err_to_string(res)); cfg.g_w = info.frame_width; cfg.g_h = info.frame_height; diff --git a/libs/libvpx/examples/svc_context.h b/libs/libvpx/examples/svc_context.h index c5779ce8a9..7ca987dc83 100644 --- a/libs/libvpx/examples/svc_context.h +++ b/libs/libvpx/examples/svc_context.h @@ -39,6 +39,7 @@ typedef struct { int speed; // speed setting for codec int threads; int aqmode; // turns on aq-mode=3 (cyclic_refresh): 0=off, 1=on. + int use_psnr; // private storage for vpx_svc_encode void *internal; } SvcContext; @@ -58,6 +59,7 @@ typedef struct SvcInternal { double psnr_sum[VPX_SS_MAX_LAYERS][COMPONENTS]; // total/Y/U/V uint64_t sse_sum[VPX_SS_MAX_LAYERS][COMPONENTS]; uint32_t bytes_sum[VPX_SS_MAX_LAYERS]; + int number_of_frames[VPX_SS_MAX_LAYERS]; // codec encoding values int width; // width of highest layer @@ -65,7 +67,6 @@ typedef struct SvcInternal { int kf_dist; // distance between keyframes // state variables - int psnr_pkt_received; int layer; int use_multiple_frame_contexts; diff --git a/libs/libvpx/examples/svc_encodeframe.c b/libs/libvpx/examples/svc_encodeframe.c index 08bda0e5c9..54843f0f0f 100644 --- a/libs/libvpx/examples/svc_encodeframe.c +++ b/libs/libvpx/examples/svc_encodeframe.c @@ -279,7 +279,7 @@ vpx_codec_err_t vpx_svc_set_options(SvcContext *svc_ctx, const char *options) { if (svc_ctx == NULL || options == NULL || si == NULL) { return VPX_CODEC_INVALID_PARAM; } - strncpy(si->options, options, sizeof(si->options)); + strncpy(si->options, options, sizeof(si->options) - 1); si->options[sizeof(si->options) - 1] = '\0'; return VPX_CODEC_OK; } @@ -381,7 +381,7 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx, vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *enc_cfg) { vpx_codec_err_t res; - int i, sl, tl; + int sl, tl; SvcInternal_t *const si = get_svc_internal(svc_ctx); if (svc_ctx == NULL || codec_ctx == NULL || iface == NULL || enc_cfg == NULL) { @@ -433,7 +433,7 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx, } for (tl = 0; tl < svc_ctx->temporal_layers; ++tl) { for (sl = 0; sl < svc_ctx->spatial_layers; ++sl) { - i = sl * svc_ctx->temporal_layers + tl; + const int i = sl * svc_ctx->temporal_layers + tl; si->svc_params.max_quantizers[i] = MAX_QUANTIZER; si->svc_params.min_quantizers[i] = 0; if (enc_cfg->rc_end_usage == VPX_CBR && @@ -503,7 +503,7 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx, for (tl = 0; tl < svc_ctx->temporal_layers; ++tl) { for (sl = 0; sl < svc_ctx->spatial_layers; ++sl) { - i = sl * svc_ctx->temporal_layers + tl; + const int i = sl * svc_ctx->temporal_layers + tl; if (enc_cfg->rc_end_usage == VPX_CBR && enc_cfg->g_pass == VPX_RC_ONE_PASS) { si->svc_params.max_quantizers[i] = enc_cfg->rc_max_quantizer; @@ -516,7 +516,11 @@ vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx, enc_cfg->g_error_resilient = 1; // Initialize codec - res = vpx_codec_enc_init(codec_ctx, iface, enc_cfg, VPX_CODEC_USE_PSNR); + vpx_codec_flags_t flags = 0; + if (svc_ctx->use_psnr) { + flags |= VPX_CODEC_USE_PSNR; + } + res = vpx_codec_enc_init(codec_ctx, iface, enc_cfg, flags); if (res != VPX_CODEC_OK) { svc_log(svc_ctx, SVC_LOG_ERROR, "svc_enc_init error\n"); return res; @@ -536,8 +540,6 @@ vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx, struct vpx_image *rawimg, vpx_codec_pts_t pts, int64_t duration, int deadline) { vpx_codec_err_t res; - vpx_codec_iter_t iter; - const vpx_codec_cx_pkt_t *cx_pkt; SvcInternal_t *const si = get_svc_internal(svc_ctx); if (svc_ctx == NULL || codec_ctx == NULL || si == NULL) { return VPX_CODEC_INVALID_PARAM; @@ -548,17 +550,6 @@ vpx_codec_err_t vpx_svc_encode(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx, if (res != VPX_CODEC_OK) { return res; } - // save compressed data - iter = NULL; - while ((cx_pkt = vpx_codec_get_cx_data(codec_ctx, &iter))) { - switch (cx_pkt->kind) { - case VPX_CODEC_PSNR_PKT: { - } - ++si->psnr_pkt_received; - break; - default: { break; } - } - } return VPX_CODEC_OK; } @@ -570,7 +561,6 @@ static double calc_psnr(double d) { // dump accumulated statistics and reset accumulated values void vpx_svc_dump_statistics(SvcContext *svc_ctx) { - int number_of_frames; int i, j; uint32_t bytes_total = 0; double scale[COMPONENTS]; @@ -581,19 +571,18 @@ void vpx_svc_dump_statistics(SvcContext *svc_ctx) { SvcInternal_t *const si = get_svc_internal(svc_ctx); if (svc_ctx == NULL || si == NULL) return; - number_of_frames = si->psnr_pkt_received; - if (number_of_frames <= 0) return; - svc_log(svc_ctx, SVC_LOG_INFO, "\n"); for (i = 0; i < svc_ctx->spatial_layers; ++i) { svc_log(svc_ctx, SVC_LOG_INFO, - "Layer %d Average PSNR=[%2.3f, %2.3f, %2.3f, %2.3f], Bytes=[%u]\n", - i, si->psnr_sum[i][0] / number_of_frames, - si->psnr_sum[i][1] / number_of_frames, - si->psnr_sum[i][2] / number_of_frames, - si->psnr_sum[i][3] / number_of_frames, si->bytes_sum[i]); + "Layer %d Average PSNR=[%2.3f, %2.3f, %2.3f, %2.3f], Bytes=[%u], " + "Number_of_frames %d \n", + i, si->psnr_sum[i][0] / si->number_of_frames[i], + si->psnr_sum[i][1] / si->number_of_frames[i], + si->psnr_sum[i][2] / si->number_of_frames[i], + si->psnr_sum[i][3] / si->number_of_frames[i], si->bytes_sum[i], + si->number_of_frames[i]); // the following psnr calculation is deduced from ffmpeg.c#print_report - y_scale = si->width * si->height * 255.0 * 255.0 * number_of_frames; + y_scale = si->width * si->height * 255.0 * 255.0 * si->number_of_frames[i]; scale[1] = y_scale; scale[2] = scale[3] = y_scale / 4; // U or V scale[0] = y_scale * 1.5; // total @@ -610,17 +599,17 @@ void vpx_svc_dump_statistics(SvcContext *svc_ctx) { mse[1], mse[2], mse[3]); bytes_total += si->bytes_sum[i]; - // Clear sums for next time. + } + // Clear sums for next time. + for (i = 0; i < svc_ctx->spatial_layers; ++i) { si->bytes_sum[i] = 0; + si->number_of_frames[i] = 0; for (j = 0; j < COMPONENTS; ++j) { si->psnr_sum[i][j] = 0; si->sse_sum[i][j] = 0; } } - // only display statistics once - si->psnr_pkt_received = 0; - svc_log(svc_ctx, SVC_LOG_INFO, "Total Bytes=[%u]\n", bytes_total); } diff --git a/libs/libvpx/examples/twopass_encoder.c b/libs/libvpx/examples/twopass_encoder.c index 07a10d9cf3..d7bdccc256 100644 --- a/libs/libvpx/examples/twopass_encoder.c +++ b/libs/libvpx/examples/twopass_encoder.c @@ -191,7 +191,6 @@ static void pass1(vpx_image_t *raw, FILE *infile, const char *outfile_name, int main(int argc, char **argv) { FILE *infile = NULL; int w, h; - vpx_codec_ctx_t codec; vpx_codec_enc_cfg_t cfg; vpx_image_t raw; vpx_codec_err_t res; @@ -228,7 +227,8 @@ int main(int argc, char **argv) { // Configuration res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); - if (res) die_codec(&codec, "Failed to get default codec config."); + if (res) + die("Failed to get default codec config: %s", vpx_codec_err_to_string(res)); cfg.g_w = w; cfg.g_h = h; diff --git a/libs/libvpx/examples/vp8_multi_resolution_encoder.c b/libs/libvpx/examples/vp8_multi_resolution_encoder.c index 62d96de557..60161da90a 100644 --- a/libs/libvpx/examples/vp8_multi_resolution_encoder.c +++ b/libs/libvpx/examples/vp8_multi_resolution_encoder.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -438,7 +437,7 @@ int main(int argc, char **argv) { /* Other-resolution encoder settings */ for (i = 1; i < NUM_ENCODERS; i++) { - memcpy(&cfg[i], &cfg[0], sizeof(vpx_codec_enc_cfg_t)); + cfg[i] = cfg[0]; cfg[i].rc_target_bitrate = target_bitrate[i]; diff --git a/libs/libvpx/examples/vp8cx_set_ref.c b/libs/libvpx/examples/vp8cx_set_ref.c index ca528f9e90..104e8ebbc7 100644 --- a/libs/libvpx/examples/vp8cx_set_ref.c +++ b/libs/libvpx/examples/vp8cx_set_ref.c @@ -140,7 +140,8 @@ int main(int argc, char **argv) { printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface())); res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); - if (res) die_codec(&codec, "Failed to get default codec config."); + if (res) + die("Failed to get default codec config: %s", vpx_codec_err_to_string(res)); cfg.g_w = info.frame_width; cfg.g_h = info.frame_height; diff --git a/libs/libvpx/examples/vp9_lossless_encoder.c b/libs/libvpx/examples/vp9_lossless_encoder.c index c4eb3a8b17..01504d40c9 100644 --- a/libs/libvpx/examples/vp9_lossless_encoder.c +++ b/libs/libvpx/examples/vp9_lossless_encoder.c @@ -96,7 +96,8 @@ int main(int argc, char **argv) { printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface())); res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); - if (res) die_codec(&codec, "Failed to get default codec config."); + if (res) + die("Failed to get default codec config: %s", vpx_codec_err_to_string(res)); cfg.g_w = info.frame_width; cfg.g_h = info.frame_height; diff --git a/libs/libvpx/examples/vp9_spatial_svc_encoder.c b/libs/libvpx/examples/vp9_spatial_svc_encoder.c index e85dbf8e71..16e6aba6cd 100644 --- a/libs/libvpx/examples/vp9_spatial_svc_encoder.c +++ b/libs/libvpx/examples/vp9_spatial_svc_encoder.c @@ -14,8 +14,11 @@ * that benefit from a scalable bitstream. */ +#include +#include #include #include +#include #include #include #include @@ -24,14 +27,16 @@ #include "../tools_common.h" #include "../video_writer.h" +#include "../vpx_ports/bitops.h" #include "../vpx_ports/vpx_timer.h" #include "./svc_context.h" #include "vpx/vp8cx.h" +#include "vpx/vpx_decoder.h" #include "vpx/vpx_encoder.h" #include "../vpxstats.h" -#include "vp9/encoder/vp9_encoder.h" #include "./y4minput.h" +#define OUTPUT_FRAME_STATS 0 #define OUTPUT_RC_STATS 1 #define SIMULCAST_MODE 0 @@ -88,6 +93,8 @@ static const arg_def_t bitrates_arg = ARG_DEF("bl", "bitrates", 1, "bitrates[sl * num_tl + tl]"); static const arg_def_t dropframe_thresh_arg = ARG_DEF(NULL, "drop-frame", 1, "Temporal resampling threshold (buf %)"); +static const arg_def_t psnr_arg = + ARG_DEF(NULL, "psnr", 1, "Enable PSNR computation and statistics"); static const struct arg_enum_list tune_content_enum[] = { { "default", VP9E_CONTENT_DEFAULT }, { "screen", VP9E_CONTENT_SCREEN }, @@ -141,6 +148,7 @@ static const arg_def_t *svc_args[] = { &frames_arg, &dropframe_thresh_arg, &tune_content_arg, &inter_layer_pred_arg, + &psnr_arg, NULL }; static const uint32_t default_frames_to_skip = 0; @@ -200,6 +208,7 @@ static void parse_command_line(int argc, const char **argv_, #endif svc_ctx->speed = default_speed; svc_ctx->threads = default_threads; + svc_ctx->use_psnr = 0; // start with default encoder configuration res = vpx_codec_enc_config_default(vpx_codec_vp9_cx(), enc_cfg, 0); @@ -315,7 +324,6 @@ static void parse_command_line(int argc, const char **argv_, break; default: die("Error: Invalid bit depth selected (%d)\n", enc_cfg->g_bit_depth); - break; } #endif // CONFIG_VP9_HIGHBITDEPTH } else if (arg_match(&arg, &dropframe_thresh_arg, argi)) { @@ -324,6 +332,8 @@ static void parse_command_line(int argc, const char **argv_, app_input->tune_content = arg_parse_uint(&arg); } else if (arg_match(&arg, &inter_layer_pred_arg, argi)) { app_input->inter_layer_pred = arg_parse_uint(&arg); + } else if (arg_match(&arg, &psnr_arg, argi)) { + svc_ctx->use_psnr = arg_parse_uint(&arg); } else { ++argj; } @@ -776,8 +786,8 @@ static void svc_output_rc_stats( int count = 0; double sum_bitrate = 0.0; double sum_bitrate2 = 0.0; - vp9_zero(sizes); - vp9_zero(sizes_parsed); + memset(sizes, 0, sizeof(sizes)); + memset(sizes_parsed, 0, sizeof(sizes_parsed)); vpx_codec_control(codec, VP9E_GET_SVC_LAYER_ID, layer_id); parse_superframe_index(cx_pkt->data.frame.buf, cx_pkt->data.frame.sz, sizes_parsed, &count); @@ -880,7 +890,9 @@ int main(int argc, const char **argv) { int pts = 0; /* PTS starts at 0 */ int frame_duration = 1; /* 1 timebase tick per frame */ int end_of_stream = 0; +#if OUTPUT_FRAME_STATS int frames_received = 0; +#endif #if OUTPUT_RC_STATS VpxVideoWriter *outfile[VPX_SS_MAX_LAYERS] = { NULL }; struct RateControlStats rc; @@ -1126,41 +1138,65 @@ int main(int argc, const char **argv) { } #endif } - /* +#if OUTPUT_FRAME_STATS printf("SVC frame: %d, kf: %d, size: %d, pts: %d\n", frames_received, !!(cx_pkt->data.frame.flags & VPX_FRAME_IS_KEY), (int)cx_pkt->data.frame.sz, (int)cx_pkt->data.frame.pts); - */ - if (enc_cfg.ss_number_layers == 1 && enc_cfg.ts_number_layers == 1) - si->bytes_sum[0] += (int)cx_pkt->data.frame.sz; ++frames_received; +#endif + if (enc_cfg.ss_number_layers > 1) { + uint64_t sizes[8] = { 0 }; + int count = 0; + int num_layers_encoded = 0; + parse_superframe_index(cx_pkt->data.frame.buf, + cx_pkt->data.frame.sz, sizes, &count); + for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) { + if (cx_pkt->data.frame.spatial_layer_encoded[sl]) { + si->bytes_sum[sl] += (int)sizes[num_layers_encoded]; + num_layers_encoded++; + } + } + } else { + si->bytes_sum[0] += (int)cx_pkt->data.frame.sz; + } #if CONFIG_VP9_DECODER && !SIMULCAST_MODE if (vpx_codec_decode(&decoder, cx_pkt->data.frame.buf, (unsigned int)cx_pkt->data.frame.sz, NULL, 0)) die_codec(&decoder, "Failed to decode frame."); + vpx_codec_control(&encoder, VP9E_GET_SVC_LAYER_ID, &layer_id); + // Don't look for mismatch on top spatial and top temporal layers as + // they are non reference frames. Don't look at frames whose top + // spatial layer is dropped. + if ((enc_cfg.ss_number_layers > 1 || enc_cfg.ts_number_layers > 1) && + cx_pkt->data.frame + .spatial_layer_encoded[enc_cfg.ss_number_layers - 1] && + !(layer_id.temporal_layer_id > 0 && + layer_id.temporal_layer_id == + (int)enc_cfg.ts_number_layers - 1)) { + test_decode(&encoder, &decoder, frame_cnt, &mismatch_seen); + } #endif break; } + case VPX_CODEC_PSNR_PKT: { + SvcInternal_t *const si = (SvcInternal_t *)svc_ctx.internal; + sl = cx_pkt->data.psnr.spatial_layer_id; + si->number_of_frames[sl]++; + for (int j = 0; j < 4; ++j) { + si->psnr_sum[sl][j] += cx_pkt->data.psnr.psnr[j]; + si->sse_sum[sl][j] += cx_pkt->data.psnr.sse[j]; + } + break; + } case VPX_CODEC_STATS_PKT: { stats_write(&app_input.rc_stats, cx_pkt->data.twopass_stats.buf, cx_pkt->data.twopass_stats.sz); break; } - default: { break; } + default: { + break; + } } - -#if CONFIG_VP9_DECODER && !SIMULCAST_MODE - vpx_codec_control(&encoder, VP9E_GET_SVC_LAYER_ID, &layer_id); - // Don't look for mismatch on top spatial and top temporal layers as they - // are non reference frames. - if ((enc_cfg.ss_number_layers > 1 || enc_cfg.ts_number_layers > 1) && - !(layer_id.temporal_layer_id > 0 && - layer_id.temporal_layer_id == (int)enc_cfg.ts_number_layers - 1 && - cx_pkt->data.frame - .spatial_layer_encoded[enc_cfg.ss_number_layers - 1])) { - test_decode(&encoder, &decoder, frame_cnt, &mismatch_seen); - } -#endif } if (!end_of_stream) { diff --git a/libs/libvpx/examples/vp9cx_set_ref.c b/libs/libvpx/examples/vp9cx_set_ref.c index 1a0823153b..6e12d668b0 100644 --- a/libs/libvpx/examples/vp9cx_set_ref.c +++ b/libs/libvpx/examples/vp9cx_set_ref.c @@ -60,7 +60,7 @@ static const char *exec_name; -void usage_exit() { +void usage_exit(void) { fprintf(stderr, "Usage: %s " " \n", diff --git a/libs/libvpx/examples/vpx_dec_fuzzer.cc b/libs/libvpx/examples/vpx_dec_fuzzer.cc index 5eba9d74da..86d2d35392 100644 --- a/libs/libvpx/examples/vpx_dec_fuzzer.cc +++ b/libs/libvpx/examples/vpx_dec_fuzzer.cc @@ -41,8 +41,8 @@ $make -j32 * Build vp9 fuzzer - $ $CXX $CXXFLAGS -std=gnu++11 -DDECODER=vp9 \ - -fsanitize=fuzzer -I../libvpx -I. -Wl,--start-group \ + $ $CXX $CXXFLAGS -std=gnu++17 -Wall -Wextra -Wimplicit-fallthrough \ + -DDECODER=vp9 -fsanitize=fuzzer -I../libvpx -I. -Wl,--start-group \ ../libvpx/examples/vpx_dec_fuzzer.cc -o ./vpx_dec_fuzzer_vp9 \ ./libvpx.a -Wl,--end-group @@ -69,6 +69,7 @@ #include #include +#include "third_party/nalloc/nalloc.h" #include "vpx/vp8dx.h" #include "vpx/vpx_decoder.h" #include "vpx_ports/mem_ops.h" @@ -85,33 +86,64 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (size <= IVF_FILE_HDR_SZ) { return 0; } + nalloc_init(nullptr); vpx_codec_ctx_t codec; // Set thread count in the range [1, 64]. const unsigned int threads = (data[IVF_FILE_HDR_SZ] & 0x3f) + 1; vpx_codec_dec_cfg_t cfg = { threads, 0, 0 }; - if (vpx_codec_dec_init(&codec, VPXD_INTERFACE(DECODER), &cfg, 0)) { + vpx_codec_flags_t flags = 0; + if ((data[IVF_FILE_HDR_SZ] & 0x40) != 0) { + flags |= VPX_CODEC_USE_POSTPROC; + } + vpx_codec_err_t err = + vpx_codec_dec_init(&codec, VPXD_INTERFACE(DECODER), &cfg, flags); + if (err == VPX_CODEC_INCAPABLE) { + // vpx_codec_dec_init may fail with VPX_CODEC_USE_POSTPROC + // if the library is configured with --disable-postproc. + flags = 0; + if (vpx_codec_dec_init(&codec, VPXD_INTERFACE(DECODER), &cfg, flags)) { + return 0; + } + } else if (err != 0) { return 0; } + nalloc_start(data, size); + if (threads > 1) { const int enable = (data[IVF_FILE_HDR_SZ] & 0xa0) != 0; - const vpx_codec_err_t err = - vpx_codec_control(&codec, VP9D_SET_LOOP_FILTER_OPT, enable); - static_cast(err); + err = vpx_codec_control(&codec, VP9D_SET_LOOP_FILTER_OPT, enable); } data += IVF_FILE_HDR_SZ; size -= IVF_FILE_HDR_SZ; + int frame_cnt = 0; while (size > IVF_FRAME_HDR_SZ) { size_t frame_size = mem_get_le32(data); size -= IVF_FRAME_HDR_SZ; data += IVF_FRAME_HDR_SZ; frame_size = std::min(size, frame_size); - const vpx_codec_err_t err = - vpx_codec_decode(&codec, data, frame_size, nullptr, 0); + vpx_codec_stream_info_t stream_info; + stream_info.sz = sizeof(stream_info); + err = vpx_codec_peek_stream_info(VPXD_INTERFACE(DECODER), data, size, + &stream_info); + + ++frame_cnt; + if (flags & VPX_CODEC_USE_POSTPROC) { + if (frame_cnt % 16 == 4) { + vp8_postproc_cfg_t pp = { 0, 0, 0 }; + if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp)) goto fail; + } else if (frame_cnt % 16 == 12) { + vp8_postproc_cfg_t pp = { VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE, 4, + 0 }; + if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp)) goto fail; + } + } + + err = vpx_codec_decode(&codec, data, frame_size, nullptr, 0); static_cast(err); vpx_codec_iter_t iter = nullptr; vpx_image_t *img = nullptr; @@ -120,6 +152,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { data += frame_size; size -= frame_size; } +fail: vpx_codec_destroy(&codec); + nalloc_end(); return 0; } diff --git a/libs/libvpx/examples/vpx_enc_fuzzer.cc b/libs/libvpx/examples/vpx_enc_fuzzer.cc new file mode 100644 index 0000000000..d71994b60e --- /dev/null +++ b/libs/libvpx/examples/vpx_enc_fuzzer.cc @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2025 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +/* + * Fuzzer for libvpx encoders + * ========================== + * Requirements + * -------------- + * Requires Clang 6.0 or above as -fsanitize=fuzzer is used as a linker + * option. + + * Steps to build + * -------------- + * Clone libvpx repository + $git clone https://chromium.googlesource.com/webm/libvpx + + * Create a directory in parallel to libvpx and change directory + $mkdir vpx_enc_fuzzer + $cd vpx_enc_fuzzer/ + + * Enable sanitizers (Supported: address integer memory thread undefined) + $source ../libvpx/tools/set_analyzer_env.sh address + + * Configure libvpx. + * Note --size-limit and VPX_MAX_ALLOCABLE_MEMORY are defined to avoid + * Out of memory errors when running generated fuzzer binary + $../libvpx/configure --disable-unit-tests --size-limit=12288x12288 \ + --extra-cflags="-fsanitize=fuzzer-no-link \ + -DVPX_MAX_ALLOCABLE_MEMORY=1073741824" \ + --disable-webm-io --enable-debug --enable-vp8-encoder \ + --enable-vp9-encoder --disable-examples + + * Build libvpx + $make -j32 + + * Build vp9 fuzzer + $ $CXX $CXXFLAGS -std=gnu++17 -Wall -Wextra -Wimplicit-fallthrough \ + -DENCODER=vp9 -fsanitize=fuzzer -I../libvpx -I. -Wl,--start-group \ + ../libvpx/examples/vpx_enc_fuzzer.cc -o ./vpx_enc_fuzzer_vp9 \ + ./libvpx.a -Wl,--end-group + + * ENCODER should be defined as vp9 or vp8 to enable vp9/vp8 + * + * create a corpus directory and copy some ivf files there. + * Based on which codec (vp8/vp9) is being tested, it is recommended to + * have corresponding ivf files in corpus directory + * Empty corpus directory also is acceptable, though not recommended + $mkdir CORPUS && cp some-files CORPUS + + * Run fuzzing: + $./vpx_enc_fuzzer_vp9 CORPUS + + * References: + * http://llvm.org/docs/LibFuzzer.html + * https://github.com/google/oss-fuzz + */ + +#include +#include +#include +#include +#include +#include + +#include "vpx/vp8cx.h" +#include "vpx/vpx_encoder.h" +#include "vpx_ports/mem_ops.h" +#include "third_party/nalloc/nalloc.h" + +// fuzz header to have config options, before raw image data +#define FUZZ_HDR_SZ 32 + +#define VPXC_INTERFACE(name) VPXC_INTERFACE_(name) +#define VPXC_INTERFACE_(name) vpx_codec_##name##_cx() + +extern "C" void usage_exit(void) { exit(EXIT_FAILURE); } + +static int vpx_img_plane_width(const vpx_image_t *img, int plane) { + if (plane > 0 && img->x_chroma_shift > 0) + return (img->d_w + 1) >> img->x_chroma_shift; + else + return img->d_w; +} + +static int vpx_img_plane_height(const vpx_image_t *img, int plane) { + if (plane > 0 && img->y_chroma_shift > 0) + return (img->d_h + 1) >> img->y_chroma_shift; + else + return img->d_h; +} + +static int fuzz_vpx_img_read(vpx_image_t *img, const uint8_t *data, + size_t size) { + int plane; + // TODO: wtc - Need to clamp the sample values so that they are in range + // For example, if the bit depth is 10, the sample values must be <= 1023. + assert(img->bit_depth == 8); + const size_t bytespp = (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1; + + if (size == 0) return 0; + size_t used = 0; + for (plane = 0; plane < 3; ++plane) { + unsigned char *buf = img->planes[plane]; + const int stride = img->stride[plane]; + int w = vpx_img_plane_width(img, plane); + const int h = vpx_img_plane_height(img, plane); + int y; + + // Assuming that for nv12 we read all chroma data at once + if (img->fmt == VPX_IMG_FMT_NV12 && plane > 1) break; + // NV12 UV plane is interleaved, so it has twice the width of a subsampled + // plane. + if (img->fmt == VPX_IMG_FMT_NV12 && plane == 1) w = w * 2; + + for (y = 0; y < h; ++y) { + size_t nb = bytespp * w; + if (nb > size - used) { + nb = size - used; + } + memcpy(buf, data, nb); + memset(buf + nb, 0, bytespp * w - nb); + buf += stride; + data += nb; + used += nb; + } + } + + return used; +} + +static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img, + int frame_index, int flags, FILE *out, + vpx_enc_deadline_t quality) { + int got_pkts = 0; + vpx_codec_iter_t iter = nullptr; + const vpx_codec_cx_pkt_t *pkt = nullptr; + const vpx_codec_err_t res = + vpx_codec_encode(codec, img, frame_index, 1, flags, quality); + if (res != VPX_CODEC_OK) return 0; + + while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != nullptr) { + got_pkts = 1; + + if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { + if (fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, out) != + pkt->data.frame.sz) + return 0; + } + } + + return got_pkts; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + if (size <= FUZZ_HDR_SZ) { + return 0; + } + nalloc_init(nullptr); + + int keyframe_interval = 0; + int frame_count = 0; + vpx_codec_ctx_t codec; + vpx_image_t raw; + vpx_codec_enc_cfg_t cfg; + vpx_enc_deadline_t quality = VPX_DL_GOOD_QUALITY; + + if ((data[0] & 0x80) != 0) { + keyframe_interval = 8; + } + if ((data[0] & 0x40) != 0) { + quality = VPX_DL_REALTIME; + } else if ((data[0] & 0x20) != 0) { + quality = VPX_DL_BEST_QUALITY; + } + const int max_frames = (quality == VPX_DL_BEST_QUALITY) ? 150 : 300; + + if (vpx_codec_enc_config_default(VPXC_INTERFACE(ENCODER), &cfg, 0)) abort(); + FILE *out = fopen("/dev/null", "wb"); + + switch (data[0] & 0x1F) { + case 0: + cfg.g_w = 64; + cfg.g_h = 1; + break; + case 1: + cfg.g_w = 1; + cfg.g_h = 48; + break; + case 2: + cfg.g_w = 1; + cfg.g_h = 1; + break; + case 3: + cfg.g_w = 4; + cfg.g_h = 4; + break; + case 4: + cfg.g_w = 16; + cfg.g_h = 16; + break; + default: + cfg.g_w = 64; + cfg.g_h = 48; + break; + } + cfg.g_timebase.num = 1; + cfg.g_timebase.den = 30; // fps + cfg.rc_target_bitrate = 200; + cfg.g_error_resilient = 1; + + if (vpx_codec_enc_init(&codec, VPXC_INTERFACE(ENCODER), &cfg, 0)) { + return 0; + } + + if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h, 1)) { + goto fail; + } + + nalloc_start(data, size); + // We may want to add more config options (for more complex encoders as seen + // in the examples) in the future while still maintaining the same format (so + // that generated corpus is still valid). So we reserve FUZZ_HDR_SZ=32 bytes + // for this even if we just use one byte so far. + data += FUZZ_HDR_SZ; + size -= FUZZ_HDR_SZ; + + // Encode frames. + for (int i = 0; i < max_frames; ++i) { + int flags = 0; + size_t size_read = fuzz_vpx_img_read(&raw, data, size); + if (size_read == 0) break; + data += size_read; + size -= size_read; + if (keyframe_interval > 0 && frame_count % keyframe_interval == 0) + flags |= VPX_EFLAG_FORCE_KF; + encode_frame(&codec, &raw, frame_count++, flags, out, quality); + } + + // Flush encoder. + while (encode_frame(&codec, nullptr, -1, 0, out, quality)) { + } + +fail: + nalloc_end(); + vpx_img_free(&raw); + vpx_codec_destroy(&codec); + fclose(out); + return 0; +} diff --git a/libs/libvpx/examples/vpx_temporal_svc_encoder.c b/libs/libvpx/examples/vpx_temporal_svc_encoder.c index a80027822a..3848b245a2 100644 --- a/libs/libvpx/examples/vpx_temporal_svc_encoder.c +++ b/libs/libvpx/examples/vpx_temporal_svc_encoder.c @@ -32,8 +32,6 @@ #define zero(Dest) memset(&(Dest), 0, sizeof(Dest)) -static const char *exec_name; - void usage_exit(void) { exit(EXIT_FAILURE); } // Denoiser states for vp8, for temporal denoising. @@ -607,19 +605,24 @@ static void set_temporal_layer_pattern(int layering_mode, } #if ROI_MAP -static void read_mask(FILE *mask_file, int *seg_map) { +static int read_mask(FILE *mask_file, int *seg_map, int allowed_mask_rows, + int allowed_mask_cols) { int mask_rows, mask_cols, i, j; int *map_start = seg_map; - fscanf(mask_file, "%d %d\n", &mask_cols, &mask_rows); + if (fscanf(mask_file, "%d %d\n", &mask_cols, &mask_rows) != 2) return 0; + if (mask_rows != allowed_mask_rows || mask_cols != allowed_mask_cols) { + return 0; + } for (i = 0; i < mask_rows; i++) { for (j = 0; j < mask_cols; j++) { - fscanf(mask_file, "%d ", &seg_map[j]); + if (fscanf(mask_file, "%d ", &seg_map[j]) != 1) return 0; // reverse the bit seg_map[j] = 1 - seg_map[j]; } seg_map += mask_cols; } seg_map = map_start; + return 1; } #endif @@ -679,7 +682,6 @@ int main(int argc, char **argv) { input_ctx.only_i420 = 1; input_ctx.bit_depth = 0; - exec_name = argv[0]; // Check usage and arguments. if (argc < min_args) { #if CONFIG_VP9_HIGHBITDEPTH @@ -965,12 +967,16 @@ int main(int argc, char **argv) { argv[argc - 1], frame_cnt); mask_file = fopen(mask_file_name, "r"); if (mask_file != NULL) { - read_mask(mask_file, mask_map); + int mask_is_valid = read_mask(mask_file, mask_map, mask_rows, mask_cols); fclose(mask_file); - // set_roi_map(encoder->name, &cfg, &roi); - set_roi_skip_map(&cfg, &roi, mask_map, prev_mask_map, frame_cnt); - if (vpx_codec_control(&codec, VP9E_SET_ROI_MAP, &roi)) - die_codec(&codec, "Failed to set ROI map"); + if (mask_is_valid) { + // set_roi_map(encoder->name, &cfg, &roi); + set_roi_skip_map(&cfg, &roi, mask_map, prev_mask_map, frame_cnt); + if (vpx_codec_control(&codec, VP9E_SET_ROI_MAP, &roi)) + die_codec(&codec, "Failed to set ROI map"); + } else { + die_codec(&codec, "Mask input is invalid for ROI map"); + } } #endif frame_avail = read_frame(&input_ctx, &raw); diff --git a/libs/libvpx/libs.doxy_template b/libs/libvpx/libs.doxy_template index 1eacc8fe2d..6d05162d00 100644 --- a/libs/libvpx/libs.doxy_template +++ b/libs/libvpx/libs.doxy_template @@ -654,12 +654,6 @@ VERBATIM_HEADERS = YES ALPHABETICAL_INDEX = NO -# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then -# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns -# in which this list will be split (can be a number in the range [1..20]) - -COLS_IN_ALPHA_INDEX = 5 - # In case all classes in a project start with a common prefix, all # classes will be put under the same header in the alphabetical index. # The IGNORE_PREFIX tag can be used to specify one or more prefixes that @@ -1099,32 +1093,10 @@ ALLEXTERNALS = NO EXTERNAL_GROUPS = YES -# The PERL_PATH should be the absolute path and name of the perl script -# interpreter (i.e. the result of `which perl'). - -PERL_PATH = /usr/bin/perl - #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- -# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will -# generate a inheritance diagram (in HTML, RTF and la_te_x) for classes with base -# or super classes. Setting the tag to NO turns the diagrams off. Note that -# this option is superseded by the HAVE_DOT option below. This is only a -# fallback. It is recommended to install and use dot, since it yields more -# powerful graphs. - -CLASS_DIAGRAMS = YES - -# You can define message sequence charts within doxygen comments using the \msc -# command. Doxygen will then run the mscgen tool (see http://www.mcternan.me.uk/mscgen/) to -# produce the chart and insert it in the documentation. The MSCGEN_PATH tag allows you to -# specify the directory where the mscgen tool resides. If left empty the tool is assumed to -# be found in the default search path. - -MSCGEN_PATH = - # If set to YES, the inheritance and collaboration graphs will hide # inheritance and usage relations if the target is undocumented # or is not a class. @@ -1138,10 +1110,14 @@ HIDE_UNDOC_RELATIONS = YES HAVE_DOT = NO -# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect inheritance relations. Setting this tag to YES will force the -# the CLASS_DIAGRAMS tag to NO. +# If the CLASS_GRAPH tag is set to YES (or GRAPH) then doxygen will generate a +# graph for each documented class showing the direct and indirect inheritance +# relations. In case HAVE_DOT is set as well dot will be used to draw the graph, +# otherwise the built-in generator will be used. If the CLASS_GRAPH tag is set +# to TEXT the direct and indirect inheritance relations will be shown as texts / +# links. +# Possible values are: NO, YES, TEXT and GRAPH. +# The default value is: YES. CLASS_GRAPH = YES @@ -1247,14 +1223,6 @@ DOT_GRAPH_MAX_NODES = 50 MAX_DOT_GRAPH_DEPTH = 0 -# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, which results in a white background. -# Warning: Depending on the platform used, enabling this option may lead to -# badly anti-aliased labels on the edges of a graph (i.e. they become hard to -# read). - -DOT_TRANSPARENT = YES - # Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) diff --git a/libs/libvpx/libs.mk b/libs/libvpx/libs.mk index 00e49a19d7..c33b8bbf44 100644 --- a/libs/libvpx/libs.mk +++ b/libs/libvpx/libs.mk @@ -178,26 +178,21 @@ INSTALL-LIBS-yes += include/vpx/vpx_image.h INSTALL-LIBS-yes += include/vpx/vpx_integer.h INSTALL-LIBS-$(CONFIG_DECODERS) += include/vpx/vpx_decoder.h INSTALL-LIBS-$(CONFIG_ENCODERS) += include/vpx/vpx_encoder.h +INSTALL-LIBS-$(CONFIG_ENCODERS) += include/vpx/vpx_tpl.h ifeq ($(CONFIG_EXTERNAL_BUILD),yes) ifeq ($(CONFIG_MSVS),yes) INSTALL-LIBS-yes += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/$(CODEC_LIB).lib) +ifeq ($(CONFIG_STATIC),yes) INSTALL-LIBS-$(CONFIG_DEBUG_LIBS) += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/$(CODEC_LIB)d.lib) +endif INSTALL-LIBS-$(CONFIG_SHARED) += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/vpx.dll) INSTALL-LIBS-$(CONFIG_SHARED) += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/vpx.exp) endif else INSTALL-LIBS-$(CONFIG_STATIC) += $(LIBSUBDIR)/libvpx.a +ifeq ($(CONFIG_STATIC),yes) INSTALL-LIBS-$(CONFIG_DEBUG_LIBS) += $(LIBSUBDIR)/libvpx_g.a endif - -ifeq ($(CONFIG_VP9_ENCODER)$(CONFIG_RATE_CTRL),yesyes) - SIMPLE_ENCODE_SRCS := $(call enabled,CODEC_SRCS) - SIMPLE_ENCODE_SRCS += $(VP9_PREFIX)simple_encode.cc - SIMPLE_ENCODE_SRCS += $(VP9_PREFIX)simple_encode.h - SIMPLE_ENCODE_SRCS += ivfenc.h - SIMPLE_ENCODE_SRCS += ivfenc.c - INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(VP9_PREFIX)simple_encode.cc - INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(VP9_PREFIX)simple_encode.h endif CODEC_SRCS=$(call enabled,CODEC_SRCS) @@ -213,6 +208,11 @@ libvpx_srcs.txt: @echo $(CODEC_SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@ CLEAN-OBJS += libvpx_srcs.txt +libvpxrc_srcs.txt: + @echo " [CREATE] $@" + @echo $(RC_RTC_SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@ +CLEAN-OBJS += libvpxrc_srcs.txt + # Assembly files that are included, but don't define symbols themselves. # Filtered out to avoid Windows build warnings. ASM_INCLUDES := \ @@ -312,7 +312,7 @@ $(BUILD_PFX)libvpx_g.a: $(LIBVPX_OBJS) # To determine SO_VERSION_{MAJOR,MINOR,PATCH}, calculate c,a,r with current # SO_VERSION_* then follow the rules in the link to detemine the new version # (c1, a1, r1) and set MAJOR to [c1-a1], MINOR to a1 and PATCH to r1 -SO_VERSION_MAJOR := 7 +SO_VERSION_MAJOR := 12 SO_VERSION_MINOR := 1 SO_VERSION_PATCH := 0 ifeq ($(filter darwin%,$(TGT_OS)),$(TGT_OS)) @@ -418,13 +418,6 @@ ifeq ($(CONFIG_ENCODERS),yes) $(BUILD_PFX)libvpxrc_g.a: $(RC_RTC_OBJS) endif -ifeq ($(CONFIG_VP9_ENCODER)$(CONFIG_RATE_CTRL),yesyes) - SIMPLE_ENCODE_OBJS=$(call objs,$(SIMPLE_ENCODE_SRCS)) - OBJS-yes += $(SIMPLE_ENCODE_OBJS) - LIBS-yes += $(BUILD_PFX)libsimple_encode.a $(BUILD_PFX)libsimple_encode_g.a - $(BUILD_PFX)libsimple_encode_g.a: $(SIMPLE_ENCODE_OBJS) -endif - endif # ifeq ($(CONFIG_EXTERNAL_BUILD),yes) libvpx.ver: $(call enabled,CODEC_EXPORTS) @@ -446,13 +439,13 @@ ifeq ($(VPX_ARCH_X86)$(VPX_ARCH_X86_64),yes) # YASM $(BUILD_PFX)vpx_config.asm: $(BUILD_PFX)vpx_config.h @echo " [CREATE] $@" - @LC_ALL=C egrep "#define [A-Z0-9_]+ [01]" $< \ + @LC_ALL=C grep -E "#define [A-Z0-9_]+ [01]" $< \ | awk '{print $$2 " equ " $$3}' > $@ else ADS2GAS=$(if $(filter yes,$(CONFIG_GCC)),| $(ASM_CONVERSION)) $(BUILD_PFX)vpx_config.asm: $(BUILD_PFX)vpx_config.h @echo " [CREATE] $@" - @LC_ALL=C egrep "#define [A-Z0-9_]+ [01]" $< \ + @LC_ALL=C grep -E "#define [A-Z0-9_]+ [01]" $< \ | awk '{print $$2 " EQU " $$3}' $(ADS2GAS) > $@ @echo " END" $(ADS2GAS) >> $@ CLEAN-OBJS += $(BUILD_PFX)vpx_config.asm @@ -512,11 +505,6 @@ RC_INTERFACE_TEST_SRCS=$(call addprefix_clean,test/,\ RC_INTERFACE_TEST_OBJS := $(sort $(call objs,$(RC_INTERFACE_TEST_SRCS))) endif -SIMPLE_ENCODE_TEST_BIN=./test_simple_encode$(EXE_SFX) -SIMPLE_ENCODE_TEST_SRCS=$(call addprefix_clean,test/,\ - $(call enabled,SIMPLE_ENCODE_TEST_SRCS)) -SIMPLE_ENCODE_TEST_OBJS := $(sort $(call objs,$(SIMPLE_ENCODE_TEST_SRCS))) - libvpx_test_srcs.txt: @echo " [CREATE] $@" @echo $(LIBVPX_TEST_SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@ @@ -536,7 +524,7 @@ $(LIBVPX_TEST_DATA): $(SRC_PATH_BARE)/test/test-data.sha1 esac \ ) -testdata:: $(LIBVPX_TEST_DATA) +testdata: $(LIBVPX_TEST_DATA) $(qexec)[ -x "$$(which sha1sum)" ] && sha1sum=sha1sum;\ [ -x "$$(which shasum)" ] && sha1sum=shasum;\ [ -x "$$(which sha1)" ] && sha1sum=sha1;\ @@ -545,7 +533,7 @@ testdata:: $(LIBVPX_TEST_DATA) echo "Checking test data:";\ for f in $(call enabled,LIBVPX_TEST_DATA); do\ grep $$f $(SRC_PATH_BARE)/test/test-data.sha1 |\ - (cd $(LIBVPX_TEST_DATA_PATH); $${sha1sum} -c);\ + (cd "$(LIBVPX_TEST_DATA_PATH)"; $${sha1sum} -c);\ done; \ else\ echo "Skipping test data integrity check, sha1sum not found.";\ @@ -631,8 +619,8 @@ test_rc_interface.$(VCPROJ_SFX): $(RC_INTERFACE_TEST_SRCS) vpx.$(VCPROJ_SFX) \ -I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" \ -L. -l$(CODEC_LIB) -l$(RC_RTC_LIB) -l$(GTEST_LIB) $^ endif # RC_INTERFACE_TEST -endif # CONFIG_VP9_ENCODER -endif +endif # CONFIG_ENCODERS +endif # CONFIG_MSVS else include $(SRC_PATH_BARE)/third_party/googletest/gtest.mk @@ -687,19 +675,7 @@ $(eval $(call linkerxx_template,$(RC_INTERFACE_TEST_BIN), \ endif # RC_INTERFACE_TEST endif # CONFIG_ENCODERS -ifneq ($(strip $(SIMPLE_ENCODE_TEST_OBJS)),) -$(SIMPLE_ENCODE_TEST_OBJS) $(SIMPLE_ENCODE_TEST_OBJS:.o=.d): \ - CXXFLAGS += $(GTEST_INCLUDES) -OBJS-yes += $(SIMPLE_ENCODE_TEST_OBJS) -BINS-yes += $(SIMPLE_ENCODE_TEST_BIN) - -$(SIMPLE_ENCODE_TEST_BIN): $(TEST_LIBS) libsimple_encode.a -$(eval $(call linkerxx_template,$(SIMPLE_ENCODE_TEST_BIN), \ - $(SIMPLE_ENCODE_TEST_OBJS) \ - -L. -lsimple_encode -lvpx -lgtest $(extralibs) -lm)) -endif # SIMPLE_ENCODE_TEST - -endif # CONFIG_UNIT_TESTS +endif # CONFIG_EXTERNAL_BUILD # Install test sources only if codec source is included INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(patsubst $(SRC_PATH_BARE)/%,%,\ @@ -709,22 +685,22 @@ INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(TEST_INTRA_PRED_SPEED_SRCS) INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(RC_INTERFACE_TEST_SRCS) define test_shard_template -test:: test_shard.$(1) -test-no-data-check:: test_shard_ndc.$(1) +test: test_shard.$(1) +test-no-data-check: test_shard_ndc.$(1) test_shard.$(1) test_shard_ndc.$(1): $(LIBVPX_TEST_BIN) @set -e; \ export GTEST_SHARD_INDEX=$(1); \ export GTEST_TOTAL_SHARDS=$(2); \ $(LIBVPX_TEST_BIN) test_shard.$(1): testdata -.PHONY: test_shard.$(1) +.PHONY: test_shard.$(1) test_shard_ndc.$(1) endef NUM_SHARDS := 10 SHARDS := 0 1 2 3 4 5 6 7 8 9 $(foreach s,$(SHARDS),$(eval $(call test_shard_template,$(s),$(NUM_SHARDS)))) -endif +endif # CONFIG_UNIT_TESTS ## ## documentation directives @@ -764,10 +740,10 @@ TEST_BIN_PATH := $(addsuffix /$(TGT_OS:win64=x64)/Release, $(TEST_BIN_PATH)) endif utiltest utiltest-no-data-check: $(qexec)$(SRC_PATH_BARE)/test/vpxdec.sh \ - --test-data-path $(LIBVPX_TEST_DATA_PATH) \ + --test-data-path "$(LIBVPX_TEST_DATA_PATH)" \ --bin-path $(TEST_BIN_PATH) $(qexec)$(SRC_PATH_BARE)/test/vpxenc.sh \ - --test-data-path $(LIBVPX_TEST_DATA_PATH) \ + --test-data-path "$(LIBVPX_TEST_DATA_PATH)" \ --bin-path $(TEST_BIN_PATH) utiltest: testdata else @@ -791,7 +767,7 @@ EXAMPLES_BIN_PATH := $(TGT_OS:win64=x64)/Release endif exampletest exampletest-no-data-check: examples $(qexec)$(SRC_PATH_BARE)/test/examples.sh \ - --test-data-path $(LIBVPX_TEST_DATA_PATH) \ + --test-data-path "$(LIBVPX_TEST_DATA_PATH)" \ --bin-path $(EXAMPLES_BIN_PATH) exampletest: testdata else diff --git a/libs/libvpx/md5_utils.c b/libs/libvpx/md5_utils.c index c4106525f2..abd8d43c39 100644 --- a/libs/libvpx/md5_utils.c +++ b/libs/libvpx/md5_utils.c @@ -151,8 +151,8 @@ void MD5Final(md5byte digest[16], struct MD5Context *ctx) { * reflect the addition of 16 longwords of new data. MD5Update blocks * the data and converts bytes into longwords for this routine. */ -VPX_NO_UNSIGNED_OVERFLOW_CHECK void MD5Transform(UWORD32 buf[4], - UWORD32 const in[16]) { +VPX_NO_UNSIGNED_OVERFLOW_CHECK VPX_NO_UNSIGNED_SHIFT_CHECK void MD5Transform( + UWORD32 buf[4], UWORD32 const in[16]) { UWORD32 a, b, c, d; a = buf[0]; diff --git a/libs/libvpx/rate_hist.c b/libs/libvpx/rate_hist.c index 947950d481..6a056cac10 100644 --- a/libs/libvpx/rate_hist.c +++ b/libs/libvpx/rate_hist.c @@ -9,10 +9,11 @@ */ #include -#include #include -#include #include +#include +#include +#include #include "./rate_hist.h" @@ -48,7 +49,8 @@ struct rate_hist *init_rate_histogram(const vpx_codec_enc_cfg_t *cfg, // Determine the number of samples in the buffer. Use the file's framerate // to determine the number of frames in rc_buf_sz milliseconds, with an // adjustment (5/4) to account for alt-refs - hist->samples = cfg->rc_buf_sz * 5 / 4 * fps->num / fps->den / 1000; + hist->samples = + (int)((int64_t)cfg->rc_buf_sz * 5 / 4 * fps->num / fps->den / 1000); // prevent division by zero if (hist->samples == 0) hist->samples = 1; diff --git a/libs/libvpx/test/acm_random.h b/libs/libvpx/test/acm_random.h index 3458340a12..7500cb8266 100644 --- a/libs/libvpx/test/acm_random.h +++ b/libs/libvpx/test/acm_random.h @@ -15,7 +15,7 @@ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "vpx/vpx_integer.h" @@ -28,43 +28,45 @@ class ACMRandom { explicit ACMRandom(int seed) : random_(seed) {} void Reset(int seed) { random_.Reseed(seed); } - uint16_t Rand16(void) { + uint16_t Rand16() { const uint32_t value = random_.Generate(testing::internal::Random::kMaxRange); return (value >> 15) & 0xffff; } - int32_t Rand20Signed(void) { + int32_t Rand20Signed() { // Use 20 bits: values between 524287 and -524288. const uint32_t value = random_.Generate(1048576); return static_cast(value) - 524288; } - int16_t Rand16Signed(void) { + int16_t Rand16Signed() { // Use 16 bits: values between 32767 and -32768. return static_cast(random_.Generate(65536)); } - int16_t Rand13Signed(void) { - // Use 13 bits: values between 4095 and -4096. - const uint32_t value = random_.Generate(8192); - return static_cast(value) - 4096; + uint16_t Rand12() { + const uint32_t value = + random_.Generate(testing::internal::Random::kMaxRange); + // There's a bit more entropy in the upper bits of this implementation. + return (value >> 19) & 0xfff; } - int16_t Rand9Signed(void) { - // Use 9 bits: values between 255 (0x0FF) and -256 (0x100). - const uint32_t value = random_.Generate(512); - return static_cast(value) - 256; + uint16_t Rand10() { + const uint32_t value = + random_.Generate(testing::internal::Random::kMaxRange); + // There's a bit more entropy in the upper bits of this implementation. + return (value >> 21) & 0x3ff; } - uint8_t Rand8(void) { + uint8_t Rand8() { const uint32_t value = random_.Generate(testing::internal::Random::kMaxRange); // There's a bit more entropy in the upper bits of this implementation. return (value >> 23) & 0xff; } - uint8_t Rand8Extremes(void) { + uint8_t Rand8Extremes() { // Returns a random value near 0 or near 255, to better exercise // saturation behavior. const uint8_t r = Rand8(); @@ -82,7 +84,7 @@ class ACMRandom { int operator()(int n) { return PseudoUniform(n); } - static int DeterministicSeed(void) { return 0xbaba; } + static int DeterministicSeed() { return 0xbaba; } private: testing::internal::Random random_; diff --git a/libs/libvpx/test/active_map_refresh_test.cc b/libs/libvpx/test/active_map_refresh_test.cc index 68d8856eaa..a0b46059a7 100644 --- a/libs/libvpx/test/active_map_refresh_test.cc +++ b/libs/libvpx/test/active_map_refresh_test.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/util.h" @@ -62,16 +62,16 @@ class ActiveMapRefreshTest public ::libvpx_test::CodecTestWith2Params { protected: ActiveMapRefreshTest() : EncoderTest(GET_PARAM(0)) {} - virtual ~ActiveMapRefreshTest() {} + ~ActiveMapRefreshTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(GET_PARAM(1)); cpu_used_ = GET_PARAM(2); } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { ::libvpx_test::Y4mVideoSource *y4m_video = static_cast(video); if (video->frame() == 0) { diff --git a/libs/libvpx/test/active_map_test.cc b/libs/libvpx/test/active_map_test.cc index 543ec0d358..e8976b416a 100644 --- a/libs/libvpx/test/active_map_test.cc +++ b/libs/libvpx/test/active_map_test.cc @@ -9,7 +9,7 @@ */ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" @@ -26,16 +26,16 @@ class ActiveMapTest static const int kHeight = 144; ActiveMapTest() : EncoderTest(GET_PARAM(0)) {} - virtual ~ActiveMapTest() {} + ~ActiveMapTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(GET_PARAM(1)); cpu_used_ = GET_PARAM(2); } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, cpu_used_); encoder->Control(VP9E_SET_AQ_MODE, GET_PARAM(3)); diff --git a/libs/libvpx/test/add_noise_test.cc b/libs/libvpx/test/add_noise_test.cc index 7dc86e3eb6..f6f30bb594 100644 --- a/libs/libvpx/test/add_noise_test.cc +++ b/libs/libvpx/test/add_noise_test.cc @@ -8,14 +8,17 @@ * be found in the AUTHORS file in the root of the source tree. */ #include + +#include #include +#include "gtest/gtest.h" #include "test/clear_system_state.h" #include "test/register_state_check.h" #include "test/util.h" -#include "third_party/googletest/src/include/gtest/gtest.h" #include "./vpx_dsp_rtcd.h" #include "vpx/vpx_integer.h" +#include "vpx_config.h" #include "vpx_dsp/postproc.h" #include "vpx_mem/vpx_mem.h" @@ -23,17 +26,17 @@ namespace { static const int kNoiseSize = 3072; -typedef void (*AddNoiseFunc)(uint8_t *start, const int8_t *noise, - int blackclamp, int whiteclamp, int width, - int height, int pitch); +using AddNoiseFunc = void (*)(uint8_t *start, const int8_t *noise, + int blackclamp, int whiteclamp, int width, + int height, int pitch); -typedef std::tuple AddNoiseTestFPParam; +using AddNoiseTestFPParam = std::tuple; class AddNoiseTest : public ::testing::Test, public ::testing::WithParamInterface { public: - virtual void TearDown() { libvpx_test::ClearSystemState(); } - virtual ~AddNoiseTest() {} + void TearDown() override { libvpx_test::ClearSystemState(); } + ~AddNoiseTest() override = default; }; double stddev6(char a, char b, char c, char d, char e, char f) { @@ -97,33 +100,35 @@ TEST_P(AddNoiseTest, CheckNoiseAdded) { } TEST_P(AddNoiseTest, CheckCvsAssembly) { - const int width = 64; + static constexpr int kWidths[] = { 8, 18, 34, 64, 66 }; const int height = 64; - const int image_size = width * height; int8_t noise[kNoiseSize]; const int clamp = vpx_setup_noise(4.4, noise, kNoiseSize); - uint8_t *const s = reinterpret_cast(vpx_calloc(image_size, 1)); - uint8_t *const d = reinterpret_cast(vpx_calloc(image_size, 1)); - ASSERT_NE(s, nullptr); - ASSERT_NE(d, nullptr); + for (int width : kWidths) { + const int image_size = width * height; + std::unique_ptr s( + reinterpret_cast(vpx_calloc(image_size, 1)), vpx_free); + std::unique_ptr d( + reinterpret_cast(vpx_calloc(image_size, 1)), vpx_free); + ASSERT_NE(s, nullptr); + ASSERT_NE(d, nullptr); - memset(s, 99, image_size); - memset(d, 99, image_size); + memset(s.get(), 99, image_size); + memset(d.get(), 99, image_size); - srand(0); - ASM_REGISTER_STATE_CHECK( - GET_PARAM(1)(s, noise, clamp, clamp, width, height, width)); - srand(0); - ASM_REGISTER_STATE_CHECK( - vpx_plane_add_noise_c(d, noise, clamp, clamp, width, height, width)); + srand(0); + ASM_REGISTER_STATE_CHECK( + GET_PARAM(1)(s.get(), noise, clamp, clamp, width, height, width)); + srand(0); + ASM_REGISTER_STATE_CHECK(vpx_plane_add_noise_c(d.get(), noise, clamp, clamp, + width, height, width)); - for (int i = 0; i < image_size; ++i) { - EXPECT_EQ(static_cast(s[i]), static_cast(d[i])) << "i = " << i; + for (int i = 0; i < image_size; ++i) { + EXPECT_EQ(static_cast(s[i]), static_cast(d[i])) + << "width = " << width << ", idx = " << i; + } } - - vpx_free(d); - vpx_free(s); } using std::make_tuple; @@ -133,7 +138,7 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values(make_tuple(3.25, vpx_plane_add_noise_c), make_tuple(4.4, vpx_plane_add_noise_c))); -#if HAVE_SSE2 +#if HAVE_SSE2 && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P( SSE2, AddNoiseTest, ::testing::Values(make_tuple(3.25, vpx_plane_add_noise_sse2), diff --git a/libs/libvpx/test/alt_ref_aq_segment_test.cc b/libs/libvpx/test/alt_ref_aq_segment_test.cc index 00a00e27c5..ade82d7ed2 100644 --- a/libs/libvpx/test/alt_ref_aq_segment_test.cc +++ b/libs/libvpx/test/alt_ref_aq_segment_test.cc @@ -7,7 +7,7 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" @@ -20,9 +20,9 @@ class AltRefAqSegmentTest public ::libvpx_test::CodecTestWith2Params { protected: AltRefAqSegmentTest() : EncoderTest(GET_PARAM(0)) {} - virtual ~AltRefAqSegmentTest() {} + ~AltRefAqSegmentTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(GET_PARAM(1)); set_cpu_used_ = GET_PARAM(2); @@ -30,8 +30,8 @@ class AltRefAqSegmentTest alt_ref_aq_mode_ = 0; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_); encoder->Control(VP9E_SET_ALT_REF_AQ, alt_ref_aq_mode_); diff --git a/libs/libvpx/test/altref_test.cc b/libs/libvpx/test/altref_test.cc index 69bcef774e..e98edcba4a 100644 --- a/libs/libvpx/test/altref_test.cc +++ b/libs/libvpx/test/altref_test.cc @@ -7,11 +7,12 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" #include "test/util.h" +#include "vpx_config.h" namespace { #if CONFIG_VP8_ENCODER @@ -24,24 +25,24 @@ class AltRefTest : public ::libvpx_test::EncoderTest, public ::libvpx_test::CodecTestWithParam { protected: AltRefTest() : EncoderTest(GET_PARAM(0)), altref_count_(0) {} - virtual ~AltRefTest() {} + ~AltRefTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(libvpx_test::kTwoPassGood); } - virtual void BeginPassHook(unsigned int /*pass*/) { altref_count_ = 0; } + void BeginPassHook(unsigned int /*pass*/) override { altref_count_ = 0; } - virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, - libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(libvpx_test::VideoSource *video, + libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1); encoder->Control(VP8E_SET_CPUUSED, 3); } } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { if (pkt->data.frame.flags & VPX_FRAME_IS_INVISIBLE) ++altref_count_; } @@ -75,17 +76,17 @@ class AltRefForcedKeyTestLarge AltRefForcedKeyTestLarge() : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), cpu_used_(GET_PARAM(2)), forced_kf_frame_num_(1), frame_num_(0) {} - virtual ~AltRefForcedKeyTestLarge() {} + ~AltRefForcedKeyTestLarge() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(encoding_mode_); cfg_.rc_end_usage = VPX_VBR; cfg_.g_threads = 0; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, cpu_used_); encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1); @@ -100,7 +101,7 @@ class AltRefForcedKeyTestLarge (video->frame() == forced_kf_frame_num_) ? VPX_EFLAG_FORCE_KF : 0; } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { if (frame_num_ == forced_kf_frame_num_) { ASSERT_TRUE(!!(pkt->data.frame.flags & VPX_FRAME_IS_KEY)) << "Frame #" << frame_num_ << " isn't a keyframe!"; diff --git a/libs/libvpx/test/android/Android.mk b/libs/libvpx/test/android/Android.mk index 87155fcb58..4114b642bd 100644 --- a/libs/libvpx/test/android/Android.mk +++ b/libs/libvpx/test/android/Android.mk @@ -10,6 +10,9 @@ # The test app itself runs on the command line through adb shell # The paths are really messed up as the libvpx make file # expects to be made from a parent directory. + +# Ignore this file during non-NDK builds. +ifdef NDK_ROOT CUR_WD := $(call my-dir) BINDINGS_DIR := $(CUR_WD)/../../.. LOCAL_PATH := $(CUR_WD)/../../.. @@ -28,6 +31,7 @@ LOCAL_PATH := $(CUR_WD)/../.. #libgtest include $(CLEAR_VARS) LOCAL_ARM_MODE := arm +LOCAL_CPPFLAGS := -std=c++17 LOCAL_CPP_EXTENSION := .cc LOCAL_MODULE := gtest LOCAL_C_INCLUDES := $(LOCAL_PATH)/third_party/googletest/src/ @@ -42,6 +46,7 @@ include $(BUILD_STATIC_LIBRARY) #libvpx_test include $(CLEAR_VARS) LOCAL_ARM_MODE := arm +LOCAL_CPPFLAGS := -std=c++17 LOCAL_MODULE := libvpx_test LOCAL_STATIC_LIBRARIES := gtest libwebm @@ -61,3 +66,4 @@ LOCAL_SRC_FILES := $(addprefix ./test/, $(FILTERED_SRC)) # some test files depend on *_rtcd.h, ensure they're generated first. $(eval $(call rtcd_dep_template)) include $(BUILD_EXECUTABLE) +endif # NDK_ROOT diff --git a/libs/libvpx/test/android/get_files.py b/libs/libvpx/test/android/get_files.py index 1c69740d2b..98ce7b1947 100644 --- a/libs/libvpx/test/android/get_files.py +++ b/libs/libvpx/test/android/get_files.py @@ -38,7 +38,7 @@ def get_file_sha(filename): buf = file.read(HASH_CHUNK) return sha_hash.hexdigest() except IOError: - print "Error reading " + filename + print("Error reading " + filename) # Downloads a file from a url, and then checks the sha against the passed # in sha @@ -67,7 +67,7 @@ try: getopt.getopt(sys.argv[1:], \ "u:i:o:", ["url=", "input_csv=", "output_dir="]) except: - print 'get_files.py -u -i -o ' + print('get_files.py -u -i -o ') sys.exit(2) for opt, arg in opts: @@ -79,7 +79,7 @@ for opt, arg in opts: local_resource_path = os.path.join(arg) if len(sys.argv) != 7: - print "Expects two paths and a url!" + print("Expects two paths and a url!") exit(1) if not os.path.isdir(local_resource_path): @@ -89,7 +89,7 @@ file_list_csv = open(file_list_path, "rb") # Our 'csv' file uses multiple spaces as a delimiter, python's # csv class only uses single character delimiters, so we convert them below -file_list_reader = csv.reader((re.sub(' +', ' ', line) \ +file_list_reader = csv.reader((re.sub(' +', ' ', line.decode('utf-8')) \ for line in file_list_csv), delimiter = ' ') file_shas = [] @@ -104,15 +104,16 @@ for row in file_list_reader: file_list_csv.close() # Download files, only if they don't already exist and have correct shas -for filename, sha in itertools.izip(file_names, file_shas): +for filename, sha in zip(file_names, file_shas): + filename = filename.lstrip('*') path = os.path.join(local_resource_path, filename) if os.path.isfile(path) \ and get_file_sha(path) == sha: - print path + ' exists, skipping' + print(path + ' exists, skipping') continue for retry in range(0, ftp_retries): - print "Downloading " + path + print("Downloading " + path) if not download_and_check_sha(url, filename, sha): - print "Sha does not match, retrying..." + print("Sha does not match, retrying...") else: break diff --git a/libs/libvpx/test/aq_segment_test.cc b/libs/libvpx/test/aq_segment_test.cc index 2cbc991d0c..f7e9a118fc 100644 --- a/libs/libvpx/test/aq_segment_test.cc +++ b/libs/libvpx/test/aq_segment_test.cc @@ -7,7 +7,7 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" @@ -20,17 +20,17 @@ class AqSegmentTest public ::libvpx_test::CodecTestWith2Params { protected: AqSegmentTest() : EncoderTest(GET_PARAM(0)) {} - virtual ~AqSegmentTest() {} + ~AqSegmentTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(GET_PARAM(1)); set_cpu_used_ = GET_PARAM(2); aq_mode_ = 0; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_); encoder->Control(VP9E_SET_AQ_MODE, aq_mode_); diff --git a/libs/libvpx/test/avg_test.cc b/libs/libvpx/test/avg_test.cc index 196522ce58..bbc8ba0a03 100644 --- a/libs/libvpx/test/avg_test.cc +++ b/libs/libvpx/test/avg_test.cc @@ -13,7 +13,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp9_rtcd.h" #include "./vpx_config.h" @@ -38,7 +38,7 @@ class AverageTestBase : public ::testing::Test { : width_(width), height_(height), source_data_(nullptr), source_stride_(0), bit_depth_(8) {} - virtual void TearDown() { + void TearDown() override { vpx_free(source_data_); source_data_ = nullptr; libvpx_test::ClearSystemState(); @@ -49,7 +49,7 @@ class AverageTestBase : public ::testing::Test { static const int kDataAlignment = 16; static const int kDataBlockSize = 64 * 128; - virtual void SetUp() { + void SetUp() override { source_data_ = reinterpret_cast( vpx_memalign(kDataAlignment, kDataBlockSize * sizeof(source_data_[0]))); ASSERT_NE(source_data_, nullptr); @@ -94,9 +94,9 @@ class AverageTestBase : public ::testing::Test { ACMRandom rnd_; }; -typedef unsigned int (*AverageFunction)(const uint8_t *s, int pitch); +using AverageFunction = unsigned int (*)(const uint8_t *s, int pitch); -typedef std::tuple AvgFunc; +using AvgFunc = std::tuple; class AverageTest : public AverageTestBase, public ::testing::WithParamInterface { @@ -153,10 +153,10 @@ class AverageTestHBD : public AverageTestBase, #endif // CONFIG_VP9_HIGHBITDEPTH #if HAVE_NEON || HAVE_SSE2 || HAVE_MSA -typedef void (*IntProRowFunc)(int16_t hbuf[16], uint8_t const *ref, - const int ref_stride, const int height); +using IntProRowFunc = void (*)(int16_t hbuf[16], uint8_t const *ref, + const int ref_stride, const int height); -typedef std::tuple IntProRowParam; +using IntProRowParam = std::tuple; class IntProRowTest : public AverageTestBase, public ::testing::WithParamInterface { @@ -169,7 +169,7 @@ class IntProRowTest : public AverageTestBase, } protected: - virtual void SetUp() { + void SetUp() override { source_data_ = reinterpret_cast( vpx_memalign(kDataAlignment, kDataBlockSize * sizeof(source_data_[0]))); ASSERT_NE(source_data_, nullptr); @@ -180,7 +180,7 @@ class IntProRowTest : public AverageTestBase, vpx_memalign(kDataAlignment, sizeof(*hbuf_c_) * 16)); } - virtual void TearDown() { + void TearDown() override { vpx_free(source_data_); source_data_ = nullptr; vpx_free(hbuf_c_); @@ -190,8 +190,9 @@ class IntProRowTest : public AverageTestBase, } void RunComparison() { - ASM_REGISTER_STATE_CHECK(c_func_(hbuf_c_, source_data_, 0, height_)); - ASM_REGISTER_STATE_CHECK(asm_func_(hbuf_asm_, source_data_, 0, height_)); + ASM_REGISTER_STATE_CHECK(c_func_(hbuf_c_, source_data_, width_, height_)); + ASM_REGISTER_STATE_CHECK( + asm_func_(hbuf_asm_, source_data_, width_, height_)); EXPECT_EQ(0, memcmp(hbuf_c_, hbuf_asm_, sizeof(*hbuf_c_) * 16)) << "Output mismatch"; } @@ -204,9 +205,9 @@ class IntProRowTest : public AverageTestBase, }; GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(IntProRowTest); -typedef int16_t (*IntProColFunc)(uint8_t const *ref, const int width); +using IntProColFunc = int16_t (*)(uint8_t const *ref, const int width); -typedef std::tuple IntProColParam; +using IntProColParam = std::tuple; class IntProColTest : public AverageTestBase, public ::testing::WithParamInterface { @@ -232,13 +233,13 @@ class IntProColTest : public AverageTestBase, GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(IntProColTest); #endif // HAVE_NEON || HAVE_SSE2 || HAVE_MSA -typedef int (*SatdFunc)(const tran_low_t *coeffs, int length); -typedef std::tuple SatdTestParam; +using SatdFunc = int (*)(const tran_low_t *coeffs, int length); +using SatdTestParam = std::tuple; class SatdTest : public ::testing::Test, public ::testing::WithParamInterface { protected: - virtual void SetUp() { + void SetUp() override { satd_size_ = GET_PARAM(0); satd_func_ = GET_PARAM(1); rnd_.Reset(ACMRandom::DeterministicSeed()); @@ -247,7 +248,7 @@ class SatdTest : public ::testing::Test, ASSERT_NE(src_, nullptr); } - virtual void TearDown() { + void TearDown() override { libvpx_test::ClearSystemState(); vpx_free(src_); } @@ -276,7 +277,7 @@ class SatdTest : public ::testing::Test, class SatdLowbdTest : public SatdTest { protected: - virtual void FillRandom() { + void FillRandom() override { for (int i = 0; i < satd_size_; ++i) { const int16_t tmp = rnd_.Rand16Signed(); src_[i] = (tran_low_t)tmp; @@ -284,15 +285,15 @@ class SatdLowbdTest : public SatdTest { } }; -typedef int64_t (*BlockErrorFunc)(const tran_low_t *coeff, - const tran_low_t *dqcoeff, int block_size); -typedef std::tuple BlockErrorTestFPParam; +using BlockErrorFunc = int64_t (*)(const tran_low_t *coeff, + const tran_low_t *dqcoeff, int block_size); +using BlockErrorTestFPParam = std::tuple; class BlockErrorTestFP : public ::testing::Test, public ::testing::WithParamInterface { protected: - virtual void SetUp() { + void SetUp() override { txfm_size_ = GET_PARAM(0); block_error_func_ = GET_PARAM(1); rnd_.Reset(ACMRandom::DeterministicSeed()); @@ -304,7 +305,7 @@ class BlockErrorTestFP ASSERT_NE(dqcoeff_, nullptr); } - virtual void TearDown() { + void TearDown() override { libvpx_test::ClearSystemState(); vpx_free(coeff_); vpx_free(dqcoeff_); @@ -463,7 +464,7 @@ TEST_P(SatdLowbdTest, DISABLED_Speed) { #if CONFIG_VP9_HIGHBITDEPTH class SatdHighbdTest : public SatdTest { protected: - virtual void FillRandom() { + void FillRandom() override { for (int i = 0; i < satd_size_; ++i) { src_[i] = rnd_.Rand20Signed(); } @@ -582,6 +583,13 @@ INSTANTIATE_TEST_SUITE_P( make_tuple(16, 16, 1, 4, &vpx_highbd_avg_4x4_sse2))); #endif // HAVE_SSE2 +#if HAVE_NEON +INSTANTIATE_TEST_SUITE_P( + NEON, AverageTestHBD, + ::testing::Values(make_tuple(16, 16, 1, 8, &vpx_highbd_avg_8x8_neon), + make_tuple(16, 16, 1, 4, &vpx_highbd_avg_4x4_neon))); +#endif // HAVE_NEON + INSTANTIATE_TEST_SUITE_P(C, SatdHighbdTest, ::testing::Values(make_tuple(16, &vpx_satd_c), make_tuple(64, &vpx_satd_c), @@ -632,12 +640,14 @@ INSTANTIATE_TEST_SUITE_P(SSE2, SatdLowbdTest, make_tuple(256, &vpx_satd_sse2), make_tuple(1024, &vpx_satd_sse2))); +#if HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P( SSE2, BlockErrorTestFP, ::testing::Values(make_tuple(16, &vp9_block_error_fp_sse2), make_tuple(64, &vp9_block_error_fp_sse2), make_tuple(256, &vp9_block_error_fp_sse2), make_tuple(1024, &vp9_block_error_fp_sse2))); +#endif // HAVE_X86_ASM #endif // HAVE_SSE2 #if HAVE_AVX2 @@ -694,18 +704,32 @@ INSTANTIATE_TEST_SUITE_P(NEON, SatdLowbdTest, make_tuple(256, &vpx_satd_neon), make_tuple(1024, &vpx_satd_neon))); -// TODO(jianj): Remove the highbitdepth flag once the SIMD functions are -// in place. -#if !CONFIG_VP9_HIGHBITDEPTH +#if CONFIG_VP9_HIGHBITDEPTH +INSTANTIATE_TEST_SUITE_P( + NEON, SatdHighbdTest, + ::testing::Values(make_tuple(16, &vpx_highbd_satd_neon), + make_tuple(64, &vpx_highbd_satd_neon), + make_tuple(256, &vpx_highbd_satd_neon), + make_tuple(1024, &vpx_highbd_satd_neon))); +#endif // CONFIG_VP9_HIGHBITDEPTH + INSTANTIATE_TEST_SUITE_P( NEON, BlockErrorTestFP, ::testing::Values(make_tuple(16, &vp9_block_error_fp_neon), make_tuple(64, &vp9_block_error_fp_neon), make_tuple(256, &vp9_block_error_fp_neon), make_tuple(1024, &vp9_block_error_fp_neon))); -#endif // !CONFIG_VP9_HIGHBITDEPTH #endif // HAVE_NEON +#if HAVE_SVE +INSTANTIATE_TEST_SUITE_P( + SVE, BlockErrorTestFP, + ::testing::Values(make_tuple(16, &vp9_block_error_fp_sve), + make_tuple(64, &vp9_block_error_fp_sve), + make_tuple(256, &vp9_block_error_fp_sve), + make_tuple(1024, &vp9_block_error_fp_sve))); +#endif // HAVE_SVE + #if HAVE_MSA INSTANTIATE_TEST_SUITE_P( MSA, AverageTest, diff --git a/libs/libvpx/test/bench.cc b/libs/libvpx/test/bench.cc index 4b883d8250..0783f2a734 100644 --- a/libs/libvpx/test/bench.cc +++ b/libs/libvpx/test/bench.cc @@ -10,6 +10,7 @@ #include #include +#include #include "test/bench.h" #include "vpx_ports/vpx_timer.h" diff --git a/libs/libvpx/test/bench.h b/libs/libvpx/test/bench.h index 57ca9118ba..203e4d247e 100644 --- a/libs/libvpx/test/bench.h +++ b/libs/libvpx/test/bench.h @@ -16,6 +16,8 @@ class AbstractBench { public: + virtual ~AbstractBench() = default; + void RunNTimes(int n); void PrintMedian(const char *title); diff --git a/libs/libvpx/test/blockiness_test.cc b/libs/libvpx/test/blockiness_test.cc index 11b2a3f61f..6e8301bb52 100644 --- a/libs/libvpx/test/blockiness_test.cc +++ b/libs/libvpx/test/blockiness_test.cc @@ -13,7 +13,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #if CONFIG_VP9_ENCODER @@ -49,14 +49,14 @@ class BlockinessTestBase : public ::testing::Test { reference_data_ = nullptr; } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: // Handle frames up to 640x480 static const int kDataAlignment = 16; static const int kDataBufferSize = 640 * 480; - virtual void SetUp() { + void SetUp() override { source_stride_ = (width_ + 31) & ~31; reference_stride_ = width_ * 2; rnd_.Reset(ACMRandom::DeterministicSeed()); @@ -139,7 +139,7 @@ class BlockinessTestBase : public ::testing::Test { }; #if CONFIG_VP9_ENCODER -typedef std::tuple BlockinessParam; +using BlockinessParam = std::tuple; class BlockinessVP9Test : public BlockinessTestBase, public ::testing::WithParamInterface { diff --git a/libs/libvpx/test/borders_test.cc b/libs/libvpx/test/borders_test.cc index 3c1f69a923..57ee179aaf 100644 --- a/libs/libvpx/test/borders_test.cc +++ b/libs/libvpx/test/borders_test.cc @@ -9,11 +9,12 @@ */ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" #include "test/util.h" +#include "vpx_config.h" namespace { @@ -22,15 +23,15 @@ class BordersTest public ::libvpx_test::CodecTestWithParam { protected: BordersTest() : EncoderTest(GET_PARAM(0)) {} - virtual ~BordersTest() {} + ~BordersTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(GET_PARAM(1)); } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, 1); encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1); @@ -40,7 +41,7 @@ class BordersTest } } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) { } } @@ -79,6 +80,11 @@ TEST_P(BordersTest, TestLowBitrate) { ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); } +#if CONFIG_REALTIME_ONLY +VP9_INSTANTIATE_TEST_SUITE(BordersTest, + ::testing::Values(::libvpx_test::kRealTime)); +#else VP9_INSTANTIATE_TEST_SUITE(BordersTest, ::testing::Values(::libvpx_test::kTwoPassGood)); +#endif } // namespace diff --git a/libs/libvpx/test/buffer.h b/libs/libvpx/test/buffer.h index 023939cedf..f2846323b3 100644 --- a/libs/libvpx/test/buffer.h +++ b/libs/libvpx/test/buffer.h @@ -15,7 +15,7 @@ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/acm_random.h" #include "vpx/vpx_integer.h" diff --git a/libs/libvpx/test/byte_alignment_test.cc b/libs/libvpx/test/byte_alignment_test.cc index 1e0ffceb8d..ba6fffc524 100644 --- a/libs/libvpx/test/byte_alignment_test.cc +++ b/libs/libvpx/test/byte_alignment_test.cc @@ -58,7 +58,7 @@ class ByteAlignmentTest ByteAlignmentTest() : video_(nullptr), decoder_(nullptr), md5_file_(nullptr) {} - virtual void SetUp() { + void SetUp() override { video_ = new libvpx_test::WebMVideoSource(kVP9TestFile); ASSERT_NE(video_, nullptr); video_->Init(); @@ -71,7 +71,7 @@ class ByteAlignmentTest OpenMd5File(kVP9Md5File); } - virtual void TearDown() { + void TearDown() override { if (md5_file_ != nullptr) fclose(md5_file_); delete decoder_; diff --git a/libs/libvpx/test/codec_factory.h b/libs/libvpx/test/codec_factory.h index 96092610c6..179ccdf011 100644 --- a/libs/libvpx/test/codec_factory.h +++ b/libs/libvpx/test/codec_factory.h @@ -40,7 +40,7 @@ class CodecFactory { const vpx_codec_flags_t flags) const = 0; virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, - unsigned long deadline, + vpx_enc_deadline_t deadline, const unsigned long init_flags, TwopassStatsStore *stats) const = 0; @@ -84,7 +84,7 @@ class VP8Decoder : public Decoder { : Decoder(cfg, flag) {} protected: - virtual vpx_codec_iface_t *CodecInterface() const { + vpx_codec_iface_t *CodecInterface() const override { #if CONFIG_VP8_DECODER return &vpx_codec_vp8_dx_algo; #else @@ -95,12 +95,12 @@ class VP8Decoder : public Decoder { class VP8Encoder : public Encoder { public: - VP8Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline, + VP8Encoder(vpx_codec_enc_cfg_t cfg, vpx_enc_deadline_t deadline, const unsigned long init_flags, TwopassStatsStore *stats) : Encoder(cfg, deadline, init_flags, stats) {} protected: - virtual vpx_codec_iface_t *CodecInterface() const { + vpx_codec_iface_t *CodecInterface() const override { #if CONFIG_VP8_ENCODER return &vpx_codec_vp8_cx_algo; #else @@ -113,12 +113,12 @@ class VP8CodecFactory : public CodecFactory { public: VP8CodecFactory() : CodecFactory() {} - virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const { + Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const override { return CreateDecoder(cfg, 0); } - virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg, - const vpx_codec_flags_t flags) const { + Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg, + const vpx_codec_flags_t flags) const override { #if CONFIG_VP8_DECODER return new VP8Decoder(cfg, flags); #else @@ -128,10 +128,9 @@ class VP8CodecFactory : public CodecFactory { #endif } - virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, - unsigned long deadline, - const unsigned long init_flags, - TwopassStatsStore *stats) const { + Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, vpx_enc_deadline_t deadline, + const unsigned long init_flags, + TwopassStatsStore *stats) const override { #if CONFIG_VP8_ENCODER return new VP8Encoder(cfg, deadline, init_flags, stats); #else @@ -143,8 +142,8 @@ class VP8CodecFactory : public CodecFactory { #endif } - virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg, - int usage) const { + vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg, + int usage) const override { #if CONFIG_VP8_ENCODER return vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, cfg, usage); #else @@ -165,7 +164,9 @@ const libvpx_test::VP8CodecFactory kVP8; &libvpx_test::kVP8)), \ __VA_ARGS__)) #else -#define VP8_INSTANTIATE_TEST_SUITE(test, ...) +// static_assert() is used to avoid warnings about an extra ';' outside of a +// function. +#define VP8_INSTANTIATE_TEST_SUITE(test, ...) static_assert(CONFIG_VP8 == 0, "") #endif // CONFIG_VP8 /* @@ -180,7 +181,7 @@ class VP9Decoder : public Decoder { : Decoder(cfg, flag) {} protected: - virtual vpx_codec_iface_t *CodecInterface() const { + vpx_codec_iface_t *CodecInterface() const override { #if CONFIG_VP9_DECODER return &vpx_codec_vp9_dx_algo; #else @@ -191,12 +192,12 @@ class VP9Decoder : public Decoder { class VP9Encoder : public Encoder { public: - VP9Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline, + VP9Encoder(vpx_codec_enc_cfg_t cfg, vpx_enc_deadline_t deadline, const unsigned long init_flags, TwopassStatsStore *stats) : Encoder(cfg, deadline, init_flags, stats) {} protected: - virtual vpx_codec_iface_t *CodecInterface() const { + vpx_codec_iface_t *CodecInterface() const override { #if CONFIG_VP9_ENCODER return &vpx_codec_vp9_cx_algo; #else @@ -209,12 +210,12 @@ class VP9CodecFactory : public CodecFactory { public: VP9CodecFactory() : CodecFactory() {} - virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const { + Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg) const override { return CreateDecoder(cfg, 0); } - virtual Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg, - const vpx_codec_flags_t flags) const { + Decoder *CreateDecoder(vpx_codec_dec_cfg_t cfg, + const vpx_codec_flags_t flags) const override { #if CONFIG_VP9_DECODER return new VP9Decoder(cfg, flags); #else @@ -224,10 +225,9 @@ class VP9CodecFactory : public CodecFactory { #endif } - virtual Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, - unsigned long deadline, - const unsigned long init_flags, - TwopassStatsStore *stats) const { + Encoder *CreateEncoder(vpx_codec_enc_cfg_t cfg, vpx_enc_deadline_t deadline, + const unsigned long init_flags, + TwopassStatsStore *stats) const override { #if CONFIG_VP9_ENCODER return new VP9Encoder(cfg, deadline, init_flags, stats); #else @@ -239,8 +239,8 @@ class VP9CodecFactory : public CodecFactory { #endif } - virtual vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg, - int usage) const { + vpx_codec_err_t DefaultEncoderConfig(vpx_codec_enc_cfg_t *cfg, + int usage) const override { #if CONFIG_VP9_ENCODER return vpx_codec_enc_config_default(&vpx_codec_vp9_cx_algo, cfg, usage); #else @@ -261,7 +261,9 @@ const libvpx_test::VP9CodecFactory kVP9; &libvpx_test::kVP9)), \ __VA_ARGS__)) #else -#define VP9_INSTANTIATE_TEST_SUITE(test, ...) +// static_assert() is used to avoid warnings about an extra ';' outside of a +// function. +#define VP9_INSTANTIATE_TEST_SUITE(test, ...) static_assert(CONFIG_VP9 == 0, "") #endif // CONFIG_VP9 } // namespace libvpx_test diff --git a/libs/libvpx/test/comp_avg_pred_test.cc b/libs/libvpx/test/comp_avg_pred_test.cc index 3977a2d0b5..de9842a88f 100644 --- a/libs/libvpx/test/comp_avg_pred_test.cc +++ b/libs/libvpx/test/comp_avg_pred_test.cc @@ -8,13 +8,14 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_dsp_rtcd.h" #include "test/acm_random.h" #include "test/buffer.h" #include "test/register_state_check.h" +#include "vpx_config.h" #include "vpx_ports/vpx_timer.h" namespace { @@ -22,13 +23,14 @@ namespace { using ::libvpx_test::ACMRandom; using ::libvpx_test::Buffer; -typedef void (*AvgPredFunc)(uint8_t *a, const uint8_t *b, int w, int h, - const uint8_t *c, int c_stride); +template +Pixel avg_with_rounding(Pixel a, Pixel b) { + return (a + b + 1) >> 1; +} -uint8_t avg_with_rounding(uint8_t a, uint8_t b) { return (a + b + 1) >> 1; } - -void reference_pred(const Buffer &pred, const Buffer &ref, - int width, int height, Buffer *avg) { +template +void reference_pred(const Buffer &pred, const Buffer &ref, + int width, int height, Buffer *avg) { ASSERT_NE(avg->TopLeftPixel(), nullptr); ASSERT_NE(pred.TopLeftPixel(), nullptr); ASSERT_NE(ref.TopLeftPixel(), nullptr); @@ -36,28 +38,36 @@ void reference_pred(const Buffer &pred, const Buffer &ref, for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { avg->TopLeftPixel()[y * avg->stride() + x] = - avg_with_rounding(pred.TopLeftPixel()[y * pred.stride() + x], - ref.TopLeftPixel()[y * ref.stride() + x]); + avg_with_rounding(pred.TopLeftPixel()[y * pred.stride() + x], + ref.TopLeftPixel()[y * ref.stride() + x]); } } } +using AvgPredFunc = void (*)(uint8_t *a, const uint8_t *b, int w, int h, + const uint8_t *c, int c_stride); + +template class AvgPredTest : public ::testing::TestWithParam { public: - virtual void SetUp() { + void SetUp() override { avg_pred_func_ = GetParam(); rnd_.Reset(ACMRandom::DeterministicSeed()); } + void TestSizeCombinations(); + void TestCompareReferenceRandom(); + void TestSpeed(); + protected: AvgPredFunc avg_pred_func_; ACMRandom rnd_; }; -TEST_P(AvgPredTest, SizeCombinations) { +template +void AvgPredTest::TestSizeCombinations() { // This is called as part of the sub pixel variance. As such it must be one of // the variance block sizes. - for (int width_pow = 2; width_pow <= 6; ++width_pow) { for (int height_pow = width_pow - 1; height_pow <= width_pow + 1; ++height_pow) { @@ -70,23 +80,30 @@ TEST_P(AvgPredTest, SizeCombinations) { const int width = 1 << width_pow; const int height = 1 << height_pow; // Only the reference buffer may have a stride not equal to width. - Buffer ref = - Buffer(width, height, ref_padding ? 8 : 0); + Buffer ref = Buffer(width, height, ref_padding ? 8 : 0); ASSERT_TRUE(ref.Init()); - Buffer pred = Buffer(width, height, 0, 16); + Buffer pred = Buffer(width, height, 0, 32); ASSERT_TRUE(pred.Init()); - Buffer avg_ref = Buffer(width, height, 0, 16); + Buffer avg_ref = Buffer(width, height, 0, 32); ASSERT_TRUE(avg_ref.Init()); - Buffer avg_chk = Buffer(width, height, 0, 16); + Buffer avg_chk = Buffer(width, height, 0, 32); ASSERT_TRUE(avg_chk.Init()); + const int bitdepth_mask = (1 << bitdepth) - 1; + for (int h = 0; h < height; ++h) { + for (int w = 0; w < width; ++w) { + ref.TopLeftPixel()[w + h * width] = rnd_.Rand16() & bitdepth_mask; + } + } + for (int h = 0; h < height; ++h) { + for (int w = 0; w < width; ++w) { + pred.TopLeftPixel()[w + h * width] = rnd_.Rand16() & bitdepth_mask; + } + } - ref.Set(&rnd_, &ACMRandom::Rand8); - pred.Set(&rnd_, &ACMRandom::Rand8); - - reference_pred(pred, ref, width, height, &avg_ref); - ASM_REGISTER_STATE_CHECK( - avg_pred_func_(avg_chk.TopLeftPixel(), pred.TopLeftPixel(), width, - height, ref.TopLeftPixel(), ref.stride())); + reference_pred(pred, ref, width, height, &avg_ref); + ASM_REGISTER_STATE_CHECK(avg_pred_func_( + (uint8_t *)avg_chk.TopLeftPixel(), (uint8_t *)pred.TopLeftPixel(), + width, height, (uint8_t *)ref.TopLeftPixel(), ref.stride())); EXPECT_TRUE(avg_chk.CheckValues(avg_ref)); if (HasFailure()) { @@ -99,26 +116,36 @@ TEST_P(AvgPredTest, SizeCombinations) { } } -TEST_P(AvgPredTest, CompareReferenceRandom) { +template +void AvgPredTest::TestCompareReferenceRandom() { const int width = 64; const int height = 32; - Buffer ref = Buffer(width, height, 8); + Buffer ref = Buffer(width, height, 8); ASSERT_TRUE(ref.Init()); - Buffer pred = Buffer(width, height, 0, 16); + Buffer pred = Buffer(width, height, 0, 32); ASSERT_TRUE(pred.Init()); - Buffer avg_ref = Buffer(width, height, 0, 16); + Buffer avg_ref = Buffer(width, height, 0, 32); ASSERT_TRUE(avg_ref.Init()); - Buffer avg_chk = Buffer(width, height, 0, 16); + Buffer avg_chk = Buffer(width, height, 0, 32); ASSERT_TRUE(avg_chk.Init()); for (int i = 0; i < 500; ++i) { - ref.Set(&rnd_, &ACMRandom::Rand8); - pred.Set(&rnd_, &ACMRandom::Rand8); + const int bitdepth_mask = (1 << bitdepth) - 1; + for (int h = 0; h < height; ++h) { + for (int w = 0; w < width; ++w) { + ref.TopLeftPixel()[w + h * width] = rnd_.Rand16() & bitdepth_mask; + } + } + for (int h = 0; h < height; ++h) { + for (int w = 0; w < width; ++w) { + pred.TopLeftPixel()[w + h * width] = rnd_.Rand16() & bitdepth_mask; + } + } - reference_pred(pred, ref, width, height, &avg_ref); - ASM_REGISTER_STATE_CHECK(avg_pred_func_(avg_chk.TopLeftPixel(), - pred.TopLeftPixel(), width, height, - ref.TopLeftPixel(), ref.stride())); + reference_pred(pred, ref, width, height, &avg_ref); + ASM_REGISTER_STATE_CHECK(avg_pred_func_( + (uint8_t *)avg_chk.TopLeftPixel(), (uint8_t *)pred.TopLeftPixel(), + width, height, (uint8_t *)ref.TopLeftPixel(), ref.stride())); EXPECT_TRUE(avg_chk.CheckValues(avg_ref)); if (HasFailure()) { printf("Width: %d Height: %d\n", width, height); @@ -128,7 +155,8 @@ TEST_P(AvgPredTest, CompareReferenceRandom) { } } -TEST_P(AvgPredTest, DISABLED_Speed) { +template +void AvgPredTest::TestSpeed() { for (int width_pow = 2; width_pow <= 6; ++width_pow) { for (int height_pow = width_pow - 1; height_pow <= width_pow + 1; ++height_pow) { @@ -138,22 +166,30 @@ TEST_P(AvgPredTest, DISABLED_Speed) { for (int ref_padding = 0; ref_padding < 2; ref_padding++) { const int width = 1 << width_pow; const int height = 1 << height_pow; - Buffer ref = - Buffer(width, height, ref_padding ? 8 : 0); + Buffer ref = Buffer(width, height, ref_padding ? 8 : 0); ASSERT_TRUE(ref.Init()); - Buffer pred = Buffer(width, height, 0, 16); + Buffer pred = Buffer(width, height, 0, 32); ASSERT_TRUE(pred.Init()); - Buffer avg = Buffer(width, height, 0, 16); + Buffer avg = Buffer(width, height, 0, 32); ASSERT_TRUE(avg.Init()); - - ref.Set(&rnd_, &ACMRandom::Rand8); - pred.Set(&rnd_, &ACMRandom::Rand8); + const int bitdepth_mask = (1 << bitdepth) - 1; + for (int h = 0; h < height; ++h) { + for (int w = 0; w < width; ++w) { + ref.TopLeftPixel()[w + h * width] = rnd_.Rand16() & bitdepth_mask; + } + } + for (int h = 0; h < height; ++h) { + for (int w = 0; w < width; ++w) { + pred.TopLeftPixel()[w + h * width] = rnd_.Rand16() & bitdepth_mask; + } + } vpx_usec_timer timer; vpx_usec_timer_start(&timer); - for (int i = 0; i < 10000000 / (width * height); ++i) { - avg_pred_func_(avg.TopLeftPixel(), pred.TopLeftPixel(), width, height, - ref.TopLeftPixel(), ref.stride()); + for (int i = 0; i < 100000000 / (width * height); ++i) { + avg_pred_func_((uint8_t *)avg.TopLeftPixel(), + (uint8_t *)pred.TopLeftPixel(), width, height, + (uint8_t *)ref.TopLeftPixel(), ref.stride()); } vpx_usec_timer_mark(&timer); @@ -166,26 +202,75 @@ TEST_P(AvgPredTest, DISABLED_Speed) { } } -INSTANTIATE_TEST_SUITE_P(C, AvgPredTest, +using AvgPredTestLBD = AvgPredTest<8, uint8_t>; + +TEST_P(AvgPredTestLBD, SizeCombinations) { TestSizeCombinations(); } + +TEST_P(AvgPredTestLBD, CompareReferenceRandom) { TestCompareReferenceRandom(); } + +TEST_P(AvgPredTestLBD, DISABLED_Speed) { TestSpeed(); } + +INSTANTIATE_TEST_SUITE_P(C, AvgPredTestLBD, ::testing::Values(&vpx_comp_avg_pred_c)); #if HAVE_SSE2 -INSTANTIATE_TEST_SUITE_P(SSE2, AvgPredTest, +INSTANTIATE_TEST_SUITE_P(SSE2, AvgPredTestLBD, ::testing::Values(&vpx_comp_avg_pred_sse2)); #endif // HAVE_SSE2 +#if HAVE_AVX2 +INSTANTIATE_TEST_SUITE_P(AVX2, AvgPredTestLBD, + ::testing::Values(&vpx_comp_avg_pred_avx2)); +#endif // HAVE_AVX2 + #if HAVE_NEON -INSTANTIATE_TEST_SUITE_P(NEON, AvgPredTest, +INSTANTIATE_TEST_SUITE_P(NEON, AvgPredTestLBD, ::testing::Values(&vpx_comp_avg_pred_neon)); #endif // HAVE_NEON #if HAVE_VSX -INSTANTIATE_TEST_SUITE_P(VSX, AvgPredTest, +INSTANTIATE_TEST_SUITE_P(VSX, AvgPredTestLBD, ::testing::Values(&vpx_comp_avg_pred_vsx)); #endif // HAVE_VSX #if HAVE_LSX -INSTANTIATE_TEST_SUITE_P(LSX, AvgPredTest, +INSTANTIATE_TEST_SUITE_P(LSX, AvgPredTestLBD, ::testing::Values(&vpx_comp_avg_pred_lsx)); #endif // HAVE_LSX + +#if CONFIG_VP9_HIGHBITDEPTH +using HighbdAvgPredFunc = void (*)(uint16_t *a, const uint16_t *b, int w, int h, + const uint16_t *c, int c_stride); + +template +void highbd_wrapper(uint8_t *a, const uint8_t *b, int w, int h, + const uint8_t *c, int c_stride) { + fn((uint16_t *)a, (const uint16_t *)b, w, h, (const uint16_t *)c, c_stride); +} + +using AvgPredTestHBD = AvgPredTest<12, uint16_t>; + +TEST_P(AvgPredTestHBD, SizeCombinations) { TestSizeCombinations(); } + +TEST_P(AvgPredTestHBD, CompareReferenceRandom) { TestCompareReferenceRandom(); } + +TEST_P(AvgPredTestHBD, DISABLED_Speed) { TestSpeed(); } + +INSTANTIATE_TEST_SUITE_P( + C, AvgPredTestHBD, + ::testing::Values(&highbd_wrapper)); + +#if HAVE_SSE2 +INSTANTIATE_TEST_SUITE_P( + SSE2, AvgPredTestHBD, + ::testing::Values(&highbd_wrapper)); +#endif // HAVE_SSE2 + +#if HAVE_NEON +INSTANTIATE_TEST_SUITE_P( + NEON, AvgPredTestHBD, + ::testing::Values(&highbd_wrapper)); +#endif // HAVE_NEON + +#endif // CONFIG_VP9_HIGHBITDEPTH } // namespace diff --git a/libs/libvpx/test/config_test.cc b/libs/libvpx/test/config_test.cc index 8f4c60e113..d3aca4cfb5 100644 --- a/libs/libvpx/test/config_test.cc +++ b/libs/libvpx/test/config_test.cc @@ -7,7 +7,7 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/util.h" @@ -22,24 +22,24 @@ class ConfigTest ConfigTest() : EncoderTest(GET_PARAM(0)), frame_count_in_(0), frame_count_out_(0), frame_count_max_(0) {} - virtual ~ConfigTest() {} + ~ConfigTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(GET_PARAM(1)); } - virtual void BeginPassHook(unsigned int /*pass*/) { + void BeginPassHook(unsigned int /*pass*/) override { frame_count_in_ = 0; frame_count_out_ = 0; } - virtual void PreEncodeFrameHook(libvpx_test::VideoSource * /*video*/) { + void PreEncodeFrameHook(libvpx_test::VideoSource * /*video*/) override { ++frame_count_in_; abort_ |= (frame_count_in_ >= frame_count_max_); } - virtual void FramePktHook(const vpx_codec_cx_pkt_t * /*pkt*/) { + void FramePktHook(const vpx_codec_cx_pkt_t * /*pkt*/) override { ++frame_count_out_; } diff --git a/libs/libvpx/test/consistency_test.cc b/libs/libvpx/test/consistency_test.cc index f0e2cb297e..3e73bec492 100644 --- a/libs/libvpx/test/consistency_test.cc +++ b/libs/libvpx/test/consistency_test.cc @@ -13,7 +13,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #if CONFIG_VP9_ENCODER @@ -65,14 +65,14 @@ class ConsistencyTestBase : public ::testing::Test { delete[] ssim_array_; } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: // Handle frames up to 640x480 static const int kDataAlignment = 16; static const int kDataBufferSize = 640 * 480; - virtual void SetUp() { + void SetUp() override { source_stride_ = (width_ + 31) & ~31; reference_stride_ = width_ * 2; rnd_.Reset(ACMRandom::DeterministicSeed()); @@ -128,7 +128,7 @@ class ConsistencyTestBase : public ::testing::Test { }; #if CONFIG_VP9_ENCODER -typedef std::tuple ConsistencyParam; +using ConsistencyParam = std::tuple; class ConsistencyVP9Test : public ConsistencyTestBase, public ::testing::WithParamInterface { diff --git a/libs/libvpx/test/convolve_test.cc b/libs/libvpx/test/convolve_test.cc index d569048691..90bdcbc108 100644 --- a/libs/libvpx/test/convolve_test.cc +++ b/libs/libvpx/test/convolve_test.cc @@ -11,7 +11,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp9_rtcd.h" #include "./vpx_config.h" @@ -32,17 +32,24 @@ namespace { static const unsigned int kMaxDimension = 64; -typedef void (*ConvolveFunc)(const uint8_t *src, ptrdiff_t src_stride, - uint8_t *dst, ptrdiff_t dst_stride, - const InterpKernel *filter, int x0_q4, - int x_step_q4, int y0_q4, int y_step_q4, int w, - int h); +using ConvolveFunc = void (*)(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h); +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +using ConvolveFunc12Tap = void (*)(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h); +#endif -typedef void (*WrapperFilterBlock2d8Func)( - const uint8_t *src_ptr, const unsigned int src_stride, - const int16_t *hfilter, const int16_t *vfilter, uint8_t *dst_ptr, - unsigned int dst_stride, unsigned int output_width, - unsigned int output_height, int use_highbd); +using WrapperFilterBlock2d8Func = + void (*)(const uint8_t *src_ptr, const unsigned int src_stride, + const int16_t *hfilter, const int16_t *vfilter, uint8_t *dst_ptr, + unsigned int dst_stride, unsigned int output_width, + unsigned int output_height, int use_highbd); struct ConvolveFunctions { ConvolveFunctions(ConvolveFunc copy, ConvolveFunc avg, ConvolveFunc h8, @@ -78,7 +85,26 @@ struct ConvolveFunctions { int use_highbd_; // 0 if high bitdepth not used, else the actual bit depth. }; -typedef std::tuple ConvolveParam; +using ConvolveParam = std::tuple; + +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +struct ConvolveFunctions12Tap { + ConvolveFunctions12Tap(ConvolveFunc12Tap h12, ConvolveFunc12Tap v12, + ConvolveFunc12Tap hv12, int bd) + : use_highbd_(bd) { + h12_ = h12; + v12_ = v12; + hv12_ = hv12; + } + + ConvolveFunc12Tap h12_; + ConvolveFunc12Tap v12_; + ConvolveFunc12Tap hv12_; + int use_highbd_; // 0 if high bitdepth not used, else the actual bit depth. +}; + +using Convolve12TapParam = std::tuple; +#endif #define ALL_SIZES(convolve_fn) \ make_tuple(4, 4, &convolve_fn), make_tuple(8, 4, &convolve_fn), \ @@ -88,7 +114,13 @@ typedef std::tuple ConvolveParam; make_tuple(16, 32, &convolve_fn), make_tuple(32, 32, &convolve_fn), \ make_tuple(64, 32, &convolve_fn), make_tuple(32, 64, &convolve_fn), \ make_tuple(64, 64, &convolve_fn) - +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +#define ALL_SIZES_12TAP(convolve_fn) \ + make_tuple(8, 8, &convolve_fn), make_tuple(16, 8, &convolve_fn), \ + make_tuple(8, 16, &convolve_fn), make_tuple(16, 16, &convolve_fn), \ + make_tuple(32, 16, &convolve_fn), make_tuple(16, 32, &convolve_fn), \ + make_tuple(32, 32, &convolve_fn) +#endif // Reference 8-tap subpixel filter, slightly modified to fit into this test. #define VP9_FILTER_WEIGHT 128 #define VP9_FILTER_SHIFT 7 @@ -244,7 +276,7 @@ void highbd_filter_block2d_8_c(const uint16_t *src_ptr, // Vertical pass (transposed intermediate -> dst). { - uint16_t *src_ptr = intermediate_buffer; + src_ptr = intermediate_buffer; const int dst_next_row_stride = dst_stride - output_width; unsigned int i, j; for (i = 0; i < output_height; ++i) { @@ -361,7 +393,7 @@ class ConvolveTest : public ::testing::TestWithParam { #endif } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } static void TearDownTestSuite() { vpx_free(input_ - 1); @@ -403,7 +435,7 @@ class ConvolveTest : public ::testing::TestWithParam { i % kOuterBlockSize >= (BorderLeft() + Width())); } - virtual void SetUp() { + void SetUp() override { UUT_ = GET_PARAM(2); #if CONFIG_VP9_HIGHBITDEPTH if (UUT_->use_highbd_ != 0) { @@ -549,6 +581,438 @@ uint16_t *ConvolveTest::input16_ = nullptr; uint16_t *ConvolveTest::output16_ = nullptr; uint16_t *ConvolveTest::output16_ref_ = nullptr; #endif +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +class ConvolveTest12Tap : public ::testing::TestWithParam { + public: + static void SetUpTestSuite() { + // Force input_ to be unaligned, output to be 16 byte aligned. + input_ = reinterpret_cast( + vpx_memalign(kDataAlignment, kInputBufferSize + 1)) + + 1; + output_ = reinterpret_cast( + vpx_memalign(kDataAlignment, kOutputBufferSize)); +#if CONFIG_VP9_HIGHBITDEPTH + input16_ = reinterpret_cast(vpx_memalign( + kDataAlignment, (kInputBufferSize + 1) * sizeof(uint16_t))) + + 1; + output16_ = reinterpret_cast( + vpx_memalign(kDataAlignment, (kOutputBufferSize) * sizeof(uint16_t))); +#endif + } + + void TearDown() override { libvpx_test::ClearSystemState(); } + + static void TearDownTestSuite() { + vpx_free(input_ - 1); + input_ = nullptr; + vpx_free(output_); + output_ = nullptr; +#if CONFIG_VP9_HIGHBITDEPTH + vpx_free(input16_ - 1); + input16_ = nullptr; + vpx_free(output16_); + output16_ = nullptr; +#endif + } + + protected: + static const int kDataAlignment = 16; + static const int kOuterBlockSize = 256; + static const int kInputStride = kOuterBlockSize; + static const int kOutputStride = kOuterBlockSize; + static const int kInputBufferSize = kOuterBlockSize * kOuterBlockSize; + static const int kOutputBufferSize = kOuterBlockSize * kOuterBlockSize; + + int Width() const { return GET_PARAM(0); } + int Height() const { return GET_PARAM(1); } + int BorderLeft() const { + const int center = (kOuterBlockSize - Width()) / 2; + return (center + (kDataAlignment - 1)) & ~(kDataAlignment - 1); + } + int BorderTop() const { return (kOuterBlockSize - Height()) / 2; } + + bool IsIndexInBorder(int i) { + return (i < BorderTop() * kOuterBlockSize || + i >= (BorderTop() + Height()) * kOuterBlockSize || + i % kOuterBlockSize < BorderLeft() || + i % kOuterBlockSize >= (BorderLeft() + Width())); + } + + void SetUp() override { + UUT_ = GET_PARAM(2); +#if CONFIG_VP9_HIGHBITDEPTH + if (UUT_->use_highbd_ != 0) { + mask_ = (1 << UUT_->use_highbd_) - 1; + } else { + mask_ = 255; + } +#endif + /* Set up guard blocks for an inner block centered in the outer block */ + for (int i = 0; i < kOutputBufferSize; ++i) { + if (IsIndexInBorder(i)) { + output_[i] = 255; +#if CONFIG_VP9_HIGHBITDEPTH + output16_[i] = mask_; +#endif + } else { + output_[i] = 0; +#if CONFIG_VP9_HIGHBITDEPTH + output16_[i] = 0; +#endif + } + } + + ::libvpx_test::ACMRandom prng; + for (int i = 0; i < kInputBufferSize; ++i) { + if (i & 1) { + input_[i] = 255; +#if CONFIG_VP9_HIGHBITDEPTH + input16_[i] = mask_; +#endif + } else { + input_[i] = prng.Rand8Extremes(); +#if CONFIG_VP9_HIGHBITDEPTH + input16_[i] = prng.Rand16() & mask_; +#endif + } + } + } + + void SetConstantInput(int value) { + memset(input_, value, kInputBufferSize); +#if CONFIG_VP9_HIGHBITDEPTH + vpx_memset16(input16_, value, kInputBufferSize); +#endif + } + + void CheckGuardBlocks() { + for (int i = 0; i < kOutputBufferSize; ++i) { + if (IsIndexInBorder(i)) { + EXPECT_EQ(255, output_[i]); + } + } + } + + uint8_t *input() const { + const int offset = BorderTop() * kOuterBlockSize + BorderLeft(); +#if CONFIG_VP9_HIGHBITDEPTH + if (UUT_->use_highbd_ == 0) { + return input_ + offset; + } else { + return CAST_TO_BYTEPTR(input16_ + offset); + } +#else + return input_ + offset; +#endif + } + + uint8_t *output() const { + const int offset = BorderTop() * kOuterBlockSize + BorderLeft(); +#if CONFIG_VP9_HIGHBITDEPTH + if (UUT_->use_highbd_ == 0) { + return output_ + offset; + } else { + return CAST_TO_BYTEPTR(output16_ + offset); + } +#else + return output_ + offset; +#endif + } + + uint16_t lookup(uint8_t *list, int index) const { +#if CONFIG_VP9_HIGHBITDEPTH + if (UUT_->use_highbd_ == 0) { + return list[index]; + } else { + return CAST_TO_SHORTPTR(list)[index]; + } +#else + return list[index]; +#endif + } + + void assign_val(uint8_t *list, int index, uint16_t val) const { +#if CONFIG_VP9_HIGHBITDEPTH + if (UUT_->use_highbd_ == 0) { + list[index] = (uint8_t)val; + } else { + CAST_TO_SHORTPTR(list)[index] = val; + } +#else + list[index] = (uint8_t)val; +#endif + } + const ConvolveFunctions12Tap *UUT_; + static uint8_t *input_; + static uint8_t *output_; +#if CONFIG_VP9_HIGHBITDEPTH + static uint16_t *input16_; + static uint16_t *output16_; + int mask_; +#endif +}; + +uint8_t *ConvolveTest12Tap::input_ = nullptr; +uint8_t *ConvolveTest12Tap::output_ = nullptr; +#if CONFIG_VP9_HIGHBITDEPTH +uint16_t *ConvolveTest12Tap::input16_ = nullptr; +uint16_t *ConvolveTest12Tap::output16_ = nullptr; +#endif + +TEST_P(ConvolveTest12Tap, MatchesReferenceSubpixelFilter) { + uint8_t *const in = input(); + uint8_t *const out = output(); +#if CONFIG_VP9_HIGHBITDEPTH + uint8_t ref8[kOutputStride * kMaxDimension]; + uint16_t ref16[kOutputStride * kMaxDimension]; + uint8_t *ref; + if (UUT_->use_highbd_ == 0) { + ref = ref8; + } else { + ref = CAST_TO_BYTEPTR(ref16); + } +#else + uint8_t ref[kOutputStride * kMaxDimension]; +#endif + + // Populate ref and out with some random data + ::libvpx_test::ACMRandom prng; + for (int y = 0; y < Height(); ++y) { + for (int x = 0; x < Width(); ++x) { + uint16_t r; +#if CONFIG_VP9_HIGHBITDEPTH + if (UUT_->use_highbd_ == 0 || UUT_->use_highbd_ == 8) { + r = prng.Rand8Extremes(); + } else { + r = prng.Rand16() & mask_; + } +#else + r = prng.Rand8Extremes(); +#endif + + assign_val(out, y * kOutputStride + x, r); + assign_val(ref, y * kOutputStride + x, r); + } + } + + const InterpKernel12 *filters = sub_pel_filters_12; + for (int filter_x = 0; filter_x < 16; ++filter_x) { + for (int filter_y = 0; filter_y < 16; ++filter_y) { +#if CONFIG_VP9_HIGHBITDEPTH + if (UUT_->use_highbd_ == 0) { + vpx_convolve12_c(in, kInputStride, ref, kOutputStride, filters, + filter_x, 16, filter_y, 16, Width(), Height()); + } else { + vpx_highbd_convolve12_c(CAST_TO_SHORTPTR(in), kInputStride, + CAST_TO_SHORTPTR(ref), kOutputStride, filters, + filter_x, 16, filter_y, 16, Width(), Height(), + UUT_->use_highbd_); + } +#else + vpx_convolve12_c(in, kInputStride, ref, kOutputStride, filters, filter_x, + 16, filter_y, 16, Width(), Height()); +#endif + if (filter_x && filter_y) + ASM_REGISTER_STATE_CHECK( + UUT_->hv12_(in, kInputStride, out, kOutputStride, filters, filter_x, + 16, filter_y, 16, Width(), Height())); + else if (filter_y) + ASM_REGISTER_STATE_CHECK(UUT_->v12_(in, kInputStride, out, + kOutputStride, filters, 0, 16, + filter_y, 16, Width(), Height())); + else if (filter_x) + ASM_REGISTER_STATE_CHECK(UUT_->h12_(in, kInputStride, out, + kOutputStride, filters, filter_x, + 16, 0, 16, Width(), Height())); + else + continue; + + CheckGuardBlocks(); + + for (int y = 0; y < Height(); ++y) { + for (int x = 0; x < Width(); ++x) + ASSERT_EQ(lookup(ref, y * kOutputStride + x), + lookup(out, y * kOutputStride + x)) + << "mismatch at (" << x << "," << y << "), " + << "filters (" + << "," << filter_x << "," << filter_y << ")"; + } + } + } +} + +TEST_P(ConvolveTest12Tap, FilterExtremes) { + uint8_t *const in = input(); + uint8_t *const out = output(); +#if CONFIG_VP9_HIGHBITDEPTH + uint8_t ref8[kOutputStride * kMaxDimension]; + uint16_t ref16[kOutputStride * kMaxDimension]; + uint8_t *ref; + if (UUT_->use_highbd_ == 0) { + ref = ref8; + } else { + ref = CAST_TO_BYTEPTR(ref16); + } +#else + uint8_t ref[kOutputStride * kMaxDimension]; +#endif + + // Populate ref and out with some random data + ::libvpx_test::ACMRandom prng; + for (int y = 0; y < Height(); ++y) { + for (int x = 0; x < Width(); ++x) { + uint16_t r; +#if CONFIG_VP9_HIGHBITDEPTH + if (UUT_->use_highbd_ == 0 || UUT_->use_highbd_ == 8) { + r = prng.Rand8Extremes(); + } else { + r = prng.Rand16() & mask_; + } +#else + r = prng.Rand8Extremes(); +#endif + assign_val(out, y * kOutputStride + x, r); + assign_val(ref, y * kOutputStride + x, r); + } + } + + for (int axis = 0; axis < 2; axis++) { + int seed_val = 0; + while (seed_val < 256) { + for (int y = 0; y < 8; ++y) { + for (int x = 0; x < 8; ++x) { +#if CONFIG_VP9_HIGHBITDEPTH + assign_val(in, y * kOutputStride + x - MAX_FILTER_TAP / 2 + 1, + ((seed_val >> (axis ? y : x)) & 1) * mask_); +#else + assign_val(in, y * kOutputStride + x - MAX_FILTER_TAP / 2 + 1, + ((seed_val >> (axis ? y : x)) & 1) * 255); +#endif + if (axis) seed_val++; + } + if (axis) { + seed_val -= 8; + } else { + seed_val++; + } + } + if (axis) seed_val += 8; + + const InterpKernel12 *filters = sub_pel_filters_12; + for (int filter_x = 0; filter_x < 16; ++filter_x) { + for (int filter_y = 0; filter_y < 16; ++filter_y) { +#if CONFIG_VP9_HIGHBITDEPTH + if (UUT_->use_highbd_ == 0) { + vpx_convolve12_c(in, kInputStride, ref, kOutputStride, filters, + filter_x, 16, filter_y, 16, Width(), Height()); + } else { + vpx_highbd_convolve12_c(CAST_TO_SHORTPTR(in), kInputStride, + CAST_TO_SHORTPTR(ref), kOutputStride, + filters, filter_x, 16, filter_y, 16, + Width(), Height(), UUT_->use_highbd_); + } +#else + vpx_convolve12_c(in, kInputStride, ref, kOutputStride, filters, + filter_x, 16, filter_y, 16, Width(), Height()); +#endif + if (filter_x && filter_y) + ASM_REGISTER_STATE_CHECK( + UUT_->hv12_(in, kInputStride, out, kOutputStride, filters, + filter_x, 16, filter_y, 16, Width(), Height())); + else if (filter_y) + ASM_REGISTER_STATE_CHECK( + UUT_->v12_(in, kInputStride, out, kOutputStride, filters, 0, 16, + filter_y, 16, Width(), Height())); + else if (filter_x) + ASM_REGISTER_STATE_CHECK( + UUT_->h12_(in, kInputStride, out, kOutputStride, filters, + filter_x, 16, 0, 16, Width(), Height())); + else + continue; + + for (int y = 0; y < Height(); ++y) { + for (int x = 0; x < Width(); ++x) + ASSERT_EQ(lookup(ref, y * kOutputStride + x), + lookup(out, y * kOutputStride + x)) + << "mismatch at (" << x << "," << y << "), " + << "filters (" + << "," << filter_x << "," << filter_y << ")"; + } + } + } + } + } +} + +TEST_P(ConvolveTest12Tap, DISABLED_12Tap_Speed) { + const uint8_t *const in = input(); + uint8_t *const out = output(); + const InterpKernel12 *const twelvetap = sub_pel_filters_12; + const int kNumTests = 5000000; + const int width = Width(); + const int height = Height(); + vpx_usec_timer timer; + + SetConstantInput(127); + + vpx_usec_timer_start(&timer); + for (int n = 0; n < kNumTests; ++n) { + UUT_->hv12_(in, kInputStride, out, kOutputStride, twelvetap, 8, 16, 8, 16, + width, height); + } + vpx_usec_timer_mark(&timer); + + const int elapsed_time = static_cast(vpx_usec_timer_elapsed(&timer)); + printf("convolve12_%dx%d_%d: %d us\n", width, height, + UUT_->use_highbd_ ? UUT_->use_highbd_ : 8, elapsed_time); +} + +TEST_P(ConvolveTest12Tap, DISABLED_12Tap_Horiz_Speed) { + const uint8_t *const in = input(); + uint8_t *const out = output(); + const InterpKernel12 *const twelvetap = sub_pel_filters_12; + const int kNumTests = 5000000; + const int width = Width(); + const int height = Height(); + vpx_usec_timer timer; + + SetConstantInput(127); + + vpx_usec_timer_start(&timer); + for (int n = 0; n < kNumTests; ++n) { + UUT_->h12_(in, kInputStride, out, kOutputStride, twelvetap, 8, 16, 8, 16, + width, height); + } + vpx_usec_timer_mark(&timer); + + const int elapsed_time = static_cast(vpx_usec_timer_elapsed(&timer)); + printf("convolve12_horiz_%dx%d_%d: %d us\n", width, height, + UUT_->use_highbd_ ? UUT_->use_highbd_ : 8, elapsed_time); +} + +TEST_P(ConvolveTest12Tap, DISABLED_12Tap_Vert_Speed) { + const uint8_t *const in = input(); + uint8_t *const out = output(); + const InterpKernel12 *const twelvetap = sub_pel_filters_12; + const int kNumTests = 5000000; + const int width = Width(); + const int height = Height(); + vpx_usec_timer timer; + + SetConstantInput(127); + + vpx_usec_timer_start(&timer); + for (int n = 0; n < kNumTests; ++n) { + UUT_->v12_(in, kInputStride, out, kOutputStride, twelvetap, 8, 16, 8, 16, + width, height); + } + vpx_usec_timer_mark(&timer); + + const int elapsed_time = static_cast(vpx_usec_timer_elapsed(&timer)); + printf("convolve12_vert_%dx%d_%d: %d us\n", width, height, + UUT_->use_highbd_ ? UUT_->use_highbd_ : 8, elapsed_time); +} +#endif TEST_P(ConvolveTest, GuardBlocks) { CheckGuardBlocks(); } @@ -1135,7 +1599,7 @@ using std::make_tuple; x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); \ } -#if HAVE_SSE2 && VPX_ARCH_X86_64 +#if HAVE_SSE2 && VPX_ARCH_X86_64 && HAVE_X86_ASM WRAP(convolve_copy_sse2, 8) WRAP(convolve_avg_sse2, 8) WRAP(convolve_copy_sse2, 10) @@ -1160,9 +1624,9 @@ WRAP(convolve8_vert_sse2, 12) WRAP(convolve8_avg_vert_sse2, 12) WRAP(convolve8_sse2, 12) WRAP(convolve8_avg_sse2, 12) -#endif // HAVE_SSE2 && VPX_ARCH_X86_64 +#endif // HAVE_SSE2 && VPX_ARCH_X86_64 && HAVE_X86_ASM -#if HAVE_AVX2 +#if HAVE_AVX2 && HAVE_X86_ASM WRAP(convolve_copy_avx2, 8) WRAP(convolve_avg_avx2, 8) WRAP(convolve8_horiz_avx2, 8) @@ -1189,7 +1653,7 @@ WRAP(convolve8_vert_avx2, 12) WRAP(convolve8_avg_avx2, 12) WRAP(convolve8_avg_horiz_avx2, 12) WRAP(convolve8_avg_vert_avx2, 12) -#endif // HAVE_AVX2 +#endif // HAVE_AVX2 && HAVE_X86_ASM #if HAVE_NEON WRAP(convolve_copy_neon, 8) @@ -1218,6 +1682,30 @@ WRAP(convolve8_neon, 12) WRAP(convolve8_avg_neon, 12) #endif // HAVE_NEON +#if HAVE_SVE +WRAP(convolve8_horiz_sve, 8) +WRAP(convolve8_avg_horiz_sve, 8) +WRAP(convolve8_horiz_sve, 10) +WRAP(convolve8_avg_horiz_sve, 10) +WRAP(convolve8_horiz_sve, 12) +WRAP(convolve8_avg_horiz_sve, 12) +#endif // HAVE_SVE + +#if HAVE_SVE2 +WRAP(convolve8_sve2, 8) +WRAP(convolve8_avg_sve2, 8) +WRAP(convolve8_vert_sve2, 8) +WRAP(convolve8_avg_vert_sve2, 8) +WRAP(convolve8_sve2, 10) +WRAP(convolve8_avg_sve2, 10) +WRAP(convolve8_vert_sve2, 10) +WRAP(convolve8_avg_vert_sve2, 10) +WRAP(convolve8_sve2, 12) +WRAP(convolve8_avg_sve2, 12) +WRAP(convolve8_vert_sve2, 12) +WRAP(convolve8_avg_vert_sve2, 12) +#endif // HAVE_SVE2 + WRAP(convolve_copy_c, 8) WRAP(convolve_avg_c, 8) WRAP(convolve8_horiz_c, 8) @@ -1280,9 +1768,107 @@ const ConvolveParam kArrayConvolve_c[] = { ALL_SIZES(convolve8_c) }; #endif INSTANTIATE_TEST_SUITE_P(C, ConvolveTest, ::testing::ValuesIn(kArrayConvolve_c)); +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +#if CONFIG_VP9_HIGHBITDEPTH +#define WRAP12TAP(func, bd) \ + void wrap_##func##_##bd( \ + const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, \ + ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, \ + int x_step_q4, int y0_q4, int y_step_q4, int w, int h) { \ + vpx_highbd_##func(reinterpret_cast(src), src_stride, \ + reinterpret_cast(dst), dst_stride, filter, \ + x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); \ + } + +#if HAVE_AVX2 && HAVE_X86_ASM +WRAP12TAP(convolve12_horiz_avx2, 8) +WRAP12TAP(convolve12_vert_avx2, 8) +WRAP12TAP(convolve12_avx2, 8) +WRAP12TAP(convolve12_horiz_avx2, 10) +WRAP12TAP(convolve12_vert_avx2, 10) +WRAP12TAP(convolve12_avx2, 10) +WRAP12TAP(convolve12_horiz_avx2, 12) +WRAP12TAP(convolve12_vert_avx2, 12) +WRAP12TAP(convolve12_avx2, 12) +#endif // HAVE_AVX2 + +#if HAVE_SSSE3 && HAVE_X86_ASM +WRAP12TAP(convolve12_horiz_ssse3, 8) +WRAP12TAP(convolve12_vert_ssse3, 8) +WRAP12TAP(convolve12_ssse3, 8) +WRAP12TAP(convolve12_horiz_ssse3, 10) +WRAP12TAP(convolve12_vert_ssse3, 10) +WRAP12TAP(convolve12_ssse3, 10) +WRAP12TAP(convolve12_horiz_ssse3, 12) +WRAP12TAP(convolve12_vert_ssse3, 12) +WRAP12TAP(convolve12_ssse3, 12) +#endif // HAVE_SSSE3 && HAVE_X86_ASM + +#if HAVE_NEON +WRAP12TAP(convolve12_horiz_neon, 8) +WRAP12TAP(convolve12_vert_neon, 8) +WRAP12TAP(convolve12_neon, 8) +WRAP12TAP(convolve12_horiz_neon, 10) +WRAP12TAP(convolve12_vert_neon, 10) +WRAP12TAP(convolve12_neon, 10) +WRAP12TAP(convolve12_horiz_neon, 12) +WRAP12TAP(convolve12_vert_neon, 12) +WRAP12TAP(convolve12_neon, 12) +#endif // HAVE_NEON + +#if HAVE_SVE2 +WRAP12TAP(convolve12_horiz_sve2, 8) +WRAP12TAP(convolve12_vert_sve2, 8) +WRAP12TAP(convolve12_sve2, 8) +WRAP12TAP(convolve12_horiz_sve2, 10) +WRAP12TAP(convolve12_vert_sve2, 10) +WRAP12TAP(convolve12_sve2, 10) +WRAP12TAP(convolve12_horiz_sve2, 12) +WRAP12TAP(convolve12_vert_sve2, 12) +WRAP12TAP(convolve12_sve2, 12) +#endif // HAVE_SVE2 + +WRAP12TAP(convolve12_horiz_c, 8) +WRAP12TAP(convolve12_vert_c, 8) +WRAP12TAP(convolve12_c, 8) +WRAP12TAP(convolve12_horiz_c, 10) +WRAP12TAP(convolve12_vert_c, 10) +WRAP12TAP(convolve12_c, 10) +WRAP12TAP(convolve12_horiz_c, 12) +WRAP12TAP(convolve12_vert_c, 12) +WRAP12TAP(convolve12_c, 12) +#undef WRAP12TAP + +const ConvolveFunctions12Tap convolve12tap_8bit_c(wrap_convolve12_horiz_c_8, + wrap_convolve12_vert_c_8, + wrap_convolve12_c_8, 8); + +const ConvolveFunctions12Tap convolve12tap_10bit_c(wrap_convolve12_horiz_c_10, + wrap_convolve12_vert_c_10, + wrap_convolve12_c_10, 10); + +const ConvolveFunctions12Tap convolve12tap_12bit_c(wrap_convolve12_horiz_c_12, + wrap_convolve12_vert_c_12, + wrap_convolve12_c_12, 12); + +const Convolve12TapParam kArrayConvolve12Tap_c[] = { + ALL_SIZES_12TAP(convolve12tap_8bit_c), ALL_SIZES_12TAP(convolve12tap_10bit_c), + ALL_SIZES_12TAP(convolve12tap_12bit_c) +}; +#else +const ConvolveFunctions12Tap convolve12Tap_c(vpx_convolve12_horiz_c, + vpx_convolve12_vert_c, + vpx_convolve12_c, 0); +const Convolve12TapParam kArrayConvolve12Tap_c[] = { ALL_SIZES_12TAP( + convolve12Tap_c) }; +#endif +INSTANTIATE_TEST_SUITE_P(C, ConvolveTest12Tap, + ::testing::ValuesIn(kArrayConvolve12Tap_c)); +#endif #if HAVE_SSE2 && VPX_ARCH_X86_64 #if CONFIG_VP9_HIGHBITDEPTH +#if HAVE_X86_ASM const ConvolveFunctions convolve8_sse2( wrap_convolve_copy_sse2_8, wrap_convolve_avg_sse2_8, wrap_convolve8_horiz_sse2_8, wrap_convolve8_avg_horiz_sse2_8, @@ -1310,6 +1896,9 @@ const ConvolveFunctions convolve12_sse2( const ConvolveParam kArrayConvolve_sse2[] = { ALL_SIZES(convolve8_sse2), ALL_SIZES(convolve10_sse2), ALL_SIZES(convolve12_sse2) }; +INSTANTIATE_TEST_SUITE_P(SSE2, ConvolveTest, + ::testing::ValuesIn(kArrayConvolve_sse2)); +#endif // HAVE_X86_ASM #else const ConvolveFunctions convolve8_sse2( vpx_convolve_copy_sse2, vpx_convolve_avg_sse2, vpx_convolve8_horiz_sse2, @@ -1319,12 +1908,12 @@ const ConvolveFunctions convolve8_sse2( vpx_scaled_avg_vert_c, vpx_scaled_2d_c, vpx_scaled_avg_2d_c, 0); const ConvolveParam kArrayConvolve_sse2[] = { ALL_SIZES(convolve8_sse2) }; -#endif // CONFIG_VP9_HIGHBITDEPTH INSTANTIATE_TEST_SUITE_P(SSE2, ConvolveTest, ::testing::ValuesIn(kArrayConvolve_sse2)); +#endif // CONFIG_VP9_HIGHBITDEPTH #endif -#if HAVE_SSSE3 +#if HAVE_SSSE3 && HAVE_X86_ASM const ConvolveFunctions convolve8_ssse3( vpx_convolve_copy_c, vpx_convolve_avg_c, vpx_convolve8_horiz_ssse3, vpx_convolve8_avg_horiz_ssse3, vpx_convolve8_vert_ssse3, @@ -1335,9 +1924,40 @@ const ConvolveFunctions convolve8_ssse3( const ConvolveParam kArrayConvolve8_ssse3[] = { ALL_SIZES(convolve8_ssse3) }; INSTANTIATE_TEST_SUITE_P(SSSE3, ConvolveTest, ::testing::ValuesIn(kArrayConvolve8_ssse3)); -#endif -#if HAVE_AVX2 +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +#if CONFIG_VP9_HIGHBITDEPTH +const ConvolveFunctions12Tap convolve12tap_8bit_ssse3( + wrap_convolve12_horiz_ssse3_8, wrap_convolve12_vert_ssse3_8, + wrap_convolve12_ssse3_8, 8); + +const ConvolveFunctions12Tap convolve12tap_10bit_ssse3( + wrap_convolve12_horiz_ssse3_10, wrap_convolve12_vert_ssse3_10, + wrap_convolve12_ssse3_10, 10); + +const ConvolveFunctions12Tap convolve12tap_12bit_ssse3( + wrap_convolve12_horiz_ssse3_12, wrap_convolve12_vert_ssse3_12, + wrap_convolve12_ssse3_12, 12); + +const Convolve12TapParam kArrayConvolve12Tap_ssse3[] = { + ALL_SIZES_12TAP(convolve12tap_8bit_ssse3), + ALL_SIZES_12TAP(convolve12tap_10bit_ssse3), + ALL_SIZES_12TAP(convolve12tap_12bit_ssse3) +}; +#else +const ConvolveFunctions12Tap convolve12_ssse3(vpx_convolve12_horiz_ssse3, + vpx_convolve12_vert_ssse3, + vpx_convolve12_ssse3, 0); +const Convolve12TapParam kArrayConvolve12Tap_ssse3[] = { ALL_SIZES_12TAP( + convolve12_ssse3) }; +#endif // CONFIG_VP9_HIGHBITDEPTH + +INSTANTIATE_TEST_SUITE_P(SSSE3, ConvolveTest12Tap, + ::testing::ValuesIn(kArrayConvolve12Tap_ssse3)); +#endif // !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +#endif // HAVE_SSSE3 && HAVE_X86_ASM + +#if HAVE_AVX2 && HAVE_X86_ASM #if CONFIG_VP9_HIGHBITDEPTH const ConvolveFunctions convolve8_avx2( wrap_convolve_copy_avx2_8, wrap_convolve_avg_avx2_8, @@ -1378,7 +1998,37 @@ const ConvolveParam kArrayConvolve8_avx2[] = { ALL_SIZES(convolve8_avx2) }; INSTANTIATE_TEST_SUITE_P(AVX2, ConvolveTest, ::testing::ValuesIn(kArrayConvolve8_avx2)); #endif // CONFIG_VP9_HIGHBITDEPTH -#endif // HAVE_AVX2 + +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +#if CONFIG_VP9_HIGHBITDEPTH +const ConvolveFunctions12Tap convolve12Tap_8bit_avx2( + wrap_convolve12_horiz_avx2_8, wrap_convolve12_vert_avx2_8, + wrap_convolve12_avx2_8, 8); + +const ConvolveFunctions12Tap convolve12Tap_10bit_avx2( + wrap_convolve12_horiz_avx2_10, wrap_convolve12_vert_avx2_10, + wrap_convolve12_avx2_10, 10); + +const ConvolveFunctions12Tap convolve12Tap_12bit_avx2( + wrap_convolve12_horiz_avx2_12, wrap_convolve12_vert_avx2_12, + wrap_convolve12_avx2_12, 12); + +const Convolve12TapParam kArrayConvolve12Tap_avx2[] = { + ALL_SIZES_12TAP(convolve12Tap_8bit_avx2), + ALL_SIZES_12TAP(convolve12Tap_10bit_avx2), + ALL_SIZES_12TAP(convolve12Tap_12bit_avx2) +}; +#else +const ConvolveFunctions12Tap convolve12Tap_avx2(vpx_convolve12_horiz_avx2, + vpx_convolve12_vert_avx2, + vpx_convolve12_avx2, 0); +const Convolve12TapParam kArrayConvolve12Tap_avx2[] = { ALL_SIZES_12TAP( + convolve12Tap_avx2) }; +#endif +INSTANTIATE_TEST_SUITE_P(AVX2, ConvolveTest12Tap, + ::testing::ValuesIn(kArrayConvolve12Tap_avx2)); +#endif +#endif // HAVE_AVX2 && HAVE_X86_ASM #if HAVE_NEON #if CONFIG_VP9_HIGHBITDEPTH @@ -1421,8 +2071,182 @@ const ConvolveParam kArrayConvolve_neon[] = { ALL_SIZES(convolve8_neon) }; #endif // CONFIG_VP9_HIGHBITDEPTH INSTANTIATE_TEST_SUITE_P(NEON, ConvolveTest, ::testing::ValuesIn(kArrayConvolve_neon)); + +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +#if CONFIG_VP9_HIGHBITDEPTH +const ConvolveFunctions12Tap convolve12tap_8bit_neon( + wrap_convolve12_horiz_neon_8, wrap_convolve12_vert_neon_8, + wrap_convolve12_neon_8, 8); + +const ConvolveFunctions12Tap convolve12tap_10bit_neon( + wrap_convolve12_horiz_neon_10, wrap_convolve12_vert_neon_10, + wrap_convolve12_neon_10, 10); + +const ConvolveFunctions12Tap convolve12tap_12bit_neon( + wrap_convolve12_horiz_neon_12, wrap_convolve12_vert_neon_12, + wrap_convolve12_neon_12, 12); + +const Convolve12TapParam kArrayConvolve12Tap_neon[] = { + ALL_SIZES_12TAP(convolve12tap_8bit_neon), + ALL_SIZES_12TAP(convolve12tap_10bit_neon), + ALL_SIZES_12TAP(convolve12tap_12bit_neon) +}; + +#else + +const ConvolveFunctions12Tap convolve12Tap_neon(vpx_convolve12_horiz_neon, + vpx_convolve12_vert_neon, + vpx_convolve12_neon, 0); +const Convolve12TapParam kArrayConvolve12Tap_neon[] = { ALL_SIZES_12TAP( + convolve12Tap_neon) }; +#endif // CONFIG_VP9_HIGHBITDEPTH + +INSTANTIATE_TEST_SUITE_P(NEON, ConvolveTest12Tap, + ::testing::ValuesIn(kArrayConvolve12Tap_neon)); +#endif // !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER #endif // HAVE_NEON +#if HAVE_NEON_DOTPROD +const ConvolveFunctions convolve8_neon_dotprod( + vpx_convolve_copy_c, vpx_convolve_avg_c, vpx_convolve8_horiz_neon_dotprod, + vpx_convolve8_avg_horiz_neon_dotprod, vpx_convolve8_vert_neon_dotprod, + vpx_convolve8_avg_vert_neon_dotprod, vpx_convolve8_neon_dotprod, + vpx_convolve8_avg_neon_dotprod, vpx_scaled_horiz_c, vpx_scaled_avg_horiz_c, + vpx_scaled_vert_c, vpx_scaled_avg_vert_c, vpx_scaled_2d_c, + vpx_scaled_avg_2d_c, 0); + +const ConvolveParam kArrayConvolve_neon_dotprod[] = { ALL_SIZES( + convolve8_neon_dotprod) }; +INSTANTIATE_TEST_SUITE_P(NEON_DOTPROD, ConvolveTest, + ::testing::ValuesIn(kArrayConvolve_neon_dotprod)); + +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +const ConvolveFunctions12Tap convolve12Tap_neon_dotprod( + vpx_convolve12_horiz_neon_dotprod, vpx_convolve12_vert_neon_dotprod, + vpx_convolve12_neon_dotprod, 0); +const Convolve12TapParam kArrayConvolve12Tap_neon_dotprod[] = { ALL_SIZES_12TAP( + convolve12Tap_neon_dotprod) }; +INSTANTIATE_TEST_SUITE_P(NEON_DOTPROD, ConvolveTest12Tap, + ::testing::ValuesIn(kArrayConvolve12Tap_neon_dotprod)); +#endif +#endif // HAVE_NEON_DOTPROD + +#if HAVE_SVE +#if CONFIG_VP9_HIGHBITDEPTH +const ConvolveFunctions convolve8_sve( + wrap_convolve_copy_c_8, wrap_convolve_avg_c_8, wrap_convolve8_horiz_sve_8, + wrap_convolve8_avg_horiz_sve_8, wrap_convolve8_vert_c_8, + wrap_convolve8_avg_vert_c_8, wrap_convolve8_c_8, wrap_convolve8_avg_c_8, + wrap_convolve8_horiz_c_8, wrap_convolve8_avg_horiz_c_8, + wrap_convolve8_vert_c_8, wrap_convolve8_avg_vert_c_8, wrap_convolve8_c_8, + wrap_convolve8_avg_c_8, 8); +const ConvolveFunctions convolve10_sve( + wrap_convolve_copy_c_10, wrap_convolve_avg_c_10, + wrap_convolve8_horiz_sve_10, wrap_convolve8_avg_horiz_sve_10, + wrap_convolve8_vert_c_10, wrap_convolve8_avg_vert_c_10, wrap_convolve8_c_10, + wrap_convolve8_avg_c_10, wrap_convolve8_horiz_c_10, + wrap_convolve8_avg_horiz_c_10, wrap_convolve8_vert_c_10, + wrap_convolve8_avg_vert_c_10, wrap_convolve8_c_10, wrap_convolve8_avg_c_10, + 10); +const ConvolveFunctions convolve12_sve( + wrap_convolve_copy_c_12, wrap_convolve_avg_c_12, + wrap_convolve8_horiz_sve_12, wrap_convolve8_avg_horiz_sve_12, + wrap_convolve8_vert_c_12, wrap_convolve8_avg_vert_c_12, wrap_convolve8_c_12, + wrap_convolve8_avg_c_12, wrap_convolve8_horiz_c_12, + wrap_convolve8_avg_horiz_c_12, wrap_convolve8_vert_c_12, + wrap_convolve8_avg_vert_c_12, wrap_convolve8_c_12, wrap_convolve8_avg_c_12, + 12); + +const ConvolveParam kArrayConvolve_sve[] = { ALL_SIZES(convolve8_sve), + ALL_SIZES(convolve10_sve), + ALL_SIZES(convolve12_sve) }; +INSTANTIATE_TEST_SUITE_P(SVE, ConvolveTest, + ::testing::ValuesIn(kArrayConvolve_sve)); +#endif // CONFIG_VP9_HIGHBITDEPTH +#endif // HAVE_SVE + +#if HAVE_SVE2 +#if CONFIG_VP9_HIGHBITDEPTH +const ConvolveFunctions convolve8_sve2( + wrap_convolve_copy_c_8, wrap_convolve_avg_c_8, wrap_convolve8_horiz_c_8, + wrap_convolve8_avg_horiz_c_8, wrap_convolve8_vert_sve2_8, + wrap_convolve8_avg_vert_sve2_8, wrap_convolve8_sve2_8, + wrap_convolve8_avg_sve2_8, wrap_convolve8_horiz_c_8, + wrap_convolve8_avg_horiz_c_8, wrap_convolve8_vert_c_8, + wrap_convolve8_avg_vert_c_8, wrap_convolve8_c_8, wrap_convolve8_avg_c_8, 8); +const ConvolveFunctions convolve10_sve2( + wrap_convolve_copy_c_10, wrap_convolve_avg_c_10, wrap_convolve8_horiz_c_10, + wrap_convolve8_avg_horiz_c_10, wrap_convolve8_vert_sve2_10, + wrap_convolve8_avg_vert_sve2_10, wrap_convolve8_sve2_10, + wrap_convolve8_avg_sve2_10, wrap_convolve8_horiz_c_10, + wrap_convolve8_avg_horiz_c_10, wrap_convolve8_vert_c_10, + wrap_convolve8_avg_vert_c_10, wrap_convolve8_c_10, wrap_convolve8_avg_c_10, + 10); +const ConvolveFunctions convolve12_sve2( + wrap_convolve_copy_c_12, wrap_convolve_avg_c_12, wrap_convolve8_horiz_c_12, + wrap_convolve8_avg_horiz_c_12, wrap_convolve8_vert_sve2_12, + wrap_convolve8_avg_vert_sve2_12, wrap_convolve8_sve2_12, + wrap_convolve8_avg_sve2_12, wrap_convolve8_horiz_c_12, + wrap_convolve8_avg_horiz_c_12, wrap_convolve8_vert_c_12, + wrap_convolve8_avg_vert_c_12, wrap_convolve8_c_12, wrap_convolve8_avg_c_12, + 12); + +const ConvolveParam kArrayConvolve_sve2[] = { ALL_SIZES(convolve8_sve2), + ALL_SIZES(convolve10_sve2), + ALL_SIZES(convolve12_sve2) }; +INSTANTIATE_TEST_SUITE_P(SVE2, ConvolveTest, + ::testing::ValuesIn(kArrayConvolve_sve2)); + +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +const ConvolveFunctions12Tap convolve12tap_8bit_sve2( + wrap_convolve12_horiz_sve2_8, wrap_convolve12_vert_sve2_8, + wrap_convolve12_sve2_8, 8); + +const ConvolveFunctions12Tap convolve12tap_10bit_sve2( + wrap_convolve12_horiz_sve2_10, wrap_convolve12_vert_sve2_10, + wrap_convolve12_sve2_10, 10); + +const ConvolveFunctions12Tap convolve12tap_12bit_sve2( + wrap_convolve12_horiz_sve2_12, wrap_convolve12_vert_sve2_12, + wrap_convolve12_sve2_12, 12); + +const Convolve12TapParam kArrayConvolve12Tap_sve2[] = { + ALL_SIZES_12TAP(convolve12tap_8bit_sve2), + ALL_SIZES_12TAP(convolve12tap_10bit_sve2), + ALL_SIZES_12TAP(convolve12tap_12bit_sve2) +}; + +INSTANTIATE_TEST_SUITE_P(SVE2, ConvolveTest12Tap, + ::testing::ValuesIn(kArrayConvolve12Tap_sve2)); +#endif // !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +#endif // CONFIG_VP9_HIGHBITDEPTH +#endif // HAVE_SVE2 + +#if HAVE_NEON_I8MM +const ConvolveFunctions convolve8_neon_i8mm( + vpx_convolve_copy_c, vpx_convolve_avg_c, vpx_convolve8_horiz_neon_i8mm, + vpx_convolve8_avg_horiz_neon_i8mm, vpx_convolve8_vert_neon_i8mm, + vpx_convolve8_avg_vert_neon_i8mm, vpx_convolve8_neon_i8mm, + vpx_convolve8_avg_neon_i8mm, vpx_scaled_horiz_c, vpx_scaled_avg_horiz_c, + vpx_scaled_vert_c, vpx_scaled_avg_vert_c, vpx_scaled_2d_c, + vpx_scaled_avg_2d_c, 0); + +const ConvolveParam kArrayConvolve_neon_i8mm[] = { ALL_SIZES( + convolve8_neon_i8mm) }; +INSTANTIATE_TEST_SUITE_P(NEON_I8MM, ConvolveTest, + ::testing::ValuesIn(kArrayConvolve_neon_i8mm)); + +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +const ConvolveFunctions12Tap convolve12Tap_neon_i8mm( + vpx_convolve12_horiz_neon_i8mm, vpx_convolve12_vert_neon_i8mm, + vpx_convolve12_neon_i8mm, 0); +const Convolve12TapParam kArrayConvolve12Tap_neon_i8mm[] = { ALL_SIZES_12TAP( + convolve12Tap_neon_i8mm) }; +INSTANTIATE_TEST_SUITE_P(NEON_I8MM, ConvolveTest12Tap, + ::testing::ValuesIn(kArrayConvolve12Tap_neon_i8mm)); +#endif +#endif // HAVE_NEON_I8MM + #if HAVE_DSPR2 const ConvolveFunctions convolve8_dspr2( vpx_convolve_copy_dspr2, vpx_convolve_avg_dspr2, vpx_convolve8_horiz_dspr2, diff --git a/libs/libvpx/test/cpu_speed_test.cc b/libs/libvpx/test/cpu_speed_test.cc index a7623f09ac..6e0a046633 100644 --- a/libs/libvpx/test/cpu_speed_test.cc +++ b/libs/libvpx/test/cpu_speed_test.cc @@ -7,7 +7,7 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" @@ -26,9 +26,9 @@ class CpuSpeedTest : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)), min_psnr_(kMaxPSNR), tune_content_(VP9E_CONTENT_DEFAULT) {} - virtual ~CpuSpeedTest() {} + ~CpuSpeedTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(encoding_mode_); if (encoding_mode_ != ::libvpx_test::kRealTime) { @@ -40,10 +40,10 @@ class CpuSpeedTest } } - virtual void BeginPassHook(unsigned int /*pass*/) { min_psnr_ = kMaxPSNR; } + void BeginPassHook(unsigned int /*pass*/) override { min_psnr_ = kMaxPSNR; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_); encoder->Control(VP9E_SET_TUNE_CONTENT, tune_content_); @@ -56,7 +56,7 @@ class CpuSpeedTest } } - virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { + void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) override { if (pkt->data.psnr.psnr[0] < min_psnr_) min_psnr_ = pkt->data.psnr.psnr[0]; } @@ -105,7 +105,7 @@ TEST_P(CpuSpeedTest, TestTuneScreen) { ::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25); cfg_.g_timebase = video.timebase(); cfg_.rc_2pass_vbr_minsection_pct = 5; - cfg_.rc_2pass_vbr_minsection_pct = 2000; + cfg_.rc_2pass_vbr_maxsection_pct = 2000; cfg_.rc_target_bitrate = 2000; cfg_.rc_max_quantizer = 63; cfg_.rc_min_quantizer = 0; @@ -148,9 +148,6 @@ TEST_P(CpuSpeedTest, TestLowBitrate) { ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); } -VP9_INSTANTIATE_TEST_SUITE(CpuSpeedTest, - ::testing::Values(::libvpx_test::kTwoPassGood, - ::libvpx_test::kOnePassGood, - ::libvpx_test::kRealTime), +VP9_INSTANTIATE_TEST_SUITE(CpuSpeedTest, ONE_PASS_TEST_MODES, ::testing::Range(0, 10)); } // namespace diff --git a/libs/libvpx/test/cq_test.cc b/libs/libvpx/test/cq_test.cc index 292adb0d04..52590d0666 100644 --- a/libs/libvpx/test/cq_test.cc +++ b/libs/libvpx/test/cq_test.cc @@ -9,11 +9,12 @@ */ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" #include "test/util.h" +#include "vpx_config.h" namespace { @@ -27,7 +28,7 @@ class CQTest : public ::libvpx_test::EncoderTest, public ::libvpx_test::CodecTestWithParam { public: // maps the cqlevel to the bitrate produced. - typedef std::map BitrateMap; + using BitrateMap = std::map; static void SetUpTestSuite() { bitrates_.clear(); } @@ -50,21 +51,21 @@ class CQTest : public ::libvpx_test::EncoderTest, init_flags_ = VPX_CODEC_USE_PSNR; } - virtual ~CQTest() {} + ~CQTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(libvpx_test::kTwoPassGood); } - virtual void BeginPassHook(unsigned int /*pass*/) { + void BeginPassHook(unsigned int /*pass*/) override { file_size_ = 0; psnr_ = 0.0; n_frames_ = 0; } - virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, - libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(libvpx_test::VideoSource *video, + libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { if (cfg_.rc_end_usage == VPX_CQ) { encoder->Control(VP8E_SET_CQ_LEVEL, cq_level_); @@ -73,12 +74,12 @@ class CQTest : public ::libvpx_test::EncoderTest, } } - virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { + void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) override { psnr_ += pow(10.0, pkt->data.psnr.psnr[0] / 10.0); n_frames_++; } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { file_size_ += pkt->data.frame.sz; } @@ -103,6 +104,10 @@ class CQTest : public ::libvpx_test::EncoderTest, CQTest::BitrateMap CQTest::bitrates_; TEST_P(CQTest, LinearPSNRIsHigherForCQLevel) { +#if CONFIG_REALTIME_ONLY + GTEST_SKIP() + << "Non-zero g_lag_in_frames is unsupported with CONFIG_REALTIME_ONLY"; +#else const vpx_rational timebase = { 33333333, 1000000000 }; cfg_.g_timebase = timebase; cfg_.rc_target_bitrate = kCQTargetBitrate; @@ -124,6 +129,7 @@ TEST_P(CQTest, LinearPSNRIsHigherForCQLevel) { ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); const double vbr_psnr_lin = GetLinearPSNROverBitrate(); EXPECT_GE(cq_psnr_lin, vbr_psnr_lin); +#endif // CONFIG_REALTIME_ONLY } VP8_INSTANTIATE_TEST_SUITE(CQTest, ::testing::Range(kCQLevelMin, kCQLevelMax, diff --git a/libs/libvpx/test/dct16x16_test.cc b/libs/libvpx/test/dct16x16_test.cc index 06837d809d..a3382ab64e 100644 --- a/libs/libvpx/test/dct16x16_test.cc +++ b/libs/libvpx/test/dct16x16_test.cc @@ -13,7 +13,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp9_rtcd.h" #include "./vpx_dsp_rtcd.h" @@ -25,8 +25,9 @@ #include "vp9/common/vp9_scan.h" #include "vpx/vpx_codec.h" #include "vpx/vpx_integer.h" +#include "vpx_config.h" #include "vpx_ports/mem.h" -#include "vpx_ports/msvc.h" // for round() +#include "vpx_ports/vpx_timer.h" using libvpx_test::ACMRandom; @@ -223,16 +224,16 @@ void reference_16x16_dct_2d(int16_t input[256], double output[256]) { } } -typedef void (*FdctFunc)(const int16_t *in, tran_low_t *out, int stride); -typedef void (*IdctFunc)(const tran_low_t *in, uint8_t *out, int stride); -typedef void (*FhtFunc)(const int16_t *in, tran_low_t *out, int stride, - int tx_type); -typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride, - int tx_type); +using FdctFunc = void (*)(const int16_t *in, tran_low_t *out, int stride); +using IdctFunc = void (*)(const tran_low_t *in, uint8_t *out, int stride); +using FhtFunc = void (*)(const int16_t *in, tran_low_t *out, int stride, + int tx_type); +using IhtFunc = void (*)(const tran_low_t *in, uint8_t *out, int stride, + int tx_type); -typedef std::tuple Dct16x16Param; -typedef std::tuple Ht16x16Param; -typedef std::tuple Idct16x16Param; +using Dct16x16Param = std::tuple; +using Ht16x16Param = std::tuple; +using Idct16x16Param = std::tuple; void fdct16x16_ref(const int16_t *in, tran_low_t *out, int stride, int /*tx_type*/) { @@ -309,7 +310,7 @@ void idct16x16_10_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) { class Trans16x16TestBase { public: - virtual ~Trans16x16TestBase() {} + virtual ~Trans16x16TestBase() = default; protected: virtual void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) = 0; @@ -548,12 +549,50 @@ class Trans16x16TestBase { } } + void RunSpeedTest() { + ACMRandom rnd(ACMRandom::DeterministicSeed()); + const int count_test_block = 10000; + int c_sum_time = 0; + int simd_sum_time = 0; + + DECLARE_ALIGNED(32, int16_t, input_block[kNumCoeffs]); + DECLARE_ALIGNED(32, tran_low_t, output_ref_block[kNumCoeffs]); + DECLARE_ALIGNED(32, tran_low_t, output_block[kNumCoeffs]); + + // Initialize a test block with input range [-mask_, mask_]. + for (int j = 0; j < kNumCoeffs; ++j) { + input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); + } + + vpx_usec_timer timer_c; + vpx_usec_timer_start(&timer_c); + for (int i = 0; i < count_test_block; ++i) { + vpx_fdct16x16_c(input_block, output_ref_block, pitch_); + } + vpx_usec_timer_mark(&timer_c); + c_sum_time += static_cast(vpx_usec_timer_elapsed(&timer_c)); + + vpx_usec_timer timer_mod; + vpx_usec_timer_start(&timer_mod); + for (int i = 0; i < count_test_block; ++i) { + RunFwdTxfm(input_block, output_block, pitch_); + } + + vpx_usec_timer_mark(&timer_mod); + simd_sum_time += static_cast(vpx_usec_timer_elapsed(&timer_mod)); + + printf( + "c_time = %d \t simd_time = %d \t Gain = %4.2f \n", c_sum_time, + simd_sum_time, + (static_cast(c_sum_time) / static_cast(simd_sum_time))); + } + void CompareInvReference(IdctFunc ref_txfm, int thresh) { ACMRandom rnd(ACMRandom::DeterministicSeed()); const int count_test_block = 10000; const int eob = 10; const int16_t *scan = vp9_default_scan_orders[TX_16X16].scan; - DECLARE_ALIGNED(16, tran_low_t, coeff[kNumCoeffs]); + DECLARE_ALIGNED(32, tran_low_t, coeff[kNumCoeffs]); DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); DECLARE_ALIGNED(16, uint8_t, ref[kNumCoeffs]); #if CONFIG_VP9_HIGHBITDEPTH @@ -604,6 +643,80 @@ class Trans16x16TestBase { } } + void RunInvTrans16x16SpeedTest(IdctFunc ref_txfm, int thresh) { + ACMRandom rnd(ACMRandom::DeterministicSeed()); + const int count_test_block = 10000; + const int eob = 10; + const int16_t *scan = vp9_default_scan_orders[TX_16X16].scan; + int64_t c_sum_time = 0; + int64_t simd_sum_time = 0; + DECLARE_ALIGNED(32, tran_low_t, coeff[kNumCoeffs]); + DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); + DECLARE_ALIGNED(16, uint8_t, ref[kNumCoeffs]); +#if CONFIG_VP9_HIGHBITDEPTH + DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); + DECLARE_ALIGNED(16, uint16_t, ref16[kNumCoeffs]); +#endif // CONFIG_VP9_HIGHBITDEPTH + + for (int j = 0; j < kNumCoeffs; ++j) { + if (j < eob) { + // Random values less than the threshold, either positive or negative + coeff[scan[j]] = rnd(thresh); + } else { + coeff[scan[j]] = 0; + } + if (bit_depth_ == VPX_BITS_8) { + dst[j] = 0; + ref[j] = 0; +#if CONFIG_VP9_HIGHBITDEPTH + } else { + dst16[j] = 0; + ref16[j] = 0; +#endif // CONFIG_VP9_HIGHBITDEPTH + } + } + + if (bit_depth_ == VPX_BITS_8) { + vpx_usec_timer timer_c; + vpx_usec_timer_start(&timer_c); + for (int i = 0; i < count_test_block; ++i) { + ref_txfm(coeff, ref, pitch_); + } + vpx_usec_timer_mark(&timer_c); + c_sum_time += vpx_usec_timer_elapsed(&timer_c); + + vpx_usec_timer timer_mod; + vpx_usec_timer_start(&timer_mod); + for (int i = 0; i < count_test_block; ++i) { + RunInvTxfm(coeff, dst, pitch_); + } + vpx_usec_timer_mark(&timer_mod); + simd_sum_time += vpx_usec_timer_elapsed(&timer_mod); + } else { +#if CONFIG_VP9_HIGHBITDEPTH + vpx_usec_timer timer_c; + vpx_usec_timer_start(&timer_c); + for (int i = 0; i < count_test_block; ++i) { + ref_txfm(coeff, CAST_TO_BYTEPTR(ref16), pitch_); + } + vpx_usec_timer_mark(&timer_c); + c_sum_time += vpx_usec_timer_elapsed(&timer_c); + + vpx_usec_timer timer_mod; + vpx_usec_timer_start(&timer_mod); + for (int i = 0; i < count_test_block; ++i) { + RunInvTxfm(coeff, CAST_TO_BYTEPTR(dst16), pitch_); + } + vpx_usec_timer_mark(&timer_mod); + simd_sum_time += vpx_usec_timer_elapsed(&timer_mod); +#endif // CONFIG_VP9_HIGHBITDEPTH + } + printf( + "c_time = %" PRId64 " \t simd_time = %" PRId64 " \t Gain = %4.2f \n", + c_sum_time, simd_sum_time, + (static_cast(c_sum_time) / static_cast(simd_sum_time))); + } + int pitch_; int tx_type_; vpx_bit_depth_t bit_depth_; @@ -615,9 +728,9 @@ class Trans16x16TestBase { class Trans16x16DCT : public Trans16x16TestBase, public ::testing::TestWithParam { public: - virtual ~Trans16x16DCT() {} + ~Trans16x16DCT() override = default; - virtual void SetUp() { + void SetUp() override { fwd_txfm_ = GET_PARAM(0); inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); @@ -636,13 +749,13 @@ class Trans16x16DCT : public Trans16x16TestBase, inv_txfm_ref = idct16x16_ref; #endif } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: - void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) { + void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) override { fwd_txfm_(in, out, stride); } - void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) { + void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) override { inv_txfm_(out, dst, stride); } @@ -664,12 +777,14 @@ TEST_P(Trans16x16DCT, QuantCheck) { TEST_P(Trans16x16DCT, InvAccuracyCheck) { RunInvAccuracyCheck(); } +TEST_P(Trans16x16DCT, DISABLED_Speed) { RunSpeedTest(); } + class Trans16x16HT : public Trans16x16TestBase, public ::testing::TestWithParam { public: - virtual ~Trans16x16HT() {} + ~Trans16x16HT() override = default; - virtual void SetUp() { + void SetUp() override { fwd_txfm_ = GET_PARAM(0); inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); @@ -688,13 +803,13 @@ class Trans16x16HT : public Trans16x16TestBase, inv_txfm_ref = iht16x16_ref; #endif } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: - void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) { + void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) override { fwd_txfm_(in, out, stride, tx_type_); } - void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) { + void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) override { inv_txfm_(out, dst, stride, tx_type_); } @@ -714,13 +829,12 @@ TEST_P(Trans16x16HT, QuantCheck) { RunQuantCheck(429, 729); } -#if HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE class InvTrans16x16DCT : public Trans16x16TestBase, public ::testing::TestWithParam { public: - virtual ~InvTrans16x16DCT() {} + ~InvTrans16x16DCT() override = default; - virtual void SetUp() { + void SetUp() override { ref_txfm_ = GET_PARAM(0); inv_txfm_ = GET_PARAM(1); thresh_ = GET_PARAM(2); @@ -728,11 +842,12 @@ class InvTrans16x16DCT : public Trans16x16TestBase, pitch_ = 16; mask_ = (1 << bit_depth_) - 1; } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: - void RunFwdTxfm(int16_t * /*in*/, tran_low_t * /*out*/, int /*stride*/) {} - void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) { + void RunFwdTxfm(int16_t * /*in*/, tran_low_t * /*out*/, + int /*stride*/) override {} + void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) override { inv_txfm_(out, dst, stride); } @@ -745,7 +860,10 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(InvTrans16x16DCT); TEST_P(InvTrans16x16DCT, CompareReference) { CompareInvReference(ref_txfm_, thresh_); } -#endif // HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE + +TEST_P(InvTrans16x16DCT, DISABLED_Speed) { + RunInvTrans16x16SpeedTest(ref_txfm_, thresh_); +} using std::make_tuple; @@ -787,15 +905,31 @@ INSTANTIATE_TEST_SUITE_P( make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 1, VPX_BITS_8), make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 2, VPX_BITS_8), make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 3, VPX_BITS_8))); + +INSTANTIATE_TEST_SUITE_P(C, InvTrans16x16DCT, + ::testing::Values(make_tuple(&vpx_idct16x16_256_add_c, + &vpx_idct16x16_256_add_c, + 6225, VPX_BITS_8))); + #endif // CONFIG_VP9_HIGHBITDEPTH -#if HAVE_NEON && !CONFIG_EMULATE_HARDWARE +#if HAVE_NEON && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE INSTANTIATE_TEST_SUITE_P( NEON, Trans16x16DCT, ::testing::Values(make_tuple(&vpx_fdct16x16_neon, &vpx_idct16x16_256_add_neon, 0, VPX_BITS_8))); #endif // HAVE_NEON && !CONFIG_EMULATE_HARDWARE +#if HAVE_NEON && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE +INSTANTIATE_TEST_SUITE_P( + NEON, Trans16x16DCT, + ::testing::Values( + make_tuple(&vpx_highbd_fdct16x16_neon, &idct16x16_10, 0, VPX_BITS_10), + make_tuple(&vpx_highbd_fdct16x16_neon, &idct16x16_12, 0, VPX_BITS_12), + make_tuple(&vpx_fdct16x16_neon, &vpx_idct16x16_256_add_c, 0, + VPX_BITS_8))); +#endif // HAVE_NEON && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE + #if HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE INSTANTIATE_TEST_SUITE_P( SSE2, Trans16x16DCT, @@ -811,8 +945,25 @@ INSTANTIATE_TEST_SUITE_P( 2, VPX_BITS_8), make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 3, VPX_BITS_8))); + +INSTANTIATE_TEST_SUITE_P(SSE2, InvTrans16x16DCT, + ::testing::Values(make_tuple( + &vpx_idct16x16_256_add_c, + &vpx_idct16x16_256_add_sse2, 6225, VPX_BITS_8))); #endif // HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE +#if HAVE_AVX2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE +INSTANTIATE_TEST_SUITE_P( + AVX2, Trans16x16DCT, + ::testing::Values(make_tuple(&vpx_fdct16x16_avx2, + &vpx_idct16x16_256_add_sse2, 0, VPX_BITS_8))); + +INSTANTIATE_TEST_SUITE_P(AVX2, InvTrans16x16DCT, + ::testing::Values(make_tuple( + &vpx_idct16x16_256_add_c, + &vpx_idct16x16_256_add_avx2, 6225, VPX_BITS_8))); +#endif // HAVE_AVX2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE + #if HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE INSTANTIATE_TEST_SUITE_P( SSE2, Trans16x16DCT, diff --git a/libs/libvpx/test/dct32x32_test.cc b/libs/libvpx/test/dct32x32_test.cc index 91bb8e01ea..77447481cb 100644 --- a/libs/libvpx/test/dct32x32_test.cc +++ b/libs/libvpx/test/dct32x32_test.cc @@ -13,7 +13,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp9_rtcd.h" #include "./vpx_config.h" @@ -24,10 +24,11 @@ #include "test/register_state_check.h" #include "test/util.h" #include "vp9/common/vp9_entropy.h" +#include "vp9/common/vp9_scan.h" #include "vpx/vpx_codec.h" #include "vpx/vpx_integer.h" #include "vpx_ports/mem.h" -#include "vpx_ports/msvc.h" // for round() +#include "vpx_ports/vpx_timer.h" using libvpx_test::ACMRandom; @@ -65,11 +66,14 @@ void reference_32x32_dct_2d(const int16_t input[kNumCoeffs], } } -typedef void (*FwdTxfmFunc)(const int16_t *in, tran_low_t *out, int stride); -typedef void (*InvTxfmFunc)(const tran_low_t *in, uint8_t *out, int stride); +using FwdTxfmFunc = void (*)(const int16_t *in, tran_low_t *out, int stride); +using InvTxfmFunc = void (*)(const tran_low_t *in, uint8_t *out, int stride); -typedef std::tuple - Trans32x32Param; +using Trans32x32Param = + std::tuple; + +using InvTrans32x32Param = + std::tuple; #if CONFIG_VP9_HIGHBITDEPTH void idct32x32_10(const tran_low_t *in, uint8_t *out, int stride) { @@ -84,8 +88,8 @@ void idct32x32_12(const tran_low_t *in, uint8_t *out, int stride) { class Trans32x32Test : public AbstractBench, public ::testing::TestWithParam { public: - virtual ~Trans32x32Test() {} - virtual void SetUp() { + ~Trans32x32Test() override = default; + void SetUp() override { fwd_txfm_ = GET_PARAM(0); inv_txfm_ = GET_PARAM(1); version_ = GET_PARAM(2); // 0: high precision forward transform @@ -94,7 +98,7 @@ class Trans32x32Test : public AbstractBench, mask_ = (1 << bit_depth_) - 1; } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: int version_; @@ -105,7 +109,7 @@ class Trans32x32Test : public AbstractBench, int16_t *bench_in_; tran_low_t *bench_out_; - virtual void Run(); + void Run() override; }; void Trans32x32Test::Run() { fwd_txfm_(bench_in_, bench_out_, 32); } @@ -314,6 +318,174 @@ TEST_P(Trans32x32Test, InverseAccuracy) { } } +class InvTrans32x32Test : public ::testing::TestWithParam { + public: + ~InvTrans32x32Test() override = default; + void SetUp() override { + ref_txfm_ = GET_PARAM(0); + inv_txfm_ = GET_PARAM(1); + version_ = GET_PARAM(2); // 0: high precision forward transform + // 1: low precision version for rd loop + bit_depth_ = GET_PARAM(3); + eob_ = GET_PARAM(4); + thresh_ = GET_PARAM(4); + mask_ = (1 << bit_depth_) - 1; + pitch_ = 32; + } + + void TearDown() override { libvpx_test::ClearSystemState(); } + + protected: + void RunRefTxfm(tran_low_t *out, uint8_t *dst, int stride) { + ref_txfm_(out, dst, stride); + } + void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) { + inv_txfm_(out, dst, stride); + } + int version_; + vpx_bit_depth_t bit_depth_; + int mask_; + int eob_; + int thresh_; + + InvTxfmFunc ref_txfm_; + InvTxfmFunc inv_txfm_; + int pitch_; + + void RunInvTrans32x32SpeedTest() { + ACMRandom rnd(ACMRandom::DeterministicSeed()); + const int count_test_block = 10000; + int64_t c_sum_time = 0; + int64_t simd_sum_time = 0; + const int16_t *scan = vp9_default_scan_orders[TX_32X32].scan; + DECLARE_ALIGNED(32, tran_low_t, coeff[kNumCoeffs]); + DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); + DECLARE_ALIGNED(16, uint8_t, ref[kNumCoeffs]); +#if CONFIG_VP9_HIGHBITDEPTH + DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); + DECLARE_ALIGNED(16, uint16_t, ref16[kNumCoeffs]); +#endif // CONFIG_VP9_HIGHBITDEPTH + + for (int j = 0; j < kNumCoeffs; ++j) { + if (j < eob_) { + // Random values less than the threshold, either positive or negative + coeff[scan[j]] = rnd(thresh_); + } else { + coeff[scan[j]] = 0; + } + if (bit_depth_ == VPX_BITS_8) { + dst[j] = 0; + ref[j] = 0; +#if CONFIG_VP9_HIGHBITDEPTH + } else { + dst16[j] = 0; + ref16[j] = 0; +#endif // CONFIG_VP9_HIGHBITDEPTH + } + } + + if (bit_depth_ == VPX_BITS_8) { + vpx_usec_timer timer_c; + vpx_usec_timer_start(&timer_c); + for (int i = 0; i < count_test_block; ++i) { + RunRefTxfm(coeff, ref, pitch_); + } + vpx_usec_timer_mark(&timer_c); + c_sum_time += vpx_usec_timer_elapsed(&timer_c); + + vpx_usec_timer timer_mod; + vpx_usec_timer_start(&timer_mod); + for (int i = 0; i < count_test_block; ++i) { + RunInvTxfm(coeff, dst, pitch_); + } + vpx_usec_timer_mark(&timer_mod); + simd_sum_time += vpx_usec_timer_elapsed(&timer_mod); + } else { +#if CONFIG_VP9_HIGHBITDEPTH + vpx_usec_timer timer_c; + vpx_usec_timer_start(&timer_c); + for (int i = 0; i < count_test_block; ++i) { + RunRefTxfm(coeff, CAST_TO_BYTEPTR(ref16), pitch_); + } + vpx_usec_timer_mark(&timer_c); + c_sum_time += vpx_usec_timer_elapsed(&timer_c); + + vpx_usec_timer timer_mod; + vpx_usec_timer_start(&timer_mod); + for (int i = 0; i < count_test_block; ++i) { + RunInvTxfm(coeff, CAST_TO_BYTEPTR(dst16), pitch_); + } + vpx_usec_timer_mark(&timer_mod); + simd_sum_time += vpx_usec_timer_elapsed(&timer_mod); +#endif // CONFIG_VP9_HIGHBITDEPTH + } + printf( + "c_time = %" PRId64 " \t simd_time = %" PRId64 " \t Gain = %4.2f \n", + c_sum_time, simd_sum_time, + (static_cast(c_sum_time) / static_cast(simd_sum_time))); + } + + void CompareInvReference32x32() { + ACMRandom rnd(ACMRandom::DeterministicSeed()); + const int count_test_block = 10000; + const int eob = 31; + const int16_t *scan = vp9_default_scan_orders[TX_32X32].scan; + DECLARE_ALIGNED(32, tran_low_t, coeff[kNumCoeffs]); + DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); + DECLARE_ALIGNED(16, uint8_t, ref[kNumCoeffs]); +#if CONFIG_VP9_HIGHBITDEPTH + DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); + DECLARE_ALIGNED(16, uint16_t, ref16[kNumCoeffs]); +#endif // CONFIG_VP9_HIGHBITDEPTH + + for (int i = 0; i < count_test_block; ++i) { + for (int j = 0; j < kNumCoeffs; ++j) { + if (j < eob) { + coeff[scan[j]] = rnd.Rand8Extremes(); + } else { + coeff[scan[j]] = 0; + } + if (bit_depth_ == VPX_BITS_8) { + dst[j] = 0; + ref[j] = 0; +#if CONFIG_VP9_HIGHBITDEPTH + } else { + dst16[j] = 0; + ref16[j] = 0; +#endif // CONFIG_VP9_HIGHBITDEPTH + } + } + if (bit_depth_ == VPX_BITS_8) { + RunRefTxfm(coeff, ref, pitch_); + RunInvTxfm(coeff, dst, pitch_); + } else { +#if CONFIG_VP9_HIGHBITDEPTH + RunRefTxfm(coeff, CAST_TO_BYTEPTR(ref16), pitch_); + ASM_REGISTER_STATE_CHECK( + RunInvTxfm(coeff, CAST_TO_BYTEPTR(dst16), pitch_)); +#endif // CONFIG_VP9_HIGHBITDEPTH + } + + for (int j = 0; j < kNumCoeffs; ++j) { +#if CONFIG_VP9_HIGHBITDEPTH + const uint32_t diff = + bit_depth_ == VPX_BITS_8 ? dst[j] - ref[j] : dst16[j] - ref16[j]; +#else + const uint32_t diff = dst[j] - ref[j]; +#endif // CONFIG_VP9_HIGHBITDEPTH + const uint32_t error = diff * diff; + EXPECT_EQ(0u, error) << "Error: 32x32 IDCT Comparison has error " + << error << " at index " << j; + } + } + } +}; + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(InvTrans32x32Test); + +TEST_P(InvTrans32x32Test, DISABLED_Speed) { RunInvTrans32x32SpeedTest(); } +TEST_P(InvTrans32x32Test, CompareReference) { CompareInvReference32x32(); } + using std::make_tuple; #if CONFIG_VP9_HIGHBITDEPTH @@ -334,6 +506,14 @@ INSTANTIATE_TEST_SUITE_P( VPX_BITS_8), make_tuple(&vpx_fdct32x32_rd_c, &vpx_idct32x32_1024_add_c, 1, VPX_BITS_8))); + +INSTANTIATE_TEST_SUITE_P( + C, InvTrans32x32Test, + ::testing::Values( + (make_tuple(&vpx_idct32x32_1024_add_c, &vpx_idct32x32_1024_add_c, 0, + VPX_BITS_8, 32, 6225)), + make_tuple(&vpx_idct32x32_135_add_c, &vpx_idct32x32_135_add_c, 0, + VPX_BITS_8, 16, 6255))); #endif // CONFIG_VP9_HIGHBITDEPTH #if HAVE_NEON && !CONFIG_EMULATE_HARDWARE @@ -352,6 +532,14 @@ INSTANTIATE_TEST_SUITE_P( &vpx_idct32x32_1024_add_sse2, 0, VPX_BITS_8), make_tuple(&vpx_fdct32x32_rd_sse2, &vpx_idct32x32_1024_add_sse2, 1, VPX_BITS_8))); + +INSTANTIATE_TEST_SUITE_P( + SSE2, InvTrans32x32Test, + ::testing::Values( + (make_tuple(&vpx_idct32x32_1024_add_c, &vpx_idct32x32_1024_add_sse2, 0, + VPX_BITS_8, 32, 6225)), + make_tuple(&vpx_idct32x32_135_add_c, &vpx_idct32x32_135_add_sse2, 0, + VPX_BITS_8, 16, 6225))); #endif // HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #if HAVE_SSE2 && CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE @@ -377,6 +565,14 @@ INSTANTIATE_TEST_SUITE_P( &vpx_idct32x32_1024_add_sse2, 0, VPX_BITS_8), make_tuple(&vpx_fdct32x32_rd_avx2, &vpx_idct32x32_1024_add_sse2, 1, VPX_BITS_8))); + +INSTANTIATE_TEST_SUITE_P( + AVX2, InvTrans32x32Test, + ::testing::Values( + (make_tuple(&vpx_idct32x32_1024_add_c, &vpx_idct32x32_1024_add_avx2, 0, + VPX_BITS_8, 32, 6225)), + make_tuple(&vpx_idct32x32_135_add_c, &vpx_idct32x32_135_add_avx2, 0, + VPX_BITS_8, 16, 6225))); #endif // HAVE_AVX2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE #if HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE diff --git a/libs/libvpx/test/dct_partial_test.cc b/libs/libvpx/test/dct_partial_test.cc index 8d0e3a912e..dc4921ab94 100644 --- a/libs/libvpx/test/dct_partial_test.cc +++ b/libs/libvpx/test/dct_partial_test.cc @@ -14,7 +14,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_dsp_rtcd.h" #include "test/acm_random.h" @@ -22,6 +22,7 @@ #include "test/clear_system_state.h" #include "test/register_state_check.h" #include "test/util.h" +#include "vpx_config.h" #include "vpx/vpx_codec.h" #include "vpx/vpx_integer.h" #include "vpx_dsp/vpx_dsp_common.h" @@ -32,10 +33,10 @@ using std::make_tuple; using std::tuple; namespace { -typedef void (*PartialFdctFunc)(const int16_t *in, tran_low_t *out, int stride); +using PartialFdctFunc = void (*)(const int16_t *in, tran_low_t *out, + int stride); -typedef tuple - PartialFdctParam; +using PartialFdctParam = tuple; tran_low_t partial_fdct_ref(const Buffer &in, int size) { int64_t sum = 0; @@ -67,7 +68,7 @@ class PartialFdctTest : public ::testing::TestWithParam { bit_depth_ = GET_PARAM(2); } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: void RunTest() { @@ -145,11 +146,17 @@ INSTANTIATE_TEST_SUITE_P( #if CONFIG_VP9_HIGHBITDEPTH INSTANTIATE_TEST_SUITE_P( NEON, PartialFdctTest, - ::testing::Values(make_tuple(&vpx_fdct32x32_1_neon, 32, VPX_BITS_8), - make_tuple(&vpx_fdct16x16_1_neon, 16, VPX_BITS_8), + ::testing::Values(make_tuple(&vpx_highbd_fdct32x32_1_neon, 32, VPX_BITS_12), + make_tuple(&vpx_highbd_fdct32x32_1_neon, 32, VPX_BITS_10), + make_tuple(&vpx_highbd_fdct32x32_1_neon, 32, VPX_BITS_8), + make_tuple(&vpx_highbd_fdct16x16_1_neon, 16, VPX_BITS_12), + make_tuple(&vpx_highbd_fdct16x16_1_neon, 16, VPX_BITS_10), + make_tuple(&vpx_highbd_fdct16x16_1_neon, 16, VPX_BITS_8), make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_12), make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_10), make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_8), + make_tuple(&vpx_fdct4x4_1_neon, 4, VPX_BITS_12), + make_tuple(&vpx_fdct4x4_1_neon, 4, VPX_BITS_10), make_tuple(&vpx_fdct4x4_1_neon, 4, VPX_BITS_8))); #else INSTANTIATE_TEST_SUITE_P( diff --git a/libs/libvpx/test/dct_test.cc b/libs/libvpx/test/dct_test.cc index 2182f87e5e..7c581674f1 100644 --- a/libs/libvpx/test/dct_test.cc +++ b/libs/libvpx/test/dct_test.cc @@ -13,7 +13,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp9_rtcd.h" #include "./vpx_dsp_rtcd.h" @@ -23,6 +23,7 @@ #include "test/register_state_check.h" #include "test/util.h" #include "vp9/common/vp9_entropy.h" +#include "vpx_config.h" #include "vpx/vpx_codec.h" #include "vpx/vpx_integer.h" #include "vpx_ports/mem.h" @@ -33,16 +34,16 @@ using std::make_tuple; using std::tuple; namespace { -typedef void (*FdctFunc)(const int16_t *in, tran_low_t *out, int stride); -typedef void (*IdctFunc)(const tran_low_t *in, uint8_t *out, int stride); -typedef void (*FhtFunc)(const int16_t *in, tran_low_t *out, int stride, - int tx_type); -typedef void (*FhtFuncRef)(const Buffer &in, Buffer *out, - int size, int tx_type); -typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride, - int tx_type); -typedef void (*IhtWithBdFunc)(const tran_low_t *in, uint8_t *out, int stride, - int tx_type, int bd); +using FdctFunc = void (*)(const int16_t *in, tran_low_t *out, int stride); +using IdctFunc = void (*)(const tran_low_t *in, uint8_t *out, int stride); +using FhtFunc = void (*)(const int16_t *in, tran_low_t *out, int stride, + int tx_type); +using FhtFuncRef = void (*)(const Buffer &in, Buffer *out, + int size, int tx_type); +using IhtFunc = void (*)(const tran_low_t *in, uint8_t *out, int stride, + int tx_type); +using IhtWithBdFunc = void (*)(const tran_low_t *in, uint8_t *out, int stride, + int tx_type, int bd); template void fdct_wrapper(const int16_t *in, tran_low_t *out, int stride, int tx_type) { @@ -66,11 +67,11 @@ void iht_wrapper(const tran_low_t *in, uint8_t *out, int stride, int tx_type, } #if CONFIG_VP9_HIGHBITDEPTH -typedef void (*HighbdIdctFunc)(const tran_low_t *in, uint16_t *out, int stride, - int bd); +using HighbdIdctFunc = void (*)(const tran_low_t *in, uint16_t *out, int stride, + int bd); -typedef void (*HighbdIhtFunc)(const tran_low_t *in, uint16_t *out, int stride, - int tx_type, int bd); +using HighbdIhtFunc = void (*)(const tran_low_t *in, uint16_t *out, int stride, + int tx_type, int bd); template void highbd_idct_wrapper(const tran_low_t *in, uint8_t *out, int stride, @@ -94,7 +95,7 @@ struct FuncInfo { }; /* forward transform, inverse transform, size, transform type, bit depth */ -typedef tuple DctParam; +using DctParam = tuple; void fdct_ref(const Buffer &in, Buffer *out, int size, int /*tx_type*/) { @@ -134,7 +135,7 @@ void fwht_ref(const Buffer &in, Buffer *out, int size, class TransTestBase : public ::testing::TestWithParam { public: - virtual void SetUp() { + void SetUp() override { rnd_.Reset(ACMRandom::DeterministicSeed()); const int idx = GET_PARAM(0); const FuncInfo *func_info = &(GET_PARAM(1)[idx]); @@ -166,7 +167,7 @@ class TransTestBase : public ::testing::TestWithParam { ASSERT_NE(dst_, nullptr); } - virtual void TearDown() { + void TearDown() override { vpx_free(src_); src_ = nullptr; vpx_free(dst_); @@ -358,14 +359,6 @@ class TransTestBase : public ::testing::TestWithParam { ASSERT_TRUE(in.Init()); Buffer coeff = Buffer(size_, size_, 0, 16); ASSERT_TRUE(coeff.Init()); - Buffer dst = Buffer(size_, size_, 0, 16); - ASSERT_TRUE(dst.Init()); - Buffer src = Buffer(size_, size_, 0); - ASSERT_TRUE(src.Init()); - Buffer dst16 = Buffer(size_, size_, 0, 16); - ASSERT_TRUE(dst16.Init()); - Buffer src16 = Buffer(size_, size_, 0); - ASSERT_TRUE(src16.Init()); for (int i = 0; i < count_test_block; ++i) { InitMem(); @@ -539,6 +532,18 @@ INSTANTIATE_TEST_SUITE_P(AVX2, TransDCT, #endif // HAVE_AVX2 && !CONFIG_VP9_HIGHBITDEPTH #if HAVE_NEON +#if CONFIG_VP9_HIGHBITDEPTH +static const FuncInfo dct_neon_func_info[] = { + { &fdct_wrapper, + &highbd_idct_wrapper, 4, 2 }, + { &fdct_wrapper, + &highbd_idct_wrapper, 8, 2 }, + { &fdct_wrapper, + &highbd_idct_wrapper, 16, 2 }, + /* { &fdct_wrapper, + &highbd_idct_wrapper, 32, 2 },*/ +}; +#else static const FuncInfo dct_neon_func_info[4] = { { &fdct_wrapper, &idct_wrapper, 4, 1 }, @@ -549,12 +554,15 @@ static const FuncInfo dct_neon_func_info[4] = { { &fdct_wrapper, &idct_wrapper, 32, 1 } }; +#endif // CONFIG_VP9_HIGHBITDEPTH INSTANTIATE_TEST_SUITE_P( NEON, TransDCT, - ::testing::Combine(::testing::Range(0, 4), - ::testing::Values(dct_neon_func_info), - ::testing::Values(0), ::testing::Values(VPX_BITS_8))); + ::testing::Combine( + ::testing::Range(0, static_cast(sizeof(dct_neon_func_info) / + sizeof(dct_neon_func_info[0]))), + ::testing::Values(dct_neon_func_info), ::testing::Values(0), + ::testing::Values(VPX_BITS_8, VPX_BITS_10, VPX_BITS_12))); #endif // HAVE_NEON #if HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH @@ -652,10 +660,16 @@ static const FuncInfo ht_neon_func_info[] = { #if CONFIG_VP9_HIGHBITDEPTH { &vp9_highbd_fht4x4_c, &highbd_iht_wrapper, 4, 2 }, + { &vp9_highbd_fht4x4_neon, &highbd_iht_wrapper, + 4, 2 }, { &vp9_highbd_fht8x8_c, &highbd_iht_wrapper, 8, 2 }, + { &vp9_highbd_fht8x8_neon, &highbd_iht_wrapper, + 8, 2 }, { &vp9_highbd_fht16x16_c, &highbd_iht_wrapper, 16, 2 }, + { &vp9_highbd_fht16x16_neon, + &highbd_iht_wrapper, 16, 2 }, #endif { &vp9_fht4x4_c, &iht_wrapper, 4, 1 }, { &vp9_fht4x4_neon, &iht_wrapper, 4, 1 }, @@ -754,7 +768,7 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values(wht_c_func_info), ::testing::Values(0), ::testing::Values(VPX_BITS_8, VPX_BITS_10, VPX_BITS_12))); -#if HAVE_SSE2 && !CONFIG_EMULATE_HARDWARE +#if HAVE_SSE2 && HAVE_X86_ASM && !CONFIG_EMULATE_HARDWARE static const FuncInfo wht_sse2_func_info = { &fdct_wrapper, &idct_wrapper, 4, 1 }; @@ -762,7 +776,7 @@ static const FuncInfo wht_sse2_func_info = { INSTANTIATE_TEST_SUITE_P(SSE2, TransWHT, ::testing::Values(make_tuple(0, &wht_sse2_func_info, 0, VPX_BITS_8))); -#endif // HAVE_SSE2 && !CONFIG_EMULATE_HARDWARE +#endif // HAVE_SSE2 && HAVE_X86_ASM && !CONFIG_EMULATE_HARDWARE #if HAVE_VSX && !CONFIG_EMULATE_HARDWARE && !CONFIG_VP9_HIGHBITDEPTH static const FuncInfo wht_vsx_func_info = { diff --git a/libs/libvpx/test/decode_api_test.cc b/libs/libvpx/test/decode_api_test.cc index 9e82ace1b8..1e70e81d4a 100644 --- a/libs/libvpx/test/decode_api_test.cc +++ b/libs/libvpx/test/decode_api_test.cc @@ -8,19 +8,30 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include +#include + +#include "gtest/gtest.h" #include "./vpx_config.h" +#if CONFIG_VP8_DECODER && CONFIG_MULTITHREAD && defined(__linux__) +#include +#endif #include "test/ivf_video_source.h" +#include "test/video_source.h" +#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER +#include "vpx/vp8cx.h" +#endif #include "vpx/vp8dx.h" #include "vpx/vpx_decoder.h" +#include "vpx/vpx_encoder.h" namespace { #define NELEMENTS(x) static_cast(sizeof(x) / sizeof(x[0])) TEST(DecodeAPI, InvalidParams) { - static const vpx_codec_iface_t *kCodecs[] = { + static vpx_codec_iface_t *kCodecs[] = { #if CONFIG_VP8_DECODER &vpx_codec_vp8_dx_algo, #endif @@ -77,6 +88,369 @@ TEST(DecodeAPI, OptionalParams) { VPX_CODEC_USE_ERROR_CONCEALMENT)); #endif // CONFIG_ERROR_CONCEALMENT } + +TEST(DecodeAPI, Vp8FlushAfterFragmentError) { + static constexpr uint8_t kInvalidKeyframe[10] = { 0 }; + vpx_codec_ctx_t dec; + + ASSERT_EQ(VPX_CODEC_OK, + vpx_codec_dec_init(&dec, &vpx_codec_vp8_dx_algo, nullptr, + VPX_CODEC_USE_INPUT_FRAGMENTS)); + EXPECT_EQ(VPX_CODEC_OK, + vpx_codec_decode(&dec, kInvalidKeyframe, sizeof(kInvalidKeyframe), + nullptr, 0)); + EXPECT_EQ(VPX_CODEC_UNSUP_BITSTREAM, + vpx_codec_decode(&dec, nullptr, 0, nullptr, 0)); + EXPECT_EQ(VPX_CODEC_OK, vpx_codec_decode(&dec, nullptr, 0, nullptr, 0)); + EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&dec)); +} + +#if CONFIG_SIZE_LIMIT && \ + (DECODE_WIDTH_LIMIT < 16383 || DECODE_HEIGHT_LIMIT < 16383) +TEST(DecodeAPI, Vp8RejectsOversizedKeyframeBeforeInitialization) { + vpx_codec_ctx_t dec; + ASSERT_EQ(VPX_CODEC_OK, + vpx_codec_dec_init(&dec, &vpx_codec_vp8_dx_algo, nullptr, 0)); + +#if DECODE_WIDTH_LIMIT < 16383 + constexpr uint16_t kWidth = DECODE_WIDTH_LIMIT + 1; + constexpr uint16_t kHeight = 1; +#else + constexpr uint16_t kWidth = 1; + constexpr uint16_t kHeight = DECODE_HEIGHT_LIMIT + 1; +#endif + static constexpr uint8_t kOversizedKeyframe[10] = { + 0x00, + 0x00, + 0x00, + 0x9d, + 0x01, + 0x2a, + static_cast(kWidth), + static_cast(kWidth >> 8), + static_cast(kHeight), + static_cast(kHeight >> 8), + }; + EXPECT_EQ( + VPX_CODEC_CORRUPT_FRAME, + vpx_codec_decode(&dec, kOversizedKeyframe, + static_cast(sizeof(kOversizedKeyframe)), + nullptr, 0)); + + static constexpr uint8_t kInterframe[10] = { 0x01 }; + EXPECT_EQ(VPX_CODEC_UNSUP_BITSTREAM, + vpx_codec_decode(&dec, kInterframe, + static_cast(sizeof(kInterframe)), + nullptr, 0)); + EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&dec)); +} +#endif // CONFIG_SIZE_LIMIT && dimension limit is representable in VP8 + +TEST(DecodeAPI, Vp8FlushWithNoFragments) { + vpx_codec_ctx_t dec; + vpx_codec_dec_cfg_t cfg = { 1, 0, 0 }; + vpx_codec_flags_t flags = VPX_CODEC_USE_INPUT_FRAGMENTS; + + EXPECT_EQ(VPX_CODEC_OK, + vpx_codec_dec_init(&dec, &vpx_codec_vp8_dx_algo, &cfg, flags)); + EXPECT_EQ(VPX_CODEC_OK, vpx_codec_decode(&dec, nullptr, 0, nullptr, 0)); + EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&dec)); +} + +#if CONFIG_VP8_ENCODER && CONFIG_MULTITHREAD +// Encodes a sequence of key frames using two token partitions, truncates the +// second token partition of one frame so that the worker thread's bool decoder +// runs past the end of its partition, and then verifies that the +// multi-threaded decoder still reports subsequent well-formed key frames as +// not corrupted. +TEST(DecodeAPI, Vp8MultiThreadedCorruptedStateResetAcrossFrames) { + constexpr int kWidth = 16; + constexpr int kHeight = 32; + constexpr int kFrames = 4; + + std::vector> frames; + { + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, &cfg, 0), + VPX_CODEC_OK); + cfg.g_w = kWidth; + cfg.g_h = kHeight; + cfg.g_lag_in_frames = 0; + ASSERT_EQ(vpx_codec_enc_init(&enc, &vpx_codec_vp8_cx_algo, &cfg, 0), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_TOKEN_PARTITIONS, + VP8_TWO_TOKENPARTITION), + VPX_CODEC_OK); + + libvpx_test::RandomVideoSource video; + video.SetSize(kWidth, kHeight); + video.set_limit(kFrames); + for (video.Begin(); video.img() != nullptr; video.Next()) { + ASSERT_EQ( + vpx_codec_encode(&enc, video.img(), video.pts(), video.duration(), + VPX_EFLAG_FORCE_KF, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_codec_iter_t iter = nullptr; + const vpx_codec_cx_pkt_t *pkt; + while ((pkt = vpx_codec_get_cx_data(&enc, &iter)) != nullptr) { + if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) continue; + ASSERT_NE(pkt->data.frame.flags & VPX_FRAME_IS_KEY, 0u); + const uint8_t *buf = static_cast(pkt->data.frame.buf); + frames.emplace_back(buf, buf + pkt->data.frame.sz); + } + } + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); + } + ASSERT_EQ(frames.size(), static_cast(kFrames)); + + // Truncate frame 1 so that only a single byte of the second token partition + // remains. The first token partition (used by the main thread) is left + // intact. + { + std::vector &f = frames[1]; + ASSERT_GT(f.size(), 10u); + const size_t first_part_sz = + (static_cast(f[0]) | (static_cast(f[1]) << 8) | + (static_cast(f[2]) << 16)) >> + 5; + const size_t part_sizes = 10 + first_part_sz; + ASSERT_LT(part_sizes + 3, f.size()); + const size_t part0_sz = static_cast(f[part_sizes]) | + (static_cast(f[part_sizes + 1]) << 8) | + (static_cast(f[part_sizes + 2]) << 16); + const size_t part1_start = part_sizes + 3 + part0_sz; + ASSERT_LT(part1_start, f.size()); + f.resize(part1_start + 1); + } + + vpx_codec_ctx_t dec; + vpx_codec_dec_cfg_t dec_cfg = { /*threads=*/4, /*w=*/0, /*h=*/0 }; + ASSERT_EQ(vpx_codec_dec_init(&dec, &vpx_codec_vp8_dx_algo, &dec_cfg, 0), + VPX_CODEC_OK); + for (int i = 0; i < kFrames; ++i) { + const vpx_codec_err_t res = vpx_codec_decode( + &dec, frames[i].data(), static_cast(frames[i].size()), + /*user_priv=*/nullptr, /*deadline=*/0); + vpx_codec_iter_t iter = nullptr; + while (vpx_codec_get_frame(&dec, &iter)) { + } + if (i == 1) continue; + EXPECT_EQ(res, VPX_CODEC_OK) + << "frame " << i << ": " << vpx_codec_error_detail(&dec); + int corrupted = -1; + EXPECT_EQ(vpx_codec_control(&dec, VP8D_GET_FRAME_CORRUPTED, &corrupted), + VPX_CODEC_OK); + EXPECT_EQ(corrupted, 0) << "frame " << i; + } + EXPECT_EQ(vpx_codec_destroy(&dec), VPX_CODEC_OK); +} + +// Issue: 559707641 +// Encodes a sequence of frames with two token partitions, truncates the second +// token partition of one frame (used by a worker thread), and verifies that +// the multi-threaded decoder returns VPX_CODEC_CORRUPT_FRAME and does not emit +// a partially written frame. Also verifies that subsequent well-formed frames +// still decode correctly. +TEST(DecodeAPI, Vp8MultiThreadedWorkerDecodeErrorFailsFrame) { + constexpr int kWidth = 32; + constexpr int kHeight = 32; + class PatternVideoSource : public libvpx_test::DummyVideoSource { + protected: + void FillFrame() override { + if (!img_) return; + // Keep row 0 flat so partition 0 size is small. + memset(img_->planes[VPX_PLANE_Y], 128, img_->stride[VPX_PLANE_Y] * 16); + // Fill row 1 with varying pattern so partition 1 has tokens to truncate. + for (int y = 16; y < 32; ++y) { + uint8_t *row = + img_->planes[VPX_PLANE_Y] + y * img_->stride[VPX_PLANE_Y]; + for (int x = 0; x < 32; ++x) { + row[x] = static_cast((x * 37 + y * 73) ^ (frame_ * 19)); + } + } + memset(img_->planes[VPX_PLANE_U], 128, img_->stride[VPX_PLANE_U] * 16); + memset(img_->planes[VPX_PLANE_V], 128, img_->stride[VPX_PLANE_V] * 16); + } + }; + + constexpr int kFrames = 4; + std::vector> frames; + { + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, &cfg, 0), + VPX_CODEC_OK); + cfg.g_w = kWidth; + cfg.g_h = kHeight; + cfg.g_lag_in_frames = 0; + ASSERT_EQ(vpx_codec_enc_init(&enc, &vpx_codec_vp8_cx_algo, &cfg, 0), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_TOKEN_PARTITIONS, + VP8_TWO_TOKENPARTITION), + VPX_CODEC_OK); + + PatternVideoSource video; + video.SetSize(kWidth, kHeight); + video.set_limit(kFrames); + for (video.Begin(); video.img() != nullptr; video.Next()) { + ASSERT_EQ( + vpx_codec_encode(&enc, video.img(), video.pts(), video.duration(), + VPX_EFLAG_FORCE_KF, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_codec_iter_t iter = nullptr; + const vpx_codec_cx_pkt_t *pkt; + while ((pkt = vpx_codec_get_cx_data(&enc, &iter)) != nullptr) { + if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) continue; + ASSERT_NE(pkt->data.frame.flags & VPX_FRAME_IS_KEY, 0u); + const uint8_t *buf = static_cast(pkt->data.frame.buf); + frames.emplace_back(buf, buf + pkt->data.frame.sz); + } + } + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); + } + ASSERT_EQ(frames.size(), static_cast(kFrames)); + + // Truncate frame 1 so that only a single byte of the second token partition + // remains. The first token partition (used by the main thread) is left + // intact. + { + std::vector &f = frames[1]; + ASSERT_GT(f.size(), 10u); + const size_t first_part_sz = + (static_cast(f[0]) | (static_cast(f[1]) << 8) | + (static_cast(f[2]) << 16)) >> + 5; + const size_t part_sizes = 10 + first_part_sz; + ASSERT_LT(part_sizes + 3, f.size()); + const size_t part0_sz = static_cast(f[part_sizes]) | + (static_cast(f[part_sizes + 1]) << 8) | + (static_cast(f[part_sizes + 2]) << 16); + const size_t part1_start = part_sizes + 3 + part0_sz; + ASSERT_LT(part1_start, f.size()); + f.resize(part1_start + 1); + } + + vpx_codec_ctx_t dec; + vpx_codec_dec_cfg_t dec_cfg = { /*threads=*/4, /*w=*/0, /*h=*/0 }; + ASSERT_EQ(vpx_codec_dec_init(&dec, &vpx_codec_vp8_dx_algo, &dec_cfg, 0), + VPX_CODEC_OK); + for (int i = 0; i < kFrames; ++i) { + const vpx_codec_err_t res = vpx_codec_decode( + &dec, frames[i].data(), static_cast(frames[i].size()), + /*user_priv=*/nullptr, /*deadline=*/0); + vpx_codec_iter_t iter = nullptr; + const vpx_image_t *img = vpx_codec_get_frame(&dec, &iter); + if (i == 1) { + EXPECT_EQ(res, VPX_CODEC_CORRUPT_FRAME); + EXPECT_EQ(img, nullptr); + continue; + } + EXPECT_EQ(res, VPX_CODEC_OK) + << "frame " << i << ": " << vpx_codec_error_detail(&dec); + EXPECT_NE(img, nullptr) << "frame " << i; + int corrupted = -1; + EXPECT_EQ(vpx_codec_control(&dec, VP8D_GET_FRAME_CORRUPTED, &corrupted), + VPX_CODEC_OK); + EXPECT_EQ(corrupted, 0) << "frame " << i; + } + EXPECT_EQ(vpx_codec_destroy(&dec), VPX_CODEC_OK); +} +#endif // CONFIG_VP8_ENCODER && CONFIG_MULTITHREAD + +#if CONFIG_MULTITHREAD && defined(__linux__) +// Issue: 571147583 +// Verifies that when restarting decode threads fails on a keyframe with a new +// resolution, the cached dimensions (ctx->si.w, ctx->si.h) are cleared so a +// subsequent decode triggers a resolution change and reallocates frame buffers. +TEST(DecodeAPI, Vp8MultiThreadedRestartResolutionChange) { + // Minimal 2-partition VP8 keyframe buffer (first partition = 256 bytes). + std::vector frame(1500, 0); + frame[0] = 0x10; + frame[1] = 0x20; + frame[3] = 0x9d; + frame[4] = 0x01; + frame[5] = 0x2a; + frame[6] = 0x00; // width = 256 + frame[7] = 0x01; + frame[8] = 0x00; // height = 256 + frame[9] = 0x01; + frame[10] = 0x0f; // 2 token partitions + frame[11] = 0xc1; + frame[12] = 0x28; + frame[266] = 0x58; // token partition 0 size = 600 + frame[267] = 0x02; + + vpx_codec_ctx_t dec; + vpx_codec_dec_cfg_t cfg = { /*threads=*/2, /*w=*/0, /*h=*/0 }; + ASSERT_EQ(vpx_codec_dec_init(&dec, &vpx_codec_vp8_dx_algo, &cfg, 0), + VPX_CODEC_OK); + + // Frame 0: valid 256x256 keyframe initializes 256x256 frame buffers + // (yv12_fb_new->y_width = 256, pc->Width = 256) and worker threads. + ASSERT_EQ( + vpx_codec_decode(&dec, frame.data(), + static_cast(frame.size()), nullptr, 0), + VPX_CODEC_OK); + + // Frame 1: truncate token partition 0 to 1 byte so the worker thread fails in + // vp8mt_decode_mb_rows(), shutting down threads and setting + // ctx->restart_threads = 1. + frame[266] = 1; + frame[267] = 0; + EXPECT_EQ( + vpx_codec_decode(&dec, frame.data(), + static_cast(frame.size()), nullptr, 0), + VPX_CODEC_CORRUPT_FRAME); + + // Change keyframe header to 16x64. In each iteration: + // 1. Set RLIMIT_NPROC = 0 so pthread_create fails inside restart_threads and + // vpx_codec_decode returns VPX_CODEC_ERROR after vp8_peek_si_internal() + // has updated ctx->si.w = 16, ctx->si.h = 64. + // 2. Restore RLIMIT_NPROC and decode again so restart_threads succeeds and + // allocates mt_yabove_row for pc->Width. + // + // Without the fix: + // - ctx->si.w = 16, ctx->si.h = 64 remain cached after step 1, so step 2 + // sees resolution_change == 0 and skips vp8_alloc_frame_buffers() + // (leaving yv12_fb_new->y_width = 256). + // - In iteration 0 step 2, vp8_decode_frame() sets pc->Width = 16 from the + // keyframe header before failing on the truncated token partition + // (setting ctx->restart_threads = 1 again). + // - In iteration 1 step 2, restart_threads allocates mt_yabove_row for + // pc->Width = 16 (103 bytes) while yv12_fb_new->y_width is still 256, + // causing a 261-byte write (heap-buffer-overflow) in + // vp8mt_decode_mb_rows(). + // + // With the fix: + // - Step 1 clears ctx->si.w = 0, ctx->si.h = 0 on thread restart failure. + // - Step 2 detects resolution_change == 1, reallocates frame buffers to + // 16x64, and cleanly returns VPX_CODEC_CORRUPT_FRAME on the truncated + // partition. + frame[6] = 16; + frame[7] = 0; + frame[8] = 64; + frame[9] = 0; + struct rlimit old_lim; + ASSERT_EQ(getrlimit(RLIMIT_NPROC, &old_lim), 0); + const struct rlimit zero_lim = { 0, old_lim.rlim_max }; + for (int i = 0; i < 2; ++i) { + ASSERT_EQ(setrlimit(RLIMIT_NPROC, &zero_lim), 0); + const vpx_codec_err_t res = + vpx_codec_decode(&dec, frame.data(), + static_cast(frame.size()), nullptr, 0); + ASSERT_EQ(setrlimit(RLIMIT_NPROC, &old_lim), 0); + EXPECT_EQ(res, VPX_CODEC_ERROR); + + EXPECT_EQ( + vpx_codec_decode(&dec, frame.data(), + static_cast(frame.size()), nullptr, 0), + VPX_CODEC_CORRUPT_FRAME); + } + + EXPECT_EQ(vpx_codec_destroy(&dec), VPX_CODEC_OK); +} +#endif // CONFIG_MULTITHREAD && defined(__linux__) #endif // CONFIG_VP8_DECODER #if CONFIG_VP9_DECODER @@ -120,7 +494,7 @@ void TestVp9Controls(vpx_codec_ctx_t *dec) { } TEST(DecodeAPI, Vp9InvalidDecode) { - const vpx_codec_iface_t *const codec = &vpx_codec_vp9_dx_algo; + vpx_codec_iface_t *const codec = &vpx_codec_vp9_dx_algo; const char filename[] = "invalid-vp90-2-00-quantizer-00.webm.ivf.s5861_r01-05_b6-.v2.ivf"; libvpx_test::IVFVideoSource video(filename); @@ -147,7 +521,7 @@ TEST(DecodeAPI, Vp9InvalidDecode) { void TestPeekInfo(const uint8_t *const data, uint32_t data_sz, uint32_t peek_size) { - const vpx_codec_iface_t *const codec = &vpx_codec_vp9_dx_algo; + vpx_codec_iface_t *const codec = &vpx_codec_vp9_dx_algo; // Verify behavior of vpx_codec_decode. vpx_codec_decode doesn't even get // to decoder_peek_si_internal on frames of size < 8. if (data_sz >= 8) { @@ -193,6 +567,49 @@ TEST(DecodeAPI, Vp9PeekStreamInfoTruncated) { TestPeekInfo(profile1_data, data_sz, 11); } } + +TEST(DecodeAPI, Buganizer499206650) { + vpx_codec_ctx_t dec; + ASSERT_EQ(vpx_codec_dec_init(&dec, vpx_codec_vp9_dx(), /*cfg=*/nullptr, + /*flags=*/0), + VPX_CODEC_OK); + + // Frame 1: VP9 intra_only, profile 0, 8x8, error_resilient=1, + // refresh_frame_flags=0x00. Clears need_resync without updating ref slots. + static constexpr std::array frame1 = { + 0x85, 0xa4, 0xc1, 0xa1, 0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x40, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + EXPECT_EQ(vpx_codec_decode(&dec, frame1.data(), + static_cast(frame1.size()), + /*user_priv=*/nullptr, /*deadline=*/0), + VPX_CODEC_OK) + << vpx_codec_error_detail(&dec); + + vpx_codec_iter_t it = nullptr; + while (vpx_codec_get_frame(&dec, &it)) { + } + + // Frame 2: VP9 inter, profile 0, show_frame=1, error_resilient=1, + // refresh=0xFF, references slot 0 (ref_frame_map[0] == -1). + static constexpr std::array frame2 = { + 0x87, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + // Ensure there is no out of bounds read using the invalid index and that the + // decoder reports an error. + EXPECT_EQ(vpx_codec_decode(&dec, frame2.data(), + static_cast(frame2.size()), + /*user_priv=*/nullptr, /*deadline=*/0), + VPX_CODEC_CORRUPT_FRAME); + + EXPECT_EQ(vpx_codec_destroy(&dec), VPX_CODEC_OK); +} #endif // CONFIG_VP9_DECODER TEST(DecodeAPI, HighBitDepthCapability) { @@ -212,4 +629,54 @@ TEST(DecodeAPI, HighBitDepthCapability) { #endif } +#if CONFIG_VP8_DECODER +TEST(DecodeAPI, SetReferenceValidationVp8) { + vpx_codec_ctx_t dec; + ASSERT_EQ(vpx_codec_dec_init(&dec, vpx_codec_vp8_dx(), nullptr, 0), + VPX_CODEC_OK); + + vpx_image_t ref_img; + ASSERT_NE(vpx_img_alloc(&ref_img, VPX_IMG_FMT_I420, 64, 64, 1), nullptr); + + for (const int plane : { VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V }) { + vpx_ref_frame_t ref_frame; + ref_frame.frame_type = VP8_LAST_FRAME; + ref_frame.img = ref_img; + ref_frame.img.planes[plane] = nullptr; + EXPECT_EQ(vpx_codec_control(&dec, VP8_SET_REFERENCE, &ref_frame), + VPX_CODEC_INVALID_PARAM); + EXPECT_EQ(vpx_codec_control(&dec, VP8_COPY_REFERENCE, &ref_frame), + VPX_CODEC_INVALID_PARAM); + } + + vpx_img_free(&ref_img); + EXPECT_EQ(vpx_codec_destroy(&dec), VPX_CODEC_OK); +} +#endif // CONFIG_VP8_DECODER + +#if CONFIG_VP9_DECODER +TEST(DecodeAPI, SetReferenceValidationVp9) { + vpx_codec_ctx_t dec; + ASSERT_EQ(vpx_codec_dec_init(&dec, vpx_codec_vp9_dx(), nullptr, 0), + VPX_CODEC_OK); + + vpx_image_t ref_img; + ASSERT_NE(vpx_img_alloc(&ref_img, VPX_IMG_FMT_I420, 64, 64, 1), nullptr); + + for (const int plane : { VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V }) { + vpx_ref_frame_t ref_frame; + ref_frame.frame_type = VP8_LAST_FRAME; + ref_frame.img = ref_img; + ref_frame.img.planes[plane] = nullptr; + EXPECT_EQ(vpx_codec_control(&dec, VP8_SET_REFERENCE, &ref_frame), + VPX_CODEC_INVALID_PARAM); + EXPECT_EQ(vpx_codec_control(&dec, VP8_COPY_REFERENCE, &ref_frame), + VPX_CODEC_INVALID_PARAM); + } + + vpx_img_free(&ref_img); + EXPECT_EQ(vpx_codec_destroy(&dec), VPX_CODEC_OK); +} +#endif // CONFIG_VP9_DECODER + } // namespace diff --git a/libs/libvpx/test/decode_corrupted.cc b/libs/libvpx/test/decode_corrupted.cc index 31e1da69cc..55919d0f49 100644 --- a/libs/libvpx/test/decode_corrupted.cc +++ b/libs/libvpx/test/decode_corrupted.cc @@ -10,12 +10,13 @@ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/util.h" #include "test/i420_video_source.h" +#include "vpx_config.h" #include "vpx_mem/vpx_mem.h" namespace { @@ -28,9 +29,9 @@ class DecodeCorruptedFrameTest DecodeCorruptedFrameTest() : EncoderTest(GET_PARAM(0)) {} protected: - virtual ~DecodeCorruptedFrameTest() {} + ~DecodeCorruptedFrameTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); cfg_.g_lag_in_frames = 0; @@ -44,21 +45,21 @@ class DecodeCorruptedFrameTest dec_cfg_.threads = 1; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) encoder->Control(VP8E_SET_CPUUSED, 7); } - virtual void MismatchHook(const vpx_image_t * /*img1*/, - const vpx_image_t * /*img2*/) {} + void MismatchHook(const vpx_image_t * /*img1*/, + const vpx_image_t * /*img2*/) override {} - virtual const vpx_codec_cx_pkt_t *MutateEncoderOutputHook( - const vpx_codec_cx_pkt_t *pkt) { + const vpx_codec_cx_pkt_t *MutateEncoderOutputHook( + const vpx_codec_cx_pkt_t *pkt) override { // Don't edit frame packet on key frame. if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) return pkt; if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) return pkt; - memcpy(&modified_pkt_, pkt, sizeof(*pkt)); + modified_pkt_ = *pkt; // Halve the size so it's corrupted to decoder. modified_pkt_.data.frame.sz = modified_pkt_.data.frame.sz / 2; @@ -66,9 +67,9 @@ class DecodeCorruptedFrameTest return &modified_pkt_; } - virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec, - const libvpx_test::VideoSource & /*video*/, - libvpx_test::Decoder *decoder) { + bool HandleDecodeResult(const vpx_codec_err_t res_dec, + const libvpx_test::VideoSource & /*video*/, + libvpx_test::Decoder *decoder) override { EXPECT_NE(res_dec, VPX_CODEC_MEM_ERROR) << decoder->DecodeError(); return VPX_CODEC_MEM_ERROR != res_dec; } diff --git a/libs/libvpx/test/decode_perf_test.cc b/libs/libvpx/test/decode_perf_test.cc index e07a667440..69c30a9e80 100644 --- a/libs/libvpx/test/decode_perf_test.cc +++ b/libs/libvpx/test/decode_perf_test.cc @@ -19,9 +19,9 @@ #include "test/md5_helper.h" #include "test/util.h" #include "test/webm_video_source.h" +#include "vpx/vpx_codec.h" #include "vpx_ports/vpx_timer.h" #include "./ivfenc.h" -#include "./vpx_version.h" using std::make_tuple; @@ -36,7 +36,7 @@ const char kNewEncodeOutputFile[] = "new_encode.ivf"; /* DecodePerfTest takes a tuple of filename + number of threads to decode with */ -typedef std::tuple DecodePerfParam; +using DecodePerfParam = std::tuple; const DecodePerfParam kVP9DecodePerfVectors[] = { make_tuple("vp90-2-bbb_426x240_tile_1x1_180kbps.webm", 1), @@ -98,7 +98,7 @@ TEST_P(DecodePerfTest, PerfTest) { printf("{\n"); printf("\t\"type\" : \"decode_perf_test\",\n"); - printf("\t\"version\" : \"%s\",\n", VERSION_STRING_NOSP); + printf("\t\"version\" : \"%s\",\n", vpx_codec_version_str()); printf("\t\"videoName\" : \"%s\",\n", video_name); printf("\t\"threadCount\" : %u,\n", threads); printf("\t\"decodeTimeSecs\" : %f,\n", elapsed_secs); @@ -116,11 +116,11 @@ class VP9NewEncodeDecodePerfTest protected: VP9NewEncodeDecodePerfTest() : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), speed_(0), - outfile_(0), out_frames_(0) {} + outfile_(nullptr), out_frames_(0) {} - virtual ~VP9NewEncodeDecodePerfTest() {} + ~VP9NewEncodeDecodePerfTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(encoding_mode_); @@ -137,8 +137,8 @@ class VP9NewEncodeDecodePerfTest cfg_.rc_end_usage = VPX_VBR; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, speed_); encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1); @@ -146,14 +146,14 @@ class VP9NewEncodeDecodePerfTest } } - virtual void BeginPassHook(unsigned int /*pass*/) { + void BeginPassHook(unsigned int /*pass*/) override { const std::string data_path = getenv("LIBVPX_TEST_DATA_PATH"); const std::string path_to_source = data_path + "/" + kNewEncodeOutputFile; outfile_ = fopen(path_to_source.c_str(), "wb"); ASSERT_NE(outfile_, nullptr); } - virtual void EndPassHook() { + void EndPassHook() override { if (outfile_ != nullptr) { if (!fseek(outfile_, 0, SEEK_SET)) { ivf_write_file_header(outfile_, &cfg_, VP9_FOURCC, out_frames_); @@ -163,7 +163,7 @@ class VP9NewEncodeDecodePerfTest } } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { ++out_frames_; // Write initial file header if first frame. @@ -177,7 +177,7 @@ class VP9NewEncodeDecodePerfTest pkt->data.frame.sz); } - virtual bool DoDecode() const { return false; } + bool DoDecode() const override { return false; } void set_speed(unsigned int speed) { speed_ = speed; } @@ -249,7 +249,7 @@ TEST_P(VP9NewEncodeDecodePerfTest, PerfTest) { printf("{\n"); printf("\t\"type\" : \"decode_perf_test\",\n"); - printf("\t\"version\" : \"%s\",\n", VERSION_STRING_NOSP); + printf("\t\"version\" : \"%s\",\n", vpx_codec_version_str()); printf("\t\"videoName\" : \"%s\",\n", kNewEncodeOutputFile); printf("\t\"threadCount\" : %u,\n", threads); printf("\t\"decodeTimeSecs\" : %f,\n", elapsed_secs); diff --git a/libs/libvpx/test/decode_svc_test.cc b/libs/libvpx/test/decode_svc_test.cc index ec9935da79..7098e7b270 100644 --- a/libs/libvpx/test/decode_svc_test.cc +++ b/libs/libvpx/test/decode_svc_test.cc @@ -25,17 +25,16 @@ class DecodeSvcTest : public ::libvpx_test::DecoderTest, public ::libvpx_test::CodecTestWithParam { protected: DecodeSvcTest() : DecoderTest(GET_PARAM(::libvpx_test::kCodecFactoryParam)) {} - virtual ~DecodeSvcTest() {} + ~DecodeSvcTest() override = default; - virtual void PreDecodeFrameHook( - const libvpx_test::CompressedVideoSource &video, - libvpx_test::Decoder *decoder) { + void PreDecodeFrameHook(const libvpx_test::CompressedVideoSource &video, + libvpx_test::Decoder *decoder) override { if (video.frame_number() == 0) decoder->Control(VP9_DECODE_SVC_SPATIAL_LAYER, spatial_layer_); } - virtual void DecompressedFrameHook(const vpx_image_t &img, - const unsigned int frame_number) { + void DecompressedFrameHook(const vpx_image_t &img, + const unsigned int frame_number) override { ASSERT_EQ(img.d_w, width_); ASSERT_EQ(img.d_h, height_); total_frames_ = frame_number; diff --git a/libs/libvpx/test/decode_test_driver.cc b/libs/libvpx/test/decode_test_driver.cc index 773d673d37..af87bc25fb 100644 --- a/libs/libvpx/test/decode_test_driver.cc +++ b/libs/libvpx/test/decode_test_driver.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/decode_test_driver.h" @@ -111,7 +111,7 @@ void DecoderTest::RunLoop(CompressedVideoSource *video) { } void DecoderTest::set_cfg(const vpx_codec_dec_cfg_t &dec_cfg) { - memcpy(&cfg_, &dec_cfg, sizeof(cfg_)); + cfg_ = dec_cfg; } void DecoderTest::set_flags(const vpx_codec_flags_t flags) { flags_ = flags; } diff --git a/libs/libvpx/test/decode_test_driver.h b/libs/libvpx/test/decode_test_driver.h index f446ab4664..81f5001ebc 100644 --- a/libs/libvpx/test/decode_test_driver.h +++ b/libs/libvpx/test/decode_test_driver.h @@ -11,7 +11,7 @@ #ifndef VPX_TEST_DECODE_TEST_DRIVER_H_ #define VPX_TEST_DECODE_TEST_DRIVER_H_ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "vpx/vpx_decoder.h" diff --git a/libs/libvpx/test/encode_api_test.cc b/libs/libvpx/test/encode_api_test.cc index 6f61c77502..9f00cf77c6 100644 --- a/libs/libvpx/test/encode_api_test.cc +++ b/libs/libvpx/test/encode_api_test.cc @@ -8,20 +8,39 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include +#include +#include #include +#include +#include +#include #include #include +#include +#include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" +#include "test/acm_random.h" +#include "test/video_source.h" +#include "test/y4m_video_source.h" +#include "test/yuv_video_source.h" #include "./vpx_config.h" -#include "test/video_source.h" #include "vpx/vp8cx.h" +#include "vpx/vpx_codec.h" #include "vpx/vpx_encoder.h" +#include "vpx/vpx_image.h" +#include "vpx_mem/vpx_mem.h" + +#if CONFIG_VP9_ENCODER +#include "vp9/encoder/vp9_encoder.h" +#include "vp9/encoder/vp9_firstpass_stats.h" +#endif namespace { -const vpx_codec_iface_t *kCodecIfaces[] = { +vpx_codec_iface_t *kCodecIfaces[] = { #if CONFIG_VP8_ENCODER &vpx_codec_vp8_cx_algo, #endif @@ -30,12 +49,94 @@ const vpx_codec_iface_t *kCodecIfaces[] = { #endif }; -bool IsVP9(const vpx_codec_iface_t *iface) { +bool IsVP9(vpx_codec_iface_t *iface) { static const char kVP9Name[] = "WebM Project VP9"; return strncmp(kVP9Name, vpx_codec_iface_name(iface), sizeof(kVP9Name) - 1) == 0; } +void *Memset16(void *dest, int val, size_t length) { + uint16_t *dest16 = reinterpret_cast(dest); + for (size_t i = 0; i < length; i++) { + *dest16++ = val; + } + return dest; +} + +vpx_image_t *CreateImage(vpx_bit_depth_t bit_depth, vpx_img_fmt_t fmt, + unsigned int width, unsigned int height, + libvpx_test::ACMRandom *rng = nullptr) { + assert(fmt != VPX_IMG_FMT_NV12); + if (bit_depth > VPX_BITS_8) { + fmt = static_cast(fmt | VPX_IMG_FMT_HIGHBITDEPTH); + } + vpx_image_t *image = vpx_img_alloc(nullptr, fmt, width, height, 1); + if (!image) return image; + + auto get_val = [bit_depth, &rng]() { + if (rng != nullptr) { + switch (bit_depth) { + case VPX_BITS_8: return static_cast(rng->Rand8()); + case VPX_BITS_10: return static_cast(rng->Rand10()); + case VPX_BITS_12: return static_cast(rng->Rand12()); + } + } + return 1 << (bit_depth - 1); + }; + const int val_y = get_val(); + const int val_u = get_val(); + const int val_v = get_val(); + const unsigned int uv_h = + (image->d_h + image->y_chroma_shift) >> image->y_chroma_shift; + const unsigned int uv_w = + (image->d_w + image->x_chroma_shift) >> image->x_chroma_shift; + if (bit_depth > VPX_BITS_8) { + for (unsigned int i = 0; i < image->d_h; ++i) { + Memset16(image->planes[0] + i * image->stride[0], val_y, image->d_w); + } + for (unsigned int i = 0; i < uv_h; ++i) { + Memset16(image->planes[1] + i * image->stride[1], val_u, uv_w); + Memset16(image->planes[2] + i * image->stride[2], val_v, uv_w); + } + } else { + for (unsigned int i = 0; i < image->d_h; ++i) { + memset(image->planes[0] + i * image->stride[0], val_y, image->d_w); + } + for (unsigned int i = 0; i < uv_h; ++i) { + memset(image->planes[1] + i * image->stride[1], val_u, uv_w); + memset(image->planes[2] + i * image->stride[2], val_v, uv_w); + } + } + + return image; +} + +void InitCodec(vpx_codec_iface_t &iface, int width, int height, + vpx_codec_ctx_t *enc, vpx_codec_enc_cfg_t *cfg) { + cfg->g_w = width; + cfg->g_h = height; + cfg->g_lag_in_frames = 0; + cfg->g_pass = VPX_RC_ONE_PASS; + ASSERT_EQ(vpx_codec_enc_init(enc, &iface, cfg, 0), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control_(enc, VP8E_SET_CPUUSED, 2), VPX_CODEC_OK); +} + +// Encodes 1 frame of size |cfg.g_w| x |cfg.g_h| setting |enc|'s configuration +// to |cfg|. +void EncodeWithConfig(const vpx_codec_enc_cfg_t &cfg, vpx_codec_ctx_t *enc) { + libvpx_test::DummyVideoSource video; + video.SetSize(cfg.g_w, cfg.g_h); + video.Begin(); + EXPECT_EQ(vpx_codec_enc_config_set(enc, &cfg), VPX_CODEC_OK) + << vpx_codec_error_detail(enc); + + EXPECT_EQ(vpx_codec_encode(enc, video.img(), video.pts(), video.duration(), + /*flags=*/0, VPX_DL_GOOD_QUALITY), + VPX_CODEC_OK) + << vpx_codec_error_detail(enc); +} + TEST(EncodeAPI, InvalidParams) { uint8_t buf[1] = { 0 }; vpx_image_t img; @@ -76,6 +177,190 @@ TEST(EncodeAPI, InvalidParams) { } } +TEST(EncodeAPI, InvalidUVStrides) { + static const std::vector kVp8ImageFormats = { + VPX_IMG_FMT_YV12, VPX_IMG_FMT_I420, VPX_IMG_FMT_NV12 + }; + static const std::vector kVp9ImageFormats = { + VPX_IMG_FMT_YV12, VPX_IMG_FMT_I420, VPX_IMG_FMT_I422, + VPX_IMG_FMT_I444, VPX_IMG_FMT_I440, VPX_IMG_FMT_NV12, + VPX_IMG_FMT_I42016, VPX_IMG_FMT_I42216, VPX_IMG_FMT_I44416, + VPX_IMG_FMT_I44016 + }; + struct UVStride { + int u_stride; + int v_stride; + }; + constexpr int kWidth = 64; + constexpr int kHeight = 64; + static constexpr std::array kUVStrides = { + UVStride{ kWidth, kWidth - 1 }, UVStride{ kWidth, kWidth + 1 }, + UVStride{ kWidth - 1, kWidth }, UVStride{ kWidth + 1, kWidth } + }; + vpx_image_t img; + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + // Allocate a buffer large enough for a non-subsampled, high bitdepth image. + auto buf = std::make_unique(kWidth * kHeight * 3 * 2); + + for (const auto *iface : kCodecIfaces) { + SCOPED_TRACE(vpx_codec_iface_name(iface)); + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, /*usage=*/0), + VPX_CODEC_OK); + + for (const auto img_fmt : + IsVP9(iface) ? kVp9ImageFormats : kVp8ImageFormats) { + const bool high_bit_depth = + (img_fmt & VPX_IMG_FMT_HIGHBITDEPTH) == VPX_IMG_FMT_HIGHBITDEPTH; + if (high_bit_depth && + !(vpx_codec_get_caps(iface) & VPX_CODEC_CAP_HIGHBITDEPTH)) { + break; + } + ASSERT_EQ(vpx_img_wrap(&img, img_fmt, kWidth, kHeight, /*stride_align=*/1, + buf.get()), + &img) + << "Unable to wrap vpx_image for format: " << img_fmt; + const bool is_420 = img.x_chroma_shift == 1 && img.y_chroma_shift == 1; + // In profiles 0 and 2, only 4:2:0 format is allowed. In profiles 1 and 3, + // all other subsampling formats are allowed. In profiles 0 and 1, only + // bit depth 8 is allowed. In profiles 2 and 3, only bit depths 10 and 12 + // are allowed. + cfg.g_profile = 2 * high_bit_depth + !is_420; + cfg.g_w = kWidth; + cfg.g_h = kHeight; + cfg.g_bit_depth = high_bit_depth ? VPX_BITS_10 : VPX_BITS_8; + ASSERT_EQ( + vpx_codec_enc_init(&enc, iface, &cfg, + high_bit_depth ? VPX_CODEC_USE_HIGHBITDEPTH : 0), + VPX_CODEC_OK) + << " high_bit_depth: " << high_bit_depth; + + for (const auto uv_stride : kUVStrides) { + const UVStride orig = { img.stride[VPX_PLANE_U], + img.stride[VPX_PLANE_V] }; + img.stride[VPX_PLANE_U] = uv_stride.u_stride; + img.stride[VPX_PLANE_V] = uv_stride.v_stride; + EXPECT_EQ(vpx_codec_encode(&enc, &img, /*pts=*/0, /*duration=*/1, + /*flags=*/0, VPX_DL_REALTIME), + VPX_CODEC_INVALID_PARAM) + << "Error: " << vpx_codec_error_detail(&enc) + << ", format: " << img_fmt << ", U stride: " << uv_stride.u_stride + << ", V stride: " << uv_stride.v_stride; + + // Ensure the encoder can recover when given valid strides. + img.stride[VPX_PLANE_U] = orig.u_stride; + img.stride[VPX_PLANE_V] = orig.v_stride; + EXPECT_EQ(vpx_codec_encode(&enc, &img, /*pts=*/0, /*duration=*/1, + /*flags=*/0, VPX_DL_REALTIME), + VPX_CODEC_OK) + << "Error: " << vpx_codec_error_detail(&enc) + << ", format: " << img_fmt << ", U stride: " << orig.u_stride + << ", V stride: " << orig.v_stride; + } + + EXPECT_EQ( + vpx_codec_encode(&enc, /*img=*/nullptr, /*pts=*/0, /*duration=*/0, + /*flags=*/0, VPX_DL_REALTIME), + VPX_CODEC_OK); + EXPECT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); + } + } +} + +#if CONFIG_VP9_ENCODER +// Encodes one 64x64 I420 frame. With high_bit_depth the image is I42016 +// (10-bit, profile 2) and the encoder is initialized with +// VPX_CODEC_USE_HIGHBITDEPTH. With flip the image is flipped with +// vpx_img_flip() before being passed to the encoder. +static void EncodeImageVp9(bool high_bit_depth, bool flip) { + constexpr int kWidth = 64; + constexpr int kHeight = 64; + + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(vpx_codec_vp9_cx(), &cfg, /*usage=*/0), + VPX_CODEC_OK); + cfg.g_profile = high_bit_depth ? 2 : 0; + cfg.g_w = kWidth; + cfg.g_h = kHeight; + cfg.g_lag_in_frames = 0; + if (high_bit_depth) cfg.g_bit_depth = VPX_BITS_10; + ASSERT_EQ(vpx_codec_enc_init(&enc, vpx_codec_vp9_cx(), &cfg, + high_bit_depth ? VPX_CODEC_USE_HIGHBITDEPTH : 0), + VPX_CODEC_OK); + + vpx_image_t *const img = vpx_img_alloc( + nullptr, high_bit_depth ? VPX_IMG_FMT_I42016 : VPX_IMG_FMT_I420, kWidth, + kHeight, 32); + ASSERT_NE(img, nullptr); + for (int plane = 0; plane < 3; ++plane) { + const int w = plane ? kWidth >> 1 : kWidth; + const int h = plane ? kHeight >> 1 : kHeight; + uint8_t *row = img->planes[plane]; + for (int y = 0; y < h; ++y) { + for (int x = 0; x < w; ++x) { + if (high_bit_depth) { + reinterpret_cast(row)[x] = + static_cast((x * 7 + y * 13) & 1023); + } else { + row[x] = static_cast((x * 7 + y * 13) & 255); + } + } + row += img->stride[plane]; + } + } + if (flip) vpx_img_flip(img); + + ASSERT_EQ(vpx_codec_encode(&enc, img, /*pts=*/0, /*duration=*/1, /*flags=*/0, + VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_codec_iter_t iter = nullptr; + while (vpx_codec_get_cx_data(&enc, &iter) != nullptr) { + } + + vpx_img_free(img); + EXPECT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +#if CONFIG_VP9_HIGHBITDEPTH +// vpx_img_flip() negates the image strides. The high bit-depth input +// validation used an unsigned stride, so with a flipped image the source +// pointer stepped far out of the allocation on the first row. Encoding a +// flipped image must succeed. +TEST(EncodeAPI, HighBitDepthFlippedImageVp9) { + EncodeImageVp9(/*high_bit_depth=*/true, /*flip=*/true); +} + +// Non-flipped high bit-depth images must keep working. +TEST(EncodeAPI, HighBitDepthImageVp9) { + EncodeImageVp9(/*high_bit_depth=*/true, /*flip=*/false); +} +#endif // CONFIG_VP9_HIGHBITDEPTH + +// Flipped 8-bit images must keep working. +TEST(EncodeAPI, FlippedImageVp9) { + EncodeImageVp9(/*high_bit_depth=*/false, /*flip=*/true); +} +#endif // CONFIG_VP9_ENCODER + +TEST(EncodeAPI, InvalidImageFormats) { + EXPECT_EQ(vpx_img_alloc(/*img=*/nullptr, VPX_IMG_FMT_NONE, /*d_w=*/32, + /*d_h=*/32, /*align=*/1), + nullptr); + EXPECT_EQ(vpx_img_alloc(/*img=*/nullptr, + static_cast(VPX_IMG_FMT_NONE - 1), + /*d_w=*/32, /*d_h=*/32, /*align=*/1), + nullptr); + EXPECT_EQ(vpx_img_alloc(/*img=*/nullptr, + static_cast(VPX_IMG_FMT_NV12 + 1), + /*d_w=*/32, /*d_h=*/32, /*align=*/1), + nullptr); + EXPECT_EQ(vpx_img_alloc(/*img=*/nullptr, + static_cast(VPX_IMG_FMT_I44016 + 1), + /*d_w=*/32, /*d_h=*/32, /*align=*/1), + nullptr); +} + TEST(EncodeAPI, HighBitDepthCapability) { // VP8 should not claim VP9 HBD as a capability. #if CONFIG_VP8_ENCODER @@ -97,12 +382,13 @@ TEST(EncodeAPI, HighBitDepthCapability) { TEST(EncodeAPI, ImageSizeSetting) { const int width = 711; const int height = 360; - const int bps = 12; + const int uv_width = (width + 1) / 2; + const int uv_height = (height + 1) / 2; vpx_image_t img; vpx_codec_ctx_t enc; vpx_codec_enc_cfg_t cfg; uint8_t *img_buf = reinterpret_cast( - calloc(width * height * bps / 8, sizeof(*img_buf))); + calloc(width * height + 2 * uv_width * uv_height, sizeof(*img_buf))); vpx_codec_enc_config_default(vpx_codec_vp8_cx(), &cfg, 0); cfg.g_w = width; @@ -118,7 +404,935 @@ TEST(EncodeAPI, ImageSizeSetting) { vpx_codec_destroy(&enc); } -#endif + +// Verifies the fix for a float-cast-overflow in vp8_change_config(). +// +// Causes cpi->framerate to become the largest possible value (10,000,000) in +// VP8 by setting cfg.g_timebase to 1/10000000 and passing a duration of 1 to +// vpx_codec_encode(). +TEST(EncodeAPI, HugeFramerateVp8) { + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_w = 271; + cfg.g_h = 1080; + cfg.g_timebase.num = 1; + // Largest value (VP8's TICKS_PER_SEC) such that frame duration is nonzero (1 + // tick). + cfg.g_timebase.den = 10000000; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 0; + cfg.rc_end_usage = VPX_CBR; + + vpx_codec_ctx_t enc; + // Before we encode the first frame, cpi->framerate is set to a guess (the + // reciprocal of cfg.g_timebase). If this guess doesn't seem reasonable + // (> 180), cpi->framerate is set to 30. + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, -12), VPX_CODEC_OK); + + vpx_image_t *const image = + vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h, 1); + ASSERT_NE(image, nullptr); + + for (unsigned int i = 0; i < image->d_h; ++i) { + memset(image->planes[0] + i * image->stride[0], 128, image->d_w); + } + const unsigned int uv_h = (image->d_h + 1) / 2; + const unsigned int uv_w = (image->d_w + 1) / 2; + for (unsigned int i = 0; i < uv_h; ++i) { + memset(image->planes[1] + i * image->stride[1], 128, uv_w); + memset(image->planes[2] + i * image->stride[2], 128, uv_w); + } + + // Encode a frame. + // Up to this point cpi->framerate is 30. Now pass a duration of only 1. This + // causes cpi->framerate to become 10,000,000. + ASSERT_EQ(vpx_codec_encode(&enc, image, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Change to the same config. Since cpi->framerate is now huge, when it is + // used to calculate raw_target_rate (bit rate of uncompressed frames), the + // result is likely to overflow an unsigned int. + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +// A test that reproduces https://crbug.com/webm/1831. +TEST(EncodeAPI, RandomPixelsVp8) { + // Initialize libvpx encoder + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.rc_target_bitrate = 2000; + cfg.g_w = 1280; + cfg.g_h = 720; + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + // Generate random frame data and encode + libvpx_test::RandomVideoSource video; + video.SetSize(cfg.g_w, cfg.g_h); + video.SetImageFormat(VPX_IMG_FMT_I420); + video.Begin(); + ASSERT_EQ(vpx_codec_encode(&enc, video.img(), video.pts(), video.duration(), + /*flags=*/0, VPX_DL_BEST_QUALITY), + VPX_CODEC_OK); + + // Destroy libvpx encoder + vpx_codec_destroy(&enc); +} + +// Large static_threshold: issue: 505902433. +TEST(EncodeAPI, LargeStaticThresholdVp8) { + // Initialize libvpx encoder + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.rc_target_bitrate = 2000; + cfg.g_w = 1280; + cfg.g_h = 720; + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, -8), VPX_CODEC_OK); + + // 131071 = 1024 << 7 - 1: max value for static_threshold. + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_STATIC_THRESHOLD, 131072), + VPX_CODEC_INVALID_PARAM); + + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_STATIC_THRESHOLD, 131071), + VPX_CODEC_OK); + + // Generate random frame data and encode + libvpx_test::RandomVideoSource video; + video.SetSize(cfg.g_w, cfg.g_h); + video.SetImageFormat(VPX_IMG_FMT_I420); + video.Begin(); + ASSERT_EQ(vpx_codec_encode(&enc, video.img(), video.pts(), video.duration(), + /*flags=*/0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Destroy libvpx encoder + vpx_codec_destroy(&enc); +} + +TEST(EncodeAPI, ChangeToL1T3AndSetBitrateVp8) { + // Initialize libvpx encoder + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_threads = 1; + cfg.g_profile = 0; + cfg.g_w = 1; + cfg.g_h = 64; + cfg.g_bit_depth = VPX_BITS_8; + cfg.g_input_bit_depth = 8; + cfg.g_timebase.num = 1; + cfg.g_timebase.den = 1000000; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 0; + cfg.rc_dropframe_thresh = 0; // Don't drop frames + cfg.rc_resize_allowed = 0; + cfg.rc_end_usage = VPX_VBR; + cfg.rc_target_bitrate = 10; + cfg.rc_min_quantizer = 2; + cfg.rc_max_quantizer = 58; + cfg.kf_mode = VPX_KF_AUTO; + cfg.kf_min_dist = 0; + cfg.kf_max_dist = 10000; + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, -6), VPX_CODEC_OK); + + // Generate random frame data and encode + uint8_t img[128]; // 1x64 with UV width == 1. + libvpx_test::ACMRandom rng; + for (size_t i = 0; i < sizeof(img); ++i) { + img[i] = rng.Rand8(); + } + vpx_image_t img_wrapper; + ASSERT_EQ( + vpx_img_wrap(&img_wrapper, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h, 1, img), + &img_wrapper); + vpx_enc_frame_flags_t flags = VPX_EFLAG_FORCE_KF; + ASSERT_EQ( + vpx_codec_encode(&enc, &img_wrapper, 0, 500000, flags, VPX_DL_REALTIME), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_encode(&enc, nullptr, -1, 0, 0, 0), VPX_CODEC_OK); + + cfg.rc_target_bitrate = 4294967; + // Set the scalability mode to L1T3. + cfg.ts_number_layers = 3; + cfg.ts_periodicity = 4; + cfg.ts_layer_id[0] = 0; + cfg.ts_layer_id[1] = 2; + cfg.ts_layer_id[2] = 1; + cfg.ts_layer_id[3] = 2; + cfg.ts_rate_decimator[0] = 4; + cfg.ts_rate_decimator[1] = 2; + cfg.ts_rate_decimator[2] = 1; + // Bitrate allocation L0: 50% L1: 20% L2: 30% + cfg.layer_target_bitrate[0] = cfg.ts_target_bitrate[0] = + 50 * cfg.rc_target_bitrate / 100; + cfg.layer_target_bitrate[1] = cfg.ts_target_bitrate[1] = + 70 * cfg.rc_target_bitrate / 100; + cfg.layer_target_bitrate[2] = cfg.ts_target_bitrate[2] = + cfg.rc_target_bitrate; + cfg.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_0212; + cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_TEMPORAL_LAYER_ID, 2), + VPX_CODEC_OK); + + constexpr vpx_enc_frame_flags_t VP8_UPDATE_NOTHING = + VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_LAST; + // Layer 2: only reference last frame, no updates + // It only depends on layer 0 + flags = VP8_UPDATE_NOTHING | VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_GF; + ASSERT_EQ( + vpx_codec_encode(&enc, &img_wrapper, 0, 500000, flags, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Destroy libvpx encoder + vpx_codec_destroy(&enc); +} + +// Bug: 526737981. +TEST(EncodeAPI, SetReferenceSizeValidationVp8) { + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_enc_cfg_t cfg; + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 128; + cfg.g_h = 128; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + vpx_image_t raw; + ASSERT_NE(vpx_img_alloc(&raw, VPX_IMG_FMT_I420, 128, 128, 1), nullptr); + memset(raw.img_data, 128, raw.stride[0] * raw.d_h * 3 / 2); + ASSERT_EQ(vpx_codec_encode(&enc, &raw, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Create a larger reference frame. + vpx_image_t ref_img; + ASSERT_NE(vpx_img_alloc(&ref_img, VPX_IMG_FMT_I420, 256, 256, 1), nullptr); + + vpx_ref_frame_t ref_frame; + ref_frame.frame_type = VP8_LAST_FRAME; + ref_frame.img = ref_img; + + // Setting the reference frame with incorrect size must fail. + EXPECT_EQ(vpx_codec_control(&enc, VP8_SET_REFERENCE, &ref_frame), + VPX_CODEC_INVALID_PARAM); + + // Copying reference frame with incorrect size must also fail. + EXPECT_EQ(vpx_codec_control(&enc, VP8_COPY_REFERENCE, &ref_frame), + VPX_CODEC_INVALID_PARAM); + + vpx_img_free(&raw); + vpx_img_free(&ref_img); + EXPECT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +// Bug: 564326761. +TEST(EncodeAPI, ValidateConfigVp8) { + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_enc_cfg_t default_cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &default_cfg, 0), VPX_CODEC_OK); + + const vpx_rational_t dsf = { 1, 1 }; + vpx_codec_ctx_t enc = {}; + + // Invalid ss_number_layers (0 and > VPX_SS_MAX_LAYERS). + for (const unsigned int layers : { 0U, VPX_SS_MAX_LAYERS + 1U }) { + vpx_codec_enc_cfg_t cfg = default_cfg; + cfg.ss_number_layers = layers; + EXPECT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), + VPX_CODEC_INVALID_PARAM); + EXPECT_EQ(vpx_codec_enc_init_multi(&enc, iface, &cfg, 1, 0, &dsf), + VPX_CODEC_INVALID_PARAM); + } + + // Invalid boost factor denominators (0). + { + vpx_codec_enc_cfg_t cfg = default_cfg; + cfg.kf_frame_max_boost_first_factor.den = 0; + EXPECT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), + VPX_CODEC_INVALID_PARAM); + } + { + vpx_codec_enc_cfg_t cfg = default_cfg; + cfg.kf_max_total_boost_factor.den = 0; + EXPECT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), + VPX_CODEC_INVALID_PARAM); + } + + // Ensure scalar range checks run before dereferencing rc_twopass_stats_in.buf + // when g_pass == VPX_RC_LAST_PASS. + { + uint8_t dummy_buf[1] = { 0 }; + constexpr size_t kDummyStatsSize = 52992; + vpx_codec_enc_cfg_t cfg = default_cfg; + cfg.g_pass = VPX_RC_LAST_PASS; + cfg.ss_number_layers = VPX_SS_MAX_LAYERS + 1; + cfg.rc_twopass_stats_in.buf = dummy_buf; + cfg.rc_twopass_stats_in.sz = kDummyStatsSize; + EXPECT_EQ(vpx_codec_enc_init_multi(&enc, iface, &cfg, 1, 0, &dsf), + VPX_CODEC_INVALID_PARAM); + } +} + +// Bug: 564326909. +TEST(EncodeAPI, SetReferenceValidationVp8) { + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_enc_cfg_t cfg; + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + vpx_image_t *const ref_img = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(ref_img, nullptr); + + for (const int plane : { VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V }) { + vpx_ref_frame_t ref_frame; + ref_frame.frame_type = VP8_LAST_FRAME; + ref_frame.img = *ref_img; + ref_frame.img.planes[plane] = nullptr; + EXPECT_EQ(vpx_codec_control(&enc, VP8_SET_REFERENCE, &ref_frame), + VPX_CODEC_INVALID_PARAM); + EXPECT_EQ(vpx_codec_control(&enc, VP8_COPY_REFERENCE, &ref_frame), + VPX_CODEC_INVALID_PARAM); + } + + vpx_img_free(ref_img); + EXPECT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +// Emulates the WebCodecs VideoEncoder interface. +class VP8Encoder { + public: + explicit VP8Encoder(int speed) : speed_(speed) {} + ~VP8Encoder(); + + void Configure(unsigned int threads, unsigned int width, unsigned int height, + vpx_rc_mode end_usage, vpx_enc_deadline_t deadline); + void Encode(bool key_frame); + + private: + const int speed_; + bool initialized_ = false; + vpx_codec_enc_cfg_t cfg_; + vpx_codec_ctx_t enc_; + int frame_index_ = 0; + vpx_enc_deadline_t deadline_ = 0; +}; + +VP8Encoder::~VP8Encoder() { + if (initialized_) { + EXPECT_EQ(vpx_codec_destroy(&enc_), VPX_CODEC_OK); + } +} + +void VP8Encoder::Configure(unsigned int threads, unsigned int width, + unsigned int height, vpx_rc_mode end_usage, + vpx_enc_deadline_t deadline) { + deadline_ = deadline; + + if (!initialized_) { + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg_, /*usage=*/0), + VPX_CODEC_OK); + cfg_.g_threads = threads; + cfg_.g_w = width; + cfg_.g_h = height; + cfg_.g_timebase.num = 1; + cfg_.g_timebase.den = 1000 * 1000; // microseconds + cfg_.g_pass = VPX_RC_ONE_PASS; + cfg_.g_lag_in_frames = 0; + cfg_.rc_end_usage = end_usage; + cfg_.rc_min_quantizer = 2; + cfg_.rc_max_quantizer = 58; + ASSERT_EQ(vpx_codec_enc_init(&enc_, iface, &cfg_, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc_, VP8E_SET_CPUUSED, speed_), VPX_CODEC_OK); + initialized_ = true; + return; + } + + cfg_.g_threads = threads; + cfg_.g_w = width; + cfg_.g_h = height; + cfg_.rc_end_usage = end_usage; + ASSERT_EQ(vpx_codec_enc_config_set(&enc_, &cfg_), VPX_CODEC_OK) + << vpx_codec_error_detail(&enc_); +} + +void VP8Encoder::Encode(bool key_frame) { + assert(initialized_); + const vpx_codec_cx_pkt_t *pkt; + vpx_image_t *image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg_.g_w, cfg_.g_h); + ASSERT_NE(image, nullptr); + const vpx_enc_frame_flags_t flags = key_frame ? VPX_EFLAG_FORCE_KF : 0; + ASSERT_EQ(vpx_codec_encode(&enc_, image, frame_index_, 1, flags, deadline_), + VPX_CODEC_OK); + ++frame_index_; + vpx_codec_iter_t iter = nullptr; + while ((pkt = vpx_codec_get_cx_data(&enc_, &iter)) != nullptr) { + ASSERT_EQ(pkt->kind, VPX_CODEC_CX_FRAME_PKT); + if (key_frame) { + ASSERT_EQ(pkt->data.frame.flags & VPX_FRAME_IS_KEY, VPX_FRAME_IS_KEY); + } + } + vpx_img_free(image); +} + +// This is the reproducer testcase for crbug.com/324459561. However, +// just running this test is not enough to reproduce the bug. We also +// need to send signals to the test. +TEST(EncodeAPI, Chromium324459561) { + VP8Encoder encoder(-12); + + encoder.Configure(11, 1685, 652, VPX_CBR, VPX_DL_REALTIME); + + encoder.Encode(true); + encoder.Encode(true); + encoder.Encode(true); + + encoder.Configure(0, 1685, 1, VPX_VBR, VPX_DL_REALTIME); +} + +TEST(EncodeAPI, VP8GlobalHeaders) { + constexpr int kWidth = 320; + constexpr int kHeight = 240; + + vpx_codec_enc_cfg_t cfg = {}; + struct Encoder { + ~Encoder() { EXPECT_EQ(vpx_codec_destroy(&ctx), VPX_CODEC_OK); } + vpx_codec_ctx_t ctx = {}; + } enc; + + ASSERT_EQ(vpx_codec_enc_config_default(vpx_codec_vp8_cx(), &cfg, 0), + VPX_CODEC_OK); + ASSERT_NO_FATAL_FAILURE( + InitCodec(*vpx_codec_vp8_cx(), kWidth, kHeight, &enc.ctx, &cfg)); + EXPECT_EQ(vpx_codec_get_global_headers(&enc.ctx), nullptr); + EXPECT_NO_FATAL_FAILURE(EncodeWithConfig(cfg, &enc.ctx)); + EXPECT_EQ(vpx_codec_get_global_headers(&enc.ctx), nullptr); +} + +// Encode a few frames for 2 temporal layers realtime mode. +// Set duration to be very large on first frame, much smaller +// on second frames, with the timestamp (pts) parameter very +// inconsistent with the duration (i.e, pts != prev_pts + duration). +// This reproduces the issue found in the bug: 431520320. +TEST(EncodeAPI, Vp8ChromiumIssue431520320) { + // Initialize libvpx encoder. + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 320; + cfg.g_h = 240; + cfg.g_lag_in_frames = 0; + cfg.rc_target_bitrate = 500; + + // 2-layers, 2-frame period. + int ids[2] = { 0, 1 }; + cfg.ts_periodicity = 2; + cfg.ts_number_layers = 2; + cfg.ts_rate_decimator[0] = 2; + cfg.ts_rate_decimator[1] = 1; + cfg.ts_target_bitrate[0] = 300; + cfg.ts_target_bitrate[1] = 500; + memcpy(cfg.ts_layer_id, ids, sizeof(ids)); + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + // Create input image. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + // Encode first frame. + ASSERT_EQ( + vpx_codec_encode(&enc, image, 0, /*duration=*/800000, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Encode second frame. + ASSERT_EQ(vpx_codec_encode(&enc, image, 40000, /*duration=*/40000, 0, + VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Encode third frame. + ASSERT_EQ(vpx_codec_encode(&enc, image, 80000, /*duration=*/40000, 0, + VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Free resources. + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, AomediaIssue3509VbrMinSection2PercentVP8) { + // Initialize libvpx encoder. + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 1920; + cfg.g_h = 1080; + cfg.g_lag_in_frames = 0; + cfg.rc_target_bitrate = 1000000; + // Set this to more than 1 percent to cause a signed integer overflow in the + // multiplication cpi->av_per_frame_bandwidth * + // cpi->oxcf.two_pass_vbrmin_section in vp8_new_framerate() if the + // multiplication is done in the `int` type. + cfg.rc_2pass_vbr_minsection_pct = 2; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + // Create input image. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + // Encode frame. + // `duration` can go as high as 300, but the UBSan error is gone if + // `duration` is 301 or higher. + ASSERT_EQ( + vpx_codec_encode(&enc, image, 0, /*duration=*/300, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Free resources. + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, AomediaIssue3509VbrMinSection101PercentVP8) { + // Initialize libvpx encoder. + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 1920; + cfg.g_h = 1080; + cfg.g_lag_in_frames = 0; + cfg.rc_target_bitrate = 1000000; + // Set this to more than 100 percent to cause an error when vbr_min_bits is + // cast to `int` in vp8_new_framerate() if vbr_min_bits is not clamped to + // INT_MAX. + cfg.rc_2pass_vbr_minsection_pct = 101; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + // Create input image. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + // Encode frame. + // `duration` can go as high as 300, but the UBSan error is gone if + // `duration` is 301 or higher. + ASSERT_EQ( + vpx_codec_encode(&enc, image, 0, /*duration=*/300, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Free resources. + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +// VP8 realtime mode does not support lag in frames. +#if !CONFIG_REALTIME_ONLY +TEST(EncodeAPI, OssFuzz69100) { + // Initialize libvpx encoder. + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 64; + cfg.g_h = 64; + cfg.g_lag_in_frames = 25; + cfg.g_timebase.num = 1; + cfg.g_timebase.den = 6240592; + cfg.rc_target_bitrate = 1202607620; + cfg.kf_max_dist = 24377; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 1), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_ARNR_MAXFRAMES, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_ARNR_STRENGTH, 3), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control_(&enc, VP8E_SET_ARNR_TYPE, 3), + VPX_CODEC_OK); // deprecated + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_NOISE_SENSITIVITY, 0), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_TOKEN_PARTITIONS, 0), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_STATIC_THRESHOLD, 0), + VPX_CODEC_OK); + + libvpx_test::RandomVideoSource video; + video.set_limit(30); + video.SetSize(cfg.g_w, cfg.g_h); + video.SetImageFormat(VPX_IMG_FMT_I420); + video.Begin(); + do { + ASSERT_EQ(vpx_codec_encode(&enc, video.img(), video.pts(), video.duration(), + /*flags=*/0, VPX_DL_GOOD_QUALITY), + VPX_CODEC_OK); + video.Next(); + } while (video.img() != nullptr); + + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} +#endif // !CONFIG_REALTIME_ONLY + +void EncodeOssFuzz69906(int cpu_used, vpx_enc_deadline_t deadline) { + char str[80]; + snprintf(str, sizeof(str), "cpu_used: %d deadline: %d", cpu_used, + static_cast(deadline)); + SCOPED_TRACE(str); + + // Initialize libvpx encoder. + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 4097; + cfg.g_h = 16; + cfg.rc_target_bitrate = 1237084865; + cfg.kf_max_dist = 4336; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, cpu_used), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_ARNR_MAXFRAMES, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_ARNR_STRENGTH, 3), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control_(&enc, VP8E_SET_ARNR_TYPE, 3), + VPX_CODEC_OK); // deprecated + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_NOISE_SENSITIVITY, 0), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_TOKEN_PARTITIONS, 0), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_STATIC_THRESHOLD, 0), + VPX_CODEC_OK); + + libvpx_test::Y4mVideoSource video("repro-oss-fuzz-69906.y4m", /*start=*/0, + /*limit=*/3); + video.Begin(); + do { + ASSERT_EQ(vpx_codec_encode(&enc, video.img(), video.pts(), video.duration(), + /*flags=*/0, deadline), + VPX_CODEC_OK); + video.Next(); + } while (video.img() != nullptr); + + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, OssFuzz69906) { + // Note the original bug report was for speed 1, good quality. The remainder + // of the settings are for added coverage. + for (int cpu_used = 0; cpu_used <= 5; ++cpu_used) { + EncodeOssFuzz69906(cpu_used, VPX_DL_GOOD_QUALITY); + } + + for (int cpu_used = -16; cpu_used <= -5; ++cpu_used) { + EncodeOssFuzz69906(cpu_used, VPX_DL_REALTIME); + } +} + +TEST(EncodeAPI, OssFuzz471723682) { + // Initialize libvpx encoder. + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 253; + cfg.g_h = 252; + cfg.rc_target_bitrate = 2611345883; + cfg.kf_max_dist = 16515082; + cfg.g_timebase.num = 89; + cfg.g_timebase.den = 655613; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.rc_dropframe_thresh = 0; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 1), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_ARNR_MAXFRAMES, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_ARNR_STRENGTH, 3), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control_(&enc, VP8E_SET_ARNR_TYPE, 3), + VPX_CODEC_OK); // deprecated + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_NOISE_SENSITIVITY, 0), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_TOKEN_PARTITIONS, 0), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_STATIC_THRESHOLD, 0), + VPX_CODEC_OK); + + libvpx_test::YUVVideoSource video( + "repro-oss-fuzz-471723682.yuv", VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h, + /*rate_numerator=*/786684, /*rate_denominator=*/4980772, + /*start=*/0, + /*limit=*/8); + video.Begin(); + do { + ASSERT_EQ(vpx_codec_encode(&enc, video.img(), /*pts=*/0, /*duration=*/46640, + /*flags=*/0, VPX_DL_GOOD_QUALITY), + VPX_CODEC_OK); + video.Next(); + } while (video.img() != nullptr); + + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, Vp8TotalrateOverflow) { + vpx_codec_enc_cfg_t cfg; + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 1156; + cfg.g_h = 700; + cfg.g_threads = 8; + cfg.g_pass = VPX_RC_ONE_PASS; + + vpx_codec_ctx_t codec; + ASSERT_EQ(vpx_codec_enc_init(&codec, iface, &cfg, 0), VPX_CODEC_OK); + + libvpx_test::ACMRandom rng; + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h, &rng); + ASSERT_NE(image, nullptr); + + EXPECT_EQ(vpx_codec_encode(&codec, image, 0, 1, 0, VPX_DL_GOOD_QUALITY), + VPX_CODEC_OK); + + vpx_img_free(image); + EXPECT_EQ(vpx_codec_destroy(&codec), VPX_CODEC_OK); +} + +// Bug: 526739171. +TEST(EncodeAPI, Vp8InvalidTemporalLayerId) { + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 64; + cfg.g_h = 64; + + cfg.ts_number_layers = 2; + cfg.ts_periodicity = 2; + cfg.ts_target_bitrate[0] = 500; + cfg.ts_target_bitrate[1] = 1000; + cfg.ts_rate_decimator[0] = 2; + cfg.ts_rate_decimator[1] = 1; + + cfg.ts_layer_id[0] = 0; + cfg.ts_layer_id[1] = 2; // Invalid, must be < ts_number_layers (2) + + EXPECT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_INVALID_PARAM); +} + +// Bug: 526739171. +TEST(EncodeAPI, Vp8InvalidTemporalLayerPeriodicity) { + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 64; + cfg.g_h = 64; + + cfg.ts_number_layers = 2; + cfg.ts_periodicity = 0; // Invalid, must be >= 1 + + EXPECT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_INVALID_PARAM); +} + +// Bug: 540945422. +// Test resolution changes combined with noise sensitivity toggles. +// If the resolution increases while noise sensitivity is disabled, +// the denoiser allocation is skipped. If noise sensitivity is subsequently +// enabled at the larger resolution, we must ensure the denoiser buffers +// are properly reallocated to match the larger size to avoid OOB writes. +TEST(EncodeAPI, Vp8DenoiserResolutionChange) { + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_enc_cfg_t cfg; + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 640; + cfg.g_h = 480; + cfg.g_lag_in_frames = 0; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + // Enable noise sensitivity to 1. + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_NOISE_SENSITIVITY, 1), + VPX_CODEC_OK); + + // Change to smaller resolution. + cfg.g_w = 320; + cfg.g_h = 240; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + // Disable noise sensitivity so the next resolution increase skips + // denoiser reallocation. + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_NOISE_SENSITIVITY, 0), + VPX_CODEC_OK); + + // Change back to large resolution. + cfg.g_w = 640; + cfg.g_h = 480; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + // Re-enable noise sensitivity. + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_NOISE_SENSITIVITY, 1), + VPX_CODEC_OK); + + // Encode a frame. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + ASSERT_EQ(vpx_codec_encode(&enc, image, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(image); + + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +// Test VP8 SSIM tuning with multiple frames. +TEST(EncodeAPI, Vp8SSIMMultipleFrames) { + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + // Set VP8_TUNE_SSIM. + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_TUNING, VP8_TUNE_SSIM), + VPX_CODEC_OK); + + vpx_image_t *const img = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(img, nullptr); + + // Encode multiple frames with GOOD_QUALITY to enable coefficient + // optimization. + for (int frame = 0; frame < 2; ++frame) { + ASSERT_EQ(vpx_codec_encode(&enc, img, frame, 1, 0, VPX_DL_GOOD_QUALITY), + VPX_CODEC_OK); + } + + vpx_img_free(img); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +// Bug: 454794528, 567288636. +TEST(EncodeAPI, Vp8GfOverspendBitsUnderflow) { + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 320; + cfg.g_h = 240; + cfg.g_threads = 0; + cfg.g_error_resilient = 0; + cfg.g_timebase.num = 1; + cfg.g_timebase.den = 1000000; + cfg.rc_target_bitrate = 40000; + cfg.rc_end_usage = VPX_VBR; + cfg.rc_dropframe_thresh = 0; + cfg.g_lag_in_frames = 0; + cfg.kf_max_dist = 3000; + cfg.kf_min_dist = 3000; + cfg.kf_mode = VPX_KF_AUTO; + cfg.g_profile = 0; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_STATIC_THRESHOLD, 1), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, -8), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_TOKEN_PARTITIONS, 0), + VPX_CODEC_OK); + + vpx_image_t *const img = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(img, nullptr); + + constexpr unsigned long kDuration = 5000000; + for (int frame = 0; frame < 120; ++frame) { + ASSERT_EQ(vpx_codec_encode(&enc, img, frame * kDuration, kDuration, + /*flags=*/0, VPX_DL_REALTIME), + VPX_CODEC_OK); + } + + vpx_img_free(img); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} +#endif // CONFIG_VP8_ENCODER + +#if CONFIG_VP9_ENCODER +TEST(EncodeAPI, SetReferenceValidationVp9) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + vpx_image_t *const ref_img = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(ref_img, nullptr); + + for (const int plane : { VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V }) { + vpx_ref_frame_t ref_frame; + ref_frame.frame_type = VP8_LAST_FRAME; + ref_frame.img = *ref_img; + ref_frame.img.planes[plane] = nullptr; + EXPECT_EQ(vpx_codec_control(&enc, VP8_SET_REFERENCE, &ref_frame), + VPX_CODEC_INVALID_PARAM); + EXPECT_EQ(vpx_codec_control(&enc, VP8_COPY_REFERENCE, &ref_frame), + VPX_CODEC_INVALID_PARAM); + } + + vpx_img_free(ref_img); + EXPECT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} +#endif // CONFIG_VP9_ENCODER // Set up 2 spatial streams with 2 temporal layers per stream, and generate // invalid configuration by setting the temporal layer rate allocation @@ -167,7 +1381,7 @@ TEST(EncodeAPI, MultiResEncode) { cfg[0].g_timebase.num = 1; /* Set fps */ cfg[0].g_timebase.den = framerate; - memcpy(&cfg[1], &cfg[0], sizeof(cfg[0])); + cfg[1] = cfg[0]; cfg[1].rc_target_bitrate = 500; cfg[1].g_w = width_down; cfg[1].g_h = height_down; @@ -194,9 +1408,77 @@ TEST(EncodeAPI, MultiResEncode) { } } +#if CONFIG_VP8_ENCODER && CONFIG_MULTI_RES_ENCODING +// Regression test for an off-by-one in vpx_codec_encode()'s multi-resolution +// loop: when the *first* iteration (highest-index encoder, smallest stream) +// returns non-OK, `break` skips `ctx--`, the post-loop `ctx++` advances ctx to +// one past the caller's array, and SAVE_STATUS(ctx, res) writes ctx->err out of +// bounds. With a heap-allocated 3-element array (matching WebRTC's +// std::vector encoders_), ASan reports a 4-byte +// heap-buffer-overflow WRITE at +16 past a 168-byte region. +// Bug: 513405023. +TEST(EncodeAPI, MultiResEncodeFirstIterFailOOB) { + constexpr int kNumEnc = 3; + // Heap-allocate exactly kNumEnc contexts, mirroring WebRTC's + // encoders_.reserve(3); encoders_.resize(3); + std::vector enc; + enc.reserve(kNumEnc); + enc.resize(kNumEnc); + memset(enc.data(), 0, sizeof(vpx_codec_ctx_t) * kNumEnc); + + vpx_codec_enc_cfg_t cfg[kNumEnc]; + vpx_rational_t dsf[kNumEnc] = { { 2, 1 }, { 2, 1 }, { 1, 1 } }; + const int w[kNumEnc] = { 320, 160, 80 }; + const int h[kNumEnc] = { 240, 120, 60 }; + + for (int i = 0; i < kNumEnc; ++i) { + ASSERT_EQ(vpx_codec_enc_config_default(&vpx_codec_vp8_cx_algo, &cfg[i], 0), + VPX_CODEC_OK); + cfg[i].g_w = w[i]; + cfg[i].g_h = h[i]; + cfg[i].g_lag_in_frames = 0; + cfg[i].rc_end_usage = VPX_CBR; + cfg[i].rc_resize_allowed = 0; + cfg[i].rc_target_bitrate = 300 >> i; + cfg[i].g_timebase.num = 1; + cfg[i].g_timebase.den = 30; + } + + ASSERT_EQ(vpx_codec_enc_init_multi(enc.data(), &vpx_codec_vp8_cx_algo, cfg, + kNumEnc, 0, dsf), + VPX_CODEC_OK); + + // Contiguous image array; vpx_codec_encode walks img += num_enc-1. + vpx_image_t imgs[kNumEnc]; + for (int i = 0; i < kNumEnc; ++i) { + ASSERT_NE(vpx_img_alloc(&imgs[i], VPX_IMG_FMT_I420, w[i], h[i], 1), + nullptr); + memset(imgs[i].img_data, 128, imgs[i].stride[0] * h[i] * 3 / 2); + } + + // Force the FIRST loop iteration (i = num_enc-1, ctx = &enc[2]) to fail in + // validate_img() before any ctx-- runs: set an unsupported format on the + // highest-index image. validate_img returns VPX_CODEC_INVALID_PARAM, the + // loop breaks, ctx++ advances to &enc[3], and SAVE_STATUS writes + // (&enc[3])->err — a 4-byte heap OOB write at offset 16 past the vector's + // 168-byte backing store. + imgs[kNumEnc - 1].fmt = VPX_IMG_FMT_I444; + + // Under ASan this line reports: + // heap-buffer-overflow WRITE of size 4 ... in vpx_codec_encode + // 0 bytes to the right of (or 16 past) 168-byte region. + EXPECT_EQ(vpx_codec_encode(enc.data(), imgs, /*pts=*/0, /*duration=*/1, + /*flags=*/0, VPX_DL_REALTIME), + VPX_CODEC_INVALID_PARAM); + + for (int i = 0; i < kNumEnc; ++i) vpx_img_free(&imgs[i]); + for (int i = kNumEnc - 1; i >= 0; --i) vpx_codec_destroy(&enc[i]); +} +#endif // CONFIG_VP8_ENCODER && CONFIG_MULTI_RES_ENCODING + TEST(EncodeAPI, SetRoi) { static struct { - const vpx_codec_iface_t *iface; + vpx_codec_iface_t *iface; int ctrl_id; } kCodecs[] = { #if CONFIG_VP8_ENCODER @@ -233,8 +1515,8 @@ TEST(EncodeAPI, SetRoi) { roi.roi_map = roi_map; // VP8 only. This value isn't range checked. roi.static_threshold[1] = 1000; - roi.static_threshold[2] = INT_MIN; - roi.static_threshold[3] = INT_MAX; + roi.static_threshold[2] = UINT_MAX / 2 + 1; + roi.static_threshold[3] = UINT_MAX; for (const auto delta : { -63, -1, 0, 1, 63 }) { for (int i = 0; i < 8; ++i) { @@ -302,32 +1584,81 @@ TEST(EncodeAPI, SetRoi) { } } -void InitCodec(const vpx_codec_iface_t &iface, int width, int height, - vpx_codec_ctx_t *enc, vpx_codec_enc_cfg_t *cfg) { - ASSERT_EQ(vpx_codec_enc_config_default(&iface, cfg, 0), VPX_CODEC_OK); - cfg->g_w = width; - cfg->g_h = height; - cfg->g_lag_in_frames = 0; - cfg->g_pass = VPX_RC_ONE_PASS; - ASSERT_EQ(vpx_codec_enc_init(enc, &iface, cfg, 0), VPX_CODEC_OK); +#if CONFIG_VP9_ENCODER +// Segment ids in the ROI map must be in [0, MAX_SEGMENTS). vp9_set_roi_map() +// did not validate the map contents, so out-of-range ids were used to index +// segment count arrays on the stack while encoding inter frames. +TEST(EncodeAPI, SetRoiInvalidSegmentIdVp9) { + constexpr int kWidth = 64; + constexpr int kHeight = 64; + constexpr int kRows = (kHeight + 7) >> 3; + constexpr int kCols = (kWidth + 7) >> 3; + constexpr uint8_t kMaxSegments = 8; // MAX_SEGMENTS - ASSERT_EQ(vpx_codec_control_(enc, VP8E_SET_CPUUSED, 2), VPX_CODEC_OK); -} + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(vpx_codec_vp9_cx(), &cfg, /*usage=*/0), + VPX_CODEC_OK); + cfg.g_w = kWidth; + cfg.g_h = kHeight; + cfg.g_lag_in_frames = 0; + ASSERT_EQ(vpx_codec_enc_init(&enc, vpx_codec_vp9_cx(), &cfg, 0), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 5), VPX_CODEC_OK); -// Encodes 1 frame of size |cfg.g_w| x |cfg.g_h| setting |enc|'s configuration -// to |cfg|. -void EncodeWithConfig(const vpx_codec_enc_cfg_t &cfg, vpx_codec_ctx_t *enc) { - libvpx_test::DummyVideoSource video; - video.SetSize(cfg.g_w, cfg.g_h); - video.Begin(); - EXPECT_EQ(vpx_codec_enc_config_set(enc, &cfg), VPX_CODEC_OK) - << vpx_codec_error_detail(enc); + vpx_image_t *const img = + vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, kWidth, kHeight, 32); + ASSERT_NE(img, nullptr); + for (int plane = 0; plane < 3; ++plane) { + const int w = plane ? kWidth >> 1 : kWidth; + const int h = plane ? kHeight >> 1 : kHeight; + uint8_t *row = img->planes[plane]; + for (int y = 0; y < h; ++y) { + for (int x = 0; x < w; ++x) { + row[x] = static_cast((x * 7 + y * 13) & 255); + } + row += img->stride[plane]; + } + } - EXPECT_EQ(vpx_codec_encode(enc, video.img(), video.pts(), video.duration(), - /*flags=*/0, VPX_DL_GOOD_QUALITY), - VPX_CODEC_OK) - << vpx_codec_error_detail(enc); + vpx_roi_map_t roi = {}; + uint8_t roi_map[kRows * kCols]; + roi.roi_map = roi_map; + roi.rows = kRows; + roi.cols = kCols; + roi.delta_q[0] = -10; // Enable segmentation. + // -1 disables the ref frame feature: with 0 the ROI would force intra + // prediction and the second frame would not exercise an inter frame. + for (int i = 0; i < 8; ++i) { + roi.ref_frame[i] = -1; + } + + // Segment ids out of range must be rejected. + memset(roi_map, kMaxSegments, sizeof(roi_map)); + EXPECT_EQ(vpx_codec_control(&enc, VP9E_SET_ROI_MAP, &roi), + VPX_CODEC_INVALID_PARAM); + + // Valid segment ids must be accepted... + for (size_t i = 0; i < sizeof(roi_map); ++i) { + roi_map[i] = static_cast(i % kMaxSegments); + } + EXPECT_EQ(vpx_codec_control(&enc, VP9E_SET_ROI_MAP, &roi), VPX_CODEC_OK); + + // ...and encoding a key frame followed by an inter frame with the ROI map + // enabled must succeed. + for (int frame = 0; frame < 2; ++frame) { + ASSERT_EQ(vpx_codec_encode(&enc, img, /*pts=*/frame, /*duration=*/1, + /*flags=*/0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_codec_iter_t iter = nullptr; + while (vpx_codec_get_cx_data(&enc, &iter) != nullptr) { + } + } + + vpx_img_free(img); + EXPECT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); } +#endif // CONFIG_VP9_ENCODER TEST(EncodeAPI, ConfigChangeThreadCount) { constexpr int kWidth = 1920; @@ -336,12 +1667,13 @@ TEST(EncodeAPI, ConfigChangeThreadCount) { for (const auto *iface : kCodecIfaces) { SCOPED_TRACE(vpx_codec_iface_name(iface)); for (int i = 0; i < (IsVP9(iface) ? 2 : 1); ++i) { - vpx_codec_enc_cfg_t cfg; + vpx_codec_enc_cfg_t cfg = {}; struct Encoder { ~Encoder() { EXPECT_EQ(vpx_codec_destroy(&ctx), VPX_CODEC_OK); } vpx_codec_ctx_t ctx = {}; } enc; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); EXPECT_NO_FATAL_FAILURE( InitCodec(*iface, kWidth, kHeight, &enc.ctx, &cfg)); if (IsVP9(iface)) { @@ -360,4 +1692,2992 @@ TEST(EncodeAPI, ConfigChangeThreadCount) { } } +TEST(EncodeAPI, ConfigResizeChangeThreadCount) { + constexpr int kInitWidth = 1024; + constexpr int kInitHeight = 1024; + + for (const auto *iface : kCodecIfaces) { + SCOPED_TRACE(vpx_codec_iface_name(iface)); + for (int i = 0; i < (IsVP9(iface) ? 2 : 1); ++i) { + vpx_codec_enc_cfg_t cfg = {}; + struct Encoder { + ~Encoder() { EXPECT_EQ(vpx_codec_destroy(&ctx), VPX_CODEC_OK); } + vpx_codec_ctx_t ctx = {}; + } enc; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + // Start in threaded mode to ensure resolution and thread related + // allocations are updated correctly across changes in resolution and + // thread counts. See https://crbug.com/1486441. + cfg.g_threads = 4; + EXPECT_NO_FATAL_FAILURE( + InitCodec(*iface, kInitWidth, kInitHeight, &enc.ctx, &cfg)); + if (IsVP9(iface)) { + EXPECT_EQ(vpx_codec_control_(&enc.ctx, VP9E_SET_TILE_COLUMNS, 6), + VPX_CODEC_OK); + EXPECT_EQ(vpx_codec_control_(&enc.ctx, VP9E_SET_ROW_MT, i), + VPX_CODEC_OK); + } + + cfg.g_w = 1000; + cfg.g_h = 608; + EXPECT_EQ(vpx_codec_enc_config_set(&enc.ctx, &cfg), VPX_CODEC_OK) + << vpx_codec_error_detail(&enc.ctx); + + cfg.g_w = 1000; + cfg.g_h = 720; + + for (const auto threads : { 1, 4, 8, 6, 2, 1 }) { + cfg.g_threads = threads; + EXPECT_NO_FATAL_FAILURE(EncodeWithConfig(cfg, &enc.ctx)) + << "iteration: " << i << " threads: " << threads; + } + } + } +} + +TEST(EncodeAPI, ConfigResizeBiggerAfterInit) { + for (const auto *iface : kCodecIfaces) { + SCOPED_TRACE(vpx_codec_iface_name(iface)); + vpx_codec_enc_cfg_t cfg; + vpx_codec_ctx_t enc; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + EXPECT_NO_FATAL_FAILURE(InitCodec(*iface, 1, 1, &enc, &cfg)); + + cfg.g_w = 1920; + cfg.g_h = 1; + EXPECT_EQ(vpx_codec_enc_config_set(&enc, &cfg), + IsVP9(iface) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM); + + EXPECT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); + } +} + +TEST(EncodeAPI, ConfigResizeBiggerAfterEncode) { + for (const auto *iface : kCodecIfaces) { + SCOPED_TRACE(vpx_codec_iface_name(iface)); + vpx_codec_enc_cfg_t cfg; + vpx_codec_ctx_t enc; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + EXPECT_NO_FATAL_FAILURE(InitCodec(*iface, 1, 1, &enc, &cfg)); + EXPECT_NO_FATAL_FAILURE(EncodeWithConfig(cfg, &enc)); + + cfg.g_w = 1920; + cfg.g_h = 1; + EXPECT_EQ(vpx_codec_enc_config_set(&enc, &cfg), + IsVP9(iface) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM); + + cfg.g_w = 1920; + cfg.g_h = 1080; + EXPECT_EQ(vpx_codec_enc_config_set(&enc, &cfg), + IsVP9(iface) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM); + + EXPECT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); + } +} + +TEST(EncodeAPI, PtsSmallerThanInitialPts) { + for (const auto *iface : kCodecIfaces) { + // Initialize libvpx encoder. + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + // Create input image. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + // Encode frame. + ASSERT_EQ(vpx_codec_encode(&enc, image, 12, 1, 0, VPX_DL_BEST_QUALITY), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_encode(&enc, image, 13, 1, 0, VPX_DL_BEST_QUALITY), + VPX_CODEC_OK); + // pts (10) is smaller than the initial pts (12). + ASSERT_EQ(vpx_codec_encode(&enc, image, 10, 1, 0, VPX_DL_BEST_QUALITY), + VPX_CODEC_INVALID_PARAM); + + // Free resources. + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); + } +} + +TEST(EncodeAPI, PtsOrDurationTooBig) { + for (const auto *iface : kCodecIfaces) { + // Initialize libvpx encoder. + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + // Create input image. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + // Encode frame. + ASSERT_EQ(vpx_codec_encode(&enc, image, 0, 1, 0, VPX_DL_BEST_QUALITY), + VPX_CODEC_OK); +#if ULONG_MAX > INT64_MAX + // duration is too big. + ASSERT_EQ(vpx_codec_encode(&enc, image, 0, (1ul << 63), 0, 2), + VPX_CODEC_INVALID_PARAM); +#endif + // pts, when converted to ticks, is too big. + ASSERT_EQ(vpx_codec_encode(&enc, image, INT64_MAX / 1000000 + 1, 1, 0, + VPX_DL_BEST_QUALITY), + VPX_CODEC_INVALID_PARAM); +#if ULONG_MAX > INT64_MAX + // duration is too big. + ASSERT_EQ( + vpx_codec_encode(&enc, image, 0, (1ul << 63), 0, VPX_DL_BEST_QUALITY), + VPX_CODEC_INVALID_PARAM); + // pts + duration is too big. + ASSERT_EQ( + vpx_codec_encode(&enc, image, 1, INT64_MAX, 0, VPX_DL_BEST_QUALITY), + VPX_CODEC_INVALID_PARAM); +#endif + // pts + duration, when converted to ticks, is too big. +#if ULONG_MAX > INT64_MAX + ASSERT_EQ(vpx_codec_encode(&enc, image, 0, 0xbd6b566b15c7, 0, + VPX_DL_BEST_QUALITY), + VPX_CODEC_INVALID_PARAM); +#endif + ASSERT_EQ(vpx_codec_encode(&enc, image, INT64_MAX / 1000000, 1, 0, + VPX_DL_BEST_QUALITY), + VPX_CODEC_INVALID_PARAM); + + // Free resources. + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); + } +} + +TEST(EncodeAPI, PerFramePsnr) { + for (const auto *iface : kCodecIfaces) { + SCOPED_TRACE(vpx_codec_iface_name(iface)); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_lag_in_frames = 0; + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + vpx_enc_frame_flags_t psnr_flags = VPX_EFLAG_CALCULATE_PSNR; + ASSERT_EQ(vpx_codec_encode(&enc, image, /*pts=*/0, /*duration=*/1, + psnr_flags, VPX_DL_REALTIME), + VPX_CODEC_OK); + + const vpx_codec_cx_pkt_t *pkt; + vpx_codec_iter_t iter = nullptr; + bool had_psnr = false; + while ((pkt = vpx_codec_get_cx_data(&enc, &iter)) != nullptr) { + if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) { + ASSERT_EQ(pkt->kind, VPX_CODEC_PSNR_PKT); + had_psnr = true; + } + } + EXPECT_TRUE(had_psnr); + + vpx_enc_frame_flags_t no_psnr_flags = 0; + ASSERT_EQ(vpx_codec_encode(&enc, image, /*pts=*/1, /*duration=*/1, + no_psnr_flags, VPX_DL_REALTIME), + VPX_CODEC_OK); + + iter = nullptr; + had_psnr = false; + while ((pkt = vpx_codec_get_cx_data(&enc, &iter)) != nullptr) { + if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) { + ASSERT_EQ(pkt->kind, VPX_CODEC_PSNR_PKT); + had_psnr = true; + } + } +#if CONFIG_INTERNAL_STATS + // CONFIG_INTERNAL_STATS unconditionally generates PSNR. + EXPECT_TRUE(had_psnr); +#else + EXPECT_FALSE(had_psnr); +#endif // CONFIG_INTERNAL_STATS + + // Free resources. + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); + } +} + +#if CONFIG_VP8_ENCODER && CONFIG_TEMPORAL_DENOISING +uint64_t CalcPlaneSseVp8(const uint8_t *a, int stride_a, const uint8_t *b, + int stride_b, int width, int height) { + uint64_t sse = 0; + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + const int diff = static_cast(a[y * stride_a + x]) - + static_cast(b[y * stride_b + x]); + sse += static_cast(diff * diff); + } + } + return sse; +} + +TEST(EncodeAPI, VP8DenoiserPsnr) { + constexpr int kWidth = 64; + constexpr int kHeight = 64; + + vpx_codec_iface_t *const iface = vpx_codec_vp8_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_w = kWidth; + cfg.g_h = kHeight; + cfg.g_lag_in_frames = 0; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.rc_end_usage = VPX_CBR; + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, VPX_CODEC_USE_PSNR), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, -6), VPX_CODEC_OK); + // Set noise_sensitivity = 2 (kDenoiserOnYUV) so UV planes are denoised + // in-place in cpi->Source. + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_NOISE_SENSITIVITY, 2), + VPX_CODEC_OK); + + // Frame 0 (keyframe, Y=128, U/V=200) initializes the denoiser reference. + // U/V must be away from 128 so vp8_denoiser_filter_uv does not skip them. + vpx_image_t *const img = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, kWidth, kHeight); + ASSERT_NE(img, nullptr); + for (int y = 0; y < kHeight / 2; ++y) { + memset(img->planes[VPX_PLANE_U] + y * img->stride[VPX_PLANE_U], 200, + kWidth / 2); + memset(img->planes[VPX_PLANE_V] + y * img->stride[VPX_PLANE_V], 200, + kWidth / 2); + } + ASSERT_EQ(vpx_codec_encode(&enc, img, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Frame 1 (inter frame, U/V=202): small chroma perturbation is filtered back + // toward 200 in-place in cpi->Source (u_buffer/v_buffer) by the denoiser. + for (int y = 0; y < kHeight / 2; ++y) { + memset(img->planes[VPX_PLANE_U] + y * img->stride[VPX_PLANE_U], 202, + kWidth / 2); + memset(img->planes[VPX_PLANE_V] + y * img->stride[VPX_PLANE_V], 202, + kWidth / 2); + } + ASSERT_EQ(vpx_codec_encode(&enc, img, 1, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + const vpx_image_t *const recon = vpx_codec_get_preview_frame(&enc); + ASSERT_NE(recon, nullptr); + + const uint64_t expected_sse_y = CalcPlaneSseVp8( + img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y], + recon->planes[VPX_PLANE_Y], recon->stride[VPX_PLANE_Y], kWidth, kHeight); + const uint64_t expected_sse_u = + CalcPlaneSseVp8(img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U], + recon->planes[VPX_PLANE_U], recon->stride[VPX_PLANE_U], + kWidth / 2, kHeight / 2); + const uint64_t expected_sse_v = + CalcPlaneSseVp8(img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V], + recon->planes[VPX_PLANE_V], recon->stride[VPX_PLANE_V], + kWidth / 2, kHeight / 2); + EXPECT_GT(expected_sse_u, 0u); + EXPECT_GT(expected_sse_v, 0u); + + const vpx_codec_cx_pkt_t *pkt; + vpx_codec_iter_t iter = nullptr; + bool had_psnr_pkt = false; + while ((pkt = vpx_codec_get_cx_data(&enc, &iter)) != nullptr) { + if (pkt->kind == VPX_CODEC_PSNR_PKT) { + had_psnr_pkt = true; + EXPECT_EQ(pkt->data.psnr.sse[0], + expected_sse_y + expected_sse_u + expected_sse_v); + EXPECT_EQ(pkt->data.psnr.sse[1], expected_sse_y); + EXPECT_EQ(pkt->data.psnr.sse[2], expected_sse_u); + EXPECT_EQ(pkt->data.psnr.sse[3], expected_sse_v); + } + } + EXPECT_TRUE(had_psnr_pkt); + + vpx_img_free(img); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} +#endif // CONFIG_VP8_ENCODER && CONFIG_TEMPORAL_DENOISING + +#if CONFIG_VP9_ENCODER +// Frame size needed to trigger the overflow exceeds the max buffer allowed on +// 32-bit systems defined by VPX_MAX_ALLOCABLE_MEMORY +#if VPX_ARCH_X86_64 || VPX_ARCH_AARCH64 +TEST(EncodeAPI, ConfigLargeTargetBitrateVp9) { +#ifdef CHROMIUM + GTEST_SKIP() << "Under Chromium's configuration the allocator is unable" + "to provide the space required for the frames below."; +#else + constexpr int kWidth = 12383; + constexpr int kHeight = 8192; + constexpr auto *iface = &vpx_codec_vp9_cx_algo; + SCOPED_TRACE(vpx_codec_iface_name(iface)); + vpx_codec_enc_cfg_t cfg = {}; + struct Encoder { + ~Encoder() { EXPECT_EQ(vpx_codec_destroy(&ctx), VPX_CODEC_OK); } + vpx_codec_ctx_t ctx = {}; + } enc; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + // The following setting will cause avg_frame_bandwidth in rate control to be + // larger than INT_MAX + cfg.rc_target_bitrate = INT_MAX; + // Framerate 0.1 (equivalent to timebase 10) is the smallest framerate allowed + // by libvpx + cfg.g_timebase.den = 1; + cfg.g_timebase.num = 10; + EXPECT_NO_FATAL_FAILURE(InitCodec(*iface, kWidth, kHeight, &enc.ctx, &cfg)) + << "target bitrate: " << cfg.rc_target_bitrate << " framerate: " + << static_cast(cfg.g_timebase.den) / cfg.g_timebase.num; +#endif // defined(CHROMIUM) +} +#endif // VPX_ARCH_X86_64 || VPX_ARCH_AARCH64 + +// Emulates the WebCodecs VideoEncoder interface. +class VP9Encoder { + public: + explicit VP9Encoder(int speed) + : speed_(speed), row_mt_(0), bit_depth_(VPX_BITS_8), + fmt_(VPX_IMG_FMT_I420) {} + // The image format `fmt` must not have the VPX_IMG_FMT_HIGHBITDEPTH bit set. + // If bit_depth > 8, we will set the VPX_IMG_FMT_HIGHBITDEPTH bit before + // passing the image format to vpx_img_alloc(). + VP9Encoder(int speed, unsigned int row_mt, vpx_bit_depth_t bit_depth, + vpx_img_fmt_t fmt) + : speed_(speed), row_mt_(row_mt), bit_depth_(bit_depth), fmt_(fmt) {} + ~VP9Encoder(); + + void Configure(unsigned int threads, unsigned int width, unsigned int height, + vpx_rc_mode end_usage, vpx_enc_deadline_t deadline); + // If `rng` is non-null, use it to generate the image values for encoding. + // Otherwise the midpoint of the configured bitdepth is used. + void Encode(bool key_frame, libvpx_test::ACMRandom *rng = nullptr); + + private: + const int speed_; + const unsigned int row_mt_; + const vpx_bit_depth_t bit_depth_; + const vpx_img_fmt_t fmt_; + bool initialized_ = false; + vpx_codec_enc_cfg_t cfg_; + vpx_codec_ctx_t enc_; + int frame_index_ = 0; + vpx_enc_deadline_t deadline_ = 0; +}; + +VP9Encoder::~VP9Encoder() { + if (initialized_) { + EXPECT_EQ(vpx_codec_destroy(&enc_), VPX_CODEC_OK); + } +} + +void VP9Encoder::Configure(unsigned int threads, unsigned int width, + unsigned int height, vpx_rc_mode end_usage, + vpx_enc_deadline_t deadline) { + deadline_ = deadline; + + if (!initialized_) { + ASSERT_EQ(fmt_ & VPX_IMG_FMT_HIGHBITDEPTH, 0); + const bool high_bit_depth = bit_depth_ > VPX_BITS_8; + const bool is_420 = fmt_ == VPX_IMG_FMT_I420; + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg_, /*usage=*/0), + VPX_CODEC_OK); + cfg_.g_threads = threads; + // In profiles 0 and 2, only 4:2:0 format is allowed. In profiles 1 and 3, + // all other subsampling formats are allowed. In profiles 0 and 1, only bit + // depth 8 is allowed. In profiles 2 and 3, only bit depths 10 and 12 are + // allowed. + cfg_.g_profile = 2 * high_bit_depth + !is_420; + cfg_.g_w = width; + cfg_.g_h = height; + cfg_.g_bit_depth = bit_depth_; + cfg_.g_input_bit_depth = bit_depth_; + cfg_.g_timebase.num = 1; + cfg_.g_timebase.den = 1000 * 1000; // microseconds + cfg_.g_pass = VPX_RC_ONE_PASS; + cfg_.g_lag_in_frames = 0; + cfg_.rc_end_usage = end_usage; + cfg_.rc_min_quantizer = 2; + cfg_.rc_max_quantizer = 58; + ASSERT_EQ( + vpx_codec_enc_init(&enc_, iface, &cfg_, + high_bit_depth ? VPX_CODEC_USE_HIGHBITDEPTH : 0), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc_, VP8E_SET_CPUUSED, speed_), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc_, VP9E_SET_ROW_MT, row_mt_), VPX_CODEC_OK); + initialized_ = true; + return; + } + + cfg_.g_threads = threads; + cfg_.g_w = width; + cfg_.g_h = height; + cfg_.rc_end_usage = end_usage; + ASSERT_EQ(vpx_codec_enc_config_set(&enc_, &cfg_), VPX_CODEC_OK) + << vpx_codec_error_detail(&enc_); +} + +void VP9Encoder::Encode(bool key_frame, libvpx_test::ACMRandom *rng) { + assert(initialized_); + const vpx_codec_cx_pkt_t *pkt; + vpx_image_t *image = CreateImage(bit_depth_, fmt_, cfg_.g_w, cfg_.g_h, rng); + ASSERT_NE(image, nullptr); + const vpx_enc_frame_flags_t frame_flags = key_frame ? VPX_EFLAG_FORCE_KF : 0; + ASSERT_EQ( + vpx_codec_encode(&enc_, image, frame_index_, 1, frame_flags, deadline_), + VPX_CODEC_OK); + ++frame_index_; + vpx_codec_iter_t iter = nullptr; + while ((pkt = vpx_codec_get_cx_data(&enc_, &iter)) != nullptr) { + ASSERT_EQ(pkt->kind, VPX_CODEC_CX_FRAME_PKT); + } + vpx_img_free(image); +} + +// This is a test case from clusterfuzz. +TEST(EncodeAPI, PrevMiCheckNullptr) { + VP9Encoder encoder(0); + encoder.Configure(0, 1554, 644, VPX_VBR, VPX_DL_REALTIME); + + // First step: encode, without forcing KF. + encoder.Encode(false); + // Second step: change config + encoder.Configure(0, 1131, 644, VPX_CBR, VPX_DL_GOOD_QUALITY); + // Third step: encode, without forcing KF + encoder.Encode(false); +} + +// This is a test case from clusterfuzz: based on b/310477034. +// Encode a few frames with multiple change config calls +// with different frame sizes. +TEST(EncodeAPI, MultipleChangeConfigResize) { + VP9Encoder encoder(3); + + // Set initial config. + encoder.Configure(3, 41, 1, VPX_VBR, VPX_DL_REALTIME); + + // Encode first frame. + encoder.Encode(true); + + // Change config. + encoder.Configure(16, 31, 1, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Change config again. + encoder.Configure(0, 17, 1, VPX_CBR, VPX_DL_REALTIME); + + // Encode 2nd frame with new config, set delta frame. + encoder.Encode(false); + + // Encode 3rd frame with same config, set delta frame. + encoder.Encode(false); +} + +// This is a test case from clusterfuzz: based on b/310663186. +// Encode set of frames while varying the deadline on the fly from +// good to realtime to best and back to realtime. +TEST(EncodeAPI, DynamicDeadlineChange) { + // Use realtime speed: 5 to 9. + VP9Encoder encoder(5); + + // Set initial config, in particular set deadline to GOOD mode. + encoder.Configure(0, 1, 1, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Encode 1st frame. + encoder.Encode(true); + + // Encode 2nd frame, delta frame. + encoder.Encode(false); + + // Change config: change deadline to REALTIME. + encoder.Configure(0, 1, 1, VPX_VBR, VPX_DL_REALTIME); + + // Encode 3rd frame with new config, set key frame. + encoder.Encode(true); + + // Encode 4th frame with same config, delta frame. + encoder.Encode(false); + + // Encode 5th frame with same config, key frame. + encoder.Encode(true); + + // Change config: change deadline to BEST. + encoder.Configure(0, 1, 1, VPX_VBR, VPX_DL_BEST_QUALITY); + + // Encode 6th frame with new config, set delta frame. + encoder.Encode(false); + + // Change config: change deadline to REALTIME. + encoder.Configure(0, 1, 1, VPX_VBR, VPX_DL_REALTIME); + + // Encode 7th frame with new config, set delta frame. + encoder.Encode(false); + + // Encode 8th frame with new config, set key frame. + encoder.Encode(true); + + // Encode 9th frame with new config, set delta frame. + encoder.Encode(false); +} + +TEST(EncodeAPI, Buganizer310340241) { + VP9Encoder encoder(-6); + + // Set initial config, in particular set deadline to GOOD mode. + encoder.Configure(0, 1, 1, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Encode 1st frame. + encoder.Encode(true); + + // Encode 2nd frame, delta frame. + encoder.Encode(false); + + // Change config: change deadline to REALTIME. + encoder.Configure(0, 1, 1, VPX_VBR, VPX_DL_REALTIME); + + // Encode 3rd frame with new config, set key frame. + encoder.Encode(true); +} + +// This is a test case from clusterfuzz: based on b/312517065. +TEST(EncodeAPI, Buganizer312517065) { + VP9Encoder encoder(4); + encoder.Configure(0, 1060, 437, VPX_CBR, VPX_DL_REALTIME); + encoder.Encode(true); + encoder.Configure(10, 33, 437, VPX_VBR, VPX_DL_GOOD_QUALITY); + encoder.Encode(false); + encoder.Configure(6, 327, 269, VPX_VBR, VPX_DL_GOOD_QUALITY); + encoder.Configure(15, 1060, 437, VPX_CBR, VPX_DL_REALTIME); + encoder.Encode(false); +} + +// This is a test case from clusterfuzz: based on b/311489136. +// Encode a few frames with multiple change config calls +// with different frame sizes. +TEST(EncodeAPI, Buganizer311489136) { + VP9Encoder encoder(1); + + // Set initial config. + encoder.Configure(12, 1678, 620, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Encode first frame. + encoder.Encode(true); + + // Change config. + encoder.Configure(3, 1678, 202, VPX_CBR, VPX_DL_GOOD_QUALITY); + + // Encode 2nd frame with new config, set delta frame. + encoder.Encode(false); + + // Change config again. + encoder.Configure(8, 1037, 476, VPX_CBR, VPX_DL_REALTIME); + + // Encode 3rd frame with new config, set delta frame. + encoder.Encode(false); + + // Change config again. + encoder.Configure(0, 580, 620, VPX_CBR, VPX_DL_GOOD_QUALITY); + + // Encode 4th frame with same config, set delta frame. + encoder.Encode(false); +} + +// This is a test case from clusterfuzz: based on b/312656387. +// Encode a few frames with multiple change config calls +// with different frame sizes. +TEST(EncodeAPI, Buganizer312656387) { + VP9Encoder encoder(1); + + // Set initial config. + encoder.Configure(16, 1, 1024, VPX_CBR, VPX_DL_REALTIME); + + // Change config. + encoder.Configure(15, 1, 1024, VPX_VBR, VPX_DL_REALTIME); + + // Encode first frame. + encoder.Encode(true); + + // Change config again. + encoder.Configure(14, 1, 595, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Encode 2nd frame with new config. + encoder.Encode(true); + + // Change config again. + encoder.Configure(2, 1, 1024, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Encode 3rd frame with new config, set delta frame. + encoder.Encode(false); +} + +// This is a test case from clusterfuzz: based on b/310329177. +// Encode a few frames with multiple change config calls +// with different frame sizes. +TEST(EncodeAPI, Buganizer310329177) { + VP9Encoder encoder(6); + + // Set initial config. + encoder.Configure(10, 41, 1, VPX_VBR, VPX_DL_REALTIME); + + // Encode first frame. + encoder.Encode(true); + + // Change config. + encoder.Configure(16, 1, 1, VPX_VBR, VPX_DL_REALTIME); + + // Encode 2nd frame with new config, set delta frame. + encoder.Encode(false); +} + +// This is a test case from clusterfuzz: based on b/311394513. +// Encode a few frames with multiple change config calls +// with different frame sizes. +TEST(EncodeAPI, Buganizer311394513) { + VP9Encoder encoder(-7); + + // Set initial config. + encoder.Configure(0, 5, 9, VPX_VBR, VPX_DL_REALTIME); + + // Encode first frame. + encoder.Encode(false); + + // Change config. + encoder.Configure(5, 2, 1, VPX_VBR, VPX_DL_REALTIME); + + // Encode 2nd frame with new config. + encoder.Encode(true); +} + +TEST(EncodeAPI, Buganizer311985118) { + VP9Encoder encoder(0); + + // Set initial config, in particular set deadline to GOOD mode. + encoder.Configure(12, 1678, 620, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Encode 1st frame. + encoder.Encode(false); + + // Change config: change threads and width. + encoder.Configure(0, 1574, 620, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Change config: change threads, width and height. + encoder.Configure(16, 837, 432, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Encode 2nd frame. + encoder.Encode(false); +} + +// This is a test case from clusterfuzz: based on b/314857577. +// Encode a few frames with multiple change config calls +// with different frame sizes. +TEST(EncodeAPI, Buganizer314857577) { + VP9Encoder encoder(4); + + // Set initial config. + encoder.Configure(12, 1060, 437, VPX_VBR, VPX_DL_REALTIME); + + // Encode first frame. + encoder.Encode(false); + + // Change config. + encoder.Configure(16, 1060, 1, VPX_CBR, VPX_DL_REALTIME); + + // Encode 2nd frame with new config. + encoder.Encode(false); + + // Encode 3rd frame with new config. + encoder.Encode(true); + + // Change config. + encoder.Configure(15, 33, 437, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Encode 4th frame with new config. + encoder.Encode(true); + + // Encode 5th frame with new config. + encoder.Encode(false); + + // Change config. + encoder.Configure(5, 327, 269, VPX_VBR, VPX_DL_REALTIME); + + // Change config. + encoder.Configure(15, 1060, 437, VPX_CBR, VPX_DL_REALTIME); + + // Encode 6th frame with new config. + encoder.Encode(false); + + // Encode 7th frame with new config. + encoder.Encode(false); + + // Change config. + encoder.Configure(4, 1060, 437, VPX_VBR, VPX_DL_REALTIME); + + // Encode 8th frame with new config. + encoder.Encode(false); +} + +TEST(EncodeAPI, Buganizer312875957PredBufferStride) { + VP9Encoder encoder(-1); + + encoder.Configure(12, 1678, 620, VPX_VBR, VPX_DL_REALTIME); + encoder.Encode(true); + encoder.Encode(false); + encoder.Configure(0, 456, 486, VPX_VBR, VPX_DL_REALTIME); + encoder.Encode(true); + encoder.Configure(0, 1678, 620, VPX_CBR, 1000000); + encoder.Encode(false); + encoder.Encode(false); +} + +// This is a test case from clusterfuzz: based on b/311294795 +// Encode a few frames with multiple change config calls +// with different frame sizes. +TEST(EncodeAPI, Buganizer311294795) { + VP9Encoder encoder(1); + + // Set initial config. + encoder.Configure(12, 1678, 620, VPX_VBR, VPX_DL_REALTIME); + + // Encode first frame. + encoder.Encode(false); + + // Change config. + encoder.Configure(16, 632, 620, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Encode 2nd frame with new config + encoder.Encode(true); + + // Change config. + encoder.Configure(16, 1678, 342, VPX_VBR, VPX_DL_GOOD_QUALITY); + + // Encode 3rd frame with new config. + encoder.Encode(false); + + // Change config. + encoder.Configure(0, 1574, 618, VPX_VBR, VPX_DL_REALTIME); + // Encode more frames with new config. + encoder.Encode(false); + encoder.Encode(false); +} + +// Test case to capture assert issue triggered in +// vp9_bitstream.c for good_quality, speed 1, lossless; +// See comment#22 in issue:433941753. +TEST(EncodeAPI, AssertIssueGoodQualitySpeed1Lossless) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_w = 1540; + cfg.g_h = 838; + cfg.g_profile = 0; + cfg.g_bit_depth = VPX_BITS_8; + cfg.g_timebase.num = 1; + cfg.g_timebase.den = 10000; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 0; + cfg.rc_end_usage = VPX_VBR; + cfg.g_threads = 1; + cfg.rc_target_bitrate = 10000; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_LOSSLESS, 1), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 1), VPX_CODEC_OK); + libvpx_test::RandomVideoSource video; + video.SetSize(cfg.g_w, cfg.g_h); + video.SetImageFormat(VPX_IMG_FMT_I420); + video.set_limit(20); + video.Begin(); + do { + ASSERT_EQ(vpx_codec_encode(&enc, video.img(), video.pts(), video.duration(), + 0, VPX_DL_GOOD_QUALITY), + VPX_CODEC_OK); + video.Next(); + } while (video.img() != nullptr); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +void FillPlane(uint8_t *plane, int stride, int width, int height, + uint8_t value) { + for (int y = 0; y < height; ++y) { + memset(plane + y * stride, value, width); + } +} + +// Test case to capture ioc in vp9_caq_select_segment() +// in b/475394382 +TEST(EncodeAPI, Buganizer475394382) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 41; + cfg.g_h = 43; + cfg.g_timebase.num = 1; + cfg.g_timebase.den = 30; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 2; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_AQ_MODE, 2), VPX_CODEC_OK); + + cfg.rc_target_bitrate = 141452; + cfg.g_lag_in_frames = 0; + vpx_codec_enc_config_set(&enc, &cfg); + + vpx_image_t *img = + vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h, 16); + ASSERT_NE(img, nullptr); + + FillPlane(img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y], cfg.g_w, + cfg.g_h, 0x80); + FillPlane(img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U], + (cfg.g_w + 1) / 2, (cfg.g_h + 1) / 2, 0x40); + FillPlane(img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V], + (cfg.g_w + 1) / 2, (cfg.g_h + 1) / 2, 0xC0); + + static constexpr std::array frame_flags = { + VPX_EFLAG_FORCE_KF, VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF, 0 + }; + + int frame_idx = 0; + for (const auto flags : frame_flags) { + vpx_codec_encode(&enc, img, frame_idx, 1, flags, VPX_DL_GOOD_QUALITY); + vpx_codec_iter_t iter = nullptr; + while (vpx_codec_get_cx_data(&enc, &iter)) { + } + ++frame_idx; + } + + vpx_img_free(img); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, Buganizer317105128) { + VP9Encoder encoder(-9); + encoder.Configure(0, 1, 1, VPX_CBR, VPX_DL_GOOD_QUALITY); + encoder.Configure(16, 1920, 1, VPX_CBR, VPX_DL_REALTIME); +} + +TEST(EncodeAPI, Buganizer319964497) { + VP9Encoder encoder(7); + encoder.Configure(/*threads=*/1, /*width=*/320, /*height=*/240, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/true); + encoder.Encode(/*key_frame=*/true); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/1, /*width=*/1, /*height=*/1, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/1, /*width=*/2, /*height=*/2, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); +} + +TEST(EncodeAPI, Buganizer329088759RowMT0) { + VP9Encoder encoder(8, 0, VPX_BITS_8, VPX_IMG_FMT_I444); + encoder.Configure(/*threads=*/8, /*width=*/1686, /*height=*/398, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/true); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/0, /*width=*/1686, /*height=*/1, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/true); + encoder.Configure(/*threads=*/0, /*width=*/1482, /*height=*/113, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/true); + encoder.Configure(/*threads=*/0, /*width=*/881, /*height=*/59, VPX_CBR, + VPX_DL_REALTIME); + encoder.Configure(/*threads=*/13, /*width=*/1271, /*height=*/385, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/2, /*width=*/1, /*height=*/62, VPX_VBR, + VPX_DL_REALTIME); +} + +TEST(EncodeAPI, Buganizer329088759RowMT1) { + VP9Encoder encoder(8, 1, VPX_BITS_8, VPX_IMG_FMT_I444); + encoder.Configure(/*threads=*/8, /*width=*/1686, /*height=*/398, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/true); + encoder.Encode(/*key_frame=*/false); + // Needs to set threads to non-zero to repro the issue. + encoder.Configure(/*threads=*/2, /*width=*/1686, /*height=*/1, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/true); + encoder.Configure(/*threads=*/2, /*width=*/1482, /*height=*/113, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/true); + encoder.Configure(/*threads=*/2, /*width=*/881, /*height=*/59, VPX_CBR, + VPX_DL_REALTIME); + encoder.Configure(/*threads=*/13, /*width=*/1271, /*height=*/385, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/2, /*width=*/1, /*height=*/62, VPX_VBR, + VPX_DL_REALTIME); +} + +TEST(EncodeAPI, Buganizer331086799) { + VP9Encoder encoder(6, 1, VPX_BITS_8, VPX_IMG_FMT_I420); + encoder.Configure(0, 1385, 1, VPX_CBR, VPX_DL_REALTIME); + encoder.Configure(0, 1, 1, VPX_VBR, VPX_DL_REALTIME); + encoder.Encode(false); + encoder.Configure(16, 1385, 1, VPX_VBR, VPX_DL_GOOD_QUALITY); + encoder.Encode(false); + encoder.Encode(false); + encoder.Configure(0, 1, 1, VPX_CBR, VPX_DL_REALTIME); + encoder.Encode(true); +} + +TEST(EncodeAPI, Buganizer331108729) { + VP9Encoder encoder(1, 1, VPX_BITS_8, VPX_IMG_FMT_I422); + encoder.Configure(0, 1919, 260, VPX_VBR, VPX_DL_REALTIME); + encoder.Configure(9, 440, 1, VPX_CBR, VPX_DL_GOOD_QUALITY); + encoder.Encode(true); + encoder.Configure(8, 1919, 260, VPX_VBR, VPX_DL_REALTIME); + encoder.Encode(false); +} + +TEST(EncodeAPI, Buganizer331108922BitDepth8) { + VP9Encoder encoder(9, 1, VPX_BITS_8, VPX_IMG_FMT_I420); + encoder.Configure(/*threads=*/1, /*width=*/1, /*height=*/1080, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/0, /*width=*/1, /*height=*/1080, VPX_CBR, + VPX_DL_GOOD_QUALITY); + encoder.Configure(/*threads=*/16, /*width=*/1, /*height=*/394, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); + encoder.Encode(/*key_frame=*/true); + encoder.Configure(/*threads=*/16, /*width=*/1, /*height=*/798, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); +} + +// Encode some frames, flip from BEST_QUALITY to REALTIME after 2 frames. +// This test is taken from the code snippet in issue:441668134. +TEST(EncodeAPI, Buganizer441668134) { + // Get VP9 encoder interface. + vpx_codec_iface_t *iface = vpx_codec_vp9_cx(); + // Initialize encoder configuration with default values. + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_lag_in_frames = 0; + cfg.rc_max_quantizer = 0; + unsigned long init_flags = 0; + vpx_codec_ctx_t ctx; + ASSERT_EQ(vpx_codec_enc_init(&ctx, iface, &cfg, init_flags), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control_(&ctx, VP8E_SET_CPUUSED, 9), 0); + ASSERT_EQ(vpx_codec_control_(&ctx, VP9E_SET_DELTA_Q_UV, -15), 0); + // Image allocation. + vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420; + vpx_image_t *img = vpx_img_alloc(nullptr, img_fmt, cfg.g_w, cfg.g_h, 32); + for (unsigned int y = 0; y < img->d_h; y++) { + for (unsigned int x = 0; x < img->d_w; x++) { + img->planes[0][y * img->stride[0] + x] = ((x ^ y) * 127) & 0xFF; + } + } + const unsigned int uv_height = (img->d_h + 1) >> 1; + for (int i : { VPX_PLANE_U, VPX_PLANE_V }) { + memset(img->planes[i], 0, img->stride[i] * uv_height); + } + // Encode some frames. + int num_frames = 6; + static constexpr int kChoices[6] = { 1, 1, 0, 0, 0, 0 }; + for (int frame = 0; frame < num_frames; frame++) { + vpx_enc_deadline_t deadline = VPX_DL_REALTIME; + uint8_t dl_choice = kChoices[frame]; + if (dl_choice == 1) deadline = VPX_DL_BEST_QUALITY; + // Encode frame. + ASSERT_EQ(vpx_codec_encode(&ctx, img, frame, 1, 0, deadline), VPX_CODEC_OK); + } + vpx_img_free(img); + vpx_codec_destroy(&ctx); +} + +// Encode a few frames, with realtime mode and tile_rows set to 1, +// with row-mt enabled. This triggers an assertion in vp9_bitstream.c (in +// function write_modes()), as in the issue:442105459. In this test it happens +// on very first encoded frame since lag_in_frames = 0. Issue is due to enabling +// TILE_ROWS, with number of tile_rows more than the number of superblocks. +// This test sets 2 tile_rows with height corresponding to 1 superblock (sb). +TEST(EncodeAPI, Buganizer442105459_2RowTiles) { + // Initialize VP9 encoder interface + vpx_codec_iface_t *iface = vpx_codec_vp9_cx(); + // Get default encoder configuration + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + // Configure encoder + cfg.g_w = 946u; + cfg.g_h = 64u; // 1 sb row, 2 tile_rows set below. + cfg.g_threads = 1; + cfg.g_profile = 0; + cfg.g_bit_depth = VPX_BITS_8; + // Rate control targeting deeper encoding paths + cfg.rc_target_bitrate = 100; + cfg.rc_min_quantizer = 0; + cfg.rc_max_quantizer = 0; + cfg.rc_end_usage = VPX_VBR; + cfg.ss_number_layers = 1; + cfg.g_lag_in_frames = 0; + // Initialize encoder context + vpx_codec_ctx_t ctx; + ASSERT_EQ(vpx_codec_enc_init(&ctx, iface, &cfg, 0), VPX_CODEC_OK); + // Set control parameters + vpx_codec_control_(&ctx, VP8E_SET_CPUUSED, -5); + vpx_codec_control_(&ctx, VP9E_SET_TILE_ROWS, 1); + vpx_codec_control_(&ctx, VP9E_SET_TILE_COLUMNS, 1); + vpx_codec_control_(&ctx, VP9E_SET_ROW_MT, 1); + // Image format selection + vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420; + // Allocate image with varied alignment + vpx_image_t *img = vpx_img_alloc(nullptr, img_fmt, cfg.g_w, cfg.g_h, 1); + for (unsigned int y = 0; y < img->d_h; y++) { + for (unsigned int x = 0; x < img->d_w; x++) { + img->planes[0][y * img->stride[0] + x] = ((x ^ y) * 127) & 0xFF; + } + } + const unsigned int uv_height = (img->d_h + 1) >> 1; + for (int i : { VPX_PLANE_U, VPX_PLANE_V }) { + memset(img->planes[i], 0, img->stride[i] * uv_height); + } + // Encode with dynamic configuration changes + int num_frames = 2; + // Per-frame constants captured from the original run (indices consumed per + // frame) + const vpx_codec_pts_t frame_pts_mul[] = { 33333UL, 33333UL }; + const unsigned long frame_durations[] = { 33333UL, 33333UL }; + const vpx_enc_deadline_t frame_deadlines[] = { VPX_DL_REALTIME, + VPX_DL_REALTIME }; + for (int frame = 0; frame < num_frames; frame++) { + // Encode frame + vpx_codec_pts_t pts = frame * frame_pts_mul[frame]; + unsigned long duration = frame_durations[frame]; + vpx_enc_deadline_t deadline = frame_deadlines[frame]; + ASSERT_EQ(vpx_codec_encode(&ctx, img, pts, duration, /*flags*/ 0, deadline), + VPX_CODEC_OK); + } + // Flush encoder. + ASSERT_EQ(vpx_codec_encode(&ctx, nullptr, 0, 0, 0, VPX_DL_REALTIME), 0); + // Get remaining data + vpx_codec_iter_t iter = nullptr; + while (vpx_codec_get_cx_data(&ctx, &iter) != nullptr) { + // Process remaining packets + } + vpx_img_free(img); + vpx_codec_destroy(&ctx); +} + +// Encode a few frames, with realtime mode and tile_rows set to 1, +// with row-mt enabled. This triggers an assertion in vp9_bitstream.c (in +// function write_modes()), as in the issue:442105459. In this test it happens +// on very first encoded frame since lag_in_frames = 0. Issue is due to enabling +// TILE_ROWS, with number of tile_rows more than the number of superblocks. +// This test sets 4 tile_rows with height corresponding to 3 superblocks. +TEST(EncodeAPI, Buganizer442105459_4RowTiles) { + // Initialize VP9 encoder interface + vpx_codec_iface_t *iface = vpx_codec_vp9_cx(); + // Get default encoder configuration + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + // Configure encoder + cfg.g_w = 946u; + cfg.g_h = 192u; // 3 sb rows, 4 tile_rows set below. + cfg.g_threads = 1; + cfg.g_profile = 0; + cfg.g_bit_depth = VPX_BITS_8; + // Rate control targeting deeper encoding paths + cfg.rc_target_bitrate = 100; + cfg.rc_min_quantizer = 0; + cfg.rc_max_quantizer = 0; + cfg.rc_end_usage = VPX_VBR; + cfg.ss_number_layers = 1; + cfg.g_lag_in_frames = 0; + // Initialize encoder context + vpx_codec_ctx_t ctx; + ASSERT_EQ(vpx_codec_enc_init(&ctx, iface, &cfg, 0), VPX_CODEC_OK); + // Set control parameters + vpx_codec_control_(&ctx, VP8E_SET_CPUUSED, -5); + vpx_codec_control_(&ctx, VP9E_SET_TILE_ROWS, 2); + vpx_codec_control_(&ctx, VP9E_SET_TILE_COLUMNS, 1); + vpx_codec_control_(&ctx, VP9E_SET_ROW_MT, 1); + // Image format selection + vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420; + // Allocate image with varied alignment + vpx_image_t *img = vpx_img_alloc(nullptr, img_fmt, cfg.g_w, cfg.g_h, 1); + for (unsigned int y = 0; y < img->d_h; y++) { + for (unsigned int x = 0; x < img->d_w; x++) { + img->planes[0][y * img->stride[0] + x] = ((x ^ y) * 127) & 0xFF; + } + } + const unsigned int uv_height = (img->d_h + 1) >> 1; + for (int i : { VPX_PLANE_U, VPX_PLANE_V }) { + memset(img->planes[i], 0, img->stride[i] * uv_height); + } + // Encode with dynamic configuration changes + int num_frames = 2; + // Per-frame constants captured from the original run (indices consumed per + // frame) + const vpx_codec_pts_t frame_pts_mul[] = { 33333UL, 33333UL }; + const unsigned long frame_durations[] = { 33333UL, 33333UL }; + const vpx_enc_deadline_t frame_deadlines[] = { VPX_DL_REALTIME, + VPX_DL_REALTIME }; + for (int frame = 0; frame < num_frames; frame++) { + // Encode frame + vpx_codec_pts_t pts = frame * frame_pts_mul[frame]; + unsigned long duration = frame_durations[frame]; + vpx_enc_deadline_t deadline = frame_deadlines[frame]; + ASSERT_EQ(vpx_codec_encode(&ctx, img, pts, duration, /*flags*/ 0, deadline), + VPX_CODEC_OK); + } + // Flush encoder. + ASSERT_EQ(vpx_codec_encode(&ctx, nullptr, 0, 0, 0, VPX_DL_REALTIME), 0); + // Get remaining data + vpx_codec_iter_t iter = nullptr; + while (vpx_codec_get_cx_data(&ctx, &iter) != nullptr) { + // Process remaining packets + } + vpx_img_free(img); + vpx_codec_destroy(&ctx); +} + +#if CONFIG_VP9_HIGHBITDEPTH +TEST(EncodeAPI, Buganizer329674887RowMT0BitDepth12) { + VP9Encoder encoder(8, 0, VPX_BITS_12, VPX_IMG_FMT_I444); + encoder.Configure(/*threads=*/2, /*width=*/1030, /*height=*/583, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/true); + encoder.Configure(/*threads=*/0, /*width=*/1030, /*height=*/1, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/true); + encoder.Configure(/*threads=*/0, /*width=*/548, /*height=*/322, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/16, /*width=*/24, /*height=*/583, VPX_CBR, + VPX_DL_GOOD_QUALITY); +} + +TEST(EncodeAPI, Buganizer329179808RowMT0BitDepth10) { + VP9Encoder encoder(4, 0, VPX_BITS_10, VPX_IMG_FMT_I444); + encoder.Configure(/*threads=*/16, /*width=*/1488, /*height=*/5, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/true); + encoder.Configure(/*threads=*/16, /*width=*/839, /*height=*/1, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/11, /*width=*/657, /*height=*/5, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); +} + +TEST(EncodeAPI, Buganizer329179808RowMT1BitDepth10) { + VP9Encoder encoder(4, 1, VPX_BITS_10, VPX_IMG_FMT_I444); + encoder.Configure(/*threads=*/16, /*width=*/1488, /*height=*/5, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/true); + encoder.Configure(/*threads=*/16, /*width=*/839, /*height=*/1, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/11, /*width=*/657, /*height=*/5, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); +} + +TEST(EncodeAPI, Buganizer331108922BitDepth12) { + VP9Encoder encoder(9, 1, VPX_BITS_12, VPX_IMG_FMT_I444); + encoder.Configure(/*threads=*/1, /*width=*/1, /*height=*/1080, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/0, /*width=*/1, /*height=*/1080, VPX_CBR, + VPX_DL_GOOD_QUALITY); + encoder.Configure(/*threads=*/16, /*width=*/1, /*height=*/394, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); + encoder.Encode(/*key_frame=*/true); + encoder.Configure(/*threads=*/16, /*width=*/1, /*height=*/798, VPX_CBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false); +} + +TEST(EncodeAPI, InvalidInputRange) { + constexpr int kWidth = 64; + constexpr int kHeight = 64; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(vpx_codec_vp9_cx(), &cfg, + /*usage=*/0), + VPX_CODEC_OK); + cfg.g_w = kWidth; + cfg.g_h = kHeight; + + std::unique_ptr image( + vpx_img_alloc(nullptr, VPX_IMG_FMT_I42016, cfg.g_w, cfg.g_h, 0), + &vpx_img_free); + vpx_image_t *img = image.get(); + ASSERT_NE(img, nullptr); + + for (const auto bitdepth : { VPX_BITS_8, VPX_BITS_10, VPX_BITS_12 }) { + cfg.g_profile = (bitdepth == VPX_BITS_8) ? 0 : 2; + cfg.g_bit_depth = bitdepth; + + // A value that's slightly over the max is used to ensure when the range is + // not checked an encode won't produce any integer overflows. Values + // outside of the valid range are not supported, so overflows will be + // ignored in that case. + const int val = 1 << bitdepth; + for (const int plane : { VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V }) { + const int width = (plane == VPX_PLANE_Y) ? img->d_w : (img->d_w + 1) / 2; + const int height = (plane == VPX_PLANE_Y) ? img->d_h : (img->d_h + 1) / 2; + uint8_t *p = img->planes[plane]; + for (int y = 0; y < height; ++y) { + vpx_memset16(p, val, width); + p += img->stride[plane]; + } + } + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, vpx_codec_vp9_cx(), &cfg, + VPX_CODEC_USE_HIGHBITDEPTH), + VPX_CODEC_OK); + + for (int check_input_range = 0; check_input_range <= 1; + ++check_input_range) { + EXPECT_EQ(vpx_codec_control(&enc, VP9E_SET_VALIDATE_HBD_INPUT, + check_input_range), + VPX_CODEC_OK); + + EXPECT_EQ(vpx_codec_encode(&enc, img, /*pts=*/0, /*duration=*/1, + /*flags=*/0, VPX_DL_REALTIME), + check_input_range ? VPX_CODEC_INVALID_PARAM : VPX_CODEC_OK) + << "Error: " << vpx_codec_error_detail(&enc) + << ", bitdepth: " << bitdepth + << ", check_input_range: " << check_input_range; + } + + EXPECT_EQ(vpx_codec_encode(&enc, /*img=*/nullptr, /*pts=*/0, /*duration=*/0, + /*flags=*/0, VPX_DL_REALTIME), + VPX_CODEC_OK); + EXPECT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); + } +} +#endif // CONFIG_VP9_HIGHBITDEPTH + +TEST(EncodeAPI, VP9GlobalHeaders) { + constexpr int kWidth = 320; + constexpr int kHeight = 240; + + libvpx_test::DummyVideoSource video; + video.SetSize(kWidth, kHeight); + +#if CONFIG_VP9_HIGHBITDEPTH + const int profiles[] = { 0, 1, 2, 3 }; +#else + const int profiles[] = { 0, 1 }; +#endif + char str[80]; + for (const int profile : profiles) { + std::vector bitdepths; + std::vector formats; + switch (profile) { + case 0: + bitdepths = { VPX_BITS_8 }; + formats = { VPX_IMG_FMT_I420 }; + break; + case 1: + bitdepths = { VPX_BITS_8 }; + formats = { VPX_IMG_FMT_I422, VPX_IMG_FMT_I444 }; + break; +#if CONFIG_VP9_HIGHBITDEPTH + case 2: + bitdepths = { VPX_BITS_10, VPX_BITS_12 }; + formats = { VPX_IMG_FMT_I42016 }; + break; + case 3: + bitdepths = { VPX_BITS_10, VPX_BITS_12 }; + formats = { VPX_IMG_FMT_I42216, VPX_IMG_FMT_I44416 }; + break; +#endif + } + + for (const auto format : formats) { + for (const auto bitdepth : bitdepths) { + snprintf(str, sizeof(str), "profile: %d bitdepth: %d format: %d", + profile, bitdepth, format); + SCOPED_TRACE(str); + + vpx_codec_enc_cfg_t cfg = {}; + struct Encoder { + ~Encoder() { EXPECT_EQ(vpx_codec_destroy(&ctx), VPX_CODEC_OK); } + vpx_codec_ctx_t ctx = {}; + } enc; + vpx_codec_ctx_t *const ctx = &enc.ctx; + + ASSERT_EQ(vpx_codec_enc_config_default(vpx_codec_vp9_cx(), &cfg, 0), + VPX_CODEC_OK); + cfg.g_w = kWidth; + cfg.g_h = kHeight; + cfg.g_lag_in_frames = 0; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_profile = profile; + cfg.g_bit_depth = bitdepth; + ASSERT_EQ( + vpx_codec_enc_init(ctx, vpx_codec_vp9_cx(), &cfg, + bitdepth == 8 ? 0 : VPX_CODEC_USE_HIGHBITDEPTH), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control_(ctx, VP8E_SET_CPUUSED, 2), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control_(ctx, VP9E_SET_TARGET_LEVEL, 62), + VPX_CODEC_OK); + + vpx_fixed_buf_t *global_headers = vpx_codec_get_global_headers(ctx); + EXPECT_NE(global_headers, nullptr); + EXPECT_EQ(global_headers->sz, size_t{ 9 }); + + video.SetImageFormat(format); + video.Begin(); + EXPECT_EQ( + vpx_codec_encode(ctx, video.img(), video.pts(), video.duration(), + /*flags=*/0, VPX_DL_GOOD_QUALITY), + VPX_CODEC_OK) + << vpx_codec_error_detail(ctx); + + global_headers = vpx_codec_get_global_headers(ctx); + EXPECT_NE(global_headers, nullptr); + EXPECT_EQ(global_headers->sz, size_t{ 12 }); + uint8_t chroma_subsampling; + if ((format & VPX_IMG_FMT_I420) == VPX_IMG_FMT_I420) { + chroma_subsampling = 1; + } else if ((format & VPX_IMG_FMT_I422) == VPX_IMG_FMT_I422) { + chroma_subsampling = 2; + } else { // VPX_IMG_FMT_I444 + chroma_subsampling = 3; + } + const uint8_t expected_headers[] = { 1, + 1, + static_cast(profile), + 2, + 1, + /*level,*/ 3, + 1, + static_cast(bitdepth), + 4, + 1, + chroma_subsampling }; + const uint8_t *actual_headers = + reinterpret_cast(global_headers->buf); + for (int i = 0; i < 5; ++i) { + EXPECT_EQ(expected_headers[i], actual_headers[i]) << "index: " << i; + } + EXPECT_NE(actual_headers[6], 0); // level + for (int i = 5; i < 11; ++i) { + EXPECT_EQ(expected_headers[i], actual_headers[i + 1]) + << "index: " << i + 1; + } + } + } + } +} + +TEST(EncodeAPI, AomediaIssue3509VbrMinSection2PercentVP9) { + // Initialize libvpx encoder. + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 1920; + cfg.g_h = 1080; + cfg.g_lag_in_frames = 0; + cfg.rc_target_bitrate = 1000000; + // Set this to more than 1 percent to cause a signed integer overflow in the + // multiplication rc->avg_frame_bandwidth * oxcf->rc_cfg.vbrmin_section in + // vp9_rc_update_framerate() if the multiplication is done in the `int` type. + cfg.rc_2pass_vbr_minsection_pct = 2; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + // Create input image. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + // Encode frame. + // `duration` can go as high as 300, but the UBSan error is gone if + // `duration` is 301 or higher. + ASSERT_EQ( + vpx_codec_encode(&enc, image, 0, /*duration=*/300, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Free resources. + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, AomediaIssue3509VbrMinSection101PercentVP9) { + // Initialize libvpx encoder. + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 1920; + cfg.g_h = 1080; + cfg.g_lag_in_frames = 0; + cfg.rc_target_bitrate = 1000000; + // Set this to more than 100 percent to cause an error when vbr_min_bits is + // cast to `int` in vp9_rc_update_framerate() if vbr_min_bits is not clamped + // to INT_MAX. + cfg.rc_2pass_vbr_minsection_pct = 101; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + // Create input image. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + // Encode frame. + // `duration` can go as high as 300, but the UBSan error is gone if + // `duration` is 301 or higher. + ASSERT_EQ( + vpx_codec_encode(&enc, image, 0, /*duration=*/300, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Free resources. + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, Chromium352414650) { + // Initialize libvpx encoder. + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 1024; + cfg.g_h = 1024; + cfg.g_profile = 0; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 0; + cfg.rc_max_quantizer = 58; + cfg.rc_min_quantizer = 2; + cfg.g_threads = 4; + cfg.rc_resize_allowed = 0; + cfg.rc_dropframe_thresh = 0; + cfg.g_timebase.num = 1; + cfg.g_timebase.den = 1000000; + cfg.kf_min_dist = 0; + cfg.kf_max_dist = 10000; + cfg.rc_end_usage = VPX_CBR; + cfg.rc_target_bitrate = 754974; + cfg.ts_number_layers = 3; + cfg.ts_periodicity = 4; + cfg.ts_layer_id[0] = 0; + cfg.ts_layer_id[1] = 2; + cfg.ts_layer_id[2] = 1; + cfg.ts_layer_id[3] = 2; + cfg.ts_rate_decimator[0] = 4; + cfg.ts_rate_decimator[1] = 2; + cfg.ts_rate_decimator[2] = 1; + cfg.layer_target_bitrate[0] = 2147483; + cfg.layer_target_bitrate[1] = 3006476; + cfg.layer_target_bitrate[2] = 4294967; + cfg.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_0212; + cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 7), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_TILE_COLUMNS, 2), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_ROW_MT, 1), VPX_CODEC_OK); + + vpx_svc_extra_cfg_t svc_cfg = {}; + svc_cfg.max_quantizers[0] = svc_cfg.max_quantizers[1] = + svc_cfg.max_quantizers[2] = 58; + svc_cfg.min_quantizers[0] = svc_cfg.min_quantizers[1] = + svc_cfg.min_quantizers[2] = 2; + svc_cfg.scaling_factor_num[0] = svc_cfg.scaling_factor_num[1] = + svc_cfg.scaling_factor_num[2] = 1; + svc_cfg.scaling_factor_den[0] = svc_cfg.scaling_factor_den[1] = + svc_cfg.scaling_factor_den[2] = 1; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_PARAMETERS, &svc_cfg), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC, 1), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_AQ_MODE, 3), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_STATIC_THRESHOLD, 1), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_COLOR_SPACE, VPX_CS_SMPTE_170), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_COLOR_RANGE, VPX_CR_STUDIO_RANGE), + VPX_CODEC_OK); + + // Create input image. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + // Encode frame. + ASSERT_EQ(vpx_codec_encode(&enc, image, 0, /*duration=*/500000, + VPX_EFLAG_FORCE_KF, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Free resources. + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, PerFramePsnrNotSupportedWithLagInFrames) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_NE(cfg.g_lag_in_frames, 0u); + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + vpx_enc_frame_flags_t psnr_flags = VPX_EFLAG_CALCULATE_PSNR; + ASSERT_EQ(vpx_codec_encode(&enc, image, /*pts=*/0, /*duration=*/1, psnr_flags, + VPX_DL_REALTIME), + VPX_CODEC_INCAPABLE); + + // Free resources. + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, Buganizer487259772ScaledRefs) { + libvpx_test::ACMRandom rng; + VP9Encoder encoder(/*speed=*/7, /*row_mt=*/0, VPX_BITS_8, VPX_IMG_FMT_I420); + encoder.Configure(/*threads=*/1, /*width=*/478, /*height=*/755, VPX_VBR, + VPX_DL_REALTIME); + encoder.Configure(/*threads=*/1, /*width=*/387, /*height=*/438, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false, &rng); + encoder.Encode(/*key_frame=*/true, &rng); + encoder.Encode(/*key_frame=*/false, &rng); + encoder.Encode(/*key_frame=*/false, &rng); + + encoder.Configure(/*threads=*/1, /*width=*/341, /*height=*/655, VPX_VBR, + VPX_DL_REALTIME); + encoder.Encode(/*key_frame=*/false, &rng); + encoder.Encode(/*key_frame=*/false, &rng); +} + +#if CONFIG_VP9_HIGHBITDEPTH +// This test uses source input based on the issue: 488585490, +// which is invalid for 10 bit. This test checks that the +// encoder correctly returns VPX_CODEC_INVALID_PARAM. +TEST(EncodeAPI, Buganizer488585490CostTableOverflow) { + // Initialize libvpx encoder. + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, /*usage=*/0), + VPX_CODEC_OK); + + cfg.g_w = 149; + cfg.g_h = 48; + cfg.g_profile = 3; + cfg.g_bit_depth = VPX_BITS_10; + cfg.g_input_bit_depth = 10; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 0; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, VPX_CODEC_USE_HIGHBITDEPTH), + VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 7), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_LOSSLESS, 1), VPX_CODEC_OK); + + libvpx_test::YUVVideoSource video( + "repro-b488585490.yuv", VPX_IMG_FMT_I44416, cfg.g_w, cfg.g_h, + /*rate_numerator=*/1, /*rate_denominator=*/30, /*start=*/0, /*limit=*/1); + video.Begin(); + ASSERT_EQ(vpx_codec_encode(&enc, video.img(), video.pts(), /*duration=*/66666, + /*flags=*/0, VPX_DL_REALTIME), + VPX_CODEC_INVALID_PARAM); + + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +void TestEncoderImageMismatch(bool use_highbitdepth) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 180; + cfg.g_h = 68; + cfg.g_lag_in_frames = 0; + + vpx_img_fmt_t img_fmt; + vpx_codec_flags_t flags = 0; + + if (use_highbitdepth) { + cfg.g_profile = 2; + cfg.g_bit_depth = VPX_BITS_10; + flags = VPX_CODEC_USE_HIGHBITDEPTH; + img_fmt = VPX_IMG_FMT_I420; + } else { + cfg.g_profile = 0; + flags = 0; + img_fmt = VPX_IMG_FMT_I42016; + } + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, flags), VPX_CODEC_OK); + + vpx_image_t *img = vpx_img_alloc(nullptr, img_fmt, cfg.g_w, cfg.g_h, 1); + ASSERT_NE(img, nullptr); + + ASSERT_EQ(vpx_codec_encode(&enc, img, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_INVALID_PARAM); + + vpx_img_free(img); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, HighbdEncoderI420ImageMismatch) { + TestEncoderImageMismatch(true); +} + +TEST(EncodeAPI, NonHighbdEncoderI42016ImageMismatch) { + TestEncoderImageMismatch(false); +} + +// Verifies that validate_img() rejects high bit-depth images whose plane +// pointers or byte strides are not 2-byte aligned. +// Bug: 578678096 +TEST(EncodeAPI, HighbdMisalignedPlanesAndStrides) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, /*usage=*/0), + VPX_CODEC_OK); + + const unsigned int kWidth = 72; + const unsigned int kHeight = 72; + const int kStride = 256; + cfg.g_w = kWidth; + cfg.g_h = kHeight; + cfg.g_profile = 2; + cfg.g_bit_depth = VPX_BITS_10; + cfg.g_input_bit_depth = 10; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 0; + cfg.rc_end_usage = VPX_Q; + cfg.rc_min_quantizer = 0; + cfg.rc_max_quantizer = 0; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, VPX_CODEC_USE_HIGHBITDEPTH), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 6), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CQ_LEVEL, 0), VPX_CODEC_OK); + + std::vector buf(kStride * kHeight * 3 + 16, 0); + // Ensure base is 2-byte aligned so base + 1 is guaranteed to be odd and + // base + 2 is guaranteed to be even. + uint8_t *base = buf.data(); + if (reinterpret_cast(base) & 1) { + ++base; + } + + // Populate a 4x4 checkerboard pattern of [0x00, 0x7F] / [0x00, 0x80] in the + // right-most 8x8 column. At base + 1 (odd), these 16-bit little-endian words + // are 0x007F / 0x0080 (< 1024); at base + 0 (even), they are 0x7F00 / 0x8000. + for (unsigned int y = 0; y < kHeight; ++y) { + for (unsigned int x = 64; x < kWidth; ++x) { + const size_t idx = y * kStride + x * 2; + const bool sx = (x & 3) < 2; + const bool sy = (y & 3) < 2; + base[idx] = 0x00; + base[idx + 1] = (sx ^ sy) ? 0x80 : 0x7F; + } + } + + vpx_image_t img; + memset(&img, 0, sizeof(img)); + ASSERT_EQ(vpx_img_wrap(&img, VPX_IMG_FMT_I42016, kWidth, kHeight, 1, base), + &img); + uint8_t *const aligned_y = base + 2; + uint8_t *const aligned_u = base + kStride * kHeight + 2; + uint8_t *const aligned_v = base + kStride * kHeight * 2 + 2; + auto reset_valid_img = [&]() { + img.planes[VPX_PLANE_Y] = aligned_y; + img.planes[VPX_PLANE_U] = aligned_u; + img.planes[VPX_PLANE_V] = aligned_v; + img.stride[VPX_PLANE_Y] = kStride; + img.stride[VPX_PLANE_U] = kStride; + img.stride[VPX_PLANE_V] = kStride; + }; + + // 1. Odd plane pointers on Y, U, or V must be rejected. + for (int plane = 0; plane < 3; ++plane) { + reset_valid_img(); + img.planes[plane] -= 1; // Odd byte address. + EXPECT_EQ(vpx_codec_encode(&enc, &img, /*pts=*/0, /*duration=*/1, + /*flags=*/VPX_EFLAG_FORCE_KF, VPX_DL_REALTIME), + VPX_CODEC_INVALID_PARAM); + } + + // 2. Odd byte strides on Y or U/V must be rejected. + reset_valid_img(); + img.stride[VPX_PLANE_Y] = kStride + 1; + EXPECT_EQ(vpx_codec_encode(&enc, &img, /*pts=*/0, /*duration=*/1, + /*flags=*/VPX_EFLAG_FORCE_KF, VPX_DL_REALTIME), + VPX_CODEC_INVALID_PARAM); + + reset_valid_img(); + img.stride[VPX_PLANE_U] = kStride + 1; + img.stride[VPX_PLANE_V] = kStride + 1; + EXPECT_EQ(vpx_codec_encode(&enc, &img, /*pts=*/0, /*duration=*/1, + /*flags=*/VPX_EFLAG_FORCE_KF, VPX_DL_REALTIME), + VPX_CODEC_INVALID_PARAM); + + // 3. Even with VP9E_SET_VALIDATE_HBD_INPUT disabled, odd plane pointers and + // strides must still be rejected because CONVERT_TO_BYTEPTR and stride >>= 1 + // require 2-byte alignment. + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_VALIDATE_HBD_INPUT, 0), + VPX_CODEC_OK); + reset_valid_img(); + img.planes[VPX_PLANE_Y] -= 1; + EXPECT_EQ(vpx_codec_encode(&enc, &img, /*pts=*/0, /*duration=*/1, + /*flags=*/VPX_EFLAG_FORCE_KF, VPX_DL_REALTIME), + VPX_CODEC_INVALID_PARAM); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_VALIDATE_HBD_INPUT, 1), + VPX_CODEC_OK); + + // 4. At the 2-byte aligned address (base + 2), the crafted bytes read as + // 0x7F00 / 0x8000 (>= 1024) and are rejected by validate_hbd_input. + // Moving the valid 10-bit samples (0x007F / 0x0080) to the 2-byte aligned + // plane address allows the frame to encode cleanly. + reset_valid_img(); + EXPECT_EQ(vpx_codec_encode(&enc, &img, /*pts=*/0, /*duration=*/1, + /*flags=*/VPX_EFLAG_FORCE_KF, VPX_DL_REALTIME), + VPX_CODEC_INVALID_PARAM); + + memmove(base, base + 1, kStride * kHeight * 3); + reset_valid_img(); + EXPECT_EQ(vpx_codec_encode(&enc, &img, /*pts=*/0, /*duration=*/1, + /*flags=*/VPX_EFLAG_FORCE_KF, VPX_DL_REALTIME), + VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} +#endif + +TEST(EncodeAPI, SvcTestInvalidInputs) { + // Initialize libvpx encoder. + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_w = 1280; + cfg.g_h = 720; + cfg.g_profile = 0; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_timebase.num = 1; + cfg.g_timebase.den = 1000; + cfg.g_lag_in_frames = 0; + cfg.rc_max_quantizer = 58; + cfg.rc_min_quantizer = 2; + cfg.ss_number_layers = 2; + cfg.ts_number_layers = 2; + cfg.ts_periodicity = 2; + cfg.ts_layer_id[0] = 0; + cfg.ts_layer_id[1] = 1; + cfg.ts_rate_decimator[0] = 2; + cfg.ts_rate_decimator[1] = 1; + cfg.layer_target_bitrate[0] = 100; + cfg.layer_target_bitrate[1] = 200; + cfg.layer_target_bitrate[2] = 300; + cfg.layer_target_bitrate[3] = 400; + cfg.rc_target_bitrate = 700; + // Multi-layer encoding is only supported for one-pass. + cfg.g_pass = VPX_RC_FIRST_PASS; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_INVALID_PARAM); + cfg.g_pass = VPX_RC_LAST_PASS; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_INVALID_PARAM); + cfg.g_pass = VPX_RC_ONE_PASS; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + vpx_svc_extra_cfg_t svc_cfg = {}; + svc_cfg.scaling_factor_num[0] = 1; + svc_cfg.scaling_factor_den[0] = 2; + svc_cfg.scaling_factor_num[1] = 1; + svc_cfg.scaling_factor_den[1] = 1; + for (unsigned int i = 0; i < cfg.ss_number_layers * cfg.ss_number_layers; + i++) { + svc_cfg.max_quantizers[i] = 56; + svc_cfg.min_quantizers[i] = 2; + } + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC, 1), VPX_CODEC_OK); + // Check for invalid quantizer inputs. + svc_cfg.min_quantizers[1] = 2; + svc_cfg.max_quantizers[1] = 65; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_PARAMETERS, &svc_cfg), + VPX_CODEC_INVALID_PARAM); + svc_cfg.min_quantizers[1] = 2; + svc_cfg.max_quantizers[1] = -1; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_PARAMETERS, &svc_cfg), + VPX_CODEC_INVALID_PARAM); + svc_cfg.min_quantizers[1] = 64; + svc_cfg.max_quantizers[1] = 56; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_PARAMETERS, &svc_cfg), + VPX_CODEC_INVALID_PARAM); + svc_cfg.min_quantizers[1] = -1; + svc_cfg.max_quantizers[1] = 56; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_PARAMETERS, &svc_cfg), + VPX_CODEC_INVALID_PARAM); + + // Check for invalid layer id input. + vpx_svc_layer_id_t layer_id = {}; + layer_id.spatial_layer_id = 0; + layer_id.temporal_layer_id = 0; + for (unsigned int i = 0; i < cfg.ss_number_layers; i++) { + layer_id.temporal_layer_id_per_spatial[i] = 0; + } + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_LAYER_ID, &layer_id), + VPX_CODEC_OK); + + layer_id.temporal_layer_id_per_spatial[0] = cfg.ts_number_layers; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_LAYER_ID, &layer_id), + VPX_CODEC_INVALID_PARAM); + + layer_id.temporal_layer_id_per_spatial[0] = -1; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_LAYER_ID, &layer_id), + VPX_CODEC_INVALID_PARAM); + layer_id.temporal_layer_id_per_spatial[0] = 0; + + layer_id.temporal_layer_id = cfg.ts_number_layers; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_LAYER_ID, &layer_id), + VPX_CODEC_INVALID_PARAM); + + layer_id.temporal_layer_id = -1; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_LAYER_ID, &layer_id), + VPX_CODEC_INVALID_PARAM); + + // Check for invalid frame buffer index input. Valid indices are in + // [0, REF_FRAMES) (REF_FRAMES is 8); -1 is used internally for "no + // reference" but is not a valid input here. + vpx_svc_ref_frame_config_t fb_config = {}; + for (unsigned int i = 0; i < cfg.ss_number_layers; i++) { + fb_config.lst_fb_idx[i] = 0; + fb_config.gld_fb_idx[i] = 0; + fb_config.alt_fb_idx[i] = 0; + fb_config.reference_last[i] = 1; + fb_config.update_last[i] = 1; + fb_config.duration[i] = 1000; + } + fb_config.lst_fb_idx[0] = 7; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_REF_FRAME_CONFIG, &fb_config), + VPX_CODEC_OK); + fb_config.lst_fb_idx[0] = 8; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_REF_FRAME_CONFIG, &fb_config), + VPX_CODEC_INVALID_PARAM); + fb_config.lst_fb_idx[0] = -1; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_REF_FRAME_CONFIG, &fb_config), + VPX_CODEC_INVALID_PARAM); + fb_config.lst_fb_idx[0] = 0; + fb_config.gld_fb_idx[0] = -2000000; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_REF_FRAME_CONFIG, &fb_config), + VPX_CODEC_INVALID_PARAM); + fb_config.gld_fb_idx[0] = 0; + fb_config.alt_fb_idx[1] = 8; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_REF_FRAME_CONFIG, &fb_config), + VPX_CODEC_INVALID_PARAM); + + // Check for invalid duration input. + vpx_svc_ref_frame_config_t ref_frame_config = {}; + for (unsigned int i = 0; i < cfg.ss_number_layers; i++) { + ref_frame_config.lst_fb_idx[i] = 0; + ref_frame_config.reference_last[i] = 1; + ref_frame_config.update_last[i] = 1; + ref_frame_config.duration[i] = 1000; + } + ref_frame_config.duration[0] = INT64_MAX; + ASSERT_EQ( + vpx_codec_control(&enc, VP9E_SET_SVC_REF_FRAME_CONFIG, &ref_frame_config), + VPX_CODEC_OK); + // Create input image. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + ASSERT_EQ(vpx_codec_encode(&enc, image, 0, 300, 0, VPX_DL_REALTIME), + VPX_CODEC_INVALID_PARAM); + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, LargeDimensionsTokenAllocOverflow) { + // To trigger the signed integer overflow, we need: + // aligned_mb_rows * aligned_mb_cols * 772 > INT_MAX (2147483647) + // aligned_mb_rows * aligned_mb_cols > 2147483647 / 772 = 2781714.5 + // For a square-ish frame, sqrt(2781714.5) is approx 1667.8. + // Since aligned dimensions are multiples of 4, we round up to 1668. + // 1668 * 1668 * 772 = 2147876928, which is > INT_MAX. + // To get aligned MBs of 1668, we need input MBs in range (1664, 1668]. + // 1665 is chosen as the smallest integer in this range. + int64_t tokens = get_token_alloc(1665, 1665); + EXPECT_EQ(tokens, (int64_t)1668 * 1668 * (16 * 16 * 3 + 4)); +} + +// 4 spatial layers, 1 temporal, speed 1 and 0 for spatial_layer = 0, 1, +// with different scale factors. Reproduces bug: 505665613. +TEST(EncodeAPI, SvcIssue505665613) { + vpx_codec_ctx_t codec; + vpx_codec_enc_cfg_t cfg; + vpx_codec_iface_t *iface = vpx_codec_vp9_cx(); + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_w = 935; + cfg.g_h = 464; + cfg.g_profile = 0; + cfg.g_lag_in_frames = 0; + cfg.ss_number_layers = 4; + cfg.ts_number_layers = 1; + for (int i = 0; i < 4; ++i) { + cfg.layer_target_bitrate[i] = cfg.rc_target_bitrate / 4; + } + ASSERT_EQ(vpx_codec_enc_init(&codec, iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&codec, VP9E_SET_SVC, 1), VPX_CODEC_OK); + + vpx_svc_extra_cfg_t svc = {}; + svc.max_quantizers[0] = 49; + svc.min_quantizers[0] = 5; + svc.scaling_factor_num[0] = 2; + svc.scaling_factor_den[0] = 12; + svc.speed_per_layer[0] = 1; + svc.loopfilter_ctrl[0] = 1; + + svc.max_quantizers[1] = 46; + svc.min_quantizers[1] = 28; + svc.scaling_factor_num[1] = 9; + svc.scaling_factor_den[1] = 9; + svc.speed_per_layer[1] = 0; + svc.loopfilter_ctrl[1] = 0; + + svc.max_quantizers[2] = 32; + svc.min_quantizers[2] = 0; + svc.scaling_factor_num[2] = 1; + svc.scaling_factor_den[2] = 4; + svc.speed_per_layer[2] = 4; + svc.loopfilter_ctrl[2] = 0; + + svc.max_quantizers[3] = 38; + svc.min_quantizers[3] = 25; + svc.scaling_factor_num[3] = 7; + svc.scaling_factor_den[3] = 16; + svc.speed_per_layer[3] = 3; + svc.loopfilter_ctrl[3] = 0; + + svc.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_0212; + ASSERT_EQ(vpx_codec_control(&codec, VP9E_SET_SVC_PARAMETERS, &svc), + VPX_CODEC_OK); + vpx_image_t *img = vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, 935, 464, 1); + ASSERT_NE(img, nullptr); + libvpx_test::ACMRandom rng(libvpx_test::ACMRandom::DeterministicSeed()); + for (unsigned int i = 0; i < img->d_h; ++i) { + for (unsigned int j = 0; j < img->d_w; ++j) { + img->planes[0][i * img->stride[0] + j] = rng.Rand8(); + } + } + const unsigned int uv_h = + (img->d_h + img->y_chroma_shift) >> img->y_chroma_shift; + const unsigned int uv_w = + (img->d_w + img->x_chroma_shift) >> img->x_chroma_shift; + for (unsigned int i = 0; i < uv_h; ++i) { + for (unsigned int j = 0; j < uv_w; ++j) { + img->planes[1][i * img->stride[1] + j] = rng.Rand8(); + img->planes[2][i * img->stride[2] + j] = rng.Rand8(); + } + } + // Encode. + ASSERT_EQ(vpx_codec_encode(&codec, img, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(img); + vpx_codec_destroy(&codec); +} + +TEST(EncodeAPI, Vp9TargetLevelTinyResolution) { + vpx_codec_enc_cfg_t cfg; + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_w = 1; + cfg.g_h = 1; + + vpx_codec_ctx_t codec; + ASSERT_EQ(vpx_codec_enc_init(&codec, iface, &cfg, 0), VPX_CODEC_OK); + + EXPECT_EQ(vpx_codec_control_(&codec, VP9E_SET_TARGET_LEVEL, 40), + VPX_CODEC_OK); + + EXPECT_EQ(vpx_codec_destroy(&codec), VPX_CODEC_OK); +} + +// Bug: 501612368. Configuration changes with different resolution +// to trigger issues in the re-allocation logic. +void VerifyVp9EncoderMidstreamReconfig(int width1, int height1, bool encode1, + int width2, int height2, bool encode2, + int width3, int height3, bool encode3) { + vpx_codec_iface_t *const iface = &vpx_codec_vp9_cx_algo; + vpx_codec_enc_cfg_t cfg; + vpx_codec_ctx_t enc; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_w = width1; + cfg.g_h = height1; + cfg.g_timebase.num = 1; + cfg.g_timebase.den = 30; + cfg.rc_target_bitrate = 1000; + cfg.g_lag_in_frames = 0; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control_(&enc, VP8E_SET_CPUUSED, 5), VPX_CODEC_OK); + + if (encode1) { + vpx_image_t *image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + + ASSERT_EQ(vpx_codec_encode(&enc, image, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(image); + } + + cfg.g_w = width2; + cfg.g_h = height2; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + if (encode2) { + vpx_image_t *image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + + ASSERT_EQ(vpx_codec_encode(&enc, image, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(image); + } + + cfg.g_w = width3; + cfg.g_h = height3; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + if (encode3) { + vpx_image_t *image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + + ASSERT_EQ(vpx_codec_encode(&enc, image, 1, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(image); + } + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +// Resizing from 64x128 to 128x64: same allocation area. +// Bug: 501612368. +TEST(EncodeAPI, Vp9EncoderMidstreamReconfig1) { + VerifyVp9EncoderMidstreamReconfig(64, 128, true, 128, 64, true, 128, 64, + true); +} + +// Resizing from 192x192 to 256x128: allocation area decreases +// but width is increased (so alloc for context_buffer is increased). +// Bug: 501612368. +TEST(EncodeAPI, Vp9EncoderMidstreamReconfig2) { + VerifyVp9EncoderMidstreamReconfig(192, 192, true, 256, 128, true, 256, 128, + true); +} + +// Resizing from 128x128 to 96x160: allocation area decreases +// but token_alloc is increased. Bug: 501612368. +TEST(EncodeAPI, Vp9EncoderMidstreamReconfig3) { + VerifyVp9EncoderMidstreamReconfig(128, 128, true, 96, 160, true, 96, 160, + true); +} + +// Start at 128x128, encode a frame. Then update to larger resolution +// twice before encoding a frame: Bug: 501612368. +TEST(EncodeAPI, Vp9EncoderMidstreamReconfig4) { + VerifyVp9EncoderMidstreamReconfig(128, 128, true, 256, 256, false, 512, 512, + true); +} +#endif // CONFIG_VP9_ENCODER + +#if CONFIG_VP9_ENCODER +void VerifyVp9UnsafeCastEosCount(double count_value) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_pass = VPX_RC_LAST_PASS; + + // Two packets required: one frame packet + one EOS packet. + FIRSTPASS_STATS packets[2] = {}; + packets[1].count = count_value; + + cfg.rc_twopass_stats_in.buf = packets; + cfg.rc_twopass_stats_in.sz = sizeof(packets); + + vpx_codec_ctx_t codec; + // This should return VPX_CODEC_INVALID_PARAM instead of triggering UB. + EXPECT_EQ(vpx_codec_enc_init(&codec, iface, &cfg, 0), + VPX_CODEC_INVALID_PARAM); +} + +TEST(EncodeAPI, Vp9UnsafeCastEosCount) { VerifyVp9UnsafeCastEosCount(1e300); } + +TEST(EncodeAPI, Vp9UnsafeCastEosCountNaN) { VerifyVp9UnsafeCastEosCount(NAN); } + +TEST(EncodeAPI, Vp9UnsafeCastEosCountZero) { VerifyVp9UnsafeCastEosCount(0.0); } + +TEST(EncodeAPI, Vp9SvcLayeringModeNotSet) { + const unsigned int kSpatialLayers = 4; + const unsigned int kTemporalLayers = 3; + const unsigned int kWidth = 640; + const unsigned int kHeight = 320; + const int kFrames = 8; + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_w = kWidth; + cfg.g_h = kHeight; + cfg.g_timebase.num = 1; + cfg.g_timebase.den = 30; + cfg.g_error_resilient = 1; + cfg.g_lag_in_frames = 0; + cfg.rc_end_usage = VPX_CBR; + cfg.ss_number_layers = kSpatialLayers; + cfg.ts_number_layers = kTemporalLayers; + cfg.rc_target_bitrate = 5000; + cfg.ss_target_bitrate[0] = 500; + cfg.ss_target_bitrate[1] = 1000; + cfg.ss_target_bitrate[2] = 1500; + cfg.ss_target_bitrate[3] = 2000; + cfg.layer_target_bitrate[0] = 50 * cfg.ss_target_bitrate[0] / 100; + cfg.layer_target_bitrate[1] = 70 * cfg.ss_target_bitrate[0] / 100; + cfg.layer_target_bitrate[2] = cfg.ss_target_bitrate[0]; + cfg.layer_target_bitrate[3] = 50 * cfg.ss_target_bitrate[1] / 100; + cfg.layer_target_bitrate[4] = 70 * cfg.ss_target_bitrate[1] / 100; + cfg.layer_target_bitrate[5] = cfg.ss_target_bitrate[1]; + cfg.layer_target_bitrate[6] = 50 * cfg.ss_target_bitrate[2] / 100; + cfg.layer_target_bitrate[7] = 70 * cfg.ss_target_bitrate[2] / 100; + cfg.layer_target_bitrate[8] = cfg.ss_target_bitrate[2]; + cfg.layer_target_bitrate[9] = 50 * cfg.ss_target_bitrate[3] / 100; + cfg.layer_target_bitrate[10] = 70 * cfg.ss_target_bitrate[3] / 100; + cfg.layer_target_bitrate[11] = cfg.ss_target_bitrate[3]; + cfg.ts_rate_decimator[0] = 4; + cfg.ts_rate_decimator[1] = 2; + cfg.ts_rate_decimator[2] = 1; + cfg.ts_periodicity = 12; + for (unsigned int i = 0; i < cfg.ts_periodicity; ++i) { + cfg.ts_layer_id[i] = i % kTemporalLayers; + } + vpx_codec_ctx_t codec; + ASSERT_EQ(vpx_codec_enc_init(&codec, iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&codec, VP9E_SET_SVC, 1), VPX_CODEC_OK); + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, kWidth, kHeight); + ASSERT_NE(image, nullptr); + + for (int f = 0; f < kFrames; ++f) { + vpx_svc_layer_id_t layer_id = {}; + layer_id.spatial_layer_id = 0; + if (f % 4 == 0) + layer_id.temporal_layer_id = 0; + else if (f % 2 == 0) + layer_id.temporal_layer_id = 1; + else if ((f - 1) % 2 == 0) + layer_id.temporal_layer_id = 2; + ASSERT_EQ(vpx_codec_control(&codec, VP9E_SET_SVC_LAYER_ID, &layer_id), + VPX_CODEC_OK); + const int flags = (f == 0) ? VPX_EFLAG_FORCE_KF : 0; + ASSERT_EQ(vpx_codec_encode(&codec, image, f, 1, flags, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_codec_iter_t iter = nullptr; + while (vpx_codec_get_cx_data(&codec, &iter) != nullptr) { + } + } + ASSERT_EQ(vpx_codec_encode(&codec, nullptr, kFrames, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_codec_iter_t iter = nullptr; + while (vpx_codec_get_cx_data(&codec, &iter) != nullptr) { + } + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&codec), VPX_CODEC_OK); +} + +// Test for SSIM tuning with resolution change: bug: 512508456. +TEST(EncodeAPI, BuganizerSSIMHeapOverflow) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_w = 16; + cfg.g_h = 16; + cfg.g_threads = 1; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 0; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + // Set VP8_TUNE_SSIM. + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_TUNING, VP8_TUNE_SSIM), + VPX_CODEC_OK); + + vpx_image_t *img = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(img, nullptr); + + // Encode first frame + ASSERT_EQ(vpx_codec_encode(&enc, img, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Change resolution to larger size. + cfg.g_w = 4096; + cfg.g_h = 4096; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + vpx_img_free(img); + img = CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(img, nullptr); + + // Encode second frame. + ASSERT_EQ(vpx_codec_encode(&enc, img, 1, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + vpx_img_free(img); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +// Configure spatial layers and encode first superframe with 0 layer bitrates +// for enhancement layers, and start with SL1 (don't call encoder for SL0). +// This causes an empty superframe. Bug: 508317885. +TEST(EncodeAPI, Vp9SvcEmptySuperframe) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 640; + cfg.g_h = 360; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 0; + cfg.rc_end_usage = VPX_CBR; + cfg.ss_number_layers = 3; + cfg.ts_number_layers = 1; + cfg.rc_dropframe_thresh = 30; + cfg.rc_target_bitrate = 30; + cfg.ss_target_bitrate[0] = 30; + cfg.ss_target_bitrate[1] = 0; + cfg.ss_target_bitrate[2] = 0; + cfg.layer_target_bitrate[0] = 30; + cfg.layer_target_bitrate[1] = 0; + cfg.layer_target_bitrate[2] = 0; + + vpx_codec_ctx_t codec; + ASSERT_EQ(vpx_codec_enc_init(&codec, iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&codec, VP9E_SET_SVC, 1), VPX_CODEC_OK); + + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + vpx_svc_layer_id_t layer_id = {}; + layer_id.spatial_layer_id = 1; + layer_id.temporal_layer_id = 0; + ASSERT_EQ(vpx_codec_control(&codec, VP9E_SET_SVC_LAYER_ID, &layer_id), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_encode(&codec, image, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + layer_id.spatial_layer_id = 2; + layer_id.temporal_layer_id = 0; + ASSERT_EQ(vpx_codec_control(&codec, VP9E_SET_SVC_LAYER_ID, &layer_id), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_encode(&codec, image, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&codec), VPX_CODEC_OK); +} + +// Increase the resolution with vpx_codec_enc_config_set() to a size whose +// context buffers exceed VPX_MAX_ALLOCABLE_MEMORY, then destroy the encoder. +// The failed reallocation must not leave freed buffers referenced by the +// encoder. The allocation limit is only low enough to fail deterministically +// when size_t is 32 bits. +#if SIZE_MAX <= UINT32_MAX +TEST(EncodeAPI, ConfigResizeAllocFailureVp9) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + vpx_codec_ctx_t enc; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + EXPECT_NO_FATAL_FAILURE(InitCodec(*iface, 64, 64, &enc, &cfg)); + + vpx_image_t *img = CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, 64, 64); + ASSERT_NE(img, nullptr); + ASSERT_EQ(vpx_codec_encode(&enc, img, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(img); + + // 46340 is the largest size whose square fits in an int, as frame size + // computations in the encoder require. + cfg.g_w = 46340; + cfg.g_h = 46340; + EXPECT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_MEM_ERROR); + + EXPECT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} +#endif // SIZE_MAX <= UINT32_MAX + +// Encode one pass VBR with nonzero-lookahead, with resize and realtime mode. +// Test for the re-allocation of count_arf_frame_usage and +// count_lastgolden_frame_usage. Bug: 515433297. +TEST(EncodeAPI, ResizeOnePassVbrAltrefUsageBug) { + vpx_codec_ctx_t codec; + vpx_codec_enc_cfg_t cfg; + vpx_image_t *image; + + const int initial_width = 16; + const int initial_height = 16; + const int new_width = 4096; + const int new_height = 4096; + + ASSERT_EQ(vpx_codec_enc_config_default(vpx_codec_vp9_cx(), &cfg, 0), + VPX_CODEC_OK); + + cfg.g_w = initial_width; + cfg.g_h = initial_height; + cfg.g_threads = 1; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 1; + cfg.rc_end_usage = VPX_VBR; + ASSERT_EQ(vpx_codec_enc_init(&codec, vpx_codec_vp9_cx(), &cfg, 0), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&codec, VP8E_SET_CPUUSED, 5), VPX_CODEC_OK); + + image = CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + ASSERT_EQ(vpx_codec_encode(&codec, image, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + cfg.g_w = new_width; + cfg.g_h = new_height; + ASSERT_EQ(vpx_codec_enc_config_set(&codec, &cfg), VPX_CODEC_OK); + + vpx_img_free(image); + image = CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + for (int i = 1; i < 30; i++) { + ASSERT_EQ(vpx_codec_encode(&codec, image, i, 1, 0, VPX_DL_GOOD_QUALITY), + VPX_CODEC_OK); + } + + vpx_img_free(image); + vpx_codec_destroy(&codec); +} + +// Resize with PERCEPTUAL_AQ. Bug: 515431489. +TEST(EncodeAPI, PerceptualAQKMeansHeapOverflow) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_ctx_t enc; + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 16; + cfg.g_h = 16; + cfg.g_threads = 1; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 0; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + vpx_image_t *img = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(img, nullptr); + + ASSERT_EQ(vpx_codec_encode(&enc, img, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_AQ_MODE, PERCEPTUAL_AQ), + VPX_CODEC_OK); + + cfg.g_w = 4096; + cfg.g_h = 4096; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + vpx_img_free(img); + img = CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(img, nullptr); + + ASSERT_EQ(vpx_codec_encode(&enc, img, 1, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + vpx_img_free(img); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +// Reproduces a VP9 encoder assertion failure / SEGV crash caused by +// superblock search failure under specific scaling and rate control scenarios. +// Bug: 479149056 +TEST(EncodeAPI, VP9OssFuzz479149056) { + VP9Encoder encoder(3, 1, VPX_BITS_8, VPX_IMG_FMT_I422); + encoder.Configure(/*threads=*/2, /*width=*/33, /*height=*/341, VPX_CBR, + VPX_DL_GOOD_QUALITY); + encoder.Encode(/*key_frame=*/true); + encoder.Encode(/*key_frame=*/false); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/14, /*width=*/29, /*height=*/177, VPX_VBR, + VPX_DL_GOOD_QUALITY); + encoder.Encode(/*key_frame=*/false); + encoder.Configure(/*threads=*/0, /*width=*/33, /*height=*/337, VPX_CBR, + VPX_DL_REALTIME); + encoder.Configure(/*threads=*/0, /*width=*/33, /*height=*/341, VPX_VBR, + VPX_DL_GOOD_QUALITY); + encoder.Encode(/*key_frame=*/false); + encoder.Encode(/*key_frame=*/false); + encoder.Encode(/*key_frame=*/false); + encoder.Encode(/*key_frame=*/false); +} + +// Bug: 526717473. Resize up followed by activating AQ_MODE 3. +// This triggers an issue because the SVC layer buffers are not reallocated +// during the resize (since AQ_MODE is off), and they are also not reallocated +// when AQ_MODE is later turned on (since the resolution hasn't changed since +// the last config update). +TEST(EncodeAPI, SvcResolutionChangeAq3Vbr) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 320; + cfg.g_h = 240; + cfg.ss_number_layers = 2; + cfg.ts_number_layers = 1; + cfg.g_threads = 1; + cfg.g_lag_in_frames = 0; + cfg.rc_end_usage = VPX_VBR; + cfg.rc_target_bitrate = 200; + cfg.ss_target_bitrate[0] = 100; + cfg.ss_target_bitrate[1] = 200; + cfg.ts_target_bitrate[0] = 200; + cfg.layer_target_bitrate[0] = 100; + cfg.layer_target_bitrate[1] = 200; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 7), VPX_CODEC_OK); + + vpx_svc_extra_cfg_t svc_cfg = {}; + for (int i = 0; i < VPX_MAX_LAYERS; ++i) { + svc_cfg.max_quantizers[i] = 58; + svc_cfg.min_quantizers[i] = 2; + svc_cfg.scaling_factor_num[i] = 1; + svc_cfg.scaling_factor_den[i] = 1; + } + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_PARAMETERS, &svc_cfg), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC, 1), VPX_CODEC_OK); + + // Resize up. + cfg.g_w = 640; + cfg.g_h = 480; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + // Set AQ mode 3. + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_AQ_MODE, 3), VPX_CODEC_OK); + + // Encode. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + ASSERT_EQ(vpx_codec_encode(&enc, image, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(image); + + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +// Bug: 526717473. +TEST(EncodeAPI, SvcResolutionChangeAq3Cbr) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 320; + cfg.g_h = 240; + cfg.ss_number_layers = 2; + cfg.ts_number_layers = 1; + cfg.g_threads = 1; + cfg.g_lag_in_frames = 0; + cfg.rc_end_usage = VPX_CBR; + cfg.rc_target_bitrate = 200; + cfg.ss_target_bitrate[0] = 100; + cfg.ss_target_bitrate[1] = 200; + cfg.ts_target_bitrate[0] = 200; + cfg.layer_target_bitrate[0] = 100; + cfg.layer_target_bitrate[1] = 200; + + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 7), VPX_CODEC_OK); + + vpx_svc_extra_cfg_t svc_cfg = {}; + for (int i = 0; i < VPX_MAX_LAYERS; ++i) { + svc_cfg.max_quantizers[i] = 58; + svc_cfg.min_quantizers[i] = 2; + svc_cfg.scaling_factor_num[i] = 1; + svc_cfg.scaling_factor_den[i] = 1; + } + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_PARAMETERS, &svc_cfg), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC, 1), VPX_CODEC_OK); + + // Resize up to 640x480 while AQ_MODE is still 0. + cfg.g_w = 640; + cfg.g_h = 480; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + // Set AQ mode 3. + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_AQ_MODE, 3), VPX_CODEC_OK); + + // Encode at 640x480. + vpx_image_t *const image = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, 640, 480); + ASSERT_NE(image, nullptr); + ASSERT_EQ(vpx_codec_encode(&enc, image, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(image); + + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} +// Bug: 540943267. +TEST(EncodeAPI, ResizeRealtimeSourceSadOverflow) { + vpx_codec_ctx_t codec; + vpx_codec_enc_cfg_t cfg; + vpx_image_t *image; + + constexpr int kInitialWidth = 16; + constexpr int kInitialHeight = 16; + constexpr int kNewWidth = 4096; + constexpr int kNewHeight = 4096; + + ASSERT_EQ(vpx_codec_enc_config_default(vpx_codec_vp9_cx(), &cfg, 0), + VPX_CODEC_OK); + + cfg.g_w = kInitialWidth; + cfg.g_h = kInitialHeight; + cfg.g_threads = 1; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 0; + ASSERT_EQ(vpx_codec_enc_init(&codec, vpx_codec_vp9_cx(), &cfg, 0), + VPX_CODEC_OK); + // Set speed 6 to enable use_source_sad allocation + ASSERT_EQ(vpx_codec_control(&codec, VP8E_SET_CPUUSED, 6), VPX_CODEC_OK); + + image = CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + ASSERT_EQ(vpx_codec_encode(&codec, image, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + cfg.g_w = kNewWidth; + cfg.g_h = kNewHeight; + ASSERT_EQ(vpx_codec_enc_config_set(&codec, &cfg), VPX_CODEC_OK); + + vpx_img_free(image); + image = CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + // Encode second frame. Without the fix, this will cause heap corruption + // which will trigger a crash during encode or on codec destroy. + ASSERT_EQ(vpx_codec_encode(&codec, image, 1, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&codec), VPX_CODEC_OK); +} + +#if CONFIG_VP9_TEMPORAL_DENOISING +uint64_t CalcPlaneSse(const uint8_t *a, int stride_a, const uint8_t *b, + int stride_b, int width, int height) { + uint64_t sse = 0; + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + const int diff = static_cast(a[y * stride_a + x]) - + static_cast(b[y * stride_b + x]); + sse += static_cast(diff * diff); + } + } + return sse; +} + +TEST(EncodeAPI, VP9DenoiserPsnr) { + constexpr int kWidth = 64; + constexpr int kHeight = 64; + + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_w = kWidth; + cfg.g_h = kHeight; + cfg.g_lag_in_frames = 0; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.rc_end_usage = VPX_CBR; + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, VPX_CODEC_USE_PSNR), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 6), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_NOISE_SENSITIVITY, 1), + VPX_CODEC_OK); + + // Frame 0 (keyframe, Y=128) initializes the temporal denoiser reference. + vpx_image_t *const img = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, kWidth, kHeight); + ASSERT_NE(img, nullptr); + ASSERT_EQ(vpx_codec_encode(&enc, img, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + // Frame 1 (inter frame, Y=130): small luma perturbation is filtered back + // toward 128 in-place in cpi->Source by the temporal denoiser. + for (int y = 0; y < kHeight; ++y) { + memset(img->planes[VPX_PLANE_Y] + y * img->stride[VPX_PLANE_Y], 130, + kWidth); + } + ASSERT_EQ(vpx_codec_encode(&enc, img, 1, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + + const vpx_image_t *const recon = vpx_codec_get_preview_frame(&enc); + ASSERT_NE(recon, nullptr); + + const uint64_t expected_sse_y = CalcPlaneSse( + img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y], + recon->planes[VPX_PLANE_Y], recon->stride[VPX_PLANE_Y], kWidth, kHeight); + const uint64_t expected_sse_u = + CalcPlaneSse(img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U], + recon->planes[VPX_PLANE_U], recon->stride[VPX_PLANE_U], + kWidth / 2, kHeight / 2); + const uint64_t expected_sse_v = + CalcPlaneSse(img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V], + recon->planes[VPX_PLANE_V], recon->stride[VPX_PLANE_V], + kWidth / 2, kHeight / 2); + EXPECT_GT(expected_sse_y, 0u); + + const vpx_codec_cx_pkt_t *pkt; + vpx_codec_iter_t iter = nullptr; + bool had_psnr_pkt = false; + while ((pkt = vpx_codec_get_cx_data(&enc, &iter)) != nullptr) { + if (pkt->kind == VPX_CODEC_PSNR_PKT) { + had_psnr_pkt = true; + EXPECT_EQ(pkt->data.psnr.sse[0], + expected_sse_y + expected_sse_u + expected_sse_v); + EXPECT_EQ(pkt->data.psnr.sse[1], expected_sse_y); + EXPECT_EQ(pkt->data.psnr.sse[2], expected_sse_u); + EXPECT_EQ(pkt->data.psnr.sse[3], expected_sse_v); + } + } + EXPECT_TRUE(had_psnr_pkt); + + vpx_img_free(img); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(EncodeAPI, VP9DenoiserResolutionChange) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + cfg.g_w = 320; + cfg.g_h = 240; + cfg.g_lag_in_frames = 0; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.rc_end_usage = VPX_CBR; + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 6), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_NOISE_SENSITIVITY, 1), + VPX_CODEC_OK); + + vpx_image_t *img = + CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(img, nullptr); + ASSERT_EQ(vpx_codec_encode(&enc, img, 0, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(img); + + // Increase frame height while temporal denoiser is enabled. + cfg.g_h = 720; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + img = CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(img, nullptr); + ASSERT_EQ( + vpx_codec_encode(&enc, img, 1, 1, VPX_EFLAG_FORCE_KF, VPX_DL_REALTIME), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_encode(&enc, img, 2, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(img); + + // Disable noise sensitivity, increase width, and re-enable noise sensitivity. + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_NOISE_SENSITIVITY, 0), + VPX_CODEC_OK); + cfg.g_w = 640; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_NOISE_SENSITIVITY, 1), + VPX_CODEC_OK); + + img = CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(img, nullptr); + ASSERT_EQ( + vpx_codec_encode(&enc, img, 3, 1, VPX_EFLAG_FORCE_KF, VPX_DL_REALTIME), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_encode(&enc, img, 4, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(img); + + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} +#endif // CONFIG_VP9_TEMPORAL_DENOISING + +// Bug: 575939911. +// Test external resolution changes via vpx_codec_enc_config_set() in 1-pass +// CBR SVC mode (1 spatial layer, 3 temporal layers, RESIZE_NONE): +// 1. Initialize and encode 1 frame at 1280x720. +// 2. Downscale via vpx_codec_enc_config_set() to 80x46 (> 2x downscale, which +// exceeds the valid reference scaling ratio and forces a keyframe) and +// encode 5 frames so reference buffer slots hold 80x46 frames. +// 3. Upscale via vpx_codec_enc_config_set() back to 1280x720. Since 1280x720 +// is within the 16x maximum upscale ratio of 80x46 (1280 <= 16 * 80 and +// 720 <= 16 * 46), no keyframe is forced and the 1280x720 inter frames +// reference the unscaled 80x46 buffers while vp9_scale_references() is +// skipped in SVC mode. +TEST(EncodeAPI, SvcResizeUnscaledReferenceMotionSearch) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + // Configure 1-pass CBR with 1 spatial layer and 3 temporal layers (L1T3). + cfg.g_w = 1280; + cfg.g_h = 720; + cfg.g_lag_in_frames = 0; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.rc_end_usage = VPX_CBR; + cfg.rc_target_bitrate = 1000; + cfg.ss_number_layers = 1; + cfg.ts_number_layers = 3; + cfg.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_0212; + cfg.ts_target_bitrate[0] = 400; + cfg.ts_target_bitrate[1] = 600; + cfg.ts_target_bitrate[2] = 1000; + cfg.layer_target_bitrate[0] = 400; + cfg.layer_target_bitrate[1] = 600; + cfg.layer_target_bitrate[2] = 1000; + cfg.ts_rate_decimator[0] = 4; + cfg.ts_rate_decimator[1] = 2; + cfg.ts_rate_decimator[2] = 1; + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + // Use speed >= 5 (non-RD pickmode) and screen content mode. + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 7), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_TUNE_CONTENT, VP9E_CONTENT_SCREEN), + VPX_CODEC_OK); + + // Enable SVC with 1:1 layer scaling factors. + vpx_svc_extra_cfg_t svc_cfg = {}; + for (int i = 0; i < VPX_MAX_LAYERS; ++i) { + svc_cfg.max_quantizers[i] = 56; + svc_cfg.min_quantizers[i] = 2; + svc_cfg.scaling_factor_num[i] = 1; + svc_cfg.scaling_factor_den[i] = 1; + } + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_PARAMETERS, &svc_cfg), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC, 1), VPX_CODEC_OK); + + // Reconfigure across three resolution batches: + // 1280x720 (1 frame) -> 80x46 (5 frames) -> 1280x720 (4 frames). + struct Batch { + unsigned int w; + unsigned int h; + int count; + }; + const Batch kBatches[] = { { 1280, 720, 1 }, + { 80, 46, 5 }, + { 1280, 720, 4 } }; + + libvpx_test::ACMRandom rng(libvpx_test::ACMRandom::DeterministicSeed()); + vpx_codec_pts_t pts = 0; + for (const auto &batch : kBatches) { + cfg.g_w = batch.w; + cfg.g_h = batch.h; + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + vpx_image_t *const img = + vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, batch.w, batch.h, 1); + ASSERT_NE(img, nullptr); + + // Fill each frame with pseudo-random noise so ZEROMV does not early-exit + // before NEWMV is evaluated in vp9_pick_inter_mode(). + for (int i = 0; i < batch.count; ++i) { + for (int plane = 0; plane < 3; ++plane) { + const unsigned int plane_w = plane ? (batch.w + 1) >> 1 : batch.w; + const unsigned int plane_h = plane ? (batch.h + 1) >> 1 : batch.h; + for (unsigned int y = 0; y < plane_h; ++y) { + uint8_t *const row = img->planes[plane] + y * img->stride[plane]; + for (unsigned int x = 0; x < plane_w; ++x) { + row[x] = rng.Rand8(); + } + } + } + ASSERT_EQ(vpx_codec_encode(&enc, img, pts++, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + } + vpx_img_free(img); + } + + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +// Bug: 575903327. +// Test that dynamically enabling a higher spatial layer (with SL0 disabled) +// in 1-pass CBR flexible SVC mode at speed 8 does not use a stale/freed +// reference buffer pointer in get_estimated_pred() when the new spatial +// layer's LAST_FRAME buffer slot is unallocated (NULL). +TEST(EncodeAPI, SvcGetEstimatedPredStaleReference) { + vpx_codec_iface_t *const iface = vpx_codec_vp9_cx(); + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + + cfg.g_w = 64; + cfg.g_h = 36; + cfg.g_lag_in_frames = 0; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.rc_end_usage = VPX_CBR; + cfg.rc_target_bitrate = 60; + cfg.g_threads = 2; + cfg.ss_number_layers = 3; + cfg.ts_number_layers = 1; + cfg.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS; + cfg.ss_target_bitrate[0] = 60; + cfg.layer_target_bitrate[0] = 60; + cfg.ss_target_bitrate[1] = 0; + cfg.layer_target_bitrate[1] = 0; + cfg.ss_target_bitrate[2] = 0; + cfg.layer_target_bitrate[2] = 0; + cfg.ts_rate_decimator[0] = 1; + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, 8), VPX_CODEC_OK); + + vpx_svc_extra_cfg_t svc_cfg = {}; + for (int i = 0; i < VPX_MAX_LAYERS; ++i) { + svc_cfg.max_quantizers[i] = 56; + svc_cfg.min_quantizers[i] = 2; + svc_cfg.scaling_factor_num[i] = 1; + svc_cfg.scaling_factor_den[i] = 1; + svc_cfg.speed_per_layer[i] = 8; + } + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_PARAMETERS, &svc_cfg), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC, 1), VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_INTER_LAYER_PRED, + INTER_LAYER_PRED_OFF), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_ROW_MT, 1), VPX_CODEC_OK); + + // Encode 2 frames on SL0 (64x36) using buffer slot 0. + vpx_image_t *img = CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, 64, 36); + ASSERT_NE(img, nullptr); + vpx_codec_pts_t pts = 0; + for (int i = 0; i < 2; ++i) { + vpx_svc_layer_id_t layer_id = {}; + layer_id.spatial_layer_id = 0; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_LAYER_ID, &layer_id), + VPX_CODEC_OK); + + vpx_svc_ref_frame_config_t ref_cfg = {}; + ref_cfg.lst_fb_idx[0] = 0; + ref_cfg.reference_last[0] = (i > 0) ? 1 : 0; + ref_cfg.update_buffer_slot[0] = (1 << 0); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_REF_FRAME_CONFIG, &ref_cfg), + VPX_CODEC_OK); + + ASSERT_EQ( + vpx_codec_encode(&enc, img, pts++, 1, (i == 0) ? VPX_EFLAG_FORCE_KF : 0, + VPX_DL_REALTIME), + VPX_CODEC_OK); + } + vpx_img_free(img); + + // Disable SL0 (64x36) and enable SL1 (128x72) and SL2 (256x144) on + // previously unused buffer slots 1 and 2 without forcing a keyframe. + cfg.g_w = 256; + cfg.g_h = 144; + cfg.rc_target_bitrate = 670; + cfg.ss_target_bitrate[0] = 0; + cfg.layer_target_bitrate[0] = 0; + cfg.ss_target_bitrate[1] = 170; + cfg.layer_target_bitrate[1] = 170; + cfg.ss_target_bitrate[2] = 500; + cfg.layer_target_bitrate[2] = 500; + + svc_cfg.scaling_factor_num[0] = 1; + svc_cfg.scaling_factor_den[0] = 4; + svc_cfg.scaling_factor_num[1] = 1; + svc_cfg.scaling_factor_den[1] = 2; + svc_cfg.scaling_factor_num[2] = 1; + svc_cfg.scaling_factor_den[2] = 1; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_PARAMETERS, &svc_cfg), + VPX_CODEC_OK); + ASSERT_EQ(vpx_codec_enc_config_set(&enc, &cfg), VPX_CODEC_OK); + + vpx_svc_layer_id_t layer_id = {}; + layer_id.spatial_layer_id = 1; + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_LAYER_ID, &layer_id), + VPX_CODEC_OK); + + vpx_svc_ref_frame_config_t ref_cfg = {}; + ref_cfg.lst_fb_idx[1] = 1; + ref_cfg.reference_last[1] = 0; + ref_cfg.update_buffer_slot[1] = (1 << 1); + ref_cfg.lst_fb_idx[2] = 2; + ref_cfg.reference_last[2] = 0; + ref_cfg.update_buffer_slot[2] = (1 << 2); + ASSERT_EQ(vpx_codec_control(&enc, VP9E_SET_SVC_REF_FRAME_CONFIG, &ref_cfg), + VPX_CODEC_OK); + + img = CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, 256, 144); + ASSERT_NE(img, nullptr); + ASSERT_EQ(vpx_codec_encode(&enc, img, pts++, 1, 0, VPX_DL_REALTIME), + VPX_CODEC_OK); + vpx_img_free(img); + + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} +#endif // CONFIG_VP9_ENCODER + } // namespace diff --git a/libs/libvpx/test/encode_perf_test.cc b/libs/libvpx/test/encode_perf_test.cc index 142a55952b..75d6838f60 100644 --- a/libs/libvpx/test/encode_perf_test.cc +++ b/libs/libvpx/test/encode_perf_test.cc @@ -7,15 +7,15 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include #include -#include "third_party/googletest/src/include/gtest/gtest.h" -#include "./vpx_config.h" -#include "./vpx_version.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" #include "test/util.h" #include "test/y4m_video_source.h" +#include "vpx/vpx_codec.h" #include "vpx_ports/vpx_timer.h" namespace { @@ -61,9 +61,9 @@ class VP9EncodePerfTest : EncoderTest(GET_PARAM(0)), min_psnr_(kMaxPsnr), nframes_(0), encoding_mode_(GET_PARAM(1)), speed_(0), threads_(1) {} - virtual ~VP9EncodePerfTest() {} + ~VP9EncodePerfTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(encoding_mode_); @@ -82,8 +82,8 @@ class VP9EncodePerfTest cfg_.g_threads = threads_; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { const int log2_tile_columns = 3; encoder->Control(VP8E_SET_CPUUSED, speed_); @@ -93,19 +93,19 @@ class VP9EncodePerfTest } } - virtual void BeginPassHook(unsigned int /*pass*/) { + void BeginPassHook(unsigned int /*pass*/) override { min_psnr_ = kMaxPsnr; nframes_ = 0; } - virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { + void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) override { if (pkt->data.psnr.psnr[0] < min_psnr_) { min_psnr_ = pkt->data.psnr.psnr[0]; } } // for performance reasons don't decode - virtual bool DoDecode() const { return false; } + bool DoDecode() const override { return false; } double min_psnr() const { return min_psnr_; } @@ -169,7 +169,7 @@ TEST_P(VP9EncodePerfTest, PerfTest) { printf("{\n"); printf("\t\"type\" : \"encode_perf_test\",\n"); - printf("\t\"version\" : \"%s\",\n", VERSION_STRING_NOSP); + printf("\t\"version\" : \"%s\",\n", vpx_codec_version_str()); printf("\t\"videoName\" : \"%s\",\n", display_name.c_str()); printf("\t\"encodeTimeSecs\" : %f,\n", elapsed_secs); printf("\t\"totalFrames\" : %u,\n", frames); diff --git a/libs/libvpx/test/encode_test_driver.cc b/libs/libvpx/test/encode_test_driver.cc index 1ce39eaeff..770f410d80 100644 --- a/libs/libvpx/test/encode_test_driver.cc +++ b/libs/libvpx/test/encode_test_driver.cc @@ -11,7 +11,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "test/codec_factory.h" @@ -52,7 +52,8 @@ void Encoder::InitEncoder(VideoSource *video) { } } -void Encoder::EncodeFrame(VideoSource *video, const unsigned long frame_flags) { +void Encoder::EncodeFrame(VideoSource *video, + const vpx_enc_frame_flags_t frame_flags) { if (video->img()) { EncodeFrameInternal(*video, frame_flags); } else { @@ -70,7 +71,7 @@ void Encoder::EncodeFrame(VideoSource *video, const unsigned long frame_flags) { } void Encoder::EncodeFrameInternal(const VideoSource &video, - const unsigned long frame_flags) { + const vpx_enc_frame_flags_t frame_flags) { vpx_codec_err_t res; const vpx_image_t *img = video.img(); @@ -169,7 +170,7 @@ void EncoderTest::RunLoop(VideoSource *video) { ASSERT_TRUE(passes_ == 1 || passes_ == 2); for (unsigned int pass = 0; pass < passes_; pass++) { - last_pts_ = 0; + vpx_codec_pts_t last_pts = 0; if (passes_ == 1) { cfg_.g_pass = VPX_RC_ONE_PASS; @@ -225,8 +226,8 @@ void EncoderTest::RunLoop(VideoSource *video) { has_dxdata = true; } - ASSERT_GE(pkt->data.frame.pts, last_pts_); - last_pts_ = pkt->data.frame.pts; + ASSERT_GE(pkt->data.frame.pts, last_pts); + last_pts = pkt->data.frame.pts; FramePktHook(pkt); break; diff --git a/libs/libvpx/test/encode_test_driver.h b/libs/libvpx/test/encode_test_driver.h index 7085945f6a..c9a7c154f2 100644 --- a/libs/libvpx/test/encode_test_driver.h +++ b/libs/libvpx/test/encode_test_driver.h @@ -13,13 +13,13 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER #include "vpx/vp8cx.h" #endif -#include "vpx/vpx_encoder.h" +#include "vpx/vpx_tpl.h" namespace libvpx_test { @@ -33,15 +33,24 @@ enum TestMode { kTwoPassGood, kTwoPassBest }; + +#if CONFIG_REALTIME_ONLY +#define ALL_TEST_MODES ::testing::Values(::libvpx_test::kRealTime) +#define ONE_PASS_TEST_MODES ::testing::Values(::libvpx_test::kRealTime) +#define ONE_OR_TWO_PASS_TEST_MODES ::testing::Values(::libvpx_test::kRealTime) +#else #define ALL_TEST_MODES \ ::testing::Values(::libvpx_test::kRealTime, ::libvpx_test::kOnePassGood, \ ::libvpx_test::kOnePassBest, ::libvpx_test::kTwoPassGood, \ ::libvpx_test::kTwoPassBest) - #define ONE_PASS_TEST_MODES \ ::testing::Values(::libvpx_test::kRealTime, ::libvpx_test::kOnePassGood, \ ::libvpx_test::kOnePassBest) +#define ONE_OR_TWO_PASS_TEST_MODES \ + ::testing::Values(::libvpx_test::kOnePassGood, ::libvpx_test::kTwoPassGood) +#endif + #define TWO_PASS_TEST_MODES \ ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kTwoPassBest) @@ -86,7 +95,7 @@ class TwopassStatsStore { // level of abstraction will be fleshed out as more tests are written. class Encoder { public: - Encoder(vpx_codec_enc_cfg_t cfg, unsigned long deadline, + Encoder(vpx_codec_enc_cfg_t cfg, vpx_enc_deadline_t deadline, const unsigned long init_flags, TwopassStatsStore *stats) : cfg_(cfg), deadline_(deadline), init_flags_(init_flags), stats_(stats) { memset(&encoder_, 0, sizeof(encoder_)); @@ -103,7 +112,7 @@ class Encoder { } // This is a thin wrapper around vpx_codec_encode(), so refer to // vpx_encoder.h for its semantics. - void EncodeFrame(VideoSource *video, const unsigned long frame_flags); + void EncodeFrame(VideoSource *video, vpx_enc_frame_flags_t frame_flags); // Convenience wrapper for EncodeFrame() void EncodeFrame(VideoSource *video) { EncodeFrame(video, 0); } @@ -153,6 +162,11 @@ class Encoder { const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg); ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); } + + void Control(int ctrl_id, VpxTplGopStats *arg) { + const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg); + ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); + } #endif // CONFIG_VP9_ENCODER #if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER @@ -172,7 +186,7 @@ class Encoder { cfg_ = *cfg; } - void set_deadline(unsigned long deadline) { deadline_ = deadline; } + void set_deadline(vpx_enc_deadline_t deadline) { deadline_ = deadline; } protected: virtual vpx_codec_iface_t *CodecInterface() const = 0; @@ -184,14 +198,14 @@ class Encoder { // Encode an image void EncodeFrameInternal(const VideoSource &video, - const unsigned long frame_flags); + vpx_enc_frame_flags_t frame_flags); // Flush the encoder on EOS void Flush(); vpx_codec_ctx_t encoder_; vpx_codec_enc_cfg_t cfg_; - unsigned long deadline_; + vpx_enc_deadline_t deadline_; unsigned long init_flags_; TwopassStatsStore *stats_; }; @@ -206,8 +220,7 @@ class Encoder { class EncoderTest { protected: explicit EncoderTest(const CodecFactory *codec) - : codec_(codec), abort_(false), init_flags_(0), frame_flags_(0), - last_pts_(0) { + : codec_(codec), abort_(false), init_flags_(0), frame_flags_(0) { // Default to 1 thread. cfg_.g_threads = 1; } @@ -260,7 +273,7 @@ class EncoderTest { const CodecFactory *codec_; // Hook to determine whether to decode frame after encoding - virtual bool DoDecode() const { return 1; } + virtual bool DoDecode() const { return true; } // Hook to handle encode/decode mismatch virtual void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2); @@ -287,11 +300,10 @@ class EncoderTest { vpx_codec_enc_cfg_t cfg_; vpx_codec_dec_cfg_t dec_cfg_; unsigned int passes_; - unsigned long deadline_; + vpx_enc_deadline_t deadline_; TwopassStatsStore stats_; unsigned long init_flags_; - unsigned long frame_flags_; - vpx_codec_pts_t last_pts_; + vpx_enc_frame_flags_t frame_flags_; }; } // namespace libvpx_test diff --git a/libs/libvpx/test/error_resilience_test.cc b/libs/libvpx/test/error_resilience_test.cc index 45a327ec2f..9bd43b72bf 100644 --- a/libs/libvpx/test/error_resilience_test.cc +++ b/libs/libvpx/test/error_resilience_test.cc @@ -8,11 +8,12 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" #include "test/util.h" +#include "vpx_config.h" namespace { @@ -30,7 +31,7 @@ class ErrorResilienceTestLarge Reset(); } - virtual ~ErrorResilienceTestLarge() {} + ~ErrorResilienceTestLarge() override = default; void Reset() { error_nframes_ = 0; @@ -38,19 +39,19 @@ class ErrorResilienceTestLarge pattern_switch_ = 0; } - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(encoding_mode_); } - virtual void BeginPassHook(unsigned int /*pass*/) { + void BeginPassHook(unsigned int /*pass*/) override { psnr_ = 0.0; nframes_ = 0; mismatch_psnr_ = 0.0; mismatch_nframes_ = 0; } - virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { + void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) override { psnr_ += pkt->data.psnr.psnr[0]; nframes_++; } @@ -90,7 +91,7 @@ class ErrorResilienceTestLarge return frame_flags; } - virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video) { + void PreEncodeFrameHook(libvpx_test::VideoSource *video) override { frame_flags_ &= ~(VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF); // For temporal layer case. @@ -129,21 +130,21 @@ class ErrorResilienceTestLarge return 0.0; } - virtual bool DoDecode() const { + bool DoDecode() const override { if (error_nframes_ > 0 && (cfg_.g_pass == VPX_RC_LAST_PASS || cfg_.g_pass == VPX_RC_ONE_PASS)) { for (unsigned int i = 0; i < error_nframes_; ++i) { if (error_frames_[i] == nframes_ - 1) { std::cout << " Skipping decoding frame: " << error_frames_[i] << "\n"; - return 0; + return false; } } } - return 1; + return true; } - virtual void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2) { + void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2) override { double mismatch_psnr = compute_psnr(img1, img2); mismatch_psnr_ += mismatch_psnr; ++mismatch_nframes_; @@ -194,6 +195,10 @@ class ErrorResilienceTestLarge }; TEST_P(ErrorResilienceTestLarge, OnVersusOff) { +#if CONFIG_REALTIME_ONLY + GTEST_SKIP() + << "Non-zero g_lag_in_frames is unsupported with CONFIG_REALTIME_ONLY"; +#else const vpx_rational timebase = { 33333333, 1000000000 }; cfg_.g_timebase = timebase; cfg_.rc_target_bitrate = 2000; @@ -222,6 +227,7 @@ TEST_P(ErrorResilienceTestLarge, OnVersusOff) { EXPECT_GE(psnr_ratio, 0.9); EXPECT_LE(psnr_ratio, 1.1); } +#endif // CONFIG_REALTIME_ONLY } // Check for successful decoding and no encoder/decoder mismatch @@ -381,7 +387,7 @@ class ErrorResilienceTestLargeCodecControls Reset(); } - virtual ~ErrorResilienceTestLargeCodecControls() {} + ~ErrorResilienceTestLargeCodecControls() override = default; void Reset() { last_pts_ = 0; @@ -393,7 +399,7 @@ class ErrorResilienceTestLargeCodecControls duration_ = 0.0; } - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(encoding_mode_); } @@ -460,8 +466,8 @@ class ErrorResilienceTestLargeCodecControls return layer_id; } - virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, - libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(libvpx_test::VideoSource *video, + libvpx_test::Encoder *encoder) override { if (cfg_.ts_number_layers > 1) { int layer_id = SetLayerId(video->frame(), cfg_.ts_number_layers); int frame_flags = SetFrameFlags(video->frame(), cfg_.ts_number_layers); @@ -476,7 +482,7 @@ class ErrorResilienceTestLargeCodecControls } } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { // Time since last timestamp = duration. vpx_codec_pts_t duration = pkt->data.frame.pts - last_pts_; if (duration > 1) { @@ -496,7 +502,7 @@ class ErrorResilienceTestLargeCodecControls ++tot_frame_number_; } - virtual void EndPassHook(void) { + void EndPassHook() override { duration_ = (last_pts_ + 1) * timebase_; if (cfg_.ts_number_layers > 1) { for (int layer = 0; layer < static_cast(cfg_.ts_number_layers); diff --git a/libs/libvpx/test/external_frame_buffer_test.cc b/libs/libvpx/test/external_frame_buffer_test.cc index 3bd4a1c473..7b9a836fbc 100644 --- a/libs/libvpx/test/external_frame_buffer_test.cc +++ b/libs/libvpx/test/external_frame_buffer_test.cc @@ -210,13 +210,12 @@ class ExternalFrameBufferMD5Test : DecoderTest(GET_PARAM(::libvpx_test::kCodecFactoryParam)), md5_file_(nullptr), num_buffers_(0) {} - virtual ~ExternalFrameBufferMD5Test() { + ~ExternalFrameBufferMD5Test() override { if (md5_file_ != nullptr) fclose(md5_file_); } - virtual void PreDecodeFrameHook( - const libvpx_test::CompressedVideoSource &video, - libvpx_test::Decoder *decoder) { + void PreDecodeFrameHook(const libvpx_test::CompressedVideoSource &video, + libvpx_test::Decoder *decoder) override { if (num_buffers_ > 0 && video.frame_number() == 0) { // Have libvpx use frame buffers we create. ASSERT_TRUE(fb_list_.CreateBufferList(num_buffers_)); @@ -232,8 +231,8 @@ class ExternalFrameBufferMD5Test << "Md5 file open failed. Filename: " << md5_file_name_; } - virtual void DecompressedFrameHook(const vpx_image_t &img, - const unsigned int frame_number) { + void DecompressedFrameHook(const vpx_image_t &img, + const unsigned int frame_number) override { ASSERT_NE(md5_file_, nullptr); char expected_md5[33]; char junk[128]; @@ -289,7 +288,7 @@ class ExternalFrameBufferTest : public ::testing::Test { ExternalFrameBufferTest() : video_(nullptr), decoder_(nullptr), num_buffers_(0) {} - virtual void SetUp() { + void SetUp() override { video_ = new libvpx_test::WebMVideoSource(kVP9TestFile); ASSERT_NE(video_, nullptr); video_->Init(); @@ -300,7 +299,7 @@ class ExternalFrameBufferTest : public ::testing::Test { ASSERT_NE(decoder_, nullptr); } - virtual void TearDown() { + void TearDown() override { delete decoder_; decoder_ = nullptr; delete video_; @@ -355,7 +354,7 @@ class ExternalFrameBufferTest : public ::testing::Test { class ExternalFrameBufferNonRefTest : public ExternalFrameBufferTest { protected: - virtual void SetUp() { + void SetUp() override { video_ = new libvpx_test::WebMVideoSource(kVP9NonRefTestFile); ASSERT_NE(video_, nullptr); video_->Init(); diff --git a/libs/libvpx/test/fdct8x8_test.cc b/libs/libvpx/test/fdct8x8_test.cc index 83d1ff1429..4c2cbf43fd 100644 --- a/libs/libvpx/test/fdct8x8_test.cc +++ b/libs/libvpx/test/fdct8x8_test.cc @@ -13,7 +13,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp9_rtcd.h" #include "./vpx_dsp_rtcd.h" @@ -23,6 +23,7 @@ #include "test/util.h" #include "vp9/common/vp9_entropy.h" #include "vp9/common/vp9_scan.h" +#include "vpx_config.h" #include "vpx/vpx_codec.h" #include "vpx/vpx_integer.h" #include "vpx_ports/mem.h" @@ -37,16 +38,16 @@ const double kPi = 3.141592653589793238462643383279502884; const int kSignBiasMaxDiff255 = 1500; const int kSignBiasMaxDiff15 = 10000; -typedef void (*FdctFunc)(const int16_t *in, tran_low_t *out, int stride); -typedef void (*IdctFunc)(const tran_low_t *in, uint8_t *out, int stride); -typedef void (*FhtFunc)(const int16_t *in, tran_low_t *out, int stride, - int tx_type); -typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride, - int tx_type); +using FdctFunc = void (*)(const int16_t *in, tran_low_t *out, int stride); +using IdctFunc = void (*)(const tran_low_t *in, uint8_t *out, int stride); +using FhtFunc = void (*)(const int16_t *in, tran_low_t *out, int stride, + int tx_type); +using IhtFunc = void (*)(const tran_low_t *in, uint8_t *out, int stride, + int tx_type); -typedef std::tuple Dct8x8Param; -typedef std::tuple Ht8x8Param; -typedef std::tuple Idct8x8Param; +using Dct8x8Param = std::tuple; +using Ht8x8Param = std::tuple; +using Idct8x8Param = std::tuple; void reference_8x8_dct_1d(const double in[8], double out[8]) { const double kInvSqrt2 = 0.707106781186547524400844362104; @@ -132,9 +133,21 @@ void idct8x8_64_add_12_sse2(const tran_low_t *in, uint8_t *out, int stride) { #endif // HAVE_SSE2 #endif // CONFIG_VP9_HIGHBITDEPTH +// Visual Studio 2022 (cl.exe) < 17.12.3 targeting AArch64 with optimizations +// enabled produces invalid code in RunExtremalCheck() and +// RunInvAccuracyCheck(). See: +// https://developercommunity.visualstudio.com/t/1770-preview-1:-Misoptimization-for-AR/10369786 +#if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 194234435 && \ + defined(_M_ARM64) && !defined(__clang__) +#define AOM_WORK_AROUND_MSVC_BUG_10369786 +#endif + +#ifdef AOM_WORK_AROUND_MSVC_BUG_10369786 +#pragma optimize("", off) +#endif class FwdTrans8x8TestBase { public: - virtual ~FwdTrans8x8TestBase() {} + virtual ~FwdTrans8x8TestBase() = default; protected: virtual void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) = 0; @@ -170,7 +183,7 @@ class FwdTrans8x8TestBase { for (int j = 0; j < 64; ++j) { const int diff = abs(count_sign_block[j][0] - count_sign_block[j][1]); const int max_diff = kSignBiasMaxDiff255; - EXPECT_LT(diff, max_diff << (bit_depth_ - 8)) + ASSERT_LT(diff, max_diff << (bit_depth_ - 8)) << "Error: 8x8 FDCT/FHT has a sign bias > " << 1. * max_diff / count_test_block * 100 << "%" << " for input range [-255, 255] at index " << j @@ -201,7 +214,7 @@ class FwdTrans8x8TestBase { for (int j = 0; j < 64; ++j) { const int diff = abs(count_sign_block[j][0] - count_sign_block[j][1]); const int max_diff = kSignBiasMaxDiff15; - EXPECT_LT(diff, max_diff << (bit_depth_ - 8)) + ASSERT_LT(diff, max_diff << (bit_depth_ - 8)) << "Error: 8x8 FDCT/FHT has a sign bias > " << 1. * max_diff / count_test_block * 100 << "%" << " for input range [-15, 15] at index " << j @@ -275,11 +288,11 @@ class FwdTrans8x8TestBase { } } - EXPECT_GE(1 << 2 * (bit_depth_ - 8), max_error) + ASSERT_GE(1 << 2 * (bit_depth_ - 8), max_error) << "Error: 8x8 FDCT/IDCT or FHT/IHT has an individual" << " roundtrip error > 1"; - EXPECT_GE((count_test_block << 2 * (bit_depth_ - 8)) / 5, total_error) + ASSERT_GE((count_test_block << 2 * (bit_depth_ - 8)) / 5, total_error) << "Error: 8x8 FDCT/IDCT or FHT/IHT has average roundtrip " << "error > 1/5 per block"; } @@ -360,17 +373,17 @@ class FwdTrans8x8TestBase { total_coeff_error += abs(coeff_diff); } - EXPECT_GE(1 << 2 * (bit_depth_ - 8), max_error) + ASSERT_GE(1 << 2 * (bit_depth_ - 8), max_error) << "Error: Extremal 8x8 FDCT/IDCT or FHT/IHT has" - << "an individual roundtrip error > 1"; + << " an individual roundtrip error > 1"; - EXPECT_GE((count_test_block << 2 * (bit_depth_ - 8)) / 5, total_error) + ASSERT_GE((count_test_block << 2 * (bit_depth_ - 8)) / 5, total_error) << "Error: Extremal 8x8 FDCT/IDCT or FHT/IHT has average" << " roundtrip error > 1/5 per block"; - EXPECT_EQ(0, total_coeff_error) + ASSERT_EQ(0, total_coeff_error) << "Error: Extremal 8x8 FDCT/FHT has" - << "overflow issues in the intermediate steps > 1"; + << " overflow issues in the intermediate steps > 1"; } } @@ -426,7 +439,7 @@ class FwdTrans8x8TestBase { const int diff = dst[j] - src[j]; #endif const uint32_t error = diff * diff; - EXPECT_GE(1u << 2 * (bit_depth_ - 8), error) + ASSERT_GE(1u << 2 * (bit_depth_ - 8), error) << "Error: 8x8 IDCT has error " << error << " at index " << j; } } @@ -456,7 +469,7 @@ class FwdTrans8x8TestBase { for (int j = 0; j < kNumCoeffs; ++j) { const int32_t diff = coeff[j] - coeff_r[j]; const uint32_t error = diff * diff; - EXPECT_GE(9u << 2 * (bit_depth_ - 8), error) + ASSERT_GE(9u << 2 * (bit_depth_ - 8), error) << "Error: 8x8 DCT has error " << error << " at index " << j; } } @@ -512,7 +525,7 @@ class FwdTrans8x8TestBase { const int diff = dst[j] - ref[j]; #endif const uint32_t error = diff * diff; - EXPECT_EQ(0u, error) + ASSERT_EQ(0u, error) << "Error: 8x8 IDCT has error " << error << " at index " << j; } } @@ -523,13 +536,16 @@ class FwdTrans8x8TestBase { vpx_bit_depth_t bit_depth_; int mask_; }; +#ifdef AOM_WORK_AROUND_MSVC_BUG_10369786 +#pragma optimize("", on) +#endif class FwdTrans8x8DCT : public FwdTrans8x8TestBase, public ::testing::TestWithParam { public: - virtual ~FwdTrans8x8DCT() {} + ~FwdTrans8x8DCT() override = default; - virtual void SetUp() { + void SetUp() override { fwd_txfm_ = GET_PARAM(0); inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); @@ -539,13 +555,13 @@ class FwdTrans8x8DCT : public FwdTrans8x8TestBase, mask_ = (1 << bit_depth_) - 1; } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: - void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) { + void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) override { fwd_txfm_(in, out, stride); } - void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) { + void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) override { inv_txfm_(out, dst, stride); } @@ -566,9 +582,9 @@ TEST_P(FwdTrans8x8DCT, InvAccuracyCheck) { RunInvAccuracyCheck(); } class FwdTrans8x8HT : public FwdTrans8x8TestBase, public ::testing::TestWithParam { public: - virtual ~FwdTrans8x8HT() {} + ~FwdTrans8x8HT() override = default; - virtual void SetUp() { + void SetUp() override { fwd_txfm_ = GET_PARAM(0); inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); @@ -578,13 +594,13 @@ class FwdTrans8x8HT : public FwdTrans8x8TestBase, mask_ = (1 << bit_depth_) - 1; } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: - void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) { + void RunFwdTxfm(int16_t *in, tran_low_t *out, int stride) override { fwd_txfm_(in, out, stride, tx_type_); } - void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) { + void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) override { inv_txfm_(out, dst, stride, tx_type_); } @@ -602,9 +618,9 @@ TEST_P(FwdTrans8x8HT, ExtremalCheck) { RunExtremalCheck(); } class InvTrans8x8DCT : public FwdTrans8x8TestBase, public ::testing::TestWithParam { public: - virtual ~InvTrans8x8DCT() {} + ~InvTrans8x8DCT() override = default; - virtual void SetUp() { + void SetUp() override { ref_txfm_ = GET_PARAM(0); inv_txfm_ = GET_PARAM(1); thresh_ = GET_PARAM(2); @@ -613,13 +629,14 @@ class InvTrans8x8DCT : public FwdTrans8x8TestBase, mask_ = (1 << bit_depth_) - 1; } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: - void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) { + void RunInvTxfm(tran_low_t *out, uint8_t *dst, int stride) override { inv_txfm_(out, dst, stride); } - void RunFwdTxfm(int16_t * /*out*/, tran_low_t * /*dst*/, int /*stride*/) {} + void RunFwdTxfm(int16_t * /*out*/, tran_low_t * /*dst*/, + int /*stride*/) override {} IdctFunc ref_txfm_; IdctFunc inv_txfm_; diff --git a/libs/libvpx/test/frame_size_tests.cc b/libs/libvpx/test/frame_size_tests.cc index d85c193e0b..a86ca9a42a 100644 --- a/libs/libvpx/test/frame_size_tests.cc +++ b/libs/libvpx/test/frame_size_tests.cc @@ -9,17 +9,17 @@ */ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/register_state_check.h" #include "test/video_source.h" +#include "vpx_config.h" namespace { class EncoderWithExpectedError : public ::libvpx_test::Encoder { public: - EncoderWithExpectedError(vpx_codec_enc_cfg_t cfg, - unsigned long deadline, // NOLINT + EncoderWithExpectedError(vpx_codec_enc_cfg_t cfg, vpx_enc_deadline_t deadline, const unsigned long init_flags, // NOLINT ::libvpx_test::TwopassStatsStore *stats) : ::libvpx_test::Encoder(cfg, deadline, init_flags, stats) {} @@ -65,7 +65,7 @@ class EncoderWithExpectedError : public ::libvpx_test::Encoder { ASSERT_EQ(expected_err, res) << EncoderError(); } - virtual vpx_codec_iface_t *CodecInterface() const { + vpx_codec_iface_t *CodecInterface() const override { #if CONFIG_VP9_ENCODER return &vpx_codec_vp9_cx_algo; #else @@ -79,22 +79,22 @@ class VP9FrameSizeTestsLarge : public ::libvpx_test::EncoderTest, protected: VP9FrameSizeTestsLarge() : EncoderTest(&::libvpx_test::kVP9), expected_res_(VPX_CODEC_OK) {} - virtual ~VP9FrameSizeTestsLarge() {} + ~VP9FrameSizeTestsLarge() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); } - virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec, - const libvpx_test::VideoSource & /*video*/, - libvpx_test::Decoder *decoder) { + bool HandleDecodeResult(const vpx_codec_err_t res_dec, + const libvpx_test::VideoSource & /*video*/, + libvpx_test::Decoder *decoder) override { EXPECT_EQ(expected_res_, res_dec) << decoder->DecodeError(); return !::testing::Test::HasFailure(); } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, 7); encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1); @@ -111,7 +111,7 @@ class VP9FrameSizeTestsLarge : public ::libvpx_test::EncoderTest, ASSERT_TRUE(passes_ == 1 || passes_ == 2); for (unsigned int pass = 0; pass < passes_; pass++) { - last_pts_ = 0; + vpx_codec_pts_t last_pts = 0; if (passes_ == 1) { cfg_.g_pass = VPX_RC_ONE_PASS; @@ -144,8 +144,8 @@ class VP9FrameSizeTestsLarge : public ::libvpx_test::EncoderTest, again = true; switch (pkt->kind) { case VPX_CODEC_CX_FRAME_PKT: - ASSERT_GE(pkt->data.frame.pts, last_pts_); - last_pts_ = pkt->data.frame.pts; + ASSERT_GE(pkt->data.frame.pts, last_pts); + last_pts = pkt->data.frame.pts; FramePktHook(pkt); break; @@ -168,6 +168,9 @@ class VP9FrameSizeTestsLarge : public ::libvpx_test::EncoderTest, }; TEST_F(VP9FrameSizeTestsLarge, TestInvalidSizes) { +#ifdef CHROMIUM + GTEST_SKIP() << "16K framebuffers are not supported by Chromium's allocator."; +#else ::libvpx_test::RandomVideoSource video; #if CONFIG_SIZE_LIMIT @@ -176,9 +179,16 @@ TEST_F(VP9FrameSizeTestsLarge, TestInvalidSizes) { expected_res_ = VPX_CODEC_MEM_ERROR; ASSERT_NO_FATAL_FAILURE(RunLoop(&video, expected_res_)); #endif + +#endif } TEST_F(VP9FrameSizeTestsLarge, ValidSizes) { +#ifdef CHROMIUM + GTEST_SKIP() + << "Under Chromium's configuration the allocator is unable to provide" + "the space required for a single frame at the maximum resolution."; +#else ::libvpx_test::RandomVideoSource video; #if CONFIG_SIZE_LIMIT @@ -194,7 +204,7 @@ TEST_F(VP9FrameSizeTestsLarge, ValidSizes) { // size or almost 1 gig of memory. // In total the allocations will exceed 2GiB which may cause a failure with // mingw + wine, use a smaller size in that case. -#if defined(_WIN32) && !defined(_WIN64) || defined(__OS2__) +#if defined(_WIN32) && !defined(_WIN64) video.SetSize(4096, 3072); #else video.SetSize(4096, 4096); @@ -203,6 +213,8 @@ TEST_F(VP9FrameSizeTestsLarge, ValidSizes) { expected_res_ = VPX_CODEC_OK; ASSERT_NO_FATAL_FAILURE(::libvpx_test::EncoderTest::RunLoop(&video)); #endif + +#endif // defined(CHROMIUM) } TEST_F(VP9FrameSizeTestsLarge, OneByOneVideo) { diff --git a/libs/libvpx/test/hadamard_test.cc b/libs/libvpx/test/hadamard_test.cc index 10b1e79c10..5b94da5a71 100644 --- a/libs/libvpx/test/hadamard_test.cc +++ b/libs/libvpx/test/hadamard_test.cc @@ -10,20 +10,21 @@ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_dsp_rtcd.h" #include "vpx_ports/vpx_timer.h" #include "test/acm_random.h" #include "test/register_state_check.h" +#include "vpx_config.h" namespace { using ::libvpx_test::ACMRandom; -typedef void (*HadamardFunc)(const int16_t *a, ptrdiff_t a_stride, - tran_low_t *b); +using HadamardFunc = void (*)(const int16_t *a, ptrdiff_t a_stride, + tran_low_t *b); void hadamard_loop(const tran_low_t *a, tran_low_t *out) { tran_low_t b[8]; @@ -130,13 +131,19 @@ std::ostream &operator<<(std::ostream &os, const HadamardFuncWithSize &hfs) { class HadamardTestBase : public ::testing::TestWithParam { public: - virtual void SetUp() { + void SetUp() override { h_func_ = GetParam().func; bwh_ = GetParam().block_size; block_size_ = bwh_ * bwh_; rnd_.Reset(ACMRandom::DeterministicSeed()); } + // The Rand() function generates values in the range [-((1 << BitDepth) - 1), + // (1 << BitDepth) - 1]. This is because the input to the Hadamard transform + // is the residual pixel, which is defined as 'source pixel - predicted + // pixel'. Source pixel and predicted pixel take values in the range + // [0, (1 << BitDepth) - 1] and thus the residual pixel ranges from + // -((1 << BitDepth) - 1) to ((1 << BitDepth) - 1). virtual int16_t Rand() = 0; void ReferenceHadamard(const int16_t *a, int a_stride, tran_low_t *b, @@ -170,6 +177,31 @@ class HadamardTestBase : public ::testing::TestWithParam { EXPECT_EQ(0, memcmp(b, b_ref, sizeof(b))); } + void ExtremeValuesTest() { + const int kMaxBlockSize = 32 * 32; + DECLARE_ALIGNED(16, int16_t, input_extreme_block[kMaxBlockSize]); + DECLARE_ALIGNED(16, tran_low_t, b[kMaxBlockSize]); + memset(b, 0, sizeof(b)); + + tran_low_t b_ref[kMaxBlockSize]; + memset(b_ref, 0, sizeof(b_ref)); + + for (int i = 0; i < 2; ++i) { + // Initialize a test block with input range [-mask_, mask_]. + const int sign = (i == 0) ? 1 : -1; + for (int j = 0; j < kMaxBlockSize; ++j) + input_extreme_block[j] = sign * 255; + + ReferenceHadamard(input_extreme_block, bwh_, b_ref, bwh_); + ASM_REGISTER_STATE_CHECK(h_func_(input_extreme_block, bwh_, b)); + + // The order of the output is not important. Sort before checking. + std::sort(b, b + block_size_); + std::sort(b_ref, b_ref + block_size_); + EXPECT_EQ(0, memcmp(b, b_ref, sizeof(b))); + } + } + void VaryStride() { const int kMaxBlockSize = 32 * 32; DECLARE_ALIGNED(16, int16_t, a[kMaxBlockSize * 8]); @@ -220,11 +252,18 @@ class HadamardTestBase : public ::testing::TestWithParam { class HadamardLowbdTest : public HadamardTestBase { protected: - virtual int16_t Rand() { return rnd_.Rand9Signed(); } + // Use values between -255 (0xFF01) and 255 (0x00FF) + int16_t Rand() override { + int16_t src = rnd_.Rand8(); + int16_t pred = rnd_.Rand8(); + return src - pred; + } }; TEST_P(HadamardLowbdTest, CompareReferenceRandom) { CompareReferenceRandom(); } +TEST_P(HadamardLowbdTest, ExtremeValuesTest) { ExtremeValuesTest(); } + TEST_P(HadamardLowbdTest, VaryStride) { VaryStride(); } TEST_P(HadamardLowbdTest, DISABLED_Speed) { @@ -254,17 +293,18 @@ INSTANTIATE_TEST_SUITE_P( HadamardFuncWithSize(&vpx_hadamard_32x32_avx2, 32))); #endif // HAVE_AVX2 -#if HAVE_SSSE3 && VPX_ARCH_X86_64 +#if HAVE_SSSE3 && VPX_ARCH_X86_64 && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P( SSSE3, HadamardLowbdTest, ::testing::Values(HadamardFuncWithSize(&vpx_hadamard_8x8_ssse3, 8))); -#endif // HAVE_SSSE3 && VPX_ARCH_X86_64 +#endif // HAVE_SSSE3 && VPX_ARCH_X86_64 && HAVE_X86_ASM #if HAVE_NEON INSTANTIATE_TEST_SUITE_P( NEON, HadamardLowbdTest, ::testing::Values(HadamardFuncWithSize(&vpx_hadamard_8x8_neon, 8), - HadamardFuncWithSize(&vpx_hadamard_16x16_neon, 16))); + HadamardFuncWithSize(&vpx_hadamard_16x16_neon, 16), + HadamardFuncWithSize(&vpx_hadamard_32x32_neon, 32))); #endif // HAVE_NEON // TODO(jingning): Remove highbitdepth flag when the SIMD functions are @@ -295,7 +335,12 @@ INSTANTIATE_TEST_SUITE_P( #if CONFIG_VP9_HIGHBITDEPTH class HadamardHighbdTest : public HadamardTestBase { protected: - virtual int16_t Rand() { return rnd_.Rand13Signed(); } + // Use values between -4095 (0xF001) and 4095 (0x0FFF) + int16_t Rand() override { + int16_t src = rnd_.Rand12(); + int16_t pred = rnd_.Rand12(); + return src - pred; + } }; TEST_P(HadamardHighbdTest, CompareReferenceRandom) { CompareReferenceRandom(); } @@ -323,5 +368,14 @@ INSTANTIATE_TEST_SUITE_P( 32))); #endif // HAVE_AVX2 +#if HAVE_NEON +INSTANTIATE_TEST_SUITE_P( + NEON, HadamardHighbdTest, + ::testing::Values(HadamardFuncWithSize(&vpx_highbd_hadamard_8x8_neon, 8), + HadamardFuncWithSize(&vpx_highbd_hadamard_16x16_neon, 16), + HadamardFuncWithSize(&vpx_highbd_hadamard_32x32_neon, + 32))); +#endif + #endif // CONFIG_VP9_HIGHBITDEPTH } // namespace diff --git a/libs/libvpx/test/idct8x8_test.cc b/libs/libvpx/test/idct8x8_test.cc index 7951bb93c9..28ab257e6e 100644 --- a/libs/libvpx/test/idct8x8_test.cc +++ b/libs/libvpx/test/idct8x8_test.cc @@ -12,12 +12,11 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_dsp_rtcd.h" #include "test/acm_random.h" #include "vpx/vpx_integer.h" -#include "vpx_ports/msvc.h" // for round() using libvpx_test::ACMRandom; diff --git a/libs/libvpx/test/idct_test.cc b/libs/libvpx/test/idct_test.cc index 1b9532e1c1..4c7c4db58a 100644 --- a/libs/libvpx/test/idct_test.cc +++ b/libs/libvpx/test/idct_test.cc @@ -11,23 +11,23 @@ #include "./vpx_config.h" #include "./vp8_rtcd.h" -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/buffer.h" #include "test/clear_system_state.h" #include "test/register_state_check.h" #include "vpx/vpx_integer.h" -typedef void (*IdctFunc)(int16_t *input, unsigned char *pred_ptr, - int pred_stride, unsigned char *dst_ptr, - int dst_stride); +using IdctFunc = void (*)(int16_t *input, unsigned char *pred_ptr, + int pred_stride, unsigned char *dst_ptr, + int dst_stride); namespace { using libvpx_test::Buffer; class IDCTTest : public ::testing::TestWithParam { protected: - virtual void SetUp() { + void SetUp() override { UUT = GetParam(); input = new Buffer(4, 4, 0); @@ -41,7 +41,7 @@ class IDCTTest : public ::testing::TestWithParam { ASSERT_TRUE(output->Init()); } - virtual void TearDown() { + void TearDown() override { delete input; delete predict; delete output; @@ -163,10 +163,10 @@ INSTANTIATE_TEST_SUITE_P(NEON, IDCTTest, ::testing::Values(vp8_short_idct4x4llm_neon)); #endif // HAVE_NEON -#if HAVE_MMX +#if HAVE_MMX && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P(MMX, IDCTTest, ::testing::Values(vp8_short_idct4x4llm_mmx)); -#endif // HAVE_MMX +#endif // HAVE_MMX && HAVE_X86_ASM #if HAVE_MSA INSTANTIATE_TEST_SUITE_P(MSA, IDCTTest, diff --git a/libs/libvpx/test/init_vpx_test.cc b/libs/libvpx/test/init_vpx_test.cc new file mode 100644 index 0000000000..4caf3a0bc8 --- /dev/null +++ b/libs/libvpx/test/init_vpx_test.cc @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "test/init_vpx_test.h" + +#include "./vpx_config.h" + +#if !CONFIG_SHARED +#include +#include "gtest/gtest.h" +#if VPX_ARCH_ARM +#include "vpx_ports/arm.h" +#endif +#if VPX_ARCH_X86 || VPX_ARCH_X86_64 +#include "vpx_ports/x86.h" +#endif +extern "C" { +#if CONFIG_VP8 +extern void vp8_rtcd(); +#endif // CONFIG_VP8 +#if CONFIG_VP9 +extern void vp9_rtcd(); +#endif // CONFIG_VP9 +extern void vpx_dsp_rtcd(); +extern void vpx_scale_rtcd(); +} + +#if VPX_ARCH_ARM || VPX_ARCH_X86 || VPX_ARCH_X86_64 +static void append_negative_gtest_filter(const char *str) { + std::string flag_value = GTEST_FLAG_GET(filter); + // Negative patterns begin with one '-' followed by a ':' separated list. + if (flag_value.find('-') == std::string::npos) flag_value += '-'; + // OPT.* matches TEST() functions + // OPT/* matches TEST_P() functions + // OPT_* matches tests which have been manually sharded. + // We do not match OPT* because of SSE/SSE2 collisions. + const char *search_terminators = "./_"; + for (size_t pos = 0; pos < strlen(search_terminators); ++pos) { + flag_value += ":"; + flag_value += str; + flag_value += search_terminators[pos]; + flag_value += "*"; + } + GTEST_FLAG_SET(filter, flag_value); +} +#endif // VPX_ARCH_ARM || VPX_ARCH_X86 || VPX_ARCH_X86_64 +#endif // !CONFIG_SHARED + +namespace libvpx_test { +void init_vpx_test() { +#if !CONFIG_SHARED +#if VPX_ARCH_AARCH64 + const int caps = arm_cpu_caps(); + if (!(caps & HAS_NEON_DOTPROD)) { + append_negative_gtest_filter("NEON_DOTPROD"); + } + if (!(caps & HAS_NEON_I8MM)) { + append_negative_gtest_filter("NEON_I8MM"); + } + if (!(caps & HAS_SVE)) { + append_negative_gtest_filter("SVE"); + } + if (!(caps & HAS_SVE2)) { + append_negative_gtest_filter("SVE2"); + } +#elif VPX_ARCH_ARM + const int caps = arm_cpu_caps(); + if (!(caps & HAS_NEON)) append_negative_gtest_filter("NEON"); +#endif // VPX_ARCH_ARM + +#if VPX_ARCH_X86 || VPX_ARCH_X86_64 + const int simd_caps = x86_simd_caps(); + if (!(simd_caps & HAS_MMX)) append_negative_gtest_filter("MMX"); + if (!(simd_caps & HAS_SSE)) append_negative_gtest_filter("SSE"); + if (!(simd_caps & HAS_SSE2)) append_negative_gtest_filter("SSE2"); + if (!(simd_caps & HAS_SSE3)) append_negative_gtest_filter("SSE3"); + if (!(simd_caps & HAS_SSSE3)) { + append_negative_gtest_filter("SSSE3"); + } + if (!(simd_caps & HAS_SSE4_1)) { + append_negative_gtest_filter("SSE4_1"); + } + if (!(simd_caps & HAS_AVX)) append_negative_gtest_filter("AVX"); + if (!(simd_caps & HAS_AVX2)) append_negative_gtest_filter("AVX2"); + if (!(simd_caps & HAS_AVX512)) { + append_negative_gtest_filter("AVX512"); + } +#endif // VPX_ARCH_X86 || VPX_ARCH_X86_64 + + // Shared library builds don't support whitebox tests that exercise internal + // symbols. +#if CONFIG_VP8 + vp8_rtcd(); +#endif // CONFIG_VP8 +#if CONFIG_VP9 + vp9_rtcd(); +#endif // CONFIG_VP9 + vpx_dsp_rtcd(); + vpx_scale_rtcd(); +#endif // !CONFIG_SHARED +} +} // namespace libvpx_test diff --git a/libs/libvpx/test/init_vpx_test.h b/libs/libvpx/test/init_vpx_test.h new file mode 100644 index 0000000000..5e0dbb0e7e --- /dev/null +++ b/libs/libvpx/test/init_vpx_test.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef TEST_INIT_VPX_TEST_H_ +#define TEST_INIT_VPX_TEST_H_ + +namespace libvpx_test { +void init_vpx_test(); +} + +#endif // TEST_INIT_VPX_TEST_H_ diff --git a/libs/libvpx/test/invalid_file_test.cc b/libs/libvpx/test/invalid_file_test.cc index 762d585f59..0b895ed902 100644 --- a/libs/libvpx/test/invalid_file_test.cc +++ b/libs/libvpx/test/invalid_file_test.cc @@ -13,7 +13,7 @@ #include #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "test/codec_factory.h" #include "test/decode_test_driver.h" @@ -40,7 +40,7 @@ class InvalidFileTest : public ::libvpx_test::DecoderTest, protected: InvalidFileTest() : DecoderTest(GET_PARAM(0)), res_file_(nullptr) {} - virtual ~InvalidFileTest() { + ~InvalidFileTest() override { if (res_file_ != nullptr) fclose(res_file_); } @@ -50,10 +50,9 @@ class InvalidFileTest : public ::libvpx_test::DecoderTest, << "Result file open failed. Filename: " << res_file_name_; } - virtual bool HandleDecodeResult( - const vpx_codec_err_t res_dec, - const libvpx_test::CompressedVideoSource &video, - libvpx_test::Decoder *decoder) { + bool HandleDecodeResult(const vpx_codec_err_t res_dec, + const libvpx_test::CompressedVideoSource &video, + libvpx_test::Decoder *decoder) override { EXPECT_NE(res_file_, nullptr); int expected_res_dec; @@ -172,9 +171,9 @@ VP9_INSTANTIATE_TEST_SUITE(InvalidFileTest, class InvalidFileInvalidPeekTest : public InvalidFileTest { protected: InvalidFileInvalidPeekTest() : InvalidFileTest() {} - virtual void HandlePeekResult(libvpx_test::Decoder *const /*decoder*/, - libvpx_test::CompressedVideoSource * /*video*/, - const vpx_codec_err_t /*res_peek*/) {} + void HandlePeekResult(libvpx_test::Decoder *const /*decoder*/, + libvpx_test::CompressedVideoSource * /*video*/, + const vpx_codec_err_t /*res_peek*/) override {} }; TEST_P(InvalidFileInvalidPeekTest, ReturnCode) { RunTest(); } diff --git a/libs/libvpx/test/ivf_video_source.h b/libs/libvpx/test/ivf_video_source.h index a8ac4f154c..57df29e9dc 100644 --- a/libs/libvpx/test/ivf_video_source.h +++ b/libs/libvpx/test/ivf_video_source.h @@ -33,19 +33,19 @@ class IVFVideoSource : public CompressedVideoSource { compressed_frame_buf_(nullptr), frame_sz_(0), frame_(0), end_of_file_(false) {} - virtual ~IVFVideoSource() { + ~IVFVideoSource() override { delete[] compressed_frame_buf_; if (input_file_) fclose(input_file_); } - virtual void Init() { + void Init() override { // Allocate a buffer for read in the compressed video frame. compressed_frame_buf_ = new uint8_t[libvpx_test::kCodeBufferSize]; ASSERT_NE(compressed_frame_buf_, nullptr) << "Allocate frame buffer failed"; } - virtual void Begin() { + void Begin() override { input_file_ = OpenTestDataFile(file_name_); ASSERT_NE(input_file_, nullptr) << "Input file open failed. Filename: " << file_name_; @@ -54,6 +54,15 @@ class IVFVideoSource : public CompressedVideoSource { uint8_t file_hdr[kIvfFileHdrSize]; ASSERT_EQ(kIvfFileHdrSize, fread(file_hdr, 1, kIvfFileHdrSize, input_file_)) << "File header read failed."; + // The following two conditions are not asserted directly as some static + // analyzers (observed with clang-19) do not properly terminate execution + // when an eof or error is assumed after the previous fread(). + if (ferror(input_file_)) { + FAIL() << "File header read failed."; + } + if (feof(input_file_)) { + FAIL() << "Unexpected eof."; + } // Check file header ASSERT_TRUE(file_hdr[0] == 'D' && file_hdr[1] == 'K' && file_hdr[2] == 'I' && file_hdr[3] == 'F') @@ -62,7 +71,7 @@ class IVFVideoSource : public CompressedVideoSource { FillFrame(); } - virtual void Next() { + void Next() override { ++frame_; FillFrame(); } @@ -86,11 +95,11 @@ class IVFVideoSource : public CompressedVideoSource { } } - virtual const uint8_t *cxdata() const { + const uint8_t *cxdata() const override { return end_of_file_ ? nullptr : compressed_frame_buf_; } - virtual size_t frame_size() const { return frame_sz_; } - virtual unsigned int frame_number() const { return frame_; } + size_t frame_size() const override { return frame_sz_; } + unsigned int frame_number() const override { return frame_; } protected: std::string file_name_; diff --git a/libs/libvpx/test/keyframe_test.cc b/libs/libvpx/test/keyframe_test.cc index a13dec9ce2..c49ea91bd2 100644 --- a/libs/libvpx/test/keyframe_test.cc +++ b/libs/libvpx/test/keyframe_test.cc @@ -8,12 +8,18 @@ * be found in the AUTHORS file in the root of the source tree. */ #include +#include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" #include "test/util.h" +#include "./vpx_config.h" +#include "vpx/vp8cx.h" +#include "vpx/vpx_codec.h" +#include "vpx/vpx_encoder.h" +#include "vpx/vpx_image.h" namespace { @@ -22,9 +28,9 @@ class KeyframeTest public ::libvpx_test::CodecTestWithParam { protected: KeyframeTest() : EncoderTest(GET_PARAM(0)) {} - virtual ~KeyframeTest() {} + ~KeyframeTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(GET_PARAM(1)); kf_count_ = 0; @@ -33,8 +39,8 @@ class KeyframeTest set_cpu_used_ = 0; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (kf_do_force_kf_) { frame_flags_ = (video->frame() % 3) ? 0 : VPX_EFLAG_FORCE_KF; } @@ -43,7 +49,7 @@ class KeyframeTest } } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) { kf_pts_list_.push_back(pkt->data.frame.pts); kf_count_++; @@ -146,4 +152,105 @@ TEST_P(KeyframeTest, TestAutoKeyframe) { } VP8_INSTANTIATE_TEST_SUITE(KeyframeTest, ALL_TEST_MODES); + +bool IsVP9(vpx_codec_iface_t *iface) { + static const char kVP9Name[] = "WebM Project VP9"; + return strncmp(kVP9Name, vpx_codec_iface_name(iface), sizeof(kVP9Name) - 1) == + 0; +} + +vpx_image_t *CreateGrayImage(vpx_img_fmt_t fmt, unsigned int w, + unsigned int h) { + vpx_image_t *const image = vpx_img_alloc(nullptr, fmt, w, h, 1); + if (!image) return image; + + for (unsigned int i = 0; i < image->d_h; ++i) { + memset(image->planes[0] + i * image->stride[0], 128, image->d_w); + } + const unsigned int uv_h = (image->d_h + 1) / 2; + const unsigned int uv_w = (image->d_w + 1) / 2; + for (unsigned int i = 0; i < uv_h; ++i) { + memset(image->planes[1] + i * image->stride[1], 128, uv_w); + memset(image->planes[2] + i * image->stride[2], 128, uv_w); + } + return image; +} + +// Tests kf_max_dist in one-pass encoding with zero lag. +void TestKeyframeMaximumInterval(vpx_codec_iface_t *iface, + vpx_enc_deadline_t deadline, + unsigned int kf_max_dist) { + vpx_codec_enc_cfg_t cfg; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, /*usage=*/0), + VPX_CODEC_OK); + cfg.g_w = 320; + cfg.g_h = 240; + cfg.g_pass = VPX_RC_ONE_PASS; + cfg.g_lag_in_frames = 0; + cfg.kf_mode = VPX_KF_AUTO; + cfg.kf_min_dist = 0; + cfg.kf_max_dist = kf_max_dist; + + vpx_codec_ctx_t enc; + ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK); + + const int speed = IsVP9(iface) ? 9 : -12; + ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_CPUUSED, speed), VPX_CODEC_OK); + + vpx_image_t *image = CreateGrayImage(VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h); + ASSERT_NE(image, nullptr); + + // Encode frames. + const vpx_codec_cx_pkt_t *pkt; + const unsigned int num_frames = kf_max_dist == 0 ? 4 : 3 * kf_max_dist + 1; + for (unsigned int i = 0; i < num_frames; ++i) { + ASSERT_EQ(vpx_codec_encode(&enc, image, i, 1, 0, deadline), VPX_CODEC_OK); + vpx_codec_iter_t iter = nullptr; + while ((pkt = vpx_codec_get_cx_data(&enc, &iter)) != nullptr) { + ASSERT_EQ(pkt->kind, VPX_CODEC_CX_FRAME_PKT); + if (kf_max_dist == 0 || i % kf_max_dist == 0) { + ASSERT_EQ(pkt->data.frame.flags & VPX_FRAME_IS_KEY, VPX_FRAME_IS_KEY); + } else { + ASSERT_EQ(pkt->data.frame.flags & VPX_FRAME_IS_KEY, 0u); + } + } + } + + // Flush the encoder. + bool got_data; + do { + ASSERT_EQ(vpx_codec_encode(&enc, nullptr, 0, 1, 0, deadline), VPX_CODEC_OK); + got_data = false; + vpx_codec_iter_t iter = nullptr; + while ((pkt = vpx_codec_get_cx_data(&enc, &iter)) != nullptr) { + ASSERT_EQ(pkt->kind, VPX_CODEC_CX_FRAME_PKT); + got_data = true; + } + } while (got_data); + + vpx_img_free(image); + ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK); +} + +TEST(KeyframeIntervalTest, KeyframeMaximumInterval) { + std::vector ifaces; +#if CONFIG_VP8_ENCODER + ifaces.push_back(vpx_codec_vp8_cx()); +#endif +#if CONFIG_VP9_ENCODER + ifaces.push_back(vpx_codec_vp9_cx()); +#endif + for (vpx_codec_iface_t *iface : ifaces) { + for (vpx_enc_deadline_t deadline : + { VPX_DL_REALTIME, VPX_DL_GOOD_QUALITY, VPX_DL_BEST_QUALITY }) { + // Test 0 and 1 (both mean all intra), some powers of 2, some multiples + // of 10, and some prime numbers. + for (unsigned int kf_max_dist : + { 0, 1, 2, 3, 4, 7, 10, 13, 16, 20, 23, 29, 32 }) { + TestKeyframeMaximumInterval(iface, deadline, kf_max_dist); + } + } + } +} + } // namespace diff --git a/libs/libvpx/test/level_test.cc b/libs/libvpx/test/level_test.cc index 038d75f44f..03217a293e 100644 --- a/libs/libvpx/test/level_test.cc +++ b/libs/libvpx/test/level_test.cc @@ -7,11 +7,12 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" #include "test/util.h" +#include "vpx_config.h" namespace { class LevelTest @@ -22,9 +23,9 @@ class LevelTest : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), cpu_used_(GET_PARAM(2)), min_gf_internal_(24), target_level_(0), level_(0) {} - virtual ~LevelTest() {} + ~LevelTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(encoding_mode_); if (encoding_mode_ != ::libvpx_test::kRealTime) { @@ -41,8 +42,8 @@ class LevelTest cfg_.rc_min_quantizer = 0; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, cpu_used_); encoder->Control(VP9E_SET_TARGET_LEVEL, target_level_); @@ -67,6 +68,9 @@ class LevelTest }; TEST_P(LevelTest, TestTargetLevel11Large) { +#if CONFIG_REALTIME_ONLY + GTEST_SKIP(); +#else ASSERT_NE(encoding_mode_, ::libvpx_test::kRealTime); ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, 60); @@ -74,9 +78,13 @@ TEST_P(LevelTest, TestTargetLevel11Large) { cfg_.rc_target_bitrate = 150; ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_GE(target_level_, level_); +#endif } TEST_P(LevelTest, TestTargetLevel20Large) { +#if CONFIG_REALTIME_ONLY + GTEST_SKIP(); +#else ASSERT_NE(encoding_mode_, ::libvpx_test::kRealTime); ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, 30, 1, 0, 60); @@ -84,9 +92,13 @@ TEST_P(LevelTest, TestTargetLevel20Large) { cfg_.rc_target_bitrate = 1200; ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_GE(target_level_, level_); +#endif } TEST_P(LevelTest, TestTargetLevel31Large) { +#if CONFIG_REALTIME_ONLY + GTEST_SKIP(); +#else ASSERT_NE(encoding_mode_, ::libvpx_test::kRealTime); ::libvpx_test::I420VideoSource video("niklas_1280_720_30.y4m", 1280, 720, 30, 1, 0, 60); @@ -94,6 +106,7 @@ TEST_P(LevelTest, TestTargetLevel31Large) { cfg_.rc_target_bitrate = 8000; ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_GE(target_level_, level_); +#endif } // Test for keeping level stats only @@ -120,7 +133,7 @@ TEST_P(LevelTest, TestTargetLevel255) { TEST_P(LevelTest, TestTargetLevelApi) { ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0, 1); - static const vpx_codec_iface_t *codec = &vpx_codec_vp9_cx_algo; + static vpx_codec_iface_t *codec = &vpx_codec_vp9_cx_algo; vpx_codec_ctx_t enc; vpx_codec_enc_cfg_t cfg; EXPECT_EQ(VPX_CODEC_OK, vpx_codec_enc_config_default(codec, &cfg, 0)); @@ -140,8 +153,6 @@ TEST_P(LevelTest, TestTargetLevelApi) { EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&enc)); } -VP9_INSTANTIATE_TEST_SUITE(LevelTest, - ::testing::Values(::libvpx_test::kTwoPassGood, - ::libvpx_test::kOnePassGood), +VP9_INSTANTIATE_TEST_SUITE(LevelTest, ONE_OR_TWO_PASS_TEST_MODES, ::testing::Range(0, 9)); } // namespace diff --git a/libs/libvpx/test/lpf_test.cc b/libs/libvpx/test/lpf_test.cc index 4cc99a6db4..b1688f7d26 100644 --- a/libs/libvpx/test/lpf_test.cc +++ b/libs/libvpx/test/lpf_test.cc @@ -13,7 +13,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" @@ -36,29 +36,29 @@ const int kNumCoeffs = 1024; const int number_of_iterations = 10000; #if CONFIG_VP9_HIGHBITDEPTH -typedef uint16_t Pixel; +using Pixel = uint16_t; #define PIXEL_WIDTH 16 -typedef void (*loop_op_t)(Pixel *s, int p, const uint8_t *blimit, - const uint8_t *limit, const uint8_t *thresh, int bd); -typedef void (*dual_loop_op_t)(Pixel *s, int p, const uint8_t *blimit0, - const uint8_t *limit0, const uint8_t *thresh0, - const uint8_t *blimit1, const uint8_t *limit1, - const uint8_t *thresh1, int bd); +using loop_op_t = void (*)(Pixel *s, int p, const uint8_t *blimit, + const uint8_t *limit, const uint8_t *thresh, int bd); +using dual_loop_op_t = void (*)(Pixel *s, int p, const uint8_t *blimit0, + const uint8_t *limit0, const uint8_t *thresh0, + const uint8_t *blimit1, const uint8_t *limit1, + const uint8_t *thresh1, int bd); #else -typedef uint8_t Pixel; +using Pixel = uint8_t; #define PIXEL_WIDTH 8 -typedef void (*loop_op_t)(Pixel *s, int p, const uint8_t *blimit, - const uint8_t *limit, const uint8_t *thresh); -typedef void (*dual_loop_op_t)(Pixel *s, int p, const uint8_t *blimit0, - const uint8_t *limit0, const uint8_t *thresh0, - const uint8_t *blimit1, const uint8_t *limit1, - const uint8_t *thresh1); +using loop_op_t = void (*)(Pixel *s, int p, const uint8_t *blimit, + const uint8_t *limit, const uint8_t *thresh); +using dual_loop_op_t = void (*)(Pixel *s, int p, const uint8_t *blimit0, + const uint8_t *limit0, const uint8_t *thresh0, + const uint8_t *blimit1, const uint8_t *limit1, + const uint8_t *thresh1); #endif // CONFIG_VP9_HIGHBITDEPTH -typedef std::tuple loop8_param_t; -typedef std::tuple dualloop8_param_t; +using loop8_param_t = std::tuple; +using dualloop8_param_t = std::tuple; void InitInput(Pixel *s, Pixel *ref_s, ACMRandom *rnd, const uint8_t limit, const int mask, const int32_t p, const int i) { @@ -129,15 +129,15 @@ uint8_t GetHevThresh(ACMRandom *rnd) { class Loop8Test6Param : public ::testing::TestWithParam { public: - virtual ~Loop8Test6Param() {} - virtual void SetUp() { + ~Loop8Test6Param() override = default; + void SetUp() override { loopfilter_op_ = GET_PARAM(0); ref_loopfilter_op_ = GET_PARAM(1); bit_depth_ = GET_PARAM(2); mask_ = (1 << bit_depth_) - 1; } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: int bit_depth_; @@ -151,15 +151,15 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(Loop8Test6Param); (HAVE_DSPR2 || HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH) class Loop8Test9Param : public ::testing::TestWithParam { public: - virtual ~Loop8Test9Param() {} - virtual void SetUp() { + ~Loop8Test9Param() override = default; + void SetUp() override { loopfilter_op_ = GET_PARAM(0); ref_loopfilter_op_ = GET_PARAM(1); bit_depth_ = GET_PARAM(2); mask_ = (1 << bit_depth_) - 1; } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: int bit_depth_; diff --git a/libs/libvpx/test/md5_helper.h b/libs/libvpx/test/md5_helper.h index dc28dc6283..9095d96a8a 100644 --- a/libs/libvpx/test/md5_helper.h +++ b/libs/libvpx/test/md5_helper.h @@ -47,7 +47,7 @@ class MD5 { MD5Update(&md5_, data, static_cast(size)); } - const char *Get(void) { + const char *Get() { static const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', diff --git a/libs/libvpx/test/mfqe_test.cc b/libs/libvpx/test/mfqe_test.cc new file mode 100644 index 0000000000..351daa87ec --- /dev/null +++ b/libs/libvpx/test/mfqe_test.cc @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2026 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include +#include + +#include "gtest/gtest.h" +#include "vpx_config.h" +#include "vp9/common/vp9_mfqe.h" +#include "vp9/common/vp9_onyxc_int.h" +#include "vpx_scale/yv12config.h" + +namespace { + +constexpr int kFrameSize = 64; +constexpr int kCheckerboardSquareSize = 4; + +class TmpFrameBuffer { + public: + // Returns an initialized frame, or nullptr if allocation fails. + static std::unique_ptr Create(int width, int height, + int stride, + bool fill_checkerboard); + + TmpFrameBuffer(const TmpFrameBuffer &) = delete; + TmpFrameBuffer &operator=(const TmpFrameBuffer &) = delete; + ~TmpFrameBuffer() { vpx_free_frame_buffer(&buffer_); } + + // Returns a borrowed reference valid for this object's lifetime. + YV12_BUFFER_CONFIG &buffer() { return buffer_; } + + private: + // Takes ownership of buffer's allocation. + explicit TmpFrameBuffer(const YV12_BUFFER_CONFIG &buffer) : buffer_(buffer) {} + + YV12_BUFFER_CONFIG buffer_ = {}; +}; + +std::unique_ptr TmpFrameBuffer::Create(int width, int height, + int stride, + bool fill_checkerboard) { + YV12_BUFFER_CONFIG buffer = {}; +#if CONFIG_VP9_HIGHBITDEPTH + const int allocation_status = + vpx_alloc_frame_buffer(&buffer, stride, height, 1, 1, 0, 0, 0); +#else + const int allocation_status = + vpx_alloc_frame_buffer(&buffer, stride, height, 1, 1, 0, 0); +#endif + if (allocation_status != 0) return nullptr; + + buffer.y_width = width; + buffer.y_height = height; + buffer.y_crop_width = width; + buffer.y_crop_height = height; + buffer.uv_width = width >> 1; + buffer.uv_height = height >> 1; + buffer.uv_crop_width = width >> 1; + buffer.uv_crop_height = height >> 1; + buffer.render_width = width; + buffer.render_height = height; + + if (fill_checkerboard) { + // Fill the luma plane with a checkerboard pattern. + for (int row = 0; row < height; ++row) { + for (int col = 0; col < width; ++col) { + const int checkerboard_row = row / kCheckerboardSquareSize; + const int checkerboard_col = col / kCheckerboardSquareSize; + int pixel_value = 0x20; + if ((checkerboard_row + checkerboard_col) % 2 != 0) { + pixel_value = 0xe0; + } + buffer.y_buffer[row * buffer.y_stride + col] = pixel_value; + } + } + } else { + // Use a distinct initial luma value so copying is observable. + for (int row = 0; row < height; ++row) { + memset(buffer.y_buffer + row * buffer.y_stride, 0, width); + } + } + + // Use neutral chroma so the checkerboard pattern is luma-only. + for (int row = 0; row < height / 2; ++row) { + memset(buffer.u_buffer + row * buffer.uv_stride, 0x80, width / 2); + memset(buffer.v_buffer + row * buffer.uv_stride, 0x80, width / 2); + } + std::unique_ptr frame(new (std::nothrow) + TmpFrameBuffer(buffer)); + if (frame == nullptr) { + vpx_free_frame_buffer(&buffer); + } + return frame; +} + +TEST(MfqeTest, Copy64x64WithDifferentStrides) { + auto source = TmpFrameBuffer::Create(kFrameSize, kFrameSize, kFrameSize, + /*fill_checkerboard=*/true); + ASSERT_NE(source, nullptr); + // The wider allocation produces a different stride while preserving the + // visible dimensions of the image. + auto destination = + TmpFrameBuffer::Create(kFrameSize, kFrameSize, kFrameSize + 16, + /*fill_checkerboard=*/false); + ASSERT_NE(destination, nullptr); + ASSERT_NE(source->buffer().y_stride, destination->buffer().y_stride); + + // One MODE_INFO entry per 8x8 MI unit in this 64x64 superblock. + std::array mi = {}; + mi[0].sb_type = BLOCK_64X64; + mi[0].mode = DC_PRED; // Force the copy path rather than MFQE filtering. + + VP9_COMMON cm = {}; + cm.frame_type = INTER_FRAME; + cm.frame_to_show = &source->buffer(); + cm.post_proc_buffer = destination->buffer(); + cm.mi_rows = MI_BLOCK_SIZE; + cm.mi_cols = MI_BLOCK_SIZE; + cm.mi_stride = MI_BLOCK_SIZE; + cm.mi = mi.data(); + + vp9_mfqe(&cm); + + for (int row = 0; row < kFrameSize; ++row) { + EXPECT_EQ( + std::memcmp( + source->buffer().y_buffer + row * source->buffer().y_stride, + cm.post_proc_buffer.y_buffer + row * cm.post_proc_buffer.y_stride, + kFrameSize), + 0) + << "row " << row; + } +} + +} // namespace diff --git a/libs/libvpx/test/minmax_test.cc b/libs/libvpx/test/minmax_test.cc index 12327bc188..8c758ab45f 100644 --- a/libs/libvpx/test/minmax_test.cc +++ b/libs/libvpx/test/minmax_test.cc @@ -11,10 +11,12 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" +#include "vpx_config.h" #include "./vpx_dsp_rtcd.h" #include "vpx/vpx_integer.h" +#include "vpx_mem/vpx_mem.h" #include "test/acm_random.h" #include "test/register_state_check.h" @@ -23,12 +25,12 @@ namespace { using ::libvpx_test::ACMRandom; -typedef void (*MinMaxFunc)(const uint8_t *a, int a_stride, const uint8_t *b, - int b_stride, int *min, int *max); +using MinMaxFunc = void (*)(const uint8_t *a, int a_stride, const uint8_t *b, + int b_stride, int *min, int *max); class MinMaxTest : public ::testing::TestWithParam { public: - virtual void SetUp() { + void SetUp() override { mm_func_ = GetParam(); rnd_.Reset(ACMRandom::DeterministicSeed()); } @@ -115,7 +117,115 @@ TEST_P(MinMaxTest, CompareReferenceAndVaryStride) { } } +#if CONFIG_VP9_HIGHBITDEPTH + +using HBDMinMaxTest = MinMaxTest; + +void highbd_reference_minmax(const uint8_t *a, int a_stride, const uint8_t *b, + int b_stride, int *min_ret, int *max_ret) { + int min = 65535; + int max = 0; + const uint16_t *a_ptr = CONVERT_TO_SHORTPTR(a); + const uint16_t *b_ptr = CONVERT_TO_SHORTPTR(b); + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + const int diff = abs(a_ptr[i * a_stride + j] - b_ptr[i * b_stride + j]); + if (min > diff) min = diff; + if (max < diff) max = diff; + } + } + + *min_ret = min; + *max_ret = max; +} + +TEST_P(HBDMinMaxTest, MinValue) { + uint8_t *a = CONVERT_TO_BYTEPTR( + reinterpret_cast(vpx_malloc(64 * sizeof(uint16_t)))); + uint8_t *b = CONVERT_TO_BYTEPTR( + reinterpret_cast(vpx_malloc(64 * sizeof(uint16_t)))); + for (int i = 0; i < 64; i++) { + vpx_memset16(CONVERT_TO_SHORTPTR(a), 0, 64); + vpx_memset16(CONVERT_TO_SHORTPTR(b), 65535, 64); + CONVERT_TO_SHORTPTR(b)[i] = i; // Set a minimum difference of i. + + int min, max; + ASM_REGISTER_STATE_CHECK(mm_func_(a, 8, b, 8, &min, &max)); + EXPECT_EQ(65535, max); + EXPECT_EQ(i, min); + } + vpx_free(CONVERT_TO_SHORTPTR(a)); + vpx_free(CONVERT_TO_SHORTPTR(b)); +} + +TEST_P(HBDMinMaxTest, MaxValue) { + uint8_t *a = CONVERT_TO_BYTEPTR( + reinterpret_cast(vpx_malloc(64 * sizeof(uint16_t)))); + uint8_t *b = CONVERT_TO_BYTEPTR( + reinterpret_cast(vpx_malloc(64 * sizeof(uint16_t)))); + for (int i = 0; i < 64; i++) { + vpx_memset16(CONVERT_TO_SHORTPTR(a), 0, 64); + vpx_memset16(CONVERT_TO_SHORTPTR(b), 0, 64); + CONVERT_TO_SHORTPTR(b)[i] = i; // Set a minimum difference of i. + + int min, max; + ASM_REGISTER_STATE_CHECK(mm_func_(a, 8, b, 8, &min, &max)); + EXPECT_EQ(i, max); + EXPECT_EQ(0, min); + } + vpx_free(CONVERT_TO_SHORTPTR(a)); + vpx_free(CONVERT_TO_SHORTPTR(b)); +} + +TEST_P(HBDMinMaxTest, CompareReference) { + uint8_t *a = CONVERT_TO_BYTEPTR( + reinterpret_cast(vpx_malloc(64 * sizeof(uint16_t)))); + uint8_t *b = CONVERT_TO_BYTEPTR( + reinterpret_cast(vpx_malloc(64 * sizeof(uint16_t)))); + for (int j = 0; j < 64; j++) { + CONVERT_TO_SHORTPTR(a)[j] = rnd_.Rand16(); + CONVERT_TO_SHORTPTR(b)[j] = rnd_.Rand16(); + } + + int min_ref, max_ref, min, max; + highbd_reference_minmax(a, 8, b, 8, &min_ref, &max_ref); + ASM_REGISTER_STATE_CHECK(mm_func_(a, 8, b, 8, &min, &max)); + vpx_free(CONVERT_TO_SHORTPTR(a)); + vpx_free(CONVERT_TO_SHORTPTR(b)); + EXPECT_EQ(max_ref, max); + EXPECT_EQ(min_ref, min); +} + +TEST_P(HBDMinMaxTest, CompareReferenceAndVaryStride) { + uint8_t *a = CONVERT_TO_BYTEPTR( + reinterpret_cast(vpx_malloc((8 * 64) * sizeof(uint16_t)))); + uint8_t *b = CONVERT_TO_BYTEPTR( + reinterpret_cast(vpx_malloc((8 * 64) * sizeof(uint16_t)))); + for (int i = 0; i < 8 * 64; i++) { + CONVERT_TO_SHORTPTR(a)[i] = rnd_.Rand16(); + CONVERT_TO_SHORTPTR(b)[i] = rnd_.Rand16(); + } + for (int a_stride = 8; a_stride <= 64; a_stride += 8) { + for (int b_stride = 8; b_stride <= 64; b_stride += 8) { + int min_ref, max_ref, min, max; + highbd_reference_minmax(a, a_stride, b, b_stride, &min_ref, &max_ref); + ASM_REGISTER_STATE_CHECK(mm_func_(a, a_stride, b, b_stride, &min, &max)); + EXPECT_EQ(max_ref, max) + << "when a_stride = " << a_stride << " and b_stride = " << b_stride; + EXPECT_EQ(min_ref, min) + << "when a_stride = " << a_stride << " and b_stride = " << b_stride; + } + } + vpx_free(CONVERT_TO_SHORTPTR(a)); + vpx_free(CONVERT_TO_SHORTPTR(b)); +} +#endif + INSTANTIATE_TEST_SUITE_P(C, MinMaxTest, ::testing::Values(&vpx_minmax_8x8_c)); +#if CONFIG_VP9_HIGHBITDEPTH +INSTANTIATE_TEST_SUITE_P(C, HBDMinMaxTest, + ::testing::Values(&vpx_highbd_minmax_8x8_c)); +#endif #if HAVE_SSE2 INSTANTIATE_TEST_SUITE_P(SSE2, MinMaxTest, @@ -125,6 +235,10 @@ INSTANTIATE_TEST_SUITE_P(SSE2, MinMaxTest, #if HAVE_NEON INSTANTIATE_TEST_SUITE_P(NEON, MinMaxTest, ::testing::Values(&vpx_minmax_8x8_neon)); +#if CONFIG_VP9_HIGHBITDEPTH +INSTANTIATE_TEST_SUITE_P(NEON, HBDMinMaxTest, + ::testing::Values(&vpx_highbd_minmax_8x8_neon)); +#endif #endif #if HAVE_MSA diff --git a/libs/libvpx/test/non_greedy_mv_test.cc b/libs/libvpx/test/non_greedy_mv_test.cc index 927029de45..b3abd9cdbd 100644 --- a/libs/libvpx/test/non_greedy_mv_test.cc +++ b/libs/libvpx/test/non_greedy_mv_test.cc @@ -9,7 +9,7 @@ */ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "vp9/encoder/vp9_non_greedy_mv.h" #include "./vpx_dsp_rtcd.h" @@ -47,7 +47,7 @@ static void read_in_local_var(const char *filename, int *rows_ptr, fscanf(input, "%d,%d\n", rows_ptr, cols_ptr); - *M_ptr = (int(*)[MF_LOCAL_STRUCTURE_SIZE])malloc( + *M_ptr = (int (*)[MF_LOCAL_STRUCTURE_SIZE])malloc( (*rows_ptr) * (*cols_ptr) * MF_LOCAL_STRUCTURE_SIZE * sizeof(int_type)); for (idx = 0; idx < (*rows_ptr) * (*cols_ptr); ++idx) { @@ -133,7 +133,7 @@ TEST(non_greedy_mv, smooth_mf) { MV *smooth_mf = nullptr; MV *estimation = nullptr; MV *ground_truth = nullptr; - int(*local_var)[MF_LOCAL_STRUCTURE_SIZE] = nullptr; + int (*local_var)[MF_LOCAL_STRUCTURE_SIZE] = nullptr; int rows = 0, cols = 0; int alpha = 100, max_iter = 100; @@ -169,8 +169,8 @@ TEST(non_greedy_mv, local_var) { const char *gt_local_var_file = "non_greedy_mv_test_files/localVar_16x16.txt"; const char *search_mf_file = "non_greedy_mv_test_files/exhaust_16x16.txt"; BLOCK_SIZE bsize = BLOCK_16X16; - int(*gt_local_var)[MF_LOCAL_STRUCTURE_SIZE] = nullptr; - int(*est_local_var)[MF_LOCAL_STRUCTURE_SIZE] = nullptr; + int (*gt_local_var)[MF_LOCAL_STRUCTURE_SIZE] = nullptr; + int (*est_local_var)[MF_LOCAL_STRUCTURE_SIZE] = nullptr; YV12_BUFFER_CONFIG ref_frame, cur_frame; int rows, cols; MV *search_mf; @@ -183,7 +183,7 @@ TEST(non_greedy_mv, local_var) { read_in_mf(search_mf_file, &rows, &cols, &search_mf); fn.sdf = vpx_sad16x16; - est_local_var = (int(*)[MF_LOCAL_STRUCTURE_SIZE])malloc( + est_local_var = (int (*)[MF_LOCAL_STRUCTURE_SIZE])malloc( rows * cols * MF_LOCAL_STRUCTURE_SIZE * sizeof(int_type)); vp9_get_local_structure(&cur_frame, &ref_frame, search_mf, &fn, rows, cols, bsize, est_local_var); diff --git a/libs/libvpx/test/partial_idct_test.cc b/libs/libvpx/test/partial_idct_test.cc index 7eb888a586..da391b1a7e 100644 --- a/libs/libvpx/test/partial_idct_test.cc +++ b/libs/libvpx/test/partial_idct_test.cc @@ -14,7 +14,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp9_rtcd.h" #include "./vpx_dsp_rtcd.h" @@ -25,16 +25,17 @@ #include "vp9/common/vp9_blockd.h" #include "vp9/common/vp9_scan.h" #include "vpx/vpx_integer.h" +#include "vpx_config.h" #include "vpx_ports/vpx_timer.h" using libvpx_test::ACMRandom; namespace { -typedef void (*FwdTxfmFunc)(const int16_t *in, tran_low_t *out, int stride); -typedef void (*InvTxfmFunc)(const tran_low_t *in, uint8_t *out, int stride); -typedef void (*InvTxfmWithBdFunc)(const tran_low_t *in, uint8_t *out, - int stride, int bd); +using FwdTxfmFunc = void (*)(const int16_t *in, tran_low_t *out, int stride); +using InvTxfmFunc = void (*)(const tran_low_t *in, uint8_t *out, int stride); +using InvTxfmWithBdFunc = void (*)(const tran_low_t *in, uint8_t *out, + int stride, int bd); template void wrapper(const tran_low_t *in, uint8_t *out, int stride, int bd) { @@ -43,24 +44,25 @@ void wrapper(const tran_low_t *in, uint8_t *out, int stride, int bd) { } #if CONFIG_VP9_HIGHBITDEPTH -typedef void (*InvTxfmHighbdFunc)(const tran_low_t *in, uint16_t *out, - int stride, int bd); +using InvTxfmHighbdFunc = void (*)(const tran_low_t *in, uint16_t *out, + int stride, int bd); + template void highbd_wrapper(const tran_low_t *in, uint8_t *out, int stride, int bd) { fn(in, CAST_TO_SHORTPTR(out), stride, bd); } #endif -typedef std::tuple - PartialInvTxfmParam; +using PartialInvTxfmParam = + std::tuple; const int kMaxNumCoeffs = 1024; const int kCountTestBlock = 1000; class PartialIDctTest : public ::testing::TestWithParam { public: - virtual ~PartialIDctTest() {} - virtual void SetUp() { + ~PartialIDctTest() override = default; + void SetUp() override { rnd_.Reset(ACMRandom::DeterministicSeed()); fwd_txfm_ = GET_PARAM(0); full_inv_txfm_ = GET_PARAM(1); @@ -76,7 +78,7 @@ class PartialIDctTest : public ::testing::TestWithParam { case TX_8X8: size_ = 8; break; case TX_16X16: size_ = 16; break; case TX_32X32: size_ = 32; break; - default: FAIL() << "Wrong Size!"; break; + default: FAIL() << "Wrong Size!"; } // Randomize stride_ to a value less than or equal to 1024 @@ -100,7 +102,7 @@ class PartialIDctTest : public ::testing::TestWithParam { vpx_memalign(16, pixel_size_ * output_block_size_)); } - virtual void TearDown() { + void TearDown() override { vpx_free(input_block_); input_block_ = nullptr; vpx_free(output_block_); diff --git a/libs/libvpx/test/postproc_test.cc b/libs/libvpx/test/postproc_test.cc new file mode 100644 index 0000000000..f430dfa27d --- /dev/null +++ b/libs/libvpx/test/postproc_test.cc @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2026 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gtest/gtest.h" + +#include "test/codec_factory.h" +#include "test/decode_test_driver.h" +#include "test/ivf_video_source.h" +#include "test/test_vectors.h" +#include "test/util.h" +#if CONFIG_WEBM_IO +#include "test/webm_video_source.h" +#endif +#include "vpx/vp8dx.h" +#include "vpx/vpx_decoder.h" + +namespace { + +struct TestParam { + int flags; + const char *filename; +}; + +std::ostream &operator<<(std::ostream &os, const TestParam ¶m) { + std::string flags_str; + if (param.flags == VP8_NOFILTERING) { + flags_str = "default flags"; + } else { + if (param.flags & VP8_DEBLOCK) flags_str += "deblock"; + if (param.flags & VP8_DEMACROBLOCK) { + if (!flags_str.empty()) flags_str += ", "; + flags_str += "demacroblock"; + } + if (param.flags & VP8_ADDNOISE) { + if (!flags_str.empty()) flags_str += ", "; + flags_str += "addnoise"; + } + if (param.flags & VP8_MFQE) { + if (!flags_str.empty()) flags_str += ", "; + flags_str += "mfqe"; + } + } + + return os << "(" << flags_str << ", " << param.filename << ")"; +} + +class PostProcTest : public ::libvpx_test::DecoderTest, + public ::libvpx_test::CodecTestWithParam { + protected: + PostProcTest() + : DecoderTest(GET_PARAM(0)), postproc_flags_(GET_PARAM(1).flags) {} + + ~PostProcTest() override = default; + + void PreDecodeFrameHook(const libvpx_test::CompressedVideoSource &video, + libvpx_test::Decoder *decoder) override { + // VP8_NOFILTERING is used to test the default flags set when only + // VPX_CODEC_USE_POSTPROC is used. + if (video.frame_number() == 0 && postproc_flags_ != VP8_NOFILTERING) { + const vp8_postproc_cfg_t vp8_pp_cfg = { postproc_flags_, + /*deblocking_level=*/2, + /*noise_level=*/10 }; + decoder->Control(VP8_SET_POSTPROC, &vp8_pp_cfg); + } + } + + void DecodeTest(); + + private: + int postproc_flags_; +}; + +void PostProcTest::DecodeTest() { + const std::string filename = GET_PARAM(1).filename; + vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t(); + cfg.threads = 2; + + // Open compressed video file. + std::unique_ptr video; + if (filename.substr(filename.length() - 3, 3) == "ivf") { + video.reset(new (std::nothrow) libvpx_test::IVFVideoSource(filename)); + } else if (filename.substr(filename.length() - 4, 4) == "webm") { +#if CONFIG_WEBM_IO + video.reset(new (std::nothrow) libvpx_test::WebMVideoSource(filename)); +#else + GTEST_SKIP() << "WebM IO is disabled, skipping test vector " << filename; +#endif + } + ASSERT_NE(video, nullptr); + video->Init(); + + // Set decode config and flags. + set_cfg(cfg); + set_flags(VPX_CODEC_USE_POSTPROC); + + // Decode frame. + ASSERT_NO_FATAL_FAILURE(RunLoop(video.get(), cfg)); +} + +TEST_P(PostProcTest, Decode) { DecodeTest(); } + +std::vector GeneratePostProcFlags() { + std::vector flags; + + flags.push_back(VP8_NOFILTERING); + // Add each flag (or flags) on their own, and with add noise enabled. + static constexpr std::array kFlags = { VP8_DEBLOCK, + VP8_DEMACROBLOCK, + VP8_ADDNOISE, + VP8_MFQE, + VP8_MFQE | VP8_DEBLOCK, + VP8_MFQE | VP8_DEMACROBLOCK, + VP8_MFQE | VP8_DEBLOCK | + VP8_DEMACROBLOCK }; + for (const int flag : kFlags) { + flags.push_back(flag); + if (flag != VP8_ADDNOISE) { + flags.push_back(flag | VP8_ADDNOISE); + } + } + + std::sort(flags.begin(), flags.end()); + return flags; +} + +template +std::vector GenerateTestParams(const std::vector &flags, + Iterator begin, Iterator end) { + std::vector params; + for (const int flag : flags) { + for (Iterator it = begin; it != end; ++it) { + params.push_back({ flag, *it }); + } + } + return params; +} + +template +std::vector GenerateTestParams( + const std::vector &flags, + const std::array &filenames) { + return GenerateTestParams(flags, filenames.cbegin(), filenames.cend()); +} + +class PostProcTestInvalidFiles : public PostProcTest { + protected: + void HandlePeekResult(libvpx_test::Decoder *const /*decoder*/, + libvpx_test::CompressedVideoSource * /*video*/, + const vpx_codec_err_t /*res_peek*/) override {} + + bool HandleDecodeResult(const vpx_codec_err_t /*res_dec*/, + const libvpx_test::CompressedVideoSource & /*video*/, + libvpx_test::Decoder * /*decoder*/) override { + // Ignore decode errors when decoding corrupted bitstreams. + return true; + } +}; + +TEST_P(PostProcTestInvalidFiles, Decode) { DecodeTest(); } + +#if CONFIG_VP8_DECODER && CONFIG_POSTPROC +VP8_INSTANTIATE_TEST_SUITE( + PostProcTest, + ::testing::ValuesIn(GenerateTestParams( + GeneratePostProcFlags(), libvpx_test::kVP8TestVectors, + libvpx_test::kVP8TestVectors + libvpx_test::kNumVP8TestVectors))); + +constexpr std::array kVP8InvalidFiles = { + "invalid-bug-1443.ivf", "invalid-bug-148271109.ivf", + "invalid-token-partition.ivf", + "invalid-vp80-00-comprehensive-018.ivf.2kf_0x6.ivf", + "invalid-vp80-00-comprehensive-s17661_r01-05_b6-.ivf" +}; + +VP8_INSTANTIATE_TEST_SUITE(PostProcTestInvalidFiles, + ::testing::ValuesIn(GenerateTestParams( + GeneratePostProcFlags(), kVP8InvalidFiles))); +#endif // CONFIG_VP8_DECODER && CONFIG_POSTPROC + +#if CONFIG_VP9_DECODER && CONFIG_VP9_POSTPROC +VP9_INSTANTIATE_TEST_SUITE( + PostProcTest, + ::testing::ValuesIn(GenerateTestParams( + GeneratePostProcFlags(), libvpx_test::kVP9TestVectors, + libvpx_test::kVP9TestVectors + libvpx_test::kNumVP9TestVectors))); + +constexpr std::array kVP9InvalidFiles = { + "invalid-crbug-1558.ivf", "invalid-crbug-1562.ivf", + "invalid-crbug-629481.webm", "invalid-crbug-667044.webm", + "invalid-vp90-01-v3.webm", "invalid-vp90-02-v2.webm", + "invalid-vp90-03-v3.webm", + "invalid-vp90-2-00-quantizer-00.webm.ivf.s5861_r01-05_b6-.v2.ivf", + "invalid-vp90-2-00-quantizer-11.webm.ivf.s52984_r01-05_b6-.ivf", + "invalid-vp90-2-00-quantizer-11.webm.ivf.s52984_r01-05_b6-z.ivf", + // This file is disabled due to its high memory usage. + // "invalid-vp90-2-00-quantizer-63.ivf.kf_65527x61446.ivf", + "invalid-vp90-2-03-size-202x210.webm.ivf.s113306_r01-05_b6-.ivf", + "invalid-vp90-2-03-size-224x196.webm.ivf.s44156_r01-05_b6-.ivf", + "invalid-vp90-2-05-resize.ivf.s59293_r01-05_b6-.ivf", + "invalid-vp90-2-07-frame_parallel-1.webm", + "invalid-vp90-2-07-frame_parallel-2.webm", + "invalid-vp90-2-07-frame_parallel-3.webm", + "invalid-vp90-2-08-tile_1x2_frame_parallel.webm.ivf.s47039_r01-05_b6-.ivf", + "invalid-vp90-2-08-tile_1x4_frame_parallel_all_key.webm", + "invalid-vp90-2-08-tile_1x8_frame_parallel.webm.ivf.s288_r01-05_b6-.ivf", + "invalid-vp90-2-09-aq2.webm.ivf.s3984_r01-05_b6-.v2.ivf", + "invalid-vp90-2-09-subpixel-00.ivf.s19552_r01-05_b6-.v2.ivf", + "invalid-vp90-2-09-subpixel-00.ivf.s20492_r01-05_b6-.v2.ivf", + "invalid-vp90-2-10-show-existing-frame.webm.ivf.s180315_r01-05_b6-.ivf", + "invalid-vp90-2-12-droppable_1.ivf.s3676_r01-05_b6-.ivf", + "invalid-vp90-2-12-droppable_1.ivf.s73804_r01-05_b6-.ivf", + "invalid-vp90-2-21-resize_inter_320x180_5_3-4.webm.ivf.s45551_r01-05_b6-.ivf", + "invalid-vp91-2-mixedrefcsp-444to420.ivf" +}; + +VP9_INSTANTIATE_TEST_SUITE(PostProcTestInvalidFiles, + ::testing::ValuesIn(GenerateTestParams( + GeneratePostProcFlags(), kVP9InvalidFiles))); + +#endif // CONFIG_VP9_DECODER && CONFIG_VP9_POSTPROC + +} // namespace diff --git a/libs/libvpx/test/pp_filter_test.cc b/libs/libvpx/test/pp_filter_test.cc index 775f7f36a3..4ab7fb9d35 100644 --- a/libs/libvpx/test/pp_filter_test.cc +++ b/libs/libvpx/test/pp_filter_test.cc @@ -7,30 +7,35 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ + #include +#include + +#include + #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" +#include "gtest/gtest.h" #include "test/acm_random.h" #include "test/bench.h" #include "test/buffer.h" #include "test/clear_system_state.h" #include "test/register_state_check.h" -#include "third_party/googletest/src/include/gtest/gtest.h" #include "vpx/vpx_integer.h" #include "vpx_mem/vpx_mem.h" using libvpx_test::ACMRandom; using libvpx_test::Buffer; -typedef void (*VpxPostProcDownAndAcrossMbRowFunc)( +using VpxPostProcDownAndAcrossMbRowFunc = void (*)( unsigned char *src_ptr, unsigned char *dst_ptr, int src_pixels_per_line, int dst_pixels_per_line, int cols, unsigned char *flimit, int size); -typedef void (*VpxMbPostProcAcrossIpFunc)(unsigned char *src, int pitch, - int rows, int cols, int flimit); +using VpxMbPostProcAcrossIpFunc = void (*)(unsigned char *src, int pitch, + int rows, int cols, int flimit); -typedef void (*VpxMbPostProcDownFunc)(unsigned char *dst, int pitch, int rows, - int cols, int flimit); +using VpxMbPostProcDownFunc = void (*)(unsigned char *dst, int pitch, int rows, + int cols, int flimit); namespace { // Compute the filter level used in post proc from the loop filter strength @@ -47,10 +52,10 @@ class VpxPostProcDownAndAcrossMbRowTest public: VpxPostProcDownAndAcrossMbRowTest() : mb_post_proc_down_and_across_(GetParam()) {} - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: - virtual void Run(); + void Run() override; const VpxPostProcDownAndAcrossMbRowFunc mb_post_proc_down_and_across_; // Size of the underlying data block that will be filtered. @@ -62,9 +67,10 @@ class VpxPostProcDownAndAcrossMbRowTest }; void VpxPostProcDownAndAcrossMbRowTest::Run() { - mb_post_proc_down_and_across_( - src_image_->TopLeftPixel(), dst_image_->TopLeftPixel(), - src_image_->stride(), dst_image_->stride(), block_width_, flimits_, 16); + mb_post_proc_down_and_across_(src_image_->TopLeftPixel(), + dst_image_->TopLeftPixel(), + src_image_->stride(), dst_image_->stride(), + block_width_, flimits_, block_height_); } // Test routine for the VPx post-processing function @@ -121,99 +127,129 @@ TEST_P(VpxPostProcDownAndAcrossMbRowTest, CheckCvsAssembly) { // Size of the underlying data block that will be filtered. // Y blocks are always a multiple of 16 wide and exactly 16 high. U and V // blocks are always a multiple of 8 wide and exactly 8 high. - block_width_ = 136; - block_height_ = 16; - - // 5-tap filter needs 2 padding rows above and below the block in the input. - // SSE2 reads in blocks of 16. Pad an extra 8 in case the width is not %16. - Buffer src_image = - Buffer(block_width_, block_height_, 2, 2, 10, 2); - ASSERT_TRUE(src_image.Init()); - - // Filter extends output block by 8 samples at left and right edges. - // Though the left padding is only 8 bytes, there is 'above' padding as well - // so when the assembly code tries to read 16 bytes before the pointer it is - // not a problem. - // SSE2 reads in blocks of 16. Pad an extra 8 in case the width is not %16. - Buffer dst_image = - Buffer(block_width_, block_height_, 8, 8, 16, 8); - ASSERT_TRUE(dst_image.Init()); - Buffer dst_image_ref = - Buffer(block_width_, block_height_, 8); - ASSERT_TRUE(dst_image_ref.Init()); - - // Filter values are set in blocks of 16 for Y and 8 for U/V. Each macroblock - // can have a different filter. SSE2 assembly reads flimits in blocks of 16 so - // it must be padded out. - const int flimits_width = block_width_ % 16 ? block_width_ + 8 : block_width_; - flimits_ = reinterpret_cast(vpx_memalign(16, flimits_width)); + static constexpr int kWidths[] = { 8, 16, 24, 32, 136 }; + static constexpr int kHeights[] = { 8, 16 }; ACMRandom rnd; rnd.Reset(ACMRandom::DeterministicSeed()); - // Initialize pixels in the input: - // block pixels to random values. - // border pixels to value 10. - src_image.SetPadding(10); - src_image.Set(&rnd, &ACMRandom::Rand8); - for (int blocks = 0; blocks < block_width_; blocks += 8) { - (void)memset(flimits_, 0, sizeof(*flimits_) * flimits_width); + for (int width : kWidths) { + for (int height : kHeights) { + char str[8]; + snprintf(str, sizeof(str), "%dx%d", width, height); + SCOPED_TRACE(str); + block_width_ = width; + block_height_ = height; - for (int f = 0; f < 255; f++) { - (void)memset(flimits_ + blocks, f, sizeof(*flimits_) * 8); - dst_image.Set(0); - dst_image_ref.Set(0); + // 5-tap filter needs 2 padding rows above and below the block in the + // input. SSE2 reads in blocks of 16. Pad an extra 8 in case the width is + // not %16. + Buffer src_image = + Buffer(block_width_, block_height_, 2, 2, 10, 2); + ASSERT_TRUE(src_image.Init()); - vpx_post_proc_down_and_across_mb_row_c( - src_image.TopLeftPixel(), dst_image_ref.TopLeftPixel(), - src_image.stride(), dst_image_ref.stride(), block_width_, flimits_, - block_height_); - ASM_REGISTER_STATE_CHECK(mb_post_proc_down_and_across_( - src_image.TopLeftPixel(), dst_image.TopLeftPixel(), - src_image.stride(), dst_image.stride(), block_width_, flimits_, - block_height_)); + // Filter extends output block by 8 samples at left and right edges. + // Though the left padding is only 8 bytes, there is 'above' padding as + // well so when the assembly code tries to read 16 bytes before the + // pointer it is not a problem. SSE2 reads in blocks of 16. Pad an extra 8 + // in case the width is not %16. + Buffer dst_image = + Buffer(block_width_, block_height_, 8, 8, 16, 8); + ASSERT_TRUE(dst_image.Init()); + Buffer dst_image_ref = + Buffer(block_width_, block_height_, 8); + ASSERT_TRUE(dst_image_ref.Init()); - ASSERT_TRUE(dst_image.CheckValues(dst_image_ref)); + // Filter values are set in blocks of 16 for Y and 8 for U/V. Each + // macroblock can have a different filter. SSE2 assembly reads flimits in + // blocks of 16 so it must be padded out. + const int flimits_width = + block_width_ % 16 ? block_width_ + 8 : block_width_; + flimits_ = reinterpret_cast(vpx_memalign(16, flimits_width)); + + // Initialize pixels in the input: + // block pixels to random values. + // border pixels to value 10. + src_image.SetPadding(10); + src_image.Set(&rnd, &ACMRandom::Rand8); + + for (int blocks = 0; blocks < block_width_; blocks += 8) { + (void)memset(flimits_, 0, sizeof(*flimits_) * flimits_width); + + for (int f = 0; f < 255; f++) { + (void)memset(flimits_ + blocks, f, sizeof(*flimits_) * 8); + dst_image.Set(0); + dst_image_ref.Set(0); + + vpx_post_proc_down_and_across_mb_row_c( + src_image.TopLeftPixel(), dst_image_ref.TopLeftPixel(), + src_image.stride(), dst_image_ref.stride(), block_width_, + flimits_, block_height_); + ASM_REGISTER_STATE_CHECK(mb_post_proc_down_and_across_( + src_image.TopLeftPixel(), dst_image.TopLeftPixel(), + src_image.stride(), dst_image.stride(), block_width_, flimits_, + block_height_)); + + ASSERT_TRUE(dst_image.CheckValues(dst_image_ref)); + } + } + + vpx_free(flimits_); } } - - vpx_free(flimits_); } TEST_P(VpxPostProcDownAndAcrossMbRowTest, DISABLED_Speed) { - // Size of the underlying data block that will be filtered. - block_width_ = 16; - block_height_ = 16; + static constexpr struct { + int width; + int height; + } kSizes[] = { + { 16, 16 }, + { 136, 16 }, + { 24, 8 }, + { 8, 8 }, + }; - // 5-tap filter needs 2 padding rows above and below the block in the input. - Buffer src_image = Buffer(block_width_, block_height_, 2); - ASSERT_TRUE(src_image.Init()); - this->src_image_ = &src_image; + for (const auto &size : kSizes) { + block_width_ = size.width; + block_height_ = size.height; - // Filter extends output block by 8 samples at left and right edges. - // Though the left padding is only 8 bytes, the assembly code tries to - // read 16 bytes before the pointer. - Buffer dst_image = - Buffer(block_width_, block_height_, 8, 16, 8, 8); - ASSERT_TRUE(dst_image.Init()); - this->dst_image_ = &dst_image; + // 5-tap filter needs 2 padding rows above and below the block in the input. + Buffer src_image = + Buffer(block_width_, block_height_, 2, 2, 10, 2); + ASSERT_TRUE(src_image.Init()); + this->src_image_ = &src_image; - flimits_ = reinterpret_cast(vpx_memalign(16, block_width_)); - (void)memset(flimits_, 255, block_width_); + // Filter extends output block by 8 samples at left and right edges. + // Though the left padding is only 8 bytes, the assembly code tries to + // read 16 bytes before the pointer. Pad an extra 8 in case the width is + // not %16. + Buffer dst_image = + Buffer(block_width_, block_height_, 8, 8, 16, 8); + ASSERT_TRUE(dst_image.Init()); + this->dst_image_ = &dst_image; - // Initialize pixels in the input: - // block pixels to value 1, - // border pixels to value 10. - src_image.SetPadding(10); - src_image.Set(1); + const int flimits_width = + block_width_ % 16 ? block_width_ + 8 : block_width_; + flimits_ = reinterpret_cast(vpx_memalign(16, flimits_width)); + (void)memset(flimits_, 255, flimits_width); - // Initialize pixels in the output to 99. - dst_image.Set(99); + // Initialize pixels in the input: + // block pixels to value 1, + // border pixels to value 10. + src_image.SetPadding(10); + src_image.Set(1); - RunNTimes(INT16_MAX); - PrintMedian("16x16"); + // Initialize pixels in the output to 99. + dst_image.Set(99); - vpx_free(flimits_); + char title[32]; + snprintf(title, sizeof(title), "%dx%d", block_width_, block_height_); + RunNTimes(INT16_MAX); + PrintMedian(title); + + vpx_free(flimits_); + } } class VpxMbPostProcAcrossIpTest @@ -223,10 +259,10 @@ class VpxMbPostProcAcrossIpTest VpxMbPostProcAcrossIpTest() : rows_(16), cols_(16), mb_post_proc_across_ip_(GetParam()), src_(Buffer(rows_, cols_, 8, 8, 17, 8)) {} - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: - virtual void Run(); + void Run() override; void SetCols(unsigned char *s, int rows, int cols, int src_width) { for (int r = 0; r < rows; r++) { @@ -352,10 +388,10 @@ class VpxMbPostProcDownTest : rows_(16), cols_(16), mb_post_proc_down_(GetParam()), src_c_(Buffer(rows_, cols_, 8, 8, 8, 17)) {} - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: - virtual void Run(); + void Run() override; void SetRows(unsigned char *src_c, int rows, int cols, int src_width) { for (int r = 0; r < rows; r++) { @@ -458,14 +494,13 @@ TEST_P(VpxMbPostProcDownTest, CheckLowFilterOutput) { SetRows(src_c_.TopLeftPixel(), rows_, cols_, src_c_.stride()); - unsigned char *expected_output = new unsigned char[rows_ * cols_]; + std::unique_ptr expected_output( + new unsigned char[rows_ * cols_]); ASSERT_NE(expected_output, nullptr); - SetRows(expected_output, rows_, cols_, cols_); + SetRows(expected_output.get(), rows_, cols_, cols_); RunFilterLevel(src_c_.TopLeftPixel(), rows_, cols_, src_c_.stride(), q2mbl(0), - expected_output); - - delete[] expected_output; + expected_output.get()); } TEST_P(VpxMbPostProcDownTest, CheckCvsAssembly) { diff --git a/libs/libvpx/test/predict_test.cc b/libs/libvpx/test/predict_test.cc index 7472970576..b8693dc7e6 100644 --- a/libs/libvpx/test/predict_test.cc +++ b/libs/libvpx/test/predict_test.cc @@ -8,11 +8,12 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include #include #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp8_rtcd.h" #include "./vpx_config.h" @@ -21,20 +22,21 @@ #include "test/clear_system_state.h" #include "test/register_state_check.h" #include "test/util.h" +#include "vp8/common/blockd.h" +#include "vp8/common/reconinter.h" #include "vpx/vpx_integer.h" #include "vpx_mem/vpx_mem.h" -#include "vpx_ports/msvc.h" namespace { using libvpx_test::ACMRandom; using std::make_tuple; -typedef void (*PredictFunc)(uint8_t *src_ptr, int src_pixels_per_line, - int xoffset, int yoffset, uint8_t *dst_ptr, - int dst_pitch); +using PredictFunc = void (*)(uint8_t *src_ptr, int src_pixels_per_line, + int xoffset, int yoffset, uint8_t *dst_ptr, + int dst_pitch); -typedef std::tuple PredictParam; +using PredictParam = std::tuple; class PredictTestBase : public AbstractBench, public ::testing::TestWithParam { @@ -43,7 +45,7 @@ class PredictTestBase : public AbstractBench, : width_(GET_PARAM(0)), height_(GET_PARAM(1)), predict_(GET_PARAM(2)), src_(nullptr), padded_dst_(nullptr), dst_(nullptr), dst_c_(nullptr) {} - virtual void SetUp() { + void SetUp() override { src_ = new uint8_t[kSrcSize]; ASSERT_NE(src_, nullptr); @@ -64,7 +66,7 @@ class PredictTestBase : public AbstractBench, memset(dst_c_, 0, 16 * 16); } - virtual void TearDown() { + void TearDown() override { delete[] src_; src_ = nullptr; vpx_free(padded_dst_); @@ -209,7 +211,7 @@ class PredictTestBase : public AbstractBench, } } - void Run() { + void Run() override { for (int xoffset = 0; xoffset < 8; ++xoffset) { for (int yoffset = 0; yoffset < 8; ++yoffset) { if (xoffset == 0 && yoffset == 0) { @@ -312,19 +314,19 @@ INSTANTIATE_TEST_SUITE_P( make_tuple(8, 4, &vp8_sixtap_predict8x4_neon), make_tuple(4, 4, &vp8_sixtap_predict4x4_neon))); #endif -#if HAVE_MMX +#if HAVE_MMX && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P( MMX, SixtapPredictTest, ::testing::Values(make_tuple(4, 4, &vp8_sixtap_predict4x4_mmx))); #endif -#if HAVE_SSE2 +#if HAVE_SSE2 && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P( SSE2, SixtapPredictTest, ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_sse2), make_tuple(8, 8, &vp8_sixtap_predict8x8_sse2), make_tuple(8, 4, &vp8_sixtap_predict8x4_sse2))); #endif -#if HAVE_SSSE3 +#if HAVE_SSSE3 && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P( SSSE3, SixtapPredictTest, ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_ssse3), @@ -350,6 +352,14 @@ INSTANTIATE_TEST_SUITE_P( make_tuple(4, 4, &vp8_sixtap_predict4x4_mmi))); #endif +#if HAVE_LSX +INSTANTIATE_TEST_SUITE_P( + LSX, SixtapPredictTest, + ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_lsx), + make_tuple(8, 8, &vp8_sixtap_predict8x8_lsx), + make_tuple(4, 4, &vp8_sixtap_predict4x4_lsx))); +#endif + class BilinearPredictTest : public PredictTestBase {}; TEST_P(BilinearPredictTest, TestWithRandomData) { @@ -389,7 +399,7 @@ INSTANTIATE_TEST_SUITE_P( make_tuple(8, 4, &vp8_bilinear_predict8x4_sse2), make_tuple(4, 4, &vp8_bilinear_predict4x4_sse2))); #endif -#if HAVE_SSSE3 +#if HAVE_SSSE3 && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P( SSSE3, BilinearPredictTest, ::testing::Values(make_tuple(16, 16, &vp8_bilinear_predict16x16_ssse3), @@ -403,4 +413,110 @@ INSTANTIATE_TEST_SUITE_P( make_tuple(8, 4, &vp8_bilinear_predict8x4_msa), make_tuple(4, 4, &vp8_bilinear_predict4x4_msa))); #endif +class BuildInterPredictorTest : public ::testing::Test { + protected: + enum { + kYStride = 64, + kYSize = kYStride * kYStride, + kUVStride = kYStride >> 1, + kUVSize = kUVStride * kUVStride, + kRef = 0x80, + kFill = 0xcd + }; + + void SetUp() override { + xd_ = + reinterpret_cast(vpx_memalign(32, sizeof(MACROBLOCKD))); + ASSERT_NE(xd_, nullptr); + memset(xd_, 0, sizeof(*xd_)); + + pre_y_ = reinterpret_cast(vpx_memalign(32, kYSize)); + pre_u_ = reinterpret_cast(vpx_memalign(32, kUVSize)); + pre_v_ = reinterpret_cast(vpx_memalign(32, kUVSize)); + dst_y_ = reinterpret_cast(vpx_memalign(32, kYSize)); + dst_u_ = reinterpret_cast(vpx_memalign(32, kUVSize)); + dst_v_ = reinterpret_cast(vpx_memalign(32, kUVSize)); + ASSERT_NE(pre_y_, nullptr); + ASSERT_NE(pre_u_, nullptr); + ASSERT_NE(pre_v_, nullptr); + ASSERT_NE(dst_y_, nullptr); + ASSERT_NE(dst_u_, nullptr); + ASSERT_NE(dst_v_, nullptr); + memset(pre_y_, kRef, kYSize); + memset(pre_u_, kRef, kUVSize); + memset(pre_v_, kRef, kUVSize); + + memset(&mi_, 0, sizeof(mi_)); + xd_->mode_info_context = &mi_; + xd_->pre.y_buffer = pre_y_ + (kYStride >> 1) * kYStride + (kYStride >> 1); + xd_->pre.u_buffer = + pre_u_ + (kUVStride >> 1) * kUVStride + (kUVStride >> 1); + xd_->pre.v_buffer = + pre_v_ + (kUVStride >> 1) * kUVStride + (kUVStride >> 1); + xd_->pre.y_stride = kYStride; + } + + void TearDown() override { + vpx_free(xd_); + vpx_free(pre_y_); + vpx_free(pre_u_); + vpx_free(pre_v_); + vpx_free(dst_y_); + vpx_free(dst_u_); + vpx_free(dst_v_); + libvpx_test::ClearSystemState(); + } + + void RunAndCheck(int row, int col) { + memset(dst_y_, kFill, kYSize); + memset(dst_u_, kFill, kUVSize); + memset(dst_v_, kFill, kUVSize); + + mi_.mbmi.mv.as_mv.row = static_cast(row); + mi_.mbmi.mv.as_mv.col = static_cast(col); + mi_.mbmi.need_to_clamp_mvs = 1; + + uint8_t *const dst_y = + dst_y_ + (kYStride >> 1) * kYStride + (kYStride >> 1); + uint8_t *const dst_u = + dst_u_ + (kUVStride >> 1) * kUVStride + (kUVStride >> 1); + uint8_t *const dst_v = + dst_v_ + (kUVStride >> 1) * kUVStride + (kUVStride >> 1); + + vp8_build_inter16x16_predictors_mb(xd_, dst_y, dst_u, dst_v, kYStride, + kUVStride); + + for (int r = 0; r < 8; ++r) { + for (int c = 0; c < 8; ++c) { + ASSERT_EQ(kRef, dst_u[r * kUVStride + c]) + << "U[" << r << "][" << c << "] mv=(" << row << "," << col << ")"; + ASSERT_EQ(kRef, dst_v[r * kUVStride + c]) + << "V[" << r << "][" << c << "] mv=(" << row << "," << col << ")"; + } + } + } + + MACROBLOCKD *xd_; + MODE_INFO mi_; + uint8_t *pre_y_; + uint8_t *pre_u_; + uint8_t *pre_v_; + uint8_t *dst_y_; + uint8_t *dst_u_; + uint8_t *dst_v_; +}; + +// With full-pixel-only chroma motion (fullpixel_mask == ~7), rounding the +// derived chroma MV down can move it just past the border tap window. The +// chroma destination must still be written from a clamped reference position. +TEST_F(BuildInterPredictorTest, FullPixelChromaMVAlwaysWritesUV) { + xd_->mb_to_left_edge = 0; + xd_->mb_to_right_edge = 0; + xd_->mb_to_top_edge = 0; + xd_->mb_to_bottom_edge = 0; + xd_->fullpixel_mask = ~7; + + RunAndCheck(0, -152); + RunAndCheck(-152, 0); +} } // namespace diff --git a/libs/libvpx/test/quantize_test.cc b/libs/libvpx/test/quantize_test.cc index 57309e8102..848f75b483 100644 --- a/libs/libvpx/test/quantize_test.cc +++ b/libs/libvpx/test/quantize_test.cc @@ -11,7 +11,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp8_rtcd.h" #include "./vpx_config.h" @@ -33,9 +33,9 @@ namespace { const int kNumBlocks = 25; const int kNumBlockEntries = 16; -typedef void (*VP8Quantize)(BLOCK *b, BLOCKD *d); +using VP8Quantize = void (*)(BLOCK *b, BLOCKD *d); -typedef std::tuple VP8QuantizeParam; +using VP8QuantizeParam = std::tuple; using libvpx_test::ACMRandom; using std::make_tuple; @@ -71,7 +71,7 @@ class QuantizeTestBase { // Copy macroblockd from the reference to get pre-set-up dequant values. macroblockd_dst_ = reinterpret_cast( vpx_memalign(32, sizeof(*macroblockd_dst_))); - memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_)); + *macroblockd_dst_ = vp8_comp_->mb.e_mbd; // Fix block pointers - currently they point to the blocks in the reference // structure. vp8_setup_block_dptrs(macroblockd_dst_); @@ -80,7 +80,7 @@ class QuantizeTestBase { void UpdateQuantizer(int q) { vp8_set_quantizer(vp8_comp_, q); - memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_)); + *macroblockd_dst_ = vp8_comp_->mb.e_mbd; vp8_setup_block_dptrs(macroblockd_dst_); } @@ -121,13 +121,13 @@ class QuantizeTest : public QuantizeTestBase, public ::testing::TestWithParam, public AbstractBench { protected: - virtual void SetUp() { + void SetUp() override { SetupCompressor(); asm_quant_ = GET_PARAM(0); c_quant_ = GET_PARAM(1); } - virtual void Run() { + void Run() override { asm_quant_(&vp8_comp_->mb.block[0], ¯oblockd_dst_->block[0]); } @@ -228,7 +228,8 @@ INSTANTIATE_TEST_SUITE_P( #if HAVE_LSX INSTANTIATE_TEST_SUITE_P( LSX, QuantizeTest, - ::testing::Values(make_tuple(&vp8_regular_quantize_b_lsx, - &vp8_regular_quantize_b_c))); + ::testing::Values( + make_tuple(&vp8_fast_quantize_b_lsx, &vp8_fast_quantize_b_c), + make_tuple(&vp8_regular_quantize_b_lsx, &vp8_regular_quantize_b_c))); #endif // HAVE_LSX } // namespace diff --git a/libs/libvpx/test/realtime_test.cc b/libs/libvpx/test/realtime_test.cc index c5de2dcb35..b0cc929dda 100644 --- a/libs/libvpx/test/realtime_test.cc +++ b/libs/libvpx/test/realtime_test.cc @@ -9,11 +9,12 @@ */ #include +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/util.h" #include "test/video_source.h" -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "vpx_config.h" namespace { @@ -26,7 +27,7 @@ class RealtimeTest public ::libvpx_test::CodecTestWithParam { protected: RealtimeTest() : EncoderTest(GET_PARAM(0)), frame_packets_(0) {} - ~RealtimeTest() override {} + ~RealtimeTest() override = default; void SetUp() override { InitializeConfig(); @@ -94,8 +95,11 @@ TEST_P(RealtimeTest, RealtimeDefaultCpuUsed) { TEST_P(RealtimeTest, IntegerOverflow) { TestIntegerOverflow(2048, 2048); } TEST_P(RealtimeTest, IntegerOverflowLarge) { +#ifdef CHROMIUM + GTEST_SKIP() << "16K framebuffers are not supported by Chromium's allocator."; +#else if (IsVP9()) { -#if VPX_ARCH_X86_64 +#if VPX_ARCH_AARCH64 || VPX_ARCH_X86_64 TestIntegerOverflow(16384, 16384); #else TestIntegerOverflow(4096, 4096); @@ -107,6 +111,7 @@ TEST_P(RealtimeTest, IntegerOverflowLarge) { "warnings are fixed."; // TestIntegerOverflow(16383, 16383); } +#endif // defined(CHROMIUM) } VP8_INSTANTIATE_TEST_SUITE(RealtimeTest, diff --git a/libs/libvpx/test/register_state_check.h b/libs/libvpx/test/register_state_check.h index 0b837dd042..96795f65be 100644 --- a/libs/libvpx/test/register_state_check.h +++ b/libs/libvpx/test/register_state_check.h @@ -11,7 +11,7 @@ #ifndef VPX_TEST_REGISTER_STATE_CHECK_H_ #define VPX_TEST_REGISTER_STATE_CHECK_H_ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "vpx/vpx_integer.h" @@ -184,13 +184,13 @@ class RegisterStateCheckMMX { uint16_t pre_fpu_env_[14]; }; -#define API_REGISTER_STATE_CHECK(statement) \ - do { \ - { \ - libvpx_test::RegisterStateCheckMMX reg_check; \ - ASM_REGISTER_STATE_CHECK(statement); \ - } \ - __asm__ volatile("" ::: "memory"); \ +#define API_REGISTER_STATE_CHECK(statement) \ + do { \ + { \ + libvpx_test::RegisterStateCheckMMX reg_check_mmx; \ + ASM_REGISTER_STATE_CHECK(statement); \ + } \ + __asm__ volatile("" ::: "memory"); \ } while (false) } // namespace libvpx_test diff --git a/libs/libvpx/test/resize_test.cc b/libs/libvpx/test/resize_test.cc index c57170ff9b..175a22826a 100644 --- a/libs/libvpx/test/resize_test.cc +++ b/libs/libvpx/test/resize_test.cc @@ -7,16 +7,15 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#include - #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" -#include "test/video_source.h" #include "test/util.h" +#include "test/video_source.h" +#include "vpx_config.h" // Enable(1) or Disable(0) writing of the compressed bitstream. #define WRITE_COMPRESSED_STREAM 0 @@ -94,23 +93,28 @@ struct FrameInfo { void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, unsigned int initial_h, unsigned int *w, unsigned int *h, bool flag_codec, - bool smaller_width_larger_size_) { - if (smaller_width_larger_size_) { - if (frame < 30) { - *w = initial_w; - *h = initial_h; - return; - } + bool smaller_width_larger_size, + bool random_input_one_half_only) { + *w = initial_w; + *h = initial_h; + + if (random_input_one_half_only == 1) { if (frame < 100) { - *w = initial_w * 7 / 10; - *h = initial_h * 16 / 10; return; } + *w = initial_w / 2; + *h = initial_h / 2; + return; + } + if (smaller_width_larger_size) { + if (frame < 30) { + return; + } + *w = initial_w * 7 / 10; + *h = initial_h * 16 / 10; return; } if (frame < 10) { - *w = initial_w; - *h = initial_h; return; } if (frame < 20) { @@ -124,8 +128,6 @@ void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, return; } if (frame < 40) { - *w = initial_w; - *h = initial_h; return; } if (frame < 50) { @@ -139,8 +141,6 @@ void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, return; } if (frame < 70) { - *w = initial_w; - *h = initial_h; return; } if (frame < 80) { @@ -159,8 +159,6 @@ void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, return; } if (frame < 110) { - *w = initial_w; - *h = initial_h; return; } if (frame < 120) { @@ -179,8 +177,6 @@ void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, return; } if (frame < 150) { - *w = initial_w; - *h = initial_h; return; } if (frame < 160) { @@ -199,8 +195,6 @@ void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, return; } if (frame < 190) { - *w = initial_w; - *h = initial_h; return; } if (frame < 200) { @@ -219,8 +213,6 @@ void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, return; } if (frame < 230) { - *w = initial_w; - *h = initial_h; return; } if (frame < 240) { @@ -234,8 +226,6 @@ void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, return; } if (frame < 260) { - *w = initial_w; - *h = initial_h; return; } // Go down very low. @@ -248,36 +238,52 @@ void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, // Cases that only works for VP9. // For VP9: Swap width and height of original. if (frame < 320) { - *w = initial_h; - *h = initial_w; return; } } - *w = initial_w; - *h = initial_h; } class ResizingVideoSource : public ::libvpx_test::DummyVideoSource { public: - ResizingVideoSource() { - SetSize(kInitialWidth, kInitialHeight); + ResizingVideoSource(int width, int height) + : smaller_width_larger_size_(false), random_input_one_half_only_(false), + configured_width_(width), configured_height_(height) { limit_ = 350; - smaller_width_larger_size_ = false; + SetSize(configured_width_, configured_height_); } bool flag_codec_; bool smaller_width_larger_size_; - virtual ~ResizingVideoSource() {} + bool random_input_one_half_only_; + // configured_width_/height_ is the configured resolution when codec is + // created. + int configured_width_; + int configured_height_; + ~ResizingVideoSource() override = default; protected: - virtual void Next() { + void Next() override { ++frame_; unsigned int width = 0; unsigned int height = 0; - ScaleForFrameNumber(frame_, kInitialWidth, kInitialHeight, &width, &height, - flag_codec_, smaller_width_larger_size_); + ScaleForFrameNumber(frame_, configured_width_, configured_height_, &width, + &height, flag_codec_, smaller_width_larger_size_, + random_input_one_half_only_); SetSize(width, height); FillFrame(); } + + void FillFrame() override { + if (img_) { + memset(img_->img_data, 0, raw_sz_); + if (random_input_one_half_only_) { + libvpx_test::ACMRandom rnd(libvpx_test::ACMRandom::DeterministicSeed()); + unsigned char *image = img_->planes[0]; + for (size_t i = 0; i < raw_sz_; ++i) { + image[i] = rnd.Rand8(); + } + } + } + } }; class ResizeTest @@ -286,14 +292,14 @@ class ResizeTest protected: ResizeTest() : EncoderTest(GET_PARAM(0)) {} - virtual ~ResizeTest() {} + ~ResizeTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(GET_PARAM(1)); } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { ASSERT_NE(static_cast(pkt->data.frame.width[0]), 0); ASSERT_NE(static_cast(pkt->data.frame.height[0]), 0); encode_frame_width_.push_back(pkt->data.frame.width[0]); @@ -308,8 +314,8 @@ class ResizeTest return encode_frame_height_[idx]; } - virtual void DecompressedFrameHook(const vpx_image_t &img, - vpx_codec_pts_t pts) { + void DecompressedFrameHook(const vpx_image_t &img, + vpx_codec_pts_t pts) override { frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h)); } @@ -319,26 +325,26 @@ class ResizeTest }; TEST_P(ResizeTest, TestExternalResizeWorks) { - ResizingVideoSource video; + ResizingVideoSource video(kInitialWidth, kInitialHeight); video.flag_codec_ = false; video.smaller_width_larger_size_ = false; cfg_.g_lag_in_frames = 0; ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); - for (std::vector::const_iterator info = frame_info_list_.begin(); - info != frame_info_list_.end(); ++info) { - const unsigned int frame = static_cast(info->pts); + for (const auto &info : frame_info_list_) { + const unsigned int frame = static_cast(info.pts); unsigned int expected_w; unsigned int expected_h; - const size_t idx = info - frame_info_list_.begin(); - ASSERT_EQ(info->w, GetFrameWidth(idx)); - ASSERT_EQ(info->h, GetFrameHeight(idx)); + const size_t idx = &info - &frame_info_list_[0]; + ASSERT_EQ(info.w, GetFrameWidth(idx)); + ASSERT_EQ(info.h, GetFrameHeight(idx)); ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight, &expected_w, &expected_h, video.flag_codec_, - video.smaller_width_larger_size_); - EXPECT_EQ(expected_w, info->w) + video.smaller_width_larger_size_, + /*random_input_one_half_only=*/false); + EXPECT_EQ(expected_w, info.w) << "Frame " << frame << " had unexpected width"; - EXPECT_EQ(expected_h, info->h) + EXPECT_EQ(expected_h, info.h) << "Frame " << frame << " had unexpected height"; } } @@ -355,15 +361,15 @@ class ResizeInternalTest : public ResizeTest { ResizeInternalTest() : ResizeTest(), frame0_psnr_(0.0) {} #endif - virtual ~ResizeInternalTest() {} + ~ResizeInternalTest() override = default; - virtual void BeginPassHook(unsigned int /*pass*/) { + void BeginPassHook(unsigned int /*pass*/) override { #if WRITE_COMPRESSED_STREAM outfile_ = fopen("vp90-2-05-resize.ivf", "wb"); #endif } - virtual void EndPassHook() { + void EndPassHook() override { #if WRITE_COMPRESSED_STREAM if (outfile_) { if (!fseek(outfile_, 0, SEEK_SET)) @@ -374,8 +380,8 @@ class ResizeInternalTest : public ResizeTest { #endif } - virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, - libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(libvpx_test::VideoSource *video, + libvpx_test::Encoder *encoder) override { if (change_config_) { int new_q = 60; if (video->frame() == 0) { @@ -400,13 +406,13 @@ class ResizeInternalTest : public ResizeTest { } } - virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { + void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) override { if (frame0_psnr_ == 0.) frame0_psnr_ = pkt->data.psnr.psnr[0]; EXPECT_NEAR(pkt->data.psnr.psnr[0], frame0_psnr_, 2.0); } #if WRITE_COMPRESSED_STREAM - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { ++out_frames_; // Write initial file header if first frame. @@ -442,15 +448,14 @@ TEST_P(ResizeInternalTest, TestInternalResizeWorks) { cfg_.g_lag_in_frames = 0; ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); - for (std::vector::const_iterator info = frame_info_list_.begin(); - info != frame_info_list_.end(); ++info) { - const vpx_codec_pts_t pts = info->pts; + for (const auto &info : frame_info_list_) { + const vpx_codec_pts_t pts = info.pts; if (pts >= kStepDownFrame && pts < kStepUpFrame) { - ASSERT_EQ(282U, info->w) << "Frame " << pts << " had unexpected width"; - ASSERT_EQ(173U, info->h) << "Frame " << pts << " had unexpected height"; + ASSERT_EQ(282U, info.w) << "Frame " << pts << " had unexpected width"; + ASSERT_EQ(173U, info.h) << "Frame " << pts << " had unexpected height"; } else { - EXPECT_EQ(352U, info->w) << "Frame " << pts << " had unexpected width"; - EXPECT_EQ(288U, info->h) << "Frame " << pts << " had unexpected height"; + EXPECT_EQ(352U, info.w) << "Frame " << pts << " had unexpected width"; + EXPECT_EQ(288U, info.h) << "Frame " << pts << " had unexpected height"; } } } @@ -469,13 +474,17 @@ class ResizeRealtimeTest public ::libvpx_test::CodecTestWith2Params { protected: ResizeRealtimeTest() : EncoderTest(GET_PARAM(0)) {} - virtual ~ResizeRealtimeTest() {} + ~ResizeRealtimeTest() override = default; - virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, - libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(libvpx_test::VideoSource *video, + libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP9E_SET_AQ_MODE, 3); encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_); + if (cfg_.g_threads > 0) { + encoder->Control(VP9E_SET_ROW_MT, 1); + encoder->Control(VP9E_SET_TILE_COLUMNS, cfg_.g_threads >> 1); + } } if (change_bitrate_ && video->frame() == 120) { @@ -485,24 +494,24 @@ class ResizeRealtimeTest } } - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(GET_PARAM(1)); set_cpu_used_ = GET_PARAM(2); } - virtual void DecompressedFrameHook(const vpx_image_t &img, - vpx_codec_pts_t pts) { + void DecompressedFrameHook(const vpx_image_t &img, + vpx_codec_pts_t pts) override { frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h)); } - virtual void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2) { + void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2) override { double mismatch_psnr = compute_psnr(img1, img2); mismatch_psnr_ += mismatch_psnr; ++mismatch_nframes_; } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { ASSERT_NE(static_cast(pkt->data.frame.width[0]), 0); ASSERT_NE(static_cast(pkt->data.frame.height[0]), 0); encode_frame_width_.push_back(pkt->data.frame.width[0]); @@ -551,7 +560,7 @@ class ResizeRealtimeTest }; TEST_P(ResizeRealtimeTest, TestExternalResizeWorks) { - ResizingVideoSource video; + ResizingVideoSource video(kInitialWidth, kInitialHeight); video.flag_codec_ = true; video.smaller_width_larger_size_ = false; DefaultConfig(); @@ -562,24 +571,57 @@ TEST_P(ResizeRealtimeTest, TestExternalResizeWorks) { mismatch_nframes_ = 0; ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); - for (std::vector::const_iterator info = frame_info_list_.begin(); - info != frame_info_list_.end(); ++info) { - const unsigned int frame = static_cast(info->pts); + for (const auto &info : frame_info_list_) { + const unsigned int frame = static_cast(info.pts); unsigned int expected_w; unsigned int expected_h; ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight, &expected_w, &expected_h, video.flag_codec_, - video.smaller_width_larger_size_); - EXPECT_EQ(expected_w, info->w) + video.smaller_width_larger_size_, + /*random_input_one_half_only=*/false); + EXPECT_EQ(expected_w, info.w) << "Frame " << frame << " had unexpected width"; - EXPECT_EQ(expected_h, info->h) + EXPECT_EQ(expected_h, info.h) << "Frame " << frame << " had unexpected height"; - EXPECT_EQ(static_cast(0), GetMismatchFrames()); + EXPECT_EQ(GetMismatchFrames(), static_cast(0)); } } -TEST_P(ResizeRealtimeTest, DISABLED_TestExternalResizeSmallerWidthBiggerSize) { - ResizingVideoSource video; +// This test uses 4 threads with small keyframe spacing, random input, +// and uses 640x480 as initial resolution. +TEST_P(ResizeRealtimeTest, TestExternalResizeWorks4Threads) { + ResizingVideoSource video(640, 480); + video.flag_codec_ = true; + video.smaller_width_larger_size_ = false; + video.random_input_one_half_only_ = true; + DefaultConfig(); + // Disable internal resize for this test. + cfg_.rc_resize_allowed = 0; + cfg_.g_threads = 4; + cfg_.kf_max_dist = 50; + cfg_.kf_min_dist = 50; + change_bitrate_ = false; + mismatch_psnr_ = 0.0; + mismatch_nframes_ = 0; + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + + for (const auto &info : frame_info_list_) { + const unsigned int frame = static_cast(info.pts); + unsigned int expected_w; + unsigned int expected_h; + ScaleForFrameNumber(frame, 640, 480, &expected_w, &expected_h, + video.flag_codec_, video.smaller_width_larger_size_, + video.random_input_one_half_only_); + EXPECT_EQ(expected_w, info.w) + << "Frame " << frame << " had unexpected width"; + EXPECT_EQ(expected_h, info.h) + << "Frame " << frame << " had unexpected height"; + EXPECT_EQ(GetMismatchFrames(), static_cast(0)); + } +} + +TEST_P(ResizeRealtimeTest, TestExternalResizeSmallerWidthBiggerSize) { + ResizingVideoSource video(kInitialWidth, kInitialHeight); video.flag_codec_ = true; video.smaller_width_larger_size_ = true; DefaultConfig(); @@ -590,19 +632,19 @@ TEST_P(ResizeRealtimeTest, DISABLED_TestExternalResizeSmallerWidthBiggerSize) { mismatch_nframes_ = 0; ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); - for (std::vector::const_iterator info = frame_info_list_.begin(); - info != frame_info_list_.end(); ++info) { - const unsigned int frame = static_cast(info->pts); + for (const auto &info : frame_info_list_) { + const unsigned int frame = static_cast(info.pts); unsigned int expected_w; unsigned int expected_h; ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight, &expected_w, &expected_h, video.flag_codec_, - video.smaller_width_larger_size_); - EXPECT_EQ(expected_w, info->w) + video.smaller_width_larger_size_, + /*random_input_one_half_only=*/false); + EXPECT_EQ(expected_w, info.w) << "Frame " << frame << " had unexpected width"; - EXPECT_EQ(expected_h, info->h) + EXPECT_EQ(expected_h, info.h) << "Frame " << frame << " had unexpected height"; - EXPECT_EQ(static_cast(0), GetMismatchFrames()); + EXPECT_EQ(GetMismatchFrames(), static_cast(0)); } } @@ -620,27 +662,27 @@ TEST_P(ResizeRealtimeTest, TestInternalResizeDown) { mismatch_nframes_ = 0; ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); +#if CONFIG_VP9_DECODER unsigned int last_w = cfg_.g_w; unsigned int last_h = cfg_.g_h; int resize_count = 0; - for (std::vector::const_iterator info = frame_info_list_.begin(); - info != frame_info_list_.end(); ++info) { - if (info->w != last_w || info->h != last_h) { + for (const auto &info : frame_info_list_) { + if (info.w != last_w || info.h != last_h) { // Verify that resize down occurs. - ASSERT_LT(info->w, last_w); - ASSERT_LT(info->h, last_h); - last_w = info->w; - last_h = info->h; + ASSERT_LT(info.w, last_w); + ASSERT_LT(info.h, last_h); + last_w = info.w; + last_h = info.h; resize_count++; } } -#if CONFIG_VP9_DECODER // Verify that we get 1 resize down event in this test. ASSERT_EQ(1, resize_count) << "Resizing should occur."; - EXPECT_EQ(static_cast(0), GetMismatchFrames()); + EXPECT_EQ(GetMismatchFrames(), static_cast(0)); #else - printf("Warning: VP9 decoder unavailable, unable to check resize count!\n"); + GTEST_SKIP() + << "Warning: VP9 decoder unavailable, unable to check resize count!\n"; #endif } @@ -665,33 +707,33 @@ TEST_P(ResizeRealtimeTest, TestInternalResizeDownUpChangeBitRate) { unsigned int last_w = cfg_.g_w; unsigned int last_h = cfg_.g_h; int resize_count = 0; - for (std::vector::const_iterator info = frame_info_list_.begin(); - info != frame_info_list_.end(); ++info) { - const size_t idx = info - frame_info_list_.begin(); - ASSERT_EQ(info->w, GetFrameWidth(idx)); - ASSERT_EQ(info->h, GetFrameHeight(idx)); - if (info->w != last_w || info->h != last_h) { + for (const auto &info : frame_info_list_) { + const size_t idx = &info - &frame_info_list_[0]; + ASSERT_EQ(info.w, GetFrameWidth(idx)); + ASSERT_EQ(info.h, GetFrameHeight(idx)); + if (info.w != last_w || info.h != last_h) { resize_count++; if (resize_count <= 2) { // Verify that resize down occurs. - ASSERT_LT(info->w, last_w); - ASSERT_LT(info->h, last_h); + ASSERT_LT(info.w, last_w); + ASSERT_LT(info.h, last_h); } else if (resize_count > 2) { // Verify that resize up occurs. - ASSERT_GT(info->w, last_w); - ASSERT_GT(info->h, last_h); + ASSERT_GT(info.w, last_w); + ASSERT_GT(info.h, last_h); } - last_w = info->w; - last_h = info->h; + last_w = info.w; + last_h = info.h; } } #if CONFIG_VP9_DECODER // Verify that we get 4 resize events in this test. ASSERT_EQ(resize_count, 4) << "Resizing should occur twice."; - EXPECT_EQ(static_cast(0), GetMismatchFrames()); + EXPECT_EQ(GetMismatchFrames(), static_cast(0)); #else - printf("Warning: VP9 decoder unavailable, unable to check resize count!\n"); + GTEST_SKIP() + << "Warning: VP9 decoder unavailable, unable to check resize count!\n"; #endif } @@ -710,15 +752,15 @@ class ResizeCspTest : public ResizeTest { ResizeCspTest() : ResizeTest(), frame0_psnr_(0.0) {} #endif - virtual ~ResizeCspTest() {} + ~ResizeCspTest() override = default; - virtual void BeginPassHook(unsigned int /*pass*/) { + void BeginPassHook(unsigned int /*pass*/) override { #if WRITE_COMPRESSED_STREAM outfile_ = fopen("vp91-2-05-cspchape.ivf", "wb"); #endif } - virtual void EndPassHook() { + void EndPassHook() override { #if WRITE_COMPRESSED_STREAM if (outfile_) { if (!fseek(outfile_, 0, SEEK_SET)) @@ -729,8 +771,11 @@ class ResizeCspTest : public ResizeTest { #endif } - virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, - libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(libvpx_test::VideoSource *video, + libvpx_test::Encoder *encoder) override { + if (video->frame() == 0) { + encoder->Control(VP8E_SET_CPUUSED, 5); + } if (CspForFrameNumber(video->frame()) != VPX_IMG_FMT_I420 && cfg_.g_profile != 1) { cfg_.g_profile = 1; @@ -743,13 +788,13 @@ class ResizeCspTest : public ResizeTest { } } - virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { + void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) override { if (frame0_psnr_ == 0.) frame0_psnr_ = pkt->data.psnr.psnr[0]; - EXPECT_NEAR(pkt->data.psnr.psnr[0], frame0_psnr_, 2.0); + EXPECT_NEAR(pkt->data.psnr.psnr[0], frame0_psnr_, 3.5); } #if WRITE_COMPRESSED_STREAM - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { ++out_frames_; // Write initial file header if first frame. @@ -775,10 +820,10 @@ class ResizingCspVideoSource : public ::libvpx_test::DummyVideoSource { limit_ = 30; } - virtual ~ResizingCspVideoSource() {} + ~ResizingCspVideoSource() override = default; protected: - virtual void Next() { + void Next() override { ++frame_; SetImageFormat(CspForFrameNumber(frame_)); FillFrame(); @@ -794,8 +839,7 @@ TEST_P(ResizeCspTest, TestResizeCspWorks) { } VP8_INSTANTIATE_TEST_SUITE(ResizeTest, ONE_PASS_TEST_MODES); -VP9_INSTANTIATE_TEST_SUITE(ResizeTest, - ::testing::Values(::libvpx_test::kRealTime)); +VP9_INSTANTIATE_TEST_SUITE(ResizeTest, ONE_PASS_TEST_MODES); VP9_INSTANTIATE_TEST_SUITE(ResizeInternalTest, ::testing::Values(::libvpx_test::kOnePassBest)); VP9_INSTANTIATE_TEST_SUITE(ResizeRealtimeTest, diff --git a/libs/libvpx/test/resize_util.sh b/libs/libvpx/test/resize_util.sh deleted file mode 100755 index a9b0f81e2b..0000000000 --- a/libs/libvpx/test/resize_util.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/sh -## -## Copyright (c) 2014 The WebM project authors. All Rights Reserved. -## -## Use of this source code is governed by a BSD-style license -## that can be found in the LICENSE file in the root of the source -## tree. An additional intellectual property rights grant can be found -## in the file PATENTS. All contributing project authors may -## be found in the AUTHORS file in the root of the source tree. -## -## This file tests the libvpx resize_util example code. To add new tests to -## this file, do the following: -## 1. Write a shell function (this is your test). -## 2. Add the function to resize_util_tests (on a new line). -## -. $(dirname $0)/tools_common.sh - -# Environment check: $YUV_RAW_INPUT is required. -resize_util_verify_environment() { - if [ ! -e "${YUV_RAW_INPUT}" ]; then - echo "Libvpx test data must exist in LIBVPX_TEST_DATA_PATH." - return 1 - fi -} - -# Resizes $YUV_RAW_INPUT using the resize_util example. $1 is the output -# dimensions that will be passed to resize_util. -resize_util() { - local resizer="${LIBVPX_BIN_PATH}/resize_util${VPX_TEST_EXE_SUFFIX}" - local output_file="${VPX_TEST_OUTPUT_DIR}/resize_util.raw" - local frames_to_resize="10" - local target_dimensions="$1" - - # resize_util is available only when CONFIG_SHARED is disabled. - if [ -z "$(vpx_config_option_enabled CONFIG_SHARED)" ]; then - if [ ! -x "${resizer}" ]; then - elog "${resizer} does not exist or is not executable." - return 1 - fi - - eval "${VPX_TEST_PREFIX}" "${resizer}" "${YUV_RAW_INPUT}" \ - "${YUV_RAW_INPUT_WIDTH}x${YUV_RAW_INPUT_HEIGHT}" \ - "${target_dimensions}" "${output_file}" ${frames_to_resize} \ - ${devnull} || return 1 - - [ -e "${output_file}" ] || return 1 - fi -} - -# Halves each dimension of $YUV_RAW_INPUT using resize_util(). -resize_down() { - local target_width=$((${YUV_RAW_INPUT_WIDTH} / 2)) - local target_height=$((${YUV_RAW_INPUT_HEIGHT} / 2)) - - resize_util "${target_width}x${target_height}" -} - -# Doubles each dimension of $YUV_RAW_INPUT using resize_util(). -resize_up() { - local target_width=$((${YUV_RAW_INPUT_WIDTH} * 2)) - local target_height=$((${YUV_RAW_INPUT_HEIGHT} * 2)) - - resize_util "${target_width}x${target_height}" -} - -resize_util_tests="resize_down - resize_up" - -run_tests resize_util_verify_environment "${resize_util_tests}" diff --git a/libs/libvpx/test/sad_test.cc b/libs/libvpx/test/sad_test.cc index 2506f1adbc..0d994571ca 100644 --- a/libs/libvpx/test/sad_test.cc +++ b/libs/libvpx/test/sad_test.cc @@ -8,10 +8,11 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" @@ -23,7 +24,6 @@ #include "vpx/vpx_codec.h" #include "vpx_mem/vpx_mem.h" #include "vpx_ports/mem.h" -#include "vpx_ports/msvc.h" #include "vpx_ports/vpx_timer.h" // const[expr] should be sufficient for DECLARE_ALIGNED but early @@ -38,23 +38,32 @@ struct TestParams { Function func; }; -typedef unsigned int (*SadMxNFunc)(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride); -typedef TestParams SadMxNParam; +using SadMxNFunc = unsigned int (*)(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride); +using SadMxNParam = TestParams; -typedef unsigned int (*SadMxNAvgFunc)(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - const uint8_t *second_pred); -typedef TestParams SadMxNAvgParam; +using SadSkipMxNFunc = unsigned int (*)(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride); +using SadSkipMxNParam = TestParams; -typedef void (*SadMxNx4Func)(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_ptr[], int ref_stride, - unsigned int *sad_array); -typedef TestParams SadMxNx4Param; +using SadMxNAvgFunc = unsigned int (*)(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + const uint8_t *second_pred); +using SadMxNAvgParam = TestParams; -typedef void (*SadMxNx8Func)(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - unsigned int *sad_array); +using SadMxNx4Func = void (*)(const uint8_t *src_ptr, int src_stride, + const uint8_t *const ref_ptr[], int ref_stride, + unsigned int *sad_array); +using SadMxNx4Param = TestParams; + +using SadSkipMxNx4Func = void (*)(const uint8_t *src_ptr, int src_stride, + const uint8_t *const ref_ptr[], + int ref_stride, unsigned int *sad_array); +using SadSkipMxNx4Param = TestParams; + +using SadMxNx8Func = void (*)(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + unsigned int *sad_array); using libvpx_test::ACMRandom; @@ -64,7 +73,7 @@ class SADTestBase : public ::testing::TestWithParam { public: explicit SADTestBase(const ParamType ¶ms) : params_(params) {} - virtual void SetUp() { + void SetUp() override { source_data8_ = reinterpret_cast( vpx_memalign(kDataAlignment, kDataBlockSize)); reference_data8_ = reinterpret_cast( @@ -99,7 +108,7 @@ class SADTestBase : public ::testing::TestWithParam { rnd_.Reset(ACMRandom::DeterministicSeed()); } - virtual void TearDown() { + void TearDown() override { vpx_free(source_data8_); source_data8_ = nullptr; vpx_free(reference_data8_); @@ -170,6 +179,34 @@ class SADTestBase : public ::testing::TestWithParam { return sad; } + // Sum of Absolute Differences Skip rows. Given two blocks, calculate the + // absolute difference between two pixels in the same relative location every + // other row; accumulate and double the result at the end. + uint32_t ReferenceSADSkip(int ref_offset) const { + uint32_t sad = 0; + const uint8_t *const reference8 = GetReferenceFromOffset(ref_offset); + const uint8_t *const source8 = source_data_; +#if CONFIG_VP9_HIGHBITDEPTH + const uint16_t *const reference16 = + CONVERT_TO_SHORTPTR(GetReferenceFromOffset(ref_offset)); + const uint16_t *const source16 = CONVERT_TO_SHORTPTR(source_data_); +#endif // CONFIG_VP9_HIGHBITDEPTH + for (int h = 0; h < params_.height; h += 2) { + for (int w = 0; w < params_.width; ++w) { + if (!use_high_bit_depth_) { + sad += abs(source8[h * source_stride_ + w] - + reference8[h * reference_stride_ + w]); +#if CONFIG_VP9_HIGHBITDEPTH + } else { + sad += abs(source16[h * source_stride_ + w] - + reference16[h * reference_stride_ + w]); +#endif // CONFIG_VP9_HIGHBITDEPTH + } + } + } + return sad * 2; + } + // Sum of Absolute Differences Average. Given two blocks, and a prediction // calculate the absolute difference between one pixel and average of the // corresponding and predicted pixels; accumulate. @@ -290,6 +327,32 @@ class SADx4Test : public SADTestBase { } }; +class SADSkipx4Test : public SADTestBase { + public: + SADSkipx4Test() : SADTestBase(GetParam()) {} + + protected: + void SADs(unsigned int *results) const { + const uint8_t *references[] = { GetReference(0), GetReference(1), + GetReference(2), GetReference(3) }; + + ASM_REGISTER_STATE_CHECK(params_.func( + source_data_, source_stride_, references, reference_stride_, results)); + } + + void CheckSADs() const { + uint32_t reference_sad; + DECLARE_ALIGNED(kDataAlignment, uint32_t, exp_sad[4]); + + SADs(exp_sad); + for (int block = 0; block < 4; ++block) { + reference_sad = ReferenceSADSkip(GetBlockRefOffset(block)); + + EXPECT_EQ(reference_sad, exp_sad[block]) << "block " << block; + } + } +}; + class SADTest : public AbstractBench, public SADTestBase { public: SADTest() : SADTestBase(GetParam()) {} @@ -311,13 +374,40 @@ class SADTest : public AbstractBench, public SADTestBase { ASSERT_EQ(reference_sad, exp_sad); } - void Run() { + void Run() override { params_.func(source_data_, source_stride_, reference_data_, reference_stride_); } }; -class SADavgTest : public SADTestBase { +class SADSkipTest : public AbstractBench, public SADTestBase { + public: + SADSkipTest() : SADTestBase(GetParam()) {} + + protected: + unsigned int SAD(int block_idx) const { + unsigned int ret; + const uint8_t *const reference = GetReference(block_idx); + + ASM_REGISTER_STATE_CHECK(ret = params_.func(source_data_, source_stride_, + reference, reference_stride_)); + return ret; + } + + void CheckSAD() const { + const unsigned int reference_sad = ReferenceSADSkip(GetBlockRefOffset(0)); + const unsigned int exp_sad = SAD(0); + + ASSERT_EQ(reference_sad, exp_sad); + } + + void Run() override { + params_.func(source_data_, source_stride_, reference_data_, + reference_stride_); + } +}; + +class SADavgTest : public AbstractBench, public SADTestBase { public: SADavgTest() : SADTestBase(GetParam()) {} @@ -338,6 +428,11 @@ class SADavgTest : public SADTestBase { ASSERT_EQ(reference_sad, exp_sad); } + + void Run() override { + params_.func(source_data_, source_stride_, reference_data_, + reference_stride_, second_pred_); + } }; TEST_P(SADTest, MaxRef) { @@ -392,6 +487,58 @@ TEST_P(SADTest, DISABLED_Speed) { PrintMedian(title); } +TEST_P(SADSkipTest, MaxRef) { + FillConstant(source_data_, source_stride_, 0); + FillConstant(reference_data_, reference_stride_, mask_); + CheckSAD(); +} + +TEST_P(SADSkipTest, MaxSrc) { + FillConstant(source_data_, source_stride_, mask_); + FillConstant(reference_data_, reference_stride_, 0); + CheckSAD(); +} + +TEST_P(SADSkipTest, ShortRef) { + const int tmp_stride = reference_stride_; + reference_stride_ >>= 1; + FillRandom(source_data_, source_stride_); + FillRandom(reference_data_, reference_stride_); + CheckSAD(); + reference_stride_ = tmp_stride; +} + +TEST_P(SADSkipTest, UnalignedRef) { + // The reference frame, but not the source frame, may be unaligned for + // certain types of searches. + const int tmp_stride = reference_stride_; + reference_stride_ -= 1; + FillRandom(source_data_, source_stride_); + FillRandom(reference_data_, reference_stride_); + CheckSAD(); + reference_stride_ = tmp_stride; +} + +TEST_P(SADSkipTest, ShortSrc) { + const int tmp_stride = source_stride_; + source_stride_ >>= 1; + FillRandom(source_data_, source_stride_); + FillRandom(reference_data_, reference_stride_); + CheckSAD(); + source_stride_ = tmp_stride; +} + +TEST_P(SADSkipTest, DISABLED_Speed) { + const int kCountSpeedTestBlock = 50000000 / (params_.width * params_.height); + FillRandom(source_data_, source_stride_); + + RunNTimes(kCountSpeedTestBlock); + + char title[16]; + snprintf(title, sizeof(title), "%dx%d", params_.width, params_.height); + PrintMedian(title); +} + TEST_P(SADavgTest, MaxRef) { FillConstant(source_data_, source_stride_, 0); FillConstant(reference_data_, reference_stride_, mask_); @@ -437,6 +584,19 @@ TEST_P(SADavgTest, ShortSrc) { source_stride_ = tmp_stride; } +TEST_P(SADavgTest, DISABLED_Speed) { + const int kCountSpeedTestBlock = 50000000 / (params_.width * params_.height); + FillRandom(source_data_, source_stride_); + FillRandom(reference_data_, reference_stride_); + FillRandom(second_pred_, params_.width); + + RunNTimes(kCountSpeedTestBlock); + + char title[16]; + snprintf(title, sizeof(title), "%dx%d", params_.width, params_.height); + PrintMedian(title); +} + TEST_P(SADx4Test, MaxRef) { FillConstant(source_data_, source_stride_, 0); FillConstant(GetReference(0), reference_stride_, mask_); @@ -517,22 +677,117 @@ TEST_P(SADx4Test, DISABLED_Speed) { uint32_t reference_sad[4]; DECLARE_ALIGNED(kDataAlignment, uint32_t, exp_sad[4]); vpx_usec_timer timer; - - memset(reference_sad, 0, sizeof(reference_sad)); - SADs(exp_sad); + for (int block = 0; block < 4; ++block) { + reference_sad[block] = ReferenceSAD(GetBlockRefOffset(block)); + } vpx_usec_timer_start(&timer); for (int i = 0; i < kCountSpeedTestBlock; ++i) { - for (int block = 0; block < 4; ++block) { - reference_sad[block] = ReferenceSAD(GetBlockRefOffset(block)); - } + SADs(exp_sad); } vpx_usec_timer_mark(&timer); for (int block = 0; block < 4; ++block) { EXPECT_EQ(reference_sad[block], exp_sad[block]) << "block " << block; } - const int elapsed_time = - static_cast(vpx_usec_timer_elapsed(&timer) / 1000); - printf("sad%dx%dx4 (%2dbit) time: %5d ms\n", params_.width, params_.height, + const double elapsed_time = vpx_usec_timer_elapsed(&timer) / 1000.0; + printf("sad%dx%dx4 (%2dbit) time: %8.3f ms\n", params_.width, params_.height, + bit_depth_, elapsed_time); + + reference_stride_ = tmp_stride; +} + +TEST_P(SADSkipx4Test, MaxRef) { + FillConstant(source_data_, source_stride_, 0); + FillConstant(GetReference(0), reference_stride_, mask_); + FillConstant(GetReference(1), reference_stride_, mask_); + FillConstant(GetReference(2), reference_stride_, mask_); + FillConstant(GetReference(3), reference_stride_, mask_); + CheckSADs(); +} + +TEST_P(SADSkipx4Test, MaxSrc) { + FillConstant(source_data_, source_stride_, mask_); + FillConstant(GetReference(0), reference_stride_, 0); + FillConstant(GetReference(1), reference_stride_, 0); + FillConstant(GetReference(2), reference_stride_, 0); + FillConstant(GetReference(3), reference_stride_, 0); + CheckSADs(); +} + +TEST_P(SADSkipx4Test, ShortRef) { + int tmp_stride = reference_stride_; + reference_stride_ >>= 1; + FillRandom(source_data_, source_stride_); + FillRandom(GetReference(0), reference_stride_); + FillRandom(GetReference(1), reference_stride_); + FillRandom(GetReference(2), reference_stride_); + FillRandom(GetReference(3), reference_stride_); + CheckSADs(); + reference_stride_ = tmp_stride; +} + +TEST_P(SADSkipx4Test, UnalignedRef) { + // The reference frame, but not the source frame, may be unaligned for + // certain types of searches. + int tmp_stride = reference_stride_; + reference_stride_ -= 1; + FillRandom(source_data_, source_stride_); + FillRandom(GetReference(0), reference_stride_); + FillRandom(GetReference(1), reference_stride_); + FillRandom(GetReference(2), reference_stride_); + FillRandom(GetReference(3), reference_stride_); + CheckSADs(); + reference_stride_ = tmp_stride; +} + +TEST_P(SADSkipx4Test, ShortSrc) { + int tmp_stride = source_stride_; + source_stride_ >>= 1; + FillRandom(source_data_, source_stride_); + FillRandom(GetReference(0), reference_stride_); + FillRandom(GetReference(1), reference_stride_); + FillRandom(GetReference(2), reference_stride_); + FillRandom(GetReference(3), reference_stride_); + CheckSADs(); + source_stride_ = tmp_stride; +} + +TEST_P(SADSkipx4Test, SrcAlignedByWidth) { + uint8_t *tmp_source_data = source_data_; + source_data_ += params_.width; + FillRandom(source_data_, source_stride_); + FillRandom(GetReference(0), reference_stride_); + FillRandom(GetReference(1), reference_stride_); + FillRandom(GetReference(2), reference_stride_); + FillRandom(GetReference(3), reference_stride_); + CheckSADs(); + source_data_ = tmp_source_data; +} + +TEST_P(SADSkipx4Test, DISABLED_Speed) { + int tmp_stride = reference_stride_; + reference_stride_ -= 1; + FillRandom(source_data_, source_stride_); + FillRandom(GetReference(0), reference_stride_); + FillRandom(GetReference(1), reference_stride_); + FillRandom(GetReference(2), reference_stride_); + FillRandom(GetReference(3), reference_stride_); + const int kCountSpeedTestBlock = 500000000 / (params_.width * params_.height); + uint32_t reference_sad[4]; + DECLARE_ALIGNED(kDataAlignment, uint32_t, exp_sad[4]); + vpx_usec_timer timer; + for (int block = 0; block < 4; ++block) { + reference_sad[block] = ReferenceSADSkip(GetBlockRefOffset(block)); + } + vpx_usec_timer_start(&timer); + for (int i = 0; i < kCountSpeedTestBlock; ++i) { + SADs(exp_sad); + } + vpx_usec_timer_mark(&timer); + for (int block = 0; block < 4; ++block) { + EXPECT_EQ(reference_sad[block], exp_sad[block]) << "block " << block; + } + const double elapsed_time = vpx_usec_timer_elapsed(&timer) / 1000.0; + printf("sad%dx%dx4 (%2dbit) time: %8.3f ms\n", params_.width, params_.height, bit_depth_, elapsed_time); reference_stride_ = tmp_stride; @@ -598,6 +853,56 @@ const SadMxNParam c_tests[] = { }; INSTANTIATE_TEST_SUITE_P(C, SADTest, ::testing::ValuesIn(c_tests)); +const SadSkipMxNParam skip_c_tests[] = { + SadSkipMxNParam(64, 64, &vpx_sad_skip_64x64_c), + SadSkipMxNParam(64, 32, &vpx_sad_skip_64x32_c), + SadSkipMxNParam(32, 64, &vpx_sad_skip_32x64_c), + SadSkipMxNParam(32, 32, &vpx_sad_skip_32x32_c), + SadSkipMxNParam(32, 16, &vpx_sad_skip_32x16_c), + SadSkipMxNParam(16, 32, &vpx_sad_skip_16x32_c), + SadSkipMxNParam(16, 16, &vpx_sad_skip_16x16_c), + SadSkipMxNParam(16, 8, &vpx_sad_skip_16x8_c), + SadSkipMxNParam(8, 16, &vpx_sad_skip_8x16_c), + SadSkipMxNParam(8, 8, &vpx_sad_skip_8x8_c), + SadSkipMxNParam(4, 8, &vpx_sad_skip_4x8_c), +#if CONFIG_VP9_HIGHBITDEPTH + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_c, 8), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_c, 8), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_c, 8), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_c, 8), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_c, 8), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_c, 8), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_c, 8), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_c, 8), + SadSkipMxNParam(8, 16, &vpx_highbd_sad_skip_8x16_c, 8), + SadSkipMxNParam(8, 8, &vpx_highbd_sad_skip_8x8_c, 8), + SadSkipMxNParam(4, 8, &vpx_highbd_sad_skip_4x8_c, 8), + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_c, 10), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_c, 10), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_c, 10), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_c, 10), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_c, 10), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_c, 10), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_c, 10), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_c, 10), + SadSkipMxNParam(8, 16, &vpx_highbd_sad_skip_8x16_c, 10), + SadSkipMxNParam(8, 8, &vpx_highbd_sad_skip_8x8_c, 10), + SadSkipMxNParam(4, 8, &vpx_highbd_sad_skip_4x8_c, 10), + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_c, 12), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_c, 12), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_c, 12), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_c, 12), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_c, 12), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_c, 12), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_c, 12), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_c, 12), + SadSkipMxNParam(8, 16, &vpx_highbd_sad_skip_8x16_c, 12), + SadSkipMxNParam(8, 8, &vpx_highbd_sad_skip_8x8_c, 12), + SadSkipMxNParam(4, 8, &vpx_highbd_sad_skip_4x8_c, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH +}; +INSTANTIATE_TEST_SUITE_P(C, SADSkipTest, ::testing::ValuesIn(skip_c_tests)); + const SadMxNAvgParam avg_c_tests[] = { SadMxNAvgParam(64, 64, &vpx_sad64x64_avg_c), SadMxNAvgParam(64, 32, &vpx_sad64x32_avg_c), @@ -714,6 +1019,57 @@ const SadMxNx4Param x4d_c_tests[] = { }; INSTANTIATE_TEST_SUITE_P(C, SADx4Test, ::testing::ValuesIn(x4d_c_tests)); +const SadSkipMxNx4Param skip_x4d_c_tests[] = { + SadSkipMxNx4Param(64, 64, &vpx_sad_skip_64x64x4d_c), + SadSkipMxNx4Param(64, 32, &vpx_sad_skip_64x32x4d_c), + SadSkipMxNx4Param(32, 64, &vpx_sad_skip_32x64x4d_c), + SadSkipMxNx4Param(32, 32, &vpx_sad_skip_32x32x4d_c), + SadSkipMxNx4Param(32, 16, &vpx_sad_skip_32x16x4d_c), + SadSkipMxNx4Param(16, 32, &vpx_sad_skip_16x32x4d_c), + SadSkipMxNx4Param(16, 16, &vpx_sad_skip_16x16x4d_c), + SadSkipMxNx4Param(16, 8, &vpx_sad_skip_16x8x4d_c), + SadSkipMxNx4Param(8, 16, &vpx_sad_skip_8x16x4d_c), + SadSkipMxNx4Param(8, 8, &vpx_sad_skip_8x8x4d_c), + SadSkipMxNx4Param(4, 8, &vpx_sad_skip_4x8x4d_c), +#if CONFIG_VP9_HIGHBITDEPTH + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_c, 8), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_c, 8), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_c, 8), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_c, 8), + SadSkipMxNx4Param(32, 16, &vpx_highbd_sad_skip_32x16x4d_c, 8), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_c, 8), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_c, 8), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_c, 8), + SadSkipMxNx4Param(8, 16, &vpx_highbd_sad_skip_8x16x4d_c, 8), + SadSkipMxNx4Param(8, 8, &vpx_highbd_sad_skip_8x8x4d_c, 8), + SadSkipMxNx4Param(4, 8, &vpx_highbd_sad_skip_4x8x4d_c, 8), + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_c, 10), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_c, 10), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_c, 10), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_c, 10), + SadSkipMxNx4Param(32, 16, &vpx_highbd_sad_skip_32x16x4d_c, 10), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_c, 10), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_c, 10), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_c, 10), + SadSkipMxNx4Param(8, 16, &vpx_highbd_sad_skip_8x16x4d_c, 10), + SadSkipMxNx4Param(8, 8, &vpx_highbd_sad_skip_8x8x4d_c, 10), + SadSkipMxNx4Param(4, 8, &vpx_highbd_sad_skip_4x8x4d_c, 10), + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_c, 12), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_c, 12), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_c, 12), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_c, 12), + SadSkipMxNx4Param(32, 16, &vpx_highbd_sad_skip_32x16x4d_c, 12), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_c, 12), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_c, 12), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_c, 12), + SadSkipMxNx4Param(8, 16, &vpx_highbd_sad_skip_8x16x4d_c, 12), + SadSkipMxNx4Param(8, 8, &vpx_highbd_sad_skip_8x8x4d_c, 12), + SadSkipMxNx4Param(4, 8, &vpx_highbd_sad_skip_4x8x4d_c, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH +}; +INSTANTIATE_TEST_SUITE_P(C, SADSkipx4Test, + ::testing::ValuesIn(skip_x4d_c_tests)); + //------------------------------------------------------------------------------ // ARM functions #if HAVE_NEON @@ -729,9 +1085,137 @@ const SadMxNParam neon_tests[] = { SadMxNParam(8, 4, &vpx_sad8x4_neon), SadMxNParam(4, 8, &vpx_sad4x8_neon), SadMxNParam(4, 4, &vpx_sad4x4_neon), +#if CONFIG_VP9_HIGHBITDEPTH + SadMxNParam(4, 4, &vpx_highbd_sad4x4_neon, 8), + SadMxNParam(4, 8, &vpx_highbd_sad4x8_neon, 8), + SadMxNParam(8, 4, &vpx_highbd_sad8x4_neon, 8), + SadMxNParam(8, 8, &vpx_highbd_sad8x8_neon, 8), + SadMxNParam(8, 16, &vpx_highbd_sad8x16_neon, 8), + SadMxNParam(16, 8, &vpx_highbd_sad16x8_neon, 8), + SadMxNParam(16, 16, &vpx_highbd_sad16x16_neon, 8), + SadMxNParam(16, 32, &vpx_highbd_sad16x32_neon, 8), + SadMxNParam(32, 32, &vpx_highbd_sad32x32_neon, 8), + SadMxNParam(32, 64, &vpx_highbd_sad32x64_neon, 8), + SadMxNParam(64, 32, &vpx_highbd_sad64x32_neon, 8), + SadMxNParam(64, 64, &vpx_highbd_sad64x64_neon, 8), + SadMxNParam(4, 4, &vpx_highbd_sad4x4_neon, 10), + SadMxNParam(4, 8, &vpx_highbd_sad4x8_neon, 10), + SadMxNParam(8, 4, &vpx_highbd_sad8x4_neon, 10), + SadMxNParam(8, 8, &vpx_highbd_sad8x8_neon, 10), + SadMxNParam(8, 16, &vpx_highbd_sad8x16_neon, 10), + SadMxNParam(16, 8, &vpx_highbd_sad16x8_neon, 10), + SadMxNParam(16, 16, &vpx_highbd_sad16x16_neon, 10), + SadMxNParam(16, 32, &vpx_highbd_sad16x32_neon, 10), + SadMxNParam(32, 32, &vpx_highbd_sad32x32_neon, 10), + SadMxNParam(32, 64, &vpx_highbd_sad32x64_neon, 10), + SadMxNParam(64, 32, &vpx_highbd_sad64x32_neon, 10), + SadMxNParam(64, 64, &vpx_highbd_sad64x64_neon, 10), + SadMxNParam(4, 4, &vpx_highbd_sad4x4_neon, 12), + SadMxNParam(4, 8, &vpx_highbd_sad4x8_neon, 12), + SadMxNParam(8, 4, &vpx_highbd_sad8x4_neon, 12), + SadMxNParam(8, 8, &vpx_highbd_sad8x8_neon, 12), + SadMxNParam(8, 16, &vpx_highbd_sad8x16_neon, 12), + SadMxNParam(16, 8, &vpx_highbd_sad16x8_neon, 12), + SadMxNParam(16, 16, &vpx_highbd_sad16x16_neon, 12), + SadMxNParam(16, 32, &vpx_highbd_sad16x32_neon, 12), + SadMxNParam(32, 32, &vpx_highbd_sad32x32_neon, 12), + SadMxNParam(32, 64, &vpx_highbd_sad32x64_neon, 12), + SadMxNParam(64, 32, &vpx_highbd_sad64x32_neon, 12), + SadMxNParam(64, 64, &vpx_highbd_sad64x64_neon, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH + }; INSTANTIATE_TEST_SUITE_P(NEON, SADTest, ::testing::ValuesIn(neon_tests)); +#if HAVE_NEON_DOTPROD +const SadMxNParam neon_dotprod_tests[] = { + SadMxNParam(64, 64, &vpx_sad64x64_neon_dotprod), + SadMxNParam(64, 32, &vpx_sad64x32_neon_dotprod), + SadMxNParam(32, 64, &vpx_sad32x64_neon_dotprod), + SadMxNParam(32, 32, &vpx_sad32x32_neon_dotprod), + SadMxNParam(32, 16, &vpx_sad32x16_neon_dotprod), + SadMxNParam(16, 32, &vpx_sad16x32_neon_dotprod), + SadMxNParam(16, 16, &vpx_sad16x16_neon_dotprod), + SadMxNParam(16, 8, &vpx_sad16x8_neon_dotprod), +}; +INSTANTIATE_TEST_SUITE_P(NEON_DOTPROD, SADTest, + ::testing::ValuesIn(neon_dotprod_tests)); +#endif // HAVE_NEON_DOTPROD + +const SadSkipMxNParam skip_neon_tests[] = { + SadSkipMxNParam(64, 64, &vpx_sad_skip_64x64_neon), + SadSkipMxNParam(64, 32, &vpx_sad_skip_64x32_neon), + SadSkipMxNParam(32, 64, &vpx_sad_skip_32x64_neon), + SadSkipMxNParam(32, 32, &vpx_sad_skip_32x32_neon), + SadSkipMxNParam(32, 16, &vpx_sad_skip_32x16_neon), + SadSkipMxNParam(16, 32, &vpx_sad_skip_16x32_neon), + SadSkipMxNParam(16, 16, &vpx_sad_skip_16x16_neon), + SadSkipMxNParam(16, 8, &vpx_sad_skip_16x8_neon), + SadSkipMxNParam(8, 16, &vpx_sad_skip_8x16_neon), + SadSkipMxNParam(8, 8, &vpx_sad_skip_8x8_neon), + SadSkipMxNParam(8, 4, &vpx_sad_skip_8x4_neon), + SadSkipMxNParam(4, 8, &vpx_sad_skip_4x8_neon), + SadSkipMxNParam(4, 4, &vpx_sad_skip_4x4_neon), +#if CONFIG_VP9_HIGHBITDEPTH + SadSkipMxNParam(4, 4, &vpx_highbd_sad_skip_4x4_neon, 8), + SadSkipMxNParam(4, 8, &vpx_highbd_sad_skip_4x8_neon, 8), + SadSkipMxNParam(8, 4, &vpx_highbd_sad_skip_8x4_neon, 8), + SadSkipMxNParam(8, 8, &vpx_highbd_sad_skip_8x8_neon, 8), + SadSkipMxNParam(8, 16, &vpx_highbd_sad_skip_8x16_neon, 8), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_neon, 8), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_neon, 8), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_neon, 8), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_neon, 8), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_neon, 8), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_neon, 8), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_neon, 8), + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_neon, 8), + SadSkipMxNParam(4, 4, &vpx_highbd_sad_skip_4x4_neon, 10), + SadSkipMxNParam(4, 8, &vpx_highbd_sad_skip_4x8_neon, 10), + SadSkipMxNParam(8, 4, &vpx_highbd_sad_skip_8x4_neon, 10), + SadSkipMxNParam(8, 8, &vpx_highbd_sad_skip_8x8_neon, 10), + SadSkipMxNParam(8, 16, &vpx_highbd_sad_skip_8x16_neon, 10), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_neon, 10), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_neon, 10), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_neon, 10), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_neon, 10), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_neon, 10), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_neon, 10), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_neon, 10), + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_neon, 10), + SadSkipMxNParam(4, 4, &vpx_highbd_sad_skip_4x4_neon, 12), + SadSkipMxNParam(4, 8, &vpx_highbd_sad_skip_4x8_neon, 12), + SadSkipMxNParam(8, 4, &vpx_highbd_sad_skip_8x4_neon, 12), + SadSkipMxNParam(8, 8, &vpx_highbd_sad_skip_8x8_neon, 12), + SadSkipMxNParam(8, 16, &vpx_highbd_sad_skip_8x16_neon, 12), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_neon, 12), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_neon, 12), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_neon, 12), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_neon, 12), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_neon, 12), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_neon, 12), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_neon, 12), + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_neon, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH +}; +INSTANTIATE_TEST_SUITE_P(NEON, SADSkipTest, + ::testing::ValuesIn(skip_neon_tests)); + +#if HAVE_NEON_DOTPROD +const SadSkipMxNParam skip_neon_dotprod_tests[] = { + SadSkipMxNParam(64, 64, &vpx_sad_skip_64x64_neon_dotprod), + SadSkipMxNParam(64, 32, &vpx_sad_skip_64x32_neon_dotprod), + SadSkipMxNParam(32, 64, &vpx_sad_skip_32x64_neon_dotprod), + SadSkipMxNParam(32, 32, &vpx_sad_skip_32x32_neon_dotprod), + SadSkipMxNParam(32, 16, &vpx_sad_skip_32x16_neon_dotprod), + SadSkipMxNParam(16, 32, &vpx_sad_skip_16x32_neon_dotprod), + SadSkipMxNParam(16, 16, &vpx_sad_skip_16x16_neon_dotprod), + SadSkipMxNParam(16, 8, &vpx_sad_skip_16x8_neon_dotprod), +}; +INSTANTIATE_TEST_SUITE_P(NEON_DOTPROD, SADSkipTest, + ::testing::ValuesIn(skip_neon_dotprod_tests)); +#endif // HAVE_NEON_DOTPROD + const SadMxNAvgParam avg_neon_tests[] = { SadMxNAvgParam(64, 64, &vpx_sad64x64_avg_neon), SadMxNAvgParam(64, 32, &vpx_sad64x32_avg_neon), @@ -746,9 +1230,65 @@ const SadMxNAvgParam avg_neon_tests[] = { SadMxNAvgParam(8, 4, &vpx_sad8x4_avg_neon), SadMxNAvgParam(4, 8, &vpx_sad4x8_avg_neon), SadMxNAvgParam(4, 4, &vpx_sad4x4_avg_neon), +#if CONFIG_VP9_HIGHBITDEPTH + SadMxNAvgParam(4, 4, &vpx_highbd_sad4x4_avg_neon, 8), + SadMxNAvgParam(4, 8, &vpx_highbd_sad4x8_avg_neon, 8), + SadMxNAvgParam(8, 4, &vpx_highbd_sad8x4_avg_neon, 8), + SadMxNAvgParam(8, 8, &vpx_highbd_sad8x8_avg_neon, 8), + SadMxNAvgParam(8, 16, &vpx_highbd_sad8x16_avg_neon, 8), + SadMxNAvgParam(16, 8, &vpx_highbd_sad16x8_avg_neon, 8), + SadMxNAvgParam(16, 16, &vpx_highbd_sad16x16_avg_neon, 8), + SadMxNAvgParam(16, 32, &vpx_highbd_sad16x32_avg_neon, 8), + SadMxNAvgParam(32, 16, &vpx_highbd_sad32x16_avg_neon, 8), + SadMxNAvgParam(32, 32, &vpx_highbd_sad32x32_avg_neon, 8), + SadMxNAvgParam(32, 64, &vpx_highbd_sad32x64_avg_neon, 8), + SadMxNAvgParam(64, 32, &vpx_highbd_sad64x32_avg_neon, 8), + SadMxNAvgParam(64, 64, &vpx_highbd_sad64x64_avg_neon, 8), + SadMxNAvgParam(4, 4, &vpx_highbd_sad4x4_avg_neon, 10), + SadMxNAvgParam(4, 8, &vpx_highbd_sad4x8_avg_neon, 10), + SadMxNAvgParam(8, 4, &vpx_highbd_sad8x4_avg_neon, 10), + SadMxNAvgParam(8, 8, &vpx_highbd_sad8x8_avg_neon, 10), + SadMxNAvgParam(8, 16, &vpx_highbd_sad8x16_avg_neon, 10), + SadMxNAvgParam(16, 8, &vpx_highbd_sad16x8_avg_neon, 10), + SadMxNAvgParam(16, 16, &vpx_highbd_sad16x16_avg_neon, 10), + SadMxNAvgParam(16, 32, &vpx_highbd_sad16x32_avg_neon, 10), + SadMxNAvgParam(32, 16, &vpx_highbd_sad32x16_avg_neon, 10), + SadMxNAvgParam(32, 32, &vpx_highbd_sad32x32_avg_neon, 10), + SadMxNAvgParam(32, 64, &vpx_highbd_sad32x64_avg_neon, 10), + SadMxNAvgParam(64, 32, &vpx_highbd_sad64x32_avg_neon, 10), + SadMxNAvgParam(64, 64, &vpx_highbd_sad64x64_avg_neon, 10), + SadMxNAvgParam(4, 4, &vpx_highbd_sad4x4_avg_neon, 12), + SadMxNAvgParam(4, 8, &vpx_highbd_sad4x8_avg_neon, 12), + SadMxNAvgParam(8, 4, &vpx_highbd_sad8x4_avg_neon, 12), + SadMxNAvgParam(8, 8, &vpx_highbd_sad8x8_avg_neon, 12), + SadMxNAvgParam(8, 16, &vpx_highbd_sad8x16_avg_neon, 12), + SadMxNAvgParam(16, 8, &vpx_highbd_sad16x8_avg_neon, 12), + SadMxNAvgParam(16, 16, &vpx_highbd_sad16x16_avg_neon, 12), + SadMxNAvgParam(16, 32, &vpx_highbd_sad16x32_avg_neon, 12), + SadMxNAvgParam(32, 16, &vpx_highbd_sad32x16_avg_neon, 12), + SadMxNAvgParam(32, 32, &vpx_highbd_sad32x32_avg_neon, 12), + SadMxNAvgParam(32, 64, &vpx_highbd_sad32x64_avg_neon, 12), + SadMxNAvgParam(64, 32, &vpx_highbd_sad64x32_avg_neon, 12), + SadMxNAvgParam(64, 64, &vpx_highbd_sad64x64_avg_neon, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH }; INSTANTIATE_TEST_SUITE_P(NEON, SADavgTest, ::testing::ValuesIn(avg_neon_tests)); +#if HAVE_NEON_DOTPROD +const SadMxNAvgParam avg_neon_dotprod_tests[] = { + SadMxNAvgParam(64, 64, &vpx_sad64x64_avg_neon_dotprod), + SadMxNAvgParam(64, 32, &vpx_sad64x32_avg_neon_dotprod), + SadMxNAvgParam(32, 64, &vpx_sad32x64_avg_neon_dotprod), + SadMxNAvgParam(32, 32, &vpx_sad32x32_avg_neon_dotprod), + SadMxNAvgParam(32, 16, &vpx_sad32x16_avg_neon_dotprod), + SadMxNAvgParam(16, 32, &vpx_sad16x32_avg_neon_dotprod), + SadMxNAvgParam(16, 16, &vpx_sad16x16_avg_neon_dotprod), + SadMxNAvgParam(16, 8, &vpx_sad16x8_avg_neon_dotprod), +}; +INSTANTIATE_TEST_SUITE_P(NEON_DOTPROD, SADavgTest, + ::testing::ValuesIn(avg_neon_dotprod_tests)); +#endif // HAVE_NEON_DOTPROD + const SadMxNx4Param x4d_neon_tests[] = { SadMxNx4Param(64, 64, &vpx_sad64x64x4d_neon), SadMxNx4Param(64, 32, &vpx_sad64x32x4d_neon), @@ -763,13 +1303,137 @@ const SadMxNx4Param x4d_neon_tests[] = { SadMxNx4Param(8, 4, &vpx_sad8x4x4d_neon), SadMxNx4Param(4, 8, &vpx_sad4x8x4d_neon), SadMxNx4Param(4, 4, &vpx_sad4x4x4d_neon), +#if CONFIG_VP9_HIGHBITDEPTH + SadMxNx4Param(4, 4, &vpx_highbd_sad4x4x4d_neon, 8), + SadMxNx4Param(4, 8, &vpx_highbd_sad4x8x4d_neon, 8), + SadMxNx4Param(8, 4, &vpx_highbd_sad8x4x4d_neon, 8), + SadMxNx4Param(8, 8, &vpx_highbd_sad8x8x4d_neon, 8), + SadMxNx4Param(8, 16, &vpx_highbd_sad8x16x4d_neon, 8), + SadMxNx4Param(16, 8, &vpx_highbd_sad16x8x4d_neon, 8), + SadMxNx4Param(16, 16, &vpx_highbd_sad16x16x4d_neon, 8), + SadMxNx4Param(16, 32, &vpx_highbd_sad16x32x4d_neon, 8), + SadMxNx4Param(32, 32, &vpx_highbd_sad32x32x4d_neon, 8), + SadMxNx4Param(32, 64, &vpx_highbd_sad32x64x4d_neon, 8), + SadMxNx4Param(64, 32, &vpx_highbd_sad64x32x4d_neon, 8), + SadMxNx4Param(64, 64, &vpx_highbd_sad64x64x4d_neon, 8), + SadMxNx4Param(4, 4, &vpx_highbd_sad4x4x4d_neon, 10), + SadMxNx4Param(4, 8, &vpx_highbd_sad4x8x4d_neon, 10), + SadMxNx4Param(8, 4, &vpx_highbd_sad8x4x4d_neon, 10), + SadMxNx4Param(8, 8, &vpx_highbd_sad8x8x4d_neon, 10), + SadMxNx4Param(8, 16, &vpx_highbd_sad8x16x4d_neon, 10), + SadMxNx4Param(16, 8, &vpx_highbd_sad16x8x4d_neon, 10), + SadMxNx4Param(16, 16, &vpx_highbd_sad16x16x4d_neon, 10), + SadMxNx4Param(16, 32, &vpx_highbd_sad16x32x4d_neon, 10), + SadMxNx4Param(32, 32, &vpx_highbd_sad32x32x4d_neon, 10), + SadMxNx4Param(32, 64, &vpx_highbd_sad32x64x4d_neon, 10), + SadMxNx4Param(64, 32, &vpx_highbd_sad64x32x4d_neon, 10), + SadMxNx4Param(64, 64, &vpx_highbd_sad64x64x4d_neon, 10), + SadMxNx4Param(4, 4, &vpx_highbd_sad4x4x4d_neon, 12), + SadMxNx4Param(4, 8, &vpx_highbd_sad4x8x4d_neon, 12), + SadMxNx4Param(8, 4, &vpx_highbd_sad8x4x4d_neon, 12), + SadMxNx4Param(8, 8, &vpx_highbd_sad8x8x4d_neon, 12), + SadMxNx4Param(8, 16, &vpx_highbd_sad8x16x4d_neon, 12), + SadMxNx4Param(16, 8, &vpx_highbd_sad16x8x4d_neon, 12), + SadMxNx4Param(16, 16, &vpx_highbd_sad16x16x4d_neon, 12), + SadMxNx4Param(16, 32, &vpx_highbd_sad16x32x4d_neon, 12), + SadMxNx4Param(32, 32, &vpx_highbd_sad32x32x4d_neon, 12), + SadMxNx4Param(32, 64, &vpx_highbd_sad32x64x4d_neon, 12), + SadMxNx4Param(64, 32, &vpx_highbd_sad64x32x4d_neon, 12), + SadMxNx4Param(64, 64, &vpx_highbd_sad64x64x4d_neon, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH }; INSTANTIATE_TEST_SUITE_P(NEON, SADx4Test, ::testing::ValuesIn(x4d_neon_tests)); + +#if HAVE_NEON_DOTPROD +const SadMxNx4Param x4d_neon_dotprod_tests[] = { + SadMxNx4Param(64, 64, &vpx_sad64x64x4d_neon_dotprod), + SadMxNx4Param(64, 32, &vpx_sad64x32x4d_neon_dotprod), + SadMxNx4Param(32, 64, &vpx_sad32x64x4d_neon_dotprod), + SadMxNx4Param(32, 32, &vpx_sad32x32x4d_neon_dotprod), + SadMxNx4Param(32, 16, &vpx_sad32x16x4d_neon_dotprod), + SadMxNx4Param(16, 32, &vpx_sad16x32x4d_neon_dotprod), + SadMxNx4Param(16, 16, &vpx_sad16x16x4d_neon_dotprod), + SadMxNx4Param(16, 8, &vpx_sad16x8x4d_neon_dotprod), +}; +INSTANTIATE_TEST_SUITE_P(NEON_DOTPROD, SADx4Test, + ::testing::ValuesIn(x4d_neon_dotprod_tests)); +#endif // HAVE_NEON_DOTPROD + +const SadSkipMxNx4Param skip_x4d_neon_tests[] = { + SadSkipMxNx4Param(64, 64, &vpx_sad_skip_64x64x4d_neon), + SadSkipMxNx4Param(64, 32, &vpx_sad_skip_64x32x4d_neon), + SadSkipMxNx4Param(32, 64, &vpx_sad_skip_32x64x4d_neon), + SadSkipMxNx4Param(32, 32, &vpx_sad_skip_32x32x4d_neon), + SadSkipMxNx4Param(32, 16, &vpx_sad_skip_32x16x4d_neon), + SadSkipMxNx4Param(16, 32, &vpx_sad_skip_16x32x4d_neon), + SadSkipMxNx4Param(16, 16, &vpx_sad_skip_16x16x4d_neon), + SadSkipMxNx4Param(16, 8, &vpx_sad_skip_16x8x4d_neon), + SadSkipMxNx4Param(8, 16, &vpx_sad_skip_8x16x4d_neon), + SadSkipMxNx4Param(8, 8, &vpx_sad_skip_8x8x4d_neon), + SadSkipMxNx4Param(8, 4, &vpx_sad_skip_8x4x4d_neon), + SadSkipMxNx4Param(4, 8, &vpx_sad_skip_4x8x4d_neon), + SadSkipMxNx4Param(4, 4, &vpx_sad_skip_4x4x4d_neon), +#if CONFIG_VP9_HIGHBITDEPTH + SadSkipMxNx4Param(4, 4, &vpx_highbd_sad_skip_4x4x4d_neon, 8), + SadSkipMxNx4Param(4, 8, &vpx_highbd_sad_skip_4x8x4d_neon, 8), + SadSkipMxNx4Param(8, 4, &vpx_highbd_sad_skip_8x4x4d_neon, 8), + SadSkipMxNx4Param(8, 8, &vpx_highbd_sad_skip_8x8x4d_neon, 8), + SadSkipMxNx4Param(8, 16, &vpx_highbd_sad_skip_8x16x4d_neon, 8), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_neon, 8), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_neon, 8), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_neon, 8), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_neon, 8), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_neon, 8), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_neon, 8), + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_neon, 8), + SadSkipMxNx4Param(4, 4, &vpx_highbd_sad_skip_4x4x4d_neon, 10), + SadSkipMxNx4Param(4, 8, &vpx_highbd_sad_skip_4x8x4d_neon, 10), + SadSkipMxNx4Param(8, 4, &vpx_highbd_sad_skip_8x4x4d_neon, 10), + SadSkipMxNx4Param(8, 8, &vpx_highbd_sad_skip_8x8x4d_neon, 10), + SadSkipMxNx4Param(8, 16, &vpx_highbd_sad_skip_8x16x4d_neon, 10), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_neon, 10), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_neon, 10), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_neon, 10), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_neon, 10), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_neon, 10), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_neon, 10), + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_neon, 10), + SadSkipMxNx4Param(4, 4, &vpx_highbd_sad_skip_4x4x4d_neon, 12), + SadSkipMxNx4Param(4, 8, &vpx_highbd_sad_skip_4x8x4d_neon, 12), + SadSkipMxNx4Param(8, 4, &vpx_highbd_sad_skip_8x4x4d_neon, 12), + SadSkipMxNx4Param(8, 8, &vpx_highbd_sad_skip_8x8x4d_neon, 12), + SadSkipMxNx4Param(8, 16, &vpx_highbd_sad_skip_8x16x4d_neon, 12), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_neon, 12), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_neon, 12), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_neon, 12), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_neon, 12), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_neon, 12), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_neon, 12), + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_neon, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH +}; +INSTANTIATE_TEST_SUITE_P(NEON, SADSkipx4Test, + ::testing::ValuesIn(skip_x4d_neon_tests)); + +#if HAVE_NEON_DOTPROD +const SadSkipMxNx4Param skip_x4d_neon_dotprod_tests[] = { + SadSkipMxNx4Param(64, 64, &vpx_sad_skip_64x64x4d_neon_dotprod), + SadSkipMxNx4Param(64, 32, &vpx_sad_skip_64x32x4d_neon_dotprod), + SadSkipMxNx4Param(32, 64, &vpx_sad_skip_32x64x4d_neon_dotprod), + SadSkipMxNx4Param(32, 32, &vpx_sad_skip_32x32x4d_neon_dotprod), + SadSkipMxNx4Param(32, 16, &vpx_sad_skip_32x16x4d_neon_dotprod), + SadSkipMxNx4Param(16, 32, &vpx_sad_skip_16x32x4d_neon_dotprod), + SadSkipMxNx4Param(16, 16, &vpx_sad_skip_16x16x4d_neon_dotprod), + SadSkipMxNx4Param(16, 8, &vpx_sad_skip_16x8x4d_neon_dotprod), +}; +INSTANTIATE_TEST_SUITE_P(NEON_DOTPROD, SADSkipx4Test, + ::testing::ValuesIn(skip_x4d_neon_dotprod_tests)); +#endif // HAVE_NEON_DOTPROD #endif // HAVE_NEON //------------------------------------------------------------------------------ // x86 functions -#if HAVE_SSE2 +#if HAVE_SSE2 && HAVE_X86_ASM const SadMxNParam sse2_tests[] = { SadMxNParam(64, 64, &vpx_sad64x64_sse2), SadMxNParam(64, 32, &vpx_sad64x32_sse2), @@ -822,6 +1486,54 @@ const SadMxNParam sse2_tests[] = { }; INSTANTIATE_TEST_SUITE_P(SSE2, SADTest, ::testing::ValuesIn(sse2_tests)); +const SadSkipMxNParam skip_sse2_tests[] = { + SadSkipMxNParam(64, 64, &vpx_sad_skip_64x64_sse2), + SadSkipMxNParam(64, 32, &vpx_sad_skip_64x32_sse2), + SadSkipMxNParam(32, 64, &vpx_sad_skip_32x64_sse2), + SadSkipMxNParam(32, 32, &vpx_sad_skip_32x32_sse2), + SadSkipMxNParam(32, 16, &vpx_sad_skip_32x16_sse2), + SadSkipMxNParam(16, 32, &vpx_sad_skip_16x32_sse2), + SadSkipMxNParam(16, 16, &vpx_sad_skip_16x16_sse2), + SadSkipMxNParam(16, 8, &vpx_sad_skip_16x8_sse2), + SadSkipMxNParam(8, 16, &vpx_sad_skip_8x16_sse2), + SadSkipMxNParam(8, 8, &vpx_sad_skip_8x8_sse2), + SadSkipMxNParam(4, 8, &vpx_sad_skip_4x8_sse2), +#if CONFIG_VP9_HIGHBITDEPTH + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_sse2, 8), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_sse2, 8), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_sse2, 8), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_sse2, 8), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_sse2, 8), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_sse2, 8), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_sse2, 8), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_sse2, 8), + SadSkipMxNParam(8, 16, &vpx_highbd_sad_skip_8x16_sse2, 8), + SadSkipMxNParam(8, 8, &vpx_highbd_sad_skip_8x8_sse2, 8), + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_sse2, 10), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_sse2, 10), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_sse2, 10), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_sse2, 10), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_sse2, 10), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_sse2, 10), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_sse2, 10), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_sse2, 10), + SadSkipMxNParam(8, 16, &vpx_highbd_sad_skip_8x16_sse2, 10), + SadSkipMxNParam(8, 8, &vpx_highbd_sad_skip_8x8_sse2, 10), + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_sse2, 12), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_sse2, 12), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_sse2, 12), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_sse2, 12), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_sse2, 12), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_sse2, 12), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_sse2, 12), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_sse2, 12), + SadSkipMxNParam(8, 16, &vpx_highbd_sad_skip_8x16_sse2, 12), + SadSkipMxNParam(8, 8, &vpx_highbd_sad_skip_8x8_sse2, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH +}; +INSTANTIATE_TEST_SUITE_P(SSE2, SADSkipTest, + ::testing::ValuesIn(skip_sse2_tests)); + const SadMxNAvgParam avg_sse2_tests[] = { SadMxNAvgParam(64, 64, &vpx_sad64x64_avg_sse2), SadMxNAvgParam(64, 32, &vpx_sad64x32_avg_sse2), @@ -931,7 +1643,58 @@ const SadMxNx4Param x4d_sse2_tests[] = { #endif // CONFIG_VP9_HIGHBITDEPTH }; INSTANTIATE_TEST_SUITE_P(SSE2, SADx4Test, ::testing::ValuesIn(x4d_sse2_tests)); -#endif // HAVE_SSE2 + +const SadSkipMxNx4Param skip_x4d_sse2_tests[] = { + SadSkipMxNx4Param(64, 64, &vpx_sad_skip_64x64x4d_sse2), + SadSkipMxNx4Param(64, 32, &vpx_sad_skip_64x32x4d_sse2), + SadSkipMxNx4Param(32, 64, &vpx_sad_skip_32x64x4d_sse2), + SadSkipMxNx4Param(32, 32, &vpx_sad_skip_32x32x4d_sse2), + SadSkipMxNx4Param(32, 16, &vpx_sad_skip_32x16x4d_sse2), + SadSkipMxNx4Param(16, 32, &vpx_sad_skip_16x32x4d_sse2), + SadSkipMxNx4Param(16, 16, &vpx_sad_skip_16x16x4d_sse2), + SadSkipMxNx4Param(16, 8, &vpx_sad_skip_16x8x4d_sse2), + SadSkipMxNx4Param(8, 16, &vpx_sad_skip_8x16x4d_sse2), + SadSkipMxNx4Param(8, 8, &vpx_sad_skip_8x8x4d_sse2), + SadSkipMxNx4Param(4, 8, &vpx_sad_skip_4x8x4d_sse2), +#if CONFIG_VP9_HIGHBITDEPTH + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_sse2, 8), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_sse2, 8), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_sse2, 8), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_sse2, 8), + SadSkipMxNx4Param(32, 16, &vpx_highbd_sad_skip_32x16x4d_sse2, 8), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_sse2, 8), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_sse2, 8), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_sse2, 8), + SadSkipMxNx4Param(8, 16, &vpx_highbd_sad_skip_8x16x4d_sse2, 8), + SadSkipMxNx4Param(8, 8, &vpx_highbd_sad_skip_8x8x4d_sse2, 8), + SadSkipMxNx4Param(4, 8, &vpx_highbd_sad_skip_4x8x4d_sse2, 8), + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_sse2, 10), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_sse2, 10), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_sse2, 10), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_sse2, 10), + SadSkipMxNx4Param(32, 16, &vpx_highbd_sad_skip_32x16x4d_sse2, 10), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_sse2, 10), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_sse2, 10), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_sse2, 10), + SadSkipMxNx4Param(8, 16, &vpx_highbd_sad_skip_8x16x4d_sse2, 10), + SadSkipMxNx4Param(8, 8, &vpx_highbd_sad_skip_8x8x4d_sse2, 10), + SadSkipMxNx4Param(4, 8, &vpx_highbd_sad_skip_4x8x4d_sse2, 10), + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_sse2, 12), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_sse2, 12), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_sse2, 12), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_sse2, 12), + SadSkipMxNx4Param(32, 16, &vpx_highbd_sad_skip_32x16x4d_sse2, 12), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_sse2, 12), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_sse2, 12), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_sse2, 12), + SadSkipMxNx4Param(8, 16, &vpx_highbd_sad_skip_8x16x4d_sse2, 12), + SadSkipMxNx4Param(8, 8, &vpx_highbd_sad_skip_8x8x4d_sse2, 12), + SadSkipMxNx4Param(4, 8, &vpx_highbd_sad_skip_4x8x4d_sse2, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH +}; +INSTANTIATE_TEST_SUITE_P(SSE2, SADSkipx4Test, + ::testing::ValuesIn(skip_x4d_sse2_tests)); +#endif // HAVE_SSE2 && HAVE_X86_ASM #if HAVE_SSE3 // Only functions are x3, which do not have tests. @@ -948,32 +1711,213 @@ const SadMxNParam avx2_tests[] = { SadMxNParam(32, 64, &vpx_sad32x64_avx2), SadMxNParam(32, 32, &vpx_sad32x32_avx2), SadMxNParam(32, 16, &vpx_sad32x16_avx2), +#if CONFIG_VP9_HIGHBITDEPTH + SadMxNParam(64, 64, &vpx_highbd_sad64x64_avx2, 8), + SadMxNParam(64, 32, &vpx_highbd_sad64x32_avx2, 8), + SadMxNParam(32, 64, &vpx_highbd_sad32x64_avx2, 8), + SadMxNParam(32, 32, &vpx_highbd_sad32x32_avx2, 8), + SadMxNParam(32, 16, &vpx_highbd_sad32x16_avx2, 8), + SadMxNParam(16, 32, &vpx_highbd_sad16x32_avx2, 8), + SadMxNParam(16, 16, &vpx_highbd_sad16x16_avx2, 8), + SadMxNParam(16, 8, &vpx_highbd_sad16x8_avx2, 8), + + SadMxNParam(64, 64, &vpx_highbd_sad64x64_avx2, 10), + SadMxNParam(64, 32, &vpx_highbd_sad64x32_avx2, 10), + SadMxNParam(32, 64, &vpx_highbd_sad32x64_avx2, 10), + SadMxNParam(32, 32, &vpx_highbd_sad32x32_avx2, 10), + SadMxNParam(32, 16, &vpx_highbd_sad32x16_avx2, 10), + SadMxNParam(16, 32, &vpx_highbd_sad16x32_avx2, 10), + SadMxNParam(16, 16, &vpx_highbd_sad16x16_avx2, 10), + SadMxNParam(16, 8, &vpx_highbd_sad16x8_avx2, 10), + + SadMxNParam(64, 64, &vpx_highbd_sad64x64_avx2, 12), + SadMxNParam(64, 32, &vpx_highbd_sad64x32_avx2, 12), + SadMxNParam(32, 64, &vpx_highbd_sad32x64_avx2, 12), + SadMxNParam(32, 32, &vpx_highbd_sad32x32_avx2, 12), + SadMxNParam(32, 16, &vpx_highbd_sad32x16_avx2, 12), + SadMxNParam(16, 32, &vpx_highbd_sad16x32_avx2, 12), + SadMxNParam(16, 16, &vpx_highbd_sad16x16_avx2, 12), + SadMxNParam(16, 8, &vpx_highbd_sad16x8_avx2, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH }; INSTANTIATE_TEST_SUITE_P(AVX2, SADTest, ::testing::ValuesIn(avx2_tests)); +const SadSkipMxNParam skip_avx2_tests[] = { + SadSkipMxNParam(64, 64, &vpx_sad_skip_64x64_avx2), + SadSkipMxNParam(64, 32, &vpx_sad_skip_64x32_avx2), + SadSkipMxNParam(32, 64, &vpx_sad_skip_32x64_avx2), + SadSkipMxNParam(32, 32, &vpx_sad_skip_32x32_avx2), + SadSkipMxNParam(32, 16, &vpx_sad_skip_32x16_avx2), +#if CONFIG_VP9_HIGHBITDEPTH + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_avx2, 8), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_avx2, 8), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_avx2, 8), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_avx2, 8), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_avx2, 8), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_avx2, 8), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_avx2, 8), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_avx2, 8), + + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_avx2, 10), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_avx2, 10), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_avx2, 10), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_avx2, 10), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_avx2, 10), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_avx2, 10), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_avx2, 10), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_avx2, 10), + + SadSkipMxNParam(64, 64, &vpx_highbd_sad_skip_64x64_avx2, 12), + SadSkipMxNParam(64, 32, &vpx_highbd_sad_skip_64x32_avx2, 12), + SadSkipMxNParam(32, 64, &vpx_highbd_sad_skip_32x64_avx2, 12), + SadSkipMxNParam(32, 32, &vpx_highbd_sad_skip_32x32_avx2, 12), + SadSkipMxNParam(32, 16, &vpx_highbd_sad_skip_32x16_avx2, 12), + SadSkipMxNParam(16, 32, &vpx_highbd_sad_skip_16x32_avx2, 12), + SadSkipMxNParam(16, 16, &vpx_highbd_sad_skip_16x16_avx2, 12), + SadSkipMxNParam(16, 8, &vpx_highbd_sad_skip_16x8_avx2, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH +}; +INSTANTIATE_TEST_SUITE_P(AVX2, SADSkipTest, + ::testing::ValuesIn(skip_avx2_tests)); + const SadMxNAvgParam avg_avx2_tests[] = { SadMxNAvgParam(64, 64, &vpx_sad64x64_avg_avx2), SadMxNAvgParam(64, 32, &vpx_sad64x32_avg_avx2), SadMxNAvgParam(32, 64, &vpx_sad32x64_avg_avx2), SadMxNAvgParam(32, 32, &vpx_sad32x32_avg_avx2), SadMxNAvgParam(32, 16, &vpx_sad32x16_avg_avx2), +#if CONFIG_VP9_HIGHBITDEPTH + SadMxNAvgParam(64, 64, &vpx_highbd_sad64x64_avg_avx2, 8), + SadMxNAvgParam(64, 32, &vpx_highbd_sad64x32_avg_avx2, 8), + SadMxNAvgParam(32, 64, &vpx_highbd_sad32x64_avg_avx2, 8), + SadMxNAvgParam(32, 32, &vpx_highbd_sad32x32_avg_avx2, 8), + SadMxNAvgParam(32, 16, &vpx_highbd_sad32x16_avg_avx2, 8), + SadMxNAvgParam(16, 32, &vpx_highbd_sad16x32_avg_avx2, 8), + SadMxNAvgParam(16, 16, &vpx_highbd_sad16x16_avg_avx2, 8), + SadMxNAvgParam(16, 8, &vpx_highbd_sad16x8_avg_avx2, 8), + SadMxNAvgParam(64, 64, &vpx_highbd_sad64x64_avg_avx2, 10), + SadMxNAvgParam(64, 32, &vpx_highbd_sad64x32_avg_avx2, 10), + SadMxNAvgParam(32, 64, &vpx_highbd_sad32x64_avg_avx2, 10), + SadMxNAvgParam(32, 32, &vpx_highbd_sad32x32_avg_avx2, 10), + SadMxNAvgParam(32, 16, &vpx_highbd_sad32x16_avg_avx2, 10), + SadMxNAvgParam(16, 32, &vpx_highbd_sad16x32_avg_avx2, 10), + SadMxNAvgParam(16, 16, &vpx_highbd_sad16x16_avg_avx2, 10), + SadMxNAvgParam(16, 8, &vpx_highbd_sad16x8_avg_avx2, 10), + SadMxNAvgParam(64, 64, &vpx_highbd_sad64x64_avg_avx2, 12), + SadMxNAvgParam(64, 32, &vpx_highbd_sad64x32_avg_avx2, 12), + SadMxNAvgParam(32, 64, &vpx_highbd_sad32x64_avg_avx2, 12), + SadMxNAvgParam(32, 32, &vpx_highbd_sad32x32_avg_avx2, 12), + SadMxNAvgParam(32, 16, &vpx_highbd_sad32x16_avg_avx2, 12), + SadMxNAvgParam(16, 32, &vpx_highbd_sad16x32_avg_avx2, 12), + SadMxNAvgParam(16, 16, &vpx_highbd_sad16x16_avg_avx2, 12), + SadMxNAvgParam(16, 8, &vpx_highbd_sad16x8_avg_avx2, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH }; INSTANTIATE_TEST_SUITE_P(AVX2, SADavgTest, ::testing::ValuesIn(avg_avx2_tests)); const SadMxNx4Param x4d_avx2_tests[] = { SadMxNx4Param(64, 64, &vpx_sad64x64x4d_avx2), SadMxNx4Param(32, 32, &vpx_sad32x32x4d_avx2), +#if CONFIG_VP9_HIGHBITDEPTH + SadMxNx4Param(64, 64, &vpx_highbd_sad64x64x4d_avx2, 8), + SadMxNx4Param(64, 32, &vpx_highbd_sad64x32x4d_avx2, 8), + SadMxNx4Param(32, 64, &vpx_highbd_sad32x64x4d_avx2, 8), + SadMxNx4Param(32, 32, &vpx_highbd_sad32x32x4d_avx2, 8), + SadMxNx4Param(32, 16, &vpx_highbd_sad32x16x4d_avx2, 8), + SadMxNx4Param(16, 32, &vpx_highbd_sad16x32x4d_avx2, 8), + SadMxNx4Param(16, 16, &vpx_highbd_sad16x16x4d_avx2, 8), + SadMxNx4Param(16, 8, &vpx_highbd_sad16x8x4d_avx2, 8), + SadMxNx4Param(64, 64, &vpx_highbd_sad64x64x4d_avx2, 10), + SadMxNx4Param(64, 32, &vpx_highbd_sad64x32x4d_avx2, 10), + SadMxNx4Param(32, 64, &vpx_highbd_sad32x64x4d_avx2, 10), + SadMxNx4Param(32, 32, &vpx_highbd_sad32x32x4d_avx2, 10), + SadMxNx4Param(32, 16, &vpx_highbd_sad32x16x4d_avx2, 10), + SadMxNx4Param(16, 32, &vpx_highbd_sad16x32x4d_avx2, 10), + SadMxNx4Param(16, 16, &vpx_highbd_sad16x16x4d_avx2, 10), + SadMxNx4Param(16, 8, &vpx_highbd_sad16x8x4d_avx2, 10), + SadMxNx4Param(64, 64, &vpx_highbd_sad64x64x4d_avx2, 12), + SadMxNx4Param(64, 32, &vpx_highbd_sad64x32x4d_avx2, 12), + SadMxNx4Param(32, 64, &vpx_highbd_sad32x64x4d_avx2, 12), + SadMxNx4Param(32, 32, &vpx_highbd_sad32x32x4d_avx2, 12), + SadMxNx4Param(32, 16, &vpx_highbd_sad32x16x4d_avx2, 12), + SadMxNx4Param(16, 32, &vpx_highbd_sad16x32x4d_avx2, 12), + SadMxNx4Param(16, 16, &vpx_highbd_sad16x16x4d_avx2, 12), + SadMxNx4Param(16, 8, &vpx_highbd_sad16x8x4d_avx2, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH }; INSTANTIATE_TEST_SUITE_P(AVX2, SADx4Test, ::testing::ValuesIn(x4d_avx2_tests)); +const SadSkipMxNx4Param skip_x4d_avx2_tests[] = { + SadSkipMxNx4Param(64, 64, &vpx_sad_skip_64x64x4d_avx2), + SadSkipMxNx4Param(64, 32, &vpx_sad_skip_64x32x4d_avx2), + SadSkipMxNx4Param(32, 64, &vpx_sad_skip_32x64x4d_avx2), + SadSkipMxNx4Param(32, 32, &vpx_sad_skip_32x32x4d_avx2), + SadSkipMxNx4Param(32, 16, &vpx_sad_skip_32x16x4d_avx2), +#if CONFIG_VP9_HIGHBITDEPTH + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_avx2, 8), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_avx2, 8), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_avx2, 8), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_avx2, 8), + SadSkipMxNx4Param(32, 16, &vpx_highbd_sad_skip_32x16x4d_avx2, 8), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_avx2, 8), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_avx2, 8), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_avx2, 8), + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_avx2, 10), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_avx2, 10), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_avx2, 10), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_avx2, 10), + SadSkipMxNx4Param(32, 16, &vpx_highbd_sad_skip_32x16x4d_avx2, 10), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_avx2, 10), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_avx2, 10), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_avx2, 10), + SadSkipMxNx4Param(64, 64, &vpx_highbd_sad_skip_64x64x4d_avx2, 12), + SadSkipMxNx4Param(64, 32, &vpx_highbd_sad_skip_64x32x4d_avx2, 12), + SadSkipMxNx4Param(32, 64, &vpx_highbd_sad_skip_32x64x4d_avx2, 12), + SadSkipMxNx4Param(32, 32, &vpx_highbd_sad_skip_32x32x4d_avx2, 12), + SadSkipMxNx4Param(32, 16, &vpx_highbd_sad_skip_32x16x4d_avx2, 12), + SadSkipMxNx4Param(16, 32, &vpx_highbd_sad_skip_16x32x4d_avx2, 12), + SadSkipMxNx4Param(16, 16, &vpx_highbd_sad_skip_16x16x4d_avx2, 12), + SadSkipMxNx4Param(16, 8, &vpx_highbd_sad_skip_16x8x4d_avx2, 12), +#endif // CONFIG_VP9_HIGHBITDEPTH +}; +INSTANTIATE_TEST_SUITE_P(AVX2, SADSkipx4Test, + ::testing::ValuesIn(skip_x4d_avx2_tests)); + #endif // HAVE_AVX2 #if HAVE_AVX512 +const SadMxNParam avx512_tests[] = { + SadMxNParam(64, 64, &vpx_sad64x64_avx512), + SadMxNParam(64, 32, &vpx_sad64x32_avx512), +}; +INSTANTIATE_TEST_SUITE_P(AVX512, SADTest, ::testing::ValuesIn(avx512_tests)); + +const SadSkipMxNParam skip_avx512_tests[] = { + SadSkipMxNParam(64, 64, &vpx_sad_skip_64x64_avx512), + SadSkipMxNParam(64, 32, &vpx_sad_skip_64x32_avx512), +}; +INSTANTIATE_TEST_SUITE_P(AVX512, SADSkipTest, + ::testing::ValuesIn(skip_avx512_tests)); + +const SadMxNAvgParam avg_avx512_tests[] = { + SadMxNAvgParam(64, 64, &vpx_sad64x64_avg_avx512), + SadMxNAvgParam(64, 32, &vpx_sad64x32_avg_avx512), +}; +INSTANTIATE_TEST_SUITE_P(AVX512, SADavgTest, + ::testing::ValuesIn(avg_avx512_tests)); + const SadMxNx4Param x4d_avx512_tests[] = { SadMxNx4Param(64, 64, &vpx_sad64x64x4d_avx512), }; INSTANTIATE_TEST_SUITE_P(AVX512, SADx4Test, ::testing::ValuesIn(x4d_avx512_tests)); + +const SadSkipMxNx4Param skip_x4d_avx512_tests[] = { + SadSkipMxNx4Param(64, 64, &vpx_sad_skip_64x64x4d_avx512), + SadSkipMxNx4Param(64, 32, &vpx_sad_skip_64x32x4d_avx512), +}; +INSTANTIATE_TEST_SUITE_P(AVX512, SADSkipx4Test, + ::testing::ValuesIn(skip_x4d_avx512_tests)); #endif // HAVE_AVX512 //------------------------------------------------------------------------------ diff --git a/libs/libvpx/test/set_roi.cc b/libs/libvpx/test/set_roi.cc index 167cf908fd..ac07ca161f 100644 --- a/libs/libvpx/test/set_roi.cc +++ b/libs/libvpx/test/set_roi.cc @@ -15,7 +15,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/acm_random.h" #include "vp8/encoder/onyx_int.h" #include "vpx/vpx_integer.h" @@ -40,7 +40,7 @@ TEST(VP8RoiMapTest, ParameterCheck) { // Initialize elements of cpi with valid defaults. VP8_COMP cpi; - cpi.mb.e_mbd.mb_segement_abs_delta = SEGMENT_DELTADATA; + cpi.mb.e_mbd.mb_segment_abs_delta = SEGMENT_DELTADATA; cpi.cyclic_refresh_mode_enabled = 0; cpi.mb.e_mbd.segmentation_enabled = 0; cpi.mb.e_mbd.update_mb_segmentation_map = 0; diff --git a/libs/libvpx/test/simple_encode_test.cc b/libs/libvpx/test/simple_encode_test.cc deleted file mode 100644 index 01fc258566..0000000000 --- a/libs/libvpx/test/simple_encode_test.cc +++ /dev/null @@ -1,574 +0,0 @@ -/* - * Copyright (c) 2019 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include -#include -#include -#include -#include "third_party/googletest/src/include/gtest/gtest.h" -#include "test/video_source.h" -#include "vp9/simple_encode.h" - -namespace vp9 { -namespace { - -double GetBitrateInKbps(size_t bit_size, int num_frames, int frame_rate_num, - int frame_rate_den) { - return static_cast(bit_size) / num_frames * frame_rate_num / - frame_rate_den / 1000.0; -} - -// Returns the number of unit in size of 4. -// For example, if size is 7, return 2. -int GetNumUnit4x4(int size) { return (size + 3) >> 2; } - -class SimpleEncodeTest : public ::testing::Test { - protected: - const int width_ = 352; - const int height_ = 288; - const int frame_rate_num_ = 30; - const int frame_rate_den_ = 1; - const int target_bitrate_ = 1000; - const int num_frames_ = 17; - const int target_level_ = LEVEL_UNKNOWN; - const std::string in_file_path_str_ = - libvpx_test::GetDataPath() + "/bus_352x288_420_f20_b8.yuv"; -}; - -TEST_F(SimpleEncodeTest, ComputeFirstPassStats) { - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - std::vector> frame_stats = - simple_encode.ObserveFirstPassStats(); - EXPECT_EQ(frame_stats.size(), static_cast(num_frames_)); - const size_t data_num = frame_stats[0].size(); - // Read ObserveFirstPassStats before changing FIRSTPASS_STATS. - EXPECT_EQ(data_num, static_cast(25)); - for (size_t i = 0; i < frame_stats.size(); ++i) { - EXPECT_EQ(frame_stats[i].size(), data_num); - // FIRSTPASS_STATS's first element is frame - EXPECT_EQ(frame_stats[i][0], i); - // FIRSTPASS_STATS's last element is count, and the count is 1 for single - // frame stats - EXPECT_EQ(frame_stats[i][data_num - 1], 1); - } -} - -TEST_F(SimpleEncodeTest, ObserveFirstPassMotionVectors) { - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - std::vector> fps_motion_vectors = - simple_encode.ObserveFirstPassMotionVectors(); - EXPECT_EQ(fps_motion_vectors.size(), static_cast(num_frames_)); - const size_t num_blocks = ((width_ + 15) >> 4) * ((height_ + 15) >> 4); - EXPECT_EQ(num_blocks, fps_motion_vectors[0].size()); - for (size_t i = 0; i < fps_motion_vectors.size(); ++i) { - EXPECT_EQ(num_blocks, fps_motion_vectors[i].size()); - for (size_t j = 0; j < num_blocks; ++j) { - const int mv_count = fps_motion_vectors[i][j].mv_count; - const int ref_count = - (fps_motion_vectors[i][j].ref_frame[0] != kRefFrameTypeNone) + - (fps_motion_vectors[i][j].ref_frame[1] != kRefFrameTypeNone); - EXPECT_EQ(mv_count, ref_count); - } - } -} - -TEST_F(SimpleEncodeTest, GetCodingFrameNum) { - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - const int num_coding_frames = simple_encode.GetCodingFrameNum(); - EXPECT_EQ(num_coding_frames, 19); -} - -TEST_F(SimpleEncodeTest, EncodeFrame) { - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - int num_coding_frames = simple_encode.GetCodingFrameNum(); - EXPECT_GE(num_coding_frames, num_frames_); - simple_encode.StartEncode(); - size_t total_data_bit_size = 0; - int coded_show_frame_count = 0; - int frame_coding_index = 0; - while (coded_show_frame_count < num_frames_) { - const GroupOfPicture group_of_picture = - simple_encode.ObserveGroupOfPicture(); - const std::vector &encode_frame_list = - group_of_picture.encode_frame_list; - for (size_t group_index = 0; group_index < encode_frame_list.size(); - ++group_index) { - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrame(&encode_frame_result); - EXPECT_EQ(encode_frame_result.show_idx, - encode_frame_list[group_index].show_idx); - EXPECT_EQ(encode_frame_result.frame_type, - encode_frame_list[group_index].frame_type); - EXPECT_EQ(encode_frame_list[group_index].coding_index, - frame_coding_index); - EXPECT_GE(encode_frame_result.psnr, 34) - << "The psnr is supposed to be greater than 34 given the " - "target_bitrate 1000 kbps"; - EXPECT_EQ(encode_frame_result.ref_frame_info, - encode_frame_list[group_index].ref_frame_info); - total_data_bit_size += encode_frame_result.coding_data_bit_size; - ++frame_coding_index; - } - coded_show_frame_count += group_of_picture.show_frame_count; - } - const double bitrate = GetBitrateInKbps(total_data_bit_size, num_frames_, - frame_rate_num_, frame_rate_den_); - const double off_target_threshold = 150; - EXPECT_LE(fabs(target_bitrate_ - bitrate), off_target_threshold); - simple_encode.EndEncode(); -} - -TEST_F(SimpleEncodeTest, ObserveKeyFrameMap) { - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - std::vector key_frame_map = simple_encode.ObserveKeyFrameMap(); - EXPECT_EQ(key_frame_map.size(), static_cast(num_frames_)); - simple_encode.StartEncode(); - int coded_show_frame_count = 0; - while (coded_show_frame_count < num_frames_) { - const GroupOfPicture group_of_picture = - simple_encode.ObserveGroupOfPicture(); - const std::vector &encode_frame_list = - group_of_picture.encode_frame_list; - for (size_t group_index = 0; group_index < encode_frame_list.size(); - ++group_index) { - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrame(&encode_frame_result); - if (encode_frame_result.frame_type == kFrameTypeKey) { - EXPECT_EQ(key_frame_map[encode_frame_result.show_idx], 1); - } else { - EXPECT_EQ(key_frame_map[encode_frame_result.show_idx], 0); - } - } - coded_show_frame_count += group_of_picture.show_frame_count; - } - simple_encode.EndEncode(); -} - -TEST_F(SimpleEncodeTest, EncodeFrameWithTargetFrameBits) { - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - const int num_coding_frames = simple_encode.GetCodingFrameNum(); - simple_encode.StartEncode(); - for (int i = 0; i < num_coding_frames; ++i) { - EncodeFrameInfo encode_frame_info = simple_encode.GetNextEncodeFrameInfo(); - int target_frame_bits; - switch (encode_frame_info.frame_type) { - case kFrameTypeInter: target_frame_bits = 20000; break; - case kFrameTypeKey: - case kFrameTypeAltRef: - case kFrameTypeGolden: target_frame_bits = 100000; break; - case kFrameTypeOverlay: target_frame_bits = 2000; break; - default: target_frame_bits = 20000; - } - - double percent_diff = 15; - if (encode_frame_info.frame_type == kFrameTypeOverlay) { - percent_diff = 100; - } - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrameWithTargetFrameBits( - &encode_frame_result, target_frame_bits, percent_diff); - const int recode_count = encode_frame_result.recode_count; - // TODO(angiebird): Replace 7 by RATE_CTRL_MAX_RECODE_NUM - EXPECT_LE(recode_count, 7); - EXPECT_GE(recode_count, 1); - - const double diff = fabs((double)encode_frame_result.coding_data_bit_size - - target_frame_bits); - EXPECT_LE(diff * 100 / target_frame_bits, percent_diff); - } - simple_encode.EndEncode(); -} - -TEST_F(SimpleEncodeTest, EncodeFrameWithQuantizeIndex) { - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - const int num_coding_frames = simple_encode.GetCodingFrameNum(); - simple_encode.StartEncode(); - for (int i = 0; i < num_coding_frames; ++i) { - const int assigned_quantize_index = 100 + i; - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrameWithQuantizeIndex(&encode_frame_result, - assigned_quantize_index); - EXPECT_EQ(encode_frame_result.quantize_index, assigned_quantize_index); - } - simple_encode.EndEncode(); -} - -// This test encodes the video using EncodeFrame(), where quantize indexes -// are selected by vp9 rate control. -// Encode stats and the quantize_indexes are collected. -// Then the test encodes the video again using EncodeFrameWithQuantizeIndex() -// using the quantize indexes collected from the first run. -// Then test whether the encode stats of the two encoding runs match. -TEST_F(SimpleEncodeTest, EncodeConsistencyTest) { - std::vector quantize_index_list; - std::vector ref_sse_list; - std::vector ref_psnr_list; - std::vector ref_bit_size_list; - std::vector ref_frame_type_list; - std::vector ref_show_idx_list; - { - // The first encode. - SimpleEncode simple_encode(width_, height_, frame_rate_num_, - frame_rate_den_, target_bitrate_, num_frames_, - target_level_, in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - const int num_coding_frames = simple_encode.GetCodingFrameNum(); - simple_encode.StartEncode(); - for (int i = 0; i < num_coding_frames; ++i) { - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrame(&encode_frame_result); - quantize_index_list.push_back(encode_frame_result.quantize_index); - ref_sse_list.push_back(encode_frame_result.sse); - ref_psnr_list.push_back(encode_frame_result.psnr); - ref_bit_size_list.push_back(encode_frame_result.coding_data_bit_size); - ref_frame_type_list.push_back(encode_frame_result.frame_type); - ref_show_idx_list.push_back(encode_frame_result.show_idx); - } - simple_encode.EndEncode(); - } - { - // The second encode with quantize index got from the first encode. - SimpleEncode simple_encode(width_, height_, frame_rate_num_, - frame_rate_den_, target_bitrate_, num_frames_, - target_level_, in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - const int num_coding_frames = simple_encode.GetCodingFrameNum(); - EXPECT_EQ(static_cast(num_coding_frames), - quantize_index_list.size()); - simple_encode.StartEncode(); - for (int i = 0; i < num_coding_frames; ++i) { - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrameWithQuantizeIndex(&encode_frame_result, - quantize_index_list[i]); - EXPECT_EQ(encode_frame_result.quantize_index, quantize_index_list[i]); - EXPECT_EQ(encode_frame_result.sse, ref_sse_list[i]); - EXPECT_DOUBLE_EQ(encode_frame_result.psnr, ref_psnr_list[i]); - EXPECT_EQ(encode_frame_result.coding_data_bit_size, ref_bit_size_list[i]); - EXPECT_EQ(encode_frame_result.frame_type, ref_frame_type_list[i]); - EXPECT_EQ(encode_frame_result.show_idx, ref_show_idx_list[i]); - } - simple_encode.EndEncode(); - } -} - -// Test the information (partition info and motion vector info) stored in -// encoder is the same between two encode runs. -TEST_F(SimpleEncodeTest, EncodeConsistencyTest2) { - const int num_rows_4x4 = GetNumUnit4x4(width_); - const int num_cols_4x4 = GetNumUnit4x4(height_); - const int num_units_4x4 = num_rows_4x4 * num_cols_4x4; - // The first encode. - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - const int num_coding_frames = simple_encode.GetCodingFrameNum(); - std::vector partition_info_list(num_units_4x4 * - num_coding_frames); - std::vector motion_vector_info_list(num_units_4x4 * - num_coding_frames); - simple_encode.StartEncode(); - for (int i = 0; i < num_coding_frames; ++i) { - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrame(&encode_frame_result); - for (int j = 0; j < num_rows_4x4 * num_cols_4x4; ++j) { - partition_info_list[i * num_units_4x4 + j] = - encode_frame_result.partition_info[j]; - motion_vector_info_list[i * num_units_4x4 + j] = - encode_frame_result.motion_vector_info[j]; - } - } - simple_encode.EndEncode(); - // The second encode. - SimpleEncode simple_encode_2(width_, height_, frame_rate_num_, - frame_rate_den_, target_bitrate_, num_frames_, - target_level_, in_file_path_str_.c_str()); - simple_encode_2.ComputeFirstPassStats(); - const int num_coding_frames_2 = simple_encode_2.GetCodingFrameNum(); - simple_encode_2.StartEncode(); - for (int i = 0; i < num_coding_frames_2; ++i) { - EncodeFrameResult encode_frame_result; - simple_encode_2.EncodeFrame(&encode_frame_result); - for (int j = 0; j < num_rows_4x4 * num_cols_4x4; ++j) { - EXPECT_EQ(encode_frame_result.partition_info[j].row, - partition_info_list[i * num_units_4x4 + j].row); - EXPECT_EQ(encode_frame_result.partition_info[j].column, - partition_info_list[i * num_units_4x4 + j].column); - EXPECT_EQ(encode_frame_result.partition_info[j].row_start, - partition_info_list[i * num_units_4x4 + j].row_start); - EXPECT_EQ(encode_frame_result.partition_info[j].column_start, - partition_info_list[i * num_units_4x4 + j].column_start); - EXPECT_EQ(encode_frame_result.partition_info[j].width, - partition_info_list[i * num_units_4x4 + j].width); - EXPECT_EQ(encode_frame_result.partition_info[j].height, - partition_info_list[i * num_units_4x4 + j].height); - - EXPECT_EQ(encode_frame_result.motion_vector_info[j].mv_count, - motion_vector_info_list[i * num_units_4x4 + j].mv_count); - EXPECT_EQ(encode_frame_result.motion_vector_info[j].ref_frame[0], - motion_vector_info_list[i * num_units_4x4 + j].ref_frame[0]); - EXPECT_EQ(encode_frame_result.motion_vector_info[j].ref_frame[1], - motion_vector_info_list[i * num_units_4x4 + j].ref_frame[1]); - EXPECT_EQ(encode_frame_result.motion_vector_info[j].mv_row[0], - motion_vector_info_list[i * num_units_4x4 + j].mv_row[0]); - EXPECT_EQ(encode_frame_result.motion_vector_info[j].mv_column[0], - motion_vector_info_list[i * num_units_4x4 + j].mv_column[0]); - EXPECT_EQ(encode_frame_result.motion_vector_info[j].mv_row[1], - motion_vector_info_list[i * num_units_4x4 + j].mv_row[1]); - EXPECT_EQ(encode_frame_result.motion_vector_info[j].mv_column[1], - motion_vector_info_list[i * num_units_4x4 + j].mv_column[1]); - } - } - simple_encode_2.EndEncode(); -} - -// Test the information stored in encoder is the same between two encode runs. -TEST_F(SimpleEncodeTest, EncodeConsistencyTest3) { - std::vector quantize_index_list; - const int num_rows_4x4 = GetNumUnit4x4(width_); - const int num_cols_4x4 = GetNumUnit4x4(height_); - const int num_units_4x4 = num_rows_4x4 * num_cols_4x4; - // The first encode. - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - const int num_coding_frames = simple_encode.GetCodingFrameNum(); - std::vector partition_info_list(num_units_4x4 * - num_coding_frames); - simple_encode.StartEncode(); - for (int i = 0; i < num_coding_frames; ++i) { - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrame(&encode_frame_result); - quantize_index_list.push_back(encode_frame_result.quantize_index); - for (int j = 0; j < num_rows_4x4 * num_cols_4x4; ++j) { - partition_info_list[i * num_units_4x4 + j] = - encode_frame_result.partition_info[j]; - } - } - simple_encode.EndEncode(); - // The second encode. - SimpleEncode simple_encode_2(width_, height_, frame_rate_num_, - frame_rate_den_, target_bitrate_, num_frames_, - target_level_, in_file_path_str_.c_str()); - simple_encode_2.ComputeFirstPassStats(); - const int num_coding_frames_2 = simple_encode_2.GetCodingFrameNum(); - simple_encode_2.StartEncode(); - for (int i = 0; i < num_coding_frames_2; ++i) { - EncodeFrameResult encode_frame_result; - simple_encode_2.EncodeFrameWithQuantizeIndex(&encode_frame_result, - quantize_index_list[i]); - for (int j = 0; j < num_rows_4x4 * num_cols_4x4; ++j) { - EXPECT_EQ(encode_frame_result.partition_info[j].row, - partition_info_list[i * num_units_4x4 + j].row); - EXPECT_EQ(encode_frame_result.partition_info[j].column, - partition_info_list[i * num_units_4x4 + j].column); - EXPECT_EQ(encode_frame_result.partition_info[j].row_start, - partition_info_list[i * num_units_4x4 + j].row_start); - EXPECT_EQ(encode_frame_result.partition_info[j].column_start, - partition_info_list[i * num_units_4x4 + j].column_start); - EXPECT_EQ(encode_frame_result.partition_info[j].width, - partition_info_list[i * num_units_4x4 + j].width); - EXPECT_EQ(encode_frame_result.partition_info[j].height, - partition_info_list[i * num_units_4x4 + j].height); - } - } - simple_encode_2.EndEncode(); -} - -// Encode with default VP9 decision first. -// Get QPs and arf locations from the first encode. -// Set external arfs and QPs for the second encode. -// Expect to get matched results. -TEST_F(SimpleEncodeTest, EncodeConsistencySetExternalGroupOfPicturesMap) { - std::vector quantize_index_list; - std::vector ref_sse_list; - std::vector ref_psnr_list; - std::vector ref_bit_size_list; - std::vector gop_map(num_frames_, 0); - { - // The first encode. - SimpleEncode simple_encode(width_, height_, frame_rate_num_, - frame_rate_den_, target_bitrate_, num_frames_, - target_level_, in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - simple_encode.StartEncode(); - - int coded_show_frame_count = 0; - while (coded_show_frame_count < num_frames_) { - const GroupOfPicture group_of_picture = - simple_encode.ObserveGroupOfPicture(); - gop_map[coded_show_frame_count] |= kGopMapFlagStart; - if (group_of_picture.use_alt_ref) { - gop_map[coded_show_frame_count] |= kGopMapFlagUseAltRef; - } - const std::vector &encode_frame_list = - group_of_picture.encode_frame_list; - for (size_t group_index = 0; group_index < encode_frame_list.size(); - ++group_index) { - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrame(&encode_frame_result); - quantize_index_list.push_back(encode_frame_result.quantize_index); - ref_sse_list.push_back(encode_frame_result.sse); - ref_psnr_list.push_back(encode_frame_result.psnr); - ref_bit_size_list.push_back(encode_frame_result.coding_data_bit_size); - } - coded_show_frame_count += group_of_picture.show_frame_count; - } - simple_encode.EndEncode(); - } - { - // The second encode with quantize index got from the first encode. - // The external arfs are the same as the first encode. - SimpleEncode simple_encode(width_, height_, frame_rate_num_, - frame_rate_den_, target_bitrate_, num_frames_, - target_level_, in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - simple_encode.SetExternalGroupOfPicturesMap(gop_map.data(), gop_map.size()); - const int num_coding_frames = simple_encode.GetCodingFrameNum(); - EXPECT_EQ(static_cast(num_coding_frames), - quantize_index_list.size()); - simple_encode.StartEncode(); - for (int i = 0; i < num_coding_frames; ++i) { - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrameWithQuantizeIndex(&encode_frame_result, - quantize_index_list[i]); - EXPECT_EQ(encode_frame_result.quantize_index, quantize_index_list[i]); - EXPECT_EQ(encode_frame_result.sse, ref_sse_list[i]); - EXPECT_DOUBLE_EQ(encode_frame_result.psnr, ref_psnr_list[i]); - EXPECT_EQ(encode_frame_result.coding_data_bit_size, ref_bit_size_list[i]); - } - simple_encode.EndEncode(); - } -} - -TEST_F(SimpleEncodeTest, SetExternalGroupOfPicturesMap) { - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - - std::vector gop_map(num_frames_, 0); - - // Should be the first gop group. - gop_map[0] = 0; - - // Second gop group with an alt ref. - gop_map[5] |= kGopMapFlagStart | kGopMapFlagUseAltRef; - - // Third gop group without an alt ref. - gop_map[10] |= kGopMapFlagStart; - - // Last gop group. - gop_map[14] |= kGopMapFlagStart | kGopMapFlagUseAltRef; - - simple_encode.SetExternalGroupOfPicturesMap(gop_map.data(), gop_map.size()); - - std::vector observed_gop_map = - simple_encode.ObserveExternalGroupOfPicturesMap(); - - // First gop group. - // There is always a key frame at show_idx 0 and key frame should always be - // the start of a gop. We expect ObserveExternalGroupOfPicturesMap() will - // insert an extra gop start here. - EXPECT_EQ(observed_gop_map[0], kGopMapFlagStart | kGopMapFlagUseAltRef); - - // Second gop group with an alt ref. - EXPECT_EQ(observed_gop_map[5], kGopMapFlagStart | kGopMapFlagUseAltRef); - - // Third gop group without an alt ref. - EXPECT_EQ(observed_gop_map[10], kGopMapFlagStart); - - // Last gop group. The last gop is not supposed to use an alt ref. We expect - // ObserveExternalGroupOfPicturesMap() will remove the alt ref flag here. - EXPECT_EQ(observed_gop_map[14], kGopMapFlagStart); - - int ref_gop_show_frame_count_list[4] = { 5, 5, 4, 3 }; - size_t ref_gop_coded_frame_count_list[4] = { 6, 6, 4, 3 }; - int gop_count = 0; - - simple_encode.StartEncode(); - int coded_show_frame_count = 0; - while (coded_show_frame_count < num_frames_) { - const GroupOfPicture group_of_picture = - simple_encode.ObserveGroupOfPicture(); - const std::vector &encode_frame_list = - group_of_picture.encode_frame_list; - EXPECT_EQ(encode_frame_list.size(), - ref_gop_coded_frame_count_list[gop_count]); - EXPECT_EQ(group_of_picture.show_frame_count, - ref_gop_show_frame_count_list[gop_count]); - for (size_t group_index = 0; group_index < encode_frame_list.size(); - ++group_index) { - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrame(&encode_frame_result); - } - coded_show_frame_count += group_of_picture.show_frame_count; - ++gop_count; - } - EXPECT_EQ(gop_count, 4); - simple_encode.EndEncode(); -} - -TEST_F(SimpleEncodeTest, GetEncodeFrameInfo) { - // Makes sure that the encode_frame_info obtained from GetEncodeFrameInfo() - // matches the counterpart in encode_frame_result obtained from EncodeFrame() - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - simple_encode.ComputeFirstPassStats(); - const int num_coding_frames = simple_encode.GetCodingFrameNum(); - simple_encode.StartEncode(); - for (int i = 0; i < num_coding_frames; ++i) { - EncodeFrameInfo encode_frame_info = simple_encode.GetNextEncodeFrameInfo(); - EncodeFrameResult encode_frame_result; - simple_encode.EncodeFrame(&encode_frame_result); - EXPECT_EQ(encode_frame_info.show_idx, encode_frame_result.show_idx); - EXPECT_EQ(encode_frame_info.frame_type, encode_frame_result.frame_type); - } - simple_encode.EndEncode(); -} - -TEST_F(SimpleEncodeTest, GetFramePixelCount) { - SimpleEncode simple_encode(width_, height_, frame_rate_num_, frame_rate_den_, - target_bitrate_, num_frames_, target_level_, - in_file_path_str_.c_str()); - EXPECT_EQ(simple_encode.GetFramePixelCount(), - static_cast(width_ * height_ * 3 / 2)); -} - -} // namespace -} // namespace vp9 - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/libs/libvpx/test/sum_squares_test.cc b/libs/libvpx/test/sum_squares_test.cc index df6da84037..c62b12d951 100644 --- a/libs/libvpx/test/sum_squares_test.cc +++ b/libs/libvpx/test/sum_squares_test.cc @@ -9,44 +9,83 @@ */ #include +#include +#include #include #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" #include "test/acm_random.h" +#include "test/bench.h" #include "test/clear_system_state.h" #include "test/register_state_check.h" #include "test/util.h" +#include "vpx_mem/vpx_mem.h" #include "vpx_ports/mem.h" +#include "vpx_ports/vpx_timer.h" using libvpx_test::ACMRandom; +using ::testing::Combine; +using ::testing::Range; +using ::testing::ValuesIn; namespace { const int kNumIterations = 10000; -typedef uint64_t (*SSI16Func)(const int16_t *src, int stride, int size); -typedef std::tuple SumSquaresParam; +using SSI16Func = uint64_t (*)(const int16_t *src, int stride, int size); +using SumSquaresParam = std::tuple; -class SumSquaresTest : public ::testing::TestWithParam { +class SumSquaresTest : public AbstractBench, + public ::testing::TestWithParam { public: - virtual ~SumSquaresTest() {} - virtual void SetUp() { + ~SumSquaresTest() override = default; + void SetUp() override { ref_func_ = GET_PARAM(0); tst_func_ = GET_PARAM(1); } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: + void Run() override { + bench_result_ = tst_func_(bench_src_, bench_stride_, bench_size_); + } + SSI16Func ref_func_; SSI16Func tst_func_; + DECLARE_ALIGNED(16, int16_t, bench_src_[128 * 256]); + int bench_stride_ = 0; + int bench_size_ = 0; + uint64_t bench_result_ = 0; }; GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SumSquaresTest); +TEST_P(SumSquaresTest, DISABLED_Speed) { + ACMRandom rnd(ACMRandom::DeterministicSeed()); + const int msb = 11; // Up to 12 bit input + const int limit = 1 << (msb + 1); + for (int i = 0; i < 128 * 256; ++i) { + bench_src_[i] = rnd(2) ? rnd(limit) : -rnd(limit); + } + + for (int size = 4; size <= 128; size *= 2) { + for (int stride : { size, 2 * size }) { + bench_size_ = size; + bench_stride_ = stride; + const uint64_t expected = ref_func_(bench_src_, stride, size); + RunNTimes(100000000 / (size * size)); + ASSERT_EQ(expected, bench_result_); + char title[64]; + snprintf(title, sizeof(title), "%3dx%-3d stride=%3d", size, size, stride); + PrintMedian(title); + } + } +} + TEST_P(SumSquaresTest, OperationCheck) { ACMRandom rnd(ACMRandom::DeterministicSeed()); DECLARE_ALIGNED(16, int16_t, src[256 * 256]); @@ -113,6 +152,13 @@ INSTANTIATE_TEST_SUITE_P( &vpx_sum_squares_2d_i16_neon))); #endif // HAVE_NEON +#if HAVE_SVE +INSTANTIATE_TEST_SUITE_P( + SVE, SumSquaresTest, + ::testing::Values(make_tuple(&vpx_sum_squares_2d_i16_c, + &vpx_sum_squares_2d_i16_sve))); +#endif // HAVE_SVE + #if HAVE_SSE2 INSTANTIATE_TEST_SUITE_P( SSE2, SumSquaresTest, @@ -126,4 +172,209 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values(make_tuple(&vpx_sum_squares_2d_i16_c, &vpx_sum_squares_2d_i16_msa))); #endif // HAVE_MSA + +using SSEFunc = int64_t (*)(const uint8_t *a, int a_stride, const uint8_t *b, + int b_stride, int width, int height); + +struct TestSSEFuncs { + TestSSEFuncs(SSEFunc ref = nullptr, SSEFunc tst = nullptr) + : ref_func(ref), tst_func(tst) {} + SSEFunc ref_func; // Pointer to reference function + SSEFunc tst_func; // Pointer to tested function +}; + +using SSETestParam = std::tuple; + +class SSETest : public ::testing::TestWithParam { + public: + ~SSETest() override = default; + void SetUp() override { + params_ = GET_PARAM(0); + width_ = GET_PARAM(1); + is_hbd_ = +#if CONFIG_VP9_HIGHBITDEPTH + params_.ref_func == vpx_highbd_sse_c; +#else + false; +#endif + rnd_.Reset(ACMRandom::DeterministicSeed()); + src_ = reinterpret_cast(vpx_memalign(32, 256 * 256 * 2)); + ref_ = reinterpret_cast(vpx_memalign(32, 256 * 256 * 2)); + ASSERT_NE(src_, nullptr); + ASSERT_NE(ref_, nullptr); + } + + void TearDown() override { + vpx_free(src_); + vpx_free(ref_); + } + void RunTest(bool is_random, int width, int height, int run_times); + + void GenRandomData(int width, int height, int stride) { + uint16_t *src16 = reinterpret_cast(src_); + uint16_t *ref16 = reinterpret_cast(ref_); + const int msb = 11; // Up to 12 bit input + const int limit = 1 << (msb + 1); + for (int ii = 0; ii < height; ii++) { + for (int jj = 0; jj < width; jj++) { + if (!is_hbd_) { + src_[ii * stride + jj] = rnd_.Rand8(); + ref_[ii * stride + jj] = rnd_.Rand8(); + } else { + src16[ii * stride + jj] = rnd_(limit); + ref16[ii * stride + jj] = rnd_(limit); + } + } + } + } + + void GenExtremeData(int width, int height, int stride, uint8_t *data, + int16_t val) { + uint16_t *data16 = reinterpret_cast(data); + for (int ii = 0; ii < height; ii++) { + for (int jj = 0; jj < width; jj++) { + if (!is_hbd_) { + data[ii * stride + jj] = static_cast(val); + } else { + data16[ii * stride + jj] = val; + } + } + } + } + + protected: + bool is_hbd_; + int width_; + TestSSEFuncs params_; + uint8_t *src_; + uint8_t *ref_; + ACMRandom rnd_; +}; +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SSETest); + +void SSETest::RunTest(bool is_random, int width, int height, int run_times) { + int failed = 0; + vpx_usec_timer ref_timer, test_timer; + for (int k = 0; k < 3; k++) { + int stride = 4 << rnd_(7); // Up to 256 stride + while (stride < width) { // Make sure it's valid + stride = 4 << rnd_(7); + } + if (is_random) { + GenRandomData(width, height, stride); + } else { + const int msb = is_hbd_ ? 12 : 8; // Up to 12 bit input + const int limit = (1 << msb) - 1; + if (k == 0) { + GenExtremeData(width, height, stride, src_, 0); + GenExtremeData(width, height, stride, ref_, limit); + } else { + GenExtremeData(width, height, stride, src_, limit); + GenExtremeData(width, height, stride, ref_, 0); + } + } + int64_t res_ref, res_tst; + uint8_t *src = src_; + uint8_t *ref = ref_; +#if CONFIG_VP9_HIGHBITDEPTH + if (is_hbd_) { + src = CONVERT_TO_BYTEPTR(src_); + ref = CONVERT_TO_BYTEPTR(ref_); + } +#endif + res_ref = params_.ref_func(src, stride, ref, stride, width, height); + res_tst = params_.tst_func(src, stride, ref, stride, width, height); + if (run_times > 1) { + vpx_usec_timer_start(&ref_timer); + for (int j = 0; j < run_times; j++) { + params_.ref_func(src, stride, ref, stride, width, height); + } + vpx_usec_timer_mark(&ref_timer); + const int elapsed_time_c = + static_cast(vpx_usec_timer_elapsed(&ref_timer)); + + vpx_usec_timer_start(&test_timer); + for (int j = 0; j < run_times; j++) { + params_.tst_func(src, stride, ref, stride, width, height); + } + vpx_usec_timer_mark(&test_timer); + const int elapsed_time_simd = + static_cast(vpx_usec_timer_elapsed(&test_timer)); + + printf( + "c_time=%d \t simd_time=%d \t " + "gain=%d\n", + elapsed_time_c, elapsed_time_simd, + (elapsed_time_c / elapsed_time_simd)); + } else { + if (!failed) { + failed = res_ref != res_tst; + EXPECT_EQ(res_ref, res_tst) + << "Error:" << (is_hbd_ ? "hbd " : " ") << k << " SSE Test [" + << width << "x" << height + << "] C output does not match optimized output."; + } + } + } +} + +TEST_P(SSETest, OperationCheck) { + for (int height = 4; height <= 128; height += 4) { + RunTest(true, width_, height, 1); // GenRandomData + } +} + +TEST_P(SSETest, ExtremeValues) { + for (int height = 4; height <= 128; height += 4) { + RunTest(false, width_, height, 1); + } +} + +TEST_P(SSETest, DISABLED_Speed) { + for (int height = 4; height <= 128; height += 4) { + RunTest(true, width_, height, 100); + } +} + +#if HAVE_NEON +TestSSEFuncs sse_neon[] = { + TestSSEFuncs(&vpx_sse_c, &vpx_sse_neon), +#if CONFIG_VP9_HIGHBITDEPTH + TestSSEFuncs(&vpx_highbd_sse_c, &vpx_highbd_sse_neon) +#endif +}; +INSTANTIATE_TEST_SUITE_P(NEON, SSETest, + Combine(ValuesIn(sse_neon), Range(4, 129, 4))); +#endif // HAVE_NEON + +#if HAVE_NEON_DOTPROD +TestSSEFuncs sse_neon_dotprod[] = { + TestSSEFuncs(&vpx_sse_c, &vpx_sse_neon_dotprod), +}; +INSTANTIATE_TEST_SUITE_P(NEON_DOTPROD, SSETest, + Combine(ValuesIn(sse_neon_dotprod), Range(4, 129, 4))); +#endif // HAVE_NEON_DOTPROD + +#if HAVE_SSE4_1 +TestSSEFuncs sse_sse4[] = { + TestSSEFuncs(&vpx_sse_c, &vpx_sse_sse4_1), +#if CONFIG_VP9_HIGHBITDEPTH + TestSSEFuncs(&vpx_highbd_sse_c, &vpx_highbd_sse_sse4_1) +#endif +}; +INSTANTIATE_TEST_SUITE_P(SSE4_1, SSETest, + Combine(ValuesIn(sse_sse4), Range(4, 129, 4))); +#endif // HAVE_SSE4_1 + +#if HAVE_AVX2 + +TestSSEFuncs sse_avx2[] = { + TestSSEFuncs(&vpx_sse_c, &vpx_sse_avx2), +#if CONFIG_VP9_HIGHBITDEPTH + TestSSEFuncs(&vpx_highbd_sse_c, &vpx_highbd_sse_avx2) +#endif +}; +INSTANTIATE_TEST_SUITE_P(AVX2, SSETest, + Combine(ValuesIn(sse_avx2), Range(4, 129, 4))); +#endif // HAVE_AVX2 } // namespace diff --git a/libs/libvpx/test/superframe_test.cc b/libs/libvpx/test/superframe_test.cc index a5c92e9147..9319fab2ae 100644 --- a/libs/libvpx/test/superframe_test.cc +++ b/libs/libvpx/test/superframe_test.cc @@ -10,7 +10,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" @@ -20,7 +20,7 @@ namespace { const int kTestMode = 0; -typedef std::tuple SuperframeTestParam; +using SuperframeTestParam = std::tuple; class SuperframeTest : public ::libvpx_test::EncoderTest, @@ -28,9 +28,9 @@ class SuperframeTest protected: SuperframeTest() : EncoderTest(GET_PARAM(0)), modified_buf_(nullptr), last_sf_pts_(0) {} - virtual ~SuperframeTest() {} + ~SuperframeTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); const SuperframeTestParam input = GET_PARAM(1); const libvpx_test::TestMode mode = std::get(input); @@ -39,17 +39,17 @@ class SuperframeTest sf_count_max_ = INT_MAX; } - virtual void TearDown() { delete[] modified_buf_; } + void TearDown() override { delete[] modified_buf_; } - virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, - libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(libvpx_test::VideoSource *video, + libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1); } } - virtual const vpx_codec_cx_pkt_t *MutateEncoderOutputHook( - const vpx_codec_cx_pkt_t *pkt) { + const vpx_codec_cx_pkt_t *MutateEncoderOutputHook( + const vpx_codec_cx_pkt_t *pkt) override { if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) return pkt; const uint8_t *buffer = reinterpret_cast(pkt->data.frame.buf); diff --git a/libs/libvpx/test/svc_datarate_test.cc b/libs/libvpx/test/svc_datarate_test.cc index 291cb01280..ba081e1785 100644 --- a/libs/libvpx/test/svc_datarate_test.cc +++ b/libs/libvpx/test/svc_datarate_test.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ #include "./vpx_config.h" -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" @@ -22,7 +22,7 @@ namespace svc_test { namespace { -typedef enum { +enum INTER_LAYER_PRED { // Inter-layer prediction is on on all frames. INTER_LAYER_PRED_ON, // Inter-layer prediction is off on all frames. @@ -33,7 +33,7 @@ typedef enum { // that any layer S (> 0) can only predict from previous spatial // layer S-1, from the same superframe. INTER_LAYER_PRED_ON_CONSTRAINED -} INTER_LAYER_PRED; +}; class DatarateOnePassCbrSvc : public OnePassCbrSvc { public: @@ -43,7 +43,7 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { } protected: - virtual ~DatarateOnePassCbrSvc() {} + ~DatarateOnePassCbrSvc() override = default; virtual void ResetModel() { last_pts_ = 0; @@ -81,12 +81,15 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { num_resize_down_ = 0; num_resize_up_ = 0; for (int i = 0; i < VPX_MAX_LAYERS; i++) { - prev_frame_width[i] = 320; - prev_frame_height[i] = 240; + prev_frame_width_[i] = 320; + prev_frame_height_[i] = 240; } ksvc_flex_noupd_tlenh_ = false; + external_resize_dynamic_drop_layer_ = false; + external_resize_pattern_ = 0; + superframe_cnt_ = 0; } - virtual void BeginPassHook(unsigned int /*pass*/) {} + void BeginPassHook(unsigned int /*pass*/) override {} // Example pattern for spatial layers and 2 temporal layers used in the // bypass/flexible mode. The pattern corresponds to the pattern @@ -179,8 +182,8 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { } } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { PreEncodeFrameHookSetup(video, encoder); if (video->frame() == 0) { @@ -207,6 +210,8 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { if (use_post_encode_drop_) { encoder->Control(VP9E_SET_POSTENCODE_DROP, use_post_encode_drop_); } + // We want to force external resize on the very first frame. + if (external_resize_dynamic_drop_layer_) video->Next(); } if (denoiser_off_on_) { @@ -256,13 +261,13 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { temporal_layer_id_ = layer_id.temporal_layer_id; for (int i = 0; i < number_spatial_layers_; i++) { layer_id.temporal_layer_id_per_spatial[i] = temporal_layer_id_; - ref_frame_config.duration[i] = 1; + ref_frame_config_.duration[i] = 1; } encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id); set_frame_flags_bypass_mode(layer_id.temporal_layer_id, - number_spatial_layers_, 0, &ref_frame_config, + number_spatial_layers_, 0, &ref_frame_config_, 1); - encoder->Control(VP9E_SET_SVC_REF_FRAME_CONFIG, &ref_frame_config); + encoder->Control(VP9E_SET_SVC_REF_FRAME_CONFIG, &ref_frame_config_); } if (update_pattern_ && video->frame() >= 100) { @@ -277,13 +282,13 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { temporal_layer_id_ = layer_id.temporal_layer_id; for (int i = 0; i < number_spatial_layers_; i++) { layer_id.temporal_layer_id_per_spatial[i] = temporal_layer_id_; - ref_frame_config.duration[i] = 1; + ref_frame_config_.duration[i] = 1; } encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id); set_frame_flags_bypass_mode(layer_id.temporal_layer_id, - number_spatial_layers_, 0, &ref_frame_config, + number_spatial_layers_, 0, &ref_frame_config_, 0); - encoder->Control(VP9E_SET_SVC_REF_FRAME_CONFIG, &ref_frame_config); + encoder->Control(VP9E_SET_SVC_REF_FRAME_CONFIG, &ref_frame_config_); } if (change_bitrate_ && video->frame() == 200) { @@ -316,7 +321,98 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { encoder->Config(&cfg_); } - if (dynamic_drop_layer_ && !single_layer_resize_) { + if (external_resize_dynamic_drop_layer_) { + frame_flags_ = 0; + for (int i = 0; i < 9; ++i) { + svc_params_.min_quantizers[i] = 20; + svc_params_.max_quantizers[i] = 56; + } + if (video->frame() == 1 || video->frame() == 150) { + // Set the new top width/height for external resize. + top_sl_width_ = video->img()->d_w; + top_sl_height_ = video->img()->d_h; + for (int i = 0; i < 9; ++i) { + bitrate_layer_[i] = cfg_.layer_target_bitrate[i]; + } + if (external_resize_pattern_ == 1) { + // Input size is 1/4. 2 top spatial layers are dropped. + // This will trigger skip encoding/dropping of two top spatial layers. + cfg_.rc_target_bitrate -= + cfg_.layer_target_bitrate[5] + cfg_.layer_target_bitrate[8]; + for (int i = 3; i < 9; ++i) { + cfg_.layer_target_bitrate[i] = 0; + } + for (int sl = 0; sl < 3; sl++) { + svc_params_.scaling_factor_num[sl] = 1; + svc_params_.scaling_factor_den[sl] = 1; + } + } else if (external_resize_pattern_ == 2) { + // Input size is 1/2. Top spatial layer is dropped. + // This will trigger skip encoding/dropping of top spatial layer. + cfg_.rc_target_bitrate -= cfg_.layer_target_bitrate[8]; + for (int i = 6; i < 9; ++i) { + cfg_.layer_target_bitrate[i] = 0; + } + svc_params_.scaling_factor_num[0] = 1; + svc_params_.scaling_factor_den[0] = 2; + svc_params_.scaling_factor_num[1] = 1; + svc_params_.scaling_factor_den[1] = 1; + svc_params_.scaling_factor_num[2] = 1; + svc_params_.scaling_factor_den[2] = 1; + } + encoder->Config(&cfg_); + encoder->Control(VP9E_SET_SVC_PARAMETERS, &svc_params_); + } else if (video->frame() == 50 || video->frame() == 200) { + top_sl_width_ = video->img()->d_w; + top_sl_height_ = video->img()->d_h; + if (external_resize_pattern_ == 1) { + // Input size is 1/2. Change layer bitrates to set top layer to 0. + // This will trigger skip encoding/dropping of top spatial layer. + cfg_.rc_target_bitrate += bitrate_layer_[5]; + for (int i = 3; i < 6; ++i) { + cfg_.layer_target_bitrate[i] = bitrate_layer_[i]; + } + svc_params_.scaling_factor_num[0] = 1; + svc_params_.scaling_factor_den[0] = 2; + svc_params_.scaling_factor_num[1] = 1; + svc_params_.scaling_factor_den[1] = 1; + svc_params_.scaling_factor_num[2] = 1; + svc_params_.scaling_factor_den[2] = 1; + } else if (external_resize_pattern_ == 2) { + // Input size is 1/4. Change layer bitrates to set two top layers to + // 0. This will trigger skip encoding/dropping of two top spatial + // layers. + cfg_.rc_target_bitrate -= bitrate_layer_[5]; + for (int i = 3; i < 6; ++i) { + cfg_.layer_target_bitrate[i] = 0; + } + for (int sl = 0; sl < 3; sl++) { + svc_params_.scaling_factor_num[sl] = 1; + svc_params_.scaling_factor_den[sl] = 1; + } + } + encoder->Config(&cfg_); + encoder->Control(VP9E_SET_SVC_PARAMETERS, &svc_params_); + } else if (video->frame() == 100 || video->frame() == 250) { + top_sl_width_ = video->img()->d_w; + top_sl_height_ = video->img()->d_h; + // Input is original size. Change layer bitrates to nonzero for all + // layers. + cfg_.rc_target_bitrate = + bitrate_layer_[2] + bitrate_layer_[5] + bitrate_layer_[8]; + for (int i = 0; i < 9; ++i) { + cfg_.layer_target_bitrate[i] = bitrate_layer_[i]; + } + svc_params_.scaling_factor_num[0] = 1; + svc_params_.scaling_factor_den[0] = 4; + svc_params_.scaling_factor_num[1] = 1; + svc_params_.scaling_factor_den[1] = 2; + svc_params_.scaling_factor_num[2] = 1; + svc_params_.scaling_factor_den[2] = 1; + encoder->Config(&cfg_); + encoder->Control(VP9E_SET_SVC_PARAMETERS, &svc_params_); + } + } else if (dynamic_drop_layer_ && !single_layer_resize_) { if (video->frame() == 0) { // Change layer bitrates to set top layers to 0. This will trigger skip // encoding/dropping of top two spatial layers. @@ -432,6 +528,7 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { const vpx_rational_t tb = video->timebase(); timebase_ = static_cast(tb.num) / tb.den; duration_ = 0; + superframe_cnt_++; } vpx_codec_err_t parse_superframe_index(const uint8_t *data, size_t data_sz, @@ -468,7 +565,7 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { return VPX_CODEC_OK; } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { uint32_t sizes[8] = { 0 }; uint32_t sizes_parsed[8] = { 0 }; int count = 0; @@ -476,6 +573,12 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { last_pts_ = pkt->data.frame.pts; const bool key_frame = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) ? true : false; + if (external_resize_dynamic_drop_layer_) { + // No key frames expected in stream, except for first. + if (cfg_.kf_max_dist > 1000) { + ASSERT_FALSE(key_frame && superframe_cnt_ > 1); + } + } if (key_frame) { // For test that inserts layer sync frames: requesting a layer_sync on // the base layer must force key frame. So if any key frame occurs after @@ -547,28 +650,31 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { } } - if (!single_layer_resize_) { - ASSERT_EQ(pkt->data.frame.width[sl], - top_sl_width_ * svc_params_.scaling_factor_num[sl] / - svc_params_.scaling_factor_den[sl]); - - ASSERT_EQ(pkt->data.frame.height[sl], - top_sl_height_ * svc_params_.scaling_factor_num[sl] / - svc_params_.scaling_factor_den[sl]); + if (!single_layer_resize_ && sl < number_spatial_layers_ - 1) { + unsigned int scaled_width = top_sl_width_ * + svc_params_.scaling_factor_num[sl] / + svc_params_.scaling_factor_den[sl]; + if (scaled_width % 2 != 0) scaled_width += 1; + ASSERT_EQ(pkt->data.frame.width[sl], scaled_width); + unsigned int scaled_height = top_sl_height_ * + svc_params_.scaling_factor_num[sl] / + svc_params_.scaling_factor_den[sl]; + if (scaled_height % 2 != 0) scaled_height += 1; + ASSERT_EQ(pkt->data.frame.height[sl], scaled_height); } else if (superframe_count_ > 0) { - if (pkt->data.frame.width[sl] < prev_frame_width[sl] && - pkt->data.frame.height[sl] < prev_frame_height[sl]) + if (pkt->data.frame.width[sl] < prev_frame_width_[sl] && + pkt->data.frame.height[sl] < prev_frame_height_[sl]) num_resize_down_ += 1; - if (pkt->data.frame.width[sl] > prev_frame_width[sl] && - pkt->data.frame.height[sl] > prev_frame_height[sl]) + if (pkt->data.frame.width[sl] > prev_frame_width_[sl] && + pkt->data.frame.height[sl] > prev_frame_height_[sl]) num_resize_up_ += 1; } - prev_frame_width[sl] = pkt->data.frame.width[sl]; - prev_frame_height[sl] = pkt->data.frame.height[sl]; + prev_frame_width_[sl] = pkt->data.frame.width[sl]; + prev_frame_height_[sl] = pkt->data.frame.height[sl]; } } - virtual void EndPassHook(void) { + void EndPassHook() override { if (change_bitrate_) last_pts_ = last_pts_ - last_pts_ref_; duration_ = (last_pts_ + 1) * timebase_; for (int sl = 0; sl < number_spatial_layers_; ++sl) { @@ -580,7 +686,7 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { } } - virtual void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2) { + void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2) override { // TODO(marpan): Look into why an assert is triggered in compute_psnr // for mismatch frames for the special test case: ksvc_flex_noupd_tlenh. // Has to do with dropped frames in bypass/flexible svc mode. @@ -608,7 +714,7 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { bool single_layer_resize_; unsigned int top_sl_width_; unsigned int top_sl_height_; - vpx_svc_ref_frame_config_t ref_frame_config; + vpx_svc_ref_frame_config_t ref_frame_config_; int update_pattern_; bool change_bitrate_; vpx_codec_pts_t last_pts_ref_; @@ -631,12 +737,16 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { bool denoiser_enable_layers_; int num_resize_up_; int num_resize_down_; - unsigned int prev_frame_width[VPX_MAX_LAYERS]; - unsigned int prev_frame_height[VPX_MAX_LAYERS]; + unsigned int prev_frame_width_[VPX_MAX_LAYERS]; + unsigned int prev_frame_height_[VPX_MAX_LAYERS]; bool ksvc_flex_noupd_tlenh_; + bool external_resize_dynamic_drop_layer_; + int bitrate_layer_[9]; + int external_resize_pattern_; + int superframe_cnt_; private: - virtual void SetConfig(const int num_temporal_layer) { + void SetConfig(const int num_temporal_layer) override { cfg_.rc_end_usage = VPX_CBR; cfg_.g_lag_in_frames = 0; cfg_.g_error_resilient = 1; @@ -659,6 +769,80 @@ class DatarateOnePassCbrSvc : public OnePassCbrSvc { unsigned int mismatch_nframes_; }; +void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w, + unsigned int initial_h, unsigned int *w, + unsigned int *h, int resize_pattern) { + *w = initial_w; + *h = initial_h; + if (resize_pattern == 1) { + if (frame < 50) { + *w = initial_w / 4; + *h = initial_h / 4; + } else if (frame < 100) { + *w = initial_w / 2; + *h = initial_h / 2; + } else if (frame < 150) { + *w = initial_w; + *h = initial_h; + } else if (frame < 200) { + *w = initial_w / 4; + *h = initial_h / 4; + } else if (frame < 250) { + *w = initial_w / 2; + *h = initial_h / 2; + } + } else if (resize_pattern == 2) { + if (frame < 50) { + *w = initial_w / 2; + *h = initial_h / 2; + } else if (frame < 100) { + *w = initial_w / 4; + *h = initial_h / 4; + } else if (frame < 150) { + *w = initial_w; + *h = initial_h; + } else if (frame < 200) { + *w = initial_w / 2; + *h = initial_h / 2; + } else if (frame < 250) { + *w = initial_w / 4; + *h = initial_h / 4; + } + } +} + +class ResizingVideoSource : public ::libvpx_test::DummyVideoSource { + public: + ResizingVideoSource(int width, int height) { + top_width_ = width; + top_height_ = height; + SetSize(top_width_, top_height_); + limit_ = 300; + } + int external_resize_pattern_ = 1; + int force_zero_source_ = 0; + int top_width_; + int top_height_; + ~ResizingVideoSource() override = default; + + protected: + void Next() override { + ++frame_; + unsigned int width = 0; + unsigned int height = 0; + libvpx_test::ACMRandom rnd(libvpx_test::ACMRandom::DeterministicSeed()); + ScaleForFrameNumber(frame_, top_width_, top_height_, &width, &height, + external_resize_pattern_); + SetSize(width, height); + FillFrame(); + unsigned char *image = img_->planes[0]; + for (size_t i = 0; i < raw_sz_; ++i) { + image[i] = rnd.Rand8(); + if (force_zero_source_ && frame_ % 20 == 0) image[i] = 0; + } + } +}; + // Params: speed setting. class DatarateOnePassCbrSvcSingleBR : public DatarateOnePassCbrSvc, @@ -667,10 +851,10 @@ class DatarateOnePassCbrSvcSingleBR DatarateOnePassCbrSvcSingleBR() : DatarateOnePassCbrSvc(GET_PARAM(0)) { memset(&svc_params_, 0, sizeof(svc_params_)); } - virtual ~DatarateOnePassCbrSvcSingleBR() {} + ~DatarateOnePassCbrSvcSingleBR() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); speed_setting_ = GET_PARAM(1); @@ -678,6 +862,152 @@ class DatarateOnePassCbrSvcSingleBR } }; +// Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and 3 +// temporal layers, for 4:4:4 Profile 1. +TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TL444Profile1) { + SetSvcConfig(3, 3); + ::libvpx_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 140); + cfg_.g_profile = 1; + cfg_.g_bit_depth = VPX_BITS_8; + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_min_quantizer = 0; + cfg_.rc_max_quantizer = 63; + cfg_.g_threads = 1; + cfg_.rc_dropframe_thresh = 0; + cfg_.kf_max_dist = 9999; + + top_sl_width_ = 352; + top_sl_height_ = 288; + cfg_.rc_target_bitrate = 500; + ResetModel(); + AssignLayerBitrates(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.78, + 1.15); +#if CONFIG_VP9_DECODER + // The non-reference frames are expected to be mismatched frames as the + // encoder will avoid loopfilter on these frames. + EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames()); +#endif +} + +// Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and 3 +// temporal layers, for 4:2:2 Profile 1. +TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2SL3TL422Profile1) { + SetSvcConfig(2, 3); + ::libvpx_test::Y4mVideoSource video("park_joy_90p_8_422.y4m", 0, 20); + cfg_.g_profile = 1; + cfg_.g_bit_depth = VPX_BITS_8; + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_min_quantizer = 0; + cfg_.rc_max_quantizer = 63; + cfg_.g_threads = 1; + cfg_.rc_dropframe_thresh = 0; + cfg_.kf_max_dist = 9999; + + top_sl_width_ = 160; + top_sl_height_ = 90; + cfg_.rc_target_bitrate = 500; + ResetModel(); + AssignLayerBitrates(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + // Use large under/over shoot thresholds as this is a very short clip, + // so not good for testing rate-targeting. + CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.5, + 1.7); +#if CONFIG_VP9_DECODER + // The non-reference frames are expected to be mismatched frames as the + // encoder will avoid loopfilter on these frames. + EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames()); +#endif +} + +#if CONFIG_VP9_HIGHBITDEPTH +// Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and 3 +// temporal layers, for Profle 2 10bit. +TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TL10bitProfile2) { + SetSvcConfig(3, 3); + ::libvpx_test::Y4mVideoSource video("park_joy_90p_10_420_20f.y4m", 0, 20); + cfg_.g_profile = 2; + cfg_.g_bit_depth = VPX_BITS_10; + cfg_.g_input_bit_depth = VPX_BITS_10; + if (cfg_.g_bit_depth > 8) init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH; + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_min_quantizer = 0; + cfg_.rc_max_quantizer = 63; + cfg_.g_threads = 1; + cfg_.rc_dropframe_thresh = 0; + cfg_.kf_max_dist = 9999; + + top_sl_width_ = 160; + top_sl_height_ = 90; + cfg_.rc_target_bitrate = 500; + ResetModel(); + AssignLayerBitrates(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + // TODO(marpan/jianj): Comment out the rate-target checking for now + // as superframe parsing to get frame size needs to be fixed for + // high bitdepth. + /* + // Use large under/over shoot thresholds as this is a very short clip, + // so not good for testing rate-targeting. + CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.5, + 1.7); + */ +#if CONFIG_VP9_DECODER + // The non-reference frames are expected to be mismatched frames as the + // encoder will avoid loopfilter on these frames. + EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames()); +#endif +} + +// Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and 3 +// temporal layers, for Profle 2 12bit. +TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc3SL3TL12bitProfile2) { + SetSvcConfig(3, 3); + ::libvpx_test::Y4mVideoSource video("park_joy_90p_12_420_20f.y4m", 0, 20); + cfg_.g_profile = 2; + cfg_.g_bit_depth = VPX_BITS_12; + cfg_.g_input_bit_depth = VPX_BITS_12; + if (cfg_.g_bit_depth > 8) init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH; + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_min_quantizer = 0; + cfg_.rc_max_quantizer = 63; + cfg_.g_threads = 1; + cfg_.rc_dropframe_thresh = 0; + cfg_.kf_max_dist = 9999; + + top_sl_width_ = 160; + top_sl_height_ = 90; + cfg_.rc_target_bitrate = 500; + ResetModel(); + AssignLayerBitrates(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + // TODO(marpan/jianj): Comment out the rate-target checking for now + // as superframe parsing to get frame size needs to be fixed for + // high bitdepth. + /* + // Use large under/over shoot thresholds as this is a very short clip, + // so not good for testing rate-targeting. + CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.5, + 1.7); + */ +#if CONFIG_VP9_DECODER + // The non-reference frames are expected to be mismatched frames as the + // encoder will avoid loopfilter on these frames. + EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames()); +#endif +} +#endif + // Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and 1 // temporal layer, with screen content mode on and same speed setting for all // layers. @@ -921,7 +1251,7 @@ TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2SL_SingleLayerResize) { #endif } -// For pass CBR SVC with 1 spatial and 2 temporal layers with dynamic resize +// For 1 pass CBR SVC with 1 spatial and 2 temporal layers with dynamic resize // and denoiser enabled. The resizer will resize the single layer down and back // up again, as the bitrate goes back up. TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc1SL2TL_DenoiseResize) { @@ -938,6 +1268,8 @@ TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc1SL2TL_DenoiseResize) { cfg_.rc_resize_allowed = 1; ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", 1280, 720, 12, 1, 0, 300); + cfg_.g_w = 1280; + cfg_.g_h = 720; top_sl_width_ = 1280; top_sl_height_ = 720; cfg_.rc_target_bitrate = 800; @@ -1003,6 +1335,172 @@ TEST_P(DatarateOnePassCbrSvcSingleBR, OnePassCbrSvc2SL1TL5x5MultipleRuns) { #endif } +// For 1 pass CBR SVC with 3 spatial and 3 temporal layers with external resize +// and denoiser enabled. The external resizer will resize down and back up, +// setting 0/nonzero bitrate on spatial enhancement layers to disable/enable +// layers. Resizing starts on first frame and the pattern is: +// 1/4 -> 1/2 -> 1 -> 1/4 -> 1/2. +TEST_P(DatarateOnePassCbrSvcSingleBR, + OnePassCbrSvc3SL3TL_DenoiseExternalResizePattern1) { + SetSvcConfig(3, 3); + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_min_quantizer = 40; + cfg_.rc_max_quantizer = 63; + cfg_.g_threads = 1; + cfg_.temporal_layering_mode = 3; + cfg_.ts_rate_decimator[0] = 4; + cfg_.ts_rate_decimator[1] = 2; + cfg_.ts_rate_decimator[2] = 1; + cfg_.rc_dropframe_thresh = 1; + cfg_.kf_max_dist = 10000; + cfg_.kf_min_dist = 10000; + cfg_.rc_resize_allowed = 0; + cfg_.g_w = 1280; + cfg_.g_h = 720; + top_sl_width_ = 1280; + top_sl_height_ = 720; + ResizingVideoSource video(1280, 720); + video.external_resize_pattern_ = 1; + video.force_zero_source_ = 0; + cfg_.rc_target_bitrate = 1000; + ResetModel(); + dynamic_drop_layer_ = false; + single_layer_resize_ = false; + denoiser_on_ = 1; + base_speed_setting_ = speed_setting_; + external_resize_dynamic_drop_layer_ = true; + external_resize_pattern_ = video.external_resize_pattern_; + AssignLayerBitrates(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); +} + +// For 1 pass CBR SVC with 3 spatial and 3 temporal layers with external resize +// and denoiser enabled. The external resizer will resize down and back up, +// setting 0/nonzero bitrate on spatial enhancement layers to disable/enable +// layers. Resizing starts on first frame and the pattern is: +// 1/2 -> 1/4 -> 1 -> 1/2 -> 1/4. +TEST_P(DatarateOnePassCbrSvcSingleBR, + OnePassCbrSvc3SL3TL_DenoiseExternalResizePattern2) { + SetSvcConfig(3, 3); + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_min_quantizer = 40; + cfg_.rc_max_quantizer = 63; + cfg_.g_threads = 1; + cfg_.temporal_layering_mode = 3; + cfg_.ts_rate_decimator[0] = 4; + cfg_.ts_rate_decimator[1] = 2; + cfg_.ts_rate_decimator[2] = 1; + cfg_.rc_dropframe_thresh = 1; + cfg_.kf_max_dist = 10000; + cfg_.kf_min_dist = 10000; + cfg_.rc_resize_allowed = 0; + cfg_.g_w = 1280; + cfg_.g_h = 720; + top_sl_width_ = 1280; + top_sl_height_ = 720; + ResizingVideoSource video(1280, 720); + video.external_resize_pattern_ = 2; + video.force_zero_source_ = 0; + cfg_.rc_target_bitrate = 1000; + ResetModel(); + dynamic_drop_layer_ = false; + single_layer_resize_ = false; + denoiser_on_ = 1; + base_speed_setting_ = speed_setting_; + external_resize_dynamic_drop_layer_ = true; + external_resize_pattern_ = video.external_resize_pattern_; + AssignLayerBitrates(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); +} + +// For 1 pass CBR SVC with 3 spatial and 3 temporal layers with external resize +// and denoiser enabled. The external resizer will resize down and back up, +// setting 0/nonzero bitrate on spatial enhancement layers to disable/enable +// layers. Resizing starts on first frame and the pattern is: +// 1/2 -> 1/4 -> 1 -> 1/2 -> 1/4. This test uses 4 threads with small keyframe +// spacing, and top resolution is 1280x960. +TEST_P(DatarateOnePassCbrSvcSingleBR, + OnePassCbrSvc3SL3TL_DenoiseExternalResizePattern2Key4Threads) { + SetSvcConfig(3, 3); + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_min_quantizer = 40; + cfg_.rc_max_quantizer = 63; + cfg_.g_threads = 4; + cfg_.temporal_layering_mode = 3; + cfg_.ts_rate_decimator[0] = 4; + cfg_.ts_rate_decimator[1] = 2; + cfg_.ts_rate_decimator[2] = 1; + cfg_.rc_dropframe_thresh = 1; + cfg_.kf_max_dist = 40; + cfg_.kf_min_dist = 40; + cfg_.rc_resize_allowed = 0; + cfg_.g_w = 1280; + cfg_.g_h = 960; + top_sl_width_ = cfg_.g_w; + top_sl_height_ = cfg_.g_h; + ResizingVideoSource video(1280, 960); + video.external_resize_pattern_ = 2; + video.force_zero_source_ = 0; + cfg_.rc_target_bitrate = 1000; + ResetModel(); + dynamic_drop_layer_ = false; + single_layer_resize_ = false; + denoiser_on_ = 1; + base_speed_setting_ = speed_setting_; + external_resize_dynamic_drop_layer_ = true; + external_resize_pattern_ = video.external_resize_pattern_; + AssignLayerBitrates(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); +} + +// For 1 pass CBR SVC with 3 spatial and 3 temporal layers with external resize +// and denoiser enabled. The external resizer will resize down and back up, +// setting 0/nonzero bitrate on spatial enhancement layers to disable/enable +// layers. Resizing starts on first frame and the pattern is: +// 1/4 -> 1/2 -> 1 -> 1/4 -> 1/2. The source will be set to 0 every x frames, +// otherwise random values, to trigger scene detection in the encoder. +TEST_P(DatarateOnePassCbrSvcSingleBR, + OnePassCbrSvc3SL3TL_DenoiseExternalResizePattern1SceneChange) { + SetSvcConfig(3, 3); + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_min_quantizer = 40; + cfg_.rc_max_quantizer = 63; + cfg_.g_threads = 1; + cfg_.temporal_layering_mode = 3; + cfg_.ts_rate_decimator[0] = 4; + cfg_.ts_rate_decimator[1] = 2; + cfg_.ts_rate_decimator[2] = 1; + cfg_.rc_dropframe_thresh = 1; + cfg_.kf_max_dist = 10000; + cfg_.kf_min_dist = 10000; + cfg_.rc_resize_allowed = 0; + cfg_.g_w = 1280; + cfg_.g_h = 720; + top_sl_width_ = 1280; + top_sl_height_ = 720; + ResizingVideoSource video(1280, 720); + video.external_resize_pattern_ = 1; + video.force_zero_source_ = 1; + cfg_.rc_target_bitrate = 1000; + ResetModel(); + dynamic_drop_layer_ = false; + single_layer_resize_ = false; + denoiser_on_ = 1; + base_speed_setting_ = speed_setting_; + external_resize_dynamic_drop_layer_ = true; + external_resize_pattern_ = video.external_resize_pattern_; + AssignLayerBitrates(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); +} + // Params: speed setting and index for bitrate array. class DatarateOnePassCbrSvcMultiBR : public DatarateOnePassCbrSvc, @@ -1011,10 +1509,10 @@ class DatarateOnePassCbrSvcMultiBR DatarateOnePassCbrSvcMultiBR() : DatarateOnePassCbrSvc(GET_PARAM(0)) { memset(&svc_params_, 0, sizeof(svc_params_)); } - virtual ~DatarateOnePassCbrSvcMultiBR() {} + ~DatarateOnePassCbrSvcMultiBR() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); speed_setting_ = GET_PARAM(1); @@ -1054,6 +1552,37 @@ TEST_P(DatarateOnePassCbrSvcMultiBR, OnePassCbrSvc2SL3TL) { #endif } +// Check basic rate targeting for 1 pass VBR SVC: 2 spatial layers and +// 3 temporal layers. Run VGA clip with 1 thread. +TEST_P(DatarateOnePassCbrSvcMultiBR, OnePassVbrSvc2SL3TL) { + SetSvcConfig(2, 3); + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_min_quantizer = 2; + cfg_.rc_max_quantizer = 56; + cfg_.g_threads = 1; + cfg_.rc_dropframe_thresh = 30; + cfg_.kf_max_dist = 9999; + cfg_.rc_end_usage = VPX_VBR; + ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1, + 0, 400); + top_sl_width_ = 640; + top_sl_height_ = 480; + const int bitrates[3] = { 200, 400, 600 }; + cfg_.rc_target_bitrate = bitrates[GET_PARAM(2)]; + ResetModel(); + AssignLayerBitrates(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.70, + 1.3); +#if CONFIG_VP9_DECODER + // The non-reference frames are expected to be mismatched frames as the + // encoder will avoid loopfilter on these frames. + EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames()); +#endif +} + // Params: speed setting, layer framedrop control and index for bitrate array. class DatarateOnePassCbrSvcFrameDropMultiBR : public DatarateOnePassCbrSvc, @@ -1063,10 +1592,10 @@ class DatarateOnePassCbrSvcFrameDropMultiBR : DatarateOnePassCbrSvc(GET_PARAM(0)) { memset(&svc_params_, 0, sizeof(svc_params_)); } - virtual ~DatarateOnePassCbrSvcFrameDropMultiBR() {} + ~DatarateOnePassCbrSvcFrameDropMultiBR() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); speed_setting_ = GET_PARAM(1); @@ -1136,6 +1665,71 @@ TEST_P(DatarateOnePassCbrSvcFrameDropMultiBR, OnePassCbrSvc3SL3TL4Threads) { #endif } +// Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and +// 3 temporal layers. Run HD clip with 4 threads, for 1284x770, which +// likely is the issue for Bug: 366146260. +TEST_P(DatarateOnePassCbrSvcFrameDropMultiBR, + OnePassCbrSvc3SL3TL4Threads1284x770) { + SetSvcConfig(3, 3); + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_min_quantizer = 0; + cfg_.rc_max_quantizer = 63; + cfg_.g_threads = 4; + cfg_.rc_dropframe_thresh = 30; + cfg_.kf_max_dist = 9999; + ::libvpx_test::Y4mVideoSource video("niklas_1284_770_30.y4m", 0, 60); + top_sl_width_ = 1284; + top_sl_height_ = 770; + layer_framedrop_ = 0; + const int bitrates[3] = { 200, 400, 600 }; + cfg_.rc_target_bitrate = bitrates[GET_PARAM(3)]; + ResetModel(); + layer_framedrop_ = GET_PARAM(2); + AssignLayerBitrates(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.58, + 1.2); +#if CONFIG_VP9_DECODER + // The non-reference frames are expected to be mismatched frames as the + // encoder will avoid loopfilter on these frames. + EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames()); +#endif +} + +// Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and +// 3 temporal layers. Run HD clip with 4 threads, for 1857x167. +TEST_P(DatarateOnePassCbrSvcFrameDropMultiBR, + OnePassCbrSvc3SL3TL4Threads1857x167) { + SetSvcConfig(3, 3); + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_min_quantizer = 0; + cfg_.rc_max_quantizer = 63; + cfg_.g_threads = 1; + cfg_.rc_dropframe_thresh = 30; + cfg_.kf_max_dist = 9999; + ::libvpx_test::Y4mVideoSource video("niklas_1857_167_30.y4m", 0, 60); + top_sl_width_ = 1857; + top_sl_height_ = 167; + layer_framedrop_ = 0; + const int bitrates[3] = { 200, 400, 600 }; + cfg_.rc_target_bitrate = bitrates[GET_PARAM(3)]; + ResetModel(); + layer_framedrop_ = GET_PARAM(2); + AssignLayerBitrates(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + CheckLayerRateTargeting(number_spatial_layers_, number_temporal_layers_, 0.58, + 1.2); +#if CONFIG_VP9_DECODER + // The non-reference frames are expected to be mismatched frames as the + // encoder will avoid loopfilter on these frames. + EXPECT_EQ(GetNonRefFrames(), GetMismatchFrames()); +#endif +} + // Check basic rate targeting for 1 pass CBR SVC: 3 spatial layers and // 2 temporal layers, for KSVC in flexible mode with no update of reference // frames for all spatial layers on TL > 0 superframes. @@ -1175,10 +1769,10 @@ class DatarateOnePassCbrSvcInterLayerPredSingleBR : DatarateOnePassCbrSvc(GET_PARAM(0)) { memset(&svc_params_, 0, sizeof(svc_params_)); } - virtual ~DatarateOnePassCbrSvcInterLayerPredSingleBR() {} + ~DatarateOnePassCbrSvcInterLayerPredSingleBR() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); speed_setting_ = GET_PARAM(1); @@ -1261,10 +1855,10 @@ class DatarateOnePassCbrSvcDenoiser DatarateOnePassCbrSvcDenoiser() : DatarateOnePassCbrSvc(GET_PARAM(0)) { memset(&svc_params_, 0, sizeof(svc_params_)); } - virtual ~DatarateOnePassCbrSvcDenoiser() {} + ~DatarateOnePassCbrSvcDenoiser() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); speed_setting_ = GET_PARAM(1); @@ -1319,10 +1913,10 @@ class DatarateOnePassCbrSvcSmallKF DatarateOnePassCbrSvcSmallKF() : DatarateOnePassCbrSvc(GET_PARAM(0)) { memset(&svc_params_, 0, sizeof(svc_params_)); } - virtual ~DatarateOnePassCbrSvcSmallKF() {} + ~DatarateOnePassCbrSvcSmallKF() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); speed_setting_ = GET_PARAM(1); @@ -1522,10 +2116,10 @@ class DatarateOnePassCbrSvcPostencodeDrop DatarateOnePassCbrSvcPostencodeDrop() : DatarateOnePassCbrSvc(GET_PARAM(0)) { memset(&svc_params_, 0, sizeof(svc_params_)); } - virtual ~DatarateOnePassCbrSvcPostencodeDrop() {} + ~DatarateOnePassCbrSvcPostencodeDrop() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); speed_setting_ = GET_PARAM(1); diff --git a/libs/libvpx/test/svc_end_to_end_test.cc b/libs/libvpx/test/svc_end_to_end_test.cc index 7300ce6679..3bd6b1307c 100644 --- a/libs/libvpx/test/svc_end_to_end_test.cc +++ b/libs/libvpx/test/svc_end_to_end_test.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ #include "./vpx_config.h" -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" @@ -22,7 +22,7 @@ namespace svc_test { namespace { -typedef enum { +enum INTER_LAYER_PRED { // Inter-layer prediction is on on all frames. INTER_LAYER_PRED_ON, // Inter-layer prediction is off on all frames. @@ -33,7 +33,7 @@ typedef enum { // that any layer S (> 0) can only predict from previous spatial // layer S-1, from the same superframe. INTER_LAYER_PRED_ON_CONSTRAINED -} INTER_LAYER_PRED; +}; class ScalePartitionOnePassCbrSvc : public OnePassCbrSvc, @@ -45,19 +45,19 @@ class ScalePartitionOnePassCbrSvc } protected: - virtual ~ScalePartitionOnePassCbrSvc() {} + ~ScalePartitionOnePassCbrSvc() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); speed_setting_ = 7; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { PreEncodeFrameHookSetup(video, encoder); } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { // Keep track of number of non-reference frames, needed for mismatch check. // Non-reference frames are top spatial and temporal layer frames, // for TL > 0. @@ -67,12 +67,12 @@ class ScalePartitionOnePassCbrSvc num_nonref_frames_++; } - virtual void MismatchHook(const vpx_image_t * /*img1*/, - const vpx_image_t * /*img2*/) { + void MismatchHook(const vpx_image_t * /*img1*/, + const vpx_image_t * /*img2*/) override { ++mismatch_nframes_; } - virtual void SetConfig(const int /*num_temporal_layer*/) {} + void SetConfig(const int /*num_temporal_layer*/) override {} unsigned int GetMismatchFrames() const { return mismatch_nframes_; } unsigned int GetNonRefFrames() const { return num_nonref_frames_; } @@ -129,14 +129,14 @@ class SyncFrameOnePassCbrSvc : public OnePassCbrSvc, } protected: - virtual ~SyncFrameOnePassCbrSvc() {} + ~SyncFrameOnePassCbrSvc() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); speed_setting_ = 7; } - virtual bool DoDecode() const { + bool DoDecode() const override { return current_video_frame_ >= frame_to_start_decode_; } @@ -225,8 +225,8 @@ class SyncFrameOnePassCbrSvc : public OnePassCbrSvc, } } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { current_video_frame_ = video->frame(); PreEncodeFrameHookSetup(video, encoder); if (video->frame() == 0) { @@ -265,8 +265,8 @@ class SyncFrameOnePassCbrSvc : public OnePassCbrSvc, } #if CONFIG_VP9_DECODER - virtual void PreDecodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Decoder *decoder) { + void PreDecodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Decoder *decoder) override { if (video->frame() < frame_to_sync_) { if (decode_to_layer_before_sync_ >= 0) decoder->Control(VP9_DECODE_SVC_SPATIAL_LAYER, @@ -284,7 +284,7 @@ class SyncFrameOnePassCbrSvc : public OnePassCbrSvc, } #endif - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { // Keep track of number of non-reference frames, needed for mismatch check. // Non-reference frames are top spatial and temporal layer frames, // for TL > 0. @@ -307,8 +307,8 @@ class SyncFrameOnePassCbrSvc : public OnePassCbrSvc, } } - virtual void MismatchHook(const vpx_image_t * /*img1*/, - const vpx_image_t * /*img2*/) { + void MismatchHook(const vpx_image_t * /*img1*/, + const vpx_image_t * /*img2*/) override { if (current_video_frame_ >= frame_to_sync_) ++mismatch_nframes_; } @@ -331,7 +331,7 @@ class SyncFrameOnePassCbrSvc : public OnePassCbrSvc, vpx_svc_ref_frame_config_t ref_frame_config_; private: - virtual void SetConfig(const int num_temporal_layer) { + void SetConfig(const int num_temporal_layer) override { cfg_.rc_buf_initial_sz = 500; cfg_.rc_buf_optimal_sz = 500; cfg_.rc_buf_sz = 1000; @@ -657,15 +657,15 @@ class LoopfilterOnePassCbrSvc : public OnePassCbrSvc, } protected: - virtual ~LoopfilterOnePassCbrSvc() {} + ~LoopfilterOnePassCbrSvc() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); speed_setting_ = 7; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { PreEncodeFrameHookSetup(video, encoder); if (number_temporal_layers_ > 1 || number_spatial_layers_ > 1) { // Consider 3 cases: @@ -694,7 +694,7 @@ class LoopfilterOnePassCbrSvc : public OnePassCbrSvc, } } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { // Keep track of number of non-reference frames, needed for mismatch check. // Non-reference frames are top spatial and temporal layer frames, // for TL > 0. @@ -704,12 +704,12 @@ class LoopfilterOnePassCbrSvc : public OnePassCbrSvc, num_nonref_frames_++; } - virtual void MismatchHook(const vpx_image_t * /*img1*/, - const vpx_image_t * /*img2*/) { + void MismatchHook(const vpx_image_t * /*img1*/, + const vpx_image_t * /*img2*/) override { ++mismatch_nframes_; } - virtual void SetConfig(const int /*num_temporal_layer*/) {} + void SetConfig(const int /*num_temporal_layer*/) override {} int GetMismatchFrames() const { return mismatch_nframes_; } int GetNonRefFrames() const { return num_nonref_frames_; } diff --git a/libs/libvpx/test/svc_test.h b/libs/libvpx/test/svc_test.h index f1d727fd9d..de39412f6d 100644 --- a/libs/libvpx/test/svc_test.h +++ b/libs/libvpx/test/svc_test.h @@ -12,7 +12,7 @@ #define VPX_TEST_SVC_TEST_H_ #include "./vpx_config.h" -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" @@ -36,7 +36,7 @@ class OnePassCbrSvc : public ::libvpx_test::EncoderTest { } protected: - virtual ~OnePassCbrSvc() {} + ~OnePassCbrSvc() override {} virtual void SetConfig(const int num_temporal_layer) = 0; @@ -46,11 +46,11 @@ class OnePassCbrSvc : public ::libvpx_test::EncoderTest { virtual void PreEncodeFrameHookSetup(::libvpx_test::VideoSource *video, ::libvpx_test::Encoder *encoder); - virtual void PostEncodeFrameHook(::libvpx_test::Encoder *encoder); + void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) override; virtual void AssignLayerBitrates(); - virtual void MismatchHook(const vpx_image_t *, const vpx_image_t *) {} + void MismatchHook(const vpx_image_t *, const vpx_image_t *) override {} vpx_svc_extra_cfg_t svc_params_; int64_t bits_in_buffer_model_[VPX_MAX_LAYERS]; diff --git a/libs/libvpx/test/test-data.mk b/libs/libvpx/test/test-data.mk index 62a9d6ef14..29045d02ca 100644 --- a/libs/libvpx/test/test-data.mk +++ b/libs/libvpx/test/test-data.mk @@ -22,13 +22,21 @@ LIBVPX_TEST_DATA-$(CONFIG_ENCODERS) += park_joy_90p_8_422.y4m LIBVPX_TEST_DATA-$(CONFIG_ENCODERS) += park_joy_90p_8_444.y4m LIBVPX_TEST_DATA-$(CONFIG_ENCODERS) += park_joy_90p_8_440.yuv +LIBVPX_TEST_DATA-$(CONFIG_VP8_ENCODER) += repro-oss-fuzz-69906.y4m +LIBVPX_TEST_DATA-$(CONFIG_VP8_ENCODER) += repro-oss-fuzz-471723682.yuv + +LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += 4x2.y4m LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += desktop_credits.y4m LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += niklas_1280_720_30.y4m +LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += niklas_1284_770_30.y4m +LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += niklas_1857_167_30.y4m LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += noisy_clip_640_360.y4m LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += rush_hour_444.y4m LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += screendata.y4m LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += niklas_640_480_30.yuv LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += bus_352x288_420_f20_b8.yuv +LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += crowd_run_360p_10_150f.y4m +LIBVPX_TEST_DATA-$(CONFIG_VP9_ENCODER) += repro-b488585490.yuv # Test vectors LIBVPX_TEST_DATA-$(CONFIG_VP8_DECODER) += vp80-00-comprehensive-001.ivf diff --git a/libs/libvpx/test/test-data.sha1 b/libs/libvpx/test/test-data.sha1 index 55f92a25df..f0d32cd44d 100644 --- a/libs/libvpx/test/test-data.sha1 +++ b/libs/libvpx/test/test-data.sha1 @@ -870,3 +870,10 @@ bac455906360b45338a16dd626ac5f19bc36a307 *desktop_office1.1280_720-020.yuv d3964f9dad9f60363c81b688324d95b4ec7c8038 *invalid-bug-148271109.ivf.res ad18ca16f0a249fb3b7c38de0d9b327fed273f96 *hantro_collage_w352h288_nv12.yuv 8a0b2c350539859463d3546a67876c83ff6ff0ac *desktopqvga.320_240.yuv +ad9942a073e245585c93f764ea299382a65939a7 *crowd_run_360p_10_150f.y4m +f9a73e921552598a5804911e9f84fec2318e056a *repro-oss-fuzz-69906.y4m +320874b648f54e9156339e9d7e322ec4c51cb5f7 *niklas_1284_770_30.y4m +64e876e725f83b93e92a8240457c152dd6f5b77d *niklas_1857_167_30.y4m +27a7f0ebda1842a27c4b973b0e9e393769f74012 *4x2.y4m +aa888af495a704d07a9b547b1cb424a01af9b578 *repro-oss-fuzz-471723682.yuv +8247ee89f9bcd78665793911e8813d8790e03141 *repro-b488585490.yuv diff --git a/libs/libvpx/test/test.mk b/libs/libvpx/test/test.mk index 6df4572904..51c018ba90 100644 --- a/libs/libvpx/test/test.mk +++ b/libs/libvpx/test/test.mk @@ -7,6 +7,8 @@ LIBVPX_TEST_SRCS-yes += codec_factory.h LIBVPX_TEST_SRCS-yes += md5_helper.h LIBVPX_TEST_SRCS-yes += register_state_check.h LIBVPX_TEST_SRCS-yes += test.mk +LIBVPX_TEST_SRCS-yes += init_vpx_test.cc +LIBVPX_TEST_SRCS-yes += init_vpx_test.h LIBVPX_TEST_SRCS-yes += test_libvpx.cc LIBVPX_TEST_SRCS-yes += test_vectors.cc LIBVPX_TEST_SRCS-yes += test_vectors.h @@ -19,13 +21,12 @@ LIBVPX_TEST_SRCS-yes += video_source.h ## Black box tests only use the public API. ## LIBVPX_TEST_SRCS-yes += ../md5_utils.h ../md5_utils.c +LIBVPX_TEST_SRCS-yes += vpx_image_test.cc LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += ivf_video_source.h LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += ../y4minput.h ../y4minput.c +ifneq ($(CONFIG_REALTIME_ONLY),yes) LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += altref_test.cc -LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += aq_segment_test.cc -LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += alt_ref_aq_segment_test.cc -LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += vp8_datarate_test.cc -LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += vp9_datarate_test.cc +endif LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += encode_api_test.cc LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += error_resilience_test.cc LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += i420_video_source.h @@ -34,9 +35,12 @@ LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += resize_test.cc LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += y4m_video_source.h LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += yuv_video_source.h +ifneq ($(CONFIG_REALTIME_ONLY),yes) LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += config_test.cc +endif LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += cq_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += keyframe_test.cc +LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += vp8_datarate_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += byte_alignment_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += decode_svc_test.cc @@ -44,6 +48,10 @@ LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += external_frame_buffer_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += user_priv_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += active_map_refresh_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += active_map_test.cc +ifneq ($(CONFIG_REALTIME_ONLY),yes) +LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += alt_ref_aq_segment_test.cc +endif +LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += aq_segment_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += borders_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += cpu_speed_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += frame_size_tests.cc @@ -58,7 +66,10 @@ LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += svc_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += svc_test.h LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += svc_end_to_end_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += timestamp_test.cc +LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_datarate_test.cc +ifneq ($(CONFIG_REALTIME_ONLY),yes) LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_ext_ratectrl_test.cc +endif LIBVPX_TEST_SRCS-yes += decode_test_driver.cc LIBVPX_TEST_SRCS-yes += decode_test_driver.h @@ -84,6 +95,7 @@ LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += ../webmdec.cc LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += ../webmdec.h LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += webm_video_source.h LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += vp9_skip_loopfilter_test.cc +$(BUILD_PFX)third_party/libwebm/%.cc.o: CXXFLAGS += $(LIBWEBM_CXXFLAGS) endif LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += decode_api_test.cc @@ -106,6 +118,11 @@ ifeq ($(findstring yes,$(CONFIG_VP8_DECODER)$(CONFIG_VP9_DECODER)), yes) LIBVPX_TEST_SRCS-yes += invalid_file_test.cc endif +ifeq ($(findstring yesyes, $(CONFIG_VP8_DECODER)$(CONFIG_POSTPROC) \ + $(CONFIG_VP9_DECODER)$(CONFIG_VP9_POSTPROC)), yesyes) +LIBVPX_TEST_SRCS-yes += postproc_test.cc +endif + ## ## WHITE BOX TESTS ## @@ -126,12 +143,15 @@ LIBVPX_TEST_SRCS-$(CONFIG_POSTPROC) += add_noise_test.cc LIBVPX_TEST_SRCS-$(CONFIG_POSTPROC) += pp_filter_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP8_DECODER) += vp8_decrypt_test.cc ifneq (, $(filter yes, $(HAVE_SSE2) $(HAVE_SSSE3) $(HAVE_SSE4_1) $(HAVE_NEON) \ - $(HAVE_MSA) $(HAVE_MMI))) + $(HAVE_MSA) $(HAVE_MMI) $(HAVE_LSX))) LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += quantize_test.cc endif LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += set_roi.cc LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += variance_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += vp8_fdct4x4_test.cc +ifneq (, $(filter yes, $(CONFIG_VP8_ENCODER) $(CONFIG_VP8_DECODER))) +LIBVPX_TEST_SRCS-$(HAVE_LSX) += vp8_loopfilter_simple_test.cc +endif LIBVPX_TEST_SRCS-yes += idct_test.cc LIBVPX_TEST_SRCS-yes += predict_test.cc @@ -152,8 +172,10 @@ ifeq ($(CONFIG_VP9_ENCODER)$(CONFIG_VP9_DECODER),yesyes) # IDCT test currently depends on FDCT function LIBVPX_TEST_SRCS-yes += idct8x8_test.cc LIBVPX_TEST_SRCS-yes += partial_idct_test.cc +ifneq ($(CONFIG_REALTIME_ONLY),yes) LIBVPX_TEST_SRCS-yes += superframe_test.cc LIBVPX_TEST_SRCS-yes += tile_independence_test.cc +endif LIBVPX_TEST_SRCS-yes += vp9_boolcoder_test.cc LIBVPX_TEST_SRCS-yes += vp9_encoder_parms_get_to_decoder.cc LIBVPX_TEST_SRCS-yes += vp9_roi_test.cc @@ -161,9 +183,15 @@ endif LIBVPX_TEST_SRCS-yes += convolve_test.cc LIBVPX_TEST_SRCS-yes += lpf_test.cc +LIBVPX_TEST_SRCS-yes += vp9_scan_test.cc +LIBVPX_TEST_SRCS-yes += vp9_entropy_test.cc +LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_tokenize_test.cc LIBVPX_TEST_SRCS-yes += vp9_intrapred_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += vp9_decrypt_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += vp9_thread_test.cc +ifeq ($(CONFIG_VP9_DECODER)$(CONFIG_VP9_POSTPROC),yesyes) +LIBVPX_TEST_SRCS-yes += mfqe_test.cc +endif LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += avg_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += comp_avg_pred_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += dct16x16_test.cc @@ -178,7 +206,7 @@ ifneq ($(CONFIG_REALTIME_ONLY),yes) LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += yuv_temporal_filter_test.cc endif LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += variance_test.cc -ifneq (, $(filter yes, $(HAVE_SSE2) $(HAVE_AVX2))) +ifneq (, $(filter yes, $(HAVE_SSE2) $(HAVE_AVX2) $(HAVE_NEON))) LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_block_error_test.cc endif LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_quantize_test.cc @@ -198,10 +226,6 @@ LIBVPX_TEST_SRCS-yes += vp9_denoiser_test.cc endif LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_arf_freq_test.cc -ifeq ($(CONFIG_VP9_ENCODER),yes) -SIMPLE_ENCODE_TEST_SRCS-$(CONFIG_RATE_CTRL) := simple_encode_test.cc -endif - endif # VP9 ## Multi-codec / unconditional whitebox tests. @@ -213,6 +237,8 @@ endif TEST_INTRA_PRED_SPEED_SRCS-yes := test_intra_pred_speed.cc TEST_INTRA_PRED_SPEED_SRCS-yes += ../md5_utils.h ../md5_utils.c +TEST_INTRA_PRED_SPEED_SRCS-yes += init_vpx_test.cc +TEST_INTRA_PRED_SPEED_SRCS-yes += init_vpx_test.h RC_INTERFACE_TEST_SRCS-yes := test_rc_interface.cc RC_INTERFACE_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_ratectrl_rtc_test.cc diff --git a/libs/libvpx/test/test_intra_pred_speed.cc b/libs/libvpx/test/test_intra_pred_speed.cc index 28b3484a03..3b2db879f2 100644 --- a/libs/libvpx/test/test_intra_pred_speed.cc +++ b/libs/libvpx/test/test_intra_pred_speed.cc @@ -12,11 +12,13 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" +#include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" #include "test/acm_random.h" #include "test/clear_system_state.h" +#include "test/init_vpx_test.h" #include "test/md5_helper.h" #include "vpx/vpx_integer.h" #include "vpx_ports/mem.h" @@ -26,8 +28,8 @@ namespace { -typedef void (*VpxPredFunc)(uint8_t *dst, ptrdiff_t y_stride, - const uint8_t *above, const uint8_t *left); +using VpxPredFunc = void (*)(uint8_t *dst, ptrdiff_t y_stride, + const uint8_t *above, const uint8_t *left); const int kBPS = 32; const int kTotalPixels = 32 * kBPS; @@ -61,7 +63,7 @@ struct IntraPredTestMem { DECLARE_ALIGNED(16, Pixel, above_mem[2 * kBPS + 16]); }; -typedef IntraPredTestMem Vp9IntraPredTestMem; +using Vp9IntraPredTestMem = IntraPredTestMem; void CheckMd5Signature(const char name[], const char *const signatures[], const void *data, size_t data_size, int elapsed_time, @@ -200,7 +202,7 @@ INTRA_PRED_TEST(C, TestIntraPred32, vpx_dc_predictor_32x32_c, vpx_d153_predictor_32x32_c, vpx_d207_predictor_32x32_c, vpx_d63_predictor_32x32_c, vpx_tm_predictor_32x32_c) -#if HAVE_SSE2 +#if HAVE_SSE2 && HAVE_X86_ASM INTRA_PRED_TEST(SSE2, TestIntraPred4, vpx_dc_predictor_4x4_sse2, vpx_dc_left_predictor_4x4_sse2, vpx_dc_top_predictor_4x4_sse2, vpx_dc_128_predictor_4x4_sse2, vpx_v_predictor_4x4_sse2, @@ -227,9 +229,9 @@ INTRA_PRED_TEST(SSE2, TestIntraPred32, vpx_dc_predictor_32x32_sse2, vpx_dc_128_predictor_32x32_sse2, vpx_v_predictor_32x32_sse2, vpx_h_predictor_32x32_sse2, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, vpx_tm_predictor_32x32_sse2) -#endif // HAVE_SSE2 +#endif // HAVE_SSE2 && HAVE_X86_ASM -#if HAVE_SSSE3 +#if HAVE_SSSE3 && HAVE_X86_ASM INTRA_PRED_TEST(SSSE3, TestIntraPred4, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, vpx_d153_predictor_4x4_ssse3, nullptr, @@ -248,7 +250,7 @@ INTRA_PRED_TEST(SSSE3, TestIntraPred32, nullptr, nullptr, nullptr, nullptr, nullptr, vpx_d153_predictor_32x32_ssse3, vpx_d207_predictor_32x32_ssse3, vpx_d63_predictor_32x32_ssse3, nullptr) -#endif // HAVE_SSSE3 +#endif // HAVE_SSSE3 && HAVE_X86_ASM #if HAVE_DSPR2 INTRA_PRED_TEST(DSPR2, TestIntraPred4, vpx_dc_predictor_4x4_dspr2, nullptr, @@ -269,28 +271,32 @@ INTRA_PRED_TEST(NEON, TestIntraPred4, vpx_dc_predictor_4x4_neon, vpx_dc_left_predictor_4x4_neon, vpx_dc_top_predictor_4x4_neon, vpx_dc_128_predictor_4x4_neon, vpx_v_predictor_4x4_neon, vpx_h_predictor_4x4_neon, vpx_d45_predictor_4x4_neon, - vpx_d135_predictor_4x4_neon, nullptr, nullptr, nullptr, nullptr, - vpx_tm_predictor_4x4_neon) + vpx_d135_predictor_4x4_neon, vpx_d117_predictor_4x4_neon, + vpx_d153_predictor_4x4_neon, vpx_d207_predictor_4x4_neon, + vpx_d63_predictor_4x4_neon, vpx_tm_predictor_4x4_neon) INTRA_PRED_TEST(NEON, TestIntraPred8, vpx_dc_predictor_8x8_neon, vpx_dc_left_predictor_8x8_neon, vpx_dc_top_predictor_8x8_neon, vpx_dc_128_predictor_8x8_neon, vpx_v_predictor_8x8_neon, vpx_h_predictor_8x8_neon, vpx_d45_predictor_8x8_neon, - vpx_d135_predictor_8x8_neon, nullptr, nullptr, nullptr, nullptr, - vpx_tm_predictor_8x8_neon) + vpx_d135_predictor_8x8_neon, vpx_d117_predictor_8x8_neon, + vpx_d153_predictor_8x8_neon, vpx_d207_predictor_8x8_neon, + vpx_d63_predictor_8x8_neon, vpx_tm_predictor_8x8_neon) INTRA_PRED_TEST(NEON, TestIntraPred16, vpx_dc_predictor_16x16_neon, vpx_dc_left_predictor_16x16_neon, vpx_dc_top_predictor_16x16_neon, vpx_dc_128_predictor_16x16_neon, vpx_v_predictor_16x16_neon, vpx_h_predictor_16x16_neon, vpx_d45_predictor_16x16_neon, - vpx_d135_predictor_16x16_neon, nullptr, nullptr, nullptr, - nullptr, vpx_tm_predictor_16x16_neon) + vpx_d135_predictor_16x16_neon, vpx_d117_predictor_16x16_neon, + vpx_d153_predictor_16x16_neon, vpx_d207_predictor_16x16_neon, + vpx_d63_predictor_16x16_neon, vpx_tm_predictor_16x16_neon) INTRA_PRED_TEST(NEON, TestIntraPred32, vpx_dc_predictor_32x32_neon, vpx_dc_left_predictor_32x32_neon, vpx_dc_top_predictor_32x32_neon, vpx_dc_128_predictor_32x32_neon, vpx_v_predictor_32x32_neon, vpx_h_predictor_32x32_neon, vpx_d45_predictor_32x32_neon, - vpx_d135_predictor_32x32_neon, nullptr, nullptr, nullptr, - nullptr, vpx_tm_predictor_32x32_neon) + vpx_d135_predictor_32x32_neon, vpx_d117_predictor_32x32_neon, + vpx_d153_predictor_32x32_neon, vpx_d207_predictor_32x32_neon, + vpx_d63_predictor_32x32_neon, vpx_tm_predictor_32x32_neon) #endif // HAVE_NEON #if HAVE_MSA @@ -344,16 +350,25 @@ INTRA_PRED_TEST(VSX, TestIntraPred32, vpx_dc_predictor_32x32_vsx, vpx_tm_predictor_32x32_vsx) #endif // HAVE_VSX +#if HAVE_LSX +INTRA_PRED_TEST(LSX, TestIntraPred8, vpx_dc_predictor_8x8_lsx, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr) +INTRA_PRED_TEST(LSX, TestIntraPred16, vpx_dc_predictor_16x16_lsx, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr) +#endif // HAVE_LSX + // ----------------------------------------------------------------------------- #if CONFIG_VP9_HIGHBITDEPTH namespace { -typedef void (*VpxHighbdPredFunc)(uint16_t *dst, ptrdiff_t y_stride, - const uint16_t *above, const uint16_t *left, - int bd); +using VpxHighbdPredFunc = void (*)(uint16_t *dst, ptrdiff_t y_stride, + const uint16_t *above, const uint16_t *left, + int bd); -typedef IntraPredTestMem Vp9HighbdIntraPredTestMem; +using Vp9HighbdIntraPredTestMem = IntraPredTestMem; void TestHighbdIntraPred(const char name[], VpxHighbdPredFunc const *pred_funcs, const char *const signatures[], int block_size) { @@ -487,6 +502,7 @@ HIGHBD_INTRA_PRED_TEST( vpx_highbd_d63_predictor_32x32_c, vpx_highbd_tm_predictor_32x32_c) #if HAVE_SSE2 +#if HAVE_X86_ASM HIGHBD_INTRA_PRED_TEST( SSE2, TestHighbdIntraPred4, vpx_highbd_dc_predictor_4x4_sse2, vpx_highbd_dc_left_predictor_4x4_sse2, vpx_highbd_dc_top_predictor_4x4_sse2, @@ -494,7 +510,7 @@ HIGHBD_INTRA_PRED_TEST( vpx_highbd_h_predictor_4x4_sse2, nullptr, vpx_highbd_d135_predictor_4x4_sse2, vpx_highbd_d117_predictor_4x4_sse2, vpx_highbd_d153_predictor_4x4_sse2, vpx_highbd_d207_predictor_4x4_sse2, - vpx_highbd_d63_predictor_4x4_sse2, vpx_highbd_tm_predictor_4x4_c) + vpx_highbd_d63_predictor_4x4_sse2, vpx_highbd_tm_predictor_4x4_sse2) HIGHBD_INTRA_PRED_TEST( SSE2, TestHighbdIntraPred8, vpx_highbd_dc_predictor_8x8_sse2, @@ -522,6 +538,36 @@ HIGHBD_INTRA_PRED_TEST(SSE2, TestHighbdIntraPred32, vpx_highbd_h_predictor_32x32_sse2, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, vpx_highbd_tm_predictor_32x32_sse2) +#else // !HAVE_X86_ASM +HIGHBD_INTRA_PRED_TEST( + SSE2, TestHighbdIntraPred4, nullptr, vpx_highbd_dc_left_predictor_4x4_sse2, + vpx_highbd_dc_top_predictor_4x4_sse2, vpx_highbd_dc_128_predictor_4x4_sse2, + nullptr, vpx_highbd_h_predictor_4x4_sse2, nullptr, + vpx_highbd_d135_predictor_4x4_sse2, vpx_highbd_d117_predictor_4x4_sse2, + vpx_highbd_d153_predictor_4x4_sse2, vpx_highbd_d207_predictor_4x4_sse2, + vpx_highbd_d63_predictor_4x4_sse2, vpx_highbd_tm_predictor_4x4_c) + +HIGHBD_INTRA_PRED_TEST(SSE2, TestHighbdIntraPred8, nullptr, + vpx_highbd_dc_left_predictor_8x8_sse2, + vpx_highbd_dc_top_predictor_8x8_sse2, + vpx_highbd_dc_128_predictor_8x8_sse2, nullptr, + vpx_highbd_h_predictor_8x8_sse2, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr) + +HIGHBD_INTRA_PRED_TEST(SSE2, TestHighbdIntraPred16, nullptr, + vpx_highbd_dc_left_predictor_16x16_sse2, + vpx_highbd_dc_top_predictor_16x16_sse2, + vpx_highbd_dc_128_predictor_16x16_sse2, nullptr, + vpx_highbd_h_predictor_16x16_sse2, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr) + +HIGHBD_INTRA_PRED_TEST(SSE2, TestHighbdIntraPred32, nullptr, + vpx_highbd_dc_left_predictor_32x32_sse2, + vpx_highbd_dc_top_predictor_32x32_sse2, + vpx_highbd_dc_128_predictor_32x32_sse2, nullptr, + vpx_highbd_h_predictor_32x32_sse2, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr) +#endif // HAVE_X86_ASM #endif // HAVE_SSE2 #if HAVE_SSSE3 @@ -555,43 +601,65 @@ HIGHBD_INTRA_PRED_TEST(SSSE3, TestHighbdIntraPred32, nullptr, nullptr, nullptr, vpx_highbd_d63_predictor_32x32_ssse3, nullptr) #endif // HAVE_SSSE3 +#if HAVE_AVX2 +HIGHBD_INTRA_PRED_TEST(AVX2, TestHighbdIntraPred16, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, vpx_highbd_d207_predictor_16x16_avx2, + vpx_highbd_d63_predictor_16x16_avx2, nullptr) +HIGHBD_INTRA_PRED_TEST(AVX2, TestHighbdIntraPred32, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, vpx_highbd_d207_predictor_32x32_avx2, + vpx_highbd_d63_predictor_32x32_avx2, nullptr) +#endif // HAVE_AVX2 + +#if HAVE_AVX512 +HIGHBD_INTRA_PRED_TEST(AVX512, TestHighbdIntraPred32, nullptr, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, vpx_highbd_d207_predictor_32x32_avx512, + vpx_highbd_d63_predictor_32x32_avx512, nullptr) +#endif // HAVE_AVX512 + #if HAVE_NEON HIGHBD_INTRA_PRED_TEST( NEON, TestHighbdIntraPred4, vpx_highbd_dc_predictor_4x4_neon, vpx_highbd_dc_left_predictor_4x4_neon, vpx_highbd_dc_top_predictor_4x4_neon, vpx_highbd_dc_128_predictor_4x4_neon, vpx_highbd_v_predictor_4x4_neon, vpx_highbd_h_predictor_4x4_neon, vpx_highbd_d45_predictor_4x4_neon, - vpx_highbd_d135_predictor_4x4_neon, nullptr, nullptr, nullptr, nullptr, - vpx_highbd_tm_predictor_4x4_neon) + vpx_highbd_d135_predictor_4x4_neon, vpx_highbd_d117_predictor_4x4_neon, + vpx_highbd_d153_predictor_4x4_neon, vpx_highbd_d207_predictor_4x4_neon, + vpx_highbd_d63_predictor_4x4_neon, vpx_highbd_tm_predictor_4x4_neon) HIGHBD_INTRA_PRED_TEST( NEON, TestHighbdIntraPred8, vpx_highbd_dc_predictor_8x8_neon, vpx_highbd_dc_left_predictor_8x8_neon, vpx_highbd_dc_top_predictor_8x8_neon, vpx_highbd_dc_128_predictor_8x8_neon, vpx_highbd_v_predictor_8x8_neon, vpx_highbd_h_predictor_8x8_neon, vpx_highbd_d45_predictor_8x8_neon, - vpx_highbd_d135_predictor_8x8_neon, nullptr, nullptr, nullptr, nullptr, - vpx_highbd_tm_predictor_8x8_neon) -HIGHBD_INTRA_PRED_TEST(NEON, TestHighbdIntraPred16, - vpx_highbd_dc_predictor_16x16_neon, - vpx_highbd_dc_left_predictor_16x16_neon, - vpx_highbd_dc_top_predictor_16x16_neon, - vpx_highbd_dc_128_predictor_16x16_neon, - vpx_highbd_v_predictor_16x16_neon, - vpx_highbd_h_predictor_16x16_neon, - vpx_highbd_d45_predictor_16x16_neon, - vpx_highbd_d135_predictor_16x16_neon, nullptr, nullptr, - nullptr, nullptr, vpx_highbd_tm_predictor_16x16_neon) -HIGHBD_INTRA_PRED_TEST(NEON, TestHighbdIntraPred32, - vpx_highbd_dc_predictor_32x32_neon, - vpx_highbd_dc_left_predictor_32x32_neon, - vpx_highbd_dc_top_predictor_32x32_neon, - vpx_highbd_dc_128_predictor_32x32_neon, - vpx_highbd_v_predictor_32x32_neon, - vpx_highbd_h_predictor_32x32_neon, - vpx_highbd_d45_predictor_32x32_neon, - vpx_highbd_d135_predictor_32x32_neon, nullptr, nullptr, - nullptr, nullptr, vpx_highbd_tm_predictor_32x32_neon) + vpx_highbd_d135_predictor_8x8_neon, vpx_highbd_d117_predictor_8x8_neon, + vpx_highbd_d153_predictor_8x8_neon, vpx_highbd_d207_predictor_8x8_neon, + vpx_highbd_d63_predictor_8x8_neon, vpx_highbd_tm_predictor_8x8_neon) +HIGHBD_INTRA_PRED_TEST( + NEON, TestHighbdIntraPred16, vpx_highbd_dc_predictor_16x16_neon, + vpx_highbd_dc_left_predictor_16x16_neon, + vpx_highbd_dc_top_predictor_16x16_neon, + vpx_highbd_dc_128_predictor_16x16_neon, vpx_highbd_v_predictor_16x16_neon, + vpx_highbd_h_predictor_16x16_neon, vpx_highbd_d45_predictor_16x16_neon, + vpx_highbd_d135_predictor_16x16_neon, vpx_highbd_d117_predictor_16x16_neon, + vpx_highbd_d153_predictor_16x16_neon, vpx_highbd_d207_predictor_16x16_neon, + vpx_highbd_d63_predictor_16x16_neon, vpx_highbd_tm_predictor_16x16_neon) +HIGHBD_INTRA_PRED_TEST( + NEON, TestHighbdIntraPred32, vpx_highbd_dc_predictor_32x32_neon, + vpx_highbd_dc_left_predictor_32x32_neon, + vpx_highbd_dc_top_predictor_32x32_neon, + vpx_highbd_dc_128_predictor_32x32_neon, vpx_highbd_v_predictor_32x32_neon, + vpx_highbd_h_predictor_32x32_neon, vpx_highbd_d45_predictor_32x32_neon, + vpx_highbd_d135_predictor_32x32_neon, vpx_highbd_d117_predictor_32x32_neon, + vpx_highbd_d153_predictor_32x32_neon, vpx_highbd_d207_predictor_32x32_neon, + vpx_highbd_d63_predictor_32x32_neon, vpx_highbd_tm_predictor_32x32_neon) #endif // HAVE_NEON #endif // CONFIG_VP9_HIGHBITDEPTH -#include "test/test_libvpx.cc" +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + ::libvpx_test::init_vpx_test(); + return RUN_ALL_TESTS(); +} diff --git a/libs/libvpx/test/test_libvpx.cc b/libs/libvpx/test/test_libvpx.cc index 222a83f8c7..ba27102385 100644 --- a/libs/libvpx/test/test_libvpx.cc +++ b/libs/libvpx/test/test_libvpx.cc @@ -7,69 +7,12 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#include -#include "third_party/googletest/src/include/gtest/gtest.h" - -#include "./vpx_config.h" -#if VPX_ARCH_X86 || VPX_ARCH_X86_64 -#include "vpx_ports/x86.h" -#endif -extern "C" { -#if CONFIG_VP8 -extern void vp8_rtcd(); -#endif // CONFIG_VP8 -#if CONFIG_VP9 -extern void vp9_rtcd(); -#endif // CONFIG_VP9 -extern void vpx_dsp_rtcd(); -extern void vpx_scale_rtcd(); -} - -#if VPX_ARCH_X86 || VPX_ARCH_X86_64 -static void append_negative_gtest_filter(const char *str) { - std::string filter = ::testing::FLAGS_gtest_filter; - // Negative patterns begin with one '-' followed by a ':' separated list. - if (filter.find('-') == std::string::npos) filter += '-'; - filter += str; - ::testing::FLAGS_gtest_filter = filter; -} -#endif // VPX_ARCH_X86 || VPX_ARCH_X86_64 +#include "gtest/gtest.h" +#include "test/init_vpx_test.h" int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); - -#if VPX_ARCH_X86 || VPX_ARCH_X86_64 - const int simd_caps = x86_simd_caps(); - if (!(simd_caps & HAS_MMX)) append_negative_gtest_filter(":MMX.*:MMX/*"); - if (!(simd_caps & HAS_SSE)) append_negative_gtest_filter(":SSE.*:SSE/*"); - if (!(simd_caps & HAS_SSE2)) append_negative_gtest_filter(":SSE2.*:SSE2/*"); - if (!(simd_caps & HAS_SSE3)) append_negative_gtest_filter(":SSE3.*:SSE3/*"); - if (!(simd_caps & HAS_SSSE3)) { - append_negative_gtest_filter(":SSSE3.*:SSSE3/*"); - } - if (!(simd_caps & HAS_SSE4_1)) { - append_negative_gtest_filter(":SSE4_1.*:SSE4_1/*"); - } - if (!(simd_caps & HAS_AVX)) append_negative_gtest_filter(":AVX.*:AVX/*"); - if (!(simd_caps & HAS_AVX2)) append_negative_gtest_filter(":AVX2.*:AVX2/*"); - if (!(simd_caps & HAS_AVX512)) { - append_negative_gtest_filter(":AVX512.*:AVX512/*"); - } -#endif // VPX_ARCH_X86 || VPX_ARCH_X86_64 - -#if !CONFIG_SHARED -// Shared library builds don't support whitebox tests -// that exercise internal symbols. -#if CONFIG_VP8 - vp8_rtcd(); -#endif // CONFIG_VP8 -#if CONFIG_VP9 - vp9_rtcd(); -#endif // CONFIG_VP9 - vpx_dsp_rtcd(); - vpx_scale_rtcd(); -#endif // !CONFIG_SHARED - + ::libvpx_test::init_vpx_test(); return RUN_ALL_TESTS(); } diff --git a/libs/libvpx/test/test_rc_interface.cc b/libs/libvpx/test/test_rc_interface.cc index ec75700f73..840a299f82 100644 --- a/libs/libvpx/test/test_rc_interface.cc +++ b/libs/libvpx/test/test_rc_interface.cc @@ -1,4 +1,14 @@ -#include "third_party/googletest/src/include/gtest/gtest.h" +/* + * Copyright (c) 2021 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "gtest/gtest.h" int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); diff --git a/libs/libvpx/test/test_vector_test.cc b/libs/libvpx/test/test_vector_test.cc index ca990f4dd4..259db92e87 100644 --- a/libs/libvpx/test/test_vector_test.cc +++ b/libs/libvpx/test/test_vector_test.cc @@ -15,7 +15,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "../tools_common.h" #include "./vpx_config.h" #include "test/codec_factory.h" @@ -35,20 +35,14 @@ const int kThreads = 0; const int kMtMode = 1; const int kFileName = 2; -typedef std::tuple DecodeParam; +using DecodeParam = std::tuple; class TestVectorTest : public ::libvpx_test::DecoderTest, public ::libvpx_test::CodecTestWithParam { protected: - TestVectorTest() : DecoderTest(GET_PARAM(0)), md5_file_(nullptr) { -#if CONFIG_VP9_DECODER - resize_clips_.insert(::libvpx_test::kVP9TestVectorsResize, - ::libvpx_test::kVP9TestVectorsResize + - ::libvpx_test::kNumVP9TestVectorsResize); -#endif - } + TestVectorTest() : DecoderTest(GET_PARAM(0)), md5_file_(nullptr) {} - virtual ~TestVectorTest() { + ~TestVectorTest() override { if (md5_file_) fclose(md5_file_); } @@ -59,9 +53,8 @@ class TestVectorTest : public ::libvpx_test::DecoderTest, } #if CONFIG_VP9_DECODER - virtual void PreDecodeFrameHook( - const libvpx_test::CompressedVideoSource &video, - libvpx_test::Decoder *decoder) { + void PreDecodeFrameHook(const libvpx_test::CompressedVideoSource &video, + libvpx_test::Decoder *decoder) override { if (video.frame_number() == 0 && mt_mode_ >= 0) { if (mt_mode_ == 1) { decoder->Control(VP9D_SET_LOOP_FILTER_OPT, 1); @@ -77,8 +70,8 @@ class TestVectorTest : public ::libvpx_test::DecoderTest, } #endif - virtual void DecompressedFrameHook(const vpx_image_t &img, - const unsigned int frame_number) { + void DecompressedFrameHook(const vpx_image_t &img, + const unsigned int frame_number) override { ASSERT_NE(md5_file_, nullptr); char expected_md5[33]; char junk[128]; @@ -97,9 +90,6 @@ class TestVectorTest : public ::libvpx_test::DecoderTest, << "Md5 checksums don't match: frame number = " << frame_number; } -#if CONFIG_VP9_DECODER - std::set resize_clips_; -#endif int mt_mode_; private: diff --git a/libs/libvpx/test/test_vectors.cc b/libs/libvpx/test/test_vectors.cc index 3ffc3efc41..954ff771a9 100644 --- a/libs/libvpx/test/test_vectors.cc +++ b/libs/libvpx/test/test_vectors.cc @@ -9,6 +9,7 @@ */ #include "test/test_vectors.h" +#include "vpx_config.h" namespace libvpx_test { diff --git a/libs/libvpx/test/tile_independence_test.cc b/libs/libvpx/test/tile_independence_test.cc index d92c13f88e..6bf203571f 100644 --- a/libs/libvpx/test/tile_independence_test.cc +++ b/libs/libvpx/test/tile_independence_test.cc @@ -11,12 +11,12 @@ #include #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" -#include "test/util.h" #include "test/md5_helper.h" +#include "test/util.h" #include "vpx_mem/vpx_mem.h" namespace { @@ -36,18 +36,18 @@ class TileIndependenceTest : public ::libvpx_test::EncoderTest, inv_dec_->Control(VP9_INVERT_TILE_DECODE_ORDER, 1); } - virtual ~TileIndependenceTest() { + ~TileIndependenceTest() override { delete fw_dec_; delete inv_dec_; } - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(libvpx_test::kTwoPassGood); } - virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, - libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(libvpx_test::VideoSource *video, + libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP9E_SET_TILE_COLUMNS, n_tiles_); } @@ -65,7 +65,7 @@ class TileIndependenceTest : public ::libvpx_test::EncoderTest, md5->Add(img); } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { UpdateMD5(fw_dec_, pkt, &md5_fw_order_); UpdateMD5(inv_dec_, pkt, &md5_inv_order_); } diff --git a/libs/libvpx/test/timestamp_test.cc b/libs/libvpx/test/timestamp_test.cc index 645a9f2ff8..3567824df3 100644 --- a/libs/libvpx/test/timestamp_test.cc +++ b/libs/libvpx/test/timestamp_test.cc @@ -7,11 +7,12 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/util.h" #include "test/video_source.h" -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "vpx_config.h" namespace { @@ -42,16 +43,16 @@ class DummyTimebaseVideoSource : public ::libvpx_test::DummyVideoSource { (static_cast(framerate_numerator_) / framerate_denominator_); } - virtual vpx_codec_pts_t pts() const { + vpx_codec_pts_t pts() const override { return static_cast(frame_ * FrameDuration() + starting_pts_ + 0.5); } - virtual unsigned long duration() const { + unsigned long duration() const override { return static_cast(FrameDuration() + 0.5); } - virtual vpx_rational_t timebase() const { return timebase_; } + vpx_rational_t timebase() const override { return timebase_; } void set_starting_pts(int64_t starting_pts) { starting_pts_ = starting_pts; } @@ -67,9 +68,9 @@ class TimestampTest public ::libvpx_test::CodecTestWithParam { protected: TimestampTest() : EncoderTest(GET_PARAM(0)) {} - virtual ~TimestampTest() {} + ~TimestampTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(GET_PARAM(1)); } @@ -94,8 +95,15 @@ TEST_P(TimestampTest, TestVpxRollover) { ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); } +#if CONFIG_REALTIME_ONLY +VP8_INSTANTIATE_TEST_SUITE(TimestampTest, + ::testing::Values(::libvpx_test::kRealTime)); +VP9_INSTANTIATE_TEST_SUITE(TimestampTest, + ::testing::Values(::libvpx_test::kRealTime)); +#else VP8_INSTANTIATE_TEST_SUITE(TimestampTest, ::testing::Values(::libvpx_test::kTwoPassGood)); VP9_INSTANTIATE_TEST_SUITE(TimestampTest, ::testing::Values(::libvpx_test::kTwoPassGood)); +#endif } // namespace diff --git a/libs/libvpx/test/tools_common.sh b/libs/libvpx/test/tools_common.sh index 844a12534d..d0dd24df36 100755 --- a/libs/libvpx/test/tools_common.sh +++ b/libs/libvpx/test/tools_common.sh @@ -133,7 +133,7 @@ vpx_config_option_enabled() { vpx_config_option="${1}" vpx_config_file="${LIBVPX_CONFIG_PATH}/vpx_config.h" config_line=$(grep "${vpx_config_option}" "${vpx_config_file}") - if echo "${config_line}" | egrep -q '1$'; then + if echo "${config_line}" | grep -E -q '1$'; then echo yes fi } @@ -222,7 +222,7 @@ filter_strings() { if [ -n "${filter}" ]; then for s in ${strings}; do - if echo "${s}" | egrep -q ${exclude} "${filter}" > /dev/null 2>&1; then + if echo "${s}" | grep -E -q ${exclude} "${filter}" > /dev/null 2>&1; then filtered_strings="${filtered_strings} ${s}" fi done @@ -280,7 +280,12 @@ run_tests() { test_end "${test}" done - local tested_config="$(test_configuration_target) @ $(current_hash)" + # C vs SIMD tests are run for x86 32-bit, 64-bit and ARM platform + if [ "${test_name}" = "vp9_c_vs_simd_encode" ]; then + local tested_config="$(current_hash)" + else + local tested_config="$(test_configuration_target) @ $(current_hash)" + fi echo "${test_name}: Done, all tests pass for ${tested_config}." } diff --git a/libs/libvpx/test/user_priv_test.cc b/libs/libvpx/test/user_priv_test.cc index 20741f8268..0f45b082e5 100644 --- a/libs/libvpx/test/user_priv_test.cc +++ b/libs/libvpx/test/user_priv_test.cc @@ -11,7 +11,7 @@ #include #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "test/acm_random.h" #include "test/codec_factory.h" diff --git a/libs/libvpx/test/util.h b/libs/libvpx/test/util.h index 985f487094..94bab66416 100644 --- a/libs/libvpx/test/util.h +++ b/libs/libvpx/test/util.h @@ -15,7 +15,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "vpx/vpx_image.h" // Macros diff --git a/libs/libvpx/test/variance_test.cc b/libs/libvpx/test/variance_test.cc index 80855052dc..14b4262fab 100644 --- a/libs/libvpx/test/variance_test.cc +++ b/libs/libvpx/test/variance_test.cc @@ -11,7 +11,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" @@ -27,9 +27,12 @@ namespace { -typedef unsigned int (*Get4x4SseFunc)(const uint8_t *a, int a_stride, - const uint8_t *b, int b_stride); -typedef unsigned int (*SumOfSquaresFunction)(const int16_t *src); +using Get4x4SseFunc = unsigned int (*)(const uint8_t *a, int a_stride, + const uint8_t *b, int b_stride); +using GetVarianceFunc = void (*)(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + uint32_t *sse, int *sum); +using SumOfSquaresFunction = unsigned int (*)(const int16_t *src); using libvpx_test::ACMRandom; @@ -63,35 +66,65 @@ static unsigned int mb_ss_ref(const int16_t *src) { * Our codebase calculates the "diff" value in the variance algorithm by * (src - ref). */ -static uint32_t variance_ref(const uint8_t *src, const uint8_t *ref, int l2w, - int l2h, int src_stride, int ref_stride, - uint32_t *sse_ptr, bool use_high_bit_depth_, - vpx_bit_depth_t bit_depth) { - int64_t se = 0; - uint64_t sse = 0; - const int w = 1 << l2w; - const int h = 1 << l2h; +static void variance(const uint8_t *src, int src_stride, const uint8_t *ref, + int ref_stride, int w, int h, bool use_high_bit_depth_, + uint64_t *sse, int64_t *se, vpx_bit_depth_t bit_depth) { + int64_t se_long = 0; + uint64_t sse_long = 0; + for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { - int diff; + int diff = 0; if (!use_high_bit_depth_) { diff = src[y * src_stride + x] - ref[y * ref_stride + x]; - se += diff; - sse += diff * diff; #if CONFIG_VP9_HIGHBITDEPTH } else { diff = CONVERT_TO_SHORTPTR(src)[y * src_stride + x] - CONVERT_TO_SHORTPTR(ref)[y * ref_stride + x]; - se += diff; - sse += diff * diff; #endif // CONFIG_VP9_HIGHBITDEPTH } + se_long += diff; + sse_long += diff * diff; } } - RoundHighBitDepth(bit_depth, &se, &sse); - *sse_ptr = static_cast(sse); + + RoundHighBitDepth(bit_depth, &se_long, &sse_long); + + *sse = sse_long; + *se = se_long; +} + +static void get_variance_ref(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, int l2w, + int l2h, bool use_high_bit_depth_, uint32_t *sse, + int *se, vpx_bit_depth_t bit_depth) { + const int w = 1 << l2w; + const int h = 1 << l2h; + int64_t se_long = 0; + uint64_t sse_long = 0; + + variance(src, src_stride, ref, ref_stride, w, h, use_high_bit_depth_, + &sse_long, &se_long, bit_depth); + + *sse = static_cast(sse_long); + *se = static_cast(se_long); +} + +static uint32_t variance_ref(const uint8_t *src, const uint8_t *ref, int l2w, + int l2h, int src_stride, int ref_stride, + uint32_t *sse_ptr, bool use_high_bit_depth_, + vpx_bit_depth_t bit_depth) { + const int w = 1 << l2w; + const int h = 1 << l2h; + int64_t se_long = 0; + uint64_t sse_long = 0; + + variance(src, src_stride, ref, ref_stride, w, h, use_high_bit_depth_, + &sse_long, &se_long, bit_depth); + + *sse_ptr = static_cast(sse_long); return static_cast( - sse - ((static_cast(se) * se) >> (l2w + l2h))); + sse_long - ((static_cast(se_long) * se_long) >> (l2w + l2h))); } /* The subpel reference functions differ from the codec version in one aspect: @@ -210,7 +243,7 @@ class SumOfSquaresTest : public ::testing::TestWithParam { public: SumOfSquaresTest() : func_(GetParam()) {} - virtual ~SumOfSquaresTest() { libvpx_test::ClearSystemState(); } + ~SumOfSquaresTest() override { libvpx_test::ClearSystemState(); } protected: void ConstTest(); @@ -289,7 +322,7 @@ template class MainTestClass : public ::testing::TestWithParam > { public: - virtual void SetUp() { + void SetUp() override { params_ = this->GetParam(); rnd_.Reset(ACMRandom::DeterministicSeed()); @@ -308,7 +341,7 @@ class MainTestClass #endif } - virtual void TearDown() { + void TearDown() override { #if CONFIG_VP9_HIGHBITDEPTH if (use_high_bit_depth()) { // TODO(skal): remove! @@ -337,6 +370,9 @@ class MainTestClass void OneQuarterTest(); void SpeedTest(); + // GetVariance tests + void RefTestGetVar(); + // MSE/SSE tests void RefTestMse(); void RefTestSse(); @@ -488,8 +524,37 @@ void MainTestClass::SpeedTest() { } vpx_usec_timer_mark(&timer); const int elapsed_time = static_cast(vpx_usec_timer_elapsed(&timer)); - printf("Variance %dx%d time: %5d ms\n", width(), height(), - elapsed_time / 1000); + printf("Variance %dx%d %dbpp time: %5d ms\n", width(), height(), + params_.bit_depth, elapsed_time / 1000); +} + +//////////////////////////////////////////////////////////////////////////////// +// Tests related to GetVariance. +template +void MainTestClass::RefTestGetVar() { + for (int i = 0; i < 10; ++i) { + for (int j = 0; j < block_size(); j++) { + if (!use_high_bit_depth()) { + src_[j] = rnd_.Rand8(); + ref_[j] = rnd_.Rand8(); +#if CONFIG_VP9_HIGHBITDEPTH + } else { + CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask(); + CONVERT_TO_SHORTPTR(ref_)[j] = rnd_.Rand16() & mask(); +#endif // CONFIG_VP9_HIGHBITDEPTH + } + } + unsigned int sse1, sse2; + int sum1, sum2; + const int stride = width(); + ASM_REGISTER_STATE_CHECK( + params_.func(src_, stride, ref_, stride, &sse1, &sum1)); + get_variance_ref(src_, stride, ref_, stride, params_.log2width, + params_.log2height, use_high_bit_depth(), &sse2, &sum2, + params_.bit_depth); + EXPECT_EQ(sse1, sse2) << "Error at test index: " << i; + EXPECT_EQ(sum1, sum2) << "Error at test index: " << i; + } } //////////////////////////////////////////////////////////////////////////////// @@ -499,14 +564,21 @@ template void MainTestClass::RefTestMse() { for (int i = 0; i < 10; ++i) { for (int j = 0; j < block_size(); ++j) { - src_[j] = rnd_.Rand8(); - ref_[j] = rnd_.Rand8(); + if (!use_high_bit_depth()) { + src_[j] = rnd_.Rand8(); + ref_[j] = rnd_.Rand8(); +#if CONFIG_VP9_HIGHBITDEPTH + } else { + CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask(); + CONVERT_TO_SHORTPTR(ref_)[j] = rnd_.Rand16() & mask(); +#endif // CONFIG_VP9_HIGHBITDEPTH + } } unsigned int sse1, sse2; const int stride = width(); ASM_REGISTER_STATE_CHECK(params_.func(src_, stride, ref_, stride, &sse1)); variance_ref(src_, ref_, params_.log2width, params_.log2height, stride, - stride, &sse2, false, VPX_BITS_8); + stride, &sse2, use_high_bit_depth(), params_.bit_depth); EXPECT_EQ(sse1, sse2); } } @@ -530,8 +602,15 @@ void MainTestClass::RefTestSse() { template void MainTestClass::MaxTestMse() { - memset(src_, 255, block_size()); - memset(ref_, 0, block_size()); + if (!use_high_bit_depth()) { + memset(src_, 255, block_size()); + memset(ref_, 0, block_size()); +#if CONFIG_VP9_HIGHBITDEPTH + } else { + vpx_memset16(CONVERT_TO_SHORTPTR(src_), 255 << byte_shift(), block_size()); + vpx_memset16(CONVERT_TO_SHORTPTR(ref_), 0, block_size()); +#endif // CONFIG_VP9_HIGHBITDEPTH + } unsigned int sse; ASM_REGISTER_STATE_CHECK(params_.func(src_, width(), ref_, width(), &sse)); const unsigned int expected = block_size() * 255 * 255; @@ -554,7 +633,7 @@ template class SubpelVarianceTest : public ::testing::TestWithParam > { public: - virtual void SetUp() { + void SetUp() override { params_ = this->GetParam(); rnd_.Reset(ACMRandom::DeterministicSeed()); @@ -578,7 +657,7 @@ class SubpelVarianceTest ASSERT_NE(ref_, nullptr); } - virtual void TearDown() { + void TearDown() override { if (!use_high_bit_depth()) { vpx_free(src_); vpx_free(sec_); @@ -749,21 +828,24 @@ void SubpelVarianceTest::RefTest() { } } -typedef MainTestClass VpxSseTest; -typedef MainTestClass VpxMseTest; -typedef MainTestClass VpxVarianceTest; -typedef SubpelVarianceTest VpxSubpelVarianceTest; -typedef SubpelVarianceTest VpxSubpelAvgVarianceTest; +using VpxSseTest = MainTestClass; +using VpxMseTest = MainTestClass; +using VpxVarianceTest = MainTestClass; +using VpxGetVarianceTest = MainTestClass; +using VpxSubpelVarianceTest = SubpelVarianceTest; +using VpxSubpelAvgVarianceTest = SubpelVarianceTest; TEST_P(VpxSseTest, RefSse) { RefTestSse(); } TEST_P(VpxSseTest, MaxSse) { MaxTestSse(); } TEST_P(VpxMseTest, RefMse) { RefTestMse(); } TEST_P(VpxMseTest, MaxMse) { MaxTestMse(); } +TEST_P(VpxMseTest, DISABLED_Speed) { SpeedTest(); } TEST_P(VpxVarianceTest, Zero) { ZeroTest(); } TEST_P(VpxVarianceTest, Ref) { RefTest(); } TEST_P(VpxVarianceTest, RefStride) { RefStrideTest(); } TEST_P(VpxVarianceTest, OneQuarter) { OneQuarterTest(); } TEST_P(VpxVarianceTest, DISABLED_Speed) { SpeedTest(); } +TEST_P(VpxGetVarianceTest, RefGetVar) { RefTestGetVar(); } TEST_P(SumOfSquaresTest, Const) { ConstTest(); } TEST_P(SumOfSquaresTest, Ref) { RefTest(); } TEST_P(VpxSubpelVarianceTest, Ref) { RefTest(); } @@ -774,19 +856,19 @@ TEST_P(VpxSubpelAvgVarianceTest, Ref) { RefTest(); } INSTANTIATE_TEST_SUITE_P(C, SumOfSquaresTest, ::testing::Values(vpx_get_mb_ss_c)); -typedef TestParams SseParams; +using SseParams = TestParams; INSTANTIATE_TEST_SUITE_P(C, VpxSseTest, ::testing::Values(SseParams(2, 2, &vpx_get4x4sse_cs_c))); -typedef TestParams MseParams; +using MseParams = TestParams; INSTANTIATE_TEST_SUITE_P(C, VpxMseTest, ::testing::Values(MseParams(4, 4, &vpx_mse16x16_c), MseParams(4, 3, &vpx_mse16x8_c), MseParams(3, 4, &vpx_mse8x16_c), MseParams(3, 3, &vpx_mse8x8_c))); -typedef TestParams VarianceParams; +using VarianceParams = TestParams; INSTANTIATE_TEST_SUITE_P( C, VpxVarianceTest, ::testing::Values(VarianceParams(6, 6, &vpx_variance64x64_c), @@ -803,7 +885,17 @@ INSTANTIATE_TEST_SUITE_P( VarianceParams(2, 3, &vpx_variance4x8_c), VarianceParams(2, 2, &vpx_variance4x4_c))); -typedef TestParams SubpelVarianceParams; +using GetVarianceParams = TestParams; +INSTANTIATE_TEST_SUITE_P( + C, VpxGetVarianceTest, + ::testing::Values(GetVarianceParams(4, 4, &vpx_get16x16var_c), + GetVarianceParams(3, 3, &vpx_get8x8var_c), + GetVarianceParams(4, 4, &vpx_get16x16var_c), + GetVarianceParams(3, 3, &vpx_get8x8var_c), + GetVarianceParams(4, 4, &vpx_get16x16var_c), + GetVarianceParams(3, 3, &vpx_get8x8var_c))); + +using SubpelVarianceParams = TestParams; INSTANTIATE_TEST_SUITE_P( C, VpxSubpelVarianceTest, ::testing::Values( @@ -821,7 +913,7 @@ INSTANTIATE_TEST_SUITE_P( SubpelVarianceParams(2, 3, &vpx_sub_pixel_variance4x8_c, 0), SubpelVarianceParams(2, 2, &vpx_sub_pixel_variance4x4_c, 0))); -typedef TestParams SubpelAvgVarianceParams; +using SubpelAvgVarianceParams = TestParams; INSTANTIATE_TEST_SUITE_P( C, VpxSubpelAvgVarianceTest, ::testing::Values( @@ -840,39 +932,41 @@ INSTANTIATE_TEST_SUITE_P( SubpelAvgVarianceParams(2, 2, &vpx_sub_pixel_avg_variance4x4_c, 0))); #if CONFIG_VP9_HIGHBITDEPTH -typedef MainTestClass VpxHBDVarianceTest; -typedef SubpelVarianceTest VpxHBDSubpelVarianceTest; -typedef SubpelVarianceTest - VpxHBDSubpelAvgVarianceTest; +using VpxHBDVarianceTest = MainTestClass; +using VpxHBDGetVarianceTest = MainTestClass; +using VpxHBDSubpelVarianceTest = SubpelVarianceTest; +using VpxHBDSubpelAvgVarianceTest = + SubpelVarianceTest; TEST_P(VpxHBDVarianceTest, Zero) { ZeroTest(); } TEST_P(VpxHBDVarianceTest, Ref) { RefTest(); } TEST_P(VpxHBDVarianceTest, RefStride) { RefStrideTest(); } TEST_P(VpxHBDVarianceTest, OneQuarter) { OneQuarterTest(); } TEST_P(VpxHBDVarianceTest, DISABLED_Speed) { SpeedTest(); } +TEST_P(VpxHBDGetVarianceTest, RefGetVar) { RefTestGetVar(); } TEST_P(VpxHBDSubpelVarianceTest, Ref) { RefTest(); } TEST_P(VpxHBDSubpelVarianceTest, ExtremeRef) { ExtremeRefTest(); } TEST_P(VpxHBDSubpelAvgVarianceTest, Ref) { RefTest(); } -/* TODO(debargha): This test does not support the highbd version -typedef MainTestClass VpxHBDMseTest; +using VpxHBDMseTest = MainTestClass; TEST_P(VpxHBDMseTest, RefMse) { RefTestMse(); } TEST_P(VpxHBDMseTest, MaxMse) { MaxTestMse(); } +TEST_P(VpxHBDMseTest, DISABLED_Speed) { SpeedTest(); } INSTANTIATE_TEST_SUITE_P( C, VpxHBDMseTest, - ::testing::Values(MseParams(4, 4, &vpx_highbd_12_mse16x16_c), - MseParams(4, 4, &vpx_highbd_12_mse16x8_c), - MseParams(4, 4, &vpx_highbd_12_mse8x16_c), - MseParams(4, 4, &vpx_highbd_12_mse8x8_c), - MseParams(4, 4, &vpx_highbd_10_mse16x16_c), - MseParams(4, 4, &vpx_highbd_10_mse16x8_c), - MseParams(4, 4, &vpx_highbd_10_mse8x16_c), - MseParams(4, 4, &vpx_highbd_10_mse8x8_c), - MseParams(4, 4, &vpx_highbd_8_mse16x16_c), - MseParams(4, 4, &vpx_highbd_8_mse16x8_c), - MseParams(4, 4, &vpx_highbd_8_mse8x16_c), - MseParams(4, 4, &vpx_highbd_8_mse8x8_c))); -*/ + ::testing::Values(MseParams(4, 4, &vpx_highbd_12_mse16x16_c, VPX_BITS_12), + MseParams(4, 3, &vpx_highbd_12_mse16x8_c, VPX_BITS_12), + MseParams(3, 4, &vpx_highbd_12_mse8x16_c, VPX_BITS_12), + MseParams(3, 3, &vpx_highbd_12_mse8x8_c, VPX_BITS_12), + MseParams(4, 4, &vpx_highbd_10_mse16x16_c, VPX_BITS_10), + MseParams(4, 3, &vpx_highbd_10_mse16x8_c, VPX_BITS_10), + MseParams(3, 4, &vpx_highbd_10_mse8x16_c, VPX_BITS_10), + MseParams(3, 3, &vpx_highbd_10_mse8x8_c, VPX_BITS_10), + MseParams(4, 4, &vpx_highbd_8_mse16x16_c, VPX_BITS_8), + MseParams(4, 3, &vpx_highbd_8_mse16x8_c, VPX_BITS_8), + MseParams(3, 4, &vpx_highbd_8_mse8x16_c, VPX_BITS_8), + MseParams(3, 3, &vpx_highbd_8_mse8x8_c, VPX_BITS_8))); + GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VpxHBDMseTest); INSTANTIATE_TEST_SUITE_P( @@ -917,6 +1011,15 @@ INSTANTIATE_TEST_SUITE_P( VarianceParams(2, 3, &vpx_highbd_8_variance4x8_c, 8), VarianceParams(2, 2, &vpx_highbd_8_variance4x4_c, 8))); +INSTANTIATE_TEST_SUITE_P( + C, VpxHBDGetVarianceTest, + ::testing::Values(GetVarianceParams(4, 4, &vpx_highbd_12_get16x16var_c, 12), + GetVarianceParams(3, 3, &vpx_highbd_12_get8x8var_c, 12), + GetVarianceParams(4, 4, &vpx_highbd_10_get16x16var_c, 10), + GetVarianceParams(3, 3, &vpx_highbd_10_get8x8var_c, 10), + GetVarianceParams(4, 4, &vpx_highbd_8_get16x16var_c, 8), + GetVarianceParams(3, 3, &vpx_highbd_8_get8x8var_c, 8))); + INSTANTIATE_TEST_SUITE_P( C, VpxHBDSubpelVarianceTest, ::testing::Values( @@ -1077,7 +1180,7 @@ INSTANTIATE_TEST_SUITE_P( 12))); #endif // CONFIG_VP9_HIGHBITDEPTH -#if HAVE_SSE2 +#if HAVE_SSE2 && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P(SSE2, SumOfSquaresTest, ::testing::Values(vpx_get_mb_ss_sse2)); @@ -1103,6 +1206,15 @@ INSTANTIATE_TEST_SUITE_P( VarianceParams(2, 3, &vpx_variance4x8_sse2), VarianceParams(2, 2, &vpx_variance4x4_sse2))); +INSTANTIATE_TEST_SUITE_P( + SSE2, VpxGetVarianceTest, + ::testing::Values(GetVarianceParams(4, 4, &vpx_get16x16var_sse2), + GetVarianceParams(3, 3, &vpx_get8x8var_sse2), + GetVarianceParams(4, 4, &vpx_get16x16var_sse2), + GetVarianceParams(3, 3, &vpx_get8x8var_sse2), + GetVarianceParams(4, 4, &vpx_get16x16var_sse2), + GetVarianceParams(3, 3, &vpx_get8x8var_sse2))); + INSTANTIATE_TEST_SUITE_P( SSE2, VpxSubpelVarianceTest, ::testing::Values( @@ -1138,22 +1250,15 @@ INSTANTIATE_TEST_SUITE_P( SubpelAvgVarianceParams(2, 2, &vpx_sub_pixel_avg_variance4x4_sse2, 0))); #if CONFIG_VP9_HIGHBITDEPTH -/* TODO(debargha): This test does not support the highbd version INSTANTIATE_TEST_SUITE_P( SSE2, VpxHBDMseTest, - ::testing::Values(MseParams(4, 4, &vpx_highbd_12_mse16x16_sse2), - MseParams(4, 3, &vpx_highbd_12_mse16x8_sse2), - MseParams(3, 4, &vpx_highbd_12_mse8x16_sse2), - MseParams(3, 3, &vpx_highbd_12_mse8x8_sse2), - MseParams(4, 4, &vpx_highbd_10_mse16x16_sse2), - MseParams(4, 3, &vpx_highbd_10_mse16x8_sse2), - MseParams(3, 4, &vpx_highbd_10_mse8x16_sse2), - MseParams(3, 3, &vpx_highbd_10_mse8x8_sse2), - MseParams(4, 4, &vpx_highbd_8_mse16x16_sse2), - MseParams(4, 3, &vpx_highbd_8_mse16x8_sse2), - MseParams(3, 4, &vpx_highbd_8_mse8x16_sse2), - MseParams(3, 3, &vpx_highbd_8_mse8x8_sse2))); -*/ + ::testing::Values( + MseParams(4, 4, &vpx_highbd_12_mse16x16_sse2, VPX_BITS_12), + MseParams(3, 3, &vpx_highbd_12_mse8x8_sse2, VPX_BITS_12), + MseParams(4, 4, &vpx_highbd_10_mse16x16_sse2, VPX_BITS_10), + MseParams(3, 3, &vpx_highbd_10_mse8x8_sse2, VPX_BITS_10), + MseParams(4, 4, &vpx_highbd_8_mse16x16_sse2, VPX_BITS_8), + MseParams(3, 3, &vpx_highbd_8_mse8x8_sse2, VPX_BITS_8))); INSTANTIATE_TEST_SUITE_P( SSE2, VpxHBDVarianceTest, @@ -1189,6 +1294,16 @@ INSTANTIATE_TEST_SUITE_P( VarianceParams(3, 4, &vpx_highbd_8_variance8x16_sse2, 8), VarianceParams(3, 3, &vpx_highbd_8_variance8x8_sse2, 8))); +INSTANTIATE_TEST_SUITE_P( + SSE2, VpxHBDGetVarianceTest, + ::testing::Values( + GetVarianceParams(4, 4, &vpx_highbd_12_get16x16var_sse2, 12), + GetVarianceParams(3, 3, &vpx_highbd_12_get8x8var_sse2, 12), + GetVarianceParams(4, 4, &vpx_highbd_10_get16x16var_sse2, 10), + GetVarianceParams(3, 3, &vpx_highbd_10_get8x8var_sse2, 10), + GetVarianceParams(4, 4, &vpx_highbd_8_get16x16var_sse2, 8), + GetVarianceParams(3, 3, &vpx_highbd_8_get8x8var_sse2, 8))); + INSTANTIATE_TEST_SUITE_P( SSE2, VpxHBDSubpelVarianceTest, ::testing::Values( @@ -1361,9 +1476,9 @@ INSTANTIATE_TEST_SUITE_P( &vpx_highbd_8_sub_pixel_avg_variance8x4_sse2, 8))); #endif // CONFIG_VP9_HIGHBITDEPTH -#endif // HAVE_SSE2 +#endif // HAVE_SSE2 && HAVE_X86_ASM -#if HAVE_SSSE3 +#if HAVE_SSSE3 && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P( SSSE3, VpxSubpelVarianceTest, ::testing::Values( @@ -1405,7 +1520,7 @@ INSTANTIATE_TEST_SUITE_P( SubpelAvgVarianceParams(2, 3, &vpx_sub_pixel_avg_variance4x8_ssse3, 0), SubpelAvgVarianceParams(2, 2, &vpx_sub_pixel_avg_variance4x4_ssse3, 0))); -#endif // HAVE_SSSE3 +#endif // HAVE_SSSE3 && HAVE_X86_ASM #if HAVE_AVX2 INSTANTIATE_TEST_SUITE_P(AVX2, VpxMseTest, @@ -1421,7 +1536,10 @@ INSTANTIATE_TEST_SUITE_P( VarianceParams(5, 4, &vpx_variance32x16_avx2), VarianceParams(4, 5, &vpx_variance16x32_avx2), VarianceParams(4, 4, &vpx_variance16x16_avx2), - VarianceParams(4, 3, &vpx_variance16x8_avx2))); + VarianceParams(4, 3, &vpx_variance16x8_avx2), + VarianceParams(3, 4, &vpx_variance8x16_avx2), + VarianceParams(3, 3, &vpx_variance8x8_avx2), + VarianceParams(3, 2, &vpx_variance8x4_avx2))); INSTANTIATE_TEST_SUITE_P( AVX2, VpxSubpelVarianceTest, @@ -1443,8 +1561,10 @@ INSTANTIATE_TEST_SUITE_P(NEON, VpxSseTest, &vpx_get4x4sse_cs_neon))); INSTANTIATE_TEST_SUITE_P(NEON, VpxMseTest, - ::testing::Values(MseParams(4, 4, - &vpx_mse16x16_neon))); + ::testing::Values(MseParams(4, 4, &vpx_mse16x16_neon), + MseParams(4, 3, &vpx_mse16x8_neon), + MseParams(3, 4, &vpx_mse8x16_neon), + MseParams(3, 3, &vpx_mse8x8_neon))); INSTANTIATE_TEST_SUITE_P( NEON, VpxVarianceTest, @@ -1462,6 +1582,76 @@ INSTANTIATE_TEST_SUITE_P( VarianceParams(2, 3, &vpx_variance4x8_neon), VarianceParams(2, 2, &vpx_variance4x4_neon))); +INSTANTIATE_TEST_SUITE_P( + NEON, VpxGetVarianceTest, + ::testing::Values(GetVarianceParams(4, 4, &vpx_get16x16var_neon), + GetVarianceParams(3, 3, &vpx_get8x8var_neon), + GetVarianceParams(4, 4, &vpx_get16x16var_neon), + GetVarianceParams(3, 3, &vpx_get8x8var_neon), + GetVarianceParams(4, 4, &vpx_get16x16var_neon), + GetVarianceParams(3, 3, &vpx_get8x8var_neon))); + +#if HAVE_NEON_DOTPROD +INSTANTIATE_TEST_SUITE_P( + NEON_DOTPROD, VpxSseTest, + ::testing::Values(SseParams(2, 2, &vpx_get4x4sse_cs_neon_dotprod))); + +INSTANTIATE_TEST_SUITE_P( + NEON_DOTPROD, VpxMseTest, + ::testing::Values(MseParams(4, 4, &vpx_mse16x16_neon_dotprod), + MseParams(4, 3, &vpx_mse16x8_neon_dotprod), + MseParams(3, 4, &vpx_mse8x16_neon_dotprod), + MseParams(3, 3, &vpx_mse8x8_neon_dotprod))); + +INSTANTIATE_TEST_SUITE_P( + NEON_DOTPROD, VpxVarianceTest, + ::testing::Values(VarianceParams(6, 6, &vpx_variance64x64_neon_dotprod), + VarianceParams(6, 5, &vpx_variance64x32_neon_dotprod), + VarianceParams(5, 6, &vpx_variance32x64_neon_dotprod), + VarianceParams(5, 5, &vpx_variance32x32_neon_dotprod), + VarianceParams(5, 4, &vpx_variance32x16_neon_dotprod), + VarianceParams(4, 5, &vpx_variance16x32_neon_dotprod), + VarianceParams(4, 4, &vpx_variance16x16_neon_dotprod), + VarianceParams(4, 3, &vpx_variance16x8_neon_dotprod), + VarianceParams(3, 4, &vpx_variance8x16_neon_dotprod), + VarianceParams(3, 3, &vpx_variance8x8_neon_dotprod), + VarianceParams(3, 2, &vpx_variance8x4_neon_dotprod), + VarianceParams(2, 3, &vpx_variance4x8_neon_dotprod))); + +INSTANTIATE_TEST_SUITE_P( + NEON_DOTPROD, VpxSubpelVarianceTest, + ::testing::Values( + SubpelVarianceParams(6, 6, &vpx_sub_pixel_variance64x64_neon_dotprod, + 0), + SubpelVarianceParams(6, 5, &vpx_sub_pixel_variance64x32_neon_dotprod, + 0), + SubpelVarianceParams(5, 6, &vpx_sub_pixel_variance32x64_neon_dotprod, + 0), + SubpelVarianceParams(5, 5, &vpx_sub_pixel_variance32x32_neon_dotprod, + 0), + SubpelVarianceParams(5, 4, &vpx_sub_pixel_variance32x16_neon_dotprod, + 0), + SubpelVarianceParams(4, 5, &vpx_sub_pixel_variance16x32_neon_dotprod, + 0), + SubpelVarianceParams(4, 4, &vpx_sub_pixel_variance16x16_neon_dotprod, + 0), + SubpelVarianceParams(4, 3, &vpx_sub_pixel_variance16x8_neon_dotprod, 0), + SubpelVarianceParams(3, 4, &vpx_sub_pixel_variance8x16_neon_dotprod, 0), + SubpelVarianceParams(3, 3, &vpx_sub_pixel_variance8x8_neon_dotprod, 0), + SubpelVarianceParams(3, 2, &vpx_sub_pixel_variance8x4_neon_dotprod, 0), + SubpelVarianceParams(2, 3, &vpx_sub_pixel_variance4x8_neon_dotprod, + 0))); + +INSTANTIATE_TEST_SUITE_P( + NEON_DOTPROD, VpxGetVarianceTest, + ::testing::Values(GetVarianceParams(4, 4, &vpx_get16x16var_neon_dotprod), + GetVarianceParams(3, 3, &vpx_get8x8var_neon_dotprod), + GetVarianceParams(4, 4, &vpx_get16x16var_neon_dotprod), + GetVarianceParams(3, 3, &vpx_get8x8var_neon_dotprod), + GetVarianceParams(4, 4, &vpx_get16x16var_neon_dotprod), + GetVarianceParams(3, 3, &vpx_get8x8var_neon_dotprod))); +#endif // HAVE_NEON_DOTPROD + INSTANTIATE_TEST_SUITE_P( NEON, VpxSubpelVarianceTest, ::testing::Values( @@ -1495,8 +1685,362 @@ INSTANTIATE_TEST_SUITE_P( SubpelAvgVarianceParams(3, 2, &vpx_sub_pixel_avg_variance8x4_neon, 0), SubpelAvgVarianceParams(2, 3, &vpx_sub_pixel_avg_variance4x8_neon, 0), SubpelAvgVarianceParams(2, 2, &vpx_sub_pixel_avg_variance4x4_neon, 0))); + +#if CONFIG_VP9_HIGHBITDEPTH +INSTANTIATE_TEST_SUITE_P( + NEON, VpxHBDMseTest, + ::testing::Values( + MseParams(4, 4, &vpx_highbd_12_mse16x16_neon, VPX_BITS_12), + MseParams(4, 3, &vpx_highbd_12_mse16x8_neon, VPX_BITS_12), + MseParams(3, 4, &vpx_highbd_12_mse8x16_neon, VPX_BITS_12), + MseParams(3, 3, &vpx_highbd_12_mse8x8_neon, VPX_BITS_12), + MseParams(4, 4, &vpx_highbd_10_mse16x16_neon, VPX_BITS_10), + MseParams(4, 3, &vpx_highbd_10_mse16x8_neon, VPX_BITS_10), + MseParams(3, 4, &vpx_highbd_10_mse8x16_neon, VPX_BITS_10), + MseParams(3, 3, &vpx_highbd_10_mse8x8_neon, VPX_BITS_10), + MseParams(4, 4, &vpx_highbd_8_mse16x16_neon, VPX_BITS_8), + MseParams(4, 3, &vpx_highbd_8_mse16x8_neon, VPX_BITS_8), + MseParams(3, 4, &vpx_highbd_8_mse8x16_neon, VPX_BITS_8), + MseParams(3, 3, &vpx_highbd_8_mse8x8_neon, VPX_BITS_8))); + +#if HAVE_NEON_DOTPROD +INSTANTIATE_TEST_SUITE_P( + NEON_DOTPROD, VpxHBDMseTest, + ::testing::Values( + MseParams(4, 4, &vpx_highbd_8_mse16x16_neon_dotprod, VPX_BITS_8), + MseParams(4, 3, &vpx_highbd_8_mse16x8_neon_dotprod, VPX_BITS_8), + MseParams(3, 4, &vpx_highbd_8_mse8x16_neon_dotprod, VPX_BITS_8), + MseParams(3, 3, &vpx_highbd_8_mse8x8_neon_dotprod, VPX_BITS_8))); +#endif // HAVE_NEON_DOTPROD + +#if HAVE_SVE +INSTANTIATE_TEST_SUITE_P( + SVE, VpxHBDMseTest, + ::testing::Values(MseParams(4, 4, &vpx_highbd_12_mse16x16_sve, VPX_BITS_12), + MseParams(4, 3, &vpx_highbd_12_mse16x8_sve, VPX_BITS_12), + MseParams(3, 4, &vpx_highbd_12_mse8x16_sve, VPX_BITS_12), + MseParams(3, 3, &vpx_highbd_12_mse8x8_sve, VPX_BITS_12), + MseParams(4, 4, &vpx_highbd_10_mse16x16_sve, VPX_BITS_10), + MseParams(4, 3, &vpx_highbd_10_mse16x8_sve, VPX_BITS_10), + MseParams(3, 4, &vpx_highbd_10_mse8x16_sve, VPX_BITS_10), + MseParams(3, 3, &vpx_highbd_10_mse8x8_sve, VPX_BITS_10))); +#endif // HAVE_SVE + +INSTANTIATE_TEST_SUITE_P( + NEON, VpxHBDVarianceTest, + ::testing::Values( + VarianceParams(6, 6, &vpx_highbd_12_variance64x64_neon, 12), + VarianceParams(6, 5, &vpx_highbd_12_variance64x32_neon, 12), + VarianceParams(5, 6, &vpx_highbd_12_variance32x64_neon, 12), + VarianceParams(5, 5, &vpx_highbd_12_variance32x32_neon, 12), + VarianceParams(5, 4, &vpx_highbd_12_variance32x16_neon, 12), + VarianceParams(4, 5, &vpx_highbd_12_variance16x32_neon, 12), + VarianceParams(4, 4, &vpx_highbd_12_variance16x16_neon, 12), + VarianceParams(4, 3, &vpx_highbd_12_variance16x8_neon, 12), + VarianceParams(3, 4, &vpx_highbd_12_variance8x16_neon, 12), + VarianceParams(3, 3, &vpx_highbd_12_variance8x8_neon, 12), + VarianceParams(3, 2, &vpx_highbd_12_variance8x4_neon, 12), + VarianceParams(2, 3, &vpx_highbd_12_variance4x8_neon, 12), + VarianceParams(2, 2, &vpx_highbd_12_variance4x4_neon, 12), + VarianceParams(6, 6, &vpx_highbd_10_variance64x64_neon, 10), + VarianceParams(6, 5, &vpx_highbd_10_variance64x32_neon, 10), + VarianceParams(5, 6, &vpx_highbd_10_variance32x64_neon, 10), + VarianceParams(5, 5, &vpx_highbd_10_variance32x32_neon, 10), + VarianceParams(5, 4, &vpx_highbd_10_variance32x16_neon, 10), + VarianceParams(4, 5, &vpx_highbd_10_variance16x32_neon, 10), + VarianceParams(4, 4, &vpx_highbd_10_variance16x16_neon, 10), + VarianceParams(4, 3, &vpx_highbd_10_variance16x8_neon, 10), + VarianceParams(3, 4, &vpx_highbd_10_variance8x16_neon, 10), + VarianceParams(3, 3, &vpx_highbd_10_variance8x8_neon, 10), + VarianceParams(3, 2, &vpx_highbd_10_variance8x4_neon, 10), + VarianceParams(2, 3, &vpx_highbd_10_variance4x8_neon, 10), + VarianceParams(2, 2, &vpx_highbd_10_variance4x4_neon, 10), + VarianceParams(6, 6, &vpx_highbd_8_variance64x64_neon, 8), + VarianceParams(6, 5, &vpx_highbd_8_variance64x32_neon, 8), + VarianceParams(5, 6, &vpx_highbd_8_variance32x64_neon, 8), + VarianceParams(5, 5, &vpx_highbd_8_variance32x32_neon, 8), + VarianceParams(5, 4, &vpx_highbd_8_variance32x16_neon, 8), + VarianceParams(4, 5, &vpx_highbd_8_variance16x32_neon, 8), + VarianceParams(4, 4, &vpx_highbd_8_variance16x16_neon, 8), + VarianceParams(4, 3, &vpx_highbd_8_variance16x8_neon, 8), + VarianceParams(3, 4, &vpx_highbd_8_variance8x16_neon, 8), + VarianceParams(3, 3, &vpx_highbd_8_variance8x8_neon, 8), + VarianceParams(3, 2, &vpx_highbd_8_variance8x4_neon, 8), + VarianceParams(2, 3, &vpx_highbd_8_variance4x8_neon, 8), + VarianceParams(2, 2, &vpx_highbd_8_variance4x4_neon, 8))); + +INSTANTIATE_TEST_SUITE_P( + NEON, VpxHBDGetVarianceTest, + ::testing::Values( + GetVarianceParams(4, 4, &vpx_highbd_12_get16x16var_neon, 12), + GetVarianceParams(3, 3, &vpx_highbd_12_get8x8var_neon, 12), + GetVarianceParams(4, 4, &vpx_highbd_10_get16x16var_neon, 10), + GetVarianceParams(3, 3, &vpx_highbd_10_get8x8var_neon, 10), + GetVarianceParams(4, 4, &vpx_highbd_8_get16x16var_neon, 8), + GetVarianceParams(3, 3, &vpx_highbd_8_get8x8var_neon, 8))); + +#if HAVE_SVE +INSTANTIATE_TEST_SUITE_P( + SVE, VpxHBDGetVarianceTest, + ::testing::Values( + GetVarianceParams(4, 4, &vpx_highbd_12_get16x16var_sve, 12), + GetVarianceParams(3, 3, &vpx_highbd_12_get8x8var_sve, 12), + GetVarianceParams(4, 4, &vpx_highbd_10_get16x16var_sve, 10), + GetVarianceParams(3, 3, &vpx_highbd_10_get8x8var_sve, 10), + GetVarianceParams(4, 4, &vpx_highbd_8_get16x16var_sve, 8), + GetVarianceParams(3, 3, &vpx_highbd_8_get8x8var_sve, 8))); +#endif // HAVE_SVE + +INSTANTIATE_TEST_SUITE_P( + NEON, VpxHBDSubpelVarianceTest, + ::testing::Values( + SubpelVarianceParams(6, 6, &vpx_highbd_12_sub_pixel_variance64x64_neon, + 12), + SubpelVarianceParams(6, 5, &vpx_highbd_12_sub_pixel_variance64x32_neon, + 12), + SubpelVarianceParams(5, 6, &vpx_highbd_12_sub_pixel_variance32x64_neon, + 12), + SubpelVarianceParams(5, 5, &vpx_highbd_12_sub_pixel_variance32x32_neon, + 12), + SubpelVarianceParams(5, 4, &vpx_highbd_12_sub_pixel_variance32x16_neon, + 12), + SubpelVarianceParams(4, 5, &vpx_highbd_12_sub_pixel_variance16x32_neon, + 12), + SubpelVarianceParams(4, 4, &vpx_highbd_12_sub_pixel_variance16x16_neon, + 12), + SubpelVarianceParams(4, 3, &vpx_highbd_12_sub_pixel_variance16x8_neon, + 12), + SubpelVarianceParams(3, 4, &vpx_highbd_12_sub_pixel_variance8x16_neon, + 12), + SubpelVarianceParams(3, 3, &vpx_highbd_12_sub_pixel_variance8x8_neon, + 12), + SubpelVarianceParams(3, 2, &vpx_highbd_12_sub_pixel_variance8x4_neon, + 12), + SubpelVarianceParams(2, 3, &vpx_highbd_12_sub_pixel_variance4x8_neon, + 12), + SubpelVarianceParams(2, 2, &vpx_highbd_12_sub_pixel_variance4x4_neon, + 12), + SubpelVarianceParams(6, 6, &vpx_highbd_10_sub_pixel_variance64x64_neon, + 10), + SubpelVarianceParams(6, 5, &vpx_highbd_10_sub_pixel_variance64x32_neon, + 10), + SubpelVarianceParams(5, 6, &vpx_highbd_10_sub_pixel_variance32x64_neon, + 10), + SubpelVarianceParams(5, 5, &vpx_highbd_10_sub_pixel_variance32x32_neon, + 10), + SubpelVarianceParams(5, 4, &vpx_highbd_10_sub_pixel_variance32x16_neon, + 10), + SubpelVarianceParams(4, 5, &vpx_highbd_10_sub_pixel_variance16x32_neon, + 10), + SubpelVarianceParams(4, 4, &vpx_highbd_10_sub_pixel_variance16x16_neon, + 10), + SubpelVarianceParams(4, 3, &vpx_highbd_10_sub_pixel_variance16x8_neon, + 10), + SubpelVarianceParams(3, 4, &vpx_highbd_10_sub_pixel_variance8x16_neon, + 10), + SubpelVarianceParams(3, 3, &vpx_highbd_10_sub_pixel_variance8x8_neon, + 10), + SubpelVarianceParams(3, 2, &vpx_highbd_10_sub_pixel_variance8x4_neon, + 10), + SubpelVarianceParams(2, 3, &vpx_highbd_10_sub_pixel_variance4x8_neon, + 10), + SubpelVarianceParams(2, 2, &vpx_highbd_10_sub_pixel_variance4x4_neon, + 10), + SubpelVarianceParams(6, 6, &vpx_highbd_8_sub_pixel_variance64x64_neon, + 8), + SubpelVarianceParams(6, 5, &vpx_highbd_8_sub_pixel_variance64x32_neon, + 8), + SubpelVarianceParams(5, 6, &vpx_highbd_8_sub_pixel_variance32x64_neon, + 8), + SubpelVarianceParams(5, 5, &vpx_highbd_8_sub_pixel_variance32x32_neon, + 8), + SubpelVarianceParams(5, 4, &vpx_highbd_8_sub_pixel_variance32x16_neon, + 8), + SubpelVarianceParams(4, 5, &vpx_highbd_8_sub_pixel_variance16x32_neon, + 8), + SubpelVarianceParams(4, 4, &vpx_highbd_8_sub_pixel_variance16x16_neon, + 8), + SubpelVarianceParams(4, 3, &vpx_highbd_8_sub_pixel_variance16x8_neon, + 8), + SubpelVarianceParams(3, 4, &vpx_highbd_8_sub_pixel_variance8x16_neon, + 8), + SubpelVarianceParams(3, 3, &vpx_highbd_8_sub_pixel_variance8x8_neon, 8), + SubpelVarianceParams(3, 2, &vpx_highbd_8_sub_pixel_variance8x4_neon, 8), + SubpelVarianceParams(2, 3, &vpx_highbd_8_sub_pixel_variance4x8_neon, 8), + SubpelVarianceParams(2, 2, &vpx_highbd_8_sub_pixel_variance4x4_neon, + 8))); + +INSTANTIATE_TEST_SUITE_P( + NEON, VpxHBDSubpelAvgVarianceTest, + ::testing::Values( + SubpelAvgVarianceParams(6, 6, + &vpx_highbd_12_sub_pixel_avg_variance64x64_neon, + 12), + SubpelAvgVarianceParams(6, 5, + &vpx_highbd_12_sub_pixel_avg_variance64x32_neon, + 12), + SubpelAvgVarianceParams(5, 6, + &vpx_highbd_12_sub_pixel_avg_variance32x64_neon, + 12), + SubpelAvgVarianceParams(5, 5, + &vpx_highbd_12_sub_pixel_avg_variance32x32_neon, + 12), + SubpelAvgVarianceParams(5, 4, + &vpx_highbd_12_sub_pixel_avg_variance32x16_neon, + 12), + SubpelAvgVarianceParams(4, 5, + &vpx_highbd_12_sub_pixel_avg_variance16x32_neon, + 12), + SubpelAvgVarianceParams(4, 4, + &vpx_highbd_12_sub_pixel_avg_variance16x16_neon, + 12), + SubpelAvgVarianceParams(4, 3, + &vpx_highbd_12_sub_pixel_avg_variance16x8_neon, + 12), + SubpelAvgVarianceParams(3, 4, + &vpx_highbd_12_sub_pixel_avg_variance8x16_neon, + 12), + SubpelAvgVarianceParams(3, 3, + &vpx_highbd_12_sub_pixel_avg_variance8x8_neon, + 12), + SubpelAvgVarianceParams(3, 2, + &vpx_highbd_12_sub_pixel_avg_variance8x4_neon, + 12), + SubpelAvgVarianceParams(2, 3, + &vpx_highbd_12_sub_pixel_avg_variance4x8_neon, + 12), + SubpelAvgVarianceParams(2, 2, + &vpx_highbd_12_sub_pixel_avg_variance4x4_neon, + 12), + SubpelAvgVarianceParams(6, 6, + &vpx_highbd_10_sub_pixel_avg_variance64x64_neon, + 10), + SubpelAvgVarianceParams(6, 5, + &vpx_highbd_10_sub_pixel_avg_variance64x32_neon, + 10), + SubpelAvgVarianceParams(5, 6, + &vpx_highbd_10_sub_pixel_avg_variance32x64_neon, + 10), + SubpelAvgVarianceParams(5, 5, + &vpx_highbd_10_sub_pixel_avg_variance32x32_neon, + 10), + SubpelAvgVarianceParams(5, 4, + &vpx_highbd_10_sub_pixel_avg_variance32x16_neon, + 10), + SubpelAvgVarianceParams(4, 5, + &vpx_highbd_10_sub_pixel_avg_variance16x32_neon, + 10), + SubpelAvgVarianceParams(4, 4, + &vpx_highbd_10_sub_pixel_avg_variance16x16_neon, + 10), + SubpelAvgVarianceParams(4, 3, + &vpx_highbd_10_sub_pixel_avg_variance16x8_neon, + 10), + SubpelAvgVarianceParams(3, 4, + &vpx_highbd_10_sub_pixel_avg_variance8x16_neon, + 10), + SubpelAvgVarianceParams(3, 3, + &vpx_highbd_10_sub_pixel_avg_variance8x8_neon, + 10), + SubpelAvgVarianceParams(3, 2, + &vpx_highbd_10_sub_pixel_avg_variance8x4_neon, + 10), + SubpelAvgVarianceParams(2, 3, + &vpx_highbd_10_sub_pixel_avg_variance4x8_neon, + 10), + SubpelAvgVarianceParams(2, 2, + &vpx_highbd_10_sub_pixel_avg_variance4x4_neon, + 10), + SubpelAvgVarianceParams(6, 6, + &vpx_highbd_8_sub_pixel_avg_variance64x64_neon, + 8), + SubpelAvgVarianceParams(6, 5, + &vpx_highbd_8_sub_pixel_avg_variance64x32_neon, + 8), + SubpelAvgVarianceParams(5, 6, + &vpx_highbd_8_sub_pixel_avg_variance32x64_neon, + 8), + SubpelAvgVarianceParams(5, 5, + &vpx_highbd_8_sub_pixel_avg_variance32x32_neon, + 8), + SubpelAvgVarianceParams(5, 4, + &vpx_highbd_8_sub_pixel_avg_variance32x16_neon, + 8), + SubpelAvgVarianceParams(4, 5, + &vpx_highbd_8_sub_pixel_avg_variance16x32_neon, + 8), + SubpelAvgVarianceParams(4, 4, + &vpx_highbd_8_sub_pixel_avg_variance16x16_neon, + 8), + SubpelAvgVarianceParams(4, 3, + &vpx_highbd_8_sub_pixel_avg_variance16x8_neon, + 8), + SubpelAvgVarianceParams(3, 4, + &vpx_highbd_8_sub_pixel_avg_variance8x16_neon, + 8), + SubpelAvgVarianceParams(3, 3, + &vpx_highbd_8_sub_pixel_avg_variance8x8_neon, + 8), + SubpelAvgVarianceParams(3, 2, + &vpx_highbd_8_sub_pixel_avg_variance8x4_neon, + 8), + SubpelAvgVarianceParams(2, 3, + &vpx_highbd_8_sub_pixel_avg_variance4x8_neon, + 8), + SubpelAvgVarianceParams(2, 2, + &vpx_highbd_8_sub_pixel_avg_variance4x4_neon, + 8))); + +#endif // CONFIG_VP9_HIGHBITDEPTH #endif // HAVE_NEON +#if HAVE_SVE +#if CONFIG_VP9_HIGHBITDEPTH +INSTANTIATE_TEST_SUITE_P( + SVE, VpxHBDVarianceTest, + ::testing::Values( + VarianceParams(6, 6, &vpx_highbd_12_variance64x64_sve, 12), + VarianceParams(6, 5, &vpx_highbd_12_variance64x32_sve, 12), + VarianceParams(5, 6, &vpx_highbd_12_variance32x64_sve, 12), + VarianceParams(5, 5, &vpx_highbd_12_variance32x32_sve, 12), + VarianceParams(5, 4, &vpx_highbd_12_variance32x16_sve, 12), + VarianceParams(4, 5, &vpx_highbd_12_variance16x32_sve, 12), + VarianceParams(4, 4, &vpx_highbd_12_variance16x16_sve, 12), + VarianceParams(4, 3, &vpx_highbd_12_variance16x8_sve, 12), + VarianceParams(3, 4, &vpx_highbd_12_variance8x16_sve, 12), + VarianceParams(3, 3, &vpx_highbd_12_variance8x8_sve, 12), + VarianceParams(3, 2, &vpx_highbd_12_variance8x4_sve, 12), + VarianceParams(2, 3, &vpx_highbd_12_variance4x8_sve, 12), + VarianceParams(2, 2, &vpx_highbd_12_variance4x4_sve, 12), + VarianceParams(6, 6, &vpx_highbd_10_variance64x64_sve, 10), + VarianceParams(6, 5, &vpx_highbd_10_variance64x32_sve, 10), + VarianceParams(5, 6, &vpx_highbd_10_variance32x64_sve, 10), + VarianceParams(5, 5, &vpx_highbd_10_variance32x32_sve, 10), + VarianceParams(5, 4, &vpx_highbd_10_variance32x16_sve, 10), + VarianceParams(4, 5, &vpx_highbd_10_variance16x32_sve, 10), + VarianceParams(4, 4, &vpx_highbd_10_variance16x16_sve, 10), + VarianceParams(4, 3, &vpx_highbd_10_variance16x8_sve, 10), + VarianceParams(3, 4, &vpx_highbd_10_variance8x16_sve, 10), + VarianceParams(3, 3, &vpx_highbd_10_variance8x8_sve, 10), + VarianceParams(3, 2, &vpx_highbd_10_variance8x4_sve, 10), + VarianceParams(2, 3, &vpx_highbd_10_variance4x8_sve, 10), + VarianceParams(2, 2, &vpx_highbd_10_variance4x4_sve, 10), + VarianceParams(6, 6, &vpx_highbd_8_variance64x64_sve, 8), + VarianceParams(6, 5, &vpx_highbd_8_variance64x32_sve, 8), + VarianceParams(5, 6, &vpx_highbd_8_variance32x64_sve, 8), + VarianceParams(5, 5, &vpx_highbd_8_variance32x32_sve, 8), + VarianceParams(5, 4, &vpx_highbd_8_variance32x16_sve, 8), + VarianceParams(4, 5, &vpx_highbd_8_variance16x32_sve, 8), + VarianceParams(4, 4, &vpx_highbd_8_variance16x16_sve, 8), + VarianceParams(4, 3, &vpx_highbd_8_variance16x8_sve, 8), + VarianceParams(3, 4, &vpx_highbd_8_variance8x16_sve, 8), + VarianceParams(3, 3, &vpx_highbd_8_variance8x8_sve, 8), + VarianceParams(3, 2, &vpx_highbd_8_variance8x4_sve, 8), + VarianceParams(2, 3, &vpx_highbd_8_variance4x8_sve, 8), + VarianceParams(2, 2, &vpx_highbd_8_variance4x4_sve, 8))); +#endif // CONFIG_VP9_HIGHBITDEPTH +#endif // HAVE_SVE + #if HAVE_MSA INSTANTIATE_TEST_SUITE_P(MSA, SumOfSquaresTest, ::testing::Values(vpx_get_mb_ss_msa)); @@ -1527,6 +2071,15 @@ INSTANTIATE_TEST_SUITE_P( VarianceParams(2, 3, &vpx_variance4x8_msa), VarianceParams(2, 2, &vpx_variance4x4_msa))); +INSTANTIATE_TEST_SUITE_P( + MSA, VpxGetVarianceTest, + ::testing::Values(GetVarianceParams(4, 4, &vpx_get16x16var_msa), + GetVarianceParams(3, 3, &vpx_get8x8var_msa), + GetVarianceParams(4, 4, &vpx_get16x16var_msa), + GetVarianceParams(3, 3, &vpx_get8x8var_msa), + GetVarianceParams(4, 4, &vpx_get16x16var_msa), + GetVarianceParams(3, 3, &vpx_get8x8var_msa))); + INSTANTIATE_TEST_SUITE_P( MSA, VpxSubpelVarianceTest, ::testing::Values( @@ -1590,6 +2143,15 @@ INSTANTIATE_TEST_SUITE_P( VarianceParams(3, 2, &vpx_variance8x4_vsx), VarianceParams(2, 3, &vpx_variance4x8_vsx), VarianceParams(2, 2, &vpx_variance4x4_vsx))); + +INSTANTIATE_TEST_SUITE_P( + VSX, VpxGetVarianceTest, + ::testing::Values(GetVarianceParams(4, 4, &vpx_get16x16var_vsx), + GetVarianceParams(3, 3, &vpx_get8x8var_vsx), + GetVarianceParams(4, 4, &vpx_get16x16var_vsx), + GetVarianceParams(3, 3, &vpx_get8x8var_vsx), + GetVarianceParams(4, 4, &vpx_get16x16var_vsx), + GetVarianceParams(3, 3, &vpx_get8x8var_vsx))); #endif // HAVE_VSX #if HAVE_MMI diff --git a/libs/libvpx/test/video_source.h b/libs/libvpx/test/video_source.h index a10ff6fb09..419d162596 100644 --- a/libs/libvpx/test/video_source.h +++ b/libs/libvpx/test/video_source.h @@ -24,10 +24,10 @@ #include #include -#include "test/acm_random.h" #if !defined(_WIN32) -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #endif +#include "test/acm_random.h" #include "vpx/vpx_encoder.h" namespace libvpx_test { @@ -64,7 +64,7 @@ inline FILE *OpenTestDataFile(const std::string &file_name) { return fopen(path_to_source.c_str(), "rb"); } -static FILE *GetTempOutFile(std::string *file_name) { +static FILE *GetTempOutFile(std::string *file_name, const char *io_mode) { file_name->clear(); #if defined(_WIN32) char fname[MAX_PATH]; @@ -73,7 +73,7 @@ static FILE *GetTempOutFile(std::string *file_name) { // Assume for now that the filename generated is unique per process if (GetTempFileNameA(tmppath, "lvx", 0, fname)) { file_name->assign(fname); - return fopen(fname, "wb+"); + return fopen(fname, io_mode); } } return nullptr; @@ -94,13 +94,16 @@ static FILE *GetTempOutFile(std::string *file_name) { const int fd = mkstemp(temp_file_name.get()); if (fd == -1) return nullptr; *file_name = temp_file_name.get(); - return fdopen(fd, "wb+"); + return fdopen(fd, io_mode); #endif } class TempOutFile { public: - TempOutFile() { file_ = GetTempOutFile(&file_name_); } + TempOutFile() { file_ = GetTempOutFile(&file_name_, "wb+"); } + TempOutFile(const char *io_mode) { + file_ = GetTempOutFile(&file_name_, io_mode); + } ~TempOutFile() { CloseFile(); if (!file_name_.empty()) { @@ -160,35 +163,35 @@ class DummyVideoSource : public VideoSource { ReallocImage(); } - virtual ~DummyVideoSource() { vpx_img_free(img_); } + ~DummyVideoSource() override { vpx_img_free(img_); } - virtual void Begin() { + void Begin() override { frame_ = 0; FillFrame(); } - virtual void Next() { + void Next() override { ++frame_; FillFrame(); } - virtual vpx_image_t *img() const { + vpx_image_t *img() const override { return (frame_ < limit_) ? img_ : nullptr; } // Models a stream where Timebase = 1/FPS, so pts == frame. - virtual vpx_codec_pts_t pts() const { return frame_; } + vpx_codec_pts_t pts() const override { return frame_; } - virtual unsigned long duration() const { return 1; } + unsigned long duration() const override { return 1; } - virtual vpx_rational_t timebase() const { + vpx_rational_t timebase() const override { const vpx_rational_t t = { 1, 30 }; return t; } - virtual unsigned int frame() const { return frame_; } + unsigned int frame() const override { return frame_; } - virtual unsigned int limit() const { return limit_; } + unsigned int limit() const override { return limit_; } void set_limit(unsigned int limit) { limit_ = limit; } @@ -233,17 +236,17 @@ class RandomVideoSource : public DummyVideoSource { RandomVideoSource(int seed = ACMRandom::DeterministicSeed()) : rnd_(seed), seed_(seed) {} - protected: // Reset the RNG to get a matching stream for the second pass - virtual void Begin() { + void Begin() override { frame_ = 0; rnd_.Reset(seed_); FillFrame(); } + protected: // 15 frames of noise, followed by 15 static frames. Reset to 0 rather // than holding previous frames to encourage keyframes to be thrown. - virtual void FillFrame() { + void FillFrame() override { if (img_) { if (frame_ % 30 < 15) { for (size_t i = 0; i < raw_sz_; ++i) img_->img_data[i] = rnd_.Rand8(); diff --git a/libs/libvpx/test/vp8_boolcoder_test.cc b/libs/libvpx/test/vp8_boolcoder_test.cc index c78b0b3b6c..0e2c7b77e1 100644 --- a/libs/libvpx/test/vp8_boolcoder_test.cc +++ b/libs/libvpx/test/vp8_boolcoder_test.cc @@ -15,7 +15,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/acm_random.h" #include "vp8/decoder/dboolhuff.h" diff --git a/libs/libvpx/test/vp8_datarate_test.cc b/libs/libvpx/test/vp8_datarate_test.cc index dcd68a2d4c..63fc724b7d 100644 --- a/libs/libvpx/test/vp8_datarate_test.cc +++ b/libs/libvpx/test/vp8_datarate_test.cc @@ -8,13 +8,13 @@ * be found in the AUTHORS file in the root of the source tree. */ #include "./vpx_config.h" -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" #include "test/util.h" #include "test/y4m_video_source.h" -#include "vpx/vpx_codec.h" +#include "vpx/vpx_encoder.h" namespace { @@ -24,31 +24,33 @@ class DatarateTestLarge public: DatarateTestLarge() : EncoderTest(GET_PARAM(0)) {} - virtual ~DatarateTestLarge() {} + ~DatarateTestLarge() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(GET_PARAM(1)); set_cpu_used_ = GET_PARAM(2); ResetModel(); } - virtual void ResetModel() { + void ResetModel() { last_pts_ = 0; bits_in_buffer_model_ = cfg_.rc_target_bitrate * cfg_.rc_buf_initial_sz; frame_number_ = 0; first_drop_ = 0; bits_total_ = 0; duration_ = 0.0; + // Denoiser is off by default. + denoiser_on_ = 0; denoiser_offon_test_ = 0; denoiser_offon_period_ = -1; gf_boost_ = 0; use_roi_ = false; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_NOISE_SENSITIVITY, denoiser_on_); encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_); @@ -74,7 +76,7 @@ class DatarateTestLarge duration_ = 0; } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { // Time since last timestamp = duration. vpx_codec_pts_t duration = pkt->data.frame.pts - last_pts_; @@ -121,7 +123,7 @@ class DatarateTestLarge ++frame_number_; } - virtual void EndPassHook(void) { + void EndPassHook() override { if (bits_total_) { const double file_size_in_kb = bits_total_ / 1000.; // bits per kilobit @@ -147,9 +149,9 @@ class DatarateTestLarge // For the temporal denoiser (#if CONFIG_TEMPORAL_DENOISING) the level j // refers to the 4 denoiser modes: denoiserYonly, denoiserOnYUV, // denoiserOnAggressive, and denoiserOnAdaptive. - denoiser_on_ = j; cfg_.rc_target_bitrate = 300; ResetModel(); + denoiser_on_ = j; ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); ASSERT_GE(cfg_.rc_target_bitrate, effective_datarate_ * 0.95) << " The datarate for the file exceeds the target!"; @@ -168,8 +170,6 @@ class DatarateTestLarge 288, 30, 1, 0, 299); cfg_.rc_target_bitrate = 300; ResetModel(); - // The denoiser is off by default. - denoiser_on_ = 0; // Set the offon test flag. denoiser_offon_test_ = 1; denoiser_offon_period_ = 100; @@ -181,7 +181,6 @@ class DatarateTestLarge } virtual void BasicBufferModelTest() { - denoiser_on_ = 0; cfg_.rc_buf_initial_sz = 500; cfg_.rc_dropframe_thresh = 1; cfg_.rc_max_quantizer = 56; @@ -212,7 +211,6 @@ class DatarateTestLarge } virtual void ChangingDropFrameThreshTest() { - denoiser_on_ = 0; cfg_.rc_buf_initial_sz = 500; cfg_.rc_max_quantizer = 36; cfg_.rc_end_usage = VPX_CBR; @@ -241,7 +239,6 @@ class DatarateTestLarge } virtual void DropFramesMultiThreadsTest() { - denoiser_on_ = 0; cfg_.rc_buf_initial_sz = 500; cfg_.rc_dropframe_thresh = 30; cfg_.rc_max_quantizer = 56; @@ -260,6 +257,26 @@ class DatarateTestLarge << " The datarate for the file missed the target!"; } + virtual void MultiThreadsPSNRTest() { + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_dropframe_thresh = 0; + cfg_.rc_max_quantizer = 56; + cfg_.rc_end_usage = VPX_CBR; + cfg_.g_threads = 4; + init_flags_ = VPX_CODEC_USE_PSNR; + + ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", + 1280, 720, 30, 1, 0, 30); + cfg_.rc_target_bitrate = 1000; + ResetModel(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + ASSERT_GE(cfg_.rc_target_bitrate, effective_datarate_ * 0.5) + << " The datarate for the file exceeds the target!"; + + ASSERT_LE(cfg_.rc_target_bitrate, file_datarate_ * 2.0) + << " The datarate for the file missed the target!"; + } + vpx_codec_pts_t last_pts_; int64_t bits_in_buffer_model_; double timebase_; @@ -301,7 +318,7 @@ TEST_P(DatarateTestLarge, DropFramesMultiThreads) { class DatarateTestRealTime : public DatarateTestLarge { public: - virtual ~DatarateTestRealTime() {} + ~DatarateTestRealTime() override = default; }; #if CONFIG_TEMPORAL_DENOISING @@ -324,8 +341,9 @@ TEST_P(DatarateTestRealTime, DropFramesMultiThreads) { DropFramesMultiThreadsTest(); } +TEST_P(DatarateTestRealTime, MultiThreadsPSNR) { MultiThreadsPSNRTest(); } + TEST_P(DatarateTestRealTime, RegionOfInterest) { - denoiser_on_ = 0; cfg_.rc_buf_initial_sz = 500; cfg_.rc_dropframe_thresh = 0; cfg_.rc_max_quantizer = 56; @@ -386,7 +404,6 @@ TEST_P(DatarateTestRealTime, RegionOfInterest) { } TEST_P(DatarateTestRealTime, GFBoost) { - denoiser_on_ = 0; cfg_.rc_buf_initial_sz = 500; cfg_.rc_dropframe_thresh = 0; cfg_.rc_max_quantizer = 56; @@ -409,7 +426,6 @@ TEST_P(DatarateTestRealTime, GFBoost) { } TEST_P(DatarateTestRealTime, NV12) { - denoiser_on_ = 0; cfg_.rc_buf_initial_sz = 500; cfg_.rc_dropframe_thresh = 0; cfg_.rc_max_quantizer = 56; @@ -430,9 +446,63 @@ TEST_P(DatarateTestRealTime, NV12) { << " The datarate for the file missed the target!"; } +class DatarateTestPsnr : public DatarateTestLarge { + public: + DatarateTestPsnr() : DatarateTestLarge() {} + ~DatarateTestPsnr() override = default; + + protected: + void SetUp() override { + InitializeConfig(); + SetMode(libvpx_test::kRealTime); + set_cpu_used_ = 10; + ResetModel(); + frame_flags_ = VPX_EFLAG_CALCULATE_PSNR; + } + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { + DatarateTestLarge::PreEncodeFrameHook(video, encoder); + frame_flags_ ^= VPX_EFLAG_CALCULATE_PSNR; +#if CONFIG_INTERNAL_STATS + // CONFIG_INTERNAL_STATS unconditionally generates PSNR. + expect_psnr_ = true; +#else + expect_psnr_ = (frame_flags_ & VPX_EFLAG_CALCULATE_PSNR) != 0; +#endif // CONFIG_INTERNAL_STATS + if (video->img() == nullptr) { + expect_psnr_ = false; + } + } + void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) override { + libvpx_test::CxDataIterator iter = encoder->GetCxData(); + + bool had_psnr = false; + while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) { + if (pkt->kind == VPX_CODEC_PSNR_PKT) had_psnr = true; + } + + EXPECT_EQ(had_psnr, expect_psnr_); + } + + private: + bool expect_psnr_; +}; + +TEST_P(DatarateTestPsnr, PerFramePsnr) { + ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, + 30, 1, 0, 100); + + ResetModel(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); +} + VP8_INSTANTIATE_TEST_SUITE(DatarateTestLarge, ALL_TEST_MODES, ::testing::Values(0)); VP8_INSTANTIATE_TEST_SUITE(DatarateTestRealTime, ::testing::Values(::libvpx_test::kRealTime), ::testing::Values(-6, -12)); +VP8_INSTANTIATE_TEST_SUITE(DatarateTestPsnr, + ::testing::Values(::libvpx_test::kRealTime), + ::testing::Values(0)); + } // namespace diff --git a/libs/libvpx/test/vp8_decrypt_test.cc b/libs/libvpx/test/vp8_decrypt_test.cc index bcac9d1a82..e00620b192 100644 --- a/libs/libvpx/test/vp8_decrypt_test.cc +++ b/libs/libvpx/test/vp8_decrypt_test.cc @@ -12,7 +12,7 @@ #include #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/ivf_video_source.h" diff --git a/libs/libvpx/test/vp8_denoiser_sse2_test.cc b/libs/libvpx/test/vp8_denoiser_sse2_test.cc index 8cb84ddd8e..6c68355d8e 100644 --- a/libs/libvpx/test/vp8_denoiser_sse2_test.cc +++ b/libs/libvpx/test/vp8_denoiser_sse2_test.cc @@ -12,7 +12,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/acm_random.h" #include "test/clear_system_state.h" #include "test/register_state_check.h" @@ -21,6 +21,7 @@ #include "vp8/encoder/denoising.h" #include "vp8/common/reconinter.h" #include "vpx/vpx_integer.h" +#include "vpx_config.h" #include "vpx_mem/vpx_mem.h" using libvpx_test::ACMRandom; @@ -30,11 +31,11 @@ namespace { const int kNumPixels = 16 * 16; class VP8DenoiserTest : public ::testing::TestWithParam { public: - virtual ~VP8DenoiserTest() {} + ~VP8DenoiserTest() override = default; - virtual void SetUp() { increase_denoising_ = GetParam(); } + void SetUp() override { increase_denoising_ = GetParam(); } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: int increase_denoising_; diff --git a/libs/libvpx/test/vp8_fdct4x4_test.cc b/libs/libvpx/test/vp8_fdct4x4_test.cc index 1b73a72a01..1fdbd82ee3 100644 --- a/libs/libvpx/test/vp8_fdct4x4_test.cc +++ b/libs/libvpx/test/vp8_fdct4x4_test.cc @@ -15,7 +15,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "./vp8_rtcd.h" @@ -25,7 +25,7 @@ namespace { -typedef void (*FdctFunc)(int16_t *a, int16_t *b, int a_stride); +using FdctFunc = void (*)(int16_t *a, int16_t *b, int a_stride); const int cospi8sqrt2minus1 = 20091; const int sinpi8sqrt2 = 35468; @@ -74,7 +74,7 @@ using libvpx_test::ACMRandom; class FdctTest : public ::testing::TestWithParam { public: - virtual void SetUp() { + void SetUp() override { fdct_func_ = GetParam(); rnd_.Reset(ACMRandom::DeterministicSeed()); } @@ -190,10 +190,10 @@ INSTANTIATE_TEST_SUITE_P(NEON, FdctTest, ::testing::Values(vp8_short_fdct4x4_neon)); #endif // HAVE_NEON -#if HAVE_SSE2 +#if HAVE_SSE2 && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P(SSE2, FdctTest, ::testing::Values(vp8_short_fdct4x4_sse2)); -#endif // HAVE_SSE2 +#endif // HAVE_SSE2 && HAVE_X86_ASM #if HAVE_MSA INSTANTIATE_TEST_SUITE_P(MSA, FdctTest, diff --git a/libs/libvpx/test/vp8_fragments_test.cc b/libs/libvpx/test/vp8_fragments_test.cc index 6e5baf229d..1f13cde812 100644 --- a/libs/libvpx/test/vp8_fragments_test.cc +++ b/libs/libvpx/test/vp8_fragments_test.cc @@ -7,7 +7,7 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/video_source.h" @@ -17,9 +17,9 @@ class VP8FragmentsTest : public ::libvpx_test::EncoderTest, public ::testing::Test { protected: VP8FragmentsTest() : EncoderTest(&::libvpx_test::kVP8) {} - virtual ~VP8FragmentsTest() {} + ~VP8FragmentsTest() override = default; - virtual void SetUp() { + void SetUp() override { const unsigned long init_flags = // NOLINT(runtime/int) VPX_CODEC_USE_OUTPUT_PARTITION; InitializeConfig(); diff --git a/libs/libvpx/test/vp8_loopfilter_simple_test.cc b/libs/libvpx/test/vp8_loopfilter_simple_test.cc new file mode 100644 index 0000000000..938523a825 --- /dev/null +++ b/libs/libvpx/test/vp8_loopfilter_simple_test.cc @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2026 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +// Compares the C and LoongArch LSX versions of the simple loop filter on +// random and near-flat input; the whole buffer must match byte for byte. + +#include + +#include +#include + +#include "gtest/gtest.h" + +#include "./vpx_config.h" +#include "./vp8_rtcd.h" +#include "test/acm_random.h" +#include "test/clear_system_state.h" +#include "vpx_ports/mem.h" + +namespace { + +using libvpx_test::ACMRandom; + +#if HAVE_LSX + +typedef void (*LoopFilterSimple)(unsigned char *y_ptr, int y_stride, + const unsigned char *blimit); + +const int kRows = 64; +const int kCols = 64; +const int kBufferSize = kRows * kCols; +// Two input distributions; see FillBuffer(). +const int kUniform = 0; +const int kBlocky = 1; +const int kNumModes = 2; + +// Fills the scratch area, addressed with 'stride' bytes per row. kUniform is +// pure noise. kBlocky is a near-flat image with 4x4 blocks and a small step at +// each block edge: that is what the filter meets in coded video, and it drives +// the filter into the small, unsaturated value range that uniform noise almost +// never reaches (noise saturates the average the filter is built around). +void FillBuffer(ACMRandom *rnd, int stride, int mode, unsigned char *buf) { + if (mode == kUniform) { + for (int i = 0; i < kBufferSize; ++i) buf[i] = (unsigned char)rnd->Rand8(); + return; + } + // Kept away from 0 and 255 so the block gains stay inside the byte range. + const int base = 48 + rnd->Rand8() % 160; + for (int y = 0; y * stride < kBufferSize; ++y) { + for (int x = 0; x < stride; ++x) { + const int v = + base + ((x >> 2) & 3) + ((y >> 2) & 3) + (int)(rnd->Rand8() % 3) - 1; + buf[y * stride + x] = (unsigned char)v; + } + } +} + +class SimpleEdgeTest : public ::testing::TestWithParam< + std::tuple > { + public: + void TearDown() override { libvpx_test::ClearSystemState(); } +}; + +TEST_P(SimpleEdgeTest, MatchC) { + LoopFilterSimple ref = std::get<0>(GetParam()); + LoopFilterSimple opt = std::get<1>(GetParam()); + // Guards against an instantiation that lists the same function twice, which + // would leave the comparison below comparing a buffer with itself. + ASSERT_NE(ref, opt); + + ACMRandom rnd(ACMRandom::DeterministicSeed()); + const std::array kStrides = { 16, 17, 24, 32, 33, 40, 48, 63 }; + // 193 is the largest blimit the codec produces (2 * (63 + 2) + 63), 194 and + // above leave that range, and 255 is the value that overflows saturated byte + // arithmetic. Every (stride, offset, mode) combination sweeps this list + // before falling back to random values. + const std::array kBlimits = { 0, 1, 2, 3, 4, + 5, 8, 16, 32, 63, + 64, 127, 128, 129, 160, + 192, 194, 200, 250, 255 }; + const int kNumBlimits = (int)kBlimits.size(); + const int kNumRandom = 100; + + DECLARE_ALIGNED(16, unsigned char, buf_ref[64 * 64]); + DECLARE_ALIGNED(16, unsigned char, buf_opt[64 * 64]); + + for (const int stride : kStrides) { + for (int offset = 0; offset < 4; ++offset) { + for (int mode = 0; mode < kNumModes; ++mode) { + for (int iter = 0; iter < kNumBlimits + kNumRandom; ++iter) { + const unsigned char blimit = + iter < kNumBlimits ? kBlimits[iter] : (unsigned char)rnd.Rand8(); + FillBuffer(&rnd, stride, mode, buf_ref); + memcpy(buf_opt, buf_ref, sizeof(buf_ref)); + ref(buf_ref + 2 * stride + 8 + offset, stride, &blimit); + opt(buf_opt + 2 * stride + 8 + offset, stride, &blimit); + ASSERT_EQ(0, memcmp(buf_ref, buf_opt, sizeof(buf_ref))) + << "stride=" << stride << " offset=" << offset << " mode=" << mode + << " iter=" << iter << " blimit=" << (int)blimit; + } + } + } + } +} + +INSTANTIATE_TEST_SUITE_P( + LSX, SimpleEdgeTest, + ::testing::Values( + std::make_tuple(&vp8_loop_filter_simple_vertical_edge_c, + &vp8_loop_filter_simple_vertical_edge_lsx), + std::make_tuple(&vp8_loop_filter_simple_horizontal_edge_c, + &vp8_loop_filter_simple_horizontal_edge_lsx), + std::make_tuple(&vp8_loop_filter_bvs_c, &vp8_loop_filter_bvs_lsx), + std::make_tuple(&vp8_loop_filter_bhs_c, &vp8_loop_filter_bhs_lsx))); + +#endif // HAVE_LSX + +} // namespace diff --git a/libs/libvpx/test/vp8_ratectrl_rtc_test.cc b/libs/libvpx/test/vp8_ratectrl_rtc_test.cc index ad310666e7..74a8cde7db 100644 --- a/libs/libvpx/test/vp8_ratectrl_rtc_test.cc +++ b/libs/libvpx/test/vp8_ratectrl_rtc_test.cc @@ -12,7 +12,7 @@ #include #include "./vpx_config.h" -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" @@ -25,7 +25,7 @@ namespace { struct Vp8RCTestVideo { - Vp8RCTestVideo() {} + Vp8RCTestVideo() = default; Vp8RCTestVideo(const char *name_, int width_, int height_, unsigned int frames_) : name(name_), width(width_), height(height_), frames(frames_) {} @@ -45,6 +45,7 @@ struct Vp8RCTestVideo { const Vp8RCTestVideo kVp8RCTestVectors[] = { Vp8RCTestVideo("niklas_640_480_30.yuv", 640, 480, 470), Vp8RCTestVideo("desktop_office1.1280_720-020.yuv", 1280, 720, 300), + Vp8RCTestVideo("hantro_collage_w352h288.yuv", 352, 288, 100), }; class Vp8RcInterfaceTest @@ -52,11 +53,12 @@ class Vp8RcInterfaceTest public ::libvpx_test::CodecTestWith2Params { public: Vp8RcInterfaceTest() - : EncoderTest(GET_PARAM(0)), key_interval_(3000), encoder_exit_(false) {} - virtual ~Vp8RcInterfaceTest() {} + : EncoderTest(GET_PARAM(0)), key_interval_(3000), encoder_exit_(false), + frame_drop_thresh_(0) {} + ~Vp8RcInterfaceTest() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); } @@ -111,8 +113,8 @@ class Vp8RcInterfaceTest return layer_id; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (rc_cfg_.ts_number_layers > 1) { const int layer_id = SetLayerId(video->frame(), cfg_.ts_number_layers); const int frame_flags = @@ -127,40 +129,51 @@ class Vp8RcInterfaceTest encoder->Control(VP8E_SET_CPUUSED, -6); encoder->Control(VP8E_SET_RTC_EXTERNAL_RATECTRL, 1); encoder->Control(VP8E_SET_MAX_INTRA_BITRATE_PCT, 1000); - } - if (frame_params_.frame_type == INTER_FRAME) { + if (rc_cfg_.is_screen) { + encoder->Control(VP8E_SET_SCREEN_CONTENT_MODE, 1); + } + } else if (frame_params_.frame_type == libvpx::RcFrameType::kInterFrame) { // Disable golden frame update. frame_flags_ |= VP8_EFLAG_NO_UPD_GF; frame_flags_ |= VP8_EFLAG_NO_UPD_ARF; } } - frame_params_.frame_type = - video->frame() % key_interval_ == 0 ? KEY_FRAME : INTER_FRAME; + frame_params_.frame_type = video->frame() % key_interval_ == 0 + ? libvpx::RcFrameType::kKeyFrame + : libvpx::RcFrameType::kInterFrame; encoder_exit_ = video->frame() == test_video_.frames; } - virtual void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) { + void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) override { if (encoder_exit_) { return; } int qp; + libvpx::UVDeltaQP uv_delta_qp; encoder->Control(VP8E_GET_LAST_QUANTIZER, &qp); - rc_api_->ComputeQP(frame_params_); - ASSERT_EQ(rc_api_->GetQP(), qp); + if (rc_api_->ComputeQP(frame_params_) == libvpx::FrameDropDecision::kOk) { + ASSERT_EQ(rc_api_->GetQP(), qp); + uv_delta_qp = rc_api_->GetUVDeltaQP(); + // delta_qp for UV channel is only set for screen. + if (!rc_cfg_.is_screen) { + ASSERT_EQ(uv_delta_qp.uvdc_delta_q, 0); + ASSERT_EQ(uv_delta_qp.uvac_delta_q, 0); + } + } else { + num_drops_++; + } } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { rc_api_->PostEncodeUpdate(pkt->data.frame.sz); } void RunOneLayer() { test_video_ = GET_PARAM(2); target_bitrate_ = GET_PARAM(1); - if (test_video_.width == 1280 && target_bitrate_ == 200) return; - if (test_video_.width == 640 && target_bitrate_ == 1000) return; SetConfig(); rc_api_ = libvpx::VP8RateControlRTC::Create(rc_cfg_); - rc_api_->UpdateRateControl(rc_cfg_); + ASSERT_TRUE(rc_api_->UpdateRateControl(rc_cfg_)); ::libvpx_test::I420VideoSource video(test_video_.name, test_video_.width, test_video_.height, 30, 1, 0, @@ -169,15 +182,51 @@ class Vp8RcInterfaceTest ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); } + void RunOneLayerScreen() { + test_video_ = GET_PARAM(2); + target_bitrate_ = GET_PARAM(1); + SetConfig(); + rc_cfg_.is_screen = true; + rc_api_ = libvpx::VP8RateControlRTC::Create(rc_cfg_); + ASSERT_TRUE(rc_api_->UpdateRateControl(rc_cfg_)); + + ::libvpx_test::I420VideoSource video(test_video_.name, test_video_.width, + test_video_.height, 30, 1, 0, + test_video_.frames); + + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + } + + void RunOneLayerDropFrames() { + test_video_ = GET_PARAM(2); + target_bitrate_ = GET_PARAM(1); + frame_drop_thresh_ = 30; + num_drops_ = 0; + // Use lower target_bitrate and max_quantizer to trigger drops. + target_bitrate_ = target_bitrate_ >> 2; + SetConfig(); + rc_cfg_.max_quantizer = 56; + cfg_.rc_max_quantizer = 56; + rc_api_ = libvpx::VP8RateControlRTC::Create(rc_cfg_); + ASSERT_TRUE(rc_api_->UpdateRateControl(rc_cfg_)); + + ::libvpx_test::I420VideoSource video(test_video_.name, test_video_.width, + test_video_.height, 30, 1, 0, + test_video_.frames); + + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + // Check that some frames were dropped, otherwise test has no value. + ASSERT_GE(num_drops_, 1); + } + void RunPeriodicKey() { test_video_ = GET_PARAM(2); target_bitrate_ = GET_PARAM(1); - if (test_video_.width == 1280 && target_bitrate_ == 200) return; - if (test_video_.width == 640 && target_bitrate_ == 1000) return; key_interval_ = 100; + frame_drop_thresh_ = 30; SetConfig(); rc_api_ = libvpx::VP8RateControlRTC::Create(rc_cfg_); - rc_api_->UpdateRateControl(rc_cfg_); + ASSERT_TRUE(rc_api_->UpdateRateControl(rc_cfg_)); ::libvpx_test::I420VideoSource video(test_video_.name, test_video_.width, test_video_.height, 30, 1, 0, @@ -189,11 +238,9 @@ class Vp8RcInterfaceTest void RunTemporalLayers2TL() { test_video_ = GET_PARAM(2); target_bitrate_ = GET_PARAM(1); - if (test_video_.width == 1280 && target_bitrate_ == 200) return; - if (test_video_.width == 640 && target_bitrate_ == 1000) return; SetConfigTemporalLayers(2); rc_api_ = libvpx::VP8RateControlRTC::Create(rc_cfg_); - rc_api_->UpdateRateControl(rc_cfg_); + ASSERT_TRUE(rc_api_->UpdateRateControl(rc_cfg_)); ::libvpx_test::I420VideoSource video(test_video_.name, test_video_.width, test_video_.height, 30, 1, 0, @@ -205,11 +252,9 @@ class Vp8RcInterfaceTest void RunTemporalLayers3TL() { test_video_ = GET_PARAM(2); target_bitrate_ = GET_PARAM(1); - if (test_video_.width == 1280 && target_bitrate_ == 200) return; - if (test_video_.width == 640 && target_bitrate_ == 1000) return; SetConfigTemporalLayers(3); rc_api_ = libvpx::VP8RateControlRTC::Create(rc_cfg_); - rc_api_->UpdateRateControl(rc_cfg_); + ASSERT_TRUE(rc_api_->UpdateRateControl(rc_cfg_)); ::libvpx_test::I420VideoSource video(test_video_.name, test_video_.width, test_video_.height, 30, 1, 0, @@ -218,6 +263,28 @@ class Vp8RcInterfaceTest ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); } + void RunTemporalLayers3TLDropFrames() { + test_video_ = GET_PARAM(2); + target_bitrate_ = GET_PARAM(1); + frame_drop_thresh_ = 30; + num_drops_ = 0; + // Use lower target_bitrate and max_quantizer to trigger drops. + target_bitrate_ = target_bitrate_ >> 2; + SetConfigTemporalLayers(3); + rc_cfg_.max_quantizer = 56; + cfg_.rc_max_quantizer = 56; + rc_api_ = libvpx::VP8RateControlRTC::Create(rc_cfg_); + ASSERT_TRUE(rc_api_->UpdateRateControl(rc_cfg_)); + + ::libvpx_test::I420VideoSource video(test_video_.name, test_video_.width, + test_video_.height, 30, 1, 0, + test_video_.frames); + + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + // Check that some frames were dropped, otherwise test has no value. + ASSERT_GE(num_drops_, 1); + } + private: void SetConfig() { rc_cfg_.width = test_video_.width; @@ -233,6 +300,7 @@ class Vp8RcInterfaceTest rc_cfg_.max_intra_bitrate_pct = 1000; rc_cfg_.framerate = 30.0; rc_cfg_.layer_target_bitrate[0] = target_bitrate_; + rc_cfg_.frame_drop_thresh = frame_drop_thresh_; // Encoder settings for ground truth. cfg_.g_w = test_video_.width; @@ -251,6 +319,7 @@ class Vp8RcInterfaceTest cfg_.rc_target_bitrate = target_bitrate_; cfg_.kf_min_dist = key_interval_; cfg_.kf_max_dist = key_interval_; + cfg_.rc_dropframe_thresh = frame_drop_thresh_; } void SetConfigTemporalLayers(int temporal_layers) { @@ -266,6 +335,7 @@ class Vp8RcInterfaceTest rc_cfg_.overshoot_pct = 50; rc_cfg_.max_intra_bitrate_pct = 1000; rc_cfg_.framerate = 30.0; + rc_cfg_.frame_drop_thresh = frame_drop_thresh_; if (temporal_layers == 2) { rc_cfg_.layer_target_bitrate[0] = 60 * target_bitrate_ / 100; rc_cfg_.layer_target_bitrate[1] = target_bitrate_; @@ -299,6 +369,7 @@ class Vp8RcInterfaceTest cfg_.rc_target_bitrate = target_bitrate_; cfg_.kf_min_dist = key_interval_; cfg_.kf_max_dist = key_interval_; + cfg_.rc_dropframe_thresh = frame_drop_thresh_; // 2 Temporal layers, no spatial layers, CBR mode. cfg_.ss_number_layers = 1; cfg_.ts_number_layers = temporal_layers; @@ -326,16 +397,26 @@ class Vp8RcInterfaceTest Vp8RCTestVideo test_video_; libvpx::VP8FrameParamsQpRTC frame_params_; bool encoder_exit_; + int frame_drop_thresh_; + int num_drops_; }; TEST_P(Vp8RcInterfaceTest, OneLayer) { RunOneLayer(); } +TEST_P(Vp8RcInterfaceTest, OneLayerScreen) { RunOneLayerScreen(); } + +TEST_P(Vp8RcInterfaceTest, OneLayerDropFrames) { RunOneLayerDropFrames(); } + TEST_P(Vp8RcInterfaceTest, OneLayerPeriodicKey) { RunPeriodicKey(); } TEST_P(Vp8RcInterfaceTest, TemporalLayers2TL) { RunTemporalLayers2TL(); } TEST_P(Vp8RcInterfaceTest, TemporalLayers3TL) { RunTemporalLayers3TL(); } +TEST_P(Vp8RcInterfaceTest, TemporalLayers3TLDropFrames) { + RunTemporalLayers3TLDropFrames(); +} + VP8_INSTANTIATE_TEST_SUITE(Vp8RcInterfaceTest, ::testing::Values(200, 400, 1000), ::testing::ValuesIn(kVp8RCTestVectors)); diff --git a/libs/libvpx/test/vp9_arf_freq_test.cc b/libs/libvpx/test/vp9_arf_freq_test.cc index c7e6f1af02..b62befe30d 100644 --- a/libs/libvpx/test/vp9_arf_freq_test.cc +++ b/libs/libvpx/test/vp9_arf_freq_test.cc @@ -10,7 +10,7 @@ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" @@ -18,6 +18,7 @@ #include "test/y4m_video_source.h" #include "test/yuv_video_source.h" #include "vp9/encoder/vp9_ratectrl.h" +#include "vpx_config.h" namespace { @@ -27,7 +28,7 @@ const int kBitrate = 500; #define ARF_NOT_SEEN 1000001 #define ARF_SEEN_ONCE 1000000 -typedef struct { +struct TestVideoParam { const char *filename; unsigned int width; unsigned int height; @@ -37,12 +38,12 @@ typedef struct { vpx_img_fmt fmt; vpx_bit_depth_t bit_depth; unsigned int profile; -} TestVideoParam; +}; -typedef struct { +struct TestEncodeParam { libvpx_test::TestMode mode; int cpu_used; -} TestEncodeParam; +}; const TestVideoParam kTestVectors[] = { // artificially increase framerate to trigger default check @@ -57,9 +58,12 @@ const TestVideoParam kTestVectors[] = { }; const TestEncodeParam kEncodeVectors[] = { +#if !CONFIG_REALTIME_ONLY { ::libvpx_test::kOnePassGood, 2 }, { ::libvpx_test::kOnePassGood, 5 }, { ::libvpx_test::kTwoPassGood, 1 }, { ::libvpx_test::kTwoPassGood, 2 }, - { ::libvpx_test::kTwoPassGood, 5 }, { ::libvpx_test::kRealTime, 5 }, + { ::libvpx_test::kTwoPassGood, 5 }, +#endif + { ::libvpx_test::kRealTime, 5 }, }; const int kMinArfVectors[] = { @@ -86,9 +90,9 @@ class ArfFreqTest : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(1)), test_encode_param_(GET_PARAM(2)), min_arf_requested_(GET_PARAM(3)) {} - virtual ~ArfFreqTest() {} + ~ArfFreqTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(test_encode_param_.mode); if (test_encode_param_.mode != ::libvpx_test::kRealTime) { @@ -104,7 +108,7 @@ class ArfFreqTest dec_cfg_.threads = 4; } - virtual void BeginPassHook(unsigned int) { + void BeginPassHook(unsigned int) override { min_run_ = ARF_NOT_SEEN; run_of_visible_frames_ = 0; } @@ -126,7 +130,7 @@ class ArfFreqTest return frames; } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { if (pkt->kind != VPX_CODEC_CX_FRAME_PKT) return; const int frames = GetNumFramesInPkt(pkt); if (frames == 1) { @@ -145,8 +149,8 @@ class ArfFreqTest } } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1); encoder->Control(VP9E_SET_TILE_COLUMNS, 4); diff --git a/libs/libvpx/test/vp9_block_error_test.cc b/libs/libvpx/test/vp9_block_error_test.cc index b93b014e65..e46da37568 100644 --- a/libs/libvpx/test/vp9_block_error_test.cc +++ b/libs/libvpx/test/vp9_block_error_test.cc @@ -13,7 +13,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "./vp9_rtcd.h" @@ -31,17 +31,17 @@ using libvpx_test::ACMRandom; namespace { const int kNumIterations = 1000; -typedef int64_t (*HBDBlockErrorFunc)(const tran_low_t *coeff, - const tran_low_t *dqcoeff, - intptr_t block_size, int64_t *ssz, - int bps); +using HBDBlockErrorFunc = int64_t (*)(const tran_low_t *coeff, + const tran_low_t *dqcoeff, + intptr_t block_size, int64_t *ssz, + int bps); -typedef std::tuple - BlockErrorParam; +using BlockErrorParam = + std::tuple; -typedef int64_t (*BlockErrorFunc)(const tran_low_t *coeff, - const tran_low_t *dqcoeff, - intptr_t block_size, int64_t *ssz); +using BlockErrorFunc = int64_t (*)(const tran_low_t *coeff, + const tran_low_t *dqcoeff, + intptr_t block_size, int64_t *ssz); template int64_t BlockError8BitWrapper(const tran_low_t *coeff, @@ -53,14 +53,14 @@ int64_t BlockError8BitWrapper(const tran_low_t *coeff, class BlockErrorTest : public ::testing::TestWithParam { public: - virtual ~BlockErrorTest() {} - virtual void SetUp() { + ~BlockErrorTest() override = default; + void SetUp() override { error_block_op_ = GET_PARAM(0); ref_error_block_op_ = GET_PARAM(1); bit_depth_ = GET_PARAM(2); } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: vpx_bit_depth_t bit_depth_; @@ -172,7 +172,7 @@ TEST_P(BlockErrorTest, ExtremeValues) { using std::make_tuple; -#if HAVE_SSE2 +#if HAVE_SSE2 && (CONFIG_VP9_HIGHBITDEPTH || HAVE_X86_ASM) const BlockErrorParam sse2_block_error_tests[] = { #if CONFIG_VP9_HIGHBITDEPTH make_tuple(&vp9_highbd_block_error_sse2, &vp9_highbd_block_error_c, @@ -182,8 +182,10 @@ const BlockErrorParam sse2_block_error_tests[] = { make_tuple(&vp9_highbd_block_error_sse2, &vp9_highbd_block_error_c, VPX_BITS_8), #endif // CONFIG_VP9_HIGHBITDEPTH +#if HAVE_X86_ASM make_tuple(&BlockError8BitWrapper, &BlockError8BitWrapper, VPX_BITS_8) +#endif }; INSTANTIATE_TEST_SUITE_P(SSE2, BlockErrorTest, @@ -197,4 +199,31 @@ INSTANTIATE_TEST_SUITE_P( &BlockError8BitWrapper, VPX_BITS_8))); #endif // HAVE_AVX2 + +#if HAVE_NEON +const BlockErrorParam neon_block_error_tests[] = { +#if CONFIG_VP9_HIGHBITDEPTH + make_tuple(&vp9_highbd_block_error_neon, &vp9_highbd_block_error_c, + VPX_BITS_10), + make_tuple(&vp9_highbd_block_error_neon, &vp9_highbd_block_error_c, + VPX_BITS_12), + make_tuple(&vp9_highbd_block_error_neon, &vp9_highbd_block_error_c, + VPX_BITS_8), +#endif // CONFIG_VP9_HIGHBITDEPTH + make_tuple(&BlockError8BitWrapper, + &BlockError8BitWrapper, VPX_BITS_8) +}; + +INSTANTIATE_TEST_SUITE_P(NEON, BlockErrorTest, + ::testing::ValuesIn(neon_block_error_tests)); +#endif // HAVE_NEON + +#if HAVE_SVE +const BlockErrorParam sve_block_error_tests[] = { make_tuple( + &BlockError8BitWrapper, + &BlockError8BitWrapper, VPX_BITS_8) }; + +INSTANTIATE_TEST_SUITE_P(SVE, BlockErrorTest, + ::testing::ValuesIn(sve_block_error_tests)); +#endif // HAVE_SVE } // namespace diff --git a/libs/libvpx/test/vp9_boolcoder_test.cc b/libs/libvpx/test/vp9_boolcoder_test.cc index 6ba171a000..fbbdb19465 100644 --- a/libs/libvpx/test/vp9_boolcoder_test.cc +++ b/libs/libvpx/test/vp9_boolcoder_test.cc @@ -12,7 +12,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/acm_random.h" #include "vpx/vpx_integer.h" @@ -53,7 +53,7 @@ TEST(VP9, TestBitIO) { ACMRandom bit_rnd(random_seed); vpx_writer bw; uint8_t bw_buffer[kBufferSize]; - vpx_start_encode(&bw, bw_buffer); + vpx_start_encode(&bw, bw_buffer, sizeof(bw_buffer)); int bit = (bit_method == 0) ? 0 : (bit_method == 1) ? 1 : 0; for (int i = 0; i < kBitsToTest; ++i) { @@ -65,7 +65,7 @@ TEST(VP9, TestBitIO) { vpx_write(&bw, bit, static_cast(probas[i])); } - vpx_stop_encode(&bw); + GTEST_ASSERT_EQ(vpx_stop_encode(&bw), 0); // vpx_reader_fill() may read into uninitialized data that // isn't used meaningfully, but may trigger an MSan warning. memset(bw_buffer + bw.pos, 0, sizeof(BD_VALUE) - 1); @@ -90,3 +90,24 @@ TEST(VP9, TestBitIO) { } } } + +TEST(VP9, TestBitIOBufferSize0) { + vpx_writer bw; + uint8_t bw_buffer[1]; + vpx_start_encode(&bw, bw_buffer, 0); + GTEST_ASSERT_EQ(vpx_stop_encode(&bw), -1); +} + +TEST(VP9, TestBitIOBufferSize1) { + vpx_writer bw; + uint8_t bw_buffer[1]; + vpx_start_encode(&bw, bw_buffer, sizeof(bw_buffer)); + GTEST_ASSERT_EQ(vpx_stop_encode(&bw), -1); +} + +TEST(VP9, TestBitIOBufferSize2) { + vpx_writer bw; + uint8_t bw_buffer[2]; + vpx_start_encode(&bw, bw_buffer, sizeof(bw_buffer)); + GTEST_ASSERT_EQ(vpx_stop_encode(&bw), 0); +} diff --git a/libs/libvpx/test/vp9_c_vs_simd_encode.sh b/libs/libvpx/test/vp9_c_vs_simd_encode.sh new file mode 100755 index 0000000000..03843610dc --- /dev/null +++ b/libs/libvpx/test/vp9_c_vs_simd_encode.sh @@ -0,0 +1,420 @@ +#!/bin/sh +## +## Copyright (c) 2023 The WebM project authors. All Rights Reserved. +## +## Use of this source code is governed by a BSD-style license +## that can be found in the LICENSE file in the root of the source +## tree. An additional intellectual property rights grant can be found +## in the file PATENTS. All contributing project authors may +## be found in the AUTHORS file in the root of the source tree. +## +## This script checks the bit exactness between C and SIMD +## implementations of VP9 encoder. +## +. $(dirname $0)/tools_common.sh + +TEST_BITRATES="1600 6400" +PRESETS="good rt" +TEST_CLIPS="yuv_raw_input y4m_360p_10bit_input yuv_480p_raw_input y4m_720p_input" +OUT_FILE_SUFFIX=".ivf" +SCRIPT_DIR=$(dirname "$0") +LIBVPX_SOURCE_DIR=$(cd "${SCRIPT_DIR}/.."; pwd) + +# Clips used in test. +YUV_RAW_INPUT="${LIBVPX_TEST_DATA_PATH}/hantro_collage_w352h288.yuv" +YUV_480P_RAW_INPUT="${LIBVPX_TEST_DATA_PATH}/niklas_640_480_30.yuv" +Y4M_360P_10BIT_INPUT="${LIBVPX_TEST_DATA_PATH}/crowd_run_360p_10_150f.y4m" +Y4M_720P_INPUT="${LIBVPX_TEST_DATA_PATH}/niklas_1280_720_30.y4m" + +# Number of frames to test. +VP9_ENCODE_C_VS_SIMD_TEST_FRAME_LIMIT=20 + +# Create a temporary directory for output files. +if [ -n "${TMPDIR}" ]; then + VPX_TEST_TEMP_ROOT="${TMPDIR}" +elif [ -n "${TEMPDIR}" ]; then + VPX_TEST_TEMP_ROOT="${TEMPDIR}" +else + VPX_TEST_TEMP_ROOT=/tmp +fi + +VPX_TEST_OUTPUT_DIR="${VPX_TEST_TEMP_ROOT}/vpx_test_$$" + +if ! mkdir -p "${VPX_TEST_OUTPUT_DIR}" || \ + [ ! -d "${VPX_TEST_OUTPUT_DIR}" ]; then + echo "${0##*/}: Cannot create output directory, giving up." + echo "${0##*/}: VPX_TEST_OUTPUT_DIR=${VPX_TEST_OUTPUT_DIR}" + exit 1 +fi + +elog() { + echo "$@" 1>&2 +} + +# Echoes path to $1 when it's executable and exists in ${VPX_TEST_OUTPUT_DIR}, +# or an empty string. Caller is responsible for testing the string once the +# function returns. +vp9_enc_tool_path() { + local target="$1" + local tool_path="${VPX_TEST_OUTPUT_DIR}/build_target_${target}/vpxenc" + + if [ ! -x "${tool_path}" ]; then + tool_path="" + fi + echo "${tool_path}" +} + +# Environment check: Make sure input and source directories are available. +vp9_c_vs_simd_enc_verify_environment() { + if [ ! -e "${YUV_RAW_INPUT}" ]; then + elog "libvpx test data must exist in LIBVPX_TEST_DATA_PATH." + return 1 + fi + if [ ! -e "${YUV_480P_RAW_INPUT}" ]; then + elog "libvpx test data must exist in LIBVPX_TEST_DATA_PATH." + return 1 + fi + if [ ! -e "${Y4M_720P_INPUT}" ]; then + elog "libvpx test data must exist in LIBVPX_TEST_DATA_PATH." + return 1 + fi + if [ ! -e "${Y4M_360P_10BIT_INPUT}" ]; then + elog "libvpx test data must exist in LIBVPX_TEST_DATA_PATH." + return 1 + fi + if [ ! -d "$LIBVPX_SOURCE_DIR" ]; then + elog "LIBVPX_SOURCE_DIR does not exist." + return 1 + fi +} + +# This is not needed since tools_common.sh does the same cleanup. +# Keep the code here for our reference. +# cleanup() { +# rm -rf ${VPX_TEST_OUTPUT_DIR} +# } + +# Echo VPX_SIMD_CAPS_MASK for different instruction set architecture. +avx512f() { + echo "0x1FF" +} + +avx2() { + echo "0x0FF" +} + +sse4_1() { + echo "0x03F" +} + +ssse3() { + echo "0x01F" +} + +sse2() { + echo "0x007" +} + +# Echo clip details to be used as input to vpxenc. +yuv_raw_input() { + echo ""${YUV_RAW_INPUT}" + --width=352 + --height=288 + --bit-depth=8 + --profile=0" +} + +yuv_480p_raw_input() { + echo ""${YUV_480P_RAW_INPUT}" + --width=640 + --height=480 + --bit-depth=8 + --profile=0" +} + +y4m_720p_input() { + echo ""${Y4M_720P_INPUT}" + --bit-depth=8 + --profile=0" +} + +y4m_360p_10bit_input() { + echo ""${Y4M_360P_10BIT_INPUT}" + --bit-depth=10 + --profile=2" +} + +has_x86_isa_extn() { + instruction_set=$1 + if ! grep -q "$instruction_set" /proc/cpuinfo; then + # This instruction_set is not supported. + return 1 + fi + # This instruction_set is supported. + return 0 +} + +# Echo good encode params for use with VP9 encoder. +vp9_encode_good_params() { + echo "--codec=vp9 \ + --good \ + --test-decode=fatal \ + --ivf \ + --threads=1 \ + --static-thresh=0 \ + --tile-columns=0 \ + --end-usage=vbr \ + --kf-max-dist=160 \ + --kf-min-dist=0 \ + --lag-in-frames=19 \ + --max-q=63 \ + --min-q=0 \ + --passes=2 \ + --undershoot-pct=100 \ + --overshoot-pct=100 \ + --verbose \ + --auto-alt-ref=1 \ + --drop-frame=0 \ + --bias-pct=50 \ + --minsection-pct=0 \ + --maxsection-pct=2000 \ + --arnr-maxframes=7 \ + --arnr-strength=5 \ + --sharpness=0 \ + --frame-parallel=0" +} + +# Echo realtime encode params for use with VP9 encoder. +vp9_encode_rt_params() { + echo "--codec=vp9 \ + --rt \ + --test-decode=fatal \ + --ivf \ + --threads=1 \ + --static-thresh=0 \ + --tile-columns=0 \ + --tile-rows=0 \ + --end-usage=cbr \ + --kf-max-dist=90000 \ + --lag-in-frames=0 \ + --max-q=58 \ + --min-q=2 \ + --passes=1 \ + --undershoot-pct=50 \ + --overshoot-pct=50 \ + --verbose \ + --row-mt=0 \ + --buf-sz=1000 \ + --buf-initial-sz=500 \ + --buf-optimal-sz=600 \ + --max-intra-rate=300 \ + --resize-allowed=0 \ + --noise-sensitivity=0 \ + --aq-mode=3 \ + --error-resilient=0" +} + +# Configures for the given target in the +# ${VPX_TEST_OUTPUT_DIR}/build_target_${target} directory. +vp9_enc_build() { + local target=$1 + local configure="$2" + local tmp_build_dir=${VPX_TEST_OUTPUT_DIR}/build_target_${target} + mkdir -p "$tmp_build_dir" + local save_dir="$PWD" + cd "$tmp_build_dir" + + echo "Building target: ${target}" + local config_args="--disable-install-docs \ + --enable-unit-tests \ + --enable-debug \ + --enable-postproc \ + --enable-vp9-postproc \ + --enable-vp9-temporal-denoising \ + --enable-vp9-highbitdepth" + + eval "$configure" --target="${target}" "${config_args}" ${devnull} + eval make -j$(nproc) ${devnull} + echo "Done building target: ${target}" + cd "${save_dir}" +} + +compare_enc_output() { + local target=$1 + local cpu=$2 + local clip=$3 + local bitrate=$4 + local preset=$5 + if ! diff -q ${VPX_TEST_OUTPUT_DIR}/Out-generic-gnu-"${clip}"-${preset}-${bitrate}kbps-cpu${cpu}${OUT_FILE_SUFFIX} \ + ${VPX_TEST_OUTPUT_DIR}/Out-${target}-"${clip}"-${preset}-${bitrate}kbps-cpu${cpu}${OUT_FILE_SUFFIX}; then + elog "C vs ${target} encode mismatches for ${clip}, at ${bitrate} kbps, speed ${cpu}, ${preset} preset" + return 1 + fi +} + +vp9_enc_test() { + local encoder="$1" + local target=$2 + if [ -z "$(vp9_enc_tool_path "${target}")" ]; then + elog "vpxenc not found. It must exist in ${VPX_TEST_OUTPUT_DIR}/build_target_${target} path" + return 1 + fi + + local tmp_build_dir=${VPX_TEST_OUTPUT_DIR}/build_target_${target} + local save_dir="$PWD" + cd "$tmp_build_dir" + for preset in ${PRESETS}; do + if [ "${preset}" = "good" ]; then + local max_cpu_used=5 + local test_params=vp9_encode_good_params + elif [ "${preset}" = "rt" ]; then + local max_cpu_used=9 + local test_params=vp9_encode_rt_params + else + elog "Invalid preset" + cd "${save_dir}" + return 1 + fi + + # Enable armv8 test for real-time only + if [ "${preset}" = "good" ] && [ "${target}" = "armv8-linux-gcc" ]; then + continue + fi + + for cpu in $(seq 0 $max_cpu_used); do + for clip in ${TEST_CLIPS}; do + for bitrate in ${TEST_BITRATES}; do + eval "${encoder}" $($clip) $($test_params) \ + "--limit=${VP9_ENCODE_C_VS_SIMD_TEST_FRAME_LIMIT}" \ + "--cpu-used=${cpu}" "--target-bitrate=${bitrate}" "-o" \ + ${VPX_TEST_OUTPUT_DIR}/Out-${target}-"${clip}"-${preset}-${bitrate}kbps-cpu${cpu}${OUT_FILE_SUFFIX} \ + ${devnull} + + if [ "${target}" != "generic-gnu" ]; then + if ! compare_enc_output ${target} $cpu ${clip} $bitrate ${preset}; then + # Find the mismatch + cd "${save_dir}" + return 1 + fi + fi + done + done + done + done + cd "${save_dir}" +} + +vp9_test_generic() { + local configure="$LIBVPX_SOURCE_DIR/configure" + local target="generic-gnu" + + echo "Build for: ${target}" + vp9_enc_build ${target} ${configure} + local encoder="$(vp9_enc_tool_path "${target}")" + vp9_enc_test $encoder "${target}" +} + +# This function encodes VP9 bitstream by enabling SSE2, SSSE3, SSE4_1, AVX2, AVX512f as there are +# no functions with MMX, SSE, SSE3 and AVX specialization. +# The value of environment variable 'VPX_SIMD_CAPS' controls enabling of different instruction +# set extension optimizations. The value of the flag 'VPX_SIMD_CAPS' and the corresponding +# instruction set extension optimization enabled are as follows: +# AVX512 AVX2 AVX SSE4_1 SSSE3 SSE3 SSE2 SSE MMX +# 1 1 1 1 1 1 1 1 1 -> 0x1FF -> Enable AVX512 and lower variants +# 0 1 1 1 1 1 1 1 1 -> 0x0FF -> Enable AVX2 and lower variants +# 0 0 1 1 1 1 1 1 1 -> 0x07F -> Enable AVX and lower variants +# 0 0 0 1 1 1 1 1 1 -> 0x03F -> Enable SSE4_1 and lower variants +# 0 0 0 0 1 1 1 1 1 -> 0x01F -> Enable SSSE3 and lower variants +# 0 0 0 0 0 1 1 1 1 -> 0x00F -> Enable SSE3 and lower variants +# 0 0 0 0 0 0 1 1 1 -> 0x007 -> Enable SSE2 and lower variants +# 0 0 0 0 0 0 0 1 1 -> 0x003 -> Enable SSE and lower variants +# 0 0 0 0 0 0 0 0 1 -> 0x001 -> Enable MMX +## NOTE: In x86_64 platform, it is not possible to enable sse/mmx/c using "VPX_SIMD_CAPS_MASK" as +# all x86_64 platforms implement sse2. +vp9_test_x86() { + local arch=$1 + + if ! uname -m | grep -q "x86"; then + elog "Machine architecture is not x86 or x86_64" + return 0 + fi + + if [ $arch = "x86" ]; then + local target="x86-linux-gcc" + elif [ $arch = "x86_64" ]; then + local target="x86_64-linux-gcc" + fi + + local x86_isa_variants="avx512f avx2 sse4_1 ssse3 sse2" + local configure="$LIBVPX_SOURCE_DIR/configure" + + echo "Build for x86: ${target}" + vp9_enc_build ${target} ${configure} + local encoder="$(vp9_enc_tool_path "${target}")" + for isa in $x86_isa_variants; do + # Note that if has_x86_isa_extn returns 1, it is false, and vice versa. + if ! has_x86_isa_extn $isa; then + echo "${isa} is not supported in this machine" + continue + fi + export VPX_SIMD_CAPS_MASK=$($isa) + if ! vp9_enc_test $encoder ${target}; then + # Find the mismatch + return 1 + fi + unset VPX_SIMD_CAPS_MASK + done +} + +vp9_test_arm() { + local target="armv8-linux-gcc" + local configure="CROSS=aarch64-linux-gnu- $LIBVPX_SOURCE_DIR/configure --extra-cflags=-march=armv8.4-a \ + --extra-cxxflags=-march=armv8.4-a" + echo "Build for arm64: ${target}" + vp9_enc_build ${target} "${configure}" + + local encoder="$(vp9_enc_tool_path "${target}")" + if ! vp9_enc_test "qemu-aarch64 -L /usr/aarch64-linux-gnu ${encoder}" ${target}; then + # Find the mismatch + return 1 + fi +} + +vp9_c_vs_simd_enc_test() { + # Test Generic + vp9_test_generic + + # Test x86 (32 bit) + echo "vp9 test for x86 (32 bit): Started." + if ! vp9_test_x86 "x86"; then + echo "vp9 test for x86 (32 bit): Done, test failed." + return 1 + else + echo "vp9 test for x86 (32 bit): Done, all tests passed." + fi + + # Test x86_64 (64 bit) + if [ "$(eval uname -m)" = "x86_64" ]; then + echo "vp9 test for x86_64 (64 bit): Started." + if ! vp9_test_x86 "x86_64"; then + echo "vp9 test for x86_64 (64 bit): Done, test failed." + return 1 + else + echo "vp9 test for x86_64 (64 bit): Done, all tests passed." + fi + fi + + # Test ARM + echo "vp9_test_arm: Started." + if ! vp9_test_arm; then + echo "vp9 test for arm: Done, test failed." + return 1 + else + echo "vp9 test for arm: Done, all tests passed." + fi +} + +# Setup a trap function to clean up build, and output files after tests complete. +# trap cleanup EXIT + +run_tests vp9_c_vs_simd_enc_verify_environment vp9_c_vs_simd_enc_test diff --git a/libs/libvpx/test/vp9_datarate_test.cc b/libs/libvpx/test/vp9_datarate_test.cc index 9930c754c7..2c90d751e7 100644 --- a/libs/libvpx/test/vp9_datarate_test.cc +++ b/libs/libvpx/test/vp9_datarate_test.cc @@ -8,7 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ #include "./vpx_config.h" -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" +#include "test/acm_random.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" @@ -27,7 +28,7 @@ class DatarateTestVP9 : public ::libvpx_test::EncoderTest { } protected: - virtual ~DatarateTestVP9() {} + ~DatarateTestVP9() override = default; virtual void ResetModel() { last_pts_ = 0; @@ -112,8 +113,8 @@ class DatarateTestVP9 : public ::libvpx_test::EncoderTest { return layer_id; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_); encoder->Control(VP9E_SET_AQ_MODE, aq_mode_); @@ -147,21 +148,23 @@ class DatarateTestVP9 : public ::libvpx_test::EncoderTest { if (video->frame() == 0) { encoder->Control(VP9E_SET_SVC, 1); } - vpx_svc_layer_id_t layer_id; - layer_id.spatial_layer_id = 0; - frame_flags_ = GetFrameFlags(video->frame(), cfg_.ts_number_layers); - layer_id.temporal_layer_id = - SetLayerId(video->frame(), cfg_.ts_number_layers); - layer_id.temporal_layer_id_per_spatial[0] = - SetLayerId(video->frame(), cfg_.ts_number_layers); - encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id); + if (cfg_.temporal_layering_mode == VP9E_TEMPORAL_LAYERING_MODE_BYPASS) { + vpx_svc_layer_id_t layer_id; + frame_flags_ = GetFrameFlags(video->frame(), cfg_.ts_number_layers); + layer_id.spatial_layer_id = 0; + layer_id.temporal_layer_id = + SetLayerId(video->frame(), cfg_.ts_number_layers); + layer_id.temporal_layer_id_per_spatial[0] = + SetLayerId(video->frame(), cfg_.ts_number_layers); + encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id); + } } const vpx_rational_t tb = video->timebase(); timebase_ = static_cast(tb.num) / tb.den; duration_ = 0; } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { // Time since last timestamp = duration. vpx_codec_pts_t duration = pkt->data.frame.pts - last_pts_; @@ -199,7 +202,7 @@ class DatarateTestVP9 : public ::libvpx_test::EncoderTest { ++tot_frame_number_; } - virtual void EndPassHook(void) { + void EndPassHook() override { for (int layer = 0; layer < static_cast(cfg_.ts_number_layers); ++layer) { duration_ = (last_pts_ + 1) * timebase_; @@ -240,7 +243,7 @@ class DatarateTestVP9RealTimeMultiBR DatarateTestVP9RealTimeMultiBR() : DatarateTestVP9(GET_PARAM(0)) {} protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); set_cpu_used_ = GET_PARAM(1); @@ -256,7 +259,7 @@ class DatarateTestVP9LargeVBR DatarateTestVP9LargeVBR() : DatarateTestVP9(GET_PARAM(0)) {} protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); set_cpu_used_ = GET_PARAM(1); @@ -576,10 +579,10 @@ class DatarateTestVP9RealTime : public DatarateTestVP9, public ::libvpx_test::CodecTestWithParam { public: DatarateTestVP9RealTime() : DatarateTestVP9(GET_PARAM(0)) {} - virtual ~DatarateTestVP9RealTime() {} + ~DatarateTestVP9RealTime() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); set_cpu_used_ = GET_PARAM(1); @@ -728,10 +731,10 @@ class DatarateTestVP9RealTimeDeltaQUV public ::libvpx_test::CodecTestWith2Params { public: DatarateTestVP9RealTimeDeltaQUV() : DatarateTestVP9(GET_PARAM(0)) {} - virtual ~DatarateTestVP9RealTimeDeltaQUV() {} + ~DatarateTestVP9RealTimeDeltaQUV() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); set_cpu_used_ = GET_PARAM(1); @@ -776,7 +779,7 @@ class DatarateTestVP9PostEncodeDrop DatarateTestVP9PostEncodeDrop() : DatarateTestVP9(GET_PARAM(0)) {} protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); set_cpu_used_ = GET_PARAM(1); @@ -809,11 +812,140 @@ TEST_P(DatarateTestVP9PostEncodeDrop, PostEncodeDropScreenContent) { << " The datarate for the file is greater than target by too much!"; } +using libvpx_test::ACMRandom; + +class DatarateTestVP9FrameQp + : public DatarateTestVP9, + public ::testing::TestWithParam { + public: + DatarateTestVP9FrameQp() : DatarateTestVP9(GetParam()), frame_(0) {} + ~DatarateTestVP9FrameQp() override = default; + + protected: + void SetUp() override { + InitializeConfig(); + SetMode(::libvpx_test::kRealTime); + ResetModel(); + } + + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { + set_cpu_used_ = 7; + DatarateTestVP9::PreEncodeFrameHook(video, encoder); + frame_qp_ = static_cast(rnd_.RandRange(64)); + encoder->Control(VP9E_SET_QUANTIZER_ONE_PASS, frame_qp_); + frame_++; + } + + void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) override { + int qp = 0; + vpx_svc_layer_id_t layer_id; + if (frame_ >= total_frame_) return; + encoder->Control(VP8E_GET_LAST_QUANTIZER_64, &qp); + ASSERT_EQ(frame_qp_, qp); + encoder->Control(VP9E_GET_SVC_LAYER_ID, &layer_id); + temporal_layer_id_ = layer_id.temporal_layer_id; + } + + void MismatchHook(const vpx_image_t * /*img1*/, + const vpx_image_t * /*img2*/) override { + if (frame_ >= total_frame_) return; + ASSERT_TRUE(cfg_.temporal_layering_mode == + VP9E_TEMPORAL_LAYERING_MODE_0212 && + temporal_layer_id_ == 2); + } + + protected: + int total_frame_; + + private: + ACMRandom rnd_; + int frame_qp_; + int frame_; + int temporal_layer_id_; +}; + +TEST_P(DatarateTestVP9FrameQp, VP9SetFrameQp) { + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_dropframe_thresh = 0; + cfg_.rc_min_quantizer = 0; + cfg_.rc_max_quantizer = 63; + cfg_.rc_end_usage = VPX_CBR; + cfg_.g_lag_in_frames = 0; + + total_frame_ = 400; + ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1, + 0, total_frame_); + ResetModel(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); +} + +TEST_P(DatarateTestVP9FrameQp, VP9SetFrameQp3TemporalLayersBypass) { + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_dropframe_thresh = 0; + cfg_.rc_max_quantizer = 63; + cfg_.rc_min_quantizer = 0; + cfg_.rc_end_usage = VPX_CBR; + cfg_.g_lag_in_frames = 0; + + // 3 Temporal layers, no spatial layers: Framerate decimation (4, 2, 1). + cfg_.ss_number_layers = 1; + cfg_.ts_number_layers = 3; + cfg_.ts_rate_decimator[0] = 4; + cfg_.ts_rate_decimator[1] = 2; + cfg_.ts_rate_decimator[2] = 1; + + cfg_.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS; + cfg_.rc_target_bitrate = 200; + total_frame_ = 400; + ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1, + 0, total_frame_); + ResetModel(); + cfg_.layer_target_bitrate[0] = 40 * cfg_.rc_target_bitrate / 100; + cfg_.layer_target_bitrate[1] = 60 * cfg_.rc_target_bitrate / 100; + cfg_.layer_target_bitrate[2] = cfg_.rc_target_bitrate; + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); +} + +TEST_P(DatarateTestVP9FrameQp, VP9SetFrameQp3TemporalLayersFixedMode) { + cfg_.rc_buf_initial_sz = 500; + cfg_.rc_buf_optimal_sz = 500; + cfg_.rc_buf_sz = 1000; + cfg_.rc_dropframe_thresh = 0; + cfg_.rc_max_quantizer = 63; + cfg_.rc_min_quantizer = 0; + cfg_.rc_end_usage = VPX_CBR; + cfg_.g_lag_in_frames = 0; + + // 3 Temporal layers, no spatial layers: Framerate decimation (4, 2, 1). + cfg_.ss_number_layers = 1; + cfg_.ts_number_layers = 3; + cfg_.ts_rate_decimator[0] = 4; + cfg_.ts_rate_decimator[1] = 2; + cfg_.ts_rate_decimator[2] = 1; + + cfg_.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_0212; + cfg_.rc_target_bitrate = 200; + cfg_.g_error_resilient = 1; + total_frame_ = 400; + ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1, + 0, total_frame_); + ResetModel(); + cfg_.layer_target_bitrate[0] = 40 * cfg_.rc_target_bitrate / 100; + cfg_.layer_target_bitrate[1] = 60 * cfg_.rc_target_bitrate / 100; + cfg_.layer_target_bitrate[2] = cfg_.rc_target_bitrate; + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); +} + #if CONFIG_VP9_TEMPORAL_DENOISING // Params: speed setting. class DatarateTestVP9RealTimeDenoiser : public DatarateTestVP9RealTime { public: - virtual ~DatarateTestVP9RealTimeDenoiser() {} + ~DatarateTestVP9RealTimeDenoiser() override = default; }; // Check basic datarate targeting, for a single bitrate, when denoiser is on. @@ -935,6 +1067,58 @@ TEST_P(DatarateTestVP9RealTimeDenoiser, DenoiserOffOn) { } #endif // CONFIG_VP9_TEMPORAL_DENOISING +class DatarateTestVP9Psnr : public DatarateTestVP9, + public ::libvpx_test::CodecTestWithParam { + protected: + DatarateTestVP9Psnr() : DatarateTestVP9(GET_PARAM(0)) {} + ~DatarateTestVP9Psnr() override = default; + + void SetUp() override { + InitializeConfig(); + cfg_.g_lag_in_frames = 0; + SetMode(libvpx_test::kRealTime); + set_cpu_used_ = 10; + ResetModel(); + frame_flags_ = VPX_EFLAG_CALCULATE_PSNR; + expect_psnr_ = true; + } + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { + DatarateTestVP9::PreEncodeFrameHook(video, encoder); + frame_flags_ ^= VPX_EFLAG_CALCULATE_PSNR; +#if CONFIG_INTERNAL_STATS + // CONFIG_INTERNAL_STATS unconditionally generates PSNR. + expect_psnr_ = true; +#else + expect_psnr_ = (frame_flags_ & VPX_EFLAG_CALCULATE_PSNR) != 0; +#endif // CONFIG_INTERNAL_STATS + if (video->img() == nullptr) { + expect_psnr_ = false; + } + } + void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) override { + libvpx_test::CxDataIterator iter = encoder->GetCxData(); + + bool had_psnr = false; + while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) { + if (pkt->kind == VPX_CODEC_PSNR_PKT) had_psnr = true; + } + + EXPECT_EQ(had_psnr, expect_psnr_); + } + + private: + bool expect_psnr_; +}; + +TEST_P(DatarateTestVP9Psnr, PerFramePsnr) { + ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, + 30, 1, 0, 100); + + ResetModel(); + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); +} + VP9_INSTANTIATE_TEST_SUITE(DatarateTestVP9RealTimeMultiBR, ::testing::Range(5, 10), ::testing::Range(0, 4)); @@ -943,6 +1127,13 @@ VP9_INSTANTIATE_TEST_SUITE(DatarateTestVP9LargeVBR, ::testing::Range(5, 9), VP9_INSTANTIATE_TEST_SUITE(DatarateTestVP9RealTime, ::testing::Range(5, 10)); +#if CONFIG_VP9 +INSTANTIATE_TEST_SUITE_P( + VP9, DatarateTestVP9FrameQp, + ::testing::Values( + static_cast(&libvpx_test::kVP9))); +#endif + VP9_INSTANTIATE_TEST_SUITE(DatarateTestVP9RealTimeDeltaQUV, ::testing::Range(5, 10), ::testing::Values(-5, -10, -15)); @@ -954,4 +1145,7 @@ VP9_INSTANTIATE_TEST_SUITE(DatarateTestVP9PostEncodeDrop, VP9_INSTANTIATE_TEST_SUITE(DatarateTestVP9RealTimeDenoiser, ::testing::Range(5, 10)); #endif + +VP9_INSTANTIATE_TEST_SUITE(DatarateTestVP9Psnr, + ::testing::Values(::libvpx_test::kRealTime)); } // namespace diff --git a/libs/libvpx/test/vp9_decrypt_test.cc b/libs/libvpx/test/vp9_decrypt_test.cc index 1874d23117..558ee70366 100644 --- a/libs/libvpx/test/vp9_decrypt_test.cc +++ b/libs/libvpx/test/vp9_decrypt_test.cc @@ -12,7 +12,7 @@ #include #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/ivf_video_source.h" diff --git a/libs/libvpx/test/vp9_denoiser_test.cc b/libs/libvpx/test/vp9_denoiser_test.cc index d884b7eb92..bc5612ea47 100644 --- a/libs/libvpx/test/vp9_denoiser_test.cc +++ b/libs/libvpx/test/vp9_denoiser_test.cc @@ -13,7 +13,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/acm_random.h" #include "test/clear_system_state.h" #include "test/register_state_check.h" @@ -24,6 +24,7 @@ #include "vp9/common/vp9_reconinter.h" #include "vp9/encoder/vp9_context_tree.h" #include "vp9/encoder/vp9_denoiser.h" +#include "vpx_config.h" using libvpx_test::ACMRandom; @@ -31,22 +32,22 @@ namespace { const int kNumPixels = 64 * 64; -typedef int (*Vp9DenoiserFilterFunc)(const uint8_t *sig, int sig_stride, - const uint8_t *mc_avg, int mc_avg_stride, - uint8_t *avg, int avg_stride, - int increase_denoising, BLOCK_SIZE bs, - int motion_magnitude); -typedef std::tuple VP9DenoiserTestParam; +using Vp9DenoiserFilterFunc = int (*)(const uint8_t *sig, int sig_stride, + const uint8_t *mc_avg, int mc_avg_stride, + uint8_t *avg, int avg_stride, + int increase_denoising, BLOCK_SIZE bs, + int motion_magnitude); +using VP9DenoiserTestParam = std::tuple; class VP9DenoiserTest : public ::testing::Test, public ::testing::WithParamInterface { public: - virtual ~VP9DenoiserTest() {} + ~VP9DenoiserTest() override = default; - virtual void SetUp() { bs_ = GET_PARAM(1); } + void SetUp() override { bs_ = GET_PARAM(1); } - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: BLOCK_SIZE bs_; diff --git a/libs/libvpx/test/vp9_encoder_parms_get_to_decoder.cc b/libs/libvpx/test/vp9_encoder_parms_get_to_decoder.cc index ce2198c592..880fe9b0fc 100644 --- a/libs/libvpx/test/vp9_encoder_parms_get_to_decoder.cc +++ b/libs/libvpx/test/vp9_encoder_parms_get_to_decoder.cc @@ -10,7 +10,7 @@ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" @@ -62,20 +62,24 @@ class VpxEncoderParmsGetToDecoder VpxEncoderParmsGetToDecoder() : EncoderTest(GET_PARAM(0)), encode_parms(GET_PARAM(1)) {} - virtual ~VpxEncoderParmsGetToDecoder() {} + ~VpxEncoderParmsGetToDecoder() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); +#if CONFIG_REALTIME_ONLY + SetMode(::libvpx_test::kRealTime); +#else SetMode(::libvpx_test::kTwoPassGood); cfg_.g_lag_in_frames = 25; +#endif cfg_.g_error_resilient = encode_parms.error_resilient; dec_cfg_.threads = 4; test_video_ = GET_PARAM(2); cfg_.rc_target_bitrate = test_video_.bitrate; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP9E_SET_COLOR_SPACE, encode_parms.cs); encoder->Control(VP9E_SET_COLOR_RANGE, encode_parms.color_range); @@ -95,9 +99,9 @@ class VpxEncoderParmsGetToDecoder } } - virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec, - const libvpx_test::VideoSource & /*video*/, - libvpx_test::Decoder *decoder) { + bool HandleDecodeResult(const vpx_codec_err_t res_dec, + const libvpx_test::VideoSource & /*video*/, + libvpx_test::Decoder *decoder) override { vpx_codec_ctx_t *const vp9_decoder = decoder->GetDecoder(); vpx_codec_alg_priv_t *const priv = reinterpret_cast(vp9_decoder->priv); diff --git a/libs/libvpx/test/vp9_end_to_end_test.cc b/libs/libvpx/test/vp9_end_to_end_test.cc index 7a85db26a4..1341f4227e 100644 --- a/libs/libvpx/test/vp9_end_to_end_test.cc +++ b/libs/libvpx/test/vp9_end_to_end_test.cc @@ -10,7 +10,7 @@ #include "memory" -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" @@ -18,6 +18,7 @@ #include "test/util.h" #include "test/y4m_video_source.h" #include "test/yuv_video_source.h" +#include "vpx_config.h" namespace { @@ -34,13 +35,13 @@ const double kPsnrThreshold[][5] = { { 28.4, 31.0, 31.0, 31.0, 31.0 }, { 27.5, 30.0, 30.0, 30.0, 30.0 }, }; -typedef struct { +struct TestVideoParam { const char *filename; unsigned int input_bit_depth; vpx_img_fmt fmt; vpx_bit_depth_t bit_depth; unsigned int profile; -} TestVideoParam; +}; const TestVideoParam kTestVectors[] = { { "park_joy_90p_8_420.y4m", 8, VPX_IMG_FMT_I420, VPX_BITS_8, 0 }, @@ -63,9 +64,17 @@ const TestVideoParam kTestVectorsNv12[] = { { "hantro_collage_w352h288_nv12.yuv", 8, VPX_IMG_FMT_NV12, VPX_BITS_8, 0 }, }; +#if !CONFIG_REALTIME_ONLY +const TestVideoParam k4x2VideoTestVectors[] = { + { "4x2.y4m", 8, VPX_IMG_FMT_I420, VPX_BITS_8, 0 }, +}; +#endif + // Encoding modes tested const libvpx_test::TestMode kEncodingModeVectors[] = { +#if !CONFIG_REALTIME_ONLY ::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood, +#endif ::libvpx_test::kRealTime }; @@ -89,9 +98,9 @@ class EndToEndTestAdaptiveRDThresh : EncoderTest(GET_PARAM(0)), cpu_used_start_(GET_PARAM(1)), cpu_used_end_(GET_PARAM(2)) {} - virtual ~EndToEndTestAdaptiveRDThresh() {} + ~EndToEndTestAdaptiveRDThresh() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); cfg_.g_lag_in_frames = 0; @@ -102,8 +111,8 @@ class EndToEndTestAdaptiveRDThresh dec_cfg_.threads = 4; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, cpu_used_start_); encoder->Control(VP9E_SET_ROW_MT, 1); @@ -131,9 +140,15 @@ class EndToEndTestLarge denoiser_on_ = 0; } - virtual ~EndToEndTestLarge() {} + ~EndToEndTestLarge() override = default; - virtual void SetUp() { + void SetUp() override { + if (encoding_mode_ == ::libvpx_test::kRealTime && cpu_used_ < 5) { + // For realtime mode the speed setting < 5 gets + // clamped to 5, so skip it as 5 is already checked, + // see kCpuUsedVectors[]. + GTEST_SKIP() << "For realtime skip speeds < 5."; + } InitializeConfig(); SetMode(encoding_mode_); if (encoding_mode_ != ::libvpx_test::kRealTime) { @@ -149,18 +164,18 @@ class EndToEndTestLarge dec_cfg_.threads = 4; } - virtual void BeginPassHook(unsigned int) { + void BeginPassHook(unsigned int) override { psnr_ = 0.0; nframes_ = 0; } - virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { + void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) override { psnr_ += pkt->data.psnr.psnr[0]; nframes_++; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1); encoder->Control(VP9E_SET_TILE_COLUMNS, 4); @@ -207,9 +222,9 @@ class EndToEndTestLoopFilterThreading EndToEndTestLoopFilterThreading() : EncoderTest(GET_PARAM(0)), use_loop_filter_opt_(GET_PARAM(1)) {} - virtual ~EndToEndTestLoopFilterThreading() {} + ~EndToEndTestLoopFilterThreading() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); cfg_.g_threads = 2; @@ -221,16 +236,16 @@ class EndToEndTestLoopFilterThreading dec_cfg_.threads = GET_PARAM(2); } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, 8); } encoder->Control(VP9E_SET_TILE_COLUMNS, 4 - video->frame() % 5); } - virtual void PreDecodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Decoder *decoder) { + void PreDecodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Decoder *decoder) override { if (video->frame() == 0) { decoder->Control(VP9D_SET_LOOP_FILTER_OPT, use_loop_filter_opt_ ? 1 : 0); } @@ -262,6 +277,26 @@ TEST_P(EndToEndNV12, EndtoEndNV12Test) { ASSERT_NO_FATAL_FAILURE(RunLoop(video.get())); } +#if !CONFIG_REALTIME_ONLY +class EndToEnd4x2Video : public EndToEndTestLarge {}; + +TEST_P(EndToEnd4x2Video, EndtoEnd4x2VideoTest) { + cfg_.rc_target_bitrate = kBitrate; + cfg_.g_error_resilient = 0; + cfg_.g_profile = test_video_param_.profile; + cfg_.g_input_bit_depth = test_video_param_.input_bit_depth; + cfg_.g_bit_depth = test_video_param_.bit_depth; + + std::unique_ptr video; + + video.reset( + new libvpx_test::Y4mVideoSource(test_video_param_.filename, 0, 200)); + ASSERT_NE(video.get(), nullptr); + + ASSERT_NO_FATAL_FAILURE(RunLoop(video.get())); +} +#endif // !CONFIG_REALTIME_ONLY + TEST_P(EndToEndTestLarge, EndtoEndPSNRTest) { cfg_.rc_target_bitrate = kBitrate; cfg_.g_error_resilient = 0; @@ -344,6 +379,13 @@ VP9_INSTANTIATE_TEST_SUITE(EndToEndNV12, ::testing::ValuesIn(kTestVectorsNv12), ::testing::Values(6, 7, 8)); +#if !CONFIG_REALTIME_ONLY +VP9_INSTANTIATE_TEST_SUITE(EndToEnd4x2Video, + ::testing::Values(::libvpx_test::kTwoPassGood), + ::testing::ValuesIn(k4x2VideoTestVectors), + ::testing::Values(0, 1)); +#endif + VP9_INSTANTIATE_TEST_SUITE(EndToEndTestAdaptiveRDThresh, ::testing::Values(5, 6, 7), ::testing::Values(8, 9)); diff --git a/libs/libvpx/test/vp9_entropy_test.cc b/libs/libvpx/test/vp9_entropy_test.cc new file mode 100644 index 0000000000..d6fb65e5bb --- /dev/null +++ b/libs/libvpx/test/vp9_entropy_test.cc @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2026 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "gtest/gtest.h" +#include "vp9/common/vp9_entropy.h" + +namespace { + +TEST(VP9Entropy, PtEnergyClassValuesInBound) { + for (int i = 0; i < ENTROPY_TOKENS; ++i) { + EXPECT_LE(vp9_pt_energy_class[i], MAX_ENERGY_CLASS) + << "vp9_pt_energy_class[" << i << "]"; + EXPECT_GE(vp9_pt_energy_class[i], 0) << "vp9_pt_energy_class[" << i << "]"; + } +} + +} // namespace diff --git a/libs/libvpx/test/vp9_ethread_test.cc b/libs/libvpx/test/vp9_ethread_test.cc index 238366cb60..9e366eb366 100644 --- a/libs/libvpx/test/vp9_ethread_test.cc +++ b/libs/libvpx/test/vp9_ethread_test.cc @@ -10,23 +10,24 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/md5_helper.h" #include "test/util.h" #include "test/y4m_video_source.h" #include "vp9/encoder/vp9_firstpass.h" +#include "vpx_config.h" namespace { // FIRSTPASS_STATS struct: // { -// 25 double members; +// 26 double members; // 1 int64_t member; // } // Whenever FIRSTPASS_STATS struct is modified, the following constants need to // be revisited. -const int kDbl = 25; +const int kDbl = 26; const int kInt = 1; const size_t kFirstPassStatsSz = kDbl * sizeof(double) + kInt * sizeof(int64_t); @@ -44,9 +45,9 @@ class VPxFirstPassEncoderThreadTest firstpass_stats_.buf = nullptr; firstpass_stats_.sz = 0; } - virtual ~VPxFirstPassEncoderThreadTest() { free(firstpass_stats_.buf); } + ~VPxFirstPassEncoderThreadTest() override { free(firstpass_stats_.buf); } - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(encoding_mode_); @@ -57,19 +58,19 @@ class VPxFirstPassEncoderThreadTest cfg_.rc_min_quantizer = 0; } - virtual void BeginPassHook(unsigned int /*pass*/) { + void BeginPassHook(unsigned int /*pass*/) override { encoder_initialized_ = false; abort_ = false; } - virtual void EndPassHook() { + void EndPassHook() override { // For first pass stats test, only run first pass encoder. if (first_pass_only_ && cfg_.g_pass == VPX_RC_FIRST_PASS) abort_ |= first_pass_only_; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource * /*video*/, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource * /*video*/, + ::libvpx_test::Encoder *encoder) override { if (!encoder_initialized_) { // Encode in 2-pass mode. encoder->Control(VP9E_SET_TILE_COLUMNS, tiles_); @@ -87,7 +88,7 @@ class VPxFirstPassEncoderThreadTest } } - virtual void StatsPktHook(const vpx_codec_cx_pkt_t *pkt) { + void StatsPktHook(const vpx_codec_cx_pkt_t *pkt) override { const uint8_t *const pkt_buf = reinterpret_cast(pkt->data.twopass_stats.buf); const size_t pkt_size = pkt->data.twopass_stats.sz; @@ -113,6 +114,7 @@ class VPxFirstPassEncoderThreadTest vpx_fixed_buf_t firstpass_stats_; }; +#if !CONFIG_REALTIME_ONLY static void compare_fp_stats(vpx_fixed_buf_t *fp_stats, double factor) { // fp_stats consists of 2 set of first pass encoding stats. These 2 set of // stats are compared to check if the stats match or at least are very close. @@ -166,8 +168,12 @@ static void compare_fp_stats_md5(vpx_fixed_buf_t *fp_stats) { memset((uint8_t *)fp_stats->buf, 0, fp_stats->sz); fp_stats->sz = 0; } +#endif // !CONFIG_REALTIME_ONLY TEST_P(VPxFirstPassEncoderThreadTest, FirstPassStatsTest) { +#if CONFIG_REALTIME_ONLY + GTEST_SKIP(); +#else ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60); first_pass_only_ = true; @@ -185,7 +191,7 @@ TEST_P(VPxFirstPassEncoderThreadTest, FirstPassStatsTest) { ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); // Compare to check if using or not using row-mt generates close stats. - ASSERT_NO_FATAL_FAILURE(compare_fp_stats(&firstpass_stats_, 1000.0)); + ASSERT_NO_FATAL_FAILURE(compare_fp_stats(&firstpass_stats_, 400.0)); // Test single thread vs multiple threads row_mt_mode_ = 1; @@ -199,7 +205,7 @@ TEST_P(VPxFirstPassEncoderThreadTest, FirstPassStatsTest) { ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); // Compare to check if single-thread and multi-thread stats are close enough. - ASSERT_NO_FATAL_FAILURE(compare_fp_stats(&firstpass_stats_, 1000.0)); + ASSERT_NO_FATAL_FAILURE(compare_fp_stats(&firstpass_stats_, 400.0)); // Bit exact test in row_mt mode. // When row_mt_mode_=1 and using >1 threads, the encoder generates bit exact @@ -216,6 +222,7 @@ TEST_P(VPxFirstPassEncoderThreadTest, FirstPassStatsTest) { // Compare to check if stats match with row-mt=0/1. compare_fp_stats_md5(&firstpass_stats_); +#endif // CONFIG_REALTIME_ONLY } class VPxEncoderThreadTest @@ -233,9 +240,9 @@ class VPxEncoderThreadTest psnr_ = 0.0; nframes_ = 0; } - virtual ~VPxEncoderThreadTest() {} + ~VPxEncoderThreadTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(encoding_mode_); @@ -252,14 +259,14 @@ class VPxEncoderThreadTest cfg_.rc_min_quantizer = 0; } - virtual void BeginPassHook(unsigned int /*pass*/) { + void BeginPassHook(unsigned int /*pass*/) override { encoder_initialized_ = false; psnr_ = 0.0; nframes_ = 0; } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource * /*video*/, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource * /*video*/, + ::libvpx_test::Encoder *encoder) override { if (!encoder_initialized_) { // Encode 4 column tiles. encoder->Control(VP9E_SET_TILE_COLUMNS, tiles_); @@ -280,21 +287,21 @@ class VPxEncoderThreadTest } } - virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { + void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) override { psnr_ += pkt->data.psnr.psnr[0]; nframes_++; } - virtual void DecompressedFrameHook(const vpx_image_t &img, - vpx_codec_pts_t /*pts*/) { + void DecompressedFrameHook(const vpx_image_t &img, + vpx_codec_pts_t /*pts*/) override { ::libvpx_test::MD5 md5_res; md5_res.Add(&img); md5_.push_back(md5_res.Get()); } - virtual bool HandleDecodeResult(const vpx_codec_err_t res, - const libvpx_test::VideoSource & /*video*/, - libvpx_test::Decoder * /*decoder*/) { + bool HandleDecodeResult(const vpx_codec_err_t res, + const libvpx_test::VideoSource & /*video*/, + libvpx_test::Decoder * /*decoder*/) override { if (res != VPX_CODEC_OK) { EXPECT_EQ(VPX_CODEC_OK, res); return false; @@ -399,17 +406,22 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values(::libvpx_test::kTwoPassGood), ::testing::Range(0, 4))); // cpu_used -// Split this into two instantiations so that we can distinguish -// between very slow runs ( ie cpu_speed 0 ) vs ones that can be +constexpr libvpx_test::TestMode kOnePassTestModes[] = { + libvpx_test::kRealTime, +#if !CONFIG_REALTIME_ONLY + libvpx_test::kOnePassGood, +#endif +}; + +// Split this into multiple instantiations so that we can distinguish +// between very slow runs ( i.e., cpu_speed 0 ) vs ones that can be // run nightly by adding Large to the title. INSTANTIATE_TEST_SUITE_P( VP9, VPxEncoderThreadTest, ::testing::Combine( ::testing::Values( static_cast(&libvpx_test::kVP9)), - ::testing::Values(::libvpx_test::kTwoPassGood, - ::libvpx_test::kOnePassGood, - ::libvpx_test::kRealTime), + ::testing::ValuesIn(kOnePassTestModes), ::testing::Range(3, 10), // cpu_used ::testing::Range(0, 3), // tile_columns ::testing::Range(2, 5))); // threads @@ -419,11 +431,21 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Combine( ::testing::Values( static_cast(&libvpx_test::kVP9)), - ::testing::Values(::libvpx_test::kTwoPassGood, - ::libvpx_test::kOnePassGood, - ::libvpx_test::kRealTime), + ::testing::ValuesIn(kOnePassTestModes), ::testing::Range(0, 3), // cpu_used ::testing::Range(0, 3), // tile_columns ::testing::Range(2, 5))); // threads +#if !CONFIG_REALTIME_ONLY +INSTANTIATE_TEST_SUITE_P( + VP9LargeBest, VPxEncoderThreadTest, + ::testing::Combine( + ::testing::Values( + static_cast(&libvpx_test::kVP9)), + ::testing::Values(libvpx_test::kOnePassBest), + ::testing::Range(0, 10), // cpu_used + ::testing::Range(0, 3), // tile_columns + ::testing::Range(2, 5))); // threads +#endif + } // namespace diff --git a/libs/libvpx/test/vp9_ext_ratectrl_test.cc b/libs/libvpx/test/vp9_ext_ratectrl_test.cc index 60a350b84e..7307b498f1 100644 --- a/libs/libvpx/test/vp9_ext_ratectrl_test.cc +++ b/libs/libvpx/test/vp9_ext_ratectrl_test.cc @@ -10,193 +10,316 @@ #include #include +#include +#include "./vpx_config.h" + +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/util.h" #include "test/yuv_video_source.h" -#include "third_party/googletest/src/include/gtest/gtest.h" +#if CONFIG_VP9_DECODER +#include "vpx/vp8dx.h" +#endif +#include "vpx/vpx_codec.h" +#include "vpx/vpx_encoder.h" #include "vpx/vpx_ext_ratectrl.h" +#include "vpx/vpx_image.h" +#include "vpx/vpx_tpl.h" +#include "vpx_dsp/vpx_dsp_common.h" namespace { -constexpr int kModelMagicNumber = 51396; -constexpr uintptr_t PrivMagicNumber = 5566; -constexpr int kFrameNum = 5; -constexpr int kLosslessCodingIndex = 2; +constexpr int kShowFrameCount = 10; +constexpr int kKeyframeQp = 10; +constexpr int kLeafQp = 40; +constexpr int kArfQp = 15; -struct ToyRateCtrl { - int magic_number; - int coding_index; +// Simple external rate controller for testing. +class RateControllerForTest { + public: + explicit RateControllerForTest(bool use_alt_ref) + : current_gop_(-1), use_alt_ref_(use_alt_ref) {} + ~RateControllerForTest() {} + + void StartNextGop() { ++current_gop_; } + + vpx_rc_gop_decision_t GetCurrentGop() const { + vpx_rc_gop_decision_t gop_decision; + if (current_gop_ == 0 && !use_alt_ref_) { + // A single GOP without ARF that covers all the frames. + gop_decision.use_key_frame = 1; + gop_decision.use_alt_ref = 0; + gop_decision.gop_coding_frames = kShowFrameCount; + // key frame + gop_decision.update_type[0] = VPX_RC_KF_UPDATE; + gop_decision.update_ref_index[0] = 0; + gop_decision.ref_frame_list[0] = get_kf_ref_frame(); + // leafs + for (int i = 1; i < gop_decision.gop_coding_frames; ++i) { + gop_decision.update_type[i] = VPX_RC_LF_UPDATE; + gop_decision.update_ref_index[i] = 2; + gop_decision.ref_frame_list[i] = get_no_arf_leaf_ref_frame(i); + } + } else if (current_gop_ == 0) { + gop_decision.use_key_frame = 1; + gop_decision.use_alt_ref = 1; + gop_decision.gop_coding_frames = + kShowFrameCount - 1 + gop_decision.use_alt_ref; + // key frame + gop_decision.update_type[0] = VPX_RC_KF_UPDATE; + gop_decision.update_ref_index[0] = 0; + gop_decision.ref_frame_list[0] = get_kf_ref_frame(); + // arf + gop_decision.update_type[1] = VPX_RC_ARF_UPDATE; + gop_decision.update_ref_index[1] = 1; + gop_decision.ref_frame_list[1] = get_arf_ref_frame(); + // leafs + for (int i = 2; i < gop_decision.gop_coding_frames; ++i) { + gop_decision.update_type[i] = VPX_RC_LF_UPDATE; + gop_decision.update_ref_index[i] = 2; + gop_decision.ref_frame_list[i] = get_leaf_ref_frame(i); + } + } else { + // Pad a overlay-only GOP as the last GOP. + EXPECT_EQ(current_gop_, 1); + gop_decision.use_key_frame = 0; + gop_decision.use_alt_ref = 0; + gop_decision.gop_coding_frames = 1; + + gop_decision.update_type[0] = VPX_RC_OVERLAY_UPDATE; + gop_decision.update_ref_index[0] = 1; + gop_decision.ref_frame_list[0] = get_ovl_ref_frame(); + } + return gop_decision; + } + + int CalculateFrameDecision(int frame_index) { + if (current_gop_ == 0 && frame_index == 0) { + // Key frame, first frame in the first GOP. + return kKeyframeQp; + } else if (frame_index == 1) { + // ARF, we always use ARF for this test. + return kArfQp; + } else { + return kLeafQp; + } + } + + private: + vpx_rc_ref_frame_t get_kf_ref_frame() const { + vpx_rc_ref_frame_t ref_frame; + ref_frame.index[0] = -1; + ref_frame.index[1] = -1; + ref_frame.index[2] = -1; + ref_frame.name[0] = VPX_RC_INVALID_REF_FRAME; + ref_frame.name[1] = VPX_RC_INVALID_REF_FRAME; + ref_frame.name[2] = VPX_RC_INVALID_REF_FRAME; + return ref_frame; + } + vpx_rc_ref_frame_t get_arf_ref_frame() const { + vpx_rc_ref_frame_t ref_frame; + ref_frame.index[0] = 0; + ref_frame.index[1] = -1; + ref_frame.index[2] = -1; + ref_frame.name[0] = VPX_RC_GOLDEN_FRAME; + ref_frame.name[1] = VPX_RC_INVALID_REF_FRAME; + ref_frame.name[2] = VPX_RC_INVALID_REF_FRAME; + return ref_frame; + } + vpx_rc_ref_frame_t get_leaf_ref_frame(int count) const { + vpx_rc_ref_frame_t ref_frame; + ref_frame.index[0] = 0; + ref_frame.index[1] = 1; + ref_frame.index[2] = count > 2 ? 2 : -1; + ref_frame.name[0] = VPX_RC_GOLDEN_FRAME; + ref_frame.name[1] = VPX_RC_ALTREF_FRAME; + ref_frame.name[2] = + count > 2 ? VPX_RC_LAST_FRAME : VPX_RC_INVALID_REF_FRAME; + return ref_frame; + } + vpx_rc_ref_frame_t get_no_arf_leaf_ref_frame(int count) const { + vpx_rc_ref_frame_t ref_frame; + ref_frame.index[0] = 0; + ref_frame.index[1] = count > 1 ? 2 : -1; + ref_frame.index[2] = -1; + ref_frame.name[0] = VPX_RC_GOLDEN_FRAME; + ref_frame.name[1] = + count > 1 ? VPX_RC_LAST_FRAME : VPX_RC_INVALID_REF_FRAME; + ref_frame.name[2] = VPX_RC_INVALID_REF_FRAME; + return ref_frame; + } + vpx_rc_ref_frame_t get_ovl_ref_frame() const { + vpx_rc_ref_frame_t ref_frame; + ref_frame.index[0] = 1; + ref_frame.index[1] = -1; + ref_frame.index[2] = -1; + ref_frame.name[0] = VPX_RC_ALTREF_FRAME; + ref_frame.name[1] = VPX_RC_INVALID_REF_FRAME; + ref_frame.name[2] = VPX_RC_INVALID_REF_FRAME; + return ref_frame; + } + + int current_gop_; + const bool use_alt_ref_; }; -vpx_rc_status_t rc_create_model(void *priv, - const vpx_rc_config_t *ratectrl_config, - vpx_rc_model_t *rate_ctrl_model_pt) { - ToyRateCtrl *toy_rate_ctrl = new (std::nothrow) ToyRateCtrl; - EXPECT_NE(toy_rate_ctrl, nullptr); - toy_rate_ctrl->magic_number = kModelMagicNumber; - toy_rate_ctrl->coding_index = -1; - *rate_ctrl_model_pt = toy_rate_ctrl; - EXPECT_EQ(priv, reinterpret_cast(PrivMagicNumber)); - EXPECT_EQ(ratectrl_config->frame_width, 352); - EXPECT_EQ(ratectrl_config->frame_height, 288); - EXPECT_EQ(ratectrl_config->show_frame_count, kFrameNum); - EXPECT_EQ(ratectrl_config->target_bitrate_kbps, 24000); - EXPECT_EQ(ratectrl_config->frame_rate_num, 30); - EXPECT_EQ(ratectrl_config->frame_rate_den, 1); +// Callbacks used in this test. +// |priv| points to a bool that indicates whether the first GOP uses ARF. +vpx_rc_status_t rc_test_create_model( + void *priv, const vpx_rc_config_t * /*ratectrl_config*/, + vpx_rc_model_t *rate_ctrl_model_ptr) { + const bool use_alt_ref = *static_cast(priv); + std::unique_ptr test_controller( + new RateControllerForTest(use_alt_ref)); + *rate_ctrl_model_ptr = test_controller.release(); return VPX_RC_OK; } -vpx_rc_status_t rc_send_firstpass_stats( - vpx_rc_model_t rate_ctrl_model, +vpx_rc_status_t rc_test_send_firstpass_stats( + vpx_rc_model_t /*rate_ctrl_model*/, const vpx_rc_firstpass_stats_t *first_pass_stats) { - const ToyRateCtrl *toy_rate_ctrl = - static_cast(rate_ctrl_model); - EXPECT_EQ(toy_rate_ctrl->magic_number, kModelMagicNumber); - EXPECT_EQ(first_pass_stats->num_frames, kFrameNum); + EXPECT_EQ(first_pass_stats->num_frames, kShowFrameCount); for (int i = 0; i < first_pass_stats->num_frames; ++i) { EXPECT_DOUBLE_EQ(first_pass_stats->frame_stats[i].frame, i); } return VPX_RC_OK; } -vpx_rc_status_t rc_get_encodeframe_decision( - vpx_rc_model_t rate_ctrl_model, - const vpx_rc_encodeframe_info_t *encode_frame_info, - vpx_rc_encodeframe_decision_t *frame_decision) { - ToyRateCtrl *toy_rate_ctrl = static_cast(rate_ctrl_model); - toy_rate_ctrl->coding_index += 1; +vpx_rc_status_t rc_test_send_tpl_gop_stats( + vpx_rc_model_t /*rate_ctrl_model*/, const VpxTplGopStats *tpl_gop_stats) { + EXPECT_GT(tpl_gop_stats->size, 0); - EXPECT_EQ(toy_rate_ctrl->magic_number, kModelMagicNumber); - - EXPECT_LT(encode_frame_info->show_index, kFrameNum); - EXPECT_EQ(encode_frame_info->coding_index, toy_rate_ctrl->coding_index); - - if (encode_frame_info->coding_index == 0) { - EXPECT_EQ(encode_frame_info->show_index, 0); - EXPECT_EQ(encode_frame_info->gop_index, 0); - EXPECT_EQ(encode_frame_info->frame_type, 0 /*kFrameTypeKey*/); - EXPECT_EQ(encode_frame_info->ref_frame_valid_list[0], - 0); // kRefFrameTypeLast - EXPECT_EQ(encode_frame_info->ref_frame_valid_list[1], - 0); // kRefFrameTypePast - EXPECT_EQ(encode_frame_info->ref_frame_valid_list[2], - 0); // kRefFrameTypeFuture + for (int i = 0; i < tpl_gop_stats->size; ++i) { + EXPECT_GT(tpl_gop_stats->frame_stats_list[i].num_blocks, 0); } - - if (encode_frame_info->coding_index == 1) { - EXPECT_EQ(encode_frame_info->show_index, 4); - EXPECT_EQ(encode_frame_info->gop_index, 1); - EXPECT_EQ(encode_frame_info->frame_type, 2 /*kFrameTypeAltRef*/); - EXPECT_EQ(encode_frame_info->ref_frame_valid_list[0], - 1); // kRefFrameTypeLast - EXPECT_EQ(encode_frame_info->ref_frame_valid_list[1], - 0); // kRefFrameTypePast - EXPECT_EQ(encode_frame_info->ref_frame_valid_list[2], - 0); // kRefFrameTypeFuture - EXPECT_EQ(encode_frame_info->ref_frame_coding_indexes[0], - 0); // kRefFrameTypeLast - } - - if (encode_frame_info->coding_index >= 2 && - encode_frame_info->coding_index < 5) { - // In the first group of pictures, coding_index and gop_index are equal. - EXPECT_EQ(encode_frame_info->gop_index, encode_frame_info->coding_index); - EXPECT_EQ(encode_frame_info->frame_type, 1 /*kFrameTypeInter*/); - } - - if (encode_frame_info->coding_index == 5) { - EXPECT_EQ(encode_frame_info->show_index, 4); - EXPECT_EQ(encode_frame_info->gop_index, 0); - EXPECT_EQ(encode_frame_info->frame_type, 3 /*kFrameTypeOverlay*/); - EXPECT_EQ(encode_frame_info->ref_frame_valid_list[0], - 1); // kRefFrameTypeLast - EXPECT_EQ(encode_frame_info->ref_frame_valid_list[1], - 1); // kRefFrameTypePast - EXPECT_EQ(encode_frame_info->ref_frame_valid_list[2], - 1); // kRefFrameTypeFuture - EXPECT_EQ(encode_frame_info->ref_frame_coding_indexes[0], - 4); // kRefFrameTypeLast - EXPECT_EQ(encode_frame_info->ref_frame_coding_indexes[1], - 0); // kRefFrameTypePast - EXPECT_EQ(encode_frame_info->ref_frame_coding_indexes[2], - 1); // kRefFrameTypeFuture - } - if (encode_frame_info->coding_index == kLosslessCodingIndex) { - // We should get sse == 0 at rc_update_encodeframe_result() - frame_decision->q_index = 0; - } else { - frame_decision->q_index = 100; - } - frame_decision->max_frame_size = 0; return VPX_RC_OK; } -vpx_rc_status_t rc_update_encodeframe_result( - vpx_rc_model_t rate_ctrl_model, - const vpx_rc_encodeframe_result_t *encode_frame_result) { - const ToyRateCtrl *toy_rate_ctrl = - static_cast(rate_ctrl_model); - EXPECT_EQ(toy_rate_ctrl->magic_number, kModelMagicNumber); +vpx_rc_status_t rc_test_get_encodeframe_decision( + vpx_rc_model_t rate_ctrl_model, const int frame_gop_index, + vpx_rc_encodeframe_decision_t *frame_decision) { + RateControllerForTest *test_controller = + static_cast(rate_ctrl_model); + frame_decision->q_index = + test_controller->CalculateFrameDecision(frame_gop_index); + frame_decision->rdmult = + frame_decision->q_index * frame_decision->q_index / 2; + frame_decision->delta_q_uv = 0; + return VPX_RC_OK; +} - const int64_t ref_pixel_count = 352 * 288 * 3 / 2; - EXPECT_EQ(encode_frame_result->pixel_count, ref_pixel_count); - if (toy_rate_ctrl->coding_index == kLosslessCodingIndex) { - EXPECT_EQ(encode_frame_result->sse, 0); - } - if (toy_rate_ctrl->coding_index == kLosslessCodingIndex) { - EXPECT_EQ(encode_frame_result->actual_encoding_qindex, 0); - } else { - EXPECT_EQ(encode_frame_result->actual_encoding_qindex, 100); - } +vpx_rc_status_t rc_test_get_gop_decision(vpx_rc_model_t rate_ctrl_model, + vpx_rc_gop_decision_t *gop_decision) { + RateControllerForTest *test_controller = + static_cast(rate_ctrl_model); + test_controller->StartNextGop(); + *gop_decision = test_controller->GetCurrentGop(); return VPX_RC_OK; } vpx_rc_status_t rc_delete_model(vpx_rc_model_t rate_ctrl_model) { - ToyRateCtrl *toy_rate_ctrl = static_cast(rate_ctrl_model); - EXPECT_EQ(toy_rate_ctrl->magic_number, kModelMagicNumber); - delete toy_rate_ctrl; + RateControllerForTest *test_controller = + static_cast(rate_ctrl_model); + delete test_controller; return VPX_RC_OK; } class ExtRateCtrlTest : public ::libvpx_test::EncoderTest, public ::testing::Test { protected: - ExtRateCtrlTest() : EncoderTest(&::libvpx_test::kVP9) {} + ExtRateCtrlTest() + : EncoderTest(&::libvpx_test::kVP9), use_alt_ref_(true), + received_show_frame_count_(0), current_frame_qp_(0) {} ~ExtRateCtrlTest() override = default; void SetUp() override { InitializeConfig(); +#if CONFIG_REALTIME_ONLY + SetMode(::libvpx_test::kRealTime); +#else SetMode(::libvpx_test::kTwoPassGood); +#endif } void PreEncodeFrameHook(::libvpx_test::VideoSource *video, ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { - vpx_rc_funcs_t rc_funcs; - rc_funcs.create_model = rc_create_model; - rc_funcs.send_firstpass_stats = rc_send_firstpass_stats; - rc_funcs.get_encodeframe_decision = rc_get_encodeframe_decision; - rc_funcs.update_encodeframe_result = rc_update_encodeframe_result; + vpx_rc_funcs_t rc_funcs = {}; + rc_funcs.rc_type = VPX_RC_GOP_QP; + rc_funcs.create_model = rc_test_create_model; + rc_funcs.send_firstpass_stats = rc_test_send_firstpass_stats; + rc_funcs.send_tpl_gop_stats = rc_test_send_tpl_gop_stats; + rc_funcs.get_gop_decision = rc_test_get_gop_decision; + rc_funcs.get_encodeframe_decision = rc_test_get_encodeframe_decision; rc_funcs.delete_model = rc_delete_model; - rc_funcs.priv = reinterpret_cast(PrivMagicNumber); + rc_funcs.priv = &use_alt_ref_; encoder->Control(VP9E_SET_EXTERNAL_RATE_CONTROL, &rc_funcs); } } + +#if CONFIG_VP9_DECODER + bool HandleDecodeResult(const vpx_codec_err_t res_dec, + const ::libvpx_test::VideoSource & /*video*/, + ::libvpx_test::Decoder *decoder) override { + EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError(); + decoder->Control(VPXD_GET_LAST_QUANTIZER, ¤t_frame_qp_); + return VPX_CODEC_OK == res_dec; + } + + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { + // We are not comparing current_frame_qp_ here because the encoder will + // pack ARF and the next show frame into one pkt. Therefore, we might + // receive two frames in one pkt. However, one thing we are sure is that + // each pkt will have just one show frame. Therefore, we can check if the + // received show frame count match the actual show frame count. + if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { + ++received_show_frame_count_; + } + } +#endif // CONFIG_VP9_DECODER + + bool use_alt_ref_; + int received_show_frame_count_; + int current_frame_qp_; }; TEST_F(ExtRateCtrlTest, EncodeTest) { - cfg_.rc_target_bitrate = 24000; + cfg_.rc_target_bitrate = 4000; + cfg_.g_lag_in_frames = 25; std::unique_ptr video; video.reset(new (std::nothrow) libvpx_test::YUVVideoSource( "bus_352x288_420_f20_b8.yuv", VPX_IMG_FMT_I420, 352, 288, 30, 1, 0, - kFrameNum)); + kShowFrameCount)); - ASSERT_NE(video.get(), nullptr); + ASSERT_NE(video, nullptr); ASSERT_NO_FATAL_FAILURE(RunLoop(video.get())); +#if CONFIG_VP9_DECODER + EXPECT_EQ(received_show_frame_count_, kShowFrameCount); +#endif +} + +// The first GOP has no ARF. In this case, TPL is run on the key frame, i.e., +// before any frame is encoded, which used to crash due to an unallocated +// buffer. +TEST_F(ExtRateCtrlTest, EncodeTestNoArf) { + cfg_.rc_target_bitrate = 4000; + cfg_.g_lag_in_frames = 25; + use_alt_ref_ = false; + + std::unique_ptr video; + video.reset(new (std::nothrow) libvpx_test::YUVVideoSource( + "bus_352x288_420_f20_b8.yuv", VPX_IMG_FMT_I420, 352, 288, 30, 1, 0, + kShowFrameCount)); + + ASSERT_NE(video, nullptr); + ASSERT_NO_FATAL_FAILURE(RunLoop(video.get())); +#if CONFIG_VP9_DECODER + EXPECT_EQ(received_show_frame_count_, kShowFrameCount); +#endif } } // namespace diff --git a/libs/libvpx/test/vp9_intrapred_test.cc b/libs/libvpx/test/vp9_intrapred_test.cc index ccace719ea..cf57da92ba 100644 --- a/libs/libvpx/test/vp9_intrapred_test.cc +++ b/libs/libvpx/test/vp9_intrapred_test.cc @@ -10,7 +10,7 @@ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" @@ -28,8 +28,8 @@ using libvpx_test::ACMRandom; const int count_test_block = 100000; -typedef void (*IntraPredFunc)(uint8_t *dst, ptrdiff_t stride, - const uint8_t *above, const uint8_t *left); +using IntraPredFunc = void (*)(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left); struct IntraPredParam { IntraPredParam(IntraPredFunc pred = nullptr, IntraPredFunc ref = nullptr, @@ -55,6 +55,21 @@ class IntraPredTest : public ::testing::TestWithParam { ref_dst_ = ref_dst; int error_count = 0; for (int i = 0; i < count_test_block; ++i) { + // TODO(webm:1797): Some of the optimised predictor implementations rely + // on the trailing half of the above_row_ being a copy of the final + // element, however relying on this in some cases can cause the MD5 tests + // to fail. We have fixed all of these cases for Neon, so fill the whole + // of above_row_ randomly. +#if HAVE_NEON + // Fill edges with random data, try first with saturated values. + for (int x = -1; x < 2 * block_size; x++) { + if (i == 0) { + above_row_[x] = mask_; + } else { + above_row_[x] = rnd.Rand16() & mask_; + } + } +#else // Fill edges with random data, try first with saturated values. for (int x = -1; x < block_size; x++) { if (i == 0) { @@ -66,6 +81,7 @@ class IntraPredTest : public ::testing::TestWithParam { for (int x = block_size; x < 2 * block_size; x++) { above_row_[x] = above_row_[block_size - 1]; } +#endif for (int y = 0; y < block_size; y++) { if (i == 0) { left_col_[y] = mask_; @@ -80,7 +96,7 @@ class IntraPredTest : public ::testing::TestWithParam { } protected: - virtual void SetUp() { + void SetUp() override { params_ = this->GetParam(); stride_ = params_.block_size * 3; mask_ = (1 << params_.bit_depth) - 1; @@ -119,7 +135,7 @@ void IntraPredTest::Predict() { params_.pred_fn(dst_, stride_, above_row_, left_col_)); } -typedef IntraPredTest VP9IntraPredTest; +using VP9IntraPredTest = IntraPredTest; TEST_P(VP9IntraPredTest, IntraPredTests) { // max block size is 32 @@ -136,7 +152,7 @@ INSTANTIATE_TEST_SUITE_P( C, VP9IntraPredTest, ::testing::Values(IntraPredParam(&vpx_d45_predictor_4x4_c, &vpx_d45_predictor_4x4_c, 4, 8))); -#if HAVE_SSE2 +#if HAVE_SSE2 && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P( SSE2, VP9IntraPredTest, ::testing::Values( @@ -198,9 +214,9 @@ INSTANTIATE_TEST_SUITE_P( 16, 8), IntraPredParam(&vpx_v_predictor_32x32_sse2, &vpx_v_predictor_32x32_c, 32, 8))); -#endif // HAVE_SSE2 +#endif // HAVE_SSE2 && HAVE_X86_ASM -#if HAVE_SSSE3 +#if HAVE_SSSE3 && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P( SSSE3, VP9IntraPredTest, ::testing::Values(IntraPredParam(&vpx_d45_predictor_16x16_ssse3, @@ -229,7 +245,7 @@ INSTANTIATE_TEST_SUITE_P( &vpx_d207_predictor_16x16_c, 16, 8), IntraPredParam(&vpx_d207_predictor_32x32_ssse3, &vpx_d207_predictor_32x32_c, 32, 8))); -#endif // HAVE_SSSE3 +#endif // HAVE_SSSE3 && HAVE_X86_ASM #if HAVE_NEON INSTANTIATE_TEST_SUITE_P( @@ -243,6 +259,22 @@ INSTANTIATE_TEST_SUITE_P( &vpx_d45_predictor_16x16_c, 16, 8), IntraPredParam(&vpx_d45_predictor_32x32_neon, &vpx_d45_predictor_32x32_c, 32, 8), + IntraPredParam(&vpx_d63_predictor_4x4_neon, &vpx_d63_predictor_4x4_c, 4, + 8), + IntraPredParam(&vpx_d63_predictor_8x8_neon, &vpx_d63_predictor_8x8_c, 8, + 8), + IntraPredParam(&vpx_d63_predictor_16x16_neon, + &vpx_d63_predictor_16x16_c, 16, 8), + IntraPredParam(&vpx_d63_predictor_32x32_neon, + &vpx_d63_predictor_32x32_c, 32, 8), + IntraPredParam(&vpx_d117_predictor_4x4_neon, &vpx_d117_predictor_4x4_c, + 4, 8), + IntraPredParam(&vpx_d117_predictor_8x8_neon, &vpx_d117_predictor_8x8_c, + 8, 8), + IntraPredParam(&vpx_d117_predictor_16x16_neon, + &vpx_d117_predictor_16x16_c, 16, 8), + IntraPredParam(&vpx_d117_predictor_32x32_neon, + &vpx_d117_predictor_32x32_c, 32, 8), IntraPredParam(&vpx_d135_predictor_4x4_neon, &vpx_d135_predictor_4x4_c, 4, 8), IntraPredParam(&vpx_d135_predictor_8x8_neon, &vpx_d135_predictor_8x8_c, @@ -251,6 +283,22 @@ INSTANTIATE_TEST_SUITE_P( &vpx_d135_predictor_16x16_c, 16, 8), IntraPredParam(&vpx_d135_predictor_32x32_neon, &vpx_d135_predictor_32x32_c, 32, 8), + IntraPredParam(&vpx_d153_predictor_4x4_neon, &vpx_d153_predictor_4x4_c, + 4, 8), + IntraPredParam(&vpx_d153_predictor_8x8_neon, &vpx_d153_predictor_8x8_c, + 8, 8), + IntraPredParam(&vpx_d153_predictor_16x16_neon, + &vpx_d153_predictor_16x16_c, 16, 8), + IntraPredParam(&vpx_d153_predictor_32x32_neon, + &vpx_d153_predictor_32x32_c, 32, 8), + IntraPredParam(&vpx_d207_predictor_4x4_neon, &vpx_d207_predictor_4x4_c, + 4, 8), + IntraPredParam(&vpx_d207_predictor_8x8_neon, &vpx_d207_predictor_8x8_c, + 8, 8), + IntraPredParam(&vpx_d207_predictor_16x16_neon, + &vpx_d207_predictor_16x16_c, 16, 8), + IntraPredParam(&vpx_d207_predictor_32x32_neon, + &vpx_d207_predictor_32x32_c, 32, 8), IntraPredParam(&vpx_dc_128_predictor_4x4_neon, &vpx_dc_128_predictor_4x4_c, 4, 8), IntraPredParam(&vpx_dc_128_predictor_8x8_neon, @@ -441,10 +489,20 @@ INSTANTIATE_TEST_SUITE_P( &vpx_v_predictor_32x32_c, 32, 8))); #endif // HAVE_VSX +#if HAVE_LSX +INSTANTIATE_TEST_SUITE_P( + LSX, VP9IntraPredTest, + ::testing::Values(IntraPredParam(&vpx_dc_predictor_8x8_lsx, + &vpx_dc_predictor_8x8_c, 8, 8), + IntraPredParam(&vpx_dc_predictor_16x16_lsx, + &vpx_dc_predictor_16x16_c, 16, 8))); +#endif // HAVE_LSX + #if CONFIG_VP9_HIGHBITDEPTH -typedef void (*HighbdIntraPred)(uint16_t *dst, ptrdiff_t stride, - const uint16_t *above, const uint16_t *left, - int bps); +using HighbdIntraPred = void (*)(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, const uint16_t *left, + int bps); + struct HighbdIntraPredParam { HighbdIntraPredParam(HighbdIntraPred pred = nullptr, HighbdIntraPred ref = nullptr, int block_size_value = 0, @@ -467,7 +525,7 @@ void IntraPredTest::Predict() { params_.pred_fn(dst_, stride_, above_row_, left_col_, bit_depth)); } -typedef IntraPredTest VP9HighbdIntraPredTest; +using VP9HighbdIntraPredTest = IntraPredTest; GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VP9HighbdIntraPredTest); TEST_P(VP9HighbdIntraPredTest, HighbdIntraPredTests) { @@ -480,6 +538,66 @@ TEST_P(VP9HighbdIntraPredTest, HighbdIntraPredTests) { } #endif +#if HAVE_AVX512 +INSTANTIATE_TEST_SUITE_P( + AVX512_TO_C_8, VP9HighbdIntraPredTest, + ::testing::Values( + HighbdIntraPredParam(&vpx_highbd_d63_predictor_32x32_avx512, + &vpx_highbd_d63_predictor_32x32_c, 32, 8), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_32x32_avx512, + &vpx_highbd_d207_predictor_32x32_c, 32, 8))); +INSTANTIATE_TEST_SUITE_P( + AVX512_TO_C_10, VP9HighbdIntraPredTest, + ::testing::Values( + HighbdIntraPredParam(&vpx_highbd_d63_predictor_32x32_avx512, + &vpx_highbd_d63_predictor_32x32_c, 32, 10), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_32x32_avx512, + &vpx_highbd_d207_predictor_32x32_c, 32, 10))); +INSTANTIATE_TEST_SUITE_P( + AVX512_TO_C_12, VP9HighbdIntraPredTest, + ::testing::Values( + HighbdIntraPredParam(&vpx_highbd_d63_predictor_32x32_avx512, + &vpx_highbd_d63_predictor_32x32_c, 32, 12), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_32x32_avx512, + &vpx_highbd_d207_predictor_32x32_c, 32, 12))); +#endif // HAVE_AVX512 + +#if HAVE_AVX2 +INSTANTIATE_TEST_SUITE_P( + AVX2_TO_C_8, VP9HighbdIntraPredTest, + ::testing::Values( + HighbdIntraPredParam(&vpx_highbd_d63_predictor_16x16_avx2, + &vpx_highbd_d63_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_32x32_avx2, + &vpx_highbd_d63_predictor_32x32_c, 32, 8), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_16x16_avx2, + &vpx_highbd_d207_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_32x32_avx2, + &vpx_highbd_d207_predictor_32x32_c, 32, 8))); +INSTANTIATE_TEST_SUITE_P( + AVX2_TO_C_10, VP9HighbdIntraPredTest, + ::testing::Values( + HighbdIntraPredParam(&vpx_highbd_d63_predictor_16x16_avx2, + &vpx_highbd_d63_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_32x32_avx2, + &vpx_highbd_d63_predictor_32x32_c, 32, 10), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_16x16_avx2, + &vpx_highbd_d207_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_32x32_avx2, + &vpx_highbd_d207_predictor_32x32_c, 32, 10))); +INSTANTIATE_TEST_SUITE_P( + AVX2_TO_C_12, VP9HighbdIntraPredTest, + ::testing::Values( + HighbdIntraPredParam(&vpx_highbd_d63_predictor_16x16_avx2, + &vpx_highbd_d63_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_32x32_avx2, + &vpx_highbd_d63_predictor_32x32_c, 32, 12), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_16x16_avx2, + &vpx_highbd_d207_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_32x32_avx2, + &vpx_highbd_d207_predictor_32x32_c, 32, 12))); +#endif // HAVE_AVX2 + #if HAVE_SSSE3 INSTANTIATE_TEST_SUITE_P( SSSE3_TO_C_8, VP9HighbdIntraPredTest, @@ -609,215 +727,236 @@ INSTANTIATE_TEST_SUITE_P( #endif // HAVE_SSSE3 #if HAVE_SSE2 -INSTANTIATE_TEST_SUITE_P( - SSE2_TO_C_8, VP9HighbdIntraPredTest, - ::testing::Values( - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_4x4_sse2, - &vpx_highbd_dc_128_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_8x8_sse2, - &vpx_highbd_dc_128_predictor_8x8_c, 8, 8), - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_16x16_sse2, - &vpx_highbd_dc_128_predictor_16x16_c, 16, 8), - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_32x32_sse2, - &vpx_highbd_dc_128_predictor_32x32_c, 32, 8), - HighbdIntraPredParam(&vpx_highbd_d63_predictor_4x4_sse2, - &vpx_highbd_d63_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_d117_predictor_4x4_sse2, - &vpx_highbd_d117_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_d135_predictor_4x4_sse2, - &vpx_highbd_d135_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_d153_predictor_4x4_sse2, - &vpx_highbd_d153_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_d207_predictor_4x4_sse2, - &vpx_highbd_d207_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_4x4_sse2, - &vpx_highbd_dc_left_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_8x8_sse2, - &vpx_highbd_dc_left_predictor_8x8_c, 8, 8), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_16x16_sse2, - &vpx_highbd_dc_left_predictor_16x16_c, 16, 8), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_32x32_sse2, - &vpx_highbd_dc_left_predictor_32x32_c, 32, 8), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_4x4_sse2, - &vpx_highbd_dc_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_8x8_sse2, - &vpx_highbd_dc_predictor_8x8_c, 8, 8), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_16x16_sse2, - &vpx_highbd_dc_predictor_16x16_c, 16, 8), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_32x32_sse2, - &vpx_highbd_dc_predictor_32x32_c, 32, 8), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_4x4_sse2, - &vpx_highbd_dc_top_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_8x8_sse2, - &vpx_highbd_dc_top_predictor_8x8_c, 8, 8), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_16x16_sse2, - &vpx_highbd_dc_top_predictor_16x16_c, 16, 8), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_32x32_sse2, - &vpx_highbd_dc_top_predictor_32x32_c, 32, 8), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_4x4_sse2, - &vpx_highbd_tm_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_8x8_sse2, - &vpx_highbd_tm_predictor_8x8_c, 8, 8), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_16x16_sse2, - &vpx_highbd_tm_predictor_16x16_c, 16, 8), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_32x32_sse2, - &vpx_highbd_tm_predictor_32x32_c, 32, 8), - HighbdIntraPredParam(&vpx_highbd_h_predictor_4x4_sse2, - &vpx_highbd_h_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_h_predictor_8x8_sse2, - &vpx_highbd_h_predictor_8x8_c, 8, 8), - HighbdIntraPredParam(&vpx_highbd_h_predictor_16x16_sse2, - &vpx_highbd_h_predictor_16x16_c, 16, 8), - HighbdIntraPredParam(&vpx_highbd_h_predictor_32x32_sse2, - &vpx_highbd_h_predictor_32x32_c, 32, 8), - HighbdIntraPredParam(&vpx_highbd_v_predictor_4x4_sse2, - &vpx_highbd_v_predictor_4x4_c, 4, 8), - HighbdIntraPredParam(&vpx_highbd_v_predictor_8x8_sse2, - &vpx_highbd_v_predictor_8x8_c, 8, 8), - HighbdIntraPredParam(&vpx_highbd_v_predictor_16x16_sse2, - &vpx_highbd_v_predictor_16x16_c, 16, 8), - HighbdIntraPredParam(&vpx_highbd_v_predictor_32x32_sse2, - &vpx_highbd_v_predictor_32x32_c, 32, 8))); +const HighbdIntraPredParam kSse2HighbdParams8[] = { + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_4x4_sse2, + &vpx_highbd_dc_128_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_8x8_sse2, + &vpx_highbd_dc_128_predictor_8x8_c, 8, 8), + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_16x16_sse2, + &vpx_highbd_dc_128_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_32x32_sse2, + &vpx_highbd_dc_128_predictor_32x32_c, 32, 8), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_4x4_sse2, + &vpx_highbd_d63_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_4x4_sse2, + &vpx_highbd_d117_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_d135_predictor_4x4_sse2, + &vpx_highbd_d135_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_4x4_sse2, + &vpx_highbd_d153_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_4x4_sse2, + &vpx_highbd_d207_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_4x4_sse2, + &vpx_highbd_dc_left_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_8x8_sse2, + &vpx_highbd_dc_left_predictor_8x8_c, 8, 8), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_16x16_sse2, + &vpx_highbd_dc_left_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_32x32_sse2, + &vpx_highbd_dc_left_predictor_32x32_c, 32, 8), +#if HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_dc_predictor_4x4_sse2, + &vpx_highbd_dc_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_dc_predictor_8x8_sse2, + &vpx_highbd_dc_predictor_8x8_c, 8, 8), + HighbdIntraPredParam(&vpx_highbd_dc_predictor_16x16_sse2, + &vpx_highbd_dc_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_dc_predictor_32x32_sse2, + &vpx_highbd_dc_predictor_32x32_c, 32, 8), +#endif // HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_4x4_sse2, + &vpx_highbd_dc_top_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_8x8_sse2, + &vpx_highbd_dc_top_predictor_8x8_c, 8, 8), + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_16x16_sse2, + &vpx_highbd_dc_top_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_32x32_sse2, + &vpx_highbd_dc_top_predictor_32x32_c, 32, 8), +#if HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_tm_predictor_4x4_sse2, + &vpx_highbd_tm_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_tm_predictor_8x8_sse2, + &vpx_highbd_tm_predictor_8x8_c, 8, 8), + HighbdIntraPredParam(&vpx_highbd_tm_predictor_16x16_sse2, + &vpx_highbd_tm_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_tm_predictor_32x32_sse2, + &vpx_highbd_tm_predictor_32x32_c, 32, 8), +#endif // HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_h_predictor_4x4_sse2, + &vpx_highbd_h_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_h_predictor_8x8_sse2, + &vpx_highbd_h_predictor_8x8_c, 8, 8), + HighbdIntraPredParam(&vpx_highbd_h_predictor_16x16_sse2, + &vpx_highbd_h_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_h_predictor_32x32_sse2, + &vpx_highbd_h_predictor_32x32_c, 32, 8), +#if HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_v_predictor_4x4_sse2, + &vpx_highbd_v_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_v_predictor_8x8_sse2, + &vpx_highbd_v_predictor_8x8_c, 8, 8), + HighbdIntraPredParam(&vpx_highbd_v_predictor_16x16_sse2, + &vpx_highbd_v_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_v_predictor_32x32_sse2, + &vpx_highbd_v_predictor_32x32_c, 32, 8), +#endif // HAVE_X86_ASM +}; +INSTANTIATE_TEST_SUITE_P(SSE2_TO_C_8, VP9HighbdIntraPredTest, + ::testing::ValuesIn(kSse2HighbdParams8)); -INSTANTIATE_TEST_SUITE_P( - SSE2_TO_C_10, VP9HighbdIntraPredTest, - ::testing::Values( - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_4x4_sse2, - &vpx_highbd_dc_128_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_8x8_sse2, - &vpx_highbd_dc_128_predictor_8x8_c, 8, 10), - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_16x16_sse2, - &vpx_highbd_dc_128_predictor_16x16_c, 16, 10), - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_32x32_sse2, - &vpx_highbd_dc_128_predictor_32x32_c, 32, 10), - HighbdIntraPredParam(&vpx_highbd_d63_predictor_4x4_sse2, - &vpx_highbd_d63_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_d117_predictor_4x4_sse2, - &vpx_highbd_d117_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_d135_predictor_4x4_sse2, - &vpx_highbd_d135_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_d153_predictor_4x4_sse2, - &vpx_highbd_d153_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_d207_predictor_4x4_sse2, - &vpx_highbd_d207_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_4x4_sse2, - &vpx_highbd_dc_left_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_8x8_sse2, - &vpx_highbd_dc_left_predictor_8x8_c, 8, 10), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_16x16_sse2, - &vpx_highbd_dc_left_predictor_16x16_c, 16, 10), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_32x32_sse2, - &vpx_highbd_dc_left_predictor_32x32_c, 32, 10), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_4x4_sse2, - &vpx_highbd_dc_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_8x8_sse2, - &vpx_highbd_dc_predictor_8x8_c, 8, 10), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_16x16_sse2, - &vpx_highbd_dc_predictor_16x16_c, 16, 10), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_32x32_sse2, - &vpx_highbd_dc_predictor_32x32_c, 32, 10), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_4x4_sse2, - &vpx_highbd_dc_top_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_8x8_sse2, - &vpx_highbd_dc_top_predictor_8x8_c, 8, 10), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_16x16_sse2, - &vpx_highbd_dc_top_predictor_16x16_c, 16, 10), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_32x32_sse2, - &vpx_highbd_dc_top_predictor_32x32_c, 32, 10), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_4x4_sse2, - &vpx_highbd_tm_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_8x8_sse2, - &vpx_highbd_tm_predictor_8x8_c, 8, 10), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_16x16_sse2, - &vpx_highbd_tm_predictor_16x16_c, 16, 10), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_32x32_sse2, - &vpx_highbd_tm_predictor_32x32_c, 32, 10), - HighbdIntraPredParam(&vpx_highbd_h_predictor_4x4_sse2, - &vpx_highbd_h_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_h_predictor_8x8_sse2, - &vpx_highbd_h_predictor_8x8_c, 8, 10), - HighbdIntraPredParam(&vpx_highbd_h_predictor_16x16_sse2, - &vpx_highbd_h_predictor_16x16_c, 16, 10), - HighbdIntraPredParam(&vpx_highbd_h_predictor_32x32_sse2, - &vpx_highbd_h_predictor_32x32_c, 32, 10), - HighbdIntraPredParam(&vpx_highbd_v_predictor_4x4_sse2, - &vpx_highbd_v_predictor_4x4_c, 4, 10), - HighbdIntraPredParam(&vpx_highbd_v_predictor_8x8_sse2, - &vpx_highbd_v_predictor_8x8_c, 8, 10), - HighbdIntraPredParam(&vpx_highbd_v_predictor_16x16_sse2, - &vpx_highbd_v_predictor_16x16_c, 16, 10), - HighbdIntraPredParam(&vpx_highbd_v_predictor_32x32_sse2, - &vpx_highbd_v_predictor_32x32_c, 32, 10))); +const HighbdIntraPredParam kSse2HighbdParams10[] = { + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_4x4_sse2, + &vpx_highbd_dc_128_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_8x8_sse2, + &vpx_highbd_dc_128_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_16x16_sse2, + &vpx_highbd_dc_128_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_32x32_sse2, + &vpx_highbd_dc_128_predictor_32x32_c, 32, 10), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_4x4_sse2, + &vpx_highbd_d63_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_4x4_sse2, + &vpx_highbd_d117_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_d135_predictor_4x4_sse2, + &vpx_highbd_d135_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_4x4_sse2, + &vpx_highbd_d153_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_4x4_sse2, + &vpx_highbd_d207_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_4x4_sse2, + &vpx_highbd_dc_left_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_8x8_sse2, + &vpx_highbd_dc_left_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_16x16_sse2, + &vpx_highbd_dc_left_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_32x32_sse2, + &vpx_highbd_dc_left_predictor_32x32_c, 32, 10), +#if HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_dc_predictor_4x4_sse2, + &vpx_highbd_dc_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_dc_predictor_8x8_sse2, + &vpx_highbd_dc_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_dc_predictor_16x16_sse2, + &vpx_highbd_dc_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_dc_predictor_32x32_sse2, + &vpx_highbd_dc_predictor_32x32_c, 32, 10), +#endif // HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_4x4_sse2, + &vpx_highbd_dc_top_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_8x8_sse2, + &vpx_highbd_dc_top_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_16x16_sse2, + &vpx_highbd_dc_top_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_32x32_sse2, + &vpx_highbd_dc_top_predictor_32x32_c, 32, 10), +#if HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_tm_predictor_4x4_sse2, + &vpx_highbd_tm_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_tm_predictor_8x8_sse2, + &vpx_highbd_tm_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_tm_predictor_16x16_sse2, + &vpx_highbd_tm_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_tm_predictor_32x32_sse2, + &vpx_highbd_tm_predictor_32x32_c, 32, 10), +#endif // HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_h_predictor_4x4_sse2, + &vpx_highbd_h_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_h_predictor_8x8_sse2, + &vpx_highbd_h_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_h_predictor_16x16_sse2, + &vpx_highbd_h_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_h_predictor_32x32_sse2, + &vpx_highbd_h_predictor_32x32_c, 32, 10), +#if HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_v_predictor_4x4_sse2, + &vpx_highbd_v_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_v_predictor_8x8_sse2, + &vpx_highbd_v_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_v_predictor_16x16_sse2, + &vpx_highbd_v_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_v_predictor_32x32_sse2, + &vpx_highbd_v_predictor_32x32_c, 32, 10), +#endif // HAVE_X86_ASM +}; +INSTANTIATE_TEST_SUITE_P(SSE2_TO_C_10, VP9HighbdIntraPredTest, + ::testing::ValuesIn(kSse2HighbdParams10)); -INSTANTIATE_TEST_SUITE_P( - SSE2_TO_C_12, VP9HighbdIntraPredTest, - ::testing::Values( - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_4x4_sse2, - &vpx_highbd_dc_128_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_8x8_sse2, - &vpx_highbd_dc_128_predictor_8x8_c, 8, 12), - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_16x16_sse2, - &vpx_highbd_dc_128_predictor_16x16_c, 16, 12), - HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_32x32_sse2, - &vpx_highbd_dc_128_predictor_32x32_c, 32, 12), - HighbdIntraPredParam(&vpx_highbd_d63_predictor_4x4_sse2, - &vpx_highbd_d63_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_d117_predictor_4x4_sse2, - &vpx_highbd_d117_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_d135_predictor_4x4_sse2, - &vpx_highbd_d135_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_d153_predictor_4x4_sse2, - &vpx_highbd_d153_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_d207_predictor_4x4_sse2, - &vpx_highbd_d207_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_4x4_sse2, - &vpx_highbd_dc_left_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_8x8_sse2, - &vpx_highbd_dc_left_predictor_8x8_c, 8, 12), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_16x16_sse2, - &vpx_highbd_dc_left_predictor_16x16_c, 16, 12), - HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_32x32_sse2, - &vpx_highbd_dc_left_predictor_32x32_c, 32, 12), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_4x4_sse2, - &vpx_highbd_dc_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_8x8_sse2, - &vpx_highbd_dc_predictor_8x8_c, 8, 12), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_16x16_sse2, - &vpx_highbd_dc_predictor_16x16_c, 16, 12), - HighbdIntraPredParam(&vpx_highbd_dc_predictor_32x32_sse2, - &vpx_highbd_dc_predictor_32x32_c, 32, 12), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_4x4_sse2, - &vpx_highbd_dc_top_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_8x8_sse2, - &vpx_highbd_dc_top_predictor_8x8_c, 8, 12), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_16x16_sse2, - &vpx_highbd_dc_top_predictor_16x16_c, 16, 12), - HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_32x32_sse2, - &vpx_highbd_dc_top_predictor_32x32_c, 32, 12), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_4x4_sse2, - &vpx_highbd_tm_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_8x8_sse2, - &vpx_highbd_tm_predictor_8x8_c, 8, 12), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_16x16_sse2, - &vpx_highbd_tm_predictor_16x16_c, 16, 12), - HighbdIntraPredParam(&vpx_highbd_tm_predictor_32x32_sse2, - &vpx_highbd_tm_predictor_32x32_c, 32, 12), - HighbdIntraPredParam(&vpx_highbd_h_predictor_4x4_sse2, - &vpx_highbd_h_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_h_predictor_8x8_sse2, - &vpx_highbd_h_predictor_8x8_c, 8, 12), - HighbdIntraPredParam(&vpx_highbd_h_predictor_16x16_sse2, - &vpx_highbd_h_predictor_16x16_c, 16, 12), - HighbdIntraPredParam(&vpx_highbd_h_predictor_32x32_sse2, - &vpx_highbd_h_predictor_32x32_c, 32, 12), - HighbdIntraPredParam(&vpx_highbd_v_predictor_4x4_sse2, - &vpx_highbd_v_predictor_4x4_c, 4, 12), - HighbdIntraPredParam(&vpx_highbd_v_predictor_8x8_sse2, - &vpx_highbd_v_predictor_8x8_c, 8, 12), - HighbdIntraPredParam(&vpx_highbd_v_predictor_16x16_sse2, - &vpx_highbd_v_predictor_16x16_c, 16, 12), - HighbdIntraPredParam(&vpx_highbd_v_predictor_32x32_sse2, - &vpx_highbd_v_predictor_32x32_c, 32, 12))); +const HighbdIntraPredParam kSse2HighbdParams12[] = { + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_4x4_sse2, + &vpx_highbd_dc_128_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_8x8_sse2, + &vpx_highbd_dc_128_predictor_8x8_c, 8, 12), + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_16x16_sse2, + &vpx_highbd_dc_128_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_32x32_sse2, + &vpx_highbd_dc_128_predictor_32x32_c, 32, 12), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_4x4_sse2, + &vpx_highbd_d63_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_4x4_sse2, + &vpx_highbd_d117_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_d135_predictor_4x4_sse2, + &vpx_highbd_d135_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_4x4_sse2, + &vpx_highbd_d153_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_4x4_sse2, + &vpx_highbd_d207_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_4x4_sse2, + &vpx_highbd_dc_left_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_8x8_sse2, + &vpx_highbd_dc_left_predictor_8x8_c, 8, 12), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_16x16_sse2, + &vpx_highbd_dc_left_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_dc_left_predictor_32x32_sse2, + &vpx_highbd_dc_left_predictor_32x32_c, 32, 12), +#if HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_dc_predictor_4x4_sse2, + &vpx_highbd_dc_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_dc_predictor_8x8_sse2, + &vpx_highbd_dc_predictor_8x8_c, 8, 12), + HighbdIntraPredParam(&vpx_highbd_dc_predictor_16x16_sse2, + &vpx_highbd_dc_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_dc_predictor_32x32_sse2, + &vpx_highbd_dc_predictor_32x32_c, 32, 12), +#endif // HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_4x4_sse2, + &vpx_highbd_dc_top_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_8x8_sse2, + &vpx_highbd_dc_top_predictor_8x8_c, 8, 12), + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_16x16_sse2, + &vpx_highbd_dc_top_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_dc_top_predictor_32x32_sse2, + &vpx_highbd_dc_top_predictor_32x32_c, 32, 12), +#if HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_tm_predictor_4x4_sse2, + &vpx_highbd_tm_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_tm_predictor_8x8_sse2, + &vpx_highbd_tm_predictor_8x8_c, 8, 12), + HighbdIntraPredParam(&vpx_highbd_tm_predictor_16x16_sse2, + &vpx_highbd_tm_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_tm_predictor_32x32_sse2, + &vpx_highbd_tm_predictor_32x32_c, 32, 12), +#endif // HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_h_predictor_4x4_sse2, + &vpx_highbd_h_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_h_predictor_8x8_sse2, + &vpx_highbd_h_predictor_8x8_c, 8, 12), + HighbdIntraPredParam(&vpx_highbd_h_predictor_16x16_sse2, + &vpx_highbd_h_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_h_predictor_32x32_sse2, + &vpx_highbd_h_predictor_32x32_c, 32, 12), +#if HAVE_X86_ASM + HighbdIntraPredParam(&vpx_highbd_v_predictor_4x4_sse2, + &vpx_highbd_v_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_v_predictor_8x8_sse2, + &vpx_highbd_v_predictor_8x8_c, 8, 12), + HighbdIntraPredParam(&vpx_highbd_v_predictor_16x16_sse2, + &vpx_highbd_v_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_v_predictor_32x32_sse2, + &vpx_highbd_v_predictor_32x32_c, 32, 12), +#endif // HAVE_X86_ASM +}; +INSTANTIATE_TEST_SUITE_P(SSE2_TO_C_12, VP9HighbdIntraPredTest, + ::testing::ValuesIn(kSse2HighbdParams12)); #endif // HAVE_SSE2 #if HAVE_NEON @@ -832,6 +971,22 @@ INSTANTIATE_TEST_SUITE_P( &vpx_highbd_d45_predictor_16x16_c, 16, 8), HighbdIntraPredParam(&vpx_highbd_d45_predictor_32x32_neon, &vpx_highbd_d45_predictor_32x32_c, 32, 8), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_4x4_neon, + &vpx_highbd_d63_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_8x8_neon, + &vpx_highbd_d63_predictor_8x8_c, 8, 8), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_16x16_neon, + &vpx_highbd_d63_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_32x32_neon, + &vpx_highbd_d63_predictor_32x32_c, 32, 8), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_4x4_neon, + &vpx_highbd_d117_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_8x8_neon, + &vpx_highbd_d117_predictor_8x8_c, 8, 8), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_16x16_neon, + &vpx_highbd_d117_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_32x32_neon, + &vpx_highbd_d117_predictor_32x32_c, 32, 8), HighbdIntraPredParam(&vpx_highbd_d135_predictor_4x4_neon, &vpx_highbd_d135_predictor_4x4_c, 4, 8), HighbdIntraPredParam(&vpx_highbd_d135_predictor_8x8_neon, @@ -840,6 +995,22 @@ INSTANTIATE_TEST_SUITE_P( &vpx_highbd_d135_predictor_16x16_c, 16, 8), HighbdIntraPredParam(&vpx_highbd_d135_predictor_32x32_neon, &vpx_highbd_d135_predictor_32x32_c, 32, 8), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_4x4_neon, + &vpx_highbd_d153_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_8x8_neon, + &vpx_highbd_d153_predictor_8x8_c, 8, 8), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_16x16_neon, + &vpx_highbd_d153_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_32x32_neon, + &vpx_highbd_d153_predictor_32x32_c, 32, 8), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_4x4_neon, + &vpx_highbd_d207_predictor_4x4_c, 4, 8), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_8x8_neon, + &vpx_highbd_d207_predictor_8x8_c, 8, 8), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_16x16_neon, + &vpx_highbd_d207_predictor_16x16_c, 16, 8), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_32x32_neon, + &vpx_highbd_d207_predictor_32x32_c, 32, 8), HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_4x4_neon, &vpx_highbd_dc_128_predictor_4x4_c, 4, 8), HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_8x8_neon, @@ -908,6 +1079,22 @@ INSTANTIATE_TEST_SUITE_P( &vpx_highbd_d45_predictor_16x16_c, 16, 10), HighbdIntraPredParam(&vpx_highbd_d45_predictor_32x32_neon, &vpx_highbd_d45_predictor_32x32_c, 32, 10), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_4x4_neon, + &vpx_highbd_d63_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_8x8_neon, + &vpx_highbd_d63_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_16x16_neon, + &vpx_highbd_d63_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_32x32_neon, + &vpx_highbd_d63_predictor_32x32_c, 32, 10), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_4x4_neon, + &vpx_highbd_d117_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_8x8_neon, + &vpx_highbd_d117_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_16x16_neon, + &vpx_highbd_d117_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_32x32_neon, + &vpx_highbd_d117_predictor_32x32_c, 32, 10), HighbdIntraPredParam(&vpx_highbd_d135_predictor_4x4_neon, &vpx_highbd_d135_predictor_4x4_c, 4, 10), HighbdIntraPredParam(&vpx_highbd_d135_predictor_8x8_neon, @@ -916,6 +1103,22 @@ INSTANTIATE_TEST_SUITE_P( &vpx_highbd_d135_predictor_16x16_c, 16, 10), HighbdIntraPredParam(&vpx_highbd_d135_predictor_32x32_neon, &vpx_highbd_d135_predictor_32x32_c, 32, 10), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_4x4_neon, + &vpx_highbd_d153_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_8x8_neon, + &vpx_highbd_d153_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_16x16_neon, + &vpx_highbd_d153_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_32x32_neon, + &vpx_highbd_d153_predictor_32x32_c, 32, 10), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_4x4_neon, + &vpx_highbd_d207_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_8x8_neon, + &vpx_highbd_d207_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_16x16_neon, + &vpx_highbd_d207_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_32x32_neon, + &vpx_highbd_d207_predictor_32x32_c, 32, 10), HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_4x4_neon, &vpx_highbd_dc_128_predictor_4x4_c, 4, 10), HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_8x8_neon, @@ -984,6 +1187,22 @@ INSTANTIATE_TEST_SUITE_P( &vpx_highbd_d45_predictor_16x16_c, 16, 12), HighbdIntraPredParam(&vpx_highbd_d45_predictor_32x32_neon, &vpx_highbd_d45_predictor_32x32_c, 32, 12), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_4x4_neon, + &vpx_highbd_d63_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_8x8_neon, + &vpx_highbd_d63_predictor_8x8_c, 8, 12), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_16x16_neon, + &vpx_highbd_d63_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_d63_predictor_32x32_neon, + &vpx_highbd_d63_predictor_32x32_c, 32, 12), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_4x4_neon, + &vpx_highbd_d117_predictor_4x4_c, 4, 10), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_8x8_neon, + &vpx_highbd_d117_predictor_8x8_c, 8, 10), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_16x16_neon, + &vpx_highbd_d117_predictor_16x16_c, 16, 10), + HighbdIntraPredParam(&vpx_highbd_d117_predictor_32x32_neon, + &vpx_highbd_d117_predictor_32x32_c, 32, 10), HighbdIntraPredParam(&vpx_highbd_d135_predictor_4x4_neon, &vpx_highbd_d135_predictor_4x4_c, 4, 12), HighbdIntraPredParam(&vpx_highbd_d135_predictor_8x8_neon, @@ -992,6 +1211,22 @@ INSTANTIATE_TEST_SUITE_P( &vpx_highbd_d135_predictor_16x16_c, 16, 12), HighbdIntraPredParam(&vpx_highbd_d135_predictor_32x32_neon, &vpx_highbd_d135_predictor_32x32_c, 32, 12), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_4x4_neon, + &vpx_highbd_d153_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_8x8_neon, + &vpx_highbd_d153_predictor_8x8_c, 8, 12), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_16x16_neon, + &vpx_highbd_d153_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_d153_predictor_32x32_neon, + &vpx_highbd_d153_predictor_32x32_c, 32, 12), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_4x4_neon, + &vpx_highbd_d207_predictor_4x4_c, 4, 12), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_8x8_neon, + &vpx_highbd_d207_predictor_8x8_c, 8, 12), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_16x16_neon, + &vpx_highbd_d207_predictor_16x16_c, 16, 12), + HighbdIntraPredParam(&vpx_highbd_d207_predictor_32x32_neon, + &vpx_highbd_d207_predictor_32x32_c, 32, 12), HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_4x4_neon, &vpx_highbd_dc_128_predictor_4x4_c, 4, 12), HighbdIntraPredParam(&vpx_highbd_dc_128_predictor_8x8_neon, diff --git a/libs/libvpx/test/vp9_lossless_test.cc b/libs/libvpx/test/vp9_lossless_test.cc index 931ac30a36..48839a7a23 100644 --- a/libs/libvpx/test/vp9_lossless_test.cc +++ b/libs/libvpx/test/vp9_lossless_test.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "test/codec_factory.h" @@ -29,15 +29,15 @@ class LosslessTest : EncoderTest(GET_PARAM(0)), psnr_(kMaxPsnr), nframes_(0), encoding_mode_(GET_PARAM(1)) {} - virtual ~LosslessTest() {} + ~LosslessTest() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(encoding_mode_); } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { // Only call Control if quantizer > 0 to verify that using quantizer // alone will activate lossless @@ -47,12 +47,12 @@ class LosslessTest } } - virtual void BeginPassHook(unsigned int /*pass*/) { + void BeginPassHook(unsigned int /*pass*/) override { psnr_ = kMaxPsnr; nframes_ = 0; } - virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { + void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) override { if (pkt->data.psnr.psnr[0] < psnr_) psnr_ = pkt->data.psnr.psnr[0]; } @@ -118,8 +118,13 @@ TEST_P(LosslessTest, TestLossLessEncodingCtrl) { EXPECT_GE(psnr_lossless, kMaxPsnr); } +#if CONFIG_REALTIME_ONLY +VP9_INSTANTIATE_TEST_SUITE(LosslessTest, + ::testing::Values(::libvpx_test::kRealTime)); +#else VP9_INSTANTIATE_TEST_SUITE(LosslessTest, ::testing::Values(::libvpx_test::kRealTime, ::libvpx_test::kOnePassGood, ::libvpx_test::kTwoPassGood)); +#endif } // namespace diff --git a/libs/libvpx/test/vp9_motion_vector_test.cc b/libs/libvpx/test/vp9_motion_vector_test.cc index 6b1082a106..b47f530909 100644 --- a/libs/libvpx/test/vp9_motion_vector_test.cc +++ b/libs/libvpx/test/vp9_motion_vector_test.cc @@ -10,12 +10,13 @@ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/util.h" #include "test/yuv_video_source.h" +#include "vpx_config.h" namespace { #define MAX_EXTREME_MV 1 @@ -23,7 +24,9 @@ namespace { // Encoding modes const libvpx_test::TestMode kEncodingModeVectors[] = { +#if !CONFIG_REALTIME_ONLY ::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood, +#endif ::libvpx_test::kRealTime }; @@ -42,9 +45,9 @@ class MotionVectorTestLarge : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), cpu_used_(GET_PARAM(2)), mv_test_mode_(GET_PARAM(3)) {} - virtual ~MotionVectorTestLarge() {} + ~MotionVectorTestLarge() override = default; - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(encoding_mode_); if (encoding_mode_ != ::libvpx_test::kRealTime) { @@ -59,8 +62,8 @@ class MotionVectorTestLarge } } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, cpu_used_); encoder->Control(VP9E_ENABLE_MOTION_VECTOR_UNIT_TEST, mv_test_mode_); diff --git a/libs/libvpx/test/vp9_quantize_test.cc b/libs/libvpx/test/vp9_quantize_test.cc index ca1062a76f..0c49598532 100644 --- a/libs/libvpx/test/vp9_quantize_test.cc +++ b/libs/libvpx/test/vp9_quantize_test.cc @@ -9,11 +9,12 @@ */ #include +#include #include #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp9_rtcd.h" #include "./vpx_config.h" @@ -26,9 +27,9 @@ #include "test/util.h" #include "vp9/common/vp9_entropy.h" #include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" #include "vpx/vpx_codec.h" #include "vpx/vpx_integer.h" -#include "vpx_ports/msvc.h" #include "vpx_ports/vpx_timer.h" using libvpx_test::ACMRandom; @@ -37,34 +38,83 @@ using libvpx_test::Buffer; namespace { const int number_of_iterations = 100; -typedef void (*QuantizeFunc)(const tran_low_t *coeff, intptr_t count, - const int16_t *zbin, const int16_t *round, - const int16_t *quant, const int16_t *quant_shift, - tran_low_t *qcoeff, tran_low_t *dqcoeff, - const int16_t *dequant, uint16_t *eob, - const int16_t *scan, const int16_t *iscan); -typedef std::tuple - QuantizeParam; +using QuantizeFunc = void (*)(const tran_low_t *coeff, intptr_t count, + const macroblock_plane *mb_plane, + tran_low_t *qcoeff, tran_low_t *dqcoeff, + const int16_t *dequant, uint16_t *eob, + const struct ScanOrder *const scan_order); +using QuantizeParam = std::tuple; + +// Wrapper for 32x32 version which does not use count +using Quantize32x32Func = void (*)(const tran_low_t *coeff, + const macroblock_plane *const mb_plane, + tran_low_t *qcoeff, tran_low_t *dqcoeff, + const int16_t *dequant, uint16_t *eob, + const struct ScanOrder *const scan_order); + +template +void Quant32x32Wrapper(const tran_low_t *coeff, intptr_t count, + const macroblock_plane *const mb_plane, + tran_low_t *qcoeff, tran_low_t *dqcoeff, + const int16_t *dequant, uint16_t *eob, + const struct ScanOrder *const scan_order) { + (void)count; + fn(coeff, mb_plane, qcoeff, dqcoeff, dequant, eob, scan_order); +} // Wrapper for FP version which does not use zbin or quant_shift. -typedef void (*QuantizeFPFunc)(const tran_low_t *coeff, intptr_t count, - const int16_t *round, const int16_t *quant, - tran_low_t *qcoeff, tran_low_t *dqcoeff, - const int16_t *dequant, uint16_t *eob, - const int16_t *scan, const int16_t *iscan); +using QuantizeFPFunc = void (*)(const tran_low_t *coeff, intptr_t count, + const macroblock_plane *const mb_plane, + tran_low_t *qcoeff, tran_low_t *dqcoeff, + const int16_t *dequant, uint16_t *eob, + const struct ScanOrder *const scan_order); template void QuantFPWrapper(const tran_low_t *coeff, intptr_t count, - const int16_t *zbin, const int16_t *round, - const int16_t *quant, const int16_t *quant_shift, - tran_low_t *qcoeff, tran_low_t *dqcoeff, - const int16_t *dequant, uint16_t *eob, const int16_t *scan, - const int16_t *iscan) { - (void)zbin; - (void)quant_shift; + const macroblock_plane *const mb_plane, tran_low_t *qcoeff, + tran_low_t *dqcoeff, const int16_t *dequant, uint16_t *eob, + const struct ScanOrder *const scan_order) { + fn(coeff, count, mb_plane, qcoeff, dqcoeff, dequant, eob, scan_order); +} - fn(coeff, count, round, quant, qcoeff, dqcoeff, dequant, eob, scan, iscan); +void GenerateHelperArrays(ACMRandom *rnd, int16_t *zbin, int16_t *round, + int16_t *quant, int16_t *quant_shift, + int16_t *dequant, int16_t *round_fp, + int16_t *quant_fp) { + // Max when q == 0. Otherwise, it is 48 for Y and 42 for U/V. + constexpr int kMaxQRoundingFactorFp = 64; + + for (int j = 0; j < 2; j++) { + // The range is 4 to 1828 in the VP9 tables. + const int qlookup = rnd->RandRange(1825) + 4; + round_fp[j] = (kMaxQRoundingFactorFp * qlookup) >> 7; + quant_fp[j] = (1 << 16) / qlookup; + + // Values determined by deconstructing vp9_init_quantizer(). + // zbin may be up to 1143 for 8 and 10 bit Y values, or 1200 for 12 bit Y + // values or U/V values of any bit depth. This is because y_delta is not + // factored into the vp9_ac_quant() call. + zbin[j] = rnd->RandRange(1200); + + // round may be up to 685 for Y values or 914 for U/V. + round[j] = rnd->RandRange(914); + // quant ranges from 1 to -32703 + quant[j] = static_cast(rnd->RandRange(32704)) - 32703; + // quant_shift goes up to 1 << 16. + quant_shift[j] = rnd->RandRange(16384); + // dequant maxes out at 1828 for all cases. + dequant[j] = rnd->RandRange(1828); + } + for (int j = 2; j < 8; j++) { + zbin[j] = zbin[1]; + round_fp[j] = round_fp[1]; + quant_fp[j] = quant_fp[1]; + round[j] = round[1]; + quant[j] = quant[1]; + quant_shift[j] = quant_shift[1]; + dequant[j] = dequant[1]; + } } class VP9QuantizeBase : public AbstractBench { @@ -80,17 +130,21 @@ class VP9QuantizeBase : public AbstractBench { #else max_value_ = (1 << bit_depth_) - 1; #endif - zbin_ptr_ = + + mb_plane_ = reinterpret_cast( + vpx_memalign(16, sizeof(macroblock_plane))); + + zbin_ptr_ = mb_plane_->zbin = reinterpret_cast(vpx_memalign(16, 8 * sizeof(*zbin_ptr_))); - round_fp_ptr_ = reinterpret_cast( + round_fp_ptr_ = mb_plane_->round_fp = reinterpret_cast( vpx_memalign(16, 8 * sizeof(*round_fp_ptr_))); - quant_fp_ptr_ = reinterpret_cast( + quant_fp_ptr_ = mb_plane_->quant_fp = reinterpret_cast( vpx_memalign(16, 8 * sizeof(*quant_fp_ptr_))); - round_ptr_ = + round_ptr_ = mb_plane_->round = reinterpret_cast(vpx_memalign(16, 8 * sizeof(*round_ptr_))); - quant_ptr_ = + quant_ptr_ = mb_plane_->quant = reinterpret_cast(vpx_memalign(16, 8 * sizeof(*quant_ptr_))); - quant_shift_ptr_ = reinterpret_cast( + quant_shift_ptr_ = mb_plane_->quant_shift = reinterpret_cast( vpx_memalign(16, 8 * sizeof(*quant_shift_ptr_))); dequant_ptr_ = reinterpret_cast( vpx_memalign(16, 8 * sizeof(*dequant_ptr_))); @@ -99,7 +153,8 @@ class VP9QuantizeBase : public AbstractBench { q_ptr_ = (is_fp_) ? quant_fp_ptr_ : quant_ptr_; } - ~VP9QuantizeBase() { + ~VP9QuantizeBase() override { + vpx_free(mb_plane_); vpx_free(zbin_ptr_); vpx_free(round_fp_ptr_); vpx_free(quant_fp_ptr_); @@ -107,6 +162,7 @@ class VP9QuantizeBase : public AbstractBench { vpx_free(quant_ptr_); vpx_free(quant_shift_ptr_); vpx_free(dequant_ptr_); + mb_plane_ = nullptr; zbin_ptr_ = nullptr; round_fp_ptr_ = nullptr; quant_fp_ptr_ = nullptr; @@ -118,9 +174,10 @@ class VP9QuantizeBase : public AbstractBench { } protected: + macroblock_plane *mb_plane_; int16_t *zbin_ptr_; - int16_t *round_fp_ptr_; int16_t *quant_fp_ptr_; + int16_t *round_fp_ptr_; int16_t *round_ptr_; int16_t *quant_ptr_; int16_t *quant_shift_ptr_; @@ -135,7 +192,7 @@ class VP9QuantizeBase : public AbstractBench { int16_t *r_ptr_; int16_t *q_ptr_; int count_; - const scan_order *scan_; + const ScanOrder *scan_; uint16_t eob_; }; @@ -147,30 +204,125 @@ class VP9QuantizeTest : public VP9QuantizeBase, quantize_op_(GET_PARAM(0)), ref_quantize_op_(GET_PARAM(1)) {} protected: - virtual void Run(); + void Run() override; + void Speed(bool is_median); const QuantizeFunc quantize_op_; const QuantizeFunc ref_quantize_op_; }; void VP9QuantizeTest::Run() { - quantize_op_(coeff_.TopLeftPixel(), count_, zbin_ptr_, r_ptr_, q_ptr_, - quant_shift_ptr_, qcoeff_.TopLeftPixel(), - dqcoeff_.TopLeftPixel(), dequant_ptr_, &eob_, scan_->scan, - scan_->iscan); + quantize_op_(coeff_.TopLeftPixel(), count_, mb_plane_, qcoeff_.TopLeftPixel(), + dqcoeff_.TopLeftPixel(), dequant_ptr_, &eob_, scan_); +} + +void VP9QuantizeTest::Speed(bool is_median) { + ACMRandom rnd(ACMRandom::DeterministicSeed()); + ASSERT_TRUE(coeff_.Init()); + ASSERT_TRUE(qcoeff_.Init()); + ASSERT_TRUE(dqcoeff_.Init()); + TX_SIZE starting_sz, ending_sz; + + if (max_size_ == 16) { + starting_sz = TX_4X4; + ending_sz = TX_16X16; + } else { + starting_sz = TX_32X32; + ending_sz = TX_32X32; + } + + for (TX_SIZE sz = starting_sz; sz <= ending_sz; ++sz) { + // zbin > coeff, zbin < coeff. + for (int i = 0; i < 2; ++i) { + // TX_TYPE defines the scan order. That is not relevant to the speed test. + // Pick the first one. + const TX_TYPE tx_type = DCT_DCT; + count_ = (4 << sz) * (4 << sz); + scan_ = &vp9_scan_orders[sz][tx_type]; + + GenerateHelperArrays(&rnd, zbin_ptr_, round_ptr_, quant_ptr_, + quant_shift_ptr_, dequant_ptr_, round_fp_ptr_, + quant_fp_ptr_); + + if (i == 0) { + // When |coeff values| are less than zbin the results are 0. + int threshold = 100; + if (max_size_ == 32) { + // For 32x32, the threshold is halved. Double it to keep the values + // from clearing it. + threshold = 200; + } + for (int j = 0; j < 8; ++j) zbin_ptr_[j] = threshold; + coeff_.Set(&rnd, -99, 99); + } else if (i == 1) { + for (int j = 0; j < 8; ++j) zbin_ptr_[j] = 50; + coeff_.Set(&rnd, -500, 500); + } + + const char *type = + (i == 0) ? "Bypass calculations " : "Full calculations "; + char block_size[16]; + snprintf(block_size, sizeof(block_size), "%dx%d", 4 << sz, 4 << sz); + char title[100]; + snprintf(title, sizeof(title), "%25s %8s ", type, block_size); + + if (is_median) { + RunNTimes(10000000 / count_); + PrintMedian(title); + } else { + Buffer ref_qcoeff = + Buffer(max_size_, max_size_, 0, 32); + ASSERT_TRUE(ref_qcoeff.Init()); + Buffer ref_dqcoeff = + Buffer(max_size_, max_size_, 0, 32); + ASSERT_TRUE(ref_dqcoeff.Init()); + uint16_t ref_eob = 0; + + const int kNumTests = 5000000; + vpx_usec_timer timer, simd_timer; + + vpx_usec_timer_start(&timer); + for (int n = 0; n < kNumTests; ++n) { + ref_quantize_op_(coeff_.TopLeftPixel(), count_, mb_plane_, + ref_qcoeff.TopLeftPixel(), + ref_dqcoeff.TopLeftPixel(), dequant_ptr_, &ref_eob, + scan_); + } + vpx_usec_timer_mark(&timer); + + vpx_usec_timer_start(&simd_timer); + for (int n = 0; n < kNumTests; ++n) { + quantize_op_(coeff_.TopLeftPixel(), count_, mb_plane_, + qcoeff_.TopLeftPixel(), dqcoeff_.TopLeftPixel(), + dequant_ptr_, &eob_, scan_); + } + vpx_usec_timer_mark(&simd_timer); + + const int elapsed_time = + static_cast(vpx_usec_timer_elapsed(&timer)); + const int simd_elapsed_time = + static_cast(vpx_usec_timer_elapsed(&simd_timer)); + printf("%s c_time = %d \t simd_time = %d \t Gain = %f \n", title, + elapsed_time, simd_elapsed_time, + ((float)elapsed_time / simd_elapsed_time)); + } + } + } } // This quantizer compares the AC coefficients to the quantization step size to // determine if further multiplication operations are needed. // Based on vp9_quantize_fp_sse2(). inline void quant_fp_nz(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *round_ptr, const int16_t *quant_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan, + const struct ScanOrder *const scan_order, int is_32x32) { int i, eob = -1; const int thr = dequant_ptr[1] >> (1 + is_32x32); - (void)iscan; + const int16_t *round_ptr = mb_plane->round_fp; + const int16_t *quant_ptr = mb_plane->quant_fp; + const int16_t *scan = scan_order->scan; // Quantization pass: All coefficients with index >= zero_flag are // skippable. Note: zero_flag can be zero. @@ -237,60 +389,21 @@ inline void quant_fp_nz(const tran_low_t *coeff_ptr, intptr_t n_coeffs, } void quantize_fp_nz_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *round_ptr, const int16_t *quant_ptr, + const struct macroblock_plane *mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { - quant_fp_nz(coeff_ptr, n_coeffs, round_ptr, quant_ptr, qcoeff_ptr, - dqcoeff_ptr, dequant_ptr, eob_ptr, scan, iscan, 0); + const struct ScanOrder *const scan_order) { + quant_fp_nz(coeff_ptr, n_coeffs, mb_plane, qcoeff_ptr, dqcoeff_ptr, + dequant_ptr, eob_ptr, scan_order, 0); } void quantize_fp_32x32_nz_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *round_ptr, const int16_t *quant_ptr, + const struct macroblock_plane *mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { - quant_fp_nz(coeff_ptr, n_coeffs, round_ptr, quant_ptr, qcoeff_ptr, - dqcoeff_ptr, dequant_ptr, eob_ptr, scan, iscan, 1); -} - -void GenerateHelperArrays(ACMRandom *rnd, int16_t *zbin, int16_t *round, - int16_t *quant, int16_t *quant_shift, - int16_t *dequant, int16_t *round_fp, - int16_t *quant_fp) { - // Max when q == 0. Otherwise, it is 48 for Y and 42 for U/V. - const int max_qrounding_factor_fp = 64; - - for (int j = 0; j < 2; j++) { - // The range is 4 to 1828 in the VP9 tables. - const int qlookup = rnd->RandRange(1825) + 4; - round_fp[j] = (max_qrounding_factor_fp * qlookup) >> 7; - quant_fp[j] = (1 << 16) / qlookup; - - // Values determined by deconstructing vp9_init_quantizer(). - // zbin may be up to 1143 for 8 and 10 bit Y values, or 1200 for 12 bit Y - // values or U/V values of any bit depth. This is because y_delta is not - // factored into the vp9_ac_quant() call. - zbin[j] = rnd->RandRange(1200); - - // round may be up to 685 for Y values or 914 for U/V. - round[j] = rnd->RandRange(914); - // quant ranges from 1 to -32703 - quant[j] = static_cast(rnd->RandRange(32704)) - 32703; - // quant_shift goes up to 1 << 16. - quant_shift[j] = rnd->RandRange(16384); - // dequant maxes out at 1828 for all cases. - dequant[j] = rnd->RandRange(1828); - } - for (int j = 2; j < 8; j++) { - zbin[j] = zbin[1]; - round_fp[j] = round_fp[1]; - quant_fp[j] = quant_fp[1]; - round[j] = round[1]; - quant[j] = quant[1]; - quant_shift[j] = quant_shift[1]; - dequant[j] = dequant[1]; - } + const struct ScanOrder *const scan_order) { + quant_fp_nz(coeff_ptr, n_coeffs, mb_plane, qcoeff_ptr, dqcoeff_ptr, + dequant_ptr, eob_ptr, scan_order, 1); } TEST_P(VP9QuantizeTest, OperationCheck) { @@ -321,15 +434,13 @@ TEST_P(VP9QuantizeTest, OperationCheck) { GenerateHelperArrays(&rnd, zbin_ptr_, round_ptr_, quant_ptr_, quant_shift_ptr_, dequant_ptr_, round_fp_ptr_, quant_fp_ptr_); - ref_quantize_op_(coeff_.TopLeftPixel(), count_, zbin_ptr_, r_ptr_, q_ptr_, - quant_shift_ptr_, ref_qcoeff.TopLeftPixel(), - ref_dqcoeff.TopLeftPixel(), dequant_ptr_, &ref_eob, - scan_->scan, scan_->iscan); + ref_quantize_op_(coeff_.TopLeftPixel(), count_, mb_plane_, + ref_qcoeff.TopLeftPixel(), ref_dqcoeff.TopLeftPixel(), + dequant_ptr_, &ref_eob, scan_); ASM_REGISTER_STATE_CHECK(quantize_op_( - coeff_.TopLeftPixel(), count_, zbin_ptr_, r_ptr_, q_ptr_, - quant_shift_ptr_, qcoeff_.TopLeftPixel(), dqcoeff_.TopLeftPixel(), - dequant_ptr_, &eob_, scan_->scan, scan_->iscan)); + coeff_.TopLeftPixel(), count_, mb_plane_, qcoeff_.TopLeftPixel(), + dqcoeff_.TopLeftPixel(), dequant_ptr_, &eob_, scan_)); EXPECT_TRUE(qcoeff_.CheckValues(ref_qcoeff)); EXPECT_TRUE(dqcoeff_.CheckValues(ref_dqcoeff)); @@ -379,15 +490,13 @@ TEST_P(VP9QuantizeTest, EOBCheck) { GenerateHelperArrays(&rnd, zbin_ptr_, round_ptr_, quant_ptr_, quant_shift_ptr_, dequant_ptr_, round_fp_ptr_, quant_fp_ptr_); - ref_quantize_op_(coeff_.TopLeftPixel(), count_, zbin_ptr_, r_ptr_, q_ptr_, - quant_shift_ptr_, ref_qcoeff.TopLeftPixel(), - ref_dqcoeff.TopLeftPixel(), dequant_ptr_, &ref_eob, - scan_->scan, scan_->iscan); + ref_quantize_op_(coeff_.TopLeftPixel(), count_, mb_plane_, + ref_qcoeff.TopLeftPixel(), ref_dqcoeff.TopLeftPixel(), + dequant_ptr_, &ref_eob, scan_); ASM_REGISTER_STATE_CHECK(quantize_op_( - coeff_.TopLeftPixel(), count_, zbin_ptr_, r_ptr_, q_ptr_, - quant_shift_ptr_, qcoeff_.TopLeftPixel(), dqcoeff_.TopLeftPixel(), - dequant_ptr_, &eob_, scan_->scan, scan_->iscan)); + coeff_.TopLeftPixel(), count_, mb_plane_, qcoeff_.TopLeftPixel(), + dqcoeff_.TopLeftPixel(), dequant_ptr_, &eob_, scan_)); EXPECT_TRUE(qcoeff_.CheckValues(ref_qcoeff)); EXPECT_TRUE(dqcoeff_.CheckValues(ref_dqcoeff)); @@ -403,60 +512,9 @@ TEST_P(VP9QuantizeTest, EOBCheck) { } } -TEST_P(VP9QuantizeTest, DISABLED_Speed) { - ACMRandom rnd(ACMRandom::DeterministicSeed()); - ASSERT_TRUE(coeff_.Init()); - ASSERT_TRUE(qcoeff_.Init()); - ASSERT_TRUE(dqcoeff_.Init()); - TX_SIZE starting_sz, ending_sz; +TEST_P(VP9QuantizeTest, DISABLED_Speed) { Speed(false); } - if (max_size_ == 16) { - starting_sz = TX_4X4; - ending_sz = TX_16X16; - } else { - starting_sz = TX_32X32; - ending_sz = TX_32X32; - } - - for (TX_SIZE sz = starting_sz; sz <= ending_sz; ++sz) { - // zbin > coeff, zbin < coeff. - for (int i = 0; i < 2; ++i) { - // TX_TYPE defines the scan order. That is not relevant to the speed test. - // Pick the first one. - const TX_TYPE tx_type = DCT_DCT; - count_ = (4 << sz) * (4 << sz); - scan_ = &vp9_scan_orders[sz][tx_type]; - - GenerateHelperArrays(&rnd, zbin_ptr_, round_ptr_, quant_ptr_, - quant_shift_ptr_, dequant_ptr_, round_fp_ptr_, - quant_fp_ptr_); - - if (i == 0) { - // When |coeff values| are less than zbin the results are 0. - int threshold = 100; - if (max_size_ == 32) { - // For 32x32, the threshold is halved. Double it to keep the values - // from clearing it. - threshold = 200; - } - for (int j = 0; j < 8; ++j) zbin_ptr_[j] = threshold; - coeff_.Set(&rnd, -99, 99); - } else if (i == 1) { - for (int j = 0; j < 8; ++j) zbin_ptr_[j] = 50; - coeff_.Set(&rnd, -500, 500); - } - - RunNTimes(10000000 / count_); - const char *type = - (i == 0) ? "Bypass calculations " : "Full calculations "; - char block_size[16]; - snprintf(block_size, sizeof(block_size), "%dx%d", 4 << sz, 4 << sz); - char title[100]; - snprintf(title, sizeof(title), "%25s %8s ", type, block_size); - PrintMedian(title); - } - } -} +TEST_P(VP9QuantizeTest, DISABLED_SpeedMedian) { Speed(true); } using std::make_tuple; @@ -465,25 +523,30 @@ using std::make_tuple; INSTANTIATE_TEST_SUITE_P( SSE2, VP9QuantizeTest, ::testing::Values( - make_tuple(&vpx_quantize_b_sse2, &vpx_quantize_b_c, VPX_BITS_8, 16, + make_tuple(vpx_quantize_b_sse2, vpx_quantize_b_c, VPX_BITS_8, 16, false), - make_tuple(&vpx_highbd_quantize_b_sse2, &vpx_highbd_quantize_b_c, + make_tuple(&QuantFPWrapper, + &QuantFPWrapper, VPX_BITS_8, 16, true), + make_tuple(vpx_highbd_quantize_b_sse2, vpx_highbd_quantize_b_c, VPX_BITS_8, 16, false), - make_tuple(&vpx_highbd_quantize_b_sse2, &vpx_highbd_quantize_b_c, + make_tuple(vpx_highbd_quantize_b_sse2, vpx_highbd_quantize_b_c, VPX_BITS_10, 16, false), - make_tuple(&vpx_highbd_quantize_b_sse2, &vpx_highbd_quantize_b_c, + make_tuple(vpx_highbd_quantize_b_sse2, vpx_highbd_quantize_b_c, VPX_BITS_12, 16, false), - make_tuple(&vpx_highbd_quantize_b_32x32_sse2, - &vpx_highbd_quantize_b_32x32_c, VPX_BITS_8, 32, false), - make_tuple(&vpx_highbd_quantize_b_32x32_sse2, - &vpx_highbd_quantize_b_32x32_c, VPX_BITS_10, 32, false), - make_tuple(&vpx_highbd_quantize_b_32x32_sse2, - &vpx_highbd_quantize_b_32x32_c, VPX_BITS_12, 32, false))); + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_8, 32, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_10, 32, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_12, 32, false))); #else INSTANTIATE_TEST_SUITE_P( SSE2, VP9QuantizeTest, - ::testing::Values(make_tuple(&vpx_quantize_b_sse2, &vpx_quantize_b_c, + ::testing::Values(make_tuple(vpx_quantize_b_sse2, vpx_quantize_b_c, VPX_BITS_8, 16, false), make_tuple(&QuantFPWrapper, &QuantFPWrapper, VPX_BITS_8, @@ -492,64 +555,126 @@ INSTANTIATE_TEST_SUITE_P( #endif // HAVE_SSE2 #if HAVE_SSSE3 -#if VPX_ARCH_X86_64 INSTANTIATE_TEST_SUITE_P( SSSE3, VP9QuantizeTest, - ::testing::Values(make_tuple(&vpx_quantize_b_ssse3, &vpx_quantize_b_c, + ::testing::Values(make_tuple(vpx_quantize_b_ssse3, vpx_quantize_b_c, VPX_BITS_8, 16, false), - make_tuple(&vpx_quantize_b_32x32_ssse3, - &vpx_quantize_b_32x32_c, VPX_BITS_8, 32, - false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_8, 32, false), make_tuple(&QuantFPWrapper, &QuantFPWrapper, VPX_BITS_8, 16, true), make_tuple(&QuantFPWrapper, &QuantFPWrapper, VPX_BITS_8, 32, true))); -#else -INSTANTIATE_TEST_SUITE_P( - SSSE3, VP9QuantizeTest, - ::testing::Values(make_tuple(&vpx_quantize_b_ssse3, &vpx_quantize_b_c, - VPX_BITS_8, 16, false), - make_tuple(&vpx_quantize_b_32x32_ssse3, - &vpx_quantize_b_32x32_c, VPX_BITS_8, 32, - false))); - -#endif // VPX_ARCH_X86_64 #endif // HAVE_SSSE3 #if HAVE_AVX -INSTANTIATE_TEST_SUITE_P(AVX, VP9QuantizeTest, - ::testing::Values(make_tuple(&vpx_quantize_b_avx, - &vpx_quantize_b_c, - VPX_BITS_8, 16, false), - make_tuple(&vpx_quantize_b_32x32_avx, - &vpx_quantize_b_32x32_c, - VPX_BITS_8, 32, false))); +INSTANTIATE_TEST_SUITE_P( + AVX, VP9QuantizeTest, + ::testing::Values(make_tuple(vpx_quantize_b_avx, vpx_quantize_b_c, + VPX_BITS_8, 16, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_8, 32, false))); #endif // HAVE_AVX #if VPX_ARCH_X86_64 && HAVE_AVX2 +#if CONFIG_VP9_HIGHBITDEPTH +INSTANTIATE_TEST_SUITE_P( + AVX2, VP9QuantizeTest, + ::testing::Values( + make_tuple(&QuantFPWrapper, + &QuantFPWrapper, VPX_BITS_8, 16, true), + make_tuple(&QuantFPWrapper, + &QuantFPWrapper, VPX_BITS_12, 16, + true), + make_tuple(&QuantFPWrapper, + &QuantFPWrapper, VPX_BITS_12, + 32, true), + make_tuple(vpx_quantize_b_avx2, vpx_quantize_b_c, VPX_BITS_8, 16, + false), + make_tuple(vpx_highbd_quantize_b_avx2, vpx_highbd_quantize_b_c, + VPX_BITS_8, 16, false), + make_tuple(vpx_highbd_quantize_b_avx2, vpx_highbd_quantize_b_c, + VPX_BITS_10, 16, false), + make_tuple(vpx_highbd_quantize_b_avx2, vpx_highbd_quantize_b_c, + VPX_BITS_12, 16, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, VPX_BITS_8, 32, + false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_8, 32, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_10, 32, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_12, 32, false))); +#else INSTANTIATE_TEST_SUITE_P( AVX2, VP9QuantizeTest, ::testing::Values(make_tuple(&QuantFPWrapper, &QuantFPWrapper, VPX_BITS_8, - 16, true))); + 16, true), + make_tuple(&QuantFPWrapper, + &QuantFPWrapper, + VPX_BITS_8, 32, true), + make_tuple(vpx_quantize_b_avx2, vpx_quantize_b_c, + VPX_BITS_8, 16, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_8, 32, false))); +#endif // CONFIG_VP9_HIGHBITDEPTH #endif // HAVE_AVX2 #if HAVE_NEON +#if CONFIG_VP9_HIGHBITDEPTH +INSTANTIATE_TEST_SUITE_P( + NEON, VP9QuantizeTest, + ::testing::Values( + make_tuple(&vpx_quantize_b_neon, &vpx_quantize_b_c, VPX_BITS_8, 16, + false), + make_tuple(vpx_highbd_quantize_b_neon, vpx_highbd_quantize_b_c, + VPX_BITS_8, 16, false), + make_tuple(vpx_highbd_quantize_b_neon, vpx_highbd_quantize_b_c, + VPX_BITS_10, 16, false), + make_tuple(vpx_highbd_quantize_b_neon, vpx_highbd_quantize_b_c, + VPX_BITS_12, 16, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, VPX_BITS_8, 32, + false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_8, 32, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_10, 32, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_12, 32, false), + make_tuple(&QuantFPWrapper, + &QuantFPWrapper, VPX_BITS_8, 16, true), + make_tuple(&QuantFPWrapper, + &QuantFPWrapper, VPX_BITS_8, 32, + true))); +#else INSTANTIATE_TEST_SUITE_P( NEON, VP9QuantizeTest, ::testing::Values(make_tuple(&vpx_quantize_b_neon, &vpx_quantize_b_c, VPX_BITS_8, 16, false), - make_tuple(&vpx_quantize_b_32x32_neon, - &vpx_quantize_b_32x32_c, VPX_BITS_8, 32, - false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_8, 32, false), make_tuple(&QuantFPWrapper, &QuantFPWrapper, VPX_BITS_8, 16, true), make_tuple(&QuantFPWrapper, &QuantFPWrapper, VPX_BITS_8, 32, true))); +#endif // CONFIG_VP9_HIGHBITDEPTH #endif // HAVE_NEON #if HAVE_VSX && !CONFIG_VP9_HIGHBITDEPTH @@ -569,13 +694,13 @@ INSTANTIATE_TEST_SUITE_P( #endif // HAVE_VSX && !CONFIG_VP9_HIGHBITDEPTH #if HAVE_LSX && !CONFIG_VP9_HIGHBITDEPTH -INSTANTIATE_TEST_SUITE_P(LSX, VP9QuantizeTest, - ::testing::Values(make_tuple(&vpx_quantize_b_lsx, - &vpx_quantize_b_c, - VPX_BITS_8, 16, false), - make_tuple(&vpx_quantize_b_32x32_lsx, - &vpx_quantize_b_32x32_c, - VPX_BITS_8, 32, false))); +INSTANTIATE_TEST_SUITE_P( + LSX, VP9QuantizeTest, + ::testing::Values(make_tuple(&vpx_quantize_b_lsx, &vpx_quantize_b_c, + VPX_BITS_8, 16, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, + VPX_BITS_8, 32, false))); #endif // HAVE_LSX && !CONFIG_VP9_HIGHBITDEPTH // Only useful to compare "Speed" test results. @@ -583,8 +708,9 @@ INSTANTIATE_TEST_SUITE_P( DISABLED_C, VP9QuantizeTest, ::testing::Values( make_tuple(&vpx_quantize_b_c, &vpx_quantize_b_c, VPX_BITS_8, 16, false), - make_tuple(&vpx_quantize_b_32x32_c, &vpx_quantize_b_32x32_c, VPX_BITS_8, - 32, false), + make_tuple(&Quant32x32Wrapper, + &Quant32x32Wrapper, VPX_BITS_8, 32, + false), make_tuple(&QuantFPWrapper, &QuantFPWrapper, VPX_BITS_8, 16, true), make_tuple(&QuantFPWrapper, diff --git a/libs/libvpx/test/vp9_ratectrl_rtc_test.cc b/libs/libvpx/test/vp9_ratectrl_rtc_test.cc index b09a45bb76..aa15b3ce33 100644 --- a/libs/libvpx/test/vp9_ratectrl_rtc_test.cc +++ b/libs/libvpx/test/vp9_ratectrl_rtc_test.cc @@ -9,16 +9,19 @@ */ #include "vp9/ratectrl_rtc.h" +#include #include // NOLINT #include #include "./vpx_config.h" -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" #include "test/i420_video_source.h" #include "test/util.h" #include "test/video_source.h" +#include "vp9/encoder/vp9_encoder.h" +#include "vp9/encoder/vp9_svc_layercontext.h" #include "vpx/vpx_codec.h" #include "vpx_ports/bitops.h" @@ -26,7 +29,12 @@ namespace { const size_t kNumFrames = 300; -const int kTemporalId[4] = { 0, 2, 1, 2 }; +const int kTemporalId3Layer[4] = { 0, 2, 1, 2 }; +const int kTemporalId2Layer[2] = { 0, 1 }; +const int kTemporalRateAllocation3Layer[3] = { 50, 70, 100 }; +const int kTemporalRateAllocation2Layer[2] = { 60, 100 }; +const int kSpatialLayerBitrate[3] = { 200, 400, 1000 }; +const int kSpatialLayerBitrateLow[3] = { 50, 100, 400 }; class RcInterfaceTest : public ::libvpx_test::EncoderTest, @@ -34,28 +42,34 @@ class RcInterfaceTest public: RcInterfaceTest() : EncoderTest(GET_PARAM(0)), aq_mode_(GET_PARAM(1)), key_interval_(3000), - encoder_exit_(false) {} + encoder_exit_(false), frame_drop_thresh_(0), num_drops_(0) {} - virtual ~RcInterfaceTest() {} + ~RcInterfaceTest() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); } - virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, - libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(libvpx_test::VideoSource *video, + libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, 7); encoder->Control(VP9E_SET_AQ_MODE, aq_mode_); - encoder->Control(VP9E_SET_TUNE_CONTENT, 0); + if (rc_cfg_.is_screen) { + encoder->Control(VP9E_SET_TUNE_CONTENT, VP9E_CONTENT_SCREEN); + } else { + encoder->Control(VP9E_SET_TUNE_CONTENT, VP9E_CONTENT_DEFAULT); + } encoder->Control(VP8E_SET_MAX_INTRA_BITRATE_PCT, 1000); encoder->Control(VP9E_SET_RTC_EXTERNAL_RATECTRL, 1); } - frame_params_.frame_type = - video->frame() % key_interval_ == 0 ? KEY_FRAME : INTER_FRAME; - if (rc_cfg_.rc_mode == VPX_CBR && frame_params_.frame_type == INTER_FRAME) { + frame_params_.frame_type = video->frame() % key_interval_ == 0 + ? libvpx::RcFrameType::kKeyFrame + : libvpx::RcFrameType::kInterFrame; + if (rc_cfg_.rc_mode == VPX_CBR && + frame_params_.frame_type == libvpx::RcFrameType::kInterFrame) { // Disable golden frame update. frame_flags_ |= VP8_EFLAG_NO_UPD_GF; frame_flags_ |= VP8_EFLAG_NO_UPD_ARF; @@ -63,20 +77,23 @@ class RcInterfaceTest encoder_exit_ = video->frame() == kNumFrames; } - virtual void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) { + void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) override { if (encoder_exit_) { return; } int loopfilter_level, qp; encoder->Control(VP9E_GET_LOOPFILTER_LEVEL, &loopfilter_level); encoder->Control(VP8E_GET_LAST_QUANTIZER, &qp); - rc_api_->ComputeQP(frame_params_); - ASSERT_EQ(rc_api_->GetQP(), qp); - ASSERT_EQ(rc_api_->GetLoopfilterLevel(), loopfilter_level); + if (rc_api_->ComputeQP(frame_params_) == libvpx::FrameDropDecision::kOk) { + ASSERT_EQ(rc_api_->GetQP(), qp); + ASSERT_EQ(rc_api_->GetLoopfilterLevel(), loopfilter_level); + } else { + num_drops_++; + } } - virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { - rc_api_->PostEncodeUpdate(pkt->data.frame.sz); + void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override { + rc_api_->PostEncodeUpdate(pkt->data.frame.sz, frame_params_); } void RunOneLayer() { @@ -91,6 +108,42 @@ class RcInterfaceTest ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); } + void RunOneLayerScreen() { + SetConfig(GET_PARAM(2)); + rc_cfg_.is_screen = true; + rc_api_ = libvpx::VP9RateControlRTC::Create(rc_cfg_); + frame_params_.spatial_layer_id = 0; + frame_params_.temporal_layer_id = 0; + + ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", + 1280, 720, 30, 1, 0, kNumFrames); + + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + } + + void RunOneLayerDropFramesCBR() { + if (GET_PARAM(2) != VPX_CBR) { + GTEST_SKIP() << "Frame dropping is only for CBR mode."; + } + frame_drop_thresh_ = 30; + SetConfig(GET_PARAM(2)); + // Use lower bitrate, lower max-q, and enable frame dropper. + rc_cfg_.target_bandwidth = 200; + cfg_.rc_target_bitrate = 200; + rc_cfg_.max_quantizer = 50; + cfg_.rc_max_quantizer = 50; + rc_api_ = libvpx::VP9RateControlRTC::Create(rc_cfg_); + frame_params_.spatial_layer_id = 0; + frame_params_.temporal_layer_id = 0; + + ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", + 1280, 720, 30, 1, 0, kNumFrames); + + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + // Check that some frames were dropped, otherwise test has no value. + ASSERT_GE(num_drops_, 1); + } + void RunOneLayerVBRPeriodicKey() { if (GET_PARAM(2) != VPX_VBR) return; key_interval_ = 100; @@ -128,6 +181,7 @@ class RcInterfaceTest rc_cfg_.min_quantizers[0] = 2; rc_cfg_.rc_mode = rc_mode; rc_cfg_.aq_mode = aq_mode_; + rc_cfg_.frame_drop_thresh = frame_drop_thresh_; // Encoder settings for ground truth. cfg_.g_w = 1280; @@ -146,6 +200,7 @@ class RcInterfaceTest cfg_.rc_target_bitrate = 1000; cfg_.kf_min_dist = key_interval_; cfg_.kf_max_dist = key_interval_; + cfg_.rc_dropframe_thresh = frame_drop_thresh_; } std::unique_ptr rc_api_; @@ -154,23 +209,31 @@ class RcInterfaceTest int key_interval_; libvpx::VP9FrameParamsQpRTC frame_params_; bool encoder_exit_; + int frame_drop_thresh_; + int num_drops_; }; -class RcInterfaceSvcTest : public ::libvpx_test::EncoderTest, - public ::libvpx_test::CodecTestWithParam { +class RcInterfaceSvcTest + : public ::libvpx_test::EncoderTest, + public ::libvpx_test::CodecTestWith2Params { public: - RcInterfaceSvcTest() : EncoderTest(GET_PARAM(0)), aq_mode_(GET_PARAM(1)) {} - virtual ~RcInterfaceSvcTest() {} + RcInterfaceSvcTest() + : EncoderTest(GET_PARAM(0)), aq_mode_(GET_PARAM(1)), key_interval_(3000), + dynamic_spatial_layers_(0), inter_layer_pred_off_(GET_PARAM(2)), + parallel_spatial_layers_(false), frame_drop_thresh_(0), + max_consec_drop_(INT_MAX), num_drops_(0) {} + ~RcInterfaceSvcTest() override = default; protected: - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); } - virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { + current_superframe_ = 0; encoder->Control(VP8E_SET_CPUUSED, 7); encoder->Control(VP9E_SET_AQ_MODE, aq_mode_); encoder->Control(VP9E_SET_TUNE_CONTENT, 0); @@ -178,49 +241,231 @@ class RcInterfaceSvcTest : public ::libvpx_test::EncoderTest, encoder->Control(VP9E_SET_RTC_EXTERNAL_RATECTRL, 1); encoder->Control(VP9E_SET_SVC, 1); encoder->Control(VP9E_SET_SVC_PARAMETERS, &svc_params_); - } - - frame_params_.frame_type = video->frame() == 0 ? KEY_FRAME : INTER_FRAME; - if (rc_cfg_.rc_mode == VPX_CBR && frame_params_.frame_type == INTER_FRAME) { - // Disable golden frame update. - frame_flags_ |= VP8_EFLAG_NO_UPD_GF; - frame_flags_ |= VP8_EFLAG_NO_UPD_ARF; - } - encoder_exit_ = video->frame() == kNumFrames; - current_superframe_ = video->frame(); - } - - virtual void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) { - ::libvpx_test::CxDataIterator iter = encoder->GetCxData(); - while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) { - ParseSuperframeSizes(static_cast(pkt->data.frame.buf), - pkt->data.frame.sz); - for (int sl = 0; sl < rc_cfg_.ss_number_layers; sl++) { - frame_params_.spatial_layer_id = sl; - frame_params_.temporal_layer_id = kTemporalId[current_superframe_ % 4]; - rc_api_->ComputeQP(frame_params_); - frame_params_.frame_type = INTER_FRAME; - rc_api_->PostEncodeUpdate(sizes_[sl]); + if (inter_layer_pred_off_) { + encoder->Control(VP9E_SET_SVC_INTER_LAYER_PRED, + INTER_LAYER_PRED_OFF_NONKEY); + } + if (frame_drop_thresh_ > 0) { + vpx_svc_frame_drop_t svc_drop_frame; + svc_drop_frame.framedrop_mode = FULL_SUPERFRAME_DROP; + for (int sl = 0; sl < rc_cfg_.ss_number_layers; ++sl) + svc_drop_frame.framedrop_thresh[sl] = frame_drop_thresh_; + svc_drop_frame.max_consec_drop = max_consec_drop_; + encoder->Control(VP9E_SET_SVC_FRAME_DROP_LAYER, &svc_drop_frame); } } - if (!encoder_exit_) { - int loopfilter_level, qp; + frame_params_.frame_type = video->frame() % key_interval_ == 0 + ? libvpx::RcFrameType::kKeyFrame + : libvpx::RcFrameType::kInterFrame; + encoder_exit_ = video->frame() == kNumFrames; + if (dynamic_spatial_layers_ == 1) { + if (video->frame() == 100) { + // Go down to 2 spatial layers: set top SL to 0 bitrate. + // Update the encoder config. + cfg_.rc_target_bitrate -= cfg_.layer_target_bitrate[8]; + cfg_.layer_target_bitrate[6] = 0; + cfg_.layer_target_bitrate[7] = 0; + cfg_.layer_target_bitrate[8] = 0; + encoder->Config(&cfg_); + // Update the RC config. + rc_cfg_.target_bandwidth -= rc_cfg_.layer_target_bitrate[8]; + rc_cfg_.layer_target_bitrate[6] = 0; + rc_cfg_.layer_target_bitrate[7] = 0; + rc_cfg_.layer_target_bitrate[8] = 0; + ASSERT_TRUE(rc_api_->UpdateRateControl(rc_cfg_)); + } else if (video->frame() == 200) { + // Go down to 1 spatial layer. + // Update the encoder config. + cfg_.rc_target_bitrate -= cfg_.layer_target_bitrate[5]; + cfg_.layer_target_bitrate[3] = 0; + cfg_.layer_target_bitrate[4] = 0; + cfg_.layer_target_bitrate[5] = 0; + encoder->Config(&cfg_); + // Update the RC config. + rc_cfg_.target_bandwidth -= rc_cfg_.layer_target_bitrate[5]; + rc_cfg_.layer_target_bitrate[3] = 0; + rc_cfg_.layer_target_bitrate[4] = 0; + rc_cfg_.layer_target_bitrate[5] = 0; + ASSERT_TRUE(rc_api_->UpdateRateControl(rc_cfg_)); + } else if (/*DISABLES CODE*/ (false) && video->frame() == 280) { + // TODO(marpan): Re-enable this going back up when issue is fixed. + // Go back up to 3 spatial layers. + // Update the encoder config: use the original bitrates. + SetEncoderConfigSvc(3, 3); + encoder->Config(&cfg_); + // Update the RC config. + SetRCConfigSvc(3, 3); + ASSERT_TRUE(rc_api_->UpdateRateControl(rc_cfg_)); + } + } + } + + virtual void SetFrameParamsSvc(int sl) { + frame_params_.spatial_layer_id = sl; + if (rc_cfg_.ts_number_layers == 3) + frame_params_.temporal_layer_id = + kTemporalId3Layer[current_superframe_ % 4]; + else if (rc_cfg_.ts_number_layers == 2) + frame_params_.temporal_layer_id = + kTemporalId2Layer[current_superframe_ % 2]; + else + frame_params_.temporal_layer_id = 0; + frame_params_.frame_type = + current_superframe_ % key_interval_ == 0 && sl == 0 + ? libvpx::RcFrameType::kKeyFrame + : libvpx::RcFrameType::kInterFrame; + } + + void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) override { + if (encoder_exit_) { + return; + } + int superframe_is_dropped = false; + ::libvpx_test::CxDataIterator iter = encoder->GetCxData(); + for (int sl = 0; sl < rc_cfg_.ss_number_layers; sl++) sizes_[sl] = 0; + std::vector rc_qp; + // For FULL_SUPERFRAME_DROP: the full superframe drop decision is + // determined on the base spatial layer. + SetFrameParamsSvc(0); + if (rc_api_->ComputeQP(frame_params_) == libvpx::FrameDropDecision::kDrop) { + superframe_is_dropped = true; + num_drops_++; + } + while (const vpx_codec_cx_pkt_t *pkt = iter.Next()) { + ASSERT_EQ(superframe_is_dropped, false); + ParseSuperframeSizes(static_cast(pkt->data.frame.buf), + pkt->data.frame.sz); + if (!parallel_spatial_layers_ || current_superframe_ == 0) { + for (int sl = 0; sl < rc_cfg_.ss_number_layers; sl++) { + if (sizes_[sl] > 0) { + SetFrameParamsSvc(sl); + // For sl=0 ComputeQP() is already called above (line 310). + if (sl > 0) rc_api_->ComputeQP(frame_params_); + rc_api_->PostEncodeUpdate(sizes_[sl], frame_params_); + rc_qp.push_back(rc_api_->GetQP()); + } + } + } else { + for (int sl = 0; sl < rc_cfg_.ss_number_layers; sl++) { + // For sl=0 ComputeQP() is already called above (line 310). + if (sizes_[sl] > 0 && sl > 0) { + SetFrameParamsSvc(sl); + rc_api_->ComputeQP(frame_params_); + } + } + for (int sl = 0; sl < rc_cfg_.ss_number_layers; sl++) { + if (sizes_[sl] > 0) { + SetFrameParamsSvc(sl); + rc_api_->PostEncodeUpdate(sizes_[sl], frame_params_); + rc_qp.push_back(rc_api_->GetQP()); + } + } + } + } + if (!superframe_is_dropped) { + int loopfilter_level; + std::vector encoder_qp(VPX_SS_MAX_LAYERS, 0); encoder->Control(VP9E_GET_LOOPFILTER_LEVEL, &loopfilter_level); - encoder->Control(VP8E_GET_LAST_QUANTIZER, &qp); - ASSERT_EQ(rc_api_->GetQP(), qp); + encoder->Control(VP9E_GET_LAST_QUANTIZER_SVC_LAYERS, encoder_qp.data()); + encoder_qp.resize(rc_qp.size()); + ASSERT_EQ(rc_qp, encoder_qp); ASSERT_EQ(rc_api_->GetLoopfilterLevel(), loopfilter_level); + current_superframe_++; } } // This method needs to be overridden because non-reference frames are // expected to be mismatched frames as the encoder will avoid loopfilter on // these frames. - virtual void MismatchHook(const vpx_image_t * /*img1*/, - const vpx_image_t * /*img2*/) {} + void MismatchHook(const vpx_image_t * /*img1*/, + const vpx_image_t * /*img2*/) override {} + + void RunSvcInvalidInputs() { + SetRCConfigSvc(3, 3); + rc_api_ = libvpx::VP9RateControlRTC::Create(rc_cfg_); + ASSERT_NE(rc_api_, nullptr); + frame_params_.frame_type = libvpx::RcFrameType::kKeyFrame; + // Verify return false on UpdateRateControl if resolution goes above + // configured setting. + rc_cfg_.width = 2560; + rc_cfg_.height = 1440; + ASSERT_FALSE(rc_api_->UpdateRateControl(rc_cfg_)); + // Go back to original resolution. + rc_cfg_.width = 1280; + rc_cfg_.height = 720; + ASSERT_TRUE(rc_api_->UpdateRateControl(rc_cfg_)); + // Set layer_id beyond the range set in init (#spatial=3, #temporal=3). + // Expect ComputeQP() to return kDrop. + frame_params_.spatial_layer_id = 4; + frame_params_.temporal_layer_id = 0; + ASSERT_EQ(rc_api_->ComputeQP(frame_params_), + libvpx::FrameDropDecision::kDrop); + frame_params_.spatial_layer_id = 0; + frame_params_.temporal_layer_id = 4; + ASSERT_EQ(rc_api_->ComputeQP(frame_params_), + libvpx::FrameDropDecision::kDrop); + // Start with valid (0, 0) layer_id, expect return kOk. + frame_params_.spatial_layer_id = 0; + frame_params_.temporal_layer_id = 0; + ASSERT_EQ(rc_api_->ComputeQP(frame_params_), + libvpx::FrameDropDecision::kOk); + } void RunSvc() { - SetConfigSvc(); + SetRCConfigSvc(3, 3); rc_api_ = libvpx::VP9RateControlRTC::Create(rc_cfg_); - SetEncoderSvc(); + SetEncoderConfigSvc(3, 3); + + ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", + 1280, 720, 30, 1, 0, kNumFrames); + + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + } + + void RunSvcDropFramesCBR() { + max_consec_drop_ = 10; + frame_drop_thresh_ = 30; + SetRCConfigSvc(3, 3); + rc_api_ = libvpx::VP9RateControlRTC::Create(rc_cfg_); + SetEncoderConfigSvc(3, 3); + + ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", + 1280, 720, 30, 1, 0, kNumFrames); + + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + // Check that some frames were dropped, otherwise test has no value. + ASSERT_GE(num_drops_, 1); + } + + void RunSvcPeriodicKey() { + SetRCConfigSvc(3, 3); + key_interval_ = 100; + rc_api_ = libvpx::VP9RateControlRTC::Create(rc_cfg_); + SetEncoderConfigSvc(3, 3); + + ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", + 1280, 720, 30, 1, 0, kNumFrames); + + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + } + + void RunSvcDynamicSpatial() { + dynamic_spatial_layers_ = 1; + SetRCConfigSvc(3, 3); + rc_api_ = libvpx::VP9RateControlRTC::Create(rc_cfg_); + SetEncoderConfigSvc(3, 3); + + ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", + 1280, 720, 30, 1, 0, kNumFrames); + + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); + } + + void RunSvcParallelSpatialLayers() { + if (!inter_layer_pred_off_) return; + parallel_spatial_layers_ = true; + SetRCConfigSvc(3, 3); + rc_api_ = libvpx::VP9RateControlRTC::Create(rc_cfg_); + SetEncoderConfigSvc(3, 3); ::libvpx_test::I420VideoSource video("desktop_office1.1280_720-020.yuv", 1280, 720, 30, 1, 0, kNumFrames); @@ -256,30 +501,54 @@ class RcInterfaceSvcTest : public ::libvpx_test::EncoderTest, return VPX_CODEC_OK; } - void SetEncoderSvc() { - cfg_.ss_number_layers = 3; - cfg_.ts_number_layers = 3; + void SetEncoderConfigSvc(int number_spatial_layers, + int number_temporal_layers) { + cfg_.g_w = 1280; + cfg_.g_h = 720; + cfg_.ss_number_layers = number_spatial_layers; + cfg_.ts_number_layers = number_temporal_layers; cfg_.g_timebase.num = 1; cfg_.g_timebase.den = 30; - svc_params_.scaling_factor_num[0] = 72; - svc_params_.scaling_factor_den[0] = 288; - svc_params_.scaling_factor_num[1] = 144; - svc_params_.scaling_factor_den[1] = 288; - svc_params_.scaling_factor_num[2] = 288; - svc_params_.scaling_factor_den[2] = 288; + if (number_spatial_layers == 3) { + svc_params_.scaling_factor_num[0] = 1; + svc_params_.scaling_factor_den[0] = 4; + svc_params_.scaling_factor_num[1] = 2; + svc_params_.scaling_factor_den[1] = 4; + svc_params_.scaling_factor_num[2] = 4; + svc_params_.scaling_factor_den[2] = 4; + } else if (number_spatial_layers == 2) { + svc_params_.scaling_factor_num[0] = 1; + svc_params_.scaling_factor_den[0] = 2; + svc_params_.scaling_factor_num[1] = 2; + svc_params_.scaling_factor_den[1] = 2; + } else if (number_spatial_layers == 1) { + svc_params_.scaling_factor_num[0] = 1; + svc_params_.scaling_factor_den[0] = 1; + } + for (int i = 0; i < VPX_MAX_LAYERS; ++i) { svc_params_.max_quantizers[i] = 56; svc_params_.min_quantizers[i] = 2; svc_params_.speed_per_layer[i] = 7; + svc_params_.loopfilter_ctrl[i] = LOOPFILTER_ALL; } cfg_.rc_end_usage = VPX_CBR; cfg_.g_lag_in_frames = 0; cfg_.g_error_resilient = 0; - // 3 temporal layers - cfg_.ts_rate_decimator[0] = 4; - cfg_.ts_rate_decimator[1] = 2; - cfg_.ts_rate_decimator[2] = 1; - cfg_.temporal_layering_mode = 3; + + if (number_temporal_layers == 3) { + cfg_.ts_rate_decimator[0] = 4; + cfg_.ts_rate_decimator[1] = 2; + cfg_.ts_rate_decimator[2] = 1; + cfg_.temporal_layering_mode = 3; + } else if (number_temporal_layers == 2) { + cfg_.ts_rate_decimator[0] = 2; + cfg_.ts_rate_decimator[1] = 1; + cfg_.temporal_layering_mode = 2; + } else if (number_temporal_layers == 1) { + cfg_.ts_rate_decimator[0] = 1; + cfg_.temporal_layering_mode = 0; + } cfg_.rc_buf_initial_sz = 500; cfg_.rc_buf_optimal_sz = 600; @@ -288,27 +557,41 @@ class RcInterfaceSvcTest : public ::libvpx_test::EncoderTest, cfg_.rc_max_quantizer = 56; cfg_.g_threads = 1; cfg_.kf_max_dist = 9999; - cfg_.rc_target_bitrate = 1600; cfg_.rc_overshoot_pct = 50; cfg_.rc_undershoot_pct = 50; + cfg_.rc_dropframe_thresh = frame_drop_thresh_; - cfg_.layer_target_bitrate[0] = 100; - cfg_.layer_target_bitrate[1] = 140; - cfg_.layer_target_bitrate[2] = 200; - cfg_.layer_target_bitrate[3] = 250; - cfg_.layer_target_bitrate[4] = 350; - cfg_.layer_target_bitrate[5] = 500; - cfg_.layer_target_bitrate[6] = 450; - cfg_.layer_target_bitrate[7] = 630; - cfg_.layer_target_bitrate[8] = 900; + cfg_.rc_target_bitrate = 0; + for (int sl = 0; sl < number_spatial_layers; sl++) { + int spatial_bitrate = 0; + if (number_spatial_layers <= 3) + spatial_bitrate = frame_drop_thresh_ > 0 ? kSpatialLayerBitrateLow[sl] + : kSpatialLayerBitrate[sl]; + for (int tl = 0; tl < number_temporal_layers; tl++) { + int layer = sl * number_temporal_layers + tl; + if (number_temporal_layers == 3) + cfg_.layer_target_bitrate[layer] = + kTemporalRateAllocation3Layer[tl] * spatial_bitrate / 100; + else if (number_temporal_layers == 2) + cfg_.layer_target_bitrate[layer] = + kTemporalRateAllocation2Layer[tl] * spatial_bitrate / 100; + else if (number_temporal_layers == 1) + cfg_.layer_target_bitrate[layer] = spatial_bitrate; + } + cfg_.rc_target_bitrate += spatial_bitrate; + } + + cfg_.kf_min_dist = key_interval_; + cfg_.kf_max_dist = key_interval_; } - void SetConfigSvc() { + void SetRCConfigSvc(int number_spatial_layers, int number_temporal_layers) { rc_cfg_.width = 1280; rc_cfg_.height = 720; + rc_cfg_.ss_number_layers = number_spatial_layers; + rc_cfg_.ts_number_layers = number_temporal_layers; rc_cfg_.max_quantizer = 56; rc_cfg_.min_quantizer = 2; - rc_cfg_.target_bandwidth = 1600; rc_cfg_.buf_initial_sz = 500; rc_cfg_.buf_optimal_sz = 600; rc_cfg_.buf_sz = 1000; @@ -316,31 +599,58 @@ class RcInterfaceSvcTest : public ::libvpx_test::EncoderTest, rc_cfg_.overshoot_pct = 50; rc_cfg_.max_intra_bitrate_pct = 900; rc_cfg_.framerate = 30.0; - rc_cfg_.ss_number_layers = 3; - rc_cfg_.ts_number_layers = 3; rc_cfg_.rc_mode = VPX_CBR; rc_cfg_.aq_mode = aq_mode_; + rc_cfg_.frame_drop_thresh = frame_drop_thresh_; + rc_cfg_.max_consec_drop = max_consec_drop_; - rc_cfg_.scaling_factor_num[0] = 1; - rc_cfg_.scaling_factor_den[0] = 4; - rc_cfg_.scaling_factor_num[1] = 2; - rc_cfg_.scaling_factor_den[1] = 4; - rc_cfg_.scaling_factor_num[2] = 4; - rc_cfg_.scaling_factor_den[2] = 4; + if (number_spatial_layers == 3) { + rc_cfg_.scaling_factor_num[0] = 1; + rc_cfg_.scaling_factor_den[0] = 4; + rc_cfg_.scaling_factor_num[1] = 2; + rc_cfg_.scaling_factor_den[1] = 4; + rc_cfg_.scaling_factor_num[2] = 4; + rc_cfg_.scaling_factor_den[2] = 4; + } else if (number_spatial_layers == 2) { + rc_cfg_.scaling_factor_num[0] = 1; + rc_cfg_.scaling_factor_den[0] = 2; + rc_cfg_.scaling_factor_num[1] = 2; + rc_cfg_.scaling_factor_den[1] = 2; + } else if (number_spatial_layers == 1) { + rc_cfg_.scaling_factor_num[0] = 1; + rc_cfg_.scaling_factor_den[0] = 1; + } - rc_cfg_.ts_rate_decimator[0] = 4; - rc_cfg_.ts_rate_decimator[1] = 2; - rc_cfg_.ts_rate_decimator[2] = 1; + if (number_temporal_layers == 3) { + rc_cfg_.ts_rate_decimator[0] = 4; + rc_cfg_.ts_rate_decimator[1] = 2; + rc_cfg_.ts_rate_decimator[2] = 1; + } else if (number_temporal_layers == 2) { + rc_cfg_.ts_rate_decimator[0] = 2; + rc_cfg_.ts_rate_decimator[1] = 1; + } else if (number_temporal_layers == 1) { + rc_cfg_.ts_rate_decimator[0] = 1; + } - rc_cfg_.layer_target_bitrate[0] = 100; - rc_cfg_.layer_target_bitrate[1] = 140; - rc_cfg_.layer_target_bitrate[2] = 200; - rc_cfg_.layer_target_bitrate[3] = 250; - rc_cfg_.layer_target_bitrate[4] = 350; - rc_cfg_.layer_target_bitrate[5] = 500; - rc_cfg_.layer_target_bitrate[6] = 450; - rc_cfg_.layer_target_bitrate[7] = 630; - rc_cfg_.layer_target_bitrate[8] = 900; + rc_cfg_.target_bandwidth = 0; + for (int sl = 0; sl < number_spatial_layers; sl++) { + int spatial_bitrate = 0; + if (number_spatial_layers <= 3) + spatial_bitrate = frame_drop_thresh_ > 0 ? kSpatialLayerBitrateLow[sl] + : kSpatialLayerBitrate[sl]; + for (int tl = 0; tl < number_temporal_layers; tl++) { + int layer = sl * number_temporal_layers + tl; + if (number_temporal_layers == 3) + rc_cfg_.layer_target_bitrate[layer] = + kTemporalRateAllocation3Layer[tl] * spatial_bitrate / 100; + else if (number_temporal_layers == 2) + rc_cfg_.layer_target_bitrate[layer] = + kTemporalRateAllocation2Layer[tl] * spatial_bitrate / 100; + else if (number_temporal_layers == 1) + rc_cfg_.layer_target_bitrate[layer] = spatial_bitrate; + } + rc_cfg_.target_bandwidth += spatial_bitrate; + } for (int sl = 0; sl < rc_cfg_.ss_number_layers; ++sl) { for (int tl = 0; tl < rc_cfg_.ts_number_layers; ++tl) { @@ -359,15 +669,40 @@ class RcInterfaceSvcTest : public ::libvpx_test::EncoderTest, bool encoder_exit_; int current_superframe_; uint32_t sizes_[8]; + int key_interval_; + int dynamic_spatial_layers_; + bool inter_layer_pred_off_; + // ComputeQP() and PostEncodeUpdate() don't need to be sequential for KSVC. + bool parallel_spatial_layers_; + int frame_drop_thresh_; + int max_consec_drop_; + int num_drops_; }; TEST_P(RcInterfaceTest, OneLayer) { RunOneLayer(); } +TEST_P(RcInterfaceTest, OneLayerDropFramesCBR) { RunOneLayerDropFramesCBR(); } + +TEST_P(RcInterfaceTest, OneLayerScreen) { RunOneLayerScreen(); } + TEST_P(RcInterfaceTest, OneLayerVBRPeriodicKey) { RunOneLayerVBRPeriodicKey(); } +TEST_P(RcInterfaceSvcTest, SvcInvalidInputs) { RunSvcInvalidInputs(); } + TEST_P(RcInterfaceSvcTest, Svc) { RunSvc(); } +TEST_P(RcInterfaceSvcTest, SvcDropFramesCBR) { RunSvcDropFramesCBR(); } + +TEST_P(RcInterfaceSvcTest, SvcParallelSpatialLayers) { + RunSvcParallelSpatialLayers(); +} + +TEST_P(RcInterfaceSvcTest, SvcPeriodicKey) { RunSvcPeriodicKey(); } + +TEST_P(RcInterfaceSvcTest, SvcDynamicSpatial) { RunSvcDynamicSpatial(); } + VP9_INSTANTIATE_TEST_SUITE(RcInterfaceTest, ::testing::Values(0, 3), ::testing::Values(VPX_CBR, VPX_VBR)); -VP9_INSTANTIATE_TEST_SUITE(RcInterfaceSvcTest, ::testing::Values(0, 3)); +VP9_INSTANTIATE_TEST_SUITE(RcInterfaceSvcTest, ::testing::Values(0, 3), + ::testing::Values(true, false)); } // namespace diff --git a/libs/libvpx/test/vp9_roi_test.cc b/libs/libvpx/test/vp9_roi_test.cc index e8373c4c0b..9427796a2b 100644 --- a/libs/libvpx/test/vp9_roi_test.cc +++ b/libs/libvpx/test/vp9_roi_test.cc @@ -12,7 +12,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "test/codec_factory.h" #include "test/encode_test_driver.h" @@ -84,9 +84,9 @@ class RoiMaskBackgroundSkip : public ::libvpx_test::EncoderTest, public ::testing::Test { protected: RoiMaskBackgroundSkip() : EncoderTest(&::libvpx_test::kVP9) {} - virtual ~RoiMaskBackgroundSkip() { free(roi_.roi_map); } + ~RoiMaskBackgroundSkip() override { free(roi_.roi_map); } - virtual void SetUp() { + void SetUp() override { InitializeConfig(); SetMode(::libvpx_test::kRealTime); SetRoi(); @@ -114,8 +114,8 @@ class RoiMaskBackgroundSkip : public ::libvpx_test::EncoderTest, } } - virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, - ::libvpx_test::Encoder *encoder) { + void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) override { if (video->frame() == 0) { encoder->Control(VP8E_SET_CPUUSED, 7); encoder->Control(VP9E_SET_AQ_MODE, 3); diff --git a/libs/libvpx/test/vp9_scale_test.cc b/libs/libvpx/test/vp9_scale_test.cc index 2d1203fb89..53b38d22aa 100644 --- a/libs/libvpx/test/vp9_scale_test.cc +++ b/libs/libvpx/test/vp9_scale_test.cc @@ -12,7 +12,7 @@ #include #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp9_rtcd.h" #include "./vpx_config.h" @@ -26,17 +26,17 @@ namespace libvpx_test { -typedef void (*ScaleFrameFunc)(const YV12_BUFFER_CONFIG *src, - YV12_BUFFER_CONFIG *dst, - INTERP_FILTER filter_type, int phase_scaler); +using ScaleFrameFunc = void (*)(const YV12_BUFFER_CONFIG *src, + YV12_BUFFER_CONFIG *dst, + INTERP_FILTER filter_type, int phase_scaler); class ScaleTest : public VpxScaleBase, public ::testing::TestWithParam { public: - virtual ~ScaleTest() {} + ~ScaleTest() override = default; protected: - virtual void SetUp() { scale_fn_ = GetParam(); } + void SetUp() override { scale_fn_ = GetParam(); } void ReferenceScaleFrame(INTERP_FILTER filter_type, int phase_scaler) { vp9_scale_and_extend_frame_c(&img_, &ref_img_, filter_type, phase_scaler); @@ -48,12 +48,11 @@ class ScaleTest : public VpxScaleBase, } void RunTest(INTERP_FILTER filter_type) { - static const int kNumSizesToTest = 20; + static const int kNumSizesToTest = 22; static const int kNumScaleFactorsToTest = 4; - static const int kSizesToTest[] = { - 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, - 22, 24, 26, 28, 30, 32, 34, 68, 128, 134 - }; + static const int kSizesToTest[] = { 1, 2, 3, 4, 6, 8, 10, 12, + 14, 16, 18, 20, 22, 24, 26, 28, + 30, 32, 34, 68, 128, 134 }; static const int kScaleFactors[] = { 1, 2, 3, 4 }; for (int phase_scaler = 0; phase_scaler < 16; ++phase_scaler) { for (int h = 0; h < kNumSizesToTest; ++h) { diff --git a/libs/libvpx/test/vp9_scan_test.cc b/libs/libvpx/test/vp9_scan_test.cc new file mode 100644 index 0000000000..638c26d437 --- /dev/null +++ b/libs/libvpx/test/vp9_scan_test.cc @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2026 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "gtest/gtest.h" +#include "vp9/common/vp9_scan.h" + +namespace { + +constexpr int kNumValues[] = { 4 * 4, 8 * 8, 16 * 16, 32 * 32 }; + +TEST(VP9Scan, DefaultScanOrderValuesInBound) { + for (int tx_size = 0; tx_size < TX_SIZES; ++tx_size) { + const ScanOrder &scan_order = vp9_default_scan_orders[tx_size]; + for (int i = 0; i < kNumValues[tx_size]; ++i) { + EXPECT_LE(scan_order.scan[i], MAX_SCAN_VALUE) + << "vp9_default_scan_orders[" << tx_size << "].scan[" << i << "]"; + EXPECT_GE(scan_order.scan[i], 0) + << "vp9_default_scan_orders[" << tx_size << "].scan[" << i << "]"; + EXPECT_LE(scan_order.iscan[i], MAX_SCAN_VALUE) + << "vp9_default_scan_orders[" << tx_size << "].iscan[" << i << "]"; + EXPECT_GE(scan_order.iscan[i], 0) + << "vp9_default_scan_orders[" << tx_size << "].iscan[" << i << "]"; + } + } +} + +TEST(VP9Scan, ScanOrderValuesInBound) { + for (int tx_size = 0; tx_size < TX_SIZES; ++tx_size) { + for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) { + const ScanOrder &scan_order = vp9_scan_orders[tx_size][tx_type]; + for (int i = 0; i < kNumValues[tx_size]; ++i) { + EXPECT_LE(scan_order.scan[i], MAX_SCAN_VALUE) + << "vp9_scan_orders[" << tx_size << "][" << tx_type << "].scan[" + << i << "]"; + EXPECT_GE(scan_order.scan[i], 0) + << "vp9_scan_orders[" << tx_size << "][" << tx_type << "].scan[" + << i << "]"; + EXPECT_LE(scan_order.iscan[i], MAX_SCAN_VALUE) + << "vp9_scan_orders[" << tx_size << "][" << tx_type << "].iscan[" + << i << "]"; + EXPECT_GE(scan_order.iscan[i], 0) + << "vp9_scan_orders[" << tx_size << "][" << tx_type << "].iscan[" + << i << "]"; + } + } + } +} + +// Both neighbors of every scan position 1 <= c <= num_values must precede c in +// scan order, including the trailing sentinel at c == num_values read by +// decode_coefs() and tokenize_b() after ++c on the final coefficient. The +// decoder, tokenizer, and vp9_optimize_b() rely on this to fill token_cache in +// scan order without initializing it first: every entry that +// get_coef_context() reads has already been written. +void CheckNeighborsPrecedeInScanOrder(const ScanOrder &scan_order, + int num_values, const char *name) { + // Map each coefficient index back to its scan position. This is derived + // from scan[] rather than read from iscan[], which is 1-based. + std::vector scan_position(num_values, -1); + for (int c = 0; c < num_values; ++c) { + const int coeff = scan_order.scan[c]; + ASSERT_GE(coeff, 0) << name << " c=" << c; + ASSERT_LT(coeff, num_values) << name << " c=" << c; + ASSERT_EQ(scan_position[coeff], -1) + << name << " c=" << c << " coeff=" << coeff << " scanned twice"; + scan_position[coeff] = c; + } + for (int c = 1; c <= num_values; ++c) { + for (int k = 0; k < MAX_NEIGHBORS; ++k) { + const int neighbor = scan_order.neighbors[MAX_NEIGHBORS * c + k]; + ASSERT_GE(neighbor, 0) << name << " c=" << c << " k=" << k; + ASSERT_LT(neighbor, num_values) << name << " c=" << c << " k=" << k; + EXPECT_LT(scan_position[neighbor], c) + << name << " c=" << c << " k=" << k << " neighbor=" << neighbor; + } + } +} + +TEST(VP9Scan, DefaultScanOrderNeighborsPrecedeInScanOrder) { + for (int tx_size = 0; tx_size < TX_SIZES; ++tx_size) { + CheckNeighborsPrecedeInScanOrder(vp9_default_scan_orders[tx_size], + kNumValues[tx_size], + "vp9_default_scan_orders"); + } +} + +TEST(VP9Scan, NeighborsPrecedeInScanOrder) { + for (int tx_size = 0; tx_size < TX_SIZES; ++tx_size) { + for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) { + CheckNeighborsPrecedeInScanOrder(vp9_scan_orders[tx_size][tx_type], + kNumValues[tx_size], "vp9_scan_orders"); + } + } +} + +} // namespace diff --git a/libs/libvpx/test/vp9_subtract_test.cc b/libs/libvpx/test/vp9_subtract_test.cc index 211cc6c7ad..cea71638aa 100644 --- a/libs/libvpx/test/vp9_subtract_test.cc +++ b/libs/libvpx/test/vp9_subtract_test.cc @@ -7,8 +7,10 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include +#include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp9_rtcd.h" #include "./vpx_config.h" @@ -17,24 +19,25 @@ #include "test/bench.h" #include "test/clear_system_state.h" #include "test/register_state_check.h" +#include "test/util.h" #include "vp9/common/vp9_blockd.h" -#include "vpx_ports/msvc.h" #include "vpx_mem/vpx_mem.h" +#include "vpx_ports/vpx_timer.h" -typedef void (*SubtractFunc)(int rows, int cols, int16_t *diff_ptr, - ptrdiff_t diff_stride, const uint8_t *src_ptr, - ptrdiff_t src_stride, const uint8_t *pred_ptr, - ptrdiff_t pred_stride); +using SubtractFunc = void (*)(int rows, int cols, int16_t *diff_ptr, + ptrdiff_t diff_stride, const uint8_t *src_ptr, + ptrdiff_t src_stride, const uint8_t *pred_ptr, + ptrdiff_t pred_stride); namespace vp9 { class VP9SubtractBlockTest : public AbstractBench, public ::testing::TestWithParam { public: - virtual void TearDown() { libvpx_test::ClearSystemState(); } + void TearDown() override { libvpx_test::ClearSystemState(); } protected: - virtual void Run() { + void Run() override { GetParam()(block_height_, block_width_, diff_, block_width_, src_, block_width_, pred_, block_width_); } @@ -129,10 +132,14 @@ TEST_P(VP9SubtractBlockTest, SimpleSubtract) { INSTANTIATE_TEST_SUITE_P(C, VP9SubtractBlockTest, ::testing::Values(vpx_subtract_block_c)); -#if HAVE_SSE2 +#if HAVE_SSE2 && HAVE_X86_ASM INSTANTIATE_TEST_SUITE_P(SSE2, VP9SubtractBlockTest, ::testing::Values(vpx_subtract_block_sse2)); #endif +#if HAVE_AVX2 +INSTANTIATE_TEST_SUITE_P(AVX2, VP9SubtractBlockTest, + ::testing::Values(vpx_subtract_block_avx2)); +#endif #if HAVE_NEON INSTANTIATE_TEST_SUITE_P(NEON, VP9SubtractBlockTest, ::testing::Values(vpx_subtract_block_neon)); @@ -157,4 +164,158 @@ INSTANTIATE_TEST_SUITE_P(LSX, VP9SubtractBlockTest, ::testing::Values(vpx_subtract_block_lsx)); #endif +#if CONFIG_VP9_HIGHBITDEPTH + +using HBDSubtractFunc = void (*)(int rows, int cols, int16_t *diff_ptr, + ptrdiff_t diff_stride, const uint8_t *src_ptr, + ptrdiff_t src_stride, const uint8_t *pred_ptr, + ptrdiff_t pred_stride, int bd); + +// +using Params = std::tuple; + +class VPXHBDSubtractBlockTest : public ::testing::TestWithParam { + public: + void SetUp() override { + block_width_ = 4 * num_4x4_blocks_wide_lookup[GET_PARAM(0)]; + block_height_ = 4 * num_4x4_blocks_high_lookup[GET_PARAM(0)]; + bit_depth_ = static_cast(GET_PARAM(1)); + func_ = GET_PARAM(2); + ref_func_ = GET_PARAM(3); + + rnd_.Reset(ACMRandom::DeterministicSeed()); + + constexpr size_t kMaxWidth = 128; + constexpr size_t kMaxBlockSize = kMaxWidth * kMaxWidth; + src_ = CONVERT_TO_BYTEPTR(reinterpret_cast( + vpx_memalign(16, kMaxBlockSize * sizeof(uint16_t)))); + ASSERT_NE(src_, nullptr); + pred_ = CONVERT_TO_BYTEPTR(reinterpret_cast( + vpx_memalign(16, kMaxBlockSize * sizeof(uint16_t)))); + ASSERT_NE(pred_, nullptr); + diff_ = reinterpret_cast( + vpx_memalign(16, kMaxBlockSize * sizeof(int16_t))); + ASSERT_NE(diff_, nullptr); + } + + void TearDown() override { + vpx_free(CONVERT_TO_SHORTPTR(src_)); + vpx_free(CONVERT_TO_SHORTPTR(pred_)); + vpx_free(diff_); + } + + protected: + void CheckResult(); + void RunForSpeed(); + + private: + ACMRandom rnd_; + int block_height_; + int block_width_; + vpx_bit_depth_t bit_depth_; + HBDSubtractFunc func_; + HBDSubtractFunc ref_func_; + uint8_t *src_; + uint8_t *pred_; + int16_t *diff_; +}; + +void VPXHBDSubtractBlockTest::CheckResult() { + constexpr int kTestNum = 100; + constexpr int kMaxWidth = 128; + constexpr int kMaxBlockSize = kMaxWidth * kMaxWidth; + const int mask = (1 << bit_depth_) - 1; + for (int i = 0; i < kTestNum; ++i) { + for (int j = 0; j < kMaxBlockSize; ++j) { + CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask; + CONVERT_TO_SHORTPTR(pred_)[j] = rnd_.Rand16() & mask; + } + + func_(block_height_, block_width_, diff_, block_width_, src_, block_width_, + pred_, block_width_, bit_depth_); + + for (int r = 0; r < block_height_; ++r) { + for (int c = 0; c < block_width_; ++c) { + EXPECT_EQ(diff_[r * block_width_ + c], + (CONVERT_TO_SHORTPTR(src_)[r * block_width_ + c] - + CONVERT_TO_SHORTPTR(pred_)[r * block_width_ + c])) + << "r = " << r << ", c = " << c << ", test: " << i; + } + } + } +} + +TEST_P(VPXHBDSubtractBlockTest, CheckResult) { CheckResult(); } + +void VPXHBDSubtractBlockTest::RunForSpeed() { + constexpr int kTestNum = 200000; + constexpr int kMaxWidth = 128; + constexpr int kMaxBlockSize = kMaxWidth * kMaxWidth; + const int mask = (1 << bit_depth_) - 1; + + if (ref_func_ == func_) GTEST_SKIP(); + + for (int j = 0; j < kMaxBlockSize; ++j) { + CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask; + CONVERT_TO_SHORTPTR(pred_)[j] = rnd_.Rand16() & mask; + } + + vpx_usec_timer ref_timer; + vpx_usec_timer_start(&ref_timer); + for (int i = 0; i < kTestNum; ++i) { + ref_func_(block_height_, block_width_, diff_, block_width_, src_, + block_width_, pred_, block_width_, bit_depth_); + } + vpx_usec_timer_mark(&ref_timer); + const int64_t ref_elapsed_time = vpx_usec_timer_elapsed(&ref_timer); + + for (int j = 0; j < kMaxBlockSize; ++j) { + CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask; + CONVERT_TO_SHORTPTR(pred_)[j] = rnd_.Rand16() & mask; + } + + vpx_usec_timer timer; + vpx_usec_timer_start(&timer); + for (int i = 0; i < kTestNum; ++i) { + func_(block_height_, block_width_, diff_, block_width_, src_, block_width_, + pred_, block_width_, bit_depth_); + } + vpx_usec_timer_mark(&timer); + const int64_t elapsed_time = vpx_usec_timer_elapsed(&timer); + + printf( + "[%dx%d]: " + "ref_time=%6" PRId64 " \t simd_time=%6" PRId64 + " \t " + "gain=%f \n", + block_width_, block_height_, ref_elapsed_time, elapsed_time, + static_cast(ref_elapsed_time) / + static_cast(elapsed_time)); +} + +TEST_P(VPXHBDSubtractBlockTest, DISABLED_Speed) { RunForSpeed(); } + +const BLOCK_SIZE kValidBlockSize[] = { BLOCK_4X4, BLOCK_4X8, BLOCK_8X4, + BLOCK_8X8, BLOCK_8X16, BLOCK_16X8, + BLOCK_16X16, BLOCK_16X32, BLOCK_32X16, + BLOCK_32X32, BLOCK_32X64, BLOCK_64X32, + BLOCK_64X64 }; + +INSTANTIATE_TEST_SUITE_P( + C, VPXHBDSubtractBlockTest, + ::testing::Combine(::testing::ValuesIn(kValidBlockSize), + ::testing::Values(12), + ::testing::Values(&vpx_highbd_subtract_block_c), + ::testing::Values(&vpx_highbd_subtract_block_c))); + +#if HAVE_AVX2 +INSTANTIATE_TEST_SUITE_P( + AVX2, VPXHBDSubtractBlockTest, + ::testing::Combine(::testing::ValuesIn(kValidBlockSize), + ::testing::Values(12), + ::testing::Values(&vpx_highbd_subtract_block_avx2), + ::testing::Values(&vpx_highbd_subtract_block_c))); +#endif // HAVE_AVX2 + +#endif // CONFIG_VP9_HIGHBITDEPTH } // namespace vp9 diff --git a/libs/libvpx/test/vp9_thread_test.cc b/libs/libvpx/test/vp9_thread_test.cc index 1ceef8185c..387bb4050b 100644 --- a/libs/libvpx/test/vp9_thread_test.cc +++ b/libs/libvpx/test/vp9_thread_test.cc @@ -10,7 +10,7 @@ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "test/codec_factory.h" #include "test/decode_test_driver.h" @@ -26,10 +26,10 @@ using std::string; class VPxWorkerThreadTest : public ::testing::TestWithParam { protected: - virtual ~VPxWorkerThreadTest() {} - virtual void SetUp() { vpx_get_worker_interface()->init(&worker_); } + ~VPxWorkerThreadTest() override = default; + void SetUp() override { vpx_get_worker_interface()->init(&worker_); } - virtual void TearDown() { vpx_get_worker_interface()->end(&worker_); } + void TearDown() override { vpx_get_worker_interface()->end(&worker_); } void Run(VPxWorker *worker) { const bool synchronous = GetParam(); diff --git a/libs/libvpx/test/vp9_tokenize_test.cc b/libs/libvpx/test/vp9_tokenize_test.cc new file mode 100644 index 0000000000..0c1e16cd0d --- /dev/null +++ b/libs/libvpx/test/vp9_tokenize_test.cc @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2026 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "gtest/gtest.h" +#include "vp9/common/vp9_entropy.h" +#include "vp9/encoder/vp9_tokenize.h" + +namespace { + +TEST(VP9Tokenize, Vp9GetTokenInBounds) { + EXPECT_LE(EOB_TOKEN, MAX_TOKEN); + for (int i = -CAT6_MIN_VAL; i <= CAT6_MIN_VAL; ++i) { + auto v = vp9_get_token(i); + EXPECT_LE(v, MAX_TOKEN) << "vp9_get_token(" << i << ")"; + EXPECT_GE(v, 0) << "vp9_get_token(" << i << ")"; + } +} + +} // namespace diff --git a/libs/libvpx/test/vpx_image_test.cc b/libs/libvpx/test/vpx_image_test.cc new file mode 100644 index 0000000000..3523b1395a --- /dev/null +++ b/libs/libvpx/test/vpx_image_test.cc @@ -0,0 +1,316 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include +#include + +#include "vpx/vpx_image.h" +#include "gtest/gtest.h" + +TEST(VpxImageTest, VpxImgWrapInvalidAlign) { + const int kWidth = 128; + const int kHeight = 128; + unsigned char buf[kWidth * kHeight * 3]; + + vpx_image_t img; + // Set img_data and img_data_owner to junk values. vpx_img_wrap() should + // not read these values on failure. + unsigned char empty[] = ""; + img.img_data = empty; + img.img_data_owner = 1; + + vpx_img_fmt_t format = VPX_IMG_FMT_I444; + // 'align' must be a power of 2 but is not. This causes the vpx_img_wrap() + // call to fail. The test verifies we do not read the junk values in 'img'. + unsigned int align = 31; + EXPECT_EQ(vpx_img_wrap(&img, format, kWidth, kHeight, align, buf), nullptr); +} + +TEST(VpxImageTest, VpxImgWrapI42xOddWidth) { + vpx_image_t img; + unsigned char buf[1]; // Should not be read + char str[32]; + for (const auto format : { VPX_IMG_FMT_I420, VPX_IMG_FMT_I422, + VPX_IMG_FMT_I42016, VPX_IMG_FMT_I42216 }) { + for (const int width : { 1, 711, 4913 }) { + snprintf(str, sizeof(str), "format: %d width: %d", format, width); + SCOPED_TRACE(str); + const int stride_in_bytes = + (format & VPX_IMG_FMT_HIGHBITDEPTH) ? width * 2 : width; + const int uv_width = (width + 1) / 2; + const int uv_stride_in_bytes = + (format & VPX_IMG_FMT_HIGHBITDEPTH) ? uv_width * 2 : uv_width; + EXPECT_EQ(vpx_img_wrap(&img, format, width, 32, /*stride_align=*/1, buf), + &img); + EXPECT_EQ(img.stride[VPX_PLANE_Y], stride_in_bytes); + EXPECT_EQ(img.stride[VPX_PLANE_U], uv_stride_in_bytes); + EXPECT_EQ(img.stride[VPX_PLANE_V], uv_stride_in_bytes); + } + } +} + +TEST(VpxImageTest, VpxImgWrapOddHeightSeparatesChromaPlanes) { + static constexpr vpx_img_fmt_t kFormats[] = { + VPX_IMG_FMT_YV12, VPX_IMG_FMT_I420, VPX_IMG_FMT_I440, + VPX_IMG_FMT_I42016, VPX_IMG_FMT_I44016, + }; + static constexpr int kWidth = 16; + static constexpr int kHeight = 3; + unsigned char buf[256]; + + for (const vpx_img_fmt_t format : kFormats) { + vpx_image_t img; + ASSERT_EQ(vpx_img_wrap(&img, format, kWidth, kHeight, + /*stride_align=*/1, buf), + &img); + + const ptrdiff_t chroma_plane_size = + ((kHeight + 1) / 2) * img.stride[VPX_PLANE_U]; + if (format & VPX_IMG_FMT_UV_FLIP) { + EXPECT_EQ(img.planes[VPX_PLANE_U] - img.planes[VPX_PLANE_V], + chroma_plane_size); + } else { + EXPECT_EQ(img.planes[VPX_PLANE_V] - img.planes[VPX_PLANE_U], + chroma_plane_size); + } + } +} + +TEST(VpxImageTest, VpxImgSetRectOverflow) { + const int kWidth = 128; + const int kHeight = 128; + unsigned char buf[kWidth * kHeight * 3]; + + vpx_image_t img; + vpx_img_fmt_t format = VPX_IMG_FMT_I444; + unsigned int align = 32; + EXPECT_EQ(vpx_img_wrap(&img, format, kWidth, kHeight, align, buf), &img); + + EXPECT_EQ(vpx_img_set_rect(&img, 0, 0, kWidth, kHeight), 0); + // This would result in overflow because -1 is cast to UINT_MAX. + EXPECT_NE(vpx_img_set_rect(&img, static_cast(-1), + static_cast(-1), kWidth, kHeight), + 0); +} + +TEST(VpxImageTest, VpxImgSetRectRejectsFlipped) { + static constexpr vpx_img_fmt_t kFormats[] = { + VPX_IMG_FMT_YV12, VPX_IMG_FMT_I420, VPX_IMG_FMT_I422, + VPX_IMG_FMT_I444, VPX_IMG_FMT_I440, VPX_IMG_FMT_NV12, + VPX_IMG_FMT_I42016, VPX_IMG_FMT_I42216, VPX_IMG_FMT_I44416, + VPX_IMG_FMT_I44016, + }; + + for (const vpx_img_fmt_t format : kFormats) { + SCOPED_TRACE(format); + vpx_image_t *img = vpx_img_alloc(nullptr, format, 4, 4, 1); + ASSERT_NE(img, nullptr); + + // An ordinary crop is valid before flipping. + ASSERT_EQ(vpx_img_set_rect(img, 2, 2, 2, 2), 0); + EXPECT_EQ(img->d_w, 2u); + EXPECT_EQ(img->d_h, 2u); + ASSERT_EQ(vpx_img_set_rect(img, 0, 0, 4, 4), 0); + + vpx_img_flip(img); + const unsigned char *const flipped_planes[] = { img->planes[VPX_PLANE_Y], + img->planes[VPX_PLANE_U], + img->planes[VPX_PLANE_V] }; + EXPECT_EQ(vpx_img_set_rect(img, 2, 2, 2, 2), -1); + EXPECT_EQ(img->d_w, 4u); + EXPECT_EQ(img->d_h, 4u); + for (int plane = VPX_PLANE_Y; plane <= VPX_PLANE_V; ++plane) { + EXPECT_EQ(img->planes[plane], flipped_planes[plane]); + } + + // Flipping back permits changing the viewport again. + vpx_img_flip(img); + EXPECT_GT(img->stride[VPX_PLANE_Y], 0); + const unsigned char *const unflipped_y_plane = img->planes[VPX_PLANE_Y]; + EXPECT_EQ(vpx_img_set_rect(img, 2, 2, 2, 2), 0); + EXPECT_NE(img->planes[VPX_PLANE_Y], unflipped_y_plane); + EXPECT_EQ(img->d_w, 2u); + EXPECT_EQ(img->d_h, 2u); + vpx_img_free(img); + } +} + +TEST(VpxImageTest, VpxImgAllocNone) { + const int kWidth = 128; + const int kHeight = 128; + + vpx_image_t img; + vpx_img_fmt_t format = VPX_IMG_FMT_NONE; + unsigned int align = 32; + ASSERT_EQ(vpx_img_alloc(&img, format, kWidth, kHeight, align), nullptr); +} + +TEST(VpxImageTest, VpxImgAllocNv12) { + const int kWidth = 128; + const int kHeight = 128; + + vpx_image_t img; + vpx_img_fmt_t format = VPX_IMG_FMT_NV12; + unsigned int align = 32; + EXPECT_EQ(vpx_img_alloc(&img, format, kWidth, kHeight, align), &img); + EXPECT_EQ(img.x_chroma_shift, 1u); + EXPECT_EQ(img.stride[VPX_PLANE_U], img.stride[VPX_PLANE_Y]); + EXPECT_EQ(img.stride[VPX_PLANE_V], img.stride[VPX_PLANE_U]); + EXPECT_EQ(img.planes[VPX_PLANE_V], img.planes[VPX_PLANE_U] + 1); + vpx_img_free(&img); +} + +TEST(VpxImageTest, VpxImgAllocHugeWidth) { + // The stride (0x80000000 * 2) would overflow unsigned int. + vpx_image_t *image = + vpx_img_alloc(nullptr, VPX_IMG_FMT_I42016, 0x80000000, 1, 1); + ASSERT_EQ(image, nullptr); + + // The stride (0x80000000) would overflow int. + image = vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, 0x80000000, 1, 1); + ASSERT_EQ(image, nullptr); + + // The aligned width (UINT_MAX + 1) would overflow unsigned int. + image = vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, UINT_MAX, 1, 1); + ASSERT_EQ(image, nullptr); + + image = vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, 0x7ffffffe, 1, 1); + if (image) { + vpx_img_free(image); + } + + image = vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, 285245883, 64, 1); + if (image) { + vpx_img_free(image); + } + + image = vpx_img_alloc(nullptr, VPX_IMG_FMT_NV12, 285245883, 64, 1); + if (image) { + vpx_img_free(image); + } + + image = vpx_img_alloc(nullptr, VPX_IMG_FMT_YV12, 285245883, 64, 1); + if (image) { + vpx_img_free(image); + } + + image = vpx_img_alloc(nullptr, VPX_IMG_FMT_I42016, 65536, 2, 1); + if (image) { + uint16_t *y_plane = + reinterpret_cast(image->planes[VPX_PLANE_Y]); + y_plane[0] = 0; + y_plane[image->d_w - 1] = 0; + vpx_img_free(image); + } + + image = vpx_img_alloc(nullptr, VPX_IMG_FMT_I42016, 285245883, 2, 1); + if (image) { + uint16_t *y_plane = + reinterpret_cast(image->planes[VPX_PLANE_Y]); + y_plane[0] = 0; + y_plane[image->d_w - 1] = 0; + vpx_img_free(image); + } +} + +TEST(VpxImageTest, VpxImgFlipNoAlpha) { + vpx_image_t *img = vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, 64, 64, 16); + ASSERT_NE(img, nullptr); + vpx_img_flip(img); + vpx_img_free(img); +} + +TEST(VpxImageTest, VpxImgFlipOneRow) { + vpx_image_t *img = vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, 16, 1, 1); + ASSERT_NE(img, nullptr); + unsigned char *const y_plane = img->planes[VPX_PLANE_Y]; + unsigned char *const u_plane = img->planes[VPX_PLANE_U]; + unsigned char *const v_plane = img->planes[VPX_PLANE_V]; + const int y_stride = img->stride[VPX_PLANE_Y]; + const int u_stride = img->stride[VPX_PLANE_U]; + const int v_stride = img->stride[VPX_PLANE_V]; + + vpx_img_flip(img); + + EXPECT_EQ(img->planes[VPX_PLANE_Y], y_plane); + EXPECT_EQ(img->planes[VPX_PLANE_U], u_plane); + EXPECT_EQ(img->planes[VPX_PLANE_V], v_plane); + EXPECT_EQ(img->stride[VPX_PLANE_Y], -y_stride); + EXPECT_EQ(img->stride[VPX_PLANE_U], -u_stride); + EXPECT_EQ(img->stride[VPX_PLANE_V], -v_stride); + + vpx_img_flip(img); + + EXPECT_EQ(img->planes[VPX_PLANE_Y], y_plane); + EXPECT_EQ(img->planes[VPX_PLANE_U], u_plane); + EXPECT_EQ(img->planes[VPX_PLANE_V], v_plane); + EXPECT_EQ(img->stride[VPX_PLANE_Y], y_stride); + EXPECT_EQ(img->stride[VPX_PLANE_U], u_stride); + EXPECT_EQ(img->stride[VPX_PLANE_V], v_stride); + + vpx_img_free(img); +} + +TEST(VpxImageTest, VpxImgFlipEmpty) { + vpx_image_t *img = vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, 16, 16, 1); + ASSERT_NE(img, nullptr); + ASSERT_EQ(vpx_img_set_rect(img, 0, 0, 16, 0), 0); + const unsigned char *const planes[] = { img->planes[VPX_PLANE_Y], + img->planes[VPX_PLANE_U], + img->planes[VPX_PLANE_V] }; + + vpx_img_flip(img); + + for (int plane = VPX_PLANE_Y; plane <= VPX_PLANE_V; ++plane) { + EXPECT_EQ(img->planes[plane], planes[plane]); + EXPECT_GT(img->stride[plane], 0); + } + vpx_img_free(img); +} + +TEST(VpxImageTest, VpxImgFlipOddHeight) { + static constexpr vpx_img_fmt_t kFormats[] = { + VPX_IMG_FMT_YV12, VPX_IMG_FMT_I420, VPX_IMG_FMT_I440, + VPX_IMG_FMT_NV12, VPX_IMG_FMT_I42016, VPX_IMG_FMT_I44016, + }; + + for (const vpx_img_fmt_t format : kFormats) { + vpx_image_t *img = vpx_img_alloc(nullptr, format, 16, 3, 1); + ASSERT_NE(img, nullptr); + unsigned char *const y_plane = img->planes[VPX_PLANE_Y]; + unsigned char *const u_plane = img->planes[VPX_PLANE_U]; + unsigned char *const v_plane = img->planes[VPX_PLANE_V]; + const int y_stride = img->stride[VPX_PLANE_Y]; + const int u_stride = img->stride[VPX_PLANE_U]; + const int v_stride = img->stride[VPX_PLANE_V]; + + vpx_img_flip(img); + + EXPECT_EQ(img->planes[VPX_PLANE_Y], y_plane + 2 * y_stride); + EXPECT_EQ(img->planes[VPX_PLANE_U], u_plane + u_stride); + EXPECT_EQ(img->planes[VPX_PLANE_V], v_plane + v_stride); + EXPECT_EQ(img->stride[VPX_PLANE_Y], -y_stride); + EXPECT_EQ(img->stride[VPX_PLANE_U], -u_stride); + EXPECT_EQ(img->stride[VPX_PLANE_V], -v_stride); + + vpx_img_flip(img); + + EXPECT_EQ(img->planes[VPX_PLANE_Y], y_plane); + EXPECT_EQ(img->planes[VPX_PLANE_U], u_plane); + EXPECT_EQ(img->planes[VPX_PLANE_V], v_plane); + EXPECT_EQ(img->stride[VPX_PLANE_Y], y_stride); + EXPECT_EQ(img->stride[VPX_PLANE_U], u_stride); + EXPECT_EQ(img->stride[VPX_PLANE_V], v_stride); + + vpx_img_free(img); + } +} diff --git a/libs/libvpx/test/vpx_scale_test.cc b/libs/libvpx/test/vpx_scale_test.cc index 7eea437fc8..a5307ace93 100644 --- a/libs/libvpx/test/vpx_scale_test.cc +++ b/libs/libvpx/test/vpx_scale_test.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "./vpx_scale_rtcd.h" @@ -30,18 +30,18 @@ const int kNumSizesToTest = 8; #endif const int kSizesToTest[] = { 1, 15, 33, 145, 512, 1025, 3840, 16383 }; -typedef void (*ExtendFrameBorderFunc)(YV12_BUFFER_CONFIG *ybf); -typedef void (*CopyFrameFunc)(const YV12_BUFFER_CONFIG *src_ybf, - YV12_BUFFER_CONFIG *dst_ybf); +using ExtendFrameBorderFunc = void (*)(YV12_BUFFER_CONFIG *ybf); +using CopyFrameFunc = void (*)(const YV12_BUFFER_CONFIG *src_ybf, + YV12_BUFFER_CONFIG *dst_ybf); class ExtendBorderTest : public VpxScaleBase, public ::testing::TestWithParam { public: - virtual ~ExtendBorderTest() {} + ~ExtendBorderTest() override = default; protected: - virtual void SetUp() { extend_fn_ = GetParam(); } + void SetUp() override { extend_fn_ = GetParam(); } void ExtendBorder() { ASM_REGISTER_STATE_CHECK(extend_fn_(&img_)); } @@ -68,10 +68,10 @@ INSTANTIATE_TEST_SUITE_P(C, ExtendBorderTest, class CopyFrameTest : public VpxScaleBase, public ::testing::TestWithParam { public: - virtual ~CopyFrameTest() {} + ~CopyFrameTest() override = default; protected: - virtual void SetUp() { copy_frame_fn_ = GetParam(); } + void SetUp() override { copy_frame_fn_ = GetParam(); } void CopyFrame() { ASM_REGISTER_STATE_CHECK(copy_frame_fn_(&img_, &dst_img_)); diff --git a/libs/libvpx/test/vpx_scale_test.h b/libs/libvpx/test/vpx_scale_test.h index 11c259ae80..89d62fcd7f 100644 --- a/libs/libvpx/test/vpx_scale_test.h +++ b/libs/libvpx/test/vpx_scale_test.h @@ -11,7 +11,7 @@ #ifndef VPX_TEST_VPX_SCALE_TEST_H_ #define VPX_TEST_VPX_SCALE_TEST_H_ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "./vpx_scale_rtcd.h" diff --git a/libs/libvpx/test/webm_video_source.h b/libs/libvpx/test/webm_video_source.h index d245926298..6ab50c849f 100644 --- a/libs/libvpx/test/webm_video_source.h +++ b/libs/libvpx/test/webm_video_source.h @@ -29,16 +29,16 @@ class WebMVideoSource : public CompressedVideoSource { webm_ctx_(new WebmInputContext()), buf_(nullptr), buf_sz_(0), frame_(0), end_of_file_(false) {} - virtual ~WebMVideoSource() { + ~WebMVideoSource() override { if (vpx_ctx_->file != nullptr) fclose(vpx_ctx_->file); webm_free(webm_ctx_); delete vpx_ctx_; delete webm_ctx_; } - virtual void Init() {} + void Init() override {} - virtual void Begin() { + void Begin() override { vpx_ctx_->file = OpenTestDataFile(file_name_); ASSERT_NE(vpx_ctx_->file, nullptr) << "Input file open failed. Filename: " << file_name_; @@ -48,7 +48,7 @@ class WebMVideoSource : public CompressedVideoSource { FillFrame(); } - virtual void Next() { + void Next() override { ++frame_; FillFrame(); } @@ -74,11 +74,11 @@ class WebMVideoSource : public CompressedVideoSource { } while (!webm_ctx_->is_key_frame && !end_of_file_); } - virtual const uint8_t *cxdata() const { + const uint8_t *cxdata() const override { return end_of_file_ ? nullptr : buf_; } - virtual size_t frame_size() const { return buf_sz_; } - virtual unsigned int frame_number() const { return frame_; } + size_t frame_size() const override { return buf_sz_; } + unsigned int frame_number() const override { return frame_; } protected: std::string file_name_; diff --git a/libs/libvpx/test/y4m_test.cc b/libs/libvpx/test/y4m_test.cc index 32f2cd51d3..3865880b60 100644 --- a/libs/libvpx/test/y4m_test.cc +++ b/libs/libvpx/test/y4m_test.cc @@ -10,7 +10,7 @@ #include -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vpx_config.h" #include "./y4menc.h" @@ -78,7 +78,7 @@ class Y4mVideoSourceTest : public ::testing::TestWithParam, protected: Y4mVideoSourceTest() : Y4mVideoSource("", 0, 0) {} - virtual ~Y4mVideoSourceTest() { CloseSource(); } + ~Y4mVideoSourceTest() override { CloseSource(); } virtual void Init(const std::string &file_name, int limit) { file_name_ = file_name; @@ -140,7 +140,7 @@ class Y4mVideoWriteTest : public Y4mVideoSourceTest { protected: Y4mVideoWriteTest() : tmpfile_(nullptr) {} - virtual ~Y4mVideoWriteTest() { + ~Y4mVideoWriteTest() override { delete tmpfile_; input_file_ = nullptr; } @@ -172,7 +172,7 @@ class Y4mVideoWriteTest : public Y4mVideoSourceTest { ReplaceInputFile(tmpfile_->file()); } - virtual void Init(const std::string &file_name, int limit) { + void Init(const std::string &file_name, int limit) override { Y4mVideoSourceTest::Init(file_name, limit); WriteY4mAndReadBack(); } diff --git a/libs/libvpx/test/y4m_video_source.h b/libs/libvpx/test/y4m_video_source.h index 71fbf31931..e43e37d9e4 100644 --- a/libs/libvpx/test/y4m_video_source.h +++ b/libs/libvpx/test/y4m_video_source.h @@ -27,7 +27,7 @@ class Y4mVideoSource : public VideoSource { start_(start), limit_(limit), frame_(0), framerate_numerator_(0), framerate_denominator_(0), y4m_() {} - virtual ~Y4mVideoSource() { + ~Y4mVideoSource() override { vpx_img_free(img_.get()); CloseSource(); } @@ -51,33 +51,33 @@ class Y4mVideoSource : public VideoSource { FillFrame(); } - virtual void Begin() { + void Begin() override { OpenSource(); ReadSourceToStart(); } - virtual void Next() { + void Next() override { ++frame_; FillFrame(); } - virtual vpx_image_t *img() const { + vpx_image_t *img() const override { return (frame_ < limit_) ? img_.get() : nullptr; } // Models a stream where Timebase = 1/FPS, so pts == frame. - virtual vpx_codec_pts_t pts() const { return frame_; } + vpx_codec_pts_t pts() const override { return frame_; } - virtual unsigned long duration() const { return 1; } + unsigned long duration() const override { return 1; } - virtual vpx_rational_t timebase() const { + vpx_rational_t timebase() const override { const vpx_rational_t t = { framerate_denominator_, framerate_numerator_ }; return t; } - virtual unsigned int frame() const { return frame_; } + unsigned int frame() const override { return frame_; } - virtual unsigned int limit() const { return limit_; } + unsigned int limit() const override { return limit_; } virtual void FillFrame() { ASSERT_NE(input_file_, nullptr); diff --git a/libs/libvpx/test/yuv_temporal_filter_test.cc b/libs/libvpx/test/yuv_temporal_filter_test.cc index 2bdcf4d86f..e3a9ae9d27 100644 --- a/libs/libvpx/test/yuv_temporal_filter_test.cc +++ b/libs/libvpx/test/yuv_temporal_filter_test.cc @@ -8,12 +8,13 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "third_party/googletest/src/include/gtest/gtest.h" +#include "gtest/gtest.h" #include "./vp9_rtcd.h" #include "test/acm_random.h" #include "test/buffer.h" #include "test/register_state_check.h" +#include "vpx_config.h" #include "vpx_ports/vpx_timer.h" namespace { @@ -21,7 +22,7 @@ namespace { using ::libvpx_test::ACMRandom; using ::libvpx_test::Buffer; -typedef void (*YUVTemporalFilterFunc)( +using YUVTemporalFilterFunc = void (*)( const uint8_t *y_src, int y_src_stride, const uint8_t *y_pre, int y_pre_stride, const uint8_t *u_src, const uint8_t *v_src, int uv_src_stride, const uint8_t *u_pre, const uint8_t *v_pre, @@ -290,7 +291,7 @@ void ApplyReferenceFilter( class YUVTemporalFilterTest : public ::testing::TestWithParam { public: - virtual void SetUp() { + void SetUp() override { filter_func_ = GetParam().temporal_filter; bd_ = GetParam().bd; use_highbd_ = (bd_ != 8); @@ -694,6 +695,18 @@ INSTANTIATE_TEST_SUITE_P( TemporalFilterWithBd(&wrap_vp9_highbd_apply_temporal_filter_sse4_1_12, 12))); #endif // HAVE_SSE4_1 +#if HAVE_NEON +WRAP_HIGHBD_FUNC(vp9_highbd_apply_temporal_filter_neon, 10) +WRAP_HIGHBD_FUNC(vp9_highbd_apply_temporal_filter_neon, 12) + +INSTANTIATE_TEST_SUITE_P( + NEON, YUVTemporalFilterTest, + ::testing::Values( + TemporalFilterWithBd(&wrap_vp9_highbd_apply_temporal_filter_neon_10, + 10), + TemporalFilterWithBd(&wrap_vp9_highbd_apply_temporal_filter_neon_12, + 12))); +#endif // HAVE_NEON #else INSTANTIATE_TEST_SUITE_P( C, YUVTemporalFilterTest, @@ -704,5 +717,11 @@ INSTANTIATE_TEST_SUITE_P(SSE4_1, YUVTemporalFilterTest, ::testing::Values(TemporalFilterWithBd( &vp9_apply_temporal_filter_sse4_1, 8))); #endif // HAVE_SSE4_1 +#if HAVE_NEON +INSTANTIATE_TEST_SUITE_P(NEON, YUVTemporalFilterTest, + ::testing::Values(TemporalFilterWithBd( + &vp9_apply_temporal_filter_neon, 8))); +#endif // HAVE_NEON #endif // CONFIG_VP9_HIGHBITDEPTH + } // namespace diff --git a/libs/libvpx/test/yuv_video_source.h b/libs/libvpx/test/yuv_video_source.h index 51948c0efb..00003daab9 100644 --- a/libs/libvpx/test/yuv_video_source.h +++ b/libs/libvpx/test/yuv_video_source.h @@ -35,12 +35,12 @@ class YUVVideoSource : public VideoSource { SetSize(width, height, format); } - virtual ~YUVVideoSource() { + ~YUVVideoSource() override { vpx_img_free(img_); if (input_file_) fclose(input_file_); } - virtual void Begin() { + void Begin() override { if (input_file_) fclose(input_file_); input_file_ = OpenTestDataFile(file_name_); ASSERT_NE(input_file_, nullptr) @@ -53,28 +53,28 @@ class YUVVideoSource : public VideoSource { FillFrame(); } - virtual void Next() { + void Next() override { ++frame_; FillFrame(); } - virtual vpx_image_t *img() const { + vpx_image_t *img() const override { return (frame_ < limit_) ? img_ : nullptr; } // Models a stream where Timebase = 1/FPS, so pts == frame. - virtual vpx_codec_pts_t pts() const { return frame_; } + vpx_codec_pts_t pts() const override { return frame_; } - virtual unsigned long duration() const { return 1; } + unsigned long duration() const override { return 1; } - virtual vpx_rational_t timebase() const { + vpx_rational_t timebase() const override { const vpx_rational_t t = { framerate_denominator_, framerate_numerator_ }; return t; } - virtual unsigned int frame() const { return frame_; } + unsigned int frame() const override { return frame_; } - virtual unsigned int limit() const { return limit_; } + unsigned int limit() const override { return limit_; } virtual void SetSize(unsigned int width, unsigned int height, vpx_img_fmt format) { @@ -102,9 +102,44 @@ class YUVVideoSource : public VideoSource { virtual void FillFrame() { ASSERT_NE(input_file_, nullptr); - // Read a frame from input_file. - if (fread(img_->img_data, raw_size_, 1, input_file_) == 0) { - limit_ = frame_; + + // If vpx_img_alloc() pads the row -- for example, to a power of 2 when + // width is odd -- the YUV data needs to be read row-wise to ensure the + // planes refer to the correct data. + const int width_in_bytes = + static_cast(width_ * (img_->bit_depth >> 3)); + if (img_->stride[VPX_PLANE_Y] != width_in_bytes) { + uint8_t *row = img_->planes[VPX_PLANE_Y]; + const int y_stride = img_->stride[VPX_PLANE_Y]; + for (unsigned int y = 0; y < height_; ++y) { + if (fread(row, width_in_bytes, 1, input_file_) == 0) { + limit_ = frame_; + return; + } + row += y_stride; + } + const int uv_width = + (width_in_bytes + img_->x_chroma_shift) >> img_->x_chroma_shift; + const int uv_height = + (height_ + img_->y_chroma_shift) >> img_->y_chroma_shift; + const int last_uv_plane = + (format_ == VPX_IMG_FMT_NV12) ? VPX_PLANE_U : VPX_PLANE_V; + for (int i = VPX_PLANE_U; i <= last_uv_plane; ++i) { + row = img_->planes[i]; + const int stride = img_->stride[i]; + for (int y = 0; y < uv_height; ++y) { + if (fread(row, uv_width, 1, input_file_) == 0) { + limit_ = frame_; + return; + } + row += stride; + } + } + } else { + // Read a frame from input_file. + if (fread(img_->img_data, raw_size_, 1, input_file_) == 0) { + limit_ = frame_; + } } } diff --git a/libs/libvpx/third_party/googletest/README.libvpx b/libs/libvpx/third_party/googletest/README.libvpx index b9a74922f0..6b424d9164 100644 --- a/libs/libvpx/third_party/googletest/README.libvpx +++ b/libs/libvpx/third_party/googletest/README.libvpx @@ -1,21 +1,36 @@ -URL: https://github.com/google/googletest.git -Version: release-1.11.0 -License: BSD -License File: LICENSE +Name: Google Test: Google's C++ Testing Framework +Short Name: googletest +URL: https://github.com/google/googletest +Version: 1.17.0 +Update Mechanism: Manual +Revision: 52eb8108c5bdec04579160ae17225d66034bd723 +License: BSD-3-Clause +License File: src/LICENSE +Shipped in Chromium: no +Security Critical: no Description: Google's framework for writing C++ tests on a variety of platforms -(Linux, Mac OS X, Windows, Windows CE, Symbian, etc). Based on the -xUnit architecture. Supports automatic test discovery, a rich set of +(Linux, macOS, Windows, Android NDK, etc). Based on the xUnit +testing framework. Supports automatic test discovery, a rich set of assertions, user-defined assertions, death tests, fatal and non-fatal -failures, various options for running the tests, and XML test report -generation. +failures, value-parameterized tests, type-parameterized tests, and +various options for running the tests. Local Modifications: - Remove everything but: + .clang-format CONTRIBUTORS googletest/ include README.md src LICENSE +- Move .clang-format, CONTRIBUTORS, and LICENSE into googletest/ +- Apply the patch googletest.patch. The patch defines the Notification + class for MinGW by using a Windows manual-reset event object to fix + the MinGW GCC (version < 13) compilation errors caused by the lack of + std::mutex and std::condition_variable in the and + headers if GCC is configured with the win32 + thread model. See + https://stackoverflow.com/questions/17242516/mingw-w64-threads-posix-vs-win32 diff --git a/libs/libvpx/third_party/googletest/googletest.patch b/libs/libvpx/third_party/googletest/googletest.patch new file mode 100644 index 0000000000..28b1a7f9b3 --- /dev/null +++ b/libs/libvpx/third_party/googletest/googletest.patch @@ -0,0 +1,89 @@ +diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h +index 25b7d194..4a5cde33 100644 +--- a/googletest/include/gtest/internal/gtest-port.h ++++ b/googletest/include/gtest/internal/gtest-port.h +@@ -1237,9 +1237,6 @@ class GTEST_API_ AutoHandle { + // Nothing to do here. + + #else +-GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ +-/* class A needs to have dll-interface to be used by clients of class B */) +- + // Allows a controller thread to pause execution of newly created + // threads until notified. Instances of this class must be created + // and destroyed in the controller thread. +@@ -1247,6 +1244,39 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ + // This class is only for testing Google Test's own constructs. Do not + // use it in user tests, either directly or indirectly. + // TODO(b/203539622): Replace unconditionally with absl::Notification. ++#ifdef GTEST_OS_WINDOWS_MINGW ++// GCC version < 13 with the win32 thread model does not provide std::mutex and ++// std::condition_variable in the and headers. So ++// we implement the Notification class using a Windows manual-reset event. See ++// https://gcc.gnu.org/gcc-13/changes.html#windows. ++class GTEST_API_ Notification { ++ public: ++ Notification(); ++ Notification(const Notification&) = delete; ++ Notification& operator=(const Notification&) = delete; ++ ~Notification(); ++ ++ // Notifies all threads created with this notification to start. Must ++ // be called from the controller thread. ++ void Notify(); ++ ++ // Blocks until the controller thread notifies. Must be called from a test ++ // thread. ++ void WaitForNotification(); ++ ++ private: ++ // Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to ++ // avoid including in this header file. Including is ++ // undesirable because it defines a lot of symbols and macros that tend to ++ // conflict with client code. This assumption is verified by ++ // WindowsTypesTest.HANDLEIsVoidStar. ++ typedef void* Handle; ++ Handle event_; ++}; ++#else ++GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ ++/* class A needs to have dll-interface to be used by clients of class B */) ++ + class GTEST_API_ Notification { + public: + Notification() : notified_(false) {} +@@ -1274,6 +1304,7 @@ class GTEST_API_ Notification { + bool notified_; + }; + GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 ++#endif // GTEST_OS_WINDOWS_MINGW + #endif // GTEST_HAS_NOTIFICATION_ + + // On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD +diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc +index 1038ad7b..53d41d38 100644 +--- a/googletest/src/gtest-port.cc ++++ b/googletest/src/gtest-port.cc +@@ -302,6 +302,22 @@ bool AutoHandle::IsCloseable() const { + return handle_ != nullptr && handle_ != INVALID_HANDLE_VALUE; + } + ++#if !GTEST_HAS_NOTIFICATION_ && defined(GTEST_OS_WINDOWS_MINGW) ++Notification::Notification() { ++ // Create a manual-reset event object. ++ event_ = ::CreateEvent(nullptr, TRUE, FALSE, nullptr); ++ GTEST_CHECK_(event_ != nullptr); ++} ++ ++Notification::~Notification() { ::CloseHandle(event_); } ++ ++void Notification::Notify() { GTEST_CHECK_(::SetEvent(event_)); } ++ ++void Notification::WaitForNotification() { ++ GTEST_CHECK_(::WaitForSingleObject(event_, INFINITE) == WAIT_OBJECT_0); ++} ++#endif // !GTEST_HAS_NOTIFICATION_ && defined(GTEST_OS_WINDOWS_MINGW) ++ + Mutex::Mutex() + : owner_thread_id_(0), + type_(kDynamic), diff --git a/libs/libvpx/third_party/googletest/src/.clang-format b/libs/libvpx/third_party/googletest/src/.clang-format new file mode 100644 index 0000000000..5b9bfe6d22 --- /dev/null +++ b/libs/libvpx/third_party/googletest/src/.clang-format @@ -0,0 +1,4 @@ +# Run manually to reformat a file: +# clang-format -i --style=file +Language: Cpp +BasedOnStyle: Google diff --git a/libs/libvpx/third_party/googletest/src/CONTRIBUTORS b/libs/libvpx/third_party/googletest/src/CONTRIBUTORS index 76db0b40ff..ccea41ea81 100644 --- a/libs/libvpx/third_party/googletest/src/CONTRIBUTORS +++ b/libs/libvpx/third_party/googletest/src/CONTRIBUTORS @@ -34,6 +34,7 @@ Manuel Klimek Mario Tanev Mark Paskin Markus Heule +Martijn Vels Matthew Simmons Mika Raento Mike Bland @@ -54,7 +55,9 @@ Russ Cox Russ Rufer Sean Mcafee Sigurður Ásgeirsson +Soyeon Kim Sverre Sundsdal +Szymon Sobik Takeshi Yoshino Tracy Bialik Vadim Berman diff --git a/libs/libvpx/third_party/googletest/src/README.md b/libs/libvpx/third_party/googletest/src/README.md index 1f8b349ae7..a760759eb0 100644 --- a/libs/libvpx/third_party/googletest/src/README.md +++ b/libs/libvpx/third_party/googletest/src/README.md @@ -9,10 +9,10 @@ depends on which build system you use, and is usually straightforward. ### Build with CMake GoogleTest comes with a CMake build script -([CMakeLists.txt](https://github.com/google/googletest/blob/master/CMakeLists.txt)) +([CMakeLists.txt](https://github.com/google/googletest/blob/main/CMakeLists.txt)) that can be used on a wide range of platforms ("C" stands for cross-platform.). If you don't have CMake installed already, you can download it for free from -. +. CMake works by generating native makefiles or build projects that can be used in the compiler environment of your choice. You can either build GoogleTest as a @@ -25,7 +25,7 @@ When building GoogleTest as a standalone project, the typical workflow starts with ``` -git clone https://github.com/google/googletest.git -b release-1.10.0 +git clone https://github.com/google/googletest.git -b v1.17.0 cd googletest # Main directory of the cloned repository. mkdir build # Create a directory to hold the build output. cd build @@ -94,7 +94,7 @@ include(FetchContent) FetchContent_Declare( googletest # Specify the commit you depend on and update it regularly. - URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip + URL https://github.com/google/googletest/archive/5376968f6948923e2411081fd9372e71a59d8e77.zip ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) @@ -124,12 +124,12 @@ match the project in which it is included. #### C++ Standard Version -An environment that supports C++11 is required in order to successfully build +An environment that supports C++17 is required in order to successfully build GoogleTest. One way to ensure this is to specify the standard in the top-level -project, for example by using the `set(CMAKE_CXX_STANDARD 11)` command. If this -is not feasible, for example in a C project using GoogleTest for validation, -then it can be specified by adding it to the options for cmake via the -`DCMAKE_CXX_FLAGS` option. +project, for example by using the `set(CMAKE_CXX_STANDARD 17)` command along +with `set(CMAKE_CXX_STANDARD_REQUIRED ON)`. If this is not feasible, for example +in a C project using GoogleTest for validation, then it can be specified by +adding it to the options for cmake via the`-DCMAKE_CXX_FLAGS` option. ### Tweaking GoogleTest @@ -140,23 +140,27 @@ command line. Generally, these macros are named like `GTEST_XYZ` and you define them to either 1 or 0 to enable or disable a certain feature. We list the most frequently used macros below. For a complete list, see file -[include/gtest/internal/gtest-port.h](https://github.com/google/googletest/blob/master/googletest/include/gtest/internal/gtest-port.h). +[include/gtest/internal/gtest-port.h](https://github.com/google/googletest/blob/main/googletest/include/gtest/internal/gtest-port.h). ### Multi-threaded Tests GoogleTest is thread-safe where the pthread library is available. After -`#include "gtest/gtest.h"`, you can check the +`#include `, you can check the `GTEST_IS_THREADSAFE` macro to see whether this is the case (yes if the macro is `#defined` to 1, no if it's undefined.). If GoogleTest doesn't correctly detect whether pthread is available in your environment, you can force it with - -DGTEST_HAS_PTHREAD=1 +``` +-DGTEST_HAS_PTHREAD=1 +``` or - -DGTEST_HAS_PTHREAD=0 +``` +-DGTEST_HAS_PTHREAD=0 +``` When GoogleTest uses pthread, you may need to add flags to your compiler and/or linker to select the pthread library, or you'll get link errors. If you use the @@ -172,23 +176,27 @@ as a DLL on Windows) if you prefer. To compile *gtest* as a shared library, add - -DGTEST_CREATE_SHARED_LIBRARY=1 +``` +-DGTEST_CREATE_SHARED_LIBRARY=1 +``` to the compiler flags. You'll also need to tell the linker to produce a shared library instead - consult your linker's manual for how to do it. To compile your *tests* that use the gtest shared library, add - -DGTEST_LINKED_AS_SHARED_LIBRARY=1 +``` +-DGTEST_LINKED_AS_SHARED_LIBRARY=1 +``` to the compiler flags. Note: while the above steps aren't technically necessary today when using some compilers (e.g. GCC), they may become necessary in the future, if we decide to improve the speed of loading the library (see - for details). Therefore you are recommended -to always add the above flags when using GoogleTest as a shared library. -Otherwise a future release of GoogleTest may break your build script. + for details). Therefore you are +recommended to always add the above flags when using GoogleTest as a shared +library. Otherwise a future release of GoogleTest may break your build script. ### Avoiding Macro Name Clashes @@ -200,16 +208,24 @@ rename its macro to avoid the conflict. Specifically, if both GoogleTest and some other code define macro FOO, you can add - -DGTEST_DONT_DEFINE_FOO=1 +``` +-DGTEST_DONT_DEFINE_FOO=1 +``` to the compiler flags to tell GoogleTest to change the macro's name from `FOO` -to `GTEST_FOO`. Currently `FOO` can be `FAIL`, `SUCCEED`, or `TEST`. For +to `GTEST_FOO`. Currently `FOO` can be `ASSERT_EQ`, `ASSERT_FALSE`, `ASSERT_GE`, +`ASSERT_GT`, `ASSERT_LE`, `ASSERT_LT`, `ASSERT_NE`, `ASSERT_TRUE`, +`EXPECT_FALSE`, `EXPECT_TRUE`, `FAIL`, `SUCCEED`, `TEST`, or `TEST_F`. For example, with `-DGTEST_DONT_DEFINE_TEST=1`, you'll need to write - GTEST_TEST(SomeTest, DoesThis) { ... } +``` +GTEST_TEST(SomeTest, DoesThis) { ... } +``` instead of - TEST(SomeTest, DoesThis) { ... } +``` +TEST(SomeTest, DoesThis) { ... } +``` in order to define a test. diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-assertion-result.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-assertion-result.h new file mode 100644 index 0000000000..954e7c40f3 --- /dev/null +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-assertion-result.h @@ -0,0 +1,244 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// The Google C++ Testing and Mocking Framework (Google Test) +// +// This file implements the AssertionResult type. + +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* + +#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_ASSERTION_RESULT_H_ +#define GOOGLETEST_INCLUDE_GTEST_GTEST_ASSERTION_RESULT_H_ + +#include +#include +#include +#include + +#include "gtest/gtest-message.h" +#include "gtest/internal/gtest-port.h" + +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ +/* class A needs to have dll-interface to be used by clients of class B */) + +namespace testing { + +// A class for indicating whether an assertion was successful. When +// the assertion wasn't successful, the AssertionResult object +// remembers a non-empty message that describes how it failed. +// +// To create an instance of this class, use one of the factory functions +// (AssertionSuccess() and AssertionFailure()). +// +// This class is useful for two purposes: +// 1. Defining predicate functions to be used with Boolean test assertions +// EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts +// 2. Defining predicate-format functions to be +// used with predicate assertions (ASSERT_PRED_FORMAT*, etc). +// +// For example, if you define IsEven predicate: +// +// testing::AssertionResult IsEven(int n) { +// if ((n % 2) == 0) +// return testing::AssertionSuccess(); +// else +// return testing::AssertionFailure() << n << " is odd"; +// } +// +// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5))) +// will print the message +// +// Value of: IsEven(Fib(5)) +// Actual: false (5 is odd) +// Expected: true +// +// instead of a more opaque +// +// Value of: IsEven(Fib(5)) +// Actual: false +// Expected: true +// +// in case IsEven is a simple Boolean predicate. +// +// If you expect your predicate to be reused and want to support informative +// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up +// about half as often as positive ones in our tests), supply messages for +// both success and failure cases: +// +// testing::AssertionResult IsEven(int n) { +// if ((n % 2) == 0) +// return testing::AssertionSuccess() << n << " is even"; +// else +// return testing::AssertionFailure() << n << " is odd"; +// } +// +// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print +// +// Value of: IsEven(Fib(6)) +// Actual: true (8 is even) +// Expected: false +// +// NB: Predicates that support negative Boolean assertions have reduced +// performance in positive ones so be careful not to use them in tests +// that have lots (tens of thousands) of positive Boolean assertions. +// +// To use this class with EXPECT_PRED_FORMAT assertions such as: +// +// // Verifies that Foo() returns an even number. +// EXPECT_PRED_FORMAT1(IsEven, Foo()); +// +// you need to define: +// +// testing::AssertionResult IsEven(const char* expr, int n) { +// if ((n % 2) == 0) +// return testing::AssertionSuccess(); +// else +// return testing::AssertionFailure() +// << "Expected: " << expr << " is even\n Actual: it's " << n; +// } +// +// If Foo() returns 5, you will see the following message: +// +// Expected: Foo() is even +// Actual: it's 5 +// + +// Returned AssertionResult objects may not be ignored. +// Note: Disabled for SWIG as it doesn't parse attributes correctly. +#if !defined(SWIG) +class [[nodiscard]] AssertionResult; +#endif // !SWIG + +class GTEST_API_ AssertionResult { + public: + // Copy constructor. + // Used in EXPECT_TRUE/FALSE(assertion_result). + AssertionResult(const AssertionResult& other); + +// C4800 is a level 3 warning in Visual Studio 2015 and earlier. +// This warning is not emitted in Visual Studio 2017. +// This warning is off by default starting in Visual Studio 2019 but can be +// enabled with command-line options. +#if defined(_MSC_VER) && (_MSC_VER < 1910 || _MSC_VER >= 1920) + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */) +#endif + + // Used in the EXPECT_TRUE/FALSE(bool_expression). + // + // T must be contextually convertible to bool. + // + // The second parameter prevents this overload from being considered if + // the argument is implicitly convertible to AssertionResult. In that case + // we want AssertionResult's copy constructor to be used. + template + explicit AssertionResult( + const T& success, + typename std::enable_if< + !std::is_convertible::value>::type* + /*enabler*/ + = nullptr) + : success_(success) {} + +#if defined(_MSC_VER) && (_MSC_VER < 1910 || _MSC_VER >= 1920) + GTEST_DISABLE_MSC_WARNINGS_POP_() +#endif + + // Assignment operator. + AssertionResult& operator=(AssertionResult other) { + swap(other); + return *this; + } + + // Returns true if and only if the assertion succeeded. + operator bool() const { return success_; } // NOLINT + + // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. + AssertionResult operator!() const; + + // Returns the text streamed into this AssertionResult. Test assertions + // use it when they fail (i.e., the predicate's outcome doesn't match the + // assertion's expectation). When nothing has been streamed into the + // object, returns an empty string. + const char* message() const { + return message_ != nullptr ? message_->c_str() : ""; + } + // Deprecated; please use message() instead. + const char* failure_message() const { return message(); } + + // Streams a custom failure message into this object. + template + AssertionResult& operator<<(const T& value) { + AppendMessage(Message() << value); + return *this; + } + + // Allows streaming basic output manipulators such as endl or flush into + // this object. + AssertionResult& operator<<( + ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) { + AppendMessage(Message() << basic_manipulator); + return *this; + } + + private: + // Appends the contents of message to message_. + void AppendMessage(const Message& a_message) { + if (message_ == nullptr) message_ = ::std::make_unique<::std::string>(); + message_->append(a_message.GetString().c_str()); + } + + // Swap the contents of this AssertionResult with other. + void swap(AssertionResult& other); + + // Stores result of the assertion predicate. + bool success_; + // Stores the message describing the condition in case the expectation + // construct is not satisfied with the predicate's outcome. + // Referenced via a pointer to avoid taking too much stack frame space + // with test assertions. + std::unique_ptr< ::std::string> message_; +}; + +// Makes a successful assertion result. +GTEST_API_ AssertionResult AssertionSuccess(); + +// Makes a failed assertion result. +GTEST_API_ AssertionResult AssertionFailure(); + +// Makes a failed assertion result with the given failure message. +// Deprecated; use AssertionFailure() << msg. +GTEST_API_ AssertionResult AssertionFailure(const Message& msg); + +} // namespace testing + +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 + +#endif // GOOGLETEST_INCLUDE_GTEST_GTEST_ASSERTION_RESULT_H_ diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-death-test.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-death-test.h index 9b4d4d1337..3c61909726 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-death-test.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-death-test.h @@ -27,21 +27,21 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// // The Google C++ Testing and Mocking Framework (Google Test) // // This header file defines the public API for death tests. It is // #included by gtest.h so a user doesn't need to include this // directly. -// GOOGLETEST_CM0001 DO NOT DELETE + +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ #include "gtest/internal/gtest-death-test-internal.h" -namespace testing { - // This flag controls the style of death tests. Valid values are "threadsafe", // meaning that the death test child process will re-execute the test binary // from the start, running only a single death test, or "fast", @@ -49,7 +49,9 @@ namespace testing { // after forking. GTEST_DECLARE_string_(death_test_style); -#if GTEST_HAS_DEATH_TEST +namespace testing { + +#ifdef GTEST_HAS_DEATH_TEST namespace internal { @@ -103,7 +105,6 @@ GTEST_API_ bool InDeathTestChild(); // // On the regular expressions used in death tests: // -// GOOGLETEST_CM0005 DO NOT DELETE // On POSIX-compliant systems (*nix), we use the library, // which uses the POSIX extended regex syntax. // @@ -169,24 +170,24 @@ GTEST_API_ bool InDeathTestChild(); // Asserts that a given `statement` causes the program to exit, with an // integer exit status that satisfies `predicate`, and emitting error output // that matches `matcher`. -# define ASSERT_EXIT(statement, predicate, matcher) \ - GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_FATAL_FAILURE_) +#define ASSERT_EXIT(statement, predicate, matcher) \ + GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_FATAL_FAILURE_) // Like `ASSERT_EXIT`, but continues on to successive tests in the // test suite, if any: -# define EXPECT_EXIT(statement, predicate, matcher) \ - GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_NONFATAL_FAILURE_) +#define EXPECT_EXIT(statement, predicate, matcher) \ + GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_NONFATAL_FAILURE_) // Asserts that a given `statement` causes the program to exit, either by // explicitly exiting with a nonzero exit code or being killed by a // signal, and emitting error output that matches `matcher`. -# define ASSERT_DEATH(statement, matcher) \ - ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher) +#define ASSERT_DEATH(statement, matcher) \ + ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher) // Like `ASSERT_DEATH`, but continues on to successive tests in the // test suite, if any: -# define EXPECT_DEATH(statement, matcher) \ - EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher) +#define EXPECT_DEATH(statement, matcher) \ + EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher) // Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*: @@ -197,22 +198,23 @@ class GTEST_API_ ExitedWithCode { ExitedWithCode(const ExitedWithCode&) = default; void operator=(const ExitedWithCode& other) = delete; bool operator()(int exit_status) const; + private: const int exit_code_; }; -# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA +#if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA) // Tests that an exit code describes an exit due to termination by a // given signal. -// GOOGLETEST_CM0006 DO NOT DELETE class GTEST_API_ KilledBySignal { public: explicit KilledBySignal(int signum); bool operator()(int exit_status) const; + private: const int signum_; }; -# endif // !GTEST_OS_WINDOWS +#endif // !GTEST_OS_WINDOWS // EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode. // The death testing framework causes this to have interesting semantics, @@ -257,23 +259,21 @@ class GTEST_API_ KilledBySignal { // EXPECT_EQ(12, DieInDebugOr12(&sideeffect)); // }, "death"); // -# ifdef NDEBUG +#ifdef NDEBUG -# define EXPECT_DEBUG_DEATH(statement, regex) \ +#define EXPECT_DEBUG_DEATH(statement, regex) \ GTEST_EXECUTE_STATEMENT_(statement, regex) -# define ASSERT_DEBUG_DEATH(statement, regex) \ +#define ASSERT_DEBUG_DEATH(statement, regex) \ GTEST_EXECUTE_STATEMENT_(statement, regex) -# else +#else -# define EXPECT_DEBUG_DEATH(statement, regex) \ - EXPECT_DEATH(statement, regex) +#define EXPECT_DEBUG_DEATH(statement, regex) EXPECT_DEATH(statement, regex) -# define ASSERT_DEBUG_DEATH(statement, regex) \ - ASSERT_DEATH(statement, regex) +#define ASSERT_DEBUG_DEATH(statement, regex) ASSERT_DEATH(statement, regex) -# endif // NDEBUG for EXPECT_DEBUG_DEATH +#endif // NDEBUG for EXPECT_DEBUG_DEATH #endif // GTEST_HAS_DEATH_TEST // This macro is used for implementing macros such as @@ -293,8 +293,8 @@ class GTEST_API_ KilledBySignal { // statement is compiled but not executed, to ensure that // EXPECT_DEATH_IF_SUPPORTED compiles with a certain // parameter if and only if EXPECT_DEATH compiles with it. -// regex - A regex that a macro such as EXPECT_DEATH would use to test -// the output of statement. This parameter has to be +// regex_or_matcher - A regex that a macro such as EXPECT_DEATH would use +// to test the output of statement. This parameter has to be // compiled but not evaluated by this macro, to ensure that // this macro only accepts expressions that a macro such as // EXPECT_DEATH would accept. @@ -311,34 +311,33 @@ class GTEST_API_ KilledBySignal { // statement unconditionally returns or throws. The Message constructor at // the end allows the syntax of streaming additional messages into the // macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH. -# define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::AlwaysTrue()) { \ - GTEST_LOG_(WARNING) \ - << "Death tests are not supported on this platform.\n" \ - << "Statement '" #statement "' cannot be verified."; \ - } else if (::testing::internal::AlwaysFalse()) { \ - ::testing::internal::RE::PartialMatch(".*", (regex)); \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - terminator; \ - } else \ - ::testing::Message() +#define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex_or_matcher, terminator) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + GTEST_LOG_(WARNING) << "Death tests are not supported on this platform.\n" \ + << "Statement '" #statement "' cannot be verified."; \ + } else if (::testing::internal::AlwaysFalse()) { \ + ::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + terminator; \ + } else \ + ::testing::Message() // EXPECT_DEATH_IF_SUPPORTED(statement, regex) and // ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if // death tests are supported; otherwise they just issue a warning. This is // useful when you are combining death test assertions with normal test // assertions in one test. -#if GTEST_HAS_DEATH_TEST -# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ - EXPECT_DEATH(statement, regex) -# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ - ASSERT_DEATH(statement, regex) +#ifdef GTEST_HAS_DEATH_TEST +#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ + EXPECT_DEATH(statement, regex) +#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ + ASSERT_DEATH(statement, regex) #else -# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ - GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, ) -# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ - GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return) +#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ + GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, ) +#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ + GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return) #endif } // namespace testing diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-matchers.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-matchers.h index 9fa34a05ba..78160f0e41 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-matchers.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-matchers.h @@ -32,10 +32,15 @@ // This file implements just enough of the matcher interface to allow // EXPECT_DEATH and friends to accept a matcher argument. +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* + #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_MATCHERS_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_MATCHERS_H_ #include +#include #include #include #include @@ -62,10 +67,10 @@ namespace testing { // To implement a matcher Foo for type T, define: // 1. a class FooMatcherMatcher that implements the matcher interface: // using is_gtest_matcher = void; -// bool MatchAndExplain(const T&, std::ostream*); +// bool MatchAndExplain(const T&, std::ostream*) const; // (MatchResultListener* can also be used instead of std::ostream*) -// void DescribeTo(std::ostream*); -// void DescribeNegationTo(std::ostream*); +// void DescribeTo(std::ostream*) const; +// void DescribeNegationTo(std::ostream*) const; // // 2. a factory function that creates a Matcher object from a // FooMatcherMatcher. @@ -98,17 +103,17 @@ class MatchResultListener { private: ::std::ostream* const stream_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener); + MatchResultListener(const MatchResultListener&) = delete; + MatchResultListener& operator=(const MatchResultListener&) = delete; }; -inline MatchResultListener::~MatchResultListener() { -} +inline MatchResultListener::~MatchResultListener() = default; // An instance of a subclass of this knows how to describe itself as a // matcher. class GTEST_API_ MatcherDescriberInterface { public: - virtual ~MatcherDescriberInterface() {} + virtual ~MatcherDescriberInterface() = default; // Describes this matcher to an ostream. The function should print // a verb phrase that describes the property a value matching this @@ -174,38 +179,14 @@ class MatcherInterface : public MatcherDescriberInterface { namespace internal { -struct AnyEq { - template - bool operator()(const A& a, const B& b) const { return a == b; } -}; -struct AnyNe { - template - bool operator()(const A& a, const B& b) const { return a != b; } -}; -struct AnyLt { - template - bool operator()(const A& a, const B& b) const { return a < b; } -}; -struct AnyGt { - template - bool operator()(const A& a, const B& b) const { return a > b; } -}; -struct AnyLe { - template - bool operator()(const A& a, const B& b) const { return a <= b; } -}; -struct AnyGe { - template - bool operator()(const A& a, const B& b) const { return a >= b; } -}; - // A match result listener that ignores the explanation. class DummyMatchResultListener : public MatchResultListener { public: DummyMatchResultListener() : MatchResultListener(nullptr) {} private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener); + DummyMatchResultListener(const DummyMatchResultListener&) = delete; + DummyMatchResultListener& operator=(const DummyMatchResultListener&) = delete; }; // A match result listener that forwards the explanation to a given @@ -217,7 +198,9 @@ class StreamMatchResultListener : public MatchResultListener { : MatchResultListener(os) {} private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener); + StreamMatchResultListener(const StreamMatchResultListener&) = delete; + StreamMatchResultListener& operator=(const StreamMatchResultListener&) = + delete; }; struct SharedPayloadBase { @@ -284,17 +267,18 @@ class MatcherBase : private MatcherDescriberInterface { } protected: - MatcherBase() : vtable_(nullptr) {} + MatcherBase() : vtable_(nullptr), buffer_() {} // Constructs a matcher from its implementation. template - explicit MatcherBase(const MatcherInterface* impl) { + explicit MatcherBase(const MatcherInterface* impl) + : vtable_(nullptr), buffer_() { Init(impl); } template ::type::is_gtest_matcher> - MatcherBase(M&& m) { // NOLINT + MatcherBase(M&& m) : vtable_(nullptr), buffer_() { // NOLINT Init(std::forward(m)); } @@ -420,8 +404,8 @@ class MatcherBase : private MatcherDescriberInterface { static const M& Get(const MatcherBase& m) { // When inlined along with Init, need to be explicit to avoid violating // strict aliasing rules. - const M *ptr = static_cast( - static_cast(&m.buffer_)); + const M* ptr = + static_cast(static_cast(&m.buffer_)); return *ptr; } static void Init(MatcherBase& m, M impl) { @@ -510,7 +494,7 @@ template <> class GTEST_API_ Matcher : public internal::MatcherBase { public: - Matcher() {} + Matcher() = default; explicit Matcher(const MatcherInterface* impl) : internal::MatcherBase(impl) {} @@ -532,7 +516,7 @@ template <> class GTEST_API_ Matcher : public internal::MatcherBase { public: - Matcher() {} + Matcher() = default; explicit Matcher(const MatcherInterface* impl) : internal::MatcherBase(impl) {} @@ -560,7 +544,7 @@ template <> class GTEST_API_ Matcher : public internal::MatcherBase { public: - Matcher() {} + Matcher() = default; explicit Matcher(const MatcherInterface* impl) : internal::MatcherBase(impl) {} @@ -586,7 +570,7 @@ template <> class GTEST_API_ Matcher : public internal::MatcherBase { public: - Matcher() {} + Matcher() = default; explicit Matcher(const MatcherInterface* impl) : internal::MatcherBase(impl) {} @@ -738,50 +722,53 @@ class ComparisonBase { }; template -class EqMatcher : public ComparisonBase, Rhs, AnyEq> { +class EqMatcher : public ComparisonBase, Rhs, std::equal_to<>> { public: explicit EqMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyEq>(rhs) { } + : ComparisonBase, Rhs, std::equal_to<>>(rhs) {} static const char* Desc() { return "is equal to"; } static const char* NegatedDesc() { return "isn't equal to"; } }; template -class NeMatcher : public ComparisonBase, Rhs, AnyNe> { +class NeMatcher + : public ComparisonBase, Rhs, std::not_equal_to<>> { public: explicit NeMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyNe>(rhs) { } + : ComparisonBase, Rhs, std::not_equal_to<>>(rhs) {} static const char* Desc() { return "isn't equal to"; } static const char* NegatedDesc() { return "is equal to"; } }; template -class LtMatcher : public ComparisonBase, Rhs, AnyLt> { +class LtMatcher : public ComparisonBase, Rhs, std::less<>> { public: explicit LtMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyLt>(rhs) { } + : ComparisonBase, Rhs, std::less<>>(rhs) {} static const char* Desc() { return "is <"; } static const char* NegatedDesc() { return "isn't <"; } }; template -class GtMatcher : public ComparisonBase, Rhs, AnyGt> { +class GtMatcher : public ComparisonBase, Rhs, std::greater<>> { public: explicit GtMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyGt>(rhs) { } + : ComparisonBase, Rhs, std::greater<>>(rhs) {} static const char* Desc() { return "is >"; } static const char* NegatedDesc() { return "isn't >"; } }; template -class LeMatcher : public ComparisonBase, Rhs, AnyLe> { +class LeMatcher + : public ComparisonBase, Rhs, std::less_equal<>> { public: explicit LeMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyLe>(rhs) { } + : ComparisonBase, Rhs, std::less_equal<>>(rhs) {} static const char* Desc() { return "is <="; } static const char* NegatedDesc() { return "isn't <="; } }; template -class GeMatcher : public ComparisonBase, Rhs, AnyGe> { +class GeMatcher + : public ComparisonBase, Rhs, std::greater_equal<>> { public: explicit GeMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyGe>(rhs) { } + : ComparisonBase, Rhs, std::greater_equal<>>(rhs) {} static const char* Desc() { return "is >="; } static const char* NegatedDesc() { return "isn't >="; } }; @@ -822,7 +809,7 @@ class MatchesRegexMatcher { template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const std::string& s2(s); + const std::string s2(s); return full_match_ ? RE::FullMatch(s2, *regex_) : RE::PartialMatch(s2, *regex_); } @@ -872,12 +859,16 @@ PolymorphicMatcher ContainsRegex( // Note: if the parameter of Eq() were declared as const T&, Eq("foo") // wouldn't compile. template -inline internal::EqMatcher Eq(T x) { return internal::EqMatcher(x); } +inline internal::EqMatcher Eq(T x) { + return internal::EqMatcher(x); +} // Constructs a Matcher from a 'value' of type T. The constructed // matcher matches any value that's equal to 'value'. template -Matcher::Matcher(T value) { *this = Eq(value); } +Matcher::Matcher(T value) { + *this = Eq(value); +} // Creates a monomorphic matcher that matches anything with type Lhs // and equal to rhs. A user may need to use this instead of Eq(...) @@ -892,7 +883,9 @@ Matcher::Matcher(T value) { *this = Eq(value); } // can always write Matcher(Lt(5)) to be explicit about the type, // for example. template -inline Matcher TypedEq(const Rhs& rhs) { return Eq(rhs); } +inline Matcher TypedEq(const Rhs& rhs) { + return Eq(rhs); +} // Creates a polymorphic matcher that matches anything >= x. template diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-message.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-message.h index becfd49fcb..448ac6b7ee 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-message.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-message.h @@ -27,7 +27,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// // The Google C++ Testing and Mocking Framework (Google Test) // // This header file defines the Message class. @@ -42,17 +41,28 @@ // to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user // program! -// GOOGLETEST_CM0001 DO NOT DELETE +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ #include #include +#include #include +#include #include "gtest/internal/gtest-port.h" +#ifdef GTEST_HAS_ABSL +#include + +#include "absl/strings/has_absl_stringify.h" +#include "absl/strings/str_cat.h" +#endif // GTEST_HAS_ABSL + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ /* class A needs to have dll-interface to be used by clients of class B */) @@ -108,10 +118,19 @@ class GTEST_API_ Message { *ss_ << str; } - // Streams a non-pointer value to this object. - template - inline Message& operator <<(const T& val) { - // Some libraries overload << for STL containers. These + // Streams a non-pointer value to this object. If building a version of + // GoogleTest with ABSL, this overload is only enabled if the value does not + // have an AbslStringify definition. + template < + typename T +#ifdef GTEST_HAS_ABSL + , + typename std::enable_if::value, // NOLINT + int>::type = 0 +#endif // GTEST_HAS_ABSL + > + inline Message& operator<<(const T& val) { + // Some libraries overload << for STL containers. These // overloads are defined in the global namespace instead of ::std. // // C++'s symbol lookup rule (i.e. Koenig lookup) says that these @@ -125,11 +144,26 @@ class GTEST_API_ Message { // from the global namespace. With this using declaration, // overloads of << defined in the global namespace and those // visible via Koenig lookup are both exposed in this function. - using ::operator <<; + using ::operator<<; *ss_ << val; return *this; } +#ifdef GTEST_HAS_ABSL + // Streams a non-pointer value with an AbslStringify definition to this + // object. + template ::value, // NOLINT + int>::type = 0> + inline Message& operator<<(const T& val) { + // ::operator<< is needed here for a similar reason as with the non-Abseil + // version above + using ::operator<<; + *ss_ << absl::StrCat(val); + return *this; + } +#endif // GTEST_HAS_ABSL + // Streams a pointer value to this object. // // This function is an overload of the previous one. When you @@ -144,7 +178,7 @@ class GTEST_API_ Message { // ensure consistent result across compilers, we always treat NULL // as "(null)". template - inline Message& operator <<(T* const& pointer) { // NOLINT + inline Message& operator<<(T* const& pointer) { // NOLINT if (pointer == nullptr) { *ss_ << "(null)"; } else { @@ -159,25 +193,23 @@ class GTEST_API_ Message { // templatized version above. Without this definition, streaming // endl or other basic IO manipulators to Message will confuse the // compiler. - Message& operator <<(BasicNarrowIoManip val) { + Message& operator<<(BasicNarrowIoManip val) { *ss_ << val; return *this; } // Instead of 1/0, we want to see true/false for bool values. - Message& operator <<(bool b) { - return *this << (b ? "true" : "false"); - } + Message& operator<<(bool b) { return *this << (b ? "true" : "false"); } // These two overloads allow streaming a wide C string to a Message // using the UTF-8 encoding. - Message& operator <<(const wchar_t* wide_c_str); - Message& operator <<(wchar_t* wide_c_str); + Message& operator<<(const wchar_t* wide_c_str); + Message& operator<<(wchar_t* wide_c_str); #if GTEST_HAS_STD_WSTRING // Converts the given wide string to a narrow string using the UTF-8 // encoding, and streams the result to this Message object. - Message& operator <<(const ::std::wstring& wstr); + Message& operator<<(const ::std::wstring& wstr); #endif // GTEST_HAS_STD_WSTRING // Gets the text streamed to this object so far as an std::string. @@ -196,7 +228,7 @@ class GTEST_API_ Message { }; // Streams a Message to an ostream. -inline std::ostream& operator <<(std::ostream& os, const Message& sb) { +inline std::ostream& operator<<(std::ostream& os, const Message& sb) { return os << sb.GetString(); } diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-param-test.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-param-test.h index 804e702817..9e023f96dc 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-param-test.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-param-test.h @@ -26,11 +26,14 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// + // Macros and functions for implementing parameterized tests // in Google C++ Testing and Mocking Framework (Google Test) -// -// GOOGLETEST_CM0001 DO NOT DELETE + +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* + #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_ @@ -171,11 +174,12 @@ TEST_P(DerivedTest, DoesBlah) { #endif // 0 +#include #include #include #include "gtest/internal/gtest-internal.h" -#include "gtest/internal/gtest-param-util.h" +#include "gtest/internal/gtest-param-util.h" // IWYU pragma: export #include "gtest/internal/gtest-port.h" namespace testing { @@ -353,9 +357,7 @@ internal::ValueArray Values(T... v) { // } // INSTANTIATE_TEST_SUITE_P(BoolSequence, FlagDependentTest, Bool()); // -inline internal::ParamGenerator Bool() { - return Values(false, true); -} +inline internal::ParamGenerator Bool() { return Values(false, true); } // Combine() allows the user to combine two or more sequences to produce // values of a Cartesian product of those sequences' elements. @@ -406,9 +408,106 @@ internal::CartesianProductHolder Combine(const Generator&... g) { return internal::CartesianProductHolder(g...); } +// ConvertGenerator() wraps a parameter generator in order to cast each produced +// value through a known type before supplying it to the test suite +// +// Synopsis: +// ConvertGenerator(gen) +// - returns a generator producing the same elements as generated by gen, but +// each T-typed element is static_cast to a type deduced from the interface +// that accepts this generator, and then returned +// +// It is useful when using the Combine() function to get the generated +// parameters in a custom type instead of std::tuple +// +// Example: +// +// This will instantiate tests in test suite AnimalTest each one with +// the parameter values tuple("cat", BLACK), tuple("cat", WHITE), +// tuple("dog", BLACK), and tuple("dog", WHITE): +// +// enum Color { BLACK, GRAY, WHITE }; +// struct ParamType { +// using TupleT = std::tuple; +// std::string animal; +// Color color; +// ParamType(TupleT t) : animal(std::get<0>(t)), color(std::get<1>(t)) {} +// }; +// class AnimalTest +// : public testing::TestWithParam {...}; +// +// TEST_P(AnimalTest, AnimalLooksNice) {...} +// +// INSTANTIATE_TEST_SUITE_P(AnimalVariations, AnimalTest, +// ConvertGenerator( +// Combine(Values("cat", "dog"), +// Values(BLACK, WHITE)))); +// +template +internal::ParamConverterGenerator ConvertGenerator( + internal::ParamGenerator gen) { + return internal::ParamConverterGenerator(std::move(gen)); +} + +// As above, but takes a callable as a second argument. The callable converts +// the generated parameter to the test fixture's parameter type. This allows you +// to use a parameter type that does not have a converting constructor from the +// generated type. +// +// Example: +// +// This will instantiate tests in test suite AnimalTest each one with +// the parameter values tuple("cat", BLACK), tuple("cat", WHITE), +// tuple("dog", BLACK), and tuple("dog", WHITE): +// +// enum Color { BLACK, GRAY, WHITE }; +// struct ParamType { +// std::string animal; +// Color color; +// }; +// class AnimalTest +// : public testing::TestWithParam {...}; +// +// TEST_P(AnimalTest, AnimalLooksNice) {...} +// +// INSTANTIATE_TEST_SUITE_P( +// AnimalVariations, AnimalTest, +// ConvertGenerator(Combine(Values("cat", "dog"), Values(BLACK, WHITE)), +// [](std::tuple t) { +// return ParamType{.animal = std::get<0>(t), +// .color = std::get<1>(t)}; +// })); +// +template ()))> +internal::ParamConverterGenerator ConvertGenerator(Gen&& gen, + Func&& f) { + return internal::ParamConverterGenerator( + std::forward(gen), std::forward(f)); +} + +// As above, but infers the T from the supplied std::function instead of +// having the caller specify it. +template ()))> +auto ConvertGenerator(Gen&& gen, Func&& f) { + constexpr bool is_single_arg_std_function = + internal::IsSingleArgStdFunction::value; + if constexpr (is_single_arg_std_function) { + return ConvertGenerator< + typename internal::FuncSingleParamType::type>( + std::forward(gen), std::forward(f)); + } else { + static_assert(is_single_arg_std_function, + "The call signature must contain a single argument."); + } +} + #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public test_suite_name { \ + : public test_suite_name, \ + private ::testing::internal::GTestNonCopyable { \ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ void TestBody() override; \ @@ -427,9 +526,7 @@ internal::CartesianProductHolder Combine(const Generator&... g) { ::testing::internal::CodeLocation(__FILE__, __LINE__)); \ return 0; \ } \ - static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ - GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \ - test_name)); \ + [[maybe_unused]] static int gtest_registering_dummy_; \ }; \ int GTEST_TEST_CLASS_NAME_(test_suite_name, \ test_name)::gtest_registering_dummy_ = \ @@ -474,22 +571,20 @@ internal::CartesianProductHolder Combine(const Generator&... g) { ::testing::internal::DefaultParamName, \ DUMMY_PARAM_))))(info); \ } \ - static int gtest_##prefix##test_suite_name##_dummy_ \ - GTEST_ATTRIBUTE_UNUSED_ = \ - ::testing::UnitTest::GetInstance() \ - ->parameterized_test_registry() \ - .GetTestSuitePatternHolder( \ - GTEST_STRINGIFY_(test_suite_name), \ - ::testing::internal::CodeLocation(__FILE__, __LINE__)) \ - ->AddTestSuiteInstantiation( \ - GTEST_STRINGIFY_(prefix), \ - >est_##prefix##test_suite_name##_EvalGenerator_, \ - >est_##prefix##test_suite_name##_EvalGenerateName_, \ - __FILE__, __LINE__) - + [[maybe_unused]] static int gtest_##prefix##test_suite_name##_dummy_ = \ + ::testing::UnitTest::GetInstance() \ + ->parameterized_test_registry() \ + .GetTestSuitePatternHolder( \ + GTEST_STRINGIFY_(test_suite_name), \ + ::testing::internal::CodeLocation(__FILE__, __LINE__)) \ + ->AddTestSuiteInstantiation( \ + GTEST_STRINGIFY_(prefix), \ + >est_##prefix##test_suite_name##_EvalGenerator_, \ + >est_##prefix##test_suite_name##_EvalGenerateName_, __FILE__, \ + __LINE__) // Allow Marking a Parameterized test class as not needing to be instantiated. -#define GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(T) \ +#define GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(T) \ namespace gtest_do_not_use_outside_namespace_scope {} \ static const ::testing::internal::MarkAsIgnored gtest_allow_ignore_##T( \ GTEST_STRINGIFY_(T)) diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-printers.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-printers.h index 076c9de1f4..198a769349 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-printers.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-printers.h @@ -27,7 +27,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - // Google Test - The Google C++ Testing and Mocking Framework // // This file implements a universal value printer that can print a @@ -44,6 +43,9 @@ // 1. foo::PrintTo(const T&, ostream*) // 2. operator<<(ostream&, const T&) defined in either foo or the // global namespace. +// * Prefer AbslStringify(..) to operator<<(..), per https://abseil.io/tips/215. +// * Define foo::PrintTo(..) if the type already has AbslStringify(..), but an +// alternative presentation in test results is of interest. // // However if T is an STL-style container then it is printed element-wise // unless foo::PrintTo(const T&, ostream*) is defined. Note that @@ -95,7 +97,9 @@ // being defined as many user-defined container types don't have // value_type. -// GOOGLETEST_CM0001 DO NOT DELETE +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ @@ -107,12 +111,25 @@ #include #include #include +#include #include #include +#ifdef GTEST_HAS_ABSL +#include "absl/strings/has_absl_stringify.h" +#include "absl/strings/str_cat.h" +#endif // GTEST_HAS_ABSL #include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-port.h" +#if GTEST_INTERNAL_HAS_STD_SPAN +#include // NOLINT +#endif // GTEST_INTERNAL_HAS_STD_SPAN + +#if GTEST_INTERNAL_HAS_COMPARE_LIB +#include // NOLINT +#endif // GTEST_INTERNAL_HAS_COMPARE_LIB + namespace testing { // Definitions in the internal* namespaces are subject to change without notice. @@ -122,13 +139,32 @@ namespace internal { template void UniversalPrint(const T& value, ::std::ostream* os); +template +struct IsStdSpan { + static constexpr bool value = false; +}; + +#if GTEST_INTERNAL_HAS_STD_SPAN +template +struct IsStdSpan> { + static constexpr bool value = true; +}; +#endif // GTEST_INTERNAL_HAS_STD_SPAN + // Used to print an STL-style container when the user doesn't define // a PrintTo() for it. +// +// NOTE: Since std::span does not have const_iterator until C++23, it would +// fail IsContainerTest before C++23. However, IsContainerTest only uses +// the presence of const_iterator to avoid treating iterators as containers +// because of iterator::iterator. Which means std::span satisfies the *intended* +// condition of IsContainerTest. struct ContainerPrinter { template (0)) == sizeof(IsContainer)) && - !IsRecursiveContainer::value>::type> + ((sizeof(IsContainerTest(0)) == sizeof(IsContainer)) && + !IsRecursiveContainer::value) || + IsStdSpan::value>::type> static void PrintValue(const T& container, std::ostream* os) { const size_t kMaxCount = 32; // The maximum number of elements to print. *os << '{'; @@ -204,12 +240,13 @@ struct StreamPrinter { // Don't accept member pointers here. We'd print them via implicit // conversion to bool, which isn't useful. typename = typename std::enable_if< - !std::is_member_pointer::value>::type, - // Only accept types for which we can find a streaming operator via - // ADL (possibly involving implicit conversions). - typename = decltype(std::declval() - << std::declval())> - static void PrintValue(const T& value, ::std::ostream* os) { + !std::is_member_pointer::value>::type> + // Only accept types for which we can find a streaming operator via + // ADL (possibly involving implicit conversions). + // (Use SFINAE via return type, because it seems GCC < 12 doesn't handle name + // lookup properly when we do it in the template parameter list.) + static auto PrintValue(const T& value, + ::std::ostream* os) -> decltype((void)(*os << value)) { // Call streaming operator found by ADL, possibly with implicit conversions // of the arguments. *os << value; @@ -257,12 +294,21 @@ struct ConvertibleToStringViewPrinter { #endif }; +#ifdef GTEST_HAS_ABSL +struct ConvertibleToAbslStringifyPrinter { + template ::value>::type> // NOLINT + static void PrintValue(const T& value, ::std::ostream* os) { + *os << absl::StrCat(value); + } +}; +#endif // GTEST_HAS_ABSL // Prints the given number of bytes in the given object to the given // ostream. GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes, - size_t count, - ::std::ostream* os); + size_t count, ::std::ostream* os); struct RawBytesPrinter { // SFINAE on `sizeof` to make sure we have a complete type. template @@ -297,8 +343,8 @@ struct FindFirstPrinter< // - Print containers (they have begin/end/etc). // - Print function pointers. // - Print object pointers. -// - Use the stream operator, if available. // - Print protocol buffers. +// - Use the stream operator, if available. // - Print types convertible to BiggestInt. // - Print types convertible to StringView, if available. // - Fallback to printing the raw bytes of the object. @@ -306,9 +352,13 @@ template void PrintWithFallback(const T& value, ::std::ostream* os) { using Printer = typename FindFirstPrinter< T, void, ContainerPrinter, FunctionPointerPrinter, PointerPrinter, + ProtobufPrinter, +#ifdef GTEST_HAS_ABSL + ConvertibleToAbslStringifyPrinter, +#endif // GTEST_HAS_ABSL internal_stream_operator_without_lexical_name_lookup::StreamPrinter, - ProtobufPrinter, ConvertibleToIntegerPrinter, - ConvertibleToStringViewPrinter, RawBytesPrinter, FallbackPrinter>::type; + ConvertibleToIntegerPrinter, ConvertibleToStringViewPrinter, + RawBytesPrinter, FallbackPrinter>::type; Printer::PrintValue(value, os); } @@ -360,7 +410,7 @@ GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char); GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char); GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t); GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t); -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char8_t); GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char8_t); #endif @@ -375,17 +425,17 @@ GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char32_t); // to point to a NUL-terminated string, and thus can print it as a string. #define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \ - template <> \ - class FormatForComparison { \ - public: \ - static ::std::string Format(CharType* value) { \ - return ::testing::PrintToString(value); \ - } \ + template <> \ + class FormatForComparison { \ + public: \ + static ::std::string Format(CharType* value) { \ + return ::testing::PrintToString(value); \ + } \ } GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string); GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string); -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char8_t, ::std::u8string); GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char8_t, ::std::u8string); #endif @@ -410,8 +460,8 @@ GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring); // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. template -std::string FormatForComparisonFailureMessage( - const T1& value, const T2& /* other_operand */) { +std::string FormatForComparisonFailureMessage(const T1& value, + const T2& /* other_operand */) { return FormatForComparison::Format(value); } @@ -473,12 +523,113 @@ GTEST_API_ void PrintTo(char32_t c, ::std::ostream* os); inline void PrintTo(char16_t c, ::std::ostream* os) { PrintTo(ImplicitCast_(c), os); } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t inline void PrintTo(char8_t c, ::std::ostream* os) { PrintTo(ImplicitCast_(c), os); } #endif +// gcc/clang __{u,}int128_t +#if defined(__SIZEOF_INT128__) +GTEST_API_ void PrintTo(__uint128_t v, ::std::ostream* os); +GTEST_API_ void PrintTo(__int128_t v, ::std::ostream* os); +#endif // __SIZEOF_INT128__ + +// The default resolution used to print floating-point values uses only +// 6 digits, which can be confusing if a test compares two values whose +// difference lies in the 7th digit. So we'd like to print out numbers +// in full precision. +// However if the value is something simple like 1.1, full will print a +// long string like 1.100000001 due to floating-point numbers not using +// a base of 10. This routiune returns an appropriate resolution for a +// given floating-point number, that is, 6 if it will be accurate, or a +// max_digits10 value (full precision) if it won't, for values between +// 0.0001 and one million. +// It does this by computing what those digits would be (by multiplying +// by an appropriate power of 10), then dividing by that power again to +// see if gets the original value back. +// A similar algorithm applies for values larger than one million; note +// that for those values, we must divide to get a six-digit number, and +// then multiply to possibly get the original value again. +template +int AppropriateResolution(FloatType val) { + int full = std::numeric_limits::max_digits10; + if (val < 0) val = -val; + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + if (val < 1000000) { + FloatType mulfor6 = 1e10; + // Without these static casts, the template instantiation for float would + // fail to compile when -Wdouble-promotion is enabled, as the arithmetic and + // comparison logic would promote floats to doubles. + if (val >= static_cast(100000.0)) { // 100,000 to 999,999 + mulfor6 = 1.0; + } else if (val >= static_cast(10000.0)) { + mulfor6 = 1e1; + } else if (val >= static_cast(1000.0)) { + mulfor6 = 1e2; + } else if (val >= static_cast(100.0)) { + mulfor6 = 1e3; + } else if (val >= static_cast(10.0)) { + mulfor6 = 1e4; + } else if (val >= static_cast(1.0)) { + mulfor6 = 1e5; + } else if (val >= static_cast(0.1)) { + mulfor6 = 1e6; + } else if (val >= static_cast(0.01)) { + mulfor6 = 1e7; + } else if (val >= static_cast(0.001)) { + mulfor6 = 1e8; + } else if (val >= static_cast(0.0001)) { + mulfor6 = 1e9; + } + if (static_cast(static_cast( + val * mulfor6 + (static_cast(0.5)))) / + mulfor6 == + val) + return 6; + } else if (val < static_cast(1e10)) { + FloatType divfor6 = static_cast(1.0); + if (val >= static_cast(1e9)) { // 1,000,000,000 to 9,999,999,999 + divfor6 = 10000; + } else if (val >= + static_cast(1e8)) { // 100,000,000 to 999,999,999 + divfor6 = 1000; + } else if (val >= + static_cast(1e7)) { // 10,000,000 to 99,999,999 + divfor6 = 100; + } else if (val >= static_cast(1e6)) { // 1,000,000 to 9,999,999 + divfor6 = 10; + } + if (static_cast(static_cast( + val / divfor6 + (static_cast(0.5)))) * + divfor6 == + val) + return 6; + } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + return full; +} + +inline void PrintTo(float f, ::std::ostream* os) { + auto old_precision = os->precision(); + os->precision(AppropriateResolution(f)); + *os << f; + os->precision(old_precision); +} + +inline void PrintTo(double d, ::std::ostream* os) { + auto old_precision = os->precision(); + os->precision(AppropriateResolution(d)); + *os << d; + os->precision(old_precision); +} + // Overloads for C strings. GTEST_API_ void PrintTo(const char* s, ::std::ostream* os); inline void PrintTo(char* s, ::std::ostream* os) { @@ -499,7 +650,7 @@ inline void PrintTo(const unsigned char* s, ::std::ostream* os) { inline void PrintTo(unsigned char* s, ::std::ostream* os) { PrintTo(ImplicitCast_(s), os); } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t // Overloads for u8 strings. GTEST_API_ void PrintTo(const char8_t* s, ::std::ostream* os); inline void PrintTo(char8_t* s, ::std::ostream* os) { @@ -545,13 +696,13 @@ void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) { } // Overloads for ::std::string. -GTEST_API_ void PrintStringTo(const ::std::string&s, ::std::ostream* os); +GTEST_API_ void PrintStringTo(const ::std::string& s, ::std::ostream* os); inline void PrintTo(const ::std::string& s, ::std::ostream* os) { PrintStringTo(s, os); } // Overloads for ::std::u8string -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t GTEST_API_ void PrintU8StringTo(const ::std::u8string& s, ::std::ostream* os); inline void PrintTo(const ::std::u8string& s, ::std::ostream* os) { PrintU8StringTo(s, os); @@ -572,7 +723,7 @@ inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) { // Overloads for ::std::wstring. #if GTEST_HAS_STD_WSTRING -GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os); +GTEST_API_ void PrintWideStringTo(const ::std::wstring& s, ::std::ostream* os); inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) { PrintWideStringTo(s, os); } @@ -587,6 +738,12 @@ inline void PrintTo(internal::StringView sp, ::std::ostream* os) { inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; } +#if GTEST_HAS_RTTI +inline void PrintTo(const std::type_info& info, std::ostream* os) { + *os << internal::GetTypeName(info); +} +#endif // GTEST_HAS_RTTI + template void PrintTo(std::reference_wrapper ref, ::std::ostream* os) { UniversalPrinter::Print(ref.get(), os); @@ -629,6 +786,41 @@ void PrintTo(const std::shared_ptr& ptr, std::ostream* os) { (PrintSmartPointer)(ptr, os, 0); } +#if GTEST_INTERNAL_HAS_COMPARE_LIB +template +void PrintOrderingHelper(T ordering, std::ostream* os) { + if (ordering == T::less) { + *os << "(less)"; + } else if (ordering == T::greater) { + *os << "(greater)"; + } else if (ordering == T::equivalent) { + *os << "(equivalent)"; + } else { + *os << "(unknown ordering)"; + } +} + +inline void PrintTo(std::strong_ordering ordering, std::ostream* os) { + if (ordering == std::strong_ordering::equal) { + *os << "(equal)"; + } else { + PrintOrderingHelper(ordering, os); + } +} + +inline void PrintTo(std::partial_ordering ordering, std::ostream* os) { + if (ordering == std::partial_ordering::unordered) { + *os << "(unordered)"; + } else { + PrintOrderingHelper(ordering, os); + } +} + +inline void PrintTo(std::weak_ordering ordering, std::ostream* os) { + PrintOrderingHelper(ordering, os); +} +#endif + // Helper function for printing a tuple. T must be instantiated with // a tuple type. template @@ -744,6 +936,14 @@ class UniversalPrinter> { } }; +template <> +class UniversalPrinter { + public: + static void Print(decltype(Nullopt()), ::std::ostream* os) { + *os << "(nullopt)"; + } +}; + #endif // GTEST_INTERNAL_HAS_OPTIONAL #if GTEST_INTERNAL_HAS_VARIANT @@ -755,7 +955,7 @@ class UniversalPrinter> { public: static void Print(const Variant& value, ::std::ostream* os) { *os << '('; -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL absl::visit(Visitor{os, value.index()}, value); #else std::visit(Visitor{os, value.index()}, value); @@ -802,10 +1002,10 @@ void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) { } } // This overload prints a (const) char array compactly. -GTEST_API_ void UniversalPrintArray( - const char* begin, size_t len, ::std::ostream* os); +GTEST_API_ void UniversalPrintArray(const char* begin, size_t len, + ::std::ostream* os); -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t // This overload prints a (const) char8_t array compactly. GTEST_API_ void UniversalPrintArray(const char8_t* begin, size_t len, ::std::ostream* os); @@ -820,8 +1020,8 @@ GTEST_API_ void UniversalPrintArray(const char32_t* begin, size_t len, ::std::ostream* os); // This overload prints a (const) wchar_t array compactly. -GTEST_API_ void UniversalPrintArray( - const wchar_t* begin, size_t len, ::std::ostream* os); +GTEST_API_ void UniversalPrintArray(const wchar_t* begin, size_t len, + ::std::ostream* os); // Implements printing an array type T[N]. template @@ -872,6 +1072,13 @@ class UniversalTersePrinter { UniversalPrint(value, os); } }; +template +class UniversalTersePrinter> { + public: + static void Print(std::reference_wrapper value, ::std::ostream* os) { + UniversalTersePrinter::Print(value.get(), os); + } +}; template class UniversalTersePrinter { public: @@ -894,7 +1101,7 @@ template <> class UniversalTersePrinter : public UniversalTersePrinter { }; -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t template <> class UniversalTersePrinter { public: @@ -980,10 +1187,10 @@ void UniversalPrint(const T& value, ::std::ostream* os) { UniversalPrinter::Print(value, os); } -typedef ::std::vector< ::std::string> Strings; +typedef ::std::vector<::std::string> Strings; - // Tersely prints the first N fields of a tuple to a string vector, - // one element for each field. +// Tersely prints the first N fields of a tuple to a string vector, +// one element for each field. template void TersePrintPrefixToStrings(const Tuple&, std::integral_constant, Strings*) {} diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-spi.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-spi.h index eacef44669..c0613b6959 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-spi.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-spi.h @@ -27,15 +27,14 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// // Utilities for testing Google Test itself and code that uses Google Test // (e.g. frameworks built on top of Google Test). -// GOOGLETEST_CM0004 DO NOT DELETE - #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_SPI_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_SPI_H_ +#include + #include "gtest/gtest.h" GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ @@ -88,7 +87,10 @@ class GTEST_API_ ScopedFakeTestPartResultReporter TestPartResultReporterInterface* old_reporter_; TestPartResultArray* const result_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter); + ScopedFakeTestPartResultReporter(const ScopedFakeTestPartResultReporter&) = + delete; + ScopedFakeTestPartResultReporter& operator=( + const ScopedFakeTestPartResultReporter&) = delete; }; namespace internal { @@ -104,12 +106,14 @@ class GTEST_API_ SingleFailureChecker { SingleFailureChecker(const TestPartResultArray* results, TestPartResult::Type type, const std::string& substr); ~SingleFailureChecker(); + private: const TestPartResultArray* const results_; const TestPartResult::Type type_; const std::string substr_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker); + SingleFailureChecker(const SingleFailureChecker&) = delete; + SingleFailureChecker& operator=(const SingleFailureChecker&) = delete; }; } // namespace internal @@ -119,7 +123,8 @@ class GTEST_API_ SingleFailureChecker { GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 // A set of macros for testing Google Test assertions or code that's expected -// to generate Google Test fatal failures. It verifies that the given +// to generate Google Test fatal failures (e.g. a failure from an ASSERT_EQ, but +// not a non-fatal failure, as from EXPECT_EQ). It verifies that the given // statement will cause exactly one fatal Google Test failure with 'substr' // being part of the failure message. // @@ -141,44 +146,46 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 // helper macro, due to some peculiarity in how the preprocessor // works. The AcceptsMacroThatExpandsToUnprotectedComma test in // gtest_unittest.cc will fail to compile if we do that. -#define EXPECT_FATAL_FAILURE(statement, substr) \ - do { \ - class GTestExpectFatalFailureHelper {\ - public:\ - static void Execute() { statement; }\ - };\ - ::testing::TestPartResultArray gtest_failures;\ - ::testing::internal::SingleFailureChecker gtest_checker(\ - >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ - {\ - ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ - ::testing::ScopedFakeTestPartResultReporter:: \ - INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ - GTestExpectFatalFailureHelper::Execute();\ - }\ +#define EXPECT_FATAL_FAILURE(statement, substr) \ + do { \ + class GTestExpectFatalFailureHelper { \ + public: \ + static void Execute() { statement; } \ + }; \ + ::testing::TestPartResultArray gtest_failures; \ + ::testing::internal::SingleFailureChecker gtest_checker( \ + >est_failures, ::testing::TestPartResult::kFatalFailure, (substr)); \ + { \ + ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \ + ::testing::ScopedFakeTestPartResultReporter:: \ + INTERCEPT_ONLY_CURRENT_THREAD, \ + >est_failures); \ + GTestExpectFatalFailureHelper::Execute(); \ + } \ } while (::testing::internal::AlwaysFalse()) -#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ - do { \ - class GTestExpectFatalFailureHelper {\ - public:\ - static void Execute() { statement; }\ - };\ - ::testing::TestPartResultArray gtest_failures;\ - ::testing::internal::SingleFailureChecker gtest_checker(\ - >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ - {\ - ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ - ::testing::ScopedFakeTestPartResultReporter:: \ - INTERCEPT_ALL_THREADS, >est_failures);\ - GTestExpectFatalFailureHelper::Execute();\ - }\ +#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ + do { \ + class GTestExpectFatalFailureHelper { \ + public: \ + static void Execute() { statement; } \ + }; \ + ::testing::TestPartResultArray gtest_failures; \ + ::testing::internal::SingleFailureChecker gtest_checker( \ + >est_failures, ::testing::TestPartResult::kFatalFailure, (substr)); \ + { \ + ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \ + ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \ + >est_failures); \ + GTestExpectFatalFailureHelper::Execute(); \ + } \ } while (::testing::internal::AlwaysFalse()) // A macro for testing Google Test assertions or code that's expected to -// generate Google Test non-fatal failures. It asserts that the given -// statement will cause exactly one non-fatal Google Test failure with 'substr' -// being part of the failure message. +// generate Google Test non-fatal failures (e.g. a failure from an EXPECT_EQ, +// but not from an ASSERT_EQ). It asserts that the given statement will cause +// exactly one non-fatal Google Test failure with 'substr' being part of the +// failure message. // // There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only // affects and considers failures generated in the current thread and @@ -207,32 +214,37 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 // instead of // GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) // to avoid an MSVC warning on unreachable code. -#define EXPECT_NONFATAL_FAILURE(statement, substr) \ - do {\ - ::testing::TestPartResultArray gtest_failures;\ - ::testing::internal::SingleFailureChecker gtest_checker(\ +#define EXPECT_NONFATAL_FAILURE(statement, substr) \ + do { \ + ::testing::TestPartResultArray gtest_failures; \ + ::testing::internal::SingleFailureChecker gtest_checker( \ >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ - (substr));\ - {\ - ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ - ::testing::ScopedFakeTestPartResultReporter:: \ - INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ - if (::testing::internal::AlwaysTrue()) { statement; }\ - }\ + (substr)); \ + { \ + ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \ + ::testing::ScopedFakeTestPartResultReporter:: \ + INTERCEPT_ONLY_CURRENT_THREAD, \ + >est_failures); \ + if (::testing::internal::AlwaysTrue()) { \ + statement; \ + } \ + } \ } while (::testing::internal::AlwaysFalse()) -#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ - do {\ - ::testing::TestPartResultArray gtest_failures;\ - ::testing::internal::SingleFailureChecker gtest_checker(\ - >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ - (substr));\ - {\ - ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ +#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ + do { \ + ::testing::TestPartResultArray gtest_failures; \ + ::testing::internal::SingleFailureChecker gtest_checker( \ + >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ + (substr)); \ + { \ + ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \ ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \ - >est_failures);\ - if (::testing::internal::AlwaysTrue()) { statement; }\ - }\ + >est_failures); \ + if (::testing::internal::AlwaysTrue()) { \ + statement; \ + } \ + } \ } while (::testing::internal::AlwaysFalse()) #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_SPI_H_ diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-test-part.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-test-part.h index 203fdf98c6..41c8a9a0d0 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-test-part.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-test-part.h @@ -26,14 +26,19 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// GOOGLETEST_CM0001 DO NOT DELETE + +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ #include +#include +#include #include + #include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-string.h" @@ -128,7 +133,7 @@ std::ostream& operator<<(std::ostream& os, const TestPartResult& result); // virtual. class GTEST_API_ TestPartResultArray { public: - TestPartResultArray() {} + TestPartResultArray() = default; // Appends the given TestPartResult to the array. void Append(const TestPartResult& result); @@ -142,13 +147,14 @@ class GTEST_API_ TestPartResultArray { private: std::vector array_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray); + TestPartResultArray(const TestPartResultArray&) = delete; + TestPartResultArray& operator=(const TestPartResultArray&) = delete; }; // This interface knows how to report a test part result. class GTEST_API_ TestPartResultReporterInterface { public: - virtual ~TestPartResultReporterInterface() {} + virtual ~TestPartResultReporterInterface() = default; virtual void ReportTestPartResult(const TestPartResult& result) = 0; }; @@ -168,11 +174,13 @@ class GTEST_API_ HasNewFatalFailureHelper ~HasNewFatalFailureHelper() override; void ReportTestPartResult(const TestPartResult& result) override; bool has_new_fatal_failure() const { return has_new_fatal_failure_; } + private: bool has_new_fatal_failure_; TestPartResultReporterInterface* original_reporter_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper); + HasNewFatalFailureHelper(const HasNewFatalFailureHelper&) = delete; + HasNewFatalFailureHelper& operator=(const HasNewFatalFailureHelper&) = delete; }; } // namespace internal diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-typed-test.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-typed-test.h index 9fdc6be10d..442e00bd34 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/gtest-typed-test.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest-typed-test.h @@ -27,7 +27,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// GOOGLETEST_CM0001 DO NOT DELETE +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_ @@ -190,7 +192,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); typedef ::testing::internal::GenerateTypeList::type \ GTEST_TYPE_PARAMS_(CaseName); \ typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \ - GTEST_NAME_GENERATOR_(CaseName) + GTEST_NAME_GENERATOR_(CaseName) #define TYPED_TEST(CaseName, TestName) \ static_assert(sizeof(GTEST_STRINGIFY_(TestName)) > 1, \ @@ -203,8 +205,8 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); typedef gtest_TypeParam_ TypeParam; \ void TestBody() override; \ }; \ - static bool gtest_##CaseName##_##TestName##_registered_ \ - GTEST_ATTRIBUTE_UNUSED_ = ::testing::internal::TypeParameterizedTest< \ + [[maybe_unused]] static bool gtest_##CaseName##_##TestName##_registered_ = \ + ::testing::internal::TypeParameterizedTest< \ CaseName, \ ::testing::internal::TemplateSel, \ @@ -256,7 +258,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); // #included in multiple translation units linked together. #define TYPED_TEST_SUITE_P(SuiteName) \ static ::testing::internal::TypedTestSuitePState \ - GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName) + GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName) // Legacy API is deprecated but still available #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ @@ -265,31 +267,31 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); TYPED_TEST_SUITE_P #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ -#define TYPED_TEST_P(SuiteName, TestName) \ - namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \ - template \ - class TestName : public SuiteName { \ - private: \ - typedef SuiteName TestFixture; \ - typedef gtest_TypeParam_ TypeParam; \ - void TestBody() override; \ - }; \ - static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \ - GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \ - __FILE__, __LINE__, GTEST_STRINGIFY_(SuiteName), \ - GTEST_STRINGIFY_(TestName)); \ - } \ - template \ - void GTEST_SUITE_NAMESPACE_( \ +#define TYPED_TEST_P(SuiteName, TestName) \ + namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \ + template \ + class TestName : public SuiteName { \ + private: \ + typedef SuiteName TestFixture; \ + typedef gtest_TypeParam_ TypeParam; \ + void TestBody() override; \ + }; \ + [[maybe_unused]] static bool gtest_##TestName##_defined_ = \ + GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \ + __FILE__, __LINE__, GTEST_STRINGIFY_(SuiteName), \ + GTEST_STRINGIFY_(TestName)); \ + } \ + template \ + void GTEST_SUITE_NAMESPACE_( \ SuiteName)::TestName::TestBody() // Note: this won't work correctly if the trailing arguments are macros. #define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...) \ namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \ - typedef ::testing::internal::Templates<__VA_ARGS__> gtest_AllTests_; \ + typedef ::testing::internal::Templates<__VA_ARGS__> gtest_AllTests_; \ } \ - static const char* const GTEST_REGISTERED_TEST_NAMES_( \ - SuiteName) GTEST_ATTRIBUTE_UNUSED_ = \ + [[maybe_unused]] static const char* const GTEST_REGISTERED_TEST_NAMES_( \ + SuiteName) = \ GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).VerifyRegisteredTestNames( \ GTEST_STRINGIFY_(SuiteName), __FILE__, __LINE__, #__VA_ARGS__) @@ -301,21 +303,21 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); REGISTER_TYPED_TEST_SUITE_P #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ -#define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \ - static_assert(sizeof(GTEST_STRINGIFY_(Prefix)) > 1, \ - "test-suit-prefix must not be empty"); \ - static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \ - ::testing::internal::TypeParameterizedTestSuite< \ - SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \ - ::testing::internal::GenerateTypeList::type>:: \ - Register(GTEST_STRINGIFY_(Prefix), \ - ::testing::internal::CodeLocation(__FILE__, __LINE__), \ - >EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), \ - GTEST_STRINGIFY_(SuiteName), \ - GTEST_REGISTERED_TEST_NAMES_(SuiteName), \ - ::testing::internal::GenerateNames< \ - ::testing::internal::NameGeneratorSelector< \ - __VA_ARGS__>::type, \ +#define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \ + static_assert(sizeof(GTEST_STRINGIFY_(Prefix)) > 1, \ + "test-suit-prefix must not be empty"); \ + [[maybe_unused]] static bool gtest_##Prefix##_##SuiteName = \ + ::testing::internal::TypeParameterizedTestSuite< \ + SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \ + ::testing::internal::GenerateTypeList::type>:: \ + Register(GTEST_STRINGIFY_(Prefix), \ + ::testing::internal::CodeLocation(__FILE__, __LINE__), \ + >EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), \ + GTEST_STRINGIFY_(SuiteName), \ + GTEST_REGISTERED_TEST_NAMES_(SuiteName), \ + ::testing::internal::GenerateNames< \ + ::testing::internal::NameGeneratorSelector< \ + __VA_ARGS__>::type, \ ::testing::internal::GenerateTypeList::type>()) // Legacy API is deprecated but still available diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest.h index 7a5d057c4a..7be0caaf51 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/gtest.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest.h @@ -27,7 +27,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// // The Google C++ Testing and Mocking Framework (Google Test) // // This header file defines the public API for Google Test. It should be @@ -47,43 +46,36 @@ // registration from Barthelemy Dagenais' (barthelemy@prologique.com) // easyUnit framework. -// GOOGLETEST_CM0001 DO NOT DELETE - #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_H_ #include +#include #include #include #include +#include +#include +#include #include #include +#include "gtest/gtest-assertion-result.h" // IWYU pragma: export +#include "gtest/gtest-death-test.h" // IWYU pragma: export +#include "gtest/gtest-matchers.h" // IWYU pragma: export +#include "gtest/gtest-message.h" // IWYU pragma: export +#include "gtest/gtest-param-test.h" // IWYU pragma: export +#include "gtest/gtest-printers.h" // IWYU pragma: export +#include "gtest/gtest-test-part.h" // IWYU pragma: export +#include "gtest/gtest-typed-test.h" // IWYU pragma: export +#include "gtest/gtest_pred_impl.h" // IWYU pragma: export +#include "gtest/gtest_prod.h" // IWYU pragma: export #include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-string.h" -#include "gtest/gtest-death-test.h" -#include "gtest/gtest-matchers.h" -#include "gtest/gtest-message.h" -#include "gtest/gtest-param-test.h" -#include "gtest/gtest-printers.h" -#include "gtest/gtest_prod.h" -#include "gtest/gtest-test-part.h" -#include "gtest/gtest-typed-test.h" GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ /* class A needs to have dll-interface to be used by clients of class B */) -namespace testing { - -// Silence C4100 (unreferenced formal parameter) and 4805 -// unsafe mix of type 'const int' and type 'const bool' -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4805) -# pragma warning(disable:4100) -#endif - - // Declares the flags. // This flag temporary enables the disabled tests. @@ -138,6 +130,12 @@ GTEST_DECLARE_int32_(random_seed); // is 1. If the value is -1 the tests are repeating forever. GTEST_DECLARE_int32_(repeat); +// This flag controls whether Google Test Environments are recreated for each +// repeat of the tests. The default value is true. If set to false the global +// test Environment objects are only set up once, for the first iteration, and +// only torn down once, for the last. +GTEST_DECLARE_bool_(recreate_environments_when_repeating); + // This flag controls whether Google Test includes Google Test internal // stack frames in failure stack traces. GTEST_DECLARE_bool_(show_internal_stack_frames); @@ -163,6 +161,12 @@ GTEST_DECLARE_string_(stream_result_to); GTEST_DECLARE_string_(flagfile); #endif // GTEST_USE_OWN_FLAGFILE_FLAG_ +namespace testing { + +// Silence C4100 (unreferenced formal parameter) and 4805 +// unsafe mix of type 'const int' and type 'const bool' +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4805 4100) + // The upper limit for valid stack trace depths. const int kMaxStackTraceDepth = 100; @@ -186,6 +190,17 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); std::set* GetIgnoredParameterizedTestSuites(); +// A base class that prevents subclasses from being copyable. +// We do this instead of using '= delete' so as to avoid triggering warnings +// inside user code regarding any of our declarations. +class GTestNonCopyable { + public: + GTestNonCopyable() = default; + GTestNonCopyable(const GTestNonCopyable&) = delete; + GTestNonCopyable& operator=(const GTestNonCopyable&) = delete; + ~GTestNonCopyable() = default; +}; + } // namespace internal // The friend relationship of some of these classes is cyclic. @@ -201,193 +216,6 @@ using TestCase = TestSuite; class TestInfo; class UnitTest; -// A class for indicating whether an assertion was successful. When -// the assertion wasn't successful, the AssertionResult object -// remembers a non-empty message that describes how it failed. -// -// To create an instance of this class, use one of the factory functions -// (AssertionSuccess() and AssertionFailure()). -// -// This class is useful for two purposes: -// 1. Defining predicate functions to be used with Boolean test assertions -// EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts -// 2. Defining predicate-format functions to be -// used with predicate assertions (ASSERT_PRED_FORMAT*, etc). -// -// For example, if you define IsEven predicate: -// -// testing::AssertionResult IsEven(int n) { -// if ((n % 2) == 0) -// return testing::AssertionSuccess(); -// else -// return testing::AssertionFailure() << n << " is odd"; -// } -// -// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5))) -// will print the message -// -// Value of: IsEven(Fib(5)) -// Actual: false (5 is odd) -// Expected: true -// -// instead of a more opaque -// -// Value of: IsEven(Fib(5)) -// Actual: false -// Expected: true -// -// in case IsEven is a simple Boolean predicate. -// -// If you expect your predicate to be reused and want to support informative -// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up -// about half as often as positive ones in our tests), supply messages for -// both success and failure cases: -// -// testing::AssertionResult IsEven(int n) { -// if ((n % 2) == 0) -// return testing::AssertionSuccess() << n << " is even"; -// else -// return testing::AssertionFailure() << n << " is odd"; -// } -// -// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print -// -// Value of: IsEven(Fib(6)) -// Actual: true (8 is even) -// Expected: false -// -// NB: Predicates that support negative Boolean assertions have reduced -// performance in positive ones so be careful not to use them in tests -// that have lots (tens of thousands) of positive Boolean assertions. -// -// To use this class with EXPECT_PRED_FORMAT assertions such as: -// -// // Verifies that Foo() returns an even number. -// EXPECT_PRED_FORMAT1(IsEven, Foo()); -// -// you need to define: -// -// testing::AssertionResult IsEven(const char* expr, int n) { -// if ((n % 2) == 0) -// return testing::AssertionSuccess(); -// else -// return testing::AssertionFailure() -// << "Expected: " << expr << " is even\n Actual: it's " << n; -// } -// -// If Foo() returns 5, you will see the following message: -// -// Expected: Foo() is even -// Actual: it's 5 -// -class GTEST_API_ AssertionResult { - public: - // Copy constructor. - // Used in EXPECT_TRUE/FALSE(assertion_result). - AssertionResult(const AssertionResult& other); - -// C4800 is a level 3 warning in Visual Studio 2015 and earlier. -// This warning is not emitted in Visual Studio 2017. -// This warning is off by default starting in Visual Studio 2019 but can be -// enabled with command-line options. -#if defined(_MSC_VER) && (_MSC_VER < 1910 || _MSC_VER >= 1920) - GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */) -#endif - - // Used in the EXPECT_TRUE/FALSE(bool_expression). - // - // T must be contextually convertible to bool. - // - // The second parameter prevents this overload from being considered if - // the argument is implicitly convertible to AssertionResult. In that case - // we want AssertionResult's copy constructor to be used. - template - explicit AssertionResult( - const T& success, - typename std::enable_if< - !std::is_convertible::value>::type* - /*enabler*/ - = nullptr) - : success_(success) {} - -#if defined(_MSC_VER) && (_MSC_VER < 1910 || _MSC_VER >= 1920) - GTEST_DISABLE_MSC_WARNINGS_POP_() -#endif - - // Assignment operator. - AssertionResult& operator=(AssertionResult other) { - swap(other); - return *this; - } - - // Returns true if and only if the assertion succeeded. - operator bool() const { return success_; } // NOLINT - - // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. - AssertionResult operator!() const; - - // Returns the text streamed into this AssertionResult. Test assertions - // use it when they fail (i.e., the predicate's outcome doesn't match the - // assertion's expectation). When nothing has been streamed into the - // object, returns an empty string. - const char* message() const { - return message_.get() != nullptr ? message_->c_str() : ""; - } - // Deprecated; please use message() instead. - const char* failure_message() const { return message(); } - - // Streams a custom failure message into this object. - template AssertionResult& operator<<(const T& value) { - AppendMessage(Message() << value); - return *this; - } - - // Allows streaming basic output manipulators such as endl or flush into - // this object. - AssertionResult& operator<<( - ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) { - AppendMessage(Message() << basic_manipulator); - return *this; - } - - private: - // Appends the contents of message to message_. - void AppendMessage(const Message& a_message) { - if (message_.get() == nullptr) message_.reset(new ::std::string); - message_->append(a_message.GetString().c_str()); - } - - // Swap the contents of this AssertionResult with other. - void swap(AssertionResult& other); - - // Stores result of the assertion predicate. - bool success_; - // Stores the message describing the condition in case the expectation - // construct is not satisfied with the predicate's outcome. - // Referenced via a pointer to avoid taking too much stack frame space - // with test assertions. - std::unique_ptr< ::std::string> message_; -}; - -// Makes a successful assertion result. -GTEST_API_ AssertionResult AssertionSuccess(); - -// Makes a failed assertion result. -GTEST_API_ AssertionResult AssertionFailure(); - -// Makes a failed assertion result with the given failure message. -// Deprecated; use AssertionFailure() << msg. -GTEST_API_ AssertionResult AssertionFailure(const Message& msg); - -} // namespace testing - -// Includes the auto-generated header that implements a family of generic -// predicate assertion macros. This include comes late because it relies on -// APIs declared above. -#include "gtest/gtest_pred_impl.h" - -namespace testing { - // The abstract class that all tests inherit from. // // In Google Test, a unit test program contains one or many TestSuites, and @@ -468,7 +296,13 @@ class GTEST_API_ Test { // SetUp/TearDown method of Environment objects registered with Google // Test) will be output as attributes of the element. static void RecordProperty(const std::string& key, const std::string& value); - static void RecordProperty(const std::string& key, int value); + // We do not define a custom serialization except for values that can be + // converted to int64_t, but other values could be logged in this way. + template ::value, + bool> = true> + static void RecordProperty(const std::string& key, const T& value) { + RecordProperty(key, (Message() << value).GetString()); + } protected: // Creates a Test object. @@ -522,7 +356,8 @@ class GTEST_API_ Test { virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; } // We disallow copying Tests. - GTEST_DISALLOW_COPY_AND_ASSIGN_(Test); + Test(const Test&) = delete; + Test& operator=(const Test&) = delete; }; typedef internal::TimeInMillis TimeInMillis; @@ -536,24 +371,17 @@ class TestProperty { // C'tor. TestProperty does NOT have a default constructor. // Always use this constructor (with parameters) to create a // TestProperty object. - TestProperty(const std::string& a_key, const std::string& a_value) : - key_(a_key), value_(a_value) { - } + TestProperty(const std::string& a_key, const std::string& a_value) + : key_(a_key), value_(a_value) {} // Gets the user supplied key. - const char* key() const { - return key_.c_str(); - } + const char* key() const { return key_.c_str(); } // Gets the user supplied value. - const char* value() const { - return value_.c_str(); - } + const char* value() const { return value_.c_str(); } // Sets a new value, overriding the one supplied in the constructor. - void SetValue(const std::string& new_value) { - value_ = new_value; - } + void SetValue(const std::string& new_value) { value_ = new_value; } private: // The key supplied by the user. @@ -687,7 +515,8 @@ class GTEST_API_ TestResult { TimeInMillis elapsed_time_; // We disallow copying TestResult. - GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult); + TestResult(const TestResult&) = delete; + TestResult& operator=(const TestResult&) = delete; }; // class TestResult // A TestInfo object stores the following information about a test: @@ -721,14 +550,14 @@ class GTEST_API_ TestInfo { // Returns the name of the parameter type, or NULL if this is not a typed // or a type-parameterized test. const char* type_param() const { - if (type_param_.get() != nullptr) return type_param_->c_str(); + if (type_param_ != nullptr) return type_param_->c_str(); return nullptr; } // Returns the text representation of the value parameter, or NULL if this // is not a value-parameterized test. const char* value_param() const { - if (value_param_.get() != nullptr) return value_param_->c_str(); + if (value_param_ != nullptr) return value_param_->c_str(); return nullptr; } @@ -770,7 +599,7 @@ class GTEST_API_ TestInfo { const TestResult* result() const { return &result_; } private: -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST friend class internal::DefaultDeathTestFactory; #endif // GTEST_HAS_DEATH_TEST friend class Test; @@ -778,7 +607,7 @@ class GTEST_API_ TestInfo { friend class internal::UnitTestImpl; friend class internal::StreamingListenerTest; friend TestInfo* internal::MakeAndRegisterTestInfo( - const char* test_suite_name, const char* name, const char* type_param, + std::string test_suite_name, const char* name, const char* type_param, const char* value_param, internal::CodeLocation code_location, internal::TypeId fixture_class_id, internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc, @@ -786,7 +615,7 @@ class GTEST_API_ TestInfo { // Constructs a TestInfo object. The newly constructed instance assumes // ownership of the factory object. - TestInfo(const std::string& test_suite_name, const std::string& name, + TestInfo(std::string test_suite_name, std::string name, const char* a_type_param, // NULL if not a type-parameterized test const char* a_value_param, // NULL if not a value-parameterized test internal::CodeLocation a_code_location, @@ -811,8 +640,8 @@ class GTEST_API_ TestInfo { } // These fields are immutable properties of the test. - const std::string test_suite_name_; // test suite name - const std::string name_; // Test name + const std::string test_suite_name_; // test suite name + const std::string name_; // Test name // Name of the parameter type, or NULL if this is not a typed or a // type-parameterized test. const std::unique_ptr type_param_; @@ -833,7 +662,8 @@ class GTEST_API_ TestInfo { // test for the second time. TestResult result_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo); + TestInfo(const TestInfo&) = delete; + TestInfo& operator=(const TestInfo&) = delete; }; // A test suite, which consists of a vector of TestInfos. @@ -853,7 +683,7 @@ class GTEST_API_ TestSuite { // this is not a type-parameterized test. // set_up_tc: pointer to the function that sets up the test suite // tear_down_tc: pointer to the function that tears down the test suite - TestSuite(const char* name, const char* a_type_param, + TestSuite(const std::string& name, const char* a_type_param, internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc); @@ -866,7 +696,7 @@ class GTEST_API_ TestSuite { // Returns the name of the parameter type, or NULL if this is not a // type-parameterized test suite. const char* type_param() const { - if (type_param_.get() != nullptr) return type_param_->c_str(); + if (type_param_ != nullptr) return type_param_->c_str(); return nullptr; } @@ -941,7 +771,7 @@ class GTEST_API_ TestSuite { // Adds a TestInfo to this test suite. Will delete the TestInfo upon // destruction of the TestSuite object. - void AddTestInfo(TestInfo * test_info); + void AddTestInfo(TestInfo* test_info); // Clears the results of all tests in this test suite. void ClearResult(); @@ -1042,7 +872,8 @@ class GTEST_API_ TestSuite { TestResult ad_hoc_test_result_; // We disallow copying TestSuites. - GTEST_DISALLOW_COPY_AND_ASSIGN_(TestSuite); + TestSuite(const TestSuite&) = delete; + TestSuite& operator=(const TestSuite&) = delete; }; // An Environment object is capable of setting up and tearing down an @@ -1062,13 +893,14 @@ class GTEST_API_ TestSuite { class Environment { public: // The d'tor is virtual as we need to subclass Environment. - virtual ~Environment() {} + virtual ~Environment() = default; // Override this to define how to set up the environment. virtual void SetUp() {} // Override this to define how to tear down the environment. virtual void TearDown() {} + private: // If you see an error about overriding the following function or // about it being private, you have mis-spelled SetUp() as Setup(). @@ -1092,7 +924,7 @@ class GTEST_API_ AssertionException // the order the corresponding events are fired. class TestEventListener { public: - virtual ~TestEventListener() {} + virtual ~TestEventListener() = default; // Fired before any test activity starts. virtual void OnTestProgramStart(const UnitTest& unit_test) = 0; @@ -1120,6 +952,9 @@ class TestEventListener { // Fired before the test starts. virtual void OnTestStart(const TestInfo& test_info) = 0; + // Fired when a test is disabled + virtual void OnTestDisabled(const TestInfo& /*test_info*/) {} + // Fired after a failed assertion or a SUCCEED() invocation. // If you want to throw an exception from this function to skip to the next // TEST, it must be AssertionException defined above, or inherited from it. @@ -1143,8 +978,7 @@ class TestEventListener { virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0; // Fired after each iteration of tests finishes. - virtual void OnTestIterationEnd(const UnitTest& unit_test, - int iteration) = 0; + virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration) = 0; // Fired after all test activities have ended. virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0; @@ -1169,6 +1003,7 @@ class EmptyTestEventListener : public TestEventListener { #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ void OnTestStart(const TestInfo& /*test_info*/) override {} + void OnTestDisabled(const TestInfo& /*test_info*/) override {} void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {} void OnTestEnd(const TestInfo& /*test_info*/) override {} void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {} @@ -1219,6 +1054,10 @@ class GTEST_API_ TestEventListeners { return default_xml_generator_; } + // Controls whether events will be forwarded by the repeater to the + // listeners in the list. + void SuppressEventForwarding(bool); + private: friend class TestSuite; friend class TestInfo; @@ -1248,7 +1087,6 @@ class GTEST_API_ TestEventListeners { // Controls whether events will be forwarded by the repeater to the // listeners in the list. bool EventForwardingEnabled() const; - void SuppressEventForwarding(); // The actual list of listeners. internal::TestEventRepeater* repeater_; @@ -1258,7 +1096,8 @@ class GTEST_API_ TestEventListeners { TestEventListener* default_xml_generator_; // We disallow copying TestEventListeners. - GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners); + TestEventListeners(const TestEventListeners&) = delete; + TestEventListeners& operator=(const TestEventListeners&) = delete; }; // A UnitTest consists of a vector of TestSuites. @@ -1284,7 +1123,7 @@ class GTEST_API_ UnitTest { // This method can only be called from the main thread. // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. - int Run() GTEST_MUST_USE_RESULT_; + [[nodiscard]] int Run(); // Returns the working directory when the first TEST() or TEST_F() // was executed. The UnitTest object owns the string. @@ -1301,8 +1140,7 @@ class GTEST_API_ UnitTest { // Returns the TestInfo object for the test that's currently running, // or NULL if no test is running. - const TestInfo* current_test_info() const - GTEST_LOCK_EXCLUDED_(mutex_); + const TestInfo* current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_); // Returns the random seed used at the start of the current test run. int random_seed() const; @@ -1408,8 +1246,7 @@ class GTEST_API_ UnitTest { // eventually call this to report their results. The user code // should use the assertion macros instead of calling this directly. void AddTestPartResult(TestPartResult::Type result_type, - const char* file_name, - int line_number, + const char* file_name, int line_number, const std::string& message, const std::string& os_stack_trace) GTEST_LOCK_EXCLUDED_(mutex_); @@ -1425,6 +1262,20 @@ class GTEST_API_ UnitTest { // total_test_suite_count() - 1. If i is not in that range, returns NULL. TestSuite* GetMutableTestSuite(int i); + // Invokes OsStackTrackGetterInterface::UponLeavingGTest. UponLeavingGTest() + // should be called immediately before Google Test calls user code. It saves + // some information about the current stack that CurrentStackTrace() will use + // to find and hide Google Test stack frames. + void UponLeavingGTest(); + + // Sets the TestSuite object for the test that's currently running. + void set_current_test_suite(TestSuite* a_current_test_suite) + GTEST_LOCK_EXCLUDED_(mutex_); + + // Sets the TestInfo object for the test that's currently running. + void set_current_test_info(TestInfo* a_current_test_info) + GTEST_LOCK_EXCLUDED_(mutex_); + // Accessors for the implementation object. internal::UnitTestImpl* impl() { return impl_; } const internal::UnitTestImpl* impl() const { return impl_; } @@ -1433,6 +1284,8 @@ class GTEST_API_ UnitTest { // members of UnitTest. friend class ScopedTrace; friend class Test; + friend class TestInfo; + friend class TestSuite; friend class internal::AssertHelper; friend class internal::StreamingListenerTest; friend class internal::UnitTestRecordPropertyTestHelper; @@ -1440,8 +1293,7 @@ class GTEST_API_ UnitTest { friend std::set* internal::GetIgnoredParameterizedTestSuites(); friend internal::UnitTestImpl* internal::GetUnitTestImpl(); friend void internal::ReportFailureInUnknownLocation( - TestPartResult::Type result_type, - const std::string& message); + TestPartResult::Type result_type, const std::string& message); // Creates an empty UnitTest. UnitTest(); @@ -1455,8 +1307,7 @@ class GTEST_API_ UnitTest { GTEST_LOCK_EXCLUDED_(mutex_); // Pops a trace from the per-thread Google Test trace stack. - void PopGTestTrace() - GTEST_LOCK_EXCLUDED_(mutex_); + void PopGTestTrace() GTEST_LOCK_EXCLUDED_(mutex_); // Protects mutable state in *impl_. This is mutable as some const // methods need to lock it too. @@ -1469,7 +1320,8 @@ class GTEST_API_ UnitTest { internal::UnitTestImpl* impl_; // We disallow copying UnitTest. - GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest); + UnitTest(const UnitTest&) = delete; + UnitTest& operator=(const UnitTest&) = delete; }; // A convenient wrapper for adding an environment for the test @@ -1520,13 +1372,11 @@ namespace internal { // when calling EXPECT_* in a tight loop. template AssertionResult CmpHelperEQFailure(const char* lhs_expression, - const char* rhs_expression, - const T1& lhs, const T2& rhs) { - return EqFailure(lhs_expression, - rhs_expression, + const char* rhs_expression, const T1& lhs, + const T2& rhs) { + return EqFailure(lhs_expression, rhs_expression, FormatForComparisonFailureMessage(lhs, rhs), - FormatForComparisonFailureMessage(rhs, lhs), - false); + FormatForComparisonFailureMessage(rhs, lhs), false); } // This block of code defines operator==/!= @@ -1539,8 +1389,7 @@ inline bool operator!=(faketype, faketype) { return false; } // The helper function for {ASSERT|EXPECT}_EQ. template AssertionResult CmpHelperEQ(const char* lhs_expression, - const char* rhs_expression, - const T1& lhs, + const char* rhs_expression, const T1& lhs, const T2& rhs) { if (lhs == rhs) { return AssertionSuccess(); @@ -1571,8 +1420,7 @@ class EqHelper { // Even though its body looks the same as the above version, we // cannot merge the two, as it will make anonymous enums unhappy. static AssertionResult Compare(const char* lhs_expression, - const char* rhs_expression, - BiggestInt lhs, + const char* rhs_expression, BiggestInt lhs, BiggestInt rhs) { return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs); } @@ -1607,16 +1455,16 @@ AssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2, // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. -#define GTEST_IMPL_CMP_HELPER_(op_name, op)\ -template \ -AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ - const T1& val1, const T2& val2) {\ - if (val1 op val2) {\ - return AssertionSuccess();\ - } else {\ - return CmpHelperOpFailure(expr1, expr2, val1, val2, #op);\ - }\ -} +#define GTEST_IMPL_CMP_HELPER_(op_name, op) \ + template \ + AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ + const T1& val1, const T2& val2) { \ + if (val1 op val2) { \ + return AssertionSuccess(); \ + } else { \ + return CmpHelperOpFailure(expr1, expr2, val1, val2, #op); \ + } \ + } // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. @@ -1638,49 +1486,42 @@ GTEST_IMPL_CMP_HELPER_(GT, >) // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression, const char* s2_expression, - const char* s1, - const char* s2); + const char* s1, const char* s2); // The helper function for {ASSERT|EXPECT}_STRCASEEQ. // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression, const char* s2_expression, - const char* s1, - const char* s2); + const char* s1, const char* s2); // The helper function for {ASSERT|EXPECT}_STRNE. // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, const char* s2_expression, - const char* s1, - const char* s2); + const char* s1, const char* s2); // The helper function for {ASSERT|EXPECT}_STRCASENE. // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression, const char* s2_expression, - const char* s1, - const char* s2); - + const char* s1, const char* s2); // Helper function for *_STREQ on wide strings. // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression, const char* s2_expression, - const wchar_t* s1, - const wchar_t* s2); + const wchar_t* s1, const wchar_t* s2); // Helper function for *_STRNE on wide strings. // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, const char* s2_expression, - const wchar_t* s1, - const wchar_t* s2); + const wchar_t* s1, const wchar_t* s2); } // namespace internal @@ -1692,32 +1533,40 @@ GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, // // The {needle,haystack}_expr arguments are the stringified // expressions that generated the two real arguments. -GTEST_API_ AssertionResult IsSubstring( - const char* needle_expr, const char* haystack_expr, - const char* needle, const char* haystack); -GTEST_API_ AssertionResult IsSubstring( - const char* needle_expr, const char* haystack_expr, - const wchar_t* needle, const wchar_t* haystack); -GTEST_API_ AssertionResult IsNotSubstring( - const char* needle_expr, const char* haystack_expr, - const char* needle, const char* haystack); -GTEST_API_ AssertionResult IsNotSubstring( - const char* needle_expr, const char* haystack_expr, - const wchar_t* needle, const wchar_t* haystack); -GTEST_API_ AssertionResult IsSubstring( - const char* needle_expr, const char* haystack_expr, - const ::std::string& needle, const ::std::string& haystack); -GTEST_API_ AssertionResult IsNotSubstring( - const char* needle_expr, const char* haystack_expr, - const ::std::string& needle, const ::std::string& haystack); +GTEST_API_ AssertionResult IsSubstring(const char* needle_expr, + const char* haystack_expr, + const char* needle, + const char* haystack); +GTEST_API_ AssertionResult IsSubstring(const char* needle_expr, + const char* haystack_expr, + const wchar_t* needle, + const wchar_t* haystack); +GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr, + const char* haystack_expr, + const char* needle, + const char* haystack); +GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr, + const char* haystack_expr, + const wchar_t* needle, + const wchar_t* haystack); +GTEST_API_ AssertionResult IsSubstring(const char* needle_expr, + const char* haystack_expr, + const ::std::string& needle, + const ::std::string& haystack); +GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr, + const char* haystack_expr, + const ::std::string& needle, + const ::std::string& haystack); #if GTEST_HAS_STD_WSTRING -GTEST_API_ AssertionResult IsSubstring( - const char* needle_expr, const char* haystack_expr, - const ::std::wstring& needle, const ::std::wstring& haystack); -GTEST_API_ AssertionResult IsNotSubstring( - const char* needle_expr, const char* haystack_expr, - const ::std::wstring& needle, const ::std::wstring& haystack); +GTEST_API_ AssertionResult IsSubstring(const char* needle_expr, + const char* haystack_expr, + const ::std::wstring& needle, + const ::std::wstring& haystack); +GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr, + const char* haystack_expr, + const ::std::wstring& needle, + const ::std::wstring& haystack); #endif // GTEST_HAS_STD_WSTRING namespace internal { @@ -1732,8 +1581,7 @@ namespace internal { template AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression, const char* rhs_expression, - RawType lhs_value, - RawType rhs_value) { + RawType lhs_value, RawType rhs_value) { const FloatingPoint lhs(lhs_value), rhs(rhs_value); if (lhs.AlmostEquals(rhs)) { @@ -1741,17 +1589,15 @@ AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression, } ::std::stringstream lhs_ss; - lhs_ss << std::setprecision(std::numeric_limits::digits10 + 2) - << lhs_value; + lhs_ss.precision(std::numeric_limits::digits10 + 2); + lhs_ss << lhs_value; ::std::stringstream rhs_ss; - rhs_ss << std::setprecision(std::numeric_limits::digits10 + 2) - << rhs_value; + rhs_ss.precision(std::numeric_limits::digits10 + 2); + rhs_ss << rhs_value; - return EqFailure(lhs_expression, - rhs_expression, - StringStreamToString(&lhs_ss), - StringStreamToString(&rhs_ss), + return EqFailure(lhs_expression, rhs_expression, + StringStreamToString(&lhs_ss), StringStreamToString(&rhs_ss), false); } @@ -1761,8 +1607,7 @@ AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression, GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1, const char* expr2, const char* abs_error_expr, - double val1, - double val2, + double val1, double val2, double abs_error); // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. @@ -1770,9 +1615,7 @@ GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1, class GTEST_API_ AssertHelper { public: // Constructor. - AssertHelper(TestPartResult::Type type, - const char* file, - int line, + AssertHelper(TestPartResult::Type type, const char* file, int line, const char* message); ~AssertHelper(); @@ -1786,11 +1629,9 @@ class GTEST_API_ AssertHelper { // re-using stack space even for temporary variables, so every EXPECT_EQ // reserves stack space for another AssertHelper. struct AssertHelperData { - AssertHelperData(TestPartResult::Type t, - const char* srcfile, - int line_num, + AssertHelperData(TestPartResult::Type t, const char* srcfile, int line_num, const char* msg) - : type(t), file(srcfile), line(line_num), message(msg) { } + : type(t), file(srcfile), line(line_num), message(msg) {} TestPartResult::Type const type; const char* const file; @@ -1798,12 +1639,14 @@ class GTEST_API_ AssertHelper { std::string const message; private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData); + AssertHelperData(const AssertHelperData&) = delete; + AssertHelperData& operator=(const AssertHelperData&) = delete; }; AssertHelperData* const data_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper); + AssertHelper(const AssertHelper&) = delete; + AssertHelper& operator=(const AssertHelper&) = delete; }; } // namespace internal @@ -1818,7 +1661,7 @@ class GTEST_API_ AssertHelper { // the GetParam() method. // // Use it with one of the parameter generator defining functions, like Range(), -// Values(), ValuesIn(), Bool(), and Combine(). +// Values(), ValuesIn(), Bool(), Combine(), and ConvertGenerator(). // // class FooTest : public ::testing::TestWithParam { // protected: @@ -1846,7 +1689,7 @@ template class WithParamInterface { public: typedef T ParamType; - virtual ~WithParamInterface() {} + virtual ~WithParamInterface() = default; // The current parameter value. Is also available in the test fixture's // constructor. @@ -1860,15 +1703,14 @@ class WithParamInterface { private: // Sets parameter value. The caller is responsible for making sure the value // remains alive and unchanged throughout the current test. - static void SetParam(const ParamType* parameter) { - parameter_ = parameter; - } + static void SetParam(const ParamType* parameter) { parameter_ = parameter; } // Static value used for accessing parameter during a test lifetime. static const ParamType* parameter_; // TestClass must be a subclass of WithParamInterface and Test. - template friend class internal::ParameterizedTestFactory; + template + friend class internal::ParameterizedTestFactory; }; template @@ -1878,8 +1720,7 @@ const T* WithParamInterface::parameter_ = nullptr; // WithParamInterface, and can just inherit from ::testing::TestWithParam. template -class TestWithParam : public Test, public WithParamInterface { -}; +class TestWithParam : public Test, public WithParamInterface {}; // Macros for indicating success/failure in test code. @@ -1910,7 +1751,7 @@ class TestWithParam : public Test, public WithParamInterface { // Generates a nonfatal failure at the given source file location with // a generic message. -#define ADD_FAILURE_AT(file, line) \ +#define ADD_FAILURE_AT(file, line) \ GTEST_MESSAGE_AT_(file, line, "Failed", \ ::testing::TestPartResult::kNonFatalFailure) @@ -1918,14 +1759,15 @@ class TestWithParam : public Test, public WithParamInterface { #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed") // Like GTEST_FAIL(), but at the given source file location. -#define GTEST_FAIL_AT(file, line) \ - GTEST_MESSAGE_AT_(file, line, "Failed", \ - ::testing::TestPartResult::kFatalFailure) +#define GTEST_FAIL_AT(file, line) \ + return GTEST_MESSAGE_AT_(file, line, "Failed", \ + ::testing::TestPartResult::kFatalFailure) // Define this macro to 1 to omit the definition of FAIL(), which is a // generic name and clashes with some other libraries. -#if !GTEST_DONT_DEFINE_FAIL -# define FAIL() GTEST_FAIL() +#if !(defined(GTEST_DONT_DEFINE_FAIL) && GTEST_DONT_DEFINE_FAIL) +#define FAIL() GTEST_FAIL() +#define FAIL_AT(file, line) GTEST_FAIL_AT(file, line) #endif // Generates a success with a generic message. @@ -1933,8 +1775,8 @@ class TestWithParam : public Test, public WithParamInterface { // Define this macro to 1 to omit the definition of SUCCEED(), which // is a generic name and clashes with some other libraries. -#if !GTEST_DONT_DEFINE_SUCCEED -# define SUCCEED() GTEST_SUCCEED() +#if !(defined(GTEST_DONT_DEFINE_SUCCEED) && GTEST_DONT_DEFINE_SUCCEED) +#define SUCCEED() GTEST_SUCCEED() #endif // Macros for testing exceptions. @@ -1962,35 +1804,34 @@ class TestWithParam : public Test, public WithParamInterface { // Boolean assertions. Condition can be either a Boolean expression or an // AssertionResult. For more information on how to use AssertionResult with // these macros see comments on that class. -#define GTEST_EXPECT_TRUE(condition) \ +#define GTEST_EXPECT_TRUE(condition) \ GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ GTEST_NONFATAL_FAILURE_) -#define GTEST_EXPECT_FALSE(condition) \ +#define GTEST_EXPECT_FALSE(condition) \ GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ GTEST_NONFATAL_FAILURE_) #define GTEST_ASSERT_TRUE(condition) \ - GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ - GTEST_FATAL_FAILURE_) -#define GTEST_ASSERT_FALSE(condition) \ + GTEST_TEST_BOOLEAN_(condition, #condition, false, true, GTEST_FATAL_FAILURE_) +#define GTEST_ASSERT_FALSE(condition) \ GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ GTEST_FATAL_FAILURE_) // Define these macros to 1 to omit the definition of the corresponding // EXPECT or ASSERT, which clashes with some users' own code. -#if !GTEST_DONT_DEFINE_EXPECT_TRUE +#if !(defined(GTEST_DONT_DEFINE_EXPECT_TRUE) && GTEST_DONT_DEFINE_EXPECT_TRUE) #define EXPECT_TRUE(condition) GTEST_EXPECT_TRUE(condition) #endif -#if !GTEST_DONT_DEFINE_EXPECT_FALSE +#if !(defined(GTEST_DONT_DEFINE_EXPECT_FALSE) && GTEST_DONT_DEFINE_EXPECT_FALSE) #define EXPECT_FALSE(condition) GTEST_EXPECT_FALSE(condition) #endif -#if !GTEST_DONT_DEFINE_ASSERT_TRUE +#if !(defined(GTEST_DONT_DEFINE_ASSERT_TRUE) && GTEST_DONT_DEFINE_ASSERT_TRUE) #define ASSERT_TRUE(condition) GTEST_ASSERT_TRUE(condition) #endif -#if !GTEST_DONT_DEFINE_ASSERT_FALSE +#if !(defined(GTEST_DONT_DEFINE_ASSERT_FALSE) && GTEST_DONT_DEFINE_ASSERT_FALSE) #define ASSERT_FALSE(condition) GTEST_ASSERT_FALSE(condition) #endif @@ -2069,28 +1910,28 @@ class TestWithParam : public Test, public WithParamInterface { // Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of // ASSERT_XY(), which clashes with some users' own code. -#if !GTEST_DONT_DEFINE_ASSERT_EQ -# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) +#if !(defined(GTEST_DONT_DEFINE_ASSERT_EQ) && GTEST_DONT_DEFINE_ASSERT_EQ) +#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) #endif -#if !GTEST_DONT_DEFINE_ASSERT_NE -# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2) +#if !(defined(GTEST_DONT_DEFINE_ASSERT_NE) && GTEST_DONT_DEFINE_ASSERT_NE) +#define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2) #endif -#if !GTEST_DONT_DEFINE_ASSERT_LE -# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2) +#if !(defined(GTEST_DONT_DEFINE_ASSERT_LE) && GTEST_DONT_DEFINE_ASSERT_LE) +#define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2) #endif -#if !GTEST_DONT_DEFINE_ASSERT_LT -# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2) +#if !(defined(GTEST_DONT_DEFINE_ASSERT_LT) && GTEST_DONT_DEFINE_ASSERT_LT) +#define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2) #endif -#if !GTEST_DONT_DEFINE_ASSERT_GE -# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2) +#if !(defined(GTEST_DONT_DEFINE_ASSERT_GE) && GTEST_DONT_DEFINE_ASSERT_GE) +#define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2) #endif -#if !GTEST_DONT_DEFINE_ASSERT_GT -# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) +#if !(defined(GTEST_DONT_DEFINE_ASSERT_GT) && GTEST_DONT_DEFINE_ASSERT_GT) +#define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) #endif // C-string Comparisons. All tests treat NULL and any non-NULL string @@ -2115,7 +1956,7 @@ class TestWithParam : public Test, public WithParamInterface { EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) #define EXPECT_STRCASEEQ(s1, s2) \ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2) -#define EXPECT_STRCASENE(s1, s2)\ +#define EXPECT_STRCASENE(s1, s2) \ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) #define ASSERT_STREQ(s1, s2) \ @@ -2124,7 +1965,7 @@ class TestWithParam : public Test, public WithParamInterface { ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) #define ASSERT_STRCASEEQ(s1, s2) \ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2) -#define ASSERT_STRCASENE(s1, s2)\ +#define ASSERT_STRCASENE(s1, s2) \ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) // Macros for comparing floating-point numbers. @@ -2141,29 +1982,29 @@ class TestWithParam : public Test, public WithParamInterface { // FloatingPoint template class in gtest-internal.h if you are // interested in the implementation details. -#define EXPECT_FLOAT_EQ(val1, val2)\ +#define EXPECT_FLOAT_EQ(val1, val2) \ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ, \ val1, val2) -#define EXPECT_DOUBLE_EQ(val1, val2)\ +#define EXPECT_DOUBLE_EQ(val1, val2) \ EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ, \ val1, val2) -#define ASSERT_FLOAT_EQ(val1, val2)\ +#define ASSERT_FLOAT_EQ(val1, val2) \ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ, \ val1, val2) -#define ASSERT_DOUBLE_EQ(val1, val2)\ +#define ASSERT_DOUBLE_EQ(val1, val2) \ ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ, \ val1, val2) -#define EXPECT_NEAR(val1, val2, abs_error)\ - EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \ - val1, val2, abs_error) +#define EXPECT_NEAR(val1, val2, abs_error) \ + EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, val1, val2, \ + abs_error) -#define ASSERT_NEAR(val1, val2, abs_error)\ - ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \ - val1, val2, abs_error) +#define ASSERT_NEAR(val1, val2, abs_error) \ + ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, val1, val2, \ + abs_error) // These predicate format functions work on floating-point values, and // can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g. @@ -2177,8 +2018,7 @@ GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2, GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, double val1, double val2); - -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Macros that test for HRESULT failure and success, these are only useful // on Windows, and rely on Windows SDK macros and APIs to compile. @@ -2189,17 +2029,17 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, // expected result and the actual result with both a human-readable // string representation of the error, if available, as well as the // hex result code. -# define EXPECT_HRESULT_SUCCEEDED(expr) \ - EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) +#define EXPECT_HRESULT_SUCCEEDED(expr) \ + EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) -# define ASSERT_HRESULT_SUCCEEDED(expr) \ - ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) +#define ASSERT_HRESULT_SUCCEEDED(expr) \ + ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) -# define EXPECT_HRESULT_FAILED(expr) \ - EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) +#define EXPECT_HRESULT_FAILED(expr) \ + EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) -# define ASSERT_HRESULT_FAILED(expr) \ - ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) +#define ASSERT_HRESULT_FAILED(expr) \ + ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) #endif // GTEST_OS_WINDOWS @@ -2214,9 +2054,9 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, // ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed"; // #define ASSERT_NO_FATAL_FAILURE(statement) \ - GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_) + GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_) #define EXPECT_NO_FATAL_FAILURE(statement) \ - GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_) + GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_) // Causes a trace (including the given source file path and line number, // and the given message) to be included in every test failure message generated @@ -2258,10 +2098,9 @@ class GTEST_API_ ScopedTrace { private: void PushTrace(const char* file, int line, std::string message); - GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace); -} GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its - // c'tor and d'tor. Therefore it doesn't - // need to be used otherwise. + ScopedTrace(const ScopedTrace&) = delete; + ScopedTrace& operator=(const ScopedTrace&) = delete; +}; // Causes a trace (including the source file path, the current line // number, and the given message) to be included in every test failure @@ -2278,9 +2117,9 @@ class GTEST_API_ ScopedTrace { // Assuming that each thread maintains its own stack of traces. // Therefore, a SCOPED_TRACE() would (correctly) only affect the // assertions in its own thread. -#define SCOPED_TRACE(message) \ - ::testing::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\ - __FILE__, __LINE__, (message)) +#define SCOPED_TRACE(message) \ + const ::testing::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)( \ + __FILE__, __LINE__, (message)) // Compile-time assertion for type equality. // StaticAssertTypeEq() compiles if and only if type1 and type2 @@ -2349,7 +2188,7 @@ constexpr bool StaticAssertTypeEq() noexcept { // Define this macro to 1 to omit the definition of TEST(), which // is a generic name and clashes with some other libraries. -#if !GTEST_DONT_DEFINE_TEST +#if !(defined(GTEST_DONT_DEFINE_TEST) && GTEST_DONT_DEFINE_TEST) #define TEST(test_suite_name, test_name) GTEST_TEST(test_suite_name, test_name) #endif @@ -2378,21 +2217,25 @@ constexpr bool StaticAssertTypeEq() noexcept { // EXPECT_EQ(a_.size(), 0); // EXPECT_EQ(b_.size(), 1); // } -// -// GOOGLETEST_CM0011 DO NOT DELETE -#if !GTEST_DONT_DEFINE_TEST -#define TEST_F(test_fixture, test_name)\ +#define GTEST_TEST_F(test_fixture, test_name) \ GTEST_TEST_(test_fixture, test_name, test_fixture, \ ::testing::internal::GetTypeId()) -#endif // !GTEST_DONT_DEFINE_TEST +#if !(defined(GTEST_DONT_DEFINE_TEST_F) && GTEST_DONT_DEFINE_TEST_F) +#define TEST_F(test_fixture, test_name) GTEST_TEST_F(test_fixture, test_name) +#endif -// Returns a path to temporary directory. -// Tries to determine an appropriate directory for the platform. +// Returns a path to a temporary directory, which should be writable. It is +// implementation-dependent whether or not the path is terminated by the +// directory-separator character. GTEST_API_ std::string TempDir(); -#ifdef _MSC_VER -# pragma warning(pop) -#endif +// Returns a path to a directory that contains ancillary data files that might +// be used by tests. It is implementation dependent whether or not the path is +// terminated by the directory-separator character. The directory and the files +// in it should be considered read-only. +GTEST_API_ std::string SrcDir(); + +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4805 4100 // Dynamically registers a test with the framework. // @@ -2445,6 +2288,7 @@ GTEST_API_ std::string TempDir(); // } // ... // int main(int argc, char** argv) { +// ::testing::InitGoogleTest(&argc, argv); // std::vector values_to_test = LoadValuesFromConfig(); // RegisterMyTests(values_to_test); // ... @@ -2480,15 +2324,14 @@ TestInfo* RegisterTest(const char* test_suite_name, const char* test_name, // tests are successful, or 1 otherwise. // // RUN_ALL_TESTS() should be invoked after the command line has been -// parsed by InitGoogleTest(). +// parsed by InitGoogleTest(). RUN_ALL_TESTS will tear down and delete any +// installed environments and should only be called once per binary. // // This function was formerly a macro; thus, it is in the global // namespace and has an all-caps name. -int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_; +[[nodiscard]] int RUN_ALL_TESTS(); -inline int RUN_ALL_TESTS() { - return ::testing::UnitTest::GetInstance()->Run(); -} +inline int RUN_ALL_TESTS() { return ::testing::UnitTest::GetInstance()->Run(); } GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest_pred_impl.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest_pred_impl.h index 5029a9bb02..47a24aa687 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/gtest_pred_impl.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest_pred_impl.h @@ -26,17 +26,19 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is AUTOMATICALLY GENERATED on 01/02/2019 by command -// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND! // // Implements a family of generic predicate assertion macros. -// GOOGLETEST_CM0001 DO NOT DELETE + +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ -#include "gtest/gtest.h" +#include "gtest/gtest-assertion-result.h" +#include "gtest/internal/gtest-internal.h" +#include "gtest/internal/gtest-port.h" namespace testing { @@ -72,22 +74,18 @@ namespace testing { // GTEST_ASSERT_ is the basic statement to which all of the assertions // in this file reduce. Don't use this in your code. -#define GTEST_ASSERT_(expression, on_failure) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ +#define GTEST_ASSERT_(expression, on_failure) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const ::testing::AssertionResult gtest_ar = (expression)) \ - ; \ - else \ + ; \ + else \ on_failure(gtest_ar.failure_message()) - // Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use // this in your code. -template -AssertionResult AssertPred1Helper(const char* pred_text, - const char* e1, - Pred pred, - const T1& v1) { +template +AssertionResult AssertPred1Helper(const char* pred_text, const char* e1, + Pred pred, const T1& v1) { if (pred(v1)) return AssertionSuccess(); return AssertionFailure() @@ -98,40 +96,27 @@ AssertionResult AssertPred1Helper(const char* pred_text, // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1. // Don't use this in your code. -#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\ - GTEST_ASSERT_(pred_format(#v1, v1), \ - on_failure) +#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure) \ + GTEST_ASSERT_(pred_format(#v1, v1), on_failure) // Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use // this in your code. -#define GTEST_PRED1_(pred, v1, on_failure)\ - GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \ - #v1, \ - pred, \ - v1), on_failure) +#define GTEST_PRED1_(pred, v1, on_failure) \ + GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, #v1, pred, v1), on_failure) // Unary predicate assertion macros. #define EXPECT_PRED_FORMAT1(pred_format, v1) \ GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_) -#define EXPECT_PRED1(pred, v1) \ - GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_) +#define EXPECT_PRED1(pred, v1) GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_) #define ASSERT_PRED_FORMAT1(pred_format, v1) \ GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_) -#define ASSERT_PRED1(pred, v1) \ - GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_) - - +#define ASSERT_PRED1(pred, v1) GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_) // Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use // this in your code. -template -AssertionResult AssertPred2Helper(const char* pred_text, - const char* e1, - const char* e2, - Pred pred, - const T1& v1, +template +AssertionResult AssertPred2Helper(const char* pred_text, const char* e1, + const char* e2, Pred pred, const T1& v1, const T2& v2) { if (pred(v1, v2)) return AssertionSuccess(); @@ -145,19 +130,14 @@ AssertionResult AssertPred2Helper(const char* pred_text, // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2. // Don't use this in your code. -#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\ - GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \ - on_failure) +#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure) \ + GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure) // Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use // this in your code. -#define GTEST_PRED2_(pred, v1, v2, on_failure)\ - GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \ - #v1, \ - #v2, \ - pred, \ - v1, \ - v2), on_failure) +#define GTEST_PRED2_(pred, v1, v2, on_failure) \ + GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, #v1, #v2, pred, v1, v2), \ + on_failure) // Binary predicate assertion macros. #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \ @@ -169,22 +149,12 @@ AssertionResult AssertPred2Helper(const char* pred_text, #define ASSERT_PRED2(pred, v1, v2) \ GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_) - - // Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use // this in your code. -template -AssertionResult AssertPred3Helper(const char* pred_text, - const char* e1, - const char* e2, - const char* e3, - Pred pred, - const T1& v1, - const T2& v2, - const T3& v3) { +template +AssertionResult AssertPred3Helper(const char* pred_text, const char* e1, + const char* e2, const char* e3, Pred pred, + const T1& v1, const T2& v2, const T3& v3) { if (pred(v1, v2, v3)) return AssertionSuccess(); return AssertionFailure() @@ -198,21 +168,15 @@ AssertionResult AssertPred3Helper(const char* pred_text, // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3. // Don't use this in your code. -#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\ - GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \ - on_failure) +#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure) \ + GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), on_failure) // Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use // this in your code. -#define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\ - GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \ - #v1, \ - #v2, \ - #v3, \ - pred, \ - v1, \ - v2, \ - v3), on_failure) +#define GTEST_PRED3_(pred, v1, v2, v3, on_failure) \ + GTEST_ASSERT_( \ + ::testing::AssertPred3Helper(#pred, #v1, #v2, #v3, pred, v1, v2, v3), \ + on_failure) // Ternary predicate assertion macros. #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \ @@ -224,25 +188,13 @@ AssertionResult AssertPred3Helper(const char* pred_text, #define ASSERT_PRED3(pred, v1, v2, v3) \ GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_) - - // Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use // this in your code. -template -AssertionResult AssertPred4Helper(const char* pred_text, - const char* e1, - const char* e2, - const char* e3, - const char* e4, - Pred pred, - const T1& v1, - const T2& v2, - const T3& v3, - const T4& v4) { +template +AssertionResult AssertPred4Helper(const char* pred_text, const char* e1, + const char* e2, const char* e3, + const char* e4, Pred pred, const T1& v1, + const T2& v2, const T3& v3, const T4& v4) { if (pred(v1, v2, v3, v4)) return AssertionSuccess(); return AssertionFailure() @@ -257,23 +209,15 @@ AssertionResult AssertPred4Helper(const char* pred_text, // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4. // Don't use this in your code. -#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\ - GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \ - on_failure) +#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure) \ + GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), on_failure) // Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use // this in your code. -#define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\ - GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \ - #v1, \ - #v2, \ - #v3, \ - #v4, \ - pred, \ - v1, \ - v2, \ - v3, \ - v4), on_failure) +#define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure) \ + GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, #v1, #v2, #v3, #v4, pred, \ + v1, v2, v3, v4), \ + on_failure) // 4-ary predicate assertion macros. #define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \ @@ -285,28 +229,15 @@ AssertionResult AssertPred4Helper(const char* pred_text, #define ASSERT_PRED4(pred, v1, v2, v3, v4) \ GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_) - - // Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use // this in your code. -template -AssertionResult AssertPred5Helper(const char* pred_text, - const char* e1, - const char* e2, - const char* e3, - const char* e4, - const char* e5, - Pred pred, - const T1& v1, - const T2& v2, - const T3& v3, - const T4& v4, - const T5& v5) { +AssertionResult AssertPred5Helper(const char* pred_text, const char* e1, + const char* e2, const char* e3, + const char* e4, const char* e5, Pred pred, + const T1& v1, const T2& v2, const T3& v3, + const T4& v4, const T5& v5) { if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess(); return AssertionFailure() @@ -322,25 +253,16 @@ AssertionResult AssertPred5Helper(const char* pred_text, // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5. // Don't use this in your code. -#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\ +#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure) \ GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \ on_failure) // Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use // this in your code. -#define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\ - GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \ - #v1, \ - #v2, \ - #v3, \ - #v4, \ - #v5, \ - pred, \ - v1, \ - v2, \ - v3, \ - v4, \ - v5), on_failure) +#define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure) \ + GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, #v1, #v2, #v3, #v4, #v5, \ + pred, v1, v2, v3, v4, v5), \ + on_failure) // 5-ary predicate assertion macros. #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \ @@ -352,8 +274,6 @@ AssertionResult AssertPred5Helper(const char* pred_text, #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \ GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_) - - } // namespace testing #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/gtest_prod.h b/libs/libvpx/third_party/googletest/src/include/gtest/gtest_prod.h index 38b9d85a51..1f37dc31c3 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/gtest_prod.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/gtest_prod.h @@ -27,9 +27,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Google C++ Testing and Mocking Framework definitions useful in production code. -// GOOGLETEST_CM0003 DO NOT DELETE +// Google C++ Testing and Mocking Framework definitions useful in production +// code. #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PROD_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_PROD_H_ @@ -55,7 +54,7 @@ // Note: The test class must be in the same namespace as the class being tested. // For example, putting MyClassTest in an anonymous namespace will not work. -#define FRIEND_TEST(test_case_name, test_name)\ -friend class test_case_name##_##test_name##_Test +#define FRIEND_TEST(test_case_name, test_name) \ + friend class test_case_name##_##test_name##_Test #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_PROD_H_ diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/internal/custom/README.md b/libs/libvpx/third_party/googletest/src/include/gtest/internal/custom/README.md index ff391fb4e2..cb49e2c754 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/internal/custom/README.md +++ b/libs/libvpx/third_party/googletest/src/include/gtest/internal/custom/README.md @@ -15,18 +15,6 @@ The custom directory is an injection point for custom user configurations. The following macros can be defined: -### Flag related macros: - -* `GTEST_FLAG(flag_name)` -* `GTEST_USE_OWN_FLAGFILE_FLAG_` - Define to 0 when the system provides its - own flagfile flag parsing. -* `GTEST_DECLARE_bool_(name)` -* `GTEST_DECLARE_int32_(name)` -* `GTEST_DECLARE_string_(name)` -* `GTEST_DEFINE_bool_(name, default_val, doc)` -* `GTEST_DEFINE_int32_(name, default_val, doc)` -* `GTEST_DEFINE_string_(name, default_val, doc)` - ### Logging: * `GTEST_LOG_(severity)` diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-death-test-internal.h b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-death-test-internal.h index 490296dfad..b363259ec6 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-death-test-internal.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-death-test-internal.h @@ -26,33 +26,59 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// + // The Google C++ Testing and Mocking Framework (Google Test) // // This header file defines internal utilities needed for implementing // death tests. They are subject to change without notice. -// GOOGLETEST_CM0001 DO NOT DELETE + +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ +#include + +#include +#include + #include "gtest/gtest-matchers.h" #include "gtest/internal/gtest-internal.h" +#include "gtest/internal/gtest-port.h" -#include -#include +GTEST_DECLARE_string_(internal_run_death_test); namespace testing { namespace internal { -GTEST_DECLARE_string_(internal_run_death_test); - -// Names of the flags (needed for parsing Google Test flags). -const char kDeathTestStyleFlag[] = "death_test_style"; -const char kDeathTestUseFork[] = "death_test_use_fork"; +// Name of the flag (needed for parsing Google Test flag). const char kInternalRunDeathTestFlag[] = "internal_run_death_test"; -#if GTEST_HAS_DEATH_TEST +// A string passed to EXPECT_DEATH (etc.) is caught by one of these overloads +// and interpreted as a regex (rather than an Eq matcher) for legacy +// compatibility. +inline Matcher MakeDeathTestMatcher( + ::testing::internal::RE regex) { + return ContainsRegex(regex.pattern()); +} +inline Matcher MakeDeathTestMatcher(const char* regex) { + return ContainsRegex(regex); +} +inline Matcher MakeDeathTestMatcher( + const ::std::string& regex) { + return ContainsRegex(regex); +} + +// If a Matcher is passed to EXPECT_DEATH (etc.), it's +// used directly. +inline Matcher MakeDeathTestMatcher( + Matcher matcher) { + return matcher; +} + +#ifdef GTEST_HAS_DEATH_TEST GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ /* class A needs to have dll-interface to be used by clients of class B */) @@ -68,7 +94,7 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ // // exit status: The integer exit information in the format specified // by wait(2) -// exit code: The integer code passed to exit(3), _exit(2), or +// exit code: The integer code passed to exit(3), _Exit(2), or // returned from main() class GTEST_API_ DeathTest { public: @@ -83,17 +109,19 @@ class GTEST_API_ DeathTest { static bool Create(const char* statement, Matcher matcher, const char* file, int line, DeathTest** test); DeathTest(); - virtual ~DeathTest() { } + virtual ~DeathTest() = default; // A helper class that aborts a death test when it's deleted. class ReturnSentinel { public: - explicit ReturnSentinel(DeathTest* test) : test_(test) { } + explicit ReturnSentinel(DeathTest* test) : test_(test) {} ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); } + private: DeathTest* const test_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel); - } GTEST_ATTRIBUTE_UNUSED_; + ReturnSentinel(const ReturnSentinel&) = delete; + ReturnSentinel& operator=(const ReturnSentinel&) = delete; + }; // An enumeration of possible roles that may be taken when a death // test is encountered. EXECUTE means that the death test logic should @@ -137,7 +165,8 @@ class GTEST_API_ DeathTest { // A string containing a description of the outcome of the last death test. static std::string last_death_test_message_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest); + DeathTest(const DeathTest&) = delete; + DeathTest& operator=(const DeathTest&) = delete; }; GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 @@ -145,7 +174,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 // Factory interface for death tests. May be mocked out for testing. class DeathTestFactory { public: - virtual ~DeathTestFactory() { } + virtual ~DeathTestFactory() = default; virtual bool Create(const char* statement, Matcher matcher, const char* file, int line, DeathTest** test) = 0; @@ -162,52 +191,30 @@ class DefaultDeathTestFactory : public DeathTestFactory { // by a signal, or exited normally with a nonzero exit code. GTEST_API_ bool ExitedUnsuccessfully(int exit_status); -// A string passed to EXPECT_DEATH (etc.) is caught by one of these overloads -// and interpreted as a regex (rather than an Eq matcher) for legacy -// compatibility. -inline Matcher MakeDeathTestMatcher( - ::testing::internal::RE regex) { - return ContainsRegex(regex.pattern()); -} -inline Matcher MakeDeathTestMatcher(const char* regex) { - return ContainsRegex(regex); -} -inline Matcher MakeDeathTestMatcher( - const ::std::string& regex) { - return ContainsRegex(regex); -} - -// If a Matcher is passed to EXPECT_DEATH (etc.), it's -// used directly. -inline Matcher MakeDeathTestMatcher( - Matcher matcher) { - return matcher; -} - // Traps C++ exceptions escaping statement and reports them as test // failures. Note that trapping SEH exceptions is not implemented here. -# if GTEST_HAS_EXCEPTIONS -# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ - try { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - } catch (const ::std::exception& gtest_exception) { \ - fprintf(\ - stderr, \ - "\n%s: Caught std::exception-derived exception escaping the " \ - "death test statement. Exception message: %s\n", \ +#if GTEST_HAS_EXCEPTIONS +#define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } catch (const ::std::exception& gtest_exception) { \ + fprintf( \ + stderr, \ + "\n%s: Caught std::exception-derived exception escaping the " \ + "death test statement. Exception message: %s\n", \ ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \ - gtest_exception.what()); \ - fflush(stderr); \ + gtest_exception.what()); \ + fflush(stderr); \ death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ - } catch (...) { \ + } catch (...) { \ death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ } -# else -# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ +#else +#define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) -# endif +#endif // This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*, // ASSERT_EXIT*, and EXPECT_EXIT*. @@ -230,14 +237,12 @@ inline Matcher MakeDeathTestMatcher( } \ break; \ case ::testing::internal::DeathTest::EXECUTE_TEST: { \ - ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \ + const ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \ gtest_dt); \ GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \ gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ break; \ } \ - default: \ - break; \ } \ } \ } else \ @@ -265,16 +270,12 @@ inline Matcher MakeDeathTestMatcher( // RUN_ALL_TESTS was called. class InternalRunDeathTestFlag { public: - InternalRunDeathTestFlag(const std::string& a_file, - int a_line, - int an_index, + InternalRunDeathTestFlag(const std::string& a_file, int a_line, int an_index, int a_write_fd) - : file_(a_file), line_(a_line), index_(an_index), - write_fd_(a_write_fd) {} + : file_(a_file), line_(a_line), index_(an_index), write_fd_(a_write_fd) {} ~InternalRunDeathTestFlag() { - if (write_fd_ >= 0) - posix::Close(write_fd_); + if (write_fd_ >= 0) posix::Close(write_fd_); } const std::string& file() const { return file_; } @@ -288,7 +289,8 @@ class InternalRunDeathTestFlag { int index_; int write_fd_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag); + InternalRunDeathTestFlag(const InternalRunDeathTestFlag&) = delete; + InternalRunDeathTestFlag& operator=(const InternalRunDeathTestFlag&) = delete; }; // Returns a newly created InternalRunDeathTestFlag object with fields diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-filepath.h b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-filepath.h index 0c033abc34..6dc47be54a 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-filepath.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-filepath.h @@ -26,7 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// + // Google Test filepath utilities // // This header file declares classes and functions used internally by @@ -35,16 +35,24 @@ // This file is #included in gtest/internal/gtest-internal.h. // Do not include this header file separately! -// GOOGLETEST_CM0001 DO NOT DELETE +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ +#include +#include + +#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-string.h" GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ /* class A needs to have dll-interface to be used by clients of class B */) +#if GTEST_HAS_FILE_SYSTEM + namespace testing { namespace internal { @@ -61,10 +69,11 @@ namespace internal { class GTEST_API_ FilePath { public: - FilePath() : pathname_("") { } - FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { } + FilePath() : pathname_("") {} + FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) {} + FilePath(FilePath&& rhs) noexcept : pathname_(std::move(rhs.pathname_)) {} - explicit FilePath(const std::string& pathname) : pathname_(pathname) { + explicit FilePath(std::string pathname) : pathname_(std::move(pathname)) { Normalize(); } @@ -72,11 +81,13 @@ class GTEST_API_ FilePath { Set(rhs); return *this; } - - void Set(const FilePath& rhs) { - pathname_ = rhs.pathname_; + FilePath& operator=(FilePath&& rhs) noexcept { + pathname_ = std::move(rhs.pathname_); + return *this; } + void Set(const FilePath& rhs) { pathname_ = rhs.pathname_; } + const std::string& string() const { return pathname_; } const char* c_str() const { return pathname_.c_str(); } @@ -88,8 +99,7 @@ class GTEST_API_ FilePath { // than zero (e.g., 12), returns "dir/test_12.xml". // On Windows platform, uses \ as the separator rather than /. static FilePath MakeFileName(const FilePath& directory, - const FilePath& base_name, - int number, + const FilePath& base_name, int number, const char* extension); // Given directory = "dir", relative_path = "test.xml", @@ -200,6 +210,16 @@ class GTEST_API_ FilePath { // separators. Returns NULL if no path separator was found. const char* FindLastPathSeparator() const; + // Returns the length of the path root, including the directory separator at + // the end of the prefix. Returns zero by definition if the path is relative. + // Examples: + // - [Windows] "..\Sibling" => 0 + // - [Windows] "\Windows" => 1 + // - [Windows] "C:/Windows\Notepad.exe" => 3 + // - [Windows] "\\Host\Share\C$/Windows" => 13 + // - [UNIX] "/bin" => 1 + size_t CalculateRootLength() const; + std::string pathname_; }; // class FilePath @@ -208,4 +228,6 @@ class GTEST_API_ FilePath { GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 +#endif // GTEST_HAS_FILE_SYSTEM + #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-internal.h b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-internal.h index f8cbdbd81d..808d89be91 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-internal.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-internal.h @@ -26,40 +26,44 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// + // The Google C++ Testing and Mocking Framework (Google Test) // // This header file declares functions and macros used internally by // Google Test. They are subject to change without notice. -// GOOGLETEST_CM0001 DO NOT DELETE +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ #include "gtest/internal/gtest-port.h" -#if GTEST_OS_LINUX -# include -# include -# include -# include +#ifdef GTEST_OS_LINUX +#include +#include +#include +#include #endif // GTEST_OS_LINUX #if GTEST_HAS_EXCEPTIONS -# include +#include #endif #include #include #include + #include -#include +#include #include #include #include #include #include +#include #include #include "gtest/gtest-message.h" @@ -74,9 +78,9 @@ // // will result in the token foo__LINE__, instead of foo followed by // the current line number. For more details, see -// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 +// https://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar) -#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar +#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo##bar // Stringifies its argument. // Work around a bug in visual studio which doesn't accept code like this: @@ -98,21 +102,21 @@ namespace testing { // Forward declarations. -class AssertionResult; // Result of an assertion. -class Message; // Represents a failure message. -class Test; // Represents a test. -class TestInfo; // Information about a test. -class TestPartResult; // Result of a test part. -class UnitTest; // A collection of test suites. +class AssertionResult; // Result of an assertion. +class Message; // Represents a failure message. +class Test; // Represents a test. +class TestInfo; // Information about a test. +class TestPartResult; // Result of a test part. +class UnitTest; // A collection of test suites. template ::std::string PrintToString(const T& value); namespace internal { -struct TraceInfo; // Information about a trace point. -class TestInfoImpl; // Opaque implementation of TestInfo -class UnitTestImpl; // Opaque implementation of UnitTest +struct TraceInfo; // Information about a trace point. +class TestInfoImpl; // Opaque implementation of TestInfo +class UnitTestImpl; // Opaque implementation of UnitTest // The text used in failure messages to indicate the start of the // stack trace. @@ -121,6 +125,7 @@ GTEST_API_ extern const char kStackTraceMarker[]; // An IgnoredValue object can be implicitly constructed from ANY value. class IgnoredValue { struct Sink {}; + public: // This constructor template allows any value to be implicitly // converted to IgnoredValue. The object has no data member and @@ -136,13 +141,13 @@ class IgnoredValue { }; // Appends the user-supplied message to the Google-Test-generated message. -GTEST_API_ std::string AppendUserMessage( - const std::string& gtest_msg, const Message& user_msg); +GTEST_API_ std::string AppendUserMessage(const std::string& gtest_msg, + const Message& user_msg); #if GTEST_HAS_EXCEPTIONS -GTEST_DISABLE_MSC_WARNINGS_PUSH_(4275 \ -/* an exported class was derived from a class that was not exported */) +GTEST_DISABLE_MSC_WARNINGS_PUSH_( + 4275 /* an exported class was derived from a class that was not exported */) // This exception is thrown by (and only by) a failed Google Test // assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions @@ -164,7 +169,7 @@ namespace edit_distance { // All edits cost the same, with replace having lower priority than // add/remove. // Simple implementation of the Wagner-Fischer algorithm. -// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm +// See https://en.wikipedia.org/wiki/Wagner-Fischer_algorithm enum EditType { kMatch, kAdd, kRemove, kReplace }; GTEST_API_ std::vector CalculateOptimalEdits( const std::vector& left, const std::vector& right); @@ -181,14 +186,6 @@ GTEST_API_ std::string CreateUnifiedDiff(const std::vector& left, } // namespace edit_distance -// Calculate the diff between 'left' and 'right' and return it in unified diff -// format. -// If not null, stores in 'total_line_count' the total number of lines found -// in left + right. -GTEST_API_ std::string DiffStrings(const std::string& left, - const std::string& right, - size_t* total_line_count); - // Constructs and returns the message for an equality assertion // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. // @@ -212,10 +209,8 @@ GTEST_API_ AssertionResult EqFailure(const char* expected_expression, // Constructs a failure message for Boolean assertions such as EXPECT_TRUE. GTEST_API_ std::string GetBoolAssertionFailureMessage( - const AssertionResult& assertion_result, - const char* expression_text, - const char* actual_predicate_value, - const char* expected_predicate_value); + const AssertionResult& assertion_result, const char* expression_text, + const char* actual_predicate_value, const char* expected_predicate_value); // This template class represents an IEEE floating-point number // (either single-precision or double-precision, depending on the @@ -241,7 +236,7 @@ GTEST_API_ std::string GetBoolAssertionFailureMessage( // For double, there are 11 exponent bits and 52 fraction bits. // // More details can be found at -// http://en.wikipedia.org/wiki/IEEE_floating-point_standard. +// https://en.wikipedia.org/wiki/IEEE_floating-point_standard. // // Template parameter: // @@ -256,11 +251,11 @@ class FloatingPoint { // Constants. // # of bits in a number. - static const size_t kBitCount = 8*sizeof(RawType); + static const size_t kBitCount = 8 * sizeof(RawType); // # of fraction bits in a number. static const size_t kFractionBitCount = - std::numeric_limits::digits - 1; + std::numeric_limits::digits - 1; // # of exponent bits in a number. static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount; @@ -269,8 +264,8 @@ class FloatingPoint { static const Bits kSignBitMask = static_cast(1) << (kBitCount - 1); // The mask for the fraction bits. - static const Bits kFractionBitMask = - ~static_cast(0) >> (kExponentBitCount + 1); + static const Bits kFractionBitMask = ~static_cast(0) >> + (kExponentBitCount + 1); // The mask for the exponent bits. static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask); @@ -286,7 +281,7 @@ class FloatingPoint { // bits. Therefore, 4 should be enough for ordinary use. // // See the following article for more details on ULP: - // http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ + // https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ static const uint32_t kMaxUlps = 4; // Constructs a FloatingPoint from a raw floating-point number. @@ -295,40 +290,35 @@ class FloatingPoint { // around may change its bits, although the new value is guaranteed // to be also a NAN. Therefore, don't expect this constructor to // preserve the bits in x when x is a NAN. - explicit FloatingPoint(const RawType& x) { u_.value_ = x; } + explicit FloatingPoint(RawType x) { memcpy(&bits_, &x, sizeof(x)); } // Static methods // Reinterprets a bit pattern as a floating-point number. // // This function is needed to test the AlmostEquals() method. - static RawType ReinterpretBits(const Bits bits) { - FloatingPoint fp(0); - fp.u_.bits_ = bits; - return fp.u_.value_; + static RawType ReinterpretBits(Bits bits) { + RawType fp; + memcpy(&fp, &bits, sizeof(fp)); + return fp; } // Returns the floating-point number that represent positive infinity. - static RawType Infinity() { - return ReinterpretBits(kExponentBitMask); - } - - // Returns the maximum representable finite floating-point number. - static RawType Max(); + static RawType Infinity() { return ReinterpretBits(kExponentBitMask); } // Non-static methods // Returns the bits that represents this number. - const Bits &bits() const { return u_.bits_; } + const Bits& bits() const { return bits_; } // Returns the exponent bits of this number. - Bits exponent_bits() const { return kExponentBitMask & u_.bits_; } + Bits exponent_bits() const { return kExponentBitMask & bits_; } // Returns the fraction bits of this number. - Bits fraction_bits() const { return kFractionBitMask & u_.bits_; } + Bits fraction_bits() const { return kFractionBitMask & bits_; } // Returns the sign bit of this number. - Bits sign_bit() const { return kSignBitMask & u_.bits_; } + Bits sign_bit() const { return kSignBitMask & bits_; } // Returns true if and only if this is NAN (not a number). bool is_nan() const { @@ -342,23 +332,16 @@ class FloatingPoint { // // - returns false if either number is (or both are) NAN. // - treats really large numbers as almost equal to infinity. - // - thinks +0.0 and -0.0 are 0 DLP's apart. + // - thinks +0.0 and -0.0 are 0 ULP's apart. bool AlmostEquals(const FloatingPoint& rhs) const { // The IEEE standard says that any comparison operation involving // a NAN must return false. if (is_nan() || rhs.is_nan()) return false; - return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_) - <= kMaxUlps; + return DistanceBetweenSignAndMagnitudeNumbers(bits_, rhs.bits_) <= kMaxUlps; } private: - // The data type used to store the actual floating-point number. - union FloatingPointUnion { - RawType value_; // The raw floating-point number. - Bits bits_; // The bits that represent the number. - }; - // Converts an integer from the sign-and-magnitude representation to // the biased representation. More precisely, let N be 2 to the // power of (kBitCount - 1), an integer x is represented by the @@ -372,9 +355,9 @@ class FloatingPoint { // N - 1 (the biggest number representable using // sign-and-magnitude) is represented by 2N - 1. // - // Read http://en.wikipedia.org/wiki/Signed_number_representations + // Read https://en.wikipedia.org/wiki/Signed_number_representations // for more details on signed number representations. - static Bits SignAndMagnitudeToBiased(const Bits &sam) { + static Bits SignAndMagnitudeToBiased(Bits sam) { if (kSignBitMask & sam) { // sam represents a negative number. return ~sam + 1; @@ -386,23 +369,15 @@ class FloatingPoint { // Given two numbers in the sign-and-magnitude representation, // returns the distance between them as an unsigned number. - static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1, - const Bits &sam2) { + static Bits DistanceBetweenSignAndMagnitudeNumbers(Bits sam1, Bits sam2) { const Bits biased1 = SignAndMagnitudeToBiased(sam1); const Bits biased2 = SignAndMagnitudeToBiased(sam2); return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1); } - FloatingPointUnion u_; + Bits bits_; // The bits that represent the number. }; -// We cannot use std::numeric_limits::max() as it clashes with the max() -// macro defined by . -template <> -inline float FloatingPoint::Max() { return FLT_MAX; } -template <> -inline double FloatingPoint::Max() { return DBL_MAX; } - // Typedefs the instances of the FloatingPoint template class that we // care to use. typedef FloatingPoint Float; @@ -451,7 +426,7 @@ GTEST_API_ TypeId GetTestTypeId(); // of a Test object. class TestFactoryBase { public: - virtual ~TestFactoryBase() {} + virtual ~TestFactoryBase() = default; // Creates a test instance to run. The instance is both created and destroyed // within TestInfoImpl::Run() @@ -461,10 +436,11 @@ class TestFactoryBase { TestFactoryBase() {} private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase); + TestFactoryBase(const TestFactoryBase&) = delete; + TestFactoryBase& operator=(const TestFactoryBase&) = delete; }; -// This class provides implementation of TeastFactoryBase interface. +// This class provides implementation of TestFactoryBase interface. // It is used in TEST and TEST_F macros. template class TestFactoryImpl : public TestFactoryBase { @@ -472,7 +448,7 @@ class TestFactoryImpl : public TestFactoryBase { Test* CreateTest() override { return new TestClass; } }; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Predicate-formatters for implementing the HRESULT checking macros // {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED} @@ -490,8 +466,8 @@ using SetUpTestSuiteFunc = void (*)(); using TearDownTestSuiteFunc = void (*)(); struct CodeLocation { - CodeLocation(const std::string& a_file, int a_line) - : file(a_file), line(a_line) {} + CodeLocation(std::string a_file, int a_line) + : file(std::move(a_file)), line(a_line) {} std::string file; int line; @@ -510,11 +486,11 @@ inline SetUpTearDownSuiteFuncType GetNotDefaultOrNull( template // Note that SuiteApiResolver inherits from T because -// SetUpTestSuite()/TearDownTestSuite() could be protected. Ths way +// SetUpTestSuite()/TearDownTestSuite() could be protected. This way // SuiteApiResolver can access them. struct SuiteApiResolver : T { // testing::Test is only forward declared at this point. So we make it a - // dependend class for the compiler to be OK with it. + // dependent class for the compiler to be OK with it. using Test = typename std::conditional::type; @@ -571,7 +547,7 @@ struct SuiteApiResolver : T { // type_param: the name of the test's type parameter, or NULL if // this is not a typed or a type-parameterized test. // value_param: text representation of the test's value parameter, -// or NULL if this is not a type-parameterized test. +// or NULL if this is not a value-parameterized test. // code_location: code location where the test is defined // fixture_class_id: ID of the test fixture class // set_up_tc: pointer to the function that sets up the test suite @@ -580,7 +556,7 @@ struct SuiteApiResolver : T { // The newly created TestInfo instance will assume // ownership of the factory object. GTEST_API_ TestInfo* MakeAndRegisterTestInfo( - const char* test_suite_name, const char* name, const char* type_param, + std::string test_suite_name, const char* name, const char* type_param, const char* value_param, CodeLocation code_location, TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc, TearDownTestSuiteFunc tear_down_tc, TestFactoryBase* factory); @@ -611,8 +587,7 @@ class GTEST_API_ TypedTestSuitePState { fflush(stderr); posix::Abort(); } - registered_tests_.insert( - ::std::make_pair(test_name, CodeLocation(file, line))); + registered_tests_.emplace(test_name, CodeLocation(file, line)); return true; } @@ -634,7 +609,7 @@ class GTEST_API_ TypedTestSuitePState { const char* registered_tests); private: - typedef ::std::map RegisteredTestsMap; + typedef ::std::map> RegisteredTestsMap; bool registered_; RegisteredTestsMap registered_tests_; @@ -654,7 +629,8 @@ inline const char* SkipComma(const char* str) { if (comma == nullptr) { return nullptr; } - while (IsSpace(*(++comma))) {} + while (IsSpace(*(++comma))) { + } return comma; } @@ -668,7 +644,7 @@ inline std::string GetPrefixUntilComma(const char* str) { // Splits a given string on a given delimiter, populating a given // vector with the fields. void SplitString(const ::std::string& str, char delimiter, - ::std::vector< ::std::string>* dest); + ::std::vector<::std::string>* dest); // The default argument to the template below for the case when the user does // not provide a name generator. @@ -715,7 +691,7 @@ class TypeParameterizedTest { // specified in INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, TestSuite, // Types). Valid values for 'index' are [0, N - 1] where N is the // length of Types. - static bool Register(const char* prefix, const CodeLocation& code_location, + static bool Register(const char* prefix, CodeLocation code_location, const char* case_name, const char* test_names, int index, const std::vector& type_names = GenerateNames()) { @@ -727,8 +703,7 @@ class TypeParameterizedTest { // list. MakeAndRegisterTestInfo( (std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + - "/" + type_names[static_cast(index)]) - .c_str(), + "/" + type_names[static_cast(index)]), StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(), GetTypeName().c_str(), nullptr, // No value parameter. @@ -740,13 +715,9 @@ class TypeParameterizedTest { new TestFactoryImpl); // Next, recurses (at compile time) with the tail of the type list. - return TypeParameterizedTest::Register(prefix, - code_location, - case_name, - test_names, - index + 1, - type_names); + return TypeParameterizedTest:: + Register(prefix, std::move(code_location), case_name, test_names, + index + 1, type_names); } }; @@ -754,7 +725,7 @@ class TypeParameterizedTest { template class TypeParameterizedTest { public: - static bool Register(const char* /*prefix*/, const CodeLocation&, + static bool Register(const char* /*prefix*/, CodeLocation, const char* /*case_name*/, const char* /*test_names*/, int /*index*/, const std::vector& = @@ -781,13 +752,13 @@ class TypeParameterizedTestSuite { const std::vector& type_names = GenerateNames()) { RegisterTypeParameterizedTestSuiteInstantiation(case_name); - std::string test_name = StripTrailingSpaces( - GetPrefixUntilComma(test_names)); + std::string test_name = + StripTrailingSpaces(GetPrefixUntilComma(test_names)); if (!state->TestExists(test_name)) { fprintf(stderr, "Failed to get code location for test %s.%s at %s.", case_name, test_name.c_str(), - FormatFileLocation(code_location.file.c_str(), - code_location.line).c_str()); + FormatFileLocation(code_location.file.c_str(), code_location.line) + .c_str()); fflush(stderr); posix::Abort(); } @@ -801,7 +772,8 @@ class TypeParameterizedTestSuite { // Next, recurses (at compile time) with the tail of the test list. return TypeParameterizedTestSuite::Register(prefix, code_location, + Types>::Register(prefix, + std::move(code_location), state, case_name, SkipComma(test_names), type_names); @@ -831,8 +803,7 @@ class TypeParameterizedTestSuite { // For example, if Foo() calls Bar(), which in turn calls // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. -GTEST_API_ std::string GetCurrentOsStackTraceExceptTop( - UnitTest* unit_test, int skip_count); +GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(int skip_count); // Helpers for suppressing warnings on unreachable code or constant // condition. @@ -881,7 +852,8 @@ class GTEST_API_ Random { private: uint32_t state_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(Random); + Random(const Random&) = delete; + Random& operator=(const Random&) = delete; }; // Turns const U&, U&, const U, and U all into U. @@ -914,9 +886,6 @@ class HasDebugStringAndShortDebugString { HasDebugStringType::value && HasShortDebugStringType::value; }; -template -constexpr bool HasDebugStringAndShortDebugString::value; - // When the compiler sees expression IsContainerTest(0), if C is an // STL-style container class, the first overload of IsContainerTest // will be viable (since both C::iterator* and C::const_iterator* are @@ -954,7 +923,9 @@ IsContainer IsContainerTest(int /* dummy */) { typedef char IsNotContainer; template -IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; } +IsNotContainer IsContainerTest(long /* dummy */) { + return '\0'; +} // Trait to detect whether a type T is a hash table. // The heuristic used is that the type contains an inner type `hasher` and does @@ -1017,11 +988,13 @@ bool ArrayEq(const T* lhs, size_t size, const U* rhs); // This generic version is used when k is 0. template -inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; } +inline bool ArrayEq(const T& lhs, const U& rhs) { + return lhs == rhs; +} // This overload is used when k >= 1. template -inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) { +inline bool ArrayEq(const T (&lhs)[N], const U (&rhs)[N]) { return internal::ArrayEq(lhs, N, rhs); } @@ -1031,8 +1004,7 @@ inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) { template bool ArrayEq(const T* lhs, size_t size, const U* rhs) { for (size_t i = 0; i != size; i++) { - if (!internal::ArrayEq(lhs[i], rhs[i])) - return false; + if (!internal::ArrayEq(lhs[i], rhs[i])) return false; } return true; } @@ -1042,8 +1014,7 @@ bool ArrayEq(const T* lhs, size_t size, const U* rhs) { template Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) { for (Iter it = begin; it != end; ++it) { - if (internal::ArrayEq(*it, elem)) - return it; + if (internal::ArrayEq(*it, elem)) return it; } return end; } @@ -1057,11 +1028,13 @@ void CopyArray(const T* from, size_t size, U* to); // This generic version is used when k is 0. template -inline void CopyArray(const T& from, U* to) { *to = from; } +inline void CopyArray(const T& from, U* to) { + *to = from; +} // This overload is used when k >= 1. template -inline void CopyArray(const T(&from)[N], U(*to)[N]) { +inline void CopyArray(const T (&from)[N], U (*to)[N]) { internal::CopyArray(from, N, *to); } @@ -1114,8 +1087,7 @@ class NativeArray { } ~NativeArray() { - if (clone_ != &NativeArray::InitRef) - delete[] array_; + if (clone_ != &NativeArray::InitRef) delete[] array_; } // STL-style container methods. @@ -1123,8 +1095,7 @@ class NativeArray { const_iterator begin() const { return array_; } const_iterator end() const { return array_ + size_; } bool operator==(const NativeArray& rhs) const { - return size() == rhs.size() && - ArrayEq(begin(), size(), rhs.begin()); + return size() == rhs.size() && ArrayEq(begin(), size(), rhs.begin()); } private: @@ -1153,40 +1124,6 @@ class NativeArray { void (NativeArray::*clone_)(const Element*, size_t); }; -// Backport of std::index_sequence. -template -struct IndexSequence { - using type = IndexSequence; -}; - -// Double the IndexSequence, and one if plus_one is true. -template -struct DoubleSequence; -template -struct DoubleSequence, sizeofT> { - using type = IndexSequence; -}; -template -struct DoubleSequence, sizeofT> { - using type = IndexSequence; -}; - -// Backport of std::make_index_sequence. -// It uses O(ln(N)) instantiation depth. -template -struct MakeIndexSequenceImpl - : DoubleSequence::type, - N / 2>::type {}; - -template <> -struct MakeIndexSequenceImpl<0> : IndexSequence<> {}; - -template -using MakeIndexSequence = typename MakeIndexSequenceImpl::type; - -template -using IndexSequenceFor = typename MakeIndexSequence::type; - template struct Ignore { Ignore(...); // NOLINT @@ -1195,7 +1132,7 @@ struct Ignore { template struct ElemFromListImpl; template -struct ElemFromListImpl> { +struct ElemFromListImpl> { // We make Ignore a template to solve a problem with MSVC. // A non-template Ignore would work fine with `decltype(Ignore(I))...`, but // MSVC doesn't understand how to deal with that pack expansion. @@ -1206,9 +1143,8 @@ struct ElemFromListImpl> { template struct ElemFromList { - using type = - decltype(ElemFromListImpl::type>::Apply( - static_cast(nullptr)...)); + using type = decltype(ElemFromListImpl>::Apply( + static_cast(nullptr)...)); }; struct FlatTupleConstructTag {}; @@ -1233,9 +1169,9 @@ template struct FlatTupleBase; template -struct FlatTupleBase, IndexSequence> +struct FlatTupleBase, std::index_sequence> : FlatTupleElemBase, Idx>... { - using Indices = IndexSequence; + using Indices = std::index_sequence; FlatTupleBase() = default; template explicit FlatTupleBase(FlatTupleConstructTag, Args&&... args) @@ -1270,14 +1206,15 @@ struct FlatTupleBase, IndexSequence> // implementations. // FlatTuple and ElemFromList are not recursive and have a fixed depth // regardless of T... -// MakeIndexSequence, on the other hand, it is recursive but with an +// std::make_index_sequence, on the other hand, it is recursive but with an // instantiation depth of O(ln(N)). template class FlatTuple : private FlatTupleBase, - typename MakeIndexSequence::type> { - using Indices = typename FlatTupleBase< - FlatTuple, typename MakeIndexSequence::type>::Indices; + std::make_index_sequence> { + using Indices = + typename FlatTupleBase, + std::make_index_sequence>::Indices; public: FlatTuple() = default; @@ -1291,30 +1228,40 @@ class FlatTuple // Utility functions to be called with static_assert to induce deprecation // warnings. -GTEST_INTERNAL_DEPRECATED( +[[deprecated( "INSTANTIATE_TEST_CASE_P is deprecated, please use " - "INSTANTIATE_TEST_SUITE_P") -constexpr bool InstantiateTestCase_P_IsDeprecated() { return true; } + "INSTANTIATE_TEST_SUITE_P")]] +constexpr bool InstantiateTestCase_P_IsDeprecated() { + return true; +} -GTEST_INTERNAL_DEPRECATED( +[[deprecated( "TYPED_TEST_CASE_P is deprecated, please use " - "TYPED_TEST_SUITE_P") -constexpr bool TypedTestCase_P_IsDeprecated() { return true; } + "TYPED_TEST_SUITE_P")]] +constexpr bool TypedTestCase_P_IsDeprecated() { + return true; +} -GTEST_INTERNAL_DEPRECATED( +[[deprecated( "TYPED_TEST_CASE is deprecated, please use " - "TYPED_TEST_SUITE") -constexpr bool TypedTestCaseIsDeprecated() { return true; } + "TYPED_TEST_SUITE")]] +constexpr bool TypedTestCaseIsDeprecated() { + return true; +} -GTEST_INTERNAL_DEPRECATED( +[[deprecated( "REGISTER_TYPED_TEST_CASE_P is deprecated, please use " - "REGISTER_TYPED_TEST_SUITE_P") -constexpr bool RegisterTypedTestCase_P_IsDeprecated() { return true; } + "REGISTER_TYPED_TEST_SUITE_P")]] +constexpr bool RegisterTypedTestCase_P_IsDeprecated() { + return true; +} -GTEST_INTERNAL_DEPRECATED( +[[deprecated( "INSTANTIATE_TYPED_TEST_CASE_P is deprecated, please use " - "INSTANTIATE_TYPED_TEST_SUITE_P") -constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; } + "INSTANTIATE_TYPED_TEST_SUITE_P")]] +constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { + return true; +} } // namespace internal } // namespace testing @@ -1335,9 +1282,9 @@ struct tuple_size> #endif } // namespace std -#define GTEST_MESSAGE_AT_(file, line, message, result_type) \ - ::testing::internal::AssertHelper(result_type, file, line, message) \ - = ::testing::Message() +#define GTEST_MESSAGE_AT_(file, line, message, result_type) \ + ::testing::internal::AssertHelper(result_type, file, line, message) = \ + ::testing::Message() #define GTEST_MESSAGE_(message, result_type) \ GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type) @@ -1458,103 +1405,113 @@ class NeverThrown { #endif // GTEST_HAS_EXCEPTIONS -#define GTEST_TEST_NO_THROW_(statement, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::TrueWithString gtest_msg{}) { \ - try { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - } \ - GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \ - catch (...) { \ - gtest_msg.value = "it throws."; \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ - } \ - } else \ - GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ - fail(("Expected: " #statement " doesn't throw an exception.\n" \ - " Actual: " + gtest_msg.value).c_str()) +#define GTEST_TEST_NO_THROW_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::TrueWithString gtest_msg{}) { \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } \ + GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \ + catch (...) { \ + gtest_msg.value = "it throws."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__) \ + : fail(("Expected: " #statement " doesn't throw an exception.\n" \ + " Actual: " + \ + gtest_msg.value) \ + .c_str()) -#define GTEST_TEST_ANY_THROW_(statement, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::AlwaysTrue()) { \ - bool gtest_caught_any = false; \ - try { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - } \ - catch (...) { \ - gtest_caught_any = true; \ - } \ - if (!gtest_caught_any) { \ +#define GTEST_TEST_ANY_THROW_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + bool gtest_caught_any = false; \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } catch (...) { \ + gtest_caught_any = true; \ + } \ + if (!gtest_caught_any) { \ goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \ - } \ - } else \ - GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \ - fail("Expected: " #statement " throws an exception.\n" \ - " Actual: it doesn't.") - + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__) \ + : fail("Expected: " #statement \ + " throws an exception.\n" \ + " Actual: it doesn't.") // Implements Boolean test assertions such as EXPECT_TRUE. expression can be // either a boolean expression or an AssertionResult. text is a textual // representation of expression as it was passed into the EXPECT_TRUE. #define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (const ::testing::AssertionResult gtest_ar_ = \ - ::testing::AssertionResult(expression)) \ - ; \ - else \ - fail(::testing::internal::GetBoolAssertionFailureMessage(\ - gtest_ar_, text, #actual, #expected).c_str()) + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (const ::testing::AssertionResult gtest_ar_ = \ + ::testing::AssertionResult(expression)) \ + ; \ + else \ + fail(::testing::internal::GetBoolAssertionFailureMessage( \ + gtest_ar_, text, #actual, #expected) \ + .c_str()) -#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::AlwaysTrue()) { \ - ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ +#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + const ::testing::internal::HasNewFatalFailureHelper \ + gtest_fatal_failure_checker; \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \ - } \ - } else \ - GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \ - fail("Expected: " #statement " doesn't generate new fatal " \ - "failures in the current thread.\n" \ - " Actual: it does.") + } \ + } else /* NOLINT */ \ + GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__) \ + : fail("Expected: " #statement \ + " doesn't generate new fatal " \ + "failures in the current thread.\n" \ + " Actual: it does.") // Expands to the name of the class that implements the given test. #define GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ test_suite_name##_##test_name##_Test // Helper macro for defining tests. -#define GTEST_TEST_(test_suite_name, test_name, parent_class, parent_id) \ - static_assert(sizeof(GTEST_STRINGIFY_(test_suite_name)) > 1, \ - "test_suite_name must not be empty"); \ - static_assert(sizeof(GTEST_STRINGIFY_(test_name)) > 1, \ - "test_name must not be empty"); \ - class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public parent_class { \ - public: \ - GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() = default; \ - ~GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() override = default; \ - GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \ - test_name)); \ - GTEST_DISALLOW_MOVE_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \ - test_name)); \ - \ - private: \ - void TestBody() override; \ - static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \ - }; \ - \ - ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name, \ - test_name)::test_info_ = \ - ::testing::internal::MakeAndRegisterTestInfo( \ - #test_suite_name, #test_name, nullptr, nullptr, \ - ::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \ - ::testing::internal::SuiteApiResolver< \ - parent_class>::GetSetUpCaseOrSuite(__FILE__, __LINE__), \ - ::testing::internal::SuiteApiResolver< \ - parent_class>::GetTearDownCaseOrSuite(__FILE__, __LINE__), \ - new ::testing::internal::TestFactoryImpl); \ +#define GTEST_TEST_(test_suite_name, test_name, parent_class, parent_id) \ + static_assert(sizeof(GTEST_STRINGIFY_(test_suite_name)) > 1, \ + "test_suite_name must not be empty"); \ + static_assert(sizeof(GTEST_STRINGIFY_(test_name)) > 1, \ + "test_name must not be empty"); \ + class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ + : public parent_class { \ + public: \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() = default; \ + ~GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() override = default; \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ + (const GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &) = delete; \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=( \ + const GTEST_TEST_CLASS_NAME_(test_suite_name, \ + test_name) &) = delete; /* NOLINT */ \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ + (GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &&) noexcept = delete; \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=( \ + GTEST_TEST_CLASS_NAME_(test_suite_name, \ + test_name) &&) noexcept = delete; /* NOLINT */ \ + \ + private: \ + void TestBody() override; \ + [[maybe_unused]] static ::testing::TestInfo* const test_info_; \ + }; \ + \ + ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name, \ + test_name)::test_info_ = \ + ::testing::internal::MakeAndRegisterTestInfo( \ + #test_suite_name, #test_name, nullptr, nullptr, \ + ::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \ + ::testing::internal::SuiteApiResolver< \ + parent_class>::GetSetUpCaseOrSuite(__FILE__, __LINE__), \ + ::testing::internal::SuiteApiResolver< \ + parent_class>::GetTearDownCaseOrSuite(__FILE__, __LINE__), \ + new ::testing::internal::TestFactoryImpl); \ void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody() #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-param-util.h b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-param-util.h index c2ef6e3124..a092a86ada 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-param-util.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-param-util.h @@ -27,10 +27,11 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - // Type and function utilities for implementing parameterized tests. -// GOOGLETEST_CM0001 DO NOT DELETE +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ @@ -38,27 +39,31 @@ #include #include +#include #include +#include #include +#include #include +#include #include #include +#include #include #include -#include "gtest/internal/gtest-internal.h" -#include "gtest/internal/gtest-port.h" #include "gtest/gtest-printers.h" #include "gtest/gtest-test-part.h" +#include "gtest/internal/gtest-internal.h" +#include "gtest/internal/gtest-port.h" namespace testing { // Input to a parameterized test name generator, describing a test parameter. // Consists of the parameter value and the integer parameter index. template struct TestParamInfo { - TestParamInfo(const ParamType& a_param, size_t an_index) : - param(a_param), - index(an_index) {} + TestParamInfo(const ParamType& a_param, size_t an_index) + : param(a_param), index(an_index) {} ParamType param; size_t index; }; @@ -82,17 +87,19 @@ namespace internal { // TEST_P macro is used to define two tests with the same name // but in different namespaces. GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name, - CodeLocation code_location); + const CodeLocation& code_location); -template class ParamGeneratorInterface; -template class ParamGenerator; +template +class ParamGeneratorInterface; +template +class ParamGenerator; // Interface for iterating over elements provided by an implementation // of ParamGeneratorInterface. template class ParamIteratorInterface { public: - virtual ~ParamIteratorInterface() {} + virtual ~ParamIteratorInterface() = default; // A pointer to the base generator instance. // Used only for the purposes of iterator comparison // to make sure that two iterators belong to the same generator. @@ -129,8 +136,7 @@ class ParamIterator { // ParamIterator assumes ownership of the impl_ pointer. ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {} ParamIterator& operator=(const ParamIterator& other) { - if (this != &other) - impl_.reset(other.impl_->Clone()); + if (this != &other) impl_.reset(other.impl_->Clone()); return *this; } @@ -157,7 +163,7 @@ class ParamIterator { private: friend class ParamGenerator; explicit ParamIterator(ParamIteratorInterface* impl) : impl_(impl) {} - std::unique_ptr > impl_; + std::unique_ptr> impl_; }; // ParamGeneratorInterface is the binary interface to access generators @@ -167,7 +173,7 @@ class ParamGeneratorInterface { public: typedef T ParamType; - virtual ~ParamGeneratorInterface() {} + virtual ~ParamGeneratorInterface() = default; // Generator interface definition virtual ParamIteratorInterface* Begin() const = 0; @@ -179,7 +185,7 @@ class ParamGeneratorInterface { // This class implements copy initialization semantics and the contained // ParamGeneratorInterface instance is shared among all copies // of the original object. This is possible because that instance is immutable. -template +template class ParamGenerator { public: typedef ParamIterator iterator; @@ -196,7 +202,7 @@ class ParamGenerator { iterator end() const { return iterator(impl_->End()); } private: - std::shared_ptr > impl_; + std::shared_ptr> impl_; }; // Generates values from a range of two comparable values. Can be used to @@ -207,9 +213,11 @@ template class RangeGenerator : public ParamGeneratorInterface { public: RangeGenerator(T begin, T end, IncrementT step) - : begin_(begin), end_(end), - step_(step), end_index_(CalculateEndIndex(begin, end, step)) {} - ~RangeGenerator() override {} + : begin_(begin), + end_(end), + step_(step), + end_index_(CalculateEndIndex(begin, end, step)) {} + ~RangeGenerator() override = default; ParamIteratorInterface* Begin() const override { return new Iterator(this, begin_, 0, step_); @@ -224,7 +232,7 @@ class RangeGenerator : public ParamGeneratorInterface { Iterator(const ParamGeneratorInterface* base, T value, int index, IncrementT step) : base_(base), value_(value), index_(index), step_(step) {} - ~Iterator() override {} + ~Iterator() override = default; const ParamGeneratorInterface* BaseGenerator() const override { return base_; @@ -251,7 +259,9 @@ class RangeGenerator : public ParamGeneratorInterface { private: Iterator(const Iterator& other) : ParamIteratorInterface(), - base_(other.base_), value_(other.value_), index_(other.index_), + base_(other.base_), + value_(other.value_), + index_(other.index_), step_(other.step_) {} // No implementation - assignment is unsupported. @@ -263,12 +273,10 @@ class RangeGenerator : public ParamGeneratorInterface { const IncrementT step_; }; // class RangeGenerator::Iterator - static int CalculateEndIndex(const T& begin, - const T& end, + static int CalculateEndIndex(const T& begin, const T& end, const IncrementT& step) { int end_index = 0; - for (T i = begin; i < end; i = static_cast(i + step)) - end_index++; + for (T i = begin; i < end; i = static_cast(i + step)) end_index++; return end_index; } @@ -283,7 +291,6 @@ class RangeGenerator : public ParamGeneratorInterface { const int end_index_; }; // class RangeGenerator - // Generates values from a pair of STL-style iterators. Used in the // ValuesIn() function. The elements are copied from the source range // since the source can be located on the stack, and the generator @@ -294,7 +301,7 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface { template ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end) : container_(begin, end) {} - ~ValuesInIteratorRangeGenerator() override {} + ~ValuesInIteratorRangeGenerator() override = default; ParamIteratorInterface* Begin() const override { return new Iterator(this, container_.begin()); @@ -311,7 +318,7 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface { Iterator(const ParamGeneratorInterface* base, typename ContainerType::const_iterator iterator) : base_(base), iterator_(iterator) {} - ~Iterator() override {} + ~Iterator() override = default; const ParamGeneratorInterface* BaseGenerator() const override { return base_; @@ -341,13 +348,13 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface { << "The program attempted to compare iterators " << "from different generators." << std::endl; return iterator_ == - CheckedDowncastToActualType(&other)->iterator_; + CheckedDowncastToActualType(&other)->iterator_; } private: Iterator(const Iterator& other) - // The explicit constructor call suppresses a false warning - // emitted by gcc when supplied with the -Wextra option. + // The explicit constructor call suppresses a false warning + // emitted by gcc when supplied with the -Wextra option. : ParamIteratorInterface(), base_(other.base_), iterator_(other.iterator_) {} @@ -374,9 +381,7 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface { // integer test parameter index. template std::string DefaultParamName(const TestParamInfo& info) { - Message name_stream; - name_stream << info.index; - return name_stream.GetString(); + return std::to_string(info.index); } template @@ -394,8 +399,8 @@ template class ParameterizedTestFactory : public TestFactoryBase { public: typedef typename TestClass::ParamType ParamType; - explicit ParameterizedTestFactory(ParamType parameter) : - parameter_(parameter) {} + explicit ParameterizedTestFactory(ParamType parameter) + : parameter_(parameter) {} Test* CreateTest() override { TestClass::SetParam(¶meter_); return new TestClass(); @@ -404,7 +409,8 @@ class ParameterizedTestFactory : public TestFactoryBase { private: const ParamType parameter_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory); + ParameterizedTestFactory(const ParameterizedTestFactory&) = delete; + ParameterizedTestFactory& operator=(const ParameterizedTestFactory&) = delete; }; // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. @@ -414,7 +420,7 @@ class ParameterizedTestFactory : public TestFactoryBase { template class TestMetaFactoryBase { public: - virtual ~TestMetaFactoryBase() {} + virtual ~TestMetaFactoryBase() = default; virtual TestFactoryBase* CreateTestFactory(ParamType parameter) = 0; }; @@ -433,14 +439,15 @@ class TestMetaFactory public: using ParamType = typename TestSuite::ParamType; - TestMetaFactory() {} + TestMetaFactory() = default; TestFactoryBase* CreateTestFactory(ParamType parameter) override { return new ParameterizedTestFactory(parameter); } private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(TestMetaFactory); + TestMetaFactory(const TestMetaFactory&) = delete; + TestMetaFactory& operator=(const TestMetaFactory&) = delete; }; // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. @@ -455,7 +462,7 @@ class TestMetaFactory // and calls RegisterTests() on each of them when asked. class ParameterizedTestSuiteInfoBase { public: - virtual ~ParameterizedTestSuiteInfoBase() {} + virtual ~ParameterizedTestSuiteInfoBase() = default; // Base part of test suite name for display purposes. virtual const std::string& GetTestSuiteName() const = 0; @@ -471,7 +478,10 @@ class ParameterizedTestSuiteInfoBase { ParameterizedTestSuiteInfoBase() {} private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase); + ParameterizedTestSuiteInfoBase(const ParameterizedTestSuiteInfoBase&) = + delete; + ParameterizedTestSuiteInfoBase& operator=( + const ParameterizedTestSuiteInfoBase&) = delete; }; // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. @@ -503,9 +513,10 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { typedef ParamGenerator(GeneratorCreationFunc)(); using ParamNameGeneratorFunc = std::string(const TestParamInfo&); - explicit ParameterizedTestSuiteInfo(const char* name, + explicit ParameterizedTestSuiteInfo(std::string name, CodeLocation code_location) - : test_suite_name_(name), code_location_(code_location) {} + : test_suite_name_(std::move(name)), + code_location_(std::move(code_location)) {} // Test suite base name for display purposes. const std::string& GetTestSuiteName() const override { @@ -519,20 +530,20 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { // prefix). test_base_name is the name of an individual test without // parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is // test suite base name and DoBar is test base name. - void AddTestPattern(const char* test_suite_name, const char* test_base_name, + void AddTestPattern(const char*, const char* test_base_name, TestMetaFactoryBase* meta_factory, CodeLocation code_location) { - tests_.push_back(std::shared_ptr(new TestInfo( - test_suite_name, test_base_name, meta_factory, code_location))); + tests_.emplace_back( + new TestInfo(test_base_name, meta_factory, std::move(code_location))); } // INSTANTIATE_TEST_SUITE_P macro uses AddGenerator() to record information // about a generator. - int AddTestSuiteInstantiation(const std::string& instantiation_name, + int AddTestSuiteInstantiation(std::string instantiation_name, GeneratorCreationFunc* func, ParamNameGeneratorFunc* name_func, const char* file, int line) { - instantiations_.push_back( - InstantiationInfo(instantiation_name, func, name_func, file, line)); + instantiations_.emplace_back(std::move(instantiation_name), func, name_func, + file, line); return 0; // Return value used only to run this method in namespace scope. } // UnitTest class invokes this method to register tests in this test suite @@ -543,119 +554,113 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { void RegisterTests() override { bool generated_instantiations = false; - for (typename TestInfoContainer::iterator test_it = tests_.begin(); - test_it != tests_.end(); ++test_it) { - std::shared_ptr test_info = *test_it; - for (typename InstantiationContainer::iterator gen_it = - instantiations_.begin(); gen_it != instantiations_.end(); - ++gen_it) { - const std::string& instantiation_name = gen_it->name; - ParamGenerator generator((*gen_it->generator)()); - ParamNameGeneratorFunc* name_func = gen_it->name_func; - const char* file = gen_it->file; - int line = gen_it->line; + std::string test_suite_name; + std::string test_name; + for (const std::shared_ptr& test_info : tests_) { + for (const InstantiationInfo& instantiation : instantiations_) { + const std::string& instantiation_name = instantiation.name; + ParamGenerator generator((*instantiation.generator)()); + ParamNameGeneratorFunc* name_func = instantiation.name_func; + const char* file = instantiation.file; + int line = instantiation.line; - std::string test_suite_name; - if ( !instantiation_name.empty() ) + if (!instantiation_name.empty()) test_suite_name = instantiation_name + "/"; - test_suite_name += test_info->test_suite_base_name; + else + test_suite_name.clear(); + test_suite_name += test_suite_name_; size_t i = 0; std::set test_param_names; - for (typename ParamGenerator::iterator param_it = - generator.begin(); - param_it != generator.end(); ++param_it, ++i) { + for (const auto& param : generator) { generated_instantiations = true; - Message test_name_stream; + test_name.clear(); - std::string param_name = name_func( - TestParamInfo(*param_it, i)); + std::string param_name = + name_func(TestParamInfo(param, i)); GTEST_CHECK_(IsValidParamName(param_name)) << "Parameterized test name '" << param_name - << "' is invalid, in " << file - << " line " << line << std::endl; + << "' is invalid (contains spaces, dashes, or any " + "non-alphanumeric characters other than underscores), in " + << file << " line " << line << "" << std::endl; GTEST_CHECK_(test_param_names.count(param_name) == 0) - << "Duplicate parameterized test name '" << param_name - << "', in " << file << " line " << line << std::endl; - - test_param_names.insert(param_name); + << "Duplicate parameterized test name '" << param_name << "', in " + << file << " line " << line << std::endl; if (!test_info->test_base_name.empty()) { - test_name_stream << test_info->test_base_name << "/"; + test_name.append(test_info->test_base_name).append("/"); } - test_name_stream << param_name; + test_name += param_name; + + test_param_names.insert(std::move(param_name)); + MakeAndRegisterTestInfo( - test_suite_name.c_str(), test_name_stream.GetString().c_str(), + test_suite_name, test_name.c_str(), nullptr, // No type parameter. - PrintToString(*param_it).c_str(), test_info->code_location, + PrintToString(param).c_str(), test_info->code_location, GetTestSuiteTypeId(), SuiteApiResolver::GetSetUpCaseOrSuite(file, line), SuiteApiResolver::GetTearDownCaseOrSuite(file, line), - test_info->test_meta_factory->CreateTestFactory(*param_it)); - } // for param_it - } // for gen_it - } // for test_it + test_info->test_meta_factory->CreateTestFactory(param)); + ++i; + } // for param + } // for instantiation + } // for test_info if (!generated_instantiations) { // There are no generaotrs, or they all generate nothing ... InsertSyntheticTestCase(GetTestSuiteName(), code_location_, !tests_.empty()); } - } // RegisterTests + } // RegisterTests private: // LocalTestInfo structure keeps information about a single test registered // with TEST_P macro. struct TestInfo { - TestInfo(const char* a_test_suite_base_name, const char* a_test_base_name, + TestInfo(const char* a_test_base_name, TestMetaFactoryBase* a_test_meta_factory, CodeLocation a_code_location) - : test_suite_base_name(a_test_suite_base_name), - test_base_name(a_test_base_name), + : test_base_name(a_test_base_name), test_meta_factory(a_test_meta_factory), - code_location(a_code_location) {} + code_location(std::move(a_code_location)) {} - const std::string test_suite_base_name; const std::string test_base_name; - const std::unique_ptr > test_meta_factory; + const std::unique_ptr> test_meta_factory; const CodeLocation code_location; }; - using TestInfoContainer = ::std::vector >; + using TestInfoContainer = ::std::vector>; // Records data received from INSTANTIATE_TEST_SUITE_P macros: // struct InstantiationInfo { - InstantiationInfo(const std::string &name_in, - GeneratorCreationFunc* generator_in, - ParamNameGeneratorFunc* name_func_in, - const char* file_in, - int line_in) - : name(name_in), - generator(generator_in), - name_func(name_func_in), - file(file_in), - line(line_in) {} + InstantiationInfo(std::string name_in, GeneratorCreationFunc* generator_in, + ParamNameGeneratorFunc* name_func_in, const char* file_in, + int line_in) + : name(std::move(name_in)), + generator(generator_in), + name_func(name_func_in), + file(file_in), + line(line_in) {} - std::string name; - GeneratorCreationFunc* generator; - ParamNameGeneratorFunc* name_func; - const char* file; - int line; + std::string name; + GeneratorCreationFunc* generator; + ParamNameGeneratorFunc* name_func; + const char* file; + int line; }; typedef ::std::vector InstantiationContainer; static bool IsValidParamName(const std::string& name) { // Check for empty string - if (name.empty()) - return false; + if (name.empty()) return false; // Check for invalid characters for (std::string::size_type index = 0; index < name.size(); ++index) { - if (!IsAlNum(name[index]) && name[index] != '_') - return false; + if (!IsAlNum(name[index]) && name[index] != '_') return false; } return true; @@ -666,7 +671,9 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { TestInfoContainer tests_; InstantiationContainer instantiations_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfo); + ParameterizedTestSuiteInfo(const ParameterizedTestSuiteInfo&) = delete; + ParameterizedTestSuiteInfo& operator=(const ParameterizedTestSuiteInfo&) = + delete; }; // class ParameterizedTestSuiteInfo // Legacy API is deprecated but still available @@ -683,7 +690,7 @@ using ParameterizedTestCaseInfo = ParameterizedTestSuiteInfo; // ParameterizedTestSuiteInfo descriptors. class ParameterizedTestSuiteRegistry { public: - ParameterizedTestSuiteRegistry() {} + ParameterizedTestSuiteRegistry() = default; ~ParameterizedTestSuiteRegistry() { for (auto& test_suite_info : test_suite_infos_) { delete test_suite_info; @@ -694,29 +701,32 @@ class ParameterizedTestSuiteRegistry { // tests and instantiations of a particular test suite. template ParameterizedTestSuiteInfo* GetTestSuitePatternHolder( - const char* test_suite_name, CodeLocation code_location) { + std::string test_suite_name, CodeLocation code_location) { ParameterizedTestSuiteInfo* typed_test_info = nullptr; - for (auto& test_suite_info : test_suite_infos_) { - if (test_suite_info->GetTestSuiteName() == test_suite_name) { - if (test_suite_info->GetTestSuiteTypeId() != GetTypeId()) { - // Complain about incorrect usage of Google Test facilities - // and terminate the program since we cannot guaranty correct - // test suite setup and tear-down in this case. - ReportInvalidTestSuiteType(test_suite_name, code_location); - posix::Abort(); - } else { - // At this point we are sure that the object we found is of the same - // type we are looking for, so we downcast it to that type - // without further checks. - typed_test_info = CheckedDowncastToActualType< - ParameterizedTestSuiteInfo >(test_suite_info); - } - break; + + auto item_it = suite_name_to_info_index_.find(test_suite_name); + if (item_it != suite_name_to_info_index_.end()) { + auto* test_suite_info = test_suite_infos_[item_it->second]; + if (test_suite_info->GetTestSuiteTypeId() != GetTypeId()) { + // Complain about incorrect usage of Google Test facilities + // and terminate the program since we cannot guaranty correct + // test suite setup and tear-down in this case. + ReportInvalidTestSuiteType(test_suite_name.c_str(), code_location); + posix::Abort(); + } else { + // At this point we are sure that the object we found is of the same + // type we are looking for, so we downcast it to that type + // without further checks. + typed_test_info = + CheckedDowncastToActualType>( + test_suite_info); } } if (typed_test_info == nullptr) { typed_test_info = new ParameterizedTestSuiteInfo( - test_suite_name, code_location); + test_suite_name, std::move(code_location)); + suite_name_to_info_index_.emplace(std::move(test_suite_name), + test_suite_infos_.size()); test_suite_infos_.push_back(typed_test_info); } return typed_test_info; @@ -730,8 +740,9 @@ class ParameterizedTestSuiteRegistry { #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ template ParameterizedTestCaseInfo* GetTestCasePatternHolder( - const char* test_case_name, CodeLocation code_location) { - return GetTestSuitePatternHolder(test_case_name, code_location); + std::string test_case_name, CodeLocation code_location) { + return GetTestSuitePatternHolder(std::move(test_case_name), + std::move(code_location)); } #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ @@ -740,8 +751,12 @@ class ParameterizedTestSuiteRegistry { using TestSuiteInfoContainer = ::std::vector; TestSuiteInfoContainer test_suite_infos_; + ::std::unordered_map suite_name_to_info_index_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteRegistry); + ParameterizedTestSuiteRegistry(const ParameterizedTestSuiteRegistry&) = + delete; + ParameterizedTestSuiteRegistry& operator=( + const ParameterizedTestSuiteRegistry&) = delete; }; // Keep track of what type-parameterized test suite are defined and @@ -763,7 +778,7 @@ class TypeParameterizedTestSuiteRegistry { private: struct TypeParameterizedTestSuiteInfo { explicit TypeParameterizedTestSuiteInfo(CodeLocation c) - : code_location(c), instantiated(false) {} + : code_location(std::move(c)), instantiated(false) {} CodeLocation code_location; bool instantiated; @@ -783,10 +798,7 @@ internal::ParamGenerator ValuesIn( namespace internal { // Used in the Values() function to provide polymorphic capabilities. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4100) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100) template class ValueArray { @@ -795,21 +807,19 @@ class ValueArray { template operator ParamGenerator() const { // NOLINT - return ValuesIn(MakeVector(MakeIndexSequence())); + return ValuesIn(MakeVector(std::make_index_sequence())); } private: template - std::vector MakeVector(IndexSequence) const { + std::vector MakeVector(std::index_sequence) const { return std::vector{static_cast(v_.template Get())...}; } FlatTuple v_; }; -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 template class CartesianProductGenerator @@ -819,7 +829,7 @@ class CartesianProductGenerator CartesianProductGenerator(const std::tuple...>& g) : generators_(g) {} - ~CartesianProductGenerator() override {} + ~CartesianProductGenerator() override = default; ParamIteratorInterface* Begin() const override { return new Iterator(this, generators_, false); @@ -832,18 +842,19 @@ class CartesianProductGenerator template class IteratorImpl; template - class IteratorImpl> + class IteratorImpl> : public ParamIteratorInterface { public: IteratorImpl(const ParamGeneratorInterface* base, - const std::tuple...>& generators, bool is_end) + const std::tuple...>& generators, + bool is_end) : base_(base), begin_(std::get(generators).begin()...), end_(std::get(generators).end()...), current_(is_end ? end_ : begin_) { ComputeCurrentValue(); } - ~IteratorImpl() override {} + ~IteratorImpl() override = default; const ParamGeneratorInterface* BaseGenerator() const override { return base_; @@ -922,7 +933,7 @@ class CartesianProductGenerator std::shared_ptr current_value_; }; - using Iterator = IteratorImpl::type>; + using Iterator = IteratorImpl>; std::tuple...> generators_; }; @@ -941,6 +952,112 @@ class CartesianProductHolder { std::tuple generators_; }; +template +class ParamGeneratorConverter : public ParamGeneratorInterface { + public: + ParamGeneratorConverter(ParamGenerator gen, Func converter) // NOLINT + : generator_(std::move(gen)), converter_(std::move(converter)) {} + + ParamIteratorInterface* Begin() const override { + return new Iterator(this, generator_.begin(), generator_.end()); + } + ParamIteratorInterface* End() const override { + return new Iterator(this, generator_.end(), generator_.end()); + } + + // Returns the std::function wrapping the user-supplied converter callable. It + // is used by the iterator (see class Iterator below) to convert the object + // (of type FROM) returned by the ParamGenerator to an object of a type that + // can be static_cast to type TO. + const Func& TypeConverter() const { return converter_; } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorConverter* base, ParamIterator it, + ParamIterator end) + : base_(base), it_(it), end_(end) { + if (it_ != end_) + value_ = + std::make_shared(static_cast(base->TypeConverter()(*it_))); + } + ~Iterator() override = default; + + const ParamGeneratorInterface* BaseGenerator() const override { + return base_; + } + void Advance() override { + ++it_; + if (it_ != end_) + value_ = + std::make_shared(static_cast(base_->TypeConverter()(*it_))); + } + ParamIteratorInterface* Clone() const override { + return new Iterator(*this); + } + const To* Current() const override { return value_.get(); } + bool Equals(const ParamIteratorInterface& other) const override { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const ParamIterator other_it = + CheckedDowncastToActualType(&other)->it_; + return it_ == other_it; + } + + private: + Iterator(const Iterator& other) = default; + + const ParamGeneratorConverter* const base_; + ParamIterator it_; + ParamIterator end_; + std::shared_ptr value_; + }; // class ParamGeneratorConverter::Iterator + + ParamGenerator generator_; + Func converter_; +}; // class ParamGeneratorConverter + +template > +class ParamConverterGenerator { + public: + ParamConverterGenerator(ParamGenerator g) // NOLINT + : generator_(std::move(g)), converter_(Identity) {} + + ParamConverterGenerator(ParamGenerator g, StdFunction converter) + : generator_(std::move(g)), converter_(std::move(converter)) {} + + template + operator ParamGenerator() const { // NOLINT + return ParamGenerator( + new ParamGeneratorConverter(generator_, + converter_)); + } + + private: + static const GeneratedT& Identity(const GeneratedT& v) { return v; } + + ParamGenerator generator_; + StdFunction converter_; +}; + +// Template to determine the param type of a single-param std::function. +template +struct FuncSingleParamType; +template +struct FuncSingleParamType> { + using type = std::remove_cv_t>; +}; + +template +struct IsSingleArgStdFunction : public std::false_type {}; +template +struct IsSingleArgStdFunction> : public std::true_type {}; + } // namespace internal } // namespace testing diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-port-arch.h b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-port-arch.h index dd845915e3..7ec968f312 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-port-arch.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-port-arch.h @@ -26,7 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// + // The Google C++ Testing and Mocking Framework (Google Test) // // This header file defines the GTEST_OS_* macro. @@ -37,70 +37,74 @@ // Determines the platform on which Google Test is compiled. #ifdef __CYGWIN__ -# define GTEST_OS_CYGWIN 1 -# elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) -# define GTEST_OS_WINDOWS_MINGW 1 -# define GTEST_OS_WINDOWS 1 +#define GTEST_OS_CYGWIN 1 +#elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) +#define GTEST_OS_WINDOWS_MINGW 1 +#define GTEST_OS_WINDOWS 1 #elif defined _WIN32 -# define GTEST_OS_WINDOWS 1 -# ifdef _WIN32_WCE -# define GTEST_OS_WINDOWS_MOBILE 1 -# elif defined(WINAPI_FAMILY) -# include -# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -# define GTEST_OS_WINDOWS_DESKTOP 1 -# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) -# define GTEST_OS_WINDOWS_PHONE 1 -# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) -# define GTEST_OS_WINDOWS_RT 1 -# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE) -# define GTEST_OS_WINDOWS_PHONE 1 -# define GTEST_OS_WINDOWS_TV_TITLE 1 -# else - // WINAPI_FAMILY defined but no known partition matched. - // Default to desktop. -# define GTEST_OS_WINDOWS_DESKTOP 1 -# endif -# else -# define GTEST_OS_WINDOWS_DESKTOP 1 -# endif // _WIN32_WCE +#define GTEST_OS_WINDOWS 1 +#ifdef _WIN32_WCE +#define GTEST_OS_WINDOWS_MOBILE 1 +#elif defined(WINAPI_FAMILY) +#include +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +#define GTEST_OS_WINDOWS_DESKTOP 1 +#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) +#define GTEST_OS_WINDOWS_PHONE 1 +#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) +#define GTEST_OS_WINDOWS_RT 1 +#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE) +#define GTEST_OS_WINDOWS_PHONE 1 +#define GTEST_OS_WINDOWS_TV_TITLE 1 +#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_GAMES) +#define GTEST_OS_WINDOWS_GAMES 1 +#else +// WINAPI_FAMILY defined but no known partition matched. +// Default to desktop. +#define GTEST_OS_WINDOWS_DESKTOP 1 +#endif +#else +#define GTEST_OS_WINDOWS_DESKTOP 1 +#endif // _WIN32_WCE #elif defined __OS2__ -# define GTEST_OS_OS2 1 +#define GTEST_OS_OS2 1 #elif defined __APPLE__ -# define GTEST_OS_MAC 1 -# include -# if TARGET_OS_IPHONE -# define GTEST_OS_IOS 1 -# endif +#define GTEST_OS_MAC 1 +#include +#if TARGET_OS_IPHONE +#define GTEST_OS_IOS 1 +#endif #elif defined __DragonFly__ -# define GTEST_OS_DRAGONFLY 1 +#define GTEST_OS_DRAGONFLY 1 #elif defined __FreeBSD__ -# define GTEST_OS_FREEBSD 1 +#define GTEST_OS_FREEBSD 1 #elif defined __Fuchsia__ -# define GTEST_OS_FUCHSIA 1 +#define GTEST_OS_FUCHSIA 1 +#elif defined(__GNU__) +#define GTEST_OS_GNU_HURD 1 #elif defined(__GLIBC__) && defined(__FreeBSD_kernel__) -# define GTEST_OS_GNU_KFREEBSD 1 +#define GTEST_OS_GNU_KFREEBSD 1 #elif defined __linux__ -# define GTEST_OS_LINUX 1 -# if defined __ANDROID__ -# define GTEST_OS_LINUX_ANDROID 1 -# endif +#define GTEST_OS_LINUX 1 +#if defined __ANDROID__ +#define GTEST_OS_LINUX_ANDROID 1 +#endif #elif defined __MVS__ -# define GTEST_OS_ZOS 1 +#define GTEST_OS_ZOS 1 #elif defined(__sun) && defined(__SVR4) -# define GTEST_OS_SOLARIS 1 +#define GTEST_OS_SOLARIS 1 #elif defined(_AIX) -# define GTEST_OS_AIX 1 +#define GTEST_OS_AIX 1 #elif defined(__hpux) -# define GTEST_OS_HPUX 1 +#define GTEST_OS_HPUX 1 #elif defined __native_client__ -# define GTEST_OS_NACL 1 +#define GTEST_OS_NACL 1 #elif defined __NetBSD__ -# define GTEST_OS_NETBSD 1 +#define GTEST_OS_NETBSD 1 #elif defined __OpenBSD__ -# define GTEST_OS_OPENBSD 1 +#define GTEST_OS_OPENBSD 1 #elif defined __QNX__ -# define GTEST_OS_QNX 1 +#define GTEST_OS_QNX 1 #elif defined(__HAIKU__) #define GTEST_OS_HAIKU 1 #elif defined ESP8266 @@ -109,6 +113,12 @@ #define GTEST_OS_ESP32 1 #elif defined(__XTENSA__) #define GTEST_OS_XTENSA 1 +#elif defined(__hexagon__) +#define GTEST_OS_QURT 1 +#elif defined(CPU_QN9090) || defined(CPU_QN9090HN) +#define GTEST_OS_NXP_QN9090 1 +#elif defined(NRF52) +#define GTEST_OS_NRF52 1 #endif // __CYGWIN__ #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-port.h b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-port.h index 0953a781c0..4a5cde3341 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-port.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-port.h @@ -26,7 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// + // Low-level types and utilities for porting Google Test to various // platforms. All macros ending with _ and symbols defined in an // internal namespace are subject to change without notice. Code @@ -38,7 +38,9 @@ // files are expected to #include this. Therefore, it cannot #include // any other Google Test header. -// GOOGLETEST_CM0001 DO NOT DELETE +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ @@ -81,6 +83,8 @@ // GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that // std::wstring does/doesn't work (Google Test can // be used where std::wstring is unavailable). +// GTEST_HAS_FILE_SYSTEM - Define it to 1/0 to indicate whether or not a +// file system is/isn't available. // GTEST_HAS_SEH - Define it to 1/0 to indicate whether the // compiler supports Microsoft's "Structured // Exception Handling". @@ -116,6 +120,7 @@ // GTEST_OS_DRAGONFLY - DragonFlyBSD // GTEST_OS_FREEBSD - FreeBSD // GTEST_OS_FUCHSIA - Fuchsia +// GTEST_OS_GNU_HURD - GNU/Hurd // GTEST_OS_GNU_KFREEBSD - GNU/kFreeBSD // GTEST_OS_HAIKU - Haiku // GTEST_OS_HPUX - HP-UX @@ -156,10 +161,10 @@ // NOT define them. // // These macros are public so that portable tests can be written. -// Such tests typically surround code using a feature with an #if +// Such tests typically surround code using a feature with an #ifdef // which controls that code. For example: // -// #if GTEST_HAS_DEATH_TEST +// #ifdef GTEST_HAS_DEATH_TEST // EXPECT_DEATH(DoSomethingDeadly()); // #endif // @@ -167,12 +172,13 @@ // GTEST_HAS_TYPED_TEST - typed tests // GTEST_HAS_TYPED_TEST_P - type-parameterized tests // GTEST_IS_THREADSAFE - Google Test is thread-safe. -// GOOGLETEST_CM0007 DO NOT DELETE +// GTEST_USES_RE2 - the RE2 regular expression library is used // GTEST_USES_POSIX_RE - enhanced POSIX regex is used. Do not confuse with // GTEST_HAS_POSIX_RE (see above) which users can // define themselves. // GTEST_USES_SIMPLE_RE - our own simple regex is used; // the above RE\b(s) are mutually exclusive. +// GTEST_HAS_ABSL - Google Test is compiled with Abseil. // Misc public macros // ------------------ @@ -188,40 +194,45 @@ // // Macros for basic C++ coding: // GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning. -// GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a -// variable don't have to be used. -// GTEST_DISALLOW_ASSIGN_ - disables copy operator=. -// GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=. -// GTEST_DISALLOW_MOVE_ASSIGN_ - disables move operator=. -// GTEST_DISALLOW_MOVE_AND_ASSIGN_ - disables move ctor and operator=. -// GTEST_MUST_USE_RESULT_ - declares that a function's result must be used. // GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is // suppressed (constant conditional). // GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127 // is suppressed. // GTEST_INTERNAL_HAS_ANY - for enabling UniversalPrinter or // UniversalPrinter specializations. +// Always defined to 0 or 1. // GTEST_INTERNAL_HAS_OPTIONAL - for enabling UniversalPrinter // or // UniversalPrinter -// specializations. +// specializations. Always defined to 0 or 1. +// GTEST_INTERNAL_HAS_STD_SPAN - for enabling UniversalPrinter +// specializations. Always defined to 0 or 1 // GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher or // Matcher -// specializations. +// specializations. Always defined to 0 or 1. // GTEST_INTERNAL_HAS_VARIANT - for enabling UniversalPrinter or // UniversalPrinter -// specializations. +// specializations. Always defined to 0 or 1. +// GTEST_USE_OWN_FLAGFILE_FLAG_ - Always defined to 0 or 1. +// GTEST_HAS_CXXABI_H_ - Always defined to 0 or 1. +// GTEST_CAN_STREAM_RESULTS_ - Always defined to 0 or 1. +// GTEST_HAS_ALT_PATH_SEP_ - Always defined to 0 or 1. +// GTEST_WIDE_STRING_USES_UTF16_ - Always defined to 0 or 1. +// GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Always defined to 0 or 1. +// GTEST_HAS_NOTIFICATION_- Always defined to 0 or 1. // // Synchronization: // Mutex, MutexLock, ThreadLocal, GetThreadCount() // - synchronization primitives. // // Regular expressions: -// RE - a simple regular expression class using the POSIX -// Extended Regular Expression syntax on UNIX-like platforms -// GOOGLETEST_CM0008 DO NOT DELETE -// or a reduced regular exception syntax on other -// platforms, including Windows. +// RE - a simple regular expression class using +// 1) the RE2 syntax on all platforms when built with RE2 +// and Abseil as dependencies +// 2) the POSIX Extended Regular Expression syntax on +// UNIX-like platforms, +// 3) A reduced regular exception syntax on other platforms, +// including Windows. // Logging: // GTEST_LOG_() - logs messages at the specified severity level. // LogToStderr() - directs all log messages to stderr. @@ -241,8 +252,6 @@ // BiggestInt - the biggest signed integer type. // // Command-line utilities: -// GTEST_DECLARE_*() - declares a flag. -// GTEST_DEFINE_*() - defines a flag. // GetInjectableArgvs() - returns the command line as a vector of strings. // // Environment variable utilities: @@ -250,11 +259,39 @@ // BoolFromGTestEnv() - parses a bool environment variable. // Int32FromGTestEnv() - parses an int32_t environment variable. // StringFromGTestEnv() - parses a string environment variable. + +// The definition of GTEST_INTERNAL_CPLUSPLUS_LANG comes first because it can +// potentially be used as an #include guard. +#if defined(_MSVC_LANG) +#define GTEST_INTERNAL_CPLUSPLUS_LANG _MSVC_LANG +#elif defined(__cplusplus) +#define GTEST_INTERNAL_CPLUSPLUS_LANG __cplusplus +#endif + +#if !defined(GTEST_INTERNAL_CPLUSPLUS_LANG) || \ + GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L +#error C++ versions less than C++17 are not supported. +#endif + +// MSVC >= 19.11 (VS 2017 Update 3) supports __has_include. +#ifdef __has_include +#define GTEST_INTERNAL_HAS_INCLUDE __has_include +#else +#define GTEST_INTERNAL_HAS_INCLUDE(...) 0 +#endif + +// Detect C++ feature test macros as gracefully as possible. +// MSVC >= 19.15, Clang >= 3.4.1, and GCC >= 4.1.2 support feature test macros. // -// Deprecation warnings: -// GTEST_INTERNAL_DEPRECATED(message) - attribute marking a function as -// deprecated; calling a marked function -// should generate a compiler warning +// GCC15 warns that is deprecated in C++17 and suggests using +// instead, even though is not available in C++17 mode prior +// to GCC9. +#if GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L || \ + GTEST_INTERNAL_HAS_INCLUDE() +#include // C++20 or support. +#else +#include // Pre-C++20 +#endif #include // for isspace, etc #include // for ptrdiff_t @@ -263,48 +300,65 @@ #include #include +// #include // Guarded by GTEST_IS_THREADSAFE below #include +#include #include +#include +#include +#include +#include +// #include // Guarded by GTEST_IS_THREADSAFE below +#include #include +#include #ifndef _WIN32_WCE -# include -# include +#include +#include #endif // !_WIN32_WCE #if defined __APPLE__ -# include -# include +#include +#include #endif -#include // NOLINT -#include -#include -#include // NOLINT -#include -#include // NOLINT - #include "gtest/internal/custom/gtest-port.h" #include "gtest/internal/gtest-port-arch.h" +#ifndef GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ +#define GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ 0 +#endif + +#ifndef GTEST_HAS_NOTIFICATION_ +#define GTEST_HAS_NOTIFICATION_ 0 +#endif + +#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS) +#define GTEST_INTERNAL_HAS_ABSL_FLAGS // Used only in this file. +#include "absl/flags/declare.h" +#include "absl/flags/flag.h" +#include "absl/flags/reflection.h" +#endif + #if !defined(GTEST_DEV_EMAIL_) -# define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com" -# define GTEST_FLAG_PREFIX_ "gtest_" -# define GTEST_FLAG_PREFIX_DASH_ "gtest-" -# define GTEST_FLAG_PREFIX_UPPER_ "GTEST_" -# define GTEST_NAME_ "Google Test" -# define GTEST_PROJECT_URL_ "https://github.com/google/googletest/" +#define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com" +#define GTEST_FLAG_PREFIX_ "gtest_" +#define GTEST_FLAG_PREFIX_DASH_ "gtest-" +#define GTEST_FLAG_PREFIX_UPPER_ "GTEST_" +#define GTEST_NAME_ "Google Test" +#define GTEST_PROJECT_URL_ "https://github.com/google/googletest/" #endif // !defined(GTEST_DEV_EMAIL_) #if !defined(GTEST_INIT_GOOGLE_TEST_NAME_) -# define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest" +#define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest" #endif // !defined(GTEST_INIT_GOOGLE_TEST_NAME_) // Determines the version of gcc that is used to compile this. #ifdef __GNUC__ // 40302 means version 4.3.2. -# define GTEST_GCC_VER_ \ - (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) +#define GTEST_GCC_VER_ \ + (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #endif // __GNUC__ // Macros for disabling Microsoft Visual C++ warnings. @@ -313,43 +367,39 @@ // /* code that triggers warnings C4800 and C4385 */ // GTEST_DISABLE_MSC_WARNINGS_POP_() #if defined(_MSC_VER) -# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \ - __pragma(warning(push)) \ - __pragma(warning(disable: warnings)) -# define GTEST_DISABLE_MSC_WARNINGS_POP_() \ - __pragma(warning(pop)) +#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \ + __pragma(warning(push)) __pragma(warning(disable : warnings)) +#define GTEST_DISABLE_MSC_WARNINGS_POP_() __pragma(warning(pop)) #else // Not all compilers are MSVC -# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) -# define GTEST_DISABLE_MSC_WARNINGS_POP_() +#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) +#define GTEST_DISABLE_MSC_WARNINGS_POP_() #endif // Clang on Windows does not understand MSVC's pragma warning. // We need clang-specific way to disable function deprecation warning. #ifdef __clang__ -# define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \ - _Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"") -#define GTEST_DISABLE_MSC_DEPRECATED_POP_() \ - _Pragma("clang diagnostic pop") +#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \ + _Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"") +#define GTEST_DISABLE_MSC_DEPRECATED_POP_() _Pragma("clang diagnostic pop") #else -# define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ - GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) -# define GTEST_DISABLE_MSC_DEPRECATED_POP_() \ - GTEST_DISABLE_MSC_WARNINGS_POP_() +#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) +#define GTEST_DISABLE_MSC_DEPRECATED_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_() #endif // Brings in definitions for functions used in the testing::internal::posix // namespace (read, write, close, chdir, isatty, stat). We do not currently // use them on Windows Mobile. -#if GTEST_OS_WINDOWS -# if !GTEST_OS_WINDOWS_MOBILE -# include -# include -# endif +#ifdef GTEST_OS_WINDOWS +#ifndef GTEST_OS_WINDOWS_MOBILE +#include +#include +#endif // In order to avoid having to include , use forward declaration -#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR) +#if defined(GTEST_OS_WINDOWS_MINGW) && !defined(__MINGW64_VERSION_MAJOR) // MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two // separate (equivalent) structs, instead of using typedef typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION; @@ -359,7 +409,7 @@ typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION; // WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION. typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #endif -#elif GTEST_OS_XTENSA +#elif defined(GTEST_OS_XTENSA) #include // Xtensa toolchains define strcasecmp in the string.h header instead of // strings.h. string.h is already included. @@ -367,68 +417,60 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // This assumes that non-Windows OSes provide unistd.h. For OSes where this // is not the case, we need to include headers that provide the functions // mentioned above. -# include -# include +#include +#include #endif // GTEST_OS_WINDOWS -#if GTEST_OS_LINUX_ANDROID +#ifdef GTEST_OS_LINUX_ANDROID // Used to define __ANDROID_API__ matching the target NDK API level. -# include // NOLINT +#include // NOLINT #endif // Defines this to true if and only if Google Test can use POSIX regular // expressions. #ifndef GTEST_HAS_POSIX_RE -# if GTEST_OS_LINUX_ANDROID +#ifdef GTEST_OS_LINUX_ANDROID // On Android, is only available starting with Gingerbread. -# define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9) -# else -#define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS && !GTEST_OS_XTENSA) -# endif +#define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9) +#else +#if !(defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_XTENSA) || \ + defined(GTEST_OS_QURT)) +#define GTEST_HAS_POSIX_RE 1 +#else +#define GTEST_HAS_POSIX_RE 0 +#endif +#endif // GTEST_OS_LINUX_ANDROID #endif -#if GTEST_USES_PCRE -// The appropriate headers have already been included. - +// Select the regular expression implementation. +#ifdef GTEST_HAS_ABSL +// When using Abseil, RE2 is required. +#include "absl/strings/string_view.h" +#include "re2/re2.h" +#define GTEST_USES_RE2 1 #elif GTEST_HAS_POSIX_RE - -// On some platforms, needs someone to define size_t, and -// won't compile otherwise. We can #include it here as we already -// included , which is guaranteed to define size_t through -// . -# include // NOLINT - -# define GTEST_USES_POSIX_RE 1 - -#elif GTEST_OS_WINDOWS - -// is not available on Windows. Use our own simple regex -// implementation instead. -# define GTEST_USES_SIMPLE_RE 1 - +#include // NOLINT +#define GTEST_USES_POSIX_RE 1 #else - -// may not be available on this platform. Use our own -// simple regex implementation instead. -# define GTEST_USES_SIMPLE_RE 1 - -#endif // GTEST_USES_PCRE +// Use our own simple regex implementation. +#define GTEST_USES_SIMPLE_RE 1 +#endif #ifndef GTEST_HAS_EXCEPTIONS // The user didn't tell us whether exceptions are enabled, so we need // to figure it out. -# if defined(_MSC_VER) && defined(_CPPUNWIND) +#if defined(_MSC_VER) && defined(_CPPUNWIND) // MSVC defines _CPPUNWIND to 1 if and only if exceptions are enabled. -# define GTEST_HAS_EXCEPTIONS 1 -# elif defined(__BORLANDC__) +#define GTEST_HAS_EXCEPTIONS 1 +#elif defined(__BORLANDC__) // C++Builder's implementation of the STL uses the _HAS_EXCEPTIONS // macro to enable exceptions, so we'll do the same. // Assumes that exceptions are enabled by default. -# ifndef _HAS_EXCEPTIONS -# define _HAS_EXCEPTIONS 1 -# endif // _HAS_EXCEPTIONS -# define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS -# elif defined(__clang__) +#ifndef _HAS_EXCEPTIONS +#define _HAS_EXCEPTIONS 1 +#endif // _HAS_EXCEPTIONS +#define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS +#elif defined(__clang__) // clang defines __EXCEPTIONS if and only if exceptions are enabled before clang // 220714, but if and only if cleanups are enabled after that. In Obj-C++ files, // there can be cleanups for ObjC exceptions which also need cleanups, even if @@ -437,27 +479,31 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // cleanups prior to that. To reliably check for C++ exception availability with // clang, check for // __EXCEPTIONS && __has_feature(cxx_exceptions). -# define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions)) -# elif defined(__GNUC__) && __EXCEPTIONS +#if defined(__EXCEPTIONS) && __EXCEPTIONS && __has_feature(cxx_exceptions) +#define GTEST_HAS_EXCEPTIONS 1 +#else +#define GTEST_HAS_EXCEPTIONS 0 +#endif +#elif defined(__GNUC__) && defined(__EXCEPTIONS) && __EXCEPTIONS // gcc defines __EXCEPTIONS to 1 if and only if exceptions are enabled. -# define GTEST_HAS_EXCEPTIONS 1 -# elif defined(__SUNPRO_CC) +#define GTEST_HAS_EXCEPTIONS 1 +#elif defined(__SUNPRO_CC) // Sun Pro CC supports exceptions. However, there is no compile-time way of // detecting whether they are enabled or not. Therefore, we assume that // they are enabled unless the user tells us otherwise. -# define GTEST_HAS_EXCEPTIONS 1 -# elif defined(__IBMCPP__) && __EXCEPTIONS +#define GTEST_HAS_EXCEPTIONS 1 +#elif defined(__IBMCPP__) && defined(__EXCEPTIONS) && __EXCEPTIONS // xlC defines __EXCEPTIONS to 1 if and only if exceptions are enabled. -# define GTEST_HAS_EXCEPTIONS 1 -# elif defined(__HP_aCC) +#define GTEST_HAS_EXCEPTIONS 1 +#elif defined(__HP_aCC) // Exception handling is in effect by default in HP aCC compiler. It has to // be turned of by +noeh compiler option if desired. -# define GTEST_HAS_EXCEPTIONS 1 -# else +#define GTEST_HAS_EXCEPTIONS 1 +#else // For other compilers, we assume exceptions are disabled to be // conservative. -# define GTEST_HAS_EXCEPTIONS 0 -# endif // defined(_MSC_VER) || defined(__BORLANDC__) +#define GTEST_HAS_EXCEPTIONS 0 +#endif // defined(_MSC_VER) || defined(__BORLANDC__) #endif // GTEST_HAS_EXCEPTIONS #ifndef GTEST_HAS_STD_WSTRING @@ -466,74 +512,84 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // Cygwin 1.7 and below doesn't support ::std::wstring. // Solaris' libc++ doesn't support it either. Android has // no support for it at least as recent as Froyo (2.2). -#define GTEST_HAS_STD_WSTRING \ - (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ - GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266 || GTEST_OS_XTENSA)) - +#if (!(defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_CYGWIN) || \ + defined(GTEST_OS_SOLARIS) || defined(GTEST_OS_HAIKU) || \ + defined(GTEST_OS_ESP32) || defined(GTEST_OS_ESP8266) || \ + defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) || \ + defined(GTEST_OS_NXP_QN9090) || defined(GTEST_OS_NRF52))) +#define GTEST_HAS_STD_WSTRING 1 +#else +#define GTEST_HAS_STD_WSTRING 0 +#endif #endif // GTEST_HAS_STD_WSTRING +#ifndef GTEST_HAS_FILE_SYSTEM +// Most platforms support a file system. +#define GTEST_HAS_FILE_SYSTEM 1 +#endif // GTEST_HAS_FILE_SYSTEM + // Determines whether RTTI is available. #ifndef GTEST_HAS_RTTI // The user didn't tell us whether RTTI is enabled, so we need to // figure it out. -# ifdef _MSC_VER +#ifdef _MSC_VER #ifdef _CPPRTTI // MSVC defines this macro if and only if RTTI is enabled. -# define GTEST_HAS_RTTI 1 -# else -# define GTEST_HAS_RTTI 0 -# endif +#define GTEST_HAS_RTTI 1 +#else +#define GTEST_HAS_RTTI 0 +#endif // Starting with version 4.3.2, gcc defines __GXX_RTTI if and only if RTTI is // enabled. -# elif defined(__GNUC__) +#elif defined(__GNUC__) -# ifdef __GXX_RTTI +#ifdef __GXX_RTTI // When building against STLport with the Android NDK and with // -frtti -fno-exceptions, the build fails at link time with undefined // references to __cxa_bad_typeid. Note sure if STL or toolchain bug, // so disable RTTI when detected. -# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \ - !defined(__EXCEPTIONS) -# define GTEST_HAS_RTTI 0 -# else -# define GTEST_HAS_RTTI 1 -# endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS -# else -# define GTEST_HAS_RTTI 0 -# endif // __GXX_RTTI +#if defined(GTEST_OS_LINUX_ANDROID) && defined(_STLPORT_MAJOR) && \ + !defined(__EXCEPTIONS) +#define GTEST_HAS_RTTI 0 +#else +#define GTEST_HAS_RTTI 1 +#endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS +#else +#define GTEST_HAS_RTTI 0 +#endif // __GXX_RTTI // Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends // using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the // first version with C++ support. -# elif defined(__clang__) +#elif defined(__clang__) -# define GTEST_HAS_RTTI __has_feature(cxx_rtti) +#define GTEST_HAS_RTTI __has_feature(cxx_rtti) // Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if // both the typeid and dynamic_cast features are present. -# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900) +#elif defined(__IBMCPP__) && (__IBMCPP__ >= 900) -# ifdef __RTTI_ALL__ -# define GTEST_HAS_RTTI 1 -# else -# define GTEST_HAS_RTTI 0 -# endif +#ifdef __RTTI_ALL__ +#define GTEST_HAS_RTTI 1 +#else +#define GTEST_HAS_RTTI 0 +#endif -# else +#else // For all other compilers, we assume RTTI is enabled. -# define GTEST_HAS_RTTI 1 +#define GTEST_HAS_RTTI 1 -# endif // _MSC_VER +#endif // _MSC_VER #endif // GTEST_HAS_RTTI // It's this header's responsibility to #include when RTTI // is enabled. #if GTEST_HAS_RTTI -# include +#include #endif // Determines whether Google Test can use the pthreads library. @@ -543,47 +599,53 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // // To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0 // to your compiler flags. -#define GTEST_HAS_PTHREAD \ - (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX || GTEST_OS_QNX || \ - GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ - GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_OPENBSD || \ - GTEST_OS_HAIKU) +#if (defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || \ + defined(GTEST_OS_HPUX) || defined(GTEST_OS_QNX) || \ + defined(GTEST_OS_FREEBSD) || defined(GTEST_OS_NACL) || \ + defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \ + defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \ + defined(GTEST_OS_OPENBSD) || defined(GTEST_OS_HAIKU) || \ + defined(GTEST_OS_GNU_HURD) || defined(GTEST_OS_SOLARIS) || \ + defined(GTEST_OS_AIX) || defined(GTEST_OS_ZOS)) +#define GTEST_HAS_PTHREAD 1 +#else +#define GTEST_HAS_PTHREAD 0 +#endif #endif // GTEST_HAS_PTHREAD #if GTEST_HAS_PTHREAD // gtest-port.h guarantees to #include when GTEST_HAS_PTHREAD is // true. -# include // NOLINT +#include // NOLINT // For timespec and nanosleep, used below. -# include // NOLINT +#include // NOLINT #endif // Determines whether clone(2) is supported. // Usually it will only be available on Linux, excluding // Linux on the Itanium architecture. -// Also see http://linux.die.net/man/2/clone. +// Also see https://linux.die.net/man/2/clone. #ifndef GTEST_HAS_CLONE // The user didn't tell us, so we need to figure it out. -# if GTEST_OS_LINUX && !defined(__ia64__) -# if GTEST_OS_LINUX_ANDROID +#if defined(GTEST_OS_LINUX) && !defined(__ia64__) +#if defined(GTEST_OS_LINUX_ANDROID) // On Android, clone() became available at different API levels for each 32-bit // architecture. -# if defined(__LP64__) || \ - (defined(__arm__) && __ANDROID_API__ >= 9) || \ - (defined(__mips__) && __ANDROID_API__ >= 12) || \ - (defined(__i386__) && __ANDROID_API__ >= 17) -# define GTEST_HAS_CLONE 1 -# else -# define GTEST_HAS_CLONE 0 -# endif -# else -# define GTEST_HAS_CLONE 1 -# endif -# else -# define GTEST_HAS_CLONE 0 -# endif // GTEST_OS_LINUX && !defined(__ia64__) +#if defined(__LP64__) || (defined(__arm__) && __ANDROID_API__ >= 9) || \ + (defined(__mips__) && __ANDROID_API__ >= 12) || \ + (defined(__i386__) && __ANDROID_API__ >= 17) +#define GTEST_HAS_CLONE 1 +#else +#define GTEST_HAS_CLONE 0 +#endif +#else +#define GTEST_HAS_CLONE 1 +#endif +#else +#define GTEST_HAS_CLONE 0 +#endif // GTEST_OS_LINUX && !defined(__ia64__) #endif // GTEST_HAS_CLONE @@ -591,24 +653,34 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // output correctness and to implement death tests. #ifndef GTEST_HAS_STREAM_REDIRECTION // By default, we assume that stream redirection is supported on all -// platforms except known mobile ones. -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ - GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA -# define GTEST_HAS_STREAM_REDIRECTION 0 -# else -# define GTEST_HAS_STREAM_REDIRECTION 1 -# endif // !GTEST_OS_WINDOWS_MOBILE +// platforms except known mobile / embedded ones. Also, if the port doesn't have +// a file system, stream redirection is not supported. +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ + defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_WINDOWS_GAMES) || \ + defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \ + defined(GTEST_OS_QURT) || !GTEST_HAS_FILE_SYSTEM +#define GTEST_HAS_STREAM_REDIRECTION 0 +#else +#define GTEST_HAS_STREAM_REDIRECTION 1 +#endif // !GTEST_OS_WINDOWS_MOBILE #endif // GTEST_HAS_STREAM_REDIRECTION // Determines whether to support death tests. // pops up a dialog window that cannot be suppressed programmatically. -#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ - (GTEST_OS_MAC && !GTEST_OS_IOS) || \ - (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER) || GTEST_OS_WINDOWS_MINGW || \ - GTEST_OS_AIX || GTEST_OS_HPUX || GTEST_OS_OPENBSD || GTEST_OS_QNX || \ - GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ - GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_HAIKU) -# define GTEST_HAS_DEATH_TEST 1 +#if (defined(GTEST_OS_LINUX) || defined(GTEST_OS_CYGWIN) || \ + defined(GTEST_OS_SOLARIS) || defined(GTEST_OS_ZOS) || \ + (defined(GTEST_OS_MAC) && !defined(GTEST_OS_IOS)) || \ + (defined(GTEST_OS_WINDOWS_DESKTOP) && _MSC_VER) || \ + defined(GTEST_OS_WINDOWS_MINGW) || defined(GTEST_OS_AIX) || \ + defined(GTEST_OS_HPUX) || defined(GTEST_OS_OPENBSD) || \ + defined(GTEST_OS_QNX) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \ + defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \ + defined(GTEST_OS_HAIKU) || defined(GTEST_OS_GNU_HURD)) +// Death tests require a file system to work properly. +#if GTEST_HAS_FILE_SYSTEM +#define GTEST_HAS_DEATH_TEST 1 +#endif // GTEST_HAS_FILE_SYSTEM #endif // Determines whether to support type-driven tests. @@ -617,18 +689,26 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // Sun Pro CC, IBM Visual Age, and HP aCC support. #if defined(__GNUC__) || defined(_MSC_VER) || defined(__SUNPRO_CC) || \ defined(__IBMCPP__) || defined(__HP_aCC) -# define GTEST_HAS_TYPED_TEST 1 -# define GTEST_HAS_TYPED_TEST_P 1 +#define GTEST_HAS_TYPED_TEST 1 +#define GTEST_HAS_TYPED_TEST_P 1 #endif // Determines whether the system compiler uses UTF-16 for encoding wide strings. -#define GTEST_WIDE_STRING_USES_UTF16_ \ - (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_AIX || GTEST_OS_OS2) +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_CYGWIN) || \ + defined(GTEST_OS_AIX) || defined(GTEST_OS_OS2) +#define GTEST_WIDE_STRING_USES_UTF16_ 1 +#else +#define GTEST_WIDE_STRING_USES_UTF16_ 0 +#endif // Determines whether test results can be streamed to a socket. -#if GTEST_OS_LINUX || GTEST_OS_GNU_KFREEBSD || GTEST_OS_DRAGONFLY || \ - GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_OPENBSD -# define GTEST_CAN_STREAM_RESULTS_ 1 +#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_GNU_KFREEBSD) || \ + defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_NETBSD) || defined(GTEST_OS_OPENBSD) || \ + defined(GTEST_OS_GNU_HURD) || defined(GTEST_OS_MAC) +#define GTEST_CAN_STREAM_RESULTS_ 1 +#else +#define GTEST_CAN_STREAM_RESULTS_ 0 #endif // Defines some utility macros. @@ -642,84 +722,68 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // // The "switch (0) case 0:" idiom is used to suppress this. #ifdef __INTEL_COMPILER -# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ +#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ #else -# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT +#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + switch (0) \ + case 0: \ + default: // NOLINT #endif -// Use this annotation at the end of a struct/class definition to -// prevent the compiler from optimizing away instances that are never -// used. This is useful when all interesting logic happens inside the -// c'tor and / or d'tor. Example: +// GTEST_HAVE_ATTRIBUTE_ // -// struct Foo { -// Foo() { ... } -// } GTEST_ATTRIBUTE_UNUSED_; +// A function-like feature checking macro that is a wrapper around +// `__has_attribute`, which is defined by GCC 5+ and Clang and evaluates to a +// nonzero constant integer if the attribute is supported or 0 if not. // -// Also use it after a variable or parameter declaration to tell the -// compiler the variable/parameter does not have to be used. -#if defined(__GNUC__) && !defined(COMPILER_ICC) -# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) -#elif defined(__clang__) -# if __has_attribute(unused) -# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) -# endif +// It evaluates to zero if `__has_attribute` is not defined by the compiler. +// +// GCC: https://gcc.gnu.org/gcc-5/changes.html +// Clang: https://clang.llvm.org/docs/LanguageExtensions.html +#ifdef __has_attribute +#define GTEST_HAVE_ATTRIBUTE_(x) __has_attribute(x) +#else +#define GTEST_HAVE_ATTRIBUTE_(x) 0 #endif -#ifndef GTEST_ATTRIBUTE_UNUSED_ -# define GTEST_ATTRIBUTE_UNUSED_ + +// GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE +// +// A function-like feature checking macro that accepts C++11 style attributes. +// It's a wrapper around `__has_cpp_attribute`, defined by ISO C++ SD-6 +// (https://en.cppreference.com/w/cpp/experimental/feature_test). If we don't +// find `__has_cpp_attribute`, will evaluate to 0. +#if defined(__has_cpp_attribute) +// NOTE: requiring __cplusplus above should not be necessary, but +// works around https://bugs.llvm.org/show_bug.cgi?id=23435. +#define GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) +#else +#define GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(x) 0 +#endif + +// GTEST_HAVE_FEATURE_ +// +// A function-like feature checking macro that is a wrapper around +// `__has_feature`. +#ifdef __has_feature +#define GTEST_HAVE_FEATURE_(x) __has_feature(x) +#else +#define GTEST_HAVE_FEATURE_(x) 0 #endif // Use this annotation before a function that takes a printf format string. -#if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC) -# if defined(__MINGW_PRINTF_FORMAT) +#if GTEST_HAVE_ATTRIBUTE_(format) && defined(__MINGW_PRINTF_FORMAT) // MinGW has two different printf implementations. Ensure the format macro // matches the selected implementation. See // https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/. -# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ - __attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \ - first_to_check))) -# else -# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ - __attribute__((__format__(__printf__, string_index, first_to_check))) -# endif +#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ + __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, first_to_check))) +#elif GTEST_HAVE_ATTRIBUTE_(format) +#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ + __attribute__((format(printf, string_index, first_to_check))) #else -# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) +#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) #endif - -// A macro to disallow copy operator= -// This should be used in the private: declarations for a class. -#define GTEST_DISALLOW_ASSIGN_(type) \ - type& operator=(type const &) = delete - -// A macro to disallow copy constructor and operator= -// This should be used in the private: declarations for a class. -#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \ - type(type const&) = delete; \ - type& operator=(type const&) = delete - -// A macro to disallow move operator= -// This should be used in the private: declarations for a class. -#define GTEST_DISALLOW_MOVE_ASSIGN_(type) \ - type& operator=(type &&) noexcept = delete - -// A macro to disallow move constructor and operator= -// This should be used in the private: declarations for a class. -#define GTEST_DISALLOW_MOVE_AND_ASSIGN_(type) \ - type(type&&) noexcept = delete; \ - type& operator=(type&&) noexcept = delete - -// Tell the compiler to warn about unused return values for functions declared -// with this macro. The macro should be used on function declarations -// following the argument list: -// -// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; -#if defined(__GNUC__) && !defined(COMPILER_ICC) -# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) -#else -# define GTEST_MUST_USE_RESULT_ -#endif // __GNUC__ && !COMPILER_ICC - // MS C++ compiler emits warning when a conditional expression is compile time // constant. In some contexts this warning is false positive and needs to be // suppressed. Use the following two macros in such cases: @@ -728,10 +792,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // while (true) { // GTEST_INTENTIONAL_CONST_COND_POP_() // } -# define GTEST_INTENTIONAL_CONST_COND_PUSH_() \ - GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127) -# define GTEST_INTENTIONAL_CONST_COND_POP_() \ - GTEST_DISABLE_MSC_WARNINGS_POP_() +#define GTEST_INTENTIONAL_CONST_COND_PUSH_() \ + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127) +#define GTEST_INTENTIONAL_CONST_COND_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_() // Determine whether the compiler supports Microsoft's Structured Exception // Handling. This is supported by several Windows compilers but generally @@ -739,114 +802,116 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #ifndef GTEST_HAS_SEH // The user didn't tell us, so we need to figure it out. -# if defined(_MSC_VER) || defined(__BORLANDC__) +#if defined(_MSC_VER) || defined(__BORLANDC__) // These two compilers are known to support SEH. -# define GTEST_HAS_SEH 1 -# else +#define GTEST_HAS_SEH 1 +#else // Assume no SEH. -# define GTEST_HAS_SEH 0 -# endif +#define GTEST_HAS_SEH 0 +#endif #endif // GTEST_HAS_SEH #ifndef GTEST_IS_THREADSAFE -#define GTEST_IS_THREADSAFE \ - (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \ - (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) || \ - GTEST_HAS_PTHREAD) +#if (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \ + (defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT)) || \ + GTEST_HAS_PTHREAD) +#define GTEST_IS_THREADSAFE 1 +#endif #endif // GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE +// Some platforms don't support including these threading related headers. +#include // NOLINT +#include // NOLINT +#endif // GTEST_IS_THREADSAFE + // GTEST_API_ qualifies all symbols that must be exported. The definitions below // are guarded by #ifndef to give embedders a chance to define GTEST_API_ in // gtest/internal/custom/gtest-port.h #ifndef GTEST_API_ #ifdef _MSC_VER -# if GTEST_LINKED_AS_SHARED_LIBRARY -# define GTEST_API_ __declspec(dllimport) -# elif GTEST_CREATE_SHARED_LIBRARY -# define GTEST_API_ __declspec(dllexport) -# endif -#elif __GNUC__ >= 4 || defined(__clang__) -# define GTEST_API_ __attribute__((visibility ("default"))) +#if defined(GTEST_LINKED_AS_SHARED_LIBRARY) && GTEST_LINKED_AS_SHARED_LIBRARY +#define GTEST_API_ __declspec(dllimport) +#elif defined(GTEST_CREATE_SHARED_LIBRARY) && GTEST_CREATE_SHARED_LIBRARY +#define GTEST_API_ __declspec(dllexport) +#endif +#elif GTEST_HAVE_ATTRIBUTE_(visibility) +#define GTEST_API_ __attribute__((visibility("default"))) #endif // _MSC_VER #endif // GTEST_API_ #ifndef GTEST_API_ -# define GTEST_API_ +#define GTEST_API_ #endif // GTEST_API_ #ifndef GTEST_DEFAULT_DEATH_TEST_STYLE -# define GTEST_DEFAULT_DEATH_TEST_STYLE "fast" +#define GTEST_DEFAULT_DEATH_TEST_STYLE "fast" #endif // GTEST_DEFAULT_DEATH_TEST_STYLE -#ifdef __GNUC__ +#if GTEST_HAVE_ATTRIBUTE_(noinline) // Ask the compiler to never inline a given function. -# define GTEST_NO_INLINE_ __attribute__((noinline)) +#define GTEST_NO_INLINE_ __attribute__((noinline)) #else -# define GTEST_NO_INLINE_ +#define GTEST_NO_INLINE_ +#endif + +#if GTEST_HAVE_ATTRIBUTE_(disable_tail_calls) +// Ask the compiler not to perform tail call optimization inside +// the marked function. +#define GTEST_NO_TAIL_CALL_ __attribute__((disable_tail_calls)) +#elif defined(__GNUC__) && !defined(__NVCOMPILER) +#define GTEST_NO_TAIL_CALL_ \ + __attribute__((optimize("no-optimize-sibling-calls"))) +#else +#define GTEST_NO_TAIL_CALL_ #endif // _LIBCPP_VERSION is defined by the libc++ library from the LLVM project. #if !defined(GTEST_HAS_CXXABI_H_) -# if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER)) -# define GTEST_HAS_CXXABI_H_ 1 -# else -# define GTEST_HAS_CXXABI_H_ 0 -# endif +#if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER)) +#define GTEST_HAS_CXXABI_H_ 1 +#else +#define GTEST_HAS_CXXABI_H_ 0 +#endif #endif // A function level attribute to disable checking for use of uninitialized // memory when built with MemorySanitizer. -#if defined(__clang__) -# if __has_feature(memory_sanitizer) -# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \ - __attribute__((no_sanitize_memory)) -# else -# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ -# endif // __has_feature(memory_sanitizer) +#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_memory) +#define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ __attribute__((no_sanitize_memory)) #else -# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ -#endif // __clang__ +#define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ +#endif // A function level attribute to disable AddressSanitizer instrumentation. -#if defined(__clang__) -# if __has_feature(address_sanitizer) -# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \ - __attribute__((no_sanitize_address)) -# else -# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ -# endif // __has_feature(address_sanitizer) +#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_address) +#define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \ + __attribute__((no_sanitize_address)) #else -# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ -#endif // __clang__ +#define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ +#endif // A function level attribute to disable HWAddressSanitizer instrumentation. -#if defined(__clang__) -# if __has_feature(hwaddress_sanitizer) -# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \ - __attribute__((no_sanitize("hwaddress"))) -# else -# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ -# endif // __has_feature(hwaddress_sanitizer) +#if GTEST_HAVE_FEATURE_(hwaddress_sanitizer) && \ + GTEST_HAVE_ATTRIBUTE_(no_sanitize) +#define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \ + __attribute__((no_sanitize("hwaddress"))) #else -# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ -#endif // __clang__ +#define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ +#endif // A function level attribute to disable ThreadSanitizer instrumentation. -#if defined(__clang__) -# if __has_feature(thread_sanitizer) -# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \ - __attribute__((no_sanitize_thread)) -# else -# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ -# endif // __has_feature(thread_sanitizer) +#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_thread) +#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ __attribute((no_sanitize_thread)) #else -# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ -#endif // __clang__ +#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ +#endif namespace testing { @@ -863,20 +928,11 @@ using std::tuple_size; namespace internal { // A secret type that Google Test users don't know about. It has no -// definition on purpose. Therefore it's impossible to create a +// accessible constructors on purpose. Therefore it's impossible to create a // Secret object, which is what we want. -class Secret; - -// The GTEST_COMPILE_ASSERT_ is a legacy macro used to verify that a compile -// time expression is true (in new code, use static_assert instead). For -// example, you could use it to verify the size of a static array: -// -// GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES, -// names_incorrect_size); -// -// The second argument to the macro must be a valid C++ identifier. If the -// expression is false, compiler will issue an error containing this identifier. -#define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg) +class Secret { + Secret(const Secret&) = delete; +}; // A helper for suppressing warnings on constant condition. It just // returns 'condition'. @@ -884,9 +940,34 @@ GTEST_API_ bool IsTrue(bool condition); // Defines RE. -#if GTEST_USES_PCRE -// if used, PCRE is injected by custom/gtest-port.h -#elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE +#ifdef GTEST_USES_RE2 + +// This is almost `using RE = ::RE2`, except it is copy-constructible, and it +// needs to disambiguate the `std::string`, `absl::string_view`, and `const +// char*` constructors. +class GTEST_API_ RE { + public: + RE(absl::string_view regex) : regex_(regex) {} // NOLINT + RE(const char* regex) : RE(absl::string_view(regex)) {} // NOLINT + RE(const std::string& regex) : RE(absl::string_view(regex)) {} // NOLINT + RE(const RE& other) : RE(other.pattern()) {} + + const std::string& pattern() const { return regex_.pattern(); } + + static bool FullMatch(absl::string_view str, const RE& re) { + return RE2::FullMatch(str, re.regex_); + } + static bool PartialMatch(absl::string_view str, const RE& re) { + return RE2::PartialMatch(str, re.regex_); + } + + private: + RE2 regex_; +}; + +#elif defined(GTEST_USES_POSIX_RE) || defined(GTEST_USES_SIMPLE_RE) +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ +/* class A needs to have dll-interface to be used by clients of class B */) // A simple C++ wrapper for . It uses the POSIX Extended // Regular Expression syntax. @@ -903,7 +984,7 @@ class GTEST_API_ RE { ~RE(); // Returns the string representation of the regex. - const char* pattern() const { return pattern_; } + const char* pattern() const { return pattern_.c_str(); } // FullMatch(str, re) returns true if and only if regular expression re // matches the entire str. @@ -921,22 +1002,22 @@ class GTEST_API_ RE { private: void Init(const char* regex); - const char* pattern_; + std::string pattern_; bool is_valid_; -# if GTEST_USES_POSIX_RE +#ifdef GTEST_USES_POSIX_RE regex_t full_regex_; // For FullMatch(). regex_t partial_regex_; // For PartialMatch(). -# else // GTEST_USES_SIMPLE_RE +#else // GTEST_USES_SIMPLE_RE - const char* full_pattern_; // For FullMatch(); + std::string full_pattern_; // For FullMatch(); -# endif +#endif }; - -#endif // GTEST_USES_PCRE +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 +#endif // ::testing::internal::RE implementation // Formats a source file path and a line number as they would appear // in an error message from the compiler used to compile this code. @@ -954,12 +1035,7 @@ GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file, // LogToStderr() - directs all log messages to stderr. // FlushInfoLog() - flushes informational log messages. -enum GTestLogSeverity { - GTEST_INFO, - GTEST_WARNING, - GTEST_ERROR, - GTEST_FATAL -}; +enum GTestLogSeverity { GTEST_INFO, GTEST_WARNING, GTEST_ERROR, GTEST_FATAL }; // Formats log entry severity, provides a stream object for streaming the // log message, and terminates the message with a newline when going out of @@ -976,14 +1052,16 @@ class GTEST_API_ GTestLog { private: const GTestLogSeverity severity_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog); + GTestLog(const GTestLog&) = delete; + GTestLog& operator=(const GTestLog&) = delete; }; #if !defined(GTEST_LOG_) -# define GTEST_LOG_(severity) \ - ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \ - __FILE__, __LINE__).GetStream() +#define GTEST_LOG_(severity) \ + ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \ + __FILE__, __LINE__) \ + .GetStream() inline void LogToStderr() {} inline void FlushInfoLog() { fflush(nullptr); } @@ -995,7 +1073,7 @@ inline void FlushInfoLog() { fflush(nullptr); } // // GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition // is not satisfied. -// Synopsys: +// Synopsis: // GTEST_CHECK_(boolean_condition); // or // GTEST_CHECK_(boolean_condition) << "Additional message"; @@ -1005,12 +1083,12 @@ inline void FlushInfoLog() { fflush(nullptr); } // condition itself, plus additional message streamed into it, if any, // and then it aborts the program. It aborts the program irrespective of // whether it is built in the debug mode or not. -# define GTEST_CHECK_(condition) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::IsTrue(condition)) \ - ; \ - else \ - GTEST_LOG_(FATAL) << "Condition " #condition " failed. " +#define GTEST_CHECK_(condition) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::IsTrue(condition)) \ + ; \ + else \ + GTEST_LOG_(FATAL) << "Condition " #condition " failed. " #endif // !defined(GTEST_CHECK_) // An all-mode assert to verify that the given POSIX-style function @@ -1019,9 +1097,8 @@ inline void FlushInfoLog() { fflush(nullptr); } // in {} if you need to use it as the only statement in an 'if' // branch. #define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \ - if (const int gtest_error = (posix_call)) \ - GTEST_LOG_(FATAL) << #posix_call << "failed with error " \ - << gtest_error + if (const int gtest_error = (posix_call)) \ + GTEST_LOG_(FATAL) << #posix_call << "failed with error " << gtest_error // Transforms "T" into "const T&" according to standard reference collapsing // rules (this is only needed as a backport for C++98 compilers that do not @@ -1035,9 +1112,13 @@ inline void FlushInfoLog() { fflush(nullptr); } // Note that the non-const reference will not have "const" added. This is // standard, and necessary so that "T" can always bind to "const T&". template -struct ConstRef { typedef const T& type; }; +struct ConstRef { + typedef const T& type; +}; template -struct ConstRef { typedef T& type; }; +struct ConstRef { + typedef T& type; +}; // The argument T must depend on some template parameters. #define GTEST_REFERENCE_TO_CONST_(T) \ @@ -1050,7 +1131,7 @@ struct ConstRef { typedef T& type; }; // const Foo*). When you use ImplicitCast_, the compiler checks that // the cast is safe. Such explicit ImplicitCast_s are necessary in // surprisingly many situations where C++ demands an exact type match -// instead of an argument type convertable to a target type. +// instead of an argument type convertible to a target type. // // The syntax for using ImplicitCast_ is the same as for static_cast: // @@ -1063,48 +1144,9 @@ struct ConstRef { typedef T& type; }; // This relatively ugly name is intentional. It prevents clashes with // similar functions users may have (e.g., implicit_cast). The internal // namespace alone is not enough because the function can be found by ADL. -template -inline To ImplicitCast_(To x) { return x; } - -// When you upcast (that is, cast a pointer from type Foo to type -// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts -// always succeed. When you downcast (that is, cast a pointer from -// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because -// how do you know the pointer is really of type SubclassOfFoo? It -// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, -// when you downcast, you should use this macro. In debug mode, we -// use dynamic_cast<> to double-check the downcast is legal (we die -// if it's not). In normal mode, we do the efficient static_cast<> -// instead. Thus, it's important to test in debug mode to make sure -// the cast is legal! -// This is the only place in the code we should use dynamic_cast<>. -// In particular, you SHOULDN'T be using dynamic_cast<> in order to -// do RTTI (eg code like this: -// if (dynamic_cast(foo)) HandleASubclass1Object(foo); -// if (dynamic_cast(foo)) HandleASubclass2Object(foo); -// You should design the code some other way not to need this. -// -// This relatively ugly name is intentional. It prevents clashes with -// similar functions users may have (e.g., down_cast). The internal -// namespace alone is not enough because the function can be found by ADL. -template // use like this: DownCast_(foo); -inline To DownCast_(From* f) { // so we only accept pointers - // Ensures that To is a sub-type of From *. This test is here only - // for compile-time type checking, and has no overhead in an - // optimized build at run-time, as it will be optimized away - // completely. - GTEST_INTENTIONAL_CONST_COND_PUSH_() - if (false) { - GTEST_INTENTIONAL_CONST_COND_POP_() - const To to = nullptr; - ::testing::internal::ImplicitCast_(to); - } - -#if GTEST_HAS_RTTI - // RTTI: debug mode only! - GTEST_CHECK_(f == nullptr || dynamic_cast(f) != nullptr); -#endif - return static_cast(f); +template +inline To ImplicitCast_(To x) { + return x; } // Downcasts the pointer of type Base to Derived. @@ -1114,17 +1156,12 @@ inline To DownCast_(From* f) { // so we only accept pointers // check to enforce this. template Derived* CheckedDowncastToActualType(Base* base) { + static_assert(std::is_base_of::value, + "target type not derived from source type"); #if GTEST_HAS_RTTI - GTEST_CHECK_(typeid(*base) == typeid(Derived)); -#endif - -#if GTEST_HAS_DOWNCAST_ - return ::down_cast(base); -#elif GTEST_HAS_RTTI - return dynamic_cast(base); // NOLINT -#else - return static_cast(base); // Poor man's downcast. + GTEST_CHECK_(base == nullptr || dynamic_cast(base) != nullptr); #endif + return static_cast(base); } #if GTEST_HAS_STREAM_REDIRECTION @@ -1150,7 +1187,7 @@ GTEST_API_ std::string ReadEntireFile(FILE* file); // All command line arguments. GTEST_API_ std::vector GetArgvs(); -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST std::vector GetInjectableArgvs(); // Deprecated: pass the args vector by value instead. @@ -1161,72 +1198,9 @@ void ClearInjectableArgvs(); #endif // GTEST_HAS_DEATH_TEST // Defines synchronization primitives. -#if GTEST_IS_THREADSAFE -# if GTEST_HAS_PTHREAD -// Sleeps for (roughly) n milliseconds. This function is only for testing -// Google Test's own constructs. Don't use it in user tests, either -// directly or indirectly. -inline void SleepMilliseconds(int n) { - const timespec time = { - 0, // 0 seconds. - n * 1000L * 1000L, // And n ms. - }; - nanosleep(&time, nullptr); -} -# endif // GTEST_HAS_PTHREAD - -# if GTEST_HAS_NOTIFICATION_ -// Notification has already been imported into the namespace. -// Nothing to do here. - -# elif GTEST_HAS_PTHREAD -// Allows a controller thread to pause execution of newly created -// threads until notified. Instances of this class must be created -// and destroyed in the controller thread. -// -// This class is only for testing Google Test's own constructs. Do not -// use it in user tests, either directly or indirectly. -class Notification { - public: - Notification() : notified_(false) { - GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr)); - } - ~Notification() { - pthread_mutex_destroy(&mutex_); - } - - // Notifies all threads created with this notification to start. Must - // be called from the controller thread. - void Notify() { - pthread_mutex_lock(&mutex_); - notified_ = true; - pthread_mutex_unlock(&mutex_); - } - - // Blocks until the controller thread notifies. Must be called from a test - // thread. - void WaitForNotification() { - for (;;) { - pthread_mutex_lock(&mutex_); - const bool notified = notified_; - pthread_mutex_unlock(&mutex_); - if (notified) - break; - SleepMilliseconds(10); - } - } - - private: - pthread_mutex_t mutex_; - bool notified_; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification); -}; - -# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT - -GTEST_API_ void SleepMilliseconds(int n); +#ifdef GTEST_IS_THREADSAFE +#ifdef GTEST_OS_WINDOWS // Provides leak-safe Windows kernel handle ownership. // Used in death tests and in threading support. class GTEST_API_ AutoHandle { @@ -1253,32 +1227,90 @@ class GTEST_API_ AutoHandle { Handle handle_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle); + AutoHandle(const AutoHandle&) = delete; + AutoHandle& operator=(const AutoHandle&) = delete; }; +#endif +#if GTEST_HAS_NOTIFICATION_ +// Notification has already been imported into the namespace. +// Nothing to do here. + +#else // Allows a controller thread to pause execution of newly created // threads until notified. Instances of this class must be created // and destroyed in the controller thread. // // This class is only for testing Google Test's own constructs. Do not // use it in user tests, either directly or indirectly. +// TODO(b/203539622): Replace unconditionally with absl::Notification. +#ifdef GTEST_OS_WINDOWS_MINGW +// GCC version < 13 with the win32 thread model does not provide std::mutex and +// std::condition_variable in the and headers. So +// we implement the Notification class using a Windows manual-reset event. See +// https://gcc.gnu.org/gcc-13/changes.html#windows. class GTEST_API_ Notification { public: Notification(); + Notification(const Notification&) = delete; + Notification& operator=(const Notification&) = delete; + ~Notification(); + + // Notifies all threads created with this notification to start. Must + // be called from the controller thread. void Notify(); + + // Blocks until the controller thread notifies. Must be called from a test + // thread. void WaitForNotification(); private: - AutoHandle event_; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification); + // Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to + // avoid including in this header file. Including is + // undesirable because it defines a lot of symbols and macros that tend to + // conflict with client code. This assumption is verified by + // WindowsTypesTest.HANDLEIsVoidStar. + typedef void* Handle; + Handle event_; }; -# endif // GTEST_HAS_NOTIFICATION_ +#else +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ +/* class A needs to have dll-interface to be used by clients of class B */) + +class GTEST_API_ Notification { + public: + Notification() : notified_(false) {} + Notification(const Notification&) = delete; + Notification& operator=(const Notification&) = delete; + + // Notifies all threads created with this notification to start. Must + // be called from the controller thread. + void Notify() { + std::lock_guard lock(mu_); + notified_ = true; + cv_.notify_all(); + } + + // Blocks until the controller thread notifies. Must be called from a test + // thread. + void WaitForNotification() { + std::unique_lock lock(mu_); + cv_.wait(lock, [this]() { return notified_; }); + } + + private: + std::mutex mu_; + std::condition_variable cv_; + bool notified_; +}; +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 +#endif // GTEST_OS_WINDOWS_MINGW +#endif // GTEST_HAS_NOTIFICATION_ // On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD // defined, but we don't want to use MinGW's pthreads implementation, which // has conformance problems with some versions of the POSIX standard. -# if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW +#if GTEST_HAS_PTHREAD && !defined(GTEST_OS_WINDOWS_MINGW) // As a C-function, ThreadFuncWithCLinkage cannot be templated itself. // Consequently, it cannot select a correct instantiation of ThreadWithParam @@ -1287,7 +1319,7 @@ class GTEST_API_ Notification { // problem. class ThreadWithParamBase { public: - virtual ~ThreadWithParamBase() {} + virtual ~ThreadWithParamBase() = default; virtual void Run() = 0; }; @@ -1354,16 +1386,18 @@ class ThreadWithParam : public ThreadWithParamBase { // finished. pthread_t thread_; // The native thread object. - GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam); + ThreadWithParam(const ThreadWithParam&) = delete; + ThreadWithParam& operator=(const ThreadWithParam&) = delete; }; -# endif // !GTEST_OS_WINDOWS && GTEST_HAS_PTHREAD || - // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ +#endif // !GTEST_OS_WINDOWS && GTEST_HAS_PTHREAD || + // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ -# if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ +#if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ // Mutex and ThreadLocal have already been imported into the namespace. // Nothing to do here. -# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT +#elif defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT) // Mutex implements mutex on Windows platforms. It is used in conjunction // with class MutexLock: @@ -1417,14 +1451,15 @@ class GTEST_API_ Mutex { long critical_section_init_phase_; // NOLINT GTEST_CRITICAL_SECTION* critical_section_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex); + Mutex(const Mutex&) = delete; + Mutex& operator=(const Mutex&) = delete; }; -# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ - extern ::testing::internal::Mutex mutex +#define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ + extern ::testing::internal::Mutex mutex -# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ - ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex) +#define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ + ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex) // We cannot name this class MutexLock because the ctor declaration would // conflict with a macro named MutexLock, which is defined on some @@ -1433,15 +1468,15 @@ class GTEST_API_ Mutex { // "MutexLock l(&mu)". Hence the typedef trick below. class GTestMutexLock { public: - explicit GTestMutexLock(Mutex* mutex) - : mutex_(mutex) { mutex_->Lock(); } + explicit GTestMutexLock(Mutex* mutex) : mutex_(mutex) { mutex_->Lock(); } ~GTestMutexLock() { mutex_->Unlock(); } private: Mutex* const mutex_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock); + GTestMutexLock(const GTestMutexLock&) = delete; + GTestMutexLock& operator=(const GTestMutexLock&) = delete; }; typedef GTestMutexLock MutexLock; @@ -1468,7 +1503,8 @@ class ThreadLocalBase { virtual ~ThreadLocalBase() {} private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocalBase); + ThreadLocalBase(const ThreadLocalBase&) = delete; + ThreadLocalBase& operator=(const ThreadLocalBase&) = delete; }; // Maps a thread to a set of ThreadLocals that have values instantiated on that @@ -1497,7 +1533,7 @@ class GTEST_API_ ThreadWithParamBase { virtual void Run() = 0; }; - ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start); + ThreadWithParamBase(Runnable* runnable, Notification* thread_can_start); virtual ~ThreadWithParamBase(); private: @@ -1511,30 +1547,26 @@ class ThreadWithParam : public ThreadWithParamBase { typedef void UserThreadFunc(T); ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start) - : ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) { - } + : ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) {} virtual ~ThreadWithParam() {} private: class RunnableImpl : public Runnable { public: - RunnableImpl(UserThreadFunc* func, T param) - : func_(func), - param_(param) { - } + RunnableImpl(UserThreadFunc* func, T param) : func_(func), param_(param) {} virtual ~RunnableImpl() {} - virtual void Run() { - func_(param_); - } + virtual void Run() { func_(param_); } private: UserThreadFunc* const func_; const T param_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(RunnableImpl); + RunnableImpl(const RunnableImpl&) = delete; + RunnableImpl& operator=(const RunnableImpl&) = delete; }; - GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam); + ThreadWithParam(const ThreadWithParam&) = delete; + ThreadWithParam& operator=(const ThreadWithParam&) = delete; }; // Implements thread-local storage on Windows systems. @@ -1571,7 +1603,7 @@ class ThreadLocal : public ThreadLocalBase { explicit ThreadLocal(const T& value) : default_factory_(new InstanceValueHolderFactory(value)) {} - ~ThreadLocal() { ThreadLocalRegistry::OnThreadLocalDestroyed(this); } + ~ThreadLocal() override { ThreadLocalRegistry::OnThreadLocalDestroyed(this); } T* pointer() { return GetOrCreateValue(); } const T* pointer() const { return GetOrCreateValue(); } @@ -1590,16 +1622,17 @@ class ThreadLocal : public ThreadLocalBase { private: T value_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder); + ValueHolder(const ValueHolder&) = delete; + ValueHolder& operator=(const ValueHolder&) = delete; }; - T* GetOrCreateValue() const { return static_cast( - ThreadLocalRegistry::GetValueOnCurrentThread(this))->pointer(); + ThreadLocalRegistry::GetValueOnCurrentThread(this)) + ->pointer(); } - virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const { + ThreadLocalValueHolderBase* NewValueForCurrentThread() const override { return default_factory_->MakeNewHolder(); } @@ -1610,7 +1643,8 @@ class ThreadLocal : public ThreadLocalBase { virtual ValueHolder* MakeNewHolder() const = 0; private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory); + ValueHolderFactory(const ValueHolderFactory&) = delete; + ValueHolderFactory& operator=(const ValueHolderFactory&) = delete; }; class DefaultValueHolderFactory : public ValueHolderFactory { @@ -1619,7 +1653,9 @@ class ThreadLocal : public ThreadLocalBase { ValueHolder* MakeNewHolder() const override { return new ValueHolder(); } private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory); + DefaultValueHolderFactory(const DefaultValueHolderFactory&) = delete; + DefaultValueHolderFactory& operator=(const DefaultValueHolderFactory&) = + delete; }; class InstanceValueHolderFactory : public ValueHolderFactory { @@ -1632,15 +1668,18 @@ class ThreadLocal : public ThreadLocalBase { private: const T value_; // The value for each thread. - GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory); + InstanceValueHolderFactory(const InstanceValueHolderFactory&) = delete; + InstanceValueHolderFactory& operator=(const InstanceValueHolderFactory&) = + delete; }; std::unique_ptr default_factory_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); + ThreadLocal(const ThreadLocal&) = delete; + ThreadLocal& operator=(const ThreadLocal&) = delete; }; -# elif GTEST_HAS_PTHREAD +#elif GTEST_HAS_PTHREAD // MutexBase and Mutex implement mutex on pthreads-based platforms. class MutexBase { @@ -1687,8 +1726,8 @@ class MutexBase { }; // Forward-declares a static mutex. -# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ - extern ::testing::internal::MutexBase mutex +#define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ + extern ::testing::internal::MutexBase mutex // Defines and statically (i.e. at link time) initializes a static mutex. // The initialization list here does not explicitly initialize each field, @@ -1707,12 +1746,11 @@ class Mutex : public MutexBase { GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr)); has_owner_ = false; } - ~Mutex() { - GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_)); - } + ~Mutex() { GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_)); } private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex); + Mutex(const Mutex&) = delete; + Mutex& operator=(const Mutex&) = delete; }; // We cannot name this class MutexLock because the ctor declaration would @@ -1722,15 +1760,15 @@ class Mutex : public MutexBase { // "MutexLock l(&mu)". Hence the typedef trick below. class GTestMutexLock { public: - explicit GTestMutexLock(MutexBase* mutex) - : mutex_(mutex) { mutex_->Lock(); } + explicit GTestMutexLock(MutexBase* mutex) : mutex_(mutex) { mutex_->Lock(); } ~GTestMutexLock() { mutex_->Unlock(); } private: MutexBase* const mutex_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock); + GTestMutexLock(const GTestMutexLock&) = delete; + GTestMutexLock& operator=(const GTestMutexLock&) = delete; }; typedef GTestMutexLock MutexLock; @@ -1741,9 +1779,9 @@ typedef GTestMutexLock MutexLock; // C-linkage. Therefore it cannot be templatized to access // ThreadLocal. Hence the need for class // ThreadLocalValueHolderBase. -class ThreadLocalValueHolderBase { +class GTEST_API_ ThreadLocalValueHolderBase { public: - virtual ~ThreadLocalValueHolderBase() {} + virtual ~ThreadLocalValueHolderBase() = default; }; // Called by pthread to delete thread-local data stored by @@ -1787,7 +1825,8 @@ class GTEST_API_ ThreadLocal { private: T value_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder); + ValueHolder(const ValueHolder&) = delete; + ValueHolder& operator=(const ValueHolder&) = delete; }; static pthread_key_t CreateKey() { @@ -1814,21 +1853,24 @@ class GTEST_API_ ThreadLocal { class ValueHolderFactory { public: - ValueHolderFactory() {} - virtual ~ValueHolderFactory() {} + ValueHolderFactory() = default; + virtual ~ValueHolderFactory() = default; virtual ValueHolder* MakeNewHolder() const = 0; private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory); + ValueHolderFactory(const ValueHolderFactory&) = delete; + ValueHolderFactory& operator=(const ValueHolderFactory&) = delete; }; class DefaultValueHolderFactory : public ValueHolderFactory { public: - DefaultValueHolderFactory() {} + DefaultValueHolderFactory() = default; ValueHolder* MakeNewHolder() const override { return new ValueHolder(); } private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory); + DefaultValueHolderFactory(const DefaultValueHolderFactory&) = delete; + DefaultValueHolderFactory& operator=(const DefaultValueHolderFactory&) = + delete; }; class InstanceValueHolderFactory : public ValueHolderFactory { @@ -1841,17 +1883,20 @@ class GTEST_API_ ThreadLocal { private: const T value_; // The value for each thread. - GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory); + InstanceValueHolderFactory(const InstanceValueHolderFactory&) = delete; + InstanceValueHolderFactory& operator=(const InstanceValueHolderFactory&) = + delete; }; // A key pthreads uses for looking up per-thread values. const pthread_key_t key_; std::unique_ptr default_factory_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); + ThreadLocal(const ThreadLocal&) = delete; + ThreadLocal& operator=(const ThreadLocal&) = delete; }; -# endif // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ +#endif // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ #else // GTEST_IS_THREADSAFE @@ -1868,10 +1913,10 @@ class Mutex { void AssertHeld() const {} }; -# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ +#define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ extern ::testing::internal::Mutex mutex -# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex +#define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex // We cannot name this class MutexLock because the ctor declaration would // conflict with a macro named MutexLock, which is defined on some @@ -1894,6 +1939,7 @@ class GTEST_API_ ThreadLocal { const T* pointer() const { return &value_; } const T& get() const { return value_; } void set(const T& value) { value_ = value; } + private: T value_; }; @@ -1904,12 +1950,12 @@ class GTEST_API_ ThreadLocal { // we cannot detect it. GTEST_API_ size_t GetThreadCount(); -#if GTEST_OS_WINDOWS -# define GTEST_PATH_SEP_ "\\" -# define GTEST_HAS_ALT_PATH_SEP_ 1 +#ifdef GTEST_OS_WINDOWS +#define GTEST_PATH_SEP_ "\\" +#define GTEST_HAS_ALT_PATH_SEP_ 1 #else -# define GTEST_PATH_SEP_ "/" -# define GTEST_HAS_ALT_PATH_SEP_ 0 +#define GTEST_PATH_SEP_ "/" +#define GTEST_HAS_ALT_PATH_SEP_ 0 #endif // GTEST_OS_WINDOWS // Utilities for char. @@ -1940,7 +1986,7 @@ inline bool IsUpper(char ch) { inline bool IsXDigit(char ch) { return isxdigit(static_cast(ch)) != 0; } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t inline bool IsXDigit(char8_t ch) { return isxdigit(static_cast(ch)) != 0; } @@ -1967,8 +2013,7 @@ inline char ToUpper(char ch) { inline std::string StripTrailingSpaces(std::string str) { std::string::iterator it = str.end(); - while (it != str.begin() && IsSpace(*--it)) - it = str.erase(it); + while (it != str.begin() && IsSpace(*--it)) it = str.erase(it); return str; } @@ -1980,72 +2025,86 @@ inline std::string StripTrailingSpaces(std::string str) { namespace posix { -// Functions with a different name on Windows. - -#if GTEST_OS_WINDOWS +// File system porting. +// Note: Not every I/O-related function is related to file systems, so don't +// just disable all of them here. For example, fileno() and isatty(), etc. must +// always be available in order to detect if a pipe points to a terminal. +#ifdef GTEST_OS_WINDOWS typedef struct _stat StatStruct; -# ifdef __BORLANDC__ -inline int DoIsATTY(int fd) { return isatty(fd); } -inline int StrCaseCmp(const char* s1, const char* s2) { - return stricmp(s1, s2); -} -inline char* StrDup(const char* src) { return strdup(src); } -# else // !__BORLANDC__ -# if GTEST_OS_WINDOWS_MOBILE -inline int DoIsATTY(int /* fd */) { return 0; } -# else -inline int DoIsATTY(int fd) { return _isatty(fd); } -# endif // GTEST_OS_WINDOWS_MOBILE -inline int StrCaseCmp(const char* s1, const char* s2) { - return _stricmp(s1, s2); -} -inline char* StrDup(const char* src) { return _strdup(src); } -# endif // __BORLANDC__ - -# if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE inline int FileNo(FILE* file) { return reinterpret_cast(_fileno(file)); } // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this // time and thus not defined there. -# else +#else inline int FileNo(FILE* file) { return _fileno(file); } +#if GTEST_HAS_FILE_SYSTEM inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } inline int RmDir(const char* dir) { return _rmdir(dir); } -inline bool IsDir(const StatStruct& st) { - return (_S_IFDIR & st.st_mode) != 0; -} -# endif // GTEST_OS_WINDOWS_MOBILE +inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; } +#endif +#endif // GTEST_OS_WINDOWS_MOBILE -#elif GTEST_OS_ESP8266 +#elif defined(GTEST_OS_ESP8266) typedef struct stat StatStruct; inline int FileNo(FILE* file) { return fileno(file); } -inline int DoIsATTY(int fd) { return isatty(fd); } +#if GTEST_HAS_FILE_SYSTEM inline int Stat(const char* path, StatStruct* buf) { // stat function not implemented on ESP8266 return 0; } -inline int StrCaseCmp(const char* s1, const char* s2) { - return strcasecmp(s1, s2); -} -inline char* StrDup(const char* src) { return strdup(src); } inline int RmDir(const char* dir) { return rmdir(dir); } inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } +#endif #else typedef struct stat StatStruct; inline int FileNo(FILE* file) { return fileno(file); } -inline int DoIsATTY(int fd) { return isatty(fd); } +#if GTEST_HAS_FILE_SYSTEM inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } +#ifdef GTEST_OS_QURT +// QuRT doesn't support any directory functions, including rmdir +inline int RmDir(const char*) { return 0; } +#else +inline int RmDir(const char* dir) { return rmdir(dir); } +#endif +inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } +#endif + +#endif // GTEST_OS_WINDOWS + +// Other functions with a different name on Windows. + +#ifdef GTEST_OS_WINDOWS + +#ifdef __BORLANDC__ +inline int DoIsATTY(int fd) { return isatty(fd); } +inline int StrCaseCmp(const char* s1, const char* s2) { + return stricmp(s1, s2); +} +#else // !__BORLANDC__ +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_ZOS) || \ + defined(GTEST_OS_IOS) || defined(GTEST_OS_WINDOWS_PHONE) || \ + defined(GTEST_OS_WINDOWS_RT) || defined(ESP_PLATFORM) +inline int DoIsATTY(int /* fd */) { return 0; } +#else +inline int DoIsATTY(int fd) { return _isatty(fd); } +#endif // GTEST_OS_WINDOWS_MOBILE +inline int StrCaseCmp(const char* s1, const char* s2) { + return _stricmp(s1, s2); +} +#endif // __BORLANDC__ + +#else + +inline int DoIsATTY(int fd) { return isatty(fd); } inline int StrCaseCmp(const char* s1, const char* s2) { return strcasecmp(s1, s2); } -inline char* StrDup(const char* src) { return strdup(src); } -inline int RmDir(const char* dir) { return rmdir(dir); } -inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } #endif // GTEST_OS_WINDOWS @@ -2067,30 +2126,32 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_() // ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and // StrError() aren't needed on Windows CE at this time and thus not // defined there. - -#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ - !GTEST_OS_WINDOWS_RT && !GTEST_OS_ESP8266 && !GTEST_OS_XTENSA +#if GTEST_HAS_FILE_SYSTEM +#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_WINDOWS_GAMES) && \ + !defined(GTEST_OS_ESP8266) && !defined(GTEST_OS_XTENSA) && \ + !defined(GTEST_OS_QURT) inline int ChDir(const char* dir) { return chdir(dir); } #endif inline FILE* FOpen(const char* path, const char* mode) { -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW) struct wchar_codecvt : public std::codecvt {}; std::wstring_convert converter; std::wstring wide_path = converter.from_bytes(path); std::wstring wide_mode = converter.from_bytes(mode); return _wfopen(wide_path.c_str(), wide_mode.c_str()); -#else // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW +#else // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW return fopen(path, mode); #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW } -#if !GTEST_OS_WINDOWS_MOBILE -inline FILE *FReopen(const char* path, const char* mode, FILE* stream) { +#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT) +inline FILE* FReopen(const char* path, const char* mode, FILE* stream) { return freopen(path, mode, stream); } inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } -#endif +#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT inline int FClose(FILE* fp) { return fclose(fp); } -#if !GTEST_OS_WINDOWS_MOBILE +#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT) inline int Read(int fd, void* buf, unsigned int count) { return static_cast(read(fd, buf, count)); } @@ -2098,11 +2159,17 @@ inline int Write(int fd, const void* buf, unsigned int count) { return static_cast(write(fd, buf, count)); } inline int Close(int fd) { return close(fd); } +#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT +#endif // GTEST_HAS_FILE_SYSTEM + +#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT) inline const char* StrError(int errnum) { return strerror(errnum); } -#endif +#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT + inline const char* GetEnv(const char* name) { -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ - GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ + defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \ + defined(GTEST_OS_QURT) // We are on an embedded platform, which has no environment variables. static_cast(name); // To prevent 'unused argument' warning. return nullptr; @@ -2118,7 +2185,7 @@ inline const char* GetEnv(const char* name) { GTEST_DISABLE_MSC_DEPRECATED_POP_() -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Windows CE has no C library. The abort() function is used in // several places in Google Test. This implementation provides a reasonable // imitation of standard behaviour. @@ -2134,15 +2201,15 @@ GTEST_DISABLE_MSC_DEPRECATED_POP_() // MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate // function in order to achieve that. We use macro definition here because // snprintf is a variadic function. -#if _MSC_VER && !GTEST_OS_WINDOWS_MOBILE +#if defined(_MSC_VER) && !defined(GTEST_OS_WINDOWS_MOBILE) // MSVC 2005 and above support variadic macros. -# define GTEST_SNPRINTF_(buffer, size, format, ...) \ - _snprintf_s(buffer, size, size, format, __VA_ARGS__) +#define GTEST_SNPRINTF_(buffer, size, format, ...) \ + _snprintf_s(buffer, size, size, format, __VA_ARGS__) #elif defined(_MSC_VER) // Windows CE does not define _snprintf_s -# define GTEST_SNPRINTF_ _snprintf +#define GTEST_SNPRINTF_ _snprintf #else -# define GTEST_SNPRINTF_ snprintf +#define GTEST_SNPRINTF_ snprintf #endif // The biggest signed integer type the compiler supports. @@ -2202,37 +2269,85 @@ using TimeInMillis = int64_t; // Represents time in milliseconds. // Macro for referencing flags. #if !defined(GTEST_FLAG) -# define GTEST_FLAG(name) FLAGS_gtest_##name +#define GTEST_FLAG_NAME_(name) gtest_##name +#define GTEST_FLAG(name) FLAGS_gtest_##name #endif // !defined(GTEST_FLAG) -#if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) -# define GTEST_USE_OWN_FLAGFILE_FLAG_ 1 -#endif // !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) - -#if !defined(GTEST_DECLARE_bool_) -# define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver - -// Macros for declaring flags. -# define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name) -# define GTEST_DECLARE_int32_(name) \ - GTEST_API_ extern std::int32_t GTEST_FLAG(name) -# define GTEST_DECLARE_string_(name) \ - GTEST_API_ extern ::std::string GTEST_FLAG(name) +// Pick a command line flags implementation. +#ifdef GTEST_INTERNAL_HAS_ABSL_FLAGS // Macros for defining flags. -# define GTEST_DEFINE_bool_(name, default_val, doc) \ - GTEST_API_ bool GTEST_FLAG(name) = (default_val) -# define GTEST_DEFINE_int32_(name, default_val, doc) \ - GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val) -# define GTEST_DEFINE_string_(name, default_val, doc) \ - GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val) +#define GTEST_DEFINE_bool_(name, default_val, doc) \ + ABSL_FLAG(bool, GTEST_FLAG_NAME_(name), default_val, doc) +#define GTEST_DEFINE_int32_(name, default_val, doc) \ + ABSL_FLAG(int32_t, GTEST_FLAG_NAME_(name), default_val, doc) +#define GTEST_DEFINE_string_(name, default_val, doc) \ + ABSL_FLAG(std::string, GTEST_FLAG_NAME_(name), default_val, doc) -#endif // !defined(GTEST_DECLARE_bool_) +// Macros for declaring flags. +#define GTEST_DECLARE_bool_(name) \ + ABSL_DECLARE_FLAG(bool, GTEST_FLAG_NAME_(name)) +#define GTEST_DECLARE_int32_(name) \ + ABSL_DECLARE_FLAG(int32_t, GTEST_FLAG_NAME_(name)) +#define GTEST_DECLARE_string_(name) \ + ABSL_DECLARE_FLAG(std::string, GTEST_FLAG_NAME_(name)) + +#define GTEST_FLAG_SAVER_ ::absl::FlagSaver + +#define GTEST_FLAG_GET(name) ::absl::GetFlag(GTEST_FLAG(name)) +#define GTEST_FLAG_SET(name, value) \ + (void)(::absl::SetFlag(>EST_FLAG(name), value)) +#define GTEST_USE_OWN_FLAGFILE_FLAG_ 0 + +#undef GTEST_INTERNAL_HAS_ABSL_FLAGS +#else // ndef GTEST_INTERNAL_HAS_ABSL_FLAGS + +// Macros for defining flags. +#define GTEST_DEFINE_bool_(name, default_val, doc) \ + namespace testing { \ + GTEST_API_ bool GTEST_FLAG(name) = (default_val); \ + } \ + static_assert(true, "no-op to require trailing semicolon") +#define GTEST_DEFINE_int32_(name, default_val, doc) \ + namespace testing { \ + GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val); \ + } \ + static_assert(true, "no-op to require trailing semicolon") +#define GTEST_DEFINE_string_(name, default_val, doc) \ + namespace testing { \ + GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val); \ + } \ + static_assert(true, "no-op to require trailing semicolon") + +// Macros for declaring flags. +#define GTEST_DECLARE_bool_(name) \ + namespace testing { \ + GTEST_API_ extern bool GTEST_FLAG(name); \ + } \ + static_assert(true, "no-op to require trailing semicolon") +#define GTEST_DECLARE_int32_(name) \ + namespace testing { \ + GTEST_API_ extern std::int32_t GTEST_FLAG(name); \ + } \ + static_assert(true, "no-op to require trailing semicolon") +#define GTEST_DECLARE_string_(name) \ + namespace testing { \ + GTEST_API_ extern ::std::string GTEST_FLAG(name); \ + } \ + static_assert(true, "no-op to require trailing semicolon") + +#define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver + +#define GTEST_FLAG_GET(name) ::testing::GTEST_FLAG(name) +#define GTEST_FLAG_SET(name, value) (void)(::testing::GTEST_FLAG(name) = value) +#define GTEST_USE_OWN_FLAGFILE_FLAG_ 1 + +#endif // GTEST_INTERNAL_HAS_ABSL_FLAGS // Thread annotations #if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) -# define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) -# define GTEST_LOCK_EXCLUDED_(locks) +#define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) +#define GTEST_LOCK_EXCLUDED_(locks) #endif // !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) // Parses 'str' for a 32-bit signed integer. If successful, writes the result @@ -2251,27 +2366,7 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val); } // namespace internal } // namespace testing -#if !defined(GTEST_INTERNAL_DEPRECATED) - -// Internal Macro to mark an API deprecated, for googletest usage only -// Usage: class GTEST_INTERNAL_DEPRECATED(message) MyClass or -// GTEST_INTERNAL_DEPRECATED(message) myFunction(); Every usage of -// a deprecated entity will trigger a warning when compiled with -// `-Wdeprecated-declarations` option (clang, gcc, any __GNUC__ compiler). -// For msvc /W3 option will need to be used -// Note that for 'other' compilers this macro evaluates to nothing to prevent -// compilations errors. -#if defined(_MSC_VER) -#define GTEST_INTERNAL_DEPRECATED(message) __declspec(deprecated(message)) -#elif defined(__GNUC__) -#define GTEST_INTERNAL_DEPRECATED(message) __attribute__((deprecated(message))) -#else -#define GTEST_INTERNAL_DEPRECATED(message) -#endif - -#endif // !defined(GTEST_INTERNAL_DEPRECATED) - -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL // Always use absl::any for UniversalPrinter<> specializations if googletest // is built with absl support. #define GTEST_INTERNAL_HAS_ANY 1 @@ -2282,8 +2377,9 @@ using Any = ::absl::any; } // namespace internal } // namespace testing #else -#ifdef __has_include -#if __has_include() && __cplusplus >= 201703L +#if defined(__cpp_lib_any) || (GTEST_INTERNAL_HAS_INCLUDE() && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L && \ + (!defined(_MSC_VER) || GTEST_HAS_RTTI)) // Otherwise for C++17 and higher use std::any for UniversalPrinter<> // specializations. #define GTEST_INTERNAL_HAS_ANY 1 @@ -2295,11 +2391,14 @@ using Any = ::std::any; } // namespace testing // The case where absl is configured NOT to alias std::any is not // supported. -#endif // __has_include() && __cplusplus >= 201703L -#endif // __has_include +#endif // __cpp_lib_any #endif // GTEST_HAS_ABSL -#if GTEST_HAS_ABSL +#ifndef GTEST_INTERNAL_HAS_ANY +#define GTEST_INTERNAL_HAS_ANY 0 +#endif + +#ifdef GTEST_HAS_ABSL // Always use absl::optional for UniversalPrinter<> specializations if // googletest is built with absl support. #define GTEST_INTERNAL_HAS_OPTIONAL 1 @@ -2308,11 +2407,12 @@ namespace testing { namespace internal { template using Optional = ::absl::optional; +inline ::absl::nullopt_t Nullopt() { return ::absl::nullopt; } } // namespace internal } // namespace testing #else -#ifdef __has_include -#if __has_include() && __cplusplus >= 201703L +#if defined(__cpp_lib_optional) || (GTEST_INTERNAL_HAS_INCLUDE() && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L) // Otherwise for C++17 and higher use std::optional for UniversalPrinter<> // specializations. #define GTEST_INTERNAL_HAS_OPTIONAL 1 @@ -2321,18 +2421,31 @@ namespace testing { namespace internal { template using Optional = ::std::optional; +inline ::std::nullopt_t Nullopt() { return ::std::nullopt; } } // namespace internal } // namespace testing // The case where absl is configured NOT to alias std::optional is not // supported. -#endif // __has_include() && __cplusplus >= 201703L -#endif // __has_include +#endif // __cpp_lib_optional #endif // GTEST_HAS_ABSL -#if GTEST_HAS_ABSL +#ifndef GTEST_INTERNAL_HAS_OPTIONAL +#define GTEST_INTERNAL_HAS_OPTIONAL 0 +#endif + +#if defined(__cpp_lib_span) || (GTEST_INTERNAL_HAS_INCLUDE() && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L) +#define GTEST_INTERNAL_HAS_STD_SPAN 1 +#endif // __cpp_lib_span + +#ifndef GTEST_INTERNAL_HAS_STD_SPAN +#define GTEST_INTERNAL_HAS_STD_SPAN 0 +#endif + +#ifdef GTEST_HAS_ABSL // Always use absl::string_view for Matcher<> specializations if googletest // is built with absl support. -# define GTEST_INTERNAL_HAS_STRING_VIEW 1 +#define GTEST_INTERNAL_HAS_STRING_VIEW 1 #include "absl/strings/string_view.h" namespace testing { namespace internal { @@ -2340,11 +2453,12 @@ using StringView = ::absl::string_view; } // namespace internal } // namespace testing #else -# ifdef __has_include -# if __has_include() && __cplusplus >= 201703L +#if defined(__cpp_lib_string_view) || \ + (GTEST_INTERNAL_HAS_INCLUDE() && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L) // Otherwise for C++17 and higher use std::string_view for Matcher<> // specializations. -# define GTEST_INTERNAL_HAS_STRING_VIEW 1 +#define GTEST_INTERNAL_HAS_STRING_VIEW 1 #include namespace testing { namespace internal { @@ -2353,11 +2467,14 @@ using StringView = ::std::string_view; } // namespace testing // The case where absl is configured NOT to alias std::string_view is not // supported. -# endif // __has_include() && __cplusplus >= 201703L -# endif // __has_include +#endif // __cpp_lib_string_view #endif // GTEST_HAS_ABSL -#if GTEST_HAS_ABSL +#ifndef GTEST_INTERNAL_HAS_STRING_VIEW +#define GTEST_INTERNAL_HAS_STRING_VIEW 0 +#endif + +#ifdef GTEST_HAS_ABSL // Always use absl::variant for UniversalPrinter<> specializations if googletest // is built with absl support. #define GTEST_INTERNAL_HAS_VARIANT 1 @@ -2369,8 +2486,8 @@ using Variant = ::absl::variant; } // namespace internal } // namespace testing #else -#ifdef __has_include -#if __has_include() && __cplusplus >= 201703L +#if defined(__cpp_lib_variant) || (GTEST_INTERNAL_HAS_INCLUDE() && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L) // Otherwise for C++17 and higher use std::variant for UniversalPrinter<> // specializations. #define GTEST_INTERNAL_HAS_VARIANT 1 @@ -2382,8 +2499,19 @@ using Variant = ::std::variant; } // namespace internal } // namespace testing // The case where absl is configured NOT to alias std::variant is not supported. -#endif // __has_include() && __cplusplus >= 201703L -#endif // __has_include +#endif // __cpp_lib_variant #endif // GTEST_HAS_ABSL +#ifndef GTEST_INTERNAL_HAS_VARIANT +#define GTEST_INTERNAL_HAS_VARIANT 0 +#endif + +#if (defined(__cpp_lib_three_way_comparison) || \ + (GTEST_INTERNAL_HAS_INCLUDE() && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 201907L)) +#define GTEST_INTERNAL_HAS_COMPARE_LIB 1 +#else +#define GTEST_INTERNAL_HAS_COMPARE_LIB 0 +#endif + #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-string.h b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-string.h index 10f774f966..7c05b58339 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-string.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-string.h @@ -26,7 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// + // The Google C++ Testing and Mocking Framework (Google Test) // // This header file declares the String class and functions used internally by @@ -36,18 +36,22 @@ // This header file is #included by gtest-internal.h. // It should not be #included by other files. -// GOOGLETEST_CM0001 DO NOT DELETE +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ #ifdef __BORLANDC__ // string.h is not guaranteed to provide strcpy on C++ Builder. -# include +#include #endif #include + #include +#include #include #include "gtest/internal/gtest-port.h" @@ -69,7 +73,7 @@ class GTEST_API_ String { // memory using malloc(). static const char* CloneCString(const char* c_str); -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be // able to pass strings to Win32 APIs on CE we need to convert them // to 'Unicode', UTF-16. @@ -123,8 +127,7 @@ class GTEST_API_ String { // Unlike strcasecmp(), this function can handle NULL argument(s). // A NULL C string is considered different to any non-NULL C string, // including the empty string. - static bool CaseInsensitiveCStringEquals(const char* lhs, - const char* rhs); + static bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs); // Compares two wide C strings, ignoring case. Returns true if and only if // they have the same content. @@ -143,8 +146,8 @@ class GTEST_API_ String { // Returns true if and only if the given string ends with the given suffix, // ignoring case. Any string is considered to end with an empty suffix. - static bool EndsWithCaseInsensitive( - const std::string& str, const std::string& suffix); + static bool EndsWithCaseInsensitive(const std::string& str, + const std::string& suffix); // Formats an int value as "%02d". static std::string FormatIntWidth2(int value); // "%02d" for width == 2 @@ -163,7 +166,7 @@ class GTEST_API_ String { private: String(); // Not meant to be instantiated. -}; // class String +}; // class String // Gets the content of the stringstream's buffer as an std::string. Each '\0' // character in the buffer is replaced with "\\0". diff --git a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-type-util.h b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-type-util.h index b87a2e2cac..78da05316d 100644 --- a/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-type-util.h +++ b/libs/libvpx/third_party/googletest/src/include/gtest/internal/gtest-type-util.h @@ -30,20 +30,26 @@ // Type utilities needed for implementing typed and type-parameterized // tests. -// GOOGLETEST_CM0001 DO NOT DELETE +// IWYU pragma: private, include "gtest/gtest.h" +// IWYU pragma: friend gtest/.* +// IWYU pragma: friend gmock/.* #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ +#include +#include +#include + #include "gtest/internal/gtest-port.h" // #ifdef __GNUC__ is too general here. It is possible to use gcc without using // libstdc++ (which is where cxxabi.h comes from). -# if GTEST_HAS_CXXABI_H_ -# include -# elif defined(__HP_aCC) -# include -# endif // GTEST_HASH_CXXABI_H_ +#if GTEST_HAS_CXXABI_H_ +#include +#elif defined(__HP_aCC) +#include +#endif // GTEST_HASH_CXXABI_H_ namespace testing { namespace internal { @@ -61,6 +67,22 @@ inline std::string CanonicalizeForStdLibVersioning(std::string s) { s.erase(strlen("std"), end - strlen("std")); } } + + // Strip redundant spaces in typename to match MSVC + // For example, std::pair -> std::pair + static const char to_search[] = ", "; + const char replace_char = ','; + size_t pos = 0; + while (true) { + // Get the next occurrence from the current position + pos = s.find(to_search, pos); + if (pos == std::string::npos) { + break; + } + // Replace this occurrence of substring + s.replace(pos, strlen(to_search), 1, replace_char); + ++pos; + } return s; } @@ -79,6 +101,20 @@ inline std::string GetTypeName(const std::type_info& type) { const std::string name_str(status == 0 ? readable_name : name); free(readable_name); return CanonicalizeForStdLibVersioning(name_str); +#elif defined(_MSC_VER) + // Strip struct and class due to differences between + // MSVC and other compilers. std::pair is printed as + // "struct std::pair" when using MSVC vs "std::pair" with + // other compilers. + std::string s = name; + // Only strip the leading "struct " and "class ", so uses rfind == 0 to + // ensure that + if (s.rfind("struct ", 0) == 0) { + s = s.substr(strlen("struct ")); + } else if (s.rfind("class ", 0) == 0) { + s = s.substr(strlen("class ")); + } + return s; #else return name; #endif // GTEST_HAS_CXXABI_H_ || __HP_aCC @@ -101,7 +137,9 @@ std::string GetTypeName() { // A unique type indicating an empty node struct None {}; -# define GTEST_TEMPLATE_ template class +#define GTEST_TEMPLATE_ \ + template \ + class // The template "selector" struct TemplateSel is used to // represent Tmpl, which must be a class template with one type @@ -119,8 +157,7 @@ struct TemplateSel { }; }; -# define GTEST_BIND_(TmplSel, T) \ - TmplSel::template Bind::type +#define GTEST_BIND_(TmplSel, T) TmplSel::template Bind::type template struct Templates { diff --git a/libs/libvpx/third_party/googletest/src/src/gtest-all.cc b/libs/libvpx/third_party/googletest/src/src/gtest-all.cc index ad292905cf..2a70ed88c7 100644 --- a/libs/libvpx/third_party/googletest/src/src/gtest-all.cc +++ b/libs/libvpx/third_party/googletest/src/src/gtest-all.cc @@ -38,7 +38,7 @@ #include "gtest/gtest.h" // The following lines pull in the real gtest *.cc files. -#include "src/gtest.cc" +#include "src/gtest-assertion-result.cc" #include "src/gtest-death-test.cc" #include "src/gtest-filepath.cc" #include "src/gtest-matchers.cc" @@ -46,3 +46,4 @@ #include "src/gtest-printers.cc" #include "src/gtest-test-part.cc" #include "src/gtest-typed-test.cc" +#include "src/gtest.cc" diff --git a/libs/libvpx/third_party/googletest/src/src/gtest-assertion-result.cc b/libs/libvpx/third_party/googletest/src/src/gtest-assertion-result.cc new file mode 100644 index 0000000000..3998921674 --- /dev/null +++ b/libs/libvpx/third_party/googletest/src/src/gtest-assertion-result.cc @@ -0,0 +1,77 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// The Google C++ Testing and Mocking Framework (Google Test) +// +// This file defines the AssertionResult type. + +#include "gtest/gtest-assertion-result.h" + +#include +#include + +#include "gtest/gtest-message.h" + +namespace testing { + +// AssertionResult constructors. +// Used in EXPECT_TRUE/FALSE(assertion_result). +AssertionResult::AssertionResult(const AssertionResult& other) + : success_(other.success_), + message_(other.message_ != nullptr + ? new ::std::string(*other.message_) + : static_cast< ::std::string*>(nullptr)) {} + +// Swaps two AssertionResults. +void AssertionResult::swap(AssertionResult& other) { + using std::swap; + swap(success_, other.success_); + swap(message_, other.message_); +} + +// Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. +AssertionResult AssertionResult::operator!() const { + AssertionResult negation(!success_); + if (message_ != nullptr) negation << *message_; + return negation; +} + +// Makes a successful assertion result. +AssertionResult AssertionSuccess() { return AssertionResult(true); } + +// Makes a failed assertion result. +AssertionResult AssertionFailure() { return AssertionResult(false); } + +// Makes a failed assertion result with the given failure message. +// Deprecated; use AssertionFailure() << message. +AssertionResult AssertionFailure(const Message& message) { + return AssertionFailure() << message; +} + +} // namespace testing diff --git a/libs/libvpx/third_party/googletest/src/src/gtest-death-test.cc b/libs/libvpx/third_party/googletest/src/src/gtest-death-test.cc index bf4f6331da..15472f1a79 100644 --- a/libs/libvpx/third_party/googletest/src/src/gtest-death-test.cc +++ b/libs/libvpx/third_party/googletest/src/src/gtest-death-test.cc @@ -32,52 +32,58 @@ #include "gtest/gtest-death-test.h" +#include + #include +#include +#include +#include #include +#include -#include "gtest/internal/gtest-port.h" #include "gtest/internal/custom/gtest.h" +#include "gtest/internal/gtest-port.h" -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST -# if GTEST_OS_MAC -# include -# endif // GTEST_OS_MAC +#ifdef GTEST_OS_MAC +#include +#endif // GTEST_OS_MAC -# include -# include -# include +#include +#include +#include -# if GTEST_OS_LINUX -# include -# endif // GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX +#include +#endif // GTEST_OS_LINUX -# include +#include -# if GTEST_OS_WINDOWS -# include -# else -# include -# include -# endif // GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS +#include +#else +#include +#include +#endif // GTEST_OS_WINDOWS -# if GTEST_OS_QNX -# include -# endif // GTEST_OS_QNX +#ifdef GTEST_OS_QNX +#include +#endif // GTEST_OS_QNX -# if GTEST_OS_FUCHSIA -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# endif // GTEST_OS_FUCHSIA +#ifdef GTEST_OS_FUCHSIA +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // GTEST_OS_FUCHSIA #endif // GTEST_HAS_DEATH_TEST @@ -96,9 +102,12 @@ namespace testing { // used internally at Google, is "threadsafe". static const char kDefaultDeathTestStyle[] = GTEST_DEFAULT_DEATH_TEST_STYLE; +} // namespace testing + GTEST_DEFINE_string_( death_test_style, - internal::StringFromGTestEnv("death_test_style", kDefaultDeathTestStyle), + testing::internal::StringFromGTestEnv("death_test_style", + testing::kDefaultDeathTestStyle), "Indicates how to run a death test in a forked child process: " "\"threadsafe\" (child process re-executes the test binary " "from the beginning, running only the specific death test) or " @@ -107,8 +116,8 @@ GTEST_DEFINE_string_( GTEST_DEFINE_bool_( death_test_use_fork, - internal::BoolFromGTestEnv("death_test_use_fork", false), - "Instructs to use fork()/_exit() instead of clone() in death tests. " + testing::internal::BoolFromGTestEnv("death_test_use_fork", false), + "Instructs to use fork()/_Exit() instead of clone() in death tests. " "Ignored and always uses fork() on POSIX systems where clone() is not " "implemented. Useful when running under valgrind or similar tools if " "those do not support clone(). Valgrind 3.3.1 will just fail if " @@ -117,7 +126,6 @@ GTEST_DEFINE_bool_( "work in 99% of the cases. Once valgrind is fixed, this flag will " "most likely be removed."); -namespace internal { GTEST_DEFINE_string_( internal_run_death_test, "", "Indicates the file, line number, temporal index of " @@ -126,17 +134,18 @@ GTEST_DEFINE_string_( "the '|' characters. This flag is specified if and only if the " "current process is a sub-process launched for running a thread-safe " "death test. FOR INTERNAL USE ONLY."); -} // namespace internal -#if GTEST_HAS_DEATH_TEST +namespace testing { + +#ifdef GTEST_HAS_DEATH_TEST namespace internal { // Valid only for fast death tests. Indicates the code is running in the // child process of a fast style death test. -# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA +#if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA) static bool g_in_fast_death_test_child = false; -# endif +#endif // Returns a Boolean value indicating whether the caller is currently // executing in the context of the death test child process. Tools such as @@ -144,16 +153,16 @@ static bool g_in_fast_death_test_child = false; // tests. IMPORTANT: This is an internal utility. Using it may break the // implementation of death tests. User code MUST NOT use it. bool InDeathTestChild() { -# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA) // On Windows and Fuchsia, death tests are thread-safe regardless of the value // of the death_test_style flag. - return !GTEST_FLAG(internal_run_death_test).empty(); + return !GTEST_FLAG_GET(internal_run_death_test).empty(); -# else +#else - if (GTEST_FLAG(death_test_style) == "threadsafe") - return !GTEST_FLAG(internal_run_death_test).empty(); + if (GTEST_FLAG_GET(death_test_style) == "threadsafe") + return !GTEST_FLAG_GET(internal_run_death_test).empty(); else return g_in_fast_death_test_child; #endif @@ -162,40 +171,38 @@ bool InDeathTestChild() { } // namespace internal // ExitedWithCode constructor. -ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) { -} +ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {} // ExitedWithCode function-call operator. bool ExitedWithCode::operator()(int exit_status) const { -# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA) return exit_status == exit_code_; -# else +#else return WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == exit_code_; -# endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA +#endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA } -# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA +#if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA) // KilledBySignal constructor. -KilledBySignal::KilledBySignal(int signum) : signum_(signum) { -} +KilledBySignal::KilledBySignal(int signum) : signum_(signum) {} // KilledBySignal function-call operator. bool KilledBySignal::operator()(int exit_status) const { -# if defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_) +#if defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_) { bool result; if (GTEST_KILLED_BY_SIGNAL_OVERRIDE_(signum_, exit_status, &result)) { return result; } } -# endif // defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_) +#endif // defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_) return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_; } -# endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA +#endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA namespace internal { @@ -206,23 +213,23 @@ namespace internal { static std::string ExitSummary(int exit_code) { Message m; -# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA) m << "Exited with exit status " << exit_code; -# else +#else if (WIFEXITED(exit_code)) { m << "Exited with exit status " << WEXITSTATUS(exit_code); } else if (WIFSIGNALED(exit_code)) { m << "Terminated by signal " << WTERMSIG(exit_code); } -# ifdef WCOREDUMP +#ifdef WCOREDUMP if (WCOREDUMP(exit_code)) { m << " (core dumped)"; } -# endif -# endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA +#endif +#endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA return m.GetString(); } @@ -233,7 +240,7 @@ bool ExitedUnsuccessfully(int exit_status) { return !ExitedWithCode(0)(exit_status); } -# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA +#if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA) // Generates a textual failure message when a death test finds more than // one thread running, or cannot determine the number of threads, prior // to executing the given statement. It is the responsibility of the @@ -248,13 +255,13 @@ static std::string DeathTestThreadWarning(size_t thread_count) { msg << "detected " << thread_count << " threads."; } msg << " See " - "https://github.com/google/googletest/blob/master/docs/" + "https://github.com/google/googletest/blob/main/docs/" "advanced.md#death-tests-and-threads" << " for more explanation and suggested solutions, especially if" << " this is the last message you see before your test times out."; return msg.GetString(); } -# endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA +#endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA // Flag characters for reporting a death test that did not die. static const char kDeathTestLived = 'L'; @@ -262,7 +269,7 @@ static const char kDeathTestReturned = 'R'; static const char kDeathTestThrew = 'T'; static const char kDeathTestInternalError = 'I'; -#if GTEST_OS_FUCHSIA +#ifdef GTEST_OS_FUCHSIA // File descriptor used for the pipe in the child process. static const int kFuchsiaReadPipeFd = 3; @@ -283,7 +290,7 @@ enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW }; // message is propagated back to the parent process. Otherwise, the // message is simply printed to stderr. In either case, the program // then exits with status 1. -static void DeathTestAbort(const std::string& message) { +[[noreturn]] static void DeathTestAbort(const std::string& message) { // On a POSIX system, this function may be called from a threadsafe-style // death test child process, which operates on a very small stack. Use // the heap for any additional non-minuscule memory requirements. @@ -294,7 +301,7 @@ static void DeathTestAbort(const std::string& message) { fputc(kDeathTestInternalError, parent); fprintf(parent, "%s", message.c_str()); fflush(parent); - _exit(1); + _Exit(1); } else { fprintf(stderr, "%s", message.c_str()); fflush(stderr); @@ -304,14 +311,14 @@ static void DeathTestAbort(const std::string& message) { // A replacement for CHECK that calls DeathTestAbort if the assertion // fails. -# define GTEST_DEATH_TEST_CHECK_(expression) \ - do { \ - if (!::testing::internal::IsTrue(expression)) { \ - DeathTestAbort( \ - ::std::string("CHECK failed: File ") + __FILE__ + ", line " \ - + ::testing::internal::StreamableToString(__LINE__) + ": " \ - + #expression); \ - } \ +#define GTEST_DEATH_TEST_CHECK_(expression) \ + do { \ + if (!::testing::internal::IsTrue(expression)) { \ + DeathTestAbort(::std::string("CHECK failed: File ") + __FILE__ + \ + ", line " + \ + ::testing::internal::StreamableToString(__LINE__) + \ + ": " + #expression); \ + } \ } while (::testing::internal::AlwaysFalse()) // This macro is similar to GTEST_DEATH_TEST_CHECK_, but it is meant for @@ -321,23 +328,23 @@ static void DeathTestAbort(const std::string& message) { // evaluates the expression as long as it evaluates to -1 and sets // errno to EINTR. If the expression evaluates to -1 but errno is // something other than EINTR, DeathTestAbort is called. -# define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \ - do { \ - int gtest_retval; \ - do { \ - gtest_retval = (expression); \ - } while (gtest_retval == -1 && errno == EINTR); \ - if (gtest_retval == -1) { \ - DeathTestAbort( \ - ::std::string("CHECK failed: File ") + __FILE__ + ", line " \ - + ::testing::internal::StreamableToString(__LINE__) + ": " \ - + #expression + " != -1"); \ - } \ +#define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \ + do { \ + int gtest_retval; \ + do { \ + gtest_retval = (expression); \ + } while (gtest_retval == -1 && errno == EINTR); \ + if (gtest_retval == -1) { \ + DeathTestAbort(::std::string("CHECK failed: File ") + __FILE__ + \ + ", line " + \ + ::testing::internal::StreamableToString(__LINE__) + \ + ": " + #expression + " != -1"); \ + } \ } while (::testing::internal::AlwaysFalse()) // Returns the message describing the last system error in errno. std::string GetLastErrnoDescription() { - return errno == 0 ? "" : posix::StrError(errno); + return errno == 0 ? "" : posix::StrError(errno); } // This is called from a death test parent process to read a failure @@ -370,8 +377,9 @@ static void FailFromInternalError(int fd) { DeathTest::DeathTest() { TestInfo* const info = GetUnitTestImpl()->current_test_info(); if (info == nullptr) { - DeathTestAbort("Cannot run a death test outside of a TEST or " - "TEST_F construct"); + DeathTestAbort( + "Cannot run a death test outside of a TEST or " + "TEST_F construct"); } } @@ -500,32 +508,30 @@ void DeathTestImpl::ReadAndInterpretStatusByte() { set_read_fd(-1); } -std::string DeathTestImpl::GetErrorLogs() { - return GetCapturedStderr(); -} +std::string DeathTestImpl::GetErrorLogs() { return GetCapturedStderr(); } // Signals that the death test code which should have exited, didn't. // Should be called only in a death test child process. // Writes a status byte to the child's status file descriptor, then -// calls _exit(1). +// calls _Exit(1). void DeathTestImpl::Abort(AbortReason reason) { // The parent process considers the death test to be a failure if // it finds any data in our pipe. So, here we write a single flag byte // to the pipe, then exit. - const char status_ch = - reason == TEST_DID_NOT_DIE ? kDeathTestLived : - reason == TEST_THREW_EXCEPTION ? kDeathTestThrew : kDeathTestReturned; + const char status_ch = reason == TEST_DID_NOT_DIE ? kDeathTestLived + : reason == TEST_THREW_EXCEPTION ? kDeathTestThrew + : kDeathTestReturned; GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Write(write_fd(), &status_ch, 1)); // We are leaking the descriptor here because on some platforms (i.e., // when built as Windows DLL), destructors of global objects will still - // run after calling _exit(). On such systems, write_fd_ will be + // run after calling _Exit(). On such systems, write_fd_ will be // indirectly closed from the destructor of UnitTestImpl, causing double // close if it is also closed here. On debug configurations, double close // may assert. As there are no in-process buffers to flush here, we are // relying on the OS to close the descriptor after the process terminates // when the destructors are not run. - _exit(1); // Exits w/o any normal exit hooks (we were supposed to crash) + _Exit(1); // Exits w/o any normal exit hooks (we were supposed to crash) } // Returns an indented copy of stderr output for a death test. @@ -533,7 +539,7 @@ void DeathTestImpl::Abort(AbortReason reason) { // much easier. static ::std::string FormatDeathTestOutput(const ::std::string& output) { ::std::string ret; - for (size_t at = 0; ; ) { + for (size_t at = 0;;) { const size_t line_end = output.find('\n', at); ret += "[ DEATH ] "; if (line_end == ::std::string::npos) { @@ -568,8 +574,7 @@ static ::std::string FormatDeathTestOutput(const ::std::string& output) { // the first failing condition, in the order given above, is the one that is // reported. Also sets the last death test message string. bool DeathTestImpl::Passed(bool status_ok) { - if (!spawned()) - return false; + if (!spawned()) return false; const std::string error_message = GetErrorLogs(); @@ -580,15 +585,18 @@ bool DeathTestImpl::Passed(bool status_ok) { switch (outcome()) { case LIVED: buffer << " Result: failed to die.\n" - << " Error msg:\n" << FormatDeathTestOutput(error_message); + << " Error msg:\n" + << FormatDeathTestOutput(error_message); break; case THREW: buffer << " Result: threw an exception.\n" - << " Error msg:\n" << FormatDeathTestOutput(error_message); + << " Error msg:\n" + << FormatDeathTestOutput(error_message); break; case RETURNED: buffer << " Result: illegal return in test statement.\n" - << " Error msg:\n" << FormatDeathTestOutput(error_message); + << " Error msg:\n" + << FormatDeathTestOutput(error_message); break; case DIED: if (status_ok) { @@ -605,7 +613,8 @@ bool DeathTestImpl::Passed(bool status_ok) { } else { buffer << " Result: died but not with expected exit code:\n" << " " << ExitSummary(status()) << "\n" - << "Actual msg:\n" << FormatDeathTestOutput(error_message); + << "Actual msg:\n" + << FormatDeathTestOutput(error_message); } break; case IN_PROGRESS: @@ -618,7 +627,21 @@ bool DeathTestImpl::Passed(bool status_ok) { return success; } -# if GTEST_OS_WINDOWS +#ifndef GTEST_OS_WINDOWS +// Note: The return value points into args, so the return value's lifetime is +// bound to that of args. +static std::vector CreateArgvFromArgs(std::vector& args) { + std::vector result; + result.reserve(args.size() + 1); + for (auto& arg : args) { + result.push_back(&arg[0]); + } + result.push_back(nullptr); // Extra null terminator. + return result; +} +#endif + +#ifdef GTEST_OS_WINDOWS // WindowsDeathTest implements death tests on Windows. Due to the // specifics of starting new processes on Windows, death tests there are // always threadsafe, and Google Test considers the @@ -679,14 +702,12 @@ class WindowsDeathTest : public DeathTestImpl { // status, or 0 if no child process exists. As a side effect, sets the // outcome data member. int WindowsDeathTest::Wait() { - if (!spawned()) - return 0; + if (!spawned()) return 0; // Wait until the child either signals that it has acquired the write end // of the pipe or it dies. - const HANDLE wait_handles[2] = { child_handle_.Get(), event_handle_.Get() }; - switch (::WaitForMultipleObjects(2, - wait_handles, + const HANDLE wait_handles[2] = {child_handle_.Get(), event_handle_.Get()}; + switch (::WaitForMultipleObjects(2, wait_handles, FALSE, // Waits for any of the handles. INFINITE)) { case WAIT_OBJECT_0: @@ -707,9 +728,8 @@ int WindowsDeathTest::Wait() { // returns immediately if the child has already exited, regardless of // whether previous calls to WaitForMultipleObjects synchronized on this // handle or not. - GTEST_DEATH_TEST_CHECK_( - WAIT_OBJECT_0 == ::WaitForSingleObject(child_handle_.Get(), - INFINITE)); + GTEST_DEATH_TEST_CHECK_(WAIT_OBJECT_0 == + ::WaitForSingleObject(child_handle_.Get(), INFINITE)); DWORD status_code; GTEST_DEATH_TEST_CHECK_( ::GetExitCodeProcess(child_handle_.Get(), &status_code) != FALSE); @@ -742,12 +762,12 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { SECURITY_ATTRIBUTES handles_are_inheritable = {sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE}; HANDLE read_handle, write_handle; - GTEST_DEATH_TEST_CHECK_( - ::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable, - 0) // Default buffer size. - != FALSE); - set_read_fd(::_open_osfhandle(reinterpret_cast(read_handle), - O_RDONLY)); + GTEST_DEATH_TEST_CHECK_(::CreatePipe(&read_handle, &write_handle, + &handles_are_inheritable, + 0) // Default buffer size. + != FALSE); + set_read_fd( + ::_open_osfhandle(reinterpret_cast(read_handle), O_RDONLY)); write_handle_.Reset(write_handle); event_handle_.Reset(::CreateEvent( &handles_are_inheritable, @@ -756,27 +776,26 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { nullptr)); // The even is unnamed. GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != nullptr); const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ + - kFilterFlag + "=" + info->test_suite_name() + - "." + info->name(); + "filter=" + info->test_suite_name() + "." + + info->name(); const std::string internal_flag = - std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + - "=" + file_ + "|" + StreamableToString(line_) + "|" + - StreamableToString(death_test_index) + "|" + + std::string("--") + GTEST_FLAG_PREFIX_ + + "internal_run_death_test=" + file_ + "|" + StreamableToString(line_) + + "|" + StreamableToString(death_test_index) + "|" + StreamableToString(static_cast(::GetCurrentProcessId())) + // size_t has the same width as pointers on both 32-bit and 64-bit // Windows platforms. - // See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx. - "|" + StreamableToString(reinterpret_cast(write_handle)) + - "|" + StreamableToString(reinterpret_cast(event_handle_.Get())); + // See https://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx. + "|" + StreamableToString(reinterpret_cast(write_handle)) + "|" + + StreamableToString(reinterpret_cast(event_handle_.Get())); char executable_path[_MAX_PATH + 1]; // NOLINT GTEST_DEATH_TEST_CHECK_(_MAX_PATH + 1 != ::GetModuleFileNameA(nullptr, executable_path, _MAX_PATH)); - std::string command_line = - std::string(::GetCommandLineA()) + " " + filter_flag + " \"" + - internal_flag + "\""; + std::string command_line = std::string(::GetCommandLineA()) + " " + + filter_flag + " \"" + internal_flag + "\""; DeathTest::set_last_death_test_message(""); @@ -796,8 +815,8 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { GTEST_DEATH_TEST_CHECK_( ::CreateProcessA( executable_path, const_cast(command_line.c_str()), - nullptr, // Retuned process handle is not inheritable. - nullptr, // Retuned thread handle is not inheritable. + nullptr, // Returned process handle is not inheritable. + nullptr, // Returned thread handle is not inheritable. TRUE, // Child inherits all inheritable handles (for write_handle_). 0x0, // Default creation flags. nullptr, // Inherit the parent's environment. @@ -809,7 +828,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { return OVERSEE_TEST; } -# elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) class FuchsiaDeathTest : public DeathTestImpl { public: @@ -837,41 +856,6 @@ class FuchsiaDeathTest : public DeathTestImpl { zx::socket stderr_socket_; }; -// Utility class for accumulating command-line arguments. -class Arguments { - public: - Arguments() { args_.push_back(nullptr); } - - ~Arguments() { - for (std::vector::iterator i = args_.begin(); i != args_.end(); - ++i) { - free(*i); - } - } - void AddArgument(const char* argument) { - args_.insert(args_.end() - 1, posix::StrDup(argument)); - } - - template - void AddArguments(const ::std::vector& arguments) { - for (typename ::std::vector::const_iterator i = arguments.begin(); - i != arguments.end(); - ++i) { - args_.insert(args_.end() - 1, posix::StrDup(i->c_str())); - } - } - char* const* Argv() { - return &args_[0]; - } - - int size() { - return static_cast(args_.size()) - 1; - } - - private: - std::vector args_; -}; - // Waits for the child in a death test to exit, returning its exit // status, or 0 if no child process exists. As a side effect, sets the // outcome data member. @@ -880,8 +864,7 @@ int FuchsiaDeathTest::Wait() { const int kSocketKey = 1; const int kExceptionKey = 2; - if (!spawned()) - return 0; + if (!spawned()) return 0; // Create a port to wait for socket/task/exception events. zx_status_t status_zx; @@ -890,8 +873,8 @@ int FuchsiaDeathTest::Wait() { GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK); // Register to wait for the child process to terminate. - status_zx = child_process_.wait_async( - port, kProcessKey, ZX_PROCESS_TERMINATED, 0); + status_zx = + child_process_.wait_async(port, kProcessKey, ZX_PROCESS_TERMINATED, 0); GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK); // Register to wait for the socket to be readable or closed. @@ -900,8 +883,8 @@ int FuchsiaDeathTest::Wait() { GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK); // Register to wait for an exception. - status_zx = exception_channel_.wait_async( - port, kExceptionKey, ZX_CHANNEL_READABLE, 0); + status_zx = exception_channel_.wait_async(port, kExceptionKey, + ZX_CHANNEL_READABLE, 0); GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK); bool process_terminated = false; @@ -931,9 +914,9 @@ int FuchsiaDeathTest::Wait() { size_t old_length = captured_stderr_.length(); size_t bytes_read = 0; captured_stderr_.resize(old_length + kBufferSize); - status_zx = stderr_socket_.read( - 0, &captured_stderr_.front() + old_length, kBufferSize, - &bytes_read); + status_zx = + stderr_socket_.read(0, &captured_stderr_.front() + old_length, + kBufferSize, &bytes_read); captured_stderr_.resize(old_length + bytes_read); } while (status_zx == ZX_OK); if (status_zx == ZX_ERR_PEER_CLOSED) { @@ -987,17 +970,16 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { // Build the child process command line. const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ + - kFilterFlag + "=" + info->test_suite_name() + - "." + info->name(); - const std::string internal_flag = - std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "=" - + file_ + "|" - + StreamableToString(line_) + "|" - + StreamableToString(death_test_index); - Arguments args; - args.AddArguments(GetInjectableArgvs()); - args.AddArgument(filter_flag.c_str()); - args.AddArgument(internal_flag.c_str()); + "filter=" + info->test_suite_name() + "." + + info->name(); + const std::string internal_flag = std::string("--") + GTEST_FLAG_PREFIX_ + + kInternalRunDeathTestFlag + "=" + file_ + + "|" + StreamableToString(line_) + "|" + + StreamableToString(death_test_index); + + std::vector args = GetInjectableArgvs(); + args.push_back(filter_flag); + args.push_back(internal_flag); // Build the pipe for communication with the child. zx_status_t status; @@ -1016,8 +998,7 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { // Create a socket pair will be used to receive the child process' stderr. zx::socket stderr_producer_socket; - status = - zx::socket::create(0, &stderr_producer_socket, &stderr_socket_); + status = zx::socket::create(0, &stderr_producer_socket, &stderr_socket_); GTEST_DEATH_TEST_CHECK_(status >= 0); int stderr_producer_fd = -1; status = @@ -1034,35 +1015,38 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { // Create a child job. zx_handle_t child_job = ZX_HANDLE_INVALID; - status = zx_job_create(zx_job_default(), 0, & child_job); + status = zx_job_create(zx_job_default(), 0, &child_job); GTEST_DEATH_TEST_CHECK_(status == ZX_OK); zx_policy_basic_t policy; policy.condition = ZX_POL_NEW_ANY; policy.policy = ZX_POL_ACTION_ALLOW; - status = zx_job_set_policy( - child_job, ZX_JOB_POL_RELATIVE, ZX_JOB_POL_BASIC, &policy, 1); + status = zx_job_set_policy(child_job, ZX_JOB_POL_RELATIVE, ZX_JOB_POL_BASIC, + &policy, 1); GTEST_DEATH_TEST_CHECK_(status == ZX_OK); // Create an exception channel attached to the |child_job|, to allow // us to suppress the system default exception handler from firing. - status = - zx_task_create_exception_channel( - child_job, 0, exception_channel_.reset_and_get_address()); + status = zx_task_create_exception_channel( + child_job, 0, exception_channel_.reset_and_get_address()); GTEST_DEATH_TEST_CHECK_(status == ZX_OK); // Spawn the child process. - status = fdio_spawn_etc( - child_job, FDIO_SPAWN_CLONE_ALL, args.Argv()[0], args.Argv(), nullptr, - 2, spawn_actions, child_process_.reset_and_get_address(), nullptr); + // Note: The test component must have `fuchsia.process.Launcher` declared + // in its manifest. (Fuchsia integration tests require creating a + // "Fuchsia Test Component" which contains a "Fuchsia Component Manifest") + // Launching processes is a privileged operation in Fuchsia, and the + // declaration indicates that the ability is required for the component. + std::vector argv = CreateArgvFromArgs(args); + status = fdio_spawn_etc(child_job, FDIO_SPAWN_CLONE_ALL, argv[0], argv.data(), + nullptr, 2, spawn_actions, + child_process_.reset_and_get_address(), nullptr); GTEST_DEATH_TEST_CHECK_(status == ZX_OK); set_spawned(true); return OVERSEE_TEST; } -std::string FuchsiaDeathTest::GetErrorLogs() { - return captured_stderr_; -} +std::string FuchsiaDeathTest::GetErrorLogs() { return captured_stderr_; } #else // We are neither on Windows, nor on Fuchsia. @@ -1093,8 +1077,7 @@ ForkingDeathTest::ForkingDeathTest(const char* a_statement, // status, or 0 if no child process exists. As a side effect, sets the // outcome data member. int ForkingDeathTest::Wait() { - if (!spawned()) - return 0; + if (!spawned()) return 0; ReadAndInterpretStatusByte(); @@ -1147,7 +1130,7 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() { LogToStderr(); // Event forwarding to the listeners of event listener API mush be shut // down in death test subprocesses. - GetUnitTestImpl()->listeners()->SuppressEventForwarding(); + GetUnitTestImpl()->listeners()->SuppressEventForwarding(true); g_in_fast_death_test_child = true; return EXECUTE_TEST; } else { @@ -1173,11 +1156,11 @@ class ExecDeathTest : public ForkingDeathTest { private: static ::std::vector GetArgvsForDeathTestChildProcess() { ::std::vector args = GetInjectableArgvs(); -# if defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_) +#if defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_) ::std::vector extra_args = GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_(); args.insert(args.end(), extra_args.begin(), extra_args.end()); -# endif // defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_) +#endif // defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_) return args; } // The name of the file in which the death test is located. @@ -1186,37 +1169,6 @@ class ExecDeathTest : public ForkingDeathTest { const int line_; }; -// Utility class for accumulating command-line arguments. -class Arguments { - public: - Arguments() { args_.push_back(nullptr); } - - ~Arguments() { - for (std::vector::iterator i = args_.begin(); i != args_.end(); - ++i) { - free(*i); - } - } - void AddArgument(const char* argument) { - args_.insert(args_.end() - 1, posix::StrDup(argument)); - } - - template - void AddArguments(const ::std::vector& arguments) { - for (typename ::std::vector::const_iterator i = arguments.begin(); - i != arguments.end(); - ++i) { - args_.insert(args_.end() - 1, posix::StrDup(i->c_str())); - } - } - char* const* Argv() { - return &args_[0]; - } - - private: - std::vector args_; -}; - // A struct that encompasses the arguments to the child process of a // threadsafe-style death test process. struct ExecDeathTestArgs { @@ -1224,9 +1176,9 @@ struct ExecDeathTestArgs { int close_fd; // File descriptor to close; the read end of a pipe }; -# if GTEST_OS_QNX +#ifdef GTEST_OS_QNX extern "C" char** environ; -# else // GTEST_OS_QNX +#else // GTEST_OS_QNX // The main function for a threadsafe-style death test child process. // This function is called in a clone()-ed process and thus must avoid // any potentially unsafe operations like malloc or libc functions. @@ -1241,8 +1193,8 @@ static int ExecDeathTestChildMain(void* child_arg) { UnitTest::GetInstance()->original_working_dir(); // We can safely call chdir() as it's a direct system call. if (chdir(original_dir) != 0) { - DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " + - GetLastErrnoDescription()); + DeathTestAbort(std::string("chdir(\"") + original_dir + + "\") failed: " + GetLastErrnoDescription()); return EXIT_FAILURE; } @@ -1253,13 +1205,12 @@ static int ExecDeathTestChildMain(void* child_arg) { // one path separator. execv(args->argv[0], args->argv); DeathTestAbort(std::string("execv(") + args->argv[0] + ", ...) in " + - original_dir + " failed: " + - GetLastErrnoDescription()); + original_dir + " failed: " + GetLastErrnoDescription()); return EXIT_FAILURE; } -# endif // GTEST_OS_QNX +#endif // GTEST_OS_QNX -# if GTEST_HAS_CLONE +#if GTEST_HAS_CLONE // Two utility routines that together determine the direction the stack // grows. // This could be accomplished more elegantly by a single recursive @@ -1293,7 +1244,7 @@ static bool StackGrowsDown() { StackLowerThanAddress(&dummy, &result); return result; } -# endif // GTEST_HAS_CLONE +#endif // GTEST_HAS_CLONE // Spawns a child process with the same executable as the current process in // a thread-safe manner and instructs it to run the death test. The @@ -1303,10 +1254,10 @@ static bool StackGrowsDown() { // spawn(2) there instead. The function dies with an error message if // anything goes wrong. static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { - ExecDeathTestArgs args = { argv, close_fd }; + ExecDeathTestArgs args = {argv, close_fd}; pid_t child_pid = -1; -# if GTEST_OS_QNX +#ifdef GTEST_OS_QNX // Obtains the current directory and sets it to be closed in the child // process. const int cwd_fd = open(".", O_RDONLY); @@ -1319,16 +1270,16 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { UnitTest::GetInstance()->original_working_dir(); // We can safely call chdir() as it's a direct system call. if (chdir(original_dir) != 0) { - DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " + - GetLastErrnoDescription()); + DeathTestAbort(std::string("chdir(\"") + original_dir + + "\") failed: " + GetLastErrnoDescription()); return EXIT_FAILURE; } int fd_flags; // Set close_fd to be closed after spawn. GTEST_DEATH_TEST_CHECK_SYSCALL_(fd_flags = fcntl(close_fd, F_GETFD)); - GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(close_fd, F_SETFD, - fd_flags | FD_CLOEXEC)); + GTEST_DEATH_TEST_CHECK_SYSCALL_( + fcntl(close_fd, F_SETFD, fd_flags | FD_CLOEXEC)); struct inheritance inherit = {0}; // spawn is a system call. child_pid = spawn(args.argv[0], 0, nullptr, &inherit, args.argv, environ); @@ -1336,8 +1287,8 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { GTEST_DEATH_TEST_CHECK_(fchdir(cwd_fd) != -1); GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd)); -# else // GTEST_OS_QNX -# if GTEST_OS_LINUX +#else // GTEST_OS_QNX +#ifdef GTEST_OS_LINUX // When a SIGPROF signal is received while fork() or clone() are executing, // the process may hang. To avoid this, we ignore SIGPROF here and re-enable // it after the call to fork()/clone() is complete. @@ -1346,12 +1297,12 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { memset(&ignore_sigprof_action, 0, sizeof(ignore_sigprof_action)); sigemptyset(&ignore_sigprof_action.sa_mask); ignore_sigprof_action.sa_handler = SIG_IGN; - GTEST_DEATH_TEST_CHECK_SYSCALL_(sigaction( - SIGPROF, &ignore_sigprof_action, &saved_sigprof_action)); -# endif // GTEST_OS_LINUX + GTEST_DEATH_TEST_CHECK_SYSCALL_( + sigaction(SIGPROF, &ignore_sigprof_action, &saved_sigprof_action)); +#endif // GTEST_OS_LINUX -# if GTEST_HAS_CLONE - const bool use_fork = GTEST_FLAG(death_test_use_fork); +#if GTEST_HAS_CLONE + const bool use_fork = GTEST_FLAG_GET(death_test_use_fork); if (!use_fork) { static const bool stack_grows_down = StackGrowsDown(); @@ -1370,7 +1321,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { const size_t kMaxStackAlignment = 64; void* const stack_top = static_cast(stack) + - (stack_grows_down ? stack_size - kMaxStackAlignment : 0); + (stack_grows_down ? stack_size - kMaxStackAlignment : 0); GTEST_DEATH_TEST_CHECK_( static_cast(stack_size) > kMaxStackAlignment && reinterpret_cast(stack_top) % kMaxStackAlignment == 0); @@ -1379,19 +1330,18 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1); } -# else +#else const bool use_fork = true; -# endif // GTEST_HAS_CLONE +#endif // GTEST_HAS_CLONE if (use_fork && (child_pid = fork()) == 0) { - ExecDeathTestChildMain(&args); - _exit(0); + _Exit(ExecDeathTestChildMain(&args)); } -# endif // GTEST_OS_QNX -# if GTEST_OS_LINUX +#endif // GTEST_OS_QNX +#ifdef GTEST_OS_LINUX GTEST_DEATH_TEST_CHECK_SYSCALL_( sigaction(SIGPROF, &saved_sigprof_action, nullptr)); -# endif // GTEST_OS_LINUX +#endif // GTEST_OS_LINUX GTEST_DEATH_TEST_CHECK_(child_pid != -1); return child_pid; @@ -1420,17 +1370,16 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1); const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ + - kFilterFlag + "=" + info->test_suite_name() + - "." + info->name(); - const std::string internal_flag = - std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "=" - + file_ + "|" + StreamableToString(line_) + "|" - + StreamableToString(death_test_index) + "|" - + StreamableToString(pipe_fd[1]); - Arguments args; - args.AddArguments(GetArgvsForDeathTestChildProcess()); - args.AddArgument(filter_flag.c_str()); - args.AddArgument(internal_flag.c_str()); + "filter=" + info->test_suite_name() + "." + + info->name(); + const std::string internal_flag = std::string("--") + GTEST_FLAG_PREFIX_ + + "internal_run_death_test=" + file_ + "|" + + StreamableToString(line_) + "|" + + StreamableToString(death_test_index) + "|" + + StreamableToString(pipe_fd[1]); + std::vector args = GetArgvsForDeathTestChildProcess(); + args.push_back(filter_flag); + args.push_back(internal_flag); DeathTest::set_last_death_test_message(""); @@ -1439,7 +1388,8 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { // is necessary. FlushInfoLog(); - const pid_t child_pid = ExecDeathTestSpawnChild(args.Argv(), pipe_fd[0]); + std::vector argv = CreateArgvFromArgs(args); + const pid_t child_pid = ExecDeathTestSpawnChild(argv.data(), pipe_fd[0]); GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1])); set_child_pid(child_pid); set_read_fd(pipe_fd[0]); @@ -1447,7 +1397,7 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { return OVERSEE_TEST; } -# endif // !GTEST_OS_WINDOWS +#endif // !GTEST_OS_WINDOWS // Creates a concrete DeathTest-derived class that depends on the // --gtest_death_test_style flag, and sets the pointer pointed to @@ -1461,15 +1411,15 @@ bool DefaultDeathTestFactory::Create(const char* statement, UnitTestImpl* const impl = GetUnitTestImpl(); const InternalRunDeathTestFlag* const flag = impl->internal_run_death_test_flag(); - const int death_test_index = impl->current_test_info() - ->increment_death_test_count(); + const int death_test_index = + impl->current_test_info()->increment_death_test_count(); if (flag != nullptr) { if (death_test_index > flag->index()) { DeathTest::set_last_death_test_message( - "Death test count (" + StreamableToString(death_test_index) - + ") somehow exceeded expected maximum (" - + StreamableToString(flag->index()) + ")"); + "Death test count (" + StreamableToString(death_test_index) + + ") somehow exceeded expected maximum (" + + StreamableToString(flag->index()) + ")"); return false; } @@ -1480,50 +1430,50 @@ bool DefaultDeathTestFactory::Create(const char* statement, } } -# if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS - if (GTEST_FLAG(death_test_style) == "threadsafe" || - GTEST_FLAG(death_test_style) == "fast") { + if (GTEST_FLAG_GET(death_test_style) == "threadsafe" || + GTEST_FLAG_GET(death_test_style) == "fast") { *test = new WindowsDeathTest(statement, std::move(matcher), file, line); } -# elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) - if (GTEST_FLAG(death_test_style) == "threadsafe" || - GTEST_FLAG(death_test_style) == "fast") { + if (GTEST_FLAG_GET(death_test_style) == "threadsafe" || + GTEST_FLAG_GET(death_test_style) == "fast") { *test = new FuchsiaDeathTest(statement, std::move(matcher), file, line); } -# else +#else - if (GTEST_FLAG(death_test_style) == "threadsafe") { + if (GTEST_FLAG_GET(death_test_style) == "threadsafe") { *test = new ExecDeathTest(statement, std::move(matcher), file, line); - } else if (GTEST_FLAG(death_test_style) == "fast") { + } else if (GTEST_FLAG_GET(death_test_style) == "fast") { *test = new NoExecDeathTest(statement, std::move(matcher)); } -# endif // GTEST_OS_WINDOWS +#endif // GTEST_OS_WINDOWS else { // NOLINT - this is more readable than unbalanced brackets inside #if. - DeathTest::set_last_death_test_message( - "Unknown death test style \"" + GTEST_FLAG(death_test_style) - + "\" encountered"); + DeathTest::set_last_death_test_message("Unknown death test style \"" + + GTEST_FLAG_GET(death_test_style) + + "\" encountered"); return false; } return true; } -# if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Recreates the pipe and event handles from the provided parameters, // signals the event, and returns a file descriptor wrapped around the pipe // handle. This function is called in the child process only. static int GetStatusFileDescriptor(unsigned int parent_process_id, - size_t write_handle_as_size_t, - size_t event_handle_as_size_t) { + size_t write_handle_as_size_t, + size_t event_handle_as_size_t) { AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE, - FALSE, // Non-inheritable. - parent_process_id)); + FALSE, // Non-inheritable. + parent_process_id)); if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) { DeathTestAbort("Unable to open parent process " + StreamableToString(parent_process_id)); @@ -1531,8 +1481,7 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id, GTEST_CHECK_(sizeof(HANDLE) <= sizeof(size_t)); - const HANDLE write_handle = - reinterpret_cast(write_handle_as_size_t); + const HANDLE write_handle = reinterpret_cast(write_handle_as_size_t); HANDLE dup_write_handle; // The newly initialized handle is accessible only in the parent @@ -1554,9 +1503,7 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id, HANDLE dup_event_handle; if (!::DuplicateHandle(parent_process_handle.Get(), event_handle, - ::GetCurrentProcess(), &dup_event_handle, - 0x0, - FALSE, + ::GetCurrentProcess(), &dup_event_handle, 0x0, FALSE, DUPLICATE_SAME_ACCESS)) { DeathTestAbort("Unable to duplicate the event handle " + StreamableToString(event_handle_as_size_t) + @@ -1578,61 +1525,57 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id, return write_fd; } -# endif // GTEST_OS_WINDOWS +#endif // GTEST_OS_WINDOWS // Returns a newly created InternalRunDeathTestFlag object with fields // initialized from the GTEST_FLAG(internal_run_death_test) flag if // the flag is specified; otherwise returns NULL. InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { - if (GTEST_FLAG(internal_run_death_test) == "") return nullptr; + if (GTEST_FLAG_GET(internal_run_death_test).empty()) return nullptr; // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we // can use it here. int line = -1; int index = -1; ::std::vector< ::std::string> fields; - SplitString(GTEST_FLAG(internal_run_death_test).c_str(), '|', &fields); + SplitString(GTEST_FLAG_GET(internal_run_death_test), '|', &fields); int write_fd = -1; -# if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS unsigned int parent_process_id = 0; size_t write_handle_as_size_t = 0; size_t event_handle_as_size_t = 0; - if (fields.size() != 6 - || !ParseNaturalNumber(fields[1], &line) - || !ParseNaturalNumber(fields[2], &index) - || !ParseNaturalNumber(fields[3], &parent_process_id) - || !ParseNaturalNumber(fields[4], &write_handle_as_size_t) - || !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) { + if (fields.size() != 6 || !ParseNaturalNumber(fields[1], &line) || + !ParseNaturalNumber(fields[2], &index) || + !ParseNaturalNumber(fields[3], &parent_process_id) || + !ParseNaturalNumber(fields[4], &write_handle_as_size_t) || + !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) { DeathTestAbort("Bad --gtest_internal_run_death_test flag: " + - GTEST_FLAG(internal_run_death_test)); + GTEST_FLAG_GET(internal_run_death_test)); } - write_fd = GetStatusFileDescriptor(parent_process_id, - write_handle_as_size_t, + write_fd = GetStatusFileDescriptor(parent_process_id, write_handle_as_size_t, event_handle_as_size_t); -# elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) - if (fields.size() != 3 - || !ParseNaturalNumber(fields[1], &line) - || !ParseNaturalNumber(fields[2], &index)) { - DeathTestAbort("Bad --gtest_internal_run_death_test flag: " - + GTEST_FLAG(internal_run_death_test)); + if (fields.size() != 3 || !ParseNaturalNumber(fields[1], &line) || + !ParseNaturalNumber(fields[2], &index)) { + DeathTestAbort("Bad --gtest_internal_run_death_test flag: " + + GTEST_FLAG_GET(internal_run_death_test)); } -# else +#else - if (fields.size() != 4 - || !ParseNaturalNumber(fields[1], &line) - || !ParseNaturalNumber(fields[2], &index) - || !ParseNaturalNumber(fields[3], &write_fd)) { - DeathTestAbort("Bad --gtest_internal_run_death_test flag: " - + GTEST_FLAG(internal_run_death_test)); + if (fields.size() != 4 || !ParseNaturalNumber(fields[1], &line) || + !ParseNaturalNumber(fields[2], &index) || + !ParseNaturalNumber(fields[3], &write_fd)) { + DeathTestAbort("Bad --gtest_internal_run_death_test flag: " + + GTEST_FLAG_GET(internal_run_death_test)); } -# endif // GTEST_OS_WINDOWS +#endif // GTEST_OS_WINDOWS return new InternalRunDeathTestFlag(fields[0], line, index, write_fd); } diff --git a/libs/libvpx/third_party/googletest/src/src/gtest-filepath.cc b/libs/libvpx/third_party/googletest/src/src/gtest-filepath.cc index 0b5629401b..902d8c7f64 100644 --- a/libs/libvpx/third_party/googletest/src/src/gtest-filepath.cc +++ b/libs/libvpx/third_party/googletest/src/src/gtest-filepath.cc @@ -30,35 +30,42 @@ #include "gtest/internal/gtest-filepath.h" #include -#include "gtest/internal/gtest-port.h" -#include "gtest/gtest-message.h" -#if GTEST_OS_WINDOWS_MOBILE -# include -#elif GTEST_OS_WINDOWS -# include -# include +#include +#include + +#include "gtest/gtest-message.h" +#include "gtest/internal/gtest-port.h" + +#ifdef GTEST_OS_WINDOWS_MOBILE +#include +#elif defined(GTEST_OS_WINDOWS) +#include +#include #else -# include -# include // Some Linux distributions define PATH_MAX here. -#endif // GTEST_OS_WINDOWS_MOBILE +#include + +#include // Some Linux distributions define PATH_MAX here. +#endif // GTEST_OS_WINDOWS_MOBILE #include "gtest/internal/gtest-string.h" -#if GTEST_OS_WINDOWS -# define GTEST_PATH_MAX_ _MAX_PATH +#ifdef GTEST_OS_WINDOWS +#define GTEST_PATH_MAX_ _MAX_PATH #elif defined(PATH_MAX) -# define GTEST_PATH_MAX_ PATH_MAX +#define GTEST_PATH_MAX_ PATH_MAX #elif defined(_XOPEN_PATH_MAX) -# define GTEST_PATH_MAX_ _XOPEN_PATH_MAX +#define GTEST_PATH_MAX_ _XOPEN_PATH_MAX #else -# define GTEST_PATH_MAX_ _POSIX_PATH_MAX +#define GTEST_PATH_MAX_ _POSIX_PATH_MAX #endif // GTEST_OS_WINDOWS +#if GTEST_HAS_FILE_SYSTEM + namespace testing { namespace internal { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // On Windows, '\\' is the standard path separator, but many tools and the // Windows API also accept '/' as an alternate path separator. Unless otherwise // noted, a file path can contain either kind of path separators, or a mixture @@ -66,16 +73,16 @@ namespace internal { const char kPathSeparator = '\\'; const char kAlternatePathSeparator = '/'; const char kAlternatePathSeparatorString[] = "/"; -# if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Windows CE doesn't have a current directory. You should not use // the current directory in tests on Windows CE, but this at least // provides a reasonable fallback. const char kCurrentDirectoryString[] = "\\"; // Windows CE doesn't define INVALID_FILE_ATTRIBUTES const DWORD kInvalidFileAttributes = 0xffffffff; -# else +#else const char kCurrentDirectoryString[] = ".\\"; -# endif // GTEST_OS_WINDOWS_MOBILE +#endif // GTEST_OS_WINDOWS_MOBILE #else const char kPathSeparator = '/'; const char kCurrentDirectoryString[] = "./"; @@ -92,24 +99,26 @@ static bool IsPathSeparator(char c) { // Returns the current working directory, or "" if unsuccessful. FilePath FilePath::GetCurrentDir() { -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ - GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 || \ - GTEST_OS_XTENSA +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ + defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \ + defined(GTEST_OS_ESP32) || defined(GTEST_OS_XTENSA) || \ + defined(GTEST_OS_QURT) || defined(GTEST_OS_NXP_QN9090) || \ + defined(GTEST_OS_NRF52) // These platforms do not have a current directory, so we just return // something reasonable. return FilePath(kCurrentDirectoryString); -#elif GTEST_OS_WINDOWS - char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; +#elif defined(GTEST_OS_WINDOWS) + char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd); #else - char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; + char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; char* result = getcwd(cwd, sizeof(cwd)); -# if GTEST_OS_NACL +#ifdef GTEST_OS_NACL // getcwd will likely fail in NaCl due to the sandbox, so return something // reasonable. The user may have provided a shim implementation for getcwd, // however, so fallback only when failure is detected. return FilePath(result == nullptr ? kCurrentDirectoryString : cwd); -# endif // GTEST_OS_NACL +#endif // GTEST_OS_NACL return FilePath(result == nullptr ? "" : cwd); #endif // GTEST_OS_WINDOWS_MOBILE } @@ -121,8 +130,8 @@ FilePath FilePath::GetCurrentDir() { FilePath FilePath::RemoveExtension(const char* extension) const { const std::string dot_extension = std::string(".") + extension; if (String::EndsWithCaseInsensitive(pathname_, dot_extension)) { - return FilePath(pathname_.substr( - 0, pathname_.length() - dot_extension.length())); + return FilePath( + pathname_.substr(0, pathname_.length() - dot_extension.length())); } return *this; } @@ -143,6 +152,44 @@ const char* FilePath::FindLastPathSeparator() const { return last_sep; } +size_t FilePath::CalculateRootLength() const { + const auto& path = pathname_; + auto s = path.begin(); + auto end = path.end(); +#ifdef GTEST_OS_WINDOWS + if (end - s >= 2 && s[1] == ':' && (end - s == 2 || IsPathSeparator(s[2])) && + (('A' <= s[0] && s[0] <= 'Z') || ('a' <= s[0] && s[0] <= 'z'))) { + // A typical absolute path like "C:\Windows" or "D:" + s += 2; + if (s != end) { + ++s; + } + } else if (end - s >= 3 && IsPathSeparator(*s) && IsPathSeparator(*(s + 1)) && + !IsPathSeparator(*(s + 2))) { + // Move past the "\\" prefix in a UNC path like "\\Server\Share\Folder" + s += 2; + // Skip 2 components and their following separators ("Server\" and "Share\") + for (int i = 0; i < 2; ++i) { + while (s != end) { + bool stop = IsPathSeparator(*s); + ++s; + if (stop) { + break; + } + } + } + } else if (s != end && IsPathSeparator(*s)) { + // A drive-rooted path like "\Windows" + ++s; + } +#else + if (s != end && IsPathSeparator(*s)) { + ++s; + } +#endif + return static_cast(s - path.begin()); +} + // Returns a copy of the FilePath with the directory part removed. // Example: FilePath("path/to/file").RemoveDirectoryName() returns // FilePath("file"). If there is no directory part ("just_a_file"), it returns @@ -178,15 +225,14 @@ FilePath FilePath::RemoveFileName() const { // than zero (e.g., 12), returns "dir/test_12.xml". // On Windows platform, uses \ as the separator rather than /. FilePath FilePath::MakeFileName(const FilePath& directory, - const FilePath& base_name, - int number, + const FilePath& base_name, int number, const char* extension) { std::string file; if (number == 0) { file = base_name.string() + "." + extension; } else { - file = base_name.string() + "_" + StreamableToString(number) - + "." + extension; + file = + base_name.string() + "_" + StreamableToString(number) + "." + extension; } return ConcatPaths(directory, FilePath(file)); } @@ -195,8 +241,7 @@ FilePath FilePath::MakeFileName(const FilePath& directory, // On Windows, uses \ as the separator rather than /. FilePath FilePath::ConcatPaths(const FilePath& directory, const FilePath& relative_path) { - if (directory.IsEmpty()) - return relative_path; + if (directory.IsEmpty()) return relative_path; const FilePath dir(directory.RemoveTrailingPathSeparator()); return FilePath(dir.string() + kPathSeparator + relative_path.string()); } @@ -204,10 +249,10 @@ FilePath FilePath::ConcatPaths(const FilePath& directory, // Returns true if pathname describes something findable in the file-system, // either a file, directory, or whatever. bool FilePath::FileOrDirectoryExists() const { -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str()); const DWORD attributes = GetFileAttributes(unicode); - delete [] unicode; + delete[] unicode; return attributes != kInvalidFileAttributes; #else posix::StatStruct file_stat{}; @@ -219,55 +264,42 @@ bool FilePath::FileOrDirectoryExists() const { // that exists. bool FilePath::DirectoryExists() const { bool result = false; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Don't strip off trailing separator if path is a root directory on // Windows (like "C:\\"). - const FilePath& path(IsRootDirectory() ? *this : - RemoveTrailingPathSeparator()); + const FilePath& path(IsRootDirectory() ? *this + : RemoveTrailingPathSeparator()); #else const FilePath& path(*this); #endif -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE LPCWSTR unicode = String::AnsiToUtf16(path.c_str()); const DWORD attributes = GetFileAttributes(unicode); - delete [] unicode; + delete[] unicode; if ((attributes != kInvalidFileAttributes) && (attributes & FILE_ATTRIBUTE_DIRECTORY)) { result = true; } #else posix::StatStruct file_stat{}; - result = posix::Stat(path.c_str(), &file_stat) == 0 && - posix::IsDir(file_stat); + result = + posix::Stat(path.c_str(), &file_stat) == 0 && posix::IsDir(file_stat); #endif // GTEST_OS_WINDOWS_MOBILE return result; } // Returns true if pathname describes a root directory. (Windows has one -// root directory per disk drive.) +// root directory per disk drive. UNC share roots are also included.) bool FilePath::IsRootDirectory() const { -#if GTEST_OS_WINDOWS - return pathname_.length() == 3 && IsAbsolutePath(); -#else - return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]); -#endif + size_t root_length = CalculateRootLength(); + return root_length > 0 && root_length == pathname_.size() && + IsPathSeparator(pathname_[root_length - 1]); } // Returns true if pathname describes an absolute path. -bool FilePath::IsAbsolutePath() const { - const char* const name = pathname_.c_str(); -#if GTEST_OS_WINDOWS - return pathname_.length() >= 3 && - ((name[0] >= 'a' && name[0] <= 'z') || - (name[0] >= 'A' && name[0] <= 'Z')) && - name[1] == ':' && - IsPathSeparator(name[2]); -#else - return IsPathSeparator(name[0]); -#endif -} +bool FilePath::IsAbsolutePath() const { return CalculateRootLength() > 0; } // Returns a pathname for a file that does not currently exist. The pathname // will be directory/base_name.extension or @@ -304,7 +336,7 @@ bool FilePath::CreateDirectoriesRecursively() const { return false; } - if (pathname_.length() == 0 || this->DirectoryExists()) { + if (pathname_.empty() || this->DirectoryExists()) { return true; } @@ -317,14 +349,16 @@ bool FilePath::CreateDirectoriesRecursively() const { // directory for any reason, including if the parent directory does not // exist. Not named "CreateDirectory" because that's a macro on Windows. bool FilePath::CreateFolder() const { -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE FilePath removed_sep(this->RemoveTrailingPathSeparator()); LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str()); int result = CreateDirectory(unicode, nullptr) ? 0 : -1; - delete [] unicode; -#elif GTEST_OS_WINDOWS + delete[] unicode; +#elif defined(GTEST_OS_WINDOWS) int result = _mkdir(pathname_.c_str()); -#elif GTEST_OS_ESP8266 || GTEST_OS_XTENSA +#elif defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \ + defined(GTEST_OS_QURT) || defined(GTEST_OS_NXP_QN9090) || \ + defined(GTEST_OS_NRF52) // do nothing int result = 0; #else @@ -341,25 +375,34 @@ bool FilePath::CreateFolder() const { // name, otherwise return the name string unmodified. // On Windows platform, uses \ as the separator, other platforms use /. FilePath FilePath::RemoveTrailingPathSeparator() const { - return IsDirectory() - ? FilePath(pathname_.substr(0, pathname_.length() - 1)) - : *this; + return IsDirectory() ? FilePath(pathname_.substr(0, pathname_.length() - 1)) + : *this; } // Removes any redundant separators that might be in the pathname. // For example, "bar///foo" becomes "bar/foo". Does not eliminate other // redundancies that might be in a pathname involving "." or "..". +// Note that "\\Host\Share" does not contain a redundancy on Windows! void FilePath::Normalize() { auto out = pathname_.begin(); - for (const char character : pathname_) { + auto i = pathname_.cbegin(); +#ifdef GTEST_OS_WINDOWS + // UNC paths are treated specially + if (pathname_.end() - i >= 3 && IsPathSeparator(*i) && + IsPathSeparator(*(i + 1)) && !IsPathSeparator(*(i + 2))) { + *(out++) = kPathSeparator; + *(out++) = kPathSeparator; + } +#endif + while (i != pathname_.end()) { + const char character = *i; if (!IsPathSeparator(character)) { *(out++) = character; } else if (out == pathname_.begin() || *std::prev(out) != kPathSeparator) { *(out++) = kPathSeparator; - } else { - continue; } + ++i; } pathname_.erase(out, pathname_.end()); @@ -367,3 +410,5 @@ void FilePath::Normalize() { } // namespace internal } // namespace testing + +#endif // GTEST_HAS_FILE_SYSTEM diff --git a/libs/libvpx/third_party/googletest/src/src/gtest-internal-inl.h b/libs/libvpx/third_party/googletest/src/src/gtest-internal-inl.h index 6d8cecbbb3..6a39b93be1 100644 --- a/libs/libvpx/third_party/googletest/src/src/gtest-internal-inl.h +++ b/libs/libvpx/third_party/googletest/src/src/gtest-internal-inl.h @@ -35,7 +35,7 @@ #define GOOGLETEST_SRC_GTEST_INTERNAL_INL_H_ #ifndef _WIN32_WCE -# include +#include #endif // !_WIN32_WCE #include #include // For strtoll/_strtoul64/malloc/free. @@ -44,28 +44,28 @@ #include #include #include +#include #include +#include #include #include "gtest/internal/gtest-port.h" #if GTEST_CAN_STREAM_RESULTS_ -# include // NOLINT -# include // NOLINT +#include // NOLINT +#include // NOLINT #endif -#if GTEST_OS_WINDOWS -# include // NOLINT -#endif // GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS +#include // NOLINT +#endif // GTEST_OS_WINDOWS -#include "gtest/gtest.h" #include "gtest/gtest-spi.h" +#include "gtest/gtest.h" GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ /* class A needs to have dll-interface to be used by clients of class B */) -namespace testing { - // Declares the flags. // // We don't want the users to modify this flag in the code, but want @@ -73,32 +73,13 @@ namespace testing { // declare it here as opposed to in gtest.h. GTEST_DECLARE_bool_(death_test_use_fork); +namespace testing { namespace internal { // The value of GetTestTypeId() as seen from within the Google Test // library. This is solely for testing GetTestTypeId(). GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest; -// Names of the flags (needed for parsing Google Test flags). -const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests"; -const char kBreakOnFailureFlag[] = "break_on_failure"; -const char kCatchExceptionsFlag[] = "catch_exceptions"; -const char kColorFlag[] = "color"; -const char kFailFast[] = "fail_fast"; -const char kFilterFlag[] = "filter"; -const char kListTestsFlag[] = "list_tests"; -const char kOutputFlag[] = "output"; -const char kBriefFlag[] = "brief"; -const char kPrintTimeFlag[] = "print_time"; -const char kPrintUTF8Flag[] = "print_utf8"; -const char kRandomSeedFlag[] = "random_seed"; -const char kRepeatFlag[] = "repeat"; -const char kShuffleFlag[] = "shuffle"; -const char kStackTraceDepthFlag[] = "stack_trace_depth"; -const char kStreamResultToFlag[] = "stream_result_to"; -const char kThrowOnFailureFlag[] = "throw_on_failure"; -const char kFlagfileFlag[] = "flagfile"; - // A valid random seed must be in [1, kMaxRandomSeed]. const int kMaxRandomSeed = 99999; @@ -112,7 +93,8 @@ GTEST_API_ TimeInMillis GetTimeInMillis(); // Returns true if and only if Google Test should use colors in the output. GTEST_API_ bool ShouldUseColor(bool stdout_is_tty); -// Formats the given time in milliseconds as seconds. +// Formats the given time in milliseconds as seconds. If the input is an exact N +// seconds, the output has a trailing decimal point (e.g., "N." instead of "N"). GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms); // Converts the given time in milliseconds to a date string in the ISO 8601 @@ -125,21 +107,21 @@ GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms); // // On success, stores the value of the flag in *value, and returns // true. On failure, returns false without changing *value. -GTEST_API_ bool ParseInt32Flag( - const char* str, const char* flag, int32_t* value); +GTEST_API_ bool ParseFlag(const char* str, const char* flag, int32_t* value); // Returns a random seed in range [1, kMaxRandomSeed] based on the // given --gtest_random_seed flag value. inline int GetRandomSeedFromFlag(int32_t random_seed_flag) { - const unsigned int raw_seed = (random_seed_flag == 0) ? - static_cast(GetTimeInMillis()) : - static_cast(random_seed_flag); + const unsigned int raw_seed = + (random_seed_flag == 0) ? static_cast(GetTimeInMillis()) + : static_cast(random_seed_flag); // Normalizes the actual seed to range [1, kMaxRandomSeed] such that // it's easy to type. const int normalized_seed = static_cast((raw_seed - 1U) % - static_cast(kMaxRandomSeed)) + 1; + static_cast(kMaxRandomSeed)) + + 1; return normalized_seed; } @@ -160,50 +142,54 @@ class GTestFlagSaver { public: // The c'tor. GTestFlagSaver() { - also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests); - break_on_failure_ = GTEST_FLAG(break_on_failure); - catch_exceptions_ = GTEST_FLAG(catch_exceptions); - color_ = GTEST_FLAG(color); - death_test_style_ = GTEST_FLAG(death_test_style); - death_test_use_fork_ = GTEST_FLAG(death_test_use_fork); - fail_fast_ = GTEST_FLAG(fail_fast); - filter_ = GTEST_FLAG(filter); - internal_run_death_test_ = GTEST_FLAG(internal_run_death_test); - list_tests_ = GTEST_FLAG(list_tests); - output_ = GTEST_FLAG(output); - brief_ = GTEST_FLAG(brief); - print_time_ = GTEST_FLAG(print_time); - print_utf8_ = GTEST_FLAG(print_utf8); - random_seed_ = GTEST_FLAG(random_seed); - repeat_ = GTEST_FLAG(repeat); - shuffle_ = GTEST_FLAG(shuffle); - stack_trace_depth_ = GTEST_FLAG(stack_trace_depth); - stream_result_to_ = GTEST_FLAG(stream_result_to); - throw_on_failure_ = GTEST_FLAG(throw_on_failure); + also_run_disabled_tests_ = GTEST_FLAG_GET(also_run_disabled_tests); + break_on_failure_ = GTEST_FLAG_GET(break_on_failure); + catch_exceptions_ = GTEST_FLAG_GET(catch_exceptions); + color_ = GTEST_FLAG_GET(color); + death_test_style_ = GTEST_FLAG_GET(death_test_style); + death_test_use_fork_ = GTEST_FLAG_GET(death_test_use_fork); + fail_fast_ = GTEST_FLAG_GET(fail_fast); + filter_ = GTEST_FLAG_GET(filter); + internal_run_death_test_ = GTEST_FLAG_GET(internal_run_death_test); + list_tests_ = GTEST_FLAG_GET(list_tests); + output_ = GTEST_FLAG_GET(output); + brief_ = GTEST_FLAG_GET(brief); + print_time_ = GTEST_FLAG_GET(print_time); + print_utf8_ = GTEST_FLAG_GET(print_utf8); + random_seed_ = GTEST_FLAG_GET(random_seed); + repeat_ = GTEST_FLAG_GET(repeat); + recreate_environments_when_repeating_ = + GTEST_FLAG_GET(recreate_environments_when_repeating); + shuffle_ = GTEST_FLAG_GET(shuffle); + stack_trace_depth_ = GTEST_FLAG_GET(stack_trace_depth); + stream_result_to_ = GTEST_FLAG_GET(stream_result_to); + throw_on_failure_ = GTEST_FLAG_GET(throw_on_failure); } // The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS. ~GTestFlagSaver() { - GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_; - GTEST_FLAG(break_on_failure) = break_on_failure_; - GTEST_FLAG(catch_exceptions) = catch_exceptions_; - GTEST_FLAG(color) = color_; - GTEST_FLAG(death_test_style) = death_test_style_; - GTEST_FLAG(death_test_use_fork) = death_test_use_fork_; - GTEST_FLAG(filter) = filter_; - GTEST_FLAG(fail_fast) = fail_fast_; - GTEST_FLAG(internal_run_death_test) = internal_run_death_test_; - GTEST_FLAG(list_tests) = list_tests_; - GTEST_FLAG(output) = output_; - GTEST_FLAG(brief) = brief_; - GTEST_FLAG(print_time) = print_time_; - GTEST_FLAG(print_utf8) = print_utf8_; - GTEST_FLAG(random_seed) = random_seed_; - GTEST_FLAG(repeat) = repeat_; - GTEST_FLAG(shuffle) = shuffle_; - GTEST_FLAG(stack_trace_depth) = stack_trace_depth_; - GTEST_FLAG(stream_result_to) = stream_result_to_; - GTEST_FLAG(throw_on_failure) = throw_on_failure_; + GTEST_FLAG_SET(also_run_disabled_tests, also_run_disabled_tests_); + GTEST_FLAG_SET(break_on_failure, break_on_failure_); + GTEST_FLAG_SET(catch_exceptions, catch_exceptions_); + GTEST_FLAG_SET(color, color_); + GTEST_FLAG_SET(death_test_style, death_test_style_); + GTEST_FLAG_SET(death_test_use_fork, death_test_use_fork_); + GTEST_FLAG_SET(filter, filter_); + GTEST_FLAG_SET(fail_fast, fail_fast_); + GTEST_FLAG_SET(internal_run_death_test, internal_run_death_test_); + GTEST_FLAG_SET(list_tests, list_tests_); + GTEST_FLAG_SET(output, output_); + GTEST_FLAG_SET(brief, brief_); + GTEST_FLAG_SET(print_time, print_time_); + GTEST_FLAG_SET(print_utf8, print_utf8_); + GTEST_FLAG_SET(random_seed, random_seed_); + GTEST_FLAG_SET(repeat, repeat_); + GTEST_FLAG_SET(recreate_environments_when_repeating, + recreate_environments_when_repeating_); + GTEST_FLAG_SET(shuffle, shuffle_); + GTEST_FLAG_SET(stack_trace_depth, stack_trace_depth_); + GTEST_FLAG_SET(stream_result_to, stream_result_to_); + GTEST_FLAG_SET(throw_on_failure, throw_on_failure_); } private: @@ -224,11 +210,12 @@ class GTestFlagSaver { bool print_utf8_; int32_t random_seed_; int32_t repeat_; + bool recreate_environments_when_repeating_; bool shuffle_; int32_t stack_trace_depth_; std::string stream_result_to_; bool throw_on_failure_; -} GTEST_ATTRIBUTE_UNUSED_; +}; // Converts a Unicode code point to a narrow string in UTF-8 encoding. // code_point parameter is of type UInt32 because wchar_t may not be @@ -278,8 +265,8 @@ GTEST_API_ int32_t Int32FromEnvOrDie(const char* env_var, int32_t default_val); // returns true if and only if the test should be run on this shard. The test id // is some arbitrary but unique non-negative integer assigned to each test // method. Assumes that 0 <= shard_index < total_shards. -GTEST_API_ bool ShouldRunTestOnShard( - int total_shards, int shard_index, int test_id); +GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, + int test_id); // STL container utilities. @@ -290,9 +277,8 @@ inline int CountIf(const Container& c, Predicate predicate) { // Implemented as an explicit loop since std::count_if() in libCstd on // Solaris has a non-standard signature. int count = 0; - for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) { - if (predicate(*it)) - ++count; + for (auto it = c.begin(); it != c.end(); ++it) { + if (predicate(*it)) ++count; } return count; } @@ -327,7 +313,7 @@ void ShuffleRange(internal::Random* random, int begin, int end, << begin << ", " << size << "]."; // Fisher-Yates shuffle, from - // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle + // https://en.wikipedia.org/wiki/Fisher-Yates_shuffle for (int range_width = end - begin; range_width >= 2; range_width--) { const int last_in_range = begin + range_width - 1; const int selected = @@ -399,13 +385,13 @@ class GTEST_API_ UnitTestOptions { static bool FilterMatchesTest(const std::string& test_suite_name, const std::string& test_name); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Function for supporting the gtest_catch_exception flag. - // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the - // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise. + // Returns EXCEPTION_EXECUTE_HANDLER if given SEH exception was handled, or + // EXCEPTION_CONTINUE_SEARCH otherwise. // This function is useful as an __except condition. - static int GTestShouldProcessSEH(DWORD exception_code); + static int GTestProcessSEH(DWORD seh_code, const char* location); #endif // GTEST_OS_WINDOWS // Returns true if "name" matches the ':' separated list of glob-style @@ -413,15 +399,17 @@ class GTEST_API_ UnitTestOptions { static bool MatchesFilter(const std::string& name, const char* filter); }; +#if GTEST_HAS_FILE_SYSTEM // Returns the current application's name, removing directory path if that // is present. Used by UnitTestOptions::GetOutputFile. GTEST_API_ FilePath GetCurrentExecutableName(); +#endif // GTEST_HAS_FILE_SYSTEM // The role interface for getting the OS stack trace as a string. class OsStackTraceGetterInterface { public: - OsStackTraceGetterInterface() {} - virtual ~OsStackTraceGetterInterface() {} + OsStackTraceGetterInterface() = default; + virtual ~OsStackTraceGetterInterface() = default; // Returns the current OS stack trace as an std::string. Parameters: // @@ -441,19 +429,21 @@ class OsStackTraceGetterInterface { static const char* const kElidedFramesMarker; private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface); + OsStackTraceGetterInterface(const OsStackTraceGetterInterface&) = delete; + OsStackTraceGetterInterface& operator=(const OsStackTraceGetterInterface&) = + delete; }; // A working implementation of the OsStackTraceGetterInterface interface. class OsStackTraceGetter : public OsStackTraceGetterInterface { public: - OsStackTraceGetter() {} + OsStackTraceGetter() = default; std::string CurrentStackTrace(int max_depth, int skip_count) override; void UponLeavingGTest() override; private: -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL Mutex mutex_; // Protects all internal state. // We save the stack frame below the frame that calls user code. @@ -463,7 +453,8 @@ class OsStackTraceGetter : public OsStackTraceGetterInterface { void* caller_frame_ = nullptr; #endif // GTEST_HAS_ABSL - GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter); + OsStackTraceGetter(const OsStackTraceGetter&) = delete; + OsStackTraceGetter& operator=(const OsStackTraceGetter&) = delete; }; // Information about a Google Test trace point. @@ -476,7 +467,7 @@ struct TraceInfo { // This is the default global test part result reporter used in UnitTestImpl. // This class should only be used by UnitTestImpl. class DefaultGlobalTestPartResultReporter - : public TestPartResultReporterInterface { + : public TestPartResultReporterInterface { public: explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test); // Implements the TestPartResultReporterInterface. Reports the test part @@ -486,7 +477,10 @@ class DefaultGlobalTestPartResultReporter private: UnitTestImpl* const unit_test_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter); + DefaultGlobalTestPartResultReporter( + const DefaultGlobalTestPartResultReporter&) = delete; + DefaultGlobalTestPartResultReporter& operator=( + const DefaultGlobalTestPartResultReporter&) = delete; }; // This is the default per thread test part result reporter used in @@ -502,7 +496,10 @@ class DefaultPerThreadTestPartResultReporter private: UnitTestImpl* const unit_test_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter); + DefaultPerThreadTestPartResultReporter( + const DefaultPerThreadTestPartResultReporter&) = delete; + DefaultPerThreadTestPartResultReporter& operator=( + const DefaultPerThreadTestPartResultReporter&) = delete; }; // The private implementation of the UnitTest class. We don't protect @@ -515,9 +512,9 @@ class GTEST_API_ UnitTestImpl { virtual ~UnitTestImpl(); // There are two different ways to register your own TestPartResultReporter. - // You can register your own repoter to listen either only for test results + // You can register your own reporter to listen either only for test results // from the current thread or for results from all threads. - // By default, each per-thread test result repoter just passes a new + // By default, each per-thread test result reporter just passes a new // TestPartResult to the global test result reporter, which registers the // test part result for the currently running test. @@ -640,7 +637,8 @@ class GTEST_API_ UnitTestImpl { // For example, if Foo() calls Bar(), which in turn calls // CurrentOsStackTraceExceptTop(1), Foo() will be included in the // trace but Bar() and CurrentOsStackTraceExceptTop() won't. - std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_; + std::string CurrentOsStackTraceExceptTop(int skip_count) + GTEST_NO_INLINE_ GTEST_NO_TAIL_CALL_; // Finds and returns a TestSuite with the given name. If one doesn't // exist, creates one and returns it. @@ -652,13 +650,15 @@ class GTEST_API_ UnitTestImpl { // this is not a typed or a type-parameterized test. // set_up_tc: pointer to the function that sets up the test suite // tear_down_tc: pointer to the function that tears down the test suite - TestSuite* GetTestSuite(const char* test_suite_name, const char* type_param, + TestSuite* GetTestSuite(const std::string& test_suite_name, + const char* type_param, internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc); // Legacy API is deprecated but still available #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ - TestCase* GetTestCase(const char* test_case_name, const char* type_param, + TestCase* GetTestCase(const std::string& test_case_name, + const char* type_param, internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc) { return GetTestSuite(test_case_name, type_param, set_up_tc, tear_down_tc); @@ -675,7 +675,7 @@ class GTEST_API_ UnitTestImpl { void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc, TestInfo* test_info) { -#if GTEST_HAS_DEATH_TEST +#if GTEST_HAS_FILE_SYSTEM // In order to support thread-safe death tests, we need to // remember the original working directory when the test program // was first invoked. We cannot do this in RUN_ALL_TESTS(), as @@ -684,13 +684,13 @@ class GTEST_API_ UnitTestImpl { // AddTestInfo(), which is called to register a TEST or TEST_F // before main() is reached. if (original_working_dir_.IsEmpty()) { - original_working_dir_.Set(FilePath::GetCurrentDir()); + original_working_dir_ = FilePath::GetCurrentDir(); GTEST_CHECK_(!original_working_dir_.IsEmpty()) << "Failed to get the current working directory."; } -#endif // GTEST_HAS_DEATH_TEST +#endif // GTEST_HAS_FILE_SYSTEM - GetTestSuite(test_info->test_suite_name(), test_info->type_param(), + GetTestSuite(test_info->test_suite_name_, test_info->type_param(), set_up_tc, tear_down_tc) ->AddTestInfo(test_info); } @@ -712,18 +712,6 @@ class GTEST_API_ UnitTestImpl { return type_parameterized_test_registry_; } - // Sets the TestSuite object for the test that's currently running. - void set_current_test_suite(TestSuite* a_current_test_suite) { - current_test_suite_ = a_current_test_suite; - } - - // Sets the TestInfo object for the test that's currently running. If - // current_test_info is NULL, the assertion results will be stored in - // ad_hoc_test_result_. - void set_current_test_info(TestInfo* a_current_test_info) { - current_test_info_ = a_current_test_info; - } - // Registers all parameterized tests defined using TEST_P and // INSTANTIATE_TEST_SUITE_P, creating regular tests for each test/parameter // combination. This method can be called more then once; it has guards @@ -744,9 +732,7 @@ class GTEST_API_ UnitTestImpl { } // Clears the results of ad-hoc test assertions. - void ClearAdHocTestResult() { - ad_hoc_test_result_.Clear(); - } + void ClearAdHocTestResult() { ad_hoc_test_result_.Clear(); } // Adds a TestProperty to the current TestResult object when invoked in a // context of a test or a test suite, or to the global property set. If the @@ -754,10 +740,7 @@ class GTEST_API_ UnitTestImpl { // updated. void RecordProperty(const TestProperty& test_property); - enum ReactionToSharding { - HONOR_SHARDING_PROTOCOL, - IGNORE_SHARDING_PROTOCOL - }; + enum ReactionToSharding { HONOR_SHARDING_PROTOCOL, IGNORE_SHARDING_PROTOCOL }; // Matches the full name of each test against the user-specified // filter to decide whether the test should run, then records the @@ -786,7 +769,7 @@ class GTEST_API_ UnitTestImpl { return gtest_trace_stack_.get(); } -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST void InitDeathTestSubprocessControlInfo() { internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag()); } @@ -843,18 +826,42 @@ class GTEST_API_ UnitTestImpl { bool catch_exceptions() const { return catch_exceptions_; } private: + // Returns true if a warning should be issued if no tests match the test + // filter flag. + bool ShouldWarnIfNoTestsMatchFilter() const; + + struct CompareTestSuitesByPointer { + bool operator()(const TestSuite* lhs, const TestSuite* rhs) const { + return lhs->name_ < rhs->name_; + } + }; + friend class ::testing::UnitTest; // Used by UnitTest::Run() to capture the state of // GTEST_FLAG(catch_exceptions) at the moment it starts. void set_catch_exceptions(bool value) { catch_exceptions_ = value; } + // Sets the TestSuite object for the test that's currently running. + void set_current_test_suite(TestSuite* a_current_test_suite) { + current_test_suite_ = a_current_test_suite; + } + + // Sets the TestInfo object for the test that's currently running. If + // current_test_info is NULL, the assertion results will be stored in + // ad_hoc_test_result_. + void set_current_test_info(TestInfo* a_current_test_info) { + current_test_info_ = a_current_test_info; + } + // The UnitTest object that owns this implementation object. UnitTest* const parent_; +#if GTEST_HAS_FILE_SYSTEM // The working directory when the first TEST() or TEST_F() was // executed. internal::FilePath original_working_dir_; +#endif // GTEST_HAS_FILE_SYSTEM // The default test part result reporters. DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_; @@ -862,7 +869,7 @@ class GTEST_API_ UnitTestImpl { default_per_thread_test_part_result_reporter_; // Points to (but doesn't own) the global test part result reporter. - TestPartResultReporterInterface* global_test_part_result_repoter_; + TestPartResultReporterInterface* global_test_part_result_reporter_; // Protects read and write access to global_test_part_result_reporter_. internal::Mutex global_test_part_result_reporter_mutex_; @@ -879,6 +886,9 @@ class GTEST_API_ UnitTestImpl { // elements in the vector. std::vector test_suites_; + // The set of TestSuites by name. + std::unordered_map test_suites_by_name_; + // Provides a level of indirection for the test suite list to allow // easy shuffling and restoring the test suite order. The i-th // element of this vector is the index of the i-th test suite in the @@ -949,7 +959,7 @@ class GTEST_API_ UnitTestImpl { // How long the test took to run, in milliseconds. TimeInMillis elapsed_time_; -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST // The decomposed components of the gtest_internal_run_death_test flag, // parsed when RUN_ALL_TESTS is called. std::unique_ptr internal_run_death_test_flag_; @@ -963,7 +973,8 @@ class GTEST_API_ UnitTestImpl { // starts. bool catch_exceptions_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl); + UnitTestImpl(const UnitTestImpl&) = delete; + UnitTestImpl& operator=(const UnitTestImpl&) = delete; }; // class UnitTestImpl // Convenience function for accessing the global UnitTest @@ -972,7 +983,7 @@ inline UnitTestImpl* GetUnitTestImpl() { return UnitTest::GetInstance()->impl(); } -#if GTEST_USES_SIMPLE_RE +#ifdef GTEST_USES_SIMPLE_RE // Internal helper functions for implementing the simple regular // expression matcher. @@ -986,8 +997,9 @@ GTEST_API_ bool IsValidEscape(char ch); GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch); GTEST_API_ bool ValidateRegex(const char* regex); GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str); -GTEST_API_ bool MatchRepetitionAndRegexAtHead( - bool escaped, char ch, char repeat, const char* regex, const char* str); +GTEST_API_ bool MatchRepetitionAndRegexAtHead(bool escaped, char ch, + char repeat, const char* regex, + const char* str); GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str); #endif // GTEST_USES_SIMPLE_RE @@ -997,7 +1009,7 @@ GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str); GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv); GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv); -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST // Returns the message describing the last system error, regardless of the // platform. @@ -1068,7 +1080,7 @@ class StreamingListener : public EmptyTestEventListener { // Abstract base class for writing strings to a socket. class AbstractSocketWriter { public: - virtual ~AbstractSocketWriter() {} + virtual ~AbstractSocketWriter() = default; // Sends a string to the socket. virtual void Send(const std::string& message) = 0; @@ -1089,8 +1101,7 @@ class StreamingListener : public EmptyTestEventListener { } ~SocketWriter() override { - if (sockfd_ != -1) - CloseConnection(); + if (sockfd_ != -1) CloseConnection(); } // Sends a string to the socket. @@ -1100,9 +1111,8 @@ class StreamingListener : public EmptyTestEventListener { const auto len = static_cast(message.length()); if (write(sockfd_, message.c_str(), len) != static_cast(len)) { - GTEST_LOG_(WARNING) - << "stream_result_to: failed to stream to " - << host_name_ << ":" << port_num_; + GTEST_LOG_(WARNING) << "stream_result_to: failed to stream to " + << host_name_ << ":" << port_num_; } } @@ -1123,7 +1133,8 @@ class StreamingListener : public EmptyTestEventListener { const std::string host_name_; const std::string port_num_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(SocketWriter); + SocketWriter(const SocketWriter&) = delete; + SocketWriter& operator=(const SocketWriter&) = delete; }; // class SocketWriter // Escapes '=', '&', '%', and '\n' characters in str as "%xx". @@ -1135,7 +1146,9 @@ class StreamingListener : public EmptyTestEventListener { } explicit StreamingListener(AbstractSocketWriter* socket_writer) - : socket_writer_(socket_writer) { Start(); } + : socket_writer_(socket_writer) { + Start(); + } void OnTestProgramStart(const UnitTest& /* unit_test */) override { SendLn("event=TestProgramStart"); @@ -1158,22 +1171,22 @@ class StreamingListener : public EmptyTestEventListener { void OnTestIterationEnd(const UnitTest& unit_test, int /* iteration */) override { - SendLn("event=TestIterationEnd&passed=" + - FormatBool(unit_test.Passed()) + "&elapsed_time=" + - StreamableToString(unit_test.elapsed_time()) + "ms"); + SendLn("event=TestIterationEnd&passed=" + FormatBool(unit_test.Passed()) + + "&elapsed_time=" + StreamableToString(unit_test.elapsed_time()) + + "ms"); } // Note that "event=TestCaseStart" is a wire format and has to remain // "case" for compatibility - void OnTestCaseStart(const TestCase& test_case) override { - SendLn(std::string("event=TestCaseStart&name=") + test_case.name()); + void OnTestSuiteStart(const TestSuite& test_suite) override { + SendLn(std::string("event=TestCaseStart&name=") + test_suite.name()); } // Note that "event=TestCaseEnd" is a wire format and has to remain // "case" for compatibility - void OnTestCaseEnd(const TestCase& test_case) override { - SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed()) + - "&elapsed_time=" + StreamableToString(test_case.elapsed_time()) + + void OnTestSuiteEnd(const TestSuite& test_suite) override { + SendLn("event=TestCaseEnd&passed=" + FormatBool(test_suite.Passed()) + + "&elapsed_time=" + StreamableToString(test_suite.elapsed_time()) + "ms"); } @@ -1183,8 +1196,7 @@ class StreamingListener : public EmptyTestEventListener { void OnTestEnd(const TestInfo& test_info) override { SendLn("event=TestEnd&passed=" + - FormatBool((test_info.result())->Passed()) + - "&elapsed_time=" + + FormatBool((test_info.result())->Passed()) + "&elapsed_time=" + StreamableToString((test_info.result())->elapsed_time()) + "ms"); } @@ -1208,7 +1220,8 @@ class StreamingListener : public EmptyTestEventListener { const std::unique_ptr socket_writer_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener); + StreamingListener(const StreamingListener&) = delete; + StreamingListener& operator=(const StreamingListener&) = delete; }; // class StreamingListener #endif // GTEST_CAN_STREAM_RESULTS_ diff --git a/libs/libvpx/third_party/googletest/src/src/gtest-matchers.cc b/libs/libvpx/third_party/googletest/src/src/gtest-matchers.cc index 65104ebab1..7e3bcc0cff 100644 --- a/libs/libvpx/third_party/googletest/src/src/gtest-matchers.cc +++ b/libs/libvpx/third_party/googletest/src/src/gtest-matchers.cc @@ -32,12 +32,13 @@ // This file implements just enough of the matcher interface to allow // EXPECT_DEATH and friends to accept a matcher argument. -#include "gtest/internal/gtest-internal.h" -#include "gtest/internal/gtest-port.h" #include "gtest/gtest-matchers.h" #include +#include "gtest/internal/gtest-internal.h" +#include "gtest/internal/gtest-port.h" + namespace testing { // Constructs a matcher that matches a const std::string& whose value is diff --git a/libs/libvpx/third_party/googletest/src/src/gtest-port.cc b/libs/libvpx/third_party/googletest/src/src/gtest-port.cc index 53a4d37f97..53d41d3886 100644 --- a/libs/libvpx/third_party/googletest/src/src/gtest-port.cc +++ b/libs/libvpx/third_party/googletest/src/src/gtest-port.cc @@ -27,61 +27,68 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "gtest/internal/gtest-port.h" #include #include #include #include + #include #include #include +#include +#include +#include +#include -#if GTEST_OS_WINDOWS -# include -# include -# include -# include // Used in ThreadLocal. -# ifdef _MSC_VER -# include -# endif // _MSC_VER +#ifdef GTEST_OS_WINDOWS +#include +#include +#include + +#include // Used in ThreadLocal. +#ifdef _MSC_VER +#include +#endif // _MSC_VER #else -# include +#include #endif // GTEST_OS_WINDOWS -#if GTEST_OS_MAC -# include -# include -# include +#ifdef GTEST_OS_MAC +#include +#include +#include #endif // GTEST_OS_MAC -#if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \ - GTEST_OS_NETBSD || GTEST_OS_OPENBSD -# include -# if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD -# include -# endif +#if defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD) || \ + defined(GTEST_OS_OPENBSD) +#include +#if defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_GNU_KFREEBSD) +#include +#endif #endif -#if GTEST_OS_QNX -# include -# include -# include +#ifdef GTEST_OS_QNX +#include +#include +#include #endif // GTEST_OS_QNX -#if GTEST_OS_AIX -# include -# include +#ifdef GTEST_OS_AIX +#include +#include #endif // GTEST_OS_AIX -#if GTEST_OS_FUCHSIA -# include -# include +#ifdef GTEST_OS_FUCHSIA +#include +#include #endif // GTEST_OS_FUCHSIA -#include "gtest/gtest-spi.h" #include "gtest/gtest-message.h" +#include "gtest/gtest-spi.h" #include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-string.h" #include "src/gtest-internal-inl.h" @@ -89,16 +96,7 @@ namespace testing { namespace internal { -#if defined(_MSC_VER) || defined(__BORLANDC__) -// MSVC and C++Builder do not provide a definition of STDERR_FILENO. -const int kStdOutFileno = 1; -const int kStdErrFileno = 2; -#else -const int kStdOutFileno = STDOUT_FILENO; -const int kStdErrFileno = STDERR_FILENO; -#endif // _MSC_VER - -#if GTEST_OS_LINUX +#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_GNU_HURD) namespace { template @@ -121,7 +119,7 @@ size_t GetThreadCount() { return ReadProcFileField(filename, 19); } -#elif GTEST_OS_MAC +#elif defined(GTEST_OS_MAC) size_t GetThreadCount() { const task_t task = mach_task_self(); @@ -131,8 +129,7 @@ size_t GetThreadCount() { if (status == KERN_SUCCESS) { // task_threads allocates resources in thread_list and we need to free them // to avoid leaks. - vm_deallocate(task, - reinterpret_cast(thread_list), + vm_deallocate(task, reinterpret_cast(thread_list), sizeof(thread_t) * thread_count); return static_cast(thread_count); } else { @@ -140,20 +137,20 @@ size_t GetThreadCount() { } } -#elif GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \ - GTEST_OS_NETBSD +#elif defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD) -#if GTEST_OS_NETBSD +#ifdef GTEST_OS_NETBSD #undef KERN_PROC #define KERN_PROC KERN_PROC2 #define kinfo_proc kinfo_proc2 #endif -#if GTEST_OS_DRAGONFLY +#ifdef GTEST_OS_DRAGONFLY #define KP_NLWP(kp) (kp.kp_nthreads) -#elif GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD +#elif defined(GTEST_OS_FREEBSD) || defined(GTEST_OS_GNU_KFREEBSD) #define KP_NLWP(kp) (kp.ki_numthreads) -#elif GTEST_OS_NETBSD +#elif defined(GTEST_OS_NETBSD) #define KP_NLWP(kp) (kp.p_nlwps) #endif @@ -161,13 +158,13 @@ size_t GetThreadCount() { // we cannot detect it. size_t GetThreadCount() { int mib[] = { - CTL_KERN, - KERN_PROC, - KERN_PROC_PID, - getpid(), -#if GTEST_OS_NETBSD - sizeof(struct kinfo_proc), - 1, + CTL_KERN, + KERN_PROC, + KERN_PROC_PID, + getpid(), +#ifdef GTEST_OS_NETBSD + sizeof(struct kinfo_proc), + 1, #endif }; u_int miblen = sizeof(mib) / sizeof(mib[0]); @@ -178,18 +175,18 @@ size_t GetThreadCount() { } return static_cast(KP_NLWP(info)); } -#elif GTEST_OS_OPENBSD +#elif defined(GTEST_OS_OPENBSD) // Returns the number of threads running in the process, or 0 to indicate that // we cannot detect it. size_t GetThreadCount() { int mib[] = { - CTL_KERN, - KERN_PROC, - KERN_PROC_PID | KERN_PROC_SHOW_THREADS, - getpid(), - sizeof(struct kinfo_proc), - 0, + CTL_KERN, + KERN_PROC, + KERN_PROC_PID | KERN_PROC_SHOW_THREADS, + getpid(), + sizeof(struct kinfo_proc), + 0, }; u_int miblen = sizeof(mib) / sizeof(mib[0]); @@ -202,21 +199,20 @@ size_t GetThreadCount() { mib[5] = static_cast(size / static_cast(mib[4])); // populate array of structs - struct kinfo_proc info[mib[5]]; - if (sysctl(mib, miblen, &info, &size, NULL, 0)) { + std::vector info(mib[5]); + if (sysctl(mib, miblen, info.data(), &size, NULL, 0)) { return 0; } // exclude empty members size_t nthreads = 0; for (size_t i = 0; i < size / static_cast(mib[4]); i++) { - if (info[i].p_tid != -1) - nthreads++; + if (info[i].p_tid != -1) nthreads++; } return nthreads; } -#elif GTEST_OS_QNX +#elif defined(GTEST_OS_QNX) // Returns the number of threads running in the process, or 0 to indicate that // we cannot detect it. @@ -236,7 +232,7 @@ size_t GetThreadCount() { } } -#elif GTEST_OS_AIX +#elif defined(GTEST_OS_AIX) size_t GetThreadCount() { struct procentry64 entry; @@ -249,18 +245,14 @@ size_t GetThreadCount() { } } -#elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) size_t GetThreadCount() { int dummy_buffer; size_t avail; - zx_status_t status = zx_object_get_info( - zx_process_self(), - ZX_INFO_PROCESS_THREADS, - &dummy_buffer, - 0, - nullptr, - &avail); + zx_status_t status = + zx_object_get_info(zx_process_self(), ZX_INFO_PROCESS_THREADS, + &dummy_buffer, 0, nullptr, &avail); if (status == ZX_OK) { return avail; } else { @@ -278,29 +270,17 @@ size_t GetThreadCount() { #endif // GTEST_OS_LINUX -#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS +#if defined(GTEST_IS_THREADSAFE) && defined(GTEST_OS_WINDOWS) -void SleepMilliseconds(int n) { - ::Sleep(static_cast(n)); -} +AutoHandle::AutoHandle() : handle_(INVALID_HANDLE_VALUE) {} -AutoHandle::AutoHandle() - : handle_(INVALID_HANDLE_VALUE) {} +AutoHandle::AutoHandle(Handle handle) : handle_(handle) {} -AutoHandle::AutoHandle(Handle handle) - : handle_(handle) {} +AutoHandle::~AutoHandle() { Reset(); } -AutoHandle::~AutoHandle() { - Reset(); -} +AutoHandle::Handle AutoHandle::Get() const { return handle_; } -AutoHandle::Handle AutoHandle::Get() const { - return handle_; -} - -void AutoHandle::Reset() { - Reset(INVALID_HANDLE_VALUE); -} +void AutoHandle::Reset() { Reset(INVALID_HANDLE_VALUE); } void AutoHandle::Reset(HANDLE handle) { // Resetting with the same handle we already own is invalid. @@ -312,7 +292,7 @@ void AutoHandle::Reset(HANDLE handle) { } else { GTEST_CHECK_(!IsCloseable()) << "Resetting a valid handle to itself is likely a programmer error " - "and thus not allowed."; + "and thus not allowed."; } } @@ -322,22 +302,21 @@ bool AutoHandle::IsCloseable() const { return handle_ != nullptr && handle_ != INVALID_HANDLE_VALUE; } -Notification::Notification() - : event_(::CreateEvent(nullptr, // Default security attributes. - TRUE, // Do not reset automatically. - FALSE, // Initially unset. - nullptr)) { // Anonymous event. - GTEST_CHECK_(event_.Get() != nullptr); +#if !GTEST_HAS_NOTIFICATION_ && defined(GTEST_OS_WINDOWS_MINGW) +Notification::Notification() { + // Create a manual-reset event object. + event_ = ::CreateEvent(nullptr, TRUE, FALSE, nullptr); + GTEST_CHECK_(event_ != nullptr); } -void Notification::Notify() { - GTEST_CHECK_(::SetEvent(event_.Get()) != FALSE); -} +Notification::~Notification() { ::CloseHandle(event_); } + +void Notification::Notify() { GTEST_CHECK_(::SetEvent(event_)); } void Notification::WaitForNotification() { - GTEST_CHECK_( - ::WaitForSingleObject(event_.Get(), INFINITE) == WAIT_OBJECT_0); + GTEST_CHECK_(::WaitForSingleObject(event_, INFINITE) == WAIT_OBJECT_0); } +#endif // !GTEST_HAS_NOTIFICATION_ && defined(GTEST_OS_WINDOWS_MINGW) Mutex::Mutex() : owner_thread_id_(0), @@ -391,25 +370,25 @@ namespace { // MemoryIsNotDeallocated memory_is_not_deallocated; // critical_section_ = new CRITICAL_SECTION; // -class MemoryIsNotDeallocated -{ +class MemoryIsNotDeallocated { public: MemoryIsNotDeallocated() : old_crtdbg_flag_(0) { old_crtdbg_flag_ = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); // Set heap allocation block type to _IGNORE_BLOCK so that MS debug CRT // doesn't report mem leak if there's no matching deallocation. - _CrtSetDbgFlag(old_crtdbg_flag_ & ~_CRTDBG_ALLOC_MEM_DF); + (void)_CrtSetDbgFlag(old_crtdbg_flag_ & ~_CRTDBG_ALLOC_MEM_DF); } ~MemoryIsNotDeallocated() { // Restore the original _CRTDBG_ALLOC_MEM_DF flag - _CrtSetDbgFlag(old_crtdbg_flag_); + (void)_CrtSetDbgFlag(old_crtdbg_flag_); } private: int old_crtdbg_flag_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(MemoryIsNotDeallocated); + MemoryIsNotDeallocated(const MemoryIsNotDeallocated&) = delete; + MemoryIsNotDeallocated& operator=(const MemoryIsNotDeallocated&) = delete; }; #endif // _MSC_VER @@ -435,15 +414,13 @@ void Mutex::ThreadSafeLazyInit() { ::InitializeCriticalSection(critical_section_); // Updates the critical_section_init_phase_ to 2 to signal // initialization complete. - GTEST_CHECK_(::InterlockedCompareExchange( - &critical_section_init_phase_, 2L, 1L) == - 1L); + GTEST_CHECK_(::InterlockedCompareExchange(&critical_section_init_phase_, + 2L, 1L) == 1L); break; case 1: // Somebody else is already initializing the mutex; spin until they // are done. - while (::InterlockedCompareExchange(&critical_section_init_phase_, - 2L, + while (::InterlockedCompareExchange(&critical_section_init_phase_, 2L, 2L) != 2L) { // Possibly yields the rest of the thread's time slice to other // threads. @@ -488,9 +465,7 @@ class ThreadWithParamSupport : public ThreadWithParamBase { private: struct ThreadMainParam { ThreadMainParam(Runnable* runnable, Notification* thread_can_start) - : runnable_(runnable), - thread_can_start_(thread_can_start) { - } + : runnable_(runnable), thread_can_start_(thread_can_start) {} std::unique_ptr runnable_; // Does not own. Notification* thread_can_start_; @@ -508,20 +483,18 @@ class ThreadWithParamSupport : public ThreadWithParamBase { // Prohibit instantiation. ThreadWithParamSupport(); - GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParamSupport); + ThreadWithParamSupport(const ThreadWithParamSupport&) = delete; + ThreadWithParamSupport& operator=(const ThreadWithParamSupport&) = delete; }; } // namespace -ThreadWithParamBase::ThreadWithParamBase(Runnable *runnable, +ThreadWithParamBase::ThreadWithParamBase(Runnable* runnable, Notification* thread_can_start) - : thread_(ThreadWithParamSupport::CreateThread(runnable, - thread_can_start)) { -} + : thread_( + ThreadWithParamSupport::CreateThread(runnable, thread_can_start)) {} -ThreadWithParamBase::~ThreadWithParamBase() { - Join(); -} +ThreadWithParamBase::~ThreadWithParamBase() { Join(); } void ThreadWithParamBase::Join() { GTEST_CHECK_(::WaitForSingleObject(thread_.Get(), INFINITE) == WAIT_OBJECT_0) @@ -548,8 +521,10 @@ class ThreadLocalRegistryImpl { ThreadIdToThreadLocals::iterator thread_local_pos = thread_to_thread_locals->find(current_thread); if (thread_local_pos == thread_to_thread_locals->end()) { - thread_local_pos = thread_to_thread_locals->insert( - std::make_pair(current_thread, ThreadLocalValues())).first; + thread_local_pos = + thread_to_thread_locals + ->insert(std::make_pair(current_thread, ThreadLocalValues())) + .first; StartWatcherThreadFor(current_thread); } ThreadLocalValues& thread_local_values = thread_local_pos->second; @@ -577,9 +552,8 @@ class ThreadLocalRegistryImpl { ThreadIdToThreadLocals* const thread_to_thread_locals = GetThreadLocalsMapLocked(); for (ThreadIdToThreadLocals::iterator it = - thread_to_thread_locals->begin(); - it != thread_to_thread_locals->end(); - ++it) { + thread_to_thread_locals->begin(); + it != thread_to_thread_locals->end(); ++it) { ThreadLocalValues& thread_local_values = it->second; ThreadLocalValues::iterator value_pos = thread_local_values.find(thread_local_instance); @@ -609,9 +583,8 @@ class ThreadLocalRegistryImpl { if (thread_local_pos != thread_to_thread_locals->end()) { ThreadLocalValues& thread_local_values = thread_local_pos->second; for (ThreadLocalValues::iterator value_pos = - thread_local_values.begin(); - value_pos != thread_local_values.end(); - ++value_pos) { + thread_local_values.begin(); + value_pos != thread_local_values.end(); ++value_pos) { value_holders.push_back(value_pos->second); } thread_to_thread_locals->erase(thread_local_pos); @@ -630,45 +603,59 @@ class ThreadLocalRegistryImpl { // thread's ID. typedef std::map ThreadIdToThreadLocals; - // Holds the thread id and thread handle that we pass from - // StartWatcherThreadFor to WatcherThreadFunc. - typedef std::pair ThreadIdAndHandle; + struct WatcherThreadParams { + DWORD thread_id; + HANDLE handle; + Notification has_initialized; + }; static void StartWatcherThreadFor(DWORD thread_id) { // The returned handle will be kept in thread_map and closed by // watcher_thread in WatcherThreadFunc. - HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION, - FALSE, - thread_id); + HANDLE thread = + ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION, FALSE, thread_id); GTEST_CHECK_(thread != nullptr); + + WatcherThreadParams* watcher_thread_params = new WatcherThreadParams; + watcher_thread_params->thread_id = thread_id; + watcher_thread_params->handle = thread; + // We need to pass a valid thread ID pointer into CreateThread for it // to work correctly under Win98. DWORD watcher_thread_id; - HANDLE watcher_thread = ::CreateThread( - nullptr, // Default security. - 0, // Default stack size - &ThreadLocalRegistryImpl::WatcherThreadFunc, - reinterpret_cast(new ThreadIdAndHandle(thread_id, thread)), - CREATE_SUSPENDED, &watcher_thread_id); - GTEST_CHECK_(watcher_thread != nullptr); + HANDLE watcher_thread = + ::CreateThread(nullptr, // Default security. + 0, // Default stack size + &ThreadLocalRegistryImpl::WatcherThreadFunc, + reinterpret_cast(watcher_thread_params), + CREATE_SUSPENDED, &watcher_thread_id); + GTEST_CHECK_(watcher_thread != nullptr) + << "CreateThread failed with error " << ::GetLastError() << "."; // Give the watcher thread the same priority as ours to avoid being // blocked by it. ::SetThreadPriority(watcher_thread, ::GetThreadPriority(::GetCurrentThread())); ::ResumeThread(watcher_thread); ::CloseHandle(watcher_thread); + + // Wait for the watcher thread to start to avoid race conditions. + // One specific race condition that can happen is that we have returned + // from main and have started to tear down, the newly spawned watcher + // thread may access already-freed variables, like global shared_ptrs. + watcher_thread_params->has_initialized.WaitForNotification(); } // Monitors exit from a given thread and notifies those // ThreadIdToThreadLocals about thread termination. static DWORD WINAPI WatcherThreadFunc(LPVOID param) { - const ThreadIdAndHandle* tah = - reinterpret_cast(param); - GTEST_CHECK_( - ::WaitForSingleObject(tah->second, INFINITE) == WAIT_OBJECT_0); - OnThreadExit(tah->first); - ::CloseHandle(tah->second); - delete tah; + WatcherThreadParams* watcher_thread_params = + reinterpret_cast(param); + watcher_thread_params->has_initialized.Notify(); + GTEST_CHECK_(::WaitForSingleObject(watcher_thread_params->handle, + INFINITE) == WAIT_OBJECT_0); + OnThreadExit(watcher_thread_params->thread_id); + ::CloseHandle(watcher_thread_params->handle); + delete watcher_thread_params; return 0; } @@ -689,22 +676,23 @@ class ThreadLocalRegistryImpl { }; Mutex ThreadLocalRegistryImpl::mutex_(Mutex::kStaticMutex); // NOLINT -Mutex ThreadLocalRegistryImpl::thread_map_mutex_(Mutex::kStaticMutex); // NOLINT +Mutex ThreadLocalRegistryImpl::thread_map_mutex_( + Mutex::kStaticMutex); // NOLINT ThreadLocalValueHolderBase* ThreadLocalRegistry::GetValueOnCurrentThread( - const ThreadLocalBase* thread_local_instance) { + const ThreadLocalBase* thread_local_instance) { return ThreadLocalRegistryImpl::GetValueOnCurrentThread( thread_local_instance); } void ThreadLocalRegistry::OnThreadLocalDestroyed( - const ThreadLocalBase* thread_local_instance) { + const ThreadLocalBase* thread_local_instance) { ThreadLocalRegistryImpl::OnThreadLocalDestroyed(thread_local_instance); } #endif // GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS -#if GTEST_USES_POSIX_RE +#ifdef GTEST_USES_POSIX_RE // Implements RE. Currently only needed for death tests. @@ -717,7 +705,6 @@ RE::~RE() { regfree(&partial_regex_); regfree(&full_regex_); } - free(const_cast(pattern_)); } // Returns true if and only if regular expression re matches the entire str. @@ -739,7 +726,18 @@ bool RE::PartialMatch(const char* str, const RE& re) { // Initializes an RE from its string representation. void RE::Init(const char* regex) { - pattern_ = posix::StrDup(regex); + pattern_ = regex; + + // NetBSD (and Android, which takes its regex implemntation from NetBSD) does + // not include the GNU regex extensions (such as Perl style character classes + // like \w) in REG_EXTENDED. REG_EXTENDED is only specified to include the + // [[:alpha:]] style character classes. Enable REG_GNU wherever it is defined + // so users can use those extensions. +#if defined(REG_GNU) + constexpr int reg_flags = REG_EXTENDED | REG_GNU; +#else + constexpr int reg_flags = REG_EXTENDED; +#endif // Reserves enough bytes to hold the regular expression used for a // full match. @@ -747,7 +745,7 @@ void RE::Init(const char* regex) { char* const full_pattern = new char[full_regex_len]; snprintf(full_pattern, full_regex_len, "^(%s)$", regex); - is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0; + is_valid_ = regcomp(&full_regex_, full_pattern, reg_flags) == 0; // We want to call regcomp(&partial_regex_, ...) even if the // previous expression returns false. Otherwise partial_regex_ may // not be properly initialized can may cause trouble when it's @@ -758,7 +756,7 @@ void RE::Init(const char* regex) { // regex. We change it to an equivalent form "()" to be safe. if (is_valid_) { const char* const partial_regex = (*regex == '\0') ? "()" : regex; - is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0; + is_valid_ = regcomp(&partial_regex_, partial_regex, reg_flags) == 0; } EXPECT_TRUE(is_valid_) << "Regular expression \"" << regex @@ -767,7 +765,7 @@ void RE::Init(const char* regex) { delete[] full_pattern; } -#elif GTEST_USES_SIMPLE_RE +#elif defined(GTEST_USES_SIMPLE_RE) // Returns true if and only if ch appears anywhere in str (excluding the // terminating '\0' character). @@ -786,7 +784,7 @@ bool IsRepeat(char ch) { return IsInSet(ch, "?*+"); } bool IsAsciiWhiteSpace(char ch) { return IsInSet(ch, " \f\n\r\t\v"); } bool IsAsciiWordChar(char ch) { return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || - ('0' <= ch && ch <= '9') || ch == '_'; + ('0' <= ch && ch <= '9') || ch == '_'; } // Returns true if and only if "\\c" is a supported escape sequence. @@ -799,17 +797,28 @@ bool IsValidEscape(char c) { bool AtomMatchesChar(bool escaped, char pattern_char, char ch) { if (escaped) { // "\\p" where p is pattern_char. switch (pattern_char) { - case 'd': return IsAsciiDigit(ch); - case 'D': return !IsAsciiDigit(ch); - case 'f': return ch == '\f'; - case 'n': return ch == '\n'; - case 'r': return ch == '\r'; - case 's': return IsAsciiWhiteSpace(ch); - case 'S': return !IsAsciiWhiteSpace(ch); - case 't': return ch == '\t'; - case 'v': return ch == '\v'; - case 'w': return IsAsciiWordChar(ch); - case 'W': return !IsAsciiWordChar(ch); + case 'd': + return IsAsciiDigit(ch); + case 'D': + return !IsAsciiDigit(ch); + case 'f': + return ch == '\f'; + case 'n': + return ch == '\n'; + case 'r': + return ch == '\r'; + case 's': + return IsAsciiWhiteSpace(ch); + case 'S': + return !IsAsciiWhiteSpace(ch); + case 't': + return ch == '\t'; + case 'v': + return ch == '\v'; + case 'w': + return IsAsciiWordChar(ch); + case 'W': + return !IsAsciiWordChar(ch); } return IsAsciiPunct(pattern_char) && pattern_char == ch; } @@ -820,7 +829,8 @@ bool AtomMatchesChar(bool escaped, char pattern_char, char ch) { // Helper function used by ValidateRegex() to format error messages. static std::string FormatRegexSyntaxError(const char* regex, int index) { return (Message() << "Syntax error at index " << index - << " in simple regular expression \"" << regex << "\": ").GetString(); + << " in simple regular expression \"" << regex << "\": ") + .GetString(); } // Generates non-fatal failures and returns false if regex is invalid; @@ -862,12 +872,12 @@ bool ValidateRegex(const char* regex) { << "'$' can only appear at the end."; is_valid = false; } else if (IsInSet(ch, "()[]{}|")) { - ADD_FAILURE() << FormatRegexSyntaxError(regex, i) - << "'" << ch << "' is unsupported."; + ADD_FAILURE() << FormatRegexSyntaxError(regex, i) << "'" << ch + << "' is unsupported."; is_valid = false; } else if (IsRepeat(ch) && !prev_repeatable) { - ADD_FAILURE() << FormatRegexSyntaxError(regex, i) - << "'" << ch << "' can only follow a repeatable token."; + ADD_FAILURE() << FormatRegexSyntaxError(regex, i) << "'" << ch + << "' can only follow a repeatable token."; is_valid = false; } @@ -885,12 +895,10 @@ bool ValidateRegex(const char* regex) { // characters to be indexable by size_t, in which case the test will // probably time out anyway. We are fine with this limitation as // std::string has it too. -bool MatchRepetitionAndRegexAtHead( - bool escaped, char c, char repeat, const char* regex, - const char* str) { +bool MatchRepetitionAndRegexAtHead(bool escaped, char c, char repeat, + const char* regex, const char* str) { const size_t min_count = (repeat == '+') ? 1 : 0; - const size_t max_count = (repeat == '?') ? 1 : - static_cast(-1) - 1; + const size_t max_count = (repeat == '?') ? 1 : static_cast(-1) - 1; // We cannot call numeric_limits::max() as it conflicts with the // max() macro on Windows. @@ -903,8 +911,7 @@ bool MatchRepetitionAndRegexAtHead( // greedy match. return true; } - if (str[i] == '\0' || !AtomMatchesChar(escaped, c, str[i])) - return false; + if (str[i] == '\0' || !AtomMatchesChar(escaped, c, str[i])) return false; } return false; } @@ -918,25 +925,23 @@ bool MatchRegexAtHead(const char* regex, const char* str) { // "$" only matches the end of a string. Note that regex being // valid guarantees that there's nothing after "$" in it. - if (*regex == '$') - return *str == '\0'; + if (*regex == '$') return *str == '\0'; // Is the first thing in regex an escape sequence? const bool escaped = *regex == '\\'; - if (escaped) - ++regex; + if (escaped) ++regex; if (IsRepeat(regex[1])) { // MatchRepetitionAndRegexAtHead() calls MatchRegexAtHead(), so // here's an indirect recursion. It terminates as the regex gets // shorter in each recursion. - return MatchRepetitionAndRegexAtHead( - escaped, regex[0], regex[1], regex + 2, str); + return MatchRepetitionAndRegexAtHead(escaped, regex[0], regex[1], regex + 2, + str); } else { // regex isn't empty, isn't "$", and doesn't start with a // repetition. We match the first atom of regex with the first // character of str and recurse. return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) && - MatchRegexAtHead(regex + 1, str + 1); + MatchRegexAtHead(regex + 1, str + 1); } } @@ -951,40 +956,37 @@ bool MatchRegexAtHead(const char* regex, const char* str) { bool MatchRegexAnywhere(const char* regex, const char* str) { if (regex == nullptr || str == nullptr) return false; - if (*regex == '^') - return MatchRegexAtHead(regex + 1, str); + if (*regex == '^') return MatchRegexAtHead(regex + 1, str); // A successful match can be anywhere in str. do { - if (MatchRegexAtHead(regex, str)) - return true; + if (MatchRegexAtHead(regex, str)) return true; } while (*str++ != '\0'); return false; } // Implements the RE class. -RE::~RE() { - free(const_cast(pattern_)); - free(const_cast(full_pattern_)); -} +RE::~RE() = default; // Returns true if and only if regular expression re matches the entire str. bool RE::FullMatch(const char* str, const RE& re) { - return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_, str); + return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_.c_str(), str); } // Returns true if and only if regular expression re matches a substring of // str (including str itself). bool RE::PartialMatch(const char* str, const RE& re) { - return re.is_valid_ && MatchRegexAnywhere(re.pattern_, str); + return re.is_valid_ && MatchRegexAnywhere(re.pattern_.c_str(), str); } // Initializes an RE from its string representation. void RE::Init(const char* regex) { - pattern_ = full_pattern_ = nullptr; + full_pattern_.clear(); + pattern_.clear(); + if (regex != nullptr) { - pattern_ = posix::StrDup(regex); + pattern_ = regex; } is_valid_ = ValidateRegex(regex); @@ -993,25 +995,19 @@ void RE::Init(const char* regex) { return; } - const size_t len = strlen(regex); // Reserves enough bytes to hold the regular expression used for a - // full match: we need space to prepend a '^', append a '$', and - // terminate the string with '\0'. - char* buffer = static_cast(malloc(len + 3)); - full_pattern_ = buffer; + // full match: we need space to prepend a '^' and append a '$'. + full_pattern_.reserve(pattern_.size() + 2); - if (*regex != '^') - *buffer++ = '^'; // Makes sure full_pattern_ starts with '^'. + if (pattern_.empty() || pattern_.front() != '^') { + full_pattern_.push_back('^'); // Makes sure full_pattern_ starts with '^'. + } - // We don't use snprintf or strncpy, as they trigger a warning when - // compiled with VC++ 8.0. - memcpy(buffer, regex, len); - buffer += len; + full_pattern_.append(pattern_); - if (len == 0 || regex[len - 1] != '$') - *buffer++ = '$'; // Makes sure full_pattern_ ends with '$'. - - *buffer = '\0'; + if (pattern_.empty() || pattern_.back() != '$') { + full_pattern_.push_back('$'); // Makes sure full_pattern_ ends with '$'. + } } #endif // GTEST_USES_POSIX_RE @@ -1038,8 +1034,8 @@ GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) { // FormatFileLocation in order to contrast the two functions. // Note that FormatCompilerIndependentFileLocation() does NOT append colon // to the file location it produces, unlike FormatFileLocation(). -GTEST_API_ ::std::string FormatCompilerIndependentFileLocation( - const char* file, int line) { +GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file, + int line) { const std::string file_name(file == nullptr ? kUnknownFile : file); if (line < 0) @@ -1050,12 +1046,13 @@ GTEST_API_ ::std::string FormatCompilerIndependentFileLocation( GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line) : severity_(severity) { - const char* const marker = - severity == GTEST_INFO ? "[ INFO ]" : - severity == GTEST_WARNING ? "[WARNING]" : - severity == GTEST_ERROR ? "[ ERROR ]" : "[ FATAL ]"; - GetStream() << ::std::endl << marker << " " - << FormatFileLocation(file, line).c_str() << ": "; + const char* const marker = severity == GTEST_INFO ? "[ INFO ]" + : severity == GTEST_WARNING ? "[WARNING]" + : severity == GTEST_ERROR ? "[ ERROR ]" + : "[ FATAL ]"; + GetStream() << ::std::endl + << marker << " " << FormatFileLocation(file, line).c_str() + << ": "; } // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program. @@ -1067,38 +1064,47 @@ GTestLog::~GTestLog() { } } +#if GTEST_HAS_STREAM_REDIRECTION + // Disable Microsoft deprecation warnings for POSIX functions called from // this class (creat, dup, dup2, and close) GTEST_DISABLE_MSC_DEPRECATED_PUSH_() -#if GTEST_HAS_STREAM_REDIRECTION +namespace { + +#if defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_IOS) +bool EndsWithPathSeparator(const std::string& path) { + return !path.empty() && path.back() == GTEST_PATH_SEP_[0]; +} +#endif + +} // namespace // Object that captures an output stream (stdout/stderr). class CapturedStream { public: // The ctor redirects the stream to a temporary file. explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { -# if GTEST_OS_WINDOWS - char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT - char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT +#ifdef GTEST_OS_WINDOWS + char temp_dir_path[MAX_PATH + 1] = {'\0'}; // NOLINT + char temp_file_path[MAX_PATH + 1] = {'\0'}; // NOLINT ::GetTempPathA(sizeof(temp_dir_path), temp_dir_path); - const UINT success = ::GetTempFileNameA(temp_dir_path, - "gtest_redir", + const UINT success = ::GetTempFileNameA(temp_dir_path, "gtest_redir", 0, // Generate unique file name. temp_file_path); GTEST_CHECK_(success != 0) << "Unable to create a temporary file in " << temp_dir_path; const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE); - GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file " - << temp_file_path; + GTEST_CHECK_(captured_fd != -1) + << "Unable to open temporary file " << temp_file_path; filename_ = temp_file_path; -# else +#else // There's no guarantee that a test has write access to the current // directory, so we create the temporary file in a temporary directory. std::string name_template; -# if GTEST_OS_LINUX_ANDROID +#ifdef GTEST_OS_LINUX_ANDROID // Note: Android applications are expected to call the framework's // Context.getExternalStorageDirectory() method through JNI to get // the location of the world-writable SD Card directory. However, @@ -1110,8 +1116,14 @@ class CapturedStream { // The location /data/local/tmp is directly accessible from native code. // '/sdcard' and other variants cannot be relied on, as they are not // guaranteed to be mounted, or may have a delay in mounting. - name_template = "/data/local/tmp/"; -# elif GTEST_OS_IOS + // + // However, prefer using the TMPDIR environment variable if set, as newer + // devices may have /data/local/tmp read-only. + name_template = TempDir(); + if (!EndsWithPathSeparator(name_template)) + name_template.push_back(GTEST_PATH_SEP_[0]); + +#elif defined(GTEST_OS_IOS) char user_temp_dir[PATH_MAX + 1]; // Documented alternative to NSTemporaryDirectory() (for obtaining creating @@ -1130,11 +1142,11 @@ class CapturedStream { ::confstr(_CS_DARWIN_USER_TEMP_DIR, user_temp_dir, sizeof(user_temp_dir)); name_template = user_temp_dir; - if (name_template.back() != GTEST_PATH_SEP_[0]) + if (!EndsWithPathSeparator(name_template)) name_template.push_back(GTEST_PATH_SEP_[0]); -# else +#else name_template = "/tmp/"; -# endif +#endif name_template.append("gtest_captured_stream.XXXXXX"); // mkstemp() modifies the string bytes in place, and does not go beyond the @@ -1150,15 +1162,13 @@ class CapturedStream { << " for test; does the test have access to the /tmp directory?"; } filename_ = std::move(name_template); -# endif // GTEST_OS_WINDOWS +#endif // GTEST_OS_WINDOWS fflush(nullptr); dup2(captured_fd, fd_); close(captured_fd); } - ~CapturedStream() { - remove(filename_.c_str()); - } + ~CapturedStream() { remove(filename_.c_str()); } std::string GetCapturedString() { if (uncaptured_fd_ != -1) { @@ -1185,7 +1195,8 @@ class CapturedStream { // Name of the temporary file holding the stderr output. ::std::string filename_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(CapturedStream); + CapturedStream(const CapturedStream&) = delete; + CapturedStream& operator=(const CapturedStream&) = delete; }; GTEST_DISABLE_MSC_DEPRECATED_POP_() @@ -1213,6 +1224,15 @@ static std::string GetCapturedStream(CapturedStream** captured_stream) { return content; } +#if defined(_MSC_VER) || defined(__BORLANDC__) +// MSVC and C++Builder do not provide a definition of STDERR_FILENO. +const int kStdOutFileno = 1; +const int kStdErrFileno = 2; +#else +const int kStdOutFileno = STDOUT_FILENO; +const int kStdErrFileno = STDERR_FILENO; +#endif // defined(_MSC_VER) || defined(__BORLANDC__) + // Starts capturing stdout. void CaptureStdout() { CaptureStream(kStdOutFileno, "stdout", &g_captured_stdout); @@ -1235,10 +1255,6 @@ std::string GetCapturedStderr() { #endif // GTEST_HAS_STREAM_REDIRECTION - - - - size_t GetFileSize(FILE* file) { fseek(file, 0, SEEK_END); return static_cast(ftell(file)); @@ -1256,7 +1272,8 @@ std::string ReadEntireFile(FILE* file) { // Keeps reading the file until we cannot read further or the // pre-determined file size is reached. do { - bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file); + bytes_last_read = + fread(buffer + bytes_read, 1, file_size - bytes_read, file); bytes_read += bytes_last_read; } while (bytes_last_read > 0 && bytes_read < file_size); @@ -1266,7 +1283,7 @@ std::string ReadEntireFile(FILE* file) { return content; } -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST static const std::vector* g_injected_test_argvs = nullptr; // Owned. @@ -1293,7 +1310,7 @@ void ClearInjectableArgvs() { } #endif // GTEST_HAS_DEATH_TEST -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE namespace posix { void Abort() { DebugBreak(); @@ -1344,11 +1361,11 @@ bool ParseInt32(const Message& src_text, const char* str, int32_t* value) { // LONG_MAX or LONG_MIN when the input overflows.) result != long_value // The parsed value overflows as an int32_t. - ) { + ) { Message msg; msg << "WARNING: " << src_text - << " is expected to be a 32-bit integer, but actually" - << " has value " << str << ", which overflows.\n"; + << " is expected to be a 32-bit integer, but actually" << " has value " + << str << ", which overflows.\n"; printf("%s", msg.GetString().c_str()); fflush(stdout); return false; @@ -1388,8 +1405,8 @@ int32_t Int32FromGTestEnv(const char* flag, int32_t default_value) { } int32_t result = default_value; - if (!ParseInt32(Message() << "Environment variable " << env_var, - string_value, &result)) { + if (!ParseInt32(Message() << "Environment variable " << env_var, string_value, + &result)) { printf("The default value %s is used.\n", (Message() << default_value).GetString().c_str()); fflush(stdout); @@ -1408,7 +1425,7 @@ int32_t Int32FromGTestEnv(const char* flag, int32_t default_value) { // not check that the flag is 'output' // In essence this checks an env variable called XML_OUTPUT_FILE // and if it is set we prepend "xml:" to its value, if it not set we return "" -std::string OutputFlagAlsoCheckEnvVar(){ +std::string OutputFlagAlsoCheckEnvVar() { std::string default_value_for_output_flag = ""; const char* xml_output_file_env = posix::GetEnv("XML_OUTPUT_FILE"); if (nullptr != xml_output_file_env) { diff --git a/libs/libvpx/third_party/googletest/src/src/gtest-printers.cc b/libs/libvpx/third_party/googletest/src/src/gtest-printers.cc index 1b68fcb500..e3acecba8e 100644 --- a/libs/libvpx/third_party/googletest/src/src/gtest-printers.cc +++ b/libs/libvpx/third_party/googletest/src/src/gtest-printers.cc @@ -27,7 +27,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - // Google Test - The Google C++ Testing and Mocking Framework // // This file implements a universal value printer that can print a @@ -48,6 +47,8 @@ #include #include #include +#include +#include #include // NOLINT #include #include @@ -101,7 +102,7 @@ void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count, PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os); *os << " ... "; // Rounds up to 2-byte boundary. - const size_t resume_pos = (count - kChunkSize + 1)/2*2; + const size_t resume_pos = (count - kChunkSize + 1) / 2 * 2; PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os); } *os << ">"; @@ -136,11 +137,7 @@ void PrintBytesInObjectTo(const unsigned char* obj_bytes, size_t count, // - as is if it's a printable ASCII (e.g. 'a', '2', ' '), // - as a hexadecimal escape sequence (e.g. '\x7F'), or // - as a special escape sequence (e.g. '\r', '\n'). -enum CharFormat { - kAsIs, - kHexEscape, - kSpecialEscape -}; +enum CharFormat { kAsIs, kHexEscape, kSpecialEscape }; // Returns true if c is a printable ASCII character. We test the // value of c directly instead of calling isprint(), which is buggy on @@ -213,35 +210,21 @@ static CharFormat PrintAsStringLiteralTo(char32_t c, ostream* os) { } } -static const char* GetCharWidthPrefix(char) { - return ""; -} +static const char* GetCharWidthPrefix(char) { return ""; } -static const char* GetCharWidthPrefix(signed char) { - return ""; -} +static const char* GetCharWidthPrefix(signed char) { return ""; } -static const char* GetCharWidthPrefix(unsigned char) { - return ""; -} +static const char* GetCharWidthPrefix(unsigned char) { return ""; } -#ifdef __cpp_char8_t -static const char* GetCharWidthPrefix(char8_t) { - return "u8"; -} +#ifdef __cpp_lib_char8_t +static const char* GetCharWidthPrefix(char8_t) { return "u8"; } #endif -static const char* GetCharWidthPrefix(char16_t) { - return "u"; -} +static const char* GetCharWidthPrefix(char16_t) { return "u"; } -static const char* GetCharWidthPrefix(char32_t) { - return "U"; -} +static const char* GetCharWidthPrefix(char32_t) { return "U"; } -static const char* GetCharWidthPrefix(wchar_t) { - return "L"; -} +static const char* GetCharWidthPrefix(wchar_t) { return "L"; } // Prints a char c as if it's part of a string literal, escaping it when // necessary; returns how c was formatted. @@ -249,7 +232,7 @@ static CharFormat PrintAsStringLiteralTo(char c, ostream* os) { return PrintAsStringLiteralTo(ToChar32(c), os); } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t static CharFormat PrintAsStringLiteralTo(char8_t c, ostream* os) { return PrintAsStringLiteralTo(ToChar32(c), os); } @@ -276,8 +259,7 @@ void PrintCharAndCodeTo(Char c, ostream* os) { // To aid user debugging, we also print c's code in decimal, unless // it's 0 (in which case c was printed as '\\0', making the code // obvious). - if (c == 0) - return; + if (c == 0) return; *os << " (" << static_cast(c); // For more convenience, we print c's code again in hexadecimal, @@ -304,17 +286,60 @@ void PrintTo(char32_t c, ::std::ostream* os) { << static_cast(c); } +// gcc/clang __{u,}int128_t +#if defined(__SIZEOF_INT128__) +void PrintTo(__uint128_t v, ::std::ostream* os) { + if (v == 0) { + *os << "0"; + return; + } + + // Buffer large enough for ceil(log10(2^128))==39 and the null terminator + char buf[40]; + char* p = buf + sizeof(buf); + + // Some configurations have a __uint128_t, but no support for built in + // division. Do manual long division instead. + + uint64_t high = static_cast(v >> 64); + uint64_t low = static_cast(v); + + *--p = 0; + while (high != 0 || low != 0) { + uint64_t high_mod = high % 10; + high = high / 10; + // This is the long division algorithm specialized for a divisor of 10 and + // only two elements. + // Notable values: + // 2^64 / 10 == 1844674407370955161 + // 2^64 % 10 == 6 + const uint64_t carry = 6 * high_mod + low % 10; + low = low / 10 + high_mod * 1844674407370955161 + carry / 10; + + char digit = static_cast(carry % 10); + *--p = static_cast('0' + digit); + } + *os << p; +} +void PrintTo(__int128_t v, ::std::ostream* os) { + __uint128_t uv = static_cast<__uint128_t>(v); + if (v < 0) { + *os << "-"; + uv = -uv; + } + PrintTo(uv, os); +} +#endif // __SIZEOF_INT128__ + // Prints the given array of characters to the ostream. CharType must be either // char, char8_t, char16_t, char32_t, or wchar_t. // The array starts at begin, the length is len, it may include '\0' characters // and may not be NUL-terminated. template -GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ -GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ -GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ -GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ -static CharFormat PrintCharsAsStringTo( - const CharType* begin, size_t len, ostream* os) { +GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ + GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ + GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ static CharFormat + PrintCharsAsStringTo(const CharType* begin, size_t len, ostream* os) { const char* const quote_prefix = GetCharWidthPrefix(*begin); *os << quote_prefix << "\""; bool is_previous_hex = false; @@ -340,12 +365,11 @@ static CharFormat PrintCharsAsStringTo( // Prints a (const) char/wchar_t array of 'len' elements, starting at address // 'begin'. CharType must be either char or wchar_t. template -GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ -GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ -GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ -GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ -static void UniversalPrintCharArray( - const CharType* begin, size_t len, ostream* os) { +GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ + GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ + GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ static void + UniversalPrintCharArray(const CharType* begin, size_t len, + ostream* os) { // The code // const char kFoo[] = "foo"; // generates an array of 4, not 3, elements, with the last one being '\0'. @@ -371,7 +395,7 @@ void UniversalPrintArray(const char* begin, size_t len, ostream* os) { UniversalPrintCharArray(begin, len, os); } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t // Prints a (const) char8_t array of 'len' elements, starting at address // 'begin'. void UniversalPrintArray(const char8_t* begin, size_t len, ostream* os) { @@ -414,7 +438,7 @@ void PrintCStringTo(const Char* s, ostream* os) { void PrintTo(const char* s, ostream* os) { PrintCStringTo(s, os); } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t void PrintTo(const char8_t* s, ostream* os) { PrintCStringTo(s, os); } #endif @@ -436,28 +460,28 @@ void PrintTo(const wchar_t* s, ostream* os) { PrintCStringTo(s, os); } namespace { bool ContainsUnprintableControlCodes(const char* str, size_t length) { - const unsigned char *s = reinterpret_cast(str); + const unsigned char* s = reinterpret_cast(str); for (size_t i = 0; i < length; i++) { unsigned char ch = *s++; if (std::iscntrl(ch)) { - switch (ch) { + switch (ch) { case '\t': case '\n': case '\r': break; default: return true; - } } + } } return false; } -bool IsUTF8TrailByte(unsigned char t) { return 0x80 <= t && t<= 0xbf; } +bool IsUTF8TrailByte(unsigned char t) { return 0x80 <= t && t <= 0xbf; } bool IsValidUTF8(const char* str, size_t length) { - const unsigned char *s = reinterpret_cast(str); + const unsigned char* s = reinterpret_cast(str); for (size_t i = 0; i < length;) { unsigned char lead = s[i++]; @@ -470,15 +494,13 @@ bool IsValidUTF8(const char* str, size_t length) { } else if (lead <= 0xdf && (i + 1) <= length && IsUTF8TrailByte(s[i])) { ++i; // 2-byte character } else if (0xe0 <= lead && lead <= 0xef && (i + 2) <= length && - IsUTF8TrailByte(s[i]) && - IsUTF8TrailByte(s[i + 1]) && + IsUTF8TrailByte(s[i]) && IsUTF8TrailByte(s[i + 1]) && // check for non-shortest form and surrogate (lead != 0xe0 || s[i] >= 0xa0) && (lead != 0xed || s[i] < 0xa0)) { i += 2; // 3-byte character } else if (0xf0 <= lead && lead <= 0xf4 && (i + 3) <= length && - IsUTF8TrailByte(s[i]) && - IsUTF8TrailByte(s[i + 1]) && + IsUTF8TrailByte(s[i]) && IsUTF8TrailByte(s[i + 1]) && IsUTF8TrailByte(s[i + 2]) && // check for non-shortest form (lead != 0xf0 || s[i] >= 0x90) && @@ -502,13 +524,13 @@ void ConditionalPrintAsText(const char* str, size_t length, ostream* os) { void PrintStringTo(const ::std::string& s, ostream* os) { if (PrintCharsAsStringTo(s.data(), s.size(), os) == kHexEscape) { - if (GTEST_FLAG(print_utf8)) { + if (GTEST_FLAG_GET(print_utf8)) { ConditionalPrintAsText(s.data(), s.size(), os); } } } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t void PrintU8StringTo(const ::std::u8string& s, ostream* os) { PrintCharsAsStringTo(s.data(), s.size(), os); } diff --git a/libs/libvpx/third_party/googletest/src/src/gtest-test-part.cc b/libs/libvpx/third_party/googletest/src/src/gtest-test-part.cc index a938683ced..6f8ddd7c48 100644 --- a/libs/libvpx/third_party/googletest/src/src/gtest-test-part.cc +++ b/libs/libvpx/third_party/googletest/src/src/gtest-test-part.cc @@ -32,13 +32,14 @@ #include "gtest/gtest-test-part.h" +#include +#include + #include "gtest/internal/gtest-port.h" #include "src/gtest-internal-inl.h" namespace testing { -using internal::GetUnitTestImpl; - // Gets the summary of the failure message by omitting the stack trace // in it. std::string TestPartResult::ExtractSummary(const char* message) { @@ -51,13 +52,11 @@ std::ostream& operator<<(std::ostream& os, const TestPartResult& result) { return os << internal::FormatFileLocation(result.file_name(), result.line_number()) << " " - << (result.type() == TestPartResult::kSuccess - ? "Success" - : result.type() == TestPartResult::kSkip - ? "Skipped" - : result.type() == TestPartResult::kFatalFailure - ? "Fatal failure" - : "Non-fatal failure") + << (result.type() == TestPartResult::kSuccess ? "Success" + : result.type() == TestPartResult::kSkip ? "Skipped" + : result.type() == TestPartResult::kFatalFailure + ? "Fatal failure" + : "Non-fatal failure") << ":\n" << result.message() << std::endl; } @@ -86,8 +85,8 @@ namespace internal { HasNewFatalFailureHelper::HasNewFatalFailureHelper() : has_new_fatal_failure_(false), - original_reporter_(GetUnitTestImpl()-> - GetTestPartResultReporterForCurrentThread()) { + original_reporter_( + GetUnitTestImpl()->GetTestPartResultReporterForCurrentThread()) { GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this); } @@ -98,8 +97,7 @@ HasNewFatalFailureHelper::~HasNewFatalFailureHelper() { void HasNewFatalFailureHelper::ReportTestPartResult( const TestPartResult& result) { - if (result.fatally_failed()) - has_new_fatal_failure_ = true; + if (result.fatally_failed()) has_new_fatal_failure_ = true; original_reporter_->ReportTestPartResult(result); } diff --git a/libs/libvpx/third_party/googletest/src/src/gtest-typed-test.cc b/libs/libvpx/third_party/googletest/src/src/gtest-typed-test.cc index c02c3df659..b251c09deb 100644 --- a/libs/libvpx/third_party/googletest/src/src/gtest-typed-test.cc +++ b/libs/libvpx/third_party/googletest/src/src/gtest-typed-test.cc @@ -27,9 +27,12 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "gtest/gtest-typed-test.h" +#include +#include +#include + #include "gtest/gtest.h" namespace testing { @@ -38,8 +41,7 @@ namespace internal { // Skips to the first non-space char in str. Returns an empty string if str // contains only whitespace characters. static const char* SkipSpaces(const char* str) { - while (IsSpace(*str)) - str++; + while (IsSpace(*str)) str++; return str; } @@ -85,15 +87,14 @@ const char* TypedTestSuitePState::VerifyRegisteredTestNames( } for (RegisteredTestIter it = registered_tests_.begin(); - it != registered_tests_.end(); - ++it) { + it != registered_tests_.end(); ++it) { if (tests.count(it->first) == 0) { errors << "You forgot to list test " << it->first << ".\n"; } } const std::string& errors_str = errors.GetString(); - if (errors_str != "") { + if (!errors_str.empty()) { fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), errors_str.c_str()); fflush(stderr); diff --git a/libs/libvpx/third_party/googletest/src/src/gtest.cc b/libs/libvpx/third_party/googletest/src/src/gtest.cc index 21c611aff1..09af15179f 100644 --- a/libs/libvpx/third_party/googletest/src/src/gtest.cc +++ b/libs/libvpx/third_party/googletest/src/src/gtest.cc @@ -31,8 +31,6 @@ // The Google C++ Testing and Mocking Framework (Google Test) #include "gtest/gtest.h" -#include "gtest/internal/custom/gtest.h" -#include "gtest/gtest-spi.h" #include #include @@ -45,95 +43,129 @@ #include #include // NOLINT #include +#include // NOLINT: raise(3) is used on some platforms #include +#include +#include +#include #include +#include +#include +#include #include #include #include #include // NOLINT +#include #include +#include +#include #include -#if GTEST_OS_LINUX +#include "gtest/gtest-assertion-result.h" +#include "gtest/gtest-spi.h" +#include "gtest/internal/custom/gtest.h" +#include "gtest/internal/gtest-port.h" -# include // NOLINT -# include // NOLINT -# include // NOLINT +#ifdef GTEST_OS_LINUX + +#include // NOLINT +#include // NOLINT +#include // NOLINT // Declares vsnprintf(). This header is not available on Windows. -# include // NOLINT -# include // NOLINT -# include // NOLINT -# include // NOLINT -# include +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT -#elif GTEST_OS_ZOS -# include // NOLINT +#include + +#elif defined(GTEST_OS_ZOS) +#include // NOLINT // On z/OS we additionally need strings.h for strcasecmp. -# include // NOLINT +#include // NOLINT -#elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE. +#elif defined(GTEST_OS_WINDOWS_MOBILE) // We are on Windows CE. -# include // NOLINT -# undef min +#include // NOLINT +#undef min -#elif GTEST_OS_WINDOWS // We are on Windows proper. +#elif defined(GTEST_OS_WINDOWS) // We are on Windows proper. -# include // NOLINT -# undef min +#include // NOLINT +#undef min #ifdef _MSC_VER -# include // NOLINT +#include // NOLINT #endif -# include // NOLINT -# include // NOLINT -# include // NOLINT -# include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT -# if GTEST_OS_WINDOWS_MINGW -# include // NOLINT -# endif // GTEST_OS_WINDOWS_MINGW +#ifdef GTEST_OS_WINDOWS_MINGW +#include // NOLINT +#endif // GTEST_OS_WINDOWS_MINGW #else // cpplint thinks that the header is already included, so we want to // silence it. -# include // NOLINT -# include // NOLINT +#include // NOLINT +#include // NOLINT #endif // GTEST_OS_LINUX #if GTEST_HAS_EXCEPTIONS -# include +#include #endif #if GTEST_CAN_STREAM_RESULTS_ -# include // NOLINT -# include // NOLINT -# include // NOLINT -# include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT #endif #include "src/gtest-internal-inl.h" -#if GTEST_OS_WINDOWS -# define vsnprintf _vsnprintf +#ifdef GTEST_OS_WINDOWS +#define vsnprintf _vsnprintf #endif // GTEST_OS_WINDOWS -#if GTEST_OS_MAC +#ifdef GTEST_OS_MAC #ifndef GTEST_OS_IOS #include #endif #endif -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL +#include "absl/container/flat_hash_set.h" #include "absl/debugging/failure_signal_handler.h" #include "absl/debugging/stacktrace.h" #include "absl/debugging/symbolize.h" +#include "absl/flags/parse.h" +#include "absl/flags/usage.h" #include "absl/strings/str_cat.h" +#include "absl/strings/str_replace.h" +#include "absl/strings/string_view.h" +#include "absl/strings/strip.h" #endif // GTEST_HAS_ABSL +// Checks builtin compiler feature |x| while avoiding an extra layer of #ifdefs +// at the callsite. +#if defined(__has_builtin) +#define GTEST_HAS_BUILTIN(x) __has_builtin(x) +#else +#define GTEST_HAS_BUILTIN(x) 0 +#endif // defined(__has_builtin) + +#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS) +#define GTEST_HAS_ABSL_FLAGS +#endif + namespace testing { using internal::CountIf; @@ -160,12 +192,17 @@ static const char kDefaultOutputFormat[] = "xml"; // The default output file. static const char kDefaultOutputFile[] = "test_detail"; +// These environment variables are set by Bazel. +// https://bazel.build/reference/test-encyclopedia#initial-conditions +// // The environment variable name for the test shard index. static const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; // The environment variable name for the total number of test shards. static const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; // The environment variable name for the test shard status file. static const char kTestShardStatusFile[] = "GTEST_SHARD_STATUS_FILE"; +// The environment variable name for the test output warnings file. +static const char kTestWarningsOutputFile[] = "TEST_WARNINGS_OUTPUT_FILE"; namespace internal { @@ -177,7 +214,8 @@ const char kStackTraceMarker[] = "\nStack trace:\n"; // is specified on the command line. bool g_help_flag = false; -// Utilty function to Open File for Writing +#if GTEST_HAS_FILE_SYSTEM +// Utility function to Open File for Writing static FILE* OpenFileForWriting(const std::string& output_file) { FILE* fileout = nullptr; FilePath output_file_path(output_file); @@ -191,6 +229,7 @@ static FILE* OpenFileForWriting(const std::string& output_file) { } return fileout; } +#endif // GTEST_HAS_FILE_SYSTEM } // namespace internal @@ -216,28 +255,39 @@ static bool GetDefaultFailFast() { return false; } +} // namespace testing + GTEST_DEFINE_bool_( - fail_fast, internal::BoolFromGTestEnv("fail_fast", GetDefaultFailFast()), + fail_fast, + testing::internal::BoolFromGTestEnv("fail_fast", + testing::GetDefaultFailFast()), "True if and only if a test failure should stop further test execution."); +GTEST_DEFINE_bool_( + fail_if_no_test_linked, + testing::internal::BoolFromGTestEnv("fail_if_no_test_linked", false), + "True if and only if the test should fail if no test case (including " + "disabled test cases) is linked."); + GTEST_DEFINE_bool_( also_run_disabled_tests, - internal::BoolFromGTestEnv("also_run_disabled_tests", false), + testing::internal::BoolFromGTestEnv("also_run_disabled_tests", false), "Run disabled tests too, in addition to the tests normally being run."); GTEST_DEFINE_bool_( - break_on_failure, internal::BoolFromGTestEnv("break_on_failure", false), + break_on_failure, + testing::internal::BoolFromGTestEnv("break_on_failure", false), "True if and only if a failed assertion should be a debugger " "break-point."); GTEST_DEFINE_bool_(catch_exceptions, - internal::BoolFromGTestEnv("catch_exceptions", true), + testing::internal::BoolFromGTestEnv("catch_exceptions", + true), "True if and only if " GTEST_NAME_ " should catch exceptions and treat them as test failures."); GTEST_DEFINE_string_( - color, - internal::StringFromGTestEnv("color", "auto"), + color, testing::internal::StringFromGTestEnv("color", "auto"), "Whether to use colors in the output. Valid values: yes, no, " "and auto. 'auto' means to use colors if the output is " "being sent to a terminal and the TERM environment variable " @@ -245,7 +295,8 @@ GTEST_DEFINE_string_( GTEST_DEFINE_string_( filter, - internal::StringFromGTestEnv("filter", GetDefaultFilter()), + testing::internal::StringFromGTestEnv("filter", + testing::GetDefaultFilter()), "A colon-separated list of glob (not regex) patterns " "for filtering the tests to run, optionally followed by a " "'-' and a : separated list of negative patterns (tests to " @@ -254,13 +305,14 @@ GTEST_DEFINE_string_( GTEST_DEFINE_bool_( install_failure_signal_handler, - internal::BoolFromGTestEnv("install_failure_signal_handler", false), - "If true and supported on the current platform, " GTEST_NAME_ " should " + testing::internal::BoolFromGTestEnv("install_failure_signal_handler", + false), + "If true and supported on the current platform, " GTEST_NAME_ + " should " "install a signal handler that dumps debugging information when fatal " "signals are raised."); -GTEST_DEFINE_bool_(list_tests, false, - "List all tests without running them."); +GTEST_DEFINE_bool_(list_tests, false, "List all tests without running them."); // The net priority order after flag processing is thus: // --gtest_output command line flag @@ -269,8 +321,8 @@ GTEST_DEFINE_bool_(list_tests, false, // '' GTEST_DEFINE_string_( output, - internal::StringFromGTestEnv("output", - internal::OutputFlagAlsoCheckEnvVar().c_str()), + testing::internal::StringFromGTestEnv( + "output", testing::internal::OutputFlagAlsoCheckEnvVar().c_str()), "A format (defaults to \"xml\" but can be specified to be \"json\"), " "optionally followed by a colon and an output file name or directory. " "A directory is indicated by a trailing pathname separator. " @@ -281,77 +333,92 @@ GTEST_DEFINE_string_( "digits."); GTEST_DEFINE_bool_( - brief, internal::BoolFromGTestEnv("brief", false), + brief, testing::internal::BoolFromGTestEnv("brief", false), "True if only test failures should be displayed in text output."); -GTEST_DEFINE_bool_(print_time, internal::BoolFromGTestEnv("print_time", true), +GTEST_DEFINE_bool_(print_time, + testing::internal::BoolFromGTestEnv("print_time", true), "True if and only if " GTEST_NAME_ " should display elapsed time in text output."); -GTEST_DEFINE_bool_(print_utf8, internal::BoolFromGTestEnv("print_utf8", true), +GTEST_DEFINE_bool_(print_utf8, + testing::internal::BoolFromGTestEnv("print_utf8", true), "True if and only if " GTEST_NAME_ " prints UTF8 characters as text."); GTEST_DEFINE_int32_( - random_seed, - internal::Int32FromGTestEnv("random_seed", 0), + random_seed, testing::internal::Int32FromGTestEnv("random_seed", 0), "Random number seed to use when shuffling test orders. Must be in range " "[1, 99999], or 0 to use a seed based on the current time."); GTEST_DEFINE_int32_( - repeat, - internal::Int32FromGTestEnv("repeat", 1), + repeat, testing::internal::Int32FromGTestEnv("repeat", 1), "How many times to repeat each test. Specify a negative number " "for repeating forever. Useful for shaking out flaky tests."); +GTEST_DEFINE_bool_( + recreate_environments_when_repeating, + testing::internal::BoolFromGTestEnv("recreate_environments_when_repeating", + false), + "Controls whether global test environments are recreated for each repeat " + "of the tests. If set to false the global test environments are only set " + "up once, for the first iteration, and only torn down once, for the last. " + "Useful for shaking out flaky tests with stable, expensive test " + "environments. If --gtest_repeat is set to a negative number, meaning " + "there is no last run, the environments will always be recreated to avoid " + "leaks."); + GTEST_DEFINE_bool_(show_internal_stack_frames, false, "True if and only if " GTEST_NAME_ " should include internal stack frames when " "printing test failure stack traces."); -GTEST_DEFINE_bool_(shuffle, internal::BoolFromGTestEnv("shuffle", false), +GTEST_DEFINE_bool_(shuffle, + testing::internal::BoolFromGTestEnv("shuffle", false), "True if and only if " GTEST_NAME_ " should randomize tests' order on every run."); GTEST_DEFINE_int32_( stack_trace_depth, - internal::Int32FromGTestEnv("stack_trace_depth", kMaxStackTraceDepth), + testing::internal::Int32FromGTestEnv("stack_trace_depth", + testing::kMaxStackTraceDepth), "The maximum number of stack frames to print when an " "assertion fails. The valid range is 0 through 100, inclusive."); GTEST_DEFINE_string_( stream_result_to, - internal::StringFromGTestEnv("stream_result_to", ""), + testing::internal::StringFromGTestEnv("stream_result_to", ""), "This flag specifies the host name and the port number on which to stream " "test results. Example: \"localhost:555\". The flag is effective only on " - "Linux."); + "Linux and macOS."); GTEST_DEFINE_bool_( throw_on_failure, - internal::BoolFromGTestEnv("throw_on_failure", false), + testing::internal::BoolFromGTestEnv("throw_on_failure", false), "When this flag is specified, a failed assertion will throw an exception " "if exceptions are enabled or exit the program with a non-zero code " "otherwise. For use with an external test framework."); #if GTEST_USE_OWN_FLAGFILE_FLAG_ GTEST_DEFINE_string_( - flagfile, - internal::StringFromGTestEnv("flagfile", ""), + flagfile, testing::internal::StringFromGTestEnv("flagfile", ""), "This flag specifies the flagfile to read command-line flags from."); #endif // GTEST_USE_OWN_FLAGFILE_FLAG_ +namespace testing { namespace internal { +const uint32_t Random::kMaxRange; + // Generates a random number from [0, range), using a Linear // Congruential Generator (LCG). Crashes if 'range' is 0 or greater // than kMaxRange. uint32_t Random::Generate(uint32_t range) { // These constants are the same as are used in glibc's rand(3). // Use wider types than necessary to prevent unsigned overflow diagnostics. - state_ = static_cast(1103515245ULL*state_ + 12345U) % kMaxRange; + state_ = static_cast(1103515245ULL * state_ + 12345U) % kMaxRange; - GTEST_CHECK_(range > 0) - << "Cannot generate a number in the range [0, 0)."; + GTEST_CHECK_(range > 0) << "Cannot generate a number in the range [0, 0)."; GTEST_CHECK_(range <= kMaxRange) << "Generation of a number in [0, " << range << ") was requested, " << "but this can only generate numbers in [0, " << kMaxRange << ")."; @@ -365,7 +432,7 @@ uint32_t Random::Generate(uint32_t range) { // GTestIsInitialized() returns true if and only if the user has initialized // Google Test. Useful for catching the user mistake of not initializing // Google Test before calling RUN_ALL_TESTS(). -static bool GTestIsInitialized() { return GetArgvs().size() > 0; } +static bool GTestIsInitialized() { return !GetArgvs().empty(); } // Iterates over a vector of TestSuites, keeping a running sum of the // results of calling a given int-returning method on each. @@ -395,33 +462,42 @@ static bool ShouldRunTestSuite(const TestSuite* test_suite) { return test_suite->should_run(); } -// AssertHelper constructor. -AssertHelper::AssertHelper(TestPartResult::Type type, - const char* file, - int line, - const char* message) - : data_(new AssertHelperData(type, file, line, message)) { +namespace { + +// Returns true if test part results of type `type` should include a stack +// trace. +bool ShouldEmitStackTraceForResultType(TestPartResult::Type type) { + // Suppress emission of the stack trace for SUCCEED() since it likely never + // requires investigation, and GTEST_SKIP() since skipping is an intentional + // act by the developer rather than a failure requiring investigation. + return type != TestPartResult::kSuccess && type != TestPartResult::kSkip; } -AssertHelper::~AssertHelper() { - delete data_; -} +} // namespace + +// AssertHelper constructor. +AssertHelper::AssertHelper(TestPartResult::Type type, const char* file, + int line, const char* message) + : data_(new AssertHelperData(type, file, line, message)) {} + +AssertHelper::~AssertHelper() { delete data_; } // Message assignment, for assertion streaming support. void AssertHelper::operator=(const Message& message) const { - UnitTest::GetInstance()-> - AddTestPartResult(data_->type, data_->file, data_->line, - AppendUserMessage(data_->message, message), - UnitTest::GetInstance()->impl() - ->CurrentOsStackTraceExceptTop(1) - // Skips the stack frame for this function itself. - ); // NOLINT + UnitTest::GetInstance()->AddTestPartResult( + data_->type, data_->file, data_->line, + AppendUserMessage(data_->message, message), + ShouldEmitStackTraceForResultType(data_->type) + ? UnitTest::GetInstance()->impl()->CurrentOsStackTraceExceptTop(1) + : "" + // Skips the stack frame for this function itself. + ); // NOLINT } namespace { // When TEST_P is found without a matching INSTANTIATE_TEST_SUITE_P -// to creates test cases for it, a syntetic test case is +// to creates test cases for it, a synthetic test case is // inserted to report ether an error or a log message. // // This configuration bit will likely be removed at some point. @@ -452,7 +528,6 @@ class FailureTest : public Test { const bool as_error_; }; - } // namespace std::set* GetIgnoredParameterizedTestSuites() { @@ -472,7 +547,8 @@ void InsertSyntheticTestCase(const std::string& name, CodeLocation location, if (ignored.find(name) != ignored.end()) return; const char kMissingInstantiation[] = // - " is defined via TEST_P, but never instantiated. None of the test cases " + " is defined via TEST_P, but never instantiated. None of the test " + "cases " "will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only " "ones provided expand to nothing." "\n\n" @@ -496,7 +572,8 @@ void InsertSyntheticTestCase(const std::string& name, CodeLocation location, "To suppress this error for this test suite, insert the following line " "(in a non-header) in the namespace it is defined in:" "\n\n" - "GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(" + name + ");"; + "GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(" + + name + ");"; std::string full_name = "UninstantiatedParameterizedTestSuite<" + name + ">"; RegisterTest( // @@ -512,23 +589,22 @@ void InsertSyntheticTestCase(const std::string& name, CodeLocation location, void RegisterTypeParameterizedTestSuite(const char* test_suite_name, CodeLocation code_location) { GetUnitTestImpl()->type_parameterized_test_registry().RegisterTestSuite( - test_suite_name, code_location); + test_suite_name, std::move(code_location)); } void RegisterTypeParameterizedTestSuiteInstantiation(const char* case_name) { - GetUnitTestImpl() - ->type_parameterized_test_registry() - .RegisterInstantiation(case_name); + GetUnitTestImpl()->type_parameterized_test_registry().RegisterInstantiation( + case_name); } void TypeParameterizedTestSuiteRegistry::RegisterTestSuite( const char* test_suite_name, CodeLocation code_location) { suites_.emplace(std::string(test_suite_name), - TypeParameterizedTestSuiteInfo(code_location)); + TypeParameterizedTestSuiteInfo(std::move(code_location))); } void TypeParameterizedTestSuiteRegistry::RegisterInstantiation( - const char* test_suite_name) { + const char* test_suite_name) { auto it = suites_.find(std::string(test_suite_name)); if (it != suites_.end()) { it->second.instantiated = true; @@ -551,10 +627,12 @@ void TypeParameterizedTestSuiteRegistry::CheckForInstantiations() { "\n\n" "Ideally, TYPED_TEST_P definitions should only ever be included as " "part of binaries that intend to use them. (As opposed to, for " - "example, being placed in a library that may be linked in to get other " + "example, being placed in a library that may be linked in to get " + "other " "utilities.)" "\n\n" - "To suppress this error for this test suite, insert the following line " + "To suppress this error for this test suite, insert the following " + "line " "(in a non-header) in the namespace it is defined in:" "\n\n" "GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(" + @@ -588,25 +666,31 @@ static ::std::vector g_argvs; #endif // defined(GTEST_CUSTOM_GET_ARGVS_) } +#if GTEST_HAS_FILE_SYSTEM // Returns the current application's name, removing directory path if that // is present. FilePath GetCurrentExecutableName() { FilePath result; -#if GTEST_OS_WINDOWS || GTEST_OS_OS2 - result.Set(FilePath(GetArgvs()[0]).RemoveExtension("exe")); + auto args = GetArgvs(); + if (!args.empty()) { +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_OS2) + result.Set(FilePath(args[0]).RemoveExtension("exe")); #else - result.Set(FilePath(GetArgvs()[0])); + result.Set(FilePath(args[0])); #endif // GTEST_OS_WINDOWS + } return result.RemoveDirectoryName(); } +#endif // GTEST_HAS_FILE_SYSTEM // Functions for processing the gtest_output flag. // Returns the output format, or "" for normal printed output. std::string UnitTestOptions::GetOutputFormat() { - const char* const gtest_output_flag = GTEST_FLAG(output).c_str(); + std::string s = GTEST_FLAG_GET(output); + const char* const gtest_output_flag = s.c_str(); const char* const colon = strchr(gtest_output_flag, ':'); return (colon == nullptr) ? std::string(gtest_output_flag) @@ -614,22 +698,23 @@ std::string UnitTestOptions::GetOutputFormat() { static_cast(colon - gtest_output_flag)); } +#if GTEST_HAS_FILE_SYSTEM // Returns the name of the requested output file, or the default if none // was explicitly specified. std::string UnitTestOptions::GetAbsolutePathToOutputFile() { - const char* const gtest_output_flag = GTEST_FLAG(output).c_str(); + std::string s = GTEST_FLAG_GET(output); + const char* const gtest_output_flag = s.c_str(); std::string format = GetOutputFormat(); - if (format.empty()) - format = std::string(kDefaultOutputFormat); + if (format.empty()) format = std::string(kDefaultOutputFormat); const char* const colon = strchr(gtest_output_flag, ':'); if (colon == nullptr) return internal::FilePath::MakeFileName( - internal::FilePath( - UnitTest::GetInstance()->original_working_dir()), - internal::FilePath(kDefaultOutputFile), 0, - format.c_str()).string(); + internal::FilePath( + UnitTest::GetInstance()->original_working_dir()), + internal::FilePath(kDefaultOutputFile), 0, format.c_str()) + .string(); internal::FilePath output_name(colon + 1); if (!output_name.IsAbsolutePath()) @@ -637,14 +722,14 @@ std::string UnitTestOptions::GetAbsolutePathToOutputFile() { internal::FilePath(UnitTest::GetInstance()->original_working_dir()), internal::FilePath(colon + 1)); - if (!output_name.IsDirectory()) - return output_name.string(); + if (!output_name.IsDirectory()) return output_name.string(); internal::FilePath result(internal::FilePath::GenerateUniqueFileName( output_name, internal::GetCurrentExecutableName(), GetOutputFormat().c_str())); return result.string(); } +#endif // GTEST_HAS_FILE_SYSTEM // Returns true if and only if the wildcard pattern matches the string. Each // pattern consists of regular characters, single-character wildcards (?), and @@ -699,86 +784,155 @@ static bool PatternMatchesString(const std::string& name_str, return true; } +namespace { + +bool IsGlobPattern(const std::string& pattern) { + return std::any_of(pattern.begin(), pattern.end(), + [](const char c) { return c == '?' || c == '*'; }); +} + +class UnitTestFilter { + public: + UnitTestFilter() = default; + + // Constructs a filter from a string of patterns separated by `:`. + explicit UnitTestFilter(const std::string& filter) { + // By design "" filter matches "" string. + std::vector all_patterns; + SplitString(filter, ':', &all_patterns); + const auto exact_match_patterns_begin = std::partition( + all_patterns.begin(), all_patterns.end(), &IsGlobPattern); + + glob_patterns_.reserve(static_cast( + std::distance(all_patterns.begin(), exact_match_patterns_begin))); + std::move(all_patterns.begin(), exact_match_patterns_begin, + std::inserter(glob_patterns_, glob_patterns_.begin())); + std::move( + exact_match_patterns_begin, all_patterns.end(), + std::inserter(exact_match_patterns_, exact_match_patterns_.begin())); + } + + // Returns true if and only if name matches at least one of the patterns in + // the filter. + bool MatchesName(const std::string& name) const { + return exact_match_patterns_.find(name) != exact_match_patterns_.end() || + std::any_of(glob_patterns_.begin(), glob_patterns_.end(), + [&name](const std::string& pattern) { + return PatternMatchesString( + name, pattern.c_str(), + pattern.c_str() + pattern.size()); + }); + } + + private: + std::vector glob_patterns_; + std::unordered_set exact_match_patterns_; +}; + +class PositiveAndNegativeUnitTestFilter { + public: + // Constructs a positive and a negative filter from a string. The string + // contains a positive filter optionally followed by a '-' character and a + // negative filter. In case only a negative filter is provided the positive + // filter will be assumed "*". + // A filter is a list of patterns separated by ':'. + explicit PositiveAndNegativeUnitTestFilter(const std::string& filter) { + std::vector positive_and_negative_filters; + + // NOTE: `SplitString` always returns a non-empty container. + SplitString(filter, '-', &positive_and_negative_filters); + const auto& positive_filter = positive_and_negative_filters.front(); + + if (positive_and_negative_filters.size() > 1) { + positive_filter_ = UnitTestFilter( + positive_filter.empty() ? kUniversalFilter : positive_filter); + + // TODO(b/214626361): Fail on multiple '-' characters + // For the moment to preserve old behavior we concatenate the rest of the + // string parts with `-` as separator to generate the negative filter. + auto negative_filter_string = positive_and_negative_filters[1]; + for (std::size_t i = 2; i < positive_and_negative_filters.size(); i++) + negative_filter_string = + negative_filter_string + '-' + positive_and_negative_filters[i]; + negative_filter_ = UnitTestFilter(negative_filter_string); + } else { + // In case we don't have a negative filter and positive filter is "" + // we do not use kUniversalFilter by design as opposed to when we have a + // negative filter. + positive_filter_ = UnitTestFilter(positive_filter); + } + } + + // Returns true if and only if test name (this is generated by appending test + // suit name and test name via a '.' character) matches the positive filter + // and does not match the negative filter. + bool MatchesTest(const std::string& test_suite_name, + const std::string& test_name) const { + return MatchesName(test_suite_name + "." + test_name); + } + + // Returns true if and only if name matches the positive filter and does not + // match the negative filter. + bool MatchesName(const std::string& name) const { + return positive_filter_.MatchesName(name) && + !negative_filter_.MatchesName(name); + } + + private: + UnitTestFilter positive_filter_; + UnitTestFilter negative_filter_; +}; +} // namespace + bool UnitTestOptions::MatchesFilter(const std::string& name_str, const char* filter) { - // The filter is a list of patterns separated by colons (:). - const char* pattern = filter; - while (true) { - // Find the bounds of this pattern. - const char* const next_sep = strchr(pattern, ':'); - const char* const pattern_end = - next_sep != nullptr ? next_sep : pattern + strlen(pattern); - - // Check if this pattern matches name_str. - if (PatternMatchesString(name_str, pattern, pattern_end)) { - return true; - } - - // Give up on this pattern. However, if we found a pattern separator (:), - // advance to the next pattern (skipping over the separator) and restart. - if (next_sep == nullptr) { - return false; - } - pattern = next_sep + 1; - } - return true; + return UnitTestFilter(filter).MatchesName(name_str); } // Returns true if and only if the user-specified filter matches the test // suite name and the test name. bool UnitTestOptions::FilterMatchesTest(const std::string& test_suite_name, const std::string& test_name) { - const std::string& full_name = test_suite_name + "." + test_name.c_str(); - // Split --gtest_filter at '-', if there is one, to separate into // positive filter and negative filter portions - const char* const p = GTEST_FLAG(filter).c_str(); - const char* const dash = strchr(p, '-'); - std::string positive; - std::string negative; - if (dash == nullptr) { - positive = GTEST_FLAG(filter).c_str(); // Whole string is a positive filter - negative = ""; - } else { - positive = std::string(p, dash); // Everything up to the dash - negative = std::string(dash + 1); // Everything after the dash - if (positive.empty()) { - // Treat '-test1' as the same as '*-test1' - positive = kUniversalFilter; - } - } - - // A filter is a colon-separated list of patterns. It matches a - // test if any pattern in it matches the test. - return (MatchesFilter(full_name, positive.c_str()) && - !MatchesFilter(full_name, negative.c_str())); + return PositiveAndNegativeUnitTestFilter(GTEST_FLAG_GET(filter)) + .MatchesTest(test_suite_name, test_name); } #if GTEST_HAS_SEH -// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the -// given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise. -// This function is useful as an __except condition. -int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) { +static std::string FormatSehExceptionMessage(DWORD exception_code, + const char* location) { + Message message; + message << "SEH exception with code 0x" << std::setbase(16) << exception_code + << std::setbase(10) << " thrown in " << location << "."; + return message.GetString(); +} + +int UnitTestOptions::GTestProcessSEH(DWORD seh_code, const char* location) { // Google Test should handle a SEH exception if: // 1. the user wants it to, AND - // 2. this is not a breakpoint exception, AND + // 2. this is not a breakpoint exception or stack overflow, AND // 3. this is not a C++ exception (VC++ implements them via SEH, // apparently). // // SEH exception code for C++ exceptions. - // (see http://support.microsoft.com/kb/185294 for more information). + // (see https://support.microsoft.com/kb/185294 for more information). const DWORD kCxxExceptionCode = 0xe06d7363; - bool should_handle = true; + if (!GTEST_FLAG_GET(catch_exceptions) || seh_code == kCxxExceptionCode || + seh_code == EXCEPTION_BREAKPOINT || + seh_code == EXCEPTION_STACK_OVERFLOW) { + return EXCEPTION_CONTINUE_SEARCH; // Don't handle these exceptions + } - if (!GTEST_FLAG(catch_exceptions)) - should_handle = false; - else if (exception_code == EXCEPTION_BREAKPOINT) - should_handle = false; - else if (exception_code == kCxxExceptionCode) - should_handle = false; + internal::ReportFailureInUnknownLocation( + TestPartResult::kFatalFailure, + FormatSehExceptionMessage(seh_code, location) + + "\n" + "Stack trace:\n" + + ::testing::internal::GetCurrentOsStackTraceExceptTop(1)); - return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH; + return EXCEPTION_EXECUTE_HANDLER; } #endif // GTEST_HAS_SEH @@ -789,8 +943,7 @@ int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) { // results. Intercepts only failures from the current thread. ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter( TestPartResultArray* result) - : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD), - result_(result) { + : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD), result_(result) { Init(); } @@ -799,8 +952,7 @@ ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter( // results. ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter( InterceptMode intercept_mode, TestPartResultArray* result) - : intercept_mode_(intercept_mode), - result_(result) { + : intercept_mode_(intercept_mode), result_(result) { Init(); } @@ -844,9 +996,7 @@ namespace internal { // from user test code. GetTestTypeId() is guaranteed to always // return the same value, as it always calls GetTypeId<>() from the // gtest.cc, which is within the Google Test framework. -TypeId GetTestTypeId() { - return GetTypeId(); -} +TypeId GetTestTypeId() { return GetTypeId(); } // The value of GetTestTypeId() as seen from within the Google Test // library. This is solely for testing GetTestTypeId(). @@ -861,9 +1011,9 @@ static AssertionResult HasOneFailure(const char* /* results_expr */, const TestPartResultArray& results, TestPartResult::Type type, const std::string& substr) { - const std::string expected(type == TestPartResult::kFatalFailure ? - "1 fatal failure" : - "1 non-fatal failure"); + const std::string expected(type == TestPartResult::kFatalFailure + ? "1 fatal failure" + : "1 non-fatal failure"); Message msg; if (results.size() != 1) { msg << "Expected: " << expected << "\n" @@ -882,10 +1032,10 @@ static AssertionResult HasOneFailure(const char* /* results_expr */, } if (strstr(r.message(), substr.c_str()) == nullptr) { - return AssertionFailure() << "Expected: " << expected << " containing \"" - << substr << "\"\n" - << " Actual:\n" - << r; + return AssertionFailure() + << "Expected: " << expected << " containing \"" << substr << "\"\n" + << " Actual:\n" + << r; } return AssertionSuccess(); @@ -908,7 +1058,8 @@ SingleFailureChecker::~SingleFailureChecker() { } DefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter( - UnitTestImpl* unit_test) : unit_test_(unit_test) {} + UnitTestImpl* unit_test) + : unit_test_(unit_test) {} void DefaultGlobalTestPartResultReporter::ReportTestPartResult( const TestPartResult& result) { @@ -917,7 +1068,8 @@ void DefaultGlobalTestPartResultReporter::ReportTestPartResult( } DefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter( - UnitTestImpl* unit_test) : unit_test_(unit_test) {} + UnitTestImpl* unit_test) + : unit_test_(unit_test) {} void DefaultPerThreadTestPartResultReporter::ReportTestPartResult( const TestPartResult& result) { @@ -928,14 +1080,14 @@ void DefaultPerThreadTestPartResultReporter::ReportTestPartResult( TestPartResultReporterInterface* UnitTestImpl::GetGlobalTestPartResultReporter() { internal::MutexLock lock(&global_test_part_result_reporter_mutex_); - return global_test_part_result_repoter_; + return global_test_part_result_reporter_; } // Sets the global test part result reporter. void UnitTestImpl::SetGlobalTestPartResultReporter( TestPartResultReporterInterface* reporter) { internal::MutexLock lock(&global_test_part_result_reporter_mutex_); - global_test_part_result_repoter_ = reporter; + global_test_part_result_reporter_ = reporter; } // Returns the test part result reporter for the current thread. @@ -1024,27 +1176,33 @@ int UnitTestImpl::test_to_run_count() const { // trace but Bar() and CurrentOsStackTraceExceptTop() won't. std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) { return os_stack_trace_getter()->CurrentStackTrace( - static_cast(GTEST_FLAG(stack_trace_depth)), - skip_count + 1 + static_cast(GTEST_FLAG_GET(stack_trace_depth)), skip_count + 1 // Skips the user-specified number of frames plus this function // itself. - ); // NOLINT + ); // NOLINT } // A helper class for measuring elapsed times. class Timer { public: - Timer() : start_(std::chrono::steady_clock::now()) {} + Timer() : start_(clock::now()) {} // Return time elapsed in milliseconds since the timer was created. TimeInMillis Elapsed() { - return std::chrono::duration_cast( - std::chrono::steady_clock::now() - start_) + return std::chrono::duration_cast(clock::now() - + start_) .count(); } private: - std::chrono::steady_clock::time_point start_; + // Fall back to the system_clock when building with newlib on a system + // without a monotonic clock. +#if defined(_NEWLIB_VERSION) && !defined(CLOCK_MONOTONIC) + using clock = std::chrono::system_clock; +#else + using clock = std::chrono::steady_clock; +#endif + clock::time_point start_; }; // Returns a timestamp as milliseconds since the epoch. Note this time may jump @@ -1061,7 +1219,7 @@ TimeInMillis GetTimeInMillis() { // class String. -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Creates a UTF-16 wide string from the given ANSI string, allocating // memory using new. The caller is responsible for deleting the return // value using delete[]. Returns the wide string, or NULL if the @@ -1072,8 +1230,7 @@ LPCWSTR String::AnsiToUtf16(const char* ansi) { const int unicode_length = MultiByteToWideChar(CP_ACP, 0, ansi, length, nullptr, 0); WCHAR* unicode = new WCHAR[unicode_length + 1]; - MultiByteToWideChar(CP_ACP, 0, ansi, length, - unicode, unicode_length); + MultiByteToWideChar(CP_ACP, 0, ansi, length, unicode, unicode_length); unicode[unicode_length] = 0; return unicode; } @@ -1082,7 +1239,7 @@ LPCWSTR String::AnsiToUtf16(const char* ansi) { // memory using new. The caller is responsible for deleting the return // value using delete[]. Returns the ANSI string, or NULL if the // input is NULL. -const char* String::Utf16ToAnsi(LPCWSTR utf16_str) { +const char* String::Utf16ToAnsi(LPCWSTR utf16_str) { if (!utf16_str) return nullptr; const int ansi_length = WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, nullptr, 0, nullptr, nullptr); @@ -1101,7 +1258,7 @@ const char* String::Utf16ToAnsi(LPCWSTR utf16_str) { // Unlike strcmp(), this function can handle NULL argument(s). A NULL // C string is considered different to any non-NULL C string, // including the empty string. -bool String::CStringEquals(const char * lhs, const char * rhs) { +bool String::CStringEquals(const char* lhs, const char* rhs) { if (lhs == nullptr) return rhs == nullptr; if (rhs == nullptr) return false; @@ -1115,11 +1272,10 @@ bool String::CStringEquals(const char * lhs, const char * rhs) { // encoding, and streams the result to the given Message object. static void StreamWideCharsToMessage(const wchar_t* wstr, size_t length, Message* msg) { - for (size_t i = 0; i != length; ) { // NOLINT + for (size_t i = 0; i != length;) { // NOLINT if (wstr[i] != L'\0') { *msg << WideStringToUtf8(wstr + i, static_cast(length - i)); - while (i != length && wstr[i] != L'\0') - i++; + while (i != length && wstr[i] != L'\0') i++; } else { *msg << '\0'; i++; @@ -1161,17 +1317,17 @@ Message::Message() : ss_(new ::std::stringstream) { // These two overloads allow streaming a wide C string to a Message // using the UTF-8 encoding. -Message& Message::operator <<(const wchar_t* wide_c_str) { +Message& Message::operator<<(const wchar_t* wide_c_str) { return *this << internal::String::ShowWideCString(wide_c_str); } -Message& Message::operator <<(wchar_t* wide_c_str) { +Message& Message::operator<<(wchar_t* wide_c_str) { return *this << internal::String::ShowWideCString(wide_c_str); } #if GTEST_HAS_STD_WSTRING // Converts the given wide string to a narrow string using the UTF-8 // encoding, and streams the result to this Message object. -Message& Message::operator <<(const ::std::wstring& wstr) { +Message& Message::operator<<(const ::std::wstring& wstr) { internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(), this); return *this; } @@ -1183,44 +1339,6 @@ std::string Message::GetString() const { return internal::StringStreamToString(ss_.get()); } -// AssertionResult constructors. -// Used in EXPECT_TRUE/FALSE(assertion_result). -AssertionResult::AssertionResult(const AssertionResult& other) - : success_(other.success_), - message_(other.message_.get() != nullptr - ? new ::std::string(*other.message_) - : static_cast< ::std::string*>(nullptr)) {} - -// Swaps two AssertionResults. -void AssertionResult::swap(AssertionResult& other) { - using std::swap; - swap(success_, other.success_); - swap(message_, other.message_); -} - -// Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. -AssertionResult AssertionResult::operator!() const { - AssertionResult negation(!success_); - if (message_.get() != nullptr) negation << *message_; - return negation; -} - -// Makes a successful assertion result. -AssertionResult AssertionSuccess() { - return AssertionResult(true); -} - -// Makes a failed assertion result. -AssertionResult AssertionFailure() { - return AssertionResult(false); -} - -// Makes a failed assertion result with the given failure message. -// Deprecated; use AssertionFailure() << message. -AssertionResult AssertionFailure(const Message& message) { - return AssertionFailure() << message; -} - namespace internal { namespace edit_distance { @@ -1512,8 +1630,7 @@ std::vector SplitEscapedString(const std::string& str) { AssertionResult EqFailure(const char* lhs_expression, const char* rhs_expression, const std::string& lhs_value, - const std::string& rhs_value, - bool ignoring_case) { + const std::string& rhs_value, bool ignoring_case) { Message msg; msg << "Expected equality of these values:"; msg << "\n " << lhs_expression; @@ -1530,10 +1647,8 @@ AssertionResult EqFailure(const char* lhs_expression, } if (!lhs_value.empty() && !rhs_value.empty()) { - const std::vector lhs_lines = - SplitEscapedString(lhs_value); - const std::vector rhs_lines = - SplitEscapedString(rhs_value); + const std::vector lhs_lines = SplitEscapedString(lhs_value); + const std::vector rhs_lines = SplitEscapedString(rhs_value); if (lhs_lines.size() > 1 || rhs_lines.size() > 1) { msg << "\nWith diff:\n" << edit_distance::CreateUnifiedDiff(lhs_lines, rhs_lines); @@ -1545,27 +1660,36 @@ AssertionResult EqFailure(const char* lhs_expression, // Constructs a failure message for Boolean assertions such as EXPECT_TRUE. std::string GetBoolAssertionFailureMessage( - const AssertionResult& assertion_result, - const char* expression_text, - const char* actual_predicate_value, - const char* expected_predicate_value) { + const AssertionResult& assertion_result, const char* expression_text, + const char* actual_predicate_value, const char* expected_predicate_value) { const char* actual_message = assertion_result.message(); Message msg; msg << "Value of: " << expression_text << "\n Actual: " << actual_predicate_value; - if (actual_message[0] != '\0') - msg << " (" << actual_message << ")"; + if (actual_message[0] != '\0') msg << " (" << actual_message << ")"; msg << "\nExpected: " << expected_predicate_value; return msg.GetString(); } -// Helper function for implementing ASSERT_NEAR. -AssertionResult DoubleNearPredFormat(const char* expr1, - const char* expr2, - const char* abs_error_expr, - double val1, - double val2, - double abs_error) { +// Helper function for implementing ASSERT_NEAR. Treats infinity as a specific +// value, such that comparing infinity to infinity is equal, the distance +// between -infinity and +infinity is infinity, and infinity <= infinity is +// true. +AssertionResult DoubleNearPredFormat(const char* expr1, const char* expr2, + const char* abs_error_expr, double val1, + double val2, double abs_error) { + // We want to return success when the two values are infinity and at least + // one of the following is true: + // * The values are the same-signed infinity. + // * The error limit itself is infinity. + // This is done here so that we don't end up with a NaN when calculating the + // difference in values. + if (std::isinf(val1) && std::isinf(val2) && + (std::signbit(val1) == std::signbit(val2) || + (abs_error > 0.0 && std::isinf(abs_error)))) { + return AssertionSuccess(); + } + const double diff = fabs(val1 - val2); if (diff <= abs_error) return AssertionSuccess(); @@ -1595,20 +1719,17 @@ AssertionResult DoubleNearPredFormat(const char* expr1, "EXPECT_EQUAL. Consider using EXPECT_DOUBLE_EQ instead."; } return AssertionFailure() - << "The difference between " << expr1 << " and " << expr2 - << " is " << diff << ", which exceeds " << abs_error_expr << ", where\n" - << expr1 << " evaluates to " << val1 << ",\n" - << expr2 << " evaluates to " << val2 << ", and\n" - << abs_error_expr << " evaluates to " << abs_error << "."; + << "The difference between " << expr1 << " and " << expr2 << " is " + << diff << ", which exceeds " << abs_error_expr << ", where\n" + << expr1 << " evaluates to " << val1 << ",\n" + << expr2 << " evaluates to " << val2 << ", and\n" + << abs_error_expr << " evaluates to " << abs_error << "."; } - // Helper template for implementing FloatLE() and DoubleLE(). template -AssertionResult FloatingPointLE(const char* expr1, - const char* expr2, - RawType val1, - RawType val2) { +AssertionResult FloatingPointLE(const char* expr1, const char* expr2, + RawType val1, RawType val2) { // Returns success if val1 is less than val2, if (val1 < val2) { return AssertionSuccess(); @@ -1633,24 +1754,24 @@ AssertionResult FloatingPointLE(const char* expr1, << val2; return AssertionFailure() - << "Expected: (" << expr1 << ") <= (" << expr2 << ")\n" - << " Actual: " << StringStreamToString(&val1_ss) << " vs " - << StringStreamToString(&val2_ss); + << "Expected: (" << expr1 << ") <= (" << expr2 << ")\n" + << " Actual: " << StringStreamToString(&val1_ss) << " vs " + << StringStreamToString(&val2_ss); } } // namespace internal // Asserts that val1 is less than, or almost equal to, val2. Fails // otherwise. In particular, it fails if either val1 or val2 is NaN. -AssertionResult FloatLE(const char* expr1, const char* expr2, - float val1, float val2) { +AssertionResult FloatLE(const char* expr1, const char* expr2, float val1, + float val2) { return internal::FloatingPointLE(expr1, expr2, val1, val2); } // Asserts that val1 is less than, or almost equal to, val2. Fails // otherwise. In particular, it fails if either val1 or val2 is NaN. -AssertionResult DoubleLE(const char* expr1, const char* expr2, - double val1, double val2) { +AssertionResult DoubleLE(const char* expr1, const char* expr2, double val1, + double val2) { return internal::FloatingPointLE(expr1, expr2, val1, val2); } @@ -1658,62 +1779,51 @@ namespace internal { // The helper function for {ASSERT|EXPECT}_STREQ. AssertionResult CmpHelperSTREQ(const char* lhs_expression, - const char* rhs_expression, - const char* lhs, + const char* rhs_expression, const char* lhs, const char* rhs) { if (String::CStringEquals(lhs, rhs)) { return AssertionSuccess(); } - return EqFailure(lhs_expression, - rhs_expression, - PrintToString(lhs), - PrintToString(rhs), - false); + return EqFailure(lhs_expression, rhs_expression, PrintToString(lhs), + PrintToString(rhs), false); } // The helper function for {ASSERT|EXPECT}_STRCASEEQ. AssertionResult CmpHelperSTRCASEEQ(const char* lhs_expression, - const char* rhs_expression, - const char* lhs, + const char* rhs_expression, const char* lhs, const char* rhs) { if (String::CaseInsensitiveCStringEquals(lhs, rhs)) { return AssertionSuccess(); } - return EqFailure(lhs_expression, - rhs_expression, - PrintToString(lhs), - PrintToString(rhs), - true); + return EqFailure(lhs_expression, rhs_expression, PrintToString(lhs), + PrintToString(rhs), true); } // The helper function for {ASSERT|EXPECT}_STRNE. AssertionResult CmpHelperSTRNE(const char* s1_expression, - const char* s2_expression, - const char* s1, + const char* s2_expression, const char* s1, const char* s2) { if (!String::CStringEquals(s1, s2)) { return AssertionSuccess(); } else { - return AssertionFailure() << "Expected: (" << s1_expression << ") != (" - << s2_expression << "), actual: \"" - << s1 << "\" vs \"" << s2 << "\""; + return AssertionFailure() + << "Expected: (" << s1_expression << ") != (" << s2_expression + << "), actual: \"" << s1 << "\" vs \"" << s2 << "\""; } } // The helper function for {ASSERT|EXPECT}_STRCASENE. AssertionResult CmpHelperSTRCASENE(const char* s1_expression, - const char* s2_expression, - const char* s1, + const char* s2_expression, const char* s1, const char* s2) { if (!String::CaseInsensitiveCStringEquals(s1, s2)) { return AssertionSuccess(); } else { return AssertionFailure() - << "Expected: (" << s1_expression << ") != (" - << s2_expression << ") (ignoring case), actual: \"" - << s1 << "\" vs \"" << s2 << "\""; + << "Expected: (" << s1_expression << ") != (" << s2_expression + << ") (ignoring case), actual: \"" << s1 << "\" vs \"" << s2 << "\""; } } @@ -1741,8 +1851,7 @@ bool IsSubstringPred(const wchar_t* needle, const wchar_t* haystack) { // StringType here can be either ::std::string or ::std::wstring. template -bool IsSubstringPred(const StringType& needle, - const StringType& haystack) { +bool IsSubstringPred(const StringType& needle, const StringType& haystack) { return haystack.find(needle) != StringType::npos; } @@ -1751,21 +1860,22 @@ bool IsSubstringPred(const StringType& needle, // StringType here can be const char*, const wchar_t*, ::std::string, // or ::std::wstring. template -AssertionResult IsSubstringImpl( - bool expected_to_be_substring, - const char* needle_expr, const char* haystack_expr, - const StringType& needle, const StringType& haystack) { +AssertionResult IsSubstringImpl(bool expected_to_be_substring, + const char* needle_expr, + const char* haystack_expr, + const StringType& needle, + const StringType& haystack) { if (IsSubstringPred(needle, haystack) == expected_to_be_substring) return AssertionSuccess(); const bool is_wide_string = sizeof(needle[0]) > 1; const char* const begin_string_quote = is_wide_string ? "L\"" : "\""; return AssertionFailure() - << "Value of: " << needle_expr << "\n" - << " Actual: " << begin_string_quote << needle << "\"\n" - << "Expected: " << (expected_to_be_substring ? "" : "not ") - << "a substring of " << haystack_expr << "\n" - << "Which is: " << begin_string_quote << haystack << "\""; + << "Value of: " << needle_expr << "\n" + << " Actual: " << begin_string_quote << needle << "\"\n" + << "Expected: " << (expected_to_be_substring ? "" : "not ") + << "a substring of " << haystack_expr << "\n" + << "Which is: " << begin_string_quote << haystack << "\""; } } // namespace @@ -1774,100 +1884,99 @@ AssertionResult IsSubstringImpl( // substring of haystack (NULL is considered a substring of itself // only), and return an appropriate error message when they fail. -AssertionResult IsSubstring( - const char* needle_expr, const char* haystack_expr, - const char* needle, const char* haystack) { +AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr, + const char* needle, const char* haystack) { return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack); } -AssertionResult IsSubstring( - const char* needle_expr, const char* haystack_expr, - const wchar_t* needle, const wchar_t* haystack) { +AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr, + const wchar_t* needle, const wchar_t* haystack) { return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack); } -AssertionResult IsNotSubstring( - const char* needle_expr, const char* haystack_expr, - const char* needle, const char* haystack) { +AssertionResult IsNotSubstring(const char* needle_expr, + const char* haystack_expr, const char* needle, + const char* haystack) { return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack); } -AssertionResult IsNotSubstring( - const char* needle_expr, const char* haystack_expr, - const wchar_t* needle, const wchar_t* haystack) { +AssertionResult IsNotSubstring(const char* needle_expr, + const char* haystack_expr, const wchar_t* needle, + const wchar_t* haystack) { return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack); } -AssertionResult IsSubstring( - const char* needle_expr, const char* haystack_expr, - const ::std::string& needle, const ::std::string& haystack) { +AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr, + const ::std::string& needle, + const ::std::string& haystack) { return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack); } -AssertionResult IsNotSubstring( - const char* needle_expr, const char* haystack_expr, - const ::std::string& needle, const ::std::string& haystack) { +AssertionResult IsNotSubstring(const char* needle_expr, + const char* haystack_expr, + const ::std::string& needle, + const ::std::string& haystack) { return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack); } #if GTEST_HAS_STD_WSTRING -AssertionResult IsSubstring( - const char* needle_expr, const char* haystack_expr, - const ::std::wstring& needle, const ::std::wstring& haystack) { +AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr, + const ::std::wstring& needle, + const ::std::wstring& haystack) { return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack); } -AssertionResult IsNotSubstring( - const char* needle_expr, const char* haystack_expr, - const ::std::wstring& needle, const ::std::wstring& haystack) { +AssertionResult IsNotSubstring(const char* needle_expr, + const char* haystack_expr, + const ::std::wstring& needle, + const ::std::wstring& haystack) { return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack); } #endif // GTEST_HAS_STD_WSTRING namespace internal { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS namespace { // Helper function for IsHRESULT{SuccessFailure} predicates -AssertionResult HRESULTFailureHelper(const char* expr, - const char* expected, +AssertionResult HRESULTFailureHelper(const char* expr, const char* expected, long hr) { // NOLINT -# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_TV_TITLE) // Windows CE doesn't support FormatMessage. const char error_text[] = ""; -# else +#else // Looks up the human-readable system message for the HRESULT code // and since we're not passing any params to FormatMessage, we don't // want inserts expanded. - const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS; + const DWORD kFlags = + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; const DWORD kBufSize = 4096; // Gets the system's human readable message string for this HRESULT. - char error_text[kBufSize] = { '\0' }; + char error_text[kBufSize] = {'\0'}; DWORD message_length = ::FormatMessageA(kFlags, - 0, // no source, we're asking system + 0, // no source, we're asking system static_cast(hr), // the error - 0, // no line width restrictions + 0, // no line width restrictions error_text, // output buffer kBufSize, // buf size nullptr); // no arguments for inserts // Trims tailing white space (FormatMessage leaves a trailing CR-LF) for (; message_length && IsSpace(error_text[message_length - 1]); - --message_length) { + --message_length) { error_text[message_length - 1] = '\0'; } -# endif // GTEST_OS_WINDOWS_MOBILE +#endif // GTEST_OS_WINDOWS_MOBILE const std::string error_hex("0x" + String::FormatHexInt(hr)); return ::testing::AssertionFailure() - << "Expected: " << expr << " " << expected << ".\n" - << " Actual: " << error_hex << " " << error_text << "\n"; + << "Expected: " << expr << " " << expected << ".\n" + << " Actual: " << error_hex << " " << error_text << "\n"; } } // namespace @@ -1901,16 +2010,18 @@ AssertionResult IsHRESULTFailure(const char* expr, long hr) { // NOLINT // 17 - 21 bits 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx // The maximum code-point a one-byte UTF-8 sequence can represent. -constexpr uint32_t kMaxCodePoint1 = (static_cast(1) << 7) - 1; +constexpr uint32_t kMaxCodePoint1 = (static_cast(1) << 7) - 1; // The maximum code-point a two-byte UTF-8 sequence can represent. constexpr uint32_t kMaxCodePoint2 = (static_cast(1) << (5 + 6)) - 1; // The maximum code-point a three-byte UTF-8 sequence can represent. -constexpr uint32_t kMaxCodePoint3 = (static_cast(1) << (4 + 2*6)) - 1; +constexpr uint32_t kMaxCodePoint3 = + (static_cast(1) << (4 + 2 * 6)) - 1; // The maximum code-point a four-byte UTF-8 sequence can represent. -constexpr uint32_t kMaxCodePoint4 = (static_cast(1) << (3 + 3*6)) - 1; +constexpr uint32_t kMaxCodePoint4 = + (static_cast(1) << (3 + 3 * 6)) - 1; // Chops off the n lowest bits from a bit pattern. Returns the n // lowest bits. As a side effect, the original bit pattern will be @@ -1935,7 +2046,7 @@ std::string CodePointToUtf8(uint32_t code_point) { char str[5]; // Big enough for the largest valid code point. if (code_point <= kMaxCodePoint1) { str[1] = '\0'; - str[0] = static_cast(code_point); // 0xxxxxxx + str[0] = static_cast(code_point); // 0xxxxxxx } else if (code_point <= kMaxCodePoint2) { str[2] = '\0'; str[1] = static_cast(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx @@ -1963,8 +2074,8 @@ std::string CodePointToUtf8(uint32_t code_point) { // and thus should be combined into a single Unicode code point // using CreateCodePointFromUtf16SurrogatePair. inline bool IsUtf16SurrogatePair(wchar_t first, wchar_t second) { - return sizeof(wchar_t) == 2 && - (first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00; + return sizeof(wchar_t) == 2 && (first & 0xFC00) == 0xD800 && + (second & 0xFC00) == 0xDC00; } // Creates a Unicode code point from UTF16 surrogate pair. @@ -1995,8 +2106,7 @@ inline uint32_t CreateCodePointFromUtf16SurrogatePair(wchar_t first, // and contains invalid UTF-16 surrogate pairs, values in those pairs // will be encoded as individual Unicode characters from Basic Normal Plane. std::string WideStringToUtf8(const wchar_t* str, int num_chars) { - if (num_chars == -1) - num_chars = static_cast(wcslen(str)); + if (num_chars == -1) num_chars = static_cast(wcslen(str)); ::std::stringstream stream; for (int i = 0; i < num_chars; ++i) { @@ -2005,8 +2115,8 @@ std::string WideStringToUtf8(const wchar_t* str, int num_chars) { if (str[i] == L'\0') { break; } else if (i + 1 < num_chars && IsUtf16SurrogatePair(str[i], str[i + 1])) { - unicode_code_point = CreateCodePointFromUtf16SurrogatePair(str[i], - str[i + 1]); + unicode_code_point = + CreateCodePointFromUtf16SurrogatePair(str[i], str[i + 1]); i++; } else { unicode_code_point = static_cast(str[i]); @@ -2019,7 +2129,7 @@ std::string WideStringToUtf8(const wchar_t* str, int num_chars) { // Converts a wide C string to an std::string using the UTF-8 encoding. // NULL will be converted to "(null)". -std::string String::ShowWideCString(const wchar_t * wide_c_str) { +std::string String::ShowWideCString(const wchar_t* wide_c_str) { if (wide_c_str == nullptr) return "(null)"; return internal::WideStringToUtf8(wide_c_str, -1); @@ -2031,7 +2141,7 @@ std::string String::ShowWideCString(const wchar_t * wide_c_str) { // Unlike wcscmp(), this function can handle NULL argument(s). A NULL // C string is considered different to any non-NULL C string, // including the empty string. -bool String::WideCStringEquals(const wchar_t * lhs, const wchar_t * rhs) { +bool String::WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs) { if (lhs == nullptr) return rhs == nullptr; if (rhs == nullptr) return false; @@ -2041,33 +2151,27 @@ bool String::WideCStringEquals(const wchar_t * lhs, const wchar_t * rhs) { // Helper function for *_STREQ on wide strings. AssertionResult CmpHelperSTREQ(const char* lhs_expression, - const char* rhs_expression, - const wchar_t* lhs, + const char* rhs_expression, const wchar_t* lhs, const wchar_t* rhs) { if (String::WideCStringEquals(lhs, rhs)) { return AssertionSuccess(); } - return EqFailure(lhs_expression, - rhs_expression, - PrintToString(lhs), - PrintToString(rhs), - false); + return EqFailure(lhs_expression, rhs_expression, PrintToString(lhs), + PrintToString(rhs), false); } // Helper function for *_STRNE on wide strings. AssertionResult CmpHelperSTRNE(const char* s1_expression, - const char* s2_expression, - const wchar_t* s1, + const char* s2_expression, const wchar_t* s1, const wchar_t* s2) { if (!String::WideCStringEquals(s1, s2)) { return AssertionSuccess(); } - return AssertionFailure() << "Expected: (" << s1_expression << ") != (" - << s2_expression << "), actual: " - << PrintToString(s1) - << " vs " << PrintToString(s2); + return AssertionFailure() + << "Expected: (" << s1_expression << ") != (" << s2_expression + << "), actual: " << PrintToString(s1) << " vs " << PrintToString(s2); } // Compares two C strings, ignoring case. Returns true if and only if they have @@ -2076,7 +2180,7 @@ AssertionResult CmpHelperSTRNE(const char* s1_expression, // Unlike strcasecmp(), this function can handle NULL argument(s). A // NULL C string is considered different to any non-NULL C string, // including the empty string. -bool String::CaseInsensitiveCStringEquals(const char * lhs, const char * rhs) { +bool String::CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) { if (lhs == nullptr) return rhs == nullptr; if (rhs == nullptr) return false; return posix::StrCaseCmp(lhs, rhs) == 0; @@ -2100,9 +2204,9 @@ bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs, if (rhs == nullptr) return false; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS return _wcsicmp(lhs, rhs) == 0; -#elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID +#elif defined(GTEST_OS_LINUX) && !defined(GTEST_OS_LINUX_ANDROID) return wcscasecmp(lhs, rhs) == 0; #else // Android, Mac OS X and Cygwin don't define wcscasecmp. @@ -2118,8 +2222,8 @@ bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs, // Returns true if and only if str ends with the given suffix, ignoring case. // Any string is considered to end with an empty suffix. -bool String::EndsWithCaseInsensitive( - const std::string& str, const std::string& suffix) { +bool String::EndsWithCaseInsensitive(const std::string& str, + const std::string& suffix) { const size_t str_len = str.length(); const size_t suffix_len = suffix.length(); return (str_len >= suffix_len) && @@ -2202,15 +2306,13 @@ TestResult::TestResult() : death_test_count_(0), start_timestamp_(0), elapsed_time_(0) {} // D'tor. -TestResult::~TestResult() { -} +TestResult::~TestResult() = default; // Returns the i-th test part result among all the results. i can // range from 0 to total_part_count() - 1. If i is not in that range, // aborts the program. const TestPartResult& TestResult::GetTestPartResult(int i) const { - if (i < 0 || i >= total_part_count()) - internal::posix::Abort(); + if (i < 0 || i >= total_part_count()) internal::posix::Abort(); return test_part_results_.at(static_cast(i)); } @@ -2218,15 +2320,12 @@ const TestPartResult& TestResult::GetTestPartResult(int i) const { // test_property_count() - 1. If i is not in that range, aborts the // program. const TestProperty& TestResult::GetTestProperty(int i) const { - if (i < 0 || i >= test_property_count()) - internal::posix::Abort(); + if (i < 0 || i >= test_property_count()) internal::posix::Abort(); return test_properties_.at(static_cast(i)); } // Clears the test part results. -void TestResult::ClearTestPartResults() { - test_part_results_.clear(); -} +void TestResult::ClearTestPartResults() { test_part_results_.clear(); } // Adds a test part result to the list. void TestResult::AddTestPartResult(const TestPartResult& test_part_result) { @@ -2255,15 +2354,8 @@ void TestResult::RecordProperty(const std::string& xml_element, // The list of reserved attributes used in the element of XML // output. static const char* const kReservedTestSuitesAttributes[] = { - "disabled", - "errors", - "failures", - "name", - "random_seed", - "tests", - "time", - "timestamp" -}; + "disabled", "errors", "failures", "name", + "random_seed", "tests", "time", "timestamp"}; // The list of reserved attributes used in the element of XML // output. @@ -2273,11 +2365,11 @@ static const char* const kReservedTestSuiteAttributes[] = { // The list of reserved attributes used in the element of XML output. static const char* const kReservedTestCaseAttributes[] = { - "classname", "name", "status", "time", "type_param", - "value_param", "file", "line"}; + "classname", "name", "status", "time", + "type_param", "value_param", "file", "line"}; // Use a slightly different set for allowed output to ensure existing tests can -// still RecordProperty("result") or "RecordProperty(timestamp") +// still RecordProperty("result") or RecordProperty("timestamp") static const char* const kReservedOutputTestCaseAttributes[] = { "classname", "name", "status", "time", "type_param", "value_param", "file", "line", "result", "timestamp"}; @@ -2302,7 +2394,9 @@ static std::vector GetReservedAttributesForElement( return std::vector(); } +#if GTEST_HAS_FILE_SYSTEM // TODO(jdesprez): Merge the two getReserved attributes once skip is improved +// This function is only used when file systems are enabled. static std::vector GetReservedOutputAttributesForElement( const std::string& xml_element) { if (xml_element == "testsuites") { @@ -2317,6 +2411,7 @@ static std::vector GetReservedOutputAttributesForElement( // This code is unreachable but some compilers may not realizes that. return std::vector(); } +#endif static std::string FormatWordList(const std::vector& words) { Message word_list; @@ -2336,7 +2431,7 @@ static bool ValidateTestPropertyName( const std::string& property_name, const std::vector& reserved_names) { if (std::find(reserved_names.begin(), reserved_names.end(), property_name) != - reserved_names.end()) { + reserved_names.end()) { ADD_FAILURE() << "Reserved key used in RecordProperty(): " << property_name << " (" << FormatWordList(reserved_names) << " are reserved by " << GTEST_NAME_ << ")"; @@ -2374,8 +2469,7 @@ bool TestResult::Skipped() const { // Returns true if and only if the test failed. bool TestResult::Failed() const { for (int i = 0; i < total_part_count(); ++i) { - if (GetTestPartResult(i).failed()) - return true; + if (GetTestPartResult(i).failed()) return true; } return false; } @@ -2416,40 +2510,28 @@ int TestResult::test_property_count() const { // Creates a Test object. // The c'tor saves the states of all flags. -Test::Test() - : gtest_flag_saver_(new GTEST_FLAG_SAVER_) { -} +Test::Test() : gtest_flag_saver_(new GTEST_FLAG_SAVER_) {} // The d'tor restores the states of all flags. The actual work is // done by the d'tor of the gtest_flag_saver_ field, and thus not // visible here. -Test::~Test() { -} +Test::~Test() = default; // Sets up the test fixture. // // A sub-class may override this. -void Test::SetUp() { -} +void Test::SetUp() {} // Tears down the test fixture. // // A sub-class may override this. -void Test::TearDown() { -} +void Test::TearDown() {} // Allows user supplied key value pairs to be recorded for later output. void Test::RecordProperty(const std::string& key, const std::string& value) { UnitTest::GetInstance()->RecordProperty(key, value); } -// Allows user supplied key value pairs to be recorded for later output. -void Test::RecordProperty(const std::string& key, int value) { - Message value_message; - value_message << value; - RecordProperty(key, value_message.GetString().c_str()); -} - namespace internal { void ReportFailureInUnknownLocation(TestPartResult::Type result_type, @@ -2532,23 +2614,6 @@ bool Test::HasSameFixtureClass() { return true; } -#if GTEST_HAS_SEH - -// Adds an "exception thrown" fatal failure to the current test. This -// function returns its result via an output parameter pointer because VC++ -// prohibits creation of objects with destructors on stack in functions -// using __try (see error C2712). -static std::string* FormatSehExceptionMessage(DWORD exception_code, - const char* location) { - Message message; - message << "SEH exception with code 0x" << std::setbase(16) << - exception_code << std::setbase(10) << " thrown in " << location << "."; - - return new std::string(message.GetString()); -} - -#endif // GTEST_HAS_SEH - namespace internal { #if GTEST_HAS_EXCEPTIONS @@ -2585,21 +2650,13 @@ GoogleTestFailureException::GoogleTestFailureException( // exceptions in the same function. Therefore, we provide a separate // wrapper function for handling SEH exceptions.) template -Result HandleSehExceptionsInMethodIfSupported( - T* object, Result (T::*method)(), const char* location) { +Result HandleSehExceptionsInMethodIfSupported(T* object, Result (T::*method)(), + const char* location) { #if GTEST_HAS_SEH __try { return (object->*method)(); - } __except (internal::UnitTestOptions::GTestShouldProcessSEH( // NOLINT - GetExceptionCode())) { - // We create the exception message on the heap because VC++ prohibits - // creation of objects with destructors on stack in functions using __try - // (see error C2712). - std::string* exception_message = FormatSehExceptionMessage( - GetExceptionCode(), location); - internal::ReportFailureInUnknownLocation(TestPartResult::kFatalFailure, - *exception_message); - delete exception_message; + } __except (internal::UnitTestOptions::GTestProcessSEH( // NOLINT + GetExceptionCode(), location)) { return static_cast(0); } #else @@ -2612,8 +2669,8 @@ Result HandleSehExceptionsInMethodIfSupported( // exceptions, if they are supported; returns the 0-value for type // Result in case of an SEH exception. template -Result HandleExceptionsInMethodIfSupported( - T* object, Result (T::*method)(), const char* location) { +Result HandleExceptionsInMethodIfSupported(T* object, Result (T::*method)(), + const char* location) { // NOTE: The user code can affect the way in which Google Test handles // exceptions by setting GTEST_FLAG(catch_exceptions), but only before // RUN_ALL_TESTS() starts. It is technically possible to check the flag @@ -2623,7 +2680,7 @@ Result HandleExceptionsInMethodIfSupported( // try { // // Perform the test method. // } catch (...) { - // if (GTEST_FLAG(catch_exceptions)) + // if (GTEST_FLAG_GET(catch_exceptions)) // // Report the exception as failure. // else // throw; // Re-throws the original exception. @@ -2679,16 +2736,16 @@ void Test::Run() { // GTEST_SKIP(). if (!HasFatalFailure() && !IsSkipped()) { impl->os_stack_trace_getter()->UponLeavingGTest(); - internal::HandleExceptionsInMethodIfSupported( - this, &Test::TestBody, "the test body"); + internal::HandleExceptionsInMethodIfSupported(this, &Test::TestBody, + "the test body"); } // However, we want to clean up as much as possible. Hence we will // always call TearDown(), even if SetUp() or the test body has // failed. impl->os_stack_trace_getter()->UponLeavingGTest(); - internal::HandleExceptionsInMethodIfSupported( - this, &Test::TearDown, "TearDown()"); + internal::HandleExceptionsInMethodIfSupported(this, &Test::TearDown, + "TearDown()"); } // Returns true if and only if the current test has a fatal failure. @@ -2698,8 +2755,9 @@ bool Test::HasFatalFailure() { // Returns true if and only if the current test has a non-fatal failure. bool Test::HasNonfatalFailure() { - return internal::GetUnitTestImpl()->current_test_result()-> - HasNonfatalFailure(); + return internal::GetUnitTestImpl() + ->current_test_result() + ->HasNonfatalFailure(); } // Returns true if and only if the current test was skipped. @@ -2711,17 +2769,16 @@ bool Test::IsSkipped() { // Constructs a TestInfo object. It assumes ownership of the test factory // object. -TestInfo::TestInfo(const std::string& a_test_suite_name, - const std::string& a_name, const char* a_type_param, - const char* a_value_param, +TestInfo::TestInfo(std::string a_test_suite_name, std::string a_name, + const char* a_type_param, const char* a_value_param, internal::CodeLocation a_code_location, internal::TypeId fixture_class_id, internal::TestFactoryBase* factory) - : test_suite_name_(a_test_suite_name), - name_(a_name), + : test_suite_name_(std::move(a_test_suite_name)), + name_(std::move(a_name)), type_param_(a_type_param ? new std::string(a_type_param) : nullptr), value_param_(a_value_param ? new std::string(a_value_param) : nullptr), - location_(a_code_location), + location_(std::move(a_code_location)), fixture_class_id_(fixture_class_id), should_run_(false), is_disabled_(false), @@ -2754,19 +2811,19 @@ namespace internal { // The newly created TestInfo instance will assume // ownership of the factory object. TestInfo* MakeAndRegisterTestInfo( - const char* test_suite_name, const char* name, const char* type_param, + std::string test_suite_name, const char* name, const char* type_param, const char* value_param, CodeLocation code_location, TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc, TearDownTestSuiteFunc tear_down_tc, TestFactoryBase* factory) { TestInfo* const test_info = - new TestInfo(test_suite_name, name, type_param, value_param, - code_location, fixture_class_id, factory); + new TestInfo(std::move(test_suite_name), name, type_param, value_param, + std::move(code_location), fixture_class_id, factory); GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info); return test_info; } void ReportInvalidTestSuiteType(const char* test_suite_name, - CodeLocation code_location) { + const CodeLocation& code_location) { Message errors; errors << "Attempted redefinition of test suite " << test_suite_name << ".\n" @@ -2782,38 +2839,6 @@ void ReportInvalidTestSuiteType(const char* test_suite_name, code_location.line) << " " << errors.GetString(); } -} // namespace internal - -namespace { - -// A predicate that checks the test name of a TestInfo against a known -// value. -// -// This is used for implementation of the TestSuite class only. We put -// it in the anonymous namespace to prevent polluting the outer -// namespace. -// -// TestNameIs is copyable. -class TestNameIs { - public: - // Constructor. - // - // TestNameIs has NO default constructor. - explicit TestNameIs(const char* name) - : name_(name) {} - - // Returns true if and only if the test name of test_info matches name_. - bool operator()(const TestInfo * test_info) const { - return test_info && test_info->name() == name_; - } - - private: - std::string name_; -}; - -} // namespace - -namespace internal { // This method expands all parameterized tests registered with macros TEST_P // and INSTANTIATE_TEST_SUITE_P into regular tests and registers those. @@ -2831,21 +2856,20 @@ void UnitTestImpl::RegisterParameterizedTests() { // Creates the test object, runs it, records its result, and then // deletes it. void TestInfo::Run() { - if (!should_run_) return; + TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); + if (!should_run_) { + if (is_disabled_ && matches_filter_) repeater->OnTestDisabled(*this); + return; + } // Tells UnitTest where to store test result. - internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); - impl->set_current_test_info(this); - - TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); + UnitTest::GetInstance()->set_current_test_info(this); // Notifies the unit test event listeners that a test is about to start. repeater->OnTestStart(*this); - result_.set_start_timestamp(internal::GetTimeInMillis()); internal::Timer timer; - - impl->os_stack_trace_getter()->UponLeavingGTest(); + UnitTest::GetInstance()->UponLeavingGTest(); // Creates the test object. Test* const test = internal::HandleExceptionsInMethodIfSupported( @@ -2863,7 +2887,7 @@ void TestInfo::Run() { if (test != nullptr) { // Deletes the test object. - impl->os_stack_trace_getter()->UponLeavingGTest(); + UnitTest::GetInstance()->UponLeavingGTest(); internal::HandleExceptionsInMethodIfSupported( test, &Test::DeleteSelf_, "the test fixture's destructor"); } @@ -2875,15 +2899,14 @@ void TestInfo::Run() { // Tells UnitTest to stop associating assertion results to this // test. - impl->set_current_test_info(nullptr); + UnitTest::GetInstance()->set_current_test_info(nullptr); } // Skip and records a skipped test result for this object. void TestInfo::Skip() { if (!should_run_) return; - internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); - impl->set_current_test_info(this); + UnitTest::GetInstance()->set_current_test_info(this); TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); @@ -2892,12 +2915,13 @@ void TestInfo::Skip() { const TestPartResult test_part_result = TestPartResult(TestPartResult::kSkip, this->file(), this->line(), ""); - impl->GetTestPartResultReporterForCurrentThread()->ReportTestPartResult( - test_part_result); + internal::GetUnitTestImpl() + ->GetTestPartResultReporterForCurrentThread() + ->ReportTestPartResult(test_part_result); // Notifies the unit test event listener that a test has just finished. repeater->OnTestEnd(*this); - impl->set_current_test_info(nullptr); + UnitTest::GetInstance()->set_current_test_info(nullptr); } // class TestSuite @@ -2951,7 +2975,7 @@ int TestSuite::total_test_count() const { // this is not a typed or a type-parameterized test suite. // set_up_tc: pointer to the function that sets up the test suite // tear_down_tc: pointer to the function that tears down the test suite -TestSuite::TestSuite(const char* a_name, const char* a_type_param, +TestSuite::TestSuite(const std::string& a_name, const char* a_type_param, internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc) : name_(a_name), @@ -2993,11 +3017,29 @@ void TestSuite::AddTestInfo(TestInfo* test_info) { void TestSuite::Run() { if (!should_run_) return; - internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); - impl->set_current_test_suite(this); + UnitTest::GetInstance()->set_current_test_suite(this); TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); + // Ensure our tests are in a deterministic order. + // + // We do this by sorting lexicographically on (file, line number), providing + // an order matching what the user can see in the source code. + // + // In the common case the line number comparison shouldn't be necessary, + // because the registrations made by the TEST macro are executed in order + // within a translation unit. But this is not true of the manual registration + // API, and in more exotic scenarios a single file may be part of multiple + // translation units. + std::stable_sort(test_info_list_.begin(), test_info_list_.end(), + [](const TestInfo* const a, const TestInfo* const b) { + if (const int result = std::strcmp(a->file(), b->file())) { + return result < 0; + } + + return a->line() < b->line(); + }); + // Call both legacy and the new API repeater->OnTestSuiteStart(*this); // Legacy API is deprecated but still available @@ -3005,15 +3047,23 @@ void TestSuite::Run() { repeater->OnTestCaseStart(*this); #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ - impl->os_stack_trace_getter()->UponLeavingGTest(); + UnitTest::GetInstance()->UponLeavingGTest(); internal::HandleExceptionsInMethodIfSupported( this, &TestSuite::RunSetUpTestSuite, "SetUpTestSuite()"); + const bool skip_all = + ad_hoc_test_result().Failed() || ad_hoc_test_result().Skipped(); + start_timestamp_ = internal::GetTimeInMillis(); internal::Timer timer; for (int i = 0; i < total_test_count(); i++) { - GetMutableTestInfo(i)->Run(); - if (GTEST_FLAG(fail_fast) && GetMutableTestInfo(i)->result()->Failed()) { + if (skip_all) { + GetMutableTestInfo(i)->Skip(); + } else { + GetMutableTestInfo(i)->Run(); + } + if (GTEST_FLAG_GET(fail_fast) && + GetMutableTestInfo(i)->result()->Failed()) { for (int j = i + 1; j < total_test_count(); j++) { GetMutableTestInfo(j)->Skip(); } @@ -3022,7 +3072,7 @@ void TestSuite::Run() { } elapsed_time_ = timer.Elapsed(); - impl->os_stack_trace_getter()->UponLeavingGTest(); + UnitTest::GetInstance()->UponLeavingGTest(); internal::HandleExceptionsInMethodIfSupported( this, &TestSuite::RunTearDownTestSuite, "TearDownTestSuite()"); @@ -3033,15 +3083,14 @@ void TestSuite::Run() { repeater->OnTestCaseEnd(*this); #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ - impl->set_current_test_suite(nullptr); + UnitTest::GetInstance()->set_current_test_suite(nullptr); } // Skips all tests under this TestSuite. void TestSuite::Skip() { if (!should_run_) return; - internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); - impl->set_current_test_suite(this); + UnitTest::GetInstance()->set_current_test_suite(this); TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); @@ -3063,7 +3112,7 @@ void TestSuite::Skip() { repeater->OnTestCaseEnd(*this); #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ - impl->set_current_test_suite(nullptr); + UnitTest::GetInstance()->set_current_test_suite(nullptr); } // Clears the results of all tests in this test suite. @@ -3089,11 +3138,10 @@ void TestSuite::UnshuffleTests() { // // FormatCountableNoun(1, "formula", "formuli") returns "1 formula". // FormatCountableNoun(5, "book", "books") returns "5 books". -static std::string FormatCountableNoun(int count, - const char * singular_form, - const char * plural_form) { +static std::string FormatCountableNoun(int count, const char* singular_form, + const char* plural_form) { return internal::StreamableToString(count) + " " + - (count == 1 ? singular_form : plural_form); + (count == 1 ? singular_form : plural_form); } // Formats the count of tests. @@ -3110,7 +3158,7 @@ static std::string FormatTestSuiteCount(int test_suite_count) { // representation. Both kNonFatalFailure and kFatalFailure are translated // to "Failure", as the user usually doesn't care about the difference // between the two when viewing the test result. -static const char * TestPartResultTypeToString(TestPartResult::Type type) { +static const char* TestPartResultTypeToString(TestPartResult::Type type) { switch (type) { case TestPartResult::kSkip: return "Skipped\n"; @@ -3137,24 +3185,25 @@ enum class GTestColor { kDefault, kRed, kGreen, kYellow }; // Prints a TestPartResult to an std::string. static std::string PrintTestPartResultToString( const TestPartResult& test_part_result) { - return (Message() - << internal::FormatFileLocation(test_part_result.file_name(), - test_part_result.line_number()) - << " " << TestPartResultTypeToString(test_part_result.type()) - << test_part_result.message()).GetString(); + return (Message() << internal::FormatFileLocation( + test_part_result.file_name(), + test_part_result.line_number()) + << " " + << TestPartResultTypeToString(test_part_result.type()) + << test_part_result.message()) + .GetString(); } // Prints a TestPartResult. static void PrintTestPartResult(const TestPartResult& test_part_result) { - const std::string& result = - PrintTestPartResultToString(test_part_result); + const std::string& result = PrintTestPartResultToString(test_part_result); printf("%s\n", result.c_str()); fflush(stdout); // If the test program runs in Visual Studio or a debugger, the // following statements add the test part result message to the Output // window such that the user can double-click on it to jump to the // corresponding source code location; otherwise they do nothing. -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) // We don't call OutputDebugString*() on Windows Mobile, as printing // to stdout is done by OutputDebugString() there already - we don't // want the same message printed twice. @@ -3164,8 +3213,9 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) { } // class PrettyUnitTestResultPrinter -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \ - !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \ + !defined(GTEST_OS_WINDOWS_GAMES) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_WINDOWS_MINGW) // Returns the character attribute for the given color. static WORD GetColorAttribute(GTestColor color) { @@ -3176,7 +3226,8 @@ static WORD GetColorAttribute(GTestColor color) { return FOREGROUND_GREEN; case GTestColor::kYellow: return FOREGROUND_RED | FOREGROUND_GREEN; - default: return 0; + default: + return 0; } } @@ -3224,7 +3275,8 @@ static const char* GetAnsiColorCode(GTestColor color) { case GTestColor::kYellow: return "3"; default: - return nullptr; + assert(false); + return "9"; } } @@ -3232,10 +3284,11 @@ static const char* GetAnsiColorCode(GTestColor color) { // Returns true if and only if Google Test should use colors in the output. bool ShouldUseColor(bool stdout_is_tty) { - const char* const gtest_color = GTEST_FLAG(color).c_str(); + std::string c = GTEST_FLAG_GET(color); + const char* const gtest_color = c.c_str(); if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) { -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW) // On Windows the TERM variable is usually not set, but the // console there does support colors. return stdout_is_tty; @@ -3243,25 +3296,24 @@ bool ShouldUseColor(bool stdout_is_tty) { // On non-Windows platforms, we rely on the TERM variable. const char* const term = posix::GetEnv("TERM"); const bool term_supports_color = - String::CStringEquals(term, "xterm") || - String::CStringEquals(term, "xterm-color") || - String::CStringEquals(term, "xterm-256color") || - String::CStringEquals(term, "screen") || - String::CStringEquals(term, "screen-256color") || - String::CStringEquals(term, "tmux") || - String::CStringEquals(term, "tmux-256color") || - String::CStringEquals(term, "rxvt-unicode") || - String::CStringEquals(term, "rxvt-unicode-256color") || - String::CStringEquals(term, "linux") || - String::CStringEquals(term, "cygwin"); + term != nullptr && (String::CStringEquals(term, "xterm") || + String::CStringEquals(term, "xterm-color") || + String::CStringEquals(term, "xterm-kitty") || + String::CStringEquals(term, "alacritty") || + String::CStringEquals(term, "screen") || + String::CStringEquals(term, "tmux") || + String::CStringEquals(term, "rxvt-unicode") || + String::CStringEquals(term, "linux") || + String::CStringEquals(term, "cygwin") || + String::EndsWithCaseInsensitive(term, "-256color")); return stdout_is_tty && term_supports_color; #endif // GTEST_OS_WINDOWS } return String::CaseInsensitiveCStringEquals(gtest_color, "yes") || - String::CaseInsensitiveCStringEquals(gtest_color, "true") || - String::CaseInsensitiveCStringEquals(gtest_color, "t") || - String::CStringEquals(gtest_color, "1"); + String::CaseInsensitiveCStringEquals(gtest_color, "true") || + String::CaseInsensitiveCStringEquals(gtest_color, "t") || + String::CStringEquals(gtest_color, "1"); // We take "yes", "true", "t", and "1" as meaning "yes". If the // value is neither one of these nor "auto", we treat it as "no" to // be conservative. @@ -3273,18 +3325,16 @@ bool ShouldUseColor(bool stdout_is_tty) { // that would be colored when printed, as can be done on Linux. GTEST_ATTRIBUTE_PRINTF_(2, 3) -static void ColoredPrintf(GTestColor color, const char *fmt, ...) { +static void ColoredPrintf(GTestColor color, const char* fmt, ...) { va_list args; va_start(args, fmt); -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \ - GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || defined(ESP_PLATFORM) - const bool use_color = AlwaysFalse(); -#else static const bool in_color_mode = + // We don't condition this on GTEST_HAS_FILE_SYSTEM because we still need + // to be able to detect terminal I/O regardless. ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0); + const bool use_color = in_color_mode && (color != GTestColor::kDefault); -#endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS if (!use_color) { vprintf(fmt, args); @@ -3292,8 +3342,9 @@ static void ColoredPrintf(GTestColor color, const char *fmt, ...) { return; } -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \ - !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \ + !defined(GTEST_OS_WINDOWS_GAMES) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_WINDOWS_MINGW) const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); // Gets the current text color. @@ -3347,7 +3398,7 @@ static void PrintFullTestCommentIfPresent(const TestInfo& test_info) { // Class PrettyUnitTestResultPrinter is copyable. class PrettyUnitTestResultPrinter : public TestEventListener { public: - PrettyUnitTestResultPrinter() {} + PrettyUnitTestResultPrinter() = default; static void PrintTestName(const char* test_suite, const char* test) { printf("%s.%s", test_suite, test); } @@ -3364,6 +3415,7 @@ class PrettyUnitTestResultPrinter : public TestEventListener { #endif // OnTestCaseStart void OnTestStart(const TestInfo& test_info) override; + void OnTestDisabled(const TestInfo& test_info) override; void OnTestPartResult(const TestPartResult& result) override; void OnTestEnd(const TestInfo& test_info) override; @@ -3384,13 +3436,14 @@ class PrettyUnitTestResultPrinter : public TestEventListener { static void PrintSkippedTests(const UnitTest& unit_test); }; - // Fired before each iteration of tests starts. +// Fired before each iteration of tests starts. void PrettyUnitTestResultPrinter::OnTestIterationStart( const UnitTest& unit_test, int iteration) { - if (GTEST_FLAG(repeat) != 1) + if (GTEST_FLAG_GET(repeat) != 1) printf("\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1); - const char* const filter = GTEST_FLAG(filter).c_str(); + std::string f = GTEST_FLAG_GET(filter); + const char* const filter = f.c_str(); // Prints the filter if it's not *. This reminds the user that some // tests may be skipped. @@ -3406,7 +3459,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart( internal::posix::GetEnv(kTestTotalShards)); } - if (GTEST_FLAG(shuffle)) { + if (GTEST_FLAG_GET(shuffle)) { ColoredPrintf(GTestColor::kYellow, "Note: Randomizing tests' orders with a seed of %d .\n", unit_test.random_seed()); @@ -3462,6 +3515,13 @@ void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) { fflush(stdout); } +void PrettyUnitTestResultPrinter::OnTestDisabled(const TestInfo& test_info) { + ColoredPrintf(GTestColor::kYellow, "[ DISABLED ] "); + PrintTestName(test_info.test_suite_name(), test_info.name()); + printf("\n"); + fflush(stdout); +} + // Called after an assertion failure. void PrettyUnitTestResultPrinter::OnTestPartResult( const TestPartResult& result) { @@ -3486,12 +3546,12 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) { ColoredPrintf(GTestColor::kRed, "[ FAILED ] "); } PrintTestName(test_info.test_suite_name(), test_info.name()); - if (test_info.result()->Failed()) - PrintFullTestCommentIfPresent(test_info); + if (test_info.result()->Failed()) PrintFullTestCommentIfPresent(test_info); - if (GTEST_FLAG(print_time)) { - printf(" (%s ms)\n", internal::StreamableToString( - test_info.result()->elapsed_time()).c_str()); + if (GTEST_FLAG_GET(print_time)) { + printf(" (%s ms)\n", + internal::StreamableToString(test_info.result()->elapsed_time()) + .c_str()); } else { printf("\n"); } @@ -3500,7 +3560,7 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) { #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ void PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestCase& test_case) { - if (!GTEST_FLAG(print_time)) return; + if (!GTEST_FLAG_GET(print_time)) return; const std::string counts = FormatCountableNoun(test_case.test_to_run_count(), "test", "tests"); @@ -3511,7 +3571,7 @@ void PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestCase& test_case) { } #else void PrettyUnitTestResultPrinter::OnTestSuiteEnd(const TestSuite& test_suite) { - if (!GTEST_FLAG(print_time)) return; + if (!GTEST_FLAG_GET(print_time)) return; const std::string counts = FormatCountableNoun(test_suite.test_to_run_count(), "test", "tests"); @@ -3607,7 +3667,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, printf("%s from %s ran.", FormatTestCount(unit_test.test_to_run_count()).c_str(), FormatTestSuiteCount(unit_test.test_suite_to_run_count()).c_str()); - if (GTEST_FLAG(print_time)) { + if (GTEST_FLAG_GET(print_time)) { printf(" (%s ms total)", internal::StreamableToString(unit_test.elapsed_time()).c_str()); } @@ -3628,7 +3688,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, } int num_disabled = unit_test.reportable_disabled_test_count(); - if (num_disabled && !GTEST_FLAG(also_run_disabled_tests)) { + if (num_disabled && !GTEST_FLAG_GET(also_run_disabled_tests)) { if (unit_test.Passed()) { printf("\n"); // Add a spacer if no FAILURE banner is displayed. } @@ -3646,7 +3706,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, // Class BriefUnitTestResultPrinter is copyable. class BriefUnitTestResultPrinter : public TestEventListener { public: - BriefUnitTestResultPrinter() {} + BriefUnitTestResultPrinter() = default; static void PrintTestName(const char* test_suite, const char* test) { printf("%s.%s", test_suite, test); } @@ -3664,6 +3724,7 @@ class BriefUnitTestResultPrinter : public TestEventListener { #endif // OnTestCaseStart void OnTestStart(const TestInfo& /*test_info*/) override {} + void OnTestDisabled(const TestInfo& /*test_info*/) override {} void OnTestPartResult(const TestPartResult& result) override; void OnTestEnd(const TestInfo& test_info) override; @@ -3700,7 +3761,7 @@ void BriefUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) { PrintTestName(test_info.test_suite_name(), test_info.name()); PrintFullTestCommentIfPresent(test_info); - if (GTEST_FLAG(print_time)) { + if (GTEST_FLAG_GET(print_time)) { printf(" (%s ms)\n", internal::StreamableToString(test_info.result()->elapsed_time()) .c_str()); @@ -3717,7 +3778,7 @@ void BriefUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, printf("%s from %s ran.", FormatTestCount(unit_test.test_to_run_count()).c_str(), FormatTestSuiteCount(unit_test.test_suite_to_run_count()).c_str()); - if (GTEST_FLAG(print_time)) { + if (GTEST_FLAG_GET(print_time)) { printf(" (%s ms total)", internal::StreamableToString(unit_test.elapsed_time()).c_str()); } @@ -3732,7 +3793,7 @@ void BriefUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, } int num_disabled = unit_test.reportable_disabled_test_count(); - if (num_disabled && !GTEST_FLAG(also_run_disabled_tests)) { + if (num_disabled && !GTEST_FLAG_GET(also_run_disabled_tests)) { if (unit_test.Passed()) { printf("\n"); // Add a spacer if no FAILURE banner is displayed. } @@ -3752,7 +3813,7 @@ class TestEventRepeater : public TestEventListener { public: TestEventRepeater() : forwarding_enabled_(true) {} ~TestEventRepeater() override; - void Append(TestEventListener *listener); + void Append(TestEventListener* listener); TestEventListener* Release(TestEventListener* listener); // Controls whether events will be forwarded to listeners_. Set to false @@ -3760,27 +3821,28 @@ class TestEventRepeater : public TestEventListener { bool forwarding_enabled() const { return forwarding_enabled_; } void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; } - void OnTestProgramStart(const UnitTest& unit_test) override; + void OnTestProgramStart(const UnitTest& parameter) override; void OnTestIterationStart(const UnitTest& unit_test, int iteration) override; - void OnEnvironmentsSetUpStart(const UnitTest& unit_test) override; - void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) override; + void OnEnvironmentsSetUpStart(const UnitTest& parameter) override; + void OnEnvironmentsSetUpEnd(const UnitTest& parameter) override; // Legacy API is deprecated but still available #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ void OnTestCaseStart(const TestSuite& parameter) override; #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ void OnTestSuiteStart(const TestSuite& parameter) override; - void OnTestStart(const TestInfo& test_info) override; - void OnTestPartResult(const TestPartResult& result) override; - void OnTestEnd(const TestInfo& test_info) override; + void OnTestStart(const TestInfo& parameter) override; + void OnTestDisabled(const TestInfo& parameter) override; + void OnTestPartResult(const TestPartResult& parameter) override; + void OnTestEnd(const TestInfo& parameter) override; // Legacy API is deprecated but still available #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ void OnTestCaseEnd(const TestCase& parameter) override; #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ void OnTestSuiteEnd(const TestSuite& parameter) override; - void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override; - void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) override; + void OnEnvironmentsTearDownStart(const UnitTest& parameter) override; + void OnEnvironmentsTearDownEnd(const UnitTest& parameter) override; void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override; - void OnTestProgramEnd(const UnitTest& unit_test) override; + void OnTestProgramEnd(const UnitTest& parameter) override; private: // Controls whether events will be forwarded to listeners_. Set to false @@ -3789,18 +3851,19 @@ class TestEventRepeater : public TestEventListener { // The list of listeners that receive events. std::vector listeners_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventRepeater); + TestEventRepeater(const TestEventRepeater&) = delete; + TestEventRepeater& operator=(const TestEventRepeater&) = delete; }; TestEventRepeater::~TestEventRepeater() { ForEach(listeners_, Delete); } -void TestEventRepeater::Append(TestEventListener *listener) { +void TestEventRepeater::Append(TestEventListener* listener) { listeners_.push_back(listener); } -TestEventListener* TestEventRepeater::Release(TestEventListener *listener) { +TestEventListener* TestEventRepeater::Release(TestEventListener* listener) { for (size_t i = 0; i < listeners_.size(); ++i) { if (listeners_[i] == listener) { listeners_.erase(listeners_.begin() + static_cast(i)); @@ -3813,14 +3876,14 @@ TestEventListener* TestEventRepeater::Release(TestEventListener *listener) { // Since most methods are very similar, use macros to reduce boilerplate. // This defines a member that forwards the call to all listeners. -#define GTEST_REPEATER_METHOD_(Name, Type) \ -void TestEventRepeater::Name(const Type& parameter) { \ - if (forwarding_enabled_) { \ - for (size_t i = 0; i < listeners_.size(); i++) { \ - listeners_[i]->Name(parameter); \ - } \ - } \ -} +#define GTEST_REPEATER_METHOD_(Name, Type) \ + void TestEventRepeater::Name(const Type& parameter) { \ + if (forwarding_enabled_) { \ + for (size_t i = 0; i < listeners_.size(); i++) { \ + listeners_[i]->Name(parameter); \ + } \ + } \ + } // This defines a member that forwards the call to all listeners in reverse // order. #define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \ @@ -3840,6 +3903,7 @@ GTEST_REPEATER_METHOD_(OnTestCaseStart, TestSuite) #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ GTEST_REPEATER_METHOD_(OnTestSuiteStart, TestSuite) GTEST_REPEATER_METHOD_(OnTestStart, TestInfo) +GTEST_REPEATER_METHOD_(OnTestDisabled, TestInfo) GTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult) GTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest) GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest) @@ -3875,6 +3939,7 @@ void TestEventRepeater::OnTestIterationEnd(const UnitTest& unit_test, // End TestEventRepeater +#if GTEST_HAS_FILE_SYSTEM // This class generates an XML output file. class XmlUnitTestResultPrinter : public EmptyTestEventListener { public: @@ -3890,12 +3955,13 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { private: // Is c a whitespace character that is normalized to a space character // when it appears in an XML attribute value? - static bool IsNormalizableWhitespace(char c) { - return c == 0x9 || c == 0xA || c == 0xD; + static bool IsNormalizableWhitespace(unsigned char c) { + return c == '\t' || c == '\n' || c == '\r'; } // May c appear in a well-formed XML document? - static bool IsValidXmlCharacter(char c) { + // https://www.w3.org/TR/REC-xml/#charsets + static bool IsValidXmlCharacter(unsigned char c) { return IsNormalizableWhitespace(c) || c >= 0x20; } @@ -3934,6 +4000,12 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { static void OutputXmlTestSuiteForTestResult(::std::ostream* stream, const TestResult& result); + // Streams a test case XML stanza containing the given test result. + // + // Requires: result.Failed() + static void OutputXmlTestCaseForTestResult(::std::ostream* stream, + const TestResult& result); + // Streams an XML representation of a TestResult object. static void OutputXmlTestResult(::std::ostream* stream, const TestResult& result); @@ -3951,21 +4023,17 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { static void PrintXmlUnitTest(::std::ostream* stream, const UnitTest& unit_test); - // Produces a string representing the test properties in a result as space - // delimited XML attributes based on the property key="value" pairs. - // When the std::string is not empty, it includes a space at the beginning, - // to delimit this attribute from prior attributes. - static std::string TestPropertiesAsXmlAttributes(const TestResult& result); - // Streams an XML representation of the test properties of a TestResult // object. static void OutputXmlTestProperties(std::ostream* stream, - const TestResult& result); + const TestResult& result, + const std::string& indent); // The output file. const std::string output_file_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(XmlUnitTestResultPrinter); + XmlUnitTestResultPrinter(const XmlUnitTestResultPrinter&) = delete; + XmlUnitTestResultPrinter& operator=(const XmlUnitTestResultPrinter&) = delete; }; // Creates a new XmlUnitTestResultPrinter. @@ -4005,8 +4073,8 @@ void XmlUnitTestResultPrinter::ListTestsMatchingFilter( // module will consist of ordinary English text. // If this module is ever modified to produce version 1.1 XML output, // most invalid characters can be retained using character references. -std::string XmlUnitTestResultPrinter::EscapeXml( - const std::string& str, bool is_attribute) { +std::string XmlUnitTestResultPrinter::EscapeXml(const std::string& str, + bool is_attribute) { Message m; for (size_t i = 0; i < str.size(); ++i) { @@ -4034,8 +4102,9 @@ std::string XmlUnitTestResultPrinter::EscapeXml( m << '"'; break; default: - if (IsValidXmlCharacter(ch)) { - if (is_attribute && IsNormalizableWhitespace(ch)) + if (IsValidXmlCharacter(static_cast(ch))) { + if (is_attribute && + IsNormalizableWhitespace(static_cast(ch))) m << "&#x" << String::FormatByte(static_cast(ch)) << ";"; else @@ -4056,7 +4125,7 @@ std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters( std::string output; output.reserve(str.size()); for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) - if (IsValidXmlCharacter(*it)) + if (IsValidXmlCharacter(static_cast(*it))) output.push_back(*it); return output; @@ -4064,7 +4133,6 @@ std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters( // The following routines generate an XML representation of a UnitTest // object. -// GOOGLETEST_CM0009 DO NOT DELETE // // This is how Google Test concepts map to the DTD: // @@ -4082,6 +4150,13 @@ std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters( // Formats the given time in milliseconds as seconds. std::string FormatTimeInMillisAsSeconds(TimeInMillis ms) { ::std::stringstream ss; + // For the exact N seconds, makes sure output has a trailing decimal point. + // Sets precision so that we won't have many trailing zeros (e.g., 300 ms + // will be just 0.3, 410 ms 0.41, and so on) + ss << std::fixed + << std::setprecision( + ms % 1000 == 0 ? 0 : (ms % 100 == 0 ? 1 : (ms % 10 == 0 ? 2 : 3))) + << std::showpoint; ss << (static_cast(ms) * 1e-3); return ss.str(); } @@ -4113,12 +4188,12 @@ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms) { return ""; // YYYY-MM-DDThh:mm:ss.sss return StreamableToString(time_struct.tm_year + 1900) + "-" + - String::FormatIntWidth2(time_struct.tm_mon + 1) + "-" + - String::FormatIntWidth2(time_struct.tm_mday) + "T" + - String::FormatIntWidth2(time_struct.tm_hour) + ":" + - String::FormatIntWidth2(time_struct.tm_min) + ":" + - String::FormatIntWidth2(time_struct.tm_sec) + "." + - String::FormatIntWidthN(static_cast(ms % 1000), 3); + String::FormatIntWidth2(time_struct.tm_mon + 1) + "-" + + String::FormatIntWidth2(time_struct.tm_mday) + "T" + + String::FormatIntWidth2(time_struct.tm_hour) + ":" + + String::FormatIntWidth2(time_struct.tm_min) + ":" + + String::FormatIntWidth2(time_struct.tm_sec) + "." + + String::FormatIntWidthN(static_cast(ms % 1000), 3); } // Streams an XML CDATA section, escaping invalid CDATA sequences as needed. @@ -4129,8 +4204,8 @@ void XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream, for (;;) { const char* const next_segment = strstr(segment, "]]>"); if (next_segment != nullptr) { - stream->write( - segment, static_cast(next_segment - segment)); + stream->write(segment, + static_cast(next_segment - segment)); *stream << "]]>]]>"); } else { @@ -4142,15 +4217,13 @@ void XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream, } void XmlUnitTestResultPrinter::OutputXmlAttribute( - std::ostream* stream, - const std::string& element_name, - const std::string& name, - const std::string& value) { + std::ostream* stream, const std::string& element_name, + const std::string& name, const std::string& value) { const std::vector& allowed_names = GetReservedOutputAttributesForElement(element_name); GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) != - allowed_names.end()) + allowed_names.end()) << "Attribute " << name << " is not allowed for element <" << element_name << ">."; @@ -4175,6 +4248,15 @@ void XmlUnitTestResultPrinter::OutputXmlTestSuiteForTestResult( FormatEpochTimeInMillisAsIso8601(result.start_timestamp())); *stream << ">"; + OutputXmlTestCaseForTestResult(stream, result); + + // Complete the test suite. + *stream << " \n"; +} + +// Streams a test case XML stanza containing the given test result. +void XmlUnitTestResultPrinter::OutputXmlTestCaseForTestResult( + ::std::ostream* stream, const TestResult& result) { // Output the boilerplate for a minimal test case with a single test. *stream << " \n"; } // Prints an XML representation of a TestInfo object. @@ -4216,10 +4295,11 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, OutputXmlAttribute(stream, kTestsuite, "type_param", test_info.type_param()); } - if (GTEST_FLAG(list_tests)) { - OutputXmlAttribute(stream, kTestsuite, "file", test_info.file()); - OutputXmlAttribute(stream, kTestsuite, "line", - StreamableToString(test_info.line())); + + OutputXmlAttribute(stream, kTestsuite, "file", test_info.file()); + OutputXmlAttribute(stream, kTestsuite, "line", + StreamableToString(test_info.line())); + if (GTEST_FLAG_GET(list_tests)) { *stream << " />\n"; return; } @@ -4254,8 +4334,7 @@ void XmlUnitTestResultPrinter::OutputXmlTestResult(::std::ostream* stream, internal::FormatCompilerIndependentFileLocation(part.file_name(), part.line_number()); const std::string summary = location + "\n" + part.summary(); - *stream << " "; const std::string detail = location + "\n" + part.message(); OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str()); @@ -4282,7 +4361,7 @@ void XmlUnitTestResultPrinter::OutputXmlTestResult(::std::ostream* stream, if (failures == 0 && skips == 0) { *stream << ">\n"; } - OutputXmlTestProperties(stream, result); + OutputXmlTestProperties(stream, result, /*indent=*/" "); *stream << " \n"; } } @@ -4295,7 +4374,7 @@ void XmlUnitTestResultPrinter::PrintXmlTestSuite(std::ostream* stream, OutputXmlAttribute(stream, kTestsuite, "name", test_suite.name()); OutputXmlAttribute(stream, kTestsuite, "tests", StreamableToString(test_suite.reportable_test_count())); - if (!GTEST_FLAG(list_tests)) { + if (!GTEST_FLAG_GET(list_tests)) { OutputXmlAttribute(stream, kTestsuite, "failures", StreamableToString(test_suite.failed_test_count())); OutputXmlAttribute( @@ -4311,13 +4390,18 @@ void XmlUnitTestResultPrinter::PrintXmlTestSuite(std::ostream* stream, OutputXmlAttribute( stream, kTestsuite, "timestamp", FormatEpochTimeInMillisAsIso8601(test_suite.start_timestamp())); - *stream << TestPropertiesAsXmlAttributes(test_suite.ad_hoc_test_result()); } *stream << ">\n"; + OutputXmlTestProperties(stream, test_suite.ad_hoc_test_result(), + /*indent=*/" "); for (int i = 0; i < test_suite.total_test_count(); ++i) { if (test_suite.GetTestInfo(i)->is_reportable()) OutputXmlTestInfo(stream, test_suite.name(), *test_suite.GetTestInfo(i)); } + if (test_suite.ad_hoc_test_result().Failed()) { + OutputXmlTestCaseForTestResult(stream, test_suite.ad_hoc_test_result()); + } + *stream << " \n"; } @@ -4343,15 +4427,16 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(std::ostream* stream, stream, kTestsuites, "timestamp", FormatEpochTimeInMillisAsIso8601(unit_test.start_timestamp())); - if (GTEST_FLAG(shuffle)) { + if (GTEST_FLAG_GET(shuffle)) { OutputXmlAttribute(stream, kTestsuites, "random_seed", StreamableToString(unit_test.random_seed())); } - *stream << TestPropertiesAsXmlAttributes(unit_test.ad_hoc_test_result()); OutputXmlAttribute(stream, kTestsuites, "name", "AllTests"); *stream << ">\n"; + OutputXmlTestProperties(stream, unit_test.ad_hoc_test_result(), + /*indent=*/" "); for (int i = 0; i < unit_test.total_test_suite_count(); ++i) { if (unit_test.GetTestSuite(i)->reportable_test_count() > 0) PrintXmlTestSuite(stream, *unit_test.GetTestSuite(i)); @@ -4388,21 +4473,8 @@ void XmlUnitTestResultPrinter::PrintXmlTestsList( *stream << "\n"; } -// Produces a string representing the test properties in a result as space -// delimited XML attributes based on the property key="value" pairs. -std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes( - const TestResult& result) { - Message attributes; - for (int i = 0; i < result.test_property_count(); ++i) { - const TestProperty& property = result.GetTestProperty(i); - attributes << " " << property.key() << "=" - << "\"" << EscapeXmlAttribute(property.value()) << "\""; - } - return attributes.GetString(); -} - void XmlUnitTestResultPrinter::OutputXmlTestProperties( - std::ostream* stream, const TestResult& result) { + std::ostream* stream, const TestResult& result, const std::string& indent) { const std::string kProperties = "properties"; const std::string kProperty = "property"; @@ -4410,19 +4482,21 @@ void XmlUnitTestResultPrinter::OutputXmlTestProperties( return; } - *stream << "<" << kProperties << ">\n"; + *stream << indent << "<" << kProperties << ">\n"; for (int i = 0; i < result.test_property_count(); ++i) { const TestProperty& property = result.GetTestProperty(i); - *stream << "<" << kProperty; + *stream << indent << " <" << kProperty; *stream << " name=\"" << EscapeXmlAttribute(property.key()) << "\""; *stream << " value=\"" << EscapeXmlAttribute(property.value()) << "\""; *stream << "/>\n"; } - *stream << "\n"; + *stream << indent << "\n"; } // End XmlUnitTestResultPrinter +#endif // GTEST_HAS_FILE_SYSTEM +#if GTEST_HAS_FILE_SYSTEM // This class generates an JSON output file. class JsonUnitTestResultPrinter : public EmptyTestEventListener { public: @@ -4442,16 +4516,12 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener { //// streams the attribute as JSON. static void OutputJsonKey(std::ostream* stream, const std::string& element_name, - const std::string& name, - const std::string& value, - const std::string& indent, - bool comma = true); + const std::string& name, const std::string& value, + const std::string& indent, bool comma = true); static void OutputJsonKey(std::ostream* stream, const std::string& element_name, - const std::string& name, - int value, - const std::string& indent, - bool comma = true); + const std::string& name, int value, + const std::string& indent, bool comma = true); // Streams a test suite JSON stanza containing the given test result. // @@ -4459,6 +4529,12 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener { static void OutputJsonTestSuiteForTestResult(::std::ostream* stream, const TestResult& result); + // Streams a test case JSON stanza containing the given test result. + // + // Requires: result.Failed() + static void OutputJsonTestCaseForTestResult(::std::ostream* stream, + const TestResult& result); + // Streams a JSON representation of a TestResult object. static void OutputJsonTestResult(::std::ostream* stream, const TestResult& result); @@ -4484,7 +4560,9 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener { // The output file. const std::string output_file_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(JsonUnitTestResultPrinter); + JsonUnitTestResultPrinter(const JsonUnitTestResultPrinter&) = delete; + JsonUnitTestResultPrinter& operator=(const JsonUnitTestResultPrinter&) = + delete; }; // Creates a new JsonUnitTestResultPrinter. @@ -4496,7 +4574,7 @@ JsonUnitTestResultPrinter::JsonUnitTestResultPrinter(const char* output_file) } void JsonUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, - int /*iteration*/) { + int /*iteration*/) { FILE* jsonout = OpenFileForWriting(output_file_); std::stringstream stream; PrintJsonUnitTest(&stream, unit_test); @@ -4562,55 +4640,48 @@ static std::string FormatEpochTimeInMillisAsRFC3339(TimeInMillis ms) { return ""; // YYYY-MM-DDThh:mm:ss return StreamableToString(time_struct.tm_year + 1900) + "-" + - String::FormatIntWidth2(time_struct.tm_mon + 1) + "-" + - String::FormatIntWidth2(time_struct.tm_mday) + "T" + - String::FormatIntWidth2(time_struct.tm_hour) + ":" + - String::FormatIntWidth2(time_struct.tm_min) + ":" + - String::FormatIntWidth2(time_struct.tm_sec) + "Z"; + String::FormatIntWidth2(time_struct.tm_mon + 1) + "-" + + String::FormatIntWidth2(time_struct.tm_mday) + "T" + + String::FormatIntWidth2(time_struct.tm_hour) + ":" + + String::FormatIntWidth2(time_struct.tm_min) + ":" + + String::FormatIntWidth2(time_struct.tm_sec) + "Z"; } static inline std::string Indent(size_t width) { return std::string(width, ' '); } -void JsonUnitTestResultPrinter::OutputJsonKey( - std::ostream* stream, - const std::string& element_name, - const std::string& name, - const std::string& value, - const std::string& indent, - bool comma) { +void JsonUnitTestResultPrinter::OutputJsonKey(std::ostream* stream, + const std::string& element_name, + const std::string& name, + const std::string& value, + const std::string& indent, + bool comma) { const std::vector& allowed_names = GetReservedOutputAttributesForElement(element_name); GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) != - allowed_names.end()) + allowed_names.end()) << "Key \"" << name << "\" is not allowed for value \"" << element_name << "\"."; *stream << indent << "\"" << name << "\": \"" << EscapeJson(value) << "\""; - if (comma) - *stream << ",\n"; + if (comma) *stream << ",\n"; } void JsonUnitTestResultPrinter::OutputJsonKey( - std::ostream* stream, - const std::string& element_name, - const std::string& name, - int value, - const std::string& indent, - bool comma) { + std::ostream* stream, const std::string& element_name, + const std::string& name, int value, const std::string& indent, bool comma) { const std::vector& allowed_names = GetReservedOutputAttributesForElement(element_name); GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) != - allowed_names.end()) + allowed_names.end()) << "Key \"" << name << "\" is not allowed for value \"" << element_name << "\"."; *stream << indent << "\"" << name << "\": " << StreamableToString(value); - if (comma) - *stream << ",\n"; + if (comma) *stream << ",\n"; } // Streams a test suite JSON stanza containing the given test result. @@ -4620,7 +4691,7 @@ void JsonUnitTestResultPrinter::OutputJsonTestSuiteForTestResult( *stream << Indent(4) << "{\n"; OutputJsonKey(stream, "testsuite", "name", "NonTestSuiteFailure", Indent(6)); OutputJsonKey(stream, "testsuite", "tests", 1, Indent(6)); - if (!GTEST_FLAG(list_tests)) { + if (!GTEST_FLAG_GET(list_tests)) { OutputJsonKey(stream, "testsuite", "failures", 1, Indent(6)); OutputJsonKey(stream, "testsuite", "disabled", 0, Indent(6)); OutputJsonKey(stream, "testsuite", "skipped", 0, Indent(6)); @@ -4634,6 +4705,15 @@ void JsonUnitTestResultPrinter::OutputJsonTestSuiteForTestResult( } *stream << Indent(6) << "\"testsuite\": [\n"; + OutputJsonTestCaseForTestResult(stream, result); + + // Finish the test suite. + *stream << "\n" << Indent(6) << "]\n" << Indent(4) << "}"; +} + +// Streams a test case JSON stanza containing the given test result. +void JsonUnitTestResultPrinter::OutputJsonTestCaseForTestResult( + ::std::ostream* stream, const TestResult& result) { // Output the boilerplate for a new test case. *stream << Indent(8) << "{\n"; OutputJsonKey(stream, "testcase", "name", "", Indent(10)); @@ -4650,9 +4730,6 @@ void JsonUnitTestResultPrinter::OutputJsonTestSuiteForTestResult( // Output the actual test result. OutputJsonTestResult(stream, result); - - // Finish the test suite. - *stream << "\n" << Indent(6) << "]\n" << Indent(4) << "}"; } // Prints a JSON representation of a TestInfo object. @@ -4674,11 +4751,14 @@ void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream, OutputJsonKey(stream, kTestsuite, "type_param", test_info.type_param(), kIndent); } - if (GTEST_FLAG(list_tests)) { - OutputJsonKey(stream, kTestsuite, "file", test_info.file(), kIndent); - OutputJsonKey(stream, kTestsuite, "line", test_info.line(), kIndent, false); + + OutputJsonKey(stream, kTestsuite, "file", test_info.file(), kIndent); + OutputJsonKey(stream, kTestsuite, "line", test_info.line(), kIndent, false); + if (GTEST_FLAG_GET(list_tests)) { *stream << "\n" << Indent(8) << "}"; return; + } else { + *stream << ",\n"; } OutputJsonKey(stream, kTestsuite, "status", @@ -4704,27 +4784,53 @@ void JsonUnitTestResultPrinter::OutputJsonTestResult(::std::ostream* stream, const TestResult& result) { const std::string kIndent = Indent(10); - int failures = 0; - for (int i = 0; i < result.total_part_count(); ++i) { - const TestPartResult& part = result.GetTestPartResult(i); - if (part.failed()) { - *stream << ",\n"; - if (++failures == 1) { - *stream << kIndent << "\"" << "failures" << "\": [\n"; + { + int failures = 0; + for (int i = 0; i < result.total_part_count(); ++i) { + const TestPartResult& part = result.GetTestPartResult(i); + if (part.failed()) { + *stream << ",\n"; + if (++failures == 1) { + *stream << kIndent << "\"" << "failures" << "\": [\n"; + } + const std::string location = + internal::FormatCompilerIndependentFileLocation(part.file_name(), + part.line_number()); + const std::string message = + EscapeJson(location + "\n" + part.message()); + *stream << kIndent << " {\n" + << kIndent << " \"failure\": \"" << message << "\",\n" + << kIndent << " \"type\": \"\"\n" + << kIndent << " }"; } - const std::string location = - internal::FormatCompilerIndependentFileLocation(part.file_name(), - part.line_number()); - const std::string message = EscapeJson(location + "\n" + part.message()); - *stream << kIndent << " {\n" - << kIndent << " \"failure\": \"" << message << "\",\n" - << kIndent << " \"type\": \"\"\n" - << kIndent << " }"; } + + if (failures > 0) *stream << "\n" << kIndent << "]"; + } + + { + int skipped = 0; + for (int i = 0; i < result.total_part_count(); ++i) { + const TestPartResult& part = result.GetTestPartResult(i); + if (part.skipped()) { + *stream << ",\n"; + if (++skipped == 1) { + *stream << kIndent << "\"" << "skipped" << "\": [\n"; + } + const std::string location = + internal::FormatCompilerIndependentFileLocation(part.file_name(), + part.line_number()); + const std::string message = + EscapeJson(location + "\n" + part.message()); + *stream << kIndent << " {\n" + << kIndent << " \"message\": \"" << message << "\"\n" + << kIndent << " }"; + } + } + + if (skipped > 0) *stream << "\n" << kIndent << "]"; } - if (failures > 0) - *stream << "\n" << kIndent << "]"; *stream << "\n" << Indent(8) << "}"; } @@ -4738,7 +4844,7 @@ void JsonUnitTestResultPrinter::PrintJsonTestSuite( OutputJsonKey(stream, kTestsuite, "name", test_suite.name(), kIndent); OutputJsonKey(stream, kTestsuite, "tests", test_suite.reportable_test_count(), kIndent); - if (!GTEST_FLAG(list_tests)) { + if (!GTEST_FLAG_GET(list_tests)) { OutputJsonKey(stream, kTestsuite, "failures", test_suite.failed_test_count(), kIndent); OutputJsonKey(stream, kTestsuite, "disabled", @@ -4768,6 +4874,16 @@ void JsonUnitTestResultPrinter::PrintJsonTestSuite( OutputJsonTestInfo(stream, test_suite.name(), *test_suite.GetTestInfo(i)); } } + + // If there was a failure in the test suite setup or teardown include that in + // the output. + if (test_suite.ad_hoc_test_result().Failed()) { + if (comma) { + *stream << ",\n"; + } + OutputJsonTestCaseForTestResult(stream, test_suite.ad_hoc_test_result()); + } + *stream << "\n" << kIndent << "]\n" << Indent(4) << "}"; } @@ -4785,7 +4901,7 @@ void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream, OutputJsonKey(stream, kTestsuites, "disabled", unit_test.reportable_disabled_test_count(), kIndent); OutputJsonKey(stream, kTestsuites, "errors", 0, kIndent); - if (GTEST_FLAG(shuffle)) { + if (GTEST_FLAG_GET(shuffle)) { OutputJsonKey(stream, kTestsuites, "random_seed", unit_test.random_seed(), kIndent); } @@ -4817,10 +4933,15 @@ void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream, // If there was a test failure outside of one of the test suites (like in a // test environment) include that in the output. if (unit_test.ad_hoc_test_result().Failed()) { + if (comma) { + *stream << ",\n"; + } OutputJsonTestSuiteForTestResult(stream, unit_test.ad_hoc_test_result()); } - *stream << "\n" << kIndent << "]\n" << "}\n"; + *stream << "\n" + << kIndent << "]\n" + << "}\n"; } void JsonUnitTestResultPrinter::PrintJsonTestList( @@ -4855,13 +4976,15 @@ std::string JsonUnitTestResultPrinter::TestPropertiesAsJson( Message attributes; for (int i = 0; i < result.test_property_count(); ++i) { const TestProperty& property = result.GetTestProperty(i); - attributes << ",\n" << indent << "\"" << property.key() << "\": " - << "\"" << EscapeJson(property.value()) << "\""; + attributes << ",\n" + << indent << "\"" << property.key() << "\": " << "\"" + << EscapeJson(property.value()) << "\""; } return attributes.GetString(); } // End JsonUnitTestResultPrinter +#endif // GTEST_HAS_FILE_SYSTEM #if GTEST_CAN_STREAM_RESULTS_ @@ -4879,7 +5002,8 @@ std::string StreamingListener::UrlEncode(const char* str) { case '=': case '&': case '\n': - result.append("%" + String::FormatByte(static_cast(ch))); + result.push_back('%'); + result.append(String::FormatByte(static_cast(ch))); break; default: result.push_back(ch); @@ -4895,14 +5019,14 @@ void StreamingListener::SocketWriter::MakeConnection() { addrinfo hints; memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; // To allow both IPv4 and IPv6 addresses. + hints.ai_family = AF_UNSPEC; // To allow both IPv4 and IPv6 addresses. hints.ai_socktype = SOCK_STREAM; addrinfo* servinfo = nullptr; // Use the getaddrinfo() to get a linked list of IP addresses for // the given host name. - const int error_num = getaddrinfo( - host_name_.c_str(), port_num_.c_str(), &hints, &servinfo); + const int error_num = + getaddrinfo(host_name_.c_str(), port_num_.c_str(), &hints, &servinfo); if (error_num != 0) { GTEST_LOG_(WARNING) << "stream_result_to: getaddrinfo() failed: " << gai_strerror(error_num); @@ -4911,8 +5035,8 @@ void StreamingListener::SocketWriter::MakeConnection() { // Loop through all the results and connect to the first we can. for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != nullptr; cur_addr = cur_addr->ai_next) { - sockfd_ = socket( - cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol); + sockfd_ = socket(cur_addr->ai_family, cur_addr->ai_socktype, + cur_addr->ai_protocol); if (sockfd_ != -1) { // Connect the client socket to the server socket. if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) { @@ -4940,7 +5064,7 @@ const char* const OsStackTraceGetterInterface::kElidedFramesMarker = std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count) GTEST_LOCK_EXCLUDED_(mutex_) { -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL std::string result; if (max_depth <= 0) { @@ -4962,7 +5086,7 @@ std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count) for (int i = 0; i < raw_stack_size; ++i) { if (raw_stack[i] == caller_frame && - !GTEST_FLAG(show_internal_stack_frames)) { + !GTEST_FLAG_GET(show_internal_stack_frames)) { // Add a marker to the trace and stop adding frames. absl::StrAppend(&result, kElidedFramesMarker, "\n"); break; @@ -4981,7 +5105,7 @@ std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count) return result; -#else // !GTEST_HAS_ABSL +#else // !GTEST_HAS_ABSL static_cast(max_depth); static_cast(skip_count); return ""; @@ -4989,7 +5113,7 @@ std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count) } void OsStackTraceGetter::UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_) { -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL void* caller_frame = nullptr; if (absl::GetStackTrace(&caller_frame, 1, 3) <= 0) { caller_frame = nullptr; @@ -5000,26 +5124,27 @@ void OsStackTraceGetter::UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_) { #endif // GTEST_HAS_ABSL } +#ifdef GTEST_HAS_DEATH_TEST // A helper class that creates the premature-exit file in its // constructor and deletes the file in its destructor. class ScopedPrematureExitFile { public: explicit ScopedPrematureExitFile(const char* premature_exit_filepath) - : premature_exit_filepath_(premature_exit_filepath ? - premature_exit_filepath : "") { + : premature_exit_filepath_( + premature_exit_filepath ? premature_exit_filepath : "") { // If a path to the premature-exit file is specified... if (!premature_exit_filepath_.empty()) { // create the file with a single "0" character in it. I/O // errors are ignored as there's nothing better we can do and we // don't want to fail the test because of this. - FILE* pfile = posix::FOpen(premature_exit_filepath, "w"); + FILE* pfile = posix::FOpen(premature_exit_filepath_.c_str(), "w"); fwrite("0", 1, 1, pfile); fclose(pfile); } } ~ScopedPrematureExitFile() { -#if !defined GTEST_OS_ESP8266 +#ifndef GTEST_OS_ESP8266 if (!premature_exit_filepath_.empty()) { int retval = remove(premature_exit_filepath_.c_str()); if (retval) { @@ -5034,8 +5159,10 @@ class ScopedPrematureExitFile { private: const std::string premature_exit_filepath_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedPrematureExitFile); + ScopedPrematureExitFile(const ScopedPrematureExitFile&) = delete; + ScopedPrematureExitFile& operator=(const ScopedPrematureExitFile&) = delete; }; +#endif // GTEST_HAS_DEATH_TEST } // namespace internal @@ -5107,8 +5234,8 @@ bool TestEventListeners::EventForwardingEnabled() const { return repeater_->forwarding_enabled(); } -void TestEventListeners::SuppressEventForwarding() { - repeater_->set_forwarding_enabled(false); +void TestEventListeners::SuppressEventForwarding(bool suppress) { + repeater_->set_forwarding_enabled(!suppress); } // class UnitTest @@ -5208,7 +5335,7 @@ int UnitTest::test_to_run_count() const { return impl()->test_to_run_count(); } // Gets the time of the test program start, in ms from the start of the // UNIX epoch. internal::TimeInMillis UnitTest::start_timestamp() const { - return impl()->start_timestamp(); + return impl()->start_timestamp(); } // Gets the elapsed time, in milliseconds. @@ -5249,11 +5376,25 @@ TestSuite* UnitTest::GetMutableTestSuite(int i) { return impl()->GetMutableSuiteCase(i); } +void UnitTest::UponLeavingGTest() { + impl()->os_stack_trace_getter()->UponLeavingGTest(); +} + +// Sets the TestSuite object for the test that's currently running. +void UnitTest::set_current_test_suite(TestSuite* a_current_test_suite) { + internal::MutexLock lock(&mutex_); + impl_->set_current_test_suite(a_current_test_suite); +} + +// Sets the TestInfo object for the test that's currently running. +void UnitTest::set_current_test_info(TestInfo* a_current_test_info) { + internal::MutexLock lock(&mutex_); + impl_->set_current_test_info(a_current_test_info); +} + // Returns the list of event listeners that can be used to track events // inside Google Test. -TestEventListeners& UnitTest::listeners() { - return *impl()->listeners(); -} +TestEventListeners& UnitTest::listeners() { return *impl()->listeners(); } // Registers and returns a global test environment. When a test // program is run, all global test environments will be set-up in the @@ -5278,34 +5419,36 @@ Environment* UnitTest::AddEnvironment(Environment* env) { // assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) eventually call // this to report their results. The user code should use the // assertion macros instead of calling this directly. -void UnitTest::AddTestPartResult( - TestPartResult::Type result_type, - const char* file_name, - int line_number, - const std::string& message, - const std::string& os_stack_trace) GTEST_LOCK_EXCLUDED_(mutex_) { +void UnitTest::AddTestPartResult(TestPartResult::Type result_type, + const char* file_name, int line_number, + const std::string& message, + const std::string& os_stack_trace) + GTEST_LOCK_EXCLUDED_(mutex_) { Message msg; msg << message; internal::MutexLock lock(&mutex_); - if (impl_->gtest_trace_stack().size() > 0) { + if (!impl_->gtest_trace_stack().empty()) { msg << "\n" << GTEST_NAME_ << " trace:"; for (size_t i = impl_->gtest_trace_stack().size(); i > 0; --i) { const internal::TraceInfo& trace = impl_->gtest_trace_stack()[i - 1]; - msg << "\n" << internal::FormatFileLocation(trace.file, trace.line) - << " " << trace.message; + msg << "\n" + << internal::FormatFileLocation(trace.file, trace.line) << " " + << trace.message; } } if (os_stack_trace.c_str() != nullptr && !os_stack_trace.empty()) { msg << internal::kStackTraceMarker << os_stack_trace; + } else { + msg << "\n"; } const TestPartResult result = TestPartResult( result_type, file_name, line_number, msg.GetString().c_str()); - impl_->GetTestPartResultReporterForCurrentThread()-> - ReportTestPartResult(result); + impl_->GetTestPartResultReporterForCurrentThread()->ReportTestPartResult( + result); if (result_type != TestPartResult::kSuccess && result_type != TestPartResult::kSkip) { @@ -5314,8 +5457,9 @@ void UnitTest::AddTestPartResult( // in the code (perhaps in order to use Google Test assertions // with another testing framework) and specify the former on the // command line for debugging. - if (GTEST_FLAG(break_on_failure)) { -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT + if (GTEST_FLAG_GET(break_on_failure)) { +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT) // Using DebugBreak on Windows allows gtest to still break into a debugger // when a failure happens and both the --gtest_break_on_failure and // the --gtest_catch_exceptions flags are specified. @@ -5325,13 +5469,17 @@ void UnitTest::AddTestPartResult( (defined(__x86_64__) || defined(__i386__))) // with clang/gcc we can achieve the same effect on x86 by invoking int3 asm("int3"); +#elif GTEST_HAS_BUILTIN(__builtin_trap) + __builtin_trap(); +#elif defined(SIGTRAP) + raise(SIGTRAP); #else // Dereference nullptr through a volatile pointer to prevent the compiler // from removing. We use this rather than abort() or __builtin_trap() for // portability: some debuggers don't correctly trap abort(). *static_cast(nullptr) = 1; #endif // GTEST_OS_WINDOWS - } else if (GTEST_FLAG(throw_on_failure)) { + } else if (GTEST_FLAG_GET(throw_on_failure)) { #if GTEST_HAS_EXCEPTIONS throw internal::GoogleTestFailureException(result); #else @@ -5359,8 +5507,9 @@ void UnitTest::RecordProperty(const std::string& key, // We don't protect this under mutex_, as we only support calling it // from the main thread. int UnitTest::Run() { +#ifdef GTEST_HAS_DEATH_TEST const bool in_death_test_child_process = - internal::GTEST_FLAG(internal_run_death_test).length() > 0; + !GTEST_FLAG_GET(internal_run_death_test).empty(); // Google Test implements this protocol for catching that a test // program exits before returning control to Google Test: @@ -5387,37 +5536,42 @@ int UnitTest::Run() { in_death_test_child_process ? nullptr : internal::posix::GetEnv("TEST_PREMATURE_EXIT_FILE")); +#else + const bool in_death_test_child_process = false; +#endif // GTEST_HAS_DEATH_TEST // Captures the value of GTEST_FLAG(catch_exceptions). This value will be // used for the duration of the program. - impl()->set_catch_exceptions(GTEST_FLAG(catch_exceptions)); + impl()->set_catch_exceptions(GTEST_FLAG_GET(catch_exceptions)); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Either the user wants Google Test to catch exceptions thrown by the // tests or this is executing in the context of death test child // process. In either case the user does not want to see pop-up dialogs // about crashes - they are expected. if (impl()->catch_exceptions() || in_death_test_child_process) { -# if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT +#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_WINDOWS_GAMES) // SetErrorMode doesn't exist on CE. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); -# endif // !GTEST_OS_WINDOWS_MOBILE +#endif // !GTEST_OS_WINDOWS_MOBILE -# if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE +#if (defined(_MSC_VER) || defined(GTEST_OS_WINDOWS_MINGW)) && \ + !defined(GTEST_OS_WINDOWS_MOBILE) // Death test children can be terminated with _abort(). On Windows, // _abort() can show a dialog with a warning message. This forces the // abort message to go to stderr instead. _set_error_mode(_OUT_TO_STDERR); -# endif +#endif -# if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE +#if defined(_MSC_VER) && !defined(GTEST_OS_WINDOWS_MOBILE) // In the debug version, Visual Studio pops up a separate dialog // offering a choice to debug the aborted program. We need to suppress // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement // executed. Google Test will notify the user of any unexpected // failure via stderr. - if (!GTEST_FLAG(break_on_failure)) + if (!GTEST_FLAG_GET(break_on_failure)) _set_abort_behavior( 0x0, // Clear the following flags: _WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump. @@ -5431,21 +5585,26 @@ int UnitTest::Run() { _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); } -# endif +#endif } +#else + (void)in_death_test_child_process; // Needed inside the #if block above #endif // GTEST_OS_WINDOWS return internal::HandleExceptionsInMethodIfSupported( - impl(), - &internal::UnitTestImpl::RunAllTests, - "auxiliary test code (environments or event listeners)") ? 0 : 1; + impl(), &internal::UnitTestImpl::RunAllTests, + "auxiliary test code (environments or event listeners)") + ? 0 + : 1; } +#if GTEST_HAS_FILE_SYSTEM // Returns the working directory when the first TEST() or TEST_F() was // executed. const char* UnitTest::original_working_dir() const { return impl_->original_working_dir_.c_str(); } +#endif // GTEST_HAS_FILE_SYSTEM // Returns the TestSuite object for the test that's currently running, // or NULL if no test is running. @@ -5483,14 +5642,10 @@ UnitTest::parameterized_test_registry() GTEST_LOCK_EXCLUDED_(mutex_) { } // Creates an empty UnitTest. -UnitTest::UnitTest() { - impl_ = new internal::UnitTestImpl(this); -} +UnitTest::UnitTest() { impl_ = new internal::UnitTestImpl(this); } // Destructor of UnitTest. -UnitTest::~UnitTest() { - delete impl_; -} +UnitTest::~UnitTest() { delete impl_; } // Pushes a trace defined by SCOPED_TRACE() on to the per-thread // Google Test trace stack. @@ -5501,8 +5656,7 @@ void UnitTest::PushGTestTrace(const internal::TraceInfo& trace) } // Pops a trace from the per-thread Google Test trace stack. -void UnitTest::PopGTestTrace() - GTEST_LOCK_EXCLUDED_(mutex_) { +void UnitTest::PopGTestTrace() GTEST_LOCK_EXCLUDED_(mutex_) { internal::MutexLock lock(&mutex_); impl_->gtest_trace_stack().pop_back(); } @@ -5514,7 +5668,7 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4355 /* using this in initializer */) default_global_test_part_result_reporter_(this), default_per_thread_test_part_result_reporter_(this), - GTEST_DISABLE_MSC_WARNINGS_POP_() global_test_part_result_repoter_( + GTEST_DISABLE_MSC_WARNINGS_POP_() global_test_part_result_reporter_( &default_global_test_part_result_reporter_), per_thread_test_part_result_reporter_( &default_per_thread_test_part_result_reporter_), @@ -5530,7 +5684,7 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent) random_(0), // Will be reseeded before first use. start_timestamp_(0), elapsed_time_(0), -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST death_test_factory_(new DefaultDeathTestFactory), #endif // Will be overridden by the flag before first use. @@ -5570,12 +5724,12 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) { test_result->RecordProperty(xml_element, test_property); } -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST // Disables event forwarding if the control is currently in a death test // subprocess. Must not be called before InitGoogleTest. void UnitTestImpl::SuppressTestEventsIfInSubprocess() { - if (internal_run_death_test_flag_.get() != nullptr) - listeners()->SuppressEventForwarding(); + if (internal_run_death_test_flag_ != nullptr) + listeners()->SuppressEventForwarding(true); } #endif // GTEST_HAS_DEATH_TEST @@ -5583,28 +5737,35 @@ void UnitTestImpl::SuppressTestEventsIfInSubprocess() { // UnitTestOptions. Must not be called before InitGoogleTest. void UnitTestImpl::ConfigureXmlOutput() { const std::string& output_format = UnitTestOptions::GetOutputFormat(); +#if GTEST_HAS_FILE_SYSTEM if (output_format == "xml") { listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter( UnitTestOptions::GetAbsolutePathToOutputFile().c_str())); } else if (output_format == "json") { listeners()->SetDefaultXmlGenerator(new JsonUnitTestResultPrinter( UnitTestOptions::GetAbsolutePathToOutputFile().c_str())); - } else if (output_format != "") { + } else if (!output_format.empty()) { GTEST_LOG_(WARNING) << "WARNING: unrecognized output format \"" << output_format << "\" ignored."; } +#else + if (!output_format.empty()) { + GTEST_LOG_(ERROR) << "ERROR: alternative output formats require " + << "GTEST_HAS_FILE_SYSTEM to be enabled"; + } +#endif // GTEST_HAS_FILE_SYSTEM } #if GTEST_CAN_STREAM_RESULTS_ // Initializes event listeners for streaming test results in string form. // Must not be called before InitGoogleTest. void UnitTestImpl::ConfigureStreamingOutput() { - const std::string& target = GTEST_FLAG(stream_result_to); + const std::string& target = GTEST_FLAG_GET(stream_result_to); if (!target.empty()) { const size_t pos = target.find(':'); if (pos != std::string::npos) { - listeners()->Append(new StreamingListener(target.substr(0, pos), - target.substr(pos+1))); + listeners()->Append( + new StreamingListener(target.substr(0, pos), target.substr(pos + 1))); } else { GTEST_LOG_(WARNING) << "unrecognized streaming target \"" << target << "\" ignored."; @@ -5628,7 +5789,7 @@ void UnitTestImpl::PostFlagParsingInit() { listeners()->Append(new GTEST_CUSTOM_TEST_EVENT_LISTENER_()); #endif // defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_) -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST InitDeathTestSubprocessControlInfo(); SuppressTestEventsIfInSubprocess(); #endif // GTEST_HAS_DEATH_TEST @@ -5642,7 +5803,7 @@ void UnitTestImpl::PostFlagParsingInit() { // to shut down the default XML output before invoking RUN_ALL_TESTS. ConfigureXmlOutput(); - if (GTEST_FLAG(brief)) { + if (GTEST_FLAG_GET(brief)) { listeners()->SetDefaultResultPrinter(new BriefUnitTestResultPrinter); } @@ -5651,8 +5812,8 @@ void UnitTestImpl::PostFlagParsingInit() { ConfigureStreamingOutput(); #endif // GTEST_CAN_STREAM_RESULTS_ -#if GTEST_HAS_ABSL - if (GTEST_FLAG(install_failure_signal_handler)) { +#ifdef GTEST_HAS_ABSL + if (GTEST_FLAG_GET(install_failure_signal_handler)) { absl::FailureSignalHandlerOptions options; absl::InstallFailureSignalHandler(options); } @@ -5660,29 +5821,6 @@ void UnitTestImpl::PostFlagParsingInit() { } } -// A predicate that checks the name of a TestSuite against a known -// value. -// -// This is used for implementation of the UnitTest class only. We put -// it in the anonymous namespace to prevent polluting the outer -// namespace. -// -// TestSuiteNameIs is copyable. -class TestSuiteNameIs { - public: - // Constructor. - explicit TestSuiteNameIs(const std::string& name) : name_(name) {} - - // Returns true if and only if the name of test_suite matches name_. - bool operator()(const TestSuite* test_suite) const { - return test_suite != nullptr && - strcmp(test_suite->name(), name_.c_str()) == 0; - } - - private: - std::string name_; -}; - // Finds and returns a TestSuite with the given name. If one doesn't // exist, creates one and returns it. It's the CALLER'S // RESPONSIBILITY to ensure that this function is only called WHEN THE @@ -5696,23 +5834,31 @@ class TestSuiteNameIs { // set_up_tc: pointer to the function that sets up the test suite // tear_down_tc: pointer to the function that tears down the test suite TestSuite* UnitTestImpl::GetTestSuite( - const char* test_suite_name, const char* type_param, + const std::string& test_suite_name, const char* type_param, internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc) { - // Can we find a TestSuite with the given name? - const auto test_suite = - std::find_if(test_suites_.rbegin(), test_suites_.rend(), - TestSuiteNameIs(test_suite_name)); + // During initialization, all TestInfos for a given suite are added in + // sequence. To optimize this case, see if the most recently added suite is + // the one being requested now. + if (!test_suites_.empty() && + (*test_suites_.rbegin())->name_ == test_suite_name) { + return *test_suites_.rbegin(); + } - if (test_suite != test_suites_.rend()) return *test_suite; + // Fall back to searching the collection. + auto item_it = test_suites_by_name_.find(test_suite_name); + if (item_it != test_suites_by_name_.end()) { + return item_it->second; + } - // No. Let's create one. + // Not found. Create a new instance. auto* const new_test_suite = new TestSuite(test_suite_name, type_param, set_up_tc, tear_down_tc); + test_suites_by_name_.emplace(test_suite_name, new_test_suite); + const UnitTestFilter death_test_suite_filter(kDeathTestSuiteFilter); // Is this a death test suite? - if (internal::UnitTestOptions::MatchesFilter(test_suite_name, - kDeathTestSuiteFilter)) { + if (death_test_suite_filter.MatchesName(test_suite_name)) { // Yes. Inserts the test suite after the last death test suite // defined so far. This only works when the test suites haven't // been shuffled. Otherwise we may end up running a death test @@ -5734,6 +5880,23 @@ TestSuite* UnitTestImpl::GetTestSuite( static void SetUpEnvironment(Environment* env) { env->SetUp(); } static void TearDownEnvironment(Environment* env) { env->TearDown(); } +// If the environment variable TEST_WARNINGS_OUTPUT_FILE was provided, appends +// `str` to the file, creating the file if necessary. +#if GTEST_HAS_FILE_SYSTEM +static void AppendToTestWarningsOutputFile(const std::string& str) { + const char* const filename = posix::GetEnv(kTestWarningsOutputFile); + if (filename == nullptr) { + return; + } + auto* const file = posix::FOpen(filename, "a"); + if (file == nullptr) { + return; + } + GTEST_CHECK_(fwrite(str.data(), 1, str.size(), file) == str.size()); + GTEST_CHECK_(posix::FClose(file) == 0); +} +#endif // GTEST_HAS_FILE_SYSTEM + // Runs all tests in this UnitTest object, prints the result, and // returns true if all tests are successful. If any exception is // thrown during a test, the test is considered to be failed, but the @@ -5749,30 +5912,52 @@ bool UnitTestImpl::RunAllTests() { const bool gtest_is_initialized_before_run_all_tests = GTestIsInitialized(); // Do not run any test if the --help flag was specified. - if (g_help_flag) - return true; + if (g_help_flag) return true; // Repeats the call to the post-flag parsing initialization in case the // user didn't call InitGoogleTest. PostFlagParsingInit(); + // Handle the case where the program has no tests linked. + // Sometimes this is a programmer mistake, but sometimes it is intended. + if (total_test_count() == 0) { + constexpr char kNoTestLinkedMessage[] = + "This test program does NOT link in any test case."; + constexpr char kNoTestLinkedFatal[] = + "This is INVALID. Please make sure to link in at least one test case."; + constexpr char kNoTestLinkedWarning[] = + "Please make sure this is intended."; + const bool fail_if_no_test_linked = GTEST_FLAG_GET(fail_if_no_test_linked); + ColoredPrintf( + GTestColor::kRed, "%s %s\n", kNoTestLinkedMessage, + fail_if_no_test_linked ? kNoTestLinkedFatal : kNoTestLinkedWarning); + if (fail_if_no_test_linked) { + return false; + } +#if GTEST_HAS_FILE_SYSTEM + AppendToTestWarningsOutputFile(std::string(kNoTestLinkedMessage) + ' ' + + kNoTestLinkedWarning + '\n'); +#endif // GTEST_HAS_FILE_SYSTEM + } + +#if GTEST_HAS_FILE_SYSTEM // Even if sharding is not on, test runners may want to use the // GTEST_SHARD_STATUS_FILE to query whether the test supports the sharding // protocol. internal::WriteToShardStatusFileIfNeeded(); +#endif // GTEST_HAS_FILE_SYSTEM // True if and only if we are in a subprocess for running a thread-safe-style // death test. bool in_subprocess_for_death_test = false; -#if GTEST_HAS_DEATH_TEST - in_subprocess_for_death_test = - (internal_run_death_test_flag_.get() != nullptr); -# if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_) +#ifdef GTEST_HAS_DEATH_TEST + in_subprocess_for_death_test = (internal_run_death_test_flag_ != nullptr); +#if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_) if (in_subprocess_for_death_test) { GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_(); } -# endif // defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_) +#endif // defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_) #endif // GTEST_HAS_DEATH_TEST const bool should_shard = ShouldShard(kTestTotalShards, kTestShardIndex, @@ -5780,19 +5965,18 @@ bool UnitTestImpl::RunAllTests() { // Compares the full test names with the filter to decide which // tests to run. - const bool has_tests_to_run = FilterTests(should_shard - ? HONOR_SHARDING_PROTOCOL - : IGNORE_SHARDING_PROTOCOL) > 0; + const bool has_tests_to_run = + FilterTests(should_shard ? HONOR_SHARDING_PROTOCOL + : IGNORE_SHARDING_PROTOCOL) > 0; // Lists the tests and exits if the --gtest_list_tests flag was specified. - if (GTEST_FLAG(list_tests)) { + if (GTEST_FLAG_GET(list_tests)) { // This must be called *after* FilterTests() has been called. ListTestsMatchingFilter(); return true; } - random_seed_ = GTEST_FLAG(shuffle) ? - GetRandomSeedFromFlag(GTEST_FLAG(random_seed)) : 0; + random_seed_ = GetRandomSeedFromFlag(GTEST_FLAG_GET(random_seed)); // True if and only if at least one test has failed. bool failed = false; @@ -5804,9 +5988,21 @@ bool UnitTestImpl::RunAllTests() { // How many times to repeat the tests? We don't want to repeat them // when we are inside the subprocess of a death test. - const int repeat = in_subprocess_for_death_test ? 1 : GTEST_FLAG(repeat); + const int repeat = in_subprocess_for_death_test ? 1 : GTEST_FLAG_GET(repeat); + // Repeats forever if the repeat count is negative. const bool gtest_repeat_forever = repeat < 0; + + // Should test environments be set up and torn down for each repeat, or only + // set up on the first and torn down on the last iteration? If there is no + // "last" iteration because the tests will repeat forever, always recreate the + // environments to avoid leaks in case one of the environments is using + // resources that are external to this process. Without this check there would + // be no way to clean up those external resources automatically. + const bool recreate_environments_when_repeating = + GTEST_FLAG_GET(recreate_environments_when_repeating) || + gtest_repeat_forever; + for (int i = 0; gtest_repeat_forever || i != repeat; i++) { // We want to preserve failures generated by ad-hoc test // assertions executed before RUN_ALL_TESTS(). @@ -5815,7 +6011,7 @@ bool UnitTestImpl::RunAllTests() { Timer timer; // Shuffles test suites and tests if requested. - if (has_tests_to_run && GTEST_FLAG(shuffle)) { + if (has_tests_to_run && GTEST_FLAG_GET(shuffle)) { random()->Reseed(static_cast(random_seed_)); // This should be done before calling OnTestIterationStart(), // such that a test event listener can see the actual test order @@ -5828,10 +6024,13 @@ bool UnitTestImpl::RunAllTests() { // Runs each test suite if there is at least one test to run. if (has_tests_to_run) { - // Sets up all environments beforehand. - repeater->OnEnvironmentsSetUpStart(*parent_); - ForEach(environments_, SetUpEnvironment); - repeater->OnEnvironmentsSetUpEnd(*parent_); + // Sets up all environments beforehand. If test environments aren't + // recreated for each iteration, only do so on the first iteration. + if (i == 0 || recreate_environments_when_repeating) { + repeater->OnEnvironmentsSetUpStart(*parent_); + ForEach(environments_, SetUpEnvironment); + repeater->OnEnvironmentsSetUpEnd(*parent_); + } // Runs the tests only if there was no fatal failure or skip triggered // during global set-up. @@ -5853,7 +6052,7 @@ bool UnitTestImpl::RunAllTests() { for (int test_index = 0; test_index < total_test_suite_count(); test_index++) { GetMutableSuiteCase(test_index)->Run(); - if (GTEST_FLAG(fail_fast) && + if (GTEST_FLAG_GET(fail_fast) && GetMutableSuiteCase(test_index)->Failed()) { for (int j = test_index + 1; j < total_test_suite_count(); j++) { GetMutableSuiteCase(j)->Skip(); @@ -5871,11 +6070,15 @@ bool UnitTestImpl::RunAllTests() { } } - // Tears down all environments in reverse order afterwards. - repeater->OnEnvironmentsTearDownStart(*parent_); - std::for_each(environments_.rbegin(), environments_.rend(), - TearDownEnvironment); - repeater->OnEnvironmentsTearDownEnd(*parent_); + // Tears down all environments in reverse order afterwards. If test + // environments aren't recreated for each iteration, only do so on the + // last iteration. + if (i == repeat - 1 || recreate_environments_when_repeating) { + repeater->OnEnvironmentsTearDownStart(*parent_); + std::for_each(environments_.rbegin(), environments_.rend(), + TearDownEnvironment); + repeater->OnEnvironmentsTearDownEnd(*parent_); + } } elapsed_time_ = timer.Elapsed(); @@ -5896,13 +6099,30 @@ bool UnitTestImpl::RunAllTests() { // (it's always safe to unshuffle the tests). UnshuffleTests(); - if (GTEST_FLAG(shuffle)) { + if (GTEST_FLAG_GET(shuffle)) { // Picks a new random seed for each iteration. random_seed_ = GetNextRandomSeed(random_seed_); } } repeater->OnTestProgramEnd(*parent_); + // Destroy environments in normal code, not in static teardown. + bool delete_environment_on_teardown = true; + if (delete_environment_on_teardown) { + ForEach(environments_, internal::Delete); + environments_.clear(); + } + + // Try to warn the user if no tests matched the test filter. + if (ShouldWarnIfNoTestsMatchFilter()) { + const std::string filter_warning = + std::string("filter \"") + GTEST_FLAG_GET(filter) + + "\" did not match any test; no tests were run\n"; + ColoredPrintf(GTestColor::kRed, "WARNING: %s", filter_warning.c_str()); +#if GTEST_HAS_FILE_SYSTEM + AppendToTestWarningsOutputFile(filter_warning); +#endif // GTEST_HAS_FILE_SYSTEM + } if (!gtest_is_initialized_before_run_all_tests) { ColoredPrintf( @@ -5912,15 +6132,12 @@ bool UnitTestImpl::RunAllTests() { "() before calling RUN_ALL_TESTS(). This is INVALID. Soon " GTEST_NAME_ " will start to enforce the valid usage. " "Please fix it ASAP, or IT WILL START TO FAIL.\n"); // NOLINT -#if GTEST_FOR_GOOGLE_ - ColoredPrintf(GTestColor::kRed, - "For more details, see http://wiki/Main/ValidGUnitMain.\n"); -#endif // GTEST_FOR_GOOGLE_ } return !failed; } +#if GTEST_HAS_FILE_SYSTEM // Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file // if the variable is present. If a file already exists at this location, this // function will write over it. If the variable is present, but the file cannot @@ -5940,6 +6157,7 @@ void WriteToShardStatusFileIfNeeded() { fclose(file); } } +#endif // GTEST_HAS_FILE_SYSTEM // Checks whether sharding is enabled by examining the relevant // environment variable values. If the variables are present, @@ -5947,8 +6165,7 @@ void WriteToShardStatusFileIfNeeded() { // an error and exits. If in_subprocess_for_death_test, sharding is // disabled because it must only be applied to the original test // process. Otherwise, we could filter out death tests we intended to execute. -bool ShouldShard(const char* total_shards_env, - const char* shard_index_env, +bool ShouldShard(const char* total_shards_env, const char* shard_index_env, bool in_subprocess_for_death_test) { if (in_subprocess_for_death_test) { return false; @@ -5960,27 +6177,27 @@ bool ShouldShard(const char* total_shards_env, if (total_shards == -1 && shard_index == -1) { return false; } else if (total_shards == -1 && shard_index != -1) { - const Message msg = Message() - << "Invalid environment variables: you have " - << kTestShardIndex << " = " << shard_index - << ", but have left " << kTestTotalShards << " unset.\n"; + const Message msg = Message() << "Invalid environment variables: you have " + << kTestShardIndex << " = " << shard_index + << ", but have left " << kTestTotalShards + << " unset.\n"; ColoredPrintf(GTestColor::kRed, "%s", msg.GetString().c_str()); fflush(stdout); exit(EXIT_FAILURE); } else if (total_shards != -1 && shard_index == -1) { const Message msg = Message() - << "Invalid environment variables: you have " - << kTestTotalShards << " = " << total_shards - << ", but have left " << kTestShardIndex << " unset.\n"; + << "Invalid environment variables: you have " + << kTestTotalShards << " = " << total_shards + << ", but have left " << kTestShardIndex << " unset.\n"; ColoredPrintf(GTestColor::kRed, "%s", msg.GetString().c_str()); fflush(stdout); exit(EXIT_FAILURE); } else if (shard_index < 0 || shard_index >= total_shards) { - const Message msg = Message() - << "Invalid environment variables: we require 0 <= " - << kTestShardIndex << " < " << kTestTotalShards - << ", but you have " << kTestShardIndex << "=" << shard_index - << ", " << kTestTotalShards << "=" << total_shards << ".\n"; + const Message msg = + Message() << "Invalid environment variables: we require 0 <= " + << kTestShardIndex << " < " << kTestTotalShards + << ", but you have " << kTestShardIndex << "=" << shard_index + << ", " << kTestTotalShards << "=" << total_shards << ".\n"; ColoredPrintf(GTestColor::kRed, "%s", msg.GetString().c_str()); fflush(stdout); exit(EXIT_FAILURE); @@ -6019,14 +6236,19 @@ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) { // each TestSuite and TestInfo object. // If shard_tests == true, further filters tests based on sharding // variables in the environment - see -// https://github.com/google/googletest/blob/master/googletest/docs/advanced.md +// https://github.com/google/googletest/blob/main/docs/advanced.md // . Returns the number of tests that should run. int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { - const int32_t total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ? - Int32FromEnvOrDie(kTestTotalShards, -1) : -1; - const int32_t shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ? - Int32FromEnvOrDie(kTestShardIndex, -1) : -1; + const int32_t total_shards = shard_tests == HONOR_SHARDING_PROTOCOL + ? Int32FromEnvOrDie(kTestTotalShards, -1) + : -1; + const int32_t shard_index = shard_tests == HONOR_SHARDING_PROTOCOL + ? Int32FromEnvOrDie(kTestShardIndex, -1) + : -1; + const PositiveAndNegativeUnitTestFilter gtest_flag_filter( + GTEST_FLAG_GET(filter)); + const UnitTestFilter disable_test_filter(kDisableTestFilter); // num_runnable_tests are the number of tests that will // run across all shards (i.e., match filter and are not disabled). // num_selected_tests are the number of tests to be run on @@ -6034,26 +6256,24 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { int num_runnable_tests = 0; int num_selected_tests = 0; for (auto* test_suite : test_suites_) { - const std::string& test_suite_name = test_suite->name(); + const std::string& test_suite_name = test_suite->name_; test_suite->set_should_run(false); - for (size_t j = 0; j < test_suite->test_info_list().size(); j++) { - TestInfo* const test_info = test_suite->test_info_list()[j]; - const std::string test_name(test_info->name()); + for (TestInfo* test_info : test_suite->test_info_list()) { + const std::string& test_name = test_info->name_; // A test is disabled if test suite name or test name matches // kDisableTestFilter. - const bool is_disabled = internal::UnitTestOptions::MatchesFilter( - test_suite_name, kDisableTestFilter) || - internal::UnitTestOptions::MatchesFilter( - test_name, kDisableTestFilter); + const bool is_disabled = + disable_test_filter.MatchesName(test_suite_name) || + disable_test_filter.MatchesName(test_name); test_info->is_disabled_ = is_disabled; - const bool matches_filter = internal::UnitTestOptions::FilterMatchesTest( - test_suite_name, test_name); + const bool matches_filter = + gtest_flag_filter.MatchesTest(test_suite_name, test_name); test_info->matches_filter_ = matches_filter; const bool is_runnable = - (GTEST_FLAG(also_run_disabled_tests) || !is_disabled) && + (GTEST_FLAG_GET(also_run_disabled_tests) || !is_disabled) && matches_filter; const bool is_in_another_shard = @@ -6072,6 +6292,30 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { return num_selected_tests; } +// Returns true if a warning should be issued if no tests match the test filter +// flag. We can't simply count the number of tests that ran because, for +// instance, test sharding and death tests might mean no tests are expected to +// run in this process, but will run in another process. +bool UnitTestImpl::ShouldWarnIfNoTestsMatchFilter() const { + if (total_test_count() == 0) { + // No tests were linked in to program. + // This case is handled by a different warning. + return false; + } + const PositiveAndNegativeUnitTestFilter gtest_flag_filter( + GTEST_FLAG_GET(filter)); + for (auto* test_suite : test_suites_) { + const std::string& test_suite_name = test_suite->name_; + for (TestInfo* test_info : test_suite->test_info_list()) { + const std::string& test_name = test_info->name_; + if (gtest_flag_filter.MatchesTest(test_suite_name, test_name)) { + return false; + } + } + } + return true; +} + // Prints the given C-string on a single line by replacing all '\n' // characters with string "\\n". If the output takes more than // max_length characters, only prints the first max_length characters @@ -6128,10 +6372,11 @@ void UnitTestImpl::ListTestsMatchingFilter() { } } fflush(stdout); +#if GTEST_HAS_FILE_SYSTEM const std::string& output_format = UnitTestOptions::GetOutputFormat(); if (output_format == "xml" || output_format == "json") { - FILE* fileout = OpenFileForWriting( - UnitTestOptions::GetAbsolutePathToOutputFile().c_str()); + FILE* fileout = + OpenFileForWriting(UnitTestOptions::GetAbsolutePathToOutputFile()); std::stringstream stream; if (output_format == "xml") { XmlUnitTestResultPrinter( @@ -6145,6 +6390,7 @@ void UnitTestImpl::ListTestsMatchingFilter() { fprintf(fileout, "%s", StringStreamToString(&stream).c_str()); fclose(fileout); } +#endif // GTEST_HAS_FILE_SYSTEM } // Sets the OS stack trace getter. @@ -6222,8 +6468,8 @@ void UnitTestImpl::UnshuffleTests() { // For example, if Foo() calls Bar(), which in turn calls // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. -std::string GetCurrentOsStackTraceExceptTop(UnitTest* /*unit_test*/, - int skip_count) { +GTEST_NO_INLINE_ GTEST_NO_TAIL_CALL_ std::string +GetCurrentOsStackTraceExceptTop(int skip_count) { // We pass skip_count + 1 to skip this wrapper function in addition // to what the user really wants to skip. return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1); @@ -6233,7 +6479,7 @@ std::string GetCurrentOsStackTraceExceptTop(UnitTest* /*unit_test*/, // suppress unreachable code warnings. namespace { class ClassUniqueToAlwaysTrue {}; -} +} // namespace bool IsTrue(bool condition) { return condition; } @@ -6241,8 +6487,7 @@ bool AlwaysTrue() { #if GTEST_HAS_EXCEPTIONS // This condition is always false so AlwaysTrue() never actually throws, // but it makes the compiler think that it may throw. - if (IsTrue(false)) - throw ClassUniqueToAlwaysTrue(); + if (IsTrue(false)) throw ClassUniqueToAlwaysTrue(); #endif // GTEST_HAS_EXCEPTIONS return true; } @@ -6264,13 +6509,14 @@ bool SkipPrefix(const char* prefix, const char** pstr) { // part can be omitted. // // Returns the value of the flag, or NULL if the parsing failed. -static const char* ParseFlagValue(const char* str, const char* flag, +static const char* ParseFlagValue(const char* str, const char* flag_name, bool def_optional) { // str and flag must not be NULL. - if (str == nullptr || flag == nullptr) return nullptr; + if (str == nullptr || flag_name == nullptr) return nullptr; // The flag must start with "--" followed by GTEST_FLAG_PREFIX_. - const std::string flag_str = std::string("--") + GTEST_FLAG_PREFIX_ + flag; + const std::string flag_str = + std::string("--") + GTEST_FLAG_PREFIX_ + flag_name; const size_t flag_len = flag_str.length(); if (strncmp(str, flag_str.c_str(), flag_len) != 0) return nullptr; @@ -6301,9 +6547,9 @@ static const char* ParseFlagValue(const char* str, const char* flag, // // On success, stores the value of the flag in *value, and returns // true. On failure, returns false without changing *value. -static bool ParseBoolFlag(const char* str, const char* flag, bool* value) { +static bool ParseFlag(const char* str, const char* flag_name, bool* value) { // Gets the value of the flag as a string. - const char* const value_str = ParseFlagValue(str, flag, true); + const char* const value_str = ParseFlagValue(str, flag_name, true); // Aborts if the parsing failed. if (value_str == nullptr) return false; @@ -6317,16 +6563,16 @@ static bool ParseBoolFlag(const char* str, const char* flag, bool* value) { // // On success, stores the value of the flag in *value, and returns // true. On failure, returns false without changing *value. -bool ParseInt32Flag(const char* str, const char* flag, int32_t* value) { +bool ParseFlag(const char* str, const char* flag_name, int32_t* value) { // Gets the value of the flag as a string. - const char* const value_str = ParseFlagValue(str, flag, false); + const char* const value_str = ParseFlagValue(str, flag_name, false); // Aborts if the parsing failed. if (value_str == nullptr) return false; // Sets *value to the value of the flag. - return ParseInt32(Message() << "The value of flag --" << flag, - value_str, value); + return ParseInt32(Message() << "The value of flag --" << flag_name, value_str, + value); } // Parses a string for a string flag, in the form of "--flag=value". @@ -6334,9 +6580,9 @@ bool ParseInt32Flag(const char* str, const char* flag, int32_t* value) { // On success, stores the value of the flag in *value, and returns // true. On failure, returns false without changing *value. template -static bool ParseStringFlag(const char* str, const char* flag, String* value) { +static bool ParseFlag(const char* str, const char* flag_name, String* value) { // Gets the value of the flag as a string. - const char* const value_str = ParseFlagValue(str, flag, false); + const char* const value_str = ParseFlagValue(str, flag_name, false); // Aborts if the parsing failed. if (value_str == nullptr) return false; @@ -6353,8 +6599,7 @@ static bool ParseStringFlag(const char* str, const char* flag, String* value) { // GTEST_INTERNAL_PREFIX_ followed by "internal_" are considered Google Test // internal flags and do not trigger the help message. static bool HasGoogleTestFlagPrefix(const char* str) { - return (SkipPrefix("--", &str) || - SkipPrefix("-", &str) || + return (SkipPrefix("--", &str) || SkipPrefix("-", &str) || SkipPrefix("/", &str)) && !SkipPrefix(GTEST_FLAG_PREFIX_ "internal_", &str) && (SkipPrefix(GTEST_FLAG_PREFIX_, &str) || @@ -6437,6 +6682,10 @@ static const char kColorEncodedHelpMessage[] = "random_seed=@Y[NUMBER]@D\n" " Random number seed to use for shuffling test orders (between 1 and\n" " 99999, or 0 to use a seed based on the current time).\n" + " @G--" GTEST_FLAG_PREFIX_ + "recreate_environments_when_repeating@D\n" + " Sets up and tears down the global test environment on each repeat\n" + " of the test.\n" "\n" "Test Output:\n" " @G--" GTEST_FLAG_PREFIX_ @@ -6454,18 +6703,18 @@ static const char kColorEncodedHelpMessage[] = " Generate a JSON or XML report in the given directory or with the " "given\n" " file name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.\n" -# if GTEST_CAN_STREAM_RESULTS_ +#if GTEST_CAN_STREAM_RESULTS_ " @G--" GTEST_FLAG_PREFIX_ "stream_result_to=@YHOST@G:@YPORT@D\n" " Stream test results to the given server.\n" -# endif // GTEST_CAN_STREAM_RESULTS_ +#endif // GTEST_CAN_STREAM_RESULTS_ "\n" "Assertion Behavior:\n" -# if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS +#if defined(GTEST_HAS_DEATH_TEST) && !defined(GTEST_OS_WINDOWS) " @G--" GTEST_FLAG_PREFIX_ "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n" " Set the default death test style.\n" -# endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS +#endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS " @G--" GTEST_FLAG_PREFIX_ "break_on_failure@D\n" " Turn assertion failures into debugger break-points.\n" @@ -6497,41 +6746,45 @@ static const char kColorEncodedHelpMessage[] = "@G<" GTEST_DEV_EMAIL_ ">@D.\n"; static bool ParseGoogleTestFlag(const char* const arg) { - return ParseBoolFlag(arg, kAlsoRunDisabledTestsFlag, - >EST_FLAG(also_run_disabled_tests)) || - ParseBoolFlag(arg, kBreakOnFailureFlag, - >EST_FLAG(break_on_failure)) || - ParseBoolFlag(arg, kCatchExceptionsFlag, - >EST_FLAG(catch_exceptions)) || - ParseStringFlag(arg, kColorFlag, >EST_FLAG(color)) || - ParseStringFlag(arg, kDeathTestStyleFlag, - >EST_FLAG(death_test_style)) || - ParseBoolFlag(arg, kDeathTestUseFork, - >EST_FLAG(death_test_use_fork)) || - ParseBoolFlag(arg, kFailFast, >EST_FLAG(fail_fast)) || - ParseStringFlag(arg, kFilterFlag, >EST_FLAG(filter)) || - ParseStringFlag(arg, kInternalRunDeathTestFlag, - >EST_FLAG(internal_run_death_test)) || - ParseBoolFlag(arg, kListTestsFlag, >EST_FLAG(list_tests)) || - ParseStringFlag(arg, kOutputFlag, >EST_FLAG(output)) || - ParseBoolFlag(arg, kBriefFlag, >EST_FLAG(brief)) || - ParseBoolFlag(arg, kPrintTimeFlag, >EST_FLAG(print_time)) || - ParseBoolFlag(arg, kPrintUTF8Flag, >EST_FLAG(print_utf8)) || - ParseInt32Flag(arg, kRandomSeedFlag, >EST_FLAG(random_seed)) || - ParseInt32Flag(arg, kRepeatFlag, >EST_FLAG(repeat)) || - ParseBoolFlag(arg, kShuffleFlag, >EST_FLAG(shuffle)) || - ParseInt32Flag(arg, kStackTraceDepthFlag, - >EST_FLAG(stack_trace_depth)) || - ParseStringFlag(arg, kStreamResultToFlag, - >EST_FLAG(stream_result_to)) || - ParseBoolFlag(arg, kThrowOnFailureFlag, >EST_FLAG(throw_on_failure)); +#define GTEST_INTERNAL_PARSE_FLAG(flag_name) \ + do { \ + auto value = GTEST_FLAG_GET(flag_name); \ + if (ParseFlag(arg, #flag_name, &value)) { \ + GTEST_FLAG_SET(flag_name, value); \ + return true; \ + } \ + } while (false) + + GTEST_INTERNAL_PARSE_FLAG(also_run_disabled_tests); + GTEST_INTERNAL_PARSE_FLAG(break_on_failure); + GTEST_INTERNAL_PARSE_FLAG(catch_exceptions); + GTEST_INTERNAL_PARSE_FLAG(color); + GTEST_INTERNAL_PARSE_FLAG(death_test_style); + GTEST_INTERNAL_PARSE_FLAG(death_test_use_fork); + GTEST_INTERNAL_PARSE_FLAG(fail_fast); + GTEST_INTERNAL_PARSE_FLAG(fail_if_no_test_linked); + GTEST_INTERNAL_PARSE_FLAG(filter); + GTEST_INTERNAL_PARSE_FLAG(internal_run_death_test); + GTEST_INTERNAL_PARSE_FLAG(list_tests); + GTEST_INTERNAL_PARSE_FLAG(output); + GTEST_INTERNAL_PARSE_FLAG(brief); + GTEST_INTERNAL_PARSE_FLAG(print_time); + GTEST_INTERNAL_PARSE_FLAG(print_utf8); + GTEST_INTERNAL_PARSE_FLAG(random_seed); + GTEST_INTERNAL_PARSE_FLAG(repeat); + GTEST_INTERNAL_PARSE_FLAG(recreate_environments_when_repeating); + GTEST_INTERNAL_PARSE_FLAG(shuffle); + GTEST_INTERNAL_PARSE_FLAG(stack_trace_depth); + GTEST_INTERNAL_PARSE_FLAG(stream_result_to); + GTEST_INTERNAL_PARSE_FLAG(throw_on_failure); + return false; } -#if GTEST_USE_OWN_FLAGFILE_FLAG_ +#if GTEST_USE_OWN_FLAGFILE_FLAG_ && GTEST_HAS_FILE_SYSTEM static void LoadFlagsFromFile(const std::string& path) { FILE* flagfile = posix::FOpen(path.c_str(), "r"); if (!flagfile) { - GTEST_LOG_(FATAL) << "Unable to open file \"" << GTEST_FLAG(flagfile) + GTEST_LOG_(FATAL) << "Unable to open file \"" << GTEST_FLAG_GET(flagfile) << "\""; } std::string contents(ReadEntireFile(flagfile)); @@ -6539,55 +6792,51 @@ static void LoadFlagsFromFile(const std::string& path) { std::vector lines; SplitString(contents, '\n', &lines); for (size_t i = 0; i < lines.size(); ++i) { - if (lines[i].empty()) - continue; - if (!ParseGoogleTestFlag(lines[i].c_str())) - g_help_flag = true; + if (lines[i].empty()) continue; + if (!ParseGoogleTestFlag(lines[i].c_str())) g_help_flag = true; } } -#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ +#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ && GTEST_HAS_FILE_SYSTEM // Parses the command line for Google Test flags, without initializing // other parts of Google Test. The type parameter CharType can be // instantiated to either char or wchar_t. template void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { + std::string flagfile_value; for (int i = 1; i < *argc; i++) { const std::string arg_string = StreamableToString(argv[i]); const char* const arg = arg_string.c_str(); - using internal::ParseBoolFlag; - using internal::ParseInt32Flag; - using internal::ParseStringFlag; + using internal::ParseFlag; bool remove_flag = false; if (ParseGoogleTestFlag(arg)) { remove_flag = true; -#if GTEST_USE_OWN_FLAGFILE_FLAG_ - } else if (ParseStringFlag(arg, kFlagfileFlag, >EST_FLAG(flagfile))) { - LoadFlagsFromFile(GTEST_FLAG(flagfile)); +#if GTEST_USE_OWN_FLAGFILE_FLAG_ && GTEST_HAS_FILE_SYSTEM + } else if (ParseFlag(arg, "flagfile", &flagfile_value)) { + GTEST_FLAG_SET(flagfile, flagfile_value); + LoadFlagsFromFile(flagfile_value); remove_flag = true; -#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ - } else if (arg_string == "--help" || arg_string == "-h" || - arg_string == "-?" || arg_string == "/?" || - HasGoogleTestFlagPrefix(arg)) { +#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ && GTEST_HAS_FILE_SYSTEM + } else if (arg_string == "--help" || HasGoogleTestFlagPrefix(arg)) { // Both help flag and unrecognized Google Test flags (excluding // internal ones) trigger help display. g_help_flag = true; } if (remove_flag) { - // Shift the remainder of the argv list left by one. Note - // that argv has (*argc + 1) elements, the last one always being - // NULL. The following loop moves the trailing NULL element as - // well. - for (int j = i; j != *argc; j++) { - argv[j] = argv[j + 1]; + // Shift the remainder of the argv list left by one. + for (int j = i + 1; j < *argc; ++j) { + argv[j - 1] = argv[j]; } // Decrements the argument count. (*argc)--; + // Terminate the array with nullptr. + argv[*argc] = nullptr; + // We also need to decrement the iterator as we just removed // an element. i--; @@ -6603,14 +6852,68 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { } // Parses the command line for Google Test flags, without initializing -// other parts of Google Test. +// other parts of Google Test. This function updates argc and argv by removing +// flags that are known to GoogleTest (including other user flags defined using +// ABSL_FLAG if GoogleTest is built with GTEST_USE_ABSL). Other arguments +// remain in place. Unrecognized flags are not reported and do not cause the +// program to exit. void ParseGoogleTestFlagsOnly(int* argc, char** argv) { +#ifdef GTEST_HAS_ABSL_FLAGS + if (*argc <= 0) return; + + std::vector positional_args; + std::vector unrecognized_flags; + absl::ParseAbseilFlagsOnly(*argc, argv, positional_args, unrecognized_flags); + absl::flat_hash_set unrecognized; + for (const auto& flag : unrecognized_flags) { + unrecognized.insert(flag.flag_name); + } + absl::flat_hash_set positional; + for (const auto& arg : positional_args) { + positional.insert(arg); + } + + int out_pos = 1; + int in_pos = 1; + for (; in_pos < *argc; ++in_pos) { + char* arg = argv[in_pos]; + absl::string_view arg_str(arg); + if (absl::ConsumePrefix(&arg_str, "--")) { + // Flag-like argument. If the flag was unrecognized, keep it. + // If it was a GoogleTest flag, remove it. + if (unrecognized.contains(arg_str)) { + argv[out_pos++] = argv[in_pos]; + continue; + } + } + + if (arg_str.empty()) { + ++in_pos; + break; // '--' indicates that the rest of the arguments are positional + } + + // Probably a positional argument. If it is in fact positional, keep it. + // If it was a value for the flag argument, remove it. + if (positional.contains(arg)) { + argv[out_pos++] = arg; + } + } + + // The rest are positional args for sure. + while (in_pos < *argc) { + argv[out_pos++] = argv[in_pos++]; + } + + *argc = out_pos; + argv[out_pos] = nullptr; +#else ParseGoogleTestFlagsOnlyImpl(argc, argv); +#endif // Fix the value of *_NSGetArgc() on macOS, but if and only if // *_NSGetArgv() == argv // Only applicable to char** version of argv -#if GTEST_OS_MAC +#ifdef GTEST_OS_MAC #ifndef GTEST_OS_IOS if (*_NSGetArgv() == argv) { *_NSGetArgc() = *argc; @@ -6638,8 +6941,16 @@ void InitGoogleTestImpl(int* argc, CharType** argv) { g_argvs.push_back(StreamableToString(argv[i])); } -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL absl::InitializeSymbolizer(g_argvs[0].c_str()); + +#ifdef GTEST_HAS_ABSL_FLAGS + // When using the Abseil Flags library, set the program usage message to the + // help message, but remove the color-encoding from the message first. + absl::SetProgramUsageMessage(absl::StrReplaceAll( + kColorEncodedHelpMessage, + {{"@D", ""}, {"@R", ""}, {"@G", ""}, {"@Y", ""}, {"@@", "@"}})); +#endif // GTEST_HAS_ABSL_FLAGS #endif // GTEST_HAS_ABSL ParseGoogleTestFlagsOnly(argc, argv); @@ -6660,7 +6971,7 @@ void InitGoogleTestImpl(int* argc, CharType** argv) { void InitGoogleTest(int* argc, char** argv) { #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv); -#else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) +#else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) internal::InitGoogleTestImpl(argc, argv); #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) } @@ -6670,7 +6981,7 @@ void InitGoogleTest(int* argc, char** argv) { void InitGoogleTest(int* argc, wchar_t** argv) { #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv); -#else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) +#else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) internal::InitGoogleTestImpl(argc, argv); #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) } @@ -6686,44 +6997,71 @@ void InitGoogleTest() { #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(&argc, argv); -#else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) +#else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) internal::InitGoogleTestImpl(&argc, argv); #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) } +#if !defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_) || \ + !defined(GTEST_CUSTOM_SRCDIR_FUNCTION_) +// Returns the value of the first environment variable that is set and contains +// a non-empty string. If there are none, returns the "fallback" string. Adds +// the director-separator character as a suffix if not provided in the +// environment variable value. +static std::string GetDirFromEnv( + std::initializer_list environment_variables, + const char* fallback, char separator) { + for (const char* variable_name : environment_variables) { + const char* value = internal::posix::GetEnv(variable_name); + if (value != nullptr && value[0] != '\0') { + if (value[strlen(value) - 1] != separator) { + return std::string(value).append(1, separator); + } + return value; + } + } + return fallback; +} +#endif + std::string TempDir() { #if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_) return GTEST_CUSTOM_TEMPDIR_FUNCTION_(); -#elif GTEST_OS_WINDOWS_MOBILE - return "\\temp\\"; -#elif GTEST_OS_WINDOWS - const char* temp_dir = internal::posix::GetEnv("TEMP"); - if (temp_dir == nullptr || temp_dir[0] == '\0') { - return "\\temp\\"; - } else if (temp_dir[strlen(temp_dir) - 1] == '\\') { - return temp_dir; - } else { - return std::string(temp_dir) + "\\"; - } -#elif GTEST_OS_LINUX_ANDROID - const char* temp_dir = internal::posix::GetEnv("TEST_TMPDIR"); - if (temp_dir == nullptr || temp_dir[0] == '\0') { - return "/data/local/tmp/"; - } else { - return temp_dir; - } -#elif GTEST_OS_LINUX - const char* temp_dir = internal::posix::GetEnv("TEST_TMPDIR"); - if (temp_dir == nullptr || temp_dir[0] == '\0') { - return "/tmp/"; - } else { - return temp_dir; - } +#elif defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_WINDOWS_MOBILE) + return GetDirFromEnv({"TEST_TMPDIR", "TEMP"}, "\\temp\\", '\\'); +#elif defined(GTEST_OS_LINUX_ANDROID) + return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/data/local/tmp/", '/'); #else - return "/tmp/"; -#endif // GTEST_OS_WINDOWS_MOBILE + return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/tmp/", '/'); +#endif } +#if GTEST_HAS_FILE_SYSTEM && !defined(GTEST_CUSTOM_SRCDIR_FUNCTION_) +// Returns the directory path (including terminating separator) of the current +// executable as derived from argv[0]. +static std::string GetCurrentExecutableDirectory() { + internal::FilePath argv_0(internal::GetArgvs()[0]); + return argv_0.RemoveFileName().string(); +} +#endif + +#if GTEST_HAS_FILE_SYSTEM +std::string SrcDir() { +#if defined(GTEST_CUSTOM_SRCDIR_FUNCTION_) + return GTEST_CUSTOM_SRCDIR_FUNCTION_(); +#elif defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_WINDOWS_MOBILE) + return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(), + '\\'); +#elif defined(GTEST_OS_LINUX_ANDROID) + return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(), + '/'); +#else + return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(), + '/'); +#endif +} +#endif + // Class ScopedTrace // Pushes the given source file location and message onto a per-thread @@ -6738,8 +7076,7 @@ void ScopedTrace::PushTrace(const char* file, int line, std::string message) { } // Pops the info pushed by the c'tor. -ScopedTrace::~ScopedTrace() - GTEST_LOCK_EXCLUDED_(&UnitTest::mutex_) { +ScopedTrace::~ScopedTrace() GTEST_LOCK_EXCLUDED_(&UnitTest::mutex_) { UnitTest::GetInstance()->PopGTestTrace(); } diff --git a/libs/libvpx/third_party/googletest/src/src/gtest_main.cc b/libs/libvpx/third_party/googletest/src/src/gtest_main.cc index 46b27c3d7d..8141caf4ca 100644 --- a/libs/libvpx/third_party/googletest/src/src/gtest_main.cc +++ b/libs/libvpx/third_party/googletest/src/src/gtest_main.cc @@ -28,23 +28,35 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include + #include "gtest/gtest.h" -#if GTEST_OS_ESP8266 || GTEST_OS_ESP32 -#if GTEST_OS_ESP8266 +#if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32) || \ + (defined(GTEST_OS_NRF52) && defined(ARDUINO)) +// Arduino-like platforms: program entry points are setup/loop instead of main. + +#ifdef GTEST_OS_ESP8266 extern "C" { #endif -void setup() { - testing::InitGoogleTest(); -} + +void setup() { testing::InitGoogleTest(); } void loop() { RUN_ALL_TESTS(); } -#if GTEST_OS_ESP8266 +#ifdef GTEST_OS_ESP8266 } #endif +#elif defined(GTEST_OS_QURT) +// QuRT: program entry point is main, but argc/argv are unusable. + +GTEST_API_ int main() { + printf("Running main() from %s\n", __FILE__); + testing::InitGoogleTest(); + return RUN_ALL_TESTS(); +} #else +// Normal platforms: program entry point is main, argc/argv are initialized. GTEST_API_ int main(int argc, char **argv) { printf("Running main() from %s\n", __FILE__); diff --git a/libs/libvpx/third_party/libwebm/AUTHORS.TXT b/libs/libvpx/third_party/libwebm/AUTHORS.TXT index 9686ac13eb..59b648ca68 100644 --- a/libs/libvpx/third_party/libwebm/AUTHORS.TXT +++ b/libs/libvpx/third_party/libwebm/AUTHORS.TXT @@ -2,3 +2,4 @@ # Name or Organization Google Inc. +Elijah Cirioli diff --git a/libs/libvpx/third_party/libwebm/Android.mk b/libs/libvpx/third_party/libwebm/Android.mk index 23f935f2db..e6c17df021 100644 --- a/libs/libvpx/third_party/libwebm/Android.mk +++ b/libs/libvpx/third_party/libwebm/Android.mk @@ -1,9 +1,11 @@ +# Ignore this file during non-NDK builds. +ifdef NDK_ROOT LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE:= libwebm LOCAL_CPPFLAGS:=-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -LOCAL_CPPFLAGS+=-D__STDC_LIMIT_MACROS -std=gnu++11 +LOCAL_CPPFLAGS+=-D__STDC_LIMIT_MACROS -std=c++11 LOCAL_C_INCLUDES:= $(LOCAL_PATH) LOCAL_EXPORT_C_INCLUDES:= $(LOCAL_PATH) @@ -18,3 +20,4 @@ LOCAL_LICENSE_KINDS := SPDX-license-identifier-BSD LOCAL_LICENSE_CONDITIONS := notice LOCAL_NOTICE_FILE := $(LOCAL_PATH)/LICENSE.TXT $(LOCAL_PATH)/PATENTS.TXT include $(BUILD_STATIC_LIBRARY) +endif # NDK_ROOT diff --git a/libs/libvpx/third_party/libwebm/README.libvpx b/libs/libvpx/third_party/libwebm/README.libvpx index 325604cc66..850b9ce360 100644 --- a/libs/libvpx/third_party/libwebm/README.libvpx +++ b/libs/libvpx/third_party/libwebm/README.libvpx @@ -1,7 +1,12 @@ +Name: libwebm URL: https://chromium.googlesource.com/webm/libwebm -Version: ee0bab576c338c9807249b99588e352b7268cb62 -License: BSD -License File: LICENSE.txt +Version: N/A +Update Mechanism: Manual +Revision: 3b630045052e1e4d563207ab9e3be8d137c26067 +License: BSD-3-Clause +License File: LICENSE.TXT +Shipped in Chromium: no +Security Critical: yes Description: libwebm is used to handle WebM container I/O. diff --git a/libs/libvpx/third_party/libwebm/common/hdr_util.cc b/libs/libvpx/third_party/libwebm/common/hdr_util.cc index 916f7170b6..f1320a5361 100644 --- a/libs/libvpx/third_party/libwebm/common/hdr_util.cc +++ b/libs/libvpx/third_party/libwebm/common/hdr_util.cc @@ -202,7 +202,8 @@ bool ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length, features->bit_depth = priv_profile; } else if (id_byte == kVp9ChromaSubsamplingId) { const int priv_profile = static_cast(private_data[offset++]); - if (priv_profile != 0 && priv_profile != 2 && priv_profile != 3) + if (priv_profile != 0 && priv_profile != 1 && priv_profile != 2 && + priv_profile != 3) return false; if (features->chroma_subsampling != Vp9CodecFeatures::kValueNotPresent && features->chroma_subsampling != priv_profile) { diff --git a/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxer.cc b/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxer.cc index ae36531439..21e51be474 100644 --- a/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxer.cc +++ b/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxer.cc @@ -65,7 +65,8 @@ bool StrCpy(const char* src, char** dst_ptr) { if (dst == NULL) return false; - strcpy(dst, src); // NOLINT + memcpy(dst, src, size - 1); + dst[size - 1] = '\0'; return true; } @@ -607,10 +608,10 @@ bool ContentEncoding::Write(IMkvWriter* writer) const { return true; } -uint64_t ContentEncoding::EncodingSize(uint64_t compresion_size, +uint64_t ContentEncoding::EncodingSize(uint64_t compression_size, uint64_t encryption_size) const { // TODO(fgalligan): Add support for compression settings. - if (compresion_size != 0) + if (compression_size != 0) return 0; uint64_t encoding_size = 0; @@ -919,11 +920,8 @@ void Track::set_codec_id(const char* codec_id) { const size_t length = strlen(codec_id) + 1; codec_id_ = new (std::nothrow) char[length]; // NOLINT if (codec_id_) { -#ifdef _MSC_VER - strcpy_s(codec_id_, length, codec_id); -#else - strcpy(codec_id_, codec_id); -#endif + memcpy(codec_id_, codec_id, length - 1); + codec_id_[length - 1] = '\0'; } } } @@ -936,11 +934,8 @@ void Track::set_language(const char* language) { const size_t length = strlen(language) + 1; language_ = new (std::nothrow) char[length]; // NOLINT if (language_) { -#ifdef _MSC_VER - strcpy_s(language_, length, language); -#else - strcpy(language_, language); -#endif + memcpy(language_, language, length - 1); + language_[length - 1] = '\0'; } } } @@ -952,11 +947,8 @@ void Track::set_name(const char* name) { const size_t length = strlen(name) + 1; name_ = new (std::nothrow) char[length]; // NOLINT if (name_) { -#ifdef _MSC_VER - strcpy_s(name_, length, name); -#else - strcpy(name_, name); -#endif + memcpy(name_, name, length - 1); + name_[length - 1] = '\0'; } } } @@ -1559,11 +1551,8 @@ void VideoTrack::set_colour_space(const char* colour_space) { const size_t length = strlen(colour_space) + 1; colour_space_ = new (std::nothrow) char[length]; // NOLINT if (colour_space_) { -#ifdef _MSC_VER - strcpy_s(colour_space_, length, colour_space); -#else - strcpy(colour_space_, colour_space); -#endif + memcpy(colour_space_, colour_space, length - 1); + colour_space_[length - 1] = '\0'; } } } @@ -2856,13 +2845,13 @@ bool SeekHead::AddSeekEntry(uint32_t id, uint64_t pos) { uint32_t SeekHead::GetId(int index) const { if (index < 0 || index >= kSeekEntryCount) - return UINT_MAX; + return UINT32_MAX; return seek_entry_id_[index]; } uint64_t SeekHead::GetPosition(int index) const { if (index < 0 || index >= kSeekEntryCount) - return ULLONG_MAX; + return UINT64_MAX; return seek_entry_pos_[index]; } @@ -2896,7 +2885,7 @@ SegmentInfo::SegmentInfo() muxing_app_(NULL), timecode_scale_(1000000ULL), writing_app_(NULL), - date_utc_(LLONG_MIN), + date_utc_(INT64_MIN), duration_pos_(-1) {} SegmentInfo::~SegmentInfo() { @@ -2927,11 +2916,8 @@ bool SegmentInfo::Init() { if (!muxing_app_) return false; -#ifdef _MSC_VER - strcpy_s(muxing_app_, app_len, temp); -#else - strcpy(muxing_app_, temp); -#endif + memcpy(muxing_app_, temp, app_len - 1); + muxing_app_[app_len - 1] = '\0'; set_writing_app(temp); if (!writing_app_) @@ -2974,7 +2960,7 @@ bool SegmentInfo::Write(IMkvWriter* writer) { if (duration_ > 0.0) size += EbmlElementSize(libwebm::kMkvDuration, static_cast(duration_)); - if (date_utc_ != LLONG_MIN) + if (date_utc_ != INT64_MIN) size += EbmlDateElementSize(libwebm::kMkvDateUTC); size += EbmlElementSize(libwebm::kMkvMuxingApp, muxing_app_); size += EbmlElementSize(libwebm::kMkvWritingApp, writing_app_); @@ -2999,7 +2985,7 @@ bool SegmentInfo::Write(IMkvWriter* writer) { return false; } - if (date_utc_ != LLONG_MIN) + if (date_utc_ != INT64_MIN) WriteEbmlDateElement(writer, libwebm::kMkvDateUTC, date_utc_); if (!WriteEbmlElement(writer, libwebm::kMkvMuxingApp, muxing_app_)) @@ -3022,11 +3008,8 @@ void SegmentInfo::set_muxing_app(const char* app) { if (!temp_str) return; -#ifdef _MSC_VER - strcpy_s(temp_str, length, app); -#else - strcpy(temp_str, app); -#endif + memcpy(temp_str, app, length - 1); + temp_str[length - 1] = '\0'; delete[] muxing_app_; muxing_app_ = temp_str; @@ -3040,11 +3023,8 @@ void SegmentInfo::set_writing_app(const char* app) { if (!temp_str) return; -#ifdef _MSC_VER - strcpy_s(temp_str, length, app); -#else - strcpy(temp_str, app); -#endif + memcpy(temp_str, app, length - 1); + temp_str[length - 1] = '\0'; delete[] writing_app_; writing_app_ = temp_str; @@ -3628,19 +3608,17 @@ bool Segment::SetChunking(bool chunking, const char* filename) { if (chunking_ && !strcmp(filename, chunking_base_name_)) return true; - const size_t name_length = strlen(filename) + 1; - char* const temp = new (std::nothrow) char[name_length]; // NOLINT + const size_t filename_length = strlen(filename); + char* const temp = new (std::nothrow) char[filename_length + 1]; // NOLINT if (!temp) return false; -#ifdef _MSC_VER - strcpy_s(temp, name_length, filename); -#else - strcpy(temp, filename); -#endif + memcpy(temp, filename, filename_length); + temp[filename_length] = '\0'; delete[] chunking_base_name_; chunking_base_name_ = temp; + // From this point, strlen(chunking_base_name_) == filename_length if (!UpdateChunkName("chk", &chunk_name_)) return false; @@ -3666,18 +3644,16 @@ bool Segment::SetChunking(bool chunking, const char* filename) { if (!chunk_writer_cluster_->Open(chunk_name_)) return false; - const size_t header_length = strlen(filename) + strlen(".hdr") + 1; + const size_t hdr_length = strlen(".hdr"); + const size_t header_length = filename_length + hdr_length + 1; char* const header = new (std::nothrow) char[header_length]; // NOLINT if (!header) return false; -#ifdef _MSC_VER - strcpy_s(header, header_length - strlen(".hdr"), chunking_base_name_); - strcat_s(header, header_length, ".hdr"); -#else - strcpy(header, chunking_base_name_); - strcat(header, ".hdr"); -#endif + memcpy(header, chunking_base_name_, filename_length); + memcpy(&header[filename_length], ".hdr", hdr_length); + header[filename_length + hdr_length] = '\0'; + if (!chunk_writer_header_->Open(header)) { delete[] header; return false; @@ -4022,18 +3998,16 @@ bool Segment::UpdateChunkName(const char* ext, char** name) const { snprintf(ext_chk, sizeof(ext_chk), "_%06d.%s", chunk_count_, ext); #endif - const size_t length = strlen(chunking_base_name_) + strlen(ext_chk) + 1; + const size_t chunking_base_name_length = strlen(chunking_base_name_); + const size_t ext_chk_length = strlen(ext_chk); + const size_t length = chunking_base_name_length + ext_chk_length + 1; char* const str = new (std::nothrow) char[length]; // NOLINT if (!str) return false; -#ifdef _MSC_VER - strcpy_s(str, length - strlen(ext_chk), chunking_base_name_); - strcat_s(str, length, ext_chk); -#else - strcpy(str, chunking_base_name_); - strcat(str, ext_chk); -#endif + memcpy(str, chunking_base_name_, chunking_base_name_length); + memcpy(&str[chunking_base_name_length], ext_chk, ext_chk_length); + str[chunking_base_name_length + ext_chk_length] = '\0'; delete[] * name; *name = str; diff --git a/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxer.h b/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxer.h index f2db377145..2c4bb9e93e 100644 --- a/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxer.h +++ b/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxer.h @@ -330,7 +330,7 @@ class ContentEncoding { private: // Returns the size in bytes for the encoding elements. - uint64_t EncodingSize(uint64_t compresion_size, + uint64_t EncodingSize(uint64_t compression_size, uint64_t encryption_size) const; // Returns the size in bytes for the encryption elements. @@ -1425,7 +1425,7 @@ class SeekHead { bool Write(IMkvWriter* writer); // We are going to put a cap on the number of Seek Entries. - const static int32_t kSeekEntryCount = 5; + constexpr static int32_t kSeekEntryCount = 5; private: // Returns the maximum size in bytes of one seek entry. @@ -1481,7 +1481,7 @@ class SegmentInfo { uint64_t timecode_scale_; // Initially set to libwebm-%d.%d.%d.%d, major, minor, build, revision. char* writing_app_; - // LLONG_MIN when DateUTC is not set. + // INT64_MIN when DateUTC is not set. int64_t date_utc_; // The file position of the duration element. @@ -1505,8 +1505,8 @@ class Segment { kBeforeClusters = 0x1 // Position Cues before Clusters }; - static const uint32_t kDefaultDocTypeVersion = 4; - static const uint64_t kDefaultMaxClusterDuration = 30000000000ULL; + static constexpr uint32_t kDefaultDocTypeVersion = 4; + static constexpr uint64_t kDefaultMaxClusterDuration = 30000000000ULL; Segment(); ~Segment(); diff --git a/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc b/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc index bd2f769138..d1e835cd00 100644 --- a/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc +++ b/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc @@ -607,25 +607,21 @@ uint64 WriteVoidElement(IMkvWriter* writer, uint64 size) { void GetVersion(int32* major, int32* minor, int32* build, int32* revision) { *major = 0; *minor = 3; - *build = 0; + *build = 3; *revision = 0; } uint64 MakeUID(unsigned int* seed) { uint64 uid = 0; -#ifdef __MINGW32__ - srand(*seed); -#endif - for (int i = 0; i < 7; ++i) { // avoid problems with 8-byte values uid <<= 8; // TODO(fgalligan): Move random number generation to platform specific code. -#ifdef _MSC_VER +#ifdef _WIN32 (void)seed; const int32 nn = rand(); -#elif __ANDROID__ +#elif defined(__ANDROID__) (void)seed; int32 temp_num = 1; int fd = open("/dev/urandom", O_RDONLY); @@ -634,8 +630,6 @@ uint64 MakeUID(unsigned int* seed) { close(fd); } const int32 nn = temp_num; -#elif defined __MINGW32__ - const int32 nn = rand(); #else const int32 nn = rand_r(seed); #endif diff --git a/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxerutil.h b/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxerutil.h index 3355428bd1..85fc2a209e 100644 --- a/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxerutil.h +++ b/libs/libvpx/third_party/libwebm/mkvmuxer/mkvmuxerutil.h @@ -8,9 +8,9 @@ #ifndef MKVMUXER_MKVMUXERUTIL_H_ #define MKVMUXER_MKVMUXERUTIL_H_ -#include "mkvmuxertypes.h" +#include -#include "stdint.h" +#include "mkvmuxertypes.h" namespace mkvmuxer { class Cluster; diff --git a/libs/libvpx/third_party/libwebm/mkvmuxer/mkvwriter.cc b/libs/libvpx/third_party/libwebm/mkvmuxer/mkvwriter.cc index d668384d85..9b714a5e7c 100644 --- a/libs/libvpx/third_party/libwebm/mkvmuxer/mkvwriter.cc +++ b/libs/libvpx/third_party/libwebm/mkvmuxer/mkvwriter.cc @@ -80,8 +80,14 @@ int32 MkvWriter::Position(int64 position) { return _fseeki64(file_, position, SEEK_SET); #elif defined(_WIN32) return fseeko64(file_, static_cast(position), SEEK_SET); -#else +#elif !(defined(__ANDROID__) && __ANDROID_API__ < 24 && !defined(__LP64__) && \ + defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) + // POSIX.1 has fseeko and ftello. fseeko and ftello are not available before + // Android API level 24. See + // https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md return fseeko(file_, static_cast(position), SEEK_SET); +#else + return fseek(file_, static_cast(position), SEEK_SET); #endif } diff --git a/libs/libvpx/third_party/libwebm/mkvparser/mkvparser.cc b/libs/libvpx/third_party/libwebm/mkvparser/mkvparser.cc index de8884b381..4fa7b37887 100644 --- a/libs/libvpx/third_party/libwebm/mkvparser/mkvparser.cc +++ b/libs/libvpx/third_party/libwebm/mkvparser/mkvparser.cc @@ -8,7 +8,6 @@ #include "mkvparser/mkvparser.h" #if defined(_MSC_VER) && _MSC_VER < 1800 -#include // _isnan() / _finite() #define MSC_COMPAT #endif @@ -16,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -55,7 +55,7 @@ Type* SafeArrayAlloc(unsigned long long num_elements, void GetVersion(int& major, int& minor, int& build, int& revision) { major = 1; minor = 1; - build = 0; + build = 3; revision = 0; } @@ -246,7 +246,8 @@ long UnserializeFloat(IMkvReader* pReader, long long pos, long long size_, if (size == 4) { union { float f; - unsigned long ff; + uint32_t ff; + static_assert(sizeof(float) == sizeof(uint32_t), ""); }; ff = 0; @@ -264,7 +265,8 @@ long UnserializeFloat(IMkvReader* pReader, long long pos, long long size_, } else { union { double d; - unsigned long long dd; + uint64_t dd; + static_assert(sizeof(double) == sizeof(uint64_t), ""); }; dd = 0; @@ -298,7 +300,7 @@ long UnserializeInt(IMkvReader* pReader, long long pos, long long size, if (status < 0) return status; - unsigned long long result = first_byte; + unsigned long long result = static_cast(first_byte); ++pos; for (long i = 1; i < size; ++i) { @@ -2432,7 +2434,7 @@ bool CuePoint::TrackPosition::Parse(IMkvReader* pReader, long long start_, pos += size; // consume payload } - if ((m_pos < 0) || (m_track <= 0)) { + if ((m_pos < 0) || (m_track <= 0) || (m_block < 0) || (m_block > LONG_MAX)) { return false; } @@ -4569,7 +4571,8 @@ int Track::Info::CopyStr(char* Info::*str, Info& dst_) const { if (dst == NULL) return -1; - strcpy(dst, src); + memcpy(dst, src, len); + dst[len] = '\0'; return 0; } @@ -7887,8 +7890,10 @@ long Block::Parse(const Cluster* pCluster) { if (frame_size <= 0) return E_FILE_FORMAT_INVALID; +#if LLONG_MAX > LONG_MAX if (frame_size > LONG_MAX) return E_FILE_FORMAT_INVALID; +#endif if ((pos + len) > stop) return E_FILE_FORMAT_INVALID; @@ -7954,8 +7959,10 @@ long Block::Parse(const Cluster* pCluster) { if (frame_size <= 0) return E_FILE_FORMAT_INVALID; +#if LLONG_MAX > LONG_MAX if (frame_size > LONG_MAX) return E_FILE_FORMAT_INVALID; +#endif curr.len = static_cast(frame_size); // Check if size + curr.len could overflow. diff --git a/libs/libvpx/third_party/libwebm/mkvparser/mkvreader.cc b/libs/libvpx/third_party/libwebm/mkvparser/mkvreader.cc index 9d19c1be56..467260402a 100644 --- a/libs/libvpx/third_party/libwebm/mkvparser/mkvreader.cc +++ b/libs/libvpx/third_party/libwebm/mkvparser/mkvreader.cc @@ -120,8 +120,14 @@ int MkvReader::Read(long long offset, long len, unsigned char* buffer) { return -1; // error #elif defined(_WIN32) fseeko64(m_file, static_cast(offset), SEEK_SET); -#else +#elif !(defined(__ANDROID__) && __ANDROID_API__ < 24 && !defined(__LP64__) && \ + defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) + // POSIX.1 has fseeko and ftello. fseeko and ftello are not available before + // Android API level 24. See + // https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md fseeko(m_file, static_cast(offset), SEEK_SET); +#else + fseek(m_file, static_cast(offset), SEEK_SET); #endif const size_t size = fread(buffer, 1, len, m_file); diff --git a/libs/libvpx/third_party/libyuv/README.libvpx b/libs/libvpx/third_party/libyuv/README.libvpx index 9519dc4bee..5b299853ca 100644 --- a/libs/libvpx/third_party/libyuv/README.libvpx +++ b/libs/libvpx/third_party/libyuv/README.libvpx @@ -1,8 +1,12 @@ Name: libyuv URL: https://chromium.googlesource.com/libyuv/libyuv -Version: a37e7bfece9e0676ae90a1700b0ec85b0f4f22a1 -License: BSD +Version: N/A +Update Mechanism: Manual +Revision: a37e7bfece9e0676ae90a1700b0ec85b0f4f22a1 +License: BSD-3-Clause License File: LICENSE +Shipped in Chromium: no +Security Critical: yes Description: libyuv is an open source project that includes YUV conversion and scaling diff --git a/libs/libvpx/third_party/nalloc/LICENSE b/libs/libvpx/third_party/nalloc/LICENSE new file mode 100644 index 0000000000..14c2b9e737 --- /dev/null +++ b/libs/libvpx/third_party/nalloc/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Catena cyber + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/libs/libvpx/third_party/nalloc/README.libvpx b/libs/libvpx/third_party/nalloc/README.libvpx new file mode 100644 index 0000000000..47129d95ed --- /dev/null +++ b/libs/libvpx/third_party/nalloc/README.libvpx @@ -0,0 +1,15 @@ +Name: nalloc +URL: https://github.com/catenacyber/nallocfuzz +Version: N/A +Update Mechanism: Manual +Revision: dc351a94bbded5ede5b7550d6d08e78e0cc6dcef +License: MIT +License File: LICENSE +Shipped in Chromium: no +Security Critical: no + +Description: +Nalloc is a tool to inject allocation failures while fuzzing. + +Local Modifications: +None diff --git a/libs/libvpx/third_party/nalloc/nalloc.h b/libs/libvpx/third_party/nalloc/nalloc.h new file mode 100644 index 0000000000..f910926b18 --- /dev/null +++ b/libs/libvpx/third_party/nalloc/nalloc.h @@ -0,0 +1,342 @@ +/* + MIT License + + Copyright (c) 2025 Catena cyber + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#ifndef NALLOC_H_ +#define NALLOC_H_ + +#if defined(__clang__) && defined(__has_feature) +#if __has_feature(address_sanitizer) +#define NALLOC_ASAN 1 +#endif +#if __has_feature(memory_sanitizer) +#define FUZZER_DISABLE_NALLOC 1 +#endif +#endif + +#if defined(FUZZER_DISABLE_NALLOC) +#define nalloc_init(x) +#define nalloc_restrict_file_prefix(x) +#define nalloc_start(x, y) +#define nalloc_end() +#else + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static const uint32_t nalloc_crc32_table[] = { + 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, + 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, + 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, + 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, + 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, + 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, + 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, + 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, + 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, + 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, + 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, + 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, + 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, + 0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, + 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, + 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, + 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, + 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, + 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, + 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, + 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, + 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, + 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1, + 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, + 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, + 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, + 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, + 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, + 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, + 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, + 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, + 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, + 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, + 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, + 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, + 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, + 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, + 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, + 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, + 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, + 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, + 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, + 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 +}; + +// Nallocfuzz data to take a decision +uint32_t nalloc_random_state = 0; +__thread unsigned int nalloc_running = 0; +bool nalloc_initialized = false; +uint32_t nalloc_runs = 0; + +// Nalloc fuzz parameters +uint32_t nalloc_bitmask = 0xFF; +bool nalloc_random_bitmask = true; +uint32_t nalloc_magic = 0x294cee63; +bool nalloc_verbose = false; + +#ifdef NALLOC_ASAN +extern void __sanitizer_print_stack_trace(void); +#endif + +// Generic init, using env variables to get parameters +void nalloc_init(const char *prog) { + if (nalloc_initialized) { + return; + } + nalloc_initialized = true; + char *bitmask = getenv("NALLOC_FREQ"); + if (bitmask) { + int shift = atoi(bitmask); + if (shift > 0 && shift < 31) { + nalloc_bitmask = 1 << shift; + nalloc_random_bitmask = false; + } else if (shift == 0) { + nalloc_random_bitmask = false; + nalloc_bitmask = 0; + } + } else if (prog == NULL || strstr(prog, "nalloc") == NULL) { + nalloc_random_bitmask = false; + nalloc_bitmask = 0; + return; + } + + char *magic = getenv("NALLOC_MAGIC"); + if (magic) { + nalloc_magic = (uint32_t)strtol(magic, NULL, 0); + } + + char *verbose = getenv("NALLOC_VERBOSE"); + if (verbose) { + nalloc_verbose = true; + } +} + +// add one byte to the CRC +static inline void nalloc_random_update(uint8_t b) { + nalloc_random_state = + ((uint32_t)((uint32_t)nalloc_random_state << 8)) ^ + nalloc_crc32_table[((nalloc_random_state >> 24) ^ b) & 0xFF]; +} + +// Start the failure injections, using a buffer as seed +static int nalloc_start(const uint8_t *data, size_t size) { + if (nalloc_random_bitmask) { + if (nalloc_random_state & 0x10) { + nalloc_bitmask = 0xFFFFFFFF; + } else { + nalloc_bitmask = 1 << (5 + (nalloc_random_state & 0xF)); + } + } else if (nalloc_bitmask == 0) { + // nalloc disabled + return 0; + } + nalloc_random_state = 0; + for (size_t i = 0; i < size; i++) { + nalloc_random_update(data[i]); + } + if (__sync_fetch_and_add(&nalloc_running, 1)) { + __sync_fetch_and_sub(&nalloc_running, 1); + return 0; + } + nalloc_runs++; + return 1; +} + +// Stop the failure injections +static void nalloc_end() { __sync_fetch_and_sub(&nalloc_running, 1); } + +static bool nalloc_backtrace_exclude(size_t size, const char *op) { + if (nalloc_verbose) { + fprintf(stderr, "failed %s(%zu) \n", op, size); +#ifdef NALLOC_ASAN + __sanitizer_print_stack_trace(); +#endif + } + + return false; +} + +// +static bool nalloc_fail(size_t size, const char *op) { + // do not fail before thread init + if (nalloc_runs == 0) { + return false; + } + if (__sync_fetch_and_add(&nalloc_running, 1) != 1) { + // do not fail allocations outside of fuzzer input + // and do not fail inside of this function + __sync_fetch_and_sub(&nalloc_running, 1); + return false; + } + nalloc_random_update((uint8_t)size); + if (size >= 0x100) { + nalloc_random_update((uint8_t)(size >> 8)); + if (size >= 0x10000) { + nalloc_random_update((uint8_t)(size >> 16)); + // bigger may already fail or oom + } + } + if (((nalloc_random_state ^ nalloc_magic) & nalloc_bitmask) == 0) { + if (nalloc_backtrace_exclude(size, op)) { + __sync_fetch_and_sub(&nalloc_running, 1); + return false; + } + __sync_fetch_and_sub(&nalloc_running, 1); + return true; + } + __sync_fetch_and_sub(&nalloc_running, 1); + return false; +} + +// ASAN interceptor for libc routines +#ifdef NALLOC_ASAN +extern void *__interceptor_malloc(size_t); +extern void *__interceptor_calloc(size_t, size_t); +extern void *__interceptor_realloc(void *, size_t); +extern void *__interceptor_reallocarray(void *, size_t, size_t); + +extern ssize_t __interceptor_read(int, void *, size_t); +extern ssize_t __interceptor_write(int, const void *, size_t); +extern ssize_t __interceptor_recv(int, void *, size_t, int); +extern ssize_t __interceptor_send(int, const void *, size_t, int); + +#define nalloc_malloc(s) __interceptor_malloc(s) +#define nalloc_calloc(s, n) __interceptor_calloc(s, n) +#define nalloc_realloc(p, s) __interceptor_realloc(p, s) +#define nalloc_reallocarray(p, s, n) __interceptor_reallocarray(p, s, n) + +#define nalloc_read(f, b, s) __interceptor_read(f, b, s) +#define nalloc_write(f, b, s) __interceptor_write(f, b, s) +#define nalloc_recv(f, b, s, x) __interceptor_recv(f, b, s, x) +#define nalloc_send(f, b, s, x) __interceptor_send(f, b, s, x) + +#else +extern void *__libc_malloc(size_t); +extern void *__libc_calloc(size_t, size_t); +extern void *__libc_realloc(void *, size_t); +extern void *__libc_reallocarray(void *, size_t, size_t); + +extern ssize_t __read(int, void *, size_t); +extern ssize_t __write(int, const void *, size_t); +extern ssize_t __recv(int, void *, size_t, int); +extern ssize_t __send(int, const void *, size_t, int); + +#define nalloc_malloc(s) __libc_malloc(s) +#define nalloc_calloc(s, n) __libc_calloc(s, n) +#define nalloc_realloc(p, s) __libc_realloc(p, s) +#define nalloc_reallocarray(p, s, n) __libc_reallocarray(p, s, n) + +#define nalloc_read(f, b, s) __read(f, b, s) +#define nalloc_write(f, b, s) __write(f, b, s) +#define nalloc_recv(f, b, s, x) __recv(f, b, s, x) +#define nalloc_send(f, b, s, x) __send(f, b, s, x) +#endif + +// nalloc standard function overwrites with pseudo-random failures +ssize_t read(int fd, void *buf, size_t count) { + if (nalloc_fail(count, "read")) { + errno = EIO; + return -1; + } + return nalloc_read(fd, buf, count); +} + +ssize_t write(int fd, const void *buf, size_t count) { + if (nalloc_fail(count, "write")) { + errno = EIO; + return -1; + } + return nalloc_write(fd, buf, count); +} + +ssize_t recv(int fd, void *buf, size_t count, int flags) { + if (nalloc_fail(count, "recv")) { + errno = EIO; + return -1; + } + return nalloc_recv(fd, buf, count, flags); +} + +ssize_t send(int fd, const void *buf, size_t count, int flags) { + if (nalloc_fail(count, "send")) { + errno = EIO; + return -1; + } + return nalloc_send(fd, buf, count, flags); +} + +void *calloc(size_t nmemb, size_t size) { + if (nalloc_fail(size, "calloc")) { + errno = ENOMEM; + return NULL; + } + return nalloc_calloc(nmemb, size); +} + +void *malloc(size_t size) { + if (nalloc_fail(size, "malloc")) { + errno = ENOMEM; + return NULL; + } + return nalloc_malloc(size); +} + +void *realloc(void *ptr, size_t size) { + if (nalloc_fail(size, "realloc")) { + errno = ENOMEM; + return NULL; + } + return nalloc_realloc(ptr, size); +} + +void *reallocarray(void *ptr, size_t nmemb, size_t size) { + if (nalloc_fail(size, "reallocarray")) { + errno = ENOMEM; + return NULL; + } + return nalloc_reallocarray(ptr, nmemb, size); +} + +#ifdef __cplusplus +} // extern "C" { +#endif + +#endif // FUZZER_DISABLE_NALLOC + +#endif // NALLOC_H_ diff --git a/libs/libvpx/third_party/x86inc/README.libvpx b/libs/libvpx/third_party/x86inc/README.libvpx index 195654f7bb..7153d88ab0 100644 --- a/libs/libvpx/third_party/x86inc/README.libvpx +++ b/libs/libvpx/third_party/x86inc/README.libvpx @@ -1,7 +1,12 @@ +Name: x86inc.asm URL: https://git.videolan.org/git/x264.git -Version: 3e5aed95cc470f37e2db3e6506a8deb89b527720 +Version: N/A +Update Mechanism: Manual +Revision: 3e5aed95cc470f37e2db3e6506a8deb89b527720 License: ISC License File: LICENSE +Shipped in Chromium: yes +Security Critical: yes Description: x264/libav's framework for x86 assembly. Contains a variety of macros and diff --git a/libs/libvpx/tools.mk b/libs/libvpx/tools.mk index dd2ebeb3d5..79bb0cb8d6 100644 --- a/libs/libvpx/tools.mk +++ b/libs/libvpx/tools.mk @@ -91,6 +91,13 @@ INSTALL-BINS-$(CONFIG_MSVS) += $(foreach p,$(VS_PLATFORMS),\ $(foreach proj,$(call enabled,PROJECTS),\ $(eval $(call vcproj_template,$(proj)))) +# Generate a list of all enabled sources, in particular for exporting to gyp +# based build systems. +tiny_ssim_srcs.txt: + @echo " [CREATE] $@" + @echo $(tiny_ssim.SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@ +CLEAN-OBJS += tiny_ssim_srcs.txt + # # Documentation Rules # diff --git a/libs/libvpx/tools/3D-Reconstruction/MotionEST/Exhaust.py b/libs/libvpx/tools/3D-Reconstruction/MotionEST/Exhaust.py index 2d6a4d8114..d763de8562 100644 --- a/libs/libvpx/tools/3D-Reconstruction/MotionEST/Exhaust.py +++ b/libs/libvpx/tools/3D-Reconstruction/MotionEST/Exhaust.py @@ -83,7 +83,7 @@ class ExhaustNeighbor(MotionEST): self.beta = beta self.metric = metric super(ExhaustNeighbor, self).__init__(cur_f, ref_f, blk_size) - self.assign = np.zeros((self.num_row, self.num_col), dtype=np.bool) + self.assign = np.zeros((self.num_row, self.num_col), dtype=bool) """ estimate neighbor loss: diff --git a/libs/libvpx/tools/3D-Reconstruction/MotionEST/GroundTruth.py b/libs/libvpx/tools/3D-Reconstruction/MotionEST/GroundTruth.py index 12bc53ff73..37305898a7 100644 --- a/libs/libvpx/tools/3D-Reconstruction/MotionEST/GroundTruth.py +++ b/libs/libvpx/tools/3D-Reconstruction/MotionEST/GroundTruth.py @@ -29,7 +29,7 @@ class GroundTruth(MotionEST): def __init__(self, cur_f, ref_f, blk_sz, gt_path, mf=None, mask=None): self.name = 'ground truth' super(GroundTruth, self).__init__(cur_f, ref_f, blk_sz) - self.mask = np.zeros((self.num_row, self.num_col), dtype=np.bool) + self.mask = np.zeros((self.num_row, self.num_col), dtype=bool) if gt_path: with open(gt_path) as gt_file: lines = gt_file.readlines() @@ -42,7 +42,7 @@ class GroundTruth(MotionEST): self.mask[i, -j - 1] = True continue #the order of original file is flipped on the x axis - self.mf[i, -j - 1] = np.array([float(y), -float(x)], dtype=np.int) + self.mf[i, -j - 1] = np.array([float(y), -float(x)], dtype=int) else: self.mf = mf self.mask = mask diff --git a/libs/libvpx/tools/3D-Reconstruction/MotionEST/MotionEST.py b/libs/libvpx/tools/3D-Reconstruction/MotionEST/MotionEST.py index 0959530fa0..fc393818d9 100644 --- a/libs/libvpx/tools/3D-Reconstruction/MotionEST/MotionEST.py +++ b/libs/libvpx/tools/3D-Reconstruction/MotionEST/MotionEST.py @@ -28,8 +28,8 @@ class MotionEST(object): self.ref_f = ref_f self.blk_sz = blk_sz #convert RGB to YUV - self.cur_yuv = np.array(self.cur_f.convert('YCbCr'), dtype=np.int) - self.ref_yuv = np.array(self.ref_f.convert('YCbCr'), dtype=np.int) + self.cur_yuv = np.array(self.cur_f.convert('YCbCr'), dtype=int) + self.ref_yuv = np.array(self.ref_f.convert('YCbCr'), dtype=int) #frame size self.width = self.cur_f.size[0] self.height = self.cur_f.size[1] diff --git a/libs/libvpx/tools/3D-Reconstruction/MotionEST/Util.py b/libs/libvpx/tools/3D-Reconstruction/MotionEST/Util.py index 551881cfd7..c2416163be 100644 --- a/libs/libvpx/tools/3D-Reconstruction/MotionEST/Util.py +++ b/libs/libvpx/tools/3D-Reconstruction/MotionEST/Util.py @@ -18,7 +18,7 @@ from PIL import Image, ImageDraw def MSE(blk1, blk2): return np.mean( LA.norm( - np.array(blk1, dtype=np.int) - np.array(blk2, dtype=np.int), axis=2)) + np.array(blk1, dtype=int) - np.array(blk2, dtype=int), axis=2)) def drawMF(img, blk_sz, mf): diff --git a/libs/libvpx/tools/README.pgo.md b/libs/libvpx/tools/README.pgo.md new file mode 100644 index 0000000000..414743f8fc --- /dev/null +++ b/libs/libvpx/tools/README.pgo.md @@ -0,0 +1,24 @@ +# Using Profile Guided Optimizations to identify compiler optimization failures + +When using Clang, the `-Rpass-missed` flag enables the verbose log of failed +compiler optimizations. However, the extensive log messages can obscure +potential optimization opportunities. + +Use the following steps to generate a more transparent optimization report +using a previously created PGO profile file. The report also includes code +hotness diagnostics: + +```bash +$ ../libvpx/configure --use-profile=perf.profdata \ + --extra-cflags="-fsave-optimization-record -fdiagnostics-show-hotness" +``` + +Convert the generated YAML files into a detailed HTML report using the +[optviewer2](https://github.com/OfekShilon/optview2) tool: + +```bash +$ opt-viewer.py --output-dir=out/ --source-dir=libvpx . +``` + +The HTML report displays each code line's relative hotness, cross-referenced +with the failed compiler optimizations. diff --git a/libs/libvpx/tools/set_analyzer_env.sh b/libs/libvpx/tools/set_analyzer_env.sh index 8ee0c4fe5a..a3e8a1ae99 100644 --- a/libs/libvpx/tools/set_analyzer_env.sh +++ b/libs/libvpx/tools/set_analyzer_env.sh @@ -68,19 +68,23 @@ echo "test_libvpx, etc) to link the stack traces to source code lines." cflags="-fsanitize=${sanitizer}" ldflags="-fsanitize=${sanitizer}" -# http://code.google.com/p/webm/issues/detail?id=570 -cflags="${cflags} -fno-strict-aliasing" # Useful backtraces. cflags="${cflags} -fno-omit-frame-pointer" # Exact backtraces. cflags="${cflags} -fno-optimize-sibling-calls" -if [ "${sanitizer}" = "cfi" ]; then - # https://clang.llvm.org/docs/ControlFlowIntegrity.html - cflags="${cflags} -fno-sanitize-trap=cfi -flto -fvisibility=hidden" - ldflags="${ldflags} -fno-sanitize-trap=cfi -flto -fuse-ld=gold" - export AR="llvm-ar" -fi +case "${sanitizer}" in + cfi) + # https://clang.llvm.org/docs/ControlFlowIntegrity.html + cflags="${cflags} -fno-sanitize-trap=cfi -flto -fvisibility=hidden" + ldflags="${ldflags} -fno-sanitize-trap=cfi -flto -fuse-ld=gold" + export AR="llvm-ar" + ;; + integer|undefined) + # https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html + cflags="${cflags} -fsanitize=float-cast-overflow" + ;; +esac set -x export CC="clang" diff --git a/libs/libvpx/tools/tiny_ssim.c b/libs/libvpx/tools/tiny_ssim.c index 8fba814621..c07a9d2118 100644 --- a/libs/libvpx/tools/tiny_ssim.c +++ b/libs/libvpx/tools/tiny_ssim.c @@ -150,12 +150,15 @@ static void close_input_file(input_file_t *in) { } } -static size_t read_input_file(input_file_t *in, unsigned char **y, - unsigned char **u, unsigned char **v, int bd) { +// Returns 1 on success, 0 on failure due to a read error or eof (or format +// error in the case of y4m). +static int read_input_file(input_file_t *in, unsigned char **y, + unsigned char **u, unsigned char **v, int bd) { size_t r1 = 0; switch (in->type) { case Y4M: r1 = y4m_input_fetch_frame(&in->y4m, in->file, &in->img); + if (r1 == (size_t)-1) return 0; *y = in->img.planes[0]; *u = in->img.planes[1]; *v = in->img.planes[2]; @@ -175,7 +178,7 @@ static size_t read_input_file(input_file_t *in, unsigned char **y, break; } - return r1; + return r1 != 0; } static void ssim_parms_8x8(const uint8_t *s, int sp, const uint8_t *r, int rp, @@ -328,20 +331,33 @@ int main(int argc, char *argv[]) { memset(in, 0, sizeof(in)); - if (argc < 2) { + if (argc < 3) { fprintf(stderr, "Usage: %s file1.{yuv|y4m} file2.{yuv|y4m}" - "[WxH tl_skip={0,1,3} frame_stats_file bits]\n", + " [WxH tl_skip={0,1,3} frame_stats_file bits]\n", argv[0]); return 1; } if (argc > 3) { - sscanf(argv[3], "%dx%d", &w, &h); + if (sscanf(argv[3], "%dx%d", &w, &h) != 2) { + fprintf(stderr, "arguments for w/h not assigned!\n"); + goto clean_up; + } + // Limit width/height to 4K. The frame_size set in the function + // open_input_file() will still be within range of int. + if (w < 1 || w > 4096 || h < 1 || h > 4096) { + fprintf(stderr, + "width or height is too large (above 4096) or below 1!\n"); + goto clean_up; + } } if (argc > 6) { - sscanf(argv[6], "%d", &bit_depth); + if (sscanf(argv[6], "%d", &bit_depth) != 1) { + fprintf(stderr, "argument for bit_depth not assigned!\n"); + goto clean_up; + } } if (open_input_file(argv[1], &in[0], w, h, bit_depth) < 0) { @@ -386,7 +402,10 @@ int main(int argc, char *argv[]) { // encoding in mode 10. 7 would be reasonable for comparing TL0 of a 4-layer // encoding. if (argc > 4) { - sscanf(argv[4], "%d", &tl_skip); + if (sscanf(argv[4], "%d", &tl_skip) != 1) { + fprintf(stderr, "argument for tl_skip not assigned!\n"); + goto clean_up; + } if (argc > 5) { framestats = fopen(argv[5], "w"); if (!framestats) { @@ -399,31 +418,37 @@ int main(int argc, char *argv[]) { } while (1) { - size_t r1, r2; + int r1, r2; unsigned char *y[2], *u[2], *v[2]; r1 = read_input_file(&in[0], &y[0], &u[0], &v[0], bit_depth); - - if (r1) { - // Reading parts of file1.yuv that were not used in temporal layer. - if (tl_skips_remaining > 0) { - --tl_skips_remaining; - continue; + if (r1 == 0) { + if (ferror(in[0].file)) { + fprintf(stderr, "Failed to read data from '%s'\n", argv[1]); + return_value = 1; + goto clean_up; } - // Use frame, but skip |tl_skip| after it. - tl_skips_remaining = tl_skip; - } - - r2 = read_input_file(&in[1], &y[1], &u[1], &v[1], bit_depth); - - if (r1 && r2 && r1 != r2) { - fprintf(stderr, "Failed to read data: %s [%d/%d]\n", strerror(errno), - (int)r1, (int)r2); - return_value = 1; - goto clean_up; - } else if (r1 == 0 || r2 == 0) { break; } + + // Reading parts of file1.yuv that were not used in temporal layer. + if (tl_skips_remaining > 0) { + --tl_skips_remaining; + continue; + } + // Use frame, but skip |tl_skip| after it. + tl_skips_remaining = tl_skip; + + r2 = read_input_file(&in[1], &y[1], &u[1], &v[1], bit_depth); + if (r2 == 0) { + if (ferror(in[1].file)) { + fprintf(stderr, "Failed to read data from '%s'\n", argv[2]); + return_value = 1; + goto clean_up; + } + break; + } + #if CONFIG_VP9_HIGHBITDEPTH #define psnr_and_ssim(ssim, psnr, buf0, buf1, w, h) \ do { \ diff --git a/libs/libvpx/tools_common.c b/libs/libvpx/tools_common.c index cbecfbb419..f1a8cbcd81 100644 --- a/libs/libvpx/tools_common.c +++ b/libs/libvpx/tools_common.c @@ -24,15 +24,11 @@ #include "vpx/vp8dx.h" #endif -#if defined(_WIN32) || defined(__OS2__) +#include "vpx/vpx_codec.h" + +#if defined(_WIN32) #include #include - -#ifdef __OS2__ -#define _setmode setmode -#define _fileno fileno -#define _O_BINARY O_BINARY -#endif #endif #define LOG_ERROR(label) \ @@ -56,7 +52,7 @@ static size_t wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { FILE *set_binary_mode(FILE *stream) { (void)stream; -#if defined(_WIN32) || defined(__OS2__) +#if defined(_WIN32) _setmode(_fileno(stream), _O_BINARY); #endif return stream; @@ -77,8 +73,8 @@ void warn(const char *fmt, ...) { LOG_ERROR("Warning"); } void die_codec(vpx_codec_ctx_t *ctx, const char *s) { const char *detail = vpx_codec_error_detail(ctx); - printf("%s: %s\n", s, vpx_codec_error(ctx)); - if (detail) printf(" %s\n", detail); + fprintf(stderr, "%s: %s\n", s, vpx_codec_error(ctx)); + if (detail) fprintf(stderr, " %s\n", detail); exit(EXIT_FAILURE); } @@ -94,10 +90,11 @@ int read_yuv_frame(struct VpxInputContext *input_ctx, vpx_image_t *yuv_frame) { int w = vpx_img_plane_width(yuv_frame, plane); const int h = vpx_img_plane_height(yuv_frame, plane); int r; - // Assuming that for nv12 we read all chroma data at one time + // Assuming that for nv12 we read all chroma data at once if (yuv_frame->fmt == VPX_IMG_FMT_NV12 && plane > 1) break; - // Fixing NV12 chroma width it is odd - if (yuv_frame->fmt == VPX_IMG_FMT_NV12 && plane == 1) w = (w + 1) & ~1; + // NV12 UV plane is interleaved, so it has twice the width of a subsampled + // plane. + if (yuv_frame->fmt == VPX_IMG_FMT_NV12 && plane == 1) w = w * 2; /* Determine the correct plane based on the image format. The for-loop * always counts in Y,U,V order, but this may not match the order of * the data on disk. @@ -227,17 +224,23 @@ int vpx_img_plane_height(const vpx_image_t *img, int plane) { void vpx_img_write(const vpx_image_t *img, FILE *file) { int plane; + const int bytespp = (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1; for (plane = 0; plane < 3; ++plane) { const unsigned char *buf = img->planes[plane]; const int stride = img->stride[plane]; - const int w = vpx_img_plane_width(img, plane) * - ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); + int w = vpx_img_plane_width(img, plane); const int h = vpx_img_plane_height(img, plane); int y; + // Assuming that for nv12 we write all chroma data at once + if (img->fmt == VPX_IMG_FMT_NV12 && plane > 1) break; + // NV12 UV plane is interleaved, so it has twice the width of a subsampled + // plane. + if (img->fmt == VPX_IMG_FMT_NV12 && plane == 1) w = w * 2; + for (y = 0; y < h; ++y) { - fwrite(buf, 1, w, file); + fwrite(buf, bytespp, w, file); buf += stride; } } @@ -245,17 +248,23 @@ void vpx_img_write(const vpx_image_t *img, FILE *file) { int vpx_img_read(vpx_image_t *img, FILE *file) { int plane; + const int bytespp = (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1; for (plane = 0; plane < 3; ++plane) { unsigned char *buf = img->planes[plane]; const int stride = img->stride[plane]; - const int w = vpx_img_plane_width(img, plane) * - ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); + int w = vpx_img_plane_width(img, plane); const int h = vpx_img_plane_height(img, plane); int y; + // Assuming that for nv12 we read all chroma data at once + if (img->fmt == VPX_IMG_FMT_NV12 && plane > 1) break; + // NV12 UV plane is interleaved, so it has twice the width of a subsampled + // plane. + if (img->fmt == VPX_IMG_FMT_NV12 && plane == 1) w = w * 2; + for (y = 0; y < h; ++y) { - if (fread(buf, 1, w, file) != (size_t)w) return 0; + if (fread(buf, bytespp, w, file) != (size_t)w) return 0; buf += stride; } } @@ -375,7 +384,7 @@ static void highbd_img_upshift(vpx_image_t *dst, vpx_image_t *src, case VPX_IMG_FMT_I42216: case VPX_IMG_FMT_I44416: case VPX_IMG_FMT_I44016: break; - default: fatal("Unsupported image conversion"); break; + default: fatal("Unsupported image conversion"); } for (plane = 0; plane < 3; plane++) { int w = src->d_w; @@ -411,7 +420,7 @@ static void lowbd_img_upshift(vpx_image_t *dst, vpx_image_t *src, case VPX_IMG_FMT_I422: case VPX_IMG_FMT_I444: case VPX_IMG_FMT_I440: break; - default: fatal("Unsupported image conversion"); break; + default: fatal("Unsupported image conversion"); } for (plane = 0; plane < 3; plane++) { int w = src->d_w; @@ -452,7 +461,7 @@ void vpx_img_truncate_16_to_8(vpx_image_t *dst, vpx_image_t *src) { case VPX_IMG_FMT_I422: case VPX_IMG_FMT_I444: case VPX_IMG_FMT_I440: break; - default: fatal("Unsupported image conversion"); break; + default: fatal("Unsupported image conversion"); } for (plane = 0; plane < 3; plane++) { int w = src->d_w; @@ -487,7 +496,7 @@ static void highbd_img_downshift(vpx_image_t *dst, vpx_image_t *src, case VPX_IMG_FMT_I42216: case VPX_IMG_FMT_I44416: case VPX_IMG_FMT_I44016: break; - default: fatal("Unsupported image conversion"); break; + default: fatal("Unsupported image conversion"); } for (plane = 0; plane < 3; plane++) { int w = src->d_w; @@ -521,7 +530,7 @@ static void lowbd_img_downshift(vpx_image_t *dst, vpx_image_t *src, case VPX_IMG_FMT_I422: case VPX_IMG_FMT_I444: case VPX_IMG_FMT_I440: break; - default: fatal("Unsupported image conversion"); break; + default: fatal("Unsupported image conversion"); } for (plane = 0; plane < 3; plane++) { int w = src->d_w; diff --git a/libs/libvpx/tools_common.h b/libs/libvpx/tools_common.h index b9cfb9cc85..81453cc065 100644 --- a/libs/libvpx/tools_common.h +++ b/libs/libvpx/tools_common.h @@ -16,7 +16,6 @@ #include "vpx/vpx_codec.h" #include "vpx/vpx_image.h" #include "vpx/vpx_integer.h" -#include "vpx_ports/msvc.h" #if CONFIG_ENCODERS #include "./y4minput.h" @@ -32,7 +31,12 @@ typedef int64_t FileOffset; #define fseeko fseeko64 #define ftello ftello64 typedef off64_t FileOffset; -#elif CONFIG_OS_SUPPORT +#elif CONFIG_OS_SUPPORT && \ + !(defined(__ANDROID__) && __ANDROID_API__ < 24 && !defined(__LP64__) && \ + defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) +/* POSIX.1 has fseeko and ftello. fseeko and ftello are not available before + * Android API level 24. See + * https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md */ #include /* NOLINT */ typedef off_t FileOffset; /* Use 32-bit file operations in WebM file format when building ARM @@ -145,9 +149,9 @@ VPX_NO_RETURN void usage_exit(void); int read_yuv_frame(struct VpxInputContext *input_ctx, vpx_image_t *yuv_frame); typedef struct VpxInterface { - const char *const name; - const uint32_t fourcc; - vpx_codec_iface_t *(*const codec_interface)(); + const char *name; + uint32_t fourcc; + vpx_codec_iface_t *(*codec_interface)(void); } VpxInterface; int get_vpx_encoder_count(void); diff --git a/libs/libvpx/video_reader.c b/libs/libvpx/video_reader.c index 16822eff3c..217e8b9fba 100644 --- a/libs/libvpx/video_reader.c +++ b/libs/libvpx/video_reader.c @@ -38,18 +38,19 @@ VpxVideoReader *vpx_video_reader_open(const char *filename) { if (fread(header, 1, 32, file) != 32) { fprintf(stderr, "File header on %s can't be read.\n", filename); // Can't read file header + fclose(file); return NULL; } if (memcmp(kIVFSignature, header, 4) != 0) { fprintf(stderr, "The IVF signature on %s is wrong.\n", filename); // Wrong IVF signature - + fclose(file); return NULL; } if (mem_get_le16(header + 4) != 0) { fprintf(stderr, "%s uses the wrong IVF version.\n", filename); // Wrong IVF version - + fclose(file); return NULL; } @@ -58,7 +59,7 @@ VpxVideoReader *vpx_video_reader_open(const char *filename) { fprintf( stderr, "Can't allocate VpxVideoReader\n"); // Can't allocate VpxVideoReader - + fclose(file); return NULL; } diff --git a/libs/libvpx/video_writer.c b/libs/libvpx/video_writer.c index 6e9a848bc3..83a5b497dc 100644 --- a/libs/libvpx/video_writer.c +++ b/libs/libvpx/video_writer.c @@ -44,6 +44,7 @@ VpxVideoWriter *vpx_video_writer_open(const char *filename, writer = malloc(sizeof(*writer)); if (!writer) { fprintf(stderr, "Can't allocate VpxVideoWriter.\n"); + fclose(file); return NULL; } writer->frame_count = 0; diff --git a/libs/libvpx/vp8/common/alloccommon.c b/libs/libvpx/vp8/common/alloccommon.c index 722b158c3a..035f1e8767 100644 --- a/libs/libvpx/vp8/common/alloccommon.c +++ b/libs/libvpx/vp8/common/alloccommon.c @@ -17,10 +17,13 @@ #include "entropymode.h" #include "systemdependent.h" +// This function frees all frame and post processing buffers, as well as +// indirect references to them via context and mode info allocations. void vp8_de_alloc_frame_buffers(VP8_COMMON *oci) { int i; for (i = 0; i < NUM_YV12_BUFFERS; ++i) { vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]); + oci->fb_idx_ref_cnt[i] = 0; } vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame); @@ -28,13 +31,14 @@ void vp8_de_alloc_frame_buffers(VP8_COMMON *oci) { vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer); if (oci->post_proc_buffer_int_used) { vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer_int); + oci->post_proc_buffer_int_used = 0; } vpx_free(oci->pp_limits_buffer); oci->pp_limits_buffer = NULL; vpx_free(oci->postproc_state.generated_noise); - oci->postproc_state.generated_noise = NULL; + memset(&oci->postproc_state, 0, sizeof(oci->postproc_state)); #endif vpx_free(oci->above_context); @@ -42,10 +46,14 @@ void vp8_de_alloc_frame_buffers(VP8_COMMON *oci) { #if CONFIG_ERROR_CONCEALMENT vpx_free(oci->prev_mip); oci->prev_mip = NULL; + oci->prev_mi = NULL; #endif oci->above_context = NULL; oci->mip = NULL; + oci->mi = NULL; + oci->show_frame_mi = NULL; + oci->frame_to_show = NULL; } int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) { @@ -59,8 +67,6 @@ int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) { if ((height & 0xf) != 0) height += 16 - (height & 0xf); for (i = 0; i < NUM_YV12_BUFFERS; ++i) { - oci->fb_idx_ref_cnt[i] = 0; - oci->yv12_fb[i].flags = 0; if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0) { goto allocation_fail; @@ -107,8 +113,6 @@ int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) { goto allocation_fail; } - oci->post_proc_buffer_int_used = 0; - memset(&oci->postproc_state, 0, sizeof(oci->postproc_state)); memset(oci->post_proc_buffer.buffer_alloc, 128, oci->post_proc_buffer.frame_size); diff --git a/libs/libvpx/vp8/common/arm/neon/sixtappredict_neon.c b/libs/libvpx/vp8/common/arm/neon/sixtappredict_neon.c index 48e86d3278..a54e81084b 100644 --- a/libs/libvpx/vp8/common/arm/neon/sixtappredict_neon.c +++ b/libs/libvpx/vp8/common/arm/neon/sixtappredict_neon.c @@ -16,7 +16,7 @@ #include "vpx_ports/mem.h" static const int8_t vp8_sub_pel_filters[8][8] = { - { 0, 0, 128, 0, 0, 0, 0, 0 }, /* note that 1/8 pel positionyys are */ + { 0, 0, -128, 0, 0, 0, 0, 0 }, /* note that 1/8 pel positions are */ { 0, -6, 123, 12, -1, 0, 0, 0 }, /* just as per alpha -0.5 bicubic */ { 2, -11, 108, 36, -8, 1, 0, 0 }, /* New 1/4 pel 6 tap filter */ { 0, -9, 93, 50, -6, 0, 0, 0 }, @@ -781,7 +781,6 @@ void vp8_sixtap_predict8x4_neon(unsigned char *src_ptr, int src_pixels_per_line, vst1_u8(dst_ptr, d8u8); dst_ptr += dst_pitch; vst1_u8(dst_ptr, d9u8); - return; } void vp8_sixtap_predict8x8_neon(unsigned char *src_ptr, int src_pixels_per_line, @@ -1250,7 +1249,6 @@ void vp8_sixtap_predict8x8_neon(unsigned char *src_ptr, int src_pixels_per_line, vst1_u8(dst_ptr, d9u8); dst_ptr += dst_pitch; } - return; } void vp8_sixtap_predict16x16_neon(unsigned char *src_ptr, @@ -1504,7 +1502,9 @@ void vp8_sixtap_predict16x16_neon(unsigned char *src_ptr, src += src_pixels_per_line; d12u8 = vld1_u8(src); d13u8 = vld1_u8(src + 8); - d14u8 = vld1_u8(src + 16); + // Only 5 pixels are needed, avoid a potential out of bounds read. + d14u8 = vld1_u8(src + 13); + d14u8 = vext_u8(d14u8, d14u8, 3); src += src_pixels_per_line; __builtin_prefetch(src); @@ -1726,5 +1726,4 @@ void vp8_sixtap_predict16x16_neon(unsigned char *src_ptr, dst += dst_pitch; } } - return; } diff --git a/libs/libvpx/vp8/common/blockd.h b/libs/libvpx/vp8/common/blockd.h index 405443449d..8300aad941 100644 --- a/libs/libvpx/vp8/common/blockd.h +++ b/libs/libvpx/vp8/common/blockd.h @@ -251,7 +251,7 @@ typedef struct macroblockd { unsigned char update_mb_segmentation_data; /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */ - unsigned char mb_segement_abs_delta; + unsigned char mb_segment_abs_delta; /* Per frame flags that define which MB level features (such as quantizer or * loop filter level) */ diff --git a/libs/libvpx/vp8/common/common.h b/libs/libvpx/vp8/common/common.h index 562569f9ab..77fa783b48 100644 --- a/libs/libvpx/vp8/common/common.h +++ b/libs/libvpx/vp8/common/common.h @@ -23,18 +23,18 @@ extern "C" { /* Only need this for fixed-size arrays, for structs just assign. */ -#define vp8_copy(Dest, Src) \ - do { \ - assert(sizeof(Dest) == sizeof(Src)); \ - memcpy(Dest, Src, sizeof(Src)); \ +#define vp8_copy(Dest, Src) \ + do { \ + static_assert(sizeof(Dest) == sizeof(Src), ""); \ + memcpy(Dest, Src, sizeof(Src)); \ } while (0) /* Use this for variably-sized arrays. */ -#define vp8_copy_array(Dest, Src, N) \ - do { \ - assert(sizeof(*(Dest)) == sizeof(*(Src))); \ - memcpy(Dest, Src, (N) * sizeof(*(Src))); \ +#define vp8_copy_array(Dest, Src, N) \ + do { \ + static_assert(sizeof(*(Dest)) == sizeof(*(Src)), ""); \ + memcpy(Dest, Src, (N) * sizeof(*(Src))); \ } while (0) #define vp8_zero(Dest) memset(&(Dest), 0, sizeof(Dest)) diff --git a/libs/libvpx/vp8/common/dequantize.c b/libs/libvpx/vp8/common/dequantize.c index 8a56ae6868..d705b91c3f 100644 --- a/libs/libvpx/vp8/common/dequantize.c +++ b/libs/libvpx/vp8/common/dequantize.c @@ -19,7 +19,7 @@ void vp8_dequantize_b_c(BLOCKD *d, short *DQC) { short *Q = d->qcoeff; for (i = 0; i < 16; ++i) { - DQ[i] = Q[i] * DQC[i]; + DQ[i] = (short)(Q[i] * DQC[i]); } } diff --git a/libs/libvpx/vp8/common/entropy.c b/libs/libvpx/vp8/common/entropy.c index fc4a3539fd..b9efc0cc1f 100644 --- a/libs/libvpx/vp8/common/entropy.c +++ b/libs/libvpx/vp8/common/entropy.c @@ -114,7 +114,7 @@ static const vp8_prob Pcat6[] = { 254, 254, 243, 230, 196, 177, p[0] = p[1] = 0; } - void init_bit_trees() { + void init_bit_trees(void) { init_bit_tree(cat1, 1); init_bit_tree(cat2, 2); init_bit_tree(cat3, 3); diff --git a/libs/libvpx/vp8/common/findnearmv.c b/libs/libvpx/vp8/common/findnearmv.c index 6889fdedde..3b31923621 100644 --- a/libs/libvpx/vp8/common/findnearmv.c +++ b/libs/libvpx/vp8/common/findnearmv.c @@ -105,9 +105,9 @@ void vp8_find_near_mvs(MACROBLOCKD *xd, const MODE_INFO *here, int_mv *nearest, tmp = near_mv_ref_cnts[CNT_NEAREST]; near_mv_ref_cnts[CNT_NEAREST] = near_mv_ref_cnts[CNT_NEAR]; near_mv_ref_cnts[CNT_NEAR] = tmp; - tmp = near_mvs[CNT_NEAREST].as_int; + tmp = (int)near_mvs[CNT_NEAREST].as_int; near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int; - near_mvs[CNT_NEAR].as_int = tmp; + near_mvs[CNT_NEAR].as_int = (uint32_t)tmp; } /* Use near_mvs[0] to store the "best" MV */ diff --git a/libs/libvpx/vp8/common/generic/systemdependent.c b/libs/libvpx/vp8/common/generic/systemdependent.c index 71529bdfd8..58c778aba5 100644 --- a/libs/libvpx/vp8/common/generic/systemdependent.c +++ b/libs/libvpx/vp8/common/generic/systemdependent.c @@ -25,23 +25,19 @@ #include "vp8/common/systemdependent.h" #if CONFIG_MULTITHREAD -#if HAVE_UNISTD_H && !defined(__OS2__) +#if HAVE_UNISTD_H #include #elif defined(_WIN32) #include typedef void(WINAPI *PGNSI)(LPSYSTEM_INFO); -#elif defined(__OS2__) -#define INCL_DOS -#define INCL_DOSSPINLOCK -#include #endif #endif #if CONFIG_MULTITHREAD -static int get_cpu_count() { +static int get_cpu_count(void) { int core_count = 16; -#if HAVE_UNISTD_H && !defined(__OS2__) +#if HAVE_UNISTD_H #if defined(_SC_NPROCESSORS_ONLN) core_count = (int)sysconf(_SC_NPROCESSORS_ONLN); #elif defined(_SC_NPROC_ONLN) @@ -49,38 +45,13 @@ static int get_cpu_count() { #endif #elif defined(_WIN32) { -#if _WIN32_WINNT >= 0x0501 +#if _WIN32_WINNT < 0x0501 +#error _WIN32_WINNT must target Windows XP or newer. +#endif SYSTEM_INFO sysinfo; GetNativeSystemInfo(&sysinfo); -#else - PGNSI pGNSI; - SYSTEM_INFO sysinfo; - - /* Call GetNativeSystemInfo if supported or - * GetSystemInfo otherwise. */ - - pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), - "GetNativeSystemInfo"); - if (pGNSI != NULL) - pGNSI(&sysinfo); - else - GetSystemInfo(&sysinfo); -#endif - core_count = (int)sysinfo.dwNumberOfProcessors; } -#elif defined(__OS2__) - { - ULONG proc_id; - ULONG status; - - core_count = 0; - for (proc_id = 1;; ++proc_id) { - if (DosGetProcessorStatus(proc_id, &status)) break; - - if (status == PROC_ONLINE) core_count++; - } - } #else /* other platforms */ #endif @@ -92,20 +63,7 @@ static int get_cpu_count() { void vp8_machine_specific_config(VP8_COMMON *ctx) { #if CONFIG_MULTITHREAD ctx->processor_core_count = get_cpu_count(); -#endif /* CONFIG_MULTITHREAD */ - -#if VPX_ARCH_ARM - ctx->cpu_caps = arm_cpu_caps(); -#elif VPX_ARCH_X86 || VPX_ARCH_X86_64 - ctx->cpu_caps = x86_simd_caps(); -#elif VPX_ARCH_PPC - ctx->cpu_caps = ppc_simd_caps(); -#elif VPX_ARCH_MIPS - ctx->cpu_caps = mips_cpu_caps(); -#elif VPX_ARCH_LOONGARCH - ctx->cpu_caps = loongarch_cpu_caps(); #else - // generic-gnu targets. - ctx->cpu_caps = 0; -#endif + (void)ctx; +#endif /* CONFIG_MULTITHREAD */ } diff --git a/libs/libvpx/vp8/common/loongarch/loopfilter_filters_lsx.c b/libs/libvpx/vp8/common/loongarch/loopfilter_filters_lsx.c index 79c3ea6dbb..44c8389bd5 100644 --- a/libs/libvpx/vp8/common/loongarch/loopfilter_filters_lsx.c +++ b/libs/libvpx/vp8/common/loongarch/loopfilter_filters_lsx.c @@ -9,6 +9,8 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include + #include "./vp8_rtcd.h" #include "vp8/common/loopfilter.h" #include "vpx_util/loongson_intrinsics.h" @@ -741,3 +743,170 @@ void vp8_loop_filter_bv_lsx(uint8_t *src_y, uint8_t *src_u, uint8_t *src_v, *lpf_info_ptr->hev_thr); } } + +/* The simple filter compares 2 * |p0 - q0| + |p1 - q1| / 2 against blimit. + * That sum does not fit in 8 bits, so evaluate the equivalent condition + * |p0 - q0| <= (blimit - |p1 - q1| / 2) / 2, which also rejects the edge when + * |p1 - q1| / 2 alone exceeds blimit. Saturating byte adds would clamp the sum + * at 255, making the comparison true for every edge at blimit 255. */ +#define VP8_LPF_SIMPLE_MASK(p1, p0, q0, q1, blimit, mask) \ + do { \ + __m128i abs_p1_q1, abs_p0_q0, limit; \ + \ + abs_p1_q1 = __lsx_vabsd_bu(p1, q1); \ + abs_p0_q0 = __lsx_vabsd_bu(p0, q0); \ + limit = __lsx_vreplgr2vr_b((blimit)[0]); \ + abs_p1_q1 = __lsx_vsrli_b(abs_p1_q1, 1); \ + mask = __lsx_vand_v( \ + __lsx_vsle_bu(abs_p1_q1, limit), \ + __lsx_vsle_bu(abs_p0_q0, \ + __lsx_vsrli_b(__lsx_vssub_bu(limit, abs_p1_q1), 1))); \ + } while (0) + +#define VP8_LPF_SIMPLE_FILT(p1, p0, q0, q1, mask) \ + do { \ + __m128i p1_m, p0_m, q0_m, q1_m, filt, q0_sub_p0, t1, t2; \ + const __m128i cnst4b = __lsx_vldi(4); \ + const __m128i cnst3b = __lsx_vldi(3); \ + \ + p1_m = __lsx_vxori_b(p1, 0x80); \ + p0_m = __lsx_vxori_b(p0, 0x80); \ + q0_m = __lsx_vxori_b(q0, 0x80); \ + q1_m = __lsx_vxori_b(q1, 0x80); \ + \ + /* clamp8(p1 - q1) + 3 * (q0 - p0) */ \ + filt = __lsx_vssub_b(p1_m, q1_m); \ + q0_sub_p0 = __lsx_vssub_b(q0_m, p0_m); \ + filt = __lsx_vsadd_b(filt, q0_sub_p0); \ + filt = __lsx_vsadd_b(filt, q0_sub_p0); \ + filt = __lsx_vsadd_b(filt, q0_sub_p0); \ + filt = __lsx_vand_v(filt, mask); \ + \ + t1 = __lsx_vsadd_b(filt, cnst4b); \ + t1 = __lsx_vsra_b(t1, cnst3b); \ + t2 = __lsx_vsadd_b(filt, cnst3b); \ + t2 = __lsx_vsra_b(t2, cnst3b); \ + \ + q0 = __lsx_vxori_b(__lsx_vssub_b(q0_m, t1), 0x80); \ + p0 = __lsx_vxori_b(__lsx_vsadd_b(p0_m, t2), 0x80); \ + } while (0) + +void vp8_loop_filter_simple_horizontal_edge_lsx(unsigned char *y_ptr, + int y_stride, + const unsigned char *blimit) { + __m128i p1, p0, q0, q1, mask; + + p1 = __lsx_vld(y_ptr - 2 * y_stride, 0); + p0 = __lsx_vld(y_ptr - y_stride, 0); + q0 = __lsx_vld(y_ptr, 0); + q1 = __lsx_vld(y_ptr + y_stride, 0); + + VP8_LPF_SIMPLE_MASK(p1, p0, q0, q1, blimit, mask); + VP8_LPF_SIMPLE_FILT(p1, p0, q0, q1, mask); + + __lsx_vst(p0, y_ptr - y_stride, 0); + __lsx_vst(q0, y_ptr, 0); +} + +static const uint8_t k_simple_pick[4][16] = { + { 0, 4, 8, 12, 16, 20, 24, 28, 0, 0, 0, 0, 0, 0, 0, 0 }, /* p1 */ + { 1, 5, 9, 13, 17, 21, 25, 29, 0, 0, 0, 0, 0, 0, 0, 0 }, /* p0 */ + { 2, 6, 10, 14, 18, 22, 26, 30, 0, 0, 0, 0, 0, 0, 0, 0 }, /* q0 */ + { 3, 7, 11, 15, 19, 23, 27, 31, 0, 0, 0, 0, 0, 0, 0, 0 }, /* q1 */ +}; + +#define VP8_LPF_SIMPLE_GATHER(dst, idx, w0, w1, w2, w3) \ + do { \ + __m128i lo = __lsx_vshuf_b(w1, w0, idx); \ + __m128i hi = __lsx_vshuf_b(w3, w2, idx); \ + dst = __lsx_vilvl_d(hi, lo); \ + } while (0) + +#define VP8_LPF_SIMPLE_LOAD_ROW(dst, ptr, lane) \ + do { \ + uint32_t w_; \ + memcpy(&w_, (ptr), 4); \ + dst = __lsx_vinsgr2vr_w(dst, w_, lane); \ + } while (0) + +#define VP8_LPF_SIMPLE_STORE_ROW(vec, ptr, lane) \ + do { \ + __lsx_vstelm_h(vec, (ptr), 0, lane); \ + } while (0) + +void vp8_loop_filter_simple_vertical_edge_lsx(unsigned char *y_ptr, + int y_stride, + const unsigned char *blimit) { + const __m128i idx_p1 = __lsx_vld(k_simple_pick[0], 0); + const __m128i idx_p0 = __lsx_vld(k_simple_pick[1], 0); + const __m128i idx_q0 = __lsx_vld(k_simple_pick[2], 0); + const __m128i idx_q1 = __lsx_vld(k_simple_pick[3], 0); + const __m128i zero = __lsx_vldi(0); + const uint8_t *src = y_ptr - 2; + __m128i w0, w1, w2, w3, p1, p0, q0, q1, mask, t_lo, t_hi; + + w0 = zero; + VP8_LPF_SIMPLE_LOAD_ROW(w0, src + 0 * y_stride, 0); + VP8_LPF_SIMPLE_LOAD_ROW(w0, src + 1 * y_stride, 1); + VP8_LPF_SIMPLE_LOAD_ROW(w0, src + 2 * y_stride, 2); + VP8_LPF_SIMPLE_LOAD_ROW(w0, src + 3 * y_stride, 3); + w1 = zero; + VP8_LPF_SIMPLE_LOAD_ROW(w1, src + 4 * y_stride, 0); + VP8_LPF_SIMPLE_LOAD_ROW(w1, src + 5 * y_stride, 1); + VP8_LPF_SIMPLE_LOAD_ROW(w1, src + 6 * y_stride, 2); + VP8_LPF_SIMPLE_LOAD_ROW(w1, src + 7 * y_stride, 3); + w2 = zero; + VP8_LPF_SIMPLE_LOAD_ROW(w2, src + 8 * y_stride, 0); + VP8_LPF_SIMPLE_LOAD_ROW(w2, src + 9 * y_stride, 1); + VP8_LPF_SIMPLE_LOAD_ROW(w2, src + 10 * y_stride, 2); + VP8_LPF_SIMPLE_LOAD_ROW(w2, src + 11 * y_stride, 3); + w3 = zero; + VP8_LPF_SIMPLE_LOAD_ROW(w3, src + 12 * y_stride, 0); + VP8_LPF_SIMPLE_LOAD_ROW(w3, src + 13 * y_stride, 1); + VP8_LPF_SIMPLE_LOAD_ROW(w3, src + 14 * y_stride, 2); + VP8_LPF_SIMPLE_LOAD_ROW(w3, src + 15 * y_stride, 3); + + VP8_LPF_SIMPLE_GATHER(p1, idx_p1, w0, w1, w2, w3); + VP8_LPF_SIMPLE_GATHER(p0, idx_p0, w0, w1, w2, w3); + VP8_LPF_SIMPLE_GATHER(q0, idx_q0, w0, w1, w2, w3); + VP8_LPF_SIMPLE_GATHER(q1, idx_q1, w0, w1, w2, w3); + + VP8_LPF_SIMPLE_MASK(p1, p0, q0, q1, blimit, mask); + VP8_LPF_SIMPLE_FILT(p1, p0, q0, q1, mask); + + t_lo = __lsx_vilvl_b(q0, p0); + t_hi = __lsx_vilvh_b(q0, p0); + VP8_LPF_SIMPLE_STORE_ROW(t_lo, y_ptr - 1 + 0 * y_stride, 0); + VP8_LPF_SIMPLE_STORE_ROW(t_lo, y_ptr - 1 + 1 * y_stride, 1); + VP8_LPF_SIMPLE_STORE_ROW(t_lo, y_ptr - 1 + 2 * y_stride, 2); + VP8_LPF_SIMPLE_STORE_ROW(t_lo, y_ptr - 1 + 3 * y_stride, 3); + VP8_LPF_SIMPLE_STORE_ROW(t_lo, y_ptr - 1 + 4 * y_stride, 4); + VP8_LPF_SIMPLE_STORE_ROW(t_lo, y_ptr - 1 + 5 * y_stride, 5); + VP8_LPF_SIMPLE_STORE_ROW(t_lo, y_ptr - 1 + 6 * y_stride, 6); + VP8_LPF_SIMPLE_STORE_ROW(t_lo, y_ptr - 1 + 7 * y_stride, 7); + VP8_LPF_SIMPLE_STORE_ROW(t_hi, y_ptr - 1 + 8 * y_stride, 0); + VP8_LPF_SIMPLE_STORE_ROW(t_hi, y_ptr - 1 + 9 * y_stride, 1); + VP8_LPF_SIMPLE_STORE_ROW(t_hi, y_ptr - 1 + 10 * y_stride, 2); + VP8_LPF_SIMPLE_STORE_ROW(t_hi, y_ptr - 1 + 11 * y_stride, 3); + VP8_LPF_SIMPLE_STORE_ROW(t_hi, y_ptr - 1 + 12 * y_stride, 4); + VP8_LPF_SIMPLE_STORE_ROW(t_hi, y_ptr - 1 + 13 * y_stride, 5); + VP8_LPF_SIMPLE_STORE_ROW(t_hi, y_ptr - 1 + 14 * y_stride, 6); + VP8_LPF_SIMPLE_STORE_ROW(t_hi, y_ptr - 1 + 15 * y_stride, 7); +} + +void vp8_loop_filter_bvs_lsx(unsigned char *y_ptr, int y_stride, + const unsigned char *blimit) { + vp8_loop_filter_simple_vertical_edge_lsx(y_ptr + 4, y_stride, blimit); + vp8_loop_filter_simple_vertical_edge_lsx(y_ptr + 8, y_stride, blimit); + vp8_loop_filter_simple_vertical_edge_lsx(y_ptr + 12, y_stride, blimit); +} + +void vp8_loop_filter_bhs_lsx(unsigned char *y_ptr, int y_stride, + const unsigned char *blimit) { + vp8_loop_filter_simple_horizontal_edge_lsx(y_ptr + 4 * y_stride, y_stride, + blimit); + vp8_loop_filter_simple_horizontal_edge_lsx(y_ptr + 8 * y_stride, y_stride, + blimit); + vp8_loop_filter_simple_horizontal_edge_lsx(y_ptr + 12 * y_stride, y_stride, + blimit); +} diff --git a/libs/libvpx/vp8/common/loongarch/sixtap_filter_lsx.c b/libs/libvpx/vp8/common/loongarch/sixtap_filter_lsx.c index cd7ba54746..2a6ec7fdc7 100644 --- a/libs/libvpx/vp8/common/loongarch/sixtap_filter_lsx.c +++ b/libs/libvpx/vp8/common/loongarch/sixtap_filter_lsx.c @@ -1645,9 +1645,6 @@ typedef void (*PVp8SixtapPredictFunc2)(uint8_t *RESTRICT src, void vp8_sixtap_predict4x4_lsx(uint8_t *RESTRICT src, int32_t src_stride, int32_t xoffset, int32_t yoffset, uint8_t *RESTRICT dst, int32_t dst_stride) { - const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; - const int8_t *v_filter = vp8_subpel_filters_lsx[yoffset - 1]; - static PVp8SixtapPredictFunc1 Predict4x4Funcs1[4] = { common_hv_6ht_6vt_4w_lsx, common_hv_6ht_4vt_4w_lsx, @@ -1662,6 +1659,8 @@ void vp8_sixtap_predict4x4_lsx(uint8_t *RESTRICT src, int32_t src_stride, if (yoffset < 8 && xoffset < 8) { if (yoffset) { if (xoffset) { + const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; + const int8_t *v_filter = vp8_subpel_filters_lsx[yoffset - 1]; switch (xoffset & 1) { case 0: switch (yoffset & 1) { @@ -1691,6 +1690,7 @@ void vp8_sixtap_predict4x4_lsx(uint8_t *RESTRICT src, int32_t src_stride, break; } } else { + const int8_t *v_filter = vp8_subpel_filters_lsx[yoffset - 1]; switch (yoffset & 1) { case 0: Predict4x4Funcs2[0](src, src_stride, dst, dst_stride, v_filter, 4); @@ -1706,34 +1706,39 @@ void vp8_sixtap_predict4x4_lsx(uint8_t *RESTRICT src, int32_t src_stride, switch (xoffset) { case 0: { __m128i tp0; - tp0 = __lsx_vinsgr2vr_w(tp0, src, 0); - src += src_stride; - tp0 = __lsx_vinsgr2vr_w(tp0, src, 0); - src += src_stride; - tp0 = __lsx_vinsgr2vr_w(tp0, src, 0); - src += src_stride; - tp0 = __lsx_vinsgr2vr_w(tp0, src, 0); + tp0 = __lsx_vldrepl_w(src, 0); + src += src_stride; __lsx_vstelm_w(tp0, dst, 0, 0); dst += dst_stride; - __lsx_vstelm_w(tp0, dst, 0, 1); + tp0 = __lsx_vldrepl_w(src, 0); + src += src_stride; + __lsx_vstelm_w(tp0, dst, 0, 0); dst += dst_stride; - __lsx_vstelm_w(tp0, dst, 0, 2); + tp0 = __lsx_vldrepl_w(src, 0); + src += src_stride; + __lsx_vstelm_w(tp0, dst, 0, 0); dst += dst_stride; - __lsx_vstelm_w(tp0, dst, 0, 3); + tp0 = __lsx_vldrepl_w(src, 0); + __lsx_vstelm_w(tp0, dst, 0, 0); + break; } case 2: case 4: - case 6: + case 6: { + const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; Predict4x4Funcs2[2](src, src_stride, dst, dst_stride, h_filter, 4); break; + } } switch (xoffset & 1) { - case 1: + case 1: { + const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; Predict4x4Funcs2[3](src, src_stride, dst, dst_stride, h_filter + 1, 4); break; + } } } } @@ -1742,9 +1747,6 @@ void vp8_sixtap_predict4x4_lsx(uint8_t *RESTRICT src, int32_t src_stride, void vp8_sixtap_predict8x8_lsx(uint8_t *RESTRICT src, int32_t src_stride, int32_t xoffset, int32_t yoffset, uint8_t *RESTRICT dst, int32_t dst_stride) { - const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; - const int8_t *v_filter = vp8_subpel_filters_lsx[yoffset - 1]; - static PVp8SixtapPredictFunc1 Predict8x8Funcs1[4] = { common_hv_6ht_6vt_8w_lsx, common_hv_6ht_4vt_8w_lsx, @@ -1760,6 +1762,8 @@ void vp8_sixtap_predict8x8_lsx(uint8_t *RESTRICT src, int32_t src_stride, if (yoffset < 8 && xoffset < 8) { if (yoffset) { if (xoffset) { + const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; + const int8_t *v_filter = vp8_subpel_filters_lsx[yoffset - 1]; switch (xoffset & 1) { case 0: switch (yoffset & 1) { @@ -1790,6 +1794,7 @@ void vp8_sixtap_predict8x8_lsx(uint8_t *RESTRICT src, int32_t src_stride, break; } } else { + const int8_t *v_filter = vp8_subpel_filters_lsx[yoffset - 1]; switch (yoffset & 1) { case 0: Predict8x8Funcs2[0](src, src_stride, dst, dst_stride, v_filter, 8); @@ -1803,18 +1808,22 @@ void vp8_sixtap_predict8x8_lsx(uint8_t *RESTRICT src, int32_t src_stride, } } else { switch (xoffset & 1) { - case 1: + case 1: { + const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; Predict8x8Funcs2[3](src, src_stride, dst, dst_stride, h_filter + 1, 8); break; + } } switch (xoffset) { case 0: vp8_copy_mem8x8(src, src_stride, dst, dst_stride); break; case 2: case 4: - case 6: + case 6: { + const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; Predict8x8Funcs2[2](src, src_stride, dst, dst_stride, h_filter, 8); break; + } } } } @@ -1823,9 +1832,6 @@ void vp8_sixtap_predict8x8_lsx(uint8_t *RESTRICT src, int32_t src_stride, void vp8_sixtap_predict16x16_lsx(uint8_t *RESTRICT src, int32_t src_stride, int32_t xoffset, int32_t yoffset, uint8_t *RESTRICT dst, int32_t dst_stride) { - const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; - const int8_t *v_filter = vp8_subpel_filters_lsx[yoffset - 1]; - static PVp8SixtapPredictFunc1 Predict16x16Funcs1[4] = { common_hv_6ht_6vt_16w_lsx, common_hv_6ht_4vt_16w_lsx, @@ -1841,6 +1847,8 @@ void vp8_sixtap_predict16x16_lsx(uint8_t *RESTRICT src, int32_t src_stride, if (yoffset < 8 && xoffset < 8) { if (yoffset) { if (xoffset) { + const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; + const int8_t *v_filter = vp8_subpel_filters_lsx[yoffset - 1]; switch (xoffset & 1) { case 0: switch (yoffset & 1) { @@ -1865,12 +1873,13 @@ void vp8_sixtap_predict16x16_lsx(uint8_t *RESTRICT src, int32_t src_stride, case 1: Predict16x16Funcs1[3](src, src_stride, dst, dst_stride, - h_filter, v_filter + 1, 16); + h_filter + 1, v_filter + 1, 16); break; } break; } } else { + const int8_t *v_filter = vp8_subpel_filters_lsx[yoffset - 1]; switch (yoffset & 1) { case 0: Predict16x16Funcs2[0](src, src_stride, dst, dst_stride, v_filter, @@ -1885,18 +1894,22 @@ void vp8_sixtap_predict16x16_lsx(uint8_t *RESTRICT src, int32_t src_stride, } } else { switch (xoffset & 1) { - case 1: + case 1: { + const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; Predict16x16Funcs2[3](src, src_stride, dst, dst_stride, h_filter + 1, 16); break; + } } switch (xoffset) { case 0: vp8_copy_mem16x16(src, src_stride, dst, dst_stride); break; case 2: case 4: - case 6: + case 6: { + const int8_t *h_filter = vp8_subpel_filters_lsx[xoffset - 1]; Predict16x16Funcs2[2](src, src_stride, dst, dst_stride, h_filter, 16); break; + } } } } diff --git a/libs/libvpx/vp8/common/mfqe.c b/libs/libvpx/vp8/common/mfqe.c index 1fe7363f17..3d801e72e2 100644 --- a/libs/libvpx/vp8/common/mfqe.c +++ b/libs/libvpx/vp8/common/mfqe.c @@ -212,7 +212,7 @@ static int qualify_inter_mb(const MODE_INFO *mode_info_context, int *map) { { 0, 1, 4, 5 }, { 2, 3, 6, 7 }, { 8, 9, 12, 13 }, { 10, 11, 14, 15 } }; int i, j; - vp8_zero(*map); + vp8_zero_array(map, 4); for (i = 0; i < 4; ++i) { map[i] = 1; for (j = 0; j < 4 && map[j]; ++j) { diff --git a/libs/libvpx/vp8/common/mips/dspr2/filter_dspr2.c b/libs/libvpx/vp8/common/mips/dspr2/filter_dspr2.c index e46827b0e4..b9da52084d 100644 --- a/libs/libvpx/vp8/common/mips/dspr2/filter_dspr2.c +++ b/libs/libvpx/vp8/common/mips/dspr2/filter_dspr2.c @@ -816,8 +816,8 @@ void vp8_filter_block2d_first_pass16_0(unsigned char *RESTRICT src_ptr, : [Temp1] "=&r"(Temp1), [Temp2] "=&r"(Temp2), [Temp3] "=&r"(Temp3), [Temp4] "=&r"(Temp4), [src_ptr] "+r"(src_ptr) - : [src_pixels_per_line] "r"(src_pixels_per_line), - [output_ptr] "r"(output_ptr)); + : [src_pixels_per_line] "r"(src_pixels_per_line), [output_ptr] "r"( + output_ptr)); __asm__ __volatile__( "ulw %[Temp1], 0(%[src_ptr]) \n\t" @@ -832,8 +832,8 @@ void vp8_filter_block2d_first_pass16_0(unsigned char *RESTRICT src_ptr, : [Temp1] "=&r"(Temp1), [Temp2] "=&r"(Temp2), [Temp3] "=&r"(Temp3), [Temp4] "=&r"(Temp4), [src_ptr] "+r"(src_ptr) - : [src_pixels_per_line] "r"(src_pixels_per_line), - [output_ptr] "r"(output_ptr)); + : [src_pixels_per_line] "r"(src_pixels_per_line), [output_ptr] "r"( + output_ptr)); __asm__ __volatile__( "ulw %[Temp1], 0(%[src_ptr]) \n\t" @@ -848,8 +848,8 @@ void vp8_filter_block2d_first_pass16_0(unsigned char *RESTRICT src_ptr, : [Temp1] "=&r"(Temp1), [Temp2] "=&r"(Temp2), [Temp3] "=&r"(Temp3), [Temp4] "=&r"(Temp4), [src_ptr] "+r"(src_ptr) - : [src_pixels_per_line] "r"(src_pixels_per_line), - [output_ptr] "r"(output_ptr)); + : [src_pixels_per_line] "r"(src_pixels_per_line), [output_ptr] "r"( + output_ptr)); output_ptr += 48; } diff --git a/libs/libvpx/vp8/common/mips/msa/sixtap_filter_msa.c b/libs/libvpx/vp8/common/mips/msa/sixtap_filter_msa.c index b0affcff01..3a1bb7cd57 100644 --- a/libs/libvpx/vp8/common/mips/msa/sixtap_filter_msa.c +++ b/libs/libvpx/vp8/common/mips/msa/sixtap_filter_msa.c @@ -35,101 +35,134 @@ static const uint8_t vp8_mc_filt_mask_arr[16 * 3] = { #define HORIZ_6TAP_FILT(src0, src1, mask0, mask1, mask2, filt_h0, filt_h1, \ filt_h2) \ ({ \ - v16i8 vec0_m, vec1_m, vec2_m; \ - v8i16 hz_out_m; \ + v16i8 _6tap_vec0_m, _6tap_vec1_m, _6tap_vec2_m; \ + v8i16 _6tap_out_m; \ \ VSHF_B3_SB(src0, src1, src0, src1, src0, src1, mask0, mask1, mask2, \ - vec0_m, vec1_m, vec2_m); \ - hz_out_m = \ - DPADD_SH3_SH(vec0_m, vec1_m, vec2_m, filt_h0, filt_h1, filt_h2); \ + _6tap_vec0_m, _6tap_vec1_m, _6tap_vec2_m); \ + _6tap_out_m = DPADD_SH3_SH(_6tap_vec0_m, _6tap_vec1_m, _6tap_vec2_m, \ + filt_h0, filt_h1, filt_h2); \ \ - hz_out_m = __msa_srari_h(hz_out_m, VP8_FILTER_SHIFT); \ - hz_out_m = __msa_sat_s_h(hz_out_m, 7); \ + _6tap_out_m = __msa_srari_h(_6tap_out_m, VP8_FILTER_SHIFT); \ + _6tap_out_m = __msa_sat_s_h(_6tap_out_m, 7); \ \ - hz_out_m; \ + _6tap_out_m; \ }) #define HORIZ_6TAP_4WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, \ mask2, filt0, filt1, filt2, out0, out1) \ { \ - v16i8 vec0_m, vec1_m, vec2_m, vec3_m, vec4_m, vec5_m; \ + v16i8 _6tap_4wid_vec0_m, _6tap_4wid_vec1_m, _6tap_4wid_vec2_m, \ + _6tap_4wid_vec3_m, _6tap_4wid_vec4_m, _6tap_4wid_vec5_m; \ \ - VSHF_B2_SB(src0, src1, src2, src3, mask0, mask0, vec0_m, vec1_m); \ - DOTP_SB2_SH(vec0_m, vec1_m, filt0, filt0, out0, out1); \ - VSHF_B2_SB(src0, src1, src2, src3, mask1, mask1, vec2_m, vec3_m); \ - DPADD_SB2_SH(vec2_m, vec3_m, filt1, filt1, out0, out1); \ - VSHF_B2_SB(src0, src1, src2, src3, mask2, mask2, vec4_m, vec5_m); \ - DPADD_SB2_SH(vec4_m, vec5_m, filt2, filt2, out0, out1); \ + VSHF_B2_SB(src0, src1, src2, src3, mask0, mask0, _6tap_4wid_vec0_m, \ + _6tap_4wid_vec1_m); \ + DOTP_SB2_SH(_6tap_4wid_vec0_m, _6tap_4wid_vec1_m, filt0, filt0, out0, \ + out1); \ + VSHF_B2_SB(src0, src1, src2, src3, mask1, mask1, _6tap_4wid_vec2_m, \ + _6tap_4wid_vec3_m); \ + DPADD_SB2_SH(_6tap_4wid_vec2_m, _6tap_4wid_vec3_m, filt1, filt1, out0, \ + out1); \ + VSHF_B2_SB(src0, src1, src2, src3, mask2, mask2, _6tap_4wid_vec4_m, \ + _6tap_4wid_vec5_m); \ + DPADD_SB2_SH(_6tap_4wid_vec4_m, _6tap_4wid_vec5_m, filt2, filt2, out0, \ + out1); \ } -#define HORIZ_6TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, \ - mask2, filt0, filt1, filt2, out0, out1, \ - out2, out3) \ - { \ - v16i8 vec0_m, vec1_m, vec2_m, vec3_m, vec4_m, vec5_m, vec6_m, vec7_m; \ - \ - VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0_m, vec1_m); \ - VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec2_m, vec3_m); \ - DOTP_SB4_SH(vec0_m, vec1_m, vec2_m, vec3_m, filt0, filt0, filt0, filt0, \ - out0, out1, out2, out3); \ - VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0_m, vec1_m); \ - VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2_m, vec3_m); \ - VSHF_B2_SB(src0, src0, src1, src1, mask2, mask2, vec4_m, vec5_m); \ - VSHF_B2_SB(src2, src2, src3, src3, mask2, mask2, vec6_m, vec7_m); \ - DPADD_SB4_SH(vec0_m, vec1_m, vec2_m, vec3_m, filt1, filt1, filt1, filt1, \ - out0, out1, out2, out3); \ - DPADD_SB4_SH(vec4_m, vec5_m, vec6_m, vec7_m, filt2, filt2, filt2, filt2, \ - out0, out1, out2, out3); \ +#define HORIZ_6TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, \ + mask2, filt0, filt1, filt2, out0, out1, \ + out2, out3) \ + { \ + v16i8 _6tap_8wid_vec0_m, _6tap_8wid_vec1_m, _6tap_8wid_vec2_m, \ + _6tap_8wid_vec3_m, _6tap_8wid_vec4_m, _6tap_8wid_vec5_m, \ + _6tap_8wid_vec6_m, _6tap_8wid_vec7_m; \ + \ + VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, _6tap_8wid_vec0_m, \ + _6tap_8wid_vec1_m); \ + VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, _6tap_8wid_vec2_m, \ + _6tap_8wid_vec3_m); \ + DOTP_SB4_SH(_6tap_8wid_vec0_m, _6tap_8wid_vec1_m, _6tap_8wid_vec2_m, \ + _6tap_8wid_vec3_m, filt0, filt0, filt0, filt0, out0, out1, \ + out2, out3); \ + VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, _6tap_8wid_vec0_m, \ + _6tap_8wid_vec1_m); \ + VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, _6tap_8wid_vec2_m, \ + _6tap_8wid_vec3_m); \ + VSHF_B2_SB(src0, src0, src1, src1, mask2, mask2, _6tap_8wid_vec4_m, \ + _6tap_8wid_vec5_m); \ + VSHF_B2_SB(src2, src2, src3, src3, mask2, mask2, _6tap_8wid_vec6_m, \ + _6tap_8wid_vec7_m); \ + DPADD_SB4_SH(_6tap_8wid_vec0_m, _6tap_8wid_vec1_m, _6tap_8wid_vec2_m, \ + _6tap_8wid_vec3_m, filt1, filt1, filt1, filt1, out0, out1, \ + out2, out3); \ + DPADD_SB4_SH(_6tap_8wid_vec4_m, _6tap_8wid_vec5_m, _6tap_8wid_vec6_m, \ + _6tap_8wid_vec7_m, filt2, filt2, filt2, filt2, out0, out1, \ + out2, out3); \ } -#define FILT_4TAP_DPADD_S_H(vec0, vec1, filt0, filt1) \ - ({ \ - v8i16 tmp0; \ - \ - tmp0 = __msa_dotp_s_h((v16i8)vec0, (v16i8)filt0); \ - tmp0 = __msa_dpadd_s_h(tmp0, (v16i8)vec1, (v16i8)filt1); \ - \ - tmp0; \ - }) - -#define HORIZ_4TAP_FILT(src0, src1, mask0, mask1, filt_h0, filt_h1) \ +#define FILT_4TAP_DPADD_S_H(vec0, vec1, filt0, filt1) \ ({ \ - v16i8 vec0_m, vec1_m; \ - v8i16 hz_out_m; \ + v8i16 _4tap_dpadd_tmp0; \ \ - VSHF_B2_SB(src0, src1, src0, src1, mask0, mask1, vec0_m, vec1_m); \ - hz_out_m = FILT_4TAP_DPADD_S_H(vec0_m, vec1_m, filt_h0, filt_h1); \ + _4tap_dpadd_tmp0 = __msa_dotp_s_h((v16i8)vec0, (v16i8)filt0); \ + _4tap_dpadd_tmp0 = \ + __msa_dpadd_s_h(_4tap_dpadd_tmp0, (v16i8)vec1, (v16i8)filt1); \ \ - hz_out_m = __msa_srari_h(hz_out_m, VP8_FILTER_SHIFT); \ - hz_out_m = __msa_sat_s_h(hz_out_m, 7); \ - \ - hz_out_m; \ + _4tap_dpadd_tmp0; \ }) -#define HORIZ_4TAP_4WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, \ - filt0, filt1, out0, out1) \ - { \ - v16i8 vec0_m, vec1_m, vec2_m, vec3_m; \ - \ - VSHF_B2_SB(src0, src1, src2, src3, mask0, mask0, vec0_m, vec1_m); \ - DOTP_SB2_SH(vec0_m, vec1_m, filt0, filt0, out0, out1); \ - VSHF_B2_SB(src0, src1, src2, src3, mask1, mask1, vec2_m, vec3_m); \ - DPADD_SB2_SH(vec2_m, vec3_m, filt1, filt1, out0, out1); \ +#define HORIZ_4TAP_FILT(src0, src1, mask0, mask1, filt_h0, filt_h1) \ + ({ \ + v16i8 _4tap_vec0_m, _4tap_vec1_m; \ + v8i16 _4tap_out_m; \ + \ + VSHF_B2_SB(src0, src1, src0, src1, mask0, mask1, _4tap_vec0_m, \ + _4tap_vec1_m); \ + _4tap_out_m = \ + FILT_4TAP_DPADD_S_H(_4tap_vec0_m, _4tap_vec1_m, filt_h0, filt_h1); \ + \ + _4tap_out_m = __msa_srari_h(_4tap_out_m, VP8_FILTER_SHIFT); \ + _4tap_out_m = __msa_sat_s_h(_4tap_out_m, 7); \ + \ + _4tap_out_m; \ + }) + +#define HORIZ_4TAP_4WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, \ + filt0, filt1, out0, out1) \ + { \ + v16i8 _4tap_4wid_vec0_m, _4tap_4wid_vec1_m, _4tap_4wid_vec2_m, \ + _4tap_4wid_vec3_m; \ + \ + VSHF_B2_SB(src0, src1, src2, src3, mask0, mask0, _4tap_4wid_vec0_m, \ + _4tap_4wid_vec1_m); \ + DOTP_SB2_SH(_4tap_4wid_vec0_m, _4tap_4wid_vec1_m, filt0, filt0, out0, \ + out1); \ + VSHF_B2_SB(src0, src1, src2, src3, mask1, mask1, _4tap_4wid_vec2_m, \ + _4tap_4wid_vec3_m); \ + DPADD_SB2_SH(_4tap_4wid_vec2_m, _4tap_4wid_vec3_m, filt1, filt1, out0, \ + out1); \ } -#define HORIZ_4TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, \ - filt0, filt1, out0, out1, out2, out3) \ - { \ - v16i8 vec0_m, vec1_m, vec2_m, vec3_m; \ - \ - VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, vec0_m, vec1_m); \ - VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, vec2_m, vec3_m); \ - DOTP_SB4_SH(vec0_m, vec1_m, vec2_m, vec3_m, filt0, filt0, filt0, filt0, \ - out0, out1, out2, out3); \ - VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, vec0_m, vec1_m); \ - VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, vec2_m, vec3_m); \ - DPADD_SB4_SH(vec0_m, vec1_m, vec2_m, vec3_m, filt1, filt1, filt1, filt1, \ - out0, out1, out2, out3); \ +#define HORIZ_4TAP_8WID_4VECS_FILT(src0, src1, src2, src3, mask0, mask1, \ + filt0, filt1, out0, out1, out2, out3) \ + { \ + v16i8 _4tap_8wid_vec0_m, _4tap_8wid_vec1_m, _4tap_8wid_vec2_m, \ + _4tap_8wid_vec3_m; \ + \ + VSHF_B2_SB(src0, src0, src1, src1, mask0, mask0, _4tap_8wid_vec0_m, \ + _4tap_8wid_vec1_m); \ + VSHF_B2_SB(src2, src2, src3, src3, mask0, mask0, _4tap_8wid_vec2_m, \ + _4tap_8wid_vec3_m); \ + DOTP_SB4_SH(_4tap_8wid_vec0_m, _4tap_8wid_vec1_m, _4tap_8wid_vec2_m, \ + _4tap_8wid_vec3_m, filt0, filt0, filt0, filt0, out0, out1, \ + out2, out3); \ + VSHF_B2_SB(src0, src0, src1, src1, mask1, mask1, _4tap_8wid_vec0_m, \ + _4tap_8wid_vec1_m); \ + VSHF_B2_SB(src2, src2, src3, src3, mask1, mask1, _4tap_8wid_vec2_m, \ + _4tap_8wid_vec3_m); \ + DPADD_SB4_SH(_4tap_8wid_vec0_m, _4tap_8wid_vec1_m, _4tap_8wid_vec2_m, \ + _4tap_8wid_vec3_m, filt1, filt1, filt1, filt1, out0, out1, \ + out2, out3); \ } static void common_hz_6t_4x4_msa(uint8_t *RESTRICT src, int32_t src_stride, diff --git a/libs/libvpx/vp8/common/mips/msa/vp8_macros_msa.h b/libs/libvpx/vp8/common/mips/msa/vp8_macros_msa.h index ddc881a7fc..79f96ce8fa 100644 --- a/libs/libvpx/vp8/common/mips/msa/vp8_macros_msa.h +++ b/libs/libvpx/vp8/common/mips/msa/vp8_macros_msa.h @@ -40,158 +40,160 @@ #define ST_SW(...) ST_W(v4i32, __VA_ARGS__) #if (__mips_isa_rev >= 6) -#define LW(psrc) \ - ({ \ - const uint8_t *psrc_m = (const uint8_t *)(psrc); \ - uint32_t val_m; \ - \ - asm volatile("lw %[val_m], %[psrc_m] \n\t" \ - \ - : [val_m] "=r"(val_m) \ - : [psrc_m] "m"(*psrc_m)); \ - \ - val_m; \ +#define LW(psrc) \ + ({ \ + const uint8_t *lw_psrc_m = (const uint8_t *)(psrc); \ + uint32_t lw_val_m; \ + \ + __asm__ __volatile__("lw %[lw_val_m], %[lw_psrc_m] \n\t" \ + \ + : [lw_val_m] "=r"(lw_val_m) \ + : [lw_psrc_m] "m"(*lw_psrc_m)); \ + \ + lw_val_m; \ }) #if (__mips == 64) -#define LD(psrc) \ - ({ \ - const uint8_t *psrc_m = (const uint8_t *)(psrc); \ - uint64_t val_m = 0; \ - \ - asm volatile("ld %[val_m], %[psrc_m] \n\t" \ - \ - : [val_m] "=r"(val_m) \ - : [psrc_m] "m"(*psrc_m)); \ - \ - val_m; \ +#define LD(psrc) \ + ({ \ + const uint8_t *ld_psrc_m = (const uint8_t *)(psrc); \ + uint64_t ld_val_m = 0; \ + \ + __asm__ __volatile__("ld %[ld_val_m], %[ld_psrc_m] \n\t" \ + \ + : [ld_val_m] "=r"(ld_val_m) \ + : [ld_psrc_m] "m"(*ld_psrc_m)); \ + \ + ld_val_m; \ }) #else // !(__mips == 64) -#define LD(psrc) \ - ({ \ - const uint8_t *psrc_m = (const uint8_t *)(psrc); \ - uint32_t val0_m, val1_m; \ - uint64_t val_m = 0; \ - \ - val0_m = LW(psrc_m); \ - val1_m = LW(psrc_m + 4); \ - \ - val_m = (uint64_t)(val1_m); \ - val_m = (uint64_t)((val_m << 32) & 0xFFFFFFFF00000000); \ - val_m = (uint64_t)(val_m | (uint64_t)val0_m); \ - \ - val_m; \ +#define LD(psrc) \ + ({ \ + const uint8_t *ld_psrc_m = (const uint8_t *)(psrc); \ + uint32_t ld_val0_m, ld_val1_m; \ + uint64_t ld_val_m = 0; \ + \ + ld_val0_m = LW(ld_psrc_m); \ + ld_val1_m = LW(ld_psrc_m + 4); \ + \ + ld_val_m = (uint64_t)(ld_val1_m); \ + ld_val_m = (uint64_t)((ld_val_m << 32) & 0xFFFFFFFF00000000); \ + ld_val_m = (uint64_t)(ld_val_m | (uint64_t)ld_val0_m); \ + \ + ld_val_m; \ }) #endif // (__mips == 64) -#define SH(val, pdst) \ - { \ - uint8_t *pdst_m = (uint8_t *)(pdst); \ - const uint16_t val_m = (val); \ - \ - asm volatile("sh %[val_m], %[pdst_m] \n\t" \ - \ - : [pdst_m] "=m"(*pdst_m) \ - : [val_m] "r"(val_m)); \ +#define SH(val, pdst) \ + { \ + uint8_t *sh_pdst_m = (uint8_t *)(pdst); \ + const uint16_t sh_val_m = (val); \ + \ + __asm__ __volatile__("sh %[sh_val_m], %[sh_pdst_m] \n\t" \ + \ + : [sh_pdst_m] "=m"(*sh_pdst_m) \ + : [sh_val_m] "r"(sh_val_m)); \ } -#define SW(val, pdst) \ - { \ - uint8_t *pdst_m = (uint8_t *)(pdst); \ - const uint32_t val_m = (val); \ - \ - asm volatile("sw %[val_m], %[pdst_m] \n\t" \ - \ - : [pdst_m] "=m"(*pdst_m) \ - : [val_m] "r"(val_m)); \ +#define SW(val, pdst) \ + { \ + uint8_t *sw_pdst_m = (uint8_t *)(pdst); \ + const uint32_t sw_val_m = (val); \ + \ + __asm__ __volatile__("sw %[sw_val_m], %[sw_pdst_m] \n\t" \ + \ + : [sw_pdst_m] "=m"(*sw_pdst_m) \ + : [sw_val_m] "r"(sw_val_m)); \ } -#define SD(val, pdst) \ - { \ - uint8_t *pdst_m = (uint8_t *)(pdst); \ - const uint64_t val_m = (val); \ - \ - asm volatile("sd %[val_m], %[pdst_m] \n\t" \ - \ - : [pdst_m] "=m"(*pdst_m) \ - : [val_m] "r"(val_m)); \ +#define SD(val, pdst) \ + { \ + uint8_t *sd_pdst_m = (uint8_t *)(pdst); \ + const uint64_t sd_val_m = (val); \ + \ + __asm__ __volatile__("sd %[sd_val_m], %[sd_pdst_m] \n\t" \ + \ + : [sd_pdst_m] "=m"(*sd_pdst_m) \ + : [sd_val_m] "r"(sd_val_m)); \ } #else // !(__mips_isa_rev >= 6) -#define LW(psrc) \ - ({ \ - const uint8_t *psrc_m = (const uint8_t *)(psrc); \ - uint32_t val_m; \ - \ - asm volatile("lwr %[val_m], 0(%[psrc_m]) \n\t" \ - "lwl %[val_m], 3(%[psrc_m]) \n\t" \ - : [val_m] "=&r"(val_m) \ - : [psrc_m] "r"(psrc_m)); \ - \ - val_m; \ +#define LW(psrc) \ + ({ \ + const uint8_t *lw_psrc_m = (const uint8_t *)(psrc); \ + uint32_t lw_val_m; \ + \ + __asm__ __volatile__( \ + "lwr %[lw_val_m], 0(%[lw_psrc_m]) \n\t" \ + "lwl %[lw_val_m], 3(%[lw_psrc_m]) \n\t" \ + : [lw_val_m] "=&r"(lw_val_m) \ + : [lw_psrc_m] "r"(lw_psrc_m)); \ + \ + lw_val_m; \ }) #if (__mips == 64) -#define LD(psrc) \ - ({ \ - const uint8_t *psrc_m = (const uint8_t *)(psrc); \ - uint64_t val_m = 0; \ - \ - asm volatile("ldr %[val_m], 0(%[psrc_m]) \n\t" \ - "ldl %[val_m], 7(%[psrc_m]) \n\t" \ - : [val_m] "=&r"(val_m) \ - : [psrc_m] "r"(psrc_m)); \ - \ - val_m; \ +#define LD(psrc) \ + ({ \ + const uint8_t *ld_psrc_m = (const uint8_t *)(psrc); \ + uint64_t ld_val_m = 0; \ + \ + __asm__ __volatile__( \ + "ldr %[ld_val_m], 0(%[ld_psrc_m]) \n\t" \ + "ldl %[ld_val_m], 7(%[ld_psrc_m]) \n\t" \ + : [ld_val_m] "=&r"(ld_val_m) \ + : [ld_psrc_m] "r"(ld_psrc_m)); \ + \ + ld_val_m; \ }) #else // !(__mips == 64) -#define LD(psrc) \ - ({ \ - const uint8_t *psrc_m1 = (const uint8_t *)(psrc); \ - uint32_t val0_m, val1_m; \ - uint64_t val_m = 0; \ - \ - val0_m = LW(psrc_m1); \ - val1_m = LW(psrc_m1 + 4); \ - \ - val_m = (uint64_t)(val1_m); \ - val_m = (uint64_t)((val_m << 32) & 0xFFFFFFFF00000000); \ - val_m = (uint64_t)(val_m | (uint64_t)val0_m); \ - \ - val_m; \ +#define LD(psrc) \ + ({ \ + const uint8_t *ld_psrc_m1 = (const uint8_t *)(psrc); \ + uint32_t ld_val0_m, ld_val1_m; \ + uint64_t ld_val_m = 0; \ + \ + ld_val0_m = LW(ld_psrc_m1); \ + ld_val1_m = LW(ld_psrc_m1 + 4); \ + \ + ld_val_m = (uint64_t)(ld_val1_m); \ + ld_val_m = (uint64_t)((ld_val_m << 32) & 0xFFFFFFFF00000000); \ + ld_val_m = (uint64_t)(ld_val_m | (uint64_t)ld_val0_m); \ + \ + ld_val_m; \ }) #endif // (__mips == 64) -#define SH(val, pdst) \ - { \ - uint8_t *pdst_m = (uint8_t *)(pdst); \ - const uint16_t val_m = (val); \ - \ - asm volatile("ush %[val_m], %[pdst_m] \n\t" \ - \ - : [pdst_m] "=m"(*pdst_m) \ - : [val_m] "r"(val_m)); \ +#define SH(val, pdst) \ + { \ + uint8_t *sh_pdst_m = (uint8_t *)(pdst); \ + const uint16_t sh_val_m = (val); \ + \ + __asm__ __volatile__("ush %[sh_val_m], %[sh_pdst_m] \n\t" \ + \ + : [sh_pdst_m] "=m"(*sh_pdst_m) \ + : [sh_val_m] "r"(sh_val_m)); \ } -#define SW(val, pdst) \ - { \ - uint8_t *pdst_m = (uint8_t *)(pdst); \ - const uint32_t val_m = (val); \ - \ - asm volatile("usw %[val_m], %[pdst_m] \n\t" \ - \ - : [pdst_m] "=m"(*pdst_m) \ - : [val_m] "r"(val_m)); \ +#define SW(val, pdst) \ + { \ + uint8_t *sw_pdst_m = (uint8_t *)(pdst); \ + const uint32_t sw_val_m = (val); \ + \ + __asm__ __volatile__("usw %[sw_val_m], %[sw_pdst_m] \n\t" \ + \ + : [sw_pdst_m] "=m"(*sw_pdst_m) \ + : [sw_val_m] "r"(sw_val_m)); \ } -#define SD(val, pdst) \ - { \ - uint8_t *pdst_m1 = (uint8_t *)(pdst); \ - uint32_t val0_m, val1_m; \ - \ - val0_m = (uint32_t)((val)&0x00000000FFFFFFFF); \ - val1_m = (uint32_t)(((val) >> 32) & 0x00000000FFFFFFFF); \ - \ - SW(val0_m, pdst_m1); \ - SW(val1_m, pdst_m1 + 4); \ +#define SD(val, pdst) \ + { \ + uint8_t *sd_pdst_m1 = (uint8_t *)(pdst); \ + uint32_t sd_val0_m, sd_val1_m; \ + \ + sd_val0_m = (uint32_t)((val) & 0x00000000FFFFFFFF); \ + sd_val1_m = (uint32_t)(((val) >> 32) & 0x00000000FFFFFFFF); \ + \ + SW(sd_val0_m, sd_pdst_m1); \ + SW(sd_val1_m, sd_pdst_m1 + 4); \ } #endif // (__mips_isa_rev >= 6) diff --git a/libs/libvpx/vp8/common/onyx.h b/libs/libvpx/vp8/common/onyx.h index 05c72df3fa..2038c000b0 100644 --- a/libs/libvpx/vp8/common/onyx.h +++ b/libs/libvpx/vp8/common/onyx.h @@ -26,13 +26,6 @@ struct VP8_COMP; /* Create/destroy static data structures. */ -typedef enum { - NORMAL = 0, - FOURFIVE = 1, - THREEFIVE = 2, - ONETWO = 3 -} VPX_SCALING; - typedef enum { USAGE_LOCAL_FILE_PLAYBACK = 0x0, USAGE_STREAM_FROM_SERVER = 0x1, @@ -58,19 +51,19 @@ typedef enum { #include static INLINE void Scale2Ratio(int mode, int *hr, int *hs) { switch (mode) { - case NORMAL: + case VP8E_NORMAL: *hr = 1; *hs = 1; break; - case FOURFIVE: + case VP8E_FOURFIVE: *hr = 4; *hs = 5; break; - case THREEFIVE: + case VP8E_THREEFIVE: *hr = 3; *hs = 5; break; - case ONETWO: + case VP8E_ONETWO: *hr = 1; *hs = 2; break; @@ -90,7 +83,14 @@ typedef struct { int Width; int Height; struct vpx_rational timebase; - unsigned int target_bandwidth; /* kilobits per second */ + /* In either kilobits per second or bits per second, depending on which + * copy of oxcf this is in. + * - ctx->oxcf.target_bandwidth is in kilobits per second. See + * set_vp8e_config(). + * - ctx->cpi->oxcf.target_bandwidth in is bits per second. See + * vp8_change_config(). + */ + unsigned int target_bandwidth; /* Parameter used for applying denoiser. * For temporal denoiser: noise_sensitivity = 0 means off, @@ -221,6 +221,7 @@ typedef struct { /* Temporal scaling parameters */ unsigned int number_of_layers; + /* kilobits per second */ unsigned int target_bitrate[VPX_TS_MAX_PERIODICITY]; unsigned int rate_decimator[VPX_TS_MAX_PERIODICITY]; unsigned int periodicity; @@ -241,13 +242,13 @@ typedef struct { #endif } VP8_CONFIG; -void vp8_initialize(); +void vp8_initialize(void); -struct VP8_COMP *vp8_create_compressor(VP8_CONFIG *oxcf); +struct VP8_COMP *vp8_create_compressor(const VP8_CONFIG *oxcf); void vp8_remove_compressor(struct VP8_COMP **comp); void vp8_init_config(struct VP8_COMP *onyx, VP8_CONFIG *oxcf); -void vp8_change_config(struct VP8_COMP *cpi, VP8_CONFIG *oxcf); +void vp8_change_config(struct VP8_COMP *cpi, const VP8_CONFIG *oxcf); int vp8_receive_raw_frame(struct VP8_COMP *cpi, unsigned int frame_flags, YV12_BUFFER_CONFIG *sd, int64_t time_stamp, @@ -273,8 +274,8 @@ int vp8_set_roimap(struct VP8_COMP *cpi, unsigned char *map, unsigned int rows, unsigned int threshold[4]); int vp8_set_active_map(struct VP8_COMP *cpi, unsigned char *map, unsigned int rows, unsigned int cols); -int vp8_set_internal_size(struct VP8_COMP *cpi, VPX_SCALING horiz_mode, - VPX_SCALING vert_mode); +int vp8_set_internal_size(struct VP8_COMP *cpi, VPX_SCALING_MODE horiz_mode, + VPX_SCALING_MODE vert_mode); int vp8_get_quantizer(struct VP8_COMP *cpi); #ifdef __cplusplus diff --git a/libs/libvpx/vp8/common/onyxc_int.h b/libs/libvpx/vp8/common/onyxc_int.h index ef8d007620..d4824d24e4 100644 --- a/libs/libvpx/vp8/common/onyxc_int.h +++ b/libs/libvpx/vp8/common/onyxc_int.h @@ -167,7 +167,6 @@ typedef struct VP8Common { #if CONFIG_POSTPROC struct postproc_state postproc_state; #endif - int cpu_caps; } VP8_COMMON; #ifdef __cplusplus diff --git a/libs/libvpx/vp8/common/onyxd.h b/libs/libvpx/vp8/common/onyxd.h index e4e81aaac5..217a598de7 100644 --- a/libs/libvpx/vp8/common/onyxd.h +++ b/libs/libvpx/vp8/common/onyxd.h @@ -41,9 +41,8 @@ void vp8dx_set_setting(struct VP8D_COMP *comp, VP8D_SETTING oxst, int x); int vp8dx_get_setting(struct VP8D_COMP *comp, VP8D_SETTING oxst); -int vp8dx_receive_compressed_data(struct VP8D_COMP *pbi, int64_t time_stamp); +int vp8dx_receive_compressed_data(struct VP8D_COMP *pbi); int vp8dx_get_raw_frame(struct VP8D_COMP *pbi, YV12_BUFFER_CONFIG *sd, - int64_t *time_stamp, int64_t *time_end_stamp, vp8_ppflags_t *flags); int vp8dx_references_buffer(struct VP8Common *oci, int ref_frame); diff --git a/libs/libvpx/vp8/common/postproc.c b/libs/libvpx/vp8/common/postproc.c index c03b16b2f5..52dc867460 100644 --- a/libs/libvpx/vp8/common/postproc.c +++ b/libs/libvpx/vp8/common/postproc.c @@ -25,23 +25,6 @@ #include #include -/* clang-format off */ -#define RGB_TO_YUV(t) \ - (unsigned char)((0.257 * (float)(t >> 16)) + \ - (0.504 * (float)(t >> 8 & 0xff)) + \ - (0.098 * (float)(t & 0xff)) + 16), \ - (unsigned char)(-(0.148 * (float)(t >> 16)) - \ - (0.291 * (float)(t >> 8 & 0xff)) + \ - (0.439 * (float)(t & 0xff)) + 128), \ - (unsigned char)((0.439 * (float)(t >> 16)) - \ - (0.368 * (float)(t >> 8 & 0xff)) - \ - (0.071 * (float)(t & 0xff)) + 128) -/* clang-format on */ - -extern void vp8_blit_text(const char *msg, unsigned char *address, - const int pitch); -extern void vp8_blit_line(int x0, int x1, int y0, int y1, unsigned char *image, - const int pitch); /*********************************************************************************************************** */ #if CONFIG_POSTPROC @@ -61,6 +44,7 @@ static void vp8_de_mblock(YV12_BUFFER_CONFIG *post, int q) { void vp8_deblock(VP8_COMMON *cm, YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *post, int q) { + vpx_clear_system_state(); double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065; int ppl = (int)(level + .5); @@ -116,6 +100,7 @@ void vp8_deblock(VP8_COMMON *cm, YV12_BUFFER_CONFIG *source, void vp8_de_noise(VP8_COMMON *cm, YV12_BUFFER_CONFIG *source, int q, int uvfilter) { int mbr; + vpx_clear_system_state(); double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065; int ppl = (int)(level + .5); int mb_rows = cm->mb_rows; @@ -151,6 +136,7 @@ int vp8_post_proc_frame(VP8_COMMON *oci, YV12_BUFFER_CONFIG *dest, int flags = ppflags->post_proc_flag; int deblock_level = ppflags->deblocking_level; int noise_level = ppflags->noise_level; + const int generated_noise_size = ALIGN_POWER_OF_TWO(oci->Width, 4) + 256; if (!oci->frame_to_show) return -1; @@ -168,10 +154,13 @@ int vp8_post_proc_frame(VP8_COMMON *oci, YV12_BUFFER_CONFIG *dest, return 0; } if (flags & VP8D_ADDNOISE) { - if (!oci->postproc_state.generated_noise) { + if (!oci->postproc_state.generated_noise || + oci->postproc_state.generated_noise_size < generated_noise_size) { + vpx_free(oci->postproc_state.generated_noise); oci->postproc_state.generated_noise = vpx_calloc( - oci->Width + 256, sizeof(*oci->postproc_state.generated_noise)); + generated_noise_size, sizeof(*oci->postproc_state.generated_noise)); if (!oci->postproc_state.generated_noise) return 1; + oci->postproc_state.generated_noise_size = generated_noise_size; } } @@ -240,8 +229,8 @@ int vp8_post_proc_frame(VP8_COMMON *oci, YV12_BUFFER_CONFIG *dest, struct postproc_state *ppstate = &oci->postproc_state; vpx_clear_system_state(); sigma = noise_level + .5 + .6 * q / 63.0; - ppstate->clamp = - vpx_setup_noise(sigma, ppstate->generated_noise, oci->Width + 256); + ppstate->clamp = vpx_setup_noise(sigma, ppstate->generated_noise, + generated_noise_size); ppstate->last_q = q; ppstate->last_noise = noise_level; } diff --git a/libs/libvpx/vp8/common/postproc.h b/libs/libvpx/vp8/common/postproc.h index 492c52aef6..3b2da1c74f 100644 --- a/libs/libvpx/vp8/common/postproc.h +++ b/libs/libvpx/vp8/common/postproc.h @@ -19,6 +19,7 @@ struct postproc_state { int last_frame_valid; int clamp; int8_t *generated_noise; + int generated_noise_size; }; #include "onyxc_int.h" #include "ppflags.h" diff --git a/libs/libvpx/vp8/common/reconinter.c b/libs/libvpx/vp8/common/reconinter.c index 2cb0709318..143d6852ab 100644 --- a/libs/libvpx/vp8/common/reconinter.c +++ b/libs/libvpx/vp8/common/reconinter.c @@ -333,12 +333,10 @@ void vp8_build_inter16x16_predictors_mb(MACROBLOCKD *x, unsigned char *dst_y, _16x16mv.as_mv.row &= x->fullpixel_mask; _16x16mv.as_mv.col &= x->fullpixel_mask; - if (2 * _16x16mv.as_mv.col < (x->mb_to_left_edge - (19 << 3)) || - 2 * _16x16mv.as_mv.col > x->mb_to_right_edge + (18 << 3) || - 2 * _16x16mv.as_mv.row < (x->mb_to_top_edge - (19 << 3)) || - 2 * _16x16mv.as_mv.row > x->mb_to_bottom_edge + (18 << 3)) { - return; - } + /* Rounding to full-pel can move the chroma MV outside the border tap + * window even though the luma MV was already clamped, so clamp again to + * keep the reference read in bounds and ensure dst_u/dst_v are written. */ + clamp_uvmv_to_umv_border(&_16x16mv.as_mv, x); pre_stride >>= 1; offset = (_16x16mv.as_mv.row >> 3) * pre_stride + (_16x16mv.as_mv.col >> 3); diff --git a/libs/libvpx/vp8/common/rtcd.c b/libs/libvpx/vp8/common/rtcd.c index 09a0e2b4b3..102b7ccd54 100644 --- a/libs/libvpx/vp8/common/rtcd.c +++ b/libs/libvpx/vp8/common/rtcd.c @@ -12,4 +12,4 @@ #include "./vp8_rtcd.h" #include "vpx_ports/vpx_once.h" -void vp8_rtcd() { once(setup_rtcd_internal); } +void vp8_rtcd(void) { once(setup_rtcd_internal); } diff --git a/libs/libvpx/vp8/common/rtcd_defs.pl b/libs/libvpx/vp8/common/rtcd_defs.pl index 739a612847..bf1a0224d5 100644 --- a/libs/libvpx/vp8/common/rtcd_defs.pl +++ b/libs/libvpx/vp8/common/rtcd_defs.pl @@ -28,75 +28,96 @@ EOF } forward_decls qw/vp8_common_forward_decls/; +# Functions that are written in assembly (as opposed to intrinsics). +$mmx_asm = $sse2_asm = $sse3_asm = $ssse3_asm = ''; +if (vpx_config("HAVE_X86_ASM") eq "yes") { + $mmx_asm = 'mmx'; + $sse2_asm = 'sse2'; + $sse3_asm = 'sse3'; + $ssse3_asm = 'ssse3'; +} + # # Dequant # add_proto qw/void vp8_dequantize_b/, "struct blockd*, short *DQC"; -specialize qw/vp8_dequantize_b mmx neon msa mmi/; +specialize qw/vp8_dequantize_b neon msa mmi/, "$mmx_asm"; add_proto qw/void vp8_dequant_idct_add/, "short *input, short *dq, unsigned char *dest, int stride"; -specialize qw/vp8_dequant_idct_add mmx neon dspr2 msa mmi/; +specialize qw/vp8_dequant_idct_add neon dspr2 msa mmi/, "$mmx_asm"; add_proto qw/void vp8_dequant_idct_add_y_block/, "short *q, short *dq, unsigned char *dst, int stride, char *eobs"; -specialize qw/vp8_dequant_idct_add_y_block sse2 neon dspr2 msa mmi lsx/; +specialize qw/vp8_dequant_idct_add_y_block neon dspr2 msa mmi lsx/, "$sse2_asm"; add_proto qw/void vp8_dequant_idct_add_uv_block/, "short *q, short *dq, unsigned char *dst_u, unsigned char *dst_v, int stride, char *eobs"; -specialize qw/vp8_dequant_idct_add_uv_block sse2 neon dspr2 msa mmi lsx/; +specialize qw/vp8_dequant_idct_add_uv_block neon dspr2 msa mmi lsx/, "$sse2_asm"; # # Loopfilter # add_proto qw/void vp8_loop_filter_mbv/, "unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr, int y_stride, int uv_stride, struct loop_filter_info *lfi"; -specialize qw/vp8_loop_filter_mbv sse2 neon dspr2 msa mmi lsx/; +specialize qw/vp8_loop_filter_mbv neon dspr2 msa mmi lsx/, "$sse2_asm"; add_proto qw/void vp8_loop_filter_bv/, "unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr, int y_stride, int uv_stride, struct loop_filter_info *lfi"; -specialize qw/vp8_loop_filter_bv sse2 neon dspr2 msa mmi lsx/; +specialize qw/vp8_loop_filter_bv neon dspr2 msa mmi lsx/, "$sse2_asm"; add_proto qw/void vp8_loop_filter_mbh/, "unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr, int y_stride, int uv_stride, struct loop_filter_info *lfi"; -specialize qw/vp8_loop_filter_mbh sse2 neon dspr2 msa mmi lsx/; +specialize qw/vp8_loop_filter_mbh neon dspr2 msa mmi lsx/, "$sse2_asm"; add_proto qw/void vp8_loop_filter_bh/, "unsigned char *y_ptr, unsigned char *u_ptr, unsigned char *v_ptr, int y_stride, int uv_stride, struct loop_filter_info *lfi"; -specialize qw/vp8_loop_filter_bh sse2 neon dspr2 msa mmi lsx/; +specialize qw/vp8_loop_filter_bh neon dspr2 msa mmi lsx/, "$sse2_asm"; add_proto qw/void vp8_loop_filter_simple_mbv/, "unsigned char *y_ptr, int y_stride, const unsigned char *blimit"; -specialize qw/vp8_loop_filter_simple_mbv sse2 neon msa mmi/; +specialize qw/vp8_loop_filter_simple_mbv neon msa mmi lsx/, "$sse2_asm"; $vp8_loop_filter_simple_mbv_c=vp8_loop_filter_simple_vertical_edge_c; -$vp8_loop_filter_simple_mbv_sse2=vp8_loop_filter_simple_vertical_edge_sse2; +if (vpx_config("HAVE_X86_ASM") eq "yes") { + $vp8_loop_filter_simple_mbv_sse2=vp8_loop_filter_simple_vertical_edge_sse2; +} $vp8_loop_filter_simple_mbv_neon=vp8_loop_filter_mbvs_neon; $vp8_loop_filter_simple_mbv_msa=vp8_loop_filter_simple_vertical_edge_msa; $vp8_loop_filter_simple_mbv_mmi=vp8_loop_filter_simple_vertical_edge_mmi; +$vp8_loop_filter_simple_mbv_lsx=vp8_loop_filter_simple_vertical_edge_lsx; add_proto qw/void vp8_loop_filter_simple_mbh/, "unsigned char *y_ptr, int y_stride, const unsigned char *blimit"; -specialize qw/vp8_loop_filter_simple_mbh sse2 neon msa mmi/; +specialize qw/vp8_loop_filter_simple_mbh neon msa mmi lsx/, "$sse2_asm"; $vp8_loop_filter_simple_mbh_c=vp8_loop_filter_simple_horizontal_edge_c; -$vp8_loop_filter_simple_mbh_sse2=vp8_loop_filter_simple_horizontal_edge_sse2; +if (vpx_config("HAVE_X86_ASM") eq "yes") { + $vp8_loop_filter_simple_mbh_sse2=vp8_loop_filter_simple_horizontal_edge_sse2; +} $vp8_loop_filter_simple_mbh_neon=vp8_loop_filter_mbhs_neon; $vp8_loop_filter_simple_mbh_msa=vp8_loop_filter_simple_horizontal_edge_msa; $vp8_loop_filter_simple_mbh_mmi=vp8_loop_filter_simple_horizontal_edge_mmi; +$vp8_loop_filter_simple_mbh_lsx=vp8_loop_filter_simple_horizontal_edge_lsx; add_proto qw/void vp8_loop_filter_simple_bv/, "unsigned char *y_ptr, int y_stride, const unsigned char *blimit"; -specialize qw/vp8_loop_filter_simple_bv sse2 neon msa mmi/; +specialize qw/vp8_loop_filter_simple_bv neon msa mmi lsx/, "$sse2_asm"; $vp8_loop_filter_simple_bv_c=vp8_loop_filter_bvs_c; -$vp8_loop_filter_simple_bv_sse2=vp8_loop_filter_bvs_sse2; +if (vpx_config("HAVE_X86_ASM") eq "yes") { + $vp8_loop_filter_simple_bv_sse2=vp8_loop_filter_bvs_sse2; +} $vp8_loop_filter_simple_bv_neon=vp8_loop_filter_bvs_neon; $vp8_loop_filter_simple_bv_msa=vp8_loop_filter_bvs_msa; $vp8_loop_filter_simple_bv_mmi=vp8_loop_filter_bvs_mmi; +$vp8_loop_filter_simple_bv_lsx=vp8_loop_filter_bvs_lsx; add_proto qw/void vp8_loop_filter_simple_bh/, "unsigned char *y_ptr, int y_stride, const unsigned char *blimit"; -specialize qw/vp8_loop_filter_simple_bh sse2 neon msa mmi/; +specialize qw/vp8_loop_filter_simple_bh neon msa mmi lsx/, "$sse2_asm"; $vp8_loop_filter_simple_bh_c=vp8_loop_filter_bhs_c; -$vp8_loop_filter_simple_bh_sse2=vp8_loop_filter_bhs_sse2; +if (vpx_config("HAVE_X86_ASM") eq "yes") { + $vp8_loop_filter_simple_bh_sse2=vp8_loop_filter_bhs_sse2; +} $vp8_loop_filter_simple_bh_neon=vp8_loop_filter_bhs_neon; $vp8_loop_filter_simple_bh_msa=vp8_loop_filter_bhs_msa; $vp8_loop_filter_simple_bh_mmi=vp8_loop_filter_bhs_mmi; +$vp8_loop_filter_simple_bh_lsx=vp8_loop_filter_bhs_lsx; # # IDCT # #idct16 add_proto qw/void vp8_short_idct4x4llm/, "short *input, unsigned char *pred_ptr, int pred_stride, unsigned char *dst_ptr, int dst_stride"; -specialize qw/vp8_short_idct4x4llm mmx neon dspr2 msa mmi/; +specialize qw/vp8_short_idct4x4llm neon dspr2 msa mmi/, "$mmx_asm"; #iwalsh1 add_proto qw/void vp8_short_inv_walsh4x4_1/, "short *input, short *mb_dqcoeff"; @@ -104,40 +125,34 @@ specialize qw/vp8_short_inv_walsh4x4_1 dspr2/; #iwalsh16 add_proto qw/void vp8_short_inv_walsh4x4/, "short *input, short *mb_dqcoeff"; -specialize qw/vp8_short_inv_walsh4x4 sse2 neon dspr2 msa mmi/; +specialize qw/vp8_short_inv_walsh4x4 neon dspr2 msa mmi/, "$sse2_asm"; #idct1_scalar_add add_proto qw/void vp8_dc_only_idct_add/, "short input_dc, unsigned char *pred_ptr, int pred_stride, unsigned char *dst_ptr, int dst_stride"; -specialize qw/vp8_dc_only_idct_add mmx neon dspr2 msa mmi lsx/; +specialize qw/vp8_dc_only_idct_add neon dspr2 msa mmi lsx/, "$mmx_asm"; # # RECON # add_proto qw/void vp8_copy_mem16x16/, "unsigned char *src, int src_stride, unsigned char *dst, int dst_stride"; -specialize qw/vp8_copy_mem16x16 sse2 neon dspr2 msa mmi/; +specialize qw/vp8_copy_mem16x16 neon dspr2 msa mmi/, "$sse2_asm"; add_proto qw/void vp8_copy_mem8x8/, "unsigned char *src, int src_stride, unsigned char *dst, int dst_stride"; -specialize qw/vp8_copy_mem8x8 mmx neon dspr2 msa mmi/; +specialize qw/vp8_copy_mem8x8 neon dspr2 msa mmi/, "$mmx_asm"; add_proto qw/void vp8_copy_mem8x4/, "unsigned char *src, int src_stride, unsigned char *dst, int dst_stride"; -specialize qw/vp8_copy_mem8x4 mmx neon dspr2 msa mmi/; +specialize qw/vp8_copy_mem8x4 neon dspr2 msa mmi/, "$mmx_asm"; # # Postproc # if (vpx_config("CONFIG_POSTPROC") eq "yes") { - add_proto qw/void vp8_blend_mb_inner/, "unsigned char *y, unsigned char *u, unsigned char *v, int y_1, int u_1, int v_1, int alpha, int stride"; - - add_proto qw/void vp8_blend_mb_outer/, "unsigned char *y, unsigned char *u, unsigned char *v, int y_1, int u_1, int v_1, int alpha, int stride"; - - add_proto qw/void vp8_blend_b/, "unsigned char *y, unsigned char *u, unsigned char *v, int y_1, int u_1, int v_1, int alpha, int stride"; - add_proto qw/void vp8_filter_by_weight16x16/, "unsigned char *src, int src_stride, unsigned char *dst, int dst_stride, int src_weight"; - specialize qw/vp8_filter_by_weight16x16 sse2 msa/; + specialize qw/vp8_filter_by_weight16x16 msa/, "$sse2_asm"; add_proto qw/void vp8_filter_by_weight8x8/, "unsigned char *src, int src_stride, unsigned char *dst, int dst_stride, int src_weight"; - specialize qw/vp8_filter_by_weight8x8 sse2 msa/; + specialize qw/vp8_filter_by_weight8x8 msa/, "$sse2_asm"; add_proto qw/void vp8_filter_by_weight4x4/, "unsigned char *src, int src_stride, unsigned char *dst, int dst_stride, int src_weight"; } @@ -146,22 +161,22 @@ if (vpx_config("CONFIG_POSTPROC") eq "yes") { # Subpixel # add_proto qw/void vp8_sixtap_predict16x16/, "unsigned char *src_ptr, int src_pixels_per_line, int xoffset, int yoffset, unsigned char *dst_ptr, int dst_pitch"; -specialize qw/vp8_sixtap_predict16x16 sse2 ssse3 neon dspr2 msa mmi lsx/; +specialize qw/vp8_sixtap_predict16x16 neon dspr2 msa mmi lsx/, "$sse2_asm", "$ssse3_asm"; add_proto qw/void vp8_sixtap_predict8x8/, "unsigned char *src_ptr, int src_pixels_per_line, int xoffset, int yoffset, unsigned char *dst_ptr, int dst_pitch"; -specialize qw/vp8_sixtap_predict8x8 sse2 ssse3 neon dspr2 msa mmi lsx/; +specialize qw/vp8_sixtap_predict8x8 neon dspr2 msa mmi lsx/, "$sse2_asm", "$ssse3_asm"; add_proto qw/void vp8_sixtap_predict8x4/, "unsigned char *src_ptr, int src_pixels_per_line, int xoffset, int yoffset, unsigned char *dst_ptr, int dst_pitch"; -specialize qw/vp8_sixtap_predict8x4 sse2 ssse3 neon dspr2 msa mmi/; +specialize qw/vp8_sixtap_predict8x4 neon dspr2 msa mmi/, "$sse2_asm", "$ssse3_asm"; add_proto qw/void vp8_sixtap_predict4x4/, "unsigned char *src_ptr, int src_pixels_per_line, int xoffset, int yoffset, unsigned char *dst_ptr, int dst_pitch"; -specialize qw/vp8_sixtap_predict4x4 mmx ssse3 neon dspr2 msa mmi lsx/; +specialize qw/vp8_sixtap_predict4x4 neon dspr2 msa mmi lsx/, "$mmx_asm", "$ssse3_asm"; add_proto qw/void vp8_bilinear_predict16x16/, "unsigned char *src_ptr, int src_pixels_per_line, int xoffset, int yoffset, unsigned char *dst_ptr, int dst_pitch"; -specialize qw/vp8_bilinear_predict16x16 sse2 ssse3 neon msa/; +specialize qw/vp8_bilinear_predict16x16 sse2 neon msa/, "$ssse3_asm"; add_proto qw/void vp8_bilinear_predict8x8/, "unsigned char *src_ptr, int src_pixels_per_line, int xoffset, int yoffset, unsigned char *dst_ptr, int dst_pitch"; -specialize qw/vp8_bilinear_predict8x8 sse2 ssse3 neon msa/; +specialize qw/vp8_bilinear_predict8x8 sse2 neon msa/, "$ssse3_asm"; add_proto qw/void vp8_bilinear_predict8x4/, "unsigned char *src_ptr, int src_pixels_per_line, int xoffset, int yoffset, unsigned char *dst_ptr, int dst_pitch"; specialize qw/vp8_bilinear_predict8x4 sse2 neon msa/; @@ -178,19 +193,19 @@ if (vpx_config("CONFIG_VP8_ENCODER") eq "yes") { # Block copy # add_proto qw/void vp8_copy32xn/, "const unsigned char *src_ptr, int src_stride, unsigned char *dst_ptr, int dst_stride, int height"; -specialize qw/vp8_copy32xn sse2 sse3/; +specialize qw/vp8_copy32xn/, "$sse2_asm", "$sse3_asm"; # # Forward DCT # add_proto qw/void vp8_short_fdct4x4/, "short *input, short *output, int pitch"; -specialize qw/vp8_short_fdct4x4 sse2 neon msa mmi lsx/; +specialize qw/vp8_short_fdct4x4 neon msa mmi lsx/, "$sse2_asm"; add_proto qw/void vp8_short_fdct8x4/, "short *input, short *output, int pitch"; -specialize qw/vp8_short_fdct8x4 sse2 neon msa mmi lsx/; +specialize qw/vp8_short_fdct8x4 neon msa mmi lsx/, "$sse2_asm"; add_proto qw/void vp8_short_walsh4x4/, "short *input, short *output, int pitch"; -specialize qw/vp8_short_walsh4x4 sse2 neon msa mmi/; +specialize qw/vp8_short_walsh4x4 neon msa mmi/, "$sse2_asm"; # # Quantizer @@ -199,19 +214,19 @@ add_proto qw/void vp8_regular_quantize_b/, "struct block *, struct blockd *"; specialize qw/vp8_regular_quantize_b sse2 sse4_1 msa mmi lsx/; add_proto qw/void vp8_fast_quantize_b/, "struct block *, struct blockd *"; -specialize qw/vp8_fast_quantize_b sse2 ssse3 neon msa mmi/; +specialize qw/vp8_fast_quantize_b sse2 ssse3 neon msa mmi lsx/; # # Block subtraction # add_proto qw/int vp8_block_error/, "short *coeff, short *dqcoeff"; -specialize qw/vp8_block_error sse2 msa lsx/; +specialize qw/vp8_block_error msa lsx/, "$sse2_asm"; add_proto qw/int vp8_mbblock_error/, "struct macroblock *mb, int dc"; -specialize qw/vp8_mbblock_error sse2 msa lsx/; +specialize qw/vp8_mbblock_error msa lsx/, "$sse2_asm"; add_proto qw/int vp8_mbuverror/, "struct macroblock *mb"; -specialize qw/vp8_mbuverror sse2 msa/; +specialize qw/vp8_mbuverror msa/, "$sse2_asm"; # # Motion search @@ -232,7 +247,7 @@ $vp8_diamond_search_sad_lsx=vp8_diamond_search_sadx4; # if (vpx_config("CONFIG_REALTIME_ONLY") ne "yes") { add_proto qw/void vp8_temporal_filter_apply/, "unsigned char *frame1, unsigned int stride, unsigned char *frame2, unsigned int block_size, int strength, int filter_weight, unsigned int *accumulator, unsigned short *count"; - specialize qw/vp8_temporal_filter_apply sse2 msa/; + specialize qw/vp8_temporal_filter_apply msa/, "$sse2_asm"; } # diff --git a/libs/libvpx/vp8/common/threading.h b/libs/libvpx/vp8/common/threading.h index ef2b701bdb..0de75cfde3 100644 --- a/libs/libvpx/vp8/common/threading.h +++ b/libs/libvpx/vp8/common/threading.h @@ -19,169 +19,67 @@ extern "C" { #if CONFIG_OS_SUPPORT && CONFIG_MULTITHREAD -/* Thread management macros */ #if defined(_WIN32) && !HAVE_PTHREAD_H /* Win32 */ -#include #include -#if defined(__GNUC__) && \ - (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) -#define THREAD_FUNCTION \ - __attribute__((force_align_arg_pointer)) unsigned int __stdcall -#else -#define THREAD_FUNCTION unsigned int __stdcall -#endif -#define THREAD_FUNCTION_RETURN DWORD -#define THREAD_SPECIFIC_INDEX DWORD -#define pthread_t HANDLE -#define pthread_attr_t DWORD -#define pthread_detach(thread) \ - if (thread != NULL) CloseHandle(thread) -#define thread_sleep(nms) Sleep(nms) -#define pthread_cancel(thread) terminate_thread(thread, 0) -#define ts_key_create(ts_key, destructor) \ - { ts_key = TlsAlloc(); }; -#define pthread_getspecific(ts_key) TlsGetValue(ts_key) -#define pthread_setspecific(ts_key, value) TlsSetValue(ts_key, (void *)value) -#define pthread_self() GetCurrentThreadId() - -#elif defined(__OS2__) -/* OS/2 */ -#define INCL_DOS -#include - -#include -#define THREAD_FUNCTION void * -#define THREAD_FUNCTION_RETURN void * -#define THREAD_SPECIFIC_INDEX PULONG -#define pthread_t TID -#define pthread_attr_t ULONG -#define pthread_detach(thread) 0 -#define thread_sleep(nms) DosSleep(nms) -#define pthread_cancel(thread) DosKillThread(thread) -#define ts_key_create(ts_key, destructor) \ - DosAllocThreadLocalMemory(1, &(ts_key)); -#define pthread_getspecific(ts_key) ((void *)(*(ts_key))) -#define pthread_setspecific(ts_key, value) (*(ts_key) = (ULONG)(value)) -#define pthread_self() _gettid() #else +/* pthreads */ #ifdef __APPLE__ #include #include #include #include #include - #else #include #endif - -#include -/* pthreads */ -/* Nearly everything is already defined */ -#define THREAD_FUNCTION void * -#define THREAD_FUNCTION_RETURN void * -#define THREAD_SPECIFIC_INDEX pthread_key_t -#define ts_key_create(ts_key, destructor) \ - pthread_key_create(&(ts_key), destructor); #endif /* Synchronization macros: Win32 and Pthreads */ #if defined(_WIN32) && !HAVE_PTHREAD_H -#define sem_t HANDLE -#define pause(voidpara) __asm PAUSE -#define sem_init(sem, sem_attr1, sem_init_value) \ - (int)((*sem = CreateSemaphore(NULL, 0, 32768, NULL)) == NULL) -#define sem_wait(sem) \ +#define vp8_sem_t HANDLE +#define vp8_sem_init(sem, pshared, value) \ + (int)((*sem = CreateSemaphore(NULL, value, 32768, NULL)) == NULL) +#define vp8_sem_wait(sem) \ (int)(WAIT_OBJECT_0 != WaitForSingleObject(*sem, INFINITE)) -#define sem_post(sem) ReleaseSemaphore(*sem, 1, NULL) -#define sem_destroy(sem) \ +#define vp8_sem_post(sem) ReleaseSemaphore(*sem, 1, NULL) +#define vp8_sem_destroy(sem) \ if (*sem) ((int)(CloseHandle(*sem)) == TRUE) #define thread_sleep(nms) Sleep(nms) -#elif defined(__OS2__) -typedef struct { - HEV event; - HMTX wait_mutex; - HMTX count_mutex; - int count; -} sem_t; - -static inline int sem_init(sem_t *sem, int pshared, unsigned int value) { - DosCreateEventSem(NULL, &sem->event, pshared ? DC_SEM_SHARED : 0, - value > 0 ? TRUE : FALSE); - DosCreateMutexSem(NULL, &sem->wait_mutex, 0, FALSE); - DosCreateMutexSem(NULL, &sem->count_mutex, 0, FALSE); - - sem->count = value; - - return 0; -} - -static inline int sem_wait(sem_t *sem) { - DosRequestMutexSem(sem->wait_mutex, -1); - - DosWaitEventSem(sem->event, -1); - - DosRequestMutexSem(sem->count_mutex, -1); - - sem->count--; - if (sem->count == 0) { - ULONG post_count; - - DosResetEventSem(sem->event, &post_count); - } - - DosReleaseMutexSem(sem->count_mutex); - - DosReleaseMutexSem(sem->wait_mutex); - - return 0; -} - -static inline int sem_post(sem_t *sem) { - DosRequestMutexSem(sem->count_mutex, -1); - - if (sem->count < 32768) { - sem->count++; - DosPostEventSem(sem->event); - } - - DosReleaseMutexSem(sem->count_mutex); - - return 0; -} - -static inline int sem_destroy(sem_t *sem) { - DosCloseEventSem(sem->event); - DosCloseMutexSem(sem->wait_mutex); - DosCloseMutexSem(sem->count_mutex); - - return 0; -} - -#define thread_sleep(nms) DosSleep(nms) - #else #ifdef __APPLE__ -#define sem_t semaphore_t -#define sem_init(X, Y, Z) \ - semaphore_create(mach_task_self(), X, SYNC_POLICY_FIFO, Z) -#define sem_wait(sem) (semaphore_wait(*sem)) -#define sem_post(sem) semaphore_signal(*sem) -#define sem_destroy(sem) semaphore_destroy(mach_task_self(), *sem) +#define vp8_sem_t semaphore_t +#define vp8_sem_init(sem, pshared, value) \ + semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, value) +#define vp8_sem_wait(sem) semaphore_wait(*sem) +#define vp8_sem_post(sem) semaphore_signal(*sem) +#define vp8_sem_destroy(sem) semaphore_destroy(mach_task_self(), *sem) #else +#include #include #include +#define vp8_sem_t sem_t +#define vp8_sem_init sem_init +static INLINE int vp8_sem_wait(vp8_sem_t *sem) { + int ret; + while ((ret = sem_wait(sem)) == -1 && errno == EINTR) { + } + return ret; +} +#define vp8_sem_post sem_post +#define vp8_sem_destroy sem_destroy #endif /* __APPLE__ */ /* Not Windows. Assume pthreads */ /* thread_sleep implementation: yield unless Linux/Unix. */ #if defined(__unix__) || defined(__APPLE__) -#define thread_sleep(nms) { struct timespec ts;ts.tv_sec=0; ts.tv_nsec = 1000*nms;sched_yield();nanosleep(&ts, NULL);} +#define thread_sleep(nms) +/* {struct timespec ts;ts.tv_sec=0; + ts.tv_nsec = 1000*nms;nanosleep(&ts, NULL);} */ #else -#define thread_sleep(nms) {struct timespec ts;ts.tv_sec=0; ts.tv_nsec = 1000*nms;sched_yield();clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);} +#define thread_sleep(nms) sched_yield(); #endif /* __unix__ || __APPLE__ */ #endif @@ -192,7 +90,6 @@ static inline int sem_destroy(sem_t *sem) { #define x86_pause_hint() #endif -#include "vpx_util/vpx_thread.h" #include "vpx_util/vpx_atomics.h" static INLINE void vp8_atomic_spin_wait( @@ -200,7 +97,7 @@ static INLINE void vp8_atomic_spin_wait( const int nsync) { while (mb_col > (vpx_atomic_load_acquire(last_row_current_mb_col) - nsync)) { x86_pause_hint(); - thread_sleep(1000); + thread_sleep(0); } } diff --git a/libs/libvpx/vp8/common/vp8_loopfilter.c b/libs/libvpx/vp8/common/vp8_loopfilter.c index 9c9e5f351b..4576c18537 100644 --- a/libs/libvpx/vp8/common/vp8_loopfilter.c +++ b/libs/libvpx/vp8/common/vp8_loopfilter.c @@ -111,7 +111,7 @@ void vp8_loop_filter_frame_init(VP8_COMMON *cm, MACROBLOCKD *mbd, /* Note the baseline filter values for each segment */ if (mbd->segmentation_enabled) { - if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA) { + if (mbd->mb_segment_abs_delta == SEGMENT_ABSDATA) { lvl_seg = mbd->segment_feature_data[MB_LVL_ALT_LF][seg]; } else { /* Delta Value */ lvl_seg += mbd->segment_feature_data[MB_LVL_ALT_LF][seg]; diff --git a/libs/libvpx/vp8/decoder/dboolhuff.h b/libs/libvpx/vp8/decoder/dboolhuff.h index f2a18f0d90..673b2fbd5d 100644 --- a/libs/libvpx/vp8/decoder/dboolhuff.h +++ b/libs/libvpx/vp8/decoder/dboolhuff.h @@ -15,6 +15,7 @@ #include #include "./vpx_config.h" +#include "vpx_ports/compiler_attributes.h" #include "vpx_ports/mem.h" #include "vpx/vp8dx.h" #include "vpx/vpx_integer.h" @@ -50,7 +51,8 @@ int vp8dx_start_decode(BOOL_DECODER *br, const unsigned char *source, void vp8dx_bool_decoder_fill(BOOL_DECODER *br); -static int vp8dx_decode_bool(BOOL_DECODER *br, int probability) { +static VPX_NO_UNSIGNED_SHIFT_CHECK int vp8dx_decode_bool(BOOL_DECODER *br, + int probability) { unsigned int bit = 0; VP8_BD_VALUE value; unsigned int split; diff --git a/libs/libvpx/vp8/decoder/decodeframe.c b/libs/libvpx/vp8/decoder/decodeframe.c index 1c1566766b..bb3b415511 100644 --- a/libs/libvpx/vp8/decoder/decodeframe.c +++ b/libs/libvpx/vp8/decoder/decodeframe.c @@ -63,7 +63,7 @@ void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd) { /* Decide whether to use the default or alternate baseline Q value. */ if (xd->segmentation_enabled) { /* Abs Value */ - if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA) { + if (xd->mb_segment_abs_delta == SEGMENT_ABSDATA) { QIndex = xd->segment_feature_data[MB_LVL_ALT_Q][mbmi->segment_id]; /* Delta Value */ @@ -829,7 +829,7 @@ static void init_frame(VP8D_COMP *pbi) { /* reset the segment feature data to 0 with delta coding (Default state). */ memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data)); - xd->mb_segement_abs_delta = SEGMENT_DELTADATA; + xd->mb_segment_abs_delta = SEGMENT_DELTADATA; /* reset the mode ref deltasa for loop filter */ memset(xd->ref_lf_deltas, 0, sizeof(xd->ref_lf_deltas)); @@ -883,7 +883,7 @@ int vp8_decode_frame(VP8D_COMP *pbi) { const unsigned char *data = pbi->fragments.ptrs[0]; const unsigned int data_sz = pbi->fragments.sizes[0]; const unsigned char *data_end = data + data_sz; - ptrdiff_t first_partition_length_in_bytes; + int first_partition_length_in_bytes; int i, j, k, l; const int *const mb_feature_data_bits = vp8_mb_feature_data_bits; @@ -924,10 +924,9 @@ int vp8_decode_frame(VP8D_COMP *pbi) { first_partition_length_in_bytes = (clear[0] | (clear[1] << 8) | (clear[2] << 16)) >> 5; - if (!pbi->ec_active && (data + first_partition_length_in_bytes > data_end || - data + first_partition_length_in_bytes < data)) { + if (!pbi->ec_active && first_partition_length_in_bytes == 0) { vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, - "Truncated packet or corrupt partition 0 length"); + "Corrupt partition 0 length"); } data += 3; @@ -936,22 +935,16 @@ int vp8_decode_frame(VP8D_COMP *pbi) { vp8_setup_version(pc); if (pc->frame_type == KEY_FRAME) { - /* vet via sync code */ - /* When error concealment is enabled we should only check the sync - * code if we have enough bits available - */ - if (data + 3 < data_end) { + if (data_end - data >= 7) { + /* vet via sync code */ + /* When error concealment is enabled we should only check the sync + * code if we have enough bits available + */ if (clear[0] != 0x9d || clear[1] != 0x01 || clear[2] != 0x2a) { vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM, "Invalid frame sync code"); } - } - /* If error concealment is enabled we should only parse the new size - * if we have enough data. Otherwise we will end up with the wrong - * size. - */ - if (data + 6 < data_end) { pc->Width = (clear[3] | (clear[4] << 8)) & 0x3fff; pc->horiz_scale = clear[4] >> 6; pc->Height = (clear[5] | (clear[6] << 8)) & 0x3fff; @@ -965,14 +958,19 @@ int vp8_decode_frame(VP8D_COMP *pbi) { data = data_end; } } else { - memcpy(&xd->pre, yv12_fb_new, sizeof(YV12_BUFFER_CONFIG)); - memcpy(&xd->dst, yv12_fb_new, sizeof(YV12_BUFFER_CONFIG)); + xd->pre = *yv12_fb_new; + xd->dst = *yv12_fb_new; } } if ((!pbi->decoded_key_frame && pc->frame_type != KEY_FRAME)) { return -1; } + if (!pbi->ec_active && data_end - data < first_partition_length_in_bytes) { + vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, + "Truncated packet or corrupt partition 0 length"); + } + init_frame(pbi); if (vp8dx_start_decode(bc, data, (unsigned int)(data_end - data), @@ -995,7 +993,7 @@ int vp8_decode_frame(VP8D_COMP *pbi) { xd->update_mb_segmentation_data = (unsigned char)vp8_read_bit(bc); if (xd->update_mb_segmentation_data) { - xd->mb_segement_abs_delta = (unsigned char)vp8_read_bit(bc); + xd->mb_segment_abs_delta = (unsigned char)vp8_read_bit(bc); memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data)); @@ -1156,7 +1154,7 @@ int vp8_decode_frame(VP8D_COMP *pbi) { if (pbi->ec_active && xd->corrupted) pc->refresh_entropy_probs = 0; #endif if (pc->refresh_entropy_probs == 0) { - memcpy(&pc->lfc, &pc->fc, sizeof(pc->fc)); + pc->lfc = pc->fc; } pc->refresh_last_frame = pc->frame_type == KEY_FRAME || vp8_read_bit(bc); @@ -1167,14 +1165,6 @@ int vp8_decode_frame(VP8D_COMP *pbi) { if (pbi->ec_active && xd->corrupted) pc->refresh_last_frame = 1; #endif - if (0) { - FILE *z = fopen("decodestats.stt", "a"); - fprintf(z, "%6d F:%d,G:%d,A:%d,L:%d,Q:%d\n", pc->current_video_frame, - pc->frame_type, pc->refresh_golden_frame, pc->refresh_alt_ref_frame, - pc->refresh_last_frame, pc->base_qindex); - fclose(z); - } - { pbi->independent_partitions = 1; @@ -1253,7 +1243,7 @@ int vp8_decode_frame(VP8D_COMP *pbi) { * \n",bc->pos+pbi->bc2.pos); */ if (pc->refresh_entropy_probs == 0) { - memcpy(&pc->fc, &pc->lfc, sizeof(pc->fc)); + pc->fc = pc->lfc; pbi->independent_partitions = prev_independent_partitions; } diff --git a/libs/libvpx/vp8/decoder/decodemv.c b/libs/libvpx/vp8/decoder/decodemv.c index 51817a2cb9..3f459d623f 100644 --- a/libs/libvpx/vp8/decoder/decodemv.c +++ b/libs/libvpx/vp8/decoder/decodemv.c @@ -372,9 +372,9 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, tmp = cnt[CNT_NEAREST]; cnt[CNT_NEAREST] = cnt[CNT_NEAR]; cnt[CNT_NEAR] = tmp; - tmp = near_mvs[CNT_NEAREST].as_int; + tmp = (int)near_mvs[CNT_NEAREST].as_int; near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int; - near_mvs[CNT_NEAR].as_int = tmp; + near_mvs[CNT_NEAR].as_int = (uint32_t)tmp; } if (vp8_read(bc, vp8_mode_contexts[cnt[CNT_NEAREST]][1])) { diff --git a/libs/libvpx/vp8/decoder/onyxd_if.c b/libs/libvpx/vp8/decoder/onyxd_if.c index 765d2ec83e..88f2de024b 100644 --- a/libs/libvpx/vp8/decoder/onyxd_if.c +++ b/libs/libvpx/vp8/decoder/onyxd_if.c @@ -302,7 +302,7 @@ static int check_fragments_for_errors(VP8D_COMP *pbi) { return 1; } -int vp8dx_receive_compressed_data(VP8D_COMP *pbi, int64_t time_stamp) { +int vp8dx_receive_compressed_data(VP8D_COMP *pbi) { VP8_COMMON *cm = &pbi->common; int retcode = -1; @@ -368,14 +368,12 @@ int vp8dx_receive_compressed_data(VP8D_COMP *pbi, int64_t time_stamp) { #endif pbi->ready_for_new_data = 0; - pbi->last_time_stamp = time_stamp; decode_exit: vpx_clear_system_state(); return retcode; } int vp8dx_get_raw_frame(VP8D_COMP *pbi, YV12_BUFFER_CONFIG *sd, - int64_t *time_stamp, int64_t *time_end_stamp, vp8_ppflags_t *flags) { int ret = -1; @@ -385,8 +383,6 @@ int vp8dx_get_raw_frame(VP8D_COMP *pbi, YV12_BUFFER_CONFIG *sd, if (pbi->common.show_frame == 0) return ret; pbi->ready_for_new_data = 1; - *time_stamp = pbi->last_time_stamp; - *time_end_stamp = 0; #if CONFIG_POSTPROC ret = vp8_post_proc_frame(&pbi->common, sd, flags); @@ -432,6 +428,7 @@ int vp8_create_decoder_instances(struct frame_buffers *fb, VP8D_CONFIG *oxcf) { #if CONFIG_MULTITHREAD if (setjmp(fb->pbi[0]->common.error.jmp)) { + fb->pbi[0]->common.error.setjmp = 0; vp8_remove_decoder_instances(fb); vp8_zero(fb->pbi); vpx_clear_system_state(); @@ -456,6 +453,7 @@ int vp8_remove_decoder_instances(struct frame_buffers *fb) { /* decoder instance for single thread mode */ remove_decompressor(pbi); + fb->pbi[0] = NULL; return VPX_CODEC_OK; } diff --git a/libs/libvpx/vp8/decoder/onyxd_int.h b/libs/libvpx/vp8/decoder/onyxd_int.h index cf2c066d9b..08a60b31b9 100644 --- a/libs/libvpx/vp8/decoder/onyxd_int.h +++ b/libs/libvpx/vp8/decoder/onyxd_int.h @@ -11,7 +11,10 @@ #ifndef VPX_VP8_DECODER_ONYXD_INT_H_ #define VPX_VP8_DECODER_ONYXD_INT_H_ +#include + #include "vpx_config.h" +#include "vpx_util/vpx_pthread.h" #include "vp8/common/onyxd.h" #include "treereader.h" #include "vp8/common/onyxc_int.h" @@ -92,12 +95,11 @@ typedef struct VP8D_COMP { DECODETHREAD_DATA *de_thread_data; pthread_t *h_decoding_thread; - sem_t *h_event_start_decoding; - sem_t h_event_end_decoding; + vp8_sem_t *h_event_start_decoding; + vp8_sem_t h_event_end_decoding; /* end of threading data */ #endif - int64_t last_time_stamp; int ready_for_new_data; vp8_prob prob_intra; @@ -133,25 +135,6 @@ int vp8_decode_frame(VP8D_COMP *pbi); int vp8_create_decoder_instances(struct frame_buffers *fb, VP8D_CONFIG *oxcf); int vp8_remove_decoder_instances(struct frame_buffers *fb); -#if CONFIG_DEBUG -#define CHECK_MEM_ERROR(lval, expr) \ - do { \ - (lval) = (expr); \ - if (!(lval)) \ - vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR, \ - "Failed to allocate " #lval " at %s:%d", __FILE__, \ - __LINE__); \ - } while (0) -#else -#define CHECK_MEM_ERROR(lval, expr) \ - do { \ - (lval) = (expr); \ - if (!(lval)) \ - vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR, \ - "Failed to allocate " #lval); \ - } while (0) -#endif - #ifdef __cplusplus } // extern "C" #endif diff --git a/libs/libvpx/vp8/decoder/threading.c b/libs/libvpx/vp8/decoder/threading.c index 490f62d1b3..43d56493b0 100644 --- a/libs/libvpx/vp8/decoder/threading.c +++ b/libs/libvpx/vp8/decoder/threading.c @@ -15,6 +15,7 @@ #endif #include "onyxd_int.h" #include "vpx_mem/vpx_mem.h" +#include "vpx_util/vpx_pthread.h" #include "vp8/common/common.h" #include "vp8/common/threading.h" #include "vp8/common/loopfilter.h" @@ -30,11 +31,13 @@ #include "error_concealment.h" #endif -#define CALLOC_ARRAY(p, n) CHECK_MEM_ERROR((p), vpx_calloc(sizeof(*(p)), (n))) -#define CALLOC_ARRAY_ALIGNED(p, n, algn) \ - do { \ - CHECK_MEM_ERROR((p), vpx_memalign((algn), sizeof(*(p)) * (n))); \ - memset((p), 0, (n) * sizeof(*(p))); \ +#define CALLOC_ARRAY(p, n) \ + CHECK_MEM_ERROR(&pbi->common.error, (p), vpx_calloc(sizeof(*(p)), (n))) +#define CALLOC_ARRAY_ALIGNED(p, n, algn) \ + do { \ + CHECK_MEM_ERROR(&pbi->common.error, (p), \ + vpx_memalign((algn), sizeof(*(p)) * (n))); \ + memset((p), 0, (n) * sizeof(*(p))); \ } while (0) static void setup_decoding_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, @@ -44,6 +47,16 @@ static void setup_decoding_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, for (i = 0; i < count; ++i) { MACROBLOCKD *mbd = &mbrd[i].mbd; + + // The worker MACROBLOCKDs persist across frames, so reset the per-frame + // error state in line with the main thread (see vp8_decode_frame()). + // This should only be done for keyframes or when error concealment + // is active. + if (pc->frame_type == KEY_FRAME || pbi->ec_active) { + mbd->corrupted = 0; + } + mbd->error_info.error_code = 0; + mbd->subpixel_predict = xd->subpixel_predict; mbd->subpixel_predict8x4 = xd->subpixel_predict8x4; mbd->subpixel_predict8x8 = xd->subpixel_predict8x8; @@ -54,7 +67,7 @@ static void setup_decoding_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, mbd->dst = xd->dst; mbd->segmentation_enabled = xd->segmentation_enabled; - mbd->mb_segement_abs_delta = xd->mb_segement_abs_delta; + mbd->mb_segment_abs_delta = xd->mb_segment_abs_delta; memcpy(mbd->segment_feature_data, xd->segment_feature_data, sizeof(xd->segment_feature_data)); @@ -225,7 +238,7 @@ static void mt_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd, vp8_short_inv_walsh4x4(&b->dqcoeff[0], xd->qcoeff); memset(b->qcoeff, 0, 16 * sizeof(b->qcoeff[0])); } else { - b->dqcoeff[0] = b->qcoeff[0] * xd->dequant_y2[0]; + b->dqcoeff[0] = (short)(b->qcoeff[0] * xd->dequant_y2[0]); vp8_short_inv_walsh4x4_1(&b->dqcoeff[0], xd->qcoeff); memset(b->qcoeff, 0, 2 * sizeof(b->qcoeff[0])); } @@ -575,10 +588,10 @@ static void mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd, /* signal end of decoding of current thread for current frame */ if (last_mb_row + (int)pbi->decoding_thread_count + 1 >= pc->mb_rows) - sem_post(&pbi->h_event_end_decoding); + vp8_sem_post(&pbi->h_event_end_decoding); } -static THREAD_FUNCTION thread_decoding_proc(void *p_data) { +static THREADFN thread_decoding_proc(void *p_data) { int ithread = ((DECODETHREAD_DATA *)p_data)->ithread; VP8D_COMP *pbi = (VP8D_COMP *)(((DECODETHREAD_DATA *)p_data)->ptr1); MB_ROW_DEC *mbrd = (MB_ROW_DEC *)(((DECODETHREAD_DATA *)p_data)->ptr2); @@ -587,7 +600,7 @@ static THREAD_FUNCTION thread_decoding_proc(void *p_data) { while (1) { if (vpx_atomic_load_acquire(&pbi->b_multithreaded_rd) == 0) break; - if (sem_wait(&pbi->h_event_start_decoding[ithread]) == 0) { + if (vp8_sem_wait(&pbi->h_event_start_decoding[ithread]) == 0) { if (vpx_atomic_load_acquire(&pbi->b_multithreaded_rd) == 0) { break; } else { @@ -596,16 +609,17 @@ static THREAD_FUNCTION thread_decoding_proc(void *p_data) { if (setjmp(xd->error_info.jmp)) { xd->error_info.setjmp = 0; // Signal the end of decoding for current thread. - sem_post(&pbi->h_event_end_decoding); + vp8_sem_post(&pbi->h_event_end_decoding); continue; } xd->error_info.setjmp = 1; mt_decode_mb_rows(pbi, xd, ithread + 1); + xd->error_info.setjmp = 0; } } } - return 0; + return THREAD_EXIT_SUCCESS; } void vp8_decoder_create_threads(VP8D_COMP *pbi) { @@ -632,13 +646,13 @@ void vp8_decoder_create_threads(VP8D_COMP *pbi) { CALLOC_ARRAY_ALIGNED(pbi->mb_row_di, pbi->decoding_thread_count, 32); CALLOC_ARRAY(pbi->de_thread_data, pbi->decoding_thread_count); - if (sem_init(&pbi->h_event_end_decoding, 0, 0)) { + if (vp8_sem_init(&pbi->h_event_end_decoding, 0, 0)) { vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR, "Failed to initialize semaphore"); } for (ithread = 0; ithread < pbi->decoding_thread_count; ++ithread) { - if (sem_init(&pbi->h_event_start_decoding[ithread], 0, 0)) break; + if (vp8_sem_init(&pbi->h_event_start_decoding[ithread], 0, 0)) break; vp8_setup_block_dptrs(&pbi->mb_row_di[ithread].mbd); @@ -648,7 +662,7 @@ void vp8_decoder_create_threads(VP8D_COMP *pbi) { if (pthread_create(&pbi->h_decoding_thread[ithread], 0, thread_decoding_proc, &pbi->de_thread_data[ithread])) { - sem_destroy(&pbi->h_event_start_decoding[ithread]); + vp8_sem_destroy(&pbi->h_event_start_decoding[ithread]); break; } } @@ -659,7 +673,7 @@ void vp8_decoder_create_threads(VP8D_COMP *pbi) { /* the remainder of cleanup cases will be handled in * vp8_decoder_remove_threads(). */ if (pbi->allocated_decoding_thread_count == 0) { - sem_destroy(&pbi->h_event_end_decoding); + vp8_sem_destroy(&pbi->h_event_end_decoding); } vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR, "Failed to create threads"); @@ -754,7 +768,7 @@ void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows) { uv_width = width >> 1; /* Allocate a vpx_atomic_int for each mb row. */ - CHECK_MEM_ERROR(pbi->mt_current_mb_col, + CHECK_MEM_ERROR(&pc->error, pbi->mt_current_mb_col, vpx_malloc(sizeof(*pbi->mt_current_mb_col) * pc->mb_rows)); for (i = 0; i < pc->mb_rows; ++i) vpx_atomic_init(&pbi->mt_current_mb_col[i], 0); @@ -762,7 +776,7 @@ void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows) { /* Allocate memory for above_row buffers. */ CALLOC_ARRAY(pbi->mt_yabove_row, pc->mb_rows); for (i = 0; i < pc->mb_rows; ++i) { - CHECK_MEM_ERROR(pbi->mt_yabove_row[i], + CHECK_MEM_ERROR(&pc->error, pbi->mt_yabove_row[i], vpx_memalign(16, sizeof(unsigned char) * (width + (VP8BORDERINPIXELS << 1)))); vp8_zero_array(pbi->mt_yabove_row[i], width + (VP8BORDERINPIXELS << 1)); @@ -770,7 +784,7 @@ void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows) { CALLOC_ARRAY(pbi->mt_uabove_row, pc->mb_rows); for (i = 0; i < pc->mb_rows; ++i) { - CHECK_MEM_ERROR(pbi->mt_uabove_row[i], + CHECK_MEM_ERROR(&pc->error, pbi->mt_uabove_row[i], vpx_memalign(16, sizeof(unsigned char) * (uv_width + VP8BORDERINPIXELS))); vp8_zero_array(pbi->mt_uabove_row[i], uv_width + VP8BORDERINPIXELS); @@ -778,7 +792,7 @@ void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows) { CALLOC_ARRAY(pbi->mt_vabove_row, pc->mb_rows); for (i = 0; i < pc->mb_rows; ++i) { - CHECK_MEM_ERROR(pbi->mt_vabove_row[i], + CHECK_MEM_ERROR(&pc->error, pbi->mt_vabove_row[i], vpx_memalign(16, sizeof(unsigned char) * (uv_width + VP8BORDERINPIXELS))); vp8_zero_array(pbi->mt_vabove_row[i], uv_width + VP8BORDERINPIXELS); @@ -787,17 +801,17 @@ void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows) { /* Allocate memory for left_col buffers. */ CALLOC_ARRAY(pbi->mt_yleft_col, pc->mb_rows); for (i = 0; i < pc->mb_rows; ++i) - CHECK_MEM_ERROR(pbi->mt_yleft_col[i], + CHECK_MEM_ERROR(&pc->error, pbi->mt_yleft_col[i], vpx_calloc(sizeof(unsigned char) * 16, 1)); CALLOC_ARRAY(pbi->mt_uleft_col, pc->mb_rows); for (i = 0; i < pc->mb_rows; ++i) - CHECK_MEM_ERROR(pbi->mt_uleft_col[i], + CHECK_MEM_ERROR(&pc->error, pbi->mt_uleft_col[i], vpx_calloc(sizeof(unsigned char) * 8, 1)); CALLOC_ARRAY(pbi->mt_vleft_col, pc->mb_rows); for (i = 0; i < pc->mb_rows; ++i) - CHECK_MEM_ERROR(pbi->mt_vleft_col[i], + CHECK_MEM_ERROR(&pc->error, pbi->mt_vleft_col[i], vpx_calloc(sizeof(unsigned char) * 8, 1)); } } @@ -810,16 +824,16 @@ void vp8_decoder_remove_threads(VP8D_COMP *pbi) { /* allow all threads to exit */ for (i = 0; i < pbi->allocated_decoding_thread_count; ++i) { - sem_post(&pbi->h_event_start_decoding[i]); + vp8_sem_post(&pbi->h_event_start_decoding[i]); pthread_join(pbi->h_decoding_thread[i], NULL); } for (i = 0; i < pbi->allocated_decoding_thread_count; ++i) { - sem_destroy(&pbi->h_event_start_decoding[i]); + vp8_sem_destroy(&pbi->h_event_start_decoding[i]); } if (pbi->allocated_decoding_thread_count) { - sem_destroy(&pbi->h_event_end_decoding); + vp8_sem_destroy(&pbi->h_event_end_decoding); } vpx_free(pbi->h_decoding_thread); @@ -881,7 +895,7 @@ int vp8mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd) { pbi->decoding_thread_count); for (i = 0; i < pbi->decoding_thread_count; ++i) { - sem_post(&pbi->h_event_start_decoding[i]); + vp8_sem_post(&pbi->h_event_start_decoding[i]); } if (setjmp(xd->error_info.jmp)) { @@ -891,15 +905,23 @@ int vp8mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd) { // the current frame while the main thread starts decoding the next frame, // which causes a data race. for (i = 0; i < pbi->decoding_thread_count; ++i) - sem_wait(&pbi->h_event_end_decoding); + vp8_sem_wait(&pbi->h_event_end_decoding); return -1; } xd->error_info.setjmp = 1; mt_decode_mb_rows(pbi, xd, 0); + xd->error_info.setjmp = 0; for (i = 0; i < pbi->decoding_thread_count + 1; ++i) - sem_wait(&pbi->h_event_end_decoding); /* add back for each frame */ + vp8_sem_wait(&pbi->h_event_end_decoding); /* add back for each frame */ + + for (i = 0; i < pbi->decoding_thread_count; ++i) { + if (pbi->mb_row_di[i].mbd.error_info.error_code) { + xd->error_info = pbi->mb_row_di[i].mbd.error_info; + return -1; + } + } return 0; } diff --git a/libs/libvpx/vp8/encoder/arm/neon/fastquantizeb_neon.c b/libs/libvpx/vp8/encoder/arm/neon/fastquantizeb_neon.c index 6fc60805f6..950c943343 100644 --- a/libs/libvpx/vp8/encoder/arm/neon/fastquantizeb_neon.c +++ b/libs/libvpx/vp8/encoder/arm/neon/fastquantizeb_neon.c @@ -28,11 +28,11 @@ void vp8_fast_quantize_b_neon(BLOCK *b, BLOCKD *d) { zig_zag1 = vld1q_u16(inv_zig_zag + 8); int16x8_t x0, x1, sz0, sz1, y0, y1; uint16x8_t eob0, eob1; -#ifndef __aarch64__ +#if !VPX_ARCH_AARCH64 uint16x4_t eob_d16; uint32x2_t eob_d32; uint32x4_t eob_q32; -#endif // __arch64__ +#endif // !VPX_ARCH_AARCH64 /* sign of z: z >> 15 */ sz0 = vshrq_n_s16(z0, 15); @@ -70,7 +70,7 @@ void vp8_fast_quantize_b_neon(BLOCK *b, BLOCKD *d) { /* select the largest value */ eob0 = vmaxq_u16(eob0, eob1); -#ifdef __aarch64__ +#if VPX_ARCH_AARCH64 *d->eob = (int8_t)vmaxvq_u16(eob0); #else eob_d16 = vmax_u16(vget_low_u16(eob0), vget_high_u16(eob0)); @@ -79,7 +79,7 @@ void vp8_fast_quantize_b_neon(BLOCK *b, BLOCKD *d) { eob_d32 = vpmax_u32(eob_d32, eob_d32); vst1_lane_s8((int8_t *)d->eob, vreinterpret_s8_u32(eob_d32), 0); -#endif // __aarch64__ +#endif // VPX_ARCH_AARCH64 /* qcoeff = x */ vst1q_s16(d->qcoeff, x0); diff --git a/libs/libvpx/vp8/encoder/bitstream.c b/libs/libvpx/vp8/encoder/bitstream.c index 0e97af5f2e..7a391a08ab 100644 --- a/libs/libvpx/vp8/encoder/bitstream.c +++ b/libs/libvpx/vp8/encoder/bitstream.c @@ -19,6 +19,7 @@ #include #include "vpx/vpx_encoder.h" #include "vpx_mem/vpx_mem.h" +#include "vpx_ports/compiler_attributes.h" #include "vpx_ports/system_state.h" #include "bitstream.h" @@ -117,7 +118,9 @@ static void write_split(vp8_writer *bc, int x) { vp8_mbsplit_encodings + x); } -void vp8_pack_tokens(vp8_writer *w, const TOKENEXTRA *p, int xcount) { +void VPX_NO_UNSIGNED_SHIFT_CHECK vp8_pack_tokens(vp8_writer *w, + const TOKENEXTRA *p, + int xcount) { const TOKENEXTRA *stop = p + xcount; unsigned int split; int shift; @@ -498,7 +501,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi) { int ct[4]; vp8_find_near_mvs(xd, m, &n1, &n2, &best_mv, ct, rf, - cpi->common.ref_frame_sign_bias); + pc->ref_frame_sign_bias); vp8_clamp_mv2(&best_mv, xd); vp8_mv_ref_probs(mv_ref_p, ct); @@ -682,12 +685,12 @@ static int independent_coef_context_savings(VP8_COMP *cpi) { int k = 0; unsigned int prev_coef_count_sum[MAX_ENTROPY_TOKENS] = { 0 }; int prev_coef_savings[MAX_ENTROPY_TOKENS] = { 0 }; - const unsigned int(*probs)[MAX_ENTROPY_TOKENS]; + const unsigned int (*probs)[MAX_ENTROPY_TOKENS]; /* Calculate new probabilities given the constraint that * they must be equal over the prev coef contexts */ - probs = (const unsigned int(*)[MAX_ENTROPY_TOKENS])x->coef_counts[i][j]; + probs = (const unsigned int (*)[MAX_ENTROPY_TOKENS])x->coef_counts[i][j]; /* Reset to default probabilities at key frames */ if (cpi->common.frame_type == KEY_FRAME) { @@ -1018,7 +1021,7 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, bc[0].error = &pc->error; - validate_buffer(cx_data, 3, cx_data_end, &cpi->common.error); + validate_buffer(cx_data, 3, cx_data_end, &pc->error); cx_data += 3; #if defined(SECTIONBITS_OUTPUT) @@ -1031,7 +1034,7 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, if (oh.type == KEY_FRAME) { int v; - validate_buffer(cx_data, 7, cx_data_end, &cpi->common.error); + validate_buffer(cx_data, 7, cx_data_end, &pc->error); /* Start / synch code */ cx_data[0] = 0x9D; @@ -1077,7 +1080,7 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, if (xd->update_mb_segmentation_data) { signed char Data; - vp8_write_bit(bc, xd->mb_segement_abs_delta); + vp8_write_bit(bc, xd->mb_segment_abs_delta); /* For each segmentation feature (Quant and loop filter level) */ for (i = 0; i < MB_LVL_MAX; ++i) { @@ -1240,7 +1243,7 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, #else if (pc->refresh_entropy_probs == 0) { /* save a copy for later refresh */ - memcpy(&cpi->common.lfc, &cpi->common.fc, sizeof(cpi->common.fc)); + pc->lfc = pc->fc; } vp8_update_coef_probs(cpi); diff --git a/libs/libvpx/vp8/encoder/denoising.c b/libs/libvpx/vp8/encoder/denoising.c index e54d1e9f4b..38d9dc2ebf 100644 --- a/libs/libvpx/vp8/encoder/denoising.c +++ b/libs/libvpx/vp8/encoder/denoising.c @@ -135,7 +135,7 @@ int vp8_denoiser_filter_c(unsigned char *mc_running_avg_y, int mc_avg_y_stride, // When adopting aggressive denoiser, the adj_val for each pixel // could be at most 8 (this is current max adjustment of the map). // In SSE code, we calculate the sum of adj_val for - // the columns, so the sum could be upto 128(16 rows). However, + // the columns, so the sum could be up to 128(16 rows). However, // the range of the value is -128 ~ 127 in SSE code, that's why // we do this change in C code. // We don't do this for UV denoiser, since there are only 8 rows, @@ -465,6 +465,7 @@ void vp8_denoiser_free(VP8_DENOISER *denoiser) { vp8_yv12_de_alloc_frame_buffer(&denoiser->yv12_mc_running_avg); vp8_yv12_de_alloc_frame_buffer(&denoiser->yv12_last_source); vpx_free(denoiser->denoise_state); + denoiser->denoise_state = NULL; } void vp8_denoiser_denoise_mb(VP8_DENOISER *denoiser, MACROBLOCK *x, diff --git a/libs/libvpx/vp8/encoder/encodeframe.c b/libs/libvpx/vp8/encoder/encodeframe.c index 620107500a..5dd7311019 100644 --- a/libs/libvpx/vp8/encoder/encodeframe.c +++ b/libs/libvpx/vp8/encoder/encodeframe.c @@ -7,36 +7,35 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include +#include #include "vpx_config.h" -#include "vp8_rtcd.h" -#include "./vpx_dsp_rtcd.h" -#include "bitstream.h" -#include "encodemb.h" -#include "encodemv.h" -#if CONFIG_MULTITHREAD -#include "ethreading.h" -#endif + #include "vp8/common/common.h" -#include "onyx_int.h" -#include "vp8/common/extend.h" #include "vp8/common/entropymode.h" -#include "vp8/common/quant_common.h" -#include "segmentation.h" -#include "vp8/common/setupintrarecon.h" -#include "encodeintra.h" -#include "vp8/common/reconinter.h" -#include "rdopt.h" -#include "pickinter.h" -#include "vp8/common/findnearmv.h" -#include -#include +#include "vp8/common/extend.h" #include "vp8/common/invtrans.h" +#include "vp8/common/quant_common.h" +#include "vp8/common/reconinter.h" +#include "vp8/common/setupintrarecon.h" +#include "vp8/common/threading.h" +#include "vp8/encoder/bitstream.h" +#include "vp8/encoder/encodeframe.h" +#include "vp8/encoder/encodeintra.h" +#include "vp8/encoder/encodemb.h" +#include "vp8/encoder/onyx_int.h" +#include "vp8/encoder/pickinter.h" +#include "vp8/encoder/rdopt.h" +#include "vp8_rtcd.h" +#include "vpx/internal/vpx_codec_internal.h" +#include "vpx_dsp_rtcd.h" +#include "vpx_mem/vpx_mem.h" #include "vpx_ports/vpx_timer.h" -#if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING -#include "bitstream.h" + +#if CONFIG_MULTITHREAD +#include "vp8/encoder/ethreading.h" #endif -#include "encodeframe.h" extern void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t); static void adjust_act_zbin(VP8_COMP *cpi, MACROBLOCK *x); @@ -97,8 +96,7 @@ static unsigned int mb_activity_measure(MACROBLOCK *x, int mb_row, int mb_col) { unsigned int mb_activity; if (ALT_ACT_MEASURE) { - int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row); - + int use_dc_pred = (mb_col > 1 && mb_row > 1); /* Or use an alternative. */ mb_activity = vp8_encode_intra(x, use_dc_pred); } else { @@ -123,7 +121,7 @@ static void calc_av_activity(VP8_COMP *cpi, int64_t activity_sum) { unsigned int tmp; /* Create a list to sort to */ - CHECK_MEM_ERROR(sortlist, + CHECK_MEM_ERROR(&cpi->common.error, sortlist, vpx_calloc(sizeof(unsigned int), cpi->common.MBs)); /* Copy map to sort list */ @@ -445,13 +443,21 @@ static void encode_mb_row(VP8_COMP *cpi, VP8_COMMON *cm, int mb_row, x->active_ptr = cpi->active_map + map_index + mb_col; if (cm->frame_type == KEY_FRAME) { - *totalrate += vp8cx_encode_intra_macroblock(cpi, x, tp); + const int intra_rate_cost = vp8cx_encode_intra_macroblock(cpi, x, tp); + if (INT_MAX - *totalrate > intra_rate_cost) + *totalrate += intra_rate_cost; + else + *totalrate = INT_MAX; #ifdef MODE_STATS y_modes[xd->mbmi.mode]++; #endif } else { - *totalrate += vp8cx_encode_inter_macroblock( + const int inter_rate_cost = vp8cx_encode_inter_macroblock( cpi, x, tp, recon_yoffset, recon_uvoffset, mb_row, mb_col); + if (INT_MAX - *totalrate > inter_rate_cost) + *totalrate += inter_rate_cost; + else + *totalrate = INT_MAX; #ifdef MODE_STATS inter_y_modes[xd->mbmi.mode]++; @@ -607,6 +613,7 @@ static void init_encode_frame_mb_context(VP8_COMP *cpi) { x->mvc = cm->fc.mvc; + xd->above_context = cm->above_context; memset(cm->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * cm->mb_cols); /* Special case treatment when GF and ARF are not sensible options @@ -740,8 +747,10 @@ void vp8_encode_frame(VP8_COMP *cpi) { #endif { +#if CONFIG_INTERNAL_STATS struct vpx_usec_timer emr_timer; vpx_usec_timer_start(&emr_timer); +#endif #if CONFIG_MULTITHREAD if (vpx_atomic_load_acquire(&cpi->b_multi_threaded)) { @@ -750,11 +759,20 @@ void vp8_encode_frame(VP8_COMP *cpi) { vp8cx_init_mbrthread_data(cpi, x, cpi->mb_row_ei, cpi->encoding_thread_count); + if (cpi->mt_current_mb_col_size != cm->mb_rows) { + vpx_free(cpi->mt_current_mb_col); + cpi->mt_current_mb_col = NULL; + cpi->mt_current_mb_col_size = 0; + CHECK_MEM_ERROR( + &cpi->common.error, cpi->mt_current_mb_col, + vpx_malloc(sizeof(*cpi->mt_current_mb_col) * cm->mb_rows)); + cpi->mt_current_mb_col_size = cm->mb_rows; + } for (i = 0; i < cm->mb_rows; ++i) vpx_atomic_store_release(&cpi->mt_current_mb_col[i], -1); for (i = 0; i < cpi->encoding_thread_count; ++i) { - sem_post(&cpi->h_event_start_encoding[i]); + vp8_sem_post(&cpi->h_event_start_encoding[i]); } for (mb_row = 0; mb_row < cm->mb_rows; @@ -787,7 +805,7 @@ void vp8_encode_frame(VP8_COMP *cpi) { } /* Wait for all the threads to finish. */ for (i = 0; i < cpi->encoding_thread_count; ++i) { - sem_wait(&cpi->h_event_end_encoding[i]); + vp8_sem_wait(&cpi->h_event_end_encoding[i]); } for (mb_row = 0; mb_row < cm->mb_rows; ++mb_row) { @@ -810,7 +828,13 @@ void vp8_encode_frame(VP8_COMP *cpi) { for (i = 0; i < cpi->encoding_thread_count; ++i) { int mode_count; int c_idx; - totalrate += cpi->mb_row_ei[i].totalrate; + /* Saturate like encode_mb_row(); per-thread totalrate is already + * clamped to INT_MAX individually, so their sum can overflow. */ + const int thread_rate = cpi->mb_row_ei[i].totalrate; + if (INT_MAX - totalrate > thread_rate) + totalrate += thread_rate; + else + totalrate = INT_MAX; cpi->mb.skip_true_count += cpi->mb_row_ei[i].mb.skip_true_count; @@ -878,8 +902,10 @@ void vp8_encode_frame(VP8_COMP *cpi) { } #endif +#if CONFIG_INTERNAL_STATS vpx_usec_timer_mark(&emr_timer); cpi->time_encode_mb_row += vpx_usec_timer_elapsed(&emr_timer); +#endif } // Work out the segment probabilities if segmentation is enabled diff --git a/libs/libvpx/vp8/encoder/encodemb.c b/libs/libvpx/vp8/encoder/encodemb.c index 3fd8d5fabe..052d09ba3b 100644 --- a/libs/libvpx/vp8/encoder/encodemb.c +++ b/libs/libvpx/vp8/encoder/encodemb.c @@ -396,8 +396,8 @@ static void optimize_mb(MACROBLOCK *x) { ENTROPY_CONTEXT *ta; ENTROPY_CONTEXT *tl; - memcpy(&t_above, x->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES)); - memcpy(&t_left, x->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES)); + t_above = *x->e_mbd.above_context; + t_left = *x->e_mbd.left_context; ta = (ENTROPY_CONTEXT *)&t_above; tl = (ENTROPY_CONTEXT *)&t_left; @@ -437,8 +437,8 @@ void vp8_optimize_mby(MACROBLOCK *x) { if (!x->e_mbd.left_context) return; - memcpy(&t_above, x->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES)); - memcpy(&t_left, x->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES)); + t_above = *x->e_mbd.above_context; + t_left = *x->e_mbd.left_context; ta = (ENTROPY_CONTEXT *)&t_above; tl = (ENTROPY_CONTEXT *)&t_left; @@ -470,8 +470,8 @@ void vp8_optimize_mbuv(MACROBLOCK *x) { if (!x->e_mbd.left_context) return; - memcpy(&t_above, x->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES)); - memcpy(&t_left, x->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES)); + t_above = *x->e_mbd.above_context; + t_left = *x->e_mbd.left_context; ta = (ENTROPY_CONTEXT *)&t_above; tl = (ENTROPY_CONTEXT *)&t_left; diff --git a/libs/libvpx/vp8/encoder/encodemv.c b/libs/libvpx/vp8/encoder/encodemv.c index c88ea1653e..384bb29389 100644 --- a/libs/libvpx/vp8/encoder/encodemv.c +++ b/libs/libvpx/vp8/encoder/encodemv.c @@ -31,17 +31,15 @@ static void encode_mvcomponent(vp8_writer *const w, const int v, vp8_write(w, 1, p[mvpis_short]); - do + do { vp8_write(w, (x >> i) & 1, p[MVPbits + i]); - - while (++i < 3); + } while (++i < 3); i = mvlong_width - 1; /* Skip bit 3, which is sometimes implicit */ - do + do { vp8_write(w, (x >> i) & 1, p[MVPbits + i]); - - while (--i > 3); + } while (--i > 3); if (x & 0xFFF0) vp8_write(w, (x >> 3) & 1, p[MVPbits + 3]); } diff --git a/libs/libvpx/vp8/encoder/ethreading.c b/libs/libvpx/vp8/encoder/ethreading.c index cb35f4f491..98c87d3cbc 100644 --- a/libs/libvpx/vp8/encoder/ethreading.c +++ b/libs/libvpx/vp8/encoder/ethreading.c @@ -7,8 +7,10 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include #include "onyx_int.h" +#include "vpx_util/vpx_pthread.h" #include "vp8/common/threading.h" #include "vp8/common/common.h" #include "vp8/common/extend.h" @@ -21,27 +23,27 @@ extern void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip); -static THREAD_FUNCTION thread_loopfilter(void *p_data) { +static THREADFN thread_loopfilter(void *p_data) { VP8_COMP *cpi = (VP8_COMP *)(((LPFTHREAD_DATA *)p_data)->ptr1); VP8_COMMON *cm = &cpi->common; while (1) { if (vpx_atomic_load_acquire(&cpi->b_multi_threaded) == 0) break; - if (sem_wait(&cpi->h_event_start_lpf) == 0) { + if (vp8_sem_wait(&cpi->h_event_start_lpf) == 0) { /* we're shutting down */ if (vpx_atomic_load_acquire(&cpi->b_multi_threaded) == 0) break; vp8_loopfilter_frame(cpi, cm); - sem_post(&cpi->h_event_end_lpf); + vp8_sem_post(&cpi->h_event_end_lpf); } } - return 0; + return THREAD_EXIT_SUCCESS; } -static THREAD_FUNCTION thread_encoding_proc(void *p_data) { +static THREADFN thread_encoding_proc(void *p_data) { int ithread = ((ENCODETHREAD_DATA *)p_data)->ithread; VP8_COMP *cpi = (VP8_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr1); MB_ROW_COMP *mbri = (MB_ROW_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr2); @@ -50,7 +52,7 @@ static THREAD_FUNCTION thread_encoding_proc(void *p_data) { while (1) { if (vpx_atomic_load_acquire(&cpi->b_multi_threaded) == 0) break; - if (sem_wait(&cpi->h_event_start_encoding[ithread]) == 0) { + if (vp8_sem_wait(&cpi->h_event_start_encoding[ithread]) == 0) { const int nsync = cpi->mt_sync_range; VP8_COMMON *cm = &cpi->common; int mb_row; @@ -306,12 +308,12 @@ static THREAD_FUNCTION thread_encoding_proc(void *p_data) { x->gf_active_ptr += cm->mb_cols * cpi->encoding_thread_count; } /* Signal that this thread has completed processing its rows. */ - sem_post(&cpi->h_event_end_encoding[ithread]); + vp8_sem_post(&cpi->h_event_end_encoding[ithread]); } } /* printf("exit thread %d\n", ithread); */ - return 0; + return THREAD_EXIT_SUCCESS; } static void setup_mbby_copy(MACROBLOCK *mbdst, MACROBLOCK *mbsrc) { @@ -402,7 +404,7 @@ static void setup_mbby_copy(MACROBLOCK *mbdst, MACROBLOCK *mbsrc) { zd->subpixel_predict8x8 = xd->subpixel_predict8x8; zd->subpixel_predict16x16 = xd->subpixel_predict16x16; zd->segmentation_enabled = xd->segmentation_enabled; - zd->mb_segement_abs_delta = xd->mb_segement_abs_delta; + zd->mb_segment_abs_delta = xd->mb_segment_abs_delta; memcpy(zd->segment_feature_data, xd->segment_feature_data, sizeof(xd->segment_feature_data)); @@ -487,15 +489,10 @@ void vp8cx_init_mbrthread_data(VP8_COMP *cpi, MACROBLOCK *x, int vp8cx_create_encoder_threads(VP8_COMP *cpi) { const VP8_COMMON *cm = &cpi->common; - - vpx_atomic_init(&cpi->b_multi_threaded, 0); - cpi->encoding_thread_count = 0; - cpi->b_lpf_running = 0; + int th_count = 0; if (cm->processor_core_count > 1 && cpi->oxcf.multi_threaded > 1) { - int ithread; - int th_count = cpi->oxcf.multi_threaded - 1; - int rc = 0; + th_count = cpi->oxcf.multi_threaded - 1; /* don't allocate more threads than cores available */ if (cpi->oxcf.multi_threaded > cm->processor_core_count) { @@ -507,19 +504,24 @@ int vp8cx_create_encoder_threads(VP8_COMP *cpi) { if (th_count > ((cm->mb_cols / cpi->mt_sync_range) - 1)) { th_count = (cm->mb_cols / cpi->mt_sync_range) - 1; } + } + if (th_count == cpi->encoding_thread_count) return 0; - if (th_count == 0) return 0; + vp8cx_remove_encoder_threads(cpi); + if (th_count != 0) { + int ithread; + int rc = 0; - CHECK_MEM_ERROR(cpi->h_encoding_thread, + CHECK_MEM_ERROR(&cpi->common.error, cpi->h_encoding_thread, vpx_malloc(sizeof(pthread_t) * th_count)); - CHECK_MEM_ERROR(cpi->h_event_start_encoding, - vpx_malloc(sizeof(sem_t) * th_count)); - CHECK_MEM_ERROR(cpi->h_event_end_encoding, - vpx_malloc(sizeof(sem_t) * th_count)); - CHECK_MEM_ERROR(cpi->mb_row_ei, + CHECK_MEM_ERROR(&cpi->common.error, cpi->h_event_start_encoding, + vpx_malloc(sizeof(vp8_sem_t) * th_count)); + CHECK_MEM_ERROR(&cpi->common.error, cpi->h_event_end_encoding, + vpx_malloc(sizeof(vp8_sem_t) * th_count)); + CHECK_MEM_ERROR(&cpi->common.error, cpi->mb_row_ei, vpx_memalign(32, sizeof(MB_ROW_COMP) * th_count)); memset(cpi->mb_row_ei, 0, sizeof(MB_ROW_COMP) * th_count); - CHECK_MEM_ERROR(cpi->en_thread_data, + CHECK_MEM_ERROR(&cpi->common.error, cpi->en_thread_data, vpx_malloc(sizeof(ENCODETHREAD_DATA) * th_count)); vpx_atomic_store_release(&cpi->b_multi_threaded, 1); @@ -537,8 +539,8 @@ int vp8cx_create_encoder_threads(VP8_COMP *cpi) { vp8_setup_block_ptrs(&cpi->mb_row_ei[ithread].mb); vp8_setup_block_dptrs(&cpi->mb_row_ei[ithread].mb.e_mbd); - sem_init(&cpi->h_event_start_encoding[ithread], 0, 0); - sem_init(&cpi->h_event_end_encoding[ithread], 0, 0); + vp8_sem_init(&cpi->h_event_start_encoding[ithread], 0, 0); + vp8_sem_init(&cpi->h_event_end_encoding[ithread], 0, 0); ethd->ithread = ithread; ethd->ptr1 = (void *)cpi; @@ -553,17 +555,25 @@ int vp8cx_create_encoder_threads(VP8_COMP *cpi) { /* shutdown other threads */ vpx_atomic_store_release(&cpi->b_multi_threaded, 0); for (--ithread; ithread >= 0; ithread--) { + vp8_sem_post(&cpi->h_event_start_encoding[ithread]); + vp8_sem_post(&cpi->h_event_end_encoding[ithread]); pthread_join(cpi->h_encoding_thread[ithread], 0); - sem_destroy(&cpi->h_event_start_encoding[ithread]); - sem_destroy(&cpi->h_event_end_encoding[ithread]); + vp8_sem_destroy(&cpi->h_event_start_encoding[ithread]); + vp8_sem_destroy(&cpi->h_event_end_encoding[ithread]); } /* free thread related resources */ vpx_free(cpi->h_event_start_encoding); + cpi->h_event_start_encoding = NULL; vpx_free(cpi->h_event_end_encoding); + cpi->h_event_end_encoding = NULL; vpx_free(cpi->h_encoding_thread); + cpi->h_encoding_thread = NULL; vpx_free(cpi->mb_row_ei); + cpi->mb_row_ei = NULL; vpx_free(cpi->en_thread_data); + cpi->en_thread_data = NULL; + cpi->encoding_thread_count = 0; return -1; } @@ -571,8 +581,8 @@ int vp8cx_create_encoder_threads(VP8_COMP *cpi) { { LPFTHREAD_DATA *lpfthd = &cpi->lpf_thread_data; - sem_init(&cpi->h_event_start_lpf, 0, 0); - sem_init(&cpi->h_event_end_lpf, 0, 0); + vp8_sem_init(&cpi->h_event_start_lpf, 0, 0); + vp8_sem_init(&cpi->h_event_end_lpf, 0, 0); lpfthd->ptr1 = (void *)cpi; rc = pthread_create(&cpi->h_filter_thread, 0, thread_loopfilter, lpfthd); @@ -581,21 +591,27 @@ int vp8cx_create_encoder_threads(VP8_COMP *cpi) { /* shutdown other threads */ vpx_atomic_store_release(&cpi->b_multi_threaded, 0); for (--ithread; ithread >= 0; ithread--) { - sem_post(&cpi->h_event_start_encoding[ithread]); - sem_post(&cpi->h_event_end_encoding[ithread]); + vp8_sem_post(&cpi->h_event_start_encoding[ithread]); + vp8_sem_post(&cpi->h_event_end_encoding[ithread]); pthread_join(cpi->h_encoding_thread[ithread], 0); - sem_destroy(&cpi->h_event_start_encoding[ithread]); - sem_destroy(&cpi->h_event_end_encoding[ithread]); + vp8_sem_destroy(&cpi->h_event_start_encoding[ithread]); + vp8_sem_destroy(&cpi->h_event_end_encoding[ithread]); } - sem_destroy(&cpi->h_event_end_lpf); - sem_destroy(&cpi->h_event_start_lpf); + vp8_sem_destroy(&cpi->h_event_end_lpf); + vp8_sem_destroy(&cpi->h_event_start_lpf); /* free thread related resources */ vpx_free(cpi->h_event_start_encoding); + cpi->h_event_start_encoding = NULL; vpx_free(cpi->h_event_end_encoding); + cpi->h_event_end_encoding = NULL; vpx_free(cpi->h_encoding_thread); + cpi->h_encoding_thread = NULL; vpx_free(cpi->mb_row_ei); + cpi->mb_row_ei = NULL; vpx_free(cpi->en_thread_data); + cpi->en_thread_data = NULL; + cpi->encoding_thread_count = 0; return -2; } @@ -612,28 +628,38 @@ void vp8cx_remove_encoder_threads(VP8_COMP *cpi) { int i; for (i = 0; i < cpi->encoding_thread_count; ++i) { - sem_post(&cpi->h_event_start_encoding[i]); - sem_post(&cpi->h_event_end_encoding[i]); + vp8_sem_post(&cpi->h_event_start_encoding[i]); + vp8_sem_post(&cpi->h_event_end_encoding[i]); pthread_join(cpi->h_encoding_thread[i], 0); - sem_destroy(&cpi->h_event_start_encoding[i]); - sem_destroy(&cpi->h_event_end_encoding[i]); + vp8_sem_destroy(&cpi->h_event_start_encoding[i]); + vp8_sem_destroy(&cpi->h_event_end_encoding[i]); } - sem_post(&cpi->h_event_start_lpf); + vp8_sem_post(&cpi->h_event_start_lpf); pthread_join(cpi->h_filter_thread, 0); } - sem_destroy(&cpi->h_event_end_lpf); - sem_destroy(&cpi->h_event_start_lpf); + vp8_sem_destroy(&cpi->h_event_end_lpf); + vp8_sem_destroy(&cpi->h_event_start_lpf); + cpi->b_lpf_running = 0; /* free thread related resources */ + vpx_free(cpi->mt_current_mb_col); + cpi->mt_current_mb_col = NULL; + cpi->mt_current_mb_col_size = 0; vpx_free(cpi->h_event_start_encoding); + cpi->h_event_start_encoding = NULL; vpx_free(cpi->h_event_end_encoding); + cpi->h_event_end_encoding = NULL; vpx_free(cpi->h_encoding_thread); + cpi->h_encoding_thread = NULL; vpx_free(cpi->mb_row_ei); + cpi->mb_row_ei = NULL; vpx_free(cpi->en_thread_data); + cpi->en_thread_data = NULL; + cpi->encoding_thread_count = 0; } } #endif diff --git a/libs/libvpx/vp8/encoder/firstpass.c b/libs/libvpx/vp8/encoder/firstpass.c index ed177e3cb6..097dc0ed78 100644 --- a/libs/libvpx/vp8/encoder/firstpass.c +++ b/libs/libvpx/vp8/encoder/firstpass.c @@ -10,6 +10,7 @@ #include #include +#include #include #include "./vpx_dsp_rtcd.h" @@ -17,6 +18,7 @@ #include "block.h" #include "onyx_int.h" #include "vpx_dsp/variance.h" +#include "vpx_dsp/vpx_dsp_common.h" #include "encodeintra.h" #include "vp8/common/common.h" #include "vp8/common/setupintrarecon.h" @@ -52,7 +54,7 @@ extern const int vp8_gf_boost_qadjustment[QINDEX_RANGE]; #define KF_MB_INTRA_MIN 300 #define GF_MB_INTRA_MIN 200 -#define DOUBLE_DIVIDE_CHECK(X) ((X) < 0 ? (X)-.000001 : (X) + .000001) +#define DOUBLE_DIVIDE_CHECK(X) ((X) < 0 ? (X) - .000001 : (X) + .000001) #define POW1 (double)cpi->oxcf.two_pass_vbrbias / 100.0 #define POW2 (double)cpi->oxcf.two_pass_vbrbias / 100.0 @@ -352,10 +354,11 @@ static int frame_max_bits(VP8_COMP *cpi) { /* For VBR base this on the bits and frames left plus the * two_pass_vbrmax_section rate passed in by the user */ - max_bits = (int)(((double)cpi->twopass.bits_left / - (cpi->twopass.total_stats.count - - (double)cpi->common.current_video_frame)) * - ((double)cpi->oxcf.two_pass_vbrmax_section / 100.0)); + max_bits = saturate_cast_double_to_int( + ((double)cpi->twopass.bits_left / + (cpi->twopass.total_stats.count - + (double)cpi->common.current_video_frame)) * + ((double)cpi->oxcf.two_pass_vbrmax_section / 100.0)); } /* Trap case where we are out of bits */ @@ -412,7 +415,7 @@ static void first_pass_motion_search(VP8_COMP *cpi, MACROBLOCK *x, int_mv ref_mv_full; int tmp_err; - int step_param = 3; /* Dont search over full range for first pass */ + int step_param = 3; /* Don't search over full range for first pass */ int further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param; int n; vp8_variance_fn_ptr_t v_fn_ptr = cpi->fn_ptr[BLOCK_16X16]; @@ -792,7 +795,7 @@ void vp8_first_pass(VP8_COMP *cpi) { fps.duration = (double)(cpi->source->ts_end - cpi->source->ts_start); /* don't want to do output stats with a stack variable! */ - memcpy(&cpi->twopass.this_frame_stats, &fps, sizeof(FIRSTPASS_STATS)); + cpi->twopass.this_frame_stats = fps; output_stats(cpi->output_pkt_list, &cpi->twopass.this_frame_stats); accumulate_stats(&cpi->twopass.total_stats, &fps); } @@ -821,22 +824,6 @@ void vp8_first_pass(VP8_COMP *cpi) { vp8_yv12_copy_frame(lst_yv12, gld_yv12); } - /* use this to see what the first pass reconstruction looks like */ - if (0) { - char filename[512]; - FILE *recon_file; - sprintf(filename, "enc%04d.yuv", (int)cm->current_video_frame); - - if (cm->current_video_frame == 0) { - recon_file = fopen(filename, "wb"); - } else { - recon_file = fopen(filename, "ab"); - } - - (void)fwrite(lst_yv12->buffer_alloc, lst_yv12->frame_size, 1, recon_file); - fclose(recon_file); - } - cm->current_video_frame++; } extern const int vp8_bits_per_mb[2][QINDEX_RANGE]; @@ -903,9 +890,9 @@ static double calc_correction_factor(double err_per_mb, double err_devisor, correction_factor = pow(error_term, power_term); /* Clip range */ - correction_factor = (correction_factor < 0.05) - ? 0.05 - : (correction_factor > 5.0) ? 5.0 : correction_factor; + correction_factor = (correction_factor < 0.05) ? 0.05 + : (correction_factor > 5.0) ? 5.0 + : correction_factor; return correction_factor; } @@ -947,11 +934,10 @@ static int estimate_max_q(VP8_COMP *cpi, FIRSTPASS_STATS *fpstats, } cpi->twopass.est_max_qcorrection_factor = - (cpi->twopass.est_max_qcorrection_factor < 0.1) - ? 0.1 - : (cpi->twopass.est_max_qcorrection_factor > 10.0) - ? 10.0 - : cpi->twopass.est_max_qcorrection_factor; + (cpi->twopass.est_max_qcorrection_factor < 0.1) ? 0.1 + : (cpi->twopass.est_max_qcorrection_factor > 10.0) + ? 10.0 + : cpi->twopass.est_max_qcorrection_factor; } /* Corrections for higher compression speed settings @@ -1039,12 +1025,6 @@ static int estimate_cq(VP8_COMP *cpi, FIRSTPASS_STATS *fpstats, double clip_iifactor; int overhead_bits_per_mb; - if (0) { - FILE *f = fopen("epmp.stt", "a"); - fprintf(f, "%10.2f\n", err_per_mb); - fclose(f); - } - target_norm_bits_per_mb = (section_target_bandwitdh < (1 << 20)) ? (512 * section_target_bandwitdh) / num_mbs : 512 * (section_target_bandwitdh / num_mbs); @@ -1178,10 +1158,9 @@ static int estimate_kf_group_q(VP8_COMP *cpi, double section_err, } else { current_spend_ratio = (double)cpi->long_rolling_actual_bits / (double)cpi->long_rolling_target_bits; - current_spend_ratio = - (current_spend_ratio > 10.0) - ? 10.0 - : (current_spend_ratio < 0.1) ? 0.1 : current_spend_ratio; + current_spend_ratio = (current_spend_ratio > 10.0) ? 10.0 + : (current_spend_ratio < 0.1) ? 0.1 + : current_spend_ratio; } /* Calculate a correction factor based on the quality of prediction in @@ -1232,17 +1211,6 @@ static int estimate_kf_group_q(VP8_COMP *cpi, double section_err, Q++; } - if (0) { - FILE *f = fopen("estkf_q.stt", "a"); - fprintf(f, "%8d %8d %8d %8.2f %8.3f %8.2f %8.3f %8.3f %8.3f %8d\n", - cpi->common.current_video_frame, bits_per_mb_at_this_q, - target_norm_bits_per_mb, err_per_mb, err_correction_factor, - current_spend_ratio, group_iiratio, iiratio_correction_factor, - (double)cpi->buffer_level / (double)cpi->oxcf.optimal_buffer_level, - Q); - fclose(f); - } - return Q; } @@ -1270,7 +1238,6 @@ void vp8_init_second_pass(VP8_COMP *cpi) { vp8_new_framerate(cpi, 10000000.0 * cpi->twopass.total_stats.count / cpi->twopass.total_stats.duration); - cpi->output_framerate = cpi->framerate; cpi->twopass.bits_left = (int64_t)(cpi->twopass.total_stats.duration * cpi->oxcf.target_bandwidth / 10000000.0); cpi->twopass.bits_left -= (int64_t)(cpi->twopass.total_stats.duration * @@ -1539,7 +1506,7 @@ static int calc_arf_boost(VP8_COMP *cpi, int offset, int f_frames, int b_frames, /* Calculate the baseline boost number for this frame */ r = calc_frame_boost(cpi, &this_frame, this_frame_mv_in_out); - /* We want to discount the the flash frame itself and the recovery + /* We want to discount the flash frame itself and the recovery * frame that follows as both will have poor scores. */ flash_detected = @@ -1583,7 +1550,7 @@ static int calc_arf_boost(VP8_COMP *cpi, int offset, int f_frames, int b_frames, /* Calculate the baseline boost number for this frame */ r = calc_frame_boost(cpi, &this_frame, this_frame_mv_in_out); - /* We want to discount the the flash frame itself and the recovery + /* We want to discount the flash frame itself and the recovery * frame that follows as both will have poor scores. */ flash_detected = @@ -1719,9 +1686,9 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { /* Break at cpi->max_gf_interval unless almost totally static */ (i >= cpi->max_gf_interval && (decay_accumulator < 0.995)) || ( - /* Dont break out with a very short interval */ + /* Don't break out with a very short interval */ (i > MIN_GF_INTERVAL) && - /* Dont break out very close to a key frame */ + /* Don't break out very close to a key frame */ ((cpi->twopass.frames_to_key - i) >= MIN_GF_INTERVAL) && ((boost_score > 20.0) || (next_frame.pcnt_inter < 0.75)) && (!flash_detected) && @@ -1733,7 +1700,7 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { break; } - memcpy(this_frame, &next_frame, sizeof(*this_frame)); + *this_frame = next_frame; old_boost_score = boost_score; } @@ -1767,7 +1734,7 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { if (boost_score > max_boost) boost_score = max_boost; } - /* Dont allow conventional gf too near the next kf */ + /* Don't allow conventional gf too near the next kf */ if ((cpi->twopass.frames_to_key - i) < MIN_GF_INTERVAL) { while (i < cpi->twopass.frames_to_key) { i++; @@ -1788,9 +1755,9 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { alt_boost = calc_arf_boost(cpi, 0, (i - 1), (i - 1), &f_boost, &b_boost); #endif - /* Should we use the alternate refernce frame */ + /* Should we use the alternate reference frame */ if (allow_alt_ref && (i >= MIN_GF_INTERVAL) && - /* dont use ARF very near next kf */ + /* don't use ARF very near next kf */ (i <= (cpi->twopass.frames_to_key - MIN_GF_INTERVAL)) && #if NEW_BOOST ((next_frame.pcnt_inter > 0.75) || (next_frame.pcnt_second_ref > 0.5)) && @@ -1968,11 +1935,10 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { } cpi->twopass.gf_group_bits = - (cpi->twopass.gf_group_bits < 0) - ? 0 - : (cpi->twopass.gf_group_bits > cpi->twopass.kf_group_bits) - ? cpi->twopass.kf_group_bits - : cpi->twopass.gf_group_bits; + (cpi->twopass.gf_group_bits < 0) ? 0 + : (cpi->twopass.gf_group_bits > cpi->twopass.kf_group_bits) + ? cpi->twopass.kf_group_bits + : cpi->twopass.gf_group_bits; /* Clip cpi->twopass.gf_group_bits based on user supplied data rate * variability limit (cpi->oxcf.two_pass_vbrmax_section) @@ -2040,8 +2006,9 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { /* Calculate the number of bits to be spent on the gf or arf based on * the boost number */ - gf_bits = (int)((double)Boost * - (cpi->twopass.gf_group_bits / (double)allocation_chunks)); + gf_bits = saturate_cast_double_to_int( + (double)Boost * + (cpi->twopass.gf_group_bits / (double)allocation_chunks)); /* If the frame that is to be boosted is simpler than the average for * the gf/arf group then use an alternative calculation @@ -2069,9 +2036,9 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { */ else { // Avoid division by 0 by clamping cpi->twopass.kf_group_error_left to 1 - int alt_gf_bits = - (int)((double)cpi->twopass.kf_group_bits * mod_frame_err / - (double)VPXMAX(cpi->twopass.kf_group_error_left, 1)); + int alt_gf_bits = saturate_cast_double_to_int( + (double)cpi->twopass.kf_group_bits * mod_frame_err / + (double)VPXMAX(cpi->twopass.kf_group_error_left, 1)); if (alt_gf_bits > gf_bits) { gf_bits = alt_gf_bits; @@ -2085,7 +2052,7 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { } } - /* Dont allow a negative value for gf_bits */ + /* Don't allow a negative value for gf_bits */ if (gf_bits < 0) gf_bits = 0; /* Add in minimum for a frame */ @@ -2126,7 +2093,7 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { if (cpi->twopass.gf_group_bits < 0) cpi->twopass.gf_group_bits = 0; /* This condition could fail if there are two kfs very close together - * despite (MIN_GF_INTERVAL) and would cause a devide by 0 in the + * despite (MIN_GF_INTERVAL) and would cause a divide by 0 in the * calculation of cpi->twopass.alt_extra_bits. */ if (cpi->baseline_gf_interval >= 3) { @@ -2205,7 +2172,8 @@ static void assign_std_frame_bits(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { } /* How many of those bits available for allocation should we give it? */ - target_frame_size = (int)((double)cpi->twopass.gf_group_bits * err_fraction); + target_frame_size = saturate_cast_double_to_int( + (double)cpi->twopass.gf_group_bits * err_fraction); /* Clip to target size to 0 - max_bits (or cpi->twopass.gf_group_bits) * at the top end. @@ -2268,7 +2236,7 @@ void vp8_second_pass(VP8_COMP *cpi) { /* keyframe and section processing ! */ if (cpi->twopass.frames_to_key == 0) { /* Define next KF group and assign bits to it */ - memcpy(&this_frame_copy, &this_frame, sizeof(this_frame)); + this_frame_copy = this_frame; find_next_key_frame(cpi, &this_frame_copy); /* Special case: Error error_resilient_mode mode does not make much @@ -2290,7 +2258,7 @@ void vp8_second_pass(VP8_COMP *cpi) { /* Is this a GF / ARF (Note that a KF is always also a GF) */ if (cpi->frames_till_gf_update_due == 0) { /* Define next gf group and assign bits to it */ - memcpy(&this_frame_copy, &this_frame, sizeof(this_frame)); + this_frame_copy = this_frame; define_gf_group(cpi, &this_frame_copy); /* If we are going to code an altref frame at the end of the group @@ -2305,7 +2273,7 @@ void vp8_second_pass(VP8_COMP *cpi) { * to the GF group */ int bak = cpi->per_frame_bandwidth; - memcpy(&this_frame_copy, &this_frame, sizeof(this_frame)); + this_frame_copy = this_frame; assign_std_frame_bits(cpi, &this_frame_copy); cpi->per_frame_bandwidth = bak; } @@ -2325,12 +2293,12 @@ void vp8_second_pass(VP8_COMP *cpi) { if (cpi->common.frame_type != KEY_FRAME) { /* Assign bits from those allocated to the GF group */ - memcpy(&this_frame_copy, &this_frame, sizeof(this_frame)); + this_frame_copy = this_frame; assign_std_frame_bits(cpi, &this_frame_copy); } } else { /* Assign bits from those allocated to the GF group */ - memcpy(&this_frame_copy, &this_frame, sizeof(this_frame)); + this_frame_copy = this_frame; assign_std_frame_bits(cpi, &this_frame_copy); } } @@ -2360,13 +2328,15 @@ void vp8_second_pass(VP8_COMP *cpi) { if (cpi->common.current_video_frame == 0) { cpi->twopass.est_max_qcorrection_factor = 1.0; + int64_t section_target_bandwidth = cpi->twopass.bits_left / frames_left; + section_target_bandwidth = VPXMIN(section_target_bandwidth, INT_MAX); + /* Set a cq_level in constrained quality mode. */ if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) { int est_cq; est_cq = estimate_cq(cpi, &cpi->twopass.total_left_stats, - (int)(cpi->twopass.bits_left / frames_left), - overhead_bits); + (int)section_target_bandwidth, overhead_bits); cpi->cq_target_quality = cpi->oxcf.cq_level; if (est_cq > cpi->cq_target_quality) cpi->cq_target_quality = est_cq; @@ -2377,8 +2347,7 @@ void vp8_second_pass(VP8_COMP *cpi) { cpi->twopass.maxq_min_limit = cpi->best_quality; tmp_q = estimate_max_q(cpi, &cpi->twopass.total_left_stats, - (int)(cpi->twopass.bits_left / frames_left), - overhead_bits); + (int)section_target_bandwidth, overhead_bits); /* Limit the maxq value returned subsequently. * This increases the risk of overspend or underspend if the initial @@ -2396,7 +2365,7 @@ void vp8_second_pass(VP8_COMP *cpi) { } /* The last few frames of a clip almost always have to few or too many - * bits and for the sake of over exact rate control we dont want to make + * bits and for the sake of over exact rate control we don't want to make * radical adjustments to the allowed quantizer range just to use up a * few surplus bits or get beneath the target rate. */ @@ -2406,9 +2375,11 @@ void vp8_second_pass(VP8_COMP *cpi) { (unsigned int)cpi->twopass.total_stats.count)) { if (frames_left < 1) frames_left = 1; + int64_t section_target_bandwidth = cpi->twopass.bits_left / frames_left; + section_target_bandwidth = VPXMIN(section_target_bandwidth, INT_MAX); + tmp_q = estimate_max_q(cpi, &cpi->twopass.total_left_stats, - (int)(cpi->twopass.bits_left / frames_left), - overhead_bits); + (int)section_target_bandwidth, overhead_bits); /* Move active_worst_quality but in a damped way */ if (tmp_q > cpi->active_worst_quality) { @@ -2459,7 +2430,7 @@ static int test_candidate_kf(VP8_COMP *cpi, FIRSTPASS_STATS *last_frame, double decay_accumulator = 1.0; double next_iiratio; - memcpy(&local_next_frame, next_frame, sizeof(*next_frame)); + local_next_frame = *next_frame; /* Note the starting file position so we can reset to it */ start_pos = cpi->twopass.stats_in; @@ -2552,7 +2523,7 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { cpi->twopass.frames_to_key = 1; /* Take a copy of the initial frame details */ - memcpy(&first_frame, this_frame, sizeof(*this_frame)); + first_frame = *this_frame; cpi->twopass.kf_group_bits = 0; cpi->twopass.kf_group_error_left = 0; @@ -2574,7 +2545,7 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { kf_group_coded_err += this_frame->coded_error; /* Load the next frame's stats. */ - memcpy(&last_frame, this_frame, sizeof(*this_frame)); + last_frame = *this_frame; input_stats(cpi, this_frame); /* Provided that we are not at the end of the file... */ @@ -2637,7 +2608,7 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { cpi->twopass.frames_to_key /= 2; /* Copy first frame details */ - memcpy(&tmp_frame, &first_frame, sizeof(first_frame)); + tmp_frame = first_frame; /* Reset to the start of the group */ reset_fpf_position(cpi, start_position); @@ -2734,9 +2705,10 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { else if (cpi->twopass.kf_group_bits < av_group_bits) { int64_t bits_below_av = av_group_bits - cpi->twopass.kf_group_bits; - cpi->twopass.kf_group_bits += (int64_t)( - (double)bits_below_av * (double)(buffer_lvl - opt_buffer_lvl) / - (double)(high_water_mark - opt_buffer_lvl)); + cpi->twopass.kf_group_bits += + (int64_t)((double)bits_below_av * + (double)(buffer_lvl - opt_buffer_lvl) / + (double)(high_water_mark - opt_buffer_lvl)); } } } @@ -2993,12 +2965,12 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { } /* Set back to unscaled by defaults */ - cpi->common.horiz_scale = NORMAL; - cpi->common.vert_scale = NORMAL; + cpi->common.horiz_scale = VP8E_NORMAL; + cpi->common.vert_scale = VP8E_NORMAL; /* Calculate Average bits per frame. */ - av_bits_per_frame = cpi->oxcf.target_bandwidth / - DOUBLE_DIVIDE_CHECK((double)cpi->framerate); + av_bits_per_frame = + cpi->oxcf.target_bandwidth / DOUBLE_DIVIDE_CHECK(cpi->framerate); /* CBR... Use the clip average as the target for deciding resample */ if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { @@ -3014,7 +2986,7 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { bits_per_frame = (double)(cpi->twopass.kf_group_bits / cpi->twopass.frames_to_key); - /* Dont turn to resampling in easy sections just because they + /* Don't turn to resampling in easy sections just because they * have been assigned a small number of bits */ if (bits_per_frame < av_bits_per_frame) { @@ -3050,16 +3022,6 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { (int)((projected_bits_perframe - av_bits_per_frame) * cpi->twopass.frames_to_key)); - if (0) { - FILE *f = fopen("Subsamle.stt", "a"); - fprintf(f, " %8d %8d %8d %8d %12.0f %8d %8d %8d\n", - cpi->common.current_video_frame, kf_q, cpi->common.horiz_scale, - cpi->common.vert_scale, kf_group_err / cpi->twopass.frames_to_key, - (int)(cpi->twopass.kf_group_bits / cpi->twopass.frames_to_key), - new_height, new_width); - fclose(f); - } - /* The trigger for spatial resampling depends on the various * parameters such as whether we are streaming (CBR) or VBR. */ @@ -3078,9 +3040,9 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { resample_trigger = 0; } } else { - int64_t clip_bits = (int64_t)( - cpi->twopass.total_stats.count * cpi->oxcf.target_bandwidth / - DOUBLE_DIVIDE_CHECK((double)cpi->framerate)); + int64_t clip_bits = (int64_t)(cpi->twopass.total_stats.count * + cpi->oxcf.target_bandwidth / + DOUBLE_DIVIDE_CHECK(cpi->framerate)); int64_t over_spend = cpi->oxcf.starting_buffer_level - cpi->buffer_level; /* If triggered last time the threshold for triggering again is @@ -3123,17 +3085,6 @@ static void find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame) { */ kf_q = estimate_kf_group_q(cpi, err_per_frame * effective_size_ratio, (int)bits_per_frame, group_iiratio); - - if (0) { - FILE *f = fopen("Subsamle.stt", "a"); - fprintf( - f, "******** %8d %8d %8d %12.0f %8d %8d %8d\n", kf_q, - cpi->common.horiz_scale, cpi->common.vert_scale, - kf_group_err / cpi->twopass.frames_to_key, - (int)(cpi->twopass.kf_group_bits / cpi->twopass.frames_to_key), - new_height, new_width); - fclose(f); - } } } diff --git a/libs/libvpx/vp8/encoder/loongarch/quantize_lsx.c b/libs/libvpx/vp8/encoder/loongarch/vp8_quantize_lsx.c similarity index 79% rename from libs/libvpx/vp8/encoder/loongarch/quantize_lsx.c rename to libs/libvpx/vp8/encoder/loongarch/vp8_quantize_lsx.c index 75889192a7..10c5da8198 100644 --- a/libs/libvpx/vp8/encoder/loongarch/quantize_lsx.c +++ b/libs/libvpx/vp8/encoder/loongarch/vp8_quantize_lsx.c @@ -12,6 +12,8 @@ #include "./vp8_rtcd.h" #include "vpx_util/loongson_intrinsics.h" #include "vp8/encoder/block.h" +#include "vpx_ports/bitops.h" +#include "vpx_ports/mem.h" #define BOOST_QUANT1(_in0, _in1, _in2, _ui) \ { \ @@ -143,3 +145,46 @@ void vp8_regular_quantize_b_lsx(BLOCK *b, BLOCKD *d) { zbin_boost_ptr, coeff_ptr, zbin_ptr, round_ptr, quant_ptr, quant_shift_ptr, dequant_ptr, zbin_oq_value, qcoeff_ptr, dqcoeff_ptr); } + +void vp8_fast_quantize_b_lsx(BLOCK *b, BLOCKD *d) { + const int16_t *coeff_ptr = b->coeff; + const int16_t *round_ptr = b->round; + const int16_t *quant_ptr = b->quant_fast; + const int16_t *dequant_ptr = d->dequant; + int16_t *qcoeff_ptr = d->qcoeff; + int16_t *dqcoeff_ptr = d->dqcoeff; + DECLARE_ALIGNED(16, static const uint8_t, + zig_zag_idx[16]) = { 0, 1, 4, 8, 5, 2, 3, 6, + 9, 12, 13, 10, 7, 11, 14, 15 }; + const __m128i zig_zag = __lsx_vld(zig_zag_idx, 0); + const __m128i zero = __lsx_vldi(0); + uint32_t mask; + __m128i c0, c1, s0, s1, x0, x1, y0, y1, a0, a1, dq0, dq1; + + c0 = __lsx_vld(coeff_ptr, 0); + c1 = __lsx_vld(coeff_ptr, 16); + s0 = __lsx_vsrai_h(c0, 15); + s1 = __lsx_vsrai_h(c1, 15); + x0 = __lsx_vsub_h(__lsx_vxor_v(c0, s0), s0); + x1 = __lsx_vsub_h(__lsx_vxor_v(c1, s1), s1); + x0 = __lsx_vadd_h(x0, __lsx_vld(round_ptr, 0)); + x1 = __lsx_vadd_h(x1, __lsx_vld(round_ptr, 16)); + y0 = __lsx_vmuh_hu(x0, __lsx_vld(quant_ptr, 0)); + y1 = __lsx_vmuh_hu(x1, __lsx_vld(quant_ptr, 16)); + a0 = y0; + a1 = y1; + y0 = __lsx_vsub_h(__lsx_vxor_v(y0, s0), s0); + y1 = __lsx_vsub_h(__lsx_vxor_v(y1, s1), s1); + __lsx_vst(y0, qcoeff_ptr, 0); + __lsx_vst(y1, qcoeff_ptr, 16); + dq0 = __lsx_vmul_h(y0, __lsx_vld(dequant_ptr, 0)); + dq1 = __lsx_vmul_h(y1, __lsx_vld(dequant_ptr, 16)); + __lsx_vst(dq0, dqcoeff_ptr, 0); + __lsx_vst(dq1, dqcoeff_ptr, 16); + y0 = __lsx_vslt_h(zero, a0); + y1 = __lsx_vslt_h(zero, a1); + y0 = __lsx_vpickev_b(y1, y0); + y0 = __lsx_vshuf_b(y0, y0, zig_zag); + mask = (uint32_t)__lsx_vpickve2gr_w(__lsx_vmskltz_b(y0), 0); + *d->eob = (char)get_msb(mask * 2 + 1); +} diff --git a/libs/libvpx/vp8/encoder/mcomp.c b/libs/libvpx/vp8/encoder/mcomp.c index ae092c66e1..6861adaa86 100644 --- a/libs/libvpx/vp8/encoder/mcomp.c +++ b/libs/libvpx/vp8/encoder/mcomp.c @@ -188,14 +188,15 @@ void vp8_init3smotion_compensation(MACROBLOCK *x, int stride) { */ /* estimated cost of a motion vector (r,c) */ -#define MVC(r, c) \ - (mvcost \ - ? ((mvcost[0][(r)-rr] + mvcost[1][(c)-rc]) * error_per_bit + 128) >> 8 \ - : 0) +#define MVC(r, c) \ + (mvcost ? ((mvcost[0][(r) - rr] + mvcost[1][(c) - rc]) * error_per_bit + \ + 128) >> \ + 8 \ + : 0) /* pointer to predictor base of a motionvector */ #define PRE(r, c) (y + (((r) >> 2) * y_stride + ((c) >> 2) - (offset))) /* convert motion vector component to offset for svf calc */ -#define SP(x) (((x)&3) << 1) +#define SP(x) (((x) & 3) << 1) /* returns subpixel variance error function. */ #define DIST(r, c) \ vfp->svf(PRE(r, c), y_stride, SP(c), SP(r), z, b->src_stride, &sse) @@ -204,20 +205,21 @@ void vp8_init3smotion_compensation(MACROBLOCK *x, int stride) { /* returns distortion + motion vector cost */ #define ERR(r, c) (MVC(r, c) + DIST(r, c)) /* checks if (r,c) has better score than previous best */ -#define CHECK_BETTER(v, r, c) \ - do { \ - IFMVCV(r, c, \ - { \ - thismse = DIST(r, c); \ - if ((v = (MVC(r, c) + thismse)) < besterr) { \ - besterr = v; \ - br = r; \ - bc = c; \ - *distortion = thismse; \ - *sse1 = sse; \ - } \ - }, \ - v = UINT_MAX;) \ +#define CHECK_BETTER(v, r, c) \ + do { \ + IFMVCV( \ + r, c, \ + { \ + thismse = DIST(r, c); \ + if ((v = (MVC(r, c) + thismse)) < besterr) { \ + besterr = v; \ + br = r; \ + bc = c; \ + *distortion = thismse; \ + *sse1 = sse; \ + } \ + }, \ + v = UINT_MAX;) \ } while (0) int vp8_find_best_sub_pixel_step_iteratively(MACROBLOCK *x, BLOCK *b, BLOCKD *d, @@ -285,8 +287,8 @@ int vp8_find_best_sub_pixel_step_iteratively(MACROBLOCK *x, BLOCK *b, BLOCKD *d, offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col; /* central mv */ - bestmv->as_mv.row *= 8; - bestmv->as_mv.col *= 8; + bestmv->as_mv.row = clamp(bestmv->as_mv.row * 8, SHRT_MIN, SHRT_MAX); + bestmv->as_mv.col = clamp(bestmv->as_mv.col * 8, SHRT_MIN, SHRT_MAX); /* calculate central point error */ besterr = vfp->vf(y, y_stride, z, b->src_stride, sse1); @@ -346,8 +348,8 @@ int vp8_find_best_sub_pixel_step_iteratively(MACROBLOCK *x, BLOCK *b, BLOCKD *d, tc = bc; } - bestmv->as_mv.row = br * 2; - bestmv->as_mv.col = bc * 2; + bestmv->as_mv.row = clamp(br * 2, SHRT_MIN, SHRT_MAX); + bestmv->as_mv.col = clamp(bc * 2, SHRT_MIN, SHRT_MAX); if ((abs(bestmv->as_mv.col - ref_mv->as_mv.col) > (MAX_FULL_PEL_VAL << 3)) || (abs(bestmv->as_mv.row - ref_mv->as_mv.row) > (MAX_FULL_PEL_VAL << 3))) { @@ -399,8 +401,8 @@ int vp8_find_best_sub_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d, #endif /* central mv */ - bestmv->as_mv.row *= 8; - bestmv->as_mv.col *= 8; + bestmv->as_mv.row = clamp(bestmv->as_mv.row * 8, SHRT_MIN, SHRT_MAX); + bestmv->as_mv.col = clamp(bestmv->as_mv.col * 8, SHRT_MIN, SHRT_MAX); startmv = *bestmv; /* calculate central point error */ @@ -695,8 +697,8 @@ int vp8_find_best_half_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d, #endif /* central mv */ - bestmv->as_mv.row *= 8; - bestmv->as_mv.col *= 8; + bestmv->as_mv.row = clamp(bestmv->as_mv.row * 8, SHRT_MIN, SHRT_MAX); + bestmv->as_mv.col = clamp(bestmv->as_mv.col * 8, SHRT_MIN, SHRT_MAX); startmv = *bestmv; /* calculate central point error */ @@ -1122,8 +1124,8 @@ int vp8_diamond_search_sad_c(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv, } } - this_mv.as_mv.row = best_mv->as_mv.row << 3; - this_mv.as_mv.col = best_mv->as_mv.col << 3; + this_mv.as_mv.row = clamp(best_mv->as_mv.row * 8, SHRT_MIN, SHRT_MAX); + this_mv.as_mv.col = clamp(best_mv->as_mv.col * 8, SHRT_MIN, SHRT_MAX); return fn_ptr->vf(what, what_stride, best_address, in_what_stride, &thissad) + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); @@ -1272,8 +1274,8 @@ int vp8_diamond_search_sadx4(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv, } } - this_mv.as_mv.row = best_mv->as_mv.row * 8; - this_mv.as_mv.col = best_mv->as_mv.col * 8; + this_mv.as_mv.row = clamp(best_mv->as_mv.row * 8, SHRT_MIN, SHRT_MAX); + this_mv.as_mv.col = clamp(best_mv->as_mv.col * 8, SHRT_MIN, SHRT_MAX); return fn_ptr->vf(what, what_stride, best_address, in_what_stride, &thissad) + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); @@ -1362,8 +1364,8 @@ int vp8_full_search_sad(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv, } } - this_mv.as_mv.row = best_mv->as_mv.row * 8; - this_mv.as_mv.col = best_mv->as_mv.col * 8; + this_mv.as_mv.row = clamp(best_mv->as_mv.row * 8, SHRT_MIN, SHRT_MAX); + this_mv.as_mv.col = clamp(best_mv->as_mv.col * 8, SHRT_MIN, SHRT_MAX); return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, &thissad) + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); @@ -1440,8 +1442,8 @@ int vp8_refining_search_sad_c(MACROBLOCK *x, BLOCK *b, BLOCKD *d, } } - this_mv.as_mv.row = ref_mv->as_mv.row << 3; - this_mv.as_mv.col = ref_mv->as_mv.col << 3; + this_mv.as_mv.row = clamp(ref_mv->as_mv.row * 8, SHRT_MIN, SHRT_MAX); + this_mv.as_mv.col = clamp(ref_mv->as_mv.col * 8, SHRT_MIN, SHRT_MAX); return fn_ptr->vf(what, what_stride, best_address, in_what_stride, &thissad) + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); @@ -1551,8 +1553,8 @@ int vp8_refining_search_sadx4(MACROBLOCK *x, BLOCK *b, BLOCKD *d, } } - this_mv.as_mv.row = ref_mv->as_mv.row * 8; - this_mv.as_mv.col = ref_mv->as_mv.col * 8; + this_mv.as_mv.row = clamp(ref_mv->as_mv.row * 8, SHRT_MIN, SHRT_MAX); + this_mv.as_mv.col = clamp(ref_mv->as_mv.col * 8, SHRT_MIN, SHRT_MAX); return fn_ptr->vf(what, what_stride, best_address, in_what_stride, &thissad) + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); diff --git a/libs/libvpx/vp8/encoder/mr_dissim.c b/libs/libvpx/vp8/encoder/mr_dissim.c index 011b62a08f..b1bfb4b54a 100644 --- a/libs/libvpx/vp8/encoder/mr_dissim.c +++ b/libs/libvpx/vp8/encoder/mr_dissim.c @@ -49,7 +49,6 @@ void vp8_cal_low_res_mb_cols(VP8_COMP *cpi) { void vp8_cal_dissimilarity(VP8_COMP *cpi) { VP8_COMMON *cm = &cpi->common; - int i; /* Note: The first row & first column in mip are outside the frame, which * were initialized to all 0.(ref_frame, mode, mv...) @@ -67,6 +66,7 @@ void vp8_cal_dissimilarity(VP8_COMP *cpi) { store_info->frame_type = cm->frame_type; if (cm->frame_type != KEY_FRAME) { + int i; store_info->is_frame_dropped = 0; for (i = 1; i < MAX_REF_FRAMES; ++i) store_info->low_res_ref_frames[i] = cpi->current_ref_frames[i]; diff --git a/libs/libvpx/vp8/encoder/onyx_if.c b/libs/libvpx/vp8/encoder/onyx_if.c index 4557e85789..6f01dd3aa1 100644 --- a/libs/libvpx/vp8/encoder/onyx_if.c +++ b/libs/libvpx/vp8/encoder/onyx_if.c @@ -9,43 +9,48 @@ */ #include "vpx_config.h" -#include "./vpx_scale_rtcd.h" -#include "./vpx_dsp_rtcd.h" #include "./vp8_rtcd.h" -#include "bitstream.h" -#include "vp8/common/onyxc_int.h" -#include "vp8/common/blockd.h" -#include "onyx_int.h" -#include "vp8/common/systemdependent.h" -#include "vp8/common/vp8_skin_detection.h" -#include "vp8/encoder/quantize.h" +#include "./vpx_dsp_rtcd.h" +#include "./vpx_scale_rtcd.h" + #include "vp8/common/alloccommon.h" -#include "mcomp.h" -#include "firstpass.h" -#include "vpx_dsp/psnr.h" -#include "vpx_scale/vpx_scale.h" +#include "vp8/common/blockd.h" #include "vp8/common/extend.h" -#include "ratectrl.h" +#include "vp8/common/onyxc_int.h" #include "vp8/common/quant_common.h" -#include "segmentation.h" +#include "vp8/common/reconintra.h" +#include "vp8/common/swapyv12buffer.h" +#include "vp8/common/systemdependent.h" +#include "vp8/common/threading.h" +#include "vp8/common/vp8_skin_detection.h" #if CONFIG_POSTPROC #include "vp8/common/postproc.h" #endif + +#include "vp8/encoder/bitstream.h" +#include "vp8/encoder/block.h" +#include "vp8/encoder/encodeframe.h" +#include "vp8/encoder/firstpass.h" +#include "vp8/encoder/mcomp.h" +#include "vp8/encoder/onyx_int.h" +#include "vp8/encoder/quantize.h" +#include "vp8/encoder/ratectrl.h" +#include "vp8/encoder/segmentation.h" +#if CONFIG_MULTI_RES_ENCODING +#include "vp8/encoder/mr_dissim.h" +#endif + +#include "vpx_dsp/psnr.h" +#include "vpx_dsp/vpx_dsp_common.h" #include "vpx_mem/vpx_mem.h" -#include "vp8/common/reconintra.h" -#include "vp8/common/swapyv12buffer.h" -#include "vp8/common/threading.h" #include "vpx_ports/system_state.h" #include "vpx_ports/vpx_once.h" #include "vpx_ports/vpx_timer.h" +#include "vpx_scale/vpx_scale.h" #include "vpx_util/vpx_write_yuv_frame.h" #if VPX_ARCH_ARM #include "vpx_ports/arm.h" #endif -#if CONFIG_MULTI_RES_ENCODING -#include "mr_dissim.h" -#endif -#include "encodeframe.h" #if CONFIG_MULTITHREAD #include "ethreading.h" #endif @@ -63,7 +68,7 @@ extern int vp8_update_coef_context(VP8_COMP *cpi); #endif -extern unsigned int vp8_get_processor_freq(); +extern unsigned int vp8_get_processor_freq(void); int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest); @@ -267,16 +272,23 @@ static int rescale(int val, int num, int denom) { int64_t llden = denom; int64_t llval = val; - return (int)(llval * llnum / llden); + int64_t result = (llval * llnum / llden); + if (result <= INT_MAX) + return (int)result; + else + return INT_MAX; } -void vp8_init_temporal_layer_context(VP8_COMP *cpi, VP8_CONFIG *oxcf, +void vp8_init_temporal_layer_context(VP8_COMP *cpi, const VP8_CONFIG *oxcf, const int layer, double prev_layer_framerate) { LAYER_CONTEXT *lc = &cpi->layer_context[layer]; lc->framerate = cpi->output_framerate / cpi->oxcf.rate_decimator[layer]; - lc->target_bandwidth = cpi->oxcf.target_bitrate[layer] * 1000; + if (cpi->oxcf.target_bitrate[layer] > INT_MAX / 1000) + lc->target_bandwidth = INT_MAX; + else + lc->target_bandwidth = cpi->oxcf.target_bitrate[layer] * 1000; lc->starting_buffer_level_in_ms = oxcf->starting_buffer_level; lc->optimal_buffer_level_in_ms = oxcf->optimal_buffer_level; @@ -328,8 +340,8 @@ void vp8_init_temporal_layer_context(VP8_COMP *cpi, VP8_CONFIG *oxcf, // for any "new" layers. For "existing" layers, let them inherit the parameters // from the previous layer state (at the same layer #). In future we may want // to better map the previous layer state(s) to the "new" ones. -static void reset_temporal_layer_change(VP8_COMP *cpi, VP8_CONFIG *oxcf, - const int prev_num_layers) { +void vp8_reset_temporal_layer_change(VP8_COMP *cpi, const VP8_CONFIG *oxcf, + const int prev_num_layers) { int i; double prev_layer_framerate = 0; const int curr_num_layers = cpi->oxcf.number_of_layers; @@ -427,6 +439,7 @@ static void dealloc_compressor_data(VP8_COMP *cpi) { vp8_yv12_de_alloc_frame_buffer(&cpi->pick_lf_lvl_frame); vp8_yv12_de_alloc_frame_buffer(&cpi->scaled_source); + vp8_yv12_de_alloc_frame_buffer(&cpi->raw_source_frame); dealloc_raw_frame_buffers(cpi); vpx_free(cpi->tok); @@ -442,11 +455,6 @@ static void dealloc_compressor_data(VP8_COMP *cpi) { vpx_free(cpi->mb.pip); cpi->mb.pip = 0; - -#if CONFIG_MULTITHREAD - vpx_free(cpi->mt_current_mb_col); - cpi->mt_current_mb_col = NULL; -#endif } static void enable_segmentation(VP8_COMP *cpi) { @@ -488,7 +496,7 @@ static void set_segmentation_map(VP8_COMP *cpi, */ static void set_segment_data(VP8_COMP *cpi, signed char *feature_data, unsigned char abs_delta) { - cpi->mb.e_mbd.mb_segement_abs_delta = abs_delta; + cpi->mb.e_mbd.mb_segment_abs_delta = abs_delta; memcpy(cpi->segment_feature_data, feature_data, sizeof(cpi->segment_feature_data)); } @@ -962,6 +970,7 @@ void vp8_set_speed_features(VP8_COMP *cpi) { if (cpi->oxcf.encode_breakout > 2000) min = cpi->oxcf.encode_breakout; min >>= 7; + if (min >= MAX_ERROR_BINS) min = MAX_ERROR_BINS - 1; for (i = 0; i < min; ++i) { sum += cpi->mb.error_bins[i]; @@ -1114,6 +1123,9 @@ static void dealloc_raw_frame_buffers(VP8_COMP *cpi) { vp8_yv12_de_alloc_frame_buffer(&cpi->alt_ref_buffer); #endif vp8_lookahead_destroy(cpi->lookahead); +#if CONFIG_TEMPORAL_DENOISING + vp8_denoiser_free(&cpi->denoiser); +#endif } static int vp8_alloc_partition_data(VP8_COMP *cpi) { @@ -1169,7 +1181,17 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi) { #else unsigned int tokens = cm->mb_rows * cm->mb_cols * 24 * 16; #endif - CHECK_MEM_ERROR(cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok))); + /* The token buffer is sized for the worst case, but only the + * [start, stop) range of each macroblock row that was written during + * tokenization is ever read back by the bitstream packer. Allocate it + * without zeroing so that the pages a frame does not use are never + * touched, which keeps them out of the resident set. */ + const size_t tok_size = (size_t)tokens * sizeof(*cpi->tok); + if (tok_size / sizeof(*cpi->tok) != tokens) { + vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, + "Token buffer size overflow"); + } + CHECK_MEM_ERROR(&cpi->common.error, cpi->tok, vpx_malloc(tok_size)); } /* Data used for real time vc mode to see if gf needs refreshing */ @@ -1178,37 +1200,39 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi) { /* Structures used to monitor GF usage */ vpx_free(cpi->gf_active_flags); CHECK_MEM_ERROR( - cpi->gf_active_flags, + &cpi->common.error, cpi->gf_active_flags, vpx_calloc(sizeof(*cpi->gf_active_flags), cm->mb_rows * cm->mb_cols)); cpi->gf_active_count = cm->mb_rows * cm->mb_cols; vpx_free(cpi->mb_activity_map); CHECK_MEM_ERROR( - cpi->mb_activity_map, + &cpi->common.error, cpi->mb_activity_map, vpx_calloc(sizeof(*cpi->mb_activity_map), cm->mb_rows * cm->mb_cols)); /* allocate memory for storing last frame's MVs for MV prediction. */ vpx_free(cpi->lfmv); - CHECK_MEM_ERROR(cpi->lfmv, vpx_calloc((cm->mb_rows + 2) * (cm->mb_cols + 2), - sizeof(*cpi->lfmv))); + CHECK_MEM_ERROR( + &cpi->common.error, cpi->lfmv, + vpx_calloc((cm->mb_rows + 2) * (cm->mb_cols + 2), sizeof(*cpi->lfmv))); vpx_free(cpi->lf_ref_frame_sign_bias); - CHECK_MEM_ERROR(cpi->lf_ref_frame_sign_bias, + CHECK_MEM_ERROR(&cpi->common.error, cpi->lf_ref_frame_sign_bias, vpx_calloc((cm->mb_rows + 2) * (cm->mb_cols + 2), sizeof(*cpi->lf_ref_frame_sign_bias))); vpx_free(cpi->lf_ref_frame); - CHECK_MEM_ERROR(cpi->lf_ref_frame, + CHECK_MEM_ERROR(&cpi->common.error, cpi->lf_ref_frame, vpx_calloc((cm->mb_rows + 2) * (cm->mb_cols + 2), sizeof(*cpi->lf_ref_frame))); /* Create the encoder segmentation map and set all entries to 0 */ vpx_free(cpi->segmentation_map); CHECK_MEM_ERROR( - cpi->segmentation_map, + &cpi->common.error, cpi->segmentation_map, vpx_calloc(cm->mb_rows * cm->mb_cols, sizeof(*cpi->segmentation_map))); cpi->cyclic_refresh_mode_index = 0; vpx_free(cpi->active_map); - CHECK_MEM_ERROR(cpi->active_map, vpx_calloc(cm->mb_rows * cm->mb_cols, - sizeof(*cpi->active_map))); + CHECK_MEM_ERROR( + &cpi->common.error, cpi->active_map, + vpx_calloc(cm->mb_rows * cm->mb_cols, sizeof(*cpi->active_map))); memset(cpi->active_map, 1, (cm->mb_rows * cm->mb_cols)); #if CONFIG_MULTITHREAD @@ -1221,21 +1245,11 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi) { } else { cpi->mt_sync_range = 16; } - - if (cpi->oxcf.multi_threaded > 1) { - int i; - - vpx_free(cpi->mt_current_mb_col); - CHECK_MEM_ERROR(cpi->mt_current_mb_col, - vpx_malloc(sizeof(*cpi->mt_current_mb_col) * cm->mb_rows)); - for (i = 0; i < cm->mb_rows; ++i) - vpx_atomic_init(&cpi->mt_current_mb_col[i], 0); - } - #endif vpx_free(cpi->tplist); - CHECK_MEM_ERROR(cpi->tplist, vpx_malloc(sizeof(TOKENLIST) * cm->mb_rows)); + CHECK_MEM_ERROR(&cpi->common.error, cpi->tplist, + vpx_malloc(sizeof(TOKENLIST) * cm->mb_rows)); #if CONFIG_TEMPORAL_DENOISING if (cpi->oxcf.noise_sensitivity > 0) { @@ -1266,16 +1280,25 @@ int vp8_reverse_trans(int x) { return 63; } -void vp8_new_framerate(VP8_COMP *cpi, double framerate) { - if (framerate < .1) framerate = 30; +static double clamp_framerate(double framerate) { + if (framerate < .1) + return 30.0; + else + return framerate; +} + +void vp8_new_framerate(VP8_COMP *cpi, double framerate) { + framerate = clamp_framerate(framerate); cpi->framerate = framerate; cpi->output_framerate = framerate; - cpi->per_frame_bandwidth = - (int)round(cpi->oxcf.target_bandwidth / cpi->output_framerate); + const double per_frame_bandwidth = + round(cpi->oxcf.target_bandwidth / cpi->output_framerate); + cpi->per_frame_bandwidth = (int)VPXMIN(per_frame_bandwidth, INT_MAX); cpi->av_per_frame_bandwidth = cpi->per_frame_bandwidth; - cpi->min_frame_bandwidth = (int)(cpi->av_per_frame_bandwidth * - cpi->oxcf.two_pass_vbrmin_section / 100); + const int64_t vbr_min_bits = (int64_t)cpi->av_per_frame_bandwidth * + cpi->oxcf.two_pass_vbrmin_section / 100; + cpi->min_frame_bandwidth = (int)VPXMIN(vbr_min_bits, INT_MAX); /* Set Maximum gf/arf interval */ cpi->max_gf_interval = ((int)(cpi->output_framerate / 2.0) + 2); @@ -1302,7 +1325,7 @@ void vp8_new_framerate(VP8_COMP *cpi, double framerate) { } } -static void init_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) { +static void init_config(VP8_COMP *cpi, const VP8_CONFIG *oxcf) { VP8_COMMON *cm = &cpi->common; cpi->oxcf = *oxcf; @@ -1393,7 +1416,10 @@ void vp8_update_layer_contexts(VP8_COMP *cpi) { LAYER_CONTEXT *lc = &cpi->layer_context[i]; lc->framerate = cpi->ref_framerate / oxcf->rate_decimator[i]; - lc->target_bandwidth = oxcf->target_bitrate[i] * 1000; + if (oxcf->target_bitrate[i] > INT_MAX / 1000) + lc->target_bandwidth = INT_MAX; + else + lc->target_bandwidth = oxcf->target_bitrate[i] * 1000; lc->starting_buffer_level = rescale( (int)oxcf->starting_buffer_level_in_ms, lc->target_bandwidth, 1000); @@ -1424,11 +1450,11 @@ void vp8_update_layer_contexts(VP8_COMP *cpi) { } } -void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) { +void vp8_change_config(VP8_COMP *cpi, const VP8_CONFIG *oxcf) { VP8_COMMON *cm = &cpi->common; int last_w, last_h; unsigned int prev_number_of_layers; - unsigned int raw_target_rate; + double raw_target_rate; if (!cpi) return; @@ -1443,11 +1469,6 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) { last_h = cpi->oxcf.Height; prev_number_of_layers = cpi->oxcf.number_of_layers; - if (cpi->initial_width) { - // TODO(https://crbug.com/1486441): Allow changing thread counts; the - // allocation is done once in vp8_create_compressor(). - oxcf->multi_threaded = cpi->oxcf.multi_threaded; - } cpi->oxcf = *oxcf; switch (cpi->oxcf.Mode) { @@ -1574,10 +1595,10 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) { cpi->oxcf.maximum_buffer_size_in_ms = 240000; } - raw_target_rate = (unsigned int)((int64_t)cpi->oxcf.Width * cpi->oxcf.Height * - 8 * 3 * cpi->framerate / 1000); + raw_target_rate = ((int64_t)cpi->oxcf.Width * cpi->oxcf.Height * 8 * 3 * + cpi->framerate / 1000.0); if (cpi->oxcf.target_bandwidth > raw_target_rate) - cpi->oxcf.target_bandwidth = raw_target_rate; + cpi->oxcf.target_bandwidth = (unsigned int)raw_target_rate; /* Convert target bandwidth from Kbit/s to Bit/s */ cpi->oxcf.target_bandwidth *= 1000; @@ -1648,7 +1669,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) { cpi->temporal_layer_id = 0; } cpi->temporal_pattern_counter = 0; - reset_temporal_layer_change(cpi, oxcf, prev_number_of_layers); + vp8_reset_temporal_layer_change(cpi, oxcf, prev_number_of_layers); } if (!cpi->initial_width) { @@ -1672,7 +1693,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) { cm->sharpness_level = cpi->oxcf.Sharpness; - if (cm->horiz_scale != NORMAL || cm->vert_scale != NORMAL) { + if (cm->horiz_scale != VP8E_NORMAL || cm->vert_scale != VP8E_NORMAL) { int hr, hs, vr, vs; Scale2Ratio(cm->horiz_scale, &hr, &hs); @@ -1756,7 +1777,7 @@ static void cal_mvsadcosts(int *mvsadcost[2]) { } while (++i <= mvfp_max); } -struct VP8_COMP *vp8_create_compressor(VP8_CONFIG *oxcf) { +struct VP8_COMP *vp8_create_compressor(const VP8_CONFIG *oxcf) { int i; VP8_COMP *cpi; @@ -1778,8 +1799,9 @@ struct VP8_COMP *vp8_create_compressor(VP8_CONFIG *oxcf) { cpi->common.error.setjmp = 1; - CHECK_MEM_ERROR(cpi->mb.ss, vpx_calloc(sizeof(search_site), - (MAX_MVSEARCH_STEPS * 8) + 1)); + CHECK_MEM_ERROR( + &cpi->common.error, cpi->mb.ss, + vpx_calloc(sizeof(search_site), (MAX_MVSEARCH_STEPS * 8) + 1)); vp8_create_common(&cpi->common); @@ -1878,24 +1900,24 @@ struct VP8_COMP *vp8_create_compressor(VP8_CONFIG *oxcf) { ? (2 * (cpi->common.mb_rows * cpi->common.mb_cols) / cpi->cyclic_refresh_mode_max_mbs_perframe) : 10; - cpi->gf_interval_onepass_cbr = - VPXMIN(40, VPXMAX(6, cpi->gf_interval_onepass_cbr)); + cpi->gf_interval_onepass_cbr = clamp(cpi->gf_interval_onepass_cbr, 6, 40); cpi->baseline_gf_interval = cpi->gf_interval_onepass_cbr; } if (cpi->cyclic_refresh_mode_enabled) { - CHECK_MEM_ERROR(cpi->cyclic_refresh_map, + CHECK_MEM_ERROR(&cpi->common.error, cpi->cyclic_refresh_map, vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1)); } else { cpi->cyclic_refresh_map = (signed char *)NULL; } - CHECK_MEM_ERROR(cpi->skin_map, vpx_calloc(cm->mb_rows * cm->mb_cols, - sizeof(cpi->skin_map[0]))); + CHECK_MEM_ERROR( + &cpi->common.error, cpi->skin_map, + vpx_calloc(cm->mb_rows * cm->mb_cols, sizeof(cpi->skin_map[0]))); - CHECK_MEM_ERROR(cpi->consec_zero_last, + CHECK_MEM_ERROR(&cpi->common.error, cpi->consec_zero_last, vpx_calloc(cm->mb_rows * cm->mb_cols, 1)); - CHECK_MEM_ERROR(cpi->consec_zero_last_mvbias, + CHECK_MEM_ERROR(&cpi->common.error, cpi->consec_zero_last_mvbias, vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1)); /*Initialize the feed-forward activity masking.*/ @@ -1914,6 +1936,7 @@ struct VP8_COMP *vp8_create_compressor(VP8_CONFIG *oxcf) { cpi->force_maxqp = 0; cpi->frames_since_last_drop_overshoot = 0; cpi->rt_always_update_correction_factor = 0; + cpi->rt_drop_recode_on_overshoot = 1; cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; #if CONFIG_INTERNAL_STATS @@ -2009,6 +2032,7 @@ struct VP8_COMP *vp8_create_compressor(VP8_CONFIG *oxcf) { #if CONFIG_MULTITHREAD if (vp8cx_create_encoder_threads(cpi)) { + cpi->common.error.setjmp = 0; vp8_remove_compressor(&cpi); return 0; } @@ -2062,8 +2086,6 @@ struct VP8_COMP *vp8_create_compressor(VP8_CONFIG *oxcf) { vp8_loop_filter_init(cm); - cpi->common.error.setjmp = 0; - #if CONFIG_MULTI_RES_ENCODING /* Calculate # of MBs in a row in lower-resolution level image. */ @@ -2090,6 +2112,8 @@ struct VP8_COMP *vp8_create_compressor(VP8_CONFIG *oxcf) { vp8_setup_block_ptrs(&cpi->mb); vp8_setup_block_dptrs(&cpi->mb.e_mbd); + cpi->common.error.setjmp = 0; + return cpi; } @@ -2114,7 +2138,6 @@ void vp8_remove_compressor(VP8_COMP **comp) { double time_encoded = (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / 10000000.000; - double dr = (double)cpi->bytes * 8.0 / 1000.0 / time_encoded; if (cpi->b_calculate_psnr) { if (cpi->oxcf.number_of_layers > 1) { @@ -2143,6 +2166,7 @@ void vp8_remove_compressor(VP8_COMP **comp) { total_psnr2, total_ssim); } } else { + double dr = (double)cpi->bytes * 8.0 / 1000.0 / time_encoded; double samples = 3.0 / 2 * cpi->count * cpi->common.Width * cpi->common.Height; double total_psnr = @@ -2191,8 +2215,8 @@ void vp8_remove_compressor(VP8_COMP **comp) { { extern int count_mb_seg[4]; FILE *f = fopen("modes.stt", "a"); - double dr = (double)cpi->framerate * (double)bytes * (double)8 / - (double)count / (double)1000; + double dr = cpi->framerate * (double)bytes * (double)8 / (double)count / + (double)1000; fprintf(f, "intra_mode in Intra Frames:\n"); fprintf(f, "Y: %8d, %8d, %8d, %8d, %8d\n", y_modes[0], y_modes[1], y_modes[2], y_modes[3], y_modes[4]); @@ -2250,7 +2274,7 @@ void vp8_remove_compressor(VP8_COMP **comp) { #if 0 { printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); - printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); + printf("\n_frames receive_data encod_mb_row compress_frame Total\n"); printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, cpi->time_receive_data / 1000, cpi->time_encode_mb_row / 1000, cpi->time_compress_data / 1000, (cpi->time_receive_data + cpi->time_compress_data) / 1000); } #endif @@ -2351,7 +2375,10 @@ static uint64_t calc_plane_error(unsigned char *orig, int orig_stride, } static void generate_psnr_packet(VP8_COMP *cpi) { - YV12_BUFFER_CONFIG *orig = cpi->Source; + YV12_BUFFER_CONFIG *orig = + (cpi->oxcf.noise_sensitivity > 0 && cpi->raw_source_frame.buffer_alloc) + ? &cpi->raw_source_frame + : cpi->Source; YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; struct vpx_codec_cx_pkt pkt; uint64_t sse; @@ -2430,6 +2457,11 @@ int vp8_get_reference(VP8_COMP *cpi, enum vpx_ref_frame_type ref_frame_flag, return -1; } + if (cm->yv12_fb[ref_fb_idx].y_width != sd->y_width || + cm->yv12_fb[ref_fb_idx].y_height != sd->y_height) { + return -1; + } + vp8_yv12_copy_frame(&cm->yv12_fb[ref_fb_idx], sd); return 0; @@ -2450,6 +2482,11 @@ int vp8_set_reference(VP8_COMP *cpi, enum vpx_ref_frame_type ref_frame_flag, return -1; } + if (cm->yv12_fb[ref_fb_idx].y_width != sd->y_width || + cm->yv12_fb[ref_fb_idx].y_height != sd->y_height) { + return -1; + } + vp8_yv12_copy_frame(sd, &cm->yv12_fb[ref_fb_idx]); return 0; @@ -2509,15 +2546,17 @@ static int resize_key_frame(VP8_COMP *cpi) { if (cpi->buffer_level < (cpi->oxcf.resample_down_water_mark * cpi->oxcf.optimal_buffer_level / 100)) { cm->horiz_scale = - (cm->horiz_scale < ONETWO) ? cm->horiz_scale + 1 : ONETWO; - cm->vert_scale = (cm->vert_scale < ONETWO) ? cm->vert_scale + 1 : ONETWO; + (cm->horiz_scale < VP8E_ONETWO) ? cm->horiz_scale + 1 : VP8E_ONETWO; + cm->vert_scale = + (cm->vert_scale < VP8E_ONETWO) ? cm->vert_scale + 1 : VP8E_ONETWO; } /* Should we now start scaling back up */ else if (cpi->buffer_level > (cpi->oxcf.resample_up_water_mark * cpi->oxcf.optimal_buffer_level / 100)) { cm->horiz_scale = - (cm->horiz_scale > NORMAL) ? cm->horiz_scale - 1 : NORMAL; - cm->vert_scale = (cm->vert_scale > NORMAL) ? cm->vert_scale - 1 : NORMAL; + (cm->horiz_scale > VP8E_NORMAL) ? cm->horiz_scale - 1 : VP8E_NORMAL; + cm->vert_scale = + (cm->vert_scale > VP8E_NORMAL) ? cm->vert_scale - 1 : VP8E_NORMAL; } /* Get the new height and width */ @@ -2599,6 +2638,7 @@ static void update_golden_frame_stats(VP8_COMP *cpi) { */ cpi->gf_overspend_bits += (cpi->projected_frame_size - cpi->inter_frame_target); + cpi->gf_overspend_bits = VPXMAX(0, cpi->gf_overspend_bits); } cpi->non_gf_bitrate_adjustment = @@ -2748,7 +2788,7 @@ static int decide_key_frame(VP8_COMP *cpi) { } /* in addition if the following are true and this is not a golden frame * then code a key frame Note that on golden frames there often seems - * to be a pop in intra useage anyway hence this restriction is + * to be a pop in intra usage anyway hence this restriction is * designed to prevent spurious key frames. The Intra pop needs to be * investigated. */ @@ -2964,8 +3004,15 @@ static void update_reference_frames(VP8_COMP *cpi) { &cpi->denoiser.yv12_running_avg[GOLDEN_FRAME]); } if (cm->refresh_last_frame) { - vp8_yv12_copy_frame(&cpi->denoiser.yv12_running_avg[INTRA_FRAME], - &cpi->denoiser.yv12_running_avg[LAST_FRAME]); + if (cpi->denoiser.denoiser_mode == kDenoiserOnYOnly) { + vp8_yv12_copy_frame(&cpi->denoiser.yv12_running_avg[INTRA_FRAME], + &cpi->denoiser.yv12_running_avg[LAST_FRAME]); + } else { + YV12_BUFFER_CONFIG tmp = cpi->denoiser.yv12_running_avg[INTRA_FRAME]; + cpi->denoiser.yv12_running_avg[INTRA_FRAME] = + cpi->denoiser.yv12_running_avg[LAST_FRAME]; + cpi->denoiser.yv12_running_avg[LAST_FRAME] = tmp; + } } } if (cpi->oxcf.noise_sensitivity == 4) @@ -3007,7 +3054,7 @@ static int measure_square_diff_partial(YV12_BUFFER_CONFIG *source, // Only return non-zero if we have at least ~1/16 samples for estimate. if (num_blocks > (tot_num_blocks >> 4)) { assert(num_blocks != 0); - return num_blocks ? (Total / num_blocks) : 0; + return (Total / num_blocks); } else { return 0; } @@ -3139,11 +3186,15 @@ void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm) { if (cm->no_lpf) { cm->filter_level = 0; } else { +#if CONFIG_INTERNAL_STATS struct vpx_usec_timer timer; +#endif vpx_clear_system_state(); +#if CONFIG_INTERNAL_STATS vpx_usec_timer_start(&timer); +#endif if (cpi->sf.auto_filter == 0) { #if CONFIG_TEMPORAL_DENOISING if (cpi->oxcf.noise_sensitivity && cm->frame_type != KEY_FRAME) { @@ -3178,13 +3229,16 @@ void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm) { vp8cx_set_alt_lf_level(cpi, cm->filter_level); } +#if CONFIG_INTERNAL_STATS vpx_usec_timer_mark(&timer); cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer); +#endif } #if CONFIG_MULTITHREAD if (vpx_atomic_load_acquire(&cpi->b_multi_threaded)) { - sem_post(&cpi->h_event_end_lpf); /* signal that we have set filter_level */ + /* signal that we have set filter_level */ + vp8_sem_post(&cpi->h_event_end_lpf); } #endif @@ -3196,6 +3250,113 @@ void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm) { vp8_yv12_extend_frame_borders(cm->frame_to_show); } +// Return 1 if frame is to be dropped. Update frame drop decimation +// counters. +int vp8_check_drop_buffer(VP8_COMP *cpi) { + VP8_COMMON *cm = &cpi->common; + int drop_mark = (int)(cpi->oxcf.drop_frames_water_mark * + cpi->oxcf.optimal_buffer_level / 100); + int drop_mark75 = drop_mark * 2 / 3; + int drop_mark50 = drop_mark / 4; + int drop_mark25 = drop_mark / 8; + if (cpi->drop_frames_allowed) { + /* The reset to decimation 0 is only done here for one pass. + * Once it is set two pass leaves decimation on till the next kf. + */ + if (cpi->buffer_level > drop_mark && cpi->decimation_factor > 0) { + cpi->decimation_factor--; + } + + if (cpi->buffer_level > drop_mark75 && cpi->decimation_factor > 0) { + cpi->decimation_factor = 1; + + } else if (cpi->buffer_level < drop_mark25 && + (cpi->decimation_factor == 2 || cpi->decimation_factor == 3)) { + cpi->decimation_factor = 3; + } else if (cpi->buffer_level < drop_mark50 && + (cpi->decimation_factor == 1 || cpi->decimation_factor == 2)) { + cpi->decimation_factor = 2; + } else if (cpi->buffer_level < drop_mark75 && + (cpi->decimation_factor == 0 || cpi->decimation_factor == 1)) { + cpi->decimation_factor = 1; + } + } + + /* The following decimates the frame rate according to a regular + * pattern (i.e. to 1/2 or 2/3 frame rate) This can be used to help + * prevent buffer under-run in CBR mode. Alternatively it might be + * desirable in some situations to drop frame rate but throw more bits + * at each frame. + * + * Note that dropping a key frame can be problematic if spatial + * resampling is also active + */ + if (cpi->decimation_factor > 0 && cpi->drop_frames_allowed) { + switch (cpi->decimation_factor) { + case 1: + cpi->per_frame_bandwidth = cpi->per_frame_bandwidth * 3 / 2; + break; + case 2: + cpi->per_frame_bandwidth = cpi->per_frame_bandwidth * 5 / 4; + break; + case 3: + cpi->per_frame_bandwidth = cpi->per_frame_bandwidth * 5 / 4; + break; + } + + /* Note that we should not throw out a key frame (especially when + * spatial resampling is enabled). + */ + if (cm->frame_type == KEY_FRAME) { + cpi->decimation_count = cpi->decimation_factor; + } else if (cpi->decimation_count > 0) { + cpi->decimation_count--; + + cpi->bits_off_target += cpi->av_per_frame_bandwidth; + if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size) { + cpi->bits_off_target = cpi->oxcf.maximum_buffer_size; + } + +#if CONFIG_MULTI_RES_ENCODING + vp8_store_drop_frame_info(cpi); +#endif + + cm->current_video_frame++; + cpi->frames_since_key++; + cpi->ext_refresh_frame_flags_pending = 0; + // We advance the temporal pattern for dropped frames. + cpi->temporal_pattern_counter++; + +#if CONFIG_INTERNAL_STATS + cpi->count++; +#endif + + cpi->buffer_level = cpi->bits_off_target; + + if (cpi->oxcf.number_of_layers > 1) { + unsigned int i; + + /* Propagate bits saved by dropping the frame to higher + * layers + */ + for (i = cpi->current_layer + 1; i < cpi->oxcf.number_of_layers; ++i) { + LAYER_CONTEXT *lc = &cpi->layer_context[i]; + lc->bits_off_target += (int)(lc->target_bandwidth / lc->framerate); + if (lc->bits_off_target > lc->maximum_buffer_size) { + lc->bits_off_target = lc->maximum_buffer_size; + } + lc->buffer_level = lc->bits_off_target; + } + } + return 1; + } else { + cpi->decimation_count = cpi->decimation_factor; + } + } else { + cpi->decimation_count = 0; + } + return 0; +} static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, unsigned char *dest, @@ -3206,7 +3367,6 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, int frame_under_shoot_limit; int Loop = 0; - int loop_count; VP8_COMMON *cm = &cpi->common; int active_worst_qchanged = 0; @@ -3222,12 +3382,6 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, int undershoot_seen = 0; #endif - int drop_mark = (int)(cpi->oxcf.drop_frames_water_mark * - cpi->oxcf.optimal_buffer_level / 100); - int drop_mark75 = drop_mark * 2 / 3; - int drop_mark50 = drop_mark / 4; - int drop_mark25 = drop_mark / 8; - /* Clear down mmx registers to allow floating point in what follows */ vpx_clear_system_state(); @@ -3251,10 +3405,12 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, } break; #endif // !CONFIG_REALTIME_ONLY - default: - cpi->per_frame_bandwidth = - (int)round(cpi->target_bandwidth / cpi->output_framerate); + default: { + const double per_frame_bandwidth = + round(cpi->target_bandwidth / cpi->output_framerate); + cpi->per_frame_bandwidth = (int)VPXMIN(per_frame_bandwidth, INT_MAX); break; + } } /* Default turn off buffer to buffer copying */ @@ -3441,102 +3597,8 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, update_rd_ref_frame_probs(cpi); - if (cpi->drop_frames_allowed) { - /* The reset to decimation 0 is only done here for one pass. - * Once it is set two pass leaves decimation on till the next kf. - */ - if ((cpi->buffer_level > drop_mark) && (cpi->decimation_factor > 0)) { - cpi->decimation_factor--; - } - - if (cpi->buffer_level > drop_mark75 && cpi->decimation_factor > 0) { - cpi->decimation_factor = 1; - - } else if (cpi->buffer_level < drop_mark25 && - (cpi->decimation_factor == 2 || cpi->decimation_factor == 3)) { - cpi->decimation_factor = 3; - } else if (cpi->buffer_level < drop_mark50 && - (cpi->decimation_factor == 1 || cpi->decimation_factor == 2)) { - cpi->decimation_factor = 2; - } else if (cpi->buffer_level < drop_mark75 && - (cpi->decimation_factor == 0 || cpi->decimation_factor == 1)) { - cpi->decimation_factor = 1; - } - } - - /* The following decimates the frame rate according to a regular - * pattern (i.e. to 1/2 or 2/3 frame rate) This can be used to help - * prevent buffer under-run in CBR mode. Alternatively it might be - * desirable in some situations to drop frame rate but throw more bits - * at each frame. - * - * Note that dropping a key frame can be problematic if spatial - * resampling is also active - */ - if (cpi->decimation_factor > 0 && cpi->drop_frames_allowed) { - switch (cpi->decimation_factor) { - case 1: - cpi->per_frame_bandwidth = cpi->per_frame_bandwidth * 3 / 2; - break; - case 2: - cpi->per_frame_bandwidth = cpi->per_frame_bandwidth * 5 / 4; - break; - case 3: - cpi->per_frame_bandwidth = cpi->per_frame_bandwidth * 5 / 4; - break; - } - - /* Note that we should not throw out a key frame (especially when - * spatial resampling is enabled). - */ - if (cm->frame_type == KEY_FRAME) { - cpi->decimation_count = cpi->decimation_factor; - } else if (cpi->decimation_count > 0) { - cpi->decimation_count--; - - cpi->bits_off_target += cpi->av_per_frame_bandwidth; - if (cpi->bits_off_target > cpi->oxcf.maximum_buffer_size) { - cpi->bits_off_target = cpi->oxcf.maximum_buffer_size; - } - -#if CONFIG_MULTI_RES_ENCODING - vp8_store_drop_frame_info(cpi); -#endif - - cm->current_video_frame++; - cpi->frames_since_key++; - cpi->ext_refresh_frame_flags_pending = 0; - // We advance the temporal pattern for dropped frames. - cpi->temporal_pattern_counter++; - -#if CONFIG_INTERNAL_STATS - cpi->count++; -#endif - - cpi->buffer_level = cpi->bits_off_target; - - if (cpi->oxcf.number_of_layers > 1) { - unsigned int i; - - /* Propagate bits saved by dropping the frame to higher - * layers - */ - for (i = cpi->current_layer + 1; i < cpi->oxcf.number_of_layers; ++i) { - LAYER_CONTEXT *lc = &cpi->layer_context[i]; - lc->bits_off_target += (int)(lc->target_bandwidth / lc->framerate); - if (lc->bits_off_target > lc->maximum_buffer_size) { - lc->bits_off_target = lc->maximum_buffer_size; - } - lc->buffer_level = lc->bits_off_target; - } - } - - return; - } else { - cpi->decimation_count = cpi->decimation_factor; - } - } else { - cpi->decimation_count = 0; + if (vp8_check_drop_buffer(cpi)) { + return; } /* Decide how big to make the frame */ @@ -3635,7 +3697,7 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, Q = cpi->avg_frame_qindex; } - /* For constrained quality dont allow Q less than the cq level */ + /* For constrained quality don't allow Q less than the cq level */ if ((cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) && (Q < cpi->cq_target_quality)) { Q = cpi->cq_target_quality; @@ -3662,7 +3724,7 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, } else { cpi->active_best_quality = inter_minq[Q]; - /* For the constant/constrained quality mode we dont want + /* For the constant/constrained quality mode we don't want * q to fall below the cq level. */ if ((cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) && @@ -3683,7 +3745,7 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, * higher quality on the frames to prevent bits just going to waste. */ if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { - /* Note that the use of >= here elliminates the risk of a devide + /* Note that the use of >= here elliminates the risk of a divide * by 0 error in the else if clause */ if (cpi->buffer_level >= cpi->oxcf.maximum_buffer_size) { @@ -3772,10 +3834,23 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, vp8_save_coding_context(cpi); - loop_count = 0; - scale_and_extend_source(cpi->un_scaled_source, cpi); + if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame && + cpi->oxcf.noise_sensitivity > 0) { + if (cpi->raw_source_frame.y_width != cpi->Source->y_width || + cpi->raw_source_frame.y_height != cpi->Source->y_height) { + vp8_yv12_de_alloc_frame_buffer(&cpi->raw_source_frame); + if (vp8_yv12_alloc_frame_buffer( + &cpi->raw_source_frame, cpi->Source->y_width, + cpi->Source->y_height, VP8BORDERINPIXELS) < 0) { + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, + "Failed to allocate raw source frame buffer"); + } + } + vp8_yv12_copy_frame(cpi->Source, &cpi->raw_source_frame); + } + #if CONFIG_TEMPORAL_DENOISING && CONFIG_POSTPROC // Option to apply spatial blur under the aggressive or adaptive // (temporal denoising) mode. @@ -3928,7 +4003,7 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, if (cm->refresh_entropy_probs == 0) { /* save a copy for later refresh */ - memcpy(&cm->lfc, &cm->fc, sizeof(cm->fc)); + cm->lfc = cm->fc; } vp8_update_coef_context(cpi); @@ -3946,7 +4021,8 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, /* transform / motion compensation build reconstruction frame */ vp8_encode_frame(cpi); - if (cpi->pass == 0 && cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { + if (cpi->pass == 0 && cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER && + cpi->rt_drop_recode_on_overshoot == 1) { if (vp8_drop_encodedframe_overshoot(cpi, Q)) { vpx_clear_system_state(); return; @@ -3996,7 +4072,6 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, q_low = cpi->active_best_quality; q_high = cpi->active_worst_quality; - loop_count++; Loop = 1; continue; @@ -4207,11 +4282,10 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, } /* Clamp cpi->zbin_over_quant */ - cpi->mb.zbin_over_quant = (cpi->mb.zbin_over_quant < zbin_oq_low) - ? zbin_oq_low - : (cpi->mb.zbin_over_quant > zbin_oq_high) - ? zbin_oq_high - : cpi->mb.zbin_over_quant; + cpi->mb.zbin_over_quant = + (cpi->mb.zbin_over_quant < zbin_oq_low) ? zbin_oq_low + : (cpi->mb.zbin_over_quant > zbin_oq_high) ? zbin_oq_high + : cpi->mb.zbin_over_quant; Loop = Q != last_q; } else { @@ -4223,7 +4297,6 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, if (Loop == 1) { vp8_restore_coding_context(cpi); - loop_count++; #if CONFIG_INTERNAL_STATS cpi->tot_recode_hits++; #endif @@ -4325,12 +4398,12 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, vp8_cal_dissimilarity(cpi); #endif - /* Update the GF useage maps. + /* Update the GF usage maps. * This is done after completing the compression of a frame when all * modes etc. are finalized but before loop filter */ if (cpi->oxcf.number_of_layers == 1) { - vp8_update_gf_useage_maps(cpi, cm, &cpi->mb); + vp8_update_gf_usage_maps(cpi, cm, &cpi->mb); } if (cm->frame_type == KEY_FRAME) cm->refresh_last_frame = 1; @@ -4397,11 +4470,11 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, #if CONFIG_MULTITHREAD if (vpx_atomic_load_acquire(&cpi->b_multi_threaded)) { /* start loopfilter in separate thread */ - sem_post(&cpi->h_event_start_lpf); + vp8_sem_post(&cpi->h_event_start_lpf); cpi->b_lpf_running = 1; /* wait for the filter_level to be picked so that we can continue with * stream packing */ - sem_wait(&cpi->h_event_end_lpf); + vp8_sem_wait(&cpi->h_event_end_lpf); } else #endif { @@ -4487,7 +4560,7 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, * size within range) then use the last frame value - 1. The -1 * is designed to stop Q and hence the data rate, from * progressively falling away during difficult sections, but at - * the same time reduce the number of itterations around the + * the same time reduce the number of iterations around the * recode loop. */ if (Q > cpi->ni_av_qi) cpi->ni_av_qi = Q - 1; @@ -4734,7 +4807,7 @@ static void encode_frame_to_data_rate(VP8_COMP *cpi, size_t *size, cpi->mb.e_mbd.update_mb_segmentation_data = 0; cpi->mb.e_mbd.mode_ref_lf_delta_update = 0; - /* Dont increment frame counters if this was an altref buffer update + /* Don't increment frame counters if this was an altref buffer update * not a real frame */ if (cm->show_frame) { @@ -4778,10 +4851,14 @@ static void Pass2Encode(VP8_COMP *cpi, size_t *size, unsigned char *dest, int vp8_receive_raw_frame(VP8_COMP *cpi, unsigned int frame_flags, YV12_BUFFER_CONFIG *sd, int64_t time_stamp, int64_t end_time) { +#if CONFIG_INTERNAL_STATS struct vpx_usec_timer timer; +#endif int res = 0; +#if CONFIG_INTERNAL_STATS vpx_usec_timer_start(&timer); +#endif /* Reinit the lookahead buffer if the frame size changes */ if (sd->y_width != cpi->oxcf.Width || sd->y_height != cpi->oxcf.Height) { @@ -4794,8 +4871,10 @@ int vp8_receive_raw_frame(VP8_COMP *cpi, unsigned int frame_flags, cpi->active_map_enabled ? cpi->active_map : NULL)) { res = -1; } +#if CONFIG_INTERNAL_STATS vpx_usec_timer_mark(&timer); cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); +#endif return res; } @@ -4816,16 +4895,19 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned char *dest_end, int64_t *time_stamp, int64_t *time_end, int flush) { VP8_COMMON *cm; - struct vpx_usec_timer tsctimer; struct vpx_usec_timer ticktimer; +#if CONFIG_INTERNAL_STATS struct vpx_usec_timer cmptimer; +#endif YV12_BUFFER_CONFIG *force_src_buffer = NULL; if (!cpi) return -1; cm = &cpi->common; +#if CONFIG_INTERNAL_STATS vpx_usec_timer_start(&cmptimer); +#endif cpi->source = NULL; @@ -4962,6 +5044,7 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, } } #endif + cpi->ref_framerate = clamp_framerate(cpi->ref_framerate); if (cpi->oxcf.number_of_layers > 1) { unsigned int i; @@ -4999,7 +5082,6 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, } if (cpi->compressor_speed == 2) { - vpx_usec_timer_start(&tsctimer); vpx_usec_timer_start(&ticktimer); } @@ -5074,7 +5156,6 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, if (cpi->compressor_speed == 2) { unsigned int duration, duration2; - vpx_usec_timer_mark(&tsctimer); vpx_usec_timer_mark(&ticktimer); duration = (int)(vpx_usec_timer_elapsed(&ticktimer)); @@ -5101,18 +5182,18 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, } if (cm->refresh_entropy_probs == 0) { - memcpy(&cm->fc, &cm->lfc, sizeof(cm->fc)); + cm->fc = cm->lfc; } /* Save the contexts separately for alt ref, gold and last. */ /* (TODO jbb -> Optimize this with pointers to avoid extra copies. ) */ - if (cm->refresh_alt_ref_frame) memcpy(&cpi->lfc_a, &cm->fc, sizeof(cm->fc)); + if (cm->refresh_alt_ref_frame) cpi->lfc_a = cm->fc; - if (cm->refresh_golden_frame) memcpy(&cpi->lfc_g, &cm->fc, sizeof(cm->fc)); + if (cm->refresh_golden_frame) cpi->lfc_g = cm->fc; - if (cm->refresh_last_frame) memcpy(&cpi->lfc_n, &cm->fc, sizeof(cm->fc)); + if (cm->refresh_last_frame) cpi->lfc_n = cm->fc; - /* if its a dropped frame honor the requests on subsequent frames */ + /* if it's a dropped frame honor the requests on subsequent frames */ if (*size > 0) { cpi->droppable = !frame_is_reference(cpi); @@ -5127,8 +5208,18 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, /* Save layer specific state */ if (cpi->oxcf.number_of_layers > 1) vp8_save_layer_context(cpi); +#if CONFIG_INTERNAL_STATS vpx_usec_timer_mark(&cmptimer); cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); +#endif + +#if CONFIG_MULTITHREAD + /* wait for the lpf thread done */ + if (vpx_atomic_load_acquire(&cpi->b_multi_threaded) && cpi->b_lpf_running) { + vp8_sem_wait(&cpi->h_event_end_lpf); + cpi->b_lpf_running = 0; + } +#endif if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame) { generate_psnr_packet(cpi); @@ -5146,7 +5237,10 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, if (cpi->b_calculate_psnr) { uint64_t ye, ue, ve; double frame_psnr; - YV12_BUFFER_CONFIG *orig = cpi->Source; + YV12_BUFFER_CONFIG *orig = (cpi->oxcf.noise_sensitivity > 0 && + cpi->raw_source_frame.buffer_alloc) + ? &cpi->raw_source_frame + : cpi->Source; YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; unsigned int y_width = cpi->common.Width; unsigned int y_height = cpi->common.Height; @@ -5257,16 +5351,6 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, #endif #endif - cpi->common.error.setjmp = 0; - -#if CONFIG_MULTITHREAD - /* wait for the lpf thread done */ - if (vpx_atomic_load_acquire(&cpi->b_multi_threaded) && cpi->b_lpf_running) { - sem_wait(&cpi->h_event_end_lpf); - cpi->b_lpf_running = 0; - } -#endif - return 0; } @@ -5386,15 +5470,15 @@ int vp8_set_active_map(VP8_COMP *cpi, unsigned char *map, unsigned int rows, } } -int vp8_set_internal_size(VP8_COMP *cpi, VPX_SCALING horiz_mode, - VPX_SCALING vert_mode) { - if (horiz_mode <= ONETWO) { +int vp8_set_internal_size(VP8_COMP *cpi, VPX_SCALING_MODE horiz_mode, + VPX_SCALING_MODE vert_mode) { + if (horiz_mode <= VP8E_ONETWO) { cpi->common.horiz_scale = horiz_mode; } else { return -1; } - if (vert_mode <= ONETWO) { + if (vert_mode <= VP8E_ONETWO) { cpi->common.vert_scale = vert_mode; } else { return -1; diff --git a/libs/libvpx/vp8/encoder/onyx_int.h b/libs/libvpx/vp8/encoder/onyx_int.h index 424f51b180..aabed21104 100644 --- a/libs/libvpx/vp8/encoder/onyx_int.h +++ b/libs/libvpx/vp8/encoder/onyx_int.h @@ -11,13 +11,16 @@ #ifndef VPX_VP8_ENCODER_ONYX_INT_H_ #define VPX_VP8_ENCODER_ONYX_INT_H_ +#include #include + #include "vpx_config.h" #include "vp8/common/onyx.h" #include "treewriter.h" #include "tokenize.h" #include "vp8/common/onyxc_int.h" #include "vpx_dsp/variance.h" +#include "vpx_util/vpx_pthread.h" #include "encodemb.h" #include "vp8/encoder/quantize.h" #include "vp8/common/entropy.h" @@ -213,7 +216,7 @@ enum { typedef struct { /* Layer configuration */ double framerate; - int target_bandwidth; + int target_bandwidth; /* bits per second */ /* Layer specific coding parameters */ int64_t starting_buffer_level; @@ -229,7 +232,7 @@ typedef struct { int64_t bits_off_target; int64_t total_actual_bits; - int total_target_vs_actual; + int64_t total_target_vs_actual; int worst_quality; int active_worst_quality; @@ -300,6 +303,7 @@ typedef struct VP8_COMP { YV12_BUFFER_CONFIG *Source; YV12_BUFFER_CONFIG *un_scaled_source; YV12_BUFFER_CONFIG scaled_source; + YV12_BUFFER_CONFIG raw_source_frame; YV12_BUFFER_CONFIG *last_frame_unscaled_source; unsigned int frames_till_alt_ref_frame; @@ -358,7 +362,7 @@ typedef struct VP8_COMP { /* GF interval chosen when we coded the last GF */ int current_gf_interval; - /* Total bits overspent becasue of GF boost (cumulative) */ + /* Total bits overspent because of GF boost (cumulative) */ int gf_overspend_bits; /* Used in the few frames following a GF to recover the extra bits @@ -410,7 +414,7 @@ typedef struct VP8_COMP { int long_rolling_actual_bits; int64_t total_actual_bits; - int total_target_vs_actual; /* debug stats */ + int64_t total_target_vs_actual; /* debug stats */ int worst_quality; int active_worst_quality; @@ -436,7 +440,7 @@ typedef struct VP8_COMP { int kf_boost; int last_boost; - int target_bandwidth; + int target_bandwidth; /* bits per second */ struct vpx_codec_pkt_list *output_pkt_list; #if 0 @@ -483,7 +487,7 @@ typedef struct VP8_COMP { unsigned char *segmentation_map; signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS]; - int segment_encode_breakout[MAX_MB_SEGMENTS]; + unsigned int segment_encode_breakout[MAX_MB_SEGMENTS]; unsigned char *active_map; unsigned int active_map_enabled; @@ -524,6 +528,7 @@ typedef struct VP8_COMP { #if CONFIG_MULTITHREAD /* multithread data */ vpx_atomic_int *mt_current_mb_col; + int mt_current_mb_col_size; int mt_sync_range; vpx_atomic_int b_multi_threaded; int encoding_thread_count; @@ -537,10 +542,10 @@ typedef struct VP8_COMP { LPFTHREAD_DATA lpf_thread_data; /* events */ - sem_t *h_event_start_encoding; - sem_t *h_event_end_encoding; - sem_t h_event_start_lpf; - sem_t h_event_end_lpf; + vp8_sem_t *h_event_start_encoding; + vp8_sem_t *h_event_end_encoding; + vp8_sem_t h_event_start_lpf; + vp8_sem_t h_event_end_lpf; #endif TOKENLIST *tplist; @@ -552,10 +557,12 @@ typedef struct VP8_COMP { vp8_refining_search_fn_t refining_search_sad; vp8_diamond_search_fn_t diamond_search_sad; vp8_variance_fn_ptr_t fn_ptr[BLOCK_MAX_SEGMENTS]; +#if CONFIG_INTERNAL_STATS uint64_t time_receive_data; uint64_t time_compress_data; uint64_t time_pick_lpf; uint64_t time_encode_mb_row; +#endif int base_skip_false_prob[128]; @@ -619,7 +626,7 @@ typedef struct VP8_COMP { double totalp_v; double totalp; double total_sq_error2; - int bytes; + uint64_t bytes; double summed_quality; double summed_weights; unsigned int tot_recode_hits; @@ -705,13 +712,19 @@ typedef struct VP8_COMP { // Always update correction factor used for rate control after each frame for // realtime encoding. int rt_always_update_correction_factor; + + // Flag to indicate frame may be dropped due to large expected overshoot, + // and re-encoded on next frame at max_qp. + int rt_drop_recode_on_overshoot; } VP8_COMP; void vp8_initialize_enc(void); void vp8_alloc_compressor_data(VP8_COMP *cpi); int vp8_reverse_trans(int x); -void vp8_init_temporal_layer_context(VP8_COMP *cpi, VP8_CONFIG *oxcf, +void vp8_reset_temporal_layer_change(VP8_COMP *cpi, const VP8_CONFIG *oxcf, + const int prev_num_layers); +void vp8_init_temporal_layer_context(VP8_COMP *cpi, const VP8_CONFIG *oxcf, const int layer, double prev_layer_framerate); void vp8_update_layer_contexts(VP8_COMP *cpi); @@ -727,24 +740,8 @@ void vp8_tokenize_mb(VP8_COMP *, MACROBLOCK *, TOKENEXTRA **); void vp8_set_speed_features(VP8_COMP *cpi); -#if CONFIG_DEBUG -#define CHECK_MEM_ERROR(lval, expr) \ - do { \ - (lval) = (expr); \ - if (!(lval)) \ - vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, \ - "Failed to allocate " #lval " at %s:%d", __FILE__, \ - __LINE__); \ - } while (0) -#else -#define CHECK_MEM_ERROR(lval, expr) \ - do { \ - (lval) = (expr); \ - if (!(lval)) \ - vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, \ - "Failed to allocate " #lval); \ - } while (0) -#endif +int vp8_check_drop_buffer(VP8_COMP *cpi); + #ifdef __cplusplus } // extern "C" #endif diff --git a/libs/libvpx/vp8/encoder/pickinter.c b/libs/libvpx/vp8/encoder/pickinter.c index f4316e795d..ca6c18f48e 100644 --- a/libs/libvpx/vp8/encoder/pickinter.c +++ b/libs/libvpx/vp8/encoder/pickinter.c @@ -135,8 +135,8 @@ int vp8_skip_fractional_mv_step(MACROBLOCK *mb, BLOCK *b, BLOCKD *d, (void)mvcost; (void)distortion; (void)sse; - bestmv->as_mv.row *= 8; - bestmv->as_mv.col *= 8; + bestmv->as_mv.row = clamp(bestmv->as_mv.row * 8, SHRT_MIN, SHRT_MAX); + bestmv->as_mv.col = clamp(bestmv->as_mv.col * 8, SHRT_MIN, SHRT_MAX); return 0; } @@ -380,12 +380,18 @@ static void update_mvcount(MACROBLOCK *x, int_mv *best_ref_mv) { /* Split MV modes currently not supported when RD is nopt enabled, * therefore, only need to modify MVcount in NEWMV mode. */ if (xd->mode_info_context->mbmi.mode == NEWMV) { - x->MVcount[0][mv_max + ((xd->mode_info_context->mbmi.mv.as_mv.row - - best_ref_mv->as_mv.row) >> - 1)]++; - x->MVcount[1][mv_max + ((xd->mode_info_context->mbmi.mv.as_mv.col - - best_ref_mv->as_mv.col) >> - 1)]++; + const int row_val = + ((xd->mode_info_context->mbmi.mv.as_mv.row - best_ref_mv->as_mv.row) >> + 1); + const int row_idx = mv_max + row_val; + const int col_val = + ((xd->mode_info_context->mbmi.mv.as_mv.col - best_ref_mv->as_mv.col) >> + 1); + const int col_idx = mv_max + col_val; + if (row_idx >= 0 && row_idx < MVvals && col_idx >= 0 && col_idx < MVvals) { + x->MVcount[0][row_idx]++; + x->MVcount[1][col_idx]++; + } } } @@ -631,16 +637,16 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, } #endif assert(plane[LAST_FRAME][0] != NULL); - if (plane[LAST_FRAME][0]) dot_artifact_candidate = check_dot_artifact_candidate( + dot_artifact_candidate = check_dot_artifact_candidate( cpi, x, target_y, stride, plane[LAST_FRAME][0], mb_row, mb_col, 0); // If not found in Y channel, check UV channel. if (!dot_artifact_candidate) { assert(plane[LAST_FRAME][1] != NULL); - if (plane[LAST_FRAME][1]) dot_artifact_candidate = check_dot_artifact_candidate( + dot_artifact_candidate = check_dot_artifact_candidate( cpi, x, target_u, stride_uv, plane[LAST_FRAME][1], mb_row, mb_col, 1); if (!dot_artifact_candidate) { assert(plane[LAST_FRAME][2] != NULL); - if (plane[LAST_FRAME][2]) dot_artifact_candidate = check_dot_artifact_candidate( + dot_artifact_candidate = check_dot_artifact_candidate( cpi, x, target_v, stride_uv, plane[LAST_FRAME][2], mb_row, mb_col, 2); } @@ -1103,7 +1109,7 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, #if CONFIG_TEMPORAL_DENOISING if (cpi->oxcf.noise_sensitivity) { /* Store for later use by denoiser. */ - // Dont' denoise with GOLDEN OR ALTREF is they are old reference + // Don't denoise with GOLDEN OR ALTREF is they are old reference // frames (greater than MAX_GF_ARF_DENOISE_RANGE frames in past). int skip_old_reference = ((this_ref_frame != LAST_FRAME) && (cpi->common.current_video_frame - diff --git a/libs/libvpx/vp8/encoder/picklpf.c b/libs/libvpx/vp8/encoder/picklpf.c index 387ac9788b..498738fd6d 100644 --- a/libs/libvpx/vp8/encoder/picklpf.c +++ b/libs/libvpx/vp8/encoder/picklpf.c @@ -50,6 +50,14 @@ static void yv12_copy_partial_frame(YV12_BUFFER_CONFIG *src_ybc, src_y = src_ybc->y_buffer + yoffset; dst_y = dst_ybc->y_buffer + yoffset; + // The border will be used in vp8_loop_filter_partial_frame so it needs to be + // extended to avoid a valgrind warning. + const unsigned char *const top_row = src_ybc->y_buffer; + for (int i = yoffset; i < 0; i += ystride, --linestocopy) { + memcpy(dst_y, top_row, ystride); + dst_y += ystride; + src_y += ystride; + } memcpy(dst_y, src_y, ystride * linestocopy); } diff --git a/libs/libvpx/vp8/encoder/ratectrl.c b/libs/libvpx/vp8/encoder/ratectrl.c index 9cd3963e22..013d5881e3 100644 --- a/libs/libvpx/vp8/encoder/ratectrl.c +++ b/libs/libvpx/vp8/encoder/ratectrl.c @@ -259,9 +259,9 @@ void vp8_setup_key_frame(VP8_COMP *cpi) { /* Make sure we initialize separate contexts for altref,gold, and normal. * TODO shouldn't need 3 different copies of structure to do this! */ - memcpy(&cpi->lfc_a, &cpi->common.fc, sizeof(cpi->common.fc)); - memcpy(&cpi->lfc_g, &cpi->common.fc, sizeof(cpi->common.fc)); - memcpy(&cpi->lfc_n, &cpi->common.fc, sizeof(cpi->common.fc)); + cpi->lfc_a = cpi->common.fc; + cpi->lfc_g = cpi->common.fc; + cpi->lfc_n = cpi->common.fc; cpi->common.filter_level = cpi->common.base_qindex * 3 / 8; @@ -329,6 +329,11 @@ static void calc_iframe_target_size(VP8_COMP *cpi) { if (cpi->oxcf.number_of_layers == 1) { kf_boost = VPXMAX(initial_boost, (int)round(2 * cpi->output_framerate - 16)); + // cpi->output_framerate may be as large as 10M. Keep kf_boost small + // enough to allow for integer math when multiplying by values in + // kf_boost_qadjustment[]. + const int kMaxKfBoost = 2000; + if (kf_boost > kMaxKfBoost) kf_boost = kMaxKfBoost; } else { /* Initial factor: set target size to: |3.0 * per_frame_bandwidth|. */ kf_boost = initial_boost; @@ -346,7 +351,8 @@ static void calc_iframe_target_size(VP8_COMP *cpi) { /* Minimal target size is |2* per_frame_bandwidth|. */ if (kf_boost < 16) kf_boost = 16; - target = ((16 + kf_boost) * cpi->per_frame_bandwidth) >> 4; + target = ((uint64_t)(16 + kf_boost) * cpi->per_frame_bandwidth) >> 4; + target = VPXMIN(INT_MAX, target); } if (cpi->oxcf.rc_max_intra_bitrate_pct) { @@ -388,7 +394,7 @@ static void calc_gf_params(VP8_COMP *cpi) { (cpi->oxcf.fixed_q < 0) ? cpi->last_q[INTER_FRAME] : cpi->oxcf.fixed_q; int Boost = 0; - int gf_frame_useage = 0; /* Golden frame useage since last GF */ + int gf_frame_usage = 0; /* Golden frame usage since last GF */ int tot_mbs = cpi->recent_ref_frame_usage[INTRA_FRAME] + cpi->recent_ref_frame_usage[LAST_FRAME] + cpi->recent_ref_frame_usage[GOLDEN_FRAME] + @@ -398,12 +404,12 @@ static void calc_gf_params(VP8_COMP *cpi) { (cpi->common.mb_rows * cpi->common.mb_cols); if (tot_mbs) { - gf_frame_useage = (cpi->recent_ref_frame_usage[GOLDEN_FRAME] + - cpi->recent_ref_frame_usage[ALTREF_FRAME]) * - 100 / tot_mbs; + gf_frame_usage = (cpi->recent_ref_frame_usage[GOLDEN_FRAME] + + cpi->recent_ref_frame_usage[ALTREF_FRAME]) * + 100 / tot_mbs; } - if (pct_gf_active > gf_frame_useage) gf_frame_useage = pct_gf_active; + if (pct_gf_active > gf_frame_usage) gf_frame_usage = pct_gf_active; /* Not two pass */ if (cpi->pass != 2) { @@ -467,7 +473,7 @@ static void calc_gf_params(VP8_COMP *cpi) { /* Adjust boost based upon ambient Q */ Boost = GFQ_ADJUSTMENT; - /* Adjust based upon most recently measure intra useage */ + /* Adjust based upon most recently measure intra usage */ Boost = Boost * gf_intra_usage_adjustment[(cpi->this_frame_percent_intra < 15) ? cpi->this_frame_percent_intra @@ -475,7 +481,7 @@ static void calc_gf_params(VP8_COMP *cpi) { 100; /* Adjust gf boost based upon GF usage since last GF */ - Boost = Boost * gf_adjust_table[gf_frame_useage] / 100; + Boost = Boost * gf_adjust_table[gf_frame_usage] / 100; #endif } @@ -516,8 +522,8 @@ static void calc_gf_params(VP8_COMP *cpi) { if (cpi->last_boost >= 1500) cpi->frames_till_gf_update_due++; - if (gf_interval_table[gf_frame_useage] > cpi->frames_till_gf_update_due) { - cpi->frames_till_gf_update_due = gf_interval_table[gf_frame_useage]; + if (gf_interval_table[gf_frame_usage] > cpi->frames_till_gf_update_due) { + cpi->frames_till_gf_update_due = gf_interval_table[gf_frame_usage]; } if (cpi->frames_till_gf_update_due > cpi->max_gf_interval) { @@ -637,11 +643,10 @@ static void calc_pframe_target_size(VP8_COMP *cpi) { /* % Adjustment limited to the range 1% to 10% */ Adjustment = (cpi->last_boost - 100) >> 5; - if (Adjustment < 1) { - Adjustment = 1; - } else if (Adjustment > 10) { + if (Adjustment > 10) { Adjustment = 10; } + assert(Adjustment >= 1); /* Convert to bits */ Adjustment = (cpi->this_frame_target * Adjustment) / 100; @@ -718,7 +723,8 @@ static void calc_pframe_target_size(VP8_COMP *cpi) { } /* lower the target bandwidth for this frame. */ - cpi->this_frame_target -= (cpi->this_frame_target * percent_low) / 200; + cpi->this_frame_target -= + (int)(((int64_t)cpi->this_frame_target * percent_low) / 200); /* Are we using allowing control of active_worst_allowed_q * according to buffer level. @@ -789,8 +795,12 @@ static void calc_pframe_target_size(VP8_COMP *cpi) { (int)((cpi->buffer_level - cpi->oxcf.optimal_buffer_level) / one_percent_bits); } else if (cpi->bits_off_target > cpi->oxcf.optimal_buffer_level) { - percent_high = - (int)((100 * cpi->bits_off_target) / (cpi->total_byte_count * 8)); + if (cpi->total_byte_count > 0) { + percent_high = (int)((100 * cpi->bits_off_target) / + (cpi->total_byte_count * 8)); + } else { + percent_high = cpi->oxcf.over_shoot_pct; + } } if (percent_high > cpi->oxcf.over_shoot_pct) { @@ -895,7 +905,7 @@ static void calc_pframe_target_size(VP8_COMP *cpi) { int Q = (cpi->oxcf.fixed_q < 0) ? cpi->last_q[INTER_FRAME] : cpi->oxcf.fixed_q; - int gf_frame_useage = 0; /* Golden frame useage since last GF */ + int gf_frame_usage = 0; /* Golden frame usage since last GF */ int tot_mbs = cpi->recent_ref_frame_usage[INTRA_FRAME] + cpi->recent_ref_frame_usage[LAST_FRAME] + cpi->recent_ref_frame_usage[GOLDEN_FRAME] + @@ -905,20 +915,20 @@ static void calc_pframe_target_size(VP8_COMP *cpi) { (cpi->common.mb_rows * cpi->common.mb_cols); if (tot_mbs) { - gf_frame_useage = (cpi->recent_ref_frame_usage[GOLDEN_FRAME] + - cpi->recent_ref_frame_usage[ALTREF_FRAME]) * - 100 / tot_mbs; + gf_frame_usage = (cpi->recent_ref_frame_usage[GOLDEN_FRAME] + + cpi->recent_ref_frame_usage[ALTREF_FRAME]) * + 100 / tot_mbs; } - if (pct_gf_active > gf_frame_useage) gf_frame_useage = pct_gf_active; + if (pct_gf_active > gf_frame_usage) gf_frame_usage = pct_gf_active; /* Is a fixed manual GF frequency being used */ if (cpi->auto_gold) { - /* For one pass throw a GF if recent frame intra useage is - * low or the GF useage is high + /* For one pass throw a GF if recent frame intra usage is + * low or the GF usage is high */ if ((cpi->pass == 0) && - (cpi->this_frame_percent_intra < 15 || gf_frame_useage >= 5)) { + (cpi->this_frame_percent_intra < 15 || gf_frame_usage >= 5)) { cpi->common.refresh_golden_frame = 1; /* Two pass GF descision */ @@ -933,10 +943,10 @@ static void calc_pframe_target_size(VP8_COMP *cpi) { if (0) { FILE *f; - f = fopen("gf_useaget.stt", "a"); + f = fopen("gf_usaget.stt", "a"); fprintf(f, " %8ld %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, cpi->gfu_boost, - GFQ_ADJUSTMENT, cpi->gfu_boost, gf_frame_useage); + GFQ_ADJUSTMENT, cpi->gfu_boost, gf_frame_usage); fclose(f); } @@ -974,7 +984,9 @@ static void calc_pframe_target_size(VP8_COMP *cpi) { int Boost = cpi->last_boost; int frames_in_section = cpi->frames_till_gf_update_due + 1; int allocation_chunks = (frames_in_section * 100) + (Boost - 100); - int bits_in_section = cpi->inter_frame_target * frames_in_section; + int bits_in_section = + (int)VPXMIN(INT_MAX, (int64_t)cpi->inter_frame_target * + frames_in_section); /* Normalize Altboost and allocations chunck down to * prevent overflow @@ -1188,10 +1200,13 @@ int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame) { /* Calculate required scaling factor based on target frame size and * size of frame produced using previous Q */ - if (target_bits_per_frame >= (INT_MAX >> BPER_MB_NORMBITS)) { - /* Case where we would overflow int */ - target_bits_per_mb = (target_bits_per_frame / cpi->common.MBs) - << BPER_MB_NORMBITS; + if (target_bits_per_frame > (INT_MAX >> BPER_MB_NORMBITS)) { + int temp = target_bits_per_frame / cpi->common.MBs; + if (temp > (INT_MAX >> BPER_MB_NORMBITS)) { + target_bits_per_mb = INT_MAX; + } else { + target_bits_per_mb = temp << BPER_MB_NORMBITS; + } } else { target_bits_per_mb = (target_bits_per_frame << BPER_MB_NORMBITS) / cpi->common.MBs; @@ -1532,9 +1547,13 @@ int vp8_drop_encodedframe_overshoot(VP8_COMP *cpi, int Q) { // undershoots significantly, and then we end up dropping every other // frame because the QP/rate_correction_factor may have been too low // before the drop and then takes too long to come up. - if (target_size >= (INT_MAX >> BPER_MB_NORMBITS)) { - target_bits_per_mb = (target_size / cpi->common.MBs) - << BPER_MB_NORMBITS; + if (target_size > (INT_MAX >> BPER_MB_NORMBITS)) { + int temp = target_size / cpi->common.MBs; + if (temp > (INT_MAX >> BPER_MB_NORMBITS)) { + target_bits_per_mb = INT_MAX; + } else { + target_bits_per_mb = temp << BPER_MB_NORMBITS; + } } else { target_bits_per_mb = (target_size << BPER_MB_NORMBITS) / cpi->common.MBs; diff --git a/libs/libvpx/vp8/encoder/rdopt.c b/libs/libvpx/vp8/encoder/rdopt.c index 5821fc7346..ad3866c770 100644 --- a/libs/libvpx/vp8/encoder/rdopt.c +++ b/libs/libvpx/vp8/encoder/rdopt.c @@ -451,8 +451,8 @@ static int vp8_rdcost_mby(MACROBLOCK *mb) { ENTROPY_CONTEXT *ta; ENTROPY_CONTEXT *tl; - memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES)); - memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES)); + t_above = *mb->e_mbd.above_context; + t_left = *mb->e_mbd.left_context; ta = (ENTROPY_CONTEXT *)&t_above; tl = (ENTROPY_CONTEXT *)&t_left; @@ -597,8 +597,8 @@ static int rd_pick_intra4x4mby_modes(MACROBLOCK *mb, int *Rate, int *rate_y, ENTROPY_CONTEXT *tl; const int *bmode_costs; - memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES)); - memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES)); + t_above = *mb->e_mbd.above_context; + t_left = *mb->e_mbd.left_context; ta = (ENTROPY_CONTEXT *)&t_above; tl = (ENTROPY_CONTEXT *)&t_left; @@ -689,8 +689,8 @@ static int rd_cost_mbuv(MACROBLOCK *mb) { ENTROPY_CONTEXT *ta; ENTROPY_CONTEXT *tl; - memcpy(&t_above, mb->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES)); - memcpy(&t_left, mb->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES)); + t_above = *mb->e_mbd.above_context; + t_left = *mb->e_mbd.left_context; ta = (ENTROPY_CONTEXT *)&t_above; tl = (ENTROPY_CONTEXT *)&t_left; @@ -962,8 +962,8 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x, BEST_SEG_INFO *bsi, ENTROPY_CONTEXT_PLANES t_above, t_left; ENTROPY_CONTEXT_PLANES t_above_b, t_left_b; - memcpy(&t_above, x->e_mbd.above_context, sizeof(ENTROPY_CONTEXT_PLANES)); - memcpy(&t_left, x->e_mbd.left_context, sizeof(ENTROPY_CONTEXT_PLANES)); + t_above = *x->e_mbd.above_context; + t_left = *x->e_mbd.left_context; vp8_zero(t_above_b); vp8_zero(t_left_b); @@ -1003,8 +1003,8 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x, BEST_SEG_INFO *bsi, ENTROPY_CONTEXT *ta_s; ENTROPY_CONTEXT *tl_s; - memcpy(&t_above_s, &t_above, sizeof(ENTROPY_CONTEXT_PLANES)); - memcpy(&t_left_s, &t_left, sizeof(ENTROPY_CONTEXT_PLANES)); + t_above_s = t_above; + t_left_s = t_left; ta_s = (ENTROPY_CONTEXT *)&t_above_s; tl_s = (ENTROPY_CONTEXT *)&t_left_s; @@ -1021,7 +1021,7 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x, BEST_SEG_INFO *bsi, BLOCK *c; BLOCKD *e; - /* Is the best so far sufficiently good that we cant justify + /* Is the best so far sufficiently good that we can't justify * doing a new motion search. */ if (best_label_rd < label_mv_thresh) break; @@ -1146,13 +1146,13 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x, BEST_SEG_INFO *bsi, mode_selected = this_mode; best_label_rd = this_rd; - memcpy(&t_above_b, &t_above_s, sizeof(ENTROPY_CONTEXT_PLANES)); - memcpy(&t_left_b, &t_left_s, sizeof(ENTROPY_CONTEXT_PLANES)); + t_above_b = t_above_s; + t_left_b = t_left_s; } } /*for each 4x4 mode*/ - memcpy(&t_above, &t_above_b, sizeof(ENTROPY_CONTEXT_PLANES)); - memcpy(&t_left, &t_left_b, sizeof(ENTROPY_CONTEXT_PLANES)); + t_above = t_above_b; + t_left = t_left_b; labels2mode(x, labels, i, mode_selected, &mode_mv[mode_selected], bsi->ref_mv, x->mvcost); @@ -1564,21 +1564,34 @@ static void rd_update_mvcount(MACROBLOCK *x, int_mv *best_ref_mv) { for (i = 0; i < x->partition_info->count; ++i) { if (x->partition_info->bmi[i].mode == NEW4X4) { - x->MVcount[0][mv_max + ((x->partition_info->bmi[i].mv.as_mv.row - - best_ref_mv->as_mv.row) >> - 1)]++; - x->MVcount[1][mv_max + ((x->partition_info->bmi[i].mv.as_mv.col - - best_ref_mv->as_mv.col) >> - 1)]++; + const int row_val = ((x->partition_info->bmi[i].mv.as_mv.row - + best_ref_mv->as_mv.row) >> + 1); + const int row_idx = mv_max + row_val; + const int col_val = ((x->partition_info->bmi[i].mv.as_mv.col - + best_ref_mv->as_mv.col) >> + 1); + const int col_idx = mv_max + col_val; + if (row_idx >= 0 && row_idx < MVvals && col_idx >= 0 && + col_idx < MVvals) { + x->MVcount[0][row_idx]++; + x->MVcount[1][col_idx]++; + } } } } else if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV) { - x->MVcount[0][mv_max + ((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row - - best_ref_mv->as_mv.row) >> - 1)]++; - x->MVcount[1][mv_max + ((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col - - best_ref_mv->as_mv.col) >> - 1)]++; + const int row_val = ((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row - + best_ref_mv->as_mv.row) >> + 1); + const int row_idx = mv_max + row_val; + const int col_val = ((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col - + best_ref_mv->as_mv.col) >> + 1); + const int col_idx = mv_max + col_val; + if (row_idx >= 0 && row_idx < MVvals && col_idx >= 0 && col_idx < MVvals) { + x->MVcount[0][row_idx]++; + x->MVcount[1][col_idx]++; + } } } @@ -1608,7 +1621,7 @@ static int evaluate_inter_mode_rd(int mdcounts[4], RATE_DISTORTION *rd, unsigned int q2dc = xd->block[24].dequant[0]; /* If theres is no codeable 2nd order dc or a very small uniform pixel change change */ - if ((sse - var> 4) || (sse / 2 > var && sse - var < 64)) { + if ((sse - var < q2dc * q2dc >> 4) || (sse / 2 > var && sse - var < 64)) { /* Check u and v to make sure skip is ok */ unsigned int sse2 = VP8_UVSSE(x); if (sse2 * 2 < threshold) { @@ -1723,9 +1736,8 @@ static void update_best_mode(BEST_MODE *best_mode, int this_rd, (rd->distortion2 - rd->distortion_uv)); best_mode->rd = this_rd; - memcpy(&best_mode->mbmode, &x->e_mbd.mode_info_context->mbmi, - sizeof(MB_MODE_INFO)); - memcpy(&best_mode->partition, x->partition_info, sizeof(PARTITION_INFO)); + best_mode->mbmode = x->e_mbd.mode_info_context->mbmi; + best_mode->partition = *x->partition_info; if ((this_mode == B_PRED) || (this_mode == SPLITMV)) { int i; @@ -1979,7 +1991,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, rd.distortion2 += distortion; /* If even the 'Y' rd value of split is higher than best so far - * then dont bother looking at UV + * then don't bother looking at UV */ if (tmp_rd < best_mode.yrd) { /* Now work out UV cost and add it in */ @@ -2335,8 +2347,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, } /* macroblock modes */ - memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mode.mbmode, - sizeof(MB_MODE_INFO)); + x->e_mbd.mode_info_context->mbmi = best_mode.mbmode; if (best_mode.mbmode.mode == B_PRED) { for (i = 0; i < 16; ++i) { @@ -2349,7 +2360,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, xd->mode_info_context->bmi[i].mv.as_int = best_mode.bmodes[i].mv.as_int; } - memcpy(x->partition_info, &best_mode.partition, sizeof(PARTITION_INFO)); + *x->partition_info = best_mode.partition; x->e_mbd.mode_info_context->mbmi.mv.as_int = x->partition_info->bmi[15].mv.as_int; diff --git a/libs/libvpx/vp8/encoder/segmentation.c b/libs/libvpx/vp8/encoder/segmentation.c index dcb68119e1..2127258111 100644 --- a/libs/libvpx/vp8/encoder/segmentation.c +++ b/libs/libvpx/vp8/encoder/segmentation.c @@ -11,7 +11,7 @@ #include "segmentation.h" #include "vpx_mem/vpx_mem.h" -void vp8_update_gf_useage_maps(VP8_COMP *cpi, VP8_COMMON *cm, MACROBLOCK *x) { +void vp8_update_gf_usage_maps(VP8_COMP *cpi, VP8_COMMON *cm, MACROBLOCK *x) { int mb_row, mb_col; MODE_INFO *this_mb_mode_info = cm->mi; @@ -19,7 +19,7 @@ void vp8_update_gf_useage_maps(VP8_COMP *cpi, VP8_COMMON *cm, MACROBLOCK *x) { x->gf_active_ptr = (signed char *)cpi->gf_active_flags; if ((cm->frame_type == KEY_FRAME) || (cm->refresh_golden_frame)) { - /* Reset Gf useage monitors */ + /* Reset Gf usage monitors */ memset(cpi->gf_active_flags, 1, (cm->mb_rows * cm->mb_cols)); cpi->gf_active_count = cm->mb_rows * cm->mb_cols; } else { diff --git a/libs/libvpx/vp8/encoder/segmentation.h b/libs/libvpx/vp8/encoder/segmentation.h index 4ddbdbbd26..0fecfc2212 100644 --- a/libs/libvpx/vp8/encoder/segmentation.h +++ b/libs/libvpx/vp8/encoder/segmentation.h @@ -19,8 +19,8 @@ extern "C" { #endif -extern void vp8_update_gf_useage_maps(VP8_COMP *cpi, VP8_COMMON *cm, - MACROBLOCK *x); +extern void vp8_update_gf_usage_maps(VP8_COMP *cpi, VP8_COMMON *cm, + MACROBLOCK *x); #ifdef __cplusplus } // extern "C" diff --git a/libs/libvpx/vp8/encoder/tokenize.h b/libs/libvpx/vp8/encoder/tokenize.h index 47b5be17f1..5223aa2d86 100644 --- a/libs/libvpx/vp8/encoder/tokenize.h +++ b/libs/libvpx/vp8/encoder/tokenize.h @@ -18,8 +18,6 @@ extern "C" { #endif -void vp8_tokenize_initialize(); - typedef struct { short Token; short Extra; diff --git a/libs/libvpx/vp8/encoder/vp8_quantize.c b/libs/libvpx/vp8/encoder/vp8_quantize.c index 5b89555108..8b9b22babe 100644 --- a/libs/libvpx/vp8/encoder/vp8_quantize.c +++ b/libs/libvpx/vp8/encoder/vp8_quantize.c @@ -9,6 +9,9 @@ */ #include + +#include "./vpx_config.h" +#include "vpx_ports/bitops.h" #include "vpx_mem/vpx_mem.h" #include "onyx_int.h" @@ -162,10 +165,10 @@ static const int qzbin_factors_y2[129] = { static void invert_quant(int improved_quant, short *quant, short *shift, short d) { if (improved_quant) { - unsigned t; + unsigned int t; int l, m; - t = d; - for (l = 0; t > 1; ++l) t >>= 1; + t = (unsigned int)d; + l = get_msb(t); m = 1 + (1 << (16 + l)) / d; *quant = (short)(m - (1 << 16)); *shift = l; @@ -294,7 +297,7 @@ void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip) { /* Select the baseline MB Q index. */ if (xd->segmentation_enabled) { /* Abs Value */ - if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA) { + if (xd->mb_segment_abs_delta == SEGMENT_ABSDATA) { QIndex = xd->segment_feature_data[MB_LVL_ALT_Q] [xd->mode_info_context->mbmi.segment_id]; /* Delta Value */ diff --git a/libs/libvpx/vp8/encoder/x86/denoising_sse2.c b/libs/libvpx/vp8/encoder/x86/denoising_sse2.c index 89cad53356..f35b930169 100644 --- a/libs/libvpx/vp8/encoder/x86/denoising_sse2.c +++ b/libs/libvpx/vp8/encoder/x86/denoising_sse2.c @@ -30,7 +30,7 @@ static INLINE unsigned int abs_sum_diff_16x1(__m128i acc_diff) { _mm_add_epi32(hg_fe_dc_ba, _mm_srli_si128(hg_fe_dc_ba, 8)); const __m128i hgfedcba = _mm_add_epi32(hgfe_dcba, _mm_srli_si128(hgfe_dcba, 4)); - unsigned int sum_diff = abs(_mm_cvtsi128_si32(hgfedcba)); + unsigned int sum_diff = (unsigned int)abs(_mm_cvtsi128_si32(hgfedcba)); return sum_diff; } diff --git a/libs/libvpx/vp8/encoder/x86/quantize_sse4.c b/libs/libvpx/vp8/encoder/x86/quantize_sse4.c index 6d03365fcb..4c2d24cc27 100644 --- a/libs/libvpx/vp8/encoder/x86/quantize_sse4.c +++ b/libs/libvpx/vp8/encoder/x86/quantize_sse4.c @@ -13,8 +13,11 @@ #include "./vp8_rtcd.h" #include "vp8/encoder/block.h" #include "vpx_ports/bitops.h" /* get_lsb */ +#include "vpx_ports/compiler_attributes.h" -void vp8_regular_quantize_b_sse4_1(BLOCK *b, BLOCKD *d) { +// Unsigned shift overflow is disabled for the use of ~1U << eob with ymask. +VPX_NO_UNSIGNED_SHIFT_CHECK void vp8_regular_quantize_b_sse4_1(BLOCK *b, + BLOCKD *d) { int eob = -1; short *zbin_boost_ptr = b->zrun_zbin_boost; __m128i zbin_boost0 = _mm_load_si128((__m128i *)(zbin_boost_ptr)); diff --git a/libs/libvpx/vp8/vp8_common.mk b/libs/libvpx/vp8/vp8_common.mk index d485965d3d..1bbcc987d1 100644 --- a/libs/libvpx/vp8/vp8_common.mk +++ b/libs/libvpx/vp8/vp8_common.mk @@ -69,11 +69,14 @@ VP8_COMMON_SRCS-yes += common/vp8_entropymodedata.h VP8_COMMON_SRCS-yes += common/treecoder.c -VP8_COMMON_SRCS-$(VPX_ARCH_X86)$(VPX_ARCH_X86_64) += common/x86/vp8_asm_stubs.c -VP8_COMMON_SRCS-$(VPX_ARCH_X86)$(VPX_ARCH_X86_64) += common/x86/loopfilter_x86.c VP8_COMMON_SRCS-$(CONFIG_POSTPROC) += common/mfqe.c VP8_COMMON_SRCS-$(CONFIG_POSTPROC) += common/postproc.h VP8_COMMON_SRCS-$(CONFIG_POSTPROC) += common/postproc.c +VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/bilinear_filter_sse2.c + +ifeq ($(HAVE_X86_ASM),yes) +VP8_COMMON_SRCS-$(VPX_ARCH_X86)$(VPX_ARCH_X86_64) += common/x86/vp8_asm_stubs.c +VP8_COMMON_SRCS-$(VPX_ARCH_X86)$(VPX_ARCH_X86_64) += common/x86/loopfilter_x86.c VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/dequantize_mmx.asm VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/idct_blk_mmx.c VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/idctllm_mmx.asm @@ -82,17 +85,17 @@ VP8_COMMON_SRCS-$(HAVE_MMX) += common/x86/subpixel_mmx.asm VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/idct_blk_sse2.c VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/idctllm_sse2.asm VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/recon_sse2.asm -VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/bilinear_filter_sse2.c VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/subpixel_sse2.asm VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/loopfilter_sse2.asm VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/iwalsh_sse2.asm VP8_COMMON_SRCS-$(HAVE_SSSE3) += common/x86/subpixel_ssse3.asm +endif -ifeq ($(CONFIG_POSTPROC),yes) +ifeq ($(CONFIG_POSTPROC)$(HAVE_X86_ASM),yesyes) VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/mfqe_sse2.asm endif -ifeq ($(VPX_ARCH_X86_64),yes) +ifeq ($(VPX_ARCH_X86_64)$(HAVE_X86_ASM),yesyes) VP8_COMMON_SRCS-$(HAVE_SSE2) += common/x86/loopfilter_block_sse2_x86_64.asm endif diff --git a/libs/libvpx/vp8/vp8_cx_iface.c b/libs/libvpx/vp8/vp8_cx_iface.c index 340f3e6638..9957c47e44 100644 --- a/libs/libvpx/vp8/vp8_cx_iface.c +++ b/libs/libvpx/vp8/vp8_cx_iface.c @@ -8,24 +8,32 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include +#include +#include +#include +#include + #include "./vpx_config.h" #include "./vp8_rtcd.h" #include "./vpx_dsp_rtcd.h" #include "./vpx_scale_rtcd.h" -#include "vpx/vpx_codec.h" +#include "vpx/vpx_encoder.h" #include "vpx/internal/vpx_codec_internal.h" #include "vpx_version.h" #include "vpx_mem/vpx_mem.h" #include "vpx_ports/static_assert.h" #include "vpx_ports/system_state.h" #include "vpx_util/vpx_timestamp.h" +#if CONFIG_MULTITHREAD +#include "vp8/encoder/ethreading.h" +#endif #include "vp8/encoder/onyx_int.h" +#include "vp8/encoder/block.h" #include "vpx/vp8cx.h" #include "vp8/encoder/firstpass.h" #include "vp8/common/onyx.h" #include "vp8/common/common.h" -#include -#include struct vp8_extracfg { struct vpx_codec_pkt_list *pkt_list; @@ -51,7 +59,7 @@ static struct vp8_extracfg default_extracfg = { #if !(CONFIG_REALTIME_ONLY) 0, /* cpu_used */ #else - 4, /* cpu_used */ + 4, /* cpu_used */ #endif 0, /* enable_auto_alt_ref */ 0, /* noise_sensitivity */ @@ -92,13 +100,17 @@ struct vpx_codec_alg_priv { vpx_enc_frame_flags_t control_frame_flags; }; +// Called by update_extracfg(), vp8e_set_config() and vp8e_encode() only. Must +// not be called by vp8e_init() because the `error` paramerer +// (cpi->common.error) will be destroyed by vpx_codec_enc_init_ver() after +// vp8e_init() returns an error. +// See the "IMPORTANT" comment in vpx_codec_enc_init_ver(). static vpx_codec_err_t update_error_state( vpx_codec_alg_priv_t *ctx, const struct vpx_internal_error_info *error) { - vpx_codec_err_t res; + const vpx_codec_err_t res = error->error_code; - if ((res = error->error_code)) { + if (res != VPX_CODEC_OK) ctx->base.err_detail = error->has_detail ? error->detail : NULL; - } return res; } @@ -189,6 +201,9 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, RANGE_CHECK_BOOL(vp8_cfg, enable_auto_alt_ref); RANGE_CHECK(vp8_cfg, cpu_used, -16, 16); + /* Prevent (static_thresh >> 7) from exceeding MAX_ERROR_BINS (1024) */ + RANGE_CHECK_HI(vp8_cfg, static_thresh, (MAX_ERROR_BINS << 7) - 1); + #if CONFIG_REALTIME_ONLY && !CONFIG_TEMPORAL_DENOISING RANGE_CHECK(vp8_cfg, noise_sensitivity, 0, 0); #else @@ -207,34 +222,12 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, RANGE_CHECK(vp8_cfg, cq_level, cfg->rc_min_quantizer, cfg->rc_max_quantizer); -#if !(CONFIG_REALTIME_ONLY) - if (cfg->g_pass == VPX_RC_LAST_PASS) { - size_t packet_sz = sizeof(FIRSTPASS_STATS); - int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz); - FIRSTPASS_STATS *stats; - - if (!cfg->rc_twopass_stats_in.buf) - ERROR("rc_twopass_stats_in.buf not set."); - - if (cfg->rc_twopass_stats_in.sz % packet_sz) - ERROR("rc_twopass_stats_in.sz indicates truncated packet."); - - if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz) - ERROR("rc_twopass_stats_in requires at least two packets."); - - stats = (void *)((char *)cfg->rc_twopass_stats_in.buf + - (n_packets - 1) * packet_sz); - - if ((int)(stats->count + 0.5) != n_packets - 1) - ERROR("rc_twopass_stats_in missing EOS stats packet"); - } -#endif - + RANGE_CHECK(cfg, ss_number_layers, 1, VPX_SS_MAX_LAYERS); RANGE_CHECK(cfg, ts_number_layers, 1, 5); if (cfg->ts_number_layers > 1) { unsigned int i; - RANGE_CHECK_HI(cfg, ts_periodicity, 16); + RANGE_CHECK(cfg, ts_periodicity, 1, 16); for (i = 1; i < cfg->ts_number_layers; ++i) { if (cfg->ts_target_bitrate[i] <= cfg->ts_target_bitrate[i - 1] && @@ -248,7 +241,9 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, ERROR("ts_rate_decimator factors are not powers of 2"); } - RANGE_CHECK_HI(cfg, ts_layer_id[i], cfg->ts_number_layers - 1); + for (i = 0; i < cfg->ts_periodicity; ++i) { + RANGE_CHECK_HI(cfg, ts_layer_id[i], cfg->ts_number_layers - 1); + } } #if (CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING) @@ -264,6 +259,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, RANGE_CHECK(cfg, sr_diff_factor.den, 1, 1000); RANGE_CHECK(cfg, kf_err_per_mb_factor.den, 1, 1000); RANGE_CHECK(cfg, kf_frame_min_boost_factor.den, 1, 1000); + RANGE_CHECK(cfg, kf_frame_max_boost_first_factor.den, 1, 1000); RANGE_CHECK(cfg, kf_frame_max_boost_subs_factor.den, 1, 1000); RANGE_CHECK(cfg, kf_max_total_boost_factor.den, 1, 1000); RANGE_CHECK(cfg, gf_max_total_boost_factor.den, 1, 1000); @@ -273,6 +269,33 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, RANGE_CHECK(cfg, rd_mult_arf_qp_fac.den, 1, 1000); RANGE_CHECK(cfg, rd_mult_key_qp_fac.den, 1, 1000); +#if !(CONFIG_REALTIME_ONLY) + if (cfg->g_pass == VPX_RC_LAST_PASS) { + const size_t packet_sz = sizeof(FIRSTPASS_STATS); + const int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz); + const FIRSTPASS_STATS *stats; + + if (!cfg->rc_twopass_stats_in.buf) { + ERROR("rc_twopass_stats_in.buf not set."); + } + + if (cfg->rc_twopass_stats_in.sz % packet_sz) { + ERROR("rc_twopass_stats_in.sz indicates truncated packet."); + } + + if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz) { + ERROR("rc_twopass_stats_in requires at least two packets."); + } + + stats = + (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + n_packets - 1; + + if ((int)(stats->count + 0.5) != n_packets - 1) { + ERROR("rc_twopass_stats_in missing EOS stats packet"); + } + } +#endif + return VPX_CODEC_OK; } @@ -290,6 +313,9 @@ static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx, if ((img->d_w != ctx->cfg.g_w) || (img->d_h != ctx->cfg.g_h)) ERROR("Image size must match encoder init configuration size"); + assert(img->fmt & VPX_IMG_FMT_PLANAR); + if (img->stride[VPX_PLANE_U] != img->stride[VPX_PLANE_V]) + ERROR("Image U/V strides must match"); return VPX_CODEC_OK; } @@ -305,7 +331,9 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf, oxcf->Height = cfg.g_h; oxcf->timebase = cfg.g_timebase; - oxcf->error_resilient_mode = cfg.g_error_resilient; + oxcf->error_resilient_mode = + cfg.g_error_resilient & + (VPX_ERROR_RESILIENT_DEFAULT | VPX_ERROR_RESILIENT_PARTITIONS); switch (cfg.g_pass) { case VPX_RC_ONE_PASS: oxcf->Mode = MODE_BESTQUALITY; break; @@ -387,8 +415,7 @@ static vpx_codec_err_t set_vp8e_config(VP8_CONFIG *oxcf, if (mr_cfg) { oxcf->mr_total_resolutions = mr_cfg->mr_total_resolutions; oxcf->mr_encoder_id = mr_cfg->mr_encoder_id; - oxcf->mr_down_sampling_factor.num = mr_cfg->mr_down_sampling_factor.num; - oxcf->mr_down_sampling_factor.den = mr_cfg->mr_down_sampling_factor.den; + oxcf->mr_down_sampling_factor = mr_cfg->mr_down_sampling_factor; oxcf->mr_low_res_mode_info = mr_cfg->mr_low_res_mode_info; } #else @@ -488,6 +515,12 @@ static vpx_codec_err_t vp8e_set_config(vpx_codec_alg_priv_t *ctx, ctx->cfg = *cfg; set_vp8e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg, NULL); vp8_change_config(ctx->cpi, &ctx->oxcf); +#if CONFIG_MULTITHREAD + if (vp8cx_create_encoder_threads(ctx->cpi)) { + ctx->cpi->common.error.setjmp = 0; + return VPX_CODEC_ERROR; + } +#endif ctx->cpi->common.error.setjmp = 0; return VPX_CODEC_OK; } @@ -510,12 +543,22 @@ static vpx_codec_err_t get_quantizer64(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t update_extracfg(vpx_codec_alg_priv_t *ctx, const struct vp8_extracfg *extra_cfg) { const vpx_codec_err_t res = validate_config(ctx, &ctx->cfg, extra_cfg, 0); - if (res == VPX_CODEC_OK) { - ctx->vp8_cfg = *extra_cfg; - set_vp8e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg, NULL); - vp8_change_config(ctx->cpi, &ctx->oxcf); + if (res != VPX_CODEC_OK) return res; + + if (setjmp(ctx->cpi->common.error.jmp)) { + const vpx_codec_err_t codec_err = + update_error_state(ctx, &ctx->cpi->common.error); + ctx->cpi->common.error.setjmp = 0; + vpx_clear_system_state(); + assert(codec_err != VPX_CODEC_OK); + return codec_err; } - return res; + ctx->cpi->common.error.setjmp = 1; + ctx->vp8_cfg = *extra_cfg; + set_vp8e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg, NULL); + vp8_change_config(ctx->cpi, &ctx->oxcf); + ctx->cpi->common.error.setjmp = 0; + return VPX_CODEC_OK; } static vpx_codec_err_t set_cpu_used(vpx_codec_alg_priv_t *ctx, va_list args) { @@ -618,10 +661,11 @@ static vpx_codec_err_t set_screen_content_mode(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t ctrl_set_rtc_external_ratectrl(vpx_codec_alg_priv_t *ctx, va_list args) { VP8_COMP *cpi = ctx->cpi; - const unsigned int data = CAST(VP8E_SET_GF_CBR_BOOST_PCT, args); + const unsigned int data = CAST(VP8E_SET_RTC_EXTERNAL_RATECTRL, args); if (data) { cpi->cyclic_refresh_mode_enabled = 0; cpi->rt_always_update_correction_factor = 1; + cpi->rt_drop_recode_on_overshoot = 0; } return VPX_CODEC_OK; } @@ -651,11 +695,22 @@ static vpx_codec_err_t vp8e_mr_alloc_mem(const vpx_codec_enc_cfg_t *cfg, } #else (void)cfg; - (void)mem_loc; + *mem_loc = NULL; #endif return res; } +static void vp8e_mr_free_mem(void *mem_loc) { +#if CONFIG_MULTI_RES_ENCODING + LOWER_RES_FRAME_INFO *shared_mem_loc = (LOWER_RES_FRAME_INFO *)mem_loc; + free(shared_mem_loc->mb_info); + free(mem_loc); +#else + (void)mem_loc; + assert(!mem_loc); +#endif +} + static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx, vpx_codec_priv_enc_mr_cfg_t *mr_cfg) { vpx_codec_err_t res = VPX_CODEC_OK; @@ -693,6 +748,7 @@ static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx, priv->cx_data = malloc(priv->cx_data_sz); if (!priv->cx_data) { + priv->cx_data_sz = 0; return VPX_CODEC_MEM_ERROR; } @@ -715,7 +771,17 @@ static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx, set_vp8e_config(&priv->oxcf, priv->cfg, priv->vp8_cfg, mr_cfg); priv->cpi = vp8_create_compressor(&priv->oxcf); - if (!priv->cpi) res = VPX_CODEC_MEM_ERROR; + if (!priv->cpi) { +#if CONFIG_MULTI_RES_ENCODING + // Release ownership of mr_cfg->mr_low_res_mode_info on failure. This + // prevents ownership confusion with the caller and avoids a double + // free when vpx_codec_destroy() is called on this instance. + priv->oxcf.mr_total_resolutions = 0; + priv->oxcf.mr_encoder_id = 0; + priv->oxcf.mr_low_res_mode_info = NULL; +#endif + res = VPX_CODEC_MEM_ERROR; + } } } @@ -727,10 +793,7 @@ static vpx_codec_err_t vp8e_destroy(vpx_codec_alg_priv_t *ctx) { /* Free multi-encoder shared memory */ if (ctx->oxcf.mr_total_resolutions > 0 && (ctx->oxcf.mr_encoder_id == ctx->oxcf.mr_total_resolutions - 1)) { - LOWER_RES_FRAME_INFO *shared_mem_loc = - (LOWER_RES_FRAME_INFO *)ctx->oxcf.mr_low_res_mode_info; - free(shared_mem_loc->mb_info); - free(ctx->oxcf.mr_low_res_mode_info); + vp8e_mr_free_mem(ctx->oxcf.mr_low_res_mode_info); } #endif @@ -751,6 +814,10 @@ static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img, yv12->u_buffer = img->planes[VPX_PLANE_U]; yv12->v_buffer = img->planes[VPX_PLANE_V]; + // TODO(issue 520751602): this should use img->w/h to set y_width/y_height + // and that should be used to calculate uv_width/height after the code is + // updated to correctly use uv_crop_width/height to avoid using uninitialized + // data from the border. yv12->y_crop_width = y_w; yv12->y_crop_height = y_h; yv12->y_width = y_w; @@ -761,15 +828,16 @@ static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img, yv12->uv_height = uv_h; yv12->y_stride = img->stride[VPX_PLANE_Y]; + assert(img->stride[VPX_PLANE_U] == img->stride[VPX_PLANE_V]); yv12->uv_stride = img->stride[VPX_PLANE_U]; yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2; return res; } -static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, - unsigned long duration, - unsigned long deadline) { +static vpx_codec_err_t pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, + unsigned long duration, + vpx_enc_deadline_t deadline) { int new_qc; #if !(CONFIG_REALTIME_ONLY) @@ -778,13 +846,15 @@ static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, if (deadline) { /* Convert duration parameter from stream timebase to microseconds */ - uint64_t duration_us; - VPX_STATIC_ASSERT(TICKS_PER_SEC > 1000000 && (TICKS_PER_SEC % 1000000) == 0); - duration_us = duration * (uint64_t)ctx->timestamp_ratio.num / - (ctx->timestamp_ratio.den * (TICKS_PER_SEC / 1000000)); + if (duration > UINT64_MAX / (uint64_t)ctx->timestamp_ratio.num) { + ERROR("duration is too big"); + } + uint64_t duration_us = + duration * (uint64_t)ctx->timestamp_ratio.num / + ((uint64_t)ctx->timestamp_ratio.den * (TICKS_PER_SEC / 1000000)); /* If the deadline is more that the duration this frame is to be shown, * use good quality mode. Otherwise use realtime mode. @@ -810,6 +880,7 @@ static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, ctx->oxcf.Mode = new_qc; vp8_change_config(ctx->cpi, &ctx->oxcf); } + return VPX_CODEC_OK; } static vpx_codec_err_t set_reference_and_update(vpx_codec_alg_priv_t *ctx, @@ -859,7 +930,7 @@ static vpx_codec_err_t vp8e_encode(vpx_codec_alg_priv_t *ctx, const vpx_image_t *img, vpx_codec_pts_t pts, unsigned long duration, vpx_enc_frame_flags_t enc_flags, - unsigned long deadline) { + vpx_enc_deadline_t deadline) { volatile vpx_codec_err_t res = VPX_CODEC_OK; // Make a copy as volatile to avoid -Wclobbered with longjmp. volatile vpx_enc_frame_flags_t flags = enc_flags; @@ -884,13 +955,7 @@ static vpx_codec_err_t vp8e_encode(vpx_codec_alg_priv_t *ctx, if (!res) res = validate_config(ctx, &ctx->cfg, &ctx->vp8_cfg, 1); - if (!ctx->pts_offset_initialized) { - ctx->pts_offset = pts_val; - ctx->pts_offset_initialized = 1; - } - pts_val -= ctx->pts_offset; - - pick_quickcompress_mode(ctx, duration, deadline); + if (!res) res = pick_quickcompress_mode(ctx, duration, deadline); vpx_codec_pkt_list_init(&ctx->pkt_list); // If no flags are set in the encode call, then use the frame flags as @@ -911,26 +976,37 @@ static vpx_codec_err_t vp8e_encode(vpx_codec_alg_priv_t *ctx, } } - if (setjmp(ctx->cpi->common.error.jmp)) { - ctx->cpi->common.error.setjmp = 0; - vpx_clear_system_state(); - return VPX_CODEC_CORRUPT_FRAME; - } - - /* Initialize the encoder instance on the first frame*/ + /* Initialize the encoder instance on the first frame */ if (!res && ctx->cpi) { unsigned int lib_flags; - YV12_BUFFER_CONFIG sd; int64_t dst_time_stamp, dst_end_time_stamp; size_t size, cx_data_sz; unsigned char *cx_data; unsigned char *cx_data_end; int comp_data_state = 0; - /* Set up internal flags */ - if (ctx->base.init_flags & VPX_CODEC_USE_PSNR) { - ((VP8_COMP *)ctx->cpi)->b_calculate_psnr = 1; + if (setjmp(ctx->cpi->common.error.jmp)) { + ctx->cpi->common.error.setjmp = 0; + res = update_error_state(ctx, &ctx->cpi->common.error); + vpx_clear_system_state(); + return res; } + ctx->cpi->common.error.setjmp = 1; + + // Per-frame PSNR is not supported when g_lag_in_frames is greater than 0. + if ((flags & VPX_EFLAG_CALCULATE_PSNR) && ctx->cfg.g_lag_in_frames != 0) { + vpx_internal_error( + &ctx->cpi->common.error, VPX_CODEC_INCAPABLE, + "Cannot calculate per-frame PSNR when g_lag_in_frames is nonzero"); + } + /* Set up internal flags */ +#if CONFIG_INTERNAL_STATS + assert(((VP8_COMP *)ctx->cpi)->b_calculate_psnr == 1); +#else + ((VP8_COMP *)ctx->cpi)->b_calculate_psnr = + (ctx->base.init_flags & VPX_CODEC_USE_PSNR) || + (flags & VPX_EFLAG_CALCULATE_PSNR); +#endif if (ctx->base.init_flags & VPX_CODEC_USE_OUTPUT_PARTITION) { ((VP8_COMP *)ctx->cpi)->output_partition = 1; @@ -939,12 +1015,44 @@ static vpx_codec_err_t vp8e_encode(vpx_codec_alg_priv_t *ctx, /* Convert API flags to internal codec lib flags */ lib_flags = (flags & VPX_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; - dst_time_stamp = - pts_val * ctx->timestamp_ratio.num / ctx->timestamp_ratio.den; - dst_end_time_stamp = (pts_val + (int64_t)duration) * - ctx->timestamp_ratio.num / ctx->timestamp_ratio.den; - if (img != NULL) { + YV12_BUFFER_CONFIG sd; + + if (!ctx->pts_offset_initialized) { + ctx->pts_offset = pts_val; + ctx->pts_offset_initialized = 1; + } + if (pts_val < ctx->pts_offset) { + vpx_internal_error(&ctx->cpi->common.error, VPX_CODEC_INVALID_PARAM, + "pts is smaller than initial pts"); + } + pts_val -= ctx->pts_offset; + if (pts_val > INT64_MAX / ctx->timestamp_ratio.num) { + vpx_internal_error( + &ctx->cpi->common.error, VPX_CODEC_INVALID_PARAM, + "conversion of relative pts to ticks would overflow"); + } + dst_time_stamp = + pts_val * ctx->timestamp_ratio.num / ctx->timestamp_ratio.den; +#if ULONG_MAX > INT64_MAX + if (duration > INT64_MAX) { + vpx_internal_error(&ctx->cpi->common.error, VPX_CODEC_INVALID_PARAM, + "duration is too big"); + } +#endif + if (pts_val > INT64_MAX - (int64_t)duration) { + vpx_internal_error(&ctx->cpi->common.error, VPX_CODEC_INVALID_PARAM, + "relative pts + duration is too big"); + } + vpx_codec_pts_t pts_end = pts_val + (int64_t)duration; + if (pts_end > INT64_MAX / ctx->timestamp_ratio.num) { + vpx_internal_error( + &ctx->cpi->common.error, VPX_CODEC_INVALID_PARAM, + "conversion of relative pts + duration to ticks would overflow"); + } + dst_end_time_stamp = + pts_end * ctx->timestamp_ratio.num / ctx->timestamp_ratio.den; + res = image2yuvconfig(img, &sd); if (vp8_receive_raw_frame(ctx->cpi, ctx->next_frame_flag | lib_flags, &sd, @@ -962,14 +1070,13 @@ static vpx_codec_err_t vp8e_encode(vpx_codec_alg_priv_t *ctx, cx_data_end = ctx->cx_data + cx_data_sz; lib_flags = 0; - ctx->cpi->common.error.setjmp = 1; - while (cx_data_sz >= ctx->cx_data_sz / 2) { comp_data_state = vp8_get_compressed_data( ctx->cpi, &lib_flags, &size, cx_data, cx_data_end, &dst_time_stamp, &dst_end_time_stamp, !img); if (comp_data_state == VPX_CODEC_CORRUPT_FRAME) { + ctx->cpi->common.error.setjmp = 0; return VPX_CODEC_CORRUPT_FRAME; } else if (comp_data_state == -1) { break; @@ -1059,6 +1166,7 @@ static vpx_codec_err_t vp8e_encode(vpx_codec_alg_priv_t *ctx, } } } + ctx->cpi->common.error.setjmp = 0; } return res; @@ -1076,9 +1184,16 @@ static vpx_codec_err_t vp8e_set_reference(vpx_codec_alg_priv_t *ctx, if (data) { vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; YV12_BUFFER_CONFIG sd; + if (frame->img.planes[VPX_PLANE_Y] == NULL || + frame->img.planes[VPX_PLANE_U] == NULL || + frame->img.planes[VPX_PLANE_V] == NULL) { + return VPX_CODEC_INVALID_PARAM; + } image2yuvconfig(&frame->img, &sd); - vp8_set_reference(ctx->cpi, frame->frame_type, &sd); + if (vp8_set_reference(ctx->cpi, frame->frame_type, &sd)) { + return VPX_CODEC_INVALID_PARAM; + } return VPX_CODEC_OK; } else { return VPX_CODEC_INVALID_PARAM; @@ -1092,9 +1207,16 @@ static vpx_codec_err_t vp8e_get_reference(vpx_codec_alg_priv_t *ctx, if (data) { vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; YV12_BUFFER_CONFIG sd; + if (frame->img.planes[VPX_PLANE_Y] == NULL || + frame->img.planes[VPX_PLANE_U] == NULL || + frame->img.planes[VPX_PLANE_V] == NULL) { + return VPX_CODEC_INVALID_PARAM; + } image2yuvconfig(&frame->img, &sd); - vp8_get_reference(ctx->cpi, frame->frame_type, &sd); + if (vp8_get_reference(ctx->cpi, frame->frame_type, &sd)) { + return VPX_CODEC_INVALID_PARAM; + } return VPX_CODEC_OK; } else { return VPX_CODEC_INVALID_PARAM; @@ -1224,8 +1346,8 @@ static vpx_codec_err_t vp8e_set_scalemode(vpx_codec_alg_priv_t *ctx, if (data) { int res; vpx_scaling_mode_t scalemode = *(vpx_scaling_mode_t *)data; - res = vp8_set_internal_size(ctx->cpi, (VPX_SCALING)scalemode.h_scaling_mode, - (VPX_SCALING)scalemode.v_scaling_mode); + res = vp8_set_internal_size(ctx->cpi, scalemode.h_scaling_mode, + scalemode.v_scaling_mode); if (!res) { /*force next frame a key frame to effect scaling mode */ @@ -1292,8 +1414,8 @@ static vpx_codec_enc_cfg_map_t vp8e_usage_cfg_map[] = { 0, /* rc_resize_allowed */ 1, /* rc_scaled_width */ 1, /* rc_scaled_height */ - 60, /* rc_resize_down_thresold */ - 30, /* rc_resize_up_thresold */ + 60, /* rc_resize_down_thresh */ + 30, /* rc_resize_up_thresh */ VPX_VBR, /* rc_end_usage */ { NULL, 0 }, /* rc_twopass_stats_in */ @@ -1374,5 +1496,6 @@ CODEC_INTERFACE(vpx_codec_vp8_cx) = { NULL, vp8e_get_preview, vp8e_mr_alloc_mem, + vp8e_mr_free_mem, } /* encoder functions */ }; diff --git a/libs/libvpx/vp8/vp8_dx_iface.c b/libs/libvpx/vp8/vp8_dx_iface.c index c11abbad9a..0507d8db40 100644 --- a/libs/libvpx/vp8/vp8_dx_iface.c +++ b/libs/libvpx/vp8/vp8_dx_iface.c @@ -20,6 +20,7 @@ #include "vpx_version.h" #include "common/alloccommon.h" #include "common/common.h" +#include "common/onyxc_int.h" #include "common/onyxd.h" #include "decoder/onyxd_int.h" #include "vpx_dsp/vpx_dsp_common.h" @@ -123,20 +124,14 @@ static vpx_codec_err_t vp8_destroy(vpx_codec_alg_priv_t *ctx) { return VPX_CODEC_OK; } -#ifdef __clang_analyzer__ -#define FUNC_ATTR_NONNULL(...) __attribute__((nonnull(__VA_ARGS__))) -#else -#define FUNC_ATTR_NONNULL(...) -#endif - static vpx_codec_err_t vp8_peek_si_internal(const uint8_t *data, unsigned int data_sz, vpx_codec_stream_info_t *si, vpx_decrypt_cb decrypt_cb, - void *decrypt_state) FUNC_ATTR_NONNULL(1) { + void *decrypt_state) { vpx_codec_err_t res = VPX_CODEC_OK; - assert(data != NULL); + if (data == NULL) return VPX_CODEC_INVALID_PARAM; if (data + data_sz <= data) { res = VPX_CODEC_INVALID_PARAM; @@ -168,7 +163,10 @@ static vpx_codec_err_t vp8_peek_si_internal(const uint8_t *data, si->h = (clear[8] | (clear[9] << 8)) & 0x3fff; /*printf("w=%d, h=%d\n", si->w, si->h);*/ - if (!(si->h && si->w)) res = VPX_CODEC_CORRUPT_FRAME; + if (!(si->h && si->w)) { + si->w = si->h = 0; + res = VPX_CODEC_CORRUPT_FRAME; + } } else { res = VPX_CODEC_UNSUP_BITSTREAM; } @@ -248,18 +246,26 @@ static int update_fragments(vpx_codec_alg_priv_t *ctx, const uint8_t *data, memset((void *)ctx->fragments.ptrs, 0, sizeof(ctx->fragments.ptrs)); memset(ctx->fragments.sizes, 0, sizeof(ctx->fragments.sizes)); } + + /* Flush signal in fragment mode but no fragments were accumulated yet. + * Nothing to decode; treat as a no-op. */ + if (ctx->fragments.enabled && data == NULL && data_sz == 0 && + ctx->fragments.count == 0) { + return 0; + } + if (ctx->fragments.enabled && !(data == NULL && data_sz == 0)) { /* Store a pointer to this fragment and return. We haven't * received the complete frame yet, so we will wait with decoding. */ - ctx->fragments.ptrs[ctx->fragments.count] = data; - ctx->fragments.sizes[ctx->fragments.count] = data_sz; - ctx->fragments.count++; - if (ctx->fragments.count > (1 << EIGHT_PARTITION) + 1) { + if (ctx->fragments.count >= MAX_PARTITIONS) { ctx->fragments.count = 0; *res = VPX_CODEC_INVALID_PARAM; return -1; } + ctx->fragments.ptrs[ctx->fragments.count] = data; + ctx->fragments.sizes[ctx->fragments.count] = data_sz; + ctx->fragments.count++; return 0; } @@ -278,10 +284,10 @@ static int update_fragments(vpx_codec_alg_priv_t *ctx, const uint8_t *data, static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx, const uint8_t *data, unsigned int data_sz, - void *user_priv, long deadline) { - volatile vpx_codec_err_t res = VPX_CODEC_INVALID_PARAM; + void *user_priv) { + volatile vpx_codec_err_t res; volatile unsigned int resolution_change = 0; - unsigned int w, h; + volatile unsigned int w, h; if (!ctx->fragments.enabled && (data == NULL && data_sz == 0)) { return 0; @@ -297,10 +303,8 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx, w = ctx->si.w; h = ctx->si.h; - if (ctx->fragments.ptrs[0]) { - res = vp8_peek_si_internal(ctx->fragments.ptrs[0], ctx->fragments.sizes[0], + res = vp8_peek_si_internal(ctx->fragments.ptrs[0], ctx->fragments.sizes[0], &ctx->si, ctx->decrypt_cb, ctx->decrypt_state); - } if ((res == VPX_CODEC_UNSUP_BITSTREAM) && !ctx->si.is_kf) { /* the peek function returns an error for non keyframes, however for @@ -308,19 +312,44 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx, res = VPX_CODEC_OK; } +#if CONFIG_SIZE_LIMIT + // Reject oversized keyframes before decoder initialization allocates frame + // buffers. + if (!res && ctx->si.is_kf && + (ctx->si.w > DECODE_WIDTH_LIMIT || ctx->si.h > DECODE_HEIGHT_LIMIT)) { + ctx->si.w = 0; + ctx->si.h = 0; + res = VPX_CODEC_CORRUPT_FRAME; + } +#endif + if (!ctx->decoder_init && !ctx->si.is_kf) res = VPX_CODEC_UNSUP_BITSTREAM; + if (!res && ctx->decoder_init && w == 0 && h == 0 && ctx->si.h == 0 && + ctx->si.w == 0) { + VP8D_COMP *pbi = ctx->yv12_frame_buffers.pbi[0]; + assert(pbi != NULL); + assert(!pbi->common.error.setjmp); + res = VPX_CODEC_CORRUPT_FRAME; + vpx_internal_error(&pbi->common.error, res, + "Keyframe / intra-only frame required to reset decoder" + " state"); + } if ((ctx->si.h != h) || (ctx->si.w != w)) resolution_change = 1; #if CONFIG_MULTITHREAD if (!res && ctx->restart_threads) { - struct frame_buffers *fb = &ctx->yv12_frame_buffers; VP8D_COMP *pbi = ctx->yv12_frame_buffers.pbi[0]; VP8_COMMON *const pc = &pbi->common; if (setjmp(pbi->common.error.jmp)) { - vp8_remove_decoder_instances(fb); - vp8_zero(fb->pbi); + pbi->common.error.setjmp = 0; + /* on failure clear the cached resolution to ensure a full + * reallocation is attempted on resync. */ + ctx->si.w = 0; + ctx->si.h = 0; + vp8_decoder_remove_threads(pbi); vpx_clear_system_state(); + ctx->fragments.count = 0; return VPX_CODEC_ERROR; } pbi->common.error.setjmp = 1; @@ -357,7 +386,14 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx, } res = vp8_create_decoder_instances(&ctx->yv12_frame_buffers, &oxcf); - if (res == VPX_CODEC_OK) ctx->decoder_init = 1; + if (res == VPX_CODEC_OK) { + ctx->decoder_init = 1; + } else { + /* on failure clear the cached resolution to ensure a full + * reallocation is attempted on resync. */ + ctx->si.w = 0; + ctx->si.h = 0; + } } /* Set these even if already initialized. The caller may have changed the @@ -387,6 +423,7 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx, ctx->si.h = 0; vpx_clear_system_state(); /* same return value as used in vp8dx_receive_compressed_data */ + ctx->fragments.count = 0; return -1; } @@ -410,6 +447,7 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx, } #endif + pbi->decoded_key_frame = 0; if (vp8_alloc_frame_buffers(pc, pc->Width, pc->Height)) { vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, "Failed to allocate frame buffers"); @@ -476,7 +514,7 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx, if (pc->fb_idx_ref_cnt[pc->new_fb_idx] > 0) { pc->fb_idx_ref_cnt[pc->new_fb_idx]--; } - pc->error.setjmp = 0; + pbi->common.error.setjmp = 0; #if CONFIG_MULTITHREAD if (pbi->restart_threads) { ctx->si.w = 0; @@ -485,6 +523,7 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx, } #endif res = update_error_state(ctx, &pbi->common.error); + ctx->fragments.count = 0; return res; } @@ -496,14 +535,15 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx, pbi->restart_threads = 0; #endif ctx->user_priv = user_priv; - if (vp8dx_receive_compressed_data(pbi, deadline)) { + if (vp8dx_receive_compressed_data(pbi)) { res = update_error_state(ctx, &pbi->common.error); } - /* get ready for the next series of fragments */ - ctx->fragments.count = 0; + pbi->common.error.setjmp = 0; } + /* A complete fragment sequence is consumed even when decoding fails. */ + ctx->fragments.count = 0; return res; } @@ -516,7 +556,6 @@ static vpx_image_t *vp8_get_frame(vpx_codec_alg_priv_t *ctx, */ if (!(*iter) && ctx->yv12_frame_buffers.pbi[0]) { YV12_BUFFER_CONFIG sd; - int64_t time_stamp = 0, time_end_stamp = 0; vp8_ppflags_t flags; vp8_zero(flags); @@ -526,8 +565,7 @@ static vpx_image_t *vp8_get_frame(vpx_codec_alg_priv_t *ctx, flags.noise_level = ctx->postproc_cfg.noise_level; } - if (0 == vp8dx_get_raw_frame(ctx->yv12_frame_buffers.pbi[0], &sd, - &time_stamp, &time_end_stamp, &flags)) { + if (0 == vp8dx_get_raw_frame(ctx->yv12_frame_buffers.pbi[0], &sd, &flags)) { yuvconfig2image(&ctx->img, &sd, ctx->user_priv); img = &ctx->img; @@ -573,8 +611,16 @@ static vpx_codec_err_t vp8_set_reference(vpx_codec_alg_priv_t *ctx, vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; YV12_BUFFER_CONFIG sd; + if (frame->img.planes[VPX_PLANE_Y] == NULL || + frame->img.planes[VPX_PLANE_U] == NULL || + frame->img.planes[VPX_PLANE_V] == NULL) { + return VPX_CODEC_INVALID_PARAM; + } + image2yuvconfig(&frame->img, &sd); + if (ctx->yv12_frame_buffers.pbi[0] == NULL) return VPX_CODEC_CORRUPT_FRAME; + return vp8dx_set_reference(ctx->yv12_frame_buffers.pbi[0], frame->frame_type, &sd); } else { @@ -590,8 +636,16 @@ static vpx_codec_err_t vp8_get_reference(vpx_codec_alg_priv_t *ctx, vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; YV12_BUFFER_CONFIG sd; + if (frame->img.planes[VPX_PLANE_Y] == NULL || + frame->img.planes[VPX_PLANE_U] == NULL || + frame->img.planes[VPX_PLANE_V] == NULL) { + return VPX_CODEC_INVALID_PARAM; + } + image2yuvconfig(&frame->img, &sd); + if (ctx->yv12_frame_buffers.pbi[0] == NULL) return VPX_CODEC_CORRUPT_FRAME; + return vp8dx_get_reference(ctx->yv12_frame_buffers.pbi[0], frame->frame_type, &sd); } else { @@ -736,6 +790,7 @@ CODEC_INTERFACE(vpx_codec_vp8_dx) = { NULL, /* vpx_codec_enc_config_set_fn_t */ NULL, /* vpx_codec_get_global_headers_fn_t */ NULL, /* vpx_codec_get_preview_frame_fn_t */ - NULL /* vpx_codec_enc_mr_get_mem_loc_fn_t */ + NULL, /* vpx_codec_enc_mr_get_mem_loc_fn_t */ + NULL /* vpx_codec_enc_mr_free_mem_loc_fn_t */ } }; diff --git a/libs/libvpx/vp8/vp8_ratectrl_rtc.cc b/libs/libvpx/vp8/vp8_ratectrl_rtc.cc index 2f23c5b1d9..312092f190 100644 --- a/libs/libvpx/vp8/vp8_ratectrl_rtc.cc +++ b/libs/libvpx/vp8/vp8_ratectrl_rtc.cc @@ -8,9 +8,14 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include -#include #include "vp8/vp8_ratectrl_rtc.h" + +#include + +#include + +#include "vp8/common/common.h" +#include "vp8/encoder/onyx_int.h" #include "vp8/encoder/ratectrl.h" #include "vpx_ports/system_state.h" @@ -60,12 +65,19 @@ std::unique_ptr VP8RateControlRTC::Create( if (!rc_api->cpi_) return nullptr; vp8_zero(*rc_api->cpi_); - rc_api->InitRateControl(cfg); + if (!rc_api->InitRateControl(cfg)) return nullptr; return rc_api; } -void VP8RateControlRTC::InitRateControl(const VP8RateControlRtcConfig &rc_cfg) { +VP8RateControlRTC::~VP8RateControlRTC() { + if (cpi_) { + vpx_free(cpi_->gf_active_flags); + vpx_free(cpi_); + } +} + +bool VP8RateControlRTC::InitRateControl(const VP8RateControlRtcConfig &rc_cfg) { VP8_COMMON *cm = &cpi_->common; VP8_CONFIG *oxcf = &cpi_->oxcf; oxcf->end_usage = USAGE_STREAM_FROM_SERVER; @@ -83,15 +95,22 @@ void VP8RateControlRTC::InitRateControl(const VP8RateControlRtcConfig &rc_cfg) { cpi_->kf_bitrate_adjustment = 0; cpi_->gf_overspend_bits = 0; cpi_->non_gf_bitrate_adjustment = 0; - UpdateRateControl(rc_cfg); + if (!UpdateRateControl(rc_cfg)) return false; cpi_->buffer_level = oxcf->starting_buffer_level; cpi_->bits_off_target = oxcf->starting_buffer_level; + return true; } -void VP8RateControlRTC::UpdateRateControl( +bool VP8RateControlRTC::UpdateRateControl( const VP8RateControlRtcConfig &rc_cfg) { + if (rc_cfg.ts_number_layers < 1 || + rc_cfg.ts_number_layers > VPX_TS_MAX_LAYERS) { + return false; + } + VP8_COMMON *cm = &cpi_->common; VP8_CONFIG *oxcf = &cpi_->oxcf; + const unsigned int prev_number_of_layers = oxcf->number_of_layers; vpx_clear_system_state(); cm->Width = rc_cfg.width; cm->Height = rc_cfg.height; @@ -117,24 +136,42 @@ void VP8RateControlRTC::UpdateRateControl( cpi_->buffered_mode = oxcf->optimal_buffer_level > 0; oxcf->under_shoot_pct = rc_cfg.undershoot_pct; oxcf->over_shoot_pct = rc_cfg.overshoot_pct; + oxcf->drop_frames_water_mark = rc_cfg.frame_drop_thresh; + if (oxcf->drop_frames_water_mark > 0) cpi_->drop_frames_allowed = 1; cpi_->oxcf.rc_max_intra_bitrate_pct = rc_cfg.max_intra_bitrate_pct; cpi_->framerate = rc_cfg.framerate; for (int i = 0; i < KEY_FRAME_CONTEXT; ++i) { cpi_->prior_key_frame_distance[i] = static_cast(cpi_->output_framerate); } - - if (oxcf->number_of_layers > 1) { + oxcf->screen_content_mode = rc_cfg.is_screen; + if (oxcf->number_of_layers > 1 || prev_number_of_layers > 1) { memcpy(oxcf->target_bitrate, rc_cfg.layer_target_bitrate, sizeof(rc_cfg.layer_target_bitrate)); memcpy(oxcf->rate_decimator, rc_cfg.ts_rate_decimator, sizeof(rc_cfg.ts_rate_decimator)); - oxcf->periodicity = 2; + if (cm->current_video_frame == 0) { + double prev_layer_framerate = 0; + for (unsigned int i = 0; i < oxcf->number_of_layers; ++i) { + vp8_init_temporal_layer_context(cpi_, oxcf, i, prev_layer_framerate); + prev_layer_framerate = cpi_->output_framerate / oxcf->rate_decimator[i]; + } + } else if (oxcf->number_of_layers != prev_number_of_layers) { + // The number of temporal layers has changed, so reset/initialize the + // temporal layer context for the new layer configuration: this means + // calling vp8_reset_temporal_layer_change() below. - double prev_layer_framerate = 0; - for (unsigned int i = 0; i < oxcf->number_of_layers; ++i) { - vp8_init_temporal_layer_context(cpi_, oxcf, i, prev_layer_framerate); - prev_layer_framerate = cpi_->output_framerate / oxcf->rate_decimator[i]; + // Start at the base of the pattern cycle, so set the layer id to 0 and + // reset the temporal pattern counter. + // TODO(marpan/jianj): don't think lines 148-151 are needed (user controls + // the layer_id) so remove. + if (cpi_->temporal_layer_id > 0) { + cpi_->temporal_layer_id = 0; + } + cpi_->temporal_pattern_counter = 0; + + vp8_reset_temporal_layer_change(cpi_, oxcf, + static_cast(prev_number_of_layers)); } } @@ -146,20 +183,24 @@ void VP8RateControlRTC::UpdateRateControl( cm->MBs = cm->mb_rows * cm->mb_cols; cm->mode_info_stride = cm->mb_cols + 1; - oxcf->starting_buffer_level = - rescale((int)oxcf->starting_buffer_level, oxcf->target_bandwidth, 1000); - /* Set or reset optimal and maximum buffer levels. */ - if (oxcf->optimal_buffer_level == 0) { - oxcf->optimal_buffer_level = oxcf->target_bandwidth / 8; - } else { - oxcf->optimal_buffer_level = - rescale((int)oxcf->optimal_buffer_level, oxcf->target_bandwidth, 1000); - } - if (oxcf->maximum_buffer_size == 0) { - oxcf->maximum_buffer_size = oxcf->target_bandwidth / 8; - } else { - oxcf->maximum_buffer_size = - rescale((int)oxcf->maximum_buffer_size, oxcf->target_bandwidth, 1000); + // For temporal layers: starting/maximum/optimal_buffer_level is already set + // via vp8_init_temporal_layer_context() or vp8_reset_temporal_layer_change(). + if (oxcf->number_of_layers <= 1 && prev_number_of_layers <= 1) { + oxcf->starting_buffer_level = + rescale((int)oxcf->starting_buffer_level, oxcf->target_bandwidth, 1000); + /* Set or reset optimal and maximum buffer levels. */ + if (oxcf->optimal_buffer_level == 0) { + oxcf->optimal_buffer_level = oxcf->target_bandwidth / 8; + } else { + oxcf->optimal_buffer_level = rescale((int)oxcf->optimal_buffer_level, + oxcf->target_bandwidth, 1000); + } + if (oxcf->maximum_buffer_size == 0) { + oxcf->maximum_buffer_size = oxcf->target_bandwidth / 8; + } else { + oxcf->maximum_buffer_size = + rescale((int)oxcf->maximum_buffer_size, oxcf->target_bandwidth, 1000); + } } if (cpi_->bits_off_target > oxcf->maximum_buffer_size) { @@ -169,9 +210,11 @@ void VP8RateControlRTC::UpdateRateControl( vp8_new_framerate(cpi_, cpi_->framerate); vpx_clear_system_state(); + return true; } -void VP8RateControlRTC::ComputeQP(const VP8FrameParamsQpRTC &frame_params) { +FrameDropDecision VP8RateControlRTC::ComputeQP( + const VP8FrameParamsQpRTC &frame_params) { VP8_COMMON *const cm = &cpi_->common; vpx_clear_system_state(); if (cpi_->oxcf.number_of_layers > 1) { @@ -182,14 +225,27 @@ void VP8RateControlRTC::ComputeQP(const VP8FrameParamsQpRTC &frame_params) { vp8_restore_layer_context(cpi_, layer); vp8_new_framerate(cpi_, cpi_->layer_context[layer].framerate); } - cm->frame_type = frame_params.frame_type; + cm->frame_type = static_cast(frame_params.frame_type); cm->refresh_golden_frame = (cm->frame_type == KEY_FRAME) ? 1 : 0; cm->refresh_alt_ref_frame = (cm->frame_type == KEY_FRAME) ? 1 : 0; if (cm->frame_type == KEY_FRAME && cpi_->common.current_video_frame > 0) { cpi_->common.frame_flags |= FRAMEFLAGS_KEY; } - vp8_pick_frame_size(cpi_); + cpi_->per_frame_bandwidth = static_cast( + round(cpi_->oxcf.target_bandwidth / cpi_->output_framerate)); + if (vp8_check_drop_buffer(cpi_)) { + if (cpi_->oxcf.number_of_layers > 1) vp8_save_layer_context(cpi_); + return FrameDropDecision::kDrop; + } + + if (!vp8_pick_frame_size(cpi_)) { + cm->current_video_frame++; + cpi_->frames_since_key++; + cpi_->ext_refresh_frame_flags_pending = 0; + if (cpi_->oxcf.number_of_layers > 1) vp8_save_layer_context(cpi_); + return FrameDropDecision::kDrop; + } if (cpi_->buffer_level >= cpi_->oxcf.optimal_buffer_level && cpi_->buffered_mode) { @@ -253,10 +309,47 @@ void VP8RateControlRTC::ComputeQP(const VP8FrameParamsQpRTC &frame_params) { q_ = vp8_regulate_q(cpi_, cpi_->this_frame_target); vp8_set_quantizer(cpi_, q_); vpx_clear_system_state(); + return FrameDropDecision::kOk; } int VP8RateControlRTC::GetQP() const { return q_; } +UVDeltaQP VP8RateControlRTC::GetUVDeltaQP() const { + VP8_COMMON *cm = &cpi_->common; + UVDeltaQP uv_delta_q; + uv_delta_q.uvdc_delta_q = cm->uvdc_delta_q; + uv_delta_q.uvac_delta_q = cm->uvac_delta_q; + return uv_delta_q; +} + +int VP8RateControlRTC::GetLoopfilterLevel() const { + VP8_COMMON *cm = &cpi_->common; + const double qp = q_; + + // This model is from linear regression + if (cm->Width * cm->Height <= 320 * 240) { + cm->filter_level = static_cast(0.352685 * qp + 2.957774); + } else if (cm->Width * cm->Height <= 640 * 480) { + cm->filter_level = static_cast(0.485069 * qp - 0.534462); + } else { + cm->filter_level = static_cast(0.314875 * qp + 7.959003); + } + + int min_filter_level = 0; + // This logic is from get_min_filter_level() in picklpf.c + if (q_ > 6 && q_ <= 16) { + min_filter_level = 1; + } else { + min_filter_level = (q_ / 8); + } + + const int max_filter_level = 63; + if (cm->filter_level < min_filter_level) cm->filter_level = min_filter_level; + if (cm->filter_level > max_filter_level) cm->filter_level = max_filter_level; + + return cm->filter_level; +} + void VP8RateControlRTC::PostEncodeUpdate(uint64_t encoded_frame_size) { VP8_COMMON *const cm = &cpi_->common; vpx_clear_system_state(); diff --git a/libs/libvpx/vp8/vp8_ratectrl_rtc.h b/libs/libvpx/vp8/vp8_ratectrl_rtc.h index def7dd8f9e..b458b5ce65 100644 --- a/libs/libvpx/vp8/vp8_ratectrl_rtc.h +++ b/libs/libvpx/vp8/vp8_ratectrl_rtc.h @@ -12,23 +12,23 @@ #define VPX_VP8_RATECTRL_RTC_H_ #include +#include #include -#include "vp8/encoder/onyx_int.h" -#include "vp8/common/common.h" #include "vpx/internal/vpx_ratectrl_rtc.h" +struct VP8_COMP; + namespace libvpx { struct VP8RateControlRtcConfig : public VpxRateControlRtcConfig { - public: VP8RateControlRtcConfig() { - vp8_zero(layer_target_bitrate); - vp8_zero(ts_rate_decimator); + memset(&layer_target_bitrate, 0, sizeof(layer_target_bitrate)); + memset(&ts_rate_decimator, 0, sizeof(ts_rate_decimator)); } }; struct VP8FrameParamsQpRTC { - FRAME_TYPE frame_type; + RcFrameType frame_type; int temporal_layer_id; }; @@ -36,26 +36,29 @@ class VP8RateControlRTC { public: static std::unique_ptr Create( const VP8RateControlRtcConfig &cfg); - ~VP8RateControlRTC() { - if (cpi_) { - vpx_free(cpi_->gf_active_flags); - vpx_free(cpi_); - } - } + ~VP8RateControlRTC(); - void UpdateRateControl(const VP8RateControlRtcConfig &rc_cfg); + bool UpdateRateControl(const VP8RateControlRtcConfig &rc_cfg); // GetQP() needs to be called after ComputeQP() to get the latest QP int GetQP() const; - // int GetLoopfilterLevel() const; - void ComputeQP(const VP8FrameParamsQpRTC &frame_params); + // GetUVDeltaQP() needs to be called after ComputeQP() to get the latest + // delta QP for UV. + UVDeltaQP GetUVDeltaQP() const; + // GetLoopfilterLevel() needs to be called after ComputeQP() since loopfilter + // level is calculated from frame qp. + int GetLoopfilterLevel() const; + // ComputeQP computes the QP if the frame is not dropped (kOk return), + // otherwise it returns kDrop and subsequent GetQP and PostEncodeUpdate + // are not to be called. + FrameDropDecision ComputeQP(const VP8FrameParamsQpRTC &frame_params); // Feedback to rate control with the size of current encoded frame void PostEncodeUpdate(uint64_t encoded_frame_size); private: - VP8RateControlRTC() {} - void InitRateControl(const VP8RateControlRtcConfig &cfg); - VP8_COMP *cpi_; - int q_; + VP8RateControlRTC() = default; + bool InitRateControl(const VP8RateControlRtcConfig &cfg); + struct VP8_COMP *cpi_ = nullptr; + int q_ = -1; }; } // namespace libvpx diff --git a/libs/libvpx/vp8/vp8cx.mk b/libs/libvpx/vp8/vp8cx.mk index 5744cbabcc..9765a44776 100644 --- a/libs/libvpx/vp8/vp8cx.mk +++ b/libs/libvpx/vp8/vp8cx.mk @@ -83,10 +83,6 @@ VP8_CX_SRCS_REMOVE-yes += encoder/temporal_filter.c VP8_CX_SRCS_REMOVE-yes += encoder/temporal_filter.h endif -VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/copy_sse2.asm -VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/copy_sse3.asm -VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/dct_sse2.asm -VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/fwalsh_sse2.asm VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp8_quantize_sse2.c VP8_CX_SRCS-$(HAVE_SSSE3) += encoder/x86/vp8_quantize_ssse3.c VP8_CX_SRCS-$(HAVE_SSE4_1) += encoder/x86/quantize_sse4.c @@ -95,11 +91,17 @@ ifeq ($(CONFIG_TEMPORAL_DENOISING),yes) VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/denoising_sse2.c endif +ifeq ($(HAVE_X86_ASM),yes) VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/block_error_sse2.asm +VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/copy_sse2.asm +VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/copy_sse3.asm +VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/dct_sse2.asm +VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/fwalsh_sse2.asm VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/temporal_filter_apply_sse2.asm VP8_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp8_enc_stubs_sse2.c +endif -ifeq ($(CONFIG_REALTIME_ONLY),yes) +ifeq ($(CONFIG_REALTIME_ONLY)$(HAVE_X86_ASM),yesyes) VP8_CX_SRCS_REMOVE-$(HAVE_SSE2) += encoder/x86/temporal_filter_apply_sse2.asm endif @@ -125,8 +127,8 @@ VP8_CX_SRCS_REMOVE-$(HAVE_MSA) += encoder/mips/msa/temporal_filter_msa.c endif # common (loongarch LSX intrinsics) -VP8_CX_SRCS-$(HAVE_LSX) += encoder/loongarch/quantize_lsx.c VP8_CX_SRCS-$(HAVE_LSX) += encoder/loongarch/dct_lsx.c VP8_CX_SRCS-$(HAVE_LSX) += encoder/loongarch/encodeopt_lsx.c +VP8_CX_SRCS-$(HAVE_LSX) += encoder/loongarch/vp8_quantize_lsx.c VP8_CX_SRCS-yes := $(filter-out $(VP8_CX_SRCS_REMOVE-yes),$(VP8_CX_SRCS-yes)) diff --git a/libs/libvpx/vp9/common/arm/neon/vp9_highbd_iht16x16_add_neon.c b/libs/libvpx/vp9/common/arm/neon/vp9_highbd_iht16x16_add_neon.c index 219ff63cb8..b43d7fa4f9 100644 --- a/libs/libvpx/vp9/common/arm/neon/vp9_highbd_iht16x16_add_neon.c +++ b/libs/libvpx/vp9/common/arm/neon/vp9_highbd_iht16x16_add_neon.c @@ -18,7 +18,7 @@ #include "vpx_dsp/arm/transpose_neon.h" #include "vpx_dsp/inv_txfm.h" -// Use macros to make sure argument lane is passed in as an constant integer. +// Use macros to make sure argument lane is passed in as a constant integer. #define vmull_lane_s32_dual(in, c, lane, out) \ do { \ @@ -64,9 +64,9 @@ highbd_dct_const_round_shift_low_8(const int64x2x2_t *const in) { #define highbd_iadst_half_butterfly(in, c, lane, out) \ do { \ - int64x2x2_t t[2]; \ - vmull_lane_s32_dual(in, c, lane, t); \ - out = highbd_dct_const_round_shift_low_8(t); \ + int64x2x2_t _t[2]; \ + vmull_lane_s32_dual(in, c, lane, _t); \ + out = highbd_dct_const_round_shift_low_8(_t); \ } while (0) #define highbd_iadst_butterfly(in0, in1, c, lane0, lane1, s0, s1) \ diff --git a/libs/libvpx/vp9/common/vp9_alloccommon.c b/libs/libvpx/vp9/common/vp9_alloccommon.c index 48103a44d8..93a8407f66 100644 --- a/libs/libvpx/vp9/common/vp9_alloccommon.c +++ b/libs/libvpx/vp9/common/vp9_alloccommon.c @@ -65,6 +65,7 @@ static void free_seg_map(VP9_COMMON *cm) { vpx_free(cm->seg_map_array[i]); cm->seg_map_array[i] = NULL; } + cm->seg_map_alloc_size = 0; cm->current_frame_seg_map = NULL; cm->last_frame_seg_map = NULL; @@ -96,6 +97,7 @@ void vp9_free_postproc_buffers(VP9_COMMON *cm) { cm->postproc_state.limits = NULL; vpx_free(cm->postproc_state.generated_noise); cm->postproc_state.generated_noise = NULL; + cm->postproc_state.generated_noise_size = 0; #else (void)cm; #endif @@ -108,6 +110,7 @@ void vp9_free_context_buffers(VP9_COMMON *cm) { cm->above_context = NULL; vpx_free(cm->above_seg_context); cm->above_seg_context = NULL; + cm->above_context_alloc_cols = 0; vpx_free(cm->lf.lfm); cm->lf.lfm = NULL; } @@ -133,7 +136,6 @@ int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) { cm->free_mi(cm); if (cm->alloc_mi(cm, new_mi_size)) goto fail; } - if (cm->above_context_alloc_cols < cm->mi_cols) { vpx_free(cm->above_context); cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc( diff --git a/libs/libvpx/vp9/common/vp9_blockd.h b/libs/libvpx/vp9/common/vp9_blockd.h index d7de46cf4f..514d6b7764 100644 --- a/libs/libvpx/vp9/common/vp9_blockd.h +++ b/libs/libvpx/vp9/common/vp9_blockd.h @@ -54,7 +54,7 @@ typedef struct { // decoder implementation modules critically rely on the defined entry values // specified herein. They should be refactored concurrently. -#define NONE (-1) +#define NO_REF_FRAME (-1) #define INTRA_FRAME 0 #define LAST_FRAME 1 #define GOLDEN_FRAME 2 @@ -142,7 +142,7 @@ struct macroblockd_plane { int *eob; }; -#define BLOCK_OFFSET(x, i) ((x) + (i)*16) +#define BLOCK_OFFSET(x, i) ((x) + (i) * 16) typedef struct RefBuffer { // TODO(dkovalev): idx is not really required and should be removed, now it diff --git a/libs/libvpx/vp9/common/vp9_common.h b/libs/libvpx/vp9/common/vp9_common.h index 3cec53bfd8..8856be2818 100644 --- a/libs/libvpx/vp9/common/vp9_common.h +++ b/libs/libvpx/vp9/common/vp9_common.h @@ -26,17 +26,17 @@ extern "C" { #endif // Only need this for fixed-size arrays, for structs just assign. -#define vp9_copy(dest, src) \ - do { \ - assert(sizeof(dest) == sizeof(src)); \ - memcpy(dest, src, sizeof(src)); \ +#define vp9_copy(dest, src) \ + do { \ + static_assert(sizeof(dest) == sizeof(src), ""); \ + memcpy(dest, src, sizeof(src)); \ } while (0) // Use this for variably-sized arrays. -#define vp9_copy_array(dest, src, n) \ - { \ - assert(sizeof(*(dest)) == sizeof(*(src))); \ - memcpy(dest, src, (n) * sizeof(*(src))); \ +#define vp9_copy_array(dest, src, n) \ + { \ + static_assert(sizeof(*(dest)) == sizeof(*(src)), ""); \ + memcpy(dest, src, (n) * sizeof(*(src))); \ } #define vp9_zero(dest) memset(&(dest), 0, sizeof(dest)) @@ -46,25 +46,6 @@ static INLINE int get_unsigned_bits(unsigned int num_values) { return num_values > 0 ? get_msb(num_values) + 1 : 0; } -#if CONFIG_DEBUG -#define CHECK_MEM_ERROR(cm, lval, expr) \ - do { \ - (lval) = (expr); \ - if (!(lval)) \ - vpx_internal_error(&(cm)->error, VPX_CODEC_MEM_ERROR, \ - "Failed to allocate " #lval " at %s:%d", __FILE__, \ - __LINE__); \ - } while (0) -#else -#define CHECK_MEM_ERROR(cm, lval, expr) \ - do { \ - (lval) = (expr); \ - if (!(lval)) \ - vpx_internal_error(&(cm)->error, VPX_CODEC_MEM_ERROR, \ - "Failed to allocate " #lval); \ - } while (0) -#endif - #define VP9_SYNC_CODE_0 0x49 #define VP9_SYNC_CODE_1 0x83 #define VP9_SYNC_CODE_2 0x42 diff --git a/libs/libvpx/vp9/common/vp9_entropy.c b/libs/libvpx/vp9/common/vp9_entropy.c index 430b917b8f..5013b097cf 100644 --- a/libs/libvpx/vp9/common/vp9_entropy.c +++ b/libs/libvpx/vp9/common/vp9_entropy.c @@ -1059,7 +1059,7 @@ static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE tx_size, vp9_coeff_probs_model *const probs = cm->fc->coef_probs[tx_size]; const vp9_coeff_probs_model *const pre_probs = pre_fc->coef_probs[tx_size]; vp9_coeff_count_model *counts = cm->counts.coef[tx_size]; - unsigned int(*eob_counts)[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] = + unsigned int (*eob_counts)[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] = cm->counts.eob_branch[tx_size]; int i, j, k, l, m; diff --git a/libs/libvpx/vp9/common/vp9_entropy.h b/libs/libvpx/vp9/common/vp9_entropy.h index d026651df7..ebe2873ef3 100644 --- a/libs/libvpx/vp9/common/vp9_entropy.h +++ b/libs/libvpx/vp9/common/vp9_entropy.h @@ -36,11 +36,13 @@ extern "C" { #define CATEGORY5_TOKEN 9 // 35-66 Extra Bits 5+1 #define CATEGORY6_TOKEN 10 // 67+ Extra Bits 14+1 #define EOB_TOKEN 11 // EOB Extra Bits 0+0 +#define MAX_TOKEN EOB_TOKEN #define ENTROPY_TOKENS 12 #define ENTROPY_NODES 11 +#define MAX_ENERGY_CLASS 5 DECLARE_ALIGNED(16, extern const uint8_t, vp9_pt_energy_class[ENTROPY_TOKENS]); #define CAT1_MIN_VAL 5 diff --git a/libs/libvpx/vp9/common/vp9_entropymode.c b/libs/libvpx/vp9/common/vp9_entropymode.c index bda824de3c..9289fc9e1f 100644 --- a/libs/libvpx/vp9/common/vp9_entropymode.c +++ b/libs/libvpx/vp9/common/vp9_entropymode.c @@ -381,7 +381,6 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) { } if (cm->tx_mode == TX_MODE_SELECT) { - int j; unsigned int branch_ct_8x8p[TX_SIZES - 3][2]; unsigned int branch_ct_16x16p[TX_SIZES - 2][2]; unsigned int branch_ct_32x32p[TX_SIZES - 1][2]; diff --git a/libs/libvpx/vp9/common/vp9_entropymode.h b/libs/libvpx/vp9/common/vp9_entropymode.h index a756c8d0b8..e616aeac5c 100644 --- a/libs/libvpx/vp9/common/vp9_entropymode.h +++ b/libs/libvpx/vp9/common/vp9_entropymode.h @@ -24,7 +24,7 @@ extern "C" { #define TX_SIZE_CONTEXTS 2 -#define INTER_OFFSET(mode) ((mode)-NEARESTMV) +#define INTER_OFFSET(mode) ((mode) - NEARESTMV) struct VP9Common; diff --git a/libs/libvpx/vp9/common/vp9_idct.c b/libs/libvpx/vp9/common/vp9_idct.c index 69069042cc..71be0f310d 100644 --- a/libs/libvpx/vp9/common/vp9_idct.c +++ b/libs/libvpx/vp9/common/vp9_idct.c @@ -150,6 +150,7 @@ void vp9_idct8x8_add(const tran_low_t *input, uint8_t *dest, int stride, void vp9_idct16x16_add(const tran_low_t *input, uint8_t *dest, int stride, int eob) { + assert(((intptr_t)input) % 32 == 0); /* The calculation can be simplified if there are not many non-zero dct * coefficients. Use eobs to separate different cases. */ if (eob == 1) /* DC only DCT coefficient. */ @@ -164,6 +165,7 @@ void vp9_idct16x16_add(const tran_low_t *input, uint8_t *dest, int stride, void vp9_idct32x32_add(const tran_low_t *input, uint8_t *dest, int stride, int eob) { + assert(((intptr_t)input) % 32 == 0); if (eob == 1) vpx_idct32x32_1_add(input, dest, stride); else if (eob <= 34) diff --git a/libs/libvpx/vp9/common/vp9_loopfilter.c b/libs/libvpx/vp9/common/vp9_loopfilter.c index 95d6029f3b..1a9d45ae77 100644 --- a/libs/libvpx/vp9/common/vp9_loopfilter.c +++ b/libs/libvpx/vp9/common/vp9_loopfilter.c @@ -932,32 +932,32 @@ void vp9_setup_mask(VP9_COMMON *const cm, const int mi_row, const int mi_col, break; default: for (idx_32 = 0; idx_32 < 4; mip += offset_32[idx_32], ++idx_32) { - const int shift_y = shift_32_y[idx_32]; - const int shift_uv = shift_32_uv[idx_32]; + const int shift_y_32 = shift_32_y[idx_32]; + const int shift_uv_32 = shift_32_uv[idx_32]; const int mi_32_col_offset = ((idx_32 & 1) << 2); const int mi_32_row_offset = ((idx_32 >> 1) << 2); if (mi_32_col_offset >= max_cols || mi_32_row_offset >= max_rows) continue; switch (mip[0]->sb_type) { case BLOCK_32X32: - build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm); + build_masks(lfi_n, mip[0], shift_y_32, shift_uv_32, lfm); break; case BLOCK_32X16: - build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm); + build_masks(lfi_n, mip[0], shift_y_32, shift_uv_32, lfm); if (mi_32_row_offset + 2 >= max_rows) continue; mip2 = mip + mode_info_stride * 2; - build_masks(lfi_n, mip2[0], shift_y + 16, shift_uv + 4, lfm); + build_masks(lfi_n, mip2[0], shift_y_32 + 16, shift_uv_32 + 4, lfm); break; case BLOCK_16X32: - build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm); + build_masks(lfi_n, mip[0], shift_y_32, shift_uv_32, lfm); if (mi_32_col_offset + 2 >= max_cols) continue; mip2 = mip + 2; - build_masks(lfi_n, mip2[0], shift_y + 2, shift_uv + 1, lfm); + build_masks(lfi_n, mip2[0], shift_y_32 + 2, shift_uv_32 + 1, lfm); break; default: for (idx_16 = 0; idx_16 < 4; mip += offset_16[idx_16], ++idx_16) { - const int shift_y = shift_32_y[idx_32] + shift_16_y[idx_16]; - const int shift_uv = shift_32_uv[idx_32] + shift_16_uv[idx_16]; + const int shift_y_16 = shift_y_32 + shift_16_y[idx_16]; + const int shift_uv_16 = shift_uv_32 + shift_16_uv[idx_16]; const int mi_16_col_offset = mi_32_col_offset + ((idx_16 & 1) << 1); const int mi_16_row_offset = @@ -968,28 +968,26 @@ void vp9_setup_mask(VP9_COMMON *const cm, const int mi_row, const int mi_col, switch (mip[0]->sb_type) { case BLOCK_16X16: - build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm); + build_masks(lfi_n, mip[0], shift_y_16, shift_uv_16, lfm); break; case BLOCK_16X8: - build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm); + build_masks(lfi_n, mip[0], shift_y_16, shift_uv_16, lfm); if (mi_16_row_offset + 1 >= max_rows) continue; mip2 = mip + mode_info_stride; - build_y_mask(lfi_n, mip2[0], shift_y + 8, lfm); + build_y_mask(lfi_n, mip2[0], shift_y_16 + 8, lfm); break; case BLOCK_8X16: - build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm); + build_masks(lfi_n, mip[0], shift_y_16, shift_uv_16, lfm); if (mi_16_col_offset + 1 >= max_cols) continue; mip2 = mip + 1; - build_y_mask(lfi_n, mip2[0], shift_y + 1, lfm); + build_y_mask(lfi_n, mip2[0], shift_y_16 + 1, lfm); break; default: { - const int shift_y = - shift_32_y[idx_32] + shift_16_y[idx_16] + shift_8_y[0]; - build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm); + const int shift_y_8_0 = shift_y_16 + shift_8_y[0]; + build_masks(lfi_n, mip[0], shift_y_8_0, shift_uv_16, lfm); mip += offset[0]; for (idx_8 = 1; idx_8 < 4; mip += offset[idx_8], ++idx_8) { - const int shift_y = shift_32_y[idx_32] + - shift_16_y[idx_16] + shift_8_y[idx_8]; + const int shift_y_8 = shift_y_16 + shift_8_y[idx_8]; const int mi_8_col_offset = mi_16_col_offset + ((idx_8 & 1)); const int mi_8_row_offset = @@ -998,7 +996,7 @@ void vp9_setup_mask(VP9_COMMON *const cm, const int mi_row, const int mi_col, if (mi_8_col_offset >= max_cols || mi_8_row_offset >= max_rows) continue; - build_y_mask(lfi_n, mip[0], shift_y, lfm); + build_y_mask(lfi_n, mip[0], shift_y_8, lfm); } break; } @@ -1180,7 +1178,7 @@ void vp9_filter_block_plane_non420(VP9_COMMON *cm, } // Disable filtering on the leftmost column - border_mask = ~(mi_col == 0 ? 1 : 0); + border_mask = ~(mi_col == 0 ? 1u : 0u); #if CONFIG_VP9_HIGHBITDEPTH if (cm->use_highbitdepth) { highbd_filter_selectively_vert( diff --git a/libs/libvpx/vp9/common/vp9_mfqe.c b/libs/libvpx/vp9/common/vp9_mfqe.c index e76d771b8d..2530f4b053 100644 --- a/libs/libvpx/vp9/common/vp9_mfqe.c +++ b/libs/libvpx/vp9/common/vp9_mfqe.c @@ -119,10 +119,10 @@ static void copy_mem64x64(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride) { copy_mem32x32(src, src_stride, dst, dst_stride); copy_mem32x32(src + 32, src_stride, dst + 32, dst_stride); - copy_mem32x32(src + src_stride * 32, src_stride, dst + src_stride * 32, + copy_mem32x32(src + src_stride * 32, src_stride, dst + dst_stride * 32, dst_stride); copy_mem32x32(src + src_stride * 32 + 32, src_stride, - dst + src_stride * 32 + 32, dst_stride); + dst + dst_stride * 32 + 32, dst_stride); } static void copy_block(const uint8_t *y, const uint8_t *u, const uint8_t *v, @@ -207,25 +207,38 @@ static int mfqe_decision(MODE_INFO *mi, BLOCK_SIZE cur_bs) { // Process each partiton in a super block, recursively. static void mfqe_partition(VP9_COMMON *cm, MODE_INFO *mi, BLOCK_SIZE bs, - const uint8_t *y, const uint8_t *u, const uint8_t *v, - int y_stride, int uv_stride, uint8_t *yd, - uint8_t *ud, uint8_t *vd, int yd_stride, - int uvd_stride) { + int mi_row, int mi_col, const uint8_t *y, + const uint8_t *u, const uint8_t *v, int y_stride, + int uv_stride, uint8_t *yd, uint8_t *ud, uint8_t *vd, + int yd_stride, int uvd_stride) { int mi_offset, y_offset, uv_offset; + const int b_width = num_8x8_blocks_wide_lookup[bs]; + const int b_height = num_8x8_blocks_high_lookup[bs]; const BLOCK_SIZE cur_bs = mi->sb_type; const int qdiff = cm->base_qindex - cm->postproc_state.last_base_qindex; const int bsl = b_width_log2_lookup[bs]; - PARTITION_TYPE partition = partition_lookup[bsl][cur_bs]; - const BLOCK_SIZE subsize = get_subsize(bs, partition); + PARTITION_TYPE partition; + BLOCK_SIZE subsize; + BLOCK_SIZE mfqe_bs, bs_tmp; - if (cur_bs < BLOCK_8X8) { - // If there are blocks smaller than 8x8, it must be on the boundary. + // Return early if the block is partially outside the frame boundaries. + // This avoids reading uninitialized/invalid block sizes outside the frame. + // Return also for blocks smaller than 8x8, and note 4x4 subblocks can occur + // inside the image (not only on boundary). + // The return here is safe as the pixels are pre-copied by vpx_yv12_copy_frame + // in vp9_mfqe() before entering the superblock loop. + if (mi_row + b_height > cm->mi_rows || mi_col + b_width > cm->mi_cols || + cur_bs < BLOCK_8X8) { return; } + // No MFQE on blocks smaller than 16x16 if (bs == BLOCK_16X16) { partition = PARTITION_NONE; + } else { + partition = partition_lookup[bsl][cur_bs]; } + subsize = get_subsize(bs, partition); if (bs == BLOCK_64X64) { mi_offset = 4; y_offset = 32; @@ -236,7 +249,6 @@ static void mfqe_partition(VP9_COMMON *cm, MODE_INFO *mi, BLOCK_SIZE bs, uv_offset = 8; } switch (partition) { - BLOCK_SIZE mfqe_bs, bs_tmp; case PARTITION_HORZ: if (bs == BLOCK_64X64) { mfqe_bs = BLOCK_64X32; @@ -317,17 +329,20 @@ static void mfqe_partition(VP9_COMMON *cm, MODE_INFO *mi, BLOCK_SIZE bs, case PARTITION_SPLIT: // Recursion on four square partitions, e.g. if bs is 64X64, // then look into four 32X32 blocks in it. - mfqe_partition(cm, mi, subsize, y, u, v, y_stride, uv_stride, yd, ud, vd, + mfqe_partition(cm, mi, subsize, mi_row, mi_col, y, u, v, y_stride, + uv_stride, yd, ud, vd, yd_stride, uvd_stride); + mfqe_partition(cm, mi + mi_offset, subsize, mi_row, mi_col + mi_offset, + y + y_offset, u + uv_offset, v + uv_offset, y_stride, + uv_stride, yd + y_offset, ud + uv_offset, vd + uv_offset, yd_stride, uvd_stride); - mfqe_partition(cm, mi + mi_offset, subsize, y + y_offset, u + uv_offset, - v + uv_offset, y_stride, uv_stride, yd + y_offset, - ud + uv_offset, vd + uv_offset, yd_stride, uvd_stride); mfqe_partition(cm, mi + mi_offset * cm->mi_stride, subsize, - y + y_offset * y_stride, u + uv_offset * uv_stride, - v + uv_offset * uv_stride, y_stride, uv_stride, - yd + y_offset * yd_stride, ud + uv_offset * uvd_stride, - vd + uv_offset * uvd_stride, yd_stride, uvd_stride); + mi_row + mi_offset, mi_col, y + y_offset * y_stride, + u + uv_offset * uv_stride, v + uv_offset * uv_stride, + y_stride, uv_stride, yd + y_offset * yd_stride, + ud + uv_offset * uvd_stride, vd + uv_offset * uvd_stride, + yd_stride, uvd_stride); mfqe_partition(cm, mi + mi_offset * cm->mi_stride + mi_offset, subsize, + mi_row + mi_offset, mi_col + mi_offset, y + y_offset * y_stride + y_offset, u + uv_offset * uv_stride + uv_offset, v + uv_offset * uv_stride + uv_offset, y_stride, uv_stride, @@ -346,6 +361,7 @@ void vp9_mfqe(VP9_COMMON *cm) { const YV12_BUFFER_CONFIG *show = cm->frame_to_show; // Last decoded frame and will store the MFQE result. YV12_BUFFER_CONFIG *dest = &cm->post_proc_buffer; + vpx_yv12_copy_frame(show, dest); // Loop through each super block. for (mi_row = 0; mi_row < cm->mi_rows; mi_row += MI_BLOCK_SIZE) { for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MI_BLOCK_SIZE) { @@ -376,8 +392,8 @@ void vp9_mfqe(VP9_COMMON *cm) { } else { mi = mi_local; } - mfqe_partition(cm, mi, BLOCK_64X64, y, u, v, y_stride, uv_stride, yd, ud, - vd, yd_stride, uvd_stride); + mfqe_partition(cm, mi, BLOCK_64X64, mi_row, mi_col, y, u, v, y_stride, + uv_stride, yd, ud, vd, yd_stride, uvd_stride); } } } diff --git a/libs/libvpx/vp9/common/vp9_onyxc_int.h b/libs/libvpx/vp9/common/vp9_onyxc_int.h index fb2ae018eb..4c8fcf6989 100644 --- a/libs/libvpx/vp9/common/vp9_onyxc_int.h +++ b/libs/libvpx/vp9/common/vp9_onyxc_int.h @@ -13,7 +13,6 @@ #include "./vpx_config.h" #include "vpx/internal/vpx_codec_internal.h" -#include "vpx_util/vpx_thread.h" #include "./vp9_rtcd.h" #include "vp9/common/vp9_alloccommon.h" #include "vp9/common/vp9_loopfilter.h" @@ -349,8 +348,6 @@ static INLINE int get_free_fb(VP9_COMMON *cm) { static INLINE void ref_cnt_fb(RefCntBuffer *bufs, int *idx, int new_idx) { const int ref_index = *idx; - if (!bufs) return; - if (ref_index >= 0 && bufs[ref_index].ref_count > 0) bufs[ref_index].ref_count--; diff --git a/libs/libvpx/vp9/common/vp9_postproc.c b/libs/libvpx/vp9/common/vp9_postproc.c index 96519f0051..e6ac148fa2 100644 --- a/libs/libvpx/vp9/common/vp9_postproc.c +++ b/libs/libvpx/vp9/common/vp9_postproc.c @@ -119,8 +119,8 @@ void vp9_highbd_mbpost_proc_across_ip_c(uint16_t *src, int pitch, int rows, uint16_t d[16]; for (r = 0; r < rows; r++) { - int sumsq = 0; - int sum = 0; + int64_t sumsq = 0; + int64_t sum = 0; for (i = -8; i <= 6; i++) { sumsq += s[i] * s[i]; @@ -138,7 +138,7 @@ void vp9_highbd_mbpost_proc_across_ip_c(uint16_t *src, int pitch, int rows, d[c & 15] = s[c]; if (sumsq * 15 - sum * sum < flimit) { - d[c & 15] = (8 + sum + s[c]) >> 4; + d[c & 15] = (uint16_t)((8 + sum + s[c]) >> 4); } s[c - 8] = d[(c - 8) & 15]; @@ -157,8 +157,8 @@ void vp9_highbd_mbpost_proc_down_c(uint16_t *dst, int pitch, int rows, int cols, for (c = 0; c < cols; c++) { uint16_t *s = &dst[c]; - int sumsq = 0; - int sum = 0; + int64_t sumsq = 0; + int64_t sum = 0; uint16_t d[16]; const int16_t *rv2 = rv3 + ((c * 17) & 127); @@ -173,7 +173,7 @@ void vp9_highbd_mbpost_proc_down_c(uint16_t *dst, int pitch, int rows, int cols, d[r & 15] = s[0]; if (sumsq * 15 - sum * sum < flimit) { - d[r & 15] = (rv2[r & 127] + sum + s[0]) >> 4; + d[r & 15] = (uint16_t)((rv2[r & 127] + sum + s[0]) >> 4); } s[-8 * pitch] = d[(r - 8) & 15]; @@ -254,8 +254,7 @@ void vp9_deblock(struct VP9Common *cm, const YV12_BUFFER_CONFIG *src, #endif // CONFIG_VP9_HIGHBITDEPTH int mbr; const int mb_rows = cm->mb_rows; - const int mb_cols = cm->mb_cols; - memset(limits, (unsigned char)ppl, 16 * mb_cols); + memset(limits, (unsigned char)ppl, cm->postproc_state.limits_size); for (mbr = 0; mbr < mb_rows; mbr++) { vpx_post_proc_down_and_across_mb_row( @@ -278,6 +277,12 @@ void vp9_deblock(struct VP9Common *cm, const YV12_BUFFER_CONFIG *src, void vp9_denoise(struct VP9Common *cm, const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst, int q, uint8_t *limits) { + if (src->uv_width < 8) { + // This function is only called by the encoder to perform an in place + // modification of 'src'. + assert(src == dst); + return; + } vp9_deblock(cm, src, dst, q, limits); } @@ -295,12 +300,26 @@ static void swap_mi_and_prev_mi(VP9_COMMON *cm) { int vp9_post_proc_frame(struct VP9Common *cm, YV12_BUFFER_CONFIG *dest, vp9_ppflags_t *ppflags, int unscaled_width) { const int q = VPXMIN(105, cm->lf.filter_level * 2); - const int flags = ppflags->post_proc_flag; YV12_BUFFER_CONFIG *const ppbuf = &cm->post_proc_buffer; struct postproc_state *const ppstate = &cm->postproc_state; + int generated_noise_size = unscaled_width + 256; + int pp_width = cm->width; + int pp_height = cm->height; if (!cm->frame_to_show) return -1; + int flags = ppflags->post_proc_flag; +#if CONFIG_VP9_HIGHBITDEPTH + if (cm->use_highbitdepth) { + // VP9D_ADDNOISE is an 8-bit only implementation. See issue 499602810. + flags &= ~VP9D_ADDNOISE; + } +#endif + if (cm->frame_to_show->uv_width < 8) { + // vp9_deblock() has a minimum width of 8. + flags &= ~VP9D_DEBLOCK; + flags &= ~VP9D_DEMACROBLOCK; + } if (!flags) { *dest = *cm->frame_to_show; return 0; @@ -314,66 +333,82 @@ int vp9_post_proc_frame(struct VP9Common *cm, YV12_BUFFER_CONFIG *dest, ppstate->last_frame_valid = 1; } - if ((flags & VP9D_MFQE) && ppstate->prev_mip == NULL) { - ppstate->prev_mip = vpx_calloc(cm->mi_alloc_size, sizeof(*cm->mip)); - if (!ppstate->prev_mip) { - return 1; + if ((flags & VP9D_MFQE)) { + if (ppstate->prev_mip == NULL || + cm->mi_alloc_size > ppstate->prev_mip_size) { + vpx_free(ppstate->prev_mip); + CHECK_MEM_ERROR(&cm->error, ppstate->prev_mip, + vpx_calloc(cm->mi_alloc_size, sizeof(*cm->mip))); + ppstate->prev_mip_size = cm->mi_alloc_size; } ppstate->prev_mi = ppstate->prev_mip + cm->mi_stride + 1; } - // Allocate post_proc_buffer_int if needed. - if ((flags & VP9D_MFQE) && !cm->post_proc_buffer_int.buffer_alloc) { - if ((flags & VP9D_DEMACROBLOCK) || (flags & VP9D_DEBLOCK)) { - const int width = ALIGN_POWER_OF_TWO(cm->width, 4); - const int height = ALIGN_POWER_OF_TWO(cm->height, 4); + // Allocate/resize post_proc_buffer_int if needed. + if ((flags & VP9D_MFQE) && + ((flags & VP9D_DEMACROBLOCK) || (flags & VP9D_DEBLOCK))) { + // Keep postproc and noise buffer sizes in sync as the dimensions from the + // buffers are used interchangeably. + pp_width = ALIGN_POWER_OF_TWO(cm->width, 4); + pp_height = ALIGN_POWER_OF_TWO(cm->height, 4); + generated_noise_size = pp_width + 256; - if (vpx_alloc_frame_buffer(&cm->post_proc_buffer_int, width, height, - cm->subsampling_x, cm->subsampling_y, + if (vpx_alloc_frame_buffer(&cm->post_proc_buffer_int, pp_width, pp_height, + cm->subsampling_x, cm->subsampling_y, #if CONFIG_VP9_HIGHBITDEPTH - cm->use_highbitdepth, + cm->use_highbitdepth, #endif // CONFIG_VP9_HIGHBITDEPTH - VP9_ENC_BORDER_IN_PIXELS, - cm->byte_alignment) < 0) { - vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, - "Failed to allocate MFQE framebuffer"); - } - - // Ensure that postproc is set to all 0s so that post proc - // doesn't pull random data in from edge. - memset(cm->post_proc_buffer_int.buffer_alloc, 128, - cm->post_proc_buffer.frame_size); + VP9_ENC_BORDER_IN_PIXELS, + cm->byte_alignment) < 0) { + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, + "Failed to allocate MFQE framebuffer"); } + + // Ensure that postproc is set to flat image so that post proc + // doesn't pull random data in from edge. + memset(cm->post_proc_buffer_int.buffer_alloc, 128, + cm->post_proc_buffer_int.frame_size); } - if (vpx_realloc_frame_buffer(&cm->post_proc_buffer, cm->width, cm->height, + if (vpx_realloc_frame_buffer(&cm->post_proc_buffer, pp_width, pp_height, cm->subsampling_x, cm->subsampling_y, #if CONFIG_VP9_HIGHBITDEPTH cm->use_highbitdepth, #endif VP9_DEC_BORDER_IN_PIXELS, cm->byte_alignment, - NULL, NULL, NULL) < 0) + NULL, NULL, NULL) < 0) { vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, "Failed to allocate post-processing buffer"); + } + memset(cm->post_proc_buffer.buffer_alloc, 128, + cm->post_proc_buffer.frame_size); if (flags & (VP9D_DEMACROBLOCK | VP9D_DEBLOCK)) { - if (!cm->postproc_state.limits) { + const int limits_size = ALIGN_POWER_OF_TWO(unscaled_width, 4); + if (!cm->postproc_state.limits || + cm->postproc_state.limits_size < limits_size) { + if (cm->postproc_state.limits) vpx_free(cm->postproc_state.limits); cm->postproc_state.limits = - vpx_calloc(unscaled_width, sizeof(*cm->postproc_state.limits)); + vpx_calloc(limits_size, sizeof(*cm->postproc_state.limits)); if (!cm->postproc_state.limits) return 1; + cm->postproc_state.limits_size = limits_size; } } if (flags & VP9D_ADDNOISE) { - if (!cm->postproc_state.generated_noise) { + if (!cm->postproc_state.generated_noise || + cm->postproc_state.generated_noise_size < generated_noise_size) { + vpx_free(cm->postproc_state.generated_noise); cm->postproc_state.generated_noise = vpx_calloc( - cm->width + 256, sizeof(*cm->postproc_state.generated_noise)); + generated_noise_size, sizeof(*cm->postproc_state.generated_noise)); if (!cm->postproc_state.generated_noise) return 1; + cm->postproc_state.generated_noise_size = generated_noise_size; } } if ((flags & VP9D_MFQE) && cm->current_video_frame >= 2 && - ppstate->last_frame_valid && cm->bit_depth == 8 && + ppstate->last_frame_valid && cm->width == cm->prev_frame->buf.y_width && + cm->height == cm->prev_frame->buf.y_height && cm->bit_depth == 8 && ppstate->last_base_qindex <= last_q_thresh && cm->base_qindex - ppstate->last_base_qindex >= q_diff_thresh) { vp9_mfqe(cm); @@ -411,14 +446,14 @@ int vp9_post_proc_frame(struct VP9Common *cm, YV12_BUFFER_CONFIG *dest, double sigma; vpx_clear_system_state(); sigma = noise_level + .5 + .6 * q / 63.0; - ppstate->clamp = - vpx_setup_noise(sigma, ppstate->generated_noise, cm->width + 256); + ppstate->clamp = vpx_setup_noise(sigma, ppstate->generated_noise, + generated_noise_size); ppstate->last_q = q; ppstate->last_noise = noise_level; } vpx_plane_add_noise(ppbuf->y_buffer, ppstate->generated_noise, - ppstate->clamp, ppstate->clamp, ppbuf->y_width, - ppbuf->y_height, ppbuf->y_stride); + ppstate->clamp, ppstate->clamp, ppbuf->y_crop_width, + ppbuf->y_crop_height, ppbuf->y_stride); } *dest = *ppbuf; diff --git a/libs/libvpx/vp9/common/vp9_postproc.h b/libs/libvpx/vp9/common/vp9_postproc.h index bbe3aed835..7b460414fc 100644 --- a/libs/libvpx/vp9/common/vp9_postproc.h +++ b/libs/libvpx/vp9/common/vp9_postproc.h @@ -30,7 +30,10 @@ struct postproc_state { MODE_INFO *prev_mi; int clamp; uint8_t *limits; + int limits_size; + int prev_mip_size; int8_t *generated_noise; + int generated_noise_size; }; struct VP9Common; diff --git a/libs/libvpx/vp9/common/vp9_reconinter.c b/libs/libvpx/vp9/common/vp9_reconinter.c index ff59ff5042..0a60b853d8 100644 --- a/libs/libvpx/vp9/common/vp9_reconinter.c +++ b/libs/libvpx/vp9/common/vp9_reconinter.c @@ -13,12 +13,13 @@ #include "./vpx_scale_rtcd.h" #include "./vpx_config.h" -#include "vpx/vpx_integer.h" - #include "vp9/common/vp9_blockd.h" #include "vp9/common/vp9_reconinter.h" #include "vp9/common/vp9_reconintra.h" +#include "vpx/vpx_integer.h" +#include "vpx_scale/yv12config.h" + #if CONFIG_VP9_HIGHBITDEPTH void vp9_highbd_build_inter_predictor( const uint16_t *src, int src_stride, uint16_t *dst, int dst_stride, @@ -158,18 +159,19 @@ static void build_inter_predictors(MACROBLOCKD *xd, int plane, int block, // Co-ordinate of containing block to pixel precision. const int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)); const int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)); + const YV12_BUFFER_CONFIG *ref_buf = xd->block_refs[ref]->buf; + uint8_t *buf_array[] = { ref_buf->y_buffer, ref_buf->u_buffer, + ref_buf->v_buffer }; + const int stride_array[] = { ref_buf->y_stride, ref_buf->uv_stride, + ref_buf->uv_stride }; #if 0 // CONFIG_BETTER_HW_COMPATIBILITY assert(xd->mi[0]->sb_type != BLOCK_4X8 && xd->mi[0]->sb_type != BLOCK_8X4); assert(mv_q4.row == mv.row * (1 << (1 - pd->subsampling_y)) && mv_q4.col == mv.col * (1 << (1 - pd->subsampling_x))); #endif - if (plane == 0) - pre_buf->buf = xd->block_refs[ref]->buf->y_buffer; - else if (plane == 1) - pre_buf->buf = xd->block_refs[ref]->buf->u_buffer; - else - pre_buf->buf = xd->block_refs[ref]->buf->v_buffer; + pre_buf->buf = buf_array[plane]; + pre_buf->stride = stride_array[plane]; pre_buf->buf += scaled_buffer_offset(x_start + x, y_start + y, pre_buf->stride, sf); diff --git a/libs/libvpx/vp9/common/vp9_rtcd.c b/libs/libvpx/vp9/common/vp9_rtcd.c index 37762ca15a..1a93b97e56 100644 --- a/libs/libvpx/vp9/common/vp9_rtcd.c +++ b/libs/libvpx/vp9/common/vp9_rtcd.c @@ -12,4 +12,4 @@ #include "./vp9_rtcd.h" #include "vpx_ports/vpx_once.h" -void vp9_rtcd() { once(setup_rtcd_internal); } +void vp9_rtcd(void) { once(setup_rtcd_internal); } diff --git a/libs/libvpx/vp9/common/vp9_rtcd_defs.pl b/libs/libvpx/vp9/common/vp9_rtcd_defs.pl index 4da0b6675b..c78b3dee10 100644 --- a/libs/libvpx/vp9/common/vp9_rtcd_defs.pl +++ b/libs/libvpx/vp9/common/vp9_rtcd_defs.pl @@ -18,12 +18,17 @@ print <> 1, where val1 and val2 are at most N. +// The result of this expression is also at most N. static INLINE int get_coef_context(const int16_t *neighbors, const uint8_t *token_cache, int c) { return (1 + token_cache[neighbors[MAX_NEIGHBORS * c + 0]] + @@ -39,8 +44,8 @@ static INLINE int get_coef_context(const int16_t *neighbors, 1; } -static INLINE const scan_order *get_scan(const MACROBLOCKD *xd, TX_SIZE tx_size, - PLANE_TYPE type, int block_idx) { +static INLINE const ScanOrder *get_scan(const MACROBLOCKD *xd, TX_SIZE tx_size, + PLANE_TYPE type, int block_idx) { const MODE_INFO *const mi = xd->mi[0]; if (is_inter_block(mi) || type != PLANE_TYPE_Y || xd->lossless) { diff --git a/libs/libvpx/vp9/common/vp9_thread_common.c b/libs/libvpx/vp9/common/vp9_thread_common.c index b3d50162b2..24adbcbff0 100644 --- a/libs/libvpx/vp9/common/vp9_thread_common.c +++ b/libs/libvpx/vp9/common/vp9_thread_common.c @@ -13,6 +13,7 @@ #include "./vpx_config.h" #include "vpx_dsp/vpx_dsp_common.h" #include "vpx_mem/vpx_mem.h" +#include "vpx_util/vpx_pthread.h" #include "vp9/common/vp9_entropymode.h" #include "vp9/common/vp9_thread_common.h" #include "vp9/common/vp9_reconinter.h" @@ -283,7 +284,7 @@ void vp9_loop_filter_alloc(VP9LfSync *lf_sync, VP9_COMMON *cm, int rows, { int i; - CHECK_MEM_ERROR(cm, lf_sync->mutex, + CHECK_MEM_ERROR(&cm->error, lf_sync->mutex, vpx_malloc(sizeof(*lf_sync->mutex) * rows)); if (lf_sync->mutex) { for (i = 0; i < rows; ++i) { @@ -291,7 +292,7 @@ void vp9_loop_filter_alloc(VP9LfSync *lf_sync, VP9_COMMON *cm, int rows, } } - CHECK_MEM_ERROR(cm, lf_sync->cond, + CHECK_MEM_ERROR(&cm->error, lf_sync->cond, vpx_malloc(sizeof(*lf_sync->cond) * rows)); if (lf_sync->cond) { for (i = 0; i < rows; ++i) { @@ -299,23 +300,21 @@ void vp9_loop_filter_alloc(VP9LfSync *lf_sync, VP9_COMMON *cm, int rows, } } - CHECK_MEM_ERROR(cm, lf_sync->lf_mutex, + CHECK_MEM_ERROR(&cm->error, lf_sync->lf_mutex, vpx_malloc(sizeof(*lf_sync->lf_mutex))); pthread_mutex_init(lf_sync->lf_mutex, NULL); - CHECK_MEM_ERROR(cm, lf_sync->recon_done_mutex, + CHECK_MEM_ERROR(&cm->error, lf_sync->recon_done_mutex, vpx_malloc(sizeof(*lf_sync->recon_done_mutex) * rows)); if (lf_sync->recon_done_mutex) { - int i; for (i = 0; i < rows; ++i) { pthread_mutex_init(&lf_sync->recon_done_mutex[i], NULL); } } - CHECK_MEM_ERROR(cm, lf_sync->recon_done_cond, + CHECK_MEM_ERROR(&cm->error, lf_sync->recon_done_cond, vpx_malloc(sizeof(*lf_sync->recon_done_cond) * rows)); if (lf_sync->recon_done_cond) { - int i; for (i = 0; i < rows; ++i) { pthread_cond_init(&lf_sync->recon_done_cond[i], NULL); } @@ -323,15 +322,15 @@ void vp9_loop_filter_alloc(VP9LfSync *lf_sync, VP9_COMMON *cm, int rows, } #endif // CONFIG_MULTITHREAD - CHECK_MEM_ERROR(cm, lf_sync->lfdata, + CHECK_MEM_ERROR(&cm->error, lf_sync->lfdata, vpx_malloc(num_workers * sizeof(*lf_sync->lfdata))); lf_sync->num_workers = num_workers; lf_sync->num_active_workers = lf_sync->num_workers; - CHECK_MEM_ERROR(cm, lf_sync->cur_sb_col, + CHECK_MEM_ERROR(&cm->error, lf_sync->cur_sb_col, vpx_malloc(sizeof(*lf_sync->cur_sb_col) * rows)); - CHECK_MEM_ERROR(cm, lf_sync->num_tiles_done, + CHECK_MEM_ERROR(&cm->error, lf_sync->num_tiles_done, vpx_malloc(sizeof(*lf_sync->num_tiles_done) * mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2)); @@ -390,10 +389,10 @@ void vp9_loop_filter_dealloc(VP9LfSync *lf_sync) { static int get_next_row(VP9_COMMON *cm, VP9LfSync *lf_sync) { int return_val = -1; - int cur_row; const int max_rows = cm->mi_rows; #if CONFIG_MULTITHREAD + int cur_row; const int tile_cols = 1 << cm->log2_tile_cols; pthread_mutex_lock(lf_sync->lf_mutex); @@ -430,14 +429,8 @@ static int get_next_row(VP9_COMMON *cm, VP9LfSync *lf_sync) { #else (void)lf_sync; if (cm->lf_row < max_rows) { - cur_row = cm->lf_row >> MI_BLOCK_SIZE_LOG2; return_val = cm->lf_row; cm->lf_row += MI_BLOCK_SIZE; - if (cm->lf_row < max_rows) { - /* If this is not the last row, make sure the next row is also decoded. - * This is because the intra predict has to happen before loop filter */ - cur_row += 1; - } } #endif // CONFIG_MULTITHREAD diff --git a/libs/libvpx/vp9/common/vp9_thread_common.h b/libs/libvpx/vp9/common/vp9_thread_common.h index 5df0117f12..96c705d0d5 100644 --- a/libs/libvpx/vp9/common/vp9_thread_common.h +++ b/libs/libvpx/vp9/common/vp9_thread_common.h @@ -12,6 +12,7 @@ #define VPX_VP9_COMMON_VP9_THREAD_COMMON_H_ #include "./vpx_config.h" #include "vp9/common/vp9_loopfilter.h" +#include "vpx_util/vpx_pthread.h" #include "vpx_util/vpx_thread.h" #ifdef __cplusplus diff --git a/libs/libvpx/vp9/decoder/vp9_decodeframe.c b/libs/libvpx/vp9/decoder/vp9_decodeframe.c index 2a27e6fdb3..9008e54e0e 100644 --- a/libs/libvpx/vp9/decoder/vp9_decodeframe.c +++ b/libs/libvpx/vp9/decoder/vp9_decodeframe.c @@ -22,6 +22,7 @@ #include "vpx_ports/mem.h" #include "vpx_ports/mem_ops.h" #include "vpx_scale/vpx_scale.h" +#include "vpx_util/vpx_pthread.h" #include "vpx_util/vpx_thread.h" #if CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG #include "vpx_util/vpx_debug_util.h" @@ -67,6 +68,7 @@ static int decode_unsigned_max(struct vpx_read_bit_buffer *rb, int max) { static TX_MODE read_tx_mode(vpx_reader *r) { TX_MODE tx_mode = vpx_read_literal(r, 2); if (tx_mode == ALLOW_32X32) tx_mode += vpx_read_bit(r); + assert(tx_mode < TX_MODES); return tx_mode; } @@ -323,9 +325,9 @@ static void predict_and_reconstruct_intra_block(TileWorkerData *twd, if (!mi->skip) { const TX_TYPE tx_type = (plane || xd->lossless) ? DCT_DCT : intra_mode_to_tx_type_lookup[mode]; - const scan_order *sc = (plane || xd->lossless) - ? &vp9_default_scan_orders[tx_size] - : &vp9_scan_orders[tx_size][tx_type]; + const ScanOrder *sc = (plane || xd->lossless) + ? &vp9_default_scan_orders[tx_size] + : &vp9_scan_orders[tx_size][tx_type]; const int eob = vp9_decode_block_tokens(twd, plane, sc, col, row, tx_size, mi->segment_id); if (eob > 0) { @@ -348,9 +350,9 @@ static void parse_intra_block_row_mt(TileWorkerData *twd, MODE_INFO *const mi, struct macroblockd_plane *const pd = &xd->plane[plane]; const TX_TYPE tx_type = (plane || xd->lossless) ? DCT_DCT : intra_mode_to_tx_type_lookup[mode]; - const scan_order *sc = (plane || xd->lossless) - ? &vp9_default_scan_orders[tx_size] - : &vp9_scan_orders[tx_size][tx_type]; + const ScanOrder *sc = (plane || xd->lossless) + ? &vp9_default_scan_orders[tx_size] + : &vp9_scan_orders[tx_size][tx_type]; *pd->eob = vp9_decode_block_tokens(twd, plane, sc, col, row, tx_size, mi->segment_id); /* Keep the alignment to 16 */ @@ -393,7 +395,7 @@ static int reconstruct_inter_block(TileWorkerData *twd, MODE_INFO *const mi, int mi_row, int mi_col) { MACROBLOCKD *const xd = &twd->xd; struct macroblockd_plane *const pd = &xd->plane[plane]; - const scan_order *sc = &vp9_default_scan_orders[tx_size]; + const ScanOrder *sc = &vp9_default_scan_orders[tx_size]; const int eob = vp9_decode_block_tokens(twd, plane, sc, col, row, tx_size, mi->segment_id); uint8_t *dst = &pd->dst.buf[4 * row * pd->dst.stride + 4 * col]; @@ -423,7 +425,7 @@ static int parse_inter_block_row_mt(TileWorkerData *twd, MODE_INFO *const mi, TX_SIZE tx_size) { MACROBLOCKD *const xd = &twd->xd; struct macroblockd_plane *const pd = &xd->plane[plane]; - const scan_order *sc = &vp9_default_scan_orders[tx_size]; + const ScanOrder *sc = &vp9_default_scan_orders[tx_size]; const int eob = vp9_decode_block_tokens(twd, plane, sc, col, row, tx_size, mi->segment_id); @@ -1469,7 +1471,7 @@ static void resize_mv_buffer(VP9_COMMON *cm) { vpx_free(cm->cur_frame->mvs); cm->cur_frame->mi_rows = cm->mi_rows; cm->cur_frame->mi_cols = cm->mi_cols; - CHECK_MEM_ERROR(cm, cm->cur_frame->mvs, + CHECK_MEM_ERROR(&cm->error, cm->cur_frame->mvs, (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols, sizeof(*cm->cur_frame->mvs))); } @@ -1558,16 +1560,13 @@ static void setup_frame_size_with_refs(VP9_COMMON *cm, BufferPool *const pool = cm->buffer_pool; for (i = 0; i < REFS_PER_FRAME; ++i) { if (vpx_rb_read_bit(rb)) { - if (cm->frame_refs[i].idx != INVALID_IDX) { - YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf; - width = buf->y_crop_width; - height = buf->y_crop_height; - found = 1; - break; - } else { - vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, - "Failed to decode frame size"); - } + assert(cm->frame_refs[i].idx >= 0 && + cm->frame_refs[i].idx < FRAME_BUFFERS); + YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf; + width = buf->y_crop_width; + height = buf->y_crop_height; + found = 1; + break; } } @@ -1581,18 +1580,18 @@ static void setup_frame_size_with_refs(VP9_COMMON *cm, // has valid dimensions. for (i = 0; i < REFS_PER_FRAME; ++i) { RefBuffer *const ref_frame = &cm->frame_refs[i]; + assert(ref_frame->idx >= 0 && ref_frame->idx < FRAME_BUFFERS); has_valid_ref_frame |= - (ref_frame->idx != INVALID_IDX && - valid_ref_frame_size(ref_frame->buf->y_crop_width, - ref_frame->buf->y_crop_height, width, height)); + valid_ref_frame_size(ref_frame->buf->y_crop_width, + ref_frame->buf->y_crop_height, width, height); } if (!has_valid_ref_frame) vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Referenced frame has invalid size"); for (i = 0; i < REFS_PER_FRAME; ++i) { RefBuffer *const ref_frame = &cm->frame_refs[i]; - if (ref_frame->idx == INVALID_IDX || - !valid_ref_frame_img_fmt(ref_frame->buf->bit_depth, + assert(ref_frame->idx >= 0 && ref_frame->idx < FRAME_BUFFERS); + if (!valid_ref_frame_img_fmt(ref_frame->buf->bit_depth, ref_frame->buf->subsampling_x, ref_frame->buf->subsampling_y, cm->bit_depth, cm->subsampling_x, cm->subsampling_y)) @@ -1776,7 +1775,8 @@ static void vp9_jobq_alloc(VP9Decoder *pbi) { if (jobq_size > row_mt_worker_data->jobq_size) { vpx_free(row_mt_worker_data->jobq_buf); - CHECK_MEM_ERROR(cm, row_mt_worker_data->jobq_buf, vpx_calloc(1, jobq_size)); + CHECK_MEM_ERROR(&cm->error, row_mt_worker_data->jobq_buf, + vpx_calloc(1, jobq_size)); vp9_jobq_init(&row_mt_worker_data->jobq, row_mt_worker_data->jobq_buf, jobq_size); row_mt_worker_data->jobq_size = jobq_size; @@ -1801,7 +1801,8 @@ static void recon_tile_row(TileWorkerData *tile_data, VP9Decoder *pbi, for (mi_col = mi_col_start; mi_col < mi_col_end; mi_col += MI_BLOCK_SIZE) { const int c = mi_col >> MI_BLOCK_SIZE_LOG2; int plane; - const int sb_num = (cur_sb_row * (aligned_cols >> MI_BLOCK_SIZE_LOG2) + c); + const size_t sb_num = + (cur_sb_row * (aligned_cols >> MI_BLOCK_SIZE_LOG2) + c); // Top Dependency if (cur_sb_row) { @@ -1876,7 +1877,7 @@ static void parse_tile_row(TileWorkerData *tile_data, VP9Decoder *pbi, const int r = mi_row >> MI_BLOCK_SIZE_LOG2; const int c = mi_col >> MI_BLOCK_SIZE_LOG2; int plane; - const int sb_num = (r * (aligned_cols >> MI_BLOCK_SIZE_LOG2) + c); + const size_t sb_num = (r * (aligned_cols >> MI_BLOCK_SIZE_LOG2) + c); for (plane = 0; plane < MAX_MB_PLANE; ++plane) { tile_data->xd.plane[plane].eob = row_mt_worker_data->eob[plane] + (sb_num << EOBS_PER_SB_LOG2); @@ -1923,7 +1924,7 @@ static int row_decode_worker_hook(void *arg1, void *arg2) { const int is_last_row = sb_rows - 1 == cur_sb_row; int mi_col_start, mi_col_end; if (!tile_data_recon) - CHECK_MEM_ERROR(cm, tile_data_recon, + CHECK_MEM_ERROR(&cm->error, tile_data_recon, vpx_memalign(32, sizeof(TileWorkerData))); tile_data_recon->xd = pbi->mb; @@ -2025,7 +2026,7 @@ static const uint8_t *decode_tiles(VP9Decoder *pbi, const uint8_t *data, if (cm->lf.filter_level && !cm->skip_loop_filter && pbi->lf_worker.data1 == NULL) { - CHECK_MEM_ERROR(cm, pbi->lf_worker.data1, + CHECK_MEM_ERROR(&cm->error, pbi->lf_worker.data1, vpx_memalign(32, sizeof(LFWorkerData))); pbi->lf_worker.hook = vp9_loop_filter_worker; if (pbi->max_threads > 1 && !winterface->reset(&pbi->lf_worker)) { @@ -2192,8 +2193,6 @@ static int tile_worker_hook(void *arg1, void *arg2) { volatile int mi_row = 0; volatile int n = tile_data->buf_start; - tile_data->error_info.setjmp = 1; - if (setjmp(tile_data->error_info.jmp)) { tile_data->error_info.setjmp = 0; tile_data->xd.corrupted = 1; @@ -2206,6 +2205,7 @@ static int tile_worker_hook(void *arg1, void *arg2) { } return 0; } + tile_data->error_info.setjmp = 1; tile_data->xd.corrupted = 0; @@ -2285,14 +2285,20 @@ static INLINE void init_mt(VP9Decoder *pbi) { if (pbi->num_tile_workers == 0) { const int num_threads = pbi->max_threads; - CHECK_MEM_ERROR(cm, pbi->tile_workers, + CHECK_MEM_ERROR(&cm->error, pbi->tile_workers, vpx_malloc(num_threads * sizeof(*pbi->tile_workers))); for (n = 0; n < num_threads; ++n) { VPxWorker *const worker = &pbi->tile_workers[n]; ++pbi->num_tile_workers; winterface->init(worker); + worker->thread_name = "vpx tile worker"; if (n < num_threads - 1 && !winterface->reset(worker)) { + do { + winterface->end(&pbi->tile_workers[pbi->num_tile_workers - 1]); + } while (--pbi->num_tile_workers != 0); + vpx_free(pbi->tile_workers); + pbi->tile_workers = NULL; vpx_internal_error(&cm->error, VPX_CODEC_ERROR, "Tile decoder thread creation failed"); } @@ -2733,6 +2739,11 @@ static size_t read_uncompressed_header(VP9Decoder *pbi, for (i = 0; i < REFS_PER_FRAME; ++i) { const int ref = vpx_rb_read_literal(rb, REF_FRAMES_LOG2); const int idx = cm->ref_frame_map[ref]; + if (idx == INVALID_IDX) { + vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, + "Invalid reference frame index"); + } + assert(idx >= 0 && idx < FRAME_BUFFERS); RefBuffer *const ref_frame = &cm->frame_refs[i]; ref_frame->idx = idx; ref_frame->buf = &frame_bufs[idx].buf; @@ -2824,7 +2835,7 @@ static size_t read_uncompressed_header(VP9Decoder *pbi, const int num_jobs = sb_rows << cm->log2_tile_cols; if (pbi->row_mt_worker_data == NULL) { - CHECK_MEM_ERROR(cm, pbi->row_mt_worker_data, + CHECK_MEM_ERROR(&cm->error, pbi->row_mt_worker_data, vpx_calloc(1, sizeof(*pbi->row_mt_worker_data))); #if CONFIG_MULTITHREAD pthread_mutex_init(&pbi->row_mt_worker_data->recon_done_mutex, NULL); @@ -3004,9 +3015,10 @@ void vp9_decode_frame(VP9Decoder *pbi, const uint8_t *data, const size_t twd_size = num_tile_workers * sizeof(*pbi->tile_worker_data); // Ensure tile data offsets will be properly aligned. This may fail on // platforms without DECLARE_ALIGNED(). - assert((sizeof(*pbi->tile_worker_data) % 16) == 0); + static_assert((sizeof(*pbi->tile_worker_data) % 16) == 0, ""); vpx_free(pbi->tile_worker_data); - CHECK_MEM_ERROR(cm, pbi->tile_worker_data, vpx_memalign(32, twd_size)); + CHECK_MEM_ERROR(&cm->error, pbi->tile_worker_data, + vpx_memalign(32, twd_size)); pbi->total_tiles = tile_rows * tile_cols; } diff --git a/libs/libvpx/vp9/decoder/vp9_decodemv.c b/libs/libvpx/vp9/decoder/vp9_decodemv.c index 8a8d2ad86e..0989cde58d 100644 --- a/libs/libvpx/vp9/decoder/vp9_decodemv.c +++ b/libs/libvpx/vp9/decoder/vp9_decodemv.c @@ -204,7 +204,7 @@ static void read_intra_frame_mode_info(VP9_COMMON *const cm, mi->skip = read_skip(cm, xd, mi->segment_id, r); mi->tx_size = read_tx_size(cm, xd, 1, r); mi->ref_frame[0] = INTRA_FRAME; - mi->ref_frame[1] = NONE; + mi->ref_frame[1] = NO_REF_FRAME; switch (bsize) { case BLOCK_4X4: @@ -299,7 +299,7 @@ static REFERENCE_MODE read_block_reference_mode(VP9_COMMON *cm, } } -// Read the referncence frame +// Read the reference frame static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd, vpx_reader *r, int segment_id, MV_REFERENCE_FRAME ref_frame[2]) { @@ -309,7 +309,7 @@ static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd, if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { ref_frame[0] = (MV_REFERENCE_FRAME)get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME); - ref_frame[1] = NONE; + ref_frame[1] = NO_REF_FRAME; } else { const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r); // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding @@ -333,7 +333,7 @@ static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd, ref_frame[0] = LAST_FRAME; } - ref_frame[1] = NONE; + ref_frame[1] = NO_REF_FRAME; } else { assert(0 && "Invalid prediction mode."); } @@ -383,7 +383,7 @@ static void read_intra_block_mode_info(VP9_COMMON *const cm, mi->interp_filter = SWITCHABLE_FILTERS; mi->ref_frame[0] = INTRA_FRAME; - mi->ref_frame[1] = NONE; + mi->ref_frame[1] = NO_REF_FRAME; } static INLINE int is_mv_valid(const MV *mv) { @@ -426,7 +426,9 @@ static INLINE int assign_mv(VP9_COMMON *cm, MACROBLOCKD *xd, zero_mv_pair(mv); break; } - default: { return 0; } + default: { + return 0; + } } return ret; } @@ -706,7 +708,7 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi, mi->mode = ZEROMV; if (bsize < BLOCK_8X8) { vpx_internal_error(xd->error_info, VPX_CODEC_UNSUP_BITSTREAM, - "Invalid usage of segement feature on small blocks"); + "Invalid usage of segment feature on small blocks"); return; } } else { @@ -755,7 +757,7 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi, if (!assign_mv(cm, xd, b_mode, mi->bmi[j].as_mv, best_ref_mvs, best_sub8x8, is_compound, allow_hp, r)) { xd->corrupted |= 1; - break; + return; } if (num_4x4_h == 2) mi->bmi[j + 2] = mi->bmi[j]; diff --git a/libs/libvpx/vp9/decoder/vp9_decoder.c b/libs/libvpx/vp9/decoder/vp9_decoder.c index 7db8ed72d5..1554361ca3 100644 --- a/libs/libvpx/vp9/decoder/vp9_decoder.c +++ b/libs/libvpx/vp9/decoder/vp9_decoder.c @@ -16,11 +16,14 @@ #include "./vpx_dsp_rtcd.h" #include "./vpx_scale_rtcd.h" +#include "vpx/internal/vpx_codec_internal.h" +#include "vpx/vpx_codec.h" #include "vpx_mem/vpx_mem.h" #include "vpx_ports/system_state.h" #include "vpx_ports/vpx_once.h" #include "vpx_ports/vpx_timer.h" #include "vpx_scale/vpx_scale.h" +#include "vpx_util/vpx_pthread.h" #include "vpx_util/vpx_thread.h" #include "vp9/common/vp9_alloccommon.h" @@ -58,15 +61,18 @@ static void vp9_dec_setup_mi(VP9_COMMON *cm) { void vp9_dec_alloc_row_mt_mem(RowMTWorkerData *row_mt_worker_data, VP9_COMMON *cm, int num_sbs, int max_threads, int num_jobs) { - int plane; - const size_t dqcoeff_size = (num_sbs << DQCOEFFS_PER_SB_LOG2) * + if ((size_t)num_sbs > SIZE_MAX / (sizeof(*row_mt_worker_data->dqcoeff[0]) + << DQCOEFFS_PER_SB_LOG2)) { + vpx_internal_error(&cm->error, VPX_CODEC_ERROR, "num_sbs too big"); + } + const size_t dqcoeff_size = ((size_t)num_sbs << DQCOEFFS_PER_SB_LOG2) * sizeof(*row_mt_worker_data->dqcoeff[0]); row_mt_worker_data->num_jobs = num_jobs; #if CONFIG_MULTITHREAD { int i; CHECK_MEM_ERROR( - cm, row_mt_worker_data->recon_sync_mutex, + &cm->error, row_mt_worker_data->recon_sync_mutex, vpx_malloc(sizeof(*row_mt_worker_data->recon_sync_mutex) * num_jobs)); if (row_mt_worker_data->recon_sync_mutex) { for (i = 0; i < num_jobs; ++i) { @@ -75,7 +81,7 @@ void vp9_dec_alloc_row_mt_mem(RowMTWorkerData *row_mt_worker_data, } CHECK_MEM_ERROR( - cm, row_mt_worker_data->recon_sync_cond, + &cm->error, row_mt_worker_data->recon_sync_cond, vpx_malloc(sizeof(*row_mt_worker_data->recon_sync_cond) * num_jobs)); if (row_mt_worker_data->recon_sync_cond) { for (i = 0; i < num_jobs; ++i) { @@ -85,25 +91,25 @@ void vp9_dec_alloc_row_mt_mem(RowMTWorkerData *row_mt_worker_data, } #endif row_mt_worker_data->num_sbs = num_sbs; - for (plane = 0; plane < 3; ++plane) { - CHECK_MEM_ERROR(cm, row_mt_worker_data->dqcoeff[plane], - vpx_memalign(16, dqcoeff_size)); + for (int plane = 0; plane < 3; ++plane) { + CHECK_MEM_ERROR(&cm->error, row_mt_worker_data->dqcoeff[plane], + vpx_memalign(32, dqcoeff_size)); memset(row_mt_worker_data->dqcoeff[plane], 0, dqcoeff_size); - CHECK_MEM_ERROR(cm, row_mt_worker_data->eob[plane], - vpx_calloc(num_sbs << EOBS_PER_SB_LOG2, + CHECK_MEM_ERROR(&cm->error, row_mt_worker_data->eob[plane], + vpx_calloc((size_t)num_sbs << EOBS_PER_SB_LOG2, sizeof(*row_mt_worker_data->eob[plane]))); } - CHECK_MEM_ERROR(cm, row_mt_worker_data->partition, - vpx_calloc(num_sbs * PARTITIONS_PER_SB, + CHECK_MEM_ERROR(&cm->error, row_mt_worker_data->partition, + vpx_calloc((size_t)num_sbs * PARTITIONS_PER_SB, sizeof(*row_mt_worker_data->partition))); - CHECK_MEM_ERROR(cm, row_mt_worker_data->recon_map, + CHECK_MEM_ERROR(&cm->error, row_mt_worker_data->recon_map, vpx_calloc(num_sbs, sizeof(*row_mt_worker_data->recon_map))); // allocate memory for thread_data if (row_mt_worker_data->thread_data == NULL) { const size_t thread_size = max_threads * sizeof(*row_mt_worker_data->thread_data); - CHECK_MEM_ERROR(cm, row_mt_worker_data->thread_data, + CHECK_MEM_ERROR(&cm->error, row_mt_worker_data->thread_data, vpx_memalign(32, thread_size)); } } @@ -181,9 +187,10 @@ VP9Decoder *vp9_decoder_create(BufferPool *const pool) { cm->error.setjmp = 1; - CHECK_MEM_ERROR(cm, cm->fc, (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); + CHECK_MEM_ERROR(&cm->error, cm->fc, + (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); CHECK_MEM_ERROR( - cm, cm->frame_contexts, + &cm->error, cm->frame_contexts, (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, sizeof(*cm->frame_contexts))); pbi->need_resync = 1; @@ -209,6 +216,7 @@ VP9Decoder *vp9_decoder_create(BufferPool *const pool) { cm->error.setjmp = 0; vpx_get_worker_interface()->init(&pbi->lf_worker); + pbi->lf_worker.thread_name = "vpx lf worker"; return pbi; } @@ -509,16 +517,27 @@ int vp9_get_raw_frame(VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd, pbi->ready_for_new_data = 1; #if CONFIG_VP9_POSTPROC + if (setjmp(cm->error.jmp)) { + cm->error.setjmp = 0; + vpx_clear_system_state(); + return -1; + } + + cm->error.setjmp = 1; + if (!cm->show_existing_frame) { ret = vp9_post_proc_frame(cm, sd, flags, cm->width); } else { *sd = *cm->frame_to_show; ret = 0; } + + cm->error.setjmp = 0; #else *sd = *cm->frame_to_show; ret = 0; #endif /*!CONFIG_POSTPROC*/ + vpx_clear_system_state(); return ret; } diff --git a/libs/libvpx/vp9/decoder/vp9_decoder.h b/libs/libvpx/vp9/decoder/vp9_decoder.h index b0ef83c73d..b3ee4eab5f 100644 --- a/libs/libvpx/vp9/decoder/vp9_decoder.h +++ b/libs/libvpx/vp9/decoder/vp9_decoder.h @@ -16,6 +16,7 @@ #include "vpx/vpx_codec.h" #include "vpx_dsp/bitreader.h" #include "vpx_scale/yv12config.h" +#include "vpx_util/vpx_pthread.h" #include "vpx_util/vpx_thread.h" #include "vp9/common/vp9_thread_common.h" @@ -54,7 +55,7 @@ typedef struct TileWorkerData { VP9LfSync *lf_sync; DECLARE_ALIGNED(16, MACROBLOCKD, xd); /* dqcoeff are shared by all the planes. So planes must be decoded serially */ - DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]); + DECLARE_ALIGNED(32, tran_low_t, dqcoeff[32 * 32]); DECLARE_ALIGNED(16, uint16_t, extend_and_predict_buf[80 * 2 * 80 * 2]); struct vpx_internal_error_info error_info; } TileWorkerData; diff --git a/libs/libvpx/vp9/decoder/vp9_detokenize.c b/libs/libvpx/vp9/decoder/vp9_detokenize.c index c2e6b3d545..2d36d213a0 100644 --- a/libs/libvpx/vp9/decoder/vp9_detokenize.c +++ b/libs/libvpx/vp9/decoder/vp9_detokenize.c @@ -124,8 +124,8 @@ static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type, const vpx_prob(*coef_probs)[COEFF_CONTEXTS][UNCONSTRAINED_NODES] = fc->coef_probs[tx_size][type][ref]; const vpx_prob *prob; - unsigned int(*coef_counts)[COEFF_CONTEXTS][UNCONSTRAINED_NODES + 1]; - unsigned int(*eob_branch_count)[COEFF_CONTEXTS]; + unsigned int (*coef_counts)[COEFF_CONTEXTS][UNCONSTRAINED_NODES + 1]; + unsigned int (*eob_branch_count)[COEFF_CONTEXTS]; uint8_t token_cache[32 * 32]; const uint8_t *band_translate = get_band_translate(tx_size); const int dq_shift = (tx_size == TX_32X32); @@ -133,17 +133,18 @@ static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type, int16_t dqv = dq[0]; const uint8_t *const cat6_prob = #if CONFIG_VP9_HIGHBITDEPTH - (xd->bd == VPX_BITS_12) - ? vp9_cat6_prob_high12 - : (xd->bd == VPX_BITS_10) ? vp9_cat6_prob_high12 + 2 : + (xd->bd == VPX_BITS_12) ? vp9_cat6_prob_high12 + : (xd->bd == VPX_BITS_10) ? vp9_cat6_prob_high12 + 2 + : #endif // CONFIG_VP9_HIGHBITDEPTH - vp9_cat6_prob; + vp9_cat6_prob; const int cat6_bits = #if CONFIG_VP9_HIGHBITDEPTH - (xd->bd == VPX_BITS_12) ? 18 - : (xd->bd == VPX_BITS_10) ? 16 : + (xd->bd == VPX_BITS_12) ? 18 + : (xd->bd == VPX_BITS_10) ? 16 + : #endif // CONFIG_VP9_HIGHBITDEPTH - 14; + 14; // Keep value, range, and count as locals. The compiler produces better // results with the locals than using r directly. BD_VALUE value = r->value; @@ -271,9 +272,8 @@ static void get_ctx_shift(MACROBLOCKD *xd, int *ctx_shift_a, int *ctx_shift_l, } } -int vp9_decode_block_tokens(TileWorkerData *twd, int plane, - const scan_order *sc, int x, int y, TX_SIZE tx_size, - int seg_id) { +int vp9_decode_block_tokens(TileWorkerData *twd, int plane, const ScanOrder *sc, + int x, int y, TX_SIZE tx_size, int seg_id) { vpx_reader *r = &twd->bit_reader; MACROBLOCKD *xd = &twd->xd; struct macroblockd_plane *const pd = &xd->plane[plane]; diff --git a/libs/libvpx/vp9/decoder/vp9_detokenize.h b/libs/libvpx/vp9/decoder/vp9_detokenize.h index a32052ffff..a8e47021b8 100644 --- a/libs/libvpx/vp9/decoder/vp9_detokenize.h +++ b/libs/libvpx/vp9/decoder/vp9_detokenize.h @@ -19,9 +19,8 @@ extern "C" { #endif -int vp9_decode_block_tokens(TileWorkerData *twd, int plane, - const scan_order *sc, int x, int y, TX_SIZE tx_size, - int seg_id); +int vp9_decode_block_tokens(TileWorkerData *twd, int plane, const ScanOrder *sc, + int x, int y, TX_SIZE tx_size, int seg_id); #ifdef __cplusplus } // extern "C" diff --git a/libs/libvpx/vp9/decoder/vp9_job_queue.c b/libs/libvpx/vp9/decoder/vp9_job_queue.c index 9a31f5a6d0..926ae87739 100644 --- a/libs/libvpx/vp9/decoder/vp9_job_queue.c +++ b/libs/libvpx/vp9/decoder/vp9_job_queue.c @@ -12,6 +12,7 @@ #include #include "vpx/vpx_integer.h" +#include "vpx_util/vpx_pthread.h" #include "vp9/decoder/vp9_job_queue.h" diff --git a/libs/libvpx/vp9/decoder/vp9_job_queue.h b/libs/libvpx/vp9/decoder/vp9_job_queue.h index bc23bf9c2c..59f71fb9ba 100644 --- a/libs/libvpx/vp9/decoder/vp9_job_queue.h +++ b/libs/libvpx/vp9/decoder/vp9_job_queue.h @@ -11,7 +11,7 @@ #ifndef VPX_VP9_DECODER_VP9_JOB_QUEUE_H_ #define VPX_VP9_DECODER_VP9_JOB_QUEUE_H_ -#include "vpx_util/vpx_thread.h" +#include "vpx_util/vpx_pthread.h" typedef struct { // Pointer to buffer base which contains the jobs diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_dct_neon.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_dct_neon.c index a07a1608d7..997b5477e1 100644 --- a/libs/libvpx/vp9/encoder/arm/neon/vp9_dct_neon.c +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_dct_neon.c @@ -18,28 +18,31 @@ #include "vpx_dsp/arm/mem_neon.h" #include "vpx_dsp/arm/transpose_neon.h" #include "vpx_dsp/arm/fdct_neon.h" +#include "vpx_dsp/arm/fdct4x4_neon.h" +#include "vpx_dsp/arm/fdct8x8_neon.h" +#include "vpx_dsp/arm/fdct16x16_neon.h" static INLINE void load_buffer_4x4(const int16_t *input, int16x8_t *in, int stride) { - // { 0, 1, 1, 1, 1, 1, 1, 1 }; - const int16x8_t nonzero_bias_a = vextq_s16(vdupq_n_s16(0), vdupq_n_s16(1), 7); - // { 1, 0, 0, 0, 0, 0, 0, 0 }; - const int16x8_t nonzero_bias_b = vextq_s16(vdupq_n_s16(1), vdupq_n_s16(0), 7); - int16x8_t mask; + // { 0, 1, 1, 1 }; + const int16x4_t nonzero_bias_a = vext_s16(vdup_n_s16(0), vdup_n_s16(1), 3); + // { 1, 0, 0, 0 }; + const int16x4_t nonzero_bias_b = vext_s16(vdup_n_s16(1), vdup_n_s16(0), 3); + int16x4_t mask; int16x4_t input_0 = vshl_n_s16(vld1_s16(input + 0 * stride), 4); int16x4_t input_1 = vshl_n_s16(vld1_s16(input + 1 * stride), 4); int16x4_t input_2 = vshl_n_s16(vld1_s16(input + 2 * stride), 4); int16x4_t input_3 = vshl_n_s16(vld1_s16(input + 3 * stride), 4); - in[0] = vcombine_s16(input_0, input_1); - in[1] = vcombine_s16(input_2, input_3); - // Copy the SSE method, use a mask to avoid an 'if' branch here to increase by // one non-zero first elements - mask = vreinterpretq_s16_u16(vceqq_s16(in[0], nonzero_bias_a)); - in[0] = vaddq_s16(in[0], mask); - in[0] = vaddq_s16(in[0], nonzero_bias_b); + mask = vreinterpret_s16_u16(vceq_s16(input_0, nonzero_bias_a)); + input_0 = vadd_s16(input_0, mask); + input_0 = vadd_s16(input_0, nonzero_bias_b); + + in[0] = vcombine_s16(input_0, input_1); + in[1] = vcombine_s16(input_2, input_3); } static INLINE void write_buffer_4x4(tran_low_t *output, int16x8_t *res) { @@ -53,72 +56,54 @@ static INLINE void write_buffer_4x4(tran_low_t *output, int16x8_t *res) { } static INLINE void fadst4x4_neon(int16x8_t *in) { - int32x4_t u0, u1, u2, u3; - int16x4_t out_0, out_1, out_2, out_3; - const int32x4_t k__DCT_CONST_ROUNDING = vdupq_n_s32(DCT_CONST_ROUNDING); + int32x4_t u[4], t[4]; + int16x4_t s[4], out[4]; - const int16x4_t s0 = vget_low_s16(in[0]); // | x_00 | x_01 | x_02 | x_03 | - const int16x4_t s1 = vget_high_s16(in[0]); // | x_10 | x_11 | x_12 | x_13 | - const int16x4_t s2 = vget_low_s16(in[1]); // | x_20 | x_21 | x_22 | x_23 | - const int16x4_t s3 = vget_high_s16(in[1]); // | x_30 | x_31 | x_32 | x_33 | + s[0] = vget_low_s16(in[0]); // | x_00 | x_01 | x_02 | x_03 | + s[1] = vget_high_s16(in[0]); // | x_10 | x_11 | x_12 | x_13 | + s[2] = vget_low_s16(in[1]); // | x_20 | x_21 | x_22 | x_23 | + s[3] = vget_high_s16(in[1]); // | x_30 | x_31 | x_32 | x_33 | - // s0 * sinpi_1_9, s0 * sinpi_4_9 // Must expand all elements to s32. See 'needs32' comment in fwd_txfm.c. - const int32x4_t s0s1_9 = vmull_n_s16(s0, sinpi_1_9); - const int32x4_t s0s4_9 = vmull_n_s16(s0, sinpi_4_9); - // s1 * sinpi_1_9, s1 * sinpi_2_9 - const int32x4_t s1s1_9 = vmull_n_s16(s1, sinpi_1_9); - const int32x4_t s1s2_9 = vmull_n_s16(s1, sinpi_2_9); - // s2 * sinpi_3_9 - const int32x4_t s2s3_9 = vmull_n_s16(s2, sinpi_3_9); - // s3 * sinpi_2_9, s3 * sinpi_4_9 - const int32x4_t s3s2_9 = vmull_n_s16(s3, sinpi_2_9); - const int32x4_t s3s4_9 = vmull_n_s16(s3, sinpi_4_9); + // t0 = s0 * sinpi_1_9 + s1 * sinpi_2_9 + s3 * sinpi_4_9 + t[0] = vmull_n_s16(s[0], sinpi_1_9); + t[0] = vmlal_n_s16(t[0], s[1], sinpi_2_9); + t[0] = vmlal_n_s16(t[0], s[3], sinpi_4_9); - // (s0 + s1) * sinpi_3_9 - const int32x4_t s0_p_s1 = vaddl_s16(s0, s1); - const int32x4_t s0_p_s1_m_s3 = vsubw_s16(s0_p_s1, s3); + // t1 = (s0 + s1) * sinpi_3_9 - s3 * sinpi_3_9 + t[1] = vmull_n_s16(s[0], sinpi_3_9); + t[1] = vmlal_n_s16(t[1], s[1], sinpi_3_9); + t[1] = vmlsl_n_s16(t[1], s[3], sinpi_3_9); + + // t2 = s0 * sinpi_4_9 - s1* sinpi_1_9 + s3 * sinpi_2_9 + t[2] = vmull_n_s16(s[0], sinpi_4_9); + t[2] = vmlsl_n_s16(t[2], s[1], sinpi_1_9); + t[2] = vmlal_n_s16(t[2], s[3], sinpi_2_9); + + // t3 = s2 * sinpi_3_9 + t[3] = vmull_n_s16(s[2], sinpi_3_9); - // s_0 * sinpi_1_9 + s_1 * sinpi_2_9 - // s_0 * sinpi_4_9 - s_1 * sinpi_1_9 - const int32x4_t s0s1_9_p_s1s2_9 = vaddq_s32(s0s1_9, s1s2_9); - const int32x4_t s0s4_9_m_s1s1_9 = vsubq_s32(s0s4_9, s1s1_9); - /* - * t0 = s0s1_9 + s1s2_9 + s3s4_9 - * t1 = (s0 + s1) * sinpi_3_9 - s3 * sinpi_3_9 - * t2 = s0s4_9 - s1s1_9 + s3s2_9 - * t3 = s2s3_9 - */ - const int32x4_t t0 = vaddq_s32(s0s1_9_p_s1s2_9, s3s4_9); - const int32x4_t t1 = vmulq_n_s32(s0_p_s1_m_s3, sinpi_3_9); - const int32x4_t t2 = vaddq_s32(s0s4_9_m_s1s1_9, s3s2_9); - const int32x4_t t3 = s2s3_9; /* * u0 = t0 + t3 * u1 = t1 * u2 = t2 - t3 * u3 = t2 - t0 + t3 */ - u0 = vaddq_s32(t0, t3); - u1 = t1; - u2 = vsubq_s32(t2, t3); - u3 = vaddq_s32(vsubq_s32(t2, t0), t3); + u[0] = vaddq_s32(t[0], t[3]); + u[1] = t[1]; + u[2] = vsubq_s32(t[2], t[3]); + u[3] = vaddq_s32(vsubq_s32(t[2], t[0]), t[3]); // fdct_round_shift - u0 = vaddq_s32(u0, k__DCT_CONST_ROUNDING); - u1 = vaddq_s32(u1, k__DCT_CONST_ROUNDING); - u2 = vaddq_s32(u2, k__DCT_CONST_ROUNDING); - u3 = vaddq_s32(u3, k__DCT_CONST_ROUNDING); + out[0] = vrshrn_n_s32(u[0], DCT_CONST_BITS); + out[1] = vrshrn_n_s32(u[1], DCT_CONST_BITS); + out[2] = vrshrn_n_s32(u[2], DCT_CONST_BITS); + out[3] = vrshrn_n_s32(u[3], DCT_CONST_BITS); - out_0 = vshrn_n_s32(u0, DCT_CONST_BITS); - out_1 = vshrn_n_s32(u1, DCT_CONST_BITS); - out_2 = vshrn_n_s32(u2, DCT_CONST_BITS); - out_3 = vshrn_n_s32(u3, DCT_CONST_BITS); + transpose_s16_4x4d(&out[0], &out[1], &out[2], &out[3]); - transpose_s16_4x4d(&out_0, &out_1, &out_2, &out_3); - - in[0] = vcombine_s16(out_0, out_1); - in[1] = vcombine_s16(out_2, out_3); + in[0] = vcombine_s16(out[0], out[1]); + in[1] = vcombine_s16(out[2], out[3]); } void vp9_fht4x4_neon(const int16_t *input, tran_low_t *output, int stride, @@ -130,12 +115,14 @@ void vp9_fht4x4_neon(const int16_t *input, tran_low_t *output, int stride, case ADST_DCT: load_buffer_4x4(input, in, stride); fadst4x4_neon(in); - vpx_fdct4x4_pass1_neon((int16x4_t *)in); + // pass1 variant is not accurate enough + vpx_fdct4x4_pass2_neon((int16x4_t *)in); write_buffer_4x4(output, in); break; case DCT_ADST: load_buffer_4x4(input, in, stride); - vpx_fdct4x4_pass1_neon((int16x4_t *)in); + // pass1 variant is not accurate enough + vpx_fdct4x4_pass2_neon((int16x4_t *)in); fadst4x4_neon(in); write_buffer_4x4(output, in); break; @@ -235,245 +222,158 @@ static INLINE void write_buffer_8x8(tran_low_t *output, int16x8_t *res, } static INLINE void fadst8x8_neon(int16x8_t *in) { - int16x4_t x0_lo, x0_hi, x1_lo, x1_hi, x2_lo, x2_hi, x3_lo, x3_hi, x4_lo, - x4_hi, x5_lo, x5_hi, x6_lo, x6_hi, x7_lo, x7_hi; - int32x4_t s0_lo, s0_hi, s1_lo, s1_hi, s2_lo, s2_hi, s3_lo, s3_hi, s4_lo, - s4_hi, s5_lo, s5_hi, s6_lo, s6_hi, s7_lo, s7_hi; - int32x4_t t0_lo, t0_hi, t1_lo, t1_hi, t2_lo, t2_hi, t3_lo, t3_hi, t4_lo, - t4_hi, t5_lo, t5_hi, t6_lo, t6_hi, t7_lo, t7_hi; - const int32x4_t k__DCT_CONST_ROUNDING = vdupq_n_s32(DCT_CONST_ROUNDING); + int16x4_t x_lo[8], x_hi[8]; + int32x4_t s_lo[8], s_hi[8]; + int32x4_t t_lo[8], t_hi[8]; - x0_lo = vget_low_s16(in[7]); - x0_hi = vget_high_s16(in[7]); - x1_lo = vget_low_s16(in[0]); - x1_hi = vget_high_s16(in[0]); - x2_lo = vget_low_s16(in[5]); - x2_hi = vget_high_s16(in[5]); - x3_lo = vget_low_s16(in[2]); - x3_hi = vget_high_s16(in[2]); - x4_lo = vget_low_s16(in[3]); - x4_hi = vget_high_s16(in[3]); - x5_lo = vget_low_s16(in[4]); - x5_hi = vget_high_s16(in[4]); - x6_lo = vget_low_s16(in[1]); - x6_hi = vget_high_s16(in[1]); - x7_lo = vget_low_s16(in[6]); - x7_hi = vget_high_s16(in[6]); + x_lo[0] = vget_low_s16(in[7]); + x_hi[0] = vget_high_s16(in[7]); + x_lo[1] = vget_low_s16(in[0]); + x_hi[1] = vget_high_s16(in[0]); + x_lo[2] = vget_low_s16(in[5]); + x_hi[2] = vget_high_s16(in[5]); + x_lo[3] = vget_low_s16(in[2]); + x_hi[3] = vget_high_s16(in[2]); + x_lo[4] = vget_low_s16(in[3]); + x_hi[4] = vget_high_s16(in[3]); + x_lo[5] = vget_low_s16(in[4]); + x_hi[5] = vget_high_s16(in[4]); + x_lo[6] = vget_low_s16(in[1]); + x_hi[6] = vget_high_s16(in[1]); + x_lo[7] = vget_low_s16(in[6]); + x_hi[7] = vget_high_s16(in[6]); // stage 1 // s0 = cospi_2_64 * x0 + cospi_30_64 * x1; - s0_lo = vaddq_s32(vmull_n_s16(x0_lo, cospi_2_64), - vmull_n_s16(x1_lo, cospi_30_64)); - s0_hi = vaddq_s32(vmull_n_s16(x0_hi, cospi_2_64), - vmull_n_s16(x1_hi, cospi_30_64)); // s1 = cospi_30_64 * x0 - cospi_2_64 * x1; - s1_lo = vsubq_s32(vmull_n_s16(x0_lo, cospi_30_64), - vmull_n_s16(x1_lo, cospi_2_64)); - s1_hi = vsubq_s32(vmull_n_s16(x0_hi, cospi_30_64), - vmull_n_s16(x1_hi, cospi_2_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[0], x_hi[0], x_lo[1], x_hi[1], + cospi_2_64, cospi_30_64, &s_lo[0], + &s_hi[0], &s_lo[1], &s_hi[1]); + // s2 = cospi_10_64 * x2 + cospi_22_64 * x3; - s2_lo = vaddq_s32(vmull_n_s16(x2_lo, cospi_10_64), - vmull_n_s16(x3_lo, cospi_22_64)); - s2_hi = vaddq_s32(vmull_n_s16(x2_hi, cospi_10_64), - vmull_n_s16(x3_hi, cospi_22_64)); // s3 = cospi_22_64 * x2 - cospi_10_64 * x3; - s3_lo = vsubq_s32(vmull_n_s16(x2_lo, cospi_22_64), - vmull_n_s16(x3_lo, cospi_10_64)); - s3_hi = vsubq_s32(vmull_n_s16(x2_hi, cospi_22_64), - vmull_n_s16(x3_hi, cospi_10_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[2], x_hi[2], x_lo[3], x_hi[3], + cospi_10_64, cospi_22_64, &s_lo[2], + &s_hi[2], &s_lo[3], &s_hi[3]); + // s4 = cospi_18_64 * x4 + cospi_14_64 * x5; - s4_lo = vaddq_s32(vmull_n_s16(x4_lo, cospi_18_64), - vmull_n_s16(x5_lo, cospi_14_64)); - s4_hi = vaddq_s32(vmull_n_s16(x4_hi, cospi_18_64), - vmull_n_s16(x5_hi, cospi_14_64)); // s5 = cospi_14_64 * x4 - cospi_18_64 * x5; - s5_lo = vsubq_s32(vmull_n_s16(x4_lo, cospi_14_64), - vmull_n_s16(x5_lo, cospi_18_64)); - s5_hi = vsubq_s32(vmull_n_s16(x4_hi, cospi_14_64), - vmull_n_s16(x5_hi, cospi_18_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[4], x_hi[4], x_lo[5], x_hi[5], + cospi_18_64, cospi_14_64, &s_lo[4], + &s_hi[4], &s_lo[5], &s_hi[5]); + // s6 = cospi_26_64 * x6 + cospi_6_64 * x7; - s6_lo = vaddq_s32(vmull_n_s16(x6_lo, cospi_26_64), - vmull_n_s16(x7_lo, cospi_6_64)); - s6_hi = vaddq_s32(vmull_n_s16(x6_hi, cospi_26_64), - vmull_n_s16(x7_hi, cospi_6_64)); // s7 = cospi_6_64 * x6 - cospi_26_64 * x7; - s7_lo = vsubq_s32(vmull_n_s16(x6_lo, cospi_6_64), - vmull_n_s16(x7_lo, cospi_26_64)); - s7_hi = vsubq_s32(vmull_n_s16(x6_hi, cospi_6_64), - vmull_n_s16(x7_hi, cospi_26_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[6], x_hi[6], x_lo[7], x_hi[7], + cospi_26_64, cospi_6_64, &s_lo[6], + &s_hi[6], &s_lo[7], &s_hi[7]); // fdct_round_shift - t0_lo = vaddq_s32(s0_lo, s4_lo); - t0_hi = vaddq_s32(s0_hi, s4_hi); - t1_lo = vaddq_s32(s1_lo, s5_lo); - t1_hi = vaddq_s32(s1_hi, s5_hi); - t2_lo = vaddq_s32(s2_lo, s6_lo); - t2_hi = vaddq_s32(s2_hi, s6_hi); - t3_lo = vaddq_s32(s3_lo, s7_lo); - t3_hi = vaddq_s32(s3_hi, s7_hi); - t4_lo = vsubq_s32(s0_lo, s4_lo); - t4_hi = vsubq_s32(s0_hi, s4_hi); - t5_lo = vsubq_s32(s1_lo, s5_lo); - t5_hi = vsubq_s32(s1_hi, s5_hi); - t6_lo = vsubq_s32(s2_lo, s6_lo); - t6_hi = vsubq_s32(s2_hi, s6_hi); - t7_lo = vsubq_s32(s3_lo, s7_lo); - t7_hi = vsubq_s32(s3_hi, s7_hi); - - t0_lo = vaddq_s32(t0_lo, k__DCT_CONST_ROUNDING); - t0_hi = vaddq_s32(t0_hi, k__DCT_CONST_ROUNDING); - t1_lo = vaddq_s32(t1_lo, k__DCT_CONST_ROUNDING); - t1_hi = vaddq_s32(t1_hi, k__DCT_CONST_ROUNDING); - t2_lo = vaddq_s32(t2_lo, k__DCT_CONST_ROUNDING); - t2_hi = vaddq_s32(t2_hi, k__DCT_CONST_ROUNDING); - t3_lo = vaddq_s32(t3_lo, k__DCT_CONST_ROUNDING); - t3_hi = vaddq_s32(t3_hi, k__DCT_CONST_ROUNDING); - t4_lo = vaddq_s32(t4_lo, k__DCT_CONST_ROUNDING); - t4_hi = vaddq_s32(t4_hi, k__DCT_CONST_ROUNDING); - t5_lo = vaddq_s32(t5_lo, k__DCT_CONST_ROUNDING); - t5_hi = vaddq_s32(t5_hi, k__DCT_CONST_ROUNDING); - t6_lo = vaddq_s32(t6_lo, k__DCT_CONST_ROUNDING); - t6_hi = vaddq_s32(t6_hi, k__DCT_CONST_ROUNDING); - t7_lo = vaddq_s32(t7_lo, k__DCT_CONST_ROUNDING); - t7_hi = vaddq_s32(t7_hi, k__DCT_CONST_ROUNDING); - - t0_lo = vshrq_n_s32(t0_lo, DCT_CONST_BITS); - t0_hi = vshrq_n_s32(t0_hi, DCT_CONST_BITS); - t1_lo = vshrq_n_s32(t1_lo, DCT_CONST_BITS); - t1_hi = vshrq_n_s32(t1_hi, DCT_CONST_BITS); - t2_lo = vshrq_n_s32(t2_lo, DCT_CONST_BITS); - t2_hi = vshrq_n_s32(t2_hi, DCT_CONST_BITS); - t3_lo = vshrq_n_s32(t3_lo, DCT_CONST_BITS); - t3_hi = vshrq_n_s32(t3_hi, DCT_CONST_BITS); - t4_lo = vshrq_n_s32(t4_lo, DCT_CONST_BITS); - t4_hi = vshrq_n_s32(t4_hi, DCT_CONST_BITS); - t5_lo = vshrq_n_s32(t5_lo, DCT_CONST_BITS); - t5_hi = vshrq_n_s32(t5_hi, DCT_CONST_BITS); - t6_lo = vshrq_n_s32(t6_lo, DCT_CONST_BITS); - t6_hi = vshrq_n_s32(t6_hi, DCT_CONST_BITS); - t7_lo = vshrq_n_s32(t7_lo, DCT_CONST_BITS); - t7_hi = vshrq_n_s32(t7_hi, DCT_CONST_BITS); + t_lo[0] = vrshrq_n_s32(vaddq_s32(s_lo[0], s_lo[4]), DCT_CONST_BITS); + t_hi[0] = vrshrq_n_s32(vaddq_s32(s_hi[0], s_hi[4]), DCT_CONST_BITS); + t_lo[1] = vrshrq_n_s32(vaddq_s32(s_lo[1], s_lo[5]), DCT_CONST_BITS); + t_hi[1] = vrshrq_n_s32(vaddq_s32(s_hi[1], s_hi[5]), DCT_CONST_BITS); + t_lo[2] = vrshrq_n_s32(vaddq_s32(s_lo[2], s_lo[6]), DCT_CONST_BITS); + t_hi[2] = vrshrq_n_s32(vaddq_s32(s_hi[2], s_hi[6]), DCT_CONST_BITS); + t_lo[3] = vrshrq_n_s32(vaddq_s32(s_lo[3], s_lo[7]), DCT_CONST_BITS); + t_hi[3] = vrshrq_n_s32(vaddq_s32(s_hi[3], s_hi[7]), DCT_CONST_BITS); + t_lo[4] = vrshrq_n_s32(vsubq_s32(s_lo[0], s_lo[4]), DCT_CONST_BITS); + t_hi[4] = vrshrq_n_s32(vsubq_s32(s_hi[0], s_hi[4]), DCT_CONST_BITS); + t_lo[5] = vrshrq_n_s32(vsubq_s32(s_lo[1], s_lo[5]), DCT_CONST_BITS); + t_hi[5] = vrshrq_n_s32(vsubq_s32(s_hi[1], s_hi[5]), DCT_CONST_BITS); + t_lo[6] = vrshrq_n_s32(vsubq_s32(s_lo[2], s_lo[6]), DCT_CONST_BITS); + t_hi[6] = vrshrq_n_s32(vsubq_s32(s_hi[2], s_hi[6]), DCT_CONST_BITS); + t_lo[7] = vrshrq_n_s32(vsubq_s32(s_lo[3], s_lo[7]), DCT_CONST_BITS); + t_hi[7] = vrshrq_n_s32(vsubq_s32(s_hi[3], s_hi[7]), DCT_CONST_BITS); // stage 2 - s0_lo = t0_lo; - s0_hi = t0_hi; - s1_lo = t1_lo; - s1_hi = t1_hi; - s2_lo = t2_lo; - s2_hi = t2_hi; - s3_lo = t3_lo; - s3_hi = t3_hi; - s4_lo = vaddq_s32(vmulq_n_s32(t4_lo, cospi_8_64), - vmulq_n_s32(t5_lo, cospi_24_64)); - s4_hi = vaddq_s32(vmulq_n_s32(t4_hi, cospi_8_64), - vmulq_n_s32(t5_hi, cospi_24_64)); - s5_lo = vsubq_s32(vmulq_n_s32(t4_lo, cospi_24_64), - vmulq_n_s32(t5_lo, cospi_8_64)); - s5_hi = vsubq_s32(vmulq_n_s32(t4_hi, cospi_24_64), - vmulq_n_s32(t5_hi, cospi_8_64)); - s6_lo = vaddq_s32(vmulq_n_s32(t6_lo, -cospi_24_64), - vmulq_n_s32(t7_lo, cospi_8_64)); - s6_hi = vaddq_s32(vmulq_n_s32(t6_hi, -cospi_24_64), - vmulq_n_s32(t7_hi, cospi_8_64)); - s7_lo = vaddq_s32(vmulq_n_s32(t6_lo, cospi_8_64), - vmulq_n_s32(t7_lo, cospi_24_64)); - s7_hi = vaddq_s32(vmulq_n_s32(t6_hi, cospi_8_64), - vmulq_n_s32(t7_hi, cospi_24_64)); + s_lo[0] = t_lo[0]; + s_hi[0] = t_hi[0]; + s_lo[1] = t_lo[1]; + s_hi[1] = t_hi[1]; + s_lo[2] = t_lo[2]; + s_hi[2] = t_hi[2]; + s_lo[3] = t_lo[3]; + s_hi[3] = t_hi[3]; + // s4 = cospi_8_64 * x4 + cospi_24_64 * x5; + // s5 = cospi_24_64 * x4 - cospi_8_64 * x5; + butterfly_two_coeff_s32_noround(t_lo[4], t_hi[4], t_lo[5], t_hi[5], + cospi_8_64, cospi_24_64, &s_lo[4], &s_hi[4], + &s_lo[5], &s_hi[5]); - // s0 + s2 - t0_lo = vaddq_s32(s0_lo, s2_lo); - t0_hi = vaddq_s32(s0_hi, s2_hi); - // s1 + s3 - t1_lo = vaddq_s32(s1_lo, s3_lo); - t1_hi = vaddq_s32(s1_hi, s3_hi); - // s0 - s2 - t2_lo = vsubq_s32(s0_lo, s2_lo); - t2_hi = vsubq_s32(s0_hi, s2_hi); - // s1 - s3 - t3_lo = vsubq_s32(s1_lo, s3_lo); - t3_hi = vsubq_s32(s1_hi, s3_hi); - // s4 + s6 - t4_lo = vaddq_s32(s4_lo, s6_lo); - t4_hi = vaddq_s32(s4_hi, s6_hi); - // s5 + s7 - t5_lo = vaddq_s32(s5_lo, s7_lo); - t5_hi = vaddq_s32(s5_hi, s7_hi); - // s4 - s6 - t6_lo = vsubq_s32(s4_lo, s6_lo); - t6_hi = vsubq_s32(s4_hi, s6_hi); - // s5 - s7 - t7_lo = vsubq_s32(s5_lo, s7_lo); - t7_hi = vsubq_s32(s5_hi, s7_hi); + // s6 = -cospi_24_64 * x6 + cospi_8_64 * x7; + // s7 = cospi_8_64 * x6 + cospi_24_64 * x7; + butterfly_two_coeff_s32_noround(t_lo[6], t_hi[6], t_lo[7], t_hi[7], + -cospi_24_64, cospi_8_64, &s_lo[6], &s_hi[6], + &s_lo[7], &s_hi[7]); // fdct_round_shift - t4_lo = vaddq_s32(t4_lo, k__DCT_CONST_ROUNDING); - t4_hi = vaddq_s32(t4_hi, k__DCT_CONST_ROUNDING); - t5_lo = vaddq_s32(t5_lo, k__DCT_CONST_ROUNDING); - t5_hi = vaddq_s32(t5_hi, k__DCT_CONST_ROUNDING); - t6_lo = vaddq_s32(t6_lo, k__DCT_CONST_ROUNDING); - t6_hi = vaddq_s32(t6_hi, k__DCT_CONST_ROUNDING); - t7_lo = vaddq_s32(t7_lo, k__DCT_CONST_ROUNDING); - t7_hi = vaddq_s32(t7_hi, k__DCT_CONST_ROUNDING); - t4_lo = vshrq_n_s32(t4_lo, DCT_CONST_BITS); - t4_hi = vshrq_n_s32(t4_hi, DCT_CONST_BITS); - t5_lo = vshrq_n_s32(t5_lo, DCT_CONST_BITS); - t5_hi = vshrq_n_s32(t5_hi, DCT_CONST_BITS); - t6_lo = vshrq_n_s32(t6_lo, DCT_CONST_BITS); - t6_hi = vshrq_n_s32(t6_hi, DCT_CONST_BITS); - t7_lo = vshrq_n_s32(t7_lo, DCT_CONST_BITS); - t7_hi = vshrq_n_s32(t7_hi, DCT_CONST_BITS); + // s0 + s2 + t_lo[0] = vaddq_s32(s_lo[0], s_lo[2]); + t_hi[0] = vaddq_s32(s_hi[0], s_hi[2]); + // s1 + s3 + t_lo[1] = vaddq_s32(s_lo[1], s_lo[3]); + t_hi[1] = vaddq_s32(s_hi[1], s_hi[3]); + // s0 - s2 + t_lo[2] = vsubq_s32(s_lo[0], s_lo[2]); + t_hi[2] = vsubq_s32(s_hi[0], s_hi[2]); + // s1 - s3 + t_lo[3] = vsubq_s32(s_lo[1], s_lo[3]); + t_hi[3] = vsubq_s32(s_hi[1], s_hi[3]); + // s4 + s6 + t_lo[4] = vrshrq_n_s32(vaddq_s32(s_lo[4], s_lo[6]), DCT_CONST_BITS); + t_hi[4] = vrshrq_n_s32(vaddq_s32(s_hi[4], s_hi[6]), DCT_CONST_BITS); + // s5 + s7 + t_lo[5] = vrshrq_n_s32(vaddq_s32(s_lo[5], s_lo[7]), DCT_CONST_BITS); + t_hi[5] = vrshrq_n_s32(vaddq_s32(s_hi[5], s_hi[7]), DCT_CONST_BITS); + // s4 - s6 + t_lo[6] = vrshrq_n_s32(vsubq_s32(s_lo[4], s_lo[6]), DCT_CONST_BITS); + t_hi[6] = vrshrq_n_s32(vsubq_s32(s_hi[4], s_hi[6]), DCT_CONST_BITS); + // s5 - s7 + t_lo[7] = vrshrq_n_s32(vsubq_s32(s_lo[5], s_lo[7]), DCT_CONST_BITS); + t_hi[7] = vrshrq_n_s32(vsubq_s32(s_hi[5], s_hi[7]), DCT_CONST_BITS); // stage 3 // cospi_16_64 * (x2 + x3) - s2_lo = vmulq_n_s32(vaddq_s32(t2_lo, t3_lo), cospi_16_64); - s2_hi = vmulq_n_s32(vaddq_s32(t2_hi, t3_hi), cospi_16_64); // cospi_16_64 * (x2 - x3) - s3_lo = vmulq_n_s32(vsubq_s32(t2_lo, t3_lo), cospi_16_64); - s3_hi = vmulq_n_s32(vsubq_s32(t2_hi, t3_hi), cospi_16_64); + butterfly_one_coeff_s32_noround(t_lo[2], t_hi[2], t_lo[3], t_hi[3], + cospi_16_64, &s_lo[2], &s_hi[2], &s_lo[3], + &s_hi[3]); + // cospi_16_64 * (x6 + x7) - s6_lo = vmulq_n_s32(vaddq_s32(t6_lo, t7_lo), cospi_16_64); - s6_hi = vmulq_n_s32(vaddq_s32(t6_hi, t7_hi), cospi_16_64); // cospi_16_64 * (x2 - x3) - s7_lo = vmulq_n_s32(vsubq_s32(t6_lo, t7_lo), cospi_16_64); - s7_hi = vmulq_n_s32(vsubq_s32(t6_hi, t7_hi), cospi_16_64); + butterfly_one_coeff_s32_noround(t_lo[6], t_hi[6], t_lo[7], t_hi[7], + cospi_16_64, &s_lo[6], &s_hi[6], &s_lo[7], + &s_hi[7]); // final fdct_round_shift - t2_lo = vaddq_s32(s2_lo, k__DCT_CONST_ROUNDING); - t2_hi = vaddq_s32(s2_hi, k__DCT_CONST_ROUNDING); - t3_lo = vaddq_s32(s3_lo, k__DCT_CONST_ROUNDING); - t3_hi = vaddq_s32(s3_hi, k__DCT_CONST_ROUNDING); - t6_lo = vaddq_s32(s6_lo, k__DCT_CONST_ROUNDING); - t6_hi = vaddq_s32(s6_hi, k__DCT_CONST_ROUNDING); - t7_lo = vaddq_s32(s7_lo, k__DCT_CONST_ROUNDING); - t7_hi = vaddq_s32(s7_hi, k__DCT_CONST_ROUNDING); - - x2_lo = vshrn_n_s32(t2_lo, DCT_CONST_BITS); - x2_hi = vshrn_n_s32(t2_hi, DCT_CONST_BITS); - x3_lo = vshrn_n_s32(t3_lo, DCT_CONST_BITS); - x3_hi = vshrn_n_s32(t3_hi, DCT_CONST_BITS); - x6_lo = vshrn_n_s32(t6_lo, DCT_CONST_BITS); - x6_hi = vshrn_n_s32(t6_hi, DCT_CONST_BITS); - x7_lo = vshrn_n_s32(t7_lo, DCT_CONST_BITS); - x7_hi = vshrn_n_s32(t7_hi, DCT_CONST_BITS); + x_lo[2] = vrshrn_n_s32(s_lo[2], DCT_CONST_BITS); + x_hi[2] = vrshrn_n_s32(s_hi[2], DCT_CONST_BITS); + x_lo[3] = vrshrn_n_s32(s_lo[3], DCT_CONST_BITS); + x_hi[3] = vrshrn_n_s32(s_hi[3], DCT_CONST_BITS); + x_lo[6] = vrshrn_n_s32(s_lo[6], DCT_CONST_BITS); + x_hi[6] = vrshrn_n_s32(s_hi[6], DCT_CONST_BITS); + x_lo[7] = vrshrn_n_s32(s_lo[7], DCT_CONST_BITS); + x_hi[7] = vrshrn_n_s32(s_hi[7], DCT_CONST_BITS); // x0, x1, x4, x5 narrow down to 16-bits directly - x0_lo = vmovn_s32(t0_lo); - x0_hi = vmovn_s32(t0_hi); - x1_lo = vmovn_s32(t1_lo); - x1_hi = vmovn_s32(t1_hi); - x4_lo = vmovn_s32(t4_lo); - x4_hi = vmovn_s32(t4_hi); - x5_lo = vmovn_s32(t5_lo); - x5_hi = vmovn_s32(t5_hi); + x_lo[0] = vmovn_s32(t_lo[0]); + x_hi[0] = vmovn_s32(t_hi[0]); + x_lo[1] = vmovn_s32(t_lo[1]); + x_hi[1] = vmovn_s32(t_hi[1]); + x_lo[4] = vmovn_s32(t_lo[4]); + x_hi[4] = vmovn_s32(t_hi[4]); + x_lo[5] = vmovn_s32(t_lo[5]); + x_hi[5] = vmovn_s32(t_hi[5]); - in[0] = vcombine_s16(x0_lo, x0_hi); - in[1] = vnegq_s16(vcombine_s16(x4_lo, x4_hi)); - in[2] = vcombine_s16(x6_lo, x6_hi); - in[3] = vnegq_s16(vcombine_s16(x2_lo, x2_hi)); - in[4] = vcombine_s16(x3_lo, x3_hi); - in[5] = vnegq_s16(vcombine_s16(x7_lo, x7_hi)); - in[6] = vcombine_s16(x5_lo, x5_hi); - in[7] = vnegq_s16(vcombine_s16(x1_lo, x1_hi)); + in[0] = vcombine_s16(x_lo[0], x_hi[0]); + in[1] = vnegq_s16(vcombine_s16(x_lo[4], x_hi[4])); + in[2] = vcombine_s16(x_lo[6], x_hi[6]); + in[3] = vnegq_s16(vcombine_s16(x_lo[2], x_hi[2])); + in[4] = vcombine_s16(x_lo[3], x_hi[3]); + in[5] = vnegq_s16(vcombine_s16(x_lo[7], x_hi[7])); + in[6] = vcombine_s16(x_lo[5], x_hi[5]); + in[7] = vnegq_s16(vcombine_s16(x_lo[1], x_hi[1])); transpose_s16_8x8(&in[0], &in[1], &in[2], &in[3], &in[4], &in[5], &in[6], &in[7]); @@ -488,13 +388,15 @@ void vp9_fht8x8_neon(const int16_t *input, tran_low_t *output, int stride, case ADST_DCT: load_buffer_8x8(input, in, stride); fadst8x8_neon(in); - vpx_fdct8x8_pass1_neon(in); + // pass1 variant is not accurate enough + vpx_fdct8x8_pass2_neon(in); right_shift_8x8(in, 1); write_buffer_8x8(output, in, 8); break; case DCT_ADST: load_buffer_8x8(input, in, stride); - vpx_fdct8x8_pass1_neon(in); + // pass1 variant is not accurate enough + vpx_fdct8x8_pass2_neon(in); fadst8x8_neon(in); right_shift_8x8(in, 1); write_buffer_8x8(output, in, 8); @@ -547,7 +449,6 @@ static void fdct16_8col(int16x8_t *in) { int16x8_t i[8], s1[8], s2[8], s3[8], t[8]; int16x4_t t_lo[8], t_hi[8]; int32x4_t u_lo[8], u_hi[8]; - const int32x4_t k__DCT_CONST_ROUNDING = vdupq_n_s32(DCT_CONST_ROUNDING); // stage 1 i[0] = vaddq_s16(in[0], in[15]); @@ -559,7 +460,8 @@ static void fdct16_8col(int16x8_t *in) { i[6] = vaddq_s16(in[6], in[9]); i[7] = vaddq_s16(in[7], in[8]); - vpx_fdct8x8_pass1_neon(i); + // pass1 variant is not accurate enough + vpx_fdct8x8_pass2_neon(i); transpose_s16_8x8(&i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6], &i[7]); // step 2 @@ -595,23 +497,14 @@ static void fdct16_8col(int16x8_t *in) { u_lo[5] = vmull_n_s16(t_lo[5], cospi_16_64); u_hi[5] = vmull_n_s16(t_hi[5], cospi_16_64); - u_lo[2] = vaddq_s32(u_lo[2], k__DCT_CONST_ROUNDING); - u_hi[2] = vaddq_s32(u_hi[2], k__DCT_CONST_ROUNDING); - u_lo[3] = vaddq_s32(u_lo[3], k__DCT_CONST_ROUNDING); - u_hi[3] = vaddq_s32(u_hi[3], k__DCT_CONST_ROUNDING); - u_lo[4] = vaddq_s32(u_lo[4], k__DCT_CONST_ROUNDING); - u_hi[4] = vaddq_s32(u_hi[4], k__DCT_CONST_ROUNDING); - u_lo[5] = vaddq_s32(u_lo[5], k__DCT_CONST_ROUNDING); - u_hi[5] = vaddq_s32(u_hi[5], k__DCT_CONST_ROUNDING); - - t_lo[2] = vshrn_n_s32(u_lo[2], DCT_CONST_BITS); - t_hi[2] = vshrn_n_s32(u_hi[2], DCT_CONST_BITS); - t_lo[3] = vshrn_n_s32(u_lo[3], DCT_CONST_BITS); - t_hi[3] = vshrn_n_s32(u_hi[3], DCT_CONST_BITS); - t_lo[4] = vshrn_n_s32(u_lo[4], DCT_CONST_BITS); - t_hi[4] = vshrn_n_s32(u_hi[4], DCT_CONST_BITS); - t_lo[5] = vshrn_n_s32(u_lo[5], DCT_CONST_BITS); - t_hi[5] = vshrn_n_s32(u_hi[5], DCT_CONST_BITS); + t_lo[2] = vrshrn_n_s32(u_lo[2], DCT_CONST_BITS); + t_hi[2] = vrshrn_n_s32(u_hi[2], DCT_CONST_BITS); + t_lo[3] = vrshrn_n_s32(u_lo[3], DCT_CONST_BITS); + t_hi[3] = vrshrn_n_s32(u_hi[3], DCT_CONST_BITS); + t_lo[4] = vrshrn_n_s32(u_lo[4], DCT_CONST_BITS); + t_hi[4] = vrshrn_n_s32(u_hi[4], DCT_CONST_BITS); + t_lo[5] = vrshrn_n_s32(u_lo[5], DCT_CONST_BITS); + t_hi[5] = vrshrn_n_s32(u_hi[5], DCT_CONST_BITS); s2[2] = vcombine_s16(t_lo[2], t_hi[2]); s2[3] = vcombine_s16(t_lo[3], t_hi[3]); @@ -646,40 +539,26 @@ static void fdct16_8col(int16x8_t *in) { t_lo[7] = vget_low_s16(s3[7]); t_hi[7] = vget_high_s16(s3[7]); - u_lo[1] = vaddq_s32(vmull_n_s16(t_lo[1], -cospi_8_64), - vmull_n_s16(t_lo[6], cospi_24_64)); - u_hi[1] = vaddq_s32(vmull_n_s16(t_hi[1], -cospi_8_64), - vmull_n_s16(t_hi[6], cospi_24_64)); - u_lo[2] = vaddq_s32(vmull_n_s16(t_lo[2], cospi_24_64), - vmull_n_s16(t_lo[5], cospi_8_64)); - u_hi[2] = vaddq_s32(vmull_n_s16(t_hi[2], cospi_24_64), - vmull_n_s16(t_hi[5], cospi_8_64)); - u_lo[5] = vaddq_s32(vmull_n_s16(t_lo[2], cospi_8_64), - vmull_n_s16(t_lo[5], -cospi_24_64)); - u_hi[5] = vaddq_s32(vmull_n_s16(t_hi[2], cospi_8_64), - vmull_n_s16(t_hi[5], -cospi_24_64)); - u_lo[6] = vaddq_s32(vmull_n_s16(t_lo[1], cospi_24_64), - vmull_n_s16(t_lo[6], cospi_8_64)); - u_hi[6] = vaddq_s32(vmull_n_s16(t_hi[1], cospi_24_64), - vmull_n_s16(t_hi[6], cospi_8_64)); + // u[1] = -cospi_8_64 * t[1] + cospi_24_64 * t[6] + // u[6] = cospi_24_64 * t[1] + cospi_8_64 * t[6] + butterfly_two_coeff_s16_s32_noround(t_lo[1], t_hi[1], t_lo[6], t_hi[6], + -cospi_8_64, cospi_24_64, &u_lo[1], + &u_hi[1], &u_lo[6], &u_hi[6]); - u_lo[1] = vaddq_s32(u_lo[1], k__DCT_CONST_ROUNDING); - u_hi[1] = vaddq_s32(u_hi[1], k__DCT_CONST_ROUNDING); - u_lo[2] = vaddq_s32(u_lo[2], k__DCT_CONST_ROUNDING); - u_hi[2] = vaddq_s32(u_hi[2], k__DCT_CONST_ROUNDING); - u_lo[5] = vaddq_s32(u_lo[5], k__DCT_CONST_ROUNDING); - u_hi[5] = vaddq_s32(u_hi[5], k__DCT_CONST_ROUNDING); - u_lo[6] = vaddq_s32(u_lo[6], k__DCT_CONST_ROUNDING); - u_hi[6] = vaddq_s32(u_hi[6], k__DCT_CONST_ROUNDING); + // u[5] = -cospi_24_64 * t[5] + cospi_8_64 * t[2] + // u[2] = cospi_8_64 * t[5] + cospi_24_64 * t[2] + butterfly_two_coeff_s16_s32_noround(t_lo[5], t_hi[5], t_lo[2], t_hi[2], + -cospi_24_64, cospi_8_64, &u_lo[5], + &u_hi[5], &u_lo[2], &u_hi[2]); - t_lo[1] = vshrn_n_s32(u_lo[1], DCT_CONST_BITS); - t_hi[1] = vshrn_n_s32(u_hi[1], DCT_CONST_BITS); - t_lo[2] = vshrn_n_s32(u_lo[2], DCT_CONST_BITS); - t_hi[2] = vshrn_n_s32(u_hi[2], DCT_CONST_BITS); - t_lo[5] = vshrn_n_s32(u_lo[5], DCT_CONST_BITS); - t_hi[5] = vshrn_n_s32(u_hi[5], DCT_CONST_BITS); - t_lo[6] = vshrn_n_s32(u_lo[6], DCT_CONST_BITS); - t_hi[6] = vshrn_n_s32(u_hi[6], DCT_CONST_BITS); + t_lo[1] = vrshrn_n_s32(u_lo[1], DCT_CONST_BITS); + t_hi[1] = vrshrn_n_s32(u_hi[1], DCT_CONST_BITS); + t_lo[2] = vrshrn_n_s32(u_lo[2], DCT_CONST_BITS); + t_hi[2] = vrshrn_n_s32(u_hi[2], DCT_CONST_BITS); + t_lo[5] = vrshrn_n_s32(u_lo[5], DCT_CONST_BITS); + t_hi[5] = vrshrn_n_s32(u_hi[5], DCT_CONST_BITS); + t_lo[6] = vrshrn_n_s32(u_lo[6], DCT_CONST_BITS); + t_hi[6] = vrshrn_n_s32(u_hi[6], DCT_CONST_BITS); s2[1] = vcombine_s16(t_lo[1], t_hi[1]); s2[2] = vcombine_s16(t_lo[2], t_hi[2]); @@ -714,88 +593,47 @@ static void fdct16_8col(int16x8_t *in) { t_lo[7] = vget_low_s16(s1[7]); t_hi[7] = vget_high_s16(s1[7]); - // step1[0] * cospi_30_64 + step1[7] * cospi_2_64; - u_lo[0] = vaddq_s32(vmull_n_s16(t_lo[0], cospi_30_64), - vmull_n_s16(t_lo[7], cospi_2_64)); - u_hi[0] = vaddq_s32(vmull_n_s16(t_hi[0], cospi_30_64), - vmull_n_s16(t_hi[7], cospi_2_64)); + // u[0] = step1[7] * cospi_2_64 + step1[0] * cospi_30_64 + // u[7] = step1[7] * cospi_30_64 - step1[0] * cospi_2_64 + butterfly_two_coeff_s16_s32_noround(t_lo[7], t_hi[7], t_lo[0], t_hi[0], + cospi_2_64, cospi_30_64, &u_lo[0], + &u_hi[0], &u_lo[7], &u_hi[7]); - // step1[1] * cospi_14_64 + step1[6] * cospi_18_64; - u_lo[1] = vaddq_s32(vmull_n_s16(t_lo[1], cospi_14_64), - vmull_n_s16(t_lo[6], cospi_18_64)); - u_hi[1] = vaddq_s32(vmull_n_s16(t_hi[1], cospi_14_64), - vmull_n_s16(t_hi[6], cospi_18_64)); + // u[1] = step1[6] * cospi_18_64 + step1[1] * cospi_14_64 + // u[6] = step1[6] * cospi_14_64 - step1[1] * cospi_18_64 + butterfly_two_coeff_s16_s32_noround(t_lo[6], t_hi[6], t_lo[1], t_hi[1], + cospi_18_64, cospi_14_64, &u_lo[1], + &u_hi[1], &u_lo[6], &u_hi[6]); - // step1[2] * cospi_22_64 + step1[5] * cospi_10_64; - u_lo[2] = vaddq_s32(vmull_n_s16(t_lo[2], cospi_22_64), - vmull_n_s16(t_lo[5], cospi_10_64)); - u_hi[2] = vaddq_s32(vmull_n_s16(t_hi[2], cospi_22_64), - vmull_n_s16(t_hi[5], cospi_10_64)); + // u[2] = step1[5] * cospi_10_64 + step1[2] * cospi_22_64 + // u[5] = step1[5] * cospi_22_64 - step1[2] * cospi_10_64 + butterfly_two_coeff_s16_s32_noround(t_lo[5], t_hi[5], t_lo[2], t_hi[2], + cospi_10_64, cospi_22_64, &u_lo[2], + &u_hi[2], &u_lo[5], &u_hi[5]); - // step1[3] * cospi_6_64 + step1[4] * cospi_26_64; - u_lo[3] = vaddq_s32(vmull_n_s16(t_lo[3], cospi_6_64), - vmull_n_s16(t_lo[4], cospi_26_64)); - u_hi[3] = vaddq_s32(vmull_n_s16(t_hi[3], cospi_6_64), - vmull_n_s16(t_hi[4], cospi_26_64)); - - // step1[3] * -cospi_26_64 + step1[4] * cospi_6_64; - u_lo[4] = vaddq_s32(vmull_n_s16(t_lo[3], -cospi_26_64), - vmull_n_s16(t_lo[4], cospi_6_64)); - u_hi[4] = vaddq_s32(vmull_n_s16(t_hi[3], -cospi_26_64), - vmull_n_s16(t_hi[4], cospi_6_64)); - - // step1[2] * -cospi_10_64 + step1[5] * cospi_22_64; - u_lo[5] = vaddq_s32(vmull_n_s16(t_lo[2], -cospi_10_64), - vmull_n_s16(t_lo[5], cospi_22_64)); - u_hi[5] = vaddq_s32(vmull_n_s16(t_hi[2], -cospi_10_64), - vmull_n_s16(t_hi[5], cospi_22_64)); - - // step1[1] * -cospi_18_64 + step1[6] * cospi_14_64; - u_lo[6] = vaddq_s32(vmull_n_s16(t_lo[1], -cospi_18_64), - vmull_n_s16(t_lo[6], cospi_14_64)); - u_hi[6] = vaddq_s32(vmull_n_s16(t_hi[1], -cospi_18_64), - vmull_n_s16(t_hi[6], cospi_14_64)); - - // step1[0] * -cospi_2_64 + step1[7] * cospi_30_64; - u_lo[7] = vaddq_s32(vmull_n_s16(t_lo[0], -cospi_2_64), - vmull_n_s16(t_lo[7], cospi_30_64)); - u_hi[7] = vaddq_s32(vmull_n_s16(t_hi[0], -cospi_2_64), - vmull_n_s16(t_hi[7], cospi_30_64)); + // u[3] = step1[4] * cospi_26_64 + step1[3] * cospi_6_64 + // u[4] = step1[4] * cospi_6_64 - step1[3] * cospi_26_64 + butterfly_two_coeff_s16_s32_noround(t_lo[4], t_hi[4], t_lo[3], t_hi[3], + cospi_26_64, cospi_6_64, &u_lo[3], + &u_hi[3], &u_lo[4], &u_hi[4]); // final fdct_round_shift - u_lo[0] = vaddq_s32(u_lo[0], k__DCT_CONST_ROUNDING); - u_hi[0] = vaddq_s32(u_hi[0], k__DCT_CONST_ROUNDING); - u_lo[1] = vaddq_s32(u_lo[1], k__DCT_CONST_ROUNDING); - u_hi[1] = vaddq_s32(u_hi[1], k__DCT_CONST_ROUNDING); - u_lo[2] = vaddq_s32(u_lo[2], k__DCT_CONST_ROUNDING); - u_hi[2] = vaddq_s32(u_hi[2], k__DCT_CONST_ROUNDING); - u_lo[3] = vaddq_s32(u_lo[3], k__DCT_CONST_ROUNDING); - u_hi[3] = vaddq_s32(u_hi[3], k__DCT_CONST_ROUNDING); - u_lo[4] = vaddq_s32(u_lo[4], k__DCT_CONST_ROUNDING); - u_hi[4] = vaddq_s32(u_hi[4], k__DCT_CONST_ROUNDING); - u_lo[5] = vaddq_s32(u_lo[5], k__DCT_CONST_ROUNDING); - u_hi[5] = vaddq_s32(u_hi[5], k__DCT_CONST_ROUNDING); - u_lo[6] = vaddq_s32(u_lo[6], k__DCT_CONST_ROUNDING); - u_hi[6] = vaddq_s32(u_hi[6], k__DCT_CONST_ROUNDING); - u_lo[7] = vaddq_s32(u_lo[7], k__DCT_CONST_ROUNDING); - u_hi[7] = vaddq_s32(u_hi[7], k__DCT_CONST_ROUNDING); - - t_lo[0] = vshrn_n_s32(u_lo[0], DCT_CONST_BITS); - t_hi[0] = vshrn_n_s32(u_hi[0], DCT_CONST_BITS); - t_lo[1] = vshrn_n_s32(u_lo[1], DCT_CONST_BITS); - t_hi[1] = vshrn_n_s32(u_hi[1], DCT_CONST_BITS); - t_lo[2] = vshrn_n_s32(u_lo[2], DCT_CONST_BITS); - t_hi[2] = vshrn_n_s32(u_hi[2], DCT_CONST_BITS); - t_lo[3] = vshrn_n_s32(u_lo[3], DCT_CONST_BITS); - t_hi[3] = vshrn_n_s32(u_hi[3], DCT_CONST_BITS); - t_lo[4] = vshrn_n_s32(u_lo[4], DCT_CONST_BITS); - t_hi[4] = vshrn_n_s32(u_hi[4], DCT_CONST_BITS); - t_lo[5] = vshrn_n_s32(u_lo[5], DCT_CONST_BITS); - t_hi[5] = vshrn_n_s32(u_hi[5], DCT_CONST_BITS); - t_lo[6] = vshrn_n_s32(u_lo[6], DCT_CONST_BITS); - t_hi[6] = vshrn_n_s32(u_hi[6], DCT_CONST_BITS); - t_lo[7] = vshrn_n_s32(u_lo[7], DCT_CONST_BITS); - t_hi[7] = vshrn_n_s32(u_hi[7], DCT_CONST_BITS); + t_lo[0] = vrshrn_n_s32(u_lo[0], DCT_CONST_BITS); + t_hi[0] = vrshrn_n_s32(u_hi[0], DCT_CONST_BITS); + t_lo[1] = vrshrn_n_s32(u_lo[1], DCT_CONST_BITS); + t_hi[1] = vrshrn_n_s32(u_hi[1], DCT_CONST_BITS); + t_lo[2] = vrshrn_n_s32(u_lo[2], DCT_CONST_BITS); + t_hi[2] = vrshrn_n_s32(u_hi[2], DCT_CONST_BITS); + t_lo[3] = vrshrn_n_s32(u_lo[3], DCT_CONST_BITS); + t_hi[3] = vrshrn_n_s32(u_hi[3], DCT_CONST_BITS); + t_lo[4] = vrshrn_n_s32(u_lo[4], DCT_CONST_BITS); + t_hi[4] = vrshrn_n_s32(u_hi[4], DCT_CONST_BITS); + t_lo[5] = vrshrn_n_s32(u_lo[5], DCT_CONST_BITS); + t_hi[5] = vrshrn_n_s32(u_hi[5], DCT_CONST_BITS); + t_lo[6] = vrshrn_n_s32(u_lo[6], DCT_CONST_BITS); + t_hi[6] = vrshrn_n_s32(u_hi[6], DCT_CONST_BITS); + t_lo[7] = vrshrn_n_s32(u_lo[7], DCT_CONST_BITS); + t_hi[7] = vrshrn_n_s32(u_hi[7], DCT_CONST_BITS); in[0] = i[0]; in[2] = i[1]; @@ -820,7 +658,6 @@ static void fadst16_8col(int16x8_t *in) { int16x4_t x_lo[16], x_hi[16]; int32x4_t s_lo[16], s_hi[16]; int32x4_t t_lo[16], t_hi[16]; - const int32x4_t k__DCT_CONST_ROUNDING = vdupq_n_s32(DCT_CONST_ROUNDING); x_lo[0] = vget_low_s16(in[15]); x_hi[0] = vget_high_s16(in[15]); @@ -857,185 +694,79 @@ static void fadst16_8col(int16x8_t *in) { // stage 1 // s0 = cospi_1_64 * x0 + cospi_31_64 * x1; - s_lo[0] = vaddq_s32(vmull_n_s16(x_lo[0], cospi_1_64), - vmull_n_s16(x_lo[1], cospi_31_64)); - s_hi[0] = vaddq_s32(vmull_n_s16(x_hi[0], cospi_1_64), - vmull_n_s16(x_hi[1], cospi_31_64)); // s1 = cospi_31_64 * x0 - cospi_1_64 * x1; - s_lo[1] = vsubq_s32(vmull_n_s16(x_lo[0], cospi_31_64), - vmull_n_s16(x_lo[1], cospi_1_64)); - s_hi[1] = vsubq_s32(vmull_n_s16(x_hi[0], cospi_31_64), - vmull_n_s16(x_hi[1], cospi_1_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[0], x_hi[0], x_lo[1], x_hi[1], + cospi_1_64, cospi_31_64, &s_lo[0], + &s_hi[0], &s_lo[1], &s_hi[1]); // s2 = cospi_5_64 * x2 + cospi_27_64 * x3; - s_lo[2] = vaddq_s32(vmull_n_s16(x_lo[2], cospi_5_64), - vmull_n_s16(x_lo[3], cospi_27_64)); - s_hi[2] = vaddq_s32(vmull_n_s16(x_hi[2], cospi_5_64), - vmull_n_s16(x_hi[3], cospi_27_64)); // s3 = cospi_27_64 * x2 - cospi_5_64 * x3; - s_lo[3] = vsubq_s32(vmull_n_s16(x_lo[2], cospi_27_64), - vmull_n_s16(x_lo[3], cospi_5_64)); - s_hi[3] = vsubq_s32(vmull_n_s16(x_hi[2], cospi_27_64), - vmull_n_s16(x_hi[3], cospi_5_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[2], x_hi[2], x_lo[3], x_hi[3], + cospi_5_64, cospi_27_64, &s_lo[2], + &s_hi[2], &s_lo[3], &s_hi[3]); // s4 = cospi_9_64 * x4 + cospi_23_64 * x5; - s_lo[4] = vaddq_s32(vmull_n_s16(x_lo[4], cospi_9_64), - vmull_n_s16(x_lo[5], cospi_23_64)); - s_hi[4] = vaddq_s32(vmull_n_s16(x_hi[4], cospi_9_64), - vmull_n_s16(x_hi[5], cospi_23_64)); // s5 = cospi_23_64 * x4 - cospi_9_64 * x5; - s_lo[5] = vsubq_s32(vmull_n_s16(x_lo[4], cospi_23_64), - vmull_n_s16(x_lo[5], cospi_9_64)); - s_hi[5] = vsubq_s32(vmull_n_s16(x_hi[4], cospi_23_64), - vmull_n_s16(x_hi[5], cospi_9_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[4], x_hi[4], x_lo[5], x_hi[5], + cospi_9_64, cospi_23_64, &s_lo[4], + &s_hi[4], &s_lo[5], &s_hi[5]); // s6 = cospi_13_64 * x6 + cospi_19_64 * x7; - s_lo[6] = vaddq_s32(vmull_n_s16(x_lo[6], cospi_13_64), - vmull_n_s16(x_lo[7], cospi_19_64)); - s_hi[6] = vaddq_s32(vmull_n_s16(x_hi[6], cospi_13_64), - vmull_n_s16(x_hi[7], cospi_19_64)); // s7 = cospi_19_64 * x6 - cospi_13_64 * x7; - s_lo[7] = vsubq_s32(vmull_n_s16(x_lo[6], cospi_19_64), - vmull_n_s16(x_lo[7], cospi_13_64)); - s_hi[7] = vsubq_s32(vmull_n_s16(x_hi[6], cospi_19_64), - vmull_n_s16(x_hi[7], cospi_13_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[6], x_hi[6], x_lo[7], x_hi[7], + cospi_13_64, cospi_19_64, &s_lo[6], + &s_hi[6], &s_lo[7], &s_hi[7]); // s8 = cospi_17_64 * x8 + cospi_15_64 * x9; - s_lo[8] = vaddq_s32(vmull_n_s16(x_lo[8], cospi_17_64), - vmull_n_s16(x_lo[9], cospi_15_64)); - s_hi[8] = vaddq_s32(vmull_n_s16(x_hi[8], cospi_17_64), - vmull_n_s16(x_hi[9], cospi_15_64)); // s9 = cospi_15_64 * x8 - cospi_17_64 * x9; - s_lo[9] = vsubq_s32(vmull_n_s16(x_lo[8], cospi_15_64), - vmull_n_s16(x_lo[9], cospi_17_64)); - s_hi[9] = vsubq_s32(vmull_n_s16(x_hi[8], cospi_15_64), - vmull_n_s16(x_hi[9], cospi_17_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[8], x_hi[8], x_lo[9], x_hi[9], + cospi_17_64, cospi_15_64, &s_lo[8], + &s_hi[8], &s_lo[9], &s_hi[9]); // s10 = cospi_21_64 * x10 + cospi_11_64 * x11; - s_lo[10] = vaddq_s32(vmull_n_s16(x_lo[10], cospi_21_64), - vmull_n_s16(x_lo[11], cospi_11_64)); - s_hi[10] = vaddq_s32(vmull_n_s16(x_hi[10], cospi_21_64), - vmull_n_s16(x_hi[11], cospi_11_64)); // s11 = cospi_11_64 * x10 - cospi_21_64 * x11; - s_lo[11] = vsubq_s32(vmull_n_s16(x_lo[10], cospi_11_64), - vmull_n_s16(x_lo[11], cospi_21_64)); - s_hi[11] = vsubq_s32(vmull_n_s16(x_hi[10], cospi_11_64), - vmull_n_s16(x_hi[11], cospi_21_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[10], x_hi[10], x_lo[11], x_hi[11], + cospi_21_64, cospi_11_64, &s_lo[10], + &s_hi[10], &s_lo[11], &s_hi[11]); // s12 = cospi_25_64 * x12 + cospi_7_64 * x13; - s_lo[12] = vaddq_s32(vmull_n_s16(x_lo[12], cospi_25_64), - vmull_n_s16(x_lo[13], cospi_7_64)); - s_hi[12] = vaddq_s32(vmull_n_s16(x_hi[12], cospi_25_64), - vmull_n_s16(x_hi[13], cospi_7_64)); // s13 = cospi_7_64 * x12 - cospi_25_64 * x13; - s_lo[13] = vsubq_s32(vmull_n_s16(x_lo[12], cospi_7_64), - vmull_n_s16(x_lo[13], cospi_25_64)); - s_hi[13] = vsubq_s32(vmull_n_s16(x_hi[12], cospi_7_64), - vmull_n_s16(x_hi[13], cospi_25_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[12], x_hi[12], x_lo[13], x_hi[13], + cospi_25_64, cospi_7_64, &s_lo[12], + &s_hi[12], &s_lo[13], &s_hi[13]); // s14 = cospi_29_64 * x14 + cospi_3_64 * x15; - s_lo[14] = vaddq_s32(vmull_n_s16(x_lo[14], cospi_29_64), - vmull_n_s16(x_lo[15], cospi_3_64)); - s_hi[14] = vaddq_s32(vmull_n_s16(x_hi[14], cospi_29_64), - vmull_n_s16(x_hi[15], cospi_3_64)); // s15 = cospi_3_64 * x14 - cospi_29_64 * x15; - s_lo[15] = vsubq_s32(vmull_n_s16(x_lo[14], cospi_3_64), - vmull_n_s16(x_lo[15], cospi_29_64)); - s_hi[15] = vsubq_s32(vmull_n_s16(x_hi[14], cospi_3_64), - vmull_n_s16(x_hi[15], cospi_29_64)); + butterfly_two_coeff_s16_s32_noround(x_lo[14], x_hi[14], x_lo[15], x_hi[15], + cospi_29_64, cospi_3_64, &s_lo[14], + &s_hi[14], &s_lo[15], &s_hi[15]); // fdct_round_shift - t_lo[0] = vaddq_s32(s_lo[0], s_lo[8]); - t_hi[0] = vaddq_s32(s_hi[0], s_hi[8]); - t_lo[1] = vaddq_s32(s_lo[1], s_lo[9]); - t_hi[1] = vaddq_s32(s_hi[1], s_hi[9]); - t_lo[2] = vaddq_s32(s_lo[2], s_lo[10]); - t_hi[2] = vaddq_s32(s_hi[2], s_hi[10]); - t_lo[3] = vaddq_s32(s_lo[3], s_lo[11]); - t_hi[3] = vaddq_s32(s_hi[3], s_hi[11]); - t_lo[4] = vaddq_s32(s_lo[4], s_lo[12]); - t_hi[4] = vaddq_s32(s_hi[4], s_hi[12]); - t_lo[5] = vaddq_s32(s_lo[5], s_lo[13]); - t_hi[5] = vaddq_s32(s_hi[5], s_hi[13]); - t_lo[6] = vaddq_s32(s_lo[6], s_lo[14]); - t_hi[6] = vaddq_s32(s_hi[6], s_hi[14]); - t_lo[7] = vaddq_s32(s_lo[7], s_lo[15]); - t_hi[7] = vaddq_s32(s_hi[7], s_hi[15]); - t_lo[8] = vsubq_s32(s_lo[0], s_lo[8]); - t_hi[8] = vsubq_s32(s_hi[0], s_hi[8]); - t_lo[9] = vsubq_s32(s_lo[1], s_lo[9]); - t_hi[9] = vsubq_s32(s_hi[1], s_hi[9]); - t_lo[10] = vsubq_s32(s_lo[2], s_lo[10]); - t_hi[10] = vsubq_s32(s_hi[2], s_hi[10]); - t_lo[11] = vsubq_s32(s_lo[3], s_lo[11]); - t_hi[11] = vsubq_s32(s_hi[3], s_hi[11]); - t_lo[12] = vsubq_s32(s_lo[4], s_lo[12]); - t_hi[12] = vsubq_s32(s_hi[4], s_hi[12]); - t_lo[13] = vsubq_s32(s_lo[5], s_lo[13]); - t_hi[13] = vsubq_s32(s_hi[5], s_hi[13]); - t_lo[14] = vsubq_s32(s_lo[6], s_lo[14]); - t_hi[14] = vsubq_s32(s_hi[6], s_hi[14]); - t_lo[15] = vsubq_s32(s_lo[7], s_lo[15]); - t_hi[15] = vsubq_s32(s_hi[7], s_hi[15]); - - t_lo[0] = vaddq_s32(t_lo[0], k__DCT_CONST_ROUNDING); - t_hi[0] = vaddq_s32(t_hi[0], k__DCT_CONST_ROUNDING); - t_lo[1] = vaddq_s32(t_lo[1], k__DCT_CONST_ROUNDING); - t_hi[1] = vaddq_s32(t_hi[1], k__DCT_CONST_ROUNDING); - t_lo[2] = vaddq_s32(t_lo[2], k__DCT_CONST_ROUNDING); - t_hi[2] = vaddq_s32(t_hi[2], k__DCT_CONST_ROUNDING); - t_lo[3] = vaddq_s32(t_lo[3], k__DCT_CONST_ROUNDING); - t_hi[3] = vaddq_s32(t_hi[3], k__DCT_CONST_ROUNDING); - t_lo[4] = vaddq_s32(t_lo[4], k__DCT_CONST_ROUNDING); - t_hi[4] = vaddq_s32(t_hi[4], k__DCT_CONST_ROUNDING); - t_lo[5] = vaddq_s32(t_lo[5], k__DCT_CONST_ROUNDING); - t_hi[5] = vaddq_s32(t_hi[5], k__DCT_CONST_ROUNDING); - t_lo[6] = vaddq_s32(t_lo[6], k__DCT_CONST_ROUNDING); - t_hi[6] = vaddq_s32(t_hi[6], k__DCT_CONST_ROUNDING); - t_lo[7] = vaddq_s32(t_lo[7], k__DCT_CONST_ROUNDING); - t_hi[7] = vaddq_s32(t_hi[7], k__DCT_CONST_ROUNDING); - t_lo[8] = vaddq_s32(t_lo[8], k__DCT_CONST_ROUNDING); - t_hi[8] = vaddq_s32(t_hi[8], k__DCT_CONST_ROUNDING); - t_lo[9] = vaddq_s32(t_lo[9], k__DCT_CONST_ROUNDING); - t_hi[9] = vaddq_s32(t_hi[9], k__DCT_CONST_ROUNDING); - t_lo[10] = vaddq_s32(t_lo[10], k__DCT_CONST_ROUNDING); - t_hi[10] = vaddq_s32(t_hi[10], k__DCT_CONST_ROUNDING); - t_lo[11] = vaddq_s32(t_lo[11], k__DCT_CONST_ROUNDING); - t_hi[11] = vaddq_s32(t_hi[11], k__DCT_CONST_ROUNDING); - t_lo[12] = vaddq_s32(t_lo[12], k__DCT_CONST_ROUNDING); - t_hi[12] = vaddq_s32(t_hi[12], k__DCT_CONST_ROUNDING); - t_lo[13] = vaddq_s32(t_lo[13], k__DCT_CONST_ROUNDING); - t_hi[13] = vaddq_s32(t_hi[13], k__DCT_CONST_ROUNDING); - t_lo[14] = vaddq_s32(t_lo[14], k__DCT_CONST_ROUNDING); - t_hi[14] = vaddq_s32(t_hi[14], k__DCT_CONST_ROUNDING); - t_lo[15] = vaddq_s32(t_lo[15], k__DCT_CONST_ROUNDING); - t_hi[15] = vaddq_s32(t_hi[15], k__DCT_CONST_ROUNDING); - - t_lo[0] = vshrq_n_s32(t_lo[0], DCT_CONST_BITS); - t_hi[0] = vshrq_n_s32(t_hi[0], DCT_CONST_BITS); - t_lo[1] = vshrq_n_s32(t_lo[1], DCT_CONST_BITS); - t_hi[1] = vshrq_n_s32(t_hi[1], DCT_CONST_BITS); - t_lo[2] = vshrq_n_s32(t_lo[2], DCT_CONST_BITS); - t_hi[2] = vshrq_n_s32(t_hi[2], DCT_CONST_BITS); - t_lo[3] = vshrq_n_s32(t_lo[3], DCT_CONST_BITS); - t_hi[3] = vshrq_n_s32(t_hi[3], DCT_CONST_BITS); - t_lo[4] = vshrq_n_s32(t_lo[4], DCT_CONST_BITS); - t_hi[4] = vshrq_n_s32(t_hi[4], DCT_CONST_BITS); - t_lo[5] = vshrq_n_s32(t_lo[5], DCT_CONST_BITS); - t_hi[5] = vshrq_n_s32(t_hi[5], DCT_CONST_BITS); - t_lo[6] = vshrq_n_s32(t_lo[6], DCT_CONST_BITS); - t_hi[6] = vshrq_n_s32(t_hi[6], DCT_CONST_BITS); - t_lo[7] = vshrq_n_s32(t_lo[7], DCT_CONST_BITS); - t_hi[7] = vshrq_n_s32(t_hi[7], DCT_CONST_BITS); - t_lo[8] = vshrq_n_s32(t_lo[8], DCT_CONST_BITS); - t_hi[8] = vshrq_n_s32(t_hi[8], DCT_CONST_BITS); - t_lo[9] = vshrq_n_s32(t_lo[9], DCT_CONST_BITS); - t_hi[9] = vshrq_n_s32(t_hi[9], DCT_CONST_BITS); - t_lo[10] = vshrq_n_s32(t_lo[10], DCT_CONST_BITS); - t_hi[10] = vshrq_n_s32(t_hi[10], DCT_CONST_BITS); - t_lo[11] = vshrq_n_s32(t_lo[11], DCT_CONST_BITS); - t_hi[11] = vshrq_n_s32(t_hi[11], DCT_CONST_BITS); - t_lo[12] = vshrq_n_s32(t_lo[12], DCT_CONST_BITS); - t_hi[12] = vshrq_n_s32(t_hi[12], DCT_CONST_BITS); - t_lo[13] = vshrq_n_s32(t_lo[13], DCT_CONST_BITS); - t_hi[13] = vshrq_n_s32(t_hi[13], DCT_CONST_BITS); - t_lo[14] = vshrq_n_s32(t_lo[14], DCT_CONST_BITS); - t_hi[14] = vshrq_n_s32(t_hi[14], DCT_CONST_BITS); - t_lo[15] = vshrq_n_s32(t_lo[15], DCT_CONST_BITS); - t_hi[15] = vshrq_n_s32(t_hi[15], DCT_CONST_BITS); + t_lo[0] = vrshrq_n_s32(vaddq_s32(s_lo[0], s_lo[8]), DCT_CONST_BITS); + t_hi[0] = vrshrq_n_s32(vaddq_s32(s_hi[0], s_hi[8]), DCT_CONST_BITS); + t_lo[1] = vrshrq_n_s32(vaddq_s32(s_lo[1], s_lo[9]), DCT_CONST_BITS); + t_hi[1] = vrshrq_n_s32(vaddq_s32(s_hi[1], s_hi[9]), DCT_CONST_BITS); + t_lo[2] = vrshrq_n_s32(vaddq_s32(s_lo[2], s_lo[10]), DCT_CONST_BITS); + t_hi[2] = vrshrq_n_s32(vaddq_s32(s_hi[2], s_hi[10]), DCT_CONST_BITS); + t_lo[3] = vrshrq_n_s32(vaddq_s32(s_lo[3], s_lo[11]), DCT_CONST_BITS); + t_hi[3] = vrshrq_n_s32(vaddq_s32(s_hi[3], s_hi[11]), DCT_CONST_BITS); + t_lo[4] = vrshrq_n_s32(vaddq_s32(s_lo[4], s_lo[12]), DCT_CONST_BITS); + t_hi[4] = vrshrq_n_s32(vaddq_s32(s_hi[4], s_hi[12]), DCT_CONST_BITS); + t_lo[5] = vrshrq_n_s32(vaddq_s32(s_lo[5], s_lo[13]), DCT_CONST_BITS); + t_hi[5] = vrshrq_n_s32(vaddq_s32(s_hi[5], s_hi[13]), DCT_CONST_BITS); + t_lo[6] = vrshrq_n_s32(vaddq_s32(s_lo[6], s_lo[14]), DCT_CONST_BITS); + t_hi[6] = vrshrq_n_s32(vaddq_s32(s_hi[6], s_hi[14]), DCT_CONST_BITS); + t_lo[7] = vrshrq_n_s32(vaddq_s32(s_lo[7], s_lo[15]), DCT_CONST_BITS); + t_hi[7] = vrshrq_n_s32(vaddq_s32(s_hi[7], s_hi[15]), DCT_CONST_BITS); + t_lo[8] = vrshrq_n_s32(vsubq_s32(s_lo[0], s_lo[8]), DCT_CONST_BITS); + t_hi[8] = vrshrq_n_s32(vsubq_s32(s_hi[0], s_hi[8]), DCT_CONST_BITS); + t_lo[9] = vrshrq_n_s32(vsubq_s32(s_lo[1], s_lo[9]), DCT_CONST_BITS); + t_hi[9] = vrshrq_n_s32(vsubq_s32(s_hi[1], s_hi[9]), DCT_CONST_BITS); + t_lo[10] = vrshrq_n_s32(vsubq_s32(s_lo[2], s_lo[10]), DCT_CONST_BITS); + t_hi[10] = vrshrq_n_s32(vsubq_s32(s_hi[2], s_hi[10]), DCT_CONST_BITS); + t_lo[11] = vrshrq_n_s32(vsubq_s32(s_lo[3], s_lo[11]), DCT_CONST_BITS); + t_hi[11] = vrshrq_n_s32(vsubq_s32(s_hi[3], s_hi[11]), DCT_CONST_BITS); + t_lo[12] = vrshrq_n_s32(vsubq_s32(s_lo[4], s_lo[12]), DCT_CONST_BITS); + t_hi[12] = vrshrq_n_s32(vsubq_s32(s_hi[4], s_hi[12]), DCT_CONST_BITS); + t_lo[13] = vrshrq_n_s32(vsubq_s32(s_lo[5], s_lo[13]), DCT_CONST_BITS); + t_hi[13] = vrshrq_n_s32(vsubq_s32(s_hi[5], s_hi[13]), DCT_CONST_BITS); + t_lo[14] = vrshrq_n_s32(vsubq_s32(s_lo[6], s_lo[14]), DCT_CONST_BITS); + t_hi[14] = vrshrq_n_s32(vsubq_s32(s_hi[6], s_hi[14]), DCT_CONST_BITS); + t_lo[15] = vrshrq_n_s32(vsubq_s32(s_lo[7], s_lo[15]), DCT_CONST_BITS); + t_hi[15] = vrshrq_n_s32(vsubq_s32(s_hi[7], s_hi[15]), DCT_CONST_BITS); // stage 2 s_lo[0] = t_lo[0]; @@ -1055,45 +786,25 @@ static void fadst16_8col(int16x8_t *in) { s_lo[7] = t_lo[7]; s_hi[7] = t_hi[7]; // s8 = x8 * cospi_4_64 + x9 * cospi_28_64; - s_lo[8] = vaddq_s32(vmulq_n_s32(t_lo[8], cospi_4_64), - vmulq_n_s32(t_lo[9], cospi_28_64)); - s_hi[8] = vaddq_s32(vmulq_n_s32(t_hi[8], cospi_4_64), - vmulq_n_s32(t_hi[9], cospi_28_64)); // s9 = x8 * cospi_28_64 - x9 * cospi_4_64; - s_lo[9] = vsubq_s32(vmulq_n_s32(t_lo[8], cospi_28_64), - vmulq_n_s32(t_lo[9], cospi_4_64)); - s_hi[9] = vsubq_s32(vmulq_n_s32(t_hi[8], cospi_28_64), - vmulq_n_s32(t_hi[9], cospi_4_64)); + butterfly_two_coeff_s32_noround(t_lo[8], t_hi[8], t_lo[9], t_hi[9], + cospi_4_64, cospi_28_64, &s_lo[8], &s_hi[8], + &s_lo[9], &s_hi[9]); // s10 = x10 * cospi_20_64 + x11 * cospi_12_64; - s_lo[10] = vaddq_s32(vmulq_n_s32(t_lo[10], cospi_20_64), - vmulq_n_s32(t_lo[11], cospi_12_64)); - s_hi[10] = vaddq_s32(vmulq_n_s32(t_hi[10], cospi_20_64), - vmulq_n_s32(t_hi[11], cospi_12_64)); // s11 = x10 * cospi_12_64 - x11 * cospi_20_64; - s_lo[11] = vsubq_s32(vmulq_n_s32(t_lo[10], cospi_12_64), - vmulq_n_s32(t_lo[11], cospi_20_64)); - s_hi[11] = vsubq_s32(vmulq_n_s32(t_hi[10], cospi_12_64), - vmulq_n_s32(t_hi[11], cospi_20_64)); + butterfly_two_coeff_s32_noround(t_lo[10], t_hi[10], t_lo[11], t_hi[11], + cospi_20_64, cospi_12_64, &s_lo[10], + &s_hi[10], &s_lo[11], &s_hi[11]); // s12 = -x12 * cospi_28_64 + x13 * cospi_4_64; - s_lo[12] = vaddq_s32(vmulq_n_s32(t_lo[12], -cospi_28_64), - vmulq_n_s32(t_lo[13], cospi_4_64)); - s_hi[12] = vaddq_s32(vmulq_n_s32(t_hi[12], -cospi_28_64), - vmulq_n_s32(t_hi[13], cospi_4_64)); // s13 = x12 * cospi_4_64 + x13 * cospi_28_64; - s_lo[13] = vaddq_s32(vmulq_n_s32(t_lo[12], cospi_4_64), - vmulq_n_s32(t_lo[13], cospi_28_64)); - s_hi[13] = vaddq_s32(vmulq_n_s32(t_hi[12], cospi_4_64), - vmulq_n_s32(t_hi[13], cospi_28_64)); + butterfly_two_coeff_s32_noround(t_lo[13], t_hi[13], t_lo[12], t_hi[12], + cospi_28_64, cospi_4_64, &s_lo[13], &s_hi[13], + &s_lo[12], &s_hi[12]); // s14 = -x14 * cospi_12_64 + x15 * cospi_20_64; - s_lo[14] = vaddq_s32(vmulq_n_s32(t_lo[14], -cospi_12_64), - vmulq_n_s32(t_lo[15], cospi_20_64)); - s_hi[14] = vaddq_s32(vmulq_n_s32(t_hi[14], -cospi_12_64), - vmulq_n_s32(t_hi[15], cospi_20_64)); // s15 = x14 * cospi_20_64 + x15 * cospi_12_64; - s_lo[15] = vaddq_s32(vmulq_n_s32(t_lo[14], cospi_20_64), - vmulq_n_s32(t_lo[15], cospi_12_64)); - s_hi[15] = vaddq_s32(vmulq_n_s32(t_hi[14], cospi_20_64), - vmulq_n_s32(t_hi[15], cospi_12_64)); + butterfly_two_coeff_s32_noround(t_lo[15], t_hi[15], t_lo[14], t_hi[14], + cospi_12_64, cospi_20_64, &s_lo[15], + &s_hi[15], &s_lo[14], &s_hi[14]); // s0 + s4 t_lo[0] = vaddq_s32(s_lo[0], s_lo[4]); @@ -1144,38 +855,22 @@ static void fadst16_8col(int16x8_t *in) { t_lo[15] = vsubq_s32(s_lo[11], s_lo[15]); t_hi[15] = vsubq_s32(s_hi[11], s_hi[15]); - t_lo[8] = vaddq_s32(t_lo[8], k__DCT_CONST_ROUNDING); - t_hi[8] = vaddq_s32(t_hi[8], k__DCT_CONST_ROUNDING); - t_lo[9] = vaddq_s32(t_lo[9], k__DCT_CONST_ROUNDING); - t_hi[9] = vaddq_s32(t_hi[9], k__DCT_CONST_ROUNDING); - t_lo[10] = vaddq_s32(t_lo[10], k__DCT_CONST_ROUNDING); - t_hi[10] = vaddq_s32(t_hi[10], k__DCT_CONST_ROUNDING); - t_lo[11] = vaddq_s32(t_lo[11], k__DCT_CONST_ROUNDING); - t_hi[11] = vaddq_s32(t_hi[11], k__DCT_CONST_ROUNDING); - t_lo[12] = vaddq_s32(t_lo[12], k__DCT_CONST_ROUNDING); - t_hi[12] = vaddq_s32(t_hi[12], k__DCT_CONST_ROUNDING); - t_lo[13] = vaddq_s32(t_lo[13], k__DCT_CONST_ROUNDING); - t_hi[13] = vaddq_s32(t_hi[13], k__DCT_CONST_ROUNDING); - t_lo[14] = vaddq_s32(t_lo[14], k__DCT_CONST_ROUNDING); - t_hi[14] = vaddq_s32(t_hi[14], k__DCT_CONST_ROUNDING); - t_lo[15] = vaddq_s32(t_lo[15], k__DCT_CONST_ROUNDING); - t_hi[15] = vaddq_s32(t_hi[15], k__DCT_CONST_ROUNDING); - t_lo[8] = vshrq_n_s32(t_lo[8], DCT_CONST_BITS); - t_hi[8] = vshrq_n_s32(t_hi[8], DCT_CONST_BITS); - t_lo[9] = vshrq_n_s32(t_lo[9], DCT_CONST_BITS); - t_hi[9] = vshrq_n_s32(t_hi[9], DCT_CONST_BITS); - t_lo[10] = vshrq_n_s32(t_lo[10], DCT_CONST_BITS); - t_hi[10] = vshrq_n_s32(t_hi[10], DCT_CONST_BITS); - t_lo[11] = vshrq_n_s32(t_lo[11], DCT_CONST_BITS); - t_hi[11] = vshrq_n_s32(t_hi[11], DCT_CONST_BITS); - t_lo[12] = vshrq_n_s32(t_lo[12], DCT_CONST_BITS); - t_hi[12] = vshrq_n_s32(t_hi[12], DCT_CONST_BITS); - t_lo[13] = vshrq_n_s32(t_lo[13], DCT_CONST_BITS); - t_hi[13] = vshrq_n_s32(t_hi[13], DCT_CONST_BITS); - t_lo[14] = vshrq_n_s32(t_lo[14], DCT_CONST_BITS); - t_hi[14] = vshrq_n_s32(t_hi[14], DCT_CONST_BITS); - t_lo[15] = vshrq_n_s32(t_lo[15], DCT_CONST_BITS); - t_hi[15] = vshrq_n_s32(t_hi[15], DCT_CONST_BITS); + t_lo[8] = vrshrq_n_s32(t_lo[8], DCT_CONST_BITS); + t_hi[8] = vrshrq_n_s32(t_hi[8], DCT_CONST_BITS); + t_lo[9] = vrshrq_n_s32(t_lo[9], DCT_CONST_BITS); + t_hi[9] = vrshrq_n_s32(t_hi[9], DCT_CONST_BITS); + t_lo[10] = vrshrq_n_s32(t_lo[10], DCT_CONST_BITS); + t_hi[10] = vrshrq_n_s32(t_hi[10], DCT_CONST_BITS); + t_lo[11] = vrshrq_n_s32(t_lo[11], DCT_CONST_BITS); + t_hi[11] = vrshrq_n_s32(t_hi[11], DCT_CONST_BITS); + t_lo[12] = vrshrq_n_s32(t_lo[12], DCT_CONST_BITS); + t_hi[12] = vrshrq_n_s32(t_hi[12], DCT_CONST_BITS); + t_lo[13] = vrshrq_n_s32(t_lo[13], DCT_CONST_BITS); + t_hi[13] = vrshrq_n_s32(t_hi[13], DCT_CONST_BITS); + t_lo[14] = vrshrq_n_s32(t_lo[14], DCT_CONST_BITS); + t_hi[14] = vrshrq_n_s32(t_hi[14], DCT_CONST_BITS); + t_lo[15] = vrshrq_n_s32(t_lo[15], DCT_CONST_BITS); + t_hi[15] = vrshrq_n_s32(t_hi[15], DCT_CONST_BITS); // stage 3 s_lo[0] = t_lo[0]; @@ -1187,25 +882,15 @@ static void fadst16_8col(int16x8_t *in) { s_lo[3] = t_lo[3]; s_hi[3] = t_hi[3]; // s4 = x4 * cospi_8_64 + x5 * cospi_24_64; - s_lo[4] = vaddq_s32(vmulq_n_s32(t_lo[4], cospi_8_64), - vmulq_n_s32(t_lo[5], cospi_24_64)); - s_hi[4] = vaddq_s32(vmulq_n_s32(t_hi[4], cospi_8_64), - vmulq_n_s32(t_hi[5], cospi_24_64)); // s5 = x4 * cospi_24_64 - x5 * cospi_8_64; - s_lo[5] = vaddq_s32(vmulq_n_s32(t_lo[4], cospi_24_64), - vmulq_n_s32(t_lo[5], -cospi_8_64)); - s_hi[5] = vaddq_s32(vmulq_n_s32(t_hi[4], cospi_24_64), - vmulq_n_s32(t_hi[5], -cospi_8_64)); + butterfly_two_coeff_s32_noround(t_lo[4], t_hi[4], t_lo[5], t_hi[5], + cospi_8_64, cospi_24_64, &s_lo[4], &s_hi[4], + &s_lo[5], &s_hi[5]); // s6 = -x6 * cospi_24_64 + x7 * cospi_8_64; - s_lo[6] = vaddq_s32(vmulq_n_s32(t_lo[6], -cospi_24_64), - vmulq_n_s32(t_lo[7], cospi_8_64)); - s_hi[6] = vaddq_s32(vmulq_n_s32(t_hi[6], -cospi_24_64), - vmulq_n_s32(t_hi[7], cospi_8_64)); // s7 = x6 * cospi_8_64 + x7 * cospi_24_64; - s_lo[7] = vaddq_s32(vmulq_n_s32(t_lo[6], cospi_8_64), - vmulq_n_s32(t_lo[7], cospi_24_64)); - s_hi[7] = vaddq_s32(vmulq_n_s32(t_hi[6], cospi_8_64), - vmulq_n_s32(t_hi[7], cospi_24_64)); + butterfly_two_coeff_s32_noround(t_lo[7], t_hi[7], t_lo[6], t_hi[6], + cospi_24_64, cospi_8_64, &s_lo[7], &s_hi[7], + &s_lo[6], &s_hi[6]); s_lo[8] = t_lo[8]; s_hi[8] = t_hi[8]; s_lo[9] = t_lo[9]; @@ -1215,25 +900,15 @@ static void fadst16_8col(int16x8_t *in) { s_lo[11] = t_lo[11]; s_hi[11] = t_hi[11]; // s12 = x12 * cospi_8_64 + x13 * cospi_24_64; - s_lo[12] = vaddq_s32(vmulq_n_s32(t_lo[12], cospi_8_64), - vmulq_n_s32(t_lo[13], cospi_24_64)); - s_hi[12] = vaddq_s32(vmulq_n_s32(t_hi[12], cospi_8_64), - vmulq_n_s32(t_hi[13], cospi_24_64)); // s13 = x12 * cospi_24_64 - x13 * cospi_8_64; - s_lo[13] = vaddq_s32(vmulq_n_s32(t_lo[12], cospi_24_64), - vmulq_n_s32(t_lo[13], -cospi_8_64)); - s_hi[13] = vaddq_s32(vmulq_n_s32(t_hi[12], cospi_24_64), - vmulq_n_s32(t_hi[13], -cospi_8_64)); + butterfly_two_coeff_s32_noround(t_lo[12], t_hi[12], t_lo[13], t_hi[13], + cospi_8_64, cospi_24_64, &s_lo[12], &s_hi[12], + &s_lo[13], &s_hi[13]); // s14 = -x14 * cospi_24_64 + x15 * cospi_8_64; - s_lo[14] = vaddq_s32(vmulq_n_s32(t_lo[14], -cospi_24_64), - vmulq_n_s32(t_lo[15], cospi_8_64)); - s_hi[14] = vaddq_s32(vmulq_n_s32(t_hi[14], -cospi_24_64), - vmulq_n_s32(t_hi[15], cospi_8_64)); // s15 = x14 * cospi_8_64 + x15 * cospi_24_64; - s_lo[15] = vaddq_s32(vmulq_n_s32(t_lo[14], cospi_8_64), - vmulq_n_s32(t_lo[15], cospi_24_64)); - s_hi[15] = vaddq_s32(vmulq_n_s32(t_hi[14], cospi_8_64), - vmulq_n_s32(t_hi[15], cospi_24_64)); + butterfly_two_coeff_s32_noround(t_lo[15], t_hi[15], t_lo[14], t_hi[14], + cospi_24_64, cospi_8_64, &s_lo[15], &s_hi[15], + &s_lo[14], &s_hi[14]); // s0 + s4 t_lo[0] = vaddq_s32(s_lo[0], s_lo[2]); @@ -1284,99 +959,62 @@ static void fadst16_8col(int16x8_t *in) { t_lo[15] = vsubq_s32(s_lo[13], s_lo[15]); t_hi[15] = vsubq_s32(s_hi[13], s_hi[15]); - t_lo[4] = vaddq_s32(t_lo[4], k__DCT_CONST_ROUNDING); - t_hi[4] = vaddq_s32(t_hi[4], k__DCT_CONST_ROUNDING); - t_lo[5] = vaddq_s32(t_lo[5], k__DCT_CONST_ROUNDING); - t_hi[5] = vaddq_s32(t_hi[5], k__DCT_CONST_ROUNDING); - t_lo[6] = vaddq_s32(t_lo[6], k__DCT_CONST_ROUNDING); - t_hi[6] = vaddq_s32(t_hi[6], k__DCT_CONST_ROUNDING); - t_lo[7] = vaddq_s32(t_lo[7], k__DCT_CONST_ROUNDING); - t_hi[7] = vaddq_s32(t_hi[7], k__DCT_CONST_ROUNDING); - t_lo[12] = vaddq_s32(t_lo[12], k__DCT_CONST_ROUNDING); - t_hi[12] = vaddq_s32(t_hi[12], k__DCT_CONST_ROUNDING); - t_lo[13] = vaddq_s32(t_lo[13], k__DCT_CONST_ROUNDING); - t_hi[13] = vaddq_s32(t_hi[13], k__DCT_CONST_ROUNDING); - t_lo[14] = vaddq_s32(t_lo[14], k__DCT_CONST_ROUNDING); - t_hi[14] = vaddq_s32(t_hi[14], k__DCT_CONST_ROUNDING); - t_lo[15] = vaddq_s32(t_lo[15], k__DCT_CONST_ROUNDING); - t_hi[15] = vaddq_s32(t_hi[15], k__DCT_CONST_ROUNDING); - t_lo[4] = vshrq_n_s32(t_lo[4], DCT_CONST_BITS); - t_hi[4] = vshrq_n_s32(t_hi[4], DCT_CONST_BITS); - t_lo[5] = vshrq_n_s32(t_lo[5], DCT_CONST_BITS); - t_hi[5] = vshrq_n_s32(t_hi[5], DCT_CONST_BITS); - t_lo[6] = vshrq_n_s32(t_lo[6], DCT_CONST_BITS); - t_hi[6] = vshrq_n_s32(t_hi[6], DCT_CONST_BITS); - t_lo[7] = vshrq_n_s32(t_lo[7], DCT_CONST_BITS); - t_hi[7] = vshrq_n_s32(t_hi[7], DCT_CONST_BITS); - t_lo[12] = vshrq_n_s32(t_lo[12], DCT_CONST_BITS); - t_hi[12] = vshrq_n_s32(t_hi[12], DCT_CONST_BITS); - t_lo[13] = vshrq_n_s32(t_lo[13], DCT_CONST_BITS); - t_hi[13] = vshrq_n_s32(t_hi[13], DCT_CONST_BITS); - t_lo[14] = vshrq_n_s32(t_lo[14], DCT_CONST_BITS); - t_hi[14] = vshrq_n_s32(t_hi[14], DCT_CONST_BITS); - t_lo[15] = vshrq_n_s32(t_lo[15], DCT_CONST_BITS); - t_hi[15] = vshrq_n_s32(t_hi[15], DCT_CONST_BITS); + t_lo[4] = vrshrq_n_s32(t_lo[4], DCT_CONST_BITS); + t_hi[4] = vrshrq_n_s32(t_hi[4], DCT_CONST_BITS); + t_lo[5] = vrshrq_n_s32(t_lo[5], DCT_CONST_BITS); + t_hi[5] = vrshrq_n_s32(t_hi[5], DCT_CONST_BITS); + t_lo[6] = vrshrq_n_s32(t_lo[6], DCT_CONST_BITS); + t_hi[6] = vrshrq_n_s32(t_hi[6], DCT_CONST_BITS); + t_lo[7] = vrshrq_n_s32(t_lo[7], DCT_CONST_BITS); + t_hi[7] = vrshrq_n_s32(t_hi[7], DCT_CONST_BITS); + t_lo[12] = vrshrq_n_s32(t_lo[12], DCT_CONST_BITS); + t_hi[12] = vrshrq_n_s32(t_hi[12], DCT_CONST_BITS); + t_lo[13] = vrshrq_n_s32(t_lo[13], DCT_CONST_BITS); + t_hi[13] = vrshrq_n_s32(t_hi[13], DCT_CONST_BITS); + t_lo[14] = vrshrq_n_s32(t_lo[14], DCT_CONST_BITS); + t_hi[14] = vrshrq_n_s32(t_hi[14], DCT_CONST_BITS); + t_lo[15] = vrshrq_n_s32(t_lo[15], DCT_CONST_BITS); + t_hi[15] = vrshrq_n_s32(t_hi[15], DCT_CONST_BITS); // stage 4 // s2 = (-cospi_16_64) * (x2 + x3); - s_lo[2] = vmulq_n_s32(vaddq_s32(t_lo[2], t_lo[3]), -cospi_16_64); - s_hi[2] = vmulq_n_s32(vaddq_s32(t_hi[2], t_hi[3]), -cospi_16_64); // s3 = cospi_16_64 * (x2 - x3); - s_lo[3] = vmulq_n_s32(vsubq_s32(t_lo[2], t_lo[3]), cospi_16_64); - s_hi[3] = vmulq_n_s32(vsubq_s32(t_hi[2], t_hi[3]), cospi_16_64); + butterfly_one_coeff_s32_noround(t_lo[3], t_hi[3], t_lo[2], t_hi[2], + -cospi_16_64, &s_lo[2], &s_hi[2], &s_lo[3], + &s_hi[3]); // s6 = cospi_16_64 * (x6 + x7); - s_lo[6] = vmulq_n_s32(vaddq_s32(t_lo[6], t_lo[7]), cospi_16_64); - s_hi[6] = vmulq_n_s32(vaddq_s32(t_hi[6], t_hi[7]), cospi_16_64); // s7 = cospi_16_64 * (-x6 + x7); - s_lo[7] = vmulq_n_s32(vsubq_s32(t_lo[7], t_lo[6]), cospi_16_64); - s_hi[7] = vmulq_n_s32(vsubq_s32(t_hi[7], t_hi[6]), cospi_16_64); + butterfly_one_coeff_s32_noround(t_lo[7], t_hi[7], t_lo[6], t_hi[6], + cospi_16_64, &s_lo[6], &s_hi[6], &s_lo[7], + &s_hi[7]); // s10 = cospi_16_64 * (x10 + x11); - s_lo[10] = vmulq_n_s32(vaddq_s32(t_lo[10], t_lo[11]), cospi_16_64); - s_hi[10] = vmulq_n_s32(vaddq_s32(t_hi[10], t_hi[11]), cospi_16_64); // s11 = cospi_16_64 * (-x10 + x11); - s_lo[11] = vmulq_n_s32(vsubq_s32(t_lo[11], t_lo[10]), cospi_16_64); - s_hi[11] = vmulq_n_s32(vsubq_s32(t_hi[11], t_hi[10]), cospi_16_64); + butterfly_one_coeff_s32_noround(t_lo[11], t_hi[11], t_lo[10], t_hi[10], + cospi_16_64, &s_lo[10], &s_hi[10], &s_lo[11], + &s_hi[11]); // s14 = (-cospi_16_64) * (x14 + x15); - s_lo[14] = vmulq_n_s32(vaddq_s32(t_lo[14], t_lo[15]), -cospi_16_64); - s_hi[14] = vmulq_n_s32(vaddq_s32(t_hi[14], t_hi[15]), -cospi_16_64); // s15 = cospi_16_64 * (x14 - x15); - s_lo[15] = vmulq_n_s32(vsubq_s32(t_lo[14], t_lo[15]), cospi_16_64); - s_hi[15] = vmulq_n_s32(vsubq_s32(t_hi[14], t_hi[15]), cospi_16_64); + butterfly_one_coeff_s32_noround(t_lo[15], t_hi[15], t_lo[14], t_hi[14], + -cospi_16_64, &s_lo[14], &s_hi[14], &s_lo[15], + &s_hi[15]); // final fdct_round_shift - t_lo[2] = vaddq_s32(s_lo[2], k__DCT_CONST_ROUNDING); - t_hi[2] = vaddq_s32(s_hi[2], k__DCT_CONST_ROUNDING); - t_lo[3] = vaddq_s32(s_lo[3], k__DCT_CONST_ROUNDING); - t_hi[3] = vaddq_s32(s_hi[3], k__DCT_CONST_ROUNDING); - t_lo[6] = vaddq_s32(s_lo[6], k__DCT_CONST_ROUNDING); - t_hi[6] = vaddq_s32(s_hi[6], k__DCT_CONST_ROUNDING); - t_lo[7] = vaddq_s32(s_lo[7], k__DCT_CONST_ROUNDING); - t_hi[7] = vaddq_s32(s_hi[7], k__DCT_CONST_ROUNDING); - t_lo[10] = vaddq_s32(s_lo[10], k__DCT_CONST_ROUNDING); - t_hi[10] = vaddq_s32(s_hi[10], k__DCT_CONST_ROUNDING); - t_lo[11] = vaddq_s32(s_lo[11], k__DCT_CONST_ROUNDING); - t_hi[11] = vaddq_s32(s_hi[11], k__DCT_CONST_ROUNDING); - t_lo[14] = vaddq_s32(s_lo[14], k__DCT_CONST_ROUNDING); - t_hi[14] = vaddq_s32(s_hi[14], k__DCT_CONST_ROUNDING); - t_lo[15] = vaddq_s32(s_lo[15], k__DCT_CONST_ROUNDING); - t_hi[15] = vaddq_s32(s_hi[15], k__DCT_CONST_ROUNDING); - - x_lo[2] = vshrn_n_s32(t_lo[2], DCT_CONST_BITS); - x_hi[2] = vshrn_n_s32(t_hi[2], DCT_CONST_BITS); - x_lo[3] = vshrn_n_s32(t_lo[3], DCT_CONST_BITS); - x_hi[3] = vshrn_n_s32(t_hi[3], DCT_CONST_BITS); - x_lo[6] = vshrn_n_s32(t_lo[6], DCT_CONST_BITS); - x_hi[6] = vshrn_n_s32(t_hi[6], DCT_CONST_BITS); - x_lo[7] = vshrn_n_s32(t_lo[7], DCT_CONST_BITS); - x_hi[7] = vshrn_n_s32(t_hi[7], DCT_CONST_BITS); - x_lo[10] = vshrn_n_s32(t_lo[10], DCT_CONST_BITS); - x_hi[10] = vshrn_n_s32(t_hi[10], DCT_CONST_BITS); - x_lo[11] = vshrn_n_s32(t_lo[11], DCT_CONST_BITS); - x_hi[11] = vshrn_n_s32(t_hi[11], DCT_CONST_BITS); - x_lo[14] = vshrn_n_s32(t_lo[14], DCT_CONST_BITS); - x_hi[14] = vshrn_n_s32(t_hi[14], DCT_CONST_BITS); - x_lo[15] = vshrn_n_s32(t_lo[15], DCT_CONST_BITS); - x_hi[15] = vshrn_n_s32(t_hi[15], DCT_CONST_BITS); + x_lo[2] = vrshrn_n_s32(s_lo[2], DCT_CONST_BITS); + x_hi[2] = vrshrn_n_s32(s_hi[2], DCT_CONST_BITS); + x_lo[3] = vrshrn_n_s32(s_lo[3], DCT_CONST_BITS); + x_hi[3] = vrshrn_n_s32(s_hi[3], DCT_CONST_BITS); + x_lo[6] = vrshrn_n_s32(s_lo[6], DCT_CONST_BITS); + x_hi[6] = vrshrn_n_s32(s_hi[6], DCT_CONST_BITS); + x_lo[7] = vrshrn_n_s32(s_lo[7], DCT_CONST_BITS); + x_hi[7] = vrshrn_n_s32(s_hi[7], DCT_CONST_BITS); + x_lo[10] = vrshrn_n_s32(s_lo[10], DCT_CONST_BITS); + x_hi[10] = vrshrn_n_s32(s_hi[10], DCT_CONST_BITS); + x_lo[11] = vrshrn_n_s32(s_lo[11], DCT_CONST_BITS); + x_hi[11] = vrshrn_n_s32(s_hi[11], DCT_CONST_BITS); + x_lo[14] = vrshrn_n_s32(s_lo[14], DCT_CONST_BITS); + x_hi[14] = vrshrn_n_s32(s_hi[14], DCT_CONST_BITS); + x_lo[15] = vrshrn_n_s32(s_lo[15], DCT_CONST_BITS); + x_hi[15] = vrshrn_n_s32(s_hi[15], DCT_CONST_BITS); // x0, x1, x4, x5, x8, x9, x12, x13 narrow down to 16-bits directly x_lo[0] = vmovn_s32(t_lo[0]); @@ -1458,3 +1096,1078 @@ void vp9_fht16x16_neon(const int16_t *input, tran_low_t *output, int stride, break; } } + +#if CONFIG_VP9_HIGHBITDEPTH + +static INLINE void highbd_load_buffer_4x4(const int16_t *input, + int32x4_t *in /*[4]*/, int stride) { + // { 0, 1, 1, 1 }; + const int32x4_t nonzero_bias_a = vextq_s32(vdupq_n_s32(0), vdupq_n_s32(1), 3); + // { 1, 0, 0, 0 }; + const int32x4_t nonzero_bias_b = vextq_s32(vdupq_n_s32(1), vdupq_n_s32(0), 3); + int32x4_t mask; + + in[0] = vshll_n_s16(vld1_s16(input + 0 * stride), 4); + in[1] = vshll_n_s16(vld1_s16(input + 1 * stride), 4); + in[2] = vshll_n_s16(vld1_s16(input + 2 * stride), 4); + in[3] = vshll_n_s16(vld1_s16(input + 3 * stride), 4); + + // Copy the SSE method, use a mask to avoid an 'if' branch here to increase by + // one non-zero first elements + mask = vreinterpretq_s32_u32(vceqq_s32(in[0], nonzero_bias_a)); + in[0] = vaddq_s32(in[0], mask); + in[0] = vaddq_s32(in[0], nonzero_bias_b); +} + +static INLINE void highbd_write_buffer_4x4(tran_low_t *output, int32x4_t *res) { + const int32x4_t one = vdupq_n_s32(1); + res[0] = vshrq_n_s32(vaddq_s32(res[0], one), 2); + res[1] = vshrq_n_s32(vaddq_s32(res[1], one), 2); + res[2] = vshrq_n_s32(vaddq_s32(res[2], one), 2); + res[3] = vshrq_n_s32(vaddq_s32(res[3], one), 2); + vst1q_s32(output + 0 * 4, res[0]); + vst1q_s32(output + 1 * 4, res[1]); + vst1q_s32(output + 2 * 4, res[2]); + vst1q_s32(output + 3 * 4, res[3]); +} + +static INLINE void highbd_fadst4x4_neon(int32x4_t *in /*[4]*/) { + int32x2_t s_lo[4], s_hi[4]; + int64x2_t u_lo[4], u_hi[4], t_lo[4], t_hi[4]; + + s_lo[0] = vget_low_s32(in[0]); + s_hi[0] = vget_high_s32(in[0]); + s_lo[1] = vget_low_s32(in[1]); + s_hi[1] = vget_high_s32(in[1]); + s_lo[2] = vget_low_s32(in[2]); + s_hi[2] = vget_high_s32(in[2]); + s_lo[3] = vget_low_s32(in[3]); + s_hi[3] = vget_high_s32(in[3]); + + // t0 = s0 * sinpi_1_9 + s1 * sinpi_2_9 + s3 * sinpi_4_9 + t_lo[0] = vmull_n_s32(s_lo[0], sinpi_1_9); + t_lo[0] = vmlal_n_s32(t_lo[0], s_lo[1], sinpi_2_9); + t_lo[0] = vmlal_n_s32(t_lo[0], s_lo[3], sinpi_4_9); + t_hi[0] = vmull_n_s32(s_hi[0], sinpi_1_9); + t_hi[0] = vmlal_n_s32(t_hi[0], s_hi[1], sinpi_2_9); + t_hi[0] = vmlal_n_s32(t_hi[0], s_hi[3], sinpi_4_9); + + // t1 = (s0 + s1) * sinpi_3_9 - s3 * sinpi_3_9 + t_lo[1] = vmull_n_s32(s_lo[0], sinpi_3_9); + t_lo[1] = vmlal_n_s32(t_lo[1], s_lo[1], sinpi_3_9); + t_lo[1] = vmlsl_n_s32(t_lo[1], s_lo[3], sinpi_3_9); + t_hi[1] = vmull_n_s32(s_hi[0], sinpi_3_9); + t_hi[1] = vmlal_n_s32(t_hi[1], s_hi[1], sinpi_3_9); + t_hi[1] = vmlsl_n_s32(t_hi[1], s_hi[3], sinpi_3_9); + + // t2 = s0 * sinpi_4_9 - s1* sinpi_1_9 + s3 * sinpi_2_9 + t_lo[2] = vmull_n_s32(s_lo[0], sinpi_4_9); + t_lo[2] = vmlsl_n_s32(t_lo[2], s_lo[1], sinpi_1_9); + t_lo[2] = vmlal_n_s32(t_lo[2], s_lo[3], sinpi_2_9); + t_hi[2] = vmull_n_s32(s_hi[0], sinpi_4_9); + t_hi[2] = vmlsl_n_s32(t_hi[2], s_hi[1], sinpi_1_9); + t_hi[2] = vmlal_n_s32(t_hi[2], s_hi[3], sinpi_2_9); + + // t3 = s2 * sinpi_3_9 + t_lo[3] = vmull_n_s32(s_lo[2], sinpi_3_9); + t_hi[3] = vmull_n_s32(s_hi[2], sinpi_3_9); + + /* + * u0 = t0 + t3 + * u1 = t1 + * u2 = t2 - t3 + * u3 = t2 - t0 + t3 + */ + u_lo[0] = vaddq_s64(t_lo[0], t_lo[3]); + u_hi[0] = vaddq_s64(t_hi[0], t_hi[3]); + u_lo[1] = t_lo[1]; + u_hi[1] = t_hi[1]; + u_lo[2] = vsubq_s64(t_lo[2], t_lo[3]); + u_hi[2] = vsubq_s64(t_hi[2], t_hi[3]); + u_lo[3] = vaddq_s64(vsubq_s64(t_lo[2], t_lo[0]), t_lo[3]); + u_hi[3] = vaddq_s64(vsubq_s64(t_hi[2], t_hi[0]), t_hi[3]); + + // fdct_round_shift + in[0] = vcombine_s32(vrshrn_n_s64(u_lo[0], DCT_CONST_BITS), + vrshrn_n_s64(u_hi[0], DCT_CONST_BITS)); + in[1] = vcombine_s32(vrshrn_n_s64(u_lo[1], DCT_CONST_BITS), + vrshrn_n_s64(u_hi[1], DCT_CONST_BITS)); + in[2] = vcombine_s32(vrshrn_n_s64(u_lo[2], DCT_CONST_BITS), + vrshrn_n_s64(u_hi[2], DCT_CONST_BITS)); + in[3] = vcombine_s32(vrshrn_n_s64(u_lo[3], DCT_CONST_BITS), + vrshrn_n_s64(u_hi[3], DCT_CONST_BITS)); + + transpose_s32_4x4(&in[0], &in[1], &in[2], &in[3]); +} + +void vp9_highbd_fht4x4_neon(const int16_t *input, tran_low_t *output, + int stride, int tx_type) { + int32x4_t in[4]; + // int i; + + switch (tx_type) { + case DCT_DCT: vpx_highbd_fdct4x4_neon(input, output, stride); break; + case ADST_DCT: + highbd_load_buffer_4x4(input, in, stride); + highbd_fadst4x4_neon(in); + vpx_highbd_fdct4x4_pass1_neon(in); + highbd_write_buffer_4x4(output, in); + break; + case DCT_ADST: + highbd_load_buffer_4x4(input, in, stride); + vpx_highbd_fdct4x4_pass1_neon(in); + highbd_fadst4x4_neon(in); + highbd_write_buffer_4x4(output, in); + break; + default: + assert(tx_type == ADST_ADST); + highbd_load_buffer_4x4(input, in, stride); + highbd_fadst4x4_neon(in); + highbd_fadst4x4_neon(in); + highbd_write_buffer_4x4(output, in); + break; + } +} + +static INLINE void highbd_load_buffer_8x8(const int16_t *input, + int32x4_t *lo /*[8]*/, + int32x4_t *hi /*[8]*/, int stride) { + int16x8_t in[8]; + in[0] = vld1q_s16(input + 0 * stride); + in[1] = vld1q_s16(input + 1 * stride); + in[2] = vld1q_s16(input + 2 * stride); + in[3] = vld1q_s16(input + 3 * stride); + in[4] = vld1q_s16(input + 4 * stride); + in[5] = vld1q_s16(input + 5 * stride); + in[6] = vld1q_s16(input + 6 * stride); + in[7] = vld1q_s16(input + 7 * stride); + lo[0] = vshll_n_s16(vget_low_s16(in[0]), 2); + hi[0] = vshll_n_s16(vget_high_s16(in[0]), 2); + lo[1] = vshll_n_s16(vget_low_s16(in[1]), 2); + hi[1] = vshll_n_s16(vget_high_s16(in[1]), 2); + lo[2] = vshll_n_s16(vget_low_s16(in[2]), 2); + hi[2] = vshll_n_s16(vget_high_s16(in[2]), 2); + lo[3] = vshll_n_s16(vget_low_s16(in[3]), 2); + hi[3] = vshll_n_s16(vget_high_s16(in[3]), 2); + lo[4] = vshll_n_s16(vget_low_s16(in[4]), 2); + hi[4] = vshll_n_s16(vget_high_s16(in[4]), 2); + lo[5] = vshll_n_s16(vget_low_s16(in[5]), 2); + hi[5] = vshll_n_s16(vget_high_s16(in[5]), 2); + lo[6] = vshll_n_s16(vget_low_s16(in[6]), 2); + hi[6] = vshll_n_s16(vget_high_s16(in[6]), 2); + lo[7] = vshll_n_s16(vget_low_s16(in[7]), 2); + hi[7] = vshll_n_s16(vget_high_s16(in[7]), 2); +} + +/* right shift and rounding + * first get the sign bit (bit 15). + * If bit == 1, it's the simple case of shifting right by one bit. + * If bit == 2, it essentially computes the expression: + * + * out[j * 16 + i] = (temp_out[j] + 1 + (temp_out[j] < 0)) >> 2; + * + * for each row. + */ +static INLINE void highbd_right_shift_8x8(int32x4_t *lo, int32x4_t *hi, + const int bit) { + int32x4_t sign_lo[8], sign_hi[8]; + sign_lo[0] = vshrq_n_s32(lo[0], 31); + sign_hi[0] = vshrq_n_s32(hi[0], 31); + sign_lo[1] = vshrq_n_s32(lo[1], 31); + sign_hi[1] = vshrq_n_s32(hi[1], 31); + sign_lo[2] = vshrq_n_s32(lo[2], 31); + sign_hi[2] = vshrq_n_s32(hi[2], 31); + sign_lo[3] = vshrq_n_s32(lo[3], 31); + sign_hi[3] = vshrq_n_s32(hi[3], 31); + sign_lo[4] = vshrq_n_s32(lo[4], 31); + sign_hi[4] = vshrq_n_s32(hi[4], 31); + sign_lo[5] = vshrq_n_s32(lo[5], 31); + sign_hi[5] = vshrq_n_s32(hi[5], 31); + sign_lo[6] = vshrq_n_s32(lo[6], 31); + sign_hi[6] = vshrq_n_s32(hi[6], 31); + sign_lo[7] = vshrq_n_s32(lo[7], 31); + sign_hi[7] = vshrq_n_s32(hi[7], 31); + + if (bit == 2) { + const int32x4_t const_rounding = vdupq_n_s32(1); + lo[0] = vaddq_s32(lo[0], const_rounding); + hi[0] = vaddq_s32(hi[0], const_rounding); + lo[1] = vaddq_s32(lo[1], const_rounding); + hi[1] = vaddq_s32(hi[1], const_rounding); + lo[2] = vaddq_s32(lo[2], const_rounding); + hi[2] = vaddq_s32(hi[2], const_rounding); + lo[3] = vaddq_s32(lo[3], const_rounding); + hi[3] = vaddq_s32(hi[3], const_rounding); + lo[4] = vaddq_s32(lo[4], const_rounding); + hi[4] = vaddq_s32(hi[4], const_rounding); + lo[5] = vaddq_s32(lo[5], const_rounding); + hi[5] = vaddq_s32(hi[5], const_rounding); + lo[6] = vaddq_s32(lo[6], const_rounding); + hi[6] = vaddq_s32(hi[6], const_rounding); + lo[7] = vaddq_s32(lo[7], const_rounding); + hi[7] = vaddq_s32(hi[7], const_rounding); + } + + lo[0] = vsubq_s32(lo[0], sign_lo[0]); + hi[0] = vsubq_s32(hi[0], sign_hi[0]); + lo[1] = vsubq_s32(lo[1], sign_lo[1]); + hi[1] = vsubq_s32(hi[1], sign_hi[1]); + lo[2] = vsubq_s32(lo[2], sign_lo[2]); + hi[2] = vsubq_s32(hi[2], sign_hi[2]); + lo[3] = vsubq_s32(lo[3], sign_lo[3]); + hi[3] = vsubq_s32(hi[3], sign_hi[3]); + lo[4] = vsubq_s32(lo[4], sign_lo[4]); + hi[4] = vsubq_s32(hi[4], sign_hi[4]); + lo[5] = vsubq_s32(lo[5], sign_lo[5]); + hi[5] = vsubq_s32(hi[5], sign_hi[5]); + lo[6] = vsubq_s32(lo[6], sign_lo[6]); + hi[6] = vsubq_s32(hi[6], sign_hi[6]); + lo[7] = vsubq_s32(lo[7], sign_lo[7]); + hi[7] = vsubq_s32(hi[7], sign_hi[7]); + + if (bit == 1) { + lo[0] = vshrq_n_s32(lo[0], 1); + hi[0] = vshrq_n_s32(hi[0], 1); + lo[1] = vshrq_n_s32(lo[1], 1); + hi[1] = vshrq_n_s32(hi[1], 1); + lo[2] = vshrq_n_s32(lo[2], 1); + hi[2] = vshrq_n_s32(hi[2], 1); + lo[3] = vshrq_n_s32(lo[3], 1); + hi[3] = vshrq_n_s32(hi[3], 1); + lo[4] = vshrq_n_s32(lo[4], 1); + hi[4] = vshrq_n_s32(hi[4], 1); + lo[5] = vshrq_n_s32(lo[5], 1); + hi[5] = vshrq_n_s32(hi[5], 1); + lo[6] = vshrq_n_s32(lo[6], 1); + hi[6] = vshrq_n_s32(hi[6], 1); + lo[7] = vshrq_n_s32(lo[7], 1); + hi[7] = vshrq_n_s32(hi[7], 1); + } else { + lo[0] = vshrq_n_s32(lo[0], 2); + hi[0] = vshrq_n_s32(hi[0], 2); + lo[1] = vshrq_n_s32(lo[1], 2); + hi[1] = vshrq_n_s32(hi[1], 2); + lo[2] = vshrq_n_s32(lo[2], 2); + hi[2] = vshrq_n_s32(hi[2], 2); + lo[3] = vshrq_n_s32(lo[3], 2); + hi[3] = vshrq_n_s32(hi[3], 2); + lo[4] = vshrq_n_s32(lo[4], 2); + hi[4] = vshrq_n_s32(hi[4], 2); + lo[5] = vshrq_n_s32(lo[5], 2); + hi[5] = vshrq_n_s32(hi[5], 2); + lo[6] = vshrq_n_s32(lo[6], 2); + hi[6] = vshrq_n_s32(hi[6], 2); + lo[7] = vshrq_n_s32(lo[7], 2); + hi[7] = vshrq_n_s32(hi[7], 2); + } +} + +static INLINE void highbd_write_buffer_8x8(tran_low_t *output, int32x4_t *lo, + int32x4_t *hi, int stride) { + vst1q_s32(output + 0 * stride, lo[0]); + vst1q_s32(output + 0 * stride + 4, hi[0]); + vst1q_s32(output + 1 * stride, lo[1]); + vst1q_s32(output + 1 * stride + 4, hi[1]); + vst1q_s32(output + 2 * stride, lo[2]); + vst1q_s32(output + 2 * stride + 4, hi[2]); + vst1q_s32(output + 3 * stride, lo[3]); + vst1q_s32(output + 3 * stride + 4, hi[3]); + vst1q_s32(output + 4 * stride, lo[4]); + vst1q_s32(output + 4 * stride + 4, hi[4]); + vst1q_s32(output + 5 * stride, lo[5]); + vst1q_s32(output + 5 * stride + 4, hi[5]); + vst1q_s32(output + 6 * stride, lo[6]); + vst1q_s32(output + 6 * stride + 4, hi[6]); + vst1q_s32(output + 7 * stride, lo[7]); + vst1q_s32(output + 7 * stride + 4, hi[7]); +} + +static INLINE void highbd_fadst8x8_neon(int32x4_t *lo /*[8]*/, + int32x4_t *hi /*[8]*/) { + int32x4_t s_lo[8], s_hi[8]; + int32x4_t t_lo[8], t_hi[8]; + int32x4_t x_lo[8], x_hi[8]; + int64x2_t s64_lo[16], s64_hi[16]; + + x_lo[0] = lo[7]; + x_hi[0] = hi[7]; + x_lo[1] = lo[0]; + x_hi[1] = hi[0]; + x_lo[2] = lo[5]; + x_hi[2] = hi[5]; + x_lo[3] = lo[2]; + x_hi[3] = hi[2]; + x_lo[4] = lo[3]; + x_hi[4] = hi[3]; + x_lo[5] = lo[4]; + x_hi[5] = hi[4]; + x_lo[6] = lo[1]; + x_hi[6] = hi[1]; + x_lo[7] = lo[6]; + x_hi[7] = hi[6]; + + // stage 1 + // s0 = cospi_2_64 * x0 + cospi_30_64 * x1; + // s1 = cospi_30_64 * x0 - cospi_2_64 * x1; + butterfly_two_coeff_s32_s64_noround( + x_lo[0], x_hi[0], x_lo[1], x_hi[1], cospi_2_64, cospi_30_64, + &s64_lo[2 * 0], &s64_hi[2 * 0], &s64_lo[2 * 1], &s64_hi[2 * 1]); + // s2 = cospi_10_64 * x2 + cospi_22_64 * x3; + // s3 = cospi_22_64 * x2 - cospi_10_64 * x3; + butterfly_two_coeff_s32_s64_noround( + x_lo[2], x_hi[2], x_lo[3], x_hi[3], cospi_10_64, cospi_22_64, + &s64_lo[2 * 2], &s64_hi[2 * 2], &s64_lo[2 * 3], &s64_hi[2 * 3]); + + // s4 = cospi_18_64 * x4 + cospi_14_64 * x5; + // s5 = cospi_14_64 * x4 - cospi_18_64 * x5; + butterfly_two_coeff_s32_s64_noround( + x_lo[4], x_hi[4], x_lo[5], x_hi[5], cospi_18_64, cospi_14_64, + &s64_lo[2 * 4], &s64_hi[2 * 4], &s64_lo[2 * 5], &s64_hi[2 * 5]); + + // s6 = cospi_26_64 * x6 + cospi_6_64 * x7; + // s7 = cospi_6_64 * x6 - cospi_26_64 * x7; + butterfly_two_coeff_s32_s64_noround( + x_lo[6], x_hi[6], x_lo[7], x_hi[7], cospi_26_64, cospi_6_64, + &s64_lo[2 * 6], &s64_hi[2 * 6], &s64_lo[2 * 7], &s64_hi[2 * 7]); + + // fdct_round_shift, indices are doubled + t_lo[0] = add_s64_round_narrow(&s64_lo[2 * 0], &s64_lo[2 * 4]); + t_hi[0] = add_s64_round_narrow(&s64_hi[2 * 0], &s64_hi[2 * 4]); + t_lo[1] = add_s64_round_narrow(&s64_lo[2 * 1], &s64_lo[2 * 5]); + t_hi[1] = add_s64_round_narrow(&s64_hi[2 * 1], &s64_hi[2 * 5]); + t_lo[2] = add_s64_round_narrow(&s64_lo[2 * 2], &s64_lo[2 * 6]); + t_hi[2] = add_s64_round_narrow(&s64_hi[2 * 2], &s64_hi[2 * 6]); + t_lo[3] = add_s64_round_narrow(&s64_lo[2 * 3], &s64_lo[2 * 7]); + t_hi[3] = add_s64_round_narrow(&s64_hi[2 * 3], &s64_hi[2 * 7]); + t_lo[4] = sub_s64_round_narrow(&s64_lo[2 * 0], &s64_lo[2 * 4]); + t_hi[4] = sub_s64_round_narrow(&s64_hi[2 * 0], &s64_hi[2 * 4]); + t_lo[5] = sub_s64_round_narrow(&s64_lo[2 * 1], &s64_lo[2 * 5]); + t_hi[5] = sub_s64_round_narrow(&s64_hi[2 * 1], &s64_hi[2 * 5]); + t_lo[6] = sub_s64_round_narrow(&s64_lo[2 * 2], &s64_lo[2 * 6]); + t_hi[6] = sub_s64_round_narrow(&s64_hi[2 * 2], &s64_hi[2 * 6]); + t_lo[7] = sub_s64_round_narrow(&s64_lo[2 * 3], &s64_lo[2 * 7]); + t_hi[7] = sub_s64_round_narrow(&s64_hi[2 * 3], &s64_hi[2 * 7]); + + // stage 2 + s_lo[0] = t_lo[0]; + s_hi[0] = t_hi[0]; + s_lo[1] = t_lo[1]; + s_hi[1] = t_hi[1]; + s_lo[2] = t_lo[2]; + s_hi[2] = t_hi[2]; + s_lo[3] = t_lo[3]; + s_hi[3] = t_hi[3]; + // s4 = cospi_8_64 * x4 + cospi_24_64 * x5; + // s5 = cospi_24_64 * x4 - cospi_8_64 * x5; + butterfly_two_coeff_s32_s64_noround( + t_lo[4], t_hi[4], t_lo[5], t_hi[5], cospi_8_64, cospi_24_64, + &s64_lo[2 * 4], &s64_hi[2 * 4], &s64_lo[2 * 5], &s64_hi[2 * 5]); + + // s6 = -cospi_24_64 * x6 + cospi_8_64 * x7; + // s7 = cospi_8_64 * x6 + cospi_24_64 * x7; + butterfly_two_coeff_s32_s64_noround( + t_lo[6], t_hi[6], t_lo[7], t_hi[7], -cospi_24_64, cospi_8_64, + &s64_lo[2 * 6], &s64_hi[2 * 6], &s64_lo[2 * 7], &s64_hi[2 * 7]); + + // fdct_round_shift + // s0 + s2 + t_lo[0] = add_s32_s64_narrow(s_lo[0], s_lo[2]); + t_hi[0] = add_s32_s64_narrow(s_hi[0], s_hi[2]); + // s0 - s2 + t_lo[2] = sub_s32_s64_narrow(s_lo[0], s_lo[2]); + t_hi[2] = sub_s32_s64_narrow(s_hi[0], s_hi[2]); + + // s1 + s3 + t_lo[1] = add_s32_s64_narrow(s_lo[1], s_lo[3]); + t_hi[1] = add_s32_s64_narrow(s_hi[1], s_hi[3]); + // s1 - s3 + t_lo[3] = sub_s32_s64_narrow(s_lo[1], s_lo[3]); + t_hi[3] = sub_s32_s64_narrow(s_hi[1], s_hi[3]); + + // s4 + s6 + t_lo[4] = add_s64_round_narrow(&s64_lo[2 * 4], &s64_lo[2 * 6]); + t_hi[4] = add_s64_round_narrow(&s64_hi[2 * 4], &s64_hi[2 * 6]); + // s4 - s6 + t_lo[6] = sub_s64_round_narrow(&s64_lo[2 * 4], &s64_lo[2 * 6]); + t_hi[6] = sub_s64_round_narrow(&s64_hi[2 * 4], &s64_hi[2 * 6]); + + // s5 + s7 + t_lo[5] = add_s64_round_narrow(&s64_lo[2 * 5], &s64_lo[2 * 7]); + t_hi[5] = add_s64_round_narrow(&s64_hi[2 * 5], &s64_hi[2 * 7]); + // s5 - s7 + t_lo[7] = sub_s64_round_narrow(&s64_lo[2 * 5], &s64_lo[2 * 7]); + t_hi[7] = sub_s64_round_narrow(&s64_hi[2 * 5], &s64_hi[2 * 7]); + + // stage 3 + // s2 = cospi_16_64 * (x2 + x3) + // s3 = cospi_16_64 * (x2 - x3) + butterfly_one_coeff_s32_fast(t_lo[2], t_hi[2], t_lo[3], t_hi[3], cospi_16_64, + &s_lo[2], &s_hi[2], &s_lo[3], &s_hi[3]); + + // s6 = cospi_16_64 * (x6 + x7) + // s7 = cospi_16_64 * (x6 - x7) + butterfly_one_coeff_s32_fast(t_lo[6], t_hi[6], t_lo[7], t_hi[7], cospi_16_64, + &s_lo[6], &s_hi[6], &s_lo[7], &s_hi[7]); + + // x0, x2, x4, x6 pass through + lo[0] = t_lo[0]; + hi[0] = t_hi[0]; + lo[2] = s_lo[6]; + hi[2] = s_hi[6]; + lo[4] = s_lo[3]; + hi[4] = s_hi[3]; + lo[6] = t_lo[5]; + hi[6] = t_hi[5]; + + lo[1] = vnegq_s32(t_lo[4]); + hi[1] = vnegq_s32(t_hi[4]); + lo[3] = vnegq_s32(s_lo[2]); + hi[3] = vnegq_s32(s_hi[2]); + lo[5] = vnegq_s32(s_lo[7]); + hi[5] = vnegq_s32(s_hi[7]); + lo[7] = vnegq_s32(t_lo[1]); + hi[7] = vnegq_s32(t_hi[1]); + + transpose_s32_8x8_2(lo, hi, lo, hi); +} + +void vp9_highbd_fht8x8_neon(const int16_t *input, tran_low_t *output, + int stride, int tx_type) { + int32x4_t lo[8], hi[8]; + + switch (tx_type) { + case DCT_DCT: vpx_highbd_fdct8x8_neon(input, output, stride); break; + case ADST_DCT: + highbd_load_buffer_8x8(input, lo, hi, stride); + highbd_fadst8x8_neon(lo, hi); + // pass1 variant is not precise enough + vpx_highbd_fdct8x8_pass2_neon(lo, hi); + highbd_right_shift_8x8(lo, hi, 1); + highbd_write_buffer_8x8(output, lo, hi, 8); + break; + case DCT_ADST: + highbd_load_buffer_8x8(input, lo, hi, stride); + // pass1 variant is not precise enough + vpx_highbd_fdct8x8_pass2_neon(lo, hi); + highbd_fadst8x8_neon(lo, hi); + highbd_right_shift_8x8(lo, hi, 1); + highbd_write_buffer_8x8(output, lo, hi, 8); + break; + default: + assert(tx_type == ADST_ADST); + highbd_load_buffer_8x8(input, lo, hi, stride); + highbd_fadst8x8_neon(lo, hi); + highbd_fadst8x8_neon(lo, hi); + highbd_right_shift_8x8(lo, hi, 1); + highbd_write_buffer_8x8(output, lo, hi, 8); + break; + } +} + +static INLINE void highbd_load_buffer_16x16( + const int16_t *input, int32x4_t *left1 /*[16]*/, int32x4_t *right1 /*[16]*/, + int32x4_t *left2 /*[16]*/, int32x4_t *right2 /*[16]*/, int stride) { + // load first 8 columns + highbd_load_buffer_8x8(input, left1, right1, stride); + highbd_load_buffer_8x8(input + 8 * stride, left1 + 8, right1 + 8, stride); + + input += 8; + // load second 8 columns + highbd_load_buffer_8x8(input, left2, right2, stride); + highbd_load_buffer_8x8(input + 8 * stride, left2 + 8, right2 + 8, stride); +} + +static INLINE void highbd_write_buffer_16x16( + tran_low_t *output, int32x4_t *left1 /*[16]*/, int32x4_t *right1 /*[16]*/, + int32x4_t *left2 /*[16]*/, int32x4_t *right2 /*[16]*/, int stride) { + // write first 8 columns + highbd_write_buffer_8x8(output, left1, right1, stride); + highbd_write_buffer_8x8(output + 8 * stride, left1 + 8, right1 + 8, stride); + + // write second 8 columns + output += 8; + highbd_write_buffer_8x8(output, left2, right2, stride); + highbd_write_buffer_8x8(output + 8 * stride, left2 + 8, right2 + 8, stride); +} + +static INLINE void highbd_right_shift_16x16(int32x4_t *left1 /*[16]*/, + int32x4_t *right1 /*[16]*/, + int32x4_t *left2 /*[16]*/, + int32x4_t *right2 /*[16]*/, + const int bit) { + // perform rounding operations + highbd_right_shift_8x8(left1, right1, bit); + highbd_right_shift_8x8(left1 + 8, right1 + 8, bit); + highbd_right_shift_8x8(left2, right2, bit); + highbd_right_shift_8x8(left2 + 8, right2 + 8, bit); +} + +static void highbd_fdct16_8col(int32x4_t *left, int32x4_t *right) { + // perform 16x16 1-D DCT for 8 columns + int32x4_t s1_lo[8], s1_hi[8], s2_lo[8], s2_hi[8], s3_lo[8], s3_hi[8]; + int32x4_t left8[8], right8[8]; + + // stage 1 + left8[0] = vaddq_s32(left[0], left[15]); + right8[0] = vaddq_s32(right[0], right[15]); + left8[1] = vaddq_s32(left[1], left[14]); + right8[1] = vaddq_s32(right[1], right[14]); + left8[2] = vaddq_s32(left[2], left[13]); + right8[2] = vaddq_s32(right[2], right[13]); + left8[3] = vaddq_s32(left[3], left[12]); + right8[3] = vaddq_s32(right[3], right[12]); + left8[4] = vaddq_s32(left[4], left[11]); + right8[4] = vaddq_s32(right[4], right[11]); + left8[5] = vaddq_s32(left[5], left[10]); + right8[5] = vaddq_s32(right[5], right[10]); + left8[6] = vaddq_s32(left[6], left[9]); + right8[6] = vaddq_s32(right[6], right[9]); + left8[7] = vaddq_s32(left[7], left[8]); + right8[7] = vaddq_s32(right[7], right[8]); + + // step 1 + s1_lo[0] = vsubq_s32(left[7], left[8]); + s1_hi[0] = vsubq_s32(right[7], right[8]); + s1_lo[1] = vsubq_s32(left[6], left[9]); + s1_hi[1] = vsubq_s32(right[6], right[9]); + s1_lo[2] = vsubq_s32(left[5], left[10]); + s1_hi[2] = vsubq_s32(right[5], right[10]); + s1_lo[3] = vsubq_s32(left[4], left[11]); + s1_hi[3] = vsubq_s32(right[4], right[11]); + s1_lo[4] = vsubq_s32(left[3], left[12]); + s1_hi[4] = vsubq_s32(right[3], right[12]); + s1_lo[5] = vsubq_s32(left[2], left[13]); + s1_hi[5] = vsubq_s32(right[2], right[13]); + s1_lo[6] = vsubq_s32(left[1], left[14]); + s1_hi[6] = vsubq_s32(right[1], right[14]); + s1_lo[7] = vsubq_s32(left[0], left[15]); + s1_hi[7] = vsubq_s32(right[0], right[15]); + + // pass1 variant is not accurate enough + vpx_highbd_fdct8x8_pass2_notranspose_neon(left8, right8); + + // step 2 + // step2[2] = (step1[5] - step1[2]) * cospi_16_64; + // step2[5] = (step1[5] + step1[2]) * cospi_16_64; + butterfly_one_coeff_s32_s64_narrow(s1_lo[5], s1_hi[5], s1_lo[2], s1_hi[2], + cospi_16_64, &s2_lo[5], &s2_hi[5], + &s2_lo[2], &s2_hi[2]); + // step2[3] = (step1[4] - step1[3]) * cospi_16_64; + // step2[4] = (step1[4] + step1[3]) * cospi_16_64; + butterfly_one_coeff_s32_s64_narrow(s1_lo[4], s1_hi[4], s1_lo[3], s1_hi[3], + cospi_16_64, &s2_lo[4], &s2_hi[4], + &s2_lo[3], &s2_hi[3]); + + // step 3 + s3_lo[0] = vaddq_s32(s1_lo[0], s2_lo[3]); + s3_hi[0] = vaddq_s32(s1_hi[0], s2_hi[3]); + s3_lo[1] = vaddq_s32(s1_lo[1], s2_lo[2]); + s3_hi[1] = vaddq_s32(s1_hi[1], s2_hi[2]); + s3_lo[2] = vsubq_s32(s1_lo[1], s2_lo[2]); + s3_hi[2] = vsubq_s32(s1_hi[1], s2_hi[2]); + s3_lo[3] = vsubq_s32(s1_lo[0], s2_lo[3]); + s3_hi[3] = vsubq_s32(s1_hi[0], s2_hi[3]); + s3_lo[4] = vsubq_s32(s1_lo[7], s2_lo[4]); + s3_hi[4] = vsubq_s32(s1_hi[7], s2_hi[4]); + s3_lo[5] = vsubq_s32(s1_lo[6], s2_lo[5]); + s3_hi[5] = vsubq_s32(s1_hi[6], s2_hi[5]); + s3_lo[6] = vaddq_s32(s1_lo[6], s2_lo[5]); + s3_hi[6] = vaddq_s32(s1_hi[6], s2_hi[5]); + s3_lo[7] = vaddq_s32(s1_lo[7], s2_lo[4]); + s3_hi[7] = vaddq_s32(s1_hi[7], s2_hi[4]); + + // step 4 + // s2[1] = cospi_24_64 * s3[6] - cospi_8_64 * s3[1] + // s2[6] = cospi_8_64 * s3[6] + cospi_24_64 * s3[1] + butterfly_two_coeff_s32_s64_narrow(s3_lo[6], s3_hi[6], s3_lo[1], s3_hi[1], + cospi_8_64, cospi_24_64, &s2_lo[6], + &s2_hi[6], &s2_lo[1], &s2_hi[1]); + + // s2[5] = cospi_8_64 * s3[2] - cospi_24_64 * s3[5] + // s2[2] = cospi_24_64 * s3[2] + cospi_8_64 * s3[5] + butterfly_two_coeff_s32_s64_narrow(s3_lo[2], s3_hi[2], s3_lo[5], s3_hi[5], + cospi_24_64, cospi_8_64, &s2_lo[2], + &s2_hi[2], &s2_lo[5], &s2_hi[5]); + + // step 5 + s1_lo[0] = vaddq_s32(s3_lo[0], s2_lo[1]); + s1_hi[0] = vaddq_s32(s3_hi[0], s2_hi[1]); + s1_lo[1] = vsubq_s32(s3_lo[0], s2_lo[1]); + s1_hi[1] = vsubq_s32(s3_hi[0], s2_hi[1]); + s1_lo[2] = vaddq_s32(s3_lo[3], s2_lo[2]); + s1_hi[2] = vaddq_s32(s3_hi[3], s2_hi[2]); + s1_lo[3] = vsubq_s32(s3_lo[3], s2_lo[2]); + s1_hi[3] = vsubq_s32(s3_hi[3], s2_hi[2]); + s1_lo[4] = vsubq_s32(s3_lo[4], s2_lo[5]); + s1_hi[4] = vsubq_s32(s3_hi[4], s2_hi[5]); + s1_lo[5] = vaddq_s32(s3_lo[4], s2_lo[5]); + s1_hi[5] = vaddq_s32(s3_hi[4], s2_hi[5]); + s1_lo[6] = vsubq_s32(s3_lo[7], s2_lo[6]); + s1_hi[6] = vsubq_s32(s3_hi[7], s2_hi[6]); + s1_lo[7] = vaddq_s32(s3_lo[7], s2_lo[6]); + s1_hi[7] = vaddq_s32(s3_hi[7], s2_hi[6]); + + // step 6 + // out[1] = step1[7] * cospi_2_64 + step1[0] * cospi_30_64 + // out[15] = step1[7] * cospi_30_64 - step1[0] * cospi_2_64 + butterfly_two_coeff_s32_s64_narrow(s1_lo[7], s1_hi[7], s1_lo[0], s1_hi[0], + cospi_2_64, cospi_30_64, &left[1], + &right[1], &left[15], &right[15]); + + // out[9] = step1[6] * cospi_18_64 + step1[1] * cospi_14_64 + // out[7] = step1[6] * cospi_14_64 - step1[1] * cospi_18_64 + butterfly_two_coeff_s32_s64_narrow(s1_lo[6], s1_hi[6], s1_lo[1], s1_hi[1], + cospi_18_64, cospi_14_64, &left[9], + &right[9], &left[7], &right[7]); + + // out[5] = step1[5] * cospi_10_64 + step1[2] * cospi_22_64 + // out[11] = step1[5] * cospi_22_64 - step1[2] * cospi_10_64 + butterfly_two_coeff_s32_s64_narrow(s1_lo[5], s1_hi[5], s1_lo[2], s1_hi[2], + cospi_10_64, cospi_22_64, &left[5], + &right[5], &left[11], &right[11]); + + // out[13] = step1[4] * cospi_26_64 + step1[3] * cospi_6_64 + // out[3] = step1[4] * cospi_6_64 - step1[3] * cospi_26_64 + butterfly_two_coeff_s32_s64_narrow(s1_lo[4], s1_hi[4], s1_lo[3], s1_hi[3], + cospi_26_64, cospi_6_64, &left[13], + &right[13], &left[3], &right[3]); + + left[0] = left8[0]; + right[0] = right8[0]; + left[2] = left8[1]; + right[2] = right8[1]; + left[4] = left8[2]; + right[4] = right8[2]; + left[6] = left8[3]; + right[6] = right8[3]; + left[8] = left8[4]; + right[8] = right8[4]; + left[10] = left8[5]; + right[10] = right8[5]; + left[12] = left8[6]; + right[12] = right8[6]; + left[14] = left8[7]; + right[14] = right8[7]; +} + +static void highbd_fadst16_8col(int32x4_t *left, int32x4_t *right) { + // perform 16x16 1-D ADST for 8 columns + int32x4_t x_lo[16], x_hi[16]; + int32x4_t s_lo[16], s_hi[16]; + int32x4_t t_lo[16], t_hi[16]; + int64x2_t s64_lo[32], s64_hi[32]; + + x_lo[0] = left[15]; + x_hi[0] = right[15]; + x_lo[1] = left[0]; + x_hi[1] = right[0]; + x_lo[2] = left[13]; + x_hi[2] = right[13]; + x_lo[3] = left[2]; + x_hi[3] = right[2]; + x_lo[4] = left[11]; + x_hi[4] = right[11]; + x_lo[5] = left[4]; + x_hi[5] = right[4]; + x_lo[6] = left[9]; + x_hi[6] = right[9]; + x_lo[7] = left[6]; + x_hi[7] = right[6]; + x_lo[8] = left[7]; + x_hi[8] = right[7]; + x_lo[9] = left[8]; + x_hi[9] = right[8]; + x_lo[10] = left[5]; + x_hi[10] = right[5]; + x_lo[11] = left[10]; + x_hi[11] = right[10]; + x_lo[12] = left[3]; + x_hi[12] = right[3]; + x_lo[13] = left[12]; + x_hi[13] = right[12]; + x_lo[14] = left[1]; + x_hi[14] = right[1]; + x_lo[15] = left[14]; + x_hi[15] = right[14]; + + // stage 1, indices are doubled + // s0 = cospi_1_64 * x0 + cospi_31_64 * x1; + // s1 = cospi_31_64 * x0 - cospi_1_64 * x1; + butterfly_two_coeff_s32_s64_noround( + x_lo[0], x_hi[0], x_lo[1], x_hi[1], cospi_1_64, cospi_31_64, + &s64_lo[2 * 0], &s64_hi[2 * 0], &s64_lo[2 * 1], &s64_hi[2 * 1]); + // s2 = cospi_5_64 * x2 + cospi_27_64 * x3; + // s3 = cospi_27_64 * x2 - cospi_5_64 * x3; + butterfly_two_coeff_s32_s64_noround( + x_lo[2], x_hi[2], x_lo[3], x_hi[3], cospi_5_64, cospi_27_64, + &s64_lo[2 * 2], &s64_hi[2 * 2], &s64_lo[2 * 3], &s64_hi[2 * 3]); + // s4 = cospi_9_64 * x4 + cospi_23_64 * x5; + // s5 = cospi_23_64 * x4 - cospi_9_64 * x5; + butterfly_two_coeff_s32_s64_noround( + x_lo[4], x_hi[4], x_lo[5], x_hi[5], cospi_9_64, cospi_23_64, + &s64_lo[2 * 4], &s64_hi[2 * 4], &s64_lo[2 * 5], &s64_hi[2 * 5]); + // s6 = cospi_13_64 * x6 + cospi_19_64 * x7; + // s7 = cospi_19_64 * x6 - cospi_13_64 * x7; + butterfly_two_coeff_s32_s64_noround( + x_lo[6], x_hi[6], x_lo[7], x_hi[7], cospi_13_64, cospi_19_64, + &s64_lo[2 * 6], &s64_hi[2 * 6], &s64_lo[2 * 7], &s64_hi[2 * 7]); + // s8 = cospi_17_64 * x8 + cospi_15_64 * x9; + // s9 = cospi_15_64 * x8 - cospi_17_64 * x9; + butterfly_two_coeff_s32_s64_noround( + x_lo[8], x_hi[8], x_lo[9], x_hi[9], cospi_17_64, cospi_15_64, + &s64_lo[2 * 8], &s64_hi[2 * 8], &s64_lo[2 * 9], &s64_hi[2 * 9]); + // s10 = cospi_21_64 * x10 + cospi_11_64 * x11; + // s11 = cospi_11_64 * x10 - cospi_21_64 * x11; + butterfly_two_coeff_s32_s64_noround( + x_lo[10], x_hi[10], x_lo[11], x_hi[11], cospi_21_64, cospi_11_64, + &s64_lo[2 * 10], &s64_hi[2 * 10], &s64_lo[2 * 11], &s64_hi[2 * 11]); + // s12 = cospi_25_64 * x12 + cospi_7_64 * x13; + // s13 = cospi_7_64 * x12 - cospi_25_64 * x13; + butterfly_two_coeff_s32_s64_noround( + x_lo[12], x_hi[12], x_lo[13], x_hi[13], cospi_25_64, cospi_7_64, + &s64_lo[2 * 12], &s64_hi[2 * 12], &s64_lo[2 * 13], &s64_hi[2 * 13]); + // s14 = cospi_29_64 * x14 + cospi_3_64 * x15; + // s15 = cospi_3_64 * x14 - cospi_29_64 * x15; + butterfly_two_coeff_s32_s64_noround( + x_lo[14], x_hi[14], x_lo[15], x_hi[15], cospi_29_64, cospi_3_64, + &s64_lo[2 * 14], &s64_hi[2 * 14], &s64_lo[2 * 15], &s64_hi[2 * 15]); + + // fdct_round_shift, indices are doubled + t_lo[0] = add_s64_round_narrow(&s64_lo[2 * 0], &s64_lo[2 * 8]); + t_hi[0] = add_s64_round_narrow(&s64_hi[2 * 0], &s64_hi[2 * 8]); + t_lo[1] = add_s64_round_narrow(&s64_lo[2 * 1], &s64_lo[2 * 9]); + t_hi[1] = add_s64_round_narrow(&s64_hi[2 * 1], &s64_hi[2 * 9]); + t_lo[2] = add_s64_round_narrow(&s64_lo[2 * 2], &s64_lo[2 * 10]); + t_hi[2] = add_s64_round_narrow(&s64_hi[2 * 2], &s64_hi[2 * 10]); + t_lo[3] = add_s64_round_narrow(&s64_lo[2 * 3], &s64_lo[2 * 11]); + t_hi[3] = add_s64_round_narrow(&s64_hi[2 * 3], &s64_hi[2 * 11]); + t_lo[4] = add_s64_round_narrow(&s64_lo[2 * 4], &s64_lo[2 * 12]); + t_hi[4] = add_s64_round_narrow(&s64_hi[2 * 4], &s64_hi[2 * 12]); + t_lo[5] = add_s64_round_narrow(&s64_lo[2 * 5], &s64_lo[2 * 13]); + t_hi[5] = add_s64_round_narrow(&s64_hi[2 * 5], &s64_hi[2 * 13]); + t_lo[6] = add_s64_round_narrow(&s64_lo[2 * 6], &s64_lo[2 * 14]); + t_hi[6] = add_s64_round_narrow(&s64_hi[2 * 6], &s64_hi[2 * 14]); + t_lo[7] = add_s64_round_narrow(&s64_lo[2 * 7], &s64_lo[2 * 15]); + t_hi[7] = add_s64_round_narrow(&s64_hi[2 * 7], &s64_hi[2 * 15]); + t_lo[8] = sub_s64_round_narrow(&s64_lo[2 * 0], &s64_lo[2 * 8]); + t_hi[8] = sub_s64_round_narrow(&s64_hi[2 * 0], &s64_hi[2 * 8]); + t_lo[9] = sub_s64_round_narrow(&s64_lo[2 * 1], &s64_lo[2 * 9]); + t_hi[9] = sub_s64_round_narrow(&s64_hi[2 * 1], &s64_hi[2 * 9]); + t_lo[10] = sub_s64_round_narrow(&s64_lo[2 * 2], &s64_lo[2 * 10]); + t_hi[10] = sub_s64_round_narrow(&s64_hi[2 * 2], &s64_hi[2 * 10]); + t_lo[11] = sub_s64_round_narrow(&s64_lo[2 * 3], &s64_lo[2 * 11]); + t_hi[11] = sub_s64_round_narrow(&s64_hi[2 * 3], &s64_hi[2 * 11]); + t_lo[12] = sub_s64_round_narrow(&s64_lo[2 * 4], &s64_lo[2 * 12]); + t_hi[12] = sub_s64_round_narrow(&s64_hi[2 * 4], &s64_hi[2 * 12]); + t_lo[13] = sub_s64_round_narrow(&s64_lo[2 * 5], &s64_lo[2 * 13]); + t_hi[13] = sub_s64_round_narrow(&s64_hi[2 * 5], &s64_hi[2 * 13]); + t_lo[14] = sub_s64_round_narrow(&s64_lo[2 * 6], &s64_lo[2 * 14]); + t_hi[14] = sub_s64_round_narrow(&s64_hi[2 * 6], &s64_hi[2 * 14]); + t_lo[15] = sub_s64_round_narrow(&s64_lo[2 * 7], &s64_lo[2 * 15]); + t_hi[15] = sub_s64_round_narrow(&s64_hi[2 * 7], &s64_hi[2 * 15]); + + // stage 2 + s_lo[0] = t_lo[0]; + s_hi[0] = t_hi[0]; + s_lo[1] = t_lo[1]; + s_hi[1] = t_hi[1]; + s_lo[2] = t_lo[2]; + s_hi[2] = t_hi[2]; + s_lo[3] = t_lo[3]; + s_hi[3] = t_hi[3]; + s_lo[4] = t_lo[4]; + s_hi[4] = t_hi[4]; + s_lo[5] = t_lo[5]; + s_hi[5] = t_hi[5]; + s_lo[6] = t_lo[6]; + s_hi[6] = t_hi[6]; + s_lo[7] = t_lo[7]; + s_hi[7] = t_hi[7]; + // s8 = x8 * cospi_4_64 + x9 * cospi_28_64; + // s9 = x8 * cospi_28_64 - x9 * cospi_4_64; + butterfly_two_coeff_s32_s64_noround( + t_lo[8], t_hi[8], t_lo[9], t_hi[9], cospi_4_64, cospi_28_64, + &s64_lo[2 * 8], &s64_hi[2 * 8], &s64_lo[2 * 9], &s64_hi[2 * 9]); + // s10 = x10 * cospi_20_64 + x11 * cospi_12_64; + // s11 = x10 * cospi_12_64 - x11 * cospi_20_64; + butterfly_two_coeff_s32_s64_noround( + t_lo[10], t_hi[10], t_lo[11], t_hi[11], cospi_20_64, cospi_12_64, + &s64_lo[2 * 10], &s64_hi[2 * 10], &s64_lo[2 * 11], &s64_hi[2 * 11]); + // s12 = -x12 * cospi_28_64 + x13 * cospi_4_64; + // s13 = x12 * cospi_4_64 + x13 * cospi_28_64; + butterfly_two_coeff_s32_s64_noround( + t_lo[13], t_hi[13], t_lo[12], t_hi[12], cospi_28_64, cospi_4_64, + &s64_lo[2 * 13], &s64_hi[2 * 13], &s64_lo[2 * 12], &s64_hi[2 * 12]); + // s14 = -x14 * cospi_12_64 + x15 * cospi_20_64; + // s15 = x14 * cospi_20_64 + x15 * cospi_12_64; + butterfly_two_coeff_s32_s64_noround( + t_lo[15], t_hi[15], t_lo[14], t_hi[14], cospi_12_64, cospi_20_64, + &s64_lo[2 * 15], &s64_hi[2 * 15], &s64_lo[2 * 14], &s64_hi[2 * 14]); + + // s0 + s4 + t_lo[0] = add_s32_s64_narrow(s_lo[0], s_lo[4]); + t_hi[0] = add_s32_s64_narrow(s_hi[0], s_hi[4]); + // s1 + s5 + t_lo[1] = add_s32_s64_narrow(s_lo[1], s_lo[5]); + t_hi[1] = add_s32_s64_narrow(s_hi[1], s_hi[5]); + // s2 + s6 + t_lo[2] = add_s32_s64_narrow(s_lo[2], s_lo[6]); + t_hi[2] = add_s32_s64_narrow(s_hi[2], s_hi[6]); + // s3 + s7 + t_lo[3] = add_s32_s64_narrow(s_lo[3], s_lo[7]); + t_hi[3] = add_s32_s64_narrow(s_hi[3], s_hi[7]); + + // s0 - s4 + t_lo[4] = sub_s32_s64_narrow(s_lo[0], s_lo[4]); + t_hi[4] = sub_s32_s64_narrow(s_hi[0], s_hi[4]); + // s1 - s5 + t_lo[5] = sub_s32_s64_narrow(s_lo[1], s_lo[5]); + t_hi[5] = sub_s32_s64_narrow(s_hi[1], s_hi[5]); + // s2 - s6 + t_lo[6] = sub_s32_s64_narrow(s_lo[2], s_lo[6]); + t_hi[6] = sub_s32_s64_narrow(s_hi[2], s_hi[6]); + // s3 - s7 + t_lo[7] = sub_s32_s64_narrow(s_lo[3], s_lo[7]); + t_hi[7] = sub_s32_s64_narrow(s_hi[3], s_hi[7]); + + // fdct_round_shift() + // s8 + s12 + t_lo[8] = add_s64_round_narrow(&s64_lo[2 * 8], &s64_lo[2 * 12]); + t_hi[8] = add_s64_round_narrow(&s64_hi[2 * 8], &s64_hi[2 * 12]); + // s9 + s13 + t_lo[9] = add_s64_round_narrow(&s64_lo[2 * 9], &s64_lo[2 * 13]); + t_hi[9] = add_s64_round_narrow(&s64_hi[2 * 9], &s64_hi[2 * 13]); + // s10 + s14 + t_lo[10] = add_s64_round_narrow(&s64_lo[2 * 10], &s64_lo[2 * 14]); + t_hi[10] = add_s64_round_narrow(&s64_hi[2 * 10], &s64_hi[2 * 14]); + // s11 + s15 + t_lo[11] = add_s64_round_narrow(&s64_lo[2 * 11], &s64_lo[2 * 15]); + t_hi[11] = add_s64_round_narrow(&s64_hi[2 * 11], &s64_hi[2 * 15]); + + // s8 - s12 + t_lo[12] = sub_s64_round_narrow(&s64_lo[2 * 8], &s64_lo[2 * 12]); + t_hi[12] = sub_s64_round_narrow(&s64_hi[2 * 8], &s64_hi[2 * 12]); + // s9 - s13 + t_lo[13] = sub_s64_round_narrow(&s64_lo[2 * 9], &s64_lo[2 * 13]); + t_hi[13] = sub_s64_round_narrow(&s64_hi[2 * 9], &s64_hi[2 * 13]); + // s10 - s14 + t_lo[14] = sub_s64_round_narrow(&s64_lo[2 * 10], &s64_lo[2 * 14]); + t_hi[14] = sub_s64_round_narrow(&s64_hi[2 * 10], &s64_hi[2 * 14]); + // s11 - s15 + t_lo[15] = sub_s64_round_narrow(&s64_lo[2 * 11], &s64_lo[2 * 15]); + t_hi[15] = sub_s64_round_narrow(&s64_hi[2 * 11], &s64_hi[2 * 15]); + + // stage 3 + s_lo[0] = t_lo[0]; + s_hi[0] = t_hi[0]; + s_lo[1] = t_lo[1]; + s_hi[1] = t_hi[1]; + s_lo[2] = t_lo[2]; + s_hi[2] = t_hi[2]; + s_lo[3] = t_lo[3]; + s_hi[3] = t_hi[3]; + // s4 = x4 * cospi_8_64 + x5 * cospi_24_64; + // s5 = x4 * cospi_24_64 - x5 * cospi_8_64; + butterfly_two_coeff_s32_s64_noround( + t_lo[4], t_hi[4], t_lo[5], t_hi[5], cospi_8_64, cospi_24_64, + &s64_lo[2 * 4], &s64_hi[2 * 4], &s64_lo[2 * 5], &s64_hi[2 * 5]); + // s6 = -x6 * cospi_24_64 + x7 * cospi_8_64; + // s7 = x6 * cospi_8_64 + x7 * cospi_24_64; + butterfly_two_coeff_s32_s64_noround( + t_lo[7], t_hi[7], t_lo[6], t_hi[6], cospi_24_64, cospi_8_64, + &s64_lo[2 * 7], &s64_hi[2 * 7], &s64_lo[2 * 6], &s64_hi[2 * 6]); + s_lo[8] = t_lo[8]; + s_hi[8] = t_hi[8]; + s_lo[9] = t_lo[9]; + s_hi[9] = t_hi[9]; + s_lo[10] = t_lo[10]; + s_hi[10] = t_hi[10]; + s_lo[11] = t_lo[11]; + s_hi[11] = t_hi[11]; + // s12 = x12 * cospi_8_64 + x13 * cospi_24_64; + // s13 = x12 * cospi_24_64 - x13 * cospi_8_64; + butterfly_two_coeff_s32_s64_noround( + t_lo[12], t_hi[12], t_lo[13], t_hi[13], cospi_8_64, cospi_24_64, + &s64_lo[2 * 12], &s64_hi[2 * 12], &s64_lo[2 * 13], &s64_hi[2 * 13]); + // s14 = -x14 * cospi_24_64 + x15 * cospi_8_64; + // s15 = x14 * cospi_8_64 + x15 * cospi_24_64; + butterfly_two_coeff_s32_s64_noround( + t_lo[15], t_hi[15], t_lo[14], t_hi[14], cospi_24_64, cospi_8_64, + &s64_lo[2 * 15], &s64_hi[2 * 15], &s64_lo[2 * 14], &s64_hi[2 * 14]); + + // s0 + s2 + t_lo[0] = add_s32_s64_narrow(s_lo[0], s_lo[2]); + t_hi[0] = add_s32_s64_narrow(s_hi[0], s_hi[2]); + // s1 + s3 + t_lo[1] = add_s32_s64_narrow(s_lo[1], s_lo[3]); + t_hi[1] = add_s32_s64_narrow(s_hi[1], s_hi[3]); + // s0 - s2 + t_lo[2] = sub_s32_s64_narrow(s_lo[0], s_lo[2]); + t_hi[2] = sub_s32_s64_narrow(s_hi[0], s_hi[2]); + // s1 - s3 + t_lo[3] = sub_s32_s64_narrow(s_lo[1], s_lo[3]); + t_hi[3] = sub_s32_s64_narrow(s_hi[1], s_hi[3]); + // fdct_round_shift() + // s4 + s6 + t_lo[4] = add_s64_round_narrow(&s64_lo[2 * 4], &s64_lo[2 * 6]); + t_hi[4] = add_s64_round_narrow(&s64_hi[2 * 4], &s64_hi[2 * 6]); + // s5 + s7 + t_lo[5] = add_s64_round_narrow(&s64_lo[2 * 5], &s64_lo[2 * 7]); + t_hi[5] = add_s64_round_narrow(&s64_hi[2 * 5], &s64_hi[2 * 7]); + // s4 - s6 + t_lo[6] = sub_s64_round_narrow(&s64_lo[2 * 4], &s64_lo[2 * 6]); + t_hi[6] = sub_s64_round_narrow(&s64_hi[2 * 4], &s64_hi[2 * 6]); + // s5 - s7 + t_lo[7] = sub_s64_round_narrow(&s64_lo[2 * 5], &s64_lo[2 * 7]); + t_hi[7] = sub_s64_round_narrow(&s64_hi[2 * 5], &s64_hi[2 * 7]); + // s8 + s10 + t_lo[8] = add_s32_s64_narrow(s_lo[8], s_lo[10]); + t_hi[8] = add_s32_s64_narrow(s_hi[8], s_hi[10]); + // s9 + s11 + t_lo[9] = add_s32_s64_narrow(s_lo[9], s_lo[11]); + t_hi[9] = add_s32_s64_narrow(s_hi[9], s_hi[11]); + // s8 - s10 + t_lo[10] = sub_s32_s64_narrow(s_lo[8], s_lo[10]); + t_hi[10] = sub_s32_s64_narrow(s_hi[8], s_hi[10]); + // s9 - s11 + t_lo[11] = sub_s32_s64_narrow(s_lo[9], s_lo[11]); + t_hi[11] = sub_s32_s64_narrow(s_hi[9], s_hi[11]); + // fdct_round_shift() + // s12 + s14 + t_lo[12] = add_s64_round_narrow(&s64_lo[2 * 12], &s64_lo[2 * 14]); + t_hi[12] = add_s64_round_narrow(&s64_hi[2 * 12], &s64_hi[2 * 14]); + // s13 + s15 + t_lo[13] = add_s64_round_narrow(&s64_lo[2 * 13], &s64_lo[2 * 15]); + t_hi[13] = add_s64_round_narrow(&s64_hi[2 * 13], &s64_hi[2 * 15]); + // s12 - s14 + t_lo[14] = sub_s64_round_narrow(&s64_lo[2 * 12], &s64_lo[2 * 14]); + t_hi[14] = sub_s64_round_narrow(&s64_hi[2 * 12], &s64_hi[2 * 14]); + // s13 - s15 + t_lo[15] = sub_s64_round_narrow(&s64_lo[2 * 13], &s64_lo[2 * 15]); + t_hi[15] = sub_s64_round_narrow(&s64_hi[2 * 13], &s64_hi[2 * 15]); + + // stage 4, with fdct_round_shift + // s2 = (-cospi_16_64) * (x2 + x3); + // s3 = cospi_16_64 * (x2 - x3); + butterfly_one_coeff_s32_s64_narrow(t_lo[3], t_hi[3], t_lo[2], t_hi[2], + -cospi_16_64, &x_lo[2], &x_hi[2], &x_lo[3], + &x_hi[3]); + // s6 = cospi_16_64 * (x6 + x7); + // s7 = cospi_16_64 * (-x6 + x7); + butterfly_one_coeff_s32_s64_narrow(t_lo[7], t_hi[7], t_lo[6], t_hi[6], + cospi_16_64, &x_lo[6], &x_hi[6], &x_lo[7], + &x_hi[7]); + // s10 = cospi_16_64 * (x10 + x11); + // s11 = cospi_16_64 * (-x10 + x11); + butterfly_one_coeff_s32_s64_narrow(t_lo[11], t_hi[11], t_lo[10], t_hi[10], + cospi_16_64, &x_lo[10], &x_hi[10], + &x_lo[11], &x_hi[11]); + // s14 = (-cospi_16_64) * (x14 + x15); + // s15 = cospi_16_64 * (x14 - x15); + butterfly_one_coeff_s32_s64_narrow(t_lo[15], t_hi[15], t_lo[14], t_hi[14], + -cospi_16_64, &x_lo[14], &x_hi[14], + &x_lo[15], &x_hi[15]); + + // Just copy x0, x1, x4, x5, x8, x9, x12, x13 + x_lo[0] = t_lo[0]; + x_hi[0] = t_hi[0]; + x_lo[1] = t_lo[1]; + x_hi[1] = t_hi[1]; + x_lo[4] = t_lo[4]; + x_hi[4] = t_hi[4]; + x_lo[5] = t_lo[5]; + x_hi[5] = t_hi[5]; + x_lo[8] = t_lo[8]; + x_hi[8] = t_hi[8]; + x_lo[9] = t_lo[9]; + x_hi[9] = t_hi[9]; + x_lo[12] = t_lo[12]; + x_hi[12] = t_hi[12]; + x_lo[13] = t_lo[13]; + x_hi[13] = t_hi[13]; + + left[0] = x_lo[0]; + right[0] = x_hi[0]; + left[1] = vnegq_s32(x_lo[8]); + right[1] = vnegq_s32(x_hi[8]); + left[2] = x_lo[12]; + right[2] = x_hi[12]; + left[3] = vnegq_s32(x_lo[4]); + right[3] = vnegq_s32(x_hi[4]); + left[4] = x_lo[6]; + right[4] = x_hi[6]; + left[5] = x_lo[14]; + right[5] = x_hi[14]; + left[6] = x_lo[10]; + right[6] = x_hi[10]; + left[7] = x_lo[2]; + right[7] = x_hi[2]; + left[8] = x_lo[3]; + right[8] = x_hi[3]; + left[9] = x_lo[11]; + right[9] = x_hi[11]; + left[10] = x_lo[15]; + right[10] = x_hi[15]; + left[11] = x_lo[7]; + right[11] = x_hi[7]; + left[12] = x_lo[5]; + right[12] = x_hi[5]; + left[13] = vnegq_s32(x_lo[13]); + right[13] = vnegq_s32(x_hi[13]); + left[14] = x_lo[9]; + right[14] = x_hi[9]; + left[15] = vnegq_s32(x_lo[1]); + right[15] = vnegq_s32(x_hi[1]); +} + +static void highbd_fdct16x16_neon(int32x4_t *left1, int32x4_t *right1, + int32x4_t *left2, int32x4_t *right2) { + // Left half. + highbd_fdct16_8col(left1, right1); + // Right half. + highbd_fdct16_8col(left2, right2); + transpose_s32_16x16(left1, right1, left2, right2); +} + +static void highbd_fadst16x16_neon(int32x4_t *left1, int32x4_t *right1, + int32x4_t *left2, int32x4_t *right2) { + // Left half. + highbd_fadst16_8col(left1, right1); + // Right half. + highbd_fadst16_8col(left2, right2); + transpose_s32_16x16(left1, right1, left2, right2); +} + +void vp9_highbd_fht16x16_neon(const int16_t *input, tran_low_t *output, + int stride, int tx_type) { + int32x4_t left1[16], right1[16], left2[16], right2[16]; + + switch (tx_type) { + case DCT_DCT: vpx_highbd_fdct16x16_neon(input, output, stride); break; + case ADST_DCT: + highbd_load_buffer_16x16(input, left1, right1, left2, right2, stride); + highbd_fadst16x16_neon(left1, right1, left2, right2); + highbd_write_buffer_16x16(output, left1, right1, left2, right2, 16); + highbd_right_shift_16x16(left1, right1, left2, right2, 2); + highbd_fdct16x16_neon(left1, right1, left2, right2); + highbd_write_buffer_16x16(output, left1, right1, left2, right2, 16); + break; + case DCT_ADST: + highbd_load_buffer_16x16(input, left1, right1, left2, right2, stride); + highbd_fdct16x16_neon(left1, right1, left2, right2); + highbd_right_shift_16x16(left1, right1, left2, right2, 2); + highbd_fadst16x16_neon(left1, right1, left2, right2); + highbd_write_buffer_16x16(output, left1, right1, left2, right2, 16); + break; + default: + assert(tx_type == ADST_ADST); + highbd_load_buffer_16x16(input, left1, right1, left2, right2, stride); + highbd_fadst16x16_neon(left1, right1, left2, right2); + highbd_right_shift_16x16(left1, right1, left2, right2, 2); + highbd_fadst16x16_neon(left1, right1, left2, right2); + highbd_write_buffer_16x16(output, left1, right1, left2, right2, 16); + break; + } +} + +#endif // CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_denoiser_neon.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_denoiser_neon.c index 53e8c7e498..d631cd437d 100644 --- a/libs/libvpx/vp9/encoder/arm/neon/vp9_denoiser_neon.c +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_denoiser_neon.c @@ -21,7 +21,7 @@ // Compute the sum of all pixel differences of this MB. static INLINE int horizontal_add_s8x16(const int8x16_t v_sum_diff_total) { -#if defined(__aarch64__) +#if VPX_ARCH_AARCH64 return vaddlvq_s8(v_sum_diff_total); #else const int16x8_t fe_dc_ba_98_76_54_32_10 = vpaddlq_s8(v_sum_diff_total); diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_diamond_search_sad_neon.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_diamond_search_sad_neon.c new file mode 100644 index 0000000000..b82b3f9db5 --- /dev/null +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_diamond_search_sad_neon.c @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "vpx_dsp/vpx_dsp_common.h" +#include "vp9/encoder/vp9_encoder.h" +#include "vpx_ports/mem.h" + +#ifdef __GNUC__ +#define LIKELY(v) __builtin_expect(v, 1) +#define UNLIKELY(v) __builtin_expect(v, 0) +#else +#define LIKELY(v) (v) +#define UNLIKELY(v) (v) +#endif + +static INLINE int_mv pack_int_mv(int16_t row, int16_t col) { + int_mv result; + result.as_mv.row = row; + result.as_mv.col = col; + return result; +} + +/***************************************************************************** + * This function utilizes 3 properties of the cost function lookup tables, * + * constructed in using 'cal_nmvjointsadcost' and 'cal_nmvsadcosts' in * + * vp9_encoder.c. * + * For the joint cost: * + * - mvjointsadcost[1] == mvjointsadcost[2] == mvjointsadcost[3] * + * For the component costs: * + * - For all i: mvsadcost[0][i] == mvsadcost[1][i] * + * (Equal costs for both components) * + * - For all i: mvsadcost[0][i] == mvsadcost[0][-i] * + * (Cost function is even) * + * If these do not hold, then this function cannot be used without * + * modification, in which case you can revert to using the C implementation, * + * which does not rely on these properties. * + *****************************************************************************/ +int vp9_diamond_search_sad_neon(const MACROBLOCK *x, + const search_site_config *cfg, MV *ref_mv, + uint32_t start_mv_sad, MV *best_mv, + int search_param, int sad_per_bit, int *num00, + const vp9_sad_fn_ptr_t *sad_fn_ptr, + const MV *center_mv) { + static const uint32_t data[4] = { 0, 1, 2, 3 }; + const uint32x4_t v_idx_d = vld1q_u32((const uint32_t *)data); + + const int32x4_t zero_s32 = vdupq_n_s32(0); + const int_mv maxmv = pack_int_mv(x->mv_limits.row_max, x->mv_limits.col_max); + const int16x8_t v_max_mv_w = vreinterpretq_s16_s32(vdupq_n_s32(maxmv.as_int)); + const int_mv minmv = pack_int_mv(x->mv_limits.row_min, x->mv_limits.col_min); + const int16x8_t v_min_mv_w = vreinterpretq_s16_s32(vdupq_n_s32(minmv.as_int)); + + const int32x4_t v_spb_d = vdupq_n_s32(sad_per_bit); + + const int32x4_t v_joint_cost_0_d = vdupq_n_s32(x->nmvjointsadcost[0]); + const int32x4_t v_joint_cost_1_d = vdupq_n_s32(x->nmvjointsadcost[1]); + + // search_param determines the length of the initial step and hence the number + // of iterations. + // 0 = initial step (MAX_FIRST_STEP) pel + // 1 = (MAX_FIRST_STEP/2) pel, + // 2 = (MAX_FIRST_STEP/4) pel... + const MV *ss_mv = &cfg->ss_mv[cfg->searches_per_step * search_param]; + const intptr_t *ss_os = &cfg->ss_os[cfg->searches_per_step * search_param]; + const int tot_steps = cfg->total_steps - search_param; + + const int_mv fcenter_mv = + pack_int_mv(center_mv->row >> 3, center_mv->col >> 3); + const int16x8_t vfcmv = vreinterpretq_s16_s32(vdupq_n_s32(fcenter_mv.as_int)); + + const int ref_row = ref_mv->row; + const int ref_col = ref_mv->col; + + int_mv bmv = pack_int_mv(ref_row, ref_col); + int_mv new_bmv = bmv; + int16x8_t v_bmv_w = vreinterpretq_s16_s32(vdupq_n_s32(bmv.as_int)); + + const int what_stride = x->plane[0].src.stride; + const int in_what_stride = x->e_mbd.plane[0].pre[0].stride; + const uint8_t *const what = x->plane[0].src.buf; + const uint8_t *const in_what = + x->e_mbd.plane[0].pre[0].buf + ref_row * in_what_stride + ref_col; + + // Work out the start point for the search + const uint8_t *best_address = in_what; + const uint8_t *new_best_address = best_address; +#if VPX_ARCH_AARCH64 + int64x2_t v_ba_q = vdupq_n_s64((intptr_t)best_address); +#else + int32x4_t v_ba_d = vdupq_n_s32((intptr_t)best_address); +#endif + // Starting position + unsigned int best_sad = start_mv_sad; + int i, j, step; + + // Check the prerequisite cost function properties that are easy to check + // in an assert. See the function-level documentation for details on all + // prerequisites. + assert(x->nmvjointsadcost[1] == x->nmvjointsadcost[2]); + assert(x->nmvjointsadcost[1] == x->nmvjointsadcost[3]); + + *num00 = 0; + + for (i = 0, step = 0; step < tot_steps; step++) { + for (j = 0; j < cfg->searches_per_step; j += 4, i += 4) { + int16x8_t v_diff_mv_w; + int8x16_t v_inside_d; + uint32x4_t v_outside_d; + int32x4_t v_cost_d, v_sad_d; +#if VPX_ARCH_AARCH64 + int64x2_t v_blocka[2]; +#else + int32x4_t v_blocka[1]; + uint32x2_t horiz_max_0, horiz_max_1; +#endif + + uint32_t horiz_max; + // Compute the candidate motion vectors + const int16x8_t v_ss_mv_w = vld1q_s16((const int16_t *)&ss_mv[i]); + const int16x8_t v_these_mv_w = vaddq_s16(v_bmv_w, v_ss_mv_w); + // Clamp them to the search bounds + int16x8_t v_these_mv_clamp_w = v_these_mv_w; + v_these_mv_clamp_w = vminq_s16(v_these_mv_clamp_w, v_max_mv_w); + v_these_mv_clamp_w = vmaxq_s16(v_these_mv_clamp_w, v_min_mv_w); + // The ones that did not change are inside the search area + v_inside_d = vreinterpretq_s8_u32( + vceqq_s32(vreinterpretq_s32_s16(v_these_mv_clamp_w), + vreinterpretq_s32_s16(v_these_mv_w))); + + // If none of them are inside, then move on +#if VPX_ARCH_AARCH64 + horiz_max = vmaxvq_u32(vreinterpretq_u32_s8(v_inside_d)); +#else + horiz_max_0 = vmax_u32(vget_low_u32(vreinterpretq_u32_s8(v_inside_d)), + vget_high_u32(vreinterpretq_u32_s8(v_inside_d))); + horiz_max_1 = vpmax_u32(horiz_max_0, horiz_max_0); + vst1_lane_u32(&horiz_max, horiz_max_1, 0); +#endif + if (LIKELY(horiz_max == 0)) { + continue; + } + + // The inverse mask indicates which of the MVs are outside + v_outside_d = + vreinterpretq_u32_s8(veorq_s8(v_inside_d, vdupq_n_s8((int8_t)0xff))); + // Shift right to keep the sign bit clear, we will use this later + // to set the cost to the maximum value. + v_outside_d = vshrq_n_u32(v_outside_d, 1); + + // Compute the difference MV + v_diff_mv_w = vsubq_s16(v_these_mv_clamp_w, vfcmv); + // We utilise the fact that the cost function is even, and use the + // absolute difference. This allows us to use unsigned indexes later + // and reduces cache pressure somewhat as only a half of the table + // is ever referenced. + v_diff_mv_w = vabsq_s16(v_diff_mv_w); + + // Compute the SIMD pointer offsets. + { +#if VPX_ARCH_AARCH64 // sizeof(intptr_t) == 8 + // Load the offsets + int64x2_t v_bo10_q = vld1q_s64((const int64_t *)&ss_os[i + 0]); + int64x2_t v_bo32_q = vld1q_s64((const int64_t *)&ss_os[i + 2]); + // Set the ones falling outside to zero + v_bo10_q = vandq_s64( + v_bo10_q, + vmovl_s32(vget_low_s32(vreinterpretq_s32_s8(v_inside_d)))); + v_bo32_q = vandq_s64( + v_bo32_q, + vmovl_s32(vget_high_s32(vreinterpretq_s32_s8(v_inside_d)))); + // Compute the candidate addresses + v_blocka[0] = vaddq_s64(v_ba_q, v_bo10_q); + v_blocka[1] = vaddq_s64(v_ba_q, v_bo32_q); +#else // sizeof(intptr_t) == 4 + int32x4_t v_bo_d = vld1q_s32((const int32_t *)&ss_os[i]); + v_bo_d = vandq_s32(v_bo_d, vreinterpretq_s32_s8(v_inside_d)); + v_blocka[0] = vaddq_s32(v_ba_d, v_bo_d); +#endif + } + + sad_fn_ptr->sdx4df(what, what_stride, (const uint8_t **)&v_blocka[0], + in_what_stride, (uint32_t *)&v_sad_d); + + // Look up the component cost of the residual motion vector + { + uint32_t cost[4]; + DECLARE_ALIGNED(16, int16_t, rowcol[8]); + vst1q_s16(rowcol, v_diff_mv_w); + + // Note: This is a use case for gather instruction + cost[0] = x->nmvsadcost[0][rowcol[0]] + x->nmvsadcost[0][rowcol[1]]; + cost[1] = x->nmvsadcost[0][rowcol[2]] + x->nmvsadcost[0][rowcol[3]]; + cost[2] = x->nmvsadcost[0][rowcol[4]] + x->nmvsadcost[0][rowcol[5]]; + cost[3] = x->nmvsadcost[0][rowcol[6]] + x->nmvsadcost[0][rowcol[7]]; + + v_cost_d = vld1q_s32((int32_t *)cost); + } + + // Now add in the joint cost + { + const uint32x4_t v_sel_d = + vceqq_s32(vreinterpretq_s32_s16(v_diff_mv_w), zero_s32); + const int32x4_t v_joint_cost_d = vreinterpretq_s32_u8( + vbslq_u8(vreinterpretq_u8_u32(v_sel_d), + vreinterpretq_u8_s32(v_joint_cost_0_d), + vreinterpretq_u8_s32(v_joint_cost_1_d))); + v_cost_d = vaddq_s32(v_cost_d, v_joint_cost_d); + } + + // Multiply by sad_per_bit + v_cost_d = vmulq_s32(v_cost_d, v_spb_d); + // ROUND_POWER_OF_TWO(v_cost_d, VP9_PROB_COST_SHIFT) + v_cost_d = + vaddq_s32(v_cost_d, vdupq_n_s32(1 << (VP9_PROB_COST_SHIFT - 1))); + v_cost_d = vshrq_n_s32(v_cost_d, VP9_PROB_COST_SHIFT); + // Add the cost to the sad + v_sad_d = vaddq_s32(v_sad_d, v_cost_d); + + // Make the motion vectors outside the search area have max cost + // by or'ing in the comparison mask, this way the minimum search won't + // pick them. + v_sad_d = vorrq_s32(v_sad_d, vreinterpretq_s32_u32(v_outside_d)); + + // Find the minimum value and index horizontally in v_sad_d + { + uint32_t local_best_sad; +#if VPX_ARCH_AARCH64 + local_best_sad = vminvq_u32(vreinterpretq_u32_s32(v_sad_d)); +#else + uint32x2_t horiz_min_0 = + vmin_u32(vget_low_u32(vreinterpretq_u32_s32(v_sad_d)), + vget_high_u32(vreinterpretq_u32_s32(v_sad_d))); + uint32x2_t horiz_min_1 = vpmin_u32(horiz_min_0, horiz_min_0); + vst1_lane_u32(&local_best_sad, horiz_min_1, 0); +#endif + + // Update the global minimum if the local minimum is smaller + if (LIKELY(local_best_sad < best_sad)) { +#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + uint32_t local_best_idx; + const uint32x4_t v_sel_d = + vceqq_s32(v_sad_d, vdupq_n_s32(local_best_sad)); + uint32x4_t v_mask_d = vandq_u32(v_sel_d, v_idx_d); + v_mask_d = vbslq_u32(v_sel_d, v_mask_d, vdupq_n_u32(0xffffffff)); + +#if VPX_ARCH_AARCH64 + local_best_idx = vminvq_u32(v_mask_d); +#else + horiz_min_0 = + vmin_u32(vget_low_u32(v_mask_d), vget_high_u32(v_mask_d)); + horiz_min_1 = vpmin_u32(horiz_min_0, horiz_min_0); + vst1_lane_u32(&local_best_idx, horiz_min_1, 0); +#endif + + new_bmv = ((const int_mv *)&v_these_mv_w)[local_best_idx]; +#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + new_best_address = ((const uint8_t **)v_blocka)[local_best_idx]; + + best_sad = local_best_sad; + } + } + } + + bmv = new_bmv; + best_address = new_best_address; + + v_bmv_w = vreinterpretq_s16_s32(vdupq_n_s32(bmv.as_int)); +#if VPX_ARCH_AARCH64 + v_ba_q = vdupq_n_s64((intptr_t)best_address); +#else + v_ba_d = vdupq_n_s32((intptr_t)best_address); +#endif + + if (UNLIKELY(best_address == in_what)) { + (*num00)++; + } + } + + *best_mv = bmv.as_mv; + return best_sad; +} diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_error_neon.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_error_neon.c index 1c7503139e..0cf0bf250e 100644 --- a/libs/libvpx/vp9/encoder/arm/neon/vp9_error_neon.c +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_error_neon.c @@ -12,30 +12,91 @@ #include #include "./vp9_rtcd.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" -int64_t vp9_block_error_fp_neon(const int16_t *coeff, const int16_t *dqcoeff, - int block_size) { - int64x2_t error = vdupq_n_s64(0); +int64_t vp9_block_error_neon(const tran_low_t *coeff, const tran_low_t *dqcoeff, + intptr_t block_size, int64_t *ssz) { + uint64x2_t err_u64 = vdupq_n_u64(0); + int64x2_t ssz_s64 = vdupq_n_s64(0); - assert(block_size >= 8); - assert((block_size % 8) == 0); + assert(block_size >= 16); + assert((block_size % 16) == 0); do { - const int16x8_t c = vld1q_s16(coeff); - const int16x8_t d = vld1q_s16(dqcoeff); - const int16x8_t diff = vsubq_s16(c, d); - const int16x4_t diff_lo = vget_low_s16(diff); - const int16x4_t diff_hi = vget_high_s16(diff); - // diff is 15-bits, the squares 30, so we can store 2 in 31-bits before + uint32x4_t err; + int32x4_t ssz0, ssz1; + + const int16x8_t c0 = load_tran_low_to_s16q(coeff); + const int16x8_t c1 = load_tran_low_to_s16q(coeff + 8); + const int16x8_t d0 = load_tran_low_to_s16q(dqcoeff); + const int16x8_t d1 = load_tran_low_to_s16q(dqcoeff + 8); + + const uint16x8_t diff0 = vreinterpretq_u16_s16(vabdq_s16(c0, d0)); + const uint16x8_t diff1 = vreinterpretq_u16_s16(vabdq_s16(c1, d1)); + + // diff is 15-bits, the squares 30, so we can store 4 in 32-bits before // accumulating them in 64-bits. - const int32x4_t err0 = vmull_s16(diff_lo, diff_lo); - const int32x4_t err1 = vmlal_s16(err0, diff_hi, diff_hi); - const int64x2_t err2 = vaddl_s32(vget_low_s32(err1), vget_high_s32(err1)); - error = vaddq_s64(error, err2); - coeff += 8; - dqcoeff += 8; - block_size -= 8; + err = vmull_u16(vget_low_u16(diff0), vget_low_u16(diff0)); + err = vmlal_u16(err, vget_high_u16(diff0), vget_high_u16(diff0)); + err = vmlal_u16(err, vget_low_u16(diff1), vget_low_u16(diff1)); + err = vmlal_u16(err, vget_high_u16(diff1), vget_high_u16(diff1)); + err_u64 = vpadalq_u32(err_u64, err); + + // We can't do the same here as we're operating on signed integers, so we + // can store 2 15-bit diff before accumulating into 64-bits. + ssz0 = vmull_s16(vget_low_s16(c0), vget_low_s16(c0)); + ssz0 = vmlal_s16(ssz0, vget_high_s16(c0), vget_high_s16(c0)); + ssz_s64 = vpadalq_s32(ssz_s64, ssz0); + + ssz1 = vmull_s16(vget_low_s16(c1), vget_low_s16(c1)); + ssz1 = vmlal_s16(ssz1, vget_high_s16(c1), vget_high_s16(c1)); + ssz_s64 = vpadalq_s32(ssz_s64, ssz1); + + coeff += 16; + dqcoeff += 16; + block_size -= 16; } while (block_size != 0); - return vgetq_lane_s64(error, 0) + vgetq_lane_s64(error, 1); + *ssz = horizontal_add_int64x2(ssz_s64); + return (int64_t)horizontal_add_uint64x2(err_u64); +} + +int64_t vp9_block_error_fp_neon(const tran_low_t *coeff, + const tran_low_t *dqcoeff, int block_size) { + uint64x2_t err_u64[2] = { vdupq_n_u64(0), vdupq_n_u64(0) }; + + assert(block_size >= 16); + assert((block_size % 16) == 0); + + do { + uint32x4_t err0, err1; + + const int16x8_t c0 = load_tran_low_to_s16q(coeff); + const int16x8_t c1 = load_tran_low_to_s16q(coeff + 8); + const int16x8_t d0 = load_tran_low_to_s16q(dqcoeff); + const int16x8_t d1 = load_tran_low_to_s16q(dqcoeff + 8); + + const uint16x8_t diff0 = vreinterpretq_u16_s16(vabdq_s16(c0, d0)); + const uint16x8_t diff1 = vreinterpretq_u16_s16(vabdq_s16(c1, d1)); + + // diff is 15-bits, the squares 30, so in theory we can store 4 in 32-bits + // before accumulating them in 64-bits. However splitting into 2 mull, mlal + // pairs is beneficial since it allows us to use both Neon + // multiply-accumulate pipes - on CPUs that have them - rather than having + // a single chain of 4 instructions executing serially. + err0 = vmull_u16(vget_low_u16(diff0), vget_low_u16(diff0)); + err0 = vmlal_u16(err0, vget_high_u16(diff0), vget_high_u16(diff0)); + err_u64[0] = vpadalq_u32(err_u64[0], err0); + + err1 = vmull_u16(vget_low_u16(diff1), vget_low_u16(diff1)); + err1 = vmlal_u16(err1, vget_high_u16(diff1), vget_high_u16(diff1)); + err_u64[1] = vpadalq_u32(err_u64[1], err1); + + coeff += 16; + dqcoeff += 16; + block_size -= 16; + } while (block_size != 0); + + return horizontal_add_uint64x2(vaddq_u64(err_u64[0], err_u64[1])); } diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_error_sve.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_error_sve.c new file mode 100644 index 0000000000..78e7361d85 --- /dev/null +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_error_sve.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vp9_rtcd.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" +#include "vpx_dsp/arm/vpx_neon_sve_bridge.h" + +int64_t vp9_block_error_sve(const tran_low_t *coeff, const tran_low_t *dqcoeff, + intptr_t block_size, int64_t *ssz) { + int64x2_t err_v = vdupq_n_s64(0); + int64x2_t ssz_v = vdupq_n_s64(0); + + assert(block_size >= 16); + assert((block_size % 16) == 0); + + do { + const int16x8_t c0 = load_tran_low_to_s16q(coeff); + const int16x8_t c1 = load_tran_low_to_s16q(coeff + 8); + + const int16x8_t d0 = load_tran_low_to_s16q(dqcoeff); + const int16x8_t d1 = load_tran_low_to_s16q(dqcoeff + 8); + + const int16x8_t diff0 = vabdq_s16(c0, d0); + const int16x8_t diff1 = vabdq_s16(c1, d1); + + err_v = vpx_dotq_s16(err_v, diff0, diff0); + err_v = vpx_dotq_s16(err_v, diff1, diff1); + + ssz_v = vpx_dotq_s16(ssz_v, c0, c0); + ssz_v = vpx_dotq_s16(ssz_v, c1, c1); + + coeff += 16; + dqcoeff += 16; + block_size -= 16; + } while (block_size != 0); + + *ssz = horizontal_add_int64x2(ssz_v); + return horizontal_add_int64x2(err_v); +} + +int64_t vp9_block_error_fp_sve(const tran_low_t *coeff, + const tran_low_t *dqcoeff, int block_size) { + int64x2_t err = vdupq_n_s64(0); + + assert(block_size >= 16); + assert((block_size % 16) == 0); + + do { + const int16x8_t c0 = load_tran_low_to_s16q(coeff); + const int16x8_t c1 = load_tran_low_to_s16q(coeff + 8); + + const int16x8_t d0 = load_tran_low_to_s16q(dqcoeff); + const int16x8_t d1 = load_tran_low_to_s16q(dqcoeff + 8); + + const int16x8_t diff0 = vabdq_s16(c0, d0); + const int16x8_t diff1 = vabdq_s16(c1, d1); + + err = vpx_dotq_s16(err, diff0, diff0); + err = vpx_dotq_s16(err, diff1, diff1); + + coeff += 16; + dqcoeff += 16; + block_size -= 16; + } while (block_size != 0); + + return horizontal_add_int64x2(err); +} diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_frame_scale_neon.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_frame_scale_neon.c index e46f789bac..bc8dd4a341 100644 --- a/libs/libvpx/vp9/encoder/arm/neon/vp9_frame_scale_neon.c +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_frame_scale_neon.c @@ -14,6 +14,7 @@ #include "./vpx_dsp_rtcd.h" #include "./vpx_scale_rtcd.h" #include "vp9/common/vp9_blockd.h" +#include "vpx_dsp/arm/mem_neon.h" #include "vpx_dsp/arm/transpose_neon.h" #include "vpx_dsp/arm/vpx_convolve8_neon.h" #include "vpx_dsp/vpx_filter.h" @@ -710,8 +711,8 @@ void vp9_scale_and_extend_frame_neon(const YV12_BUFFER_CONFIG *src, const int src_h = src->y_crop_height; const int dst_w = dst->y_crop_width; const int dst_h = dst->y_crop_height; - const int dst_uv_w = dst_w / 2; - const int dst_uv_h = dst_h / 2; + const int dst_uv_w = dst->uv_crop_width; + const int dst_uv_h = dst->uv_crop_height; int scaled = 0; // phase_scaler is usually 0 or 8. diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_error_neon.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_error_neon.c new file mode 100644 index 0000000000..d9b183472d --- /dev/null +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_error_neon.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vp9_rtcd.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" + +int64_t vp9_highbd_block_error_neon(const tran_low_t *coeff, + const tran_low_t *dqcoeff, + intptr_t block_size, int64_t *ssz, int bd) { + uint64x2_t err_u64 = vdupq_n_u64(0); + int64x2_t ssz_s64 = vdupq_n_s64(0); + + const int shift = 2 * (bd - 8); + const int rounding = shift > 0 ? 1 << (shift - 1) : 0; + + assert(block_size >= 16); + assert((block_size % 16) == 0); + + do { + const int32x4_t c = load_tran_low_to_s32q(coeff); + const int32x4_t d = load_tran_low_to_s32q(dqcoeff); + + const uint32x4_t diff = vreinterpretq_u32_s32(vabdq_s32(c, d)); + + err_u64 = vmlal_u32(err_u64, vget_low_u32(diff), vget_low_u32(diff)); + err_u64 = vmlal_u32(err_u64, vget_high_u32(diff), vget_high_u32(diff)); + + ssz_s64 = vmlal_s32(ssz_s64, vget_low_s32(c), vget_low_s32(c)); + ssz_s64 = vmlal_s32(ssz_s64, vget_high_s32(c), vget_high_s32(c)); + + coeff += 4; + dqcoeff += 4; + block_size -= 4; + } while (block_size != 0); + + *ssz = (horizontal_add_int64x2(ssz_s64) + rounding) >> shift; + return ((int64_t)horizontal_add_uint64x2(err_u64) + rounding) >> shift; +} diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_temporal_filter_neon.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_temporal_filter_neon.c new file mode 100644 index 0000000000..f990a747ed --- /dev/null +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_temporal_filter_neon.c @@ -0,0 +1,1076 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vp9_rtcd.h" +#include "./vpx_config.h" +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/transpose_neon.h" +#include "vp9/encoder/vp9_encoder.h" +#include "vp9/encoder/vp9_temporal_filter.h" +#include "vp9/encoder/vp9_temporal_filter_constants.h" + +// Compute (a-b)**2 for 8 pixels with size 16-bit +static INLINE void highbd_store_dist_8(const uint16_t *a, const uint16_t *b, + uint32_t *dst) { + const uint16x8_t a_reg = vld1q_u16(a); + const uint16x8_t b_reg = vld1q_u16(b); + + uint16x8_t dist = vabdq_u16(a_reg, b_reg); + uint32x4_t dist_first = vmull_u16(vget_low_u16(dist), vget_low_u16(dist)); + uint32x4_t dist_second = vmull_u16(vget_high_u16(dist), vget_high_u16(dist)); + + vst1q_u32(dst, dist_first); + vst1q_u32(dst + 4, dist_second); +} + +// Sum up three neighboring distortions for the pixels +static INLINE void highbd_get_sum_4(const uint32_t *dist, uint32x4_t *sum) { + uint32x4_t dist_reg, dist_left, dist_right; + + dist_reg = vld1q_u32(dist); + dist_left = vld1q_u32(dist - 1); + dist_right = vld1q_u32(dist + 1); + + *sum = vaddq_u32(dist_reg, dist_left); + *sum = vaddq_u32(*sum, dist_right); +} + +static INLINE void highbd_get_sum_8(const uint32_t *dist, uint32x4_t *sum_first, + uint32x4_t *sum_second) { + highbd_get_sum_4(dist, sum_first); + highbd_get_sum_4(dist + 4, sum_second); +} + +// Average the value based on the number of values summed (9 for pixels away +// from the border, 4 for pixels in corners, and 6 for other edge values, plus +// however many values from y/uv plane are). +// +// Add in the rounding factor and shift, clamp to 16, invert and shift. Multiply +// by weight. +static INLINE void highbd_average_4(uint32x4_t *output, const uint32x4_t sum, + const uint32x4_t *mul_constants, + const int strength, const int rounding, + const int weight) { + const int64x2_t strength_s64 = vdupq_n_s64(-strength - 32); + const uint64x2_t rounding_u64 = vdupq_n_u64((uint64_t)rounding << 32); + const uint32x4_t weight_u32 = vdupq_n_u32(weight); + const uint32x4_t sixteen = vdupq_n_u32(16); + uint32x4_t sum2; + + // modifier * 3 / index; + uint64x2_t sum_lo = + vmlal_u32(rounding_u64, vget_low_u32(sum), vget_low_u32(*mul_constants)); + uint64x2_t sum_hi = vmlal_u32(rounding_u64, vget_high_u32(sum), + vget_high_u32(*mul_constants)); + + // we cannot use vshrn_n_u64 as strength is not known at compile time. + sum_lo = vshlq_u64(sum_lo, strength_s64); + sum_hi = vshlq_u64(sum_hi, strength_s64); + + sum2 = vcombine_u32(vmovn_u64(sum_lo), vmovn_u64(sum_hi)); + + // Multiply with the weight + sum2 = vminq_u32(sum2, sixteen); + sum2 = vsubq_u32(sixteen, sum2); + *output = vmulq_u32(sum2, weight_u32); +} + +static INLINE void highbd_average_8(uint32x4_t *output_0, uint32x4_t *output_1, + const uint32x4_t sum_0_u32, + const uint32x4_t sum_1_u32, + const uint32x4_t *mul_constants_0, + const uint32x4_t *mul_constants_1, + const int strength, const int rounding, + const int weight) { + highbd_average_4(output_0, sum_0_u32, mul_constants_0, strength, rounding, + weight); + highbd_average_4(output_1, sum_1_u32, mul_constants_1, strength, rounding, + weight); +} + +// Add 'sum_u32' to 'count'. Multiply by 'pred' and add to 'accumulator.' +static INLINE void highbd_accumulate_and_store_8( + const uint32x4_t sum_first_u32, const uint32x4_t sum_second_u32, + const uint16_t *pred, uint16_t *count, uint32_t *accumulator) { + const uint16x8_t sum_u16 = + vcombine_u16(vqmovn_u32(sum_first_u32), vqmovn_u32(sum_second_u32)); + uint16x8_t pred_u16 = vld1q_u16(pred); + uint16x8_t count_u16 = vld1q_u16(count); + uint32x4_t pred_0_u32, pred_1_u32; + uint32x4_t accum_0_u32, accum_1_u32; + + count_u16 = vqaddq_u16(count_u16, sum_u16); + vst1q_u16(count, count_u16); + + accum_0_u32 = vld1q_u32(accumulator); + accum_1_u32 = vld1q_u32(accumulator + 4); + + pred_0_u32 = vmovl_u16(vget_low_u16(pred_u16)); + pred_1_u32 = vmovl_u16(vget_high_u16(pred_u16)); + + // Don't use sum_u16 as that produces different results to the C version + accum_0_u32 = vmlaq_u32(accum_0_u32, sum_first_u32, pred_0_u32); + accum_1_u32 = vmlaq_u32(accum_1_u32, sum_second_u32, pred_1_u32); + + vst1q_u32(accumulator, accum_0_u32); + vst1q_u32(accumulator + 4, accum_1_u32); +} + +static INLINE void highbd_read_dist_4(const uint32_t *dist, + uint32x4_t *dist_reg) { + *dist_reg = vld1q_u32(dist); +} + +static INLINE void highbd_read_dist_8(const uint32_t *dist, + uint32x4_t *reg_first, + uint32x4_t *reg_second) { + highbd_read_dist_4(dist, reg_first); + highbd_read_dist_4(dist + 4, reg_second); +} + +static INLINE void highbd_read_chroma_dist_row_8( + int ss_x, const uint32_t *u_dist, const uint32_t *v_dist, + uint32x4_t *u_first, uint32x4_t *u_second, uint32x4_t *v_first, + uint32x4_t *v_second) { + if (!ss_x) { + // If there is no chroma subsampling in the horizontal direction, then we + // need to load 8 entries from chroma. + highbd_read_dist_8(u_dist, u_first, u_second); + highbd_read_dist_8(v_dist, v_first, v_second); + } else { // ss_x == 1 + // Otherwise, we only need to load 8 entries + uint32x4_t u_reg, v_reg; + uint32x4x2_t pair; + + highbd_read_dist_4(u_dist, &u_reg); + + pair = vzipq_u32(u_reg, u_reg); + *u_first = pair.val[0]; + *u_second = pair.val[1]; + + highbd_read_dist_4(v_dist, &v_reg); + + pair = vzipq_u32(v_reg, v_reg); + *v_first = pair.val[0]; + *v_second = pair.val[1]; + } +} + +static void highbd_apply_temporal_filter_luma_8( + const uint16_t *y_pre, int y_pre_stride, unsigned int block_width, + unsigned int block_height, int ss_x, int ss_y, int strength, + int use_whole_blk, uint32_t *y_accum, uint16_t *y_count, + const uint32_t *y_dist, const uint32_t *u_dist, const uint32_t *v_dist, + const uint32_t *const *neighbors_first, + const uint32_t *const *neighbors_second, int top_weight, + int bottom_weight) { + const int rounding = (1 << strength) >> 1; + int weight = top_weight; + + uint32x4_t mul_first, mul_second; + + uint32x4_t sum_row_1_first, sum_row_1_second; + uint32x4_t sum_row_2_first, sum_row_2_second; + uint32x4_t sum_row_3_first, sum_row_3_second; + + uint32x4_t u_first, u_second; + uint32x4_t v_first, v_second; + + uint32x4_t sum_row_first; + uint32x4_t sum_row_second; + + // Loop variables + unsigned int h; + + assert(strength >= 4 && strength <= 14 && + "invalid adjusted temporal filter strength"); + assert(block_width == 8); + + (void)block_width; + + // First row + mul_first = vld1q_u32(neighbors_first[0]); + mul_second = vld1q_u32(neighbors_second[0]); + + // Add luma values + highbd_get_sum_8(y_dist, &sum_row_2_first, &sum_row_2_second); + highbd_get_sum_8(y_dist + DIST_STRIDE, &sum_row_3_first, &sum_row_3_second); + + // We don't need to saturate here because the maximum value is UINT12_MAX ** 2 + // * 9 ~= 2**24 * 9 < 2 ** 28 < INT32_MAX + sum_row_first = vaddq_u32(sum_row_2_first, sum_row_3_first); + sum_row_second = vaddq_u32(sum_row_2_second, sum_row_3_second); + + // Add chroma values + highbd_read_chroma_dist_row_8(ss_x, u_dist, v_dist, &u_first, &u_second, + &v_first, &v_second); + + // Max value here is 2 ** 24 * (9 + 2), so no saturation is needed + sum_row_first = vaddq_u32(sum_row_first, u_first); + sum_row_second = vaddq_u32(sum_row_second, u_second); + + sum_row_first = vaddq_u32(sum_row_first, v_first); + sum_row_second = vaddq_u32(sum_row_second, v_second); + + // Get modifier and store result + highbd_average_8(&sum_row_first, &sum_row_second, sum_row_first, + sum_row_second, &mul_first, &mul_second, strength, rounding, + weight); + + highbd_accumulate_and_store_8(sum_row_first, sum_row_second, y_pre, y_count, + y_accum); + + y_pre += y_pre_stride; + y_count += y_pre_stride; + y_accum += y_pre_stride; + y_dist += DIST_STRIDE; + + u_dist += DIST_STRIDE; + v_dist += DIST_STRIDE; + + // Then all the rows except the last one + mul_first = vld1q_u32(neighbors_first[1]); + mul_second = vld1q_u32(neighbors_second[1]); + + for (h = 1; h < block_height - 1; ++h) { + // Move the weight to bottom half + if (!use_whole_blk && h == block_height / 2) { + weight = bottom_weight; + } + // Shift the rows up + sum_row_1_first = sum_row_2_first; + sum_row_1_second = sum_row_2_second; + sum_row_2_first = sum_row_3_first; + sum_row_2_second = sum_row_3_second; + + // Add luma values to the modifier + sum_row_first = vaddq_u32(sum_row_1_first, sum_row_2_first); + sum_row_second = vaddq_u32(sum_row_1_second, sum_row_2_second); + + highbd_get_sum_8(y_dist + DIST_STRIDE, &sum_row_3_first, &sum_row_3_second); + + sum_row_first = vaddq_u32(sum_row_first, sum_row_3_first); + sum_row_second = vaddq_u32(sum_row_second, sum_row_3_second); + + // Add chroma values to the modifier + if (ss_y == 0 || h % 2 == 0) { + // Only calculate the new chroma distortion if we are at a pixel that + // corresponds to a new chroma row + highbd_read_chroma_dist_row_8(ss_x, u_dist, v_dist, &u_first, &u_second, + &v_first, &v_second); + + u_dist += DIST_STRIDE; + v_dist += DIST_STRIDE; + } + + sum_row_first = vaddq_u32(sum_row_first, u_first); + sum_row_second = vaddq_u32(sum_row_second, u_second); + sum_row_first = vaddq_u32(sum_row_first, v_first); + sum_row_second = vaddq_u32(sum_row_second, v_second); + + // Get modifier and store result + highbd_average_8(&sum_row_first, &sum_row_second, sum_row_first, + sum_row_second, &mul_first, &mul_second, strength, + rounding, weight); + highbd_accumulate_and_store_8(sum_row_first, sum_row_second, y_pre, y_count, + y_accum); + + y_pre += y_pre_stride; + y_count += y_pre_stride; + y_accum += y_pre_stride; + y_dist += DIST_STRIDE; + } + + // The last row + mul_first = vld1q_u32(neighbors_first[0]); + mul_second = vld1q_u32(neighbors_second[0]); + + // Shift the rows up + sum_row_1_first = sum_row_2_first; + sum_row_1_second = sum_row_2_second; + sum_row_2_first = sum_row_3_first; + sum_row_2_second = sum_row_3_second; + + // Add luma values to the modifier + sum_row_first = vaddq_u32(sum_row_1_first, sum_row_2_first); + sum_row_second = vaddq_u32(sum_row_1_second, sum_row_2_second); + + // Add chroma values to the modifier + if (ss_y == 0) { + // Only calculate the new chroma distortion if we are at a pixel that + // corresponds to a new chroma row + highbd_read_chroma_dist_row_8(ss_x, u_dist, v_dist, &u_first, &u_second, + &v_first, &v_second); + } + + sum_row_first = vaddq_u32(sum_row_first, u_first); + sum_row_second = vaddq_u32(sum_row_second, u_second); + sum_row_first = vaddq_u32(sum_row_first, v_first); + sum_row_second = vaddq_u32(sum_row_second, v_second); + + // Get modifier and store result + highbd_average_8(&sum_row_first, &sum_row_second, sum_row_first, + sum_row_second, &mul_first, &mul_second, strength, rounding, + weight); + highbd_accumulate_and_store_8(sum_row_first, sum_row_second, y_pre, y_count, + y_accum); +} + +// Perform temporal filter for the luma component. +static void highbd_apply_temporal_filter_luma( + const uint16_t *y_pre, int y_pre_stride, unsigned int block_width, + unsigned int block_height, int ss_x, int ss_y, int strength, + const int *blk_fw, int use_whole_blk, uint32_t *y_accum, uint16_t *y_count, + const uint32_t *y_dist, const uint32_t *u_dist, const uint32_t *v_dist) { + unsigned int blk_col = 0, uv_blk_col = 0; + const unsigned int blk_col_step = 8, uv_blk_col_step = 8 >> ss_x; + const unsigned int mid_width = block_width >> 1, + last_width = block_width - blk_col_step; + int top_weight = blk_fw[0], + bottom_weight = use_whole_blk ? blk_fw[0] : blk_fw[2]; + const uint32_t *const *neighbors_first; + const uint32_t *const *neighbors_second; + + // Left + neighbors_first = HIGHBD_LUMA_LEFT_COLUMN_NEIGHBORS; + neighbors_second = HIGHBD_LUMA_MIDDLE_COLUMN_NEIGHBORS; + highbd_apply_temporal_filter_luma_8( + y_pre + blk_col, y_pre_stride, blk_col_step, block_height, ss_x, ss_y, + strength, use_whole_blk, y_accum + blk_col, y_count + blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, + neighbors_first, neighbors_second, top_weight, bottom_weight); + + blk_col += blk_col_step; + uv_blk_col += uv_blk_col_step; + + // Middle First + neighbors_first = HIGHBD_LUMA_MIDDLE_COLUMN_NEIGHBORS; + for (; blk_col < mid_width; + blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { + highbd_apply_temporal_filter_luma_8( + y_pre + blk_col, y_pre_stride, blk_col_step, block_height, ss_x, ss_y, + strength, use_whole_blk, y_accum + blk_col, y_count + blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, + neighbors_first, neighbors_second, top_weight, bottom_weight); + } + + if (!use_whole_blk) { + top_weight = blk_fw[1]; + bottom_weight = blk_fw[3]; + } + + // Middle Second + for (; blk_col < last_width; + blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { + highbd_apply_temporal_filter_luma_8( + y_pre + blk_col, y_pre_stride, blk_col_step, block_height, ss_x, ss_y, + strength, use_whole_blk, y_accum + blk_col, y_count + blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, + neighbors_first, neighbors_second, top_weight, bottom_weight); + } + + // Right + neighbors_second = HIGHBD_LUMA_RIGHT_COLUMN_NEIGHBORS; + highbd_apply_temporal_filter_luma_8( + y_pre + blk_col, y_pre_stride, blk_col_step, block_height, ss_x, ss_y, + strength, use_whole_blk, y_accum + blk_col, y_count + blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, + neighbors_first, neighbors_second, top_weight, bottom_weight); +} + +// Add a row of luma distortion that corresponds to 8 chroma mods. If we are +// subsampling in x direction, then we have 16 lumas, else we have 8. +static INLINE void highbd_add_luma_dist_to_8_chroma_mod( + const uint32_t *y_dist, int ss_x, int ss_y, uint32x4_t *u_mod_fst, + uint32x4_t *u_mod_snd, uint32x4_t *v_mod_fst, uint32x4_t *v_mod_snd) { + uint32x4_t y_reg_fst, y_reg_snd; + if (!ss_x) { + highbd_read_dist_8(y_dist, &y_reg_fst, &y_reg_snd); + if (ss_y == 1) { + uint32x4_t y_tmp_fst, y_tmp_snd; + highbd_read_dist_8(y_dist + DIST_STRIDE, &y_tmp_fst, &y_tmp_snd); + y_reg_fst = vaddq_u32(y_reg_fst, y_tmp_fst); + y_reg_snd = vaddq_u32(y_reg_snd, y_tmp_snd); + } + } else { + // Temporary + uint32x4_t y_fst, y_snd; + uint64x2_t y_fst64, y_snd64; + + // First 8 + highbd_read_dist_8(y_dist, &y_fst, &y_snd); + if (ss_y == 1) { + uint32x4_t y_tmp_fst, y_tmp_snd; + highbd_read_dist_8(y_dist + DIST_STRIDE, &y_tmp_fst, &y_tmp_snd); + + y_fst = vaddq_u32(y_fst, y_tmp_fst); + y_snd = vaddq_u32(y_snd, y_tmp_snd); + } + + y_fst64 = vpaddlq_u32(y_fst); + y_snd64 = vpaddlq_u32(y_snd); + y_reg_fst = vcombine_u32(vqmovn_u64(y_fst64), vqmovn_u64(y_snd64)); + + // Second 8 + highbd_read_dist_8(y_dist + 8, &y_fst, &y_snd); + if (ss_y == 1) { + uint32x4_t y_tmp_fst, y_tmp_snd; + highbd_read_dist_8(y_dist + 8 + DIST_STRIDE, &y_tmp_fst, &y_tmp_snd); + + y_fst = vaddq_u32(y_fst, y_tmp_fst); + y_snd = vaddq_u32(y_snd, y_tmp_snd); + } + + y_fst64 = vpaddlq_u32(y_fst); + y_snd64 = vpaddlq_u32(y_snd); + y_reg_snd = vcombine_u32(vqmovn_u64(y_fst64), vqmovn_u64(y_snd64)); + } + + *u_mod_fst = vaddq_u32(*u_mod_fst, y_reg_fst); + *u_mod_snd = vaddq_u32(*u_mod_snd, y_reg_snd); + *v_mod_fst = vaddq_u32(*v_mod_fst, y_reg_fst); + *v_mod_snd = vaddq_u32(*v_mod_snd, y_reg_snd); +} + +// Apply temporal filter to the chroma components. This performs temporal +// filtering on a chroma block of 8 X uv_height. If blk_fw is not NULL, use +// blk_fw as an array of size 4 for the weights for each of the 4 subblocks, +// else use top_weight for top half, and bottom weight for bottom half. +static void highbd_apply_temporal_filter_chroma_8( + const uint16_t *u_pre, const uint16_t *v_pre, int uv_pre_stride, + unsigned int uv_block_width, unsigned int uv_block_height, int ss_x, + int ss_y, int strength, uint32_t *u_accum, uint16_t *u_count, + uint32_t *v_accum, uint16_t *v_count, const uint32_t *y_dist, + const uint32_t *u_dist, const uint32_t *v_dist, + const uint32_t *const *neighbors_fst, const uint32_t *const *neighbors_snd, + int top_weight, int bottom_weight, const int *blk_fw) { + const int rounding = (1 << strength) >> 1; + int weight = top_weight; + + uint32x4_t mul_fst, mul_snd; + + uint32x4_t u_sum_row_1_fst, u_sum_row_2_fst, u_sum_row_3_fst; + uint32x4_t v_sum_row_1_fst, v_sum_row_2_fst, v_sum_row_3_fst; + uint32x4_t u_sum_row_1_snd, u_sum_row_2_snd, u_sum_row_3_snd; + uint32x4_t v_sum_row_1_snd, v_sum_row_2_snd, v_sum_row_3_snd; + + uint32x4_t u_sum_row_fst, v_sum_row_fst; + uint32x4_t u_sum_row_snd, v_sum_row_snd; + + // Loop variable + unsigned int h; + + (void)uv_block_width; + + // First row + mul_fst = vld1q_u32(neighbors_fst[0]); + mul_snd = vld1q_u32(neighbors_snd[0]); + + // Add chroma values + highbd_get_sum_8(u_dist, &u_sum_row_2_fst, &u_sum_row_2_snd); + highbd_get_sum_8(u_dist + DIST_STRIDE, &u_sum_row_3_fst, &u_sum_row_3_snd); + + u_sum_row_fst = vaddq_u32(u_sum_row_2_fst, u_sum_row_3_fst); + u_sum_row_snd = vaddq_u32(u_sum_row_2_snd, u_sum_row_3_snd); + + highbd_get_sum_8(v_dist, &v_sum_row_2_fst, &v_sum_row_2_snd); + highbd_get_sum_8(v_dist + DIST_STRIDE, &v_sum_row_3_fst, &v_sum_row_3_snd); + + v_sum_row_fst = vaddq_u32(v_sum_row_2_fst, v_sum_row_3_fst); + v_sum_row_snd = vaddq_u32(v_sum_row_2_snd, v_sum_row_3_snd); + + // Add luma values + highbd_add_luma_dist_to_8_chroma_mod(y_dist, ss_x, ss_y, &u_sum_row_fst, + &u_sum_row_snd, &v_sum_row_fst, + &v_sum_row_snd); + + // Get modifier and store result + if (blk_fw) { + highbd_average_4(&u_sum_row_fst, u_sum_row_fst, &mul_fst, strength, + rounding, blk_fw[0]); + highbd_average_4(&u_sum_row_snd, u_sum_row_snd, &mul_snd, strength, + rounding, blk_fw[1]); + + highbd_average_4(&v_sum_row_fst, v_sum_row_fst, &mul_fst, strength, + rounding, blk_fw[0]); + highbd_average_4(&v_sum_row_snd, v_sum_row_snd, &mul_snd, strength, + rounding, blk_fw[1]); + + } else { + highbd_average_8(&u_sum_row_fst, &u_sum_row_snd, u_sum_row_fst, + u_sum_row_snd, &mul_fst, &mul_snd, strength, rounding, + weight); + highbd_average_8(&v_sum_row_fst, &v_sum_row_snd, v_sum_row_fst, + v_sum_row_snd, &mul_fst, &mul_snd, strength, rounding, + weight); + } + highbd_accumulate_and_store_8(u_sum_row_fst, u_sum_row_snd, u_pre, u_count, + u_accum); + highbd_accumulate_and_store_8(v_sum_row_fst, v_sum_row_snd, v_pre, v_count, + v_accum); + + u_pre += uv_pre_stride; + u_dist += DIST_STRIDE; + v_pre += uv_pre_stride; + v_dist += DIST_STRIDE; + u_count += uv_pre_stride; + u_accum += uv_pre_stride; + v_count += uv_pre_stride; + v_accum += uv_pre_stride; + + y_dist += DIST_STRIDE * (1 + ss_y); + + // Then all the rows except the last one + mul_fst = vld1q_u32(neighbors_fst[1]); + mul_snd = vld1q_u32(neighbors_snd[1]); + + for (h = 1; h < uv_block_height - 1; ++h) { + // Move the weight pointer to the bottom half of the blocks + if (h == uv_block_height / 2) { + if (blk_fw) { + blk_fw += 2; + } else { + weight = bottom_weight; + } + } + + // Shift the rows up + u_sum_row_1_fst = u_sum_row_2_fst; + u_sum_row_2_fst = u_sum_row_3_fst; + u_sum_row_1_snd = u_sum_row_2_snd; + u_sum_row_2_snd = u_sum_row_3_snd; + + v_sum_row_1_fst = v_sum_row_2_fst; + v_sum_row_2_fst = v_sum_row_3_fst; + v_sum_row_1_snd = v_sum_row_2_snd; + v_sum_row_2_snd = v_sum_row_3_snd; + + // Add chroma values + u_sum_row_fst = vaddq_u32(u_sum_row_1_fst, u_sum_row_2_fst); + u_sum_row_snd = vaddq_u32(u_sum_row_1_snd, u_sum_row_2_snd); + highbd_get_sum_8(u_dist + DIST_STRIDE, &u_sum_row_3_fst, &u_sum_row_3_snd); + u_sum_row_fst = vaddq_u32(u_sum_row_fst, u_sum_row_3_fst); + u_sum_row_snd = vaddq_u32(u_sum_row_snd, u_sum_row_3_snd); + + v_sum_row_fst = vaddq_u32(v_sum_row_1_fst, v_sum_row_2_fst); + v_sum_row_snd = vaddq_u32(v_sum_row_1_snd, v_sum_row_2_snd); + highbd_get_sum_8(v_dist + DIST_STRIDE, &v_sum_row_3_fst, &v_sum_row_3_snd); + v_sum_row_fst = vaddq_u32(v_sum_row_fst, v_sum_row_3_fst); + v_sum_row_snd = vaddq_u32(v_sum_row_snd, v_sum_row_3_snd); + + // Add luma values + highbd_add_luma_dist_to_8_chroma_mod(y_dist, ss_x, ss_y, &u_sum_row_fst, + &u_sum_row_snd, &v_sum_row_fst, + &v_sum_row_snd); + + // Get modifier and store result + if (blk_fw) { + highbd_average_4(&u_sum_row_fst, u_sum_row_fst, &mul_fst, strength, + rounding, blk_fw[0]); + highbd_average_4(&u_sum_row_snd, u_sum_row_snd, &mul_snd, strength, + rounding, blk_fw[1]); + + highbd_average_4(&v_sum_row_fst, v_sum_row_fst, &mul_fst, strength, + rounding, blk_fw[0]); + highbd_average_4(&v_sum_row_snd, v_sum_row_snd, &mul_snd, strength, + rounding, blk_fw[1]); + + } else { + highbd_average_8(&u_sum_row_fst, &u_sum_row_snd, u_sum_row_fst, + u_sum_row_snd, &mul_fst, &mul_snd, strength, rounding, + weight); + highbd_average_8(&v_sum_row_fst, &v_sum_row_snd, v_sum_row_fst, + v_sum_row_snd, &mul_fst, &mul_snd, strength, rounding, + weight); + } + + highbd_accumulate_and_store_8(u_sum_row_fst, u_sum_row_snd, u_pre, u_count, + u_accum); + highbd_accumulate_and_store_8(v_sum_row_fst, v_sum_row_snd, v_pre, v_count, + v_accum); + + u_pre += uv_pre_stride; + u_dist += DIST_STRIDE; + v_pre += uv_pre_stride; + v_dist += DIST_STRIDE; + u_count += uv_pre_stride; + u_accum += uv_pre_stride; + v_count += uv_pre_stride; + v_accum += uv_pre_stride; + + y_dist += DIST_STRIDE * (1 + ss_y); + } + + // The last row + mul_fst = vld1q_u32(neighbors_fst[0]); + mul_snd = vld1q_u32(neighbors_snd[0]); + + // Shift the rows up + u_sum_row_1_fst = u_sum_row_2_fst; + u_sum_row_2_fst = u_sum_row_3_fst; + u_sum_row_1_snd = u_sum_row_2_snd; + u_sum_row_2_snd = u_sum_row_3_snd; + + v_sum_row_1_fst = v_sum_row_2_fst; + v_sum_row_2_fst = v_sum_row_3_fst; + v_sum_row_1_snd = v_sum_row_2_snd; + v_sum_row_2_snd = v_sum_row_3_snd; + + // Add chroma values + u_sum_row_fst = vaddq_u32(u_sum_row_1_fst, u_sum_row_2_fst); + v_sum_row_fst = vaddq_u32(v_sum_row_1_fst, v_sum_row_2_fst); + u_sum_row_snd = vaddq_u32(u_sum_row_1_snd, u_sum_row_2_snd); + v_sum_row_snd = vaddq_u32(v_sum_row_1_snd, v_sum_row_2_snd); + + // Add luma values + highbd_add_luma_dist_to_8_chroma_mod(y_dist, ss_x, ss_y, &u_sum_row_fst, + &u_sum_row_snd, &v_sum_row_fst, + &v_sum_row_snd); + + // Get modifier and store result + if (blk_fw) { + highbd_average_4(&u_sum_row_fst, u_sum_row_fst, &mul_fst, strength, + rounding, blk_fw[0]); + highbd_average_4(&u_sum_row_snd, u_sum_row_snd, &mul_snd, strength, + rounding, blk_fw[1]); + + highbd_average_4(&v_sum_row_fst, v_sum_row_fst, &mul_fst, strength, + rounding, blk_fw[0]); + highbd_average_4(&v_sum_row_snd, v_sum_row_snd, &mul_snd, strength, + rounding, blk_fw[1]); + + } else { + highbd_average_8(&u_sum_row_fst, &u_sum_row_snd, u_sum_row_fst, + u_sum_row_snd, &mul_fst, &mul_snd, strength, rounding, + weight); + highbd_average_8(&v_sum_row_fst, &v_sum_row_snd, v_sum_row_fst, + v_sum_row_snd, &mul_fst, &mul_snd, strength, rounding, + weight); + } + + highbd_accumulate_and_store_8(u_sum_row_fst, u_sum_row_snd, u_pre, u_count, + u_accum); + highbd_accumulate_and_store_8(v_sum_row_fst, v_sum_row_snd, v_pre, v_count, + v_accum); +} + +// Perform temporal filter for the chroma components. +static void highbd_apply_temporal_filter_chroma( + const uint16_t *u_pre, const uint16_t *v_pre, int uv_pre_stride, + unsigned int block_width, unsigned int block_height, int ss_x, int ss_y, + int strength, const int *blk_fw, int use_whole_blk, uint32_t *u_accum, + uint16_t *u_count, uint32_t *v_accum, uint16_t *v_count, + const uint32_t *y_dist, const uint32_t *u_dist, const uint32_t *v_dist) { + const unsigned int uv_width = block_width >> ss_x, + uv_height = block_height >> ss_y; + + unsigned int blk_col = 0, uv_blk_col = 0; + const unsigned int uv_blk_col_step = 8, blk_col_step = 8 << ss_x; + const unsigned int uv_mid_width = uv_width >> 1, + uv_last_width = uv_width - uv_blk_col_step; + int top_weight = blk_fw[0], + bottom_weight = use_whole_blk ? blk_fw[0] : blk_fw[2]; + const uint32_t *const *neighbors_fst; + const uint32_t *const *neighbors_snd; + + if (uv_width == 8) { + // Special Case: We are subsampling in x direction on a 16x16 block. Since + // we are operating on a row of 8 chroma pixels, we can't use the usual + // left-middle-right pattern. + assert(ss_x); + + if (ss_y) { + neighbors_fst = HIGHBD_CHROMA_DOUBLE_SS_LEFT_COLUMN_NEIGHBORS; + neighbors_snd = HIGHBD_CHROMA_DOUBLE_SS_RIGHT_COLUMN_NEIGHBORS; + } else { + neighbors_fst = HIGHBD_CHROMA_SINGLE_SS_LEFT_COLUMN_NEIGHBORS; + neighbors_snd = HIGHBD_CHROMA_SINGLE_SS_RIGHT_COLUMN_NEIGHBORS; + } + + if (use_whole_blk) { + highbd_apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, + uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, + u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, + neighbors_fst, neighbors_snd, top_weight, bottom_weight, NULL); + } else { + highbd_apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, + uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, + u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, + neighbors_fst, neighbors_snd, 0, 0, blk_fw); + } + + return; + } + + // Left + if (ss_x && ss_y) { + neighbors_fst = HIGHBD_CHROMA_DOUBLE_SS_LEFT_COLUMN_NEIGHBORS; + neighbors_snd = HIGHBD_CHROMA_DOUBLE_SS_MIDDLE_COLUMN_NEIGHBORS; + } else if (ss_x || ss_y) { + neighbors_fst = HIGHBD_CHROMA_SINGLE_SS_LEFT_COLUMN_NEIGHBORS; + neighbors_snd = HIGHBD_CHROMA_SINGLE_SS_MIDDLE_COLUMN_NEIGHBORS; + } else { + neighbors_fst = HIGHBD_CHROMA_NO_SS_LEFT_COLUMN_NEIGHBORS; + neighbors_snd = HIGHBD_CHROMA_NO_SS_MIDDLE_COLUMN_NEIGHBORS; + } + + highbd_apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, + uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, + u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_fst, + neighbors_snd, top_weight, bottom_weight, NULL); + + blk_col += blk_col_step; + uv_blk_col += uv_blk_col_step; + + // Middle First + if (ss_x && ss_y) { + neighbors_fst = HIGHBD_CHROMA_DOUBLE_SS_MIDDLE_COLUMN_NEIGHBORS; + } else if (ss_x || ss_y) { + neighbors_fst = HIGHBD_CHROMA_SINGLE_SS_MIDDLE_COLUMN_NEIGHBORS; + } else { + neighbors_fst = HIGHBD_CHROMA_NO_SS_MIDDLE_COLUMN_NEIGHBORS; + } + + for (; uv_blk_col < uv_mid_width; + blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { + highbd_apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, + uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, + u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, + neighbors_fst, neighbors_snd, top_weight, bottom_weight, NULL); + } + + if (!use_whole_blk) { + top_weight = blk_fw[1]; + bottom_weight = blk_fw[3]; + } + + // Middle Second + for (; uv_blk_col < uv_last_width; + blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { + highbd_apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, + uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, + u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, + neighbors_fst, neighbors_snd, top_weight, bottom_weight, NULL); + } + + // Right + if (ss_x && ss_y) { + neighbors_snd = HIGHBD_CHROMA_DOUBLE_SS_RIGHT_COLUMN_NEIGHBORS; + } else if (ss_x || ss_y) { + neighbors_snd = HIGHBD_CHROMA_SINGLE_SS_RIGHT_COLUMN_NEIGHBORS; + } else { + neighbors_snd = HIGHBD_CHROMA_NO_SS_RIGHT_COLUMN_NEIGHBORS; + } + + highbd_apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, + uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, + u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_fst, + neighbors_snd, top_weight, bottom_weight, NULL); +} + +void vp9_highbd_apply_temporal_filter_neon( + const uint16_t *y_src, int y_src_stride, const uint16_t *y_pre, + int y_pre_stride, const uint16_t *u_src, const uint16_t *v_src, + int uv_src_stride, const uint16_t *u_pre, const uint16_t *v_pre, + int uv_pre_stride, unsigned int block_width, unsigned int block_height, + int ss_x, int ss_y, int strength, const int *const blk_fw, + int use_whole_blk, uint32_t *y_accum, uint16_t *y_count, uint32_t *u_accum, + uint16_t *u_count, uint32_t *v_accum, uint16_t *v_count) { + const unsigned int chroma_height = block_height >> ss_y, + chroma_width = block_width >> ss_x; + + DECLARE_ALIGNED(16, uint32_t, y_dist[BH * DIST_STRIDE]) = { 0 }; + DECLARE_ALIGNED(16, uint32_t, u_dist[BH * DIST_STRIDE]) = { 0 }; + DECLARE_ALIGNED(16, uint32_t, v_dist[BH * DIST_STRIDE]) = { 0 }; + + uint32_t *y_dist_ptr = y_dist + 1, *u_dist_ptr = u_dist + 1, + *v_dist_ptr = v_dist + 1; + const uint16_t *y_src_ptr = y_src, *u_src_ptr = u_src, *v_src_ptr = v_src; + const uint16_t *y_pre_ptr = y_pre, *u_pre_ptr = u_pre, *v_pre_ptr = v_pre; + + // Loop variables + unsigned int row, blk_col; + + assert(block_width <= BW && "block width too large"); + assert(block_height <= BH && "block height too large"); + assert(block_width % 16 == 0 && "block width must be multiple of 16"); + assert(block_height % 2 == 0 && "block height must be even"); + assert((ss_x == 0 || ss_x == 1) && (ss_y == 0 || ss_y == 1) && + "invalid chroma subsampling"); + assert(strength >= 4 && strength <= 14 && + "invalid adjusted temporal filter strength"); + assert(blk_fw[0] >= 0 && "filter weight must be positive"); + assert( + (use_whole_blk || (blk_fw[1] >= 0 && blk_fw[2] >= 0 && blk_fw[3] >= 0)) && + "subblock filter weight must be positive"); + assert(blk_fw[0] <= 2 && "subblock filter weight must be less than 2"); + assert( + (use_whole_blk || (blk_fw[1] <= 2 && blk_fw[2] <= 2 && blk_fw[3] <= 2)) && + "subblock filter weight must be less than 2"); + + // Precompute the difference squared + for (row = 0; row < block_height; row++) { + for (blk_col = 0; blk_col < block_width; blk_col += 8) { + highbd_store_dist_8(y_src_ptr + blk_col, y_pre_ptr + blk_col, + y_dist_ptr + blk_col); + } + y_src_ptr += y_src_stride; + y_pre_ptr += y_pre_stride; + y_dist_ptr += DIST_STRIDE; + } + + for (row = 0; row < chroma_height; row++) { + for (blk_col = 0; blk_col < chroma_width; blk_col += 8) { + highbd_store_dist_8(u_src_ptr + blk_col, u_pre_ptr + blk_col, + u_dist_ptr + blk_col); + highbd_store_dist_8(v_src_ptr + blk_col, v_pre_ptr + blk_col, + v_dist_ptr + blk_col); + } + + u_src_ptr += uv_src_stride; + u_pre_ptr += uv_pre_stride; + u_dist_ptr += DIST_STRIDE; + v_src_ptr += uv_src_stride; + v_pre_ptr += uv_pre_stride; + v_dist_ptr += DIST_STRIDE; + } + + y_dist_ptr = y_dist + 1; + u_dist_ptr = u_dist + 1; + v_dist_ptr = v_dist + 1; + + highbd_apply_temporal_filter_luma(y_pre, y_pre_stride, block_width, + block_height, ss_x, ss_y, strength, blk_fw, + use_whole_blk, y_accum, y_count, y_dist_ptr, + u_dist_ptr, v_dist_ptr); + + highbd_apply_temporal_filter_chroma( + u_pre, v_pre, uv_pre_stride, block_width, block_height, ss_x, ss_y, + strength, blk_fw, use_whole_blk, u_accum, u_count, v_accum, v_count, + y_dist_ptr, u_dist_ptr, v_dist_ptr); +} + +static INLINE uint16x8_t highbd_convolve12_8( + const int16x8_t s0, const int16x8_t s1, const int16x8_t s2, + const int16x8_t s3, const int16x8_t s4, const int16x8_t s5, + const int16x8_t s6, const int16x8_t s7, const int16x8_t s8, + const int16x8_t s9, const int16x8_t sA, const int16x8_t sB, + const int16x8_t filter_0_7, const int16x4_t filter_8_11, uint16x8_t max) { + const int16x4_t filter_0_3 = vget_low_s16(filter_0_7); + const int16x4_t filter_4_7 = vget_high_s16(filter_0_7); + + int32x4_t sum_lo = vmull_lane_s16(vget_low_s16(s0), filter_0_3, 0); + sum_lo = vmlal_lane_s16(sum_lo, vget_low_s16(s1), filter_0_3, 1); + sum_lo = vmlal_lane_s16(sum_lo, vget_low_s16(s2), filter_0_3, 2); + sum_lo = vmlal_lane_s16(sum_lo, vget_low_s16(s3), filter_0_3, 3); + sum_lo = vmlal_lane_s16(sum_lo, vget_low_s16(s4), filter_4_7, 0); + sum_lo = vmlal_lane_s16(sum_lo, vget_low_s16(s5), filter_4_7, 1); + sum_lo = vmlal_lane_s16(sum_lo, vget_low_s16(s6), filter_4_7, 2); + sum_lo = vmlal_lane_s16(sum_lo, vget_low_s16(s7), filter_4_7, 3); + sum_lo = vmlal_lane_s16(sum_lo, vget_low_s16(s8), filter_8_11, 0); + sum_lo = vmlal_lane_s16(sum_lo, vget_low_s16(s9), filter_8_11, 1); + sum_lo = vmlal_lane_s16(sum_lo, vget_low_s16(sA), filter_8_11, 2); + sum_lo = vmlal_lane_s16(sum_lo, vget_low_s16(sB), filter_8_11, 3); + + int32x4_t sum_hi = vmull_lane_s16(vget_high_s16(s0), filter_0_3, 0); + sum_hi = vmlal_lane_s16(sum_hi, vget_high_s16(s1), filter_0_3, 1); + sum_hi = vmlal_lane_s16(sum_hi, vget_high_s16(s2), filter_0_3, 2); + sum_hi = vmlal_lane_s16(sum_hi, vget_high_s16(s3), filter_0_3, 3); + sum_hi = vmlal_lane_s16(sum_hi, vget_high_s16(s4), filter_4_7, 0); + sum_hi = vmlal_lane_s16(sum_hi, vget_high_s16(s5), filter_4_7, 1); + sum_hi = vmlal_lane_s16(sum_hi, vget_high_s16(s6), filter_4_7, 2); + sum_hi = vmlal_lane_s16(sum_hi, vget_high_s16(s7), filter_4_7, 3); + sum_hi = vmlal_lane_s16(sum_hi, vget_high_s16(s8), filter_8_11, 0); + sum_hi = vmlal_lane_s16(sum_hi, vget_high_s16(s9), filter_8_11, 1); + sum_hi = vmlal_lane_s16(sum_hi, vget_high_s16(sA), filter_8_11, 2); + sum_hi = vmlal_lane_s16(sum_hi, vget_high_s16(sB), filter_8_11, 3); + + uint16x4_t sum_lo_s16 = vqrshrun_n_s32(sum_lo, FILTER_BITS); + uint16x4_t sum_hi_s16 = vqrshrun_n_s32(sum_hi, FILTER_BITS); + + uint16x8_t sum = vcombine_u16(sum_lo_s16, sum_hi_s16); + return vminq_u16(sum, max); +} + +void vpx_highbd_convolve12_horiz_neon(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + // Scaling not supported by Neon implementation. + if (x_step_q4 != 16) { + vpx_highbd_convolve12_horiz_c(src, src_stride, dst, dst_stride, filter, + x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h % 4 == 0); + + const int16x8_t filter_0_7 = vld1q_s16(filter[x0_q4]); + const int16x4_t filter_8_11 = vld1_s16(filter[x0_q4] + 8); + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + src -= MAX_FILTER_TAP / 2 - 1; + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int width = w; + + do { + int16x8_t s0[12], s1[12]; + load_s16_8x12(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3], + &s0[4], &s0[5], &s0[6], &s0[7], &s0[8], &s0[9], &s0[10], + &s0[11]); + load_s16_8x12(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3], + &s1[4], &s1[5], &s1[6], &s1[7], &s1[8], &s1[9], &s1[10], + &s1[11]); + + uint16x8_t d0 = highbd_convolve12_8( + s0[0], s0[1], s0[2], s0[3], s0[4], s0[5], s0[6], s0[7], s0[8], s0[9], + s0[10], s0[11], filter_0_7, filter_8_11, max); + uint16x8_t d1 = highbd_convolve12_8( + s1[0], s1[1], s1[2], s1[3], s1[4], s1[5], s1[6], s1[7], s1[8], s1[9], + s1[10], s1[11], filter_0_7, filter_8_11, max); + + vst1q_u16(d + 0 * dst_stride, d0); + vst1q_u16(d + 1 * dst_stride, d1); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 2 * src_stride; + dst += 2 * dst_stride; + h -= 2; + } while (h != 0); +} + +void vpx_highbd_convolve12_vert_neon(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + // Scaling not supported by Neon implementation. + if (y_step_q4 != 16) { + vpx_highbd_convolve12_vert_c(src, src_stride, dst, dst_stride, filter, + x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h == 32 || h == 16 || h == 8); + + const int16x8_t filter_0_7 = vld1q_s16(filter[y0_q4]); + const int16x4_t filter_8_11 = vld1_s16(filter[y0_q4] + 8); + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + src -= src_stride * (MAX_FILTER_TAP / 2 - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int height = h; + + int16x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA; + load_s16_8x11(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7, &s8, + &s9, &sA); + s += 11 * src_stride; + + do { + int16x8_t sB, sC, sD, sE; + load_s16_8x4(s, src_stride, &sB, &sC, &sD, &sE); + + uint16x8_t d0 = + highbd_convolve12_8(s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, + filter_0_7, filter_8_11, max); + uint16x8_t d1 = + highbd_convolve12_8(s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, + filter_0_7, filter_8_11, max); + uint16x8_t d2 = + highbd_convolve12_8(s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, + filter_0_7, filter_8_11, max); + uint16x8_t d3 = + highbd_convolve12_8(s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, + filter_0_7, filter_8_11, max); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + s0 = s4; + s1 = s5; + s2 = s6; + s3 = s7; + s4 = s8; + s5 = s9; + s6 = sA; + s7 = sB; + s8 = sC; + s9 = sD; + sA = sE; + + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); +} + +void vpx_highbd_convolve12_neon(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h, int bd) { + // Scaling not supported by Neon implementation. + if (x_step_q4 != 16 || y_step_q4 != 16) { + vpx_highbd_convolve12_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h == 32 || h == 16 || h == 8); + + DECLARE_ALIGNED(32, uint16_t, im_block[BW * (BH + MAX_FILTER_TAP)]); + + const int im_stride = BW; + // Account for the vertical pass needing MAX_FILTER_TAP / 2 - 1 lines prior + // and MAX_FILTER_TAP / 2 lines post. (+1 to make total divisible by 2.) + const int im_height = h + MAX_FILTER_TAP; + const ptrdiff_t border_offset = MAX_FILTER_TAP / 2 - 1; + + // Filter starting border_offset rows up. + vpx_highbd_convolve12_horiz_neon( + src - src_stride * border_offset, src_stride, im_block, im_stride, filter, + x0_q4, x_step_q4, y0_q4, y_step_q4, w, im_height, bd); + + vpx_highbd_convolve12_vert_neon(im_block + im_stride * border_offset, + im_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); +} diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_temporal_filter_sve2.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_temporal_filter_sve2.c new file mode 100644 index 0000000000..73660eb4ac --- /dev/null +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_highbd_temporal_filter_sve2.c @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2025 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include +#include + +#include "./vp9_rtcd.h" +#include "./vpx_config.h" +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/transpose_neon.h" +#include "vp9/encoder/vp9_temporal_filter.h" +#include "vpx_dsp/arm/vpx_neon_sve_bridge.h" +#include "vpx_dsp/arm/vpx_neon_sve2_bridge.h" + +DECLARE_ALIGNED(16, static const uint16_t, kDotProdPermuteTbl[32]) = { + // clang-format off + 0, 1, 2, 3, 1, 2, 3, 4, + 2, 3, 4, 5, 3, 4, 5, 6, + 4, 5, 6, 7, 5, 6, 7, 0, + 6, 7, 0, 1, 7, 0, 1, 2, + // clang-format on +}; + +static INLINE uint16x8_t highbd_convolve12_8_h( + const int16x8_t s0, const int16x8_t s1, const int16x8_t s2, + const int16x8_t filter_0_7, const int16x8_t filter_4_11, + const uint16x8x4_t perm_tbl, const uint16x8_t max) { + int16x8_t perm_samples[8]; + + perm_samples[0] = vpx_tbl_s16(s0, perm_tbl.val[0]); + perm_samples[1] = vpx_tbl_s16(s0, perm_tbl.val[1]); + perm_samples[2] = vpx_tbl2_s16(s0, s1, perm_tbl.val[2]); + perm_samples[3] = vpx_tbl2_s16(s0, s1, perm_tbl.val[3]); + perm_samples[4] = vpx_tbl_s16(s1, perm_tbl.val[0]); + perm_samples[5] = vpx_tbl_s16(s1, perm_tbl.val[1]); + perm_samples[6] = vpx_tbl2_s16(s1, s2, perm_tbl.val[2]); + perm_samples[7] = vpx_tbl2_s16(s1, s2, perm_tbl.val[3]); + + int64x2_t sum01 = + vpx_dotq_lane_s16(vdupq_n_s64(0), perm_samples[0], filter_0_7, 0); + sum01 = vpx_dotq_lane_s16(sum01, perm_samples[2], filter_0_7, 1); + sum01 = vpx_dotq_lane_s16(sum01, perm_samples[4], filter_4_11, 1); + + int64x2_t sum23 = + vpx_dotq_lane_s16(vdupq_n_s64(0), perm_samples[1], filter_0_7, 0); + sum23 = vpx_dotq_lane_s16(sum23, perm_samples[3], filter_0_7, 1); + sum23 = vpx_dotq_lane_s16(sum23, perm_samples[5], filter_4_11, 1); + + int64x2_t sum45 = + vpx_dotq_lane_s16(vdupq_n_s64(0), perm_samples[2], filter_0_7, 0); + sum45 = vpx_dotq_lane_s16(sum45, perm_samples[4], filter_0_7, 1); + sum45 = vpx_dotq_lane_s16(sum45, perm_samples[6], filter_4_11, 1); + + int64x2_t sum67 = + vpx_dotq_lane_s16(vdupq_n_s64(0), perm_samples[3], filter_0_7, 0); + sum67 = vpx_dotq_lane_s16(sum67, perm_samples[5], filter_0_7, 1); + sum67 = vpx_dotq_lane_s16(sum67, perm_samples[7], filter_4_11, 1); + + int32x4_t sum0123 = vcombine_s32(vmovn_s64(sum01), vmovn_s64(sum23)); + int32x4_t sum4567 = vcombine_s32(vmovn_s64(sum45), vmovn_s64(sum67)); + + uint16x8_t res = vcombine_u16(vqrshrun_n_s32(sum0123, FILTER_BITS), + vqrshrun_n_s32(sum4567, FILTER_BITS)); + return vminq_u16(res, max); +} + +void vpx_highbd_convolve12_horiz_sve2(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + // Scaling not supported by SVE2 implementation. + if (x_step_q4 != 16) { + vpx_highbd_convolve12_horiz_c(src, src_stride, dst, dst_stride, filter, + x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h % 4 == 0); + + const int16x8_t filter_0_7 = vld1q_s16(filter[x0_q4]); + const int16x8_t filter_4_11 = vld1q_s16(filter[x0_q4] + 4); + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + uint16x8x4_t permute_tbl = vld1q_u16_x4(kDotProdPermuteTbl); + + // Scale indices by size of the true vector length to avoid reading from an + // 'undefined' portion of a vector on a system with SVE vectors > 128-bit. + permute_tbl.val[2] = vsetq_lane_u16(svcnth(), permute_tbl.val[2], 7); + permute_tbl.val[3] = vsetq_lane_u16(svcnth(), permute_tbl.val[3], 5); + uint16x8_t permute_tbl_3_offsets = + vreinterpretq_u16_u64(vdupq_n_u64(svcnth() * 0x0001000100000000ULL)); + permute_tbl.val[3] = + vaddq_u16(permute_tbl.val[3], permute_tbl_3_offsets); // 2, 3, 6, 7 + + src -= MAX_FILTER_TAP / 2 - 1; + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int width = w; + + do { + int16x8_t s0[3], s1[3]; + + load_s16_8x3(s + 0 * src_stride, 8, &s0[0], &s0[1], &s0[2]); + load_s16_8x3(s + 1 * src_stride, 8, &s1[0], &s1[1], &s1[2]); + + uint16x8_t d0 = highbd_convolve12_8_h(s0[0], s0[1], s0[2], filter_0_7, + filter_4_11, permute_tbl, max); + uint16x8_t d1 = highbd_convolve12_8_h(s1[0], s1[1], s1[2], filter_0_7, + filter_4_11, permute_tbl, max); + + vst1q_u16(d + 0 * dst_stride, d0); + vst1q_u16(d + 1 * dst_stride, d1); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 2 * src_stride; + dst += 2 * dst_stride; + h -= 2; + } while (h != 0); +} + +static INLINE uint16x4_t highbd_convolve12_4_v(const int16x8_t s0[2], + const int16x8_t s1[2], + const int16x8_t s2[2], + const int16x8_t filter_0_7, + const int16x8_t filter_4_11, + const uint16x4_t max) { + int64x2_t sum01 = vpx_dotq_lane_s16(vdupq_n_s64(0), s0[0], filter_0_7, 0); + sum01 = vpx_dotq_lane_s16(sum01, s1[0], filter_0_7, 1); + sum01 = vpx_dotq_lane_s16(sum01, s2[0], filter_4_11, 1); + + int64x2_t sum23 = vpx_dotq_lane_s16(vdupq_n_s64(0), s0[1], filter_0_7, 0); + sum23 = vpx_dotq_lane_s16(sum23, s1[1], filter_0_7, 1); + sum23 = vpx_dotq_lane_s16(sum23, s2[1], filter_4_11, 1); + + int32x4_t sum0123 = vcombine_s32(vmovn_s64(sum01), vmovn_s64(sum23)); + + uint16x4_t res = vqrshrun_n_s32(sum0123, FILTER_BITS); + + return vmin_u16(res, max); +} + +void vpx_highbd_convolve12_vert_sve2(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + // Scaling not supported by SVE2 implementation. + if (y_step_q4 != 16) { + vpx_highbd_convolve12_vert_c(src, src_stride, dst, dst_stride, filter, + x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + assert(w == 32 || w == 16 || w == 8); + assert(h % 4 == 0); + + const int16x8_t filter_0_7 = vld1q_s16(filter[y0_q4]); + const int16x8_t filter_4_11 = vld1q_s16(filter[y0_q4] + 4); + + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + + src -= src_stride * (MAX_FILTER_TAP / 2 - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int height = h; + + int16x4_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA; + load_s16_4x11(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7, &s8, + &s9, &sA); + s += 11 * src_stride; + + int16x8_t s0123[2], s1234[2], s2345[2], s3456[2], s4567[2], s5678[2], + s6789[2], s789A[2]; + transpose_concat_s16_4x4(s0, s1, s2, s3, &s0123[0], &s0123[1]); + transpose_concat_s16_4x4(s1, s2, s3, s4, &s1234[0], &s1234[1]); + transpose_concat_s16_4x4(s2, s3, s4, s5, &s2345[0], &s2345[1]); + transpose_concat_s16_4x4(s3, s4, s5, s6, &s3456[0], &s3456[1]); + transpose_concat_s16_4x4(s4, s5, s6, s7, &s4567[0], &s4567[1]); + transpose_concat_s16_4x4(s5, s6, s7, s8, &s5678[0], &s5678[1]); + transpose_concat_s16_4x4(s6, s7, s8, s9, &s6789[0], &s6789[1]); + transpose_concat_s16_4x4(s7, s8, s9, sA, &s789A[0], &s789A[1]); + + do { + int16x4_t sB, sC, sD, sE; + load_s16_4x4(s, src_stride, &sB, &sC, &sD, &sE); + + int16x8_t s89AB[2], s9ABC[2], sABCD[2], sBCDE[2]; + transpose_concat_s16_4x4(s8, s9, sA, sB, &s89AB[0], &s89AB[1]); + transpose_concat_s16_4x4(s9, sA, sB, sC, &s9ABC[0], &s9ABC[1]); + transpose_concat_s16_4x4(sA, sB, sC, sD, &sABCD[0], &sABCD[1]); + transpose_concat_s16_4x4(sB, sC, sD, sE, &sBCDE[0], &sBCDE[1]); + + uint16x4_t d0 = highbd_convolve12_4_v(s0123, s4567, s89AB, filter_0_7, + filter_4_11, max); + uint16x4_t d1 = highbd_convolve12_4_v(s1234, s5678, s9ABC, filter_0_7, + filter_4_11, max); + uint16x4_t d2 = highbd_convolve12_4_v(s2345, s6789, sABCD, filter_0_7, + filter_4_11, max); + uint16x4_t d3 = highbd_convolve12_4_v(s3456, s789A, sBCDE, filter_0_7, + filter_4_11, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + // Prepare block for next iteration - reusing as much as possible. + // Shuffle everything up four rows. + s0123[0] = s4567[0]; + s0123[1] = s4567[1]; + s1234[0] = s5678[0]; + s1234[1] = s5678[1]; + s2345[0] = s6789[0]; + s2345[1] = s6789[1]; + s3456[0] = s789A[0]; + s3456[1] = s789A[1]; + s4567[0] = s89AB[0]; + s4567[1] = s89AB[1]; + s5678[0] = s9ABC[0]; + s5678[1] = s9ABC[1]; + s6789[0] = sABCD[0]; + s6789[1] = sABCD[1]; + s789A[0] = sBCDE[0]; + s789A[1] = sBCDE[1]; + + s8 = sC; + s9 = sD; + sA = sE; + + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 4; + dst += 4; + w -= 4; + } while (w != 0); +} + +void vpx_highbd_convolve12_sve2(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h, int bd) { + // Scaling not supported by SVE2 implementation. + if (x_step_q4 != 16 || y_step_q4 != 16) { + vpx_highbd_convolve12_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h == 32 || h == 16 || h == 8); + + DECLARE_ALIGNED(32, uint16_t, im_block[BW * (BH + MAX_FILTER_TAP)]); + + const int im_stride = BW; + // Account for the vertical pass needing MAX_FILTER_TAP / 2 - 1 lines prior + // and MAX_FILTER_TAP / 2 lines post. (+1 to make total divisible by 4.) + const int im_height = h + MAX_FILTER_TAP; + const ptrdiff_t border_offset = MAX_FILTER_TAP / 2 - 1; + + // Filter starting border_offset rows up. + vpx_highbd_convolve12_horiz_sve2( + src - src_stride * border_offset, src_stride, im_block, im_stride, filter, + x0_q4, x_step_q4, y0_q4, y_step_q4, w, im_height, bd); + + vpx_highbd_convolve12_vert_sve2(im_block + im_stride * border_offset, + im_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); +} diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_quantize_neon.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_quantize_neon.c index 236c3176c7..96d0614367 100644 --- a/libs/libvpx/vp9/encoder/arm/neon/vp9_quantize_neon.c +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_quantize_neon.c @@ -11,11 +11,13 @@ #include #include #include +#include #include "./vpx_config.h" #include "vpx_mem/vpx_mem.h" #include "vp9/common/vp9_quant_common.h" +#include "vp9/common/vp9_scan.h" #include "vp9/common/vp9_seg_common.h" #include "vp9/encoder/vp9_encoder.h" @@ -26,9 +28,8 @@ #include "vpx_dsp/arm/mem_neon.h" #include "vpx_dsp/vpx_dsp_common.h" -static INLINE void calculate_dqcoeff_and_store(const int16x8_t qcoeff, - const int16x8_t dequant, - tran_low_t *dqcoeff) { +static VPX_FORCE_INLINE void calculate_dqcoeff_and_store( + const int16x8_t qcoeff, const int16x8_t dequant, tran_low_t *dqcoeff) { const int32x4_t dqcoeff_0 = vmull_s16(vget_low_s16(qcoeff), vget_low_s16(dequant)); const int32x4_t dqcoeff_1 = @@ -42,144 +43,135 @@ static INLINE void calculate_dqcoeff_and_store(const int16x8_t qcoeff, #endif // CONFIG_VP9_HIGHBITDEPTH } -void vp9_quantize_fp_neon(const tran_low_t *coeff_ptr, intptr_t count, - const int16_t *round_ptr, const int16_t *quant_ptr, +static VPX_FORCE_INLINE int16x8_t get_max_lane_eob(const int16_t *iscan_ptr, + int16x8_t v_eobmax, + uint16x8_t v_nz_mask) { + const int16x8_t v_iscan = vld1q_s16(&iscan_ptr[0]); + const int16x8_t v_nz_iscan = vbslq_s16(v_nz_mask, vdupq_n_s16(0), v_iscan); + return vmaxq_s16(v_eobmax, v_nz_iscan); +} + +static VPX_FORCE_INLINE uint16_t get_max_eob(int16x8_t v_eobmax) { +#if VPX_ARCH_AARCH64 + return (uint16_t)vmaxvq_s16(v_eobmax); +#else + const int16x4_t v_eobmax_3210 = + vmax_s16(vget_low_s16(v_eobmax), vget_high_s16(v_eobmax)); + const int64x1_t v_eobmax_xx32 = + vshr_n_s64(vreinterpret_s64_s16(v_eobmax_3210), 32); + const int16x4_t v_eobmax_tmp = + vmax_s16(v_eobmax_3210, vreinterpret_s16_s64(v_eobmax_xx32)); + const int64x1_t v_eobmax_xxx3 = + vshr_n_s64(vreinterpret_s64_s16(v_eobmax_tmp), 16); + const int16x4_t v_eobmax_final = + vmax_s16(v_eobmax_tmp, vreinterpret_s16_s64(v_eobmax_xxx3)); + + return (uint16_t)vget_lane_s16(v_eobmax_final, 0); +#endif // VPX_ARCH_AARCH64 +} + +static VPX_FORCE_INLINE void load_fp_values( + const struct macroblock_plane *mb_plane, const int16_t *dequant_ptr, + int16x8_t *round, int16x8_t *quant, int16x8_t *dequant) { + *round = vld1q_s16(mb_plane->round_fp); + *quant = vld1q_s16(mb_plane->quant_fp); + *dequant = vld1q_s16(dequant_ptr); +} + +static VPX_FORCE_INLINE void update_fp_values(int16x8_t *v_round, + int16x8_t *v_quant, + int16x8_t *v_dequant) { +#if VPX_ARCH_AARCH64 + *v_round = vdupq_laneq_s16(*v_round, 1); + *v_quant = vdupq_laneq_s16(*v_quant, 1); + *v_dequant = vdupq_laneq_s16(*v_dequant, 1); +#else + *v_round = vdupq_lane_s16(vget_low_s16(*v_round), 1); + *v_quant = vdupq_lane_s16(vget_low_s16(*v_quant), 1); + *v_dequant = vdupq_lane_s16(vget_low_s16(*v_dequant), 1); +#endif +} + +static VPX_FORCE_INLINE void quantize_fp_8( + const int16x8_t *v_round, const int16x8_t *v_quant, + const int16x8_t *v_dequant, const tran_low_t *coeff_ptr, + const int16_t *iscan_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + int16x8_t *v_eobmax) { + const int16x8_t v_zero = vdupq_n_s16(0); + const int16x8_t v_coeff = load_tran_low_to_s16q(coeff_ptr); + const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15); + const int16x8_t v_abs = vabsq_s16(v_coeff); + const int16x8_t v_tmp = vqaddq_s16(v_abs, *v_round); + const int32x4_t v_tmp_lo = + vmull_s16(vget_low_s16(v_tmp), vget_low_s16(*v_quant)); + const int32x4_t v_tmp_hi = + vmull_s16(vget_high_s16(v_tmp), vget_high_s16(*v_quant)); + const int16x8_t v_tmp2 = + vcombine_s16(vshrn_n_s32(v_tmp_lo, 16), vshrn_n_s32(v_tmp_hi, 16)); + const uint16x8_t v_nz_mask = vceqq_s16(v_tmp2, v_zero); + const int16x8_t v_qcoeff_a = veorq_s16(v_tmp2, v_coeff_sign); + const int16x8_t v_qcoeff = vsubq_s16(v_qcoeff_a, v_coeff_sign); + calculate_dqcoeff_and_store(v_qcoeff, *v_dequant, dqcoeff_ptr); + store_s16q_to_tran_low(qcoeff_ptr, v_qcoeff); + + *v_eobmax = get_max_lane_eob(iscan_ptr, *v_eobmax, v_nz_mask); +} + +void vp9_quantize_fp_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { + const struct ScanOrder *const scan_order) { // Quantization pass: All coefficients with index >= zero_flag are // skippable. Note: zero_flag can be zero. int i; - const int16x8_t v_zero = vdupq_n_s16(0); - const int16x8_t v_one = vdupq_n_s16(1); - int16x8_t v_eobmax_76543210 = vdupq_n_s16(-1); - int16x8_t v_round = vmovq_n_s16(round_ptr[1]); - int16x8_t v_quant = vmovq_n_s16(quant_ptr[1]); - int16x8_t v_dequant = vmovq_n_s16(dequant_ptr[1]); + int16x8_t v_eobmax = vdupq_n_s16(-1); + int16x8_t v_round, v_quant, v_dequant; + const int16_t *iscan = scan_order->iscan; - (void)scan; - - // adjust for dc - v_round = vsetq_lane_s16(round_ptr[0], v_round, 0); - v_quant = vsetq_lane_s16(quant_ptr[0], v_quant, 0); - v_dequant = vsetq_lane_s16(dequant_ptr[0], v_dequant, 0); + load_fp_values(mb_plane, dequant_ptr, &v_round, &v_quant, &v_dequant); // process dc and the first seven ac coeffs - { - const int16x8_t v_iscan = vld1q_s16(&iscan[0]); - const int16x8_t v_coeff = load_tran_low_to_s16q(coeff_ptr); - const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15); - const int16x8_t v_abs = vabsq_s16(v_coeff); - const int16x8_t v_tmp = vqaddq_s16(v_abs, v_round); - const int32x4_t v_tmp_lo = - vmull_s16(vget_low_s16(v_tmp), vget_low_s16(v_quant)); - const int32x4_t v_tmp_hi = - vmull_s16(vget_high_s16(v_tmp), vget_high_s16(v_quant)); - const int16x8_t v_tmp2 = - vcombine_s16(vshrn_n_s32(v_tmp_lo, 16), vshrn_n_s32(v_tmp_hi, 16)); - const uint16x8_t v_nz_mask = vceqq_s16(v_tmp2, v_zero); - const int16x8_t v_iscan_plus1 = vaddq_s16(v_iscan, v_one); - const int16x8_t v_nz_iscan = vbslq_s16(v_nz_mask, v_zero, v_iscan_plus1); - const int16x8_t v_qcoeff_a = veorq_s16(v_tmp2, v_coeff_sign); - const int16x8_t v_qcoeff = vsubq_s16(v_qcoeff_a, v_coeff_sign); - calculate_dqcoeff_and_store(v_qcoeff, v_dequant, dqcoeff_ptr); - v_eobmax_76543210 = vmaxq_s16(v_eobmax_76543210, v_nz_iscan); - store_s16q_to_tran_low(qcoeff_ptr, v_qcoeff); - v_round = vmovq_n_s16(round_ptr[1]); - v_quant = vmovq_n_s16(quant_ptr[1]); - v_dequant = vmovq_n_s16(dequant_ptr[1]); - } - // now process the rest of the ac coeffs - for (i = 8; i < count; i += 8) { - const int16x8_t v_iscan = vld1q_s16(&iscan[i]); - const int16x8_t v_coeff = load_tran_low_to_s16q(coeff_ptr + i); - const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15); - const int16x8_t v_abs = vabsq_s16(v_coeff); - const int16x8_t v_tmp = vqaddq_s16(v_abs, v_round); - const int32x4_t v_tmp_lo = - vmull_s16(vget_low_s16(v_tmp), vget_low_s16(v_quant)); - const int32x4_t v_tmp_hi = - vmull_s16(vget_high_s16(v_tmp), vget_high_s16(v_quant)); - const int16x8_t v_tmp2 = - vcombine_s16(vshrn_n_s32(v_tmp_lo, 16), vshrn_n_s32(v_tmp_hi, 16)); - const uint16x8_t v_nz_mask = vceqq_s16(v_tmp2, v_zero); - const int16x8_t v_iscan_plus1 = vaddq_s16(v_iscan, v_one); - const int16x8_t v_nz_iscan = vbslq_s16(v_nz_mask, v_zero, v_iscan_plus1); - const int16x8_t v_qcoeff_a = veorq_s16(v_tmp2, v_coeff_sign); - const int16x8_t v_qcoeff = vsubq_s16(v_qcoeff_a, v_coeff_sign); - calculate_dqcoeff_and_store(v_qcoeff, v_dequant, dqcoeff_ptr + i); - v_eobmax_76543210 = vmaxq_s16(v_eobmax_76543210, v_nz_iscan); - store_s16q_to_tran_low(qcoeff_ptr + i, v_qcoeff); - } -#ifdef __aarch64__ - *eob_ptr = vmaxvq_s16(v_eobmax_76543210); -#else - { - const int16x4_t v_eobmax_3210 = vmax_s16(vget_low_s16(v_eobmax_76543210), - vget_high_s16(v_eobmax_76543210)); - const int64x1_t v_eobmax_xx32 = - vshr_n_s64(vreinterpret_s64_s16(v_eobmax_3210), 32); - const int16x4_t v_eobmax_tmp = - vmax_s16(v_eobmax_3210, vreinterpret_s16_s64(v_eobmax_xx32)); - const int64x1_t v_eobmax_xxx3 = - vshr_n_s64(vreinterpret_s64_s16(v_eobmax_tmp), 16); - const int16x4_t v_eobmax_final = - vmax_s16(v_eobmax_tmp, vreinterpret_s16_s64(v_eobmax_xxx3)); + quantize_fp_8(&v_round, &v_quant, &v_dequant, coeff_ptr, iscan, qcoeff_ptr, + dqcoeff_ptr, &v_eobmax); - *eob_ptr = (uint16_t)vget_lane_s16(v_eobmax_final, 0); + // now process the rest of the ac coeffs + update_fp_values(&v_round, &v_quant, &v_dequant); + for (i = 8; i < n_coeffs; i += 8) { + quantize_fp_8(&v_round, &v_quant, &v_dequant, coeff_ptr + i, iscan + i, + qcoeff_ptr + i, dqcoeff_ptr + i, &v_eobmax); } -#endif // __aarch64__ + + *eob_ptr = get_max_eob(v_eobmax); } static INLINE int32x4_t extract_sign_bit(int32x4_t a) { return vreinterpretq_s32_u32(vshrq_n_u32(vreinterpretq_u32_s32(a), 31)); } -void vp9_quantize_fp_32x32_neon(const tran_low_t *coeff_ptr, intptr_t count, - const int16_t *round_ptr, - const int16_t *quant_ptr, - tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, - const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { - const int16x8_t one = vdupq_n_s16(1); - const int16x8_t neg_one = vdupq_n_s16(-1); +static VPX_FORCE_INLINE void quantize_fp_32x32_8( + const int16x8_t *v_round, const int16x8_t *v_quant, + const int16x8_t *v_dequant, const int16x8_t *dequant_thresh, + const tran_low_t *coeff_ptr, const int16_t *iscan_ptr, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, int16x8_t *v_eobmax) { + const int16x8_t v_coeff = load_tran_low_to_s16q(coeff_ptr); + const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15); + const int16x8_t v_coeff_abs = vabsq_s16(v_coeff); + const int16x8_t v_thr_mask = + vreinterpretq_s16_u16(vcgeq_s16(v_coeff_abs, *dequant_thresh)); + const int16x8_t v_tmp_rnd = + vandq_s16(vqaddq_s16(v_coeff_abs, *v_round), v_thr_mask); + const int16x8_t v_abs_qcoeff = vqdmulhq_s16(v_tmp_rnd, *v_quant); + const int16x8_t v_qcoeff = + vsubq_s16(veorq_s16(v_abs_qcoeff, v_coeff_sign), v_coeff_sign); + const uint16x8_t v_nz_mask = vceqq_s16(v_abs_qcoeff, vdupq_n_s16(0)); - // ROUND_POWER_OF_TWO(round_ptr[], 1) - const int16x8_t round = vrshrq_n_s16(vld1q_s16(round_ptr), 1); - const int16x8_t quant = vld1q_s16(quant_ptr); - const int16x4_t dequant = vld1_s16(dequant_ptr); - // dequant >> 2 is used similar to zbin as a threshold. - const int16x8_t dequant_thresh = vshrq_n_s16(vld1q_s16(dequant_ptr), 2); - - // Process dc and the first seven ac coeffs. - const uint16x8_t v_iscan = - vreinterpretq_u16_s16(vaddq_s16(vld1q_s16(iscan), one)); - const int16x8_t coeff = load_tran_low_to_s16q(coeff_ptr); - const int16x8_t coeff_sign = vshrq_n_s16(coeff, 15); - const int16x8_t coeff_abs = vabsq_s16(coeff); - const int16x8_t dequant_mask = - vreinterpretq_s16_u16(vcgeq_s16(coeff_abs, dequant_thresh)); - - int16x8_t qcoeff = vqaddq_s16(coeff_abs, round); int32x4_t dqcoeff_0, dqcoeff_1; - uint16x8_t eob_max; - (void)scan; - (void)count; - - // coeff * quant_ptr[]) >> 15 - qcoeff = vqdmulhq_s16(qcoeff, quant); - - // Restore sign. - qcoeff = veorq_s16(qcoeff, coeff_sign); - qcoeff = vsubq_s16(qcoeff, coeff_sign); - qcoeff = vandq_s16(qcoeff, dequant_mask); - - // qcoeff * dequant[] / 2 - dqcoeff_0 = vmull_s16(vget_low_s16(qcoeff), dequant); - dqcoeff_1 = vmull_n_s16(vget_high_s16(qcoeff), dequant_ptr[1]); - + dqcoeff_0 = vmull_s16(vget_low_s16(v_qcoeff), vget_low_s16(*v_dequant)); + dqcoeff_1 = vmull_s16(vget_high_s16(v_qcoeff), vget_high_s16(*v_dequant)); // Add 1 if negative to round towards zero because the C uses division. dqcoeff_0 = vaddq_s32(dqcoeff_0, extract_sign_bit(dqcoeff_0)); dqcoeff_1 = vaddq_s32(dqcoeff_1, extract_sign_bit(dqcoeff_1)); + #if CONFIG_VP9_HIGHBITDEPTH vst1q_s32(dqcoeff_ptr, vshrq_n_s32(dqcoeff_0, 1)); vst1q_s32(dqcoeff_ptr + 4, vshrq_n_s32(dqcoeff_1, 1)); @@ -188,76 +180,224 @@ void vp9_quantize_fp_32x32_neon(const tran_low_t *coeff_ptr, intptr_t count, vshrn_n_s32(dqcoeff_1, 1))); #endif - eob_max = vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan); + store_s16q_to_tran_low(qcoeff_ptr, v_qcoeff); - store_s16q_to_tran_low(qcoeff_ptr, qcoeff); + *v_eobmax = get_max_lane_eob(iscan_ptr, *v_eobmax, v_nz_mask); +} + +void vp9_quantize_fp_32x32_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + int16x8_t eob_max = vdupq_n_s16(-1); + // ROUND_POWER_OF_TWO(round_ptr[], 1) + int16x8_t round = vrshrq_n_s16(vld1q_s16(mb_plane->round_fp), 1); + int16x8_t quant = vld1q_s16(mb_plane->quant_fp); + int16x8_t dequant = vld1q_s16(dequant_ptr); + // dequant >> 2 is used similar to zbin as a threshold. + int16x8_t dequant_thresh = vshrq_n_s16(vld1q_s16(dequant_ptr), 2); + int i; + const int16_t *iscan = scan_order->iscan; + + (void)n_coeffs; + + // Process dc and the first seven ac coeffs. + quantize_fp_32x32_8(&round, &quant, &dequant, &dequant_thresh, coeff_ptr, + iscan, qcoeff_ptr, dqcoeff_ptr, &eob_max); + + update_fp_values(&round, &quant, &dequant); + dequant_thresh = vdupq_lane_s16(vget_low_s16(dequant_thresh), 1); iscan += 8; coeff_ptr += 8; qcoeff_ptr += 8; dqcoeff_ptr += 8; - { - int i; - const int16x8_t round = vrshrq_n_s16(vmovq_n_s16(round_ptr[1]), 1); - const int16x8_t quant = vmovq_n_s16(quant_ptr[1]); - const int16x8_t dequant_thresh = - vshrq_n_s16(vmovq_n_s16(dequant_ptr[1]), 2); + // Process the rest of the ac coeffs. + for (i = 8; i < 32 * 32; i += 8) { + quantize_fp_32x32_8(&round, &quant, &dequant, &dequant_thresh, coeff_ptr, + iscan, qcoeff_ptr, dqcoeff_ptr, &eob_max); - // Process the rest of the ac coeffs. - for (i = 8; i < 32 * 32; i += 8) { - const uint16x8_t v_iscan = - vreinterpretq_u16_s16(vaddq_s16(vld1q_s16(iscan), one)); - const int16x8_t coeff = load_tran_low_to_s16q(coeff_ptr); - const int16x8_t coeff_sign = vshrq_n_s16(coeff, 15); - const int16x8_t coeff_abs = vabsq_s16(coeff); - const int16x8_t dequant_mask = - vreinterpretq_s16_u16(vcgeq_s16(coeff_abs, dequant_thresh)); + iscan += 8; + coeff_ptr += 8; + qcoeff_ptr += 8; + dqcoeff_ptr += 8; + } - int16x8_t qcoeff = vqaddq_s16(coeff_abs, round); - int32x4_t dqcoeff_0, dqcoeff_1; - - qcoeff = vqdmulhq_s16(qcoeff, quant); - qcoeff = veorq_s16(qcoeff, coeff_sign); - qcoeff = vsubq_s16(qcoeff, coeff_sign); - qcoeff = vandq_s16(qcoeff, dequant_mask); - - dqcoeff_0 = vmull_n_s16(vget_low_s16(qcoeff), dequant_ptr[1]); - dqcoeff_1 = vmull_n_s16(vget_high_s16(qcoeff), dequant_ptr[1]); - - dqcoeff_0 = vaddq_s32(dqcoeff_0, extract_sign_bit(dqcoeff_0)); - dqcoeff_1 = vaddq_s32(dqcoeff_1, extract_sign_bit(dqcoeff_1)); + *eob_ptr = get_max_eob(eob_max); +} #if CONFIG_VP9_HIGHBITDEPTH - vst1q_s32(dqcoeff_ptr, vshrq_n_s32(dqcoeff_0, 1)); - vst1q_s32(dqcoeff_ptr + 4, vshrq_n_s32(dqcoeff_1, 1)); -#else - store_s16q_to_tran_low( - dqcoeff_ptr, - vcombine_s16(vshrn_n_s32(dqcoeff_0, 1), vshrn_n_s32(dqcoeff_1, 1))); -#endif +static VPX_FORCE_INLINE uint16x4_t +highbd_quantize_fp_4(const tran_low_t *coeff_ptr, tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, int32x4_t v_quant_s32, + int32x4_t v_dequant_s32, int32x4_t v_round_s32) { + const int32x4_t v_coeff = vld1q_s32(coeff_ptr); + const int32x4_t v_coeff_sign = + vreinterpretq_s32_u32(vcltq_s32(v_coeff, vdupq_n_s32(0))); + const int32x4_t v_abs_coeff = vabsq_s32(v_coeff); + const int32x4_t v_tmp = vaddq_s32(v_abs_coeff, v_round_s32); + // const int abs_qcoeff = (int)((tmp * quant) >> 16); + const int32x4_t v_abs_qcoeff = vqdmulhq_s32(v_tmp, v_quant_s32); + // qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign); + const int32x4_t v_qcoeff = + vsubq_s32(veorq_s32(v_abs_qcoeff, v_coeff_sign), v_coeff_sign); + const int32x4_t v_abs_dqcoeff = vmulq_s32(v_abs_qcoeff, v_dequant_s32); + // dqcoeff_ptr[rc] = (tran_low_t)((abs_dqcoeff ^ coeff_sign) - coeff_sign); + const int32x4_t v_dqcoeff = + vsubq_s32(veorq_s32(v_abs_dqcoeff, v_coeff_sign), v_coeff_sign); - eob_max = - vmaxq_u16(eob_max, vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan)); + vst1q_s32(qcoeff_ptr, v_qcoeff); + vst1q_s32(dqcoeff_ptr, v_dqcoeff); - store_s16q_to_tran_low(qcoeff_ptr, qcoeff); - - iscan += 8; - coeff_ptr += 8; - qcoeff_ptr += 8; - dqcoeff_ptr += 8; - } - -#ifdef __aarch64__ - *eob_ptr = vmaxvq_u16(eob_max); -#else - { - const uint16x4_t eob_max_0 = - vmax_u16(vget_low_u16(eob_max), vget_high_u16(eob_max)); - const uint16x4_t eob_max_1 = vpmax_u16(eob_max_0, eob_max_0); - const uint16x4_t eob_max_2 = vpmax_u16(eob_max_1, eob_max_1); - vst1_lane_u16(eob_ptr, eob_max_2, 0); - } -#endif // __aarch64__ - } + // Packed nz_qcoeff_mask. Used to find eob. + return vmovn_u32(vceqq_s32(v_abs_qcoeff, vdupq_n_s32(0))); } + +void vp9_highbd_quantize_fp_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *mb_plane, + tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + const int16x4_t v_zero = vdup_n_s16(0); + const int16x4_t v_quant = vld1_s16(mb_plane->quant_fp); + const int16x4_t v_dequant = vld1_s16(dequant_ptr); + const int16x4_t v_round = vld1_s16(mb_plane->round_fp); + int32x4_t v_round_s32 = vaddl_s16(v_round, v_zero); + int32x4_t v_quant_s32 = vshlq_n_s32(vaddl_s16(v_quant, v_zero), 15); + int32x4_t v_dequant_s32 = vaddl_s16(v_dequant, v_zero); + uint16x4_t v_mask_lo, v_mask_hi; + int16x8_t v_eobmax = vdupq_n_s16(-1); + const int16_t *iscan = scan_order->iscan; + + // DC and first 3 AC + v_mask_lo = highbd_quantize_fp_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, + v_quant_s32, v_dequant_s32, v_round_s32); + + // overwrite the DC constants with AC constants + v_round_s32 = vdupq_lane_s32(vget_low_s32(v_round_s32), 1); + v_quant_s32 = vdupq_lane_s32(vget_low_s32(v_quant_s32), 1); + v_dequant_s32 = vdupq_lane_s32(vget_low_s32(v_dequant_s32), 1); + + // 4 more AC + v_mask_hi = + highbd_quantize_fp_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4, + v_quant_s32, v_dequant_s32, v_round_s32); + + // Find the max lane eob for the first 8 coeffs. + v_eobmax = + get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi)); + + n_coeffs -= 8; + do { + coeff_ptr += 8; + qcoeff_ptr += 8; + dqcoeff_ptr += 8; + iscan += 8; + v_mask_lo = highbd_quantize_fp_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, + v_quant_s32, v_dequant_s32, v_round_s32); + v_mask_hi = + highbd_quantize_fp_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4, + v_quant_s32, v_dequant_s32, v_round_s32); + // Find the max lane eob for 8 coeffs. + v_eobmax = + get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi)); + n_coeffs -= 8; + } while (n_coeffs); + + *eob_ptr = get_max_eob(v_eobmax); +} + +static VPX_FORCE_INLINE uint16x4_t +highbd_quantize_fp_32x32_4(const tran_low_t *coeff_ptr, tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, int32x4_t v_quant_s32, + int32x4_t v_dequant_s32, int32x4_t v_round_s32) { + const int32x4_t v_coeff = vld1q_s32(coeff_ptr); + const int32x4_t v_coeff_sign = + vreinterpretq_s32_u32(vcltq_s32(v_coeff, vdupq_n_s32(0))); + const int32x4_t v_abs_coeff = vabsq_s32(v_coeff); + // ((abs_coeff << (1 + log_scale)) >= dequant_ptr[rc01]) + const int32x4_t v_abs_coeff_scaled = vshlq_n_s32(v_abs_coeff, 2); + const uint32x4_t v_mask = vcgeq_s32(v_abs_coeff_scaled, v_dequant_s32); + // const int64_t tmp = vmask ? (int64_t)abs_coeff + log_scaled_round : 0 + const int32x4_t v_tmp = vandq_s32(vaddq_s32(v_abs_coeff, v_round_s32), + vreinterpretq_s32_u32(v_mask)); + // const int abs_qcoeff = (int)((tmp * quant) >> (16 - log_scale)); + const int32x4_t v_abs_qcoeff = + vqdmulhq_s32(vshlq_n_s32(v_tmp, 1), v_quant_s32); + // qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign); + const int32x4_t v_qcoeff = + vsubq_s32(veorq_s32(v_abs_qcoeff, v_coeff_sign), v_coeff_sign); + // vshlq_s32 will shift right if shift value is negative. + const int32x4_t v_abs_dqcoeff = + vshrq_n_s32(vmulq_s32(v_abs_qcoeff, v_dequant_s32), 1); + // dqcoeff_ptr[rc] = (tran_low_t)((abs_dqcoeff ^ coeff_sign) - coeff_sign); + const int32x4_t v_dqcoeff = + vsubq_s32(veorq_s32(v_abs_dqcoeff, v_coeff_sign), v_coeff_sign); + + vst1q_s32(qcoeff_ptr, v_qcoeff); + vst1q_s32(dqcoeff_ptr, v_dqcoeff); + + // Packed nz_qcoeff_mask. Used to find eob. + return vmovn_u32(vceqq_s32(v_abs_qcoeff, vdupq_n_s32(0))); +} + +void vp9_highbd_quantize_fp_32x32_neon( + const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *mb_plane, tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + const int16x4_t v_quant = vld1_s16(mb_plane->quant_fp); + const int16x4_t v_dequant = vld1_s16(dequant_ptr); + const int16x4_t v_zero = vdup_n_s16(0); + const int16x4_t v_round = + vqrdmulh_n_s16(vld1_s16(mb_plane->round_fp), (int16_t)(1 << 14)); + int32x4_t v_round_s32 = vaddl_s16(v_round, v_zero); + int32x4_t v_quant_s32 = vshlq_n_s32(vaddl_s16(v_quant, v_zero), 15); + int32x4_t v_dequant_s32 = vaddl_s16(v_dequant, v_zero); + uint16x4_t v_mask_lo, v_mask_hi; + int16x8_t v_eobmax = vdupq_n_s16(-1); + const int16_t *iscan = scan_order->iscan; + + // DC and first 3 AC + v_mask_lo = + highbd_quantize_fp_32x32_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, + v_quant_s32, v_dequant_s32, v_round_s32); + + // overwrite the DC constants with AC constants + v_round_s32 = vdupq_lane_s32(vget_low_s32(v_round_s32), 1); + v_quant_s32 = vdupq_lane_s32(vget_low_s32(v_quant_s32), 1); + v_dequant_s32 = vdupq_lane_s32(vget_low_s32(v_dequant_s32), 1); + + // 4 more AC + v_mask_hi = + highbd_quantize_fp_32x32_4(coeff_ptr + 4, qcoeff_ptr + 4, dqcoeff_ptr + 4, + v_quant_s32, v_dequant_s32, v_round_s32); + + // Find the max lane eob for the first 8 coeffs. + v_eobmax = + get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi)); + + n_coeffs -= 8; + do { + coeff_ptr += 8; + qcoeff_ptr += 8; + dqcoeff_ptr += 8; + iscan += 8; + v_mask_lo = + highbd_quantize_fp_32x32_4(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, + v_quant_s32, v_dequant_s32, v_round_s32); + v_mask_hi = highbd_quantize_fp_32x32_4(coeff_ptr + 4, qcoeff_ptr + 4, + dqcoeff_ptr + 4, v_quant_s32, + v_dequant_s32, v_round_s32); + // Find the max lane eob for 8 coeffs. + v_eobmax = + get_max_lane_eob(iscan, v_eobmax, vcombine_u16(v_mask_lo, v_mask_hi)); + n_coeffs -= 8; + } while (n_coeffs); + + *eob_ptr = get_max_eob(v_eobmax); +} +#endif // CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon.c new file mode 100644 index 0000000000..b6cce39bfe --- /dev/null +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon.c @@ -0,0 +1,1103 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vp9_rtcd.h" +#include "./vpx_config.h" +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/transpose_neon.h" +#include "vp9/encoder/vp9_encoder.h" +#include "vp9/encoder/vp9_temporal_filter.h" +#include "vp9/encoder/vp9_temporal_filter_constants.h" + +// Read in 8 pixels from a and b as 8-bit unsigned integers, compute the +// difference squared, and store as unsigned 16-bit integer to dst. +static INLINE void store_dist_8(const uint8_t *a, const uint8_t *b, + uint16_t *dst) { + const uint8x8_t a_reg = vld1_u8(a); + const uint8x8_t b_reg = vld1_u8(b); + + uint16x8_t dist_first = vabdl_u8(a_reg, b_reg); + dist_first = vmulq_u16(dist_first, dist_first); + + vst1q_u16(dst, dist_first); +} + +static INLINE void store_dist_16(const uint8_t *a, const uint8_t *b, + uint16_t *dst) { + const uint8x16_t a_reg = vld1q_u8(a); + const uint8x16_t b_reg = vld1q_u8(b); + + uint16x8_t dist_first = vabdl_u8(vget_low_u8(a_reg), vget_low_u8(b_reg)); + uint16x8_t dist_second = vabdl_u8(vget_high_u8(a_reg), vget_high_u8(b_reg)); + dist_first = vmulq_u16(dist_first, dist_first); + dist_second = vmulq_u16(dist_second, dist_second); + + vst1q_u16(dst, dist_first); + vst1q_u16(dst + 8, dist_second); +} + +static INLINE void read_dist_8(const uint16_t *dist, uint16x8_t *dist_reg) { + *dist_reg = vld1q_u16(dist); +} + +static INLINE void read_dist_16(const uint16_t *dist, uint16x8_t *reg_first, + uint16x8_t *reg_second) { + read_dist_8(dist, reg_first); + read_dist_8(dist + 8, reg_second); +} + +// Average the value based on the number of values summed (9 for pixels away +// from the border, 4 for pixels in corners, and 6 for other edge values). +// +// Add in the rounding factor and shift, clamp to 16, invert and shift. Multiply +// by weight. +static INLINE uint16x8_t average_8(uint16x8_t sum, + const uint16x8_t *mul_constants, + const int strength, const int rounding, + const uint16x8_t *weight) { + const uint32x4_t rounding_u32 = vdupq_n_u32(rounding << 16); + const uint16x8_t weight_u16 = *weight; + const uint16x8_t sixteen = vdupq_n_u16(16); + const int32x4_t strength_u32 = vdupq_n_s32(-strength - 16); + + // modifier * 3 / index; + uint32x4_t sum_hi = + vmull_u16(vget_low_u16(sum), vget_low_u16(*mul_constants)); + uint32x4_t sum_lo = + vmull_u16(vget_high_u16(sum), vget_high_u16(*mul_constants)); + + sum_lo = vqaddq_u32(sum_lo, rounding_u32); + sum_hi = vqaddq_u32(sum_hi, rounding_u32); + + // we cannot use vshrn_n_u32 as strength is not known at compile time. + sum_lo = vshlq_u32(sum_lo, strength_u32); + sum_hi = vshlq_u32(sum_hi, strength_u32); + + sum = vcombine_u16(vmovn_u32(sum_hi), vmovn_u32(sum_lo)); + + // The maximum input to this comparison is UINT16_MAX * NEIGHBOR_CONSTANT_4 + // >> 16 (also NEIGHBOR_CONSTANT_4 -1) which is 49151 / 0xbfff / -16385 + // So this needs to use the epu16 version which did not come until SSE4. + sum = vminq_u16(sum, sixteen); + sum = vsubq_u16(sixteen, sum); + return vmulq_u16(sum, weight_u16); +} + +// Add 'sum_u16' to 'count'. Multiply by 'pred' and add to 'accumulator.' +static void accumulate_and_store_8(const uint16x8_t sum_u16, + const uint8_t *pred, uint16_t *count, + uint32_t *accumulator) { + uint16x8_t pred_u16 = vmovl_u8(vld1_u8(pred)); + uint16x8_t count_u16 = vld1q_u16(count); + uint32x4_t accum_0_u32, accum_1_u32; + + count_u16 = vqaddq_u16(count_u16, sum_u16); + vst1q_u16(count, count_u16); + + accum_0_u32 = vld1q_u32(accumulator); + accum_1_u32 = vld1q_u32(accumulator + 4); + + accum_0_u32 = + vmlal_u16(accum_0_u32, vget_low_u16(sum_u16), vget_low_u16(pred_u16)); + accum_1_u32 = + vmlal_u16(accum_1_u32, vget_high_u16(sum_u16), vget_high_u16(pred_u16)); + + vst1q_u32(accumulator, accum_0_u32); + vst1q_u32(accumulator + 4, accum_1_u32); +} + +static INLINE void accumulate_and_store_16(const uint16x8_t sum_0_u16, + const uint16x8_t sum_1_u16, + const uint8_t *pred, uint16_t *count, + uint32_t *accumulator) { + uint8x16_t pred_u8 = vld1q_u8(pred); + uint16x8_t pred_0_u16 = vmovl_u8(vget_low_u8(pred_u8)); + uint16x8_t pred_1_u16 = vmovl_u8(vget_high_u8(pred_u8)); + uint16x8_t count_0_u16 = vld1q_u16(count); + uint16x8_t count_1_u16 = vld1q_u16(count + 8); + uint32x4_t accum_0_u32, accum_1_u32, accum_2_u32, accum_3_u32; + + count_0_u16 = vqaddq_u16(count_0_u16, sum_0_u16); + vst1q_u16(count, count_0_u16); + count_1_u16 = vqaddq_u16(count_1_u16, sum_1_u16); + vst1q_u16(count + 8, count_1_u16); + + accum_0_u32 = vld1q_u32(accumulator); + accum_1_u32 = vld1q_u32(accumulator + 4); + accum_2_u32 = vld1q_u32(accumulator + 8); + accum_3_u32 = vld1q_u32(accumulator + 12); + + accum_0_u32 = + vmlal_u16(accum_0_u32, vget_low_u16(sum_0_u16), vget_low_u16(pred_0_u16)); + accum_1_u32 = vmlal_u16(accum_1_u32, vget_high_u16(sum_0_u16), + vget_high_u16(pred_0_u16)); + accum_2_u32 = + vmlal_u16(accum_2_u32, vget_low_u16(sum_1_u16), vget_low_u16(pred_1_u16)); + accum_3_u32 = vmlal_u16(accum_3_u32, vget_high_u16(sum_1_u16), + vget_high_u16(pred_1_u16)); + + vst1q_u32(accumulator, accum_0_u32); + vst1q_u32(accumulator + 4, accum_1_u32); + vst1q_u32(accumulator + 8, accum_2_u32); + vst1q_u32(accumulator + 12, accum_3_u32); +} + +// Read in 8 pixels from y_dist. For each index i, compute y_dist[i-1] + +// y_dist[i] + y_dist[i+1] and store in sum as 16-bit unsigned int. +static INLINE void get_sum_8(const uint16_t *y_dist, uint16x8_t *sum) { + uint16x8_t dist_reg, dist_left, dist_right; + + dist_reg = vld1q_u16(y_dist); + dist_left = vld1q_u16(y_dist - 1); + dist_right = vld1q_u16(y_dist + 1); + + *sum = vqaddq_u16(dist_reg, dist_left); + *sum = vqaddq_u16(*sum, dist_right); +} + +// Read in 16 pixels from y_dist. For each index i, compute y_dist[i-1] + +// y_dist[i] + y_dist[i+1]. Store the result for first 8 pixels in sum_first and +// the rest in sum_second. +static INLINE void get_sum_16(const uint16_t *y_dist, uint16x8_t *sum_first, + uint16x8_t *sum_second) { + get_sum_8(y_dist, sum_first); + get_sum_8(y_dist + 8, sum_second); +} + +// Read in a row of chroma values corresponds to a row of 16 luma values. +static INLINE void read_chroma_dist_row_16(int ss_x, const uint16_t *u_dist, + const uint16_t *v_dist, + uint16x8_t *u_first, + uint16x8_t *u_second, + uint16x8_t *v_first, + uint16x8_t *v_second) { + if (!ss_x) { + // If there is no chroma subsampling in the horizontal direction, then we + // need to load 16 entries from chroma. + read_dist_16(u_dist, u_first, u_second); + read_dist_16(v_dist, v_first, v_second); + } else { // ss_x == 1 + // Otherwise, we only need to load 8 entries + uint16x8_t u_reg, v_reg; + uint16x8x2_t pair; + + read_dist_8(u_dist, &u_reg); + + pair = vzipq_u16(u_reg, u_reg); + *u_first = pair.val[0]; + *u_second = pair.val[1]; + + read_dist_8(v_dist, &v_reg); + + pair = vzipq_u16(v_reg, v_reg); + *v_first = pair.val[0]; + *v_second = pair.val[1]; + } +} + +// Add a row of luma distortion to 8 corresponding chroma mods. +static INLINE void add_luma_dist_to_8_chroma_mod(const uint16_t *y_dist, + int ss_x, int ss_y, + uint16x8_t *u_mod, + uint16x8_t *v_mod) { + uint16x8_t y_reg; + if (!ss_x) { + read_dist_8(y_dist, &y_reg); + if (ss_y == 1) { + uint16x8_t y_tmp; + read_dist_8(y_dist + DIST_STRIDE, &y_tmp); + + y_reg = vqaddq_u16(y_reg, y_tmp); + } + } else { + uint16x8_t y_first, y_second; + uint32x4_t y_first32, y_second32; + + read_dist_16(y_dist, &y_first, &y_second); + if (ss_y == 1) { + uint16x8_t y_tmp_0, y_tmp_1; + read_dist_16(y_dist + DIST_STRIDE, &y_tmp_0, &y_tmp_1); + + y_first = vqaddq_u16(y_first, y_tmp_0); + y_second = vqaddq_u16(y_second, y_tmp_1); + } + + y_first32 = vpaddlq_u16(y_first); + y_second32 = vpaddlq_u16(y_second); + + y_reg = vcombine_u16(vqmovn_u32(y_first32), vqmovn_u32(y_second32)); + } + + *u_mod = vqaddq_u16(*u_mod, y_reg); + *v_mod = vqaddq_u16(*v_mod, y_reg); +} + +// Apply temporal filter to the luma components. This performs temporal +// filtering on a luma block of 16 X block_height. Use blk_fw as an array of +// size 4 for the weights for each of the 4 subblocks if blk_fw is not NULL, +// else use top_weight for top half, and bottom weight for bottom half. +static void apply_temporal_filter_luma_16( + const uint8_t *y_pre, int y_pre_stride, unsigned int block_width, + unsigned int block_height, int ss_x, int ss_y, int strength, + int use_whole_blk, uint32_t *y_accum, uint16_t *y_count, + const uint16_t *y_dist, const uint16_t *u_dist, const uint16_t *v_dist, + const int16_t *const *neighbors_first, + const int16_t *const *neighbors_second, int top_weight, int bottom_weight, + const int *blk_fw) { + const int rounding = (1 << strength) >> 1; + uint16x8_t weight_first, weight_second; + + uint16x8_t mul_first, mul_second; + + uint16x8_t sum_row_1_first, sum_row_1_second; + uint16x8_t sum_row_2_first, sum_row_2_second; + uint16x8_t sum_row_3_first, sum_row_3_second; + + uint16x8_t u_first, u_second; + uint16x8_t v_first, v_second; + + uint16x8_t sum_row_first; + uint16x8_t sum_row_second; + + // Loop variables + unsigned int h; + + assert(strength >= 0); + assert(strength <= 6); + + assert(block_width == 16); + (void)block_width; + + // Initialize the weights + if (blk_fw) { + weight_first = vdupq_n_u16(blk_fw[0]); + weight_second = vdupq_n_u16(blk_fw[1]); + } else { + weight_first = vdupq_n_u16(top_weight); + weight_second = weight_first; + } + + // First row + mul_first = vld1q_u16((const uint16_t *)neighbors_first[0]); + mul_second = vld1q_u16((const uint16_t *)neighbors_second[0]); + + // Add luma values + get_sum_16(y_dist, &sum_row_2_first, &sum_row_2_second); + get_sum_16(y_dist + DIST_STRIDE, &sum_row_3_first, &sum_row_3_second); + + sum_row_first = vqaddq_u16(sum_row_2_first, sum_row_3_first); + sum_row_second = vqaddq_u16(sum_row_2_second, sum_row_3_second); + + // Add chroma values + read_chroma_dist_row_16(ss_x, u_dist, v_dist, &u_first, &u_second, &v_first, + &v_second); + + sum_row_first = vqaddq_u16(sum_row_first, u_first); + sum_row_second = vqaddq_u16(sum_row_second, u_second); + + sum_row_first = vqaddq_u16(sum_row_first, v_first); + sum_row_second = vqaddq_u16(sum_row_second, v_second); + + // Get modifier and store result + sum_row_first = + average_8(sum_row_first, &mul_first, strength, rounding, &weight_first); + + sum_row_second = average_8(sum_row_second, &mul_second, strength, rounding, + &weight_second); + + accumulate_and_store_16(sum_row_first, sum_row_second, y_pre, y_count, + y_accum); + + y_pre += y_pre_stride; + y_count += y_pre_stride; + y_accum += y_pre_stride; + y_dist += DIST_STRIDE; + + u_dist += DIST_STRIDE; + v_dist += DIST_STRIDE; + + // Then all the rows except the last one + mul_first = vld1q_u16((const uint16_t *)neighbors_first[1]); + mul_second = vld1q_u16((const uint16_t *)neighbors_second[1]); + + for (h = 1; h < block_height - 1; ++h) { + // Move the weight to bottom half + if (!use_whole_blk && h == block_height / 2) { + if (blk_fw) { + weight_first = vdupq_n_u16(blk_fw[2]); + weight_second = vdupq_n_u16(blk_fw[3]); + } else { + weight_first = vdupq_n_u16(bottom_weight); + weight_second = weight_first; + } + } + // Shift the rows up + sum_row_1_first = sum_row_2_first; + sum_row_1_second = sum_row_2_second; + sum_row_2_first = sum_row_3_first; + sum_row_2_second = sum_row_3_second; + + // Add luma values to the modifier + sum_row_first = vqaddq_u16(sum_row_1_first, sum_row_2_first); + sum_row_second = vqaddq_u16(sum_row_1_second, sum_row_2_second); + + get_sum_16(y_dist + DIST_STRIDE, &sum_row_3_first, &sum_row_3_second); + + sum_row_first = vqaddq_u16(sum_row_first, sum_row_3_first); + sum_row_second = vqaddq_u16(sum_row_second, sum_row_3_second); + + // Add chroma values to the modifier + if (ss_y == 0 || h % 2 == 0) { + // Only calculate the new chroma distortion if we are at a pixel that + // corresponds to a new chroma row + read_chroma_dist_row_16(ss_x, u_dist, v_dist, &u_first, &u_second, + &v_first, &v_second); + u_dist += DIST_STRIDE; + v_dist += DIST_STRIDE; + } + + sum_row_first = vqaddq_u16(sum_row_first, u_first); + sum_row_second = vqaddq_u16(sum_row_second, u_second); + sum_row_first = vqaddq_u16(sum_row_first, v_first); + sum_row_second = vqaddq_u16(sum_row_second, v_second); + + // Get modifier and store result + sum_row_first = + average_8(sum_row_first, &mul_first, strength, rounding, &weight_first); + sum_row_second = average_8(sum_row_second, &mul_second, strength, rounding, + &weight_second); + accumulate_and_store_16(sum_row_first, sum_row_second, y_pre, y_count, + y_accum); + y_pre += y_pre_stride; + y_count += y_pre_stride; + y_accum += y_pre_stride; + y_dist += DIST_STRIDE; + } + + // The last row + mul_first = vld1q_u16((const uint16_t *)neighbors_first[0]); + mul_second = vld1q_u16((const uint16_t *)neighbors_second[0]); + + // Shift the rows up + sum_row_1_first = sum_row_2_first; + sum_row_1_second = sum_row_2_second; + sum_row_2_first = sum_row_3_first; + sum_row_2_second = sum_row_3_second; + + // Add luma values to the modifier + sum_row_first = vqaddq_u16(sum_row_1_first, sum_row_2_first); + sum_row_second = vqaddq_u16(sum_row_1_second, sum_row_2_second); + + // Add chroma values to the modifier + if (ss_y == 0) { + // Only calculate the new chroma distortion if we are at a pixel that + // corresponds to a new chroma row + read_chroma_dist_row_16(ss_x, u_dist, v_dist, &u_first, &u_second, &v_first, + &v_second); + } + + sum_row_first = vqaddq_u16(sum_row_first, u_first); + sum_row_second = vqaddq_u16(sum_row_second, u_second); + sum_row_first = vqaddq_u16(sum_row_first, v_first); + sum_row_second = vqaddq_u16(sum_row_second, v_second); + + // Get modifier and store result + sum_row_first = + average_8(sum_row_first, &mul_first, strength, rounding, &weight_first); + sum_row_second = average_8(sum_row_second, &mul_second, strength, rounding, + &weight_second); + accumulate_and_store_16(sum_row_first, sum_row_second, y_pre, y_count, + y_accum); +} + +// Perform temporal filter for the luma component. +static void apply_temporal_filter_luma( + const uint8_t *y_pre, int y_pre_stride, unsigned int block_width, + unsigned int block_height, int ss_x, int ss_y, int strength, + const int *blk_fw, int use_whole_blk, uint32_t *y_accum, uint16_t *y_count, + const uint16_t *y_dist, const uint16_t *u_dist, const uint16_t *v_dist) { + unsigned int blk_col = 0, uv_blk_col = 0; + const unsigned int blk_col_step = 16, uv_blk_col_step = 16 >> ss_x; + const unsigned int mid_width = block_width >> 1, + last_width = block_width - blk_col_step; + int top_weight = blk_fw[0], + bottom_weight = use_whole_blk ? blk_fw[0] : blk_fw[2]; + const int16_t *const *neighbors_first; + const int16_t *const *neighbors_second; + + if (block_width == 16) { + // Special Case: The block width is 16 and we are operating on a row of 16 + // chroma pixels. In this case, we can't use the usual left-middle-right + // pattern. We also don't support splitting now. + neighbors_first = LUMA_LEFT_COLUMN_NEIGHBORS; + neighbors_second = LUMA_RIGHT_COLUMN_NEIGHBORS; + if (use_whole_blk) { + apply_temporal_filter_luma_16( + y_pre + blk_col, y_pre_stride, 16, block_height, ss_x, ss_y, strength, + use_whole_blk, y_accum + blk_col, y_count + blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_first, + neighbors_second, top_weight, bottom_weight, NULL); + } else { + apply_temporal_filter_luma_16( + y_pre + blk_col, y_pre_stride, 16, block_height, ss_x, ss_y, strength, + use_whole_blk, y_accum + blk_col, y_count + blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_first, + neighbors_second, 0, 0, blk_fw); + } + + return; + } + + // Left + neighbors_first = LUMA_LEFT_COLUMN_NEIGHBORS; + neighbors_second = LUMA_MIDDLE_COLUMN_NEIGHBORS; + apply_temporal_filter_luma_16( + y_pre + blk_col, y_pre_stride, 16, block_height, ss_x, ss_y, strength, + use_whole_blk, y_accum + blk_col, y_count + blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_first, + neighbors_second, top_weight, bottom_weight, NULL); + + blk_col += blk_col_step; + uv_blk_col += uv_blk_col_step; + + // Middle First + neighbors_first = LUMA_MIDDLE_COLUMN_NEIGHBORS; + for (; blk_col < mid_width; + blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { + apply_temporal_filter_luma_16( + y_pre + blk_col, y_pre_stride, 16, block_height, ss_x, ss_y, strength, + use_whole_blk, y_accum + blk_col, y_count + blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_first, + neighbors_second, top_weight, bottom_weight, NULL); + } + + if (!use_whole_blk) { + top_weight = blk_fw[1]; + bottom_weight = blk_fw[3]; + } + + // Middle Second + for (; blk_col < last_width; + blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { + apply_temporal_filter_luma_16( + y_pre + blk_col, y_pre_stride, 16, block_height, ss_x, ss_y, strength, + use_whole_blk, y_accum + blk_col, y_count + blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_first, + neighbors_second, top_weight, bottom_weight, NULL); + } + + // Right + neighbors_second = LUMA_RIGHT_COLUMN_NEIGHBORS; + apply_temporal_filter_luma_16( + y_pre + blk_col, y_pre_stride, 16, block_height, ss_x, ss_y, strength, + use_whole_blk, y_accum + blk_col, y_count + blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_first, + neighbors_second, top_weight, bottom_weight, NULL); +} + +// Apply temporal filter to the chroma components. This performs temporal +// filtering on a chroma block of 8 X uv_height. If blk_fw is not NULL, use +// blk_fw as an array of size 4 for the weights for each of the 4 subblocks, +// else use top_weight for top half, and bottom weight for bottom half. +static void apply_temporal_filter_chroma_8( + const uint8_t *u_pre, const uint8_t *v_pre, int uv_pre_stride, + unsigned int uv_block_height, int ss_x, int ss_y, int strength, + uint32_t *u_accum, uint16_t *u_count, uint32_t *v_accum, uint16_t *v_count, + const uint16_t *y_dist, const uint16_t *u_dist, const uint16_t *v_dist, + const int16_t *const *neighbors, int top_weight, int bottom_weight, + const int *blk_fw) { + const int rounding = (1 << strength) >> 1; + + uint16x8_t weight; + + uint16x8_t mul; + + uint16x8_t u_sum_row_1, u_sum_row_2, u_sum_row_3; + uint16x8_t v_sum_row_1, v_sum_row_2, v_sum_row_3; + + uint16x8_t u_sum_row, v_sum_row; + + // Loop variable + unsigned int h; + + // Initialize weight + if (blk_fw) { + weight = vcombine_u16(vdup_n_u16(blk_fw[0]), vdup_n_u16(blk_fw[1])); + } else { + weight = vdupq_n_u16(top_weight); + } + + // First row + mul = vld1q_u16((const uint16_t *)neighbors[0]); + + // Add chroma values + get_sum_8(u_dist, &u_sum_row_2); + get_sum_8(u_dist + DIST_STRIDE, &u_sum_row_3); + + u_sum_row = vqaddq_u16(u_sum_row_2, u_sum_row_3); + + get_sum_8(v_dist, &v_sum_row_2); + get_sum_8(v_dist + DIST_STRIDE, &v_sum_row_3); + + v_sum_row = vqaddq_u16(v_sum_row_2, v_sum_row_3); + + // Add luma values + add_luma_dist_to_8_chroma_mod(y_dist, ss_x, ss_y, &u_sum_row, &v_sum_row); + + // Get modifier and store result + u_sum_row = average_8(u_sum_row, &mul, strength, rounding, &weight); + v_sum_row = average_8(v_sum_row, &mul, strength, rounding, &weight); + + accumulate_and_store_8(u_sum_row, u_pre, u_count, u_accum); + accumulate_and_store_8(v_sum_row, v_pre, v_count, v_accum); + + u_pre += uv_pre_stride; + u_dist += DIST_STRIDE; + v_pre += uv_pre_stride; + v_dist += DIST_STRIDE; + u_count += uv_pre_stride; + u_accum += uv_pre_stride; + v_count += uv_pre_stride; + v_accum += uv_pre_stride; + + y_dist += DIST_STRIDE * (1 + ss_y); + + // Then all the rows except the last one + mul = vld1q_u16((const uint16_t *)neighbors[1]); + + for (h = 1; h < uv_block_height - 1; ++h) { + // Move the weight pointer to the bottom half of the blocks + if (h == uv_block_height / 2) { + if (blk_fw) { + weight = vcombine_u16(vdup_n_u16(blk_fw[2]), vdup_n_u16(blk_fw[3])); + } else { + weight = vdupq_n_u16(bottom_weight); + } + } + + // Shift the rows up + u_sum_row_1 = u_sum_row_2; + u_sum_row_2 = u_sum_row_3; + + v_sum_row_1 = v_sum_row_2; + v_sum_row_2 = v_sum_row_3; + + // Add chroma values + u_sum_row = vqaddq_u16(u_sum_row_1, u_sum_row_2); + get_sum_8(u_dist + DIST_STRIDE, &u_sum_row_3); + u_sum_row = vqaddq_u16(u_sum_row, u_sum_row_3); + + v_sum_row = vqaddq_u16(v_sum_row_1, v_sum_row_2); + get_sum_8(v_dist + DIST_STRIDE, &v_sum_row_3); + v_sum_row = vqaddq_u16(v_sum_row, v_sum_row_3); + + // Add luma values + add_luma_dist_to_8_chroma_mod(y_dist, ss_x, ss_y, &u_sum_row, &v_sum_row); + + // Get modifier and store result + u_sum_row = average_8(u_sum_row, &mul, strength, rounding, &weight); + v_sum_row = average_8(v_sum_row, &mul, strength, rounding, &weight); + + accumulate_and_store_8(u_sum_row, u_pre, u_count, u_accum); + accumulate_and_store_8(v_sum_row, v_pre, v_count, v_accum); + + u_pre += uv_pre_stride; + u_dist += DIST_STRIDE; + v_pre += uv_pre_stride; + v_dist += DIST_STRIDE; + u_count += uv_pre_stride; + u_accum += uv_pre_stride; + v_count += uv_pre_stride; + v_accum += uv_pre_stride; + + y_dist += DIST_STRIDE * (1 + ss_y); + } + + // The last row + mul = vld1q_u16((const uint16_t *)neighbors[0]); + + // Shift the rows up + u_sum_row_1 = u_sum_row_2; + u_sum_row_2 = u_sum_row_3; + + v_sum_row_1 = v_sum_row_2; + v_sum_row_2 = v_sum_row_3; + + // Add chroma values + u_sum_row = vqaddq_u16(u_sum_row_1, u_sum_row_2); + v_sum_row = vqaddq_u16(v_sum_row_1, v_sum_row_2); + + // Add luma values + add_luma_dist_to_8_chroma_mod(y_dist, ss_x, ss_y, &u_sum_row, &v_sum_row); + + // Get modifier and store result + u_sum_row = average_8(u_sum_row, &mul, strength, rounding, &weight); + v_sum_row = average_8(v_sum_row, &mul, strength, rounding, &weight); + + accumulate_and_store_8(u_sum_row, u_pre, u_count, u_accum); + accumulate_and_store_8(v_sum_row, v_pre, v_count, v_accum); +} + +// Perform temporal filter for the chroma components. +static void apply_temporal_filter_chroma( + const uint8_t *u_pre, const uint8_t *v_pre, int uv_pre_stride, + unsigned int block_width, unsigned int block_height, int ss_x, int ss_y, + int strength, const int *blk_fw, int use_whole_blk, uint32_t *u_accum, + uint16_t *u_count, uint32_t *v_accum, uint16_t *v_count, + const uint16_t *y_dist, const uint16_t *u_dist, const uint16_t *v_dist) { + const unsigned int uv_width = block_width >> ss_x, + uv_height = block_height >> ss_y; + + unsigned int blk_col = 0, uv_blk_col = 0; + const unsigned int uv_blk_col_step = 8, blk_col_step = 8 << ss_x; + const unsigned int uv_mid_width = uv_width >> 1, + uv_last_width = uv_width - uv_blk_col_step; + int top_weight = blk_fw[0], + bottom_weight = use_whole_blk ? blk_fw[0] : blk_fw[2]; + const int16_t *const *neighbors; + + if (uv_width == 8) { + // Special Case: We are subsampling in x direction on a 16x16 block. Since + // we are operating on a row of 8 chroma pixels, we can't use the usual + // left-middle-right pattern. + assert(ss_x); + + if (ss_y) { + neighbors = CHROMA_DOUBLE_SS_SINGLE_COLUMN_NEIGHBORS; + } else { + neighbors = CHROMA_SINGLE_SS_SINGLE_COLUMN_NEIGHBORS; + } + + if (use_whole_blk) { + apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_height, + ss_x, ss_y, strength, u_accum + uv_blk_col, u_count + uv_blk_col, + v_accum + uv_blk_col, v_count + uv_blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors, top_weight, + bottom_weight, NULL); + } else { + apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_height, + ss_x, ss_y, strength, u_accum + uv_blk_col, u_count + uv_blk_col, + v_accum + uv_blk_col, v_count + uv_blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors, 0, 0, blk_fw); + } + + return; + } + + // Left + if (ss_x && ss_y) { + neighbors = CHROMA_DOUBLE_SS_LEFT_COLUMN_NEIGHBORS; + } else if (ss_x || ss_y) { + neighbors = CHROMA_SINGLE_SS_LEFT_COLUMN_NEIGHBORS; + } else { + neighbors = CHROMA_NO_SS_LEFT_COLUMN_NEIGHBORS; + } + + apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_height, ss_x, + ss_y, strength, u_accum + uv_blk_col, u_count + uv_blk_col, + v_accum + uv_blk_col, v_count + uv_blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors, top_weight, + bottom_weight, NULL); + + blk_col += blk_col_step; + uv_blk_col += uv_blk_col_step; + + // Middle First + if (ss_x && ss_y) { + neighbors = CHROMA_DOUBLE_SS_MIDDLE_COLUMN_NEIGHBORS; + } else if (ss_x || ss_y) { + neighbors = CHROMA_SINGLE_SS_MIDDLE_COLUMN_NEIGHBORS; + } else { + neighbors = CHROMA_NO_SS_MIDDLE_COLUMN_NEIGHBORS; + } + + for (; uv_blk_col < uv_mid_width; + blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { + apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_height, ss_x, + ss_y, strength, u_accum + uv_blk_col, u_count + uv_blk_col, + v_accum + uv_blk_col, v_count + uv_blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors, top_weight, + bottom_weight, NULL); + } + + if (!use_whole_blk) { + top_weight = blk_fw[1]; + bottom_weight = blk_fw[3]; + } + + // Middle Second + for (; uv_blk_col < uv_last_width; + blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { + apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_height, ss_x, + ss_y, strength, u_accum + uv_blk_col, u_count + uv_blk_col, + v_accum + uv_blk_col, v_count + uv_blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors, top_weight, + bottom_weight, NULL); + } + + // Right + if (ss_x && ss_y) { + neighbors = CHROMA_DOUBLE_SS_RIGHT_COLUMN_NEIGHBORS; + } else if (ss_x || ss_y) { + neighbors = CHROMA_SINGLE_SS_RIGHT_COLUMN_NEIGHBORS; + } else { + neighbors = CHROMA_NO_SS_RIGHT_COLUMN_NEIGHBORS; + } + + apply_temporal_filter_chroma_8( + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_height, ss_x, + ss_y, strength, u_accum + uv_blk_col, u_count + uv_blk_col, + v_accum + uv_blk_col, v_count + uv_blk_col, y_dist + blk_col, + u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors, top_weight, + bottom_weight, NULL); +} + +void vp9_apply_temporal_filter_neon( + const uint8_t *y_src, int y_src_stride, const uint8_t *y_pre, + int y_pre_stride, const uint8_t *u_src, const uint8_t *v_src, + int uv_src_stride, const uint8_t *u_pre, const uint8_t *v_pre, + int uv_pre_stride, unsigned int block_width, unsigned int block_height, + int ss_x, int ss_y, int strength, const int *const blk_fw, + int use_whole_blk, uint32_t *y_accum, uint16_t *y_count, uint32_t *u_accum, + uint16_t *u_count, uint32_t *v_accum, uint16_t *v_count) { + const unsigned int chroma_height = block_height >> ss_y, + chroma_width = block_width >> ss_x; + + DECLARE_ALIGNED(16, uint16_t, y_dist[BH * DIST_STRIDE]) = { 0 }; + DECLARE_ALIGNED(16, uint16_t, u_dist[BH * DIST_STRIDE]) = { 0 }; + DECLARE_ALIGNED(16, uint16_t, v_dist[BH * DIST_STRIDE]) = { 0 }; + const int *blk_fw_ptr = blk_fw; + + uint16_t *y_dist_ptr = y_dist + 1, *u_dist_ptr = u_dist + 1, + *v_dist_ptr = v_dist + 1; + const uint8_t *y_src_ptr = y_src, *u_src_ptr = u_src, *v_src_ptr = v_src; + const uint8_t *y_pre_ptr = y_pre, *u_pre_ptr = u_pre, *v_pre_ptr = v_pre; + + // Loop variables + unsigned int row, blk_col; + + assert(block_width <= BW && "block width too large"); + assert(block_height <= BH && "block height too large"); + assert(block_width % 16 == 0 && "block width must be multiple of 16"); + assert(block_height % 2 == 0 && "block height must be even"); + assert((ss_x == 0 || ss_x == 1) && (ss_y == 0 || ss_y == 1) && + "invalid chroma subsampling"); + assert(strength >= 0 && strength <= 6 && "invalid temporal filter strength"); + assert(blk_fw[0] >= 0 && "filter weight must be positive"); + assert( + (use_whole_blk || (blk_fw[1] >= 0 && blk_fw[2] >= 0 && blk_fw[3] >= 0)) && + "subblock filter weight must be positive"); + assert(blk_fw[0] <= 2 && "subblock filter weight must be less than 2"); + assert( + (use_whole_blk || (blk_fw[1] <= 2 && blk_fw[2] <= 2 && blk_fw[3] <= 2)) && + "subblock filter weight must be less than 2"); + + // Precompute the difference squared + for (row = 0; row < block_height; row++) { + for (blk_col = 0; blk_col < block_width; blk_col += 16) { + store_dist_16(y_src_ptr + blk_col, y_pre_ptr + blk_col, + y_dist_ptr + blk_col); + } + y_src_ptr += y_src_stride; + y_pre_ptr += y_pre_stride; + y_dist_ptr += DIST_STRIDE; + } + + for (row = 0; row < chroma_height; row++) { + for (blk_col = 0; blk_col < chroma_width; blk_col += 8) { + store_dist_8(u_src_ptr + blk_col, u_pre_ptr + blk_col, + u_dist_ptr + blk_col); + store_dist_8(v_src_ptr + blk_col, v_pre_ptr + blk_col, + v_dist_ptr + blk_col); + } + + u_src_ptr += uv_src_stride; + u_pre_ptr += uv_pre_stride; + u_dist_ptr += DIST_STRIDE; + v_src_ptr += uv_src_stride; + v_pre_ptr += uv_pre_stride; + v_dist_ptr += DIST_STRIDE; + } + + y_dist_ptr = y_dist + 1; + u_dist_ptr = u_dist + 1; + v_dist_ptr = v_dist + 1; + + apply_temporal_filter_luma(y_pre, y_pre_stride, block_width, block_height, + ss_x, ss_y, strength, blk_fw_ptr, use_whole_blk, + y_accum, y_count, y_dist_ptr, u_dist_ptr, + v_dist_ptr); + + apply_temporal_filter_chroma(u_pre, v_pre, uv_pre_stride, block_width, + block_height, ss_x, ss_y, strength, blk_fw_ptr, + use_whole_blk, u_accum, u_count, v_accum, + v_count, y_dist_ptr, u_dist_ptr, v_dist_ptr); +} + +static INLINE uint8x8_t convolve12_8(const int16x8_t s0, const int16x8_t s1, + const int16x8_t s2, const int16x8_t s3, + const int16x8_t s4, const int16x8_t s5, + const int16x8_t s6, const int16x8_t s7, + const int16x8_t s8, const int16x8_t s9, + const int16x8_t sA, const int16x8_t sB, + const int16x8_t filter_0_7, + const int16x4_t filter_8_11) { + const int16x4_t filter_0_3 = vget_low_s16(filter_0_7); + const int16x4_t filter_4_7 = vget_high_s16(filter_0_7); + + int16x8_t sum = vmulq_lane_s16(s0, filter_0_3, 0); + sum = vmlaq_lane_s16(sum, s1, filter_0_3, 1); + sum = vmlaq_lane_s16(sum, s2, filter_0_3, 2); + sum = vmlaq_lane_s16(sum, s3, filter_0_3, 3); + sum = vmlaq_lane_s16(sum, s4, filter_4_7, 0); + + sum = vmlaq_lane_s16(sum, s7, filter_4_7, 3); + sum = vmlaq_lane_s16(sum, s8, filter_8_11, 0); + sum = vmlaq_lane_s16(sum, s9, filter_8_11, 1); + sum = vmlaq_lane_s16(sum, sA, filter_8_11, 2); + sum = vmlaq_lane_s16(sum, sB, filter_8_11, 3); + + // Saturating addition is required for the largest filter taps to avoid + // overflow (while staying in 16-bit elements.) + sum = vqaddq_s16(sum, vmulq_lane_s16(s5, filter_4_7, 1)); + sum = vqaddq_s16(sum, vmulq_lane_s16(s6, filter_4_7, 2)); + + return vqrshrun_n_s16(sum, FILTER_BITS); +} + +void vpx_convolve12_horiz_neon(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + // Scaling not supported by Neon implementation. + if (x_step_q4 != 16) { + vpx_convolve12_horiz_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h % 4 == 0); + + const int16x8_t filter_0_7 = vld1q_s16(filter[x0_q4]); + const int16x4_t filter_8_11 = vld1_s16(filter[x0_q4] + 8); + + src -= MAX_FILTER_TAP / 2 - 1; + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + uint8x8_t t0, t1, t2, t3; + load_u8_8x4(s, src_stride, &t0, &t1, &t2, &t3); + transpose_u8_8x4(&t0, &t1, &t2, &t3); + + int16x4_t s0 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t0))); + int16x4_t s1 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t1))); + int16x4_t s2 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t2))); + int16x4_t s3 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t3))); + int16x4_t s4 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t0))); + int16x4_t s5 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t1))); + int16x4_t s6 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t2))); + int16x4_t s7 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t3))); + + int16x8_t s0s1 = vcombine_s16(s0, s1); + int16x8_t s1s2 = vcombine_s16(s1, s2); + int16x8_t s2s3 = vcombine_s16(s2, s3); + int16x8_t s3s4 = vcombine_s16(s3, s4); + int16x8_t s4s5 = vcombine_s16(s4, s5); + int16x8_t s5s6 = vcombine_s16(s5, s6); + int16x8_t s6s7 = vcombine_s16(s6, s7); + + load_u8_8x4(s + 8, src_stride, &t0, &t1, &t2, &t3); + transpose_u8_8x4(&t0, &t1, &t2, &t3); + + int16x4_t s8 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t0))); + int16x4_t s9 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t1))); + int16x4_t sA = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t2))); + + int16x8_t s7s8 = vcombine_s16(s7, s8); + int16x8_t s8s9 = vcombine_s16(s8, s9); + int16x8_t s9sA = vcombine_s16(s9, sA); + + s += 11; + + do { + load_u8_8x4(s, src_stride, &t0, &t1, &t2, &t3); + transpose_u8_8x4(&t0, &t1, &t2, &t3); + + int16x4_t sB = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t0))); + int16x4_t sC = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t1))); + int16x4_t sD = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t2))); + int16x4_t sE = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t3))); + + int16x8_t sAsB = vcombine_s16(sA, sB); + int16x8_t sBsC = vcombine_s16(sB, sC); + int16x8_t sCsD = vcombine_s16(sC, sD); + int16x8_t sDsE = vcombine_s16(sD, sE); + + uint8x8_t d01 = + convolve12_8(s0s1, s1s2, s2s3, s3s4, s4s5, s5s6, s6s7, s7s8, s8s9, + s9sA, sAsB, sBsC, filter_0_7, filter_8_11); + uint8x8_t d23 = + convolve12_8(s2s3, s3s4, s4s5, s5s6, s6s7, s7s8, s8s9, s9sA, sAsB, + sBsC, sCsD, sDsE, filter_0_7, filter_8_11); + + transpose_u8_4x4(&d01, &d23); + + store_u8(d + 0 * dst_stride, 2 * dst_stride, d01); + store_u8(d + 1 * dst_stride, 2 * dst_stride, d23); + + s0s1 = s4s5; + s1s2 = s5s6; + s2s3 = s6s7; + s3s4 = s7s8; + s4s5 = s8s9; + s5s6 = s9sA; + s6s7 = sAsB; + s7s8 = sBsC; + s8s9 = sCsD; + s9sA = sDsE; + sA = sE; + s += 4; + d += 4; + width -= 4; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); +} + +void vpx_convolve12_vert_neon(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + // Scaling not supported by Neon implementation. + if (y_step_q4 != 16) { + vpx_convolve12_vert_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h == 32 || h == 16 || h == 8); + + const int16x8_t filter_0_7 = vld1q_s16(filter[y0_q4]); + const int16x4_t filter_8_11 = vld1_s16(filter[y0_q4] + 8); + + src -= src_stride * (MAX_FILTER_TAP / 2 - 1); + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int height = h; + + uint8x8_t t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, tA; + load_u8_8x11(s, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7, &t8, + &t9, &tA); + int16x8_t s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); + int16x8_t s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); + int16x8_t s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); + int16x8_t s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); + int16x8_t s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); + int16x8_t s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); + int16x8_t s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); + int16x8_t s7 = vreinterpretq_s16_u16(vmovl_u8(t7)); + int16x8_t s8 = vreinterpretq_s16_u16(vmovl_u8(t8)); + int16x8_t s9 = vreinterpretq_s16_u16(vmovl_u8(t9)); + int16x8_t sA = vreinterpretq_s16_u16(vmovl_u8(tA)); + + s += 11 * src_stride; + + do { + uint8x8_t tB, tC, tD, tE; + load_u8_8x4(s, src_stride, &tB, &tC, &tD, &tE); + + int16x8_t sB = vreinterpretq_s16_u16(vmovl_u8(tB)); + int16x8_t sC = vreinterpretq_s16_u16(vmovl_u8(tC)); + int16x8_t sD = vreinterpretq_s16_u16(vmovl_u8(tD)); + int16x8_t sE = vreinterpretq_s16_u16(vmovl_u8(tE)); + + uint8x8_t d0 = convolve12_8(s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, + sB, filter_0_7, filter_8_11); + uint8x8_t d1 = convolve12_8(s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, + sC, filter_0_7, filter_8_11); + uint8x8_t d2 = convolve12_8(s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, + sD, filter_0_7, filter_8_11); + uint8x8_t d3 = convolve12_8(s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, + sE, filter_0_7, filter_8_11); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s0 = s4; + s1 = s5; + s2 = s6; + s3 = s7; + s4 = s8; + s5 = s9; + s6 = sA; + s7 = sB; + s8 = sC; + s9 = sD; + sA = sE; + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); +} + +void vpx_convolve12_neon(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, const InterpKernel12 *filter, + int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + // Scaling not supported by Neon implementation. + if (x_step_q4 != 16 || y_step_q4 != 16) { + vpx_convolve12_c(src, src_stride, dst, dst_stride, filter, x0_q4, x_step_q4, + y0_q4, y_step_q4, w, h); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h == 32 || h == 16 || h == 8); + + DECLARE_ALIGNED(32, uint8_t, im_block[BW * (BH + MAX_FILTER_TAP)]); + + const int im_stride = BW; + // Account for the vertical pass needing MAX_FILTER_TAP / 2 - 1 lines prior + // and MAX_FILTER_TAP / 2 lines post. (+1 to make total divisible by 4.) + const int im_height = h + MAX_FILTER_TAP; + const ptrdiff_t border_offset = MAX_FILTER_TAP / 2 - 1; + + // Filter starting border_offset rows up. + vpx_convolve12_horiz_neon(src - src_stride * border_offset, src_stride, + im_block, im_stride, filter, x0_q4, x_step_q4, + y0_q4, y_step_q4, w, im_height); + + vpx_convolve12_vert_neon(im_block + im_stride * border_offset, im_stride, dst, + dst_stride, filter, x0_q4, x_step_q4, y0_q4, + y_step_q4, w, h); +} diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon_dotprod.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon_dotprod.c new file mode 100644 index 0000000000..1fa2d8732f --- /dev/null +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon_dotprod.c @@ -0,0 +1,367 @@ +/* + * Copyright (c) 2025 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vp9_rtcd.h" +#include "./vpx_config.h" +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/transpose_neon.h" +#include "vp9/encoder/vp9_temporal_filter.h" + +DECLARE_ALIGNED(16, static const uint8_t, kDotProdPermuteTbl[48]) = { + // clang-format off + 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, + 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, + 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14 + // clang-format on +}; + +DECLARE_ALIGNED(16, static const uint8_t, kDotProdMergeBlockTbl[48]) = { + // clang-format off + // Shift left and insert new last column in transposed 4x4 block. + 1, 2, 3, 16, 5, 6, 7, 20, 9, 10, 11, 24, 13, 14, 15, 28, + // Shift left and insert two new columns in transposed 4x4 block. + 2, 3, 16, 17, 6, 7, 20, 21, 10, 11, 24, 25, 14, 15, 28, 29, + // Shift left and insert three new columns in transposed 4x4 block. + 3, 16, 17, 18, 7, 20, 21, 22, 11, 24, 25, 26, 15, 28, 29, 30 + // clang-format on +}; + +static INLINE uint8x8_t convolve12_8_h(uint8x16_t samples[2], + const int8x16_t filter, + const uint8x16x3_t perm_tbl) { + // Transform sample range to [-128, 127] for 8-bit signed dot product. + int8x16_t samples_128[2] = { + vreinterpretq_s8_u8(vsubq_u8(samples[0], vdupq_n_u8(128))), + vreinterpretq_s8_u8(vsubq_u8(samples[1], vdupq_n_u8(128))) + }; + + // Permute samples ready for dot product. + // { 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6 } + // { 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10 } + // { 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14 } + // { 12, 13, 14, 15, 13, 14, 15, 16, 14, 15, 16, 17, 15, 16, 17, 18 } + int8x16_t perm_samples[4] = { vqtbl1q_s8(samples_128[0], perm_tbl.val[0]), + vqtbl1q_s8(samples_128[0], perm_tbl.val[1]), + vqtbl1q_s8(samples_128[0], perm_tbl.val[2]), + vqtbl1q_s8(samples_128[1], perm_tbl.val[2]) }; + + // Accumulate into 128 << FILTER_BITS to account for range transform. + int32x4_t acc = vdupq_n_s32(128 << FILTER_BITS); + + int32x4_t sum0123 = vdotq_laneq_s32(acc, perm_samples[0], filter, 0); + sum0123 = vdotq_laneq_s32(sum0123, perm_samples[1], filter, 1); + sum0123 = vdotq_laneq_s32(sum0123, perm_samples[2], filter, 2); + + int32x4_t sum4567 = vdotq_laneq_s32(acc, perm_samples[1], filter, 0); + sum4567 = vdotq_laneq_s32(sum4567, perm_samples[2], filter, 1); + sum4567 = vdotq_laneq_s32(sum4567, perm_samples[3], filter, 2); + + // Narrow and re-pack. + int16x8_t sum_s16 = vcombine_s16(vqrshrn_n_s32(sum0123, FILTER_BITS), + vqrshrn_n_s32(sum4567, FILTER_BITS)); + return vqmovun_s16(sum_s16); +} + +void vpx_convolve12_horiz_neon_dotprod(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + // Scaling not supported by Neon implementation. + if (x_step_q4 != 16) { + vpx_convolve12_horiz_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h == 32 || h == 16 || h == 8); + + const int16x8_t x_filter_0_7 = vld1q_s16(filter[x0_q4]); + const int16x4_t x_filter_8_11 = vld1_s16(filter[x0_q4] + 8); + const int16x8_t x_filter_8_15 = vcombine_s16(x_filter_8_11, vdup_n_s16(0)); + const int8x16_t x_filter = + vcombine_s8(vmovn_s16(x_filter_0_7), vmovn_s16(x_filter_8_15)); + + const uint8x16x3_t permute_tbl = vld1q_u8_x3(kDotProdPermuteTbl); + + src -= MAX_FILTER_TAP / 2 - 1; + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0[2], s1[2], s2[2], s3[2]; + load_u8_16x4(s, src_stride, &s0[0], &s1[0], &s2[0], &s3[0]); + load_u8_16x4(s + 4, src_stride, &s0[1], &s1[1], &s2[1], &s3[1]); + + uint8x8_t d0 = convolve12_8_h(s0, x_filter, permute_tbl); + uint8x8_t d1 = convolve12_8_h(s1, x_filter, permute_tbl); + uint8x8_t d2 = convolve12_8_h(s2, x_filter, permute_tbl); + uint8x8_t d3 = convolve12_8_h(s3, x_filter, permute_tbl); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); +} + +static INLINE uint8x8_t convolve12_8_v( + const int8x16_t s0_lo, const int8x16_t s0_hi, const int8x16_t s1_lo, + const int8x16_t s1_hi, const int8x16_t s2_lo, const int8x16_t s2_hi, + const int8x8_t filters_0_7, const int8x8_t filters_4_11) { + // The sample range transform and permutation are performed by the caller. + // Accumulate into 128 << FILTER_BITS to account for range transform. + int32x4_t acc = vdupq_n_s32(128 << FILTER_BITS); + + int32x4_t sum0123 = vdotq_lane_s32(acc, s0_lo, filters_0_7, 0); + sum0123 = vdotq_lane_s32(sum0123, s1_lo, filters_0_7, 1); + sum0123 = vdotq_lane_s32(sum0123, s2_lo, filters_4_11, 1); + + int32x4_t sum4567 = vdotq_lane_s32(acc, s0_hi, filters_0_7, 0); + sum4567 = vdotq_lane_s32(sum4567, s1_hi, filters_0_7, 1); + sum4567 = vdotq_lane_s32(sum4567, s2_hi, filters_4_11, 1); + + // Narrow and re-pack. + int16x8_t sum = vcombine_s16(vqmovn_s32(sum0123), vqmovn_s32(sum4567)); + return vqrshrun_n_s16(sum, FILTER_BITS); +} + +void vpx_convolve12_vert_neon_dotprod(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + // Scaling not supported by Neon implementation. + if (y_step_q4 != 16) { + vpx_convolve12_vert_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h == 32 || h == 16 || h == 8); + + const int8x8_t filter_0_7 = vmovn_s16(vld1q_s16(filter[y0_q4])); + const int8x8_t filter_4_11 = vmovn_s16(vld1q_s16(filter[y0_q4] + 4)); + + const uint8x16x3_t merge_block_tbl = vld1q_u8_x3(kDotProdMergeBlockTbl); + + src -= src_stride * (MAX_FILTER_TAP / 2 - 1); + + do { + int height = h; + const uint8_t *s = src; + uint8_t *d = dst; + + uint8x8_t t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, tA; + load_u8_8x11(s, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7, &t8, + &t9, &tA); + s += 11 * src_stride; + + // Transform sample range to [-128, 127] for 8-bit signed dot product. + int8x8_t s0 = vreinterpret_s8_u8(vsub_u8(t0, vdup_n_u8(128))); + int8x8_t s1 = vreinterpret_s8_u8(vsub_u8(t1, vdup_n_u8(128))); + int8x8_t s2 = vreinterpret_s8_u8(vsub_u8(t2, vdup_n_u8(128))); + int8x8_t s3 = vreinterpret_s8_u8(vsub_u8(t3, vdup_n_u8(128))); + int8x8_t s4 = vreinterpret_s8_u8(vsub_u8(t4, vdup_n_u8(128))); + int8x8_t s5 = vreinterpret_s8_u8(vsub_u8(t5, vdup_n_u8(128))); + int8x8_t s6 = vreinterpret_s8_u8(vsub_u8(t6, vdup_n_u8(128))); + int8x8_t s7 = vreinterpret_s8_u8(vsub_u8(t7, vdup_n_u8(128))); + int8x8_t s8 = vreinterpret_s8_u8(vsub_u8(t8, vdup_n_u8(128))); + int8x8_t s9 = vreinterpret_s8_u8(vsub_u8(t9, vdup_n_u8(128))); + int8x8_t sA = vreinterpret_s8_u8(vsub_u8(tA, vdup_n_u8(128))); + + // This operation combines a conventional transpose and the sample permute + // (see horizontal case) required before computing the dot product. + int8x16_t s0123_lo, s0123_hi, s1234_lo, s1234_hi, s2345_lo, s2345_hi, + s3456_lo, s3456_hi, s4567_lo, s4567_hi, s5678_lo, s5678_hi, s6789_lo, + s6789_hi, s789A_lo, s789A_hi; + transpose_concat_s8_8x4(s0, s1, s2, s3, &s0123_lo, &s0123_hi); + transpose_concat_s8_8x4(s1, s2, s3, s4, &s1234_lo, &s1234_hi); + transpose_concat_s8_8x4(s2, s3, s4, s5, &s2345_lo, &s2345_hi); + transpose_concat_s8_8x4(s3, s4, s5, s6, &s3456_lo, &s3456_hi); + transpose_concat_s8_8x4(s4, s5, s6, s7, &s4567_lo, &s4567_hi); + transpose_concat_s8_8x4(s5, s6, s7, s8, &s5678_lo, &s5678_hi); + transpose_concat_s8_8x4(s6, s7, s8, s9, &s6789_lo, &s6789_hi); + transpose_concat_s8_8x4(s7, s8, s9, sA, &s789A_lo, &s789A_hi); + + do { + uint8x8_t tB, tC, tD, tE; + load_u8_8x4(s, src_stride, &tB, &tC, &tD, &tE); + + int8x8_t sB = vreinterpret_s8_u8(vsub_u8(tB, vdup_n_u8(128))); + int8x8_t sC = vreinterpret_s8_u8(vsub_u8(tC, vdup_n_u8(128))); + int8x8_t sD = vreinterpret_s8_u8(vsub_u8(tD, vdup_n_u8(128))); + int8x8_t sE = vreinterpret_s8_u8(vsub_u8(tE, vdup_n_u8(128))); + + int8x16_t s89AB_lo, s89AB_hi, s9ABC_lo, s9ABC_hi, sABCD_lo, sABCD_hi, + sBCDE_lo, sBCDE_hi; + transpose_concat_s8_8x4(sB, sC, sD, sE, &sBCDE_lo, &sBCDE_hi); + + // Merge new data into block from previous iteration. + int8x16x2_t samples_LUT_lo = { { s789A_lo, sBCDE_lo } }; + s89AB_lo = vqtbl2q_s8(samples_LUT_lo, merge_block_tbl.val[0]); + s9ABC_lo = vqtbl2q_s8(samples_LUT_lo, merge_block_tbl.val[1]); + sABCD_lo = vqtbl2q_s8(samples_LUT_lo, merge_block_tbl.val[2]); + + int8x16x2_t samples_LUT_hi = { { s789A_hi, sBCDE_hi } }; + s89AB_hi = vqtbl2q_s8(samples_LUT_hi, merge_block_tbl.val[0]); + s9ABC_hi = vqtbl2q_s8(samples_LUT_hi, merge_block_tbl.val[1]); + sABCD_hi = vqtbl2q_s8(samples_LUT_hi, merge_block_tbl.val[2]); + + uint8x8_t d0 = + convolve12_8_v(s0123_lo, s0123_hi, s4567_lo, s4567_hi, s89AB_lo, + s89AB_hi, filter_0_7, filter_4_11); + uint8x8_t d1 = + convolve12_8_v(s1234_lo, s1234_hi, s5678_lo, s5678_hi, s9ABC_lo, + s9ABC_hi, filter_0_7, filter_4_11); + uint8x8_t d2 = + convolve12_8_v(s2345_lo, s2345_hi, s6789_lo, s6789_hi, sABCD_lo, + sABCD_hi, filter_0_7, filter_4_11); + uint8x8_t d3 = + convolve12_8_v(s3456_lo, s3456_hi, s789A_lo, s789A_hi, sBCDE_lo, + sBCDE_hi, filter_0_7, filter_4_11); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + // Prepare block for next iteration - re-using as much as possible. + // Shuffle everything up four rows. + s0123_lo = s4567_lo; + s0123_hi = s4567_hi; + s1234_lo = s5678_lo; + s1234_hi = s5678_hi; + s2345_lo = s6789_lo; + s2345_hi = s6789_hi; + s3456_lo = s789A_lo; + s3456_hi = s789A_hi; + s4567_lo = s89AB_lo; + s4567_hi = s89AB_hi; + s5678_lo = s9ABC_lo; + s5678_hi = s9ABC_hi; + s6789_lo = sABCD_lo; + s6789_hi = sABCD_hi; + s789A_lo = sBCDE_lo; + s789A_hi = sBCDE_hi; + + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); +} + +static INLINE void vpx_convolve12_2d_horiz_neon_dotprod( + const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int w, + int h) { + assert(w == 32 || w == 16 || w == 8); + assert(h % 4 == 3); + + const int16x8_t x_filter_0_7 = vld1q_s16(filter[x0_q4]); + const int16x4_t x_filter_8_11 = vld1_s16(filter[x0_q4] + 8); + const int16x8_t x_filter_8_15 = vcombine_s16(x_filter_8_11, vdup_n_s16(0)); + const int8x16_t x_filter = + vcombine_s8(vmovn_s16(x_filter_0_7), vmovn_s16(x_filter_8_15)); + + const uint8x16x3_t permute_tbl = vld1q_u8_x3(kDotProdPermuteTbl); + + src -= MAX_FILTER_TAP / 2 - 1; + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0[2], s1[2], s2[2], s3[2]; + load_u8_16x4(s, src_stride, &s0[0], &s1[0], &s2[0], &s3[0]); + load_u8_16x4(s + 4, src_stride, &s0[1], &s1[1], &s2[1], &s3[1]); + + uint8x8_t d0 = convolve12_8_h(s0, x_filter, permute_tbl); + uint8x8_t d1 = convolve12_8_h(s1, x_filter, permute_tbl); + uint8x8_t d2 = convolve12_8_h(s2, x_filter, permute_tbl); + uint8x8_t d3 = convolve12_8_h(s3, x_filter, permute_tbl); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 3); + + do { + uint8x16_t s0[2], s1[2], s2[2]; + load_u8_16x3(src, src_stride, &s0[0], &s1[0], &s2[0]); + load_u8_16x3(src + 4, src_stride, &s0[1], &s1[1], &s2[1]); + + uint8x8_t d0 = convolve12_8_h(s0, x_filter, permute_tbl); + uint8x8_t d1 = convolve12_8_h(s1, x_filter, permute_tbl); + uint8x8_t d2 = convolve12_8_h(s2, x_filter, permute_tbl); + + store_u8_8x3(dst, dst_stride, d0, d1, d2); + + src += 8; + dst += 8; + w -= 8; + } while (w != 0); +} + +void vpx_convolve12_neon_dotprod(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + // Scaling not supported by Neon implementation. + if (x_step_q4 != 16 || y_step_q4 != 16) { + vpx_convolve12_c(src, src_stride, dst, dst_stride, filter, x0_q4, x_step_q4, + y0_q4, y_step_q4, w, h); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h == 32 || h == 16 || h == 8); + + DECLARE_ALIGNED(32, uint8_t, im_block[BW * (BH + MAX_FILTER_TAP)]); + + const int im_stride = BW; + // Account for the vertical pass needing MAX_FILTER_TAP / 2 - 1 lines prior + // and MAX_FILTER_TAP / 2 lines post. + const int im_height = h + MAX_FILTER_TAP - 1; + const ptrdiff_t border_offset = MAX_FILTER_TAP / 2 - 1; + + // Filter starting border_offset rows up. + vpx_convolve12_2d_horiz_neon_dotprod(src - src_stride * border_offset, + src_stride, im_block, im_stride, filter, + x0_q4, w, im_height); + + vpx_convolve12_vert_neon_dotprod(im_block + im_stride * border_offset, + im_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h); +} diff --git a/libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon_i8mm.c b/libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon_i8mm.c new file mode 100644 index 0000000000..3803873a44 --- /dev/null +++ b/libs/libvpx/vp9/encoder/arm/neon/vp9_temporal_filter_neon_i8mm.c @@ -0,0 +1,351 @@ +/* + * Copyright (c) 2025 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vp9_rtcd.h" +#include "./vpx_config.h" +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/transpose_neon.h" +#include "vp9/encoder/vp9_temporal_filter.h" + +DECLARE_ALIGNED(16, static const uint8_t, kMatMulPermuteTbl[32]) = { + // clang-format off + 0, 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 8, 9, + 4, 5, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11, 12, 13 + // clang-format on +}; + +DECLARE_ALIGNED(16, static const uint8_t, kDotProdMergeBlockTbl[48]) = { + // clang-format off + // Shift left and insert new last column in transposed 4x4 block. + 1, 2, 3, 16, 5, 6, 7, 20, 9, 10, 11, 24, 13, 14, 15, 28, + // Shift left and insert two new columns in transposed 4x4 block. + 2, 3, 16, 17, 6, 7, 20, 21, 10, 11, 24, 25, 14, 15, 28, 29, + // Shift left and insert three new columns in transposed 4x4 block. + 3, 16, 17, 18, 7, 20, 21, 22, 11, 24, 25, 26, 15, 28, 29, 30 + // clang-format on +}; + +static INLINE uint8x8_t convolve12_8_h(uint8x16_t samples[2], + const int8x16_t filter[2], + const uint8x16x2_t perm_tbl) { + // Permute samples ready for matrix multiply. + // { 0, 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 8, 9 } + // { 4, 5, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11, 12, 13 } + // { 6, 7, 8, 9, 10, 11, 12, 13, 8, 9, 10, 11, 12, 13, 14, 15 } + // { 10, 11, 12, 13, 14, 15, 16, 17, 12, 13, 14, 15, 16, 17, 18, 19 } + uint8x16_t perm_samples[4] = { vqtbl1q_u8(samples[0], perm_tbl.val[0]), + vqtbl1q_u8(samples[0], perm_tbl.val[1]), + vqtbl1q_u8(samples[1], perm_tbl.val[0]), + vqtbl1q_u8(samples[1], perm_tbl.val[1]) }; + + // These instructions multiply a 2x8 matrix (samples) by an 8x2 matrix + // (filter), destructively accumulating into the destination register. + int32x4_t sum0123 = vusmmlaq_s32(vdupq_n_s32(0), perm_samples[0], filter[0]); + int32x4_t sum4567 = vusmmlaq_s32(vdupq_n_s32(0), perm_samples[1], filter[0]); + sum0123 = vusmmlaq_s32(sum0123, perm_samples[2], filter[1]); + sum4567 = vusmmlaq_s32(sum4567, perm_samples[3], filter[1]); + + // Narrow and re-pack. + int16x8_t sum_s16 = vcombine_s16(vqrshrn_n_s32(sum0123, FILTER_BITS), + vqrshrn_n_s32(sum4567, FILTER_BITS)); + return vqmovun_s16(sum_s16); +} + +void vpx_convolve12_horiz_neon_i8mm(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + // Scaling not supported by Neon implementation. + if (x_step_q4 != 16) { + vpx_convolve12_horiz_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h == 32 || h == 16 || h == 8); + + // Split 12-tap filter into two 6-tap filters, masking the top two elements. + // { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0 } + const int8x8_t mask = vcreate_s8(0x0000ffffffffffff); + const int8x8_t filter_0 = vand_s8(vmovn_s16(vld1q_s16(filter[x0_q4])), mask); + const int8x8_t filter_1 = + vext_s8(vmovn_s16(vld1q_s16(filter[x0_q4] + 4)), vdup_n_s8(0), 2); + + // Stagger each 6-tap filter to enable use of matrix multiply instructions. + // { f0, f1, f2, f3, f4, f5, 0, 0, 0, f0, f1, f2, f3, f4, f5, 0 } + const int8x16_t x_filter[2] = { + vcombine_s8(filter_0, vext_s8(filter_0, filter_0, 7)), + vcombine_s8(filter_1, vext_s8(filter_1, filter_1, 7)) + }; + + const uint8x16x2_t permute_tbl = vld1q_u8_x2(kMatMulPermuteTbl); + + src -= MAX_FILTER_TAP / 2 - 1; + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0[2], s1[2], s2[2], s3[2]; + load_u8_16x4(s, src_stride, &s0[0], &s1[0], &s2[0], &s3[0]); + load_u8_16x4(s + 6, src_stride, &s0[1], &s1[1], &s2[1], &s3[1]); + + uint8x8_t d0 = convolve12_8_h(s0, x_filter, permute_tbl); + uint8x8_t d1 = convolve12_8_h(s1, x_filter, permute_tbl); + uint8x8_t d2 = convolve12_8_h(s2, x_filter, permute_tbl); + uint8x8_t d3 = convolve12_8_h(s3, x_filter, permute_tbl); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); +} + +static INLINE uint8x8_t convolve12_8_v( + const uint8x16_t s0_lo, const uint8x16_t s0_hi, const uint8x16_t s1_lo, + const uint8x16_t s1_hi, const uint8x16_t s2_lo, const uint8x16_t s2_hi, + const int8x8_t filters_0_7, const int8x8_t filters_4_11) { + // The sample range transform and permutation are performed by the caller. + int32x4_t sum0123 = vusdotq_lane_s32(vdupq_n_s32(0), s0_lo, filters_0_7, 0); + sum0123 = vusdotq_lane_s32(sum0123, s1_lo, filters_0_7, 1); + sum0123 = vusdotq_lane_s32(sum0123, s2_lo, filters_4_11, 1); + + int32x4_t sum4567 = vusdotq_lane_s32(vdupq_n_s32(0), s0_hi, filters_0_7, 0); + sum4567 = vusdotq_lane_s32(sum4567, s1_hi, filters_0_7, 1); + sum4567 = vusdotq_lane_s32(sum4567, s2_hi, filters_4_11, 1); + + // Narrow and re-pack. + int16x8_t sum = vcombine_s16(vqmovn_s32(sum0123), vqmovn_s32(sum4567)); + return vqrshrun_n_s16(sum, FILTER_BITS); +} + +void vpx_convolve12_vert_neon_i8mm(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + // Scaling not supported by Neon implementation. + if (y_step_q4 != 16) { + vpx_convolve12_vert_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h == 32 || h == 16 || h == 8); + + const int8x8_t filter_0_7 = vmovn_s16(vld1q_s16(filter[y0_q4])); + const int8x8_t filter_4_11 = vmovn_s16(vld1q_s16(filter[y0_q4] + 4)); + + const uint8x16x3_t merge_block_tbl = vld1q_u8_x3(kDotProdMergeBlockTbl); + + src -= src_stride * (MAX_FILTER_TAP / 2 - 1); + + do { + int height = h; + const uint8_t *s = src; + uint8_t *d = dst; + + uint8x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA; + load_u8_8x11(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7, &s8, + &s9, &sA); + s += 11 * src_stride; + + // This operation combines a conventional transpose and the sample permute + // (see horizontal case) required before computing the dot product. + uint8x16_t s0123_lo, s0123_hi, s1234_lo, s1234_hi, s2345_lo, s2345_hi, + s3456_lo, s3456_hi, s4567_lo, s4567_hi, s5678_lo, s5678_hi, s6789_lo, + s6789_hi, s789A_lo, s789A_hi; + transpose_concat_u8_8x4(s0, s1, s2, s3, &s0123_lo, &s0123_hi); + transpose_concat_u8_8x4(s1, s2, s3, s4, &s1234_lo, &s1234_hi); + transpose_concat_u8_8x4(s2, s3, s4, s5, &s2345_lo, &s2345_hi); + transpose_concat_u8_8x4(s3, s4, s5, s6, &s3456_lo, &s3456_hi); + transpose_concat_u8_8x4(s4, s5, s6, s7, &s4567_lo, &s4567_hi); + transpose_concat_u8_8x4(s5, s6, s7, s8, &s5678_lo, &s5678_hi); + transpose_concat_u8_8x4(s6, s7, s8, s9, &s6789_lo, &s6789_hi); + transpose_concat_u8_8x4(s7, s8, s9, sA, &s789A_lo, &s789A_hi); + + do { + uint8x8_t sB, sC, sD, sE; + load_u8_8x4(s, src_stride, &sB, &sC, &sD, &sE); + + uint8x16_t s89AB_lo, s89AB_hi, s9ABC_lo, s9ABC_hi, sABCD_lo, sABCD_hi, + sBCDE_lo, sBCDE_hi; + transpose_concat_u8_8x4(sB, sC, sD, sE, &sBCDE_lo, &sBCDE_hi); + + // Merge new data into block from previous iteration. + uint8x16x2_t samples_LUT_lo = { { s789A_lo, sBCDE_lo } }; + s89AB_lo = vqtbl2q_u8(samples_LUT_lo, merge_block_tbl.val[0]); + s9ABC_lo = vqtbl2q_u8(samples_LUT_lo, merge_block_tbl.val[1]); + sABCD_lo = vqtbl2q_u8(samples_LUT_lo, merge_block_tbl.val[2]); + + uint8x16x2_t samples_LUT_hi = { { s789A_hi, sBCDE_hi } }; + s89AB_hi = vqtbl2q_u8(samples_LUT_hi, merge_block_tbl.val[0]); + s9ABC_hi = vqtbl2q_u8(samples_LUT_hi, merge_block_tbl.val[1]); + sABCD_hi = vqtbl2q_u8(samples_LUT_hi, merge_block_tbl.val[2]); + + uint8x8_t d0 = + convolve12_8_v(s0123_lo, s0123_hi, s4567_lo, s4567_hi, s89AB_lo, + s89AB_hi, filter_0_7, filter_4_11); + uint8x8_t d1 = + convolve12_8_v(s1234_lo, s1234_hi, s5678_lo, s5678_hi, s9ABC_lo, + s9ABC_hi, filter_0_7, filter_4_11); + uint8x8_t d2 = + convolve12_8_v(s2345_lo, s2345_hi, s6789_lo, s6789_hi, sABCD_lo, + sABCD_hi, filter_0_7, filter_4_11); + uint8x8_t d3 = + convolve12_8_v(s3456_lo, s3456_hi, s789A_lo, s789A_hi, sBCDE_lo, + sBCDE_hi, filter_0_7, filter_4_11); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + // Prepare block for next iteration - re-using as much as possible. + // Shuffle everything up four rows. + s0123_lo = s4567_lo; + s0123_hi = s4567_hi; + s1234_lo = s5678_lo; + s1234_hi = s5678_hi; + s2345_lo = s6789_lo; + s2345_hi = s6789_hi; + s3456_lo = s789A_lo; + s3456_hi = s789A_hi; + s4567_lo = s89AB_lo; + s4567_hi = s89AB_hi; + s5678_lo = s9ABC_lo; + s5678_hi = s9ABC_hi; + s6789_lo = sABCD_lo; + s6789_hi = sABCD_hi; + s789A_lo = sBCDE_lo; + s789A_hi = sBCDE_hi; + + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); +} + +static INLINE void vpx_convolve12_2d_horiz_neon_i8mm( + const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int w, + int h) { + assert(w == 32 || w == 16 || w == 8); + assert(h % 4 == 3); + + // Split 12-tap filter into two 6-tap filters, masking the top two elements. + // { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0 } + const int8x8_t mask = vcreate_s8(0x0000ffffffffffff); + const int8x8_t filter_0 = vand_s8(vmovn_s16(vld1q_s16(filter[x0_q4])), mask); + const int8x8_t filter_1 = + vext_s8(vmovn_s16(vld1q_s16(filter[x0_q4] + 4)), vdup_n_s8(0), 2); + + // Stagger each 6-tap filter to enable use of matrix multiply instructions. + // { f0, f1, f2, f3, f4, f5, 0, 0, 0, f0, f1, f2, f3, f4, f5, 0 } + const int8x16_t x_filter[2] = { + vcombine_s8(filter_0, vext_s8(filter_0, filter_0, 7)), + vcombine_s8(filter_1, vext_s8(filter_1, filter_1, 7)) + }; + + const uint8x16x2_t permute_tbl = vld1q_u8_x2(kMatMulPermuteTbl); + + src -= MAX_FILTER_TAP / 2 - 1; + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0[2], s1[2], s2[2], s3[2]; + load_u8_16x4(s, src_stride, &s0[0], &s1[0], &s2[0], &s3[0]); + load_u8_16x4(s + 6, src_stride, &s0[1], &s1[1], &s2[1], &s3[1]); + + uint8x8_t d0 = convolve12_8_h(s0, x_filter, permute_tbl); + uint8x8_t d1 = convolve12_8_h(s1, x_filter, permute_tbl); + uint8x8_t d2 = convolve12_8_h(s2, x_filter, permute_tbl); + uint8x8_t d3 = convolve12_8_h(s3, x_filter, permute_tbl); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 3); + + do { + uint8x16_t s0[2], s1[2], s2[2]; + load_u8_16x3(src, src_stride, &s0[0], &s1[0], &s2[0]); + load_u8_16x3(src + 6, src_stride, &s0[1], &s1[1], &s2[1]); + + uint8x8_t d0 = convolve12_8_h(s0, x_filter, permute_tbl); + uint8x8_t d1 = convolve12_8_h(s1, x_filter, permute_tbl); + uint8x8_t d2 = convolve12_8_h(s2, x_filter, permute_tbl); + + store_u8_8x3(dst, dst_stride, d0, d1, d2); + + src += 8; + dst += 8; + w -= 8; + } while (w != 0); +} + +void vpx_convolve12_neon_i8mm(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + // Scaling not supported by Neon implementation. + if (x_step_q4 != 16 || y_step_q4 != 16) { + vpx_convolve12_c(src, src_stride, dst, dst_stride, filter, x0_q4, x_step_q4, + y0_q4, y_step_q4, w, h); + return; + } + + assert(w == 32 || w == 16 || w == 8); + assert(h == 32 || h == 16 || h == 8); + + DECLARE_ALIGNED(32, uint8_t, im_block[BW * (BH + MAX_FILTER_TAP)]); + + const int im_stride = BW; + // Account for the vertical pass needing MAX_FILTER_TAP / 2 - 1 lines prior + // and MAX_FILTER_TAP / 2 lines post. + const int im_height = h + MAX_FILTER_TAP - 1; + const ptrdiff_t border_offset = MAX_FILTER_TAP / 2 - 1; + + // Filter starting border_offset rows up. + vpx_convolve12_2d_horiz_neon_i8mm(src - src_stride * border_offset, + src_stride, im_block, im_stride, filter, + x0_q4, w, im_height); + + vpx_convolve12_vert_neon_i8mm(im_block + im_stride * border_offset, im_stride, + dst, dst_stride, filter, x0_q4, x_step_q4, + y0_q4, y_step_q4, w, h); +} diff --git a/libs/libvpx/vp9/encoder/vp9_aq_complexity.c b/libs/libvpx/vp9/encoder/vp9_aq_complexity.c index bd3812036c..ca14f442df 100644 --- a/libs/libvpx/vp9/encoder/vp9_aq_complexity.c +++ b/libs/libvpx/vp9/encoder/vp9_aq_complexity.c @@ -87,7 +87,7 @@ void vp9_setup_in_frame_q_adj(VP9_COMP *cpi) { &cpi->rc, cm->frame_type, cm->base_qindex, aq_c_q_adj_factor[aq_strength][segment], cm->bit_depth); - // For AQ complexity mode, we dont allow Q0 in a segment if the base + // For AQ complexity mode, we don't allow Q0 in a segment if the base // Q is not 0. Q0 (lossless) implies 4x4 only and in AQ mode 2 a segment // Q delta is sometimes applied without going back around the rd loop. // This could lead to an illegal combination of partition size and q. @@ -125,8 +125,11 @@ void vp9_caq_select_segment(VP9_COMP *cpi, MACROBLOCK *mb, BLOCK_SIZE bs, } else { // Rate depends on fraction of a SB64 in frame (xmis * ymis / bw * bh). // It is converted to bits * 256 units. + cpi->rc.sb64_target_rate = VPXMIN(INT_MAX / 256, cpi->rc.sb64_target_rate); + const int target_rate = - (cpi->rc.sb64_target_rate * xmis * ymis * 256) / (bw * bh); + (int)(((int64_t)cpi->rc.sb64_target_rate * xmis * ymis * 256) / + (bw * bh)); double logvar; double low_var_thresh; const int aq_strength = get_aq_c_strength(cm->base_qindex, cm->bit_depth); diff --git a/libs/libvpx/vp9/encoder/vp9_aq_cyclicrefresh.c b/libs/libvpx/vp9/encoder/vp9_aq_cyclicrefresh.c index e336179e90..92a31ebf63 100644 --- a/libs/libvpx/vp9/encoder/vp9_aq_cyclicrefresh.c +++ b/libs/libvpx/vp9/encoder/vp9_aq_cyclicrefresh.c @@ -114,18 +114,18 @@ int vp9_cyclic_refresh_estimate_bits_at_q(const VP9_COMP *cpi, double weight_segment1 = (double)cr->actual_num_seg1_blocks / num8x8bl; double weight_segment2 = (double)cr->actual_num_seg2_blocks / num8x8bl; // Take segment weighted average for estimated bits. - estimated_bits = - (int)((1.0 - weight_segment1 - weight_segment2) * - vp9_estimate_bits_at_q(cm->frame_type, cm->base_qindex, mbs, - correction_factor, cm->bit_depth) + - weight_segment1 * - vp9_estimate_bits_at_q(cm->frame_type, - cm->base_qindex + cr->qindex_delta[1], - mbs, correction_factor, cm->bit_depth) + - weight_segment2 * - vp9_estimate_bits_at_q(cm->frame_type, - cm->base_qindex + cr->qindex_delta[2], - mbs, correction_factor, cm->bit_depth)); + estimated_bits = (int)round( + (1.0 - weight_segment1 - weight_segment2) * + vp9_estimate_bits_at_q(cm->frame_type, cm->base_qindex, mbs, + correction_factor, cm->bit_depth) + + weight_segment1 * + vp9_estimate_bits_at_q(cm->frame_type, + cm->base_qindex + cr->qindex_delta[1], mbs, + correction_factor, cm->bit_depth) + + weight_segment2 * + vp9_estimate_bits_at_q(cm->frame_type, + cm->base_qindex + cr->qindex_delta[2], mbs, + correction_factor, cm->bit_depth)); return estimated_bits; } @@ -145,12 +145,13 @@ int vp9_cyclic_refresh_rc_bits_per_mb(const VP9_COMP *cpi, int i, else deltaq = -(cr->max_qdelta_perc * i) / 200; // Take segment weighted average for bits per mb. - bits_per_mb = (int)((1.0 - cr->weight_segment) * - vp9_rc_bits_per_mb(cm->frame_type, i, - correction_factor, cm->bit_depth) + - cr->weight_segment * - vp9_rc_bits_per_mb(cm->frame_type, i + deltaq, - correction_factor, cm->bit_depth)); + bits_per_mb = + (int)round((1.0 - cr->weight_segment) * + vp9_rc_bits_per_mb(cm->frame_type, i, correction_factor, + cm->bit_depth) + + cr->weight_segment * + vp9_rc_bits_per_mb(cm->frame_type, i + deltaq, + correction_factor, cm->bit_depth)); return bits_per_mb; } @@ -471,7 +472,7 @@ static void cyclic_refresh_update_map(VP9_COMP *const cpi) { cr->sb_index = i; cr->reduce_refresh = 0; if (cpi->oxcf.content != VP9E_CONTENT_SCREEN) - if (count_sel<(3 * count_tot)>> 2) cr->reduce_refresh = 1; + if (count_sel < (3 * count_tot) >> 2) cr->reduce_refresh = 1; } // Set cyclic refresh parameters. @@ -558,7 +559,7 @@ void vp9_cyclic_refresh_update_parameters(VP9_COMP *const cpi) { cr->percent_refresh = 10; cr->rate_ratio_qdelta = 1.5; cr->rate_boost_fac = 10; - if (cpi->refresh_golden_frame == 1) { + if (cpi->refresh_golden_frame == 1 && !cpi->use_svc) { cr->percent_refresh = 0; cr->rate_ratio_qdelta = 1.0; } @@ -602,14 +603,16 @@ void vp9_cyclic_refresh_setup(VP9_COMP *const cpi) { (cpi->use_svc && cpi->svc.high_source_sad_superframe); if (cm->current_video_frame == 0) cr->low_content_avg = 0.0; // Reset if resoluton change has occurred. - if (cpi->resize_pending != 0) vp9_cyclic_refresh_reset_resize(cpi); + if (cpi->resize_pending != 0 && cpi->svc.temporal_layer_id == 0) + vp9_cyclic_refresh_reset_resize(cpi); if (!cr->apply_cyclic_refresh || (cpi->force_update_segmentation) || scene_change_detected) { // Set segmentation map to 0 and disable. unsigned char *const seg_map = cpi->segmentation_map; memset(seg_map, 0, cm->mi_rows * cm->mi_cols); vp9_disable_segmentation(&cm->seg); - if (cm->frame_type == KEY_FRAME || scene_change_detected) { + if ((cm->frame_type == KEY_FRAME || scene_change_detected) && + cpi->svc.temporal_layer_id == 0) { memset(cr->last_coded_q_map, MAXQ, cm->mi_rows * cm->mi_cols * sizeof(*cr->last_coded_q_map)); cr->sb_index = 0; diff --git a/libs/libvpx/vp9/encoder/vp9_aq_variance.c b/libs/libvpx/vp9/encoder/vp9_aq_variance.c index 9e5f3bfb28..2d57615259 100644 --- a/libs/libvpx/vp9/encoder/vp9_aq_variance.c +++ b/libs/libvpx/vp9/encoder/vp9_aq_variance.c @@ -32,7 +32,7 @@ static const double rate_ratio[MAX_SEGMENTS] = { 2.5, 2.0, 1.5, 1.0, 0.75, 1.0, 1.0, 1.0 }; static const int segment_id[ENERGY_SPAN] = { 0, 1, 1, 2, 3, 4 }; -#define SEGMENT_ID(i) segment_id[(i)-ENERGY_MIN] +#define SEGMENT_ID(i) segment_id[(i) - ENERGY_MIN] DECLARE_ALIGNED(16, static const uint8_t, vp9_64_zeros[64]) = { 0 }; #if CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vp9/encoder/vp9_bitstream.c b/libs/libvpx/vp9/encoder/vp9_bitstream.c index 75bd097f24..6163a57672 100644 --- a/libs/libvpx/vp9/encoder/vp9_bitstream.c +++ b/libs/libvpx/vp9/encoder/vp9_bitstream.c @@ -9,6 +9,7 @@ */ #include +#include #include #include @@ -55,6 +56,7 @@ static const struct vp9_token inter_mode_encodings[INTER_MODES] = { static void write_intra_mode(vpx_writer *w, PREDICTION_MODE mode, const vpx_prob *probs) { + assert(!is_inter_mode(mode)); vp9_write_token(w, vp9_intra_mode_tree, probs, &intra_mode_encodings[mode]); } @@ -134,9 +136,9 @@ static void pack_mb_tokens(vpx_writer *w, TOKENEXTRA **tp, const TOKENEXTRA *p; const vp9_extra_bit *const extra_bits = #if CONFIG_VP9_HIGHBITDEPTH - (bit_depth == VPX_BITS_12) - ? vp9_extra_bits_high12 - : (bit_depth == VPX_BITS_10) ? vp9_extra_bits_high10 : vp9_extra_bits; + (bit_depth == VPX_BITS_12) ? vp9_extra_bits_high12 + : (bit_depth == VPX_BITS_10) ? vp9_extra_bits_high10 + : vp9_extra_bits; #else vp9_extra_bits; (void)bit_depth; @@ -169,8 +171,8 @@ static void pack_mb_tokens(vpx_writer *w, TOKENEXTRA **tp, vpx_write_bit(w, p->extra & 1); } else { // t >= TWO_TOKEN && t < EOB_TOKEN const struct vp9_token *const a = &vp9_coef_encodings[t]; - const int v = a->value; - const int n = a->len; + int v = a->value; + int n = a->len; const int e = p->extra; vpx_write(w, 1, context_tree[2]); vp9_write_tree(w, vp9_coef_con_tree, @@ -179,8 +181,8 @@ static void pack_mb_tokens(vpx_writer *w, TOKENEXTRA **tp, if (t >= CATEGORY1_TOKEN) { const vp9_extra_bit *const b = &extra_bits[t]; const unsigned char *pb = b->prob; - int v = e >> 1; - int n = b->len; // number of bits in v, assumed nonzero + v = e >> 1; + n = b->len; // number of bits in v, assumed nonzero do { const int bb = (v >> --n) & 1; vpx_write(w, bb, *pb++); @@ -518,7 +520,7 @@ static void build_tree_distribution(VP9_COMP *cpi, TX_SIZE tx_size, vp9_coeff_stats *coef_branch_ct, vp9_coeff_probs_model *coef_probs) { vp9_coeff_count *coef_counts = cpi->td.rd_counts.coef_counts[tx_size]; - unsigned int(*eob_branch_ct)[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] = + unsigned int (*eob_branch_ct)[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] = cpi->common.counts.eob_branch[tx_size]; int i, j, k, l, m; @@ -599,7 +601,6 @@ static void update_coef_probs_common(vpx_writer *const bc, VP9_COMP *cpi, for (t = 0; t < entropy_nodes_update; ++t) { vpx_prob newp = new_coef_probs[i][j][k][l][t]; vpx_prob *oldp = old_coef_probs[i][j][k][l] + t; - const vpx_prob upd = DIFF_UPDATE_PROB; int64_t s; int u = 0; if (t == PIVOT_NODE) @@ -900,6 +901,19 @@ static void write_tile_info(const VP9_COMMON *const cm, } int vp9_get_refresh_mask(VP9_COMP *cpi) { + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_GOP) != 0 && + cpi->ext_ratectrl.funcs.get_gop_decision != NULL) { + GF_GROUP *const gf_group = &cpi->twopass.gf_group; + const int this_gf_index = gf_group->index; + const int update_ref_idx = gf_group->update_ref_idx[this_gf_index]; + + if (update_ref_idx != INVALID_IDX) { + return (1 << update_ref_idx); + } else { + return 0; + } + } if (vp9_preserve_existing_gf(cpi)) { // We have decided to preserve the previously existing golden frame as our // new ARF frame. However, in the short term we leave it in the GF slot and, @@ -944,12 +958,11 @@ static int encode_tile_worker(void *arg1, void *arg2) { VP9BitstreamWorkerData *data = (VP9BitstreamWorkerData *)arg2; MACROBLOCKD *const xd = &data->xd; const int tile_row = 0; - vpx_start_encode(&data->bit_writer, data->dest); + vpx_start_encode(&data->bit_writer, data->dest, data->dest_size); write_modes(cpi, xd, &cpi->tile_data[data->tile_idx].tile_info, &data->bit_writer, tile_row, data->tile_idx, &data->max_mv_magnitude, data->interp_filter_selected); - vpx_stop_encode(&data->bit_writer); - return 1; + return vpx_stop_encode(&data->bit_writer) == 0; } void vp9_bitstream_encode_tiles_buffer_dealloc(VP9_COMP *const cpi) { @@ -963,35 +976,47 @@ void vp9_bitstream_encode_tiles_buffer_dealloc(VP9_COMP *const cpi) { } } -static void encode_tiles_buffer_alloc(VP9_COMP *const cpi) { +static size_t encode_tiles_buffer_alloc_size(const VP9_COMP *cpi) { + const VP9_COMMON *cm = &cpi->common; + const int image_bps = + (8 + 2 * (8 >> (cm->subsampling_x + cm->subsampling_y))) * + (1 + (cm->bit_depth > 8)); + const int64_t size = + (int64_t)cpi->oxcf.width * cpi->oxcf.height * image_bps / 8; + return (size_t)size; +} + +static void encode_tiles_buffer_alloc(VP9_COMP *const cpi, + size_t buffer_alloc_size) { VP9_COMMON *const cm = &cpi->common; int i; const size_t worker_data_size = cpi->num_workers * sizeof(*cpi->vp9_bitstream_worker_data); - CHECK_MEM_ERROR(cm, cpi->vp9_bitstream_worker_data, + CHECK_MEM_ERROR(&cm->error, cpi->vp9_bitstream_worker_data, vpx_memalign(16, worker_data_size)); memset(cpi->vp9_bitstream_worker_data, 0, worker_data_size); for (i = 1; i < cpi->num_workers; ++i) { - cpi->vp9_bitstream_worker_data[i].dest_size = - cpi->oxcf.width * cpi->oxcf.height; - CHECK_MEM_ERROR(cm, cpi->vp9_bitstream_worker_data[i].dest, - vpx_malloc(cpi->vp9_bitstream_worker_data[i].dest_size)); + CHECK_MEM_ERROR(&cm->error, cpi->vp9_bitstream_worker_data[i].dest, + vpx_malloc(buffer_alloc_size)); + cpi->vp9_bitstream_worker_data[i].dest_size = buffer_alloc_size; } } -static size_t encode_tiles_mt(VP9_COMP *cpi, uint8_t *data_ptr) { +static size_t encode_tiles_mt(VP9_COMP *cpi, uint8_t *data_ptr, + size_t data_size) { const VPxWorkerInterface *const winterface = vpx_get_worker_interface(); VP9_COMMON *const cm = &cpi->common; const int tile_cols = 1 << cm->log2_tile_cols; const int num_workers = cpi->num_workers; size_t total_size = 0; int tile_col = 0; + int error = 0; + const size_t buffer_alloc_size = encode_tiles_buffer_alloc_size(cpi); if (!cpi->vp9_bitstream_worker_data || - cpi->vp9_bitstream_worker_data[1].dest_size > - (cpi->oxcf.width * cpi->oxcf.height)) { + cpi->vp9_bitstream_worker_data[1].dest_size != buffer_alloc_size) { vp9_bitstream_encode_tiles_buffer_dealloc(cpi); - encode_tiles_buffer_alloc(cpi); + encode_tiles_buffer_alloc(cpi, buffer_alloc_size); } while (tile_col < tile_cols) { @@ -1011,8 +1036,13 @@ static size_t encode_tiles_mt(VP9_COMP *cpi, uint8_t *data_ptr) { if (i == 0) { // If this worker happens to be for the last tile, then do not offset it // by 4 for the tile size. - data->dest = - data_ptr + total_size + (tile_col == tile_cols - 1 ? 0 : 4); + const size_t offset = total_size + (tile_col == tile_cols - 1 ? 0 : 4); + if (data_size < offset) { + vpx_internal_error(&cm->error, VPX_CODEC_ERROR, + "encode_tiles_mt: output buffer full"); + } + data->dest = data_ptr + offset; + data->dest_size = data_size - offset; } worker->data1 = cpi; worker->data2 = data; @@ -1033,7 +1063,11 @@ static size_t encode_tiles_mt(VP9_COMP *cpi, uint8_t *data_ptr) { uint32_t tile_size; int k; - if (!winterface->sync(worker)) return 0; + if (!winterface->sync(worker)) { + error = 1; + continue; + } + tile_size = data->bit_writer.pos; // Aggregate per-thread bitstream stats. @@ -1045,19 +1079,31 @@ static size_t encode_tiles_mt(VP9_COMP *cpi, uint8_t *data_ptr) { // Prefix the size of the tile on all but the last. if (tile_col != tile_cols || j < i - 1) { + if (data_size - total_size < 4) { + error = 1; + continue; + } mem_put_be32(data_ptr + total_size, tile_size); total_size += 4; } if (j > 0) { + if (data_size - total_size < tile_size) { + error = 1; + continue; + } memcpy(data_ptr + total_size, data->dest, tile_size); } total_size += tile_size; } + if (error) { + vpx_internal_error(&cm->error, VPX_CODEC_ERROR, + "encode_tiles_mt: output buffer full"); + } } return total_size; } -static size_t encode_tiles(VP9_COMP *cpi, uint8_t *data_ptr) { +static size_t encode_tiles(VP9_COMP *cpi, uint8_t *data_ptr, size_t data_size) { VP9_COMMON *const cm = &cpi->common; MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; vpx_writer residual_bc; @@ -1074,23 +1120,32 @@ static size_t encode_tiles(VP9_COMP *cpi, uint8_t *data_ptr) { // that it does not make the overall process worse in any case. if (cpi->oxcf.mode == REALTIME && cpi->num_workers > 1 && tile_rows == 1 && tile_cols > 1) { - return encode_tiles_mt(cpi, data_ptr); + return encode_tiles_mt(cpi, data_ptr, data_size); } for (tile_row = 0; tile_row < tile_rows; tile_row++) { for (tile_col = 0; tile_col < tile_cols; tile_col++) { int tile_idx = tile_row * tile_cols + tile_col; + size_t offset; if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) - vpx_start_encode(&residual_bc, data_ptr + total_size + 4); + offset = total_size + 4; else - vpx_start_encode(&residual_bc, data_ptr + total_size); + offset = total_size; + if (data_size < offset) { + vpx_internal_error(&cm->error, VPX_CODEC_ERROR, + "encode_tiles: output buffer full"); + } + vpx_start_encode(&residual_bc, data_ptr + offset, data_size - offset); write_modes(cpi, xd, &cpi->tile_data[tile_idx].tile_info, &residual_bc, tile_row, tile_col, &cpi->max_mv_magnitude, cpi->interp_filter_selected); - vpx_stop_encode(&residual_bc); + if (vpx_stop_encode(&residual_bc)) { + vpx_internal_error(&cm->error, VPX_CODEC_ERROR, + "encode_tiles: output buffer full"); + } if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) { // size of this tile mem_put_be32(data_ptr + total_size, residual_bc.pos); @@ -1195,6 +1250,7 @@ static void write_bitdepth_colorspace_sampling( } } else { assert(cm->profile == PROFILE_1 || cm->profile == PROFILE_3); + assert(cm->subsampling_x == 0 && cm->subsampling_y == 0); vpx_wb_write_bit(wb, 0); // unused } } @@ -1272,14 +1328,15 @@ static void write_uncompressed_header(VP9_COMP *cpi, write_tile_info(cm, wb); } -static size_t write_compressed_header(VP9_COMP *cpi, uint8_t *data) { +static size_t write_compressed_header(VP9_COMP *cpi, uint8_t *data, + size_t data_size) { VP9_COMMON *const cm = &cpi->common; MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; FRAME_CONTEXT *const fc = cm->fc; FRAME_COUNTS *counts = cpi->td.counts; vpx_writer header_bc; - vpx_start_encode(&header_bc, data); + vpx_start_encode(&header_bc, data, data_size); if (xd->lossless) cm->tx_mode = ONLY_4X4; @@ -1343,26 +1400,36 @@ static size_t write_compressed_header(VP9_COMP *cpi, uint8_t *data) { &counts->mv); } - vpx_stop_encode(&header_bc); - assert(header_bc.pos <= 0xffff); + if (vpx_stop_encode(&header_bc)) { + vpx_internal_error(&cm->error, VPX_CODEC_ERROR, + "write_compressed_header: output buffer full"); + } return header_bc.pos; } -void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, size_t *size) { +void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, size_t dest_size, + size_t *size) { + VP9_COMMON *const cm = &cpi->common; uint8_t *data = dest; - size_t first_part_size, uncompressed_hdr_size; - struct vpx_write_bit_buffer wb = { data, 0 }; + size_t data_size = dest_size; + size_t uncompressed_hdr_size, compressed_hdr_size; + struct vpx_write_bit_buffer wb; struct vpx_write_bit_buffer saved_wb; #if CONFIG_BITSTREAM_DEBUG bitstream_queue_reset_write(); #endif + vpx_wb_init(&wb, data, data_size); write_uncompressed_header(cpi, &wb); + if (vpx_wb_has_error(&wb)) { + vpx_internal_error(&cm->error, VPX_CODEC_ERROR, + "vp9_pack_bitstream: output buffer full"); + } // Skip the rest coding process if use show existing frame. - if (cpi->common.show_existing_frame) { + if (cm->show_existing_frame) { uncompressed_hdr_size = vpx_wb_bytes_written(&wb); data += uncompressed_hdr_size; *size = data - dest; @@ -1370,19 +1437,30 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, size_t *size) { } saved_wb = wb; - vpx_wb_write_literal(&wb, 0, 16); // don't know in advance first part. size + // don't know in advance compressed header size + vpx_wb_write_literal(&wb, 0, 16); + if (vpx_wb_has_error(&wb)) { + vpx_internal_error(&cm->error, VPX_CODEC_ERROR, + "vp9_pack_bitstream: output buffer full"); + } uncompressed_hdr_size = vpx_wb_bytes_written(&wb); data += uncompressed_hdr_size; + data_size -= uncompressed_hdr_size; vpx_clear_system_state(); - first_part_size = write_compressed_header(cpi, data); - data += first_part_size; - // TODO(jbb): Figure out what to do if first_part_size > 16 bits. - vpx_wb_write_literal(&saved_wb, (int)first_part_size, 16); + compressed_hdr_size = write_compressed_header(cpi, data, data_size); + data += compressed_hdr_size; + data_size -= compressed_hdr_size; + if (compressed_hdr_size > UINT16_MAX) { + vpx_internal_error(&cm->error, VPX_CODEC_ERROR, + "compressed_hdr_size > 16 bits"); + } + vpx_wb_write_literal(&saved_wb, (int)compressed_hdr_size, 16); + assert(!vpx_wb_has_error(&saved_wb)); - data += encode_tiles(cpi, data); + data += encode_tiles(cpi, data, data_size); *size = data - dest; } diff --git a/libs/libvpx/vp9/encoder/vp9_bitstream.h b/libs/libvpx/vp9/encoder/vp9_bitstream.h index 208651dc22..1120841ecb 100644 --- a/libs/libvpx/vp9/encoder/vp9_bitstream.h +++ b/libs/libvpx/vp9/encoder/vp9_bitstream.h @@ -19,7 +19,7 @@ extern "C" { typedef struct VP9BitstreamWorkerData { uint8_t *dest; - int dest_size; + size_t dest_size; vpx_writer bit_writer; int tile_idx; unsigned int max_mv_magnitude; @@ -35,7 +35,8 @@ int vp9_get_refresh_mask(VP9_COMP *cpi); void vp9_bitstream_encode_tiles_buffer_dealloc(VP9_COMP *const cpi); -void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, size_t *size); +void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, size_t dest_size, + size_t *size); static INLINE int vp9_preserve_existing_gf(VP9_COMP *cpi) { return cpi->refresh_golden_frame && cpi->rc.is_src_frame_alt_ref && diff --git a/libs/libvpx/vp9/encoder/vp9_block.h b/libs/libvpx/vp9/encoder/vp9_block.h index 20294b4b94..abb462c46a 100644 --- a/libs/libvpx/vp9/encoder/vp9_block.h +++ b/libs/libvpx/vp9/encoder/vp9_block.h @@ -11,8 +11,7 @@ #ifndef VPX_VP9_ENCODER_VP9_BLOCK_H_ #define VPX_VP9_ENCODER_VP9_BLOCK_H_ -#include "vpx_util/vpx_thread.h" - +#include "vp9/common/vp9_blockd.h" #include "vp9/common/vp9_entropymv.h" #include "vp9/common/vp9_entropy.h" @@ -20,12 +19,6 @@ extern "C" { #endif -typedef struct { - unsigned int sse; - int sum; - unsigned int var; -} diff; - struct macroblock_plane { DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]); tran_low_t *qcoeff; @@ -33,8 +26,8 @@ struct macroblock_plane { uint16_t *eobs; struct buf_2d src; - // Quantizer setings - DECLARE_ALIGNED(16, int16_t, round_fp[8]); + // Quantizer settings + int16_t *round_fp; int16_t *quant_fp; int16_t *quant; int16_t *quant_shift; @@ -78,16 +71,16 @@ struct macroblock { int skip_recode; int skip_optimize; int q_index; - int block_qcoeff_opt; + double log_block_src_var; int block_tx_domain; // The equivalent error at the current rdmult of one whole bit (not one // bitcost unit). int errorperbit; - // The equivalend SAD error of one (whole) bit at the current quantizer + // The equivalent SAD error of one (whole) bit at the current quantizer // for large blocks. int sadperbit16; - // The equivalend SAD error of one (whole) bit at the current quantizer + // The equivalent SAD error of one (whole) bit at the current quantizer // for sub-8x8 blocks. int sadperbit4; int rddiv; @@ -127,7 +120,7 @@ struct macroblock { // from extending outside the UMV borders MvLimits mv_limits; - // Notes transform blocks where no coefficents are coded. + // Notes transform blocks where no coefficients are coded. // Set during mode selection. Read during block encoding. uint8_t zcoeff_blk[TX_SIZES][256]; diff --git a/libs/libvpx/vp9/encoder/vp9_context_tree.c b/libs/libvpx/vp9/encoder/vp9_context_tree.c index b74b9027ca..ee0fcd8729 100644 --- a/libs/libvpx/vp9/encoder/vp9_context_tree.c +++ b/libs/libvpx/vp9/encoder/vp9_context_tree.c @@ -25,16 +25,17 @@ static void alloc_mode_context(VP9_COMMON *cm, int num_4x4_blk, int i, k; ctx->num_4x4_blk = num_blk; - CHECK_MEM_ERROR(cm, ctx->zcoeff_blk, vpx_calloc(num_blk, sizeof(uint8_t))); + CHECK_MEM_ERROR(&cm->error, ctx->zcoeff_blk, + vpx_calloc(num_blk, sizeof(uint8_t))); for (i = 0; i < MAX_MB_PLANE; ++i) { for (k = 0; k < 3; ++k) { - CHECK_MEM_ERROR(cm, ctx->coeff[i][k], + CHECK_MEM_ERROR(&cm->error, ctx->coeff[i][k], vpx_memalign(32, num_pix * sizeof(*ctx->coeff[i][k]))); - CHECK_MEM_ERROR(cm, ctx->qcoeff[i][k], + CHECK_MEM_ERROR(&cm->error, ctx->qcoeff[i][k], vpx_memalign(32, num_pix * sizeof(*ctx->qcoeff[i][k]))); - CHECK_MEM_ERROR(cm, ctx->dqcoeff[i][k], + CHECK_MEM_ERROR(&cm->error, ctx->dqcoeff[i][k], vpx_memalign(32, num_pix * sizeof(*ctx->dqcoeff[i][k]))); - CHECK_MEM_ERROR(cm, ctx->eobs[i][k], + CHECK_MEM_ERROR(&cm->error, ctx->eobs[i][k], vpx_memalign(32, num_blk * sizeof(*ctx->eobs[i][k]))); ctx->coeff_pbuf[i][k] = ctx->coeff[i][k]; ctx->qcoeff_pbuf[i][k] = ctx->qcoeff[i][k]; @@ -100,10 +101,10 @@ void vp9_setup_pc_tree(VP9_COMMON *cm, ThreadData *td) { int nodes; vpx_free(td->leaf_tree); - CHECK_MEM_ERROR(cm, td->leaf_tree, + CHECK_MEM_ERROR(&cm->error, td->leaf_tree, vpx_calloc(leaf_nodes, sizeof(*td->leaf_tree))); vpx_free(td->pc_tree); - CHECK_MEM_ERROR(cm, td->pc_tree, + CHECK_MEM_ERROR(&cm->error, td->pc_tree, vpx_calloc(tree_nodes, sizeof(*td->pc_tree))); this_pc = &td->pc_tree[0]; @@ -118,8 +119,8 @@ void vp9_setup_pc_tree(VP9_COMMON *cm, ThreadData *td) { PC_TREE *const tree = &td->pc_tree[pc_tree_index]; tree->block_size = square[0]; alloc_tree_contexts(cm, tree, 4); - tree->leaf_split[0] = this_leaf++; - for (j = 1; j < 4; j++) tree->leaf_split[j] = tree->leaf_split[0]; + tree->u.leaf_split[0] = this_leaf++; + for (j = 1; j < 4; j++) tree->u.leaf_split[j] = tree->u.leaf_split[0]; } // Each node has 4 leaf nodes, fill each block_size level of the tree @@ -129,7 +130,7 @@ void vp9_setup_pc_tree(VP9_COMMON *cm, ThreadData *td) { PC_TREE *const tree = &td->pc_tree[pc_tree_index]; alloc_tree_contexts(cm, tree, 4 << (2 * square_index)); tree->block_size = square[square_index]; - for (j = 0; j < 4; j++) tree->split[j] = this_pc++; + for (j = 0; j < 4; j++) tree->u.split[j] = this_pc++; ++pc_tree_index; } ++square_index; diff --git a/libs/libvpx/vp9/encoder/vp9_context_tree.h b/libs/libvpx/vp9/encoder/vp9_context_tree.h index 4e301cc17d..51e13ba654 100644 --- a/libs/libvpx/vp9/encoder/vp9_context_tree.h +++ b/libs/libvpx/vp9/encoder/vp9_context_tree.h @@ -90,7 +90,7 @@ typedef struct PC_TREE { union { struct PC_TREE *split[4]; PICK_MODE_CONTEXT *leaf_split[4]; - }; + } u; // Obtained from a simple motion search. Used by the ML based partition search // speed feature. MV mv; diff --git a/libs/libvpx/vp9/encoder/vp9_denoiser.c b/libs/libvpx/vp9/encoder/vp9_denoiser.c index 2885223b59..bc9a77808e 100644 --- a/libs/libvpx/vp9/encoder/vp9_denoiser.c +++ b/libs/libvpx/vp9/encoder/vp9_denoiser.c @@ -233,7 +233,7 @@ static VP9_DENOISER_DECISION perform_motion_compensation( frame == ALTREF_FRAME || (frame == GOLDEN_FRAME && use_gf_temporal_ref) || (frame != LAST_FRAME && - ((ctx->zeromv_lastref_sse<(5 * ctx->zeromv_sse)>> 2) || + ((ctx->zeromv_lastref_sse < (5 * ctx->zeromv_sse) >> 2) || denoiser->denoising_level >= kDenHigh))) { frame = LAST_FRAME; ctx->newmv_sse = ctx->zeromv_lastref_sse; @@ -319,7 +319,7 @@ static VP9_DENOISER_DECISION perform_motion_compensation( filter_mbd->plane[2].dst.stride = denoiser->mc_running_avg_y[denoise_layer_idx].uv_stride; - set_ref_ptrs(cm, filter_mbd, saved_frame, NONE); + set_ref_ptrs(cm, filter_mbd, saved_frame, NO_REF_FRAME); vp9_build_inter_predictors_sby(filter_mbd, mi_row, mi_col, bs); // Restore everything to its original state @@ -387,7 +387,7 @@ void vp9_denoiser_denoise(VP9_COMP *cpi, MACROBLOCK *mb, int mi_row, int mi_col, consec_zeromv = VPXMIN(cpi->consec_zero_mv[bl_index], consec_zeromv); // No need to keep checking 8x8 blocks if any of the sub-blocks // has small consec_zeromv (since threshold for no_skin based on - // zero/small motion in skin detection is high, i.e, > 4). + // zero/small motion in skin detection is high, i.e., > 4). if (consec_zeromv < 4) { i = ymis; break; @@ -634,11 +634,11 @@ int vp9_denoiser_alloc(VP9_COMMON *cm, struct SVC *svc, VP9_DENOISER *denoiser, denoiser->num_ref_frames = use_svc ? SVC_REF_FRAMES : NONSVC_REF_FRAMES; init_num_ref_frames = use_svc ? MAX_REF_FRAMES : NONSVC_REF_FRAMES; denoiser->num_layers = num_layers; - CHECK_MEM_ERROR(cm, denoiser->running_avg_y, + CHECK_MEM_ERROR(&cm->error, denoiser->running_avg_y, vpx_calloc(denoiser->num_ref_frames * num_layers, sizeof(denoiser->running_avg_y[0]))); CHECK_MEM_ERROR( - cm, denoiser->mc_running_avg_y, + &cm->error, denoiser->mc_running_avg_y, vpx_calloc(num_layers, sizeof(denoiser->mc_running_avg_y[0]))); for (layer = 0; layer < num_layers; ++layer) { @@ -714,6 +714,8 @@ void vp9_denoiser_free(VP9_DENOISER *denoiser) { vpx_free(denoiser->mc_running_avg_y); denoiser->mc_running_avg_y = NULL; vpx_free_frame_buffer(&denoiser->last_source); + denoiser->num_ref_frames = 0; + denoiser->num_layers = 0; } static void force_refresh_longterm_ref(VP9_COMP *const cpi) { @@ -764,8 +766,9 @@ int64_t vp9_scale_acskip_thresh(int64_t threshold, VP9_DENOISER_LEVEL noise_level, int abs_sumdiff, int temporal_layer_id) { if (noise_level >= kDenLow && abs_sumdiff < 5) - return threshold *= - (noise_level == kDenLow) ? 2 : (temporal_layer_id == 2) ? 10 : 6; + return threshold *= (noise_level == kDenLow) ? 2 + : (temporal_layer_id == 2) ? 10 + : 6; else return threshold; } diff --git a/libs/libvpx/vp9/encoder/vp9_encodeframe.c b/libs/libvpx/vp9/encoder/vp9_encodeframe.c index a9f392bf51..f834b2dc41 100644 --- a/libs/libvpx/vp9/encoder/vp9_encodeframe.c +++ b/libs/libvpx/vp9/encoder/vp9_encodeframe.c @@ -21,7 +21,7 @@ #include "vpx_ports/mem.h" #include "vpx_ports/vpx_timer.h" #include "vpx_ports/system_state.h" - +#include "vpx_util/vpx_pthread.h" #if CONFIG_MISMATCH_DEBUG #include "vpx_util/vpx_debug_util.h" #endif // CONFIG_MISMATCH_DEBUG @@ -48,6 +48,7 @@ #include "vp9/encoder/vp9_encodeframe.h" #include "vp9/encoder/vp9_encodemb.h" #include "vp9/encoder/vp9_encodemv.h" +#include "vp9/encoder/vp9_encoder.h" #include "vp9/encoder/vp9_ethread.h" #include "vp9/encoder/vp9_extend.h" #include "vp9/encoder/vp9_multi_thread.h" @@ -349,17 +350,17 @@ typedef struct { int32_t sum_error; int log2_count; int variance; -} var; +} Var; typedef struct { - var none; - var horz[2]; - var vert[2]; + Var none; + Var horz[2]; + Var vert[2]; } partition_variance; typedef struct { partition_variance part_variances; - var split[4]; + Var split[4]; } v4x4; typedef struct { @@ -384,7 +385,7 @@ typedef struct { typedef struct { partition_variance *part_variances; - var *split[4]; + Var *split[4]; } variance_node; typedef enum { @@ -436,13 +437,13 @@ static void tree_to_node(void *data, BLOCK_SIZE bsize, variance_node *node) { } // Set variance values given sum square error, sum error, count. -static void fill_variance(uint32_t s2, int32_t s, int c, var *v) { +static void fill_variance(uint32_t s2, int32_t s, int c, Var *v) { v->sum_square_error = s2; v->sum_error = s; v->log2_count = c; } -static void get_variance(var *v) { +static void get_variance(Var *v) { v->variance = (int)(256 * (v->sum_square_error - (uint32_t)(((int64_t)v->sum_error * v->sum_error) >> @@ -450,7 +451,7 @@ static void get_variance(var *v) { v->log2_count); } -static void sum_2_variances(const var *a, const var *b, var *r) { +static void sum_2_variances(const Var *a, const Var *b, Var *r) { assert(a->log2_count == b->log2_count); fill_variance(a->sum_square_error + b->sum_square_error, a->sum_error + b->sum_error, a->log2_count + 1, r); @@ -964,6 +965,10 @@ static int copy_partitioning(VP9_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd, return 0; } +// Set the partition for mi_col/row_high (current resolution) based on +// the previous spatial layer (mi_col/row). Returns 0 if partition is set, +// returns 1 if no scale partitioning is done. Return 1 means the variance +// partitioning will be used. static int scale_partitioning_svc(VP9_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd, BLOCK_SIZE bsize, int mi_row, int mi_col, int mi_row_high, int mi_col_high) { @@ -973,31 +978,29 @@ static int scale_partitioning_svc(VP9_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd, // Variables with _high are for higher resolution. int bsize_high = 0; int subsize_high = 0; - const int bsl_high = b_width_log2_lookup[bsize]; - const int bs_high = (1 << bsl_high) >> 2; - const int has_rows = (mi_row_high + bs_high) < cm->mi_rows; - const int has_cols = (mi_col_high + bs_high) < cm->mi_cols; + const int bsl = b_width_log2_lookup[bsize]; + const int bs = (1 << bsl) >> 2; + const int has_rows = (mi_row_high + bs) < cm->mi_rows; + const int has_cols = (mi_col_high + bs) < cm->mi_cols; - const int row_boundary_block_scale_factor[BLOCK_SIZES] = { 13, 13, 13, 1, 0, - 1, 1, 0, 1, 1, - 0, 1, 0 }; - const int col_boundary_block_scale_factor[BLOCK_SIZES] = { 13, 13, 13, 2, 2, - 0, 2, 2, 0, 2, - 2, 0, 0 }; int start_pos; BLOCK_SIZE bsize_low; PARTITION_TYPE partition_high; - if (mi_row_high >= cm->mi_rows || mi_col_high >= cm->mi_cols) return 0; + // If the lower layer frame is outside the boundary (this can happen for + // odd size resolutions) then do not scale partitioning from the lower + // layer. Do variance based partitioning instead (return 1). if (mi_row >= svc->mi_rows[svc->spatial_layer_id - 1] || mi_col >= svc->mi_cols[svc->spatial_layer_id - 1]) - return 0; + return 1; + + // Do not scale partitioning from lower layers on the boundary. Do + // variance based partitioning instead (return 1). + if (!has_rows || !has_cols) return 1; // Find corresponding (mi_col/mi_row) block down-scaled by 2x2. start_pos = mi_row * (svc->mi_stride[svc->spatial_layer_id - 1]) + mi_col; bsize_low = prev_part[start_pos]; - // The block size is too big for boundaries. Do variance based partitioning. - if ((!has_rows || !has_cols) && bsize_low > BLOCK_16X16) return 1; // For reference frames: return 1 (do variance-based partitioning) if the // superblock is not low source sad and lower-resoln bsize is below 32x32. @@ -1011,23 +1014,13 @@ static int scale_partitioning_svc(VP9_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd, } else if (bsize_low >= BLOCK_32X32) { bsize_high = BLOCK_64X64; } - // Scale up blocks on boundary. - if (!has_cols && has_rows) { - bsize_high = bsize_low + row_boundary_block_scale_factor[bsize_low]; - } else if (has_cols && !has_rows) { - bsize_high = bsize_low + col_boundary_block_scale_factor[bsize_low]; - } else if (!has_cols && !has_rows) { - bsize_high = bsize_low; - } - partition_high = partition_lookup[bsl_high][bsize_high]; + partition_high = partition_lookup[bsl][bsize_high]; subsize_high = get_subsize(bsize, partition_high); if (subsize_high < BLOCK_8X8) { set_block_size(cpi, x, xd, mi_row_high, mi_col_high, bsize_high); } else { - const int bsl = b_width_log2_lookup[bsize]; - const int bs = (1 << bsl) >> 2; switch (partition_high) { case PARTITION_NONE: set_block_size(cpi, x, xd, mi_row_high, mi_col_high, bsize_high); @@ -1035,13 +1028,13 @@ static int scale_partitioning_svc(VP9_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd, case PARTITION_HORZ: set_block_size(cpi, x, xd, mi_row_high, mi_col_high, subsize_high); if (subsize_high < BLOCK_64X64) - set_block_size(cpi, x, xd, mi_row_high + bs_high, mi_col_high, + set_block_size(cpi, x, xd, mi_row_high + bs, mi_col_high, subsize_high); break; case PARTITION_VERT: set_block_size(cpi, x, xd, mi_row_high, mi_col_high, subsize_high); if (subsize_high < BLOCK_64X64) - set_block_size(cpi, x, xd, mi_row_high, mi_col_high + bs_high, + set_block_size(cpi, x, xd, mi_row_high, mi_col_high + bs, subsize_high); break; default: @@ -1050,15 +1043,15 @@ static int scale_partitioning_svc(VP9_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd, mi_row_high, mi_col_high)) return 1; if (scale_partitioning_svc(cpi, x, xd, subsize_high, mi_row + (bs >> 1), - mi_col, mi_row_high + bs_high, mi_col_high)) + mi_col, mi_row_high + bs, mi_col_high)) return 1; if (scale_partitioning_svc(cpi, x, xd, subsize_high, mi_row, mi_col + (bs >> 1), mi_row_high, - mi_col_high + bs_high)) + mi_col_high + bs)) return 1; if (scale_partitioning_svc(cpi, x, xd, subsize_high, mi_row + (bs >> 1), - mi_col + (bs >> 1), mi_row_high + bs_high, - mi_col_high + bs_high)) + mi_col + (bs >> 1), mi_row_high + bs, + mi_col_high + bs)) return 1; break; } @@ -1255,6 +1248,30 @@ static uint64_t avg_source_sad(VP9_COMP *cpi, MACROBLOCK *x, int shift, return tmp_sad; } +// Check whether the current frame should be treated as a key frame for the +// purpose of superblock partitioning. Under SVC mode, treat the frame as key if +// the base layer frame is a key frame, or if LAST_FRAME is NULL or has a +// different resolution than the current frame (e.g., when enhancement spatial +// layers are enabled dynamically and the only reference is GOLDEN). +static INLINE int is_key_frame_for_partition(const VP9_COMP *const cpi) { + const VP9_COMMON *const cm = &cpi->common; + const YV12_BUFFER_CONFIG *ref; + if (frame_is_intra_only(cm) || + (is_one_pass_svc(cpi) && + cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame)) { + return 1; + } + ref = get_ref_frame_buffer(cpi, LAST_FRAME); + if (ref == NULL || + cm->frame_refs[LAST_FRAME - 1].sf.x_scale_fp == REF_INVALID_SCALE || + cm->frame_refs[LAST_FRAME - 1].sf.y_scale_fp == REF_INVALID_SCALE || + (cpi->use_svc && + (ref->y_crop_height != cm->height || ref->y_crop_width != cm->width))) { + return 1; + } + return 0; +} + // This function chooses partitioning based on the variance between source and // reconstructed last, where variance is computed for down-sampled inputs. static int choose_partitioning(VP9_COMP *cpi, const TileInfo *const tile, @@ -1294,33 +1311,20 @@ static int choose_partitioning(VP9_COMP *cpi, const TileInfo *const tile, (cpi->oxcf.content == VP9E_CONTENT_SCREEN && cpi->compute_source_sad_onepass && cpi->sf.use_source_sad && !x->zero_temp_sad_source); + const int is_key_frame = is_key_frame_for_partition(cpi); - // For the variance computation under SVC mode, we treat the frame as key if - // the reference (base layer frame) is key frame (i.e., is_key_frame == 1). - int is_key_frame = - (frame_is_intra_only(cm) || - (is_one_pass_cbr_svc(cpi) && - cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame)); - // Always use 4x4 partition for key frame. - const int use_4x4_partition = frame_is_intra_only(cm); + // Allow for sub8x8 (4x4) partition on key frames, but only for hybrid mode + // (i.e., sf->nonrd_keyframe = 0), where for small blocks rd intra pickmode + // (vp9_rd_pick_intra_mode_sb) is used. The nonrd intra pickmode + // (vp9_pick_intra_mode) does not currently support sub8x8 blocks. This causes + // the issue: 44166813. Assert is added in vp9_pick_intra_mode to check this. + const int use_4x4_partition = + frame_is_intra_only(cm) && !cpi->sf.nonrd_keyframe; const int low_res = (cm->width <= 352 && cm->height <= 288); int variance4x4downsample[16]; int segment_id; int sb_offset = (cm->mi_stride >> 3) * (mi_row >> 3) + (mi_col >> 3); - // For SVC: check if LAST frame is NULL or if the resolution of LAST is - // different than the current frame resolution, and if so, treat this frame - // as a key frame, for the purpose of the superblock partitioning. - // LAST == NULL can happen in some cases where enhancement spatial layers are - // enabled dyanmically in the stream and the only reference is the spatial - // reference (GOLDEN). - if (cpi->use_svc) { - const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, LAST_FRAME); - if (ref == NULL || ref->y_crop_height != cm->height || - ref->y_crop_width != cm->width) - is_key_frame = 1; - } - set_offsets(cpi, tile, x, mi_row, mi_col, BLOCK_64X64); set_segment_index(cpi, x, mi_row, mi_col, BLOCK_64X64, 0); segment_id = xd->mi[0]->segment_id; @@ -1406,7 +1410,7 @@ static int choose_partitioning(VP9_COMP *cpi, const TileInfo *const tile, assert(yv12 != NULL); - if (!(is_one_pass_cbr_svc(cpi) && cpi->svc.spatial_layer_id) || + if (!(is_one_pass_svc(cpi) && cpi->svc.spatial_layer_id) || cpi->svc.use_gf_temporal_ref_current_layer) { // For now, GOLDEN will not be used for non-zero spatial layers, since // it may not be a temporal reference. @@ -1437,7 +1441,7 @@ static int choose_partitioning(VP9_COMP *cpi, const TileInfo *const tile, &cm->frame_refs[LAST_FRAME - 1].sf); mi->ref_frame[0] = LAST_FRAME; } - mi->ref_frame[1] = NONE; + mi->ref_frame[1] = NO_REF_FRAME; mi->sb_type = BLOCK_64X64; mi->mv[0].as_int = 0; mi->interp_filter = BILINEAR; @@ -1545,7 +1549,7 @@ static int choose_partitioning(VP9_COMP *cpi, const TileInfo *const tile, } if (low_res && threshold_4x4avg < INT64_MAX) - CHECK_MEM_ERROR(cm, vt2, vpx_calloc(16, sizeof(*vt2))); + CHECK_MEM_ERROR(&cm->error, vt2, vpx_calloc(16, sizeof(*vt2))); // Fill in the entire tree of 8x8 (or 4x4 under some conditions) variances // for splits. for (i = 0; i < 4; i++) { @@ -1706,7 +1710,7 @@ static int choose_partitioning(VP9_COMP *cpi, const TileInfo *const tile, const int y16_idx = ((j >> 1) << 1); // For inter frames: if variance4x4downsample[] == 1 for this 16x16 // block, then the variance is based on 4x4 down-sampling, so use vt2 - // in set_vt_partioning(), otherwise use vt. + // in set_vt_partitioning(), otherwise use vt. v16x16 *vtemp = (!is_key_frame && variance4x4downsample[i2 + j] == 1) ? &vt2[i2 + j] : &vt.split[i].split[j]; @@ -1863,8 +1867,8 @@ static void update_state(VP9_COMP *cpi, ThreadData *td, PICK_MODE_CONTEXT *ctx, vp9_update_mv_count(td); if (cm->interp_filter == SWITCHABLE) { - const int ctx = get_pred_context_switchable_interp(xd); - ++td->counts->switchable_interp[ctx][xdmi->interp_filter]; + const int ctx_interp = get_pred_context_switchable_interp(xd); + ++td->counts->switchable_interp[ctx_interp][xdmi->interp_filter]; } } @@ -1924,7 +1928,7 @@ static void set_mode_info_seg_skip(MACROBLOCK *x, TX_MODE tx_mode, mi->skip = 1; mi->uv_mode = DC_PRED; mi->ref_frame[0] = LAST_FRAME; - mi->ref_frame[1] = NONE; + mi->ref_frame[1] = NO_REF_FRAME; mi->mv[0].as_int = 0; mi->interp_filter = filter_ref; @@ -1980,6 +1984,9 @@ static void rd_pick_sb_modes(VP9_COMP *cpi, TileDataEnc *tile_data, int64_t best_rd = INT64_MAX; vpx_clear_system_state(); +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, rd_pick_sb_modes_time); +#endif // Use the lower precision, but faster, 32x32 fdct for mode selection. x->use_lp32x32fdct = 1; @@ -2018,20 +2025,20 @@ static void rd_pick_sb_modes(VP9_COMP *cpi, TileDataEnc *tile_data, // Save rdmult before it might be changed, so it can be restored later. orig_rdmult = x->rdmult; - if ((cpi->sf.tx_domain_thresh > 0.0) || (cpi->sf.quant_opt_thresh > 0.0)) { + if ((cpi->sf.tx_domain_thresh > 0.0) || + (cpi->sf.trellis_opt_tx_rd.thresh > 0.0)) { double logvar = vp9_log_block_var(cpi, x, bsize); - // Check block complexity as part of descision on using pixel or transform + // Check block complexity as part of decision on using pixel or transform // domain distortion in rd tests. x->block_tx_domain = cpi->sf.allow_txfm_domain_distortion && (logvar >= cpi->sf.tx_domain_thresh); - // Check block complexity as part of descision on using quantized - // coefficient optimisation inside the rd loop. - x->block_qcoeff_opt = - cpi->sf.allow_quant_coeff_opt && (logvar <= cpi->sf.quant_opt_thresh); + // Store block complexity to decide on using quantized coefficient + // optimization inside the rd loop. + x->log_block_src_var = logvar; } else { x->block_tx_domain = cpi->sf.allow_txfm_domain_distortion; - x->block_qcoeff_opt = cpi->sf.allow_quant_coeff_opt; + x->log_block_src_var = 0.0; } set_segment_index(cpi, x, mi_row, mi_col, bsize, 0); @@ -2047,15 +2054,27 @@ static void rd_pick_sb_modes(VP9_COMP *cpi, TileDataEnc *tile_data, vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, best_rd); } else { if (bsize >= BLOCK_8X8) { +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, vp9_rd_pick_inter_mode_sb_time); +#endif if (segfeature_active(&cm->seg, mi->segment_id, SEG_LVL_SKIP)) vp9_rd_pick_inter_mode_sb_seg_skip(cpi, tile_data, x, rd_cost, bsize, ctx, best_rd); else vp9_rd_pick_inter_mode_sb(cpi, tile_data, x, mi_row, mi_col, rd_cost, bsize, ctx, best_rd); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, vp9_rd_pick_inter_mode_sb_time); +#endif } else { +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, vp9_rd_pick_inter_mode_sub8x8_time); +#endif vp9_rd_pick_inter_mode_sub8x8(cpi, tile_data, x, mi_row, mi_col, rd_cost, bsize, ctx, best_rd); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, vp9_rd_pick_inter_mode_sub8x8_time); +#endif } } @@ -2078,6 +2097,9 @@ static void rd_pick_sb_modes(VP9_COMP *cpi, TileDataEnc *tile_data, ctx->rate = rd_cost->rate; ctx->dist = rd_cost->dist; +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, rd_pick_sb_modes_time); +#endif } #endif // !CONFIG_REALTIME_ONLY @@ -2277,16 +2299,16 @@ static void encode_sb(VP9_COMP *cpi, ThreadData *td, const TileInfo *const tile, assert(partition == PARTITION_SPLIT); if (bsize == BLOCK_8X8) { encode_b(cpi, tile, td, tp, mi_row, mi_col, output_enabled, subsize, - pc_tree->leaf_split[0]); + pc_tree->u.leaf_split[0]); } else { encode_sb(cpi, td, tile, tp, mi_row, mi_col, output_enabled, subsize, - pc_tree->split[0]); + pc_tree->u.split[0]); encode_sb(cpi, td, tile, tp, mi_row, mi_col + hbs, output_enabled, - subsize, pc_tree->split[1]); + subsize, pc_tree->u.split[1]); encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col, output_enabled, - subsize, pc_tree->split[2]); + subsize, pc_tree->u.split[2]); encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs, output_enabled, - subsize, pc_tree->split[3]); + subsize, pc_tree->u.split[3]); } break; } @@ -2368,120 +2390,6 @@ static void set_fixed_partitioning(VP9_COMP *cpi, const TileInfo *const tile, } } -static const struct { - int row; - int col; -} coord_lookup[16] = { - // 32x32 index = 0 - { 0, 0 }, - { 0, 2 }, - { 2, 0 }, - { 2, 2 }, - // 32x32 index = 1 - { 0, 4 }, - { 0, 6 }, - { 2, 4 }, - { 2, 6 }, - // 32x32 index = 2 - { 4, 0 }, - { 4, 2 }, - { 6, 0 }, - { 6, 2 }, - // 32x32 index = 3 - { 4, 4 }, - { 4, 6 }, - { 6, 4 }, - { 6, 6 }, -}; - -static void set_source_var_based_partition(VP9_COMP *cpi, - const TileInfo *const tile, - MACROBLOCK *const x, - MODE_INFO **mi_8x8, int mi_row, - int mi_col) { - VP9_COMMON *const cm = &cpi->common; - const int mis = cm->mi_stride; - const int row8x8_remaining = tile->mi_row_end - mi_row; - const int col8x8_remaining = tile->mi_col_end - mi_col; - MODE_INFO *mi_upper_left = cm->mi + mi_row * mis + mi_col; - - vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); - - assert((row8x8_remaining > 0) && (col8x8_remaining > 0)); - - // In-image SB64 - if ((col8x8_remaining >= MI_BLOCK_SIZE) && - (row8x8_remaining >= MI_BLOCK_SIZE)) { - int i, j; - int index; - diff d32[4]; - const int offset = (mi_row >> 1) * cm->mb_cols + (mi_col >> 1); - int is_larger_better = 0; - int use32x32 = 0; - unsigned int thr = cpi->source_var_thresh; - - memset(d32, 0, 4 * sizeof(diff)); - - for (i = 0; i < 4; i++) { - diff *d16[4]; - - for (j = 0; j < 4; j++) { - int b_mi_row = coord_lookup[i * 4 + j].row; - int b_mi_col = coord_lookup[i * 4 + j].col; - int boffset = b_mi_row / 2 * cm->mb_cols + b_mi_col / 2; - - d16[j] = cpi->source_diff_var + offset + boffset; - - index = b_mi_row * mis + b_mi_col; - mi_8x8[index] = mi_upper_left + index; - mi_8x8[index]->sb_type = BLOCK_16X16; - - // TODO(yunqingwang): If d16[j].var is very large, use 8x8 partition - // size to further improve quality. - } - - is_larger_better = (d16[0]->var < thr) && (d16[1]->var < thr) && - (d16[2]->var < thr) && (d16[3]->var < thr); - - // Use 32x32 partition - if (is_larger_better) { - use32x32 += 1; - - for (j = 0; j < 4; j++) { - d32[i].sse += d16[j]->sse; - d32[i].sum += d16[j]->sum; - } - - d32[i].var = - (unsigned int)(d32[i].sse - - (unsigned int)(((int64_t)d32[i].sum * d32[i].sum) >> - 10)); - - index = coord_lookup[i * 4].row * mis + coord_lookup[i * 4].col; - mi_8x8[index] = mi_upper_left + index; - mi_8x8[index]->sb_type = BLOCK_32X32; - } - } - - if (use32x32 == 4) { - thr <<= 1; - is_larger_better = (d32[0].var < thr) && (d32[1].var < thr) && - (d32[2].var < thr) && (d32[3].var < thr); - - // Use 64x64 partition - if (is_larger_better) { - mi_8x8[0] = mi_upper_left; - mi_8x8[0]->sb_type = BLOCK_64X64; - } - } - } else { // partial in-image SB64 - int bh = num_8x8_blocks_high_lookup[BLOCK_16X16]; - int bw = num_8x8_blocks_wide_lookup[BLOCK_16X16]; - set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, row8x8_remaining, - col8x8_remaining, BLOCK_16X16, mi_8x8); - } -} - static void update_state_rt(VP9_COMP *cpi, ThreadData *td, PICK_MODE_CONTEXT *ctx, int mi_row, int mi_col, int bsize) { @@ -2619,13 +2527,13 @@ static void encode_sb_rt(VP9_COMP *cpi, ThreadData *td, assert(partition == PARTITION_SPLIT); subsize = get_subsize(bsize, PARTITION_SPLIT); encode_sb_rt(cpi, td, tile, tp, mi_row, mi_col, output_enabled, subsize, - pc_tree->split[0]); + pc_tree->u.split[0]); encode_sb_rt(cpi, td, tile, tp, mi_row, mi_col + hbs, output_enabled, - subsize, pc_tree->split[1]); + subsize, pc_tree->u.split[1]); encode_sb_rt(cpi, td, tile, tp, mi_row + hbs, mi_col, output_enabled, - subsize, pc_tree->split[2]); + subsize, pc_tree->u.split[2]); encode_sb_rt(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs, - output_enabled, subsize, pc_tree->split[3]); + output_enabled, subsize, pc_tree->u.split[3]); break; } @@ -2730,10 +2638,10 @@ static void rd_use_partition(VP9_COMP *cpi, ThreadData *td, if (last_part_rdc.rate != INT_MAX && bsize >= BLOCK_8X8 && mi_row + (mi_step >> 1) < cm->mi_rows) { RD_COST tmp_rdc; - PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0]; + PICK_MODE_CONTEXT *hctx = &pc_tree->horizontal[0]; vp9_rd_cost_init(&tmp_rdc); - update_state(cpi, td, ctx, mi_row, mi_col, subsize, 0); - encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, ctx); + update_state(cpi, td, hctx, mi_row, mi_col, subsize, 0); + encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, hctx); pc_tree->horizontal[1].skip_ref_frame_mask = 0; rd_pick_sb_modes(cpi, tile_data, x, mi_row + (mi_step >> 1), mi_col, &tmp_rdc, subsize, &pc_tree->horizontal[1], INT_MAX, @@ -2754,10 +2662,10 @@ static void rd_use_partition(VP9_COMP *cpi, ThreadData *td, if (last_part_rdc.rate != INT_MAX && bsize >= BLOCK_8X8 && mi_col + (mi_step >> 1) < cm->mi_cols) { RD_COST tmp_rdc; - PICK_MODE_CONTEXT *ctx = &pc_tree->vertical[0]; + PICK_MODE_CONTEXT *vctx = &pc_tree->vertical[0]; vp9_rd_cost_init(&tmp_rdc); - update_state(cpi, td, ctx, mi_row, mi_col, subsize, 0); - encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, ctx); + update_state(cpi, td, vctx, mi_row, mi_col, subsize, 0); + encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, vctx); pc_tree->vertical[bsize > BLOCK_8X8].skip_ref_frame_mask = 0; rd_pick_sb_modes( cpi, tile_data, x, mi_row, mi_col + (mi_step >> 1), &tmp_rdc, @@ -2775,7 +2683,7 @@ static void rd_use_partition(VP9_COMP *cpi, ThreadData *td, assert(partition == PARTITION_SPLIT); if (bsize == BLOCK_8X8) { rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &last_part_rdc, - subsize, pc_tree->leaf_split[0], INT_MAX, INT64_MAX); + subsize, pc_tree->u.leaf_split[0], INT_MAX, INT64_MAX); break; } last_part_rdc.rate = 0; @@ -2793,7 +2701,7 @@ static void rd_use_partition(VP9_COMP *cpi, ThreadData *td, rd_use_partition(cpi, td, tile_data, mi_8x8 + jj * bss * mis + ii * bss, tp, mi_row + y_idx, mi_col + x_idx, subsize, &tmp_rdc.rate, &tmp_rdc.dist, i != 3, - pc_tree->split[i]); + pc_tree->u.split[i]); if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { vp9_rd_cost_reset(&last_part_rdc); break; @@ -2829,16 +2737,14 @@ static void rd_use_partition(VP9_COMP *cpi, ThreadData *td, int x_idx = (i & 1) * (mi_step >> 1); int y_idx = (i >> 1) * (mi_step >> 1); RD_COST tmp_rdc; - ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; - PARTITION_CONTEXT sl[8], sa[8]; if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) continue; save_context(x, mi_row, mi_col, a, l, sa, sl, bsize); - pc_tree->split[i]->partitioning = PARTITION_NONE; + pc_tree->u.split[i]->partitioning = PARTITION_NONE; rd_pick_sb_modes(cpi, tile_data, x, mi_row + y_idx, mi_col + x_idx, - &tmp_rdc, split_subsize, &pc_tree->split[i]->none, + &tmp_rdc, split_subsize, &pc_tree->u.split[i]->none, INT_MAX, INT64_MAX); restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize); @@ -2853,7 +2759,7 @@ static void rd_use_partition(VP9_COMP *cpi, ThreadData *td, if (i != 3) encode_sb(cpi, td, tile_info, tp, mi_row + y_idx, mi_col + x_idx, 0, - split_subsize, pc_tree->split[i]); + split_subsize, pc_tree->u.split[i]); pl = partition_plane_context(xd, mi_row + y_idx, mi_col + x_idx, split_subsize); @@ -2970,7 +2876,8 @@ static void rd_auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile, // NOTE: each call to get_sb_partition_size_range() uses the previous // passed in values for min and max as a starting point. // Find the min and max partition used in previous frame at this location - if (cm->frame_type != KEY_FRAME) { + if (cm->frame_type != KEY_FRAME && + (cm->width == cm->last_width && cm->height == cm->last_height)) { MODE_INFO **prev_mi = &cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col]; get_sb_partition_size_range(xd, prev_mi, &min_size, &max_size, bs_hist); @@ -3027,23 +2934,27 @@ static void set_partition_range(VP9_COMMON *cm, MACROBLOCKD *xd, int mi_row, int mi_width = num_8x8_blocks_wide_lookup[bsize]; int mi_height = num_8x8_blocks_high_lookup[bsize]; int idx, idy; - - MODE_INFO *mi; - const int idx_str = cm->mi_stride * mi_row + mi_col; - MODE_INFO **prev_mi = &cm->prev_mi_grid_visible[idx_str]; BLOCK_SIZE bs, min_size, max_size; min_size = BLOCK_64X64; max_size = BLOCK_4X4; - if (prev_mi) { - for (idy = 0; idy < mi_height; ++idy) { - for (idx = 0; idx < mi_width; ++idx) { - mi = prev_mi[idy * cm->mi_stride + idx]; - bs = mi ? mi->sb_type : bsize; - min_size = VPXMIN(min_size, bs); - max_size = VPXMAX(max_size, bs); - } + if (cm->width != cm->last_width || cm->height != cm->last_height) { + *min_bs = min_size; + *max_bs = max_size; + return; + } + + MODE_INFO *mi; + const int idx_str = cm->mi_stride * mi_row + mi_col; + MODE_INFO **prev_mi = &cm->prev_mi_grid_visible[idx_str]; + + for (idy = 0; idy < mi_height; ++idy) { + for (idx = 0; idx < mi_width; ++idx) { + mi = prev_mi[idy * cm->mi_stride + idx]; + bs = mi ? mi->sb_type : bsize; + min_size = VPXMIN(min_size, bs); + max_size = VPXMAX(max_size, bs); } } @@ -3141,8 +3052,6 @@ static int ml_pruning_partition(VP9_COMMON *const cm, MACROBLOCKD *const xd, abs(ctx->mic.mv[0].as_mv.col) + abs(ctx->mic.mv[0].as_mv.row); const int left_in_image = !!xd->left_mi; const int above_in_image = !!xd->above_mi; - MODE_INFO **prev_mi = - &cm->prev_mi_grid_visible[mi_col + cm->mi_stride * mi_row]; int above_par = 0; // above_partitioning int left_par = 0; // left_partitioning int last_par = 0; // last_partitioning @@ -3189,12 +3098,16 @@ static int ml_pruning_partition(VP9_COMMON *const cm, MACROBLOCKD *const xd, left_par = 1; } - if (prev_mi) { - context_size = prev_mi[0]->sb_type; - if (context_size < bsize) - last_par = 2; - else if (context_size == bsize) - last_par = 1; + if (cm->width == cm->last_width && cm->height == cm->last_height) { + MODE_INFO **prev_mi = + &cm->prev_mi_grid_visible[mi_col + cm->mi_stride * mi_row]; + if (prev_mi[0]) { + context_size = prev_mi[0]->sb_type; + if (context_size < bsize) + last_par = 2; + else if (context_size == bsize) + last_par = 1; + } } mean = &vp9_partition_feature_mean[offset]; @@ -3369,7 +3282,7 @@ static void ml_prune_rect_partition(VP9_COMP *const cpi, MACROBLOCK *const x, features[feature_index++] = VPXMIN(rd_ratio, 2.0f); for (i = 0; i < 4; ++i) { - const int64_t this_rd = pc_tree->split[i]->none.rdcost; + const int64_t this_rd = pc_tree->u.split[i]->none.rdcost; const int rd_valid = this_rd > 0 && this_rd < 1000000000; // Ratio between sub-block RD and whole block RD. features[feature_index++] = @@ -3413,7 +3326,8 @@ static void simple_motion_search(const VP9_COMP *const cpi, MACROBLOCK *const x, const VP9_COMMON *const cm = &cpi->common; MACROBLOCKD *const xd = &x->e_mbd; MODE_INFO *const mi = xd->mi[0]; - const YV12_BUFFER_CONFIG *const yv12 = get_ref_frame_buffer(cpi, ref); + YV12_BUFFER_CONFIG *yv12; + YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, ref); const int step_param = 1; const MvLimits tmp_mv_limits = x->mv_limits; const SEARCH_METHODS search_method = NSTEP; @@ -3421,13 +3335,23 @@ static void simple_motion_search(const VP9_COMP *const cpi, MACROBLOCK *const x, MV ref_mv_full = { ref_mv.row >> 3, ref_mv.col >> 3 }; MV best_mv = { 0, 0 }; int cost_list[5]; + struct buf_2d backup_pre[MAX_MB_PLANE] = { { 0, 0 } }; + + if (scaled_ref_frame) { + yv12 = scaled_ref_frame; + // As reported in b/311294795, the reference buffer pointer needs to be + // saved and restored after the search. Otherwise, it causes problems while + // the reference frame scaling happens. + for (int i = 0; i < MAX_MB_PLANE; i++) backup_pre[i] = xd->plane[i].pre[0]; + } else { + yv12 = get_ref_frame_buffer(cpi, ref); + } assert(yv12 != NULL); if (!yv12) return; - vp9_setup_pre_planes(xd, 0, yv12, mi_row, mi_col, - &cm->frame_refs[ref - 1].sf); + vp9_setup_pre_planes(xd, 0, yv12, mi_row, mi_col, NULL); mi->ref_frame[0] = ref; - mi->ref_frame[1] = NONE; + mi->ref_frame[1] = NO_REF_FRAME; mi->sb_type = bsize; vp9_set_mv_search_range(&x->mv_limits, &ref_mv); vp9_full_pixel_search(cpi, x, bsize, &ref_mv_full, step_param, search_method, @@ -3438,6 +3362,11 @@ static void simple_motion_search(const VP9_COMP *const cpi, MACROBLOCK *const x, x->mv_limits = tmp_mv_limits; mi->mv[0].as_mv = best_mv; + // Restore reference buffer pointer. + if (scaled_ref_frame) { + for (int i = 0; i < MAX_MB_PLANE; i++) xd->plane[i].pre[0] = backup_pre[i]; + } + set_ref_ptrs(cm, xd, mi->ref_frame[0], mi->ref_frame[1]); xd->plane[0].dst.buf = pred_buf; xd->plane[0].dst.stride = 64; @@ -3448,15 +3377,15 @@ static void simple_motion_search(const VP9_COMP *const cpi, MACROBLOCK *const x, // Features used: QP; spatial block size contexts; variance of prediction // residue after simple_motion_search. #define FEATURES 12 -static void ml_predict_var_rd_paritioning(const VP9_COMP *const cpi, - MACROBLOCK *const x, - PC_TREE *const pc_tree, - BLOCK_SIZE bsize, int mi_row, - int mi_col, int *none, int *split) { +static void ml_predict_var_rd_partitioning(const VP9_COMP *const cpi, + MACROBLOCK *const x, + PC_TREE *const pc_tree, + BLOCK_SIZE bsize, int mi_row, + int mi_col, int *none, int *split) { const VP9_COMMON *const cm = &cpi->common; const NN_CONFIG *nn_config = NULL; + const MACROBLOCKD *const xd = &x->e_mbd; #if CONFIG_VP9_HIGHBITDEPTH - MACROBLOCKD *xd = &x->e_mbd; DECLARE_ALIGNED(16, uint8_t, pred_buffer[64 * 64 * 2]); uint8_t *const pred_buf = (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ? (CONVERT_TO_BYTEPTR(pred_buffer)) @@ -3539,7 +3468,6 @@ static void ml_predict_var_rd_paritioning(const VP9_COMP *const cpi, const unsigned int var = cpi->fn_ptr[bsize].vf(src, src_stride, pred, pred_stride, &sse); const float factor = (var == 0) ? 1.0f : (1.0f / (float)var); - const MACROBLOCKD *const xd = &x->e_mbd; const int has_above = !!xd->above_mi; const int has_left = !!xd->left_mi; const BLOCK_SIZE above_bsize = has_above ? xd->above_mi->sb_type : bsize; @@ -3689,7 +3617,6 @@ static int get_rdmult_delta(VP9_COMP *cpi, BLOCK_SIZE bsize, int mi_row, int row, col; int dr = 0; - int count = 0; double r0, rk, beta; TplDepFrame *tpl_frame; @@ -3705,6 +3632,17 @@ static int get_rdmult_delta(VP9_COMP *cpi, BLOCK_SIZE bsize, int mi_row, if (cpi->twopass.gf_group.layer_depth[gf_group_index] > 1) return orig_rdmult; + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_QP) != 0 && + cpi->ext_ratectrl.funcs.get_encodeframe_decision != NULL) { + int sb_size = num_8x8_blocks_wide_lookup[BLOCK_64X64] * MI_SIZE; + int sb_stride = (cpi->common.width + sb_size - 1) / sb_size; + int sby = mi_row / 8; + int sbx = mi_col / 8; + return (int)((cpi->sb_mul_scale[sby * sb_stride + sbx] * orig_rdmult) / + 256); + } + for (row = mi_row; row < mi_row + mi_high; ++row) { for (col = mi_col; col < mi_col + mi_wide; ++col) { TplDepStats *this_stats = &tpl_stats[row * tpl_stride + col]; @@ -3713,8 +3651,6 @@ static int get_rdmult_delta(VP9_COMP *cpi, BLOCK_SIZE bsize, int mi_row, intra_cost += this_stats->intra_cost; mc_dep_cost += this_stats->mc_dep_cost; - - ++count; } } @@ -3725,225 +3661,13 @@ static int get_rdmult_delta(VP9_COMP *cpi, BLOCK_SIZE bsize, int mi_row, beta = r0 / rk; dr = vp9_get_adaptive_rdmult(cpi, beta); - dr = VPXMIN(dr, orig_rdmult * 3 / 2); - dr = VPXMAX(dr, orig_rdmult * 1 / 2); - + dr = clamp(dr, orig_rdmult * 1 / 2, orig_rdmult * 3 / 2); dr = VPXMAX(1, dr); return dr; } #endif // !CONFIG_REALTIME_ONLY -#if CONFIG_RATE_CTRL -static void assign_partition_info( - const int row_start_4x4, const int col_start_4x4, const int block_width_4x4, - const int block_height_4x4, const int num_unit_rows, - const int num_unit_cols, PARTITION_INFO *partition_info) { - int i, j; - for (i = 0; i < block_height_4x4; ++i) { - for (j = 0; j < block_width_4x4; ++j) { - const int row_4x4 = row_start_4x4 + i; - const int col_4x4 = col_start_4x4 + j; - const int unit_index = row_4x4 * num_unit_cols + col_4x4; - if (row_4x4 >= num_unit_rows || col_4x4 >= num_unit_cols) continue; - partition_info[unit_index].row = row_4x4 << 2; - partition_info[unit_index].column = col_4x4 << 2; - partition_info[unit_index].row_start = row_start_4x4 << 2; - partition_info[unit_index].column_start = col_start_4x4 << 2; - partition_info[unit_index].width = block_width_4x4 << 2; - partition_info[unit_index].height = block_height_4x4 << 2; - } - } -} - -static void assign_motion_vector_info(const int block_width_4x4, - const int block_height_4x4, - const int row_start_4x4, - const int col_start_4x4, - const int num_unit_rows, - const int num_unit_cols, MV *source_mv[2], - MV_REFERENCE_FRAME source_ref_frame[2], - MOTION_VECTOR_INFO *motion_vector_info) { - int i, j; - for (i = 0; i < block_height_4x4; ++i) { - for (j = 0; j < block_width_4x4; ++j) { - const int row_4x4 = row_start_4x4 + i; - const int col_4x4 = col_start_4x4 + j; - const int unit_index = row_4x4 * num_unit_cols + col_4x4; - if (row_4x4 >= num_unit_rows || col_4x4 >= num_unit_cols) continue; - if (source_ref_frame[1] == NONE) { - assert(source_mv[1]->row == 0 && source_mv[1]->col == 0); - } - motion_vector_info[unit_index].ref_frame[0] = source_ref_frame[0]; - motion_vector_info[unit_index].ref_frame[1] = source_ref_frame[1]; - motion_vector_info[unit_index].mv[0].as_mv.row = source_mv[0]->row; - motion_vector_info[unit_index].mv[0].as_mv.col = source_mv[0]->col; - motion_vector_info[unit_index].mv[1].as_mv.row = source_mv[1]->row; - motion_vector_info[unit_index].mv[1].as_mv.col = source_mv[1]->col; - } - } -} - -static void store_superblock_info( - const PC_TREE *const pc_tree, MODE_INFO **mi_grid_visible, - const int mi_stride, const int square_size_4x4, const int num_unit_rows, - const int num_unit_cols, const int row_start_4x4, const int col_start_4x4, - PARTITION_INFO *partition_info, MOTION_VECTOR_INFO *motion_vector_info) { - const int subblock_square_size_4x4 = square_size_4x4 >> 1; - if (row_start_4x4 >= num_unit_rows || col_start_4x4 >= num_unit_cols) return; - assert(pc_tree->partitioning != PARTITION_INVALID); - // End node, no split. - if (pc_tree->partitioning == PARTITION_NONE || - pc_tree->partitioning == PARTITION_HORZ || - pc_tree->partitioning == PARTITION_VERT || square_size_4x4 == 1) { - const int mi_row = row_start_4x4 >> 1; - const int mi_col = col_start_4x4 >> 1; - const int mi_idx = mi_stride * mi_row + mi_col; - MODE_INFO **mi = mi_grid_visible + mi_idx; - MV *source_mv[2]; - MV_REFERENCE_FRAME source_ref_frame[2]; - - // partition info - const int block_width_4x4 = (pc_tree->partitioning == PARTITION_VERT) - ? square_size_4x4 >> 1 - : square_size_4x4; - const int block_height_4x4 = (pc_tree->partitioning == PARTITION_HORZ) - ? square_size_4x4 >> 1 - : square_size_4x4; - assign_partition_info(row_start_4x4, col_start_4x4, block_width_4x4, - block_height_4x4, num_unit_rows, num_unit_cols, - partition_info); - if (pc_tree->partitioning == PARTITION_VERT) { - assign_partition_info(row_start_4x4, col_start_4x4 + block_width_4x4, - block_width_4x4, block_height_4x4, num_unit_rows, - num_unit_cols, partition_info); - } else if (pc_tree->partitioning == PARTITION_HORZ) { - assign_partition_info(row_start_4x4 + block_height_4x4, col_start_4x4, - block_width_4x4, block_height_4x4, num_unit_rows, - num_unit_cols, partition_info); - } - - // motion vector info - if (pc_tree->partitioning == PARTITION_HORZ) { - int is_valid_second_rectangle = 0; - assert(square_size_4x4 > 1); - // First rectangle. - source_ref_frame[0] = mi[0]->ref_frame[0]; - source_ref_frame[1] = mi[0]->ref_frame[1]; - source_mv[0] = &mi[0]->mv[0].as_mv; - source_mv[1] = &mi[0]->mv[1].as_mv; - assign_motion_vector_info(block_width_4x4, block_height_4x4, - row_start_4x4, col_start_4x4, num_unit_rows, - num_unit_cols, source_mv, source_ref_frame, - motion_vector_info); - // Second rectangle. - if (square_size_4x4 == 2) { - is_valid_second_rectangle = 1; - source_ref_frame[0] = mi[0]->ref_frame[0]; - source_ref_frame[1] = mi[0]->ref_frame[1]; - source_mv[0] = &mi[0]->bmi[2].as_mv[0].as_mv; - source_mv[1] = &mi[0]->bmi[2].as_mv[1].as_mv; - } else { - const int mi_row_2 = mi_row + (block_height_4x4 >> 1); - const int mi_col_2 = mi_col; - if (mi_row_2 * 2 < num_unit_rows && mi_col_2 * 2 < num_unit_cols) { - const int mi_idx_2 = mi_stride * mi_row_2 + mi_col_2; - is_valid_second_rectangle = 1; - mi = mi_grid_visible + mi_idx_2; - source_ref_frame[0] = mi[0]->ref_frame[0]; - source_ref_frame[1] = mi[0]->ref_frame[1]; - source_mv[0] = &mi[0]->mv[0].as_mv; - source_mv[1] = &mi[0]->mv[1].as_mv; - } - } - if (is_valid_second_rectangle) { - assign_motion_vector_info( - block_width_4x4, block_height_4x4, row_start_4x4 + block_height_4x4, - col_start_4x4, num_unit_rows, num_unit_cols, source_mv, - source_ref_frame, motion_vector_info); - } - } else if (pc_tree->partitioning == PARTITION_VERT) { - int is_valid_second_rectangle = 0; - assert(square_size_4x4 > 1); - // First rectangle. - source_ref_frame[0] = mi[0]->ref_frame[0]; - source_ref_frame[1] = mi[0]->ref_frame[1]; - source_mv[0] = &mi[0]->mv[0].as_mv; - source_mv[1] = &mi[0]->mv[1].as_mv; - assign_motion_vector_info(block_width_4x4, block_height_4x4, - row_start_4x4, col_start_4x4, num_unit_rows, - num_unit_cols, source_mv, source_ref_frame, - motion_vector_info); - // Second rectangle. - if (square_size_4x4 == 2) { - is_valid_second_rectangle = 1; - source_ref_frame[0] = mi[0]->ref_frame[0]; - source_ref_frame[1] = mi[0]->ref_frame[1]; - source_mv[0] = &mi[0]->bmi[1].as_mv[0].as_mv; - source_mv[1] = &mi[0]->bmi[1].as_mv[1].as_mv; - } else { - const int mi_row_2 = mi_row; - const int mi_col_2 = mi_col + (block_width_4x4 >> 1); - if (mi_row_2 * 2 < num_unit_rows && mi_col_2 * 2 < num_unit_cols) { - const int mi_idx_2 = mi_stride * mi_row_2 + mi_col_2; - is_valid_second_rectangle = 1; - mi = mi_grid_visible + mi_idx_2; - source_ref_frame[0] = mi[0]->ref_frame[0]; - source_ref_frame[1] = mi[0]->ref_frame[1]; - source_mv[0] = &mi[0]->mv[0].as_mv; - source_mv[1] = &mi[0]->mv[1].as_mv; - } - } - if (is_valid_second_rectangle) { - assign_motion_vector_info( - block_width_4x4, block_height_4x4, row_start_4x4, - col_start_4x4 + block_width_4x4, num_unit_rows, num_unit_cols, - source_mv, source_ref_frame, motion_vector_info); - } - } else { - assert(pc_tree->partitioning == PARTITION_NONE || square_size_4x4 == 1); - source_ref_frame[0] = mi[0]->ref_frame[0]; - source_ref_frame[1] = mi[0]->ref_frame[1]; - if (square_size_4x4 == 1) { - const int sub8x8_row = row_start_4x4 % 2; - const int sub8x8_col = col_start_4x4 % 2; - const int sub8x8_idx = sub8x8_row * 2 + sub8x8_col; - source_mv[0] = &mi[0]->bmi[sub8x8_idx].as_mv[0].as_mv; - source_mv[1] = &mi[0]->bmi[sub8x8_idx].as_mv[1].as_mv; - } else { - source_mv[0] = &mi[0]->mv[0].as_mv; - source_mv[1] = &mi[0]->mv[1].as_mv; - } - assign_motion_vector_info(block_width_4x4, block_height_4x4, - row_start_4x4, col_start_4x4, num_unit_rows, - num_unit_cols, source_mv, source_ref_frame, - motion_vector_info); - } - - return; - } - // recursively traverse partition tree when partition is split. - assert(pc_tree->partitioning == PARTITION_SPLIT); - store_superblock_info(pc_tree->split[0], mi_grid_visible, mi_stride, - subblock_square_size_4x4, num_unit_rows, num_unit_cols, - row_start_4x4, col_start_4x4, partition_info, - motion_vector_info); - store_superblock_info(pc_tree->split[1], mi_grid_visible, mi_stride, - subblock_square_size_4x4, num_unit_rows, num_unit_cols, - row_start_4x4, col_start_4x4 + subblock_square_size_4x4, - partition_info, motion_vector_info); - store_superblock_info(pc_tree->split[2], mi_grid_visible, mi_stride, - subblock_square_size_4x4, num_unit_rows, num_unit_cols, - row_start_4x4 + subblock_square_size_4x4, col_start_4x4, - partition_info, motion_vector_info); - store_superblock_info(pc_tree->split[3], mi_grid_visible, mi_stride, - subblock_square_size_4x4, num_unit_rows, num_unit_cols, - row_start_4x4 + subblock_square_size_4x4, - col_start_4x4 + subblock_square_size_4x4, - partition_info, motion_vector_info); -} -#endif // CONFIG_RATE_CTRL - #if !CONFIG_REALTIME_ONLY // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are // unlikely to be selected depending on previous rate-distortion optimization @@ -4074,13 +3798,21 @@ static int rd_pick_partition(VP9_COMP *cpi, ThreadData *td, mi_row + num_8x8_blocks_high_lookup[bsize] <= cm->mi_rows && mi_col + num_8x8_blocks_wide_lookup[bsize] <= cm->mi_cols; if (do_rd_ml_partition_var_pruning) { - ml_predict_var_rd_paritioning(cpi, x, pc_tree, bsize, mi_row, mi_col, - &partition_none_allowed, &do_split); + ml_predict_var_rd_partitioning(cpi, x, pc_tree, bsize, mi_row, mi_col, + &partition_none_allowed, &do_split); + // ml_predict_var_rd_partitioning() may pruune out either + // partition_none_allowed or do_split, but we should keep the + // partition_none_allowed for 8x8 blocks unless disable_split_mask is + // off (0). + if (bsize == BLOCK_8X8 && cpi->sf.disable_split_mask && + partition_none_allowed == 0) { + partition_none_allowed = 1; + } } else { vp9_zero(pc_tree->mv); } if (bsize > BLOCK_8X8) { // Store MV result as reference for subblocks. - for (i = 0; i < 4; ++i) pc_tree->split[i]->mv = pc_tree->mv; + for (i = 0; i < 4; ++i) pc_tree->u.split[i]->mv = pc_tree->mv; } } @@ -4165,25 +3897,25 @@ static int rd_pick_partition(VP9_COMP *cpi, ThreadData *td, // PARTITION_SPLIT // TODO(jingning): use the motion vectors given by the above search as // the starting point of motion search in the following partition type check. - pc_tree->split[0]->none.rdcost = 0; - pc_tree->split[1]->none.rdcost = 0; - pc_tree->split[2]->none.rdcost = 0; - pc_tree->split[3]->none.rdcost = 0; + pc_tree->u.split[0]->none.rdcost = 0; + pc_tree->u.split[1]->none.rdcost = 0; + pc_tree->u.split[2]->none.rdcost = 0; + pc_tree->u.split[3]->none.rdcost = 0; if (do_split || must_split) { subsize = get_subsize(bsize, PARTITION_SPLIT); load_pred_mv(x, ctx); if (bsize == BLOCK_8X8) { i = 4; if (cpi->sf.adaptive_pred_interp_filter && partition_none_allowed) - pc_tree->leaf_split[0]->pred_interp_filter = pred_interp_filter; + pc_tree->u.leaf_split[0]->pred_interp_filter = pred_interp_filter; rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, subsize, - pc_tree->leaf_split[0], best_rdc.rate, best_rdc.dist); + pc_tree->u.leaf_split[0], best_rdc.rate, best_rdc.dist); if (sum_rdc.rate == INT_MAX) { sum_rdc.rdcost = INT64_MAX; } else { if (cpi->sf.prune_ref_frame_for_rect_partitions) { - const int ref1 = pc_tree->leaf_split[0]->mic.ref_frame[0]; - const int ref2 = pc_tree->leaf_split[0]->mic.ref_frame[1]; + const int ref1 = pc_tree->u.leaf_split[0]->mic.ref_frame[0]; + const int ref2 = pc_tree->u.leaf_split[0]->mic.ref_frame[1]; for (i = 0; i < 4; ++i) { ref_frames_used[i] |= (1 << ref1); if (ref2 > 0) ref_frames_used[i] |= (1 << ref2); @@ -4216,21 +3948,21 @@ static int rd_pick_partition(VP9_COMP *cpi, ThreadData *td, if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) continue; - pc_tree->split[i]->index = i; + pc_tree->u.split[i]->index = i; if (cpi->sf.prune_ref_frame_for_rect_partitions) - pc_tree->split[i]->none.rate = INT_MAX; + pc_tree->u.split[i]->none.rate = INT_MAX; found_best_rd = rd_pick_partition( cpi, td, tile_data, tp, mi_row + y_idx, mi_col + x_idx, subsize, - &this_rdc, best_rdc_split, pc_tree->split[i]); + &this_rdc, best_rdc_split, pc_tree->u.split[i]); if (found_best_rd == 0) { sum_rdc.rdcost = INT64_MAX; break; } else { if (cpi->sf.prune_ref_frame_for_rect_partitions && - pc_tree->split[i]->none.rate != INT_MAX) { - const int ref1 = pc_tree->split[i]->none.mic.ref_frame[0]; - const int ref2 = pc_tree->split[i]->none.mic.ref_frame[1]; + pc_tree->u.split[i]->none.rate != INT_MAX) { + const int ref1 = pc_tree->u.split[i]->none.mic.ref_frame[0]; + const int ref2 = pc_tree->u.split[i]->none.mic.ref_frame[1]; ref_frames_used[i] |= (1 << ref1); if (ref2 > 0) ref_frames_used[i] |= (1 << ref2); } @@ -4324,9 +4056,9 @@ static int rd_pick_partition(VP9_COMP *cpi, ThreadData *td, if (sum_rdc.rdcost < best_rdc.rdcost && mi_row + mi_step < cm->mi_rows && bsize > BLOCK_8X8) { - PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0]; - update_state(cpi, td, ctx, mi_row, mi_col, subsize, 0); - encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, ctx); + PICK_MODE_CONTEXT *hctx = &pc_tree->horizontal[0]; + update_state(cpi, td, hctx, mi_row, mi_col, subsize, 0); + encode_superblock(cpi, td, tp, 0, mi_row, mi_col, subsize, hctx); if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && partition_none_allowed) pc_tree->horizontal[1].pred_interp_filter = pred_interp_filter; @@ -4401,27 +4133,31 @@ static int rd_pick_partition(VP9_COMP *cpi, ThreadData *td, restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize); } + if (bsize == BLOCK_64X64 && best_rdc.rdcost == INT64_MAX) { + vp9_rd_cost_reset(&this_rdc); + rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &this_rdc, BLOCK_64X64, + ctx, INT_MAX, INT64_MAX); + ctx->rdcost = this_rdc.rdcost; + vp9_rd_cost_update(partition_mul, x->rddiv, &this_rdc); + if (this_rdc.rdcost < best_rdc.rdcost) { + best_rdc = this_rdc; + should_encode_sb = 1; + pc_tree->partitioning = PARTITION_NONE; + } + } + *rd_cost = best_rdc; if (should_encode_sb && pc_tree->index != 3) { int output_enabled = (bsize == BLOCK_64X64); +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, encode_sb_time); +#endif encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, bsize, pc_tree); -#if CONFIG_RATE_CTRL - if (oxcf->use_simple_encode_api) { - // Store partition, motion vector of the superblock. - if (output_enabled) { - const int num_unit_rows = - get_num_unit_4x4(cpi->frame_info.frame_height); - const int num_unit_cols = get_num_unit_4x4(cpi->frame_info.frame_width); - store_superblock_info(pc_tree, cm->mi_grid_visible, cm->mi_stride, - num_4x4_blocks_wide_lookup[BLOCK_64X64], - num_unit_rows, num_unit_cols, mi_row << 1, - mi_col << 1, cpi->partition_info, - cpi->motion_vector_info); - } - } -#endif // CONFIG_RATE_CTRL +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, encode_sb_time); +#endif } if (bsize == BLOCK_64X64) { @@ -4533,8 +4269,15 @@ static void encode_rd_sb_row(VP9_COMP *cpi, ThreadData *td, &x->min_partition_size, &x->max_partition_size); } td->pc_root->none.rdcost = 0; + +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, rd_pick_partition_time); +#endif rd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, BLOCK_64X64, &dummy_rdc, dummy_rdc, td->pc_root); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, rd_pick_partition_time); +#endif } (*(cpi->row_mt_sync_write_ptr))(&tile_data->row_mt_sync, sb_row, sb_col_in_tile, num_sb_cols); @@ -4666,6 +4409,8 @@ static void nonrd_pick_sb_modes(VP9_COMP *cpi, TileDataEnc *tile_data, set_segment_index(cpi, x, mi_row, mi_col, bsize, 0); + x->skip_recode = 0; + mi = xd->mi[0]; mi->sb_type = bsize; @@ -4759,13 +4504,13 @@ static void fill_mode_info_sb(VP9_COMMON *cm, MACROBLOCK *x, int mi_row, } break; case PARTITION_SPLIT: { - fill_mode_info_sb(cm, x, mi_row, mi_col, subsize, pc_tree->split[0]); + fill_mode_info_sb(cm, x, mi_row, mi_col, subsize, pc_tree->u.split[0]); fill_mode_info_sb(cm, x, mi_row, mi_col + hbs, subsize, - pc_tree->split[1]); + pc_tree->u.split[1]); fill_mode_info_sb(cm, x, mi_row + hbs, mi_col, subsize, - pc_tree->split[2]); + pc_tree->u.split[2]); fill_mode_info_sb(cm, x, mi_row + hbs, mi_col + hbs, subsize, - pc_tree->split[3]); + pc_tree->u.split[3]); break; } default: break; @@ -4783,15 +4528,16 @@ static void pred_pixel_ready_reset(PC_TREE *pc_tree, BLOCK_SIZE bsize) { if (bsize > BLOCK_8X8) { BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_SPLIT); int i; - for (i = 0; i < 4; ++i) pred_pixel_ready_reset(pc_tree->split[i], subsize); + for (i = 0; i < 4; ++i) + pred_pixel_ready_reset(pc_tree->u.split[i], subsize); } } #define FEATURES 6 #define LABELS 2 -static int ml_predict_var_paritioning(VP9_COMP *cpi, MACROBLOCK *x, - BLOCK_SIZE bsize, int mi_row, - int mi_col) { +static int ml_predict_var_partitioning(VP9_COMP *cpi, MACROBLOCK *x, + BLOCK_SIZE bsize, int mi_row, + int mi_col) { VP9_COMMON *const cm = &cpi->common; const NN_CONFIG *nn_config = NULL; @@ -4923,7 +4669,7 @@ static void nonrd_pick_partition(VP9_COMP *cpi, ThreadData *td, if (partition_none_allowed || do_split) do_rect = 0; if (partition_none_allowed && do_split) { const int ml_predicted_partition = - ml_predict_var_paritioning(cpi, x, bsize, mi_row, mi_col); + ml_predict_var_partitioning(cpi, x, bsize, mi_row, mi_col); if (ml_predicted_partition == PARTITION_NONE) do_split = 0; if (ml_predicted_partition == PARTITION_SPLIT) partition_none_allowed = 0; } @@ -4984,9 +4730,9 @@ static void nonrd_pick_partition(VP9_COMP *cpi, ThreadData *td, if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) continue; load_pred_mv(x, ctx); - nonrd_pick_partition(cpi, td, tile_data, tp, mi_row + y_idx, - mi_col + x_idx, subsize, &this_rdc, 0, - best_rdc.rdcost - sum_rdc.rdcost, pc_tree->split[i]); + nonrd_pick_partition( + cpi, td, tile_data, tp, mi_row + y_idx, mi_col + x_idx, subsize, + &this_rdc, 0, best_rdc.rdcost - sum_rdc.rdcost, pc_tree->u.split[i]); if (this_rdc.rate == INT_MAX) { vp9_rd_cost_reset(&sum_rdc); @@ -5219,10 +4965,10 @@ static void nonrd_select_partition(VP9_COMP *cpi, ThreadData *td, subsize = get_subsize(bsize, PARTITION_SPLIT); nonrd_select_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, subsize, output_enabled, rd_cost, - pc_tree->split[0]); + pc_tree->u.split[0]); nonrd_select_partition(cpi, td, tile_data, mi + hbs, tp, mi_row, mi_col + hbs, subsize, output_enabled, &this_rdc, - pc_tree->split[1]); + pc_tree->u.split[1]); if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { rd_cost->rate += this_rdc.rate; @@ -5230,7 +4976,7 @@ static void nonrd_select_partition(VP9_COMP *cpi, ThreadData *td, } nonrd_select_partition(cpi, td, tile_data, mi + hbs * mis, tp, mi_row + hbs, mi_col, subsize, output_enabled, - &this_rdc, pc_tree->split[2]); + &this_rdc, pc_tree->u.split[2]); if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { rd_cost->rate += this_rdc.rate; @@ -5238,7 +4984,7 @@ static void nonrd_select_partition(VP9_COMP *cpi, ThreadData *td, } nonrd_select_partition(cpi, td, tile_data, mi + hbs * mis + hbs, tp, mi_row + hbs, mi_col + hbs, subsize, - output_enabled, &this_rdc, pc_tree->split[3]); + output_enabled, &this_rdc, pc_tree->u.split[3]); if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { rd_cost->rate += this_rdc.rate; @@ -5338,21 +5084,21 @@ static void nonrd_use_partition(VP9_COMP *cpi, ThreadData *td, subsize = get_subsize(bsize, PARTITION_SPLIT); if (bsize == BLOCK_8X8) { nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost, - subsize, pc_tree->leaf_split[0]); + subsize, pc_tree->u.leaf_split[0]); encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, - subsize, pc_tree->leaf_split[0]); + subsize, pc_tree->u.leaf_split[0]); } else { nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, subsize, - output_enabled, dummy_cost, pc_tree->split[0]); + output_enabled, dummy_cost, pc_tree->u.split[0]); nonrd_use_partition(cpi, td, tile_data, mi + hbs, tp, mi_row, mi_col + hbs, subsize, output_enabled, dummy_cost, - pc_tree->split[1]); + pc_tree->u.split[1]); nonrd_use_partition(cpi, td, tile_data, mi + hbs * mis, tp, mi_row + hbs, mi_col, subsize, output_enabled, - dummy_cost, pc_tree->split[2]); + dummy_cost, pc_tree->u.split[2]); nonrd_use_partition(cpi, td, tile_data, mi + hbs * mis + hbs, tp, mi_row + hbs, mi_col + hbs, subsize, output_enabled, - dummy_cost, pc_tree->split[3]); + dummy_cost, pc_tree->u.split[3]); } break; } @@ -5365,7 +5111,8 @@ static void nonrd_use_partition(VP9_COMP *cpi, ThreadData *td, static void get_estimated_pred(VP9_COMP *cpi, const TileInfo *const tile, MACROBLOCK *x, int mi_row, int mi_col) { VP9_COMMON *const cm = &cpi->common; - const int is_key_frame = frame_is_intra_only(cm); + const int is_key_frame = is_key_frame_for_partition(cpi) || + !(cpi->ref_frame_flags & VP9_LAST_FLAG); MACROBLOCKD *xd = &x->e_mbd; set_offsets(cpi, tile, x, mi_row, mi_col, BLOCK_64X64); @@ -5381,7 +5128,7 @@ static void get_estimated_pred(VP9_COMP *cpi, const TileInfo *const tile, assert(yv12 != NULL); - if (!(is_one_pass_cbr_svc(cpi) && cpi->svc.spatial_layer_id) || + if (!(is_one_pass_svc(cpi) && cpi->svc.spatial_layer_id) || cpi->svc.use_gf_temporal_ref_current_layer) { // For now, GOLDEN will not be used for non-zero spatial layers, since // it may not be a temporal reference. @@ -5412,7 +5159,7 @@ static void get_estimated_pred(VP9_COMP *cpi, const TileInfo *const tile, &cm->frame_refs[LAST_FRAME - 1].sf); mi->ref_frame[0] = LAST_FRAME; } - mi->ref_frame[1] = NONE; + mi->ref_frame[1] = NO_REF_FRAME; mi->sb_type = BLOCK_64X64; mi->mv[0].as_int = 0; mi->interp_filter = BILINEAR; @@ -5581,11 +5328,6 @@ static void encode_nonrd_sb_row(VP9_COMP *cpi, ThreadData *td, BLOCK_64X64, &dummy_rdc, 1, INT64_MAX, td->pc_root); break; - case SOURCE_VAR_BASED_PARTITION: - set_source_var_based_partition(cpi, tile_info, x, mi, mi_row, mi_col); - nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, - BLOCK_64X64, 1, &dummy_rdc, td->pc_root); - break; case FIXED_PARTITION: if (!seg_skip) bsize = sf->always_this_block_size; set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize); @@ -5602,7 +5344,7 @@ static void encode_nonrd_sb_row(VP9_COMP *cpi, ThreadData *td, if ((cpi->oxcf.rc_mode == VPX_VBR && cpi->rc.high_source_sad && cpi->oxcf.speed < 6 && !frame_is_intra_only(cm) && (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) { - // Use lower max_partition_size for low resoultions. + // Use lower max_partition_size for low resolutions. if (cm->width <= 352 && cm->height <= 288) x->max_partition_size = BLOCK_32X32; else @@ -5644,128 +5386,6 @@ static void encode_nonrd_sb_row(VP9_COMP *cpi, ThreadData *td, } // end RTC play code -static INLINE uint32_t variance(const diff *const d) { - return d->sse - (uint32_t)(((int64_t)d->sum * d->sum) >> 8); -} - -#if CONFIG_VP9_HIGHBITDEPTH -static INLINE uint32_t variance_highbd(diff *const d) { - const int64_t var = (int64_t)d->sse - (((int64_t)d->sum * d->sum) >> 8); - return (var >= 0) ? (uint32_t)var : 0; -} -#endif // CONFIG_VP9_HIGHBITDEPTH - -static int set_var_thresh_from_histogram(VP9_COMP *cpi) { - const SPEED_FEATURES *const sf = &cpi->sf; - const VP9_COMMON *const cm = &cpi->common; - - const uint8_t *src = cpi->Source->y_buffer; - const uint8_t *last_src = cpi->Last_Source->y_buffer; - const int src_stride = cpi->Source->y_stride; - const int last_stride = cpi->Last_Source->y_stride; - - // Pick cutoff threshold - const int cutoff = (VPXMIN(cm->width, cm->height) >= 720) - ? (cm->MBs * VAR_HIST_LARGE_CUT_OFF / 100) - : (cm->MBs * VAR_HIST_SMALL_CUT_OFF / 100); - DECLARE_ALIGNED(16, int, hist[VAR_HIST_BINS]); - diff *var16 = cpi->source_diff_var; - - int sum = 0; - int i, j; - - memset(hist, 0, VAR_HIST_BINS * sizeof(hist[0])); - - for (i = 0; i < cm->mb_rows; i++) { - for (j = 0; j < cm->mb_cols; j++) { -#if CONFIG_VP9_HIGHBITDEPTH - if (cm->use_highbitdepth) { - switch (cm->bit_depth) { - case VPX_BITS_8: - vpx_highbd_8_get16x16var(src, src_stride, last_src, last_stride, - &var16->sse, &var16->sum); - var16->var = variance(var16); - break; - case VPX_BITS_10: - vpx_highbd_10_get16x16var(src, src_stride, last_src, last_stride, - &var16->sse, &var16->sum); - var16->var = variance_highbd(var16); - break; - default: - assert(cm->bit_depth == VPX_BITS_12); - vpx_highbd_12_get16x16var(src, src_stride, last_src, last_stride, - &var16->sse, &var16->sum); - var16->var = variance_highbd(var16); - break; - } - } else { - vpx_get16x16var(src, src_stride, last_src, last_stride, &var16->sse, - &var16->sum); - var16->var = variance(var16); - } -#else - vpx_get16x16var(src, src_stride, last_src, last_stride, &var16->sse, - &var16->sum); - var16->var = variance(var16); -#endif // CONFIG_VP9_HIGHBITDEPTH - - if (var16->var >= VAR_HIST_MAX_BG_VAR) - hist[VAR_HIST_BINS - 1]++; - else - hist[var16->var / VAR_HIST_FACTOR]++; - - src += 16; - last_src += 16; - var16++; - } - - src = src - cm->mb_cols * 16 + 16 * src_stride; - last_src = last_src - cm->mb_cols * 16 + 16 * last_stride; - } - - cpi->source_var_thresh = 0; - - if (hist[VAR_HIST_BINS - 1] < cutoff) { - for (i = 0; i < VAR_HIST_BINS - 1; i++) { - sum += hist[i]; - - if (sum > cutoff) { - cpi->source_var_thresh = (i + 1) * VAR_HIST_FACTOR; - return 0; - } - } - } - - return sf->search_type_check_frequency; -} - -static void source_var_based_partition_search_method(VP9_COMP *cpi) { - VP9_COMMON *const cm = &cpi->common; - SPEED_FEATURES *const sf = &cpi->sf; - - if (cm->frame_type == KEY_FRAME) { - // For key frame, use SEARCH_PARTITION. - sf->partition_search_type = SEARCH_PARTITION; - } else if (cm->intra_only) { - sf->partition_search_type = FIXED_PARTITION; - } else { - if (cm->last_width != cm->width || cm->last_height != cm->height) { - if (cpi->source_diff_var) vpx_free(cpi->source_diff_var); - - CHECK_MEM_ERROR(cm, cpi->source_diff_var, - vpx_calloc(cm->MBs, sizeof(diff))); - } - - if (!cpi->frames_till_next_var_check) - cpi->frames_till_next_var_check = set_var_thresh_from_histogram(cpi); - - if (cpi->frames_till_next_var_check > 0) { - sf->partition_search_type = FIXED_PARTITION; - cpi->frames_till_next_var_check--; - } - } -} - static int get_skip_encode_frame(const VP9_COMMON *cm, ThreadData *const td) { unsigned int intra_count = 0, inter_count = 0; int j; @@ -5786,13 +5406,18 @@ void vp9_init_tile_data(VP9_COMP *cpi) { int tile_col, tile_row; TOKENEXTRA *pre_tok = cpi->tile_tok[0][0]; TOKENLIST *tplist = cpi->tplist[0][0]; - int tile_tok = 0; + int64_t tile_tok = 0; int tplist_count = 0; if (cpi->tile_data == NULL || cpi->allocated_tiles < tile_cols * tile_rows) { - if (cpi->tile_data != NULL) vpx_free(cpi->tile_data); + if (cpi->tile_data != NULL) { + // Free the row mt memory in cpi->tile_data first. + vp9_row_mt_mem_dealloc(cpi); + vpx_free(cpi->tile_data); + } + cpi->allocated_tiles = 0; CHECK_MEM_ERROR( - cm, cpi->tile_data, + &cm->error, cpi->tile_data, vpx_malloc(tile_cols * tile_rows * sizeof(*cpi->tile_data))); cpi->allocated_tiles = tile_cols * tile_rows; @@ -5801,20 +5426,15 @@ void vp9_init_tile_data(VP9_COMP *cpi) { TileDataEnc *tile_data = &cpi->tile_data[tile_row * tile_cols + tile_col]; int i, j; + const MV zero_mv = { 0, 0 }; for (i = 0; i < BLOCK_SIZES; ++i) { for (j = 0; j < MAX_MODES; ++j) { tile_data->thresh_freq_fact[i][j] = RD_THRESH_INIT_FACT; -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - tile_data->thresh_freq_fact_prev[i][j] = RD_THRESH_INIT_FACT; - } -#endif // CONFIG_RATE_CTRL -#if CONFIG_CONSISTENT_RECODE tile_data->thresh_freq_fact_prev[i][j] = RD_THRESH_INIT_FACT; -#endif // CONFIG_CONSISTENT_RECODE tile_data->mode_map[i][j] = j; } } + tile_data->firstpass_top_mv = zero_mv; #if CONFIG_MULTITHREAD tile_data->row_base_thresh_freq_fact = NULL; #endif @@ -5825,9 +5445,9 @@ void vp9_init_tile_data(VP9_COMP *cpi) { for (tile_col = 0; tile_col < tile_cols; ++tile_col) { TileDataEnc *this_tile = &cpi->tile_data[tile_row * tile_cols + tile_col]; TileInfo *tile_info = &this_tile->tile_info; - if (cpi->sf.adaptive_rd_thresh_row_mt && - this_tile->row_base_thresh_freq_fact == NULL) + if (cpi->sf.adaptive_rd_thresh_row_mt) { vp9_row_mt_alloc_rd_thresh(cpi, this_tile); + } vp9_tile_init(tile_info, cm, tile_row, tile_col); cpi->tile_tok[tile_row][tile_col] = pre_tok + tile_tok; @@ -6031,9 +5651,7 @@ static void encode_frame_internal(VP9_COMP *cpi) { x->fwd_txfm4x4 = xd->lossless ? vp9_fwht4x4 : vpx_fdct4x4; #endif // CONFIG_VP9_HIGHBITDEPTH x->inv_txfm_add = xd->lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; -#if CONFIG_CONSISTENT_RECODE x->optimize = sf->optimize_coefficients == 1 && cpi->oxcf.pass != 1; -#endif if (xd->lossless) x->optimize = 0; x->sharpness = cpi->oxcf.sharpness; x->adjust_rdmult_by_segment = (cpi->oxcf.aq_mode == VARIANCE_AQ); @@ -6075,9 +5693,6 @@ static void encode_frame_internal(VP9_COMP *cpi) { !(cpi->oxcf.lag_in_frames > 0 && cpi->oxcf.rc_mode == VPX_VBR) && !cpi->use_svc) cpi->ref_frame_flags &= (~VP9_GOLD_FLAG); - - if (sf->partition_search_type == SOURCE_VAR_BASED_PARTITION) - source_var_based_partition_search_method(cpi); } else if (gf_group_index && gf_group_index < MAX_ARF_GOP_SIZE && cpi->sf.enable_tpl_model) { TplDepFrame *tpl_frame = &cpi->tpl_stats[cpi->twopass.gf_group.index]; @@ -6102,12 +5717,23 @@ static void encode_frame_internal(VP9_COMP *cpi) { cpi->rd.r0 = (double)intra_cost_base / mc_dep_cost_base; } + for (MV_REFERENCE_FRAME ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; + ++ref_frame) { + if (cpi->ref_frame_flags & ref_frame_to_flag(ref_frame)) { + if (cm->frame_refs[ref_frame - 1].sf.x_scale_fp == REF_INVALID_SCALE || + cm->frame_refs[ref_frame - 1].sf.y_scale_fp == REF_INVALID_SCALE) + cpi->ref_frame_flags &= ~ref_frame_to_flag(ref_frame); + } + } + // Frame segmentation if (cpi->oxcf.aq_mode == PERCEPTUAL_AQ) build_kmeans_segmentation(cpi); { +#if CONFIG_INTERNAL_STATS struct vpx_usec_timer emr_timer; vpx_usec_timer_start(&emr_timer); +#endif if (!cpi->row_mt) { cpi->row_mt_sync_read_ptr = vp9_row_mt_sync_read_dummy; @@ -6124,8 +5750,10 @@ static void encode_frame_internal(VP9_COMP *cpi) { vp9_encode_tiles_row_mt(cpi); } +#if CONFIG_INTERNAL_STATS vpx_usec_timer_mark(&emr_timer); cpi->time_encode_sb_row += vpx_usec_timer_elapsed(&emr_timer); +#endif } sf->skip_encode_frame = @@ -6160,7 +5788,6 @@ static int compute_frame_aq_offset(struct VP9_COMP *cpi) { int mi_row, mi_col; int sum_delta = 0; - int map_index = 0; int qdelta_index; int segment_id; @@ -6170,7 +5797,6 @@ static int compute_frame_aq_offset(struct VP9_COMP *cpi) { segment_id = mi_8x8[0]->segment_id; qdelta_index = get_segdata(seg, segment_id, SEG_LVL_ALT_Q); sum_delta += qdelta_index; - map_index++; } mi_8x8_ptr += cm->mi_stride; } @@ -6178,13 +5804,11 @@ static int compute_frame_aq_offset(struct VP9_COMP *cpi) { return sum_delta / (cm->mi_rows * cm->mi_cols); } -#if CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL static void restore_encode_params(VP9_COMP *cpi) { VP9_COMMON *const cm = &cpi->common; - const int tile_cols = 1 << cm->log2_tile_cols; - const int tile_rows = 1 << cm->log2_tile_rows; - int tile_col, tile_row; + int tile_idx; int i, j; + TileDataEnc *tile_data; RD_OPT *rd_opt = &cpi->rd; for (i = 0; i < MAX_REF_FRAMES; i++) { for (j = 0; j < REFERENCE_MODES; j++) @@ -6195,35 +5819,19 @@ static void restore_encode_params(VP9_COMP *cpi) { rd_opt->filter_threshes[i][j] = rd_opt->filter_threshes_prev[i][j]; } - if (cpi->tile_data != NULL) { - for (tile_row = 0; tile_row < tile_rows; ++tile_row) - for (tile_col = 0; tile_col < tile_cols; ++tile_col) { - TileDataEnc *tile_data = - &cpi->tile_data[tile_row * tile_cols + tile_col]; - for (i = 0; i < BLOCK_SIZES; ++i) { - for (j = 0; j < MAX_MODES; ++j) { - tile_data->thresh_freq_fact[i][j] = - tile_data->thresh_freq_fact_prev[i][j]; - } - } - } + for (tile_idx = 0; tile_idx < cpi->allocated_tiles; tile_idx++) { + assert(cpi->tile_data); + tile_data = &cpi->tile_data[tile_idx]; + vp9_copy(tile_data->thresh_freq_fact, tile_data->thresh_freq_fact_prev); } cm->interp_filter = cpi->sf.default_interp_filter; } -#endif // CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL void vp9_encode_frame(VP9_COMP *cpi) { VP9_COMMON *const cm = &cpi->common; -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - restore_encode_params(cpi); - } -#endif // CONFIG_RATE_CTRL -#if CONFIG_CONSISTENT_RECODE restore_encode_params(cpi); -#endif #if CONFIG_MISMATCH_DEBUG mismatch_reset_frame(MAX_MB_PLANE); @@ -6277,7 +5885,13 @@ void vp9_encode_frame(VP9_COMP *cpi) { if (cm->interp_filter == SWITCHABLE) cm->interp_filter = get_interp_filter(filter_thrs, is_alt_ref); +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, encode_frame_internal_time); +#endif encode_frame_internal(cpi); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, encode_frame_internal_time); +#endif for (i = 0; i < REFERENCE_MODES; ++i) mode_thrs[i] = (mode_thrs[i] + rdc->comp_pred_diff[i] / cm->MBs) / 2; diff --git a/libs/libvpx/vp9/encoder/vp9_encodeframe.h b/libs/libvpx/vp9/encoder/vp9_encodeframe.h index fd0a9c517e..97fe52484a 100644 --- a/libs/libvpx/vp9/encoder/vp9_encodeframe.h +++ b/libs/libvpx/vp9/encoder/vp9_encodeframe.h @@ -22,13 +22,6 @@ struct yv12_buffer_config; struct VP9_COMP; struct ThreadData; -// Constants used in SOURCE_VAR_BASED_PARTITION -#define VAR_HIST_MAX_BG_VAR 1000 -#define VAR_HIST_FACTOR 10 -#define VAR_HIST_BINS (VAR_HIST_MAX_BG_VAR / VAR_HIST_FACTOR + 1) -#define VAR_HIST_LARGE_CUT_OFF 75 -#define VAR_HIST_SMALL_CUT_OFF 45 - void vp9_setup_src_planes(struct macroblock *x, const struct yv12_buffer_config *src, int mi_row, int mi_col); diff --git a/libs/libvpx/vp9/encoder/vp9_encodemb.c b/libs/libvpx/vp9/encoder/vp9_encodemb.c index fa222f9dcf..4d59cba108 100644 --- a/libs/libvpx/vp9/encoder/vp9_encodemb.c +++ b/libs/libvpx/vp9/encoder/vp9_encodemb.c @@ -8,6 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include + #include "./vp9_rtcd.h" #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" @@ -26,9 +28,48 @@ #include "vp9/common/vp9_scan.h" #include "vp9/encoder/vp9_encodemb.h" +#include "vp9/encoder/vp9_encoder.h" #include "vp9/encoder/vp9_rd.h" #include "vp9/encoder/vp9_tokenize.h" +#if defined(NDEBUG) +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_assume) +// This is verified by test/vp9_scan_test.cc +#define ASSUME_VALID_SCAN_VALUE(i) \ + __builtin_assume(0 <= i && i <= MAX_SCAN_VALUE) +// This is verified by test/vp9_entropy_test.cc +#define ASSUME_VALID_ENERGY_CLASS(i) \ + __builtin_assume(0 <= i && i <= MAX_ENERGY_CLASS) +#define ASSUME_VALID_TOKEN(i) __builtin_assume(0 <= i && i <= MAX_TOKEN) +#else +#define ASSUME_VALID_SCAN_VALUE(i) \ + do { \ + } while (0) +#define ASSUME_VALID_ENERGY_CLASS(i) \ + do { \ + } while (0) +#define ASSUME_VALID_TOKEN(i) \ + do { \ + } while (0) +#endif +#else +#define ASSUME_VALID_SCAN_VALUE(i) \ + do { \ + } while (0) +#define ASSUME_VALID_ENERGY_CLASS(i) \ + do { \ + } while (0) +#define ASSUME_VALID_TOKEN(i) \ + do { \ + } while (0) +#endif +#else +#define ASSUME_VALID_SCAN_VALUE(i) assert(0 <= i && i <= MAX_SCAN_VALUE) +#define ASSUME_VALID_ENERGY_CLASS(i) assert(0 <= i && i <= MAX_ENERGY_CLASS) +#define ASSUME_VALID_TOKEN(i) assert(0 <= i && i <= MAX_TOKEN) +#endif + struct optimize_ctx { ENTROPY_CONTEXT ta[MAX_MB_PLANE][16]; ENTROPY_CONTEXT tl[MAX_MB_PLANE][16]; @@ -63,12 +104,12 @@ static const int plane_rd_mult[REF_TYPES][PLANE_TYPES] = { (((num) >= 0) ? (num) >> (shift) : -((-(num)) >> (shift))) int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, - int ctx) { + int ctx, int *rate) { MACROBLOCKD *const xd = &mb->e_mbd; struct macroblock_plane *const p = &mb->plane[plane]; struct macroblockd_plane *const pd = &xd->plane[plane]; const int ref = is_inter_block(xd->mi[0]); - uint8_t token_cache[1024]; + uint8_t token_cache[MAX_SCAN_VALUE + 1]; const tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); @@ -78,7 +119,7 @@ int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, const int shift = (tx_size == TX_32X32); const int16_t *const dequant_ptr = pd->dequant; const uint8_t *const band_translate = get_band_translate(tx_size); - const scan_order *const so = get_scan(xd, tx_size, plane_type, block); + const ScanOrder *const so = get_scan(xd, tx_size, plane_type, block); const int16_t *const scan = so->scan; const int16_t *const nb = so->neighbors; const MODE_INFO *mbmi = xd->mi[0]; @@ -99,16 +140,16 @@ int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, #else const uint16_t *cat6_high_cost = vp9_get_high_cost_table(8); #endif - unsigned int(*const token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = + unsigned int (*const token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = mb->token_costs[tx_size][plane_type][ref]; - unsigned int(*token_costs_cur)[2][COEFF_CONTEXTS][ENTROPY_TOKENS]; + unsigned int (*token_costs_cur)[2][COEFF_CONTEXTS][ENTROPY_TOKENS]; int64_t eob_cost0, eob_cost1; - const int ctx0 = ctx; int64_t accu_rate = 0; // Initialized to the worst possible error for the largest transform size. // This ensures that it never goes negative. int64_t accu_error = ((int64_t)1) << 50; int64_t best_block_rd_cost = INT64_MAX; + int64_t best_rate; int x_prev = 1; tran_low_t before_best_eob_qc = 0; tran_low_t before_best_eob_dqc = 0; @@ -116,29 +157,52 @@ int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, assert((!plane_type && !plane) || (plane_type && plane)); assert(eob <= default_eob); - for (i = 0; i < eob; i++) { - const int rc = scan[i]; - token_cache[rc] = vp9_pt_energy_class[vp9_get_token(qcoeff[rc])]; - } + // Seed index 0 so compilers (e.g. GCC -Wmaybe-uninitialized) see token_cache + // initialized before iteration 0's neighbor lookup without adding a branch + // inside the loop; scan[0] is always 0 and overwritten on iteration 0. + token_cache[0] = 0; final_eob = 0; + // This is used in the first iteration, and must be inbounds. We cannot + // locally verify that this is in bounds, so we need to verify at runtime. + // For now, only verify if we have array-bounds turned on. +#if defined(__clang__) && defined(__has_feature) +#if __has_feature(array_bounds_sanitizer) + if (ctx < 0 || ctx > MAX_ENERGY_CLASS) { + abort(); + } +#endif +#endif + // Initial RD cost. token_costs_cur = token_costs + band_translate[0]; - rate0 = (*token_costs_cur)[0][ctx0][EOB_TOKEN]; + rate0 = (*token_costs_cur)[0][ctx][EOB_TOKEN]; best_block_rd_cost = RDCOST(rdmult, rddiv, rate0, accu_error); + best_rate = rate0; // For each token, pick one of two choices greedily: // (i) First candidate: Keep current quantized value, OR // (ii) Second candidate: Reduce quantized value by 1. + // + // token_cache is filled in scan order as coefficients are visited. It needs + // no up-front initialization: in every VP9 scan order both neighbors of scan + // position c lie at scan positions < c (see + // VP9Scan.NeighborsPrecedeInScanOrder in test/vp9_scan_test.cc), so every + // entry that get_coef_context() reads below has already been written during + // this pass. for (i = 0; i < eob; i++) { const int rc = scan[i]; + ASSUME_VALID_SCAN_VALUE(rc); const int x = qcoeff[rc]; const int band_cur = band_translate[i]; const int ctx_cur = (i == 0) ? ctx : get_coef_context(nb, token_cache, i); + ASSUME_VALID_ENERGY_CLASS(ctx_cur); const int token_tree_sel_cur = (x_prev == 0); token_costs_cur = token_costs + band_cur; if (x == 0) { // No need to search const int token = vp9_get_token(x); + ASSUME_VALID_TOKEN(token); + token_cache[rc] = 0; rate0 = (*token_costs_cur)[token_tree_sel_cur][ctx_cur][token]; accu_rate += rate0; x_prev = 0; @@ -199,7 +263,10 @@ int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, int rdcost_better_for_x1, eob_rdcost_better_for_x1; int dqc0, dqc1; int64_t best_eob_cost_cur; + int64_t eob_rate0, eob_rate1; int use_x1; + const int e_t0 = vp9_pt_energy_class[t0]; + const int e_t1 = vp9_pt_energy_class[t1]; // Calculate RD Cost effect on the next coeff for the two candidates. int64_t next_bits0 = 0; @@ -207,28 +274,41 @@ int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, int64_t next_eob_bits0 = 0; int64_t next_eob_bits1 = 0; if (i < default_eob - 1) { - int ctx_next, token_tree_sel_next; + int token_tree_sel_next; const int band_next = band_translate[i + 1]; const int token_next = (i + 1 != eob) ? vp9_get_token(qcoeff[scan[i + 1]]) : EOB_TOKEN; - unsigned int(*const token_costs_next)[2][COEFF_CONTEXTS] - [ENTROPY_TOKENS] = - token_costs + band_next; - token_cache[rc] = vp9_pt_energy_class[t0]; - ctx_next = get_coef_context(nb, token_cache, i + 1); + ASSUME_VALID_TOKEN(token_next); + unsigned int (*const token_costs_next)[2][COEFF_CONTEXTS] + [ENTROPY_TOKENS] = + token_costs + band_next; + const int n0 = nb[2 * (i + 1)]; + const int n1 = nb[2 * (i + 1) + 1]; + ASSUME_VALID_SCAN_VALUE(n0); + ASSUME_VALID_SCAN_VALUE(n1); + // token_cache[rc] is only written once the choice below is made, so + // use e_t0/e_t1 in its place when rc is a neighbor of position i + 1. + const int e0 = (n0 == rc) ? 0 : token_cache[n0]; + const int e1 = (n1 == rc) ? 0 : token_cache[n1]; + const int ctx_next0 = + (1 + ((n0 == rc) ? e_t0 : e0) + ((n1 == rc) ? e_t0 : e1)) >> 1; + const int ctx_next1 = + (1 + ((n0 == rc) ? e_t1 : e0) + ((n1 == rc) ? e_t1 : e1)) >> 1; + // Visited token_cache entries and e_t0/e_t1 are valid energy classes, + // so their rounded average is at most MAX_ENERGY_CLASS. + ASSUME_VALID_ENERGY_CLASS(ctx_next0); + ASSUME_VALID_ENERGY_CLASS(ctx_next1); token_tree_sel_next = (x == 0); next_bits0 = - (*token_costs_next)[token_tree_sel_next][ctx_next][token_next]; + (*token_costs_next)[token_tree_sel_next][ctx_next0][token_next]; next_eob_bits0 = - (*token_costs_next)[token_tree_sel_next][ctx_next][EOB_TOKEN]; - token_cache[rc] = vp9_pt_energy_class[t1]; - ctx_next = get_coef_context(nb, token_cache, i + 1); + (*token_costs_next)[token_tree_sel_next][ctx_next0][EOB_TOKEN]; token_tree_sel_next = (x1 == 0); next_bits1 = - (*token_costs_next)[token_tree_sel_next][ctx_next][token_next]; + (*token_costs_next)[token_tree_sel_next][ctx_next1][token_next]; if (x1 != 0) { next_eob_bits1 = - (*token_costs_next)[token_tree_sel_next][ctx_next][EOB_TOKEN]; + (*token_costs_next)[token_tree_sel_next][ctx_next1][EOB_TOKEN]; } } @@ -236,13 +316,15 @@ int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, rd_cost0 = RDCOST(rdmult, rddiv, (rate0 + next_bits0), distortion0); rd_cost1 = RDCOST(rdmult, rddiv, (rate1 + next_bits1), distortion1); rdcost_better_for_x1 = (rd_cost1 < rd_cost0); - eob_cost0 = RDCOST(rdmult, rddiv, (accu_rate + rate0 + next_eob_bits0), + eob_rate0 = accu_rate + rate0 + next_eob_bits0; + eob_rate1 = eob_rate0; + eob_cost0 = RDCOST(rdmult, rddiv, eob_rate0, (accu_error + distortion0 - distortion_for_zero)); eob_cost1 = eob_cost0; if (x1 != 0) { - eob_cost1 = - RDCOST(rdmult, rddiv, (accu_rate + rate1 + next_eob_bits1), - (accu_error + distortion1 - distortion_for_zero)); + eob_rate1 = accu_rate + rate1 + next_eob_bits1; + eob_cost1 = RDCOST(rdmult, rddiv, eob_rate1, + (accu_error + distortion1 - distortion_for_zero)); eob_rdcost_better_for_x1 = (eob_cost1 < eob_cost0); } else { eob_rdcost_better_for_x1 = 0; @@ -266,12 +348,12 @@ int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, accu_rate += rate1; accu_error += distortion1 - distortion_for_zero; assert(distortion1 <= distortion_for_zero); - token_cache[rc] = vp9_pt_energy_class[t1]; + token_cache[rc] = e_t1; } else { accu_rate += rate0; accu_error += distortion0 - distortion_for_zero; assert(distortion0 <= distortion_for_zero); - token_cache[rc] = vp9_pt_energy_class[t0]; + token_cache[rc] = e_t0; } if (sharpness > 0 && abs(qcoeff[rc]) > 1) count_high_values_after_eob++; assert(accu_error >= 0); @@ -285,6 +367,7 @@ int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, best_block_rd_cost = best_eob_cost_cur; final_eob = i + 1; count_high_values_after_eob = 0; + best_rate = use_x1 ? eob_rate1 : eob_rate0; if (use_x1) { before_best_eob_qc = x1; before_best_eob_dqc = dqc1; @@ -300,6 +383,7 @@ int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, final_eob = eob - 1; for (; final_eob >= 0; final_eob--) { const int rc = scan[final_eob]; + ASSUME_VALID_SCAN_VALUE(rc); const int x = qcoeff[rc]; if (x) { break; @@ -313,15 +397,18 @@ int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, assert(before_best_eob_qc != 0); i = final_eob - 1; rc = scan[i]; + ASSUME_VALID_SCAN_VALUE(rc); qcoeff[rc] = before_best_eob_qc; dqcoeff[rc] = before_best_eob_dqc; } for (i = final_eob; i < eob; i++) { int rc = scan[i]; + ASSUME_VALID_SCAN_VALUE(rc); qcoeff[rc] = 0; dqcoeff[rc] = 0; } } + if (rate) *rate = (count_high_values_after_eob > 0) ? -1 : (int)best_rate; mb->plane[plane].eobs[block] = final_eob; return final_eob; } @@ -350,7 +437,7 @@ void vp9_xform_quant_fp(MACROBLOCK *x, int plane, int block, int row, int col, MACROBLOCKD *const xd = &x->e_mbd; const struct macroblock_plane *const p = &x->plane[plane]; const struct macroblockd_plane *const pd = &xd->plane[plane]; - const scan_order *const scan_order = &vp9_default_scan_orders[tx_size]; + const ScanOrder *const scan_order = &vp9_default_scan_orders[tx_size]; tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); @@ -366,28 +453,24 @@ void vp9_xform_quant_fp(MACROBLOCK *x, int plane, int block, int row, int col, switch (tx_size) { case TX_32X32: highbd_fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride); - vp9_highbd_quantize_fp_32x32(coeff, 1024, p->round_fp, p->quant_fp, - qcoeff, dqcoeff, pd->dequant, eob, - scan_order->scan, scan_order->iscan); + vp9_highbd_quantize_fp_32x32(coeff, 1024, p, qcoeff, dqcoeff, + pd->dequant, eob, scan_order); break; case TX_16X16: vpx_highbd_fdct16x16(src_diff, coeff, diff_stride); - vp9_highbd_quantize_fp(coeff, 256, p->round_fp, p->quant_fp, qcoeff, - dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vp9_highbd_quantize_fp(coeff, 256, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; case TX_8X8: vpx_highbd_fdct8x8(src_diff, coeff, diff_stride); - vp9_highbd_quantize_fp(coeff, 64, p->round_fp, p->quant_fp, qcoeff, - dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vp9_highbd_quantize_fp(coeff, 64, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; default: assert(tx_size == TX_4X4); x->fwd_txfm4x4(src_diff, coeff, diff_stride); - vp9_highbd_quantize_fp(coeff, 16, p->round_fp, p->quant_fp, qcoeff, - dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vp9_highbd_quantize_fp(coeff, 16, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; } return; @@ -397,26 +480,25 @@ void vp9_xform_quant_fp(MACROBLOCK *x, int plane, int block, int row, int col, switch (tx_size) { case TX_32X32: fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride); - vp9_quantize_fp_32x32(coeff, 1024, p->round_fp, p->quant_fp, qcoeff, - dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vp9_quantize_fp_32x32(coeff, 1024, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; case TX_16X16: vpx_fdct16x16(src_diff, coeff, diff_stride); - vp9_quantize_fp(coeff, 256, p->round_fp, p->quant_fp, qcoeff, dqcoeff, - pd->dequant, eob, scan_order->scan, scan_order->iscan); + vp9_quantize_fp(coeff, 256, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; case TX_8X8: vpx_fdct8x8(src_diff, coeff, diff_stride); - vp9_quantize_fp(coeff, 64, p->round_fp, p->quant_fp, qcoeff, dqcoeff, - pd->dequant, eob, scan_order->scan, scan_order->iscan); + vp9_quantize_fp(coeff, 64, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; default: assert(tx_size == TX_4X4); x->fwd_txfm4x4(src_diff, coeff, diff_stride); - vp9_quantize_fp(coeff, 16, p->round_fp, p->quant_fp, qcoeff, dqcoeff, - pd->dequant, eob, scan_order->scan, scan_order->iscan); + vp9_quantize_fp(coeff, 16, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; } } @@ -495,7 +577,7 @@ void vp9_xform_quant(MACROBLOCK *x, int plane, int block, int row, int col, MACROBLOCKD *const xd = &x->e_mbd; const struct macroblock_plane *const p = &x->plane[plane]; const struct macroblockd_plane *const pd = &xd->plane[plane]; - const scan_order *const scan_order = &vp9_default_scan_orders[tx_size]; + const ScanOrder *const scan_order = &vp9_default_scan_orders[tx_size]; tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); @@ -511,28 +593,24 @@ void vp9_xform_quant(MACROBLOCK *x, int plane, int block, int row, int col, switch (tx_size) { case TX_32X32: highbd_fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride); - vpx_highbd_quantize_b_32x32( - coeff, 1024, p->zbin, p->round, p->quant, p->quant_shift, qcoeff, - dqcoeff, pd->dequant, eob, scan_order->scan, scan_order->iscan); + vpx_highbd_quantize_b_32x32(coeff, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; case TX_16X16: vpx_highbd_fdct16x16(src_diff, coeff, diff_stride); - vpx_highbd_quantize_b(coeff, 256, p->zbin, p->round, p->quant, - p->quant_shift, qcoeff, dqcoeff, pd->dequant, eob, - scan_order->scan, scan_order->iscan); + vpx_highbd_quantize_b(coeff, 256, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; case TX_8X8: vpx_highbd_fdct8x8(src_diff, coeff, diff_stride); - vpx_highbd_quantize_b(coeff, 64, p->zbin, p->round, p->quant, - p->quant_shift, qcoeff, dqcoeff, pd->dequant, eob, - scan_order->scan, scan_order->iscan); + vpx_highbd_quantize_b(coeff, 64, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; default: assert(tx_size == TX_4X4); x->fwd_txfm4x4(src_diff, coeff, diff_stride); - vpx_highbd_quantize_b(coeff, 16, p->zbin, p->round, p->quant, - p->quant_shift, qcoeff, dqcoeff, pd->dequant, eob, - scan_order->scan, scan_order->iscan); + vpx_highbd_quantize_b(coeff, 16, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; } return; @@ -542,28 +620,24 @@ void vp9_xform_quant(MACROBLOCK *x, int plane, int block, int row, int col, switch (tx_size) { case TX_32X32: fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride); - vpx_quantize_b_32x32(coeff, 1024, p->zbin, p->round, p->quant, - p->quant_shift, qcoeff, dqcoeff, pd->dequant, eob, - scan_order->scan, scan_order->iscan); + vpx_quantize_b_32x32(coeff, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; case TX_16X16: vpx_fdct16x16(src_diff, coeff, diff_stride); - vpx_quantize_b(coeff, 256, p->zbin, p->round, p->quant, p->quant_shift, - qcoeff, dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vpx_quantize_b(coeff, 256, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; case TX_8X8: vpx_fdct8x8(src_diff, coeff, diff_stride); - vpx_quantize_b(coeff, 64, p->zbin, p->round, p->quant, p->quant_shift, - qcoeff, dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vpx_quantize_b(coeff, 64, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; default: assert(tx_size == TX_4X4); x->fwd_txfm4x4(src_diff, coeff, diff_stride); - vpx_quantize_b(coeff, 16, p->zbin, p->round, p->quant, p->quant_shift, - qcoeff, dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vpx_quantize_b(coeff, 16, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; } } @@ -641,7 +715,7 @@ static void encode_block(int plane, int block, int row, int col, if (x->optimize && (!x->skip_recode || !x->skip_optimize)) { const int ctx = combine_entropy_contexts(*a, *l); - *a = *l = vp9_optimize_b(x, plane, block, tx_size, ctx) > 0; + *a = *l = vp9_optimize_b(x, plane, block, tx_size, ctx, NULL) > 0; } else { *a = *l = p->eobs[block] > 0; } @@ -759,10 +833,26 @@ void vp9_encode_sb(MACROBLOCK *x, BLOCK_SIZE bsize, int mi_row, int mi_col, MODE_INFO *mi = xd->mi[0]; int plane; #if CONFIG_MISMATCH_DEBUG - struct encode_b_args arg = { x, 1, NULL, NULL, - &mi->skip, mi_row, mi_col, output_enabled }; + struct encode_b_args arg = { x, + 1, // enable_trellis_opt + 0.0, // trellis_opt_thresh + NULL, // &sse_calc_done + NULL, // &sse + NULL, // above entropy context + NULL, // left entropy context + &mi->skip, // skip + NULL, // rate + mi_row, mi_col, output_enabled }; #else - struct encode_b_args arg = { x, 1, NULL, NULL, &mi->skip }; + struct encode_b_args arg = { x, + 1, // enable_trellis_opt + 0.0, // trellis_opt_thresh + NULL, // &sse_calc_done + NULL, // &sse + NULL, // above entropy context + NULL, // left entropy context + &mi->skip, // skip + NULL }; // rate (void)mi_row; (void)mi_col; (void)output_enabled; @@ -780,9 +870,9 @@ void vp9_encode_sb(MACROBLOCK *x, BLOCK_SIZE bsize, int mi_row, int mi_col, const TX_SIZE tx_size = plane ? get_uv_tx_size(mi, pd) : mi->tx_size; vp9_get_entropy_contexts(bsize, tx_size, pd, ctx.ta[plane], ctx.tl[plane]); - arg.enable_coeff_opt = 1; + arg.enable_trellis_opt = 1; } else { - arg.enable_coeff_opt = 0; + arg.enable_trellis_opt = 0; } arg.ta = ctx.ta[plane]; arg.tl = ctx.tl[plane]; @@ -804,7 +894,7 @@ void vp9_encode_block_intra(int plane, int block, int row, int col, tran_low_t *coeff = BLOCK_OFFSET(p->coeff, block); tran_low_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block); tran_low_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); - const scan_order *scan_order; + const ScanOrder *scan_order; TX_TYPE tx_type = DCT_DCT; PREDICTION_MODE mode; const int bwl = b_width_log2_lookup[plane_bsize]; @@ -814,17 +904,13 @@ void vp9_encode_block_intra(int plane, int block, int row, int col, uint16_t *eob = &p->eobs[block]; const int src_stride = p->src.stride; const int dst_stride = pd->dst.stride; + int enable_trellis_opt = !x->skip_recode; ENTROPY_CONTEXT *a = NULL; ENTROPY_CONTEXT *l = NULL; int entropy_ctx = 0; dst = &pd->dst.buf[4 * (row * dst_stride + col)]; src = &p->src.buf[4 * (row * src_stride + col)]; src_diff = &p->src_diff[4 * (row * diff_stride + col)]; - if (args->enable_coeff_opt) { - a = &args->ta[col]; - l = &args->tl[row]; - entropy_ctx = combine_entropy_contexts(*a, *l); - } if (tx_size == TX_4X4) { tx_type = get_tx_type_4x4(get_plane_type(plane), xd, block); @@ -848,21 +934,44 @@ void vp9_encode_block_intra(int plane, int block, int row, int col, // skip block condition should be handled before this is called. assert(!x->skip_block); + if (!x->skip_recode) { + const int tx_size_in_pixels = (1 << tx_size) << 2; +#if CONFIG_VP9_HIGHBITDEPTH + if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { + vpx_highbd_subtract_block(tx_size_in_pixels, tx_size_in_pixels, src_diff, + diff_stride, src, src_stride, dst, dst_stride, + xd->bd); + } else { + vpx_subtract_block(tx_size_in_pixels, tx_size_in_pixels, src_diff, + diff_stride, src, src_stride, dst, dst_stride); + } +#else + vpx_subtract_block(tx_size_in_pixels, tx_size_in_pixels, src_diff, + diff_stride, src, src_stride, dst, dst_stride); +#endif + enable_trellis_opt = do_trellis_opt(pd, src_diff, diff_stride, row, col, + plane_bsize, tx_size, args); + } + + if (enable_trellis_opt) { + a = &args->ta[col]; + l = &args->tl[row]; + entropy_ctx = combine_entropy_contexts(*a, *l); + } + #if CONFIG_VP9_HIGHBITDEPTH if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { uint16_t *const dst16 = CONVERT_TO_SHORTPTR(dst); switch (tx_size) { case TX_32X32: if (!x->skip_recode) { - vpx_highbd_subtract_block(32, 32, src_diff, diff_stride, src, - src_stride, dst, dst_stride, xd->bd); highbd_fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride); - vpx_highbd_quantize_b_32x32( - coeff, 1024, p->zbin, p->round, p->quant, p->quant_shift, qcoeff, - dqcoeff, pd->dequant, eob, scan_order->scan, scan_order->iscan); + vpx_highbd_quantize_b_32x32(coeff, p, qcoeff, dqcoeff, pd->dequant, + eob, scan_order); } - if (args->enable_coeff_opt && !x->skip_recode) { - *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0; + if (enable_trellis_opt) { + *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx, + args->rate) > 0; } if (!x->skip_encode && *eob) { vp9_highbd_idct32x32_add(dqcoeff, dst16, dst_stride, *eob, xd->bd); @@ -870,18 +979,16 @@ void vp9_encode_block_intra(int plane, int block, int row, int col, break; case TX_16X16: if (!x->skip_recode) { - vpx_highbd_subtract_block(16, 16, src_diff, diff_stride, src, - src_stride, dst, dst_stride, xd->bd); if (tx_type == DCT_DCT) vpx_highbd_fdct16x16(src_diff, coeff, diff_stride); else vp9_highbd_fht16x16(src_diff, coeff, diff_stride, tx_type); - vpx_highbd_quantize_b(coeff, 256, p->zbin, p->round, p->quant, - p->quant_shift, qcoeff, dqcoeff, pd->dequant, - eob, scan_order->scan, scan_order->iscan); + vpx_highbd_quantize_b(coeff, 256, p, qcoeff, dqcoeff, pd->dequant, + eob, scan_order); } - if (args->enable_coeff_opt && !x->skip_recode) { - *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0; + if (enable_trellis_opt) { + *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx, + args->rate) > 0; } if (!x->skip_encode && *eob) { vp9_highbd_iht16x16_add(tx_type, dqcoeff, dst16, dst_stride, *eob, @@ -890,18 +997,16 @@ void vp9_encode_block_intra(int plane, int block, int row, int col, break; case TX_8X8: if (!x->skip_recode) { - vpx_highbd_subtract_block(8, 8, src_diff, diff_stride, src, - src_stride, dst, dst_stride, xd->bd); if (tx_type == DCT_DCT) vpx_highbd_fdct8x8(src_diff, coeff, diff_stride); else vp9_highbd_fht8x8(src_diff, coeff, diff_stride, tx_type); - vpx_highbd_quantize_b(coeff, 64, p->zbin, p->round, p->quant, - p->quant_shift, qcoeff, dqcoeff, pd->dequant, - eob, scan_order->scan, scan_order->iscan); + vpx_highbd_quantize_b(coeff, 64, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); } - if (args->enable_coeff_opt && !x->skip_recode) { - *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0; + if (enable_trellis_opt) { + *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx, + args->rate) > 0; } if (!x->skip_encode && *eob) { vp9_highbd_iht8x8_add(tx_type, dqcoeff, dst16, dst_stride, *eob, @@ -911,18 +1016,16 @@ void vp9_encode_block_intra(int plane, int block, int row, int col, default: assert(tx_size == TX_4X4); if (!x->skip_recode) { - vpx_highbd_subtract_block(4, 4, src_diff, diff_stride, src, - src_stride, dst, dst_stride, xd->bd); if (tx_type != DCT_DCT) vp9_highbd_fht4x4(src_diff, coeff, diff_stride, tx_type); else x->fwd_txfm4x4(src_diff, coeff, diff_stride); - vpx_highbd_quantize_b(coeff, 16, p->zbin, p->round, p->quant, - p->quant_shift, qcoeff, dqcoeff, pd->dequant, - eob, scan_order->scan, scan_order->iscan); + vpx_highbd_quantize_b(coeff, 16, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); } - if (args->enable_coeff_opt && !x->skip_recode) { - *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0; + if (enable_trellis_opt) { + *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx, + args->rate) > 0; } if (!x->skip_encode && *eob) { if (tx_type == DCT_DCT) { @@ -945,45 +1048,39 @@ void vp9_encode_block_intra(int plane, int block, int row, int col, switch (tx_size) { case TX_32X32: if (!x->skip_recode) { - vpx_subtract_block(32, 32, src_diff, diff_stride, src, src_stride, dst, - dst_stride); fdct32x32(x->use_lp32x32fdct, src_diff, coeff, diff_stride); - vpx_quantize_b_32x32(coeff, 1024, p->zbin, p->round, p->quant, - p->quant_shift, qcoeff, dqcoeff, pd->dequant, eob, - scan_order->scan, scan_order->iscan); + vpx_quantize_b_32x32(coeff, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); } - if (args->enable_coeff_opt && !x->skip_recode) { - *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0; + if (enable_trellis_opt) { + *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx, + args->rate) > 0; } if (!x->skip_encode && *eob) vp9_idct32x32_add(dqcoeff, dst, dst_stride, *eob); break; case TX_16X16: if (!x->skip_recode) { - vpx_subtract_block(16, 16, src_diff, diff_stride, src, src_stride, dst, - dst_stride); vp9_fht16x16(src_diff, coeff, diff_stride, tx_type); - vpx_quantize_b(coeff, 256, p->zbin, p->round, p->quant, p->quant_shift, - qcoeff, dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vpx_quantize_b(coeff, 256, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); } - if (args->enable_coeff_opt && !x->skip_recode) { - *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0; + if (enable_trellis_opt) { + *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx, + args->rate) > 0; } if (!x->skip_encode && *eob) vp9_iht16x16_add(tx_type, dqcoeff, dst, dst_stride, *eob); break; case TX_8X8: if (!x->skip_recode) { - vpx_subtract_block(8, 8, src_diff, diff_stride, src, src_stride, dst, - dst_stride); vp9_fht8x8(src_diff, coeff, diff_stride, tx_type); - vpx_quantize_b(coeff, 64, p->zbin, p->round, p->quant, p->quant_shift, - qcoeff, dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vpx_quantize_b(coeff, 64, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); } - if (args->enable_coeff_opt && !x->skip_recode) { - *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0; + if (enable_trellis_opt) { + *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx, + args->rate) > 0; } if (!x->skip_encode && *eob) vp9_iht8x8_add(tx_type, dqcoeff, dst, dst_stride, *eob); @@ -991,18 +1088,16 @@ void vp9_encode_block_intra(int plane, int block, int row, int col, default: assert(tx_size == TX_4X4); if (!x->skip_recode) { - vpx_subtract_block(4, 4, src_diff, diff_stride, src, src_stride, dst, - dst_stride); if (tx_type != DCT_DCT) vp9_fht4x4(src_diff, coeff, diff_stride, tx_type); else x->fwd_txfm4x4(src_diff, coeff, diff_stride); - vpx_quantize_b(coeff, 16, p->zbin, p->round, p->quant, p->quant_shift, - qcoeff, dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vpx_quantize_b(coeff, 16, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); } - if (args->enable_coeff_opt && !x->skip_recode) { - *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx) > 0; + if (enable_trellis_opt) { + *a = *l = vp9_optimize_b(x, plane, block, tx_size, entropy_ctx, + args->rate) > 0; } if (!x->skip_encode && *eob) { if (tx_type == DCT_DCT) @@ -1019,28 +1114,45 @@ void vp9_encode_block_intra(int plane, int block, int row, int col, } void vp9_encode_intra_block_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane, - int enable_optimize_b) { + int enable_trellis_opt) { const MACROBLOCKD *const xd = &x->e_mbd; struct optimize_ctx ctx; #if CONFIG_MISMATCH_DEBUG // TODO(angiebird): make mismatch_debug support intra mode struct encode_b_args arg = { - x, enable_optimize_b, ctx.ta[plane], ctx.tl[plane], &xd->mi[0]->skip, 0, 0, - 0 + x, + enable_trellis_opt, + 0.0, // trellis_opt_thresh + NULL, // &sse_calc_done + NULL, // &sse + ctx.ta[plane], + ctx.tl[plane], + &xd->mi[0]->skip, + NULL, // rate + 0, // mi_row + 0, // mi_col + 0 // output_enabled }; #else - struct encode_b_args arg = { x, enable_optimize_b, ctx.ta[plane], - ctx.tl[plane], &xd->mi[0]->skip }; + struct encode_b_args arg = { x, + enable_trellis_opt, + 0.0, // trellis_opt_thresh + NULL, // &sse_calc_done + NULL, // &sse + ctx.ta[plane], + ctx.tl[plane], + &xd->mi[0]->skip, + NULL }; // rate #endif - if (enable_optimize_b && x->optimize && + if (enable_trellis_opt && x->optimize && (!x->skip_recode || !x->skip_optimize)) { const struct macroblockd_plane *const pd = &xd->plane[plane]; const TX_SIZE tx_size = plane ? get_uv_tx_size(xd->mi[0], pd) : xd->mi[0]->tx_size; vp9_get_entropy_contexts(bsize, tx_size, pd, ctx.ta[plane], ctx.tl[plane]); } else { - arg.enable_coeff_opt = 0; + arg.enable_trellis_opt = 0; } vp9_foreach_transformed_block_in_plane(xd, bsize, plane, diff --git a/libs/libvpx/vp9/encoder/vp9_encodemb.h b/libs/libvpx/vp9/encoder/vp9_encodemb.h index 1975ee73ac..cde301bcf9 100644 --- a/libs/libvpx/vp9/encoder/vp9_encodemb.h +++ b/libs/libvpx/vp9/encoder/vp9_encodemb.h @@ -20,18 +20,31 @@ extern "C" { struct encode_b_args { MACROBLOCK *x; - int enable_coeff_opt; + int enable_trellis_opt; + double trellis_opt_thresh; + int *sse_calc_done; + int64_t *sse; ENTROPY_CONTEXT *ta; ENTROPY_CONTEXT *tl; int8_t *skip; + // Optional output for the token rate of the trellis-optimized block as + // computed by cost_coeffs() (vp9_rdopt.c) with precise, i.e. non-fast, + // coefficient costing, or -1 when the rate is unavailable. May be NULL if the + // caller does not need the rate. See vp9_optimize_b(). + int *rate; #if CONFIG_MISMATCH_DEBUG int mi_row; int mi_col; int output_enabled; #endif }; +// Optimizes the quantized coefficients of `block` using trellis RDO and returns +// the final EOB position. If `rate` is non-NULL, `*rate` receives the token +// rate of the optimized block, equal to cost_coeffs() (vp9_rdopt.c) with +// precise, i.e. non-fast, coefficient costing, or -1 when the rate is +// unavailable because the post-EOB sharpness adjustment moved the final EOB. int vp9_optimize_b(MACROBLOCK *mb, int plane, int block, TX_SIZE tx_size, - int ctx); + int ctx, int *rate); void vp9_encode_sb(MACROBLOCK *x, BLOCK_SIZE bsize, int mi_row, int mi_col, int output_enabled); void vp9_encode_sby_pass1(MACROBLOCK *x, BLOCK_SIZE bsize); @@ -48,7 +61,7 @@ void vp9_encode_block_intra(int plane, int block, int row, int col, BLOCK_SIZE plane_bsize, TX_SIZE tx_size, void *arg); void vp9_encode_intra_block_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane, - int enable_optimize_b); + int enable_trellis_opt); #ifdef __cplusplus } // extern "C" diff --git a/libs/libvpx/vp9/encoder/vp9_encoder.c b/libs/libvpx/vp9/encoder/vp9_encoder.c index 8c4c21b60a..68ba212a00 100644 --- a/libs/libvpx/vp9/encoder/vp9_encoder.c +++ b/libs/libvpx/vp9/encoder/vp9_encoder.c @@ -10,40 +10,45 @@ #include #include +#include #include #include +#include #include "./vp9_rtcd.h" #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" #include "./vpx_scale_rtcd.h" +#include "vpx/vpx_codec.h" +#include "vpx/vpx_ext_ratectrl.h" #include "vpx_dsp/psnr.h" #include "vpx_dsp/vpx_dsp_common.h" #include "vpx_dsp/vpx_filter.h" #if CONFIG_INTERNAL_STATS #include "vpx_dsp/ssim.h" #endif +#include "vpx_mem/vpx_mem.h" #include "vpx_ports/mem.h" #include "vpx_ports/system_state.h" #include "vpx_ports/vpx_once.h" #include "vpx_ports/vpx_timer.h" +#include "vpx_util/vpx_pthread.h" #if CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG #include "vpx_util/vpx_debug_util.h" #endif // CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG #include "vp9/common/vp9_alloccommon.h" +#include "vp9/common/vp9_blockd.h" +#include "vp9/common/vp9_enums.h" #include "vp9/common/vp9_filter.h" #include "vp9/common/vp9_idct.h" -#if CONFIG_NON_GREEDY_MV -#include "vp9/common/vp9_mvref_common.h" -#endif #if CONFIG_VP9_POSTPROC #include "vp9/common/vp9_postproc.h" #endif #include "vp9/common/vp9_reconinter.h" #include "vp9/common/vp9_reconintra.h" +#include "vp9/common/vp9_scale.h" #include "vp9/common/vp9_tile_common.h" -#include "vp9/common/vp9_scan.h" #if !CONFIG_REALTIME_ONLY #include "vp9/encoder/vp9_alt_ref_aq.h" @@ -73,6 +78,7 @@ #include "vp9/encoder/vp9_multi_thread.h" #include "vp9/encoder/vp9_noise_estimate.h" #include "vp9/encoder/vp9_picklpf.h" +#include "vp9/encoder/vp9_quantize.h" #include "vp9/encoder/vp9_ratectrl.h" #include "vp9/encoder/vp9_rd.h" #include "vp9/encoder/vp9_resize.h" @@ -81,6 +87,7 @@ #include "vp9/encoder/vp9_speed_features.h" #include "vp9/encoder/vp9_svc_layercontext.h" #include "vp9/encoder/vp9_temporal_filter.h" +#include "vp9/encoder/vp9_tpl_model.h" #include "vp9/vp9_cx_iface.h" #define AM_SEGMENT_ID_INACTIVE 7 @@ -126,13 +133,6 @@ static int is_spatial_denoise_enabled(VP9_COMP *cpi) { } #endif -#if CONFIG_VP9_HIGHBITDEPTH -void highbd_wht_fwd_txfm(int16_t *src_diff, int bw, tran_low_t *coeff, - TX_SIZE tx_size); -#endif -void wht_fwd_txfm(int16_t *src_diff, int bw, tran_low_t *coeff, - TX_SIZE tx_size); - #if !CONFIG_REALTIME_ONLY // compute adaptive threshold for skip recoding static int compute_context_model_thresh(const VP9_COMP *const cpi) { @@ -148,7 +148,7 @@ static int compute_context_model_thresh(const VP9_COMP *const cpi) { // frame context probability model is less than a certain threshold. // The first component is the most critical part to guarantee adaptivity. // Other parameters are estimated based on normal setting of hd resolution - // parameters. e.g frame_size = 1920x1080, bitrate = 8000, qindex_factor < 50 + // parameters. e.g. frame_size = 1920x1080, bitrate = 8000, qindex_factor < 50 const int thresh = ((FRAME_SIZE_FACTOR * frame_size - FRAME_RATE_FACTOR * bitrate) * qindex_factor) >> @@ -502,22 +502,22 @@ static const char *level_fail_messages[TARGET_LEVEL_FAIL_IDS] = { "Too many reference buffers are used." }; -static INLINE void Scale2Ratio(VPX_SCALING mode, int *hr, int *hs) { +static INLINE void Scale2Ratio(VPX_SCALING_MODE mode, int *hr, int *hs) { switch (mode) { - case NORMAL: + case VP8E_NORMAL: *hr = 1; *hs = 1; break; - case FOURFIVE: + case VP8E_FOURFIVE: *hr = 4; *hs = 5; break; - case THREEFIVE: + case VP8E_THREEFIVE: *hr = 3; *hs = 5; break; default: - assert(mode == ONETWO); + assert(mode == VP8E_ONETWO); *hr = 1; *hs = 2; break; @@ -690,9 +690,10 @@ VP9_LEVEL vp9_get_level(const Vp9LevelSpec *const level_spec) { return (i == VP9_LEVELS) ? LEVEL_UNKNOWN : vp9_level_defs[i].level; } -int vp9_set_roi_map(VP9_COMP *cpi, unsigned char *map, unsigned int rows, - unsigned int cols, int delta_q[8], int delta_lf[8], - int skip[8], int ref_frame[8]) { +vpx_codec_err_t vp9_set_roi_map(VP9_COMP *cpi, unsigned char *map, + unsigned int rows, unsigned int cols, + int delta_q[8], int delta_lf[8], int skip[8], + int ref_frame[8]) { VP9_COMMON *cm = &cpi->common; vpx_roi_map_t *roi = &cpi->roi; const int range = 63; @@ -703,13 +704,13 @@ int vp9_set_roi_map(VP9_COMP *cpi, unsigned char *map, unsigned int rows, // Check number of rows and columns match if (frame_rows != (int)rows || frame_cols != (int)cols) { - return -1; + return VPX_CODEC_INVALID_PARAM; } if (!check_seg_range(delta_q, range) || !check_seg_range(delta_lf, range) || !check_seg_range(ref_frame, ref_frame_range) || !check_seg_range(skip, skip_range)) - return -1; + return VPX_CODEC_INVALID_PARAM; // Also disable segmentation if no deltas are specified. if (!map || @@ -723,14 +724,20 @@ int vp9_set_roi_map(VP9_COMP *cpi, unsigned char *map, unsigned int rows, ref_frame[6] == -1 && ref_frame[7] == -1))) { vp9_disable_segmentation(&cm->seg); cpi->roi.enabled = 0; - return 0; + return VPX_CODEC_OK; + } + + // Each byte of the map is used as a segment id and must be in range. + for (unsigned int i = 0; i < rows * cols; ++i) { + if (map[i] >= MAX_SEGMENTS) return VPX_CODEC_INVALID_PARAM; } if (roi->roi_map) { vpx_free(roi->roi_map); roi->roi_map = NULL; } - CHECK_MEM_ERROR(cm, roi->roi_map, vpx_malloc(rows * cols)); + roi->roi_map = vpx_malloc(rows * cols); + if (!roi->roi_map) return VPX_CODEC_MEM_ERROR; // Copy to ROI structure in the compressor. memcpy(roi->roi_map, map, rows * cols); @@ -742,7 +749,7 @@ int vp9_set_roi_map(VP9_COMP *cpi, unsigned char *map, unsigned int rows, roi->rows = rows; roi->cols = cols; - return 0; + return VPX_CODEC_OK; } int vp9_set_active_map(VP9_COMP *cpi, unsigned char *new_map_16x16, int rows, @@ -886,10 +893,11 @@ static int vp9_enc_alloc_mi(VP9_COMMON *cm, int mi_size) { if (!cm->prev_mip) return 1; cm->mi_alloc_size = mi_size; - cm->mi_grid_base = (MODE_INFO **)vpx_calloc(mi_size, sizeof(MODE_INFO *)); + cm->mi_grid_base = + (MODE_INFO **)vpx_calloc(mi_size, sizeof(*cm->mi_grid_base)); if (!cm->mi_grid_base) return 1; cm->prev_mi_grid_base = - (MODE_INFO **)vpx_calloc(mi_size, sizeof(MODE_INFO *)); + (MODE_INFO **)vpx_calloc(mi_size, sizeof(*cm->prev_mi_grid_base)); if (!cm->prev_mi_grid_base) return 1; return 0; @@ -1019,18 +1027,12 @@ static void dealloc_compressor_data(VP9_COMP *cpi) { vpx_free(cpi->mb_wiener_variance); cpi->mb_wiener_variance = NULL; + vpx_free(cpi->sb_mul_scale); + cpi->sb_mul_scale = NULL; + vpx_free(cpi->mi_ssim_rdmult_scaling_factors); cpi->mi_ssim_rdmult_scaling_factors = NULL; -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - free_partition_info(cpi); - free_motion_vector_info(cpi); - free_fp_motion_vector_info(cpi); - free_tpl_stats_info(cpi); - } -#endif - vp9_free_ref_frame_buffers(cm->buffer_pool); #if CONFIG_VP9_POSTPROC vp9_free_postproc_buffers(cm); @@ -1040,8 +1042,8 @@ static void dealloc_compressor_data(VP9_COMP *cpi) { vpx_free_frame_buffer(&cpi->last_frame_uf); vpx_free_frame_buffer(&cpi->scaled_source); vpx_free_frame_buffer(&cpi->scaled_last_source); - vpx_free_frame_buffer(&cpi->alt_ref_buffer); -#ifdef ENABLE_KF_DENOISE + vpx_free_frame_buffer(&cpi->tf_buffer); +#if defined(ENABLE_KF_DENOISE) || CONFIG_VP9_TEMPORAL_DENOISING vpx_free_frame_buffer(&cpi->raw_unscaled_source); vpx_free_frame_buffer(&cpi->raw_scaled_source); #endif @@ -1056,18 +1058,6 @@ static void dealloc_compressor_data(VP9_COMP *cpi) { vp9_free_pc_tree(&cpi->td); - for (i = 0; i < cpi->svc.number_spatial_layers; ++i) { - LAYER_CONTEXT *const lc = &cpi->svc.layer_context[i]; - vpx_free(lc->rc_twopass_stats_in.buf); - lc->rc_twopass_stats_in.buf = NULL; - lc->rc_twopass_stats_in.sz = 0; - } - - if (cpi->source_diff_var != NULL) { - vpx_free(cpi->source_diff_var); - cpi->source_diff_var = NULL; - } - for (i = 0; i < MAX_LAG_BUFFERS; ++i) { vpx_free_frame_buffer(&cpi->svc.scaled_frames[i]); } @@ -1297,7 +1287,7 @@ static void alloc_raw_frame_buffers(VP9_COMP *cpi) { "Failed to allocate lag buffers"); // TODO(agrange) Check if ARF is enabled and skip allocation if not. - if (vpx_realloc_frame_buffer(&cpi->alt_ref_buffer, oxcf->width, oxcf->height, + if (vpx_realloc_frame_buffer(&cpi->tf_buffer, oxcf->width, oxcf->height, cm->subsampling_x, cm->subsampling_y, #if CONFIG_VP9_HIGHBITDEPTH cm->use_highbitdepth, @@ -1305,7 +1295,7 @@ static void alloc_raw_frame_buffers(VP9_COMP *cpi) { VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, - "Failed to allocate altref buffer"); + "Failed to allocate temporal filter buffer"); } static void alloc_util_frame_buffers(VP9_COMP *cpi) { @@ -1333,7 +1323,7 @@ static void alloc_util_frame_buffers(VP9_COMP *cpi) { // For 1 pass cbr: allocate scaled_frame that may be used as an intermediate // buffer for a 2 stage down-sampling: two stages of 1:2 down-sampling for a // target of 1/4x1/4. number_spatial_layers must be greater than 2. - if (is_one_pass_cbr_svc(cpi) && !cpi->svc.scaled_temp_is_alloc && + if (is_one_pass_svc(cpi) && !cpi->svc.scaled_temp_is_alloc && cpi->svc.number_spatial_layers > 2) { cpi->svc.scaled_temp_is_alloc = 1; if (vpx_realloc_frame_buffer( @@ -1383,7 +1373,7 @@ static void alloc_context_buffers_ext(VP9_COMP *cpi) { VP9_COMMON *cm = &cpi->common; int mi_size = cm->mi_cols * cm->mi_rows; - CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, + CHECK_MEM_ERROR(&cm->error, cpi->mbmi_ext_base, vpx_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); } @@ -1399,20 +1389,48 @@ static void alloc_compressor_data(VP9_COMP *cpi) { alloc_context_buffers_ext(cpi); vpx_free(cpi->tile_tok[0][0]); + cpi->tile_tok[0][0] = NULL; { - unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); - CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], - vpx_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); + int64_t tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); +#if INT64_MAX > SIZE_MAX + if ((uint64_t)tokens > SIZE_MAX) { + vpx_internal_error( + &cm->error, VPX_CODEC_MEM_ERROR, + "Size of cpi->tile_tok[0][0] can't be represented in size_t"); + } +#endif + // The token buffer is sized for the worst case, but only the + // [start, start + count) range of each superblock row that was written + // during tokenization is ever read back by the bitstream packer. Allocate + // it without zeroing so that the pages a frame does not use are never + // touched, which keeps them out of the resident set. + { + const size_t tok_size = (size_t)tokens * sizeof(*cpi->tile_tok[0][0]); + if (tok_size / sizeof(*cpi->tile_tok[0][0]) != (size_t)tokens) { + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, + "Size of cpi->tile_tok[0][0] overflows size_t"); + } + CHECK_MEM_ERROR(&cm->error, cpi->tile_tok[0][0], vpx_malloc(tok_size)); + } } sb_rows = mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2; vpx_free(cpi->tplist[0][0]); CHECK_MEM_ERROR( - cm, cpi->tplist[0][0], + &cm->error, cpi->tplist[0][0], vpx_calloc(sb_rows * 4 * (1 << 6), sizeof(*cpi->tplist[0][0]))); vp9_setup_pc_tree(&cpi->common, &cpi->td); + + if (cpi->kmeans_data_arr_alloc) { +#if CONFIG_MULTITHREAD + pthread_mutex_destroy(&cpi->kmeans_mutex); +#endif + vpx_free(cpi->kmeans_data_arr); + cpi->kmeans_data_arr = NULL; + cpi->kmeans_data_arr_alloc = 0; + } } void vp9_new_framerate(VP9_COMP *cpi, double framerate) { @@ -1428,7 +1446,14 @@ static void set_tile_limits(VP9_COMP *cpi) { cm->log2_tile_cols = clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols); - cm->log2_tile_rows = cpi->oxcf.tile_rows; + + // Max allowed number of tile_rows is 4 (so log2_tile_rows = 2), and each + // tile_row contains a multiple of superblocks. + const int sb64_rows = mi_cols_aligned_to_sb(cm->mi_rows) >> 3; + const int max_log2_tile_rows = (sb64_rows >= 4) ? 2 + : (sb64_rows >= 2) ? 1 + : 0; + cm->log2_tile_rows = VPXMIN(cpi->oxcf.tile_rows, max_log2_tile_rows); if (cpi->oxcf.target_level == LEVEL_AUTO) { const int level_tile_cols = @@ -1511,10 +1536,8 @@ static void init_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { // Temporal scalability. cpi->svc.number_temporal_layers = oxcf->ts_number_layers; - if ((cpi->svc.number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) || - ((cpi->svc.number_temporal_layers > 1 || - cpi->svc.number_spatial_layers > 1) && - cpi->oxcf.pass != 1)) { + if (cpi->svc.number_temporal_layers > 1 || + cpi->svc.number_spatial_layers > 1) { vp9_init_layer_context(cpi); } @@ -1527,6 +1550,7 @@ static void init_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { init_buffer_indices(cpi); vp9_noise_estimate_init(&cpi->noise_estimate, cm->width, cm->height); + cpi->fixed_qp_onepass = 0; } void vp9_check_reset_rc_flag(VP9_COMP *cpi) { @@ -1537,7 +1561,7 @@ void vp9_check_reset_rc_flag(VP9_COMP *cpi) { if (cpi->use_svc) { vp9_svc_check_reset_layer_rc_flag(cpi); } else { - if (rc->avg_frame_bandwidth > (3 * rc->last_avg_frame_bandwidth >> 1) || + if (rc->avg_frame_bandwidth / 3 > (rc->last_avg_frame_bandwidth >> 1) || rc->avg_frame_bandwidth < (rc->last_avg_frame_bandwidth >> 1)) { rc->rc_1_frame = 0; rc->rc_2_frame = 0; @@ -1570,13 +1594,15 @@ void vp9_set_rc_buffer_sizes(VP9_COMP *cpi) { } #if CONFIG_VP9_HIGHBITDEPTH -#define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF) \ - cpi->fn_ptr[BT].sdf = SDF; \ - cpi->fn_ptr[BT].sdaf = SDAF; \ - cpi->fn_ptr[BT].vf = VF; \ - cpi->fn_ptr[BT].svf = SVF; \ - cpi->fn_ptr[BT].svaf = SVAF; \ - cpi->fn_ptr[BT].sdx4df = SDX4DF; +#define HIGHBD_BFP(BT, SDF, SDSF, SDAF, VF, SVF, SVAF, SDX4DF, SDSX4DF) \ + cpi->fn_ptr[BT].sdf = SDF; \ + cpi->fn_ptr[BT].sdsf = SDSF; \ + cpi->fn_ptr[BT].sdaf = SDAF; \ + cpi->fn_ptr[BT].vf = VF; \ + cpi->fn_ptr[BT].svf = SVF; \ + cpi->fn_ptr[BT].svaf = SVAF; \ + cpi->fn_ptr[BT].sdx4df = SDX4DF; \ + cpi->fn_ptr[BT].sdsx4df = SDSX4DF; #define MAKE_BFP_SAD_WRAPPER(fnname) \ static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ @@ -1636,284 +1662,361 @@ void vp9_set_rc_buffer_sizes(VP9_COMP *cpi) { } MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad32x16) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_32x16) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad32x16_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad32x16x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_32x16x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad16x32) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_16x32) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad16x32_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad16x32x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_16x32x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad64x32) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_64x32) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad64x32_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad64x32x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_64x32x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad32x64) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_32x64) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad32x64_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad32x64x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_32x64x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad32x32) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_32x32) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad32x32_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad32x32x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_32x32x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad64x64) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_64x64) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad64x64_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad64x64x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_64x64x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad16x16) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_16x16) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad16x16_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad16x16x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_16x16x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad16x8) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_16x8) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad16x8_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad16x8x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_16x8x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad8x16) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_8x16) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad8x16_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad8x16x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_8x16x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad8x8) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_8x8) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad8x8_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad8x8x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_8x8x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad8x4) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_8x4) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad8x4_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad8x4x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_8x4x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad4x8) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_4x8) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad4x8_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad4x8x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_4x8x4d) + MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad4x4) +MAKE_BFP_SAD_WRAPPER(vpx_highbd_sad_skip_4x4) MAKE_BFP_SADAVG_WRAPPER(vpx_highbd_sad4x4_avg) MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad4x4x4d) +MAKE_BFP_SAD4D_WRAPPER(vpx_highbd_sad_skip_4x4x4d) static void highbd_set_var_fns(VP9_COMP *const cpi) { VP9_COMMON *const cm = &cpi->common; if (cm->use_highbitdepth) { switch (cm->bit_depth) { case VPX_BITS_8: - HIGHBD_BFP(BLOCK_32X16, vpx_highbd_sad32x16_bits8, - vpx_highbd_sad32x16_avg_bits8, vpx_highbd_8_variance32x16, - vpx_highbd_8_sub_pixel_variance32x16, - vpx_highbd_8_sub_pixel_avg_variance32x16, - vpx_highbd_sad32x16x4d_bits8) - - HIGHBD_BFP(BLOCK_16X32, vpx_highbd_sad16x32_bits8, - vpx_highbd_sad16x32_avg_bits8, vpx_highbd_8_variance16x32, - vpx_highbd_8_sub_pixel_variance16x32, - vpx_highbd_8_sub_pixel_avg_variance16x32, - vpx_highbd_sad16x32x4d_bits8) - - HIGHBD_BFP(BLOCK_64X32, vpx_highbd_sad64x32_bits8, - vpx_highbd_sad64x32_avg_bits8, vpx_highbd_8_variance64x32, - vpx_highbd_8_sub_pixel_variance64x32, - vpx_highbd_8_sub_pixel_avg_variance64x32, - vpx_highbd_sad64x32x4d_bits8) - - HIGHBD_BFP(BLOCK_32X64, vpx_highbd_sad32x64_bits8, - vpx_highbd_sad32x64_avg_bits8, vpx_highbd_8_variance32x64, - vpx_highbd_8_sub_pixel_variance32x64, - vpx_highbd_8_sub_pixel_avg_variance32x64, - vpx_highbd_sad32x64x4d_bits8) - - HIGHBD_BFP(BLOCK_32X32, vpx_highbd_sad32x32_bits8, - vpx_highbd_sad32x32_avg_bits8, vpx_highbd_8_variance32x32, - vpx_highbd_8_sub_pixel_variance32x32, - vpx_highbd_8_sub_pixel_avg_variance32x32, - vpx_highbd_sad32x32x4d_bits8) - - HIGHBD_BFP(BLOCK_64X64, vpx_highbd_sad64x64_bits8, - vpx_highbd_sad64x64_avg_bits8, vpx_highbd_8_variance64x64, - vpx_highbd_8_sub_pixel_variance64x64, - vpx_highbd_8_sub_pixel_avg_variance64x64, - vpx_highbd_sad64x64x4d_bits8) - - HIGHBD_BFP(BLOCK_16X16, vpx_highbd_sad16x16_bits8, - vpx_highbd_sad16x16_avg_bits8, vpx_highbd_8_variance16x16, - vpx_highbd_8_sub_pixel_variance16x16, - vpx_highbd_8_sub_pixel_avg_variance16x16, - vpx_highbd_sad16x16x4d_bits8) - - HIGHBD_BFP(BLOCK_16X8, vpx_highbd_sad16x8_bits8, - vpx_highbd_sad16x8_avg_bits8, vpx_highbd_8_variance16x8, - vpx_highbd_8_sub_pixel_variance16x8, - vpx_highbd_8_sub_pixel_avg_variance16x8, - vpx_highbd_sad16x8x4d_bits8) - - HIGHBD_BFP(BLOCK_8X16, vpx_highbd_sad8x16_bits8, - vpx_highbd_sad8x16_avg_bits8, vpx_highbd_8_variance8x16, - vpx_highbd_8_sub_pixel_variance8x16, - vpx_highbd_8_sub_pixel_avg_variance8x16, - vpx_highbd_sad8x16x4d_bits8) + HIGHBD_BFP( + BLOCK_32X16, vpx_highbd_sad32x16_bits8, + vpx_highbd_sad_skip_32x16_bits8, vpx_highbd_sad32x16_avg_bits8, + vpx_highbd_8_variance32x16, vpx_highbd_8_sub_pixel_variance32x16, + vpx_highbd_8_sub_pixel_avg_variance32x16, + vpx_highbd_sad32x16x4d_bits8, vpx_highbd_sad_skip_32x16x4d_bits8) HIGHBD_BFP( - BLOCK_8X8, vpx_highbd_sad8x8_bits8, vpx_highbd_sad8x8_avg_bits8, - vpx_highbd_8_variance8x8, vpx_highbd_8_sub_pixel_variance8x8, - vpx_highbd_8_sub_pixel_avg_variance8x8, vpx_highbd_sad8x8x4d_bits8) + BLOCK_16X32, vpx_highbd_sad16x32_bits8, + vpx_highbd_sad_skip_16x32_bits8, vpx_highbd_sad16x32_avg_bits8, + vpx_highbd_8_variance16x32, vpx_highbd_8_sub_pixel_variance16x32, + vpx_highbd_8_sub_pixel_avg_variance16x32, + vpx_highbd_sad16x32x4d_bits8, vpx_highbd_sad_skip_16x32x4d_bits8) HIGHBD_BFP( - BLOCK_8X4, vpx_highbd_sad8x4_bits8, vpx_highbd_sad8x4_avg_bits8, - vpx_highbd_8_variance8x4, vpx_highbd_8_sub_pixel_variance8x4, - vpx_highbd_8_sub_pixel_avg_variance8x4, vpx_highbd_sad8x4x4d_bits8) + BLOCK_64X32, vpx_highbd_sad64x32_bits8, + vpx_highbd_sad_skip_64x32_bits8, vpx_highbd_sad64x32_avg_bits8, + vpx_highbd_8_variance64x32, vpx_highbd_8_sub_pixel_variance64x32, + vpx_highbd_8_sub_pixel_avg_variance64x32, + vpx_highbd_sad64x32x4d_bits8, vpx_highbd_sad_skip_64x32x4d_bits8) HIGHBD_BFP( - BLOCK_4X8, vpx_highbd_sad4x8_bits8, vpx_highbd_sad4x8_avg_bits8, - vpx_highbd_8_variance4x8, vpx_highbd_8_sub_pixel_variance4x8, - vpx_highbd_8_sub_pixel_avg_variance4x8, vpx_highbd_sad4x8x4d_bits8) + BLOCK_32X64, vpx_highbd_sad32x64_bits8, + vpx_highbd_sad_skip_32x64_bits8, vpx_highbd_sad32x64_avg_bits8, + vpx_highbd_8_variance32x64, vpx_highbd_8_sub_pixel_variance32x64, + vpx_highbd_8_sub_pixel_avg_variance32x64, + vpx_highbd_sad32x64x4d_bits8, vpx_highbd_sad_skip_32x64x4d_bits8) HIGHBD_BFP( - BLOCK_4X4, vpx_highbd_sad4x4_bits8, vpx_highbd_sad4x4_avg_bits8, - vpx_highbd_8_variance4x4, vpx_highbd_8_sub_pixel_variance4x4, - vpx_highbd_8_sub_pixel_avg_variance4x4, vpx_highbd_sad4x4x4d_bits8) + BLOCK_32X32, vpx_highbd_sad32x32_bits8, + vpx_highbd_sad_skip_32x32_bits8, vpx_highbd_sad32x32_avg_bits8, + vpx_highbd_8_variance32x32, vpx_highbd_8_sub_pixel_variance32x32, + vpx_highbd_8_sub_pixel_avg_variance32x32, + vpx_highbd_sad32x32x4d_bits8, vpx_highbd_sad_skip_32x32x4d_bits8) + + HIGHBD_BFP( + BLOCK_64X64, vpx_highbd_sad64x64_bits8, + vpx_highbd_sad_skip_64x64_bits8, vpx_highbd_sad64x64_avg_bits8, + vpx_highbd_8_variance64x64, vpx_highbd_8_sub_pixel_variance64x64, + vpx_highbd_8_sub_pixel_avg_variance64x64, + vpx_highbd_sad64x64x4d_bits8, vpx_highbd_sad_skip_64x64x4d_bits8) + + HIGHBD_BFP( + BLOCK_16X16, vpx_highbd_sad16x16_bits8, + vpx_highbd_sad_skip_16x16_bits8, vpx_highbd_sad16x16_avg_bits8, + vpx_highbd_8_variance16x16, vpx_highbd_8_sub_pixel_variance16x16, + vpx_highbd_8_sub_pixel_avg_variance16x16, + vpx_highbd_sad16x16x4d_bits8, vpx_highbd_sad_skip_16x16x4d_bits8) + + HIGHBD_BFP( + BLOCK_16X8, vpx_highbd_sad16x8_bits8, + vpx_highbd_sad_skip_16x8_bits8, vpx_highbd_sad16x8_avg_bits8, + vpx_highbd_8_variance16x8, vpx_highbd_8_sub_pixel_variance16x8, + vpx_highbd_8_sub_pixel_avg_variance16x8, + vpx_highbd_sad16x8x4d_bits8, vpx_highbd_sad_skip_16x8x4d_bits8) + + HIGHBD_BFP( + BLOCK_8X16, vpx_highbd_sad8x16_bits8, + vpx_highbd_sad_skip_8x16_bits8, vpx_highbd_sad8x16_avg_bits8, + vpx_highbd_8_variance8x16, vpx_highbd_8_sub_pixel_variance8x16, + vpx_highbd_8_sub_pixel_avg_variance8x16, + vpx_highbd_sad8x16x4d_bits8, vpx_highbd_sad_skip_8x16x4d_bits8) + + HIGHBD_BFP(BLOCK_8X8, vpx_highbd_sad8x8_bits8, + vpx_highbd_sad_skip_8x8_bits8, vpx_highbd_sad8x8_avg_bits8, + vpx_highbd_8_variance8x8, vpx_highbd_8_sub_pixel_variance8x8, + vpx_highbd_8_sub_pixel_avg_variance8x8, + vpx_highbd_sad8x8x4d_bits8, vpx_highbd_sad_skip_8x8x4d_bits8) + + HIGHBD_BFP(BLOCK_8X4, vpx_highbd_sad8x4_bits8, + vpx_highbd_sad_skip_8x4_bits8, vpx_highbd_sad8x4_avg_bits8, + vpx_highbd_8_variance8x4, vpx_highbd_8_sub_pixel_variance8x4, + vpx_highbd_8_sub_pixel_avg_variance8x4, + vpx_highbd_sad8x4x4d_bits8, vpx_highbd_sad_skip_8x4x4d_bits8) + + HIGHBD_BFP(BLOCK_4X8, vpx_highbd_sad4x8_bits8, + vpx_highbd_sad_skip_4x8_bits8, vpx_highbd_sad4x8_avg_bits8, + vpx_highbd_8_variance4x8, vpx_highbd_8_sub_pixel_variance4x8, + vpx_highbd_8_sub_pixel_avg_variance4x8, + vpx_highbd_sad4x8x4d_bits8, vpx_highbd_sad_skip_4x8x4d_bits8) + + HIGHBD_BFP(BLOCK_4X4, vpx_highbd_sad4x4_bits8, + vpx_highbd_sad_skip_4x4_bits8, vpx_highbd_sad4x4_avg_bits8, + vpx_highbd_8_variance4x4, vpx_highbd_8_sub_pixel_variance4x4, + vpx_highbd_8_sub_pixel_avg_variance4x4, + vpx_highbd_sad4x4x4d_bits8, vpx_highbd_sad_skip_4x4x4d_bits8) break; case VPX_BITS_10: - HIGHBD_BFP(BLOCK_32X16, vpx_highbd_sad32x16_bits10, - vpx_highbd_sad32x16_avg_bits10, vpx_highbd_10_variance32x16, - vpx_highbd_10_sub_pixel_variance32x16, - vpx_highbd_10_sub_pixel_avg_variance32x16, - vpx_highbd_sad32x16x4d_bits10) + HIGHBD_BFP( + BLOCK_32X16, vpx_highbd_sad32x16_bits10, + vpx_highbd_sad_skip_32x16_bits10, vpx_highbd_sad32x16_avg_bits10, + vpx_highbd_10_variance32x16, vpx_highbd_10_sub_pixel_variance32x16, + vpx_highbd_10_sub_pixel_avg_variance32x16, + vpx_highbd_sad32x16x4d_bits10, vpx_highbd_sad_skip_32x16x4d_bits10) - HIGHBD_BFP(BLOCK_16X32, vpx_highbd_sad16x32_bits10, - vpx_highbd_sad16x32_avg_bits10, vpx_highbd_10_variance16x32, - vpx_highbd_10_sub_pixel_variance16x32, - vpx_highbd_10_sub_pixel_avg_variance16x32, - vpx_highbd_sad16x32x4d_bits10) + HIGHBD_BFP( + BLOCK_16X32, vpx_highbd_sad16x32_bits10, + vpx_highbd_sad_skip_16x32_bits10, vpx_highbd_sad16x32_avg_bits10, + vpx_highbd_10_variance16x32, vpx_highbd_10_sub_pixel_variance16x32, + vpx_highbd_10_sub_pixel_avg_variance16x32, + vpx_highbd_sad16x32x4d_bits10, vpx_highbd_sad_skip_16x32x4d_bits10) - HIGHBD_BFP(BLOCK_64X32, vpx_highbd_sad64x32_bits10, - vpx_highbd_sad64x32_avg_bits10, vpx_highbd_10_variance64x32, - vpx_highbd_10_sub_pixel_variance64x32, - vpx_highbd_10_sub_pixel_avg_variance64x32, - vpx_highbd_sad64x32x4d_bits10) + HIGHBD_BFP( + BLOCK_64X32, vpx_highbd_sad64x32_bits10, + vpx_highbd_sad_skip_64x32_bits10, vpx_highbd_sad64x32_avg_bits10, + vpx_highbd_10_variance64x32, vpx_highbd_10_sub_pixel_variance64x32, + vpx_highbd_10_sub_pixel_avg_variance64x32, + vpx_highbd_sad64x32x4d_bits10, vpx_highbd_sad_skip_64x32x4d_bits10) - HIGHBD_BFP(BLOCK_32X64, vpx_highbd_sad32x64_bits10, - vpx_highbd_sad32x64_avg_bits10, vpx_highbd_10_variance32x64, - vpx_highbd_10_sub_pixel_variance32x64, - vpx_highbd_10_sub_pixel_avg_variance32x64, - vpx_highbd_sad32x64x4d_bits10) + HIGHBD_BFP( + BLOCK_32X64, vpx_highbd_sad32x64_bits10, + vpx_highbd_sad_skip_32x64_bits10, vpx_highbd_sad32x64_avg_bits10, + vpx_highbd_10_variance32x64, vpx_highbd_10_sub_pixel_variance32x64, + vpx_highbd_10_sub_pixel_avg_variance32x64, + vpx_highbd_sad32x64x4d_bits10, vpx_highbd_sad_skip_32x64x4d_bits10) - HIGHBD_BFP(BLOCK_32X32, vpx_highbd_sad32x32_bits10, - vpx_highbd_sad32x32_avg_bits10, vpx_highbd_10_variance32x32, - vpx_highbd_10_sub_pixel_variance32x32, - vpx_highbd_10_sub_pixel_avg_variance32x32, - vpx_highbd_sad32x32x4d_bits10) + HIGHBD_BFP( + BLOCK_32X32, vpx_highbd_sad32x32_bits10, + vpx_highbd_sad_skip_32x32_bits10, vpx_highbd_sad32x32_avg_bits10, + vpx_highbd_10_variance32x32, vpx_highbd_10_sub_pixel_variance32x32, + vpx_highbd_10_sub_pixel_avg_variance32x32, + vpx_highbd_sad32x32x4d_bits10, vpx_highbd_sad_skip_32x32x4d_bits10) - HIGHBD_BFP(BLOCK_64X64, vpx_highbd_sad64x64_bits10, - vpx_highbd_sad64x64_avg_bits10, vpx_highbd_10_variance64x64, - vpx_highbd_10_sub_pixel_variance64x64, - vpx_highbd_10_sub_pixel_avg_variance64x64, - vpx_highbd_sad64x64x4d_bits10) + HIGHBD_BFP( + BLOCK_64X64, vpx_highbd_sad64x64_bits10, + vpx_highbd_sad_skip_64x64_bits10, vpx_highbd_sad64x64_avg_bits10, + vpx_highbd_10_variance64x64, vpx_highbd_10_sub_pixel_variance64x64, + vpx_highbd_10_sub_pixel_avg_variance64x64, + vpx_highbd_sad64x64x4d_bits10, vpx_highbd_sad_skip_64x64x4d_bits10) - HIGHBD_BFP(BLOCK_16X16, vpx_highbd_sad16x16_bits10, - vpx_highbd_sad16x16_avg_bits10, vpx_highbd_10_variance16x16, - vpx_highbd_10_sub_pixel_variance16x16, - vpx_highbd_10_sub_pixel_avg_variance16x16, - vpx_highbd_sad16x16x4d_bits10) + HIGHBD_BFP( + BLOCK_16X16, vpx_highbd_sad16x16_bits10, + vpx_highbd_sad_skip_16x16_bits10, vpx_highbd_sad16x16_avg_bits10, + vpx_highbd_10_variance16x16, vpx_highbd_10_sub_pixel_variance16x16, + vpx_highbd_10_sub_pixel_avg_variance16x16, + vpx_highbd_sad16x16x4d_bits10, vpx_highbd_sad_skip_16x16x4d_bits10) - HIGHBD_BFP(BLOCK_16X8, vpx_highbd_sad16x8_bits10, - vpx_highbd_sad16x8_avg_bits10, vpx_highbd_10_variance16x8, - vpx_highbd_10_sub_pixel_variance16x8, - vpx_highbd_10_sub_pixel_avg_variance16x8, - vpx_highbd_sad16x8x4d_bits10) + HIGHBD_BFP( + BLOCK_16X8, vpx_highbd_sad16x8_bits10, + vpx_highbd_sad_skip_16x8_bits10, vpx_highbd_sad16x8_avg_bits10, + vpx_highbd_10_variance16x8, vpx_highbd_10_sub_pixel_variance16x8, + vpx_highbd_10_sub_pixel_avg_variance16x8, + vpx_highbd_sad16x8x4d_bits10, vpx_highbd_sad_skip_16x8x4d_bits10) - HIGHBD_BFP(BLOCK_8X16, vpx_highbd_sad8x16_bits10, - vpx_highbd_sad8x16_avg_bits10, vpx_highbd_10_variance8x16, - vpx_highbd_10_sub_pixel_variance8x16, - vpx_highbd_10_sub_pixel_avg_variance8x16, - vpx_highbd_sad8x16x4d_bits10) + HIGHBD_BFP( + BLOCK_8X16, vpx_highbd_sad8x16_bits10, + vpx_highbd_sad_skip_8x16_bits10, vpx_highbd_sad8x16_avg_bits10, + vpx_highbd_10_variance8x16, vpx_highbd_10_sub_pixel_variance8x16, + vpx_highbd_10_sub_pixel_avg_variance8x16, + vpx_highbd_sad8x16x4d_bits10, vpx_highbd_sad_skip_8x16x4d_bits10) - HIGHBD_BFP(BLOCK_8X8, vpx_highbd_sad8x8_bits10, - vpx_highbd_sad8x8_avg_bits10, vpx_highbd_10_variance8x8, - vpx_highbd_10_sub_pixel_variance8x8, - vpx_highbd_10_sub_pixel_avg_variance8x8, - vpx_highbd_sad8x8x4d_bits10) + HIGHBD_BFP( + BLOCK_8X8, vpx_highbd_sad8x8_bits10, vpx_highbd_sad_skip_8x8_bits10, + vpx_highbd_sad8x8_avg_bits10, vpx_highbd_10_variance8x8, + vpx_highbd_10_sub_pixel_variance8x8, + vpx_highbd_10_sub_pixel_avg_variance8x8, + vpx_highbd_sad8x8x4d_bits10, vpx_highbd_sad_skip_8x8x4d_bits10) - HIGHBD_BFP(BLOCK_8X4, vpx_highbd_sad8x4_bits10, - vpx_highbd_sad8x4_avg_bits10, vpx_highbd_10_variance8x4, - vpx_highbd_10_sub_pixel_variance8x4, - vpx_highbd_10_sub_pixel_avg_variance8x4, - vpx_highbd_sad8x4x4d_bits10) + HIGHBD_BFP( + BLOCK_8X4, vpx_highbd_sad8x4_bits10, vpx_highbd_sad_skip_8x4_bits10, + vpx_highbd_sad8x4_avg_bits10, vpx_highbd_10_variance8x4, + vpx_highbd_10_sub_pixel_variance8x4, + vpx_highbd_10_sub_pixel_avg_variance8x4, + vpx_highbd_sad8x4x4d_bits10, vpx_highbd_sad_skip_8x4x4d_bits10) - HIGHBD_BFP(BLOCK_4X8, vpx_highbd_sad4x8_bits10, - vpx_highbd_sad4x8_avg_bits10, vpx_highbd_10_variance4x8, - vpx_highbd_10_sub_pixel_variance4x8, - vpx_highbd_10_sub_pixel_avg_variance4x8, - vpx_highbd_sad4x8x4d_bits10) + HIGHBD_BFP( + BLOCK_4X8, vpx_highbd_sad4x8_bits10, vpx_highbd_sad_skip_4x8_bits10, + vpx_highbd_sad4x8_avg_bits10, vpx_highbd_10_variance4x8, + vpx_highbd_10_sub_pixel_variance4x8, + vpx_highbd_10_sub_pixel_avg_variance4x8, + vpx_highbd_sad4x8x4d_bits10, vpx_highbd_sad_skip_4x8x4d_bits10) - HIGHBD_BFP(BLOCK_4X4, vpx_highbd_sad4x4_bits10, - vpx_highbd_sad4x4_avg_bits10, vpx_highbd_10_variance4x4, - vpx_highbd_10_sub_pixel_variance4x4, - vpx_highbd_10_sub_pixel_avg_variance4x4, - vpx_highbd_sad4x4x4d_bits10) + HIGHBD_BFP( + BLOCK_4X4, vpx_highbd_sad4x4_bits10, vpx_highbd_sad_skip_4x4_bits10, + vpx_highbd_sad4x4_avg_bits10, vpx_highbd_10_variance4x4, + vpx_highbd_10_sub_pixel_variance4x4, + vpx_highbd_10_sub_pixel_avg_variance4x4, + vpx_highbd_sad4x4x4d_bits10, vpx_highbd_sad_skip_4x4x4d_bits10) break; default: assert(cm->bit_depth == VPX_BITS_12); - HIGHBD_BFP(BLOCK_32X16, vpx_highbd_sad32x16_bits12, - vpx_highbd_sad32x16_avg_bits12, vpx_highbd_12_variance32x16, - vpx_highbd_12_sub_pixel_variance32x16, - vpx_highbd_12_sub_pixel_avg_variance32x16, - vpx_highbd_sad32x16x4d_bits12) + HIGHBD_BFP( + BLOCK_32X16, vpx_highbd_sad32x16_bits12, + vpx_highbd_sad_skip_32x16_bits12, vpx_highbd_sad32x16_avg_bits12, + vpx_highbd_12_variance32x16, vpx_highbd_12_sub_pixel_variance32x16, + vpx_highbd_12_sub_pixel_avg_variance32x16, + vpx_highbd_sad32x16x4d_bits12, vpx_highbd_sad_skip_32x16x4d_bits12) - HIGHBD_BFP(BLOCK_16X32, vpx_highbd_sad16x32_bits12, - vpx_highbd_sad16x32_avg_bits12, vpx_highbd_12_variance16x32, - vpx_highbd_12_sub_pixel_variance16x32, - vpx_highbd_12_sub_pixel_avg_variance16x32, - vpx_highbd_sad16x32x4d_bits12) + HIGHBD_BFP( + BLOCK_16X32, vpx_highbd_sad16x32_bits12, + vpx_highbd_sad_skip_16x32_bits12, vpx_highbd_sad16x32_avg_bits12, + vpx_highbd_12_variance16x32, vpx_highbd_12_sub_pixel_variance16x32, + vpx_highbd_12_sub_pixel_avg_variance16x32, + vpx_highbd_sad16x32x4d_bits12, vpx_highbd_sad_skip_16x32x4d_bits12) - HIGHBD_BFP(BLOCK_64X32, vpx_highbd_sad64x32_bits12, - vpx_highbd_sad64x32_avg_bits12, vpx_highbd_12_variance64x32, - vpx_highbd_12_sub_pixel_variance64x32, - vpx_highbd_12_sub_pixel_avg_variance64x32, - vpx_highbd_sad64x32x4d_bits12) + HIGHBD_BFP( + BLOCK_64X32, vpx_highbd_sad64x32_bits12, + vpx_highbd_sad_skip_64x32_bits12, vpx_highbd_sad64x32_avg_bits12, + vpx_highbd_12_variance64x32, vpx_highbd_12_sub_pixel_variance64x32, + vpx_highbd_12_sub_pixel_avg_variance64x32, + vpx_highbd_sad64x32x4d_bits12, vpx_highbd_sad_skip_64x32x4d_bits12) - HIGHBD_BFP(BLOCK_32X64, vpx_highbd_sad32x64_bits12, - vpx_highbd_sad32x64_avg_bits12, vpx_highbd_12_variance32x64, - vpx_highbd_12_sub_pixel_variance32x64, - vpx_highbd_12_sub_pixel_avg_variance32x64, - vpx_highbd_sad32x64x4d_bits12) + HIGHBD_BFP( + BLOCK_32X64, vpx_highbd_sad32x64_bits12, + vpx_highbd_sad_skip_32x64_bits12, vpx_highbd_sad32x64_avg_bits12, + vpx_highbd_12_variance32x64, vpx_highbd_12_sub_pixel_variance32x64, + vpx_highbd_12_sub_pixel_avg_variance32x64, + vpx_highbd_sad32x64x4d_bits12, vpx_highbd_sad_skip_32x64x4d_bits12) - HIGHBD_BFP(BLOCK_32X32, vpx_highbd_sad32x32_bits12, - vpx_highbd_sad32x32_avg_bits12, vpx_highbd_12_variance32x32, - vpx_highbd_12_sub_pixel_variance32x32, - vpx_highbd_12_sub_pixel_avg_variance32x32, - vpx_highbd_sad32x32x4d_bits12) + HIGHBD_BFP( + BLOCK_32X32, vpx_highbd_sad32x32_bits12, + vpx_highbd_sad_skip_32x32_bits12, vpx_highbd_sad32x32_avg_bits12, + vpx_highbd_12_variance32x32, vpx_highbd_12_sub_pixel_variance32x32, + vpx_highbd_12_sub_pixel_avg_variance32x32, + vpx_highbd_sad32x32x4d_bits12, vpx_highbd_sad_skip_32x32x4d_bits12) - HIGHBD_BFP(BLOCK_64X64, vpx_highbd_sad64x64_bits12, - vpx_highbd_sad64x64_avg_bits12, vpx_highbd_12_variance64x64, - vpx_highbd_12_sub_pixel_variance64x64, - vpx_highbd_12_sub_pixel_avg_variance64x64, - vpx_highbd_sad64x64x4d_bits12) + HIGHBD_BFP( + BLOCK_64X64, vpx_highbd_sad64x64_bits12, + vpx_highbd_sad_skip_64x64_bits12, vpx_highbd_sad64x64_avg_bits12, + vpx_highbd_12_variance64x64, vpx_highbd_12_sub_pixel_variance64x64, + vpx_highbd_12_sub_pixel_avg_variance64x64, + vpx_highbd_sad64x64x4d_bits12, vpx_highbd_sad_skip_64x64x4d_bits12) - HIGHBD_BFP(BLOCK_16X16, vpx_highbd_sad16x16_bits12, - vpx_highbd_sad16x16_avg_bits12, vpx_highbd_12_variance16x16, - vpx_highbd_12_sub_pixel_variance16x16, - vpx_highbd_12_sub_pixel_avg_variance16x16, - vpx_highbd_sad16x16x4d_bits12) + HIGHBD_BFP( + BLOCK_16X16, vpx_highbd_sad16x16_bits12, + vpx_highbd_sad_skip_16x16_bits12, vpx_highbd_sad16x16_avg_bits12, + vpx_highbd_12_variance16x16, vpx_highbd_12_sub_pixel_variance16x16, + vpx_highbd_12_sub_pixel_avg_variance16x16, + vpx_highbd_sad16x16x4d_bits12, vpx_highbd_sad_skip_16x16x4d_bits12) - HIGHBD_BFP(BLOCK_16X8, vpx_highbd_sad16x8_bits12, - vpx_highbd_sad16x8_avg_bits12, vpx_highbd_12_variance16x8, - vpx_highbd_12_sub_pixel_variance16x8, - vpx_highbd_12_sub_pixel_avg_variance16x8, - vpx_highbd_sad16x8x4d_bits12) + HIGHBD_BFP( + BLOCK_16X8, vpx_highbd_sad16x8_bits12, + vpx_highbd_sad_skip_16x8_bits12, vpx_highbd_sad16x8_avg_bits12, + vpx_highbd_12_variance16x8, vpx_highbd_12_sub_pixel_variance16x8, + vpx_highbd_12_sub_pixel_avg_variance16x8, + vpx_highbd_sad16x8x4d_bits12, vpx_highbd_sad_skip_16x8x4d_bits12) - HIGHBD_BFP(BLOCK_8X16, vpx_highbd_sad8x16_bits12, - vpx_highbd_sad8x16_avg_bits12, vpx_highbd_12_variance8x16, - vpx_highbd_12_sub_pixel_variance8x16, - vpx_highbd_12_sub_pixel_avg_variance8x16, - vpx_highbd_sad8x16x4d_bits12) + HIGHBD_BFP( + BLOCK_8X16, vpx_highbd_sad8x16_bits12, + vpx_highbd_sad_skip_8x16_bits12, vpx_highbd_sad8x16_avg_bits12, + vpx_highbd_12_variance8x16, vpx_highbd_12_sub_pixel_variance8x16, + vpx_highbd_12_sub_pixel_avg_variance8x16, + vpx_highbd_sad8x16x4d_bits12, vpx_highbd_sad_skip_8x16x4d_bits12) - HIGHBD_BFP(BLOCK_8X8, vpx_highbd_sad8x8_bits12, - vpx_highbd_sad8x8_avg_bits12, vpx_highbd_12_variance8x8, - vpx_highbd_12_sub_pixel_variance8x8, - vpx_highbd_12_sub_pixel_avg_variance8x8, - vpx_highbd_sad8x8x4d_bits12) + HIGHBD_BFP( + BLOCK_8X8, vpx_highbd_sad8x8_bits12, vpx_highbd_sad_skip_8x8_bits12, + vpx_highbd_sad8x8_avg_bits12, vpx_highbd_12_variance8x8, + vpx_highbd_12_sub_pixel_variance8x8, + vpx_highbd_12_sub_pixel_avg_variance8x8, + vpx_highbd_sad8x8x4d_bits12, vpx_highbd_sad_skip_8x8x4d_bits12) - HIGHBD_BFP(BLOCK_8X4, vpx_highbd_sad8x4_bits12, - vpx_highbd_sad8x4_avg_bits12, vpx_highbd_12_variance8x4, - vpx_highbd_12_sub_pixel_variance8x4, - vpx_highbd_12_sub_pixel_avg_variance8x4, - vpx_highbd_sad8x4x4d_bits12) + HIGHBD_BFP( + BLOCK_8X4, vpx_highbd_sad8x4_bits12, vpx_highbd_sad_skip_8x4_bits12, + vpx_highbd_sad8x4_avg_bits12, vpx_highbd_12_variance8x4, + vpx_highbd_12_sub_pixel_variance8x4, + vpx_highbd_12_sub_pixel_avg_variance8x4, + vpx_highbd_sad8x4x4d_bits12, vpx_highbd_sad_skip_8x4x4d_bits12) - HIGHBD_BFP(BLOCK_4X8, vpx_highbd_sad4x8_bits12, - vpx_highbd_sad4x8_avg_bits12, vpx_highbd_12_variance4x8, - vpx_highbd_12_sub_pixel_variance4x8, - vpx_highbd_12_sub_pixel_avg_variance4x8, - vpx_highbd_sad4x8x4d_bits12) + HIGHBD_BFP( + BLOCK_4X8, vpx_highbd_sad4x8_bits12, vpx_highbd_sad_skip_4x8_bits12, + vpx_highbd_sad4x8_avg_bits12, vpx_highbd_12_variance4x8, + vpx_highbd_12_sub_pixel_variance4x8, + vpx_highbd_12_sub_pixel_avg_variance4x8, + vpx_highbd_sad4x8x4d_bits12, vpx_highbd_sad_skip_4x8x4d_bits12) - HIGHBD_BFP(BLOCK_4X4, vpx_highbd_sad4x4_bits12, - vpx_highbd_sad4x4_avg_bits12, vpx_highbd_12_variance4x4, - vpx_highbd_12_sub_pixel_variance4x4, - vpx_highbd_12_sub_pixel_avg_variance4x4, - vpx_highbd_sad4x4x4d_bits12) + HIGHBD_BFP( + BLOCK_4X4, vpx_highbd_sad4x4_bits12, vpx_highbd_sad_skip_4x4_bits12, + vpx_highbd_sad4x4_avg_bits12, vpx_highbd_12_variance4x4, + vpx_highbd_12_sub_pixel_variance4x4, + vpx_highbd_12_sub_pixel_avg_variance4x4, + vpx_highbd_sad4x4x4d_bits12, vpx_highbd_sad_skip_4x4x4d_bits12) break; } } @@ -1925,48 +2028,48 @@ static void realloc_segmentation_maps(VP9_COMP *cpi) { // Create the encoder segmentation map and set all entries to 0 vpx_free(cpi->segmentation_map); - CHECK_MEM_ERROR(cm, cpi->segmentation_map, + CHECK_MEM_ERROR(&cm->error, cpi->segmentation_map, vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); // Create a map used for cyclic background refresh. if (cpi->cyclic_refresh) vp9_cyclic_refresh_free(cpi->cyclic_refresh); - CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, + CHECK_MEM_ERROR(&cm->error, cpi->cyclic_refresh, vp9_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); // Create a map used to mark inactive areas. vpx_free(cpi->active_map.map); - CHECK_MEM_ERROR(cm, cpi->active_map.map, + CHECK_MEM_ERROR(&cm->error, cpi->active_map.map, vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); // And a place holder structure is the coding context // for use if we want to save and restore it vpx_free(cpi->coding_context.last_frame_seg_map_copy); - CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy, + CHECK_MEM_ERROR(&cm->error, cpi->coding_context.last_frame_seg_map_copy, vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); } static void alloc_copy_partition_data(VP9_COMP *cpi) { VP9_COMMON *const cm = &cpi->common; if (cpi->prev_partition == NULL) { - CHECK_MEM_ERROR(cm, cpi->prev_partition, + CHECK_MEM_ERROR(&cm->error, cpi->prev_partition, (BLOCK_SIZE *)vpx_calloc(cm->mi_stride * cm->mi_rows, sizeof(*cpi->prev_partition))); } if (cpi->prev_segment_id == NULL) { CHECK_MEM_ERROR( - cm, cpi->prev_segment_id, + &cm->error, cpi->prev_segment_id, (int8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(*cpi->prev_segment_id))); } if (cpi->prev_variance_low == NULL) { - CHECK_MEM_ERROR(cm, cpi->prev_variance_low, + CHECK_MEM_ERROR(&cm->error, cpi->prev_variance_low, (uint8_t *)vpx_calloc( (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1) * 25, sizeof(*cpi->prev_variance_low))); } if (cpi->copied_frame_cnt == NULL) { CHECK_MEM_ERROR( - cm, cpi->copied_frame_cnt, + &cm->error, cpi->copied_frame_cnt, (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(*cpi->copied_frame_cnt))); } @@ -1983,6 +2086,24 @@ static void free_copy_partition_data(VP9_COMP *cpi) { cpi->copied_frame_cnt = NULL; } +#if CONFIG_VP9_TEMPORAL_DENOISING +static void setup_denoiser_buffer(VP9_COMP *cpi) { + VP9_COMMON *const cm = &cpi->common; + if (cpi->oxcf.noise_sensitivity > 0 && + !cpi->denoiser.frame_buffer_initialized) { + if (vp9_denoiser_alloc(cm, &cpi->svc, &cpi->denoiser, cpi->use_svc, + cpi->oxcf.noise_sensitivity, cm->width, cm->height, + cm->subsampling_x, cm->subsampling_y, +#if CONFIG_VP9_HIGHBITDEPTH + cm->use_highbitdepth, +#endif + VP9_ENC_BORDER_IN_PIXELS)) + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, + "Failed to allocate denoiser"); + } +} +#endif + void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { VP9_COMMON *const cm = &cpi->common; RATE_CONTROL *const rc = &cpi->rc; @@ -2056,25 +2177,19 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { cpi->external_resize = 1; } - if (cpi->initial_width) { - int new_mi_size = 0; - vp9_set_mb_mi(cm, cm->width, cm->height); - new_mi_size = cm->mi_stride * calc_mi_size(cm->mi_rows); - if (cm->mi_alloc_size < new_mi_size) { - vp9_free_context_buffers(cm); - vp9_free_pc_tree(&cpi->td); - vpx_free(cpi->mbmi_ext_base); - alloc_compressor_data(cpi); - realloc_segmentation_maps(cpi); - cpi->initial_width = cpi->initial_height = 0; - cpi->external_resize = 0; - } else if (cm->mi_alloc_size == new_mi_size && - (cpi->oxcf.width > last_w || cpi->oxcf.height > last_h)) { - if (vp9_alloc_loop_filter(cm)) { - vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, - "Failed to allocate loop filter data"); - } - } + if (cpi->initial_width && cpi->initial_height && + (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { + vp9_free_context_buffers(cm); + vp9_free_pc_tree(&cpi->td); + vpx_free(cpi->mbmi_ext_base); + cpi->mbmi_ext_base = NULL; + vpx_free(cpi->content_state_sb_fd); + cpi->content_state_sb_fd = NULL; + alloc_compressor_data(cpi); + realloc_segmentation_maps(cpi); + cpi->initial_width = cm->width; + cpi->initial_height = cm->height; + cpi->external_resize = 0; } if (cm->current_video_frame == 0 || last_w != cpi->oxcf.width || @@ -2082,25 +2197,75 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { update_frame_size(cpi); if (last_w != cpi->oxcf.width || last_h != cpi->oxcf.height) { + int svc_alloc_mi_area = cm->mi_rows * cm->mi_cols; + if (cpi->svc.number_spatial_layers > 1 && cpi->initial_width && + cpi->initial_height) { + int init_mi_rows, init_mi_cols, init_mi_stride; + vp9_set_mi_size(&init_mi_rows, &init_mi_cols, &init_mi_stride, + cpi->initial_width, cpi->initial_height); + svc_alloc_mi_area = + VPXMAX(svc_alloc_mi_area, init_mi_rows * init_mi_cols); + } vpx_free(cpi->consec_zero_mv); CHECK_MEM_ERROR( - cm, cpi->consec_zero_mv, - vpx_calloc(cm->mi_rows * cm->mi_cols, sizeof(*cpi->consec_zero_mv))); + &cm->error, cpi->consec_zero_mv, + vpx_calloc(svc_alloc_mi_area, sizeof(*cpi->consec_zero_mv))); vpx_free(cpi->skin_map); - CHECK_MEM_ERROR( - cm, cpi->skin_map, - vpx_calloc(cm->mi_rows * cm->mi_cols, sizeof(cpi->skin_map[0]))); + CHECK_MEM_ERROR(&cm->error, cpi->skin_map, + vpx_calloc(svc_alloc_mi_area, sizeof(*cpi->skin_map))); + +#if CONFIG_VP9_TEMPORAL_DENOISING + // Reset the denoiser on the resize change. + if (cpi->oxcf.noise_sensitivity > 0 || + cpi->denoiser.frame_buffer_initialized) { + vp9_denoiser_free(&cpi->denoiser); + setup_denoiser_buffer(cpi); + } +#endif + + if (cpi->svc.number_spatial_layers > 1) { + for (int sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) { + const int layer = + LAYER_IDS_TO_IDX(sl, 0, cpi->svc.number_temporal_layers); + LAYER_CONTEXT *const lc = &cpi->svc.layer_context[layer]; + lc->sb_index = 0; + lc->actual_num_seg1_blocks = 0; + lc->actual_num_seg2_blocks = 0; + lc->counter_encode_maxq_scene_change = 0; + vpx_free(lc->map); + CHECK_MEM_ERROR(&cm->error, lc->map, + vpx_calloc(svc_alloc_mi_area, sizeof(*lc->map))); + vpx_free(lc->last_coded_q_map); + CHECK_MEM_ERROR( + &cm->error, lc->last_coded_q_map, + vpx_malloc(svc_alloc_mi_area * sizeof(*lc->last_coded_q_map))); + memset(lc->last_coded_q_map, MAXQ, svc_alloc_mi_area); + vpx_free(lc->consec_zero_mv); + CHECK_MEM_ERROR( + &cm->error, lc->consec_zero_mv, + vpx_calloc(svc_alloc_mi_area, sizeof(*lc->consec_zero_mv))); + } + if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { + cpi->refresh_golden_frame = 1; + cpi->refresh_alt_ref_frame = 1; + } + } free_copy_partition_data(cpi); alloc_copy_partition_data(cpi); - if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) + if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && + cpi->svc.number_spatial_layers == 1) vp9_cyclic_refresh_reset_resize(cpi); + vpx_free(cpi->count_arf_frame_usage); + cpi->count_arf_frame_usage = NULL; + vpx_free(cpi->count_lastgolden_frame_usage); + cpi->count_lastgolden_frame_usage = NULL; rc->rc_1_frame = 0; rc->rc_2_frame = 0; } - if ((cpi->svc.number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) || + if ((cpi->svc.number_temporal_layers > 1) || ((cpi->svc.number_temporal_layers > 1 || cpi->svc.number_spatial_layers > 1) && cpi->oxcf.pass != 1)) { @@ -2131,18 +2296,13 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { vp9_set_row_mt(cpi); } -#ifndef M_LOG2_E -#define M_LOG2_E 0.693147180559945309417 -#endif -#define log2f(x) (log(x) / (float)M_LOG2_E) - /*********************************************************************** * Read before modifying 'cal_nmvjointsadcost' or 'cal_nmvsadcosts' * *********************************************************************** * The following 2 functions ('cal_nmvjointsadcost' and * * 'cal_nmvsadcosts') are used to calculate cost lookup tables * * used by 'vp9_diamond_search_sad'. The C implementation of the * - * function is generic, but the AVX intrinsics optimised version * + * function is generic, but the NEON intrinsics optimised version * * relies on the following properties of the computed tables: * * For cal_nmvjointsadcost: * * - mvjointsadcost[1] == mvjointsadcost[2] == mvjointsadcost[3] * @@ -2151,7 +2311,7 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { * (Equal costs for both components) * * - For all i: mvsadcost[0][i] == mvsadcost[0][-i] * * (Cost function is even) * - * If these do not hold, then the AVX optimised version of the * + * If these do not hold, then the NEON optimised version of the * * 'vp9_diamond_search_sad' function cannot be used as it is, in which * * case you can revert to using the C function instead. * ***********************************************************************/ @@ -2231,85 +2391,25 @@ static void update_initial_width(VP9_COMP *cpi, int use_highbitdepth, cm->use_highbitdepth = use_highbitdepth; #endif alloc_util_frame_buffers(cpi); - cpi->initial_width = cm->width; - cpi->initial_height = cm->height; + // The initial_width/height is used to clamp the encoding width/height in + // vp9_set_size_literal(). The check below is added to avoid setting the + // initial_width/height to a smaller resolution than the one configured. + // This can happen when the user passes in a lower resolution on the very + // first frame (after creating the encoder with a larger resolution). For + // spatial layers this will prevent user from going back up in resolution + // (i.e., the top layer will get stuck at the lower resolution). + if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) { + cpi->initial_width = cm->width; + cpi->initial_height = cm->height; + } cpi->initial_mbs = cm->MBs; } } -// TODO(angiebird): Check whether we can move this function to vpx_image.c -static INLINE void vpx_img_chroma_subsampling(vpx_img_fmt_t fmt, - unsigned int *subsampling_x, - unsigned int *subsampling_y) { - switch (fmt) { - case VPX_IMG_FMT_I420: - case VPX_IMG_FMT_YV12: - case VPX_IMG_FMT_NV12: - case VPX_IMG_FMT_I422: - case VPX_IMG_FMT_I42016: - case VPX_IMG_FMT_I42216: *subsampling_x = 1; break; - default: *subsampling_x = 0; break; - } - - switch (fmt) { - case VPX_IMG_FMT_I420: - case VPX_IMG_FMT_I440: - case VPX_IMG_FMT_YV12: - case VPX_IMG_FMT_NV12: - case VPX_IMG_FMT_I42016: - case VPX_IMG_FMT_I44016: *subsampling_y = 1; break; - default: *subsampling_y = 0; break; - } -} - -// TODO(angiebird): Check whether we can move this function to vpx_image.c -static INLINE int vpx_img_use_highbitdepth(vpx_img_fmt_t fmt) { - return fmt & VPX_IMG_FMT_HIGHBITDEPTH; -} - -#if CONFIG_VP9_TEMPORAL_DENOISING -static void setup_denoiser_buffer(VP9_COMP *cpi) { - VP9_COMMON *const cm = &cpi->common; - if (cpi->oxcf.noise_sensitivity > 0 && - !cpi->denoiser.frame_buffer_initialized) { - if (vp9_denoiser_alloc(cm, &cpi->svc, &cpi->denoiser, cpi->use_svc, - cpi->oxcf.noise_sensitivity, cm->width, cm->height, - cm->subsampling_x, cm->subsampling_y, -#if CONFIG_VP9_HIGHBITDEPTH - cm->use_highbitdepth, -#endif - VP9_ENC_BORDER_IN_PIXELS)) - vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, - "Failed to allocate denoiser"); - } -} -#endif - -void vp9_update_compressor_with_img_fmt(VP9_COMP *cpi, vpx_img_fmt_t img_fmt) { - const VP9EncoderConfig *oxcf = &cpi->oxcf; - unsigned int subsampling_x, subsampling_y; - const int use_highbitdepth = vpx_img_use_highbitdepth(img_fmt); - vpx_img_chroma_subsampling(img_fmt, &subsampling_x, &subsampling_y); - - update_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); -#if CONFIG_VP9_TEMPORAL_DENOISING - setup_denoiser_buffer(cpi); -#endif - - assert(cpi->lookahead == NULL); - cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height, subsampling_x, - subsampling_y, -#if CONFIG_VP9_HIGHBITDEPTH - use_highbitdepth, -#endif - oxcf->lag_in_frames); - alloc_raw_frame_buffers(cpi); -} - VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf, BufferPool *const pool) { unsigned int i; - VP9_COMP *volatile const cpi = vpx_memalign(32, sizeof(VP9_COMP)); + VP9_COMP *volatile const cpi = vpx_memalign(32, sizeof(*cpi)); VP9_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; if (!cm) return NULL; @@ -2327,9 +2427,10 @@ VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf, cm->free_mi = vp9_enc_free_mi; cm->setup_mi = vp9_enc_setup_mi; - CHECK_MEM_ERROR(cm, cm->fc, (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); + CHECK_MEM_ERROR(&cm->error, cm->fc, + (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); CHECK_MEM_ERROR( - cm, cm->frame_contexts, + &cm->error, cm->frame_contexts, (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, sizeof(*cm->frame_contexts))); cpi->compute_frame_low_motion_onepass = 1; @@ -2351,43 +2452,45 @@ VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf, vp9_init_rd_parameters(cpi); init_frame_indexes(cm); + cpi->initial_width = cpi->oxcf.width; + cpi->initial_height = cpi->oxcf.height; cpi->tile_data = NULL; realloc_segmentation_maps(cpi); CHECK_MEM_ERROR( - cm, cpi->skin_map, - vpx_calloc(cm->mi_rows * cm->mi_cols, sizeof(cpi->skin_map[0]))); + &cm->error, cpi->skin_map, + vpx_calloc(cm->mi_rows * cm->mi_cols, sizeof(*cpi->skin_map))); #if !CONFIG_REALTIME_ONLY - CHECK_MEM_ERROR(cm, cpi->alt_ref_aq, vp9_alt_ref_aq_create()); + CHECK_MEM_ERROR(&cm->error, cpi->alt_ref_aq, vp9_alt_ref_aq_create()); #endif CHECK_MEM_ERROR( - cm, cpi->consec_zero_mv, + &cm->error, cpi->consec_zero_mv, vpx_calloc(cm->mi_rows * cm->mi_cols, sizeof(*cpi->consec_zero_mv))); - CHECK_MEM_ERROR(cm, cpi->nmvcosts[0], + CHECK_MEM_ERROR(&cm->error, cpi->nmvcosts[0], vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts[0]))); - CHECK_MEM_ERROR(cm, cpi->nmvcosts[1], + CHECK_MEM_ERROR(&cm->error, cpi->nmvcosts[1], vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts[1]))); - CHECK_MEM_ERROR(cm, cpi->nmvcosts_hp[0], + CHECK_MEM_ERROR(&cm->error, cpi->nmvcosts_hp[0], vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts_hp[0]))); - CHECK_MEM_ERROR(cm, cpi->nmvcosts_hp[1], + CHECK_MEM_ERROR(&cm->error, cpi->nmvcosts_hp[1], vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts_hp[1]))); - CHECK_MEM_ERROR(cm, cpi->nmvsadcosts[0], + CHECK_MEM_ERROR(&cm->error, cpi->nmvsadcosts[0], vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts[0]))); - CHECK_MEM_ERROR(cm, cpi->nmvsadcosts[1], + CHECK_MEM_ERROR(&cm->error, cpi->nmvsadcosts[1], vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts[1]))); - CHECK_MEM_ERROR(cm, cpi->nmvsadcosts_hp[0], + CHECK_MEM_ERROR(&cm->error, cpi->nmvsadcosts_hp[0], vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts_hp[0]))); - CHECK_MEM_ERROR(cm, cpi->nmvsadcosts_hp[1], + CHECK_MEM_ERROR(&cm->error, cpi->nmvsadcosts_hp[1], vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts_hp[1]))); for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); i++) { CHECK_MEM_ERROR( - cm, cpi->mbgraph_stats[i].mb_stats, + &cm->error, cpi->mbgraph_stats[i].mb_stats, vpx_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); } @@ -2431,7 +2534,7 @@ VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf, } if (cpi->b_calculate_consistency) { - CHECK_MEM_ERROR(cm, cpi->ssim_vars, + CHECK_MEM_ERROR(&cm->error, cpi->ssim_vars, vpx_calloc(cpi->common.mi_rows * cpi->common.mi_cols, sizeof(*cpi->ssim_vars) * 4)); cpi->worst_consistency = 100.0; @@ -2497,150 +2600,103 @@ VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf, } else if (oxcf->pass == 2) { const size_t packet_sz = sizeof(FIRSTPASS_STATS); const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); + int num_frames; - if (cpi->svc.number_spatial_layers > 1 || - cpi->svc.number_temporal_layers > 1) { - FIRSTPASS_STATS *const stats = oxcf->two_pass_stats_in.buf; - FIRSTPASS_STATS *stats_copy[VPX_SS_MAX_LAYERS] = { 0 }; - int i; + cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; + cpi->twopass.stats_in = cpi->twopass.stats_in_start; + cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; + // Note the last packet is cumulative first pass stats. + // So the number of frames is packet number minus one + num_frames = packets - 1; + fps_init_first_pass_info(&cpi->twopass.first_pass_info, + oxcf->two_pass_stats_in.buf, num_frames); - for (i = 0; i < oxcf->ss_number_layers; ++i) { - FIRSTPASS_STATS *const last_packet_for_layer = - &stats[packets - oxcf->ss_number_layers + i]; - const int layer_id = (int)last_packet_for_layer->spatial_layer_id; - const int packets_in_layer = (int)last_packet_for_layer->count + 1; - if (layer_id >= 0 && layer_id < oxcf->ss_number_layers) { - int num_frames; - LAYER_CONTEXT *const lc = &cpi->svc.layer_context[layer_id]; - - vpx_free(lc->rc_twopass_stats_in.buf); - - lc->rc_twopass_stats_in.sz = packets_in_layer * packet_sz; - CHECK_MEM_ERROR(cm, lc->rc_twopass_stats_in.buf, - vpx_malloc(lc->rc_twopass_stats_in.sz)); - lc->twopass.stats_in_start = lc->rc_twopass_stats_in.buf; - lc->twopass.stats_in = lc->twopass.stats_in_start; - lc->twopass.stats_in_end = - lc->twopass.stats_in_start + packets_in_layer - 1; - // Note the last packet is cumulative first pass stats. - // So the number of frames is packet number minus one - num_frames = packets_in_layer - 1; - fps_init_first_pass_info(&lc->twopass.first_pass_info, - lc->rc_twopass_stats_in.buf, num_frames); - stats_copy[layer_id] = lc->rc_twopass_stats_in.buf; - } - } - - for (i = 0; i < packets; ++i) { - const int layer_id = (int)stats[i].spatial_layer_id; - if (layer_id >= 0 && layer_id < oxcf->ss_number_layers && - stats_copy[layer_id] != NULL) { - *stats_copy[layer_id] = stats[i]; - ++stats_copy[layer_id]; - } - } - - vp9_init_second_pass_spatial_svc(cpi); - } else { - int num_frames; - - cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; - cpi->twopass.stats_in = cpi->twopass.stats_in_start; - cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; - // Note the last packet is cumulative first pass stats. - // So the number of frames is packet number minus one - num_frames = packets - 1; - fps_init_first_pass_info(&cpi->twopass.first_pass_info, - oxcf->two_pass_stats_in.buf, num_frames); - - vp9_init_second_pass(cpi); - } + vp9_init_second_pass(cpi); } #endif // !CONFIG_REALTIME_ONLY cpi->mb_wiener_var_cols = 0; cpi->mb_wiener_var_rows = 0; cpi->mb_wiener_variance = NULL; + cpi->mi_ssim_rdmult_scaling_factors = NULL; + cpi->mi_ssim_rdmult_scaling_factors_rows = 0; + cpi->mi_ssim_rdmult_scaling_factors_cols = 0; + cpi->sb_mul_scale = NULL; + cpi->sb_mul_scale_rows = 0; + cpi->sb_mul_scale_cols = 0; vp9_set_speed_features_framesize_independent(cpi, oxcf->speed); vp9_set_speed_features_framesize_dependent(cpi, oxcf->speed); - { - const int bsize = BLOCK_16X16; - const int w = num_8x8_blocks_wide_lookup[bsize]; - const int h = num_8x8_blocks_high_lookup[bsize]; - const int num_cols = (cm->mi_cols + w - 1) / w; - const int num_rows = (cm->mi_rows + h - 1) / h; - CHECK_MEM_ERROR(cm, cpi->mi_ssim_rdmult_scaling_factors, - vpx_calloc(num_rows * num_cols, - sizeof(*cpi->mi_ssim_rdmult_scaling_factors))); - } - cpi->kmeans_data_arr_alloc = 0; #if CONFIG_NON_GREEDY_MV cpi->tpl_ready = 0; #endif // CONFIG_NON_GREEDY_MV - for (i = 0; i < MAX_ARF_GOP_SIZE; ++i) cpi->tpl_stats[i].tpl_stats_ptr = NULL; + for (i = 0; i < MAX_ARF_GOP_SIZE; ++i) { + cpi->tpl_stats[i].tpl_stats_ptr = NULL; + } - // Allocate memory to store variances for a frame. - CHECK_MEM_ERROR(cm, cpi->source_diff_var, vpx_calloc(cm->MBs, sizeof(diff))); - cpi->source_var_thresh = 0; - cpi->frames_till_next_var_check = 0; -#define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF) \ - cpi->fn_ptr[BT].sdf = SDF; \ - cpi->fn_ptr[BT].sdaf = SDAF; \ - cpi->fn_ptr[BT].vf = VF; \ - cpi->fn_ptr[BT].svf = SVF; \ - cpi->fn_ptr[BT].svaf = SVAF; \ - cpi->fn_ptr[BT].sdx4df = SDX4DF; +#define BFP(BT, SDF, SDSF, SDAF, VF, SVF, SVAF, SDX4DF, SDSX4DF) \ + cpi->fn_ptr[BT].sdf = SDF; \ + cpi->fn_ptr[BT].sdsf = SDSF; \ + cpi->fn_ptr[BT].sdaf = SDAF; \ + cpi->fn_ptr[BT].vf = VF; \ + cpi->fn_ptr[BT].svf = SVF; \ + cpi->fn_ptr[BT].svaf = SVAF; \ + cpi->fn_ptr[BT].sdx4df = SDX4DF; \ + cpi->fn_ptr[BT].sdsx4df = SDSX4DF; - BFP(BLOCK_32X16, vpx_sad32x16, vpx_sad32x16_avg, vpx_variance32x16, - vpx_sub_pixel_variance32x16, vpx_sub_pixel_avg_variance32x16, - vpx_sad32x16x4d) + BFP(BLOCK_32X16, vpx_sad32x16, vpx_sad_skip_32x16, vpx_sad32x16_avg, + vpx_variance32x16, vpx_sub_pixel_variance32x16, + vpx_sub_pixel_avg_variance32x16, vpx_sad32x16x4d, vpx_sad_skip_32x16x4d) - BFP(BLOCK_16X32, vpx_sad16x32, vpx_sad16x32_avg, vpx_variance16x32, - vpx_sub_pixel_variance16x32, vpx_sub_pixel_avg_variance16x32, - vpx_sad16x32x4d) + BFP(BLOCK_16X32, vpx_sad16x32, vpx_sad_skip_16x32, vpx_sad16x32_avg, + vpx_variance16x32, vpx_sub_pixel_variance16x32, + vpx_sub_pixel_avg_variance16x32, vpx_sad16x32x4d, vpx_sad_skip_16x32x4d) - BFP(BLOCK_64X32, vpx_sad64x32, vpx_sad64x32_avg, vpx_variance64x32, - vpx_sub_pixel_variance64x32, vpx_sub_pixel_avg_variance64x32, - vpx_sad64x32x4d) + BFP(BLOCK_64X32, vpx_sad64x32, vpx_sad_skip_64x32, vpx_sad64x32_avg, + vpx_variance64x32, vpx_sub_pixel_variance64x32, + vpx_sub_pixel_avg_variance64x32, vpx_sad64x32x4d, vpx_sad_skip_64x32x4d) - BFP(BLOCK_32X64, vpx_sad32x64, vpx_sad32x64_avg, vpx_variance32x64, - vpx_sub_pixel_variance32x64, vpx_sub_pixel_avg_variance32x64, - vpx_sad32x64x4d) + BFP(BLOCK_32X64, vpx_sad32x64, vpx_sad_skip_32x64, vpx_sad32x64_avg, + vpx_variance32x64, vpx_sub_pixel_variance32x64, + vpx_sub_pixel_avg_variance32x64, vpx_sad32x64x4d, vpx_sad_skip_32x64x4d) - BFP(BLOCK_32X32, vpx_sad32x32, vpx_sad32x32_avg, vpx_variance32x32, - vpx_sub_pixel_variance32x32, vpx_sub_pixel_avg_variance32x32, - vpx_sad32x32x4d) + BFP(BLOCK_32X32, vpx_sad32x32, vpx_sad_skip_32x32, vpx_sad32x32_avg, + vpx_variance32x32, vpx_sub_pixel_variance32x32, + vpx_sub_pixel_avg_variance32x32, vpx_sad32x32x4d, vpx_sad_skip_32x32x4d) - BFP(BLOCK_64X64, vpx_sad64x64, vpx_sad64x64_avg, vpx_variance64x64, - vpx_sub_pixel_variance64x64, vpx_sub_pixel_avg_variance64x64, - vpx_sad64x64x4d) + BFP(BLOCK_64X64, vpx_sad64x64, vpx_sad_skip_64x64, vpx_sad64x64_avg, + vpx_variance64x64, vpx_sub_pixel_variance64x64, + vpx_sub_pixel_avg_variance64x64, vpx_sad64x64x4d, vpx_sad_skip_64x64x4d) - BFP(BLOCK_16X16, vpx_sad16x16, vpx_sad16x16_avg, vpx_variance16x16, - vpx_sub_pixel_variance16x16, vpx_sub_pixel_avg_variance16x16, - vpx_sad16x16x4d) + BFP(BLOCK_16X16, vpx_sad16x16, vpx_sad_skip_16x16, vpx_sad16x16_avg, + vpx_variance16x16, vpx_sub_pixel_variance16x16, + vpx_sub_pixel_avg_variance16x16, vpx_sad16x16x4d, vpx_sad_skip_16x16x4d) - BFP(BLOCK_16X8, vpx_sad16x8, vpx_sad16x8_avg, vpx_variance16x8, - vpx_sub_pixel_variance16x8, vpx_sub_pixel_avg_variance16x8, - vpx_sad16x8x4d) + BFP(BLOCK_16X8, vpx_sad16x8, vpx_sad_skip_16x8, vpx_sad16x8_avg, + vpx_variance16x8, vpx_sub_pixel_variance16x8, + vpx_sub_pixel_avg_variance16x8, vpx_sad16x8x4d, vpx_sad_skip_16x8x4d) - BFP(BLOCK_8X16, vpx_sad8x16, vpx_sad8x16_avg, vpx_variance8x16, - vpx_sub_pixel_variance8x16, vpx_sub_pixel_avg_variance8x16, - vpx_sad8x16x4d) + BFP(BLOCK_8X16, vpx_sad8x16, vpx_sad_skip_8x16, vpx_sad8x16_avg, + vpx_variance8x16, vpx_sub_pixel_variance8x16, + vpx_sub_pixel_avg_variance8x16, vpx_sad8x16x4d, vpx_sad_skip_8x16x4d) - BFP(BLOCK_8X8, vpx_sad8x8, vpx_sad8x8_avg, vpx_variance8x8, - vpx_sub_pixel_variance8x8, vpx_sub_pixel_avg_variance8x8, vpx_sad8x8x4d) + BFP(BLOCK_8X8, vpx_sad8x8, vpx_sad_skip_8x8, vpx_sad8x8_avg, vpx_variance8x8, + vpx_sub_pixel_variance8x8, vpx_sub_pixel_avg_variance8x8, vpx_sad8x8x4d, + vpx_sad_skip_8x8x4d) - BFP(BLOCK_8X4, vpx_sad8x4, vpx_sad8x4_avg, vpx_variance8x4, - vpx_sub_pixel_variance8x4, vpx_sub_pixel_avg_variance8x4, vpx_sad8x4x4d) + BFP(BLOCK_8X4, vpx_sad8x4, vpx_sad_skip_8x4, vpx_sad8x4_avg, vpx_variance8x4, + vpx_sub_pixel_variance8x4, vpx_sub_pixel_avg_variance8x4, vpx_sad8x4x4d, + vpx_sad_skip_8x4x4d) - BFP(BLOCK_4X8, vpx_sad4x8, vpx_sad4x8_avg, vpx_variance4x8, - vpx_sub_pixel_variance4x8, vpx_sub_pixel_avg_variance4x8, vpx_sad4x8x4d) + BFP(BLOCK_4X8, vpx_sad4x8, vpx_sad_skip_4x8, vpx_sad4x8_avg, vpx_variance4x8, + vpx_sub_pixel_variance4x8, vpx_sub_pixel_avg_variance4x8, vpx_sad4x8x4d, + vpx_sad_skip_4x8x4d) - BFP(BLOCK_4X4, vpx_sad4x4, vpx_sad4x4_avg, vpx_variance4x4, - vpx_sub_pixel_variance4x4, vpx_sub_pixel_avg_variance4x4, vpx_sad4x4x4d) + BFP(BLOCK_4X4, vpx_sad4x4, vpx_sad_skip_4x4, vpx_sad4x4_avg, vpx_variance4x4, + vpx_sub_pixel_variance4x4, vpx_sub_pixel_avg_variance4x4, vpx_sad4x4x4d, + vpx_sad_skip_4x4x4d) #if CONFIG_VP9_HIGHBITDEPTH highbd_set_var_fns(cpi); @@ -2668,16 +2724,6 @@ VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf, cm->error.setjmp = 0; -#if CONFIG_RATE_CTRL - encode_command_init(&cpi->encode_command); - if (oxcf->use_simple_encode_api) { - partition_info_init(cpi); - motion_vector_info_init(cpi); - fp_motion_vector_info_init(cpi); - tpl_stats_info_init(cpi); - } -#endif - return cpi; } @@ -2688,8 +2734,6 @@ VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf, snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) #endif // CONFIG_INTERNAL_STATS -static void free_tpl_buffer(VP9_COMP *cpi); - void vp9_remove_compressor(VP9_COMP *cpi) { VP9_COMMON *cm; unsigned int i; @@ -2783,7 +2827,7 @@ void vp9_remove_compressor(VP9_COMP *cpi) { #if 0 { printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); - printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); + printf("\n_frames receive_data encod_mb_row compress_frame Total\n"); printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, cpi->time_compress_data / 1000, @@ -2803,7 +2847,7 @@ void vp9_remove_compressor(VP9_COMP *cpi) { vpx_free(cpi->kmeans_data_arr); } - free_tpl_buffer(cpi); + vp9_free_tpl_buffer(cpi); vp9_loop_filter_dealloc(&cpi->lf_row_sync); vp9_bitstream_encode_tiles_buffer_dealloc(cpi); @@ -2823,6 +2867,10 @@ void vp9_remove_compressor(VP9_COMP *cpi) { vp9_extrc_delete(&cpi->ext_ratectrl); + // Help detect use after free of the error detail string. + memset(cm->error.detail, 'A', sizeof(cm->error.detail) - 1); + cm->error.detail[sizeof(cm->error.detail) - 1] = '\0'; + vp9_remove_common(cm); vp9_free_ref_frame_buffers(cm->buffer_pool); #if CONFIG_VP9_POSTPROC @@ -2865,9 +2913,11 @@ int vp9_get_psnr(const VP9_COMP *cpi, PSNR_STATS *psnr) { if (is_psnr_calc_enabled(cpi)) { #if CONFIG_VP9_HIGHBITDEPTH vpx_calc_highbd_psnr(cpi->raw_source_frame, cpi->common.frame_to_show, psnr, - cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); + cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth, + cpi->svc.spatial_layer_id); #else - vpx_calc_psnr(cpi->raw_source_frame, cpi->common.frame_to_show, psnr); + vpx_calc_psnr(cpi->raw_source_frame, cpi->common.frame_to_show, psnr, + cpi->svc.spatial_layer_id); #endif return 1; } else { @@ -2892,7 +2942,7 @@ void vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags) { static YV12_BUFFER_CONFIG *get_vp9_ref_frame_buffer( VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag) { - MV_REFERENCE_FRAME ref_frame = NONE; + MV_REFERENCE_FRAME ref_frame = NO_REF_FRAME; if (ref_frame_flag == VP9_LAST_FLAG) ref_frame = LAST_FRAME; else if (ref_frame_flag == VP9_GOLD_FLAG) @@ -2900,7 +2950,8 @@ static YV12_BUFFER_CONFIG *get_vp9_ref_frame_buffer( else if (ref_frame_flag == VP9_ALT_FLAG) ref_frame = ALTREF_FRAME; - return ref_frame == NONE ? NULL : get_ref_frame_buffer(cpi, ref_frame); + return ref_frame == NO_REF_FRAME ? NULL + : get_ref_frame_buffer(cpi, ref_frame); } int vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag, @@ -2993,12 +3044,11 @@ void vp9_write_yuv_rec_frame(VP9_COMMON *cm) { #endif #if CONFIG_VP9_HIGHBITDEPTH -static void scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src, - YV12_BUFFER_CONFIG *dst, - int bd) { +void vp9_scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src, + YV12_BUFFER_CONFIG *dst, int bd) { #else -static void scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src, - YV12_BUFFER_CONFIG *dst) { +void vp9_scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src, + YV12_BUFFER_CONFIG *dst) { #endif // CONFIG_VP9_HIGHBITDEPTH // TODO(dkovalev): replace YV12_BUFFER_CONFIG with vpx_image_t int i; @@ -3043,6 +3093,23 @@ static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src, const int src_h = src->y_crop_height; const int dst_w = dst->y_crop_width; const int dst_h = dst->y_crop_height; + + // The issue b/311394513 reveals a corner case bug. + // For bd = 8, vpx_scaled_2d() requires both x_step_q4 and y_step_q4 are less + // than or equal to 64. For bd >= 10, vpx_highbd_convolve8() requires both + // x_step_q4 and y_step_q4 are less than or equal to 32. If this condition + // isn't met, it needs to call vp9_scale_and_extend_frame_nonnormative() that + // supports arbitrary scaling. + const int x_step_q4 = 16 * src_w / dst_w; + const int y_step_q4 = 16 * src_h / dst_h; + const int is_arbitrary_scaling = + (bd == 8 && (x_step_q4 > 64 || y_step_q4 > 64)) || + (bd >= 10 && (x_step_q4 > 32 || y_step_q4 > 32)); + if (is_arbitrary_scaling) { + vp9_scale_and_extend_frame_nonnormative(src, dst, bd); + return; + } + const uint8_t *const srcs[3] = { src->y_buffer, src->u_buffer, src->v_buffer }; const int src_strides[3] = { src->y_stride, src->uv_stride, src->uv_stride }; @@ -3194,6 +3261,34 @@ static void update_ref_frames(VP9_COMP *cpi) { BufferPool *const pool = cm->buffer_pool; GF_GROUP *const gf_group = &cpi->twopass.gf_group; + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_GOP) != 0 && + cpi->ext_ratectrl.funcs.get_gop_decision != NULL) { + const int this_gf_index = gf_group->index; + const int update_ref_idx = gf_group->update_ref_idx[this_gf_index]; + if (gf_group->update_type[this_gf_index] == KF_UPDATE) { + ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[0], cm->new_fb_idx); + ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[1], cm->new_fb_idx); + ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[2], cm->new_fb_idx); + } else if (update_ref_idx != INVALID_IDX) { + ref_cnt_fb(pool->frame_bufs, + &cm->ref_frame_map[gf_group->update_ref_idx[this_gf_index]], + cm->new_fb_idx); + } + + const int next_gf_index = gf_group->index + 1; + + // Overlay frame should ideally look at the colocated ref frame from rc lib. + // Here temporarily just don't update the indices. + if (next_gf_index < gf_group->gf_group_size) { + cpi->lst_fb_idx = gf_group->ext_rc_ref[next_gf_index].last_index; + cpi->gld_fb_idx = gf_group->ext_rc_ref[next_gf_index].golden_index; + cpi->alt_fb_idx = gf_group->ext_rc_ref[next_gf_index].altref_index; + } + + return; + } + if (cpi->rc.show_arf_as_gld) { int tmp = cpi->alt_fb_idx; cpi->alt_fb_idx = cpi->gld_fb_idx; @@ -3286,7 +3381,7 @@ void vp9_update_reference_frames(VP9_COMP *cpi) { vp9_denoiser_update_ref_frame(cpi); #endif - if (is_one_pass_cbr_svc(cpi)) vp9_svc_update_ref_frame(cpi); + if (is_one_pass_svc(cpi)) vp9_svc_update_ref_frame(cpi); } static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { @@ -3316,11 +3411,15 @@ static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { lf->filter_level = 0; lf->last_filt_level = 0; } else { +#if CONFIG_INTERNAL_STATS struct vpx_usec_timer timer; +#endif vpx_clear_system_state(); +#if CONFIG_INTERNAL_STATS vpx_usec_timer_start(&timer); +#endif if (!cpi->rc.is_src_frame_alt_ref) { if ((cpi->common.frame_type == KEY_FRAME) && @@ -3333,8 +3432,10 @@ static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { lf->filter_level = 0; } +#if CONFIG_INTERNAL_STATS vpx_usec_timer_mark(&timer); cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer); +#endif } if (lf->filter_level > 0 && is_reference_frame) { @@ -3351,19 +3452,6 @@ static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { vpx_extend_frame_inner_borders(cm->frame_to_show); } -static INLINE void alloc_frame_mvs(VP9_COMMON *const cm, int buffer_idx) { - RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; - if (new_fb_ptr->mvs == NULL || new_fb_ptr->mi_rows < cm->mi_rows || - new_fb_ptr->mi_cols < cm->mi_cols) { - vpx_free(new_fb_ptr->mvs); - CHECK_MEM_ERROR(cm, new_fb_ptr->mvs, - (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols, - sizeof(*new_fb_ptr->mvs))); - new_fb_ptr->mi_rows = cm->mi_rows; - new_fb_ptr->mi_cols = cm->mi_cols; - } -} - void vp9_scale_references(VP9_COMP *cpi) { VP9_COMMON *cm = &cpi->common; MV_REFERENCE_FRAME ref_frame; @@ -3382,19 +3470,23 @@ void vp9_scale_references(VP9_COMP *cpi) { continue; } -#if CONFIG_VP9_HIGHBITDEPTH if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { RefCntBuffer *new_fb_ptr = NULL; int force_scaling = 0; int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; if (new_fb == INVALID_IDX) { new_fb = get_free_fb(cm); + if (new_fb == INVALID_IDX) { + assert(cm->error.setjmp); + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, + "Unable to find free frame buffer"); + } force_scaling = 1; } - if (new_fb == INVALID_IDX) return; new_fb_ptr = &pool->frame_bufs[new_fb]; if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || new_fb_ptr->buf.y_crop_height != cm->height) { +#if CONFIG_VP9_HIGHBITDEPTH if (vpx_realloc_frame_buffer(&new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x, cm->subsampling_y, cm->use_highbitdepth, @@ -3404,22 +3496,7 @@ void vp9_scale_references(VP9_COMP *cpi) { "Failed to allocate frame buffer"); scale_and_extend_frame(ref, &new_fb_ptr->buf, (int)cm->bit_depth, EIGHTTAP, 0); - cpi->scaled_ref_idx[ref_frame - 1] = new_fb; - alloc_frame_mvs(cm, new_fb); - } #else - if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { - RefCntBuffer *new_fb_ptr = NULL; - int force_scaling = 0; - int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; - if (new_fb == INVALID_IDX) { - new_fb = get_free_fb(cm); - force_scaling = 1; - } - if (new_fb == INVALID_IDX) return; - new_fb_ptr = &pool->frame_bufs[new_fb]; - if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || - new_fb_ptr->buf.y_crop_height != cm->height) { if (vpx_realloc_frame_buffer(&new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x, cm->subsampling_y, VP9_ENC_BORDER_IN_PIXELS, @@ -3427,10 +3504,10 @@ void vp9_scale_references(VP9_COMP *cpi) { vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, "Failed to allocate frame buffer"); vp9_scale_and_extend_frame(ref, &new_fb_ptr->buf, EIGHTTAP, 0); +#endif // CONFIG_VP9_HIGHBITDEPTH cpi->scaled_ref_idx[ref_frame - 1] = new_fb; alloc_frame_mvs(cm, new_fb); } -#endif // CONFIG_VP9_HIGHBITDEPTH } else { int buf_idx; RefCntBuffer *buf = NULL; @@ -3709,10 +3786,15 @@ static void set_size_dependent_vars(VP9_COMP *cpi, int *q, int *bottom_index, case 5: l = 100; break; case 6: l = 150; break; } - if (!cpi->common.postproc_state.limits) { - CHECK_MEM_ERROR(cm, cpi->common.postproc_state.limits, + if (!cpi->common.postproc_state.limits || + cpi->common.postproc_state.limits_size < + cpi->un_scaled_source->y_width) { + if (cpi->common.postproc_state.limits) + vpx_free(cpi->common.postproc_state.limits); + CHECK_MEM_ERROR(&cm->error, cpi->common.postproc_state.limits, vpx_calloc(cpi->un_scaled_source->y_width, sizeof(*cpi->common.postproc_state.limits))); + cpi->common.postproc_state.limits_size = cpi->un_scaled_source->y_width; } vp9_denoise(&cpi->common, cpi->Source, cpi->Source, l, cpi->common.postproc_state.limits); @@ -3799,6 +3881,7 @@ static void set_frame_size(VP9_COMP *cpi) { alloc_util_frame_buffers(cpi); init_motion_estimation(cpi); + int has_valid_ref_frame = 0; for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); @@ -3817,22 +3900,25 @@ static void set_frame_size(VP9_COMP *cpi) { buf->y_crop_height, cm->width, cm->height); #endif // CONFIG_VP9_HIGHBITDEPTH + has_valid_ref_frame |= vp9_is_valid_scale(&ref_buf->sf); if (vp9_is_scaled(&ref_buf->sf)) vpx_extend_frame_borders(buf); } else { ref_buf->buf = NULL; } } + if (!frame_is_intra_only(cm) && !has_valid_ref_frame) { + vpx_internal_error( + &cm->error, VPX_CODEC_ERROR, + "Can't find at least one reference frame with valid size"); + } set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); } -#if CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL static void save_encode_params(VP9_COMP *cpi) { - VP9_COMMON *const cm = &cpi->common; - const int tile_cols = 1 << cm->log2_tile_cols; - const int tile_rows = 1 << cm->log2_tile_rows; - int tile_col, tile_row; + int tile_idx; int i, j; + TileDataEnc *tile_data; RD_OPT *rd_opt = &cpi->rd; for (i = 0; i < MAX_REF_FRAMES; i++) { for (j = 0; j < REFERENCE_MODES; j++) @@ -3843,28 +3929,40 @@ static void save_encode_params(VP9_COMP *cpi) { rd_opt->filter_threshes_prev[i][j] = rd_opt->filter_threshes[i][j]; } - if (cpi->tile_data != NULL) { - for (tile_row = 0; tile_row < tile_rows; ++tile_row) - for (tile_col = 0; tile_col < tile_cols; ++tile_col) { - TileDataEnc *tile_data = - &cpi->tile_data[tile_row * tile_cols + tile_col]; - for (i = 0; i < BLOCK_SIZES; ++i) { - for (j = 0; j < MAX_MODES; ++j) { - tile_data->thresh_freq_fact_prev[i][j] = - tile_data->thresh_freq_fact[i][j]; - } - } - } + for (tile_idx = 0; tile_idx < cpi->allocated_tiles; tile_idx++) { + assert(cpi->tile_data); + tile_data = &cpi->tile_data[tile_idx]; + vp9_copy(tile_data->thresh_freq_fact_prev, tile_data->thresh_freq_fact); } } -#endif // CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL static INLINE void set_raw_source_frame(VP9_COMP *cpi) { +#if defined(ENABLE_KF_DENOISE) || CONFIG_VP9_TEMPORAL_DENOISING + VP9_COMMON *const cm = &cpi->common; + int use_raw_source = 0; #ifdef ENABLE_KF_DENOISE - if (is_spatial_denoise_enabled(cpi)) { - cpi->raw_source_frame = vp9_scale_if_required( - cm, &cpi->raw_unscaled_source, &cpi->raw_scaled_source, - (oxcf->pass == 0), EIGHTTAP, 0); + use_raw_source |= is_spatial_denoise_enabled(cpi); +#endif +#if CONFIG_VP9_TEMPORAL_DENOISING + use_raw_source |= (cpi->oxcf.noise_sensitivity > 0); +#endif + if (use_raw_source) { + if (cpi->Source == cpi->un_scaled_source) { + cpi->raw_source_frame = &cpi->raw_unscaled_source; + } else { + if (vpx_realloc_frame_buffer( + &cpi->raw_scaled_source, cpi->Source->y_crop_width, + cpi->Source->y_crop_height, cpi->Source->subsampling_x, + cpi->Source->subsampling_y, +#if CONFIG_VP9_HIGHBITDEPTH + cm->use_highbitdepth, +#endif + VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, + "Failed to allocate scaled raw source frame buffer"); + vp9_copy_and_extend_frame(cpi->Source, &cpi->raw_scaled_source); + cpi->raw_source_frame = &cpi->raw_scaled_source; + } } else { cpi->raw_source_frame = cpi->Source; } @@ -3873,18 +3971,47 @@ static INLINE void set_raw_source_frame(VP9_COMP *cpi) { #endif } +static YV12_BUFFER_CONFIG *svc_twostage_scale( + VP9_COMMON *cm, YV12_BUFFER_CONFIG *unscaled, YV12_BUFFER_CONFIG *scaled, + YV12_BUFFER_CONFIG *scaled_temp, INTERP_FILTER filter_type, + int phase_scaler, INTERP_FILTER filter_type2, int phase_scaler2) { + if (cm->mi_cols * MI_SIZE != unscaled->y_width || + cm->mi_rows * MI_SIZE != unscaled->y_height) { +#if CONFIG_VP9_HIGHBITDEPTH + if (cm->bit_depth == VPX_BITS_8) { + vp9_scale_and_extend_frame(unscaled, scaled_temp, filter_type2, + phase_scaler2); + vp9_scale_and_extend_frame(scaled_temp, scaled, filter_type, + phase_scaler); + } else { + scale_and_extend_frame(unscaled, scaled_temp, (int)cm->bit_depth, + filter_type2, phase_scaler2); + scale_and_extend_frame(scaled_temp, scaled, (int)cm->bit_depth, + filter_type, phase_scaler); + } +#else + vp9_scale_and_extend_frame(unscaled, scaled_temp, filter_type2, + phase_scaler2); + vp9_scale_and_extend_frame(scaled_temp, scaled, filter_type, phase_scaler); +#endif // CONFIG_VP9_HIGHBITDEPTH + return scaled; + } else { + return unscaled; + } +} + static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, - uint8_t *dest) { + uint8_t *dest, size_t dest_size) { VP9_COMMON *const cm = &cpi->common; SVC *const svc = &cpi->svc; int q = 0, bottom_index = 0, top_index = 0; int no_drop_scene_change = 0; const INTERP_FILTER filter_scaler = - (is_one_pass_cbr_svc(cpi)) + (is_one_pass_svc(cpi)) ? svc->downsample_filter_type[svc->spatial_layer_id] : EIGHTTAP; const int phase_scaler = - (is_one_pass_cbr_svc(cpi)) + (is_one_pass_svc(cpi)) ? svc->downsample_filter_phase[svc->spatial_layer_id] : 0; @@ -3905,7 +4032,7 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, set_frame_size(cpi); - if (is_one_pass_cbr_svc(cpi) && + if (is_one_pass_svc(cpi) && cpi->un_scaled_source->y_width == cm->width << 2 && cpi->un_scaled_source->y_height == cm->height << 2 && svc->scaled_temp.y_width == cm->width << 1 && @@ -3915,11 +4042,11 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, // result will be saved in scaled_temp and might be used later. const INTERP_FILTER filter_scaler2 = svc->downsample_filter_type[1]; const int phase_scaler2 = svc->downsample_filter_phase[1]; - cpi->Source = vp9_svc_twostage_scale( + cpi->Source = svc_twostage_scale( cm, cpi->un_scaled_source, &cpi->scaled_source, &svc->scaled_temp, filter_scaler, phase_scaler, filter_scaler2, phase_scaler2); svc->scaled_one_half = 1; - } else if (is_one_pass_cbr_svc(cpi) && + } else if (is_one_pass_svc(cpi) && cpi->un_scaled_source->y_width == cm->width << 1 && cpi->un_scaled_source->y_height == cm->height << 1 && svc->scaled_one_half) { @@ -3934,24 +4061,14 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, } #ifdef OUTPUT_YUV_SVC_SRC // Write out at most 3 spatial layers. - if (is_one_pass_cbr_svc(cpi) && svc->spatial_layer_id < 3) { + if (is_one_pass_svc(cpi) && svc->spatial_layer_id < 3) { vpx_write_yuv_frame(yuv_svc_src[svc->spatial_layer_id], cpi->Source); } #endif // Unfiltered raw source used in metrics calculation if the source // has been filtered. if (is_psnr_calc_enabled(cpi)) { -#ifdef ENABLE_KF_DENOISE - if (is_spatial_denoise_enabled(cpi)) { - cpi->raw_source_frame = vp9_scale_if_required( - cm, &cpi->raw_unscaled_source, &cpi->raw_scaled_source, - (cpi->oxcf.pass == 0), EIGHTTAP, phase_scaler); - } else { - cpi->raw_source_frame = cpi->Source; - } -#else - cpi->raw_source_frame = cpi->Source; -#endif + set_raw_source_frame(cpi); } if ((cpi->use_svc && @@ -3968,14 +4085,12 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, } // Avoid scaling last_source unless its needed. - // Last source is needed if avg_source_sad() is used, or if - // partition_search_type == SOURCE_VAR_BASED_PARTITION, or if noise - // estimation is enabled. + // Last source is needed if avg_source_sad() is used, or if noise estimation + // is enabled. if (cpi->unscaled_last_source != NULL && (cpi->oxcf.content == VP9E_CONTENT_SCREEN || (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.mode == REALTIME && cpi->oxcf.speed >= 5) || - cpi->sf.partition_search_type == SOURCE_VAR_BASED_PARTITION || (cpi->noise_estimate.enabled && !cpi->oxcf.noise_sensitivity) || cpi->compute_source_sad_onepass)) cpi->Last_Source = vp9_scale_if_required( @@ -3998,15 +4113,14 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, #endif // Scene detection is always used for VBR mode or screen-content case. - // For other cases (e.g., CBR mode) use it for 5 <= speed < 8 for now - // (need to check encoding time cost for doing this for speed 8). + // For other cases (e.g., CBR mode) use it for 5 <= speed. cpi->rc.high_source_sad = 0; cpi->rc.hybrid_intra_scene_change = 0; cpi->rc.re_encode_maxq_scene_change = 0; if (cm->show_frame && cpi->oxcf.mode == REALTIME && + !cpi->disable_scene_detection_rtc_ratectrl && (cpi->oxcf.rc_mode == VPX_VBR || - cpi->oxcf.content == VP9E_CONTENT_SCREEN || - (cpi->oxcf.speed >= 5 && cpi->oxcf.speed < 8))) + cpi->oxcf.content == VP9E_CONTENT_SCREEN || cpi->oxcf.speed >= 5)) vp9_scene_detection_onepass(cpi); if (svc->spatial_layer_id == svc->first_spatial_layer_to_encode) { @@ -4043,14 +4157,16 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, if (vp9_rc_drop_frame(cpi)) return 0; } - // For 1 pass CBR SVC, only ZEROMV is allowed for spatial reference frame - // when svc->force_zero_mode_spatial_ref = 1. Under those conditions we can - // avoid this frame-level upsampling (for non intra_only frames). + // For 1 pass SVC wth use_nonrd_pick_mode, only ZEROMV is allowed for + // spatial reference frame when svc->force_zero_mode_spatial_ref = 1. + // Under those conditions we can avoid this frame-level upsampling + // (for non intra_only frames). // For SVC single_layer mode, dynamic resize is allowed and we need to // scale references for this case. if (frame_is_intra_only(cm) == 0 && ((svc->single_layer_svc && cpi->oxcf.resize_mode == RESIZE_DYNAMIC) || - !(is_one_pass_cbr_svc(cpi) && svc->force_zero_mode_spatial_ref))) { + !(is_one_pass_svc(cpi) && svc->force_zero_mode_spatial_ref && + cpi->sf.use_nonrd_pick_mode))) { vp9_scale_references(cpi); } @@ -4066,7 +4182,7 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, svc->spatial_layer_id == svc->number_spatial_layers - 2) { if (svc->prev_partition_svc == NULL) { CHECK_MEM_ERROR( - cm, svc->prev_partition_svc, + &cm->error, svc->prev_partition_svc, (BLOCK_SIZE *)vpx_calloc(cm->mi_stride * cm->mi_rows, sizeof(*svc->prev_partition_svc))); } @@ -4086,7 +4202,7 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, cpi->oxcf.rc_mode == VPX_CBR && cm->frame_type != KEY_FRAME; - vp9_set_quantizer(cpi, q); + vp9_set_quantizer(cpi, q, 0); vp9_set_variance_partition_thresholds(cpi, q, 0); setup_frame(cpi); @@ -4115,7 +4231,7 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, (cpi->rc.high_source_sad || (cpi->use_svc && svc->high_source_sad_superframe))) { if (vp9_encodedframe_overshoot(cpi, -1, &q)) { - vp9_set_quantizer(cpi, q); + vp9_set_quantizer(cpi, q, 0); vp9_set_variance_partition_thresholds(cpi, q, 0); } } @@ -4169,14 +4285,14 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, int frame_size = 0; // Get an estimate of the encoded frame size. save_coding_context(cpi); - vp9_pack_bitstream(cpi, dest, size); + vp9_pack_bitstream(cpi, dest, dest_size, size); restore_coding_context(cpi); frame_size = (int)(*size) << 3; // Check if encoded frame will overshoot too much, and if so, set the q and // adjust some rate control parameters, and return to re-encode the frame. if (vp9_encodedframe_overshoot(cpi, frame_size, &q)) { vpx_clear_system_state(); - vp9_set_quantizer(cpi, q); + vp9_set_quantizer(cpi, q, 0); vp9_set_variance_partition_thresholds(cpi, q, 0); suppress_active_map(cpi); // Turn-off cyclic refresh for re-encoded frame. @@ -4235,149 +4351,8 @@ static int get_qstep_adj(int rate_excess, int rate_limit) { return VPXMIN(qstep, MAX_QSTEP_ADJ); } -#if CONFIG_RATE_CTRL -static void init_rq_history(RATE_QINDEX_HISTORY *rq_history) { - rq_history->recode_count = 0; - rq_history->q_index_high = 255; - rq_history->q_index_low = 0; -} - -static void update_rq_history(RATE_QINDEX_HISTORY *rq_history, int target_bits, - int actual_bits, int q_index) { - rq_history->q_index_history[rq_history->recode_count] = q_index; - rq_history->rate_history[rq_history->recode_count] = actual_bits; - if (actual_bits <= target_bits) { - rq_history->q_index_high = q_index; - } - if (actual_bits >= target_bits) { - rq_history->q_index_low = q_index; - } - rq_history->recode_count += 1; -} - -static int guess_q_index_from_model(const RATE_QSTEP_MODEL *rq_model, - int target_bits) { - // The model predicts bits as follows. - // target_bits = bias - ratio * log2(q_step) - // Given the target_bits, we compute the q_step as follows. - double q_step; - assert(rq_model->ratio > 0); - q_step = pow(2.0, (rq_model->bias - target_bits) / rq_model->ratio); - // TODO(angiebird): Make this function support highbitdepth. - return vp9_convert_q_to_qindex(q_step, VPX_BITS_8); -} - -static int guess_q_index_linear(int prev_q_index, int target_bits, - int actual_bits, int gap) { - int q_index = prev_q_index; - if (actual_bits < target_bits) { - q_index -= gap; - q_index = VPXMAX(q_index, 0); - } else { - q_index += gap; - q_index = VPXMIN(q_index, 255); - } - return q_index; -} - -static double get_bits_percent_diff(int target_bits, int actual_bits) { - double diff; - target_bits = VPXMAX(target_bits, 1); - diff = abs(target_bits - actual_bits) * 1. / target_bits; - return diff * 100; -} - -static int rq_model_predict_q_index(const RATE_QSTEP_MODEL *rq_model, - const RATE_QINDEX_HISTORY *rq_history, - int target_bits) { - int q_index = 128; - if (rq_history->recode_count > 0) { - const int actual_bits = - rq_history->rate_history[rq_history->recode_count - 1]; - const int prev_q_index = - rq_history->q_index_history[rq_history->recode_count - 1]; - const double percent_diff = get_bits_percent_diff(target_bits, actual_bits); - if (percent_diff > 50) { - // Binary search. - // When the actual_bits and target_bits are far apart, binary search - // q_index is faster. - q_index = (rq_history->q_index_low + rq_history->q_index_high) / 2; - } else { - if (rq_model->ready) { - q_index = guess_q_index_from_model(rq_model, target_bits); - } else { - // TODO(angiebird): Find a better way to set the gap. - q_index = - guess_q_index_linear(prev_q_index, target_bits, actual_bits, 20); - } - } - } else { - if (rq_model->ready) { - q_index = guess_q_index_from_model(rq_model, target_bits); - } - } - - assert(rq_history->q_index_low <= rq_history->q_index_high); - if (q_index <= rq_history->q_index_low) { - q_index = rq_history->q_index_low + 1; - } - if (q_index >= rq_history->q_index_high) { - q_index = rq_history->q_index_high - 1; - } - return q_index; -} - -static void rq_model_update(const RATE_QINDEX_HISTORY *rq_history, - int target_bits, RATE_QSTEP_MODEL *rq_model) { - const int recode_count = rq_history->recode_count; - const double delta = 0.00001; - if (recode_count >= 2) { - const int q_index1 = rq_history->q_index_history[recode_count - 2]; - const int q_index2 = rq_history->q_index_history[recode_count - 1]; - const int r1 = rq_history->rate_history[recode_count - 2]; - const int r2 = rq_history->rate_history[recode_count - 1]; - int valid = 0; - // lower q_index should yield higher bit rate - if (q_index1 < q_index2) { - valid = r1 > r2; - } else if (q_index1 > q_index2) { - valid = r1 < r2; - } - // Only update the model when the q_index and rate behave normally. - if (valid) { - // Fit the ratio and bias of rq_model based on last two recode histories. - const double s1 = vp9_convert_qindex_to_q(q_index1, VPX_BITS_8); - const double s2 = vp9_convert_qindex_to_q(q_index2, VPX_BITS_8); - if (fabs(log2(s1) - log2(s2)) > delta) { - rq_model->ratio = (r2 - r1) / (log2(s1) - log2(s2)); - rq_model->bias = r1 + (rq_model->ratio) * log2(s1); - if (rq_model->ratio > delta && rq_model->bias > delta) { - rq_model->ready = 1; - } - } - } - } else if (recode_count == 1) { - if (rq_model->ready) { - // Update the ratio only when the initial model exists and we only have - // one recode history. - const int prev_q = rq_history->q_index_history[recode_count - 1]; - const double prev_q_step = vp9_convert_qindex_to_q(prev_q, VPX_BITS_8); - if (fabs(log2(prev_q_step)) > delta) { - const int actual_bits = rq_history->rate_history[recode_count - 1]; - rq_model->ratio = - rq_model->ratio + (target_bits - actual_bits) / log2(prev_q_step); - } - } - } -} -#endif // CONFIG_RATE_CTRL - -static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest -#if CONFIG_RATE_CTRL - , - RATE_QINDEX_HISTORY *rq_history -#endif // CONFIG_RATE_CTRL -) { +static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest, + size_t dest_size) { const VP9EncoderConfig *const oxcf = &cpi->oxcf; VP9_COMMON *const cm = &cpi->common; RATE_CONTROL *const rc = &cpi->rc; @@ -4390,32 +4365,13 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest int frame_over_shoot_limit; int frame_under_shoot_limit; int q = 0, q_low = 0, q_high = 0; - int last_q_attempt = 0; int enable_acl; #ifdef AGGRESSIVE_VBR int qrange_adj = 1; #endif - // A flag which indicates whether we are recoding the current frame - // when the current frame size is larger than the max frame size in the - // external rate control model. - // This flag doesn't have any impact when external rate control is not used. - int ext_rc_recode = 0; - // Maximal frame size allowed by the external rate control. - // case: 0, we ignore the max frame size limit, and encode with the qindex - // passed in by the external rate control model. - // case: -1, we take VP9's decision for the max frame size. - int ext_rc_max_frame_size = 0; const int orig_rc_max_frame_bandwidth = rc->max_frame_bandwidth; -#if CONFIG_RATE_CTRL - const FRAME_UPDATE_TYPE update_type = - cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index]; - const ENCODE_FRAME_TYPE frame_type = get_encode_frame_type(update_type); - RATE_QSTEP_MODEL *rq_model = &cpi->rq_model[frame_type]; - init_rq_history(rq_history); -#endif // CONFIG_RATE_CTRL - if (cm->show_existing_frame) { rc->this_frame_target = 0; if (is_psnr_calc_enabled(cpi)) set_raw_source_frame(cpi); @@ -4428,6 +4384,9 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest (cpi->twopass.gf_group.index == 1) : 0; +#if CONFIG_COLLECT_COMPONENT_TIMING + printf("\n Encoding a frame: \n"); +#endif do { vpx_clear_system_state(); @@ -4476,17 +4435,7 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest // Unfiltered raw source used in metrics calculation if the source // has been filtered. if (is_psnr_calc_enabled(cpi)) { -#ifdef ENABLE_KF_DENOISE - if (is_spatial_denoise_enabled(cpi)) { - cpi->raw_source_frame = vp9_scale_if_required( - cm, &cpi->raw_unscaled_source, &cpi->raw_scaled_source, - (oxcf->pass == 0), EIGHTTAP, 0); - } else { - cpi->raw_source_frame = cpi->Source; - } -#else - cpi->raw_source_frame = cpi->Source; -#endif + set_raw_source_frame(cpi); } if (cpi->unscaled_last_source != NULL) @@ -4501,42 +4450,47 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest vp9_scale_references(cpi); } -#if CONFIG_RATE_CTRL - // TODO(angiebird): This is a hack for making sure the encoder use the - // external_quantize_index exactly. Avoid this kind of hack later. - if (cpi->oxcf.use_simple_encode_api) { - if (cpi->encode_command.use_external_target_frame_bits) { - q = rq_model_predict_q_index(rq_model, rq_history, - rc->this_frame_target); - } - if (cpi->encode_command.use_external_quantize_index) { - q = cpi->encode_command.external_quantize_index; - } - } -#endif // CONFIG_RATE_CTRL - if (cpi->ext_ratectrl.ready && !ext_rc_recode) { + const GF_GROUP *gf_group = &cpi->twopass.gf_group; + int ext_rc_delta_q_uv = 0; + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_QP) != 0 && + cpi->ext_ratectrl.funcs.get_encodeframe_decision != NULL) { vpx_codec_err_t codec_status; - const GF_GROUP *gf_group = &cpi->twopass.gf_group; vpx_rc_encodeframe_decision_t encode_frame_decision; - FRAME_UPDATE_TYPE update_type = gf_group->update_type[gf_group->index]; - const int ref_frame_flags = get_ref_frame_flags(cpi); - RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES]; - const RefCntBuffer *curr_frame_buf = - get_ref_cnt_buffer(cm, cm->new_fb_idx); - get_ref_frame_bufs(cpi, ref_frame_bufs); + int sb_size = num_8x8_blocks_wide_lookup[BLOCK_64X64] * MI_SIZE; + int frame_height_sb = (cm->height + sb_size - 1) / sb_size; + int frame_width_sb = (cm->width + sb_size - 1) / sb_size; + CHECK_MEM_ERROR(&cm->error, encode_frame_decision.sb_params_list, + (sb_params *)vpx_calloc( + frame_height_sb * frame_width_sb, + sizeof(*encode_frame_decision.sb_params_list))); codec_status = vp9_extrc_get_encodeframe_decision( - &cpi->ext_ratectrl, curr_frame_buf->frame_index, - cm->current_frame_coding_index, gf_group->index, update_type, - ref_frame_bufs, ref_frame_flags, &encode_frame_decision); + &cpi->ext_ratectrl, gf_group->index, &encode_frame_decision); if (codec_status != VPX_CODEC_OK) { vpx_internal_error(&cm->error, codec_status, "vp9_extrc_get_encodeframe_decision() failed"); } - q = encode_frame_decision.q_index; - ext_rc_max_frame_size = encode_frame_decision.max_frame_size; + for (int idx = 0; idx < frame_height_sb * frame_width_sb; ++idx) { + cpi->sb_mul_scale[idx] = + (((int64_t)encode_frame_decision.sb_params_list[idx].rdmult * 256) / + (encode_frame_decision.rdmult + 1)); + } + vpx_free(encode_frame_decision.sb_params_list); + // If the external model recommends a reserved value, we use + // libvpx's default q. + if (encode_frame_decision.q_index != VPX_DEFAULT_Q) { + q = encode_frame_decision.q_index; + } + ext_rc_delta_q_uv = encode_frame_decision.delta_q_uv; } - vp9_set_quantizer(cpi, q); + if (cpi->ext_ratectrl.ready && cpi->ext_ratectrl.log_file) { + fprintf(cpi->ext_ratectrl.log_file, + "ENCODE_FRAME_INFO gop_index %d update_type %d q %d\n", + gf_group->index, gf_group->update_type[gf_group->index], q); + } + + vp9_set_quantizer(cpi, q, ext_rc_delta_q_uv); if (loop_count == 0) setup_frame(cpi); @@ -4567,71 +4521,18 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest // to recode. if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { save_coding_context(cpi); - if (!cpi->sf.use_nonrd_pick_mode) vp9_pack_bitstream(cpi, dest, size); + if (!cpi->sf.use_nonrd_pick_mode) + vp9_pack_bitstream(cpi, dest, dest_size, size); rc->projected_frame_size = (int)(*size) << 3; if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; } - if (cpi->ext_ratectrl.ready) { - last_q_attempt = q; - // In general, for the external rate control, we take the qindex provided - // as input and encode the frame with this qindex faithfully. However, - // in some extreme scenarios, the provided qindex leads to a massive - // overshoot of frame size. In this case, we fall back to VP9's decision - // to pick a new qindex and recode the frame. We return the new qindex - // through the API to the external model. - if (ext_rc_max_frame_size == 0) { - break; - } else if (ext_rc_max_frame_size == -1) { - if (rc->projected_frame_size < rc->max_frame_bandwidth) { - break; - } - } else { - if (rc->projected_frame_size < ext_rc_max_frame_size) { - break; - } - } - rc->max_frame_bandwidth = ext_rc_max_frame_size; - // If the current frame size exceeds the ext_rc_max_frame_size, - // we adjust the worst qindex to meet the frame size constraint. - q_high = 255; - ext_rc_recode = 1; + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_QP) != 0) { + break; } -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - // This part needs to be after save_coding_context() because - // restore_coding_context will be called in the end of this function. - // TODO(angiebird): This is a hack for making sure the encoder use the - // external_quantize_index exactly. Avoid this kind of hack later. - if (cpi->encode_command.use_external_quantize_index) { - break; - } - - if (cpi->encode_command.use_external_target_frame_bits) { - const double percent_diff = get_bits_percent_diff( - rc->this_frame_target, rc->projected_frame_size); - update_rq_history(rq_history, rc->this_frame_target, - rc->projected_frame_size, q); - loop_count += 1; - - rq_model_update(rq_history, rc->this_frame_target, rq_model); - - // Check if we hit the target bitrate. - if (percent_diff <= - cpi->encode_command.target_frame_bits_error_percent || - rq_history->recode_count >= RATE_CTRL_MAX_RECODE_NUM || - rq_history->q_index_low >= rq_history->q_index_high) { - break; - } - - loop = 1; - restore_coding_context(cpi); - continue; - } - } -#endif // CONFIG_RATE_CTRL if (oxcf->rc_mode == VPX_Q) { loop = 0; @@ -4799,23 +4700,6 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest rc->projected_frame_size < rc->max_frame_bandwidth) loop = 0; - // Special handling of external max frame size constraint - if (ext_rc_recode) { - // If the largest q is not able to meet the max frame size limit, - // do nothing. - if (rc->projected_frame_size > ext_rc_max_frame_size && - last_q_attempt == 255) { - break; - } - // If VP9's q selection leads to a smaller q, we force it to use - // a larger q to better approximate the external max frame size - // constraint. - if (rc->projected_frame_size > ext_rc_max_frame_size && - q <= last_q_attempt) { - q = VPXMIN(255, last_q_attempt + 1); - } - } - if (loop) { ++loop_count; ++loop_at_this_size; @@ -4827,6 +4711,9 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) if (loop) restore_coding_context(cpi); +#if CONFIG_COLLECT_COMPONENT_TIMING + if (loop) printf("\n Recoding:"); +#endif } while (loop); rc->max_frame_bandwidth = orig_rc_max_frame_bandwidth; @@ -4881,35 +4768,6 @@ static void set_ext_overrides(VP9_COMP *cpi) { } } -YV12_BUFFER_CONFIG *vp9_svc_twostage_scale( - VP9_COMMON *cm, YV12_BUFFER_CONFIG *unscaled, YV12_BUFFER_CONFIG *scaled, - YV12_BUFFER_CONFIG *scaled_temp, INTERP_FILTER filter_type, - int phase_scaler, INTERP_FILTER filter_type2, int phase_scaler2) { - if (cm->mi_cols * MI_SIZE != unscaled->y_width || - cm->mi_rows * MI_SIZE != unscaled->y_height) { -#if CONFIG_VP9_HIGHBITDEPTH - if (cm->bit_depth == VPX_BITS_8) { - vp9_scale_and_extend_frame(unscaled, scaled_temp, filter_type2, - phase_scaler2); - vp9_scale_and_extend_frame(scaled_temp, scaled, filter_type, - phase_scaler); - } else { - scale_and_extend_frame(unscaled, scaled_temp, (int)cm->bit_depth, - filter_type2, phase_scaler2); - scale_and_extend_frame(scaled_temp, scaled, (int)cm->bit_depth, - filter_type, phase_scaler); - } -#else - vp9_scale_and_extend_frame(unscaled, scaled_temp, filter_type2, - phase_scaler2); - vp9_scale_and_extend_frame(scaled_temp, scaled, filter_type, phase_scaler); -#endif // CONFIG_VP9_HIGHBITDEPTH - return scaled; - } else { - return unscaled; - } -} - YV12_BUFFER_CONFIG *vp9_scale_if_required( VP9_COMMON *cm, YV12_BUFFER_CONFIG *unscaled, YV12_BUFFER_CONFIG *scaled, int use_normative_scaler, INTERP_FILTER filter_type, int phase_scaler) { @@ -4924,13 +4782,14 @@ YV12_BUFFER_CONFIG *vp9_scale_if_required( scale_and_extend_frame(unscaled, scaled, (int)cm->bit_depth, filter_type, phase_scaler); else - scale_and_extend_frame_nonnormative(unscaled, scaled, (int)cm->bit_depth); + vp9_scale_and_extend_frame_nonnormative(unscaled, scaled, + (int)cm->bit_depth); #else if (use_normative_scaler && unscaled->y_width <= (scaled->y_width << 1) && unscaled->y_height <= (scaled->y_height << 1)) vp9_scale_and_extend_frame(unscaled, scaled, filter_type, phase_scaler); else - scale_and_extend_frame_nonnormative(unscaled, scaled); + vp9_scale_and_extend_frame_nonnormative(unscaled, scaled); #endif // CONFIG_VP9_HIGHBITDEPTH return scaled; } else { @@ -4982,8 +4841,8 @@ static int setup_interp_filter_search_mask(VP9_COMP *cpi) { #ifdef ENABLE_KF_DENOISE // Baseline kernel weights for denoise -static uint8_t dn_kernal_3[9] = { 1, 2, 1, 2, 4, 2, 1, 2, 1 }; -static uint8_t dn_kernal_5[25] = { 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 4, +static uint8_t dn_kernel_3[9] = { 1, 2, 1, 2, 4, 2, 1, 2, 1 }; +static uint8_t dn_kernel_5[25] = { 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 4, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1 }; static INLINE void add_denoise_point(int centre_val, int data_val, int thresh, @@ -5000,17 +4859,17 @@ static void spatial_denoise_point(uint8_t *src_ptr, const int stride, int sum_weight = 0; int sum_val = 0; int thresh = strength; - int kernal_size = 5; + int kernel_size = 5; int half_k_size = 2; int i, j; int max_diff = 0; uint8_t *tmp_ptr; - uint8_t *kernal_ptr; + uint8_t *kernel_ptr; // Find the maximum deviation from the source point in the locale. tmp_ptr = src_ptr - (stride * (half_k_size + 1)) - (half_k_size + 1); - for (i = 0; i < kernal_size + 2; ++i) { - for (j = 0; j < kernal_size + 2; ++j) { + for (i = 0; i < kernel_size + 2; ++i) { + for (j = 0; j < kernel_size + 2; ++j) { max_diff = VPXMAX(max_diff, abs((int)*src_ptr - (int)tmp_ptr[j])); } tmp_ptr += stride; @@ -5018,19 +4877,19 @@ static void spatial_denoise_point(uint8_t *src_ptr, const int stride, // Select the kernel size. if (max_diff > (strength + (strength >> 1))) { - kernal_size = 3; + kernel_size = 3; half_k_size = 1; thresh = thresh >> 1; } - kernal_ptr = (kernal_size == 3) ? dn_kernal_3 : dn_kernal_5; + kernel_ptr = (kernel_size == 3) ? dn_kernel_3 : dn_kernel_5; // Apply the kernel tmp_ptr = src_ptr - (stride * half_k_size) - half_k_size; - for (i = 0; i < kernal_size; ++i) { - for (j = 0; j < kernal_size; ++j) { - add_denoise_point((int)*src_ptr, (int)tmp_ptr[j], thresh, *kernal_ptr, + for (i = 0; i < kernel_size; ++i) { + for (j = 0; j < kernel_size; ++j) { + add_denoise_point((int)*src_ptr, (int)tmp_ptr[j], thresh, *kernel_ptr, &sum_val, &sum_weight); - ++kernal_ptr; + ++kernel_ptr; } tmp_ptr += stride; } @@ -5045,17 +4904,17 @@ static void highbd_spatial_denoise_point(uint16_t *src_ptr, const int stride, int sum_weight = 0; int sum_val = 0; int thresh = strength; - int kernal_size = 5; + int kernel_size = 5; int half_k_size = 2; int i, j; int max_diff = 0; uint16_t *tmp_ptr; - uint8_t *kernal_ptr; + uint8_t *kernel_ptr; // Find the maximum deviation from the source point in the locale. tmp_ptr = src_ptr - (stride * (half_k_size + 1)) - (half_k_size + 1); - for (i = 0; i < kernal_size + 2; ++i) { - for (j = 0; j < kernal_size + 2; ++j) { + for (i = 0; i < kernel_size + 2; ++i) { + for (j = 0; j < kernel_size + 2; ++j) { max_diff = VPXMAX(max_diff, abs((int)src_ptr - (int)tmp_ptr[j])); } tmp_ptr += stride; @@ -5063,19 +4922,19 @@ static void highbd_spatial_denoise_point(uint16_t *src_ptr, const int stride, // Select the kernel size. if (max_diff > (strength + (strength >> 1))) { - kernal_size = 3; + kernel_size = 3; half_k_size = 1; thresh = thresh >> 1; } - kernal_ptr = (kernal_size == 3) ? dn_kernal_3 : dn_kernal_5; + kernel_ptr = (kernel_size == 3) ? dn_kernel_3 : dn_kernel_5; // Apply the kernel tmp_ptr = src_ptr - (stride * half_k_size) - half_k_size; - for (i = 0; i < kernal_size; ++i) { - for (j = 0; j < kernal_size; ++j) { - add_denoise_point((int)*src_ptr, (int)tmp_ptr[j], thresh, *kernal_ptr, + for (i = 0; i < kernel_size; ++i) { + for (j = 0; j < kernel_size; ++j) { + add_denoise_point((int)*src_ptr, (int)tmp_ptr[j], thresh, *kernel_ptr, &sum_val, &sum_weight); - ++kernal_ptr; + ++kernel_ptr; } tmp_ptr += stride; } @@ -5120,8 +4979,7 @@ static void spatial_denoise_frame(VP9_COMP *cpi) { // Base the filter strength on the current active max Q. const int q = (int)(vp9_convert_qindex_to_q(twopass->active_worst_quality, cm->bit_depth)); - int strength = - VPXMAX(oxcf->arnr_strength >> 2, VPXMIN(oxcf->arnr_strength, (q >> 4))); + int strength = clamp(q >> 4, oxcf->arnr_strength >> 2, oxcf->arnr_strength); // Denoise each of Y,U and V buffers. spatial_denoise_buffer(cpi, src->y_buffer, src->y_stride, src->y_width, @@ -5138,7 +4996,7 @@ static void spatial_denoise_frame(VP9_COMP *cpi) { #if !CONFIG_REALTIME_ONLY static void vp9_try_disable_lookahead_aq(VP9_COMP *cpi, size_t *size, - uint8_t *dest) { + uint8_t *dest, size_t dest_size) { if (cpi->common.seg.enabled) if (ALT_REF_AQ_PROTECT_GAIN) { size_t nsize = *size; @@ -5149,7 +5007,7 @@ static void vp9_try_disable_lookahead_aq(VP9_COMP *cpi, size_t *size, save_coding_context(cpi); vp9_disable_segmentation(&cpi->common.seg); - vp9_pack_bitstream(cpi, dest, &nsize); + vp9_pack_bitstream(cpi, dest, dest_size, &nsize); restore_coding_context(cpi); overhead = (int)*size - (int)nsize; @@ -5173,6 +5031,24 @@ static void set_frame_index(VP9_COMP *cpi, VP9_COMMON *cm) { } } +static void init_mb_ssim_rdmult_scaling_buffer(VP9_COMP *cpi) { + VP9_COMMON *cm = &cpi->common; + + if (cpi->mi_ssim_rdmult_scaling_factors && + cpi->mi_ssim_rdmult_scaling_factors_rows >= cm->mb_rows && + cpi->mi_ssim_rdmult_scaling_factors_cols >= cm->mb_cols) + return; + + vpx_free(cpi->mi_ssim_rdmult_scaling_factors); + cpi->mi_ssim_rdmult_scaling_factors = NULL; + + CHECK_MEM_ERROR(&cm->error, cpi->mi_ssim_rdmult_scaling_factors, + vpx_calloc(cm->mb_rows * cm->mb_cols, + sizeof(*cpi->mi_ssim_rdmult_scaling_factors))); + cpi->mi_ssim_rdmult_scaling_factors_rows = cm->mb_rows; + cpi->mi_ssim_rdmult_scaling_factors_cols = cm->mb_cols; +} + static void set_mb_ssim_rdmult_scaling(VP9_COMP *cpi) { VP9_COMMON *cm = &cpi->common; ThreadData *td = &cpi->td; @@ -5244,8 +5120,8 @@ static void set_mb_ssim_rdmult_scaling(VP9_COMP *cpi) { // Process the wiener variance in 16x16 block basis. static int qsort_comp(const void *elem1, const void *elem2) { - int a = *((const int *)elem1); - int b = *((const int *)elem2); + int a = *((const tran_low_t *)elem1); + int b = *((const tran_low_t *)elem2); if (a > b) return 1; if (a < b) return -1; return 0; @@ -5262,12 +5138,34 @@ static void init_mb_wiener_var_buffer(VP9_COMP *cpi) { cpi->mb_wiener_variance = NULL; CHECK_MEM_ERROR( - cm, cpi->mb_wiener_variance, + &cm->error, cpi->mb_wiener_variance, vpx_calloc(cm->mb_rows * cm->mb_cols, sizeof(*cpi->mb_wiener_variance))); cpi->mb_wiener_var_rows = cm->mb_rows; cpi->mb_wiener_var_cols = cm->mb_cols; } +static void init_sb_mul_scale_buffer(VP9_COMP *cpi) { + VP9_COMMON *cm = &cpi->common; + + // Note: sb_mul_scale must use its own dimension tracking. It must not share + // mb_wiener_var_rows/cols with mb_wiener_variance, otherwise one of the two + // buffers may be left unallocated. + if (cpi->sb_mul_scale && cpi->sb_mul_scale_rows >= cm->mb_rows && + cpi->sb_mul_scale_cols >= cm->mb_cols) + return; + + vpx_free(cpi->sb_mul_scale); + cpi->sb_mul_scale = NULL; + cpi->sb_mul_scale_rows = 0; + cpi->sb_mul_scale_cols = 0; + + CHECK_MEM_ERROR( + &cm->error, cpi->sb_mul_scale, + vpx_calloc(cm->mb_rows * cm->mb_cols, sizeof(*cpi->sb_mul_scale))); + cpi->sb_mul_scale_rows = cm->mb_rows; + cpi->sb_mul_scale_cols = cm->mb_cols; +} + static void set_mb_wiener_variance(VP9_COMP *cpi) { VP9_COMMON *cm = &cpi->common; uint8_t *buffer = cpi->Source->y_buffer; @@ -5321,22 +5219,22 @@ static void set_mb_wiener_variance(VP9_COMP *cpi) { vpx_highbd_subtract_block(block_size, block_size, src_diff, block_size, mb_buffer, buf_stride, zero_pred, block_size, xd->bd); - highbd_wht_fwd_txfm(src_diff, block_size, coeff, tx_size); + vp9_highbd_wht_fwd_txfm(src_diff, block_size, coeff, tx_size); } else { vpx_subtract_block(block_size, block_size, src_diff, block_size, mb_buffer, buf_stride, zero_pred, block_size); - wht_fwd_txfm(src_diff, block_size, coeff, tx_size); + vp9_wht_fwd_txfm(src_diff, block_size, coeff, tx_size); } #else vpx_subtract_block(block_size, block_size, src_diff, block_size, mb_buffer, buf_stride, zero_pred, block_size); - wht_fwd_txfm(src_diff, block_size, coeff, tx_size); + vp9_wht_fwd_txfm(src_diff, block_size, coeff, tx_size); #endif // CONFIG_VP9_HIGHBITDEPTH coeff[0] = 0; for (idx = 1; idx < coeff_count; ++idx) coeff[idx] = abs(coeff[idx]); - qsort(coeff, coeff_count - 1, sizeof(*coeff), qsort_comp); + qsort(coeff, coeff_count, sizeof(*coeff), qsort_comp); // Noise level estimation median_val = coeff[coeff_count / 2]; @@ -5364,6 +5262,23 @@ static void set_mb_wiener_variance(VP9_COMP *cpi) { } #if !CONFIG_REALTIME_ONLY +static PSNR_STATS compute_psnr_stats(const YV12_BUFFER_CONFIG *source_frame, + const YV12_BUFFER_CONFIG *coded_frame, + uint32_t bit_depth, + uint32_t input_bit_depth, + int spatial_layer_id) { + PSNR_STATS psnr; +#if CONFIG_VP9_HIGHBITDEPTH + vpx_calc_highbd_psnr(source_frame, coded_frame, &psnr, bit_depth, + input_bit_depth, spatial_layer_id); +#else // CONFIG_VP9_HIGHBITDEPTH + (void)bit_depth; + (void)input_bit_depth; + vpx_calc_psnr(source_frame, coded_frame, &psnr, spatial_layer_id); +#endif // CONFIG_VP9_HIGHBITDEPTH + return psnr; +} + static void update_encode_frame_result_basic( FRAME_UPDATE_TYPE update_type, int show_idx, int quantize_index, ENCODE_FRAME_RESULT *encode_frame_result) { @@ -5371,104 +5286,17 @@ static void update_encode_frame_result_basic( encode_frame_result->update_type = update_type; encode_frame_result->quantize_index = quantize_index; } - -#if CONFIG_RATE_CTRL -static void yv12_buffer_to_image_buffer(const YV12_BUFFER_CONFIG *yv12_buffer, - IMAGE_BUFFER *image_buffer) { - const uint8_t *src_buf_ls[3] = { yv12_buffer->y_buffer, yv12_buffer->u_buffer, - yv12_buffer->v_buffer }; - const int src_stride_ls[3] = { yv12_buffer->y_stride, yv12_buffer->uv_stride, - yv12_buffer->uv_stride }; - const int w_ls[3] = { yv12_buffer->y_crop_width, yv12_buffer->uv_crop_width, - yv12_buffer->uv_crop_width }; - const int h_ls[3] = { yv12_buffer->y_crop_height, yv12_buffer->uv_crop_height, - yv12_buffer->uv_crop_height }; - int plane; - for (plane = 0; plane < 3; ++plane) { - const int src_stride = src_stride_ls[plane]; - const int w = w_ls[plane]; - const int h = h_ls[plane]; - const uint8_t *src_buf = src_buf_ls[plane]; - uint8_t *dst_buf = image_buffer->plane_buffer[plane]; - int r; - assert(image_buffer->plane_width[plane] == w); - assert(image_buffer->plane_height[plane] == h); - for (r = 0; r < h; ++r) { - memcpy(dst_buf, src_buf, sizeof(*src_buf) * w); - src_buf += src_stride; - dst_buf += w; - } - } -} -// This function will update extra information specific for simple_encode APIs -static void update_encode_frame_result_simple_encode( - int ref_frame_flags, FRAME_UPDATE_TYPE update_type, - const YV12_BUFFER_CONFIG *source_frame, const RefCntBuffer *coded_frame_buf, - RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES], int quantize_index, - uint32_t bit_depth, uint32_t input_bit_depth, const FRAME_COUNTS *counts, - const PARTITION_INFO *partition_info, - const MOTION_VECTOR_INFO *motion_vector_info, - const TplDepStats *tpl_stats_info, - ENCODE_FRAME_RESULT *encode_frame_result) { - PSNR_STATS psnr; - update_encode_frame_result_basic(update_type, coded_frame_buf->frame_index, - quantize_index, encode_frame_result); -#if CONFIG_VP9_HIGHBITDEPTH - vpx_calc_highbd_psnr(source_frame, &coded_frame_buf->buf, &psnr, bit_depth, - input_bit_depth); -#else // CONFIG_VP9_HIGHBITDEPTH - (void)bit_depth; - (void)input_bit_depth; - vpx_calc_psnr(source_frame, &coded_frame_buf->buf, &psnr); -#endif // CONFIG_VP9_HIGHBITDEPTH - encode_frame_result->frame_coding_index = coded_frame_buf->frame_coding_index; - - vp9_get_ref_frame_info(update_type, ref_frame_flags, ref_frame_bufs, - encode_frame_result->ref_frame_coding_indexes, - encode_frame_result->ref_frame_valid_list); - - encode_frame_result->psnr = psnr.psnr[0]; - encode_frame_result->sse = psnr.sse[0]; - encode_frame_result->frame_counts = *counts; - encode_frame_result->partition_info = partition_info; - encode_frame_result->motion_vector_info = motion_vector_info; - encode_frame_result->tpl_stats_info = tpl_stats_info; - if (encode_frame_result->coded_frame.allocated) { - yv12_buffer_to_image_buffer(&coded_frame_buf->buf, - &encode_frame_result->coded_frame); - } -} -#endif // CONFIG_RATE_CTRL #endif // !CONFIG_REALTIME_ONLY static void encode_frame_to_data_rate( - VP9_COMP *cpi, size_t *size, uint8_t *dest, unsigned int *frame_flags, - ENCODE_FRAME_RESULT *encode_frame_result) { + VP9_COMP *cpi, size_t *size, uint8_t *dest, size_t dest_size, + unsigned int *frame_flags, ENCODE_FRAME_RESULT *encode_frame_result) { VP9_COMMON *const cm = &cpi->common; const VP9EncoderConfig *const oxcf = &cpi->oxcf; struct segmentation *const seg = &cm->seg; TX_SIZE t; - // SVC: skip encoding of enhancement layer if the layer target bandwidth = 0. - // No need to set svc.skip_enhancement_layer if whole superframe will be - // dropped. - if (cpi->use_svc && cpi->svc.spatial_layer_id > 0 && - cpi->oxcf.target_bandwidth == 0 && - !(cpi->svc.framedrop_mode != LAYER_DROP && - (cpi->svc.framedrop_mode != CONSTRAINED_FROM_ABOVE_DROP || - cpi->svc - .force_drop_constrained_from_above[cpi->svc.number_spatial_layers - - 1]) && - cpi->svc.drop_spatial_layer[0])) { - cpi->svc.skip_enhancement_layer = 1; - vp9_rc_postencode_update_drop_frame(cpi); - cpi->ext_refresh_frame_flags_pending = 0; - cpi->last_frame_dropped = 1; - cpi->svc.last_layer_dropped[cpi->svc.spatial_layer_id] = 1; - cpi->svc.drop_spatial_layer[cpi->svc.spatial_layer_id] = 1; - vp9_inc_frame_in_layer(cpi); - return; - } + if (vp9_svc_check_skip_enhancement_layer(cpi)) return; set_ext_overrides(cpi); vpx_clear_system_state(); @@ -5486,6 +5314,11 @@ static void encode_frame_to_data_rate( set_ref_sign_bias(cpi); } + // On the very first frame set the deadline_mode_previous_frame to + // the current mode. + if (cpi->common.current_video_frame == 0) + cpi->deadline_mode_previous_frame = cpi->oxcf.mode; + // Set default state for segment based loop filter update flags. cm->lf.mode_ref_delta_update = 0; @@ -5520,37 +5353,65 @@ static void encode_frame_to_data_rate( } } - if (oxcf->tuning == VP8_TUNE_SSIM) set_mb_ssim_rdmult_scaling(cpi); + if (oxcf->tuning == VP8_TUNE_SSIM) { + init_mb_ssim_rdmult_scaling_buffer(cpi); + set_mb_ssim_rdmult_scaling(cpi); + } if (oxcf->aq_mode == PERCEPTUAL_AQ) { init_mb_wiener_var_buffer(cpi); set_mb_wiener_variance(cpi); } + init_sb_mul_scale_buffer(cpi); + vpx_clear_system_state(); #if CONFIG_INTERNAL_STATS memset(cpi->mode_chosen_counts, 0, MAX_MODES * sizeof(*cpi->mode_chosen_counts)); #endif -#if CONFIG_CONSISTENT_RECODE // Backup to ensure consistency between recodes save_encode_params(cpi); -#elif CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - save_encode_params(cpi); + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_RDMULT) != 0 && + cpi->ext_ratectrl.funcs.get_frame_rdmult != NULL) { + vpx_codec_err_t codec_status; + const GF_GROUP *gf_group = &cpi->twopass.gf_group; + FRAME_UPDATE_TYPE update_type = gf_group->update_type[gf_group->index]; + const int ref_frame_flags = get_ref_frame_flags(cpi); + RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES]; + const RefCntBuffer *curr_frame_buf = get_ref_cnt_buffer(cm, cm->new_fb_idx); + // index 0 of a gf group is always KEY/OVERLAY/GOLDEN. + // index 1 refers to the first encoding frame in a gf group. + // Therefore if it is ARF_UPDATE, it means this gf group uses alt ref. + // See function define_gf_group_structure(). + const int use_alt_ref = gf_group->update_type[1] == ARF_UPDATE; + int ext_rdmult = VPX_DEFAULT_RDMULT; + get_ref_frame_bufs(cpi, ref_frame_bufs); + codec_status = vp9_extrc_get_frame_rdmult( + &cpi->ext_ratectrl, curr_frame_buf->frame_index, + cm->current_frame_coding_index, gf_group->index, update_type, + gf_group->gf_group_size, use_alt_ref, ref_frame_bufs, ref_frame_flags, + &ext_rdmult); + if (codec_status != VPX_CODEC_OK) { + vpx_internal_error(&cm->error, codec_status, + "vp9_extrc_get_frame_rdmult() failed"); + } + cpi->ext_ratectrl.ext_rdmult = ext_rdmult; } -#endif if (cpi->sf.recode_loop == DISALLOW_RECODE) { - if (!encode_without_recode_loop(cpi, size, dest)) return; + if (!encode_without_recode_loop(cpi, size, dest, dest_size)) return; } else { #if !CONFIG_REALTIME_ONLY -#if CONFIG_RATE_CTRL - encode_with_recode_loop(cpi, size, dest, &encode_frame_result->rq_history); -#else // CONFIG_RATE_CTRL - encode_with_recode_loop(cpi, size, dest); -#endif // CONFIG_RATE_CTRL +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, encode_with_recode_loop_time); +#endif + encode_with_recode_loop(cpi, size, dest, dest_size); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, encode_with_recode_loop_time); +#endif #endif // !CONFIG_REALTIME_ONLY } @@ -5566,7 +5427,7 @@ static void encode_frame_to_data_rate( #if !CONFIG_REALTIME_ONLY // Disable segmentation if it decrease rate/distortion ratio if (cpi->oxcf.aq_mode == LOOKAHEAD_AQ) - vp9_try_disable_lookahead_aq(cpi, size, dest); + vp9_try_disable_lookahead_aq(cpi, size, dest, dest_size); #endif #if CONFIG_VP9_TEMPORAL_DENOISING @@ -5608,20 +5469,30 @@ static void encode_frame_to_data_rate( cm->frame_to_show->render_width = cm->render_width; cm->frame_to_show->render_height = cm->render_height; +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, loopfilter_frame_time); +#endif // Pick the loop filter level for the frame. loopfilter_frame(cpi, cm); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, loopfilter_frame_time); +#endif if (cpi->rc.use_post_encode_drop) save_coding_context(cpi); +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, vp9_pack_bitstream_time); +#endif // build the bitstream - vp9_pack_bitstream(cpi, dest, size); + vp9_pack_bitstream(cpi, dest, dest_size, size); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, vp9_pack_bitstream_time); +#endif - { - const RefCntBuffer *coded_frame_buf = - get_ref_cnt_buffer(cm, cm->new_fb_idx); + if (cpi->ext_ratectrl.ready && + cpi->ext_ratectrl.funcs.update_encodeframe_result != NULL) { vpx_codec_err_t codec_status = vp9_extrc_update_encodeframe_result( - &cpi->ext_ratectrl, (*size) << 3, cpi->Source, &coded_frame_buf->buf, - cm->bit_depth, cpi->oxcf.input_bit_depth, cm->base_qindex); + &cpi->ext_ratectrl, (*size) << 3, cm->base_qindex); if (codec_status != VPX_CODEC_OK) { vpx_internal_error(&cm->error, codec_status, "vp9_extrc_update_encodeframe_result() failed"); @@ -5630,7 +5501,7 @@ static void encode_frame_to_data_rate( #if CONFIG_REALTIME_ONLY (void)encode_frame_result; assert(encode_frame_result == NULL); -#else // CONFIG_REALTIME_ONLY +#else // CONFIG_REALTIME_ONLY if (encode_frame_result != NULL) { const RefCntBuffer *coded_frame_buf = get_ref_cnt_buffer(cm, cm->new_fb_idx); @@ -5658,18 +5529,14 @@ static void encode_frame_to_data_rate( update_encode_frame_result_basic(update_type, coded_frame_buf->frame_index, quantize_index, encode_frame_result); -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - const int ref_frame_flags = get_ref_frame_flags(cpi); - update_encode_frame_result_simple_encode( - ref_frame_flags, - cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], - cpi->Source, coded_frame_buf, ref_frame_bufs, quantize_index, - cm->bit_depth, cpi->oxcf.input_bit_depth, cpi->td.counts, - cpi->partition_info, cpi->motion_vector_info, cpi->tpl_stats_info, - encode_frame_result); + if (cpi->ext_ratectrl.ready && cpi->ext_ratectrl.log_file) { + PSNR_STATS psnr = compute_psnr_stats( + cpi->Source, &coded_frame_buf->buf, cm->bit_depth, + cpi->oxcf.input_bit_depth, cpi->svc.spatial_layer_id); + fprintf(cpi->ext_ratectrl.log_file, + "ENCODE_FRAME_RESULT gop_index %d psnr %f bits %zu\n", + cpi->twopass.gf_group.index, psnr.psnr[0], (*size) << 3); } -#endif // CONFIG_RATE_CTRL } #endif // CONFIG_REALTIME_ONLY @@ -5801,42 +5668,33 @@ static void encode_frame_to_data_rate( } static void SvcEncode(VP9_COMP *cpi, size_t *size, uint8_t *dest, - unsigned int *frame_flags) { + size_t dest_size, unsigned int *frame_flags) { vp9_rc_get_svc_params(cpi); - encode_frame_to_data_rate(cpi, size, dest, frame_flags, + encode_frame_to_data_rate(cpi, size, dest, dest_size, frame_flags, /*encode_frame_result = */ NULL); } static void Pass0Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, - unsigned int *frame_flags) { + size_t dest_size, unsigned int *frame_flags) { if (cpi->oxcf.rc_mode == VPX_CBR) { vp9_rc_get_one_pass_cbr_params(cpi); } else { vp9_rc_get_one_pass_vbr_params(cpi); } - encode_frame_to_data_rate(cpi, size, dest, frame_flags, + encode_frame_to_data_rate(cpi, size, dest, dest_size, frame_flags, /*encode_frame_result = */ NULL); } #if !CONFIG_REALTIME_ONLY static void Pass2Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, - unsigned int *frame_flags, + size_t dest_size, unsigned int *frame_flags, ENCODE_FRAME_RESULT *encode_frame_result) { cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; - - if (cpi->common.current_frame_coding_index == 0) { - VP9_COMMON *cm = &cpi->common; - const vpx_codec_err_t codec_status = vp9_extrc_send_firstpass_stats( - &cpi->ext_ratectrl, &cpi->twopass.first_pass_info); - if (codec_status != VPX_CODEC_OK) { - vpx_internal_error(&cm->error, codec_status, - "vp9_extrc_send_firstpass_stats() failed"); - } - } #if CONFIG_MISMATCH_DEBUG mismatch_move_frame_idx_w(); #endif - encode_frame_to_data_rate(cpi, size, dest, frame_flags, encode_frame_result); + encode_frame_to_data_rate(cpi, size, dest, dest_size, frame_flags, + encode_frame_result); } #endif // !CONFIG_REALTIME_ONLY @@ -5844,7 +5702,9 @@ int vp9_receive_raw_frame(VP9_COMP *cpi, vpx_enc_frame_flags_t frame_flags, YV12_BUFFER_CONFIG *sd, int64_t time_stamp, int64_t end_time) { VP9_COMMON *const cm = &cpi->common; +#if CONFIG_INTERNAL_STATS struct vpx_usec_timer timer; +#endif int res = 0; const int subsampling_x = sd->subsampling_x; const int subsampling_y = sd->subsampling_y; @@ -5854,6 +5714,31 @@ int vp9_receive_raw_frame(VP9_COMP *cpi, vpx_enc_frame_flags_t frame_flags, const int use_highbitdepth = 0; #endif + if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && + (subsampling_x != 1 || subsampling_y != 1)) { + vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, + "Non-4:2:0 color format requires profile 1 or 3"); + return -1; + } + if ((cm->profile == PROFILE_1 || cm->profile == PROFILE_3) && + (subsampling_x == 1 && subsampling_y == 1)) { + vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, + "4:2:0 color format requires profile 0 or 2"); + return -1; + } + if (cm->color_space == VPX_CS_SRGB) { + if (cm->profile == PROFILE_0 || cm->profile == PROFILE_2) { + vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, + "SRGB color space requires profile 1 or 3"); + return -1; + } + if (subsampling_x != 0 || subsampling_y != 0) { + vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, + "SRGB color space requires 4:4:4"); + return -1; + } + } + update_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); #if CONFIG_VP9_TEMPORAL_DENOISING setup_denoiser_buffer(cpi); @@ -5861,26 +5746,17 @@ int vp9_receive_raw_frame(VP9_COMP *cpi, vpx_enc_frame_flags_t frame_flags, alloc_raw_frame_buffers(cpi); +#if CONFIG_INTERNAL_STATS vpx_usec_timer_start(&timer); +#endif if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, use_highbitdepth, frame_flags)) res = -1; +#if CONFIG_INTERNAL_STATS vpx_usec_timer_mark(&timer); cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); - - if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && - (subsampling_x != 1 || subsampling_y != 1)) { - vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, - "Non-4:2:0 color format requires profile 1 or 3"); - res = -1; - } - if ((cm->profile == PROFILE_1 || cm->profile == PROFILE_3) && - (subsampling_x == 1 && subsampling_y == 1)) { - vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, - "4:2:0 color format requires profile 0 or 2"); - res = -1; - } +#endif return res; } @@ -6005,7 +5881,7 @@ static void level_rc_framerate(VP9_COMP *cpi, int arf_src_index) { } } -static void update_level_info(VP9_COMP *cpi, size_t *size, int arf_src_index) { +static void update_level_info(VP9_COMP *cpi, size_t size, int arf_src_index) { VP9_COMMON *const cm = &cpi->common; Vp9LevelInfo *const level_info = &cpi->level_info; Vp9LevelSpec *const level_spec = &level_info->level_spec; @@ -6021,7 +5897,7 @@ static void update_level_info(VP9_COMP *cpi, size_t *size, int arf_src_index) { vpx_clear_system_state(); // update level_stats - level_stats->total_compressed_size += *size; + level_stats->total_compressed_size += size; if (cm->show_frame) { level_stats->total_uncompressed_size += luma_pic_size + @@ -6052,7 +5928,7 @@ static void update_level_info(VP9_COMP *cpi, size_t *size, int arf_src_index) { level_stats->frame_window_buffer.start = (idx + 1) % FRAME_WINDOW_SIZE; } level_stats->frame_window_buffer.buf[idx].ts = cpi->last_time_stamp_seen; - level_stats->frame_window_buffer.buf[idx].size = (uint32_t)(*size); + level_stats->frame_window_buffer.buf[idx].size = (uint32_t)size; level_stats->frame_window_buffer.buf[idx].luma_samples = luma_pic_size; if (cm->frame_type == KEY_FRAME) { @@ -6214,1391 +6090,6 @@ static void update_level_info(VP9_COMP *cpi, size_t *size, int arf_src_index) { } } -typedef struct GF_PICTURE { - YV12_BUFFER_CONFIG *frame; - int ref_frame[3]; - FRAME_UPDATE_TYPE update_type; -} GF_PICTURE; - -static void init_gop_frames(VP9_COMP *cpi, GF_PICTURE *gf_picture, - const GF_GROUP *gf_group, int *tpl_group_frames) { - VP9_COMMON *cm = &cpi->common; - int frame_idx = 0; - int i; - int gld_index = -1; - int alt_index = -1; - int lst_index = -1; - int arf_index_stack[MAX_ARF_LAYERS]; - int arf_stack_size = 0; - int extend_frame_count = 0; - int pframe_qindex = cpi->tpl_stats[2].base_qindex; - int frame_gop_offset = 0; - - RefCntBuffer *frame_bufs = cm->buffer_pool->frame_bufs; - int8_t recon_frame_index[REFS_PER_FRAME + MAX_ARF_LAYERS]; - - memset(recon_frame_index, -1, sizeof(recon_frame_index)); - stack_init(arf_index_stack, MAX_ARF_LAYERS); - - // TODO(jingning): To be used later for gf frame type parsing. - (void)gf_group; - - for (i = 0; i < FRAME_BUFFERS; ++i) { - if (frame_bufs[i].ref_count == 0) { - alloc_frame_mvs(cm, i); - if (vpx_realloc_frame_buffer(&frame_bufs[i].buf, cm->width, cm->height, - cm->subsampling_x, cm->subsampling_y, -#if CONFIG_VP9_HIGHBITDEPTH - cm->use_highbitdepth, -#endif - VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, - NULL, NULL, NULL)) - vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, - "Failed to allocate frame buffer"); - - recon_frame_index[frame_idx] = i; - ++frame_idx; - - if (frame_idx >= REFS_PER_FRAME + cpi->oxcf.enable_auto_arf) break; - } - } - - for (i = 0; i < REFS_PER_FRAME + 1; ++i) { - assert(recon_frame_index[i] >= 0); - cpi->tpl_recon_frames[i] = &frame_bufs[recon_frame_index[i]].buf; - } - - *tpl_group_frames = 0; - - // Initialize Golden reference frame. - gf_picture[0].frame = get_ref_frame_buffer(cpi, GOLDEN_FRAME); - for (i = 0; i < 3; ++i) gf_picture[0].ref_frame[i] = -1; - gf_picture[0].update_type = gf_group->update_type[0]; - gld_index = 0; - ++*tpl_group_frames; - - // Initialize base layer ARF frame - gf_picture[1].frame = cpi->Source; - gf_picture[1].ref_frame[0] = gld_index; - gf_picture[1].ref_frame[1] = lst_index; - gf_picture[1].ref_frame[2] = alt_index; - gf_picture[1].update_type = gf_group->update_type[1]; - alt_index = 1; - ++*tpl_group_frames; - - // Initialize P frames - for (frame_idx = 2; frame_idx < MAX_ARF_GOP_SIZE; ++frame_idx) { - struct lookahead_entry *buf; - frame_gop_offset = gf_group->frame_gop_index[frame_idx]; - buf = vp9_lookahead_peek(cpi->lookahead, frame_gop_offset - 1); - - if (buf == NULL) break; - - gf_picture[frame_idx].frame = &buf->img; - gf_picture[frame_idx].ref_frame[0] = gld_index; - gf_picture[frame_idx].ref_frame[1] = lst_index; - gf_picture[frame_idx].ref_frame[2] = alt_index; - gf_picture[frame_idx].update_type = gf_group->update_type[frame_idx]; - - switch (gf_group->update_type[frame_idx]) { - case ARF_UPDATE: - stack_push(arf_index_stack, alt_index, arf_stack_size); - ++arf_stack_size; - alt_index = frame_idx; - break; - case LF_UPDATE: lst_index = frame_idx; break; - case OVERLAY_UPDATE: - gld_index = frame_idx; - alt_index = stack_pop(arf_index_stack, arf_stack_size); - --arf_stack_size; - break; - case USE_BUF_FRAME: - lst_index = alt_index; - alt_index = stack_pop(arf_index_stack, arf_stack_size); - --arf_stack_size; - break; - default: break; - } - - ++*tpl_group_frames; - - // The length of group of pictures is baseline_gf_interval, plus the - // beginning golden frame from last GOP, plus the last overlay frame in - // the same GOP. - if (frame_idx == gf_group->gf_group_size) break; - } - - alt_index = -1; - ++frame_idx; - ++frame_gop_offset; - - // Extend two frames outside the current gf group. - for (; frame_idx < MAX_LAG_BUFFERS && extend_frame_count < 2; ++frame_idx) { - struct lookahead_entry *buf = - vp9_lookahead_peek(cpi->lookahead, frame_gop_offset - 1); - - if (buf == NULL) break; - - cpi->tpl_stats[frame_idx].base_qindex = pframe_qindex; - - gf_picture[frame_idx].frame = &buf->img; - gf_picture[frame_idx].ref_frame[0] = gld_index; - gf_picture[frame_idx].ref_frame[1] = lst_index; - gf_picture[frame_idx].ref_frame[2] = alt_index; - gf_picture[frame_idx].update_type = LF_UPDATE; - lst_index = frame_idx; - ++*tpl_group_frames; - ++extend_frame_count; - ++frame_gop_offset; - } -} - -static void init_tpl_stats(VP9_COMP *cpi) { - int frame_idx; - for (frame_idx = 0; frame_idx < MAX_ARF_GOP_SIZE; ++frame_idx) { - TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx]; - memset(tpl_frame->tpl_stats_ptr, 0, - tpl_frame->height * tpl_frame->width * - sizeof(*tpl_frame->tpl_stats_ptr)); - tpl_frame->is_valid = 0; - } -} - -#if CONFIG_NON_GREEDY_MV -static uint32_t full_pixel_motion_search(VP9_COMP *cpi, ThreadData *td, - MotionField *motion_field, - int frame_idx, uint8_t *cur_frame_buf, - uint8_t *ref_frame_buf, int stride, - BLOCK_SIZE bsize, int mi_row, - int mi_col, MV *mv) { - MACROBLOCK *const x = &td->mb; - MACROBLOCKD *const xd = &x->e_mbd; - MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv; - int step_param; - uint32_t bestsme = UINT_MAX; - const MvLimits tmp_mv_limits = x->mv_limits; - // lambda is used to adjust the importance of motion vector consistency. - // TODO(angiebird): Figure out lambda's proper value. - const int lambda = cpi->tpl_stats[frame_idx].lambda; - int_mv nb_full_mvs[NB_MVS_NUM]; - int nb_full_mv_num; - - MV best_ref_mv1 = { 0, 0 }; - MV best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */ - - best_ref_mv1_full.col = best_ref_mv1.col >> 3; - best_ref_mv1_full.row = best_ref_mv1.row >> 3; - - // Setup frame pointers - x->plane[0].src.buf = cur_frame_buf; - x->plane[0].src.stride = stride; - xd->plane[0].pre[0].buf = ref_frame_buf; - xd->plane[0].pre[0].stride = stride; - - step_param = mv_sf->reduce_first_step_size; - step_param = VPXMIN(step_param, MAX_MVSEARCH_STEPS - 2); - - vp9_set_mv_search_range(&x->mv_limits, &best_ref_mv1); - - nb_full_mv_num = - vp9_prepare_nb_full_mvs(motion_field, mi_row, mi_col, nb_full_mvs); - vp9_full_pixel_diamond_new(cpi, x, bsize, &best_ref_mv1_full, step_param, - lambda, 1, nb_full_mvs, nb_full_mv_num, mv); - - /* restore UMV window */ - x->mv_limits = tmp_mv_limits; - - return bestsme; -} - -static uint32_t sub_pixel_motion_search(VP9_COMP *cpi, ThreadData *td, - uint8_t *cur_frame_buf, - uint8_t *ref_frame_buf, int stride, - BLOCK_SIZE bsize, MV *mv) { - MACROBLOCK *const x = &td->mb; - MACROBLOCKD *const xd = &x->e_mbd; - MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv; - uint32_t bestsme = UINT_MAX; - uint32_t distortion; - uint32_t sse; - int cost_list[5]; - - MV best_ref_mv1 = { 0, 0 }; - - // Setup frame pointers - x->plane[0].src.buf = cur_frame_buf; - x->plane[0].src.stride = stride; - xd->plane[0].pre[0].buf = ref_frame_buf; - xd->plane[0].pre[0].stride = stride; - - // TODO(yunqing): may use higher tap interp filter than 2 taps. - // Ignore mv costing by sending NULL pointer instead of cost array - bestsme = cpi->find_fractional_mv_step( - x, mv, &best_ref_mv1, cpi->common.allow_high_precision_mv, x->errorperbit, - &cpi->fn_ptr[bsize], 0, mv_sf->subpel_search_level, - cond_cost_list(cpi, cost_list), NULL, NULL, &distortion, &sse, NULL, 0, 0, - USE_2_TAPS); - - return bestsme; -} - -#else // CONFIG_NON_GREEDY_MV -static uint32_t motion_compensated_prediction(VP9_COMP *cpi, ThreadData *td, - uint8_t *cur_frame_buf, - uint8_t *ref_frame_buf, - int stride, BLOCK_SIZE bsize, - MV *mv) { - MACROBLOCK *const x = &td->mb; - MACROBLOCKD *const xd = &x->e_mbd; - MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv; - const SEARCH_METHODS search_method = NSTEP; - int step_param; - int sadpb = x->sadperbit16; - uint32_t bestsme = UINT_MAX; - uint32_t distortion; - uint32_t sse; - int cost_list[5]; - const MvLimits tmp_mv_limits = x->mv_limits; - - MV best_ref_mv1 = { 0, 0 }; - MV best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */ - - best_ref_mv1_full.col = best_ref_mv1.col >> 3; - best_ref_mv1_full.row = best_ref_mv1.row >> 3; - - // Setup frame pointers - x->plane[0].src.buf = cur_frame_buf; - x->plane[0].src.stride = stride; - xd->plane[0].pre[0].buf = ref_frame_buf; - xd->plane[0].pre[0].stride = stride; - - step_param = mv_sf->reduce_first_step_size; - step_param = VPXMIN(step_param, MAX_MVSEARCH_STEPS - 2); - - vp9_set_mv_search_range(&x->mv_limits, &best_ref_mv1); - - vp9_full_pixel_search(cpi, x, bsize, &best_ref_mv1_full, step_param, - search_method, sadpb, cond_cost_list(cpi, cost_list), - &best_ref_mv1, mv, 0, 0); - - /* restore UMV window */ - x->mv_limits = tmp_mv_limits; - - // TODO(yunqing): may use higher tap interp filter than 2 taps. - // Ignore mv costing by sending NULL pointer instead of cost array - bestsme = cpi->find_fractional_mv_step( - x, mv, &best_ref_mv1, cpi->common.allow_high_precision_mv, x->errorperbit, - &cpi->fn_ptr[bsize], 0, mv_sf->subpel_search_level, - cond_cost_list(cpi, cost_list), NULL, NULL, &distortion, &sse, NULL, 0, 0, - USE_2_TAPS); - - return bestsme; -} -#endif - -static int get_overlap_area(int grid_pos_row, int grid_pos_col, int ref_pos_row, - int ref_pos_col, int block, BLOCK_SIZE bsize) { - int width = 0, height = 0; - int bw = 4 << b_width_log2_lookup[bsize]; - int bh = 4 << b_height_log2_lookup[bsize]; - - switch (block) { - case 0: - width = grid_pos_col + bw - ref_pos_col; - height = grid_pos_row + bh - ref_pos_row; - break; - case 1: - width = ref_pos_col + bw - grid_pos_col; - height = grid_pos_row + bh - ref_pos_row; - break; - case 2: - width = grid_pos_col + bw - ref_pos_col; - height = ref_pos_row + bh - grid_pos_row; - break; - case 3: - width = ref_pos_col + bw - grid_pos_col; - height = ref_pos_row + bh - grid_pos_row; - break; - default: assert(0); - } - - return width * height; -} - -static int round_floor(int ref_pos, int bsize_pix) { - int round; - if (ref_pos < 0) - round = -(1 + (-ref_pos - 1) / bsize_pix); - else - round = ref_pos / bsize_pix; - - return round; -} - -static void tpl_model_store(TplDepStats *tpl_stats, int mi_row, int mi_col, - BLOCK_SIZE bsize, int stride) { - const int mi_height = num_8x8_blocks_high_lookup[bsize]; - const int mi_width = num_8x8_blocks_wide_lookup[bsize]; - const TplDepStats *src_stats = &tpl_stats[mi_row * stride + mi_col]; - int idx, idy; - - for (idy = 0; idy < mi_height; ++idy) { - for (idx = 0; idx < mi_width; ++idx) { - TplDepStats *tpl_ptr = &tpl_stats[(mi_row + idy) * stride + mi_col + idx]; - const int64_t mc_flow = tpl_ptr->mc_flow; - const int64_t mc_ref_cost = tpl_ptr->mc_ref_cost; - *tpl_ptr = *src_stats; - tpl_ptr->mc_flow = mc_flow; - tpl_ptr->mc_ref_cost = mc_ref_cost; - tpl_ptr->mc_dep_cost = tpl_ptr->intra_cost + tpl_ptr->mc_flow; - } - } -} - -static void tpl_model_update_b(TplDepFrame *tpl_frame, TplDepStats *tpl_stats, - int mi_row, int mi_col, const BLOCK_SIZE bsize) { - TplDepFrame *ref_tpl_frame = &tpl_frame[tpl_stats->ref_frame_index]; - TplDepStats *ref_stats = ref_tpl_frame->tpl_stats_ptr; - MV mv = tpl_stats->mv.as_mv; - int mv_row = mv.row >> 3; - int mv_col = mv.col >> 3; - - int ref_pos_row = mi_row * MI_SIZE + mv_row; - int ref_pos_col = mi_col * MI_SIZE + mv_col; - - const int bw = 4 << b_width_log2_lookup[bsize]; - const int bh = 4 << b_height_log2_lookup[bsize]; - const int mi_height = num_8x8_blocks_high_lookup[bsize]; - const int mi_width = num_8x8_blocks_wide_lookup[bsize]; - const int pix_num = bw * bh; - - // top-left on grid block location in pixel - int grid_pos_row_base = round_floor(ref_pos_row, bh) * bh; - int grid_pos_col_base = round_floor(ref_pos_col, bw) * bw; - int block; - - for (block = 0; block < 4; ++block) { - int grid_pos_row = grid_pos_row_base + bh * (block >> 1); - int grid_pos_col = grid_pos_col_base + bw * (block & 0x01); - - if (grid_pos_row >= 0 && grid_pos_row < ref_tpl_frame->mi_rows * MI_SIZE && - grid_pos_col >= 0 && grid_pos_col < ref_tpl_frame->mi_cols * MI_SIZE) { - int overlap_area = get_overlap_area( - grid_pos_row, grid_pos_col, ref_pos_row, ref_pos_col, block, bsize); - int ref_mi_row = round_floor(grid_pos_row, bh) * mi_height; - int ref_mi_col = round_floor(grid_pos_col, bw) * mi_width; - - int64_t mc_flow = tpl_stats->mc_dep_cost - - (tpl_stats->mc_dep_cost * tpl_stats->inter_cost) / - tpl_stats->intra_cost; - - int idx, idy; - - for (idy = 0; idy < mi_height; ++idy) { - for (idx = 0; idx < mi_width; ++idx) { - TplDepStats *des_stats = - &ref_stats[(ref_mi_row + idy) * ref_tpl_frame->stride + - (ref_mi_col + idx)]; - - des_stats->mc_flow += (mc_flow * overlap_area) / pix_num; - des_stats->mc_ref_cost += - ((tpl_stats->intra_cost - tpl_stats->inter_cost) * overlap_area) / - pix_num; - assert(overlap_area >= 0); - } - } - } - } -} - -static void tpl_model_update(TplDepFrame *tpl_frame, TplDepStats *tpl_stats, - int mi_row, int mi_col, const BLOCK_SIZE bsize) { - int idx, idy; - const int mi_height = num_8x8_blocks_high_lookup[bsize]; - const int mi_width = num_8x8_blocks_wide_lookup[bsize]; - - for (idy = 0; idy < mi_height; ++idy) { - for (idx = 0; idx < mi_width; ++idx) { - TplDepStats *tpl_ptr = - &tpl_stats[(mi_row + idy) * tpl_frame->stride + (mi_col + idx)]; - tpl_model_update_b(tpl_frame, tpl_ptr, mi_row + idy, mi_col + idx, - BLOCK_8X8); - } - } -} - -static void get_quantize_error(MACROBLOCK *x, int plane, tran_low_t *coeff, - tran_low_t *qcoeff, tran_low_t *dqcoeff, - TX_SIZE tx_size, int64_t *recon_error, - int64_t *sse) { - MACROBLOCKD *const xd = &x->e_mbd; - const struct macroblock_plane *const p = &x->plane[plane]; - const struct macroblockd_plane *const pd = &xd->plane[plane]; - const scan_order *const scan_order = &vp9_default_scan_orders[tx_size]; - uint16_t eob; - int pix_num = 1 << num_pels_log2_lookup[txsize_to_bsize[tx_size]]; - const int shift = tx_size == TX_32X32 ? 0 : 2; - - // skip block condition should be handled before this is called. - assert(!x->skip_block); - -#if CONFIG_VP9_HIGHBITDEPTH - if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { - vp9_highbd_quantize_fp_32x32(coeff, pix_num, p->round_fp, p->quant_fp, - qcoeff, dqcoeff, pd->dequant, &eob, - scan_order->scan, scan_order->iscan); - } else { - vp9_quantize_fp_32x32(coeff, pix_num, p->round_fp, p->quant_fp, qcoeff, - dqcoeff, pd->dequant, &eob, scan_order->scan, - scan_order->iscan); - } -#else - vp9_quantize_fp_32x32(coeff, pix_num, p->round_fp, p->quant_fp, qcoeff, - dqcoeff, pd->dequant, &eob, scan_order->scan, - scan_order->iscan); -#endif // CONFIG_VP9_HIGHBITDEPTH - - *recon_error = vp9_block_error(coeff, dqcoeff, pix_num, sse) >> shift; - *recon_error = VPXMAX(*recon_error, 1); - - *sse = (*sse) >> shift; - *sse = VPXMAX(*sse, 1); -} - -#if CONFIG_VP9_HIGHBITDEPTH -void highbd_wht_fwd_txfm(int16_t *src_diff, int bw, tran_low_t *coeff, - TX_SIZE tx_size) { - // TODO(sdeng): Implement SIMD based high bit-depth Hadamard transforms. - switch (tx_size) { - case TX_8X8: vpx_highbd_hadamard_8x8(src_diff, bw, coeff); break; - case TX_16X16: vpx_highbd_hadamard_16x16(src_diff, bw, coeff); break; - case TX_32X32: vpx_highbd_hadamard_32x32(src_diff, bw, coeff); break; - default: assert(0); - } -} -#endif // CONFIG_VP9_HIGHBITDEPTH - -void wht_fwd_txfm(int16_t *src_diff, int bw, tran_low_t *coeff, - TX_SIZE tx_size) { - switch (tx_size) { - case TX_8X8: vpx_hadamard_8x8(src_diff, bw, coeff); break; - case TX_16X16: vpx_hadamard_16x16(src_diff, bw, coeff); break; - case TX_32X32: vpx_hadamard_32x32(src_diff, bw, coeff); break; - default: assert(0); - } -} - -static void set_mv_limits(const VP9_COMMON *cm, MACROBLOCK *x, int mi_row, - int mi_col) { - x->mv_limits.row_min = -((mi_row * MI_SIZE) + (17 - 2 * VP9_INTERP_EXTEND)); - x->mv_limits.row_max = - (cm->mi_rows - 1 - mi_row) * MI_SIZE + (17 - 2 * VP9_INTERP_EXTEND); - x->mv_limits.col_min = -((mi_col * MI_SIZE) + (17 - 2 * VP9_INTERP_EXTEND)); - x->mv_limits.col_max = - ((cm->mi_cols - 1 - mi_col) * MI_SIZE) + (17 - 2 * VP9_INTERP_EXTEND); -} - -static void mode_estimation(VP9_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd, - struct scale_factors *sf, GF_PICTURE *gf_picture, - int frame_idx, TplDepFrame *tpl_frame, - int16_t *src_diff, tran_low_t *coeff, - tran_low_t *qcoeff, tran_low_t *dqcoeff, int mi_row, - int mi_col, BLOCK_SIZE bsize, TX_SIZE tx_size, - YV12_BUFFER_CONFIG *ref_frame[], uint8_t *predictor, - int64_t *recon_error, int64_t *sse) { - VP9_COMMON *cm = &cpi->common; - ThreadData *td = &cpi->td; - - const int bw = 4 << b_width_log2_lookup[bsize]; - const int bh = 4 << b_height_log2_lookup[bsize]; - const int pix_num = bw * bh; - int best_rf_idx = -1; - int_mv best_mv; - int64_t best_inter_cost = INT64_MAX; - int64_t inter_cost; - int rf_idx; - const InterpKernel *const kernel = vp9_filter_kernels[EIGHTTAP]; - - int64_t best_intra_cost = INT64_MAX; - int64_t intra_cost; - PREDICTION_MODE mode; - int mb_y_offset = mi_row * MI_SIZE * xd->cur_buf->y_stride + mi_col * MI_SIZE; - MODE_INFO mi_above, mi_left; - const int mi_height = num_8x8_blocks_high_lookup[bsize]; - const int mi_width = num_8x8_blocks_wide_lookup[bsize]; - TplDepStats *tpl_stats = - &tpl_frame->tpl_stats_ptr[mi_row * tpl_frame->stride + mi_col]; - - xd->mb_to_top_edge = -((mi_row * MI_SIZE) * 8); - xd->mb_to_bottom_edge = ((cm->mi_rows - 1 - mi_row) * MI_SIZE) * 8; - xd->mb_to_left_edge = -((mi_col * MI_SIZE) * 8); - xd->mb_to_right_edge = ((cm->mi_cols - 1 - mi_col) * MI_SIZE) * 8; - xd->above_mi = (mi_row > 0) ? &mi_above : NULL; - xd->left_mi = (mi_col > 0) ? &mi_left : NULL; - - // Intra prediction search - for (mode = DC_PRED; mode <= TM_PRED; ++mode) { - uint8_t *src, *dst; - int src_stride, dst_stride; - - src = xd->cur_buf->y_buffer + mb_y_offset; - src_stride = xd->cur_buf->y_stride; - - dst = &predictor[0]; - dst_stride = bw; - - xd->mi[0]->sb_type = bsize; - xd->mi[0]->ref_frame[0] = INTRA_FRAME; - - vp9_predict_intra_block(xd, b_width_log2_lookup[bsize], tx_size, mode, src, - src_stride, dst, dst_stride, 0, 0, 0); - -#if CONFIG_VP9_HIGHBITDEPTH - if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { - vpx_highbd_subtract_block(bh, bw, src_diff, bw, src, src_stride, dst, - dst_stride, xd->bd); - highbd_wht_fwd_txfm(src_diff, bw, coeff, tx_size); - intra_cost = vpx_highbd_satd(coeff, pix_num); - } else { - vpx_subtract_block(bh, bw, src_diff, bw, src, src_stride, dst, - dst_stride); - wht_fwd_txfm(src_diff, bw, coeff, tx_size); - intra_cost = vpx_satd(coeff, pix_num); - } -#else - vpx_subtract_block(bh, bw, src_diff, bw, src, src_stride, dst, dst_stride); - wht_fwd_txfm(src_diff, bw, coeff, tx_size); - intra_cost = vpx_satd(coeff, pix_num); -#endif // CONFIG_VP9_HIGHBITDEPTH - - if (intra_cost < best_intra_cost) best_intra_cost = intra_cost; - } - - // Motion compensated prediction - best_mv.as_int = 0; - - set_mv_limits(cm, x, mi_row, mi_col); - - for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { - int_mv mv; -#if CONFIG_NON_GREEDY_MV - MotionField *motion_field; -#endif - if (ref_frame[rf_idx] == NULL) continue; - -#if CONFIG_NON_GREEDY_MV - (void)td; - motion_field = vp9_motion_field_info_get_motion_field( - &cpi->motion_field_info, frame_idx, rf_idx, bsize); - mv = vp9_motion_field_mi_get_mv(motion_field, mi_row, mi_col); -#else - motion_compensated_prediction(cpi, td, xd->cur_buf->y_buffer + mb_y_offset, - ref_frame[rf_idx]->y_buffer + mb_y_offset, - xd->cur_buf->y_stride, bsize, &mv.as_mv); -#endif - -#if CONFIG_VP9_HIGHBITDEPTH - if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { - vp9_highbd_build_inter_predictor( - CONVERT_TO_SHORTPTR(ref_frame[rf_idx]->y_buffer + mb_y_offset), - ref_frame[rf_idx]->y_stride, CONVERT_TO_SHORTPTR(&predictor[0]), bw, - &mv.as_mv, sf, bw, bh, 0, kernel, MV_PRECISION_Q3, mi_col * MI_SIZE, - mi_row * MI_SIZE, xd->bd); - vpx_highbd_subtract_block( - bh, bw, src_diff, bw, xd->cur_buf->y_buffer + mb_y_offset, - xd->cur_buf->y_stride, &predictor[0], bw, xd->bd); - highbd_wht_fwd_txfm(src_diff, bw, coeff, tx_size); - inter_cost = vpx_highbd_satd(coeff, pix_num); - } else { - vp9_build_inter_predictor( - ref_frame[rf_idx]->y_buffer + mb_y_offset, - ref_frame[rf_idx]->y_stride, &predictor[0], bw, &mv.as_mv, sf, bw, bh, - 0, kernel, MV_PRECISION_Q3, mi_col * MI_SIZE, mi_row * MI_SIZE); - vpx_subtract_block(bh, bw, src_diff, bw, - xd->cur_buf->y_buffer + mb_y_offset, - xd->cur_buf->y_stride, &predictor[0], bw); - wht_fwd_txfm(src_diff, bw, coeff, tx_size); - inter_cost = vpx_satd(coeff, pix_num); - } -#else - vp9_build_inter_predictor(ref_frame[rf_idx]->y_buffer + mb_y_offset, - ref_frame[rf_idx]->y_stride, &predictor[0], bw, - &mv.as_mv, sf, bw, bh, 0, kernel, MV_PRECISION_Q3, - mi_col * MI_SIZE, mi_row * MI_SIZE); - vpx_subtract_block(bh, bw, src_diff, bw, - xd->cur_buf->y_buffer + mb_y_offset, - xd->cur_buf->y_stride, &predictor[0], bw); - wht_fwd_txfm(src_diff, bw, coeff, tx_size); - inter_cost = vpx_satd(coeff, pix_num); -#endif - - if (inter_cost < best_inter_cost) { - best_rf_idx = rf_idx; - best_inter_cost = inter_cost; - best_mv.as_int = mv.as_int; - get_quantize_error(x, 0, coeff, qcoeff, dqcoeff, tx_size, recon_error, - sse); - } - } - best_intra_cost = VPXMAX(best_intra_cost, 1); - best_inter_cost = VPXMIN(best_intra_cost, best_inter_cost); - tpl_stats->inter_cost = VPXMAX( - 1, (best_inter_cost << TPL_DEP_COST_SCALE_LOG2) / (mi_height * mi_width)); - tpl_stats->intra_cost = VPXMAX( - 1, (best_intra_cost << TPL_DEP_COST_SCALE_LOG2) / (mi_height * mi_width)); - tpl_stats->ref_frame_index = gf_picture[frame_idx].ref_frame[best_rf_idx]; - tpl_stats->mv.as_int = best_mv.as_int; -} - -#if CONFIG_NON_GREEDY_MV -static int get_block_src_pred_buf(MACROBLOCKD *xd, GF_PICTURE *gf_picture, - int frame_idx, int rf_idx, int mi_row, - int mi_col, struct buf_2d *src, - struct buf_2d *pre) { - const int mb_y_offset = - mi_row * MI_SIZE * xd->cur_buf->y_stride + mi_col * MI_SIZE; - YV12_BUFFER_CONFIG *ref_frame = NULL; - int ref_frame_idx = gf_picture[frame_idx].ref_frame[rf_idx]; - if (ref_frame_idx != -1) { - ref_frame = gf_picture[ref_frame_idx].frame; - src->buf = xd->cur_buf->y_buffer + mb_y_offset; - src->stride = xd->cur_buf->y_stride; - pre->buf = ref_frame->y_buffer + mb_y_offset; - pre->stride = ref_frame->y_stride; - assert(src->stride == pre->stride); - return 1; - } else { - printf("invalid ref_frame_idx"); - assert(ref_frame_idx != -1); - return 0; - } -} - -#define kMvPreCheckLines 5 -#define kMvPreCheckSize 15 - -#define MV_REF_POS_NUM 3 -POSITION mv_ref_pos[MV_REF_POS_NUM] = { - { -1, 0 }, - { 0, -1 }, - { -1, -1 }, -}; - -static int_mv *get_select_mv(VP9_COMP *cpi, TplDepFrame *tpl_frame, int mi_row, - int mi_col) { - return &cpi->select_mv_arr[mi_row * tpl_frame->stride + mi_col]; -} - -static int_mv find_ref_mv(int mv_mode, VP9_COMP *cpi, TplDepFrame *tpl_frame, - BLOCK_SIZE bsize, int mi_row, int mi_col) { - int i; - const int mi_height = num_8x8_blocks_high_lookup[bsize]; - const int mi_width = num_8x8_blocks_wide_lookup[bsize]; - int_mv nearest_mv, near_mv, invalid_mv; - nearest_mv.as_int = INVALID_MV; - near_mv.as_int = INVALID_MV; - invalid_mv.as_int = INVALID_MV; - for (i = 0; i < MV_REF_POS_NUM; ++i) { - int nb_row = mi_row + mv_ref_pos[i].row * mi_height; - int nb_col = mi_col + mv_ref_pos[i].col * mi_width; - assert(mv_ref_pos[i].row <= 0); - assert(mv_ref_pos[i].col <= 0); - if (nb_row >= 0 && nb_col >= 0) { - if (nearest_mv.as_int == INVALID_MV) { - nearest_mv = *get_select_mv(cpi, tpl_frame, nb_row, nb_col); - } else { - int_mv mv = *get_select_mv(cpi, tpl_frame, nb_row, nb_col); - if (mv.as_int == nearest_mv.as_int) { - continue; - } else { - near_mv = mv; - break; - } - } - } - } - if (nearest_mv.as_int == INVALID_MV) { - nearest_mv.as_mv.row = 0; - nearest_mv.as_mv.col = 0; - } - if (near_mv.as_int == INVALID_MV) { - near_mv.as_mv.row = 0; - near_mv.as_mv.col = 0; - } - if (mv_mode == NEAREST_MV_MODE) { - return nearest_mv; - } - if (mv_mode == NEAR_MV_MODE) { - return near_mv; - } - assert(0); - return invalid_mv; -} - -static int_mv get_mv_from_mv_mode(int mv_mode, VP9_COMP *cpi, - MotionField *motion_field, - TplDepFrame *tpl_frame, BLOCK_SIZE bsize, - int mi_row, int mi_col) { - int_mv mv; - switch (mv_mode) { - case ZERO_MV_MODE: - mv.as_mv.row = 0; - mv.as_mv.col = 0; - break; - case NEW_MV_MODE: - mv = vp9_motion_field_mi_get_mv(motion_field, mi_row, mi_col); - break; - case NEAREST_MV_MODE: - mv = find_ref_mv(mv_mode, cpi, tpl_frame, bsize, mi_row, mi_col); - break; - case NEAR_MV_MODE: - mv = find_ref_mv(mv_mode, cpi, tpl_frame, bsize, mi_row, mi_col); - break; - default: - mv.as_int = INVALID_MV; - assert(0); - break; - } - return mv; -} - -static double get_mv_dist(int mv_mode, VP9_COMP *cpi, MACROBLOCKD *xd, - GF_PICTURE *gf_picture, MotionField *motion_field, - int frame_idx, TplDepFrame *tpl_frame, int rf_idx, - BLOCK_SIZE bsize, int mi_row, int mi_col, - int_mv *mv) { - uint32_t sse; - struct buf_2d src; - struct buf_2d pre; - MV full_mv; - *mv = get_mv_from_mv_mode(mv_mode, cpi, motion_field, tpl_frame, bsize, - mi_row, mi_col); - full_mv = get_full_mv(&mv->as_mv); - if (get_block_src_pred_buf(xd, gf_picture, frame_idx, rf_idx, mi_row, mi_col, - &src, &pre)) { - // TODO(angiebird): Consider subpixel when computing the sse. - cpi->fn_ptr[bsize].vf(src.buf, src.stride, get_buf_from_mv(&pre, &full_mv), - pre.stride, &sse); - return (double)(sse << VP9_DIST_SCALE_LOG2); - } else { - assert(0); - return 0; - } -} - -static int get_mv_mode_cost(int mv_mode) { - // TODO(angiebird): The probabilities are roughly inferred from - // default_inter_mode_probs. Check if there is a better way to set the - // probabilities. - const int zero_mv_prob = 16; - const int new_mv_prob = 24 * 1; - const int ref_mv_prob = 256 - zero_mv_prob - new_mv_prob; - assert(zero_mv_prob + new_mv_prob + ref_mv_prob == 256); - switch (mv_mode) { - case ZERO_MV_MODE: return vp9_prob_cost[zero_mv_prob]; break; - case NEW_MV_MODE: return vp9_prob_cost[new_mv_prob]; break; - case NEAREST_MV_MODE: return vp9_prob_cost[ref_mv_prob]; break; - case NEAR_MV_MODE: return vp9_prob_cost[ref_mv_prob]; break; - default: assert(0); return -1; - } -} - -static INLINE double get_mv_diff_cost(MV *new_mv, MV *ref_mv) { - double mv_diff_cost = log2(1 + abs(new_mv->row - ref_mv->row)) + - log2(1 + abs(new_mv->col - ref_mv->col)); - mv_diff_cost *= (1 << VP9_PROB_COST_SHIFT); - return mv_diff_cost; -} -static double get_mv_cost(int mv_mode, VP9_COMP *cpi, MotionField *motion_field, - TplDepFrame *tpl_frame, BLOCK_SIZE bsize, int mi_row, - int mi_col) { - double mv_cost = get_mv_mode_cost(mv_mode); - if (mv_mode == NEW_MV_MODE) { - MV new_mv = get_mv_from_mv_mode(mv_mode, cpi, motion_field, tpl_frame, - bsize, mi_row, mi_col) - .as_mv; - MV nearest_mv = get_mv_from_mv_mode(NEAREST_MV_MODE, cpi, motion_field, - tpl_frame, bsize, mi_row, mi_col) - .as_mv; - MV near_mv = get_mv_from_mv_mode(NEAR_MV_MODE, cpi, motion_field, tpl_frame, - bsize, mi_row, mi_col) - .as_mv; - double nearest_cost = get_mv_diff_cost(&new_mv, &nearest_mv); - double near_cost = get_mv_diff_cost(&new_mv, &near_mv); - mv_cost += nearest_cost < near_cost ? nearest_cost : near_cost; - } - return mv_cost; -} - -static double eval_mv_mode(int mv_mode, VP9_COMP *cpi, MACROBLOCK *x, - GF_PICTURE *gf_picture, MotionField *motion_field, - int frame_idx, TplDepFrame *tpl_frame, int rf_idx, - BLOCK_SIZE bsize, int mi_row, int mi_col, - int_mv *mv) { - MACROBLOCKD *xd = &x->e_mbd; - double mv_dist = - get_mv_dist(mv_mode, cpi, xd, gf_picture, motion_field, frame_idx, - tpl_frame, rf_idx, bsize, mi_row, mi_col, mv); - double mv_cost = - get_mv_cost(mv_mode, cpi, motion_field, tpl_frame, bsize, mi_row, mi_col); - double mult = 180; - - return mv_cost + mult * log2f(1 + mv_dist); -} - -static int find_best_ref_mv_mode(VP9_COMP *cpi, MACROBLOCK *x, - GF_PICTURE *gf_picture, - MotionField *motion_field, int frame_idx, - TplDepFrame *tpl_frame, int rf_idx, - BLOCK_SIZE bsize, int mi_row, int mi_col, - double *rd, int_mv *mv) { - int best_mv_mode = ZERO_MV_MODE; - int update = 0; - int mv_mode; - *rd = 0; - for (mv_mode = 0; mv_mode < MAX_MV_MODE; ++mv_mode) { - double this_rd; - int_mv this_mv; - if (mv_mode == NEW_MV_MODE) { - continue; - } - this_rd = eval_mv_mode(mv_mode, cpi, x, gf_picture, motion_field, frame_idx, - tpl_frame, rf_idx, bsize, mi_row, mi_col, &this_mv); - if (update == 0) { - *rd = this_rd; - *mv = this_mv; - best_mv_mode = mv_mode; - update = 1; - } else { - if (this_rd < *rd) { - *rd = this_rd; - *mv = this_mv; - best_mv_mode = mv_mode; - } - } - } - return best_mv_mode; -} - -static void predict_mv_mode(VP9_COMP *cpi, MACROBLOCK *x, - GF_PICTURE *gf_picture, MotionField *motion_field, - int frame_idx, TplDepFrame *tpl_frame, int rf_idx, - BLOCK_SIZE bsize, int mi_row, int mi_col) { - const int mi_height = num_8x8_blocks_high_lookup[bsize]; - const int mi_width = num_8x8_blocks_wide_lookup[bsize]; - int tmp_mv_mode_arr[kMvPreCheckSize]; - int *mv_mode_arr = tpl_frame->mv_mode_arr[rf_idx]; - double *rd_diff_arr = tpl_frame->rd_diff_arr[rf_idx]; - int_mv *select_mv_arr = cpi->select_mv_arr; - int_mv tmp_select_mv_arr[kMvPreCheckSize]; - int stride = tpl_frame->stride; - double new_mv_rd = 0; - double no_new_mv_rd = 0; - double this_new_mv_rd = 0; - double this_no_new_mv_rd = 0; - int idx; - int tmp_idx; - assert(kMvPreCheckSize == (kMvPreCheckLines * (kMvPreCheckLines + 1)) >> 1); - - // no new mv - // diagonal scan order - tmp_idx = 0; - for (idx = 0; idx < kMvPreCheckLines; ++idx) { - int r; - for (r = 0; r <= idx; ++r) { - int c = idx - r; - int nb_row = mi_row + r * mi_height; - int nb_col = mi_col + c * mi_width; - if (nb_row < tpl_frame->mi_rows && nb_col < tpl_frame->mi_cols) { - double this_rd; - int_mv *mv = &select_mv_arr[nb_row * stride + nb_col]; - mv_mode_arr[nb_row * stride + nb_col] = find_best_ref_mv_mode( - cpi, x, gf_picture, motion_field, frame_idx, tpl_frame, rf_idx, - bsize, nb_row, nb_col, &this_rd, mv); - if (r == 0 && c == 0) { - this_no_new_mv_rd = this_rd; - } - no_new_mv_rd += this_rd; - tmp_mv_mode_arr[tmp_idx] = mv_mode_arr[nb_row * stride + nb_col]; - tmp_select_mv_arr[tmp_idx] = select_mv_arr[nb_row * stride + nb_col]; - ++tmp_idx; - } - } - } - - // new mv - mv_mode_arr[mi_row * stride + mi_col] = NEW_MV_MODE; - this_new_mv_rd = eval_mv_mode( - NEW_MV_MODE, cpi, x, gf_picture, motion_field, frame_idx, tpl_frame, - rf_idx, bsize, mi_row, mi_col, &select_mv_arr[mi_row * stride + mi_col]); - new_mv_rd = this_new_mv_rd; - // We start from idx = 1 because idx = 0 is evaluated as NEW_MV_MODE - // beforehand. - for (idx = 1; idx < kMvPreCheckLines; ++idx) { - int r; - for (r = 0; r <= idx; ++r) { - int c = idx - r; - int nb_row = mi_row + r * mi_height; - int nb_col = mi_col + c * mi_width; - if (nb_row < tpl_frame->mi_rows && nb_col < tpl_frame->mi_cols) { - double this_rd; - int_mv *mv = &select_mv_arr[nb_row * stride + nb_col]; - mv_mode_arr[nb_row * stride + nb_col] = find_best_ref_mv_mode( - cpi, x, gf_picture, motion_field, frame_idx, tpl_frame, rf_idx, - bsize, nb_row, nb_col, &this_rd, mv); - new_mv_rd += this_rd; - } - } - } - - // update best_mv_mode - tmp_idx = 0; - if (no_new_mv_rd < new_mv_rd) { - for (idx = 0; idx < kMvPreCheckLines; ++idx) { - int r; - for (r = 0; r <= idx; ++r) { - int c = idx - r; - int nb_row = mi_row + r * mi_height; - int nb_col = mi_col + c * mi_width; - if (nb_row < tpl_frame->mi_rows && nb_col < tpl_frame->mi_cols) { - mv_mode_arr[nb_row * stride + nb_col] = tmp_mv_mode_arr[tmp_idx]; - select_mv_arr[nb_row * stride + nb_col] = tmp_select_mv_arr[tmp_idx]; - ++tmp_idx; - } - } - } - rd_diff_arr[mi_row * stride + mi_col] = 0; - } else { - rd_diff_arr[mi_row * stride + mi_col] = - (no_new_mv_rd - this_no_new_mv_rd) - (new_mv_rd - this_new_mv_rd); - } -} - -static void predict_mv_mode_arr(VP9_COMP *cpi, MACROBLOCK *x, - GF_PICTURE *gf_picture, - MotionField *motion_field, int frame_idx, - TplDepFrame *tpl_frame, int rf_idx, - BLOCK_SIZE bsize) { - const int mi_height = num_8x8_blocks_high_lookup[bsize]; - const int mi_width = num_8x8_blocks_wide_lookup[bsize]; - const int unit_rows = tpl_frame->mi_rows / mi_height; - const int unit_cols = tpl_frame->mi_cols / mi_width; - const int max_diagonal_lines = unit_rows + unit_cols - 1; - int idx; - for (idx = 0; idx < max_diagonal_lines; ++idx) { - int r; - for (r = VPXMAX(idx - unit_cols + 1, 0); r <= VPXMIN(idx, unit_rows - 1); - ++r) { - int c = idx - r; - int mi_row = r * mi_height; - int mi_col = c * mi_width; - assert(c >= 0 && c < unit_cols); - assert(mi_row >= 0 && mi_row < tpl_frame->mi_rows); - assert(mi_col >= 0 && mi_col < tpl_frame->mi_cols); - predict_mv_mode(cpi, x, gf_picture, motion_field, frame_idx, tpl_frame, - rf_idx, bsize, mi_row, mi_col); - } - } -} - -static void do_motion_search(VP9_COMP *cpi, ThreadData *td, - MotionField *motion_field, int frame_idx, - YV12_BUFFER_CONFIG *ref_frame, BLOCK_SIZE bsize, - int mi_row, int mi_col) { - VP9_COMMON *cm = &cpi->common; - MACROBLOCK *x = &td->mb; - MACROBLOCKD *xd = &x->e_mbd; - const int mb_y_offset = - mi_row * MI_SIZE * xd->cur_buf->y_stride + mi_col * MI_SIZE; - assert(ref_frame != NULL); - set_mv_limits(cm, x, mi_row, mi_col); - { - int_mv mv = vp9_motion_field_mi_get_mv(motion_field, mi_row, mi_col); - uint8_t *cur_frame_buf = xd->cur_buf->y_buffer + mb_y_offset; - uint8_t *ref_frame_buf = ref_frame->y_buffer + mb_y_offset; - const int stride = xd->cur_buf->y_stride; - full_pixel_motion_search(cpi, td, motion_field, frame_idx, cur_frame_buf, - ref_frame_buf, stride, bsize, mi_row, mi_col, - &mv.as_mv); - sub_pixel_motion_search(cpi, td, cur_frame_buf, ref_frame_buf, stride, - bsize, &mv.as_mv); - vp9_motion_field_mi_set_mv(motion_field, mi_row, mi_col, mv); - } -} - -static void build_motion_field( - VP9_COMP *cpi, int frame_idx, - YV12_BUFFER_CONFIG *ref_frame[MAX_INTER_REF_FRAMES], BLOCK_SIZE bsize) { - VP9_COMMON *cm = &cpi->common; - ThreadData *td = &cpi->td; - TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx]; - const int mi_height = num_8x8_blocks_high_lookup[bsize]; - const int mi_width = num_8x8_blocks_wide_lookup[bsize]; - const int pw = num_4x4_blocks_wide_lookup[bsize] << 2; - const int ph = num_4x4_blocks_high_lookup[bsize] << 2; - int mi_row, mi_col; - int rf_idx; - - tpl_frame->lambda = (pw * ph) >> 2; - assert(pw * ph == tpl_frame->lambda << 2); - - for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { - MotionField *motion_field = vp9_motion_field_info_get_motion_field( - &cpi->motion_field_info, frame_idx, rf_idx, bsize); - if (ref_frame[rf_idx] == NULL) { - continue; - } - vp9_motion_field_reset_mvs(motion_field); - for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) { - for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) { - do_motion_search(cpi, td, motion_field, frame_idx, ref_frame[rf_idx], - bsize, mi_row, mi_col); - } - } - } -} -#endif // CONFIG_NON_GREEDY_MV - -static void mc_flow_dispenser(VP9_COMP *cpi, GF_PICTURE *gf_picture, - int frame_idx, BLOCK_SIZE bsize) { - TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx]; - YV12_BUFFER_CONFIG *this_frame = gf_picture[frame_idx].frame; - YV12_BUFFER_CONFIG *ref_frame[MAX_INTER_REF_FRAMES] = { NULL, NULL, NULL }; - - VP9_COMMON *cm = &cpi->common; - struct scale_factors sf; - int rdmult, idx; - ThreadData *td = &cpi->td; - MACROBLOCK *x = &td->mb; - MACROBLOCKD *xd = &x->e_mbd; - int mi_row, mi_col; - -#if CONFIG_VP9_HIGHBITDEPTH - DECLARE_ALIGNED(16, uint16_t, predictor16[32 * 32 * 3]); - DECLARE_ALIGNED(16, uint8_t, predictor8[32 * 32 * 3]); - uint8_t *predictor; -#else - DECLARE_ALIGNED(16, uint8_t, predictor[32 * 32 * 3]); -#endif - DECLARE_ALIGNED(16, int16_t, src_diff[32 * 32]); - DECLARE_ALIGNED(16, tran_low_t, coeff[32 * 32]); - DECLARE_ALIGNED(16, tran_low_t, qcoeff[32 * 32]); - DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]); - - const TX_SIZE tx_size = max_txsize_lookup[bsize]; - const int mi_height = num_8x8_blocks_high_lookup[bsize]; - const int mi_width = num_8x8_blocks_wide_lookup[bsize]; - int64_t recon_error, sse; -#if CONFIG_NON_GREEDY_MV - int square_block_idx; - int rf_idx; -#endif - - // Setup scaling factor -#if CONFIG_VP9_HIGHBITDEPTH - vp9_setup_scale_factors_for_frame( - &sf, this_frame->y_crop_width, this_frame->y_crop_height, - this_frame->y_crop_width, this_frame->y_crop_height, - cpi->common.use_highbitdepth); - - if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) - predictor = CONVERT_TO_BYTEPTR(predictor16); - else - predictor = predictor8; -#else - vp9_setup_scale_factors_for_frame( - &sf, this_frame->y_crop_width, this_frame->y_crop_height, - this_frame->y_crop_width, this_frame->y_crop_height); -#endif // CONFIG_VP9_HIGHBITDEPTH - - // Prepare reference frame pointers. If any reference frame slot is - // unavailable, the pointer will be set to Null. - for (idx = 0; idx < MAX_INTER_REF_FRAMES; ++idx) { - int rf_idx = gf_picture[frame_idx].ref_frame[idx]; - if (rf_idx != -1) ref_frame[idx] = gf_picture[rf_idx].frame; - } - - xd->mi = cm->mi_grid_visible; - xd->mi[0] = cm->mi; - xd->cur_buf = this_frame; - - // Get rd multiplier set up. - rdmult = vp9_compute_rd_mult_based_on_qindex(cpi, tpl_frame->base_qindex); - set_error_per_bit(&cpi->td.mb, rdmult); - vp9_initialize_me_consts(cpi, &cpi->td.mb, tpl_frame->base_qindex); - - tpl_frame->is_valid = 1; - - cm->base_qindex = tpl_frame->base_qindex; - vp9_frame_init_quantizer(cpi); - -#if CONFIG_NON_GREEDY_MV - for (square_block_idx = 0; square_block_idx < SQUARE_BLOCK_SIZES; - ++square_block_idx) { - BLOCK_SIZE square_bsize = square_block_idx_to_bsize(square_block_idx); - build_motion_field(cpi, frame_idx, ref_frame, square_bsize); - } - for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { - int ref_frame_idx = gf_picture[frame_idx].ref_frame[rf_idx]; - if (ref_frame_idx != -1) { - MotionField *motion_field = vp9_motion_field_info_get_motion_field( - &cpi->motion_field_info, frame_idx, rf_idx, bsize); - predict_mv_mode_arr(cpi, x, gf_picture, motion_field, frame_idx, - tpl_frame, rf_idx, bsize); - } - } -#endif - - for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) { - for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) { - mode_estimation(cpi, x, xd, &sf, gf_picture, frame_idx, tpl_frame, - src_diff, coeff, qcoeff, dqcoeff, mi_row, mi_col, bsize, - tx_size, ref_frame, predictor, &recon_error, &sse); - // Motion flow dependency dispenser. - tpl_model_store(tpl_frame->tpl_stats_ptr, mi_row, mi_col, bsize, - tpl_frame->stride); - - tpl_model_update(cpi->tpl_stats, tpl_frame->tpl_stats_ptr, mi_row, mi_col, - bsize); - } - } -} - -#if CONFIG_NON_GREEDY_MV -#define DUMP_TPL_STATS 0 -#if DUMP_TPL_STATS -static void dump_buf(uint8_t *buf, int stride, int row, int col, int h, int w) { - int i, j; - printf("%d %d\n", h, w); - for (i = 0; i < h; ++i) { - for (j = 0; j < w; ++j) { - printf("%d ", buf[(row + i) * stride + col + j]); - } - } - printf("\n"); -} - -static void dump_frame_buf(const YV12_BUFFER_CONFIG *frame_buf) { - dump_buf(frame_buf->y_buffer, frame_buf->y_stride, 0, 0, frame_buf->y_height, - frame_buf->y_width); - dump_buf(frame_buf->u_buffer, frame_buf->uv_stride, 0, 0, - frame_buf->uv_height, frame_buf->uv_width); - dump_buf(frame_buf->v_buffer, frame_buf->uv_stride, 0, 0, - frame_buf->uv_height, frame_buf->uv_width); -} - -static void dump_tpl_stats(const VP9_COMP *cpi, int tpl_group_frames, - const GF_GROUP *gf_group, - const GF_PICTURE *gf_picture, BLOCK_SIZE bsize) { - int frame_idx; - const VP9_COMMON *cm = &cpi->common; - int rf_idx; - for (frame_idx = 1; frame_idx < tpl_group_frames; ++frame_idx) { - for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { - const TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx]; - int mi_row, mi_col; - int ref_frame_idx; - const int mi_height = num_8x8_blocks_high_lookup[bsize]; - const int mi_width = num_8x8_blocks_wide_lookup[bsize]; - ref_frame_idx = gf_picture[frame_idx].ref_frame[rf_idx]; - if (ref_frame_idx != -1) { - YV12_BUFFER_CONFIG *ref_frame_buf = gf_picture[ref_frame_idx].frame; - const int gf_frame_offset = gf_group->frame_gop_index[frame_idx]; - const int ref_gf_frame_offset = - gf_group->frame_gop_index[ref_frame_idx]; - printf("=\n"); - printf( - "frame_idx %d mi_rows %d mi_cols %d bsize %d ref_frame_idx %d " - "rf_idx %d gf_frame_offset %d ref_gf_frame_offset %d\n", - frame_idx, cm->mi_rows, cm->mi_cols, mi_width * MI_SIZE, - ref_frame_idx, rf_idx, gf_frame_offset, ref_gf_frame_offset); - for (mi_row = 0; mi_row < cm->mi_rows; ++mi_row) { - for (mi_col = 0; mi_col < cm->mi_cols; ++mi_col) { - if ((mi_row % mi_height) == 0 && (mi_col % mi_width) == 0) { - int_mv mv = vp9_motion_field_info_get_mv(&cpi->motion_field_info, - frame_idx, rf_idx, bsize, - mi_row, mi_col); - printf("%d %d %d %d\n", mi_row, mi_col, mv.as_mv.row, - mv.as_mv.col); - } - } - } - for (mi_row = 0; mi_row < cm->mi_rows; ++mi_row) { - for (mi_col = 0; mi_col < cm->mi_cols; ++mi_col) { - if ((mi_row % mi_height) == 0 && (mi_col % mi_width) == 0) { - const TplDepStats *tpl_ptr = - &tpl_frame - ->tpl_stats_ptr[mi_row * tpl_frame->stride + mi_col]; - printf("%f ", tpl_ptr->feature_score); - } - } - } - printf("\n"); - - for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) { - for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) { - const int mv_mode = - tpl_frame - ->mv_mode_arr[rf_idx][mi_row * tpl_frame->stride + mi_col]; - printf("%d ", mv_mode); - } - } - printf("\n"); - - dump_frame_buf(gf_picture[frame_idx].frame); - dump_frame_buf(ref_frame_buf); - } - } - } -} -#endif // DUMP_TPL_STATS -#endif // CONFIG_NON_GREEDY_MV - -static void init_tpl_buffer(VP9_COMP *cpi) { - VP9_COMMON *cm = &cpi->common; - int frame; - - const int mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); - const int mi_rows = mi_cols_aligned_to_sb(cm->mi_rows); -#if CONFIG_NON_GREEDY_MV - int rf_idx; - - vpx_free(cpi->select_mv_arr); - CHECK_MEM_ERROR( - cm, cpi->select_mv_arr, - vpx_calloc(mi_rows * mi_cols * 4, sizeof(*cpi->select_mv_arr))); -#endif - - // TODO(jingning): Reduce the actual memory use for tpl model build up. - for (frame = 0; frame < MAX_ARF_GOP_SIZE; ++frame) { - if (cpi->tpl_stats[frame].width >= mi_cols && - cpi->tpl_stats[frame].height >= mi_rows && - cpi->tpl_stats[frame].tpl_stats_ptr) - continue; - -#if CONFIG_NON_GREEDY_MV - for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { - vpx_free(cpi->tpl_stats[frame].mv_mode_arr[rf_idx]); - CHECK_MEM_ERROR( - cm, cpi->tpl_stats[frame].mv_mode_arr[rf_idx], - vpx_calloc(mi_rows * mi_cols * 4, - sizeof(*cpi->tpl_stats[frame].mv_mode_arr[rf_idx]))); - vpx_free(cpi->tpl_stats[frame].rd_diff_arr[rf_idx]); - CHECK_MEM_ERROR( - cm, cpi->tpl_stats[frame].rd_diff_arr[rf_idx], - vpx_calloc(mi_rows * mi_cols * 4, - sizeof(*cpi->tpl_stats[frame].rd_diff_arr[rf_idx]))); - } -#endif - vpx_free(cpi->tpl_stats[frame].tpl_stats_ptr); - CHECK_MEM_ERROR(cm, cpi->tpl_stats[frame].tpl_stats_ptr, - vpx_calloc(mi_rows * mi_cols, - sizeof(*cpi->tpl_stats[frame].tpl_stats_ptr))); - cpi->tpl_stats[frame].is_valid = 0; - cpi->tpl_stats[frame].width = mi_cols; - cpi->tpl_stats[frame].height = mi_rows; - cpi->tpl_stats[frame].stride = mi_cols; - cpi->tpl_stats[frame].mi_rows = cm->mi_rows; - cpi->tpl_stats[frame].mi_cols = cm->mi_cols; - } - - for (frame = 0; frame < REF_FRAMES; ++frame) { - cpi->enc_frame_buf[frame].mem_valid = 0; - cpi->enc_frame_buf[frame].released = 1; - } -} - -static void free_tpl_buffer(VP9_COMP *cpi) { - int frame; -#if CONFIG_NON_GREEDY_MV - vp9_free_motion_field_info(&cpi->motion_field_info); - vpx_free(cpi->select_mv_arr); -#endif - for (frame = 0; frame < MAX_ARF_GOP_SIZE; ++frame) { -#if CONFIG_NON_GREEDY_MV - int rf_idx; - for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { - vpx_free(cpi->tpl_stats[frame].mv_mode_arr[rf_idx]); - vpx_free(cpi->tpl_stats[frame].rd_diff_arr[rf_idx]); - } -#endif - vpx_free(cpi->tpl_stats[frame].tpl_stats_ptr); - cpi->tpl_stats[frame].is_valid = 0; - } -} - -#if CONFIG_RATE_CTRL -static void accumulate_frame_tpl_stats(VP9_COMP *cpi) { - VP9_COMMON *const cm = &cpi->common; - const GF_GROUP *gf_group = &cpi->twopass.gf_group; - int show_frame_count = 0; - int frame_idx; - // Accumulate tpl stats for each frame in the current group of picture. - for (frame_idx = 1; frame_idx < gf_group->gf_group_size; ++frame_idx) { - TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx]; - TplDepStats *tpl_stats = tpl_frame->tpl_stats_ptr; - const int tpl_stride = tpl_frame->stride; - int64_t intra_cost_base = 0; - int64_t inter_cost_base = 0; - int64_t mc_dep_cost_base = 0; - int64_t mc_ref_cost_base = 0; - int64_t mc_flow_base = 0; - int row, col; - - if (!tpl_frame->is_valid) continue; - - for (row = 0; row < cm->mi_rows && tpl_frame->is_valid; ++row) { - for (col = 0; col < cm->mi_cols; ++col) { - TplDepStats *this_stats = &tpl_stats[row * tpl_stride + col]; - intra_cost_base += this_stats->intra_cost; - inter_cost_base += this_stats->inter_cost; - mc_dep_cost_base += this_stats->mc_dep_cost; - mc_ref_cost_base += this_stats->mc_ref_cost; - mc_flow_base += this_stats->mc_flow; - } - } - - cpi->tpl_stats_info[show_frame_count].intra_cost = intra_cost_base; - cpi->tpl_stats_info[show_frame_count].inter_cost = inter_cost_base; - cpi->tpl_stats_info[show_frame_count].mc_dep_cost = mc_dep_cost_base; - cpi->tpl_stats_info[show_frame_count].mc_ref_cost = mc_ref_cost_base; - cpi->tpl_stats_info[show_frame_count].mc_flow = mc_flow_base; - - ++show_frame_count; - } -} -#endif // CONFIG_RATE_CTRL - -static void setup_tpl_stats(VP9_COMP *cpi) { - GF_PICTURE gf_picture[MAX_ARF_GOP_SIZE]; - const GF_GROUP *gf_group = &cpi->twopass.gf_group; - int tpl_group_frames = 0; - int frame_idx; - cpi->tpl_bsize = BLOCK_32X32; - - init_gop_frames(cpi, gf_picture, gf_group, &tpl_group_frames); - - init_tpl_stats(cpi); - - // Backward propagation from tpl_group_frames to 1. - for (frame_idx = tpl_group_frames - 1; frame_idx > 0; --frame_idx) { - if (gf_picture[frame_idx].update_type == USE_BUF_FRAME) continue; - mc_flow_dispenser(cpi, gf_picture, frame_idx, cpi->tpl_bsize); - } -#if CONFIG_NON_GREEDY_MV - cpi->tpl_ready = 1; -#if DUMP_TPL_STATS - dump_tpl_stats(cpi, tpl_group_frames, gf_group, gf_picture, cpi->tpl_bsize); -#endif // DUMP_TPL_STATS -#endif // CONFIG_NON_GREEDY_MV - -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - accumulate_frame_tpl_stats(cpi); - } -#endif // CONFIG_RATE_CTRL -} - void vp9_get_ref_frame_info(FRAME_UPDATE_TYPE update_type, int ref_frame_flags, RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES], int *ref_frame_coding_indexes, @@ -7625,23 +6116,38 @@ void vp9_get_ref_frame_info(FRAME_UPDATE_TYPE update_type, int ref_frame_flags, void vp9_init_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result) { encode_frame_result->show_idx = -1; // Actual encoding doesn't happen. -#if CONFIG_RATE_CTRL - encode_frame_result->frame_coding_index = -1; - vp9_zero(encode_frame_result->coded_frame); - encode_frame_result->coded_frame.allocated = 0; - init_rq_history(&encode_frame_result->rq_history); -#endif // CONFIG_RATE_CTRL +} + +// Returns if TPL stats need to be calculated. +static INLINE int should_run_tpl(VP9_COMP *cpi, int gf_group_index) { + RATE_CONTROL *const rc = &cpi->rc; + if (!cpi->sf.enable_tpl_model) return 0; + // If there is an ARF for this GOP, TPL stats is always calculated. + if (gf_group_index == 1 && + cpi->twopass.gf_group.update_type[gf_group_index] == ARF_UPDATE) + return 1; + // If this GOP doesn't have an ARF, TPL stats is still calculated, only when + // external rate control is used. + if (cpi->ext_ratectrl.ready && + cpi->ext_ratectrl.funcs.send_tpl_gop_stats != NULL && + rc->frames_till_gf_update_due == rc->baseline_gf_interval && + cpi->twopass.gf_group.update_type[1] != ARF_UPDATE) { + return 1; + } + return 0; } int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, - size_t *size, uint8_t *dest, int64_t *time_stamp, - int64_t *time_end, int flush, + size_t *size, uint8_t *dest, size_t dest_size, + int64_t *time_stamp, int64_t *time_end, int flush, ENCODE_FRAME_RESULT *encode_frame_result) { const VP9EncoderConfig *const oxcf = &cpi->oxcf; VP9_COMMON *const cm = &cpi->common; BufferPool *const pool = cm->buffer_pool; RATE_CONTROL *const rc = &cpi->rc; +#if CONFIG_INTERNAL_STATS struct vpx_usec_timer cmptimer; +#endif YV12_BUFFER_CONFIG *force_src_buffer = NULL; struct lookahead_entry *last_source = NULL; struct lookahead_entry *source = NULL; @@ -7649,11 +6155,17 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, const int gf_group_index = cpi->twopass.gf_group.index; int i; - if (is_one_pass_cbr_svc(cpi)) { - vp9_one_pass_cbr_svc_start_layer(cpi); +#if CONFIG_COLLECT_COMPONENT_TIMING + if (oxcf->pass == 2) start_timing(cpi, vp9_get_compressed_data_time); +#endif + + if (is_one_pass_svc(cpi)) { + vp9_one_pass_svc_start_layer(cpi); } +#if CONFIG_INTERNAL_STATS vpx_usec_timer_start(&cmptimer); +#endif vp9_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); @@ -7670,7 +6182,7 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, // Normal defaults cm->reset_frame_context = 0; cm->refresh_frame_context = 1; - if (!is_one_pass_cbr_svc(cpi)) { + if (!is_one_pass_svc(cpi)) { cpi->refresh_last_frame = 1; cpi->refresh_golden_frame = 0; cpi->refresh_alt_ref_frame = 0; @@ -7700,7 +6212,12 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, } if (arf_src_index) { - assert(arf_src_index <= rc->frames_to_key); + if (!(cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_GOP) != 0 && + cpi->ext_ratectrl.funcs.get_gop_decision != NULL)) { + // This assert only makes sense when not using external RC. + assert(arf_src_index <= rc->frames_to_key); + } if ((source = vp9_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { cpi->alt_ref_source = source; @@ -7713,16 +6230,22 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, int not_last_frame = (cpi->lookahead->sz - arf_src_index > 1); not_last_frame |= ALT_REF_AQ_APPLY_TO_LAST_FRAME; +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, vp9_temporal_filter_time); +#endif // Produce the filtered ARF frame. vp9_temporal_filter(cpi, arf_src_index); - vpx_extend_frame_borders(&cpi->alt_ref_buffer); + vpx_extend_frame_borders(&cpi->tf_buffer); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, vp9_temporal_filter_time); +#endif // for small bitrates segmentation overhead usually // eats all bitrate gain from enabling delta quantizers if (cpi->oxcf.alt_ref_aq != 0 && not_low_bitrate && not_last_frame) vp9_alt_ref_aq_setup_mode(cpi->alt_ref_aq, cpi); - force_src_buffer = &cpi->alt_ref_buffer; + force_src_buffer = &cpi->tf_buffer; } #endif cm->show_frame = 0; @@ -7770,10 +6293,33 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, cpi->un_scaled_source = cpi->Source = force_src_buffer ? force_src_buffer : &source->img; -#ifdef ENABLE_KF_DENOISE +#if defined(ENABLE_KF_DENOISE) || CONFIG_VP9_TEMPORAL_DENOISING // Copy of raw source for metrics calculation. - if (is_psnr_calc_enabled(cpi)) - vp9_copy_and_extend_frame(cpi->Source, &cpi->raw_unscaled_source); + if (is_psnr_calc_enabled(cpi) && + (!cpi->use_svc || + cpi->svc.spatial_layer_id == cpi->svc.first_spatial_layer_to_encode)) { + int copy_raw_source = 0; +#ifdef ENABLE_KF_DENOISE + copy_raw_source |= is_spatial_denoise_enabled(cpi); +#endif +#if CONFIG_VP9_TEMPORAL_DENOISING + copy_raw_source |= (cpi->oxcf.noise_sensitivity > 0); +#endif + if (copy_raw_source) { + if (vpx_realloc_frame_buffer( + &cpi->raw_unscaled_source, cpi->Source->y_crop_width, + cpi->Source->y_crop_height, cpi->Source->subsampling_x, + cpi->Source->subsampling_y, +#if CONFIG_VP9_HIGHBITDEPTH + cm->use_highbitdepth, +#endif + VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) + vpx_internal_error( + &cm->error, VPX_CODEC_MEM_ERROR, + "Failed to allocate unscaled raw source frame buffer"); + vp9_copy_and_extend_frame(cpi->Source, &cpi->raw_unscaled_source); + } + } #endif cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL; @@ -7797,13 +6343,21 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, // adjust frame rates based on timestamps given if (cm->show_frame) { if (cpi->use_svc && cpi->svc.use_set_ref_frame_config && - cpi->svc.duration[cpi->svc.spatial_layer_id] > 0) - vp9_svc_adjust_frame_rate(cpi); - else + cpi->svc.duration[cpi->svc.spatial_layer_id] > 0) { + if (cpi->svc.timebase_fac > 0 && + cpi->svc.duration[cpi->svc.spatial_layer_id] > + INT64_MAX / cpi->svc.timebase_fac) { + vpx_internal_error(&cpi->common.error, VPX_CODEC_INVALID_PARAM, + "svc duration would overflow timebase conversion"); + } else { + vp9_svc_adjust_frame_rate(cpi); + } + } else { adjust_frame_rate(cpi, source); + } } - if (is_one_pass_cbr_svc(cpi)) { + if (is_one_pass_svc(cpi)) { vp9_update_temporal_layer_framerate(cpi); vp9_restore_layer_context(cpi); } @@ -7829,10 +6383,36 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, #if !CONFIG_REALTIME_ONLY if ((oxcf->pass == 2) && !cpi->use_svc) { +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, vp9_rc_get_second_pass_params_time); +#endif vp9_rc_get_second_pass_params(cpi); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, vp9_rc_get_second_pass_params_time); +#endif } else if (oxcf->pass == 1) { set_frame_size(cpi); } + + // Key frame temporal filtering + const int is_key_temporal_filter_enabled = + oxcf->enable_keyframe_filtering && cpi->oxcf.mode != REALTIME && + (oxcf->pass != 1) && !cpi->use_svc && + !is_lossless_requested(&cpi->oxcf) && cm->frame_type == KEY_FRAME && + (oxcf->arnr_max_frames > 0) && (oxcf->arnr_strength > 0) && + cpi->oxcf.speed < 2; + // Save the pointer to the original source image. + YV12_BUFFER_CONFIG *source_buffer = cpi->un_scaled_source; + + if (is_key_temporal_filter_enabled && source != NULL) { + // Produce the filtered Key frame. Set distance to -1 since the key frame + // is already popped out. + vp9_temporal_filter(cpi, -1); + vpx_extend_frame_borders(&cpi->tf_buffer); + force_src_buffer = &cpi->tf_buffer; + cpi->un_scaled_source = cpi->Source = + force_src_buffer ? force_src_buffer : &source->img; + } #endif // !CONFIG_REALTIME_ONLY if (oxcf->pass != 1 && cpi->level_constraint.level_index >= 0 && @@ -7844,13 +6424,16 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, } if (cpi->kmeans_data_arr_alloc == 0) { - const int mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); - const int mi_rows = mi_cols_aligned_to_sb(cm->mi_rows); + int init_mi_rows, init_mi_cols, init_mi_stride; + vp9_set_mi_size(&init_mi_rows, &init_mi_cols, &init_mi_stride, + cpi->initial_width, cpi->initial_height); + const int mi_cols = mi_cols_aligned_to_sb(init_mi_cols); + const int mi_rows = mi_cols_aligned_to_sb(init_mi_rows); #if CONFIG_MULTITHREAD pthread_mutex_init(&cpi->kmeans_mutex, NULL); #endif CHECK_MEM_ERROR( - cm, cpi->kmeans_data_arr, + &cm->error, cpi->kmeans_data_arr, vpx_calloc(mi_rows * mi_cols, sizeof(*cpi->kmeans_data_arr))); cpi->kmeans_data_stride = mi_cols; cpi->kmeans_data_arr_alloc = 1; @@ -7869,13 +6452,21 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, } #endif // CONFIG_NON_GREEDY_MV - if (gf_group_index == 1 && - cpi->twopass.gf_group.update_type[gf_group_index] == ARF_UPDATE && - cpi->sf.enable_tpl_model) { - init_tpl_buffer(cpi); - vp9_estimate_qp_gop(cpi); - setup_tpl_stats(cpi); +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, setup_tpl_stats_time); +#endif + if (should_run_tpl(cpi, cpi->twopass.gf_group.index)) { + // vp9_estimate_tpl_qp_gop() may write to sb_mul_scale. TPL can run before + // the first call to encode_frame_to_data_rate(), e.g., on the key frame of + // a GOP without ARF, so make sure the buffer is allocated here. + init_sb_mul_scale_buffer(cpi); + vp9_init_tpl_buffer(cpi); + vp9_estimate_tpl_qp_gop(cpi); + vp9_setup_tpl_stats(cpi); } +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, setup_tpl_stats_time); +#endif #if CONFIG_BITSTREAM_DEBUG assert(cpi->oxcf.max_threads == 0 && @@ -7890,10 +6481,10 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, #if CONFIG_REALTIME_ONLY (void)encode_frame_result; if (cpi->use_svc) { - SvcEncode(cpi, size, dest, frame_flags); + SvcEncode(cpi, size, dest, dest_size, frame_flags); } else { // One pass encode - Pass0Encode(cpi, size, dest, frame_flags); + Pass0Encode(cpi, size, dest, dest_size, frame_flags); } #else // !CONFIG_REALTIME_ONLY if (oxcf->pass == 1 && !cpi->use_svc) { @@ -7912,13 +6503,20 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, cpi->td.mb.inv_txfm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; vp9_first_pass(cpi, source); } else if (oxcf->pass == 2 && !cpi->use_svc) { - Pass2Encode(cpi, size, dest, frame_flags, encode_frame_result); +#if CONFIG_COLLECT_COMPONENT_TIMING + // Accumulate 2nd pass time in 2-pass case. + start_timing(cpi, Pass2Encode_time); +#endif + Pass2Encode(cpi, size, dest, dest_size, frame_flags, encode_frame_result); vp9_twopass_postencode_update(cpi); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, Pass2Encode_time); +#endif } else if (cpi->use_svc) { - SvcEncode(cpi, size, dest, frame_flags); + SvcEncode(cpi, size, dest, dest_size, frame_flags); } else { // One pass encode - Pass0Encode(cpi, size, dest, frame_flags); + Pass0Encode(cpi, size, dest, dest_size, frame_flags); } #endif // CONFIG_REALTIME_ONLY @@ -7937,23 +6535,35 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, } // Save layer specific state. - if (is_one_pass_cbr_svc(cpi) || ((cpi->svc.number_temporal_layers > 1 || - cpi->svc.number_spatial_layers > 1) && - oxcf->pass == 2)) { + if (is_one_pass_svc(cpi) || ((cpi->svc.number_temporal_layers > 1 || + cpi->svc.number_spatial_layers > 1) && + oxcf->pass == 2)) { vp9_save_layer_context(cpi); } + if (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1) + cpi->fixed_qp_onepass = 0; + +#if CONFIG_INTERNAL_STATS vpx_usec_timer_mark(&cmptimer); cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); +#endif if (cpi->keep_level_stats && oxcf->pass != 1) - update_level_info(cpi, size, arf_src_index); + update_level_info(cpi, *size, arf_src_index); + +#if !CONFIG_REALTIME_ONLY + if (is_key_temporal_filter_enabled && cpi->b_calculate_psnr) { + cpi->raw_source_frame = vp9_scale_if_required( + cm, source_buffer, &cpi->scaled_source, (oxcf->pass == 0), EIGHTTAP, 0); + } +#endif // !CONFIG_REALTIME_ONLY #if CONFIG_INTERNAL_STATS - if (oxcf->pass != 1) { + if (oxcf->pass != 1 && !cpi->last_frame_dropped) { double samples = 0.0; - cpi->bytes += (int)(*size); + cpi->bytes += *size; if (cm->show_frame) { uint32_t bit_depth = 8; @@ -7973,9 +6583,9 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, PSNR_STATS psnr; #if CONFIG_VP9_HIGHBITDEPTH vpx_calc_highbd_psnr(orig, recon, &psnr, cpi->td.mb.e_mbd.bd, - in_bit_depth); + in_bit_depth, cpi->svc.spatial_layer_id); #else - vpx_calc_psnr(orig, recon, &psnr); + vpx_calc_psnr(orig, recon, &psnr, cpi->svc.spatial_layer_id); #endif // CONFIG_VP9_HIGHBITDEPTH adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], @@ -8011,9 +6621,10 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, #if CONFIG_VP9_HIGHBITDEPTH vpx_calc_highbd_psnr(orig, pp, &psnr2, cpi->td.mb.e_mbd.bd, - cpi->oxcf.input_bit_depth); + cpi->oxcf.input_bit_depth, + cpi->svc.spatial_layer_id); #else - vpx_calc_psnr(orig, pp, &psnr2); + vpx_calc_psnr(orig, pp, &psnr2, cpi->svc.spatial_layer_id); #endif // CONFIG_VP9_HIGHBITDEPTH cpi->totalp_sq_error += psnr2.sse[0]; @@ -8113,7 +6724,42 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, #endif - if (is_one_pass_cbr_svc(cpi)) { +#if CONFIG_COLLECT_COMPONENT_TIMING + if (oxcf->pass == 2) end_timing(cpi, vp9_get_compressed_data_time); + + // Print out timing information. + // Note: Use "cpi->frame_component_time[0] > 100 us" to avoid showing of + // show_existing_frame and lag-in-frames. + // if (cpi->frame_component_time[0] > 100) + if (oxcf->pass == 2) { + uint64_t frame_total = 0, total = 0; + int i; + + fprintf(stderr, + "\n Frame number: %d, Frame type: %s, Show Frame: %d, Q: %d\n", + cm->current_video_frame, get_frame_type_enum(cm->frame_type), + cm->show_frame, cm->base_qindex); + for (i = 0; i < kTimingComponents; i++) { + cpi->component_time[i] += cpi->frame_component_time[i]; + // Use vp9_get_compressed_data_time (i = 0) as the total time. + if (i == 0) { + frame_total = cpi->frame_component_time[0]; + total = cpi->component_time[0]; + } + fprintf(stderr, + " %50s: %15" PRId64 " us [%6.2f%%] (total: %15" PRId64 + " us [%6.2f%%])\n", + get_component_name(i), cpi->frame_component_time[i], + (float)((float)cpi->frame_component_time[i] * 100.0 / + (float)frame_total), + cpi->component_time[i], + (float)((float)cpi->component_time[i] * 100.0 / (float)total)); + cpi->frame_component_time[i] = 0; + } + } +#endif + + if (is_one_pass_svc(cpi)) { if (cm->show_frame) { ++cpi->svc.spatial_layer_to_encode; if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers) @@ -8155,12 +6801,12 @@ int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest, } } -int vp9_set_internal_size(VP9_COMP *cpi, VPX_SCALING horiz_mode, - VPX_SCALING vert_mode) { +int vp9_set_internal_size(VP9_COMP *cpi, VPX_SCALING_MODE horiz_mode, + VPX_SCALING_MODE vert_mode) { VP9_COMMON *cm = &cpi->common; int hr = 0, hs = 0, vr = 0, vs = 0; - if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; + if (horiz_mode > VP8E_ONETWO || vert_mode > VP8E_ONETWO) return -1; Scale2Ratio(horiz_mode, &hr, &hs); Scale2Ratio(vert_mode, &vr, &vs); @@ -8182,9 +6828,11 @@ int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width, unsigned int height) { VP9_COMMON *cm = &cpi->common; #if CONFIG_VP9_HIGHBITDEPTH - update_initial_width(cpi, cm->use_highbitdepth, 1, 1); + update_initial_width(cpi, cm->use_highbitdepth, cpi->common.subsampling_x, + cpi->common.subsampling_y); #else - update_initial_width(cpi, 0, 1, 1); + update_initial_width(cpi, 0, cpi->common.subsampling_x, + cpi->common.subsampling_y); #endif // CONFIG_VP9_HIGHBITDEPTH #if CONFIG_VP9_TEMPORAL_DENOISING @@ -8195,7 +6843,6 @@ int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width, cm->width = width; if (cm->width > cpi->initial_width) { cm->width = cpi->initial_width; - printf("Warning: Desired width too large, changed to %d\n", cm->width); } } @@ -8203,7 +6850,6 @@ int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width, cm->height = height; if (cm->height > cpi->initial_height) { cm->height = cpi->initial_height; - printf("Warning: Desired height too large, changed to %d\n", cm->height); } } assert(cm->width <= cpi->initial_width); diff --git a/libs/libvpx/vp9/encoder/vp9_encoder.h b/libs/libvpx/vp9/encoder/vp9_encoder.h index 1d58945250..2a59b7d1a6 100644 --- a/libs/libvpx/vp9/encoder/vp9_encoder.h +++ b/libs/libvpx/vp9/encoder/vp9_encoder.h @@ -14,15 +14,18 @@ #include #include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" #include "vpx/internal/vpx_codec_internal.h" #include "vpx/vpx_ext_ratectrl.h" #include "vpx/vp8cx.h" +#include "vpx/vpx_tpl.h" #if CONFIG_INTERNAL_STATS #include "vpx_dsp/ssim.h" #endif #include "vpx_dsp/variance.h" #include "vpx_dsp/psnr.h" #include "vpx_ports/system_state.h" +#include "vpx_util/vpx_pthread.h" #include "vpx_util/vpx_thread.h" #include "vpx_util/vpx_timestamp.h" @@ -90,13 +93,6 @@ typedef enum { ENCODE_BREAKOUT_LIMITED = 2 } ENCODE_BREAKOUT_TYPE; -typedef enum { - NORMAL = 0, - FOURFIVE = 1, - THREEFIVE = 2, - ONETWO = 3 -} VPX_SCALING; - typedef enum { // Good Quality Fast Encoding. The encoder balances quality with the amount of // time it takes to encode the output. Speed setting controls how fast. @@ -160,7 +156,7 @@ typedef struct VP9EncoderConfig { vpx_bit_depth_t bit_depth; // Codec bit-depth. int width; // width of data passed to the compressor int height; // height of data passed to the compressor - unsigned int input_bit_depth; // Input bit depth. + unsigned int input_bit_depth; // Actual bit-depth of the input source double init_framerate; // set to passed in framerate vpx_rational_t g_timebase; // equivalent to g_timebase in vpx_codec_enc_cfg_t vpx_rational64_t g_timebase_in_ts; // g_timebase * TICKS_PER_SEC @@ -267,6 +263,8 @@ typedef struct VP9EncoderConfig { int enable_tpl_model; + int enable_keyframe_filtering; + int max_threads; unsigned int target_level; @@ -287,7 +285,6 @@ typedef struct VP9EncoderConfig { int row_mt; unsigned int motion_vector_unit_test; int delta_q_uv; - int use_simple_encode_api; // Use SimpleEncode APIs or not } VP9EncoderConfig; static INLINE int is_lossless_requested(const VP9EncoderConfig *cfg) { @@ -336,15 +333,18 @@ typedef struct TplDepFrame { typedef struct TileDataEnc { TileInfo tile_info; int thresh_freq_fact[BLOCK_SIZES][MAX_MODES]; -#if CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL int thresh_freq_fact_prev[BLOCK_SIZES][MAX_MODES]; -#endif // CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL int8_t mode_map[BLOCK_SIZES][MAX_MODES]; FIRSTPASS_DATA fp_data; VP9RowMTSync row_mt_sync; // Used for adaptive_rd_thresh with row multithreading int *row_base_thresh_freq_fact; + // The value of sb_rows when row_base_thresh_freq_fact is allocated. + // The row_base_thresh_freq_fact array has sb_rows * BLOCK_SIZES * MAX_MODES + // elements. + int sb_rows; + MV firstpass_top_mv; } TileDataEnc; typedef struct RowMTInfo { @@ -504,6 +504,7 @@ typedef struct ARNRFilterData { int frame_count; int alt_ref_index; struct scale_factors sf; + YV12_BUFFER_CONFIG *dst; } ARNRFilterData; typedef struct EncFrameBuf { @@ -513,6 +514,7 @@ typedef struct EncFrameBuf { } EncFrameBuf; // Maximum operating frame buffer size needed for a GOP using ARF reference. +// This is used to allocate the memory for TPL stats for a GOP. #define MAX_ARF_GOP_SIZE (2 * MAX_LAG_BUFFERS) #define MAX_KMEANS_GROUPS 8 @@ -522,142 +524,71 @@ typedef struct KMEANS_DATA { int group_idx; } KMEANS_DATA; -#if CONFIG_RATE_CTRL -typedef struct PARTITION_INFO { - int row; // row pixel offset of current 4x4 block - int column; // column pixel offset of current 4x4 block - int row_start; // row pixel offset of the start of the prediction block - int column_start; // column pixel offset of the start of the prediction block - int width; // prediction block width - int height; // prediction block height -} PARTITION_INFO; +#if CONFIG_COLLECT_COMPONENT_TIMING +#include "vpx_ports/vpx_timer.h" +// Adjust the following to add new components. +typedef enum { + vp9_get_compressed_data_time, + vp9_temporal_filter_time, + vp9_rc_get_second_pass_params_time, + setup_tpl_stats_time, + Pass2Encode_time, -typedef struct MOTION_VECTOR_INFO { - MV_REFERENCE_FRAME ref_frame[2]; - int_mv mv[2]; -} MOTION_VECTOR_INFO; + encode_with_recode_loop_time, + loopfilter_frame_time, + vp9_pack_bitstream_time, -typedef struct GOP_COMMAND { - int use; // use this command to set gop or not. If not, use vp9's decision. - int show_frame_count; - int use_alt_ref; -} GOP_COMMAND; + encode_frame_internal_time, + rd_pick_partition_time, + rd_pick_sb_modes_time, + encode_sb_time, -static INLINE void gop_command_on(GOP_COMMAND *gop_command, - int show_frame_count, int use_alt_ref) { - gop_command->use = 1; - gop_command->show_frame_count = show_frame_count; - gop_command->use_alt_ref = use_alt_ref; -} + vp9_rd_pick_inter_mode_sb_time, + vp9_rd_pick_inter_mode_sub8x8_time, -static INLINE void gop_command_off(GOP_COMMAND *gop_command) { - gop_command->use = 0; - gop_command->show_frame_count = 0; - gop_command->use_alt_ref = 0; -} + intra_mode_search_time, + handle_inter_mode_time, + single_motion_search_time, + joint_motion_search_time, + interp_filter_time, -static INLINE int gop_command_coding_frame_count( - const GOP_COMMAND *gop_command) { - if (gop_command->use == 0) { - assert(0); - return -1; + kTimingComponents, +} TIMING_COMPONENT; + +static INLINE char const *get_component_name(int index) { + switch (index) { + case vp9_get_compressed_data_time: return "vp9_get_compressed_data_time"; + case vp9_temporal_filter_time: return "vp9_temporal_filter_time"; + case vp9_rc_get_second_pass_params_time: + return "vp9_rc_get_second_pass_params_time"; + case setup_tpl_stats_time: return "setup_tpl_stats_time"; + case Pass2Encode_time: return "Pass2Encode_time"; + + case encode_with_recode_loop_time: return "encode_with_recode_loop_time"; + case loopfilter_frame_time: return "loopfilter_frame_time"; + case vp9_pack_bitstream_time: return "vp9_pack_bitstream_time"; + + case encode_frame_internal_time: return "encode_frame_internal_time"; + case rd_pick_partition_time: return "rd_pick_partition_time"; + case rd_pick_sb_modes_time: return "rd_pick_sb_modes_time"; + case encode_sb_time: return "encode_sb_time"; + + case vp9_rd_pick_inter_mode_sb_time: + return "vp9_rd_pick_inter_mode_sb_time"; + case vp9_rd_pick_inter_mode_sub8x8_time: + return "vp9_rd_pick_inter_mode_sub8x8_time"; + + case intra_mode_search_time: return "intra_mode_search_time"; + case handle_inter_mode_time: return "handle_inter_mode_time"; + case single_motion_search_time: return "single_motion_search_time"; + case joint_motion_search_time: return "joint_motion_search_time"; + case interp_filter_time: return "interp_filter_time"; + + default: assert(0); } - return gop_command->show_frame_count + gop_command->use_alt_ref; + return "error"; } - -// TODO(angiebird): See if we can merge this one with FrameType in -// simple_encode.h -typedef enum ENCODE_FRAME_TYPE { - ENCODE_FRAME_TYPE_KEY, - ENCODE_FRAME_TYPE_INTER, - ENCODE_FRAME_TYPE_ALTREF, - ENCODE_FRAME_TYPE_OVERLAY, - ENCODE_FRAME_TYPE_GOLDEN, - ENCODE_FRAME_TYPES, -} ENCODE_FRAME_TYPE; - -// TODO(angiebird): Merge this function with get_frame_type_from_update_type() -static INLINE ENCODE_FRAME_TYPE -get_encode_frame_type(FRAME_UPDATE_TYPE update_type) { - switch (update_type) { - case KF_UPDATE: return ENCODE_FRAME_TYPE_KEY; - case ARF_UPDATE: return ENCODE_FRAME_TYPE_ALTREF; - case GF_UPDATE: return ENCODE_FRAME_TYPE_GOLDEN; - case OVERLAY_UPDATE: return ENCODE_FRAME_TYPE_OVERLAY; - case LF_UPDATE: return ENCODE_FRAME_TYPE_INTER; - default: - fprintf(stderr, "Unsupported update_type %d\n", update_type); - abort(); - return ENCODE_FRAME_TYPE_INTER; - } -} - -typedef struct RATE_QSTEP_MODEL { - // The rq model predicts the bit usage as follows. - // rate = bias - ratio * log2(q_step) - int ready; - double bias; - double ratio; -} RATE_QSTEP_MODEL; - -typedef struct ENCODE_COMMAND { - int use_external_quantize_index; - int external_quantize_index; - - int use_external_target_frame_bits; - int target_frame_bits; - double target_frame_bits_error_percent; - - GOP_COMMAND gop_command; -} ENCODE_COMMAND; - -static INLINE void encode_command_set_gop_command( - ENCODE_COMMAND *encode_command, GOP_COMMAND gop_command) { - encode_command->gop_command = gop_command; -} - -static INLINE void encode_command_set_external_quantize_index( - ENCODE_COMMAND *encode_command, int quantize_index) { - encode_command->use_external_quantize_index = 1; - encode_command->external_quantize_index = quantize_index; -} - -static INLINE void encode_command_reset_external_quantize_index( - ENCODE_COMMAND *encode_command) { - encode_command->use_external_quantize_index = 0; - encode_command->external_quantize_index = -1; -} - -static INLINE void encode_command_set_target_frame_bits( - ENCODE_COMMAND *encode_command, int target_frame_bits, - double target_frame_bits_error_percent) { - encode_command->use_external_target_frame_bits = 1; - encode_command->target_frame_bits = target_frame_bits; - encode_command->target_frame_bits_error_percent = - target_frame_bits_error_percent; -} - -static INLINE void encode_command_reset_target_frame_bits( - ENCODE_COMMAND *encode_command) { - encode_command->use_external_target_frame_bits = 0; - encode_command->target_frame_bits = -1; - encode_command->target_frame_bits_error_percent = 0; -} - -static INLINE void encode_command_init(ENCODE_COMMAND *encode_command) { - vp9_zero(*encode_command); - encode_command_reset_external_quantize_index(encode_command); - encode_command_reset_target_frame_bits(encode_command); - gop_command_off(&encode_command->gop_command); -} - -// Returns number of units in size of 4, if not multiple not a multiple of 4, -// round it up. For example, size is 7, return 2. -static INLINE int get_num_unit_4x4(int size) { return (size + 3) >> 2; } -// Returns number of units in size of 16, if not multiple not a multiple of 16, -// round it up. For example, size is 17, return 2. -static INLINE int get_num_unit_16x16(int size) { return (size + 15) >> 4; } -#endif // CONFIG_RATE_CTRL +#endif typedef struct VP9_COMP { FRAME_INFO frame_info; @@ -677,7 +608,7 @@ typedef struct VP9_COMP { YV12_BUFFER_CONFIG scaled_source; YV12_BUFFER_CONFIG *unscaled_last_source; YV12_BUFFER_CONFIG scaled_last_source; -#ifdef ENABLE_KF_DENOISE +#if defined(ENABLE_KF_DENOISE) || CONFIG_VP9_TEMPORAL_DENOISING YV12_BUFFER_CONFIG raw_unscaled_source; YV12_BUFFER_CONFIG raw_scaled_source; #endif @@ -685,6 +616,8 @@ typedef struct VP9_COMP { BLOCK_SIZE tpl_bsize; TplDepFrame tpl_stats[MAX_ARF_GOP_SIZE]; + // Used to store TPL stats before propagation + VpxTplGopStats tpl_gop_stats; YV12_BUFFER_CONFIG *tpl_recon_frames[REF_FRAMES]; EncFrameBuf enc_frame_buf[REF_FRAMES]; #if CONFIG_MULTITHREAD @@ -731,6 +664,12 @@ typedef struct VP9_COMP { int mb_wiener_var_rows; int mb_wiener_var_cols; double *mi_ssim_rdmult_scaling_factors; + int mi_ssim_rdmult_scaling_factors_rows; + int mi_ssim_rdmult_scaling_factors_cols; + + int64_t *sb_mul_scale; + int sb_mul_scale_rows; + int sb_mul_scale_cols; YV12_BUFFER_CONFIG last_frame_uf; @@ -784,7 +723,7 @@ typedef struct VP9_COMP { uint8_t *skin_map; - // segment threashold for encode breakout + // segment threshold for encode breakout int segment_encode_breakout[MAX_SEGMENTS]; CYCLIC_REFRESH *cyclic_refresh; @@ -794,17 +733,19 @@ typedef struct VP9_COMP { struct scale_factors me_sf; vp9_diamond_search_fn_t diamond_search_sad; vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES]; +#if CONFIG_INTERNAL_STATS uint64_t time_receive_data; uint64_t time_compress_data; uint64_t time_pick_lpf; uint64_t time_encode_sb_row; +#endif TWO_PASS twopass; // Force recalculation of segment_ids for each mode info uint8_t force_update_segmentation; - YV12_BUFFER_CONFIG alt_ref_buffer; + YV12_BUFFER_CONFIG tf_buffer; // class responsible for adaptive // quantization of altref frames @@ -825,7 +766,7 @@ typedef struct VP9_COMP { double total_blockiness; double worst_blockiness; - int bytes; + uint64_t bytes; double summed_quality; double summed_weights; double summedp_quality; @@ -858,16 +799,13 @@ typedef struct VP9_COMP { // number of MBs in the current frame when the frame is // scaled. + int last_coded_width; + int last_coded_height; + int use_svc; SVC svc; - // Store frame variance info in SOURCE_VAR_BASED_PARTITION search type. - diff *source_diff_var; - // The threshold used in SOURCE_VAR_BASED_PARTITION search type. - unsigned int source_var_thresh; - int frames_till_next_var_check; - int frame_flags; search_site_config ss_cfg; @@ -961,151 +899,37 @@ typedef struct VP9_COMP { vpx_roi_map_t roi; LOOPFILTER_CONTROL loopfilter_ctrl; -#if CONFIG_RATE_CTRL - ENCODE_COMMAND encode_command; - PARTITION_INFO *partition_info; - MOTION_VECTOR_INFO *motion_vector_info; - MOTION_VECTOR_INFO *fp_motion_vector_info; - TplDepStats *tpl_stats_info; - - RATE_QSTEP_MODEL rq_model[ENCODE_FRAME_TYPES]; -#endif EXT_RATECTRL ext_ratectrl; + + int fixed_qp_onepass; + + // Flag to keep track of dynamic change in deadline mode + // (good/best/realtime). + MODE deadline_mode_previous_frame; + + // Flag to disable scene detection when rtc rate control library is used. + int disable_scene_detection_rtc_ratectrl; + +#if CONFIG_COLLECT_COMPONENT_TIMING + /*! + * component_time[] are initialized to zero while encoder starts. + */ + uint64_t component_time[kTimingComponents]; + /*! + * Stores timing for individual components between calls of start_timing() + * and end_timing(). + */ + struct vpx_usec_timer component_timer[kTimingComponents]; + /*! + * frame_component_time[] are initialized to zero at beginning of each frame. + */ + uint64_t frame_component_time[kTimingComponents]; +#endif } VP9_COMP; -#if CONFIG_RATE_CTRL -// Allocates memory for the partition information. -// The unit size is each 4x4 block. -// Only called once in vp9_create_compressor(). -static INLINE void partition_info_init(struct VP9_COMP *cpi) { - VP9_COMMON *const cm = &cpi->common; - const int unit_width = get_num_unit_4x4(cpi->frame_info.frame_width); - const int unit_height = get_num_unit_4x4(cpi->frame_info.frame_height); - CHECK_MEM_ERROR(cm, cpi->partition_info, - (PARTITION_INFO *)vpx_calloc(unit_width * unit_height, - sizeof(PARTITION_INFO))); - memset(cpi->partition_info, 0, - unit_width * unit_height * sizeof(PARTITION_INFO)); -} - -// Frees memory of the partition information. -// Only called once in dealloc_compressor_data(). -static INLINE void free_partition_info(struct VP9_COMP *cpi) { - vpx_free(cpi->partition_info); - cpi->partition_info = NULL; -} - -static INLINE void reset_mv_info(MOTION_VECTOR_INFO *mv_info) { - mv_info->ref_frame[0] = NONE; - mv_info->ref_frame[1] = NONE; - mv_info->mv[0].as_int = INVALID_MV; - mv_info->mv[1].as_int = INVALID_MV; -} - -// Allocates memory for the motion vector information. -// The unit size is each 4x4 block. -// Only called once in vp9_create_compressor(). -static INLINE void motion_vector_info_init(struct VP9_COMP *cpi) { - VP9_COMMON *const cm = &cpi->common; - const int unit_width = get_num_unit_4x4(cpi->frame_info.frame_width); - const int unit_height = get_num_unit_4x4(cpi->frame_info.frame_height); - CHECK_MEM_ERROR(cm, cpi->motion_vector_info, - (MOTION_VECTOR_INFO *)vpx_calloc(unit_width * unit_height, - sizeof(MOTION_VECTOR_INFO))); - memset(cpi->motion_vector_info, 0, - unit_width * unit_height * sizeof(MOTION_VECTOR_INFO)); -} - -// Frees memory of the motion vector information. -// Only called once in dealloc_compressor_data(). -static INLINE void free_motion_vector_info(struct VP9_COMP *cpi) { - vpx_free(cpi->motion_vector_info); - cpi->motion_vector_info = NULL; -} - -// Allocates memory for the tpl stats information. -// Only called once in vp9_create_compressor(). -static INLINE void tpl_stats_info_init(struct VP9_COMP *cpi) { - VP9_COMMON *const cm = &cpi->common; - CHECK_MEM_ERROR( - cm, cpi->tpl_stats_info, - (TplDepStats *)vpx_calloc(MAX_LAG_BUFFERS, sizeof(TplDepStats))); - memset(cpi->tpl_stats_info, 0, MAX_LAG_BUFFERS * sizeof(TplDepStats)); -} - -// Frees memory of the tpl stats information. -// Only called once in dealloc_compressor_data(). -static INLINE void free_tpl_stats_info(struct VP9_COMP *cpi) { - vpx_free(cpi->tpl_stats_info); - cpi->tpl_stats_info = NULL; -} - -// Allocates memory for the first pass motion vector information. -// The unit size is each 16x16 block. -// Only called once in vp9_create_compressor(). -static INLINE void fp_motion_vector_info_init(struct VP9_COMP *cpi) { - VP9_COMMON *const cm = &cpi->common; - const int unit_width = get_num_unit_16x16(cpi->frame_info.frame_width); - const int unit_height = get_num_unit_16x16(cpi->frame_info.frame_height); - CHECK_MEM_ERROR(cm, cpi->fp_motion_vector_info, - (MOTION_VECTOR_INFO *)vpx_calloc(unit_width * unit_height, - sizeof(MOTION_VECTOR_INFO))); -} - -static INLINE void fp_motion_vector_info_reset( - int frame_width, int frame_height, - MOTION_VECTOR_INFO *fp_motion_vector_info) { - const int unit_width = get_num_unit_16x16(frame_width); - const int unit_height = get_num_unit_16x16(frame_height); - int i; - for (i = 0; i < unit_width * unit_height; ++i) { - reset_mv_info(fp_motion_vector_info + i); - } -} - -// Frees memory of the first pass motion vector information. -// Only called once in dealloc_compressor_data(). -static INLINE void free_fp_motion_vector_info(struct VP9_COMP *cpi) { - vpx_free(cpi->fp_motion_vector_info); - cpi->fp_motion_vector_info = NULL; -} - -// This is the c-version counter part of ImageBuffer -typedef struct IMAGE_BUFFER { - int allocated; - int plane_width[3]; - int plane_height[3]; - uint8_t *plane_buffer[3]; -} IMAGE_BUFFER; - -#define RATE_CTRL_MAX_RECODE_NUM 7 - -typedef struct RATE_QINDEX_HISTORY { - int recode_count; - int q_index_history[RATE_CTRL_MAX_RECODE_NUM]; - int rate_history[RATE_CTRL_MAX_RECODE_NUM]; - int q_index_high; - int q_index_low; -} RATE_QINDEX_HISTORY; - -#endif // CONFIG_RATE_CTRL - typedef struct ENCODE_FRAME_RESULT { int show_idx; FRAME_UPDATE_TYPE update_type; -#if CONFIG_RATE_CTRL - int frame_coding_index; - int ref_frame_coding_indexes[MAX_INTER_REF_FRAMES]; - int ref_frame_valid_list[MAX_INTER_REF_FRAMES]; - double psnr; - uint64_t sse; - FRAME_COUNTS frame_counts; - const PARTITION_INFO *partition_info; - const MOTION_VECTOR_INFO *motion_vector_info; - const TplDepStats *tpl_stats_info; - IMAGE_BUFFER coded_frame; - RATE_QINDEX_HISTORY rq_history; -#endif // CONFIG_RATE_CTRL int quantize_index; } ENCODE_FRAME_RESULT; @@ -1113,7 +937,6 @@ void vp9_init_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result); void vp9_initialize_enc(void); -void vp9_update_compressor_with_img_fmt(VP9_COMP *cpi, vpx_img_fmt_t img_fmt); struct VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf, BufferPool *const pool); void vp9_remove_compressor(VP9_COMP *cpi); @@ -1127,8 +950,8 @@ int vp9_receive_raw_frame(VP9_COMP *cpi, vpx_enc_frame_flags_t frame_flags, int64_t end_time); int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, - size_t *size, uint8_t *dest, int64_t *time_stamp, - int64_t *time_end, int flush, + size_t *size, uint8_t *dest, size_t dest_size, + int64_t *time_stamp, int64_t *time_end, int flush, ENCODE_FRAME_RESULT *encode_frame_result); int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest, @@ -1152,8 +975,8 @@ int vp9_set_active_map(VP9_COMP *cpi, unsigned char *new_map_16x16, int rows, int vp9_get_active_map(VP9_COMP *cpi, unsigned char *new_map_16x16, int rows, int cols); -int vp9_set_internal_size(VP9_COMP *cpi, VPX_SCALING horiz_mode, - VPX_SCALING vert_mode); +int vp9_set_internal_size(VP9_COMP *cpi, VPX_SCALING_MODE horiz_mode, + VPX_SCALING_MODE vert_mode); int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width, unsigned int height); @@ -1245,18 +1068,24 @@ static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer( : NULL; } -static INLINE int get_token_alloc(int mb_rows, int mb_cols) { +static INLINE int64_t get_token_alloc(int mb_rows, int mb_cols) { // TODO(JBB): double check we can't exceed this token count if we have a // 32x32 transform crossing a boundary at a multiple of 16. // mb_rows, cols are in units of 16 pixels. We assume 3 planes all at full // resolution. We assume up to 1 token per pixel, and then allow // a head room of 4. - return mb_rows * mb_cols * (16 * 16 * 3 + 4); + + // Use aligned mb_rows and mb_cols to better align with actual token sizes. + const int aligned_mb_rows = + ALIGN_POWER_OF_TWO(mb_rows, MI_BLOCK_SIZE_LOG2 - 1); + const int aligned_mb_cols = + ALIGN_POWER_OF_TWO(mb_cols, MI_BLOCK_SIZE_LOG2 - 1); + return (int64_t)aligned_mb_rows * aligned_mb_cols * (16 * 16 * 3 + 4); } // Get the allocated token size for a tile. It does the same calculation as in // the frame token allocation. -static INLINE int allocated_tokens(TileInfo tile) { +static INLINE int64_t allocated_tokens(TileInfo tile) { int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1; int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1; @@ -1294,10 +1123,13 @@ void vp9_get_ref_frame_info(FRAME_UPDATE_TYPE update_type, int ref_frame_flags, void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv); -YV12_BUFFER_CONFIG *vp9_svc_twostage_scale( - VP9_COMMON *cm, YV12_BUFFER_CONFIG *unscaled, YV12_BUFFER_CONFIG *scaled, - YV12_BUFFER_CONFIG *scaled_temp, INTERP_FILTER filter_type, - int phase_scaler, INTERP_FILTER filter_type2, int phase_scaler2); +#if CONFIG_VP9_HIGHBITDEPTH +void vp9_scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src, + YV12_BUFFER_CONFIG *dst, int bd); +#else +void vp9_scale_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src, + YV12_BUFFER_CONFIG *dst); +#endif // CONFIG_VP9_HIGHBITDEPTH YV12_BUFFER_CONFIG *vp9_scale_if_required( VP9_COMMON *cm, YV12_BUFFER_CONFIG *unscaled, YV12_BUFFER_CONFIG *scaled, @@ -1305,7 +1137,7 @@ YV12_BUFFER_CONFIG *vp9_scale_if_required( void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags); -static INLINE int is_one_pass_cbr_svc(const struct VP9_COMP *const cpi) { +static INLINE int is_one_pass_svc(const struct VP9_COMP *const cpi) { return (cpi->use_svc && cpi->oxcf.pass == 0); } @@ -1367,7 +1199,7 @@ static INLINE int log_tile_cols_from_picsize_level(uint32_t width, int i; const uint32_t pic_size = width * height; const uint32_t pic_breadth = VPXMAX(width, height); - for (i = LEVEL_1; i < LEVEL_MAX; ++i) { + for (i = 0; i < VP9_LEVELS; ++i) { if (vp9_level_defs[i].max_luma_picture_size >= pic_size && vp9_level_defs[i].max_luma_picture_breadth >= pic_breadth) { return get_msb(vp9_level_defs[i].max_col_tiles); @@ -1378,9 +1210,10 @@ static INLINE int log_tile_cols_from_picsize_level(uint32_t width, VP9_LEVEL vp9_get_level(const Vp9LevelSpec *const level_spec); -int vp9_set_roi_map(VP9_COMP *cpi, unsigned char *map, unsigned int rows, - unsigned int cols, int delta_q[8], int delta_lf[8], - int skip[8], int ref_frame[8]); +vpx_codec_err_t vp9_set_roi_map(VP9_COMP *cpi, unsigned char *map, + unsigned int rows, unsigned int cols, + int delta_q[8], int delta_lf[8], int skip[8], + int ref_frame[8]); void vp9_new_framerate(VP9_COMP *cpi, double framerate); @@ -1390,6 +1223,171 @@ int vp9_get_psnr(const VP9_COMP *cpi, PSNR_STATS *psnr); #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl)) +static INLINE void alloc_frame_mvs(VP9_COMMON *const cm, int buffer_idx) { + RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; + if (new_fb_ptr->mvs == NULL || new_fb_ptr->mi_rows < cm->mi_rows || + new_fb_ptr->mi_cols < cm->mi_cols) { + vpx_free(new_fb_ptr->mvs); + CHECK_MEM_ERROR(&cm->error, new_fb_ptr->mvs, + (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols, + sizeof(*new_fb_ptr->mvs))); + new_fb_ptr->mi_rows = cm->mi_rows; + new_fb_ptr->mi_cols = cm->mi_cols; + } +} + +static INLINE int mv_cost(const MV *mv, const int *joint_cost, + int *const comp_cost[2]) { + assert(mv->row >= -MV_MAX && mv->row < MV_MAX); + assert(mv->col >= -MV_MAX && mv->col < MV_MAX); + return joint_cost[vp9_get_mv_joint(mv)] + comp_cost[0][mv->row] + + comp_cost[1][mv->col]; +} + +static INLINE int mvsad_err_cost(const MACROBLOCK *x, const MV *mv, + const MV *ref, int sad_per_bit) { + MV diff; + diff.row = mv->row - ref->row; + diff.col = mv->col - ref->col; + return ROUND_POWER_OF_TWO( + (unsigned)mv_cost(&diff, x->nmvjointsadcost, x->nmvsadcost) * sad_per_bit, + VP9_PROB_COST_SHIFT); +} + +static INLINE uint32_t get_start_mv_sad(const MACROBLOCK *x, const MV *mvp_full, + const MV *ref_mv_full, + vpx_sad_fn_t sad_fn_ptr, int sadpb) { + const int src_buf_stride = x->plane[0].src.stride; + const uint8_t *const src_buf = x->plane[0].src.buf; + const MACROBLOCKD *const xd = &x->e_mbd; + const int pred_buf_stride = xd->plane[0].pre[0].stride; + const uint8_t *const pred_buf = + xd->plane[0].pre[0].buf + mvp_full->row * pred_buf_stride + mvp_full->col; + uint32_t start_mv_sad = + sad_fn_ptr(src_buf, src_buf_stride, pred_buf, pred_buf_stride); + start_mv_sad += mvsad_err_cost(x, mvp_full, ref_mv_full, sadpb); + + return start_mv_sad; +} + +static INLINE int num_4x4_to_edge(int plane_4x4_dim, int mb_to_edge_dim, + int subsampling_dim, int blk_dim) { + return plane_4x4_dim + (mb_to_edge_dim >> (5 + subsampling_dim)) - blk_dim; +} + +// Compute the sum of squares on all visible 4x4s in the transform block. +static int64_t sum_squares_visible(const MACROBLOCKD *xd, + const struct macroblockd_plane *const pd, + const int16_t *diff, const int diff_stride, + int blk_row, int blk_col, + const BLOCK_SIZE plane_bsize, + const BLOCK_SIZE tx_bsize, + int *visible_width, int *visible_height) { + int64_t sse; + const int plane_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize]; + const int plane_4x4_h = num_4x4_blocks_high_lookup[plane_bsize]; + const int tx_4x4_w = num_4x4_blocks_wide_lookup[tx_bsize]; + const int tx_4x4_h = num_4x4_blocks_high_lookup[tx_bsize]; + const int b4x4s_to_right_edge = num_4x4_to_edge( + plane_4x4_w, xd->mb_to_right_edge, pd->subsampling_x, blk_col); + const int b4x4s_to_bottom_edge = num_4x4_to_edge( + plane_4x4_h, xd->mb_to_bottom_edge, pd->subsampling_y, blk_row); + if (tx_bsize == BLOCK_4X4 || + (b4x4s_to_right_edge >= tx_4x4_w && b4x4s_to_bottom_edge >= tx_4x4_h)) { + assert(tx_4x4_w == tx_4x4_h); + sse = (int64_t)vpx_sum_squares_2d_i16(diff, diff_stride, tx_4x4_w << 2); + *visible_width = tx_4x4_w << 2; + *visible_height = tx_4x4_h << 2; + } else { + int r, c; + const int max_r = VPXMIN(b4x4s_to_bottom_edge, tx_4x4_h); + const int max_c = VPXMIN(b4x4s_to_right_edge, tx_4x4_w); + sse = 0; + // if we are in the unrestricted motion border. + for (r = 0; r < max_r; ++r) { + // Skip visiting the sub blocks that are wholly within the UMV. + for (c = 0; c < max_c; ++c) { + sse += (int64_t)vpx_sum_squares_2d_i16( + diff + r * diff_stride * 4 + c * 4, diff_stride, 4); + } + } + *visible_width = max_c << 2; + *visible_height = max_r << 2; + } + return sse; +} + +// Check if trellis coefficient optimization of the transform block is enabled. +static INLINE int do_trellis_opt(const struct macroblockd_plane *pd, + const int16_t *src_diff, int diff_stride, + int blk_row, int blk_col, + BLOCK_SIZE plane_bsize, TX_SIZE tx_size, + void *arg) { + const struct encode_b_args *const args = (struct encode_b_args *)arg; + const MACROBLOCK *const x = args->x; + + switch (args->enable_trellis_opt) { + case DISABLE_TRELLIS_OPT: return 0; + case ENABLE_TRELLIS_OPT: return 1; + case ENABLE_TRELLIS_OPT_TX_RD_SRC_VAR: { + vpx_clear_system_state(); + + return (args->trellis_opt_thresh > 0.0) + ? (x->log_block_src_var <= args->trellis_opt_thresh) + : 1; + } + case ENABLE_TRELLIS_OPT_TX_RD_RESIDUAL_MSE: { + const MACROBLOCKD *const xd = &x->e_mbd; + const BLOCK_SIZE tx_bsize = txsize_to_bsize[tx_size]; +#if CONFIG_VP9_HIGHBITDEPTH + const int dequant_shift = + (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ? xd->bd - 5 : 3; +#else + const int dequant_shift = 3; +#endif // CONFIG_VP9_HIGHBITDEPTH + const int qstep = pd->dequant[1] >> dequant_shift; + int *sse_calc_done = args->sse_calc_done; + int64_t *sse = args->sse; + int visible_width = 0, visible_height = 0; + + // TODO: Enable the sf for high bit-depth case + if ((xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) || !sse || + !sse_calc_done) + return 1; + + *sse = sum_squares_visible(xd, pd, src_diff, diff_stride, blk_row, + blk_col, plane_bsize, tx_bsize, &visible_width, + &visible_height); + *sse_calc_done = 1; + + vpx_clear_system_state(); + + return (*(sse) <= (int64_t)visible_width * visible_height * qstep * + qstep * args->trellis_opt_thresh); + } + default: assert(0 && "Invalid trellis optimization method."); return 1; + } +} + +#if CONFIG_COLLECT_COMPONENT_TIMING +static INLINE void start_timing(VP9_COMP *cpi, int component) { + vpx_usec_timer_start(&cpi->component_timer[component]); +} +static INLINE void end_timing(VP9_COMP *cpi, int component) { + vpx_usec_timer_mark(&cpi->component_timer[component]); + cpi->frame_component_time[component] += + vpx_usec_timer_elapsed(&cpi->component_timer[component]); +} +static INLINE char const *get_frame_type_enum(int type) { + switch (type) { + case 0: return "KEY_FRAME"; + case 1: return "INTER_FRAME"; + default: assert(0); + } + return "error"; +} +#endif + #ifdef __cplusplus } // extern "C" #endif diff --git a/libs/libvpx/vp9/encoder/vp9_ethread.c b/libs/libvpx/vp9/encoder/vp9_ethread.c index 453fe2e0df..efe47259ef 100644 --- a/libs/libvpx/vp9/encoder/vp9_ethread.c +++ b/libs/libvpx/vp9/encoder/vp9_ethread.c @@ -17,6 +17,7 @@ #include "vp9/encoder/vp9_multi_thread.h" #include "vp9/encoder/vp9_temporal_filter.h" #include "vpx_dsp/vpx_dsp_common.h" +#include "vpx_util/vpx_pthread.h" static void accumulate_rd_opt(ThreadData *td, ThreadData *td_t) { int i, j, k, l, m, n; @@ -55,7 +56,7 @@ static int enc_worker_hook(void *arg1, void *unused) { vp9_encode_tile(cpi, thread_data->td, tile_row, tile_col); } - return 0; + return 1; } static int get_max_tile_cols(VP9_COMP *cpi) { @@ -94,10 +95,10 @@ static void create_enc_workers(VP9_COMP *cpi, int num_workers) { vp9_bitstream_encode_tiles_buffer_dealloc(cpi); vp9_encode_free_mt_data(cpi); - CHECK_MEM_ERROR(cm, cpi->workers, + CHECK_MEM_ERROR(&cm->error, cpi->workers, vpx_malloc(num_workers * sizeof(*cpi->workers))); - CHECK_MEM_ERROR(cm, cpi->tile_thr_data, + CHECK_MEM_ERROR(&cm->error, cpi->tile_thr_data, vpx_calloc(num_workers, sizeof(*cpi->tile_thr_data))); for (i = 0; i < num_workers; i++) { @@ -106,12 +107,13 @@ static void create_enc_workers(VP9_COMP *cpi, int num_workers) { ++cpi->num_workers; winterface->init(worker); + worker->thread_name = "vpx enc worker"; if (i < num_workers - 1) { thread_data->cpi = cpi; // Allocate thread data. - CHECK_MEM_ERROR(cm, thread_data->td, + CHECK_MEM_ERROR(&cm->error, thread_data->td, vpx_memalign(32, sizeof(*thread_data->td))); vp9_zero(*thread_data->td); @@ -121,7 +123,7 @@ static void create_enc_workers(VP9_COMP *cpi, int num_workers) { vp9_setup_pc_tree(cm, thread_data->td); // Allocate frame counters in thread data. - CHECK_MEM_ERROR(cm, thread_data->td->counts, + CHECK_MEM_ERROR(&cm->error, thread_data->td->counts, vpx_calloc(1, sizeof(*thread_data->td->counts))); // Create threads @@ -187,7 +189,9 @@ void vp9_encode_free_mt_data(struct VP9_COMP *cpi) { } } vpx_free(cpi->tile_thr_data); + cpi->tile_thr_data = NULL; vpx_free(cpi->workers); + cpi->workers = NULL; cpi->num_workers = 0; } @@ -202,8 +206,7 @@ void vp9_encode_tiles_mt(VP9_COMP *cpi) { create_enc_workers(cpi, num_workers); for (i = 0; i < num_workers; i++) { - EncWorkerData *thread_data; - thread_data = &cpi->tile_thr_data[i]; + EncWorkerData *const thread_data = &cpi->tile_thr_data[i]; // Before encoding a frame, copy the thread data from cpi. if (thread_data->td != &cpi->td) { @@ -265,6 +268,7 @@ static void accumulate_fp_tile_stat(TileDataEnc *tile_data, tile_data->fp_data.intra_count_high += tile_data_t->fp_data.intra_count_high; tile_data->fp_data.intra_skip_count += tile_data_t->fp_data.intra_skip_count; tile_data->fp_data.mvcount += tile_data_t->fp_data.mvcount; + tile_data->fp_data.new_mv_count += tile_data_t->fp_data.new_mv_count; tile_data->fp_data.sum_mvr += tile_data_t->fp_data.sum_mvr; tile_data->fp_data.sum_mvr_abs += tile_data_t->fp_data.sum_mvr_abs; tile_data->fp_data.sum_mvc += tile_data_t->fp_data.sum_mvc; @@ -274,13 +278,13 @@ static void accumulate_fp_tile_stat(TileDataEnc *tile_data, tile_data->fp_data.sum_in_vectors += tile_data_t->fp_data.sum_in_vectors; tile_data->fp_data.intra_smooth_count += tile_data_t->fp_data.intra_smooth_count; + const int min_start_row = VPXMIN(tile_data->fp_data.image_data_start_row, + tile_data_t->fp_data.image_data_start_row); tile_data->fp_data.image_data_start_row = - VPXMIN(tile_data->fp_data.image_data_start_row, - tile_data_t->fp_data.image_data_start_row) == INVALID_ROW + (min_start_row == INVALID_ROW) ? VPXMAX(tile_data->fp_data.image_data_start_row, tile_data_t->fp_data.image_data_start_row) - : VPXMIN(tile_data->fp_data.image_data_start_row, - tile_data_t->fp_data.image_data_start_row); + : min_start_row; } #endif // !CONFIG_REALTIME_ONLY @@ -292,7 +296,7 @@ void vp9_row_mt_sync_mem_alloc(VP9RowMTSync *row_mt_sync, VP9_COMMON *cm, { int i; - CHECK_MEM_ERROR(cm, row_mt_sync->mutex, + CHECK_MEM_ERROR(&cm->error, row_mt_sync->mutex, vpx_malloc(sizeof(*row_mt_sync->mutex) * rows)); if (row_mt_sync->mutex) { for (i = 0; i < rows; ++i) { @@ -300,7 +304,7 @@ void vp9_row_mt_sync_mem_alloc(VP9RowMTSync *row_mt_sync, VP9_COMMON *cm, } } - CHECK_MEM_ERROR(cm, row_mt_sync->cond, + CHECK_MEM_ERROR(&cm->error, row_mt_sync->cond, vpx_malloc(sizeof(*row_mt_sync->cond) * rows)); if (row_mt_sync->cond) { for (i = 0; i < rows; ++i) { @@ -310,7 +314,7 @@ void vp9_row_mt_sync_mem_alloc(VP9RowMTSync *row_mt_sync, VP9_COMMON *cm, } #endif // CONFIG_MULTITHREAD - CHECK_MEM_ERROR(cm, row_mt_sync->cur_col, + CHECK_MEM_ERROR(&cm->error, row_mt_sync->cur_col, vpx_malloc(sizeof(*row_mt_sync->cur_col) * rows)); // Set up nsync. @@ -453,7 +457,7 @@ static int first_pass_worker_hook(void *arg1, void *arg2) { this_tile, &best_ref_mv, mb_row); } } - return 0; + return 1; } void vp9_encode_fp_row_mt(VP9_COMP *cpi) { @@ -540,7 +544,7 @@ static int temporal_filter_worker_hook(void *arg1, void *arg2) { mb_col_start, mb_col_end); } } - return 0; + return 1; } void vp9_temporal_filter_row_mt(VP9_COMP *cpi) { @@ -613,7 +617,7 @@ static int enc_row_mt_worker_hook(void *arg1, void *arg2) { vp9_encode_sb_row(cpi, thread_data->td, tile_row, tile_col, mi_row); } } - return 0; + return 1; } void vp9_encode_tiles_row_mt(VP9_COMP *cpi) { diff --git a/libs/libvpx/vp9/encoder/vp9_ethread.h b/libs/libvpx/vp9/encoder/vp9_ethread.h index 4c192da515..46478bef9f 100644 --- a/libs/libvpx/vp9/encoder/vp9_ethread.h +++ b/libs/libvpx/vp9/encoder/vp9_ethread.h @@ -11,13 +11,15 @@ #ifndef VPX_VP9_ENCODER_VP9_ETHREAD_H_ #define VPX_VP9_ENCODER_VP9_ETHREAD_H_ +#include "vpx_util/vpx_pthread.h" + #ifdef __cplusplus extern "C" { #endif #define MAX_NUM_TILE_COLS (1 << 6) #define MAX_NUM_TILE_ROWS 4 -#define MAX_NUM_THREADS 80 +#define MAX_NUM_THREADS 64 struct VP9_COMP; struct ThreadData; diff --git a/libs/libvpx/vp9/encoder/vp9_ext_ratectrl.c b/libs/libvpx/vp9/encoder/vp9_ext_ratectrl.c index 9f0098ab5a..e8cc006b1e 100644 --- a/libs/libvpx/vp9/encoder/vp9_ext_ratectrl.c +++ b/libs/libvpx/vp9/encoder/vp9_ext_ratectrl.c @@ -8,10 +8,16 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include +#include + #include "vp9/encoder/vp9_ext_ratectrl.h" #include "vp9/encoder/vp9_encoder.h" #include "vp9/common/vp9_common.h" #include "vpx_dsp/psnr.h" +#include "vpx/vpx_codec.h" +#include "vpx/vpx_ext_ratectrl.h" +#include "vpx/vpx_tpl.h" vpx_codec_err_t vp9_extrc_init(EXT_RATECTRL *ext_ratectrl) { if (ext_ratectrl == NULL) { @@ -46,6 +52,14 @@ vpx_codec_err_t vp9_extrc_create(vpx_rc_funcs_t funcs, if (rc_firstpass_stats->frame_stats == NULL) { return VPX_CODEC_MEM_ERROR; } + if (funcs.rate_ctrl_log_path != NULL) { + ext_ratectrl->log_file = fopen(funcs.rate_ctrl_log_path, "w"); + if (!ext_ratectrl->log_file) { + return VPX_CODEC_ERROR; + } + } else { + ext_ratectrl->log_file = NULL; + } ext_ratectrl->ready = 1; return VPX_CODEC_OK; } @@ -55,6 +69,9 @@ vpx_codec_err_t vp9_extrc_delete(EXT_RATECTRL *ext_ratectrl) { return VPX_CODEC_INVALID_PARAM; } if (ext_ratectrl->ready) { + if (ext_ratectrl->log_file) { + fclose(ext_ratectrl->log_file); + } vpx_rc_status_t rc_status = ext_ratectrl->funcs.delete_model(ext_ratectrl->model); if (rc_status == VPX_RC_ERROR) { @@ -92,6 +109,7 @@ static void gen_rc_firstpass_stats(const FIRSTPASS_STATS *stats, rc_frame_stats->mv_in_out_count = stats->mv_in_out_count; rc_frame_stats->duration = stats->duration; rc_frame_stats->count = stats->count; + rc_frame_stats->new_mv_count = stats->new_mv_count; } vpx_codec_err_t vp9_extrc_send_firstpass_stats( @@ -118,6 +136,21 @@ vpx_codec_err_t vp9_extrc_send_firstpass_stats( return VPX_CODEC_OK; } +vpx_codec_err_t vp9_extrc_send_tpl_stats(EXT_RATECTRL *ext_ratectrl, + const VpxTplGopStats *tpl_gop_stats) { + if (ext_ratectrl == NULL) { + return VPX_CODEC_INVALID_PARAM; + } + if (ext_ratectrl->ready && ext_ratectrl->funcs.send_tpl_gop_stats != NULL) { + vpx_rc_status_t rc_status = ext_ratectrl->funcs.send_tpl_gop_stats( + ext_ratectrl->model, tpl_gop_stats); + if (rc_status == VPX_RC_ERROR) { + return VPX_CODEC_ERROR; + } + } + return VPX_CODEC_OK; +} + static int extrc_get_frame_type(FRAME_UPDATE_TYPE update_type) { // TODO(angiebird): Add unit test to make sure this function behaves like // get_frame_type_from_update_type() @@ -131,65 +164,33 @@ static int extrc_get_frame_type(FRAME_UPDATE_TYPE update_type) { default: fprintf(stderr, "Unsupported update_type %d\n", update_type); abort(); - return 1; } } vpx_codec_err_t vp9_extrc_get_encodeframe_decision( - EXT_RATECTRL *ext_ratectrl, int show_index, int coding_index, int gop_index, - FRAME_UPDATE_TYPE update_type, - RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES], int ref_frame_flags, + EXT_RATECTRL *ext_ratectrl, int gop_index, vpx_rc_encodeframe_decision_t *encode_frame_decision) { - if (ext_ratectrl == NULL) { - return VPX_CODEC_INVALID_PARAM; - } - if (ext_ratectrl->ready) { - vpx_rc_status_t rc_status; - vpx_rc_encodeframe_info_t encode_frame_info; - encode_frame_info.show_index = show_index; - encode_frame_info.coding_index = coding_index; - encode_frame_info.gop_index = gop_index; - encode_frame_info.frame_type = extrc_get_frame_type(update_type); + assert(ext_ratectrl != NULL); + assert(ext_ratectrl->ready && (ext_ratectrl->funcs.rc_type & VPX_RC_QP) != 0); - vp9_get_ref_frame_info(update_type, ref_frame_flags, ref_frame_bufs, - encode_frame_info.ref_frame_coding_indexes, - encode_frame_info.ref_frame_valid_list); - - rc_status = ext_ratectrl->funcs.get_encodeframe_decision( - ext_ratectrl->model, &encode_frame_info, encode_frame_decision); - if (rc_status == VPX_RC_ERROR) { - return VPX_CODEC_ERROR; - } + vpx_rc_status_t rc_status = ext_ratectrl->funcs.get_encodeframe_decision( + ext_ratectrl->model, gop_index, encode_frame_decision); + if (rc_status == VPX_RC_ERROR) { + return VPX_CODEC_ERROR; } return VPX_CODEC_OK; } vpx_codec_err_t vp9_extrc_update_encodeframe_result( - EXT_RATECTRL *ext_ratectrl, int64_t bit_count, - const YV12_BUFFER_CONFIG *source_frame, - const YV12_BUFFER_CONFIG *coded_frame, uint32_t bit_depth, - uint32_t input_bit_depth, const int actual_encoding_qindex) { + EXT_RATECTRL *ext_ratectrl, int64_t bit_count, int actual_encoding_qindex) { if (ext_ratectrl == NULL) { return VPX_CODEC_INVALID_PARAM; } if (ext_ratectrl->ready) { - PSNR_STATS psnr; vpx_rc_status_t rc_status; vpx_rc_encodeframe_result_t encode_frame_result; encode_frame_result.bit_count = bit_count; - encode_frame_result.pixel_count = - source_frame->y_crop_width * source_frame->y_crop_height + - 2 * source_frame->uv_crop_width * source_frame->uv_crop_height; encode_frame_result.actual_encoding_qindex = actual_encoding_qindex; -#if CONFIG_VP9_HIGHBITDEPTH - vpx_calc_highbd_psnr(source_frame, coded_frame, &psnr, bit_depth, - input_bit_depth); -#else - (void)bit_depth; - (void)input_bit_depth; - vpx_calc_psnr(source_frame, coded_frame, &psnr); -#endif - encode_frame_result.sse = psnr.sse[0]; rc_status = ext_ratectrl->funcs.update_encodeframe_result( ext_ratectrl->model, &encode_frame_result); if (rc_status == VPX_RC_ERROR) { @@ -198,3 +199,59 @@ vpx_codec_err_t vp9_extrc_update_encodeframe_result( } return VPX_CODEC_OK; } + +vpx_codec_err_t vp9_extrc_get_gop_decision( + EXT_RATECTRL *ext_ratectrl, vpx_rc_gop_decision_t *gop_decision) { + vpx_rc_status_t rc_status; + if (ext_ratectrl == NULL || !ext_ratectrl->ready || + (ext_ratectrl->funcs.rc_type & VPX_RC_GOP) == 0) { + return VPX_CODEC_INVALID_PARAM; + } + rc_status = + ext_ratectrl->funcs.get_gop_decision(ext_ratectrl->model, gop_decision); + if (rc_status == VPX_RC_ERROR) { + return VPX_CODEC_ERROR; + } + return VPX_CODEC_OK; +} + +vpx_codec_err_t vp9_extrc_get_key_frame_decision( + EXT_RATECTRL *ext_ratectrl, + vpx_rc_key_frame_decision_t *key_frame_decision) { + if (ext_ratectrl == NULL || !ext_ratectrl->ready || + (ext_ratectrl->funcs.rc_type & VPX_RC_GOP) == 0) { + return VPX_CODEC_INVALID_PARAM; + } + vpx_rc_status_t rc_status = ext_ratectrl->funcs.get_key_frame_decision( + ext_ratectrl->model, key_frame_decision); + return rc_status == VPX_RC_OK ? VPX_CODEC_OK : VPX_CODEC_ERROR; +} + +vpx_codec_err_t vp9_extrc_get_frame_rdmult( + EXT_RATECTRL *ext_ratectrl, int show_index, int coding_index, int gop_index, + FRAME_UPDATE_TYPE update_type, int gop_size, int use_alt_ref, + RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES], int ref_frame_flags, + int *rdmult) { + vpx_rc_status_t rc_status; + vpx_rc_encodeframe_info_t encode_frame_info; + if (ext_ratectrl == NULL || !ext_ratectrl->ready || + (ext_ratectrl->funcs.rc_type & VPX_RC_RDMULT) == 0) { + return VPX_CODEC_INVALID_PARAM; + } + encode_frame_info.show_index = show_index; + encode_frame_info.coding_index = coding_index; + encode_frame_info.gop_index = gop_index; + encode_frame_info.frame_type = extrc_get_frame_type(update_type); + encode_frame_info.gop_size = gop_size; + encode_frame_info.use_alt_ref = use_alt_ref; + + vp9_get_ref_frame_info(update_type, ref_frame_flags, ref_frame_bufs, + encode_frame_info.ref_frame_coding_indexes, + encode_frame_info.ref_frame_valid_list); + rc_status = ext_ratectrl->funcs.get_frame_rdmult(ext_ratectrl->model, + &encode_frame_info, rdmult); + if (rc_status == VPX_RC_ERROR) { + return VPX_CODEC_ERROR; + } + return VPX_CODEC_OK; +} diff --git a/libs/libvpx/vp9/encoder/vp9_ext_ratectrl.h b/libs/libvpx/vp9/encoder/vp9_ext_ratectrl.h index 74fd68b96d..4ea1b24646 100644 --- a/libs/libvpx/vp9/encoder/vp9_ext_ratectrl.h +++ b/libs/libvpx/vp9/encoder/vp9_ext_ratectrl.h @@ -12,14 +12,17 @@ #define VPX_VP9_ENCODER_VP9_EXT_RATECTRL_H_ #include "vpx/vpx_ext_ratectrl.h" +#include "vpx/vpx_tpl.h" #include "vp9/encoder/vp9_firstpass.h" typedef struct EXT_RATECTRL { int ready; + int ext_rdmult; vpx_rc_model_t model; vpx_rc_funcs_t funcs; vpx_rc_config_t ratectrl_config; vpx_rc_firstpass_stats_t rc_firstpass_stats; + FILE *log_file; } EXT_RATECTRL; vpx_codec_err_t vp9_extrc_init(EXT_RATECTRL *ext_ratectrl); @@ -33,16 +36,28 @@ vpx_codec_err_t vp9_extrc_delete(EXT_RATECTRL *ext_ratectrl); vpx_codec_err_t vp9_extrc_send_firstpass_stats( EXT_RATECTRL *ext_ratectrl, const FIRST_PASS_INFO *first_pass_info); +vpx_codec_err_t vp9_extrc_send_tpl_stats(EXT_RATECTRL *ext_ratectrl, + const VpxTplGopStats *tpl_gop_stats); + vpx_codec_err_t vp9_extrc_get_encodeframe_decision( - EXT_RATECTRL *ext_ratectrl, int show_index, int coding_index, int gop_index, - FRAME_UPDATE_TYPE update_type, - RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES], int ref_frame_flags, + EXT_RATECTRL *ext_ratectrl, int gop_index, vpx_rc_encodeframe_decision_t *encode_frame_decision); -vpx_codec_err_t vp9_extrc_update_encodeframe_result( - EXT_RATECTRL *ext_ratectrl, int64_t bit_count, - const YV12_BUFFER_CONFIG *source_frame, - const YV12_BUFFER_CONFIG *coded_frame, uint32_t bit_depth, - uint32_t input_bit_depth, const int actual_encoding_qindex); +vpx_codec_err_t vp9_extrc_update_encodeframe_result(EXT_RATECTRL *ext_ratectrl, + int64_t bit_count, + int actual_encoding_qindex); + +vpx_codec_err_t vp9_extrc_get_key_frame_decision( + EXT_RATECTRL *ext_ratectrl, + vpx_rc_key_frame_decision_t *key_frame_decision); + +vpx_codec_err_t vp9_extrc_get_gop_decision(EXT_RATECTRL *ext_ratectrl, + vpx_rc_gop_decision_t *gop_decision); + +vpx_codec_err_t vp9_extrc_get_frame_rdmult( + EXT_RATECTRL *ext_ratectrl, int show_index, int coding_index, int gop_index, + FRAME_UPDATE_TYPE update_type, int gop_size, int use_alt_ref, + RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES], int ref_frame_flags, + int *rdmult); #endif // VPX_VP9_ENCODER_VP9_EXT_RATECTRL_H_ diff --git a/libs/libvpx/vp9/encoder/vp9_extend.c b/libs/libvpx/vp9/encoder/vp9_extend.c index dcb62e8768..69261ac65f 100644 --- a/libs/libvpx/vp9/encoder/vp9_extend.c +++ b/libs/libvpx/vp9/encoder/vp9_extend.c @@ -162,42 +162,3 @@ void vp9_copy_and_extend_frame(const YV12_BUFFER_CONFIG *src, dst->uv_stride, src->uv_crop_width, src->uv_crop_height, et_uv, el_uv, eb_uv, er_uv, chroma_step); } - -void vp9_copy_and_extend_frame_with_rect(const YV12_BUFFER_CONFIG *src, - YV12_BUFFER_CONFIG *dst, int srcy, - int srcx, int srch, int srcw) { - // If the side is not touching the bounder then don't extend. - const int et_y = srcy ? 0 : dst->border; - const int el_y = srcx ? 0 : dst->border; - const int eb_y = srcy + srch != src->y_height - ? 0 - : dst->border + dst->y_height - src->y_height; - const int er_y = srcx + srcw != src->y_width - ? 0 - : dst->border + dst->y_width - src->y_width; - const int src_y_offset = srcy * src->y_stride + srcx; - const int dst_y_offset = srcy * dst->y_stride + srcx; - - const int et_uv = ROUND_POWER_OF_TWO(et_y, 1); - const int el_uv = ROUND_POWER_OF_TWO(el_y, 1); - const int eb_uv = ROUND_POWER_OF_TWO(eb_y, 1); - const int er_uv = ROUND_POWER_OF_TWO(er_y, 1); - const int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1); - const int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1); - const int srch_uv = ROUND_POWER_OF_TWO(srch, 1); - const int srcw_uv = ROUND_POWER_OF_TWO(srcw, 1); - // detect nv12 colorspace - const int chroma_step = src->v_buffer - src->u_buffer == 1 ? 2 : 1; - - copy_and_extend_plane(src->y_buffer + src_y_offset, src->y_stride, - dst->y_buffer + dst_y_offset, dst->y_stride, srcw, srch, - et_y, el_y, eb_y, er_y, 1); - - copy_and_extend_plane(src->u_buffer + src_uv_offset, src->uv_stride, - dst->u_buffer + dst_uv_offset, dst->uv_stride, srcw_uv, - srch_uv, et_uv, el_uv, eb_uv, er_uv, chroma_step); - - copy_and_extend_plane(src->v_buffer + src_uv_offset, src->uv_stride, - dst->v_buffer + dst_uv_offset, dst->uv_stride, srcw_uv, - srch_uv, et_uv, el_uv, eb_uv, er_uv, chroma_step); -} diff --git a/libs/libvpx/vp9/encoder/vp9_extend.h b/libs/libvpx/vp9/encoder/vp9_extend.h index 4ba7fc95e3..21d7e68b9f 100644 --- a/libs/libvpx/vp9/encoder/vp9_extend.h +++ b/libs/libvpx/vp9/encoder/vp9_extend.h @@ -21,9 +21,6 @@ extern "C" { void vp9_copy_and_extend_frame(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst); -void vp9_copy_and_extend_frame_with_rect(const YV12_BUFFER_CONFIG *src, - YV12_BUFFER_CONFIG *dst, int srcy, - int srcx, int srch, int srcw); #ifdef __cplusplus } // extern "C" #endif diff --git a/libs/libvpx/vp9/encoder/vp9_firstpass.c b/libs/libvpx/vp9/encoder/vp9_firstpass.c index 67302ed035..e5918a9bfe 100644 --- a/libs/libvpx/vp9/encoder/vp9_firstpass.c +++ b/libs/libvpx/vp9/encoder/vp9_firstpass.c @@ -10,6 +10,7 @@ #include #include +#include #include #include "./vpx_dsp_rtcd.h" @@ -33,10 +34,15 @@ #include "vp9/encoder/vp9_encoder.h" #include "vp9/encoder/vp9_ethread.h" #include "vp9/encoder/vp9_extend.h" +#include "vp9/encoder/vp9_ext_ratectrl.h" #include "vp9/encoder/vp9_firstpass.h" #include "vp9/encoder/vp9_mcomp.h" #include "vp9/encoder/vp9_quantize.h" +#include "vp9/encoder/vp9_ratectrl.h" #include "vp9/encoder/vp9_rd.h" +#include "vpx/internal/vpx_codec_internal.h" +#include "vpx/vpx_codec.h" +#include "vpx/vpx_ext_ratectrl.h" #include "vpx_dsp/variance.h" #define OUTPUT_FPF 0 @@ -78,7 +84,7 @@ #define HIGH_UNDERSHOOT_RATIO 2 #define AV_WQ_FACTOR 4.0 -#define DOUBLE_DIVIDE_CHECK(x) ((x) < 0 ? (x)-0.000001 : (x) + 0.000001) +#define DOUBLE_DIVIDE_CHECK(x) ((x) < 0 ? (x) - 0.000001 : (x) + 0.000001) #if ARF_STATS_OUTPUT unsigned int arf_count = 0; @@ -152,6 +158,7 @@ static void zero_stats(FIRSTPASS_STATS *section) { section->pcnt_intra_high = 0.0; section->inactive_zone_rows = 0.0; section->inactive_zone_cols = 0.0; + section->new_mv_count = 0.0; section->MVr = 0.0; section->mvr_abs = 0.0; section->MVc = 0.0; @@ -183,6 +190,7 @@ static void accumulate_stats(FIRSTPASS_STATS *section, section->pcnt_intra_high += frame->pcnt_intra_high; section->inactive_zone_rows += frame->inactive_zone_rows; section->inactive_zone_cols += frame->inactive_zone_cols; + section->new_mv_count += frame->new_mv_count; section->MVr += frame->MVr; section->mvr_abs += frame->mvr_abs; section->MVc += frame->MVc; @@ -212,6 +220,7 @@ static void subtract_stats(FIRSTPASS_STATS *section, section->pcnt_intra_high -= frame->pcnt_intra_high; section->inactive_zone_rows -= frame->inactive_zone_rows; section->inactive_zone_cols -= frame->inactive_zone_cols; + section->new_mv_count -= frame->new_mv_count; section->MVr -= frame->MVr; section->mvr_abs -= frame->mvr_abs; section->MVc -= frame->MVc; @@ -361,7 +370,6 @@ static vpx_variance_fn_t highbd_get_block_variance_fn(BLOCK_SIZE bsize, case BLOCK_8X16: return vpx_highbd_8_mse8x16; default: return vpx_highbd_8_mse16x16; } - break; case 10: switch (bsize) { case BLOCK_8X8: return vpx_highbd_10_mse8x8; @@ -369,7 +377,6 @@ static vpx_variance_fn_t highbd_get_block_variance_fn(BLOCK_SIZE bsize, case BLOCK_8X16: return vpx_highbd_10_mse8x16; default: return vpx_highbd_10_mse16x16; } - break; case 12: switch (bsize) { case BLOCK_8X8: return vpx_highbd_12_mse8x8; @@ -377,7 +384,6 @@ static vpx_variance_fn_t highbd_get_block_variance_fn(BLOCK_SIZE bsize, case BLOCK_8X16: return vpx_highbd_12_mse8x16; default: return vpx_highbd_12_mse16x16; } - break; } } @@ -396,7 +402,8 @@ static unsigned int highbd_get_prediction_error(BLOCK_SIZE bsize, // for first pass test. static int get_search_range(const VP9_COMP *cpi) { int sr = 0; - const int dim = VPXMIN(cpi->initial_width, cpi->initial_height); + int dim = VPXMIN(cpi->initial_width, cpi->initial_height); + dim = VPXMAX(dim, MI_SIZE); while ((dim << sr) < MAX_FULL_PEL_VAL) ++sr; return sr; @@ -435,6 +442,9 @@ static void first_pass_motion_search(VP9_COMP *cpi, MACROBLOCK *x, const BLOCK_SIZE bsize = xd->mi[0]->sb_type; vp9_variance_fn_ptr_t v_fn_ptr = cpi->fn_ptr[bsize]; const int new_mv_mode_penalty = NEW_MV_MODE_PENALTY; + MV center_mv_full = ref_mv_full; + unsigned int start_mv_sad; + vp9_sad_fn_ptr_t sad_fn_ptr; int step_param = 3; int further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param; @@ -455,10 +465,18 @@ static void first_pass_motion_search(VP9_COMP *cpi, MACROBLOCK *x, } #endif // CONFIG_VP9_HIGHBITDEPTH + // Calculate SAD of the start mv + clamp_mv(&ref_mv_full, x->mv_limits.col_min, x->mv_limits.col_max, + x->mv_limits.row_min, x->mv_limits.row_max); + start_mv_sad = get_start_mv_sad(x, &ref_mv_full, ¢er_mv_full, + cpi->fn_ptr[bsize].sdf, x->sadperbit16); + sad_fn_ptr.sdf = cpi->fn_ptr[bsize].sdf; + sad_fn_ptr.sdx4df = cpi->fn_ptr[bsize].sdx4df; + // Center the initial step/diamond search on best mv. - tmp_err = cpi->diamond_search_sad(x, &cpi->ss_cfg, &ref_mv_full, &tmp_mv, - step_param, x->sadperbit16, &num00, - &v_fn_ptr, ref_mv); + tmp_err = cpi->diamond_search_sad(x, &cpi->ss_cfg, &ref_mv_full, start_mv_sad, + &tmp_mv, step_param, x->sadperbit16, &num00, + &sad_fn_ptr, ref_mv); if (tmp_err < INT_MAX) tmp_err = vp9_get_mvpred_var(x, &tmp_mv, ref_mv, &v_fn_ptr, 1); if (tmp_err < INT_MAX - new_mv_mode_penalty) tmp_err += new_mv_mode_penalty; @@ -478,9 +496,9 @@ static void first_pass_motion_search(VP9_COMP *cpi, MACROBLOCK *x, if (num00) { --num00; } else { - tmp_err = cpi->diamond_search_sad(x, &cpi->ss_cfg, &ref_mv_full, &tmp_mv, - step_param + n, x->sadperbit16, &num00, - &v_fn_ptr, ref_mv); + tmp_err = cpi->diamond_search_sad( + x, &cpi->ss_cfg, &ref_mv_full, start_mv_sad, &tmp_mv, step_param + n, + x->sadperbit16, &num00, &sad_fn_ptr, ref_mv); if (tmp_err < INT_MAX) tmp_err = vp9_get_mvpred_var(x, &tmp_mv, ref_mv, &v_fn_ptr, 1); if (tmp_err < INT_MAX - new_mv_mode_penalty) @@ -595,11 +613,11 @@ static int get_smooth_intra_threshold(VP9_COMMON *cm) { #define FP_MAX_DN_THRESH 24 #define KERNEL_SIZE 3 -// Baseline Kernal weights for first pass noise metric -static uint8_t fp_dn_kernal_3[KERNEL_SIZE * KERNEL_SIZE] = { 1, 2, 1, 2, 4, +// Baseline Kernel weights for first pass noise metric +static uint8_t fp_dn_kernel_3[KERNEL_SIZE * KERNEL_SIZE] = { 1, 2, 1, 2, 4, 2, 1, 2, 1 }; -// Estimate noise at a single point based on the impace of a spatial kernal +// Estimate noise at a single point based on the impact of a spatial kernel // on the point value static int fp_estimate_point_noise(uint8_t *src_ptr, const int stride) { int sum_weight = 0; @@ -609,23 +627,23 @@ static int fp_estimate_point_noise(uint8_t *src_ptr, const int stride) { int diff; int dn_diff; uint8_t *tmp_ptr; - uint8_t *kernal_ptr; + uint8_t *kernel_ptr; uint8_t dn_val; uint8_t centre_val = *src_ptr; - kernal_ptr = fp_dn_kernal_3; + kernel_ptr = fp_dn_kernel_3; - // Apply the kernal + // Apply the kernel tmp_ptr = src_ptr - stride - 1; for (i = 0; i < KERNEL_SIZE; ++i) { for (j = 0; j < KERNEL_SIZE; ++j) { diff = abs((int)centre_val - (int)tmp_ptr[j]); max_diff = VPXMAX(max_diff, diff); if (diff <= FP_DN_THRESH) { - sum_weight += *kernal_ptr; - sum_val += (int)tmp_ptr[j] * (int)*kernal_ptr; + sum_weight += *kernel_ptr; + sum_val += (int)tmp_ptr[j] * (int)*kernel_ptr; } - ++kernal_ptr; + ++kernel_ptr; } tmp_ptr += stride; } @@ -651,13 +669,13 @@ static int fp_highbd_estimate_point_noise(uint8_t *src_ptr, const int stride) { int dn_diff; uint8_t *tmp_ptr; uint16_t *tmp_ptr16; - uint8_t *kernal_ptr; + uint8_t *kernel_ptr; uint16_t dn_val; uint16_t centre_val = *CONVERT_TO_SHORTPTR(src_ptr); - kernal_ptr = fp_dn_kernal_3; + kernel_ptr = fp_dn_kernel_3; - // Apply the kernal + // Apply the kernel tmp_ptr = src_ptr - stride - 1; for (i = 0; i < KERNEL_SIZE; ++i) { tmp_ptr16 = CONVERT_TO_SHORTPTR(tmp_ptr); @@ -665,10 +683,10 @@ static int fp_highbd_estimate_point_noise(uint8_t *src_ptr, const int stride) { diff = abs((int)centre_val - (int)tmp_ptr16[j]); max_diff = VPXMAX(max_diff, diff); if (diff <= FP_DN_THRESH) { - sum_weight += *kernal_ptr; - sum_val += (int)tmp_ptr16[j] * (int)*kernal_ptr; + sum_weight += *kernel_ptr; + sum_val += (int)tmp_ptr16[j] * (int)*kernel_ptr; } - ++kernal_ptr; + ++kernel_ptr; } tmp_ptr += stride; } @@ -793,6 +811,7 @@ static void first_pass_stat_calc(VP9_COMP *cpi, FIRSTPASS_STATS *fps, fps->inactive_zone_cols = (double)0; if (fp_acc_data->mvcount > 0) { + fps->new_mv_count = (double)(fp_acc_data->new_mv_count) / num_mbs; fps->MVr = (double)(fp_acc_data->sum_mvr) / fp_acc_data->mvcount; fps->mvr_abs = (double)(fp_acc_data->sum_mvr_abs) / fp_acc_data->mvcount; fps->MVc = (double)(fp_acc_data->sum_mvc) / fp_acc_data->mvcount; @@ -809,6 +828,7 @@ static void first_pass_stat_calc(VP9_COMP *cpi, FIRSTPASS_STATS *fps, (double)(fp_acc_data->sum_in_vectors) / (fp_acc_data->mvcount * 2); fps->pcnt_motion = (double)(fp_acc_data->mvcount) / num_mbs; } else { + fps->new_mv_count = 0.0; fps->MVr = 0.0; fps->mvr_abs = 0.0; fps->MVc = 0.0; @@ -834,6 +854,7 @@ static void accumulate_fp_mb_row_stat(TileDataEnc *this_tile, this_tile->fp_data.intra_count_low += fp_acc_data->intra_count_low; this_tile->fp_data.intra_count_high += fp_acc_data->intra_count_high; this_tile->fp_data.intra_skip_count += fp_acc_data->intra_skip_count; + this_tile->fp_data.new_mv_count += fp_acc_data->new_mv_count; this_tile->fp_data.mvcount += fp_acc_data->mvcount; this_tile->fp_data.sum_mvr += fp_acc_data->sum_mvr; this_tile->fp_data.sum_mvr_abs += fp_acc_data->sum_mvr_abs; @@ -843,31 +864,15 @@ static void accumulate_fp_mb_row_stat(TileDataEnc *this_tile, this_tile->fp_data.sum_mvcs += fp_acc_data->sum_mvcs; this_tile->fp_data.sum_in_vectors += fp_acc_data->sum_in_vectors; this_tile->fp_data.intra_smooth_count += fp_acc_data->intra_smooth_count; + const int min_start_row = VPXMIN(this_tile->fp_data.image_data_start_row, + fp_acc_data->image_data_start_row); this_tile->fp_data.image_data_start_row = - VPXMIN(this_tile->fp_data.image_data_start_row, - fp_acc_data->image_data_start_row) == INVALID_ROW + (min_start_row == INVALID_ROW) ? VPXMAX(this_tile->fp_data.image_data_start_row, fp_acc_data->image_data_start_row) - : VPXMIN(this_tile->fp_data.image_data_start_row, - fp_acc_data->image_data_start_row); + : min_start_row; } -#if CONFIG_RATE_CTRL -static void store_fp_motion_vector(VP9_COMP *cpi, const MV *mv, - const int mb_row, const int mb_col, - MV_REFERENCE_FRAME frame_type, - const int mv_idx) { - VP9_COMMON *const cm = &cpi->common; - const int mb_index = mb_row * cm->mb_cols + mb_col; - MOTION_VECTOR_INFO *this_motion_vector_info = - &cpi->fp_motion_vector_info[mb_index]; - this_motion_vector_info->ref_frame[mv_idx] = frame_type; - if (frame_type != INTRA_FRAME) { - this_motion_vector_info->mv[mv_idx].as_mv = *mv; - } -} -#endif // CONFIG_RATE_CTRL - #define NZ_MOTION_PENALTY 128 #define INTRA_MODE_PENALTY 1024 void vp9_first_pass_encode_tile_mb_row(VP9_COMP *cpi, ThreadData *td, @@ -904,6 +909,9 @@ void vp9_first_pass_encode_tile_mb_row(VP9_COMP *cpi, ThreadData *td, double mb_neutral_count; int scaled_low_intra_thresh = scale_sse_threshold(cm, LOW_I_THRESH); + MV *first_top_mv = &tile_data->firstpass_top_mv; + MV last_nonzero_mv = { 0, 0 }; + // First pass code requires valid last and new frame buffers. assert(new_yv12 != NULL); assert(frame_is_intra_only(cm) || (lst_yv12 != NULL)); @@ -944,6 +952,10 @@ void vp9_first_pass_encode_tile_mb_row(VP9_COMP *cpi, ThreadData *td, (*(cpi->row_mt_sync_read_ptr))(&tile_data->row_mt_sync, mb_row, c); + if (mb_col == mb_col_start) { + last_nonzero_mv = *first_top_mv; + } + // Adjust to the next column of MBs. x->plane[0].src.buf = cpi->Source->y_buffer + mb_row * 16 * x->plane[0].src.stride + mb_col * 16; @@ -1091,13 +1103,6 @@ void vp9_first_pass_encode_tile_mb_row(VP9_COMP *cpi, ThreadData *td, struct buf_2d unscaled_last_source_buf_2d; vp9_variance_fn_ptr_t v_fn_ptr = cpi->fn_ptr[bsize]; -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - // Store zero mv as default - store_fp_motion_vector(cpi, &mv, mb_row, mb_col, LAST_FRAME, 0); - } -#endif // CONFIG_RAGE_CTRL - xd->plane[0].pre[0].buf = first_ref_buf->y_buffer + recon_yoffset; #if CONFIG_VP9_HIGHBITDEPTH if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { @@ -1143,7 +1148,7 @@ void vp9_first_pass_encode_tile_mb_row(VP9_COMP *cpi, ThreadData *td, v_fn_ptr.vf = get_block_variance_fn(bsize); #if CONFIG_VP9_HIGHBITDEPTH if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { - v_fn_ptr.vf = highbd_get_block_variance_fn(bsize, 8); + v_fn_ptr.vf = highbd_get_block_variance_fn(bsize, xd->bd); } #endif // CONFIG_VP9_HIGHBITDEPTH this_motion_error = @@ -1162,11 +1167,6 @@ void vp9_first_pass_encode_tile_mb_row(VP9_COMP *cpi, ThreadData *td, vp9_get_mvpred_var(x, &tmp_mv, &zero_mv, &v_fn_ptr, 0); } } -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - store_fp_motion_vector(cpi, &mv, mb_row, mb_col, LAST_FRAME, 0); - } -#endif // CONFIG_RAGE_CTRL // Search in an older reference frame. if ((cm->current_video_frame > 1) && gld_yv12 != NULL) { @@ -1188,12 +1188,6 @@ void vp9_first_pass_encode_tile_mb_row(VP9_COMP *cpi, ThreadData *td, #endif // CONFIG_VP9_HIGHBITDEPTH first_pass_motion_search(cpi, x, &zero_mv, &tmp_mv, &gf_motion_error); -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - store_fp_motion_vector(cpi, &tmp_mv, mb_row, mb_col, GOLDEN_FRAME, - 1); - } -#endif // CONFIG_RAGE_CTRL if (gf_motion_error < motion_error && gf_motion_error < this_error) ++(fp_acc_data->second_ref_count); @@ -1253,7 +1247,7 @@ void vp9_first_pass_encode_tile_mb_row(VP9_COMP *cpi, ThreadData *td, xd->mi[0]->mv[0].as_mv = mv; xd->mi[0]->tx_size = TX_4X4; xd->mi[0]->ref_frame[0] = LAST_FRAME; - xd->mi[0]->ref_frame[1] = NONE; + xd->mi[0]->ref_frame[1] = NO_REF_FRAME; vp9_build_inter_predictors_sby(xd, mb_row << 1, mb_col << 1, bsize); vp9_encode_sby_pass1(x, bsize); fp_acc_data->sum_mvr += mv.row; @@ -1268,6 +1262,10 @@ void vp9_first_pass_encode_tile_mb_row(VP9_COMP *cpi, ThreadData *td, if (!is_zero_mv(&mv)) { ++(fp_acc_data->mvcount); + if (!is_equal_mv(&mv, &last_nonzero_mv)) { + ++(fp_acc_data->new_mv_count); + } + last_nonzero_mv = mv; // Does the row vector point inwards or outwards? if (mb_row < cm->mb_rows / 2) { @@ -1315,14 +1313,12 @@ void vp9_first_pass_encode_tile_mb_row(VP9_COMP *cpi, ThreadData *td, } } else { fp_acc_data->sr_coded_error += (int64_t)this_error; -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - store_fp_motion_vector(cpi, NULL, mb_row, mb_col, INTRA_FRAME, 0); - } -#endif // CONFIG_RAGE_CTRL } fp_acc_data->coded_error += (int64_t)this_error; + if (mb_col == mb_col_start) { + *first_top_mv = last_nonzero_mv; + } recon_yoffset += 16; recon_uvoffset += uv_mb_height; @@ -1345,14 +1341,7 @@ static void first_pass_encode(VP9_COMP *cpi, FIRSTPASS_DATA *fp_acc_data) { MV best_ref_mv; // Tiling is ignored in the first pass. vp9_tile_init(tile, cm, 0, 0); - -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - fp_motion_vector_info_reset(cpi->frame_info.frame_width, - cpi->frame_info.frame_height, - cpi->fp_motion_vector_info); - } -#endif + tile_data.firstpass_top_mv = zero_mv; for (mb_row = 0; mb_row < cm->mb_rows; ++mb_row) { best_ref_mv = zero_mv; @@ -1386,7 +1375,7 @@ void vp9_first_pass(VP9_COMP *cpi, const struct lookahead_entry *source) { assert(frame_is_intra_only(cm) || (lst_yv12 != NULL)); set_first_pass_params(cpi); - vp9_set_quantizer(cpi, find_fp_qindex(cm->bit_depth)); + vp9_set_quantizer(cpi, find_fp_qindex(cm->bit_depth), 0); vp9_setup_block_planes(&x->e_mbd, cm->subsampling_x, cm->subsampling_y); @@ -1411,7 +1400,7 @@ void vp9_first_pass(VP9_COMP *cpi, const struct lookahead_entry *source) { if (cpi->row_mt_bit_exact && cpi->twopass.fp_mb_float_stats == NULL) CHECK_MEM_ERROR( - cm, cpi->twopass.fp_mb_float_stats, + &cm->error, cpi->twopass.fp_mb_float_stats, vpx_calloc(cm->MBs * sizeof(*cpi->twopass.fp_mb_float_stats), 1)); { @@ -1437,7 +1426,7 @@ void vp9_first_pass(VP9_COMP *cpi, const struct lookahead_entry *source) { first_pass_stat_calc(cpi, &fps, &(first_tile_col->fp_data)); } - // Dont allow a value of 0 for duration. + // Don't allow a value of 0 for duration. // (Section duration is also defaulted to minimum of 1.0). fps.duration = VPXMAX(1.0, (double)(source->ts_end - source->ts_start)); @@ -1447,7 +1436,7 @@ void vp9_first_pass(VP9_COMP *cpi, const struct lookahead_entry *source) { accumulate_stats(&twopass->total_stats, &fps); } - // Copy the previous Last Frame back into gf and and arf buffers if + // Copy the previous Last Frame back into gf and arf buffers if // the prediction is good enough... but also don't allow it to lag too far. if ((twopass->sr_update_lag > 3) || ((cm->current_video_frame > 0) && @@ -1476,22 +1465,6 @@ void vp9_first_pass(VP9_COMP *cpi, const struct lookahead_entry *source) { cm->ref_frame_map[cpi->lst_fb_idx]); } - // Use this to see what the first pass reconstruction looks like. - if (0) { - char filename[512]; - FILE *recon_file; - snprintf(filename, sizeof(filename), "enc%04d.yuv", - (int)cm->current_video_frame); - - if (cm->current_video_frame == 0) - recon_file = fopen(filename, "wb"); - else - recon_file = fopen(filename, "ab"); - - (void)fwrite(lst_yv12->buffer_alloc, lst_yv12->frame_size, 1, recon_file); - fclose(recon_file); - } - // In the first pass, every frame is considered as a show frame. update_frame_indexes(cm, /*show_frame=*/1); if (cpi->use_svc) vp9_inc_frame_in_layer(cpi); @@ -1564,9 +1537,9 @@ static int get_twopass_worst_quality(VP9_COMP *cpi, const double section_err, last_group_rate_err = (double)twopass->rolling_arf_group_actual_bits / DOUBLE_DIVIDE_CHECK((double)twopass->rolling_arf_group_target_bits); - last_group_rate_err = VPXMAX(0.25, VPXMIN(4.0, last_group_rate_err)); + last_group_rate_err = fclamp(last_group_rate_err, 0.25, 4.0); twopass->bpm_factor *= (3.0 + last_group_rate_err) / 4.0; - twopass->bpm_factor = VPXMAX(0.25, VPXMIN(4.0, twopass->bpm_factor)); + twopass->bpm_factor = fclamp(twopass->bpm_factor, 0.25, 4.0); #endif if (target_rate <= 0) { @@ -1579,8 +1552,8 @@ static int get_twopass_worst_quality(VP9_COMP *cpi, const double section_err, const int active_mbs = (int)VPXMAX(1, (double)num_mbs * active_pct); const double av_err_per_mb = section_err / active_pct; const double speed_term = 1.0 + 0.04 * oxcf->speed; - const int target_norm_bits_per_mb = - (int)(((uint64_t)target_rate << BPER_MB_NORMBITS) / active_mbs); + const uint64_t target_norm_bits_per_mb = + ((uint64_t)target_rate << BPER_MB_NORMBITS) / active_mbs; int q; // TODO(jimbankoski): remove #if here or above when this has been @@ -1590,9 +1563,9 @@ static int get_twopass_worst_quality(VP9_COMP *cpi, const double section_err, last_group_rate_err = (double)twopass->rolling_arf_group_actual_bits / DOUBLE_DIVIDE_CHECK((double)twopass->rolling_arf_group_target_bits); - last_group_rate_err = VPXMAX(0.25, VPXMIN(4.0, last_group_rate_err)); + last_group_rate_err = fclamp(last_group_rate_err, 0.25, 4.0); twopass->bpm_factor *= (3.0 + last_group_rate_err) / 4.0; - twopass->bpm_factor = VPXMAX(0.25, VPXMIN(4.0, twopass->bpm_factor)); + twopass->bpm_factor = fclamp(twopass->bpm_factor, 0.25, 4.0); #endif // Try and pick a max Q that will be high enough to encode the @@ -1604,7 +1577,7 @@ static int get_twopass_worst_quality(VP9_COMP *cpi, const double section_err, INTER_FRAME, q, factor * speed_term * cpi->twopass.bpm_factor * noise_factor, cpi->common.bit_depth); - if (bits_per_mb <= target_norm_bits_per_mb) break; + if ((uint64_t)bits_per_mb <= target_norm_bits_per_mb) break; } // Restriction on active max q for constrained quality mode. @@ -1664,7 +1637,7 @@ void vp9_init_second_pass(VP9_COMP *cpi) { // Scan the first pass file and calculate a modified score for each // frame that is used to distribute bits. The modified score is assumed - // to provide a linear basis for bit allocation. I.e a frame A with a score + // to provide a linear basis for bit allocation. I.e., a frame A with a score // that is double that of frame B will be allocated 2x as many bits. { double modified_score_total = 0.0; @@ -1689,8 +1662,8 @@ void vp9_init_second_pass(VP9_COMP *cpi) { } // Second scan using clamps based on the previous cycle average. - // This may modify the total and average somewhat but we dont bother with - // further itterations. + // This may modify the total and average somewhat but we don't bother with + // further iterations. modified_score_total = 0.0; s = twopass->stats_in; while (s < twopass->stats_in_end) { @@ -1847,7 +1820,7 @@ static int detect_flash_from_frame_stats(const FIRSTPASS_STATS *frame_stats) { // brief break in prediction (such as a flash) but subsequent frames // are reasonably well predicted by an earlier (pre flash) frame. // The recovery after a flash is indicated by a high pcnt_second_ref - // useage or a second ref coded error notabley lower than the last + // usage or a second ref coded error notabley lower than the last // frame coded error. if (frame_stats == NULL) { return 0; @@ -2027,7 +2000,7 @@ static int compute_arf_boost(const FRAME_INFO *frame_info, this_frame, &this_frame_mv_in_out, &mv_in_out_accumulator, &abs_mv_in_out_accumulator, &mv_ratio_accumulator); - // We want to discount the the flash frame itself and the recovery + // We want to discount the flash frame itself and the recovery // frame that follows as both will have poor scores. flash_detected = detect_flash_from_frame_stats(this_frame) || detect_flash_from_frame_stats(next_frame); @@ -2113,11 +2086,10 @@ static int64_t calculate_total_gf_group_bits(VP9_COMP *cpi, } // Clamp odd edge cases. - total_group_bits = (total_group_bits < 0) - ? 0 - : (total_group_bits > twopass->kf_group_bits) - ? twopass->kf_group_bits - : total_group_bits; + total_group_bits = (total_group_bits < 0) ? 0 + : (total_group_bits > twopass->kf_group_bits) + ? twopass->kf_group_bits + : total_group_bits; // Clip based on user supplied data rate variability limit. if (total_group_bits > (int64_t)max_bits * gop_frames) @@ -2159,7 +2131,7 @@ static double calculate_group_score(VP9_COMP *cpi, double av_score, double score_total = 0.0; int i = 0; - // We dont ever want to return a 0 score here. + // We don't ever want to return a 0 score here. if (frame_count == 0) return 1.0; while ((i < frame_count) && (s < twopass->stats_in_end)) { @@ -2282,6 +2254,7 @@ static void define_gf_group_structure(VP9_COMP *cpi) { find_arf_order(cpi, gf_group, &frame_index, layer_depth, 1, gop_frames); + // TODO(b/345523905): Why do we need to set an overlay frame in the end? set_gf_overlay_frame_type(gf_group, frame_index, rc->source_alt_ref_pending); gf_group->arf_src_offset[frame_index] = 0; gf_group->frame_gop_index[frame_index] = rc->baseline_gf_interval; @@ -2290,6 +2263,131 @@ static void define_gf_group_structure(VP9_COMP *cpi) { gf_group->gf_group_size = frame_index; } +static INLINE void gf_group_set_overlay_frame(GF_GROUP *gf_group, + int frame_index, + int show_frame_index) { + gf_group->update_type[frame_index] = OVERLAY_UPDATE; + gf_group->arf_src_offset[frame_index] = 0; + gf_group->frame_gop_index[frame_index] = show_frame_index; + gf_group->rf_level[frame_index] = INTER_NORMAL; + gf_group->layer_depth[frame_index] = MAX_ARF_LAYERS - 1; +} + +static INLINE void gf_group_set_key_frame(GF_GROUP *gf_group, int frame_index, + int show_frame_index) { + gf_group->update_type[frame_index] = KF_UPDATE; + gf_group->arf_src_offset[frame_index] = 0; + gf_group->frame_gop_index[frame_index] = show_frame_index; + gf_group->rf_level[frame_index] = KF_STD; + gf_group->layer_depth[frame_index] = 0; +} + +static INLINE void gf_group_set_arf_frame(GF_GROUP *gf_group, int frame_index, + int show_frame_index) { + gf_group->update_type[frame_index] = ARF_UPDATE; + gf_group->arf_src_offset[frame_index] = + (unsigned char)(show_frame_index - frame_index); + gf_group->frame_gop_index[frame_index] = show_frame_index; + gf_group->rf_level[frame_index] = GF_ARF_STD; + gf_group->layer_depth[frame_index] = 1; +} + +static INLINE void gf_group_set_inter_normal_frame(GF_GROUP *gf_group, + int frame_index, + int show_frame_index) { + gf_group->update_type[frame_index] = LF_UPDATE; + gf_group->arf_src_offset[frame_index] = 0; + gf_group->frame_gop_index[frame_index] = show_frame_index; + gf_group->rf_level[frame_index] = INTER_NORMAL; + gf_group->layer_depth[frame_index] = 2; +} + +static INLINE void set_gf_frame_type(vpx_rc_frame_update_type_t update_type, + int show_frame_count, GF_GROUP *gf_group, + int *frame_index, int *show_frame_index) { + if (update_type == VPX_RC_KF_UPDATE) { + gf_group_set_key_frame(gf_group, *frame_index, *show_frame_index); + ++(*frame_index); + ++(*show_frame_index); + } else if (update_type == VPX_RC_OVERLAY_UPDATE) { + gf_group_set_overlay_frame(gf_group, *frame_index, *show_frame_index); + ++(*frame_index); + ++(*show_frame_index); + } else if (update_type == VPX_RC_ARF_UPDATE) { + gf_group_set_arf_frame(gf_group, *frame_index, show_frame_count); + ++(*frame_index); + } else if (update_type == VPX_RC_LF_UPDATE) { + gf_group_set_inter_normal_frame(gf_group, *frame_index, *show_frame_index); + ++(*frame_index); + ++(*show_frame_index); + } else { + assert(0); + } +} + +static void ext_rc_define_gf_group_structure( + const vpx_rc_gop_decision_t *gop_decision, GF_GROUP *gf_group) { + const int gop_coding_frames = gop_decision->gop_coding_frames; + + const int show_frame_count = gop_coding_frames - gop_decision->use_alt_ref; + int frame_index = 0; + int show_frame_index = 0; + + for (int i = frame_index; i < gop_coding_frames; i++) { + set_gf_frame_type(gop_decision->update_type[i], show_frame_count, gf_group, + &frame_index, &show_frame_index); + + gf_group->update_ref_idx[i] = gop_decision->update_ref_index[i]; + + gf_group->ext_rc_ref[i].last_index = 0; + gf_group->ext_rc_ref[i].golden_index = 0; + gf_group->ext_rc_ref[i].altref_index = 0; + for (int ref_frame = 0; ref_frame < 3; ref_frame++) { + const vpx_rc_ref_frame_t *const ext_ref_frame = + &gop_decision->ref_frame_list[i]; + const int ref_index = ext_ref_frame->index[ref_frame]; + gf_group->ref_frame_list[i][ref_frame] = ext_ref_frame->index[ref_frame]; + switch (ext_ref_frame->name[ref_frame]) { + case VPX_RC_LAST_FRAME: + gf_group->ext_rc_ref[i].last_index = ref_index; + break; + case VPX_RC_GOLDEN_FRAME: + gf_group->ext_rc_ref[i].golden_index = ref_index; + break; + case VPX_RC_ALTREF_FRAME: + gf_group->ext_rc_ref[i].altref_index = ref_index; + break; + default: break; + } + } + if (gf_group->update_type[i] == OVERLAY_UPDATE) { + // From ext_rc, overlay may not update any ref. But here we force it to + // update its arf's slot. This is probably OK since the arf and this + // overlay frame should be very similar. + gf_group->update_ref_idx[i] = gf_group->ext_rc_ref[i].altref_index; + } + } + // max_layer_depth is hardcoded to match the behavior of + // define_gf_group_structure() + // TODO(angiebird): Check whether max_layer_depth has performance impact. + gf_group->max_layer_depth = 2; + gf_group->allowed_max_layer_depth = 1; + gf_group->gf_group_size = gop_coding_frames; + + // TODO(b/345523905): Why do we need to set an overlay frame in the end? + assert(show_frame_count == show_frame_index); + if (gop_decision->use_alt_ref) { + gf_group_set_overlay_frame(gf_group, gf_group->gf_group_size, + show_frame_index); + } else { + gf_group_set_inter_normal_frame(gf_group, gf_group->gf_group_size, + show_frame_index); + } + + gf_group->frame_start = 0; + gf_group->frame_end = gf_group->gf_group_size - gop_decision->use_alt_ref; +} + static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits, int gf_arf_bits) { VP9EncoderConfig *const oxcf = &cpi->oxcf; @@ -2483,9 +2581,6 @@ typedef struct RANGE { * rc->frames_since_key * rc->source_alt_ref_active * - * Special case: if CONFIG_RATE_CTRL is true, the external arf indexes will - * determine the arf position. - * * TODO(angiebird): Separate the dynamic fields and static fields into two * structs. */ @@ -2493,7 +2588,7 @@ static int get_gop_coding_frame_num( int *use_alt_ref, const FRAME_INFO *frame_info, const TWO_PASS *const twopass, const RATE_CONTROL *rc, int gf_start_show_idx, const RANGE *active_gf_interval, - double gop_intra_factor, int lag_in_frames) { + double gop_intra_factor, int lag_in_frames, int *end_of_sequence) { const FIRST_PASS_INFO *first_pass_info = &twopass->first_pass_info; double loop_decay_rate = 1.00; double mv_ratio_accumulator = 0.0; @@ -2519,6 +2614,7 @@ static int get_gop_coding_frame_num( next_frame = fps_get_frame_stats(first_pass_info, gf_start_show_idx + gop_coding_frames); if (next_frame == NULL) { + *end_of_sequence = gop_coding_frames == 1 && rc->source_alt_ref_active; break; } @@ -2587,7 +2683,7 @@ static int get_gop_coding_frame_num( if ( // Don't break out with a very short interval. (gop_coding_frames >= active_gf_interval->min) && - // If possible dont break very close to a kf + // If possible don't break very close to a kf ((rc->frames_to_key - gop_coding_frames) >= rc->min_gf_interval) && (gop_coding_frames & 0x01) && (!flash_detected) && ((mv_ratio_accumulator > mv_ratio_accumulator_thresh) || @@ -2602,21 +2698,6 @@ static int get_gop_coding_frame_num( return gop_coding_frames; } -static RANGE get_active_gf_inverval_range_simple(int min_gf_interval, - int arf_active_or_kf, - int frames_to_key) { - RANGE active_gf_interval; - active_gf_interval.min = min_gf_interval + arf_active_or_kf + 2; - active_gf_interval.max = 16 + arf_active_or_kf; - - if ((active_gf_interval.max <= frames_to_key) && - (active_gf_interval.max >= (frames_to_key - min_gf_interval))) { - active_gf_interval.min = frames_to_key / 2; - active_gf_interval.max = frames_to_key / 2; - } - return active_gf_interval; -} - static RANGE get_active_gf_inverval_range( const FRAME_INFO *frame_info, const RATE_CONTROL *rc, int arf_active_or_kf, int gf_start_show_idx, int active_worst_quality, int last_boosted_qindex) { @@ -2700,7 +2781,23 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { int64_t gf_group_bits; int gf_arf_bits; - const int is_key_frame = frame_is_intra_only(cm); + int is_key_frame = frame_is_intra_only(cm); + + vpx_rc_gop_decision_t gop_decision; + int gop_decision_ready = 0; + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_GOP) != 0 && + cpi->ext_ratectrl.funcs.get_gop_decision != NULL) { + vpx_codec_err_t codec_status = + vp9_extrc_get_gop_decision(&cpi->ext_ratectrl, &gop_decision); + if (codec_status != VPX_CODEC_OK) { + vpx_internal_error(&cm->error, codec_status, + "vp9_extrc_get_gop_decision() failed"); + } + is_key_frame = gop_decision.use_key_frame; + gop_decision_ready = 1; + } + // If this is a key frame or the overlay from a previous arf then // the error score / cost of this frame has already been accounted for. const int arf_active_or_kf = is_key_frame || rc->source_alt_ref_active; @@ -2709,23 +2806,23 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { double gop_intra_factor; int gop_frames; RANGE active_gf_interval; + // Whether this is at the end of last GOP of this sequence. + int end_of_sequence = 0; // Reset the GF group data structures unless this is a key // frame in which case it will already have been done. if (is_key_frame == 0) { vp9_zero(twopass->gf_group); + ++rc->gop_global_index; + } else { + rc->gop_global_index = 0; } vpx_clear_system_state(); - if (oxcf->use_simple_encode_api) { - active_gf_interval = get_active_gf_inverval_range_simple( - rc->min_gf_interval, arf_active_or_kf, rc->frames_to_key); - } else { - active_gf_interval = get_active_gf_inverval_range( - frame_info, rc, arf_active_or_kf, gf_start_show_idx, - twopass->active_worst_quality, rc->last_boosted_qindex); - } + active_gf_interval = get_active_gf_inverval_range( + frame_info, rc, arf_active_or_kf, gf_start_show_idx, + twopass->active_worst_quality, rc->last_boosted_qindex); if (cpi->multi_layer_arf) { int arf_layers = get_arf_layers(cpi->multi_layer_arf, oxcf->enable_auto_arf, @@ -2737,20 +2834,14 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { gop_coding_frames = get_gop_coding_frame_num( &use_alt_ref, frame_info, twopass, rc, gf_start_show_idx, - &active_gf_interval, gop_intra_factor, cpi->oxcf.lag_in_frames); + &active_gf_interval, gop_intra_factor, cpi->oxcf.lag_in_frames, + &end_of_sequence); use_alt_ref &= allow_alt_ref; -#if CONFIG_RATE_CTRL - // If the external gop_command is on, we will override the decisions - // of gop_coding_frames and use_alt_ref. - if (cpi->oxcf.use_simple_encode_api) { - const GOP_COMMAND *gop_command = &cpi->encode_command.gop_command; - assert(allow_alt_ref == 1); - if (gop_command->use) { - gop_coding_frames = gop_command_coding_frame_count(gop_command); - use_alt_ref = gop_command->use_alt_ref; - } + + if (gop_decision_ready) { + gop_coding_frames = gop_decision.gop_coding_frames; + use_alt_ref = gop_decision.use_alt_ref; } -#endif // Was the group length constrained by the requirement for a new KF? rc->constrained_gf_group = (gop_coding_frames >= rc->frames_to_key) ? 1 : 0; @@ -2843,6 +2934,25 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { int show_idx = gf_start_show_idx + j; const FIRSTPASS_STATS *frame_stats = fps_get_frame_stats(first_pass_info, show_idx); + if (frame_stats == NULL) { + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_GOP) != 0 && + cpi->ext_ratectrl.funcs.get_gop_decision != NULL) { + // Since in ext_ratectrl, gop_coding_frames means the count of both + // show and no show frames. Using this variable to access + // first_pass_info will trigger out-of-range error because + // first_pass_info only contains show frames. This part is used for + // computing gf_group_err which will be used to compute gf_group_bits + // for libvpx internal rate control. Since ext_ratectrl is using + // external rate control module, this part becomes non-critical. + // Hence, we can safely turn off this error reporting. + break; + } + vpx_internal_error(&cm->error, VPX_CODEC_ERROR, + "In define_gf_group(), frame_stats is NULL when " + "calculating gf_group_err."); + break; + } // Accumulate error score of frames in this gf group. gf_group_err += calc_norm_frame_score(oxcf, frame_info, frame_stats, mean_mod_score, av_err); @@ -2913,7 +3023,15 @@ static void define_gf_group(VP9_COMP *cpi, int gf_start_show_idx) { twopass->kf_group_error_left -= gf_group_err; // Decide GOP structure. - define_gf_group_structure(cpi); + if (gop_decision_ready) { + ext_rc_define_gf_group_structure(&gop_decision, &twopass->gf_group); + // Set the fb idx for the first frame in this GOP. + cpi->lst_fb_idx = twopass->gf_group.ext_rc_ref[0].last_index; + cpi->gld_fb_idx = twopass->gf_group.ext_rc_ref[0].golden_index; + cpi->alt_fb_idx = twopass->gf_group.ext_rc_ref[0].altref_index; + } else { + define_gf_group_structure(cpi); + } // Allocate bits to each of the frames in the GF group. allocate_gf_group_bits(cpi, gf_group_bits, gf_arf_bits); @@ -2987,7 +3105,7 @@ static int intra_step_transition(const FIRSTPASS_STATS *this_frame, next_frame->intra_error / DOUBLE_DIVIDE_CHECK(next_frame->coded_error); // Return true the intra/inter ratio for the current frame is - // low but better in the next and previous frame and the relative useage of + // low but better in the next and previous frame and the relative usage of // intra in the current frame is markedly higher than the last and next frame. if ((this_ii_ratio < 2.0) && (last_ii_ratio > 2.25) && (next_ii_ratio > 2.25) && (this_pcnt_intra > (3 * last_pcnt_intra)) && @@ -3008,8 +3126,8 @@ static int intra_step_transition(const FIRSTPASS_STATS *this_frame, // Minimum % intra coding observed in first pass (1.0 = 100%) #define MIN_INTRA_LEVEL 0.25 // Threshold for use of the lagging second reference frame. Scene cuts do not -// usually have a high second ref useage. -#define SECOND_REF_USEAGE_THRESH 0.2 +// usually have a high second ref usage. +#define SECOND_REF_USAGE_THRESH 0.2 // Hard threshold where the first pass chooses intra for almost all blocks. // In such a case even if the frame is not a scene cut coding a key frame // may be a good option. @@ -3039,7 +3157,7 @@ static int test_candidate_kf(const FIRST_PASS_INFO *first_pass_info, detect_flash_from_frame_stats(next_frame); if (!detect_flash_from_frame_stats(this_frame) && !detect_flash_from_frame_stats(next_frame) && - (this_frame->pcnt_second_ref < SECOND_REF_USEAGE_THRESH) && + (this_frame->pcnt_second_ref < SECOND_REF_USAGE_THRESH) && ((this_frame->pcnt_inter < VERY_LOW_INTER_THRESH) || (slide_transition(this_frame, last_frame, next_frame)) || (intra_step_transition(this_frame, last_frame, next_frame)) || @@ -3223,8 +3341,22 @@ static void find_next_key_frame(VP9_COMP *cpi, int kf_show_idx) { kf_mod_err = calc_norm_frame_score(oxcf, frame_info, keyframe_stats, mean_mod_score, av_err); - rc->frames_to_key = vp9_get_frames_to_next_key(oxcf, twopass, kf_show_idx, - rc->min_gf_interval); + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_GOP) != 0 && + cpi->ext_ratectrl.funcs.get_key_frame_decision != NULL) { + vpx_rc_key_frame_decision_t key_frame_decision; + vpx_codec_err_t codec_status = vp9_extrc_get_key_frame_decision( + &cpi->ext_ratectrl, &key_frame_decision); + if (codec_status == VPX_CODEC_OK) { + rc->frames_to_key = key_frame_decision.key_frame_group_size; + } else { + vpx_internal_error(&cpi->common.error, codec_status, + "vp9_extrc_get_key_frame_decision() failed"); + } + } else { + rc->frames_to_key = vp9_get_frames_to_next_key(oxcf, twopass, kf_show_idx, + rc->min_gf_interval); + } // If there is a max kf interval set by the user we must obey it. // We already breakout of the loop above at 2x max. @@ -3254,8 +3386,9 @@ static void find_next_key_frame(VP9_COMP *cpi, int kf_show_idx) { // Default allocation based on bits left and relative // complexity of the section. - twopass->kf_group_bits = (int64_t)( - twopass->bits_left * (kf_group_err / twopass->normalized_score_left)); + twopass->kf_group_bits = + (int64_t)(twopass->bits_left * + (kf_group_err / twopass->normalized_score_left)); // Clip based on maximum per frame rate defined by the user. max_grp_bits = (int64_t)max_bits * (int64_t)rc->frames_to_key; @@ -3286,8 +3419,8 @@ static void find_next_key_frame(VP9_COMP *cpi, int kf_show_idx) { kf_boost_scan_frames = (int)(VPXMAX(64 * zero_motion_avg - 16, 160 * motion_compensable_avg - 112)); kf_boost_scan_frames = - VPXMAX(VPXMIN(kf_boost_scan_frames, MAX_SCAN_FRAMES_FOR_KF_BOOST), - MIN_SCAN_FRAMES_FOR_KF_BOOST); + clamp(kf_boost_scan_frames, MIN_SCAN_FRAMES_FOR_KF_BOOST, + MAX_SCAN_FRAMES_FOR_KF_BOOST); } reset_fpf_position(twopass, start_position); @@ -3317,7 +3450,7 @@ static void find_next_key_frame(VP9_COMP *cpi, int kf_show_idx) { // The second (lagging) ref error is not valid immediately after // a key frame because either the lag has not built up (in the case of - // the first key frame or it points to a refernce before the new key + // the first key frame or it points to a reference before the new key // frame. if (i < 2) sr_accumulator = 0.0; frame_boost = @@ -3347,7 +3480,7 @@ static void find_next_key_frame(VP9_COMP *cpi, int kf_show_idx) { twopass->key_frame_section_intra_rating = calculate_section_intra_ratio( start_position, twopass->stats_in_end, rc->frames_to_key); - // Special case for static / slide show content but dont apply + // Special case for static / slide show content but don't apply // if the kf group is very short. if ((zero_motion_accumulator > 0.99) && (rc->frames_to_key > 8)) { rc->kf_boost = (int)(twopass->kf_max_total_boost); @@ -3461,6 +3594,16 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { FIRSTPASS_STATS this_frame; const int show_idx = cm->current_video_frame; + if (cpi->common.current_frame_coding_index == 0 && + cpi->ext_ratectrl.funcs.send_firstpass_stats != NULL) { + const vpx_codec_err_t codec_status = vp9_extrc_send_firstpass_stats( + &cpi->ext_ratectrl, &cpi->twopass.first_pass_info); + if (codec_status != VPX_CODEC_OK) { + vpx_internal_error(&cm->error, codec_status, + "vp9_extrc_send_firstpass_stats() failed"); + } + } + if (!twopass->stats_in) return; // Configure image size specific vizier parameters @@ -3470,7 +3613,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { vp9_init_vizier_params(twopass, screen_area); } - // If this is an arf frame then we dont want to read the stats file or + // If this is an arf frame then we don't want to read the stats file or // advance the input pointer as we already have what we need. if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { int target_rate; @@ -3504,8 +3647,8 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { const int frames_left = (int)(twopass->total_stats.count - cm->current_video_frame); // Special case code for first frame. - const int section_target_bandwidth = - (int)(twopass->bits_left / frames_left); + int64_t section_target_bandwidth = twopass->bits_left / frames_left; + section_target_bandwidth = VPXMIN(section_target_bandwidth, INT_MAX); const double section_length = twopass->total_left_stats.count; const double section_error = twopass->total_left_stats.coded_error / section_length; @@ -3520,7 +3663,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { tmp_q = get_twopass_worst_quality( cpi, section_error, section_intra_skip + section_inactive_zone, - section_noise, section_target_bandwidth); + section_noise, (int)section_target_bandwidth); twopass->active_worst_quality = tmp_q; twopass->baseline_active_worst_quality = tmp_q; @@ -3552,22 +3695,28 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { if (rc->frames_till_gf_update_due == 0) { define_gf_group(cpi, show_idx); - rc->frames_till_gf_update_due = rc->baseline_gf_interval; - #if ARF_STATS_OUTPUT { FILE *fpfile; fpfile = fopen("arf.stt", "a"); ++arf_count; fprintf(fpfile, "%10d %10ld %10d %10d %10ld %10ld\n", - cm->current_video_frame, rc->frames_till_gf_update_due, - rc->kf_boost, arf_count, rc->gfu_boost, cm->frame_type); + cm->current_video_frame, rc->baseline_gf_interval, rc->kf_boost, + arf_count, rc->gfu_boost, cm->frame_type); fclose(fpfile); } #endif } + if (rc->frames_till_gf_update_due == 0) { + if (cpi->ext_ratectrl.ready && cpi->ext_ratectrl.log_file) { + fprintf(cpi->ext_ratectrl.log_file, "GOP_INFO show_frame_count %d\n", + rc->baseline_gf_interval); + } + rc->frames_till_gf_update_due = rc->baseline_gf_interval; + } + vp9_configure_buffer_updates(cpi, gf_group->index); rc->base_frame_target = gf_group->bit_allocation[gf_group->index]; @@ -3679,7 +3828,8 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) { rc->vbr_bits_off_target_fast += fast_extra_thresh - rc->projected_frame_size; rc->vbr_bits_off_target_fast = - VPXMIN(rc->vbr_bits_off_target_fast, (4 * rc->avg_frame_bandwidth)); + VPXMIN(rc->vbr_bits_off_target_fast, + (4 * (int64_t)rc->avg_frame_bandwidth)); // Fast adaptation of minQ if necessary to use up the extra bits. if (rc->avg_frame_bandwidth) { @@ -3698,145 +3848,6 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) { } } -#if CONFIG_RATE_CTRL -void vp9_get_next_group_of_picture(const VP9_COMP *cpi, int *first_is_key_frame, - int *use_alt_ref, int *coding_frame_count, - int *first_show_idx, - int *last_gop_use_alt_ref) { - const GOP_COMMAND *gop_command = &cpi->encode_command.gop_command; - // We make a copy of rc here because we want to get information from the - // encoder without changing its state. - // TODO(angiebird): Avoid copying rc here. - RATE_CONTROL rc = cpi->rc; - const int multi_layer_arf = 0; - const int allow_alt_ref = 1; - // We assume that current_video_frame is updated to the show index of the - // frame we are about to called. Note that current_video_frame is updated at - // the end of encode_frame_to_data_rate(). - // TODO(angiebird): Avoid this kind of fragile style. - *first_show_idx = cpi->common.current_video_frame; - *last_gop_use_alt_ref = rc.source_alt_ref_active; - - *first_is_key_frame = 0; - if (rc.frames_to_key == 0) { - rc.frames_to_key = vp9_get_frames_to_next_key( - &cpi->oxcf, &cpi->twopass, *first_show_idx, rc.min_gf_interval); - rc.frames_since_key = 0; - *first_is_key_frame = 1; - } - - if (gop_command->use) { - *coding_frame_count = gop_command_coding_frame_count(gop_command); - *use_alt_ref = gop_command->use_alt_ref; - assert(gop_command->show_frame_count <= rc.frames_to_key); - } else { - *coding_frame_count = vp9_get_gop_coding_frame_count( - &cpi->oxcf, &cpi->twopass, &cpi->frame_info, &rc, *first_show_idx, - multi_layer_arf, allow_alt_ref, *first_is_key_frame, - *last_gop_use_alt_ref, use_alt_ref); - } -} - -int vp9_get_gop_coding_frame_count(const VP9EncoderConfig *oxcf, - const TWO_PASS *const twopass, - const FRAME_INFO *frame_info, - const RATE_CONTROL *rc, int show_idx, - int multi_layer_arf, int allow_alt_ref, - int first_is_key_frame, - int last_gop_use_alt_ref, int *use_alt_ref) { - int frame_count; - double gop_intra_factor; - const int arf_active_or_kf = last_gop_use_alt_ref || first_is_key_frame; - RANGE active_gf_interval; - int arf_layers; - if (oxcf->use_simple_encode_api) { - active_gf_interval = get_active_gf_inverval_range_simple( - rc->min_gf_interval, arf_active_or_kf, rc->frames_to_key); - } else { - active_gf_interval = get_active_gf_inverval_range( - frame_info, rc, arf_active_or_kf, show_idx, /*active_worst_quality=*/0, - /*last_boosted_qindex=*/0); - } - - arf_layers = get_arf_layers(multi_layer_arf, oxcf->enable_auto_arf, - active_gf_interval.max); - if (multi_layer_arf) { - gop_intra_factor = 1.0 + 0.25 * arf_layers; - } else { - gop_intra_factor = 1.0; - } - - frame_count = get_gop_coding_frame_num(use_alt_ref, frame_info, twopass, rc, - show_idx, &active_gf_interval, - gop_intra_factor, oxcf->lag_in_frames); - *use_alt_ref &= allow_alt_ref; - return frame_count; -} - -// Under CONFIG_RATE_CTRL, once the first_pass_info is ready, the number of -// coding frames (including show frame and alt ref) can be determined. -int vp9_get_coding_frame_num(const VP9EncoderConfig *oxcf, - const TWO_PASS *const twopass, - const FRAME_INFO *frame_info, int multi_layer_arf, - int allow_alt_ref) { - const FIRST_PASS_INFO *first_pass_info = &twopass->first_pass_info; - int coding_frame_num = 0; - RATE_CONTROL rc; - int gop_coding_frame_count; - int gop_show_frames; - int show_idx = 0; - int last_gop_use_alt_ref = 0; - vp9_rc_init(oxcf, 1, &rc); - - while (show_idx < first_pass_info->num_frames) { - int use_alt_ref; - int first_is_key_frame = 0; - if (rc.frames_to_key == 0) { - rc.frames_to_key = vp9_get_frames_to_next_key(oxcf, twopass, show_idx, - rc.min_gf_interval); - rc.frames_since_key = 0; - first_is_key_frame = 1; - } - - gop_coding_frame_count = vp9_get_gop_coding_frame_count( - oxcf, twopass, frame_info, &rc, show_idx, multi_layer_arf, - allow_alt_ref, first_is_key_frame, last_gop_use_alt_ref, &use_alt_ref); - - rc.source_alt_ref_active = use_alt_ref; - last_gop_use_alt_ref = use_alt_ref; - gop_show_frames = gop_coding_frame_count - use_alt_ref; - rc.frames_to_key -= gop_show_frames; - rc.frames_since_key += gop_show_frames; - show_idx += gop_show_frames; - coding_frame_num += gop_show_frames + use_alt_ref; - } - return coding_frame_num; -} - -void vp9_get_key_frame_map(const VP9EncoderConfig *oxcf, - const TWO_PASS *const twopass, int *key_frame_map) { - const FIRST_PASS_INFO *first_pass_info = &twopass->first_pass_info; - int show_idx = 0; - RATE_CONTROL rc; - vp9_rc_init(oxcf, 1, &rc); - - // key_frame_map points to an int array with size equal to - // first_pass_info->num_frames, which is also the number of show frames in the - // video. - memset(key_frame_map, 0, - sizeof(*key_frame_map) * first_pass_info->num_frames); - while (show_idx < first_pass_info->num_frames) { - int key_frame_group_size; - key_frame_map[show_idx] = 1; - key_frame_group_size = - vp9_get_frames_to_next_key(oxcf, twopass, show_idx, rc.min_gf_interval); - assert(key_frame_group_size > 0); - show_idx += key_frame_group_size; - } - assert(show_idx == first_pass_info->num_frames); -} -#endif // CONFIG_RATE_CTRL - FIRSTPASS_STATS vp9_get_frame_stats(const TWO_PASS *twopass) { return twopass->this_frame_stats; } diff --git a/libs/libvpx/vp9/encoder/vp9_firstpass.h b/libs/libvpx/vp9/encoder/vp9_firstpass.h index cdcf568723..9fdd5fcb1d 100644 --- a/libs/libvpx/vp9/encoder/vp9_firstpass.h +++ b/libs/libvpx/vp9/encoder/vp9_firstpass.h @@ -14,6 +14,7 @@ #include #include "vp9/common/vp9_onyxc_int.h" +#include "vp9/encoder/vp9_firstpass_stats.h" #include "vp9/encoder/vp9_lookahead.h" #include "vp9/encoder/vp9_ratectrl.h" @@ -55,37 +56,9 @@ typedef struct { int64_t sum_mvcs; int sum_in_vectors; int intra_smooth_count; + int new_mv_count; } FIRSTPASS_DATA; -typedef struct { - double frame; - double weight; - double intra_error; - double coded_error; - double sr_coded_error; - double frame_noise_energy; - double pcnt_inter; - double pcnt_motion; - double pcnt_second_ref; - double pcnt_neutral; - double pcnt_intra_low; // Coded intra but low variance - double pcnt_intra_high; // Coded intra high variance - double intra_skip_pct; - double intra_smooth_pct; // % of blocks that are smooth - double inactive_zone_rows; // Image mask rows top and bottom. - double inactive_zone_cols; // Image mask columns at left and right edges. - double MVr; - double mvr_abs; - double MVc; - double mvc_abs; - double MVrv; - double MVcv; - double mv_in_out_count; - double duration; - double count; - int64_t spatial_layer_id; -} FIRSTPASS_STATS; - typedef enum { KF_UPDATE = 0, LF_UPDATE = 1, @@ -104,6 +77,12 @@ typedef enum { FRAME_CONTENT_TYPES = 2 } FRAME_CONTENT_TYPE; +typedef struct ExternalRcReference { + int last_index; + int golden_index; + int altref_index; +} ExternalRcReference; + typedef struct { unsigned char index; RATE_FACTOR_LEVEL rf_level[MAX_STATIC_GF_GROUP_LENGTH + 2]; @@ -113,6 +92,7 @@ typedef struct { unsigned char frame_gop_index[MAX_STATIC_GF_GROUP_LENGTH + 2]; int bit_allocation[MAX_STATIC_GF_GROUP_LENGTH + 2]; int gfu_boost[MAX_STATIC_GF_GROUP_LENGTH + 2]; + int update_ref_idx[MAX_STATIC_GF_GROUP_LENGTH + 2]; int frame_start; int frame_end; @@ -124,6 +104,11 @@ typedef struct { int max_layer_depth; int allowed_max_layer_depth; int group_noise_energy; + + // Structure to store the reference information from external RC. + // Used to override reference frame decisions in libvpx. + ExternalRcReference ext_rc_ref[MAX_STATIC_GF_GROUP_LENGTH + 2]; + int ref_frame_list[MAX_STATIC_GF_GROUP_LENGTH + 2][REFS_PER_FRAME]; } GF_GROUP; typedef struct { @@ -242,54 +227,6 @@ struct VP9EncoderConfig; int vp9_get_frames_to_next_key(const struct VP9EncoderConfig *oxcf, const TWO_PASS *const twopass, int kf_show_idx, int min_gf_interval); -#if CONFIG_RATE_CTRL -/* Call this function to get info about the next group of pictures. - * This function should be called after vp9_create_compressor() when encoding - * starts or after vp9_get_compressed_data() when the encoding process of - * the last group of pictures is just finished. - */ -void vp9_get_next_group_of_picture(const struct VP9_COMP *cpi, - int *first_is_key_frame, int *use_alt_ref, - int *coding_frame_count, int *first_show_idx, - int *last_gop_use_alt_ref); - -/*!\brief Call this function before coding a new group of pictures to get - * information about it. - * \param[in] oxcf Encoder config - * \param[in] twopass Twopass info - * \param[in] frame_info Frame info - * \param[in] rc Rate control state - * \param[in] show_idx Show index of the first frame in the group - * \param[in] multi_layer_arf Is multi-layer alternate reference used - * \param[in] allow_alt_ref Is alternate reference allowed - * \param[in] first_is_key_frame Is the first frame in the group a key frame - * \param[in] last_gop_use_alt_ref Does the last group use alternate reference - * - * \param[out] use_alt_ref Does this group use alternate reference - * - * \return Returns coding frame count - */ -int vp9_get_gop_coding_frame_count(const struct VP9EncoderConfig *oxcf, - const TWO_PASS *const twopass, - const FRAME_INFO *frame_info, - const RATE_CONTROL *rc, int show_idx, - int multi_layer_arf, int allow_alt_ref, - int first_is_key_frame, - int last_gop_use_alt_ref, int *use_alt_ref); - -int vp9_get_coding_frame_num(const struct VP9EncoderConfig *oxcf, - const TWO_PASS *const twopass, - const FRAME_INFO *frame_info, int multi_layer_arf, - int allow_alt_ref); - -/*!\brief Compute a key frame binary map indicates whether key frames appear - * in the corresponding positions. The passed in key_frame_map must point to an - * integer array with length equal to twopass->first_pass_info.num_frames, - * which is the number of show frames in the video. - */ -void vp9_get_key_frame_map(const struct VP9EncoderConfig *oxcf, - const TWO_PASS *const twopass, int *key_frame_map); -#endif // CONFIG_RATE_CTRL FIRSTPASS_STATS vp9_get_frame_stats(const TWO_PASS *twopass); FIRSTPASS_STATS vp9_get_total_stats(const TWO_PASS *twopass); diff --git a/libs/libvpx/vp9/encoder/vp9_firstpass_stats.h b/libs/libvpx/vp9/encoder/vp9_firstpass_stats.h new file mode 100644 index 0000000000..01928e7816 --- /dev/null +++ b/libs/libvpx/vp9/encoder/vp9_firstpass_stats.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VP9_ENCODER_VP9_FIRSTPASS_STATS_H_ +#define VPX_VP9_ENCODER_VP9_FIRSTPASS_STATS_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + double frame; + double weight; + double intra_error; + double coded_error; + double sr_coded_error; + double frame_noise_energy; + double pcnt_inter; + double pcnt_motion; + double pcnt_second_ref; + double pcnt_neutral; + double pcnt_intra_low; // Coded intra but low variance + double pcnt_intra_high; // Coded intra high variance + double intra_skip_pct; + double intra_smooth_pct; // % of blocks that are smooth + double inactive_zone_rows; // Image mask rows top and bottom. + double inactive_zone_cols; // Image mask columns at left and right edges. + double MVr; + double mvr_abs; + double MVc; + double mvc_abs; + double MVrv; + double MVcv; + double mv_in_out_count; + double duration; + double count; + double new_mv_count; + int64_t spatial_layer_id; +} FIRSTPASS_STATS; + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // VPX_VP9_ENCODER_VP9_FIRSTPASS_STATS_H_ diff --git a/libs/libvpx/vp9/encoder/vp9_frame_scale.c b/libs/libvpx/vp9/encoder/vp9_frame_scale.c index a410d0407f..c74d523246 100644 --- a/libs/libvpx/vp9/encoder/vp9_frame_scale.c +++ b/libs/libvpx/vp9/encoder/vp9_frame_scale.c @@ -9,9 +9,12 @@ */ #include "./vp9_rtcd.h" +#include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" #include "./vpx_scale_rtcd.h" #include "vp9/common/vp9_blockd.h" +#include "vp9/encoder/vp9_encoder.h" +#include "vpx/vpx_codec.h" #include "vpx_dsp/vpx_filter.h" #include "vpx_scale/yv12config.h" @@ -91,6 +94,23 @@ void vp9_scale_and_extend_frame_c(const YV12_BUFFER_CONFIG *src, { const int dst_w = dst->y_crop_width; const int dst_h = dst->y_crop_height; + + // The issue b/311394513 reveals a corner case bug. vpx_scaled_2d() requires + // both x_step_q4 and y_step_q4 are less than or equal to 64. Otherwise, it + // needs to call vp9_scale_and_extend_frame_nonnormative() that supports + // arbitrary scaling. + const int x_step_q4 = 16 * src_w / dst_w; + const int y_step_q4 = 16 * src_h / dst_h; + if (x_step_q4 > 64 || y_step_q4 > 64) { + // This function is only called while cm->bit_depth is VPX_BITS_8. +#if CONFIG_VP9_HIGHBITDEPTH + vp9_scale_and_extend_frame_nonnormative(src, dst, (int)VPX_BITS_8); +#else + vp9_scale_and_extend_frame_nonnormative(src, dst); +#endif // CONFIG_VP9_HIGHBITDEPTH + return; + } + for (i = 0; i < MAX_MB_PLANE; ++i) { const int factor = (i == 0 || i == 3 ? 1 : 2); const int src_stride = src_strides[i]; diff --git a/libs/libvpx/vp9/encoder/vp9_lookahead.c b/libs/libvpx/vp9/encoder/vp9_lookahead.c index 97838c38e6..ba4fe3d3b7 100644 --- a/libs/libvpx/vp9/encoder/vp9_lookahead.c +++ b/libs/libvpx/vp9/encoder/vp9_lookahead.c @@ -9,6 +9,7 @@ */ #include #include +#include #include "./vpx_config.h" @@ -81,7 +82,6 @@ bail: return NULL; } -#define USE_PARTIAL_COPY 0 int vp9_lookahead_full(const struct lookahead_ctx *ctx) { return ctx->sz + 1 + MAX_PRE_FRAMES > ctx->max_sz; } @@ -94,11 +94,6 @@ int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src, int64_t ts_start, int64_t ts_end, int use_highbitdepth, vpx_enc_frame_flags_t flags) { struct lookahead_entry *buf; -#if USE_PARTIAL_COPY - int row, col, active_end; - int mb_rows = (src->y_height + 15) >> 4; - int mb_cols = (src->y_width + 15) >> 4; -#endif int width = src->y_crop_width; int height = src->y_crop_height; int uv_width = src->uv_crop_width; @@ -119,76 +114,44 @@ int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src, height != buf->img.y_crop_height || uv_width != buf->img.uv_crop_width || uv_height != buf->img.uv_crop_height; - larger_dimensions = width > buf->img.y_width || height > buf->img.y_height || - uv_width > buf->img.uv_width || - uv_height > buf->img.uv_height; + larger_dimensions = + width > buf->img.y_crop_width || height > buf->img.y_crop_height || + uv_width > buf->img.uv_crop_width || uv_height > buf->img.uv_crop_height; assert(!larger_dimensions || new_dimensions); -#if USE_PARTIAL_COPY - // TODO(jkoleszar): This is disabled for now, as - // vp9_copy_and_extend_frame_with_rect is not subsampling/alpha aware. - - // Only do this partial copy if the following conditions are all met: - // 1. Lookahead queue has has size of 1. - // 2. Active map is provided. - // 3. This is not a key frame, golden nor altref frame. - if (!new_dimensions && ctx->max_sz == 1 && active_map && !flags) { - for (row = 0; row < mb_rows; ++row) { - col = 0; - - while (1) { - // Find the first active macroblock in this row. - for (; col < mb_cols; ++col) { - if (active_map[col]) break; - } - - // No more active macroblock in this row. - if (col == mb_cols) break; - - // Find the end of active region in this row. - active_end = col; - - for (; active_end < mb_cols; ++active_end) { - if (!active_map[active_end]) break; - } - - // Only copy this active region. - vp9_copy_and_extend_frame_with_rect(src, &buf->img, row << 4, col << 4, - 16, (active_end - col) << 4); - - // Start again from the end of this active region. - col = active_end; - } - - active_map += mb_cols; - } - } else { -#endif - if (larger_dimensions) { - YV12_BUFFER_CONFIG new_img; - memset(&new_img, 0, sizeof(new_img)); - if (vpx_alloc_frame_buffer(&new_img, width, height, subsampling_x, - subsampling_y, + if (larger_dimensions) { + YV12_BUFFER_CONFIG new_img; + memset(&new_img, 0, sizeof(new_img)); + if (vpx_alloc_frame_buffer(&new_img, width, height, subsampling_x, + subsampling_y, #if CONFIG_VP9_HIGHBITDEPTH - use_highbitdepth, + use_highbitdepth, #endif - VP9_ENC_BORDER_IN_PIXELS, 0)) - return 1; - vpx_free_frame_buffer(&buf->img); - buf->img = new_img; - } else if (new_dimensions) { - buf->img.y_crop_width = src->y_crop_width; - buf->img.y_crop_height = src->y_crop_height; - buf->img.uv_crop_width = src->uv_crop_width; - buf->img.uv_crop_height = src->uv_crop_height; - buf->img.subsampling_x = src->subsampling_x; - buf->img.subsampling_y = src->subsampling_y; - } - // Partial copy not implemented yet - vp9_copy_and_extend_frame(src, &buf->img); -#if USE_PARTIAL_COPY + VP9_ENC_BORDER_IN_PIXELS, 0)) + return 1; + vpx_free_frame_buffer(&buf->img); + buf->img = new_img; + } else if (new_dimensions) { + int aligned_width = ALIGN_POWER_OF_TWO(width, 3); + buf->img.y_width = src->y_width; + buf->img.y_height = src->y_height; + buf->img.uv_width = src->uv_width; + buf->img.uv_height = src->uv_height; + buf->img.y_crop_width = src->y_crop_width; + buf->img.y_crop_height = src->y_crop_height; + buf->img.uv_crop_width = src->uv_crop_width; + buf->img.uv_crop_height = src->uv_crop_height; + buf->img.subsampling_x = src->subsampling_x; + buf->img.subsampling_y = src->subsampling_y; + // Here the new width (src->y_crop_width) is <= the previous width + // (since otherwise it would enter the "larger_dimensions" code), so + // it is safe here to update the stride. + // The stride setting is taken from vpx_alloc_frame_buffer(). + buf->img.y_stride = + ALIGN_POWER_OF_TWO((aligned_width + 2 * buf->img.border), 5); + buf->img.uv_stride = buf->img.y_stride >> subsampling_x; } -#endif + vp9_copy_and_extend_frame(src, &buf->img); buf->ts_start = ts_start; buf->ts_end = ts_end; diff --git a/libs/libvpx/vp9/encoder/vp9_mbgraph.c b/libs/libvpx/vp9/encoder/vp9_mbgraph.c index 7c2790cb98..2f20a8fe6d 100644 --- a/libs/libvpx/vp9/encoder/vp9_mbgraph.c +++ b/libs/libvpx/vp9/encoder/vp9_mbgraph.c @@ -98,8 +98,7 @@ static int do_16x16_motion_search(VP9_COMP *cpi, const MV *ref_mv, // If the current best reference mv is not centered on 0,0 then do a 0,0 // based search as well. if (ref_mv->row != 0 || ref_mv->col != 0) { - unsigned int tmp_err; - MV zero_ref_mv = { 0, 0 }, tmp_mv; + MV zero_ref_mv = { 0, 0 }; tmp_err = do_16x16_motion_iteration(cpi, &zero_ref_mv, &tmp_mv, mb_row, mb_col); @@ -238,7 +237,7 @@ static void update_mbgraph_frame_stats(VP9_COMP *cpi, xd->mi[0] = &mi_local; mi_local.sb_type = BLOCK_16X16; mi_local.ref_frame[0] = LAST_FRAME; - mi_local.ref_frame[1] = NONE; + mi_local.ref_frame[1] = NO_REF_FRAME; for (mb_row = 0; mb_row < cm->mb_rows; mb_row++) { MV gld_left_mv = gld_top_mv; @@ -289,7 +288,7 @@ static void separate_arf_mbs(VP9_COMP *cpi) { int *arf_not_zz; CHECK_MEM_ERROR( - cm, arf_not_zz, + &cm->error, arf_not_zz, vpx_calloc(cm->mb_rows * cm->mb_cols * sizeof(*arf_not_zz), 1)); // We are not interested in results beyond the alt ref itself. @@ -334,23 +333,16 @@ static void separate_arf_mbs(VP9_COMP *cpi) { } } - // Only bother with segmentation if over 10% of the MBs in static segment - // if ( ncnt[1] && (ncnt[0] / ncnt[1] < 10) ) - if (1) { - // Note % of blocks that are marked as static - if (cm->MBs) - cpi->static_mb_pct = (ncnt[1] * 100) / (cm->mi_rows * cm->mi_cols); + // Note % of blocks that are marked as static + if (cm->MBs) + cpi->static_mb_pct = (ncnt[1] * 100) / (cm->mi_rows * cm->mi_cols); - // This error case should not be reachable as this function should - // never be called with the common data structure uninitialized. - else - cpi->static_mb_pct = 0; - - vp9_enable_segmentation(&cm->seg); - } else { + // This error case should not be reachable as this function should + // never be called with the common data structure uninitialized. + else cpi->static_mb_pct = 0; - vp9_disable_segmentation(&cm->seg); - } + + vp9_enable_segmentation(&cm->seg); // Free localy allocated storage vpx_free(arf_not_zz); diff --git a/libs/libvpx/vp9/encoder/vp9_mcomp.c b/libs/libvpx/vp9/encoder/vp9_mcomp.c index 1f08aa5de7..5576fab587 100644 --- a/libs/libvpx/vp9/encoder/vp9_mcomp.c +++ b/libs/libvpx/vp9/encoder/vp9_mcomp.c @@ -77,14 +77,6 @@ int vp9_init_search_range(int size) { return sr; } -static INLINE int mv_cost(const MV *mv, const int *joint_cost, - int *const comp_cost[2]) { - assert(mv->row >= -MV_MAX && mv->row < MV_MAX); - assert(mv->col >= -MV_MAX && mv->col < MV_MAX); - return joint_cost[vp9_get_mv_joint(mv)] + comp_cost[0][mv->row] + - comp_cost[1][mv->col]; -} - int vp9_mv_bit_cost(const MV *mv, const MV *ref, const int *mvjcost, int *mvcost[2], int weight) { const MV diff = { mv->row - ref->row, mv->col - ref->col }; @@ -103,15 +95,6 @@ static int mv_err_cost(const MV *mv, const MV *ref, const int *mvjcost, } return 0; } - -static int mvsad_err_cost(const MACROBLOCK *x, const MV *mv, const MV *ref, - int sad_per_bit) { - const MV diff = { mv->row - ref->row, mv->col - ref->col }; - return ROUND_POWER_OF_TWO( - (unsigned)mv_cost(&diff, x->nmvjointsadcost, x->nmvsadcost) * sad_per_bit, - VP9_PROB_COST_SHIFT); -} - void vp9_init_dsmotion_compensation(search_site_config *cfg, int stride) { int len; int ss_count = 0; @@ -163,8 +146,8 @@ static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c) { do { \ if (c >= minc && c <= maxc && r >= minr && r <= maxr) { \ int64_t tmpmse; \ - const MV mv = { r, c }; \ - const MV ref_mv = { rr, rc }; \ + const MV cb_mv = { r, c }; \ + const MV cb_ref_mv = { rr, rc }; \ if (second_pred == NULL) { \ thismse = vfp->svf(pre(y, y_stride, r, c), y_stride, sp(c), sp(r), z, \ src_stride, &sse); \ @@ -173,7 +156,8 @@ static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c) { src_stride, &sse, second_pred); \ } \ tmpmse = thismse; \ - tmpmse += mv_err_cost(&mv, &ref_mv, mvjcost, mvcost, error_per_bit); \ + tmpmse += \ + mv_err_cost(&cb_mv, &cb_ref_mv, mvjcost, mvcost, error_per_bit); \ if (tmpmse >= INT_MAX) { \ v = INT_MAX; \ } else if ((v = (uint32_t)tmpmse) < besterr) { \ @@ -192,15 +176,16 @@ static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c) { #define CHECK_BETTER(v, r, c) \ do { \ if (c >= minc && c <= maxc && r >= minr && r <= maxr) { \ - const MV mv = { r, c }; \ - const MV ref_mv = { rr, rc }; \ + const MV cb_mv = { r, c }; \ + const MV cb_ref_mv = { rr, rc }; \ if (second_pred == NULL) \ thismse = vfp->svf(pre(y, y_stride, r, c), y_stride, sp(c), sp(r), z, \ src_stride, &sse); \ else \ thismse = vfp->svaf(pre(y, y_stride, r, c), y_stride, sp(c), sp(r), z, \ src_stride, &sse, second_pred); \ - if ((v = mv_err_cost(&mv, &ref_mv, mvjcost, mvcost, error_per_bit) + \ + if ((v = mv_err_cost(&cb_mv, &cb_ref_mv, mvjcost, mvcost, \ + error_per_bit) + \ thismse) < besterr) { \ besterr = v; \ br = r; \ @@ -312,7 +297,7 @@ static unsigned int setup_center_error( besterr = vfp->vf(CONVERT_TO_BYTEPTR(comp_pred16), w, src, src_stride, sse1); } else { - DECLARE_ALIGNED(16, uint8_t, comp_pred[64 * 64]); + DECLARE_ALIGNED(32, uint8_t, comp_pred[64 * 64]); vpx_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride); besterr = vfp->vf(comp_pred, w, src, src_stride, sse1); } @@ -327,7 +312,7 @@ static unsigned int setup_center_error( uint32_t besterr; (void)xd; if (second_pred != NULL) { - DECLARE_ALIGNED(16, uint8_t, comp_pred[64 * 64]); + DECLARE_ALIGNED(32, uint8_t, comp_pred[64 * 64]); vpx_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride); besterr = vfp->vf(comp_pred, w, src, src_stride, sse1); } else { @@ -650,7 +635,7 @@ static int accurate_sub_pel_search( vp9_build_inter_predictor(pre_address, y_stride, pred, w, this_mv, sf, w, h, 0, kernel, MV_PRECISION_Q3, 0, 0); if (second_pred != NULL) { - DECLARE_ALIGNED(16, uint8_t, comp_pred[64 * 64]); + DECLARE_ALIGNED(32, uint8_t, comp_pred[64 * 64]); vpx_comp_avg_pred(comp_pred, second_pred, w, h, pred, w); besterr = vfp->vf(comp_pred, w, src_address, src_stride, sse); } else { @@ -669,7 +654,7 @@ static int accurate_sub_pel_search( vp9_build_inter_predictor(pre_address, y_stride, pred, w, this_mv, sf, w, h, 0, kernel, MV_PRECISION_Q3, 0, 0); if (second_pred != NULL) { - DECLARE_ALIGNED(16, uint8_t, comp_pred[64 * 64]); + DECLARE_ALIGNED(32, uint8_t, comp_pred[64 * 64]); vpx_comp_avg_pred(comp_pred, second_pred, w, h, pred, w); besterr = vfp->vf(comp_pred, w, src_address, src_stride, sse); } else { @@ -686,13 +671,14 @@ static int accurate_sub_pel_search( do { \ if (c >= minc && c <= maxc && r >= minr && r <= maxr) { \ int64_t tmpmse; \ - const MV mv = { r, c }; \ - const MV ref_mv = { rr, rc }; \ - thismse = accurate_sub_pel_search(xd, &mv, x->me_sf, kernel, vfp, z, \ + const MV cb_mv = { r, c }; \ + const MV cb_ref_mv = { rr, rc }; \ + thismse = accurate_sub_pel_search(xd, &cb_mv, x->me_sf, kernel, vfp, z, \ src_stride, y, y_stride, second_pred, \ w, h, &sse); \ tmpmse = thismse; \ - tmpmse += mv_err_cost(&mv, &ref_mv, mvjcost, mvcost, error_per_bit); \ + tmpmse += \ + mv_err_cost(&cb_mv, &cb_ref_mv, mvjcost, mvcost, error_per_bit); \ if (tmpmse >= INT_MAX) { \ v = INT_MAX; \ } else if ((v = (uint32_t)tmpmse) < besterr) { \ @@ -711,12 +697,13 @@ static int accurate_sub_pel_search( #define CHECK_BETTER1(v, r, c) \ do { \ if (c >= minc && c <= maxc && r >= minr && r <= maxr) { \ - const MV mv = { r, c }; \ - const MV ref_mv = { rr, rc }; \ - thismse = accurate_sub_pel_search(xd, &mv, x->me_sf, kernel, vfp, z, \ + const MV cb_mv = { r, c }; \ + const MV cb_ref_mv = { rr, rc }; \ + thismse = accurate_sub_pel_search(xd, &cb_mv, x->me_sf, kernel, vfp, z, \ src_stride, y, y_stride, second_pred, \ w, h, &sse); \ - if ((v = mv_err_cost(&mv, &ref_mv, mvjcost, mvcost, error_per_bit) + \ + if ((v = mv_err_cost(&cb_mv, &cb_ref_mv, mvjcost, mvcost, \ + error_per_bit) + \ thismse) < besterr) { \ besterr = v; \ br = r; \ @@ -966,7 +953,7 @@ static INLINE int is_mv_in(const MvLimits *mv_limits, const MV *mv) { } #define MAX_PATTERN_SCALES 11 -#define MAX_PATTERN_CANDIDATES 8 // max number of canddiates per scale +#define MAX_PATTERN_CANDIDATES 8 // max number of candidates per scale #define PATTERN_CANDIDATES_REF 3 // number of refinement candidates // Calculate and return a sad+mvcost list around an integer best pel. @@ -980,16 +967,14 @@ static INLINE void calc_int_cost_list(const MACROBLOCK *x, const MV *ref_mv, const MV fcenter_mv = { ref_mv->row >> 3, ref_mv->col >> 3 }; int br = best_mv->row; int bc = best_mv->col; - MV this_mv; + const MV mv = { br, bc }; int i; unsigned int sse; - this_mv.row = br; - this_mv.col = bc; cost_list[0] = - fn_ptr->vf(what->buf, what->stride, get_buf_from_mv(in_what, &this_mv), + fn_ptr->vf(what->buf, what->stride, get_buf_from_mv(in_what, &mv), in_what->stride, &sse) + - mvsad_err_cost(x, &this_mv, &fcenter_mv, sadpb); + mvsad_err_cost(x, &mv, &fcenter_mv, sadpb); if (check_bounds(&x->mv_limits, br, bc, 1)) { for (i = 0; i < 4; i++) { const MV this_mv = { br + neighbors[i].row, bc + neighbors[i].col }; @@ -1049,7 +1034,7 @@ static int vp9_pattern_search( in_what->stride) + mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); - // Search all possible scales upto the search param around the center point + // Search all possible scales up to the search param around the center point // pick the scale of the point that is best as the starting scale of // further steps around it. if (do_init_search) { @@ -1170,6 +1155,9 @@ static int vp9_pattern_search( } while (s--); } + best_mv->row = br; + best_mv->col = bc; + // Returns the one-away integer pel sad values around the best as follows: // cost_list[0]: cost at the best integer pel // cost_list[1]: cost at delta {0, -1} (left) from the best integer pel @@ -1177,11 +1165,8 @@ static int vp9_pattern_search( // cost_list[3]: cost at delta { 0, 1} (right) from the best integer pel // cost_list[4]: cost at delta {-1, 0} (top) from the best integer pel if (cost_list) { - const MV best_mv = { br, bc }; - calc_int_cost_list(x, &fcenter_mv, sad_per_bit, vfp, &best_mv, cost_list); + calc_int_cost_list(x, &fcenter_mv, sad_per_bit, vfp, best_mv, cost_list); } - best_mv->row = br; - best_mv->col = bc; return bestsad; } @@ -1223,7 +1208,7 @@ static int vp9_pattern_search_sad( in_what->stride) + mvsad_err_cost(x, ref_mv, &fcenter_mv, sad_per_bit); - // Search all possible scales upto the search param around the center point + // Search all possible scales up to the search param around the center point // pick the scale of the point that is best as the starting scale of // further steps around it. if (do_init_search) { @@ -1883,8 +1868,8 @@ static int64_t full_pixel_exhaustive_new(const VP9_COMP *cpi, MACROBLOCK *x, // Check size of proposed first range against magnitude of the centre // value used as a starting point. - range = VPXMAX(range, (5 * VPXMAX(abs(temp_mv.row), abs(temp_mv.col))) / 4); - range = VPXMIN(range, MAX_RANGE); + range = clamp(range, (5 * VPXMAX(abs(temp_mv.row), abs(temp_mv.col))) / 4, + MAX_RANGE); interval = VPXMAX(interval, range / baseline_interval_divisor); // initial search @@ -2068,9 +2053,9 @@ int vp9_prepare_nb_full_mvs(const MotionField *motion_field, int mi_row, #endif // CONFIG_NON_GREEDY_MV int vp9_diamond_search_sad_c(const MACROBLOCK *x, const search_site_config *cfg, - MV *ref_mv, MV *best_mv, int search_param, - int sad_per_bit, int *num00, - const vp9_variance_fn_ptr_t *fn_ptr, + MV *ref_mv, uint32_t start_mv_sad, MV *best_mv, + int search_param, int sad_per_bit, int *num00, + const vp9_sad_fn_ptr_t *sad_fn_ptr, const MV *center_mv) { int i, j, step; @@ -2081,7 +2066,7 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x, const search_site_config *cfg, const int in_what_stride = xd->plane[0].pre[0].stride; const uint8_t *best_address; - unsigned int bestsad = INT_MAX; + unsigned int bestsad = start_mv_sad; int best_site = -1; int last_site = -1; @@ -2099,8 +2084,6 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x, const search_site_config *cfg, const int tot_steps = cfg->total_steps - search_param; const MV fcenter_mv = { center_mv->row >> 3, center_mv->col >> 3 }; - clamp_mv(ref_mv, x->mv_limits.col_min, x->mv_limits.col_max, - x->mv_limits.row_min, x->mv_limits.row_max); ref_row = ref_mv->row; ref_col = ref_mv->col; *num00 = 0; @@ -2111,10 +2094,6 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x, const search_site_config *cfg, in_what = xd->plane[0].pre[0].buf + ref_row * in_what_stride + ref_col; best_address = in_what; - // Check the starting position - bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride) + - mvsad_err_cost(x, best_mv, &fcenter_mv, sad_per_bit); - i = 0; for (step = 0; step < tot_steps; step++) { @@ -2138,8 +2117,8 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x, const search_site_config *cfg, for (t = 0; t < 4; t++) block_offset[t] = ss_os[i + t] + best_address; - fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride, - sad_array); + sad_fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride, + sad_array); for (t = 0; t < 4; t++, i++) { if (sad_array[t] < bestsad) { @@ -2163,7 +2142,7 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x, const search_site_config *cfg, if (is_mv_in(&x->mv_limits, &this_mv)) { const uint8_t *const check_here = ss_os[i] + best_address; unsigned int thissad = - fn_ptr->sdf(what, what_stride, check_here, in_what_stride); + sad_fn_ptr->sdf(what, what_stride, check_here, in_what_stride); if (thissad < bestsad) { thissad += mvsad_err_cost(x, &this_mv, &fcenter_mv, sad_per_bit); @@ -2298,7 +2277,6 @@ unsigned int vp9_int_pro_motion_estimation(const VP9_COMP *cpi, MACROBLOCK *x, const int search_width = bw << 1; const int search_height = bh << 1; const int src_stride = x->plane[0].src.stride; - const int ref_stride = xd->plane[0].pre[0].stride; uint8_t const *ref_buf, *src_buf; MV *tmp_mv = &xd->mi[0]->mv[0].as_mv; unsigned int best_sad, tmp_sad, this_sad[4]; @@ -2309,6 +2287,8 @@ unsigned int vp9_int_pro_motion_estimation(const VP9_COMP *cpi, MACROBLOCK *x, MvLimits subpel_mv_limits; if (scaled_ref_frame) { + assert(scaled_ref_frame->y_width == cpi->Source->y_width && + scaled_ref_frame->y_height == cpi->Source->y_height); int i; // Swap out the reference frame for a version that's been scaled to // match the resolution of the current frame, allowing the existing @@ -2316,22 +2296,22 @@ unsigned int vp9_int_pro_motion_estimation(const VP9_COMP *cpi, MACROBLOCK *x, for (i = 0; i < MAX_MB_PLANE; i++) backup_yv12[i] = xd->plane[i].pre[0]; vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); } + const int ref_stride = xd->plane[0].pre[0].stride; #if CONFIG_VP9_HIGHBITDEPTH // TODO(jingning): Implement integral projection functions for high bit-depth // setting and remove this part of code. if (xd->bd != 8) { - unsigned int this_sad; + const unsigned int sad = cpi->fn_ptr[bsize].sdf( + x->plane[0].src.buf, src_stride, xd->plane[0].pre[0].buf, ref_stride); tmp_mv->row = 0; tmp_mv->col = 0; - this_sad = cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf, src_stride, - xd->plane[0].pre[0].buf, ref_stride); if (scaled_ref_frame) { int i; for (i = 0; i < MAX_MB_PLANE; i++) xd->plane[i].pre[0] = backup_yv12[i]; } - return this_sad; + return sad; } #endif @@ -2506,15 +2486,54 @@ int vp9_full_pixel_diamond_new(const VP9_COMP *cpi, MACROBLOCK *x, point as the best match, we will do a final 1-away diamond refining search */ static int full_pixel_diamond(const VP9_COMP *const cpi, - const MACROBLOCK *const x, MV *mvp_full, - int step_param, int sadpb, int further_steps, - int do_refine, int *cost_list, + const MACROBLOCK *const x, BLOCK_SIZE bsize, + MV *mvp_full, int step_param, int sadpb, + int further_steps, int do_refine, + int use_downsampled_sad, int *cost_list, const vp9_variance_fn_ptr_t *fn_ptr, const MV *ref_mv, MV *dst_mv) { MV temp_mv; int thissme, n, num00 = 0; - int bestsme = cpi->diamond_search_sad(x, &cpi->ss_cfg, mvp_full, &temp_mv, - step_param, sadpb, &n, fn_ptr, ref_mv); + int bestsme; + const int src_buf_stride = x->plane[0].src.stride; + const uint8_t *const src_buf = x->plane[0].src.buf; + const MACROBLOCKD *const xd = &x->e_mbd; + const int pred_buf_stride = xd->plane[0].pre[0].stride; + uint8_t *pred_buf; + vp9_sad_fn_ptr_t sad_fn_ptr; + unsigned int start_mv_sad, start_mv_sad_even_rows, start_mv_sad_odd_rows; + const MV ref_mv_full = { ref_mv->row >> 3, ref_mv->col >> 3 }; + clamp_mv(mvp_full, x->mv_limits.col_min, x->mv_limits.col_max, + x->mv_limits.row_min, x->mv_limits.row_max); + + pred_buf = + xd->plane[0].pre[0].buf + mvp_full->row * pred_buf_stride + mvp_full->col; + start_mv_sad_even_rows = + fn_ptr->sdsf(src_buf, src_buf_stride, pred_buf, pred_buf_stride); + start_mv_sad_odd_rows = + fn_ptr->sdsf(src_buf + src_buf_stride, src_buf_stride, + pred_buf + pred_buf_stride, pred_buf_stride); + start_mv_sad = (start_mv_sad_even_rows + start_mv_sad_odd_rows) >> 1; + start_mv_sad += mvsad_err_cost(x, mvp_full, &ref_mv_full, sadpb); + + sad_fn_ptr.sdf = fn_ptr->sdf; + sad_fn_ptr.sdx4df = fn_ptr->sdx4df; + if (use_downsampled_sad && num_4x4_blocks_high_lookup[bsize] >= 2) { + // If the absolute difference between the pred-to-src SAD of even rows and + // the pred-to-src SAD of odd rows is small, skip every other row in sad + // computation. + const int odd_to_even_diff_sad = + abs((int)start_mv_sad_even_rows - (int)start_mv_sad_odd_rows); + const int mult_thresh = 10; + if (odd_to_even_diff_sad * mult_thresh < (int)start_mv_sad_even_rows) { + sad_fn_ptr.sdf = fn_ptr->sdsf; + sad_fn_ptr.sdx4df = fn_ptr->sdsx4df; + } + } + + bestsme = + cpi->diamond_search_sad(x, &cpi->ss_cfg, mvp_full, start_mv_sad, &temp_mv, + step_param, sadpb, &n, &sad_fn_ptr, ref_mv); if (bestsme < INT_MAX) bestsme = vp9_get_mvpred_var(x, &temp_mv, ref_mv, fn_ptr, 1); *dst_mv = temp_mv; @@ -2529,9 +2548,9 @@ static int full_pixel_diamond(const VP9_COMP *const cpi, if (num00) { num00--; } else { - thissme = cpi->diamond_search_sad(x, &cpi->ss_cfg, mvp_full, &temp_mv, - step_param + n, sadpb, &num00, fn_ptr, - ref_mv); + thissme = cpi->diamond_search_sad(x, &cpi->ss_cfg, mvp_full, start_mv_sad, + &temp_mv, step_param + n, sadpb, &num00, + &sad_fn_ptr, ref_mv); if (thissme < INT_MAX) thissme = vp9_get_mvpred_var(x, &temp_mv, ref_mv, fn_ptr, 1); @@ -2549,8 +2568,8 @@ static int full_pixel_diamond(const VP9_COMP *const cpi, if (do_refine) { const int search_range = 8; MV best_mv = *dst_mv; - thissme = vp9_refining_search_sad(x, &best_mv, sadpb, search_range, fn_ptr, - ref_mv); + thissme = vp9_refining_search_sad(x, &best_mv, sadpb, search_range, + &sad_fn_ptr, ref_mv); if (thissme < INT_MAX) thissme = vp9_get_mvpred_var(x, &best_mv, ref_mv, fn_ptr, 1); if (thissme < bestsme) { @@ -2559,6 +2578,27 @@ static int full_pixel_diamond(const VP9_COMP *const cpi, } } + if (sad_fn_ptr.sdf != fn_ptr->sdf) { + // If we are skipping rows when we perform the motion search, we need to + // check the quality of skipping. If it's bad, then we run search with + // skip row features off. + const uint8_t *best_address = get_buf_from_mv(&xd->plane[0].pre[0], dst_mv); + const int sad = + fn_ptr->sdf(src_buf, src_buf_stride, best_address, pred_buf_stride); + const int skip_sad = + fn_ptr->sdsf(src_buf, src_buf_stride, best_address, pred_buf_stride); + // We will keep the result of skipping rows if it's good enough. + const int kSADThresh = + 1 << (b_width_log2_lookup[bsize] + b_height_log2_lookup[bsize]); + if (sad > kSADThresh && abs(skip_sad - sad) * 10 >= VPXMAX(sad, 1) * 9) { + // There is a large discrepancy between skipping and not skipping, so we + // need to redo the motion search. + return full_pixel_diamond(cpi, x, bsize, mvp_full, step_param, sadpb, + further_steps, do_refine, 0, cost_list, fn_ptr, + ref_mv, dst_mv); + } + } + // Return cost list. if (cost_list) { calc_int_cost_list(x, ref_mv, sadpb, fn_ptr, dst_mv, cost_list); @@ -2591,8 +2631,8 @@ static int full_pixel_exhaustive(const VP9_COMP *const cpi, // Check size of proposed first range against magnitude of the centre // value used as a starting point. - range = VPXMAX(range, (5 * VPXMAX(abs(temp_mv.row), abs(temp_mv.col))) / 4); - range = VPXMIN(range, MAX_RANGE); + range = clamp(range, (5 * VPXMAX(abs(temp_mv.row), abs(temp_mv.col))) / 4, + MAX_RANGE); interval = VPXMAX(interval, range / baseline_interval_divisor); // initial search @@ -2710,7 +2750,7 @@ int64_t vp9_refining_search_sad_new(const MACROBLOCK *x, MV *best_full_mv, int vp9_refining_search_sad(const MACROBLOCK *x, MV *ref_mv, int error_per_bit, int search_range, - const vp9_variance_fn_ptr_t *fn_ptr, + const vp9_sad_fn_ptr_t *sad_fn_ptr, const MV *center_mv) { const MACROBLOCKD *const xd = &x->e_mbd; const MV neighbors[4] = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } }; @@ -2719,7 +2759,7 @@ int vp9_refining_search_sad(const MACROBLOCK *x, MV *ref_mv, int error_per_bit, const MV fcenter_mv = { center_mv->row >> 3, center_mv->col >> 3 }; const uint8_t *best_address = get_buf_from_mv(in_what, ref_mv); unsigned int best_sad = - fn_ptr->sdf(what->buf, what->stride, best_address, in_what->stride) + + sad_fn_ptr->sdf(what->buf, what->stride, best_address, in_what->stride) + mvsad_err_cost(x, ref_mv, &fcenter_mv, error_per_bit); int i, j; @@ -2736,7 +2776,8 @@ int vp9_refining_search_sad(const MACROBLOCK *x, MV *ref_mv, int error_per_bit, best_address - 1, best_address + 1, best_address + in_what->stride }; - fn_ptr->sdx4df(what->buf, what->stride, positions, in_what->stride, sads); + sad_fn_ptr->sdx4df(what->buf, what->stride, positions, in_what->stride, + sads); for (j = 0; j < 4; ++j) { if (sads[j] < best_sad) { @@ -2756,8 +2797,8 @@ int vp9_refining_search_sad(const MACROBLOCK *x, MV *ref_mv, int error_per_bit, if (is_mv_in(&x->mv_limits, &mv)) { unsigned int sad = - fn_ptr->sdf(what->buf, what->stride, - get_buf_from_mv(in_what, &mv), in_what->stride); + sad_fn_ptr->sdf(what->buf, what->stride, + get_buf_from_mv(in_what, &mv), in_what->stride); if (sad < best_sad) { sad += mvsad_err_cost(x, &mv, &fcenter_mv, error_per_bit); if (sad < best_sad) { @@ -2874,9 +2915,10 @@ int vp9_full_pixel_search(const VP9_COMP *const cpi, const MACROBLOCK *const x, break; case NSTEP: case MESH: - var = full_pixel_diamond(cpi, x, mvp_full, step_param, error_per_bit, - MAX_MVSEARCH_STEPS - 1 - step_param, 1, - cost_list, fn_ptr, ref_mv, tmp_mv); + var = full_pixel_diamond( + cpi, x, bsize, mvp_full, step_param, error_per_bit, + MAX_MVSEARCH_STEPS - 1 - step_param, 1, + cpi->sf.mv.use_downsampled_sad, cost_list, fn_ptr, ref_mv, tmp_mv); break; default: assert(0 && "Unknown search method"); } diff --git a/libs/libvpx/vp9/encoder/vp9_mcomp.h b/libs/libvpx/vp9/encoder/vp9_mcomp.h index bdaf2ce77d..fd6a8b9aca 100644 --- a/libs/libvpx/vp9/encoder/vp9_mcomp.h +++ b/libs/libvpx/vp9/encoder/vp9_mcomp.h @@ -41,6 +41,11 @@ typedef struct search_site_config { int total_steps; } search_site_config; +typedef struct vp9_sad_table { + vpx_sad_fn_t sdf; + vpx_sad_multi_d_fn_t sdx4df; +} vp9_sad_fn_ptr_t; + static INLINE const uint8_t *get_buf_from_mv(const struct buf_2d *buf, const MV *mv) { return &buf->buf[mv->row * buf->stride + mv->col]; @@ -63,12 +68,13 @@ int vp9_get_mvpred_av_var(const MACROBLOCK *x, const MV *best_mv, struct VP9_COMP; struct SPEED_FEATURES; +struct vp9_sad_table; int vp9_init_search_range(int size); int vp9_refining_search_sad(const struct macroblock *x, struct mv *ref_mv, int error_per_bit, int search_range, - const struct vp9_variance_vtable *fn_ptr, + const struct vp9_sad_table *sad_fn_ptr, const struct mv *center_mv); // Perform integral projection based motion estimation. @@ -94,9 +100,9 @@ extern fractional_mv_step_fp vp9_return_max_sub_pixel_mv; extern fractional_mv_step_fp vp9_return_min_sub_pixel_mv; typedef int (*vp9_diamond_search_fn_t)( - const MACROBLOCK *x, const search_site_config *cfg, MV *ref_mv, MV *best_mv, - int search_param, int sad_per_bit, int *num00, - const vp9_variance_fn_ptr_t *fn_ptr, const MV *center_mv); + const MACROBLOCK *x, const search_site_config *cfg, MV *ref_mv, + uint32_t start_mv_sad, MV *best_mv, int search_param, int sad_per_bit, + int *num00, const vp9_sad_fn_ptr_t *sad_fn_ptr, const MV *center_mv); int vp9_refining_search_8p_c(const MACROBLOCK *x, MV *ref_mv, int error_per_bit, int search_range, diff --git a/libs/libvpx/vp9/encoder/vp9_multi_thread.c b/libs/libvpx/vp9/encoder/vp9_multi_thread.c index 45659f2a9a..8437ce7531 100644 --- a/libs/libvpx/vp9/encoder/vp9_multi_thread.c +++ b/libs/libvpx/vp9/encoder/vp9_multi_thread.c @@ -10,6 +10,7 @@ #include +#include "vpx_util/vpx_pthread.h" #include "vp9/encoder/vp9_encoder.h" #include "vp9/encoder/vp9_ethread.h" #include "vp9/encoder/vp9_multi_thread.h" @@ -54,16 +55,23 @@ void *vp9_enc_grp_get_next_job(MultiThreadHandle *multi_thread_ctxt, void vp9_row_mt_alloc_rd_thresh(VP9_COMP *const cpi, TileDataEnc *const this_tile) { VP9_COMMON *const cm = &cpi->common; - const int sb_rows = - (mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2) + 1; + const int sb_rows = mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2; int i; + if (this_tile->row_base_thresh_freq_fact != NULL) { + if (sb_rows <= this_tile->sb_rows) { + return; + } + vpx_free(this_tile->row_base_thresh_freq_fact); + this_tile->row_base_thresh_freq_fact = NULL; + } CHECK_MEM_ERROR( - cm, this_tile->row_base_thresh_freq_fact, + &cm->error, this_tile->row_base_thresh_freq_fact, (int *)vpx_calloc(sb_rows * BLOCK_SIZES * MAX_MODES, sizeof(*(this_tile->row_base_thresh_freq_fact)))); for (i = 0; i < sb_rows * BLOCK_SIZES * MAX_MODES; i++) this_tile->row_base_thresh_freq_fact[i] = RD_THRESH_INIT_FACT; + this_tile->sb_rows = sb_rows; } void vp9_row_mt_mem_alloc(VP9_COMP *cpi) { @@ -85,7 +93,7 @@ void vp9_row_mt_mem_alloc(VP9_COMP *cpi) { multi_thread_ctxt->allocated_tile_rows = tile_rows; multi_thread_ctxt->allocated_vert_unit_rows = jobs_per_tile_col; - CHECK_MEM_ERROR(cm, multi_thread_ctxt->job_queue, + CHECK_MEM_ERROR(&cm->error, multi_thread_ctxt->job_queue, (JobQueue *)vpx_memalign(32, total_jobs * sizeof(JobQueue))); #if CONFIG_MULTITHREAD @@ -100,13 +108,6 @@ void vp9_row_mt_mem_alloc(VP9_COMP *cpi) { for (tile_col = 0; tile_col < tile_cols; tile_col++) { TileDataEnc *this_tile = &cpi->tile_data[tile_col]; vp9_row_mt_sync_mem_alloc(&this_tile->row_mt_sync, cm, jobs_per_tile_col); - if (cpi->sf.adaptive_rd_thresh_row_mt) { - if (this_tile->row_base_thresh_freq_fact != NULL) { - vpx_free(this_tile->row_base_thresh_freq_fact); - this_tile->row_base_thresh_freq_fact = NULL; - } - vp9_row_mt_alloc_rd_thresh(cpi, this_tile); - } } // Assign the sync pointer of tile row zero for every tile row > 0 @@ -135,14 +136,17 @@ void vp9_row_mt_mem_dealloc(VP9_COMP *cpi) { #endif // Deallocate memory for job queue - if (multi_thread_ctxt->job_queue) vpx_free(multi_thread_ctxt->job_queue); + if (multi_thread_ctxt->job_queue) { + vpx_free(multi_thread_ctxt->job_queue); + multi_thread_ctxt->job_queue = NULL; + } #if CONFIG_MULTITHREAD // Destroy mutex for each tile for (tile_col = 0; tile_col < multi_thread_ctxt->allocated_tile_cols; tile_col++) { RowMTInfo *row_mt_info = &multi_thread_ctxt->row_mt_info[tile_col]; - if (row_mt_info) pthread_mutex_destroy(&row_mt_info->job_mutex); + pthread_mutex_destroy(&row_mt_info->job_mutex); } #endif @@ -168,6 +172,10 @@ void vp9_row_mt_mem_dealloc(VP9_COMP *cpi) { } } #endif + + multi_thread_ctxt->allocated_tile_cols = 0; + multi_thread_ctxt->allocated_tile_rows = 0; + multi_thread_ctxt->allocated_vert_unit_rows = 0; } void vp9_multi_thread_tile_init(VP9_COMP *cpi) { diff --git a/libs/libvpx/vp9/encoder/vp9_noise_estimate.c b/libs/libvpx/vp9/encoder/vp9_noise_estimate.c index 9696529c50..4ee6e51ba8 100644 --- a/libs/libvpx/vp9/encoder/vp9_noise_estimate.c +++ b/libs/libvpx/vp9/encoder/vp9_noise_estimate.c @@ -202,7 +202,7 @@ void vp9_update_noise_estimate(VP9_COMP *const cpi) { VPXMIN(cpi->consec_zero_mv[bl_index1], VPXMIN(cpi->consec_zero_mv[bl_index2], cpi->consec_zero_mv[bl_index3]))); - // Only consider blocks that are likely steady background. i.e, have + // Only consider blocks that are likely steady background. i.e., have // been encoded as zero/low motion x (= thresh_consec_zeromv) frames // in a row. consec_zero_mv[] defined for 8x8 blocks, so consider all // 4 sub-blocks for 16x16 block. And exclude this frame if diff --git a/libs/libvpx/vp9/encoder/vp9_pickmode.c b/libs/libvpx/vp9/encoder/vp9_pickmode.c index 697c589ab3..4c4f3a8450 100644 --- a/libs/libvpx/vp9/encoder/vp9_pickmode.c +++ b/libs/libvpx/vp9/encoder/vp9_pickmode.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "./vp9_rtcd.h" #include "./vpx_dsp_rtcd.h" @@ -128,15 +129,24 @@ static int mv_refs_rt(VP9_COMP *cpi, const VP9_COMMON *cm, const MACROBLOCK *x, !cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame && ref_frame == LAST_FRAME) { // Get base layer mv. - MV_REF *candidate = - &cm->prev_frame - ->mvs[(mi_col >> 1) + (mi_row >> 1) * (cm->mi_cols >> 1)]; - if (candidate->mv[0].as_int != INVALID_MV) { - base_mv->as_mv.row = (candidate->mv[0].as_mv.row * 2); - base_mv->as_mv.col = (candidate->mv[0].as_mv.col * 2); - clamp_mv_ref(&base_mv->as_mv, xd); - } else { - base_mv->as_int = INVALID_MV; + const int prev_layer = cpi->svc.spatial_layer_id - 1; + const int index = + (mi_col >> 1) + (mi_row >> 1) * cpi->svc.mi_cols[prev_layer]; + // prev_frame->mvs[] is allocated to size mi_cols * mi_rows corresponding + // to the previous spatial layer, so the index check is against + // svc.mi_col/rows[prev_layer]. + if (index < cpi->svc.mi_cols[prev_layer] * cpi->svc.mi_rows[prev_layer]) { + MV_REF *candidate = &cm->prev_frame->mvs[index]; + // Avoid using base_mv if scaled mv is out of range, for either component. + if (candidate->mv[0].as_int != INVALID_MV && + abs(candidate->mv[0].as_mv.row) <= INT16_MAX >> 1 && + abs(candidate->mv[0].as_mv.col) <= INT16_MAX >> 1) { + base_mv->as_mv.row = candidate->mv[0].as_mv.row * 2; + base_mv->as_mv.col = candidate->mv[0].as_mv.col * 2; + clamp_mv_ref(&base_mv->as_mv, xd); + } else { + base_mv->as_int = INVALID_MV; + } } } @@ -173,6 +183,8 @@ static int combined_motion_search(VP9_COMP *cpi, MACROBLOCK *x, const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, ref); if (scaled_ref_frame) { + assert(scaled_ref_frame->y_width == cpi->Source->y_width && + scaled_ref_frame->y_height == cpi->Source->y_height); int i; // Swap out the reference frame for a version that's been scaled to // match the resolution of the current frame, allowing the existing @@ -268,6 +280,7 @@ static void block_variance(const uint8_t *src, int src_stride, #endif uint32_t *sse8x8, int *sum8x8, uint32_t *var8x8) { int i, j, k = 0; + uint32_t k_sqr = 0; *sse = 0; *sum = 0; @@ -305,7 +318,8 @@ static void block_variance(const uint8_t *src, int src_stride, #endif *sse += sse8x8[k]; *sum += sum8x8[k]; - var8x8[k] = sse8x8[k] - (uint32_t)(((int64_t)sum8x8[k] * sum8x8[k]) >> 6); + k_sqr = (uint32_t)(((int64_t)sum8x8[k] * sum8x8[k]) >> 6); + var8x8[k] = sse8x8[k] > k_sqr ? sse8x8[k] - k_sqr : k_sqr - sse8x8[k]; k++; } } @@ -319,6 +333,7 @@ static void calculate_variance(int bw, int bh, TX_SIZE tx_size, const int nw = 1 << (bw - b_width_log2_lookup[unit_size]); const int nh = 1 << (bh - b_height_log2_lookup[unit_size]); int i, j, k = 0; + uint32_t k_sqr = 0; for (i = 0; i < nh; i += 2) { for (j = 0; j < nw; j += 2) { @@ -326,9 +341,10 @@ static void calculate_variance(int bw, int bh, TX_SIZE tx_size, sse_i[(i + 1) * nw + j] + sse_i[(i + 1) * nw + j + 1]; sum_o[k] = sum_i[i * nw + j] + sum_i[i * nw + j + 1] + sum_i[(i + 1) * nw + j] + sum_i[(i + 1) * nw + j + 1]; - var_o[k] = sse_o[k] - (uint32_t)(((int64_t)sum_o[k] * sum_o[k]) >> - (b_width_log2_lookup[unit_size] + - b_height_log2_lookup[unit_size] + 6)); + k_sqr = (uint32_t)(((int64_t)sum_o[k] * sum_o[k]) >> + (b_width_log2_lookup[unit_size] + + b_height_log2_lookup[unit_size] + 6)); + var_o[k] = sse_o[k] > k_sqr ? sse_o[k] - k_sqr : k_sqr - sse_o[k]; k++; } } @@ -452,6 +468,7 @@ static void model_rd_for_sb_y_large(VP9_COMP *cpi, BLOCK_SIZE bsize, unsigned int var8x8[64] = { 0 }; TX_SIZE tx_size; int i, k; + uint32_t sum_sqr; #if CONFIG_VP9_HIGHBITDEPTH const vpx_bit_depth_t bd = cpi->common.bit_depth; #endif @@ -463,7 +480,8 @@ static void model_rd_for_sb_y_large(VP9_COMP *cpi, BLOCK_SIZE bsize, cpi->common.use_highbitdepth, bd, #endif sse8x8, sum8x8, var8x8); - var = sse - (unsigned int)(((int64_t)sum * sum) >> (bw + bh + 4)); + sum_sqr = (uint32_t)((int64_t)sum * sum) >> (bw + bh + 4); + var = sse > sum_sqr ? sse - sum_sqr : sum_sqr - sse; *var_y = var; *sse_y = sse; @@ -560,23 +578,26 @@ static void model_rd_for_sb_y_large(VP9_COMP *cpi, BLOCK_SIZE bsize, // Transform skipping test in UV planes. for (i = 1; i <= 2; i++) { - struct macroblock_plane *const p = &x->plane[i]; - struct macroblockd_plane *const pd = &xd->plane[i]; - const TX_SIZE uv_tx_size = get_uv_tx_size(xd->mi[0], pd); + struct macroblock_plane *const p_uv = &x->plane[i]; + struct macroblockd_plane *const pd_uv = &xd->plane[i]; + const TX_SIZE uv_tx_size = get_uv_tx_size(xd->mi[0], pd_uv); const BLOCK_SIZE unit_size = txsize_to_bsize[uv_tx_size]; - const BLOCK_SIZE uv_bsize = get_plane_block_size(bsize, pd); + const BLOCK_SIZE uv_bsize = get_plane_block_size(bsize, pd_uv); const int uv_bw = b_width_log2_lookup[uv_bsize]; const int uv_bh = b_height_log2_lookup[uv_bsize]; const int sf = (uv_bw - b_width_log2_lookup[unit_size]) + (uv_bh - b_height_log2_lookup[unit_size]); - const uint32_t uv_dc_thr = pd->dequant[0] * pd->dequant[0] >> (6 - sf); - const uint32_t uv_ac_thr = pd->dequant[1] * pd->dequant[1] >> (6 - sf); + const uint32_t uv_dc_thr = + pd_uv->dequant[0] * pd_uv->dequant[0] >> (6 - sf); + const uint32_t uv_ac_thr = + pd_uv->dequant[1] * pd_uv->dequant[1] >> (6 - sf); int j = i - 1; vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, i); flag_preduv_computed[i - 1] = 1; - var_uv[j] = cpi->fn_ptr[uv_bsize].vf( - p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride, &sse_uv[j]); + var_uv[j] = cpi->fn_ptr[uv_bsize].vf(p_uv->src.buf, p_uv->src.stride, + pd_uv->dst.buf, pd_uv->dst.stride, + &sse_uv[j]); if ((var_uv[j] < uv_ac_thr || var_uv[j] == 0) && (sse_uv[j] - var_uv[j] < uv_dc_thr || sse_uv[j] == var_uv[j])) @@ -762,7 +783,7 @@ static void block_yrd(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *this_rdc, for (r = 0; r < max_blocks_high; r += block_step) { for (c = 0; c < num_4x4_w; c += block_step) { if (c < max_blocks_wide) { - const scan_order *const scan_order = &vp9_default_scan_orders[tx_size]; + const ScanOrder *const scan_order = &vp9_default_scan_orders[tx_size]; tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); @@ -777,22 +798,19 @@ static void block_yrd(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *this_rdc, switch (tx_size) { case TX_16X16: vpx_hadamard_16x16(src_diff, diff_stride, coeff); - vp9_quantize_fp(coeff, 256, p->round_fp, p->quant_fp, qcoeff, - dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vp9_quantize_fp(coeff, 256, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; case TX_8X8: vpx_hadamard_8x8(src_diff, diff_stride, coeff); - vp9_quantize_fp(coeff, 64, p->round_fp, p->quant_fp, qcoeff, - dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vp9_quantize_fp(coeff, 64, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; default: assert(tx_size == TX_4X4); x->fwd_txfm4x4(src_diff, coeff, diff_stride); - vp9_quantize_fp(coeff, 16, p->round_fp, p->quant_fp, qcoeff, - dqcoeff, pd->dequant, eob, scan_order->scan, - scan_order->iscan); + vp9_quantize_fp(coeff, 16, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); break; } *skippable &= (*eob == 0); @@ -1112,7 +1130,7 @@ static INLINE int rd_less_than_thresh_row_mt(int64_t best_rd, int thresh, } static INLINE void update_thresh_freq_fact_row_mt( - VP9_COMP *cpi, TileDataEnc *tile_data, int source_variance, + VP9_COMP *cpi, TileDataEnc *tile_data, unsigned int source_variance, int thresh_freq_fact_idx, MV_REFERENCE_FRAME ref_frame, THR_MODES best_mode_idx, PREDICTION_MODE mode) { THR_MODES thr_mode_idx = mode_idx[ref_frame][mode_offset(mode)]; @@ -1163,6 +1181,7 @@ void vp9_pick_intra_mode(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost, const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); bmode_costs = cpi->y_mode_costs[A][L]; + assert(bsize >= BLOCK_8X8); (void)ctx; vp9_rd_cost_reset(&best_rdc); @@ -1389,8 +1408,8 @@ static void recheck_zeromv_after_denoising( RD_COST this_rdc; mi->mode = ZEROMV; mi->ref_frame[0] = LAST_FRAME; - mi->ref_frame[1] = NONE; - set_ref_ptrs(cm, xd, mi->ref_frame[0], NONE); + mi->ref_frame[1] = NO_REF_FRAME; + set_ref_ptrs(cm, xd, mi->ref_frame[0], NO_REF_FRAME); mi->mv[0].as_int = 0; mi->interp_filter = EIGHTTAP; if (cpi->sf.default_interp_filter == BILINEAR) mi->interp_filter = BILINEAR; @@ -1408,7 +1427,7 @@ static void recheck_zeromv_after_denoising( this_rdc = *best_rdc; mi->mode = ctx_den->best_mode; mi->ref_frame[0] = ctx_den->best_ref_frame; - set_ref_ptrs(cm, xd, mi->ref_frame[0], NONE); + set_ref_ptrs(cm, xd, mi->ref_frame[0], NO_REF_FRAME); mi->interp_filter = ctx_den->best_pred_filter; if (ctx_den->best_ref_frame == INTRA_FRAME) { mi->mv[0].as_int = INVALID_MV; @@ -1627,9 +1646,9 @@ static int search_new_mv(VP9_COMP *cpi, MACROBLOCK *x, return -1; // Exit NEWMV search if base_mv_sse is large. - if (sf->base_mv_aggressive && base_mv_sse > (best_sse_sofar << scale)) + if (sf->base_mv_aggressive && (base_mv_sse >> scale) > best_sse_sofar) return -1; - if (base_mv_sse < (best_sse_sofar << 1)) { + if ((base_mv_sse >> 1) < best_sse_sofar) { // Base layer mv is good. // Exit NEWMV search if the base_mv is (0, 0) and sse is low, since // (0, 0) mode is already tested. @@ -1672,7 +1691,7 @@ static INLINE void init_best_pickmode(BEST_PICKMODE *bp) { bp->best_intra_tx_size = TX_SIZES; bp->best_pred_filter = EIGHTTAP; bp->best_mode_skip_txfm = SKIP_TXFM_NONE; - bp->best_second_ref_frame = NONE; + bp->best_second_ref_frame = NO_REF_FRAME; bp->best_pred = NULL; } @@ -1692,7 +1711,7 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data, MV_REFERENCE_FRAME usable_ref_frame, second_ref_frame; int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; uint8_t mode_checked[MB_MODE_COUNT][MAX_REF_FRAMES]; - struct buf_2d yv12_mb[4][MAX_MB_PLANE]; + struct buf_2d yv12_mb[4][MAX_MB_PLANE] = { 0 }; RD_COST this_rdc, best_rdc; // var_y and sse_y are saved to be used in skipping checking unsigned int var_y = UINT_MAX; @@ -1805,9 +1824,10 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data, &cm->frame_refs[GOLDEN_FRAME - 1].sf; gf_temporal_ref = 1; // For temporal long term prediction, check that the golden reference - // is same scale as last reference, otherwise disable. + // is same scale as last reference and not scaled, otherwise disable. if ((sf_last->x_scale_fp != sf_golden->x_scale_fp) || - (sf_last->y_scale_fp != sf_golden->y_scale_fp)) { + (sf_last->y_scale_fp != sf_golden->y_scale_fp) || + vp9_is_scaled(sf_golden)) { gf_temporal_ref = 0; } else { if (cpi->rc.avg_frame_low_motion > 70) @@ -1866,8 +1886,8 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data, vp9_rd_cost_reset(&best_rdc); vp9_rd_cost_reset(rd_cost); mi->sb_type = bsize; - mi->ref_frame[0] = NONE; - mi->ref_frame[1] = NONE; + mi->ref_frame[0] = NO_REF_FRAME; + mi->ref_frame[1] = NO_REF_FRAME; mi->tx_size = VPXMIN(max_txsize_lookup[bsize], tx_mode_to_biggest_tx_size[cm->tx_mode]); @@ -1922,20 +1942,21 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data, } } - // For svc mode, on spatial_layer_id > 0: if the reference has different scale + // For svc mode: if the reference has different scale and was not scaled, // constrain the inter mode to only test zero motion. - if (cpi->use_svc && svc->force_zero_mode_spatial_ref && - svc->spatial_layer_id > 0 && !gf_temporal_ref) { + if (cpi->use_svc && svc->force_zero_mode_spatial_ref) { if (cpi->ref_frame_flags & VP9_LAST_FLAG) { - struct scale_factors *const sf = &cm->frame_refs[LAST_FRAME - 1].sf; - if (vp9_is_scaled(sf)) { + struct scale_factors *const ref_sf = &cm->frame_refs[LAST_FRAME - 1].sf; + if (vp9_is_scaled(ref_sf) && + vp9_get_scaled_ref_frame(cpi, LAST_FRAME) == NULL) { svc_force_zero_mode[LAST_FRAME - 1] = 1; inter_layer_ref = LAST_FRAME; } } if (cpi->ref_frame_flags & VP9_GOLD_FLAG) { - struct scale_factors *const sf = &cm->frame_refs[GOLDEN_FRAME - 1].sf; - if (vp9_is_scaled(sf)) { + struct scale_factors *const ref_sf = &cm->frame_refs[GOLDEN_FRAME - 1].sf; + if (vp9_is_scaled(ref_sf) && + vp9_get_scaled_ref_frame(cpi, GOLDEN_FRAME) == NULL) { svc_force_zero_mode[GOLDEN_FRAME - 1] = 1; inter_layer_ref = GOLDEN_FRAME; } @@ -2045,7 +2066,7 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data, int comp_pred = 0; int force_mv_inter_layer = 0; PREDICTION_MODE this_mode; - second_ref_frame = NONE; + second_ref_frame = NO_REF_FRAME; if (idx < num_inter_modes) { this_mode = ref_mode_set[idx].pred_mode; @@ -2192,8 +2213,9 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data, if (!force_skip_low_temp_var && usable_ref_frame > LAST_FRAME) { i = (ref_frame == LAST_FRAME) ? GOLDEN_FRAME : LAST_FRAME; if ((cpi->ref_frame_flags & ref_frame_to_flag(i))) - if (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[i] << 1)) - ref_frame_skip_mask |= (1 << ref_frame); + if (x->pred_mv_sad[i] < INT_MAX) + if (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[i] << 1)) + ref_frame_skip_mask |= (1 << ref_frame); } } else if (!cpi->rc.is_src_frame_alt_ref && !(frame_mv[this_mode][ref_frame].as_int == 0 && @@ -2201,8 +2223,10 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data, int ref1 = (ref_frame == GOLDEN_FRAME) ? LAST_FRAME : GOLDEN_FRAME; int ref2 = (ref_frame == ALTREF_FRAME) ? LAST_FRAME : ALTREF_FRAME; if (((cpi->ref_frame_flags & ref_frame_to_flag(ref1)) && + x->pred_mv_sad[ref1] < INT_MAX && (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[ref1] << 1))) || ((cpi->ref_frame_flags & ref_frame_to_flag(ref2)) && + x->pred_mv_sad[ref2] < INT_MAX && (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[ref2] << 1)))) ref_frame_skip_mask |= (1 << ref_frame); } @@ -2266,6 +2290,18 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data, // need to compute best_pred_sad which is only used to skip golden NEWMV. if (use_golden_nonzeromv && this_mode == NEWMV && ref_frame == LAST_FRAME && frame_mv[NEWMV][LAST_FRAME].as_int != INVALID_MV) { + struct buf_2d backup_yv12[MAX_MB_PLANE] = { { 0, 0 } }; + const YV12_BUFFER_CONFIG *scaled_ref_frame = + vp9_get_scaled_ref_frame(cpi, ref_frame); + if (scaled_ref_frame) { + assert(scaled_ref_frame->y_width == cpi->Source->y_width && + scaled_ref_frame->y_height == cpi->Source->y_height); + // Swap out the reference frame for a version that's been scaled to + // match the resolution of the current frame, allowing the existing + // motion search code to be used without additional modifications. + for (i = 0; i < MAX_MB_PLANE; i++) backup_yv12[i] = xd->plane[i].pre[0]; + vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); + } const int pre_stride = xd->plane[0].pre[0].stride; const uint8_t *const pre_buf = xd->plane[0].pre[0].buf + @@ -2274,6 +2310,9 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data, best_pred_sad = cpi->fn_ptr[bsize].sdf( x->plane[0].src.buf, x->plane[0].src.stride, pre_buf, pre_stride); x->pred_mv_sad[LAST_FRAME] = best_pred_sad; + if (scaled_ref_frame) { + for (i = 0; i < MAX_MB_PLANE; i++) xd->plane[i].pre[0] = backup_yv12[i]; + } } if (this_mode != NEARESTMV && !comp_pred && @@ -2622,7 +2661,7 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data, best_pickmode.best_mode = this_mode; best_pickmode.best_intra_tx_size = mi->tx_size; best_pickmode.best_ref_frame = INTRA_FRAME; - best_pickmode.best_second_ref_frame = NONE; + best_pickmode.best_second_ref_frame = NO_REF_FRAME; mi->uv_mode = this_mode; mi->mv[0].as_int = INVALID_MV; mi->mv[1].as_int = INVALID_MV; @@ -2744,8 +2783,8 @@ void vp9_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, int mi_row, MODE_INFO *const mi = xd->mi[0]; MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext; const struct segmentation *const seg = &cm->seg; - MV_REFERENCE_FRAME ref_frame, second_ref_frame = NONE; - MV_REFERENCE_FRAME best_ref_frame = NONE; + MV_REFERENCE_FRAME ref_frame, second_ref_frame = NO_REF_FRAME; + MV_REFERENCE_FRAME best_ref_frame = NO_REF_FRAME; unsigned char segment_id = mi->segment_id; struct buf_2d yv12_mb[4][MAX_MB_PLANE]; int64_t best_rd = INT64_MAX; @@ -2766,9 +2805,10 @@ void vp9_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, int mi_row, if ((cpi->ref_frame_flags & ref_frame_to_flag(ref_frame)) && (yv12 != NULL)) { int_mv *const candidates = mbmi_ext->ref_mvs[ref_frame]; - const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; - vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, - sf); + const struct scale_factors *const ref_sf = + &cm->frame_refs[ref_frame - 1].sf; + vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, ref_sf, + ref_sf); vp9_find_mv_refs(cm, xd, xd->mi[0], ref_frame, candidates, mi_row, mi_col, mbmi_ext->mode_context); @@ -2783,7 +2823,7 @@ void vp9_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, int mi_row, mi->tx_size = TX_4X4; mi->uv_mode = DC_PRED; mi->ref_frame[0] = LAST_FRAME; - mi->ref_frame[1] = NONE; + mi->ref_frame[1] = NO_REF_FRAME; mi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP : cm->interp_filter; diff --git a/libs/libvpx/vp9/encoder/vp9_quantize.c b/libs/libvpx/vp9/encoder/vp9_quantize.c index 9058997b0f..31b148e9a8 100644 --- a/libs/libvpx/vp9/encoder/vp9_quantize.c +++ b/libs/libvpx/vp9/encoder/vp9_quantize.c @@ -12,9 +12,11 @@ #include #include "./vpx_dsp_rtcd.h" #include "vpx_mem/vpx_mem.h" +#include "vpx_ports/bitops.h" #include "vpx_ports/mem.h" #include "vp9/common/vp9_quant_common.h" +#include "vp9/common/vp9_scan.h" #include "vp9/common/vp9_seg_common.h" #include "vp9/encoder/vp9_encoder.h" @@ -22,12 +24,14 @@ #include "vp9/encoder/vp9_rd.h" void vp9_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *round_ptr, const int16_t *quant_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { + const struct ScanOrder *const scan_order) { int i, eob = -1; - (void)iscan; + const int16_t *round_ptr = mb_plane->round_fp; + const int16_t *quant_ptr = mb_plane->quant_fp; + const int16_t *scan = scan_order->scan; memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); @@ -53,15 +57,15 @@ void vp9_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, #if CONFIG_VP9_HIGHBITDEPTH void vp9_highbd_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *round_ptr, - const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, - tran_low_t *dqcoeff_ptr, + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { + const struct ScanOrder *const scan_order) { int i; int eob = -1; - - (void)iscan; + const int16_t *round_ptr = mb_plane->round_fp; + const int16_t *quant_ptr = mb_plane->quant_fp; + const int16_t *scan = scan_order->scan; memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); @@ -86,12 +90,14 @@ void vp9_highbd_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, // TODO(jingning) Refactor this file and combine functions with similar // operations. void vp9_quantize_fp_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *round_ptr, const int16_t *quant_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { + const struct ScanOrder *const scan_order) { int i, eob = -1; - (void)iscan; + const int16_t *round_ptr = mb_plane->round_fp; + const int16_t *quant_ptr = mb_plane->quant_fp; + const int16_t *scan = scan_order->scan; memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); @@ -118,13 +124,14 @@ void vp9_quantize_fp_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, #if CONFIG_VP9_HIGHBITDEPTH void vp9_highbd_quantize_fp_32x32_c( - const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, - const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, - const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, - const int16_t *iscan) { + const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { int i, eob = -1; - - (void)iscan; + const int16_t *round_ptr = mb_plane->round_fp; + const int16_t *quant_ptr = mb_plane->quant_fp; + const int16_t *scan = scan_order->scan; memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); @@ -149,39 +156,11 @@ void vp9_highbd_quantize_fp_32x32_c( } #endif -void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int plane, int block, - const int16_t *scan, const int16_t *iscan) { - MACROBLOCKD *const xd = &x->e_mbd; - struct macroblock_plane *p = &x->plane[plane]; - struct macroblockd_plane *pd = &xd->plane[plane]; - tran_low_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block), - *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); - const int n_coeffs = 4 * 4; - - if (x->skip_block) { - memset(qcoeff, 0, n_coeffs * sizeof(*qcoeff)); - memset(dqcoeff, 0, n_coeffs * sizeof(*dqcoeff)); - return; - } - -#if CONFIG_VP9_HIGHBITDEPTH - if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { - vpx_highbd_quantize_b(BLOCK_OFFSET(p->coeff, block), n_coeffs, p->zbin, - p->round, p->quant, p->quant_shift, qcoeff, dqcoeff, - pd->dequant, &p->eobs[block], scan, iscan); - return; - } -#endif - vpx_quantize_b(BLOCK_OFFSET(p->coeff, block), n_coeffs, p->zbin, p->round, - p->quant, p->quant_shift, qcoeff, dqcoeff, pd->dequant, - &p->eobs[block], scan, iscan); -} - static void invert_quant(int16_t *quant, int16_t *shift, int d) { - unsigned t; + unsigned int t; int l, m; - t = d; - for (l = 0; t > 1; l++) t >>= 1; + t = (unsigned int)d; + l = get_msb(t); m = 1 + (1 << (16 + l)) / d; *quant = (int16_t)(m - (1 << 16)); *shift = 1 << (16 - l); @@ -277,8 +256,7 @@ void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) { // Y x->plane[0].quant = quants->y_quant[qindex]; x->plane[0].quant_fp = quants->y_quant_fp[qindex]; - memcpy(x->plane[0].round_fp, quants->y_round_fp[qindex], - 8 * sizeof(*(x->plane[0].round_fp))); + x->plane[0].round_fp = quants->y_round_fp[qindex]; x->plane[0].quant_shift = quants->y_quant_shift[qindex]; x->plane[0].zbin = quants->y_zbin[qindex]; x->plane[0].round = quants->y_round[qindex]; @@ -290,8 +268,7 @@ void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) { for (i = 1; i < 3; i++) { x->plane[i].quant = quants->uv_quant[qindex]; x->plane[i].quant_fp = quants->uv_quant_fp[qindex]; - memcpy(x->plane[i].round_fp, quants->uv_round_fp[qindex], - 8 * sizeof(*(x->plane[i].round_fp))); + x->plane[i].round_fp = quants->uv_round_fp[qindex]; x->plane[i].quant_shift = quants->uv_quant_shift[qindex]; x->plane[i].zbin = quants->uv_zbin[qindex]; x->plane[i].round = quants->uv_round[qindex]; @@ -312,7 +289,7 @@ void vp9_frame_init_quantizer(VP9_COMP *cpi) { vp9_init_plane_quantizers(cpi, &cpi->td.mb); } -void vp9_set_quantizer(VP9_COMP *cpi, int q) { +void vp9_set_quantizer(VP9_COMP *cpi, int q, int ext_rc_delta_q_uv) { VP9_COMMON *cm = &cpi->common; // quantizer has to be reinitialized with vp9_init_quantizer() if any // delta_q changes. @@ -320,6 +297,13 @@ void vp9_set_quantizer(VP9_COMP *cpi, int q) { cm->y_dc_delta_q = 0; cm->uv_dc_delta_q = 0; cm->uv_ac_delta_q = 0; + + if (ext_rc_delta_q_uv != 0) { + cm->uv_dc_delta_q = cm->uv_ac_delta_q = ext_rc_delta_q_uv; + vp9_init_quantizer(cpi); + return; + } + if (cpi->oxcf.delta_q_uv != 0) { cm->uv_dc_delta_q = cm->uv_ac_delta_q = cpi->oxcf.delta_q_uv; vp9_init_quantizer(cpi); @@ -337,6 +321,7 @@ static const int quantizer_to_qindex[] = { }; int vp9_quantizer_to_qindex(int quantizer) { + assert(quantizer >= 0 && quantizer <= 63); return quantizer_to_qindex[quantizer]; } diff --git a/libs/libvpx/vp9/encoder/vp9_quantize.h b/libs/libvpx/vp9/encoder/vp9_quantize.h index 2e6d7da2b6..bca2e055a2 100644 --- a/libs/libvpx/vp9/encoder/vp9_quantize.h +++ b/libs/libvpx/vp9/encoder/vp9_quantize.h @@ -37,9 +37,6 @@ typedef struct { DECLARE_ALIGNED(16, int16_t, uv_round[QINDEX_RANGE][8]); } QUANTS; -void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int plane, int block, - const int16_t *scan, const int16_t *iscan); - struct VP9_COMP; struct VP9Common; @@ -49,7 +46,7 @@ void vp9_init_plane_quantizers(struct VP9_COMP *cpi, MACROBLOCK *x); void vp9_init_quantizer(struct VP9_COMP *cpi); -void vp9_set_quantizer(struct VP9_COMP *cm, int q); +void vp9_set_quantizer(struct VP9_COMP *cpi, int q, int ext_rc_delta_q_uv); int vp9_quantizer_to_qindex(int quantizer); diff --git a/libs/libvpx/vp9/encoder/vp9_ratectrl.c b/libs/libvpx/vp9/encoder/vp9_ratectrl.c index 0852973914..958f36ea73 100644 --- a/libs/libvpx/vp9/encoder/vp9_ratectrl.c +++ b/libs/libvpx/vp9/encoder/vp9_ratectrl.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -22,14 +23,24 @@ #include "vpx_ports/system_state.h" #include "vp9/common/vp9_alloccommon.h" -#include "vp9/encoder/vp9_aq_cyclicrefresh.h" +#include "vp9/common/vp9_blockd.h" #include "vp9/common/vp9_common.h" #include "vp9/common/vp9_entropymode.h" +#include "vp9/common/vp9_onyxc_int.h" #include "vp9/common/vp9_quant_common.h" #include "vp9/common/vp9_seg_common.h" +#include "vp9/encoder/vp9_aq_cyclicrefresh.h" #include "vp9/encoder/vp9_encodemv.h" +#include "vp9/encoder/vp9_encoder.h" +#include "vp9/encoder/vp9_ext_ratectrl.h" +#include "vp9/encoder/vp9_firstpass.h" #include "vp9/encoder/vp9_ratectrl.h" +#include "vp9/encoder/vp9_svc_layercontext.h" + +#include "vpx/vpx_codec.h" +#include "vpx/vpx_ext_ratectrl.h" +#include "vpx/internal/vpx_codec_internal.h" // Max rate per frame for 1080P and below encodes if no level requirement given. // For larger formats limit to MAX_MB_RATE bits per MB @@ -260,7 +271,7 @@ void vp9_update_buffer_level_preencode(VP9_COMP *cpi) { // for the layered rate control which involves cumulative buffer levels for // the temporal layers. Allow for using the timestamp(pts) delta for the // framerate when the set_ref_frame_config is used. -static void update_buffer_level_svc_preencode(VP9_COMP *cpi) { +void vp9_update_buffer_level_svc_preencode(VP9_COMP *cpi) { SVC *const svc = &cpi->svc; int i; // Set this to 1 to use timestamp delta for "framerate" under @@ -278,9 +289,11 @@ static void update_buffer_level_svc_preencode(VP9_COMP *cpi) { svc->current_superframe > 0) { // TODO(marpan): This may need to be modified for temporal layers. const double framerate_pts = 10000000.0 / ts_delta; - lrc->bits_off_target += (int)round(lc->target_bandwidth / framerate_pts); + lrc->bits_off_target += saturate_cast_double_to_int( + round(lc->target_bandwidth / framerate_pts)); } else { - lrc->bits_off_target += (int)round(lc->target_bandwidth / lc->framerate); + lrc->bits_off_target += saturate_cast_double_to_int( + round(lc->target_bandwidth / lc->framerate)); } // Clip buffer level to maximum buffer size for the layer. lrc->bits_off_target = @@ -327,7 +340,7 @@ static void update_buffer_level_postencode(VP9_COMP *cpi, rc->buffer_level = rc->bits_off_target; - if (is_one_pass_cbr_svc(cpi)) { + if (is_one_pass_svc(cpi)) { update_layer_buffer_level_postencode(&cpi->svc, encoded_frame_size); } } @@ -338,13 +351,13 @@ int vp9_rc_get_default_min_gf_interval(int width, int height, static const double factor_safe = 3840 * 2160 * 20.0; const double factor = width * height * framerate; const int default_interval = - clamp((int)(framerate * 0.125), MIN_GF_INTERVAL, MAX_GF_INTERVAL); + clamp((int)round(framerate * 0.125), MIN_GF_INTERVAL, MAX_GF_INTERVAL); if (factor <= factor_safe) return default_interval; else return VPXMAX(default_interval, - (int)(MIN_GF_INTERVAL * factor / factor_safe + 0.5)); + (int)round(MIN_GF_INTERVAL * factor / factor_safe)); // Note this logic makes: // 4K24: 5 // 4K30: 6 @@ -352,7 +365,7 @@ int vp9_rc_get_default_min_gf_interval(int width, int height, } int vp9_rc_get_default_max_gf_interval(double framerate, int min_gf_interval) { - int interval = VPXMIN(MAX_GF_INTERVAL, (int)(framerate * 0.75)); + int interval = VPXMIN(MAX_GF_INTERVAL, (int)round(framerate * 0.75)); interval += (interval & 0x01); // Round to even value return VPXMAX(interval, min_gf_interval); } @@ -680,7 +693,8 @@ static int adjust_q_cbr(const VP9_COMP *cpi, int q) { else q = qclamp; } - if (cpi->oxcf.content == VP9E_CONTENT_SCREEN) + if (cpi->oxcf.content == VP9E_CONTENT_SCREEN && + cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) vp9_cyclic_refresh_limit_q(cpi, &q); return VPXMAX(VPXMIN(q, cpi->rc.worst_quality), cpi->rc.best_quality); } @@ -842,15 +856,19 @@ int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame, frame_type, i, correction_factor, cm->bit_depth); } + int diff_bits = (int)VPXMIN( + VPXMAX(((int64_t)target_bits_per_mb - (int64_t)bits_per_mb_at_this_q), + -INT_MAX), + INT_MAX); if (bits_per_mb_at_this_q <= target_bits_per_mb) { - if ((target_bits_per_mb - bits_per_mb_at_this_q) <= last_error) + if (diff_bits <= last_error) q = i; else q = i - 1; break; } else { - last_error = bits_per_mb_at_this_q - target_bits_per_mb; + last_error = -diff_bits; } } while (++i <= active_worst_quality); @@ -910,7 +928,7 @@ static int calc_active_worst_quality_one_pass_vbr(const VP9_COMP *cpi) { active_worst_quality = curr_frame == 0 ? rc->worst_quality : rc->last_q[KEY_FRAME] << 1; } else { - if (!rc->is_src_frame_alt_ref && + if (!rc->is_src_frame_alt_ref && !cpi->use_svc && (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) { active_worst_quality = curr_frame == 1 @@ -1078,7 +1096,7 @@ static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi, // Special case code to try and match quality with forced key frames if (frame_is_intra_only(cm) && rc->this_key_frame_forced) { - q = rc->last_boosted_qindex; + q = clamp(rc->last_boosted_qindex, rc->best_quality, rc->worst_quality); } else { q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality, active_worst_quality); @@ -1150,8 +1168,9 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, if (frame_is_intra_only(cm)) { if (oxcf->rc_mode == VPX_Q) { int qindex = cq_level; - double q = vp9_convert_qindex_to_q(qindex, cm->bit_depth); - int delta_qindex = vp9_compute_qdelta(rc, q, q * 0.25, cm->bit_depth); + double qstart = vp9_convert_qindex_to_q(qindex, cm->bit_depth); + int delta_qindex = + vp9_compute_qdelta(rc, qstart, qstart * 0.25, cm->bit_depth); active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality); } else if (rc->this_key_frame_forced) { // Handle the special case for key frames forced when we have reached @@ -1195,7 +1214,7 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, } else { q = rc->avg_frame_qindex[KEY_FRAME]; } - // For constrained quality dont allow Q less than the cq level + // For constrained quality don't allow Q less than the cq level if (oxcf->rc_mode == VPX_CQ) { if (q < cq_level) q = cq_level; @@ -1206,12 +1225,14 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, } else if (oxcf->rc_mode == VPX_Q) { int qindex = cq_level; - double q = vp9_convert_qindex_to_q(qindex, cm->bit_depth); + double qstart = vp9_convert_qindex_to_q(qindex, cm->bit_depth); int delta_qindex; if (cpi->refresh_alt_ref_frame) - delta_qindex = vp9_compute_qdelta(rc, q, q * 0.40, cm->bit_depth); + delta_qindex = + vp9_compute_qdelta(rc, qstart, qstart * 0.40, cm->bit_depth); else - delta_qindex = vp9_compute_qdelta(rc, q, q * 0.50, cm->bit_depth); + delta_qindex = + vp9_compute_qdelta(rc, qstart, qstart * 0.50, cm->bit_depth); active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality); } else { active_best_quality = get_gf_active_quality(cpi, q, cm->bit_depth); @@ -1219,11 +1240,12 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, } else { if (oxcf->rc_mode == VPX_Q) { int qindex = cq_level; - double q = vp9_convert_qindex_to_q(qindex, cm->bit_depth); + double qstart = vp9_convert_qindex_to_q(qindex, cm->bit_depth); double delta_rate[FIXED_GF_INTERVAL] = { 0.50, 1.0, 0.85, 1.0, 0.70, 1.0, 0.85, 1.0 }; int delta_qindex = vp9_compute_qdelta( - rc, q, q * delta_rate[cm->current_video_frame % FIXED_GF_INTERVAL], + rc, qstart, + qstart * delta_rate[cm->current_video_frame % FIXED_GF_INTERVAL], cm->bit_depth); active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality); } else { @@ -1277,10 +1299,34 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, q = active_best_quality; // Special case code to try and match quality with forced key frames } else if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced) { - q = rc->last_boosted_qindex; + q = clamp(rc->last_boosted_qindex, rc->best_quality, rc->worst_quality); } else { q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality, active_worst_quality); + + // For no lookahead: if buffer_level indicates overshoot, then avoid going + // to very low QP. This reduces overshoot observed in Issue: 376707227. + // Note the buffer_level is updated for every encoded frame as: + // buffer_level - starting_buffer_level += (avg_frame_bandwidth - + // encoded_frame_size). So normalizing this with framerate and #encoded + // frames (current_video_frame) gives the difference/error between target + // and encoding bitrate. The additional avg_frame_bandwidth term is to + // compensate for the pre-encoded buffer update (in + // vp9_rc_get_one_pass_vbr_params). + const int qp_thresh = 32; + const int64_t bitrate_err = + (int64_t)(cpi->framerate * + (rc->buffer_level - rc->starting_buffer_level - + rc->avg_frame_bandwidth) / + (cm->current_video_frame + 1)); + // Threshold may be tuned, but for now condition this on low QP. + if (cpi->oxcf.lag_in_frames == 0 && bitrate_err / 1000 < -10 && + qp_thresh < rc->worst_quality && + (q < qp_thresh || *top_index < qp_thresh)) { + q = qp_thresh; + *top_index = VPXMAX(*top_index, q); + } + if (q > *top_index) { // Special case when we are targeting the max allowed rate if (rc->this_frame_target >= rc->max_frame_bandwidth) @@ -1355,7 +1401,7 @@ static void pick_kf_q_bound_two_pass(const VP9_COMP *cpi, int *bottom_index, active_best_quality /= 4; } - // Dont allow the active min to be lossless (q0) unlesss the max q + // Don't allow the active min to be lossless (q0) unlesss the max q // already indicates lossless. active_best_quality = VPXMIN(active_worst_quality, VPXMAX(1, active_best_quality)); @@ -1419,8 +1465,8 @@ static int rc_constant_q(const VP9_COMP *cpi, int *bottom_index, int *top_index, return q; } -static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, int *bottom_index, - int *top_index, int gf_group_index) { +int vp9_rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, int *bottom_index, + int *top_index, int gf_group_index) { const VP9_COMMON *const cm = &cpi->common; const RATE_CONTROL *const rc = &cpi->rc; const VP9EncoderConfig *const oxcf = &cpi->oxcf; @@ -1453,7 +1499,7 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, int *bottom_index, } else { q = active_worst_quality; } - // For constrained quality dont allow Q less than the cq level + // For constrained quality don't allow Q less than the cq level if (oxcf->rc_mode == VPX_CQ) { if (q < cq_level) q = cq_level; } @@ -1567,7 +1613,6 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, int *bottom_index, q = active_worst_quality; } } - clamp(q, active_best_quality, active_worst_quality); *top_index = active_worst_quality; *bottom_index = active_best_quality; @@ -1589,12 +1634,12 @@ int vp9_rc_pick_q_and_bounds(const VP9_COMP *cpi, int *bottom_index, else q = rc_pick_q_and_bounds_one_pass_vbr(cpi, bottom_index, top_index); } else { - q = rc_pick_q_and_bounds_two_pass(cpi, bottom_index, top_index, - gf_group_index); + q = vp9_rc_pick_q_and_bounds_two_pass(cpi, bottom_index, top_index, + gf_group_index); } if (cpi->sf.use_nonrd_pick_mode) { - if (cpi->sf.force_frame_boost == 1) q -= cpi->sf.max_delta_qindex; - + if (cpi->sf.force_frame_boost == 1) + q = VPXMAX(q - cpi->sf.max_delta_qindex, cpi->rc.best_quality); if (q < *bottom_index) *bottom_index = q; else if (q > *top_index) @@ -1661,31 +1706,6 @@ void vp9_configure_buffer_updates(VP9_COMP *cpi, int gf_group_index) { } } -void vp9_estimate_qp_gop(VP9_COMP *cpi) { - int gop_length = cpi->twopass.gf_group.gf_group_size; - int bottom_index, top_index; - int idx; - const int gf_index = cpi->twopass.gf_group.index; - const int is_src_frame_alt_ref = cpi->rc.is_src_frame_alt_ref; - const int refresh_frame_context = cpi->common.refresh_frame_context; - - for (idx = 1; idx <= gop_length; ++idx) { - TplDepFrame *tpl_frame = &cpi->tpl_stats[idx]; - int target_rate = cpi->twopass.gf_group.bit_allocation[idx]; - cpi->twopass.gf_group.index = idx; - vp9_rc_set_frame_target(cpi, target_rate); - vp9_configure_buffer_updates(cpi, idx); - tpl_frame->base_qindex = - rc_pick_q_and_bounds_two_pass(cpi, &bottom_index, &top_index, idx); - tpl_frame->base_qindex = VPXMAX(tpl_frame->base_qindex, 1); - } - // Reset the actual index and frame update - cpi->twopass.gf_group.index = gf_index; - cpi->rc.is_src_frame_alt_ref = is_src_frame_alt_ref; - cpi->common.refresh_frame_context = refresh_frame_context; - vp9_configure_buffer_updates(cpi, gf_index); -} - void vp9_rc_compute_frame_size_bounds(const VP9_COMP *cpi, int frame_target, int *frame_under_shoot_limit, int *frame_over_shoot_limit) { @@ -1718,17 +1738,10 @@ void vp9_rc_set_frame_target(VP9_COMP *cpi, int target) { rate_thresh_mult[rc->frame_size_selector]); } -#if CONFIG_RATE_CTRL - if (cpi->oxcf.use_simple_encode_api) { - if (cpi->encode_command.use_external_target_frame_bits) { - rc->this_frame_target = cpi->encode_command.target_frame_bits; - } - } -#endif // CONFIG_RATE_CTRL - // Target rate per SB64 (including partial SB64s. - rc->sb64_target_rate = (int)(((int64_t)rc->this_frame_target * 64 * 64) / - (cm->width * cm->height)); + const int64_t sb64_target_rate = + ((int64_t)rc->this_frame_target * 64 * 64) / (cm->width * cm->height); + rc->sb64_target_rate = (int)VPXMIN(sb64_target_rate, INT_MAX); } static void update_alt_ref_frame_stats(VP9_COMP *cpi) { @@ -1787,7 +1800,9 @@ static void update_altref_usage(VP9_COMP *const cpi) { int arf_frame_usage = 0; int mi_row, mi_col; if (cpi->rc.alt_ref_gf_group && !cpi->rc.is_src_frame_alt_ref && - !cpi->refresh_golden_frame && !cpi->refresh_alt_ref_frame) + !cpi->refresh_golden_frame && !cpi->refresh_alt_ref_frame && + cpi->count_arf_frame_usage != NULL && + cpi->count_lastgolden_frame_usage != NULL) for (mi_row = 0; mi_row < cm->mi_rows; mi_row += 8) { for (mi_col = 0; mi_col < cm->mi_cols; mi_col += 8) { int sboffset = ((cm->mi_cols + 7) >> 3) * (mi_row >> 3) + (mi_col >> 3); @@ -1859,8 +1874,7 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) { rc->avg_frame_qindex[KEY_FRAME] = ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[KEY_FRAME] + qindex, 2); if (cpi->use_svc) { - int i = 0; - SVC *svc = &cpi->svc; + int i; for (i = 0; i < svc->number_temporal_layers; ++i) { const int layer = LAYER_IDS_TO_IDX(svc->spatial_layer_id, i, svc->number_temporal_layers); @@ -1871,7 +1885,7 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) { } } } else { - if ((cpi->use_svc && oxcf->rc_mode == VPX_CBR) || + if ((cpi->use_svc) || (!rc->is_src_frame_alt_ref && !(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) { rc->last_q[INTER_FRAME] = qindex; @@ -1988,6 +2002,7 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) { rc->last_avg_frame_bandwidth = rc->avg_frame_bandwidth; if (cpi->use_svc && svc->spatial_layer_id < svc->number_spatial_layers - 1) svc->lower_layer_qindex = cm->base_qindex; + cpi->deadline_mode_previous_frame = cpi->oxcf.mode; } void vp9_rc_postencode_update_drop_frame(VP9_COMP *cpi) { @@ -2008,6 +2023,7 @@ void vp9_rc_postencode_update_drop_frame(VP9_COMP *cpi) { cpi->rc.buffer_level = cpi->rc.optimal_buffer_level; cpi->rc.bits_off_target = cpi->rc.optimal_buffer_level; } + cpi->deadline_mode_previous_frame = cpi->oxcf.mode; } int vp9_calc_pframe_target_size_one_pass_vbr(const VP9_COMP *cpi) { @@ -2021,6 +2037,11 @@ int vp9_calc_pframe_target_size_one_pass_vbr(const VP9_COMP *cpi) { (rc->baseline_gf_interval + af_ratio - 1) : ((int64_t)rc->avg_frame_bandwidth * rc->baseline_gf_interval) / (rc->baseline_gf_interval + af_ratio - 1); + // For SVC: refresh flags are used to define the pattern, so we can't + // use that for boosting the target size here. + // TODO(marpan): Consider adding internal boost on TL0 for VBR-SVC. + // For now just use the CBR logic for setting target size. + if (cpi->use_svc) target = vp9_calc_pframe_target_size_one_pass_cbr(cpi); if (target > INT_MAX) target = INT_MAX; return vp9_rc_clamp_pframe_target_size(cpi, (int)target); } @@ -2028,7 +2049,11 @@ int vp9_calc_pframe_target_size_one_pass_vbr(const VP9_COMP *cpi) { int vp9_calc_iframe_target_size_one_pass_vbr(const VP9_COMP *cpi) { static const int kf_ratio = 25; const RATE_CONTROL *rc = &cpi->rc; - const int target = rc->avg_frame_bandwidth * kf_ratio; + int target = rc->avg_frame_bandwidth; + if (target > INT_MAX / kf_ratio) + target = INT_MAX; + else + target = rc->avg_frame_bandwidth * kf_ratio; return vp9_rc_clamp_iframe_target_size(cpi, target); } @@ -2106,7 +2131,8 @@ void vp9_rc_get_one_pass_vbr_params(VP9_COMP *cpi) { int target; if (!cpi->refresh_alt_ref_frame && (cm->current_video_frame == 0 || (cpi->frame_flags & FRAMEFLAGS_KEY) || - rc->frames_to_key == 0)) { + rc->frames_to_key == 0 || + (cpi->oxcf.mode != cpi->deadline_mode_previous_frame))) { cm->frame_type = KEY_FRAME; rc->this_key_frame_forced = cm->current_video_frame != 0 && rc->frames_to_key == 0; @@ -2122,6 +2148,7 @@ void vp9_rc_get_one_pass_vbr_params(VP9_COMP *cpi) { else target = vp9_calc_pframe_target_size_one_pass_vbr(cpi); vp9_rc_set_frame_target(cpi, target); + if (cm->show_frame) vp9_update_buffer_level_preencode(cpi); if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cpi->oxcf.pass == 0) vp9_cyclic_refresh_update_parameters(cpi); } @@ -2134,20 +2161,21 @@ int vp9_calc_pframe_target_size_one_pass_cbr(const VP9_COMP *cpi) { const int64_t one_pct_bits = 1 + rc->optimal_buffer_level / 100; int min_frame_target = VPXMAX(rc->avg_frame_bandwidth >> 4, FRAME_OVERHEAD_BITS); - int target; + int64_t target; - if (oxcf->gf_cbr_boost_pct) { + if (oxcf->gf_cbr_boost_pct && rc->baseline_gf_interval != INT_MAX) { const int af_ratio_pct = oxcf->gf_cbr_boost_pct + 100; target = cpi->refresh_golden_frame - ? (rc->avg_frame_bandwidth * rc->baseline_gf_interval * - af_ratio_pct) / + ? ((int64_t)rc->avg_frame_bandwidth * + rc->baseline_gf_interval * af_ratio_pct) / (rc->baseline_gf_interval * 100 + af_ratio_pct - 100) - : (rc->avg_frame_bandwidth * rc->baseline_gf_interval * 100) / + : ((int64_t)rc->avg_frame_bandwidth * + rc->baseline_gf_interval * 100) / (rc->baseline_gf_interval * 100 + af_ratio_pct - 100); } else { target = rc->avg_frame_bandwidth; } - if (is_one_pass_cbr_svc(cpi)) { + if (is_one_pass_svc(cpi)) { // Note that for layers, avg_frame_bandwidth is the cumulative // per-frame-bandwidth. For the target size of this frame, use the // layer average frame size (i.e., non-cumulative per-frame-bw). @@ -2168,22 +2196,21 @@ int vp9_calc_pframe_target_size_one_pass_cbr(const VP9_COMP *cpi) { target += (target * pct_high) / 200; } if (oxcf->rc_max_inter_bitrate_pct) { - const int max_rate = - rc->avg_frame_bandwidth * oxcf->rc_max_inter_bitrate_pct / 100; + const int64_t max_rate = + (int64_t)rc->avg_frame_bandwidth * oxcf->rc_max_inter_bitrate_pct / 100; target = VPXMIN(target, max_rate); } - return VPXMAX(min_frame_target, target); + if (target > INT_MAX) target = INT_MAX; + return VPXMAX(min_frame_target, (int)target); } int vp9_calc_iframe_target_size_one_pass_cbr(const VP9_COMP *cpi) { const RATE_CONTROL *rc = &cpi->rc; const VP9EncoderConfig *oxcf = &cpi->oxcf; const SVC *const svc = &cpi->svc; - int target; + int64_t target; if (cpi->common.current_video_frame == 0) { - target = ((rc->starting_buffer_level / 2) > INT_MAX) - ? INT_MAX - : (int)(rc->starting_buffer_level / 2); + target = rc->starting_buffer_level / 2; } else { int kf_boost = 32; double framerate = cpi->framerate; @@ -2195,13 +2222,15 @@ int vp9_calc_iframe_target_size_one_pass_cbr(const VP9_COMP *cpi) { const LAYER_CONTEXT *lc = &svc->layer_context[layer]; framerate = lc->framerate; } - kf_boost = VPXMAX(kf_boost, (int)(2 * framerate - 16)); + kf_boost = VPXMAX(kf_boost, (int)round(2 * framerate - 16)); if (rc->frames_since_key < framerate / 2) { - kf_boost = (int)(kf_boost * rc->frames_since_key / (framerate / 2)); + kf_boost = (int)round(kf_boost * rc->frames_since_key / (framerate / 2)); } - target = ((16 + kf_boost) * rc->avg_frame_bandwidth) >> 4; + + target = ((int64_t)(16 + kf_boost) * rc->avg_frame_bandwidth) >> 4; } - return vp9_rc_clamp_iframe_target_size(cpi, target); + target = VPXMIN(INT_MAX, target); + return vp9_rc_clamp_iframe_target_size(cpi, (int)target); } static void set_intra_only_frame(VP9_COMP *cpi) { @@ -2272,17 +2301,18 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) { // Periodic key frames is based on the super-frame counter // (svc.current_superframe), also only base spatial layer is key frame. // Key frame is set for any of the following: very first frame, frame flags - // indicates key, superframe counter hits key frequency, or (non-intra) sync - // flag is set for spatial layer 0. + // indicates key, superframe counter hits key frequency,(non-intra) sync + // flag is set for spatial layer 0, or deadline mode changes. if ((cm->current_video_frame == 0 && !svc->previous_frame_is_intra_only) || (cpi->frame_flags & FRAMEFLAGS_KEY) || (cpi->oxcf.auto_key && (svc->current_superframe % cpi->oxcf.key_freq == 0) && !svc->previous_frame_is_intra_only && svc->spatial_layer_id == 0) || - (svc->spatial_layer_sync[0] == 1 && svc->spatial_layer_id == 0)) { + (svc->spatial_layer_sync[0] == 1 && svc->spatial_layer_id == 0) || + (cpi->oxcf.mode != cpi->deadline_mode_previous_frame)) { cm->frame_type = KEY_FRAME; rc->source_alt_ref_active = 0; - if (is_one_pass_cbr_svc(cpi)) { + if (is_one_pass_svc(cpi)) { if (cm->current_video_frame > 0) vp9_svc_reset_temporal_layers(cpi, 1); layer = LAYER_IDS_TO_IDX(svc->spatial_layer_id, svc->temporal_layer_id, svc->number_temporal_layers); @@ -2290,11 +2320,14 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) { cpi->ref_frame_flags &= (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG); // Assumption here is that LAST_FRAME is being updated for a keyframe. // Thus no change in update flags. - target = vp9_calc_iframe_target_size_one_pass_cbr(cpi); + if (cpi->oxcf.rc_mode == VPX_CBR) + target = vp9_calc_iframe_target_size_one_pass_cbr(cpi); + else + target = vp9_calc_iframe_target_size_one_pass_vbr(cpi); } } else { cm->frame_type = INTER_FRAME; - if (is_one_pass_cbr_svc(cpi)) { + if (is_one_pass_svc(cpi)) { LAYER_CONTEXT *lc = &svc->layer_context[layer]; // Add condition current_video_frame > 0 for the case where first frame // is intra only followed by overlay/copy frame. In this case we don't @@ -2303,7 +2336,23 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) { (svc->spatial_layer_id == 0 && cm->current_video_frame > 0) ? 0 : svc->layer_context[svc->temporal_layer_id].is_key_frame; - target = vp9_calc_pframe_target_size_one_pass_cbr(cpi); + if (cpi->oxcf.rc_mode == VPX_CBR) { + target = vp9_calc_pframe_target_size_one_pass_cbr(cpi); + } else { + double rate_err = 0.0; + rc->fac_active_worst_inter = 140; + rc->fac_active_worst_gf = 100; + if (rc->rolling_target_bits > 0) { + rate_err = + (double)rc->rolling_actual_bits / (double)rc->rolling_target_bits; + if (rate_err < 1.0) + rc->fac_active_worst_inter = 120; + else if (rate_err > 2.0) + // Increase active_worst faster if rate fluctuation is high. + rc->fac_active_worst_inter = 160; + } + target = vp9_calc_pframe_target_size_one_pass_vbr(cpi); + } } } @@ -2312,7 +2361,10 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) { svc->layer_context[layer].is_key_frame == 1) { cm->frame_type = KEY_FRAME; cpi->ref_frame_flags &= (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG); - target = vp9_calc_iframe_target_size_one_pass_cbr(cpi); + if (cpi->oxcf.rc_mode == VPX_CBR) + target = vp9_calc_iframe_target_size_one_pass_cbr(cpi); + else + target = vp9_calc_iframe_target_size_one_pass_vbr(cpi); } // Set the buffer idx and refresh flags for key frames in simulcast mode. // Note the buffer slot for long-term reference is set below (line 2255), @@ -2397,7 +2449,10 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) { } if (svc->set_intra_only_frame) { set_intra_only_frame(cpi); - target = vp9_calc_iframe_target_size_one_pass_cbr(cpi); + if (cpi->oxcf.rc_mode == VPX_CBR) + target = vp9_calc_iframe_target_size_one_pass_cbr(cpi); + else + target = vp9_calc_iframe_target_size_one_pass_vbr(cpi); } // Overlay frame predicts from LAST (intra-only) if (svc->previous_frame_is_intra_only) cpi->ref_frame_flags |= VP9_LAST_FLAG; @@ -2408,7 +2463,7 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) { vp9_cyclic_refresh_update_parameters(cpi); vp9_rc_set_frame_target(cpi, target); - if (cm->show_frame) update_buffer_level_svc_preencode(cpi); + if (cm->show_frame) vp9_update_buffer_level_svc_preencode(cpi); if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC && svc->single_layer_svc == 1 && svc->spatial_layer_id == svc->first_spatial_layer_to_encode && @@ -2453,7 +2508,8 @@ void vp9_rc_get_one_pass_cbr_params(VP9_COMP *cpi) { RATE_CONTROL *const rc = &cpi->rc; int target; if ((cm->current_video_frame == 0) || (cpi->frame_flags & FRAMEFLAGS_KEY) || - (cpi->oxcf.auto_key && rc->frames_to_key == 0)) { + (cpi->oxcf.auto_key && rc->frames_to_key == 0) || + (cpi->oxcf.mode != cpi->deadline_mode_previous_frame)) { cm->frame_type = KEY_FRAME; rc->frames_to_key = cpi->oxcf.key_freq; rc->kf_boost = DEFAULT_KF_BOOST; @@ -2554,13 +2610,6 @@ void vp9_rc_set_gf_interval_range(const VP9_COMP *const cpi, // Set Maximum gf/arf interval rc->max_gf_interval = oxcf->max_gf_interval; rc->min_gf_interval = oxcf->min_gf_interval; -#if CONFIG_RATE_CTRL - if (oxcf->use_simple_encode_api) { - // In this experiment, we avoid framerate being changed dynamically during - // encoding. - framerate = oxcf->init_framerate; - } -#endif // CONFIG_RATE_CTRL if (rc->min_gf_interval == 0) { rc->min_gf_interval = vp9_rc_get_default_min_gf_interval( oxcf->width, oxcf->height, framerate); @@ -2584,13 +2633,12 @@ void vp9_rc_set_gf_interval_range(const VP9_COMP *const cpi, const uint32_t pic_breadth = VPXMAX(cpi->common.width, cpi->common.height); int i; - for (i = LEVEL_1; i < LEVEL_MAX; ++i) { + for (i = 0; i < VP9_LEVELS; ++i) { if (vp9_level_defs[i].max_luma_picture_size >= pic_size && vp9_level_defs[i].max_luma_picture_breadth >= pic_breadth) { if (rc->min_gf_interval <= (int)vp9_level_defs[i].min_altref_distance) { - rc->min_gf_interval = - (int)vp9_level_defs[i].min_altref_distance + 1; + rc->min_gf_interval = (int)vp9_level_defs[i].min_altref_distance; rc->max_gf_interval = VPXMAX(rc->max_gf_interval, rc->min_gf_interval); } @@ -2605,14 +2653,15 @@ void vp9_rc_update_framerate(VP9_COMP *cpi) { const VP9_COMMON *const cm = &cpi->common; const VP9EncoderConfig *const oxcf = &cpi->oxcf; RATE_CONTROL *const rc = &cpi->rc; - int vbr_max_bits; - rc->avg_frame_bandwidth = (int)(oxcf->target_bandwidth / cpi->framerate); - rc->min_frame_bandwidth = - (int)(rc->avg_frame_bandwidth * oxcf->two_pass_vbrmin_section / 100); + rc->avg_frame_bandwidth = saturate_cast_double_to_int( + round(oxcf->target_bandwidth / cpi->framerate)); - rc->min_frame_bandwidth = - VPXMAX(rc->min_frame_bandwidth, FRAME_OVERHEAD_BITS); + int64_t vbr_min_bits = + (int64_t)rc->avg_frame_bandwidth * oxcf->two_pass_vbrmin_section / 100; + vbr_min_bits = VPXMIN(vbr_min_bits, INT_MAX); + + rc->min_frame_bandwidth = VPXMAX((int)vbr_min_bits, FRAME_OVERHEAD_BITS); // A maximum bitrate for a frame is defined. // However this limit is extended if a very high rate is given on the command @@ -2621,11 +2670,12 @@ void vp9_rc_update_framerate(VP9_COMP *cpi) { // // If a level is specified that requires a lower maximum rate then the level // value take precedence. - vbr_max_bits = - (int)(((int64_t)rc->avg_frame_bandwidth * oxcf->two_pass_vbrmax_section) / - 100); + int64_t vbr_max_bits = + (int64_t)rc->avg_frame_bandwidth * oxcf->two_pass_vbrmax_section / 100; + vbr_max_bits = VPXMIN(vbr_max_bits, INT_MAX); + rc->max_frame_bandwidth = - VPXMAX(VPXMAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P), vbr_max_bits); + VPXMAX(VPXMAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P), (int)vbr_max_bits); vp9_rc_set_gf_interval_range(cpi, rc); } @@ -2635,44 +2685,43 @@ void vp9_rc_update_framerate(VP9_COMP *cpi) { static void vbr_rate_correction(VP9_COMP *cpi, int *this_frame_target) { RATE_CONTROL *const rc = &cpi->rc; int64_t vbr_bits_off_target = rc->vbr_bits_off_target; - int max_delta; - int frame_window = VPXMIN(16, ((int)cpi->twopass.total_stats.count - - cpi->common.current_video_frame)); + int64_t frame_target = *this_frame_target; + int frame_window = (int)VPXMIN( + 16, cpi->twopass.total_stats.count - cpi->common.current_video_frame); // Calcluate the adjustment to rate for this frame. if (frame_window > 0) { - max_delta = (vbr_bits_off_target > 0) - ? (int)(vbr_bits_off_target / frame_window) - : (int)(-vbr_bits_off_target / frame_window); + int64_t max_delta = (vbr_bits_off_target > 0) + ? (vbr_bits_off_target / frame_window) + : (-vbr_bits_off_target / frame_window); - max_delta = VPXMIN(max_delta, - ((*this_frame_target * VBR_PCT_ADJUSTMENT_LIMIT) / 100)); + max_delta = + VPXMIN(max_delta, ((frame_target * VBR_PCT_ADJUSTMENT_LIMIT) / 100)); // vbr_bits_off_target > 0 means we have extra bits to spend if (vbr_bits_off_target > 0) { - *this_frame_target += (vbr_bits_off_target > max_delta) - ? max_delta - : (int)vbr_bits_off_target; + frame_target += VPXMIN(vbr_bits_off_target, max_delta); } else { - *this_frame_target -= (vbr_bits_off_target < -max_delta) - ? max_delta - : (int)-vbr_bits_off_target; + frame_target -= VPXMIN(-vbr_bits_off_target, max_delta); } } // Fast redistribution of bits arising from massive local undershoot. - // Dont do it for kf,arf,gf or overlay frames. + // Don't do it for kf,arf,gf or overlay frames. if (!frame_is_kf_gf_arf(cpi) && !rc->is_src_frame_alt_ref && rc->vbr_bits_off_target_fast) { - int one_frame_bits = VPXMAX(rc->avg_frame_bandwidth, *this_frame_target); - int fast_extra_bits; - fast_extra_bits = (int)VPXMIN(rc->vbr_bits_off_target_fast, one_frame_bits); - fast_extra_bits = (int)VPXMIN( - fast_extra_bits, - VPXMAX(one_frame_bits / 8, rc->vbr_bits_off_target_fast / 8)); - *this_frame_target += (int)fast_extra_bits; + int64_t one_frame_bits = VPXMAX(rc->avg_frame_bandwidth, frame_target); + int64_t fast_extra_bits = + VPXMIN(rc->vbr_bits_off_target_fast, one_frame_bits); + fast_extra_bits = + VPXMIN(fast_extra_bits, + VPXMAX(one_frame_bits / 8, rc->vbr_bits_off_target_fast / 8)); + frame_target += fast_extra_bits; rc->vbr_bits_off_target_fast -= fast_extra_bits; } + + // Clamp the target for the frame to the maximum allowed for one frame. + *this_frame_target = (int)VPXMIN(frame_target, INT_MAX); } void vp9_set_target_rate(VP9_COMP *cpi) { @@ -2749,7 +2798,7 @@ int vp9_resize_one_pass_cbr(VP9_COMP *cpi) { // Resize based on average buffer underflow and QP over some window. // Ignore samples close to key frame, since QP is usually high after key. if (!force_downsize_rate && cpi->rc.frames_since_key > cpi->framerate) { - const int window = VPXMIN(30, (int)(2 * cpi->framerate)); + const int window = VPXMIN(30, (int)round(2 * cpi->framerate)); cpi->resize_avg_qp += rc->last_q[INTER_FRAME]; if (cpi->rc.buffer_level < (int)(30 * rc->optimal_buffer_level / 100)) ++cpi->resize_buffer_underflow; @@ -3223,12 +3272,21 @@ int vp9_encodedframe_overshoot(VP9_COMP *cpi, int frame_size, int *q) { double rate_correction_factor = cpi->rc.rate_correction_factors[INTER_NORMAL]; const int target_size = cpi->rc.avg_frame_bandwidth; + const uint64_t sad_thr = 64 * 64 * 32; + int force_maxqp = 1; double new_correction_factor; int target_bits_per_mb; double q2; int enumerator; - // Force a re-encode, and for now use max-QP. - *q = cpi->rc.worst_quality; + // Set a larger QP. + if (cpi->oxcf.content != VP9E_CONTENT_SCREEN && + (rc->buffer_level > (3 * rc->optimal_buffer_level) >> 2) && + (cpi->rc.avg_source_sad[0] < sad_thr)) { + *q = (*q + cpi->rc.worst_quality) >> 1; + force_maxqp = 0; + } else { + *q = cpi->rc.worst_quality; + } cpi->cyclic_refresh->counter_encode_maxq_scene_change = 0; cpi->rc.re_encode_maxq_scene_change = 1; // If the frame_size is much larger than the threshold (big content change) @@ -3240,11 +3298,9 @@ int vp9_encodedframe_overshoot(VP9_COMP *cpi, int frame_size, int *q) { MODE_INFO **mi = cm->mi_grid_visible; int sum_intra_usage = 0; int mi_row, mi_col; - int tot = 0; for (mi_row = 0; mi_row < cm->mi_rows; mi_row++) { for (mi_col = 0; mi_col < cm->mi_cols; mi_col++) { if (mi[0]->ref_frame[0] == INTRA_FRAME) sum_intra_usage++; - tot++; mi++; } mi += 8; @@ -3279,14 +3335,20 @@ int vp9_encodedframe_overshoot(VP9_COMP *cpi, int frame_size, int *q) { cpi->rc.rate_correction_factors[INTER_NORMAL] = rate_correction_factor; } // For temporal layers, reset the rate control parametes across all - // temporal layers. If the first_spatial_layer_to_encode > 0, then this - // superframe has skipped lower base layers. So in this case we should also - // reset and force max-q for spatial layers < first_spatial_layer_to_encode. + // temporal layers. + // If the first_spatial_layer_to_encode > 0, then this superframe has + // skipped lower base layers. So in this case we should also reset and + // force max-q for spatial layers < first_spatial_layer_to_encode. + // For the case of no inter-layer prediction on delta frames: reset and + // force max-q for all spatial layers, to avoid excessive frame drops. if (cpi->use_svc) { int tl = 0; int sl = 0; SVC *svc = &cpi->svc; - for (sl = 0; sl < VPXMAX(1, svc->first_spatial_layer_to_encode); ++sl) { + int num_spatial_layers = VPXMAX(1, svc->first_spatial_layer_to_encode); + if (svc->disable_inter_layer_pred != INTER_LAYER_PRED_ON) + num_spatial_layers = svc->number_spatial_layers; + for (sl = 0; sl < num_spatial_layers; ++sl) { for (tl = 0; tl < svc->number_temporal_layers; ++tl) { const int layer = LAYER_IDS_TO_IDX(sl, tl, svc->number_temporal_layers); @@ -3298,7 +3360,7 @@ int vp9_encodedframe_overshoot(VP9_COMP *cpi, int frame_size, int *q) { lrc->rc_1_frame = 0; lrc->rc_2_frame = 0; lrc->rate_correction_factors[INTER_NORMAL] = rate_correction_factor; - lrc->force_max_q = 1; + lrc->force_max_q = force_maxqp; } } } diff --git a/libs/libvpx/vp9/encoder/vp9_ratectrl.h b/libs/libvpx/vp9/encoder/vp9_ratectrl.h index 83a12cde73..0c61ad3461 100644 --- a/libs/libvpx/vp9/encoder/vp9_ratectrl.h +++ b/libs/libvpx/vp9/encoder/vp9_ratectrl.h @@ -211,6 +211,10 @@ typedef struct { // Flag to constrain golden frame interval on key frame frequency for 1 pass // VBR. int constrain_gf_key_freq_onepass_vbr; + + // The index of the current GOP. Start from zero. + // When a key frame is inserted, it resets to zero. + int gop_global_index; } RATE_CONTROL; struct VP9_COMP; @@ -342,10 +346,14 @@ int vp9_encodedframe_overshoot(struct VP9_COMP *cpi, int frame_size, int *q); void vp9_configure_buffer_updates(struct VP9_COMP *cpi, int gf_group_index); -void vp9_estimate_qp_gop(struct VP9_COMP *cpi); - void vp9_compute_frame_low_motion(struct VP9_COMP *const cpi); +void vp9_update_buffer_level_svc_preencode(struct VP9_COMP *cpi); + +int vp9_rc_pick_q_and_bounds_two_pass(const struct VP9_COMP *cpi, + int *bottom_index, int *top_index, + int gf_group_index); + #ifdef __cplusplus } // extern "C" #endif diff --git a/libs/libvpx/vp9/encoder/vp9_rd.c b/libs/libvpx/vp9/encoder/vp9_rd.c index 873aab3184..95c95971c5 100644 --- a/libs/libvpx/vp9/encoder/vp9_rd.c +++ b/libs/libvpx/vp9/encoder/vp9_rd.c @@ -244,6 +244,12 @@ int vp9_compute_rd_mult_based_on_qindex(const VP9_COMP *cpi, int qindex) { // largest dc_quant is 21387, therefore rdmult should fit in int32_t int rdmult = q * q; + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_RDMULT) != 0 && + cpi->ext_ratectrl.ext_rdmult != VPX_DEFAULT_RDMULT) { + return cpi->ext_ratectrl.ext_rdmult; + } + // Make sure this function is floating point safe. vpx_clear_system_state(); @@ -287,6 +293,11 @@ static int modulate_rdmult(const VP9_COMP *cpi, int rdmult) { int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex) { int rdmult = vp9_compute_rd_mult_based_on_qindex(cpi, qindex); + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_RDMULT) != 0 && + cpi->ext_ratectrl.ext_rdmult != VPX_DEFAULT_RDMULT) { + return cpi->ext_ratectrl.ext_rdmult; + } return modulate_rdmult(cpi, rdmult); } @@ -502,22 +513,6 @@ static void model_rd_norm(int xsq_q10, int *r_q10, int *d_q10) { *d_q10 = (dist_tab_q10[xq] * b_q10 + dist_tab_q10[xq + 1] * a_q10) >> 10; } -static void model_rd_norm_vec(int xsq_q10[MAX_MB_PLANE], - int r_q10[MAX_MB_PLANE], - int d_q10[MAX_MB_PLANE]) { - int i; - const int one_q10 = 1 << 10; - for (i = 0; i < MAX_MB_PLANE; ++i) { - const int tmp = (xsq_q10[i] >> 2) + 8; - const int k = get_msb(tmp) - 3; - const int xq = (k << 3) + ((tmp >> k) & 0x7); - const int a_q10 = ((xsq_q10[i] - xsq_iq_q10[xq]) << 10) >> (2 + k); - const int b_q10 = one_q10 - a_q10; - r_q10[i] = (rate_tab_q10[xq] * b_q10 + rate_tab_q10[xq + 1] * a_q10) >> 10; - d_q10[i] = (dist_tab_q10[xq] * b_q10 + dist_tab_q10[xq + 1] * a_q10) >> 10; - } -} - static const uint32_t MAX_XSQ_Q10 = 245727; void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n_log2, @@ -543,30 +538,12 @@ void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n_log2, } } -// Implements a fixed length vector form of vp9_model_rd_from_var_lapndz where -// vectors are of length MAX_MB_PLANE and all elements of var are non-zero. -void vp9_model_rd_from_var_lapndz_vec(unsigned int var[MAX_MB_PLANE], - unsigned int n_log2[MAX_MB_PLANE], - unsigned int qstep[MAX_MB_PLANE], - int64_t *rate_sum, int64_t *dist_sum) { - int i; - int xsq_q10[MAX_MB_PLANE], d_q10[MAX_MB_PLANE], r_q10[MAX_MB_PLANE]; - for (i = 0; i < MAX_MB_PLANE; ++i) { - const uint64_t xsq_q10_64 = - (((uint64_t)qstep[i] * qstep[i] << (n_log2[i] + 10)) + (var[i] >> 1)) / - var[i]; - xsq_q10[i] = (int)VPXMIN(xsq_q10_64, MAX_XSQ_Q10); - } - model_rd_norm_vec(xsq_q10, r_q10, d_q10); - for (i = 0; i < MAX_MB_PLANE; ++i) { - int rate = - ROUND_POWER_OF_TWO(r_q10[i] << n_log2[i], 10 - VP9_PROB_COST_SHIFT); - int64_t dist = (var[i] * (int64_t)d_q10[i] + 512) >> 10; - *rate_sum += rate; - *dist_sum += dist; - } -} - +// Disable gcc 12.2 false positive warning. +// warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size, const struct macroblockd_plane *pd, ENTROPY_CONTEXT t_above[16], @@ -604,6 +581,9 @@ void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size, break; } } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif void vp9_mv_pred(VP9_COMP *cpi, MACROBLOCK *x, uint8_t *ref_y_buffer, int ref_y_stride, int ref_frame, BLOCK_SIZE block_size) { @@ -629,7 +609,7 @@ void vp9_mv_pred(VP9_COMP *cpi, MACROBLOCK *x, uint8_t *ref_y_buffer, x->mbmi_ext->ref_mvs[ref_frame][1].as_int; // Get the sad for each candidate reference mv. - for (i = 0; i < num_mv_refs && i < MAX_MV_REF_CANDIDATES + 1; ++i) { + for (i = 0; i < num_mv_refs; ++i) { const MV *this_mv = &pred_mv[i]; int fp_row, fp_col; if (this_mv->row == INT16_MAX || this_mv->col == INT16_MAX) continue; diff --git a/libs/libvpx/vp9/encoder/vp9_rd.h b/libs/libvpx/vp9/encoder/vp9_rd.h index d2bc5e60ed..6c61ae514a 100644 --- a/libs/libvpx/vp9/encoder/vp9_rd.h +++ b/libs/libvpx/vp9/encoder/vp9_rd.h @@ -121,11 +121,9 @@ typedef struct RD_OPT { int64_t prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES]; int64_t filter_threshes[MAX_REF_FRAMES][SWITCHABLE_FILTER_CONTEXTS]; -#if CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL int64_t prediction_type_threshes_prev[MAX_REF_FRAMES][REFERENCE_MODES]; int64_t filter_threshes_prev[MAX_REF_FRAMES][SWITCHABLE_FILTER_CONTEXTS]; -#endif // CONFIG_CONSISTENT_RECODE || CONFIG_RATE_CTRL int RDMULT; int RDDIV; double r0; @@ -166,11 +164,6 @@ void vp9_initialize_me_consts(struct VP9_COMP *cpi, MACROBLOCK *x, int qindex); void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n_log2, unsigned int qstep, int *rate, int64_t *dist); -void vp9_model_rd_from_var_lapndz_vec(unsigned int var[MAX_MB_PLANE], - unsigned int n_log2[MAX_MB_PLANE], - unsigned int qstep[MAX_MB_PLANE], - int64_t *rate_sum, int64_t *dist_sum); - int vp9_get_switchable_rate(const struct VP9_COMP *cpi, const MACROBLOCKD *const xd); diff --git a/libs/libvpx/vp9/encoder/vp9_rdopt.c b/libs/libvpx/vp9/encoder/vp9_rdopt.c index 0171a05720..ce8e3fb148 100644 --- a/libs/libvpx/vp9/encoder/vp9_rdopt.c +++ b/libs/libvpx/vp9/encoder/vp9_rdopt.c @@ -77,7 +77,7 @@ struct rdcost_block_args { int64_t best_rd; int exit_early; int use_fast_coef_costing; - const scan_order *so; + const ScanOrder *so; uint8_t skippable; struct buf_2d *this_recon; }; @@ -86,28 +86,28 @@ struct rdcost_block_args { #if !CONFIG_REALTIME_ONLY static const MODE_DEFINITION vp9_mode_order[MAX_MODES] = { - { NEARESTMV, { LAST_FRAME, NONE } }, - { NEARESTMV, { ALTREF_FRAME, NONE } }, - { NEARESTMV, { GOLDEN_FRAME, NONE } }, + { NEARESTMV, { LAST_FRAME, NO_REF_FRAME } }, + { NEARESTMV, { ALTREF_FRAME, NO_REF_FRAME } }, + { NEARESTMV, { GOLDEN_FRAME, NO_REF_FRAME } }, - { DC_PRED, { INTRA_FRAME, NONE } }, + { DC_PRED, { INTRA_FRAME, NO_REF_FRAME } }, - { NEWMV, { LAST_FRAME, NONE } }, - { NEWMV, { ALTREF_FRAME, NONE } }, - { NEWMV, { GOLDEN_FRAME, NONE } }, + { NEWMV, { LAST_FRAME, NO_REF_FRAME } }, + { NEWMV, { ALTREF_FRAME, NO_REF_FRAME } }, + { NEWMV, { GOLDEN_FRAME, NO_REF_FRAME } }, - { NEARMV, { LAST_FRAME, NONE } }, - { NEARMV, { ALTREF_FRAME, NONE } }, - { NEARMV, { GOLDEN_FRAME, NONE } }, + { NEARMV, { LAST_FRAME, NO_REF_FRAME } }, + { NEARMV, { ALTREF_FRAME, NO_REF_FRAME } }, + { NEARMV, { GOLDEN_FRAME, NO_REF_FRAME } }, - { ZEROMV, { LAST_FRAME, NONE } }, - { ZEROMV, { GOLDEN_FRAME, NONE } }, - { ZEROMV, { ALTREF_FRAME, NONE } }, + { ZEROMV, { LAST_FRAME, NO_REF_FRAME } }, + { ZEROMV, { GOLDEN_FRAME, NO_REF_FRAME } }, + { ZEROMV, { ALTREF_FRAME, NO_REF_FRAME } }, { NEARESTMV, { LAST_FRAME, ALTREF_FRAME } }, { NEARESTMV, { GOLDEN_FRAME, ALTREF_FRAME } }, - { TM_PRED, { INTRA_FRAME, NONE } }, + { TM_PRED, { INTRA_FRAME, NO_REF_FRAME } }, { NEARMV, { LAST_FRAME, ALTREF_FRAME } }, { NEWMV, { LAST_FRAME, ALTREF_FRAME } }, @@ -117,20 +117,20 @@ static const MODE_DEFINITION vp9_mode_order[MAX_MODES] = { { ZEROMV, { LAST_FRAME, ALTREF_FRAME } }, { ZEROMV, { GOLDEN_FRAME, ALTREF_FRAME } }, - { H_PRED, { INTRA_FRAME, NONE } }, - { V_PRED, { INTRA_FRAME, NONE } }, - { D135_PRED, { INTRA_FRAME, NONE } }, - { D207_PRED, { INTRA_FRAME, NONE } }, - { D153_PRED, { INTRA_FRAME, NONE } }, - { D63_PRED, { INTRA_FRAME, NONE } }, - { D117_PRED, { INTRA_FRAME, NONE } }, - { D45_PRED, { INTRA_FRAME, NONE } }, + { H_PRED, { INTRA_FRAME, NO_REF_FRAME } }, + { V_PRED, { INTRA_FRAME, NO_REF_FRAME } }, + { D135_PRED, { INTRA_FRAME, NO_REF_FRAME } }, + { D207_PRED, { INTRA_FRAME, NO_REF_FRAME } }, + { D153_PRED, { INTRA_FRAME, NO_REF_FRAME } }, + { D63_PRED, { INTRA_FRAME, NO_REF_FRAME } }, + { D117_PRED, { INTRA_FRAME, NO_REF_FRAME } }, + { D45_PRED, { INTRA_FRAME, NO_REF_FRAME } }, }; static const REF_DEFINITION vp9_ref_order[MAX_REFS] = { - { { LAST_FRAME, NONE } }, { { GOLDEN_FRAME, NONE } }, - { { ALTREF_FRAME, NONE } }, { { LAST_FRAME, ALTREF_FRAME } }, - { { GOLDEN_FRAME, ALTREF_FRAME } }, { { INTRA_FRAME, NONE } }, + { { LAST_FRAME, NO_REF_FRAME } }, { { GOLDEN_FRAME, NO_REF_FRAME } }, + { { ALTREF_FRAME, NO_REF_FRAME } }, { { LAST_FRAME, ALTREF_FRAME } }, + { { GOLDEN_FRAME, ALTREF_FRAME } }, { { INTRA_FRAME, NO_REF_FRAME } }, }; #endif // !CONFIG_REALTIME_ONLY @@ -160,10 +160,13 @@ static void swap_block_ptr(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, int m, int n, } #if !CONFIG_REALTIME_ONLY -static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, MACROBLOCK *x, - MACROBLOCKD *xd, int *out_rate_sum, - int64_t *out_dist_sum, int *skip_txfm_sb, - int64_t *skip_sse_sb) { +// Planewise build inter prediction and compute rdcost with early termination +// option +static int build_inter_pred_model_rd_earlyterm( + VP9_COMP *cpi, int mi_row, int mi_col, BLOCK_SIZE bsize, MACROBLOCK *x, + MACROBLOCKD *xd, int *out_rate_sum, int64_t *out_dist_sum, + int *skip_txfm_sb, int64_t *skip_sse_sb, int do_earlyterm, + int64_t best_rd) { // Note our transform coeffs are 8 times an orthogonal transform. // Hence quantizer step is also 8 times. To get effective quantizer // we need to divide by 8 before sending to modeling function. @@ -176,19 +179,15 @@ static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, MACROBLOCK *x, int64_t total_sse = 0; int skip_flag = 1; const int shift = 6; - int64_t dist; const int dequant_shift = #if CONFIG_VP9_HIGHBITDEPTH (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ? xd->bd - 5 : #endif // CONFIG_VP9_HIGHBITDEPTH 3; - unsigned int qstep_vec[MAX_MB_PLANE]; - unsigned int nlog2_vec[MAX_MB_PLANE]; - unsigned int sum_sse_vec[MAX_MB_PLANE]; - int any_zero_sum_sse = 0; x->pred_sse[ref] = 0; + // Build prediction signal, compute stats and RD cost on per-plane basis for (i = 0; i < MAX_MB_PLANE; ++i) { struct macroblock_plane *const p = &x->plane[i]; struct macroblockd_plane *const pd = &xd->plane[i]; @@ -207,7 +206,14 @@ static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, MACROBLOCK *x, int idx, idy; int lw = b_width_log2_lookup[unit_size] + 2; int lh = b_height_log2_lookup[unit_size] + 2; + unsigned int qstep; + unsigned int nlog2; + int64_t dist = 0; + // Build inter predictor + vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, i); + + // Compute useful stats for (idy = 0; idy < bh; ++idy) { for (idx = 0; idx < bw; ++idx) { uint8_t *src = p->src.buf + (idy * p->src.stride << lh) + (idx << lw); @@ -243,46 +249,36 @@ static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, MACROBLOCK *x, } total_sse += sum_sse; - sum_sse_vec[i] = sum_sse; - any_zero_sum_sse = any_zero_sum_sse || (sum_sse == 0); - qstep_vec[i] = pd->dequant[1] >> dequant_shift; - nlog2_vec[i] = num_pels_log2_lookup[bs]; - } + qstep = pd->dequant[1] >> dequant_shift; + nlog2 = num_pels_log2_lookup[bs]; - // Fast approximate the modelling function. - if (cpi->sf.simple_model_rd_from_var) { - for (i = 0; i < MAX_MB_PLANE; ++i) { + // Fast approximate the modelling function. + if (cpi->sf.simple_model_rd_from_var) { int64_t rate; - const int64_t square_error = sum_sse_vec[i]; - int quantizer = qstep_vec[i]; - - if (quantizer < 120) - rate = (square_error * (280 - quantizer)) >> (16 - VP9_PROB_COST_SHIFT); + if (qstep < 120) + rate = ((int64_t)sum_sse * (280 - qstep)) >> (16 - VP9_PROB_COST_SHIFT); else rate = 0; - dist = (square_error * quantizer) >> 8; + dist = ((int64_t)sum_sse * qstep) >> 8; rate_sum += rate; - dist_sum += dist; - } - } else { - if (any_zero_sum_sse) { - for (i = 0; i < MAX_MB_PLANE; ++i) { - int rate; - vp9_model_rd_from_var_lapndz(sum_sse_vec[i], nlog2_vec[i], qstep_vec[i], - &rate, &dist); - rate_sum += rate; - dist_sum += dist; - } } else { - vp9_model_rd_from_var_lapndz_vec(sum_sse_vec, nlog2_vec, qstep_vec, - &rate_sum, &dist_sum); + int rate; + vp9_model_rd_from_var_lapndz(sum_sse, nlog2, qstep, &rate, &dist); + rate_sum += rate; + } + dist_sum += dist; + if (do_earlyterm) { + if (RDCOST(x->rdmult, x->rddiv, rate_sum, + dist_sum << VP9_DIST_SCALE_LOG2) >= best_rd) + return 1; } } - *skip_txfm_sb = skip_flag; *skip_sse_sb = total_sse << VP9_DIST_SCALE_LOG2; *out_rate_sum = (int)rate_sum; *out_dist_sum = dist_sum << VP9_DIST_SCALE_LOG2; + + return 0; } #endif // !CONFIG_REALTIME_ONLY @@ -369,7 +365,7 @@ static int cost_coeffs(MACROBLOCK *x, int plane, int block, TX_SIZE tx_size, const int16_t *band_count = &band_counts[tx_size][1]; const int eob = p->eobs[block]; const tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); - unsigned int(*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = + unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = x->token_costs[tx_size][type][is_inter_block(mi)]; uint8_t token_cache[32 * 32]; int cost; @@ -426,7 +422,7 @@ static int cost_coeffs(MACROBLOCK *x, int plane, int block, TX_SIZE tx_size, // dc token int v = qcoeff[0]; int16_t tok; - unsigned int(*tok_cost_ptr)[COEFF_CONTEXTS][ENTROPY_TOKENS]; + unsigned int (*tok_cost_ptr)[COEFF_CONTEXTS][ENTROPY_TOKENS]; cost = vp9_get_token_cost(v, &tok, cat6_high_cost); cost += (*token_costs)[0][pt][tok]; @@ -462,11 +458,6 @@ static int cost_coeffs(MACROBLOCK *x, int plane, int block, TX_SIZE tx_size, return cost; } -static INLINE int num_4x4_to_edge(int plane_4x4_dim, int mb_to_edge_dim, - int subsampling_dim, int blk_dim) { - return plane_4x4_dim + (mb_to_edge_dim >> (5 + subsampling_dim)) - blk_dim; -} - // Copy all visible 4x4s in the transform block. static void copy_block_visible(const MACROBLOCKD *xd, const struct macroblockd_plane *const pd, @@ -567,47 +558,11 @@ static unsigned pixel_sse(const VP9_COMP *const cpi, const MACROBLOCKD *xd, return sse; } -// Compute the squares sum squares on all visible 4x4s in the transform block. -static int64_t sum_squares_visible(const MACROBLOCKD *xd, - const struct macroblockd_plane *const pd, - const int16_t *diff, const int diff_stride, - int blk_row, int blk_col, - const BLOCK_SIZE plane_bsize, - const BLOCK_SIZE tx_bsize) { - int64_t sse; - const int plane_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize]; - const int plane_4x4_h = num_4x4_blocks_high_lookup[plane_bsize]; - const int tx_4x4_w = num_4x4_blocks_wide_lookup[tx_bsize]; - const int tx_4x4_h = num_4x4_blocks_high_lookup[tx_bsize]; - int b4x4s_to_right_edge = num_4x4_to_edge(plane_4x4_w, xd->mb_to_right_edge, - pd->subsampling_x, blk_col); - int b4x4s_to_bottom_edge = num_4x4_to_edge(plane_4x4_h, xd->mb_to_bottom_edge, - pd->subsampling_y, blk_row); - if (tx_bsize == BLOCK_4X4 || - (b4x4s_to_right_edge >= tx_4x4_w && b4x4s_to_bottom_edge >= tx_4x4_h)) { - assert(tx_4x4_w == tx_4x4_h); - sse = (int64_t)vpx_sum_squares_2d_i16(diff, diff_stride, tx_4x4_w << 2); - } else { - int r, c; - int max_r = VPXMIN(b4x4s_to_bottom_edge, tx_4x4_h); - int max_c = VPXMIN(b4x4s_to_right_edge, tx_4x4_w); - sse = 0; - // if we are in the unrestricted motion border. - for (r = 0; r < max_r; ++r) { - // Skip visiting the sub blocks that are wholly within the UMV. - for (c = 0; c < max_c; ++c) { - sse += (int64_t)vpx_sum_squares_2d_i16( - diff + r * diff_stride * 4 + c * 4, diff_stride, 4); - } - } - } - return sse; -} - static void dist_block(const VP9_COMP *cpi, MACROBLOCK *x, int plane, BLOCK_SIZE plane_bsize, int block, int blk_row, int blk_col, TX_SIZE tx_size, int64_t *out_dist, - int64_t *out_sse, struct buf_2d *out_recon) { + int64_t *out_sse, struct buf_2d *out_recon, + int sse_calc_done) { MACROBLOCKD *const xd = &x->e_mbd; const struct macroblock_plane *const p = &x->plane[plane]; const struct macroblockd_plane *const pd = &xd->plane[plane]; @@ -633,15 +588,15 @@ static void dist_block(const VP9_COMP *cpi, MACROBLOCK *x, int plane, if (x->skip_encode && !is_inter_block(xd->mi[0])) { // TODO(jingning): tune the model to better capture the distortion. - const int64_t p = + const int64_t mean_quant_error = (pd->dequant[1] * pd->dequant[1] * (1 << ss_txfrm_size)) >> #if CONFIG_VP9_HIGHBITDEPTH (shift + 2 + (bd - 8) * 2); #else (shift + 2); #endif // CONFIG_VP9_HIGHBITDEPTH - *out_dist += (p >> 4); - *out_sse += p; + *out_dist += (mean_quant_error >> 4); + *out_sse += mean_quant_error; } } else { const BLOCK_SIZE tx_bsize = txsize_to_bsize[tx_size]; @@ -657,8 +612,12 @@ static void dist_block(const VP9_COMP *cpi, MACROBLOCK *x, int plane, const tran_low_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); unsigned int tmp; - tmp = pixel_sse(cpi, xd, pd, src, src_stride, dst, dst_stride, blk_row, - blk_col, plane_bsize, tx_bsize); + if (sse_calc_done) { + tmp = (unsigned int)(*out_sse); + } else { + tmp = pixel_sse(cpi, xd, pd, src, src_stride, dst, dst_stride, blk_row, + blk_col, plane_bsize, tx_bsize); + } *out_sse = (int64_t)tmp * 16; if (out_recon) { const int out_recon_idx = 4 * (blk_row * out_recon->stride + blk_col); @@ -745,6 +704,7 @@ static void block_rd_txfm(int plane, int block, int blk_row, int blk_col, MODE_INFO *const mi = xd->mi[0]; int64_t rd1, rd2, rd; int rate; + int trellis_rate = -1; int64_t dist = INT64_MAX; int64_t sse = INT64_MAX; const int coeff_ctx = @@ -754,20 +714,41 @@ static void block_rd_txfm(int plane, int block, int blk_row, int blk_col, const struct macroblockd_plane *const pd = &xd->plane[plane]; const int dst_stride = pd->dst.stride; const uint8_t *dst = &pd->dst.buf[4 * (blk_row * dst_stride + blk_col)]; + const int enable_trellis_opt = args->cpi->sf.trellis_opt_tx_rd.method; + const double trellis_opt_thresh = args->cpi->sf.trellis_opt_tx_rd.thresh; + int sse_calc_done = 0; +#if CONFIG_MISMATCH_DEBUG + struct encode_b_args encode_b_arg = { + x, + enable_trellis_opt, + trellis_opt_thresh, + &sse_calc_done, + &sse, + args->t_above, + args->t_left, + &mi->skip, + &trellis_rate, + 0, // mi_row + 0, // mi_col + 0 // output_enabled + }; +#else + struct encode_b_args encode_b_arg = { x, + enable_trellis_opt, + trellis_opt_thresh, + &sse_calc_done, + &sse, + args->t_above, + args->t_left, + &mi->skip, + &trellis_rate }; +#endif if (args->exit_early) return; if (!is_inter_block(mi)) { -#if CONFIG_MISMATCH_DEBUG - struct encode_b_args intra_arg = { - x, x->block_qcoeff_opt, args->t_above, args->t_left, &mi->skip, 0, 0, 0 - }; -#else - struct encode_b_args intra_arg = { x, x->block_qcoeff_opt, args->t_above, - args->t_left, &mi->skip }; -#endif vp9_encode_block_intra(plane, block, blk_row, blk_col, plane_bsize, tx_size, - &intra_arg); + &encode_b_arg); if (recon) { uint8_t *rec_ptr = &recon->buf[4 * (blk_row * recon->stride + blk_col)]; copy_block_visible(xd, pd, dst, dst_stride, rec_ptr, recon->stride, @@ -775,16 +756,21 @@ static void block_rd_txfm(int plane, int block, int blk_row, int blk_col, } if (x->block_tx_domain) { dist_block(args->cpi, x, plane, plane_bsize, block, blk_row, blk_col, - tx_size, &dist, &sse, /*recon =*/0); + tx_size, &dist, &sse, /*out_recon=*/NULL, sse_calc_done); } else { const struct macroblock_plane *const p = &x->plane[plane]; const int src_stride = p->src.stride; - const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; const uint8_t *src = &p->src.buf[4 * (blk_row * src_stride + blk_col)]; - const int16_t *diff = &p->src_diff[4 * (blk_row * diff_stride + blk_col)]; unsigned int tmp; - sse = sum_squares_visible(xd, pd, diff, diff_stride, blk_row, blk_col, - plane_bsize, tx_bsize); + if (!sse_calc_done) { + const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; + const int16_t *diff = + &p->src_diff[4 * (blk_row * diff_stride + blk_col)]; + int visible_width, visible_height; + sse = sum_squares_visible(xd, pd, diff, diff_stride, blk_row, blk_col, + plane_bsize, tx_bsize, &visible_width, + &visible_height); + } #if CONFIG_VP9_HIGHBITDEPTH if ((xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) && (xd->bd > 8)) sse = ROUND64_POWER_OF_TWO(sse, (xd->bd - 8) * 2); @@ -808,12 +794,19 @@ static void block_rd_txfm(int plane, int block, int blk_row, int blk_col, if (skip_txfm_flag == SKIP_TXFM_NONE || (recon && skip_txfm_flag == SKIP_TXFM_AC_ONLY)) { + const struct macroblock_plane *const p = &x->plane[plane]; + const int diff_stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; + const int16_t *const diff = + &p->src_diff[4 * (blk_row * diff_stride + blk_col)]; + const int use_trellis_opt = + do_trellis_opt(pd, diff, diff_stride, blk_row, blk_col, plane_bsize, + tx_size, &encode_b_arg); // full forward transform and quantization vp9_xform_quant(x, plane, block, blk_row, blk_col, plane_bsize, tx_size); - if (x->block_qcoeff_opt) - vp9_optimize_b(x, plane, block, tx_size, coeff_ctx); + if (use_trellis_opt) + vp9_optimize_b(x, plane, block, tx_size, coeff_ctx, &trellis_rate); dist_block(args->cpi, x, plane, plane_bsize, block, blk_row, blk_col, - tx_size, &dist, &sse, recon); + tx_size, &dist, &sse, recon, sse_calc_done); } else if (skip_txfm_flag == SKIP_TXFM_AC_ONLY) { // compute DC coefficient tran_low_t *const coeff = BLOCK_OFFSET(x->plane[plane].coeff, block); @@ -844,7 +837,14 @@ static void block_rd_txfm(int plane, int block, int blk_row, int blk_col, return; } - rate = rate_block(plane, block, tx_size, coeff_ctx, args); +#ifndef NDEBUG + if (trellis_rate >= 0 && !args->use_fast_coef_costing) { + assert(trellis_rate == rate_block(plane, block, tx_size, coeff_ctx, args)); + } +#endif + rate = (trellis_rate >= 0 && !args->use_fast_coef_costing) + ? trellis_rate + : rate_block(plane, block, tx_size, coeff_ctx, args); args->t_above[blk_col] = (x->plane[plane].eobs[block] > 0) ? 1 : 0; args->t_left[blk_row] = (x->plane[plane].eobs[block] > 0) ? 1 : 0; rd1 = RDCOST(x->rdmult, x->rddiv, rate, dist); @@ -1093,7 +1093,7 @@ static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int row, const int src_stride = p->src.stride; const int dst_stride = pd->dst.stride; const uint8_t *src_init = &p->src.buf[row * 4 * src_stride + col * 4]; - uint8_t *dst_init = &pd->dst.buf[row * 4 * src_stride + col * 4]; + uint8_t *dst_init = &pd->dst.buf[row * 4 * dst_stride + col * 4]; ENTROPY_CONTEXT ta[2], tempa[2]; ENTROPY_CONTEXT tl[2], templ[2]; const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; @@ -1108,6 +1108,8 @@ static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int row, xd->mi[0]->tx_size = TX_4X4; + assert(!x->skip_block); + #if CONFIG_VP9_HIGHBITDEPTH if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { for (mode = DC_PRED; mode <= TM_PRED; ++mode) { @@ -1135,7 +1137,10 @@ static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int row, uint16_t *const dst16 = CONVERT_TO_SHORTPTR(dst); int16_t *const src_diff = vp9_raster_block_offset_int16(BLOCK_8X8, block, p->src_diff); - tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block); + tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); + tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); + tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); + uint16_t *const eob = &p->eobs[block]; xd->mi[0]->bmi[block].as_mode = mode; vp9_predict_intra_block(xd, 1, TX_4X4, mode, x->skip_encode ? src : dst, @@ -1144,11 +1149,12 @@ static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int row, vpx_highbd_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride, xd->bd); if (xd->lossless) { - const scan_order *so = &vp9_default_scan_orders[TX_4X4]; + const ScanOrder *so = &vp9_default_scan_orders[TX_4X4]; const int coeff_ctx = combine_entropy_contexts(tempa[idx], templ[idy]); vp9_highbd_fwht4x4(src_diff, coeff, 8); - vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan); + vpx_highbd_quantize_b(coeff, 4 * 4, p, qcoeff, dqcoeff, pd->dequant, + eob, so); ratey += cost_coeffs(x, 0, block, TX_4X4, coeff_ctx, so->scan, so->neighbors, cpi->sf.use_fast_coef_costing); tempa[idx] = templ[idy] = (x->plane[0].eobs[block] > 0 ? 1 : 0); @@ -1159,14 +1165,15 @@ static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int row, } else { int64_t unused; const TX_TYPE tx_type = get_tx_type_4x4(PLANE_TYPE_Y, xd, block); - const scan_order *so = &vp9_scan_orders[TX_4X4][tx_type]; + const ScanOrder *so = &vp9_scan_orders[TX_4X4][tx_type]; const int coeff_ctx = combine_entropy_contexts(tempa[idx], templ[idy]); if (tx_type == DCT_DCT) vpx_highbd_fdct4x4(src_diff, coeff, 8); else vp9_highbd_fht4x4(src_diff, coeff, 8, tx_type); - vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan); + vpx_highbd_quantize_b(coeff, 4 * 4, p, qcoeff, dqcoeff, pd->dequant, + eob, so); ratey += cost_coeffs(x, 0, block, TX_4X4, coeff_ctx, so->scan, so->neighbors, cpi->sf.use_fast_coef_costing); distortion += vp9_highbd_block_error_dispatch( @@ -1199,7 +1206,7 @@ static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int row, num_4x4_blocks_wide * 4 * sizeof(uint16_t)); } } - next_highbd : {} + next_highbd: {} } if (best_rd >= rd_thresh || x->skip_encode) return best_rd; @@ -1236,7 +1243,10 @@ static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int row, uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride]; int16_t *const src_diff = vp9_raster_block_offset_int16(BLOCK_8X8, block, p->src_diff); - tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block); + tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); + tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); + tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); + uint16_t *const eob = &p->eobs[block]; xd->mi[0]->bmi[block].as_mode = mode; vp9_predict_intra_block(xd, 1, TX_4X4, mode, x->skip_encode ? src : dst, x->skip_encode ? src_stride : dst_stride, dst, @@ -1244,11 +1254,12 @@ static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int row, vpx_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride); if (xd->lossless) { - const scan_order *so = &vp9_default_scan_orders[TX_4X4]; + const ScanOrder *so = &vp9_default_scan_orders[TX_4X4]; const int coeff_ctx = combine_entropy_contexts(tempa[idx], templ[idy]); vp9_fwht4x4(src_diff, coeff, 8); - vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan); + vpx_quantize_b(coeff, 4 * 4, p, qcoeff, dqcoeff, pd->dequant, eob, + so); ratey += cost_coeffs(x, 0, block, TX_4X4, coeff_ctx, so->scan, so->neighbors, cpi->sf.use_fast_coef_costing); tempa[idx] = templ[idy] = (x->plane[0].eobs[block] > 0) ? 1 : 0; @@ -1259,11 +1270,12 @@ static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int row, } else { int64_t unused; const TX_TYPE tx_type = get_tx_type_4x4(PLANE_TYPE_Y, xd, block); - const scan_order *so = &vp9_scan_orders[TX_4X4][tx_type]; + const ScanOrder *so = &vp9_scan_orders[TX_4X4][tx_type]; const int coeff_ctx = combine_entropy_contexts(tempa[idx], templ[idy]); vp9_fht4x4(src_diff, coeff, 8, tx_type); - vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan); + vpx_quantize_b(coeff, 4 * 4, p, qcoeff, dqcoeff, pd->dequant, eob, + so); ratey += cost_coeffs(x, 0, block, TX_4X4, coeff_ctx, so->scan, so->neighbors, cpi->sf.use_fast_coef_costing); tempa[idx] = templ[idy] = (x->plane[0].eobs[block] > 0) ? 1 : 0; @@ -1293,7 +1305,7 @@ static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int row, memcpy(best_dst + idy * 8, dst_init + idy * dst_stride, num_4x4_blocks_wide * 4); } - next : {} + next: {} } if (best_rd >= rd_thresh || x->skip_encode) return best_rd; @@ -1400,7 +1412,7 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x, int *rate, mic->mode = mode; super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, &s, NULL, - bsize, best_rd, /*recon = */ 0); + bsize, best_rd, /*recon=*/NULL); if (this_rate_tokenonly == INT_MAX) continue; @@ -1440,7 +1452,6 @@ static int super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x, int *rate, if (ref_best_rd < 0) is_cost_valid = 0; if (is_inter_block(mi) && is_cost_valid) { - int plane; for (plane = 1; plane < MAX_MB_PLANE; ++plane) vp9_subtract_plane(x, bsize, plane); } @@ -1453,7 +1464,7 @@ static int super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x, int *rate, for (plane = 1; plane < MAX_MB_PLANE; ++plane) { txfm_rd_in_plane(cpi, x, &pnrate, &pndist, &pnskip, &pnsse, ref_best_rd, plane, bsize, uv_tx_size, cpi->sf.use_fast_coef_costing, - /*recon = */ 0); + /*recon=*/NULL); if (pnrate == INT_MAX) { is_cost_valid = 0; break; @@ -1636,10 +1647,12 @@ static int64_t encode_inter_mb_segment(VP9_COMP *cpi, MACROBLOCK *x, &pd->dst.buf[vp9_raster_block_offset(BLOCK_8X8, i, pd->dst.stride)]; int64_t thisdistortion = 0, thissse = 0; int thisrate = 0, ref; - const scan_order *so = &vp9_default_scan_orders[TX_4X4]; + const ScanOrder *so = &vp9_default_scan_orders[TX_4X4]; const int is_compound = has_second_ref(mi); const InterpKernel *kernel = vp9_filter_kernels[mi->interp_filter]; + assert(!x->skip_block); + for (ref = 0; ref < 1 + is_compound; ++ref) { const int bw = b_width_log2_lookup[BLOCK_8X8]; const int h = 4 * (i >> bw); @@ -1701,18 +1714,25 @@ static int64_t encode_inter_mb_segment(VP9_COMP *cpi, MACROBLOCK *x, const int bd = (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) ? xd->bd : 8; #endif int64_t ssz, rd, rd1, rd2; - tran_low_t *coeff; + tran_low_t *coeff, *qcoeff, *dqcoeff; + uint16_t *eob; int coeff_ctx; k += (idy * 2 + idx); coeff_ctx = combine_entropy_contexts(ta[k & 1], tl[k >> 1]); coeff = BLOCK_OFFSET(p->coeff, k); + qcoeff = BLOCK_OFFSET(p->qcoeff, k); + dqcoeff = BLOCK_OFFSET(pd->dqcoeff, k); + eob = &p->eobs[k]; + x->fwd_txfm4x4(vp9_raster_block_offset_int16(BLOCK_8X8, k, p->src_diff), coeff, 8); - vp9_regular_quantize_b_4x4(x, 0, k, so->scan, so->iscan); #if CONFIG_VP9_HIGHBITDEPTH + vpx_highbd_quantize_b(coeff, 4 * 4, p, qcoeff, dqcoeff, pd->dequant, eob, + so); thisdistortion += vp9_highbd_block_error_dispatch( coeff, BLOCK_OFFSET(pd->dqcoeff, k), 16, &ssz, bd); #else + vpx_quantize_b(coeff, 4 * 4, p, qcoeff, dqcoeff, pd->dequant, eob, so); thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k), 16, &ssz); #endif // CONFIG_VP9_HIGHBITDEPTH @@ -1806,7 +1826,7 @@ static int check_best_zero_mv(const VP9_COMP *cpi, const MV_REFERENCE_FRAME ref_frames[2]) { if ((this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) && frame_mv[this_mode][ref_frames[0]].as_int == 0 && - (ref_frames[1] == NONE || + (ref_frames[1] == NO_REF_FRAME || frame_mv[this_mode][ref_frames[1]].as_int == 0)) { int rfc = mode_context[ref_frames[0]]; int c1 = cost_mv_ref(cpi, NEARMV, rfc); @@ -1819,7 +1839,7 @@ static int check_best_zero_mv(const VP9_COMP *cpi, if (c2 > c3) return 0; } else { assert(this_mode == ZEROMV); - if (ref_frames[1] == NONE) { + if (ref_frames[1] == NO_REF_FRAME) { if ((c3 >= c2 && frame_mv[NEARESTMV][ref_frames[0]].as_int == 0) || (c3 >= c1 && frame_mv[NEARMV][ref_frames[0]].as_int == 0)) return 0; @@ -1835,10 +1855,80 @@ static int check_best_zero_mv(const VP9_COMP *cpi, return 1; } +static INLINE int skip_iters(int_mv iter_mvs[][2], int ite, int id) { + if (ite >= 2 && iter_mvs[ite - 2][!id].as_int == iter_mvs[ite][!id].as_int) { + int_mv cur_fullpel_mv, prev_fullpel_mv; + cur_fullpel_mv.as_mv.row = iter_mvs[ite][id].as_mv.row >> 3; + cur_fullpel_mv.as_mv.col = iter_mvs[ite][id].as_mv.col >> 3; + prev_fullpel_mv.as_mv.row = iter_mvs[ite - 2][id].as_mv.row >> 3; + prev_fullpel_mv.as_mv.col = iter_mvs[ite - 2][id].as_mv.col >> 3; + if (cur_fullpel_mv.as_int == prev_fullpel_mv.as_int) return 1; + } + return 0; +} + +// Compares motion vector and mode rate of current mode and given mode. +static INLINE int compare_mv_mode_rate(MV this_mv, MV mode_mv, + int this_mode_rate, int mode_rate, + int mv_thresh) { + const int mv_diff = + abs(mode_mv.col - this_mv.col) + abs(mode_mv.row - this_mv.row); + if (mv_diff <= mv_thresh && mode_rate < this_mode_rate) return 1; + return 0; +} + +// Skips single reference inter modes NEARMV and ZEROMV based on motion vector +// difference and mode rate. +static INLINE int skip_single_mode_based_on_mode_rate( + int_mv (*mode_mv)[MAX_REF_FRAMES], int *single_mode_rate, int this_mode, + int ref0, int this_mode_rate, int best_mode_index) { + MV this_mv = mode_mv[this_mode][ref0].as_mv; + const int mv_thresh = 3; + + // Pruning is not applicable for NEARESTMV or NEWMV modes. + if (this_mode == NEARESTMV || this_mode == NEWMV) return 0; + // Pruning is not done when reference frame of the mode is same as best + // reference so far. + if (best_mode_index > 0 && + ref0 == vp9_mode_order[best_mode_index].ref_frame[0]) + return 0; + + // Check absolute mv difference and mode rate of current mode w.r.t NEARESTMV + if (compare_mv_mode_rate( + this_mv, mode_mv[NEARESTMV][ref0].as_mv, this_mode_rate, + single_mode_rate[INTER_OFFSET(NEARESTMV)], mv_thresh)) + return 1; + + // Check absolute mv difference and mode rate of current mode w.r.t NEWMV + if (compare_mv_mode_rate(this_mv, mode_mv[NEWMV][ref0].as_mv, this_mode_rate, + single_mode_rate[INTER_OFFSET(NEWMV)], mv_thresh)) + return 1; + + // Pruning w.r.t NEARMV is applicable only for ZEROMV mode + if (this_mode == NEARMV) return 0; + // Check absolute mv difference and mode rate of current mode w.r.t NEARMV + if (compare_mv_mode_rate(this_mv, mode_mv[NEARMV][ref0].as_mv, this_mode_rate, + single_mode_rate[INTER_OFFSET(NEARMV)], mv_thresh)) + return 1; + return 0; +} + +#define MAX_JOINT_MV_SEARCH_ITERS 4 +static INLINE int get_joint_search_iters(int sf_level, BLOCK_SIZE bsize) { + int num_iters = MAX_JOINT_MV_SEARCH_ITERS; // sf_level = 0 + if (sf_level >= 2) + num_iters = 0; + else if (sf_level >= 1) + num_iters = bsize < BLOCK_8X8 + ? 0 + : (bsize <= BLOCK_16X16 ? 2 : MAX_JOINT_MV_SEARCH_ITERS); + return num_iters; +} + static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, int_mv *frame_mv, int mi_row, int mi_col, int_mv single_newmv[MAX_REF_FRAMES], - int *rate_mv) { + int *rate_mv, int num_iters) { const VP9_COMMON *const cm = &cpi->common; const int pw = 4 * num_4x4_blocks_wide_lookup[bsize]; const int ph = 4 * num_4x4_blocks_high_lookup[bsize]; @@ -1847,6 +1937,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, const int refs[2] = { mi->ref_frame[0], mi->ref_frame[1] < 0 ? 0 : mi->ref_frame[1] }; int_mv ref_mv[2]; + int_mv iter_mvs[MAX_JOINT_MV_SEARCH_ITERS][2]; int ite, ref; const InterpKernel *kernel = vp9_filter_kernels[mi->interp_filter]; struct scale_factors sf; @@ -1861,12 +1952,15 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, // Prediction buffer from second frame. #if CONFIG_VP9_HIGHBITDEPTH - DECLARE_ALIGNED(16, uint16_t, second_pred_alloc_16[64 * 64]); + DECLARE_ALIGNED(32, uint16_t, second_pred_alloc_16[64 * 64]); uint8_t *second_pred; #else - DECLARE_ALIGNED(16, uint8_t, second_pred[64 * 64]); + DECLARE_ALIGNED(32, uint8_t, second_pred[64 * 64]); #endif // CONFIG_VP9_HIGHBITDEPTH + // Check number of iterations do not exceed the max + assert(num_iters <= MAX_JOINT_MV_SEARCH_ITERS); + for (ref = 0; ref < 2; ++ref) { ref_mv[ref] = x->mbmi_ext->ref_mvs[refs[ref]][0]; @@ -1882,6 +1976,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, } frame_mv[refs[ref]].as_int = single_newmv[refs[ref]].as_int; + iter_mvs[0][ref].as_int = single_newmv[refs[ref]].as_int; } // Since we have scaled the reference frames to match the size of the current @@ -1896,7 +1991,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, // Allow joint search multiple times iteratively for each reference frame // and break out of the search loop if it couldn't find a better mv. - for (ite = 0; ite < 4; ite++) { + for (ite = 0; ite < num_iters; ite++) { struct buf_2d ref_yv12[2]; uint32_t bestsme = UINT_MAX; int sadpb = x->sadperbit16; @@ -1908,6 +2003,11 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, // odd iterations search in the second. The predictor // found for the 'other' reference frame is factored in. + // Skip further iterations of search if in the previous iteration, the + // motion vector of the searched ref frame is unchanged, and the other ref + // frame's full-pixel mv is unchanged. + if (skip_iters(iter_mvs, ite, id)) break; + // Initialized here because of compiler problem in Visual Studio. ref_yv12[0] = xd->plane[0].pre[0]; ref_yv12[1] = xd->plane[0].pre[1]; @@ -1973,6 +2073,10 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, } else { break; } + if (ite < num_iters - 1) { + iter_mvs[ite + 1][0].as_int = frame_mv[refs[0]].as_int; + iter_mvs[ite + 1][1].as_int = frame_mv[refs[1]].as_int; + } } *rate_mv = 0; @@ -1993,7 +2097,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, static int64_t rd_pick_best_sub8x8_mode( VP9_COMP *cpi, MACROBLOCK *x, int_mv *best_ref_mv, - int_mv *second_best_ref_mv, int64_t best_rd, int *returntotrate, + int_mv *second_best_ref_mv, int64_t best_rd_so_far, int *returntotrate, int *returnyrate, int64_t *returndistortion, int *skippable, int64_t *psse, int mvthresh, int_mv seg_mvs[4][MAX_REF_FRAMES], BEST_SEG_INFO *bsi_buf, int filter_idx, int mi_row, int mi_col) { @@ -2026,7 +2130,7 @@ static int64_t rd_pick_best_sub8x8_mode( vp9_zero(*bsi); - bsi->segment_rd = best_rd; + bsi->segment_rd = best_rd_so_far; bsi->ref_mv[0] = best_ref_mv; bsi->ref_mv[1] = second_best_ref_mv; bsi->mvp.as_int = best_ref_mv->as_int; @@ -2052,14 +2156,14 @@ static int64_t rd_pick_best_sub8x8_mode( int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; PREDICTION_MODE mode_selected = ZEROMV; int64_t best_rd = INT64_MAX; - const int i = idy * 2 + idx; + const int block = idy * 2 + idx; int ref; for (ref = 0; ref < 1 + has_second_rf; ++ref) { const MV_REFERENCE_FRAME frame = mi->ref_frame[ref]; frame_mv[ZEROMV][frame].as_int = 0; vp9_append_sub8x8_mvs_for_idx( - cm, xd, i, ref, mi_row, mi_col, &frame_mv[NEARESTMV][frame], + cm, xd, block, ref, mi_row, mi_col, &frame_mv[NEARESTMV][frame], &frame_mv[NEARMV][frame], mbmi_ext->mode_context); } @@ -2069,7 +2173,7 @@ static int64_t rd_pick_best_sub8x8_mode( struct buf_2d orig_pre[2]; mode_idx = INTER_OFFSET(this_mode); - bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; + bsi->rdstat[block][mode_idx].brdcost = INT64_MAX; if (!(inter_mode_mask & (1 << this_mode))) continue; if (!check_best_zero_mv(cpi, mbmi_ext->mode_context, frame_mv, @@ -2077,14 +2181,14 @@ static int64_t rd_pick_best_sub8x8_mode( continue; memcpy(orig_pre, pd->pre, sizeof(orig_pre)); - memcpy(bsi->rdstat[i][mode_idx].ta, t_above, - sizeof(bsi->rdstat[i][mode_idx].ta)); - memcpy(bsi->rdstat[i][mode_idx].tl, t_left, - sizeof(bsi->rdstat[i][mode_idx].tl)); + memcpy(bsi->rdstat[block][mode_idx].ta, t_above, + sizeof(bsi->rdstat[block][mode_idx].ta)); + memcpy(bsi->rdstat[block][mode_idx].tl, t_left, + sizeof(bsi->rdstat[block][mode_idx].tl)); // motion search for newmv (single predictor case only) if (!has_second_rf && this_mode == NEWMV && - seg_mvs[i][mi->ref_frame[0]].as_int == INVALID_MV) { + seg_mvs[block][mi->ref_frame[0]].as_int == INVALID_MV) { MV *const new_mv = &mode_mv[NEWMV][0].as_mv; int step_param = 0; uint32_t bestsme = UINT_MAX; @@ -2094,18 +2198,19 @@ static int64_t rd_pick_best_sub8x8_mode( int cost_list[5]; const MvLimits tmp_mv_limits = x->mv_limits; - /* Is the best so far sufficiently good that we cant justify doing + /* Is the best so far sufficiently good that we can't justify doing * and new motion search. */ if (best_rd < label_mv_thresh) break; if (cpi->oxcf.mode != BEST) { // use previous block's result as next block's MV predictor. - if (i > 0) { - bsi->mvp.as_int = mi->bmi[i - 1].as_mv[0].as_int; - if (i == 2) bsi->mvp.as_int = mi->bmi[i - 2].as_mv[0].as_int; + if (block > 0) { + bsi->mvp.as_int = mi->bmi[block - 1].as_mv[0].as_int; + if (block == 2) + bsi->mvp.as_int = mi->bmi[block - 2].as_mv[0].as_int; } } - if (i == 0) + if (block == 0) max_mv = x->max_mv_context[mi->ref_frame[0]]; else max_mv = @@ -2134,7 +2239,7 @@ static int64_t rd_pick_best_sub8x8_mode( } // adjust src pointer for this block - mi_buf_shift(x, i); + mi_buf_shift(x, block); vp9_set_mv_search_range(&x->mv_limits, &bsi->ref_mv[0]->as_mv); @@ -2157,7 +2262,7 @@ static int64_t rd_pick_best_sub8x8_mode( cpi->sf.use_accurate_subpel_search); // save motion search result for use in compound prediction - seg_mvs[i][mi->ref_frame[0]].as_mv = *new_mv; + seg_mvs[block][mi->ref_frame[0]].as_mv = *new_mv; } x->pred_mv[mi->ref_frame[0]] = *new_mv; @@ -2167,40 +2272,44 @@ static int64_t rd_pick_best_sub8x8_mode( } if (has_second_rf) { - if (seg_mvs[i][mi->ref_frame[1]].as_int == INVALID_MV || - seg_mvs[i][mi->ref_frame[0]].as_int == INVALID_MV) + if (seg_mvs[block][mi->ref_frame[1]].as_int == INVALID_MV || + seg_mvs[block][mi->ref_frame[0]].as_int == INVALID_MV) continue; } if (has_second_rf && this_mode == NEWMV && mi->interp_filter == EIGHTTAP) { + // Decide number of joint motion search iterations + const int num_joint_search_iters = get_joint_search_iters( + cpi->sf.comp_inter_joint_search_iter_level, bsize); // adjust src pointers - mi_buf_shift(x, i); - if (sf->comp_inter_joint_search_thresh <= bsize) { + mi_buf_shift(x, block); + if (num_joint_search_iters) { int rate_mv; joint_motion_search(cpi, x, bsize, frame_mv[this_mode], mi_row, - mi_col, seg_mvs[i], &rate_mv); - seg_mvs[i][mi->ref_frame[0]].as_int = + mi_col, seg_mvs[block], &rate_mv, + num_joint_search_iters); + seg_mvs[block][mi->ref_frame[0]].as_int = frame_mv[this_mode][mi->ref_frame[0]].as_int; - seg_mvs[i][mi->ref_frame[1]].as_int = + seg_mvs[block][mi->ref_frame[1]].as_int = frame_mv[this_mode][mi->ref_frame[1]].as_int; } // restore src pointers mi_buf_restore(x, orig_src, orig_pre); } - bsi->rdstat[i][mode_idx].brate = set_and_cost_bmi_mvs( - cpi, x, xd, i, this_mode, mode_mv[this_mode], frame_mv, seg_mvs[i], - bsi->ref_mv, x->nmvjointcost, x->mvcost); + bsi->rdstat[block][mode_idx].brate = set_and_cost_bmi_mvs( + cpi, x, xd, block, this_mode, mode_mv[this_mode], frame_mv, + seg_mvs[block], bsi->ref_mv, x->nmvjointcost, x->mvcost); for (ref = 0; ref < 1 + has_second_rf; ++ref) { - bsi->rdstat[i][mode_idx].mvs[ref].as_int = + bsi->rdstat[block][mode_idx].mvs[ref].as_int = mode_mv[this_mode][ref].as_int; if (num_4x4_blocks_wide > 1) - bsi->rdstat[i + 1][mode_idx].mvs[ref].as_int = + bsi->rdstat[block + 1][mode_idx].mvs[ref].as_int = mode_mv[this_mode][ref].as_int; if (num_4x4_blocks_high > 1) - bsi->rdstat[i + 2][mode_idx].mvs[ref].as_int = + bsi->rdstat[block + 2][mode_idx].mvs[ref].as_int = mode_mv[this_mode][ref].as_int; } @@ -2218,7 +2327,7 @@ static int64_t rd_pick_best_sub8x8_mode( for (ref = 0; ref < 1 + has_second_rf; ++ref) { subpelmv |= mv_has_subpel(&mode_mv[this_mode][ref].as_mv); have_ref &= mode_mv[this_mode][ref].as_int == - ref_bsi->rdstat[i][mode_idx].mvs[ref].as_int; + ref_bsi->rdstat[block][mode_idx].mvs[ref].as_int; } if (filter_idx > 1 && !subpelmv && !have_ref) { @@ -2226,53 +2335,54 @@ static int64_t rd_pick_best_sub8x8_mode( have_ref = 1; for (ref = 0; ref < 1 + has_second_rf; ++ref) have_ref &= mode_mv[this_mode][ref].as_int == - ref_bsi->rdstat[i][mode_idx].mvs[ref].as_int; + ref_bsi->rdstat[block][mode_idx].mvs[ref].as_int; } if (!subpelmv && have_ref && - ref_bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) { - memcpy(&bsi->rdstat[i][mode_idx], &ref_bsi->rdstat[i][mode_idx], - sizeof(SEG_RDSTAT)); + ref_bsi->rdstat[block][mode_idx].brdcost < INT64_MAX) { + bsi->rdstat[block][mode_idx] = ref_bsi->rdstat[block][mode_idx]; if (num_4x4_blocks_wide > 1) - bsi->rdstat[i + 1][mode_idx].eobs = - ref_bsi->rdstat[i + 1][mode_idx].eobs; + bsi->rdstat[block + 1][mode_idx].eobs = + ref_bsi->rdstat[block + 1][mode_idx].eobs; if (num_4x4_blocks_high > 1) - bsi->rdstat[i + 2][mode_idx].eobs = - ref_bsi->rdstat[i + 2][mode_idx].eobs; + bsi->rdstat[block + 2][mode_idx].eobs = + ref_bsi->rdstat[block + 2][mode_idx].eobs; - if (bsi->rdstat[i][mode_idx].brdcost < best_rd) { + if (bsi->rdstat[block][mode_idx].brdcost < best_rd) { mode_selected = this_mode; - best_rd = bsi->rdstat[i][mode_idx].brdcost; + best_rd = bsi->rdstat[block][mode_idx].brdcost; } continue; } } - bsi->rdstat[i][mode_idx].brdcost = encode_inter_mb_segment( - cpi, x, bsi->segment_rd - this_segment_rd, i, - &bsi->rdstat[i][mode_idx].byrate, &bsi->rdstat[i][mode_idx].bdist, - &bsi->rdstat[i][mode_idx].bsse, bsi->rdstat[i][mode_idx].ta, - bsi->rdstat[i][mode_idx].tl, mi_row, mi_col); - if (bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) { - bsi->rdstat[i][mode_idx].brdcost += - RDCOST(x->rdmult, x->rddiv, bsi->rdstat[i][mode_idx].brate, 0); - bsi->rdstat[i][mode_idx].brate += bsi->rdstat[i][mode_idx].byrate; - bsi->rdstat[i][mode_idx].eobs = p->eobs[i]; + bsi->rdstat[block][mode_idx].brdcost = encode_inter_mb_segment( + cpi, x, bsi->segment_rd - this_segment_rd, block, + &bsi->rdstat[block][mode_idx].byrate, + &bsi->rdstat[block][mode_idx].bdist, + &bsi->rdstat[block][mode_idx].bsse, bsi->rdstat[block][mode_idx].ta, + bsi->rdstat[block][mode_idx].tl, mi_row, mi_col); + if (bsi->rdstat[block][mode_idx].brdcost < INT64_MAX) { + bsi->rdstat[block][mode_idx].brdcost += RDCOST( + x->rdmult, x->rddiv, bsi->rdstat[block][mode_idx].brate, 0); + bsi->rdstat[block][mode_idx].brate += + bsi->rdstat[block][mode_idx].byrate; + bsi->rdstat[block][mode_idx].eobs = p->eobs[block]; if (num_4x4_blocks_wide > 1) - bsi->rdstat[i + 1][mode_idx].eobs = p->eobs[i + 1]; + bsi->rdstat[block + 1][mode_idx].eobs = p->eobs[block + 1]; if (num_4x4_blocks_high > 1) - bsi->rdstat[i + 2][mode_idx].eobs = p->eobs[i + 2]; + bsi->rdstat[block + 2][mode_idx].eobs = p->eobs[block + 2]; } - if (bsi->rdstat[i][mode_idx].brdcost < best_rd) { + if (bsi->rdstat[block][mode_idx].brdcost < best_rd) { mode_selected = this_mode; - best_rd = bsi->rdstat[i][mode_idx].brdcost; + best_rd = bsi->rdstat[block][mode_idx].brdcost; } } /*for each 4x4 mode*/ if (best_rd == INT64_MAX) { int iy, midx; - for (iy = i + 1; iy < 4; ++iy) + for (iy = block + 1; iy < 4; ++iy) for (midx = 0; midx < INTER_MODES; ++midx) bsi->rdstat[iy][midx].brdcost = INT64_MAX; bsi->segment_rd = INT64_MAX; @@ -2280,22 +2390,22 @@ static int64_t rd_pick_best_sub8x8_mode( } mode_idx = INTER_OFFSET(mode_selected); - memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above)); - memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left)); + memcpy(t_above, bsi->rdstat[block][mode_idx].ta, sizeof(t_above)); + memcpy(t_left, bsi->rdstat[block][mode_idx].tl, sizeof(t_left)); - set_and_cost_bmi_mvs(cpi, x, xd, i, mode_selected, mode_mv[mode_selected], - frame_mv, seg_mvs[i], bsi->ref_mv, x->nmvjointcost, - x->mvcost); + set_and_cost_bmi_mvs(cpi, x, xd, block, mode_selected, + mode_mv[mode_selected], frame_mv, seg_mvs[block], + bsi->ref_mv, x->nmvjointcost, x->mvcost); - br += bsi->rdstat[i][mode_idx].brate; - bd += bsi->rdstat[i][mode_idx].bdist; - block_sse += bsi->rdstat[i][mode_idx].bsse; - segmentyrate += bsi->rdstat[i][mode_idx].byrate; - this_segment_rd += bsi->rdstat[i][mode_idx].brdcost; + br += bsi->rdstat[block][mode_idx].brate; + bd += bsi->rdstat[block][mode_idx].bdist; + block_sse += bsi->rdstat[block][mode_idx].bsse; + segmentyrate += bsi->rdstat[block][mode_idx].byrate; + this_segment_rd += bsi->rdstat[block][mode_idx].brdcost; if (this_segment_rd > bsi->segment_rd) { int iy, midx; - for (iy = i + 1; iy < 4; ++iy) + for (iy = block + 1; iy < 4; ++iy) for (midx = 0; midx < INTER_MODES; ++midx) bsi->rdstat[iy][midx].brdcost = INT64_MAX; bsi->segment_rd = INT64_MAX; @@ -2313,7 +2423,7 @@ static int64_t rd_pick_best_sub8x8_mode( // update the coding decisions for (k = 0; k < 4; ++k) bsi->modes[k] = mi->bmi[k].as_mode; - if (bsi->segment_rd > best_rd) return INT64_MAX; + if (bsi->segment_rd > best_rd_so_far) return INT64_MAX; /* set it to the best */ for (i = 0; i < 4; i++) { mode_idx = INTER_OFFSET(bsi->modes[i]); @@ -2558,9 +2668,9 @@ static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, tmp_mv->as_int = INVALID_MV; if (scaled_ref_frame) { - int i; - for (i = 0; i < MAX_MB_PLANE; ++i) - xd->plane[i].pre[0] = backup_yv12[i]; + int j; + for (j = 0; j < MAX_MB_PLANE; ++j) + xd->plane[j].pre[0] = backup_yv12[j]; } return; } @@ -2725,8 +2835,9 @@ static int64_t handle_inter_mode( struct buf_2d *recon, int *disable_skip, int_mv (*mode_mv)[MAX_REF_FRAMES], int mi_row, int mi_col, int_mv single_newmv[MAX_REF_FRAMES], INTERP_FILTER (*single_filter)[MAX_REF_FRAMES], - int (*single_skippable)[MAX_REF_FRAMES], int64_t *psse, - const int64_t ref_best_rd, int64_t *mask_filter, int64_t filter_cache[]) { + int (*single_skippable)[MAX_REF_FRAMES], int *single_mode_rate, + int64_t *psse, const int64_t ref_best_rd, int64_t *mask_filter, + int64_t filter_cache[], int best_mode_index) { VP9_COMMON *cm = &cpi->common; MACROBLOCKD *xd = &x->e_mbd; MODE_INFO *mi = xd->mi[0]; @@ -2744,9 +2855,8 @@ static int64_t handle_inter_mode( #else DECLARE_ALIGNED(16, uint8_t, tmp_buf[MAX_MB_PLANE * 64 * 64]); #endif // CONFIG_VP9_HIGHBITDEPTH - int pred_exists = 0; int intpel_mv; - int64_t rd, tmp_rd, best_rd = INT64_MAX; + int64_t rd, tmp_rd = INT64_MAX, best_rd = INT64_MAX; int best_needs_copy = 0; uint8_t *orig_dst[MAX_MB_PLANE]; int orig_dst_stride[MAX_MB_PLANE]; @@ -2755,13 +2865,12 @@ static int64_t handle_inter_mode( uint8_t skip_txfm[MAX_MB_PLANE << 2] = { 0 }; int64_t bsse[MAX_MB_PLANE << 2] = { 0 }; - int bsl = mi_width_log2_lookup[bsize]; - int pred_filter_search = - cpi->sf.cb_pred_filter_search - ? (((mi_row + mi_col) >> bsl) + - get_chessboard_index(cm->current_video_frame)) & - 0x1 - : 0; + const int bsl = mi_width_log2_lookup[bsize]; + const int blk_parity = (((mi_row + mi_col) >> bsl) + + get_chessboard_index(cm->current_video_frame)) & + 0x1; + const int pred_filter_search = + (cpi->sf.cb_pred_filter_search >= 2) && blk_parity; int skip_txfm_sb = 0; int64_t skip_sse_sb = INT64_MAX; @@ -2800,13 +2909,23 @@ static int64_t handle_inter_mode( if (this_mode == NEWMV) { int rate_mv; if (is_comp_pred) { + // Decide number of joint motion search iterations + const int num_joint_search_iters = get_joint_search_iters( + cpi->sf.comp_inter_joint_search_iter_level, bsize); + // Initialize mv using single prediction mode result. frame_mv[refs[0]].as_int = single_newmv[refs[0]].as_int; frame_mv[refs[1]].as_int = single_newmv[refs[1]].as_int; - if (cpi->sf.comp_inter_joint_search_thresh <= bsize) { + if (num_joint_search_iters) { +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, joint_motion_search_time); +#endif joint_motion_search(cpi, x, bsize, frame_mv, mi_row, mi_col, - single_newmv, &rate_mv); + single_newmv, &rate_mv, num_joint_search_iters); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, joint_motion_search_time); +#endif } else { rate_mv = vp9_mv_bit_cost(&frame_mv[refs[0]].as_mv, &x->mbmi_ext->ref_mvs[refs[0]][0].as_mv, @@ -2818,7 +2937,13 @@ static int64_t handle_inter_mode( *rate2 += rate_mv; } else { int_mv tmp_mv; +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, single_motion_search_time); +#endif single_motion_search(cpi, x, bsize, mi_row, mi_col, &tmp_mv, &rate_mv); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, single_motion_search_time); +#endif if (tmp_mv.as_int == INVALID_MV) return INT64_MAX; frame_mv[refs[0]].as_int = xd->mi[0]->bmi[0].as_mv[0].as_int = @@ -2872,23 +2997,45 @@ static int64_t handle_inter_mode( *rate2 += cost_mv_ref(cpi, this_mode, mbmi_ext->mode_context[refs[0]]); } + if (!is_comp_pred && cpi->sf.prune_single_mode_based_on_mv_diff_mode_rate) { + single_mode_rate[INTER_OFFSET(this_mode)] = *rate2; + // Prune NEARMV and ZEROMV modes based on motion vector difference and mode + // rate. + if (skip_single_mode_based_on_mode_rate(mode_mv, single_mode_rate, + this_mode, refs[0], *rate2, + best_mode_index)) { + // Check when the single inter mode is pruned, NEARESTMV or NEWMV modes + // are not early terminated. This ensures all single modes are not getting + // skipped when the speed feature is enabled. + assert(single_mode_rate[INTER_OFFSET(NEARESTMV)] != INT_MAX || + single_mode_rate[INTER_OFFSET(NEWMV)] != INT_MAX); + return INT64_MAX; + } + } if (RDCOST(x->rdmult, x->rddiv, *rate2, 0) > ref_best_rd && mi->mode != NEARESTMV) return INT64_MAX; - pred_exists = 0; // Are all MVs integer pel for Y and UV intpel_mv = !mv_has_subpel(&mi->mv[0].as_mv); if (is_comp_pred) intpel_mv &= !mv_has_subpel(&mi->mv[1].as_mv); +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, interp_filter_time); +#endif // Search for best switchable filter by checking the variance of // pred error irrespective of whether the filter will be used for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) filter_cache[i] = INT64_MAX; if (cm->interp_filter != BILINEAR) { + // Use cb pattern for filter eval when filter is not switchable + const int enable_interp_search = + (cpi->sf.cb_pred_filter_search && cm->interp_filter != SWITCHABLE) + ? blk_parity + : 1; if (x->source_variance < cpi->sf.disable_filter_search_var_thresh) { best_filter = EIGHTTAP; - } else if (best_filter == SWITCHABLE) { + } else if (best_filter == SWITCHABLE && enable_interp_search) { int newbest; int tmp_rate_sum = 0; int64_t tmp_dist_sum = 0; @@ -2898,6 +3045,9 @@ static int64_t handle_inter_mode( int64_t rs_rd; int tmp_skip_sb = 0; int64_t tmp_skip_sse = INT64_MAX; + const int enable_earlyterm = + cpi->sf.early_term_interp_search_plane_rd && cm->interp_filter != i; + int64_t filt_best_rd; mi->interp_filter = i; rs = vp9_get_switchable_rate(cpi, xd); @@ -2931,9 +3081,16 @@ static int64_t handle_inter_mode( xd->plane[j].dst.stride = 64; } } - vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize); - model_rd_for_sb(cpi, bsize, x, xd, &rate_sum, &dist_sum, &tmp_skip_sb, - &tmp_skip_sse); + + filt_best_rd = + cm->interp_filter == SWITCHABLE ? (best_rd - rs_rd) : best_rd; + if (build_inter_pred_model_rd_earlyterm( + cpi, mi_row, mi_col, bsize, x, xd, &rate_sum, &dist_sum, + &tmp_skip_sb, &tmp_skip_sse, enable_earlyterm, + filt_best_rd)) { + filter_cache[i] = INT64_MAX; + continue; + } rd = RDCOST(x->rdmult, x->rddiv, rate_sum, dist_sum); filter_cache[i] = rd; @@ -2966,7 +3123,6 @@ static int64_t handle_inter_mode( if ((cm->interp_filter == SWITCHABLE && newbest) || (cm->interp_filter != SWITCHABLE && cm->interp_filter == mi->interp_filter)) { - pred_exists = 1; tmp_rd = best_rd; skip_txfm_sb = tmp_skip_sb; @@ -2978,12 +3134,15 @@ static int64_t handle_inter_mode( restore_dst_buf(xd, orig_dst, orig_dst_stride); } } +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, interp_filter_time); +#endif // Set the appropriate filter mi->interp_filter = cm->interp_filter != SWITCHABLE ? cm->interp_filter : best_filter; rs = cm->interp_filter == SWITCHABLE ? vp9_get_switchable_rate(cpi, xd) : 0; - if (pred_exists) { + if (tmp_rd != INT64_MAX) { if (best_needs_copy) { // again temporarily set the buffers to local memory to prevent a memcpy for (i = 0; i < MAX_MB_PLANE; i++) { @@ -2998,9 +3157,9 @@ static int64_t handle_inter_mode( // Handles the special case when a filter that is not in the // switchable list (ex. bilinear) is indicated at the frame level, or // skip condition holds. - vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize); - model_rd_for_sb(cpi, bsize, x, xd, &tmp_rate, &tmp_dist, &skip_txfm_sb, - &skip_sse_sb); + build_inter_pred_model_rd_earlyterm( + cpi, mi_row, mi_col, bsize, x, xd, &tmp_rate, &tmp_dist, &skip_txfm_sb, + &skip_sse_sb, 0 /*do_earlyterm*/, INT64_MAX); rd = RDCOST(x->rdmult, x->rddiv, rs + tmp_rate, tmp_dist); memcpy(skip_txfm, x->skip_txfm, sizeof(skip_txfm)); memcpy(bsse, x->bsse, sizeof(bsse)); @@ -3093,7 +3252,7 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost, x->skip_encode = 0; ctx->skip = 0; xd->mi[0]->ref_frame[0] = INTRA_FRAME; - xd->mi[0]->ref_frame[1] = NONE; + xd->mi[0]->ref_frame[1] = NO_REF_FRAME; // Initialize interp_filter here so we do not have to check for inter block // modes in get_pred_context_switchable_interp() xd->mi[0]->interp_filter = SWITCHABLE_FILTERS; @@ -3242,6 +3401,7 @@ int vp9_active_h_edge(VP9_COMP *cpi, int mi_row, int mi_step) { // For two pass account for any formatting bars detected. if (cpi->oxcf.pass == 2) { TWO_PASS *twopass = &cpi->twopass; + vpx_clear_system_state(); // The inactive region is specified in MBs not mi units. // The image edge is in the following MB row. @@ -3269,6 +3429,7 @@ int vp9_active_v_edge(VP9_COMP *cpi, int mi_col, int mi_step) { // For two pass account for any formatting bars detected. if (cpi->oxcf.pass == 2) { TWO_PASS *twopass = &cpi->twopass; + vpx_clear_system_state(); // The inactive region is specified in MBs not mi units. // The image edge is in the following MB row. @@ -3294,6 +3455,14 @@ int vp9_active_edge_sb(VP9_COMP *cpi, int mi_row, int mi_col) { } #if !CONFIG_REALTIME_ONLY +static void init_frame_mv(int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]) { + for (int mode = 0; mode < MB_MODE_COUNT; ++mode) { + for (int ref_frame = 0; ref_frame < MAX_REF_FRAMES; ++ref_frame) { + frame_mv[mode][ref_frame].as_int = INVALID_MV; + } + } +} + void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, MACROBLOCK *x, int mi_row, int mi_col, RD_COST *rd_cost, BLOCK_SIZE bsize, @@ -3311,10 +3480,11 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, unsigned char segment_id = mi->segment_id; int comp_pred, i, k; int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; - struct buf_2d yv12_mb[4][MAX_MB_PLANE]; + struct buf_2d yv12_mb[4][MAX_MB_PLANE] = { 0 }; int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } }; INTERP_FILTER single_inter_filter[MB_MODE_COUNT][MAX_REF_FRAMES]; int single_skippable[MB_MODE_COUNT][MAX_REF_FRAMES]; + int single_mode_rate[MAX_REF_FRAMES][INTER_MODES]; int64_t best_rd = best_rd_so_far; int64_t best_pred_diff[REFERENCE_MODES]; int64_t best_pred_rd[REFERENCE_MODES]; @@ -3388,6 +3558,8 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, rd_cost->rate = INT_MAX; + init_frame_mv(frame_mv); + for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { x->pred_mv_sad[ref_frame] = INT_MAX; if ((cpi->ref_frame_flags & ref_frame_to_flag(ref_frame)) && @@ -3459,18 +3631,19 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, if (sf->adaptive_mode_search) { if (cm->show_frame && !cpi->rc.is_src_frame_alt_ref && - cpi->rc.frames_since_golden >= 3) + cpi->rc.frames_since_golden >= 3 && + x->pred_mv_sad[LAST_FRAME] < INT_MAX) if (x->pred_mv_sad[GOLDEN_FRAME] > (x->pred_mv_sad[LAST_FRAME] << 1)) mode_skip_mask[GOLDEN_FRAME] |= INTER_ALL; } - if (bsize > sf->max_intra_bsize) { + if (bsize > sf->max_intra_bsize && cpi->ref_frame_flags != 0) { ref_frame_skip_mask[0] |= (1 << INTRA_FRAME); ref_frame_skip_mask[1] |= (1 << INTRA_FRAME); } mode_skip_mask[INTRA_FRAME] |= - ~(sf->intra_y_mode_mask[max_txsize_lookup[bsize]]); + (uint16_t)~(sf->intra_y_mode_mask[max_txsize_lookup[bsize]]); for (i = 0; i <= LAST_NEW_MV_INDEX; ++i) mode_threshold[i] = 0; @@ -3513,6 +3686,10 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, second_ref_frame = vp9_mode_order[mode_index].ref_frame[1]; vp9_zero(x->sum_y_eobs); + comp_pred = second_ref_frame > INTRA_FRAME; + if (!comp_pred && ref_frame != INTRA_FRAME && + sf->prune_single_mode_based_on_mv_diff_mode_rate) + single_mode_rate[ref_frame][INTER_OFFSET(this_mode)] = INT_MAX; if (is_rect_partition) { if (ctx->skip_ref_frame_mask & (1 << ref_frame)) continue; @@ -3531,7 +3708,7 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, ref_frame_skip_mask[0] |= GOLDEN_FRAME_MODE_MASK; break; case ALTREF_FRAME: ref_frame_skip_mask[0] |= ALT_REF_MODE_MASK; break; - case NONE: + case NO_REF_FRAME: case MAX_REF_FRAMES: assert(0 && "Invalid Reference frame"); break; } } @@ -3564,7 +3741,7 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, MODE_INFO *ref_mi; int const_motion = 1; int skip_ref_frame = !cb_partition_search_ctrl; - MV_REFERENCE_FRAME rf = NONE; + MV_REFERENCE_FRAME rf = NO_REF_FRAME; int_mv ref_mv; ref_mv.as_int = INVALID_MV; @@ -3581,7 +3758,7 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, if ((mi_col - 1) >= tile_info->mi_col_start) { if (ref_mv.as_int == INVALID_MV) ref_mv = xd->mi[-1]->mv[0]; - if (rf == NONE) rf = xd->mi[-1]->ref_frame[0]; + if (rf == NO_REF_FRAME) rf = xd->mi[-1]->ref_frame[0]; for (i = 0; i < mi_height; ++i) { ref_mi = xd->mi[i * xd->mi_stride - 1]; const_motion &= (ref_mv.as_int == ref_mi->mv[0].as_int) && @@ -3598,7 +3775,6 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, if (this_mode == NEARMV || this_mode == ZEROMV) continue; } - comp_pred = second_ref_frame > INTRA_FRAME; if (comp_pred) { if (!cpi->allow_comp_inter_inter) continue; @@ -3678,19 +3854,30 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, if (ref_frame == INTRA_FRAME) { TX_SIZE uv_tx; struct macroblockd_plane *const pd = &xd->plane[1]; +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, intra_mode_search_time); +#endif memset(x->skip_txfm, 0, sizeof(x->skip_txfm)); super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable, NULL, bsize, best_rd, recon); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, intra_mode_search_time); +#endif if (rate_y == INT_MAX) continue; uv_tx = uv_txsize_lookup[bsize][mi->tx_size][pd->subsampling_x] [pd->subsampling_y]; +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, intra_mode_search_time); +#endif if (rate_uv_intra[uv_tx] == INT_MAX) { choose_intra_uv_mode(cpi, x, ctx, bsize, uv_tx, &rate_uv_intra[uv_tx], &rate_uv_tokenonly[uv_tx], &dist_uv[uv_tx], &skip_uv[uv_tx], &mode_uv[uv_tx]); } - +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, intra_mode_search_time); +#endif rate_uv = rate_uv_tokenonly[uv_tx]; distortion_uv = dist_uv[uv_tx]; skippable = skippable && skip_uv[uv_tx]; @@ -3701,11 +3888,18 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, rate2 += intra_cost_penalty; distortion2 = distortion_y + distortion_uv; } else { +#if CONFIG_COLLECT_COMPONENT_TIMING + start_timing(cpi, handle_inter_mode_time); +#endif this_rd = handle_inter_mode( cpi, x, bsize, &rate2, &distortion2, &skippable, &rate_y, &rate_uv, recon, &disable_skip, frame_mv, mi_row, mi_col, single_newmv, - single_inter_filter, single_skippable, &total_sse, best_rd, - &mask_filter, filter_cache); + single_inter_filter, single_skippable, + &single_mode_rate[ref_frame][0], &total_sse, best_rd, &mask_filter, + filter_cache, best_mode_index); +#if CONFIG_COLLECT_COMPONENT_TIMING + end_timing(cpi, handle_inter_mode_time); +#endif if (this_rd == INT64_MAX) continue; compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred); @@ -3941,13 +4135,9 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, TileDataEnc *tile_data, } if (best_mode_index < 0 || best_rd >= best_rd_so_far) { -// If adaptive interp filter is enabled, then the current leaf node of 8x8 -// data is needed for sub8x8. Hence preserve the context. -#if CONFIG_CONSISTENT_RECODE + // If adaptive interp filter is enabled, then the current leaf node of 8x8 + // data is needed for sub8x8. Hence preserve the context. if (bsize == BLOCK_8X8) ctx->mic = *xd->mi[0]; -#else - if (cpi->row_mt && bsize == BLOCK_8X8) ctx->mic = *xd->mi[0]; -#endif rd_cost->rate = INT_MAX; rd_cost->rdcost = INT64_MAX; return; @@ -4062,7 +4252,7 @@ void vp9_rd_pick_inter_mode_sb_seg_skip(VP9_COMP *cpi, TileDataEnc *tile_data, mi->mode = ZEROMV; mi->uv_mode = DC_PRED; mi->ref_frame[0] = LAST_FRAME; - mi->ref_frame[1] = NONE; + mi->ref_frame[1] = NO_REF_FRAME; mi->mv[0].as_int = 0; x->skip = 1; @@ -4138,7 +4328,7 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, TileDataEnc *tile_data, unsigned char segment_id = mi->segment_id; int comp_pred, i; int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; - struct buf_2d yv12_mb[4][MAX_MB_PLANE]; + struct buf_2d yv12_mb[4][MAX_MB_PLANE] = { 0 }; int64_t best_rd = best_rd_so_far; int64_t best_yrd = best_rd_so_far; // FIXME(rbultje) more precise int64_t best_pred_diff[REFERENCE_MODES]; @@ -4207,7 +4397,6 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, TileDataEnc *tile_data, int rate2 = 0, rate_y = 0, rate_uv = 0; int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; int skippable = 0; - int i; int this_skip2 = 0; int64_t total_sse = INT_MAX; int early_term = 0; @@ -4245,7 +4434,7 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, TileDataEnc *tile_data, case ALTREF_FRAME: ref_frame_skip_mask[0] |= (1 << GOLDEN_FRAME) | (1 << LAST_FRAME); break; - case NONE: + case NO_REF_FRAME: case MAX_REF_FRAMES: assert(0 && "Invalid Reference frame"); break; } } @@ -4368,7 +4557,6 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, TileDataEnc *tile_data, : NULL; if (scaled_ref_frame[ref]) { - int i; // Swap out the reference frame for a version that's been scaled to // match the resolution of the current frame, allowing the existing // motion search code to be used without additional modifications. @@ -4505,14 +4693,13 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, TileDataEnc *tile_data, if (tmp_best_rdu > 0) { // If even the 'Y' rd value of split is higher than best so far - // then dont bother looking at UV + // then don't bother looking at UV vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, BLOCK_8X8); memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm)); if (!super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable, &uv_sse, BLOCK_8X8, tmp_best_rdu)) { for (ref = 0; ref < 2; ++ref) { if (scaled_ref_frame[ref]) { - int i; for (i = 0; i < MAX_MB_PLANE; ++i) xd->plane[i].pre[ref] = backup_yv12[ref][i]; } @@ -4529,7 +4716,6 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, TileDataEnc *tile_data, for (ref = 0; ref < 2; ++ref) { if (scaled_ref_frame[ref]) { // Restore the prediction frame pointers to their unscaled versions. - int i; for (i = 0; i < MAX_MB_PLANE; ++i) xd->plane[i].pre[ref] = backup_yv12[ref][i]; } @@ -4728,14 +4914,13 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, TileDataEnc *tile_data, if (!is_inter_block(&best_mbmode)) { for (i = 0; i < 4; i++) xd->mi[0]->bmi[i].as_mode = best_bmodes[i].as_mode; } else { - for (i = 0; i < 4; ++i) - memcpy(&xd->mi[0]->bmi[i], &best_bmodes[i], sizeof(b_mode_info)); + for (i = 0; i < 4; ++i) xd->mi[0]->bmi[i] = best_bmodes[i]; mi->mv[0].as_int = xd->mi[0]->bmi[3].as_mv[0].as_int; mi->mv[1].as_int = xd->mi[0]->bmi[3].as_mv[1].as_int; } // If the second reference does not exist, set the corresponding mv to zero. - if (mi->ref_frame[1] == NONE) { + if (mi->ref_frame[1] == NO_REF_FRAME) { mi->mv[1].as_int = 0; for (i = 0; i < 4; ++i) { mi->bmi[i].as_mv[1].as_int = 0; diff --git a/libs/libvpx/vp9/encoder/vp9_resize.c b/libs/libvpx/vp9/encoder/vp9_resize.c index 7486dee25b..352d8f1273 100644 --- a/libs/libvpx/vp9/encoder/vp9_resize.c +++ b/libs/libvpx/vp9/encoder/vp9_resize.c @@ -360,6 +360,12 @@ static int get_down2_steps(int in_length, int out_length) { while ((proj_in_length = get_down2_length(in_length, 1)) >= out_length) { ++steps; in_length = proj_in_length; + if (in_length == 1) { + // Special case: we break because any further calls to get_down2_length() + // with be with length == 1, which return 1, resulting in an infinite + // loop. + break; + } } return steps; } @@ -744,83 +750,3 @@ Error: free(arrbuf2); } #endif // CONFIG_VP9_HIGHBITDEPTH - -void vp9_resize_frame420(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, uint8_t *oy, - int oy_stride, uint8_t *ou, uint8_t *ov, - int ouv_stride, int oheight, int owidth) { - vp9_resize_plane(y, height, width, y_stride, oy, oheight, owidth, oy_stride); - vp9_resize_plane(u, height / 2, width / 2, uv_stride, ou, oheight / 2, - owidth / 2, ouv_stride); - vp9_resize_plane(v, height / 2, width / 2, uv_stride, ov, oheight / 2, - owidth / 2, ouv_stride); -} - -void vp9_resize_frame422(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, uint8_t *oy, - int oy_stride, uint8_t *ou, uint8_t *ov, - int ouv_stride, int oheight, int owidth) { - vp9_resize_plane(y, height, width, y_stride, oy, oheight, owidth, oy_stride); - vp9_resize_plane(u, height, width / 2, uv_stride, ou, oheight, owidth / 2, - ouv_stride); - vp9_resize_plane(v, height, width / 2, uv_stride, ov, oheight, owidth / 2, - ouv_stride); -} - -void vp9_resize_frame444(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, uint8_t *oy, - int oy_stride, uint8_t *ou, uint8_t *ov, - int ouv_stride, int oheight, int owidth) { - vp9_resize_plane(y, height, width, y_stride, oy, oheight, owidth, oy_stride); - vp9_resize_plane(u, height, width, uv_stride, ou, oheight, owidth, - ouv_stride); - vp9_resize_plane(v, height, width, uv_stride, ov, oheight, owidth, - ouv_stride); -} - -#if CONFIG_VP9_HIGHBITDEPTH -void vp9_highbd_resize_frame420(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, - uint8_t *oy, int oy_stride, uint8_t *ou, - uint8_t *ov, int ouv_stride, int oheight, - int owidth, int bd) { - vp9_highbd_resize_plane(y, height, width, y_stride, oy, oheight, owidth, - oy_stride, bd); - vp9_highbd_resize_plane(u, height / 2, width / 2, uv_stride, ou, oheight / 2, - owidth / 2, ouv_stride, bd); - vp9_highbd_resize_plane(v, height / 2, width / 2, uv_stride, ov, oheight / 2, - owidth / 2, ouv_stride, bd); -} - -void vp9_highbd_resize_frame422(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, - uint8_t *oy, int oy_stride, uint8_t *ou, - uint8_t *ov, int ouv_stride, int oheight, - int owidth, int bd) { - vp9_highbd_resize_plane(y, height, width, y_stride, oy, oheight, owidth, - oy_stride, bd); - vp9_highbd_resize_plane(u, height, width / 2, uv_stride, ou, oheight, - owidth / 2, ouv_stride, bd); - vp9_highbd_resize_plane(v, height, width / 2, uv_stride, ov, oheight, - owidth / 2, ouv_stride, bd); -} - -void vp9_highbd_resize_frame444(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, - uint8_t *oy, int oy_stride, uint8_t *ou, - uint8_t *ov, int ouv_stride, int oheight, - int owidth, int bd) { - vp9_highbd_resize_plane(y, height, width, y_stride, oy, oheight, owidth, - oy_stride, bd); - vp9_highbd_resize_plane(u, height, width, uv_stride, ou, oheight, owidth, - ouv_stride, bd); - vp9_highbd_resize_plane(v, height, width, uv_stride, ov, oheight, owidth, - ouv_stride, bd); -} -#endif // CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vp9/encoder/vp9_resize.h b/libs/libvpx/vp9/encoder/vp9_resize.h index 5d4ce97eba..7a984dbc94 100644 --- a/libs/libvpx/vp9/encoder/vp9_resize.h +++ b/libs/libvpx/vp9/encoder/vp9_resize.h @@ -21,44 +21,11 @@ extern "C" { void vp9_resize_plane(const uint8_t *const input, int height, int width, int in_stride, uint8_t *output, int height2, int width2, int out_stride); -void vp9_resize_frame420(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, uint8_t *oy, - int oy_stride, uint8_t *ou, uint8_t *ov, - int ouv_stride, int oheight, int owidth); -void vp9_resize_frame422(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, uint8_t *oy, - int oy_stride, uint8_t *ou, uint8_t *ov, - int ouv_stride, int oheight, int owidth); -void vp9_resize_frame444(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, uint8_t *oy, - int oy_stride, uint8_t *ou, uint8_t *ov, - int ouv_stride, int oheight, int owidth); #if CONFIG_VP9_HIGHBITDEPTH void vp9_highbd_resize_plane(const uint8_t *const input, int height, int width, int in_stride, uint8_t *output, int height2, int width2, int out_stride, int bd); -void vp9_highbd_resize_frame420(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, - uint8_t *oy, int oy_stride, uint8_t *ou, - uint8_t *ov, int ouv_stride, int oheight, - int owidth, int bd); -void vp9_highbd_resize_frame422(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, - uint8_t *oy, int oy_stride, uint8_t *ou, - uint8_t *ov, int ouv_stride, int oheight, - int owidth, int bd); -void vp9_highbd_resize_frame444(const uint8_t *const y, int y_stride, - const uint8_t *const u, const uint8_t *const v, - int uv_stride, int height, int width, - uint8_t *oy, int oy_stride, uint8_t *ou, - uint8_t *ov, int ouv_stride, int oheight, - int owidth, int bd); #endif // CONFIG_VP9_HIGHBITDEPTH #ifdef __cplusplus diff --git a/libs/libvpx/vp9/encoder/vp9_segmentation.c b/libs/libvpx/vp9/encoder/vp9_segmentation.c index a163297e6e..d75488a8e6 100644 --- a/libs/libvpx/vp9/encoder/vp9_segmentation.c +++ b/libs/libvpx/vp9/encoder/vp9_segmentation.c @@ -39,7 +39,7 @@ void vp9_set_segment_data(struct segmentation *seg, signed char *feature_data, } void vp9_disable_segfeature(struct segmentation *seg, int segment_id, SEG_LVL_FEATURES feature_id) { - seg->feature_mask[segment_id] &= ~(1 << feature_id); + seg->feature_mask[segment_id] &= ~(1u << feature_id); } void vp9_clear_segdata(struct segmentation *seg, int segment_id, diff --git a/libs/libvpx/vp9/encoder/vp9_speed_features.c b/libs/libvpx/vp9/encoder/vp9_speed_features.c index 0431d8a452..2d50323348 100644 --- a/libs/libvpx/vp9/encoder/vp9_speed_features.c +++ b/libs/libvpx/vp9/encoder/vp9_speed_features.c @@ -16,8 +16,11 @@ #include "vpx_dsp/vpx_dsp_common.h" // Mesh search patters for various speed settings -static MESH_PATTERN best_quality_mesh_pattern[MAX_MESH_STEP] = { - { 64, 4 }, { 28, 2 }, { 15, 1 }, { 7, 1 } +// Define 2 mesh density levels for FC_GRAPHICS_ANIMATION content type and non +// FC_GRAPHICS_ANIMATION content type. +static MESH_PATTERN best_quality_mesh_pattern[2][MAX_MESH_STEP] = { + { { 64, 4 }, { 28, 2 }, { 15, 1 }, { 7, 1 } }, + { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } }, }; #if !CONFIG_REALTIME_ONLY @@ -39,7 +42,7 @@ static int frame_is_boosted(const VP9_COMP *cpi) { // Sets a partition size down to which the auto partition code will always // search (can go lower), based on the image dimensions. The logic here // is that the extent to which ringing artefacts are offensive, depends -// partly on the screen area that over which they propogate. Propogation is +// partly on the screen area that over which they propagate. Propagation is // limited by transform block size but the screen area take up by a given block // size will be larger for a small image format stretched to full screen. static BLOCK_SIZE set_partition_min_limit(VP9_COMMON *const cm) { @@ -67,6 +70,7 @@ static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi, const int is_720p_or_larger = min_frame_size >= 720; const int is_1080p_or_larger = min_frame_size >= 1080; const int is_2160p_or_larger = min_frame_size >= 2160; + const int boosted = frame_is_boosted(cpi); // speed 0 features sf->partition_search_breakout_thr.dist = (1 << 20); @@ -78,9 +82,13 @@ static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi, // Currently, the machine-learning based partition search early termination // is only used while VPXMIN(cm->width, cm->height) >= 480 and speed = 0. sf->rd_ml_partition.search_early_termination = 1; + sf->recode_tolerance_high = 45; } else { sf->use_square_only_thresh_high = BLOCK_32X32; } + if (is_720p_or_larger) { + sf->alt_ref_search_fp = 1; + } if (!is_1080p_or_larger) { sf->rd_ml_partition.search_breakout = 1; @@ -95,6 +103,13 @@ static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi, } } + if (!is_720p_or_larger) { + if (is_480p_or_larger) + sf->prune_single_mode_based_on_mv_diff_mode_rate = boosted ? 0 : 1; + else + sf->prune_single_mode_based_on_mv_diff_mode_rate = 1; + } + if (speed >= 1) { sf->rd_ml_partition.search_early_termination = 0; sf->rd_ml_partition.search_breakout = 1; @@ -152,7 +167,7 @@ static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi, sf->intra_y_mode_mask[TX_32X32] = INTRA_DC; sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC; sf->alt_ref_search_fp = 1; - sf->cb_pred_filter_search = 1; + sf->cb_pred_filter_search = 2; sf->adaptive_interp_filter_search = 1; sf->disable_split_mask = DISABLE_ALL_SPLIT; } @@ -209,15 +224,32 @@ static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi, const int boosted = frame_is_boosted(cpi); int i; - sf->tx_size_search_breakout = 1; + sf->adaptive_interp_filter_search = 1; + sf->adaptive_pred_interp_filter = 1; sf->adaptive_rd_thresh = 1; sf->adaptive_rd_thresh_row_mt = 0; sf->allow_skip_recode = 1; sf->less_rectangular_check = 1; - sf->use_square_partition_only = !boosted; + sf->mv.auto_mv_step_size = 1; + sf->mv.use_downsampled_sad = 1; sf->prune_ref_frame_for_rect_partitions = 1; - sf->rd_ml_partition.var_pruning = 1; + sf->temporal_filter_search_method = NSTEP; + sf->tx_size_search_breakout = 1; + sf->use_square_partition_only = !boosted; + sf->early_term_interp_search_plane_rd = 1; + sf->cb_pred_filter_search = 1; + sf->trellis_opt_tx_rd.method = sf->optimize_coefficients + ? ENABLE_TRELLIS_OPT_TX_RD_RESIDUAL_MSE + : DISABLE_TRELLIS_OPT; + sf->trellis_opt_tx_rd.thresh = boosted ? 4.0 : 3.0; + sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; + sf->comp_inter_joint_search_iter_level = 1; + + // Reference masking is not supported in dynamic scaling mode. + sf->reference_masking = oxcf->resize_mode != RESIZE_DYNAMIC; + + sf->rd_ml_partition.var_pruning = 1; sf->rd_ml_partition.prune_rect_thresh[0] = -1; sf->rd_ml_partition.prune_rect_thresh[1] = 350; sf->rd_ml_partition.prune_rect_thresh[2] = 325; @@ -238,7 +270,6 @@ static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi, } if (speed >= 1) { - sf->temporal_filter_search_method = NSTEP; sf->rd_ml_partition.var_pruning = !boosted; sf->rd_ml_partition.prune_rect_thresh[1] = 225; sf->rd_ml_partition.prune_rect_thresh[2] = 225; @@ -258,19 +289,18 @@ static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi, sf->allow_txfm_domain_distortion = 1; sf->tx_domain_thresh = tx_dom_thresholds[(speed < 6) ? speed : 5]; - sf->allow_quant_coeff_opt = sf->optimize_coefficients; - sf->quant_opt_thresh = qopt_thresholds[(speed < 6) ? speed : 5]; + sf->trellis_opt_tx_rd.method = sf->optimize_coefficients + ? ENABLE_TRELLIS_OPT_TX_RD_SRC_VAR + : DISABLE_TRELLIS_OPT; + sf->trellis_opt_tx_rd.thresh = qopt_thresholds[(speed < 6) ? speed : 5]; sf->less_rectangular_check = 1; sf->use_rd_breakout = 1; sf->adaptive_motion_search = 1; - sf->mv.auto_mv_step_size = 1; sf->adaptive_rd_thresh = 2; sf->mv.subpel_search_level = 1; if (cpi->oxcf.content != VP9E_CONTENT_FILM) sf->mode_skip_start = 10; - sf->adaptive_pred_interp_filter = 1; sf->allow_acl = 0; - sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; if (cpi->oxcf.content != VP9E_CONTENT_FILM) { sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V; @@ -296,18 +326,14 @@ static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi, sf->tx_size_search_method = frame_is_boosted(cpi) ? USE_FULL_RD : USE_LARGESTALL; - // Reference masking is not supported in dynamic scaling mode. - sf->reference_masking = oxcf->resize_mode != RESIZE_DYNAMIC ? 1 : 0; - sf->mode_search_skip_flags = (cm->frame_type == KEY_FRAME) ? 0 : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER | FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR; sf->disable_filter_search_var_thresh = 100; - sf->comp_inter_joint_search_thresh = BLOCK_SIZES; + sf->comp_inter_joint_search_iter_level = 2; sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; - sf->recode_tolerance_low = 15; sf->recode_tolerance_high = 45; sf->enhanced_full_pixel_motion_search = 0; sf->prune_ref_frame_for_rect_partitions = 0; @@ -337,14 +363,13 @@ static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi, sf->adaptive_pred_interp_filter = 0; sf->adaptive_mode_search = 1; sf->cb_partition_search = !boosted; - sf->cb_pred_filter_search = 1; + sf->cb_pred_filter_search = 2; sf->alt_ref_search_fp = 1; sf->recode_loop = ALLOW_RECODE_KFMAXBW; sf->adaptive_rd_thresh = 3; sf->mode_skip_start = 6; sf->intra_y_mode_mask[TX_32X32] = INTRA_DC; sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC; - sf->adaptive_interp_filter_search = 1; if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) { for (i = 0; i < MAX_MESH_STEP; ++i) { @@ -373,7 +398,6 @@ static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi, } if (speed >= 5) { - int i; sf->optimize_coefficients = 0; sf->mv.search_method = HEX; sf->disable_filter_search_var_thresh = 500; @@ -461,8 +485,8 @@ static void set_rt_speed_feature_framesize_independent( if (speed >= 1) { sf->allow_txfm_domain_distortion = 1; sf->tx_domain_thresh = 0.0; - sf->allow_quant_coeff_opt = 0; - sf->quant_opt_thresh = 0.0; + sf->trellis_opt_tx_rd.method = DISABLE_TRELLIS_OPT; + sf->trellis_opt_tx_rd.thresh = 0.0; sf->use_square_partition_only = !frame_is_intra_only(cm); sf->less_rectangular_check = 1; sf->tx_size_search_method = @@ -507,7 +531,7 @@ static void set_rt_speed_feature_framesize_independent( } sf->disable_filter_search_var_thresh = 50; - sf->comp_inter_joint_search_thresh = BLOCK_SIZES; + sf->comp_inter_joint_search_iter_level = 2; sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; sf->lf_motion_threshold = LOW_MOTION_THRESHOLD; sf->adjust_partitioning_from_last_frame = 1; @@ -631,7 +655,7 @@ static void set_rt_speed_feature_framesize_independent( sf->use_altref_onepass = 1; sf->use_compound_nonrd_pickmode = 1; } - if (cm->width * cm->height > 1280 * 720) sf->cb_pred_filter_search = 1; + if (cm->width * cm->height > 1280 * 720) sf->cb_pred_filter_search = 2; if (!cpi->external_resize) sf->use_source_sad = 1; } @@ -652,9 +676,12 @@ static void set_rt_speed_feature_framesize_independent( if (cpi->content_state_sb_fd == NULL && (!cpi->use_svc || svc->spatial_layer_id == svc->number_spatial_layers - 1)) { - CHECK_MEM_ERROR(cm, cpi->content_state_sb_fd, + int init_mi_rows, init_mi_cols, init_mi_stride; + vp9_set_mi_size(&init_mi_rows, &init_mi_cols, &init_mi_stride, + cpi->initial_width, cpi->initial_height); + CHECK_MEM_ERROR(&cm->error, cpi->content_state_sb_fd, (uint8_t *)vpx_calloc( - (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), + (init_mi_stride >> 3) * ((init_mi_rows >> 3) + 1), sizeof(uint8_t))); } } @@ -721,7 +748,7 @@ static void set_rt_speed_feature_framesize_independent( if (cpi->use_svc && svc->use_gf_temporal_ref_current_layer && svc->temporal_layer_id > 0) cpi->ref_frame_flags &= (~VP9_GOLD_FLAG); - if (cm->width * cm->height > 640 * 480) sf->cb_pred_filter_search = 1; + if (cm->width * cm->height > 640 * 480) sf->cb_pred_filter_search = 2; } if (speed >= 8) { @@ -735,7 +762,8 @@ static void set_rt_speed_feature_framesize_independent( if (cpi->row_mt && cpi->oxcf.max_threads > 1) sf->adaptive_rd_thresh_row_mt = 1; // Enable ML based partition for low res. - if (!frame_is_intra_only(cm) && cm->width * cm->height <= 352 * 288) { + if (!frame_is_intra_only(cm) && !cpi->use_svc && + cm->width * cm->height <= 352 * 288) { sf->nonrd_use_ml_partition = 1; } #if CONFIG_VP9_HIGHBITDEPTH @@ -765,7 +793,7 @@ static void set_rt_speed_feature_framesize_independent( } sf->limit_newmv_early_exit = 0; sf->use_simple_block_yrd = 1; - if (cm->width * cm->height > 352 * 288) sf->cb_pred_filter_search = 1; + if (cm->width * cm->height > 352 * 288) sf->cb_pred_filter_search = 2; } if (speed >= 9) { @@ -775,7 +803,7 @@ static void set_rt_speed_feature_framesize_independent( for (i = 0; i < BLOCK_SIZES; ++i) sf->intra_y_mode_bsize_mask[i] = INTRA_DC; } - sf->cb_pred_filter_search = 1; + sf->cb_pred_filter_search = 2; sf->mv.enable_adaptive_subpel_force_stop = 1; sf->mv.adapt_subpel_force_stop.mv_thresh = 1; sf->mv.adapt_subpel_force_stop.force_stop_below = QUARTER_PEL; @@ -808,13 +836,13 @@ static void set_rt_speed_feature_framesize_independent( } if (cpi->count_arf_frame_usage == NULL) { CHECK_MEM_ERROR( - cm, cpi->count_arf_frame_usage, + &cm->error, cpi->count_arf_frame_usage, (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(*cpi->count_arf_frame_usage))); } if (cpi->count_lastgolden_frame_usage == NULL) CHECK_MEM_ERROR( - cm, cpi->count_lastgolden_frame_usage, + &cm->error, cpi->count_lastgolden_frame_usage, (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(*cpi->count_lastgolden_frame_usage))); } @@ -835,6 +863,15 @@ static void set_rt_speed_feature_framesize_independent( // off for now. if (speed <= 3 && cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) cpi->oxcf.aq_mode = 0; + // For all speeds for rt mode: if the deadline mode changed (was good/best + // quality on previous frame and now is realtime) set nonrd_keyframe to 1 to + // avoid entering rd pickmode. This causes issues, such as: b/310663186. + if (cpi->oxcf.mode != cpi->deadline_mode_previous_frame) + sf->nonrd_keyframe = 1; + + // TODO(marpan): Force this feature off always, for the issue: 366146260 + // Remove this disabling when underlying issue is resolved. + sf->svc_use_lowres_part = 0; } void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi, int speed) { @@ -904,14 +941,17 @@ void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) { sf->coeff_prob_appx_step = 1; sf->mv.auto_mv_step_size = 0; sf->mv.fullpel_search_step_param = 6; - sf->comp_inter_joint_search_thresh = BLOCK_4X4; + sf->mv.use_downsampled_sad = 0; + sf->comp_inter_joint_search_iter_level = 0; sf->tx_size_search_method = USE_FULL_RD; sf->use_lp32x32fdct = 0; sf->adaptive_motion_search = 0; sf->enhanced_full_pixel_motion_search = 1; sf->adaptive_pred_interp_filter = 0; sf->adaptive_mode_search = 0; + sf->prune_single_mode_based_on_mv_diff_mode_rate = 0; sf->cb_pred_filter_search = 0; + sf->early_term_interp_search_plane_rd = 0; sf->cb_partition_search = 0; sf->motion_field_mode_search = 0; sf->alt_ref_search_fp = 0; @@ -936,8 +976,9 @@ void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) { sf->adaptive_interp_filter_search = 0; sf->allow_txfm_domain_distortion = 0; sf->tx_domain_thresh = 99.0; - sf->allow_quant_coeff_opt = sf->optimize_coefficients; - sf->quant_opt_thresh = 99.0; + sf->trellis_opt_tx_rd.method = + sf->optimize_coefficients ? ENABLE_TRELLIS_OPT : DISABLE_TRELLIS_OPT; + sf->trellis_opt_tx_rd.thresh = 99.0; sf->allow_acl = 1; sf->enable_tpl_model = oxcf->enable_tpl_model; sf->prune_ref_frame_for_rect_partitions = 0; @@ -964,7 +1005,6 @@ void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) { // This setting only takes effect when partition_search_type is set // to FIXED_PARTITION. sf->always_this_block_size = BLOCK_16X16; - sf->search_type_check_frequency = 50; sf->encode_breakout_thresh = 0; // Recode loop tolerance %. sf->recode_tolerance_low = 12; @@ -991,10 +1031,14 @@ void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) { sf->exhaustive_searches_thresh = (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 20) : INT_MAX; - if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) { + { + const int mesh_density_level = + (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? 0 : 1; for (i = 0; i < MAX_MESH_STEP; ++i) { - sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range; - sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval; + sf->mesh_patterns[i].range = + best_quality_mesh_pattern[mesh_density_level][i].range; + sf->mesh_patterns[i].interval = + best_quality_mesh_pattern[mesh_density_level][i].interval; } } diff --git a/libs/libvpx/vp9/encoder/vp9_speed_features.h b/libs/libvpx/vp9/encoder/vp9_speed_features.h index c2ae970b77..92a7df767f 100644 --- a/libs/libvpx/vp9/encoder/vp9_speed_features.h +++ b/libs/libvpx/vp9/encoder/vp9_speed_features.h @@ -148,9 +148,6 @@ typedef enum { // a 64X64 SB. VAR_BASED_PARTITION, - // Use non-fixed partitions based on source variance. - SOURCE_VAR_BASED_PARTITION, - // Make partition decisions with machine learning models. ML_BASED_PARTITION } PARTITION_SEARCH_TYPE; @@ -210,6 +207,10 @@ typedef struct MV_SPEED_FEATURES { // This variable sets the step_param used in full pel motion search. int fullpel_search_step_param; + + // Whether to downsample the rows in sad calculation during motion search. + // This is only active when there are at least 8 rows. + int use_downsampled_sad; } MV_SPEED_FEATURES; typedef struct PARTITION_SEARCH_BREAKOUT_THR { @@ -246,6 +247,24 @@ typedef enum { USE_8_TAPS_SHARP, } SUBPEL_SEARCH_TYPE; +typedef enum { + // Disable trellis coefficient optimization + DISABLE_TRELLIS_OPT, + // Enable trellis coefficient optimization + ENABLE_TRELLIS_OPT, + // Enable trellis coefficient optimization based on source variance of the + // prediction block during transform RD + ENABLE_TRELLIS_OPT_TX_RD_SRC_VAR, + // Enable trellis coefficient optimization based on residual mse of the + // transform block during transform RD + ENABLE_TRELLIS_OPT_TX_RD_RESIDUAL_MSE, +} ENABLE_TRELLIS_OPT_METHOD; + +typedef struct TRELLIS_OPT_CONTROL { + ENABLE_TRELLIS_OPT_METHOD method; + double thresh; +} TRELLIS_OPT_CONTROL; + typedef struct SPEED_FEATURES { MV_SPEED_FEATURES mv; @@ -264,18 +283,27 @@ typedef struct SPEED_FEATURES { // adds overhead. int static_segmentation; - // If 1 we iterate finding a best reference for 2 ref frames together - via - // a log search that iterates 4 times (check around mv for last for best - // error of combined predictor then check around mv for alt). If 0 we - // we just use the best motion vector found for each frame by itself. - BLOCK_SIZE comp_inter_joint_search_thresh; + // The best compound predictor is found using an iterative log search process + // that searches for best ref0 mv using error of combined predictor and then + // searches for best ref1 mv. This sf determines the number of iterations of + // this process based on block size. The sf becomes more aggressive from level + // 0 to 2. The following table indicates the number of iterations w.r.t bsize: + // ----------------------------------------------- + // |sf (level)|bsize < 8X8| [8X8, 16X16] | > 16X16 | + // | 0 | 4 | 4 | 4 | + // | 1 | 0 | 2 | 4 | + // | 2 | 0 | 0 | 0 | + // ----------------------------------------------- + // Here, 0 iterations indicate using the best single motion vector selected + // for each ref frame without any iterative refinement. + int comp_inter_joint_search_iter_level; // This variable is used to cap the maximum number of times we skip testing a // mode to be evaluated. A high value means we will be faster. // Turned off when (row_mt_bit_exact == 1 && adaptive_rd_thresh_row_mt == 0). int adaptive_rd_thresh; - // Flag to use adaptive_rd_thresh when row-mt it enabled, only for non-rd + // Flag to use adaptive_rd_thresh when row-mt is enabled, only for non-rd // pickmode. int adaptive_rd_thresh_row_mt; @@ -292,8 +320,8 @@ typedef struct SPEED_FEATURES { int coeff_prob_appx_step; // Enable uniform quantizer followed by trellis coefficient optimization - int allow_quant_coeff_opt; - double quant_opt_thresh; + // during transform RD + TRELLIS_OPT_CONTROL trellis_opt_tx_rd; // Enable asymptotic closed-loop encoding decision for key frame and // alternate reference frames. @@ -333,7 +361,7 @@ typedef struct SPEED_FEATURES { PARTITION_SEARCH_TYPE partition_search_type; - // Used if partition_search_type = FIXED_SIZE_PARTITION + // Used if partition_search_type = FIXED_PARTITION BLOCK_SIZE always_this_block_size; // Skip rectangular partition test when partition type none gives better @@ -399,9 +427,21 @@ typedef struct SPEED_FEATURES { // Adaptive prediction mode search int adaptive_mode_search; - // Chessboard pattern prediction filter type search + // Prune NEAREST and ZEROMV single reference modes based on motion vector + // difference and mode rate + int prune_single_mode_based_on_mv_diff_mode_rate; + + // Chessboard pattern prediction for interp filter. Aggressiveness increases + // with levels. + // 0: disable + // 1: cb pattern in eval when filter is not switchable + // 2: cb pattern prediction for filter search int cb_pred_filter_search; + // This variable enables an early termination of interpolation filter eval + // based on the current rd cost after processing each plane + int early_term_interp_search_plane_rd; + int cb_partition_search; int motion_field_mode_search; @@ -474,10 +514,6 @@ typedef struct SPEED_FEATURES { // TODO(aconverse): Fold this into one of the other many mode skips BLOCK_SIZE max_intra_bsize; - // The frequency that we check if SOURCE_VAR_BASED_PARTITION or - // FIXED_PARTITION search type should be used. - int search_type_check_frequency; - // When partition is pre-set, the inter prediction result from pick_inter_mode // can be reused in final block encoding process. It is enabled only for real- // time mode speed 6. @@ -600,7 +636,7 @@ typedef struct SPEED_FEATURES { // Use machine learning based partition search. int nonrd_use_ml_partition; - // Multiplier for base thresold for variance partitioning. + // Multiplier for base threshold for variance partitioning. int variance_part_thresh_mult; // Force subpel motion filter to always use SMOOTH_FILTER. diff --git a/libs/libvpx/vp9/encoder/vp9_subexp.c b/libs/libvpx/vp9/encoder/vp9_subexp.c index e7db5f4ce4..2e1810b0ee 100644 --- a/libs/libvpx/vp9/encoder/vp9_subexp.c +++ b/libs/libvpx/vp9/encoder/vp9_subexp.c @@ -64,18 +64,16 @@ static int remap_prob(int v, int m) { 228, 229, 17, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 18, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 19, }; - - assert(m > 0); - v--; m--; + assert(m >= 0); if ((m << 1) <= MAX_PROB) i = recenter_nonneg(v, m) - 1; else i = recenter_nonneg(MAX_PROB - 1 - v, MAX_PROB - 1 - m) - 1; assert(i >= 0 && (size_t)i < sizeof(map_table)); - if (i >= 0 && (size_t)i < sizeof(map_table)) i = map_table[i]; + i = map_table[i]; return i; } diff --git a/libs/libvpx/vp9/encoder/vp9_svc_layercontext.c b/libs/libvpx/vp9/encoder/vp9_svc_layercontext.c index a57a70ab16..3aa7243594 100644 --- a/libs/libvpx/vp9/encoder/vp9_svc_layercontext.c +++ b/libs/libvpx/vp9/encoder/vp9_svc_layercontext.c @@ -107,7 +107,6 @@ void vp9_init_layer_context(VP9_COMP *const cpi) { int layer = LAYER_IDS_TO_IDX(sl, tl, oxcf->ts_number_layers); LAYER_CONTEXT *const lc = &svc->layer_context[layer]; RATE_CONTROL *const lrc = &lc->rc; - int i; lc->current_video_frame_in_layer = 0; lc->layer_size = 0; lc->frames_from_key_frame = 0; @@ -164,17 +163,17 @@ void vp9_init_layer_context(VP9_COMP *const cpi) { lc->actual_num_seg1_blocks = 0; lc->actual_num_seg2_blocks = 0; lc->counter_encode_maxq_scene_change = 0; - CHECK_MEM_ERROR(cm, lc->map, + CHECK_MEM_ERROR(&cm->error, lc->map, vpx_malloc(mi_rows * mi_cols * sizeof(*lc->map))); memset(lc->map, 0, mi_rows * mi_cols); last_coded_q_map_size = mi_rows * mi_cols * sizeof(*lc->last_coded_q_map); - CHECK_MEM_ERROR(cm, lc->last_coded_q_map, + CHECK_MEM_ERROR(&cm->error, lc->last_coded_q_map, vpx_malloc(last_coded_q_map_size)); assert(MAXQ <= 255); memset(lc->last_coded_q_map, MAXQ, last_coded_q_map_size); consec_zero_mv_size = mi_rows * mi_cols * sizeof(*lc->consec_zero_mv); - CHECK_MEM_ERROR(cm, lc->consec_zero_mv, + CHECK_MEM_ERROR(&cm->error, lc->consec_zero_mv, vpx_malloc(consec_zero_mv_size)); memset(lc->consec_zero_mv, 0, consec_zero_mv_size); } @@ -220,39 +219,38 @@ void vp9_update_layer_context_change_config(VP9_COMP *const cpi, RATE_CONTROL *const lrc = &lc->rc; lc->spatial_layer_target_bandwidth = spatial_layer_target; - bitrate_alloc = (float)lc->target_bandwidth / target_bandwidth; + if (target_bandwidth != 0) { + bitrate_alloc = (float)lc->target_bandwidth / target_bandwidth; + } lrc->starting_buffer_level = - (int64_t)(rc->starting_buffer_level * bitrate_alloc); + (int64_t)(rc->starting_buffer_level * bitrate_alloc + 0.5); lrc->optimal_buffer_level = - (int64_t)(rc->optimal_buffer_level * bitrate_alloc); + (int64_t)(rc->optimal_buffer_level * bitrate_alloc + 0.5); lrc->maximum_buffer_size = - (int64_t)(rc->maximum_buffer_size * bitrate_alloc); + (int64_t)(rc->maximum_buffer_size * bitrate_alloc + 0.5); lrc->bits_off_target = VPXMIN(lrc->bits_off_target, lrc->maximum_buffer_size); lrc->buffer_level = VPXMIN(lrc->buffer_level, lrc->maximum_buffer_size); lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[tl]; - lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); + lrc->avg_frame_bandwidth = saturate_cast_double_to_int( + round(lc->target_bandwidth / lc->framerate)); lrc->max_frame_bandwidth = rc->max_frame_bandwidth; lrc->worst_quality = rc->worst_quality; lrc->best_quality = rc->best_quality; } } } else { - int layer_end; - - if (svc->number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) { - layer_end = svc->number_temporal_layers; - } else { - layer_end = svc->number_spatial_layers; - } - + assert(svc->number_temporal_layers == 1); + int layer_end = svc->number_spatial_layers; for (layer = 0; layer < layer_end; ++layer) { LAYER_CONTEXT *const lc = &svc->layer_context[layer]; RATE_CONTROL *const lrc = &lc->rc; lc->target_bandwidth = oxcf->layer_target_bitrate[layer]; - bitrate_alloc = (float)lc->target_bandwidth / target_bandwidth; + if (target_bandwidth != 0) { + bitrate_alloc = (float)lc->target_bandwidth / target_bandwidth; + } // Update buffer-related quantities. lrc->starting_buffer_level = (int64_t)(rc->starting_buffer_level * bitrate_alloc); @@ -263,13 +261,9 @@ void vp9_update_layer_context_change_config(VP9_COMP *const cpi, lrc->bits_off_target = VPXMIN(lrc->bits_off_target, lrc->maximum_buffer_size); lrc->buffer_level = VPXMIN(lrc->buffer_level, lrc->maximum_buffer_size); - // Update framerate-related quantities. - if (svc->number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) { - lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[layer]; - } else { - lc->framerate = cpi->framerate; - } - lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); + lc->framerate = cpi->framerate; + lrc->avg_frame_bandwidth = saturate_cast_double_to_int( + round(lc->target_bandwidth / lc->framerate)); lrc->max_frame_bandwidth = rc->max_frame_bandwidth; // Update qp-related quantities. lrc->worst_quality = rc->worst_quality; @@ -290,7 +284,7 @@ void vp9_update_layer_context_change_config(VP9_COMP *const cpi, } static LAYER_CONTEXT *get_layer_context(VP9_COMP *const cpi) { - if (is_one_pass_cbr_svc(cpi)) + if (is_one_pass_svc(cpi)) return &cpi->svc.layer_context[cpi->svc.spatial_layer_id * cpi->svc.number_temporal_layers + cpi->svc.temporal_layer_id]; @@ -311,7 +305,8 @@ void vp9_update_temporal_layer_framerate(VP9_COMP *const cpi) { const int tl = svc->temporal_layer_id; lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[tl]; - lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); + lrc->avg_frame_bandwidth = + saturate_cast_double_to_int(round(lc->target_bandwidth / lc->framerate)); lrc->max_frame_bandwidth = cpi->rc.max_frame_bandwidth; // Update the average layer frame size (non-cumulative per-frame-bw). if (tl == 0) { @@ -333,12 +328,14 @@ void vp9_update_spatial_layer_framerate(VP9_COMP *const cpi, double framerate) { RATE_CONTROL *const lrc = &lc->rc; lc->framerate = framerate; - lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); - lrc->min_frame_bandwidth = - (int)(lrc->avg_frame_bandwidth * oxcf->two_pass_vbrmin_section / 100); - lrc->max_frame_bandwidth = (int)(((int64_t)lrc->avg_frame_bandwidth * - oxcf->two_pass_vbrmax_section) / - 100); + lrc->avg_frame_bandwidth = + saturate_cast_double_to_int(round(lc->target_bandwidth / lc->framerate)); + const int64_t vbr_min_bits = + (int64_t)lrc->avg_frame_bandwidth * oxcf->two_pass_vbrmin_section / 100; + lrc->min_frame_bandwidth = (int)VPXMIN(vbr_min_bits, INT_MAX); + const int64_t vbr_max_bits = + (int64_t)lrc->avg_frame_bandwidth * oxcf->two_pass_vbrmax_section / 100; + lrc->max_frame_bandwidth = (int)VPXMIN(vbr_max_bits, INT_MAX); vp9_rc_set_gf_interval_range(cpi, lrc); } @@ -349,13 +346,16 @@ void vp9_restore_layer_context(VP9_COMP *const cpi) { const int old_ext_use_post_encode_drop = cpi->rc.ext_use_post_encode_drop; cpi->rc = lc->rc; - cpi->twopass = lc->twopass; cpi->oxcf.target_bandwidth = lc->target_bandwidth; cpi->alt_ref_source = lc->alt_ref_source; // Check if it is one_pass_cbr_svc mode and lc->speed > 0 (real-time mode // does not use speed = 0). - if (is_one_pass_cbr_svc(cpi) && lc->speed > 0) { + if (is_one_pass_svc(cpi) && lc->speed > 0) { +#if CONFIG_REALTIME_ONLY + cpi->oxcf.speed = VPXMAX(lc->speed, 5); +#else cpi->oxcf.speed = lc->speed; +#endif } cpi->loopfilter_ctrl = lc->loopfilter_ctrl; // Reset the frames_since_key and frames_to_key counters to their values @@ -386,9 +386,10 @@ void vp9_save_layer_context(VP9_COMP *const cpi) { LAYER_CONTEXT *const lc = get_layer_context(cpi); lc->rc = cpi->rc; - lc->twopass = cpi->twopass; lc->target_bandwidth = (int)oxcf->target_bandwidth; lc->alt_ref_source = cpi->alt_ref_source; + lc->frame_qp = cpi->common.base_qindex; + lc->MBs = cpi->common.MBs; // For spatial-svc, allow cyclic-refresh to be applied on the spatial layers, // for the base temporal layer. @@ -408,27 +409,12 @@ void vp9_save_layer_context(VP9_COMP *const cpi) { lc->actual_num_seg1_blocks = cr->actual_num_seg1_blocks; lc->actual_num_seg2_blocks = cr->actual_num_seg2_blocks; lc->counter_encode_maxq_scene_change = cr->counter_encode_maxq_scene_change; + lc->qindex_delta[0] = cr->qindex_delta[0]; + lc->qindex_delta[1] = cr->qindex_delta[1]; + lc->qindex_delta[2] = cr->qindex_delta[2]; } } -#if !CONFIG_REALTIME_ONLY -void vp9_init_second_pass_spatial_svc(VP9_COMP *cpi) { - SVC *const svc = &cpi->svc; - int i; - - for (i = 0; i < svc->number_spatial_layers; ++i) { - TWO_PASS *const twopass = &svc->layer_context[i].twopass; - - svc->spatial_layer_id = i; - vp9_init_second_pass(cpi); - - twopass->total_stats.spatial_layer_id = i; - twopass->total_left_stats.spatial_layer_id = i; - } - svc->spatial_layer_id = 0; -} -#endif // !CONFIG_REALTIME_ONLY - void vp9_inc_frame_in_layer(VP9_COMP *const cpi) { LAYER_CONTEXT *const lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id * @@ -444,10 +430,16 @@ void get_layer_resolution(const int width_org, const int height_org, int *height_out) { int w, h; - if (width_out == NULL || height_out == NULL || den == 0) return; + if (width_out == NULL || height_out == NULL) return; - w = width_org * num / den; - h = height_org * num / den; + if (den == 0 || num == 0) { + *width_out = width_org; + *height_out = height_org; + return; + } + + w = (int)((int64_t)width_org * num / den); + h = (int)((int64_t)height_org * num / den); // make height and width even to make chrome player happy w += w % 2; @@ -754,7 +746,7 @@ void vp9_copy_flags_ref_update_idx(VP9_COMP *const cpi) { svc->reference_altref[sl] = (uint8_t)(cpi->ref_frame_flags & VP9_ALT_FLAG); } -int vp9_one_pass_cbr_svc_start_layer(VP9_COMP *const cpi) { +int vp9_one_pass_svc_start_layer(VP9_COMP *const cpi) { int width = 0, height = 0; SVC *const svc = &cpi->svc; LAYER_CONTEXT *lc = NULL; @@ -774,9 +766,6 @@ int vp9_one_pass_cbr_svc_start_layer(VP9_COMP *const cpi) { svc->use_partition_reuse = 1; } svc->force_zero_mode_spatial_ref = 1; - svc->mi_stride[svc->spatial_layer_id] = cpi->common.mi_stride; - svc->mi_rows[svc->spatial_layer_id] = cpi->common.mi_rows; - svc->mi_cols[svc->spatial_layer_id] = cpi->common.mi_cols; // For constrained_from_above drop mode: before encoding superframe (i.e., // at SL0 frame) check all spatial layers (starting from top) for possible @@ -790,9 +779,9 @@ int vp9_one_pass_cbr_svc_start_layer(VP9_COMP *const cpi) { for (sl = svc->number_spatial_layers - 1; sl >= svc->first_spatial_layer_to_encode; sl--) { int layer = sl * svc->number_temporal_layers + svc->temporal_layer_id; - LAYER_CONTEXT *const lc = &svc->layer_context[layer]; - cpi->rc = lc->rc; - cpi->oxcf.target_bandwidth = lc->target_bandwidth; + LAYER_CONTEXT *const sl_lc = &svc->layer_context[layer]; + cpi->rc = sl_lc->rc; + cpi->oxcf.target_bandwidth = sl_lc->target_bandwidth; if (vp9_test_drop(cpi)) { int sl2; // Set flag to force drop in encoding for this mode. @@ -894,6 +883,10 @@ int vp9_one_pass_cbr_svc_start_layer(VP9_COMP *const cpi) { RATE_CONTROL *const lrc = &lc->rc; lrc->worst_quality = vp9_quantizer_to_qindex(lc->max_q); lrc->best_quality = vp9_quantizer_to_qindex(lc->min_q); + if (cpi->fixed_qp_onepass) { + lrc->worst_quality = cpi->rc.worst_quality; + lrc->best_quality = cpi->rc.best_quality; + } } if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC && svc->single_layer_svc == 1 && @@ -914,7 +907,7 @@ int vp9_one_pass_cbr_svc_start_layer(VP9_COMP *const cpi) { svc->downsample_filter_type[svc->spatial_layer_id] = EIGHTTAP_SMOOTH; // For scale factors > 0.75, set the phase to 0 (aligns decimated pixel // to source pixel). - if (scaling_factor_num > (3 * scaling_factor_den) >> 2) + if (scaling_factor_num > ((int64_t)3 * scaling_factor_den) >> 2) svc->downsample_filter_phase[svc->spatial_layer_id] = 0; // The usage of use_base_mv or partition_reuse assumes down-scale of 2x2. @@ -974,6 +967,9 @@ int vp9_one_pass_cbr_svc_start_layer(VP9_COMP *const cpi) { if (vp9_set_size_literal(cpi, width, height) != 0) return VPX_CODEC_INVALID_PARAM; + svc->mi_stride[svc->spatial_layer_id] = cpi->common.mi_stride; + svc->mi_rows[svc->spatial_layer_id] = cpi->common.mi_rows; + svc->mi_cols[svc->spatial_layer_id] = cpi->common.mi_cols; return 0; } @@ -1037,17 +1033,17 @@ void vp9_svc_check_reset_layer_rc_flag(VP9_COMP *const cpi) { int sl, tl; for (sl = 0; sl < svc->number_spatial_layers; ++sl) { // Check for reset based on avg_frame_bandwidth for spatial layer sl. - int layer = LAYER_IDS_TO_IDX(sl, svc->number_temporal_layers - 1, - svc->number_temporal_layers); - LAYER_CONTEXT *lc = &svc->layer_context[layer]; + const int spatial_layer_idx = LAYER_IDS_TO_IDX( + sl, svc->number_temporal_layers - 1, svc->number_temporal_layers); + LAYER_CONTEXT *lc = &svc->layer_context[spatial_layer_idx]; RATE_CONTROL *lrc = &lc->rc; - if (lrc->avg_frame_bandwidth > (3 * lrc->last_avg_frame_bandwidth >> 1) || + if (lrc->avg_frame_bandwidth / 3 > (lrc->last_avg_frame_bandwidth >> 1) || lrc->avg_frame_bandwidth < (lrc->last_avg_frame_bandwidth >> 1)) { // Reset for all temporal layers with spatial layer sl. for (tl = 0; tl < svc->number_temporal_layers; ++tl) { - int layer = LAYER_IDS_TO_IDX(sl, tl, svc->number_temporal_layers); - LAYER_CONTEXT *lc = &svc->layer_context[layer]; - RATE_CONTROL *lrc = &lc->rc; + int temporal_layer_idx = + LAYER_IDS_TO_IDX(sl, tl, svc->number_temporal_layers); + lrc = &svc->layer_context[temporal_layer_idx].rc; lrc->rc_1_frame = 0; lrc->rc_2_frame = 0; lrc->bits_off_target = lrc->optimal_buffer_level; @@ -1133,7 +1129,7 @@ void vp9_svc_constrain_inter_layer_pred(VP9_COMP *const cpi) { void vp9_svc_assert_constraints_pattern(VP9_COMP *const cpi) { SVC *const svc = &cpi->svc; // For fixed/non-flexible mode, the following constraint are expected, - // when inter-layer prediciton is on (default). + // when inter-layer prediction is on (default). if (svc->temporal_layering_mode != VP9E_TEMPORAL_LAYERING_MODE_BYPASS && svc->disable_inter_layer_pred == INTER_LAYER_PRED_ON && svc->framedrop_mode != LAYER_DROP) { @@ -1316,12 +1312,12 @@ void vp9_svc_adjust_avg_frame_qindex(VP9_COMP *const cpi) { VP9_COMMON *const cm = &cpi->common; SVC *const svc = &cpi->svc; RATE_CONTROL *const rc = &cpi->rc; - // On key frames in CBR mode: reset the avg_frame_index for base layer + // On key frames in CBR mode: reset the avg_frame_qindex for base layer // (to level closer to worst_quality) if the overshoot is significant. // Reset it for all temporal layers on base spatial layer. if (cm->frame_type == KEY_FRAME && cpi->oxcf.rc_mode == VPX_CBR && !svc->simulcast_mode && - rc->projected_frame_size > 3 * rc->avg_frame_bandwidth) { + rc->projected_frame_size / 3 > rc->avg_frame_bandwidth) { int tl; rc->avg_frame_qindex[INTER_FRAME] = VPXMAX(rc->avg_frame_qindex[INTER_FRAME], @@ -1334,3 +1330,27 @@ void vp9_svc_adjust_avg_frame_qindex(VP9_COMP *const cpi) { } } } + +// SVC: skip encoding of enhancement layer if the layer target bandwidth = 0. +// No need to set svc.skip_enhancement_layer if whole superframe will be +// dropped. +int vp9_svc_check_skip_enhancement_layer(VP9_COMP *const cpi) { + if (cpi->use_svc && cpi->svc.spatial_layer_id > 0 && + cpi->oxcf.target_bandwidth == 0 && + !(cpi->svc.framedrop_mode != LAYER_DROP && + (cpi->svc.framedrop_mode != CONSTRAINED_FROM_ABOVE_DROP || + cpi->svc + .force_drop_constrained_from_above[cpi->svc.number_spatial_layers - + 1]) && + cpi->svc.drop_spatial_layer[0])) { + cpi->svc.skip_enhancement_layer = 1; + vp9_rc_postencode_update_drop_frame(cpi); + cpi->ext_refresh_frame_flags_pending = 0; + cpi->last_frame_dropped = 1; + cpi->svc.last_layer_dropped[cpi->svc.spatial_layer_id] = 1; + cpi->svc.drop_spatial_layer[cpi->svc.spatial_layer_id] = 1; + vp9_inc_frame_in_layer(cpi); + return 1; + } + return 0; +} diff --git a/libs/libvpx/vp9/encoder/vp9_svc_layercontext.h b/libs/libvpx/vp9/encoder/vp9_svc_layercontext.h index b2d1d1b98f..c8d7f23b68 100644 --- a/libs/libvpx/vp9/encoder/vp9_svc_layercontext.h +++ b/libs/libvpx/vp9/encoder/vp9_svc_layercontext.h @@ -50,8 +50,6 @@ typedef struct { // Scaling factors used for internal resize scaling for single layer SVC. int scaling_factor_num_resize; int scaling_factor_den_resize; - TWO_PASS twopass; - vpx_fixed_buf_t rc_twopass_stats_in; unsigned int current_video_frame_in_layer; int is_key_frame; int frames_from_key_frame; @@ -70,8 +68,11 @@ typedef struct { int actual_num_seg1_blocks; int actual_num_seg2_blocks; int counter_encode_maxq_scene_change; + int qindex_delta[3]; uint8_t speed; int loopfilter_ctrl; + int frame_qp; + int MBs; } LAYER_CONTEXT; typedef struct SVC { @@ -228,9 +229,6 @@ void vp9_restore_layer_context(struct VP9_COMP *const cpi); // Save the layer context after encoding the frame. void vp9_save_layer_context(struct VP9_COMP *const cpi); -// Initialize second pass rc for spatial svc. -void vp9_init_second_pass_spatial_svc(struct VP9_COMP *cpi); - void get_layer_resolution(const int width_org, const int height_org, const int num, const int den, int *width_out, int *height_out); @@ -255,7 +253,7 @@ int vp9_denoise_svc_non_key(struct VP9_COMP *const cpi); void vp9_copy_flags_ref_update_idx(struct VP9_COMP *const cpi); -int vp9_one_pass_cbr_svc_start_layer(struct VP9_COMP *const cpi); +int vp9_one_pass_svc_start_layer(struct VP9_COMP *const cpi); void vp9_free_svc_cyclic_refresh(struct VP9_COMP *const cpi); @@ -278,6 +276,8 @@ void vp9_svc_update_ref_frame(struct VP9_COMP *const cpi); void vp9_svc_adjust_frame_rate(struct VP9_COMP *const cpi); void vp9_svc_adjust_avg_frame_qindex(struct VP9_COMP *const cpi); + +int vp9_svc_check_skip_enhancement_layer(struct VP9_COMP *const cpi); #ifdef __cplusplus } // extern "C" #endif diff --git a/libs/libvpx/vp9/encoder/vp9_temporal_filter.c b/libs/libvpx/vp9/encoder/vp9_temporal_filter.c index 701bb89287..46f36c3eb9 100644 --- a/libs/libvpx/vp9/encoder/vp9_temporal_filter.c +++ b/libs/libvpx/vp9/encoder/vp9_temporal_filter.c @@ -45,13 +45,230 @@ static int64_t highbd_index_mult[14] = { 0U, 0U, 0U, 0U, 991146300U }; #endif // CONFIG_VP9_HIGHBITDEPTH +static const MV kZeroMv = { 0, 0 }; +#define TF_INTERP_EXTEND 6 + +// Prediction function using 12-tap interpolation filter. +void vpx_convolve12_horiz_c(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + (void)y0_q4; + (void)y_step_q4; + int x, y; + src -= MAX_FILTER_TAP / 2 - 1; + + for (y = 0; y < h; ++y) { + int x_q4 = x0_q4; + for (x = 0; x < w; ++x) { + const uint8_t *const src_x = &src[x_q4 >> SUBPEL_BITS]; + const int16_t *const x_filter = filter[x_q4 & SUBPEL_MASK]; + int k, sum = 0; + for (k = 0; k < MAX_FILTER_TAP; ++k) sum += src_x[k] * x_filter[k]; + dst[x] = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS)); + x_q4 += x_step_q4; + } + src += src_stride; + dst += dst_stride; + } +} + +void vpx_convolve12_vert_c(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + (void)x0_q4; + (void)x_step_q4; + int x, y; + src -= src_stride * (MAX_FILTER_TAP / 2 - 1); + + for (x = 0; x < w; ++x) { + int y_q4 = y0_q4; + for (y = 0; y < h; ++y) { + const uint8_t *src_y = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; + const int16_t *const y_filter = filter[y_q4 & SUBPEL_MASK]; + int k, sum = 0; + for (k = 0; k < MAX_FILTER_TAP; ++k) + sum += src_y[k * src_stride] * y_filter[k]; + dst[y * dst_stride] = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS)); + y_q4 += y_step_q4; + } + ++src; + ++dst; + } +} + +// Copied from vpx_convolve8_c(). Possible block sizes are 32x32, 16x16, 8x8. +void vpx_convolve12_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, const InterpKernel12 *filter, + int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + uint8_t temp[BW * (BH + MAX_FILTER_TAP - 1)]; + const int temp_stride = BW; + const int intermediate_height = + (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + MAX_FILTER_TAP; + + vpx_convolve12_horiz_c(src - src_stride * (MAX_FILTER_TAP / 2 - 1), + src_stride, temp, temp_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, intermediate_height); + vpx_convolve12_vert_c(temp + temp_stride * (MAX_FILTER_TAP / 2 - 1), + temp_stride, dst, dst_stride, filter, x0_q4, x_step_q4, + y0_q4, y_step_q4, w, h); +} + +static void vp9_build_inter_predictor_12( + const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, + const MV *src_mv, const struct scale_factors *sf, int w, int h, int ref, + const InterpKernel12 *kernel, enum mv_precision precision, int x, int y) { + (void)ref; + const int is_q4 = precision == MV_PRECISION_Q4; + const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2, + is_q4 ? src_mv->col : src_mv->col * 2 }; + MV32 mv = vp9_scale_mv(&mv_q4, x, y, sf); + const int subpel_x = mv.col & SUBPEL_MASK; + const int subpel_y = mv.row & SUBPEL_MASK; + + src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS); + + if (subpel_x == 0 && subpel_y == 0) { + vpx_convolve_copy(src, src_stride, dst, dst_stride, NULL, subpel_x, + sf->x_step_q4, subpel_y, sf->y_step_q4, w, h); + } else if (subpel_x == 0 && subpel_y != 0) { + vpx_convolve12_vert(src, src_stride, dst, dst_stride, kernel, subpel_x, + sf->x_step_q4, subpel_y, sf->y_step_q4, w, h); + } else if (subpel_x != 0 && subpel_y == 0) { + vpx_convolve12_horiz(src, src_stride, dst, dst_stride, kernel, subpel_x, + sf->x_step_q4, subpel_y, sf->y_step_q4, w, h); + } else { + vpx_convolve12(src, src_stride, dst, dst_stride, kernel, subpel_x, + sf->x_step_q4, subpel_y, sf->y_step_q4, w, h); + } +} + +#if CONFIG_VP9_HIGHBITDEPTH +void vpx_highbd_convolve12_horiz_c(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + (void)y0_q4; + (void)y_step_q4; + int x, y; + src -= MAX_FILTER_TAP / 2 - 1; + + for (y = 0; y < h; ++y) { + int x_q4 = x0_q4; + for (x = 0; x < w; ++x) { + const uint16_t *const src_x = &src[x_q4 >> SUBPEL_BITS]; + const int16_t *const x_filter = filter[x_q4 & SUBPEL_MASK]; + int k, sum = 0; + for (k = 0; k < MAX_FILTER_TAP; ++k) sum += src_x[k] * x_filter[k]; + dst[x] = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd); + x_q4 += x_step_q4; + } + src += src_stride; + dst += dst_stride; + } +} + +void vpx_highbd_convolve12_vert_c(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + (void)x0_q4; + (void)x_step_q4; + int x, y; + src -= src_stride * (MAX_FILTER_TAP / 2 - 1); + + for (x = 0; x < w; ++x) { + int y_q4 = y0_q4; + for (y = 0; y < h; ++y) { + const uint16_t *src_y = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; + const int16_t *const y_filter = filter[y_q4 & SUBPEL_MASK]; + int k, sum = 0; + for (k = 0; k < MAX_FILTER_TAP; ++k) + sum += src_y[k * src_stride] * y_filter[k]; + dst[y * dst_stride] = + clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd); + y_q4 += y_step_q4; + } + ++src; + ++dst; + } +} + +static void highbd_convolve12(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h, int bd) { + uint16_t temp[BW * (BH + MAX_FILTER_TAP - 1)]; + const int temp_stride = BW; + const int intermediate_height = + (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + MAX_FILTER_TAP; + + vpx_highbd_convolve12_horiz_c(src - src_stride * (MAX_FILTER_TAP / 2 - 1), + src_stride, temp, temp_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, + intermediate_height, bd); + vpx_highbd_convolve12_vert_c(temp + temp_stride * (MAX_FILTER_TAP / 2 - 1), + temp_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); +} + +// Copied from vpx_highbd_convolve8_c() +void vpx_highbd_convolve12_c(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h, int bd) { + highbd_convolve12(src, src_stride, dst, dst_stride, filter, x0_q4, x_step_q4, + y0_q4, y_step_q4, w, h, bd); +} + +static void vp9_highbd_build_inter_predictor_12( + const uint16_t *src, int src_stride, uint16_t *dst, int dst_stride, + const MV *src_mv, const struct scale_factors *sf, int w, int h, int ref, + const InterpKernel12 *kernel, enum mv_precision precision, int x, int y, + int bd) { + (void)ref; + const int is_q4 = precision == MV_PRECISION_Q4; + const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2, + is_q4 ? src_mv->col : src_mv->col * 2 }; + MV32 mv = vp9_scale_mv(&mv_q4, x, y, sf); + const int subpel_x = mv.col & SUBPEL_MASK; + const int subpel_y = mv.row & SUBPEL_MASK; + + src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS); + + if (subpel_x == 0 && subpel_y == 0) { + vpx_highbd_convolve_copy(src, src_stride, dst, dst_stride, NULL, subpel_x, + sf->x_step_q4, subpel_y, sf->y_step_q4, w, h, bd); + } else if (subpel_x == 0 && subpel_y != 0) { + vpx_highbd_convolve12_vert(src, src_stride, dst, dst_stride, kernel, + subpel_x, sf->x_step_q4, subpel_y, sf->y_step_q4, + w, h, bd); + } else if (subpel_x != 0 && subpel_y == 0) { + vpx_highbd_convolve12_horiz(src, src_stride, dst, dst_stride, kernel, + subpel_x, sf->x_step_q4, subpel_y, + sf->y_step_q4, w, h, bd); + } else { + vpx_highbd_convolve12(src, src_stride, dst, dst_stride, kernel, subpel_x, + sf->x_step_q4, subpel_y, sf->y_step_q4, w, h, bd); + } +} +#endif // CONFIG_VP9_HIGHBITDEPTH + static void temporal_filter_predictors_mb_c( MACROBLOCKD *xd, uint8_t *y_mb_ptr, uint8_t *u_mb_ptr, uint8_t *v_mb_ptr, int stride, int uv_block_width, int uv_block_height, int mv_row, int mv_col, uint8_t *pred, struct scale_factors *scale, int x, int y, MV *blk_mvs, int use_32x32) { const int which_mv = 0; - const InterpKernel *const kernel = vp9_filter_kernels[EIGHTTAP_SHARP]; + const InterpKernel12 *const kernel = sub_pel_filters_12; int i, j, k = 0, ys = (BH >> 1), xs = (BW >> 1); enum mv_precision mv_precision_uv; @@ -71,18 +288,18 @@ static void temporal_filter_predictors_mb_c( const MV mv = { mv_row, mv_col }; #if CONFIG_VP9_HIGHBITDEPTH if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { - vp9_highbd_build_inter_predictor(CONVERT_TO_SHORTPTR(y_mb_ptr), stride, - CONVERT_TO_SHORTPTR(&pred[0]), BW, &mv, - scale, BW, BH, which_mv, kernel, - MV_PRECISION_Q3, x, y, xd->bd); + vp9_highbd_build_inter_predictor_12(CONVERT_TO_SHORTPTR(y_mb_ptr), stride, + CONVERT_TO_SHORTPTR(&pred[0]), BW, + &mv, scale, BW, BH, which_mv, kernel, + MV_PRECISION_Q3, x, y, xd->bd); - vp9_highbd_build_inter_predictor( + vp9_highbd_build_inter_predictor_12( CONVERT_TO_SHORTPTR(u_mb_ptr), uv_stride, CONVERT_TO_SHORTPTR(&pred[BLK_PELS]), uv_block_width, &mv, scale, uv_block_width, uv_block_height, which_mv, kernel, mv_precision_uv, x, y, xd->bd); - vp9_highbd_build_inter_predictor( + vp9_highbd_build_inter_predictor_12( CONVERT_TO_SHORTPTR(v_mb_ptr), uv_stride, CONVERT_TO_SHORTPTR(&pred[(BLK_PELS << 1)]), uv_block_width, &mv, scale, uv_block_width, uv_block_height, which_mv, kernel, @@ -90,18 +307,18 @@ static void temporal_filter_predictors_mb_c( return; } #endif // CONFIG_VP9_HIGHBITDEPTH - vp9_build_inter_predictor(y_mb_ptr, stride, &pred[0], BW, &mv, scale, BW, - BH, which_mv, kernel, MV_PRECISION_Q3, x, y); + vp9_build_inter_predictor_12(y_mb_ptr, stride, &pred[0], BW, &mv, scale, BW, + BH, which_mv, kernel, MV_PRECISION_Q3, x, y); - vp9_build_inter_predictor(u_mb_ptr, uv_stride, &pred[BLK_PELS], - uv_block_width, &mv, scale, uv_block_width, - uv_block_height, which_mv, kernel, - mv_precision_uv, x, y); + vp9_build_inter_predictor_12(u_mb_ptr, uv_stride, &pred[BLK_PELS], + uv_block_width, &mv, scale, uv_block_width, + uv_block_height, which_mv, kernel, + mv_precision_uv, x, y); - vp9_build_inter_predictor(v_mb_ptr, uv_stride, &pred[(BLK_PELS << 1)], - uv_block_width, &mv, scale, uv_block_width, - uv_block_height, which_mv, kernel, - mv_precision_uv, x, y); + vp9_build_inter_predictor_12(v_mb_ptr, uv_stride, &pred[(BLK_PELS << 1)], + uv_block_width, &mv, scale, uv_block_width, + uv_block_height, which_mv, kernel, + mv_precision_uv, x, y); return; } @@ -116,19 +333,19 @@ static void temporal_filter_predictors_mb_c( #if CONFIG_VP9_HIGHBITDEPTH if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { - vp9_highbd_build_inter_predictor( + vp9_highbd_build_inter_predictor_12( CONVERT_TO_SHORTPTR(y_mb_ptr + y_offset), stride, CONVERT_TO_SHORTPTR(&pred[p_offset]), BW, &mv, scale, xs, ys, which_mv, kernel, MV_PRECISION_Q3, x, y, xd->bd); } else { - vp9_build_inter_predictor(y_mb_ptr + y_offset, stride, &pred[p_offset], - BW, &mv, scale, xs, ys, which_mv, kernel, - MV_PRECISION_Q3, x, y); + vp9_build_inter_predictor_12(y_mb_ptr + y_offset, stride, + &pred[p_offset], BW, &mv, scale, xs, ys, + which_mv, kernel, MV_PRECISION_Q3, x, y); } #else - vp9_build_inter_predictor(y_mb_ptr + y_offset, stride, &pred[p_offset], - BW, &mv, scale, xs, ys, which_mv, kernel, - MV_PRECISION_Q3, x, y); + vp9_build_inter_predictor_12(y_mb_ptr + y_offset, stride, &pred[p_offset], + BW, &mv, scale, xs, ys, which_mv, kernel, + MV_PRECISION_Q3, x, y); #endif // CONFIG_VP9_HIGHBITDEPTH k++; } @@ -147,38 +364,38 @@ static void temporal_filter_predictors_mb_c( #if CONFIG_VP9_HIGHBITDEPTH if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { - vp9_highbd_build_inter_predictor( + vp9_highbd_build_inter_predictor_12( CONVERT_TO_SHORTPTR(u_mb_ptr + uv_offset), uv_stride, CONVERT_TO_SHORTPTR(&pred[BLK_PELS + p_offset]), uv_block_width, &mv, scale, xs, ys, which_mv, kernel, mv_precision_uv, x, y, xd->bd); - vp9_highbd_build_inter_predictor( + vp9_highbd_build_inter_predictor_12( CONVERT_TO_SHORTPTR(v_mb_ptr + uv_offset), uv_stride, CONVERT_TO_SHORTPTR(&pred[(BLK_PELS << 1) + p_offset]), uv_block_width, &mv, scale, xs, ys, which_mv, kernel, mv_precision_uv, x, y, xd->bd); } else { - vp9_build_inter_predictor(u_mb_ptr + uv_offset, uv_stride, - &pred[BLK_PELS + p_offset], uv_block_width, - &mv, scale, xs, ys, which_mv, kernel, - mv_precision_uv, x, y); + vp9_build_inter_predictor_12(u_mb_ptr + uv_offset, uv_stride, + &pred[BLK_PELS + p_offset], uv_block_width, + &mv, scale, xs, ys, which_mv, kernel, + mv_precision_uv, x, y); - vp9_build_inter_predictor(v_mb_ptr + uv_offset, uv_stride, - &pred[(BLK_PELS << 1) + p_offset], - uv_block_width, &mv, scale, xs, ys, which_mv, - kernel, mv_precision_uv, x, y); + vp9_build_inter_predictor_12(v_mb_ptr + uv_offset, uv_stride, + &pred[(BLK_PELS << 1) + p_offset], + uv_block_width, &mv, scale, xs, ys, + which_mv, kernel, mv_precision_uv, x, y); } #else - vp9_build_inter_predictor(u_mb_ptr + uv_offset, uv_stride, - &pred[BLK_PELS + p_offset], uv_block_width, &mv, - scale, xs, ys, which_mv, kernel, - mv_precision_uv, x, y); + vp9_build_inter_predictor_12(u_mb_ptr + uv_offset, uv_stride, + &pred[BLK_PELS + p_offset], uv_block_width, + &mv, scale, xs, ys, which_mv, kernel, + mv_precision_uv, x, y); - vp9_build_inter_predictor(v_mb_ptr + uv_offset, uv_stride, - &pred[(BLK_PELS << 1) + p_offset], - uv_block_width, &mv, scale, xs, ys, which_mv, - kernel, mv_precision_uv, x, y); + vp9_build_inter_predictor_12(v_mb_ptr + uv_offset, uv_stride, + &pred[(BLK_PELS << 1) + p_offset], + uv_block_width, &mv, scale, xs, ys, which_mv, + kernel, mv_precision_uv, x, y); #endif // CONFIG_VP9_HIGHBITDEPTH k++; } @@ -450,8 +667,6 @@ void vp9_highbd_apply_temporal_filter_c( // Apply the filter to luma for (row = 0; row < (int)block_height; row++) { for (col = 0; col < (int)block_width; col++) { - const int uv_row = row >> ss_y; - const int uv_col = col >> ss_x; const int filter_weight = get_filter_weight( row, col, block_height, block_width, blk_fw, use_32x32); @@ -476,6 +691,8 @@ void vp9_highbd_apply_temporal_filter_c( // Sum the corresponding uv pixels to the current y modifier // Note we are rounding down instead of rounding to the nearest pixel. + uv_row = row >> ss_y; + uv_col = col >> ss_x; y_mod += u_diff_sse[uv_row * uv_diff_stride + uv_col]; y_mod += v_diff_sse[uv_row * uv_diff_stride + uv_col]; @@ -552,7 +769,7 @@ void vp9_highbd_apply_temporal_filter_c( static uint32_t temporal_filter_find_matching_mb_c( VP9_COMP *cpi, ThreadData *td, uint8_t *arf_frame_buf, uint8_t *frame_ptr_buf, int stride, MV *ref_mv, MV *blk_mvs, - int *blk_bestsme) { + int *blk_bestsme, int *is_dc_diff_large) { MACROBLOCK *const x = &td->mb; MACROBLOCKD *const xd = &x->e_mbd; MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv; @@ -582,6 +799,7 @@ static uint32_t temporal_filter_find_matching_mb_c( x->plane[0].src.stride = stride; xd->plane[0].pre[0].buf = frame_ptr_buf; xd->plane[0].pre[0].stride = stride; + *is_dc_diff_large = 0; step_param = mv_sf->reduce_first_step_size; step_param = VPXMIN(step_param, MAX_MVSEARCH_STEPS - 2); @@ -603,6 +821,7 @@ static uint32_t temporal_filter_find_matching_mb_c( x->errorperbit, &cpi->fn_ptr[TF_BLOCK], 0, mv_sf->subpel_search_level, cond_cost_list(cpi, cost_list), NULL, NULL, &distortion, &sse, NULL, BW, BH, USE_8_TAPS_SHARP); + *is_dc_diff_large = 50 * bestsme < sse; // DO motion search on 4 16x16 sub_blocks. best_ref_mv1.row = ref_mv->row; @@ -660,6 +879,7 @@ void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, DECLARE_ALIGNED(16, uint16_t, count[BLK_PELS * 3]); MACROBLOCKD *mbd = &td->mb.e_mbd; YV12_BUFFER_CONFIG *f = frames[alt_ref_index]; + YV12_BUFFER_CONFIG *dst = arnr_filter_data->dst; uint8_t *dst1, *dst2; #if CONFIG_VP9_HIGHBITDEPTH DECLARE_ALIGNED(16, uint16_t, predictor16[BLK_PELS * 3]); @@ -685,18 +905,17 @@ void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, // Source frames are extended to 16 pixels. This is different than // L/A/G reference frames that have a border of 32 (VP9ENCBORDERINPIXELS) - // A 6/8 tap filter is used for motion search. This requires 2 pixels - // before and 3 pixels after. So the largest Y mv on a border would - // then be 16 - VP9_INTERP_EXTEND. The UV blocks are half the size of the - // Y and therefore only extended by 8. The largest mv that a UV block - // can support is 8 - VP9_INTERP_EXTEND. A UV mv is half of a Y mv. - // (16 - VP9_INTERP_EXTEND) >> 1 which is greater than - // 8 - VP9_INTERP_EXTEND. - // To keep the mv in play for both Y and UV planes the max that it - // can be on a border is therefore 16 - (2*VP9_INTERP_EXTEND+1). - td->mb.mv_limits.row_min = -((mb_row * BH) + (17 - 2 * VP9_INTERP_EXTEND)); + // A 6/8/12 tap filter is used for motion search and prediction. So the + // largest Y mv on a border would then be 16 - TF_INTERP_EXTEND. The UV + // blocks are half the size of the Y and therefore only extended by 8. + // The largest mv that a UV block can support is 8 - TF_INTERP_EXTEND. + // A UV mv is half of a Y mv. (16 - TF_INTERP_EXTEND) >> 1 is greater than + // 8 - TF_INTERP_EXTEND. To keep the mv in play for both Y and UV planes, + // the max that it can be on a border is therefore 16 - (2 * TF_INTERP_EXTEND + // + 1). + td->mb.mv_limits.row_min = -((mb_row * BH) + (17 - 2 * TF_INTERP_EXTEND)); td->mb.mv_limits.row_max = - ((mb_rows - 1 - mb_row) * BH) + (17 - 2 * VP9_INTERP_EXTEND); + ((mb_rows - 1 - mb_row) * BH) + (17 - 2 * TF_INTERP_EXTEND); for (mb_col = mb_col_start; mb_col < mb_col_end; mb_col++) { int i, j, k; @@ -706,9 +925,9 @@ void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, vp9_zero_array(accumulator, BLK_PELS * 3); vp9_zero_array(count, BLK_PELS * 3); - td->mb.mv_limits.col_min = -((mb_col * BW) + (17 - 2 * VP9_INTERP_EXTEND)); + td->mb.mv_limits.col_min = -((mb_col * BW) + (17 - 2 * TF_INTERP_EXTEND)); td->mb.mv_limits.col_max = - ((mb_cols - 1 - mb_col) * BW) + (17 - 2 * VP9_INTERP_EXTEND); + ((mb_cols - 1 - mb_col) * BW) + (17 - 2 * TF_INTERP_EXTEND); if (cpi->oxcf.content == VP9E_CONTENT_FILM) { unsigned int src_variance; @@ -756,12 +975,17 @@ void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, const int thresh_low = 10000; const int thresh_high = 20000; int blk_bestsme[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX }; + int is_dc_diff_large = 0; // Find best match in this frame by MC int err = temporal_filter_find_matching_mb_c( cpi, td, frames[alt_ref_index]->y_buffer + mb_y_offset, frames[frame]->y_buffer + mb_y_offset, frames[frame]->y_stride, - &ref_mv, blk_mvs, blk_bestsme); + &ref_mv, blk_mvs, blk_bestsme, &is_dc_diff_large); + + if (cpi->oxcf.enable_keyframe_filtering == 1 && + cpi->common.frame_type == KEY_FRAME && is_dc_diff_large) + strength = VPXMIN(strength, 1); int err16 = blk_bestsme[0] + blk_bestsme[1] + blk_bestsme[2] + blk_bestsme[3]; @@ -777,16 +1001,16 @@ void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, // Assign higher weight to matching MB if it's error // score is lower. If not applying MC default behavior // is to weight all MBs equal. - blk_fw[0] = err < (thresh_low << THR_SHIFT) - ? 2 - : err < (thresh_high << THR_SHIFT) ? 1 : 0; + blk_fw[0] = err < (thresh_low << THR_SHIFT) ? 2 + : err < (thresh_high << THR_SHIFT) ? 1 + : 0; blk_fw[1] = blk_fw[2] = blk_fw[3] = blk_fw[0]; } else { use_32x32 = 0; for (k = 0; k < 4; k++) - blk_fw[k] = blk_bestsme[k] < thresh_low - ? 2 - : blk_bestsme[k] < thresh_high ? 1 : 0; + blk_fw[k] = blk_bestsme[k] < thresh_low ? 2 + : blk_bestsme[k] < thresh_high ? 1 + : 0; } for (k = 0; k < 4; k++) { @@ -853,9 +1077,9 @@ void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, uint16_t *dst1_16; uint16_t *dst2_16; // Normalize filter output to produce AltRef frame - dst1 = cpi->alt_ref_buffer.y_buffer; + dst1 = dst->y_buffer; dst1_16 = CONVERT_TO_SHORTPTR(dst1); - stride = cpi->alt_ref_buffer.y_stride; + stride = dst->y_stride; byte = mb_y_offset; for (i = 0, k = 0; i < BH; i++) { for (j = 0; j < BW; j++, k++) { @@ -872,11 +1096,11 @@ void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, byte += stride - BW; } - dst1 = cpi->alt_ref_buffer.u_buffer; - dst2 = cpi->alt_ref_buffer.v_buffer; + dst1 = dst->u_buffer; + dst2 = dst->v_buffer; dst1_16 = CONVERT_TO_SHORTPTR(dst1); dst2_16 = CONVERT_TO_SHORTPTR(dst2); - stride = cpi->alt_ref_buffer.uv_stride; + stride = dst->uv_stride; byte = mb_uv_offset; for (i = 0, k = BLK_PELS; i < mb_uv_height; i++) { for (j = 0; j < mb_uv_width; j++, k++) { @@ -902,8 +1126,8 @@ void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, } } else { // Normalize filter output to produce AltRef frame - dst1 = cpi->alt_ref_buffer.y_buffer; - stride = cpi->alt_ref_buffer.y_stride; + dst1 = dst->y_buffer; + stride = dst->y_stride; byte = mb_y_offset; for (i = 0, k = 0; i < BH; i++) { for (j = 0; j < BW; j++, k++) { @@ -919,9 +1143,9 @@ void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, byte += stride - BW; } - dst1 = cpi->alt_ref_buffer.u_buffer; - dst2 = cpi->alt_ref_buffer.v_buffer; - stride = cpi->alt_ref_buffer.uv_stride; + dst1 = dst->u_buffer; + dst2 = dst->v_buffer; + stride = dst->uv_stride; byte = mb_uv_offset; for (i = 0, k = BLK_PELS; i < mb_uv_height; i++) { for (j = 0; j < mb_uv_width; j++, k++) { @@ -947,8 +1171,8 @@ void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, } #else // Normalize filter output to produce AltRef frame - dst1 = cpi->alt_ref_buffer.y_buffer; - stride = cpi->alt_ref_buffer.y_stride; + dst1 = dst->y_buffer; + stride = dst->y_stride; byte = mb_y_offset; for (i = 0, k = 0; i < BH; i++) { for (j = 0; j < BW; j++, k++) { @@ -964,9 +1188,9 @@ void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, byte += stride - BW; } - dst1 = cpi->alt_ref_buffer.u_buffer; - dst2 = cpi->alt_ref_buffer.v_buffer; - stride = cpi->alt_ref_buffer.uv_stride; + dst1 = dst->u_buffer; + dst2 = dst->v_buffer; + stride = dst->uv_stride; byte = mb_uv_offset; for (i = 0, k = BLK_PELS; i < mb_uv_height; i++) { for (j = 0; j < mb_uv_width; j++, k++) { @@ -1029,37 +1253,25 @@ static void temporal_filter_iterate_c(VP9_COMP *cpi) { // Apply buffer limits and context specific adjustments to arnr filter. static void adjust_arnr_filter(VP9_COMP *cpi, int distance, int group_boost, - int *arnr_frames, int *arnr_strength) { + int *arnr_frames, int *frames_backward, + int *frames_forward, int *arnr_strength) { const VP9EncoderConfig *const oxcf = &cpi->oxcf; - const GF_GROUP *const gf_group = &cpi->twopass.gf_group; - const int frames_after_arf = - vp9_lookahead_depth(cpi->lookahead) - distance - 1; - int frames_fwd = (cpi->oxcf.arnr_max_frames - 1) >> 1; - int frames_bwd; - int q, frames, base_strength, strength; + + int max_fwd = + VPXMAX((int)vp9_lookahead_depth(cpi->lookahead) - distance - 1, 0); + int max_bwd = VPXMAX(distance, 0); + int frames = VPXMAX(oxcf->arnr_max_frames, 1); + int q, base_strength, strength; // Context dependent two pass adjustment to strength. if (oxcf->pass == 2) { base_strength = oxcf->arnr_strength + cpi->twopass.arnr_strength_adjustment; // Clip to allowed range. - base_strength = VPXMIN(6, VPXMAX(0, base_strength)); + base_strength = clamp(base_strength, 0, 6); } else { base_strength = oxcf->arnr_strength; } - // Define the forward and backwards filter limits for this arnr group. - if (frames_fwd > frames_after_arf) frames_fwd = frames_after_arf; - if (frames_fwd > distance) frames_fwd = distance; - - frames_bwd = frames_fwd; - - // For even length filter there is one more frame backward - // than forward: e.g. len=6 ==> bbbAff, len=7 ==> bbbAfff. - if (frames_bwd < distance) frames_bwd += (oxcf->arnr_max_frames + 1) & 0x1; - - // Set the baseline active filter size. - frames = frames_bwd + 1 + frames_fwd; - // Adjust the strength based on active max q. if (cpi->common.current_video_frame > 1) q = ((int)vp9_convert_qindex_to_q(cpi->rc.avg_frame_qindex[INTER_FRAME], @@ -1075,15 +1287,29 @@ static void adjust_arnr_filter(VP9_COMP *cpi, int distance, int group_boost, } // Adjust number of frames in filter and strength based on gf boost level. - if (frames > group_boost / 150) { - frames = group_boost / 150; - frames += !(frames & 1); - } + frames = VPXMIN(frames, group_boost / 150); if (strength > group_boost / 300) { strength = group_boost / 300; } + if (VPXMIN(max_fwd, max_bwd) >= frames / 2) { + // Handle the even/odd case. + *frames_backward = frames / 2; + *frames_forward = (frames - 1) / 2; + } else { + if (max_fwd < frames / 2) { + *frames_forward = max_fwd; + *frames_backward = VPXMIN(frames - 1 - *frames_forward, max_bwd); + } else { + *frames_backward = max_bwd; + *frames_forward = VPXMIN(frames - 1 - *frames_backward, max_fwd); + } + } + + // Set the baseline active filter size. + frames = *frames_backward + 1 + *frames_forward; + // Adjustments for second level arf in multi arf case. // Leave commented out place holder for possible filtering adjustment with // new multi-layer arf code. @@ -1093,9 +1319,11 @@ static void adjust_arnr_filter(VP9_COMP *cpi, int distance, int group_boost, // TODO(jingning): Skip temporal filtering for intermediate frames that will // be used as show_existing_frame. Need to further explore the possibility to // apply certain filter. - if (gf_group->arf_src_offset[gf_group->index] < - cpi->rc.baseline_gf_interval - 1) + if (frames <= 1) { frames = 1; + *frames_backward = 0; + *frames_forward = 0; + } *arnr_frames = frames; *arnr_strength = strength; @@ -1117,14 +1345,15 @@ void vp9_temporal_filter(VP9_COMP *cpi, int distance) { int rdmult; // Apply context specific adjustments to the arnr filter parameters. - adjust_arnr_filter(cpi, distance, rc->gfu_boost, &frames_to_blur, &strength); - frames_to_blur_backward = (frames_to_blur / 2); - frames_to_blur_forward = ((frames_to_blur - 1) / 2); + adjust_arnr_filter(cpi, distance, rc->gfu_boost, &frames_to_blur, + &frames_to_blur_backward, &frames_to_blur_forward, + &strength); start_frame = distance + frames_to_blur_forward; arnr_filter_data->strength = strength; arnr_filter_data->frame_count = frames_to_blur; arnr_filter_data->alt_ref_index = frames_to_blur_backward; + arnr_filter_data->dst = &cpi->tf_buffer; // Setup frame pointers, NULL indicates frame not included in filter. for (frame = 0; frame < frames_to_blur; ++frame) { @@ -1134,6 +1363,11 @@ void vp9_temporal_filter(VP9_COMP *cpi, int distance) { frames[frames_to_blur - 1 - frame] = &buf->img; } + YV12_BUFFER_CONFIG *f = frames[arnr_filter_data->alt_ref_index]; + xd->cur_buf = f; + xd->plane[1].subsampling_y = f->subsampling_y; + xd->plane[1].subsampling_x = f->subsampling_x; + if (frames_to_blur > 0) { // Setup scaling factors. Scaling on each of the arnr frames is not // supported. diff --git a/libs/libvpx/vp9/encoder/vp9_temporal_filter.h b/libs/libvpx/vp9/encoder/vp9_temporal_filter.h index 553a468280..59fb71fc0d 100644 --- a/libs/libvpx/vp9/encoder/vp9_temporal_filter.h +++ b/libs/libvpx/vp9/encoder/vp9_temporal_filter.h @@ -16,7 +16,8 @@ extern "C" { #endif #define ARNR_FILT_QINDEX 128 -static const MV kZeroMv = { 0, 0 }; +struct VP9_COMP; +struct ThreadData; // Block size used in temporal filtering #define TF_BLOCK BLOCK_32X32 @@ -31,13 +32,37 @@ static const MV kZeroMv = { 0, 0 }; #define TF_SUB_BLOCK BLOCK_16X16 #define SUB_BH 16 #define SUB_BW 16 +#define MAX_FILTER_TAP 12 + +typedef int16_t InterpKernel12[MAX_FILTER_TAP]; + +// 12-tap filter (used by the encoder only). +DECLARE_ALIGNED(256, static const InterpKernel12, + sub_pel_filters_12[SUBPEL_SHIFTS]) = { + { 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0 }, + { 0, 1, -2, 3, -7, 127, 8, -4, 2, -1, 1, 0 }, + { -1, 2, -3, 6, -13, 124, 18, -8, 4, -2, 2, -1 }, + { -1, 3, -4, 8, -18, 120, 28, -12, 7, -4, 2, -1 }, + { -1, 3, -6, 10, -21, 115, 38, -15, 8, -5, 3, -1 }, + { -2, 4, -6, 12, -24, 108, 49, -18, 10, -6, 3, -2 }, + { -2, 4, -7, 13, -25, 100, 60, -21, 11, -7, 4, -2 }, + { -2, 4, -7, 13, -26, 91, 71, -24, 13, -7, 4, -2 }, + { -2, 4, -7, 13, -25, 81, 81, -25, 13, -7, 4, -2 }, + { -2, 4, -7, 13, -24, 71, 91, -26, 13, -7, 4, -2 }, + { -2, 4, -7, 11, -21, 60, 100, -25, 13, -7, 4, -2 }, + { -2, 3, -6, 10, -18, 49, 108, -24, 12, -6, 4, -2 }, + { -1, 3, -5, 8, -15, 38, 115, -21, 10, -6, 3, -1 }, + { -1, 2, -4, 7, -12, 28, 120, -18, 8, -4, 3, -1 }, + { -1, 2, -2, 4, -8, 18, 124, -13, 6, -3, 2, -1 }, + { 0, 1, -1, 2, -4, 8, 127, -7, 3, -2, 1, 0 } +}; void vp9_temporal_filter_init(void); -void vp9_temporal_filter(VP9_COMP *cpi, int distance); +void vp9_temporal_filter(struct VP9_COMP *cpi, int distance); -void vp9_temporal_filter_iterate_row_c(VP9_COMP *cpi, ThreadData *td, - int mb_row, int mb_col_start, - int mb_col_end); +void vp9_temporal_filter_iterate_row_c(struct VP9_COMP *cpi, + struct ThreadData *td, int mb_row, + int mb_col_start, int mb_col_end); #ifdef __cplusplus } // extern "C" diff --git a/libs/libvpx/vp9/encoder/x86/temporal_filter_constants.h b/libs/libvpx/vp9/encoder/vp9_temporal_filter_constants.h similarity index 95% rename from libs/libvpx/vp9/encoder/x86/temporal_filter_constants.h rename to libs/libvpx/vp9/encoder/vp9_temporal_filter_constants.h index 7dcedda192..04087cc964 100644 --- a/libs/libvpx/vp9/encoder/x86/temporal_filter_constants.h +++ b/libs/libvpx/vp9/encoder/vp9_temporal_filter_constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 The WebM project authors. All Rights Reserved. + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef VPX_VP9_ENCODER_X86_TEMPORAL_FILTER_CONSTANTS_H_ -#define VPX_VP9_ENCODER_X86_TEMPORAL_FILTER_CONSTANTS_H_ +#ifndef VPX_VP9_ENCODER_TEMPORAL_FILTER_CONSTANTS_H_ +#define VPX_VP9_ENCODER_TEMPORAL_FILTER_CONSTANTS_H_ #include "./vpx_config.h" // Division using multiplication and shifting. The C implementation does: @@ -374,37 +374,37 @@ static const uint32_t *const HIGHBD_CHROMA_NO_SS_RIGHT_COLUMN_NEIGHBORS[2] = { HIGHBD_RIGHT_CORNER_NEIGHBORS_PLUS_1, HIGHBD_RIGHT_EDGE_NEIGHBORS_PLUS_1 }; -static const uint32_t - *const HIGHBD_CHROMA_SINGLE_SS_LEFT_COLUMN_NEIGHBORS[2] = { +static const uint32_t *const + HIGHBD_CHROMA_SINGLE_SS_LEFT_COLUMN_NEIGHBORS[2] = { HIGHBD_LEFT_CORNER_NEIGHBORS_PLUS_2, HIGHBD_LEFT_EDGE_NEIGHBORS_PLUS_2 }; -static const uint32_t - *const HIGHBD_CHROMA_SINGLE_SS_MIDDLE_COLUMN_NEIGHBORS[2] = { +static const uint32_t *const + HIGHBD_CHROMA_SINGLE_SS_MIDDLE_COLUMN_NEIGHBORS[2] = { HIGHBD_MIDDLE_EDGE_NEIGHBORS_PLUS_2, HIGHBD_MIDDLE_CENTER_NEIGHBORS_PLUS_2 }; -static const uint32_t - *const HIGHBD_CHROMA_SINGLE_SS_RIGHT_COLUMN_NEIGHBORS[2] = { +static const uint32_t *const + HIGHBD_CHROMA_SINGLE_SS_RIGHT_COLUMN_NEIGHBORS[2] = { HIGHBD_RIGHT_CORNER_NEIGHBORS_PLUS_2, HIGHBD_RIGHT_EDGE_NEIGHBORS_PLUS_2 }; -static const uint32_t - *const HIGHBD_CHROMA_DOUBLE_SS_LEFT_COLUMN_NEIGHBORS[2] = { +static const uint32_t *const + HIGHBD_CHROMA_DOUBLE_SS_LEFT_COLUMN_NEIGHBORS[2] = { HIGHBD_LEFT_CORNER_NEIGHBORS_PLUS_4, HIGHBD_LEFT_EDGE_NEIGHBORS_PLUS_4 }; -static const uint32_t - *const HIGHBD_CHROMA_DOUBLE_SS_MIDDLE_COLUMN_NEIGHBORS[2] = { +static const uint32_t *const + HIGHBD_CHROMA_DOUBLE_SS_MIDDLE_COLUMN_NEIGHBORS[2] = { HIGHBD_MIDDLE_EDGE_NEIGHBORS_PLUS_4, HIGHBD_MIDDLE_CENTER_NEIGHBORS_PLUS_4 }; -static const uint32_t - *const HIGHBD_CHROMA_DOUBLE_SS_RIGHT_COLUMN_NEIGHBORS[2] = { +static const uint32_t *const + HIGHBD_CHROMA_DOUBLE_SS_RIGHT_COLUMN_NEIGHBORS[2] = { HIGHBD_RIGHT_CORNER_NEIGHBORS_PLUS_4, HIGHBD_RIGHT_EDGE_NEIGHBORS_PLUS_4 }; #endif // CONFIG_VP9_HIGHBITDEPTH #define DIST_STRIDE ((BW) + 2) -#endif // VPX_VP9_ENCODER_X86_TEMPORAL_FILTER_CONSTANTS_H_ +#endif // VPX_VP9_ENCODER_TEMPORAL_FILTER_CONSTANTS_H_ diff --git a/libs/libvpx/vp9/encoder/vp9_tokenize.c b/libs/libvpx/vp9/encoder/vp9_tokenize.c index 814d769be3..342a4f5c59 100644 --- a/libs/libvpx/vp9/encoder/vp9_tokenize.c +++ b/libs/libvpx/vp9/encoder/vp9_tokenize.c @@ -364,13 +364,13 @@ static void tokenize_b(int plane, int block, int row, int col, const PLANE_TYPE type = get_plane_type(plane); const tran_low_t *qcoeff = BLOCK_OFFSET(p->qcoeff, block); const int16_t *scan, *nb; - const scan_order *so; + const ScanOrder *so; const int ref = is_inter_block(mi); - unsigned int(*const counts)[COEFF_CONTEXTS][ENTROPY_TOKENS] = + unsigned int (*const counts)[COEFF_CONTEXTS][ENTROPY_TOKENS] = td->rd_counts.coef_counts[tx_size][type][ref]; vpx_prob(*const coef_probs)[COEFF_CONTEXTS][UNCONSTRAINED_NODES] = cpi->common.fc->coef_probs[tx_size][type][ref]; - unsigned int(*const eob_branch)[COEFF_CONTEXTS] = + unsigned int (*const eob_branch)[COEFF_CONTEXTS] = td->counts->eob_branch[tx_size][type][ref]; const uint8_t *const band = get_band_translate(tx_size); const int tx_eob = 16 << (tx_size << 1); diff --git a/libs/libvpx/vp9/encoder/vp9_tpl_model.c b/libs/libvpx/vp9/encoder/vp9_tpl_model.c new file mode 100644 index 0000000000..cecee3706c --- /dev/null +++ b/libs/libvpx/vp9/encoder/vp9_tpl_model.c @@ -0,0 +1,1793 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_dsp_rtcd.h" +#if CONFIG_NON_GREEDY_MV +#include "vp9/common/vp9_mvref_common.h" +#endif +#include "vp9/common/vp9_reconinter.h" +#include "vp9/common/vp9_reconintra.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_encoder.h" +#include "vp9/encoder/vp9_ext_ratectrl.h" +#include "vp9/encoder/vp9_firstpass.h" +#include "vp9/encoder/vp9_ratectrl.h" +#include "vp9/encoder/vp9_tpl_model.h" +#include "vpx/internal/vpx_codec_internal.h" +#include "vpx/vpx_codec.h" +#include "vpx/vpx_ext_ratectrl.h" + +static int init_gop_frames_rc(VP9_COMP *cpi, GF_PICTURE *gf_picture, + const GF_GROUP *gf_group, int *tpl_group_frames) { + VP9_COMMON *cm = &cpi->common; + int frame_idx = 0; + int i; + int extend_frame_count = 0; + int pframe_qindex = cpi->tpl_stats[2].base_qindex; + int frame_gop_offset = 0; + + int added_overlay = 0; + + RefCntBuffer *frame_bufs = cm->buffer_pool->frame_bufs; + int8_t recon_frame_index[REFS_PER_FRAME + MAX_ARF_LAYERS]; + + memset(recon_frame_index, -1, sizeof(recon_frame_index)); + + for (i = 0; i < FRAME_BUFFERS; ++i) { + if (frame_bufs[i].ref_count == 0) { + alloc_frame_mvs(cm, i); + if (vpx_realloc_frame_buffer(&frame_bufs[i].buf, cm->width, cm->height, + cm->subsampling_x, cm->subsampling_y, +#if CONFIG_VP9_HIGHBITDEPTH + cm->use_highbitdepth, +#endif + VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, + NULL, NULL, NULL)) + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, + "Failed to allocate frame buffer"); + + recon_frame_index[frame_idx] = i; + ++frame_idx; + + if (frame_idx >= REFS_PER_FRAME + cpi->oxcf.enable_auto_arf) break; + } + } + + for (i = 0; i < REFS_PER_FRAME + 1; ++i) { + assert(recon_frame_index[i] >= 0); + cpi->tpl_recon_frames[i] = &frame_bufs[recon_frame_index[i]].buf; + } + + *tpl_group_frames = 0; + + int ref_table[3]; + + if (gf_group->index == 1 && gf_group->update_type[1] == ARF_UPDATE) { + if (gf_group->update_type[0] == KF_UPDATE) { + // This is the only frame in ref buffer. We need it to be on + // gf_picture[0]. + for (i = 0; i < 3; ++i) ref_table[i] = -REFS_PER_FRAME; + + gf_picture[0].frame = + &cm->buffer_pool + ->frame_bufs[cm->ref_frame_map[gf_group->update_ref_idx[0]]] + .buf; + ref_table[gf_group->update_ref_idx[0]] = 0; + + for (i = 0; i < 3; ++i) gf_picture[0].ref_frame[i] = -REFS_PER_FRAME; + gf_picture[0].update_type = gf_group->update_type[0]; + } else { + for (i = 0; i < REFS_PER_FRAME; i++) { + if (cm->ref_frame_map[i] != -1) { + gf_picture[-i].frame = + &cm->buffer_pool->frame_bufs[cm->ref_frame_map[i]].buf; + ref_table[i] = -i; + } else { + ref_table[i] = -REFS_PER_FRAME; + } + } + for (i = 0; i < 3; ++i) { + gf_picture[0].ref_frame[i] = ref_table[i]; + } + } + ++*tpl_group_frames; + + // Initialize base layer ARF frame + gf_picture[1].frame = cpi->Source; + for (i = 0; i < 3; ++i) gf_picture[1].ref_frame[i] = ref_table[i]; + gf_picture[1].update_type = gf_group->update_type[1]; + ref_table[gf_group->update_ref_idx[1]] = 1; + + ++*tpl_group_frames; + } else { + assert(gf_group->index == 0); + if (gf_group->update_type[0] == KF_UPDATE) { + // This is the only frame in ref buffer. We need it to be on + // gf_picture[0]. + gf_picture[0].frame = cpi->Source; + for (i = 0; i < 3; ++i) gf_picture[0].ref_frame[i] = -REFS_PER_FRAME; + gf_picture[0].update_type = gf_group->update_type[0]; + + for (i = 0; i < 3; ++i) ref_table[i] = -REFS_PER_FRAME; + ref_table[gf_group->update_ref_idx[0]] = 0; + } else { + // Initialize ref table + for (i = 0; i < REFS_PER_FRAME; i++) { + if (cm->ref_frame_map[i] != -1) { + gf_picture[-i].frame = + &cm->buffer_pool->frame_bufs[cm->ref_frame_map[i]].buf; + ref_table[i] = -i; + } else { + ref_table[i] = -REFS_PER_FRAME; + } + } + for (i = 0; i < 3; ++i) { + gf_picture[0].ref_frame[i] = ref_table[i]; + } + gf_picture[0].update_type = gf_group->update_type[0]; + if (gf_group->update_type[0] != OVERLAY_UPDATE && + gf_group->update_ref_idx[0] != -1) { + ref_table[gf_group->update_ref_idx[0]] = 0; + } + } + ++*tpl_group_frames; + } + + int has_arf = + gf_group->gf_group_size > 1 && gf_group->update_type[1] == ARF_UPDATE && + gf_group->update_type[gf_group->gf_group_size] == OVERLAY_UPDATE; + + // Initialize P frames + for (frame_idx = *tpl_group_frames; frame_idx < MAX_ARF_GOP_SIZE; + ++frame_idx) { + if (frame_idx >= gf_group->gf_group_size && !has_arf) break; + struct lookahead_entry *buf; + frame_gop_offset = gf_group->frame_gop_index[frame_idx]; + buf = vp9_lookahead_peek(cpi->lookahead, frame_gop_offset - 1); + + if (buf == NULL) break; + + gf_picture[frame_idx].frame = &buf->img; + for (i = 0; i < 3; ++i) { + gf_picture[frame_idx].ref_frame[i] = ref_table[i]; + } + + if (gf_group->update_type[frame_idx] != OVERLAY_UPDATE && + gf_group->update_ref_idx[frame_idx] != -1) { + ref_table[gf_group->update_ref_idx[frame_idx]] = frame_idx; + } + + gf_picture[frame_idx].update_type = gf_group->update_type[frame_idx]; + + ++*tpl_group_frames; + + // The length of group of pictures is baseline_gf_interval, plus the + // beginning golden frame from last GOP, plus the last overlay frame in + // the same GOP. + if (frame_idx == gf_group->gf_group_size) { + added_overlay = 1; + + ++frame_idx; + ++frame_gop_offset; + break; + } + + if (frame_idx == gf_group->gf_group_size - 1 && + gf_group->update_type[gf_group->gf_group_size] != OVERLAY_UPDATE) { + ++frame_idx; + ++frame_gop_offset; + break; + } + } + + int lst_index = frame_idx - 1; + // Extend two frames outside the current gf group. + for (; has_arf && frame_idx < MAX_LAG_BUFFERS && extend_frame_count < 2; + ++frame_idx) { + struct lookahead_entry *buf = + vp9_lookahead_peek(cpi->lookahead, frame_gop_offset - 1); + + if (buf == NULL) break; + + cpi->tpl_stats[frame_idx].base_qindex = pframe_qindex; + + gf_picture[frame_idx].frame = &buf->img; + gf_picture[frame_idx].ref_frame[0] = gf_picture[lst_index].ref_frame[0]; + gf_picture[frame_idx].ref_frame[1] = gf_picture[lst_index].ref_frame[1]; + gf_picture[frame_idx].ref_frame[2] = gf_picture[lst_index].ref_frame[2]; + + if (gf_picture[frame_idx].ref_frame[0] > + gf_picture[frame_idx].ref_frame[1] && + gf_picture[frame_idx].ref_frame[0] > + gf_picture[frame_idx].ref_frame[2]) { + gf_picture[frame_idx].ref_frame[0] = lst_index; + } else if (gf_picture[frame_idx].ref_frame[1] > + gf_picture[frame_idx].ref_frame[0] && + gf_picture[frame_idx].ref_frame[1] > + gf_picture[frame_idx].ref_frame[2]) { + gf_picture[frame_idx].ref_frame[1] = lst_index; + } else { + gf_picture[frame_idx].ref_frame[2] = lst_index; + } + + gf_picture[frame_idx].update_type = LF_UPDATE; + lst_index = frame_idx; + ++*tpl_group_frames; + ++extend_frame_count; + ++frame_gop_offset; + } + + return extend_frame_count + added_overlay; +} + +static int init_gop_frames(VP9_COMP *cpi, GF_PICTURE *gf_picture, + const GF_GROUP *gf_group, int *tpl_group_frames) { + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_GOP) != 0) { + return init_gop_frames_rc(cpi, gf_picture, gf_group, tpl_group_frames); + } + + VP9_COMMON *cm = &cpi->common; + int frame_idx = 0; + int i; + int gld_index = -1; + int alt_index = -2; + int lst_index = -1; + int arf_index_stack[MAX_ARF_LAYERS]; + int arf_stack_size = 0; + int extend_frame_count = 0; + int pframe_qindex = cpi->tpl_stats[2].base_qindex; + int frame_gop_offset = 0; + + RefCntBuffer *frame_bufs = cm->buffer_pool->frame_bufs; + int8_t recon_frame_index[REFS_PER_FRAME + MAX_ARF_LAYERS]; + + memset(recon_frame_index, -1, sizeof(recon_frame_index)); + stack_init(arf_index_stack, MAX_ARF_LAYERS); + + for (i = 0; i < FRAME_BUFFERS; ++i) { + if (frame_bufs[i].ref_count == 0) { + alloc_frame_mvs(cm, i); + if (vpx_realloc_frame_buffer(&frame_bufs[i].buf, cm->width, cm->height, + cm->subsampling_x, cm->subsampling_y, +#if CONFIG_VP9_HIGHBITDEPTH + cm->use_highbitdepth, +#endif + VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, + NULL, NULL, NULL)) + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, + "Failed to allocate frame buffer"); + + recon_frame_index[frame_idx] = i; + ++frame_idx; + + if (frame_idx >= REFS_PER_FRAME + cpi->oxcf.enable_auto_arf) break; + } + } + + for (i = 0; i < REFS_PER_FRAME + 1; ++i) { + assert(recon_frame_index[i] >= 0); + cpi->tpl_recon_frames[i] = &frame_bufs[recon_frame_index[i]].buf; + } + + *tpl_group_frames = 0; + + // Initialize Golden reference frame. + gf_picture[0].frame = get_ref_frame_buffer(cpi, GOLDEN_FRAME); + for (i = 0; i < 3; ++i) gf_picture[0].ref_frame[i] = -REFS_PER_FRAME; + gf_picture[0].update_type = gf_group->update_type[0]; + gld_index = 0; + ++*tpl_group_frames; + + gf_picture[-1].frame = get_ref_frame_buffer(cpi, LAST_FRAME); + gf_picture[-2].frame = get_ref_frame_buffer(cpi, ALTREF_FRAME); + + // Initialize base layer ARF frame + gf_picture[1].frame = cpi->Source; + gf_picture[1].ref_frame[0] = gld_index; + gf_picture[1].ref_frame[1] = lst_index; + gf_picture[1].ref_frame[2] = alt_index; + gf_picture[1].update_type = gf_group->update_type[1]; + alt_index = 1; + ++*tpl_group_frames; + + // Initialize P frames + for (frame_idx = 2; frame_idx < MAX_ARF_GOP_SIZE; ++frame_idx) { + struct lookahead_entry *buf; + frame_gop_offset = gf_group->frame_gop_index[frame_idx]; + buf = vp9_lookahead_peek(cpi->lookahead, frame_gop_offset - 1); + + if (buf == NULL) break; + + gf_picture[frame_idx].frame = &buf->img; + gf_picture[frame_idx].ref_frame[0] = gld_index; + gf_picture[frame_idx].ref_frame[1] = lst_index; + gf_picture[frame_idx].ref_frame[2] = alt_index; + gf_picture[frame_idx].update_type = gf_group->update_type[frame_idx]; + + switch (gf_group->update_type[frame_idx]) { + case ARF_UPDATE: + stack_push(arf_index_stack, alt_index, arf_stack_size); + ++arf_stack_size; + alt_index = frame_idx; + break; + case LF_UPDATE: lst_index = frame_idx; break; + case OVERLAY_UPDATE: + gld_index = frame_idx; + alt_index = stack_pop(arf_index_stack, arf_stack_size); + --arf_stack_size; + break; + case USE_BUF_FRAME: + lst_index = alt_index; + alt_index = stack_pop(arf_index_stack, arf_stack_size); + --arf_stack_size; + break; + default: break; + } + + ++*tpl_group_frames; + + // The length of group of pictures is baseline_gf_interval, plus the + // beginning golden frame from last GOP, plus the last overlay frame in + // the same GOP. + if (frame_idx == gf_group->gf_group_size) break; + } + + alt_index = -1; + ++frame_idx; + ++frame_gop_offset; + + // Extend two frames outside the current gf group. + for (; frame_idx < MAX_LAG_BUFFERS && extend_frame_count < 2; ++frame_idx) { + struct lookahead_entry *buf = + vp9_lookahead_peek(cpi->lookahead, frame_gop_offset - 1); + + if (buf == NULL) break; + + cpi->tpl_stats[frame_idx].base_qindex = pframe_qindex; + + gf_picture[frame_idx].frame = &buf->img; + gf_picture[frame_idx].ref_frame[0] = gld_index; + gf_picture[frame_idx].ref_frame[1] = lst_index; + gf_picture[frame_idx].ref_frame[2] = alt_index; + gf_picture[frame_idx].update_type = LF_UPDATE; + lst_index = frame_idx; + ++*tpl_group_frames; + ++extend_frame_count; + ++frame_gop_offset; + } + + return extend_frame_count; +} + +static void init_tpl_stats(VP9_COMP *cpi) { + int frame_idx; + for (frame_idx = 0; frame_idx < MAX_ARF_GOP_SIZE; ++frame_idx) { + TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx]; + memset(tpl_frame->tpl_stats_ptr, 0, + tpl_frame->height * tpl_frame->width * + sizeof(*tpl_frame->tpl_stats_ptr)); + tpl_frame->is_valid = 0; + } +} + +static void free_tpl_frame_stats_list(VpxTplGopStats *tpl_gop_stats) { + int frame_idx; + for (frame_idx = 0; frame_idx < tpl_gop_stats->size; ++frame_idx) { + vpx_free(tpl_gop_stats->frame_stats_list[frame_idx].block_stats_list); + } + vpx_free(tpl_gop_stats->frame_stats_list); +} + +static void init_tpl_stats_before_propagation( + struct vpx_internal_error_info *error_info, VpxTplGopStats *tpl_gop_stats, + TplDepFrame *tpl_stats, int tpl_gop_frames, int frame_width, + int frame_height) { + int frame_idx; + free_tpl_frame_stats_list(tpl_gop_stats); + CHECK_MEM_ERROR( + error_info, tpl_gop_stats->frame_stats_list, + vpx_calloc(tpl_gop_frames, sizeof(*tpl_gop_stats->frame_stats_list))); + tpl_gop_stats->size = tpl_gop_frames; + for (frame_idx = 0; frame_idx < tpl_gop_frames; ++frame_idx) { + const int mi_rows = tpl_stats[frame_idx].mi_rows; + const int mi_cols = tpl_stats[frame_idx].mi_cols; + CHECK_MEM_ERROR( + error_info, tpl_gop_stats->frame_stats_list[frame_idx].block_stats_list, + vpx_calloc( + mi_rows * mi_cols, + sizeof( + *tpl_gop_stats->frame_stats_list[frame_idx].block_stats_list))); + tpl_gop_stats->frame_stats_list[frame_idx].num_blocks = mi_rows * mi_cols; + tpl_gop_stats->frame_stats_list[frame_idx].frame_width = frame_width; + tpl_gop_stats->frame_stats_list[frame_idx].frame_height = frame_height; + } +} + +#if CONFIG_NON_GREEDY_MV +static uint32_t full_pixel_motion_search(VP9_COMP *cpi, ThreadData *td, + MotionField *motion_field, + int frame_idx, uint8_t *cur_frame_buf, + uint8_t *ref_frame_buf, int stride, + BLOCK_SIZE bsize, int mi_row, + int mi_col, MV *mv) { + MACROBLOCK *const x = &td->mb; + MACROBLOCKD *const xd = &x->e_mbd; + MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv; + int step_param; + uint32_t bestsme = UINT_MAX; + const MvLimits tmp_mv_limits = x->mv_limits; + // lambda is used to adjust the importance of motion vector consistency. + // TODO(angiebird): Figure out lambda's proper value. + const int lambda = cpi->tpl_stats[frame_idx].lambda; + int_mv nb_full_mvs[NB_MVS_NUM]; + int nb_full_mv_num; + + MV best_ref_mv1 = { 0, 0 }; + MV best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */ + + best_ref_mv1_full.col = best_ref_mv1.col >> 3; + best_ref_mv1_full.row = best_ref_mv1.row >> 3; + + // Setup frame pointers + x->plane[0].src.buf = cur_frame_buf; + x->plane[0].src.stride = stride; + xd->plane[0].pre[0].buf = ref_frame_buf; + xd->plane[0].pre[0].stride = stride; + + step_param = mv_sf->reduce_first_step_size; + step_param = VPXMIN(step_param, MAX_MVSEARCH_STEPS - 2); + + vp9_set_mv_search_range(&x->mv_limits, &best_ref_mv1); + + nb_full_mv_num = + vp9_prepare_nb_full_mvs(motion_field, mi_row, mi_col, nb_full_mvs); + vp9_full_pixel_diamond_new(cpi, x, bsize, &best_ref_mv1_full, step_param, + lambda, 1, nb_full_mvs, nb_full_mv_num, mv); + + /* restore UMV window */ + x->mv_limits = tmp_mv_limits; + + return bestsme; +} + +static uint32_t sub_pixel_motion_search(VP9_COMP *cpi, ThreadData *td, + uint8_t *cur_frame_buf, + uint8_t *ref_frame_buf, int stride, + BLOCK_SIZE bsize, MV *mv) { + MACROBLOCK *const x = &td->mb; + MACROBLOCKD *const xd = &x->e_mbd; + MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv; + uint32_t bestsme = UINT_MAX; + uint32_t distortion; + uint32_t sse; + int cost_list[5]; + + MV best_ref_mv1 = { 0, 0 }; + + // Setup frame pointers + x->plane[0].src.buf = cur_frame_buf; + x->plane[0].src.stride = stride; + xd->plane[0].pre[0].buf = ref_frame_buf; + xd->plane[0].pre[0].stride = stride; + + // TODO(yunqing): may use higher tap interp filter than 2 taps. + // Ignore mv costing by sending NULL pointer instead of cost array + bestsme = cpi->find_fractional_mv_step( + x, mv, &best_ref_mv1, cpi->common.allow_high_precision_mv, x->errorperbit, + &cpi->fn_ptr[bsize], 0, mv_sf->subpel_search_level, + cond_cost_list(cpi, cost_list), NULL, NULL, &distortion, &sse, NULL, 0, 0, + USE_2_TAPS); + + return bestsme; +} + +#else // CONFIG_NON_GREEDY_MV +static uint32_t motion_compensated_prediction(VP9_COMP *cpi, ThreadData *td, + uint8_t *cur_frame_buf, + uint8_t *ref_frame_buf, + int stride, BLOCK_SIZE bsize, + MV *mv) { + MACROBLOCK *const x = &td->mb; + MACROBLOCKD *const xd = &x->e_mbd; + MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv; + const SEARCH_METHODS search_method = NSTEP; + int step_param; + int sadpb = x->sadperbit16; + uint32_t bestsme = UINT_MAX; + uint32_t distortion; + uint32_t sse; + int cost_list[5]; + const MvLimits tmp_mv_limits = x->mv_limits; + + MV best_ref_mv1 = { 0, 0 }; + MV best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */ + + best_ref_mv1_full.col = best_ref_mv1.col >> 3; + best_ref_mv1_full.row = best_ref_mv1.row >> 3; + + // Setup frame pointers + x->plane[0].src.buf = cur_frame_buf; + x->plane[0].src.stride = stride; + xd->plane[0].pre[0].buf = ref_frame_buf; + xd->plane[0].pre[0].stride = stride; + + step_param = mv_sf->reduce_first_step_size; + step_param = VPXMIN(step_param, MAX_MVSEARCH_STEPS - 2); + + vp9_set_mv_search_range(&x->mv_limits, &best_ref_mv1); + + vp9_full_pixel_search(cpi, x, bsize, &best_ref_mv1_full, step_param, + search_method, sadpb, cond_cost_list(cpi, cost_list), + &best_ref_mv1, mv, 0, 0); + + /* restore UMV window */ + x->mv_limits = tmp_mv_limits; + + // TODO(yunqing): may use higher tap interp filter than 2 taps. + // Ignore mv costing by sending NULL pointer instead of cost array + bestsme = cpi->find_fractional_mv_step( + x, mv, &best_ref_mv1, cpi->common.allow_high_precision_mv, x->errorperbit, + &cpi->fn_ptr[bsize], 0, mv_sf->subpel_search_level, + cond_cost_list(cpi, cost_list), NULL, NULL, &distortion, &sse, NULL, 0, 0, + USE_2_TAPS); + + return bestsme; +} +#endif + +static int get_overlap_area(int grid_pos_row, int grid_pos_col, int ref_pos_row, + int ref_pos_col, int block, BLOCK_SIZE bsize) { + int width = 0, height = 0; + int bw = 4 << b_width_log2_lookup[bsize]; + int bh = 4 << b_height_log2_lookup[bsize]; + + switch (block) { + case 0: + width = grid_pos_col + bw - ref_pos_col; + height = grid_pos_row + bh - ref_pos_row; + break; + case 1: + width = ref_pos_col + bw - grid_pos_col; + height = grid_pos_row + bh - ref_pos_row; + break; + case 2: + width = grid_pos_col + bw - ref_pos_col; + height = ref_pos_row + bh - grid_pos_row; + break; + case 3: + width = ref_pos_col + bw - grid_pos_col; + height = ref_pos_row + bh - grid_pos_row; + break; + default: assert(0); + } + + return width * height; +} + +static int round_floor(int ref_pos, int bsize_pix) { + int round; + if (ref_pos < 0) + round = -(1 + (-ref_pos - 1) / bsize_pix); + else + round = ref_pos / bsize_pix; + + return round; +} + +static void tpl_model_store(TplDepStats *tpl_stats, int mi_row, int mi_col, + BLOCK_SIZE bsize, int stride) { + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + const TplDepStats *src_stats = &tpl_stats[mi_row * stride + mi_col]; + int idx, idy; + + for (idy = 0; idy < mi_height; ++idy) { + for (idx = 0; idx < mi_width; ++idx) { + TplDepStats *tpl_ptr = &tpl_stats[(mi_row + idy) * stride + mi_col + idx]; + const int64_t mc_flow = tpl_ptr->mc_flow; + const int64_t mc_ref_cost = tpl_ptr->mc_ref_cost; + *tpl_ptr = *src_stats; + tpl_ptr->mc_flow = mc_flow; + tpl_ptr->mc_ref_cost = mc_ref_cost; + tpl_ptr->mc_dep_cost = tpl_ptr->intra_cost + tpl_ptr->mc_flow; + } + } +} + +static void tpl_store_before_propagation(VpxTplBlockStats *tpl_block_stats, + TplDepStats *tpl_stats, int mi_row, + int mi_col, BLOCK_SIZE bsize, + int src_stride, int64_t recon_error, + int64_t pred_error, int64_t rate_cost, + int ref_frame_idx, int mi_rows, + int mi_cols) { + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + const TplDepStats *src_stats = &tpl_stats[mi_row * src_stride + mi_col]; + int idx, idy; + + for (idy = 0; idy < mi_height; ++idy) { + for (idx = 0; idx < mi_width; ++idx) { + if (mi_row + idy >= mi_rows || mi_col + idx >= mi_cols) continue; + VpxTplBlockStats *tpl_block_stats_ptr = + &tpl_block_stats[(mi_row + idy) * mi_cols + mi_col + idx]; + tpl_block_stats_ptr->row = mi_row * 8 + idy * 8; + tpl_block_stats_ptr->col = mi_col * 8 + idx * 8; + tpl_block_stats_ptr->inter_cost = src_stats->inter_cost; + tpl_block_stats_ptr->intra_cost = src_stats->intra_cost; + // inter/intra_cost here is calculated with SATD which should be close + // enough to be used as inter/intra_pred_error + tpl_block_stats_ptr->inter_pred_err = src_stats->inter_cost; + tpl_block_stats_ptr->intra_pred_err = src_stats->intra_cost; + tpl_block_stats_ptr->srcrf_dist = recon_error << TPL_DEP_COST_SCALE_LOG2; + tpl_block_stats_ptr->srcrf_rate = rate_cost << TPL_DEP_COST_SCALE_LOG2; + tpl_block_stats_ptr->pred_error = pred_error << TPL_DEP_COST_SCALE_LOG2; + tpl_block_stats_ptr->mv_r = (src_stats->mv.as_mv.row >= 0 ? 1 : -1) * + (abs(src_stats->mv.as_mv.row) + 4) / 8; + tpl_block_stats_ptr->mv_c = (src_stats->mv.as_mv.col >= 0 ? 1 : -1) * + (abs(src_stats->mv.as_mv.col) + 4) / 8; + tpl_block_stats_ptr->ref_frame_index = ref_frame_idx; + } + } +} + +static void tpl_model_update_b(TplDepFrame *tpl_frame, TplDepStats *tpl_stats, + int mi_row, int mi_col, const BLOCK_SIZE bsize) { + if (tpl_stats->ref_frame_index < 0) return; + + TplDepFrame *ref_tpl_frame = &tpl_frame[tpl_stats->ref_frame_index]; + TplDepStats *ref_stats = ref_tpl_frame->tpl_stats_ptr; + MV mv = tpl_stats->mv.as_mv; + int mv_row = mv.row >> 3; + int mv_col = mv.col >> 3; + + int ref_pos_row = mi_row * MI_SIZE + mv_row; + int ref_pos_col = mi_col * MI_SIZE + mv_col; + + const int bw = 4 << b_width_log2_lookup[bsize]; + const int bh = 4 << b_height_log2_lookup[bsize]; + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + const int pix_num = bw * bh; + + // top-left on grid block location in pixel + int grid_pos_row_base = round_floor(ref_pos_row, bh) * bh; + int grid_pos_col_base = round_floor(ref_pos_col, bw) * bw; + int block; + + for (block = 0; block < 4; ++block) { + int grid_pos_row = grid_pos_row_base + bh * (block >> 1); + int grid_pos_col = grid_pos_col_base + bw * (block & 0x01); + + if (grid_pos_row >= 0 && grid_pos_row < ref_tpl_frame->mi_rows * MI_SIZE && + grid_pos_col >= 0 && grid_pos_col < ref_tpl_frame->mi_cols * MI_SIZE) { + int overlap_area = get_overlap_area( + grid_pos_row, grid_pos_col, ref_pos_row, ref_pos_col, block, bsize); + int ref_mi_row = round_floor(grid_pos_row, bh) * mi_height; + int ref_mi_col = round_floor(grid_pos_col, bw) * mi_width; + + int64_t mc_flow = tpl_stats->mc_dep_cost - + (tpl_stats->mc_dep_cost * tpl_stats->inter_cost) / + tpl_stats->intra_cost; + + int idx, idy; + + for (idy = 0; idy < mi_height; ++idy) { + for (idx = 0; idx < mi_width; ++idx) { + TplDepStats *des_stats = + &ref_stats[(ref_mi_row + idy) * ref_tpl_frame->stride + + (ref_mi_col + idx)]; + + des_stats->mc_flow += (mc_flow * overlap_area) / pix_num; + des_stats->mc_ref_cost += + ((tpl_stats->intra_cost - tpl_stats->inter_cost) * overlap_area) / + pix_num; + assert(overlap_area >= 0); + } + } + } + } +} + +static void tpl_model_update(TplDepFrame *tpl_frame, TplDepStats *tpl_stats, + int mi_row, int mi_col, const BLOCK_SIZE bsize) { + int idx, idy; + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + + for (idy = 0; idy < mi_height; ++idy) { + for (idx = 0; idx < mi_width; ++idx) { + TplDepStats *tpl_ptr = + &tpl_stats[(mi_row + idy) * tpl_frame->stride + (mi_col + idx)]; + tpl_model_update_b(tpl_frame, tpl_ptr, mi_row + idy, mi_col + idx, + BLOCK_8X8); + } + } +} + +static void get_quantize_error(MACROBLOCK *x, int plane, tran_low_t *coeff, + tran_low_t *qcoeff, tran_low_t *dqcoeff, + TX_SIZE tx_size, int64_t *recon_error, + int64_t *sse, uint16_t *eob) { + MACROBLOCKD *const xd = &x->e_mbd; + const struct macroblock_plane *const p = &x->plane[plane]; + const struct macroblockd_plane *const pd = &xd->plane[plane]; + const ScanOrder *const scan_order = &vp9_default_scan_orders[tx_size]; + int pix_num = 1 << num_pels_log2_lookup[txsize_to_bsize[tx_size]]; + const int shift = tx_size == TX_32X32 ? 0 : 2; + + // skip block condition should be handled before this is called. + assert(!x->skip_block); + +#if CONFIG_VP9_HIGHBITDEPTH + if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { + vp9_highbd_quantize_fp_32x32(coeff, pix_num, p, qcoeff, dqcoeff, + pd->dequant, eob, scan_order); + } else { + vp9_quantize_fp_32x32(coeff, pix_num, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); + } +#else + vp9_quantize_fp_32x32(coeff, pix_num, p, qcoeff, dqcoeff, pd->dequant, eob, + scan_order); +#endif // CONFIG_VP9_HIGHBITDEPTH + + *recon_error = vp9_block_error(coeff, dqcoeff, pix_num, sse) >> shift; + *recon_error = VPXMAX(*recon_error, 1); + + *sse = (*sse) >> shift; + *sse = VPXMAX(*sse, 1); +} + +#if CONFIG_VP9_HIGHBITDEPTH +void vp9_highbd_wht_fwd_txfm(int16_t *src_diff, int bw, tran_low_t *coeff, + TX_SIZE tx_size) { + // TODO(sdeng): Implement SIMD based high bit-depth Hadamard transforms. + switch (tx_size) { + case TX_8X8: vpx_highbd_hadamard_8x8(src_diff, bw, coeff); break; + case TX_16X16: vpx_highbd_hadamard_16x16(src_diff, bw, coeff); break; + case TX_32X32: vpx_highbd_hadamard_32x32(src_diff, bw, coeff); break; + default: assert(0); + } +} +#endif // CONFIG_VP9_HIGHBITDEPTH + +void vp9_wht_fwd_txfm(int16_t *src_diff, int bw, tran_low_t *coeff, + TX_SIZE tx_size) { + switch (tx_size) { + case TX_8X8: vpx_hadamard_8x8(src_diff, bw, coeff); break; + case TX_16X16: vpx_hadamard_16x16(src_diff, bw, coeff); break; + case TX_32X32: vpx_hadamard_32x32(src_diff, bw, coeff); break; + default: assert(0); + } +} + +static void set_mv_limits(const VP9_COMMON *cm, MACROBLOCK *x, int mi_row, + int mi_col) { + x->mv_limits.row_min = -((mi_row * MI_SIZE) + (17 - 2 * VP9_INTERP_EXTEND)); + x->mv_limits.row_max = + (cm->mi_rows - 1 - mi_row) * MI_SIZE + (17 - 2 * VP9_INTERP_EXTEND); + x->mv_limits.col_min = -((mi_col * MI_SIZE) + (17 - 2 * VP9_INTERP_EXTEND)); + x->mv_limits.col_max = + ((cm->mi_cols - 1 - mi_col) * MI_SIZE) + (17 - 2 * VP9_INTERP_EXTEND); +} + +static int rate_estimator(const tran_low_t *qcoeff, int eob, TX_SIZE tx_size) { + const ScanOrder *const scan_order = &vp9_scan_orders[tx_size][DCT_DCT]; + int rate_cost = 1; + int idx; + assert((1 << num_pels_log2_lookup[txsize_to_bsize[tx_size]]) >= eob); + for (idx = 0; idx < eob; ++idx) { + unsigned int abs_level = abs(qcoeff[scan_order->scan[idx]]); + rate_cost += get_msb(abs_level + 1) + 1 + (abs_level > 0); + } + + return (rate_cost << VP9_PROB_COST_SHIFT); +} + +static void mode_estimation(VP9_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd, + struct scale_factors *sf, GF_PICTURE *gf_picture, + int frame_idx, TplDepFrame *tpl_frame, + int16_t *src_diff, tran_low_t *coeff, + tran_low_t *qcoeff, tran_low_t *dqcoeff, int mi_row, + int mi_col, BLOCK_SIZE bsize, TX_SIZE tx_size, + YV12_BUFFER_CONFIG *ref_frame[], uint8_t *predictor, + int64_t *recon_error, int64_t *rate_cost, + int64_t *sse, int *ref_frame_idx) { + VP9_COMMON *cm = &cpi->common; + ThreadData *td = &cpi->td; + + const int bw = 4 << b_width_log2_lookup[bsize]; + const int bh = 4 << b_height_log2_lookup[bsize]; + const int pix_num = bw * bh; + int best_rf_idx = -1; + int_mv best_mv; + int64_t best_inter_cost = INT64_MAX; + int64_t inter_cost; + int rf_idx; + const InterpKernel *const kernel = vp9_filter_kernels[EIGHTTAP]; + + int64_t best_intra_cost = INT64_MAX; + int64_t intra_cost; + PREDICTION_MODE mode; + int mb_y_offset = mi_row * MI_SIZE * xd->cur_buf->y_stride + mi_col * MI_SIZE; + MODE_INFO mi_above, mi_left; + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + TplDepStats *tpl_stats = + &tpl_frame->tpl_stats_ptr[mi_row * tpl_frame->stride + mi_col]; + + xd->mb_to_top_edge = -((mi_row * MI_SIZE) * 8); + xd->mb_to_bottom_edge = ((cm->mi_rows - 1 - mi_row) * MI_SIZE) * 8; + xd->mb_to_left_edge = -((mi_col * MI_SIZE) * 8); + xd->mb_to_right_edge = ((cm->mi_cols - 1 - mi_col) * MI_SIZE) * 8; + xd->above_mi = (mi_row > 0) ? &mi_above : NULL; + xd->left_mi = (mi_col > 0) ? &mi_left : NULL; + + // Intra prediction search + for (mode = DC_PRED; mode <= TM_PRED; ++mode) { + uint8_t *src, *dst; + int src_stride, dst_stride; + + src = xd->cur_buf->y_buffer + mb_y_offset; + src_stride = xd->cur_buf->y_stride; + + dst = &predictor[0]; + dst_stride = bw; + + xd->mi[0]->sb_type = bsize; + xd->mi[0]->ref_frame[0] = INTRA_FRAME; + + vp9_predict_intra_block(xd, b_width_log2_lookup[bsize], tx_size, mode, src, + src_stride, dst, dst_stride, 0, 0, 0); + +#if CONFIG_VP9_HIGHBITDEPTH + if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { + vpx_highbd_subtract_block(bh, bw, src_diff, bw, src, src_stride, dst, + dst_stride, xd->bd); + vp9_highbd_wht_fwd_txfm(src_diff, bw, coeff, tx_size); + intra_cost = vpx_highbd_satd(coeff, pix_num); + } else { + vpx_subtract_block(bh, bw, src_diff, bw, src, src_stride, dst, + dst_stride); + vp9_wht_fwd_txfm(src_diff, bw, coeff, tx_size); + intra_cost = vpx_satd(coeff, pix_num); + } +#else + vpx_subtract_block(bh, bw, src_diff, bw, src, src_stride, dst, dst_stride); + vp9_wht_fwd_txfm(src_diff, bw, coeff, tx_size); + intra_cost = vpx_satd(coeff, pix_num); +#endif // CONFIG_VP9_HIGHBITDEPTH + + if (intra_cost < best_intra_cost) best_intra_cost = intra_cost; + } + + // Motion compensated prediction + best_mv.as_int = 0; + + set_mv_limits(cm, x, mi_row, mi_col); + + for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { + int_mv mv; +#if CONFIG_NON_GREEDY_MV + MotionField *motion_field; +#endif + if (ref_frame[rf_idx] == NULL) continue; + +#if CONFIG_NON_GREEDY_MV + (void)td; + motion_field = vp9_motion_field_info_get_motion_field( + &cpi->motion_field_info, frame_idx, rf_idx, bsize); + mv = vp9_motion_field_mi_get_mv(motion_field, mi_row, mi_col); +#else + motion_compensated_prediction(cpi, td, xd->cur_buf->y_buffer + mb_y_offset, + ref_frame[rf_idx]->y_buffer + mb_y_offset, + xd->cur_buf->y_stride, bsize, &mv.as_mv); +#endif + +#if CONFIG_VP9_HIGHBITDEPTH + if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { + vp9_highbd_build_inter_predictor( + CONVERT_TO_SHORTPTR(ref_frame[rf_idx]->y_buffer + mb_y_offset), + ref_frame[rf_idx]->y_stride, CONVERT_TO_SHORTPTR(&predictor[0]), bw, + &mv.as_mv, sf, bw, bh, 0, kernel, MV_PRECISION_Q3, mi_col * MI_SIZE, + mi_row * MI_SIZE, xd->bd); + vpx_highbd_subtract_block( + bh, bw, src_diff, bw, xd->cur_buf->y_buffer + mb_y_offset, + xd->cur_buf->y_stride, &predictor[0], bw, xd->bd); + vp9_highbd_wht_fwd_txfm(src_diff, bw, coeff, tx_size); + inter_cost = vpx_highbd_satd(coeff, pix_num); + } else { + vp9_build_inter_predictor( + ref_frame[rf_idx]->y_buffer + mb_y_offset, + ref_frame[rf_idx]->y_stride, &predictor[0], bw, &mv.as_mv, sf, bw, bh, + 0, kernel, MV_PRECISION_Q3, mi_col * MI_SIZE, mi_row * MI_SIZE); + vpx_subtract_block(bh, bw, src_diff, bw, + xd->cur_buf->y_buffer + mb_y_offset, + xd->cur_buf->y_stride, &predictor[0], bw); + vp9_wht_fwd_txfm(src_diff, bw, coeff, tx_size); + inter_cost = vpx_satd(coeff, pix_num); + } +#else + vp9_build_inter_predictor(ref_frame[rf_idx]->y_buffer + mb_y_offset, + ref_frame[rf_idx]->y_stride, &predictor[0], bw, + &mv.as_mv, sf, bw, bh, 0, kernel, MV_PRECISION_Q3, + mi_col * MI_SIZE, mi_row * MI_SIZE); + vpx_subtract_block(bh, bw, src_diff, bw, + xd->cur_buf->y_buffer + mb_y_offset, + xd->cur_buf->y_stride, &predictor[0], bw); + vp9_wht_fwd_txfm(src_diff, bw, coeff, tx_size); + inter_cost = vpx_satd(coeff, pix_num); +#endif + + if (inter_cost < best_inter_cost) { + uint16_t eob = 0; + best_rf_idx = rf_idx; + best_inter_cost = inter_cost; + best_mv.as_int = mv.as_int; + // Since best_inter_cost is initialized as INT64_MAX, recon_error and + // rate_cost will be calculated with the best reference frame. + get_quantize_error(x, 0, coeff, qcoeff, dqcoeff, tx_size, recon_error, + sse, &eob); + *rate_cost = rate_estimator(qcoeff, eob, tx_size); + } + } + best_intra_cost = VPXMAX(best_intra_cost, 1); + best_inter_cost = VPXMIN(best_intra_cost, best_inter_cost); + tpl_stats->inter_cost = VPXMAX( + 1, (best_inter_cost << TPL_DEP_COST_SCALE_LOG2) / (mi_height * mi_width)); + tpl_stats->intra_cost = VPXMAX( + 1, (best_intra_cost << TPL_DEP_COST_SCALE_LOG2) / (mi_height * mi_width)); + if (best_rf_idx >= 0) { + tpl_stats->ref_frame_index = gf_picture[frame_idx].ref_frame[best_rf_idx]; + } + tpl_stats->mv.as_int = best_mv.as_int; + *ref_frame_idx = best_rf_idx; +} + +#if CONFIG_NON_GREEDY_MV +static int get_block_src_pred_buf(MACROBLOCKD *xd, GF_PICTURE *gf_picture, + int frame_idx, int rf_idx, int mi_row, + int mi_col, struct buf_2d *src, + struct buf_2d *pre) { + const int mb_y_offset = + mi_row * MI_SIZE * xd->cur_buf->y_stride + mi_col * MI_SIZE; + YV12_BUFFER_CONFIG *ref_frame = NULL; + int ref_frame_idx = gf_picture[frame_idx].ref_frame[rf_idx]; + if (ref_frame_idx != -1) { + ref_frame = gf_picture[ref_frame_idx].frame; + src->buf = xd->cur_buf->y_buffer + mb_y_offset; + src->stride = xd->cur_buf->y_stride; + pre->buf = ref_frame->y_buffer + mb_y_offset; + pre->stride = ref_frame->y_stride; + assert(src->stride == pre->stride); + return 1; + } else { + printf("invalid ref_frame_idx"); + assert(ref_frame_idx != -1); + return 0; + } +} + +#define kMvPreCheckLines 5 +#define kMvPreCheckSize 15 + +#define MV_REF_POS_NUM 3 +POSITION mv_ref_pos[MV_REF_POS_NUM] = { + { -1, 0 }, + { 0, -1 }, + { -1, -1 }, +}; + +static int_mv *get_select_mv(VP9_COMP *cpi, TplDepFrame *tpl_frame, int mi_row, + int mi_col) { + return &cpi->select_mv_arr[mi_row * tpl_frame->stride + mi_col]; +} + +static int_mv find_ref_mv(int mv_mode, VP9_COMP *cpi, TplDepFrame *tpl_frame, + BLOCK_SIZE bsize, int mi_row, int mi_col) { + int i; + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + int_mv nearest_mv, near_mv, invalid_mv; + nearest_mv.as_int = INVALID_MV; + near_mv.as_int = INVALID_MV; + invalid_mv.as_int = INVALID_MV; + for (i = 0; i < MV_REF_POS_NUM; ++i) { + int nb_row = mi_row + mv_ref_pos[i].row * mi_height; + int nb_col = mi_col + mv_ref_pos[i].col * mi_width; + assert(mv_ref_pos[i].row <= 0); + assert(mv_ref_pos[i].col <= 0); + if (nb_row >= 0 && nb_col >= 0) { + if (nearest_mv.as_int == INVALID_MV) { + nearest_mv = *get_select_mv(cpi, tpl_frame, nb_row, nb_col); + } else { + int_mv mv = *get_select_mv(cpi, tpl_frame, nb_row, nb_col); + if (mv.as_int == nearest_mv.as_int) { + continue; + } else { + near_mv = mv; + break; + } + } + } + } + if (nearest_mv.as_int == INVALID_MV) { + nearest_mv.as_mv.row = 0; + nearest_mv.as_mv.col = 0; + } + if (near_mv.as_int == INVALID_MV) { + near_mv.as_mv.row = 0; + near_mv.as_mv.col = 0; + } + if (mv_mode == NEAREST_MV_MODE) { + return nearest_mv; + } + if (mv_mode == NEAR_MV_MODE) { + return near_mv; + } + assert(0); + return invalid_mv; +} + +static int_mv get_mv_from_mv_mode(int mv_mode, VP9_COMP *cpi, + MotionField *motion_field, + TplDepFrame *tpl_frame, BLOCK_SIZE bsize, + int mi_row, int mi_col) { + int_mv mv; + switch (mv_mode) { + case ZERO_MV_MODE: + mv.as_mv.row = 0; + mv.as_mv.col = 0; + break; + case NEW_MV_MODE: + mv = vp9_motion_field_mi_get_mv(motion_field, mi_row, mi_col); + break; + case NEAREST_MV_MODE: + mv = find_ref_mv(mv_mode, cpi, tpl_frame, bsize, mi_row, mi_col); + break; + case NEAR_MV_MODE: + mv = find_ref_mv(mv_mode, cpi, tpl_frame, bsize, mi_row, mi_col); + break; + default: + mv.as_int = INVALID_MV; + assert(0); + break; + } + return mv; +} + +static double get_mv_dist(int mv_mode, VP9_COMP *cpi, MACROBLOCKD *xd, + GF_PICTURE *gf_picture, MotionField *motion_field, + int frame_idx, TplDepFrame *tpl_frame, int rf_idx, + BLOCK_SIZE bsize, int mi_row, int mi_col, + int_mv *mv) { + uint32_t sse; + struct buf_2d src; + struct buf_2d pre; + MV full_mv; + *mv = get_mv_from_mv_mode(mv_mode, cpi, motion_field, tpl_frame, bsize, + mi_row, mi_col); + full_mv = get_full_mv(&mv->as_mv); + if (get_block_src_pred_buf(xd, gf_picture, frame_idx, rf_idx, mi_row, mi_col, + &src, &pre)) { + // TODO(angiebird): Consider subpixel when computing the sse. + cpi->fn_ptr[bsize].vf(src.buf, src.stride, get_buf_from_mv(&pre, &full_mv), + pre.stride, &sse); + return (double)(sse << VP9_DIST_SCALE_LOG2); + } else { + assert(0); + return 0; + } +} + +static int get_mv_mode_cost(int mv_mode) { + // TODO(angiebird): The probabilities are roughly inferred from + // default_inter_mode_probs. Check if there is a better way to set the + // probabilities. + const int zero_mv_prob = 16; + const int new_mv_prob = 24 * 1; + const int ref_mv_prob = 256 - zero_mv_prob - new_mv_prob; + assert(zero_mv_prob + new_mv_prob + ref_mv_prob == 256); + switch (mv_mode) { + case ZERO_MV_MODE: return vp9_prob_cost[zero_mv_prob]; break; + case NEW_MV_MODE: return vp9_prob_cost[new_mv_prob]; break; + case NEAREST_MV_MODE: return vp9_prob_cost[ref_mv_prob]; break; + case NEAR_MV_MODE: return vp9_prob_cost[ref_mv_prob]; break; + default: assert(0); return -1; + } +} + +static INLINE double get_mv_diff_cost(MV *new_mv, MV *ref_mv) { + double mv_diff_cost = log2(1 + abs(new_mv->row - ref_mv->row)) + + log2(1 + abs(new_mv->col - ref_mv->col)); + mv_diff_cost *= (1 << VP9_PROB_COST_SHIFT); + return mv_diff_cost; +} +static double get_mv_cost(int mv_mode, VP9_COMP *cpi, MotionField *motion_field, + TplDepFrame *tpl_frame, BLOCK_SIZE bsize, int mi_row, + int mi_col) { + double mv_cost = get_mv_mode_cost(mv_mode); + if (mv_mode == NEW_MV_MODE) { + MV new_mv = get_mv_from_mv_mode(mv_mode, cpi, motion_field, tpl_frame, + bsize, mi_row, mi_col) + .as_mv; + MV nearest_mv = get_mv_from_mv_mode(NEAREST_MV_MODE, cpi, motion_field, + tpl_frame, bsize, mi_row, mi_col) + .as_mv; + MV near_mv = get_mv_from_mv_mode(NEAR_MV_MODE, cpi, motion_field, tpl_frame, + bsize, mi_row, mi_col) + .as_mv; + double nearest_cost = get_mv_diff_cost(&new_mv, &nearest_mv); + double near_cost = get_mv_diff_cost(&new_mv, &near_mv); + mv_cost += nearest_cost < near_cost ? nearest_cost : near_cost; + } + return mv_cost; +} + +static double eval_mv_mode(int mv_mode, VP9_COMP *cpi, MACROBLOCK *x, + GF_PICTURE *gf_picture, MotionField *motion_field, + int frame_idx, TplDepFrame *tpl_frame, int rf_idx, + BLOCK_SIZE bsize, int mi_row, int mi_col, + int_mv *mv) { + MACROBLOCKD *xd = &x->e_mbd; + double mv_dist = + get_mv_dist(mv_mode, cpi, xd, gf_picture, motion_field, frame_idx, + tpl_frame, rf_idx, bsize, mi_row, mi_col, mv); + double mv_cost = + get_mv_cost(mv_mode, cpi, motion_field, tpl_frame, bsize, mi_row, mi_col); + double mult = 180; + + return mv_cost + mult * log2f(1 + mv_dist); +} + +static int find_best_ref_mv_mode(VP9_COMP *cpi, MACROBLOCK *x, + GF_PICTURE *gf_picture, + MotionField *motion_field, int frame_idx, + TplDepFrame *tpl_frame, int rf_idx, + BLOCK_SIZE bsize, int mi_row, int mi_col, + double *rd, int_mv *mv) { + int best_mv_mode = ZERO_MV_MODE; + int update = 0; + int mv_mode; + *rd = 0; + for (mv_mode = 0; mv_mode < MAX_MV_MODE; ++mv_mode) { + double this_rd; + int_mv this_mv; + if (mv_mode == NEW_MV_MODE) { + continue; + } + this_rd = eval_mv_mode(mv_mode, cpi, x, gf_picture, motion_field, frame_idx, + tpl_frame, rf_idx, bsize, mi_row, mi_col, &this_mv); + if (update == 0) { + *rd = this_rd; + *mv = this_mv; + best_mv_mode = mv_mode; + update = 1; + } else { + if (this_rd < *rd) { + *rd = this_rd; + *mv = this_mv; + best_mv_mode = mv_mode; + } + } + } + return best_mv_mode; +} + +static void predict_mv_mode(VP9_COMP *cpi, MACROBLOCK *x, + GF_PICTURE *gf_picture, MotionField *motion_field, + int frame_idx, TplDepFrame *tpl_frame, int rf_idx, + BLOCK_SIZE bsize, int mi_row, int mi_col) { + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + int tmp_mv_mode_arr[kMvPreCheckSize]; + int *mv_mode_arr = tpl_frame->mv_mode_arr[rf_idx]; + double *rd_diff_arr = tpl_frame->rd_diff_arr[rf_idx]; + int_mv *select_mv_arr = cpi->select_mv_arr; + int_mv tmp_select_mv_arr[kMvPreCheckSize]; + int stride = tpl_frame->stride; + double new_mv_rd = 0; + double no_new_mv_rd = 0; + double this_new_mv_rd = 0; + double this_no_new_mv_rd = 0; + int idx; + int tmp_idx; + assert(kMvPreCheckSize == (kMvPreCheckLines * (kMvPreCheckLines + 1)) >> 1); + + // no new mv + // diagonal scan order + tmp_idx = 0; + for (idx = 0; idx < kMvPreCheckLines; ++idx) { + int r; + for (r = 0; r <= idx; ++r) { + int c = idx - r; + int nb_row = mi_row + r * mi_height; + int nb_col = mi_col + c * mi_width; + if (nb_row < tpl_frame->mi_rows && nb_col < tpl_frame->mi_cols) { + double this_rd; + int_mv *mv = &select_mv_arr[nb_row * stride + nb_col]; + mv_mode_arr[nb_row * stride + nb_col] = find_best_ref_mv_mode( + cpi, x, gf_picture, motion_field, frame_idx, tpl_frame, rf_idx, + bsize, nb_row, nb_col, &this_rd, mv); + if (r == 0 && c == 0) { + this_no_new_mv_rd = this_rd; + } + no_new_mv_rd += this_rd; + tmp_mv_mode_arr[tmp_idx] = mv_mode_arr[nb_row * stride + nb_col]; + tmp_select_mv_arr[tmp_idx] = select_mv_arr[nb_row * stride + nb_col]; + ++tmp_idx; + } + } + } + + // new mv + mv_mode_arr[mi_row * stride + mi_col] = NEW_MV_MODE; + this_new_mv_rd = eval_mv_mode( + NEW_MV_MODE, cpi, x, gf_picture, motion_field, frame_idx, tpl_frame, + rf_idx, bsize, mi_row, mi_col, &select_mv_arr[mi_row * stride + mi_col]); + new_mv_rd = this_new_mv_rd; + // We start from idx = 1 because idx = 0 is evaluated as NEW_MV_MODE + // beforehand. + for (idx = 1; idx < kMvPreCheckLines; ++idx) { + int r; + for (r = 0; r <= idx; ++r) { + int c = idx - r; + int nb_row = mi_row + r * mi_height; + int nb_col = mi_col + c * mi_width; + if (nb_row < tpl_frame->mi_rows && nb_col < tpl_frame->mi_cols) { + double this_rd; + int_mv *mv = &select_mv_arr[nb_row * stride + nb_col]; + mv_mode_arr[nb_row * stride + nb_col] = find_best_ref_mv_mode( + cpi, x, gf_picture, motion_field, frame_idx, tpl_frame, rf_idx, + bsize, nb_row, nb_col, &this_rd, mv); + new_mv_rd += this_rd; + } + } + } + + // update best_mv_mode + tmp_idx = 0; + if (no_new_mv_rd < new_mv_rd) { + for (idx = 0; idx < kMvPreCheckLines; ++idx) { + int r; + for (r = 0; r <= idx; ++r) { + int c = idx - r; + int nb_row = mi_row + r * mi_height; + int nb_col = mi_col + c * mi_width; + if (nb_row < tpl_frame->mi_rows && nb_col < tpl_frame->mi_cols) { + mv_mode_arr[nb_row * stride + nb_col] = tmp_mv_mode_arr[tmp_idx]; + select_mv_arr[nb_row * stride + nb_col] = tmp_select_mv_arr[tmp_idx]; + ++tmp_idx; + } + } + } + rd_diff_arr[mi_row * stride + mi_col] = 0; + } else { + rd_diff_arr[mi_row * stride + mi_col] = + (no_new_mv_rd - this_no_new_mv_rd) - (new_mv_rd - this_new_mv_rd); + } +} + +static void predict_mv_mode_arr(VP9_COMP *cpi, MACROBLOCK *x, + GF_PICTURE *gf_picture, + MotionField *motion_field, int frame_idx, + TplDepFrame *tpl_frame, int rf_idx, + BLOCK_SIZE bsize) { + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + const int unit_rows = tpl_frame->mi_rows / mi_height; + const int unit_cols = tpl_frame->mi_cols / mi_width; + const int max_diagonal_lines = unit_rows + unit_cols - 1; + int idx; + for (idx = 0; idx < max_diagonal_lines; ++idx) { + int r; + for (r = VPXMAX(idx - unit_cols + 1, 0); r <= VPXMIN(idx, unit_rows - 1); + ++r) { + int c = idx - r; + int mi_row = r * mi_height; + int mi_col = c * mi_width; + assert(c >= 0 && c < unit_cols); + assert(mi_row >= 0 && mi_row < tpl_frame->mi_rows); + assert(mi_col >= 0 && mi_col < tpl_frame->mi_cols); + predict_mv_mode(cpi, x, gf_picture, motion_field, frame_idx, tpl_frame, + rf_idx, bsize, mi_row, mi_col); + } + } +} + +static void do_motion_search(VP9_COMP *cpi, ThreadData *td, + MotionField *motion_field, int frame_idx, + YV12_BUFFER_CONFIG *ref_frame, BLOCK_SIZE bsize, + int mi_row, int mi_col) { + VP9_COMMON *cm = &cpi->common; + MACROBLOCK *x = &td->mb; + MACROBLOCKD *xd = &x->e_mbd; + const int mb_y_offset = + mi_row * MI_SIZE * xd->cur_buf->y_stride + mi_col * MI_SIZE; + assert(ref_frame != NULL); + set_mv_limits(cm, x, mi_row, mi_col); + { + int_mv mv = vp9_motion_field_mi_get_mv(motion_field, mi_row, mi_col); + uint8_t *cur_frame_buf = xd->cur_buf->y_buffer + mb_y_offset; + uint8_t *ref_frame_buf = ref_frame->y_buffer + mb_y_offset; + const int stride = xd->cur_buf->y_stride; + full_pixel_motion_search(cpi, td, motion_field, frame_idx, cur_frame_buf, + ref_frame_buf, stride, bsize, mi_row, mi_col, + &mv.as_mv); + sub_pixel_motion_search(cpi, td, cur_frame_buf, ref_frame_buf, stride, + bsize, &mv.as_mv); + vp9_motion_field_mi_set_mv(motion_field, mi_row, mi_col, mv); + } +} + +static void build_motion_field( + VP9_COMP *cpi, int frame_idx, + YV12_BUFFER_CONFIG *ref_frame[MAX_INTER_REF_FRAMES], BLOCK_SIZE bsize) { + VP9_COMMON *cm = &cpi->common; + ThreadData *td = &cpi->td; + TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx]; + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + const int pw = num_4x4_blocks_wide_lookup[bsize] << 2; + const int ph = num_4x4_blocks_high_lookup[bsize] << 2; + int mi_row, mi_col; + int rf_idx; + + tpl_frame->lambda = (pw * ph) >> 2; + assert(pw * ph == tpl_frame->lambda << 2); + + for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { + MotionField *motion_field = vp9_motion_field_info_get_motion_field( + &cpi->motion_field_info, frame_idx, rf_idx, bsize); + if (ref_frame[rf_idx] == NULL) { + continue; + } + vp9_motion_field_reset_mvs(motion_field); + for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) { + for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) { + do_motion_search(cpi, td, motion_field, frame_idx, ref_frame[rf_idx], + bsize, mi_row, mi_col); + } + } + } +} +#endif // CONFIG_NON_GREEDY_MV + +static void mc_flow_dispenser(VP9_COMP *cpi, GF_PICTURE *gf_picture, + int frame_idx, BLOCK_SIZE bsize) { + TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx]; + VpxTplFrameStats *tpl_frame_stats_before_propagation = + &cpi->tpl_gop_stats.frame_stats_list[frame_idx]; + YV12_BUFFER_CONFIG *this_frame = gf_picture[frame_idx].frame; + YV12_BUFFER_CONFIG *ref_frame[MAX_INTER_REF_FRAMES] = { NULL, NULL, NULL }; + + VP9_COMMON *cm = &cpi->common; + struct scale_factors sf; + int rdmult, idx; + ThreadData *td = &cpi->td; + MACROBLOCK *x = &td->mb; + MACROBLOCKD *xd = &x->e_mbd; + int mi_row, mi_col; + +#if CONFIG_VP9_HIGHBITDEPTH + DECLARE_ALIGNED(16, uint16_t, predictor16[32 * 32 * 3]); + DECLARE_ALIGNED(16, uint8_t, predictor8[32 * 32 * 3]); + uint8_t *predictor; +#else + DECLARE_ALIGNED(16, uint8_t, predictor[32 * 32 * 3]); +#endif + DECLARE_ALIGNED(16, int16_t, src_diff[32 * 32]); + DECLARE_ALIGNED(16, tran_low_t, coeff[32 * 32]); + DECLARE_ALIGNED(16, tran_low_t, qcoeff[32 * 32]); + DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]); + + const TX_SIZE tx_size = max_txsize_lookup[bsize]; + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + + tpl_frame_stats_before_propagation->frame_width = cm->width; + tpl_frame_stats_before_propagation->frame_height = cm->height; + // Setup scaling factor +#if CONFIG_VP9_HIGHBITDEPTH + vp9_setup_scale_factors_for_frame( + &sf, this_frame->y_crop_width, this_frame->y_crop_height, + this_frame->y_crop_width, this_frame->y_crop_height, + cpi->common.use_highbitdepth); + + // Note: xd->cur_buf is not set up yet at this point. It may even be NULL if + // TPL runs before any frame is encoded. Use this_frame instead. + if (this_frame->flags & YV12_FLAG_HIGHBITDEPTH) + predictor = CONVERT_TO_BYTEPTR(predictor16); + else + predictor = predictor8; +#else + vp9_setup_scale_factors_for_frame( + &sf, this_frame->y_crop_width, this_frame->y_crop_height, + this_frame->y_crop_width, this_frame->y_crop_height); +#endif // CONFIG_VP9_HIGHBITDEPTH + + // Prepare reference frame pointers. If any reference frame slot is + // unavailable, the pointer will be set to Null. + for (idx = 0; idx < MAX_INTER_REF_FRAMES; ++idx) { + int rf_idx = gf_picture[frame_idx].ref_frame[idx]; + if (rf_idx != -REFS_PER_FRAME) ref_frame[idx] = gf_picture[rf_idx].frame; + } + + xd->mi = cm->mi_grid_visible; + xd->mi[0] = cm->mi; + xd->cur_buf = this_frame; + + // Get rd multiplier set up. + rdmult = vp9_compute_rd_mult_based_on_qindex(cpi, tpl_frame->base_qindex); + set_error_per_bit(&cpi->td.mb, rdmult); + vp9_initialize_me_consts(cpi, &cpi->td.mb, tpl_frame->base_qindex); + + tpl_frame->is_valid = 1; + + cm->base_qindex = tpl_frame->base_qindex; + vp9_frame_init_quantizer(cpi); + +#if CONFIG_NON_GREEDY_MV + { + int square_block_idx; + int rf_idx; + for (square_block_idx = 0; square_block_idx < SQUARE_BLOCK_SIZES; + ++square_block_idx) { + BLOCK_SIZE square_bsize = square_block_idx_to_bsize(square_block_idx); + build_motion_field(cpi, frame_idx, ref_frame, square_bsize); + } + for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { + int ref_frame_idx = gf_picture[frame_idx].ref_frame[rf_idx]; + if (ref_frame_idx != -1) { + MotionField *motion_field = vp9_motion_field_info_get_motion_field( + &cpi->motion_field_info, frame_idx, rf_idx, bsize); + predict_mv_mode_arr(cpi, x, gf_picture, motion_field, frame_idx, + tpl_frame, rf_idx, bsize); + } + } + } +#endif // CONFIG_NON_GREEDY_MV + + for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) { + for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) { + int64_t recon_error = 0; + int64_t rate_cost = 0; + int64_t sse = 0; + // Ref frame index in the ref frame buffer. + int ref_frame_idx = -1; + mode_estimation(cpi, x, xd, &sf, gf_picture, frame_idx, tpl_frame, + src_diff, coeff, qcoeff, dqcoeff, mi_row, mi_col, bsize, + tx_size, ref_frame, predictor, &recon_error, &rate_cost, + &sse, &ref_frame_idx); + // Motion flow dependency dispenser. + tpl_model_store(tpl_frame->tpl_stats_ptr, mi_row, mi_col, bsize, + tpl_frame->stride); + + tpl_store_before_propagation( + tpl_frame_stats_before_propagation->block_stats_list, + tpl_frame->tpl_stats_ptr, mi_row, mi_col, bsize, tpl_frame->stride, + recon_error, sse, rate_cost, ref_frame_idx, tpl_frame->mi_rows, + tpl_frame->mi_cols); + + tpl_model_update(cpi->tpl_stats, tpl_frame->tpl_stats_ptr, mi_row, mi_col, + bsize); + } + } +} + +static void trim_tpl_stats(struct vpx_internal_error_info *error_info, + VpxTplGopStats *tpl_gop_stats, int extra_frames) { + int i; + VpxTplFrameStats *new_frame_stats; + const int new_size = tpl_gop_stats->size - extra_frames; + if (tpl_gop_stats->size <= extra_frames) + vpx_internal_error( + error_info, VPX_CODEC_ERROR, + "The number of frames in VpxTplGopStats is fewer than expected."); + CHECK_MEM_ERROR(error_info, new_frame_stats, + vpx_calloc(new_size, sizeof(*new_frame_stats))); + for (i = 0; i < new_size; i++) { + VpxTplFrameStats *frame_stats = &tpl_gop_stats->frame_stats_list[i]; + const int num_blocks = frame_stats->num_blocks; + new_frame_stats[i].num_blocks = frame_stats->num_blocks; + new_frame_stats[i].frame_width = frame_stats->frame_width; + new_frame_stats[i].frame_height = frame_stats->frame_height; + new_frame_stats[i].num_blocks = num_blocks; + CHECK_MEM_ERROR( + error_info, new_frame_stats[i].block_stats_list, + vpx_calloc(num_blocks, sizeof(*new_frame_stats[i].block_stats_list))); + memcpy(new_frame_stats[i].block_stats_list, frame_stats->block_stats_list, + num_blocks * sizeof(*new_frame_stats[i].block_stats_list)); + } + free_tpl_frame_stats_list(tpl_gop_stats); + tpl_gop_stats->size = new_size; + tpl_gop_stats->frame_stats_list = new_frame_stats; +} + +#if CONFIG_NON_GREEDY_MV +#define DUMP_TPL_STATS 0 +#if DUMP_TPL_STATS +static void dump_buf(uint8_t *buf, int stride, int row, int col, int h, int w) { + int i, j; + printf("%d %d\n", h, w); + for (i = 0; i < h; ++i) { + for (j = 0; j < w; ++j) { + printf("%d ", buf[(row + i) * stride + col + j]); + } + } + printf("\n"); +} + +static void dump_frame_buf(const YV12_BUFFER_CONFIG *frame_buf) { + dump_buf(frame_buf->y_buffer, frame_buf->y_stride, 0, 0, frame_buf->y_height, + frame_buf->y_width); + dump_buf(frame_buf->u_buffer, frame_buf->uv_stride, 0, 0, + frame_buf->uv_height, frame_buf->uv_width); + dump_buf(frame_buf->v_buffer, frame_buf->uv_stride, 0, 0, + frame_buf->uv_height, frame_buf->uv_width); +} + +static void dump_tpl_stats(const VP9_COMP *cpi, int tpl_group_frames, + const GF_GROUP *gf_group, + const GF_PICTURE *gf_picture, BLOCK_SIZE bsize) { + int frame_idx; + const VP9_COMMON *cm = &cpi->common; + int rf_idx; + for (frame_idx = 1; frame_idx < tpl_group_frames; ++frame_idx) { + for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { + const TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx]; + int mi_row, mi_col; + int ref_frame_idx; + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + ref_frame_idx = gf_picture[frame_idx].ref_frame[rf_idx]; + if (ref_frame_idx != -1) { + YV12_BUFFER_CONFIG *ref_frame_buf = gf_picture[ref_frame_idx].frame; + const int gf_frame_offset = gf_group->frame_gop_index[frame_idx]; + const int ref_gf_frame_offset = + gf_group->frame_gop_index[ref_frame_idx]; + printf("=\n"); + printf( + "frame_idx %d mi_rows %d mi_cols %d bsize %d ref_frame_idx %d " + "rf_idx %d gf_frame_offset %d ref_gf_frame_offset %d\n", + frame_idx, cm->mi_rows, cm->mi_cols, mi_width * MI_SIZE, + ref_frame_idx, rf_idx, gf_frame_offset, ref_gf_frame_offset); + for (mi_row = 0; mi_row < cm->mi_rows; ++mi_row) { + for (mi_col = 0; mi_col < cm->mi_cols; ++mi_col) { + if ((mi_row % mi_height) == 0 && (mi_col % mi_width) == 0) { + int_mv mv = vp9_motion_field_info_get_mv(&cpi->motion_field_info, + frame_idx, rf_idx, bsize, + mi_row, mi_col); + printf("%d %d %d %d\n", mi_row, mi_col, mv.as_mv.row, + mv.as_mv.col); + } + } + } + for (mi_row = 0; mi_row < cm->mi_rows; ++mi_row) { + for (mi_col = 0; mi_col < cm->mi_cols; ++mi_col) { + if ((mi_row % mi_height) == 0 && (mi_col % mi_width) == 0) { + const TplDepStats *tpl_ptr = + &tpl_frame + ->tpl_stats_ptr[mi_row * tpl_frame->stride + mi_col]; + printf("%f ", tpl_ptr->feature_score); + } + } + } + printf("\n"); + + for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) { + for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) { + const int mv_mode = + tpl_frame + ->mv_mode_arr[rf_idx][mi_row * tpl_frame->stride + mi_col]; + printf("%d ", mv_mode); + } + } + printf("\n"); + + dump_frame_buf(gf_picture[frame_idx].frame); + dump_frame_buf(ref_frame_buf); + } + } + } +} +#endif // DUMP_TPL_STATS +#endif // CONFIG_NON_GREEDY_MV + +void vp9_init_tpl_buffer(VP9_COMP *cpi) { + VP9_COMMON *cm = &cpi->common; + int frame; + + const int mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); + const int mi_rows = mi_cols_aligned_to_sb(cm->mi_rows); +#if CONFIG_NON_GREEDY_MV + int rf_idx; + + vpx_free(cpi->select_mv_arr); + CHECK_MEM_ERROR( + &cm->error, cpi->select_mv_arr, + vpx_calloc(mi_rows * mi_cols * 4, sizeof(*cpi->select_mv_arr))); +#endif + + // TODO(jingning): Reduce the actual memory use for tpl model build up. + for (frame = 0; frame < MAX_ARF_GOP_SIZE; ++frame) { + if (cpi->tpl_stats[frame].width >= mi_cols && + cpi->tpl_stats[frame].height >= mi_rows && + cpi->tpl_stats[frame].tpl_stats_ptr) + continue; + +#if CONFIG_NON_GREEDY_MV + for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { + vpx_free(cpi->tpl_stats[frame].mv_mode_arr[rf_idx]); + CHECK_MEM_ERROR( + &cm->error, cpi->tpl_stats[frame].mv_mode_arr[rf_idx], + vpx_calloc(mi_rows * mi_cols * 4, + sizeof(*cpi->tpl_stats[frame].mv_mode_arr[rf_idx]))); + vpx_free(cpi->tpl_stats[frame].rd_diff_arr[rf_idx]); + CHECK_MEM_ERROR( + &cm->error, cpi->tpl_stats[frame].rd_diff_arr[rf_idx], + vpx_calloc(mi_rows * mi_cols * 4, + sizeof(*cpi->tpl_stats[frame].rd_diff_arr[rf_idx]))); + } +#endif + vpx_free(cpi->tpl_stats[frame].tpl_stats_ptr); + CHECK_MEM_ERROR(&cm->error, cpi->tpl_stats[frame].tpl_stats_ptr, + vpx_calloc(mi_rows * mi_cols, + sizeof(*cpi->tpl_stats[frame].tpl_stats_ptr))); + cpi->tpl_stats[frame].is_valid = 0; + cpi->tpl_stats[frame].width = mi_cols; + cpi->tpl_stats[frame].height = mi_rows; + cpi->tpl_stats[frame].stride = mi_cols; + cpi->tpl_stats[frame].mi_rows = cm->mi_rows; + cpi->tpl_stats[frame].mi_cols = cm->mi_cols; + } + + for (frame = 0; frame < REF_FRAMES; ++frame) { + cpi->enc_frame_buf[frame].mem_valid = 0; + cpi->enc_frame_buf[frame].released = 1; + } +} + +void vp9_free_tpl_buffer(VP9_COMP *cpi) { + int frame; +#if CONFIG_NON_GREEDY_MV + vp9_free_motion_field_info(&cpi->motion_field_info); + vpx_free(cpi->select_mv_arr); +#endif + for (frame = 0; frame < MAX_ARF_GOP_SIZE; ++frame) { +#if CONFIG_NON_GREEDY_MV + int rf_idx; + for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) { + vpx_free(cpi->tpl_stats[frame].mv_mode_arr[rf_idx]); + vpx_free(cpi->tpl_stats[frame].rd_diff_arr[rf_idx]); + } +#endif + vpx_free(cpi->tpl_stats[frame].tpl_stats_ptr); + cpi->tpl_stats[frame].is_valid = 0; + } + free_tpl_frame_stats_list(&cpi->tpl_gop_stats); +} + +void vp9_estimate_tpl_qp_gop(VP9_COMP *cpi) { + VP9_COMMON *cm = &cpi->common; + int gop_length = cpi->twopass.gf_group.gf_group_size; + int bottom_index, top_index; + int idx; + const int gf_index = cpi->twopass.gf_group.index; + const int is_src_frame_alt_ref = cpi->rc.is_src_frame_alt_ref; + const int refresh_frame_context = cpi->common.refresh_frame_context; + + const int sb_size = num_8x8_blocks_wide_lookup[BLOCK_64X64] * MI_SIZE; + const int frame_height_sb = (cm->height + sb_size - 1) / sb_size; + const int frame_width_sb = (cm->width + sb_size - 1) / sb_size; + + vpx_codec_err_t codec_status; + const GF_GROUP *gf_group = &cpi->twopass.gf_group; + vpx_rc_encodeframe_decision_t encode_frame_decision; + + CHECK_MEM_ERROR( + &cm->error, encode_frame_decision.sb_params_list, + (sb_params *)vpx_malloc(frame_height_sb * frame_width_sb * + sizeof(*encode_frame_decision.sb_params_list))); + + for (idx = gf_index; idx <= gop_length; ++idx) { + TplDepFrame *tpl_frame = &cpi->tpl_stats[idx]; + int target_rate = cpi->twopass.gf_group.bit_allocation[idx]; + cpi->twopass.gf_group.index = idx; + vp9_rc_set_frame_target(cpi, target_rate); + vp9_configure_buffer_updates(cpi, idx); + if (cpi->ext_ratectrl.ready && + (cpi->ext_ratectrl.funcs.rc_type & VPX_RC_QP) != 0 && + cpi->ext_ratectrl.funcs.get_encodeframe_decision != NULL) { + if (idx == gop_length) break; + memset(encode_frame_decision.sb_params_list, 0, + sizeof(*encode_frame_decision.sb_params_list) * frame_height_sb * + frame_width_sb); + codec_status = vp9_extrc_get_encodeframe_decision( + &cpi->ext_ratectrl, gf_group->index, &encode_frame_decision); + if (codec_status != VPX_CODEC_OK) { + vpx_internal_error(&cm->error, codec_status, + "vp9_extrc_get_encodeframe_decision() failed"); + } + for (int i = 0; i < frame_height_sb * frame_width_sb; ++i) { + cpi->sb_mul_scale[i] = + (((int64_t)encode_frame_decision.sb_params_list[i].rdmult * 256) / + (encode_frame_decision.rdmult + 1)); + } + tpl_frame->base_qindex = encode_frame_decision.q_index; + } else { + tpl_frame->base_qindex = vp9_rc_pick_q_and_bounds_two_pass( + cpi, &bottom_index, &top_index, idx); + tpl_frame->base_qindex = VPXMAX(tpl_frame->base_qindex, 1); + } + } + // Reset the actual index and frame update + cpi->twopass.gf_group.index = gf_index; + cpi->rc.is_src_frame_alt_ref = is_src_frame_alt_ref; + cpi->common.refresh_frame_context = refresh_frame_context; + vp9_configure_buffer_updates(cpi, gf_index); + + vpx_free(encode_frame_decision.sb_params_list); +} + +void vp9_setup_tpl_stats(VP9_COMP *cpi) { + GF_PICTURE gf_picture_buf[MAX_ARF_GOP_SIZE + REFS_PER_FRAME]; + GF_PICTURE *gf_picture = &gf_picture_buf[REFS_PER_FRAME]; + const GF_GROUP *gf_group = &cpi->twopass.gf_group; + int tpl_group_frames = 0; + int frame_idx; + int extended_frame_count; + cpi->tpl_bsize = BLOCK_32X32; + + memset(gf_picture_buf, 0, sizeof(gf_picture_buf)); + extended_frame_count = + init_gop_frames(cpi, gf_picture, gf_group, &tpl_group_frames); + + init_tpl_stats(cpi); + + init_tpl_stats_before_propagation(&cpi->common.error, &cpi->tpl_gop_stats, + cpi->tpl_stats, tpl_group_frames, + cpi->common.width, cpi->common.height); + + // Backward propagation from tpl_group_frames to 1. + for (frame_idx = tpl_group_frames - 1; frame_idx > 0; --frame_idx) { + if (gf_picture[frame_idx].update_type == USE_BUF_FRAME) continue; + mc_flow_dispenser(cpi, gf_picture, frame_idx, cpi->tpl_bsize); + } + + if (cpi->ext_ratectrl.ready && + cpi->ext_ratectrl.funcs.send_tpl_gop_stats != NULL) { + // Intra search on key frame + if (gf_group->update_type[0] != OVERLAY_UPDATE) { + mc_flow_dispenser(cpi, gf_picture, 0, cpi->tpl_bsize); + } + // TPL stats has extra frames from next GOP. Trim those extra frames for + // Qmode. + trim_tpl_stats(&cpi->common.error, &cpi->tpl_gop_stats, + extended_frame_count); + const vpx_codec_err_t codec_status = + vp9_extrc_send_tpl_stats(&cpi->ext_ratectrl, &cpi->tpl_gop_stats); + if (codec_status != VPX_CODEC_OK) { + vpx_internal_error(&cpi->common.error, codec_status, + "vp9_extrc_send_tpl_stats() failed"); + } + } + +#if CONFIG_NON_GREEDY_MV + cpi->tpl_ready = 1; +#if DUMP_TPL_STATS + dump_tpl_stats(cpi, tpl_group_frames, gf_group, gf_picture, cpi->tpl_bsize); +#endif // DUMP_TPL_STATS +#endif // CONFIG_NON_GREEDY_MV +} diff --git a/libs/libvpx/vp9/encoder/vp9_tpl_model.h b/libs/libvpx/vp9/encoder/vp9_tpl_model.h new file mode 100644 index 0000000000..de0ac39a1f --- /dev/null +++ b/libs/libvpx/vp9/encoder/vp9_tpl_model.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VP9_ENCODER_VP9_TPL_MODEL_H_ +#define VPX_VP9_ENCODER_VP9_TPL_MODEL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef M_LOG2_E +#define M_LOG2_E 0.693147180559945309417 +#endif +#define log2f(x) (log(x) / (float)M_LOG2_E) + +#define TPL_DEP_COST_SCALE_LOG2 4 + +typedef struct GF_PICTURE { + YV12_BUFFER_CONFIG *frame; + int ref_frame[3]; + FRAME_UPDATE_TYPE update_type; +} GF_PICTURE; + +void vp9_init_tpl_buffer(VP9_COMP *cpi); +void vp9_setup_tpl_stats(VP9_COMP *cpi); +void vp9_free_tpl_buffer(VP9_COMP *cpi); +void vp9_estimate_tpl_qp_gop(VP9_COMP *cpi); + +void vp9_wht_fwd_txfm(int16_t *src_diff, int bw, tran_low_t *coeff, + TX_SIZE tx_size); +#if CONFIG_VP9_HIGHBITDEPTH +void vp9_highbd_wht_fwd_txfm(int16_t *src_diff, int bw, tran_low_t *coeff, + TX_SIZE tx_size); +#endif + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // VPX_VP9_ENCODER_VP9_TPL_MODEL_H_ diff --git a/libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_avx2.c b/libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_avx2.c new file mode 100644 index 0000000000..418edd62b5 --- /dev/null +++ b/libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_avx2.c @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vp9_rtcd.h" +#include "./vpx_dsp_rtcd.h" +#include "vp9/encoder/vp9_temporal_filter.h" + +static INLINE void highbd_shuffle_12tap_filter_avx2(const int16_t *filter, + __m256i *f) { + const __m256i f_low = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i *)filter)); + const __m256i f_high = _mm256_broadcastsi128_si256( + _mm_loadl_epi64((const __m128i *)(filter + 8))); + + f[0] = _mm256_shuffle_epi32(f_low, 0x00); + f[1] = _mm256_shuffle_epi32(f_low, 0x55); + f[2] = _mm256_shuffle_epi32(f_low, 0xaa); + f[3] = _mm256_shuffle_epi32(f_low, 0xff); + f[4] = _mm256_shuffle_epi32(f_high, 0x00); + f[5] = _mm256_shuffle_epi32(f_high, 0x55); +} + +static INLINE __m256i highbd_convolve_12tap(const __m256i *s, + const __m256i *f) { + const __m256i res_0 = _mm256_madd_epi16(s[0], f[0]); + const __m256i res_1 = _mm256_madd_epi16(s[1], f[1]); + const __m256i res_2 = _mm256_madd_epi16(s[2], f[2]); + const __m256i res_3 = _mm256_madd_epi16(s[3], f[3]); + const __m256i res_4 = _mm256_madd_epi16(s[4], f[4]); + const __m256i res_5 = _mm256_madd_epi16(s[5], f[5]); + + const __m256i res = + _mm256_add_epi32(_mm256_add_epi32(res_0, res_1), + _mm256_add_epi32(_mm256_add_epi32(res_2, res_3), + _mm256_add_epi32(res_4, res_5))); + return res; +} + +static INLINE void reuse_src_data_avx2(const __m256i *src, __m256i *des) { + des[0] = src[0]; + des[1] = src[1]; + des[2] = src[2]; + des[3] = src[3]; + des[4] = src[4]; +} + +void vpx_highbd_convolve12_horiz_avx2(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + assert(x_step_q4 == 16); + (void)y0_q4; + (void)x_step_q4; + (void)y_step_q4; + const uint16_t *src_ptr = src; + src_ptr -= MAX_FILTER_TAP / 2 - 1; + __m256i s[6], f[6]; + const __m256i rounding = _mm256_set1_epi32(1 << (FILTER_BITS - 1)); + const __m256i max = _mm256_set1_epi16((1 << bd) - 1); + highbd_shuffle_12tap_filter_avx2(filter[x0_q4], f); + + for (int j = 0; j < w; j += 8) { + for (int i = 0; i < h; i += 2) { + // s00 s01 s02 s03 s04 s05 s06 s07 s08 s09 s010 s011 s012 s013 s014 s015 + const __m256i row0 = + _mm256_loadu_si256((const __m256i *)&src_ptr[i * src_stride + j]); + // s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s110 s111 s112 s113 s114 + // s115 + const __m256i row1 = _mm256_loadu_si256( + (const __m256i *)&src_ptr[(i + 1) * src_stride + j]); + // s016 s017 s018 s019 s020 s021 s022 s023 + const __m128i row0_16 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride + j + 16]); + // s116 s117 s118 s119 s120 s121 s122 s123 + const __m128i row1_16 = _mm_loadu_si128( + (const __m128i *)&src_ptr[(i + 1) * src_stride + j + 16]); + + // s00 s01 s02 s03 s04 s05 s06 s07 | s10 s11 s12 s13 s14 s15 s16 s17 + const __m256i r0 = _mm256_permute2x128_si256(row0, row1, 0x20); + // s08 s09 s010 s011 s012 s013 s014 s015 | s18 s19 s110 s111 s112 s113 + // s114 s115 + const __m256i r1 = _mm256_permute2x128_si256(row0, row1, 0x31); + // s016 s017 s018 s019 s020 s021 s022 s023 | s116 s117 s118 s119 s120 s121 + // s122 s123 + const __m256i r2 = + _mm256_inserti128_si256(_mm256_castsi128_si256(row0_16), row1_16, 1); + + // even pixels + s[0] = r0; + s[1] = _mm256_alignr_epi8(r1, r0, 4); + s[2] = _mm256_alignr_epi8(r1, r0, 8); + s[3] = _mm256_alignr_epi8(r1, r0, 12); + s[4] = r1; + s[5] = _mm256_alignr_epi8(r2, r1, 4); + + // 00 02 04 06 | 10 12 14 16 + __m256i res_even = highbd_convolve_12tap(s, f); + res_even = + _mm256_srai_epi32(_mm256_add_epi32(res_even, rounding), FILTER_BITS); + + // odd pixels + s[0] = _mm256_alignr_epi8(r1, r0, 2); + s[1] = _mm256_alignr_epi8(r1, r0, 6); + s[2] = _mm256_alignr_epi8(r1, r0, 10); + s[3] = _mm256_alignr_epi8(r1, r0, 14); + s[4] = _mm256_alignr_epi8(r2, r1, 2); + s[5] = _mm256_alignr_epi8(r2, r1, 6); + + // 01 03 05 07 | 11 13 15 17 + __m256i res_odd = highbd_convolve_12tap(s, f); + res_odd = + _mm256_srai_epi32(_mm256_add_epi32(res_odd, rounding), FILTER_BITS); + + // 00 01 02 03 | 10 11 12 13 + const __m256i res_0 = _mm256_unpacklo_epi32(res_even, res_odd); + // 04 05 06 07 | 14 15 16 17 + const __m256i res_1 = _mm256_unpackhi_epi32(res_even, res_odd); + // 00 01 02 03 | 04 05 06 07 | 10 11 12 13 | 14 15 16 17 + const __m256i res_2 = _mm256_packus_epi32(res_0, res_1); + const __m256i res = _mm256_min_epi16(res_2, max); + _mm_storeu_si128((__m128i *)&dst[i * dst_stride + j], + _mm256_castsi256_si128(res)); + if (i + 1 < h) { + _mm_storeu_si128((__m128i *)(&dst[(i + 1) * dst_stride + j]), + _mm256_extractf128_si256(res, 1)); + } + } + } +} + +void vpx_highbd_convolve12_vert_avx2(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + assert(y_step_q4 == 16); + (void)x0_q4; + (void)x_step_q4; + (void)y_step_q4; + const uint16_t *src_ptr = src; + src_ptr -= src_stride * (MAX_FILTER_TAP / 2 - 1); + __m256i s[12], f[6]; + const __m256i rounding = _mm256_set1_epi32(((1 << FILTER_BITS) >> 1)); + const __m256i max = _mm256_set1_epi16((1 << bd) - 1); + highbd_shuffle_12tap_filter_avx2(filter[y0_q4], f); + + for (int j = 0; j < w; j += 8) { + __m128i s0 = + _mm_loadu_si128((const __m128i *)(src_ptr + 0 * src_stride + j)); + __m128i s1 = + _mm_loadu_si128((const __m128i *)(src_ptr + 1 * src_stride + j)); + __m128i s2 = + _mm_loadu_si128((const __m128i *)(src_ptr + 2 * src_stride + j)); + __m128i s3 = + _mm_loadu_si128((const __m128i *)(src_ptr + 3 * src_stride + j)); + __m128i s4 = + _mm_loadu_si128((const __m128i *)(src_ptr + 4 * src_stride + j)); + __m128i s5 = + _mm_loadu_si128((const __m128i *)(src_ptr + 5 * src_stride + j)); + __m128i s6 = + _mm_loadu_si128((const __m128i *)(src_ptr + 6 * src_stride + j)); + __m128i s7 = + _mm_loadu_si128((const __m128i *)(src_ptr + 7 * src_stride + j)); + __m128i s8 = + _mm_loadu_si128((const __m128i *)(src_ptr + 8 * src_stride + j)); + __m128i s9 = + _mm_loadu_si128((const __m128i *)(src_ptr + 9 * src_stride + j)); + __m128i s10t = + _mm_loadu_si128((const __m128i *)(src_ptr + 10 * src_stride + j)); + + __m256i r01 = _mm256_inserti128_si256(_mm256_castsi128_si256(s0), s1, 1); + __m256i r12 = _mm256_inserti128_si256(_mm256_castsi128_si256(s1), s2, 1); + __m256i r23 = _mm256_inserti128_si256(_mm256_castsi128_si256(s2), s3, 1); + __m256i r34 = _mm256_inserti128_si256(_mm256_castsi128_si256(s3), s4, 1); + __m256i r45 = _mm256_inserti128_si256(_mm256_castsi128_si256(s4), s5, 1); + __m256i r56 = _mm256_inserti128_si256(_mm256_castsi128_si256(s5), s6, 1); + __m256i r67 = _mm256_inserti128_si256(_mm256_castsi128_si256(s6), s7, 1); + __m256i r78 = _mm256_inserti128_si256(_mm256_castsi128_si256(s7), s8, 1); + __m256i r89 = _mm256_inserti128_si256(_mm256_castsi128_si256(s8), s9, 1); + __m256i r910 = _mm256_inserti128_si256(_mm256_castsi128_si256(s9), s10t, 1); + + s[0] = _mm256_unpacklo_epi16(r01, r12); + s[1] = _mm256_unpacklo_epi16(r23, r34); + s[2] = _mm256_unpacklo_epi16(r45, r56); + s[3] = _mm256_unpacklo_epi16(r67, r78); + s[4] = _mm256_unpacklo_epi16(r89, r910); + + s[6] = _mm256_unpackhi_epi16(r01, r12); + s[7] = _mm256_unpackhi_epi16(r23, r34); + s[8] = _mm256_unpackhi_epi16(r45, r56); + s[9] = _mm256_unpackhi_epi16(r67, r78); + s[10] = _mm256_unpackhi_epi16(r89, r910); + for (int i = 0; i < h; i += 2) { + const __m128i s10 = _mm_loadu_si128( + (const __m128i *)(src_ptr + (i + 10) * src_stride + j)); + const __m128i s11 = _mm_loadu_si128( + (const __m128i *)(src_ptr + (i + 11) * src_stride + j)); + const __m128i s12 = _mm_loadu_si128( + (const __m128i *)(src_ptr + (i + 12) * src_stride + j)); + __m256i r1011 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s10), s11, 1); + __m256i r1112 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s11), s12, 1); + + s[5] = _mm256_unpacklo_epi16(r1011, r1112); + s[11] = _mm256_unpackhi_epi16(r1011, r1112); + + // 00 01 02 03 | 10 11 12 13 + const __m256i res_a = highbd_convolve_12tap(s, f); + __m256i res_a_round = + _mm256_srai_epi32(_mm256_add_epi32(res_a, rounding), FILTER_BITS); + // 04 05 06 07 | 14 15 16 17 + const __m256i res_b = highbd_convolve_12tap(s + 6, f); + __m256i res_b_round = + _mm256_srai_epi32(_mm256_add_epi32(res_b, rounding), FILTER_BITS); + + // 00 01 02 03 | 04 05 06 07 | 10 11 12 13 | 14 15 16 17 + const __m256i res_0 = _mm256_packus_epi32(res_a_round, res_b_round); + const __m256i res = _mm256_min_epi16(res_0, max); + _mm_storeu_si128((__m128i *)&dst[i * dst_stride + j], + _mm256_castsi256_si128(res)); + + _mm_storeu_si128((__m128i *)(&dst[(i + 1) * dst_stride + j]), + _mm256_extractf128_si256(res, 1)); + + reuse_src_data_avx2(s + 1, s); + reuse_src_data_avx2(s + 7, s + 6); + } + } +} + +void vpx_highbd_convolve12_avx2(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h, int bd) { + assert(x_step_q4 == 16 && y_step_q4 == 16); + assert(h == 32 || h == 16 || h == 8); + assert(w == 32 || w == 16 || w == 8); + DECLARE_ALIGNED(32, uint16_t, temp[BW * (BH + MAX_FILTER_TAP - 1)]); + const int temp_stride = BW; + const int intermediate_height = + (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + MAX_FILTER_TAP; + + vpx_highbd_convolve12_horiz_avx2(src - src_stride * (MAX_FILTER_TAP / 2 - 1), + src_stride, temp, temp_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, + intermediate_height, bd); + vpx_highbd_convolve12_vert_avx2(temp + temp_stride * (MAX_FILTER_TAP / 2 - 1), + temp_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); +} diff --git a/libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_sse4.c b/libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_sse4.c index 4fa24512c5..97f182c660 100644 --- a/libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_sse4.c +++ b/libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_sse4.c @@ -16,7 +16,7 @@ #include "vpx/vpx_integer.h" #include "vp9/encoder/vp9_encoder.h" #include "vp9/encoder/vp9_temporal_filter.h" -#include "vp9/encoder/x86/temporal_filter_constants.h" +#include "vp9/encoder/vp9_temporal_filter_constants.h" // Compute (a-b)**2 for 8 pixels with size 16-bit static INLINE void highbd_store_dist_8(const uint16_t *a, const uint16_t *b, @@ -141,11 +141,12 @@ static INLINE void highbd_accumulate_and_store_8(const __m128i sum_first_u32, count_u16 = _mm_adds_epu16(count_u16, sum_u16); _mm_storeu_si128((__m128i *)count, count_u16); - pred_u16 = _mm_mullo_epi16(sum_u16, pred_u16); - pred_0_u32 = _mm_cvtepu16_epi32(pred_u16); pred_1_u32 = _mm_unpackhi_epi16(pred_u16, zero); + pred_0_u32 = _mm_mullo_epi32(sum_first_u32, pred_0_u32); + pred_1_u32 = _mm_mullo_epi32(sum_second_u32, pred_1_u32); + accum_0_u32 = _mm_loadu_si128((const __m128i *)accumulator); accum_1_u32 = _mm_loadu_si128((const __m128i *)(accumulator + 4)); @@ -191,13 +192,11 @@ static INLINE void highbd_read_chroma_dist_row_8( } static void vp9_highbd_apply_temporal_filter_luma_8( - const uint16_t *y_src, int y_src_stride, const uint16_t *y_pre, - int y_pre_stride, const uint16_t *u_src, const uint16_t *v_src, - int uv_src_stride, const uint16_t *u_pre, const uint16_t *v_pre, - int uv_pre_stride, unsigned int block_width, unsigned int block_height, - int ss_x, int ss_y, int strength, int use_whole_blk, uint32_t *y_accum, - uint16_t *y_count, const uint32_t *y_dist, const uint32_t *u_dist, - const uint32_t *v_dist, const uint32_t *const *neighbors_first, + const uint16_t *y_pre, int y_pre_stride, unsigned int block_width, + unsigned int block_height, int ss_x, int ss_y, int strength, + int use_whole_blk, uint32_t *y_accum, uint16_t *y_count, + const uint32_t *y_dist, const uint32_t *u_dist, const uint32_t *v_dist, + const uint32_t *const *neighbors_first, const uint32_t *const *neighbors_second, int top_weight, int bottom_weight) { const int rounding = (1 << strength) >> 1; @@ -256,17 +255,12 @@ static void vp9_highbd_apply_temporal_filter_luma_8( highbd_accumulate_and_store_8(sum_row_first, sum_row_second, y_pre, y_count, y_accum); - y_src += y_src_stride; y_pre += y_pre_stride; y_count += y_pre_stride; y_accum += y_pre_stride; y_dist += DIST_STRIDE; - u_src += uv_src_stride; - u_pre += uv_pre_stride; u_dist += DIST_STRIDE; - v_src += uv_src_stride; - v_pre += uv_pre_stride; v_dist += DIST_STRIDE; // Then all the rows except the last one @@ -300,11 +294,7 @@ static void vp9_highbd_apply_temporal_filter_luma_8( highbd_read_chroma_dist_row_8(ss_x, u_dist, v_dist, &u_first, &u_second, &v_first, &v_second); - u_src += uv_src_stride; - u_pre += uv_pre_stride; u_dist += DIST_STRIDE; - v_src += uv_src_stride; - v_pre += uv_pre_stride; v_dist += DIST_STRIDE; } @@ -320,7 +310,6 @@ static void vp9_highbd_apply_temporal_filter_luma_8( highbd_accumulate_and_store_8(sum_row_first, sum_row_second, y_pre, y_count, y_accum); - y_src += y_src_stride; y_pre += y_pre_stride; y_count += y_pre_stride; y_accum += y_pre_stride; @@ -364,13 +353,10 @@ static void vp9_highbd_apply_temporal_filter_luma_8( // Perform temporal filter for the luma component. static void vp9_highbd_apply_temporal_filter_luma( - const uint16_t *y_src, int y_src_stride, const uint16_t *y_pre, - int y_pre_stride, const uint16_t *u_src, const uint16_t *v_src, - int uv_src_stride, const uint16_t *u_pre, const uint16_t *v_pre, - int uv_pre_stride, unsigned int block_width, unsigned int block_height, - int ss_x, int ss_y, int strength, const int *blk_fw, int use_whole_blk, - uint32_t *y_accum, uint16_t *y_count, const uint32_t *y_dist, - const uint32_t *u_dist, const uint32_t *v_dist) { + const uint16_t *y_pre, int y_pre_stride, unsigned int block_width, + unsigned int block_height, int ss_x, int ss_y, int strength, + const int *blk_fw, int use_whole_blk, uint32_t *y_accum, uint16_t *y_count, + const uint32_t *y_dist, const uint32_t *u_dist, const uint32_t *v_dist) { unsigned int blk_col = 0, uv_blk_col = 0; const unsigned int blk_col_step = 8, uv_blk_col_step = 8 >> ss_x; const unsigned int mid_width = block_width >> 1, @@ -384,9 +370,7 @@ static void vp9_highbd_apply_temporal_filter_luma( neighbors_first = HIGHBD_LUMA_LEFT_COLUMN_NEIGHBORS; neighbors_second = HIGHBD_LUMA_MIDDLE_COLUMN_NEIGHBORS; vp9_highbd_apply_temporal_filter_luma_8( - y_src + blk_col, y_src_stride, y_pre + blk_col, y_pre_stride, - u_src + uv_blk_col, v_src + uv_blk_col, uv_src_stride, u_pre + uv_blk_col, - v_pre + uv_blk_col, uv_pre_stride, blk_col_step, block_height, ss_x, ss_y, + y_pre + blk_col, y_pre_stride, blk_col_step, block_height, ss_x, ss_y, strength, use_whole_blk, y_accum + blk_col, y_count + blk_col, y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_first, neighbors_second, top_weight, bottom_weight); @@ -399,13 +383,10 @@ static void vp9_highbd_apply_temporal_filter_luma( for (; blk_col < mid_width; blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { vp9_highbd_apply_temporal_filter_luma_8( - y_src + blk_col, y_src_stride, y_pre + blk_col, y_pre_stride, - u_src + uv_blk_col, v_src + uv_blk_col, uv_src_stride, - u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, blk_col_step, - block_height, ss_x, ss_y, strength, use_whole_blk, y_accum + blk_col, - y_count + blk_col, y_dist + blk_col, u_dist + uv_blk_col, - v_dist + uv_blk_col, neighbors_first, neighbors_second, top_weight, - bottom_weight); + y_pre + blk_col, y_pre_stride, blk_col_step, block_height, ss_x, ss_y, + strength, use_whole_blk, y_accum + blk_col, y_count + blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, + neighbors_first, neighbors_second, top_weight, bottom_weight); } if (!use_whole_blk) { @@ -417,21 +398,16 @@ static void vp9_highbd_apply_temporal_filter_luma( for (; blk_col < last_width; blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { vp9_highbd_apply_temporal_filter_luma_8( - y_src + blk_col, y_src_stride, y_pre + blk_col, y_pre_stride, - u_src + uv_blk_col, v_src + uv_blk_col, uv_src_stride, - u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, blk_col_step, - block_height, ss_x, ss_y, strength, use_whole_blk, y_accum + blk_col, - y_count + blk_col, y_dist + blk_col, u_dist + uv_blk_col, - v_dist + uv_blk_col, neighbors_first, neighbors_second, top_weight, - bottom_weight); + y_pre + blk_col, y_pre_stride, blk_col_step, block_height, ss_x, ss_y, + strength, use_whole_blk, y_accum + blk_col, y_count + blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, + neighbors_first, neighbors_second, top_weight, bottom_weight); } // Right neighbors_second = HIGHBD_LUMA_RIGHT_COLUMN_NEIGHBORS; vp9_highbd_apply_temporal_filter_luma_8( - y_src + blk_col, y_src_stride, y_pre + blk_col, y_pre_stride, - u_src + uv_blk_col, v_src + uv_blk_col, uv_src_stride, u_pre + uv_blk_col, - v_pre + uv_blk_col, uv_pre_stride, blk_col_step, block_height, ss_x, ss_y, + y_pre + blk_col, y_pre_stride, blk_col_step, block_height, ss_x, ss_y, strength, use_whole_blk, y_accum + blk_col, y_count + blk_col, y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_first, neighbors_second, top_weight, bottom_weight); @@ -491,13 +467,11 @@ static INLINE void highbd_add_luma_dist_to_8_chroma_mod( // blk_fw as an array of size 4 for the weights for each of the 4 subblocks, // else use top_weight for top half, and bottom weight for bottom half. static void vp9_highbd_apply_temporal_filter_chroma_8( - const uint16_t *y_src, int y_src_stride, const uint16_t *y_pre, - int y_pre_stride, const uint16_t *u_src, const uint16_t *v_src, - int uv_src_stride, const uint16_t *u_pre, const uint16_t *v_pre, - int uv_pre_stride, unsigned int uv_block_width, - unsigned int uv_block_height, int ss_x, int ss_y, int strength, - uint32_t *u_accum, uint16_t *u_count, uint32_t *v_accum, uint16_t *v_count, - const uint32_t *y_dist, const uint32_t *u_dist, const uint32_t *v_dist, + const uint16_t *u_pre, const uint16_t *v_pre, int uv_pre_stride, + unsigned int uv_block_width, unsigned int uv_block_height, int ss_x, + int ss_y, int strength, uint32_t *u_accum, uint16_t *u_count, + uint32_t *v_accum, uint16_t *v_count, const uint32_t *y_dist, + const uint32_t *u_dist, const uint32_t *v_dist, const uint32_t *const *neighbors_fst, const uint32_t *const *neighbors_snd, int top_weight, int bottom_weight, const int *blk_fw) { const int rounding = (1 << strength) >> 1; @@ -565,10 +539,8 @@ static void vp9_highbd_apply_temporal_filter_chroma_8( highbd_accumulate_and_store_8(v_sum_row_fst, v_sum_row_snd, v_pre, v_count, v_accum); - u_src += uv_src_stride; u_pre += uv_pre_stride; u_dist += DIST_STRIDE; - v_src += uv_src_stride; v_pre += uv_pre_stride; v_dist += DIST_STRIDE; u_count += uv_pre_stride; @@ -576,8 +548,6 @@ static void vp9_highbd_apply_temporal_filter_chroma_8( v_count += uv_pre_stride; v_accum += uv_pre_stride; - y_src += y_src_stride * (1 + ss_y); - y_pre += y_pre_stride * (1 + ss_y); y_dist += DIST_STRIDE * (1 + ss_y); // Then all the rows except the last one @@ -649,10 +619,8 @@ static void vp9_highbd_apply_temporal_filter_chroma_8( highbd_accumulate_and_store_8(v_sum_row_fst, v_sum_row_snd, v_pre, v_count, v_accum); - u_src += uv_src_stride; u_pre += uv_pre_stride; u_dist += DIST_STRIDE; - v_src += uv_src_stride; v_pre += uv_pre_stride; v_dist += DIST_STRIDE; u_count += uv_pre_stride; @@ -660,8 +628,6 @@ static void vp9_highbd_apply_temporal_filter_chroma_8( v_count += uv_pre_stride; v_accum += uv_pre_stride; - y_src += y_src_stride * (1 + ss_y); - y_pre += y_pre_stride * (1 + ss_y); y_dist += DIST_STRIDE * (1 + ss_y); } @@ -720,12 +686,10 @@ static void vp9_highbd_apply_temporal_filter_chroma_8( // Perform temporal filter for the chroma components. static void vp9_highbd_apply_temporal_filter_chroma( - const uint16_t *y_src, int y_src_stride, const uint16_t *y_pre, - int y_pre_stride, const uint16_t *u_src, const uint16_t *v_src, - int uv_src_stride, const uint16_t *u_pre, const uint16_t *v_pre, - int uv_pre_stride, unsigned int block_width, unsigned int block_height, - int ss_x, int ss_y, int strength, const int *blk_fw, int use_whole_blk, - uint32_t *u_accum, uint16_t *u_count, uint32_t *v_accum, uint16_t *v_count, + const uint16_t *u_pre, const uint16_t *v_pre, int uv_pre_stride, + unsigned int block_width, unsigned int block_height, int ss_x, int ss_y, + int strength, const int *blk_fw, int use_whole_blk, uint32_t *u_accum, + uint16_t *u_count, uint32_t *v_accum, uint16_t *v_count, const uint32_t *y_dist, const uint32_t *u_dist, const uint32_t *v_dist) { const unsigned int uv_width = block_width >> ss_x, uv_height = block_height >> ss_y; @@ -755,8 +719,6 @@ static void vp9_highbd_apply_temporal_filter_chroma( if (use_whole_blk) { vp9_highbd_apply_temporal_filter_chroma_8( - y_src + blk_col, y_src_stride, y_pre + blk_col, y_pre_stride, - u_src + uv_blk_col, v_src + uv_blk_col, uv_src_stride, u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, @@ -764,8 +726,6 @@ static void vp9_highbd_apply_temporal_filter_chroma( neighbors_fst, neighbors_snd, top_weight, bottom_weight, NULL); } else { vp9_highbd_apply_temporal_filter_chroma_8( - y_src + blk_col, y_src_stride, y_pre + blk_col, y_pre_stride, - u_src + uv_blk_col, v_src + uv_blk_col, uv_src_stride, u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, @@ -789,13 +749,11 @@ static void vp9_highbd_apply_temporal_filter_chroma( } vp9_highbd_apply_temporal_filter_chroma_8( - y_src + blk_col, y_src_stride, y_pre + blk_col, y_pre_stride, - u_src + uv_blk_col, v_src + uv_blk_col, uv_src_stride, u_pre + uv_blk_col, - v_pre + uv_blk_col, uv_pre_stride, uv_width, uv_height, ss_x, ss_y, - strength, u_accum + uv_blk_col, u_count + uv_blk_col, - v_accum + uv_blk_col, v_count + uv_blk_col, y_dist + blk_col, - u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_fst, neighbors_snd, - top_weight, bottom_weight, NULL); + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, + uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, + u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_fst, + neighbors_snd, top_weight, bottom_weight, NULL); blk_col += blk_col_step; uv_blk_col += uv_blk_col_step; @@ -812,8 +770,6 @@ static void vp9_highbd_apply_temporal_filter_chroma( for (; uv_blk_col < uv_mid_width; blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { vp9_highbd_apply_temporal_filter_chroma_8( - y_src + blk_col, y_src_stride, y_pre + blk_col, y_pre_stride, - u_src + uv_blk_col, v_src + uv_blk_col, uv_src_stride, u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, @@ -830,8 +786,6 @@ static void vp9_highbd_apply_temporal_filter_chroma( for (; uv_blk_col < uv_last_width; blk_col += blk_col_step, uv_blk_col += uv_blk_col_step) { vp9_highbd_apply_temporal_filter_chroma_8( - y_src + blk_col, y_src_stride, y_pre + blk_col, y_pre_stride, - u_src + uv_blk_col, v_src + uv_blk_col, uv_src_stride, u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, @@ -849,13 +803,11 @@ static void vp9_highbd_apply_temporal_filter_chroma( } vp9_highbd_apply_temporal_filter_chroma_8( - y_src + blk_col, y_src_stride, y_pre + blk_col, y_pre_stride, - u_src + uv_blk_col, v_src + uv_blk_col, uv_src_stride, u_pre + uv_blk_col, - v_pre + uv_blk_col, uv_pre_stride, uv_width, uv_height, ss_x, ss_y, - strength, u_accum + uv_blk_col, u_count + uv_blk_col, - v_accum + uv_blk_col, v_count + uv_blk_col, y_dist + blk_col, - u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_fst, neighbors_snd, - top_weight, bottom_weight, NULL); + u_pre + uv_blk_col, v_pre + uv_blk_col, uv_pre_stride, uv_width, + uv_height, ss_x, ss_y, strength, u_accum + uv_blk_col, + u_count + uv_blk_col, v_accum + uv_blk_col, v_count + uv_blk_col, + y_dist + blk_col, u_dist + uv_blk_col, v_dist + uv_blk_col, neighbors_fst, + neighbors_snd, top_weight, bottom_weight, NULL); } void vp9_highbd_apply_temporal_filter_sse4_1( @@ -929,14 +881,12 @@ void vp9_highbd_apply_temporal_filter_sse4_1( u_dist_ptr = u_dist + 1; v_dist_ptr = v_dist + 1; - vp9_highbd_apply_temporal_filter_luma( - y_src, y_src_stride, y_pre, y_pre_stride, u_src, v_src, uv_src_stride, - u_pre, v_pre, uv_pre_stride, block_width, block_height, ss_x, ss_y, - strength, blk_fw, use_whole_blk, y_accum, y_count, y_dist_ptr, u_dist_ptr, - v_dist_ptr); + vp9_highbd_apply_temporal_filter_luma(y_pre, y_pre_stride, block_width, + block_height, ss_x, ss_y, strength, + blk_fw, use_whole_blk, y_accum, y_count, + y_dist_ptr, u_dist_ptr, v_dist_ptr); vp9_highbd_apply_temporal_filter_chroma( - y_src, y_src_stride, y_pre, y_pre_stride, u_src, v_src, uv_src_stride, u_pre, v_pre, uv_pre_stride, block_width, block_height, ss_x, ss_y, strength, blk_fw, use_whole_blk, u_accum, u_count, v_accum, v_count, y_dist_ptr, u_dist_ptr, v_dist_ptr); diff --git a/libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_ssse3.c b/libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_ssse3.c new file mode 100644 index 0000000000..4540dca3a6 --- /dev/null +++ b/libs/libvpx/vp9/encoder/x86/highbd_temporal_filter_ssse3.c @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include // SSSE3 + +#include "./vp9_rtcd.h" +#include "./vpx_dsp_rtcd.h" +#include "vp9/encoder/vp9_temporal_filter.h" + +static INLINE void highbd_shuffle_12tap_filter_ssse3(const int16_t *filter, + __m128i *f) { + const __m128i f_low = _mm_loadu_si128((const __m128i *)filter); + const __m128i f_high = _mm_loadl_epi64((const __m128i *)(filter + 8)); + + f[0] = _mm_shuffle_epi32(f_low, 0x00); + f[1] = _mm_shuffle_epi32(f_low, 0x55); + f[2] = _mm_shuffle_epi32(f_low, 0xaa); + f[3] = _mm_shuffle_epi32(f_low, 0xff); + f[4] = _mm_shuffle_epi32(f_high, 0x00); + f[5] = _mm_shuffle_epi32(f_high, 0x55); +} + +static INLINE void unpacklo_src_ssse3(__m128i *a, __m128i *s) { + s[0] = _mm_unpacklo_epi16(a[0], a[1]); + s[1] = _mm_unpacklo_epi16(a[2], a[3]); + s[2] = _mm_unpacklo_epi16(a[4], a[5]); + s[3] = _mm_unpacklo_epi16(a[6], a[7]); + s[4] = _mm_unpacklo_epi16(a[8], a[9]); +} + +static INLINE void unpackhi_src_ssse3(__m128i *a, __m128i *s) { + s[0] = _mm_unpackhi_epi16(a[0], a[1]); + s[1] = _mm_unpackhi_epi16(a[2], a[3]); + s[2] = _mm_unpackhi_epi16(a[4], a[5]); + s[3] = _mm_unpackhi_epi16(a[6], a[7]); + s[4] = _mm_unpackhi_epi16(a[8], a[9]); +} + +static INLINE __m128i highbd_convolve_12tap(const __m128i *s, + const __m128i *f) { + const __m128i rounding = _mm_set1_epi32(1 << (FILTER_BITS - 1)); + const __m128i res_0 = _mm_madd_epi16(s[0], f[0]); + const __m128i res_1 = _mm_madd_epi16(s[1], f[1]); + const __m128i res_2 = _mm_madd_epi16(s[2], f[2]); + const __m128i res_3 = _mm_madd_epi16(s[3], f[3]); + const __m128i res_4 = _mm_madd_epi16(s[4], f[4]); + const __m128i res_5 = _mm_madd_epi16(s[5], f[5]); + + const __m128i res_6 = _mm_add_epi32( + _mm_add_epi32(res_0, res_1), + _mm_add_epi32(_mm_add_epi32(res_2, res_3), _mm_add_epi32(res_4, res_5))); + const __m128i res = + _mm_srai_epi32(_mm_add_epi32(res_6, rounding), FILTER_BITS); + return res; +} + +static INLINE void reuse_src_data_ssse3(const __m128i *src, __m128i *des) { + des[0] = src[0]; + des[1] = src[1]; + des[2] = src[2]; + des[3] = src[3]; + des[4] = src[4]; +} + +void vpx_highbd_convolve12_horiz_ssse3(const uint16_t *src, + ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + assert(x_step_q4 == 16); + (void)y0_q4; + (void)x_step_q4; + (void)y_step_q4; + const uint16_t *src_ptr = src; + src_ptr -= MAX_FILTER_TAP / 2 - 1; + __m128i s[6], f[6]; + const __m128i max = _mm_set1_epi16((1 << bd) - 1); + const __m128i min = _mm_setzero_si128(); + highbd_shuffle_12tap_filter_ssse3(filter[x0_q4], f); + + for (int j = 0; j < w; j += 8) { + for (int i = 0; i < h; i++) { + // s00 s01 s02 s03 s04 s05 s06 s07 + const __m128i r0 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride + j]); + // s08 s09 s010 s011 s012 s013 s014 s015 + const __m128i r1 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride + j + 8]); + // s016 s017 s018 s019 s020 s021 s022 s023 + const __m128i r2 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride + j + 16]); + + // even pixels + s[0] = r0; + s[1] = _mm_alignr_epi8(r1, r0, 4); + s[2] = _mm_alignr_epi8(r1, r0, 8); + s[3] = _mm_alignr_epi8(r1, r0, 12); + s[4] = r1; + s[5] = _mm_alignr_epi8(r2, r1, 4); + + // 00 02 04 06 + __m128i res_even = highbd_convolve_12tap(s, f); + + // odd pixels + s[0] = _mm_alignr_epi8(r1, r0, 2); + s[1] = _mm_alignr_epi8(r1, r0, 6); + s[2] = _mm_alignr_epi8(r1, r0, 10); + s[3] = _mm_alignr_epi8(r1, r0, 14); + s[4] = _mm_alignr_epi8(r2, r1, 2); + s[5] = _mm_alignr_epi8(r2, r1, 6); + + // 01 03 05 07 + __m128i res_odd = highbd_convolve_12tap(s, f); + + // 00 01 02 03 + const __m128i res_0 = _mm_unpacklo_epi32(res_even, res_odd); + // 04 05 06 07 + const __m128i res_1 = _mm_unpackhi_epi32(res_even, res_odd); + // 00 01 02 03 | 04 05 06 07 + const __m128i res_2 = _mm_packs_epi32(res_0, res_1); + const __m128i res = _mm_max_epi16(_mm_min_epi16(res_2, max), min); + _mm_storeu_si128((__m128i *)&dst[i * dst_stride + j], res); + } + } +} + +void vpx_highbd_convolve12_vert_ssse3(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + assert(y_step_q4 == 16); + (void)x0_q4; + (void)x_step_q4; + (void)y_step_q4; + const uint16_t *src_ptr = src; + src_ptr -= src_stride * (MAX_FILTER_TAP / 2 - 1); + __m128i s[12], r[12], a[11], f[6]; + const __m128i max = _mm_set1_epi16((1 << bd) - 1); + const __m128i min = _mm_setzero_si128(); + highbd_shuffle_12tap_filter_ssse3(filter[y0_q4], f); + + for (int j = 0; j < w; j += 8) { + a[0] = _mm_loadu_si128((const __m128i *)(src_ptr + 0 * src_stride + j)); + a[1] = _mm_loadu_si128((const __m128i *)(src_ptr + 1 * src_stride + j)); + a[2] = _mm_loadu_si128((const __m128i *)(src_ptr + 2 * src_stride + j)); + a[3] = _mm_loadu_si128((const __m128i *)(src_ptr + 3 * src_stride + j)); + a[4] = _mm_loadu_si128((const __m128i *)(src_ptr + 4 * src_stride + j)); + a[5] = _mm_loadu_si128((const __m128i *)(src_ptr + 5 * src_stride + j)); + a[6] = _mm_loadu_si128((const __m128i *)(src_ptr + 6 * src_stride + j)); + a[7] = _mm_loadu_si128((const __m128i *)(src_ptr + 7 * src_stride + j)); + a[8] = _mm_loadu_si128((const __m128i *)(src_ptr + 8 * src_stride + j)); + a[9] = _mm_loadu_si128((const __m128i *)(src_ptr + 9 * src_stride + j)); + a[10] = _mm_loadu_si128((const __m128i *)(src_ptr + 10 * src_stride + j)); + + // even row + unpacklo_src_ssse3(a, s); + unpackhi_src_ssse3(a, s + 6); + // odd row + unpacklo_src_ssse3(a + 1, r); + unpackhi_src_ssse3(a + 1, r + 6); + + for (int i = 0; i < h; i += 2) { + const __m128i s0 = _mm_loadu_si128( + (const __m128i *)(src_ptr + (i + 10) * src_stride + j)); + const __m128i s1 = _mm_loadu_si128( + (const __m128i *)(src_ptr + (i + 11) * src_stride + j)); + const __m128i s2 = _mm_loadu_si128( + (const __m128i *)(src_ptr + (i + 12) * src_stride + j)); + + s[5] = _mm_unpacklo_epi16(s0, s1); + r[5] = _mm_unpacklo_epi16(s1, s2); + + s[11] = _mm_unpackhi_epi16(s0, s1); + r[11] = _mm_unpackhi_epi16(s1, s2); + + // 00 01 02 03 + const __m128i res_a = highbd_convolve_12tap(s, f); + // 04 05 06 07 + const __m128i res_b = highbd_convolve_12tap(s + 6, f); + // 10 11 12 13 + const __m128i res_c = highbd_convolve_12tap(r, f); + // 14 15 16 17 + const __m128i res_d = highbd_convolve_12tap(r + 6, f); + + // 00 01 02 03 | 04 05 06 07 + const __m128i res_0 = _mm_packs_epi32(res_a, res_b); + // 10 11 12 13 | 14 15 16 17 + const __m128i res_1 = _mm_packs_epi32(res_c, res_d); + const __m128i res_r0 = _mm_max_epi16(_mm_min_epi16(res_0, max), min); + const __m128i res_r1 = _mm_max_epi16(_mm_min_epi16(res_1, max), min); + + _mm_storeu_si128((__m128i *)&dst[i * dst_stride + j], res_r0); + _mm_storeu_si128((__m128i *)&dst[(i + 1) * dst_stride + j], res_r1); + + reuse_src_data_ssse3(s + 1, s); + reuse_src_data_ssse3(s + 7, s + 6); + reuse_src_data_ssse3(r + 1, r); + reuse_src_data_ssse3(r + 7, r + 6); + } + } +} + +void vpx_highbd_convolve12_ssse3(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h, int bd) { + assert(x_step_q4 == 16 && y_step_q4 == 16); + assert(h == 32 || h == 16 || h == 8); + assert(w == 32 || w == 16 || w == 8); + DECLARE_ALIGNED(32, uint16_t, temp[BW * (BH + MAX_FILTER_TAP - 1)]); + const int temp_stride = BW; + const int intermediate_height = + (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + MAX_FILTER_TAP; + + vpx_highbd_convolve12_horiz_ssse3(src - src_stride * (MAX_FILTER_TAP / 2 - 1), + src_stride, temp, temp_stride, filter, + x0_q4, x_step_q4, y0_q4, y_step_q4, w, + intermediate_height, bd); + vpx_highbd_convolve12_vert_ssse3( + temp + temp_stride * (MAX_FILTER_TAP / 2 - 1), temp_stride, dst, + dst_stride, filter, x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); +} diff --git a/libs/libvpx/vp9/encoder/x86/temporal_filter_avx2.c b/libs/libvpx/vp9/encoder/x86/temporal_filter_avx2.c new file mode 100644 index 0000000000..9d94ff8d69 --- /dev/null +++ b/libs/libvpx/vp9/encoder/x86/temporal_filter_avx2.c @@ -0,0 +1,441 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vp9_rtcd.h" +#include "vp9/encoder/vp9_temporal_filter.h" + +DECLARE_ALIGNED(32, static const uint8_t, + shuffle_src_mask1_avx2[32]) = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, + 6, 6, 7, 7, 8, 0, 1, 1, 2, 2, 3, + 3, 4, 4, 5, 5, 6, 6, 7, 7, 8 }; + +DECLARE_ALIGNED(32, static const uint8_t, shuffle_src_mask2_avx2[32]) = { + 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, + 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10 +}; + +DECLARE_ALIGNED(32, static const uint8_t, shuffle_src_mask3_avx2[32]) = { + 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, + 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12 +}; + +DECLARE_ALIGNED(32, static const uint8_t, shuffle_src_mask4_avx2[32]) = { + 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, + 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14 +}; + +static INLINE void shuffle_12tap_filter_avx2(const int16_t *filter, + __m256i *f) { + const __m256i f_low = + _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i *)filter)); + const __m256i f_high = _mm256_broadcastsi128_si256( + _mm_loadl_epi64((const __m128i *)(filter + 8))); + + f[0] = _mm256_shuffle_epi8(f_low, _mm256_set1_epi16(0x0200u)); + f[1] = _mm256_shuffle_epi8(f_low, _mm256_set1_epi16(0x0604u)); + f[2] = _mm256_shuffle_epi8(f_low, _mm256_set1_epi16(0x0a08u)); + f[3] = _mm256_shuffle_epi8(f_low, _mm256_set1_epi16(0x0e0cu)); + f[4] = _mm256_shuffle_epi8(f_high, _mm256_set1_epi16(0x0200u)); + f[5] = _mm256_shuffle_epi8(f_high, _mm256_set1_epi16(0x0604u)); +} + +static INLINE void shuffle_src_data_avx2(const __m256i *r1, const __m256i *r2, + const __m256i *f, __m256i *s) { + s[0] = _mm256_shuffle_epi8(*r1, f[0]); + s[1] = _mm256_shuffle_epi8(*r1, f[1]); + s[2] = _mm256_shuffle_epi8(*r1, f[2]); + s[3] = _mm256_shuffle_epi8(*r1, f[3]); + s[4] = _mm256_shuffle_epi8(*r2, f[0]); + s[5] = _mm256_shuffle_epi8(*r2, f[1]); +} + +static INLINE void reuse_src_data_avx2(const __m256i *src, __m256i *des) { + des[0] = src[0]; + des[1] = src[1]; + des[2] = src[2]; + des[3] = src[3]; + des[4] = src[4]; +} + +static INLINE __m256i convolve12_16_avx2(const __m256i *s, const __m256i *f) { + // multiply 2 adjacent elements with the filter and add the result + const __m256i k_64 = _mm256_set1_epi16(1 << (FILTER_BITS - 1)); + const __m256i x0 = _mm256_maddubs_epi16(s[0], f[0]); + const __m256i x1 = _mm256_maddubs_epi16(s[1], f[1]); + const __m256i x2 = _mm256_maddubs_epi16(s[2], f[2]); + const __m256i x3 = _mm256_maddubs_epi16(s[3], f[3]); + const __m256i x4 = _mm256_maddubs_epi16(s[4], f[4]); + const __m256i x5 = _mm256_maddubs_epi16(s[5], f[5]); + __m256i sum1, sum2, sum3; + + sum1 = _mm256_add_epi16(x0, x2); + sum2 = _mm256_add_epi16(x3, x5); + sum3 = _mm256_add_epi16(x1, x4); + sum3 = _mm256_add_epi16(sum3, k_64); + + const __m256i s0 = _mm256_cvtepi16_epi32(_mm256_castsi256_si128(sum1)); + const __m256i s1 = _mm256_cvtepi16_epi32(_mm256_extracti128_si256(sum1, 1)); + const __m256i s2 = _mm256_cvtepi16_epi32(_mm256_castsi256_si128(sum2)); + const __m256i s3 = _mm256_cvtepi16_epi32(_mm256_extracti128_si256(sum2, 1)); + const __m256i s4 = _mm256_cvtepi16_epi32(_mm256_castsi256_si128(sum3)); + const __m256i s5 = _mm256_cvtepi16_epi32(_mm256_extracti128_si256(sum3, 1)); + + sum1 = _mm256_add_epi32(s0, s2); + sum2 = _mm256_add_epi32(s1, s3); + sum1 = _mm256_add_epi32(sum1, s4); + sum2 = _mm256_add_epi32(sum2, s5); + + // round and shift by 7 bit each 32 bit + // 0 1 2 3 4 5 6 7 + sum1 = _mm256_srai_epi32(sum1, FILTER_BITS); + // 8 9 10 11 12 13 14 15 + sum2 = _mm256_srai_epi32(sum2, FILTER_BITS); + + // 0 1 2 3 8 9 10 11 4 5 6 7 12 13 14 15 + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 + __m256i const res = + _mm256_permute4x64_epi64(_mm256_packus_epi32(sum1, sum2), 0xD8); + return res; +} + +void vpx_convolve12_horiz_avx2(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + assert(x_step_q4 == 16); + assert(w == 32 || w == 16 || w == 8); + (void)y0_q4; + (void)x_step_q4; + (void)y_step_q4; + const uint8_t *src_ptr = src; + src_ptr -= MAX_FILTER_TAP / 2 - 1; + __m256i s[6], f[6], src_mask[4]; + + shuffle_12tap_filter_avx2(filter[x0_q4], f); + src_mask[0] = _mm256_load_si256((__m256i const *)shuffle_src_mask1_avx2); + src_mask[1] = _mm256_load_si256((__m256i const *)shuffle_src_mask2_avx2); + src_mask[2] = _mm256_load_si256((__m256i const *)shuffle_src_mask3_avx2); + src_mask[3] = _mm256_load_si256((__m256i const *)shuffle_src_mask4_avx2); + if (w == 8) { + for (int i = 0; i < h; i += 4) { + // s00 s01 s02 s03 s04 s05 s06 s07 s08 s09 s010 s011 s012 s013 s014 s015 + const __m128i row0 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride]); + // s08 s09 s010 s011 s012 s013 s014 s015 s016 s017 s018 s019 s020 s021 + // s022 s023 + const __m128i row0_8 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride + 8]); + // s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s110 s111 s112 s113 s114 s115 + const __m128i row1 = + _mm_loadu_si128((const __m128i *)&src_ptr[(i + 1) * src_stride]); + const __m128i row1_8 = + _mm_loadu_si128((const __m128i *)&src_ptr[(i + 1) * src_stride + 8]); + // s20 s21 s22 s23 s24 s25 s26 s27 s28 s29 s210 s211 s212 s213 s214 s215 + const __m128i row2 = + _mm_loadu_si128((const __m128i *)&src_ptr[(i + 2) * src_stride]); + const __m128i row2_8 = + _mm_loadu_si128((const __m128i *)&src_ptr[(i + 2) * src_stride + 8]); + // s30 s31 s32 s33 s34 s35 s36 s37 s38 s39 s310 s311 s312 s313 s314 s115 + const __m128i row3 = + _mm_loadu_si128((const __m128i *)&src_ptr[(i + 3) * src_stride]); + const __m128i row3_8 = + _mm_loadu_si128((const __m128i *)&src_ptr[(i + 3) * src_stride + 8]); + // s00 s01 s02 s03 s04 s05 s06 s07 s08 s09 s010 s011 s012 s013 s014 s015 | + // s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s110 s111 s112 s113 s114 s115 + const __m256i row01 = + _mm256_inserti128_si256(_mm256_castsi128_si256(row0), row1, 1); + // s20 s21 s22 s23 s24 s25 s26 s27 s28 s29 s210 s211 s212 s213 s214 s215 | + // s30 s31 s32 s33 s34 s35 s36 s37 s38 s39 s310 s311 s312 s313 s314 s115 + const __m256i row23 = + _mm256_inserti128_si256(_mm256_castsi128_si256(row2), row3, 1); + // s08 s09 s010 s011 s012 s013 s014 s015 s016 s017 s018 s019 s020 s021 + // s022 s023 | s18 s19 s110 s111 s112 s113 s114 s115 s116 s117 s118 s119 + // s120 s121 s122 s123 + const __m256i row01_8 = + _mm256_inserti128_si256(_mm256_castsi128_si256(row0_8), row1_8, 1); + const __m256i row23_8 = + _mm256_inserti128_si256(_mm256_castsi128_si256(row2_8), row3_8, 1); + + shuffle_src_data_avx2(&row01, &row01_8, src_mask, s); + const __m256i res_0 = convolve12_16_avx2(s, f); + + shuffle_src_data_avx2(&row23, &row23_8, src_mask, s); + const __m256i res_1 = convolve12_16_avx2(s, f); + + // 00 01 02 03 04 05 06 07 | 10 11 12 13 14 15 16 17 | 08 09 010 011 012 + // 013 014 015 | 18 19 110 111 112 113 114 115 + const __m256i res = _mm256_packus_epi16(res_0, res_1); + const __m128i res_lo = _mm256_castsi256_si128(res); + const __m128i res_hi = _mm256_extracti128_si256(res, 1); + + _mm_storel_epi64((__m128i *)&dst[i * dst_stride], res_lo); + _mm_storel_epi64((__m128i *)&dst[(i + 1) * dst_stride], res_hi); + _mm_storel_epi64((__m128i *)&dst[(i + 2) * dst_stride], + _mm_srli_si128(res_lo, 8)); + _mm_storel_epi64((__m128i *)&dst[(i + 3) * dst_stride], + _mm_srli_si128(res_hi, 8)); + } + } else { + for (int j = 0; j < w; j += 16) { + for (int i = 0; i < h; i += 2) { + // s00 s01 s02 s03 s04 s05 s06 s07 s08 s09 s010 s011 s012 s013 s014 s015 + const __m128i row0 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride + j]); + // s016 s017 s018 s019 s020 s021 s022 s023 s024 s025 s026 s027 s028 s029 + // s030 s031 + const __m128i row0_16 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride + j + 16]); + // s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s110 s111 s112 s113 s114 + // s115 + const __m128i row1 = _mm_loadu_si128( + (const __m128i *)&src_ptr[(i + 1) * src_stride + j]); + // s116 s117 s118 s119 s120 s121 s122 s123 s124 s125 s126 s127 s128 + // s129 s130 s131 + const __m128i row1_16 = _mm_loadu_si128( + (const __m128i *)&src_ptr[(i + 1) * src_stride + j + 16]); + + // s00 s01 s02 s03 s04 s05 s06 s07 s08 s09 s010 s011 s012 s013 s014 s015 + // | s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s110 s111 s112 s113 s114 + // s115 + const __m256i r0 = + _mm256_inserti128_si256(_mm256_castsi128_si256(row0), row1, 1); + // s016 s017 s018 s019 s020 s021 s022 s023 s024 s025 s026 s027 s028 s029 + // s030 s031 | s116 s117 s118 s119 s120 s121 s122 s123 s124 s125 s126 + // s127 s128 s129 s130 s131 + const __m256i r2 = _mm256_inserti128_si256( + _mm256_castsi128_si256(row0_16), row1_16, 1); + + // s08 s09 s010 s011 s012 s013 s014 s015 s016 s017 s018 s019 s020 s021 + // s022 s023 | s18 s19 s110 s111 s112 s113 s114 s115 s116 s117 s118 s119 + // s120 s121 s122 s123 + const __m256i r1 = _mm256_alignr_epi8(r2, r0, 8); + + shuffle_src_data_avx2(&r0, &r1, src_mask, s); + const __m256i res_0 = convolve12_16_avx2(s, f); + + shuffle_src_data_avx2(&r1, &r2, src_mask, s); + const __m256i res_1 = convolve12_16_avx2(s, f); + + const __m256i res = _mm256_packus_epi16(res_0, res_1); + + _mm_storeu_si128((__m128i *)&dst[i * dst_stride + j], + _mm256_castsi256_si128(res)); + if (i + 1 < h) { + _mm_storeu_si128((__m128i *)&dst[(i + 1) * dst_stride + j], + _mm256_extracti128_si256(res, 1)); + } + } + } + } +} + +void vpx_convolve12_vert_avx2(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + assert(y_step_q4 == 16); + assert(h == 32 || h == 16 || h == 8); + assert(w == 32 || w == 16 || w == 8); + (void)x0_q4; + (void)x_step_q4; + (void)y_step_q4; + const uint8_t *src_ptr = src; + src_ptr -= src_stride * (MAX_FILTER_TAP / 2 - 1); + __m256i s[12], f[6]; + + shuffle_12tap_filter_avx2(filter[y0_q4], f); + if (w == 8) { + const __m128i s0 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 0 * src_stride)); + const __m128i s1 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 1 * src_stride)); + const __m128i s2 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 2 * src_stride)); + const __m128i s3 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 3 * src_stride)); + const __m128i s4 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 4 * src_stride)); + const __m128i s5 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 5 * src_stride)); + const __m128i s6 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 6 * src_stride)); + const __m128i s7 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 7 * src_stride)); + const __m128i s8 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 8 * src_stride)); + const __m128i s9 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 9 * src_stride)); + const __m128i s10t = + _mm_loadl_epi64((const __m128i *)(src_ptr + 10 * src_stride)); + + const __m256i r01 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s0), s1, 1); + const __m256i r12 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s1), s2, 1); + const __m256i r23 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s2), s3, 1); + const __m256i r34 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s3), s4, 1); + const __m256i r45 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s4), s5, 1); + const __m256i r56 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s5), s6, 1); + const __m256i r67 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s6), s7, 1); + const __m256i r78 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s7), s8, 1); + const __m256i r89 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s8), s9, 1); + const __m256i r910 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s9), s10t, 1); + + s[0] = _mm256_unpacklo_epi8(r01, r12); + s[1] = _mm256_unpacklo_epi8(r23, r34); + s[2] = _mm256_unpacklo_epi8(r45, r56); + s[3] = _mm256_unpacklo_epi8(r67, r78); + s[4] = _mm256_unpacklo_epi8(r89, r910); + for (int i = 0; i < h; i += 2) { + const __m128i s10 = + _mm_loadl_epi64((const __m128i *)(src_ptr + (i + 10) * src_stride)); + const __m128i s11 = + _mm_loadl_epi64((const __m128i *)(src_ptr + (i + 11) * src_stride)); + const __m128i s12 = + _mm_loadl_epi64((const __m128i *)(src_ptr + (i + 12) * src_stride)); + + const __m256i r1011 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s10), s11, 1); + const __m256i r1112 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s11), s12, 1); + s[5] = _mm256_unpacklo_epi8(r1011, r1112); + const __m256i res_0 = convolve12_16_avx2(s, f); + + __m256i res = _mm256_packus_epi16(res_0, res_0); + + _mm_storel_epi64((__m128i *)&dst[i * dst_stride], + _mm256_castsi256_si128(res)); + _mm_storel_epi64((__m128i *)&dst[(i + 1) * dst_stride], + _mm256_extracti128_si256(res, 1)); + + reuse_src_data_avx2(s + 1, s); + } + } else { + for (int j = 0; j < w; j += 16) { + const __m128i s0 = + _mm_loadu_si128((const __m128i *)(src_ptr + 0 * src_stride + j)); + const __m128i s1 = + _mm_loadu_si128((const __m128i *)(src_ptr + 1 * src_stride + j)); + const __m128i s2 = + _mm_loadu_si128((const __m128i *)(src_ptr + 2 * src_stride + j)); + const __m128i s3 = + _mm_loadu_si128((const __m128i *)(src_ptr + 3 * src_stride + j)); + const __m128i s4 = + _mm_loadu_si128((const __m128i *)(src_ptr + 4 * src_stride + j)); + const __m128i s5 = + _mm_loadu_si128((const __m128i *)(src_ptr + 5 * src_stride + j)); + const __m128i s6 = + _mm_loadu_si128((const __m128i *)(src_ptr + 6 * src_stride + j)); + const __m128i s7 = + _mm_loadu_si128((const __m128i *)(src_ptr + 7 * src_stride + j)); + const __m128i s8 = + _mm_loadu_si128((const __m128i *)(src_ptr + 8 * src_stride + j)); + const __m128i s9 = + _mm_loadu_si128((const __m128i *)(src_ptr + 9 * src_stride + j)); + const __m128i s10t = + _mm_loadu_si128((const __m128i *)(src_ptr + 10 * src_stride + j)); + + const __m256i r01 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s0), s1, 1); + const __m256i r12 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s1), s2, 1); + const __m256i r23 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s2), s3, 1); + const __m256i r34 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s3), s4, 1); + const __m256i r45 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s4), s5, 1); + const __m256i r56 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s5), s6, 1); + const __m256i r67 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s6), s7, 1); + const __m256i r78 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s7), s8, 1); + const __m256i r89 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s8), s9, 1); + const __m256i r910 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s9), s10t, 1); + + s[0] = _mm256_unpacklo_epi8(r01, r12); + s[1] = _mm256_unpacklo_epi8(r23, r34); + s[2] = _mm256_unpacklo_epi8(r45, r56); + s[3] = _mm256_unpacklo_epi8(r67, r78); + s[4] = _mm256_unpacklo_epi8(r89, r910); + + s[6] = _mm256_unpackhi_epi8(r01, r12); + s[7] = _mm256_unpackhi_epi8(r23, r34); + s[8] = _mm256_unpackhi_epi8(r45, r56); + s[9] = _mm256_unpackhi_epi8(r67, r78); + s[10] = _mm256_unpackhi_epi8(r89, r910); + for (int i = 0; i < h; i += 2) { + const __m128i s10 = _mm_loadu_si128( + (const __m128i *)(src_ptr + (i + 10) * src_stride + j)); + const __m128i s11 = _mm_loadu_si128( + (const __m128i *)(src_ptr + (i + 11) * src_stride + j)); + const __m128i s12 = _mm_loadu_si128( + (const __m128i *)(src_ptr + (i + 12) * src_stride + j)); + + const __m256i r1011 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s10), s11, 1); + const __m256i r1112 = + _mm256_inserti128_si256(_mm256_castsi128_si256(s11), s12, 1); + + s[5] = _mm256_unpacklo_epi8(r1011, r1112); + s[11] = _mm256_unpackhi_epi8(r1011, r1112); + + const __m256i res_0 = convolve12_16_avx2(s, f); + const __m256i res_1 = convolve12_16_avx2(s + 6, f); + + __m256i res = _mm256_packus_epi16(res_0, res_1); + + _mm_storeu_si128((__m128i *)&dst[i * dst_stride + j], + _mm256_castsi256_si128(res)); + _mm_storeu_si128((__m128i *)&dst[(i + 1) * dst_stride + j], + _mm256_extracti128_si256(res, 1)); + + reuse_src_data_avx2(s + 1, s); + reuse_src_data_avx2(s + 7, s + 6); + } + } + } +} + +void vpx_convolve12_avx2(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, const InterpKernel12 *filter, + int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + assert(x_step_q4 == 16 && y_step_q4 == 16); + assert(h == 32 || h == 16 || h == 8); + assert(w == 32 || w == 16 || w == 8); + DECLARE_ALIGNED(32, uint8_t, temp[BW * (BH + MAX_FILTER_TAP - 1)]); + const int temp_stride = BW; + const int intermediate_height = + (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + MAX_FILTER_TAP; + vpx_convolve12_horiz_avx2(src - src_stride * (MAX_FILTER_TAP / 2 - 1), + src_stride, temp, temp_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, + intermediate_height); + vpx_convolve12_vert_avx2(temp + temp_stride * (MAX_FILTER_TAP / 2 - 1), + temp_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h); +} diff --git a/libs/libvpx/vp9/encoder/x86/temporal_filter_sse4.c b/libs/libvpx/vp9/encoder/x86/temporal_filter_sse4.c index 87e68fb438..7571bfccac 100644 --- a/libs/libvpx/vp9/encoder/x86/temporal_filter_sse4.c +++ b/libs/libvpx/vp9/encoder/x86/temporal_filter_sse4.c @@ -16,7 +16,7 @@ #include "vpx/vpx_integer.h" #include "vp9/encoder/vp9_encoder.h" #include "vp9/encoder/vp9_temporal_filter.h" -#include "vp9/encoder/x86/temporal_filter_constants.h" +#include "vp9/encoder/vp9_temporal_filter_constants.h" // Read in 8 pixels from a and b as 8-bit unsigned integers, compute the // difference squared, and store as unsigned 16-bit integer to dst. diff --git a/libs/libvpx/vp9/encoder/x86/temporal_filter_ssse3.c b/libs/libvpx/vp9/encoder/x86/temporal_filter_ssse3.c new file mode 100644 index 0000000000..abf0ae1381 --- /dev/null +++ b/libs/libvpx/vp9/encoder/x86/temporal_filter_ssse3.c @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include // SSSE3 + +#include "./vp9_rtcd.h" +#include "./vpx_dsp_rtcd.h" +#include "vp9/encoder/vp9_temporal_filter.h" + +DECLARE_ALIGNED(16, static const uint8_t, + shuffle_src_mask1_ssse3[32]) = { 0, 1, 1, 2, 2, 3, 3, 4, + 4, 5, 5, 6, 6, 7, 7, 8 }; + +DECLARE_ALIGNED(16, static const uint8_t, + shuffle_src_mask2_ssse3[32]) = { 2, 3, 3, 4, 4, 5, 5, 6, + 6, 7, 7, 8, 8, 9, 9, 10 }; + +DECLARE_ALIGNED(16, static const uint8_t, + shuffle_src_mask3_ssse3[32]) = { 4, 5, 5, 6, 6, 7, 7, 8, + 8, 9, 9, 10, 10, 11, 11, 12 }; + +DECLARE_ALIGNED(16, static const uint8_t, shuffle_src_mask4_ssse3[32]) = { + 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14 +}; + +static INLINE void sign_extend_16bit_to_32bit_ssse3(__m128i in, __m128i zero, + __m128i *out_lo, + __m128i *out_hi) { + const __m128i sign_bits = _mm_cmpgt_epi16(zero, in); + *out_lo = _mm_unpacklo_epi16(in, sign_bits); + *out_hi = _mm_unpackhi_epi16(in, sign_bits); +} + +static INLINE void shuffle_12tap_filter_ssse3(const int16_t *filter, + __m128i *f) { + const __m128i f_low = _mm_loadu_si128((const __m128i *)filter); + const __m128i f_high = _mm_loadl_epi64((const __m128i *)(filter + 8)); + + f[0] = _mm_shuffle_epi8(f_low, _mm_set1_epi16(0x0200u)); + f[1] = _mm_shuffle_epi8(f_low, _mm_set1_epi16(0x0604u)); + f[2] = _mm_shuffle_epi8(f_low, _mm_set1_epi16(0x0a08u)); + f[3] = _mm_shuffle_epi8(f_low, _mm_set1_epi16(0x0e0cu)); + f[4] = _mm_shuffle_epi8(f_high, _mm_set1_epi16(0x0200u)); + f[5] = _mm_shuffle_epi8(f_high, _mm_set1_epi16(0x0604u)); +} + +static INLINE void shuffle_src_data_ssse3(const __m128i *r1, const __m128i *r2, + const __m128i *f, __m128i *s) { + s[0] = _mm_shuffle_epi8(*r1, f[0]); + s[1] = _mm_shuffle_epi8(*r1, f[1]); + s[2] = _mm_shuffle_epi8(*r1, f[2]); + s[3] = _mm_shuffle_epi8(*r1, f[3]); + s[4] = _mm_shuffle_epi8(*r2, f[0]); + s[5] = _mm_shuffle_epi8(*r2, f[1]); +} + +static INLINE void reuse_src_data_ssse3(const __m128i *src, __m128i *des) { + des[0] = src[0]; + des[1] = src[1]; + des[2] = src[2]; + des[3] = src[3]; + des[4] = src[4]; +} + +static INLINE __m128i convolve12_16_ssse3(const __m128i *const s, + const __m128i *const f) { + // multiply 2 adjacent elements with the filter and add the result + const __m128i k_64 = _mm_set1_epi16(1 << (FILTER_BITS - 1)); + const __m128i x0 = _mm_maddubs_epi16(s[0], f[0]); + const __m128i x1 = _mm_maddubs_epi16(s[1], f[1]); + const __m128i x2 = _mm_maddubs_epi16(s[2], f[2]); + const __m128i x3 = _mm_maddubs_epi16(s[3], f[3]); + const __m128i x4 = _mm_maddubs_epi16(s[4], f[4]); + const __m128i x5 = _mm_maddubs_epi16(s[5], f[5]); + __m128i sum1, sum2, sum3, s0, s1, s2, s3, s4, s5; + + sum1 = _mm_add_epi16(x0, x2); + sum2 = _mm_add_epi16(x3, x5); + sum3 = _mm_add_epi16(x1, x4); + sum3 = _mm_add_epi16(sum3, k_64); + + sign_extend_16bit_to_32bit_ssse3(sum1, _mm_setzero_si128(), &s0, &s1); + sign_extend_16bit_to_32bit_ssse3(sum2, _mm_setzero_si128(), &s2, &s3); + sign_extend_16bit_to_32bit_ssse3(sum3, _mm_setzero_si128(), &s4, &s5); + sum1 = _mm_add_epi32(s0, s2); + sum2 = _mm_add_epi32(s1, s3); + sum1 = _mm_add_epi32(sum1, s4); + sum2 = _mm_add_epi32(sum2, s5); + + // round and shift by 7 bit each 32 bit + // 0 1 2 3 + sum1 = _mm_srai_epi32(sum1, FILTER_BITS); + // 4 5 6 7 + sum2 = _mm_srai_epi32(sum2, FILTER_BITS); + + // 0 1 2 3 4 5 6 7 + __m128i const res = _mm_packs_epi32(sum1, sum2); + return res; +} + +void vpx_convolve12_horiz_ssse3(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + assert(x_step_q4 == 16); + assert(w == 32 || w == 16 || w == 8); + (void)y0_q4; + (void)x_step_q4; + (void)y_step_q4; + const uint8_t *src_ptr = src; + src_ptr -= MAX_FILTER_TAP / 2 - 1; + __m128i s[6], f[6], src_mask[4]; + + shuffle_12tap_filter_ssse3(filter[x0_q4], f); + src_mask[0] = _mm_load_si128((__m128i const *)shuffle_src_mask1_ssse3); + src_mask[1] = _mm_load_si128((__m128i const *)shuffle_src_mask2_ssse3); + src_mask[2] = _mm_load_si128((__m128i const *)shuffle_src_mask3_ssse3); + src_mask[3] = _mm_load_si128((__m128i const *)shuffle_src_mask4_ssse3); + if (w == 8) { + for (int i = 0; i < h; i += 2) { + // s00 s01 s02 s03 s04 s05 s06 s07 s08 s09 s010 s011 s012 s013 s014 s015 + const __m128i row0 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride]); + // s08 s09 s010 s011 s012 s013 s014 s015 s016 s017 s018 s019 s020 s021 + // s022 s023 + const __m128i row0_8 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride + 8]); + // s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s110 s111 s112 s113 s114 s115 + const __m128i row1 = + _mm_loadu_si128((const __m128i *)&src_ptr[(i + 1) * src_stride]); + const __m128i row1_8 = + _mm_loadu_si128((const __m128i *)&src_ptr[(i + 1) * src_stride + 8]); + + shuffle_src_data_ssse3(&row0, &row0_8, src_mask, s); + const __m128i res_0 = convolve12_16_ssse3(s, f); + + shuffle_src_data_ssse3(&row1, &row1_8, src_mask, s); + const __m128i res_1 = convolve12_16_ssse3(s, f); + + const __m128i res = _mm_packus_epi16(res_0, res_1); + _mm_storel_epi64((__m128i *)&dst[i * dst_stride], res); + _mm_storel_epi64((__m128i *)&dst[(i + 1) * dst_stride], + _mm_srli_si128(res, 8)); + } + } else { + for (int j = 0; j < w; j += 16) { + for (int i = 0; i < h; i++) { + // s00 s01 s02 s03 s04 s05 s06 s07 s08 s09 s010 s011 s012 s013 s014 s015 + const __m128i r0 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride + j]); + // s016 s017 s018 s019 s020 s021 s022 s023 s024 s025 s026 s027 s028 s029 + // s030 s031 + const __m128i r2 = + _mm_loadu_si128((const __m128i *)&src_ptr[i * src_stride + j + 16]); + + // s08 s09 s010 s011 s012 s013 s014 s015 s016 s017 s018 s019 s020 s021 + // s022 s023 + const __m128i r1 = _mm_alignr_epi8(r2, r0, 8); + + shuffle_src_data_ssse3(&r0, &r1, src_mask, s); + const __m128i res_0 = convolve12_16_ssse3(s, f); + + shuffle_src_data_ssse3(&r1, &r2, src_mask, s); + const __m128i res_1 = convolve12_16_ssse3(s, f); + + const __m128i res = _mm_packus_epi16(res_0, res_1); + _mm_storeu_si128((__m128i *)&dst[i * dst_stride + j], res); + } + } + } +} + +void vpx_convolve12_vert_ssse3(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + assert(y_step_q4 == 16); + assert(h == 32 || h == 16 || h == 8); + assert(w == 32 || w == 16 || w == 8); + (void)x0_q4; + (void)x_step_q4; + (void)y_step_q4; + const uint8_t *src_ptr = src; + src_ptr -= src_stride * (MAX_FILTER_TAP / 2 - 1); + __m128i s[12], f[6]; + + shuffle_12tap_filter_ssse3(filter[y0_q4], f); + for (int j = 0; j < w; j += 8) { + const __m128i s0 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 0 * src_stride + j)); + const __m128i s1 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 1 * src_stride + j)); + const __m128i s2 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 2 * src_stride + j)); + const __m128i s3 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 3 * src_stride + j)); + const __m128i s4 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 4 * src_stride + j)); + const __m128i s5 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 5 * src_stride + j)); + const __m128i s6 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 6 * src_stride + j)); + const __m128i s7 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 7 * src_stride + j)); + const __m128i s8 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 8 * src_stride + j)); + const __m128i s9 = + _mm_loadl_epi64((const __m128i *)(src_ptr + 9 * src_stride + j)); + const __m128i s10t = + _mm_loadl_epi64((const __m128i *)(src_ptr + 10 * src_stride + j)); + + // 00 10 01 11 02 12 03 13 04 14 05 15 06 16 07 17 + s[0] = _mm_unpacklo_epi8(s0, s1); + s[1] = _mm_unpacklo_epi8(s2, s3); + s[2] = _mm_unpacklo_epi8(s4, s5); + s[3] = _mm_unpacklo_epi8(s6, s7); + s[4] = _mm_unpacklo_epi8(s8, s9); + + s[6] = _mm_unpacklo_epi8(s1, s2); + s[7] = _mm_unpacklo_epi8(s3, s4); + s[8] = _mm_unpacklo_epi8(s5, s6); + s[9] = _mm_unpacklo_epi8(s7, s8); + s[10] = _mm_unpacklo_epi8(s9, s10t); + for (int i = 0; i < h; i += 2) { + const __m128i s10 = _mm_loadl_epi64( + (const __m128i *)(src_ptr + (i + 10) * src_stride + j)); + const __m128i s11 = _mm_loadl_epi64( + (const __m128i *)(src_ptr + (i + 11) * src_stride + j)); + const __m128i s12 = _mm_loadl_epi64( + (const __m128i *)(src_ptr + (i + 12) * src_stride + j)); + + s[5] = _mm_unpacklo_epi8(s10, s11); + s[11] = _mm_unpacklo_epi8(s11, s12); + + const __m128i res_0 = convolve12_16_ssse3(s, f); + const __m128i res_1 = convolve12_16_ssse3(s + 6, f); + + __m128i res = _mm_packus_epi16(res_0, res_1); + + _mm_storel_epi64((__m128i *)&dst[i * dst_stride + j], res); + _mm_storel_epi64((__m128i *)&dst[(i + 1) * dst_stride + j], + _mm_srli_si128(res, 8)); + + reuse_src_data_ssse3(s + 1, s); + reuse_src_data_ssse3(s + 7, s + 6); + } + } +} + +void vpx_convolve12_ssse3(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel12 *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + assert(x_step_q4 == 16 && y_step_q4 == 16); + assert(h == 32 || h == 16 || h == 8); + assert(w == 32 || w == 16 || w == 8); + DECLARE_ALIGNED(32, uint8_t, temp[BW * (BH + MAX_FILTER_TAP - 1)]); + const int temp_stride = BW; + const int intermediate_height = + (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + MAX_FILTER_TAP; + vpx_convolve12_horiz_ssse3(src - src_stride * (MAX_FILTER_TAP / 2 - 1), + src_stride, temp, temp_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, + intermediate_height); + vpx_convolve12_vert_ssse3(temp + temp_stride * (MAX_FILTER_TAP / 2 - 1), + temp_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h); +} diff --git a/libs/libvpx/vp9/encoder/x86/vp9_dct_intrin_sse2.c b/libs/libvpx/vp9/encoder/x86/vp9_dct_intrin_sse2.c index 2188903b17..e9943447fd 100644 --- a/libs/libvpx/vp9/encoder/x86/vp9_dct_intrin_sse2.c +++ b/libs/libvpx/vp9/encoder/x86/vp9_dct_intrin_sse2.c @@ -111,7 +111,7 @@ static void fadst4_sse2(__m128i *in) { const __m128i k__sinpi_p03_p04 = pair_set_epi16(sinpi_3_9, sinpi_4_9); const __m128i k__sinpi_m03_p02 = pair_set_epi16(-sinpi_3_9, sinpi_2_9); const __m128i k__sinpi_p03_p03 = _mm_set1_epi16((int16_t)sinpi_3_9); - const __m128i kZero = _mm_set1_epi16(0); + const __m128i kZero = _mm_setzero_si128(); const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING); __m128i u[8], v[8]; __m128i in7 = _mm_add_epi16(in[0], in[1]); @@ -424,7 +424,7 @@ static void fadst8_sse2(__m128i *in) { const __m128i k__cospi_m24_p08 = pair_set_epi16(-cospi_24_64, cospi_8_64); const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64); const __m128i k__cospi_p16_p16 = _mm_set1_epi16(cospi_16_64); - const __m128i k__const_0 = _mm_set1_epi16(0); + const __m128i k__const_0 = _mm_setzero_si128(); const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING); __m128i u0, u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, u11, u12, u13, u14, u15; @@ -1056,7 +1056,7 @@ static void fadst16_8col(__m128i *in) { const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64); const __m128i k__cospi_m16_p16 = pair_set_epi16(-cospi_16_64, cospi_16_64); const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING); - const __m128i kZero = _mm_set1_epi16(0); + const __m128i kZero = _mm_setzero_si128(); u[0] = _mm_unpacklo_epi16(in[15], in[0]); u[1] = _mm_unpackhi_epi16(in[15], in[0]); diff --git a/libs/libvpx/vp9/encoder/x86/vp9_diamond_search_sad_avx.c b/libs/libvpx/vp9/encoder/x86/vp9_diamond_search_sad_avx.c deleted file mode 100644 index fcf50eb2a7..0000000000 --- a/libs/libvpx/vp9/encoder/x86/vp9_diamond_search_sad_avx.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (c) 2015 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#if defined(_MSC_VER) -#include -#endif -#include -#include - -#include "vpx_dsp/vpx_dsp_common.h" -#include "vp9/encoder/vp9_encoder.h" -#include "vpx_ports/mem.h" - -#ifdef __GNUC__ -#define LIKELY(v) __builtin_expect(v, 1) -#define UNLIKELY(v) __builtin_expect(v, 0) -#else -#define LIKELY(v) (v) -#define UNLIKELY(v) (v) -#endif - -static INLINE int_mv pack_int_mv(int16_t row, int16_t col) { - int_mv result; - result.as_mv.row = row; - result.as_mv.col = col; - return result; -} - -static INLINE MV_JOINT_TYPE get_mv_joint(const int_mv mv) { - // This is simplified from the C implementation to utilise that - // x->nmvjointsadcost[1] == x->nmvjointsadcost[2] and - // x->nmvjointsadcost[1] == x->nmvjointsadcost[3] - return mv.as_int == 0 ? 0 : 1; -} - -static INLINE int mv_cost(const int_mv mv, const int *joint_cost, - int *const comp_cost[2]) { - return joint_cost[get_mv_joint(mv)] + comp_cost[0][mv.as_mv.row] + - comp_cost[1][mv.as_mv.col]; -} - -static int mvsad_err_cost(const MACROBLOCK *x, const int_mv mv, const MV *ref, - int sad_per_bit) { - const int_mv diff = - pack_int_mv(mv.as_mv.row - ref->row, mv.as_mv.col - ref->col); - return ROUND_POWER_OF_TWO( - (unsigned)mv_cost(diff, x->nmvjointsadcost, x->nmvsadcost) * sad_per_bit, - VP9_PROB_COST_SHIFT); -} - -/***************************************************************************** - * This function utilizes 3 properties of the cost function lookup tables, * - * constructed in using 'cal_nmvjointsadcost' and 'cal_nmvsadcosts' in * - * vp9_encoder.c. * - * For the joint cost: * - * - mvjointsadcost[1] == mvjointsadcost[2] == mvjointsadcost[3] * - * For the component costs: * - * - For all i: mvsadcost[0][i] == mvsadcost[1][i] * - * (Equal costs for both components) * - * - For all i: mvsadcost[0][i] == mvsadcost[0][-i] * - * (Cost function is even) * - * If these do not hold, then this function cannot be used without * - * modification, in which case you can revert to using the C implementation, * - * which does not rely on these properties. * - *****************************************************************************/ -int vp9_diamond_search_sad_avx(const MACROBLOCK *x, - const search_site_config *cfg, MV *ref_mv, - MV *best_mv, int search_param, int sad_per_bit, - int *num00, const vp9_variance_fn_ptr_t *fn_ptr, - const MV *center_mv) { - const int_mv maxmv = pack_int_mv(x->mv_limits.row_max, x->mv_limits.col_max); - const __m128i v_max_mv_w = _mm_set1_epi32(maxmv.as_int); - const int_mv minmv = pack_int_mv(x->mv_limits.row_min, x->mv_limits.col_min); - const __m128i v_min_mv_w = _mm_set1_epi32(minmv.as_int); - - const __m128i v_spb_d = _mm_set1_epi32(sad_per_bit); - - const __m128i v_joint_cost_0_d = _mm_set1_epi32(x->nmvjointsadcost[0]); - const __m128i v_joint_cost_1_d = _mm_set1_epi32(x->nmvjointsadcost[1]); - - // search_param determines the length of the initial step and hence the number - // of iterations. - // 0 = initial step (MAX_FIRST_STEP) pel - // 1 = (MAX_FIRST_STEP/2) pel, - // 2 = (MAX_FIRST_STEP/4) pel... - const MV *ss_mv = &cfg->ss_mv[cfg->searches_per_step * search_param]; - const intptr_t *ss_os = &cfg->ss_os[cfg->searches_per_step * search_param]; - const int tot_steps = cfg->total_steps - search_param; - - const int_mv fcenter_mv = - pack_int_mv(center_mv->row >> 3, center_mv->col >> 3); - const __m128i vfcmv = _mm_set1_epi32(fcenter_mv.as_int); - - const int ref_row = clamp(ref_mv->row, minmv.as_mv.row, maxmv.as_mv.row); - const int ref_col = clamp(ref_mv->col, minmv.as_mv.col, maxmv.as_mv.col); - - int_mv bmv = pack_int_mv(ref_row, ref_col); - int_mv new_bmv = bmv; - __m128i v_bmv_w = _mm_set1_epi32(bmv.as_int); - - const int what_stride = x->plane[0].src.stride; - const int in_what_stride = x->e_mbd.plane[0].pre[0].stride; - const uint8_t *const what = x->plane[0].src.buf; - const uint8_t *const in_what = - x->e_mbd.plane[0].pre[0].buf + ref_row * in_what_stride + ref_col; - - // Work out the start point for the search - const uint8_t *best_address = in_what; - const uint8_t *new_best_address = best_address; -#if VPX_ARCH_X86_64 - __m128i v_ba_q = _mm_set1_epi64x((intptr_t)best_address); -#else - __m128i v_ba_d = _mm_set1_epi32((intptr_t)best_address); -#endif - - unsigned int best_sad; - int i, j, step; - - // Check the prerequisite cost function properties that are easy to check - // in an assert. See the function-level documentation for details on all - // prerequisites. - assert(x->nmvjointsadcost[1] == x->nmvjointsadcost[2]); - assert(x->nmvjointsadcost[1] == x->nmvjointsadcost[3]); - - // Check the starting position - best_sad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride); - best_sad += mvsad_err_cost(x, bmv, &fcenter_mv.as_mv, sad_per_bit); - - *num00 = 0; - - for (i = 0, step = 0; step < tot_steps; step++) { - for (j = 0; j < cfg->searches_per_step; j += 4, i += 4) { - __m128i v_sad_d, v_cost_d, v_outside_d, v_inside_d, v_diff_mv_w; -#if VPX_ARCH_X86_64 - __m128i v_blocka[2]; -#else - __m128i v_blocka[1]; -#endif - - // Compute the candidate motion vectors - const __m128i v_ss_mv_w = _mm_loadu_si128((const __m128i *)&ss_mv[i]); - const __m128i v_these_mv_w = _mm_add_epi16(v_bmv_w, v_ss_mv_w); - // Clamp them to the search bounds - __m128i v_these_mv_clamp_w = v_these_mv_w; - v_these_mv_clamp_w = _mm_min_epi16(v_these_mv_clamp_w, v_max_mv_w); - v_these_mv_clamp_w = _mm_max_epi16(v_these_mv_clamp_w, v_min_mv_w); - // The ones that did not change are inside the search area - v_inside_d = _mm_cmpeq_epi32(v_these_mv_clamp_w, v_these_mv_w); - - // If none of them are inside, then move on - if (LIKELY(_mm_test_all_zeros(v_inside_d, v_inside_d))) { - continue; - } - - // The inverse mask indicates which of the MVs are outside - v_outside_d = _mm_xor_si128(v_inside_d, _mm_set1_epi8((int8_t)0xff)); - // Shift right to keep the sign bit clear, we will use this later - // to set the cost to the maximum value. - v_outside_d = _mm_srli_epi32(v_outside_d, 1); - - // Compute the difference MV - v_diff_mv_w = _mm_sub_epi16(v_these_mv_clamp_w, vfcmv); - // We utilise the fact that the cost function is even, and use the - // absolute difference. This allows us to use unsigned indexes later - // and reduces cache pressure somewhat as only a half of the table - // is ever referenced. - v_diff_mv_w = _mm_abs_epi16(v_diff_mv_w); - - // Compute the SIMD pointer offsets. - { -#if VPX_ARCH_X86_64 // sizeof(intptr_t) == 8 - // Load the offsets - __m128i v_bo10_q = _mm_loadu_si128((const __m128i *)&ss_os[i + 0]); - __m128i v_bo32_q = _mm_loadu_si128((const __m128i *)&ss_os[i + 2]); - // Set the ones falling outside to zero - v_bo10_q = _mm_and_si128(v_bo10_q, _mm_cvtepi32_epi64(v_inside_d)); - v_bo32_q = - _mm_and_si128(v_bo32_q, _mm_unpackhi_epi32(v_inside_d, v_inside_d)); - // Compute the candidate addresses - v_blocka[0] = _mm_add_epi64(v_ba_q, v_bo10_q); - v_blocka[1] = _mm_add_epi64(v_ba_q, v_bo32_q); -#else // VPX_ARCH_X86 // sizeof(intptr_t) == 4 - __m128i v_bo_d = _mm_loadu_si128((const __m128i *)&ss_os[i]); - v_bo_d = _mm_and_si128(v_bo_d, v_inside_d); - v_blocka[0] = _mm_add_epi32(v_ba_d, v_bo_d); -#endif - } - - fn_ptr->sdx4df(what, what_stride, (const uint8_t **)&v_blocka[0], - in_what_stride, (uint32_t *)&v_sad_d); - - // Look up the component cost of the residual motion vector - { - const int32_t row0 = _mm_extract_epi16(v_diff_mv_w, 0); - const int32_t col0 = _mm_extract_epi16(v_diff_mv_w, 1); - const int32_t row1 = _mm_extract_epi16(v_diff_mv_w, 2); - const int32_t col1 = _mm_extract_epi16(v_diff_mv_w, 3); - const int32_t row2 = _mm_extract_epi16(v_diff_mv_w, 4); - const int32_t col2 = _mm_extract_epi16(v_diff_mv_w, 5); - const int32_t row3 = _mm_extract_epi16(v_diff_mv_w, 6); - const int32_t col3 = _mm_extract_epi16(v_diff_mv_w, 7); - - // Note: This is a use case for vpgather in AVX2 - const uint32_t cost0 = x->nmvsadcost[0][row0] + x->nmvsadcost[0][col0]; - const uint32_t cost1 = x->nmvsadcost[0][row1] + x->nmvsadcost[0][col1]; - const uint32_t cost2 = x->nmvsadcost[0][row2] + x->nmvsadcost[0][col2]; - const uint32_t cost3 = x->nmvsadcost[0][row3] + x->nmvsadcost[0][col3]; - - __m128i v_cost_10_d, v_cost_32_d; - v_cost_10_d = _mm_cvtsi32_si128(cost0); - v_cost_10_d = _mm_insert_epi32(v_cost_10_d, cost1, 1); - v_cost_32_d = _mm_cvtsi32_si128(cost2); - v_cost_32_d = _mm_insert_epi32(v_cost_32_d, cost3, 1); - v_cost_d = _mm_unpacklo_epi64(v_cost_10_d, v_cost_32_d); - } - - // Now add in the joint cost - { - const __m128i v_sel_d = - _mm_cmpeq_epi32(v_diff_mv_w, _mm_setzero_si128()); - const __m128i v_joint_cost_d = - _mm_blendv_epi8(v_joint_cost_1_d, v_joint_cost_0_d, v_sel_d); - v_cost_d = _mm_add_epi32(v_cost_d, v_joint_cost_d); - } - - // Multiply by sad_per_bit - v_cost_d = _mm_mullo_epi32(v_cost_d, v_spb_d); - // ROUND_POWER_OF_TWO(v_cost_d, VP9_PROB_COST_SHIFT) - v_cost_d = _mm_add_epi32(v_cost_d, - _mm_set1_epi32(1 << (VP9_PROB_COST_SHIFT - 1))); - v_cost_d = _mm_srai_epi32(v_cost_d, VP9_PROB_COST_SHIFT); - // Add the cost to the sad - v_sad_d = _mm_add_epi32(v_sad_d, v_cost_d); - - // Make the motion vectors outside the search area have max cost - // by or'ing in the comparison mask, this way the minimum search won't - // pick them. - v_sad_d = _mm_or_si128(v_sad_d, v_outside_d); - - // Find the minimum value and index horizontally in v_sad_d - { - // Try speculatively on 16 bits, so we can use the minpos intrinsic - const __m128i v_sad_w = _mm_packus_epi32(v_sad_d, v_sad_d); - const __m128i v_minp_w = _mm_minpos_epu16(v_sad_w); - - uint32_t local_best_sad = _mm_extract_epi16(v_minp_w, 0); - uint32_t local_best_idx = _mm_extract_epi16(v_minp_w, 1); - - // If the local best value is not saturated, just use it, otherwise - // find the horizontal minimum again the hard way on 32 bits. - // This is executed rarely. - if (UNLIKELY(local_best_sad == 0xffff)) { - __m128i v_loval_d, v_hival_d, v_loidx_d, v_hiidx_d, v_sel_d; - - v_loval_d = v_sad_d; - v_loidx_d = _mm_set_epi32(3, 2, 1, 0); - v_hival_d = _mm_srli_si128(v_loval_d, 8); - v_hiidx_d = _mm_srli_si128(v_loidx_d, 8); - - v_sel_d = _mm_cmplt_epi32(v_hival_d, v_loval_d); - - v_loval_d = _mm_blendv_epi8(v_loval_d, v_hival_d, v_sel_d); - v_loidx_d = _mm_blendv_epi8(v_loidx_d, v_hiidx_d, v_sel_d); - v_hival_d = _mm_srli_si128(v_loval_d, 4); - v_hiidx_d = _mm_srli_si128(v_loidx_d, 4); - - v_sel_d = _mm_cmplt_epi32(v_hival_d, v_loval_d); - - v_loval_d = _mm_blendv_epi8(v_loval_d, v_hival_d, v_sel_d); - v_loidx_d = _mm_blendv_epi8(v_loidx_d, v_hiidx_d, v_sel_d); - - local_best_sad = _mm_extract_epi32(v_loval_d, 0); - local_best_idx = _mm_extract_epi32(v_loidx_d, 0); - } - - // Update the global minimum if the local minimum is smaller - if (LIKELY(local_best_sad < best_sad)) { -#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif - new_bmv = ((const int_mv *)&v_these_mv_w)[local_best_idx]; -#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__clang__) -#pragma GCC diagnostic pop -#endif - new_best_address = ((const uint8_t **)v_blocka)[local_best_idx]; - - best_sad = local_best_sad; - } - } - } - - bmv = new_bmv; - best_address = new_best_address; - - v_bmv_w = _mm_set1_epi32(bmv.as_int); -#if VPX_ARCH_X86_64 - v_ba_q = _mm_set1_epi64x((intptr_t)best_address); -#else - v_ba_d = _mm_set1_epi32((intptr_t)best_address); -#endif - - if (UNLIKELY(best_address == in_what)) { - (*num00)++; - } - } - - *best_mv = bmv.as_mv; - return best_sad; -} diff --git a/libs/libvpx/vp9/encoder/x86/vp9_frame_scale_ssse3.c b/libs/libvpx/vp9/encoder/x86/vp9_frame_scale_ssse3.c index 7685e7bc3e..628dc4fead 100644 --- a/libs/libvpx/vp9/encoder/x86/vp9_frame_scale_ssse3.c +++ b/libs/libvpx/vp9/encoder/x86/vp9_frame_scale_ssse3.c @@ -469,18 +469,18 @@ static void scale_plane_4_to_3_general(const uint8_t *src, const int src_stride, // It's used to choose the src offset and filter coefficient offset. const int offset_idx1 = (offset1_q4 >> 4) & 1; const int offset_idx2 = (offset2_q4 >> 4) & 1; - static const shuffle_filter_funcs shuffle_filter_funcs[2] = { + static const shuffle_filter_funcs kShuffleFilterFuncs[2] = { shuffle_filter_ssse3, shuffle_filter_odd_ssse3 }; - static const convolve8_funcs convolve8_funcs[2] = { + static const convolve8_funcs kConvolve8Funcs[2] = { convolve8_8_even_offset_ssse3, convolve8_8_odd_offset_ssse3 }; assert(w && h); shuffle_filter_ssse3(coef[(phase_scaler + 0 * step_q4) & SUBPEL_MASK], f0); - shuffle_filter_funcs[offset_idx1](coef[offset1_q4 & SUBPEL_MASK], f1); - shuffle_filter_funcs[offset_idx2](coef[offset2_q4 & SUBPEL_MASK], f2); + kShuffleFilterFuncs[offset_idx1](coef[offset1_q4 & SUBPEL_MASK], f1); + kShuffleFilterFuncs[offset_idx2](coef[offset2_q4 & SUBPEL_MASK], f2); // Sub 64 to avoid overflow. // Coef 128 would be treated as -128 in PMADDUBSW. Sub 64 here. @@ -522,11 +522,11 @@ static void scale_plane_4_to_3_general(const uint8_t *src, const int src_stride, // 04 14 24 34 44 54 64 74 // 05 15 25 35 45 55 65 75 d[0] = convolve8_8_even_offset_ssse3(&s[0], f0); - d[1] = convolve8_funcs[offset_idx1](&s[offset1_q4 >> 5], f1); - d[2] = convolve8_funcs[offset_idx2](&s[offset2_q4 >> 5], f2); + d[1] = kConvolve8Funcs[offset_idx1](&s[offset1_q4 >> 5], f1); + d[2] = kConvolve8Funcs[offset_idx2](&s[offset2_q4 >> 5], f2); d[3] = convolve8_8_even_offset_ssse3(&s[2], f0); - d[4] = convolve8_funcs[offset_idx1](&s[2 + (offset1_q4 >> 5)], f1); - d[5] = convolve8_funcs[offset_idx2](&s[2 + (offset2_q4 >> 5)], f2); + d[4] = kConvolve8Funcs[offset_idx1](&s[2 + (offset1_q4 >> 5)], f1); + d[5] = kConvolve8Funcs[offset_idx2](&s[2 + (offset2_q4 >> 5)], f2); // 00 10 20 30 40 50 60 70 02 12 22 32 42 52 62 72 // 01 11 21 31 41 51 61 71 03 13 23 33 43 53 63 73 @@ -598,11 +598,11 @@ static void scale_plane_4_to_3_general(const uint8_t *src, const int src_stride, loadu_8bit_16x4(t, stride_hor, &s[4]); d[0] = convolve8_8_even_offset_ssse3(&s[0], f0); - d[1] = convolve8_funcs[offset_idx1](&s[offset1_q4 >> 5], f1); - d[2] = convolve8_funcs[offset_idx2](&s[offset2_q4 >> 5], f2); + d[1] = kConvolve8Funcs[offset_idx1](&s[offset1_q4 >> 5], f1); + d[2] = kConvolve8Funcs[offset_idx2](&s[offset2_q4 >> 5], f2); d[3] = convolve8_8_even_offset_ssse3(&s[2], f0); - d[4] = convolve8_funcs[offset_idx1](&s[2 + (offset1_q4 >> 5)], f1); - d[5] = convolve8_funcs[offset_idx2](&s[2 + (offset2_q4 >> 5)], f2); + d[4] = kConvolve8Funcs[offset_idx1](&s[2 + (offset1_q4 >> 5)], f1); + d[5] = kConvolve8Funcs[offset_idx2](&s[2 + (offset2_q4 >> 5)], f2); // 00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17 // 20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37 @@ -754,8 +754,8 @@ void vp9_scale_and_extend_frame_ssse3(const YV12_BUFFER_CONFIG *src, const int src_h = src->y_crop_height; const int dst_w = dst->y_crop_width; const int dst_h = dst->y_crop_height; - const int dst_uv_w = dst_w / 2; - const int dst_uv_h = dst_h / 2; + const int dst_uv_w = dst->uv_crop_width; + const int dst_uv_h = dst->uv_crop_height; int scaled = 0; // phase_scaler is usually 0 or 8. @@ -886,14 +886,14 @@ void vp9_scale_and_extend_frame_ssse3(const YV12_BUFFER_CONFIG *src, scale_plane_1_to_2_phase_0( src->y_buffer, src->y_stride, dst->y_buffer, dst->y_stride, src_w, src_h, vp9_filter_kernels[filter_type][8], temp_buffer); - scale_plane_1_to_2_phase_0(src->u_buffer, src->uv_stride, dst->u_buffer, - dst->uv_stride, src_w / 2, src_h / 2, - vp9_filter_kernels[filter_type][8], - temp_buffer); - scale_plane_1_to_2_phase_0(src->v_buffer, src->uv_stride, dst->v_buffer, - dst->uv_stride, src_w / 2, src_h / 2, - vp9_filter_kernels[filter_type][8], - temp_buffer); + const int src_uv_w = src->uv_crop_width; + const int src_uv_h = src->uv_crop_height; + scale_plane_1_to_2_phase_0( + src->u_buffer, src->uv_stride, dst->u_buffer, dst->uv_stride, + src_uv_w, src_uv_h, vp9_filter_kernels[filter_type][8], temp_buffer); + scale_plane_1_to_2_phase_0( + src->v_buffer, src->uv_stride, dst->v_buffer, dst->uv_stride, + src_uv_w, src_uv_h, vp9_filter_kernels[filter_type][8], temp_buffer); free(temp_buffer); } } diff --git a/libs/libvpx/vp9/encoder/x86/vp9_quantize_avx2.c b/libs/libvpx/vp9/encoder/x86/vp9_quantize_avx2.c index db18b1a7a4..bf44b08674 100644 --- a/libs/libvpx/vp9/encoder/x86/vp9_quantize_avx2.c +++ b/libs/libvpx/vp9/encoder/x86/vp9_quantize_avx2.c @@ -16,9 +16,11 @@ #include "vpx_dsp/vpx_dsp_common.h" #include "vpx_dsp/x86/bitdepth_conversion_avx2.h" #include "vpx_dsp/x86/quantize_sse2.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" // Zero fill 8 positions in the output buffer. -static INLINE void store_zero_tran_low(tran_low_t *a) { +static VPX_FORCE_INLINE void store_zero_tran_low(tran_low_t *a) { const __m256i zero = _mm256_setzero_si256(); #if CONFIG_VP9_HIGHBITDEPTH _mm256_storeu_si256((__m256i *)(a), zero); @@ -28,34 +30,85 @@ static INLINE void store_zero_tran_low(tran_low_t *a) { #endif } -static INLINE __m256i scan_eob_256(const __m256i *iscan_ptr, - __m256i *coeff256) { - const __m256i iscan = _mm256_loadu_si256(iscan_ptr); - const __m256i zero256 = _mm256_setzero_si256(); +static VPX_FORCE_INLINE void load_fp_values_avx2( + const struct macroblock_plane *mb_plane, __m256i *round, __m256i *quant, + const int16_t *dequant_ptr, __m256i *dequant) { + *round = _mm256_castsi128_si256( + _mm_load_si128((const __m128i *)mb_plane->round_fp)); + *round = _mm256_permute4x64_epi64(*round, 0x54); + *quant = _mm256_castsi128_si256( + _mm_load_si128((const __m128i *)mb_plane->quant_fp)); + *quant = _mm256_permute4x64_epi64(*quant, 0x54); + *dequant = + _mm256_castsi128_si256(_mm_load_si128((const __m128i *)dequant_ptr)); + *dequant = _mm256_permute4x64_epi64(*dequant, 0x54); +} + +static VPX_FORCE_INLINE __m256i get_max_lane_eob(const int16_t *iscan, + __m256i v_eobmax, + __m256i v_mask) { #if CONFIG_VP9_HIGHBITDEPTH - // The _mm256_packs_epi32() in load_tran_low() packs the 64 bit coeff as - // B1 A1 B0 A0. Shuffle to B1 B0 A1 A0 in order to scan eob correctly. - const __m256i _coeff256 = _mm256_permute4x64_epi64(*coeff256, 0xd8); - const __m256i zero_coeff0 = _mm256_cmpeq_epi16(_coeff256, zero256); + const __m256i v_iscan = _mm256_permute4x64_epi64( + _mm256_loadu_si256((const __m256i *)iscan), 0xD8); #else - const __m256i zero_coeff0 = _mm256_cmpeq_epi16(*coeff256, zero256); + const __m256i v_iscan = _mm256_loadu_si256((const __m256i *)iscan); #endif - const __m256i nzero_coeff0 = _mm256_cmpeq_epi16(zero_coeff0, zero256); - // Add one to convert from indices to counts - const __m256i iscan_plus_one = _mm256_sub_epi16(iscan, nzero_coeff0); - return _mm256_and_si256(iscan_plus_one, nzero_coeff0); + const __m256i v_nz_iscan = _mm256_and_si256(v_iscan, v_mask); + return _mm256_max_epi16(v_eobmax, v_nz_iscan); +} + +static VPX_FORCE_INLINE uint16_t get_max_eob(__m256i eob256) { + const __m256i eob_lo = eob256; + // Copy upper 128 to lower 128 + const __m256i eob_hi = _mm256_permute2x128_si256(eob256, eob256, 0X81); + __m256i eob = _mm256_max_epi16(eob_lo, eob_hi); + __m256i eob_s = _mm256_shuffle_epi32(eob, 0xe); + eob = _mm256_max_epi16(eob, eob_s); + eob_s = _mm256_shufflelo_epi16(eob, 0xe); + eob = _mm256_max_epi16(eob, eob_s); + eob_s = _mm256_shufflelo_epi16(eob, 1); + eob = _mm256_max_epi16(eob, eob_s); +#if defined(_MSC_VER) && (_MSC_VER < 1910) + return _mm_cvtsi128_si32(_mm256_extracti128_si256(eob, 0)) & 0xffff; +#else + return (uint16_t)_mm256_extract_epi16(eob, 0); +#endif +} + +static VPX_FORCE_INLINE void quantize_fp_16( + const __m256i *round, const __m256i *quant, const __m256i *dequant, + const __m256i *thr, const tran_low_t *coeff_ptr, const int16_t *iscan_ptr, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, __m256i *eob_max) { + const __m256i coeff = load_tran_low(coeff_ptr); + const __m256i abs_coeff = _mm256_abs_epi16(coeff); + const int32_t nzflag = + _mm256_movemask_epi8(_mm256_cmpgt_epi16(abs_coeff, *thr)); + + if (nzflag) { + const __m256i tmp_rnd = _mm256_adds_epi16(abs_coeff, *round); + const __m256i abs_qcoeff = _mm256_mulhi_epi16(tmp_rnd, *quant); + const __m256i qcoeff = _mm256_sign_epi16(abs_qcoeff, coeff); + const __m256i dqcoeff = _mm256_mullo_epi16(qcoeff, *dequant); + const __m256i nz_mask = + _mm256_cmpgt_epi16(abs_qcoeff, _mm256_setzero_si256()); + store_tran_low(qcoeff, qcoeff_ptr); + store_tran_low(dqcoeff, dqcoeff_ptr); + + *eob_max = get_max_lane_eob(iscan_ptr, *eob_max, nz_mask); + } else { + store_zero_tran_low(qcoeff_ptr); + store_zero_tran_low(dqcoeff_ptr); + } } void vp9_quantize_fp_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *round_ptr, const int16_t *quant_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { - __m128i eob; - __m256i round256, quant256, dequant256; - __m256i eob256, thr256; - - (void)scan; + const struct ScanOrder *const scan_order) { + __m256i round, quant, dequant, thr; + __m256i eob_max = _mm256_setzero_si256(); + const int16_t *iscan = scan_order->iscan; coeff_ptr += n_coeffs; iscan += n_coeffs; @@ -63,74 +116,324 @@ void vp9_quantize_fp_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, dqcoeff_ptr += n_coeffs; n_coeffs = -n_coeffs; - { - __m256i coeff256; + // Setup global values + load_fp_values_avx2(mb_plane, &round, &quant, dequant_ptr, &dequant); + thr = _mm256_setzero_si256(); - // Setup global values - { - const __m128i round = _mm_load_si128((const __m128i *)round_ptr); - const __m128i quant = _mm_load_si128((const __m128i *)quant_ptr); - const __m128i dequant = _mm_load_si128((const __m128i *)dequant_ptr); - round256 = _mm256_castsi128_si256(round); - round256 = _mm256_permute4x64_epi64(round256, 0x54); + quantize_fp_16(&round, &quant, &dequant, &thr, coeff_ptr + n_coeffs, + iscan + n_coeffs, qcoeff_ptr + n_coeffs, + dqcoeff_ptr + n_coeffs, &eob_max); - quant256 = _mm256_castsi128_si256(quant); - quant256 = _mm256_permute4x64_epi64(quant256, 0x54); - - dequant256 = _mm256_castsi128_si256(dequant); - dequant256 = _mm256_permute4x64_epi64(dequant256, 0x54); - } - - { - __m256i qcoeff256; - __m256i qtmp256; - coeff256 = load_tran_low(coeff_ptr + n_coeffs); - qcoeff256 = _mm256_abs_epi16(coeff256); - qcoeff256 = _mm256_adds_epi16(qcoeff256, round256); - qtmp256 = _mm256_mulhi_epi16(qcoeff256, quant256); - qcoeff256 = _mm256_sign_epi16(qtmp256, coeff256); - store_tran_low(qcoeff256, qcoeff_ptr + n_coeffs); - coeff256 = _mm256_mullo_epi16(qcoeff256, dequant256); - store_tran_low(coeff256, dqcoeff_ptr + n_coeffs); - } - - eob256 = scan_eob_256((const __m256i *)(iscan + n_coeffs), &coeff256); - n_coeffs += 8 * 2; - } + n_coeffs += 8 * 2; // remove dc constants - dequant256 = _mm256_permute2x128_si256(dequant256, dequant256, 0x31); - quant256 = _mm256_permute2x128_si256(quant256, quant256, 0x31); - round256 = _mm256_permute2x128_si256(round256, round256, 0x31); - - thr256 = _mm256_srai_epi16(dequant256, 1); + dequant = _mm256_permute2x128_si256(dequant, dequant, 0x31); + quant = _mm256_permute2x128_si256(quant, quant, 0x31); + round = _mm256_permute2x128_si256(round, round, 0x31); + thr = _mm256_srai_epi16(dequant, 1); // AC only loop while (n_coeffs < 0) { - __m256i coeff256 = load_tran_low(coeff_ptr + n_coeffs); - __m256i qcoeff256 = _mm256_abs_epi16(coeff256); - int32_t nzflag = - _mm256_movemask_epi8(_mm256_cmpgt_epi16(qcoeff256, thr256)); - - if (nzflag) { - __m256i qtmp256; - qcoeff256 = _mm256_adds_epi16(qcoeff256, round256); - qtmp256 = _mm256_mulhi_epi16(qcoeff256, quant256); - qcoeff256 = _mm256_sign_epi16(qtmp256, coeff256); - store_tran_low(qcoeff256, qcoeff_ptr + n_coeffs); - coeff256 = _mm256_mullo_epi16(qcoeff256, dequant256); - store_tran_low(coeff256, dqcoeff_ptr + n_coeffs); - eob256 = _mm256_max_epi16( - eob256, scan_eob_256((const __m256i *)(iscan + n_coeffs), &coeff256)); - } else { - store_zero_tran_low(qcoeff_ptr + n_coeffs); - store_zero_tran_low(dqcoeff_ptr + n_coeffs); - } + quantize_fp_16(&round, &quant, &dequant, &thr, coeff_ptr + n_coeffs, + iscan + n_coeffs, qcoeff_ptr + n_coeffs, + dqcoeff_ptr + n_coeffs, &eob_max); n_coeffs += 8 * 2; } - eob = _mm_max_epi16(_mm256_castsi256_si128(eob256), - _mm256_extracti128_si256(eob256, 1)); - - *eob_ptr = accumulate_eob(eob); + *eob_ptr = get_max_eob(eob_max); } + +// Enable this flag when matching the optimized code to +// vp9_quantize_fp_32x32_c(). Disabled, the optimized code will match the +// existing ssse3 code and quantize_fp_32x32_nz_c(). +// +// #define MATCH_VP9_QUANTIZE_FP_32X32_C + +#ifndef MATCH_VP9_QUANTIZE_FP_32X32_C +static VPX_FORCE_INLINE void quantize_fp_32x32_16_no_nzflag( + const __m256i *round, const __m256i *quant, const __m256i *dequant, + const __m256i *thr, const tran_low_t *coeff_ptr, const int16_t *iscan_ptr, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, __m256i *eob_max) { + const __m256i coeff = load_tran_low(coeff_ptr); + const __m256i abs_coeff = _mm256_abs_epi16(coeff); + const __m256i tmp_rnd = _mm256_adds_epi16(abs_coeff, *round); + const __m256i abs_qcoeff = _mm256_mulhi_epi16(tmp_rnd, *quant); + const __m256i qcoeff = _mm256_sign_epi16(abs_qcoeff, coeff); + const __m256i abs_dqcoeff = + _mm256_srli_epi16(_mm256_mullo_epi16(abs_qcoeff, *dequant), 1); + const __m256i dqcoeff = _mm256_sign_epi16(abs_dqcoeff, coeff); + const __m256i nz_mask = + _mm256_cmpgt_epi16(abs_qcoeff, _mm256_setzero_si256()); + store_tran_low(qcoeff, qcoeff_ptr); + store_tran_low(dqcoeff, dqcoeff_ptr); + + *eob_max = get_max_lane_eob(iscan_ptr, *eob_max, nz_mask); + (void)thr; +} +#endif + +static VPX_FORCE_INLINE void quantize_fp_32x32_16( + const __m256i *round, const __m256i *quant, const __m256i *dequant, + const __m256i *thr, const tran_low_t *coeff_ptr, const int16_t *iscan_ptr, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, __m256i *eob_max) { + const __m256i coeff = load_tran_low(coeff_ptr); + const __m256i abs_coeff = _mm256_abs_epi16(coeff); + const __m256i thr_mask = _mm256_cmpgt_epi16(abs_coeff, *thr); + const int32_t nzflag = _mm256_movemask_epi8(thr_mask); + + if (nzflag) { +#ifdef MATCH_VP9_QUANTIZE_FP_32X32_C + const __m256i tmp_rnd = + _mm256_and_si256(_mm256_adds_epi16(abs_coeff, *round), thr_mask); +#else + const __m256i tmp_rnd = _mm256_adds_epi16(abs_coeff, *round); +#endif + const __m256i abs_qcoeff = _mm256_mulhi_epi16(tmp_rnd, *quant); + const __m256i qcoeff = _mm256_sign_epi16(abs_qcoeff, coeff); + const __m256i abs_dqcoeff = + _mm256_srli_epi16(_mm256_mullo_epi16(abs_qcoeff, *dequant), 1); + const __m256i dqcoeff = _mm256_sign_epi16(abs_dqcoeff, coeff); + const __m256i nz_mask = + _mm256_cmpgt_epi16(abs_qcoeff, _mm256_setzero_si256()); + store_tran_low(qcoeff, qcoeff_ptr); + store_tran_low(dqcoeff, dqcoeff_ptr); + + *eob_max = get_max_lane_eob(iscan_ptr, *eob_max, nz_mask); + } else { + store_zero_tran_low(qcoeff_ptr); + store_zero_tran_low(dqcoeff_ptr); + } +} + +void vp9_quantize_fp_32x32_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + __m256i round, quant, dequant, thr; + __m256i eob_max = _mm256_setzero_si256(); + const int16_t *iscan = scan_order->iscan; + + coeff_ptr += n_coeffs; + iscan += n_coeffs; + qcoeff_ptr += n_coeffs; + dqcoeff_ptr += n_coeffs; + n_coeffs = -n_coeffs; + + // Setup global values + load_fp_values_avx2(mb_plane, &round, &quant, dequant_ptr, &dequant); + thr = _mm256_srli_epi16(dequant, 2); + quant = _mm256_slli_epi16(quant, 1); + { + const __m256i rnd = _mm256_set1_epi16((int16_t)1); + round = _mm256_add_epi16(round, rnd); + round = _mm256_srai_epi16(round, 1); + } + +#ifdef MATCH_VP9_QUANTIZE_FP_32X32_C + // Subtracting 1 here eliminates a _mm256_cmpeq_epi16() instruction when + // calculating the zbin mask. + thr = _mm256_sub_epi16(thr, _mm256_set1_epi16(1)); + quantize_fp_32x32_16(&round, &quant, &dequant, &thr, coeff_ptr + n_coeffs, + iscan + n_coeffs, qcoeff_ptr + n_coeffs, + dqcoeff_ptr + n_coeffs, &eob_max); +#else + quantize_fp_32x32_16_no_nzflag( + &round, &quant, &dequant, &thr, coeff_ptr + n_coeffs, iscan + n_coeffs, + qcoeff_ptr + n_coeffs, dqcoeff_ptr + n_coeffs, &eob_max); +#endif + + n_coeffs += 8 * 2; + + // remove dc constants + dequant = _mm256_permute2x128_si256(dequant, dequant, 0x31); + quant = _mm256_permute2x128_si256(quant, quant, 0x31); + round = _mm256_permute2x128_si256(round, round, 0x31); + thr = _mm256_permute2x128_si256(thr, thr, 0x31); + + // AC only loop + while (n_coeffs < 0) { + quantize_fp_32x32_16(&round, &quant, &dequant, &thr, coeff_ptr + n_coeffs, + iscan + n_coeffs, qcoeff_ptr + n_coeffs, + dqcoeff_ptr + n_coeffs, &eob_max); + n_coeffs += 8 * 2; + } + + *eob_ptr = get_max_eob(eob_max); +} + +#if CONFIG_VP9_HIGHBITDEPTH +static VPX_FORCE_INLINE __m256i mm256_mul_shift_epi32_logscale(const __m256i *x, + const __m256i *y, + int log_scale) { + __m256i prod_lo = _mm256_mul_epi32(*x, *y); + __m256i prod_hi = _mm256_srli_epi64(*x, 32); + const __m256i mult_hi = _mm256_srli_epi64(*y, 32); + const __m256i mask = _mm256_set_epi32(0, -1, 0, -1, 0, -1, 0, -1); + prod_hi = _mm256_mul_epi32(prod_hi, mult_hi); + prod_lo = _mm256_srli_epi64(prod_lo, 16 - log_scale); + prod_lo = _mm256_and_si256(prod_lo, mask); + prod_hi = _mm256_srli_epi64(prod_hi, 16 - log_scale); + prod_hi = _mm256_slli_epi64(prod_hi, 32); + return _mm256_or_si256(prod_lo, prod_hi); +} + +static VPX_FORCE_INLINE __m256i highbd_init_256(const int16_t *val_ptr) { + const __m128i v = _mm_load_si128((const __m128i *)val_ptr); + const __m128i zero = _mm_setzero_si128(); + const __m128i dc = _mm_unpacklo_epi16(v, zero); + const __m128i ac = _mm_unpackhi_epi16(v, zero); + return _mm256_insertf128_si256(_mm256_castsi128_si256(dc), ac, 1); +} + +static VPX_FORCE_INLINE void highbd_load_fp_values( + const struct macroblock_plane *mb_plane, __m256i *round, __m256i *quant, + const int16_t *dequant_ptr, __m256i *dequant) { + *round = highbd_init_256(mb_plane->round_fp); + *quant = highbd_init_256(mb_plane->quant_fp); + *dequant = highbd_init_256(dequant_ptr); +} + +static VPX_FORCE_INLINE __m256i highbd_get_max_lane_eob( + const int16_t *iscan_ptr, __m256i eobmax, __m256i nz_mask) { + const __m256i packed_nz_mask = + _mm256_packs_epi32(nz_mask, _mm256_setzero_si256()); + const __m256i packed_nz_mask_perm = + _mm256_permute4x64_epi64(packed_nz_mask, 0xD8); + const __m256i iscan = + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i *)iscan_ptr)); + const __m256i nz_iscan = _mm256_and_si256(iscan, packed_nz_mask_perm); + return _mm256_max_epi16(eobmax, nz_iscan); +} + +static VPX_FORCE_INLINE void highbd_quantize_fp( + const __m256i *round, const __m256i *quant, const __m256i *dequant, + const tran_low_t *coeff_ptr, const int16_t *iscan_ptr, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, __m256i *eob) { + const __m256i coeff = _mm256_loadu_si256((const __m256i *)coeff_ptr); + const __m256i abs_coeff = _mm256_abs_epi32(coeff); + const __m256i tmp_rnd = _mm256_add_epi32(abs_coeff, *round); + const __m256i abs_q = mm256_mul_shift_epi32_logscale(&tmp_rnd, quant, 0); + const __m256i abs_dq = _mm256_mullo_epi32(abs_q, *dequant); + const __m256i q = _mm256_sign_epi32(abs_q, coeff); + const __m256i dq = _mm256_sign_epi32(abs_dq, coeff); + const __m256i nz_mask = _mm256_cmpgt_epi32(abs_q, _mm256_setzero_si256()); + + _mm256_storeu_si256((__m256i *)qcoeff_ptr, q); + _mm256_storeu_si256((__m256i *)dqcoeff_ptr, dq); + + *eob = highbd_get_max_lane_eob(iscan_ptr, *eob, nz_mask); +} + +void vp9_highbd_quantize_fp_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + const int step = 8; + __m256i round, quant, dequant; + __m256i eob_max = _mm256_setzero_si256(); + const int16_t *iscan = scan_order->iscan; + + coeff_ptr += n_coeffs; + iscan += n_coeffs; + qcoeff_ptr += n_coeffs; + dqcoeff_ptr += n_coeffs; + n_coeffs = -n_coeffs; + + // Setup global values + highbd_load_fp_values(mb_plane, &round, &quant, dequant_ptr, &dequant); + + highbd_quantize_fp(&round, &quant, &dequant, coeff_ptr + n_coeffs, + iscan + n_coeffs, qcoeff_ptr + n_coeffs, + dqcoeff_ptr + n_coeffs, &eob_max); + + n_coeffs += step; + + // remove dc constants + dequant = _mm256_permute2x128_si256(dequant, dequant, 0x31); + quant = _mm256_permute2x128_si256(quant, quant, 0x31); + round = _mm256_permute2x128_si256(round, round, 0x31); + + // AC only loop + while (n_coeffs < 0) { + highbd_quantize_fp(&round, &quant, &dequant, coeff_ptr + n_coeffs, + iscan + n_coeffs, qcoeff_ptr + n_coeffs, + dqcoeff_ptr + n_coeffs, &eob_max); + n_coeffs += step; + } + + *eob_ptr = get_max_eob(eob_max); +} + +static VPX_FORCE_INLINE void highbd_quantize_fp_32x32( + const __m256i *round, const __m256i *quant, const __m256i *dequant, + const __m256i *thr, const tran_low_t *coeff_ptr, const int16_t *iscan_ptr, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, __m256i *eob) { + const __m256i coeff = _mm256_loadu_si256((const __m256i *)coeff_ptr); + const __m256i abs_coeff = _mm256_abs_epi32(coeff); + const __m256i thr_mask = _mm256_cmpgt_epi32(abs_coeff, *thr); + const __m256i tmp_rnd = + _mm256_and_si256(_mm256_add_epi32(abs_coeff, *round), thr_mask); + const __m256i abs_q = mm256_mul_shift_epi32_logscale(&tmp_rnd, quant, 0); + const __m256i abs_dq = + _mm256_srli_epi32(_mm256_mullo_epi32(abs_q, *dequant), 1); + const __m256i q = _mm256_sign_epi32(abs_q, coeff); + const __m256i dq = _mm256_sign_epi32(abs_dq, coeff); + const __m256i nz_mask = _mm256_cmpgt_epi32(abs_q, _mm256_setzero_si256()); + + _mm256_storeu_si256((__m256i *)qcoeff_ptr, q); + _mm256_storeu_si256((__m256i *)dqcoeff_ptr, dq); + + *eob = highbd_get_max_lane_eob(iscan_ptr, *eob, nz_mask); +} + +void vp9_highbd_quantize_fp_32x32_avx2( + const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + const int step = 8; + __m256i round, quant, dequant, thr; + __m256i eob_max = _mm256_setzero_si256(); + const int16_t *iscan = scan_order->iscan; + + coeff_ptr += n_coeffs; + iscan += n_coeffs; + qcoeff_ptr += n_coeffs; + dqcoeff_ptr += n_coeffs; + n_coeffs = -n_coeffs; + + // Setup global values + highbd_load_fp_values(mb_plane, &round, &quant, dequant_ptr, &dequant); + thr = _mm256_srli_epi32(dequant, 2); + // Subtracting 1 here eliminates a _mm256_cmpeq_epi32() instruction when + // calculating the zbin mask. + thr = _mm256_sub_epi32(thr, _mm256_set1_epi32(1)); + quant = _mm256_slli_epi32(quant, 1); + round = _mm256_srai_epi32(_mm256_add_epi32(round, _mm256_set1_epi32(1)), 1); + + highbd_quantize_fp_32x32(&round, &quant, &dequant, &thr, coeff_ptr + n_coeffs, + iscan + n_coeffs, qcoeff_ptr + n_coeffs, + dqcoeff_ptr + n_coeffs, &eob_max); + + n_coeffs += step; + + // remove dc constants + dequant = _mm256_permute2x128_si256(dequant, dequant, 0x31); + quant = _mm256_permute2x128_si256(quant, quant, 0x31); + round = _mm256_permute2x128_si256(round, round, 0x31); + thr = _mm256_permute2x128_si256(thr, thr, 0x31); + + // AC only loop + while (n_coeffs < 0) { + highbd_quantize_fp_32x32( + &round, &quant, &dequant, &thr, coeff_ptr + n_coeffs, iscan + n_coeffs, + qcoeff_ptr + n_coeffs, dqcoeff_ptr + n_coeffs, &eob_max); + n_coeffs += step; + } + + *eob_ptr = get_max_eob(eob_max); +} +#endif // CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vp9/encoder/x86/vp9_quantize_sse2.c b/libs/libvpx/vp9/encoder/x86/vp9_quantize_sse2.c index 4bcadaa6a1..2481eb366e 100644 --- a/libs/libvpx/vp9/encoder/x86/vp9_quantize_sse2.c +++ b/libs/libvpx/vp9/encoder/x86/vp9_quantize_sse2.c @@ -16,184 +16,111 @@ #include "vpx/vpx_integer.h" #include "vpx_dsp/vpx_dsp_common.h" #include "vpx_dsp/x86/bitdepth_conversion_sse2.h" +#include "vpx_dsp/x86/quantize_sse2.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" void vp9_quantize_fp_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *round_ptr, const int16_t *quant_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { - __m128i zero; + const struct ScanOrder *const scan_order) { + const __m128i zero = _mm_setzero_si128(); __m128i thr; int nzflag; - __m128i eob; + int index = 16; __m128i round, quant, dequant; + __m128i coeff0, coeff1, coeff0_sign, coeff1_sign; + __m128i qcoeff0, qcoeff1; + __m128i eob; + const int16_t *iscan = scan_order->iscan; - (void)scan; + // Setup global values. + load_fp_values(mb_plane, &round, &quant, dequant_ptr, &dequant); - coeff_ptr += n_coeffs; - iscan += n_coeffs; - qcoeff_ptr += n_coeffs; - dqcoeff_ptr += n_coeffs; - n_coeffs = -n_coeffs; - zero = _mm_setzero_si128(); + // Do DC and first 15 AC. + coeff0 = load_tran_low(coeff_ptr); + coeff1 = load_tran_low(coeff_ptr + 8); - { - __m128i coeff0, coeff1; + // Poor man's abs(). + coeff0_sign = _mm_srai_epi16(coeff0, 15); + coeff1_sign = _mm_srai_epi16(coeff1, 15); + qcoeff0 = invert_sign_sse2(coeff0, coeff0_sign); + qcoeff1 = invert_sign_sse2(coeff1, coeff1_sign); - // Setup global values - { - round = _mm_load_si128((const __m128i *)round_ptr); - quant = _mm_load_si128((const __m128i *)quant_ptr); - dequant = _mm_load_si128((const __m128i *)dequant_ptr); - } + qcoeff0 = _mm_adds_epi16(qcoeff0, round); + qcoeff0 = _mm_mulhi_epi16(qcoeff0, quant); - { - __m128i coeff0_sign, coeff1_sign; - __m128i qcoeff0, qcoeff1; - __m128i qtmp0, qtmp1; - // Do DC and first 15 AC - coeff0 = load_tran_low(coeff_ptr + n_coeffs); - coeff1 = load_tran_low(coeff_ptr + n_coeffs + 8); + round = _mm_unpackhi_epi64(round, round); + quant = _mm_unpackhi_epi64(quant, quant); - // Poor man's sign extract - coeff0_sign = _mm_srai_epi16(coeff0, 15); - coeff1_sign = _mm_srai_epi16(coeff1, 15); - qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign); - qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign); - qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign); - qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign); + qcoeff1 = _mm_adds_epi16(qcoeff1, round); + qcoeff1 = _mm_mulhi_epi16(qcoeff1, quant); - qcoeff0 = _mm_adds_epi16(qcoeff0, round); - round = _mm_unpackhi_epi64(round, round); - qcoeff1 = _mm_adds_epi16(qcoeff1, round); - qtmp0 = _mm_mulhi_epi16(qcoeff0, quant); - quant = _mm_unpackhi_epi64(quant, quant); - qtmp1 = _mm_mulhi_epi16(qcoeff1, quant); + // Reinsert signs. + qcoeff0 = invert_sign_sse2(qcoeff0, coeff0_sign); + qcoeff1 = invert_sign_sse2(qcoeff1, coeff1_sign); - // Reinsert signs - qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign); - qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign); - qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign); - qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign); + store_tran_low(qcoeff0, qcoeff_ptr); + store_tran_low(qcoeff1, qcoeff_ptr + 8); - store_tran_low(qcoeff0, qcoeff_ptr + n_coeffs); - store_tran_low(qcoeff1, qcoeff_ptr + n_coeffs + 8); + qcoeff0 = _mm_mullo_epi16(qcoeff0, dequant); + dequant = _mm_unpackhi_epi64(dequant, dequant); + qcoeff1 = _mm_mullo_epi16(qcoeff1, dequant); - coeff0 = _mm_mullo_epi16(qcoeff0, dequant); - dequant = _mm_unpackhi_epi64(dequant, dequant); - coeff1 = _mm_mullo_epi16(qcoeff1, dequant); + store_tran_low(qcoeff0, dqcoeff_ptr); + store_tran_low(qcoeff1, dqcoeff_ptr + 8); - store_tran_low(coeff0, dqcoeff_ptr + n_coeffs); - store_tran_low(coeff1, dqcoeff_ptr + n_coeffs + 8); - } - - { - // Scan for eob - __m128i zero_coeff0, zero_coeff1; - __m128i nzero_coeff0, nzero_coeff1; - __m128i iscan0, iscan1; - __m128i eob1; - zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero); - zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero); - nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero); - nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero); - iscan0 = _mm_load_si128((const __m128i *)(iscan + n_coeffs)); - iscan1 = _mm_load_si128((const __m128i *)(iscan + n_coeffs) + 1); - // Add one to convert from indices to counts - iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0); - iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1); - eob = _mm_and_si128(iscan0, nzero_coeff0); - eob1 = _mm_and_si128(iscan1, nzero_coeff1); - eob = _mm_max_epi16(eob, eob1); - } - n_coeffs += 8 * 2; - } + eob = scan_for_eob(&qcoeff0, &qcoeff1, iscan, 0, zero); thr = _mm_srai_epi16(dequant, 1); - // AC only loop - while (n_coeffs < 0) { - __m128i coeff0, coeff1; - { - __m128i coeff0_sign, coeff1_sign; - __m128i qcoeff0, qcoeff1; - __m128i qtmp0, qtmp1; + // AC only loop. + while (index < n_coeffs) { + coeff0 = load_tran_low(coeff_ptr + index); + coeff1 = load_tran_low(coeff_ptr + index + 8); - coeff0 = load_tran_low(coeff_ptr + n_coeffs); - coeff1 = load_tran_low(coeff_ptr + n_coeffs + 8); + // Poor man's abs(). + coeff0_sign = _mm_srai_epi16(coeff0, 15); + coeff1_sign = _mm_srai_epi16(coeff1, 15); + qcoeff0 = invert_sign_sse2(coeff0, coeff0_sign); + qcoeff1 = invert_sign_sse2(coeff1, coeff1_sign); - // Poor man's sign extract - coeff0_sign = _mm_srai_epi16(coeff0, 15); - coeff1_sign = _mm_srai_epi16(coeff1, 15); - qcoeff0 = _mm_xor_si128(coeff0, coeff0_sign); - qcoeff1 = _mm_xor_si128(coeff1, coeff1_sign); - qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign); - qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign); - - nzflag = _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff0, thr)) | - _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff1, thr)); - - if (nzflag) { - qcoeff0 = _mm_adds_epi16(qcoeff0, round); - qcoeff1 = _mm_adds_epi16(qcoeff1, round); - qtmp0 = _mm_mulhi_epi16(qcoeff0, quant); - qtmp1 = _mm_mulhi_epi16(qcoeff1, quant); - - // Reinsert signs - qcoeff0 = _mm_xor_si128(qtmp0, coeff0_sign); - qcoeff1 = _mm_xor_si128(qtmp1, coeff1_sign); - qcoeff0 = _mm_sub_epi16(qcoeff0, coeff0_sign); - qcoeff1 = _mm_sub_epi16(qcoeff1, coeff1_sign); - - store_tran_low(qcoeff0, qcoeff_ptr + n_coeffs); - store_tran_low(qcoeff1, qcoeff_ptr + n_coeffs + 8); - - coeff0 = _mm_mullo_epi16(qcoeff0, dequant); - coeff1 = _mm_mullo_epi16(qcoeff1, dequant); - - store_tran_low(coeff0, dqcoeff_ptr + n_coeffs); - store_tran_low(coeff1, dqcoeff_ptr + n_coeffs + 8); - } else { - store_zero_tran_low(qcoeff_ptr + n_coeffs); - store_zero_tran_low(qcoeff_ptr + n_coeffs + 8); - - store_zero_tran_low(dqcoeff_ptr + n_coeffs); - store_zero_tran_low(dqcoeff_ptr + n_coeffs + 8); - } - } + nzflag = _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff0, thr)) | + _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff1, thr)); if (nzflag) { - // Scan for eob - __m128i zero_coeff0, zero_coeff1; - __m128i nzero_coeff0, nzero_coeff1; - __m128i iscan0, iscan1; - __m128i eob0, eob1; - zero_coeff0 = _mm_cmpeq_epi16(coeff0, zero); - zero_coeff1 = _mm_cmpeq_epi16(coeff1, zero); - nzero_coeff0 = _mm_cmpeq_epi16(zero_coeff0, zero); - nzero_coeff1 = _mm_cmpeq_epi16(zero_coeff1, zero); - iscan0 = _mm_load_si128((const __m128i *)(iscan + n_coeffs)); - iscan1 = _mm_load_si128((const __m128i *)(iscan + n_coeffs) + 1); - // Add one to convert from indices to counts - iscan0 = _mm_sub_epi16(iscan0, nzero_coeff0); - iscan1 = _mm_sub_epi16(iscan1, nzero_coeff1); - eob0 = _mm_and_si128(iscan0, nzero_coeff0); - eob1 = _mm_and_si128(iscan1, nzero_coeff1); - eob0 = _mm_max_epi16(eob0, eob1); + __m128i eob0; + qcoeff0 = _mm_adds_epi16(qcoeff0, round); + qcoeff1 = _mm_adds_epi16(qcoeff1, round); + qcoeff0 = _mm_mulhi_epi16(qcoeff0, quant); + qcoeff1 = _mm_mulhi_epi16(qcoeff1, quant); + + // Reinsert signs. + qcoeff0 = invert_sign_sse2(qcoeff0, coeff0_sign); + qcoeff1 = invert_sign_sse2(qcoeff1, coeff1_sign); + + store_tran_low(qcoeff0, qcoeff_ptr + index); + store_tran_low(qcoeff1, qcoeff_ptr + index + 8); + + qcoeff0 = _mm_mullo_epi16(qcoeff0, dequant); + qcoeff1 = _mm_mullo_epi16(qcoeff1, dequant); + + store_tran_low(qcoeff0, dqcoeff_ptr + index); + store_tran_low(qcoeff1, dqcoeff_ptr + index + 8); + + eob0 = scan_for_eob(&qcoeff0, &qcoeff1, iscan, index, zero); eob = _mm_max_epi16(eob, eob0); + } else { + store_zero_tran_low(qcoeff_ptr + index); + store_zero_tran_low(qcoeff_ptr + index + 8); + + store_zero_tran_low(dqcoeff_ptr + index); + store_zero_tran_low(dqcoeff_ptr + index + 8); } - n_coeffs += 8 * 2; + + index += 16; } - // Accumulate EOB - { - __m128i eob_shuffled; - eob_shuffled = _mm_shuffle_epi32(eob, 0xe); - eob = _mm_max_epi16(eob, eob_shuffled); - eob_shuffled = _mm_shufflelo_epi16(eob, 0xe); - eob = _mm_max_epi16(eob, eob_shuffled); - eob_shuffled = _mm_shufflelo_epi16(eob, 0x1); - eob = _mm_max_epi16(eob, eob_shuffled); - *eob_ptr = _mm_extract_epi16(eob, 1); - } + *eob_ptr = accumulate_eob(eob); } diff --git a/libs/libvpx/vp9/encoder/x86/vp9_quantize_ssse3.c b/libs/libvpx/vp9/encoder/x86/vp9_quantize_ssse3.c new file mode 100644 index 0000000000..98decae749 --- /dev/null +++ b/libs/libvpx/vp9/encoder/x86/vp9_quantize_ssse3.c @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vp9_rtcd.h" +#include "vpx/vpx_integer.h" +#include "vpx_dsp/vpx_dsp_common.h" +#include "vpx_dsp/x86/bitdepth_conversion_sse2.h" +#include "vpx_dsp/x86/quantize_sse2.h" +#include "vpx_dsp/x86/quantize_ssse3.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" + +void vp9_quantize_fp_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + const __m128i zero = _mm_setzero_si128(); + __m128i thr; + int nzflag; + int index = 16; + __m128i round, quant, dequant; + __m128i coeff0, coeff1; + __m128i qcoeff0, qcoeff1; + __m128i eob; + const int16_t *iscan = scan_order->iscan; + + // Setup global values. + load_fp_values(mb_plane, &round, &quant, dequant_ptr, &dequant); + + // Do DC and first 15 AC. + coeff0 = load_tran_low(coeff_ptr); + coeff1 = load_tran_low(coeff_ptr + 8); + + qcoeff0 = _mm_abs_epi16(coeff0); + qcoeff1 = _mm_abs_epi16(coeff1); + + qcoeff0 = _mm_adds_epi16(qcoeff0, round); + qcoeff0 = _mm_mulhi_epi16(qcoeff0, quant); + + round = _mm_unpackhi_epi64(round, round); + quant = _mm_unpackhi_epi64(quant, quant); + + qcoeff1 = _mm_adds_epi16(qcoeff1, round); + qcoeff1 = _mm_mulhi_epi16(qcoeff1, quant); + + // Reinsert signs. + qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0); + qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1); + + store_tran_low(qcoeff0, qcoeff_ptr); + store_tran_low(qcoeff1, qcoeff_ptr + 8); + + qcoeff0 = _mm_mullo_epi16(qcoeff0, dequant); + dequant = _mm_unpackhi_epi64(dequant, dequant); + qcoeff1 = _mm_mullo_epi16(qcoeff1, dequant); + + store_tran_low(qcoeff0, dqcoeff_ptr); + store_tran_low(qcoeff1, dqcoeff_ptr + 8); + + eob = scan_for_eob(&qcoeff0, &qcoeff1, iscan, 0, zero); + + thr = _mm_srai_epi16(dequant, 1); + + // AC only loop. + while (index < n_coeffs) { + coeff0 = load_tran_low(coeff_ptr + index); + coeff1 = load_tran_low(coeff_ptr + index + 8); + + qcoeff0 = _mm_abs_epi16(coeff0); + qcoeff1 = _mm_abs_epi16(coeff1); + + nzflag = _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff0, thr)) | + _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff1, thr)); + + if (nzflag) { + __m128i eob0; + qcoeff0 = _mm_adds_epi16(qcoeff0, round); + qcoeff1 = _mm_adds_epi16(qcoeff1, round); + qcoeff0 = _mm_mulhi_epi16(qcoeff0, quant); + qcoeff1 = _mm_mulhi_epi16(qcoeff1, quant); + + // Reinsert signs. + qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0); + qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1); + + store_tran_low(qcoeff0, qcoeff_ptr + index); + store_tran_low(qcoeff1, qcoeff_ptr + index + 8); + + qcoeff0 = _mm_mullo_epi16(qcoeff0, dequant); + qcoeff1 = _mm_mullo_epi16(qcoeff1, dequant); + + store_tran_low(qcoeff0, dqcoeff_ptr + index); + store_tran_low(qcoeff1, dqcoeff_ptr + index + 8); + + eob0 = scan_for_eob(&qcoeff0, &qcoeff1, iscan, index, zero); + eob = _mm_max_epi16(eob, eob0); + } else { + store_zero_tran_low(qcoeff_ptr + index); + store_zero_tran_low(qcoeff_ptr + index + 8); + + store_zero_tran_low(dqcoeff_ptr + index); + store_zero_tran_low(dqcoeff_ptr + index + 8); + } + + index += 16; + } + + *eob_ptr = accumulate_eob(eob); +} + +void vp9_quantize_fp_32x32_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + const __m128i zero = _mm_setzero_si128(); + const __m128i one_s16 = _mm_set1_epi16(1); + __m128i thr; + int nzflag; + int index = 16; + __m128i round, quant, dequant; + __m128i coeff0, coeff1; + __m128i qcoeff0, qcoeff1; + __m128i eob; + const int16_t *iscan = scan_order->iscan; + + // Setup global values. + load_fp_values(mb_plane, &round, &quant, dequant_ptr, &dequant); + // The 32x32 halves round. + round = _mm_add_epi16(round, one_s16); + round = _mm_srli_epi16(round, 1); + + // The 16x16 shifts by 16, the 32x32 shifts by 15. We want to use pmulhw so + // upshift quant to account for this. + quant = _mm_slli_epi16(quant, 1); + + // Do DC and first 15 AC. + coeff0 = load_tran_low(coeff_ptr); + coeff1 = load_tran_low(coeff_ptr + 8); + + qcoeff0 = _mm_abs_epi16(coeff0); + qcoeff1 = _mm_abs_epi16(coeff1); + + qcoeff0 = _mm_adds_epi16(qcoeff0, round); + qcoeff0 = _mm_mulhi_epi16(qcoeff0, quant); + + round = _mm_unpackhi_epi64(round, round); + quant = _mm_unpackhi_epi64(quant, quant); + + qcoeff1 = _mm_adds_epi16(qcoeff1, round); + qcoeff1 = _mm_mulhi_epi16(qcoeff1, quant); + + // Reinsert signs. + qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0); + qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1); + + store_tran_low(qcoeff0, qcoeff_ptr); + store_tran_low(qcoeff1, qcoeff_ptr + 8); + + // Get the abs value of qcoeff again so we can use shifts for division. + qcoeff0 = _mm_abs_epi16(qcoeff0); + qcoeff1 = _mm_abs_epi16(qcoeff1); + + qcoeff0 = _mm_mullo_epi16(qcoeff0, dequant); + dequant = _mm_unpackhi_epi64(dequant, dequant); + qcoeff1 = _mm_mullo_epi16(qcoeff1, dequant); + + // Divide by 2. + qcoeff0 = _mm_srli_epi16(qcoeff0, 1); + qcoeff1 = _mm_srli_epi16(qcoeff1, 1); + + // Reinsert signs. + qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0); + qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1); + + store_tran_low(qcoeff0, dqcoeff_ptr); + store_tran_low(qcoeff1, dqcoeff_ptr + 8); + + eob = scan_for_eob(&qcoeff0, &qcoeff1, iscan, 0, zero); + + thr = _mm_srai_epi16(dequant, 2); + + // AC only loop. + while (index < n_coeffs) { + coeff0 = load_tran_low(coeff_ptr + index); + coeff1 = load_tran_low(coeff_ptr + index + 8); + + qcoeff0 = _mm_abs_epi16(coeff0); + qcoeff1 = _mm_abs_epi16(coeff1); + + nzflag = _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff0, thr)) | + _mm_movemask_epi8(_mm_cmpgt_epi16(qcoeff1, thr)); + + if (nzflag) { + qcoeff0 = _mm_adds_epi16(qcoeff0, round); + qcoeff1 = _mm_adds_epi16(qcoeff1, round); + qcoeff0 = _mm_mulhi_epi16(qcoeff0, quant); + qcoeff1 = _mm_mulhi_epi16(qcoeff1, quant); + + // Reinsert signs. + qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0); + qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1); + + store_tran_low(qcoeff0, qcoeff_ptr + index); + store_tran_low(qcoeff1, qcoeff_ptr + index + 8); + + // Get the abs value of qcoeff again so we can use shifts for division. + qcoeff0 = _mm_abs_epi16(qcoeff0); + qcoeff1 = _mm_abs_epi16(qcoeff1); + + qcoeff0 = _mm_mullo_epi16(qcoeff0, dequant); + qcoeff1 = _mm_mullo_epi16(qcoeff1, dequant); + + // Divide by 2. + qcoeff0 = _mm_srli_epi16(qcoeff0, 1); + qcoeff1 = _mm_srli_epi16(qcoeff1, 1); + + // Reinsert signs. + qcoeff0 = _mm_sign_epi16(qcoeff0, coeff0); + qcoeff1 = _mm_sign_epi16(qcoeff1, coeff1); + + store_tran_low(qcoeff0, dqcoeff_ptr + index); + store_tran_low(qcoeff1, dqcoeff_ptr + index + 8); + } else { + store_zero_tran_low(qcoeff_ptr + index); + store_zero_tran_low(qcoeff_ptr + index + 8); + + store_zero_tran_low(dqcoeff_ptr + index); + store_zero_tran_low(dqcoeff_ptr + index + 8); + } + + if (nzflag) { + const __m128i eob0 = scan_for_eob(&qcoeff0, &qcoeff1, iscan, index, zero); + eob = _mm_max_epi16(eob, eob0); + } + index += 16; + } + + *eob_ptr = accumulate_eob(eob); +} diff --git a/libs/libvpx/vp9/encoder/x86/vp9_quantize_ssse3_x86_64.asm b/libs/libvpx/vp9/encoder/x86/vp9_quantize_ssse3_x86_64.asm deleted file mode 100644 index 680acfec69..0000000000 --- a/libs/libvpx/vp9/encoder/x86/vp9_quantize_ssse3_x86_64.asm +++ /dev/null @@ -1,178 +0,0 @@ -; -; Copyright (c) 2010 The WebM project authors. All Rights Reserved. -; -; Use of this source code is governed by a BSD-style license -; that can be found in the LICENSE file in the root of the source -; tree. An additional intellectual property rights grant can be found -; in the file PATENTS. All contributing project authors may -; be found in the AUTHORS file in the root of the source tree. -; - -%define private_prefix vp9 - -%include "third_party/x86inc/x86inc.asm" -%include "vpx_dsp/x86/bitdepth_conversion_sse2.asm" - -SECTION_RODATA -pw_1: times 8 dw 1 - -SECTION .text - -%macro QUANTIZE_FP 2 -cglobal quantize_%1, 0, %2, 15, coeff, ncoeff, round, quant, \ - qcoeff, dqcoeff, dequant, \ - eob, scan, iscan - - ; actual quantize loop - setup pointers, rounders, etc. - movifnidn coeffq, coeffmp - movifnidn ncoeffq, ncoeffmp - movifnidn roundq, roundmp - movifnidn quantq, quantmp - mova m1, [roundq] ; m1 = round - mova m2, [quantq] ; m2 = quant - mov r2, dequantmp -%ifidn %1, fp_32x32 - pcmpeqw m5, m5 - psrlw m5, 15 - paddw m1, m5 - psrlw m1, 1 ; m1 = (m1 + 1) / 2 -%endif - mova m3, [r2q] ; m3 = dequant - mov r3, qcoeffmp - mov r4, dqcoeffmp - mov r5, iscanmp -%ifidn %1, fp_32x32 - psllw m2, 1 -%endif - pxor m5, m5 ; m5 = dedicated zero - - INCREMENT_ELEMENTS_TRAN_LOW coeffq, ncoeffq - lea r5q, [r5q+ncoeffq*2] - INCREMENT_ELEMENTS_TRAN_LOW r3q, ncoeffq - INCREMENT_ELEMENTS_TRAN_LOW r4q, ncoeffq - neg ncoeffq - - ; get DC and first 15 AC coeffs - LOAD_TRAN_LOW 9, coeffq, ncoeffq ; m9 = c[i] - LOAD_TRAN_LOW 10, coeffq, ncoeffq + 8 ; m10 = c[i] - pabsw m6, m9 ; m6 = abs(m9) - pabsw m11, m10 ; m11 = abs(m10) - pcmpeqw m7, m7 - - paddsw m6, m1 ; m6 += round - punpckhqdq m1, m1 - paddsw m11, m1 ; m11 += round - pmulhw m8, m6, m2 ; m8 = m6*q>>16 - punpckhqdq m2, m2 - pmulhw m13, m11, m2 ; m13 = m11*q>>16 - psignw m8, m9 ; m8 = reinsert sign - psignw m13, m10 ; m13 = reinsert sign - STORE_TRAN_LOW 8, r3q, ncoeffq, 6, 11, 12 - STORE_TRAN_LOW 13, r3q, ncoeffq + 8, 6, 11, 12 -%ifidn %1, fp_32x32 - pabsw m8, m8 - pabsw m13, m13 -%endif - pmullw m8, m3 ; r4[i] = r3[i] * q - punpckhqdq m3, m3 - pmullw m13, m3 ; r4[i] = r3[i] * q -%ifidn %1, fp_32x32 - psrlw m8, 1 - psrlw m13, 1 - psignw m8, m9 - psignw m13, m10 - psrlw m0, m3, 2 -%else - psrlw m0, m3, 1 -%endif - STORE_TRAN_LOW 8, r4q, ncoeffq, 6, 11, 12 - STORE_TRAN_LOW 13, r4q, ncoeffq + 8, 6, 11, 12 - pcmpeqw m8, m5 ; m8 = c[i] == 0 - pcmpeqw m13, m5 ; m13 = c[i] == 0 - mova m6, [ r5q+ncoeffq*2+ 0] ; m6 = scan[i] - mova m11, [ r5q+ncoeffq*2+16] ; m11 = scan[i] - psubw m6, m7 ; m6 = scan[i] + 1 - psubw m11, m7 ; m11 = scan[i] + 1 - pandn m8, m6 ; m8 = max(eob) - pandn m13, m11 ; m13 = max(eob) - pmaxsw m8, m13 - add ncoeffq, mmsize - jz .accumulate_eob - -.ac_only_loop: - LOAD_TRAN_LOW 9, coeffq, ncoeffq ; m9 = c[i] - LOAD_TRAN_LOW 10, coeffq, ncoeffq + 8 ; m10 = c[i] - pabsw m6, m9 ; m6 = abs(m9) - pabsw m11, m10 ; m11 = abs(m10) - - pcmpgtw m7, m6, m0 - pcmpgtw m12, m11, m0 - pmovmskb r6d, m7 - pmovmskb r2d, m12 - - or r6, r2 - jz .skip_iter - - pcmpeqw m7, m7 - - paddsw m6, m1 ; m6 += round - paddsw m11, m1 ; m11 += round - pmulhw m14, m6, m2 ; m14 = m6*q>>16 - pmulhw m13, m11, m2 ; m13 = m11*q>>16 - psignw m14, m9 ; m14 = reinsert sign - psignw m13, m10 ; m13 = reinsert sign - STORE_TRAN_LOW 14, r3q, ncoeffq, 6, 11, 12 - STORE_TRAN_LOW 13, r3q, ncoeffq + 8, 6, 11, 12 -%ifidn %1, fp_32x32 - pabsw m14, m14 - pabsw m13, m13 -%endif - pmullw m14, m3 ; r4[i] = r3[i] * q - pmullw m13, m3 ; r4[i] = r3[i] * q -%ifidn %1, fp_32x32 - psrlw m14, 1 - psrlw m13, 1 - psignw m14, m9 - psignw m13, m10 -%endif - STORE_TRAN_LOW 14, r4q, ncoeffq, 6, 11, 12 - STORE_TRAN_LOW 13, r4q, ncoeffq + 8, 6, 11, 12 - pcmpeqw m14, m5 ; m14 = c[i] == 0 - pcmpeqw m13, m5 ; m13 = c[i] == 0 - mova m6, [ r5q+ncoeffq*2+ 0] ; m6 = scan[i] - mova m11, [ r5q+ncoeffq*2+16] ; m11 = scan[i] - psubw m6, m7 ; m6 = scan[i] + 1 - psubw m11, m7 ; m11 = scan[i] + 1 - pandn m14, m6 ; m14 = max(eob) - pandn m13, m11 ; m13 = max(eob) - pmaxsw m8, m14 - pmaxsw m8, m13 - add ncoeffq, mmsize - jl .ac_only_loop - - jmp .accumulate_eob -.skip_iter: - STORE_ZERO_TRAN_LOW 5, r3q, ncoeffq - STORE_ZERO_TRAN_LOW 5, r3q, ncoeffq + 8 - STORE_ZERO_TRAN_LOW 5, r4q, ncoeffq - STORE_ZERO_TRAN_LOW 5, r4q, ncoeffq + 8 - add ncoeffq, mmsize - jl .ac_only_loop - -.accumulate_eob: - ; horizontally accumulate/max eobs and write into [eob] memory pointer - mov r2, eobmp - pshufd m7, m8, 0xe - pmaxsw m8, m7 - pshuflw m7, m8, 0xe - pmaxsw m8, m7 - pshuflw m7, m8, 0x1 - pmaxsw m8, m7 - pextrw r6, m8, 0 - mov [r2], r6w - RET -%endmacro - -INIT_XMM ssse3 -QUANTIZE_FP fp, 7 -QUANTIZE_FP fp_32x32, 7 diff --git a/libs/libvpx/vp9/ratectrl_rtc.cc b/libs/libvpx/vp9/ratectrl_rtc.cc index f4d7f7e9e7..43292a2b85 100644 --- a/libs/libvpx/vp9/ratectrl_rtc.cc +++ b/libs/libvpx/vp9/ratectrl_rtc.cc @@ -12,10 +12,12 @@ #include #include "vp9/common/vp9_common.h" +#include "vp9/encoder/vp9_aq_cyclicrefresh.h" #include "vp9/encoder/vp9_encoder.h" #include "vp9/encoder/vp9_picklpf.h" #include "vpx/vp8cx.h" #include "vpx/vpx_codec.h" +#include "vpx_mem/vpx_mem.h" namespace libvpx { @@ -25,22 +27,16 @@ std::unique_ptr VP9RateControlRTC::Create( VP9RateControlRTC()); if (!rc_api) return nullptr; rc_api->cpi_ = static_cast(vpx_memalign(32, sizeof(*cpi_))); - if (!rc_api->cpi_) { - rc_api.reset(); - return nullptr; - } + if (!rc_api->cpi_) return nullptr; vp9_zero(*rc_api->cpi_); - rc_api->InitRateControl(cfg); + if (!rc_api->InitRateControl(cfg)) return nullptr; if (cfg.aq_mode) { VP9_COMP *const cpi = rc_api->cpi_; cpi->segmentation_map = static_cast( vpx_calloc(cpi->common.mi_rows * cpi->common.mi_cols, sizeof(*cpi->segmentation_map))); - if (!cpi->segmentation_map) { - rc_api.reset(); - return nullptr; - } + if (!cpi->segmentation_map) return nullptr; cpi->cyclic_refresh = vp9_cyclic_refresh_alloc(cpi->common.mi_rows, cpi->common.mi_cols); cpi->cyclic_refresh->content_mode = 0; @@ -48,7 +44,24 @@ std::unique_ptr VP9RateControlRTC::Create( return rc_api; } -void VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) { +VP9RateControlRTC::~VP9RateControlRTC() { + if (cpi_) { + for (int layer = 0; layer < VPX_MAX_LAYERS; layer++) { + LAYER_CONTEXT *const lc = &cpi_->svc.layer_context[layer]; + vpx_free(lc->map); + vpx_free(lc->last_coded_q_map); + vpx_free(lc->consec_zero_mv); + } + if (cpi_->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { + vpx_free(cpi_->segmentation_map); + cpi_->segmentation_map = NULL; + vp9_cyclic_refresh_free(cpi_->cyclic_refresh); + } + vpx_free(cpi_); + } +} + +bool VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) { VP9_COMMON *cm = &cpi_->common; VP9EncoderConfig *oxcf = &cpi_->oxcf; RATE_CONTROL *const rc = &cpi_->rc; @@ -65,7 +78,7 @@ void VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) { cm->current_video_frame = 0; rc->kf_boost = DEFAULT_KF_BOOST; - UpdateRateControl(rc_cfg); + if (!UpdateRateControl(rc_cfg)) return false; vp9_set_mb_mi(cm, cm->width, cm->height); cpi_->use_svc = (cpi_->svc.number_spatial_layers > 1 || @@ -79,10 +92,31 @@ void VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) { vp9_rc_init(oxcf, 0, rc); rc->constrain_gf_key_freq_onepass_vbr = 0; cpi_->sf.use_nonrd_pick_mode = 1; + rc_is_valid_ = true; + return true; } -void VP9RateControlRTC::UpdateRateControl( +bool VP9RateControlRTC::UpdateRateControl( const VP9RateControlRtcConfig &rc_cfg) { + // Since VPX_MAX_LAYERS (12) is less than the product of VPX_SS_MAX_LAYERS (5) + // and VPX_TS_MAX_LAYERS (5), check all three. + if (rc_cfg.ss_number_layers < 1 || + rc_cfg.ss_number_layers > VPX_SS_MAX_LAYERS || + rc_cfg.ts_number_layers < 1 || + rc_cfg.ts_number_layers > VPX_TS_MAX_LAYERS || + rc_cfg.ss_number_layers * rc_cfg.ts_number_layers > VPX_MAX_LAYERS) { + rc_is_valid_ = false; + return false; + } + if (initial_width_ == 0 && initial_height_ == 0) { + initial_width_ = rc_cfg.width; + initial_height_ = rc_cfg.height; + } + if (rc_cfg.width > initial_width_ || rc_cfg.height > initial_height_) { + rc_is_valid_ = false; + return false; + } + VP9_COMMON *cm = &cpi_->common; VP9EncoderConfig *oxcf = &cpi_->oxcf; RATE_CONTROL *const rc = &cpi_->rc; @@ -102,18 +136,38 @@ void VP9RateControlRTC::UpdateRateControl( oxcf->maximum_buffer_size_ms = rc_cfg.buf_sz; oxcf->under_shoot_pct = rc_cfg.undershoot_pct; oxcf->over_shoot_pct = rc_cfg.overshoot_pct; + oxcf->drop_frames_water_mark = rc_cfg.frame_drop_thresh; + oxcf->content = rc_cfg.is_screen ? VP9E_CONTENT_SCREEN : VP9E_CONTENT_DEFAULT; oxcf->ss_number_layers = rc_cfg.ss_number_layers; oxcf->ts_number_layers = rc_cfg.ts_number_layers; - oxcf->temporal_layering_mode = (VP9E_TEMPORAL_LAYERING_MODE)( - (rc_cfg.ts_number_layers > 1) ? rc_cfg.ts_number_layers : 0); + oxcf->temporal_layering_mode = + (VP9E_TEMPORAL_LAYERING_MODE)((rc_cfg.ts_number_layers > 1) + ? rc_cfg.ts_number_layers + : 0); cpi_->oxcf.rc_max_intra_bitrate_pct = rc_cfg.max_intra_bitrate_pct; cpi_->oxcf.rc_max_inter_bitrate_pct = rc_cfg.max_inter_bitrate_pct; cpi_->framerate = rc_cfg.framerate; cpi_->svc.number_spatial_layers = rc_cfg.ss_number_layers; cpi_->svc.number_temporal_layers = rc_cfg.ts_number_layers; + vp9_set_mb_mi(cm, cm->width, cm->height); + + if (setjmp(cpi_->common.error.jmp)) { + cpi_->common.error.setjmp = 0; + vpx_clear_system_state(); + return false; + } + cpi_->common.error.setjmp = 1; + + for (int tl = 0; tl < cpi_->svc.number_temporal_layers; ++tl) { + oxcf->ts_rate_decimator[tl] = rc_cfg.ts_rate_decimator[tl]; + } for (int sl = 0; sl < cpi_->svc.number_spatial_layers; ++sl) { + if (rc_cfg.scaling_factor_den[sl] < rc_cfg.scaling_factor_num[sl]) { + rc_is_valid_ = false; + return false; + } for (int tl = 0; tl < cpi_->svc.number_temporal_layers; ++tl) { const int layer = LAYER_IDS_TO_IDX(sl, tl, cpi_->svc.number_temporal_layers); @@ -121,26 +175,62 @@ void VP9RateControlRTC::UpdateRateControl( RATE_CONTROL *const lrc = &lc->rc; oxcf->layer_target_bitrate[layer] = 1000 * rc_cfg.layer_target_bitrate[layer]; + if (rc_cfg.max_quantizers[layer] > 63 || + rc_cfg.min_quantizers[layer] < 0 || + rc_cfg.min_quantizers[layer] > rc_cfg.max_quantizers[layer]) { + rc_is_valid_ = false; + return false; + } lrc->worst_quality = vp9_quantizer_to_qindex(rc_cfg.max_quantizers[layer]); lrc->best_quality = vp9_quantizer_to_qindex(rc_cfg.min_quantizers[layer]); lc->scaling_factor_num = rc_cfg.scaling_factor_num[sl]; lc->scaling_factor_den = rc_cfg.scaling_factor_den[sl]; - oxcf->ts_rate_decimator[tl] = rc_cfg.ts_rate_decimator[tl]; } } vp9_set_rc_buffer_sizes(cpi_); vp9_new_framerate(cpi_, cpi_->framerate); if (cpi_->svc.number_temporal_layers > 1 || cpi_->svc.number_spatial_layers > 1) { - if (cm->current_video_frame == 0) vp9_init_layer_context(cpi_); + if (cm->current_video_frame == 0) { + for (int layer = 0; layer < VPX_MAX_LAYERS; layer++) { + LAYER_CONTEXT *const lc = &cpi_->svc.layer_context[layer]; + vpx_free(lc->map); + vpx_free(lc->last_coded_q_map); + vpx_free(lc->consec_zero_mv); + lc->map = nullptr; + lc->last_coded_q_map = nullptr; + lc->consec_zero_mv = nullptr; + } + vp9_init_layer_context(cpi_); + // svc->framedrop_mode is not currently exposed, so only allow for + // full superframe drop for now. + cpi_->svc.framedrop_mode = FULL_SUPERFRAME_DROP; + } vp9_update_layer_context_change_config(cpi_, (int)cpi_->oxcf.target_bandwidth); + cpi_->svc.max_consec_drop = rc_cfg.max_consec_drop; } vp9_check_reset_rc_flag(cpi_); + + cpi_->common.error.setjmp = 0; + rc_is_valid_ = true; + return true; } -void VP9RateControlRTC::ComputeQP(const VP9FrameParamsQpRTC &frame_params) { +// Compute the QP for the frame. If the frame is dropped this function +// returns kDrop, and no QP is computed. If the frame is encoded (not dropped) +// the QP is computed and kOk is returned. +FrameDropDecision VP9RateControlRTC::ComputeQP( + const VP9FrameParamsQpRTC &frame_params) { + if (!rc_is_valid_) return FrameDropDecision::kDrop; + if (frame_params.spatial_layer_id < 0 || + frame_params.spatial_layer_id >= cpi_->svc.number_spatial_layers || + frame_params.temporal_layer_id < 0 || + frame_params.temporal_layer_id >= cpi_->svc.number_temporal_layers || + initial_width_ == 0 || initial_height_ == 0) { + return FrameDropDecision::kDrop; + } VP9_COMMON *const cm = &cpi_->common; int width, height; cpi_->svc.spatial_layer_id = frame_params.spatial_layer_id; @@ -157,7 +247,9 @@ void VP9RateControlRTC::ComputeQP(const VP9FrameParamsQpRTC &frame_params) { cm->height = height; } vp9_set_mb_mi(cm, cm->width, cm->height); - cm->frame_type = frame_params.frame_type; + cm->frame_type = static_cast(frame_params.frame_type); + // This is needed to ensure key frame does not get unset in rc_get_svc_params. + cpi_->frame_flags = (cm->frame_type == KEY_FRAME) ? FRAMEFLAGS_KEY : 0; cpi_->refresh_golden_frame = (cm->frame_type == KEY_FRAME) ? 1 : 0; cpi_->sf.use_nonrd_pick_mode = 1; if (cpi_->svc.number_spatial_layers == 1 && @@ -190,30 +282,106 @@ void VP9RateControlRTC::ComputeQP(const VP9FrameParamsQpRTC &frame_params) { vp9_restore_layer_context(cpi_); vp9_rc_get_svc_params(cpi_); } + if (cpi_->svc.spatial_layer_id == 0) vp9_zero(cpi_->svc.drop_spatial_layer); + // SVC: check for skip encoding of enhancement layer if the + // layer target bandwidth = 0. + if (vp9_svc_check_skip_enhancement_layer(cpi_)) + return FrameDropDecision::kDrop; + // Check for dropping this frame based on buffer level. + // Never drop on key frame, or if base layer is key for svc, + if (!frame_is_intra_only(cm) && + (!cpi_->use_svc || + !cpi_->svc.layer_context[cpi_->svc.temporal_layer_id].is_key_frame)) { + if (vp9_rc_drop_frame(cpi_)) { + // For FULL_SUPERFRAME_DROP mode (the only mode considered here): + // if the superframe drop is decided we need to save the layer context for + // all spatial layers, and call update_buffer_level and postencode_drop + // for all spatial layers. + if (cpi_->svc.number_spatial_layers > 1 || + cpi_->svc.number_temporal_layers > 1) { + vp9_save_layer_context(cpi_); + for (int sl = 1; sl < cpi_->svc.number_spatial_layers; sl++) { + cpi_->svc.spatial_layer_id = sl; + vp9_restore_layer_context(cpi_); + vp9_update_buffer_level_svc_preencode(cpi_); + vp9_rc_postencode_update_drop_frame(cpi_); + vp9_save_layer_context(cpi_); + } + } + return FrameDropDecision::kDrop; + } + } + // Compute the QP for the frame. int bottom_index, top_index; cpi_->common.base_qindex = vp9_rc_pick_q_and_bounds(cpi_, &bottom_index, &top_index); if (cpi_->oxcf.aq_mode == CYCLIC_REFRESH_AQ) vp9_cyclic_refresh_setup(cpi_); + if (cpi_->svc.number_spatial_layers > 1 || + cpi_->svc.number_temporal_layers > 1) + vp9_save_layer_context(cpi_); + + cpi_->last_frame_dropped = 0; + cpi_->svc.last_layer_dropped[cpi_->svc.spatial_layer_id] = 0; + if (cpi_->svc.spatial_layer_id == cpi_->svc.number_spatial_layers - 1) + cpi_->svc.num_encoded_top_layer++; + + return FrameDropDecision::kOk; } -int VP9RateControlRTC::GetQP() const { return cpi_->common.base_qindex; } +int VP9RateControlRTC::GetQP() const { + if (!rc_is_valid_) return 0; + return cpi_->common.base_qindex; +} int VP9RateControlRTC::GetLoopfilterLevel() const { + if (!rc_is_valid_) return 0; struct loopfilter *const lf = &cpi_->common.lf; vp9_pick_filter_level(nullptr, cpi_, LPF_PICK_FROM_Q); return lf->filter_level; } -signed char *VP9RateControlRTC::GetCyclicRefreshMap() const { - return cpi_->cyclic_refresh->map; +bool VP9RateControlRTC::GetSegmentationData( + VP9SegmentationData *segmentation_data) const { + if (!rc_is_valid_) return false; + if (!cpi_->cyclic_refresh || !cpi_->cyclic_refresh->apply_cyclic_refresh) { + return false; + } + + segmentation_data->segmentation_map = cpi_->segmentation_map; + segmentation_data->segmentation_map_size = + cpi_->common.mi_cols * cpi_->common.mi_rows; + segmentation_data->delta_q = cpi_->cyclic_refresh->qindex_delta; + segmentation_data->delta_q_size = 3u; + return true; } -int *VP9RateControlRTC::GetDeltaQ() const { - return cpi_->cyclic_refresh->qindex_delta; -} - -void VP9RateControlRTC::PostEncodeUpdate(uint64_t encoded_frame_size) { +void VP9RateControlRTC::PostEncodeUpdate( + uint64_t encoded_frame_size, const VP9FrameParamsQpRTC &frame_params) { + if (!rc_is_valid_) return; + cpi_->common.frame_type = static_cast(frame_params.frame_type); + cpi_->svc.spatial_layer_id = frame_params.spatial_layer_id; + cpi_->svc.temporal_layer_id = frame_params.temporal_layer_id; + if (cpi_->svc.number_spatial_layers > 1 || + cpi_->svc.number_temporal_layers > 1) { + vp9_restore_layer_context(cpi_); + const int layer = LAYER_IDS_TO_IDX(cpi_->svc.spatial_layer_id, + cpi_->svc.temporal_layer_id, + cpi_->svc.number_temporal_layers); + LAYER_CONTEXT *lc = &cpi_->svc.layer_context[layer]; + cpi_->common.base_qindex = lc->frame_qp; + cpi_->common.MBs = lc->MBs; + // For spatial-svc, allow cyclic-refresh to be applied on the spatial + // layers, for the base temporal layer. + if (cpi_->oxcf.aq_mode == CYCLIC_REFRESH_AQ && + cpi_->svc.number_spatial_layers > 1 && + cpi_->svc.temporal_layer_id == 0) { + CYCLIC_REFRESH *const cr = cpi_->cyclic_refresh; + cr->qindex_delta[0] = lc->qindex_delta[0]; + cr->qindex_delta[1] = lc->qindex_delta[1]; + cr->qindex_delta[2] = lc->qindex_delta[2]; + } + } vp9_rc_postencode_update(cpi_, encoded_frame_size); if (cpi_->svc.number_spatial_layers > 1 || cpi_->svc.number_temporal_layers > 1) diff --git a/libs/libvpx/vp9/ratectrl_rtc.h b/libs/libvpx/vp9/ratectrl_rtc.h index d2b9417aef..3a8cfae62d 100644 --- a/libs/libvpx/vp9/ratectrl_rtc.h +++ b/libs/libvpx/vp9/ratectrl_rtc.h @@ -12,30 +12,20 @@ #define VPX_VP9_RATECTRL_RTC_H_ #include +#include +#include #include -#include "vp9/common/vp9_entropymode.h" -#include "vp9/common/vp9_enums.h" -#include "vp9/common/vp9_onyxc_int.h" -#include "vp9/vp9_iface_common.h" -#include "vp9/encoder/vp9_aq_cyclicrefresh.h" -#include "vp9/encoder/vp9_encoder.h" -#include "vp9/encoder/vp9_firstpass.h" -#include "vp9/vp9_cx_iface.h" +#include "vpx/vpx_encoder.h" #include "vpx/internal/vpx_ratectrl_rtc.h" -#include "vpx_mem/vpx_mem.h" + +struct VP9_COMP; namespace libvpx { - struct VP9RateControlRtcConfig : public VpxRateControlRtcConfig { - public: VP9RateControlRtcConfig() { - vp9_zero(max_quantizers); - vp9_zero(min_quantizers); - vp9_zero(scaling_factor_den); - vp9_zero(scaling_factor_num); - vp9_zero(layer_target_bitrate); - vp9_zero(ts_rate_decimator); + memset(layer_target_bitrate, 0, sizeof(layer_target_bitrate)); + memset(ts_rate_decimator, 0, sizeof(ts_rate_decimator)); scaling_factor_num[0] = 1; scaling_factor_den[0] = 1; max_quantizers[0] = max_quantizer; @@ -43,83 +33,75 @@ struct VP9RateControlRtcConfig : public VpxRateControlRtcConfig { } // Number of spatial layers - int ss_number_layers; - // Number of temporal layers - int ts_number_layers; - int max_quantizers[VPX_MAX_LAYERS]; - int min_quantizers[VPX_MAX_LAYERS]; - int scaling_factor_num[VPX_SS_MAX_LAYERS]; - int scaling_factor_den[VPX_SS_MAX_LAYERS]; + int ss_number_layers = 1; + int max_quantizers[VPX_MAX_LAYERS] = {}; + int min_quantizers[VPX_MAX_LAYERS] = {}; + int scaling_factor_num[VPX_SS_MAX_LAYERS] = {}; + int scaling_factor_den[VPX_SS_MAX_LAYERS] = {}; + // This is only for SVC for now. + int max_consec_drop = std::numeric_limits::max(); }; struct VP9FrameParamsQpRTC { - FRAME_TYPE frame_type; + RcFrameType frame_type; int spatial_layer_id; int temporal_layer_id; }; +struct VP9SegmentationData { + const uint8_t *segmentation_map; + size_t segmentation_map_size; + const int *delta_q; + size_t delta_q_size; +}; + // This interface allows using VP9 real-time rate control without initializing // the encoder. To use this interface, you need to link with libvpxrc.a. // // #include "vp9/ratectrl_rtc.h" -// VP9RateControlRTC rc_api; // VP9RateControlRtcConfig cfg; // VP9FrameParamsQpRTC frame_params; // // YourFunctionToInitializeConfig(cfg); -// rc_api.InitRateControl(cfg); +// std::unique_ptr rc_api = VP9RateControlRTC::Create(cfg); // // start encoding // while (frame_to_encode) { // if (config_changed) -// rc_api.UpdateRateControl(cfg); +// rc_api->UpdateRateControl(cfg); // YourFunctionToFillFrameParams(frame_params); -// rc_api.ComputeQP(frame_params); -// YourFunctionToUseQP(rc_api.GetQP()); -// YourFunctionToUseLoopfilter(rc_api.GetLoopfilterLevel()); +// rc_api->ComputeQP(frame_params); +// YourFunctionToUseQP(rc_api->GetQP()); +// YourFunctionToUseLoopfilter(rc_api->GetLoopfilterLevel()); // // After encoding -// rc_api.PostEncode(encoded_frame_size); +// rc_api->PostEncode(encoded_frame_size, frame_params); // } class VP9RateControlRTC { public: static std::unique_ptr Create( const VP9RateControlRtcConfig &cfg); - ~VP9RateControlRTC() { - if (cpi_) { - if (cpi_->svc.number_spatial_layers > 1 || - cpi_->svc.number_temporal_layers > 1) { - for (int sl = 0; sl < cpi_->svc.number_spatial_layers; sl++) { - for (int tl = 0; tl < cpi_->svc.number_temporal_layers; tl++) { - int layer = LAYER_IDS_TO_IDX(sl, tl, cpi_->oxcf.ts_number_layers); - LAYER_CONTEXT *const lc = &cpi_->svc.layer_context[layer]; - vpx_free(lc->map); - vpx_free(lc->last_coded_q_map); - vpx_free(lc->consec_zero_mv); - } - } - } - if (cpi_->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { - vpx_free(cpi_->segmentation_map); - cpi_->segmentation_map = NULL; - vp9_cyclic_refresh_free(cpi_->cyclic_refresh); - } - vpx_free(cpi_); - } - } + ~VP9RateControlRTC(); - void UpdateRateControl(const VP9RateControlRtcConfig &rc_cfg); + bool UpdateRateControl(const VP9RateControlRtcConfig &rc_cfg); // GetQP() needs to be called after ComputeQP() to get the latest QP int GetQP() const; int GetLoopfilterLevel() const; - signed char *GetCyclicRefreshMap() const; - int *GetDeltaQ() const; - void ComputeQP(const VP9FrameParamsQpRTC &frame_params); + bool GetSegmentationData(VP9SegmentationData *segmentation_data) const; + // ComputeQP computes the QP if the frame is not dropped (kOk return), + // otherwise it returns kDrop and subsequent GetQP and PostEncodeUpdate + // are not to be called (vp9_rc_postencode_update_drop_frame is already + // called via ComputeQP if drop is decided). + FrameDropDecision ComputeQP(const VP9FrameParamsQpRTC &frame_params); // Feedback to rate control with the size of current encoded frame - void PostEncodeUpdate(uint64_t encoded_frame_size); + void PostEncodeUpdate(uint64_t encoded_frame_size, + const VP9FrameParamsQpRTC &frame_params); private: - VP9RateControlRTC() {} - void InitRateControl(const VP9RateControlRtcConfig &cfg); - VP9_COMP *cpi_; + VP9RateControlRTC() = default; + bool InitRateControl(const VP9RateControlRtcConfig &cfg); + struct VP9_COMP *cpi_ = nullptr; + int initial_width_ = 0; + int initial_height_ = 0; + bool rc_is_valid_ = false; }; } // namespace libvpx diff --git a/libs/libvpx/vp9/simple_encode.cc b/libs/libvpx/vp9/simple_encode.cc deleted file mode 100644 index 654699e1b2..0000000000 --- a/libs/libvpx/vp9/simple_encode.cc +++ /dev/null @@ -1,1330 +0,0 @@ -/* - * Copyright (c) 2019 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include -#include -#include "./ivfenc.h" -#include "vp9/common/vp9_entropymode.h" -#include "vp9/common/vp9_enums.h" -#include "vp9/common/vp9_onyxc_int.h" -#include "vp9/vp9_iface_common.h" -#include "vp9/encoder/vp9_encoder.h" -#include "vp9/encoder/vp9_firstpass.h" -#include "vp9/simple_encode.h" -#include "vp9/vp9_cx_iface.h" - -namespace vp9 { - -static int get_plane_height(vpx_img_fmt_t img_fmt, int frame_height, - int plane) { - assert(plane < 3); - if (plane == 0) { - return frame_height; - } - switch (img_fmt) { - case VPX_IMG_FMT_I420: - case VPX_IMG_FMT_I440: - case VPX_IMG_FMT_YV12: - case VPX_IMG_FMT_I42016: - case VPX_IMG_FMT_I44016: return (frame_height + 1) >> 1; - default: return frame_height; - } -} - -static int get_plane_width(vpx_img_fmt_t img_fmt, int frame_width, int plane) { - assert(plane < 3); - if (plane == 0) { - return frame_width; - } - switch (img_fmt) { - case VPX_IMG_FMT_I420: - case VPX_IMG_FMT_YV12: - case VPX_IMG_FMT_I422: - case VPX_IMG_FMT_I42016: - case VPX_IMG_FMT_I42216: return (frame_width + 1) >> 1; - default: return frame_width; - } -} - -// TODO(angiebird): Merge this function with vpx_img_plane_width() -static int img_plane_width(const vpx_image_t *img, int plane) { - if (plane > 0 && img->x_chroma_shift > 0) - return (img->d_w + 1) >> img->x_chroma_shift; - else - return img->d_w; -} - -// TODO(angiebird): Merge this function with vpx_img_plane_height() -static int img_plane_height(const vpx_image_t *img, int plane) { - if (plane > 0 && img->y_chroma_shift > 0) - return (img->d_h + 1) >> img->y_chroma_shift; - else - return img->d_h; -} - -// TODO(angiebird): Merge this function with vpx_img_read() -static int img_read(vpx_image_t *img, FILE *file) { - int plane; - - for (plane = 0; plane < 3; ++plane) { - unsigned char *buf = img->planes[plane]; - const int stride = img->stride[plane]; - const int w = img_plane_width(img, plane) * - ((img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? 2 : 1); - const int h = img_plane_height(img, plane); - int y; - - for (y = 0; y < h; ++y) { - if (fread(buf, 1, w, file) != (size_t)w) return 0; - buf += stride; - } - } - - return 1; -} - -// Assume every config in VP9EncoderConfig is less than 100 characters. -#define ENCODE_CONFIG_BUF_SIZE 100 -struct EncodeConfig { - char name[ENCODE_CONFIG_BUF_SIZE]; - char value[ENCODE_CONFIG_BUF_SIZE]; -}; - -class SimpleEncode::EncodeImpl { - public: - VP9_COMP *cpi; - vpx_img_fmt_t img_fmt; - vpx_image_t tmp_img; - std::vector first_pass_stats; - std::vector encode_config_list; -}; - -static VP9_COMP *init_encoder(const VP9EncoderConfig *oxcf, - vpx_img_fmt_t img_fmt) { - VP9_COMP *cpi; - BufferPool *buffer_pool = (BufferPool *)vpx_calloc(1, sizeof(*buffer_pool)); - if (!buffer_pool) return NULL; - vp9_initialize_enc(); - cpi = vp9_create_compressor(oxcf, buffer_pool); - vp9_update_compressor_with_img_fmt(cpi, img_fmt); - return cpi; -} - -static void free_encoder(VP9_COMP *cpi) { - BufferPool *buffer_pool = cpi->common.buffer_pool; - vp9_remove_compressor(cpi); - // buffer_pool needs to be free after cpi because buffer_pool contains - // allocated buffers that will be free in vp9_remove_compressor() - vpx_free(buffer_pool); -} - -static INLINE vpx_rational_t make_vpx_rational(int num, int den) { - vpx_rational_t v; - v.num = num; - v.den = den; - return v; -} - -static INLINE FrameType -get_frame_type_from_update_type(FRAME_UPDATE_TYPE update_type) { - switch (update_type) { - case KF_UPDATE: return kFrameTypeKey; - case ARF_UPDATE: return kFrameTypeAltRef; - case GF_UPDATE: return kFrameTypeGolden; - case OVERLAY_UPDATE: return kFrameTypeOverlay; - case LF_UPDATE: return kFrameTypeInter; - default: - fprintf(stderr, "Unsupported update_type %d\n", update_type); - abort(); - return kFrameTypeInter; - } -} - -static void update_partition_info(const PARTITION_INFO *input_partition_info, - const int num_rows_4x4, - const int num_cols_4x4, - PartitionInfo *output_partition_info) { - const int num_units_4x4 = num_rows_4x4 * num_cols_4x4; - for (int i = 0; i < num_units_4x4; ++i) { - output_partition_info[i].row = input_partition_info[i].row; - output_partition_info[i].column = input_partition_info[i].column; - output_partition_info[i].row_start = input_partition_info[i].row_start; - output_partition_info[i].column_start = - input_partition_info[i].column_start; - output_partition_info[i].width = input_partition_info[i].width; - output_partition_info[i].height = input_partition_info[i].height; - } -} - -// translate MV_REFERENCE_FRAME to RefFrameType -static RefFrameType mv_ref_frame_to_ref_frame_type( - MV_REFERENCE_FRAME mv_ref_frame) { - switch (mv_ref_frame) { - case LAST_FRAME: return kRefFrameTypeLast; - case GOLDEN_FRAME: return kRefFrameTypePast; - case ALTREF_FRAME: return kRefFrameTypeFuture; - default: return kRefFrameTypeNone; - } -} - -static void update_motion_vector_info( - const MOTION_VECTOR_INFO *input_motion_vector_info, const int num_rows_4x4, - const int num_cols_4x4, MotionVectorInfo *output_motion_vector_info, - int motion_vector_scale) { - const int num_units_4x4 = num_rows_4x4 * num_cols_4x4; - for (int i = 0; i < num_units_4x4; ++i) { - const MV_REFERENCE_FRAME *in_ref_frame = - input_motion_vector_info[i].ref_frame; - output_motion_vector_info[i].mv_count = - (in_ref_frame[0] == INTRA_FRAME) ? 0 - : ((in_ref_frame[1] == NONE) ? 1 : 2); - if (in_ref_frame[0] == NONE) { - fprintf(stderr, "in_ref_frame[0] shouldn't be NONE\n"); - abort(); - } - output_motion_vector_info[i].ref_frame[0] = - mv_ref_frame_to_ref_frame_type(in_ref_frame[0]); - output_motion_vector_info[i].ref_frame[1] = - mv_ref_frame_to_ref_frame_type(in_ref_frame[1]); - output_motion_vector_info[i].mv_row[0] = - (double)input_motion_vector_info[i].mv[0].as_mv.row / - motion_vector_scale; - output_motion_vector_info[i].mv_column[0] = - (double)input_motion_vector_info[i].mv[0].as_mv.col / - motion_vector_scale; - output_motion_vector_info[i].mv_row[1] = - (double)input_motion_vector_info[i].mv[1].as_mv.row / - motion_vector_scale; - output_motion_vector_info[i].mv_column[1] = - (double)input_motion_vector_info[i].mv[1].as_mv.col / - motion_vector_scale; - } -} - -static void update_tpl_stats_info(const TplDepStats *input_tpl_stats_info, - const int show_frame_count, - TplStatsInfo *output_tpl_stats_info) { - int frame_idx; - for (frame_idx = 0; frame_idx < show_frame_count; ++frame_idx) { - output_tpl_stats_info[frame_idx].intra_cost = - input_tpl_stats_info[frame_idx].intra_cost; - output_tpl_stats_info[frame_idx].inter_cost = - input_tpl_stats_info[frame_idx].inter_cost; - output_tpl_stats_info[frame_idx].mc_flow = - input_tpl_stats_info[frame_idx].mc_flow; - output_tpl_stats_info[frame_idx].mc_dep_cost = - input_tpl_stats_info[frame_idx].mc_dep_cost; - output_tpl_stats_info[frame_idx].mc_ref_cost = - input_tpl_stats_info[frame_idx].mc_ref_cost; - } -} - -static void update_frame_counts(const FRAME_COUNTS *input_counts, - FrameCounts *output_counts) { - // Init array sizes. - output_counts->y_mode.resize(BLOCK_SIZE_GROUPS); - for (int i = 0; i < BLOCK_SIZE_GROUPS; ++i) { - output_counts->y_mode[i].resize(INTRA_MODES); - } - - output_counts->uv_mode.resize(INTRA_MODES); - for (int i = 0; i < INTRA_MODES; ++i) { - output_counts->uv_mode[i].resize(INTRA_MODES); - } - - output_counts->partition.resize(PARTITION_CONTEXTS); - for (int i = 0; i < PARTITION_CONTEXTS; ++i) { - output_counts->partition[i].resize(PARTITION_TYPES); - } - - output_counts->coef.resize(TX_SIZES); - output_counts->eob_branch.resize(TX_SIZES); - for (int i = 0; i < TX_SIZES; ++i) { - output_counts->coef[i].resize(PLANE_TYPES); - output_counts->eob_branch[i].resize(PLANE_TYPES); - for (int j = 0; j < PLANE_TYPES; ++j) { - output_counts->coef[i][j].resize(REF_TYPES); - output_counts->eob_branch[i][j].resize(REF_TYPES); - for (int k = 0; k < REF_TYPES; ++k) { - output_counts->coef[i][j][k].resize(COEF_BANDS); - output_counts->eob_branch[i][j][k].resize(COEF_BANDS); - for (int l = 0; l < COEF_BANDS; ++l) { - output_counts->coef[i][j][k][l].resize(COEFF_CONTEXTS); - output_counts->eob_branch[i][j][k][l].resize(COEFF_CONTEXTS); - for (int m = 0; m < COEFF_CONTEXTS; ++m) { - output_counts->coef[i][j][k][l][m].resize(UNCONSTRAINED_NODES + 1); - } - } - } - } - } - - output_counts->switchable_interp.resize(SWITCHABLE_FILTER_CONTEXTS); - for (int i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) { - output_counts->switchable_interp[i].resize(SWITCHABLE_FILTERS); - } - - output_counts->inter_mode.resize(INTER_MODE_CONTEXTS); - for (int i = 0; i < INTER_MODE_CONTEXTS; ++i) { - output_counts->inter_mode[i].resize(INTER_MODES); - } - - output_counts->intra_inter.resize(INTRA_INTER_CONTEXTS); - for (int i = 0; i < INTRA_INTER_CONTEXTS; ++i) { - output_counts->intra_inter[i].resize(2); - } - - output_counts->comp_inter.resize(COMP_INTER_CONTEXTS); - for (int i = 0; i < COMP_INTER_CONTEXTS; ++i) { - output_counts->comp_inter[i].resize(2); - } - - output_counts->single_ref.resize(REF_CONTEXTS); - for (int i = 0; i < REF_CONTEXTS; ++i) { - output_counts->single_ref[i].resize(2); - for (int j = 0; j < 2; ++j) { - output_counts->single_ref[i][j].resize(2); - } - } - - output_counts->comp_ref.resize(REF_CONTEXTS); - for (int i = 0; i < REF_CONTEXTS; ++i) { - output_counts->comp_ref[i].resize(2); - } - - output_counts->skip.resize(SKIP_CONTEXTS); - for (int i = 0; i < SKIP_CONTEXTS; ++i) { - output_counts->skip[i].resize(2); - } - - output_counts->tx.p32x32.resize(TX_SIZE_CONTEXTS); - output_counts->tx.p16x16.resize(TX_SIZE_CONTEXTS); - output_counts->tx.p8x8.resize(TX_SIZE_CONTEXTS); - for (int i = 0; i < TX_SIZE_CONTEXTS; i++) { - output_counts->tx.p32x32[i].resize(TX_SIZES); - output_counts->tx.p16x16[i].resize(TX_SIZES - 1); - output_counts->tx.p8x8[i].resize(TX_SIZES - 2); - } - output_counts->tx.tx_totals.resize(TX_SIZES); - - output_counts->mv.joints.resize(MV_JOINTS); - output_counts->mv.comps.resize(2); - for (int i = 0; i < 2; ++i) { - output_counts->mv.comps[i].sign.resize(2); - output_counts->mv.comps[i].classes.resize(MV_CLASSES); - output_counts->mv.comps[i].class0.resize(CLASS0_SIZE); - output_counts->mv.comps[i].bits.resize(MV_OFFSET_BITS); - for (int j = 0; j < MV_OFFSET_BITS; ++j) { - output_counts->mv.comps[i].bits[j].resize(2); - } - output_counts->mv.comps[i].class0_fp.resize(CLASS0_SIZE); - for (int j = 0; j < CLASS0_SIZE; ++j) { - output_counts->mv.comps[i].class0_fp[j].resize(MV_FP_SIZE); - } - output_counts->mv.comps[i].fp.resize(MV_FP_SIZE); - output_counts->mv.comps[i].class0_hp.resize(2); - output_counts->mv.comps[i].hp.resize(2); - } - - // Populate counts. - for (int i = 0; i < BLOCK_SIZE_GROUPS; ++i) { - for (int j = 0; j < INTRA_MODES; ++j) { - output_counts->y_mode[i][j] = input_counts->y_mode[i][j]; - } - } - for (int i = 0; i < INTRA_MODES; ++i) { - for (int j = 0; j < INTRA_MODES; ++j) { - output_counts->uv_mode[i][j] = input_counts->uv_mode[i][j]; - } - } - for (int i = 0; i < PARTITION_CONTEXTS; ++i) { - for (int j = 0; j < PARTITION_TYPES; ++j) { - output_counts->partition[i][j] = input_counts->partition[i][j]; - } - } - for (int i = 0; i < TX_SIZES; ++i) { - for (int j = 0; j < PLANE_TYPES; ++j) { - for (int k = 0; k < REF_TYPES; ++k) { - for (int l = 0; l < COEF_BANDS; ++l) { - for (int m = 0; m < COEFF_CONTEXTS; ++m) { - output_counts->eob_branch[i][j][k][l][m] = - input_counts->eob_branch[i][j][k][l][m]; - for (int n = 0; n < UNCONSTRAINED_NODES + 1; n++) { - output_counts->coef[i][j][k][l][m][n] = - input_counts->coef[i][j][k][l][m][n]; - } - } - } - } - } - } - for (int i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) { - for (int j = 0; j < SWITCHABLE_FILTERS; ++j) { - output_counts->switchable_interp[i][j] = - input_counts->switchable_interp[i][j]; - } - } - for (int i = 0; i < INTER_MODE_CONTEXTS; ++i) { - for (int j = 0; j < INTER_MODES; ++j) { - output_counts->inter_mode[i][j] = input_counts->inter_mode[i][j]; - } - } - for (int i = 0; i < INTRA_INTER_CONTEXTS; ++i) { - for (int j = 0; j < 2; ++j) { - output_counts->intra_inter[i][j] = input_counts->intra_inter[i][j]; - } - } - for (int i = 0; i < COMP_INTER_CONTEXTS; ++i) { - for (int j = 0; j < 2; ++j) { - output_counts->comp_inter[i][j] = input_counts->comp_inter[i][j]; - } - } - for (int i = 0; i < REF_CONTEXTS; ++i) { - for (int j = 0; j < 2; ++j) { - for (int k = 0; k < 2; ++k) { - output_counts->single_ref[i][j][k] = input_counts->single_ref[i][j][k]; - } - } - } - for (int i = 0; i < REF_CONTEXTS; ++i) { - for (int j = 0; j < 2; ++j) { - output_counts->comp_ref[i][j] = input_counts->comp_ref[i][j]; - } - } - for (int i = 0; i < SKIP_CONTEXTS; ++i) { - for (int j = 0; j < 2; ++j) { - output_counts->skip[i][j] = input_counts->skip[i][j]; - } - } - for (int i = 0; i < TX_SIZE_CONTEXTS; i++) { - for (int j = 0; j < TX_SIZES; j++) { - output_counts->tx.p32x32[i][j] = input_counts->tx.p32x32[i][j]; - } - for (int j = 0; j < TX_SIZES - 1; j++) { - output_counts->tx.p16x16[i][j] = input_counts->tx.p16x16[i][j]; - } - for (int j = 0; j < TX_SIZES - 2; j++) { - output_counts->tx.p8x8[i][j] = input_counts->tx.p8x8[i][j]; - } - } - for (int i = 0; i < TX_SIZES; i++) { - output_counts->tx.tx_totals[i] = input_counts->tx.tx_totals[i]; - } - for (int i = 0; i < MV_JOINTS; i++) { - output_counts->mv.joints[i] = input_counts->mv.joints[i]; - } - for (int k = 0; k < 2; k++) { - const nmv_component_counts *const comps_t = &input_counts->mv.comps[k]; - for (int i = 0; i < 2; i++) { - output_counts->mv.comps[k].sign[i] = comps_t->sign[i]; - output_counts->mv.comps[k].class0_hp[i] = comps_t->class0_hp[i]; - output_counts->mv.comps[k].hp[i] = comps_t->hp[i]; - } - for (int i = 0; i < MV_CLASSES; i++) { - output_counts->mv.comps[k].classes[i] = comps_t->classes[i]; - } - for (int i = 0; i < CLASS0_SIZE; i++) { - output_counts->mv.comps[k].class0[i] = comps_t->class0[i]; - for (int j = 0; j < MV_FP_SIZE; j++) { - output_counts->mv.comps[k].class0_fp[i][j] = comps_t->class0_fp[i][j]; - } - } - for (int i = 0; i < MV_OFFSET_BITS; i++) { - for (int j = 0; j < 2; j++) { - output_counts->mv.comps[k].bits[i][j] = comps_t->bits[i][j]; - } - } - for (int i = 0; i < MV_FP_SIZE; i++) { - output_counts->mv.comps[k].fp[i] = comps_t->fp[i]; - } - } -} - -void output_image_buffer(const ImageBuffer &image_buffer, std::FILE *out_file) { - for (int plane = 0; plane < 3; ++plane) { - const int w = image_buffer.plane_width[plane]; - const int h = image_buffer.plane_height[plane]; - const uint8_t *buf = image_buffer.plane_buffer[plane].get(); - fprintf(out_file, "%d %d\n", h, w); - for (int i = 0; i < w * h; ++i) { - fprintf(out_file, "%d ", (int)buf[i]); - } - fprintf(out_file, "\n"); - } -} - -static bool init_image_buffer(ImageBuffer *image_buffer, int frame_width, - int frame_height, vpx_img_fmt_t img_fmt) { - for (int plane = 0; plane < 3; ++plane) { - const int w = get_plane_width(img_fmt, frame_width, plane); - const int h = get_plane_height(img_fmt, frame_height, plane); - image_buffer->plane_width[plane] = w; - image_buffer->plane_height[plane] = h; - image_buffer->plane_buffer[plane].reset(new (std::nothrow) uint8_t[w * h]); - if (image_buffer->plane_buffer[plane].get() == nullptr) { - return false; - } - } - return true; -} - -static void ImageBuffer_to_IMAGE_BUFFER(const ImageBuffer &image_buffer, - IMAGE_BUFFER *image_buffer_c) { - image_buffer_c->allocated = 1; - for (int plane = 0; plane < 3; ++plane) { - image_buffer_c->plane_width[plane] = image_buffer.plane_width[plane]; - image_buffer_c->plane_height[plane] = image_buffer.plane_height[plane]; - image_buffer_c->plane_buffer[plane] = - image_buffer.plane_buffer[plane].get(); - } -} - -static size_t get_max_coding_data_byte_size(int frame_width, int frame_height) { - return frame_width * frame_height * 3; -} - -static bool init_encode_frame_result(EncodeFrameResult *encode_frame_result, - int frame_width, int frame_height, - vpx_img_fmt_t img_fmt) { - const size_t max_coding_data_byte_size = - get_max_coding_data_byte_size(frame_width, frame_height); - - encode_frame_result->coding_data.reset( - new (std::nothrow) uint8_t[max_coding_data_byte_size]); - - encode_frame_result->num_rows_4x4 = get_num_unit_4x4(frame_height); - encode_frame_result->num_cols_4x4 = get_num_unit_4x4(frame_width); - encode_frame_result->partition_info.resize(encode_frame_result->num_rows_4x4 * - encode_frame_result->num_cols_4x4); - encode_frame_result->motion_vector_info.resize( - encode_frame_result->num_rows_4x4 * encode_frame_result->num_cols_4x4); - encode_frame_result->tpl_stats_info.resize(MAX_LAG_BUFFERS); - - if (encode_frame_result->coding_data.get() == nullptr) { - return false; - } - return init_image_buffer(&encode_frame_result->coded_frame, frame_width, - frame_height, img_fmt); -} - -static void encode_frame_result_update_rq_history( - const RATE_QINDEX_HISTORY *rq_history, - EncodeFrameResult *encode_frame_result) { - encode_frame_result->recode_count = rq_history->recode_count; - for (int i = 0; i < encode_frame_result->recode_count; ++i) { - const int q_index = rq_history->q_index_history[i]; - const int rate = rq_history->rate_history[i]; - encode_frame_result->q_index_history.push_back(q_index); - encode_frame_result->rate_history.push_back(rate); - } -} - -static void update_encode_frame_result( - EncodeFrameResult *encode_frame_result, const int show_frame_count, - const ENCODE_FRAME_RESULT *encode_frame_info) { - encode_frame_result->coding_data_bit_size = - encode_frame_result->coding_data_byte_size * 8; - encode_frame_result->show_idx = encode_frame_info->show_idx; - encode_frame_result->coding_idx = encode_frame_info->frame_coding_index; - assert(kRefFrameTypeMax == MAX_INTER_REF_FRAMES); - for (int i = 0; i < kRefFrameTypeMax; ++i) { - encode_frame_result->ref_frame_info.coding_indexes[i] = - encode_frame_info->ref_frame_coding_indexes[i]; - encode_frame_result->ref_frame_info.valid_list[i] = - encode_frame_info->ref_frame_valid_list[i]; - } - encode_frame_result->frame_type = - get_frame_type_from_update_type(encode_frame_info->update_type); - encode_frame_result->psnr = encode_frame_info->psnr; - encode_frame_result->sse = encode_frame_info->sse; - encode_frame_result->quantize_index = encode_frame_info->quantize_index; - update_partition_info(encode_frame_info->partition_info, - encode_frame_result->num_rows_4x4, - encode_frame_result->num_cols_4x4, - &encode_frame_result->partition_info[0]); - update_motion_vector_info(encode_frame_info->motion_vector_info, - encode_frame_result->num_rows_4x4, - encode_frame_result->num_cols_4x4, - &encode_frame_result->motion_vector_info[0], - kMotionVectorSubPixelPrecision); - update_frame_counts(&encode_frame_info->frame_counts, - &encode_frame_result->frame_counts); - if (encode_frame_result->frame_type == kFrameTypeAltRef) { - update_tpl_stats_info(encode_frame_info->tpl_stats_info, show_frame_count, - &encode_frame_result->tpl_stats_info[0]); - } - encode_frame_result_update_rq_history(&encode_frame_info->rq_history, - encode_frame_result); -} - -static void IncreaseGroupOfPictureIndex(GroupOfPicture *group_of_picture) { - ++group_of_picture->next_encode_frame_index; -} - -static int IsGroupOfPictureFinished(const GroupOfPicture &group_of_picture) { - return static_cast(group_of_picture.next_encode_frame_index) == - group_of_picture.encode_frame_list.size(); -} - -bool operator==(const RefFrameInfo &a, const RefFrameInfo &b) { - bool match = true; - for (int i = 0; i < kRefFrameTypeMax; ++i) { - match &= a.coding_indexes[i] == b.coding_indexes[i]; - match &= a.valid_list[i] == b.valid_list[i]; - } - return match; -} - -static void InitRefFrameInfo(RefFrameInfo *ref_frame_info) { - for (int i = 0; i < kRefFrameTypeMax; ++i) { - ref_frame_info->coding_indexes[i] = -1; - ref_frame_info->valid_list[i] = 0; - } -} - -// After finishing coding a frame, this function will update the coded frame -// into the ref_frame_info based on the frame_type and the coding_index. -static void PostUpdateRefFrameInfo(FrameType frame_type, int frame_coding_index, - RefFrameInfo *ref_frame_info) { - // This part is written based on the logics in vp9_configure_buffer_updates() - // and update_ref_frames() - int *ref_frame_coding_indexes = ref_frame_info->coding_indexes; - switch (frame_type) { - case kFrameTypeKey: - ref_frame_coding_indexes[kRefFrameTypeLast] = frame_coding_index; - ref_frame_coding_indexes[kRefFrameTypePast] = frame_coding_index; - ref_frame_coding_indexes[kRefFrameTypeFuture] = frame_coding_index; - break; - case kFrameTypeInter: - ref_frame_coding_indexes[kRefFrameTypeLast] = frame_coding_index; - break; - case kFrameTypeAltRef: - ref_frame_coding_indexes[kRefFrameTypeFuture] = frame_coding_index; - break; - case kFrameTypeOverlay: - // Reserve the past coding_index in the future slot. This logic is from - // update_ref_frames() with condition vp9_preserve_existing_gf() == 1 - // TODO(angiebird): Invetegate why we need this. - ref_frame_coding_indexes[kRefFrameTypeFuture] = - ref_frame_coding_indexes[kRefFrameTypePast]; - ref_frame_coding_indexes[kRefFrameTypePast] = frame_coding_index; - break; - case kFrameTypeGolden: - ref_frame_coding_indexes[kRefFrameTypePast] = frame_coding_index; - ref_frame_coding_indexes[kRefFrameTypeLast] = frame_coding_index; - break; - } - - // This part is written based on the logics in get_ref_frame_flags() but we - // rename the flags alt, golden to future, past respectively. Mark - // non-duplicated reference frames as valid. The priorities are - // kRefFrameTypeLast > kRefFrameTypePast > kRefFrameTypeFuture. - const int last_index = ref_frame_coding_indexes[kRefFrameTypeLast]; - const int past_index = ref_frame_coding_indexes[kRefFrameTypePast]; - const int future_index = ref_frame_coding_indexes[kRefFrameTypeFuture]; - - int *ref_frame_valid_list = ref_frame_info->valid_list; - for (int ref_frame_idx = 0; ref_frame_idx < kRefFrameTypeMax; - ++ref_frame_idx) { - ref_frame_valid_list[ref_frame_idx] = 1; - } - - if (past_index == last_index) { - ref_frame_valid_list[kRefFrameTypePast] = 0; - } - - if (future_index == last_index) { - ref_frame_valid_list[kRefFrameTypeFuture] = 0; - } - - if (future_index == past_index) { - ref_frame_valid_list[kRefFrameTypeFuture] = 0; - } -} - -static void SetGroupOfPicture(int first_is_key_frame, int use_alt_ref, - int coding_frame_count, int first_show_idx, - int last_gop_use_alt_ref, int start_coding_index, - const RefFrameInfo &start_ref_frame_info, - GroupOfPicture *group_of_picture) { - // Clean up the state of previous group of picture. - group_of_picture->encode_frame_list.clear(); - group_of_picture->next_encode_frame_index = 0; - group_of_picture->show_frame_count = coding_frame_count - use_alt_ref; - group_of_picture->start_show_index = first_show_idx; - group_of_picture->start_coding_index = start_coding_index; - group_of_picture->first_is_key_frame = first_is_key_frame; - group_of_picture->use_alt_ref = use_alt_ref; - group_of_picture->last_gop_use_alt_ref = last_gop_use_alt_ref; - - // We need to make a copy of start reference frame info because we - // use it to simulate the ref frame update. - RefFrameInfo ref_frame_info = start_ref_frame_info; - - { - // First frame in the group of pictures. It's either key frame or show inter - // frame. - EncodeFrameInfo encode_frame_info; - // Set frame_type - if (first_is_key_frame) { - encode_frame_info.frame_type = kFrameTypeKey; - } else { - if (last_gop_use_alt_ref) { - encode_frame_info.frame_type = kFrameTypeOverlay; - } else { - encode_frame_info.frame_type = kFrameTypeGolden; - } - } - - encode_frame_info.show_idx = first_show_idx; - encode_frame_info.coding_index = start_coding_index; - - encode_frame_info.ref_frame_info = ref_frame_info; - PostUpdateRefFrameInfo(encode_frame_info.frame_type, - encode_frame_info.coding_index, &ref_frame_info); - - group_of_picture->encode_frame_list.push_back(encode_frame_info); - } - - const int show_frame_count = coding_frame_count - use_alt_ref; - if (use_alt_ref) { - // If there is alternate reference, it is always coded at the second place. - // Its show index (or timestamp) is at the last of this group - EncodeFrameInfo encode_frame_info; - encode_frame_info.frame_type = kFrameTypeAltRef; - encode_frame_info.show_idx = first_show_idx + show_frame_count; - encode_frame_info.coding_index = start_coding_index + 1; - - encode_frame_info.ref_frame_info = ref_frame_info; - PostUpdateRefFrameInfo(encode_frame_info.frame_type, - encode_frame_info.coding_index, &ref_frame_info); - - group_of_picture->encode_frame_list.push_back(encode_frame_info); - } - - // Encode the rest show inter frames. - for (int i = 1; i < show_frame_count; ++i) { - EncodeFrameInfo encode_frame_info; - encode_frame_info.frame_type = kFrameTypeInter; - encode_frame_info.show_idx = first_show_idx + i; - encode_frame_info.coding_index = start_coding_index + use_alt_ref + i; - - encode_frame_info.ref_frame_info = ref_frame_info; - PostUpdateRefFrameInfo(encode_frame_info.frame_type, - encode_frame_info.coding_index, &ref_frame_info); - - group_of_picture->encode_frame_list.push_back(encode_frame_info); - } -} - -// Gets group of picture information from VP9's decision, and update -// |group_of_picture| accordingly. -// This is called at the starting of encoding of each group of picture. -static void UpdateGroupOfPicture(const VP9_COMP *cpi, int start_coding_index, - const RefFrameInfo &start_ref_frame_info, - GroupOfPicture *group_of_picture) { - int first_is_key_frame; - int use_alt_ref; - int coding_frame_count; - int first_show_idx; - int last_gop_use_alt_ref; - vp9_get_next_group_of_picture(cpi, &first_is_key_frame, &use_alt_ref, - &coding_frame_count, &first_show_idx, - &last_gop_use_alt_ref); - SetGroupOfPicture(first_is_key_frame, use_alt_ref, coding_frame_count, - first_show_idx, last_gop_use_alt_ref, start_coding_index, - start_ref_frame_info, group_of_picture); -} - -#define SET_STRUCT_VALUE(config, structure, ret, field) \ - if (strcmp(config.name, #field) == 0) { \ - structure->field = atoi(config.value); \ - ret = 1; \ - } - -static void UpdateEncodeConfig(const EncodeConfig &config, - VP9EncoderConfig *oxcf) { - int ret = 0; - SET_STRUCT_VALUE(config, oxcf, ret, key_freq); - SET_STRUCT_VALUE(config, oxcf, ret, two_pass_vbrmin_section); - SET_STRUCT_VALUE(config, oxcf, ret, two_pass_vbrmax_section); - SET_STRUCT_VALUE(config, oxcf, ret, under_shoot_pct); - SET_STRUCT_VALUE(config, oxcf, ret, over_shoot_pct); - SET_STRUCT_VALUE(config, oxcf, ret, max_threads); - SET_STRUCT_VALUE(config, oxcf, ret, frame_parallel_decoding_mode); - SET_STRUCT_VALUE(config, oxcf, ret, tile_columns); - SET_STRUCT_VALUE(config, oxcf, ret, arnr_max_frames); - SET_STRUCT_VALUE(config, oxcf, ret, arnr_strength); - SET_STRUCT_VALUE(config, oxcf, ret, lag_in_frames); - SET_STRUCT_VALUE(config, oxcf, ret, encode_breakout); - SET_STRUCT_VALUE(config, oxcf, ret, enable_tpl_model); - SET_STRUCT_VALUE(config, oxcf, ret, enable_auto_arf); - if (strcmp(config.name, "rc_mode") == 0) { - int rc_mode = atoi(config.value); - if (rc_mode >= VPX_VBR && rc_mode <= VPX_Q) { - oxcf->rc_mode = (enum vpx_rc_mode)rc_mode; - ret = 1; - } else { - fprintf(stderr, "Invalid rc_mode value: %d\n", rc_mode); - } - } - SET_STRUCT_VALUE(config, oxcf, ret, cq_level); - if (ret == 0) { - fprintf(stderr, "Ignored unsupported encode_config %s\n", config.name); - } -} - -static VP9EncoderConfig GetEncodeConfig( - int frame_width, int frame_height, vpx_rational_t frame_rate, - int target_bitrate, int encode_speed, int target_level, - vpx_enc_pass enc_pass, - const std::vector &encode_config_list) { - VP9EncoderConfig oxcf = vp9_get_encoder_config( - frame_width, frame_height, frame_rate, target_bitrate, encode_speed, - target_level, enc_pass); - for (const auto &config : encode_config_list) { - UpdateEncodeConfig(config, &oxcf); - } - if (enc_pass == VPX_RC_FIRST_PASS) { - oxcf.lag_in_frames = 0; - } - oxcf.use_simple_encode_api = 1; - return oxcf; -} - -SimpleEncode::SimpleEncode(int frame_width, int frame_height, - int frame_rate_num, int frame_rate_den, - int target_bitrate, int num_frames, int target_level, - const char *infile_path, const char *outfile_path) { - impl_ptr_ = std::unique_ptr(new EncodeImpl()); - frame_width_ = frame_width; - frame_height_ = frame_height; - frame_rate_num_ = frame_rate_num; - frame_rate_den_ = frame_rate_den; - target_bitrate_ = target_bitrate; - num_frames_ = num_frames; - encode_speed_ = 0; - target_level_ = target_level; - - frame_coding_index_ = 0; - show_frame_count_ = 0; - - key_frame_group_index_ = 0; - key_frame_group_size_ = 0; - - // TODO(angirbid): Should we keep a file pointer here or keep the file_path? - assert(infile_path != nullptr); - in_file_ = fopen(infile_path, "r"); - if (outfile_path != nullptr) { - out_file_ = fopen(outfile_path, "w"); - } else { - out_file_ = nullptr; - } - impl_ptr_->cpi = nullptr; - impl_ptr_->img_fmt = VPX_IMG_FMT_I420; - - InitRefFrameInfo(&ref_frame_info_); -} - -void SimpleEncode::SetEncodeSpeed(int encode_speed) { - encode_speed_ = encode_speed; -} - -StatusCode SimpleEncode::SetEncodeConfig(const char *name, const char *value) { - if (name == nullptr || value == nullptr) { - fprintf(stderr, "SetEncodeConfig: null pointer, name %p value %p\n", name, - value); - return StatusError; - } - EncodeConfig config; - snprintf(config.name, ENCODE_CONFIG_BUF_SIZE, "%s", name); - snprintf(config.value, ENCODE_CONFIG_BUF_SIZE, "%s", value); - impl_ptr_->encode_config_list.push_back(config); - return StatusOk; -} - -StatusCode SimpleEncode::DumpEncodeConfigs(int pass, FILE *fp) { - if (fp == nullptr) { - fprintf(stderr, "DumpEncodeConfigs: null pointer, fp %p\n", fp); - return StatusError; - } - vpx_enc_pass enc_pass; - if (pass == 1) { - enc_pass = VPX_RC_FIRST_PASS; - } else { - enc_pass = VPX_RC_LAST_PASS; - } - const vpx_rational_t frame_rate = - make_vpx_rational(frame_rate_num_, frame_rate_den_); - const VP9EncoderConfig oxcf = GetEncodeConfig( - frame_width_, frame_height_, frame_rate, target_bitrate_, encode_speed_, - target_level_, enc_pass, impl_ptr_->encode_config_list); - vp9_dump_encoder_config(&oxcf, fp); - return StatusOk; -} - -void SimpleEncode::ComputeFirstPassStats() { - vpx_rational_t frame_rate = - make_vpx_rational(frame_rate_num_, frame_rate_den_); - const VP9EncoderConfig oxcf = GetEncodeConfig( - frame_width_, frame_height_, frame_rate, target_bitrate_, encode_speed_, - target_level_, VPX_RC_FIRST_PASS, impl_ptr_->encode_config_list); - impl_ptr_->cpi = init_encoder(&oxcf, impl_ptr_->img_fmt); - struct lookahead_ctx *lookahead = impl_ptr_->cpi->lookahead; - int i; - int use_highbitdepth = 0; - const int num_rows_16x16 = get_num_unit_16x16(frame_height_); - const int num_cols_16x16 = get_num_unit_16x16(frame_width_); -#if CONFIG_VP9_HIGHBITDEPTH - use_highbitdepth = impl_ptr_->cpi->common.use_highbitdepth; -#endif - vpx_image_t img; - vpx_img_alloc(&img, impl_ptr_->img_fmt, frame_width_, frame_height_, 1); - rewind(in_file_); - impl_ptr_->first_pass_stats.clear(); - for (i = 0; i < num_frames_; ++i) { - assert(!vp9_lookahead_full(lookahead)); - if (img_read(&img, in_file_)) { - int next_show_idx = vp9_lookahead_next_show_idx(lookahead); - int64_t ts_start = - timebase_units_to_ticks(&oxcf.g_timebase_in_ts, next_show_idx); - int64_t ts_end = - timebase_units_to_ticks(&oxcf.g_timebase_in_ts, next_show_idx + 1); - YV12_BUFFER_CONFIG sd; - image2yuvconfig(&img, &sd); - vp9_lookahead_push(lookahead, &sd, ts_start, ts_end, use_highbitdepth, 0); - { - int64_t time_stamp; - int64_t time_end; - int flush = 1; // Makes vp9_get_compressed_data process a frame - size_t size; - unsigned int frame_flags = 0; - ENCODE_FRAME_RESULT encode_frame_info; - vp9_init_encode_frame_result(&encode_frame_info); - // TODO(angiebird): Call vp9_first_pass directly - vp9_get_compressed_data(impl_ptr_->cpi, &frame_flags, &size, nullptr, - &time_stamp, &time_end, flush, - &encode_frame_info); - // vp9_get_compressed_data only generates first pass stats not - // compresses data - assert(size == 0); - // Get vp9 first pass motion vector info. - std::vector mv_info(num_rows_16x16 * num_cols_16x16); - update_motion_vector_info( - impl_ptr_->cpi->fp_motion_vector_info, num_rows_16x16, - num_cols_16x16, mv_info.data(), kMotionVectorFullPixelPrecision); - fp_motion_vector_info_.push_back(mv_info); - } - impl_ptr_->first_pass_stats.push_back( - vp9_get_frame_stats(&impl_ptr_->cpi->twopass)); - } - } - // TODO(angiebird): Store the total_stats apart form first_pass_stats - impl_ptr_->first_pass_stats.push_back( - vp9_get_total_stats(&impl_ptr_->cpi->twopass)); - vp9_end_first_pass(impl_ptr_->cpi); - - // Generate key_frame_map based on impl_ptr_->first_pass_stats. - key_frame_map_ = ComputeKeyFrameMap(); - - free_encoder(impl_ptr_->cpi); - impl_ptr_->cpi = nullptr; - rewind(in_file_); - vpx_img_free(&img); -} - -std::vector> SimpleEncode::ObserveFirstPassStats() { - std::vector> output_stats; - // TODO(angiebird): This function make several assumptions of - // FIRSTPASS_STATS. 1) All elements in FIRSTPASS_STATS are double except the - // last one. 2) The last entry of first_pass_stats is the total_stats. - // Change the code structure, so that we don't have to make these assumptions - - // Note the last entry of first_pass_stats is the total_stats, we don't need - // it. - for (size_t i = 0; i < impl_ptr_->first_pass_stats.size() - 1; ++i) { - double *buf_start = - reinterpret_cast(&impl_ptr_->first_pass_stats[i]); - // We use - 1 here because the last member in FIRSTPASS_STATS is not double - double *buf_end = - buf_start + sizeof(impl_ptr_->first_pass_stats[i]) / sizeof(*buf_end) - - 1; - std::vector this_stats(buf_start, buf_end); - output_stats.push_back(this_stats); - } - return output_stats; -} - -std::vector> -SimpleEncode::ObserveFirstPassMotionVectors() { - return fp_motion_vector_info_; -} - -void SimpleEncode::SetExternalGroupOfPicturesMap(int *gop_map, - int gop_map_size) { - for (int i = 0; i < gop_map_size; ++i) { - gop_map_.push_back(gop_map[i]); - } - // The following will check and modify gop_map_ to make sure the - // gop_map_ satisfies the constraints. - // 1) Each key frame position should be at the start of a gop. - // 2) The last gop should not use an alt ref. - assert(gop_map_.size() == key_frame_map_.size()); - int last_gop_start = 0; - for (int i = 0; static_cast(i) < gop_map_.size(); ++i) { - if (key_frame_map_[i] == 1 && gop_map_[i] == 0) { - fprintf(stderr, "Add an extra gop start at show_idx %d\n", i); - // Insert a gop start at key frame location. - gop_map_[i] |= kGopMapFlagStart; - gop_map_[i] |= kGopMapFlagUseAltRef; - } - if (gop_map_[i] & kGopMapFlagStart) { - last_gop_start = i; - } - } - if (gop_map_[last_gop_start] & kGopMapFlagUseAltRef) { - fprintf(stderr, - "Last group of pictures starting at show_idx %d shouldn't use alt " - "ref\n", - last_gop_start); - gop_map_[last_gop_start] &= ~kGopMapFlagUseAltRef; - } -} - -std::vector SimpleEncode::ObserveExternalGroupOfPicturesMap() { - return gop_map_; -} - -template -T *GetVectorData(const std::vector &v) { - if (v.empty()) { - return nullptr; - } - return const_cast(v.data()); -} - -static GOP_COMMAND GetGopCommand(const std::vector &gop_map, - int start_show_index) { - GOP_COMMAND gop_command; - if (static_cast(start_show_index) < gop_map.size()) { - assert((gop_map[start_show_index] & kGopMapFlagStart) != 0); - int end_show_index = start_show_index + 1; - // gop_map[end_show_index] & kGopMapFlagStart == 0 means this is - // the start of a gop. - while (static_cast(end_show_index) < gop_map.size() && - (gop_map[end_show_index] & kGopMapFlagStart) == 0) { - ++end_show_index; - } - const int show_frame_count = end_show_index - start_show_index; - int use_alt_ref = (gop_map[start_show_index] & kGopMapFlagUseAltRef) != 0; - if (static_cast(end_show_index) == gop_map.size()) { - // This is the last gop group, there must be no altref. - use_alt_ref = 0; - } - gop_command_on(&gop_command, show_frame_count, use_alt_ref); - } else { - gop_command_off(&gop_command); - } - return gop_command; -} - -void SimpleEncode::StartEncode() { - assert(impl_ptr_->first_pass_stats.size() > 0); - vpx_rational_t frame_rate = - make_vpx_rational(frame_rate_num_, frame_rate_den_); - VP9EncoderConfig oxcf = GetEncodeConfig( - frame_width_, frame_height_, frame_rate, target_bitrate_, encode_speed_, - target_level_, VPX_RC_LAST_PASS, impl_ptr_->encode_config_list); - - vpx_fixed_buf_t stats; - stats.buf = GetVectorData(impl_ptr_->first_pass_stats); - stats.sz = sizeof(impl_ptr_->first_pass_stats[0]) * - impl_ptr_->first_pass_stats.size(); - - vp9_set_first_pass_stats(&oxcf, &stats); - assert(impl_ptr_->cpi == nullptr); - impl_ptr_->cpi = init_encoder(&oxcf, impl_ptr_->img_fmt); - vpx_img_alloc(&impl_ptr_->tmp_img, impl_ptr_->img_fmt, frame_width_, - frame_height_, 1); - - frame_coding_index_ = 0; - show_frame_count_ = 0; - - assert(impl_ptr_->cpi != nullptr); - FRAME_INFO frame_info = vp9_get_frame_info(&oxcf); - unsigned int screen_area = frame_info.frame_width * frame_info.frame_height; - vp9_init_vizier_params(&impl_ptr_->cpi->twopass, screen_area); - - UpdateKeyFrameGroup(show_frame_count_); - - const GOP_COMMAND gop_command = GetGopCommand(gop_map_, show_frame_count_); - encode_command_set_gop_command(&impl_ptr_->cpi->encode_command, gop_command); - UpdateGroupOfPicture(impl_ptr_->cpi, frame_coding_index_, ref_frame_info_, - &group_of_picture_); - rewind(in_file_); - - if (out_file_ != nullptr) { - const char *fourcc = "VP90"; - // In SimpleEncode, we use time_base = 1 / TICKS_PER_SEC. - // Based on that, the ivf_timestamp for each image is set to - // show_idx * TICKS_PER_SEC / frame_rate - // such that each image's actual timestamp in seconds can be computed as - // ivf_timestamp * time_base == show_idx / frame_rate - // TODO(angiebird): 1) Add unit test for ivf timestamp. - // 2) Simplify the frame_rate setting process. - vpx_rational_t time_base = make_vpx_rational(1, TICKS_PER_SEC); - ivf_write_file_header_with_video_info(out_file_, *(const uint32_t *)fourcc, - num_frames_, frame_width_, - frame_height_, time_base); - } -} - -void SimpleEncode::EndEncode() { - free_encoder(impl_ptr_->cpi); - impl_ptr_->cpi = nullptr; - vpx_img_free(&impl_ptr_->tmp_img); - rewind(in_file_); -} - -void SimpleEncode::UpdateKeyFrameGroup(int key_frame_show_index) { - const VP9_COMP *cpi = impl_ptr_->cpi; - key_frame_group_index_ = 0; - key_frame_group_size_ = vp9_get_frames_to_next_key( - &cpi->oxcf, &cpi->twopass, key_frame_show_index, cpi->rc.min_gf_interval); - assert(key_frame_group_size_ > 0); - // Init the reference frame info when a new key frame group appears. - InitRefFrameInfo(&ref_frame_info_); -} - -void SimpleEncode::PostUpdateKeyFrameGroupIndex(FrameType frame_type) { - if (frame_type != kFrameTypeAltRef) { - // key_frame_group_index_ only counts show frames - ++key_frame_group_index_; - } -} - -int SimpleEncode::GetKeyFrameGroupSize() const { return key_frame_group_size_; } - -GroupOfPicture SimpleEncode::ObserveGroupOfPicture() const { - return group_of_picture_; -} - -EncodeFrameInfo SimpleEncode::GetNextEncodeFrameInfo() const { - return group_of_picture_ - .encode_frame_list[group_of_picture_.next_encode_frame_index]; -} - -void SimpleEncode::PostUpdateState( - const EncodeFrameResult &encode_frame_result) { - // This function needs to be called before the increament of - // frame_coding_index_ - PostUpdateRefFrameInfo(encode_frame_result.frame_type, frame_coding_index_, - &ref_frame_info_); - ++frame_coding_index_; - if (encode_frame_result.frame_type != kFrameTypeAltRef) { - // Only kFrameTypeAltRef is not a show frame - ++show_frame_count_; - } - - PostUpdateKeyFrameGroupIndex(encode_frame_result.frame_type); - if (key_frame_group_index_ == key_frame_group_size_) { - UpdateKeyFrameGroup(show_frame_count_); - } - - IncreaseGroupOfPictureIndex(&group_of_picture_); - if (IsGroupOfPictureFinished(group_of_picture_)) { - const GOP_COMMAND gop_command = GetGopCommand(gop_map_, show_frame_count_); - encode_command_set_gop_command(&impl_ptr_->cpi->encode_command, - gop_command); - // This function needs to be called after ref_frame_info_ is updated - // properly in PostUpdateRefFrameInfo() and UpdateKeyFrameGroup(). - UpdateGroupOfPicture(impl_ptr_->cpi, frame_coding_index_, ref_frame_info_, - &group_of_picture_); - } -} - -void SimpleEncode::EncodeFrame(EncodeFrameResult *encode_frame_result) { - VP9_COMP *cpi = impl_ptr_->cpi; - struct lookahead_ctx *lookahead = cpi->lookahead; - int use_highbitdepth = 0; -#if CONFIG_VP9_HIGHBITDEPTH - use_highbitdepth = cpi->common.use_highbitdepth; -#endif - // The lookahead's size is set to oxcf->lag_in_frames. - // We want to fill lookahead to it's max capacity if possible so that the - // encoder can construct alt ref frame in time. - // In the other words, we hope vp9_get_compressed_data to encode a frame - // every time in the function - while (!vp9_lookahead_full(lookahead)) { - // TODO(angiebird): Check whether we can move this file read logics to - // lookahead - if (img_read(&impl_ptr_->tmp_img, in_file_)) { - int next_show_idx = vp9_lookahead_next_show_idx(lookahead); - int64_t ts_start = - timebase_units_to_ticks(&cpi->oxcf.g_timebase_in_ts, next_show_idx); - int64_t ts_end = timebase_units_to_ticks(&cpi->oxcf.g_timebase_in_ts, - next_show_idx + 1); - YV12_BUFFER_CONFIG sd; - image2yuvconfig(&impl_ptr_->tmp_img, &sd); - vp9_lookahead_push(lookahead, &sd, ts_start, ts_end, use_highbitdepth, 0); - } else { - break; - } - } - - if (init_encode_frame_result(encode_frame_result, frame_width_, frame_height_, - impl_ptr_->img_fmt)) { - int64_t time_stamp; - int64_t time_end; - int flush = 1; // Make vp9_get_compressed_data encode a frame - unsigned int frame_flags = 0; - ENCODE_FRAME_RESULT encode_frame_info; - vp9_init_encode_frame_result(&encode_frame_info); - ImageBuffer_to_IMAGE_BUFFER(encode_frame_result->coded_frame, - &encode_frame_info.coded_frame); - vp9_get_compressed_data(cpi, &frame_flags, - &encode_frame_result->coding_data_byte_size, - encode_frame_result->coding_data.get(), &time_stamp, - &time_end, flush, &encode_frame_info); - if (out_file_ != nullptr) { - ivf_write_frame_header(out_file_, time_stamp, - encode_frame_result->coding_data_byte_size); - fwrite(encode_frame_result->coding_data.get(), 1, - encode_frame_result->coding_data_byte_size, out_file_); - } - - // vp9_get_compressed_data is expected to encode a frame every time, so the - // data size should be greater than zero. - if (encode_frame_result->coding_data_byte_size <= 0) { - fprintf(stderr, "Coding data size <= 0\n"); - abort(); - } - const size_t max_coding_data_byte_size = - get_max_coding_data_byte_size(frame_width_, frame_height_); - if (encode_frame_result->coding_data_byte_size > - max_coding_data_byte_size) { - fprintf(stderr, "Coding data size exceeds the maximum.\n"); - abort(); - } - - const GroupOfPicture group_of_picture = this->ObserveGroupOfPicture(); - const int show_frame_count = group_of_picture.show_frame_count; - update_encode_frame_result(encode_frame_result, show_frame_count, - &encode_frame_info); - PostUpdateState(*encode_frame_result); - } else { - // TODO(angiebird): Clean up encode_frame_result. - fprintf(stderr, "init_encode_frame_result() failed.\n"); - this->EndEncode(); - } -} - -void SimpleEncode::EncodeFrameWithQuantizeIndex( - EncodeFrameResult *encode_frame_result, int quantize_index) { - encode_command_set_external_quantize_index(&impl_ptr_->cpi->encode_command, - quantize_index); - EncodeFrame(encode_frame_result); - encode_command_reset_external_quantize_index(&impl_ptr_->cpi->encode_command); -} - -void SimpleEncode::EncodeFrameWithTargetFrameBits( - EncodeFrameResult *encode_frame_result, int target_frame_bits, - double percent_diff) { - encode_command_set_target_frame_bits(&impl_ptr_->cpi->encode_command, - target_frame_bits, percent_diff); - EncodeFrame(encode_frame_result); - encode_command_reset_target_frame_bits(&impl_ptr_->cpi->encode_command); -} - -static int GetCodingFrameNumFromGopMap(const std::vector &gop_map) { - int start_show_index = 0; - int coding_frame_count = 0; - while (static_cast(start_show_index) < gop_map.size()) { - const GOP_COMMAND gop_command = GetGopCommand(gop_map, start_show_index); - start_show_index += gop_command.show_frame_count; - coding_frame_count += gop_command_coding_frame_count(&gop_command); - } - assert(static_cast(start_show_index) == gop_map.size()); - return coding_frame_count; -} - -int SimpleEncode::GetCodingFrameNum() const { - assert(impl_ptr_->first_pass_stats.size() > 0); - if (gop_map_.size() > 0) { - return GetCodingFrameNumFromGopMap(gop_map_); - } - - // These are the default settings for now. - TWO_PASS twopass; - const int multi_layer_arf = 0; - const int allow_alt_ref = 1; - vpx_rational_t frame_rate = - make_vpx_rational(frame_rate_num_, frame_rate_den_); - const VP9EncoderConfig oxcf = GetEncodeConfig( - frame_width_, frame_height_, frame_rate, target_bitrate_, encode_speed_, - target_level_, VPX_RC_LAST_PASS, impl_ptr_->encode_config_list); - FRAME_INFO frame_info = vp9_get_frame_info(&oxcf); - fps_init_first_pass_info(&twopass.first_pass_info, - GetVectorData(impl_ptr_->first_pass_stats), - num_frames_); - unsigned int screen_area = frame_info.frame_width * frame_info.frame_height; - vp9_init_vizier_params(&twopass, screen_area); - return vp9_get_coding_frame_num(&oxcf, &twopass, &frame_info, multi_layer_arf, - allow_alt_ref); -} - -std::vector SimpleEncode::ComputeKeyFrameMap() const { - // The last entry of first_pass_stats is the overall stats. - assert(impl_ptr_->first_pass_stats.size() == - static_cast(num_frames_) + 1); - vpx_rational_t frame_rate = - make_vpx_rational(frame_rate_num_, frame_rate_den_); - const VP9EncoderConfig oxcf = GetEncodeConfig( - frame_width_, frame_height_, frame_rate, target_bitrate_, encode_speed_, - target_level_, VPX_RC_LAST_PASS, impl_ptr_->encode_config_list); - TWO_PASS twopass; - fps_init_first_pass_info(&twopass.first_pass_info, - GetVectorData(impl_ptr_->first_pass_stats), - num_frames_); - std::vector key_frame_map(num_frames_, 0); - vp9_get_key_frame_map(&oxcf, &twopass, GetVectorData(key_frame_map)); - return key_frame_map; -} - -std::vector SimpleEncode::ObserveKeyFrameMap() const { - return key_frame_map_; -} - -uint64_t SimpleEncode::GetFramePixelCount() const { - assert(frame_width_ % 2 == 0); - assert(frame_height_ % 2 == 0); - switch (impl_ptr_->img_fmt) { - case VPX_IMG_FMT_I420: return frame_width_ * frame_height_ * 3 / 2; - case VPX_IMG_FMT_I422: return frame_width_ * frame_height_ * 2; - case VPX_IMG_FMT_I444: return frame_width_ * frame_height_ * 3; - case VPX_IMG_FMT_I440: return frame_width_ * frame_height_ * 2; - case VPX_IMG_FMT_I42016: return frame_width_ * frame_height_ * 3 / 2; - case VPX_IMG_FMT_I42216: return frame_width_ * frame_height_ * 2; - case VPX_IMG_FMT_I44416: return frame_width_ * frame_height_ * 3; - case VPX_IMG_FMT_I44016: return frame_width_ * frame_height_ * 2; - default: return 0; - } -} - -SimpleEncode::~SimpleEncode() { - if (in_file_ != nullptr) { - fclose(in_file_); - } - if (out_file_ != nullptr) { - fclose(out_file_); - } -} - -} // namespace vp9 diff --git a/libs/libvpx/vp9/simple_encode.h b/libs/libvpx/vp9/simple_encode.h deleted file mode 100644 index 7920e95ee9..0000000000 --- a/libs/libvpx/vp9/simple_encode.h +++ /dev/null @@ -1,583 +0,0 @@ -/* - * Copyright (c) 2019 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef VPX_VP9_SIMPLE_ENCODE_H_ -#define VPX_VP9_SIMPLE_ENCODE_H_ - -#include -#include -#include -#include -#include - -namespace vp9 { - -enum StatusCode { - StatusOk = 0, - StatusError, -}; - -// TODO(angiebird): Add description for each frame type. -enum FrameType { - kFrameTypeKey = 0, - kFrameTypeInter = 1, - kFrameTypeAltRef = 2, - kFrameTypeOverlay = 3, - kFrameTypeGolden = 4, -}; - -// TODO(angiebird): Add description for each reference frame type. -// This enum numbers have to be contiguous and start from zero except -// kNoneRefFrame. -enum RefFrameType { - kRefFrameTypeLast = 0, - kRefFrameTypePast = 1, - kRefFrameTypeFuture = 2, - kRefFrameTypeMax = 3, - kRefFrameTypeNone = -1, -}; - -enum VP9_LEVEL { - LEVEL_UNKNOWN = 0, - LEVEL_AUTO = 1, - LEVEL_1 = 10, - LEVEL_1_1 = 11, - LEVEL_2 = 20, - LEVEL_2_1 = 21, - LEVEL_3 = 30, - LEVEL_3_1 = 31, - LEVEL_4 = 40, - LEVEL_4_1 = 41, - LEVEL_5 = 50, - LEVEL_5_1 = 51, - LEVEL_5_2 = 52, - LEVEL_6 = 60, - LEVEL_6_1 = 61, - LEVEL_6_2 = 62, - LEVEL_MAX = 255 -}; - -enum GopMapFlag { - kGopMapFlagStart = - 1 << 0, // Indicate this location is the start of a group of pictures. - kGopMapFlagUseAltRef = - 1 << 1, // Indicate this group of pictures will use an alt ref. Only set - // this flag when kGopMapFlagStart is set. -}; - -// The frame is split to 4x4 blocks. -// This structure contains the information of each 4x4 block. -struct PartitionInfo { - int row; // row pixel offset of current 4x4 block - int column; // column pixel offset of current 4x4 block - int row_start; // row pixel offset of the start of the prediction block - int column_start; // column pixel offset of the start of the prediction block - int width; // prediction block width - int height; // prediction block height -}; - -constexpr int kMotionVectorSubPixelPrecision = 8; -constexpr int kMotionVectorFullPixelPrecision = 1; - -// In the first pass. The frame is split to 16x16 blocks. -// This structure contains the information of each 16x16 block. -// In the second pass. The frame is split to 4x4 blocks. -// This structure contains the information of each 4x4 block. -struct MotionVectorInfo { - // Number of valid motion vectors, always 0 if this block is in the key frame. - // For inter frames, it could be 1 or 2. - int mv_count; - // The reference frame for motion vectors. If the second motion vector does - // not exist (mv_count = 1), the reference frame is kNoneRefFrame. - // Otherwise, the reference frame is either kRefFrameTypeLast, or - // kRefFrameTypePast, or kRefFrameTypeFuture. - RefFrameType ref_frame[2]; - // The row offset of motion vectors in the unit of pixel. - // If the second motion vector does not exist, the value is 0. - double mv_row[2]; - // The column offset of motion vectors in the unit of pixel. - // If the second motion vector does not exist, the value is 0. - double mv_column[2]; -}; - -// Accumulated tpl stats of all blocks in one frame. -// For each frame, the tpl stats are computed per 32x32 block. -struct TplStatsInfo { - // Intra complexity: the sum of absolute transform difference (SATD) of - // intra predicted residuals. - int64_t intra_cost; - // Inter complexity: the SATD of inter predicted residuals. - int64_t inter_cost; - // Motion compensated information flow. It measures how much information - // is propagated from the current frame to other frames. - int64_t mc_flow; - // Motion compensated dependency cost. It equals to its own intra_cost - // plus the mc_flow. - int64_t mc_dep_cost; - // Motion compensated reference cost. - int64_t mc_ref_cost; -}; - -struct RefFrameInfo { - int coding_indexes[kRefFrameTypeMax]; - - // Indicate whether the reference frames are available or not. - // When the reference frame type is not valid, it means either the to-be-coded - // frame is a key frame or the reference frame already appears in other - // reference frame type. vp9 always keeps three types of reference frame - // available. However, the duplicated reference frames will not be - // chosen by the encoder. The priorities of choosing reference frames are - // kRefFrameTypeLast > kRefFrameTypePast > kRefFrameTypeFuture. - // For example, if kRefFrameTypeLast and kRefFrameTypePast both point to the - // same frame, kRefFrameTypePast will be set to invalid. - // 1: the ref frame type is available 0: the ref frame type is not available - int valid_list[kRefFrameTypeMax]; -}; - -bool operator==(const RefFrameInfo &a, const RefFrameInfo &b); - -struct EncodeFrameInfo { - int show_idx; - - // Each show or no show frame is assigned with a coding index based on its - // coding order (starting from zero) in the coding process of the entire - // video. The coding index for each frame is unique. - int coding_index; - RefFrameInfo ref_frame_info; - FrameType frame_type; -}; - -// This structure is a copy of vp9 |nmv_component_counts|. -struct NewMotionvectorComponentCounts { - std::vector sign; - std::vector classes; - std::vector class0; - std::vector> bits; - std::vector> class0_fp; - std::vector fp; - std::vector class0_hp; - std::vector hp; -}; - -// This structure is a copy of vp9 |nmv_context_counts|. -struct NewMotionVectorContextCounts { - std::vector joints; - std::vector comps; -}; - -using UintArray2D = std::vector>; -using UintArray3D = std::vector>>; -using UintArray5D = std::vector< - std::vector>>>>; -using UintArray6D = std::vector>>>>>; - -// This structure is a copy of vp9 |tx_counts|. -struct TransformSizeCounts { - // Transform size found in blocks of partition size 32x32. - // First dimension: transform size contexts (2). - // Second dimension: transform size type (3: 32x32, 16x16, 8x8) - UintArray2D p32x32; - // Transform size found in blocks of partition size 16x16. - // First dimension: transform size contexts (2). - // Second dimension: transform size type (2: 16x16, 8x8) - UintArray2D p16x16; - // Transform size found in blocks of partition size 8x8. - // First dimension: transform size contexts (2). - // Second dimension: transform size type (1: 8x8) - UintArray2D p8x8; - // Overall transform size count. - std::vector tx_totals; -}; - -// This structure is a copy of vp9 |FRAME_COUNTS|. -struct FrameCounts { - // Intra prediction mode for luma plane. First dimension: block size (4). - // Second dimension: intra prediction mode (10). - UintArray2D y_mode; - // Intra prediction mode for chroma plane. First and second dimension: - // intra prediction mode (10). - UintArray2D uv_mode; - // Partition type. First dimension: partition contexts (16). - // Second dimension: partition type (4). - UintArray2D partition; - // Transform coefficient. - UintArray6D coef; - // End of block (the position of the last non-zero transform coefficient) - UintArray5D eob_branch; - // Interpolation filter type. First dimension: switchable filter contexts (4). - // Second dimension: filter types (3). - UintArray2D switchable_interp; - // Inter prediction mode (the motion vector type). - // First dimension: inter mode contexts (7). - // Second dimension: mode type (4). - UintArray2D inter_mode; - // Block is intra or inter predicted. First dimension: contexts (4). - // Second dimension: type (0 for intra, 1 for inter). - UintArray2D intra_inter; - // Block is compound predicted (predicted from average of two blocks). - // First dimension: contexts (5). - // Second dimension: type (0 for single, 1 for compound prediction). - UintArray2D comp_inter; - // Type of the reference frame. Only one reference frame. - // First dimension: context (5). Second dimension: context (2). - // Third dimension: count (2). - UintArray3D single_ref; - // Type of the two reference frames. - // First dimension: context (5). Second dimension: count (2). - UintArray2D comp_ref; - // Block skips transform and quantization, uses prediction as reconstruction. - // First dimension: contexts (3). Second dimension: type (0 not skip, 1 skip). - UintArray2D skip; - // Transform size. - TransformSizeCounts tx; - // New motion vector. - NewMotionVectorContextCounts mv; -}; - -struct ImageBuffer { - // The image data is stored in raster order, - // i.e. image[plane][r][c] = - // plane_buffer[plane][r * plane_width[plane] + plane_height[plane]]. - std::unique_ptr plane_buffer[3]; - int plane_width[3]; - int plane_height[3]; -}; - -void output_image_buffer(const ImageBuffer &image_buffer, std::FILE *out_file); - -struct EncodeFrameResult { - int show_idx; - FrameType frame_type; - int coding_idx; - RefFrameInfo ref_frame_info; - size_t coding_data_bit_size; - size_t coding_data_byte_size; - // The EncodeFrame will allocate a buffer, write the coding data into the - // buffer and give the ownership of the buffer to coding_data. - std::unique_ptr coding_data; - double psnr; - uint64_t sse; - int quantize_index; - FrameCounts frame_counts; - int num_rows_4x4; // number of row units, in size of 4. - int num_cols_4x4; // number of column units, in size of 4. - // A vector of the partition information of the frame. - // The number of elements is |num_rows_4x4| * |num_cols_4x4|. - // The frame is divided 4x4 blocks of |num_rows_4x4| rows and - // |num_cols_4x4| columns. - // Each 4x4 block contains the current pixel position (|row|, |column|), - // the start pixel position of the partition (|row_start|, |column_start|), - // and the |width|, |height| of the partition. - // The current pixel position can be the same as the start pixel position - // if the 4x4 block is the top-left block in the partition. Otherwise, they - // are different. - // Within the same partition, all 4x4 blocks have the same |row_start|, - // |column_start|, |width| and |height|. - // For example, if the frame is partitioned to a 32x32 block, - // starting at (0, 0). Then, there're 64 4x4 blocks within this partition. - // They all have the same |row_start|, |column_start|, |width|, |height|, - // which can be used to figure out the start of the current partition and - // the start of the next partition block. - // Horizontal next: |column_start| + |width|, - // Vertical next: |row_start| + |height|. - std::vector partition_info; - // A vector of the motion vector information of the frame. - // The number of elements is |num_rows_4x4| * |num_cols_4x4|. - // The frame is divided into 4x4 blocks of |num_rows_4x4| rows and - // |num_cols_4x4| columns. - // Each 4x4 block contains 0 motion vector if this is an intra predicted - // frame (for example, the key frame). If the frame is inter predicted, - // each 4x4 block contains either 1 or 2 motion vectors. - // Similar to partition info, all 4x4 blocks inside the same partition block - // share the same motion vector information. - std::vector motion_vector_info; - // A vector of the tpl stats information. - // The tpl stats measure the complexity of a frame, as well as the - // information propagated along the motion trajectory between frames, in - // the reference frame structure. - // The tpl stats could be used as a more accurate spatial and temporal - // complexity measure in addition to the first pass stats. - // The vector contains tpl stats for all show frames in a GOP. - // The tpl stats stored in the vector is according to the encoding order. - // For example, suppose there are N show frames for the current GOP. - // Then tpl_stats_info[0] stores the information of the first frame to be - // encoded for this GOP, i.e, the AltRef frame. - std::vector tpl_stats_info; - ImageBuffer coded_frame; - - // recode_count, q_index_history and rate_history are only available when - // EncodeFrameWithTargetFrameBits() is used. - int recode_count; - std::vector q_index_history; - std::vector rate_history; -}; - -struct GroupOfPicture { - // This list will be updated internally in StartEncode() and - // EncodeFrame()/EncodeFrameWithQuantizeIndex(). - // In EncodeFrame()/EncodeFrameWithQuantizeIndex(), the update will only be - // triggered when the coded frame is the last one in the previous group of - // pictures. - std::vector encode_frame_list; - - // Indicates the index of the next coding frame in encode_frame_list. - // In other words, EncodeFrameInfo of the next coding frame can be - // obtained with encode_frame_list[next_encode_frame_index]. - // Internally, next_encode_frame_index will be set to zero after the last - // frame of the group of pictures is coded. Otherwise, next_encode_frame_index - // will be increased after each EncodeFrame()/EncodeFrameWithQuantizeIndex() - // call. - int next_encode_frame_index; - - // Number of show frames in this group of pictures. - int show_frame_count; - - // The show index/timestamp of the earliest show frame in the group of - // pictures. - int start_show_index; - - // The coding index of the first coding frame in the group of pictures. - int start_coding_index; - - // Indicates whether this group of pictures starts with a key frame. - int first_is_key_frame; - - // Indicates whether this group of pictures uses an alt ref. - int use_alt_ref; - - // Indicates whether previous group of pictures used an alt ref. - int last_gop_use_alt_ref; -}; - -class SimpleEncode { - public: - // When outfile_path is set, the encoder will output the bitstream in ivf - // format. - SimpleEncode(int frame_width, int frame_height, int frame_rate_num, - int frame_rate_den, int target_bitrate, int num_frames, - int target_level, const char *infile_path, - const char *outfile_path = nullptr); - ~SimpleEncode(); - SimpleEncode(SimpleEncode &) = delete; - SimpleEncode &operator=(const SimpleEncode &) = delete; - - // Adjusts the encoder's coding speed. - // If this function is not called, the encoder will use default encode_speed - // 0. Call this function before ComputeFirstPassStats() if needed. - // The encode_speed is equivalent to --cpu-used of the vpxenc command. - // The encode_speed's range should be [0, 9]. - // Setting the encode_speed to a higher level will yield faster coding - // at the cost of lower compression efficiency. - void SetEncodeSpeed(int encode_speed); - - // Set encoder config - // The following configs in VP9EncoderConfig are allowed to change in this - // function. See https://ffmpeg.org/ffmpeg-codecs.html#libvpx for each - // config's meaning. - // Configs in VP9EncoderConfig: Equivalent configs in ffmpeg: - // 1 key_freq -g - // 2 two_pass_vbrmin_section -minrate * 100LL / bit_rate - // 3 two_pass_vbrmax_section -maxrate * 100LL / bit_rate - // 4 under_shoot_pct -undershoot-pct - // 5 over_shoot_pct -overshoot-pct - // 6 max_threads -threads - // 7 frame_parallel_decoding_mode -frame-parallel - // 8 tile_column -tile-columns - // 9 arnr_max_frames -arnr-maxframes - // 10 arnr_strength -arnr-strength - // 11 lag_in_frames -rc_lookahead - // 12 encode_breakout -static-thresh - // 13 enable_tpl_model -enable-tpl - // 14 enable_auto_arf -auto-alt-ref - // 15 rc_mode - // Possible Settings: - // 0 - Variable Bit Rate (VPX_VBR) -b:v - // 1 - Constant Bit Rate (VPX_CBR) -b:v -minrate - // -maxrate - // two_pass_vbrmin_section == 100 i.e. bit_rate == minrate == maxrate - // two_pass_vbrmax_section == 100 - // 2 - Constrained Quality (VPX_CQ) -crf -b:v bit_rate - // 3 - Constant Quality (VPX_Q) -crf -b:v 0 - // See https://trac.ffmpeg.org/wiki/Encode/VP9 for more details. - // 16 cq_level see rc_mode for details. - StatusCode SetEncodeConfig(const char *name, const char *value); - - // A debug function that dumps configs from VP9EncoderConfig - // pass = 1: first pass, pass = 2: second pass - // fp: file pointer for dumping config - StatusCode DumpEncodeConfigs(int pass, FILE *fp); - - // Makes encoder compute the first pass stats and store it at - // impl_ptr_->first_pass_stats. key_frame_map_ is also computed based on the - // first pass stats. - void ComputeFirstPassStats(); - - // Outputs the first pass stats represented by a 2-D vector. - // One can use the frame index at first dimension to retrieve the stats for - // each video frame. The stats of each video frame is a vector of 25 double - // values. For details, please check FIRSTPASS_STATS in vp9_firstpass.h - std::vector> ObserveFirstPassStats(); - - // Outputs the first pass motion vectors represented by a 2-D vector. - // One can use the frame index at first dimension to retrieve the mvs for - // each video frame. The frame is divided into 16x16 blocks. The number of - // elements is round_up(|num_rows_4x4| / 4) * round_up(|num_cols_4x4| / 4). - std::vector> ObserveFirstPassMotionVectors(); - - // Ouputs a copy of key_frame_map_, a binary vector with size equal to the - // number of show frames in the video. For each entry in the vector, 1 - // indicates the position is a key frame and 0 indicates it's not a key frame. - // This function should be called after ComputeFirstPassStats() - std::vector ObserveKeyFrameMap() const; - - // Sets group of pictures map for coding the entire video. - // Each entry in the gop_map corresponds to a show frame in the video. - // Therefore, the size of gop_map should equal to the number of show frames in - // the entire video. - // If a given entry's kGopMapFlagStart is set, it means this is the start of a - // gop. Once kGopMapFlagStart is set, one can set kGopMapFlagUseAltRef to - // indicate whether this gop use altref. - // If a given entry is zero, it means it's in the middle of a gop. - // This function should be called only once after ComputeFirstPassStats(), - // before StartEncode(). - // This API will check and modify the gop_map to satisfy the following - // constraints. - // 1) Each key frame position should be at the start of a gop. - // 2) The last gop should not use an alt ref. - void SetExternalGroupOfPicturesMap(int *gop_map, int gop_map_size); - - // Observe the group of pictures map set through - // SetExternalGroupOfPicturesMap(). This function should be called after - // SetExternalGroupOfPicturesMap(). - std::vector ObserveExternalGroupOfPicturesMap(); - - // Initializes the encoder for actual encoding. - // This function should be called after ComputeFirstPassStats(). - void StartEncode(); - - // Frees the encoder. - // This function should be called after StartEncode() or EncodeFrame(). - void EndEncode(); - - // The key frame group size includes one key frame plus the number of - // following inter frames. Note that the key frame group size only counts the - // show frames. The number of no show frames like alternate refereces are not - // counted. - int GetKeyFrameGroupSize() const; - - // Provides the group of pictures that the next coding frame is in. - // Only call this function between StartEncode() and EndEncode() - GroupOfPicture ObserveGroupOfPicture() const; - - // Gets encode_frame_info for the next coding frame. - // Only call this function between StartEncode() and EndEncode() - EncodeFrameInfo GetNextEncodeFrameInfo() const; - - // Encodes a frame - // This function should be called after StartEncode() and before EndEncode(). - void EncodeFrame(EncodeFrameResult *encode_frame_result); - - // Encodes a frame with a specific quantize index. - // This function should be called after StartEncode() and before EndEncode(). - void EncodeFrameWithQuantizeIndex(EncodeFrameResult *encode_frame_result, - int quantize_index); - - // Encode a frame with target frame bits usage. - // The encoder will find a quantize index to make the actual frame bits usage - // match the target. EncodeFrameWithTargetFrameBits() will recode the frame - // up to 7 times to find a q_index to make the actual_frame_bits satisfy the - // following inequality. |actual_frame_bits - target_frame_bits| * 100 / - // target_frame_bits - // <= percent_diff. - void EncodeFrameWithTargetFrameBits(EncodeFrameResult *encode_frame_result, - int target_frame_bits, - double percent_diff); - - // Gets the number of coding frames for the video. The coding frames include - // show frame and no show frame. - // This function should be called after ComputeFirstPassStats(). - int GetCodingFrameNum() const; - - // Gets the total number of pixels of YUV planes per frame. - uint64_t GetFramePixelCount() const; - - private: - // Compute the key frame locations of the video based on first pass stats. - // The results are returned as a binary vector with 1s indicating keyframes - // and 0s indicating non keyframes. - // It has to be called after impl_ptr_->first_pass_stats is computed. - std::vector ComputeKeyFrameMap() const; - - // Updates key_frame_group_size_, reset key_frame_group_index_ and init - // ref_frame_info_. - void UpdateKeyFrameGroup(int key_frame_show_index); - - // Update key_frame_group_index_. - void PostUpdateKeyFrameGroupIndex(FrameType frame_type); - - void PostUpdateState(const EncodeFrameResult &encode_frame_result); - - class EncodeImpl; - - int frame_width_; // frame width in pixels. - int frame_height_; // frame height in pixels. - int frame_rate_num_; - int frame_rate_den_; - int target_bitrate_; - int num_frames_; - int encode_speed_; - int target_level_; - - std::FILE *in_file_; - std::FILE *out_file_; - std::unique_ptr impl_ptr_; - - std::vector key_frame_map_; - std::vector gop_map_; - GroupOfPicture group_of_picture_; - - // The key frame group size includes one key frame plus the number of - // following inter frames. Note that the key frame group size only counts the - // show frames. The number of no show frames like alternate references are not - // counted. - int key_frame_group_size_; - - // The index for the to-be-coded show frame in the key frame group. - int key_frame_group_index_; - - // Each show or no show frame is assigned with a coding index based on its - // coding order (starting from zero) in the coding process of the entire - // video. The coding index of the to-be-coded frame. - int frame_coding_index_; - - // Number of show frames we have coded so far. - int show_frame_count_; - - // TODO(angiebird): Do we need to reset ref_frames_info_ when the next key - // frame appears? - // Reference frames info of the to-be-coded frame. - RefFrameInfo ref_frame_info_; - - // A 2-D vector of motion vector information of the frame collected - // from the first pass. The first dimension is the frame index. - // Each frame is divided into 16x16 blocks. The number of elements is - // round_up(|num_rows_4x4| / 4) * round_up(|num_cols_4x4| / 4). - // Each 16x16 block contains 0 motion vector if this is an intra predicted - // frame (for example, the key frame). If the frame is inter predicted, - // each 16x16 block contains either 1 or 2 motion vectors. - // The first motion vector is always from the LAST_FRAME. - // The second motion vector is always from the GOLDEN_FRAME. - std::vector> fp_motion_vector_info_; -}; - -} // namespace vp9 - -#endif // VPX_VP9_SIMPLE_ENCODE_H_ diff --git a/libs/libvpx/vp9/vp9_common.mk b/libs/libvpx/vp9/vp9_common.mk index 5ef2f891a8..77345238df 100644 --- a/libs/libvpx/vp9/vp9_common.mk +++ b/libs/libvpx/vp9/vp9_common.mk @@ -80,8 +80,10 @@ VP9_COMMON_SRCS-$(HAVE_NEON) += common/arm/neon/vp9_iht_neon.h ifeq ($(CONFIG_VP9_POSTPROC),yes) VP9_COMMON_SRCS-$(HAVE_MSA) += common/mips/msa/vp9_mfqe_msa.c +ifeq ($(HAVE_X86_ASM),yes) VP9_COMMON_SRCS-$(HAVE_SSE2) += common/x86/vp9_mfqe_sse2.asm endif +endif ifneq ($(CONFIG_VP9_HIGHBITDEPTH),yes) VP9_COMMON_SRCS-$(HAVE_DSPR2) += common/mips/dspr2/vp9_itrans4_dspr2.c diff --git a/libs/libvpx/vp9/vp9_cx_iface.c b/libs/libvpx/vp9/vp9_cx_iface.c index 05ac9e1691..bbd3ef3456 100644 --- a/libs/libvpx/vp9/vp9_cx_iface.c +++ b/libs/libvpx/vp9/vp9_cx_iface.c @@ -8,27 +8,39 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include +#include +#include +#include +#include #include #include #include "./vpx_config.h" #include "vpx/vpx_encoder.h" +#include "vpx/vpx_image.h" #include "vpx/vpx_ext_ratectrl.h" #include "vpx_dsp/psnr.h" +#include "vpx_dsp/vpx_dsp_common.h" #include "vpx_ports/static_assert.h" #include "vpx_ports/system_state.h" +#include "vpx_scale/yv12config.h" #include "vpx_util/vpx_timestamp.h" #include "vpx/internal/vpx_codec_internal.h" #include "./vpx_version.h" #include "vp9/encoder/vp9_encoder.h" +#include "vp9/encoder/vp9_ethread.h" #include "vpx/vp8cx.h" #include "vp9/common/vp9_alloccommon.h" +#include "vp9/common/vp9_scale.h" #include "vp9/vp9_cx_iface.h" #include "vp9/encoder/vp9_firstpass.h" #include "vp9/encoder/vp9_lookahead.h" #include "vp9/vp9_cx_iface.h" #include "vp9/vp9_iface_common.h" +#include "vpx/vpx_tpl.h" + typedef struct vp9_extracfg { int cpu_used; // available cpu percentage in 1/16 unsigned int enable_auto_alt_ref; @@ -38,6 +50,7 @@ typedef struct vp9_extracfg { unsigned int tile_columns; unsigned int tile_rows; unsigned int enable_tpl_model; + unsigned int enable_keyframe_filtering; unsigned int arnr_max_frames; unsigned int arnr_strength; unsigned int min_gf_interval; @@ -62,6 +75,7 @@ typedef struct vp9_extracfg { unsigned int row_mt; unsigned int motion_vector_unit_test; int delta_q_uv; + unsigned int validate_hbd_input; } vp9_extracfg; static struct vp9_extracfg default_extra_cfg = { @@ -77,6 +91,7 @@ static struct vp9_extracfg default_extra_cfg = { 6, // tile_columns 0, // tile_rows 1, // enable_tpl_model + 0, // enable_keyframe_filtering 7, // arnr_max_frames 5, // arnr_strength 0, // min_gf_interval; 0 -> default decision @@ -101,19 +116,20 @@ static struct vp9_extracfg default_extra_cfg = { 0, // row_mt 0, // motion_vector_unit_test 0, // delta_q_uv + 1, // validate_hbd_input }; struct vpx_codec_alg_priv { vpx_codec_priv_t base; vpx_codec_enc_cfg_t cfg; struct vp9_extracfg extra_cfg; - vpx_rational64_t timestamp_ratio; vpx_codec_pts_t pts_offset; unsigned char pts_offset_initialized; VP9EncoderConfig oxcf; VP9_COMP *cpi; unsigned char *cx_data; size_t cx_data_sz; + // pending_cx_data either is a null pointer or points into the cx_data buffer. unsigned char *pending_cx_data; size_t pending_cx_data_sz; int pending_frame_count; @@ -127,8 +143,14 @@ struct vpx_codec_alg_priv { vpx_codec_priv_output_cx_pkt_cb_pair_t output_cx_pkt_cb; // BufferPool that holds all reference frames. BufferPool *buffer_pool; + vpx_fixed_buf_t global_headers; + int global_header_subsampling; }; +// Called by encoder_set_config() and encoder_encode() only. Must not be called +// by encoder_init() because the `error` paramerer (cpi->common.error) will be +// destroyed by vpx_codec_enc_init_ver() after encoder_init() returns an error. +// See the "IMPORTANT" comment in vpx_codec_enc_init_ver(). static vpx_codec_err_t update_error_state( vpx_codec_alg_priv_t *ctx, const struct vpx_internal_error_info *error) { const vpx_codec_err_t res = error->error_code; @@ -170,8 +192,8 @@ static vpx_codec_err_t update_error_state( static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, const vpx_codec_enc_cfg_t *cfg, const struct vp9_extracfg *extra_cfg) { - RANGE_CHECK(cfg, g_w, 1, 65535); // 16 bits available - RANGE_CHECK(cfg, g_h, 1, 65535); // 16 bits available + RANGE_CHECK(cfg, g_w, 1, 65536); // 16 bits available + RANGE_CHECK(cfg, g_h, 1, 65536); // 16 bits available RANGE_CHECK(cfg, g_timebase.den, 1, 1000000000); RANGE_CHECK(cfg, g_timebase.num, 1, 1000000000); RANGE_CHECK_HI(cfg, g_profile, 3); @@ -183,7 +205,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, RANGE_CHECK(extra_cfg, aq_mode, 0, AQ_MODE_COUNT - 2); RANGE_CHECK(extra_cfg, alt_ref_aq, 0, 1); RANGE_CHECK(extra_cfg, frame_periodic_boost, 0, 1); - RANGE_CHECK_HI(cfg, g_threads, 64); + RANGE_CHECK_HI(cfg, g_threads, MAX_NUM_THREADS); RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS); RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_Q); RANGE_CHECK_HI(cfg, rc_undershoot_pct, 100); @@ -238,6 +260,9 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, if (cfg->ss_number_layers * cfg->ts_number_layers > VPX_MAX_LAYERS) ERROR("ss_number_layers * ts_number_layers is out of range"); + if ((cfg->ss_number_layers > 1 || cfg->ts_number_layers > 1) && + cfg->g_pass != VPX_RC_ONE_PASS) + ERROR("SVC is only supported for one-pass encoding."); if (cfg->ts_number_layers > 1) { unsigned int sl, tl; for (sl = 1; sl < cfg->ss_number_layers; ++sl) { @@ -276,6 +301,8 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, RANGE_CHECK(extra_cfg, cq_level, 0, 63); RANGE_CHECK(cfg, g_bit_depth, VPX_BITS_8, VPX_BITS_12); RANGE_CHECK(cfg, g_input_bit_depth, 8, 12); + if (cfg->g_input_bit_depth > (unsigned int)cfg->g_bit_depth) + ERROR("Input bit-depth must not exceed codec bit-depth"); RANGE_CHECK(extra_cfg, content, VP9E_CONTENT_DEFAULT, VP9E_CONTENT_INVALID - 1); @@ -291,45 +318,16 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, if (cfg->rc_twopass_stats_in.sz % packet_sz) ERROR("rc_twopass_stats_in.sz indicates truncated packet."); - if (cfg->ss_number_layers > 1 || cfg->ts_number_layers > 1) { - int i; - unsigned int n_packets_per_layer[VPX_SS_MAX_LAYERS] = { 0 }; + if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz) + ERROR("rc_twopass_stats_in requires at least two packets."); - stats = cfg->rc_twopass_stats_in.buf; - for (i = 0; i < n_packets; ++i) { - const int layer_id = (int)stats[i].spatial_layer_id; - if (layer_id >= 0 && layer_id < (int)cfg->ss_number_layers) { - ++n_packets_per_layer[layer_id]; - } - } + stats = + (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + n_packets - 1; - for (i = 0; i < (int)cfg->ss_number_layers; ++i) { - unsigned int layer_id; - if (n_packets_per_layer[i] < 2) { - ERROR( - "rc_twopass_stats_in requires at least two packets for each " - "layer."); - } - - stats = (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + - n_packets - cfg->ss_number_layers + i; - layer_id = (int)stats->spatial_layer_id; - - if (layer_id >= cfg->ss_number_layers || - (unsigned int)(stats->count + 0.5) != - n_packets_per_layer[layer_id] - 1) - ERROR("rc_twopass_stats_in missing EOS stats packet"); - } - } else { - if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz) - ERROR("rc_twopass_stats_in requires at least two packets."); - - stats = - (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + n_packets - 1; - - if ((int)(stats->count + 0.5) != n_packets - 1) - ERROR("rc_twopass_stats_in missing EOS stats packet"); - } + const double count_rounded = stats->count + 0.5; + if (!isfinite((float)stats->count) || stats->count < 0.0 || + count_rounded > (double)INT_MAX || (int)count_rounded != n_packets - 1) + ERROR("rc_twopass_stats_in missing EOS stats packet"); } #endif // !CONFIG_REALTIME_ONLY @@ -342,9 +340,6 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, cfg->g_bit_depth > VPX_BITS_8) { ERROR("Codec high bit-depth not supported in profile < 2"); } - if (cfg->g_profile <= (unsigned int)PROFILE_1 && cfg->g_input_bit_depth > 8) { - ERROR("Source high bit-depth not supported in profile < 2"); - } if (cfg->g_profile > (unsigned int)PROFILE_1 && cfg->g_bit_depth == VPX_BITS_8) { ERROR("Codec bit-depth 8 not supported in profile > 1"); @@ -407,6 +402,60 @@ static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx, if (img->d_w != ctx->cfg.g_w || img->d_h != ctx->cfg.g_h) ERROR("Image size must match encoder init configuration size"); + assert(img->fmt & VPX_IMG_FMT_PLANAR); + if (img->stride[VPX_PLANE_U] != img->stride[VPX_PLANE_V]) + ERROR("Image U/V strides must match"); + +#if CONFIG_VP9_HIGHBITDEPTH + // The following checks ensure that the image format matches the encoder's + // high bit-depth setting. Currently, libvpx overwrites function pointers if + // use_highbitdepth is set to 1, but there is no other way around if the + // internal flag gets reset to 0. + if (ctx->oxcf.use_highbitdepth && !(img->fmt & VPX_IMG_FMT_HIGHBITDEPTH)) { + ERROR( + "Encoder initialized with VPX_CODEC_USE_HIGHBITDEPTH requires a " + "high-bit-depth image format (e.g. VPX_IMG_FMT_I42016)"); + } + if (!ctx->oxcf.use_highbitdepth && (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH)) { + ERROR( + "Non-high-bit-depth encoder cannot accept a high-bit-depth image " + "format"); + } + + if (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) { + // Validate that it is safe to cast each row pointer to `unsigned short *`. + for (int plane = 0; plane < 3; ++plane) { + if ((((uintptr_t)img->planes[plane]) & 1) || (img->stride[plane] & 1)) { + ERROR("High bit-depth image planes and strides must be 2-byte aligned"); + } + } + } + + if (ctx->extra_cfg.validate_hbd_input && + (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH)) { + const unsigned int h = img->d_h; + const unsigned int w = img->d_w; + const unsigned int bit_depth = ctx->cfg.g_bit_depth; + const int max_val = 1 << bit_depth; + for (int plane = 0; plane < 3; ++plane) { + const unsigned short *src = (const unsigned short *)img->planes[plane]; + if (!src) return VPX_CODEC_INVALID_PARAM; + const int stride = img->stride[plane] / 2; + const unsigned int ph = + (plane == 0) ? h : (h + img->y_chroma_shift) >> img->y_chroma_shift; + const unsigned int pw = + (plane == 0) ? w : (w + img->x_chroma_shift) >> img->x_chroma_shift; + for (unsigned int i = 0; i < ph; ++i) { + for (unsigned int j = 0; j < pw; ++j) { + if (src[j] >= max_val) { + ERROR("Input pixel value out of range for encoder bit depth"); + } + } + src += stride; + } + } + } +#endif // CONFIG_VP9_HIGHBITDEPTH return VPX_CODEC_OK; } @@ -446,12 +495,14 @@ static void config_target_level(VP9EncoderConfig *oxcf) { if (oxcf->ss_number_layers == 1 && oxcf->pass != 0) oxcf->ss_target_bitrate[0] = (int)oxcf->target_bandwidth; - // Adjust max over-shoot percentage. - max_over_shoot_pct = - (int)((max_average_bitrate * 1.10 - (double)oxcf->target_bandwidth) * - 100 / (double)(oxcf->target_bandwidth)); - if (oxcf->over_shoot_pct > max_over_shoot_pct) - oxcf->over_shoot_pct = max_over_shoot_pct; + // Adjust max over-shoot percentage (only when target_bandwidth > 0). + if (oxcf->target_bandwidth > 0) { + max_over_shoot_pct = + (int)((max_average_bitrate * 1.10 - (double)oxcf->target_bandwidth) * + 100 / (double)(oxcf->target_bandwidth)); + if (oxcf->over_shoot_pct > max_over_shoot_pct) + oxcf->over_shoot_pct = max_over_shoot_pct; + } // Adjust worst allowed quantizer. oxcf->worst_allowed_q = vp9_quantizer_to_qindex(63); @@ -494,7 +545,6 @@ static vpx_rational64_t get_g_timebase_in_ts(vpx_rational_t g_timebase) { static vpx_codec_err_t set_encoder_config( VP9EncoderConfig *oxcf, vpx_codec_enc_cfg_t *cfg, const struct vp9_extracfg *extra_cfg) { - const int is_vbr = cfg->rc_end_usage == VPX_VBR; int sl, tl; unsigned int raw_target_rate; oxcf->profile = cfg->g_profile; @@ -557,9 +607,9 @@ static vpx_codec_err_t set_encoder_config( oxcf->resize_mode = RESIZE_NONE; } - oxcf->maximum_buffer_size_ms = is_vbr ? 240000 : cfg->rc_buf_sz; - oxcf->starting_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_initial_sz; - oxcf->optimal_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_optimal_sz; + oxcf->maximum_buffer_size_ms = cfg->rc_buf_sz; + oxcf->starting_buffer_level_ms = cfg->rc_buf_initial_sz; + oxcf->optimal_buffer_level_ms = cfg->rc_buf_optimal_sz; oxcf->drop_frames_water_mark = cfg->rc_dropframe_thresh; @@ -603,6 +653,8 @@ static vpx_codec_err_t set_encoder_config( oxcf->enable_tpl_model = extra_cfg->enable_tpl_model; + oxcf->enable_keyframe_filtering = extra_cfg->enable_keyframe_filtering; + // TODO(yunqing): The dependencies between row tiles cause error in multi- // threaded encoding. For now, tile_rows is forced to be 0 in this case. // The further fix can be done by adding synchronizations after a tile row @@ -613,7 +665,8 @@ static vpx_codec_err_t set_encoder_config( else oxcf->tile_rows = extra_cfg->tile_rows; - oxcf->error_resilient_mode = cfg->g_error_resilient; + oxcf->error_resilient_mode = + cfg->g_error_resilient & VPX_ERROR_RESILIENT_DEFAULT; oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode; oxcf->aq_mode = extra_cfg->aq_mode; @@ -625,6 +678,12 @@ static vpx_codec_err_t set_encoder_config( oxcf->ts_number_layers = cfg->ts_number_layers; oxcf->temporal_layering_mode = (enum vp9e_temporal_layering_mode)cfg->temporal_layering_mode; + if (oxcf->temporal_layering_mode == VP9E_TEMPORAL_LAYERING_MODE_NOLAYERING) { + if (oxcf->ts_number_layers == 2) + oxcf->temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_0101; + else if (oxcf->ts_number_layers == 3) + oxcf->temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_0212; + } oxcf->target_level = extra_cfg->target_level; @@ -635,8 +694,12 @@ static vpx_codec_err_t set_encoder_config( for (sl = 0; sl < oxcf->ss_number_layers; ++sl) { for (tl = 0; tl < oxcf->ts_number_layers; ++tl) { - oxcf->layer_target_bitrate[sl * oxcf->ts_number_layers + tl] = - 1000 * cfg->layer_target_bitrate[sl * oxcf->ts_number_layers + tl]; + const int layer = sl * oxcf->ts_number_layers + tl; + if (cfg->layer_target_bitrate[layer] > INT_MAX / 1000) + oxcf->layer_target_bitrate[layer] = INT_MAX; + else + oxcf->layer_target_bitrate[layer] = + 1000 * cfg->layer_target_bitrate[layer]; } } if (oxcf->ss_number_layers == 1 && oxcf->pass != 0) { @@ -652,7 +715,6 @@ static vpx_codec_err_t set_encoder_config( } if (get_level_index(oxcf->target_level) >= 0) config_target_level(oxcf); - oxcf->use_simple_encode_api = 0; // vp9_dump_encoder_config(oxcf, stderr); return VPX_CODEC_OK; } @@ -789,10 +851,25 @@ static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx, if (cfg->g_w != ctx->cfg.g_w || cfg->g_h != ctx->cfg.g_h) { if (cfg->g_lag_in_frames > 1 || cfg->g_pass != VPX_RC_ONE_PASS) ERROR("Cannot change width or height after initialization"); - if (!valid_ref_frame_size(ctx->cfg.g_w, ctx->cfg.g_h, cfg->g_w, cfg->g_h) || + // Note: function encoder_set_config() is allowed to be called multiple + // times. However, when the original frame width or height is less than two + // times of the new frame width or height, a forced key frame should be + // used (for the case of single spatial layer, since otherwise a previous + // encoded frame at a lower layer may be the desired reference). To make + // sure the correct detection of a forced key frame, we need + // to update the frame width and height only when the actual encoding is + // performed. cpi->last_coded_width and cpi->last_coded_height are used to + // track the actual coded frame size. + if ((ctx->cpi->last_coded_width && ctx->cpi->last_coded_height && + (!valid_ref_frame_size(ctx->cpi->last_coded_width, + ctx->cpi->last_coded_height, cfg->g_w, + cfg->g_h) && + ctx->cpi->svc.number_spatial_layers == 1)) || (ctx->cpi->initial_width && (int)cfg->g_w > ctx->cpi->initial_width) || - (ctx->cpi->initial_height && (int)cfg->g_h > ctx->cpi->initial_height)) + (ctx->cpi->initial_height && + (int)cfg->g_h > ctx->cpi->initial_height)) { force_key = 1; + } } // Prevent increasing lag_in_frames. This check is stricter than it needs @@ -813,6 +890,7 @@ static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx, assert(codec_err != VPX_CODEC_OK); return codec_err; } + ctx->cpi->common.error.setjmp = 1; ctx->cfg = *cfg; set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); @@ -879,8 +957,7 @@ static vpx_codec_err_t ctrl_set_cpuused(vpx_codec_alg_priv_t *ctx, struct vp9_extracfg extra_cfg = ctx->extra_cfg; // Use fastest speed setting (speed 9 or -9) if it's set beyond the range. extra_cfg.cpu_used = CAST(VP8E_SET_CPUUSED, args); - extra_cfg.cpu_used = VPXMIN(9, extra_cfg.cpu_used); - extra_cfg.cpu_used = VPXMAX(-9, extra_cfg.cpu_used); + extra_cfg.cpu_used = clamp(extra_cfg.cpu_used, -9, 9); #if CONFIG_REALTIME_ONLY if (extra_cfg.cpu_used > -5 && extra_cfg.cpu_used < 5) extra_cfg.cpu_used = (extra_cfg.cpu_used > 0) ? 5 : -5; @@ -937,6 +1014,20 @@ static vpx_codec_err_t ctrl_set_tpl_model(vpx_codec_alg_priv_t *ctx, return update_extra_cfg(ctx, &extra_cfg); } +static vpx_codec_err_t ctrl_set_keyframe_filtering(vpx_codec_alg_priv_t *ctx, + va_list args) { + struct vp9_extracfg extra_cfg = ctx->extra_cfg; + extra_cfg.enable_keyframe_filtering = + CAST(VP9E_SET_KEY_FRAME_FILTERING, args); + return update_extra_cfg(ctx, &extra_cfg); +} + +static vpx_codec_err_t ctrl_set_validate_hbd_input(vpx_codec_alg_priv_t *ctx, + va_list args) { + struct vp9_extracfg extra_cfg = ctx->extra_cfg; + extra_cfg.validate_hbd_input = CAST(VP9E_SET_VALIDATE_HBD_INPUT, args); + return update_extra_cfg(ctx, &extra_cfg); +} static vpx_codec_err_t ctrl_set_arnr_max_frames(vpx_codec_alg_priv_t *ctx, va_list args) { struct vp9_extracfg extra_cfg = ctx->extra_cfg; @@ -1014,6 +1105,7 @@ static vpx_codec_err_t ctrl_set_aq_mode(vpx_codec_alg_priv_t *ctx, va_list args) { struct vp9_extracfg extra_cfg = ctx->extra_cfg; extra_cfg.aq_mode = CAST(VP9E_SET_AQ_MODE, args); + if (ctx->cpi->fixed_qp_onepass) extra_cfg.aq_mode = 0; return update_extra_cfg(ctx, &extra_cfg); } @@ -1067,6 +1159,7 @@ static vpx_codec_err_t ctrl_set_rtc_external_ratectrl(vpx_codec_alg_priv_t *ctx, cpi->compute_frame_low_motion_onepass = 0; cpi->rc.constrain_gf_key_freq_onepass_vbr = 0; cpi->cyclic_refresh->content_mode = 0; + cpi->disable_scene_detection_rtc_ratectrl = 1; } return VPX_CODEC_OK; } @@ -1114,10 +1207,7 @@ static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx, if (res == VPX_CODEC_OK) { priv->pts_offset_initialized = 0; - // TODO(angiebird): Replace priv->timestamp_ratio by - // oxcf->g_timebase_in_ts - priv->timestamp_ratio = get_g_timebase_in_ts(priv->cfg.g_timebase); - + priv->global_header_subsampling = -1; set_encoder_config(&priv->oxcf, &priv->cfg, &priv->extra_cfg); #if CONFIG_VP9_HIGHBITDEPTH priv->oxcf.use_highbitdepth = @@ -1134,15 +1224,16 @@ static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx, static vpx_codec_err_t encoder_destroy(vpx_codec_alg_priv_t *ctx) { free(ctx->cx_data); + free(ctx->global_headers.buf); vp9_remove_compressor(ctx->cpi); vpx_free(ctx->buffer_pool); vpx_free(ctx); return VPX_CODEC_OK; } -static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, - unsigned long duration, - unsigned long deadline) { +static vpx_codec_err_t pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, + unsigned long duration, + vpx_enc_deadline_t deadline) { MODE new_mode = BEST; #if CONFIG_REALTIME_ONLY @@ -1153,13 +1244,16 @@ static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, case VPX_RC_ONE_PASS: if (deadline > 0) { // Convert duration parameter from stream timebase to microseconds. - uint64_t duration_us; - VPX_STATIC_ASSERT(TICKS_PER_SEC > 1000000 && (TICKS_PER_SEC % 1000000) == 0); - duration_us = duration * (uint64_t)ctx->timestamp_ratio.num / - (ctx->timestamp_ratio.den * (TICKS_PER_SEC / 1000000)); + if (duration > UINT64_MAX / (uint64_t)ctx->oxcf.g_timebase_in_ts.num) { + ERROR("duration is too big"); + } + uint64_t duration_us = duration * + (uint64_t)ctx->oxcf.g_timebase_in_ts.num / + ((uint64_t)ctx->oxcf.g_timebase_in_ts.den * + (TICKS_PER_SEC / 1000000)); // If the deadline is more that the duration this frame is to be shown, // use good quality mode. Otherwise use realtime mode. @@ -1176,12 +1270,14 @@ static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, if (deadline == VPX_DL_REALTIME) { ctx->oxcf.pass = 0; new_mode = REALTIME; + ctx->oxcf.speed = VPXMAX(ctx->oxcf.speed, 5); } if (ctx->oxcf.mode != new_mode) { ctx->oxcf.mode = new_mode; vp9_change_config(ctx->cpi, &ctx->oxcf); } + return VPX_CODEC_OK; } // Turn on to test if supplemental superframe data breaks decoding @@ -1191,7 +1287,6 @@ static int write_superframe_index(vpx_codec_alg_priv_t *ctx) { unsigned int mask; int mag, index_sz; - assert(ctx->pending_frame_count); assert(ctx->pending_frame_count <= 8); // Add the number of frames to the marker byte @@ -1207,8 +1302,12 @@ static int write_superframe_index(vpx_codec_alg_priv_t *ctx) { // Write the index index_sz = 2 + (mag + 1) * ctx->pending_frame_count; - if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) { - uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz; + unsigned char *cx_data_end = ctx->cx_data + ctx->cx_data_sz; + unsigned char *pending_cx_data_end = + ctx->pending_cx_data + ctx->pending_cx_data_sz; + ptrdiff_t space_remaining = cx_data_end - pending_cx_data_end; + if (index_sz <= space_remaining) { + uint8_t *x = pending_cx_data_end; int i, j; #ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA uint8_t marker_test = 0xc0; @@ -1239,6 +1338,8 @@ static int write_superframe_index(vpx_codec_alg_priv_t *ctx) { #ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA index_sz += index_sz_test; #endif + } else { + index_sz = 0; } return index_sz; } @@ -1255,6 +1356,10 @@ static vpx_codec_frame_flags_t get_frame_pkt_flags(const VP9_COMP *cpi, .is_key_frame)) flags |= VPX_FRAME_IS_KEY; + if (!cpi->common.show_frame) { + flags |= VPX_FRAME_IS_INVISIBLE; + } + if (cpi->droppable) flags |= VPX_FRAME_IS_DROPPABLE; return flags; @@ -1287,44 +1392,59 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx, vpx_codec_pts_t pts_val, unsigned long duration, vpx_enc_frame_flags_t enc_flags, - unsigned long deadline) { - volatile vpx_codec_err_t res = VPX_CODEC_OK; + vpx_enc_deadline_t deadline) { + volatile vpx_codec_err_t res; volatile vpx_enc_frame_flags_t flags = enc_flags; volatile vpx_codec_pts_t pts = pts_val; VP9_COMP *const cpi = ctx->cpi; - const vpx_rational64_t *const timestamp_ratio = &ctx->timestamp_ratio; + const vpx_rational64_t *const timebase_in_ts = &ctx->oxcf.g_timebase_in_ts; size_t data_sz; vpx_codec_cx_pkt_t pkt; memset(&pkt, 0, sizeof(pkt)); if (cpi == NULL) return VPX_CODEC_INVALID_PARAM; + cpi->last_coded_width = ctx->oxcf.width; + cpi->last_coded_height = ctx->oxcf.height; + if (img != NULL) { res = validate_img(ctx, img); - if (res == VPX_CODEC_OK) { - // There's no codec control for multiple alt-refs so check the encoder - // instance for its status to determine the compressed data size. - data_sz = ctx->cfg.g_w * ctx->cfg.g_h * get_image_bps(img) / 8 * - (cpi->multi_layer_arf ? 8 : 2); - if (data_sz < kMinCompressedSize) data_sz = kMinCompressedSize; - if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) { - ctx->cx_data_sz = data_sz; - free(ctx->cx_data); - ctx->cx_data = (unsigned char *)malloc(ctx->cx_data_sz); - if (ctx->cx_data == NULL) { - return VPX_CODEC_MEM_ERROR; - } + if (res != VPX_CODEC_OK) { + return res; + } + // There's no codec control for multiple alt-refs so check the encoder + // instance for its status to determine the compressed data size. + data_sz = ctx->cfg.g_w * ctx->cfg.g_h * get_image_bps(img) / 8 * + (cpi->multi_layer_arf ? 8 : 2); + if (data_sz < kMinCompressedSize) data_sz = kMinCompressedSize; + if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) { + ctx->cx_data_sz = data_sz; + free(ctx->cx_data); + ctx->cx_data = (unsigned char *)malloc(ctx->cx_data_sz); + if (ctx->cx_data == NULL) { + return VPX_CODEC_MEM_ERROR; } } + + int chroma_subsampling = -1; + if ((img->fmt & VPX_IMG_FMT_I420) == VPX_IMG_FMT_I420 || + (img->fmt & VPX_IMG_FMT_NV12) == VPX_IMG_FMT_NV12 || + (img->fmt & VPX_IMG_FMT_YV12) == VPX_IMG_FMT_YV12) { + chroma_subsampling = 1; // matches default for Codec Parameter String + } else if ((img->fmt & VPX_IMG_FMT_I422) == VPX_IMG_FMT_I422) { + chroma_subsampling = 2; + } else if ((img->fmt & VPX_IMG_FMT_I444) == VPX_IMG_FMT_I444) { + chroma_subsampling = 3; + } + if (chroma_subsampling > ctx->global_header_subsampling) { + ctx->global_header_subsampling = chroma_subsampling; + } } - if (!ctx->pts_offset_initialized) { - ctx->pts_offset = pts; - ctx->pts_offset_initialized = 1; + res = pick_quickcompress_mode(ctx, duration, deadline); + if (res != VPX_CODEC_OK) { + return res; } - pts -= ctx->pts_offset; - - pick_quickcompress_mode(ctx, duration, deadline); vpx_codec_pkt_list_init(&ctx->pkt_list); // Handle Flags @@ -1342,7 +1462,7 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx, } cpi->common.error.setjmp = 1; - if (res == VPX_CODEC_OK) vp9_apply_encoding_flags(cpi, flags); + vp9_apply_encoding_flags(cpi, flags); // Handle fixed keyframe intervals if (ctx->cfg.kf_mode == VPX_KF_AUTO && @@ -1353,184 +1473,227 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx, } } - if (res == VPX_CODEC_OK) { - unsigned int lib_flags = 0; - YV12_BUFFER_CONFIG sd; - int64_t dst_time_stamp = timebase_units_to_ticks(timestamp_ratio, pts); - int64_t dst_end_time_stamp = - timebase_units_to_ticks(timestamp_ratio, pts + duration); - size_t size, cx_data_sz; - unsigned char *cx_data; + unsigned int lib_flags = 0; + size_t size, cx_data_sz; + unsigned char *cx_data; - cpi->svc.timebase_fac = timebase_units_to_ticks(timestamp_ratio, 1); + // Per-frame PSNR is not supported when g_lag_in_frames is greater than 0. + if ((flags & VPX_EFLAG_CALCULATE_PSNR) && ctx->cfg.g_lag_in_frames != 0) { + vpx_internal_error( + &ctx->cpi->common.error, VPX_CODEC_INCAPABLE, + "Cannot calculate per-frame PSNR when g_lag_in_frames is nonzero"); + } + // Set up internal flags +#if CONFIG_INTERNAL_STATS + assert(cpi->b_calculate_psnr == 1); +#else + cpi->b_calculate_psnr = (ctx->base.init_flags & VPX_CODEC_USE_PSNR) || + (flags & VPX_EFLAG_CALCULATE_PSNR); +#endif + + if (img != NULL) { + YV12_BUFFER_CONFIG sd; + + if (!ctx->pts_offset_initialized) { + ctx->pts_offset = pts; + ctx->pts_offset_initialized = 1; + } + if (pts < ctx->pts_offset) { + vpx_internal_error(&cpi->common.error, VPX_CODEC_INVALID_PARAM, + "pts is smaller than initial pts"); + } + pts -= ctx->pts_offset; + if (pts > INT64_MAX / timebase_in_ts->num) { + vpx_internal_error(&cpi->common.error, VPX_CODEC_INVALID_PARAM, + "conversion of relative pts to ticks would overflow"); + } + const int64_t dst_time_stamp = timebase_units_to_ticks(timebase_in_ts, pts); + + cpi->svc.timebase_fac = timebase_units_to_ticks(timebase_in_ts, 1); cpi->svc.time_stamp_superframe = dst_time_stamp; - // Set up internal flags - if (ctx->base.init_flags & VPX_CODEC_USE_PSNR) cpi->b_calculate_psnr = 1; - - if (img != NULL) { - res = image2yuvconfig(img, &sd); - - // Store the original flags in to the frame buffer. Will extract the - // key frame flag when we actually encode this frame. - if (vp9_receive_raw_frame(cpi, flags | ctx->next_frame_flags, &sd, - dst_time_stamp, dst_end_time_stamp)) { - res = update_error_state(ctx, &cpi->common.error); - } - ctx->next_frame_flags = 0; +#if ULONG_MAX > INT64_MAX + if (duration > INT64_MAX) { + vpx_internal_error(&cpi->common.error, VPX_CODEC_INVALID_PARAM, + "duration is too big"); } - - cx_data = ctx->cx_data; - cx_data_sz = ctx->cx_data_sz; - - /* Any pending invisible frames? */ - if (ctx->pending_cx_data) { - memmove(cx_data, ctx->pending_cx_data, ctx->pending_cx_data_sz); - ctx->pending_cx_data = cx_data; - cx_data += ctx->pending_cx_data_sz; - cx_data_sz -= ctx->pending_cx_data_sz; - - /* TODO: this is a minimal check, the underlying codec doesn't respect - * the buffer size anyway. - */ - if (cx_data_sz < ctx->cx_data_sz / 2) { - vpx_internal_error(&cpi->common.error, VPX_CODEC_ERROR, - "Compressed data buffer too small"); - return VPX_CODEC_ERROR; - } +#endif + if (pts > INT64_MAX - (int64_t)duration) { + vpx_internal_error(&cpi->common.error, VPX_CODEC_INVALID_PARAM, + "relative pts + duration is too big"); } + vpx_codec_pts_t pts_end = pts + (int64_t)duration; + if (pts_end > INT64_MAX / timebase_in_ts->num) { + vpx_internal_error( + &cpi->common.error, VPX_CODEC_INVALID_PARAM, + "conversion of relative pts + duration to ticks would overflow"); + } + const int64_t dst_end_time_stamp = + timebase_units_to_ticks(timebase_in_ts, pts_end); + res = image2yuvconfig(img, &sd); - if (cpi->oxcf.pass == 1 && !cpi->use_svc) { + // Store the original flags in to the frame buffer. Will extract the + // key frame flag when we actually encode this frame. + if (vp9_receive_raw_frame(cpi, flags | ctx->next_frame_flags, &sd, + dst_time_stamp, dst_end_time_stamp)) { + res = update_error_state(ctx, &cpi->common.error); + } + ctx->next_frame_flags = 0; + } + + cx_data = ctx->cx_data; + cx_data_sz = ctx->cx_data_sz; + + /* Any pending invisible frames? */ + if (ctx->pending_cx_data) { + assert(cx_data_sz >= ctx->pending_cx_data_sz); + memmove(cx_data, ctx->pending_cx_data, ctx->pending_cx_data_sz); + ctx->pending_cx_data = cx_data; + cx_data += ctx->pending_cx_data_sz; + cx_data_sz -= ctx->pending_cx_data_sz; + + /* TODO(webm:1844): this is a minimal check, the underlying codec doesn't + * respect the buffer size anyway. + */ + if (cx_data_sz < ctx->cx_data_sz / 2) { + vpx_internal_error(&cpi->common.error, VPX_CODEC_ERROR, + "Compressed data buffer too small"); + } + } + + if (cpi->oxcf.pass == 1 && !cpi->use_svc) { #if !CONFIG_REALTIME_ONLY - // compute first pass stats - if (img) { - int ret; - vpx_codec_cx_pkt_t fps_pkt; - ENCODE_FRAME_RESULT encode_frame_result; - vp9_init_encode_frame_result(&encode_frame_result); - // TODO(angiebird): Call vp9_first_pass directly - ret = vp9_get_compressed_data(cpi, &lib_flags, &size, cx_data, - &dst_time_stamp, &dst_end_time_stamp, - !img, &encode_frame_result); - assert(size == 0); // There is no compressed data in the first pass - (void)ret; - assert(ret == 0); - fps_pkt = get_first_pass_stats_pkt(&cpi->twopass.this_frame_stats); - vpx_codec_pkt_list_add(&ctx->pkt_list.head, &fps_pkt); - } else { - if (!cpi->twopass.first_pass_done) { - vpx_codec_cx_pkt_t fps_pkt; - vp9_end_first_pass(cpi); - fps_pkt = get_first_pass_stats_pkt(&cpi->twopass.total_stats); - vpx_codec_pkt_list_add(&ctx->pkt_list.head, &fps_pkt); - } - } -#else // !CONFIG_REALTIME_ONLY - assert(0); -#endif // !CONFIG_REALTIME_ONLY - } else { + // compute first pass stats + if (img) { + int ret; + int64_t dst_time_stamp; + int64_t dst_end_time_stamp; + vpx_codec_cx_pkt_t fps_pkt; ENCODE_FRAME_RESULT encode_frame_result; vp9_init_encode_frame_result(&encode_frame_result); - while (cx_data_sz >= ctx->cx_data_sz / 2 && - -1 != vp9_get_compressed_data(cpi, &lib_flags, &size, cx_data, - &dst_time_stamp, &dst_end_time_stamp, - !img, &encode_frame_result)) { - // Pack psnr pkt - if (size > 0 && !cpi->use_svc) { - // TODO(angiebird): Figure out while we don't need psnr pkt when - // use_svc is on - PSNR_STATS psnr; - if (vp9_get_psnr(cpi, &psnr)) { - vpx_codec_cx_pkt_t psnr_pkt = get_psnr_pkt(&psnr); - vpx_codec_pkt_list_add(&ctx->pkt_list.head, &psnr_pkt); - } + // TODO(angiebird): Call vp9_first_pass directly + ret = vp9_get_compressed_data(cpi, &lib_flags, &size, cx_data, cx_data_sz, + &dst_time_stamp, &dst_end_time_stamp, !img, + &encode_frame_result); + assert(size == 0); // There is no compressed data in the first pass + (void)ret; + assert(ret == 0); + fps_pkt = get_first_pass_stats_pkt(&cpi->twopass.this_frame_stats); + vpx_codec_pkt_list_add(&ctx->pkt_list.head, &fps_pkt); + } else { + if (!cpi->twopass.first_pass_done) { + vpx_codec_cx_pkt_t fps_pkt; + vp9_end_first_pass(cpi); + fps_pkt = get_first_pass_stats_pkt(&cpi->twopass.total_stats); + vpx_codec_pkt_list_add(&ctx->pkt_list.head, &fps_pkt); + } + } +#else // !CONFIG_REALTIME_ONLY + assert(0); +#endif // !CONFIG_REALTIME_ONLY + } else { + ENCODE_FRAME_RESULT encode_frame_result; + int64_t dst_time_stamp; + int64_t dst_end_time_stamp; + vp9_init_encode_frame_result(&encode_frame_result); + while (cx_data_sz >= ctx->cx_data_sz / 2 && + -1 != vp9_get_compressed_data(cpi, &lib_flags, &size, cx_data, + cx_data_sz, &dst_time_stamp, + &dst_end_time_stamp, !img, + &encode_frame_result)) { + // Pack psnr pkt. + if (size > 0) { + PSNR_STATS psnr; + if (vp9_get_psnr(cpi, &psnr)) { + vpx_codec_cx_pkt_t psnr_pkt = get_psnr_pkt(&psnr); + vpx_codec_pkt_list_add(&ctx->pkt_list.head, &psnr_pkt); } + } - if (size || (cpi->use_svc && cpi->svc.skip_enhancement_layer)) { - // Pack invisible frames with the next visible frame - if (!cpi->common.show_frame || - (cpi->use_svc && cpi->svc.spatial_layer_id < - cpi->svc.number_spatial_layers - 1)) { - if (ctx->pending_cx_data == 0) ctx->pending_cx_data = cx_data; - ctx->pending_cx_data_sz += size; - if (size) - ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; - ctx->pending_frame_magnitude |= size; - cx_data += size; - cx_data_sz -= size; - pkt.data.frame.width[cpi->svc.spatial_layer_id] = cpi->common.width; - pkt.data.frame.height[cpi->svc.spatial_layer_id] = - cpi->common.height; - pkt.data.frame.spatial_layer_encoded[cpi->svc.spatial_layer_id] = - 1 - cpi->svc.drop_spatial_layer[cpi->svc.spatial_layer_id]; - - if (ctx->output_cx_pkt_cb.output_cx_pkt) { - pkt.kind = VPX_CODEC_CX_FRAME_PKT; - pkt.data.frame.pts = - ticks_to_timebase_units(timestamp_ratio, dst_time_stamp) + - ctx->pts_offset; - pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units( - timestamp_ratio, dst_end_time_stamp - dst_time_stamp); - pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags); - pkt.data.frame.buf = ctx->pending_cx_data; - pkt.data.frame.sz = size; - ctx->pending_cx_data = NULL; - ctx->pending_cx_data_sz = 0; - ctx->pending_frame_count = 0; - ctx->pending_frame_magnitude = 0; - ctx->output_cx_pkt_cb.output_cx_pkt( - &pkt, ctx->output_cx_pkt_cb.user_priv); - } - continue; - } - - // Add the frame packet to the list of returned packets. - pkt.kind = VPX_CODEC_CX_FRAME_PKT; - pkt.data.frame.pts = - ticks_to_timebase_units(timestamp_ratio, dst_time_stamp) + - ctx->pts_offset; - pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units( - timestamp_ratio, dst_end_time_stamp - dst_time_stamp); - pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags); + if (size || (cpi->use_svc && cpi->svc.skip_enhancement_layer)) { + // Pack invisible frames with the next visible frame + if (!cpi->common.show_frame || + (cpi->use_svc && + cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1)) { + if (ctx->pending_cx_data == NULL) ctx->pending_cx_data = cx_data; + ctx->pending_cx_data_sz += size; + if (size) ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; + ctx->pending_frame_magnitude |= size; + cx_data += size; + cx_data_sz -= size; pkt.data.frame.width[cpi->svc.spatial_layer_id] = cpi->common.width; pkt.data.frame.height[cpi->svc.spatial_layer_id] = cpi->common.height; pkt.data.frame.spatial_layer_encoded[cpi->svc.spatial_layer_id] = 1 - cpi->svc.drop_spatial_layer[cpi->svc.spatial_layer_id]; - if (ctx->pending_cx_data) { - if (size) - ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; - ctx->pending_frame_magnitude |= size; - ctx->pending_cx_data_sz += size; - // write the superframe only for the case when - if (!ctx->output_cx_pkt_cb.output_cx_pkt) - size += write_superframe_index(ctx); + if (ctx->output_cx_pkt_cb.output_cx_pkt) { + pkt.kind = VPX_CODEC_CX_FRAME_PKT; + pkt.data.frame.pts = + ticks_to_timebase_units(timebase_in_ts, dst_time_stamp) + + ctx->pts_offset; + pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units( + timebase_in_ts, dst_end_time_stamp - dst_time_stamp); + pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags); pkt.data.frame.buf = ctx->pending_cx_data; - pkt.data.frame.sz = ctx->pending_cx_data_sz; + pkt.data.frame.sz = size; ctx->pending_cx_data = NULL; ctx->pending_cx_data_sz = 0; ctx->pending_frame_count = 0; ctx->pending_frame_magnitude = 0; - } else { - pkt.data.frame.buf = cx_data; - pkt.data.frame.sz = size; - } - pkt.data.frame.partition_id = -1; - - if (ctx->output_cx_pkt_cb.output_cx_pkt) ctx->output_cx_pkt_cb.output_cx_pkt( &pkt, ctx->output_cx_pkt_cb.user_priv); - else - vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); - - cx_data += size; - cx_data_sz -= size; - if (is_one_pass_cbr_svc(cpi) && - (cpi->svc.spatial_layer_id == - cpi->svc.number_spatial_layers - 1)) { - // Encoded all spatial layers; exit loop. - break; } + continue; + } + + // Add the frame packet to the list of returned packets. + pkt.kind = VPX_CODEC_CX_FRAME_PKT; + pkt.data.frame.pts = + ticks_to_timebase_units(timebase_in_ts, dst_time_stamp) + + ctx->pts_offset; + pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units( + timebase_in_ts, dst_end_time_stamp - dst_time_stamp); + pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags); + pkt.data.frame.width[cpi->svc.spatial_layer_id] = cpi->common.width; + pkt.data.frame.height[cpi->svc.spatial_layer_id] = cpi->common.height; + pkt.data.frame.spatial_layer_encoded[cpi->svc.spatial_layer_id] = + 1 - cpi->svc.drop_spatial_layer[cpi->svc.spatial_layer_id]; + + if (ctx->pending_cx_data) { + if (size) ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; + ctx->pending_frame_magnitude |= size; + ctx->pending_cx_data_sz += size; + // write the superframe only for the case when the callback function + // for getting per-layer packets is not registered. + if (!ctx->output_cx_pkt_cb.output_cx_pkt && + ctx->pending_frame_count > 0) { + size += write_superframe_index(ctx); + assert(size <= cx_data_sz); + } + pkt.data.frame.buf = ctx->pending_cx_data; + pkt.data.frame.sz = ctx->pending_cx_data_sz; + ctx->pending_cx_data = NULL; + ctx->pending_cx_data_sz = 0; + ctx->pending_frame_count = 0; + ctx->pending_frame_magnitude = 0; + } else { + pkt.data.frame.buf = cx_data; + pkt.data.frame.sz = size; + } + pkt.data.frame.partition_id = -1; + + if (ctx->output_cx_pkt_cb.output_cx_pkt) + ctx->output_cx_pkt_cb.output_cx_pkt(&pkt, + ctx->output_cx_pkt_cb.user_priv); + else + vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); + + cx_data += size; + cx_data_sz -= size; + if (is_one_pass_svc(cpi) && + (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1)) { + // Encoded all spatial layers; exit loop. + break; } } } @@ -1552,9 +1715,17 @@ static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx, if (frame != NULL) { YV12_BUFFER_CONFIG sd; + if (frame->img.planes[VPX_PLANE_Y] == NULL || + frame->img.planes[VPX_PLANE_U] == NULL || + frame->img.planes[VPX_PLANE_V] == NULL) { + return VPX_CODEC_INVALID_PARAM; + } + image2yuvconfig(&frame->img, &sd); - vp9_set_reference_enc(ctx->cpi, ref_frame_to_vp9_reframe(frame->frame_type), - &sd); + if (vp9_set_reference_enc( + ctx->cpi, ref_frame_to_vp9_reframe(frame->frame_type), &sd)) { + return VPX_CODEC_ERROR; + } return VPX_CODEC_OK; } return VPX_CODEC_INVALID_PARAM; @@ -1567,9 +1738,17 @@ static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx, if (frame != NULL) { YV12_BUFFER_CONFIG sd; + if (frame->img.planes[VPX_PLANE_Y] == NULL || + frame->img.planes[VPX_PLANE_U] == NULL || + frame->img.planes[VPX_PLANE_V] == NULL) { + return VPX_CODEC_INVALID_PARAM; + } + image2yuvconfig(&frame->img, &sd); - vp9_copy_reference_enc(ctx->cpi, - ref_frame_to_vp9_reframe(frame->frame_type), &sd); + if (vp9_copy_reference_enc( + ctx->cpi, ref_frame_to_vp9_reframe(frame->frame_type), &sd)) { + return VPX_CODEC_ERROR; + } return VPX_CODEC_OK; } return VPX_CODEC_INVALID_PARAM; @@ -1605,6 +1784,34 @@ static vpx_codec_err_t ctrl_set_previewpp(vpx_codec_alg_priv_t *ctx, #endif } +// Returns the contents of CodecPrivate described in: +// https://www.webmproject.org/docs/container/#vp9-codec-feature-metadata-codecprivate +// This includes Profile, Level, Bit depth and Chroma subsampling. Each entry +// is 3 bytes. 1 byte ID, 1 byte length (= 1) and 1 byte value. +static vpx_fixed_buf_t *encoder_get_global_headers(vpx_codec_alg_priv_t *ctx) { + if (!ctx->cpi) return NULL; + + const unsigned int profile = ctx->cfg.g_profile; + const VP9_LEVEL level = vp9_get_level(&ctx->cpi->level_info.level_spec); + const vpx_bit_depth_t bit_depth = ctx->cfg.g_bit_depth; + const int subsampling = ctx->global_header_subsampling; + const uint8_t buf[12] = { + 1, 1, (uint8_t)profile, 2, 1, (uint8_t)level, + 3, 1, (uint8_t)bit_depth, 4, 1, (uint8_t)subsampling + }; + + if (ctx->global_headers.buf) free(ctx->global_headers.buf); + ctx->global_headers.buf = malloc(sizeof(buf)); + if (!ctx->global_headers.buf) return NULL; + + ctx->global_headers.sz = sizeof(buf); + // No data or I440, which isn't mapped. + if (ctx->global_header_subsampling == -1) ctx->global_headers.sz -= 3; + memcpy(ctx->global_headers.buf, buf, ctx->global_headers.sz); + + return &ctx->global_headers; +} + static vpx_image_t *encoder_get_preview(vpx_codec_alg_priv_t *ctx) { YV12_BUFFER_CONFIG sd; vp9_ppflags_t flags; @@ -1629,13 +1836,9 @@ static vpx_codec_err_t ctrl_set_roi_map(vpx_codec_alg_priv_t *ctx, if (data) { vpx_roi_map_t *roi = (vpx_roi_map_t *)data; - - if (!vp9_set_roi_map(ctx->cpi, roi->roi_map, roi->rows, roi->cols, - roi->delta_q, roi->delta_lf, roi->skip, - roi->ref_frame)) { - return VPX_CODEC_OK; - } - return VPX_CODEC_INVALID_PARAM; + return vp9_set_roi_map(ctx->cpi, roi->roi_map, roi->rows, roi->cols, + roi->delta_q, roi->delta_lf, roi->skip, + roi->ref_frame); } return VPX_CODEC_INVALID_PARAM; } @@ -1673,9 +1876,8 @@ static vpx_codec_err_t ctrl_set_scale_mode(vpx_codec_alg_priv_t *ctx, vpx_scaling_mode_t *const mode = va_arg(args, vpx_scaling_mode_t *); if (mode) { - const int res = - vp9_set_internal_size(ctx->cpi, (VPX_SCALING)mode->h_scaling_mode, - (VPX_SCALING)mode->v_scaling_mode); + const int res = vp9_set_internal_size(ctx->cpi, mode->h_scaling_mode, + mode->v_scaling_mode); return (res == 0) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM; } return VPX_CODEC_INVALID_PARAM; @@ -1684,23 +1886,13 @@ static vpx_codec_err_t ctrl_set_scale_mode(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t ctrl_set_svc(vpx_codec_alg_priv_t *ctx, va_list args) { int data = va_arg(args, int); const vpx_codec_enc_cfg_t *cfg = &ctx->cfg; - // Both one-pass and two-pass RC are supported now. - // User setting this has to make sure of the following. - // In two-pass setting: either (but not both) - // cfg->ss_number_layers > 1, or cfg->ts_number_layers > 1 - // In one-pass setting: - // either or both cfg->ss_number_layers > 1, or cfg->ts_number_layers > 1 - - vp9_set_svc(ctx->cpi, data); - + // SVC is only supported for one-pass. if (data == 1 && - (cfg->g_pass == VPX_RC_FIRST_PASS || cfg->g_pass == VPX_RC_LAST_PASS) && - cfg->ss_number_layers > 1 && cfg->ts_number_layers > 1) { + (cfg->g_pass == VPX_RC_FIRST_PASS || cfg->g_pass == VPX_RC_LAST_PASS)) { return VPX_CODEC_INVALID_PARAM; } - + vp9_set_svc(ctx->cpi, data); vp9_set_row_mt(ctx->cpi); - return VPX_CODEC_OK; } @@ -1710,6 +1902,28 @@ static vpx_codec_err_t ctrl_set_svc_layer_id(vpx_codec_alg_priv_t *ctx, VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi; SVC *const svc = &cpi->svc; int sl; + // Checks on valid spatial_layer_id input. + if (data->spatial_layer_id < 0 || + data->spatial_layer_id >= (int)ctx->cfg.ss_number_layers) { + return VPX_CODEC_INVALID_PARAM; + } + // Validate temporal_layer_id and every temporal_layer_id_per_spatial[] + // entry before storing any of them. Both are later used to index + // svc.layer_context[] (VPX_MAX_LAYERS entries) in + // vp9_one_pass_svc_start_layer(); an out-of-range value causes an + // out-of-bounds access during encoding. Validating up front also leaves + // svc unchanged when the input is rejected. + if (data->temporal_layer_id < 0 || + data->temporal_layer_id >= (int)ctx->cfg.ts_number_layers) { + return VPX_CODEC_INVALID_PARAM; + } + for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) { + if (data->temporal_layer_id_per_spatial[sl] < 0 || + data->temporal_layer_id_per_spatial[sl] >= + (int)ctx->cfg.ts_number_layers) { + return VPX_CODEC_INVALID_PARAM; + } + } svc->spatial_layer_to_encode = data->spatial_layer_id; svc->first_spatial_layer_to_encode = data->spatial_layer_id; @@ -1720,11 +1934,6 @@ static vpx_codec_err_t ctrl_set_svc_layer_id(vpx_codec_alg_priv_t *ctx, svc->temporal_layer_id_per_spatial[sl] = data->temporal_layer_id_per_spatial[sl]; } - // Checks on valid layer_id input. - if (svc->temporal_layer_id < 0 || - svc->temporal_layer_id >= (int)ctx->cfg.ts_number_layers) { - return VPX_CODEC_INVALID_PARAM; - } return VPX_CODEC_OK; } @@ -1754,8 +1963,20 @@ static vpx_codec_err_t ctrl_set_svc_parameters(vpx_codec_alg_priv_t *ctx, const int layer = LAYER_IDS_TO_IDX(sl, tl, cpi->svc.number_temporal_layers); LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer]; + if (params->max_quantizers[layer] < 0 || + params->max_quantizers[layer] > 63 || + params->min_quantizers[layer] < 0 || + params->min_quantizers[layer] > params->max_quantizers[layer]) { + return VPX_CODEC_INVALID_PARAM; + } lc->max_q = params->max_quantizers[layer]; lc->min_q = params->min_quantizers[layer]; + // Checks on valid scale factors. + if (params->scaling_factor_num[sl] < 1 || + params->scaling_factor_den[sl] < 1 || + (params->scaling_factor_num[sl] > params->scaling_factor_den[sl])) { + return VPX_CODEC_INVALID_PARAM; + } lc->scaling_factor_num = params->scaling_factor_num[sl]; lc->scaling_factor_den = params->scaling_factor_den[sl]; lc->speed = params->speed_per_layer[sl]; @@ -1792,6 +2013,13 @@ static vpx_codec_err_t ctrl_set_svc_ref_frame_config(vpx_codec_alg_priv_t *ctx, VP9_COMP *const cpi = ctx->cpi; vpx_svc_ref_frame_config_t *data = va_arg(args, vpx_svc_ref_frame_config_t *); int sl; + for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) { + if (data->lst_fb_idx[sl] < 0 || data->lst_fb_idx[sl] >= REF_FRAMES || + data->gld_fb_idx[sl] < 0 || data->gld_fb_idx[sl] >= REF_FRAMES || + data->alt_fb_idx[sl] < 0 || data->alt_fb_idx[sl] >= REF_FRAMES) { + return VPX_CODEC_INVALID_PARAM; + } + } cpi->svc.use_set_ref_frame_config = 1; for (sl = 0; sl < cpi->svc.number_spatial_layers; ++sl) { cpi->svc.update_buffer_slot[sl] = data->update_buffer_slot[sl]; @@ -1803,6 +2031,7 @@ static vpx_codec_err_t ctrl_set_svc_ref_frame_config(vpx_codec_alg_priv_t *ctx, cpi->svc.alt_fb_idx[sl] = data->alt_fb_idx[sl]; cpi->svc.duration[sl] = data->duration[sl]; } + cpi->svc.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS; return VPX_CODEC_OK; } @@ -1851,7 +2080,7 @@ static vpx_codec_err_t ctrl_set_delta_q_uv(vpx_codec_alg_priv_t *ctx, va_list args) { struct vp9_extracfg extra_cfg = ctx->extra_cfg; int data = va_arg(args, int); - data = VPXMIN(VPXMAX(data, -15), 15); + data = clamp(data, -15, 15); extra_cfg.delta_q_uv = data; return update_extra_cfg(ctx, &extra_cfg); } @@ -1926,21 +2155,35 @@ static vpx_codec_err_t ctrl_set_external_rate_control(vpx_codec_alg_priv_t *ctx, VP9_COMP *cpi = ctx->cpi; EXT_RATECTRL *ext_ratectrl = &cpi->ext_ratectrl; const VP9EncoderConfig *oxcf = &cpi->oxcf; - // TODO(angiebird): Check the possibility of this flag being set at pass == 1 if (oxcf->pass == 2) { const FRAME_INFO *frame_info = &cpi->frame_info; vpx_rc_config_t ratectrl_config; vpx_codec_err_t codec_status; + memset(&ratectrl_config, 0, sizeof(ratectrl_config)); ratectrl_config.frame_width = frame_info->frame_width; ratectrl_config.frame_height = frame_info->frame_height; ratectrl_config.show_frame_count = cpi->twopass.first_pass_info.num_frames; - + ratectrl_config.max_gf_interval = oxcf->max_gf_interval; + ratectrl_config.min_gf_interval = oxcf->min_gf_interval; // TODO(angiebird): Double check whether this is the proper way to set up // target_bitrate and frame_rate. ratectrl_config.target_bitrate_kbps = (int)(oxcf->target_bandwidth / 1000); ratectrl_config.frame_rate_num = oxcf->g_timebase.den; ratectrl_config.frame_rate_den = oxcf->g_timebase.num; + ratectrl_config.overshoot_percent = oxcf->over_shoot_pct; + ratectrl_config.undershoot_percent = oxcf->under_shoot_pct; + ratectrl_config.min_base_q_index = oxcf->best_allowed_q; + ratectrl_config.max_base_q_index = oxcf->worst_allowed_q; + ratectrl_config.base_qp = oxcf->cq_level; + + if (oxcf->rc_mode == VPX_VBR) { + ratectrl_config.rc_mode = VPX_RC_VBR; + } else if (oxcf->rc_mode == VPX_Q) { + ratectrl_config.rc_mode = VPX_RC_QMODE; + } else if (oxcf->rc_mode == VPX_CQ) { + ratectrl_config.rc_mode = VPX_RC_CQ; + } codec_status = vp9_extrc_create(funcs, ratectrl_config, ext_ratectrl); if (codec_status != VPX_CODEC_OK) { @@ -1950,6 +2193,25 @@ static vpx_codec_err_t ctrl_set_external_rate_control(vpx_codec_alg_priv_t *ctx, return VPX_CODEC_OK; } +static vpx_codec_err_t ctrl_set_quantizer_one_pass(vpx_codec_alg_priv_t *ctx, + va_list args) { + VP9_COMP *const cpi = ctx->cpi; + const int qp = va_arg(args, int); + vpx_codec_enc_cfg_t *cfg = &ctx->cfg; + struct vp9_extracfg extra_cfg = ctx->extra_cfg; + vpx_codec_err_t res; + + if (cfg->g_pass != VPX_RC_ONE_PASS) return VPX_CODEC_INVALID_PARAM; + if (qp < 0 || qp > 63) return VPX_CODEC_INVALID_PARAM; + + cfg->rc_min_quantizer = cfg->rc_max_quantizer = qp; + extra_cfg.aq_mode = 0; + cpi->fixed_qp_onepass = 1; + + res = update_extra_cfg(ctx, &extra_cfg); + return res; +} + static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = { { VP8_COPY_REFERENCE, ctrl_copy_reference }, @@ -1966,6 +2228,8 @@ static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = { { VP9E_SET_TILE_COLUMNS, ctrl_set_tile_columns }, { VP9E_SET_TILE_ROWS, ctrl_set_tile_rows }, { VP9E_SET_TPL, ctrl_set_tpl_model }, + { VP9E_SET_KEY_FRAME_FILTERING, ctrl_set_keyframe_filtering }, + { VP9E_SET_VALIDATE_HBD_INPUT, ctrl_set_validate_hbd_input }, { VP8E_SET_ARNR_MAXFRAMES, ctrl_set_arnr_max_frames }, { VP8E_SET_ARNR_STRENGTH, ctrl_set_arnr_strength }, { VP8E_SET_ARNR_TYPE, ctrl_set_arnr_type }, @@ -2004,6 +2268,7 @@ static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = { { VP9E_SET_DISABLE_LOOPFILTER, ctrl_set_disable_loopfilter }, { VP9E_SET_RTC_EXTERNAL_RATECTRL, ctrl_set_rtc_external_ratectrl }, { VP9E_SET_EXTERNAL_RATE_CONTROL, ctrl_set_external_rate_control }, + { VP9E_SET_QUANTIZER_ONE_PASS, ctrl_set_quantizer_one_pass }, // Getters { VP8E_GET_LAST_QUANTIZER, ctrl_get_quantizer }, @@ -2044,8 +2309,8 @@ static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = { 0, // rc_resize_allowed 0, // rc_scaled_width 0, // rc_scaled_height - 60, // rc_resize_down_thresold - 30, // rc_resize_up_thresold + 60, // rc_resize_down_thresh + 30, // rc_resize_up_thresh VPX_VBR, // rc_end_usage { NULL, 0 }, // rc_twopass_stats_in @@ -2078,7 +2343,7 @@ static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = { { 0 }, // ts_rate_decimator 0, // ts_periodicity { 0 }, // ts_layer_id - { 0 }, // layer_taget_bitrate + { 0 }, // layer_target_bitrate 0, // temporal_layering_mode 0, // use_vizier_rc_params { 1, 1 }, // active_wq_factor @@ -2122,14 +2387,15 @@ CODEC_INTERFACE(vpx_codec_vp9_cx) = { }, { // NOLINT - 1, // 1 cfg map - encoder_usage_cfg_map, // vpx_codec_enc_cfg_map_t - encoder_encode, // vpx_codec_encode_fn_t - encoder_get_cxdata, // vpx_codec_get_cx_data_fn_t - encoder_set_config, // vpx_codec_enc_config_set_fn_t - NULL, // vpx_codec_get_global_headers_fn_t - encoder_get_preview, // vpx_codec_get_preview_frame_fn_t - NULL // vpx_codec_enc_mr_get_mem_loc_fn_t + 1, // 1 cfg map + encoder_usage_cfg_map, // vpx_codec_enc_cfg_map_t + encoder_encode, // vpx_codec_encode_fn_t + encoder_get_cxdata, // vpx_codec_get_cx_data_fn_t + encoder_set_config, // vpx_codec_enc_config_set_fn_t + encoder_get_global_headers, // vpx_codec_get_global_headers_fn_t + encoder_get_preview, // vpx_codec_get_preview_frame_fn_t + NULL, // vpx_codec_enc_mr_get_mem_loc_fn_t + NULL // vpx_codec_enc_mr_free_mem_loc_fn_t } }; @@ -2148,7 +2414,7 @@ static vpx_codec_enc_cfg_t get_enc_cfg(int frame_width, int frame_height, return enc_cfg; } -static vp9_extracfg get_extra_cfg() { +static vp9_extracfg get_extra_cfg(void) { vp9_extracfg extra_cfg = default_extra_cfg; return extra_cfg; } @@ -2313,6 +2579,8 @@ void vp9_dump_encoder_config(const VP9EncoderConfig *oxcf, FILE *fp) { DUMP_STRUCT_VALUE(fp, oxcf, enable_tpl_model); + DUMP_STRUCT_VALUE(fp, oxcf, enable_keyframe_filtering); + DUMP_STRUCT_VALUE(fp, oxcf, max_threads); DUMP_STRUCT_VALUE(fp, oxcf, target_level); @@ -2332,7 +2600,6 @@ void vp9_dump_encoder_config(const VP9EncoderConfig *oxcf, FILE *fp) { DUMP_STRUCT_VALUE(fp, oxcf, row_mt); DUMP_STRUCT_VALUE(fp, oxcf, motion_vector_unit_test); DUMP_STRUCT_VALUE(fp, oxcf, delta_q_uv); - DUMP_STRUCT_VALUE(fp, oxcf, use_simple_encode_api); } FRAME_INFO vp9_get_frame_info(const VP9EncoderConfig *oxcf) { diff --git a/libs/libvpx/vp9/vp9_dx_iface.c b/libs/libvpx/vp9/vp9_dx_iface.c index 3c42c7dfed..bad1135950 100644 --- a/libs/libvpx/vp9/vp9_dx_iface.c +++ b/libs/libvpx/vp9/vp9_dx_iface.c @@ -19,7 +19,6 @@ #include "vpx/vpx_decoder.h" #include "vpx_dsp/bitreader_buffer.h" #include "vpx_dsp/vpx_dsp_common.h" -#include "vpx_util/vpx_thread.h" #include "vp9/common/vp9_alloccommon.h" #include "vp9/common/vp9_frame_buffers.h" @@ -256,6 +255,7 @@ static void set_ppflags(const vpx_codec_alg_priv_t *ctx, vp9_ppflags_t *flags) { } while (0) static vpx_codec_err_t init_decoder(vpx_codec_alg_priv_t *ctx) { + vpx_codec_err_t res; ctx->last_show_frame = -1; ctx->need_resync = 1; ctx->flushed = 0; @@ -265,6 +265,8 @@ static vpx_codec_err_t init_decoder(vpx_codec_alg_priv_t *ctx) { ctx->pbi = vp9_decoder_create(ctx->buffer_pool); if (ctx->pbi == NULL) { + vpx_free(ctx->buffer_pool); + ctx->buffer_pool = NULL; set_error_detail(ctx, "Failed to allocate decoder"); return VPX_CODEC_MEM_ERROR; } @@ -282,7 +284,14 @@ static vpx_codec_err_t init_decoder(vpx_codec_alg_priv_t *ctx) { if (!ctx->postproc_cfg_set && (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) set_default_ppflags(&ctx->postproc_cfg); - return init_buffer_callbacks(ctx); + res = init_buffer_callbacks(ctx); + if (res != VPX_CODEC_OK) { + vpx_free(ctx->buffer_pool); + ctx->buffer_pool = NULL; + vp9_decoder_remove(ctx->pbi); + ctx->pbi = NULL; + } + return res; } static INLINE void check_resync(vpx_codec_alg_priv_t *const ctx, @@ -295,9 +304,7 @@ static INLINE void check_resync(vpx_codec_alg_priv_t *const ctx, static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, const uint8_t **data, unsigned int data_sz, - void *user_priv, int64_t deadline) { - (void)deadline; - + void *user_priv) { // Determine the stream parameters. Note that we rely on peek_si to // validate that we have a buffer that does not wrap around the top // of the heap. @@ -332,9 +339,8 @@ static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx, const uint8_t *data, unsigned int data_sz, - void *user_priv, long deadline) { + void *user_priv) { const uint8_t *data_start = data; - const uint8_t *const data_end = data + data_sz; vpx_codec_err_t res; uint32_t frame_sizes[8]; int frame_count; @@ -349,7 +355,7 @@ static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx, // Initialize the decoder on the first frame. if (ctx->pbi == NULL) { - const vpx_codec_err_t res = init_decoder(ctx); + res = init_decoder(ctx); if (res != VPX_CODEC_OK) return res; } @@ -362,27 +368,27 @@ static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx, // Decode in serial mode. if (frame_count > 0) { + const uint8_t *const data_end = data + data_sz; int i; for (i = 0; i < frame_count; ++i) { const uint8_t *data_start_copy = data_start; const uint32_t frame_size = frame_sizes[i]; - vpx_codec_err_t res; if (data_start < data || frame_size > (uint32_t)(data_end - data_start)) { set_error_detail(ctx, "Invalid frame size in index"); return VPX_CODEC_CORRUPT_FRAME; } - res = decode_one(ctx, &data_start_copy, frame_size, user_priv, deadline); + res = decode_one(ctx, &data_start_copy, frame_size, user_priv); if (res != VPX_CODEC_OK) return res; data_start += frame_size; } } else { + const uint8_t *const data_end = data + data_sz; while (data_start < data_end) { const uint32_t frame_size = (uint32_t)(data_end - data_start); - const vpx_codec_err_t res = - decode_one(ctx, &data_start, frame_size, user_priv, deadline); + res = decode_one(ctx, &data_start, frame_size, user_priv); if (res != VPX_CODEC_OK) return res; // Account for suboptimal termination by the encoder. @@ -448,7 +454,15 @@ static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx, if (data) { vpx_ref_frame_t *const frame = (vpx_ref_frame_t *)data; YV12_BUFFER_CONFIG sd; + + if (frame->img.planes[VPX_PLANE_Y] == NULL || + frame->img.planes[VPX_PLANE_U] == NULL || + frame->img.planes[VPX_PLANE_V] == NULL) { + return VPX_CODEC_INVALID_PARAM; + } + image2yuvconfig(&frame->img, &sd); + if (!ctx->pbi) return VPX_CODEC_ERROR; return vp9_set_reference_dec( &ctx->pbi->common, ref_frame_to_vp9_reframe(frame->frame_type), &sd); } else { @@ -463,7 +477,15 @@ static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx, if (data) { vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; YV12_BUFFER_CONFIG sd; + + if (frame->img.planes[VPX_PLANE_Y] == NULL || + frame->img.planes[VPX_PLANE_U] == NULL || + frame->img.planes[VPX_PLANE_V] == NULL) { + return VPX_CODEC_INVALID_PARAM; + } + image2yuvconfig(&frame->img, &sd); + if (!ctx->pbi) return VPX_CODEC_ERROR; return vp9_copy_reference_dec(ctx->pbi, (VP9_REFFRAME)frame->frame_type, &sd); } else { @@ -731,6 +753,7 @@ CODEC_INTERFACE(vpx_codec_vp9_dx) = { NULL, // vpx_codec_enc_config_set_fn_t NULL, // vpx_codec_get_global_headers_fn_t NULL, // vpx_codec_get_preview_frame_fn_t - NULL // vpx_codec_enc_mr_get_mem_loc_fn_t + NULL, // vpx_codec_enc_mr_get_mem_loc_fn_t + NULL // vpx_codec_enc_mr_free_mem_loc_fn_t } }; diff --git a/libs/libvpx/vp9/vp9_iface_common.c b/libs/libvpx/vp9/vp9_iface_common.c index 8d031694d8..9527cc5625 100644 --- a/libs/libvpx/vp9/vp9_iface_common.c +++ b/libs/libvpx/vp9/vp9_iface_common.c @@ -7,6 +7,7 @@ * All contributing project authors may be found in the AUTHORS file in * the root of the source tree. */ +#include #include "vp9/vp9_iface_common.h" void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12, @@ -36,8 +37,8 @@ void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12, img->cs = yv12->color_space; img->range = yv12->color_range; img->bit_depth = 8; - img->w = yv12->y_stride; - img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9_ENC_BORDER_IN_PIXELS, 3); + img->w = yv12->y_width; + img->h = yv12->y_height; img->d_w = yv12->y_crop_width; img->d_h = yv12->y_crop_height; img->r_w = yv12->render_width; @@ -85,18 +86,19 @@ vpx_codec_err_t image2yuvconfig(const vpx_image_t *img, yv12->y_crop_height = img->d_h; yv12->render_width = img->r_w; yv12->render_height = img->r_h; - yv12->y_width = img->d_w; - yv12->y_height = img->d_h; + yv12->y_width = img->w; + yv12->y_height = img->h; - yv12->uv_width = img->x_chroma_shift == 1 || img->fmt == VPX_IMG_FMT_NV12 - ? (1 + yv12->y_width) / 2 - : yv12->y_width; + yv12->uv_width = (yv12->y_width + img->x_chroma_shift) >> img->x_chroma_shift; yv12->uv_height = - img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2 : yv12->y_height; - yv12->uv_crop_width = yv12->uv_width; - yv12->uv_crop_height = yv12->uv_height; + (yv12->y_height + img->y_chroma_shift) >> img->y_chroma_shift; + yv12->uv_crop_width = + (yv12->y_crop_width + img->x_chroma_shift) >> img->x_chroma_shift; + yv12->uv_crop_height = + (yv12->y_crop_height + img->y_chroma_shift) >> img->y_chroma_shift; yv12->y_stride = img->stride[VPX_PLANE_Y]; + assert(img->stride[VPX_PLANE_U] == img->stride[VPX_PLANE_V]); yv12->uv_stride = img->stride[VPX_PLANE_U]; yv12->color_space = img->cs; yv12->color_range = img->range; @@ -122,15 +124,9 @@ vpx_codec_err_t image2yuvconfig(const vpx_image_t *img, } else { yv12->flags = 0; } - yv12->border = (yv12->y_stride - img->w) / 2; -#else - yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2; #endif // CONFIG_VP9_HIGHBITDEPTH + yv12->border = 0; yv12->subsampling_x = img->x_chroma_shift; yv12->subsampling_y = img->y_chroma_shift; - // When reading the data, UV are in one plane for NV12 format, thus - // x_chroma_shift is 0. After converting, UV are in separate planes, and - // subsampling_x should be set to 1. - if (img->fmt == VPX_IMG_FMT_NV12) yv12->subsampling_x = 1; return VPX_CODEC_OK; } diff --git a/libs/libvpx/vp9/vp9cx.mk b/libs/libvpx/vp9/vp9cx.mk index 92a7fddb9d..bd0cc84608 100644 --- a/libs/libvpx/vp9/vp9cx.mk +++ b/libs/libvpx/vp9/vp9cx.mk @@ -40,6 +40,7 @@ VP9_CX_SRCS-yes += encoder/vp9_encodemb.h VP9_CX_SRCS-yes += encoder/vp9_encodemv.h VP9_CX_SRCS-yes += encoder/vp9_extend.h VP9_CX_SRCS-yes += encoder/vp9_firstpass.h +VP9_CX_SRCS-yes += encoder/vp9_firstpass_stats.h VP9_CX_SRCS-yes += encoder/vp9_frame_scale.c VP9_CX_SRCS-yes += encoder/vp9_job_queue.h VP9_CX_SRCS-yes += encoder/vp9_lookahead.c @@ -104,25 +105,36 @@ VP9_CX_SRCS-$(CONFIG_INTERNAL_STATS) += common/vp9_postproc.c endif VP9_CX_SRCS-yes += encoder/vp9_temporal_filter.c VP9_CX_SRCS-yes += encoder/vp9_temporal_filter.h +VP9_CX_SRCS-yes += encoder/vp9_tpl_model.c +VP9_CX_SRCS-yes += encoder/vp9_tpl_model.h VP9_CX_SRCS-yes += encoder/vp9_mbgraph.c VP9_CX_SRCS-yes += encoder/vp9_mbgraph.h +VP9_CX_SRCS-$(HAVE_SSSE3) += encoder/x86/temporal_filter_ssse3.c VP9_CX_SRCS-$(HAVE_SSE4_1) += encoder/x86/temporal_filter_sse4.c -VP9_CX_SRCS-$(HAVE_SSE4_1) += encoder/x86/temporal_filter_constants.h +VP9_CX_SRCS-$(HAVE_AVX2) += encoder/x86/temporal_filter_avx2.c +VP9_CX_SRCS-$(HAVE_SSE4_1) += encoder/vp9_temporal_filter_constants.h +VP9_CX_SRCS-$(HAVE_NEON) += encoder/arm/neon/vp9_temporal_filter_neon.c +VP9_CX_SRCS-$(HAVE_NEON) += encoder/vp9_temporal_filter_constants.h +VP9_CX_SRCS-$(HAVE_NEON_DOTPROD) += encoder/arm/neon/vp9_temporal_filter_neon_dotprod.c +VP9_CX_SRCS-$(HAVE_NEON_I8MM) += encoder/arm/neon/vp9_temporal_filter_neon_i8mm.c VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_quantize_sse2.c +VP9_CX_SRCS-$(HAVE_SSSE3) += encoder/x86/vp9_quantize_ssse3.c VP9_CX_SRCS-$(HAVE_AVX2) += encoder/x86/vp9_quantize_avx2.c -VP9_CX_SRCS-$(HAVE_AVX) += encoder/x86/vp9_diamond_search_sad_avx.c +VP9_CX_SRCS-$(HAVE_NEON) += encoder/arm/neon/vp9_diamond_search_sad_neon.c ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes) VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_highbd_block_error_intrin_sse2.c +VP9_CX_SRCS-$(HAVE_SSSE3) += encoder/x86/highbd_temporal_filter_ssse3.c VP9_CX_SRCS-$(HAVE_SSE4_1) += encoder/x86/highbd_temporal_filter_sse4.c +VP9_CX_SRCS-$(HAVE_AVX2) += encoder/x86/highbd_temporal_filter_avx2.c +VP9_CX_SRCS-$(HAVE_NEON) += encoder/arm/neon/vp9_highbd_temporal_filter_neon.c +VP9_CX_SRCS-$(HAVE_SVE2) += encoder/arm/neon/vp9_highbd_temporal_filter_sve2.c endif +ifeq ($(HAVE_X86_ASM),yes) VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_dct_sse2.asm VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_error_sse2.asm - -ifeq ($(VPX_ARCH_X86_64),yes) -VP9_CX_SRCS-$(HAVE_SSSE3) += encoder/x86/vp9_quantize_ssse3_x86_64.asm endif VP9_CX_SRCS-$(HAVE_SSE2) += encoder/x86/vp9_dct_intrin_sse2.c @@ -136,11 +148,13 @@ endif VP9_CX_SRCS-$(HAVE_AVX2) += encoder/x86/vp9_error_avx2.c -ifneq ($(CONFIG_VP9_HIGHBITDEPTH),yes) VP9_CX_SRCS-$(HAVE_NEON) += encoder/arm/neon/vp9_error_neon.c -endif +VP9_CX_SRCS-$(HAVE_SVE) += encoder/arm/neon/vp9_error_sve.c VP9_CX_SRCS-$(HAVE_NEON) += encoder/arm/neon/vp9_frame_scale_neon.c VP9_CX_SRCS-$(HAVE_NEON) += encoder/arm/neon/vp9_quantize_neon.c +ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes) +VP9_CX_SRCS-$(HAVE_NEON) += encoder/arm/neon/vp9_highbd_error_neon.c +endif VP9_CX_SRCS-$(HAVE_MSA) += encoder/mips/msa/vp9_error_msa.c @@ -157,9 +171,18 @@ VP9_CX_SRCS-$(HAVE_VSX) += encoder/ppc/vp9_quantize_vsx.c VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/vp9_firstpass.c VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/vp9_mbgraph.c VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/vp9_temporal_filter.c +VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/x86/temporal_filter_ssse3.c VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/x86/temporal_filter_sse4.c -VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/x86/temporal_filter_constants.h +VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/x86/temporal_filter_avx2.c +VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/vp9_temporal_filter_constants.h +VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/x86/highbd_temporal_filter_ssse3.c VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/x86/highbd_temporal_filter_sse4.c +VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/x86/highbd_temporal_filter_avx2.c +VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/arm/neon/vp9_temporal_filter_neon.c +VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/arm/neon/vp9_temporal_filter_neon_dotprod.c +VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/arm/neon/vp9_temporal_filter_neon_i8mm.c +VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/arm/neon/vp9_highbd_temporal_filter_neon.c +VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/arm/neon/vp9_highbd_temporal_filter_sve2.c VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/vp9_alt_ref_aq.h VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/vp9_alt_ref_aq.c VP9_CX_SRCS_REMOVE-$(CONFIG_REALTIME_ONLY) += encoder/vp9_aq_variance.c diff --git a/libs/libvpx/vpx/internal/vpx_codec_internal.h b/libs/libvpx/vpx/internal/vpx_codec_internal.h index 670fe380ed..ff51881eea 100644 --- a/libs/libvpx/vpx/internal/vpx_codec_internal.h +++ b/libs/libvpx/vpx/internal/vpx_codec_internal.h @@ -48,6 +48,8 @@ #include "../vpx_encoder.h" #include +#include "vpx_config.h" + #ifdef __cplusplus extern "C" { #endif @@ -196,8 +198,7 @@ typedef const struct vpx_codec_ctrl_fn_map { typedef vpx_codec_err_t (*vpx_codec_decode_fn_t)(vpx_codec_alg_priv_t *ctx, const uint8_t *data, unsigned int data_sz, - void *user_priv, - long deadline); + void *user_priv); /*!\brief Decoded frames iterator * @@ -253,7 +254,7 @@ typedef vpx_codec_err_t (*vpx_codec_encode_fn_t)(vpx_codec_alg_priv_t *ctx, vpx_codec_pts_t pts, unsigned long duration, vpx_enc_frame_flags_t flags, - unsigned long deadline); + vpx_enc_deadline_t deadline); typedef const vpx_codec_cx_pkt_t *(*vpx_codec_get_cx_data_fn_t)( vpx_codec_alg_priv_t *ctx, vpx_codec_iter_t *iter); @@ -268,6 +269,8 @@ typedef vpx_image_t *(*vpx_codec_get_preview_frame_fn_t)( typedef vpx_codec_err_t (*vpx_codec_enc_mr_get_mem_loc_fn_t)( const vpx_codec_enc_cfg_t *cfg, void **mem_loc); +typedef void (*vpx_codec_enc_mr_free_mem_loc_fn_t)(void *mem_loc); + /*!\brief usage configuration mapping * * This structure stores the mapping between usage identifiers and @@ -317,6 +320,8 @@ struct vpx_codec_iface { get_preview; /**< \copydoc ::vpx_codec_get_preview_frame_fn_t */ vpx_codec_enc_mr_get_mem_loc_fn_t mr_get_mem_loc; /**< \copydoc ::vpx_codec_enc_mr_get_mem_loc_fn_t */ + vpx_codec_enc_mr_free_mem_loc_fn_t + mr_free_mem_loc; /**< \copydoc ::vpx_codec_enc_mr_free_mem_loc_fn_t */ } enc; }; @@ -427,6 +432,27 @@ struct vpx_internal_error_info { jmp_buf jmp; }; +#if CONFIG_DEBUG +#define CHECK_MEM_ERROR(error, lval, expr) \ + do { \ + assert((error)->setjmp); \ + (lval) = (expr); \ + if (!(lval)) \ + vpx_internal_error(error, VPX_CODEC_MEM_ERROR, \ + "Failed to allocate " #lval " at %s:%d", __FILE__, \ + __LINE__); \ + } while (0) +#else +#define CHECK_MEM_ERROR(error, lval, expr) \ + do { \ + assert((error)->setjmp); \ + (lval) = (expr); \ + if (!(lval)) \ + vpx_internal_error(error, VPX_CODEC_MEM_ERROR, \ + "Failed to allocate " #lval); \ + } while (0) +#endif + #define CLANG_ANALYZER_NORETURN #if defined(__has_feature) #if __has_feature(attribute_analyzer_noreturn) diff --git a/libs/libvpx/vpx/internal/vpx_ratectrl_rtc.h b/libs/libvpx/vpx/internal/vpx_ratectrl_rtc.h index 65398c654d..2643b5578a 100644 --- a/libs/libvpx/vpx/internal/vpx_ratectrl_rtc.h +++ b/libs/libvpx/vpx/internal/vpx_ratectrl_rtc.h @@ -14,8 +14,22 @@ #include "vpx/vpx_encoder.h" namespace libvpx { + +enum class RcFrameType { kKeyFrame = 0, kInterFrame = 1 }; + +enum class FrameDropDecision { + kOk, // Frame is encoded. + kDrop, // Frame is dropped. +}; + +struct UVDeltaQP { + // For the UV channel: the QP for the dc/ac value is given as + // GetQP() + uvdc/ac_delta_q, where the uvdc/ac_delta_q are negative numbers. + int uvdc_delta_q; + int uvac_delta_q; +}; + struct VpxRateControlRtcConfig { - public: VpxRateControlRtcConfig() { width = 1280; height = 720; @@ -34,6 +48,8 @@ struct VpxRateControlRtcConfig { aq_mode = 0; layer_target_bitrate[0] = static_cast(target_bandwidth); ts_rate_decimator[0] = 1; + frame_drop_thresh = 0; + is_screen = false; } int width; @@ -57,6 +73,8 @@ struct VpxRateControlRtcConfig { // vbr, cbr enum vpx_rc_mode rc_mode; int aq_mode; + int frame_drop_thresh; + bool is_screen; }; } // namespace libvpx #endif // VPX_VPX_INTERNAL_VPX_RATECTRL_RTC_H_ diff --git a/libs/libvpx/vpx/src/vpx_codec.c b/libs/libvpx/vpx/src/vpx_codec.c index 114b94e194..c54a18ecd4 100644 --- a/libs/libvpx/vpx/src/vpx_codec.c +++ b/libs/libvpx/vpx/src/vpx_codec.c @@ -13,6 +13,7 @@ * */ #include +#include #include #include "vpx/vpx_integer.h" #include "vpx/internal/vpx_codec_internal.h" @@ -50,12 +51,12 @@ const char *vpx_codec_err_to_string(vpx_codec_err_t err) { return "Unrecognized error code"; } -const char *vpx_codec_error(vpx_codec_ctx_t *ctx) { +const char *vpx_codec_error(const vpx_codec_ctx_t *ctx) { return (ctx) ? vpx_codec_err_to_string(ctx->err) : vpx_codec_err_to_string(VPX_CODEC_INVALID_PARAM); } -const char *vpx_codec_error_detail(vpx_codec_ctx_t *ctx) { +const char *vpx_codec_error_detail(const vpx_codec_ctx_t *ctx) { if (ctx && ctx->err) return ctx->priv ? ctx->priv->err_detail : ctx->err_detail; @@ -82,7 +83,7 @@ vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx) { } vpx_codec_caps_t vpx_codec_get_caps(vpx_codec_iface_t *iface) { - return (iface) ? iface->caps : 0; + return iface ? iface->caps : 0; } vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t *ctx, int ctrl_id, ...) { diff --git a/libs/libvpx/vpx/src/vpx_decoder.c b/libs/libvpx/vpx/src/vpx_decoder.c index 427cd1bf43..c79cc708cd 100644 --- a/libs/libvpx/vpx/src/vpx_decoder.c +++ b/libs/libvpx/vpx/src/vpx_decoder.c @@ -105,6 +105,7 @@ vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, const uint8_t *data, unsigned int data_sz, void *user_priv, long deadline) { vpx_codec_err_t res; + (void)deadline; /* Sanity checks */ /* NULL data ptr allowed if data_sz is 0 too */ @@ -112,10 +113,8 @@ vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, const uint8_t *data, res = VPX_CODEC_INVALID_PARAM; else if (!ctx->iface || !ctx->priv) res = VPX_CODEC_ERROR; - else { - res = ctx->iface->dec.decode(get_alg_priv(ctx), data, data_sz, user_priv, - deadline); - } + else + res = ctx->iface->dec.decode(get_alg_priv(ctx), data, data_sz, user_priv); return SAVE_STATUS(ctx, res); } diff --git a/libs/libvpx/vpx/src/vpx_encoder.c b/libs/libvpx/vpx/src/vpx_encoder.c index 846638fe55..f2b8b9f6a5 100644 --- a/libs/libvpx/vpx/src/vpx_encoder.c +++ b/libs/libvpx/vpx/src/vpx_encoder.c @@ -14,10 +14,10 @@ */ #include #include -#include +#include #include -#include "vp8/common/blockd.h" #include "vpx_config.h" +#include "vpx/vpx_encoder.h" #include "vpx/internal/vpx_codec_internal.h" #define SAVE_STATUS(ctx, var) ((ctx) ? ((ctx)->err = (var)) : (var)) @@ -54,6 +54,10 @@ vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, res = ctx->iface->init(ctx, NULL); if (res) { + // IMPORTANT: ctx->priv->err_detail must be null or point to a string + // that remains valid after ctx->priv is destroyed, such as a C string + // literal. This makes it safe to call vpx_codec_error_detail() after + // vpx_codec_enc_init_ver() failed. ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL; vpx_codec_destroy(ctx); } @@ -63,13 +67,14 @@ vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, } vpx_codec_err_t vpx_codec_enc_init_multi_ver( - vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg, - int num_enc, vpx_codec_flags_t flags, vpx_rational_t *dsf, int ver) { + vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, + const vpx_codec_enc_cfg_t *cfg, int num_enc, vpx_codec_flags_t flags, + const vpx_rational_t *dsf, int ver) { vpx_codec_err_t res = VPX_CODEC_OK; if (ver != VPX_ENCODER_ABI_VERSION) res = VPX_CODEC_ABI_MISMATCH; - else if (!ctx || !iface || !cfg || (num_enc > 16 || num_enc < 1)) + else if (!ctx || !iface || !cfg || (num_enc > 16 || num_enc < 1) || !dsf) res = VPX_CODEC_INVALID_PARAM; else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION) res = VPX_CODEC_ABI_MISMATCH; @@ -85,7 +90,7 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver( #if CONFIG_MULTI_RES_ENCODING int mem_loc_owned = 0; #endif - void *mem_loc = NULL; + void *mem_loc; if (iface->enc.mr_get_mem_loc == NULL) return VPX_CODEC_INCAPABLE; @@ -101,14 +106,16 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver( mr_cfg.mr_low_res_mode_info = mem_loc; mr_cfg.mr_total_resolutions = num_enc; mr_cfg.mr_encoder_id = num_enc - 1 - i; - mr_cfg.mr_down_sampling_factor.num = dsf->num; - mr_cfg.mr_down_sampling_factor.den = dsf->den; + mr_cfg.mr_down_sampling_factor = *dsf; ctx->iface = iface; ctx->name = iface->name; ctx->priv = NULL; ctx->init_flags = flags; ctx->config.enc = cfg; + // ctx takes ownership of mr_cfg.mr_low_res_mode_info if and only if + // this call succeeds. The first ctx entry in the array is + // responsible for freeing the memory. res = ctx->iface->init(ctx, &mr_cfg); } @@ -128,8 +135,7 @@ vpx_codec_err_t vpx_codec_enc_init_multi_ver( #if CONFIG_MULTI_RES_ENCODING if (!mem_loc_owned) { assert(mem_loc); - free(((LOWER_RES_FRAME_INFO *)mem_loc)->mb_info); - free(mem_loc); + iface->enc.mr_free_mem_loc(mem_loc); } #endif return SAVE_STATUS(ctx, res); @@ -180,14 +186,14 @@ vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface, while (0) #else -static void FLOATING_POINT_INIT() {} -static void FLOATING_POINT_RESTORE() {} +static void FLOATING_POINT_INIT(void) {} +static void FLOATING_POINT_RESTORE(void) {} #endif vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img, vpx_codec_pts_t pts, unsigned long duration, vpx_enc_frame_flags_t flags, - unsigned long deadline) { + vpx_enc_deadline_t deadline) { vpx_codec_err_t res = VPX_CODEC_OK; if (!ctx || (img && !duration)) @@ -196,6 +202,10 @@ vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img, res = VPX_CODEC_ERROR; else if (!(ctx->iface->caps & VPX_CODEC_CAP_ENCODER)) res = VPX_CODEC_INCAPABLE; +#if ULONG_MAX > UINT32_MAX + else if (duration > UINT32_MAX || deadline > UINT32_MAX) + res = VPX_CODEC_INVALID_PARAM; +#endif else { unsigned int num_enc = ctx->priv->enc.total_encoders; @@ -226,7 +236,10 @@ vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img, ctx--; if (img) img--; } - ctx++; + // Only restore ctx to &ctx[0] when the loop ran to completion. If an + // iteration failed, ctx already points at the failing element; advancing + // it would point past the array when the first iteration failed. + if (i < 0) ctx++; } FLOATING_POINT_RESTORE(); diff --git a/libs/libvpx/vpx/src/vpx_image.c b/libs/libvpx/vpx/src/vpx_image.c index f9f0dd6025..e4dc1a18c0 100644 --- a/libs/libvpx/vpx/src/vpx_image.c +++ b/libs/libvpx/vpx/src/vpx_image.c @@ -8,7 +8,9 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include #include +#include #include #include @@ -16,17 +18,44 @@ #include "vpx/vpx_integer.h" #include "vpx_mem/vpx_mem.h" +static int is_valid_img_fmt(vpx_img_fmt_t fmt) { + switch (fmt) { + case VPX_IMG_FMT_YV12: + case VPX_IMG_FMT_I420: + case VPX_IMG_FMT_I422: + case VPX_IMG_FMT_I444: + case VPX_IMG_FMT_I440: + case VPX_IMG_FMT_NV12: + case VPX_IMG_FMT_I42016: + case VPX_IMG_FMT_I42216: + case VPX_IMG_FMT_I44416: + case VPX_IMG_FMT_I44016: return 1; + default: return 0; + } +} + static vpx_image_t *img_alloc_helper(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int buf_align, unsigned int stride_align, unsigned char *img_data) { - unsigned int h, w, s, xcs, ycs, bps; - unsigned int stride_in_bytes; + unsigned int h, w, xcs, ycs, bps; + uint64_t s; + int stride_in_bytes; unsigned int align; if (img != NULL) memset(img, 0, sizeof(vpx_image_t)); + if (!is_valid_img_fmt(fmt)) goto fail; + + /* Impose maximum values on input parameters so that this function can + * perform arithmetic operations without worrying about overflows. + */ + if (d_w > 0x08000000 || d_h > 0x08000000 || buf_align > 65536 || + stride_align > 65536) { + goto fail; + } + /* Treat align==0 like align==1 */ if (!buf_align) buf_align = 1; @@ -55,11 +84,10 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img, vpx_img_fmt_t fmt, } /* Get chroma shift values for this format */ - // For VPX_IMG_FMT_NV12, xcs needs to be 0 such that UV data is all read at - // one time. switch (fmt) { case VPX_IMG_FMT_I420: case VPX_IMG_FMT_YV12: + case VPX_IMG_FMT_NV12: case VPX_IMG_FMT_I422: case VPX_IMG_FMT_I42016: case VPX_IMG_FMT_I42216: xcs = 1; break; @@ -76,13 +104,35 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img, vpx_img_fmt_t fmt, default: ycs = 0; break; } - /* Calculate storage sizes. If the buffer was allocated externally, the width - * and height shouldn't be adjusted. */ - w = d_w; - h = d_h; - s = (fmt & VPX_IMG_FMT_PLANAR) ? w : bps * w / 8; - s = (s + stride_align - 1) & ~(stride_align - 1); - stride_in_bytes = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? s * 2 : s; + /* Calculate storage sizes. */ + if (img_data) { + /* If the buffer was allocated externally, the width and height shouldn't + * be adjusted. */ + w = d_w; + h = d_h; + } else { + /* Calculate storage sizes given the chroma subsampling */ + align = (1 << xcs) - 1; + w = (d_w + align) & ~align; + assert(d_w <= w); + align = (1 << ycs) - 1; + h = (d_h + align) & ~align; + assert(d_h <= h); + } + + s = (fmt & VPX_IMG_FMT_PLANAR) ? w : (uint64_t)bps * w / 8; + s = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? s * 2 : s; + s = (s + stride_align - 1) & ~((uint64_t)stride_align - 1); + if (s > INT_MAX) goto fail; + stride_in_bytes = (int)s; + uint64_t uv_s = s; + // Convert to number of samples. + uv_s = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? uv_s / 2 : uv_s; + // Apply chroma subsampling. + uv_s = (uv_s + xcs) >> xcs; + // Convert back to number of bytes. + uv_s = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? uv_s * 2 : uv_s; + const int uv_stride_in_bytes = (int)uv_s; /* Allocate the new image */ if (!img) { @@ -97,15 +147,7 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img, vpx_img_fmt_t fmt, if (!img_data) { uint64_t alloc_size; - /* Calculate storage sizes given the chroma subsampling */ - align = (1 << xcs) - 1; - w = (d_w + align) & ~align; - align = (1 << ycs) - 1; - h = (d_h + align) & ~align; - - s = (fmt & VPX_IMG_FMT_PLANAR) ? w : bps * w / 8; - s = (s + stride_align - 1) & ~(stride_align - 1); - stride_in_bytes = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? s * 2 : s; + s = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? s / 2 : s; alloc_size = (fmt & VPX_IMG_FMT_PLANAR) ? (uint64_t)h * s * bps / 8 : (uint64_t)h * s; @@ -127,10 +169,22 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img, vpx_img_fmt_t fmt, /* Calculate strides */ img->stride[VPX_PLANE_Y] = img->stride[VPX_PLANE_ALPHA] = stride_in_bytes; - img->stride[VPX_PLANE_U] = img->stride[VPX_PLANE_V] = stride_in_bytes >> xcs; + img->stride[VPX_PLANE_U] = img->stride[VPX_PLANE_V] = uv_stride_in_bytes; - /* Default viewport to entire image */ - if (!vpx_img_set_rect(img, 0, 0, d_w, d_h)) return img; + if (fmt == VPX_IMG_FMT_NV12) { + img->stride[VPX_PLANE_U] = img->stride[VPX_PLANE_V] = stride_in_bytes; + } + + if (fmt == VPX_IMG_FMT_NV12) { + img->stride[VPX_PLANE_U] = img->stride[VPX_PLANE_V] = stride_in_bytes; + } + + /* Default viewport to entire image. (This vpx_img_set_rect call always + * succeeds.) */ + int ret = vpx_img_set_rect(img, 0, 0, d_w, d_h); + assert(ret == 0); + (void)ret; + return img; fail: vpx_img_free(img); @@ -146,13 +200,15 @@ vpx_image_t *vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt, vpx_image_t *vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int stride_align, unsigned char *img_data) { - /* By setting buf_align = 1, we don't change buffer alignment in this - * function. */ + /* Set buf_align = 1. It is ignored by img_alloc_helper because img_data is + * not NULL. */ return img_alloc_helper(img, fmt, d_w, d_h, 1, stride_align, img_data); } int vpx_img_set_rect(vpx_image_t *img, unsigned int x, unsigned int y, unsigned int w, unsigned int h) { + if (img->stride[VPX_PLANE_Y] < 0) return -1; + if (x <= UINT_MAX - w && x + w <= img->w && y <= UINT_MAX - h && y + h <= img->h) { img->d_w = w; @@ -170,34 +226,33 @@ int vpx_img_set_rect(vpx_image_t *img, unsigned int x, unsigned int y, if (img->fmt & VPX_IMG_FMT_HAS_ALPHA) { img->planes[VPX_PLANE_ALPHA] = data + x * bytes_per_sample + y * img->stride[VPX_PLANE_ALPHA]; - data += img->h * img->stride[VPX_PLANE_ALPHA]; + data += (size_t)img->h * img->stride[VPX_PLANE_ALPHA]; } img->planes[VPX_PLANE_Y] = data + x * bytes_per_sample + y * img->stride[VPX_PLANE_Y]; - data += img->h * img->stride[VPX_PLANE_Y]; + data += (size_t)img->h * img->stride[VPX_PLANE_Y]; + unsigned int uv_x = x >> img->x_chroma_shift; + unsigned int uv_y = y >> img->y_chroma_shift; + const unsigned int uv_height = + (img->h + img->y_chroma_shift) >> img->y_chroma_shift; if (img->fmt == VPX_IMG_FMT_NV12) { - img->planes[VPX_PLANE_U] = - data + (x >> img->x_chroma_shift) + - (y >> img->y_chroma_shift) * img->stride[VPX_PLANE_U]; - img->planes[VPX_PLANE_V] = img->planes[VPX_PLANE_U] + 1; + img->planes[VPX_PLANE_U] = data + uv_x * bytes_per_sample * 2 + + uv_y * img->stride[VPX_PLANE_U]; + img->planes[VPX_PLANE_V] = img->planes[VPX_PLANE_U] + bytes_per_sample; } else if (!(img->fmt & VPX_IMG_FMT_UV_FLIP)) { img->planes[VPX_PLANE_U] = - data + (x >> img->x_chroma_shift) * bytes_per_sample + - (y >> img->y_chroma_shift) * img->stride[VPX_PLANE_U]; - data += (img->h >> img->y_chroma_shift) * img->stride[VPX_PLANE_U]; + data + uv_x * bytes_per_sample + uv_y * img->stride[VPX_PLANE_U]; + data += (size_t)uv_height * img->stride[VPX_PLANE_U]; img->planes[VPX_PLANE_V] = - data + (x >> img->x_chroma_shift) * bytes_per_sample + - (y >> img->y_chroma_shift) * img->stride[VPX_PLANE_V]; + data + uv_x * bytes_per_sample + uv_y * img->stride[VPX_PLANE_V]; } else { img->planes[VPX_PLANE_V] = - data + (x >> img->x_chroma_shift) * bytes_per_sample + - (y >> img->y_chroma_shift) * img->stride[VPX_PLANE_V]; - data += (img->h >> img->y_chroma_shift) * img->stride[VPX_PLANE_V]; + data + uv_x * bytes_per_sample + uv_y * img->stride[VPX_PLANE_V]; + data += (size_t)uv_height * img->stride[VPX_PLANE_V]; img->planes[VPX_PLANE_U] = - data + (x >> img->x_chroma_shift) * bytes_per_sample + - (y >> img->y_chroma_shift) * img->stride[VPX_PLANE_U]; + data + uv_x * bytes_per_sample + uv_y * img->stride[VPX_PLANE_U]; } } return 0; @@ -206,26 +261,28 @@ int vpx_img_set_rect(vpx_image_t *img, unsigned int x, unsigned int y, } void vpx_img_flip(vpx_image_t *img) { - /* Note: In the calculation pointer adjustment calculation, we want the - * rhs to be promoted to a signed type. Section 6.3.1.8 of the ISO C99 - * standard indicates that if the adjustment parameter is unsigned, the - * stride parameter will be promoted to unsigned, causing errors when - * the lhs is a larger type than the rhs. - */ - img->planes[VPX_PLANE_Y] += (signed)(img->d_h - 1) * img->stride[VPX_PLANE_Y]; + const unsigned int chroma_height = + (img->d_h + img->y_chroma_shift) >> img->y_chroma_shift; + + if (img->d_h == 0) return; + + img->planes[VPX_PLANE_Y] += + (ptrdiff_t)(img->d_h - 1) * img->stride[VPX_PLANE_Y]; img->stride[VPX_PLANE_Y] = -img->stride[VPX_PLANE_Y]; - img->planes[VPX_PLANE_U] += (signed)((img->d_h >> img->y_chroma_shift) - 1) * - img->stride[VPX_PLANE_U]; + img->planes[VPX_PLANE_U] += + (ptrdiff_t)(chroma_height - 1) * img->stride[VPX_PLANE_U]; img->stride[VPX_PLANE_U] = -img->stride[VPX_PLANE_U]; - img->planes[VPX_PLANE_V] += (signed)((img->d_h >> img->y_chroma_shift) - 1) * - img->stride[VPX_PLANE_V]; + img->planes[VPX_PLANE_V] += + (ptrdiff_t)(chroma_height - 1) * img->stride[VPX_PLANE_V]; img->stride[VPX_PLANE_V] = -img->stride[VPX_PLANE_V]; - img->planes[VPX_PLANE_ALPHA] += - (signed)(img->d_h - 1) * img->stride[VPX_PLANE_ALPHA]; - img->stride[VPX_PLANE_ALPHA] = -img->stride[VPX_PLANE_ALPHA]; + if (img->fmt & VPX_IMG_FMT_HAS_ALPHA) { + img->planes[VPX_PLANE_ALPHA] += + (ptrdiff_t)(img->d_h - 1) * img->stride[VPX_PLANE_ALPHA]; + img->stride[VPX_PLANE_ALPHA] = -img->stride[VPX_PLANE_ALPHA]; + } } void vpx_img_free(vpx_image_t *img) { diff --git a/libs/libvpx/vpx/vp8cx.h b/libs/libvpx/vpx/vp8cx.h index a61238cb10..3bc6e77167 100644 --- a/libs/libvpx/vpx/vp8cx.h +++ b/libs/libvpx/vpx/vp8cx.h @@ -166,6 +166,7 @@ enum vp8e_enc_control_id { * * \note Valid range for VP8: -16..16 * \note Valid range for VP9: -9..9 + * \note A negative value (-n) is treated as its absolute value (n) in VP9. * * Supported in codecs: VP8, VP9 */ @@ -302,7 +303,7 @@ enum vp8e_enc_control_id { * the feature is off, i.e., no golden frame boost in CBR mode and * average bitrate target is used. * - * For example, to allow 100% more bits, i.e, 2X, in a golden frame + * For example, to allow 100% more bits, i.e., 2X, in a golden frame * than average frame, set this to 100. * * Supported in codecs: VP9 @@ -598,7 +599,7 @@ enum vp8e_enc_control_id { * the feature is off, i.e., no golden frame boost in CBR mode and * average bitrate target is used. * - * For example, to allow 100% more bits, i.e, 2X, in a golden frame + * For example, to allow 100% more bits, i.e., 2X, in a golden frame * than average frame, set this to 100. * * Supported in codecs: VP8 @@ -672,7 +673,7 @@ enum vp8e_enc_control_id { */ VP9E_SET_TPL, - /*!\brief Codec control function to enable postencode frame drop. + /*!\brief Codec control function to enable post encode frame drop. * * This will allow encoder to drop frame after it's encoded. * @@ -757,6 +758,34 @@ enum vp8e_enc_control_id { * Supported in codecs: VP8 */ VP8E_SET_RTC_EXTERNAL_RATECTRL, + + /*!\brief Codec control to set quantizer for the next frame. + * + * This will turn off cyclic refresh. Only applicable to 1-pass without + * spatial layers. + * + * Supported in codecs: VP9 + * + */ + VP9E_SET_QUANTIZER_ONE_PASS, + + /*!\brief Codec control function to enable key frame temporal filtering. + * + * Vp9 allows the encoder to run key frame temporal filtering and use it to + * improve the compression performance. To enable, set this parameter to be + * 1. The default value is set to be 0. + */ + VP9E_SET_KEY_FRAME_FILTERING, + + /*!\brief Codec control function to validate HBD input, int parameter. + * + * VP9 allows the encoder to validate the high bitdepth (HBD) input and + * ensure that every pixel is within the valid range. To disable/enable, + * set this parameter to 0/1. The default value is set to be 1. + * + * Supported in codecs: VP9 + */ + VP9E_SET_VALIDATE_HBD_INPUT, }; /*!\brief vpx 1-D scaling mode @@ -783,8 +812,7 @@ typedef enum vp9e_temporal_layering_mode { VP9E_TEMPORAL_LAYERING_MODE_NOLAYERING = 0, /*!\brief Bypass mode. - * Used when application needs to control temporal layering. - * This will only work when the number of spatial layers equals 1. + * Used when application needs to control spatial and temporal layering. */ VP9E_TEMPORAL_LAYERING_MODE_BYPASS = 1, @@ -858,7 +886,7 @@ typedef enum { VP8_EIGHT_TOKENPARTITION = 3 } vp8e_token_partitions; -/*!brief VP9 encoder content type */ +/*!\brief VP9 encoder content type */ typedef enum { VP9E_CONTENT_DEFAULT, VP9E_CONTENT_SCREEN, @@ -1085,6 +1113,12 @@ VPX_CTRL_USE_TYPE(VP9E_GET_LAST_QUANTIZER_SVC_LAYERS, int *) #define VPX_CTRL_VP9E_GET_LAST_QUANTIZER_SVC_LAYERS VPX_CTRL_USE_TYPE(VP8E_SET_RTC_EXTERNAL_RATECTRL, int) #define VPX_CTRL_VP8E_SET_RTC_EXTERNAL_RATECTRL +VPX_CTRL_USE_TYPE(VP9E_SET_QUANTIZER_ONE_PASS, int) +#define VPX_CTRL_VP9E_SET_QUANTIZER_ONE_PASS +VPX_CTRL_USE_TYPE(VP9E_SET_KEY_FRAME_FILTERING, int) +#define VPX_CTRL_VP9E_SET_KEY_FRAME_FILTERING +VPX_CTRL_USE_TYPE(VP9E_SET_VALIDATE_HBD_INPUT, int) +#define VPX_CTRL_VP9E_SET_VALIDATE_HBD_INPUT /*!\endcond */ /*! @} - end defgroup vp8_encoder */ diff --git a/libs/libvpx/vpx/vp8dx.h b/libs/libvpx/vpx/vp8dx.h index 8c13649f4a..49e67172a7 100644 --- a/libs/libvpx/vpx/vp8dx.h +++ b/libs/libvpx/vpx/vp8dx.h @@ -75,7 +75,12 @@ enum vp8_dec_control_id { */ VP8D_GET_LAST_REF_UPDATES = VP8_DECODER_CTRL_ID_START, - /** check if the indicated frame is corrupted */ + /** check if the last decoded frame is corrupted. For VP8, + * vpx_codec_decode() may return VPX_CODEC_OK for a corrupted frame, so this + * must be checked after every decode. This happens when data is missing + * from the last token partition, whose size is implicit, or when the frame + * references a corrupted frame. + */ VP8D_GET_FRAME_CORRUPTED, /** control function to get info on which reference frames were used diff --git a/libs/libvpx/vpx/vpx_codec.h b/libs/libvpx/vpx/vpx_codec.h index b0a931e019..602889773d 100644 --- a/libs/libvpx/vpx/vpx_codec.h +++ b/libs/libvpx/vpx/vpx_codec.h @@ -50,7 +50,7 @@ extern "C" { /*!\brief Decorator indicating a function is deprecated */ #ifndef VPX_DEPRECATED -#if defined(__GNUC__) && __GNUC__ +#if defined(__GNUC__) #define VPX_DEPRECATED __attribute__((deprecated)) #elif defined(_MSC_VER) #define VPX_DEPRECATED @@ -60,7 +60,7 @@ extern "C" { #endif /* VPX_DEPRECATED */ #ifndef VPX_DECLSPEC_DEPRECATED -#if defined(__GNUC__) && __GNUC__ +#if defined(__GNUC__) #define VPX_DECLSPEC_DEPRECATED /**< \copydoc #VPX_DEPRECATED */ #elif defined(_MSC_VER) /*!\brief \copydoc #VPX_DEPRECATED */ @@ -318,19 +318,21 @@ const char *vpx_codec_err_to_string(vpx_codec_err_t err); * \param[in] ctx Pointer to this instance's context. * */ -const char *vpx_codec_error(vpx_codec_ctx_t *ctx); +const char *vpx_codec_error(const vpx_codec_ctx_t *ctx); /*!\brief Retrieve detailed error information for codec context * * Returns a human readable string providing detailed information about - * the last error. + * the last error. The returned string is only valid until the next + * vpx_codec_* function call (except vpx_codec_error and + * vpx_codec_error_detail) on the codec context. * * \param[in] ctx Pointer to this instance's context. * * \retval NULL * No detailed information is available. */ -const char *vpx_codec_error_detail(vpx_codec_ctx_t *ctx); +const char *vpx_codec_error_detail(const vpx_codec_ctx_t *ctx); /* REQUIRED FUNCTIONS * @@ -345,9 +347,11 @@ const char *vpx_codec_error_detail(vpx_codec_ctx_t *ctx); * \param[in] ctx Pointer to this instance's context * * \retval #VPX_CODEC_OK - * The codec algorithm initialized. - * \retval #VPX_CODEC_MEM_ERROR - * Memory allocation failed. + * The codec instance has been destroyed. + * \retval #VPX_CODEC_INVALID_PARAM + * ctx is a null pointer. + * \retval #VPX_CODEC_ERROR + * Codec context not initialized. */ vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx); diff --git a/libs/libvpx/vpx/vpx_codec.mk b/libs/libvpx/vpx/vpx_codec.mk index de86579d58..778f1a6146 100644 --- a/libs/libvpx/vpx/vpx_codec.mk +++ b/libs/libvpx/vpx/vpx_codec.mk @@ -24,9 +24,10 @@ API_DOC_SRCS-$(CONFIG_VP8_DECODER) += vp8dx.h API_DOC_SRCS-yes += vpx_codec.h API_DOC_SRCS-yes += vpx_decoder.h API_DOC_SRCS-yes += vpx_encoder.h -API_DOC_SRCS-yes += vpx_ext_ratectrl.h +API_DOC_SRCS-$(CONFIG_ENCODERS) += vpx_ext_ratectrl.h API_DOC_SRCS-yes += vpx_frame_buffer.h API_DOC_SRCS-yes += vpx_image.h +API_DOC_SRCS-$(CONFIG_ENCODERS) += vpx_tpl.h API_SRCS-yes += src/vpx_decoder.c API_SRCS-yes += vpx_decoder.h @@ -42,3 +43,4 @@ API_SRCS-yes += vpx_frame_buffer.h API_SRCS-yes += vpx_image.h API_SRCS-yes += vpx_integer.h API_SRCS-yes += vpx_ext_ratectrl.h +API_SRCS-yes += vpx_tpl.h diff --git a/libs/libvpx/vpx/vpx_decoder.h b/libs/libvpx/vpx/vpx_decoder.h index 39e5f585f6..911ffaa52c 100644 --- a/libs/libvpx/vpx/vpx_decoder.h +++ b/libs/libvpx/vpx/vpx_decoder.h @@ -29,7 +29,7 @@ extern "C" { #endif -#include "./vpx_codec.h" +#include "./vpx_codec.h" // IWYU pragma: export #include "./vpx_frame_buffer.h" /*!\brief Current ABI version number @@ -60,7 +60,7 @@ extern "C" { #define VPX_CODEC_CAP_INPUT_FRAGMENTS 0x100000 /*!\brief Can support frame-based multi-threading */ #define VPX_CODEC_CAP_FRAME_THREADING 0x200000 -/*!brief Can support external frame buffers */ +/*!\brief Can support external frame buffers */ #define VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER 0x400000 /*! \brief Initialization-time Feature Enabling @@ -120,6 +120,10 @@ typedef struct vpx_codec_dec_cfg { * is not thread safe and should be guarded with a lock if being used * in a multithreaded context. * + * On success, vpx_codec_destroy() must be used to free resources allocated for + * the decoder context. If vpx_codec_dec_init_ver() fails, it is not necessary + * to call vpx_codec_destroy() on the decoder context. + * * \param[in] ctx Pointer to this instance's context. * \param[in] iface Pointer to the algorithm interface to use. * \param[in] cfg Configuration to use, if known. May be NULL. @@ -127,7 +131,7 @@ typedef struct vpx_codec_dec_cfg { * \param[in] ver ABI version number. Must be set to * VPX_DECODER_ABI_VERSION * \retval #VPX_CODEC_OK - * The decoder algorithm initialized. + * The decoder algorithm has been initialized. * \retval #VPX_CODEC_MEM_ERROR * Memory allocation failed. */ @@ -152,7 +156,7 @@ vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx, * \param[in] iface Pointer to the algorithm interface * \param[in] data Pointer to a block of data to parse * \param[in] data_sz Size of the data buffer - * \param[in,out] si Pointer to stream info to update. The size member + * \param[in,out] si Pointer to stream info to update. The sz member * \ref MUST be properly initialized, but \ref MAY be * clobbered by the algorithm. This parameter \ref MAY * be NULL. @@ -170,7 +174,7 @@ vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface, * Returns information about the stream that has been parsed during decoding. * * \param[in] ctx Pointer to this instance's context - * \param[in,out] si Pointer to stream info to update. The size member + * \param[in,out] si Pointer to stream info to update. The sz member * \ref MUST be properly initialized, but \ref MAY be * clobbered by the algorithm. This parameter \ref MAY * be NULL. @@ -205,6 +209,8 @@ vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx, * this frame. * \param[in] deadline Soft deadline the decoder should attempt to meet, * in us. Set to zero for unlimited. + * NOTE: The deadline parameter is ignored. Always + * pass 0. * * \return Returns #VPX_CODEC_OK if the coded data was processed completely * and future pictures can be decoded without error. Otherwise, diff --git a/libs/libvpx/vpx/vpx_encoder.h b/libs/libvpx/vpx/vpx_encoder.h index 21254bb547..2671fb3b76 100644 --- a/libs/libvpx/vpx/vpx_encoder.h +++ b/libs/libvpx/vpx/vpx_encoder.h @@ -29,7 +29,7 @@ extern "C" { #endif -#include "./vpx_codec.h" +#include "./vpx_codec.h" // IWYU pragma: export #include "./vpx_ext_ratectrl.h" /*! Temporal Scalability: Maximum length of the sequence defining frame @@ -56,9 +56,14 @@ extern "C" { * must be bumped. Examples include, but are not limited to, changing * types, removing or reassigning enums, adding/removing/rearranging * fields to structures + * + * \note + * VPX_ENCODER_ABI_VERSION has a VPX_EXT_RATECTRL_ABI_VERSION component + * because the VP9E_SET_EXTERNAL_RATE_CONTROL codec control uses + * vpx_rc_funcs_t. */ #define VPX_ENCODER_ABI_VERSION \ - (15 + VPX_CODEC_ABI_VERSION + \ + (18 + VPX_CODEC_ABI_VERSION + \ VPX_EXT_RATECTRL_ABI_VERSION) /**<\hideinitializer*/ /*! \brief Encoder capabilities bitfield @@ -115,14 +120,14 @@ typedef int64_t vpx_codec_pts_t; * support frame types that are codec specific (MPEG-1 D-frames for example) */ typedef uint32_t vpx_codec_frame_flags_t; -#define VPX_FRAME_IS_KEY 0x1 /**< frame is the start of a GOP */ +#define VPX_FRAME_IS_KEY 0x1u /**< frame is the start of a GOP */ /*!\brief frame can be dropped without affecting the stream (no future frame * depends on this one) */ -#define VPX_FRAME_IS_DROPPABLE 0x2 +#define VPX_FRAME_IS_DROPPABLE 0x2u /*!\brief frame should be decoded but will not be shown */ -#define VPX_FRAME_IS_INVISIBLE 0x4 +#define VPX_FRAME_IS_INVISIBLE 0x4u /*!\brief this is a fragment of the encoded frame */ -#define VPX_FRAME_IS_FRAGMENT 0x8 +#define VPX_FRAME_IS_FRAGMENT 0x8u /*!\brief Error Resilient flags * @@ -132,12 +137,13 @@ typedef uint32_t vpx_codec_frame_flags_t; */ typedef uint32_t vpx_codec_er_flags_t; /*!\brief Improve resiliency against losses of whole frames */ -#define VPX_ERROR_RESILIENT_DEFAULT 0x1 +#define VPX_ERROR_RESILIENT_DEFAULT 0x1u /*!\brief The frame partitions are independently decodable by the bool decoder, * meaning that partitions can be decoded even though earlier partitions have * been lost. Note that intra prediction is still done over the partition - * boundary. */ -#define VPX_ERROR_RESILIENT_PARTITIONS 0x2 + * boundary. + * \note This is only supported by VP8.*/ +#define VPX_ERROR_RESILIENT_PARTITIONS 0x2u /*!\brief Encoder output packet variants * @@ -187,6 +193,7 @@ typedef struct vpx_codec_cx_pkt { unsigned int samples[4]; /**< Number of samples, total/y/u/v */ uint64_t sse[4]; /**< sum squared error, total/y/u/v */ double psnr[4]; /**< PSNR, total/y/u/v */ + int spatial_layer_id; /**< Spatial layer id */ } psnr; /**< data for PSNR packet */ vpx_fixed_buf_t raw; /**< data for arbitrary packets */ @@ -260,6 +267,8 @@ enum vpx_kf_mode { */ typedef long vpx_enc_frame_flags_t; #define VPX_EFLAG_FORCE_KF (1 << 0) /**< Force this frame to be a keyframe */ +/** Calculate PSNR on this frame, requires g_lag_in_frames to be 0 */ +#define VPX_EFLAG_CALCULATE_PSNR (1 << 1) /*!\brief Encoder configuration structure * @@ -322,11 +331,15 @@ typedef struct vpx_codec_enc_cfg { */ vpx_bit_depth_t g_bit_depth; - /*!\brief Bit-depth of the input frames + /*!\brief Bit-depth of the input source * - * This value identifies the bit_depth of the input frames in bits. - * Note that the frames passed as input to the encoder must have - * this bit-depth. + * This value identifies the actual bit-depth of the input source in bits. It + * must not exceed codec bit-depth. Note that the frames passed as input to + * the encoder must match codec bit-depth. So, if there is a mismatch between + * source bit-depth and codec bit-depth, the application is required to + * upshift the frame to the codec bit-depth before passing it for encoding. + * This is only used for computing quality metrics relative to the actual + * input source and has no effect on the encoder's output. */ unsigned int g_input_bit_depth; @@ -458,6 +471,8 @@ typedef struct vpx_codec_enc_cfg { /*!\brief Target data rate * * Target bitrate to use for this stream, in kilobits per second. + * Internally capped to the smaller of the uncompressed bitrate and + * 1000000 kilobits per second. */ unsigned int rc_target_bitrate; @@ -857,7 +872,7 @@ typedef struct vpx_svc_parameters { /*!\brief Initialize an encoder instance * - * Initializes a encoder context using the given interface. Applications + * Initializes an encoder context using the given interface. Applications * should call the vpx_codec_enc_init convenience macro instead of this * function directly, to ensure that the ABI version number parameter * is properly initialized. @@ -866,9 +881,13 @@ typedef struct vpx_svc_parameters { * is not thread safe and should be guarded with a lock if being used * in a multithreaded context. * + * On success, vpx_codec_destroy() must be used to free resources allocated for + * the encoder context. If vpx_codec_enc_init_ver() fails, it is not necessary + * to call vpx_codec_destroy() on the encoder context. + * * \param[in] ctx Pointer to this instance's context. * \param[in] iface Pointer to the algorithm interface to use. - * \param[in] cfg Configuration to use, if known. May be NULL. + * \param[in] cfg Configuration to use. * \param[in] flags Bitfield of VPX_CODEC_USE_* flags * \param[in] ver ABI version number. Must be set to * VPX_ENCODER_ABI_VERSION @@ -891,27 +910,32 @@ vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, /*!\brief Initialize multi-encoder instance * - * Initializes multi-encoder context using the given interface. + * Initializes multiple encoder contexts using the given interface. * Applications should call the vpx_codec_enc_init_multi convenience macro * instead of this function directly, to ensure that the ABI version number * parameter is properly initialized. * - * \param[in] ctx Pointer to this instance's context. + * \param[in] ctx Pointer to an array of num_enc instances' contexts. * \param[in] iface Pointer to the algorithm interface to use. - * \param[in] cfg Configuration to use, if known. May be NULL. + * \param[in] cfg An array of num_enc configurations to use. * \param[in] num_enc Total number of encoders. * \param[in] flags Bitfield of VPX_CODEC_USE_* flags - * \param[in] dsf Pointer to down-sampling factors. + * \param[in] dsf Pointer to an array of num_enc down-sampling factors. * \param[in] ver ABI version number. Must be set to * VPX_ENCODER_ABI_VERSION * \retval #VPX_CODEC_OK - * The decoder algorithm initialized. + * The encoder algorithm has been initialized. * \retval #VPX_CODEC_MEM_ERROR * Memory allocation failed. + * + * \note + * This is only supported by VP8. iface must point to the interface to the VP8 + * encoder. */ vpx_codec_err_t vpx_codec_enc_init_multi_ver( - vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg, - int num_enc, vpx_codec_flags_t flags, vpx_rational_t *dsf, int ver); + vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, + const vpx_codec_enc_cfg_t *cfg, int num_enc, vpx_codec_flags_t flags, + const vpx_rational_t *dsf, int ver); /*!\brief Convenience macro for vpx_codec_enc_init_multi_ver() * @@ -965,21 +989,36 @@ vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx, * * Retrieves a stream level global header packet, if supported by the codec. * + * \li VP8: Unsupported + * \li VP9: Returns a buffer of ID (1 byte)|Length (1 byte)|Length + * bytes values. The function should be called after encoding to retrieve + * the most accurate information. + * * \param[in] ctx Pointer to this instance's context * * \retval NULL * Encoder does not support global header * \retval Non-NULL - * Pointer to buffer containing global header packet + * Pointer to buffer containing global header packet. The buffer pointer + * and its contents are only valid for the lifetime of \a ctx. The contents + * may change in subsequent calls to the function. + * \sa + * https://www.webmproject.org/docs/container/#vp9-codec-feature-metadata-codecprivate */ vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx); +/*!\brief Encode Deadline + * + * This type indicates a deadline, in microseconds, to be passed to + * vpx_codec_encode(). + */ +typedef unsigned long vpx_enc_deadline_t; /*!\brief deadline parameter analogous to VPx REALTIME mode. */ -#define VPX_DL_REALTIME (1) +#define VPX_DL_REALTIME 1ul /*!\brief deadline parameter analogous to VPx GOOD QUALITY mode. */ -#define VPX_DL_GOOD_QUALITY (1000000) +#define VPX_DL_GOOD_QUALITY 1000000ul /*!\brief deadline parameter analogous to VPx BEST QUALITY mode. */ -#define VPX_DL_BEST_QUALITY (0) +#define VPX_DL_BEST_QUALITY 0ul /*!\brief Encode a frame * * Encodes a video frame at the given "presentation time." The presentation @@ -1004,6 +1043,8 @@ vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx); * * \param[in] ctx Pointer to this instance's context * \param[in] img Image data to encode, NULL to flush. + * Encoding sample values outside the range + * [0..(1<bit_depth)-1] is undefined behavior. * \param[in] pts Presentation time stamp, in timebase units. * \param[in] duration Duration to show frame, in timebase units. * \param[in] flags Flags to use for encoding this frame. @@ -1019,7 +1060,7 @@ vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx); vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img, vpx_codec_pts_t pts, unsigned long duration, vpx_enc_frame_flags_t flags, - unsigned long deadline); + vpx_enc_deadline_t deadline); /*!\brief Set compressed data output buffer * @@ -1063,6 +1104,12 @@ vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img, * The buffer was set successfully. * \retval #VPX_CODEC_INVALID_PARAM * A parameter was NULL, the image format is unsupported, etc. + * + * \note + * `duration` and `deadline` are of the unsigned long type, which can be 32 + * or 64 bits. `duration` and `deadline` must be less than or equal to + * UINT32_MAX so that their ranges are independent of the size of unsigned + * long. */ vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx, const vpx_fixed_buf_t *buf, diff --git a/libs/libvpx/vpx/vpx_ext_ratectrl.h b/libs/libvpx/vpx/vpx_ext_ratectrl.h index a193e55953..1c502f8101 100644 --- a/libs/libvpx/vpx/vpx_ext_ratectrl.h +++ b/libs/libvpx/vpx/vpx_ext_ratectrl.h @@ -8,6 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ +/*!\file + * \brief Defines structs and callbacks needed for external rate control. + * + */ #ifndef VPX_VPX_VPX_EXT_RATECTRL_H_ #define VPX_VPX_VPX_EXT_RATECTRL_H_ @@ -16,6 +20,7 @@ extern "C" { #endif #include "./vpx_integer.h" +#include "./vpx_tpl.h" /*!\brief Current ABI version number * @@ -25,34 +30,137 @@ extern "C" { * types, removing or reassigning enums, adding/removing/rearranging * fields to structures. */ -#define VPX_EXT_RATECTRL_ABI_VERSION (1) +#define VPX_EXT_RATECTRL_ABI_VERSION (7 + VPX_TPL_ABI_VERSION) + +/*!\brief Corresponds to MAX_STATIC_GF_GROUP_LENGTH defined in vp9_ratectrl.h + */ +#define VPX_RC_MAX_STATIC_GF_GROUP_LENGTH 250 + +/*!\brief Max number of ref frames returned by the external RC. + * + * Corresponds to MAX_REF_FRAMES defined in vp9_blockd.h. + */ +#define VPX_RC_MAX_REF_FRAMES 4 + +/*!\brief The type of the external rate control. + * + * This controls what encoder parameters are determined by the external rate + * control. + */ +typedef enum vpx_rc_type { + /*! + * The external rate control doesn't determine anything. + * This mode is used as baseline. + */ + VPX_RC_NONE = 0, + /*! + * The external rate control model determines the quantization parameter (QP) + * for each frame. + */ + VPX_RC_QP = 1 << 0, + /*! + * The external rate control model determines the group of picture (GOP) of + * the video sequence. + */ + VPX_RC_GOP = 1 << 1, + /*! + * The external rate control model determines the rate-distortion multiplier + * (rdmult) for the current frame. + */ + VPX_RC_RDMULT = 1 << 2, + /*! + * The external rate control model determines both QP and GOP. + */ + VPX_RC_GOP_QP = VPX_RC_QP | VPX_RC_GOP, + /*! + * The external rate control model determines the QP, GOP and the rdmult. + */ + VPX_RC_GOP_QP_RDMULT = VPX_RC_QP | VPX_RC_GOP | VPX_RC_RDMULT +} vpx_rc_type_t; + +/*!\brief The rate control mode for the external rate control model. + */ +typedef enum vpx_ext_rc_mode { + VPX_RC_QMODE = 0, + VPX_RC_VBR = 1, + VPX_RC_CQ = 2, +} vpx_ext_rc_mode_t; + +/*!\brief Corresponds to FRAME_UPDATE_TYPE defined in vp9_firstpass.h. + */ +typedef enum vpx_rc_frame_update_type { + VPX_RC_INVALID_UPDATE_TYPE = -1, + VPX_RC_KF_UPDATE = 0, + VPX_RC_LF_UPDATE = 1, + VPX_RC_GF_UPDATE = 2, + VPX_RC_ARF_UPDATE = 3, + VPX_RC_OVERLAY_UPDATE = 4, + VPX_RC_MID_OVERLAY_UPDATE = 5, + VPX_RC_USE_BUF_FRAME = 6, +} vpx_rc_frame_update_type_t; + +/*!\brief Name for the ref frames returned by the external RC. + * + * Corresponds to the ref frames defined in vp9_blockd.h. + */ +typedef enum vpx_rc_ref_name { + VPX_RC_INVALID_REF_FRAME = -1, + VPX_RC_INTRA_FRAME = 0, + VPX_RC_LAST_FRAME = 1, + VPX_RC_GOLDEN_FRAME = 2, + VPX_RC_ALTREF_FRAME = 3, +} vpx_rc_ref_name_t; /*!\brief Abstract rate control model handler * - * The encoder will receive the model handler from create_model() defined in - * vpx_rc_funcs_t. + * The encoder will receive the model handler from + * vpx_rc_funcs_t::create_model(). */ typedef void *vpx_rc_model_t; +/*!\brief A reserved value for the q index. + * If the external rate control model returns this value, + * the encoder will use the default q selected by libvpx's rate control + * system. + */ +#define VPX_DEFAULT_Q -1 + +/*!\brief A reserved value for the rdmult. + * If the external rate control model returns this value, + * the encoder will use the default rdmult selected by libvpx's rate control + * system. + */ +#define VPX_DEFAULT_RDMULT -1 + +/*!\brief Superblock quantization parameters + * Store the superblock quantization parameters + */ +typedef struct sb_parameters { + int q_index; /**< Quantizer step index [0..255]*/ + int rdmult; /**< Superblock level Lagrangian multiplier*/ +} sb_params; + /*!\brief Encode frame decision made by the external rate control model * * The encoder will receive the decision from the external rate control model - * through get_encodeframe_decision() defined in vpx_rc_funcs_t. - * - * If max_frame_size = 0, the encoding ignores max frame size limit. - * If max_frame_size = -1, the encoding uses VP9's max frame size as the limit. - * If the encoded frame size is larger than max_frame_size, the frame is - * recoded to meet the size limit, following VP9's recoding principles. + * through vpx_rc_funcs_t::get_encodeframe_decision(). */ typedef struct vpx_rc_encodeframe_decision { - int q_index; /**< Quantizer step index [0..255]*/ - int max_frame_size; /**< Maximal frame size allowed to encode a frame*/ + int q_index; /**< Required: Quantizer step index [0..255]*/ + int rdmult; /**< Required: Frame level Lagrangian multiplier*/ + int delta_q_uv; /**< Required: Delta QP for UV */ + /*! + * Optional: Superblock quantization parameters + * It is zero initialized by default. It will be set for key and ARF frames + * but not leaf frames. + */ + sb_params *sb_params_list; } vpx_rc_encodeframe_decision_t; /*!\brief Information for the frame to be encoded. * * The encoder will send the information to external rate control model through - * get_encodeframe_decision() defined in vpx_rc_funcs_t. + * vpx_rc_funcs_t::get_encodeframe_decision(). * */ typedef struct vpx_rc_encodeframe_info { @@ -67,7 +175,7 @@ typedef struct vpx_rc_encodeframe_info { int show_index; /**< display index, starts from zero*/ int coding_index; /**< coding index, starts from zero*/ /*! - * index in group of picture, starts from zero. + * index of the current frame in this group of picture, starts from zero. */ int gop_index; int ref_frame_coding_indexes[3]; /**< three reference frames' coding indices*/ @@ -77,17 +185,23 @@ typedef struct vpx_rc_encodeframe_info { * 1: Valid */ int ref_frame_valid_list[3]; + /*! + * The length of the current GOP. + */ + int gop_size; + /*! + * Whether the current GOP uses an alt ref. + */ + int use_alt_ref; } vpx_rc_encodeframe_info_t; /*!\brief Frame coding result * * The encoder will send the result to the external rate control model through - * update_encodeframe_result() defined in vpx_rc_funcs_t. + * vpx_rc_funcs_t::update_encodeframe_result(). */ typedef struct vpx_rc_encodeframe_result { - int64_t sse; /**< sum of squared error of the reconstructed frame */ - int64_t bit_count; /**< number of bits spent on coding the frame*/ - int64_t pixel_count; /**< number of pixels in YUV planes of the frame*/ + int64_t bit_count; /**< number of bits spent on coding the frame*/ int actual_encoding_qindex; /**< the actual qindex used to encode the frame*/ } vpx_rc_encodeframe_result_t; @@ -227,6 +341,10 @@ typedef struct vpx_rc_frame_stats { * number of frames whose stats are accumulated. */ double count; + /*! + * Number of new mv in a frame. + */ + double new_mv_count; } vpx_rc_frame_stats_t; /*!\brief Collection of first pass frame stats @@ -250,26 +368,81 @@ typedef struct vpx_rc_config { int frame_width; /**< frame width */ int frame_height; /**< frame height */ int show_frame_count; /**< number of visible frames in the video */ + int max_gf_interval; /**< max GOP size in number of show frames */ + int min_gf_interval; /**< min GOP size in number of show frames */ /*! * Target bitrate in kilobytes per second */ int target_bitrate_kbps; int frame_rate_num; /**< numerator of frame rate */ int frame_rate_den; /**< denominator of frame rate */ + /*! + * The following fields are only for external rate control models that support + * different rate control modes. + */ + vpx_ext_rc_mode_t rc_mode; /**< Q mode or VBR mode */ + int overshoot_percent; /**< for VBR mode only */ + int undershoot_percent; /**< for VBR mode only */ + int min_base_q_index; /**< for VBR mode only */ + int max_base_q_index; /**< for VBR mode only */ + int base_qp; /**< base QP for leaf frames, 0-255 */ } vpx_rc_config_t; +/*!\brief Control what ref frame to use and its index. + */ +typedef struct vpx_rc_ref_frame { + /*! + * Ref frame index. Corresponding to |lst_fb_idx|, |gld_fb_idx| or + * |alt_fb_idx| in VP9_COMP depending on the ref frame #name. + */ + int index[VPX_RC_MAX_REF_FRAMES]; + /*! + * Ref frame name. This decides whether the #index is used as + * |lst_fb_idx|, |gld_fb_idx| or |alt_fb_idx| in VP9_COMP. + * + */ + vpx_rc_ref_name_t name[VPX_RC_MAX_REF_FRAMES]; +} vpx_rc_ref_frame_t; + +/*!\brief The decision made by the external rate control model to set the + * group of picture. + */ +typedef struct vpx_rc_gop_decision { + int gop_coding_frames; /**< The number of frames of this GOP */ + int use_alt_ref; /**< Whether to use alt ref for this GOP */ + int use_key_frame; /**< Whether to set key frame for this GOP */ + /*! + * Frame type for each frame in this GOP. + * This will be populated to |update_type| in GF_GROUP defined in + * vp9_firstpass.h + */ + vpx_rc_frame_update_type_t update_type[VPX_RC_MAX_STATIC_GF_GROUP_LENGTH + 2]; + /*! Ref frame buffer index to be updated for each frame in this GOP. */ + int update_ref_index[VPX_RC_MAX_STATIC_GF_GROUP_LENGTH + 2]; + /*! Ref frame list to be used for each frame in this GOP. */ + vpx_rc_ref_frame_t ref_frame_list[VPX_RC_MAX_STATIC_GF_GROUP_LENGTH + 2]; +} vpx_rc_gop_decision_t; + +/*!\brief The decision made by the external rate control model to set the + * key frame location and the show frame count in the key frame group + */ +typedef struct vpx_rc_key_frame_decision { + int key_frame_show_index; /**< This key frame's show index in the video */ + int key_frame_group_size; /**< Show frame count of this key frame group */ +} vpx_rc_key_frame_decision_t; + /*!\brief Create an external rate control model callback prototype * * This callback is invoked by the encoder to create an external rate control * model. * - * \param[in] priv Callback's private data - * \param[in] ratectrl_config Pointer to vpx_rc_config_t - * \param[out] rate_ctrl_model_pt Pointer to vpx_rc_model_t + * \param[in] priv Callback's private data + * \param[in] ratectrl_config Pointer to vpx_rc_config_t + * \param[out] rate_ctrl_model_ptr Pointer to vpx_rc_model_t */ typedef vpx_rc_status_t (*vpx_rc_create_model_cb_fn_t)( void *priv, const vpx_rc_config_t *ratectrl_config, - vpx_rc_model_t *rate_ctrl_model_pt); + vpx_rc_model_t *rate_ctrl_model_ptr); /*!\brief Send first pass stats to the external rate control model callback * prototype @@ -284,18 +457,29 @@ typedef vpx_rc_status_t (*vpx_rc_send_firstpass_stats_cb_fn_t)( vpx_rc_model_t rate_ctrl_model, const vpx_rc_firstpass_stats_t *first_pass_stats); +/*!\brief Send TPL stats for the current GOP to the external rate control model + * callback prototype + * + * This callback is invoked by the encoder to send TPL stats for the GOP to the + * external rate control model. + * + * \param[in] rate_ctrl_model rate control model + * \param[in] tpl_gop_stats TPL stats for current GOP + */ +typedef vpx_rc_status_t (*vpx_rc_send_tpl_gop_stats_cb_fn_t)( + vpx_rc_model_t rate_ctrl_model, const VpxTplGopStats *tpl_gop_stats); + /*!\brief Receive encode frame decision callback prototype * * This callback is invoked by the encoder to receive encode frame decision from * the external rate control model. * * \param[in] rate_ctrl_model rate control model - * \param[in] encode_frame_info information of the coding frame + * \param[in] frame_gop_index index of the frame in current gop * \param[out] frame_decision encode decision of the coding frame */ typedef vpx_rc_status_t (*vpx_rc_get_encodeframe_decision_cb_fn_t)( - vpx_rc_model_t rate_ctrl_model, - const vpx_rc_encodeframe_info_t *encode_frame_info, + vpx_rc_model_t rate_ctrl_model, const int frame_gop_index, vpx_rc_encodeframe_decision_t *frame_decision); /*!\brief Update encode frame result callback prototype @@ -310,6 +494,42 @@ typedef vpx_rc_status_t (*vpx_rc_update_encodeframe_result_cb_fn_t)( vpx_rc_model_t rate_ctrl_model, const vpx_rc_encodeframe_result_t *encode_frame_result); +/*!\brief Get the key frame decision from the external rate control model. + * + * This callback is invoked by the encoder to get key frame decision from + * the external rate control model. + * + * \param[in] rate_ctrl_model rate control model + * \param[out] key_frame_decision key frame decision from the model + */ +typedef vpx_rc_status_t (*vpx_rc_get_key_frame_decision_cb_fn_t)( + vpx_rc_model_t rate_ctrl_model, + vpx_rc_key_frame_decision_t *key_frame_decision); + +/*!\brief Get the GOP structure from the external rate control model. + * + * This callback is invoked by the encoder to get GOP decisions from + * the external rate control model. + * + * \param[in] rate_ctrl_model rate control model + * \param[out] gop_decision GOP decision from the model + */ +typedef vpx_rc_status_t (*vpx_rc_get_gop_decision_cb_fn_t)( + vpx_rc_model_t rate_ctrl_model, vpx_rc_gop_decision_t *gop_decision); + +/*!\brief Get the frame rdmult from the external rate control model. + * + * This callback is invoked by the encoder to get rdmult from + * the external rate control model. + * + * \param[in] rate_ctrl_model rate control model + * \param[in] frame_info information collected from the encoder + * \param[out] rdmult frame rate-distortion multiplier from the model + */ +typedef vpx_rc_status_t (*vpx_rc_get_frame_rdmult_cb_fn_t)( + vpx_rc_model_t rate_ctrl_model, const vpx_rc_encodeframe_info_t *frame_info, + int *rdmult); + /*!\brief Delete the external rate control model callback prototype * * This callback is invoked by the encoder to delete the external rate control @@ -324,9 +544,13 @@ typedef vpx_rc_status_t (*vpx_rc_delete_model_cb_fn_t)( * * The user can enable external rate control by registering * a set of callback functions with the codec control flag - * VP9E_SET_EXTERNAL_RATE_CONTROL. + * #VP9E_SET_EXTERNAL_RATE_CONTROL. */ typedef struct vpx_rc_funcs { + /*! + * The rate control type of this API. + */ + vpx_rc_type_t rc_type; /*! * Create an external rate control model. */ @@ -335,6 +559,10 @@ typedef struct vpx_rc_funcs { * Send first pass stats to the external rate control model. */ vpx_rc_send_firstpass_stats_cb_fn_t send_firstpass_stats; + /*! + * Send TPL stats for current GOP to the external rate control model. + */ + vpx_rc_send_tpl_gop_stats_cb_fn_t send_tpl_gop_stats; /*! * Get encodeframe decision from the external rate control model. */ @@ -343,10 +571,27 @@ typedef struct vpx_rc_funcs { * Update encodeframe result to the external rate control model. */ vpx_rc_update_encodeframe_result_cb_fn_t update_encodeframe_result; + /*! + * Get key frame decision from the external rate control model. + */ + vpx_rc_get_key_frame_decision_cb_fn_t get_key_frame_decision; + /*! + * Get GOP decisions from the external rate control model. + */ + vpx_rc_get_gop_decision_cb_fn_t get_gop_decision; + /*! + * Get rdmult for the frame from the external rate control model. + */ + vpx_rc_get_frame_rdmult_cb_fn_t get_frame_rdmult; /*! * Delete the external rate control model. */ vpx_rc_delete_model_cb_fn_t delete_model; + + /*! + * Rate control log path. + */ + const char *rate_ctrl_log_path; /*! * Private data for the external rate control model. */ diff --git a/libs/libvpx/vpx/vpx_image.h b/libs/libvpx/vpx/vpx_image.h index 1adc9b9d9e..bec72d4a08 100644 --- a/libs/libvpx/vpx/vpx_image.h +++ b/libs/libvpx/vpx/vpx_image.h @@ -64,8 +64,12 @@ typedef enum vpx_color_space { /*!\brief List of supported color range */ typedef enum vpx_color_range { - VPX_CR_STUDIO_RANGE = 0, /**< Y [16..235], UV [16..240] */ - VPX_CR_FULL_RANGE = 1 /**< YUV/RGB [0..255] */ + VPX_CR_STUDIO_RANGE = 0, /**<- Y [16..235], UV [16..240] (bit depth 8) */ + /**<- Y [64..940], UV [64..960] (bit depth 10) */ + /**<- Y [256..3760], UV [256..3840] (bit depth 12) */ + VPX_CR_FULL_RANGE = 1 /**<- YUV/RGB [0..255] (bit depth 8) */ + /**<- YUV/RGB [0..1023] (bit depth 10) */ + /**<- YUV/RGB [0..4095] (bit depth 12) */ } vpx_color_range_t; /**< alias for enum vpx_color_range */ /**\brief Image Descriptor */ @@ -98,7 +102,12 @@ typedef struct vpx_image { #define VPX_PLANE_V 2 /**< V (Chroma) plane */ #define VPX_PLANE_ALPHA 3 /**< A (Transparency) plane */ unsigned char *planes[4]; /**< pointer to the top left pixel for each plane */ - int stride[4]; /**< stride between rows for each plane */ + /*!Stride between rows for each plane + * + * \note With planar formats, \c stride[VPX_PLANE_U] must be the same as \c + * stride[VPX_PLANE_V]. + */ + int stride[4]; int bps; /**< bits per sample (for packed formats) */ @@ -126,16 +135,19 @@ typedef struct vpx_image_rect { /*!\brief Open a descriptor, allocating storage for the underlying image * * Returns a descriptor for storing an image of the given format. The - * storage for the descriptor is allocated on the heap. + * storage for the image is allocated on the heap. * * \param[in] img Pointer to storage for descriptor. If this parameter * is NULL, the storage for the descriptor will be * allocated on the heap. * \param[in] fmt Format for the image - * \param[in] d_w Width of the image - * \param[in] d_h Height of the image + * \param[in] d_w Width of the image. Must not exceed 0x08000000 + * (2^27). + * \param[in] d_h Height of the image. Must not exceed 0x08000000 + * (2^27). * \param[in] align Alignment, in bytes, of the image buffer and - * each row in the image(stride). + * each row in the image (stride). Must not exceed + * 65536. * * \return Returns a pointer to the initialized image descriptor. If the img * parameter is non-null, the value of the img parameter will be @@ -148,21 +160,55 @@ vpx_image_t *vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt, /*!\brief Open a descriptor, using existing storage for the underlying image * * Returns a descriptor for storing an image of the given format. The - * storage for descriptor has been allocated elsewhere, and a descriptor is + * storage for the image has been allocated elsewhere, and a descriptor is * desired to "wrap" that storage. * * \param[in] img Pointer to storage for descriptor. If this * parameter is NULL, the storage for the descriptor * will be allocated on the heap. * \param[in] fmt Format for the image - * \param[in] d_w Width of the image - * \param[in] d_h Height of the image - * \param[in] stride_align Alignment, in bytes, of each row in the image. - * \param[in] img_data Storage to use for the image + * \param[in] d_w Width of the image. Must not exceed 0x08000000 + * (2^27). + * \param[in] d_h Height of the image. Must not exceed 0x08000000 + * (2^27). + * \param[in] stride_align Alignment, in bytes, of each row in the image + * (stride). Must not exceed 65536. + * \param[in] img_data Storage to use for the image. The storage must + * outlive the returned image descriptor; it can be + * disposed of after calling vpx_img_free(). * * \return Returns a pointer to the initialized image descriptor. If the img * parameter is non-null, the value of the img parameter will be * returned. + * + * \note \a img_data is required to have a minimum allocation size that + * satisfies the requirements of the \a fmt, \a d_w, \a d_h and \a + * stride_align parameters. This size can be calculated as follows (see + * \c img_alloc_helper in the vpx_image.c file in the libvpx source tree + * for more detail): + * \code + * align = (1 << x_chroma_shift) - 1; + * w = (d_w + align) & ~align; + * align = (1 << y_chroma_shift) - 1; + * h = (d_h + align) & ~align; + * + * s = (fmt & VPX_IMG_FMT_PLANAR) ? w : (uint64_t)bps * w / 8; + * s = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? s * 2 : s; + * s = (s + stride_align - 1) & ~((uint64_t)stride_align - 1); + * s = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? s / 2 : s; + * alloc_size = (fmt & VPX_IMG_FMT_PLANAR) ? (uint64_t)h * s * bps / 8 + * : (uint64_t)h * s; + * \endcode + * \a x_chroma_shift, \a y_chroma_shift and \a bps can be obtained by calling + * \ref vpx_img_wrap with a non-\c NULL \a img_data parameter. The \c + * vpx_image_t pointer should \em not be used in other API calls until \em after + * a successful call to \ref vpx_img_wrap with a valid image buffer. For + * example: + * \code + * vpx_img_wrap(img, fmt, d_w, d_h, stride_align, (unsigned char *)1); + * ... calculate buffer size and allocate buffer as described earlier + * vpx_img_wrap(img, fmt, d_w, d_h, stride_align, img_data); + * \endcode */ vpx_image_t *vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int stride_align, @@ -172,7 +218,8 @@ vpx_image_t *vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, * * Updates the displayed rectangle (aka viewport) on the image surface to * match the specified coordinates and size. Specifically, sets img->d_w, - * img->d_h, and elements of the img->planes[] array. + * img->d_h, and elements of the img->planes[] array. The image must not be + * vertically flipped. On failure, the image descriptor is left unchanged. * * \param[in] img Image descriptor * \param[in] x leftmost column @@ -180,7 +227,8 @@ vpx_image_t *vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, * \param[in] w width * \param[in] h height * - * \return 0 if the requested rectangle is valid, nonzero (-1) otherwise. + * \return 0 if the requested rectangle is valid and the image is not flipped, + * nonzero (-1) otherwise. */ int vpx_img_set_rect(vpx_image_t *img, unsigned int x, unsigned int y, unsigned int w, unsigned int h); diff --git a/libs/libvpx/vpx/vpx_integer.h b/libs/libvpx/vpx/vpx_integer.h index 4129d156f8..34e3796411 100644 --- a/libs/libvpx/vpx/vpx_integer.h +++ b/libs/libvpx/vpx/vpx_integer.h @@ -12,7 +12,7 @@ #define VPX_VPX_VPX_INTEGER_H_ /* get ptrdiff_t, size_t, wchar_t, NULL */ -#include +#include // IWYU pragma: export #if defined(_MSC_VER) #define VPX_FORCE_INLINE __forceinline @@ -34,7 +34,7 @@ #endif #endif // __cplusplus -#include -#include +#include // IWYU pragma: export +#include // IWYU pragma: export #endif // VPX_VPX_VPX_INTEGER_H_ diff --git a/libs/libvpx/vpx/vpx_tpl.h b/libs/libvpx/vpx/vpx_tpl.h new file mode 100644 index 0000000000..ecee5d1efe --- /dev/null +++ b/libs/libvpx/vpx/vpx_tpl.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +/*!\file + * \brief Describes the TPL stats descriptor and associated operations + * + */ +#ifndef VPX_VPX_VPX_TPL_H_ +#define VPX_VPX_VPX_TPL_H_ + +#include "./vpx_integer.h" +#include "./vpx_codec.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*!\brief Current ABI version number + * + * \internal + * If this file is altered in any way that changes the ABI, this value + * must be bumped. Examples include, but are not limited to, changing + * types, removing or reassigning enums, adding/removing/rearranging + * fields to structures + */ +#define VPX_TPL_ABI_VERSION 5 /**<\hideinitializer*/ + +/*!\brief Temporal dependency model stats for each block before propagation */ +typedef struct VpxTplBlockStats { + int16_t row; /**< Pixel row of the top left corner */ + int16_t col; /**< Pixel col of the top left corner */ + int64_t intra_cost; /**< Intra cost */ + int64_t inter_cost; /**< Inter cost */ + int16_t mv_r; /**< Motion vector row in pixel */ + int16_t mv_c; /**< Motion vector col in pixel */ + int64_t srcrf_rate; /**< Rate from source ref frame */ + int64_t srcrf_dist; /**< Distortion from source ref frame */ + int64_t pred_error; /**< Prediction error */ + int64_t inter_pred_err; /**< Inter prediction error */ + int64_t intra_pred_err; /**< Intra prediction error */ + int ref_frame_index; /**< Ref frame index in the ref frame buffer */ +} VpxTplBlockStats; + +/*!\brief Temporal dependency model stats for each frame before propagation */ +typedef struct VpxTplFrameStats { + int frame_width; /**< Frame width */ + int frame_height; /**< Frame height */ + int num_blocks; /**< Number of blocks. Size of block_stats_list */ + VpxTplBlockStats *block_stats_list; /**< List of tpl stats for each block */ +} VpxTplFrameStats; + +/*!\brief Temporal dependency model stats for each GOP before propagation */ +typedef struct VpxTplGopStats { + int size; /**< GOP size, also the size of frame_stats_list. */ + VpxTplFrameStats *frame_stats_list; /**< List of tpl stats for each frame */ +} VpxTplGopStats; + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // VPX_VPX_VPX_TPL_H_ diff --git a/libs/libvpx/vpx_dsp/arm/avg_neon.c b/libs/libvpx/vpx_dsp/arm/avg_neon.c index 8e57bdaa50..1b17a326b4 100644 --- a/libs/libvpx/vpx_dsp/arm/avg_neon.c +++ b/libs/libvpx/vpx_dsp/arm/avg_neon.c @@ -46,96 +46,93 @@ uint32_t vpx_avg_8x8_neon(const uint8_t *a, int a_stride) { // coeff: 16 bits, dynamic range [-32640, 32640]. // length: value range {16, 64, 256, 1024}. +// satd: 26 bits, dynamic range [-32640 * 1024, 32640 * 1024] int vpx_satd_neon(const tran_low_t *coeff, int length) { - const int16x4_t zero = vdup_n_s16(0); - int32x4_t accum = vdupq_n_s32(0); + int32x4_t sum_s32[2] = { vdupq_n_s32(0), vdupq_n_s32(0) }; do { - const int16x8_t src0 = load_tran_low_to_s16q(coeff); - const int16x8_t src8 = load_tran_low_to_s16q(coeff + 8); - accum = vabal_s16(accum, vget_low_s16(src0), zero); - accum = vabal_s16(accum, vget_high_s16(src0), zero); - accum = vabal_s16(accum, vget_low_s16(src8), zero); - accum = vabal_s16(accum, vget_high_s16(src8), zero); + int16x8_t abs0, abs1; + const int16x8_t s0 = load_tran_low_to_s16q(coeff); + const int16x8_t s1 = load_tran_low_to_s16q(coeff + 8); + + abs0 = vabsq_s16(s0); + sum_s32[0] = vpadalq_s16(sum_s32[0], abs0); + abs1 = vabsq_s16(s1); + sum_s32[1] = vpadalq_s16(sum_s32[1], abs1); + length -= 16; coeff += 16; } while (length != 0); - { - // satd: 26 bits, dynamic range [-32640 * 1024, 32640 * 1024] - const int64x2_t s0 = vpaddlq_s32(accum); // cascading summation of 'accum'. - const int32x2_t s1 = vadd_s32(vreinterpret_s32_s64(vget_low_s64(s0)), - vreinterpret_s32_s64(vget_high_s64(s0))); - const int satd = vget_lane_s32(s1, 0); - return satd; - } + return horizontal_add_int32x4(vaddq_s32(sum_s32[0], sum_s32[1])); } void vpx_int_pro_row_neon(int16_t hbuf[16], uint8_t const *ref, const int ref_stride, const int height) { int i; - uint16x8_t vec_sum_lo = vdupq_n_u16(0); - uint16x8_t vec_sum_hi = vdupq_n_u16(0); - const int shift_factor = ((height >> 5) + 3) * -1; - const int16x8_t vec_shift = vdupq_n_s16(shift_factor); + uint8x16_t r0, r1, r2, r3; + uint16x8_t sum_lo[2], sum_hi[2]; + uint16x8_t tmp_lo[2], tmp_hi[2]; + int16x8_t avg_lo, avg_hi; - for (i = 0; i < height; i += 8) { - const uint8x16_t vec_row1 = vld1q_u8(ref); - const uint8x16_t vec_row2 = vld1q_u8(ref + ref_stride); - const uint8x16_t vec_row3 = vld1q_u8(ref + ref_stride * 2); - const uint8x16_t vec_row4 = vld1q_u8(ref + ref_stride * 3); - const uint8x16_t vec_row5 = vld1q_u8(ref + ref_stride * 4); - const uint8x16_t vec_row6 = vld1q_u8(ref + ref_stride * 5); - const uint8x16_t vec_row7 = vld1q_u8(ref + ref_stride * 6); - const uint8x16_t vec_row8 = vld1q_u8(ref + ref_stride * 7); + const int norm_factor = (height >> 5) + 3; + const int16x8_t neg_norm_factor = vdupq_n_s16(-norm_factor); - vec_sum_lo = vaddw_u8(vec_sum_lo, vget_low_u8(vec_row1)); - vec_sum_hi = vaddw_u8(vec_sum_hi, vget_high_u8(vec_row1)); + assert(height >= 4 && height % 4 == 0); - vec_sum_lo = vaddw_u8(vec_sum_lo, vget_low_u8(vec_row2)); - vec_sum_hi = vaddw_u8(vec_sum_hi, vget_high_u8(vec_row2)); + r0 = vld1q_u8(ref + 0 * ref_stride); + r1 = vld1q_u8(ref + 1 * ref_stride); + r2 = vld1q_u8(ref + 2 * ref_stride); + r3 = vld1q_u8(ref + 3 * ref_stride); - vec_sum_lo = vaddw_u8(vec_sum_lo, vget_low_u8(vec_row3)); - vec_sum_hi = vaddw_u8(vec_sum_hi, vget_high_u8(vec_row3)); + sum_lo[0] = vaddl_u8(vget_low_u8(r0), vget_low_u8(r1)); + sum_hi[0] = vaddl_u8(vget_high_u8(r0), vget_high_u8(r1)); + sum_lo[1] = vaddl_u8(vget_low_u8(r2), vget_low_u8(r3)); + sum_hi[1] = vaddl_u8(vget_high_u8(r2), vget_high_u8(r3)); - vec_sum_lo = vaddw_u8(vec_sum_lo, vget_low_u8(vec_row4)); - vec_sum_hi = vaddw_u8(vec_sum_hi, vget_high_u8(vec_row4)); + ref += 4 * ref_stride; - vec_sum_lo = vaddw_u8(vec_sum_lo, vget_low_u8(vec_row5)); - vec_sum_hi = vaddw_u8(vec_sum_hi, vget_high_u8(vec_row5)); + for (i = 4; i < height; i += 4) { + r0 = vld1q_u8(ref + 0 * ref_stride); + r1 = vld1q_u8(ref + 1 * ref_stride); + r2 = vld1q_u8(ref + 2 * ref_stride); + r3 = vld1q_u8(ref + 3 * ref_stride); - vec_sum_lo = vaddw_u8(vec_sum_lo, vget_low_u8(vec_row6)); - vec_sum_hi = vaddw_u8(vec_sum_hi, vget_high_u8(vec_row6)); + tmp_lo[0] = vaddl_u8(vget_low_u8(r0), vget_low_u8(r1)); + tmp_hi[0] = vaddl_u8(vget_high_u8(r0), vget_high_u8(r1)); + tmp_lo[1] = vaddl_u8(vget_low_u8(r2), vget_low_u8(r3)); + tmp_hi[1] = vaddl_u8(vget_high_u8(r2), vget_high_u8(r3)); - vec_sum_lo = vaddw_u8(vec_sum_lo, vget_low_u8(vec_row7)); - vec_sum_hi = vaddw_u8(vec_sum_hi, vget_high_u8(vec_row7)); + sum_lo[0] = vaddq_u16(sum_lo[0], tmp_lo[0]); + sum_hi[0] = vaddq_u16(sum_hi[0], tmp_hi[0]); + sum_lo[1] = vaddq_u16(sum_lo[1], tmp_lo[1]); + sum_hi[1] = vaddq_u16(sum_hi[1], tmp_hi[1]); - vec_sum_lo = vaddw_u8(vec_sum_lo, vget_low_u8(vec_row8)); - vec_sum_hi = vaddw_u8(vec_sum_hi, vget_high_u8(vec_row8)); - - ref += ref_stride * 8; + ref += 4 * ref_stride; } - vec_sum_lo = vshlq_u16(vec_sum_lo, vec_shift); - vec_sum_hi = vshlq_u16(vec_sum_hi, vec_shift); + sum_lo[0] = vaddq_u16(sum_lo[0], sum_lo[1]); + sum_hi[0] = vaddq_u16(sum_hi[0], sum_hi[1]); - vst1q_s16(hbuf, vreinterpretq_s16_u16(vec_sum_lo)); - hbuf += 8; - vst1q_s16(hbuf, vreinterpretq_s16_u16(vec_sum_hi)); + avg_lo = vshlq_s16(vreinterpretq_s16_u16(sum_lo[0]), neg_norm_factor); + avg_hi = vshlq_s16(vreinterpretq_s16_u16(sum_hi[0]), neg_norm_factor); + + vst1q_s16(hbuf, avg_lo); + vst1q_s16(hbuf + 8, avg_hi); } int16_t vpx_int_pro_col_neon(uint8_t const *ref, const int width) { + uint16x8_t sum; int i; - uint16x8_t vec_sum = vdupq_n_u16(0); - for (i = 0; i < width; i += 16) { - const uint8x16_t vec_row = vld1q_u8(ref); - vec_sum = vaddw_u8(vec_sum, vget_low_u8(vec_row)); - vec_sum = vaddw_u8(vec_sum, vget_high_u8(vec_row)); - ref += 16; + assert(width >= 16 && width % 16 == 0); + + sum = vpaddlq_u8(vld1q_u8(ref)); + for (i = 16; i < width; i += 16) { + sum = vpadalq_u8(sum, vld1q_u8(ref + i)); } - return (int16_t)horizontal_add_uint16x8(vec_sum); + return (int16_t)horizontal_add_uint16x8(sum); } // ref, src = [0, 510] - max diff = 16-bits @@ -214,11 +211,16 @@ void vpx_minmax_8x8_neon(const uint8_t *a, int a_stride, const uint8_t *b, const uint8x16_t ab07_max = vmaxq_u8(ab0123_max, ab4567_max); const uint8x16_t ab07_min = vminq_u8(ab0123_min, ab4567_min); - // Split to D and start doing pairwise. +#if VPX_ARCH_AARCH64 + *min = *max = 0; // Clear high bits + *((uint8_t *)max) = vmaxvq_u8(ab07_max); + *((uint8_t *)min) = vminvq_u8(ab07_min); +#else + // Split into 64-bit vectors and execute pairwise min/max. uint8x8_t ab_max = vmax_u8(vget_high_u8(ab07_max), vget_low_u8(ab07_max)); uint8x8_t ab_min = vmin_u8(vget_high_u8(ab07_min), vget_low_u8(ab07_min)); - // Enough runs of vpmax/min propogate the max/min values to every position. + // Enough runs of vpmax/min propagate the max/min values to every position. ab_max = vpmax_u8(ab_max, ab_max); ab_min = vpmin_u8(ab_min, ab_min); @@ -232,4 +234,5 @@ void vpx_minmax_8x8_neon(const uint8_t *a, int a_stride, const uint8_t *b, // Store directly to avoid costly neon->gpr transfer. vst1_lane_u8((uint8_t *)max, ab_max, 0); vst1_lane_u8((uint8_t *)min, ab_min, 0); +#endif } diff --git a/libs/libvpx/vpx_dsp/arm/fdct16x16_neon.c b/libs/libvpx/vpx_dsp/arm/fdct16x16_neon.c index 67f43246aa..fde71ff30d 100644 --- a/libs/libvpx/vpx_dsp/arm/fdct16x16_neon.c +++ b/libs/libvpx/vpx_dsp/arm/fdct16x16_neon.c @@ -28,6 +28,124 @@ void vpx_fdct16x16_neon(const int16_t *input, tran_low_t *output, int stride) { #else +// Main body of fdct16x16. +static void vpx_fdct8x16_body(const int16x8_t *in /*[16]*/, + int16x8_t *out /*[16]*/) { + int16x8_t s[8]; + int16x8_t x[4]; + int16x8_t step[8]; + + // stage 1 + // From fwd_txfm.c: Work on the first eight values; fdct8(input, + // even_results);" + s[0] = vaddq_s16(in[0], in[7]); + s[1] = vaddq_s16(in[1], in[6]); + s[2] = vaddq_s16(in[2], in[5]); + s[3] = vaddq_s16(in[3], in[4]); + s[4] = vsubq_s16(in[3], in[4]); + s[5] = vsubq_s16(in[2], in[5]); + s[6] = vsubq_s16(in[1], in[6]); + s[7] = vsubq_s16(in[0], in[7]); + + // fdct4(step, step); + x[0] = vaddq_s16(s[0], s[3]); + x[1] = vaddq_s16(s[1], s[2]); + x[2] = vsubq_s16(s[1], s[2]); + x[3] = vsubq_s16(s[0], s[3]); + + // out[0] = fdct_round_shift((x0 + x1) * cospi_16_64) + // out[8] = fdct_round_shift((x0 - x1) * cospi_16_64) + butterfly_one_coeff_s16_s32_fast_narrow(x[0], x[1], cospi_16_64, &out[0], + &out[8]); + // out[4] = fdct_round_shift(x3 * cospi_8_64 + x2 * cospi_24_64); + // out[12] = fdct_round_shift(x3 * cospi_24_64 - x2 * cospi_8_64); + butterfly_two_coeff(x[3], x[2], cospi_8_64, cospi_24_64, &out[4], &out[12]); + + // Stage 2 + // Re-using source s5/s6 + // s5 = fdct_round_shift((s6 - s5) * cospi_16_64) + // s6 = fdct_round_shift((s6 + s5) * cospi_16_64) + butterfly_one_coeff_s16_fast(s[6], s[5], cospi_16_64, &s[6], &s[5]); + + // Stage 3 + x[0] = vaddq_s16(s[4], s[5]); + x[1] = vsubq_s16(s[4], s[5]); + x[2] = vsubq_s16(s[7], s[6]); + x[3] = vaddq_s16(s[7], s[6]); + + // Stage 4 + // out[2] = fdct_round_shift(x3 * cospi_4_64 + x0 * cospi_28_64) + // out[14] = fdct_round_shift(x3 * cospi_28_64 - x0 * cospi_4_64) + butterfly_two_coeff(x[3], x[0], cospi_4_64, cospi_28_64, &out[2], &out[14]); + // out[6] = fdct_round_shift(x2 * cospi_20_64 + x1 * cospi_12_64) + // out[10] = fdct_round_shift(x2 * cospi_12_64 - x1 * cospi_20_64) + butterfly_two_coeff(x[2], x[1], cospi_20_64, cospi_12_64, &out[10], &out[6]); + + // step 2 + // From fwd_txfm.c: Work on the next eight values; step1 -> odd_results" + // That file distinguished between "in_high" and "step1" but the only + // difference is that "in_high" is the first 8 values and "step 1" is the + // second. Here, since they are all in one array, "step1" values are += 8. + + // step2[2] = fdct_round_shift((step1[5] - step1[2]) * cospi_16_64) + // step2[3] = fdct_round_shift((step1[4] - step1[3]) * cospi_16_64) + // step2[4] = fdct_round_shift((step1[4] + step1[3]) * cospi_16_64) + // step2[5] = fdct_round_shift((step1[5] + step1[2]) * cospi_16_64) + butterfly_one_coeff_s16_fast(in[13], in[10], cospi_16_64, &s[5], &s[2]); + butterfly_one_coeff_s16_fast(in[12], in[11], cospi_16_64, &s[4], &s[3]); + + // step 3 + s[0] = vaddq_s16(in[8], s[3]); + s[1] = vaddq_s16(in[9], s[2]); + x[0] = vsubq_s16(in[9], s[2]); + x[1] = vsubq_s16(in[8], s[3]); + x[2] = vsubq_s16(in[15], s[4]); + x[3] = vsubq_s16(in[14], s[5]); + s[6] = vaddq_s16(in[14], s[5]); + s[7] = vaddq_s16(in[15], s[4]); + + // step 4 + // step2[6] = fdct_round_shift(step3[6] * cospi_8_64 + step3[1] * + // cospi_24_64) step2[1] = fdct_round_shift(step3[6] * cospi_24_64 - step3[1] + // * cospi_8_64) + butterfly_two_coeff(s[6], s[1], cospi_8_64, cospi_24_64, &s[6], &s[1]); + + // step2[2] = fdct_round_shift(step3[2] * cospi_24_64 + step3[5] * cospi_8_64) + // step2[5] = fdct_round_shift(step3[2] * cospi_8_64 - step3[5] * + // cospi_24_64) + butterfly_two_coeff(x[0], x[3], cospi_24_64, cospi_8_64, &s[2], &s[5]); + + // step 5 + step[0] = vaddq_s16(s[0], s[1]); + step[1] = vsubq_s16(s[0], s[1]); + step[2] = vaddq_s16(x[1], s[2]); + step[3] = vsubq_s16(x[1], s[2]); + step[4] = vsubq_s16(x[2], s[5]); + step[5] = vaddq_s16(x[2], s[5]); + step[6] = vsubq_s16(s[7], s[6]); + step[7] = vaddq_s16(s[7], s[6]); + + // step 6 + // out[9] = fdct_round_shift(step1[6] * cospi_18_64 + step1[1] * cospi_14_64) + // out[7] = fdct_round_shift(step1[6] * cospi_14_64 - step1[1] * cospi_18_64) + butterfly_two_coeff(step[6], step[1], cospi_18_64, cospi_14_64, &out[9], + &out[7]); + // out[1] = fdct_round_shift(step1[7] * cospi_2_64 + step1[0] * cospi_30_64) + // out[15] = fdct_round_shift(step1[7] * cospi_30_64 - step1[0] * cospi_2_64) + butterfly_two_coeff(step[7], step[0], cospi_2_64, cospi_30_64, &out[1], + &out[15]); + + // out[13] = fdct_round_shift(step1[4] * cospi_26_64 + step1[3] * cospi_6_64) + // out[3] = fdct_round_shift(step1[4] * cospi_6_64 - step1[3] * cospi_26_64) + butterfly_two_coeff(step[4], step[3], cospi_26_64, cospi_6_64, &out[13], + &out[3]); + + // out[5] = fdct_round_shift(step1[5] * cospi_10_64 + step1[2] * cospi_22_64) + // out[11] = fdct_round_shift(step1[5] * cospi_22_64 - step1[2] * cospi_10_64) + butterfly_two_coeff(step[5], step[2], cospi_10_64, cospi_22_64, &out[5], + &out[11]); +} + void vpx_fdct16x16_neon(const int16_t *input, tran_low_t *output, int stride) { int16x8_t temp0[16]; int16x8_t temp1[16]; @@ -35,22 +153,23 @@ void vpx_fdct16x16_neon(const int16_t *input, tran_low_t *output, int stride) { int16x8_t temp3[16]; // Left half. - load(input, stride, temp0); - cross_input(temp0, temp1, 0); - vpx_fdct16x16_body(temp1, temp0); + load_cross(input, stride, temp0); + scale_input(temp0, temp1); + vpx_fdct8x16_body(temp1, temp0); // Right half. - load(input + 8, stride, temp1); - cross_input(temp1, temp2, 0); - vpx_fdct16x16_body(temp2, temp1); + load_cross(input + 8, stride, temp1); + scale_input(temp1, temp2); + vpx_fdct8x16_body(temp2, temp1); // Transpose top left and top right quarters into one contiguous location to // process to the top half. - transpose_8x8(&temp0[0], &temp2[0]); - transpose_8x8(&temp1[0], &temp2[8]); + + transpose_s16_8x8q(&temp0[0], &temp2[0]); + transpose_s16_8x8q(&temp1[0], &temp2[8]); partial_round_shift(temp2); - cross_input(temp2, temp3, 1); - vpx_fdct16x16_body(temp3, temp2); + cross_input(temp2, temp3); + vpx_fdct8x16_body(temp3, temp2); transpose_s16_8x8(&temp2[0], &temp2[1], &temp2[2], &temp2[3], &temp2[4], &temp2[5], &temp2[6], &temp2[7]); transpose_s16_8x8(&temp2[8], &temp2[9], &temp2[10], &temp2[11], &temp2[12], @@ -61,12 +180,13 @@ void vpx_fdct16x16_neon(const int16_t *input, tran_low_t *output, int stride) { // Transpose bottom left and bottom right quarters into one contiguous // location to process to the bottom half. - transpose_8x8(&temp0[8], &temp1[0]); + transpose_s16_8x8q(&temp0[8], &temp1[0]); + transpose_s16_8x8(&temp1[8], &temp1[9], &temp1[10], &temp1[11], &temp1[12], &temp1[13], &temp1[14], &temp1[15]); partial_round_shift(temp1); - cross_input(temp1, temp0, 1); - vpx_fdct16x16_body(temp0, temp1); + cross_input(temp1, temp0); + vpx_fdct8x16_body(temp0, temp1); transpose_s16_8x8(&temp1[0], &temp1[1], &temp1[2], &temp1[3], &temp1[4], &temp1[5], &temp1[6], &temp1[7]); transpose_s16_8x8(&temp1[8], &temp1[9], &temp1[10], &temp1[11], &temp1[12], @@ -74,5 +194,246 @@ void vpx_fdct16x16_neon(const int16_t *input, tran_low_t *output, int stride) { store(output, temp1); store(output + 8, temp1 + 8); } + +#if CONFIG_VP9_HIGHBITDEPTH + +// Main body of fdct8x16 column +static void vpx_highbd_fdct8x16_body(int32x4_t *left /*[16]*/, + int32x4_t *right /* [16] */) { + int32x4_t sl[8]; + int32x4_t sr[8]; + int32x4_t xl[4]; + int32x4_t xr[4]; + int32x4_t inl[8]; + int32x4_t inr[8]; + int32x4_t stepl[8]; + int32x4_t stepr[8]; + + // stage 1 + // From fwd_txfm.c: Work on the first eight values; fdct8(input, + // even_results);" + sl[0] = vaddq_s32(left[0], left[7]); + sr[0] = vaddq_s32(right[0], right[7]); + sl[1] = vaddq_s32(left[1], left[6]); + sr[1] = vaddq_s32(right[1], right[6]); + sl[2] = vaddq_s32(left[2], left[5]); + sr[2] = vaddq_s32(right[2], right[5]); + sl[3] = vaddq_s32(left[3], left[4]); + sr[3] = vaddq_s32(right[3], right[4]); + sl[4] = vsubq_s32(left[3], left[4]); + sr[4] = vsubq_s32(right[3], right[4]); + sl[5] = vsubq_s32(left[2], left[5]); + sr[5] = vsubq_s32(right[2], right[5]); + sl[6] = vsubq_s32(left[1], left[6]); + sr[6] = vsubq_s32(right[1], right[6]); + sl[7] = vsubq_s32(left[0], left[7]); + sr[7] = vsubq_s32(right[0], right[7]); + + // Copy values 8-15 as we're storing in-place + inl[0] = left[8]; + inr[0] = right[8]; + inl[1] = left[9]; + inr[1] = right[9]; + inl[2] = left[10]; + inr[2] = right[10]; + inl[3] = left[11]; + inr[3] = right[11]; + inl[4] = left[12]; + inr[4] = right[12]; + inl[5] = left[13]; + inr[5] = right[13]; + inl[6] = left[14]; + inr[6] = right[14]; + inl[7] = left[15]; + inr[7] = right[15]; + + // fdct4(step, step); + xl[0] = vaddq_s32(sl[0], sl[3]); + xr[0] = vaddq_s32(sr[0], sr[3]); + xl[1] = vaddq_s32(sl[1], sl[2]); + xr[1] = vaddq_s32(sr[1], sr[2]); + xl[2] = vsubq_s32(sl[1], sl[2]); + xr[2] = vsubq_s32(sr[1], sr[2]); + xl[3] = vsubq_s32(sl[0], sl[3]); + xr[3] = vsubq_s32(sr[0], sr[3]); + + // out[0] = fdct_round_shift((x0 + x1) * cospi_16_64) + // out[8] = fdct_round_shift((x0 - x1) * cospi_16_64) + butterfly_one_coeff_s32_fast(xl[0], xr[0], xl[1], xr[1], cospi_16_64, + &left[0], &right[0], &left[8], &right[8]); + + // out[4] = fdct_round_shift(x3 * cospi_8_64 + x2 * cospi_24_64); + // out[12] = fdct_round_shift(x3 * cospi_24_64 - x2 * cospi_8_64); + butterfly_two_coeff_s32_s64_narrow(xl[3], xr[3], xl[2], xr[2], cospi_8_64, + cospi_24_64, &left[4], &right[4], + &left[12], &right[12]); + + // Stage 2 + // Re-using source s5/s6 + // s5 = fdct_round_shift((s6 - s5) * cospi_16_64) + // s6 = fdct_round_shift((s6 + s5) * cospi_16_64) + butterfly_one_coeff_s32_fast(sl[6], sr[6], sl[5], sr[5], cospi_16_64, &sl[6], + &sr[6], &sl[5], &sr[5]); + + // Stage 3 + xl[0] = vaddq_s32(sl[4], sl[5]); + xr[0] = vaddq_s32(sr[4], sr[5]); + xl[1] = vsubq_s32(sl[4], sl[5]); + xr[1] = vsubq_s32(sr[4], sr[5]); + xl[2] = vsubq_s32(sl[7], sl[6]); + xr[2] = vsubq_s32(sr[7], sr[6]); + xl[3] = vaddq_s32(sl[7], sl[6]); + xr[3] = vaddq_s32(sr[7], sr[6]); + + // Stage 4 + // out[2] = fdct_round_shift(x3 * cospi_4_64 + x0 * cospi_28_64) + // out[14] = fdct_round_shift(x3 * cospi_28_64 - x0 * cospi_4_64) + butterfly_two_coeff_s32_s64_narrow(xl[3], xr[3], xl[0], xr[0], cospi_4_64, + cospi_28_64, &left[2], &right[2], + &left[14], &right[14]); + // out[6] = fdct_round_shift(x2 * cospi_20_64 + x1 * cospi_12_64) + // out[10] = fdct_round_shift(x2 * cospi_12_64 - x1 * cospi_20_64) + butterfly_two_coeff_s32_s64_narrow(xl[2], xr[2], xl[1], xr[1], cospi_20_64, + cospi_12_64, &left[10], &right[10], + &left[6], &right[6]); + + // step 2 + // From fwd_txfm.c: Work on the next eight values; step1 -> odd_results" + // That file distinguished between "in_high" and "step1" but the only + // difference is that "in_high" is the first 8 values and "step 1" is the + // second. Here, since they are all in one array, "step1" values are += 8. + + // step2[2] = fdct_round_shift((step1[5] - step1[2]) * cospi_16_64) + // step2[3] = fdct_round_shift((step1[4] - step1[3]) * cospi_16_64) + // step2[4] = fdct_round_shift((step1[4] + step1[3]) * cospi_16_64) + // step2[5] = fdct_round_shift((step1[5] + step1[2]) * cospi_16_64) + butterfly_one_coeff_s32_fast(inl[5], inr[5], inl[2], inr[2], cospi_16_64, + &sl[5], &sr[5], &sl[2], &sr[2]); + butterfly_one_coeff_s32_fast(inl[4], inr[4], inl[3], inr[3], cospi_16_64, + &sl[4], &sr[4], &sl[3], &sr[3]); + + // step 3 + sl[0] = vaddq_s32(inl[0], sl[3]); + sr[0] = vaddq_s32(inr[0], sr[3]); + sl[1] = vaddq_s32(inl[1], sl[2]); + sr[1] = vaddq_s32(inr[1], sr[2]); + xl[0] = vsubq_s32(inl[1], sl[2]); + xr[0] = vsubq_s32(inr[1], sr[2]); + xl[1] = vsubq_s32(inl[0], sl[3]); + xr[1] = vsubq_s32(inr[0], sr[3]); + xl[2] = vsubq_s32(inl[7], sl[4]); + xr[2] = vsubq_s32(inr[7], sr[4]); + xl[3] = vsubq_s32(inl[6], sl[5]); + xr[3] = vsubq_s32(inr[6], sr[5]); + sl[6] = vaddq_s32(inl[6], sl[5]); + sr[6] = vaddq_s32(inr[6], sr[5]); + sl[7] = vaddq_s32(inl[7], sl[4]); + sr[7] = vaddq_s32(inr[7], sr[4]); + + // step 4 + // step2[6] = fdct_round_shift(step3[6] * cospi_8_64 + step3[1] * + // cospi_24_64) step2[1] = fdct_round_shift(step3[6] * cospi_24_64 - step3[1] + // * cospi_8_64) + butterfly_two_coeff_s32_s64_narrow(sl[6], sr[6], sl[1], sr[1], cospi_8_64, + cospi_24_64, &sl[6], &sr[6], &sl[1], + &sr[1]); + // step2[2] = fdct_round_shift(step3[2] * cospi_24_64 + step3[5] * cospi_8_64) + // step2[5] = fdct_round_shift(step3[2] * cospi_8_64 - step3[5] * + // cospi_24_64) + butterfly_two_coeff_s32_s64_narrow(xl[0], xr[0], xl[3], xr[3], cospi_24_64, + cospi_8_64, &sl[2], &sr[2], &sl[5], + &sr[5]); + + // step 5 + stepl[0] = vaddq_s32(sl[0], sl[1]); + stepr[0] = vaddq_s32(sr[0], sr[1]); + stepl[1] = vsubq_s32(sl[0], sl[1]); + stepr[1] = vsubq_s32(sr[0], sr[1]); + stepl[2] = vaddq_s32(xl[1], sl[2]); + stepr[2] = vaddq_s32(xr[1], sr[2]); + stepl[3] = vsubq_s32(xl[1], sl[2]); + stepr[3] = vsubq_s32(xr[1], sr[2]); + stepl[4] = vsubq_s32(xl[2], sl[5]); + stepr[4] = vsubq_s32(xr[2], sr[5]); + stepl[5] = vaddq_s32(xl[2], sl[5]); + stepr[5] = vaddq_s32(xr[2], sr[5]); + stepl[6] = vsubq_s32(sl[7], sl[6]); + stepr[6] = vsubq_s32(sr[7], sr[6]); + stepl[7] = vaddq_s32(sl[7], sl[6]); + stepr[7] = vaddq_s32(sr[7], sr[6]); + + // step 6 + // out[9] = fdct_round_shift(step1[6] * cospi_18_64 + step1[1] * cospi_14_64) + // out[7] = fdct_round_shift(step1[6] * cospi_14_64 - step1[1] * cospi_18_64) + butterfly_two_coeff_s32_s64_narrow(stepl[6], stepr[6], stepl[1], stepr[1], + cospi_18_64, cospi_14_64, &left[9], + &right[9], &left[7], &right[7]); + // out[1] = fdct_round_shift(step1[7] * cospi_2_64 + step1[0] * cospi_30_64) + // out[15] = fdct_round_shift(step1[7] * cospi_30_64 - step1[0] * cospi_2_64) + butterfly_two_coeff_s32_s64_narrow(stepl[7], stepr[7], stepl[0], stepr[0], + cospi_2_64, cospi_30_64, &left[1], + &right[1], &left[15], &right[15]); + // out[13] = fdct_round_shift(step1[4] * cospi_26_64 + step1[3] * cospi_6_64) + // out[3] = fdct_round_shift(step1[4] * cospi_6_64 - step1[3] * cospi_26_64) + butterfly_two_coeff_s32_s64_narrow(stepl[4], stepr[4], stepl[3], stepr[3], + cospi_26_64, cospi_6_64, &left[13], + &right[13], &left[3], &right[3]); + // out[5] = fdct_round_shift(step1[5] * cospi_10_64 + step1[2] * cospi_22_64) + // out[11] = fdct_round_shift(step1[5] * cospi_22_64 - step1[2] * cospi_10_64) + butterfly_two_coeff_s32_s64_narrow(stepl[5], stepr[5], stepl[2], stepr[2], + cospi_10_64, cospi_22_64, &left[5], + &right[5], &left[11], &right[11]); +} + +void vpx_highbd_fdct16x16_neon(const int16_t *input, tran_low_t *output, + int stride) { + int16x8_t temp0[16]; + int32x4_t left1[16], left2[16], left3[16], left4[16], right1[16], right2[16], + right3[16], right4[16]; + + // Left half. + load_cross(input, stride, temp0); + highbd_scale_input(temp0, left1, right1); + vpx_highbd_fdct8x16_body(left1, right1); + + // right half. + load_cross(input + 8, stride, temp0); + highbd_scale_input(temp0, left2, right2); + vpx_highbd_fdct8x16_body(left2, right2); + + // Transpose top left and top right quarters into one contiguous location to + // process to the top half. + + transpose_s32_8x8_2(left1, right1, left3, right3); + transpose_s32_8x8_2(left2, right2, left3 + 8, right3 + 8); + transpose_s32_8x8_2(left1 + 8, right1 + 8, left4, right4); + transpose_s32_8x8_2(left2 + 8, right2 + 8, left4 + 8, right4 + 8); + + highbd_partial_round_shift(left3, right3); + highbd_cross_input(left3, right3, left1, right1); + vpx_highbd_fdct8x16_body(left1, right1); + + // Transpose bottom left and bottom right quarters into one contiguous + // location to process to the bottom half. + + highbd_partial_round_shift(left4, right4); + highbd_cross_input(left4, right4, left2, right2); + vpx_highbd_fdct8x16_body(left2, right2); + + transpose_s32_8x8_2(left1, right1, left3, right3); + transpose_s32_8x8_2(left2, right2, left3 + 8, right3 + 8); + transpose_s32_8x8_2(left1 + 8, right1 + 8, left4, right4); + transpose_s32_8x8_2(left2 + 8, right2 + 8, left4 + 8, right4 + 8); + store16_s32(output, left3); + output += 4; + store16_s32(output, right3); + output += 4; + + store16_s32(output, left4); + output += 4; + store16_s32(output, right4); +} +#endif // CONFIG_VP9_HIGHBITDEPTH + #endif // !defined(__clang__) && !defined(__ANDROID__) && defined(__GNUC__) && // __GNUC__ == 4 && __GNUC_MINOR__ == 9 && __GNUC_PATCHLEVEL__ < 4 diff --git a/libs/libvpx/vpx_dsp/arm/fdct16x16_neon.h b/libs/libvpx/vpx_dsp/arm/fdct16x16_neon.h index 0dd21153fc..cd58675ca4 100644 --- a/libs/libvpx/vpx_dsp/arm/fdct16x16_neon.h +++ b/libs/libvpx/vpx_dsp/arm/fdct16x16_neon.h @@ -13,6 +13,8 @@ #include +#include "fdct_neon.h" + static INLINE void load(const int16_t *a, int stride, int16x8_t *b /*[16]*/) { b[0] = vld1q_s16(a); a += stride; @@ -72,45 +74,67 @@ static INLINE void store(tran_low_t *a, const int16x8_t *b /*[8]*/) { // To maybe reduce register usage this could be combined with the load() step to // get the first 4 and last 4 values, cross those, then load the middle 8 values // and cross them. +static INLINE void scale_input(const int16x8_t *a /*[16]*/, + int16x8_t *b /*[16]*/) { + b[0] = vshlq_n_s16(a[0], 2); + b[1] = vshlq_n_s16(a[1], 2); + b[2] = vshlq_n_s16(a[2], 2); + b[3] = vshlq_n_s16(a[3], 2); + b[4] = vshlq_n_s16(a[4], 2); + b[5] = vshlq_n_s16(a[5], 2); + b[6] = vshlq_n_s16(a[6], 2); + b[7] = vshlq_n_s16(a[7], 2); + + b[8] = vshlq_n_s16(a[8], 2); + b[9] = vshlq_n_s16(a[9], 2); + b[10] = vshlq_n_s16(a[10], 2); + b[11] = vshlq_n_s16(a[11], 2); + b[12] = vshlq_n_s16(a[12], 2); + b[13] = vshlq_n_s16(a[13], 2); + b[14] = vshlq_n_s16(a[14], 2); + b[15] = vshlq_n_s16(a[15], 2); +} + static INLINE void cross_input(const int16x8_t *a /*[16]*/, - int16x8_t *b /*[16]*/, const int pass) { - if (pass == 0) { - b[0] = vshlq_n_s16(vaddq_s16(a[0], a[15]), 2); - b[1] = vshlq_n_s16(vaddq_s16(a[1], a[14]), 2); - b[2] = vshlq_n_s16(vaddq_s16(a[2], a[13]), 2); - b[3] = vshlq_n_s16(vaddq_s16(a[3], a[12]), 2); - b[4] = vshlq_n_s16(vaddq_s16(a[4], a[11]), 2); - b[5] = vshlq_n_s16(vaddq_s16(a[5], a[10]), 2); - b[6] = vshlq_n_s16(vaddq_s16(a[6], a[9]), 2); - b[7] = vshlq_n_s16(vaddq_s16(a[7], a[8]), 2); + int16x8_t *b /*[16]*/) { + b[0] = vaddq_s16(a[0], a[15]); + b[1] = vaddq_s16(a[1], a[14]); + b[2] = vaddq_s16(a[2], a[13]); + b[3] = vaddq_s16(a[3], a[12]); + b[4] = vaddq_s16(a[4], a[11]); + b[5] = vaddq_s16(a[5], a[10]); + b[6] = vaddq_s16(a[6], a[9]); + b[7] = vaddq_s16(a[7], a[8]); - b[8] = vshlq_n_s16(vsubq_s16(a[7], a[8]), 2); - b[9] = vshlq_n_s16(vsubq_s16(a[6], a[9]), 2); - b[10] = vshlq_n_s16(vsubq_s16(a[5], a[10]), 2); - b[11] = vshlq_n_s16(vsubq_s16(a[4], a[11]), 2); - b[12] = vshlq_n_s16(vsubq_s16(a[3], a[12]), 2); - b[13] = vshlq_n_s16(vsubq_s16(a[2], a[13]), 2); - b[14] = vshlq_n_s16(vsubq_s16(a[1], a[14]), 2); - b[15] = vshlq_n_s16(vsubq_s16(a[0], a[15]), 2); - } else { - b[0] = vaddq_s16(a[0], a[15]); - b[1] = vaddq_s16(a[1], a[14]); - b[2] = vaddq_s16(a[2], a[13]); - b[3] = vaddq_s16(a[3], a[12]); - b[4] = vaddq_s16(a[4], a[11]); - b[5] = vaddq_s16(a[5], a[10]); - b[6] = vaddq_s16(a[6], a[9]); - b[7] = vaddq_s16(a[7], a[8]); + b[8] = vsubq_s16(a[7], a[8]); + b[9] = vsubq_s16(a[6], a[9]); + b[10] = vsubq_s16(a[5], a[10]); + b[11] = vsubq_s16(a[4], a[11]); + b[12] = vsubq_s16(a[3], a[12]); + b[13] = vsubq_s16(a[2], a[13]); + b[14] = vsubq_s16(a[1], a[14]); + b[15] = vsubq_s16(a[0], a[15]); +} - b[8] = vsubq_s16(a[7], a[8]); - b[9] = vsubq_s16(a[6], a[9]); - b[10] = vsubq_s16(a[5], a[10]); - b[11] = vsubq_s16(a[4], a[11]); - b[12] = vsubq_s16(a[3], a[12]); - b[13] = vsubq_s16(a[2], a[13]); - b[14] = vsubq_s16(a[1], a[14]); - b[15] = vsubq_s16(a[0], a[15]); - } +static INLINE void load_cross(const int16_t *a, int stride, + int16x8_t *b /*[16]*/) { + b[0] = vaddq_s16(vld1q_s16(a + 0 * stride), vld1q_s16(a + 15 * stride)); + b[1] = vaddq_s16(vld1q_s16(a + 1 * stride), vld1q_s16(a + 14 * stride)); + b[2] = vaddq_s16(vld1q_s16(a + 2 * stride), vld1q_s16(a + 13 * stride)); + b[3] = vaddq_s16(vld1q_s16(a + 3 * stride), vld1q_s16(a + 12 * stride)); + b[4] = vaddq_s16(vld1q_s16(a + 4 * stride), vld1q_s16(a + 11 * stride)); + b[5] = vaddq_s16(vld1q_s16(a + 5 * stride), vld1q_s16(a + 10 * stride)); + b[6] = vaddq_s16(vld1q_s16(a + 6 * stride), vld1q_s16(a + 9 * stride)); + b[7] = vaddq_s16(vld1q_s16(a + 7 * stride), vld1q_s16(a + 8 * stride)); + + b[8] = vsubq_s16(vld1q_s16(a + 7 * stride), vld1q_s16(a + 8 * stride)); + b[9] = vsubq_s16(vld1q_s16(a + 6 * stride), vld1q_s16(a + 9 * stride)); + b[10] = vsubq_s16(vld1q_s16(a + 5 * stride), vld1q_s16(a + 10 * stride)); + b[11] = vsubq_s16(vld1q_s16(a + 4 * stride), vld1q_s16(a + 11 * stride)); + b[12] = vsubq_s16(vld1q_s16(a + 3 * stride), vld1q_s16(a + 12 * stride)); + b[13] = vsubq_s16(vld1q_s16(a + 2 * stride), vld1q_s16(a + 13 * stride)); + b[14] = vsubq_s16(vld1q_s16(a + 1 * stride), vld1q_s16(a + 14 * stride)); + b[15] = vsubq_s16(vld1q_s16(a + 0 * stride), vld1q_s16(a + 15 * stride)); } // Quarter round at the beginning of the second pass. Can't use vrshr (rounding) @@ -135,193 +159,160 @@ static INLINE void partial_round_shift(int16x8_t *a /*[16]*/) { a[15] = vshrq_n_s16(vaddq_s16(a[15], one), 2); } -// fdct_round_shift((a +/- b) * c) -static INLINE void butterfly_one_coeff(const int16x8_t a, const int16x8_t b, - const tran_high_t c, int16x8_t *add, - int16x8_t *sub) { - const int32x4_t a0 = vmull_n_s16(vget_low_s16(a), c); - const int32x4_t a1 = vmull_n_s16(vget_high_s16(a), c); - const int32x4_t sum0 = vmlal_n_s16(a0, vget_low_s16(b), c); - const int32x4_t sum1 = vmlal_n_s16(a1, vget_high_s16(b), c); - const int32x4_t diff0 = vmlsl_n_s16(a0, vget_low_s16(b), c); - const int32x4_t diff1 = vmlsl_n_s16(a1, vget_high_s16(b), c); - const int16x4_t rounded0 = vqrshrn_n_s32(sum0, 14); - const int16x4_t rounded1 = vqrshrn_n_s32(sum1, 14); - const int16x4_t rounded2 = vqrshrn_n_s32(diff0, 14); - const int16x4_t rounded3 = vqrshrn_n_s32(diff1, 14); - *add = vcombine_s16(rounded0, rounded1); - *sub = vcombine_s16(rounded2, rounded3); +#if CONFIG_VP9_HIGHBITDEPTH + +static INLINE void highbd_scale_input(const int16x8_t *a /*[16]*/, + int32x4_t *left /*[16]*/, + int32x4_t *right /* [16] */) { + left[0] = vshll_n_s16(vget_low_s16(a[0]), 2); + left[1] = vshll_n_s16(vget_low_s16(a[1]), 2); + left[2] = vshll_n_s16(vget_low_s16(a[2]), 2); + left[3] = vshll_n_s16(vget_low_s16(a[3]), 2); + left[4] = vshll_n_s16(vget_low_s16(a[4]), 2); + left[5] = vshll_n_s16(vget_low_s16(a[5]), 2); + left[6] = vshll_n_s16(vget_low_s16(a[6]), 2); + left[7] = vshll_n_s16(vget_low_s16(a[7]), 2); + left[8] = vshll_n_s16(vget_low_s16(a[8]), 2); + left[9] = vshll_n_s16(vget_low_s16(a[9]), 2); + left[10] = vshll_n_s16(vget_low_s16(a[10]), 2); + left[11] = vshll_n_s16(vget_low_s16(a[11]), 2); + left[12] = vshll_n_s16(vget_low_s16(a[12]), 2); + left[13] = vshll_n_s16(vget_low_s16(a[13]), 2); + left[14] = vshll_n_s16(vget_low_s16(a[14]), 2); + left[15] = vshll_n_s16(vget_low_s16(a[15]), 2); + + right[0] = vshll_n_s16(vget_high_s16(a[0]), 2); + right[1] = vshll_n_s16(vget_high_s16(a[1]), 2); + right[2] = vshll_n_s16(vget_high_s16(a[2]), 2); + right[3] = vshll_n_s16(vget_high_s16(a[3]), 2); + right[4] = vshll_n_s16(vget_high_s16(a[4]), 2); + right[5] = vshll_n_s16(vget_high_s16(a[5]), 2); + right[6] = vshll_n_s16(vget_high_s16(a[6]), 2); + right[7] = vshll_n_s16(vget_high_s16(a[7]), 2); + right[8] = vshll_n_s16(vget_high_s16(a[8]), 2); + right[9] = vshll_n_s16(vget_high_s16(a[9]), 2); + right[10] = vshll_n_s16(vget_high_s16(a[10]), 2); + right[11] = vshll_n_s16(vget_high_s16(a[11]), 2); + right[12] = vshll_n_s16(vget_high_s16(a[12]), 2); + right[13] = vshll_n_s16(vget_high_s16(a[13]), 2); + right[14] = vshll_n_s16(vget_high_s16(a[14]), 2); + right[15] = vshll_n_s16(vget_high_s16(a[15]), 2); } -// fdct_round_shift(a * c0 +/- b * c1) -static INLINE void butterfly_two_coeff(const int16x8_t a, const int16x8_t b, - const tran_coef_t c0, - const tran_coef_t c1, int16x8_t *add, - int16x8_t *sub) { - const int32x4_t a0 = vmull_n_s16(vget_low_s16(a), c0); - const int32x4_t a1 = vmull_n_s16(vget_high_s16(a), c0); - const int32x4_t a2 = vmull_n_s16(vget_low_s16(a), c1); - const int32x4_t a3 = vmull_n_s16(vget_high_s16(a), c1); - const int32x4_t sum0 = vmlal_n_s16(a2, vget_low_s16(b), c0); - const int32x4_t sum1 = vmlal_n_s16(a3, vget_high_s16(b), c0); - const int32x4_t diff0 = vmlsl_n_s16(a0, vget_low_s16(b), c1); - const int32x4_t diff1 = vmlsl_n_s16(a1, vget_high_s16(b), c1); - const int16x4_t rounded0 = vqrshrn_n_s32(sum0, 14); - const int16x4_t rounded1 = vqrshrn_n_s32(sum1, 14); - const int16x4_t rounded2 = vqrshrn_n_s32(diff0, 14); - const int16x4_t rounded3 = vqrshrn_n_s32(diff1, 14); - *add = vcombine_s16(rounded0, rounded1); - *sub = vcombine_s16(rounded2, rounded3); +static INLINE void highbd_cross_input(const int32x4_t *a_left /*[16]*/, + int32x4_t *a_right /*[16]*/, + int32x4_t *b_left /*[16]*/, + int32x4_t *b_right /*[16]*/) { + b_left[0] = vaddq_s32(a_left[0], a_left[15]); + b_left[1] = vaddq_s32(a_left[1], a_left[14]); + b_left[2] = vaddq_s32(a_left[2], a_left[13]); + b_left[3] = vaddq_s32(a_left[3], a_left[12]); + b_left[4] = vaddq_s32(a_left[4], a_left[11]); + b_left[5] = vaddq_s32(a_left[5], a_left[10]); + b_left[6] = vaddq_s32(a_left[6], a_left[9]); + b_left[7] = vaddq_s32(a_left[7], a_left[8]); + + b_right[0] = vaddq_s32(a_right[0], a_right[15]); + b_right[1] = vaddq_s32(a_right[1], a_right[14]); + b_right[2] = vaddq_s32(a_right[2], a_right[13]); + b_right[3] = vaddq_s32(a_right[3], a_right[12]); + b_right[4] = vaddq_s32(a_right[4], a_right[11]); + b_right[5] = vaddq_s32(a_right[5], a_right[10]); + b_right[6] = vaddq_s32(a_right[6], a_right[9]); + b_right[7] = vaddq_s32(a_right[7], a_right[8]); + + b_left[8] = vsubq_s32(a_left[7], a_left[8]); + b_left[9] = vsubq_s32(a_left[6], a_left[9]); + b_left[10] = vsubq_s32(a_left[5], a_left[10]); + b_left[11] = vsubq_s32(a_left[4], a_left[11]); + b_left[12] = vsubq_s32(a_left[3], a_left[12]); + b_left[13] = vsubq_s32(a_left[2], a_left[13]); + b_left[14] = vsubq_s32(a_left[1], a_left[14]); + b_left[15] = vsubq_s32(a_left[0], a_left[15]); + + b_right[8] = vsubq_s32(a_right[7], a_right[8]); + b_right[9] = vsubq_s32(a_right[6], a_right[9]); + b_right[10] = vsubq_s32(a_right[5], a_right[10]); + b_right[11] = vsubq_s32(a_right[4], a_right[11]); + b_right[12] = vsubq_s32(a_right[3], a_right[12]); + b_right[13] = vsubq_s32(a_right[2], a_right[13]); + b_right[14] = vsubq_s32(a_right[1], a_right[14]); + b_right[15] = vsubq_s32(a_right[0], a_right[15]); } -// Transpose 8x8 to a new location. Don't use transpose_neon.h because those -// are all in-place. -static INLINE void transpose_8x8(const int16x8_t *a /*[8]*/, - int16x8_t *b /*[8]*/) { - // Swap 16 bit elements. - const int16x8x2_t c0 = vtrnq_s16(a[0], a[1]); - const int16x8x2_t c1 = vtrnq_s16(a[2], a[3]); - const int16x8x2_t c2 = vtrnq_s16(a[4], a[5]); - const int16x8x2_t c3 = vtrnq_s16(a[6], a[7]); +static INLINE void highbd_partial_round_shift(int32x4_t *left /*[16]*/, + int32x4_t *right /* [16] */) { + const int32x4_t one = vdupq_n_s32(1); + left[0] = vshrq_n_s32(vaddq_s32(left[0], one), 2); + left[1] = vshrq_n_s32(vaddq_s32(left[1], one), 2); + left[2] = vshrq_n_s32(vaddq_s32(left[2], one), 2); + left[3] = vshrq_n_s32(vaddq_s32(left[3], one), 2); + left[4] = vshrq_n_s32(vaddq_s32(left[4], one), 2); + left[5] = vshrq_n_s32(vaddq_s32(left[5], one), 2); + left[6] = vshrq_n_s32(vaddq_s32(left[6], one), 2); + left[7] = vshrq_n_s32(vaddq_s32(left[7], one), 2); + left[8] = vshrq_n_s32(vaddq_s32(left[8], one), 2); + left[9] = vshrq_n_s32(vaddq_s32(left[9], one), 2); + left[10] = vshrq_n_s32(vaddq_s32(left[10], one), 2); + left[11] = vshrq_n_s32(vaddq_s32(left[11], one), 2); + left[12] = vshrq_n_s32(vaddq_s32(left[12], one), 2); + left[13] = vshrq_n_s32(vaddq_s32(left[13], one), 2); + left[14] = vshrq_n_s32(vaddq_s32(left[14], one), 2); + left[15] = vshrq_n_s32(vaddq_s32(left[15], one), 2); - // Swap 32 bit elements. - const int32x4x2_t d0 = vtrnq_s32(vreinterpretq_s32_s16(c0.val[0]), - vreinterpretq_s32_s16(c1.val[0])); - const int32x4x2_t d1 = vtrnq_s32(vreinterpretq_s32_s16(c0.val[1]), - vreinterpretq_s32_s16(c1.val[1])); - const int32x4x2_t d2 = vtrnq_s32(vreinterpretq_s32_s16(c2.val[0]), - vreinterpretq_s32_s16(c3.val[0])); - const int32x4x2_t d3 = vtrnq_s32(vreinterpretq_s32_s16(c2.val[1]), - vreinterpretq_s32_s16(c3.val[1])); - - // Swap 64 bit elements - const int16x8x2_t e0 = vpx_vtrnq_s64_to_s16(d0.val[0], d2.val[0]); - const int16x8x2_t e1 = vpx_vtrnq_s64_to_s16(d1.val[0], d3.val[0]); - const int16x8x2_t e2 = vpx_vtrnq_s64_to_s16(d0.val[1], d2.val[1]); - const int16x8x2_t e3 = vpx_vtrnq_s64_to_s16(d1.val[1], d3.val[1]); - - b[0] = e0.val[0]; - b[1] = e1.val[0]; - b[2] = e2.val[0]; - b[3] = e3.val[0]; - b[4] = e0.val[1]; - b[5] = e1.val[1]; - b[6] = e2.val[1]; - b[7] = e3.val[1]; + right[0] = vshrq_n_s32(vaddq_s32(right[0], one), 2); + right[1] = vshrq_n_s32(vaddq_s32(right[1], one), 2); + right[2] = vshrq_n_s32(vaddq_s32(right[2], one), 2); + right[3] = vshrq_n_s32(vaddq_s32(right[3], one), 2); + right[4] = vshrq_n_s32(vaddq_s32(right[4], one), 2); + right[5] = vshrq_n_s32(vaddq_s32(right[5], one), 2); + right[6] = vshrq_n_s32(vaddq_s32(right[6], one), 2); + right[7] = vshrq_n_s32(vaddq_s32(right[7], one), 2); + right[8] = vshrq_n_s32(vaddq_s32(right[8], one), 2); + right[9] = vshrq_n_s32(vaddq_s32(right[9], one), 2); + right[10] = vshrq_n_s32(vaddq_s32(right[10], one), 2); + right[11] = vshrq_n_s32(vaddq_s32(right[11], one), 2); + right[12] = vshrq_n_s32(vaddq_s32(right[12], one), 2); + right[13] = vshrq_n_s32(vaddq_s32(right[13], one), 2); + right[14] = vshrq_n_s32(vaddq_s32(right[14], one), 2); + right[15] = vshrq_n_s32(vaddq_s32(right[15], one), 2); } -// Main body of fdct16x16. -static void vpx_fdct16x16_body(const int16x8_t *in /*[16]*/, - int16x8_t *out /*[16]*/) { - int16x8_t s[8]; - int16x8_t x[4]; - int16x8_t step[8]; - - // stage 1 - // From fwd_txfm.c: Work on the first eight values; fdct8(input, - // even_results);" - s[0] = vaddq_s16(in[0], in[7]); - s[1] = vaddq_s16(in[1], in[6]); - s[2] = vaddq_s16(in[2], in[5]); - s[3] = vaddq_s16(in[3], in[4]); - s[4] = vsubq_s16(in[3], in[4]); - s[5] = vsubq_s16(in[2], in[5]); - s[6] = vsubq_s16(in[1], in[6]); - s[7] = vsubq_s16(in[0], in[7]); - - // fdct4(step, step); - x[0] = vaddq_s16(s[0], s[3]); - x[1] = vaddq_s16(s[1], s[2]); - x[2] = vsubq_s16(s[1], s[2]); - x[3] = vsubq_s16(s[0], s[3]); - - // out[0] = fdct_round_shift((x0 + x1) * cospi_16_64) - // out[8] = fdct_round_shift((x0 - x1) * cospi_16_64) - butterfly_one_coeff(x[0], x[1], cospi_16_64, &out[0], &out[8]); - // out[4] = fdct_round_shift(x3 * cospi_8_64 + x2 * cospi_24_64); - // out[12] = fdct_round_shift(x3 * cospi_24_64 - x2 * cospi_8_64); - butterfly_two_coeff(x[3], x[2], cospi_24_64, cospi_8_64, &out[4], &out[12]); - - // Stage 2 - // Re-using source s5/s6 - // s5 = fdct_round_shift((s6 - s5) * cospi_16_64) - // s6 = fdct_round_shift((s6 + s5) * cospi_16_64) - butterfly_one_coeff(s[6], s[5], cospi_16_64, &s[6], &s[5]); - - // Stage 3 - x[0] = vaddq_s16(s[4], s[5]); - x[1] = vsubq_s16(s[4], s[5]); - x[2] = vsubq_s16(s[7], s[6]); - x[3] = vaddq_s16(s[7], s[6]); - - // Stage 4 - // out[2] = fdct_round_shift(x0 * cospi_28_64 + x3 * cospi_4_64) - // out[14] = fdct_round_shift(x3 * cospi_28_64 + x0 * -cospi_4_64) - butterfly_two_coeff(x[3], x[0], cospi_28_64, cospi_4_64, &out[2], &out[14]); - // out[6] = fdct_round_shift(x1 * cospi_12_64 + x2 * cospi_20_64) - // out[10] = fdct_round_shift(x2 * cospi_12_64 + x1 * -cospi_20_64) - butterfly_two_coeff(x[2], x[1], cospi_12_64, cospi_20_64, &out[10], &out[6]); - - // step 2 - // From fwd_txfm.c: Work on the next eight values; step1 -> odd_results" - // That file distinguished between "in_high" and "step1" but the only - // difference is that "in_high" is the first 8 values and "step 1" is the - // second. Here, since they are all in one array, "step1" values are += 8. - - // step2[2] = fdct_round_shift((step1[5] - step1[2]) * cospi_16_64) - // step2[3] = fdct_round_shift((step1[4] - step1[3]) * cospi_16_64) - // step2[4] = fdct_round_shift((step1[4] + step1[3]) * cospi_16_64) - // step2[5] = fdct_round_shift((step1[5] + step1[2]) * cospi_16_64) - butterfly_one_coeff(in[13], in[10], cospi_16_64, &s[5], &s[2]); - butterfly_one_coeff(in[12], in[11], cospi_16_64, &s[4], &s[3]); - - // step 3 - s[0] = vaddq_s16(in[8], s[3]); - s[1] = vaddq_s16(in[9], s[2]); - x[0] = vsubq_s16(in[9], s[2]); - x[1] = vsubq_s16(in[8], s[3]); - x[2] = vsubq_s16(in[15], s[4]); - x[3] = vsubq_s16(in[14], s[5]); - s[6] = vaddq_s16(in[14], s[5]); - s[7] = vaddq_s16(in[15], s[4]); - - // step 4 - // step2[1] = fdct_round_shift(step3[1] *-cospi_8_64 + step3[6] * cospi_24_64) - // step2[6] = fdct_round_shift(step3[1] * cospi_24_64 + step3[6] * cospi_8_64) - butterfly_two_coeff(s[6], s[1], cospi_24_64, cospi_8_64, &s[6], &s[1]); - - // step2[2] = fdct_round_shift(step3[2] * cospi_24_64 + step3[5] * cospi_8_64) - // step2[5] = fdct_round_shift(step3[2] * cospi_8_64 - step3[5] * cospi_24_64) - butterfly_two_coeff(x[0], x[3], cospi_8_64, cospi_24_64, &s[2], &s[5]); - - // step 5 - step[0] = vaddq_s16(s[0], s[1]); - step[1] = vsubq_s16(s[0], s[1]); - step[2] = vaddq_s16(x[1], s[2]); - step[3] = vsubq_s16(x[1], s[2]); - step[4] = vsubq_s16(x[2], s[5]); - step[5] = vaddq_s16(x[2], s[5]); - step[6] = vsubq_s16(s[7], s[6]); - step[7] = vaddq_s16(s[7], s[6]); - - // step 6 - // out[1] = fdct_round_shift(step1[0] * cospi_30_64 + step1[7] * cospi_2_64) - // out[9] = fdct_round_shift(step1[1] * cospi_14_64 + step1[6] * cospi_18_64) - // out[5] = fdct_round_shift(step1[2] * cospi_22_64 + step1[5] * cospi_10_64) - // out[13] = fdct_round_shift(step1[3] * cospi_6_64 + step1[4] * cospi_26_64) - // out[3] = fdct_round_shift(step1[3] * -cospi_26_64 + step1[4] * cospi_6_64) - // out[11] = fdct_round_shift(step1[2] * -cospi_10_64 + step1[5] * - // cospi_22_64) - // out[7] = fdct_round_shift(step1[1] * -cospi_18_64 + step1[6] * cospi_14_64) - // out[15] = fdct_round_shift(step1[0] * -cospi_2_64 + step1[7] * cospi_30_64) - butterfly_two_coeff(step[6], step[1], cospi_14_64, cospi_18_64, &out[9], - &out[7]); - butterfly_two_coeff(step[7], step[0], cospi_30_64, cospi_2_64, &out[1], - &out[15]); - butterfly_two_coeff(step[4], step[3], cospi_6_64, cospi_26_64, &out[13], - &out[3]); - butterfly_two_coeff(step[5], step[2], cospi_22_64, cospi_10_64, &out[5], - &out[11]); +// Store 16 32x4 vectors, assuming stride == 16. +static INLINE void store16_s32(tran_low_t *a, const int32x4_t *b /*[32]*/) { + vst1q_s32(a, b[0]); + a += 16; + vst1q_s32(a, b[1]); + a += 16; + vst1q_s32(a, b[2]); + a += 16; + vst1q_s32(a, b[3]); + a += 16; + vst1q_s32(a, b[4]); + a += 16; + vst1q_s32(a, b[5]); + a += 16; + vst1q_s32(a, b[6]); + a += 16; + vst1q_s32(a, b[7]); + a += 16; + vst1q_s32(a, b[8]); + a += 16; + vst1q_s32(a, b[9]); + a += 16; + vst1q_s32(a, b[10]); + a += 16; + vst1q_s32(a, b[11]); + a += 16; + vst1q_s32(a, b[12]); + a += 16; + vst1q_s32(a, b[13]); + a += 16; + vst1q_s32(a, b[14]); + a += 16; + vst1q_s32(a, b[15]); } +#endif // CONFIG_VP9_HIGHBITDEPTH + #endif // VPX_VPX_DSP_ARM_FDCT16X16_NEON_H_ diff --git a/libs/libvpx/vpx_dsp/arm/fdct32x32_neon.c b/libs/libvpx/vpx_dsp/arm/fdct32x32_neon.c index de74e6630b..448fa941ba 100644 --- a/libs/libvpx/vpx_dsp/arm/fdct32x32_neon.c +++ b/libs/libvpx/vpx_dsp/arm/fdct32x32_neon.c @@ -15,6 +15,8 @@ #include "vpx_dsp/txfm_common.h" #include "vpx_dsp/arm/mem_neon.h" #include "vpx_dsp/arm/transpose_neon.h" +#include "vpx_dsp/arm/fdct_neon.h" +#include "vpx_dsp/arm/fdct32x32_neon.h" // Most gcc 4.9 distributions outside of Android do not generate correct code // for this function. @@ -32,1287 +34,105 @@ void vpx_fdct32x32_rd_neon(const int16_t *input, tran_low_t *output, #else -#define LOAD_INCREMENT(src, stride, dest, index) \ - do { \ - dest[index] = vld1q_s16(src); \ - src += stride; \ - } while (0) - -#define ADD_S16(src, index0, index1, dest, index3) \ - do { \ - dest[index3] = vaddq_s16(src[index0], src[index1]); \ - } while (0) - -#define ADD_SHIFT_S16(src, index0, index1) \ - do { \ - src[index1] = vshlq_n_s16(vsubq_s16(src[index0], src[index1]), 2); \ - } while (0) - -// Load, cross, and multiply by 4. Load the first 8 and last 8, then the -// middle -// 16. Doing sets of 16 at a time. Maybe sets of 8 would be better? -static INLINE void load(const int16_t *a, int stride, int16x8_t *b) { - const int16_t *a_end = a + 24 * stride; - int16x8_t c[8]; - - LOAD_INCREMENT(a, stride, b, 0); - LOAD_INCREMENT(a, stride, b, 1); - LOAD_INCREMENT(a, stride, b, 2); - LOAD_INCREMENT(a, stride, b, 3); - LOAD_INCREMENT(a, stride, b, 4); - LOAD_INCREMENT(a, stride, b, 5); - LOAD_INCREMENT(a, stride, b, 6); - LOAD_INCREMENT(a, stride, b, 7); - - LOAD_INCREMENT(a_end, stride, b, 24); - LOAD_INCREMENT(a_end, stride, b, 25); - LOAD_INCREMENT(a_end, stride, b, 26); - LOAD_INCREMENT(a_end, stride, b, 27); - LOAD_INCREMENT(a_end, stride, b, 28); - LOAD_INCREMENT(a_end, stride, b, 29); - LOAD_INCREMENT(a_end, stride, b, 30); - LOAD_INCREMENT(a_end, stride, b, 31); - - ADD_S16(b, 0, 31, c, 0); - ADD_S16(b, 1, 30, c, 1); - ADD_S16(b, 2, 29, c, 2); - ADD_S16(b, 3, 28, c, 3); - ADD_S16(b, 4, 27, c, 4); - ADD_S16(b, 5, 26, c, 5); - ADD_S16(b, 6, 25, c, 6); - ADD_S16(b, 7, 24, c, 7); - - ADD_SHIFT_S16(b, 7, 24); - ADD_SHIFT_S16(b, 6, 25); - ADD_SHIFT_S16(b, 5, 26); - ADD_SHIFT_S16(b, 4, 27); - ADD_SHIFT_S16(b, 3, 28); - ADD_SHIFT_S16(b, 2, 29); - ADD_SHIFT_S16(b, 1, 30); - ADD_SHIFT_S16(b, 0, 31); - - b[0] = vshlq_n_s16(c[0], 2); - b[1] = vshlq_n_s16(c[1], 2); - b[2] = vshlq_n_s16(c[2], 2); - b[3] = vshlq_n_s16(c[3], 2); - b[4] = vshlq_n_s16(c[4], 2); - b[5] = vshlq_n_s16(c[5], 2); - b[6] = vshlq_n_s16(c[6], 2); - b[7] = vshlq_n_s16(c[7], 2); - - LOAD_INCREMENT(a, stride, b, 8); - LOAD_INCREMENT(a, stride, b, 9); - LOAD_INCREMENT(a, stride, b, 10); - LOAD_INCREMENT(a, stride, b, 11); - LOAD_INCREMENT(a, stride, b, 12); - LOAD_INCREMENT(a, stride, b, 13); - LOAD_INCREMENT(a, stride, b, 14); - LOAD_INCREMENT(a, stride, b, 15); - LOAD_INCREMENT(a, stride, b, 16); - LOAD_INCREMENT(a, stride, b, 17); - LOAD_INCREMENT(a, stride, b, 18); - LOAD_INCREMENT(a, stride, b, 19); - LOAD_INCREMENT(a, stride, b, 20); - LOAD_INCREMENT(a, stride, b, 21); - LOAD_INCREMENT(a, stride, b, 22); - LOAD_INCREMENT(a, stride, b, 23); - - ADD_S16(b, 8, 23, c, 0); - ADD_S16(b, 9, 22, c, 1); - ADD_S16(b, 10, 21, c, 2); - ADD_S16(b, 11, 20, c, 3); - ADD_S16(b, 12, 19, c, 4); - ADD_S16(b, 13, 18, c, 5); - ADD_S16(b, 14, 17, c, 6); - ADD_S16(b, 15, 16, c, 7); - - ADD_SHIFT_S16(b, 15, 16); - ADD_SHIFT_S16(b, 14, 17); - ADD_SHIFT_S16(b, 13, 18); - ADD_SHIFT_S16(b, 12, 19); - ADD_SHIFT_S16(b, 11, 20); - ADD_SHIFT_S16(b, 10, 21); - ADD_SHIFT_S16(b, 9, 22); - ADD_SHIFT_S16(b, 8, 23); - - b[8] = vshlq_n_s16(c[0], 2); - b[9] = vshlq_n_s16(c[1], 2); - b[10] = vshlq_n_s16(c[2], 2); - b[11] = vshlq_n_s16(c[3], 2); - b[12] = vshlq_n_s16(c[4], 2); - b[13] = vshlq_n_s16(c[5], 2); - b[14] = vshlq_n_s16(c[6], 2); - b[15] = vshlq_n_s16(c[7], 2); -} - -#undef LOAD_INCREMENT -#undef ADD_S16 -#undef ADD_SHIFT_S16 - -#define STORE_S16(src, index, dest) \ - do { \ - store_s16q_to_tran_low(dest, src[index]); \ - dest += 8; \ - } while (0) - -// Store 32 16x8 values, assuming stride == 32. -// Slight twist: store horizontally in blocks of 8. -static INLINE void store(tran_low_t *a, const int16x8_t *b) { - STORE_S16(b, 0, a); - STORE_S16(b, 8, a); - STORE_S16(b, 16, a); - STORE_S16(b, 24, a); - STORE_S16(b, 1, a); - STORE_S16(b, 9, a); - STORE_S16(b, 17, a); - STORE_S16(b, 25, a); - STORE_S16(b, 2, a); - STORE_S16(b, 10, a); - STORE_S16(b, 18, a); - STORE_S16(b, 26, a); - STORE_S16(b, 3, a); - STORE_S16(b, 11, a); - STORE_S16(b, 19, a); - STORE_S16(b, 27, a); - STORE_S16(b, 4, a); - STORE_S16(b, 12, a); - STORE_S16(b, 20, a); - STORE_S16(b, 28, a); - STORE_S16(b, 5, a); - STORE_S16(b, 13, a); - STORE_S16(b, 21, a); - STORE_S16(b, 29, a); - STORE_S16(b, 6, a); - STORE_S16(b, 14, a); - STORE_S16(b, 22, a); - STORE_S16(b, 30, a); - STORE_S16(b, 7, a); - STORE_S16(b, 15, a); - STORE_S16(b, 23, a); - STORE_S16(b, 31, a); -} - -#undef STORE_S16 - -// fdct_round_shift((a +/- b) * c) -static INLINE void butterfly_one_coeff(const int16x8_t a, const int16x8_t b, - const tran_high_t constant, - int16x8_t *add, int16x8_t *sub) { - const int32x4_t a0 = vmull_n_s16(vget_low_s16(a), constant); - const int32x4_t a1 = vmull_n_s16(vget_high_s16(a), constant); - const int32x4_t sum0 = vmlal_n_s16(a0, vget_low_s16(b), constant); - const int32x4_t sum1 = vmlal_n_s16(a1, vget_high_s16(b), constant); - const int32x4_t diff0 = vmlsl_n_s16(a0, vget_low_s16(b), constant); - const int32x4_t diff1 = vmlsl_n_s16(a1, vget_high_s16(b), constant); - const int16x4_t rounded0 = vqrshrn_n_s32(sum0, DCT_CONST_BITS); - const int16x4_t rounded1 = vqrshrn_n_s32(sum1, DCT_CONST_BITS); - const int16x4_t rounded2 = vqrshrn_n_s32(diff0, DCT_CONST_BITS); - const int16x4_t rounded3 = vqrshrn_n_s32(diff1, DCT_CONST_BITS); - *add = vcombine_s16(rounded0, rounded1); - *sub = vcombine_s16(rounded2, rounded3); -} - -// fdct_round_shift(a * c0 +/- b * c1) -static INLINE void butterfly_two_coeff(const int16x8_t a, const int16x8_t b, - const tran_coef_t constant0, - const tran_coef_t constant1, - int16x8_t *add, int16x8_t *sub) { - const int32x4_t a0 = vmull_n_s16(vget_low_s16(a), constant0); - const int32x4_t a1 = vmull_n_s16(vget_high_s16(a), constant0); - const int32x4_t a2 = vmull_n_s16(vget_low_s16(a), constant1); - const int32x4_t a3 = vmull_n_s16(vget_high_s16(a), constant1); - const int32x4_t sum0 = vmlal_n_s16(a2, vget_low_s16(b), constant0); - const int32x4_t sum1 = vmlal_n_s16(a3, vget_high_s16(b), constant0); - const int32x4_t diff0 = vmlsl_n_s16(a0, vget_low_s16(b), constant1); - const int32x4_t diff1 = vmlsl_n_s16(a1, vget_high_s16(b), constant1); - const int16x4_t rounded0 = vqrshrn_n_s32(sum0, DCT_CONST_BITS); - const int16x4_t rounded1 = vqrshrn_n_s32(sum1, DCT_CONST_BITS); - const int16x4_t rounded2 = vqrshrn_n_s32(diff0, DCT_CONST_BITS); - const int16x4_t rounded3 = vqrshrn_n_s32(diff1, DCT_CONST_BITS); - *add = vcombine_s16(rounded0, rounded1); - *sub = vcombine_s16(rounded2, rounded3); -} - -// Add 2 if positive, 1 if negative, and shift by 2. -// In practice, subtract the sign bit, then shift with rounding. -static INLINE int16x8_t sub_round_shift(const int16x8_t a) { - const uint16x8_t a_u16 = vreinterpretq_u16_s16(a); - const uint16x8_t a_sign_u16 = vshrq_n_u16(a_u16, 15); - const int16x8_t a_sign_s16 = vreinterpretq_s16_u16(a_sign_u16); - return vrshrq_n_s16(vsubq_s16(a, a_sign_s16), 2); -} - -static void dct_body_first_pass(const int16x8_t *in, int16x8_t *out) { - int16x8_t a[32]; - int16x8_t b[32]; - - // Stage 1: Done as part of the load. - - // Stage 2. - // Mini cross. X the first 16 values and the middle 8 of the second half. - a[0] = vaddq_s16(in[0], in[15]); - a[1] = vaddq_s16(in[1], in[14]); - a[2] = vaddq_s16(in[2], in[13]); - a[3] = vaddq_s16(in[3], in[12]); - a[4] = vaddq_s16(in[4], in[11]); - a[5] = vaddq_s16(in[5], in[10]); - a[6] = vaddq_s16(in[6], in[9]); - a[7] = vaddq_s16(in[7], in[8]); - - a[8] = vsubq_s16(in[7], in[8]); - a[9] = vsubq_s16(in[6], in[9]); - a[10] = vsubq_s16(in[5], in[10]); - a[11] = vsubq_s16(in[4], in[11]); - a[12] = vsubq_s16(in[3], in[12]); - a[13] = vsubq_s16(in[2], in[13]); - a[14] = vsubq_s16(in[1], in[14]); - a[15] = vsubq_s16(in[0], in[15]); - - a[16] = in[16]; - a[17] = in[17]; - a[18] = in[18]; - a[19] = in[19]; - - butterfly_one_coeff(in[27], in[20], cospi_16_64, &a[27], &a[20]); - butterfly_one_coeff(in[26], in[21], cospi_16_64, &a[26], &a[21]); - butterfly_one_coeff(in[25], in[22], cospi_16_64, &a[25], &a[22]); - butterfly_one_coeff(in[24], in[23], cospi_16_64, &a[24], &a[23]); - - a[28] = in[28]; - a[29] = in[29]; - a[30] = in[30]; - a[31] = in[31]; - - // Stage 3. - b[0] = vaddq_s16(a[0], a[7]); - b[1] = vaddq_s16(a[1], a[6]); - b[2] = vaddq_s16(a[2], a[5]); - b[3] = vaddq_s16(a[3], a[4]); - - b[4] = vsubq_s16(a[3], a[4]); - b[5] = vsubq_s16(a[2], a[5]); - b[6] = vsubq_s16(a[1], a[6]); - b[7] = vsubq_s16(a[0], a[7]); - - b[8] = a[8]; - b[9] = a[9]; - - butterfly_one_coeff(a[13], a[10], cospi_16_64, &b[13], &b[10]); - butterfly_one_coeff(a[12], a[11], cospi_16_64, &b[12], &b[11]); - - b[14] = a[14]; - b[15] = a[15]; - - b[16] = vaddq_s16(in[16], a[23]); - b[17] = vaddq_s16(in[17], a[22]); - b[18] = vaddq_s16(in[18], a[21]); - b[19] = vaddq_s16(in[19], a[20]); - - b[20] = vsubq_s16(in[19], a[20]); - b[21] = vsubq_s16(in[18], a[21]); - b[22] = vsubq_s16(in[17], a[22]); - b[23] = vsubq_s16(in[16], a[23]); - - b[24] = vsubq_s16(in[31], a[24]); - b[25] = vsubq_s16(in[30], a[25]); - b[26] = vsubq_s16(in[29], a[26]); - b[27] = vsubq_s16(in[28], a[27]); - - b[28] = vaddq_s16(in[28], a[27]); - b[29] = vaddq_s16(in[29], a[26]); - b[30] = vaddq_s16(in[30], a[25]); - b[31] = vaddq_s16(in[31], a[24]); - - // Stage 4. - a[0] = vaddq_s16(b[0], b[3]); - a[1] = vaddq_s16(b[1], b[2]); - a[2] = vsubq_s16(b[1], b[2]); - a[3] = vsubq_s16(b[0], b[3]); - - a[4] = b[4]; - - butterfly_one_coeff(b[6], b[5], cospi_16_64, &a[6], &a[5]); - - a[7] = b[7]; - - a[8] = vaddq_s16(b[8], b[11]); - a[9] = vaddq_s16(b[9], b[10]); - a[10] = vsubq_s16(b[9], b[10]); - a[11] = vsubq_s16(b[8], b[11]); - a[12] = vsubq_s16(b[15], b[12]); - a[13] = vsubq_s16(b[14], b[13]); - a[14] = vaddq_s16(b[14], b[13]); - a[15] = vaddq_s16(b[15], b[12]); - - a[16] = b[16]; - a[17] = b[17]; - - butterfly_two_coeff(b[29], b[18], cospi_24_64, cospi_8_64, &a[29], &a[18]); - butterfly_two_coeff(b[28], b[19], cospi_24_64, cospi_8_64, &a[28], &a[19]); - butterfly_two_coeff(b[27], b[20], -cospi_8_64, cospi_24_64, &a[27], &a[20]); - butterfly_two_coeff(b[26], b[21], -cospi_8_64, cospi_24_64, &a[26], &a[21]); - - a[22] = b[22]; - a[23] = b[23]; - a[24] = b[24]; - a[25] = b[25]; - - a[30] = b[30]; - a[31] = b[31]; - - // Stage 5. - butterfly_one_coeff(a[0], a[1], cospi_16_64, &b[0], &b[1]); - butterfly_two_coeff(a[3], a[2], cospi_24_64, cospi_8_64, &b[2], &b[3]); - - b[4] = vaddq_s16(a[4], a[5]); - b[5] = vsubq_s16(a[4], a[5]); - b[6] = vsubq_s16(a[7], a[6]); - b[7] = vaddq_s16(a[7], a[6]); - - b[8] = a[8]; - - butterfly_two_coeff(a[14], a[9], cospi_24_64, cospi_8_64, &b[14], &b[9]); - butterfly_two_coeff(a[13], a[10], -cospi_8_64, cospi_24_64, &b[13], &b[10]); - - b[11] = a[11]; - b[12] = a[12]; - - b[15] = a[15]; - - b[16] = vaddq_s16(a[19], a[16]); - b[17] = vaddq_s16(a[18], a[17]); - b[18] = vsubq_s16(a[17], a[18]); - b[19] = vsubq_s16(a[16], a[19]); - b[20] = vsubq_s16(a[23], a[20]); - b[21] = vsubq_s16(a[22], a[21]); - b[22] = vaddq_s16(a[21], a[22]); - b[23] = vaddq_s16(a[20], a[23]); - b[24] = vaddq_s16(a[27], a[24]); - b[25] = vaddq_s16(a[26], a[25]); - b[26] = vsubq_s16(a[25], a[26]); - b[27] = vsubq_s16(a[24], a[27]); - b[28] = vsubq_s16(a[31], a[28]); - b[29] = vsubq_s16(a[30], a[29]); - b[30] = vaddq_s16(a[29], a[30]); - b[31] = vaddq_s16(a[28], a[31]); - - // Stage 6. - a[0] = b[0]; - a[1] = b[1]; - a[2] = b[2]; - a[3] = b[3]; - - butterfly_two_coeff(b[7], b[4], cospi_28_64, cospi_4_64, &a[4], &a[7]); - butterfly_two_coeff(b[6], b[5], cospi_12_64, cospi_20_64, &a[5], &a[6]); - - a[8] = vaddq_s16(b[8], b[9]); - a[9] = vsubq_s16(b[8], b[9]); - a[10] = vsubq_s16(b[11], b[10]); - a[11] = vaddq_s16(b[11], b[10]); - a[12] = vaddq_s16(b[12], b[13]); - a[13] = vsubq_s16(b[12], b[13]); - a[14] = vsubq_s16(b[15], b[14]); - a[15] = vaddq_s16(b[15], b[14]); - - a[16] = b[16]; - a[19] = b[19]; - a[20] = b[20]; - a[23] = b[23]; - a[24] = b[24]; - a[27] = b[27]; - a[28] = b[28]; - a[31] = b[31]; - - butterfly_two_coeff(b[30], b[17], cospi_28_64, cospi_4_64, &a[30], &a[17]); - butterfly_two_coeff(b[29], b[18], -cospi_4_64, cospi_28_64, &a[29], &a[18]); - - butterfly_two_coeff(b[26], b[21], cospi_12_64, cospi_20_64, &a[26], &a[21]); - butterfly_two_coeff(b[25], b[22], -cospi_20_64, cospi_12_64, &a[25], &a[22]); - - // Stage 7. - b[0] = a[0]; - b[1] = a[1]; - b[2] = a[2]; - b[3] = a[3]; - b[4] = a[4]; - b[5] = a[5]; - b[6] = a[6]; - b[7] = a[7]; - - butterfly_two_coeff(a[15], a[8], cospi_30_64, cospi_2_64, &b[8], &b[15]); - butterfly_two_coeff(a[14], a[9], cospi_14_64, cospi_18_64, &b[9], &b[14]); - butterfly_two_coeff(a[13], a[10], cospi_22_64, cospi_10_64, &b[10], &b[13]); - butterfly_two_coeff(a[12], a[11], cospi_6_64, cospi_26_64, &b[11], &b[12]); - - b[16] = vaddq_s16(a[16], a[17]); - b[17] = vsubq_s16(a[16], a[17]); - b[18] = vsubq_s16(a[19], a[18]); - b[19] = vaddq_s16(a[19], a[18]); - b[20] = vaddq_s16(a[20], a[21]); - b[21] = vsubq_s16(a[20], a[21]); - b[22] = vsubq_s16(a[23], a[22]); - b[23] = vaddq_s16(a[23], a[22]); - b[24] = vaddq_s16(a[24], a[25]); - b[25] = vsubq_s16(a[24], a[25]); - b[26] = vsubq_s16(a[27], a[26]); - b[27] = vaddq_s16(a[27], a[26]); - b[28] = vaddq_s16(a[28], a[29]); - b[29] = vsubq_s16(a[28], a[29]); - b[30] = vsubq_s16(a[31], a[30]); - b[31] = vaddq_s16(a[31], a[30]); - - // Final stage. - // Also compute partial rounding shift: - // output[j * 32 + i] = (temp_out[j] + 1 + (temp_out[j] > 0)) >> 2; - out[0] = sub_round_shift(b[0]); - out[16] = sub_round_shift(b[1]); - out[8] = sub_round_shift(b[2]); - out[24] = sub_round_shift(b[3]); - out[4] = sub_round_shift(b[4]); - out[20] = sub_round_shift(b[5]); - out[12] = sub_round_shift(b[6]); - out[28] = sub_round_shift(b[7]); - out[2] = sub_round_shift(b[8]); - out[18] = sub_round_shift(b[9]); - out[10] = sub_round_shift(b[10]); - out[26] = sub_round_shift(b[11]); - out[6] = sub_round_shift(b[12]); - out[22] = sub_round_shift(b[13]); - out[14] = sub_round_shift(b[14]); - out[30] = sub_round_shift(b[15]); - - butterfly_two_coeff(b[31], b[16], cospi_31_64, cospi_1_64, &a[1], &a[31]); - out[1] = sub_round_shift(a[1]); - out[31] = sub_round_shift(a[31]); - - butterfly_two_coeff(b[30], b[17], cospi_15_64, cospi_17_64, &a[17], &a[15]); - out[17] = sub_round_shift(a[17]); - out[15] = sub_round_shift(a[15]); - - butterfly_two_coeff(b[29], b[18], cospi_23_64, cospi_9_64, &a[9], &a[23]); - out[9] = sub_round_shift(a[9]); - out[23] = sub_round_shift(a[23]); - - butterfly_two_coeff(b[28], b[19], cospi_7_64, cospi_25_64, &a[25], &a[7]); - out[25] = sub_round_shift(a[25]); - out[7] = sub_round_shift(a[7]); - - butterfly_two_coeff(b[27], b[20], cospi_27_64, cospi_5_64, &a[5], &a[27]); - out[5] = sub_round_shift(a[5]); - out[27] = sub_round_shift(a[27]); - - butterfly_two_coeff(b[26], b[21], cospi_11_64, cospi_21_64, &a[21], &a[11]); - out[21] = sub_round_shift(a[21]); - out[11] = sub_round_shift(a[11]); - - butterfly_two_coeff(b[25], b[22], cospi_19_64, cospi_13_64, &a[13], &a[19]); - out[13] = sub_round_shift(a[13]); - out[19] = sub_round_shift(a[19]); - - butterfly_two_coeff(b[24], b[23], cospi_3_64, cospi_29_64, &a[29], &a[3]); - out[29] = sub_round_shift(a[29]); - out[3] = sub_round_shift(a[3]); -} - -#define PASS_THROUGH(src, dst, element) \ - do { \ - dst##_lo[element] = src##_lo[element]; \ - dst##_hi[element] = src##_hi[element]; \ - } while (0) - -#define ADD_S16_S32(a, left_index, right_index, b, b_index) \ - do { \ - b##_lo[b_index] = \ - vaddl_s16(vget_low_s16(a[left_index]), vget_low_s16(a[right_index])); \ - b##_hi[b_index] = vaddl_s16(vget_high_s16(a[left_index]), \ - vget_high_s16(a[right_index])); \ - } while (0) - -#define SUB_S16_S32(a, left_index, right_index, b, b_index) \ - do { \ - b##_lo[b_index] = \ - vsubl_s16(vget_low_s16(a[left_index]), vget_low_s16(a[right_index])); \ - b##_hi[b_index] = vsubl_s16(vget_high_s16(a[left_index]), \ - vget_high_s16(a[right_index])); \ - } while (0) - -#define ADDW_S16_S32(a, a_index, b, b_index, c, c_index) \ - do { \ - c##_lo[c_index] = vaddw_s16(a##_lo[a_index], vget_low_s16(b[b_index])); \ - c##_hi[c_index] = vaddw_s16(a##_hi[a_index], vget_high_s16(b[b_index])); \ - } while (0) - -#define SUBW_S16_S32(a, a_index, b, b_index, temp, temp_index, c, c_index) \ - do { \ - temp##_lo[temp_index] = vmovl_s16(vget_low_s16(a[a_index])); \ - temp##_hi[temp_index] = vmovl_s16(vget_high_s16(a[a_index])); \ - c##_lo[c_index] = vsubq_s32(temp##_lo[temp_index], b##_lo[b_index]); \ - c##_hi[c_index] = vsubq_s32(temp##_hi[temp_index], b##_hi[b_index]); \ - } while (0) - -#define ADD_S32(a, left_index, right_index, b, b_index) \ - do { \ - b##_lo[b_index] = vaddq_s32(a##_lo[left_index], a##_lo[right_index]); \ - b##_hi[b_index] = vaddq_s32(a##_hi[left_index], a##_hi[right_index]); \ - } while (0) - -#define SUB_S32(a, left_index, right_index, b, b_index) \ - do { \ - b##_lo[b_index] = vsubq_s32(a##_lo[left_index], a##_lo[right_index]); \ - b##_hi[b_index] = vsubq_s32(a##_hi[left_index], a##_hi[right_index]); \ - } while (0) - -// Like butterfly_one_coeff, but don't narrow results. -static INLINE void butterfly_one_coeff_s16_s32( - const int16x8_t a, const int16x8_t b, const tran_high_t constant, - int32x4_t *add_lo, int32x4_t *add_hi, int32x4_t *sub_lo, - int32x4_t *sub_hi) { - const int32x4_t a0 = vmull_n_s16(vget_low_s16(a), constant); - const int32x4_t a1 = vmull_n_s16(vget_high_s16(a), constant); - const int32x4_t sum0 = vmlal_n_s16(a0, vget_low_s16(b), constant); - const int32x4_t sum1 = vmlal_n_s16(a1, vget_high_s16(b), constant); - const int32x4_t diff0 = vmlsl_n_s16(a0, vget_low_s16(b), constant); - const int32x4_t diff1 = vmlsl_n_s16(a1, vget_high_s16(b), constant); - *add_lo = vrshrq_n_s32(sum0, DCT_CONST_BITS); - *add_hi = vrshrq_n_s32(sum1, DCT_CONST_BITS); - *sub_lo = vrshrq_n_s32(diff0, DCT_CONST_BITS); - *sub_hi = vrshrq_n_s32(diff1, DCT_CONST_BITS); -} - -#define BUTTERFLY_ONE_S16_S32(a, left_index, right_index, constant, b, \ - add_index, sub_index) \ - do { \ - butterfly_one_coeff_s16_s32(a[left_index], a[right_index], constant, \ - &b##_lo[add_index], &b##_hi[add_index], \ - &b##_lo[sub_index], &b##_hi[sub_index]); \ - } while (0) - -// Like butterfly_one_coeff, but with s32. -static INLINE void butterfly_one_coeff_s32( - const int32x4_t a_lo, const int32x4_t a_hi, const int32x4_t b_lo, - const int32x4_t b_hi, const int32_t constant, int32x4_t *add_lo, - int32x4_t *add_hi, int32x4_t *sub_lo, int32x4_t *sub_hi) { - const int32x4_t a_lo_0 = vmulq_n_s32(a_lo, constant); - const int32x4_t a_hi_0 = vmulq_n_s32(a_hi, constant); - const int32x4_t sum0 = vmlaq_n_s32(a_lo_0, b_lo, constant); - const int32x4_t sum1 = vmlaq_n_s32(a_hi_0, b_hi, constant); - const int32x4_t diff0 = vmlsq_n_s32(a_lo_0, b_lo, constant); - const int32x4_t diff1 = vmlsq_n_s32(a_hi_0, b_hi, constant); - *add_lo = vrshrq_n_s32(sum0, DCT_CONST_BITS); - *add_hi = vrshrq_n_s32(sum1, DCT_CONST_BITS); - *sub_lo = vrshrq_n_s32(diff0, DCT_CONST_BITS); - *sub_hi = vrshrq_n_s32(diff1, DCT_CONST_BITS); -} - -#define BUTTERFLY_ONE_S32(a, left_index, right_index, constant, b, add_index, \ - sub_index) \ - do { \ - butterfly_one_coeff_s32(a##_lo[left_index], a##_hi[left_index], \ - a##_lo[right_index], a##_hi[right_index], \ - constant, &b##_lo[add_index], &b##_hi[add_index], \ - &b##_lo[sub_index], &b##_hi[sub_index]); \ - } while (0) - -// Like butterfly_two_coeff, but with s32. -static INLINE void butterfly_two_coeff_s32( - const int32x4_t a_lo, const int32x4_t a_hi, const int32x4_t b_lo, - const int32x4_t b_hi, const int32_t constant0, const int32_t constant1, - int32x4_t *add_lo, int32x4_t *add_hi, int32x4_t *sub_lo, - int32x4_t *sub_hi) { - const int32x4_t a0 = vmulq_n_s32(a_lo, constant0); - const int32x4_t a1 = vmulq_n_s32(a_hi, constant0); - const int32x4_t a2 = vmulq_n_s32(a_lo, constant1); - const int32x4_t a3 = vmulq_n_s32(a_hi, constant1); - const int32x4_t sum0 = vmlaq_n_s32(a2, b_lo, constant0); - const int32x4_t sum1 = vmlaq_n_s32(a3, b_hi, constant0); - const int32x4_t diff0 = vmlsq_n_s32(a0, b_lo, constant1); - const int32x4_t diff1 = vmlsq_n_s32(a1, b_hi, constant1); - *add_lo = vrshrq_n_s32(sum0, DCT_CONST_BITS); - *add_hi = vrshrq_n_s32(sum1, DCT_CONST_BITS); - *sub_lo = vrshrq_n_s32(diff0, DCT_CONST_BITS); - *sub_hi = vrshrq_n_s32(diff1, DCT_CONST_BITS); -} - -#define BUTTERFLY_TWO_S32(a, left_index, right_index, left_constant, \ - right_constant, b, add_index, sub_index) \ - do { \ - butterfly_two_coeff_s32(a##_lo[left_index], a##_hi[left_index], \ - a##_lo[right_index], a##_hi[right_index], \ - left_constant, right_constant, &b##_lo[add_index], \ - &b##_hi[add_index], &b##_lo[sub_index], \ - &b##_hi[sub_index]); \ - } while (0) - -// Add 1 if positive, 2 if negative, and shift by 2. -// In practice, add 1, then add the sign bit, then shift without rounding. -static INLINE int16x8_t add_round_shift_s32(const int32x4_t a_lo, - const int32x4_t a_hi) { - const int32x4_t one = vdupq_n_s32(1); - const uint32x4_t a_lo_u32 = vreinterpretq_u32_s32(a_lo); - const uint32x4_t a_lo_sign_u32 = vshrq_n_u32(a_lo_u32, 31); - const int32x4_t a_lo_sign_s32 = vreinterpretq_s32_u32(a_lo_sign_u32); - const int16x4_t b_lo = - vshrn_n_s32(vqaddq_s32(vqaddq_s32(a_lo, a_lo_sign_s32), one), 2); - const uint32x4_t a_hi_u32 = vreinterpretq_u32_s32(a_hi); - const uint32x4_t a_hi_sign_u32 = vshrq_n_u32(a_hi_u32, 31); - const int32x4_t a_hi_sign_s32 = vreinterpretq_s32_u32(a_hi_sign_u32); - const int16x4_t b_hi = - vshrn_n_s32(vqaddq_s32(vqaddq_s32(a_hi, a_hi_sign_s32), one), 2); - return vcombine_s16(b_lo, b_hi); -} - -static void dct_body_second_pass(const int16x8_t *in, int16x8_t *out) { - int16x8_t a[32]; - int16x8_t b[32]; - int32x4_t c_lo[32]; - int32x4_t c_hi[32]; - int32x4_t d_lo[32]; - int32x4_t d_hi[32]; - - // Stage 1. Done as part of the load for the first pass. - a[0] = vaddq_s16(in[0], in[31]); - a[1] = vaddq_s16(in[1], in[30]); - a[2] = vaddq_s16(in[2], in[29]); - a[3] = vaddq_s16(in[3], in[28]); - a[4] = vaddq_s16(in[4], in[27]); - a[5] = vaddq_s16(in[5], in[26]); - a[6] = vaddq_s16(in[6], in[25]); - a[7] = vaddq_s16(in[7], in[24]); - a[8] = vaddq_s16(in[8], in[23]); - a[9] = vaddq_s16(in[9], in[22]); - a[10] = vaddq_s16(in[10], in[21]); - a[11] = vaddq_s16(in[11], in[20]); - a[12] = vaddq_s16(in[12], in[19]); - a[13] = vaddq_s16(in[13], in[18]); - a[14] = vaddq_s16(in[14], in[17]); - a[15] = vaddq_s16(in[15], in[16]); - a[16] = vsubq_s16(in[15], in[16]); - a[17] = vsubq_s16(in[14], in[17]); - a[18] = vsubq_s16(in[13], in[18]); - a[19] = vsubq_s16(in[12], in[19]); - a[20] = vsubq_s16(in[11], in[20]); - a[21] = vsubq_s16(in[10], in[21]); - a[22] = vsubq_s16(in[9], in[22]); - a[23] = vsubq_s16(in[8], in[23]); - a[24] = vsubq_s16(in[7], in[24]); - a[25] = vsubq_s16(in[6], in[25]); - a[26] = vsubq_s16(in[5], in[26]); - a[27] = vsubq_s16(in[4], in[27]); - a[28] = vsubq_s16(in[3], in[28]); - a[29] = vsubq_s16(in[2], in[29]); - a[30] = vsubq_s16(in[1], in[30]); - a[31] = vsubq_s16(in[0], in[31]); - - // Stage 2. - b[0] = vaddq_s16(a[0], a[15]); - b[1] = vaddq_s16(a[1], a[14]); - b[2] = vaddq_s16(a[2], a[13]); - b[3] = vaddq_s16(a[3], a[12]); - b[4] = vaddq_s16(a[4], a[11]); - b[5] = vaddq_s16(a[5], a[10]); - b[6] = vaddq_s16(a[6], a[9]); - b[7] = vaddq_s16(a[7], a[8]); - - b[8] = vsubq_s16(a[7], a[8]); - b[9] = vsubq_s16(a[6], a[9]); - b[10] = vsubq_s16(a[5], a[10]); - b[11] = vsubq_s16(a[4], a[11]); - b[12] = vsubq_s16(a[3], a[12]); - b[13] = vsubq_s16(a[2], a[13]); - b[14] = vsubq_s16(a[1], a[14]); - b[15] = vsubq_s16(a[0], a[15]); - - b[16] = a[16]; - b[17] = a[17]; - b[18] = a[18]; - b[19] = a[19]; - - butterfly_one_coeff(a[27], a[20], cospi_16_64, &b[27], &b[20]); - butterfly_one_coeff(a[26], a[21], cospi_16_64, &b[26], &b[21]); - butterfly_one_coeff(a[25], a[22], cospi_16_64, &b[25], &b[22]); - butterfly_one_coeff(a[24], a[23], cospi_16_64, &b[24], &b[23]); - - b[28] = a[28]; - b[29] = a[29]; - b[30] = a[30]; - b[31] = a[31]; - - // Stage 3. With extreme values for input this calculation rolls over int16_t. - // The sources for b[0] get added multiple times and, through testing, have - // been shown to overflow starting here. - ADD_S16_S32(b, 0, 7, c, 0); - ADD_S16_S32(b, 1, 6, c, 1); - ADD_S16_S32(b, 2, 5, c, 2); - ADD_S16_S32(b, 3, 4, c, 3); - SUB_S16_S32(b, 3, 4, c, 4); - SUB_S16_S32(b, 2, 5, c, 5); - SUB_S16_S32(b, 1, 6, c, 6); - SUB_S16_S32(b, 0, 7, c, 7); - - a[8] = b[8]; - a[9] = b[9]; - - BUTTERFLY_ONE_S16_S32(b, 13, 10, cospi_16_64, c, 13, 10); - BUTTERFLY_ONE_S16_S32(b, 12, 11, cospi_16_64, c, 12, 11); - - a[14] = b[14]; - a[15] = b[15]; - - ADD_S16_S32(b, 16, 23, c, 16); - ADD_S16_S32(b, 17, 22, c, 17); - ADD_S16_S32(b, 18, 21, c, 18); - ADD_S16_S32(b, 19, 20, c, 19); - SUB_S16_S32(b, 19, 20, c, 20); - SUB_S16_S32(b, 18, 21, c, 21); - SUB_S16_S32(b, 17, 22, c, 22); - SUB_S16_S32(b, 16, 23, c, 23); - SUB_S16_S32(b, 31, 24, c, 24); - SUB_S16_S32(b, 30, 25, c, 25); - SUB_S16_S32(b, 29, 26, c, 26); - SUB_S16_S32(b, 28, 27, c, 27); - ADD_S16_S32(b, 28, 27, c, 28); - ADD_S16_S32(b, 29, 26, c, 29); - ADD_S16_S32(b, 30, 25, c, 30); - ADD_S16_S32(b, 31, 24, c, 31); - - // Stage 4. - ADD_S32(c, 0, 3, d, 0); - ADD_S32(c, 1, 2, d, 1); - SUB_S32(c, 1, 2, d, 2); - SUB_S32(c, 0, 3, d, 3); - - PASS_THROUGH(c, d, 4); - - BUTTERFLY_ONE_S32(c, 6, 5, cospi_16_64, d, 6, 5); - - PASS_THROUGH(c, d, 7); - - ADDW_S16_S32(c, 11, a, 8, d, 8); - ADDW_S16_S32(c, 10, a, 9, d, 9); - SUBW_S16_S32(a, 9, c, 10, c, 9, d, 10); - SUBW_S16_S32(a, 8, c, 11, c, 8, d, 11); - SUBW_S16_S32(a, 15, c, 12, c, 15, d, 12); - SUBW_S16_S32(a, 14, c, 13, c, 14, d, 13); - ADDW_S16_S32(c, 13, b, 14, d, 14); - ADDW_S16_S32(c, 12, b, 15, d, 15); - - PASS_THROUGH(c, d, 16); - PASS_THROUGH(c, d, 17); - - BUTTERFLY_TWO_S32(c, 29, 18, cospi_24_64, cospi_8_64, d, 29, 18); - BUTTERFLY_TWO_S32(c, 28, 19, cospi_24_64, cospi_8_64, d, 28, 19); - BUTTERFLY_TWO_S32(c, 27, 20, -cospi_8_64, cospi_24_64, d, 27, 20); - BUTTERFLY_TWO_S32(c, 26, 21, -cospi_8_64, cospi_24_64, d, 26, 21); - - PASS_THROUGH(c, d, 22); - PASS_THROUGH(c, d, 23); - PASS_THROUGH(c, d, 24); - PASS_THROUGH(c, d, 25); - - PASS_THROUGH(c, d, 30); - PASS_THROUGH(c, d, 31); - - // Stage 5. - BUTTERFLY_ONE_S32(d, 0, 1, cospi_16_64, c, 0, 1); - BUTTERFLY_TWO_S32(d, 3, 2, cospi_24_64, cospi_8_64, c, 2, 3); - - ADD_S32(d, 4, 5, c, 4); - SUB_S32(d, 4, 5, c, 5); - SUB_S32(d, 7, 6, c, 6); - ADD_S32(d, 7, 6, c, 7); - - PASS_THROUGH(d, c, 8); - - BUTTERFLY_TWO_S32(d, 14, 9, cospi_24_64, cospi_8_64, c, 14, 9); - BUTTERFLY_TWO_S32(d, 13, 10, -cospi_8_64, cospi_24_64, c, 13, 10); - - PASS_THROUGH(d, c, 11); - PASS_THROUGH(d, c, 12); - PASS_THROUGH(d, c, 15); - - ADD_S32(d, 16, 19, c, 16); - ADD_S32(d, 17, 18, c, 17); - SUB_S32(d, 17, 18, c, 18); - SUB_S32(d, 16, 19, c, 19); - SUB_S32(d, 23, 20, c, 20); - SUB_S32(d, 22, 21, c, 21); - ADD_S32(d, 22, 21, c, 22); - ADD_S32(d, 23, 20, c, 23); - ADD_S32(d, 24, 27, c, 24); - ADD_S32(d, 25, 26, c, 25); - SUB_S32(d, 25, 26, c, 26); - SUB_S32(d, 24, 27, c, 27); - SUB_S32(d, 31, 28, c, 28); - SUB_S32(d, 30, 29, c, 29); - ADD_S32(d, 30, 29, c, 30); - ADD_S32(d, 31, 28, c, 31); - - // Stage 6. - PASS_THROUGH(c, d, 0); - PASS_THROUGH(c, d, 1); - PASS_THROUGH(c, d, 2); - PASS_THROUGH(c, d, 3); - - BUTTERFLY_TWO_S32(c, 7, 4, cospi_28_64, cospi_4_64, d, 4, 7); - BUTTERFLY_TWO_S32(c, 6, 5, cospi_12_64, cospi_20_64, d, 5, 6); - - ADD_S32(c, 8, 9, d, 8); - SUB_S32(c, 8, 9, d, 9); - SUB_S32(c, 11, 10, d, 10); - ADD_S32(c, 11, 10, d, 11); - ADD_S32(c, 12, 13, d, 12); - SUB_S32(c, 12, 13, d, 13); - SUB_S32(c, 15, 14, d, 14); - ADD_S32(c, 15, 14, d, 15); - - PASS_THROUGH(c, d, 16); - PASS_THROUGH(c, d, 19); - PASS_THROUGH(c, d, 20); - PASS_THROUGH(c, d, 23); - PASS_THROUGH(c, d, 24); - PASS_THROUGH(c, d, 27); - PASS_THROUGH(c, d, 28); - PASS_THROUGH(c, d, 31); - - BUTTERFLY_TWO_S32(c, 30, 17, cospi_28_64, cospi_4_64, d, 30, 17); - BUTTERFLY_TWO_S32(c, 29, 18, -cospi_4_64, cospi_28_64, d, 29, 18); - BUTTERFLY_TWO_S32(c, 26, 21, cospi_12_64, cospi_20_64, d, 26, 21); - BUTTERFLY_TWO_S32(c, 25, 22, -cospi_20_64, cospi_12_64, d, 25, 22); - - // Stage 7. - PASS_THROUGH(d, c, 0); - PASS_THROUGH(d, c, 1); - PASS_THROUGH(d, c, 2); - PASS_THROUGH(d, c, 3); - PASS_THROUGH(d, c, 4); - PASS_THROUGH(d, c, 5); - PASS_THROUGH(d, c, 6); - PASS_THROUGH(d, c, 7); - - BUTTERFLY_TWO_S32(d, 15, 8, cospi_30_64, cospi_2_64, c, 8, 15); - BUTTERFLY_TWO_S32(d, 14, 9, cospi_14_64, cospi_18_64, c, 9, 14); - BUTTERFLY_TWO_S32(d, 13, 10, cospi_22_64, cospi_10_64, c, 10, 13); - BUTTERFLY_TWO_S32(d, 12, 11, cospi_6_64, cospi_26_64, c, 11, 12); - - ADD_S32(d, 16, 17, c, 16); - SUB_S32(d, 16, 17, c, 17); - SUB_S32(d, 19, 18, c, 18); - ADD_S32(d, 19, 18, c, 19); - ADD_S32(d, 20, 21, c, 20); - SUB_S32(d, 20, 21, c, 21); - SUB_S32(d, 23, 22, c, 22); - ADD_S32(d, 23, 22, c, 23); - ADD_S32(d, 24, 25, c, 24); - SUB_S32(d, 24, 25, c, 25); - SUB_S32(d, 27, 26, c, 26); - ADD_S32(d, 27, 26, c, 27); - ADD_S32(d, 28, 29, c, 28); - SUB_S32(d, 28, 29, c, 29); - SUB_S32(d, 31, 30, c, 30); - ADD_S32(d, 31, 30, c, 31); - - // Final stage. - // Roll rounding into this function so we can pass back int16x8. - - out[0] = add_round_shift_s32(c_lo[0], c_hi[0]); - out[16] = add_round_shift_s32(c_lo[1], c_hi[1]); - - out[8] = add_round_shift_s32(c_lo[2], c_hi[2]); - out[24] = add_round_shift_s32(c_lo[3], c_hi[3]); - out[4] = add_round_shift_s32(c_lo[4], c_hi[4]); - out[20] = add_round_shift_s32(c_lo[5], c_hi[5]); - out[12] = add_round_shift_s32(c_lo[6], c_hi[6]); - - out[28] = add_round_shift_s32(c_lo[7], c_hi[7]); - out[2] = add_round_shift_s32(c_lo[8], c_hi[8]); - out[18] = add_round_shift_s32(c_lo[9], c_hi[9]); - out[10] = add_round_shift_s32(c_lo[10], c_hi[10]); - - out[26] = add_round_shift_s32(c_lo[11], c_hi[11]); - out[6] = add_round_shift_s32(c_lo[12], c_hi[12]); - out[22] = add_round_shift_s32(c_lo[13], c_hi[13]); - out[14] = add_round_shift_s32(c_lo[14], c_hi[14]); - out[30] = add_round_shift_s32(c_lo[15], c_hi[15]); - - BUTTERFLY_TWO_S32(c, 31, 16, cospi_31_64, cospi_1_64, d, 1, 31); - out[1] = add_round_shift_s32(d_lo[1], d_hi[1]); - out[31] = add_round_shift_s32(d_lo[31], d_hi[31]); - - BUTTERFLY_TWO_S32(c, 30, 17, cospi_15_64, cospi_17_64, d, 17, 15); - out[17] = add_round_shift_s32(d_lo[17], d_hi[17]); - out[15] = add_round_shift_s32(d_lo[15], d_hi[15]); - - BUTTERFLY_TWO_S32(c, 29, 18, cospi_23_64, cospi_9_64, d, 9, 23); - out[9] = add_round_shift_s32(d_lo[9], d_hi[9]); - out[23] = add_round_shift_s32(d_lo[23], d_hi[23]); - - BUTTERFLY_TWO_S32(c, 28, 19, cospi_7_64, cospi_25_64, d, 25, 7); - out[25] = add_round_shift_s32(d_lo[25], d_hi[25]); - out[7] = add_round_shift_s32(d_lo[7], d_hi[7]); - - BUTTERFLY_TWO_S32(c, 27, 20, cospi_27_64, cospi_5_64, d, 5, 27); - out[5] = add_round_shift_s32(d_lo[5], d_hi[5]); - out[27] = add_round_shift_s32(d_lo[27], d_hi[27]); - - BUTTERFLY_TWO_S32(c, 26, 21, cospi_11_64, cospi_21_64, d, 21, 11); - out[21] = add_round_shift_s32(d_lo[21], d_hi[21]); - out[11] = add_round_shift_s32(d_lo[11], d_hi[11]); - - BUTTERFLY_TWO_S32(c, 25, 22, cospi_19_64, cospi_13_64, d, 13, 19); - out[13] = add_round_shift_s32(d_lo[13], d_hi[13]); - out[19] = add_round_shift_s32(d_lo[19], d_hi[19]); - - BUTTERFLY_TWO_S32(c, 24, 23, cospi_3_64, cospi_29_64, d, 29, 3); - out[29] = add_round_shift_s32(d_lo[29], d_hi[29]); - out[3] = add_round_shift_s32(d_lo[3], d_hi[3]); -} - -// Add 1 if positive, 2 if negative, and shift by 2. -// In practice, add 1, then add the sign bit, then shift without rounding. -static INLINE int16x8_t add_round_shift_s16(const int16x8_t a) { - const int16x8_t one = vdupq_n_s16(1); - const uint16x8_t a_u16 = vreinterpretq_u16_s16(a); - const uint16x8_t a_sign_u16 = vshrq_n_u16(a_u16, 15); - const int16x8_t a_sign_s16 = vreinterpretq_s16_u16(a_sign_u16); - return vshrq_n_s16(vaddq_s16(vaddq_s16(a, a_sign_s16), one), 2); -} - -static void dct_body_second_pass_rd(const int16x8_t *in, int16x8_t *out) { - int16x8_t a[32]; - int16x8_t b[32]; - - // Stage 1. Done as part of the load for the first pass. - a[0] = vaddq_s16(in[0], in[31]); - a[1] = vaddq_s16(in[1], in[30]); - a[2] = vaddq_s16(in[2], in[29]); - a[3] = vaddq_s16(in[3], in[28]); - a[4] = vaddq_s16(in[4], in[27]); - a[5] = vaddq_s16(in[5], in[26]); - a[6] = vaddq_s16(in[6], in[25]); - a[7] = vaddq_s16(in[7], in[24]); - a[8] = vaddq_s16(in[8], in[23]); - a[9] = vaddq_s16(in[9], in[22]); - a[10] = vaddq_s16(in[10], in[21]); - a[11] = vaddq_s16(in[11], in[20]); - a[12] = vaddq_s16(in[12], in[19]); - a[13] = vaddq_s16(in[13], in[18]); - a[14] = vaddq_s16(in[14], in[17]); - a[15] = vaddq_s16(in[15], in[16]); - a[16] = vsubq_s16(in[15], in[16]); - a[17] = vsubq_s16(in[14], in[17]); - a[18] = vsubq_s16(in[13], in[18]); - a[19] = vsubq_s16(in[12], in[19]); - a[20] = vsubq_s16(in[11], in[20]); - a[21] = vsubq_s16(in[10], in[21]); - a[22] = vsubq_s16(in[9], in[22]); - a[23] = vsubq_s16(in[8], in[23]); - a[24] = vsubq_s16(in[7], in[24]); - a[25] = vsubq_s16(in[6], in[25]); - a[26] = vsubq_s16(in[5], in[26]); - a[27] = vsubq_s16(in[4], in[27]); - a[28] = vsubq_s16(in[3], in[28]); - a[29] = vsubq_s16(in[2], in[29]); - a[30] = vsubq_s16(in[1], in[30]); - a[31] = vsubq_s16(in[0], in[31]); - - // Stage 2. - // For the "rd" version, all the values are rounded down after stage 2 to keep - // the values in 16 bits. - b[0] = add_round_shift_s16(vaddq_s16(a[0], a[15])); - b[1] = add_round_shift_s16(vaddq_s16(a[1], a[14])); - b[2] = add_round_shift_s16(vaddq_s16(a[2], a[13])); - b[3] = add_round_shift_s16(vaddq_s16(a[3], a[12])); - b[4] = add_round_shift_s16(vaddq_s16(a[4], a[11])); - b[5] = add_round_shift_s16(vaddq_s16(a[5], a[10])); - b[6] = add_round_shift_s16(vaddq_s16(a[6], a[9])); - b[7] = add_round_shift_s16(vaddq_s16(a[7], a[8])); - - b[8] = add_round_shift_s16(vsubq_s16(a[7], a[8])); - b[9] = add_round_shift_s16(vsubq_s16(a[6], a[9])); - b[10] = add_round_shift_s16(vsubq_s16(a[5], a[10])); - b[11] = add_round_shift_s16(vsubq_s16(a[4], a[11])); - b[12] = add_round_shift_s16(vsubq_s16(a[3], a[12])); - b[13] = add_round_shift_s16(vsubq_s16(a[2], a[13])); - b[14] = add_round_shift_s16(vsubq_s16(a[1], a[14])); - b[15] = add_round_shift_s16(vsubq_s16(a[0], a[15])); - - b[16] = add_round_shift_s16(a[16]); - b[17] = add_round_shift_s16(a[17]); - b[18] = add_round_shift_s16(a[18]); - b[19] = add_round_shift_s16(a[19]); - - butterfly_one_coeff(a[27], a[20], cospi_16_64, &b[27], &b[20]); - butterfly_one_coeff(a[26], a[21], cospi_16_64, &b[26], &b[21]); - butterfly_one_coeff(a[25], a[22], cospi_16_64, &b[25], &b[22]); - butterfly_one_coeff(a[24], a[23], cospi_16_64, &b[24], &b[23]); - b[20] = add_round_shift_s16(b[20]); - b[21] = add_round_shift_s16(b[21]); - b[22] = add_round_shift_s16(b[22]); - b[23] = add_round_shift_s16(b[23]); - b[24] = add_round_shift_s16(b[24]); - b[25] = add_round_shift_s16(b[25]); - b[26] = add_round_shift_s16(b[26]); - b[27] = add_round_shift_s16(b[27]); - - b[28] = add_round_shift_s16(a[28]); - b[29] = add_round_shift_s16(a[29]); - b[30] = add_round_shift_s16(a[30]); - b[31] = add_round_shift_s16(a[31]); - - // Stage 3. - a[0] = vaddq_s16(b[0], b[7]); - a[1] = vaddq_s16(b[1], b[6]); - a[2] = vaddq_s16(b[2], b[5]); - a[3] = vaddq_s16(b[3], b[4]); - - a[4] = vsubq_s16(b[3], b[4]); - a[5] = vsubq_s16(b[2], b[5]); - a[6] = vsubq_s16(b[1], b[6]); - a[7] = vsubq_s16(b[0], b[7]); - - a[8] = b[8]; - a[9] = b[9]; - - butterfly_one_coeff(b[13], b[10], cospi_16_64, &a[13], &a[10]); - butterfly_one_coeff(b[12], b[11], cospi_16_64, &a[12], &a[11]); - - a[14] = b[14]; - a[15] = b[15]; - - a[16] = vaddq_s16(b[16], b[23]); - a[17] = vaddq_s16(b[17], b[22]); - a[18] = vaddq_s16(b[18], b[21]); - a[19] = vaddq_s16(b[19], b[20]); - - a[20] = vsubq_s16(b[19], b[20]); - a[21] = vsubq_s16(b[18], b[21]); - a[22] = vsubq_s16(b[17], b[22]); - a[23] = vsubq_s16(b[16], b[23]); - - a[24] = vsubq_s16(b[31], b[24]); - a[25] = vsubq_s16(b[30], b[25]); - a[26] = vsubq_s16(b[29], b[26]); - a[27] = vsubq_s16(b[28], b[27]); - - a[28] = vaddq_s16(b[28], b[27]); - a[29] = vaddq_s16(b[29], b[26]); - a[30] = vaddq_s16(b[30], b[25]); - a[31] = vaddq_s16(b[31], b[24]); - - // Stage 4. - b[0] = vaddq_s16(a[0], a[3]); - b[1] = vaddq_s16(a[1], a[2]); - b[2] = vsubq_s16(a[1], a[2]); - b[3] = vsubq_s16(a[0], a[3]); - - b[4] = a[4]; - - butterfly_one_coeff(a[6], a[5], cospi_16_64, &b[6], &b[5]); - - b[7] = a[7]; - - b[8] = vaddq_s16(a[8], a[11]); - b[9] = vaddq_s16(a[9], a[10]); - b[10] = vsubq_s16(a[9], a[10]); - b[11] = vsubq_s16(a[8], a[11]); - b[12] = vsubq_s16(a[15], a[12]); - b[13] = vsubq_s16(a[14], a[13]); - b[14] = vaddq_s16(a[14], a[13]); - b[15] = vaddq_s16(a[15], a[12]); - - b[16] = a[16]; - b[17] = a[17]; - - butterfly_two_coeff(a[29], a[18], cospi_24_64, cospi_8_64, &b[29], &b[18]); - butterfly_two_coeff(a[28], a[19], cospi_24_64, cospi_8_64, &b[28], &b[19]); - butterfly_two_coeff(a[27], a[20], -cospi_8_64, cospi_24_64, &b[27], &b[20]); - butterfly_two_coeff(a[26], a[21], -cospi_8_64, cospi_24_64, &b[26], &b[21]); - - b[22] = a[22]; - b[23] = a[23]; - b[24] = a[24]; - b[25] = a[25]; - - b[30] = a[30]; - b[31] = a[31]; - - // Stage 5. - butterfly_one_coeff(b[0], b[1], cospi_16_64, &a[0], &a[1]); - butterfly_two_coeff(b[3], b[2], cospi_24_64, cospi_8_64, &a[2], &a[3]); - - a[4] = vaddq_s16(b[4], b[5]); - a[5] = vsubq_s16(b[4], b[5]); - a[6] = vsubq_s16(b[7], b[6]); - a[7] = vaddq_s16(b[7], b[6]); - - a[8] = b[8]; - - butterfly_two_coeff(b[14], b[9], cospi_24_64, cospi_8_64, &a[14], &a[9]); - butterfly_two_coeff(b[13], b[10], -cospi_8_64, cospi_24_64, &a[13], &a[10]); - - a[11] = b[11]; - a[12] = b[12]; - - a[15] = b[15]; - - a[16] = vaddq_s16(b[19], b[16]); - a[17] = vaddq_s16(b[18], b[17]); - a[18] = vsubq_s16(b[17], b[18]); - a[19] = vsubq_s16(b[16], b[19]); - a[20] = vsubq_s16(b[23], b[20]); - a[21] = vsubq_s16(b[22], b[21]); - a[22] = vaddq_s16(b[21], b[22]); - a[23] = vaddq_s16(b[20], b[23]); - a[24] = vaddq_s16(b[27], b[24]); - a[25] = vaddq_s16(b[26], b[25]); - a[26] = vsubq_s16(b[25], b[26]); - a[27] = vsubq_s16(b[24], b[27]); - a[28] = vsubq_s16(b[31], b[28]); - a[29] = vsubq_s16(b[30], b[29]); - a[30] = vaddq_s16(b[29], b[30]); - a[31] = vaddq_s16(b[28], b[31]); - - // Stage 6. - b[0] = a[0]; - b[1] = a[1]; - b[2] = a[2]; - b[3] = a[3]; - - butterfly_two_coeff(a[7], a[4], cospi_28_64, cospi_4_64, &b[4], &b[7]); - butterfly_two_coeff(a[6], a[5], cospi_12_64, cospi_20_64, &b[5], &b[6]); - - b[8] = vaddq_s16(a[8], a[9]); - b[9] = vsubq_s16(a[8], a[9]); - b[10] = vsubq_s16(a[11], a[10]); - b[11] = vaddq_s16(a[11], a[10]); - b[12] = vaddq_s16(a[12], a[13]); - b[13] = vsubq_s16(a[12], a[13]); - b[14] = vsubq_s16(a[15], a[14]); - b[15] = vaddq_s16(a[15], a[14]); - - b[16] = a[16]; - b[19] = a[19]; - b[20] = a[20]; - b[23] = a[23]; - b[24] = a[24]; - b[27] = a[27]; - b[28] = a[28]; - b[31] = a[31]; - - butterfly_two_coeff(a[30], a[17], cospi_28_64, cospi_4_64, &b[30], &b[17]); - butterfly_two_coeff(a[29], a[18], -cospi_4_64, cospi_28_64, &b[29], &b[18]); - - butterfly_two_coeff(a[26], a[21], cospi_12_64, cospi_20_64, &b[26], &b[21]); - butterfly_two_coeff(a[25], a[22], -cospi_20_64, cospi_12_64, &b[25], &b[22]); - - // Stage 7. - a[0] = b[0]; - a[1] = b[1]; - a[2] = b[2]; - a[3] = b[3]; - a[4] = b[4]; - a[5] = b[5]; - a[6] = b[6]; - a[7] = b[7]; - - butterfly_two_coeff(b[15], b[8], cospi_30_64, cospi_2_64, &a[8], &a[15]); - butterfly_two_coeff(b[14], b[9], cospi_14_64, cospi_18_64, &a[9], &a[14]); - butterfly_two_coeff(b[13], b[10], cospi_22_64, cospi_10_64, &a[10], &a[13]); - butterfly_two_coeff(b[12], b[11], cospi_6_64, cospi_26_64, &a[11], &a[12]); - - a[16] = vaddq_s16(b[16], b[17]); - a[17] = vsubq_s16(b[16], b[17]); - a[18] = vsubq_s16(b[19], b[18]); - a[19] = vaddq_s16(b[19], b[18]); - a[20] = vaddq_s16(b[20], b[21]); - a[21] = vsubq_s16(b[20], b[21]); - a[22] = vsubq_s16(b[23], b[22]); - a[23] = vaddq_s16(b[23], b[22]); - a[24] = vaddq_s16(b[24], b[25]); - a[25] = vsubq_s16(b[24], b[25]); - a[26] = vsubq_s16(b[27], b[26]); - a[27] = vaddq_s16(b[27], b[26]); - a[28] = vaddq_s16(b[28], b[29]); - a[29] = vsubq_s16(b[28], b[29]); - a[30] = vsubq_s16(b[31], b[30]); - a[31] = vaddq_s16(b[31], b[30]); - - // Final stage. - out[0] = a[0]; - out[16] = a[1]; - out[8] = a[2]; - out[24] = a[3]; - out[4] = a[4]; - out[20] = a[5]; - out[12] = a[6]; - out[28] = a[7]; - out[2] = a[8]; - out[18] = a[9]; - out[10] = a[10]; - out[26] = a[11]; - out[6] = a[12]; - out[22] = a[13]; - out[14] = a[14]; - out[30] = a[15]; - - butterfly_two_coeff(a[31], a[16], cospi_31_64, cospi_1_64, &out[1], &out[31]); - butterfly_two_coeff(a[30], a[17], cospi_15_64, cospi_17_64, &out[17], - &out[15]); - butterfly_two_coeff(a[29], a[18], cospi_23_64, cospi_9_64, &out[9], &out[23]); - butterfly_two_coeff(a[28], a[19], cospi_7_64, cospi_25_64, &out[25], &out[7]); - butterfly_two_coeff(a[27], a[20], cospi_27_64, cospi_5_64, &out[5], &out[27]); - butterfly_two_coeff(a[26], a[21], cospi_11_64, cospi_21_64, &out[21], - &out[11]); - butterfly_two_coeff(a[25], a[22], cospi_19_64, cospi_13_64, &out[13], - &out[19]); - butterfly_two_coeff(a[24], a[23], cospi_3_64, cospi_29_64, &out[29], &out[3]); -} - -#undef PASS_THROUGH -#undef ADD_S16_S32 -#undef SUB_S16_S32 -#undef ADDW_S16_S32 -#undef SUBW_S16_S32 -#undef ADD_S32 -#undef SUB_S32 -#undef BUTTERFLY_ONE_S16_S32 -#undef BUTTERFLY_ONE_S32 -#undef BUTTERFLY_TWO_S32 - -// Transpose 8x8 to a new location. Don't use transpose_neon.h because those -// are all in-place. -// TODO(johannkoenig): share with other fdcts. -static INLINE void transpose_8x8(const int16x8_t *a, int16x8_t *b) { - // Swap 16 bit elements. - const int16x8x2_t c0 = vtrnq_s16(a[0], a[1]); - const int16x8x2_t c1 = vtrnq_s16(a[2], a[3]); - const int16x8x2_t c2 = vtrnq_s16(a[4], a[5]); - const int16x8x2_t c3 = vtrnq_s16(a[6], a[7]); - - // Swap 32 bit elements. - const int32x4x2_t d0 = vtrnq_s32(vreinterpretq_s32_s16(c0.val[0]), - vreinterpretq_s32_s16(c1.val[0])); - const int32x4x2_t d1 = vtrnq_s32(vreinterpretq_s32_s16(c0.val[1]), - vreinterpretq_s32_s16(c1.val[1])); - const int32x4x2_t d2 = vtrnq_s32(vreinterpretq_s32_s16(c2.val[0]), - vreinterpretq_s32_s16(c3.val[0])); - const int32x4x2_t d3 = vtrnq_s32(vreinterpretq_s32_s16(c2.val[1]), - vreinterpretq_s32_s16(c3.val[1])); - - // Swap 64 bit elements - const int16x8x2_t e0 = vpx_vtrnq_s64_to_s16(d0.val[0], d2.val[0]); - const int16x8x2_t e1 = vpx_vtrnq_s64_to_s16(d1.val[0], d3.val[0]); - const int16x8x2_t e2 = vpx_vtrnq_s64_to_s16(d0.val[1], d2.val[1]); - const int16x8x2_t e3 = vpx_vtrnq_s64_to_s16(d1.val[1], d3.val[1]); - - b[0] = e0.val[0]; - b[1] = e1.val[0]; - b[2] = e2.val[0]; - b[3] = e3.val[0]; - b[4] = e0.val[1]; - b[5] = e1.val[1]; - b[6] = e2.val[1]; - b[7] = e3.val[1]; +// Combine the load/cross and scale stages for the 8-bit transforms. +static INLINE void load_cross_scale(const int16_t *a, int stride, + int16x8_t *b) { + { + const int16x8_t lo = vld1q_s16(a + 0 * stride); + const int16x8_t hi = vld1q_s16(a + 31 * stride); + b[0] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[31] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 1 * stride); + const int16x8_t hi = vld1q_s16(a + 30 * stride); + b[1] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[30] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 2 * stride); + const int16x8_t hi = vld1q_s16(a + 29 * stride); + b[2] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[29] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 3 * stride); + const int16x8_t hi = vld1q_s16(a + 28 * stride); + b[3] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[28] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 4 * stride); + const int16x8_t hi = vld1q_s16(a + 27 * stride); + b[4] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[27] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 5 * stride); + const int16x8_t hi = vld1q_s16(a + 26 * stride); + b[5] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[26] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 6 * stride); + const int16x8_t hi = vld1q_s16(a + 25 * stride); + b[6] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[25] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 7 * stride); + const int16x8_t hi = vld1q_s16(a + 24 * stride); + b[7] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[24] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 8 * stride); + const int16x8_t hi = vld1q_s16(a + 23 * stride); + b[8] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[23] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 9 * stride); + const int16x8_t hi = vld1q_s16(a + 22 * stride); + b[9] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[22] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 10 * stride); + const int16x8_t hi = vld1q_s16(a + 21 * stride); + b[10] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[21] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 11 * stride); + const int16x8_t hi = vld1q_s16(a + 20 * stride); + b[11] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[20] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 12 * stride); + const int16x8_t hi = vld1q_s16(a + 19 * stride); + b[12] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[19] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 13 * stride); + const int16x8_t hi = vld1q_s16(a + 18 * stride); + b[13] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[18] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 14 * stride); + const int16x8_t hi = vld1q_s16(a + 17 * stride); + b[14] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[17] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } + { + const int16x8_t lo = vld1q_s16(a + 15 * stride); + const int16x8_t hi = vld1q_s16(a + 16 * stride); + b[15] = vshlq_n_s16(vaddq_s16(lo, hi), 2); + b[16] = vshlq_n_s16(vsubq_s16(lo, hi), 2); + } } void vpx_fdct32x32_neon(const int16_t *input, tran_low_t *output, int stride) { @@ -1324,23 +144,23 @@ void vpx_fdct32x32_neon(const int16_t *input, tran_low_t *output, int stride) { int16x8_t temp5[32]; // Process in 8x32 columns. - load(input, stride, temp0); - dct_body_first_pass(temp0, temp1); + load_cross_scale(input, stride, temp5); + dct_body_first_pass(temp5, temp1); - load(input + 8, stride, temp0); - dct_body_first_pass(temp0, temp2); + load_cross_scale(input + 8, stride, temp5); + dct_body_first_pass(temp5, temp2); - load(input + 16, stride, temp0); - dct_body_first_pass(temp0, temp3); + load_cross_scale(input + 16, stride, temp5); + dct_body_first_pass(temp5, temp3); - load(input + 24, stride, temp0); - dct_body_first_pass(temp0, temp4); + load_cross_scale(input + 24, stride, temp5); + dct_body_first_pass(temp5, temp4); // Generate the top row by munging the first set of 8 from each one together. - transpose_8x8(&temp1[0], &temp0[0]); - transpose_8x8(&temp2[0], &temp0[8]); - transpose_8x8(&temp3[0], &temp0[16]); - transpose_8x8(&temp4[0], &temp0[24]); + transpose_s16_8x8q(&temp1[0], &temp0[0]); + transpose_s16_8x8q(&temp2[0], &temp0[8]); + transpose_s16_8x8q(&temp3[0], &temp0[16]); + transpose_s16_8x8q(&temp4[0], &temp0[24]); dct_body_second_pass(temp0, temp5); @@ -1355,10 +175,10 @@ void vpx_fdct32x32_neon(const int16_t *input, tran_low_t *output, int stride) { store(output, temp5); // Second row of 8x32. - transpose_8x8(&temp1[8], &temp0[0]); - transpose_8x8(&temp2[8], &temp0[8]); - transpose_8x8(&temp3[8], &temp0[16]); - transpose_8x8(&temp4[8], &temp0[24]); + transpose_s16_8x8q(&temp1[8], &temp0[0]); + transpose_s16_8x8q(&temp2[8], &temp0[8]); + transpose_s16_8x8q(&temp3[8], &temp0[16]); + transpose_s16_8x8q(&temp4[8], &temp0[24]); dct_body_second_pass(temp0, temp5); @@ -1373,10 +193,10 @@ void vpx_fdct32x32_neon(const int16_t *input, tran_low_t *output, int stride) { store(output + 8 * 32, temp5); // Third row of 8x32 - transpose_8x8(&temp1[16], &temp0[0]); - transpose_8x8(&temp2[16], &temp0[8]); - transpose_8x8(&temp3[16], &temp0[16]); - transpose_8x8(&temp4[16], &temp0[24]); + transpose_s16_8x8q(&temp1[16], &temp0[0]); + transpose_s16_8x8q(&temp2[16], &temp0[8]); + transpose_s16_8x8q(&temp3[16], &temp0[16]); + transpose_s16_8x8q(&temp4[16], &temp0[24]); dct_body_second_pass(temp0, temp5); @@ -1391,10 +211,10 @@ void vpx_fdct32x32_neon(const int16_t *input, tran_low_t *output, int stride) { store(output + 16 * 32, temp5); // Final row of 8x32. - transpose_8x8(&temp1[24], &temp0[0]); - transpose_8x8(&temp2[24], &temp0[8]); - transpose_8x8(&temp3[24], &temp0[16]); - transpose_8x8(&temp4[24], &temp0[24]); + transpose_s16_8x8q(&temp1[24], &temp0[0]); + transpose_s16_8x8q(&temp2[24], &temp0[8]); + transpose_s16_8x8q(&temp3[24], &temp0[16]); + transpose_s16_8x8q(&temp4[24], &temp0[24]); dct_body_second_pass(temp0, temp5); @@ -1419,23 +239,23 @@ void vpx_fdct32x32_rd_neon(const int16_t *input, tran_low_t *output, int16x8_t temp5[32]; // Process in 8x32 columns. - load(input, stride, temp0); - dct_body_first_pass(temp0, temp1); + load_cross_scale(input, stride, temp5); + dct_body_first_pass(temp5, temp1); - load(input + 8, stride, temp0); - dct_body_first_pass(temp0, temp2); + load_cross_scale(input + 8, stride, temp5); + dct_body_first_pass(temp5, temp2); - load(input + 16, stride, temp0); - dct_body_first_pass(temp0, temp3); + load_cross_scale(input + 16, stride, temp5); + dct_body_first_pass(temp5, temp3); - load(input + 24, stride, temp0); - dct_body_first_pass(temp0, temp4); + load_cross_scale(input + 24, stride, temp5); + dct_body_first_pass(temp5, temp4); // Generate the top row by munging the first set of 8 from each one together. - transpose_8x8(&temp1[0], &temp0[0]); - transpose_8x8(&temp2[0], &temp0[8]); - transpose_8x8(&temp3[0], &temp0[16]); - transpose_8x8(&temp4[0], &temp0[24]); + transpose_s16_8x8q(&temp1[0], &temp0[0]); + transpose_s16_8x8q(&temp2[0], &temp0[8]); + transpose_s16_8x8q(&temp3[0], &temp0[16]); + transpose_s16_8x8q(&temp4[0], &temp0[24]); dct_body_second_pass_rd(temp0, temp5); @@ -1450,10 +270,10 @@ void vpx_fdct32x32_rd_neon(const int16_t *input, tran_low_t *output, store(output, temp5); // Second row of 8x32. - transpose_8x8(&temp1[8], &temp0[0]); - transpose_8x8(&temp2[8], &temp0[8]); - transpose_8x8(&temp3[8], &temp0[16]); - transpose_8x8(&temp4[8], &temp0[24]); + transpose_s16_8x8q(&temp1[8], &temp0[0]); + transpose_s16_8x8q(&temp2[8], &temp0[8]); + transpose_s16_8x8q(&temp3[8], &temp0[16]); + transpose_s16_8x8q(&temp4[8], &temp0[24]); dct_body_second_pass_rd(temp0, temp5); @@ -1468,10 +288,10 @@ void vpx_fdct32x32_rd_neon(const int16_t *input, tran_low_t *output, store(output + 8 * 32, temp5); // Third row of 8x32 - transpose_8x8(&temp1[16], &temp0[0]); - transpose_8x8(&temp2[16], &temp0[8]); - transpose_8x8(&temp3[16], &temp0[16]); - transpose_8x8(&temp4[16], &temp0[24]); + transpose_s16_8x8q(&temp1[16], &temp0[0]); + transpose_s16_8x8q(&temp2[16], &temp0[8]); + transpose_s16_8x8q(&temp3[16], &temp0[16]); + transpose_s16_8x8q(&temp4[16], &temp0[24]); dct_body_second_pass_rd(temp0, temp5); @@ -1486,10 +306,10 @@ void vpx_fdct32x32_rd_neon(const int16_t *input, tran_low_t *output, store(output + 16 * 32, temp5); // Final row of 8x32. - transpose_8x8(&temp1[24], &temp0[0]); - transpose_8x8(&temp2[24], &temp0[8]); - transpose_8x8(&temp3[24], &temp0[16]); - transpose_8x8(&temp4[24], &temp0[24]); + transpose_s16_8x8q(&temp1[24], &temp0[0]); + transpose_s16_8x8q(&temp2[24], &temp0[8]); + transpose_s16_8x8q(&temp3[24], &temp0[16]); + transpose_s16_8x8q(&temp4[24], &temp0[24]); dct_body_second_pass_rd(temp0, temp5); @@ -1503,5 +323,190 @@ void vpx_fdct32x32_rd_neon(const int16_t *input, tran_low_t *output, &temp5[29], &temp5[30], &temp5[31]); store(output + 24 * 32, temp5); } + +#if CONFIG_VP9_HIGHBITDEPTH + +void vpx_highbd_fdct32x32_neon(const int16_t *input, tran_low_t *output, + int stride) { + int16x8_t temp0[32]; + int32x4_t left1[32], left2[32], left3[32], left4[32], right1[32], right2[32], + right3[32], right4[32]; + int32x4_t left5[32], right5[32], left6[32], right6[32], left7[32], right7[32], + left8[32], right8[32]; + int32x4_t temp1[32], temp2[32]; + + // Process in 8x32 columns. + load_cross(input, stride, temp0); + highbd_scale_input(temp0, left1, right1); + highbd_dct8x32_body_first_pass(left1, right1); + highbd_partial_sub_round_shift(left1, right1); + + load_cross(input + 8, stride, temp0); + highbd_scale_input(temp0, left2, right2); + highbd_dct8x32_body_first_pass(left2, right2); + highbd_partial_sub_round_shift(left2, right2); + + load_cross(input + 16, stride, temp0); + highbd_scale_input(temp0, left3, right3); + highbd_dct8x32_body_first_pass(left3, right3); + highbd_partial_sub_round_shift(left3, right3); + + load_cross(input + 24, stride, temp0); + highbd_scale_input(temp0, left4, right4); + highbd_dct8x32_body_first_pass(left4, right4); + highbd_partial_sub_round_shift(left4, right4); + + // Generate the top row by munging the first set of 8 from each one together. + transpose_s32_8x8_2(left1, right1, temp1, temp2); + transpose_s32_8x8_2(left2, right2, temp1 + 8, temp2 + 8); + transpose_s32_8x8_2(left3, right3, temp1 + 16, temp2 + 16); + transpose_s32_8x8_2(left4, right4, temp1 + 24, temp2 + 24); + + highbd_cross_input(temp1, temp2, left5, right5); + highbd_dct8x32_body_second_pass(left5, right5); + highbd_partial_add_round_shift(left5, right5); + + // Second row of 8x32. + transpose_s32_8x8_2(left1 + 8, right1 + 8, temp1, temp2); + transpose_s32_8x8_2(left2 + 8, right2 + 8, temp1 + 8, temp2 + 8); + transpose_s32_8x8_2(left3 + 8, right3 + 8, temp1 + 16, temp2 + 16); + transpose_s32_8x8_2(left4 + 8, right4 + 8, temp1 + 24, temp2 + 24); + + highbd_cross_input(temp1, temp2, left6, right6); + highbd_dct8x32_body_second_pass(left6, right6); + highbd_partial_add_round_shift(left6, right6); + + // Third row of 8x32 + transpose_s32_8x8_2(left1 + 16, right1 + 16, temp1, temp2); + transpose_s32_8x8_2(left2 + 16, right2 + 16, temp1 + 8, temp2 + 8); + transpose_s32_8x8_2(left3 + 16, right3 + 16, temp1 + 16, temp2 + 16); + transpose_s32_8x8_2(left4 + 16, right4 + 16, temp1 + 24, temp2 + 24); + + highbd_cross_input(temp1, temp2, left7, right7); + highbd_dct8x32_body_second_pass(left7, right7); + highbd_partial_add_round_shift(left7, right7); + + // Final row of 8x32. + transpose_s32_8x8_2(left1 + 24, right1 + 24, temp1, temp2); + transpose_s32_8x8_2(left2 + 24, right2 + 24, temp1 + 8, temp2 + 8); + transpose_s32_8x8_2(left3 + 24, right3 + 24, temp1 + 16, temp2 + 16); + transpose_s32_8x8_2(left4 + 24, right4 + 24, temp1 + 24, temp2 + 24); + + highbd_cross_input(temp1, temp2, left8, right8); + highbd_dct8x32_body_second_pass(left8, right8); + highbd_partial_add_round_shift(left8, right8); + + // Final transpose + transpose_s32_8x8_2(left5, right5, left1, right1); + transpose_s32_8x8_2(left5 + 8, right5 + 8, left2, right2); + transpose_s32_8x8_2(left5 + 16, right5 + 16, left3, right3); + transpose_s32_8x8_2(left5 + 24, right5 + 24, left4, right4); + transpose_s32_8x8_2(left6, right6, left1 + 8, right1 + 8); + transpose_s32_8x8_2(left6 + 8, right6 + 8, left2 + 8, right2 + 8); + transpose_s32_8x8_2(left6 + 16, right6 + 16, left3 + 8, right3 + 8); + transpose_s32_8x8_2(left6 + 24, right6 + 24, left4 + 8, right4 + 8); + transpose_s32_8x8_2(left7, right7, left1 + 16, right1 + 16); + transpose_s32_8x8_2(left7 + 8, right7 + 8, left2 + 16, right2 + 16); + transpose_s32_8x8_2(left7 + 16, right7 + 16, left3 + 16, right3 + 16); + transpose_s32_8x8_2(left7 + 24, right7 + 24, left4 + 16, right4 + 16); + transpose_s32_8x8_2(left8, right8, left1 + 24, right1 + 24); + transpose_s32_8x8_2(left8 + 8, right8 + 8, left2 + 24, right2 + 24); + transpose_s32_8x8_2(left8 + 16, right8 + 16, left3 + 24, right3 + 24); + transpose_s32_8x8_2(left8 + 24, right8 + 24, left4 + 24, right4 + 24); + + store32x32_s32(output, left1, right1, left2, right2, left3, right3, left4, + right4); +} + +void vpx_highbd_fdct32x32_rd_neon(const int16_t *input, tran_low_t *output, + int stride) { + int16x8_t temp0[32]; + int32x4_t left1[32], left2[32], left3[32], left4[32], right1[32], right2[32], + right3[32], right4[32]; + int32x4_t left5[32], right5[32], left6[32], right6[32], left7[32], right7[32], + left8[32], right8[32]; + int32x4_t temp1[32], temp2[32]; + + // Process in 8x32 columns. + load_cross(input, stride, temp0); + highbd_scale_input(temp0, left1, right1); + highbd_dct8x32_body_first_pass(left1, right1); + highbd_partial_sub_round_shift(left1, right1); + + load_cross(input + 8, stride, temp0); + highbd_scale_input(temp0, left2, right2); + highbd_dct8x32_body_first_pass(left2, right2); + highbd_partial_sub_round_shift(left2, right2); + + load_cross(input + 16, stride, temp0); + highbd_scale_input(temp0, left3, right3); + highbd_dct8x32_body_first_pass(left3, right3); + highbd_partial_sub_round_shift(left3, right3); + + load_cross(input + 24, stride, temp0); + highbd_scale_input(temp0, left4, right4); + highbd_dct8x32_body_first_pass(left4, right4); + highbd_partial_sub_round_shift(left4, right4); + + // Generate the top row by munging the first set of 8 from each one together. + transpose_s32_8x8_2(left1, right1, temp1, temp2); + transpose_s32_8x8_2(left2, right2, temp1 + 8, temp2 + 8); + transpose_s32_8x8_2(left3, right3, temp1 + 16, temp2 + 16); + transpose_s32_8x8_2(left4, right4, temp1 + 24, temp2 + 24); + + highbd_cross_input(temp1, temp2, left5, right5); + highbd_dct8x32_body_second_pass_rd(left5, right5); + + // Second row of 8x32. + transpose_s32_8x8_2(left1 + 8, right1 + 8, temp1, temp2); + transpose_s32_8x8_2(left2 + 8, right2 + 8, temp1 + 8, temp2 + 8); + transpose_s32_8x8_2(left3 + 8, right3 + 8, temp1 + 16, temp2 + 16); + transpose_s32_8x8_2(left4 + 8, right4 + 8, temp1 + 24, temp2 + 24); + + highbd_cross_input(temp1, temp2, left6, right6); + highbd_dct8x32_body_second_pass_rd(left6, right6); + + // Third row of 8x32 + transpose_s32_8x8_2(left1 + 16, right1 + 16, temp1, temp2); + transpose_s32_8x8_2(left2 + 16, right2 + 16, temp1 + 8, temp2 + 8); + transpose_s32_8x8_2(left3 + 16, right3 + 16, temp1 + 16, temp2 + 16); + transpose_s32_8x8_2(left4 + 16, right4 + 16, temp1 + 24, temp2 + 24); + + highbd_cross_input(temp1, temp2, left7, right7); + highbd_dct8x32_body_second_pass_rd(left7, right7); + + // Final row of 8x32. + transpose_s32_8x8_2(left1 + 24, right1 + 24, temp1, temp2); + transpose_s32_8x8_2(left2 + 24, right2 + 24, temp1 + 8, temp2 + 8); + transpose_s32_8x8_2(left3 + 24, right3 + 24, temp1 + 16, temp2 + 16); + transpose_s32_8x8_2(left4 + 24, right4 + 24, temp1 + 24, temp2 + 24); + + highbd_cross_input(temp1, temp2, left8, right8); + highbd_dct8x32_body_second_pass_rd(left8, right8); + + // Final transpose + transpose_s32_8x8_2(left5, right5, left1, right1); + transpose_s32_8x8_2(left5 + 8, right5 + 8, left2, right2); + transpose_s32_8x8_2(left5 + 16, right5 + 16, left3, right3); + transpose_s32_8x8_2(left5 + 24, right5 + 24, left4, right4); + transpose_s32_8x8_2(left6, right6, left1 + 8, right1 + 8); + transpose_s32_8x8_2(left6 + 8, right6 + 8, left2 + 8, right2 + 8); + transpose_s32_8x8_2(left6 + 16, right6 + 16, left3 + 8, right3 + 8); + transpose_s32_8x8_2(left6 + 24, right6 + 24, left4 + 8, right4 + 8); + transpose_s32_8x8_2(left7, right7, left1 + 16, right1 + 16); + transpose_s32_8x8_2(left7 + 8, right7 + 8, left2 + 16, right2 + 16); + transpose_s32_8x8_2(left7 + 16, right7 + 16, left3 + 16, right3 + 16); + transpose_s32_8x8_2(left7 + 24, right7 + 24, left4 + 16, right4 + 16); + transpose_s32_8x8_2(left8, right8, left1 + 24, right1 + 24); + transpose_s32_8x8_2(left8 + 8, right8 + 8, left2 + 24, right2 + 24); + transpose_s32_8x8_2(left8 + 16, right8 + 16, left3 + 24, right3 + 24); + transpose_s32_8x8_2(left8 + 24, right8 + 24, left4 + 24, right4 + 24); + + store32x32_s32(output, left1, right1, left2, right2, left3, right3, left4, + right4); +} + +#endif // CONFIG_VP9_HIGHBITDEPTH + #endif // !defined(__clang__) && !defined(__ANDROID__) && defined(__GNUC__) && // __GNUC__ == 4 && __GNUC_MINOR__ <= 9 diff --git a/libs/libvpx/vpx_dsp/arm/fdct32x32_neon.h b/libs/libvpx/vpx_dsp/arm/fdct32x32_neon.h new file mode 100644 index 0000000000..2e3c9eafc0 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/fdct32x32_neon.h @@ -0,0 +1,2867 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VPX_DSP_ARM_FDCT32X32_NEON_H_ +#define VPX_VPX_DSP_ARM_FDCT32X32_NEON_H_ + +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" +#include "vpx_dsp/txfm_common.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/transpose_neon.h" +#include "vpx_dsp/arm/fdct_neon.h" + +// Load & cross the first 8 and last 8, then the middle +static INLINE void load_cross(const int16_t *a, int stride, int16x8_t *b) { + b[0] = vaddq_s16(vld1q_s16(a + 0 * stride), vld1q_s16(a + 31 * stride)); + b[1] = vaddq_s16(vld1q_s16(a + 1 * stride), vld1q_s16(a + 30 * stride)); + b[2] = vaddq_s16(vld1q_s16(a + 2 * stride), vld1q_s16(a + 29 * stride)); + b[3] = vaddq_s16(vld1q_s16(a + 3 * stride), vld1q_s16(a + 28 * stride)); + b[4] = vaddq_s16(vld1q_s16(a + 4 * stride), vld1q_s16(a + 27 * stride)); + b[5] = vaddq_s16(vld1q_s16(a + 5 * stride), vld1q_s16(a + 26 * stride)); + b[6] = vaddq_s16(vld1q_s16(a + 6 * stride), vld1q_s16(a + 25 * stride)); + b[7] = vaddq_s16(vld1q_s16(a + 7 * stride), vld1q_s16(a + 24 * stride)); + + b[24] = vsubq_s16(vld1q_s16(a + 7 * stride), vld1q_s16(a + 24 * stride)); + b[25] = vsubq_s16(vld1q_s16(a + 6 * stride), vld1q_s16(a + 25 * stride)); + b[26] = vsubq_s16(vld1q_s16(a + 5 * stride), vld1q_s16(a + 26 * stride)); + b[27] = vsubq_s16(vld1q_s16(a + 4 * stride), vld1q_s16(a + 27 * stride)); + b[28] = vsubq_s16(vld1q_s16(a + 3 * stride), vld1q_s16(a + 28 * stride)); + b[29] = vsubq_s16(vld1q_s16(a + 2 * stride), vld1q_s16(a + 29 * stride)); + b[30] = vsubq_s16(vld1q_s16(a + 1 * stride), vld1q_s16(a + 30 * stride)); + b[31] = vsubq_s16(vld1q_s16(a + 0 * stride), vld1q_s16(a + 31 * stride)); + + b[8] = vaddq_s16(vld1q_s16(a + 8 * stride), vld1q_s16(a + 23 * stride)); + b[9] = vaddq_s16(vld1q_s16(a + 9 * stride), vld1q_s16(a + 22 * stride)); + b[10] = vaddq_s16(vld1q_s16(a + 10 * stride), vld1q_s16(a + 21 * stride)); + b[11] = vaddq_s16(vld1q_s16(a + 11 * stride), vld1q_s16(a + 20 * stride)); + b[12] = vaddq_s16(vld1q_s16(a + 12 * stride), vld1q_s16(a + 19 * stride)); + b[13] = vaddq_s16(vld1q_s16(a + 13 * stride), vld1q_s16(a + 18 * stride)); + b[14] = vaddq_s16(vld1q_s16(a + 14 * stride), vld1q_s16(a + 17 * stride)); + b[15] = vaddq_s16(vld1q_s16(a + 15 * stride), vld1q_s16(a + 16 * stride)); + + b[16] = vsubq_s16(vld1q_s16(a + 15 * stride), vld1q_s16(a + 16 * stride)); + b[17] = vsubq_s16(vld1q_s16(a + 14 * stride), vld1q_s16(a + 17 * stride)); + b[18] = vsubq_s16(vld1q_s16(a + 13 * stride), vld1q_s16(a + 18 * stride)); + b[19] = vsubq_s16(vld1q_s16(a + 12 * stride), vld1q_s16(a + 19 * stride)); + b[20] = vsubq_s16(vld1q_s16(a + 11 * stride), vld1q_s16(a + 20 * stride)); + b[21] = vsubq_s16(vld1q_s16(a + 10 * stride), vld1q_s16(a + 21 * stride)); + b[22] = vsubq_s16(vld1q_s16(a + 9 * stride), vld1q_s16(a + 22 * stride)); + b[23] = vsubq_s16(vld1q_s16(a + 8 * stride), vld1q_s16(a + 23 * stride)); +} + +#define STORE_S16(src, index, dest) \ + do { \ + store_s16q_to_tran_low(dest, src[index]); \ + dest += 8; \ + } while (0) + +// Store 32 16x8 values, assuming stride == 32. +// Slight twist: store horizontally in blocks of 8. +static INLINE void store(tran_low_t *a, const int16x8_t *b) { + STORE_S16(b, 0, a); + STORE_S16(b, 8, a); + STORE_S16(b, 16, a); + STORE_S16(b, 24, a); + STORE_S16(b, 1, a); + STORE_S16(b, 9, a); + STORE_S16(b, 17, a); + STORE_S16(b, 25, a); + STORE_S16(b, 2, a); + STORE_S16(b, 10, a); + STORE_S16(b, 18, a); + STORE_S16(b, 26, a); + STORE_S16(b, 3, a); + STORE_S16(b, 11, a); + STORE_S16(b, 19, a); + STORE_S16(b, 27, a); + STORE_S16(b, 4, a); + STORE_S16(b, 12, a); + STORE_S16(b, 20, a); + STORE_S16(b, 28, a); + STORE_S16(b, 5, a); + STORE_S16(b, 13, a); + STORE_S16(b, 21, a); + STORE_S16(b, 29, a); + STORE_S16(b, 6, a); + STORE_S16(b, 14, a); + STORE_S16(b, 22, a); + STORE_S16(b, 30, a); + STORE_S16(b, 7, a); + STORE_S16(b, 15, a); + STORE_S16(b, 23, a); + STORE_S16(b, 31, a); +} + +#undef STORE_S16 + +static INLINE void scale_input(const int16x8_t *in /*32*/, + int16x8_t *out /*32*/) { + out[0] = vshlq_n_s16(in[0], 2); + out[1] = vshlq_n_s16(in[1], 2); + out[2] = vshlq_n_s16(in[2], 2); + out[3] = vshlq_n_s16(in[3], 2); + out[4] = vshlq_n_s16(in[4], 2); + out[5] = vshlq_n_s16(in[5], 2); + out[6] = vshlq_n_s16(in[6], 2); + out[7] = vshlq_n_s16(in[7], 2); + + out[8] = vshlq_n_s16(in[8], 2); + out[9] = vshlq_n_s16(in[9], 2); + out[10] = vshlq_n_s16(in[10], 2); + out[11] = vshlq_n_s16(in[11], 2); + out[12] = vshlq_n_s16(in[12], 2); + out[13] = vshlq_n_s16(in[13], 2); + out[14] = vshlq_n_s16(in[14], 2); + out[15] = vshlq_n_s16(in[15], 2); + + out[16] = vshlq_n_s16(in[16], 2); + out[17] = vshlq_n_s16(in[17], 2); + out[18] = vshlq_n_s16(in[18], 2); + out[19] = vshlq_n_s16(in[19], 2); + out[20] = vshlq_n_s16(in[20], 2); + out[21] = vshlq_n_s16(in[21], 2); + out[22] = vshlq_n_s16(in[22], 2); + out[23] = vshlq_n_s16(in[23], 2); + + out[24] = vshlq_n_s16(in[24], 2); + out[25] = vshlq_n_s16(in[25], 2); + out[26] = vshlq_n_s16(in[26], 2); + out[27] = vshlq_n_s16(in[27], 2); + out[28] = vshlq_n_s16(in[28], 2); + out[29] = vshlq_n_s16(in[29], 2); + out[30] = vshlq_n_s16(in[30], 2); + out[31] = vshlq_n_s16(in[31], 2); +} + +// Input and output must not overlap: even outputs are stored before +// the odd branch reads its inputs. All callers use distinct arrays. +static INLINE void dct_body_first_pass(const int16x8_t *in, int16x8_t *out) { + int16x8_t a[32]; + int16x8_t b[32]; + + // Stage 1: Done as part of the load. + + // Complete the even output branch. + // Stage 2. + // Mini cross. X the first 16 values. + a[0] = vaddq_s16(in[0], in[15]); + a[1] = vaddq_s16(in[1], in[14]); + a[2] = vaddq_s16(in[2], in[13]); + a[3] = vaddq_s16(in[3], in[12]); + a[4] = vaddq_s16(in[4], in[11]); + a[5] = vaddq_s16(in[5], in[10]); + a[6] = vaddq_s16(in[6], in[9]); + a[7] = vaddq_s16(in[7], in[8]); + a[8] = vsubq_s16(in[7], in[8]); + a[9] = vsubq_s16(in[6], in[9]); + a[10] = vsubq_s16(in[5], in[10]); + a[11] = vsubq_s16(in[4], in[11]); + a[12] = vsubq_s16(in[3], in[12]); + a[13] = vsubq_s16(in[2], in[13]); + a[14] = vsubq_s16(in[1], in[14]); + a[15] = vsubq_s16(in[0], in[15]); + + // Stage 3. + b[0] = vaddq_s16(a[0], a[7]); + b[1] = vaddq_s16(a[1], a[6]); + b[2] = vaddq_s16(a[2], a[5]); + b[3] = vaddq_s16(a[3], a[4]); + b[4] = vsubq_s16(a[3], a[4]); + b[5] = vsubq_s16(a[2], a[5]); + b[6] = vsubq_s16(a[1], a[6]); + b[7] = vsubq_s16(a[0], a[7]); + b[8] = a[8]; + b[9] = a[9]; + butterfly_one_coeff_s16_s32_narrow(a[13], a[10], cospi_16_64, &b[13], &b[10]); + butterfly_one_coeff_s16_s32_narrow(a[12], a[11], cospi_16_64, &b[12], &b[11]); + b[14] = a[14]; + b[15] = a[15]; + + // Stage 4. + a[0] = vaddq_s16(b[0], b[3]); + a[1] = vaddq_s16(b[1], b[2]); + a[2] = vsubq_s16(b[1], b[2]); + a[3] = vsubq_s16(b[0], b[3]); + a[4] = b[4]; + butterfly_one_coeff_s16_s32_narrow(b[6], b[5], cospi_16_64, &a[6], &a[5]); + a[7] = b[7]; + a[8] = vaddq_s16(b[8], b[11]); + a[9] = vaddq_s16(b[9], b[10]); + a[10] = vsubq_s16(b[9], b[10]); + a[11] = vsubq_s16(b[8], b[11]); + a[12] = vsubq_s16(b[15], b[12]); + a[13] = vsubq_s16(b[14], b[13]); + a[14] = vaddq_s16(b[14], b[13]); + a[15] = vaddq_s16(b[15], b[12]); + + // Stage 5. + butterfly_one_coeff_s16_fast(a[0], a[1], cospi_16_64, &b[0], &b[1]); + butterfly_two_coeff(a[3], a[2], cospi_8_64, cospi_24_64, &b[2], &b[3]); + b[4] = vaddq_s16(a[4], a[5]); + b[5] = vsubq_s16(a[4], a[5]); + b[6] = vsubq_s16(a[7], a[6]); + b[7] = vaddq_s16(a[7], a[6]); + b[8] = a[8]; + butterfly_two_coeff(a[14], a[9], cospi_8_64, cospi_24_64, &b[14], &b[9]); + butterfly_two_coeff(a[13], a[10], cospi_24_64, -cospi_8_64, &b[13], &b[10]); + b[11] = a[11]; + b[12] = a[12]; + b[15] = a[15]; + + // Stage 6. + a[0] = b[0]; + a[1] = b[1]; + a[2] = b[2]; + a[3] = b[3]; + butterfly_two_coeff(b[7], b[4], cospi_4_64, cospi_28_64, &a[4], &a[7]); + butterfly_two_coeff(b[6], b[5], cospi_20_64, cospi_12_64, &a[5], &a[6]); + a[8] = vaddq_s16(b[8], b[9]); + a[9] = vsubq_s16(b[8], b[9]); + a[10] = vsubq_s16(b[11], b[10]); + a[11] = vaddq_s16(b[11], b[10]); + a[12] = vaddq_s16(b[12], b[13]); + a[13] = vsubq_s16(b[12], b[13]); + a[14] = vsubq_s16(b[15], b[14]); + a[15] = vaddq_s16(b[15], b[14]); + + // Stage 7. + b[0] = a[0]; + b[1] = a[1]; + b[2] = a[2]; + b[3] = a[3]; + b[4] = a[4]; + b[5] = a[5]; + b[6] = a[6]; + b[7] = a[7]; + butterfly_two_coeff(a[15], a[8], cospi_2_64, cospi_30_64, &b[8], &b[15]); + butterfly_two_coeff(a[14], a[9], cospi_18_64, cospi_14_64, &b[9], &b[14]); + butterfly_two_coeff(a[13], a[10], cospi_10_64, cospi_22_64, &b[10], &b[13]); + butterfly_two_coeff(a[12], a[11], cospi_26_64, cospi_6_64, &b[11], &b[12]); + + // Final stage. + out[0] = sub_round_shift_s16(b[0]); + out[16] = sub_round_shift_s16(b[1]); + out[8] = sub_round_shift_s16(b[2]); + out[24] = sub_round_shift_s16(b[3]); + out[4] = sub_round_shift_s16(b[4]); + out[20] = sub_round_shift_s16(b[5]); + out[12] = sub_round_shift_s16(b[6]); + out[28] = sub_round_shift_s16(b[7]); + out[2] = sub_round_shift_s16(b[8]); + out[18] = sub_round_shift_s16(b[9]); + out[10] = sub_round_shift_s16(b[10]); + out[26] = sub_round_shift_s16(b[11]); + out[6] = sub_round_shift_s16(b[12]); + out[22] = sub_round_shift_s16(b[13]); + out[14] = sub_round_shift_s16(b[14]); + out[30] = sub_round_shift_s16(b[15]); + + // Complete the odd output branch. + // Stage 2. + // Mini cross. X the middle 8 of the second half. + a[16] = in[16]; + a[17] = in[17]; + a[18] = in[18]; + a[19] = in[19]; + butterfly_one_coeff_s16_s32_narrow(in[27], in[20], cospi_16_64, &a[27], + &a[20]); + butterfly_one_coeff_s16_s32_narrow(in[26], in[21], cospi_16_64, &a[26], + &a[21]); + butterfly_one_coeff_s16_s32_narrow(in[25], in[22], cospi_16_64, &a[25], + &a[22]); + butterfly_one_coeff_s16_s32_narrow(in[24], in[23], cospi_16_64, &a[24], + &a[23]); + a[28] = in[28]; + a[29] = in[29]; + a[30] = in[30]; + a[31] = in[31]; + + // Stage 3. + b[16] = vaddq_s16(in[16], a[23]); + b[17] = vaddq_s16(in[17], a[22]); + b[18] = vaddq_s16(in[18], a[21]); + b[19] = vaddq_s16(in[19], a[20]); + b[20] = vsubq_s16(in[19], a[20]); + b[21] = vsubq_s16(in[18], a[21]); + b[22] = vsubq_s16(in[17], a[22]); + b[23] = vsubq_s16(in[16], a[23]); + b[24] = vsubq_s16(in[31], a[24]); + b[25] = vsubq_s16(in[30], a[25]); + b[26] = vsubq_s16(in[29], a[26]); + b[27] = vsubq_s16(in[28], a[27]); + b[28] = vaddq_s16(in[28], a[27]); + b[29] = vaddq_s16(in[29], a[26]); + b[30] = vaddq_s16(in[30], a[25]); + b[31] = vaddq_s16(in[31], a[24]); + + // Stage 4. + a[16] = b[16]; + a[17] = b[17]; + butterfly_two_coeff(b[29], b[18], cospi_8_64, cospi_24_64, &a[29], &a[18]); + butterfly_two_coeff(b[28], b[19], cospi_8_64, cospi_24_64, &a[28], &a[19]); + butterfly_two_coeff(b[27], b[20], cospi_24_64, -cospi_8_64, &a[27], &a[20]); + butterfly_two_coeff(b[26], b[21], cospi_24_64, -cospi_8_64, &a[26], &a[21]); + a[22] = b[22]; + a[23] = b[23]; + a[24] = b[24]; + a[25] = b[25]; + a[30] = b[30]; + a[31] = b[31]; + + // Stage 5. + b[16] = vaddq_s16(a[19], a[16]); + b[17] = vaddq_s16(a[18], a[17]); + b[18] = vsubq_s16(a[17], a[18]); + b[19] = vsubq_s16(a[16], a[19]); + b[20] = vsubq_s16(a[23], a[20]); + b[21] = vsubq_s16(a[22], a[21]); + b[22] = vaddq_s16(a[21], a[22]); + b[23] = vaddq_s16(a[20], a[23]); + b[24] = vaddq_s16(a[27], a[24]); + b[25] = vaddq_s16(a[26], a[25]); + b[26] = vsubq_s16(a[25], a[26]); + b[27] = vsubq_s16(a[24], a[27]); + b[28] = vsubq_s16(a[31], a[28]); + b[29] = vsubq_s16(a[30], a[29]); + b[30] = vaddq_s16(a[29], a[30]); + b[31] = vaddq_s16(a[28], a[31]); + + // Stage 6. + a[16] = b[16]; + a[19] = b[19]; + a[20] = b[20]; + a[23] = b[23]; + a[24] = b[24]; + a[27] = b[27]; + a[28] = b[28]; + a[31] = b[31]; + butterfly_two_coeff(b[30], b[17], cospi_4_64, cospi_28_64, &a[30], &a[17]); + butterfly_two_coeff(b[29], b[18], cospi_28_64, -cospi_4_64, &a[29], &a[18]); + butterfly_two_coeff(b[26], b[21], cospi_20_64, cospi_12_64, &a[26], &a[21]); + butterfly_two_coeff(b[25], b[22], cospi_12_64, -cospi_20_64, &a[25], &a[22]); + + // Stage 7. + b[16] = vaddq_s16(a[16], a[17]); + b[17] = vsubq_s16(a[16], a[17]); + b[18] = vsubq_s16(a[19], a[18]); + b[19] = vaddq_s16(a[19], a[18]); + b[20] = vaddq_s16(a[20], a[21]); + b[21] = vsubq_s16(a[20], a[21]); + b[22] = vsubq_s16(a[23], a[22]); + b[23] = vaddq_s16(a[23], a[22]); + b[24] = vaddq_s16(a[24], a[25]); + b[25] = vsubq_s16(a[24], a[25]); + b[26] = vsubq_s16(a[27], a[26]); + b[27] = vaddq_s16(a[27], a[26]); + b[28] = vaddq_s16(a[28], a[29]); + b[29] = vsubq_s16(a[28], a[29]); + b[30] = vsubq_s16(a[31], a[30]); + b[31] = vaddq_s16(a[31], a[30]); + + // Final stage. + butterfly_two_coeff(b[31], b[16], cospi_1_64, cospi_31_64, &a[1], &a[31]); + out[1] = sub_round_shift_s16(a[1]); + out[31] = sub_round_shift_s16(a[31]); + butterfly_two_coeff(b[30], b[17], cospi_17_64, cospi_15_64, &a[17], &a[15]); + out[17] = sub_round_shift_s16(a[17]); + out[15] = sub_round_shift_s16(a[15]); + butterfly_two_coeff(b[29], b[18], cospi_9_64, cospi_23_64, &a[9], &a[23]); + out[9] = sub_round_shift_s16(a[9]); + out[23] = sub_round_shift_s16(a[23]); + butterfly_two_coeff(b[28], b[19], cospi_25_64, cospi_7_64, &a[25], &a[7]); + out[25] = sub_round_shift_s16(a[25]); + out[7] = sub_round_shift_s16(a[7]); + butterfly_two_coeff(b[27], b[20], cospi_5_64, cospi_27_64, &a[5], &a[27]); + out[5] = sub_round_shift_s16(a[5]); + out[27] = sub_round_shift_s16(a[27]); + butterfly_two_coeff(b[26], b[21], cospi_21_64, cospi_11_64, &a[21], &a[11]); + out[21] = sub_round_shift_s16(a[21]); + out[11] = sub_round_shift_s16(a[11]); + butterfly_two_coeff(b[25], b[22], cospi_13_64, cospi_19_64, &a[13], &a[19]); + out[13] = sub_round_shift_s16(a[13]); + out[19] = sub_round_shift_s16(a[19]); + butterfly_two_coeff(b[24], b[23], cospi_29_64, cospi_3_64, &a[29], &a[3]); + out[29] = sub_round_shift_s16(a[29]); + out[3] = sub_round_shift_s16(a[3]); +} + +#define PASS_THROUGH(src, dst, element) \ + do { \ + dst##_lo[element] = src##_lo[element]; \ + dst##_hi[element] = src##_hi[element]; \ + } while (0) + +#define ADD_S16_S32(a, left_index, right_index, b, b_index) \ + do { \ + b##_lo[b_index] = \ + vaddl_s16(vget_low_s16(a[left_index]), vget_low_s16(a[right_index])); \ + b##_hi[b_index] = vaddl_s16(vget_high_s16(a[left_index]), \ + vget_high_s16(a[right_index])); \ + } while (0) + +#define SUB_S16_S32(a, left_index, right_index, b, b_index) \ + do { \ + b##_lo[b_index] = \ + vsubl_s16(vget_low_s16(a[left_index]), vget_low_s16(a[right_index])); \ + b##_hi[b_index] = vsubl_s16(vget_high_s16(a[left_index]), \ + vget_high_s16(a[right_index])); \ + } while (0) + +#define ADDW_S16_S32(a, a_index, b, b_index, c, c_index) \ + do { \ + c##_lo[c_index] = vaddw_s16(a##_lo[a_index], vget_low_s16(b[b_index])); \ + c##_hi[c_index] = vaddw_s16(a##_hi[a_index], vget_high_s16(b[b_index])); \ + } while (0) + +#define SUBW_S16_S32(a, a_index, b, b_index, temp, temp_index, c, c_index) \ + do { \ + temp##_lo[temp_index] = vmovl_s16(vget_low_s16(a[a_index])); \ + temp##_hi[temp_index] = vmovl_s16(vget_high_s16(a[a_index])); \ + c##_lo[c_index] = vsubq_s32(temp##_lo[temp_index], b##_lo[b_index]); \ + c##_hi[c_index] = vsubq_s32(temp##_hi[temp_index], b##_hi[b_index]); \ + } while (0) + +#define ADD_S32(a, left_index, right_index, b, b_index) \ + do { \ + b##_lo[b_index] = vaddq_s32(a##_lo[left_index], a##_lo[right_index]); \ + b##_hi[b_index] = vaddq_s32(a##_hi[left_index], a##_hi[right_index]); \ + } while (0) + +#define SUB_S32(a, left_index, right_index, b, b_index) \ + do { \ + b##_lo[b_index] = vsubq_s32(a##_lo[left_index], a##_lo[right_index]); \ + b##_hi[b_index] = vsubq_s32(a##_hi[left_index], a##_hi[right_index]); \ + } while (0) + +#define BUTTERFLY_ONE_S16_S32(a, left_index, right_index, constant, b, \ + add_index, sub_index) \ + do { \ + butterfly_one_coeff_s16_s32(a[left_index], a[right_index], constant, \ + &b##_lo[add_index], &b##_hi[add_index], \ + &b##_lo[sub_index], &b##_hi[sub_index]); \ + } while (0) + +#define BUTTERFLY_ONE_S32(a, left_index, right_index, constant, b, add_index, \ + sub_index) \ + do { \ + butterfly_one_coeff_s32_fast( \ + a##_lo[left_index], a##_hi[left_index], a##_lo[right_index], \ + a##_hi[right_index], constant, &b##_lo[add_index], &b##_hi[add_index], \ + &b##_lo[sub_index], &b##_hi[sub_index]); \ + } while (0) + +#define BUTTERFLY_TWO_S32(a, left_index, right_index, left_constant, \ + right_constant, b, add_index, sub_index) \ + do { \ + butterfly_two_coeff_s32(a##_lo[left_index], a##_hi[left_index], \ + a##_lo[right_index], a##_hi[right_index], \ + left_constant, right_constant, &b##_lo[add_index], \ + &b##_hi[add_index], &b##_lo[sub_index], \ + &b##_hi[sub_index]); \ + } while (0) + +// Input and output must not overlap: even outputs are stored before +// the odd branch reads its inputs. All callers use distinct arrays. +static INLINE void dct_body_second_pass(const int16x8_t *in, int16x8_t *out) { + int16x8_t a[32]; + int16x8_t b[32]; + int32x4_t c_lo[32]; + int32x4_t c_hi[32]; + int32x4_t d_lo[32]; + int32x4_t d_hi[32]; + + // Complete the even output branch. + // Stage 1. Done as part of the load for the first pass. + a[0] = vaddq_s16(in[0], in[31]); + a[1] = vaddq_s16(in[1], in[30]); + a[2] = vaddq_s16(in[2], in[29]); + a[3] = vaddq_s16(in[3], in[28]); + a[4] = vaddq_s16(in[4], in[27]); + a[5] = vaddq_s16(in[5], in[26]); + a[6] = vaddq_s16(in[6], in[25]); + a[7] = vaddq_s16(in[7], in[24]); + a[8] = vaddq_s16(in[8], in[23]); + a[9] = vaddq_s16(in[9], in[22]); + a[10] = vaddq_s16(in[10], in[21]); + a[11] = vaddq_s16(in[11], in[20]); + a[12] = vaddq_s16(in[12], in[19]); + a[13] = vaddq_s16(in[13], in[18]); + a[14] = vaddq_s16(in[14], in[17]); + a[15] = vaddq_s16(in[15], in[16]); + + // Stage 2. + b[0] = vaddq_s16(a[0], a[15]); + b[1] = vaddq_s16(a[1], a[14]); + b[2] = vaddq_s16(a[2], a[13]); + b[3] = vaddq_s16(a[3], a[12]); + b[4] = vaddq_s16(a[4], a[11]); + b[5] = vaddq_s16(a[5], a[10]); + b[6] = vaddq_s16(a[6], a[9]); + b[7] = vaddq_s16(a[7], a[8]); + b[8] = vsubq_s16(a[7], a[8]); + b[9] = vsubq_s16(a[6], a[9]); + b[10] = vsubq_s16(a[5], a[10]); + b[11] = vsubq_s16(a[4], a[11]); + b[12] = vsubq_s16(a[3], a[12]); + b[13] = vsubq_s16(a[2], a[13]); + b[14] = vsubq_s16(a[1], a[14]); + b[15] = vsubq_s16(a[0], a[15]); + + // Stage 3. With extreme values for input this calculation overflows int16_t. + // The sources for b[0] get added multiple times and, through testing, have + // been shown to overflow starting here. + ADD_S16_S32(b, 0, 7, c, 0); + ADD_S16_S32(b, 1, 6, c, 1); + ADD_S16_S32(b, 2, 5, c, 2); + ADD_S16_S32(b, 3, 4, c, 3); + SUB_S16_S32(b, 3, 4, c, 4); + SUB_S16_S32(b, 2, 5, c, 5); + SUB_S16_S32(b, 1, 6, c, 6); + SUB_S16_S32(b, 0, 7, c, 7); + a[8] = b[8]; + a[9] = b[9]; + BUTTERFLY_ONE_S16_S32(b, 13, 10, cospi_16_64, c, 13, 10); + BUTTERFLY_ONE_S16_S32(b, 12, 11, cospi_16_64, c, 12, 11); + a[14] = b[14]; + a[15] = b[15]; + + // Stage 4. + ADD_S32(c, 0, 3, d, 0); + ADD_S32(c, 1, 2, d, 1); + SUB_S32(c, 1, 2, d, 2); + SUB_S32(c, 0, 3, d, 3); + PASS_THROUGH(c, d, 4); + BUTTERFLY_ONE_S32(c, 6, 5, cospi_16_64, d, 6, 5); + PASS_THROUGH(c, d, 7); + ADDW_S16_S32(c, 11, a, 8, d, 8); + ADDW_S16_S32(c, 10, a, 9, d, 9); + SUBW_S16_S32(a, 9, c, 10, c, 9, d, 10); + SUBW_S16_S32(a, 8, c, 11, c, 8, d, 11); + SUBW_S16_S32(a, 15, c, 12, c, 15, d, 12); + SUBW_S16_S32(a, 14, c, 13, c, 14, d, 13); + ADDW_S16_S32(c, 13, b, 14, d, 14); + ADDW_S16_S32(c, 12, b, 15, d, 15); + + // Stage 5. + BUTTERFLY_ONE_S32(d, 0, 1, cospi_16_64, c, 0, 1); + BUTTERFLY_TWO_S32(d, 3, 2, cospi_8_64, cospi_24_64, c, 2, 3); + ADD_S32(d, 4, 5, c, 4); + SUB_S32(d, 4, 5, c, 5); + SUB_S32(d, 7, 6, c, 6); + ADD_S32(d, 7, 6, c, 7); + PASS_THROUGH(d, c, 8); + BUTTERFLY_TWO_S32(d, 14, 9, cospi_8_64, cospi_24_64, c, 14, 9); + BUTTERFLY_TWO_S32(d, 13, 10, cospi_24_64, -cospi_8_64, c, 13, 10); + PASS_THROUGH(d, c, 11); + PASS_THROUGH(d, c, 12); + PASS_THROUGH(d, c, 15); + + // Stage 6. + PASS_THROUGH(c, d, 0); + PASS_THROUGH(c, d, 1); + PASS_THROUGH(c, d, 2); + PASS_THROUGH(c, d, 3); + BUTTERFLY_TWO_S32(c, 7, 4, cospi_4_64, cospi_28_64, d, 4, 7); + BUTTERFLY_TWO_S32(c, 6, 5, cospi_20_64, cospi_12_64, d, 5, 6); + ADD_S32(c, 8, 9, d, 8); + SUB_S32(c, 8, 9, d, 9); + SUB_S32(c, 11, 10, d, 10); + ADD_S32(c, 11, 10, d, 11); + ADD_S32(c, 12, 13, d, 12); + SUB_S32(c, 12, 13, d, 13); + SUB_S32(c, 15, 14, d, 14); + ADD_S32(c, 15, 14, d, 15); + + // Stage 7. + PASS_THROUGH(d, c, 0); + PASS_THROUGH(d, c, 1); + PASS_THROUGH(d, c, 2); + PASS_THROUGH(d, c, 3); + PASS_THROUGH(d, c, 4); + PASS_THROUGH(d, c, 5); + PASS_THROUGH(d, c, 6); + PASS_THROUGH(d, c, 7); + BUTTERFLY_TWO_S32(d, 15, 8, cospi_2_64, cospi_30_64, c, 8, 15); + BUTTERFLY_TWO_S32(d, 14, 9, cospi_18_64, cospi_14_64, c, 9, 14); + BUTTERFLY_TWO_S32(d, 13, 10, cospi_10_64, cospi_22_64, c, 10, 13); + BUTTERFLY_TWO_S32(d, 12, 11, cospi_26_64, cospi_6_64, c, 11, 12); + + // Final stage. + // Roll rounding into this function so we can pass back int16x8. + out[0] = add_round_shift_s32_narrow(c_lo[0], c_hi[0]); + out[16] = add_round_shift_s32_narrow(c_lo[1], c_hi[1]); + out[8] = add_round_shift_s32_narrow(c_lo[2], c_hi[2]); + out[24] = add_round_shift_s32_narrow(c_lo[3], c_hi[3]); + out[4] = add_round_shift_s32_narrow(c_lo[4], c_hi[4]); + out[20] = add_round_shift_s32_narrow(c_lo[5], c_hi[5]); + out[12] = add_round_shift_s32_narrow(c_lo[6], c_hi[6]); + out[28] = add_round_shift_s32_narrow(c_lo[7], c_hi[7]); + out[2] = add_round_shift_s32_narrow(c_lo[8], c_hi[8]); + out[18] = add_round_shift_s32_narrow(c_lo[9], c_hi[9]); + out[10] = add_round_shift_s32_narrow(c_lo[10], c_hi[10]); + out[26] = add_round_shift_s32_narrow(c_lo[11], c_hi[11]); + out[6] = add_round_shift_s32_narrow(c_lo[12], c_hi[12]); + out[22] = add_round_shift_s32_narrow(c_lo[13], c_hi[13]); + out[14] = add_round_shift_s32_narrow(c_lo[14], c_hi[14]); + out[30] = add_round_shift_s32_narrow(c_lo[15], c_hi[15]); + + // Complete the odd output branch. + // Stage 1. Done as part of the load for the first pass. + a[16] = vsubq_s16(in[15], in[16]); + a[17] = vsubq_s16(in[14], in[17]); + a[18] = vsubq_s16(in[13], in[18]); + a[19] = vsubq_s16(in[12], in[19]); + a[20] = vsubq_s16(in[11], in[20]); + a[21] = vsubq_s16(in[10], in[21]); + a[22] = vsubq_s16(in[9], in[22]); + a[23] = vsubq_s16(in[8], in[23]); + a[24] = vsubq_s16(in[7], in[24]); + a[25] = vsubq_s16(in[6], in[25]); + a[26] = vsubq_s16(in[5], in[26]); + a[27] = vsubq_s16(in[4], in[27]); + a[28] = vsubq_s16(in[3], in[28]); + a[29] = vsubq_s16(in[2], in[29]); + a[30] = vsubq_s16(in[1], in[30]); + a[31] = vsubq_s16(in[0], in[31]); + + // Stage 2. + b[16] = a[16]; + b[17] = a[17]; + b[18] = a[18]; + b[19] = a[19]; + butterfly_one_coeff_s16_s32_narrow(a[27], a[20], cospi_16_64, &b[27], &b[20]); + butterfly_one_coeff_s16_s32_narrow(a[26], a[21], cospi_16_64, &b[26], &b[21]); + butterfly_one_coeff_s16_s32_narrow(a[25], a[22], cospi_16_64, &b[25], &b[22]); + butterfly_one_coeff_s16_s32_narrow(a[24], a[23], cospi_16_64, &b[24], &b[23]); + b[28] = a[28]; + b[29] = a[29]; + b[30] = a[30]; + b[31] = a[31]; + + // Stage 3. With extreme values for input this calculation rolls over int16_t. + // The sources for b[0] get added multiple times and, through testing, have + // been shown to overflow starting here. + ADD_S16_S32(b, 16, 23, c, 16); + ADD_S16_S32(b, 17, 22, c, 17); + ADD_S16_S32(b, 18, 21, c, 18); + ADD_S16_S32(b, 19, 20, c, 19); + SUB_S16_S32(b, 19, 20, c, 20); + SUB_S16_S32(b, 18, 21, c, 21); + SUB_S16_S32(b, 17, 22, c, 22); + SUB_S16_S32(b, 16, 23, c, 23); + SUB_S16_S32(b, 31, 24, c, 24); + SUB_S16_S32(b, 30, 25, c, 25); + SUB_S16_S32(b, 29, 26, c, 26); + SUB_S16_S32(b, 28, 27, c, 27); + ADD_S16_S32(b, 28, 27, c, 28); + ADD_S16_S32(b, 29, 26, c, 29); + ADD_S16_S32(b, 30, 25, c, 30); + ADD_S16_S32(b, 31, 24, c, 31); + + // Stage 4. + PASS_THROUGH(c, d, 16); + PASS_THROUGH(c, d, 17); + BUTTERFLY_TWO_S32(c, 29, 18, cospi_8_64, cospi_24_64, d, 29, 18); + BUTTERFLY_TWO_S32(c, 28, 19, cospi_8_64, cospi_24_64, d, 28, 19); + BUTTERFLY_TWO_S32(c, 27, 20, cospi_24_64, -cospi_8_64, d, 27, 20); + BUTTERFLY_TWO_S32(c, 26, 21, cospi_24_64, -cospi_8_64, d, 26, 21); + PASS_THROUGH(c, d, 22); + PASS_THROUGH(c, d, 23); + PASS_THROUGH(c, d, 24); + PASS_THROUGH(c, d, 25); + PASS_THROUGH(c, d, 30); + PASS_THROUGH(c, d, 31); + + // Stage 5. + ADD_S32(d, 16, 19, c, 16); + ADD_S32(d, 17, 18, c, 17); + SUB_S32(d, 17, 18, c, 18); + SUB_S32(d, 16, 19, c, 19); + SUB_S32(d, 23, 20, c, 20); + SUB_S32(d, 22, 21, c, 21); + ADD_S32(d, 22, 21, c, 22); + ADD_S32(d, 23, 20, c, 23); + ADD_S32(d, 24, 27, c, 24); + ADD_S32(d, 25, 26, c, 25); + SUB_S32(d, 25, 26, c, 26); + SUB_S32(d, 24, 27, c, 27); + SUB_S32(d, 31, 28, c, 28); + SUB_S32(d, 30, 29, c, 29); + ADD_S32(d, 30, 29, c, 30); + ADD_S32(d, 31, 28, c, 31); + + // Stage 6. + PASS_THROUGH(c, d, 16); + PASS_THROUGH(c, d, 19); + PASS_THROUGH(c, d, 20); + PASS_THROUGH(c, d, 23); + PASS_THROUGH(c, d, 24); + PASS_THROUGH(c, d, 27); + PASS_THROUGH(c, d, 28); + PASS_THROUGH(c, d, 31); + BUTTERFLY_TWO_S32(c, 30, 17, cospi_4_64, cospi_28_64, d, 30, 17); + BUTTERFLY_TWO_S32(c, 29, 18, cospi_28_64, -cospi_4_64, d, 29, 18); + BUTTERFLY_TWO_S32(c, 26, 21, cospi_20_64, cospi_12_64, d, 26, 21); + BUTTERFLY_TWO_S32(c, 25, 22, cospi_12_64, -cospi_20_64, d, 25, 22); + + // Stage 7. + ADD_S32(d, 16, 17, c, 16); + SUB_S32(d, 16, 17, c, 17); + SUB_S32(d, 19, 18, c, 18); + ADD_S32(d, 19, 18, c, 19); + ADD_S32(d, 20, 21, c, 20); + SUB_S32(d, 20, 21, c, 21); + SUB_S32(d, 23, 22, c, 22); + ADD_S32(d, 23, 22, c, 23); + ADD_S32(d, 24, 25, c, 24); + SUB_S32(d, 24, 25, c, 25); + SUB_S32(d, 27, 26, c, 26); + ADD_S32(d, 27, 26, c, 27); + ADD_S32(d, 28, 29, c, 28); + SUB_S32(d, 28, 29, c, 29); + SUB_S32(d, 31, 30, c, 30); + ADD_S32(d, 31, 30, c, 31); + + // Final stage. + // Roll rounding into this function so we can pass back int16x8. + BUTTERFLY_TWO_S32(c, 31, 16, cospi_1_64, cospi_31_64, d, 1, 31); + out[1] = add_round_shift_s32_narrow(d_lo[1], d_hi[1]); + out[31] = add_round_shift_s32_narrow(d_lo[31], d_hi[31]); + BUTTERFLY_TWO_S32(c, 30, 17, cospi_17_64, cospi_15_64, d, 17, 15); + out[17] = add_round_shift_s32_narrow(d_lo[17], d_hi[17]); + out[15] = add_round_shift_s32_narrow(d_lo[15], d_hi[15]); + BUTTERFLY_TWO_S32(c, 29, 18, cospi_9_64, cospi_23_64, d, 9, 23); + out[9] = add_round_shift_s32_narrow(d_lo[9], d_hi[9]); + out[23] = add_round_shift_s32_narrow(d_lo[23], d_hi[23]); + BUTTERFLY_TWO_S32(c, 28, 19, cospi_25_64, cospi_7_64, d, 25, 7); + out[25] = add_round_shift_s32_narrow(d_lo[25], d_hi[25]); + out[7] = add_round_shift_s32_narrow(d_lo[7], d_hi[7]); + BUTTERFLY_TWO_S32(c, 27, 20, cospi_5_64, cospi_27_64, d, 5, 27); + out[5] = add_round_shift_s32_narrow(d_lo[5], d_hi[5]); + out[27] = add_round_shift_s32_narrow(d_lo[27], d_hi[27]); + BUTTERFLY_TWO_S32(c, 26, 21, cospi_21_64, cospi_11_64, d, 21, 11); + out[21] = add_round_shift_s32_narrow(d_lo[21], d_hi[21]); + out[11] = add_round_shift_s32_narrow(d_lo[11], d_hi[11]); + BUTTERFLY_TWO_S32(c, 25, 22, cospi_13_64, cospi_19_64, d, 13, 19); + out[13] = add_round_shift_s32_narrow(d_lo[13], d_hi[13]); + out[19] = add_round_shift_s32_narrow(d_lo[19], d_hi[19]); + BUTTERFLY_TWO_S32(c, 24, 23, cospi_29_64, cospi_3_64, d, 29, 3); + out[29] = add_round_shift_s32_narrow(d_lo[29], d_hi[29]); + out[3] = add_round_shift_s32_narrow(d_lo[3], d_hi[3]); +} + +// Input and output must not overlap: even outputs are stored before +// the odd branch reads its inputs. All callers use distinct arrays. +static INLINE void dct_body_second_pass_rd(const int16x8_t *in, + int16x8_t *out) { + int16x8_t a[32]; + int16x8_t b[32]; + + // Complete the even output branch. + // Stage 1. Done as part of the load for the first pass. + a[0] = vaddq_s16(in[0], in[31]); + a[1] = vaddq_s16(in[1], in[30]); + a[2] = vaddq_s16(in[2], in[29]); + a[3] = vaddq_s16(in[3], in[28]); + a[4] = vaddq_s16(in[4], in[27]); + a[5] = vaddq_s16(in[5], in[26]); + a[6] = vaddq_s16(in[6], in[25]); + a[7] = vaddq_s16(in[7], in[24]); + a[8] = vaddq_s16(in[8], in[23]); + a[9] = vaddq_s16(in[9], in[22]); + a[10] = vaddq_s16(in[10], in[21]); + a[11] = vaddq_s16(in[11], in[20]); + a[12] = vaddq_s16(in[12], in[19]); + a[13] = vaddq_s16(in[13], in[18]); + a[14] = vaddq_s16(in[14], in[17]); + a[15] = vaddq_s16(in[15], in[16]); + + // Stage 2. + // For the "rd" version, all the values are rounded down after stage 2 to keep + // the values in 16 bits. + b[0] = add_round_shift_s16(vaddq_s16(a[0], a[15])); + b[1] = add_round_shift_s16(vaddq_s16(a[1], a[14])); + b[2] = add_round_shift_s16(vaddq_s16(a[2], a[13])); + b[3] = add_round_shift_s16(vaddq_s16(a[3], a[12])); + b[4] = add_round_shift_s16(vaddq_s16(a[4], a[11])); + b[5] = add_round_shift_s16(vaddq_s16(a[5], a[10])); + b[6] = add_round_shift_s16(vaddq_s16(a[6], a[9])); + b[7] = add_round_shift_s16(vaddq_s16(a[7], a[8])); + b[8] = add_round_shift_s16(vsubq_s16(a[7], a[8])); + b[9] = add_round_shift_s16(vsubq_s16(a[6], a[9])); + b[10] = add_round_shift_s16(vsubq_s16(a[5], a[10])); + b[11] = add_round_shift_s16(vsubq_s16(a[4], a[11])); + b[12] = add_round_shift_s16(vsubq_s16(a[3], a[12])); + b[13] = add_round_shift_s16(vsubq_s16(a[2], a[13])); + b[14] = add_round_shift_s16(vsubq_s16(a[1], a[14])); + b[15] = add_round_shift_s16(vsubq_s16(a[0], a[15])); + + // Stage 3. + a[0] = vaddq_s16(b[0], b[7]); + a[1] = vaddq_s16(b[1], b[6]); + a[2] = vaddq_s16(b[2], b[5]); + a[3] = vaddq_s16(b[3], b[4]); + a[4] = vsubq_s16(b[3], b[4]); + a[5] = vsubq_s16(b[2], b[5]); + a[6] = vsubq_s16(b[1], b[6]); + a[7] = vsubq_s16(b[0], b[7]); + a[8] = b[8]; + a[9] = b[9]; + butterfly_one_coeff_s16_s32_narrow(b[13], b[10], cospi_16_64, &a[13], &a[10]); + butterfly_one_coeff_s16_s32_narrow(b[12], b[11], cospi_16_64, &a[12], &a[11]); + a[14] = b[14]; + a[15] = b[15]; + + // Stage 4. + b[0] = vaddq_s16(a[0], a[3]); + b[1] = vaddq_s16(a[1], a[2]); + b[2] = vsubq_s16(a[1], a[2]); + b[3] = vsubq_s16(a[0], a[3]); + b[4] = a[4]; + butterfly_one_coeff_s16_s32_narrow(a[6], a[5], cospi_16_64, &b[6], &b[5]); + b[7] = a[7]; + b[8] = vaddq_s16(a[8], a[11]); + b[9] = vaddq_s16(a[9], a[10]); + b[10] = vsubq_s16(a[9], a[10]); + b[11] = vsubq_s16(a[8], a[11]); + b[12] = vsubq_s16(a[15], a[12]); + b[13] = vsubq_s16(a[14], a[13]); + b[14] = vaddq_s16(a[14], a[13]); + b[15] = vaddq_s16(a[15], a[12]); + + // Stage 5. + butterfly_one_coeff_s16_s32_narrow(b[0], b[1], cospi_16_64, &a[0], &a[1]); + butterfly_two_coeff(b[3], b[2], cospi_8_64, cospi_24_64, &a[2], &a[3]); + a[4] = vaddq_s16(b[4], b[5]); + a[5] = vsubq_s16(b[4], b[5]); + a[6] = vsubq_s16(b[7], b[6]); + a[7] = vaddq_s16(b[7], b[6]); + a[8] = b[8]; + butterfly_two_coeff(b[14], b[9], cospi_8_64, cospi_24_64, &a[14], &a[9]); + butterfly_two_coeff(b[13], b[10], cospi_24_64, -cospi_8_64, &a[13], &a[10]); + a[11] = b[11]; + a[12] = b[12]; + a[15] = b[15]; + + // Stage 6. + b[0] = a[0]; + b[1] = a[1]; + b[2] = a[2]; + b[3] = a[3]; + butterfly_two_coeff(a[7], a[4], cospi_4_64, cospi_28_64, &b[4], &b[7]); + butterfly_two_coeff(a[6], a[5], cospi_20_64, cospi_12_64, &b[5], &b[6]); + b[8] = vaddq_s16(a[8], a[9]); + b[9] = vsubq_s16(a[8], a[9]); + b[10] = vsubq_s16(a[11], a[10]); + b[11] = vaddq_s16(a[11], a[10]); + b[12] = vaddq_s16(a[12], a[13]); + b[13] = vsubq_s16(a[12], a[13]); + b[14] = vsubq_s16(a[15], a[14]); + b[15] = vaddq_s16(a[15], a[14]); + + // Stage 7. + a[0] = b[0]; + a[1] = b[1]; + a[2] = b[2]; + a[3] = b[3]; + a[4] = b[4]; + a[5] = b[5]; + a[6] = b[6]; + a[7] = b[7]; + butterfly_two_coeff(b[15], b[8], cospi_2_64, cospi_30_64, &a[8], &a[15]); + butterfly_two_coeff(b[14], b[9], cospi_18_64, cospi_14_64, &a[9], &a[14]); + butterfly_two_coeff(b[13], b[10], cospi_10_64, cospi_22_64, &a[10], &a[13]); + butterfly_two_coeff(b[12], b[11], cospi_26_64, cospi_6_64, &a[11], &a[12]); + + // Final stage. + out[0] = a[0]; + out[16] = a[1]; + out[8] = a[2]; + out[24] = a[3]; + out[4] = a[4]; + out[20] = a[5]; + out[12] = a[6]; + out[28] = a[7]; + out[2] = a[8]; + out[18] = a[9]; + out[10] = a[10]; + out[26] = a[11]; + out[6] = a[12]; + out[22] = a[13]; + out[14] = a[14]; + out[30] = a[15]; + + // Complete the odd output branch. + // Stage 1. Done as part of the load for the first pass. + a[16] = vsubq_s16(in[15], in[16]); + a[17] = vsubq_s16(in[14], in[17]); + a[18] = vsubq_s16(in[13], in[18]); + a[19] = vsubq_s16(in[12], in[19]); + a[20] = vsubq_s16(in[11], in[20]); + a[21] = vsubq_s16(in[10], in[21]); + a[22] = vsubq_s16(in[9], in[22]); + a[23] = vsubq_s16(in[8], in[23]); + a[24] = vsubq_s16(in[7], in[24]); + a[25] = vsubq_s16(in[6], in[25]); + a[26] = vsubq_s16(in[5], in[26]); + a[27] = vsubq_s16(in[4], in[27]); + a[28] = vsubq_s16(in[3], in[28]); + a[29] = vsubq_s16(in[2], in[29]); + a[30] = vsubq_s16(in[1], in[30]); + a[31] = vsubq_s16(in[0], in[31]); + + // Stage 2. + // For the "rd" version, all the values are rounded down after stage 2 to keep + // the values in 16 bits. + b[16] = add_round_shift_s16(a[16]); + b[17] = add_round_shift_s16(a[17]); + b[18] = add_round_shift_s16(a[18]); + b[19] = add_round_shift_s16(a[19]); + butterfly_one_coeff_s16_s32_narrow(a[27], a[20], cospi_16_64, &b[27], &b[20]); + butterfly_one_coeff_s16_s32_narrow(a[26], a[21], cospi_16_64, &b[26], &b[21]); + butterfly_one_coeff_s16_s32_narrow(a[25], a[22], cospi_16_64, &b[25], &b[22]); + butterfly_one_coeff_s16_s32_narrow(a[24], a[23], cospi_16_64, &b[24], &b[23]); + b[20] = add_round_shift_s16(b[20]); + b[21] = add_round_shift_s16(b[21]); + b[22] = add_round_shift_s16(b[22]); + b[23] = add_round_shift_s16(b[23]); + b[24] = add_round_shift_s16(b[24]); + b[25] = add_round_shift_s16(b[25]); + b[26] = add_round_shift_s16(b[26]); + b[27] = add_round_shift_s16(b[27]); + b[28] = add_round_shift_s16(a[28]); + b[29] = add_round_shift_s16(a[29]); + b[30] = add_round_shift_s16(a[30]); + b[31] = add_round_shift_s16(a[31]); + + // Stage 3. + a[16] = vaddq_s16(b[16], b[23]); + a[17] = vaddq_s16(b[17], b[22]); + a[18] = vaddq_s16(b[18], b[21]); + a[19] = vaddq_s16(b[19], b[20]); + a[20] = vsubq_s16(b[19], b[20]); + a[21] = vsubq_s16(b[18], b[21]); + a[22] = vsubq_s16(b[17], b[22]); + a[23] = vsubq_s16(b[16], b[23]); + a[24] = vsubq_s16(b[31], b[24]); + a[25] = vsubq_s16(b[30], b[25]); + a[26] = vsubq_s16(b[29], b[26]); + a[27] = vsubq_s16(b[28], b[27]); + a[28] = vaddq_s16(b[28], b[27]); + a[29] = vaddq_s16(b[29], b[26]); + a[30] = vaddq_s16(b[30], b[25]); + a[31] = vaddq_s16(b[31], b[24]); + + // Stage 4. + b[16] = a[16]; + b[17] = a[17]; + butterfly_two_coeff(a[29], a[18], cospi_8_64, cospi_24_64, &b[29], &b[18]); + butterfly_two_coeff(a[28], a[19], cospi_8_64, cospi_24_64, &b[28], &b[19]); + butterfly_two_coeff(a[27], a[20], cospi_24_64, -cospi_8_64, &b[27], &b[20]); + butterfly_two_coeff(a[26], a[21], cospi_24_64, -cospi_8_64, &b[26], &b[21]); + b[22] = a[22]; + b[23] = a[23]; + b[24] = a[24]; + b[25] = a[25]; + b[30] = a[30]; + b[31] = a[31]; + + // Stage 5. + a[16] = vaddq_s16(b[19], b[16]); + a[17] = vaddq_s16(b[18], b[17]); + a[18] = vsubq_s16(b[17], b[18]); + a[19] = vsubq_s16(b[16], b[19]); + a[20] = vsubq_s16(b[23], b[20]); + a[21] = vsubq_s16(b[22], b[21]); + a[22] = vaddq_s16(b[21], b[22]); + a[23] = vaddq_s16(b[20], b[23]); + a[24] = vaddq_s16(b[27], b[24]); + a[25] = vaddq_s16(b[26], b[25]); + a[26] = vsubq_s16(b[25], b[26]); + a[27] = vsubq_s16(b[24], b[27]); + a[28] = vsubq_s16(b[31], b[28]); + a[29] = vsubq_s16(b[30], b[29]); + a[30] = vaddq_s16(b[29], b[30]); + a[31] = vaddq_s16(b[28], b[31]); + + // Stage 6. + b[16] = a[16]; + b[19] = a[19]; + b[20] = a[20]; + b[23] = a[23]; + b[24] = a[24]; + b[27] = a[27]; + b[28] = a[28]; + b[31] = a[31]; + butterfly_two_coeff(a[30], a[17], cospi_4_64, cospi_28_64, &b[30], &b[17]); + butterfly_two_coeff(a[29], a[18], cospi_28_64, -cospi_4_64, &b[29], &b[18]); + butterfly_two_coeff(a[26], a[21], cospi_20_64, cospi_12_64, &b[26], &b[21]); + butterfly_two_coeff(a[25], a[22], cospi_12_64, -cospi_20_64, &b[25], &b[22]); + + // Stage 7. + a[16] = vaddq_s16(b[16], b[17]); + a[17] = vsubq_s16(b[16], b[17]); + a[18] = vsubq_s16(b[19], b[18]); + a[19] = vaddq_s16(b[19], b[18]); + a[20] = vaddq_s16(b[20], b[21]); + a[21] = vsubq_s16(b[20], b[21]); + a[22] = vsubq_s16(b[23], b[22]); + a[23] = vaddq_s16(b[23], b[22]); + a[24] = vaddq_s16(b[24], b[25]); + a[25] = vsubq_s16(b[24], b[25]); + a[26] = vsubq_s16(b[27], b[26]); + a[27] = vaddq_s16(b[27], b[26]); + a[28] = vaddq_s16(b[28], b[29]); + a[29] = vsubq_s16(b[28], b[29]); + a[30] = vsubq_s16(b[31], b[30]); + a[31] = vaddq_s16(b[31], b[30]); + + // Final stage. + butterfly_two_coeff(a[31], a[16], cospi_1_64, cospi_31_64, &out[1], &out[31]); + butterfly_two_coeff(a[30], a[17], cospi_17_64, cospi_15_64, &out[17], + &out[15]); + butterfly_two_coeff(a[29], a[18], cospi_9_64, cospi_23_64, &out[9], &out[23]); + butterfly_two_coeff(a[28], a[19], cospi_25_64, cospi_7_64, &out[25], &out[7]); + butterfly_two_coeff(a[27], a[20], cospi_5_64, cospi_27_64, &out[5], &out[27]); + butterfly_two_coeff(a[26], a[21], cospi_21_64, cospi_11_64, &out[21], + &out[11]); + butterfly_two_coeff(a[25], a[22], cospi_13_64, cospi_19_64, &out[13], + &out[19]); + butterfly_two_coeff(a[24], a[23], cospi_29_64, cospi_3_64, &out[29], &out[3]); +} + +#undef PASS_THROUGH +#undef ADD_S16_S32 +#undef SUB_S16_S32 +#undef ADDW_S16_S32 +#undef SUBW_S16_S32 +#undef ADD_S32 +#undef SUB_S32 +#undef BUTTERFLY_ONE_S16_S32 +#undef BUTTERFLY_ONE_S32 +#undef BUTTERFLY_TWO_S32 + +#if CONFIG_VP9_HIGHBITDEPTH + +// Store 32 32x4 vectors, assuming stride == 32. +static INLINE void store32x32_s32( + tran_low_t *a, const int32x4_t *l1 /*[16]*/, const int32x4_t *r1 /*[16]*/, + const int32x4_t *l2 /*[16]*/, const int32x4_t *r2 /*[16]*/, + const int32x4_t *l3 /*[16]*/, const int32x4_t *r3 /*[16]*/, + const int32x4_t *l4 /*[16]*/, const int32x4_t *r4 /*[16]*/) { + int i; + for (i = 0; i < 32; i++) { + vst1q_s32(a, l1[i]); + vst1q_s32(a + 4, r1[i]); + vst1q_s32(a + 8, l2[i]); + vst1q_s32(a + 12, r2[i]); + vst1q_s32(a + 16, l3[i]); + vst1q_s32(a + 20, r3[i]); + vst1q_s32(a + 24, l4[i]); + vst1q_s32(a + 28, r4[i]); + a += 32; + } +} + +static INLINE void highbd_scale_input(const int16x8_t *a /*[32]*/, + int32x4_t *left /*[32]*/, + int32x4_t *right /* [32] */) { + left[0] = vshll_n_s16(vget_low_s16(a[0]), 2); + left[1] = vshll_n_s16(vget_low_s16(a[1]), 2); + left[2] = vshll_n_s16(vget_low_s16(a[2]), 2); + left[3] = vshll_n_s16(vget_low_s16(a[3]), 2); + left[4] = vshll_n_s16(vget_low_s16(a[4]), 2); + left[5] = vshll_n_s16(vget_low_s16(a[5]), 2); + left[6] = vshll_n_s16(vget_low_s16(a[6]), 2); + left[7] = vshll_n_s16(vget_low_s16(a[7]), 2); + left[8] = vshll_n_s16(vget_low_s16(a[8]), 2); + left[9] = vshll_n_s16(vget_low_s16(a[9]), 2); + left[10] = vshll_n_s16(vget_low_s16(a[10]), 2); + left[11] = vshll_n_s16(vget_low_s16(a[11]), 2); + left[12] = vshll_n_s16(vget_low_s16(a[12]), 2); + left[13] = vshll_n_s16(vget_low_s16(a[13]), 2); + left[14] = vshll_n_s16(vget_low_s16(a[14]), 2); + left[15] = vshll_n_s16(vget_low_s16(a[15]), 2); + left[16] = vshll_n_s16(vget_low_s16(a[16]), 2); + left[17] = vshll_n_s16(vget_low_s16(a[17]), 2); + left[18] = vshll_n_s16(vget_low_s16(a[18]), 2); + left[19] = vshll_n_s16(vget_low_s16(a[19]), 2); + left[20] = vshll_n_s16(vget_low_s16(a[20]), 2); + left[21] = vshll_n_s16(vget_low_s16(a[21]), 2); + left[22] = vshll_n_s16(vget_low_s16(a[22]), 2); + left[23] = vshll_n_s16(vget_low_s16(a[23]), 2); + left[24] = vshll_n_s16(vget_low_s16(a[24]), 2); + left[25] = vshll_n_s16(vget_low_s16(a[25]), 2); + left[26] = vshll_n_s16(vget_low_s16(a[26]), 2); + left[27] = vshll_n_s16(vget_low_s16(a[27]), 2); + left[28] = vshll_n_s16(vget_low_s16(a[28]), 2); + left[29] = vshll_n_s16(vget_low_s16(a[29]), 2); + left[30] = vshll_n_s16(vget_low_s16(a[30]), 2); + left[31] = vshll_n_s16(vget_low_s16(a[31]), 2); + + right[0] = vshll_n_s16(vget_high_s16(a[0]), 2); + right[1] = vshll_n_s16(vget_high_s16(a[1]), 2); + right[2] = vshll_n_s16(vget_high_s16(a[2]), 2); + right[3] = vshll_n_s16(vget_high_s16(a[3]), 2); + right[4] = vshll_n_s16(vget_high_s16(a[4]), 2); + right[5] = vshll_n_s16(vget_high_s16(a[5]), 2); + right[6] = vshll_n_s16(vget_high_s16(a[6]), 2); + right[7] = vshll_n_s16(vget_high_s16(a[7]), 2); + right[8] = vshll_n_s16(vget_high_s16(a[8]), 2); + right[9] = vshll_n_s16(vget_high_s16(a[9]), 2); + right[10] = vshll_n_s16(vget_high_s16(a[10]), 2); + right[11] = vshll_n_s16(vget_high_s16(a[11]), 2); + right[12] = vshll_n_s16(vget_high_s16(a[12]), 2); + right[13] = vshll_n_s16(vget_high_s16(a[13]), 2); + right[14] = vshll_n_s16(vget_high_s16(a[14]), 2); + right[15] = vshll_n_s16(vget_high_s16(a[15]), 2); + right[16] = vshll_n_s16(vget_high_s16(a[16]), 2); + right[17] = vshll_n_s16(vget_high_s16(a[17]), 2); + right[18] = vshll_n_s16(vget_high_s16(a[18]), 2); + right[19] = vshll_n_s16(vget_high_s16(a[19]), 2); + right[20] = vshll_n_s16(vget_high_s16(a[20]), 2); + right[21] = vshll_n_s16(vget_high_s16(a[21]), 2); + right[22] = vshll_n_s16(vget_high_s16(a[22]), 2); + right[23] = vshll_n_s16(vget_high_s16(a[23]), 2); + right[24] = vshll_n_s16(vget_high_s16(a[24]), 2); + right[25] = vshll_n_s16(vget_high_s16(a[25]), 2); + right[26] = vshll_n_s16(vget_high_s16(a[26]), 2); + right[27] = vshll_n_s16(vget_high_s16(a[27]), 2); + right[28] = vshll_n_s16(vget_high_s16(a[28]), 2); + right[29] = vshll_n_s16(vget_high_s16(a[29]), 2); + right[30] = vshll_n_s16(vget_high_s16(a[30]), 2); + right[31] = vshll_n_s16(vget_high_s16(a[31]), 2); +} + +static INLINE void highbd_cross_input(const int32x4_t *a_left /*[32]*/, + int32x4_t *a_right /*[32]*/, + int32x4_t *b_left /*[32]*/, + int32x4_t *b_right /*[32]*/) { + // Stage 1. Done as part of the load for the first pass. + b_left[0] = vaddq_s32(a_left[0], a_left[31]); + b_left[1] = vaddq_s32(a_left[1], a_left[30]); + b_left[2] = vaddq_s32(a_left[2], a_left[29]); + b_left[3] = vaddq_s32(a_left[3], a_left[28]); + b_left[4] = vaddq_s32(a_left[4], a_left[27]); + b_left[5] = vaddq_s32(a_left[5], a_left[26]); + b_left[6] = vaddq_s32(a_left[6], a_left[25]); + b_left[7] = vaddq_s32(a_left[7], a_left[24]); + b_left[8] = vaddq_s32(a_left[8], a_left[23]); + b_left[9] = vaddq_s32(a_left[9], a_left[22]); + b_left[10] = vaddq_s32(a_left[10], a_left[21]); + b_left[11] = vaddq_s32(a_left[11], a_left[20]); + b_left[12] = vaddq_s32(a_left[12], a_left[19]); + b_left[13] = vaddq_s32(a_left[13], a_left[18]); + b_left[14] = vaddq_s32(a_left[14], a_left[17]); + b_left[15] = vaddq_s32(a_left[15], a_left[16]); + + b_right[0] = vaddq_s32(a_right[0], a_right[31]); + b_right[1] = vaddq_s32(a_right[1], a_right[30]); + b_right[2] = vaddq_s32(a_right[2], a_right[29]); + b_right[3] = vaddq_s32(a_right[3], a_right[28]); + b_right[4] = vaddq_s32(a_right[4], a_right[27]); + b_right[5] = vaddq_s32(a_right[5], a_right[26]); + b_right[6] = vaddq_s32(a_right[6], a_right[25]); + b_right[7] = vaddq_s32(a_right[7], a_right[24]); + b_right[8] = vaddq_s32(a_right[8], a_right[23]); + b_right[9] = vaddq_s32(a_right[9], a_right[22]); + b_right[10] = vaddq_s32(a_right[10], a_right[21]); + b_right[11] = vaddq_s32(a_right[11], a_right[20]); + b_right[12] = vaddq_s32(a_right[12], a_right[19]); + b_right[13] = vaddq_s32(a_right[13], a_right[18]); + b_right[14] = vaddq_s32(a_right[14], a_right[17]); + b_right[15] = vaddq_s32(a_right[15], a_right[16]); + + b_left[16] = vsubq_s32(a_left[15], a_left[16]); + b_left[17] = vsubq_s32(a_left[14], a_left[17]); + b_left[18] = vsubq_s32(a_left[13], a_left[18]); + b_left[19] = vsubq_s32(a_left[12], a_left[19]); + b_left[20] = vsubq_s32(a_left[11], a_left[20]); + b_left[21] = vsubq_s32(a_left[10], a_left[21]); + b_left[22] = vsubq_s32(a_left[9], a_left[22]); + b_left[23] = vsubq_s32(a_left[8], a_left[23]); + b_left[24] = vsubq_s32(a_left[7], a_left[24]); + b_left[25] = vsubq_s32(a_left[6], a_left[25]); + b_left[26] = vsubq_s32(a_left[5], a_left[26]); + b_left[27] = vsubq_s32(a_left[4], a_left[27]); + b_left[28] = vsubq_s32(a_left[3], a_left[28]); + b_left[29] = vsubq_s32(a_left[2], a_left[29]); + b_left[30] = vsubq_s32(a_left[1], a_left[30]); + b_left[31] = vsubq_s32(a_left[0], a_left[31]); + + b_right[16] = vsubq_s32(a_right[15], a_right[16]); + b_right[17] = vsubq_s32(a_right[14], a_right[17]); + b_right[18] = vsubq_s32(a_right[13], a_right[18]); + b_right[19] = vsubq_s32(a_right[12], a_right[19]); + b_right[20] = vsubq_s32(a_right[11], a_right[20]); + b_right[21] = vsubq_s32(a_right[10], a_right[21]); + b_right[22] = vsubq_s32(a_right[9], a_right[22]); + b_right[23] = vsubq_s32(a_right[8], a_right[23]); + b_right[24] = vsubq_s32(a_right[7], a_right[24]); + b_right[25] = vsubq_s32(a_right[6], a_right[25]); + b_right[26] = vsubq_s32(a_right[5], a_right[26]); + b_right[27] = vsubq_s32(a_right[4], a_right[27]); + b_right[28] = vsubq_s32(a_right[3], a_right[28]); + b_right[29] = vsubq_s32(a_right[2], a_right[29]); + b_right[30] = vsubq_s32(a_right[1], a_right[30]); + b_right[31] = vsubq_s32(a_right[0], a_right[31]); +} + +static INLINE void highbd_partial_add_round_shift(int32x4_t *left /*[32]*/, + int32x4_t *right /* [32] */) { + // Also compute partial rounding shift: + // output[j * 32 + i] = (temp_out[j] + 1 + (temp_out[j] > 0)) >> 2; + + left[0] = add_round_shift_s32(left[0]); + left[1] = add_round_shift_s32(left[1]); + left[2] = add_round_shift_s32(left[2]); + left[3] = add_round_shift_s32(left[3]); + left[4] = add_round_shift_s32(left[4]); + left[5] = add_round_shift_s32(left[5]); + left[6] = add_round_shift_s32(left[6]); + left[7] = add_round_shift_s32(left[7]); + left[8] = add_round_shift_s32(left[8]); + left[9] = add_round_shift_s32(left[9]); + left[10] = add_round_shift_s32(left[10]); + left[11] = add_round_shift_s32(left[11]); + left[12] = add_round_shift_s32(left[12]); + left[13] = add_round_shift_s32(left[13]); + left[14] = add_round_shift_s32(left[14]); + left[15] = add_round_shift_s32(left[15]); + left[16] = add_round_shift_s32(left[16]); + left[17] = add_round_shift_s32(left[17]); + left[18] = add_round_shift_s32(left[18]); + left[19] = add_round_shift_s32(left[19]); + left[20] = add_round_shift_s32(left[20]); + left[21] = add_round_shift_s32(left[21]); + left[22] = add_round_shift_s32(left[22]); + left[23] = add_round_shift_s32(left[23]); + left[24] = add_round_shift_s32(left[24]); + left[25] = add_round_shift_s32(left[25]); + left[26] = add_round_shift_s32(left[26]); + left[27] = add_round_shift_s32(left[27]); + left[28] = add_round_shift_s32(left[28]); + left[29] = add_round_shift_s32(left[29]); + left[30] = add_round_shift_s32(left[30]); + left[31] = add_round_shift_s32(left[31]); + + right[0] = add_round_shift_s32(right[0]); + right[1] = add_round_shift_s32(right[1]); + right[2] = add_round_shift_s32(right[2]); + right[3] = add_round_shift_s32(right[3]); + right[4] = add_round_shift_s32(right[4]); + right[5] = add_round_shift_s32(right[5]); + right[6] = add_round_shift_s32(right[6]); + right[7] = add_round_shift_s32(right[7]); + right[8] = add_round_shift_s32(right[8]); + right[9] = add_round_shift_s32(right[9]); + right[10] = add_round_shift_s32(right[10]); + right[11] = add_round_shift_s32(right[11]); + right[12] = add_round_shift_s32(right[12]); + right[13] = add_round_shift_s32(right[13]); + right[14] = add_round_shift_s32(right[14]); + right[15] = add_round_shift_s32(right[15]); + right[16] = add_round_shift_s32(right[16]); + right[17] = add_round_shift_s32(right[17]); + right[18] = add_round_shift_s32(right[18]); + right[19] = add_round_shift_s32(right[19]); + right[20] = add_round_shift_s32(right[20]); + right[21] = add_round_shift_s32(right[21]); + right[22] = add_round_shift_s32(right[22]); + right[23] = add_round_shift_s32(right[23]); + right[24] = add_round_shift_s32(right[24]); + right[25] = add_round_shift_s32(right[25]); + right[26] = add_round_shift_s32(right[26]); + right[27] = add_round_shift_s32(right[27]); + right[28] = add_round_shift_s32(right[28]); + right[29] = add_round_shift_s32(right[29]); + right[30] = add_round_shift_s32(right[30]); + right[31] = add_round_shift_s32(right[31]); +} + +static INLINE void highbd_partial_sub_round_shift(int32x4_t *left /*[32]*/, + int32x4_t *right /* [32] */) { + // Also compute partial rounding shift: + // output[j * 32 + i] = (temp_out[j] + 1 + (temp_out[j] > 0)) >> 2; + + left[0] = sub_round_shift_s32(left[0]); + left[1] = sub_round_shift_s32(left[1]); + left[2] = sub_round_shift_s32(left[2]); + left[3] = sub_round_shift_s32(left[3]); + left[4] = sub_round_shift_s32(left[4]); + left[5] = sub_round_shift_s32(left[5]); + left[6] = sub_round_shift_s32(left[6]); + left[7] = sub_round_shift_s32(left[7]); + left[8] = sub_round_shift_s32(left[8]); + left[9] = sub_round_shift_s32(left[9]); + left[10] = sub_round_shift_s32(left[10]); + left[11] = sub_round_shift_s32(left[11]); + left[12] = sub_round_shift_s32(left[12]); + left[13] = sub_round_shift_s32(left[13]); + left[14] = sub_round_shift_s32(left[14]); + left[15] = sub_round_shift_s32(left[15]); + left[16] = sub_round_shift_s32(left[16]); + left[17] = sub_round_shift_s32(left[17]); + left[18] = sub_round_shift_s32(left[18]); + left[19] = sub_round_shift_s32(left[19]); + left[20] = sub_round_shift_s32(left[20]); + left[21] = sub_round_shift_s32(left[21]); + left[22] = sub_round_shift_s32(left[22]); + left[23] = sub_round_shift_s32(left[23]); + left[24] = sub_round_shift_s32(left[24]); + left[25] = sub_round_shift_s32(left[25]); + left[26] = sub_round_shift_s32(left[26]); + left[27] = sub_round_shift_s32(left[27]); + left[28] = sub_round_shift_s32(left[28]); + left[29] = sub_round_shift_s32(left[29]); + left[30] = sub_round_shift_s32(left[30]); + left[31] = sub_round_shift_s32(left[31]); + + right[0] = sub_round_shift_s32(right[0]); + right[1] = sub_round_shift_s32(right[1]); + right[2] = sub_round_shift_s32(right[2]); + right[3] = sub_round_shift_s32(right[3]); + right[4] = sub_round_shift_s32(right[4]); + right[5] = sub_round_shift_s32(right[5]); + right[6] = sub_round_shift_s32(right[6]); + right[7] = sub_round_shift_s32(right[7]); + right[8] = sub_round_shift_s32(right[8]); + right[9] = sub_round_shift_s32(right[9]); + right[10] = sub_round_shift_s32(right[10]); + right[11] = sub_round_shift_s32(right[11]); + right[12] = sub_round_shift_s32(right[12]); + right[13] = sub_round_shift_s32(right[13]); + right[14] = sub_round_shift_s32(right[14]); + right[15] = sub_round_shift_s32(right[15]); + right[16] = sub_round_shift_s32(right[16]); + right[17] = sub_round_shift_s32(right[17]); + right[18] = sub_round_shift_s32(right[18]); + right[19] = sub_round_shift_s32(right[19]); + right[20] = sub_round_shift_s32(right[20]); + right[21] = sub_round_shift_s32(right[21]); + right[22] = sub_round_shift_s32(right[22]); + right[23] = sub_round_shift_s32(right[23]); + right[24] = sub_round_shift_s32(right[24]); + right[25] = sub_round_shift_s32(right[25]); + right[26] = sub_round_shift_s32(right[26]); + right[27] = sub_round_shift_s32(right[27]); + right[28] = sub_round_shift_s32(right[28]); + right[29] = sub_round_shift_s32(right[29]); + right[30] = sub_round_shift_s32(right[30]); + right[31] = sub_round_shift_s32(right[31]); +} + +static INLINE void highbd_dct8x32_body_first_pass(int32x4_t *left /*32*/, + int32x4_t *right /*32*/) { + int32x4_t al[32], ar[32]; + int32x4_t bl[32], br[32]; + + // Stage 1: Done as part of the load. + + // Stage 2. + // Mini cross. X the first 16 values and the middle 8 of the second half. + al[0] = vaddq_s32(left[0], left[15]); + ar[0] = vaddq_s32(right[0], right[15]); + al[1] = vaddq_s32(left[1], left[14]); + ar[1] = vaddq_s32(right[1], right[14]); + al[2] = vaddq_s32(left[2], left[13]); + ar[2] = vaddq_s32(right[2], right[13]); + al[3] = vaddq_s32(left[3], left[12]); + ar[3] = vaddq_s32(right[3], right[12]); + al[4] = vaddq_s32(left[4], left[11]); + ar[4] = vaddq_s32(right[4], right[11]); + al[5] = vaddq_s32(left[5], left[10]); + ar[5] = vaddq_s32(right[5], right[10]); + al[6] = vaddq_s32(left[6], left[9]); + ar[6] = vaddq_s32(right[6], right[9]); + al[7] = vaddq_s32(left[7], left[8]); + ar[7] = vaddq_s32(right[7], right[8]); + + al[8] = vsubq_s32(left[7], left[8]); + ar[8] = vsubq_s32(right[7], right[8]); + al[9] = vsubq_s32(left[6], left[9]); + ar[9] = vsubq_s32(right[6], right[9]); + al[10] = vsubq_s32(left[5], left[10]); + ar[10] = vsubq_s32(right[5], right[10]); + al[11] = vsubq_s32(left[4], left[11]); + ar[11] = vsubq_s32(right[4], right[11]); + al[12] = vsubq_s32(left[3], left[12]); + ar[12] = vsubq_s32(right[3], right[12]); + al[13] = vsubq_s32(left[2], left[13]); + ar[13] = vsubq_s32(right[2], right[13]); + al[14] = vsubq_s32(left[1], left[14]); + ar[14] = vsubq_s32(right[1], right[14]); + al[15] = vsubq_s32(left[0], left[15]); + ar[15] = vsubq_s32(right[0], right[15]); + + al[16] = left[16]; + ar[16] = right[16]; + al[17] = left[17]; + ar[17] = right[17]; + al[18] = left[18]; + ar[18] = right[18]; + al[19] = left[19]; + ar[19] = right[19]; + + butterfly_one_coeff_s32_fast(left[27], right[27], left[20], right[20], + cospi_16_64, &al[27], &ar[27], &al[20], &ar[20]); + butterfly_one_coeff_s32_fast(left[26], right[26], left[21], right[21], + cospi_16_64, &al[26], &ar[26], &al[21], &ar[21]); + butterfly_one_coeff_s32_fast(left[25], right[25], left[22], right[22], + cospi_16_64, &al[25], &ar[25], &al[22], &ar[22]); + butterfly_one_coeff_s32_fast(left[24], right[24], left[23], right[23], + cospi_16_64, &al[24], &ar[24], &al[23], &ar[23]); + + al[28] = left[28]; + ar[28] = right[28]; + al[29] = left[29]; + ar[29] = right[29]; + al[30] = left[30]; + ar[30] = right[30]; + al[31] = left[31]; + ar[31] = right[31]; + + // Stage 3. + bl[0] = vaddq_s32(al[0], al[7]); + br[0] = vaddq_s32(ar[0], ar[7]); + bl[1] = vaddq_s32(al[1], al[6]); + br[1] = vaddq_s32(ar[1], ar[6]); + bl[2] = vaddq_s32(al[2], al[5]); + br[2] = vaddq_s32(ar[2], ar[5]); + bl[3] = vaddq_s32(al[3], al[4]); + br[3] = vaddq_s32(ar[3], ar[4]); + + bl[4] = vsubq_s32(al[3], al[4]); + br[4] = vsubq_s32(ar[3], ar[4]); + bl[5] = vsubq_s32(al[2], al[5]); + br[5] = vsubq_s32(ar[2], ar[5]); + bl[6] = vsubq_s32(al[1], al[6]); + br[6] = vsubq_s32(ar[1], ar[6]); + bl[7] = vsubq_s32(al[0], al[7]); + br[7] = vsubq_s32(ar[0], ar[7]); + + bl[8] = al[8]; + br[8] = ar[8]; + bl[9] = al[9]; + br[9] = ar[9]; + + butterfly_one_coeff_s32_fast(al[13], ar[13], al[10], ar[10], cospi_16_64, + &bl[13], &br[13], &bl[10], &br[10]); + butterfly_one_coeff_s32_fast(al[12], ar[12], al[11], ar[11], cospi_16_64, + &bl[12], &br[12], &bl[11], &br[11]); + + bl[14] = al[14]; + br[14] = ar[14]; + bl[15] = al[15]; + br[15] = ar[15]; + + bl[16] = vaddq_s32(left[16], al[23]); + br[16] = vaddq_s32(right[16], ar[23]); + bl[17] = vaddq_s32(left[17], al[22]); + br[17] = vaddq_s32(right[17], ar[22]); + bl[18] = vaddq_s32(left[18], al[21]); + br[18] = vaddq_s32(right[18], ar[21]); + bl[19] = vaddq_s32(left[19], al[20]); + br[19] = vaddq_s32(right[19], ar[20]); + + bl[20] = vsubq_s32(left[19], al[20]); + br[20] = vsubq_s32(right[19], ar[20]); + bl[21] = vsubq_s32(left[18], al[21]); + br[21] = vsubq_s32(right[18], ar[21]); + bl[22] = vsubq_s32(left[17], al[22]); + br[22] = vsubq_s32(right[17], ar[22]); + bl[23] = vsubq_s32(left[16], al[23]); + br[23] = vsubq_s32(right[16], ar[23]); + + bl[24] = vsubq_s32(left[31], al[24]); + br[24] = vsubq_s32(right[31], ar[24]); + bl[25] = vsubq_s32(left[30], al[25]); + br[25] = vsubq_s32(right[30], ar[25]); + bl[26] = vsubq_s32(left[29], al[26]); + br[26] = vsubq_s32(right[29], ar[26]); + bl[27] = vsubq_s32(left[28], al[27]); + br[27] = vsubq_s32(right[28], ar[27]); + + bl[28] = vaddq_s32(left[28], al[27]); + br[28] = vaddq_s32(right[28], ar[27]); + bl[29] = vaddq_s32(left[29], al[26]); + br[29] = vaddq_s32(right[29], ar[26]); + bl[30] = vaddq_s32(left[30], al[25]); + br[30] = vaddq_s32(right[30], ar[25]); + bl[31] = vaddq_s32(left[31], al[24]); + br[31] = vaddq_s32(right[31], ar[24]); + + // Stage 4. + al[0] = vaddq_s32(bl[0], bl[3]); + ar[0] = vaddq_s32(br[0], br[3]); + al[1] = vaddq_s32(bl[1], bl[2]); + ar[1] = vaddq_s32(br[1], br[2]); + al[2] = vsubq_s32(bl[1], bl[2]); + ar[2] = vsubq_s32(br[1], br[2]); + al[3] = vsubq_s32(bl[0], bl[3]); + ar[3] = vsubq_s32(br[0], br[3]); + + al[4] = bl[4]; + ar[4] = br[4]; + + butterfly_one_coeff_s32_fast(bl[6], br[6], bl[5], br[5], cospi_16_64, &al[6], + &ar[6], &al[5], &ar[5]); + + al[7] = bl[7]; + ar[7] = br[7]; + + al[8] = vaddq_s32(bl[8], bl[11]); + ar[8] = vaddq_s32(br[8], br[11]); + al[9] = vaddq_s32(bl[9], bl[10]); + ar[9] = vaddq_s32(br[9], br[10]); + al[10] = vsubq_s32(bl[9], bl[10]); + ar[10] = vsubq_s32(br[9], br[10]); + al[11] = vsubq_s32(bl[8], bl[11]); + ar[11] = vsubq_s32(br[8], br[11]); + al[12] = vsubq_s32(bl[15], bl[12]); + ar[12] = vsubq_s32(br[15], br[12]); + al[13] = vsubq_s32(bl[14], bl[13]); + ar[13] = vsubq_s32(br[14], br[13]); + al[14] = vaddq_s32(bl[14], bl[13]); + ar[14] = vaddq_s32(br[14], br[13]); + al[15] = vaddq_s32(bl[15], bl[12]); + ar[15] = vaddq_s32(br[15], br[12]); + + al[16] = bl[16]; + ar[16] = br[16]; + al[17] = bl[17]; + ar[17] = br[17]; + + butterfly_two_coeff_s32_s64_narrow(bl[29], br[29], bl[18], br[18], cospi_8_64, + cospi_24_64, &al[29], &ar[29], &al[18], + &ar[18]); + butterfly_two_coeff_s32_s64_narrow(bl[28], br[28], bl[19], br[19], cospi_8_64, + cospi_24_64, &al[28], &ar[28], &al[19], + &ar[19]); + butterfly_two_coeff_s32_s64_narrow(bl[27], br[27], bl[20], br[20], + cospi_24_64, -cospi_8_64, &al[27], &ar[27], + &al[20], &ar[20]); + butterfly_two_coeff_s32_s64_narrow(bl[26], br[26], bl[21], br[21], + cospi_24_64, -cospi_8_64, &al[26], &ar[26], + &al[21], &ar[21]); + + al[22] = bl[22]; + ar[22] = br[22]; + al[23] = bl[23]; + ar[23] = br[23]; + al[24] = bl[24]; + ar[24] = br[24]; + al[25] = bl[25]; + ar[25] = br[25]; + + al[30] = bl[30]; + ar[30] = br[30]; + al[31] = bl[31]; + ar[31] = br[31]; + + // Stage 5. + butterfly_one_coeff_s32_fast(al[0], ar[0], al[1], ar[1], cospi_16_64, &bl[0], + &br[0], &bl[1], &br[1]); + butterfly_two_coeff_s32_s64_narrow(al[3], ar[3], al[2], ar[2], cospi_8_64, + cospi_24_64, &bl[2], &br[2], &bl[3], + &br[3]); + + bl[4] = vaddq_s32(al[4], al[5]); + br[4] = vaddq_s32(ar[4], ar[5]); + bl[5] = vsubq_s32(al[4], al[5]); + br[5] = vsubq_s32(ar[4], ar[5]); + bl[6] = vsubq_s32(al[7], al[6]); + br[6] = vsubq_s32(ar[7], ar[6]); + bl[7] = vaddq_s32(al[7], al[6]); + br[7] = vaddq_s32(ar[7], ar[6]); + + bl[8] = al[8]; + br[8] = ar[8]; + + butterfly_two_coeff_s32_s64_narrow(al[14], ar[14], al[9], ar[9], cospi_8_64, + cospi_24_64, &bl[14], &br[14], &bl[9], + &br[9]); + butterfly_two_coeff_s32_s64_narrow(al[13], ar[13], al[10], ar[10], + cospi_24_64, -cospi_8_64, &bl[13], &br[13], + &bl[10], &br[10]); + + bl[11] = al[11]; + br[11] = ar[11]; + bl[12] = al[12]; + br[12] = ar[12]; + + bl[15] = al[15]; + br[15] = ar[15]; + + bl[16] = vaddq_s32(al[19], al[16]); + br[16] = vaddq_s32(ar[19], ar[16]); + bl[17] = vaddq_s32(al[18], al[17]); + br[17] = vaddq_s32(ar[18], ar[17]); + bl[18] = vsubq_s32(al[17], al[18]); + br[18] = vsubq_s32(ar[17], ar[18]); + bl[19] = vsubq_s32(al[16], al[19]); + br[19] = vsubq_s32(ar[16], ar[19]); + bl[20] = vsubq_s32(al[23], al[20]); + br[20] = vsubq_s32(ar[23], ar[20]); + bl[21] = vsubq_s32(al[22], al[21]); + br[21] = vsubq_s32(ar[22], ar[21]); + bl[22] = vaddq_s32(al[21], al[22]); + br[22] = vaddq_s32(ar[21], ar[22]); + bl[23] = vaddq_s32(al[20], al[23]); + br[23] = vaddq_s32(ar[20], ar[23]); + bl[24] = vaddq_s32(al[27], al[24]); + br[24] = vaddq_s32(ar[27], ar[24]); + bl[25] = vaddq_s32(al[26], al[25]); + br[25] = vaddq_s32(ar[26], ar[25]); + bl[26] = vsubq_s32(al[25], al[26]); + br[26] = vsubq_s32(ar[25], ar[26]); + bl[27] = vsubq_s32(al[24], al[27]); + br[27] = vsubq_s32(ar[24], ar[27]); + bl[28] = vsubq_s32(al[31], al[28]); + br[28] = vsubq_s32(ar[31], ar[28]); + bl[29] = vsubq_s32(al[30], al[29]); + br[29] = vsubq_s32(ar[30], ar[29]); + bl[30] = vaddq_s32(al[29], al[30]); + br[30] = vaddq_s32(ar[29], ar[30]); + bl[31] = vaddq_s32(al[28], al[31]); + br[31] = vaddq_s32(ar[28], ar[31]); + + // Stage 6. + al[0] = bl[0]; + ar[0] = br[0]; + al[1] = bl[1]; + ar[1] = br[1]; + al[2] = bl[2]; + ar[2] = br[2]; + al[3] = bl[3]; + ar[3] = br[3]; + + butterfly_two_coeff_s32_s64_narrow(bl[7], br[7], bl[4], br[4], cospi_4_64, + cospi_28_64, &al[4], &ar[4], &al[7], + &ar[7]); + butterfly_two_coeff_s32_s64_narrow(bl[6], br[6], bl[5], br[5], cospi_20_64, + cospi_12_64, &al[5], &ar[5], &al[6], + &ar[6]); + + al[8] = vaddq_s32(bl[8], bl[9]); + ar[8] = vaddq_s32(br[8], br[9]); + al[9] = vsubq_s32(bl[8], bl[9]); + ar[9] = vsubq_s32(br[8], br[9]); + al[10] = vsubq_s32(bl[11], bl[10]); + ar[10] = vsubq_s32(br[11], br[10]); + al[11] = vaddq_s32(bl[11], bl[10]); + ar[11] = vaddq_s32(br[11], br[10]); + al[12] = vaddq_s32(bl[12], bl[13]); + ar[12] = vaddq_s32(br[12], br[13]); + al[13] = vsubq_s32(bl[12], bl[13]); + ar[13] = vsubq_s32(br[12], br[13]); + al[14] = vsubq_s32(bl[15], bl[14]); + ar[14] = vsubq_s32(br[15], br[14]); + al[15] = vaddq_s32(bl[15], bl[14]); + ar[15] = vaddq_s32(br[15], br[14]); + + al[16] = bl[16]; + ar[16] = br[16]; + al[19] = bl[19]; + ar[19] = br[19]; + al[20] = bl[20]; + ar[20] = br[20]; + al[23] = bl[23]; + ar[23] = br[23]; + al[24] = bl[24]; + ar[24] = br[24]; + al[27] = bl[27]; + ar[27] = br[27]; + al[28] = bl[28]; + ar[28] = br[28]; + al[31] = bl[31]; + ar[31] = br[31]; + + butterfly_two_coeff_s32_s64_narrow(bl[30], br[30], bl[17], br[17], cospi_4_64, + cospi_28_64, &al[30], &ar[30], &al[17], + &ar[17]); + butterfly_two_coeff_s32_s64_narrow(bl[29], br[29], bl[18], br[18], + cospi_28_64, -cospi_4_64, &al[29], &ar[29], + &al[18], &ar[18]); + butterfly_two_coeff_s32_s64_narrow(bl[26], br[26], bl[21], br[21], + cospi_20_64, cospi_12_64, &al[26], &ar[26], + &al[21], &ar[21]); + butterfly_two_coeff_s32_s64_narrow(bl[25], br[25], bl[22], br[22], + cospi_12_64, -cospi_20_64, &al[25], + &ar[25], &al[22], &ar[22]); + + // Stage 7. + bl[0] = al[0]; + br[0] = ar[0]; + bl[1] = al[1]; + br[1] = ar[1]; + bl[2] = al[2]; + br[2] = ar[2]; + bl[3] = al[3]; + br[3] = ar[3]; + bl[4] = al[4]; + br[4] = ar[4]; + bl[5] = al[5]; + br[5] = ar[5]; + bl[6] = al[6]; + br[6] = ar[6]; + bl[7] = al[7]; + br[7] = ar[7]; + + butterfly_two_coeff_s32_s64_narrow(al[15], ar[15], al[8], ar[8], cospi_2_64, + cospi_30_64, &bl[8], &br[8], &bl[15], + &br[15]); + butterfly_two_coeff_s32_s64_narrow(al[14], ar[14], al[9], ar[9], cospi_18_64, + cospi_14_64, &bl[9], &br[9], &bl[14], + &br[14]); + butterfly_two_coeff_s32_s64_narrow(al[13], ar[13], al[10], ar[10], + cospi_10_64, cospi_22_64, &bl[10], &br[10], + &bl[13], &br[13]); + butterfly_two_coeff_s32_s64_narrow(al[12], ar[12], al[11], ar[11], + cospi_26_64, cospi_6_64, &bl[11], &br[11], + &bl[12], &br[12]); + + bl[16] = vaddq_s32(al[16], al[17]); + br[16] = vaddq_s32(ar[16], ar[17]); + bl[17] = vsubq_s32(al[16], al[17]); + br[17] = vsubq_s32(ar[16], ar[17]); + bl[18] = vsubq_s32(al[19], al[18]); + br[18] = vsubq_s32(ar[19], ar[18]); + bl[19] = vaddq_s32(al[19], al[18]); + br[19] = vaddq_s32(ar[19], ar[18]); + bl[20] = vaddq_s32(al[20], al[21]); + br[20] = vaddq_s32(ar[20], ar[21]); + bl[21] = vsubq_s32(al[20], al[21]); + br[21] = vsubq_s32(ar[20], ar[21]); + bl[22] = vsubq_s32(al[23], al[22]); + br[22] = vsubq_s32(ar[23], ar[22]); + bl[23] = vaddq_s32(al[23], al[22]); + br[23] = vaddq_s32(ar[23], ar[22]); + bl[24] = vaddq_s32(al[24], al[25]); + br[24] = vaddq_s32(ar[24], ar[25]); + bl[25] = vsubq_s32(al[24], al[25]); + br[25] = vsubq_s32(ar[24], ar[25]); + bl[26] = vsubq_s32(al[27], al[26]); + br[26] = vsubq_s32(ar[27], ar[26]); + bl[27] = vaddq_s32(al[27], al[26]); + br[27] = vaddq_s32(ar[27], ar[26]); + bl[28] = vaddq_s32(al[28], al[29]); + br[28] = vaddq_s32(ar[28], ar[29]); + bl[29] = vsubq_s32(al[28], al[29]); + br[29] = vsubq_s32(ar[28], ar[29]); + bl[30] = vsubq_s32(al[31], al[30]); + br[30] = vsubq_s32(ar[31], ar[30]); + bl[31] = vaddq_s32(al[31], al[30]); + br[31] = vaddq_s32(ar[31], ar[30]); + + // Final stage. + + left[0] = bl[0]; + right[0] = br[0]; + left[16] = bl[1]; + right[16] = br[1]; + left[8] = bl[2]; + right[8] = br[2]; + left[24] = bl[3]; + right[24] = br[3]; + left[4] = bl[4]; + right[4] = br[4]; + left[20] = bl[5]; + right[20] = br[5]; + left[12] = bl[6]; + right[12] = br[6]; + left[28] = bl[7]; + right[28] = br[7]; + left[2] = bl[8]; + right[2] = br[8]; + left[18] = bl[9]; + right[18] = br[9]; + left[10] = bl[10]; + right[10] = br[10]; + left[26] = bl[11]; + right[26] = br[11]; + left[6] = bl[12]; + right[6] = br[12]; + left[22] = bl[13]; + right[22] = br[13]; + left[14] = bl[14]; + right[14] = br[14]; + left[30] = bl[15]; + right[30] = br[15]; + + butterfly_two_coeff_s32_s64_narrow(bl[31], br[31], bl[16], br[16], cospi_1_64, + cospi_31_64, &al[1], &ar[1], &al[31], + &ar[31]); + left[1] = al[1]; + right[1] = ar[1]; + left[31] = al[31]; + right[31] = ar[31]; + + butterfly_two_coeff_s32_s64_narrow(bl[30], br[30], bl[17], br[17], + cospi_17_64, cospi_15_64, &al[17], &ar[17], + &al[15], &ar[15]); + left[17] = al[17]; + right[17] = ar[17]; + left[15] = al[15]; + right[15] = ar[15]; + + butterfly_two_coeff_s32_s64_narrow(bl[29], br[29], bl[18], br[18], cospi_9_64, + cospi_23_64, &al[9], &ar[9], &al[23], + &ar[23]); + left[9] = al[9]; + right[9] = ar[9]; + left[23] = al[23]; + right[23] = ar[23]; + + butterfly_two_coeff_s32_s64_narrow(bl[28], br[28], bl[19], br[19], + cospi_25_64, cospi_7_64, &al[25], &ar[25], + &al[7], &ar[7]); + left[25] = al[25]; + right[25] = ar[25]; + left[7] = al[7]; + right[7] = ar[7]; + + butterfly_two_coeff_s32_s64_narrow(bl[27], br[27], bl[20], br[20], cospi_5_64, + cospi_27_64, &al[5], &ar[5], &al[27], + &ar[27]); + left[5] = al[5]; + right[5] = ar[5]; + left[27] = al[27]; + right[27] = ar[27]; + + butterfly_two_coeff_s32_s64_narrow(bl[26], br[26], bl[21], br[21], + cospi_21_64, cospi_11_64, &al[21], &ar[21], + &al[11], &ar[11]); + left[21] = al[21]; + right[21] = ar[21]; + left[11] = al[11]; + right[11] = ar[11]; + + butterfly_two_coeff_s32_s64_narrow(bl[25], br[25], bl[22], br[22], + cospi_13_64, cospi_19_64, &al[13], &ar[13], + &al[19], &ar[19]); + left[13] = al[13]; + right[13] = ar[13]; + left[19] = al[19]; + right[19] = ar[19]; + + butterfly_two_coeff_s32_s64_narrow(bl[24], br[24], bl[23], br[23], + cospi_29_64, cospi_3_64, &al[29], &ar[29], + &al[3], &ar[3]); + left[29] = al[29]; + right[29] = ar[29]; + left[3] = al[3]; + right[3] = ar[3]; +} + +static INLINE void highbd_dct8x32_body_second_pass(int32x4_t *left /*32*/, + int32x4_t *right /*32*/) { + int32x4_t al[32], ar[32]; + int32x4_t bl[32], br[32]; + + // Stage 1: Done as part of the load. + + // Stage 2. + // Mini cross. X the first 16 values and the middle 8 of the second half. + al[0] = vaddq_s32(left[0], left[15]); + ar[0] = vaddq_s32(right[0], right[15]); + al[1] = vaddq_s32(left[1], left[14]); + ar[1] = vaddq_s32(right[1], right[14]); + al[2] = vaddq_s32(left[2], left[13]); + ar[2] = vaddq_s32(right[2], right[13]); + al[3] = vaddq_s32(left[3], left[12]); + ar[3] = vaddq_s32(right[3], right[12]); + al[4] = vaddq_s32(left[4], left[11]); + ar[4] = vaddq_s32(right[4], right[11]); + al[5] = vaddq_s32(left[5], left[10]); + ar[5] = vaddq_s32(right[5], right[10]); + al[6] = vaddq_s32(left[6], left[9]); + ar[6] = vaddq_s32(right[6], right[9]); + al[7] = vaddq_s32(left[7], left[8]); + ar[7] = vaddq_s32(right[7], right[8]); + + al[8] = vsubq_s32(left[7], left[8]); + ar[8] = vsubq_s32(right[7], right[8]); + al[9] = vsubq_s32(left[6], left[9]); + ar[9] = vsubq_s32(right[6], right[9]); + al[10] = vsubq_s32(left[5], left[10]); + ar[10] = vsubq_s32(right[5], right[10]); + al[11] = vsubq_s32(left[4], left[11]); + ar[11] = vsubq_s32(right[4], right[11]); + al[12] = vsubq_s32(left[3], left[12]); + ar[12] = vsubq_s32(right[3], right[12]); + al[13] = vsubq_s32(left[2], left[13]); + ar[13] = vsubq_s32(right[2], right[13]); + al[14] = vsubq_s32(left[1], left[14]); + ar[14] = vsubq_s32(right[1], right[14]); + al[15] = vsubq_s32(left[0], left[15]); + ar[15] = vsubq_s32(right[0], right[15]); + + al[16] = left[16]; + ar[16] = right[16]; + al[17] = left[17]; + ar[17] = right[17]; + al[18] = left[18]; + ar[18] = right[18]; + al[19] = left[19]; + ar[19] = right[19]; + + butterfly_one_coeff_s32_fast(left[27], right[27], left[20], right[20], + cospi_16_64, &al[27], &ar[27], &al[20], &ar[20]); + butterfly_one_coeff_s32_fast(left[26], right[26], left[21], right[21], + cospi_16_64, &al[26], &ar[26], &al[21], &ar[21]); + butterfly_one_coeff_s32_fast(left[25], right[25], left[22], right[22], + cospi_16_64, &al[25], &ar[25], &al[22], &ar[22]); + butterfly_one_coeff_s32_fast(left[24], right[24], left[23], right[23], + cospi_16_64, &al[24], &ar[24], &al[23], &ar[23]); + + al[28] = left[28]; + ar[28] = right[28]; + al[29] = left[29]; + ar[29] = right[29]; + al[30] = left[30]; + ar[30] = right[30]; + al[31] = left[31]; + ar[31] = right[31]; + + // Stage 3. + bl[0] = vaddq_s32(al[0], al[7]); + br[0] = vaddq_s32(ar[0], ar[7]); + bl[1] = vaddq_s32(al[1], al[6]); + br[1] = vaddq_s32(ar[1], ar[6]); + bl[2] = vaddq_s32(al[2], al[5]); + br[2] = vaddq_s32(ar[2], ar[5]); + bl[3] = vaddq_s32(al[3], al[4]); + br[3] = vaddq_s32(ar[3], ar[4]); + + bl[4] = vsubq_s32(al[3], al[4]); + br[4] = vsubq_s32(ar[3], ar[4]); + bl[5] = vsubq_s32(al[2], al[5]); + br[5] = vsubq_s32(ar[2], ar[5]); + bl[6] = vsubq_s32(al[1], al[6]); + br[6] = vsubq_s32(ar[1], ar[6]); + bl[7] = vsubq_s32(al[0], al[7]); + br[7] = vsubq_s32(ar[0], ar[7]); + + bl[8] = al[8]; + br[8] = ar[8]; + bl[9] = al[9]; + br[9] = ar[9]; + + butterfly_one_coeff_s32_fast(al[13], ar[13], al[10], ar[10], cospi_16_64, + &bl[13], &br[13], &bl[10], &br[10]); + butterfly_one_coeff_s32_fast(al[12], ar[12], al[11], ar[11], cospi_16_64, + &bl[12], &br[12], &bl[11], &br[11]); + + bl[14] = al[14]; + br[14] = ar[14]; + bl[15] = al[15]; + br[15] = ar[15]; + + bl[16] = vaddq_s32(left[16], al[23]); + br[16] = vaddq_s32(right[16], ar[23]); + bl[17] = vaddq_s32(left[17], al[22]); + br[17] = vaddq_s32(right[17], ar[22]); + bl[18] = vaddq_s32(left[18], al[21]); + br[18] = vaddq_s32(right[18], ar[21]); + bl[19] = vaddq_s32(left[19], al[20]); + br[19] = vaddq_s32(right[19], ar[20]); + + bl[20] = vsubq_s32(left[19], al[20]); + br[20] = vsubq_s32(right[19], ar[20]); + bl[21] = vsubq_s32(left[18], al[21]); + br[21] = vsubq_s32(right[18], ar[21]); + bl[22] = vsubq_s32(left[17], al[22]); + br[22] = vsubq_s32(right[17], ar[22]); + bl[23] = vsubq_s32(left[16], al[23]); + br[23] = vsubq_s32(right[16], ar[23]); + + bl[24] = vsubq_s32(left[31], al[24]); + br[24] = vsubq_s32(right[31], ar[24]); + bl[25] = vsubq_s32(left[30], al[25]); + br[25] = vsubq_s32(right[30], ar[25]); + bl[26] = vsubq_s32(left[29], al[26]); + br[26] = vsubq_s32(right[29], ar[26]); + bl[27] = vsubq_s32(left[28], al[27]); + br[27] = vsubq_s32(right[28], ar[27]); + + bl[28] = vaddq_s32(left[28], al[27]); + br[28] = vaddq_s32(right[28], ar[27]); + bl[29] = vaddq_s32(left[29], al[26]); + br[29] = vaddq_s32(right[29], ar[26]); + bl[30] = vaddq_s32(left[30], al[25]); + br[30] = vaddq_s32(right[30], ar[25]); + bl[31] = vaddq_s32(left[31], al[24]); + br[31] = vaddq_s32(right[31], ar[24]); + + // Stage 4. + al[0] = vaddq_s32(bl[0], bl[3]); + ar[0] = vaddq_s32(br[0], br[3]); + al[1] = vaddq_s32(bl[1], bl[2]); + ar[1] = vaddq_s32(br[1], br[2]); + al[2] = vsubq_s32(bl[1], bl[2]); + ar[2] = vsubq_s32(br[1], br[2]); + al[3] = vsubq_s32(bl[0], bl[3]); + ar[3] = vsubq_s32(br[0], br[3]); + + al[4] = bl[4]; + ar[4] = br[4]; + + butterfly_one_coeff_s32_fast(bl[6], br[6], bl[5], br[5], cospi_16_64, &al[6], + &ar[6], &al[5], &ar[5]); + + al[7] = bl[7]; + ar[7] = br[7]; + + al[8] = vaddq_s32(bl[8], bl[11]); + ar[8] = vaddq_s32(br[8], br[11]); + al[9] = vaddq_s32(bl[9], bl[10]); + ar[9] = vaddq_s32(br[9], br[10]); + al[10] = vsubq_s32(bl[9], bl[10]); + ar[10] = vsubq_s32(br[9], br[10]); + al[11] = vsubq_s32(bl[8], bl[11]); + ar[11] = vsubq_s32(br[8], br[11]); + al[12] = vsubq_s32(bl[15], bl[12]); + ar[12] = vsubq_s32(br[15], br[12]); + al[13] = vsubq_s32(bl[14], bl[13]); + ar[13] = vsubq_s32(br[14], br[13]); + al[14] = vaddq_s32(bl[14], bl[13]); + ar[14] = vaddq_s32(br[14], br[13]); + al[15] = vaddq_s32(bl[15], bl[12]); + ar[15] = vaddq_s32(br[15], br[12]); + + al[16] = bl[16]; + ar[16] = br[16]; + al[17] = bl[17]; + ar[17] = br[17]; + + butterfly_two_coeff_s32_s64_narrow(bl[29], br[29], bl[18], br[18], cospi_8_64, + cospi_24_64, &al[29], &ar[29], &al[18], + &ar[18]); + butterfly_two_coeff_s32_s64_narrow(bl[28], br[28], bl[19], br[19], cospi_8_64, + cospi_24_64, &al[28], &ar[28], &al[19], + &ar[19]); + butterfly_two_coeff_s32_s64_narrow(bl[27], br[27], bl[20], br[20], + cospi_24_64, -cospi_8_64, &al[27], &ar[27], + &al[20], &ar[20]); + butterfly_two_coeff_s32_s64_narrow(bl[26], br[26], bl[21], br[21], + cospi_24_64, -cospi_8_64, &al[26], &ar[26], + &al[21], &ar[21]); + + al[22] = bl[22]; + ar[22] = br[22]; + al[23] = bl[23]; + ar[23] = br[23]; + al[24] = bl[24]; + ar[24] = br[24]; + al[25] = bl[25]; + ar[25] = br[25]; + + al[30] = bl[30]; + ar[30] = br[30]; + al[31] = bl[31]; + ar[31] = br[31]; + + // Stage 5. + butterfly_one_coeff_s32_fast(al[0], ar[0], al[1], ar[1], cospi_16_64, &bl[0], + &br[0], &bl[1], &br[1]); + butterfly_two_coeff_s32_s64_narrow(al[3], ar[3], al[2], ar[2], cospi_8_64, + cospi_24_64, &bl[2], &br[2], &bl[3], + &br[3]); + + bl[4] = vaddq_s32(al[4], al[5]); + br[4] = vaddq_s32(ar[4], ar[5]); + bl[5] = vsubq_s32(al[4], al[5]); + br[5] = vsubq_s32(ar[4], ar[5]); + bl[6] = vsubq_s32(al[7], al[6]); + br[6] = vsubq_s32(ar[7], ar[6]); + bl[7] = vaddq_s32(al[7], al[6]); + br[7] = vaddq_s32(ar[7], ar[6]); + + bl[8] = al[8]; + br[8] = ar[8]; + + butterfly_two_coeff_s32_s64_narrow(al[14], ar[14], al[9], ar[9], cospi_8_64, + cospi_24_64, &bl[14], &br[14], &bl[9], + &br[9]); + butterfly_two_coeff_s32_s64_narrow(al[13], ar[13], al[10], ar[10], + cospi_24_64, -cospi_8_64, &bl[13], &br[13], + &bl[10], &br[10]); + + bl[11] = al[11]; + br[11] = ar[11]; + bl[12] = al[12]; + br[12] = ar[12]; + + bl[15] = al[15]; + br[15] = ar[15]; + + bl[16] = vaddq_s32(al[19], al[16]); + br[16] = vaddq_s32(ar[19], ar[16]); + bl[17] = vaddq_s32(al[18], al[17]); + br[17] = vaddq_s32(ar[18], ar[17]); + bl[18] = vsubq_s32(al[17], al[18]); + br[18] = vsubq_s32(ar[17], ar[18]); + bl[19] = vsubq_s32(al[16], al[19]); + br[19] = vsubq_s32(ar[16], ar[19]); + bl[20] = vsubq_s32(al[23], al[20]); + br[20] = vsubq_s32(ar[23], ar[20]); + bl[21] = vsubq_s32(al[22], al[21]); + br[21] = vsubq_s32(ar[22], ar[21]); + bl[22] = vaddq_s32(al[21], al[22]); + br[22] = vaddq_s32(ar[21], ar[22]); + bl[23] = vaddq_s32(al[20], al[23]); + br[23] = vaddq_s32(ar[20], ar[23]); + bl[24] = vaddq_s32(al[27], al[24]); + br[24] = vaddq_s32(ar[27], ar[24]); + bl[25] = vaddq_s32(al[26], al[25]); + br[25] = vaddq_s32(ar[26], ar[25]); + bl[26] = vsubq_s32(al[25], al[26]); + br[26] = vsubq_s32(ar[25], ar[26]); + bl[27] = vsubq_s32(al[24], al[27]); + br[27] = vsubq_s32(ar[24], ar[27]); + bl[28] = vsubq_s32(al[31], al[28]); + br[28] = vsubq_s32(ar[31], ar[28]); + bl[29] = vsubq_s32(al[30], al[29]); + br[29] = vsubq_s32(ar[30], ar[29]); + bl[30] = vaddq_s32(al[29], al[30]); + br[30] = vaddq_s32(ar[29], ar[30]); + bl[31] = vaddq_s32(al[28], al[31]); + br[31] = vaddq_s32(ar[28], ar[31]); + + // Stage 6. + al[0] = bl[0]; + ar[0] = br[0]; + al[1] = bl[1]; + ar[1] = br[1]; + al[2] = bl[2]; + ar[2] = br[2]; + al[3] = bl[3]; + ar[3] = br[3]; + + butterfly_two_coeff_s32_s64_narrow(bl[7], br[7], bl[4], br[4], cospi_4_64, + cospi_28_64, &al[4], &ar[4], &al[7], + &ar[7]); + butterfly_two_coeff_s32_s64_narrow(bl[6], br[6], bl[5], br[5], cospi_20_64, + cospi_12_64, &al[5], &ar[5], &al[6], + &ar[6]); + + al[8] = vaddq_s32(bl[8], bl[9]); + ar[8] = vaddq_s32(br[8], br[9]); + al[9] = vsubq_s32(bl[8], bl[9]); + ar[9] = vsubq_s32(br[8], br[9]); + al[10] = vsubq_s32(bl[11], bl[10]); + ar[10] = vsubq_s32(br[11], br[10]); + al[11] = vaddq_s32(bl[11], bl[10]); + ar[11] = vaddq_s32(br[11], br[10]); + al[12] = vaddq_s32(bl[12], bl[13]); + ar[12] = vaddq_s32(br[12], br[13]); + al[13] = vsubq_s32(bl[12], bl[13]); + ar[13] = vsubq_s32(br[12], br[13]); + al[14] = vsubq_s32(bl[15], bl[14]); + ar[14] = vsubq_s32(br[15], br[14]); + al[15] = vaddq_s32(bl[15], bl[14]); + ar[15] = vaddq_s32(br[15], br[14]); + + al[16] = bl[16]; + ar[16] = br[16]; + al[19] = bl[19]; + ar[19] = br[19]; + al[20] = bl[20]; + ar[20] = br[20]; + al[23] = bl[23]; + ar[23] = br[23]; + al[24] = bl[24]; + ar[24] = br[24]; + al[27] = bl[27]; + ar[27] = br[27]; + al[28] = bl[28]; + ar[28] = br[28]; + al[31] = bl[31]; + ar[31] = br[31]; + + butterfly_two_coeff_s32_s64_narrow(bl[30], br[30], bl[17], br[17], cospi_4_64, + cospi_28_64, &al[30], &ar[30], &al[17], + &ar[17]); + butterfly_two_coeff_s32_s64_narrow(bl[29], br[29], bl[18], br[18], + cospi_28_64, -cospi_4_64, &al[29], &ar[29], + &al[18], &ar[18]); + butterfly_two_coeff_s32_s64_narrow(bl[26], br[26], bl[21], br[21], + cospi_20_64, cospi_12_64, &al[26], &ar[26], + &al[21], &ar[21]); + butterfly_two_coeff_s32_s64_narrow(bl[25], br[25], bl[22], br[22], + cospi_12_64, -cospi_20_64, &al[25], + &ar[25], &al[22], &ar[22]); + + // Stage 7. + bl[0] = al[0]; + br[0] = ar[0]; + bl[1] = al[1]; + br[1] = ar[1]; + bl[2] = al[2]; + br[2] = ar[2]; + bl[3] = al[3]; + br[3] = ar[3]; + bl[4] = al[4]; + br[4] = ar[4]; + bl[5] = al[5]; + br[5] = ar[5]; + bl[6] = al[6]; + br[6] = ar[6]; + bl[7] = al[7]; + br[7] = ar[7]; + + butterfly_two_coeff_s32_s64_narrow(al[15], ar[15], al[8], ar[8], cospi_2_64, + cospi_30_64, &bl[8], &br[8], &bl[15], + &br[15]); + butterfly_two_coeff_s32_s64_narrow(al[14], ar[14], al[9], ar[9], cospi_18_64, + cospi_14_64, &bl[9], &br[9], &bl[14], + &br[14]); + butterfly_two_coeff_s32_s64_narrow(al[13], ar[13], al[10], ar[10], + cospi_10_64, cospi_22_64, &bl[10], &br[10], + &bl[13], &br[13]); + butterfly_two_coeff_s32_s64_narrow(al[12], ar[12], al[11], ar[11], + cospi_26_64, cospi_6_64, &bl[11], &br[11], + &bl[12], &br[12]); + + bl[16] = vaddq_s32(al[16], al[17]); + br[16] = vaddq_s32(ar[16], ar[17]); + bl[17] = vsubq_s32(al[16], al[17]); + br[17] = vsubq_s32(ar[16], ar[17]); + bl[18] = vsubq_s32(al[19], al[18]); + br[18] = vsubq_s32(ar[19], ar[18]); + bl[19] = vaddq_s32(al[19], al[18]); + br[19] = vaddq_s32(ar[19], ar[18]); + bl[20] = vaddq_s32(al[20], al[21]); + br[20] = vaddq_s32(ar[20], ar[21]); + bl[21] = vsubq_s32(al[20], al[21]); + br[21] = vsubq_s32(ar[20], ar[21]); + bl[22] = vsubq_s32(al[23], al[22]); + br[22] = vsubq_s32(ar[23], ar[22]); + bl[23] = vaddq_s32(al[23], al[22]); + br[23] = vaddq_s32(ar[23], ar[22]); + bl[24] = vaddq_s32(al[24], al[25]); + br[24] = vaddq_s32(ar[24], ar[25]); + bl[25] = vsubq_s32(al[24], al[25]); + br[25] = vsubq_s32(ar[24], ar[25]); + bl[26] = vsubq_s32(al[27], al[26]); + br[26] = vsubq_s32(ar[27], ar[26]); + bl[27] = vaddq_s32(al[27], al[26]); + br[27] = vaddq_s32(ar[27], ar[26]); + bl[28] = vaddq_s32(al[28], al[29]); + br[28] = vaddq_s32(ar[28], ar[29]); + bl[29] = vsubq_s32(al[28], al[29]); + br[29] = vsubq_s32(ar[28], ar[29]); + bl[30] = vsubq_s32(al[31], al[30]); + br[30] = vsubq_s32(ar[31], ar[30]); + bl[31] = vaddq_s32(al[31], al[30]); + br[31] = vaddq_s32(ar[31], ar[30]); + + // Final stage. + + left[0] = bl[0]; + right[0] = br[0]; + left[16] = bl[1]; + right[16] = br[1]; + left[8] = bl[2]; + right[8] = br[2]; + left[24] = bl[3]; + right[24] = br[3]; + left[4] = bl[4]; + right[4] = br[4]; + left[20] = bl[5]; + right[20] = br[5]; + left[12] = bl[6]; + right[12] = br[6]; + left[28] = bl[7]; + right[28] = br[7]; + left[2] = bl[8]; + right[2] = br[8]; + left[18] = bl[9]; + right[18] = br[9]; + left[10] = bl[10]; + right[10] = br[10]; + left[26] = bl[11]; + right[26] = br[11]; + left[6] = bl[12]; + right[6] = br[12]; + left[22] = bl[13]; + right[22] = br[13]; + left[14] = bl[14]; + right[14] = br[14]; + left[30] = bl[15]; + right[30] = br[15]; + + butterfly_two_coeff_s32_s64_narrow(bl[31], br[31], bl[16], br[16], cospi_1_64, + cospi_31_64, &al[1], &ar[1], &al[31], + &ar[31]); + left[1] = al[1]; + right[1] = ar[1]; + left[31] = al[31]; + right[31] = ar[31]; + + butterfly_two_coeff_s32_s64_narrow(bl[30], br[30], bl[17], br[17], + cospi_17_64, cospi_15_64, &al[17], &ar[17], + &al[15], &ar[15]); + left[17] = al[17]; + right[17] = ar[17]; + left[15] = al[15]; + right[15] = ar[15]; + + butterfly_two_coeff_s32_s64_narrow(bl[29], br[29], bl[18], br[18], cospi_9_64, + cospi_23_64, &al[9], &ar[9], &al[23], + &ar[23]); + left[9] = al[9]; + right[9] = ar[9]; + left[23] = al[23]; + right[23] = ar[23]; + + butterfly_two_coeff_s32_s64_narrow(bl[28], br[28], bl[19], br[19], + cospi_25_64, cospi_7_64, &al[25], &ar[25], + &al[7], &ar[7]); + left[25] = al[25]; + right[25] = ar[25]; + left[7] = al[7]; + right[7] = ar[7]; + + butterfly_two_coeff_s32_s64_narrow(bl[27], br[27], bl[20], br[20], cospi_5_64, + cospi_27_64, &al[5], &ar[5], &al[27], + &ar[27]); + left[5] = al[5]; + right[5] = ar[5]; + left[27] = al[27]; + right[27] = ar[27]; + + butterfly_two_coeff_s32_s64_narrow(bl[26], br[26], bl[21], br[21], + cospi_21_64, cospi_11_64, &al[21], &ar[21], + &al[11], &ar[11]); + left[21] = al[21]; + right[21] = ar[21]; + left[11] = al[11]; + right[11] = ar[11]; + + butterfly_two_coeff_s32_s64_narrow(bl[25], br[25], bl[22], br[22], + cospi_13_64, cospi_19_64, &al[13], &ar[13], + &al[19], &ar[19]); + left[13] = al[13]; + right[13] = ar[13]; + left[19] = al[19]; + right[19] = ar[19]; + + butterfly_two_coeff_s32_s64_narrow(bl[24], br[24], bl[23], br[23], + cospi_29_64, cospi_3_64, &al[29], &ar[29], + &al[3], &ar[3]); + left[29] = al[29]; + right[29] = ar[29]; + left[3] = al[3]; + right[3] = ar[3]; +} + +static INLINE void highbd_dct8x32_body_second_pass_rd(int32x4_t *left /*32*/, + int32x4_t *right /*32*/) { + int32x4_t al[32], ar[32]; + int32x4_t bl[32], br[32]; + + // Stage 1: Done as part of the load. + + // Stage 2. + // For the "rd" version, all the values are rounded down after stage 2 to keep + // the values in 16 bits. + al[0] = add_round_shift_s32(vaddq_s32(left[0], left[15])); + ar[0] = add_round_shift_s32(vaddq_s32(right[0], right[15])); + al[1] = add_round_shift_s32(vaddq_s32(left[1], left[14])); + ar[1] = add_round_shift_s32(vaddq_s32(right[1], right[14])); + al[2] = add_round_shift_s32(vaddq_s32(left[2], left[13])); + ar[2] = add_round_shift_s32(vaddq_s32(right[2], right[13])); + al[3] = add_round_shift_s32(vaddq_s32(left[3], left[12])); + ar[3] = add_round_shift_s32(vaddq_s32(right[3], right[12])); + al[4] = add_round_shift_s32(vaddq_s32(left[4], left[11])); + ar[4] = add_round_shift_s32(vaddq_s32(right[4], right[11])); + al[5] = add_round_shift_s32(vaddq_s32(left[5], left[10])); + ar[5] = add_round_shift_s32(vaddq_s32(right[5], right[10])); + al[6] = add_round_shift_s32(vaddq_s32(left[6], left[9])); + ar[6] = add_round_shift_s32(vaddq_s32(right[6], right[9])); + al[7] = add_round_shift_s32(vaddq_s32(left[7], left[8])); + ar[7] = add_round_shift_s32(vaddq_s32(right[7], right[8])); + + al[8] = add_round_shift_s32(vsubq_s32(left[7], left[8])); + ar[8] = add_round_shift_s32(vsubq_s32(right[7], right[8])); + al[9] = add_round_shift_s32(vsubq_s32(left[6], left[9])); + ar[9] = add_round_shift_s32(vsubq_s32(right[6], right[9])); + al[10] = add_round_shift_s32(vsubq_s32(left[5], left[10])); + ar[10] = add_round_shift_s32(vsubq_s32(right[5], right[10])); + al[11] = add_round_shift_s32(vsubq_s32(left[4], left[11])); + ar[11] = add_round_shift_s32(vsubq_s32(right[4], right[11])); + al[12] = add_round_shift_s32(vsubq_s32(left[3], left[12])); + ar[12] = add_round_shift_s32(vsubq_s32(right[3], right[12])); + al[13] = add_round_shift_s32(vsubq_s32(left[2], left[13])); + ar[13] = add_round_shift_s32(vsubq_s32(right[2], right[13])); + al[14] = add_round_shift_s32(vsubq_s32(left[1], left[14])); + ar[14] = add_round_shift_s32(vsubq_s32(right[1], right[14])); + al[15] = add_round_shift_s32(vsubq_s32(left[0], left[15])); + ar[15] = add_round_shift_s32(vsubq_s32(right[0], right[15])); + + al[16] = add_round_shift_s32(left[16]); + ar[16] = add_round_shift_s32(right[16]); + al[17] = add_round_shift_s32(left[17]); + ar[17] = add_round_shift_s32(right[17]); + al[18] = add_round_shift_s32(left[18]); + ar[18] = add_round_shift_s32(right[18]); + al[19] = add_round_shift_s32(left[19]); + ar[19] = add_round_shift_s32(right[19]); + + butterfly_one_coeff_s32_fast(left[27], right[27], left[20], right[20], + cospi_16_64, &al[27], &ar[27], &al[20], &ar[20]); + butterfly_one_coeff_s32_fast(left[26], right[26], left[21], right[21], + cospi_16_64, &al[26], &ar[26], &al[21], &ar[21]); + butterfly_one_coeff_s32_fast(left[25], right[25], left[22], right[22], + cospi_16_64, &al[25], &ar[25], &al[22], &ar[22]); + butterfly_one_coeff_s32_fast(left[24], right[24], left[23], right[23], + cospi_16_64, &al[24], &ar[24], &al[23], &ar[23]); + + al[20] = add_round_shift_s32(al[20]); + ar[20] = add_round_shift_s32(ar[20]); + al[21] = add_round_shift_s32(al[21]); + ar[21] = add_round_shift_s32(ar[21]); + al[22] = add_round_shift_s32(al[22]); + ar[22] = add_round_shift_s32(ar[22]); + al[23] = add_round_shift_s32(al[23]); + ar[23] = add_round_shift_s32(ar[23]); + al[24] = add_round_shift_s32(al[24]); + ar[24] = add_round_shift_s32(ar[24]); + al[25] = add_round_shift_s32(al[25]); + ar[25] = add_round_shift_s32(ar[25]); + al[26] = add_round_shift_s32(al[26]); + ar[26] = add_round_shift_s32(ar[26]); + al[27] = add_round_shift_s32(al[27]); + ar[27] = add_round_shift_s32(ar[27]); + + al[28] = add_round_shift_s32(left[28]); + ar[28] = add_round_shift_s32(right[28]); + al[29] = add_round_shift_s32(left[29]); + ar[29] = add_round_shift_s32(right[29]); + al[30] = add_round_shift_s32(left[30]); + ar[30] = add_round_shift_s32(right[30]); + al[31] = add_round_shift_s32(left[31]); + ar[31] = add_round_shift_s32(right[31]); + + // Stage 3. + bl[0] = vaddq_s32(al[0], al[7]); + br[0] = vaddq_s32(ar[0], ar[7]); + bl[1] = vaddq_s32(al[1], al[6]); + br[1] = vaddq_s32(ar[1], ar[6]); + bl[2] = vaddq_s32(al[2], al[5]); + br[2] = vaddq_s32(ar[2], ar[5]); + bl[3] = vaddq_s32(al[3], al[4]); + br[3] = vaddq_s32(ar[3], ar[4]); + + bl[4] = vsubq_s32(al[3], al[4]); + br[4] = vsubq_s32(ar[3], ar[4]); + bl[5] = vsubq_s32(al[2], al[5]); + br[5] = vsubq_s32(ar[2], ar[5]); + bl[6] = vsubq_s32(al[1], al[6]); + br[6] = vsubq_s32(ar[1], ar[6]); + bl[7] = vsubq_s32(al[0], al[7]); + br[7] = vsubq_s32(ar[0], ar[7]); + + bl[8] = al[8]; + br[8] = ar[8]; + bl[9] = al[9]; + br[9] = ar[9]; + + butterfly_one_coeff_s32_fast(al[13], ar[13], al[10], ar[10], cospi_16_64, + &bl[13], &br[13], &bl[10], &br[10]); + butterfly_one_coeff_s32_fast(al[12], ar[12], al[11], ar[11], cospi_16_64, + &bl[12], &br[12], &bl[11], &br[11]); + + bl[14] = al[14]; + br[14] = ar[14]; + bl[15] = al[15]; + br[15] = ar[15]; + + bl[16] = vaddq_s32(al[16], al[23]); + br[16] = vaddq_s32(ar[16], ar[23]); + bl[17] = vaddq_s32(al[17], al[22]); + br[17] = vaddq_s32(ar[17], ar[22]); + bl[18] = vaddq_s32(al[18], al[21]); + br[18] = vaddq_s32(ar[18], ar[21]); + bl[19] = vaddq_s32(al[19], al[20]); + br[19] = vaddq_s32(ar[19], ar[20]); + + bl[20] = vsubq_s32(al[19], al[20]); + br[20] = vsubq_s32(ar[19], ar[20]); + bl[21] = vsubq_s32(al[18], al[21]); + br[21] = vsubq_s32(ar[18], ar[21]); + bl[22] = vsubq_s32(al[17], al[22]); + br[22] = vsubq_s32(ar[17], ar[22]); + bl[23] = vsubq_s32(al[16], al[23]); + br[23] = vsubq_s32(ar[16], ar[23]); + + bl[24] = vsubq_s32(al[31], al[24]); + br[24] = vsubq_s32(ar[31], ar[24]); + bl[25] = vsubq_s32(al[30], al[25]); + br[25] = vsubq_s32(ar[30], ar[25]); + bl[26] = vsubq_s32(al[29], al[26]); + br[26] = vsubq_s32(ar[29], ar[26]); + bl[27] = vsubq_s32(al[28], al[27]); + br[27] = vsubq_s32(ar[28], ar[27]); + + bl[28] = vaddq_s32(al[28], al[27]); + br[28] = vaddq_s32(ar[28], ar[27]); + bl[29] = vaddq_s32(al[29], al[26]); + br[29] = vaddq_s32(ar[29], ar[26]); + bl[30] = vaddq_s32(al[30], al[25]); + br[30] = vaddq_s32(ar[30], ar[25]); + bl[31] = vaddq_s32(al[31], al[24]); + br[31] = vaddq_s32(ar[31], ar[24]); + + // Stage 4. + al[0] = vaddq_s32(bl[0], bl[3]); + ar[0] = vaddq_s32(br[0], br[3]); + al[1] = vaddq_s32(bl[1], bl[2]); + ar[1] = vaddq_s32(br[1], br[2]); + al[2] = vsubq_s32(bl[1], bl[2]); + ar[2] = vsubq_s32(br[1], br[2]); + al[3] = vsubq_s32(bl[0], bl[3]); + ar[3] = vsubq_s32(br[0], br[3]); + + al[4] = bl[4]; + ar[4] = br[4]; + + butterfly_one_coeff_s32_fast(bl[6], br[6], bl[5], br[5], cospi_16_64, &al[6], + &ar[6], &al[5], &ar[5]); + + al[7] = bl[7]; + ar[7] = br[7]; + + al[8] = vaddq_s32(bl[8], bl[11]); + ar[8] = vaddq_s32(br[8], br[11]); + al[9] = vaddq_s32(bl[9], bl[10]); + ar[9] = vaddq_s32(br[9], br[10]); + al[10] = vsubq_s32(bl[9], bl[10]); + ar[10] = vsubq_s32(br[9], br[10]); + al[11] = vsubq_s32(bl[8], bl[11]); + ar[11] = vsubq_s32(br[8], br[11]); + al[12] = vsubq_s32(bl[15], bl[12]); + ar[12] = vsubq_s32(br[15], br[12]); + al[13] = vsubq_s32(bl[14], bl[13]); + ar[13] = vsubq_s32(br[14], br[13]); + al[14] = vaddq_s32(bl[14], bl[13]); + ar[14] = vaddq_s32(br[14], br[13]); + al[15] = vaddq_s32(bl[15], bl[12]); + ar[15] = vaddq_s32(br[15], br[12]); + + al[16] = bl[16]; + ar[16] = br[16]; + al[17] = bl[17]; + ar[17] = br[17]; + + butterfly_two_coeff_s32(bl[29], br[29], bl[18], br[18], cospi_8_64, + cospi_24_64, &al[29], &ar[29], &al[18], &ar[18]); + butterfly_two_coeff_s32(bl[28], br[28], bl[19], br[19], cospi_8_64, + cospi_24_64, &al[28], &ar[28], &al[19], &ar[19]); + butterfly_two_coeff_s32(bl[27], br[27], bl[20], br[20], cospi_24_64, + -cospi_8_64, &al[27], &ar[27], &al[20], &ar[20]); + butterfly_two_coeff_s32(bl[26], br[26], bl[21], br[21], cospi_24_64, + -cospi_8_64, &al[26], &ar[26], &al[21], &ar[21]); + + al[22] = bl[22]; + ar[22] = br[22]; + al[23] = bl[23]; + ar[23] = br[23]; + al[24] = bl[24]; + ar[24] = br[24]; + al[25] = bl[25]; + ar[25] = br[25]; + + al[30] = bl[30]; + ar[30] = br[30]; + al[31] = bl[31]; + ar[31] = br[31]; + + // Stage 5. + butterfly_one_coeff_s32_fast(al[0], ar[0], al[1], ar[1], cospi_16_64, &bl[0], + &br[0], &bl[1], &br[1]); + butterfly_two_coeff_s32(al[3], ar[3], al[2], ar[2], cospi_8_64, cospi_24_64, + &bl[2], &br[2], &bl[3], &br[3]); + + bl[4] = vaddq_s32(al[4], al[5]); + br[4] = vaddq_s32(ar[4], ar[5]); + bl[5] = vsubq_s32(al[4], al[5]); + br[5] = vsubq_s32(ar[4], ar[5]); + bl[6] = vsubq_s32(al[7], al[6]); + br[6] = vsubq_s32(ar[7], ar[6]); + bl[7] = vaddq_s32(al[7], al[6]); + br[7] = vaddq_s32(ar[7], ar[6]); + + bl[8] = al[8]; + br[8] = ar[8]; + + butterfly_two_coeff_s32(al[14], ar[14], al[9], ar[9], cospi_8_64, cospi_24_64, + &bl[14], &br[14], &bl[9], &br[9]); + butterfly_two_coeff_s32(al[13], ar[13], al[10], ar[10], cospi_24_64, + -cospi_8_64, &bl[13], &br[13], &bl[10], &br[10]); + + bl[11] = al[11]; + br[11] = ar[11]; + bl[12] = al[12]; + br[12] = ar[12]; + + bl[15] = al[15]; + br[15] = ar[15]; + + bl[16] = vaddq_s32(al[19], al[16]); + br[16] = vaddq_s32(ar[19], ar[16]); + bl[17] = vaddq_s32(al[18], al[17]); + br[17] = vaddq_s32(ar[18], ar[17]); + bl[18] = vsubq_s32(al[17], al[18]); + br[18] = vsubq_s32(ar[17], ar[18]); + bl[19] = vsubq_s32(al[16], al[19]); + br[19] = vsubq_s32(ar[16], ar[19]); + bl[20] = vsubq_s32(al[23], al[20]); + br[20] = vsubq_s32(ar[23], ar[20]); + bl[21] = vsubq_s32(al[22], al[21]); + br[21] = vsubq_s32(ar[22], ar[21]); + bl[22] = vaddq_s32(al[21], al[22]); + br[22] = vaddq_s32(ar[21], ar[22]); + bl[23] = vaddq_s32(al[20], al[23]); + br[23] = vaddq_s32(ar[20], ar[23]); + bl[24] = vaddq_s32(al[27], al[24]); + br[24] = vaddq_s32(ar[27], ar[24]); + bl[25] = vaddq_s32(al[26], al[25]); + br[25] = vaddq_s32(ar[26], ar[25]); + bl[26] = vsubq_s32(al[25], al[26]); + br[26] = vsubq_s32(ar[25], ar[26]); + bl[27] = vsubq_s32(al[24], al[27]); + br[27] = vsubq_s32(ar[24], ar[27]); + bl[28] = vsubq_s32(al[31], al[28]); + br[28] = vsubq_s32(ar[31], ar[28]); + bl[29] = vsubq_s32(al[30], al[29]); + br[29] = vsubq_s32(ar[30], ar[29]); + bl[30] = vaddq_s32(al[29], al[30]); + br[30] = vaddq_s32(ar[29], ar[30]); + bl[31] = vaddq_s32(al[28], al[31]); + br[31] = vaddq_s32(ar[28], ar[31]); + + // Stage 6. + al[0] = bl[0]; + ar[0] = br[0]; + al[1] = bl[1]; + ar[1] = br[1]; + al[2] = bl[2]; + ar[2] = br[2]; + al[3] = bl[3]; + ar[3] = br[3]; + + butterfly_two_coeff_s32(bl[7], br[7], bl[4], br[4], cospi_4_64, cospi_28_64, + &al[4], &ar[4], &al[7], &ar[7]); + butterfly_two_coeff_s32(bl[6], br[6], bl[5], br[5], cospi_20_64, cospi_12_64, + &al[5], &ar[5], &al[6], &ar[6]); + + al[8] = vaddq_s32(bl[8], bl[9]); + ar[8] = vaddq_s32(br[8], br[9]); + al[9] = vsubq_s32(bl[8], bl[9]); + ar[9] = vsubq_s32(br[8], br[9]); + al[10] = vsubq_s32(bl[11], bl[10]); + ar[10] = vsubq_s32(br[11], br[10]); + al[11] = vaddq_s32(bl[11], bl[10]); + ar[11] = vaddq_s32(br[11], br[10]); + al[12] = vaddq_s32(bl[12], bl[13]); + ar[12] = vaddq_s32(br[12], br[13]); + al[13] = vsubq_s32(bl[12], bl[13]); + ar[13] = vsubq_s32(br[12], br[13]); + al[14] = vsubq_s32(bl[15], bl[14]); + ar[14] = vsubq_s32(br[15], br[14]); + al[15] = vaddq_s32(bl[15], bl[14]); + ar[15] = vaddq_s32(br[15], br[14]); + + al[16] = bl[16]; + ar[16] = br[16]; + al[19] = bl[19]; + ar[19] = br[19]; + al[20] = bl[20]; + ar[20] = br[20]; + al[23] = bl[23]; + ar[23] = br[23]; + al[24] = bl[24]; + ar[24] = br[24]; + al[27] = bl[27]; + ar[27] = br[27]; + al[28] = bl[28]; + ar[28] = br[28]; + al[31] = bl[31]; + ar[31] = br[31]; + + butterfly_two_coeff_s32(bl[30], br[30], bl[17], br[17], cospi_4_64, + cospi_28_64, &al[30], &ar[30], &al[17], &ar[17]); + butterfly_two_coeff_s32(bl[29], br[29], bl[18], br[18], cospi_28_64, + -cospi_4_64, &al[29], &ar[29], &al[18], &ar[18]); + butterfly_two_coeff_s32(bl[26], br[26], bl[21], br[21], cospi_20_64, + cospi_12_64, &al[26], &ar[26], &al[21], &ar[21]); + butterfly_two_coeff_s32(bl[25], br[25], bl[22], br[22], cospi_12_64, + -cospi_20_64, &al[25], &ar[25], &al[22], &ar[22]); + + // Stage 7. + bl[0] = al[0]; + br[0] = ar[0]; + bl[1] = al[1]; + br[1] = ar[1]; + bl[2] = al[2]; + br[2] = ar[2]; + bl[3] = al[3]; + br[3] = ar[3]; + bl[4] = al[4]; + br[4] = ar[4]; + bl[5] = al[5]; + br[5] = ar[5]; + bl[6] = al[6]; + br[6] = ar[6]; + bl[7] = al[7]; + br[7] = ar[7]; + + butterfly_two_coeff_s32(al[15], ar[15], al[8], ar[8], cospi_2_64, cospi_30_64, + &bl[8], &br[8], &bl[15], &br[15]); + butterfly_two_coeff_s32(al[14], ar[14], al[9], ar[9], cospi_18_64, + cospi_14_64, &bl[9], &br[9], &bl[14], &br[14]); + butterfly_two_coeff_s32(al[13], ar[13], al[10], ar[10], cospi_10_64, + cospi_22_64, &bl[10], &br[10], &bl[13], &br[13]); + butterfly_two_coeff_s32(al[12], ar[12], al[11], ar[11], cospi_26_64, + cospi_6_64, &bl[11], &br[11], &bl[12], &br[12]); + + bl[16] = vaddq_s32(al[16], al[17]); + br[16] = vaddq_s32(ar[16], ar[17]); + bl[17] = vsubq_s32(al[16], al[17]); + br[17] = vsubq_s32(ar[16], ar[17]); + bl[18] = vsubq_s32(al[19], al[18]); + br[18] = vsubq_s32(ar[19], ar[18]); + bl[19] = vaddq_s32(al[19], al[18]); + br[19] = vaddq_s32(ar[19], ar[18]); + bl[20] = vaddq_s32(al[20], al[21]); + br[20] = vaddq_s32(ar[20], ar[21]); + bl[21] = vsubq_s32(al[20], al[21]); + br[21] = vsubq_s32(ar[20], ar[21]); + bl[22] = vsubq_s32(al[23], al[22]); + br[22] = vsubq_s32(ar[23], ar[22]); + bl[23] = vaddq_s32(al[23], al[22]); + br[23] = vaddq_s32(ar[23], ar[22]); + bl[24] = vaddq_s32(al[24], al[25]); + br[24] = vaddq_s32(ar[24], ar[25]); + bl[25] = vsubq_s32(al[24], al[25]); + br[25] = vsubq_s32(ar[24], ar[25]); + bl[26] = vsubq_s32(al[27], al[26]); + br[26] = vsubq_s32(ar[27], ar[26]); + bl[27] = vaddq_s32(al[27], al[26]); + br[27] = vaddq_s32(ar[27], ar[26]); + bl[28] = vaddq_s32(al[28], al[29]); + br[28] = vaddq_s32(ar[28], ar[29]); + bl[29] = vsubq_s32(al[28], al[29]); + br[29] = vsubq_s32(ar[28], ar[29]); + bl[30] = vsubq_s32(al[31], al[30]); + br[30] = vsubq_s32(ar[31], ar[30]); + bl[31] = vaddq_s32(al[31], al[30]); + br[31] = vaddq_s32(ar[31], ar[30]); + + // Final stage. + left[0] = bl[0]; + right[0] = br[0]; + left[16] = bl[1]; + right[16] = br[1]; + left[8] = bl[2]; + right[8] = br[2]; + left[24] = bl[3]; + right[24] = br[3]; + left[4] = bl[4]; + right[4] = br[4]; + left[20] = bl[5]; + right[20] = br[5]; + left[12] = bl[6]; + right[12] = br[6]; + left[28] = bl[7]; + right[28] = br[7]; + left[2] = bl[8]; + right[2] = br[8]; + left[18] = bl[9]; + right[18] = br[9]; + left[10] = bl[10]; + right[10] = br[10]; + left[26] = bl[11]; + right[26] = br[11]; + left[6] = bl[12]; + right[6] = br[12]; + left[22] = bl[13]; + right[22] = br[13]; + left[14] = bl[14]; + right[14] = br[14]; + left[30] = bl[15]; + right[30] = br[15]; + + butterfly_two_coeff_s32(bl[31], br[31], bl[16], br[16], cospi_1_64, + cospi_31_64, &al[1], &ar[1], &al[31], &ar[31]); + left[1] = al[1]; + right[1] = ar[1]; + left[31] = al[31]; + right[31] = ar[31]; + + butterfly_two_coeff_s32(bl[30], br[30], bl[17], br[17], cospi_17_64, + cospi_15_64, &al[17], &ar[17], &al[15], &ar[15]); + left[17] = al[17]; + right[17] = ar[17]; + left[15] = al[15]; + right[15] = ar[15]; + + butterfly_two_coeff_s32(bl[29], br[29], bl[18], br[18], cospi_9_64, + cospi_23_64, &al[9], &ar[9], &al[23], &ar[23]); + left[9] = al[9]; + right[9] = ar[9]; + left[23] = al[23]; + right[23] = ar[23]; + + butterfly_two_coeff_s32(bl[28], br[28], bl[19], br[19], cospi_25_64, + cospi_7_64, &al[25], &ar[25], &al[7], &ar[7]); + left[25] = al[25]; + right[25] = ar[25]; + left[7] = al[7]; + right[7] = ar[7]; + + butterfly_two_coeff_s32(bl[27], br[27], bl[20], br[20], cospi_5_64, + cospi_27_64, &al[5], &ar[5], &al[27], &ar[27]); + left[5] = al[5]; + right[5] = ar[5]; + left[27] = al[27]; + right[27] = ar[27]; + + butterfly_two_coeff_s32(bl[26], br[26], bl[21], br[21], cospi_21_64, + cospi_11_64, &al[21], &ar[21], &al[11], &ar[11]); + left[21] = al[21]; + right[21] = ar[21]; + left[11] = al[11]; + right[11] = ar[11]; + + butterfly_two_coeff_s32(bl[25], br[25], bl[22], br[22], cospi_13_64, + cospi_19_64, &al[13], &ar[13], &al[19], &ar[19]); + left[13] = al[13]; + right[13] = ar[13]; + left[19] = al[19]; + right[19] = ar[19]; + + butterfly_two_coeff_s32(bl[24], br[24], bl[23], br[23], cospi_29_64, + cospi_3_64, &al[29], &ar[29], &al[3], &ar[3]); + left[29] = al[29]; + right[29] = ar[29]; + left[3] = al[3]; + right[3] = ar[3]; +} + +#endif // CONFIG_VP9_HIGHBITDEPTH + +#endif // VPX_VPX_DSP_ARM_FDCT32X32_NEON_H_ diff --git a/libs/libvpx/vpx_dsp/arm/fdct_neon.c b/libs/libvpx/vpx_dsp/arm/fdct4x4_neon.c similarity index 56% rename from libs/libvpx/vpx_dsp/arm/fdct_neon.c rename to libs/libvpx/vpx_dsp/arm/fdct4x4_neon.c index 2827791f1e..4bc968ecba 100644 --- a/libs/libvpx/vpx_dsp/arm/fdct_neon.c +++ b/libs/libvpx/vpx_dsp/arm/fdct4x4_neon.c @@ -18,10 +18,10 @@ #include "vpx_dsp/arm/fdct_neon.h" #include "vpx_dsp/arm/mem_neon.h" #include "vpx_dsp/arm/transpose_neon.h" +#include "vpx_dsp/arm/fdct4x4_neon.h" void vpx_fdct4x4_neon(const int16_t *input, tran_low_t *final_output, int stride) { - int i; // input[M * stride] * 16 int16x4_t in[4]; in[0] = vshl_n_s16(vld1_s16(input + 0 * stride), 4); @@ -34,9 +34,8 @@ void vpx_fdct4x4_neon(const int16_t *input, tran_low_t *final_output, const int16x4_t one = vreinterpret_s16_s64(vdup_n_s64(1)); in[0] = vadd_s16(in[0], one); } - for (i = 0; i < 2; ++i) { - vpx_fdct4x4_pass1_neon(in); - } + vpx_fdct4x4_pass1_neon(in); + vpx_fdct4x4_pass2_neon(in); { // Not quite a rounding shift. Only add 1 despite shifting by 2. const int16x8_t one = vdupq_n_s16(1); @@ -48,3 +47,39 @@ void vpx_fdct4x4_neon(const int16_t *input, tran_low_t *final_output, store_s16q_to_tran_low(final_output + 1 * 8, out_23); } } + +#if CONFIG_VP9_HIGHBITDEPTH + +void vpx_highbd_fdct4x4_neon(const int16_t *input, tran_low_t *final_output, + int stride) { + const int32x4_t const_one = vdupq_n_s32(1); + + // input[M * stride] * 16 + int32x4_t in[4]; + in[0] = vshll_n_s16(vld1_s16(input + 0 * stride), 4); + in[1] = vshll_n_s16(vld1_s16(input + 1 * stride), 4); + in[2] = vshll_n_s16(vld1_s16(input + 2 * stride), 4); + in[3] = vshll_n_s16(vld1_s16(input + 3 * stride), 4); + + // If the very first value != 0, then add 1. + if (input[0] != 0) { + static const int32_t k1000[4] = { 1, 0, 0, 0 }; + in[0] = vaddq_s32(in[0], vld1q_s32(k1000)); + } + + vpx_highbd_fdct4x4_pass1_neon(in); + vpx_highbd_fdct4x4_pass1_neon(in); + { + // Not quite a rounding shift. Only add 1 despite shifting by 2. + in[0] = vshrq_n_s32(vaddq_s32(in[0], const_one), 2); + in[1] = vshrq_n_s32(vaddq_s32(in[1], const_one), 2); + in[2] = vshrq_n_s32(vaddq_s32(in[2], const_one), 2); + in[3] = vshrq_n_s32(vaddq_s32(in[3], const_one), 2); + + vst1q_s32(final_output, in[0]); + vst1q_s32(final_output + 4, in[1]); + vst1q_s32(final_output + 8, in[2]); + vst1q_s32(final_output + 12, in[3]); + } +} +#endif // CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vpx_dsp/arm/fdct4x4_neon.h b/libs/libvpx/vpx_dsp/arm/fdct4x4_neon.h new file mode 100644 index 0000000000..de3db9774c --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/fdct4x4_neon.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VPX_DSP_ARM_FDCT4X4_NEON_H_ +#define VPX_VPX_DSP_ARM_FDCT4X4_NEON_H_ + +#include + +static INLINE void vpx_fdct4x4_pass1_neon(int16x4_t *in) { + int16x4_t out[4]; + + const int16x8_t input_01 = vcombine_s16(in[0], in[1]); + const int16x8_t input_32 = vcombine_s16(in[3], in[2]); + + // in_0 +/- in_3, in_1 +/- in_2 + const int16x8_t s_01 = vaddq_s16(input_01, input_32); + const int16x8_t s_32 = vsubq_s16(input_01, input_32); + + // step_0 +/- step_1, step_2 +/- step_3 + const int16x4_t s_0 = vget_low_s16(s_01); + const int16x4_t s_1 = vget_high_s16(s_01); + const int16x4_t s_2 = vget_high_s16(s_32); + const int16x4_t s_3 = vget_low_s16(s_32); + + // fdct_round_shift(s_0 +/- s_1) * cospi_16_64 + butterfly_one_coeff_s16_fast_half(s_0, s_1, cospi_16_64, &out[0], &out[2]); + + // s_3 * cospi_8_64 + s_2 * cospi_24_64 + // s_3 * cospi_24_64 - s_2 * cospi_8_64 + butterfly_two_coeff_half(s_3, s_2, cospi_8_64, cospi_24_64, &out[1], &out[3]); + + transpose_s16_4x4d(&out[0], &out[1], &out[2], &out[3]); + + in[0] = out[0]; + in[1] = out[1]; + in[2] = out[2]; + in[3] = out[3]; +} + +static INLINE void vpx_fdct4x4_pass2_neon(int16x4_t *in) { + int16x4_t out[4]; + + const int16x8_t input_01 = vcombine_s16(in[0], in[1]); + const int16x8_t input_32 = vcombine_s16(in[3], in[2]); + + // in_0 +/- in_3, in_1 +/- in_2 + const int16x8_t s_01 = vaddq_s16(input_01, input_32); + const int16x8_t s_32 = vsubq_s16(input_01, input_32); + + // step_0 +/- step_1, step_2 +/- step_3 + const int16x4_t s_0 = vget_low_s16(s_01); + const int16x4_t s_1 = vget_high_s16(s_01); + const int16x4_t s_2 = vget_high_s16(s_32); + const int16x4_t s_3 = vget_low_s16(s_32); + + // fdct_round_shift(s_0 +/- s_1) * cospi_16_64 + butterfly_one_coeff_s16_s32_fast_narrow_half(s_0, s_1, cospi_16_64, &out[0], + &out[2]); + + // s_3 * cospi_8_64 + s_2 * cospi_24_64 + // s_3 * cospi_24_64 - s_2 * cospi_8_64 + butterfly_two_coeff_half(s_3, s_2, cospi_8_64, cospi_24_64, &out[1], &out[3]); + + transpose_s16_4x4d(&out[0], &out[1], &out[2], &out[3]); + + in[0] = out[0]; + in[1] = out[1]; + in[2] = out[2]; + in[3] = out[3]; +} + +#if CONFIG_VP9_HIGHBITDEPTH + +static INLINE void vpx_highbd_fdct4x4_pass1_neon(int32x4_t *in) { + int32x4_t out[4]; + // in_0 +/- in_3, in_1 +/- in_2 + const int32x4_t s_0 = vaddq_s32(in[0], in[3]); + const int32x4_t s_1 = vaddq_s32(in[1], in[2]); + const int32x4_t s_2 = vsubq_s32(in[1], in[2]); + const int32x4_t s_3 = vsubq_s32(in[0], in[3]); + + butterfly_one_coeff_s32_fast_half(s_0, s_1, cospi_16_64, &out[0], &out[2]); + + // out[1] = s_3 * cospi_8_64 + s_2 * cospi_24_64 + // out[3] = s_3 * cospi_24_64 - s_2 * cospi_8_64 + butterfly_two_coeff_s32_s64_narrow_half(s_3, s_2, cospi_8_64, cospi_24_64, + &out[1], &out[3]); + + transpose_s32_4x4(&out[0], &out[1], &out[2], &out[3]); + + in[0] = out[0]; + in[1] = out[1]; + in[2] = out[2]; + in[3] = out[3]; +} + +#endif // CONFIG_VP9_HIGHBITDEPTH +#endif // VPX_VPX_DSP_ARM_FDCT4X4_NEON_H_ diff --git a/libs/libvpx/vpx_dsp/arm/fdct8x8_neon.c b/libs/libvpx/vpx_dsp/arm/fdct8x8_neon.c new file mode 100644 index 0000000000..75ee6f2230 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/fdct8x8_neon.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2015 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" +#include "vpx_dsp/txfm_common.h" +#include "vpx_dsp/vpx_dsp_common.h" +#include "vpx_dsp/arm/idct_neon.h" +#include "vpx_dsp/arm/fdct_neon.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/fdct8x8_neon.h" + +void vpx_fdct8x8_neon(const int16_t *input, tran_low_t *final_output, + int stride) { + // stage 1 + int16x8_t in[8]; + in[0] = vshlq_n_s16(vld1q_s16(&input[0 * stride]), 2); + in[1] = vshlq_n_s16(vld1q_s16(&input[1 * stride]), 2); + in[2] = vshlq_n_s16(vld1q_s16(&input[2 * stride]), 2); + in[3] = vshlq_n_s16(vld1q_s16(&input[3 * stride]), 2); + in[4] = vshlq_n_s16(vld1q_s16(&input[4 * stride]), 2); + in[5] = vshlq_n_s16(vld1q_s16(&input[5 * stride]), 2); + in[6] = vshlq_n_s16(vld1q_s16(&input[6 * stride]), 2); + in[7] = vshlq_n_s16(vld1q_s16(&input[7 * stride]), 2); + + vpx_fdct8x8_pass1_neon(in); + vpx_fdct8x8_pass2_neon(in); + { + // from vpx_dct_sse2.c + // Post-condition (division by two) + // division of two 16 bits signed numbers using shifts + // n / 2 = (n - (n >> 15)) >> 1 + const int16x8_t sign_in0 = vshrq_n_s16(in[0], 15); + const int16x8_t sign_in1 = vshrq_n_s16(in[1], 15); + const int16x8_t sign_in2 = vshrq_n_s16(in[2], 15); + const int16x8_t sign_in3 = vshrq_n_s16(in[3], 15); + const int16x8_t sign_in4 = vshrq_n_s16(in[4], 15); + const int16x8_t sign_in5 = vshrq_n_s16(in[5], 15); + const int16x8_t sign_in6 = vshrq_n_s16(in[6], 15); + const int16x8_t sign_in7 = vshrq_n_s16(in[7], 15); + in[0] = vhsubq_s16(in[0], sign_in0); + in[1] = vhsubq_s16(in[1], sign_in1); + in[2] = vhsubq_s16(in[2], sign_in2); + in[3] = vhsubq_s16(in[3], sign_in3); + in[4] = vhsubq_s16(in[4], sign_in4); + in[5] = vhsubq_s16(in[5], sign_in5); + in[6] = vhsubq_s16(in[6], sign_in6); + in[7] = vhsubq_s16(in[7], sign_in7); + // store results + store_s16q_to_tran_low(final_output + 0 * 8, in[0]); + store_s16q_to_tran_low(final_output + 1 * 8, in[1]); + store_s16q_to_tran_low(final_output + 2 * 8, in[2]); + store_s16q_to_tran_low(final_output + 3 * 8, in[3]); + store_s16q_to_tran_low(final_output + 4 * 8, in[4]); + store_s16q_to_tran_low(final_output + 5 * 8, in[5]); + store_s16q_to_tran_low(final_output + 6 * 8, in[6]); + store_s16q_to_tran_low(final_output + 7 * 8, in[7]); + } +} + +#if CONFIG_VP9_HIGHBITDEPTH + +void vpx_highbd_fdct8x8_neon(const int16_t *input, tran_low_t *final_output, + int stride) { + // input[M * stride] * 16 + int32x4_t left[8], right[8]; + int16x8_t in[8]; + in[0] = vld1q_s16(input + 0 * stride); + in[1] = vld1q_s16(input + 1 * stride); + in[2] = vld1q_s16(input + 2 * stride); + in[3] = vld1q_s16(input + 3 * stride); + in[4] = vld1q_s16(input + 4 * stride); + in[5] = vld1q_s16(input + 5 * stride); + in[6] = vld1q_s16(input + 6 * stride); + in[7] = vld1q_s16(input + 7 * stride); + + left[0] = vshll_n_s16(vget_low_s16(in[0]), 2); + left[1] = vshll_n_s16(vget_low_s16(in[1]), 2); + left[2] = vshll_n_s16(vget_low_s16(in[2]), 2); + left[3] = vshll_n_s16(vget_low_s16(in[3]), 2); + left[4] = vshll_n_s16(vget_low_s16(in[4]), 2); + left[5] = vshll_n_s16(vget_low_s16(in[5]), 2); + left[6] = vshll_n_s16(vget_low_s16(in[6]), 2); + left[7] = vshll_n_s16(vget_low_s16(in[7]), 2); + right[0] = vshll_n_s16(vget_high_s16(in[0]), 2); + right[1] = vshll_n_s16(vget_high_s16(in[1]), 2); + right[2] = vshll_n_s16(vget_high_s16(in[2]), 2); + right[3] = vshll_n_s16(vget_high_s16(in[3]), 2); + right[4] = vshll_n_s16(vget_high_s16(in[4]), 2); + right[5] = vshll_n_s16(vget_high_s16(in[5]), 2); + right[6] = vshll_n_s16(vget_high_s16(in[6]), 2); + right[7] = vshll_n_s16(vget_high_s16(in[7]), 2); + + vpx_highbd_fdct8x8_pass1_neon(left, right); + vpx_highbd_fdct8x8_pass2_neon(left, right); + { + left[0] = add_round_shift_half_s32(left[0]); + left[1] = add_round_shift_half_s32(left[1]); + left[2] = add_round_shift_half_s32(left[2]); + left[3] = add_round_shift_half_s32(left[3]); + left[4] = add_round_shift_half_s32(left[4]); + left[5] = add_round_shift_half_s32(left[5]); + left[6] = add_round_shift_half_s32(left[6]); + left[7] = add_round_shift_half_s32(left[7]); + right[0] = add_round_shift_half_s32(right[0]); + right[1] = add_round_shift_half_s32(right[1]); + right[2] = add_round_shift_half_s32(right[2]); + right[3] = add_round_shift_half_s32(right[3]); + right[4] = add_round_shift_half_s32(right[4]); + right[5] = add_round_shift_half_s32(right[5]); + right[6] = add_round_shift_half_s32(right[6]); + right[7] = add_round_shift_half_s32(right[7]); + + // store results + vst1q_s32(final_output, left[0]); + vst1q_s32(final_output + 4, right[0]); + vst1q_s32(final_output + 8, left[1]); + vst1q_s32(final_output + 12, right[1]); + vst1q_s32(final_output + 16, left[2]); + vst1q_s32(final_output + 20, right[2]); + vst1q_s32(final_output + 24, left[3]); + vst1q_s32(final_output + 28, right[3]); + vst1q_s32(final_output + 32, left[4]); + vst1q_s32(final_output + 36, right[4]); + vst1q_s32(final_output + 40, left[5]); + vst1q_s32(final_output + 44, right[5]); + vst1q_s32(final_output + 48, left[6]); + vst1q_s32(final_output + 52, right[6]); + vst1q_s32(final_output + 56, left[7]); + vst1q_s32(final_output + 60, right[7]); + } +} + +#endif // CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vpx_dsp/arm/fdct8x8_neon.h b/libs/libvpx/vpx_dsp/arm/fdct8x8_neon.h new file mode 100644 index 0000000000..cc65157430 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/fdct8x8_neon.h @@ -0,0 +1,307 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VPX_DSP_ARM_FDCT8X8_NEON_H_ +#define VPX_VPX_DSP_ARM_FDCT8X8_NEON_H_ + +#include + +static INLINE void vpx_fdct8x8_pass1_notranspose_neon(int16x8_t *in, + int16x8_t *out) { + int16x8_t s[8], x[4], t[2]; + + s[0] = vaddq_s16(in[0], in[7]); + s[1] = vaddq_s16(in[1], in[6]); + s[2] = vaddq_s16(in[2], in[5]); + s[3] = vaddq_s16(in[3], in[4]); + s[4] = vsubq_s16(in[3], in[4]); + s[5] = vsubq_s16(in[2], in[5]); + s[6] = vsubq_s16(in[1], in[6]); + s[7] = vsubq_s16(in[0], in[7]); + // fdct4(step, step); + x[0] = vaddq_s16(s[0], s[3]); + x[1] = vaddq_s16(s[1], s[2]); + x[2] = vsubq_s16(s[1], s[2]); + x[3] = vsubq_s16(s[0], s[3]); + + // fdct4(step, step); + // out[0] = (tran_low_t)fdct_round_shift((x0 + x1) * cospi_16_64) + // out[4] = (tran_low_t)fdct_round_shift((x0 - x1) * cospi_16_64) + butterfly_one_coeff_s16_fast(x[0], x[1], cospi_16_64, &out[0], &out[4]); + // out[2] = (tran_low_t)fdct_round_shift(x2 * cospi_24_64 + x3 * cospi_8_64) + // out[6] = (tran_low_t)fdct_round_shift(-x2 * cospi_8_64 + x3 * cospi_24_64) + butterfly_two_coeff(x[3], x[2], cospi_8_64, cospi_24_64, &out[2], &out[6]); + + // Stage 2 + // t0 = (s6 - s5) * cospi_16_64; + // t1 = (s6 + s5) * cospi_16_64; + butterfly_one_coeff_s16_fast(s[6], s[5], cospi_16_64, &t[1], &t[0]); + + // Stage 3 + x[0] = vaddq_s16(s[4], t[0]); + x[1] = vsubq_s16(s[4], t[0]); + x[2] = vsubq_s16(s[7], t[1]); + x[3] = vaddq_s16(s[7], t[1]); + + // Stage 4 + // out[1] = (tran_low_t)fdct_round_shift(x0 * cospi_28_64 + x3 * cospi_4_64) + // out[7] = (tran_low_t)fdct_round_shift(x3 * cospi_28_64 + x0 * -cospi_4_64) + butterfly_two_coeff(x[3], x[0], cospi_4_64, cospi_28_64, &out[1], &out[7]); + + // out[5] = (tran_low_t)fdct_round_shift(x1 * cospi_12_64 + x2 * cospi_20_64) + // out[3] = (tran_low_t)fdct_round_shift(x2 * cospi_12_64 + x1 * -cospi_20_64) + butterfly_two_coeff(x[2], x[1], cospi_20_64, cospi_12_64, &out[5], &out[3]); +} + +static INLINE void vpx_fdct8x8_pass2_notranspose_neon(int16x8_t *in, + int16x8_t *out) { + int16x8_t s[8], x[4], t[2]; + + s[0] = vaddq_s16(in[0], in[7]); + s[1] = vaddq_s16(in[1], in[6]); + s[2] = vaddq_s16(in[2], in[5]); + s[3] = vaddq_s16(in[3], in[4]); + s[4] = vsubq_s16(in[3], in[4]); + s[5] = vsubq_s16(in[2], in[5]); + s[6] = vsubq_s16(in[1], in[6]); + s[7] = vsubq_s16(in[0], in[7]); + // fdct4(step, step); + x[0] = vaddq_s16(s[0], s[3]); + x[1] = vaddq_s16(s[1], s[2]); + x[2] = vsubq_s16(s[1], s[2]); + x[3] = vsubq_s16(s[0], s[3]); + + // fdct4(step, step); + // out[0] = (tran_low_t)fdct_round_shift((x0 + x1) * cospi_16_64) + // out[4] = (tran_low_t)fdct_round_shift((x0 - x1) * cospi_16_64) + butterfly_one_coeff_s16_s32_fast_narrow(x[0], x[1], cospi_16_64, &out[0], + &out[4]); + // out[2] = (tran_low_t)fdct_round_shift(x2 * cospi_24_64 + x3 * cospi_8_64) + // out[6] = (tran_low_t)fdct_round_shift(-x2 * cospi_8_64 + x3 * cospi_24_64) + butterfly_two_coeff(x[3], x[2], cospi_8_64, cospi_24_64, &out[2], &out[6]); + + // Stage 2 + // t0 = (s6 - s5) * cospi_16_64; + // t1 = (s6 + s5) * cospi_16_64; + butterfly_one_coeff_s16_s32_fast_narrow(s[6], s[5], cospi_16_64, &t[1], + &t[0]); + + // Stage 3 + x[0] = vaddq_s16(s[4], t[0]); + x[1] = vsubq_s16(s[4], t[0]); + x[2] = vsubq_s16(s[7], t[1]); + x[3] = vaddq_s16(s[7], t[1]); + + // Stage 4 + // out[1] = (tran_low_t)fdct_round_shift(x0 * cospi_28_64 + x3 * cospi_4_64) + // out[7] = (tran_low_t)fdct_round_shift(x3 * cospi_28_64 + x0 * -cospi_4_64) + butterfly_two_coeff(x[3], x[0], cospi_4_64, cospi_28_64, &out[1], &out[7]); + + // out[5] = (tran_low_t)fdct_round_shift(x1 * cospi_12_64 + x2 * cospi_20_64) + // out[3] = (tran_low_t)fdct_round_shift(x2 * cospi_12_64 + x1 * -cospi_20_64) + butterfly_two_coeff(x[2], x[1], cospi_20_64, cospi_12_64, &out[5], &out[3]); +} + +static INLINE void vpx_fdct8x8_pass1_neon(int16x8_t *in) { + int16x8_t out[8]; + vpx_fdct8x8_pass1_notranspose_neon(in, out); + // transpose 8x8 + transpose_s16_8x8(&out[0], &out[1], &out[2], &out[3], &out[4], &out[5], + &out[6], &out[7]); + in[0] = out[0]; + in[1] = out[1]; + in[2] = out[2]; + in[3] = out[3]; + in[4] = out[4]; + in[5] = out[5]; + in[6] = out[6]; + in[7] = out[7]; +} + +static INLINE void vpx_fdct8x8_pass2_neon(int16x8_t *in) { + int16x8_t out[8]; + vpx_fdct8x8_pass2_notranspose_neon(in, out); + // transpose 8x8 + transpose_s16_8x8(&out[0], &out[1], &out[2], &out[3], &out[4], &out[5], + &out[6], &out[7]); + in[0] = out[0]; + in[1] = out[1]; + in[2] = out[2]; + in[3] = out[3]; + in[4] = out[4]; + in[5] = out[5]; + in[6] = out[6]; + in[7] = out[7]; +} + +#if CONFIG_VP9_HIGHBITDEPTH +static INLINE void vpx_highbd_fdct8x8_pass1_notranspose_neon(int32x4_t *left, + int32x4_t *right) { + int32x4_t sl[8], sr[8], xl[4], xr[4], tl[4], tr[4]; + + sl[0] = vaddq_s32(left[0], left[7]); + sl[1] = vaddq_s32(left[1], left[6]); + sl[2] = vaddq_s32(left[2], left[5]); + sl[3] = vaddq_s32(left[3], left[4]); + sl[4] = vsubq_s32(left[3], left[4]); + sl[5] = vsubq_s32(left[2], left[5]); + sl[6] = vsubq_s32(left[1], left[6]); + sl[7] = vsubq_s32(left[0], left[7]); + sr[0] = vaddq_s32(right[0], right[7]); + sr[1] = vaddq_s32(right[1], right[6]); + sr[2] = vaddq_s32(right[2], right[5]); + sr[3] = vaddq_s32(right[3], right[4]); + sr[4] = vsubq_s32(right[3], right[4]); + sr[5] = vsubq_s32(right[2], right[5]); + sr[6] = vsubq_s32(right[1], right[6]); + sr[7] = vsubq_s32(right[0], right[7]); + + // fdct4(step, step); + // x0 = s0 + s3; + xl[0] = vaddq_s32(sl[0], sl[3]); + xr[0] = vaddq_s32(sr[0], sr[3]); + // x1 = s1 + s2; + xl[1] = vaddq_s32(sl[1], sl[2]); + xr[1] = vaddq_s32(sr[1], sr[2]); + // x2 = s1 - s2; + xl[2] = vsubq_s32(sl[1], sl[2]); + xr[2] = vsubq_s32(sr[1], sr[2]); + // x3 = s0 - s3; + xl[3] = vsubq_s32(sl[0], sl[3]); + xr[3] = vsubq_s32(sr[0], sr[3]); + + // fdct4(step, step); + // out[0] = (tran_low_t)fdct_round_shift((x0 + x1) * cospi_16_64) + // out[4] = (tran_low_t)fdct_round_shift((x0 - x1) * cospi_16_64) + butterfly_one_coeff_s32_fast(xl[0], xr[0], xl[1], xr[1], cospi_16_64, + &left[0], &right[0], &left[4], &right[4]); + // out[2] = (tran_low_t)fdct_round_shift(x2 * cospi_24_64 + x3 * cospi_8_64) + // out[6] = (tran_low_t)fdct_round_shift(-x2 * cospi_8_64 + x3 * cospi_24_64) + butterfly_two_coeff_s32(xl[3], xr[3], xl[2], xr[2], cospi_8_64, cospi_24_64, + &left[2], &right[2], &left[6], &right[6]); + + // Stage 2 + // t0 = (s6 - s5) * cospi_16_64; + // t1 = (s6 + s5) * cospi_16_64; + butterfly_one_coeff_s32_fast(sl[6], sr[6], sl[5], sr[5], cospi_16_64, &tl[1], + &tr[1], &tl[0], &tr[0]); + + // Stage 3 + xl[0] = vaddq_s32(sl[4], tl[0]); + xr[0] = vaddq_s32(sr[4], tr[0]); + xl[1] = vsubq_s32(sl[4], tl[0]); + xr[1] = vsubq_s32(sr[4], tr[0]); + xl[2] = vsubq_s32(sl[7], tl[1]); + xr[2] = vsubq_s32(sr[7], tr[1]); + xl[3] = vaddq_s32(sl[7], tl[1]); + xr[3] = vaddq_s32(sr[7], tr[1]); + + // Stage 4 + // out[1] = (tran_low_t)fdct_round_shift(x0 * cospi_28_64 + x3 * cospi_4_64) + // out[7] = (tran_low_t)fdct_round_shift(x3 * cospi_28_64 + x0 * -cospi_4_64) + butterfly_two_coeff_s32(xl[3], xr[3], xl[0], xr[0], cospi_4_64, cospi_28_64, + &left[1], &right[1], &left[7], &right[7]); + + // out[5] = (tran_low_t)fdct_round_shift(x1 * cospi_12_64 + x2 * cospi_20_64) + // out[3] = (tran_low_t)fdct_round_shift(x2 * cospi_12_64 + x1 * -cospi_20_64) + butterfly_two_coeff_s32(xl[2], xr[2], xl[1], xr[1], cospi_20_64, cospi_12_64, + &left[5], &right[5], &left[3], &right[3]); +} + +static INLINE void vpx_highbd_fdct8x8_pass2_notranspose_neon(int32x4_t *left, + int32x4_t *right) { + int32x4_t sl[8], sr[8], xl[4], xr[4], tl[4], tr[4]; + + sl[0] = vaddq_s32(left[0], left[7]); + sl[1] = vaddq_s32(left[1], left[6]); + sl[2] = vaddq_s32(left[2], left[5]); + sl[3] = vaddq_s32(left[3], left[4]); + sl[4] = vsubq_s32(left[3], left[4]); + sl[5] = vsubq_s32(left[2], left[5]); + sl[6] = vsubq_s32(left[1], left[6]); + sl[7] = vsubq_s32(left[0], left[7]); + sr[0] = vaddq_s32(right[0], right[7]); + sr[1] = vaddq_s32(right[1], right[6]); + sr[2] = vaddq_s32(right[2], right[5]); + sr[3] = vaddq_s32(right[3], right[4]); + sr[4] = vsubq_s32(right[3], right[4]); + sr[5] = vsubq_s32(right[2], right[5]); + sr[6] = vsubq_s32(right[1], right[6]); + sr[7] = vsubq_s32(right[0], right[7]); + + // fdct4(step, step); + // x0 = s0 + s3; + xl[0] = vaddq_s32(sl[0], sl[3]); + xr[0] = vaddq_s32(sr[0], sr[3]); + // x1 = s1 + s2; + xl[1] = vaddq_s32(sl[1], sl[2]); + xr[1] = vaddq_s32(sr[1], sr[2]); + // x2 = s1 - s2; + xl[2] = vsubq_s32(sl[1], sl[2]); + xr[2] = vsubq_s32(sr[1], sr[2]); + // x3 = s0 - s3; + xl[3] = vsubq_s32(sl[0], sl[3]); + xr[3] = vsubq_s32(sr[0], sr[3]); + + // fdct4(step, step); + // out[0] = (tran_low_t)fdct_round_shift((x0 + x1) * cospi_16_64) + // out[4] = (tran_low_t)fdct_round_shift((x0 - x1) * cospi_16_64) + butterfly_one_coeff_s32_fast(xl[0], xr[0], xl[1], xr[1], cospi_16_64, + &left[0], &right[0], &left[4], &right[4]); + // out[2] = (tran_low_t)fdct_round_shift(x2 * cospi_24_64 + x3 * cospi_8_64) + // out[6] = (tran_low_t)fdct_round_shift(-x2 * cospi_8_64 + x3 * cospi_24_64) + butterfly_two_coeff_s32_s64_narrow(xl[3], xr[3], xl[2], xr[2], cospi_8_64, + cospi_24_64, &left[2], &right[2], &left[6], + &right[6]); + + // Stage 2 + // t0 = (s6 - s5) * cospi_16_64; + // t1 = (s6 + s5) * cospi_16_64; + butterfly_one_coeff_s32_fast(sl[6], sr[6], sl[5], sr[5], cospi_16_64, &tl[1], + &tr[1], &tl[0], &tr[0]); + + // Stage 3 + xl[0] = vaddq_s32(sl[4], tl[0]); + xr[0] = vaddq_s32(sr[4], tr[0]); + xl[1] = vsubq_s32(sl[4], tl[0]); + xr[1] = vsubq_s32(sr[4], tr[0]); + xl[2] = vsubq_s32(sl[7], tl[1]); + xr[2] = vsubq_s32(sr[7], tr[1]); + xl[3] = vaddq_s32(sl[7], tl[1]); + xr[3] = vaddq_s32(sr[7], tr[1]); + + // Stage 4 + // out[1] = (tran_low_t)fdct_round_shift(x0 * cospi_28_64 + x3 * cospi_4_64) + // out[7] = (tran_low_t)fdct_round_shift(x3 * cospi_28_64 + x0 * -cospi_4_64) + butterfly_two_coeff_s32_s64_narrow(xl[3], xr[3], xl[0], xr[0], cospi_4_64, + cospi_28_64, &left[1], &right[1], &left[7], + &right[7]); + + // out[5] = (tran_low_t)fdct_round_shift(x1 * cospi_12_64 + x2 * cospi_20_64) + // out[3] = (tran_low_t)fdct_round_shift(x2 * cospi_12_64 + x1 * -cospi_20_64) + butterfly_two_coeff_s32_s64_narrow(xl[2], xr[2], xl[1], xr[1], cospi_20_64, + cospi_12_64, &left[5], &right[5], &left[3], + &right[3]); +} + +static INLINE void vpx_highbd_fdct8x8_pass1_neon(int32x4_t *left, + int32x4_t *right) { + vpx_highbd_fdct8x8_pass1_notranspose_neon(left, right); + transpose_s32_8x8_2(left, right, left, right); +} + +static INLINE void vpx_highbd_fdct8x8_pass2_neon(int32x4_t *left, + int32x4_t *right) { + vpx_highbd_fdct8x8_pass2_notranspose_neon(left, right); + transpose_s32_8x8_2(left, right, left, right); +} + +#endif // CONFIG_VP9_HIGHBITDEPTH +#endif // VPX_VPX_DSP_ARM_FDCT8X8_NEON_H_ diff --git a/libs/libvpx/vpx_dsp/arm/fdct_neon.h b/libs/libvpx/vpx_dsp/arm/fdct_neon.h index 28d7d86bf8..16f5c5fc0e 100644 --- a/libs/libvpx/vpx_dsp/arm/fdct_neon.h +++ b/libs/libvpx/vpx_dsp/arm/fdct_neon.h @@ -13,201 +13,530 @@ #include -static INLINE void vpx_fdct4x4_pass1_neon(int16x4_t *in) { - const int16x8_t input_01 = vcombine_s16(in[0], in[1]); - const int16x8_t input_32 = vcombine_s16(in[3], in[2]); - - // in_0 +/- in_3, in_1 +/- in_2 - const int16x8_t s_01 = vaddq_s16(input_01, input_32); - const int16x8_t s_32 = vsubq_s16(input_01, input_32); - - // step_0 +/- step_1, step_2 +/- step_3 - const int16x4_t s_0 = vget_low_s16(s_01); - const int16x4_t s_1 = vget_high_s16(s_01); - const int16x4_t s_2 = vget_high_s16(s_32); - const int16x4_t s_3 = vget_low_s16(s_32); - - // (s_0 +/- s_1) * cospi_16_64 - // Must expand all elements to s32. See 'needs32' comment in fwd_txfm.c. - const int32x4_t s_0_p_s_1 = vaddl_s16(s_0, s_1); - const int32x4_t s_0_m_s_1 = vsubl_s16(s_0, s_1); - const int32x4_t temp1 = vmulq_n_s32(s_0_p_s_1, cospi_16_64); - const int32x4_t temp2 = vmulq_n_s32(s_0_m_s_1, cospi_16_64); - - // fdct_round_shift - int16x4_t out_0 = vrshrn_n_s32(temp1, DCT_CONST_BITS); - int16x4_t out_2 = vrshrn_n_s32(temp2, DCT_CONST_BITS); - - // s_3 * cospi_8_64 + s_2 * cospi_24_64 - // s_3 * cospi_24_64 - s_2 * cospi_8_64 - const int32x4_t s_3_cospi_8_64 = vmull_n_s16(s_3, cospi_8_64); - const int32x4_t s_3_cospi_24_64 = vmull_n_s16(s_3, cospi_24_64); - - const int32x4_t temp3 = vmlal_n_s16(s_3_cospi_8_64, s_2, cospi_24_64); - const int32x4_t temp4 = vmlsl_n_s16(s_3_cospi_24_64, s_2, cospi_8_64); - - // fdct_round_shift - int16x4_t out_1 = vrshrn_n_s32(temp3, DCT_CONST_BITS); - int16x4_t out_3 = vrshrn_n_s32(temp4, DCT_CONST_BITS); - - transpose_s16_4x4d(&out_0, &out_1, &out_2, &out_3); - - in[0] = out_0; - in[1] = out_1; - in[2] = out_2; - in[3] = out_3; +// fdct_round_shift((a +/- b) * c) +// Variant that performs fast vqrdmulh_s16 operation on half vector +// can be slightly less accurate, adequate for pass1 +static INLINE void butterfly_one_coeff_s16_fast_half(const int16x4_t a, + const int16x4_t b, + const tran_coef_t constant, + int16x4_t *add, + int16x4_t *sub) { + int16x4_t c = vdup_n_s16(2 * constant); + *add = vqrdmulh_s16(vadd_s16(a, b), c); + *sub = vqrdmulh_s16(vsub_s16(a, b), c); } -static INLINE void vpx_fdct8x8_pass1_notranspose_neon(int16x8_t *in, - int16x8_t *out) { - const int16x8_t v_s0 = vaddq_s16(in[0], in[7]); - const int16x8_t v_s1 = vaddq_s16(in[1], in[6]); - const int16x8_t v_s2 = vaddq_s16(in[2], in[5]); - const int16x8_t v_s3 = vaddq_s16(in[3], in[4]); - const int16x8_t v_s4 = vsubq_s16(in[3], in[4]); - const int16x8_t v_s5 = vsubq_s16(in[2], in[5]); - const int16x8_t v_s6 = vsubq_s16(in[1], in[6]); - const int16x8_t v_s7 = vsubq_s16(in[0], in[7]); - // fdct4(step, step); - int16x8_t v_x0 = vaddq_s16(v_s0, v_s3); - int16x8_t v_x1 = vaddq_s16(v_s1, v_s2); - int16x8_t v_x2 = vsubq_s16(v_s1, v_s2); - int16x8_t v_x3 = vsubq_s16(v_s0, v_s3); - // fdct4(step, step); - int32x4_t v_t0_lo = vaddl_s16(vget_low_s16(v_x0), vget_low_s16(v_x1)); - int32x4_t v_t0_hi = vaddl_s16(vget_high_s16(v_x0), vget_high_s16(v_x1)); - int32x4_t v_t1_lo = vsubl_s16(vget_low_s16(v_x0), vget_low_s16(v_x1)); - int32x4_t v_t1_hi = vsubl_s16(vget_high_s16(v_x0), vget_high_s16(v_x1)); - int32x4_t v_t2_lo = vmull_n_s16(vget_low_s16(v_x2), cospi_24_64); - int32x4_t v_t2_hi = vmull_n_s16(vget_high_s16(v_x2), cospi_24_64); - int32x4_t v_t3_lo = vmull_n_s16(vget_low_s16(v_x3), cospi_24_64); - int32x4_t v_t3_hi = vmull_n_s16(vget_high_s16(v_x3), cospi_24_64); - v_t2_lo = vmlal_n_s16(v_t2_lo, vget_low_s16(v_x3), cospi_8_64); - v_t2_hi = vmlal_n_s16(v_t2_hi, vget_high_s16(v_x3), cospi_8_64); - v_t3_lo = vmlsl_n_s16(v_t3_lo, vget_low_s16(v_x2), cospi_8_64); - v_t3_hi = vmlsl_n_s16(v_t3_hi, vget_high_s16(v_x2), cospi_8_64); - v_t0_lo = vmulq_n_s32(v_t0_lo, cospi_16_64); - v_t0_hi = vmulq_n_s32(v_t0_hi, cospi_16_64); - v_t1_lo = vmulq_n_s32(v_t1_lo, cospi_16_64); - v_t1_hi = vmulq_n_s32(v_t1_hi, cospi_16_64); - { - const int16x4_t a = vrshrn_n_s32(v_t0_lo, DCT_CONST_BITS); - const int16x4_t b = vrshrn_n_s32(v_t0_hi, DCT_CONST_BITS); - const int16x4_t c = vrshrn_n_s32(v_t1_lo, DCT_CONST_BITS); - const int16x4_t d = vrshrn_n_s32(v_t1_hi, DCT_CONST_BITS); - const int16x4_t e = vrshrn_n_s32(v_t2_lo, DCT_CONST_BITS); - const int16x4_t f = vrshrn_n_s32(v_t2_hi, DCT_CONST_BITS); - const int16x4_t g = vrshrn_n_s32(v_t3_lo, DCT_CONST_BITS); - const int16x4_t h = vrshrn_n_s32(v_t3_hi, DCT_CONST_BITS); - out[0] = vcombine_s16(a, c); // 00 01 02 03 40 41 42 43 - out[2] = vcombine_s16(e, g); // 20 21 22 23 60 61 62 63 - out[4] = vcombine_s16(b, d); // 04 05 06 07 44 45 46 47 - out[6] = vcombine_s16(f, h); // 24 25 26 27 64 65 66 67 - } - // Stage 2 - v_x0 = vsubq_s16(v_s6, v_s5); - v_x1 = vaddq_s16(v_s6, v_s5); - v_t0_lo = vmull_n_s16(vget_low_s16(v_x0), cospi_16_64); - v_t0_hi = vmull_n_s16(vget_high_s16(v_x0), cospi_16_64); - v_t1_lo = vmull_n_s16(vget_low_s16(v_x1), cospi_16_64); - v_t1_hi = vmull_n_s16(vget_high_s16(v_x1), cospi_16_64); - { - const int16x4_t a = vrshrn_n_s32(v_t0_lo, DCT_CONST_BITS); - const int16x4_t b = vrshrn_n_s32(v_t0_hi, DCT_CONST_BITS); - const int16x4_t c = vrshrn_n_s32(v_t1_lo, DCT_CONST_BITS); - const int16x4_t d = vrshrn_n_s32(v_t1_hi, DCT_CONST_BITS); - const int16x8_t ab = vcombine_s16(a, b); - const int16x8_t cd = vcombine_s16(c, d); - // Stage 3 - v_x0 = vaddq_s16(v_s4, ab); - v_x1 = vsubq_s16(v_s4, ab); - v_x2 = vsubq_s16(v_s7, cd); - v_x3 = vaddq_s16(v_s7, cd); - } - // Stage 4 - v_t0_lo = vmull_n_s16(vget_low_s16(v_x3), cospi_4_64); - v_t0_hi = vmull_n_s16(vget_high_s16(v_x3), cospi_4_64); - v_t0_lo = vmlal_n_s16(v_t0_lo, vget_low_s16(v_x0), cospi_28_64); - v_t0_hi = vmlal_n_s16(v_t0_hi, vget_high_s16(v_x0), cospi_28_64); - v_t1_lo = vmull_n_s16(vget_low_s16(v_x1), cospi_12_64); - v_t1_hi = vmull_n_s16(vget_high_s16(v_x1), cospi_12_64); - v_t1_lo = vmlal_n_s16(v_t1_lo, vget_low_s16(v_x2), cospi_20_64); - v_t1_hi = vmlal_n_s16(v_t1_hi, vget_high_s16(v_x2), cospi_20_64); - v_t2_lo = vmull_n_s16(vget_low_s16(v_x2), cospi_12_64); - v_t2_hi = vmull_n_s16(vget_high_s16(v_x2), cospi_12_64); - v_t2_lo = vmlsl_n_s16(v_t2_lo, vget_low_s16(v_x1), cospi_20_64); - v_t2_hi = vmlsl_n_s16(v_t2_hi, vget_high_s16(v_x1), cospi_20_64); - v_t3_lo = vmull_n_s16(vget_low_s16(v_x3), cospi_28_64); - v_t3_hi = vmull_n_s16(vget_high_s16(v_x3), cospi_28_64); - v_t3_lo = vmlsl_n_s16(v_t3_lo, vget_low_s16(v_x0), cospi_4_64); - v_t3_hi = vmlsl_n_s16(v_t3_hi, vget_high_s16(v_x0), cospi_4_64); - { - const int16x4_t a = vrshrn_n_s32(v_t0_lo, DCT_CONST_BITS); - const int16x4_t b = vrshrn_n_s32(v_t0_hi, DCT_CONST_BITS); - const int16x4_t c = vrshrn_n_s32(v_t1_lo, DCT_CONST_BITS); - const int16x4_t d = vrshrn_n_s32(v_t1_hi, DCT_CONST_BITS); - const int16x4_t e = vrshrn_n_s32(v_t2_lo, DCT_CONST_BITS); - const int16x4_t f = vrshrn_n_s32(v_t2_hi, DCT_CONST_BITS); - const int16x4_t g = vrshrn_n_s32(v_t3_lo, DCT_CONST_BITS); - const int16x4_t h = vrshrn_n_s32(v_t3_hi, DCT_CONST_BITS); - out[1] = vcombine_s16(a, c); // 10 11 12 13 50 51 52 53 - out[3] = vcombine_s16(e, g); // 30 31 32 33 70 71 72 73 - out[5] = vcombine_s16(b, d); // 14 15 16 17 54 55 56 57 - out[7] = vcombine_s16(f, h); // 34 35 36 37 74 75 76 77 - } +// fdct_round_shift((a +/- b) * c) +// Variant that performs fast vqrdmulh_s16 operation on full vector +// can be slightly less accurate, adequate for pass1 +static INLINE void butterfly_one_coeff_s16_fast(const int16x8_t a, + const int16x8_t b, + const tran_coef_t constant, + int16x8_t *add, + int16x8_t *sub) { + int16x8_t c = vdupq_n_s16(2 * constant); + *add = vqrdmulhq_s16(vaddq_s16(a, b), c); + *sub = vqrdmulhq_s16(vsubq_s16(a, b), c); } -static INLINE void vpx_fdct8x8_pass1_neon(int16x8_t *in) { - int16x8_t out[8]; - vpx_fdct8x8_pass1_notranspose_neon(in, out); - // transpose 8x8 - // Can't use transpose_s16_8x8() because the values are arranged in two 4x8 - // columns. - { - // 00 01 02 03 40 41 42 43 - // 10 11 12 13 50 51 52 53 - // 20 21 22 23 60 61 62 63 - // 30 31 32 33 70 71 72 73 - // 04 05 06 07 44 45 46 47 - // 14 15 16 17 54 55 56 57 - // 24 25 26 27 64 65 66 67 - // 34 35 36 37 74 75 76 77 - const int32x4x2_t r02_s32 = - vtrnq_s32(vreinterpretq_s32_s16(out[0]), vreinterpretq_s32_s16(out[2])); - const int32x4x2_t r13_s32 = - vtrnq_s32(vreinterpretq_s32_s16(out[1]), vreinterpretq_s32_s16(out[3])); - const int32x4x2_t r46_s32 = - vtrnq_s32(vreinterpretq_s32_s16(out[4]), vreinterpretq_s32_s16(out[6])); - const int32x4x2_t r57_s32 = - vtrnq_s32(vreinterpretq_s32_s16(out[5]), vreinterpretq_s32_s16(out[7])); - const int16x8x2_t r01_s16 = - vtrnq_s16(vreinterpretq_s16_s32(r02_s32.val[0]), - vreinterpretq_s16_s32(r13_s32.val[0])); - const int16x8x2_t r23_s16 = - vtrnq_s16(vreinterpretq_s16_s32(r02_s32.val[1]), - vreinterpretq_s16_s32(r13_s32.val[1])); - const int16x8x2_t r45_s16 = - vtrnq_s16(vreinterpretq_s16_s32(r46_s32.val[0]), - vreinterpretq_s16_s32(r57_s32.val[0])); - const int16x8x2_t r67_s16 = - vtrnq_s16(vreinterpretq_s16_s32(r46_s32.val[1]), - vreinterpretq_s16_s32(r57_s32.val[1])); - in[0] = r01_s16.val[0]; - in[1] = r01_s16.val[1]; - in[2] = r23_s16.val[0]; - in[3] = r23_s16.val[1]; - in[4] = r45_s16.val[0]; - in[5] = r45_s16.val[1]; - in[6] = r67_s16.val[0]; - in[7] = r67_s16.val[1]; - // 00 10 20 30 40 50 60 70 - // 01 11 21 31 41 51 61 71 - // 02 12 22 32 42 52 62 72 - // 03 13 23 33 43 53 63 73 - // 04 14 24 34 44 54 64 74 - // 05 15 25 35 45 55 65 75 - // 06 16 26 36 46 56 66 76 - // 07 17 27 37 47 57 67 77 - } +// fdct_round_shift((a +/- b) * c) +// Variant that performs fast vqrdmulhq_s32 operation on full vector +// more accurate does 32-bit processing, takes 16-bit input values, +// returns full 32-bit values, high/low +static INLINE void butterfly_one_coeff_s16_s32_fast( + const int16x8_t a, const int16x8_t b, const tran_coef_t constant, + int32x4_t *add_lo, int32x4_t *add_hi, int32x4_t *sub_lo, + int32x4_t *sub_hi) { + int32x4_t c = vdupq_n_s32(constant << 17); + const int16x4_t a_lo = vget_low_s16(a); + const int16x4_t a_hi = vget_high_s16(a); + const int16x4_t b_lo = vget_low_s16(b); + const int16x4_t b_hi = vget_high_s16(b); + *add_lo = vqrdmulhq_s32(vaddl_s16(a_lo, b_lo), c); + *add_hi = vqrdmulhq_s32(vaddl_s16(a_hi, b_hi), c); + *sub_lo = vqrdmulhq_s32(vsubl_s16(a_lo, b_lo), c); + *sub_hi = vqrdmulhq_s32(vsubl_s16(a_hi, b_hi), c); } + +// fdct_round_shift((a +/- b) * c) +// Variant that performs fast vqrdmulhq_s32 operation on full vector +// more accurate does 32-bit processing, takes 16-bit input values, +// returns full 32-bit values, high/low +static INLINE void butterfly_one_coeff_s16_s32_fast_narrow( + const int16x8_t a, const int16x8_t b, const tran_coef_t constant, + int16x8_t *add, int16x8_t *sub) { + int32x4_t add_lo, add_hi, sub_lo, sub_hi; + butterfly_one_coeff_s16_s32_fast(a, b, constant, &add_lo, &add_hi, &sub_lo, + &sub_hi); + *add = vcombine_s16(vmovn_s32(add_lo), vmovn_s32(add_hi)); + *sub = vcombine_s16(vmovn_s32(sub_lo), vmovn_s32(sub_hi)); +} + +// fdct_round_shift((a +/- b) * c) +// Variant that performs fast vqrdmulhq_s32 operation on full vector +// more accurate does 32-bit processing, takes 16-bit input values, +// returns full 32-bit values, high/low +static INLINE void butterfly_one_coeff_s16_s32_fast_half( + const int16x4_t a, const int16x4_t b, const tran_coef_t constant, + int32x4_t *add, int32x4_t *sub) { + int32x4_t c = vdupq_n_s32(constant << 17); + *add = vqrdmulhq_s32(vaddl_s16(a, b), c); + *sub = vqrdmulhq_s32(vsubl_s16(a, b), c); +} + +// fdct_round_shift((a +/- b) * c) +// Variant that performs fast vqrdmulhq_s32 operation on half vector +// more accurate does 32-bit processing, takes 16-bit input values, +// returns narrowed down 16-bit values +static INLINE void butterfly_one_coeff_s16_s32_fast_narrow_half( + const int16x4_t a, const int16x4_t b, const tran_coef_t constant, + int16x4_t *add, int16x4_t *sub) { + int32x4_t add32, sub32; + butterfly_one_coeff_s16_s32_fast_half(a, b, constant, &add32, &sub32); + *add = vmovn_s32(add32); + *sub = vmovn_s32(sub32); +} + +// fdct_round_shift((a +/- b) * c) +// Original Variant that performs normal implementation on full vector +// fully accurate does 32-bit processing, takes 16-bit values +static INLINE void butterfly_one_coeff_s16_s32( + const int16x8_t a, const int16x8_t b, const tran_coef_t constant, + int32x4_t *add_lo, int32x4_t *add_hi, int32x4_t *sub_lo, + int32x4_t *sub_hi) { + const int32x4_t a0 = vmull_n_s16(vget_low_s16(a), constant); + const int32x4_t a1 = vmull_n_s16(vget_high_s16(a), constant); + const int32x4_t sum0 = vmlal_n_s16(a0, vget_low_s16(b), constant); + const int32x4_t sum1 = vmlal_n_s16(a1, vget_high_s16(b), constant); + const int32x4_t diff0 = vmlsl_n_s16(a0, vget_low_s16(b), constant); + const int32x4_t diff1 = vmlsl_n_s16(a1, vget_high_s16(b), constant); + *add_lo = vrshrq_n_s32(sum0, DCT_CONST_BITS); + *add_hi = vrshrq_n_s32(sum1, DCT_CONST_BITS); + *sub_lo = vrshrq_n_s32(diff0, DCT_CONST_BITS); + *sub_hi = vrshrq_n_s32(diff1, DCT_CONST_BITS); +} + +// fdct_round_shift((a +/- b) * c) +// Original Variant that performs normal implementation on full vector +// fully accurate does 32-bit processing, takes 16-bit values +// returns narrowed down 16-bit values +static INLINE void butterfly_one_coeff_s16_s32_narrow( + const int16x8_t a, const int16x8_t b, const tran_coef_t constant, + int16x8_t *add, int16x8_t *sub) { + int32x4_t add32_lo, add32_hi, sub32_lo, sub32_hi; + butterfly_one_coeff_s16_s32(a, b, constant, &add32_lo, &add32_hi, &sub32_lo, + &sub32_hi); + *add = vcombine_s16(vmovn_s32(add32_lo), vmovn_s32(add32_hi)); + *sub = vcombine_s16(vmovn_s32(sub32_lo), vmovn_s32(sub32_hi)); +} + +// fdct_round_shift((a +/- b) * c) +// Variant that performs fast vqrdmulhq_s32 operation on full vector +// more accurate does 32-bit processing, takes and returns 32-bit values, +// high/low +static INLINE void butterfly_one_coeff_s32_noround( + const int32x4_t a_lo, const int32x4_t a_hi, const int32x4_t b_lo, + const int32x4_t b_hi, const tran_coef_t constant, int32x4_t *add_lo, + int32x4_t *add_hi, int32x4_t *sub_lo, int32x4_t *sub_hi) { + const int32x4_t a1 = vmulq_n_s32(a_lo, constant); + const int32x4_t a2 = vmulq_n_s32(a_hi, constant); + const int32x4_t a3 = vmulq_n_s32(a_lo, constant); + const int32x4_t a4 = vmulq_n_s32(a_hi, constant); + *add_lo = vmlaq_n_s32(a1, b_lo, constant); + *add_hi = vmlaq_n_s32(a2, b_hi, constant); + *sub_lo = vmlsq_n_s32(a3, b_lo, constant); + *sub_hi = vmlsq_n_s32(a4, b_hi, constant); +} + +// fdct_round_shift((a +/- b) * c) +// Variant that performs fast vqrdmulhq_s32 operation on full vector +// more accurate does 32-bit processing, takes and returns 32-bit values, +// high/low +static INLINE void butterfly_one_coeff_s32_fast_half(const int32x4_t a, + const int32x4_t b, + const tran_coef_t constant, + int32x4_t *add, + int32x4_t *sub) { + const int32x4_t c = vdupq_n_s32(constant << 17); + *add = vqrdmulhq_s32(vaddq_s32(a, b), c); + *sub = vqrdmulhq_s32(vsubq_s32(a, b), c); +} + +// fdct_round_shift((a +/- b) * c) +// Variant that performs fast vqrdmulhq_s32 operation on full vector +// more accurate does 32-bit processing, takes and returns 32-bit values, +// high/low +static INLINE void butterfly_one_coeff_s32_fast( + const int32x4_t a_lo, const int32x4_t a_hi, const int32x4_t b_lo, + const int32x4_t b_hi, const tran_coef_t constant, int32x4_t *add_lo, + int32x4_t *add_hi, int32x4_t *sub_lo, int32x4_t *sub_hi) { + const int32x4_t c = vdupq_n_s32(constant << 17); + *add_lo = vqrdmulhq_s32(vaddq_s32(a_lo, b_lo), c); + *add_hi = vqrdmulhq_s32(vaddq_s32(a_hi, b_hi), c); + *sub_lo = vqrdmulhq_s32(vsubq_s32(a_lo, b_lo), c); + *sub_hi = vqrdmulhq_s32(vsubq_s32(a_hi, b_hi), c); +} + +// fdct_round_shift((a +/- b) * c) +// Variant that performs normal implementation on full vector +// more accurate does 64-bit processing, takes and returns 32-bit values +// returns narrowed results +static INLINE void butterfly_one_coeff_s32_s64_narrow( + const int32x4_t a_lo, const int32x4_t a_hi, const int32x4_t b_lo, + const int32x4_t b_hi, const tran_coef_t constant, int32x4_t *add_lo, + int32x4_t *add_hi, int32x4_t *sub_lo, int32x4_t *sub_hi) { + // ac holds the following values: + // ac: vget_low_s32(a_lo) * c, vget_high_s32(a_lo) * c, + // vget_low_s32(a_hi) * c, vget_high_s32(a_hi) * c + int64x2_t ac[4]; + int64x2_t sum[4]; + int64x2_t diff[4]; + + ac[0] = vmull_n_s32(vget_low_s32(a_lo), constant); + ac[1] = vmull_n_s32(vget_high_s32(a_lo), constant); + ac[2] = vmull_n_s32(vget_low_s32(a_hi), constant); + ac[3] = vmull_n_s32(vget_high_s32(a_hi), constant); + + sum[0] = vmlal_n_s32(ac[0], vget_low_s32(b_lo), constant); + sum[1] = vmlal_n_s32(ac[1], vget_high_s32(b_lo), constant); + sum[2] = vmlal_n_s32(ac[2], vget_low_s32(b_hi), constant); + sum[3] = vmlal_n_s32(ac[3], vget_high_s32(b_hi), constant); + *add_lo = vcombine_s32(vrshrn_n_s64(sum[0], DCT_CONST_BITS), + vrshrn_n_s64(sum[1], DCT_CONST_BITS)); + *add_hi = vcombine_s32(vrshrn_n_s64(sum[2], DCT_CONST_BITS), + vrshrn_n_s64(sum[3], DCT_CONST_BITS)); + + diff[0] = vmlsl_n_s32(ac[0], vget_low_s32(b_lo), constant); + diff[1] = vmlsl_n_s32(ac[1], vget_high_s32(b_lo), constant); + diff[2] = vmlsl_n_s32(ac[2], vget_low_s32(b_hi), constant); + diff[3] = vmlsl_n_s32(ac[3], vget_high_s32(b_hi), constant); + *sub_lo = vcombine_s32(vrshrn_n_s64(diff[0], DCT_CONST_BITS), + vrshrn_n_s64(diff[1], DCT_CONST_BITS)); + *sub_hi = vcombine_s32(vrshrn_n_s64(diff[2], DCT_CONST_BITS), + vrshrn_n_s64(diff[3], DCT_CONST_BITS)); +} + +// fdct_round_shift(a * c1 +/- b * c2) +// Variant that performs normal implementation on half vector +// more accurate does 64-bit processing, takes and returns 32-bit values +// returns narrowed results +static INLINE void butterfly_two_coeff_s32_s64_narrow_half( + const int32x4_t a, const int32x4_t b, const tran_coef_t constant1, + const tran_coef_t constant2, int32x4_t *add, int32x4_t *sub) { + const int32x2_t a_lo = vget_low_s32(a); + const int32x2_t a_hi = vget_high_s32(a); + const int32x2_t b_lo = vget_low_s32(b); + const int32x2_t b_hi = vget_high_s32(b); + + const int64x2_t axc0_64_lo = vmull_n_s32(a_lo, constant1); + const int64x2_t axc0_64_hi = vmull_n_s32(a_hi, constant1); + const int64x2_t axc1_64_lo = vmull_n_s32(a_lo, constant2); + const int64x2_t axc1_64_hi = vmull_n_s32(a_hi, constant2); + + const int64x2_t sum_lo = vmlal_n_s32(axc0_64_lo, b_lo, constant2); + const int64x2_t sum_hi = vmlal_n_s32(axc0_64_hi, b_hi, constant2); + const int64x2_t diff_lo = vmlsl_n_s32(axc1_64_lo, b_lo, constant1); + const int64x2_t diff_hi = vmlsl_n_s32(axc1_64_hi, b_hi, constant1); + + *add = vcombine_s32(vrshrn_n_s64(sum_lo, DCT_CONST_BITS), + vrshrn_n_s64(sum_hi, DCT_CONST_BITS)); + *sub = vcombine_s32(vrshrn_n_s64(diff_lo, DCT_CONST_BITS), + vrshrn_n_s64(diff_hi, DCT_CONST_BITS)); +} + +// fdct_round_shift(a * c1 +/- b * c2) +// Variant that performs normal implementation on full vector +// more accurate does 64-bit processing, takes and returns 64-bit values +// returns results without rounding +static INLINE void butterfly_two_coeff_s32_s64_noround( + const int32x4_t a_lo, const int32x4_t a_hi, const int32x4_t b_lo, + const int32x4_t b_hi, const tran_coef_t constant1, + const tran_coef_t constant2, int64x2_t *add_lo /*[2]*/, + int64x2_t *add_hi /*[2]*/, int64x2_t *sub_lo /*[2]*/, + int64x2_t *sub_hi /*[2]*/) { + // ac1/ac2 hold the following values: + // ac1: vget_low_s32(a_lo) * c1, vget_high_s32(a_lo) * c1, + // vget_low_s32(a_hi) * c1, vget_high_s32(a_hi) * c1 + // ac2: vget_low_s32(a_lo) * c2, vget_high_s32(a_lo) * c2, + // vget_low_s32(a_hi) * c2, vget_high_s32(a_hi) * c2 + int64x2_t ac1[4]; + int64x2_t ac2[4]; + + ac1[0] = vmull_n_s32(vget_low_s32(a_lo), constant1); + ac1[1] = vmull_n_s32(vget_high_s32(a_lo), constant1); + ac1[2] = vmull_n_s32(vget_low_s32(a_hi), constant1); + ac1[3] = vmull_n_s32(vget_high_s32(a_hi), constant1); + ac2[0] = vmull_n_s32(vget_low_s32(a_lo), constant2); + ac2[1] = vmull_n_s32(vget_high_s32(a_lo), constant2); + ac2[2] = vmull_n_s32(vget_low_s32(a_hi), constant2); + ac2[3] = vmull_n_s32(vget_high_s32(a_hi), constant2); + + add_lo[0] = vmlal_n_s32(ac1[0], vget_low_s32(b_lo), constant2); + add_lo[1] = vmlal_n_s32(ac1[1], vget_high_s32(b_lo), constant2); + add_hi[0] = vmlal_n_s32(ac1[2], vget_low_s32(b_hi), constant2); + add_hi[1] = vmlal_n_s32(ac1[3], vget_high_s32(b_hi), constant2); + + sub_lo[0] = vmlsl_n_s32(ac2[0], vget_low_s32(b_lo), constant1); + sub_lo[1] = vmlsl_n_s32(ac2[1], vget_high_s32(b_lo), constant1); + sub_hi[0] = vmlsl_n_s32(ac2[2], vget_low_s32(b_hi), constant1); + sub_hi[1] = vmlsl_n_s32(ac2[3], vget_high_s32(b_hi), constant1); +} + +// fdct_round_shift(a * c1 +/- b * c2) +// Variant that performs normal implementation on full vector +// more accurate does 64-bit processing, takes and returns 32-bit values +// returns narrowed results +static INLINE void butterfly_two_coeff_s32_s64_narrow( + const int32x4_t a_lo, const int32x4_t a_hi, const int32x4_t b_lo, + const int32x4_t b_hi, const tran_coef_t constant1, + const tran_coef_t constant2, int32x4_t *add_lo, int32x4_t *add_hi, + int32x4_t *sub_lo, int32x4_t *sub_hi) { + // ac1/ac2 hold the following values: + // ac1: vget_low_s32(a_lo) * c1, vget_high_s32(a_lo) * c1, + // vget_low_s32(a_hi) * c1, vget_high_s32(a_hi) * c1 + // ac2: vget_low_s32(a_lo) * c2, vget_high_s32(a_lo) * c2, + // vget_low_s32(a_hi) * c2, vget_high_s32(a_hi) * c2 + int64x2_t ac1[4]; + int64x2_t ac2[4]; + int64x2_t sum[4]; + int64x2_t diff[4]; + + ac1[0] = vmull_n_s32(vget_low_s32(a_lo), constant1); + ac1[1] = vmull_n_s32(vget_high_s32(a_lo), constant1); + ac1[2] = vmull_n_s32(vget_low_s32(a_hi), constant1); + ac1[3] = vmull_n_s32(vget_high_s32(a_hi), constant1); + ac2[0] = vmull_n_s32(vget_low_s32(a_lo), constant2); + ac2[1] = vmull_n_s32(vget_high_s32(a_lo), constant2); + ac2[2] = vmull_n_s32(vget_low_s32(a_hi), constant2); + ac2[3] = vmull_n_s32(vget_high_s32(a_hi), constant2); + + sum[0] = vmlal_n_s32(ac1[0], vget_low_s32(b_lo), constant2); + sum[1] = vmlal_n_s32(ac1[1], vget_high_s32(b_lo), constant2); + sum[2] = vmlal_n_s32(ac1[2], vget_low_s32(b_hi), constant2); + sum[3] = vmlal_n_s32(ac1[3], vget_high_s32(b_hi), constant2); + *add_lo = vcombine_s32(vrshrn_n_s64(sum[0], DCT_CONST_BITS), + vrshrn_n_s64(sum[1], DCT_CONST_BITS)); + *add_hi = vcombine_s32(vrshrn_n_s64(sum[2], DCT_CONST_BITS), + vrshrn_n_s64(sum[3], DCT_CONST_BITS)); + + diff[0] = vmlsl_n_s32(ac2[0], vget_low_s32(b_lo), constant1); + diff[1] = vmlsl_n_s32(ac2[1], vget_high_s32(b_lo), constant1); + diff[2] = vmlsl_n_s32(ac2[2], vget_low_s32(b_hi), constant1); + diff[3] = vmlsl_n_s32(ac2[3], vget_high_s32(b_hi), constant1); + *sub_lo = vcombine_s32(vrshrn_n_s64(diff[0], DCT_CONST_BITS), + vrshrn_n_s64(diff[1], DCT_CONST_BITS)); + *sub_hi = vcombine_s32(vrshrn_n_s64(diff[2], DCT_CONST_BITS), + vrshrn_n_s64(diff[3], DCT_CONST_BITS)); +} + +// fdct_round_shift(a * c1 +/- b * c2) +// Original Variant that performs normal implementation on full vector +// more accurate does 32-bit processing, takes and returns 32-bit values +// returns narrowed results +static INLINE void butterfly_two_coeff_s16_s32_noround( + const int16x4_t a_lo, const int16x4_t a_hi, const int16x4_t b_lo, + const int16x4_t b_hi, const tran_coef_t constant1, + const tran_coef_t constant2, int32x4_t *add_lo, int32x4_t *add_hi, + int32x4_t *sub_lo, int32x4_t *sub_hi) { + const int32x4_t a1 = vmull_n_s16(a_lo, constant1); + const int32x4_t a2 = vmull_n_s16(a_hi, constant1); + const int32x4_t a3 = vmull_n_s16(a_lo, constant2); + const int32x4_t a4 = vmull_n_s16(a_hi, constant2); + *add_lo = vmlal_n_s16(a1, b_lo, constant2); + *add_hi = vmlal_n_s16(a2, b_hi, constant2); + *sub_lo = vmlsl_n_s16(a3, b_lo, constant1); + *sub_hi = vmlsl_n_s16(a4, b_hi, constant1); +} + +// fdct_round_shift(a * c1 +/- b * c2) +// Original Variant that performs normal implementation on full vector +// more accurate does 32-bit processing, takes and returns 32-bit values +// returns narrowed results +static INLINE void butterfly_two_coeff_s32_noround( + const int32x4_t a_lo, const int32x4_t a_hi, const int32x4_t b_lo, + const int32x4_t b_hi, const tran_coef_t constant1, + const tran_coef_t constant2, int32x4_t *add_lo, int32x4_t *add_hi, + int32x4_t *sub_lo, int32x4_t *sub_hi) { + const int32x4_t a1 = vmulq_n_s32(a_lo, constant1); + const int32x4_t a2 = vmulq_n_s32(a_hi, constant1); + const int32x4_t a3 = vmulq_n_s32(a_lo, constant2); + const int32x4_t a4 = vmulq_n_s32(a_hi, constant2); + *add_lo = vmlaq_n_s32(a1, b_lo, constant2); + *add_hi = vmlaq_n_s32(a2, b_hi, constant2); + *sub_lo = vmlsq_n_s32(a3, b_lo, constant1); + *sub_hi = vmlsq_n_s32(a4, b_hi, constant1); +} + +// fdct_round_shift(a * c1 +/- b * c2) +// Variant that performs normal implementation on half vector +// more accurate does 32-bit processing, takes and returns 16-bit values +// returns narrowed results +static INLINE void butterfly_two_coeff_half(const int16x4_t a, + const int16x4_t b, + const tran_coef_t constant1, + const tran_coef_t constant2, + int16x4_t *add, int16x4_t *sub) { + const int32x4_t a1 = vmull_n_s16(a, constant1); + const int32x4_t a2 = vmull_n_s16(a, constant2); + const int32x4_t sum = vmlal_n_s16(a1, b, constant2); + const int32x4_t diff = vmlsl_n_s16(a2, b, constant1); + *add = vqrshrn_n_s32(sum, DCT_CONST_BITS); + *sub = vqrshrn_n_s32(diff, DCT_CONST_BITS); +} + +// fdct_round_shift(a * c1 +/- b * c2) +// Original Variant that performs normal implementation on full vector +// more accurate does 32-bit processing, takes and returns 16-bit values +// returns narrowed results +static INLINE void butterfly_two_coeff(const int16x8_t a, const int16x8_t b, + const tran_coef_t constant1, + const tran_coef_t constant2, + int16x8_t *add, int16x8_t *sub) { + const int32x4_t a1 = vmull_n_s16(vget_low_s16(a), constant1); + const int32x4_t a2 = vmull_n_s16(vget_high_s16(a), constant1); + const int32x4_t a3 = vmull_n_s16(vget_low_s16(a), constant2); + const int32x4_t a4 = vmull_n_s16(vget_high_s16(a), constant2); + const int32x4_t sum0 = vmlal_n_s16(a1, vget_low_s16(b), constant2); + const int32x4_t sum1 = vmlal_n_s16(a2, vget_high_s16(b), constant2); + const int32x4_t diff0 = vmlsl_n_s16(a3, vget_low_s16(b), constant1); + const int32x4_t diff1 = vmlsl_n_s16(a4, vget_high_s16(b), constant1); + const int16x4_t rounded0 = vqrshrn_n_s32(sum0, DCT_CONST_BITS); + const int16x4_t rounded1 = vqrshrn_n_s32(sum1, DCT_CONST_BITS); + const int16x4_t rounded2 = vqrshrn_n_s32(diff0, DCT_CONST_BITS); + const int16x4_t rounded3 = vqrshrn_n_s32(diff1, DCT_CONST_BITS); + *add = vcombine_s16(rounded0, rounded1); + *sub = vcombine_s16(rounded2, rounded3); +} + +// fdct_round_shift(a * c1 +/- b * c2) +// Original Variant that performs normal implementation on full vector +// more accurate does 32-bit processing, takes and returns 32-bit values +// returns narrowed results +static INLINE void butterfly_two_coeff_s32( + const int32x4_t a_lo, const int32x4_t a_hi, const int32x4_t b_lo, + const int32x4_t b_hi, const tran_coef_t constant1, + const tran_coef_t constant2, int32x4_t *add_lo, int32x4_t *add_hi, + int32x4_t *sub_lo, int32x4_t *sub_hi) { + const int32x4_t a1 = vmulq_n_s32(a_lo, constant1); + const int32x4_t a2 = vmulq_n_s32(a_hi, constant1); + const int32x4_t a3 = vmulq_n_s32(a_lo, constant2); + const int32x4_t a4 = vmulq_n_s32(a_hi, constant2); + const int32x4_t sum0 = vmlaq_n_s32(a1, b_lo, constant2); + const int32x4_t sum1 = vmlaq_n_s32(a2, b_hi, constant2); + const int32x4_t diff0 = vmlsq_n_s32(a3, b_lo, constant1); + const int32x4_t diff1 = vmlsq_n_s32(a4, b_hi, constant1); + *add_lo = vrshrq_n_s32(sum0, DCT_CONST_BITS); + *add_hi = vrshrq_n_s32(sum1, DCT_CONST_BITS); + *sub_lo = vrshrq_n_s32(diff0, DCT_CONST_BITS); + *sub_hi = vrshrq_n_s32(diff1, DCT_CONST_BITS); +} + +// Add 1 if positive, 2 if negative, and shift by 2. +// In practice, add 1, then add the sign bit, then shift without rounding. +static INLINE int16x8_t add_round_shift_s16(const int16x8_t a) { + const int16x8_t one = vdupq_n_s16(1); + const uint16x8_t a_u16 = vreinterpretq_u16_s16(a); + const uint16x8_t a_sign_u16 = vshrq_n_u16(a_u16, 15); + const int16x8_t a_sign_s16 = vreinterpretq_s16_u16(a_sign_u16); + return vshrq_n_s16(vaddq_s16(vaddq_s16(a, a_sign_s16), one), 2); +} + +// Add 1 if positive, 2 if negative, and shift by 2. +// In practice, add 1, then add the sign bit, then shift and round, +// return narrowed results +static INLINE int16x8_t add_round_shift_s32_narrow(const int32x4_t a_lo, + const int32x4_t a_hi) { + const int32x4_t one = vdupq_n_s32(1); + const uint32x4_t a_lo_u32 = vreinterpretq_u32_s32(a_lo); + const uint32x4_t a_lo_sign_u32 = vshrq_n_u32(a_lo_u32, 31); + const int32x4_t a_lo_sign_s32 = vreinterpretq_s32_u32(a_lo_sign_u32); + const int16x4_t b_lo = + vshrn_n_s32(vqaddq_s32(vqaddq_s32(a_lo, a_lo_sign_s32), one), 2); + const uint32x4_t a_hi_u32 = vreinterpretq_u32_s32(a_hi); + const uint32x4_t a_hi_sign_u32 = vshrq_n_u32(a_hi_u32, 31); + const int32x4_t a_hi_sign_s32 = vreinterpretq_s32_u32(a_hi_sign_u32); + const int16x4_t b_hi = + vshrn_n_s32(vqaddq_s32(vqaddq_s32(a_hi, a_hi_sign_s32), one), 2); + return vcombine_s16(b_lo, b_hi); +} + +// Add 1 if negative, and shift by 1. +// In practice, add the sign bit, then shift and round +static INLINE int32x4_t add_round_shift_half_s32(const int32x4_t a) { + const uint32x4_t a_u32 = vreinterpretq_u32_s32(a); + const uint32x4_t a_sign_u32 = vshrq_n_u32(a_u32, 31); + const int32x4_t a_sign_s32 = vreinterpretq_s32_u32(a_sign_u32); + return vshrq_n_s32(vaddq_s32(a, a_sign_s32), 1); +} + +// Add 1 if positive, 2 if negative, and shift by 2. +// In practice, add 1, then add the sign bit, then shift without rounding. +static INLINE int32x4_t add_round_shift_s32(const int32x4_t a) { + const int32x4_t one = vdupq_n_s32(1); + const uint32x4_t a_u32 = vreinterpretq_u32_s32(a); + const uint32x4_t a_sign_u32 = vshrq_n_u32(a_u32, 31); + const int32x4_t a_sign_s32 = vreinterpretq_s32_u32(a_sign_u32); + return vshrq_n_s32(vaddq_s32(vaddq_s32(a, a_sign_s32), one), 2); +} + +// Add 2 if positive, 1 if negative, and shift by 2. +// In practice, subtract the sign bit, then shift with rounding. +static INLINE int16x8_t sub_round_shift_s16(const int16x8_t a) { + const uint16x8_t a_u16 = vreinterpretq_u16_s16(a); + const uint16x8_t a_sign_u16 = vshrq_n_u16(a_u16, 15); + const int16x8_t a_sign_s16 = vreinterpretq_s16_u16(a_sign_u16); + return vrshrq_n_s16(vsubq_s16(a, a_sign_s16), 2); +} + +// Add 2 if positive, 1 if negative, and shift by 2. +// In practice, subtract the sign bit, then shift with rounding. +static INLINE int32x4_t sub_round_shift_s32(const int32x4_t a) { + const uint32x4_t a_u32 = vreinterpretq_u32_s32(a); + const uint32x4_t a_sign_u32 = vshrq_n_u32(a_u32, 31); + const int32x4_t a_sign_s32 = vreinterpretq_s32_u32(a_sign_u32); + return vrshrq_n_s32(vsubq_s32(a, a_sign_s32), 2); +} + +static INLINE int32x4_t add_s64_round_narrow(const int64x2_t *a /*[2]*/, + const int64x2_t *b /*[2]*/) { + int64x2_t result[2]; + result[0] = vaddq_s64(a[0], b[0]); + result[1] = vaddq_s64(a[1], b[1]); + return vcombine_s32(vrshrn_n_s64(result[0], DCT_CONST_BITS), + vrshrn_n_s64(result[1], DCT_CONST_BITS)); +} + +static INLINE int32x4_t sub_s64_round_narrow(const int64x2_t *a /*[2]*/, + const int64x2_t *b /*[2]*/) { + int64x2_t result[2]; + result[0] = vsubq_s64(a[0], b[0]); + result[1] = vsubq_s64(a[1], b[1]); + return vcombine_s32(vrshrn_n_s64(result[0], DCT_CONST_BITS), + vrshrn_n_s64(result[1], DCT_CONST_BITS)); +} + +static INLINE int32x4_t add_s32_s64_narrow(const int32x4_t a, + const int32x4_t b) { + int64x2_t a64[2], b64[2], result[2]; + a64[0] = vmovl_s32(vget_low_s32(a)); + a64[1] = vmovl_s32(vget_high_s32(a)); + b64[0] = vmovl_s32(vget_low_s32(b)); + b64[1] = vmovl_s32(vget_high_s32(b)); + result[0] = vaddq_s64(a64[0], b64[0]); + result[1] = vaddq_s64(a64[1], b64[1]); + return vcombine_s32(vmovn_s64(result[0]), vmovn_s64(result[1])); +} + +static INLINE int32x4_t sub_s32_s64_narrow(const int32x4_t a, + const int32x4_t b) { + int64x2_t a64[2], b64[2], result[2]; + a64[0] = vmovl_s32(vget_low_s32(a)); + a64[1] = vmovl_s32(vget_high_s32(a)); + b64[0] = vmovl_s32(vget_low_s32(b)); + b64[1] = vmovl_s32(vget_high_s32(b)); + result[0] = vsubq_s64(a64[0], b64[0]); + result[1] = vsubq_s64(a64[1], b64[1]); + return vcombine_s32(vmovn_s64(result[0]), vmovn_s64(result[1])); +} + #endif // VPX_VPX_DSP_ARM_FDCT_NEON_H_ diff --git a/libs/libvpx/vpx_dsp/arm/fdct_partial_neon.c b/libs/libvpx/vpx_dsp/arm/fdct_partial_neon.c index 0a1cdca41d..ee9e599e09 100644 --- a/libs/libvpx/vpx_dsp/arm/fdct_partial_neon.c +++ b/libs/libvpx/vpx_dsp/arm/fdct_partial_neon.c @@ -37,6 +37,17 @@ void vpx_fdct4x4_1_neon(const int16_t *input, tran_low_t *output, int stride) { output[1] = 0; } +// Visual Studio 2022 (cl.exe) < 17.7 targeting AArch64 with optimizations +// enabled will fail with an internal compiler error. See: +// https://developercommunity.visualstudio.com/t/Compiler-crash-C1001-when-building-a-for/10346110 +#if defined(_MSC_VER) && _MSC_VER < 1937 && defined(_M_ARM64) && \ + !defined(__clang__) +#define AOM_WORK_AROUND_MSVC_BUG_10346110 +#endif + +#ifdef AOM_WORK_AROUND_MSVC_BUG_10346110 +#pragma optimize("", off) +#endif void vpx_fdct8x8_1_neon(const int16_t *input, tran_low_t *output, int stride) { int r; int16x8_t sum = vld1q_s16(&input[0]); @@ -49,6 +60,10 @@ void vpx_fdct8x8_1_neon(const int16_t *input, tran_low_t *output, int stride) { output[0] = (tran_low_t)horizontal_add_int16x8(sum); output[1] = 0; } +#ifdef AOM_WORK_AROUND_MSVC_BUG_10346110 +#pragma optimize("", on) +#endif +#undef AOM_WORK_AROUND_MSVC_BUG_10346110 void vpx_fdct16x16_1_neon(const int16_t *input, tran_low_t *output, int stride) { @@ -101,3 +116,68 @@ void vpx_fdct32x32_1_neon(const int16_t *input, tran_low_t *output, output[0] = (tran_low_t)(sum >> 3); output[1] = 0; } + +#if CONFIG_VP9_HIGHBITDEPTH + +void vpx_highbd_fdct16x16_1_neon(const int16_t *input, tran_low_t *output, + int stride) { + int32x4_t partial_sum[4] = { vdupq_n_s32(0), vdupq_n_s32(0), vdupq_n_s32(0), + vdupq_n_s32(0) }; + int32_t sum; + + int r = 0; + do { + const int16x8_t a = vld1q_s16(input); + const int16x8_t b = vld1q_s16(input + 8); + input += stride; + partial_sum[0] = vaddw_s16(partial_sum[0], vget_low_s16(a)); + partial_sum[1] = vaddw_s16(partial_sum[1], vget_high_s16(a)); + partial_sum[2] = vaddw_s16(partial_sum[2], vget_low_s16(b)); + partial_sum[3] = vaddw_s16(partial_sum[3], vget_high_s16(b)); + r++; + } while (r < 16); + + partial_sum[0] = vaddq_s32(partial_sum[0], partial_sum[1]); + partial_sum[2] = vaddq_s32(partial_sum[2], partial_sum[3]); + partial_sum[0] = vaddq_s32(partial_sum[0], partial_sum[2]); + sum = horizontal_add_int32x4(partial_sum[0]); + + output[0] = (tran_low_t)(sum >> 1); + output[1] = 0; +} + +void vpx_highbd_fdct32x32_1_neon(const int16_t *input, tran_low_t *output, + int stride) { + int32x4_t partial_sum[4] = { vdupq_n_s32(0), vdupq_n_s32(0), vdupq_n_s32(0), + vdupq_n_s32(0) }; + + int32_t sum; + + int r = 0; + do { + const int16x8_t a0 = vld1q_s16(input); + const int16x8_t a1 = vld1q_s16(input + 8); + const int16x8_t a2 = vld1q_s16(input + 16); + const int16x8_t a3 = vld1q_s16(input + 24); + input += stride; + partial_sum[0] = vaddw_s16(partial_sum[0], vget_low_s16(a0)); + partial_sum[0] = vaddw_s16(partial_sum[0], vget_high_s16(a0)); + partial_sum[1] = vaddw_s16(partial_sum[1], vget_low_s16(a1)); + partial_sum[1] = vaddw_s16(partial_sum[1], vget_high_s16(a1)); + partial_sum[2] = vaddw_s16(partial_sum[2], vget_low_s16(a2)); + partial_sum[2] = vaddw_s16(partial_sum[2], vget_high_s16(a2)); + partial_sum[3] = vaddw_s16(partial_sum[3], vget_low_s16(a3)); + partial_sum[3] = vaddw_s16(partial_sum[3], vget_high_s16(a3)); + r++; + } while (r < 32); + + partial_sum[0] = vaddq_s32(partial_sum[0], partial_sum[1]); + partial_sum[2] = vaddq_s32(partial_sum[2], partial_sum[3]); + partial_sum[0] = vaddq_s32(partial_sum[0], partial_sum[2]); + sum = horizontal_add_int32x4(partial_sum[0]); + + output[0] = (tran_low_t)(sum >> 3); + output[1] = 0; +} + +#endif // CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vpx_dsp/arm/fwd_txfm_neon.c b/libs/libvpx/vpx_dsp/arm/fwd_txfm_neon.c deleted file mode 100644 index d9161c6d38..0000000000 --- a/libs/libvpx/vpx_dsp/arm/fwd_txfm_neon.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2015 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include - -#include "./vpx_config.h" -#include "./vpx_dsp_rtcd.h" -#include "vpx_dsp/txfm_common.h" -#include "vpx_dsp/vpx_dsp_common.h" -#include "vpx_dsp/arm/idct_neon.h" -#include "vpx_dsp/arm/fdct_neon.h" -#include "vpx_dsp/arm/mem_neon.h" - -void vpx_fdct8x8_neon(const int16_t *input, tran_low_t *final_output, - int stride) { - int i; - // stage 1 - int16x8_t in[8]; - in[0] = vshlq_n_s16(vld1q_s16(&input[0 * stride]), 2); - in[1] = vshlq_n_s16(vld1q_s16(&input[1 * stride]), 2); - in[2] = vshlq_n_s16(vld1q_s16(&input[2 * stride]), 2); - in[3] = vshlq_n_s16(vld1q_s16(&input[3 * stride]), 2); - in[4] = vshlq_n_s16(vld1q_s16(&input[4 * stride]), 2); - in[5] = vshlq_n_s16(vld1q_s16(&input[5 * stride]), 2); - in[6] = vshlq_n_s16(vld1q_s16(&input[6 * stride]), 2); - in[7] = vshlq_n_s16(vld1q_s16(&input[7 * stride]), 2); - for (i = 0; i < 2; ++i) { - vpx_fdct8x8_pass1_neon(in); - } // for - { - // from vpx_dct_sse2.c - // Post-condition (division by two) - // division of two 16 bits signed numbers using shifts - // n / 2 = (n - (n >> 15)) >> 1 - const int16x8_t sign_in0 = vshrq_n_s16(in[0], 15); - const int16x8_t sign_in1 = vshrq_n_s16(in[1], 15); - const int16x8_t sign_in2 = vshrq_n_s16(in[2], 15); - const int16x8_t sign_in3 = vshrq_n_s16(in[3], 15); - const int16x8_t sign_in4 = vshrq_n_s16(in[4], 15); - const int16x8_t sign_in5 = vshrq_n_s16(in[5], 15); - const int16x8_t sign_in6 = vshrq_n_s16(in[6], 15); - const int16x8_t sign_in7 = vshrq_n_s16(in[7], 15); - in[0] = vhsubq_s16(in[0], sign_in0); - in[1] = vhsubq_s16(in[1], sign_in1); - in[2] = vhsubq_s16(in[2], sign_in2); - in[3] = vhsubq_s16(in[3], sign_in3); - in[4] = vhsubq_s16(in[4], sign_in4); - in[5] = vhsubq_s16(in[5], sign_in5); - in[6] = vhsubq_s16(in[6], sign_in6); - in[7] = vhsubq_s16(in[7], sign_in7); - // store results - store_s16q_to_tran_low(final_output + 0 * 8, in[0]); - store_s16q_to_tran_low(final_output + 1 * 8, in[1]); - store_s16q_to_tran_low(final_output + 2 * 8, in[2]); - store_s16q_to_tran_low(final_output + 3 * 8, in[3]); - store_s16q_to_tran_low(final_output + 4 * 8, in[4]); - store_s16q_to_tran_low(final_output + 5 * 8, in[5]); - store_s16q_to_tran_low(final_output + 6 * 8, in[6]); - store_s16q_to_tran_low(final_output + 7 * 8, in[7]); - } -} diff --git a/libs/libvpx/vpx_dsp/arm/hadamard_neon.c b/libs/libvpx/vpx_dsp/arm/hadamard_neon.c index 523a63c6f7..f5a044be4d 100644 --- a/libs/libvpx/vpx_dsp/arm/hadamard_neon.c +++ b/libs/libvpx/vpx_dsp/arm/hadamard_neon.c @@ -114,3 +114,45 @@ void vpx_hadamard_16x16_neon(const int16_t *src_diff, ptrdiff_t src_stride, coeff += 8; } } + +void vpx_hadamard_32x32_neon(const int16_t *src_diff, ptrdiff_t src_stride, + tran_low_t *coeff) { + int i; + + /* Rearrange 32x32 to 16x64 and remove stride. + * Top left first. */ + vpx_hadamard_16x16_neon(src_diff + 0 + 0 * src_stride, src_stride, coeff + 0); + /* Top right. */ + vpx_hadamard_16x16_neon(src_diff + 16 + 0 * src_stride, src_stride, + coeff + 256); + /* Bottom left. */ + vpx_hadamard_16x16_neon(src_diff + 0 + 16 * src_stride, src_stride, + coeff + 512); + /* Bottom right. */ + vpx_hadamard_16x16_neon(src_diff + 16 + 16 * src_stride, src_stride, + coeff + 768); + + for (i = 0; i < 256; i += 8) { + const int16x8_t a0 = load_tran_low_to_s16q(coeff + 0); + const int16x8_t a1 = load_tran_low_to_s16q(coeff + 256); + const int16x8_t a2 = load_tran_low_to_s16q(coeff + 512); + const int16x8_t a3 = load_tran_low_to_s16q(coeff + 768); + + const int16x8_t b0 = vshrq_n_s16(vhaddq_s16(a0, a1), 1); + const int16x8_t b1 = vshrq_n_s16(vhsubq_s16(a0, a1), 1); + const int16x8_t b2 = vshrq_n_s16(vhaddq_s16(a2, a3), 1); + const int16x8_t b3 = vshrq_n_s16(vhsubq_s16(a2, a3), 1); + + const int16x8_t c0 = vaddq_s16(b0, b2); + const int16x8_t c1 = vaddq_s16(b1, b3); + const int16x8_t c2 = vsubq_s16(b0, b2); + const int16x8_t c3 = vsubq_s16(b1, b3); + + store_s16q_to_tran_low(coeff + 0, c0); + store_s16q_to_tran_low(coeff + 256, c1); + store_s16q_to_tran_low(coeff + 512, c2); + store_s16q_to_tran_low(coeff + 768, c3); + + coeff += 8; + } +} diff --git a/libs/libvpx/vpx_dsp/arm/highbd_avg_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_avg_neon.c new file mode 100644 index 0000000000..4265596c8c --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_avg_neon.c @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_dsp_rtcd.h" +#include "./vpx_config.h" + +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" + +uint32_t vpx_highbd_avg_4x4_neon(const uint8_t *s8, int p) { + const uint16_t *a_ptr = CONVERT_TO_SHORTPTR(s8); + const uint16x8_t a0 = load_unaligned_u16q(a_ptr + 0 * p, p); + const uint16x8_t a1 = load_unaligned_u16q(a_ptr + 2 * p, p); + return (horizontal_add_uint16x8(vaddq_u16(a0, a1)) + (1 << 3)) >> 4; +} + +uint32_t vpx_highbd_avg_8x8_neon(const uint8_t *s8, int p) { + const uint16_t *a_ptr = CONVERT_TO_SHORTPTR(s8); + uint16x8_t sum, a0, a1, a2, a3, a4, a5, a6, a7; + + load_u16_8x8(a_ptr, p, &a0, &a1, &a2, &a3, &a4, &a5, &a6, &a7); + + sum = vaddq_u16(a0, a1); + sum = vaddq_u16(sum, a2); + sum = vaddq_u16(sum, a3); + sum = vaddq_u16(sum, a4); + sum = vaddq_u16(sum, a5); + sum = vaddq_u16(sum, a6); + sum = vaddq_u16(sum, a7); + + return (horizontal_add_uint16x8(sum) + (1 << 5)) >> 6; +} + +// coeff: 32 bits, dynamic range [-2147483648, 2147483647]. +// length: value range {16, 64, 256, 1024}. +// satd: 42 bits, dynamic range [-2147483648 * 1024, 2147483647 * 1024] +int vpx_highbd_satd_neon(const tran_low_t *coeff, int length) { + int64x2_t sum_s64[2] = { vdupq_n_s64(0), vdupq_n_s64(0) }; + + do { + int32x4_t abs0, abs1; + const int32x4_t s0 = load_tran_low_to_s32q(coeff); + const int32x4_t s1 = load_tran_low_to_s32q(coeff + 4); + + abs0 = vabsq_s32(s0); + sum_s64[0] = vpadalq_s32(sum_s64[0], abs0); + abs1 = vabsq_s32(s1); + sum_s64[1] = vpadalq_s32(sum_s64[1], abs1); + + length -= 8; + coeff += 8; + } while (length != 0); + + return (int)horizontal_add_int64x2(vaddq_s64(sum_s64[0], sum_s64[1])); +} + +void vpx_highbd_minmax_8x8_neon(const uint8_t *s8, int p, const uint8_t *d8, + int dp, int *min, int *max) { + const uint16_t *a_ptr = CONVERT_TO_SHORTPTR(s8); + const uint16_t *b_ptr = CONVERT_TO_SHORTPTR(d8); + + const uint16x8_t a0 = vld1q_u16(a_ptr + 0 * p); + const uint16x8_t a1 = vld1q_u16(a_ptr + 1 * p); + const uint16x8_t a2 = vld1q_u16(a_ptr + 2 * p); + const uint16x8_t a3 = vld1q_u16(a_ptr + 3 * p); + const uint16x8_t a4 = vld1q_u16(a_ptr + 4 * p); + const uint16x8_t a5 = vld1q_u16(a_ptr + 5 * p); + const uint16x8_t a6 = vld1q_u16(a_ptr + 6 * p); + const uint16x8_t a7 = vld1q_u16(a_ptr + 7 * p); + + const uint16x8_t b0 = vld1q_u16(b_ptr + 0 * dp); + const uint16x8_t b1 = vld1q_u16(b_ptr + 1 * dp); + const uint16x8_t b2 = vld1q_u16(b_ptr + 2 * dp); + const uint16x8_t b3 = vld1q_u16(b_ptr + 3 * dp); + const uint16x8_t b4 = vld1q_u16(b_ptr + 4 * dp); + const uint16x8_t b5 = vld1q_u16(b_ptr + 5 * dp); + const uint16x8_t b6 = vld1q_u16(b_ptr + 6 * dp); + const uint16x8_t b7 = vld1q_u16(b_ptr + 7 * dp); + + const uint16x8_t abs_diff0 = vabdq_u16(a0, b0); + const uint16x8_t abs_diff1 = vabdq_u16(a1, b1); + const uint16x8_t abs_diff2 = vabdq_u16(a2, b2); + const uint16x8_t abs_diff3 = vabdq_u16(a3, b3); + const uint16x8_t abs_diff4 = vabdq_u16(a4, b4); + const uint16x8_t abs_diff5 = vabdq_u16(a5, b5); + const uint16x8_t abs_diff6 = vabdq_u16(a6, b6); + const uint16x8_t abs_diff7 = vabdq_u16(a7, b7); + + const uint16x8_t max01 = vmaxq_u16(abs_diff0, abs_diff1); + const uint16x8_t max23 = vmaxq_u16(abs_diff2, abs_diff3); + const uint16x8_t max45 = vmaxq_u16(abs_diff4, abs_diff5); + const uint16x8_t max67 = vmaxq_u16(abs_diff6, abs_diff7); + + const uint16x8_t max0123 = vmaxq_u16(max01, max23); + const uint16x8_t max4567 = vmaxq_u16(max45, max67); + const uint16x8_t max07 = vmaxq_u16(max0123, max4567); + + const uint16x8_t min01 = vminq_u16(abs_diff0, abs_diff1); + const uint16x8_t min23 = vminq_u16(abs_diff2, abs_diff3); + const uint16x8_t min45 = vminq_u16(abs_diff4, abs_diff5); + const uint16x8_t min67 = vminq_u16(abs_diff6, abs_diff7); + + const uint16x8_t min0123 = vminq_u16(min01, min23); + const uint16x8_t min4567 = vminq_u16(min45, min67); + const uint16x8_t min07 = vminq_u16(min0123, min4567); + +#if VPX_ARCH_AARCH64 + *min = *max = 0; // Clear high bits + *((uint16_t *)max) = vmaxvq_u16(max07); + *((uint16_t *)min) = vminvq_u16(min07); +#else + // Split into 64-bit vectors and execute pairwise min/max. + uint16x4_t ab_max = vmax_u16(vget_high_u16(max07), vget_low_u16(max07)); + uint16x4_t ab_min = vmin_u16(vget_high_u16(min07), vget_low_u16(min07)); + + // Enough runs of vpmax/min propagate the max/min values to every position. + ab_max = vpmax_u16(ab_max, ab_max); + ab_min = vpmin_u16(ab_min, ab_min); + + ab_max = vpmax_u16(ab_max, ab_max); + ab_min = vpmin_u16(ab_min, ab_min); + + ab_max = vpmax_u16(ab_max, ab_max); + ab_min = vpmin_u16(ab_min, ab_min); + + *min = *max = 0; // Clear high bits + // Store directly to avoid costly neon->gpr transfer. + vst1_lane_u16((uint16_t *)max, ab_max, 0); + vst1_lane_u16((uint16_t *)min, ab_min, 0); +#endif +} diff --git a/libs/libvpx/vpx_dsp/arm/highbd_avg_pred_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_avg_pred_neon.c new file mode 100644 index 0000000000..3063acbb3e --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_avg_pred_neon.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_dsp_rtcd.h" +#include "./vpx_config.h" + +void vpx_highbd_comp_avg_pred_neon(uint16_t *comp_pred, const uint16_t *pred, + int width, int height, const uint16_t *ref, + int ref_stride) { + int i = height; + if (width > 8) { + do { + int j = 0; + do { + const uint16x8_t p = vld1q_u16(pred + j); + const uint16x8_t r = vld1q_u16(ref + j); + + uint16x8_t avg = vrhaddq_u16(p, r); + vst1q_u16(comp_pred + j, avg); + + j += 8; + } while (j < width); + + comp_pred += width; + pred += width; + ref += ref_stride; + } while (--i != 0); + } else if (width == 8) { + do { + const uint16x8_t p = vld1q_u16(pred); + const uint16x8_t r = vld1q_u16(ref); + + uint16x8_t avg = vrhaddq_u16(p, r); + vst1q_u16(comp_pred, avg); + + comp_pred += width; + pred += width; + ref += ref_stride; + } while (--i != 0); + } else { + assert(width == 4); + do { + const uint16x4_t p = vld1_u16(pred); + const uint16x4_t r = vld1_u16(ref); + + uint16x4_t avg = vrhadd_u16(p, r); + vst1_u16(comp_pred, avg); + + comp_pred += width; + pred += width; + ref += ref_stride; + } while (--i != 0); + } +} diff --git a/libs/libvpx/vpx_dsp/arm/highbd_convolve8_neon.h b/libs/libvpx/vpx_dsp/arm/highbd_convolve8_neon.h new file mode 100644 index 0000000000..ccc4a797b7 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_convolve8_neon.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VPX_DSP_ARM_HIGHBD_CONVOLVE8_NEON_H_ +#define VPX_VPX_DSP_ARM_HIGHBD_CONVOLVE8_NEON_H_ + +#include + +static INLINE uint16x4_t highbd_convolve4_4_neon( + const int16x4_t s0, const int16x4_t s1, const int16x4_t s2, + const int16x4_t s3, const int16x4_t filters, const uint16x4_t max) { + int32x4_t sum = vmull_lane_s16(s0, filters, 0); + sum = vmlal_lane_s16(sum, s1, filters, 1); + sum = vmlal_lane_s16(sum, s2, filters, 2); + sum = vmlal_lane_s16(sum, s3, filters, 3); + + uint16x4_t res = vqrshrun_n_s32(sum, FILTER_BITS); + return vmin_u16(res, max); +} + +static INLINE uint16x8_t highbd_convolve4_8_neon( + const int16x8_t s0, const int16x8_t s1, const int16x8_t s2, + const int16x8_t s3, const int16x4_t filters, const uint16x8_t max) { + int32x4_t sum0 = vmull_lane_s16(vget_low_s16(s0), filters, 0); + sum0 = vmlal_lane_s16(sum0, vget_low_s16(s1), filters, 1); + sum0 = vmlal_lane_s16(sum0, vget_low_s16(s2), filters, 2); + sum0 = vmlal_lane_s16(sum0, vget_low_s16(s3), filters, 3); + + int32x4_t sum1 = vmull_lane_s16(vget_high_s16(s0), filters, 0); + sum1 = vmlal_lane_s16(sum1, vget_high_s16(s1), filters, 1); + sum1 = vmlal_lane_s16(sum1, vget_high_s16(s2), filters, 2); + sum1 = vmlal_lane_s16(sum1, vget_high_s16(s3), filters, 3); + + uint16x8_t res = vcombine_u16(vqrshrun_n_s32(sum0, FILTER_BITS), + vqrshrun_n_s32(sum1, FILTER_BITS)); + return vminq_u16(res, max); +} + +#endif // VPX_VPX_DSP_ARM_HIGHBD_CONVOLVE8_NEON_H_ diff --git a/libs/libvpx/vpx_dsp/arm/highbd_convolve8_sve.h b/libs/libvpx/vpx_dsp/arm/highbd_convolve8_sve.h new file mode 100644 index 0000000000..bc90d9b4dd --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_convolve8_sve.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VPX_DSP_ARM_HIGHBD_CONVOLVE8_SVE_H_ +#define VPX_VPX_DSP_ARM_HIGHBD_CONVOLVE8_SVE_H_ + +#include + +#include "vpx_dsp/arm/vpx_neon_sve_bridge.h" + +static INLINE uint16x4_t highbd_convolve4_4_sve(const int16x4_t s[4], + const int16x8_t filter, + const uint16x4_t max) { + int16x8_t s01 = vcombine_s16(s[0], s[1]); + int16x8_t s23 = vcombine_s16(s[2], s[3]); + + int64x2_t sum01 = vpx_dotq_lane_s16(vdupq_n_s64(0), s01, filter, 0); + int64x2_t sum23 = vpx_dotq_lane_s16(vdupq_n_s64(0), s23, filter, 0); + + int32x4_t res_s32 = vcombine_s32(vmovn_s64(sum01), vmovn_s64(sum23)); + + uint16x4_t res_u16 = vqrshrun_n_s32(res_s32, FILTER_BITS); + return vmin_u16(res_u16, max); +} + +static INLINE uint16x8_t highbd_convolve4_8_sve(const int16x8_t s[4], + const int16x8_t filter, + const uint16x8_t max, + uint16x8_t idx) { + int64x2_t sum04 = vpx_dotq_lane_s16(vdupq_n_s64(0), s[0], filter, 0); + int64x2_t sum15 = vpx_dotq_lane_s16(vdupq_n_s64(0), s[1], filter, 0); + int64x2_t sum26 = vpx_dotq_lane_s16(vdupq_n_s64(0), s[2], filter, 0); + int64x2_t sum37 = vpx_dotq_lane_s16(vdupq_n_s64(0), s[3], filter, 0); + + int32x4_t res0 = vcombine_s32(vmovn_s64(sum04), vmovn_s64(sum15)); + int32x4_t res1 = vcombine_s32(vmovn_s64(sum26), vmovn_s64(sum37)); + + uint16x8_t res = vcombine_u16(vqrshrun_n_s32(res0, FILTER_BITS), + vqrshrun_n_s32(res1, FILTER_BITS)); + + res = vpx_tbl_u16(res, idx); + + return vminq_u16(res, max); +} + +static INLINE uint16x4_t highbd_convolve8_4(const int16x8_t s[4], + const int16x8_t filter, + const uint16x4_t max) { + int64x2_t sum[4]; + + sum[0] = vpx_dotq_s16(vdupq_n_s64(0), s[0], filter); + sum[1] = vpx_dotq_s16(vdupq_n_s64(0), s[1], filter); + sum[2] = vpx_dotq_s16(vdupq_n_s64(0), s[2], filter); + sum[3] = vpx_dotq_s16(vdupq_n_s64(0), s[3], filter); + + sum[0] = vpaddq_s64(sum[0], sum[1]); + sum[2] = vpaddq_s64(sum[2], sum[3]); + + int32x4_t res_s32 = vcombine_s32(vmovn_s64(sum[0]), vmovn_s64(sum[2])); + + uint16x4_t res_u16 = vqrshrun_n_s32(res_s32, FILTER_BITS); + return vmin_u16(res_u16, max); +} + +static INLINE uint16x8_t highbd_convolve8_8(const int16x8_t s[8], + const int16x8_t filter, + const uint16x8_t max) { + int64x2_t sum[8]; + + sum[0] = vpx_dotq_s16(vdupq_n_s64(0), s[0], filter); + sum[1] = vpx_dotq_s16(vdupq_n_s64(0), s[1], filter); + sum[2] = vpx_dotq_s16(vdupq_n_s64(0), s[2], filter); + sum[3] = vpx_dotq_s16(vdupq_n_s64(0), s[3], filter); + sum[4] = vpx_dotq_s16(vdupq_n_s64(0), s[4], filter); + sum[5] = vpx_dotq_s16(vdupq_n_s64(0), s[5], filter); + sum[6] = vpx_dotq_s16(vdupq_n_s64(0), s[6], filter); + sum[7] = vpx_dotq_s16(vdupq_n_s64(0), s[7], filter); + + int64x2_t sum01 = vpaddq_s64(sum[0], sum[1]); + int64x2_t sum23 = vpaddq_s64(sum[2], sum[3]); + int64x2_t sum45 = vpaddq_s64(sum[4], sum[5]); + int64x2_t sum67 = vpaddq_s64(sum[6], sum[7]); + + int32x4_t res0 = vcombine_s32(vmovn_s64(sum01), vmovn_s64(sum23)); + int32x4_t res1 = vcombine_s32(vmovn_s64(sum45), vmovn_s64(sum67)); + + uint16x8_t res = vcombine_u16(vqrshrun_n_s32(res0, FILTER_BITS), + vqrshrun_n_s32(res1, FILTER_BITS)); + return vminq_u16(res, max); +} + +#endif // VPX_VPX_DSP_ARM_HIGHBD_CONVOLVE8_SVE_H_ diff --git a/libs/libvpx/vpx_dsp/arm/highbd_hadamard_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_hadamard_neon.c new file mode 100644 index 0000000000..7be88f6bcb --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_hadamard_neon.c @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_dsp_rtcd.h" +#include "./vpx_config.h" + +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/transpose_neon.h" + +static INLINE void hadamard_highbd_col8_first_pass(int16x8_t *a0, int16x8_t *a1, + int16x8_t *a2, int16x8_t *a3, + int16x8_t *a4, int16x8_t *a5, + int16x8_t *a6, + int16x8_t *a7) { + int16x8_t b0 = vaddq_s16(*a0, *a1); + int16x8_t b1 = vsubq_s16(*a0, *a1); + int16x8_t b2 = vaddq_s16(*a2, *a3); + int16x8_t b3 = vsubq_s16(*a2, *a3); + int16x8_t b4 = vaddq_s16(*a4, *a5); + int16x8_t b5 = vsubq_s16(*a4, *a5); + int16x8_t b6 = vaddq_s16(*a6, *a7); + int16x8_t b7 = vsubq_s16(*a6, *a7); + + int16x8_t c0 = vaddq_s16(b0, b2); + int16x8_t c2 = vsubq_s16(b0, b2); + int16x8_t c1 = vaddq_s16(b1, b3); + int16x8_t c3 = vsubq_s16(b1, b3); + int16x8_t c4 = vaddq_s16(b4, b6); + int16x8_t c6 = vsubq_s16(b4, b6); + int16x8_t c5 = vaddq_s16(b5, b7); + int16x8_t c7 = vsubq_s16(b5, b7); + + *a0 = vaddq_s16(c0, c4); + *a2 = vsubq_s16(c0, c4); + *a7 = vaddq_s16(c1, c5); + *a6 = vsubq_s16(c1, c5); + *a3 = vaddq_s16(c2, c6); + *a1 = vsubq_s16(c2, c6); + *a4 = vaddq_s16(c3, c7); + *a5 = vsubq_s16(c3, c7); +} + +static INLINE void hadamard_highbd_col4_second_pass(int16x4_t a0, int16x4_t a1, + int16x4_t a2, int16x4_t a3, + int16x4_t a4, int16x4_t a5, + int16x4_t a6, int16x4_t a7, + tran_low_t *coeff) { + int32x4_t b0 = vaddl_s16(a0, a1); + int32x4_t b1 = vsubl_s16(a0, a1); + int32x4_t b2 = vaddl_s16(a2, a3); + int32x4_t b3 = vsubl_s16(a2, a3); + int32x4_t b4 = vaddl_s16(a4, a5); + int32x4_t b5 = vsubl_s16(a4, a5); + int32x4_t b6 = vaddl_s16(a6, a7); + int32x4_t b7 = vsubl_s16(a6, a7); + + int32x4_t c0 = vaddq_s32(b0, b2); + int32x4_t c2 = vsubq_s32(b0, b2); + int32x4_t c1 = vaddq_s32(b1, b3); + int32x4_t c3 = vsubq_s32(b1, b3); + int32x4_t c4 = vaddq_s32(b4, b6); + int32x4_t c6 = vsubq_s32(b4, b6); + int32x4_t c5 = vaddq_s32(b5, b7); + int32x4_t c7 = vsubq_s32(b5, b7); + + int32x4_t d0 = vaddq_s32(c0, c4); + int32x4_t d2 = vsubq_s32(c0, c4); + int32x4_t d7 = vaddq_s32(c1, c5); + int32x4_t d6 = vsubq_s32(c1, c5); + int32x4_t d3 = vaddq_s32(c2, c6); + int32x4_t d1 = vsubq_s32(c2, c6); + int32x4_t d4 = vaddq_s32(c3, c7); + int32x4_t d5 = vsubq_s32(c3, c7); + + store_s32q_to_tran_low(coeff + 0, d0); + store_s32q_to_tran_low(coeff + 4, d1); + store_s32q_to_tran_low(coeff + 8, d2); + store_s32q_to_tran_low(coeff + 12, d3); + store_s32q_to_tran_low(coeff + 16, d4); + store_s32q_to_tran_low(coeff + 20, d5); + store_s32q_to_tran_low(coeff + 24, d6); + store_s32q_to_tran_low(coeff + 28, d7); +} + +void vpx_highbd_hadamard_8x8_neon(const int16_t *src_diff, ptrdiff_t src_stride, + tran_low_t *coeff) { + int16x4_t b0, b1, b2, b3, b4, b5, b6, b7; + + int16x8_t s0 = vld1q_s16(src_diff + 0 * src_stride); + int16x8_t s1 = vld1q_s16(src_diff + 1 * src_stride); + int16x8_t s2 = vld1q_s16(src_diff + 2 * src_stride); + int16x8_t s3 = vld1q_s16(src_diff + 3 * src_stride); + int16x8_t s4 = vld1q_s16(src_diff + 4 * src_stride); + int16x8_t s5 = vld1q_s16(src_diff + 5 * src_stride); + int16x8_t s6 = vld1q_s16(src_diff + 6 * src_stride); + int16x8_t s7 = vld1q_s16(src_diff + 7 * src_stride); + + // For the first pass we can stay in 16-bit elements (4095*8 = 32760). + hadamard_highbd_col8_first_pass(&s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7); + + transpose_s16_8x8(&s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7); + + // For the second pass we need to widen to 32-bit elements, so we're + // processing 4 columns at a time. + // Skip the second transpose because it is not required. + + b0 = vget_low_s16(s0); + b1 = vget_low_s16(s1); + b2 = vget_low_s16(s2); + b3 = vget_low_s16(s3); + b4 = vget_low_s16(s4); + b5 = vget_low_s16(s5); + b6 = vget_low_s16(s6); + b7 = vget_low_s16(s7); + + hadamard_highbd_col4_second_pass(b0, b1, b2, b3, b4, b5, b6, b7, coeff); + + b0 = vget_high_s16(s0); + b1 = vget_high_s16(s1); + b2 = vget_high_s16(s2); + b3 = vget_high_s16(s3); + b4 = vget_high_s16(s4); + b5 = vget_high_s16(s5); + b6 = vget_high_s16(s6); + b7 = vget_high_s16(s7); + + hadamard_highbd_col4_second_pass(b0, b1, b2, b3, b4, b5, b6, b7, coeff + 32); +} + +void vpx_highbd_hadamard_16x16_neon(const int16_t *src_diff, + ptrdiff_t src_stride, tran_low_t *coeff) { + int i = 0; + + // Rearrange 16x16 to 8x32 and remove stride. + // Top left first. + vpx_highbd_hadamard_8x8_neon(src_diff, src_stride, coeff); + // Top right. + vpx_highbd_hadamard_8x8_neon(src_diff + 8, src_stride, coeff + 64); + // Bottom left. + vpx_highbd_hadamard_8x8_neon(src_diff + 8 * src_stride, src_stride, + coeff + 128); + // Bottom right. + vpx_highbd_hadamard_8x8_neon(src_diff + 8 * src_stride + 8, src_stride, + coeff + 192); + + do { + int32x4_t a0 = load_tran_low_to_s32q(coeff + 4 * i); + int32x4_t a1 = load_tran_low_to_s32q(coeff + 4 * i + 64); + int32x4_t a2 = load_tran_low_to_s32q(coeff + 4 * i + 128); + int32x4_t a3 = load_tran_low_to_s32q(coeff + 4 * i + 192); + + int32x4_t b0 = vhaddq_s32(a0, a1); + int32x4_t b1 = vhsubq_s32(a0, a1); + int32x4_t b2 = vhaddq_s32(a2, a3); + int32x4_t b3 = vhsubq_s32(a2, a3); + + int32x4_t c0 = vaddq_s32(b0, b2); + int32x4_t c1 = vaddq_s32(b1, b3); + int32x4_t c2 = vsubq_s32(b0, b2); + int32x4_t c3 = vsubq_s32(b1, b3); + + store_s32q_to_tran_low(coeff + 4 * i, c0); + store_s32q_to_tran_low(coeff + 4 * i + 64, c1); + store_s32q_to_tran_low(coeff + 4 * i + 128, c2); + store_s32q_to_tran_low(coeff + 4 * i + 192, c3); + } while (++i < 16); +} + +void vpx_highbd_hadamard_32x32_neon(const int16_t *src_diff, + ptrdiff_t src_stride, tran_low_t *coeff) { + int i = 0; + + // Rearrange 32x32 to 16x64 and remove stride. + // Top left first. + vpx_highbd_hadamard_16x16_neon(src_diff, src_stride, coeff); + // Top right. + vpx_highbd_hadamard_16x16_neon(src_diff + 16, src_stride, coeff + 256); + // Bottom left. + vpx_highbd_hadamard_16x16_neon(src_diff + 16 * src_stride, src_stride, + coeff + 512); + // Bottom right. + vpx_highbd_hadamard_16x16_neon(src_diff + 16 * src_stride + 16, src_stride, + coeff + 768); + + do { + int32x4_t a0 = load_tran_low_to_s32q(coeff + 4 * i); + int32x4_t a1 = load_tran_low_to_s32q(coeff + 4 * i + 256); + int32x4_t a2 = load_tran_low_to_s32q(coeff + 4 * i + 512); + int32x4_t a3 = load_tran_low_to_s32q(coeff + 4 * i + 768); + + int32x4_t b0 = vshrq_n_s32(vaddq_s32(a0, a1), 2); + int32x4_t b1 = vshrq_n_s32(vsubq_s32(a0, a1), 2); + int32x4_t b2 = vshrq_n_s32(vaddq_s32(a2, a3), 2); + int32x4_t b3 = vshrq_n_s32(vsubq_s32(a2, a3), 2); + + int32x4_t c0 = vaddq_s32(b0, b2); + int32x4_t c1 = vaddq_s32(b1, b3); + int32x4_t c2 = vsubq_s32(b0, b2); + int32x4_t c3 = vsubq_s32(b1, b3); + + store_s32q_to_tran_low(coeff + 4 * i, c0); + store_s32q_to_tran_low(coeff + 4 * i + 256, c1); + store_s32q_to_tran_low(coeff + 4 * i + 512, c2); + store_s32q_to_tran_low(coeff + 4 * i + 768, c3); + } while (++i < 64); +} diff --git a/libs/libvpx/vpx_dsp/arm/highbd_intrapred_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_intrapred_neon.c index 6f7e5da762..235cb5b996 100644 --- a/libs/libvpx/vpx_dsp/arm/highbd_intrapred_neon.c +++ b/libs/libvpx/vpx_dsp/arm/highbd_intrapred_neon.c @@ -12,23 +12,22 @@ #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" +#include "sum_neon.h" #include "vpx/vpx_integer.h" //------------------------------------------------------------------------------ // DC 4x4 -static INLINE uint16x4_t dc_sum_4(const uint16_t *ref) { +static INLINE uint16_t dc_sum_4(const uint16_t *ref) { const uint16x4_t ref_u16 = vld1_u16(ref); - const uint16x4_t p0 = vpadd_u16(ref_u16, ref_u16); - return vpadd_u16(p0, p0); + return horizontal_add_uint16x4(ref_u16); } static INLINE void dc_store_4x4(uint16_t *dst, ptrdiff_t stride, const uint16x4_t dc) { - const uint16x4_t dc_dup = vdup_lane_u16(dc, 0); int i; for (i = 0; i < 4; ++i, dst += stride) { - vst1_u16(dst, dc_dup); + vst1_u16(dst, dc); } } @@ -37,21 +36,17 @@ void vpx_highbd_dc_predictor_4x4_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *left, int bd) { const uint16x4_t a = vld1_u16(above); const uint16x4_t l = vld1_u16(left); - uint16x4_t sum; - uint16x4_t dc; + const uint16_t sum = horizontal_add_uint16x4(vadd_u16(a, l)); + const uint16x4_t dc = vrshr_n_u16(vdup_n_u16(sum), 3); (void)bd; - sum = vadd_u16(a, l); - sum = vpadd_u16(sum, sum); - sum = vpadd_u16(sum, sum); - dc = vrshr_n_u16(sum, 3); dc_store_4x4(dst, stride, dc); } void vpx_highbd_dc_left_predictor_4x4_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x4_t sum = dc_sum_4(left); - const uint16x4_t dc = vrshr_n_u16(sum, 2); + const uint16_t sum = dc_sum_4(left); + const uint16x4_t dc = vrshr_n_u16(vdup_n_u16(sum), 2); (void)above; (void)bd; dc_store_4x4(dst, stride, dc); @@ -60,8 +55,8 @@ void vpx_highbd_dc_left_predictor_4x4_neon(uint16_t *dst, ptrdiff_t stride, void vpx_highbd_dc_top_predictor_4x4_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x4_t sum = dc_sum_4(above); - const uint16x4_t dc = vrshr_n_u16(sum, 2); + const uint16_t sum = dc_sum_4(above); + const uint16x4_t dc = vrshr_n_u16(vdup_n_u16(sum), 2); (void)left; (void)bd; dc_store_4x4(dst, stride, dc); @@ -79,19 +74,16 @@ void vpx_highbd_dc_128_predictor_4x4_neon(uint16_t *dst, ptrdiff_t stride, //------------------------------------------------------------------------------ // DC 8x8 -static INLINE uint16x4_t dc_sum_8(const uint16_t *ref) { +static INLINE uint16_t dc_sum_8(const uint16_t *ref) { const uint16x8_t ref_u16 = vld1q_u16(ref); - uint16x4_t sum = vadd_u16(vget_low_u16(ref_u16), vget_high_u16(ref_u16)); - sum = vpadd_u16(sum, sum); - return vpadd_u16(sum, sum); + return horizontal_add_uint16x8(ref_u16); } static INLINE void dc_store_8x8(uint16_t *dst, ptrdiff_t stride, - const uint16x4_t dc) { - const uint16x8_t dc_dup = vdupq_lane_u16(dc, 0); + const uint16x8_t dc) { int i; for (i = 0; i < 8; ++i, dst += stride) { - vst1q_u16(dst, dc_dup); + vst1q_u16(dst, dc); } } @@ -101,20 +93,17 @@ void vpx_highbd_dc_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, const uint16x8_t above_u16 = vld1q_u16(above); const uint16x8_t left_u16 = vld1q_u16(left); const uint16x8_t p0 = vaddq_u16(above_u16, left_u16); - uint16x4_t sum = vadd_u16(vget_low_u16(p0), vget_high_u16(p0)); - uint16x4_t dc; + const uint16_t sum = horizontal_add_uint16x8(p0); + const uint16x8_t dc = vrshrq_n_u16(vdupq_n_u16(sum), 4); (void)bd; - sum = vpadd_u16(sum, sum); - sum = vpadd_u16(sum, sum); - dc = vrshr_n_u16(sum, 4); dc_store_8x8(dst, stride, dc); } void vpx_highbd_dc_left_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x4_t sum = dc_sum_8(left); - const uint16x4_t dc = vrshr_n_u16(sum, 3); + const uint16_t sum = dc_sum_8(left); + const uint16x8_t dc = vrshrq_n_u16(vdupq_n_u16(sum), 3); (void)above; (void)bd; dc_store_8x8(dst, stride, dc); @@ -123,8 +112,8 @@ void vpx_highbd_dc_left_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, void vpx_highbd_dc_top_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x4_t sum = dc_sum_8(above); - const uint16x4_t dc = vrshr_n_u16(sum, 3); + const uint16_t sum = dc_sum_8(above); + const uint16x8_t dc = vrshrq_n_u16(vdupq_n_u16(sum), 3); (void)left; (void)bd; dc_store_8x8(dst, stride, dc); @@ -133,7 +122,7 @@ void vpx_highbd_dc_top_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, void vpx_highbd_dc_128_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x4_t dc = vdup_n_u16(1 << (bd - 1)); + const uint16x8_t dc = vdupq_n_u16(1 << (bd - 1)); (void)above; (void)left; dc_store_8x8(dst, stride, dc); @@ -142,47 +131,43 @@ void vpx_highbd_dc_128_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, //------------------------------------------------------------------------------ // DC 16x16 -static INLINE uint16x4_t dc_sum_16(const uint16_t *ref) { - const uint16x8x2_t ref_u16 = vld2q_u16(ref); - const uint16x8_t p0 = vaddq_u16(ref_u16.val[0], ref_u16.val[1]); - uint16x4_t sum = vadd_u16(vget_low_u16(p0), vget_high_u16(p0)); - sum = vpadd_u16(sum, sum); - return vpadd_u16(sum, sum); +static INLINE uint16_t dc_sum_16(const uint16_t *ref) { + const uint16x8_t ref_u16_0 = vld1q_u16(ref + 0); + const uint16x8_t ref_u16_1 = vld1q_u16(ref + 8); + const uint16x8_t p0 = vaddq_u16(ref_u16_0, ref_u16_1); + return horizontal_add_uint16x8(p0); } static INLINE void dc_store_16x16(uint16_t *dst, ptrdiff_t stride, - const uint16x4_t dc) { - uint16x8x2_t dc_dup; + const uint16x8_t dc) { int i; - dc_dup.val[0] = dc_dup.val[1] = vdupq_lane_u16(dc, 0); for (i = 0; i < 16; ++i, dst += stride) { - vst2q_u16(dst, dc_dup); + vst1q_u16(dst + 0, dc); + vst1q_u16(dst + 8, dc); } } void vpx_highbd_dc_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x8x2_t a = vld2q_u16(above); - const uint16x8x2_t l = vld2q_u16(left); - const uint16x8_t pa = vaddq_u16(a.val[0], a.val[1]); - const uint16x8_t pl = vaddq_u16(l.val[0], l.val[1]); + const uint16x8_t a0 = vld1q_u16(above + 0); + const uint16x8_t a1 = vld1q_u16(above + 8); + const uint16x8_t l0 = vld1q_u16(left + 0); + const uint16x8_t l1 = vld1q_u16(left + 8); + const uint16x8_t pa = vaddq_u16(a0, a1); + const uint16x8_t pl = vaddq_u16(l0, l1); const uint16x8_t pal0 = vaddq_u16(pa, pl); - uint16x4_t pal1 = vadd_u16(vget_low_u16(pal0), vget_high_u16(pal0)); - uint32x2_t sum; - uint16x4_t dc; + const uint32_t sum = horizontal_add_uint16x8(pal0); + const uint16x8_t dc = vdupq_lane_u16(vrshrn_n_u32(vdupq_n_u32(sum), 5), 0); (void)bd; - pal1 = vpadd_u16(pal1, pal1); - sum = vpaddl_u16(pal1); - dc = vreinterpret_u16_u32(vrshr_n_u32(sum, 5)); dc_store_16x16(dst, stride, dc); } void vpx_highbd_dc_left_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x4_t sum = dc_sum_16(left); - const uint16x4_t dc = vrshr_n_u16(sum, 4); + const uint16_t sum = dc_sum_16(left); + const uint16x8_t dc = vrshrq_n_u16(vdupq_n_u16(sum), 4); (void)above; (void)bd; dc_store_16x16(dst, stride, dc); @@ -191,8 +176,8 @@ void vpx_highbd_dc_left_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, void vpx_highbd_dc_top_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x4_t sum = dc_sum_16(above); - const uint16x4_t dc = vrshr_n_u16(sum, 4); + const uint16_t sum = dc_sum_16(above); + const uint16x8_t dc = vrshrq_n_u16(vdupq_n_u16(sum), 4); (void)left; (void)bd; dc_store_16x16(dst, stride, dc); @@ -201,7 +186,7 @@ void vpx_highbd_dc_top_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, void vpx_highbd_dc_128_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x4_t dc = vdup_n_u16(1 << (bd - 1)); + const uint16x8_t dc = vdupq_n_u16(1 << (bd - 1)); (void)above; (void)left; dc_store_16x16(dst, stride, dc); @@ -210,56 +195,58 @@ void vpx_highbd_dc_128_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, //------------------------------------------------------------------------------ // DC 32x32 -static INLINE uint32x2_t dc_sum_32(const uint16_t *ref) { - const uint16x8x4_t r = vld4q_u16(ref); - const uint16x8_t p0 = vaddq_u16(r.val[0], r.val[1]); - const uint16x8_t p1 = vaddq_u16(r.val[2], r.val[3]); +static INLINE uint32_t dc_sum_32(const uint16_t *ref) { + const uint16x8_t r0 = vld1q_u16(ref + 0); + const uint16x8_t r1 = vld1q_u16(ref + 8); + const uint16x8_t r2 = vld1q_u16(ref + 16); + const uint16x8_t r3 = vld1q_u16(ref + 24); + const uint16x8_t p0 = vaddq_u16(r0, r1); + const uint16x8_t p1 = vaddq_u16(r2, r3); const uint16x8_t p2 = vaddq_u16(p0, p1); - uint16x4_t sum = vadd_u16(vget_low_u16(p2), vget_high_u16(p2)); - sum = vpadd_u16(sum, sum); - return vpaddl_u16(sum); + return horizontal_add_uint16x8(p2); } static INLINE void dc_store_32x32(uint16_t *dst, ptrdiff_t stride, - const uint16x4_t dc) { - uint16x8x2_t dc_dup; + const uint16x8_t dc) { int i; - dc_dup.val[0] = dc_dup.val[1] = vdupq_lane_u16(dc, 0); - for (i = 0; i < 32; ++i) { - vst2q_u16(dst, dc_dup); - dst += 16; - vst2q_u16(dst, dc_dup); - dst += stride - 16; + vst1q_u16(dst + 0, dc); + vst1q_u16(dst + 8, dc); + vst1q_u16(dst + 16, dc); + vst1q_u16(dst + 24, dc); + dst += stride; } } void vpx_highbd_dc_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x8x4_t a = vld4q_u16(above); - const uint16x8x4_t l = vld4q_u16(left); - const uint16x8_t pa0 = vaddq_u16(a.val[0], a.val[1]); - const uint16x8_t pa1 = vaddq_u16(a.val[2], a.val[3]); - const uint16x8_t pl0 = vaddq_u16(l.val[0], l.val[1]); - const uint16x8_t pl1 = vaddq_u16(l.val[2], l.val[3]); + const uint16x8_t a0 = vld1q_u16(above + 0); + const uint16x8_t a1 = vld1q_u16(above + 8); + const uint16x8_t a2 = vld1q_u16(above + 16); + const uint16x8_t a3 = vld1q_u16(above + 24); + const uint16x8_t l0 = vld1q_u16(left + 0); + const uint16x8_t l1 = vld1q_u16(left + 8); + const uint16x8_t l2 = vld1q_u16(left + 16); + const uint16x8_t l3 = vld1q_u16(left + 24); + const uint16x8_t pa0 = vaddq_u16(a0, a1); + const uint16x8_t pa1 = vaddq_u16(a2, a3); + const uint16x8_t pl0 = vaddq_u16(l0, l1); + const uint16x8_t pl1 = vaddq_u16(l2, l3); const uint16x8_t pa = vaddq_u16(pa0, pa1); const uint16x8_t pl = vaddq_u16(pl0, pl1); const uint16x8_t pal0 = vaddq_u16(pa, pl); - const uint16x4_t pal1 = vadd_u16(vget_low_u16(pal0), vget_high_u16(pal0)); - uint32x2_t sum = vpaddl_u16(pal1); - uint16x4_t dc; + const uint32_t sum = horizontal_add_uint16x8(pal0); + const uint16x8_t dc = vdupq_lane_u16(vrshrn_n_u32(vdupq_n_u32(sum), 6), 0); (void)bd; - sum = vpadd_u32(sum, sum); - dc = vreinterpret_u16_u32(vrshr_n_u32(sum, 6)); dc_store_32x32(dst, stride, dc); } void vpx_highbd_dc_left_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint32x2_t sum = dc_sum_32(left); - const uint16x4_t dc = vreinterpret_u16_u32(vrshr_n_u32(sum, 5)); + const uint32_t sum = dc_sum_32(left); + const uint16x8_t dc = vdupq_lane_u16(vrshrn_n_u32(vdupq_n_u32(sum), 5), 0); (void)above; (void)bd; dc_store_32x32(dst, stride, dc); @@ -268,8 +255,8 @@ void vpx_highbd_dc_left_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, void vpx_highbd_dc_top_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint32x2_t sum = dc_sum_32(above); - const uint16x4_t dc = vreinterpret_u16_u32(vrshr_n_u32(sum, 5)); + const uint32_t sum = dc_sum_32(above); + const uint16x8_t dc = vdupq_lane_u16(vrshrn_n_u32(vdupq_n_u32(sum), 5), 0); (void)left; (void)bd; dc_store_32x32(dst, stride, dc); @@ -278,7 +265,7 @@ void vpx_highbd_dc_top_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, void vpx_highbd_dc_128_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x4_t dc = vdup_n_u16(1 << (bd - 1)); + const uint16x8_t dc = vdupq_n_u16(1 << (bd - 1)); (void)above; (void)left; dc_store_32x32(dst, stride, dc); @@ -289,166 +276,1304 @@ void vpx_highbd_dc_128_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, void vpx_highbd_d45_predictor_4x4_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x8_t ABCDEFGH = vld1q_u16(above); - const uint16x8_t BCDEFGH0 = vld1q_u16(above + 1); - const uint16x8_t CDEFGH00 = vld1q_u16(above + 2); - const uint16x8_t avg1 = vhaddq_u16(ABCDEFGH, CDEFGH00); - const uint16x8_t avg2 = vrhaddq_u16(avg1, BCDEFGH0); - const uint16x4_t avg2_low = vget_low_u16(avg2); - const uint16x4_t avg2_high = vget_high_u16(avg2); - const uint16x4_t r1 = vext_u16(avg2_low, avg2_high, 1); - const uint16x4_t r2 = vext_u16(avg2_low, avg2_high, 2); - const uint16x4_t r3 = vext_u16(avg2_low, avg2_high, 3); + uint16x8_t a0, a1, a2, d0; + uint16_t a7; (void)left; (void)bd; - vst1_u16(dst, avg2_low); - dst += stride; - vst1_u16(dst, r1); - dst += stride; - vst1_u16(dst, r2); - dst += stride; - vst1_u16(dst, r3); - vst1q_lane_u16(dst + 3, ABCDEFGH, 7); -} -static INLINE void d45_store_8(uint16_t **dst, const ptrdiff_t stride, - const uint16x8_t above_right, uint16x8_t *row) { - *row = vextq_u16(*row, above_right, 1); - vst1q_u16(*dst, *row); - *dst += stride; + a0 = vld1q_u16(above); + a7 = above[7]; + + // [ above[1], ..., above[6], x, x ] + a1 = vextq_u16(a0, a0, 1); + // [ above[2], ..., above[7], x, x ] + a2 = vextq_u16(a0, a0, 2); + + // d0[0] = AVG3(above[0], above[1], above[2]); + // ... + // d0[5] = AVG3(above[5], above[6], above[7]); + // d0[6] = x (don't care) + // d0[7] = x (don't care) + d0 = vrhaddq_u16(vhaddq_u16(a0, a2), a1); + + // We want: + // stride=0 [ d0[0], d0[1], d0[2], d0[3] ] + // stride=1 [ d0[1], d0[2], d0[3], d0[4] ] + // stride=2 [ d0[2], d0[3], d0[4], d0[5] ] + // stride=2 [ d0[3], d0[4], d0[5], above[7] ] + vst1_u16(dst + 0 * stride, vget_low_u16(d0)); + vst1_u16(dst + 1 * stride, vget_low_u16(vextq_u16(d0, d0, 1))); + vst1_u16(dst + 2 * stride, vget_low_u16(vextq_u16(d0, d0, 2))); + vst1_u16(dst + 3 * stride, vget_low_u16(vextq_u16(d0, d0, 3))); + + // We stored d0[6] above, so fixup into above[7]. + dst[3 * stride + 3] = a7; } void vpx_highbd_d45_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x8_t A0 = vld1q_u16(above); - const uint16x8_t above_right = vdupq_lane_u16(vget_high_u16(A0), 3); - const uint16x8_t A1 = vld1q_u16(above + 1); - const uint16x8_t A2 = vld1q_u16(above + 2); - const uint16x8_t avg1 = vhaddq_u16(A0, A2); - uint16x8_t row = vrhaddq_u16(avg1, A1); + uint16x8_t ax0, a0, a1, a7, d0; (void)left; (void)bd; - vst1q_u16(dst, row); - dst += stride; - d45_store_8(&dst, stride, above_right, &row); - d45_store_8(&dst, stride, above_right, &row); - d45_store_8(&dst, stride, above_right, &row); - d45_store_8(&dst, stride, above_right, &row); - d45_store_8(&dst, stride, above_right, &row); - d45_store_8(&dst, stride, above_right, &row); - vst1q_u16(dst, above_right); -} + a0 = vld1q_u16(above + 0); + a1 = vld1q_u16(above + 1); + a7 = vld1q_dup_u16(above + 7); -static INLINE void d45_store_16(uint16_t **dst, const ptrdiff_t stride, - const uint16x8_t above_right, uint16x8_t *row_0, - uint16x8_t *row_1) { - *row_0 = vextq_u16(*row_0, *row_1, 1); - *row_1 = vextq_u16(*row_1, above_right, 1); - vst1q_u16(*dst, *row_0); - *dst += 8; - vst1q_u16(*dst, *row_1); - *dst += stride - 8; + // We want to calculate the AVG3 result in lanes 1-7 inclusive so we can + // shift in above[7] later, so shift a0 across by one to get the right + // inputs: + // [ x, above[0], ... , above[6] ] + ax0 = vextq_u16(a0, a0, 7); + + // d0[0] = x (don't care) + // d0[1] = AVG3(above[0], above[1], above[2]); + // ... + // d0[7] = AVG3(above[6], above[7], above[8]); + d0 = vrhaddq_u16(vhaddq_u16(ax0, a1), a0); + + // Undo the earlier ext, incrementally shift in duplicates of above[7]. + vst1q_u16(dst + 0 * stride, vextq_u16(d0, a7, 1)); + vst1q_u16(dst + 1 * stride, vextq_u16(d0, a7, 2)); + vst1q_u16(dst + 2 * stride, vextq_u16(d0, a7, 3)); + vst1q_u16(dst + 3 * stride, vextq_u16(d0, a7, 4)); + vst1q_u16(dst + 4 * stride, vextq_u16(d0, a7, 5)); + vst1q_u16(dst + 5 * stride, vextq_u16(d0, a7, 6)); + vst1q_u16(dst + 6 * stride, vextq_u16(d0, a7, 7)); + vst1q_u16(dst + 7 * stride, a7); } void vpx_highbd_d45_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x8_t A0_0 = vld1q_u16(above); - const uint16x8_t A0_1 = vld1q_u16(above + 8); - const uint16x8_t above_right = vdupq_lane_u16(vget_high_u16(A0_1), 3); - const uint16x8_t A1_0 = vld1q_u16(above + 1); - const uint16x8_t A1_1 = vld1q_u16(above + 9); - const uint16x8_t A2_0 = vld1q_u16(above + 2); - const uint16x8_t A2_1 = vld1q_u16(above + 10); - const uint16x8_t avg_0 = vhaddq_u16(A0_0, A2_0); - const uint16x8_t avg_1 = vhaddq_u16(A0_1, A2_1); - uint16x8_t row_0 = vrhaddq_u16(avg_0, A1_0); - uint16x8_t row_1 = vrhaddq_u16(avg_1, A1_1); + uint16x8_t ax0, a0, a1, a7, a8, a9, a15, d0[2]; (void)left; (void)bd; - vst1q_u16(dst, row_0); - vst1q_u16(dst + 8, row_1); - dst += stride; - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - d45_store_16(&dst, stride, above_right, &row_0, &row_1); - vst1q_u16(dst, above_right); - vst1q_u16(dst + 8, above_right); + a0 = vld1q_u16(above + 0); + a1 = vld1q_u16(above + 1); + a7 = vld1q_u16(above + 7); + a8 = vld1q_u16(above + 8); + a9 = vld1q_u16(above + 9); + a15 = vld1q_dup_u16(above + 15); + + // [ x, above[0], ... , above[6] ] + ax0 = vextq_u16(a0, a0, 7); + + // We have one unused lane here to leave room to shift in above[15] in the + // last lane: + // d0[0][1] = x (don't care) + // d0[0][1] = AVG3(above[0], above[1], above[2]); + // ... + // d0[0][7] = AVG3(above[6], above[7], above[8]); + // d0[1][0] = AVG3(above[7], above[8], above[9]); + // ... + // d0[1][7] = AVG3(above[14], above[15], above[16]); + d0[0] = vrhaddq_u16(vhaddq_u16(ax0, a1), a0); + d0[1] = vrhaddq_u16(vhaddq_u16(a7, a9), a8); + + // Incrementally shift in duplicates of above[15]. + vst1q_u16(dst + 0 * stride + 0, vextq_u16(d0[0], d0[1], 1)); + vst1q_u16(dst + 0 * stride + 8, vextq_u16(d0[1], a15, 1)); + vst1q_u16(dst + 1 * stride + 0, vextq_u16(d0[0], d0[1], 2)); + vst1q_u16(dst + 1 * stride + 8, vextq_u16(d0[1], a15, 2)); + vst1q_u16(dst + 2 * stride + 0, vextq_u16(d0[0], d0[1], 3)); + vst1q_u16(dst + 2 * stride + 8, vextq_u16(d0[1], a15, 3)); + vst1q_u16(dst + 3 * stride + 0, vextq_u16(d0[0], d0[1], 4)); + vst1q_u16(dst + 3 * stride + 8, vextq_u16(d0[1], a15, 4)); + vst1q_u16(dst + 4 * stride + 0, vextq_u16(d0[0], d0[1], 5)); + vst1q_u16(dst + 4 * stride + 8, vextq_u16(d0[1], a15, 5)); + vst1q_u16(dst + 5 * stride + 0, vextq_u16(d0[0], d0[1], 6)); + vst1q_u16(dst + 5 * stride + 8, vextq_u16(d0[1], a15, 6)); + vst1q_u16(dst + 6 * stride + 0, vextq_u16(d0[0], d0[1], 7)); + vst1q_u16(dst + 6 * stride + 8, vextq_u16(d0[1], a15, 7)); + vst1q_u16(dst + 7 * stride + 0, d0[1]); + vst1q_u16(dst + 7 * stride + 8, a15); + + vst1q_u16(dst + 8 * stride + 0, vextq_u16(d0[1], a15, 1)); + vst1q_u16(dst + 8 * stride + 8, a15); + vst1q_u16(dst + 9 * stride + 0, vextq_u16(d0[1], a15, 2)); + vst1q_u16(dst + 9 * stride + 8, a15); + vst1q_u16(dst + 10 * stride + 0, vextq_u16(d0[1], a15, 3)); + vst1q_u16(dst + 10 * stride + 8, a15); + vst1q_u16(dst + 11 * stride + 0, vextq_u16(d0[1], a15, 4)); + vst1q_u16(dst + 11 * stride + 8, a15); + vst1q_u16(dst + 12 * stride + 0, vextq_u16(d0[1], a15, 5)); + vst1q_u16(dst + 12 * stride + 8, a15); + vst1q_u16(dst + 13 * stride + 0, vextq_u16(d0[1], a15, 6)); + vst1q_u16(dst + 13 * stride + 8, a15); + vst1q_u16(dst + 14 * stride + 0, vextq_u16(d0[1], a15, 7)); + vst1q_u16(dst + 14 * stride + 8, a15); + vst1q_u16(dst + 15 * stride + 0, a15); + vst1q_u16(dst + 15 * stride + 8, a15); } void vpx_highbd_d45_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x8_t A0_0 = vld1q_u16(above); - const uint16x8_t A0_1 = vld1q_u16(above + 8); - const uint16x8_t A0_2 = vld1q_u16(above + 16); - const uint16x8_t A0_3 = vld1q_u16(above + 24); - const uint16x8_t above_right = vdupq_lane_u16(vget_high_u16(A0_3), 3); - const uint16x8_t A1_0 = vld1q_u16(above + 1); - const uint16x8_t A1_1 = vld1q_u16(above + 9); - const uint16x8_t A1_2 = vld1q_u16(above + 17); - const uint16x8_t A1_3 = vld1q_u16(above + 25); - const uint16x8_t A2_0 = vld1q_u16(above + 2); - const uint16x8_t A2_1 = vld1q_u16(above + 10); - const uint16x8_t A2_2 = vld1q_u16(above + 18); - const uint16x8_t A2_3 = vld1q_u16(above + 26); - const uint16x8_t avg_0 = vhaddq_u16(A0_0, A2_0); - const uint16x8_t avg_1 = vhaddq_u16(A0_1, A2_1); - const uint16x8_t avg_2 = vhaddq_u16(A0_2, A2_2); - const uint16x8_t avg_3 = vhaddq_u16(A0_3, A2_3); - uint16x8_t row_0 = vrhaddq_u16(avg_0, A1_0); - uint16x8_t row_1 = vrhaddq_u16(avg_1, A1_1); - uint16x8_t row_2 = vrhaddq_u16(avg_2, A1_2); - uint16x8_t row_3 = vrhaddq_u16(avg_3, A1_3); + uint16x8_t ax0, a0, a1, a7, a8, a9, a15, a16, a17, a23, a24, a25, a31, d0[4]; int i; (void)left; (void)bd; - vst1q_u16(dst, row_0); - dst += 8; - vst1q_u16(dst, row_1); - dst += 8; - vst1q_u16(dst, row_2); - dst += 8; - vst1q_u16(dst, row_3); - dst += stride - 24; + a0 = vld1q_u16(above + 0); + a1 = vld1q_u16(above + 1); + a7 = vld1q_u16(above + 7); + a8 = vld1q_u16(above + 8); + a9 = vld1q_u16(above + 9); + a15 = vld1q_u16(above + 15); + a16 = vld1q_u16(above + 16); + a17 = vld1q_u16(above + 17); + a23 = vld1q_u16(above + 23); + a24 = vld1q_u16(above + 24); + a25 = vld1q_u16(above + 25); + a31 = vld1q_dup_u16(above + 31); - for (i = 0; i < 30; ++i) { - row_0 = vextq_u16(row_0, row_1, 1); - row_1 = vextq_u16(row_1, row_2, 1); - row_2 = vextq_u16(row_2, row_3, 1); - row_3 = vextq_u16(row_3, above_right, 1); - vst1q_u16(dst, row_0); - dst += 8; - vst1q_u16(dst, row_1); - dst += 8; - vst1q_u16(dst, row_2); - dst += 8; - vst1q_u16(dst, row_3); - dst += stride - 24; + // [ x, above[0], ... , above[6] ] + ax0 = vextq_u16(a0, a0, 7); + + d0[0] = vrhaddq_u16(vhaddq_u16(ax0, a1), a0); + d0[1] = vrhaddq_u16(vhaddq_u16(a7, a9), a8); + d0[2] = vrhaddq_u16(vhaddq_u16(a15, a17), a16); + d0[3] = vrhaddq_u16(vhaddq_u16(a23, a25), a24); + + for (i = 0; i < 32; ++i) { + d0[0] = vextq_u16(d0[0], d0[1], 1); + d0[1] = vextq_u16(d0[1], d0[2], 1); + d0[2] = vextq_u16(d0[2], d0[3], 1); + d0[3] = vextq_u16(d0[3], a31, 1); + vst1q_u16(dst + 0, d0[0]); + vst1q_u16(dst + 8, d0[1]); + vst1q_u16(dst + 16, d0[2]); + vst1q_u16(dst + 24, d0[3]); + dst += stride; } +} - vst1q_u16(dst, above_right); - dst += 8; - vst1q_u16(dst, above_right); - dst += 8; - vst1q_u16(dst, above_right); - dst += 8; - vst1q_u16(dst, above_right); +// ----------------------------------------------------------------------------- + +void vpx_highbd_d63_predictor_4x4_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + uint16x4_t a0, a1, a2, a3, d0, d1, d2, d3; + (void)left; + (void)bd; + + a0 = vld1_u16(above + 0); + a1 = vld1_u16(above + 1); + a2 = vld1_u16(above + 2); + a3 = vld1_u16(above + 3); + + d0 = vrhadd_u16(a0, a1); + d1 = vrhadd_u16(vhadd_u16(a0, a2), a1); + d2 = vrhadd_u16(a1, a2); + d3 = vrhadd_u16(vhadd_u16(a1, a3), a2); + + // Note that here we are performing a full avg calculation for the final + // elements rather than storing a duplicate of above[3], which differs + // (correctly) from the general scheme employed by the bs={8,16,32} + // implementations in order to match the original C implementation. + vst1_u16(dst + 0 * stride, d0); + vst1_u16(dst + 1 * stride, d1); + vst1_u16(dst + 2 * stride, d2); + vst1_u16(dst + 3 * stride, d3); +} + +void vpx_highbd_d63_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + uint16x8_t a0, a1, a2, a7, d0, d1, d0_ext, d1_ext; + (void)left; + (void)bd; + + a0 = vld1q_u16(above + 0); + a1 = vld1q_u16(above + 1); + a2 = vld1q_u16(above + 2); + a7 = vld1q_dup_u16(above + 7); + + d0 = vrhaddq_u16(a0, a1); + d1 = vrhaddq_u16(vhaddq_u16(a0, a2), a1); + + // We want to store: + // stride=0 [ d0[0], d0[1], d0[2], d0[3], d0[4], d0[5], d0[6], d0[7] ] + // stride=1 [ d1[0], d1[1], d1[2], d1[3], d1[4], d1[5], d1[6], d1[7] ] + // stride=2 [ d0[1], d0[2], d0[3], d0[4], d0[5], d0[6], a[7], a[7] ] + // stride=3 [ d1[1], d1[2], d1[3], d1[4], d1[5], d1[6], a[7], a[7] ] + // stride=4 [ d0[2], d0[3], d0[4], d0[5], d0[6], a[7], a[7], a[7] ] + // stride=5 [ d1[2], d1[3], d1[4], d1[5], d1[6], a[7], a[7], a[7] ] + // stride=6 [ d0[3], d0[4], d0[5], d0[6], a[7], a[7], a[7], a[7] ] + // stride=7 [ d1[3], d1[4], d1[5], d1[6], a[7], a[7], a[7], a[7] ] + // Note in particular that d0[7] and d1[7] are only ever referenced in the + // stride=0 and stride=1 cases respectively, and in later strides are + // replaced by a copy of above[7]. These are equivalent if for i>7, + // above[i]==above[7], however that is not always the case. + + // Strip out d0[7] and d1[7] so that we can replace it with an additional + // copy of above[7], the first vector here doesn't matter so just reuse + // d0/d1. + d0_ext = vextq_u16(d0, d0, 7); + d1_ext = vextq_u16(d1, d1, 7); + + // Shuffle in duplicates of above[7] and store. + vst1q_u16(dst + 0 * stride, d0); + vst1q_u16(dst + 1 * stride, d1); + vst1q_u16(dst + 2 * stride, vextq_u16(d0_ext, a7, 2)); + vst1q_u16(dst + 3 * stride, vextq_u16(d1_ext, a7, 2)); + vst1q_u16(dst + 4 * stride, vextq_u16(d0_ext, a7, 3)); + vst1q_u16(dst + 5 * stride, vextq_u16(d1_ext, a7, 3)); + vst1q_u16(dst + 6 * stride, vextq_u16(d0_ext, a7, 4)); + vst1q_u16(dst + 7 * stride, vextq_u16(d1_ext, a7, 4)); +} + +void vpx_highbd_d63_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + // See vpx_highbd_d63_predictor_8x8_neon for details on the implementation. + uint16x8_t a0, a1, a2, a8, a9, a10, a15, d0[2], d1[2], d0_ext, d1_ext; + (void)left; + (void)bd; + + a0 = vld1q_u16(above + 0); + a1 = vld1q_u16(above + 1); + a2 = vld1q_u16(above + 2); + a8 = vld1q_u16(above + 8); + a9 = vld1q_u16(above + 9); + a10 = vld1q_u16(above + 10); + a15 = vld1q_dup_u16(above + 15); + + d0[0] = vrhaddq_u16(a0, a1); + d0[1] = vrhaddq_u16(a8, a9); + d1[0] = vrhaddq_u16(vhaddq_u16(a0, a2), a1); + d1[1] = vrhaddq_u16(vhaddq_u16(a8, a10), a9); + + // Strip out the final element of d0/d1 so that we can replace it with an + // additional copy of above[7], the first vector here doesn't matter so just + // reuse the same vector. + d0_ext = vextq_u16(d0[1], d0[1], 7); + d1_ext = vextq_u16(d1[1], d1[1], 7); + + // Shuffle in duplicates of above[7] and store. Note that cases involving + // {d0,d1}_ext require an extra shift to undo the shifting out of the final + // element from above. + vst1q_u16(dst + 0 * stride + 0, d0[0]); + vst1q_u16(dst + 0 * stride + 8, d0[1]); + vst1q_u16(dst + 1 * stride + 0, d1[0]); + vst1q_u16(dst + 1 * stride + 8, d1[1]); + vst1q_u16(dst + 2 * stride + 0, vextq_u16(d0[0], d0[1], 1)); + vst1q_u16(dst + 2 * stride + 8, vextq_u16(d0_ext, a15, 2)); + vst1q_u16(dst + 3 * stride + 0, vextq_u16(d1[0], d1[1], 1)); + vst1q_u16(dst + 3 * stride + 8, vextq_u16(d1_ext, a15, 2)); + vst1q_u16(dst + 4 * stride + 0, vextq_u16(d0[0], d0[1], 2)); + vst1q_u16(dst + 4 * stride + 8, vextq_u16(d0_ext, a15, 3)); + vst1q_u16(dst + 5 * stride + 0, vextq_u16(d1[0], d1[1], 2)); + vst1q_u16(dst + 5 * stride + 8, vextq_u16(d1_ext, a15, 3)); + vst1q_u16(dst + 6 * stride + 0, vextq_u16(d0[0], d0[1], 3)); + vst1q_u16(dst + 6 * stride + 8, vextq_u16(d0_ext, a15, 4)); + vst1q_u16(dst + 7 * stride + 0, vextq_u16(d1[0], d1[1], 3)); + vst1q_u16(dst + 7 * stride + 8, vextq_u16(d1_ext, a15, 4)); + vst1q_u16(dst + 8 * stride + 0, vextq_u16(d0[0], d0[1], 4)); + vst1q_u16(dst + 8 * stride + 8, vextq_u16(d0_ext, a15, 5)); + vst1q_u16(dst + 9 * stride + 0, vextq_u16(d1[0], d1[1], 4)); + vst1q_u16(dst + 9 * stride + 8, vextq_u16(d1_ext, a15, 5)); + vst1q_u16(dst + 10 * stride + 0, vextq_u16(d0[0], d0[1], 5)); + vst1q_u16(dst + 10 * stride + 8, vextq_u16(d0_ext, a15, 6)); + vst1q_u16(dst + 11 * stride + 0, vextq_u16(d1[0], d1[1], 5)); + vst1q_u16(dst + 11 * stride + 8, vextq_u16(d1_ext, a15, 6)); + vst1q_u16(dst + 12 * stride + 0, vextq_u16(d0[0], d0[1], 6)); + vst1q_u16(dst + 12 * stride + 8, vextq_u16(d0_ext, a15, 7)); + vst1q_u16(dst + 13 * stride + 0, vextq_u16(d1[0], d1[1], 6)); + vst1q_u16(dst + 13 * stride + 8, vextq_u16(d1_ext, a15, 7)); + vst1q_u16(dst + 14 * stride + 0, vextq_u16(d0[0], d0[1], 7)); + vst1q_u16(dst + 14 * stride + 8, a15); + vst1q_u16(dst + 15 * stride + 0, vextq_u16(d1[0], d1[1], 7)); + vst1q_u16(dst + 15 * stride + 8, a15); +} + +void vpx_highbd_d63_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + // See vpx_highbd_d63_predictor_8x8_neon for details on the implementation. + uint16x8_t a0, a1, a2, a8, a9, a10, a16, a17, a18, a24, a25, a26, a31, d0[4], + d1[4], d0_ext, d1_ext; + (void)left; + (void)bd; + + a0 = vld1q_u16(above + 0); + a1 = vld1q_u16(above + 1); + a2 = vld1q_u16(above + 2); + a8 = vld1q_u16(above + 8); + a9 = vld1q_u16(above + 9); + a10 = vld1q_u16(above + 10); + a16 = vld1q_u16(above + 16); + a17 = vld1q_u16(above + 17); + a18 = vld1q_u16(above + 18); + a24 = vld1q_u16(above + 24); + a25 = vld1q_u16(above + 25); + a26 = vld1q_u16(above + 26); + a31 = vld1q_dup_u16(above + 31); + + d0[0] = vrhaddq_u16(a0, a1); + d0[1] = vrhaddq_u16(a8, a9); + d0[2] = vrhaddq_u16(a16, a17); + d0[3] = vrhaddq_u16(a24, a25); + d1[0] = vrhaddq_u16(vhaddq_u16(a0, a2), a1); + d1[1] = vrhaddq_u16(vhaddq_u16(a8, a10), a9); + d1[2] = vrhaddq_u16(vhaddq_u16(a16, a18), a17); + d1[3] = vrhaddq_u16(vhaddq_u16(a24, a26), a25); + + // Strip out the final element of d0/d1 so that we can replace it with an + // additional copy of above[7], the first vector here doesn't matter so just + // reuse the same vector. + d0_ext = vextq_u16(d0[3], d0[3], 7); + d1_ext = vextq_u16(d1[3], d1[3], 7); + + // Shuffle in duplicates of above[7] and store. Note that cases involving + // {d0,d1}_ext require an extra shift to undo the shifting out of the final + // element from above. + + vst1q_u16(dst + 0 * stride + 0, d0[0]); + vst1q_u16(dst + 0 * stride + 8, d0[1]); + vst1q_u16(dst + 0 * stride + 16, d0[2]); + vst1q_u16(dst + 0 * stride + 24, d0[3]); + vst1q_u16(dst + 1 * stride + 0, d1[0]); + vst1q_u16(dst + 1 * stride + 8, d1[1]); + vst1q_u16(dst + 1 * stride + 16, d1[2]); + vst1q_u16(dst + 1 * stride + 24, d1[3]); + + vst1q_u16(dst + 2 * stride + 0, vextq_u16(d0[0], d0[1], 1)); + vst1q_u16(dst + 2 * stride + 8, vextq_u16(d0[1], d0[2], 1)); + vst1q_u16(dst + 2 * stride + 16, vextq_u16(d0[2], d0[3], 1)); + vst1q_u16(dst + 2 * stride + 24, vextq_u16(d0_ext, a31, 2)); + vst1q_u16(dst + 3 * stride + 0, vextq_u16(d1[0], d1[1], 1)); + vst1q_u16(dst + 3 * stride + 8, vextq_u16(d1[1], d1[2], 1)); + vst1q_u16(dst + 3 * stride + 16, vextq_u16(d1[2], d1[3], 1)); + vst1q_u16(dst + 3 * stride + 24, vextq_u16(d1_ext, a31, 2)); + + vst1q_u16(dst + 4 * stride + 0, vextq_u16(d0[0], d0[1], 2)); + vst1q_u16(dst + 4 * stride + 8, vextq_u16(d0[1], d0[2], 2)); + vst1q_u16(dst + 4 * stride + 16, vextq_u16(d0[2], d0[3], 2)); + vst1q_u16(dst + 4 * stride + 24, vextq_u16(d0_ext, a31, 3)); + vst1q_u16(dst + 5 * stride + 0, vextq_u16(d1[0], d1[1], 2)); + vst1q_u16(dst + 5 * stride + 8, vextq_u16(d1[1], d1[2], 2)); + vst1q_u16(dst + 5 * stride + 16, vextq_u16(d1[2], d1[3], 2)); + vst1q_u16(dst + 5 * stride + 24, vextq_u16(d1_ext, a31, 3)); + + vst1q_u16(dst + 6 * stride + 0, vextq_u16(d0[0], d0[1], 3)); + vst1q_u16(dst + 6 * stride + 8, vextq_u16(d0[1], d0[2], 3)); + vst1q_u16(dst + 6 * stride + 16, vextq_u16(d0[2], d0[3], 3)); + vst1q_u16(dst + 6 * stride + 24, vextq_u16(d0_ext, a31, 4)); + vst1q_u16(dst + 7 * stride + 0, vextq_u16(d1[0], d1[1], 3)); + vst1q_u16(dst + 7 * stride + 8, vextq_u16(d1[1], d1[2], 3)); + vst1q_u16(dst + 7 * stride + 16, vextq_u16(d1[2], d1[3], 3)); + vst1q_u16(dst + 7 * stride + 24, vextq_u16(d1_ext, a31, 4)); + + vst1q_u16(dst + 8 * stride + 0, vextq_u16(d0[0], d0[1], 4)); + vst1q_u16(dst + 8 * stride + 8, vextq_u16(d0[1], d0[2], 4)); + vst1q_u16(dst + 8 * stride + 16, vextq_u16(d0[2], d0[3], 4)); + vst1q_u16(dst + 8 * stride + 24, vextq_u16(d0_ext, a31, 5)); + vst1q_u16(dst + 9 * stride + 0, vextq_u16(d1[0], d1[1], 4)); + vst1q_u16(dst + 9 * stride + 8, vextq_u16(d1[1], d1[2], 4)); + vst1q_u16(dst + 9 * stride + 16, vextq_u16(d1[2], d1[3], 4)); + vst1q_u16(dst + 9 * stride + 24, vextq_u16(d1_ext, a31, 5)); + + vst1q_u16(dst + 10 * stride + 0, vextq_u16(d0[0], d0[1], 5)); + vst1q_u16(dst + 10 * stride + 8, vextq_u16(d0[1], d0[2], 5)); + vst1q_u16(dst + 10 * stride + 16, vextq_u16(d0[2], d0[3], 5)); + vst1q_u16(dst + 10 * stride + 24, vextq_u16(d0_ext, a31, 6)); + vst1q_u16(dst + 11 * stride + 0, vextq_u16(d1[0], d1[1], 5)); + vst1q_u16(dst + 11 * stride + 8, vextq_u16(d1[1], d1[2], 5)); + vst1q_u16(dst + 11 * stride + 16, vextq_u16(d1[2], d1[3], 5)); + vst1q_u16(dst + 11 * stride + 24, vextq_u16(d1_ext, a31, 6)); + + vst1q_u16(dst + 12 * stride + 0, vextq_u16(d0[0], d0[1], 6)); + vst1q_u16(dst + 12 * stride + 8, vextq_u16(d0[1], d0[2], 6)); + vst1q_u16(dst + 12 * stride + 16, vextq_u16(d0[2], d0[3], 6)); + vst1q_u16(dst + 12 * stride + 24, vextq_u16(d0_ext, a31, 7)); + vst1q_u16(dst + 13 * stride + 0, vextq_u16(d1[0], d1[1], 6)); + vst1q_u16(dst + 13 * stride + 8, vextq_u16(d1[1], d1[2], 6)); + vst1q_u16(dst + 13 * stride + 16, vextq_u16(d1[2], d1[3], 6)); + vst1q_u16(dst + 13 * stride + 24, vextq_u16(d1_ext, a31, 7)); + + vst1q_u16(dst + 14 * stride + 0, vextq_u16(d0[0], d0[1], 7)); + vst1q_u16(dst + 14 * stride + 8, vextq_u16(d0[1], d0[2], 7)); + vst1q_u16(dst + 14 * stride + 16, vextq_u16(d0[2], d0[3], 7)); + vst1q_u16(dst + 14 * stride + 24, a31); + vst1q_u16(dst + 15 * stride + 0, vextq_u16(d1[0], d1[1], 7)); + vst1q_u16(dst + 15 * stride + 8, vextq_u16(d1[1], d1[2], 7)); + vst1q_u16(dst + 15 * stride + 16, vextq_u16(d1[2], d1[3], 7)); + vst1q_u16(dst + 15 * stride + 24, a31); + + vst1q_u16(dst + 16 * stride + 0, d0[1]); + vst1q_u16(dst + 16 * stride + 8, d0[2]); + vst1q_u16(dst + 16 * stride + 16, vextq_u16(d0_ext, a31, 1)); + vst1q_u16(dst + 16 * stride + 24, a31); + vst1q_u16(dst + 17 * stride + 0, d1[1]); + vst1q_u16(dst + 17 * stride + 8, d1[2]); + vst1q_u16(dst + 17 * stride + 16, vextq_u16(d1_ext, a31, 1)); + vst1q_u16(dst + 17 * stride + 24, a31); + + vst1q_u16(dst + 18 * stride + 0, vextq_u16(d0[1], d0[2], 1)); + vst1q_u16(dst + 18 * stride + 8, vextq_u16(d0[2], d0[3], 1)); + vst1q_u16(dst + 18 * stride + 16, vextq_u16(d0_ext, a31, 2)); + vst1q_u16(dst + 18 * stride + 24, a31); + vst1q_u16(dst + 19 * stride + 0, vextq_u16(d1[1], d1[2], 1)); + vst1q_u16(dst + 19 * stride + 8, vextq_u16(d1[2], d1[3], 1)); + vst1q_u16(dst + 19 * stride + 16, vextq_u16(d1_ext, a31, 2)); + vst1q_u16(dst + 19 * stride + 24, a31); + + vst1q_u16(dst + 20 * stride + 0, vextq_u16(d0[1], d0[2], 2)); + vst1q_u16(dst + 20 * stride + 8, vextq_u16(d0[2], d0[3], 2)); + vst1q_u16(dst + 20 * stride + 16, vextq_u16(d0_ext, a31, 3)); + vst1q_u16(dst + 20 * stride + 24, a31); + vst1q_u16(dst + 21 * stride + 0, vextq_u16(d1[1], d1[2], 2)); + vst1q_u16(dst + 21 * stride + 8, vextq_u16(d1[2], d1[3], 2)); + vst1q_u16(dst + 21 * stride + 16, vextq_u16(d1_ext, a31, 3)); + vst1q_u16(dst + 21 * stride + 24, a31); + + vst1q_u16(dst + 22 * stride + 0, vextq_u16(d0[1], d0[2], 3)); + vst1q_u16(dst + 22 * stride + 8, vextq_u16(d0[2], d0[3], 3)); + vst1q_u16(dst + 22 * stride + 16, vextq_u16(d0_ext, a31, 4)); + vst1q_u16(dst + 22 * stride + 24, a31); + vst1q_u16(dst + 23 * stride + 0, vextq_u16(d1[1], d1[2], 3)); + vst1q_u16(dst + 23 * stride + 8, vextq_u16(d1[2], d1[3], 3)); + vst1q_u16(dst + 23 * stride + 16, vextq_u16(d1_ext, a31, 4)); + vst1q_u16(dst + 23 * stride + 24, a31); + + vst1q_u16(dst + 24 * stride + 0, vextq_u16(d0[1], d0[2], 4)); + vst1q_u16(dst + 24 * stride + 8, vextq_u16(d0[2], d0[3], 4)); + vst1q_u16(dst + 24 * stride + 16, vextq_u16(d0_ext, a31, 5)); + vst1q_u16(dst + 24 * stride + 24, a31); + vst1q_u16(dst + 25 * stride + 0, vextq_u16(d1[1], d1[2], 4)); + vst1q_u16(dst + 25 * stride + 8, vextq_u16(d1[2], d1[3], 4)); + vst1q_u16(dst + 25 * stride + 16, vextq_u16(d1_ext, a31, 5)); + vst1q_u16(dst + 25 * stride + 24, a31); + + vst1q_u16(dst + 26 * stride + 0, vextq_u16(d0[1], d0[2], 5)); + vst1q_u16(dst + 26 * stride + 8, vextq_u16(d0[2], d0[3], 5)); + vst1q_u16(dst + 26 * stride + 16, vextq_u16(d0_ext, a31, 6)); + vst1q_u16(dst + 26 * stride + 24, a31); + vst1q_u16(dst + 27 * stride + 0, vextq_u16(d1[1], d1[2], 5)); + vst1q_u16(dst + 27 * stride + 8, vextq_u16(d1[2], d1[3], 5)); + vst1q_u16(dst + 27 * stride + 16, vextq_u16(d1_ext, a31, 6)); + vst1q_u16(dst + 27 * stride + 24, a31); + + vst1q_u16(dst + 28 * stride + 0, vextq_u16(d0[1], d0[2], 6)); + vst1q_u16(dst + 28 * stride + 8, vextq_u16(d0[2], d0[3], 6)); + vst1q_u16(dst + 28 * stride + 16, vextq_u16(d0_ext, a31, 7)); + vst1q_u16(dst + 28 * stride + 24, a31); + vst1q_u16(dst + 29 * stride + 0, vextq_u16(d1[1], d1[2], 6)); + vst1q_u16(dst + 29 * stride + 8, vextq_u16(d1[2], d1[3], 6)); + vst1q_u16(dst + 29 * stride + 16, vextq_u16(d1_ext, a31, 7)); + vst1q_u16(dst + 29 * stride + 24, a31); + + vst1q_u16(dst + 30 * stride + 0, vextq_u16(d0[1], d0[2], 7)); + vst1q_u16(dst + 30 * stride + 8, vextq_u16(d0[2], d0[3], 7)); + vst1q_u16(dst + 30 * stride + 16, a31); + vst1q_u16(dst + 30 * stride + 24, a31); + vst1q_u16(dst + 31 * stride + 0, vextq_u16(d1[1], d1[2], 7)); + vst1q_u16(dst + 31 * stride + 8, vextq_u16(d1[2], d1[3], 7)); + vst1q_u16(dst + 31 * stride + 16, a31); + vst1q_u16(dst + 31 * stride + 24, a31); +} + +// ----------------------------------------------------------------------------- + +void vpx_highbd_d117_predictor_4x4_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + uint16x4_t az, a0, l0az, l0, l1, azl0, col0, col0_even, col0_odd, d0, d1; + (void)bd; + + az = vld1_u16(above - 1); + a0 = vld1_u16(above + 0); + // [ left[0], above[-1], above[0], above[1] ] + l0az = vext_u16(vld1_dup_u16(left), az, 3); + + l0 = vld1_u16(left + 0); + // The last lane here is unused, reading left[4] could cause a buffer + // over-read, so just fill with a duplicate of left[0] to avoid needing to + // materialize a zero: + // [ left[1], left[2], left[3], x ] + l1 = vext_u16(l0, l0, 1); + // [ above[-1], left[0], left[1], left[2] ] + azl0 = vext_u16(vld1_dup_u16(above - 1), l0, 3); + + d0 = vrhadd_u16(az, a0); + d1 = vrhadd_u16(vhadd_u16(l0az, a0), az); + + col0 = vrhadd_u16(vhadd_u16(azl0, l1), l0); + col0_even = vdup_lane_u16(col0, 0); + col0_odd = vdup_lane_u16(col0, 1); + + vst1_u16(dst + 0 * stride, d0); + vst1_u16(dst + 1 * stride, d1); + vst1_u16(dst + 2 * stride, vext_u16(col0_even, d0, 3)); + vst1_u16(dst + 3 * stride, vext_u16(col0_odd, d1, 3)); +} + +void vpx_highbd_d117_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + uint16x8_t az, a0, l0az, l0, l1, azl0, col0, col0_even, col0_odd, d0, d1; + (void)bd; + + az = vld1q_u16(above - 1); + a0 = vld1q_u16(above + 0); + // [ left[0], above[-1], ..., left[5] ] + l0az = vextq_u16(vld1q_dup_u16(left), az, 7); + + l0 = vld1q_u16(left + 0); + // The last lane here is unused, reading left[8] could cause a buffer + // over-read, so just fill with a duplicate of left[0] to avoid needing to + // materialize a zero: + // [ left[1], ... , left[7], x ] + l1 = vextq_u16(l0, l0, 1); + // [ above[-1], left[0], ..., left[6] ] + azl0 = vextq_u16(vld1q_dup_u16(above - 1), l0, 7); + + // d0[0] = AVG2(above[-1], above[0]) + // ... + // d0[7] = AVG2(above[6], above[7]) + d0 = vrhaddq_u16(az, a0); + + // d1[0] = AVG3(left[0], above[-1], above[0]) + // d1[1] = AVG3(above[-1], above[0], above[1]) + // ... + // d1[7] = AVG3(above[5], above[6], above[7]) + d1 = vrhaddq_u16(vhaddq_u16(l0az, a0), az); + + // The ext instruction shifts elements in from the end of the vector rather + // than the start, so reverse the vector to put the elements to be shifted in + // at the end: + // col0[7] = AVG3(above[-1], left[0], left[1]) + // col0[6] = AVG3(left[0], left[1], left[2]) + // ... + // col0[0] = AVG3(left[6], left[7], left[8]) + col0 = vrhaddq_u16(vhaddq_u16(azl0, l1), l0); + col0 = vrev64q_u16(vextq_u16(col0, col0, 4)); + + // We don't care about the first parameter to this uzp since we only ever use + // the high three elements, we just use col0 again since it is already + // available: + // col0_even = [ x, x, x, x, x, col0[3], col0[5], col0[7] ] + // col0_odd = [ x, x, x, x, x, col0[2], col0[4], col0[6] ] + col0_even = vuzpq_u16(col0, col0).val[1]; + col0_odd = vuzpq_u16(col0, col0).val[0]; + + // Incrementally shift more elements from col0 into d0/1: + // stride=0 [ d0[0], d0[1], d0[2], d0[3], d0[4], d0[5], d0[6], d0[7] ] + // stride=1 [ d1[0], d1[1], d1[2], d1[3], d1[4], d1[5], d1[6], d1[7] ] + // stride=2 [ col0[7], d0[0], d0[1], d0[2], d0[3], d0[4], d0[5], d0[6] ] + // stride=3 [ col0[6], d1[0], d1[1], d1[2], d1[3], d1[4], d1[5], d1[6] ] + // stride=4 [ col0[5], col0[7], d0[0], d0[1], d0[2], d0[3], d0[4], d0[5] ] + // stride=5 [ col0[4], col0[6], d1[0], d1[1], d1[2], d1[3], d1[4], d1[5] ] + // stride=6 [ col0[3], col0[5], col0[7], d0[0], d0[1], d0[2], d0[3], d0[4] ] + // stride=7 [ col0[2], col0[4], col0[6], d1[0], d1[1], d1[2], d1[3], d1[4] ] + vst1q_u16(dst + 0 * stride, d0); + vst1q_u16(dst + 1 * stride, d1); + vst1q_u16(dst + 2 * stride, vextq_u16(col0_even, d0, 7)); + vst1q_u16(dst + 3 * stride, vextq_u16(col0_odd, d1, 7)); + vst1q_u16(dst + 4 * stride, vextq_u16(col0_even, d0, 6)); + vst1q_u16(dst + 5 * stride, vextq_u16(col0_odd, d1, 6)); + vst1q_u16(dst + 6 * stride, vextq_u16(col0_even, d0, 5)); + vst1q_u16(dst + 7 * stride, vextq_u16(col0_odd, d1, 5)); +} + +void vpx_highbd_d117_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + uint16x8_t az, a0, a6, a7, a8, l0az, l0, l1, l7, l8, l9, azl0, col0_lo, + col0_hi, col0_even, col0_odd, d0_lo, d0_hi, d1_lo, d1_hi; + (void)bd; + + az = vld1q_u16(above - 1); + a0 = vld1q_u16(above + 0); + a6 = vld1q_u16(above + 6); + a7 = vld1q_u16(above + 7); + a8 = vld1q_u16(above + 8); + // [ left[0], above[-1], ..., left[5] ] + l0az = vextq_u16(vld1q_dup_u16(left), az, 7); + + l0 = vld1q_u16(left + 0); + l1 = vld1q_u16(left + 1); + l7 = vld1q_u16(left + 7); + l8 = vld1q_u16(left + 8); + // The last lane here is unused, reading left[16] could cause a buffer + // over-read, so just fill with a duplicate of left[8] to avoid needing to + // materialize a zero: + // [ left[9], ... , left[15], x ] + l9 = vextq_u16(l8, l8, 1); + // [ above[-1], left[0], ..., left[6] ] + azl0 = vextq_u16(vld1q_dup_u16(above - 1), l0, 7); + + d0_lo = vrhaddq_u16(az, a0); + d0_hi = vrhaddq_u16(a7, a8); + d1_lo = vrhaddq_u16(vhaddq_u16(l0az, a0), az); + d1_hi = vrhaddq_u16(vhaddq_u16(a6, a8), a7); + + col0_lo = vrhaddq_u16(vhaddq_u16(azl0, l1), l0); + col0_hi = vrhaddq_u16(vhaddq_u16(l7, l9), l8); + + // Reverse within each vector, then swap the array indices in the uzp to + // complete the reversal across all 16 elements. + col0_lo = vrev64q_u16(vextq_u16(col0_lo, col0_lo, 4)); + col0_hi = vrev64q_u16(vextq_u16(col0_hi, col0_hi, 4)); + col0_even = vuzpq_u16(col0_hi, col0_lo).val[1]; + col0_odd = vuzpq_u16(col0_hi, col0_lo).val[0]; + + vst1q_u16(dst + 0 * stride + 0, d0_lo); + vst1q_u16(dst + 0 * stride + 8, d0_hi); + vst1q_u16(dst + 1 * stride + 0, d1_lo); + vst1q_u16(dst + 1 * stride + 8, d1_hi); + + vst1q_u16(dst + 2 * stride + 0, vextq_u16(col0_even, d0_lo, 7)); + vst1q_u16(dst + 2 * stride + 8, vextq_u16(d0_lo, d0_hi, 7)); + vst1q_u16(dst + 3 * stride + 0, vextq_u16(col0_odd, d1_lo, 7)); + vst1q_u16(dst + 3 * stride + 8, vextq_u16(d1_lo, d1_hi, 7)); + + vst1q_u16(dst + 4 * stride + 0, vextq_u16(col0_even, d0_lo, 6)); + vst1q_u16(dst + 4 * stride + 8, vextq_u16(d0_lo, d0_hi, 6)); + vst1q_u16(dst + 5 * stride + 0, vextq_u16(col0_odd, d1_lo, 6)); + vst1q_u16(dst + 5 * stride + 8, vextq_u16(d1_lo, d1_hi, 6)); + + vst1q_u16(dst + 6 * stride + 0, vextq_u16(col0_even, d0_lo, 5)); + vst1q_u16(dst + 6 * stride + 8, vextq_u16(d0_lo, d0_hi, 5)); + vst1q_u16(dst + 7 * stride + 0, vextq_u16(col0_odd, d1_lo, 5)); + vst1q_u16(dst + 7 * stride + 8, vextq_u16(d1_lo, d1_hi, 5)); + + vst1q_u16(dst + 8 * stride + 0, vextq_u16(col0_even, d0_lo, 4)); + vst1q_u16(dst + 8 * stride + 8, vextq_u16(d0_lo, d0_hi, 4)); + vst1q_u16(dst + 9 * stride + 0, vextq_u16(col0_odd, d1_lo, 4)); + vst1q_u16(dst + 9 * stride + 8, vextq_u16(d1_lo, d1_hi, 4)); + + vst1q_u16(dst + 10 * stride + 0, vextq_u16(col0_even, d0_lo, 3)); + vst1q_u16(dst + 10 * stride + 8, vextq_u16(d0_lo, d0_hi, 3)); + vst1q_u16(dst + 11 * stride + 0, vextq_u16(col0_odd, d1_lo, 3)); + vst1q_u16(dst + 11 * stride + 8, vextq_u16(d1_lo, d1_hi, 3)); + + vst1q_u16(dst + 12 * stride + 0, vextq_u16(col0_even, d0_lo, 2)); + vst1q_u16(dst + 12 * stride + 8, vextq_u16(d0_lo, d0_hi, 2)); + vst1q_u16(dst + 13 * stride + 0, vextq_u16(col0_odd, d1_lo, 2)); + vst1q_u16(dst + 13 * stride + 8, vextq_u16(d1_lo, d1_hi, 2)); + + vst1q_u16(dst + 14 * stride + 0, vextq_u16(col0_even, d0_lo, 1)); + vst1q_u16(dst + 14 * stride + 8, vextq_u16(d0_lo, d0_hi, 1)); + vst1q_u16(dst + 15 * stride + 0, vextq_u16(col0_odd, d1_lo, 1)); + vst1q_u16(dst + 15 * stride + 8, vextq_u16(d1_lo, d1_hi, 1)); +} + +void vpx_highbd_d117_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + uint16x8_t az, a0, a6, a7, a8, a14, a15, a16, a22, a23, a24, l0az, l0, l1, l7, + l8, l9, l15, l16, l17, l23, l24, l25, azl0, d0[4], d1[4], col0[4], + col0_even[2], col0_odd[2]; + (void)bd; + + az = vld1q_u16(above - 1); + a0 = vld1q_u16(above + 0); + a6 = vld1q_u16(above + 6); + a7 = vld1q_u16(above + 7); + a8 = vld1q_u16(above + 8); + a14 = vld1q_u16(above + 14); + a15 = vld1q_u16(above + 15); + a16 = vld1q_u16(above + 16); + a22 = vld1q_u16(above + 22); + a23 = vld1q_u16(above + 23); + a24 = vld1q_u16(above + 24); + // [ left[0], above[-1], ..., left[5] ] + l0az = vextq_u16(vld1q_dup_u16(left), az, 7); + + l0 = vld1q_u16(left + 0); + l1 = vld1q_u16(left + 1); + l7 = vld1q_u16(left + 7); + l8 = vld1q_u16(left + 8); + l9 = vld1q_u16(left + 9); + l15 = vld1q_u16(left + 15); + l16 = vld1q_u16(left + 16); + l17 = vld1q_u16(left + 17); + l23 = vld1q_u16(left + 23); + l24 = vld1q_u16(left + 24); + l25 = vld1q_u16(left + 25); + // The last lane here is unused, reading left[32] could cause a buffer + // over-read, so just fill with a duplicate of left[24] to avoid needing to + // materialize a zero: + // [ left[25], ... , left[31], x ] + l25 = vextq_u16(l24, l24, 1); + // [ above[-1], left[0], ..., left[6] ] + azl0 = vextq_u16(vld1q_dup_u16(above - 1), l0, 7); + + d0[0] = vrhaddq_u16(az, a0); + d0[1] = vrhaddq_u16(a7, a8); + d0[2] = vrhaddq_u16(a15, a16); + d0[3] = vrhaddq_u16(a23, a24); + d1[0] = vrhaddq_u16(vhaddq_u16(l0az, a0), az); + d1[1] = vrhaddq_u16(vhaddq_u16(a6, a8), a7); + d1[2] = vrhaddq_u16(vhaddq_u16(a14, a16), a15); + d1[3] = vrhaddq_u16(vhaddq_u16(a22, a24), a23); + + col0[0] = vrhaddq_u16(vhaddq_u16(azl0, l1), l0); + col0[1] = vrhaddq_u16(vhaddq_u16(l7, l9), l8); + col0[2] = vrhaddq_u16(vhaddq_u16(l15, l17), l16); + col0[3] = vrhaddq_u16(vhaddq_u16(l23, l25), l24); + + // Reverse within each vector, then swap the array indices in both the uzp + // and the col0_{even,odd} assignment to complete the reversal across all + // 32-elements. + col0[0] = vrev64q_u16(vextq_u16(col0[0], col0[0], 4)); + col0[1] = vrev64q_u16(vextq_u16(col0[1], col0[1], 4)); + col0[2] = vrev64q_u16(vextq_u16(col0[2], col0[2], 4)); + col0[3] = vrev64q_u16(vextq_u16(col0[3], col0[3], 4)); + + col0_even[1] = vuzpq_u16(col0[1], col0[0]).val[1]; + col0_even[0] = vuzpq_u16(col0[3], col0[2]).val[1]; + col0_odd[1] = vuzpq_u16(col0[1], col0[0]).val[0]; + col0_odd[0] = vuzpq_u16(col0[3], col0[2]).val[0]; + + vst1q_u16(dst + 0 * stride + 0, d0[0]); + vst1q_u16(dst + 0 * stride + 8, d0[1]); + vst1q_u16(dst + 0 * stride + 16, d0[2]); + vst1q_u16(dst + 0 * stride + 24, d0[3]); + vst1q_u16(dst + 1 * stride + 0, d1[0]); + vst1q_u16(dst + 1 * stride + 8, d1[1]); + vst1q_u16(dst + 1 * stride + 16, d1[2]); + vst1q_u16(dst + 1 * stride + 24, d1[3]); + + vst1q_u16(dst + 2 * stride + 0, vextq_u16(col0_even[1], d0[0], 7)); + vst1q_u16(dst + 2 * stride + 8, vextq_u16(d0[0], d0[1], 7)); + vst1q_u16(dst + 2 * stride + 16, vextq_u16(d0[1], d0[2], 7)); + vst1q_u16(dst + 2 * stride + 24, vextq_u16(d0[2], d0[3], 7)); + vst1q_u16(dst + 3 * stride + 0, vextq_u16(col0_odd[1], d1[0], 7)); + vst1q_u16(dst + 3 * stride + 8, vextq_u16(d1[0], d1[1], 7)); + vst1q_u16(dst + 3 * stride + 16, vextq_u16(d1[1], d1[2], 7)); + vst1q_u16(dst + 3 * stride + 24, vextq_u16(d1[2], d1[3], 7)); + + vst1q_u16(dst + 4 * stride + 0, vextq_u16(col0_even[1], d0[0], 6)); + vst1q_u16(dst + 4 * stride + 8, vextq_u16(d0[0], d0[1], 6)); + vst1q_u16(dst + 4 * stride + 16, vextq_u16(d0[1], d0[2], 6)); + vst1q_u16(dst + 4 * stride + 24, vextq_u16(d0[2], d0[3], 6)); + vst1q_u16(dst + 5 * stride + 0, vextq_u16(col0_odd[1], d1[0], 6)); + vst1q_u16(dst + 5 * stride + 8, vextq_u16(d1[0], d1[1], 6)); + vst1q_u16(dst + 5 * stride + 16, vextq_u16(d1[1], d1[2], 6)); + vst1q_u16(dst + 5 * stride + 24, vextq_u16(d1[2], d1[3], 6)); + + vst1q_u16(dst + 6 * stride + 0, vextq_u16(col0_even[1], d0[0], 5)); + vst1q_u16(dst + 6 * stride + 8, vextq_u16(d0[0], d0[1], 5)); + vst1q_u16(dst + 6 * stride + 16, vextq_u16(d0[1], d0[2], 5)); + vst1q_u16(dst + 6 * stride + 24, vextq_u16(d0[2], d0[3], 5)); + vst1q_u16(dst + 7 * stride + 0, vextq_u16(col0_odd[1], d1[0], 5)); + vst1q_u16(dst + 7 * stride + 8, vextq_u16(d1[0], d1[1], 5)); + vst1q_u16(dst + 7 * stride + 16, vextq_u16(d1[1], d1[2], 5)); + vst1q_u16(dst + 7 * stride + 24, vextq_u16(d1[2], d1[3], 5)); + + vst1q_u16(dst + 8 * stride + 0, vextq_u16(col0_even[1], d0[0], 4)); + vst1q_u16(dst + 8 * stride + 8, vextq_u16(d0[0], d0[1], 4)); + vst1q_u16(dst + 8 * stride + 16, vextq_u16(d0[1], d0[2], 4)); + vst1q_u16(dst + 8 * stride + 24, vextq_u16(d0[2], d0[3], 4)); + vst1q_u16(dst + 9 * stride + 0, vextq_u16(col0_odd[1], d1[0], 4)); + vst1q_u16(dst + 9 * stride + 8, vextq_u16(d1[0], d1[1], 4)); + vst1q_u16(dst + 9 * stride + 16, vextq_u16(d1[1], d1[2], 4)); + vst1q_u16(dst + 9 * stride + 24, vextq_u16(d1[2], d1[3], 4)); + + vst1q_u16(dst + 10 * stride + 0, vextq_u16(col0_even[1], d0[0], 3)); + vst1q_u16(dst + 10 * stride + 8, vextq_u16(d0[0], d0[1], 3)); + vst1q_u16(dst + 10 * stride + 16, vextq_u16(d0[1], d0[2], 3)); + vst1q_u16(dst + 10 * stride + 24, vextq_u16(d0[2], d0[3], 3)); + vst1q_u16(dst + 11 * stride + 0, vextq_u16(col0_odd[1], d1[0], 3)); + vst1q_u16(dst + 11 * stride + 8, vextq_u16(d1[0], d1[1], 3)); + vst1q_u16(dst + 11 * stride + 16, vextq_u16(d1[1], d1[2], 3)); + vst1q_u16(dst + 11 * stride + 24, vextq_u16(d1[2], d1[3], 3)); + + vst1q_u16(dst + 12 * stride + 0, vextq_u16(col0_even[1], d0[0], 2)); + vst1q_u16(dst + 12 * stride + 8, vextq_u16(d0[0], d0[1], 2)); + vst1q_u16(dst + 12 * stride + 16, vextq_u16(d0[1], d0[2], 2)); + vst1q_u16(dst + 12 * stride + 24, vextq_u16(d0[2], d0[3], 2)); + vst1q_u16(dst + 13 * stride + 0, vextq_u16(col0_odd[1], d1[0], 2)); + vst1q_u16(dst + 13 * stride + 8, vextq_u16(d1[0], d1[1], 2)); + vst1q_u16(dst + 13 * stride + 16, vextq_u16(d1[1], d1[2], 2)); + vst1q_u16(dst + 13 * stride + 24, vextq_u16(d1[2], d1[3], 2)); + + vst1q_u16(dst + 14 * stride + 0, vextq_u16(col0_even[1], d0[0], 1)); + vst1q_u16(dst + 14 * stride + 8, vextq_u16(d0[0], d0[1], 1)); + vst1q_u16(dst + 14 * stride + 16, vextq_u16(d0[1], d0[2], 1)); + vst1q_u16(dst + 14 * stride + 24, vextq_u16(d0[2], d0[3], 1)); + vst1q_u16(dst + 15 * stride + 0, vextq_u16(col0_odd[1], d1[0], 1)); + vst1q_u16(dst + 15 * stride + 8, vextq_u16(d1[0], d1[1], 1)); + vst1q_u16(dst + 15 * stride + 16, vextq_u16(d1[1], d1[2], 1)); + vst1q_u16(dst + 15 * stride + 24, vextq_u16(d1[2], d1[3], 1)); + + vst1q_u16(dst + 16 * stride + 0, col0_even[1]); + vst1q_u16(dst + 16 * stride + 8, d0[0]); + vst1q_u16(dst + 16 * stride + 16, d0[1]); + vst1q_u16(dst + 16 * stride + 24, d0[2]); + vst1q_u16(dst + 17 * stride + 0, col0_odd[1]); + vst1q_u16(dst + 17 * stride + 8, d1[0]); + vst1q_u16(dst + 17 * stride + 16, d1[1]); + vst1q_u16(dst + 17 * stride + 24, d1[2]); + + vst1q_u16(dst + 18 * stride + 0, vextq_u16(col0_even[0], col0_even[1], 7)); + vst1q_u16(dst + 18 * stride + 8, vextq_u16(col0_even[1], d0[0], 7)); + vst1q_u16(dst + 18 * stride + 16, vextq_u16(d0[0], d0[1], 7)); + vst1q_u16(dst + 18 * stride + 24, vextq_u16(d0[1], d0[2], 7)); + vst1q_u16(dst + 19 * stride + 0, vextq_u16(col0_odd[0], col0_odd[1], 7)); + vst1q_u16(dst + 19 * stride + 8, vextq_u16(col0_odd[1], d1[0], 7)); + vst1q_u16(dst + 19 * stride + 16, vextq_u16(d1[0], d1[1], 7)); + vst1q_u16(dst + 19 * stride + 24, vextq_u16(d1[1], d1[2], 7)); + + vst1q_u16(dst + 20 * stride + 0, vextq_u16(col0_even[0], col0_even[1], 6)); + vst1q_u16(dst + 20 * stride + 8, vextq_u16(col0_even[1], d0[0], 6)); + vst1q_u16(dst + 20 * stride + 16, vextq_u16(d0[0], d0[1], 6)); + vst1q_u16(dst + 20 * stride + 24, vextq_u16(d0[1], d0[2], 6)); + vst1q_u16(dst + 21 * stride + 0, vextq_u16(col0_odd[0], col0_odd[1], 6)); + vst1q_u16(dst + 21 * stride + 8, vextq_u16(col0_odd[1], d1[0], 6)); + vst1q_u16(dst + 21 * stride + 16, vextq_u16(d1[0], d1[1], 6)); + vst1q_u16(dst + 21 * stride + 24, vextq_u16(d1[1], d1[2], 6)); + + vst1q_u16(dst + 22 * stride + 0, vextq_u16(col0_even[0], col0_even[1], 5)); + vst1q_u16(dst + 22 * stride + 8, vextq_u16(col0_even[1], d0[0], 5)); + vst1q_u16(dst + 22 * stride + 16, vextq_u16(d0[0], d0[1], 5)); + vst1q_u16(dst + 22 * stride + 24, vextq_u16(d0[1], d0[2], 5)); + vst1q_u16(dst + 23 * stride + 0, vextq_u16(col0_odd[0], col0_odd[1], 5)); + vst1q_u16(dst + 23 * stride + 8, vextq_u16(col0_odd[1], d1[0], 5)); + vst1q_u16(dst + 23 * stride + 16, vextq_u16(d1[0], d1[1], 5)); + vst1q_u16(dst + 23 * stride + 24, vextq_u16(d1[1], d1[2], 5)); + + vst1q_u16(dst + 24 * stride + 0, vextq_u16(col0_even[0], col0_even[1], 4)); + vst1q_u16(dst + 24 * stride + 8, vextq_u16(col0_even[1], d0[0], 4)); + vst1q_u16(dst + 24 * stride + 16, vextq_u16(d0[0], d0[1], 4)); + vst1q_u16(dst + 24 * stride + 24, vextq_u16(d0[1], d0[2], 4)); + vst1q_u16(dst + 25 * stride + 0, vextq_u16(col0_odd[0], col0_odd[1], 4)); + vst1q_u16(dst + 25 * stride + 8, vextq_u16(col0_odd[1], d1[0], 4)); + vst1q_u16(dst + 25 * stride + 16, vextq_u16(d1[0], d1[1], 4)); + vst1q_u16(dst + 25 * stride + 24, vextq_u16(d1[1], d1[2], 4)); + + vst1q_u16(dst + 26 * stride + 0, vextq_u16(col0_even[0], col0_even[1], 3)); + vst1q_u16(dst + 26 * stride + 8, vextq_u16(col0_even[1], d0[0], 3)); + vst1q_u16(dst + 26 * stride + 16, vextq_u16(d0[0], d0[1], 3)); + vst1q_u16(dst + 26 * stride + 24, vextq_u16(d0[1], d0[2], 3)); + vst1q_u16(dst + 27 * stride + 0, vextq_u16(col0_odd[0], col0_odd[1], 3)); + vst1q_u16(dst + 27 * stride + 8, vextq_u16(col0_odd[1], d1[0], 3)); + vst1q_u16(dst + 27 * stride + 16, vextq_u16(d1[0], d1[1], 3)); + vst1q_u16(dst + 27 * stride + 24, vextq_u16(d1[1], d1[2], 3)); + + vst1q_u16(dst + 28 * stride + 0, vextq_u16(col0_even[0], col0_even[1], 2)); + vst1q_u16(dst + 28 * stride + 8, vextq_u16(col0_even[1], d0[0], 2)); + vst1q_u16(dst + 28 * stride + 16, vextq_u16(d0[0], d0[1], 2)); + vst1q_u16(dst + 28 * stride + 24, vextq_u16(d0[1], d0[2], 2)); + vst1q_u16(dst + 29 * stride + 0, vextq_u16(col0_odd[0], col0_odd[1], 2)); + vst1q_u16(dst + 29 * stride + 8, vextq_u16(col0_odd[1], d1[0], 2)); + vst1q_u16(dst + 29 * stride + 16, vextq_u16(d1[0], d1[1], 2)); + vst1q_u16(dst + 29 * stride + 24, vextq_u16(d1[1], d1[2], 2)); + + vst1q_u16(dst + 30 * stride + 0, vextq_u16(col0_even[0], col0_even[1], 1)); + vst1q_u16(dst + 30 * stride + 8, vextq_u16(col0_even[1], d0[0], 1)); + vst1q_u16(dst + 30 * stride + 16, vextq_u16(d0[0], d0[1], 1)); + vst1q_u16(dst + 30 * stride + 24, vextq_u16(d0[1], d0[2], 1)); + vst1q_u16(dst + 31 * stride + 0, vextq_u16(col0_odd[0], col0_odd[1], 1)); + vst1q_u16(dst + 31 * stride + 8, vextq_u16(col0_odd[1], d1[0], 1)); + vst1q_u16(dst + 31 * stride + 16, vextq_u16(d1[0], d1[1], 1)); + vst1q_u16(dst + 31 * stride + 24, vextq_u16(d1[1], d1[2], 1)); +} + +// ----------------------------------------------------------------------------- + +void vpx_highbd_d153_predictor_4x4_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + // See vpx_highbd_d153_predictor_8x8_neon for details on the implementation. + uint16x4_t az, a0, l0az, l0, l1, azl0, d0, d1, d2, d20_lo, d20_hi; + (void)bd; + + az = vld1_u16(above - 1); + a0 = vld1_u16(above + 0); + // [ left[0], above[-1], above[0], above[1] ] + l0az = vext_u16(vld1_dup_u16(left), az, 3); + + l0 = vld1_u16(left); + // The last lane here is unused, reading left[4] could cause a buffer + // over-read, so just fill with a duplicate of left[0] to avoid needing to + // materialize a zero: + // [ left[1], left[2], left[3], x ] + l1 = vext_u16(l0, l0, 1); + // [ above[-1], left[0], left[1], left[2] ] + azl0 = vext_u16(vld1_dup_u16(above - 1), l0, 3); + + d0 = vrhadd_u16(azl0, l0); + d1 = vrhadd_u16(vhadd_u16(l0az, a0), az); + d2 = vrhadd_u16(vhadd_u16(azl0, l1), l0); + + d20_lo = vzip_u16(vrev64_u16(d2), vrev64_u16(d0)).val[0]; + d20_hi = vzip_u16(vrev64_u16(d2), vrev64_u16(d0)).val[1]; + + // Incrementally shift more elements from d0/d2 reversed into d1: + // stride=0 [ d0[0], d1[0], d1[1], d1[2] ] + // stride=1 [ d0[1], d2[0], d0[0], d1[0] ] + // stride=2 [ d0[2], d2[1], d0[1], d2[0] ] + // stride=3 [ d0[3], d2[2], d0[2], d2[1] ] + vst1_u16(dst + 0 * stride, vext_u16(d20_hi, d1, 3)); + vst1_u16(dst + 1 * stride, vext_u16(d20_hi, d1, 1)); + vst1_u16(dst + 2 * stride, vext_u16(d20_lo, d20_hi, 3)); + vst1_u16(dst + 3 * stride, vext_u16(d20_lo, d20_hi, 1)); +} + +void vpx_highbd_d153_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + uint16x8_t az, a0, l0az, l0, l1, azl0, d0, d1, d2, d0_rev, d2_rev, d20_lo, + d20_hi; + (void)bd; + + az = vld1q_u16(above - 1); + a0 = vld1q_u16(above + 0); + // [ left[0], above[-1], ... , above[5] ] + l0az = vextq_u16(vld1q_dup_u16(left), az, 7); + + l0 = vld1q_u16(left); + // The last lane here is unused, reading left[8] could cause a buffer + // over-read, so just fill with a duplicate of left[0] to avoid needing to + // materialize a zero: + // [ left[1], ... , left[7], x ] + l1 = vextq_u16(l0, l0, 1); + // [ above[-1], left[0], ... , left[6] ] + azl0 = vextq_u16(vld1q_dup_u16(above - 1), l0, 7); + + // d0[0] = AVG2(above[-1], left[0]) + // d0[1] = AVG2(left[0], left[1]) + // ... + // d0[7] = AVG2(left[6], left[7]) + d0 = vrhaddq_u16(azl0, l0); + + // d1[0] = AVG3(left[0], above[-1], above[0]) + // d1[1] = AVG3(above[-1], above[0], above[1]) + // ... + // d1[7] = AVG3(above[5], above[6], above[7]) + d1 = vrhaddq_u16(vhaddq_u16(l0az, a0), az); + + // d2[0] = AVG3(above[-1], left[0], left[1]) + // d2[1] = AVG3(left[0], left[1], left[2]) + // ... + // d2[7] = AVG3(left[6], left[7], left[8]) + d2 = vrhaddq_u16(vhaddq_u16(azl0, l1), l0); + + // The ext instruction shifts elements in from the end of the vector rather + // than the start, so reverse the vectors to put the elements to be shifted + // in at the end: + d0_rev = vrev64q_u16(vextq_u16(d0, d0, 4)); + d2_rev = vrev64q_u16(vextq_u16(d2, d2, 4)); + + d20_lo = vzipq_u16(d2_rev, d0_rev).val[0]; + d20_hi = vzipq_u16(d2_rev, d0_rev).val[1]; + + // Incrementally shift more elements from d0/d2 reversed into d1: + // stride=0 [ d0[0], d1[0], d1[1], d1[2], d1[3], d1[4], d1[5], d1[6] ] + // stride=1 [ d0[1], d2[0], d0[0], d1[0], d1[1], d1[2], d1[3], d1[4] ] + // stride=2 [ d0[2], d2[1], d0[1], d2[0], d0[0], d1[0], d1[1], d1[2] ] + // stride=3 [ d0[3], d2[2], d0[2], d2[1], d0[1], d2[0], d0[0], d1[0] ] + // stride=4 [ d0[4], d2[3], d0[3], d2[2], d0[2], d2[1], d0[1], d2[0] ] + // stride=5 [ d0[5], d2[4], d0[4], d2[3], d0[3], d2[2], d0[2], d2[1] ] + // stride=6 [ d0[6], d2[5], d0[5], d2[4], d0[4], d2[3], d0[3], d2[2] ] + // stride=7 [ d0[7], d2[6], d0[6], d2[5], d0[5], d2[4], d0[4], d2[3] ] + vst1q_u16(dst + 0 * stride, vextq_u16(d20_hi, d1, 7)); + vst1q_u16(dst + 1 * stride, vextq_u16(d20_hi, d1, 5)); + vst1q_u16(dst + 2 * stride, vextq_u16(d20_hi, d1, 3)); + vst1q_u16(dst + 3 * stride, vextq_u16(d20_hi, d1, 1)); + vst1q_u16(dst + 4 * stride, vextq_u16(d20_lo, d20_hi, 7)); + vst1q_u16(dst + 5 * stride, vextq_u16(d20_lo, d20_hi, 5)); + vst1q_u16(dst + 6 * stride, vextq_u16(d20_lo, d20_hi, 3)); + vst1q_u16(dst + 7 * stride, vextq_u16(d20_lo, d20_hi, 1)); +} + +void vpx_highbd_d153_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + // See vpx_highbd_d153_predictor_8x8_neon for details on the implementation. + uint16x8_t az, a0, a6, a7, a8, l0az, l0, l1, l7, l8, l9, azl0, d0[2], d1[2], + d2[2], d20[4]; + (void)bd; + + az = vld1q_u16(above - 1); + a0 = vld1q_u16(above + 0); + a6 = vld1q_u16(above + 6); + a7 = vld1q_u16(above + 7); + a8 = vld1q_u16(above + 8); + // [ left[0], above[-1], ... , above[13] ] + l0az = vextq_u16(vld1q_dup_u16(left), az, 7); + + l0 = vld1q_u16(left + 0); + l1 = vld1q_u16(left + 1); + l7 = vld1q_u16(left + 7); + l8 = vld1q_u16(left + 8); + // The last lane here is unused, reading left[16] could cause a buffer + // over-read, so just fill with a duplicate of left[8] to avoid needing to + // materialize a zero: + // [ left[9], ... , left[15], x ] + l9 = vextq_u16(l8, l8, 1); + // [ above[-1], left[0], ... , left[14] ] + azl0 = vextq_u16(vld1q_dup_u16(above - 1), l0, 7); + + d0[0] = vrhaddq_u16(azl0, l0); + d0[1] = vrhaddq_u16(l7, l8); + d1[0] = vrhaddq_u16(vhaddq_u16(l0az, a0), az); + d1[1] = vrhaddq_u16(vhaddq_u16(a6, a8), a7); + d2[0] = vrhaddq_u16(vhaddq_u16(azl0, l1), l0); + d2[1] = vrhaddq_u16(vhaddq_u16(l7, l9), l8); + + d0[0] = vrev64q_u16(vextq_u16(d0[0], d0[0], 4)); + d0[1] = vrev64q_u16(vextq_u16(d0[1], d0[1], 4)); + d2[0] = vrev64q_u16(vextq_u16(d2[0], d2[0], 4)); + d2[1] = vrev64q_u16(vextq_u16(d2[1], d2[1], 4)); + + d20[0] = vzipq_u16(d2[1], d0[1]).val[0]; + d20[1] = vzipq_u16(d2[1], d0[1]).val[1]; + d20[2] = vzipq_u16(d2[0], d0[0]).val[0]; + d20[3] = vzipq_u16(d2[0], d0[0]).val[1]; + + vst1q_u16(dst + 0 * stride + 0, vextq_u16(d20[3], d1[0], 7)); + vst1q_u16(dst + 0 * stride + 8, vextq_u16(d1[0], d1[1], 7)); + vst1q_u16(dst + 1 * stride + 0, vextq_u16(d20[3], d1[0], 5)); + vst1q_u16(dst + 1 * stride + 8, vextq_u16(d1[0], d1[1], 5)); + vst1q_u16(dst + 2 * stride + 0, vextq_u16(d20[3], d1[0], 3)); + vst1q_u16(dst + 2 * stride + 8, vextq_u16(d1[0], d1[1], 3)); + vst1q_u16(dst + 3 * stride + 0, vextq_u16(d20[3], d1[0], 1)); + vst1q_u16(dst + 3 * stride + 8, vextq_u16(d1[0], d1[1], 1)); + + vst1q_u16(dst + 4 * stride + 0, vextq_u16(d20[2], d20[3], 7)); + vst1q_u16(dst + 4 * stride + 8, vextq_u16(d20[3], d1[0], 7)); + vst1q_u16(dst + 5 * stride + 0, vextq_u16(d20[2], d20[3], 5)); + vst1q_u16(dst + 5 * stride + 8, vextq_u16(d20[3], d1[0], 5)); + vst1q_u16(dst + 6 * stride + 0, vextq_u16(d20[2], d20[3], 3)); + vst1q_u16(dst + 6 * stride + 8, vextq_u16(d20[3], d1[0], 3)); + vst1q_u16(dst + 7 * stride + 0, vextq_u16(d20[2], d20[3], 1)); + vst1q_u16(dst + 7 * stride + 8, vextq_u16(d20[3], d1[0], 1)); + + vst1q_u16(dst + 8 * stride + 0, vextq_u16(d20[1], d20[2], 7)); + vst1q_u16(dst + 8 * stride + 8, vextq_u16(d20[2], d20[3], 7)); + vst1q_u16(dst + 9 * stride + 0, vextq_u16(d20[1], d20[2], 5)); + vst1q_u16(dst + 9 * stride + 8, vextq_u16(d20[2], d20[3], 5)); + vst1q_u16(dst + 10 * stride + 0, vextq_u16(d20[1], d20[2], 3)); + vst1q_u16(dst + 10 * stride + 8, vextq_u16(d20[2], d20[3], 3)); + vst1q_u16(dst + 11 * stride + 0, vextq_u16(d20[1], d20[2], 1)); + vst1q_u16(dst + 11 * stride + 8, vextq_u16(d20[2], d20[3], 1)); + + vst1q_u16(dst + 12 * stride + 0, vextq_u16(d20[0], d20[1], 7)); + vst1q_u16(dst + 12 * stride + 8, vextq_u16(d20[1], d20[2], 7)); + vst1q_u16(dst + 13 * stride + 0, vextq_u16(d20[0], d20[1], 5)); + vst1q_u16(dst + 13 * stride + 8, vextq_u16(d20[1], d20[2], 5)); + vst1q_u16(dst + 14 * stride + 0, vextq_u16(d20[0], d20[1], 3)); + vst1q_u16(dst + 14 * stride + 8, vextq_u16(d20[1], d20[2], 3)); + vst1q_u16(dst + 15 * stride + 0, vextq_u16(d20[0], d20[1], 1)); + vst1q_u16(dst + 15 * stride + 8, vextq_u16(d20[1], d20[2], 1)); +} + +void vpx_highbd_d153_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + // See vpx_highbd_d153_predictor_8x8_neon for details on the implementation. + uint16x8_t az, a0, a6, a7, a8, a14, a15, a16, a22, a23, a24, l0az, l0, l1, l7, + l8, l9, l15, l16, l17, l23, l24, l25, azl0, d0[4], d1[4], d2[4], d20[8]; + (void)bd; + + az = vld1q_u16(above - 1); + a0 = vld1q_u16(above + 0); + a6 = vld1q_u16(above + 6); + a7 = vld1q_u16(above + 7); + a8 = vld1q_u16(above + 8); + a14 = vld1q_u16(above + 14); + a15 = vld1q_u16(above + 15); + a16 = vld1q_u16(above + 16); + a22 = vld1q_u16(above + 22); + a23 = vld1q_u16(above + 23); + a24 = vld1q_u16(above + 24); + // [ left[0], above[-1], ... , above[13] ] + l0az = vextq_u16(vld1q_dup_u16(left), az, 7); + + l0 = vld1q_u16(left + 0); + l1 = vld1q_u16(left + 1); + l7 = vld1q_u16(left + 7); + l8 = vld1q_u16(left + 8); + l9 = vld1q_u16(left + 9); + l15 = vld1q_u16(left + 15); + l16 = vld1q_u16(left + 16); + l17 = vld1q_u16(left + 17); + l23 = vld1q_u16(left + 23); + l24 = vld1q_u16(left + 24); + // The last lane here is unused, reading left[32] could cause a buffer + // over-read, so just fill with a duplicate of left[24] to avoid needing to + // materialize a zero: + // [ left[25], ... , left[31], x ] + l25 = vextq_u16(l24, l24, 1); + // [ above[-1], left[0], ... , left[14] ] + azl0 = vextq_u16(vld1q_dup_u16(above - 1), l0, 7); + + d0[0] = vrhaddq_u16(azl0, l0); + d0[1] = vrhaddq_u16(l7, l8); + d0[2] = vrhaddq_u16(l15, l16); + d0[3] = vrhaddq_u16(l23, l24); + + d1[0] = vrhaddq_u16(vhaddq_u16(l0az, a0), az); + d1[1] = vrhaddq_u16(vhaddq_u16(a6, a8), a7); + d1[2] = vrhaddq_u16(vhaddq_u16(a14, a16), a15); + d1[3] = vrhaddq_u16(vhaddq_u16(a22, a24), a23); + + d2[0] = vrhaddq_u16(vhaddq_u16(azl0, l1), l0); + d2[1] = vrhaddq_u16(vhaddq_u16(l7, l9), l8); + d2[2] = vrhaddq_u16(vhaddq_u16(l15, l17), l16); + d2[3] = vrhaddq_u16(vhaddq_u16(l23, l25), l24); + + d0[0] = vrev64q_u16(vextq_u16(d0[0], d0[0], 4)); + d0[1] = vrev64q_u16(vextq_u16(d0[1], d0[1], 4)); + d0[2] = vrev64q_u16(vextq_u16(d0[2], d0[2], 4)); + d0[3] = vrev64q_u16(vextq_u16(d0[3], d0[3], 4)); + d2[0] = vrev64q_u16(vextq_u16(d2[0], d2[0], 4)); + d2[1] = vrev64q_u16(vextq_u16(d2[1], d2[1], 4)); + d2[2] = vrev64q_u16(vextq_u16(d2[2], d2[2], 4)); + d2[3] = vrev64q_u16(vextq_u16(d2[3], d2[3], 4)); + + d20[0] = vzipq_u16(d2[3], d0[3]).val[0]; + d20[1] = vzipq_u16(d2[3], d0[3]).val[1]; + d20[2] = vzipq_u16(d2[2], d0[2]).val[0]; + d20[3] = vzipq_u16(d2[2], d0[2]).val[1]; + d20[4] = vzipq_u16(d2[1], d0[1]).val[0]; + d20[5] = vzipq_u16(d2[1], d0[1]).val[1]; + d20[6] = vzipq_u16(d2[0], d0[0]).val[0]; + d20[7] = vzipq_u16(d2[0], d0[0]).val[1]; + + vst1q_u16(dst + 0 * stride + 0, vextq_u16(d20[7], d1[0], 7)); + vst1q_u16(dst + 0 * stride + 8, vextq_u16(d1[0], d1[1], 7)); + vst1q_u16(dst + 0 * stride + 16, vextq_u16(d1[1], d1[2], 7)); + vst1q_u16(dst + 0 * stride + 24, vextq_u16(d1[2], d1[3], 7)); + vst1q_u16(dst + 1 * stride + 0, vextq_u16(d20[7], d1[0], 5)); + vst1q_u16(dst + 1 * stride + 8, vextq_u16(d1[0], d1[1], 5)); + vst1q_u16(dst + 1 * stride + 16, vextq_u16(d1[1], d1[2], 5)); + vst1q_u16(dst + 1 * stride + 24, vextq_u16(d1[2], d1[3], 5)); + vst1q_u16(dst + 2 * stride + 0, vextq_u16(d20[7], d1[0], 3)); + vst1q_u16(dst + 2 * stride + 8, vextq_u16(d1[0], d1[1], 3)); + vst1q_u16(dst + 2 * stride + 16, vextq_u16(d1[1], d1[2], 3)); + vst1q_u16(dst + 2 * stride + 24, vextq_u16(d1[2], d1[3], 3)); + vst1q_u16(dst + 3 * stride + 0, vextq_u16(d20[7], d1[0], 1)); + vst1q_u16(dst + 3 * stride + 8, vextq_u16(d1[0], d1[1], 1)); + vst1q_u16(dst + 3 * stride + 16, vextq_u16(d1[1], d1[2], 1)); + vst1q_u16(dst + 3 * stride + 24, vextq_u16(d1[2], d1[3], 1)); + + vst1q_u16(dst + 4 * stride + 0, vextq_u16(d20[6], d20[7], 7)); + vst1q_u16(dst + 4 * stride + 8, vextq_u16(d20[7], d1[0], 7)); + vst1q_u16(dst + 4 * stride + 16, vextq_u16(d1[0], d1[1], 7)); + vst1q_u16(dst + 4 * stride + 24, vextq_u16(d1[1], d1[2], 7)); + vst1q_u16(dst + 5 * stride + 0, vextq_u16(d20[6], d20[7], 5)); + vst1q_u16(dst + 5 * stride + 8, vextq_u16(d20[7], d1[0], 5)); + vst1q_u16(dst + 5 * stride + 16, vextq_u16(d1[0], d1[1], 5)); + vst1q_u16(dst + 5 * stride + 24, vextq_u16(d1[1], d1[2], 5)); + vst1q_u16(dst + 6 * stride + 0, vextq_u16(d20[6], d20[7], 3)); + vst1q_u16(dst + 6 * stride + 8, vextq_u16(d20[7], d1[0], 3)); + vst1q_u16(dst + 6 * stride + 16, vextq_u16(d1[0], d1[1], 3)); + vst1q_u16(dst + 6 * stride + 24, vextq_u16(d1[1], d1[2], 3)); + vst1q_u16(dst + 7 * stride + 0, vextq_u16(d20[6], d20[7], 1)); + vst1q_u16(dst + 7 * stride + 8, vextq_u16(d20[7], d1[0], 1)); + vst1q_u16(dst + 7 * stride + 16, vextq_u16(d1[0], d1[1], 1)); + vst1q_u16(dst + 7 * stride + 24, vextq_u16(d1[1], d1[2], 1)); + + vst1q_u16(dst + 8 * stride + 0, vextq_u16(d20[5], d20[6], 7)); + vst1q_u16(dst + 8 * stride + 8, vextq_u16(d20[6], d20[7], 7)); + vst1q_u16(dst + 8 * stride + 16, vextq_u16(d20[7], d1[0], 7)); + vst1q_u16(dst + 8 * stride + 24, vextq_u16(d1[0], d1[1], 7)); + vst1q_u16(dst + 9 * stride + 0, vextq_u16(d20[5], d20[6], 5)); + vst1q_u16(dst + 9 * stride + 8, vextq_u16(d20[6], d20[7], 5)); + vst1q_u16(dst + 9 * stride + 16, vextq_u16(d20[7], d1[0], 5)); + vst1q_u16(dst + 9 * stride + 24, vextq_u16(d1[0], d1[1], 5)); + vst1q_u16(dst + 10 * stride + 0, vextq_u16(d20[5], d20[6], 3)); + vst1q_u16(dst + 10 * stride + 8, vextq_u16(d20[6], d20[7], 3)); + vst1q_u16(dst + 10 * stride + 16, vextq_u16(d20[7], d1[0], 3)); + vst1q_u16(dst + 10 * stride + 24, vextq_u16(d1[0], d1[1], 3)); + vst1q_u16(dst + 11 * stride + 0, vextq_u16(d20[5], d20[6], 1)); + vst1q_u16(dst + 11 * stride + 8, vextq_u16(d20[6], d20[7], 1)); + vst1q_u16(dst + 11 * stride + 16, vextq_u16(d20[7], d1[0], 1)); + vst1q_u16(dst + 11 * stride + 24, vextq_u16(d1[0], d1[1], 1)); + + vst1q_u16(dst + 12 * stride + 0, vextq_u16(d20[4], d20[5], 7)); + vst1q_u16(dst + 12 * stride + 8, vextq_u16(d20[5], d20[6], 7)); + vst1q_u16(dst + 12 * stride + 16, vextq_u16(d20[6], d20[7], 7)); + vst1q_u16(dst + 12 * stride + 24, vextq_u16(d20[7], d1[0], 7)); + vst1q_u16(dst + 13 * stride + 0, vextq_u16(d20[4], d20[5], 5)); + vst1q_u16(dst + 13 * stride + 8, vextq_u16(d20[5], d20[6], 5)); + vst1q_u16(dst + 13 * stride + 16, vextq_u16(d20[6], d20[7], 5)); + vst1q_u16(dst + 13 * stride + 24, vextq_u16(d20[7], d1[0], 5)); + vst1q_u16(dst + 14 * stride + 0, vextq_u16(d20[4], d20[5], 3)); + vst1q_u16(dst + 14 * stride + 8, vextq_u16(d20[5], d20[6], 3)); + vst1q_u16(dst + 14 * stride + 16, vextq_u16(d20[6], d20[7], 3)); + vst1q_u16(dst + 14 * stride + 24, vextq_u16(d20[7], d1[0], 3)); + vst1q_u16(dst + 15 * stride + 0, vextq_u16(d20[4], d20[5], 1)); + vst1q_u16(dst + 15 * stride + 8, vextq_u16(d20[5], d20[6], 1)); + vst1q_u16(dst + 15 * stride + 16, vextq_u16(d20[6], d20[7], 1)); + vst1q_u16(dst + 15 * stride + 24, vextq_u16(d20[7], d1[0], 1)); + + vst1q_u16(dst + 16 * stride + 0, vextq_u16(d20[3], d20[4], 7)); + vst1q_u16(dst + 16 * stride + 8, vextq_u16(d20[4], d20[5], 7)); + vst1q_u16(dst + 16 * stride + 16, vextq_u16(d20[5], d20[6], 7)); + vst1q_u16(dst + 16 * stride + 24, vextq_u16(d20[6], d20[7], 7)); + vst1q_u16(dst + 17 * stride + 0, vextq_u16(d20[3], d20[4], 5)); + vst1q_u16(dst + 17 * stride + 8, vextq_u16(d20[4], d20[5], 5)); + vst1q_u16(dst + 17 * stride + 16, vextq_u16(d20[5], d20[6], 5)); + vst1q_u16(dst + 17 * stride + 24, vextq_u16(d20[6], d20[7], 5)); + vst1q_u16(dst + 18 * stride + 0, vextq_u16(d20[3], d20[4], 3)); + vst1q_u16(dst + 18 * stride + 8, vextq_u16(d20[4], d20[5], 3)); + vst1q_u16(dst + 18 * stride + 16, vextq_u16(d20[5], d20[6], 3)); + vst1q_u16(dst + 18 * stride + 24, vextq_u16(d20[6], d20[7], 3)); + vst1q_u16(dst + 19 * stride + 0, vextq_u16(d20[3], d20[4], 1)); + vst1q_u16(dst + 19 * stride + 8, vextq_u16(d20[4], d20[5], 1)); + vst1q_u16(dst + 19 * stride + 16, vextq_u16(d20[5], d20[6], 1)); + vst1q_u16(dst + 19 * stride + 24, vextq_u16(d20[6], d20[7], 1)); + + vst1q_u16(dst + 20 * stride + 0, vextq_u16(d20[2], d20[3], 7)); + vst1q_u16(dst + 20 * stride + 8, vextq_u16(d20[3], d20[4], 7)); + vst1q_u16(dst + 20 * stride + 16, vextq_u16(d20[4], d20[5], 7)); + vst1q_u16(dst + 20 * stride + 24, vextq_u16(d20[5], d20[6], 7)); + vst1q_u16(dst + 21 * stride + 0, vextq_u16(d20[2], d20[3], 5)); + vst1q_u16(dst + 21 * stride + 8, vextq_u16(d20[3], d20[4], 5)); + vst1q_u16(dst + 21 * stride + 16, vextq_u16(d20[4], d20[5], 5)); + vst1q_u16(dst + 21 * stride + 24, vextq_u16(d20[5], d20[6], 5)); + vst1q_u16(dst + 22 * stride + 0, vextq_u16(d20[2], d20[3], 3)); + vst1q_u16(dst + 22 * stride + 8, vextq_u16(d20[3], d20[4], 3)); + vst1q_u16(dst + 22 * stride + 16, vextq_u16(d20[4], d20[5], 3)); + vst1q_u16(dst + 22 * stride + 24, vextq_u16(d20[5], d20[6], 3)); + vst1q_u16(dst + 23 * stride + 0, vextq_u16(d20[2], d20[3], 1)); + vst1q_u16(dst + 23 * stride + 8, vextq_u16(d20[3], d20[4], 1)); + vst1q_u16(dst + 23 * stride + 16, vextq_u16(d20[4], d20[5], 1)); + vst1q_u16(dst + 23 * stride + 24, vextq_u16(d20[5], d20[6], 1)); + + vst1q_u16(dst + 24 * stride + 0, vextq_u16(d20[1], d20[2], 7)); + vst1q_u16(dst + 24 * stride + 8, vextq_u16(d20[2], d20[3], 7)); + vst1q_u16(dst + 24 * stride + 16, vextq_u16(d20[3], d20[4], 7)); + vst1q_u16(dst + 24 * stride + 24, vextq_u16(d20[4], d20[5], 7)); + vst1q_u16(dst + 25 * stride + 0, vextq_u16(d20[1], d20[2], 5)); + vst1q_u16(dst + 25 * stride + 8, vextq_u16(d20[2], d20[3], 5)); + vst1q_u16(dst + 25 * stride + 16, vextq_u16(d20[3], d20[4], 5)); + vst1q_u16(dst + 25 * stride + 24, vextq_u16(d20[4], d20[5], 5)); + vst1q_u16(dst + 26 * stride + 0, vextq_u16(d20[1], d20[2], 3)); + vst1q_u16(dst + 26 * stride + 8, vextq_u16(d20[2], d20[3], 3)); + vst1q_u16(dst + 26 * stride + 16, vextq_u16(d20[3], d20[4], 3)); + vst1q_u16(dst + 26 * stride + 24, vextq_u16(d20[4], d20[5], 3)); + vst1q_u16(dst + 27 * stride + 0, vextq_u16(d20[1], d20[2], 1)); + vst1q_u16(dst + 27 * stride + 8, vextq_u16(d20[2], d20[3], 1)); + vst1q_u16(dst + 27 * stride + 16, vextq_u16(d20[3], d20[4], 1)); + vst1q_u16(dst + 27 * stride + 24, vextq_u16(d20[4], d20[5], 1)); + + vst1q_u16(dst + 28 * stride + 0, vextq_u16(d20[0], d20[1], 7)); + vst1q_u16(dst + 28 * stride + 8, vextq_u16(d20[1], d20[2], 7)); + vst1q_u16(dst + 28 * stride + 16, vextq_u16(d20[2], d20[3], 7)); + vst1q_u16(dst + 28 * stride + 24, vextq_u16(d20[3], d20[4], 7)); + vst1q_u16(dst + 29 * stride + 0, vextq_u16(d20[0], d20[1], 5)); + vst1q_u16(dst + 29 * stride + 8, vextq_u16(d20[1], d20[2], 5)); + vst1q_u16(dst + 29 * stride + 16, vextq_u16(d20[2], d20[3], 5)); + vst1q_u16(dst + 29 * stride + 24, vextq_u16(d20[3], d20[4], 5)); + vst1q_u16(dst + 30 * stride + 0, vextq_u16(d20[0], d20[1], 3)); + vst1q_u16(dst + 30 * stride + 8, vextq_u16(d20[1], d20[2], 3)); + vst1q_u16(dst + 30 * stride + 16, vextq_u16(d20[2], d20[3], 3)); + vst1q_u16(dst + 30 * stride + 24, vextq_u16(d20[3], d20[4], 3)); + vst1q_u16(dst + 31 * stride + 0, vextq_u16(d20[0], d20[1], 1)); + vst1q_u16(dst + 31 * stride + 8, vextq_u16(d20[1], d20[2], 1)); + vst1q_u16(dst + 31 * stride + 16, vextq_u16(d20[2], d20[3], 1)); + vst1q_u16(dst + 31 * stride + 24, vextq_u16(d20[3], d20[4], 1)); } // ----------------------------------------------------------------------------- @@ -696,6 +1821,311 @@ void vpx_highbd_d135_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, //------------------------------------------------------------------------------ +void vpx_highbd_d207_predictor_4x4_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + uint16x4_t l0, l1, l2, l3, c0, c1, c01_lo, c01_hi; + (void)above; + (void)bd; + + l0 = vld1_u16(left + 0); + l3 = vld1_dup_u16(left + 3); + + // [ left[1], left[2], left[3], left[3] ] + l1 = vext_u16(l0, l3, 1); + // [ left[2], left[3], left[3], left[3] ] + l2 = vext_u16(l0, l3, 2); + + c0 = vrhadd_u16(l0, l1); + c1 = vrhadd_u16(vhadd_u16(l0, l2), l1); + + c01_lo = vzip_u16(c0, c1).val[0]; + c01_hi = vzip_u16(c0, c1).val[1]; + + // stride=0 [ c0[0], c1[0], c0[1], c1[1] ] + // stride=1 [ c0[1], c1[1], c0[2], c1[2] ] + // stride=2 [ c0[2], c1[2], c0[3], c1[3] ] + // stride=3 [ c0[3], c1[3], left[3], left[3] ] + vst1_u16(dst + 0 * stride, c01_lo); + vst1_u16(dst + 1 * stride, vext_u16(c01_lo, c01_hi, 2)); + vst1_u16(dst + 2 * stride, c01_hi); + vst1_u16(dst + 3 * stride, vext_u16(c01_hi, l3, 2)); +} + +void vpx_highbd_d207_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + uint16x8_t l0, l1, l2, l7, c0, c1, c01_lo, c01_hi; + (void)above; + (void)bd; + + l0 = vld1q_u16(left + 0); + l7 = vld1q_dup_u16(left + 7); + + // [ left[1], left[2], left[3], left[4], left[5], left[6], left[7], left[7] ] + l1 = vextq_u16(l0, l7, 1); + // [ left[2], left[3], left[4], left[5], left[6], left[7], left[7], left[7] ] + l2 = vextq_u16(l0, l7, 2); + + c0 = vrhaddq_u16(l0, l1); + c1 = vrhaddq_u16(vhaddq_u16(l0, l2), l1); + + c01_lo = vzipq_u16(c0, c1).val[0]; + c01_hi = vzipq_u16(c0, c1).val[1]; + + vst1q_u16(dst + 0 * stride, c01_lo); + vst1q_u16(dst + 1 * stride, vextq_u16(c01_lo, c01_hi, 2)); + vst1q_u16(dst + 2 * stride, vextq_u16(c01_lo, c01_hi, 4)); + vst1q_u16(dst + 3 * stride, vextq_u16(c01_lo, c01_hi, 6)); + vst1q_u16(dst + 4 * stride, c01_hi); + vst1q_u16(dst + 5 * stride, vextq_u16(c01_hi, l7, 2)); + vst1q_u16(dst + 6 * stride, vextq_u16(c01_hi, l7, 4)); + vst1q_u16(dst + 7 * stride, vextq_u16(c01_hi, l7, 6)); +} + +void vpx_highbd_d207_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + uint16x8_t l0, l1, l2, l8, l9, l10, l15, c0[2], c1[2], c01[4]; + (void)above; + (void)bd; + + l0 = vld1q_u16(left + 0); + l1 = vld1q_u16(left + 1); + l2 = vld1q_u16(left + 2); + l8 = vld1q_u16(left + 8); + l15 = vld1q_dup_u16(left + 15); + + l9 = vextq_u16(l8, l15, 1); + l10 = vextq_u16(l8, l15, 2); + + c0[0] = vrhaddq_u16(l0, l1); + c0[1] = vrhaddq_u16(l8, l9); + c1[0] = vrhaddq_u16(vhaddq_u16(l0, l2), l1); + c1[1] = vrhaddq_u16(vhaddq_u16(l8, l10), l9); + + c01[0] = vzipq_u16(c0[0], c1[0]).val[0]; + c01[1] = vzipq_u16(c0[0], c1[0]).val[1]; + c01[2] = vzipq_u16(c0[1], c1[1]).val[0]; + c01[3] = vzipq_u16(c0[1], c1[1]).val[1]; + + vst1q_u16(dst + 0 * stride + 0, c01[0]); + vst1q_u16(dst + 0 * stride + 8, c01[1]); + vst1q_u16(dst + 1 * stride + 0, vextq_u16(c01[0], c01[1], 2)); + vst1q_u16(dst + 1 * stride + 8, vextq_u16(c01[1], c01[2], 2)); + vst1q_u16(dst + 2 * stride + 0, vextq_u16(c01[0], c01[1], 4)); + vst1q_u16(dst + 2 * stride + 8, vextq_u16(c01[1], c01[2], 4)); + vst1q_u16(dst + 3 * stride + 0, vextq_u16(c01[0], c01[1], 6)); + vst1q_u16(dst + 3 * stride + 8, vextq_u16(c01[1], c01[2], 6)); + + vst1q_u16(dst + 4 * stride + 0, c01[1]); + vst1q_u16(dst + 4 * stride + 8, c01[2]); + vst1q_u16(dst + 5 * stride + 0, vextq_u16(c01[1], c01[2], 2)); + vst1q_u16(dst + 5 * stride + 8, vextq_u16(c01[2], c01[3], 2)); + vst1q_u16(dst + 6 * stride + 0, vextq_u16(c01[1], c01[2], 4)); + vst1q_u16(dst + 6 * stride + 8, vextq_u16(c01[2], c01[3], 4)); + vst1q_u16(dst + 7 * stride + 0, vextq_u16(c01[1], c01[2], 6)); + vst1q_u16(dst + 7 * stride + 8, vextq_u16(c01[2], c01[3], 6)); + + vst1q_u16(dst + 8 * stride + 0, c01[2]); + vst1q_u16(dst + 8 * stride + 8, c01[3]); + vst1q_u16(dst + 9 * stride + 0, vextq_u16(c01[2], c01[3], 2)); + vst1q_u16(dst + 9 * stride + 8, vextq_u16(c01[3], l15, 2)); + vst1q_u16(dst + 10 * stride + 0, vextq_u16(c01[2], c01[3], 4)); + vst1q_u16(dst + 10 * stride + 8, vextq_u16(c01[3], l15, 4)); + vst1q_u16(dst + 11 * stride + 0, vextq_u16(c01[2], c01[3], 6)); + vst1q_u16(dst + 11 * stride + 8, vextq_u16(c01[3], l15, 6)); + + vst1q_u16(dst + 12 * stride + 0, c01[3]); + vst1q_u16(dst + 12 * stride + 8, l15); + vst1q_u16(dst + 13 * stride + 0, vextq_u16(c01[3], l15, 2)); + vst1q_u16(dst + 13 * stride + 8, l15); + vst1q_u16(dst + 14 * stride + 0, vextq_u16(c01[3], l15, 4)); + vst1q_u16(dst + 14 * stride + 8, l15); + vst1q_u16(dst + 15 * stride + 0, vextq_u16(c01[3], l15, 6)); + vst1q_u16(dst + 15 * stride + 8, l15); +} + +void vpx_highbd_d207_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + uint16x8_t l0, l1, l2, l8, l9, l10, l16, l17, l18, l24, l25, l26, l31, c0[4], + c1[4], c01[8]; + (void)above; + (void)bd; + + l0 = vld1q_u16(left + 0); + l1 = vld1q_u16(left + 1); + l2 = vld1q_u16(left + 2); + l8 = vld1q_u16(left + 8); + l9 = vld1q_u16(left + 9); + l10 = vld1q_u16(left + 10); + l16 = vld1q_u16(left + 16); + l17 = vld1q_u16(left + 17); + l18 = vld1q_u16(left + 18); + l24 = vld1q_u16(left + 24); + l31 = vld1q_dup_u16(left + 31); + + l25 = vextq_u16(l24, l31, 1); + l26 = vextq_u16(l24, l31, 2); + + c0[0] = vrhaddq_u16(l0, l1); + c0[1] = vrhaddq_u16(l8, l9); + c0[2] = vrhaddq_u16(l16, l17); + c0[3] = vrhaddq_u16(l24, l25); + c1[0] = vrhaddq_u16(vhaddq_u16(l0, l2), l1); + c1[1] = vrhaddq_u16(vhaddq_u16(l8, l10), l9); + c1[2] = vrhaddq_u16(vhaddq_u16(l16, l18), l17); + c1[3] = vrhaddq_u16(vhaddq_u16(l24, l26), l25); + + c01[0] = vzipq_u16(c0[0], c1[0]).val[0]; + c01[1] = vzipq_u16(c0[0], c1[0]).val[1]; + c01[2] = vzipq_u16(c0[1], c1[1]).val[0]; + c01[3] = vzipq_u16(c0[1], c1[1]).val[1]; + c01[4] = vzipq_u16(c0[2], c1[2]).val[0]; + c01[5] = vzipq_u16(c0[2], c1[2]).val[1]; + c01[6] = vzipq_u16(c0[3], c1[3]).val[0]; + c01[7] = vzipq_u16(c0[3], c1[3]).val[1]; + + vst1q_u16(dst + 0 * stride + 0, c01[0]); + vst1q_u16(dst + 0 * stride + 8, c01[1]); + vst1q_u16(dst + 0 * stride + 16, c01[2]); + vst1q_u16(dst + 0 * stride + 24, c01[3]); + vst1q_u16(dst + 1 * stride + 0, vextq_u16(c01[0], c01[1], 2)); + vst1q_u16(dst + 1 * stride + 8, vextq_u16(c01[1], c01[2], 2)); + vst1q_u16(dst + 1 * stride + 16, vextq_u16(c01[2], c01[3], 2)); + vst1q_u16(dst + 1 * stride + 24, vextq_u16(c01[3], c01[4], 2)); + vst1q_u16(dst + 2 * stride + 0, vextq_u16(c01[0], c01[1], 4)); + vst1q_u16(dst + 2 * stride + 8, vextq_u16(c01[1], c01[2], 4)); + vst1q_u16(dst + 2 * stride + 16, vextq_u16(c01[2], c01[3], 4)); + vst1q_u16(dst + 2 * stride + 24, vextq_u16(c01[3], c01[4], 4)); + vst1q_u16(dst + 3 * stride + 0, vextq_u16(c01[0], c01[1], 6)); + vst1q_u16(dst + 3 * stride + 8, vextq_u16(c01[1], c01[2], 6)); + vst1q_u16(dst + 3 * stride + 16, vextq_u16(c01[2], c01[3], 6)); + vst1q_u16(dst + 3 * stride + 24, vextq_u16(c01[3], c01[4], 6)); + + vst1q_u16(dst + 4 * stride + 0, c01[1]); + vst1q_u16(dst + 4 * stride + 8, c01[2]); + vst1q_u16(dst + 4 * stride + 16, c01[3]); + vst1q_u16(dst + 4 * stride + 24, c01[4]); + vst1q_u16(dst + 5 * stride + 0, vextq_u16(c01[1], c01[2], 2)); + vst1q_u16(dst + 5 * stride + 8, vextq_u16(c01[2], c01[3], 2)); + vst1q_u16(dst + 5 * stride + 16, vextq_u16(c01[3], c01[4], 2)); + vst1q_u16(dst + 5 * stride + 24, vextq_u16(c01[4], c01[5], 2)); + vst1q_u16(dst + 6 * stride + 0, vextq_u16(c01[1], c01[2], 4)); + vst1q_u16(dst + 6 * stride + 8, vextq_u16(c01[2], c01[3], 4)); + vst1q_u16(dst + 6 * stride + 16, vextq_u16(c01[3], c01[4], 4)); + vst1q_u16(dst + 6 * stride + 24, vextq_u16(c01[4], c01[5], 4)); + vst1q_u16(dst + 7 * stride + 0, vextq_u16(c01[1], c01[2], 6)); + vst1q_u16(dst + 7 * stride + 8, vextq_u16(c01[2], c01[3], 6)); + vst1q_u16(dst + 7 * stride + 16, vextq_u16(c01[3], c01[4], 6)); + vst1q_u16(dst + 7 * stride + 24, vextq_u16(c01[4], c01[5], 6)); + + vst1q_u16(dst + 8 * stride + 0, c01[2]); + vst1q_u16(dst + 8 * stride + 8, c01[3]); + vst1q_u16(dst + 8 * stride + 16, c01[4]); + vst1q_u16(dst + 8 * stride + 24, c01[5]); + vst1q_u16(dst + 9 * stride + 0, vextq_u16(c01[2], c01[3], 2)); + vst1q_u16(dst + 9 * stride + 8, vextq_u16(c01[3], c01[4], 2)); + vst1q_u16(dst + 9 * stride + 16, vextq_u16(c01[4], c01[5], 2)); + vst1q_u16(dst + 9 * stride + 24, vextq_u16(c01[5], c01[6], 2)); + vst1q_u16(dst + 10 * stride + 0, vextq_u16(c01[2], c01[3], 4)); + vst1q_u16(dst + 10 * stride + 8, vextq_u16(c01[3], c01[4], 4)); + vst1q_u16(dst + 10 * stride + 16, vextq_u16(c01[4], c01[5], 4)); + vst1q_u16(dst + 10 * stride + 24, vextq_u16(c01[5], c01[6], 4)); + vst1q_u16(dst + 11 * stride + 0, vextq_u16(c01[2], c01[3], 6)); + vst1q_u16(dst + 11 * stride + 8, vextq_u16(c01[3], c01[4], 6)); + vst1q_u16(dst + 11 * stride + 16, vextq_u16(c01[4], c01[5], 6)); + vst1q_u16(dst + 11 * stride + 24, vextq_u16(c01[5], c01[6], 6)); + + vst1q_u16(dst + 12 * stride + 0, c01[3]); + vst1q_u16(dst + 12 * stride + 8, c01[4]); + vst1q_u16(dst + 12 * stride + 16, c01[5]); + vst1q_u16(dst + 12 * stride + 24, c01[6]); + vst1q_u16(dst + 13 * stride + 0, vextq_u16(c01[3], c01[4], 2)); + vst1q_u16(dst + 13 * stride + 8, vextq_u16(c01[4], c01[5], 2)); + vst1q_u16(dst + 13 * stride + 16, vextq_u16(c01[5], c01[6], 2)); + vst1q_u16(dst + 13 * stride + 24, vextq_u16(c01[6], c01[7], 2)); + vst1q_u16(dst + 14 * stride + 0, vextq_u16(c01[3], c01[4], 4)); + vst1q_u16(dst + 14 * stride + 8, vextq_u16(c01[4], c01[5], 4)); + vst1q_u16(dst + 14 * stride + 16, vextq_u16(c01[5], c01[6], 4)); + vst1q_u16(dst + 14 * stride + 24, vextq_u16(c01[6], c01[7], 4)); + vst1q_u16(dst + 15 * stride + 0, vextq_u16(c01[3], c01[4], 6)); + vst1q_u16(dst + 15 * stride + 8, vextq_u16(c01[4], c01[5], 6)); + vst1q_u16(dst + 15 * stride + 16, vextq_u16(c01[5], c01[6], 6)); + vst1q_u16(dst + 15 * stride + 24, vextq_u16(c01[6], c01[7], 6)); + + vst1q_u16(dst + 16 * stride + 0, c01[4]); + vst1q_u16(dst + 16 * stride + 8, c01[5]); + vst1q_u16(dst + 16 * stride + 16, c01[6]); + vst1q_u16(dst + 16 * stride + 24, c01[7]); + vst1q_u16(dst + 17 * stride + 0, vextq_u16(c01[4], c01[5], 2)); + vst1q_u16(dst + 17 * stride + 8, vextq_u16(c01[5], c01[6], 2)); + vst1q_u16(dst + 17 * stride + 16, vextq_u16(c01[6], c01[7], 2)); + vst1q_u16(dst + 17 * stride + 24, vextq_u16(c01[7], l31, 2)); + vst1q_u16(dst + 18 * stride + 0, vextq_u16(c01[4], c01[5], 4)); + vst1q_u16(dst + 18 * stride + 8, vextq_u16(c01[5], c01[6], 4)); + vst1q_u16(dst + 18 * stride + 16, vextq_u16(c01[6], c01[7], 4)); + vst1q_u16(dst + 18 * stride + 24, vextq_u16(c01[7], l31, 4)); + vst1q_u16(dst + 19 * stride + 0, vextq_u16(c01[4], c01[5], 6)); + vst1q_u16(dst + 19 * stride + 8, vextq_u16(c01[5], c01[6], 6)); + vst1q_u16(dst + 19 * stride + 16, vextq_u16(c01[6], c01[7], 6)); + vst1q_u16(dst + 19 * stride + 24, vextq_u16(c01[7], l31, 6)); + + vst1q_u16(dst + 20 * stride + 0, c01[5]); + vst1q_u16(dst + 20 * stride + 8, c01[6]); + vst1q_u16(dst + 20 * stride + 16, c01[7]); + vst1q_u16(dst + 20 * stride + 24, l31); + vst1q_u16(dst + 21 * stride + 0, vextq_u16(c01[5], c01[6], 2)); + vst1q_u16(dst + 21 * stride + 8, vextq_u16(c01[6], c01[7], 2)); + vst1q_u16(dst + 21 * stride + 16, vextq_u16(c01[7], l31, 2)); + vst1q_u16(dst + 21 * stride + 24, vextq_u16(l31, l31, 2)); + vst1q_u16(dst + 22 * stride + 0, vextq_u16(c01[5], c01[6], 4)); + vst1q_u16(dst + 22 * stride + 8, vextq_u16(c01[6], c01[7], 4)); + vst1q_u16(dst + 22 * stride + 16, vextq_u16(c01[7], l31, 4)); + vst1q_u16(dst + 22 * stride + 24, vextq_u16(l31, l31, 4)); + vst1q_u16(dst + 23 * stride + 0, vextq_u16(c01[5], c01[6], 6)); + vst1q_u16(dst + 23 * stride + 8, vextq_u16(c01[6], c01[7], 6)); + vst1q_u16(dst + 23 * stride + 16, vextq_u16(c01[7], l31, 6)); + vst1q_u16(dst + 23 * stride + 24, vextq_u16(l31, l31, 6)); + + vst1q_u16(dst + 24 * stride + 0, c01[6]); + vst1q_u16(dst + 24 * stride + 8, c01[7]); + vst1q_u16(dst + 24 * stride + 16, l31); + vst1q_u16(dst + 24 * stride + 24, l31); + vst1q_u16(dst + 25 * stride + 0, vextq_u16(c01[6], c01[7], 2)); + vst1q_u16(dst + 25 * stride + 8, vextq_u16(c01[7], l31, 2)); + vst1q_u16(dst + 25 * stride + 16, vextq_u16(l31, l31, 2)); + vst1q_u16(dst + 25 * stride + 24, vextq_u16(l31, l31, 2)); + vst1q_u16(dst + 26 * stride + 0, vextq_u16(c01[6], c01[7], 4)); + vst1q_u16(dst + 26 * stride + 8, vextq_u16(c01[7], l31, 4)); + vst1q_u16(dst + 26 * stride + 16, vextq_u16(l31, l31, 4)); + vst1q_u16(dst + 26 * stride + 24, vextq_u16(l31, l31, 4)); + vst1q_u16(dst + 27 * stride + 0, vextq_u16(c01[6], c01[7], 6)); + vst1q_u16(dst + 27 * stride + 8, vextq_u16(c01[7], l31, 6)); + vst1q_u16(dst + 27 * stride + 16, vextq_u16(l31, l31, 6)); + vst1q_u16(dst + 27 * stride + 24, vextq_u16(l31, l31, 6)); + + vst1q_u16(dst + 28 * stride + 0, c01[7]); + vst1q_u16(dst + 28 * stride + 8, l31); + vst1q_u16(dst + 28 * stride + 16, l31); + vst1q_u16(dst + 28 * stride + 24, l31); + vst1q_u16(dst + 29 * stride + 0, vextq_u16(c01[7], l31, 2)); + vst1q_u16(dst + 29 * stride + 8, vextq_u16(l31, l31, 2)); + vst1q_u16(dst + 29 * stride + 16, vextq_u16(l31, l31, 2)); + vst1q_u16(dst + 29 * stride + 24, vextq_u16(l31, l31, 2)); + vst1q_u16(dst + 30 * stride + 0, vextq_u16(c01[7], l31, 4)); + vst1q_u16(dst + 30 * stride + 8, vextq_u16(l31, l31, 4)); + vst1q_u16(dst + 30 * stride + 16, vextq_u16(l31, l31, 4)); + vst1q_u16(dst + 30 * stride + 24, vextq_u16(l31, l31, 4)); + vst1q_u16(dst + 31 * stride + 0, vextq_u16(c01[7], l31, 6)); + vst1q_u16(dst + 31 * stride + 8, vextq_u16(l31, l31, 6)); + vst1q_u16(dst + 31 * stride + 16, vextq_u16(l31, l31, 6)); + vst1q_u16(dst + 31 * stride + 24, vextq_u16(l31, l31, 6)); +} + +//------------------------------------------------------------------------------ + void vpx_highbd_v_predictor_4x4_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { @@ -725,30 +2155,36 @@ void vpx_highbd_v_predictor_8x8_neon(uint16_t *dst, ptrdiff_t stride, void vpx_highbd_v_predictor_16x16_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x8x2_t row = vld2q_u16(above); + const uint16x8_t row0 = vld1q_u16(above + 0); + const uint16x8_t row1 = vld1q_u16(above + 8); int i; (void)left; (void)bd; - for (i = 0; i < 16; i++, dst += stride) { - vst2q_u16(dst, row); + for (i = 0; i < 16; i++) { + vst1q_u16(dst + 0, row0); + vst1q_u16(dst + 8, row1); + dst += stride; } } void vpx_highbd_v_predictor_32x32_neon(uint16_t *dst, ptrdiff_t stride, const uint16_t *above, const uint16_t *left, int bd) { - const uint16x8x2_t row0 = vld2q_u16(above); - const uint16x8x2_t row1 = vld2q_u16(above + 16); + const uint16x8_t row0 = vld1q_u16(above + 0); + const uint16x8_t row1 = vld1q_u16(above + 8); + const uint16x8_t row2 = vld1q_u16(above + 16); + const uint16x8_t row3 = vld1q_u16(above + 24); int i; (void)left; (void)bd; for (i = 0; i < 32; i++) { - vst2q_u16(dst, row0); - dst += 16; - vst2q_u16(dst, row1); - dst += stride - 16; + vst1q_u16(dst + 0, row0); + vst1q_u16(dst + 8, row1); + vst1q_u16(dst + 16, row2); + vst1q_u16(dst + 24, row3); + dst += stride; } } diff --git a/libs/libvpx/vpx_dsp/arm/highbd_quantize_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_quantize_neon.c new file mode 100644 index 0000000000..c2ad34a695 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_quantize_neon.c @@ -0,0 +1,300 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" + +static VPX_FORCE_INLINE void highbd_calculate_dqcoeff_and_store( + const int32x4_t dqcoeff_0, const int32x4_t dqcoeff_1, + tran_low_t *dqcoeff_ptr) { + vst1q_s32(dqcoeff_ptr, dqcoeff_0); + vst1q_s32(dqcoeff_ptr + 4, dqcoeff_1); +} + +static VPX_FORCE_INLINE void highbd_quantize_8_neon( + const int32x4_t coeff_0, const int32x4_t coeff_1, const int32x4_t zbin, + const int32x4_t round, const int32x4_t quant, const int32x4_t quant_shift, + int32x4_t *qcoeff_0, int32x4_t *qcoeff_1) { + // Load coeffs as 2 vectors of 4 x 32-bit ints each, take sign and abs values + const int32x4_t coeff_0_sign = vshrq_n_s32(coeff_0, 31); + const int32x4_t coeff_1_sign = vshrq_n_s32(coeff_1, 31); + const int32x4_t coeff_0_abs = vabsq_s32(coeff_0); + const int32x4_t coeff_1_abs = vabsq_s32(coeff_1); + + // Calculate 2 masks of elements outside the bin + const int32x4_t zbin_mask_0 = + vreinterpretq_s32_u32(vcgeq_s32(coeff_0_abs, zbin)); + const int32x4_t zbin_mask_1 = vreinterpretq_s32_u32( + vcgeq_s32(coeff_1_abs, vdupq_lane_s32(vget_low_s32(zbin), 1))); + + // Get the rounded values + const int32x4_t rounded_0 = vaddq_s32(coeff_0_abs, round); + const int32x4_t rounded_1 = + vaddq_s32(coeff_1_abs, vdupq_lane_s32(vget_low_s32(round), 1)); + + // (round * (quant << 15) * 2) >> 16 == (round * quant) + int32x4_t qcoeff_tmp_0 = vqdmulhq_s32(rounded_0, quant); + int32x4_t qcoeff_tmp_1 = + vqdmulhq_s32(rounded_1, vdupq_lane_s32(vget_low_s32(quant), 1)); + + // Add rounded values + qcoeff_tmp_0 = vaddq_s32(qcoeff_tmp_0, rounded_0); + qcoeff_tmp_1 = vaddq_s32(qcoeff_tmp_1, rounded_1); + + // (round * (quant_shift << 15) * 2) >> 16 == (round * quant_shift) + qcoeff_tmp_0 = vqdmulhq_s32(qcoeff_tmp_0, quant_shift); + qcoeff_tmp_1 = + vqdmulhq_s32(qcoeff_tmp_1, vdupq_lane_s32(vget_low_s32(quant_shift), 1)); + + // Restore the sign bit. + qcoeff_tmp_0 = veorq_s32(qcoeff_tmp_0, coeff_0_sign); + qcoeff_tmp_1 = veorq_s32(qcoeff_tmp_1, coeff_1_sign); + qcoeff_tmp_0 = vsubq_s32(qcoeff_tmp_0, coeff_0_sign); + qcoeff_tmp_1 = vsubq_s32(qcoeff_tmp_1, coeff_1_sign); + + // Only keep the relevant coeffs + *qcoeff_0 = vandq_s32(qcoeff_tmp_0, zbin_mask_0); + *qcoeff_1 = vandq_s32(qcoeff_tmp_1, zbin_mask_1); +} + +static VPX_FORCE_INLINE int16x8_t +highbd_quantize_b_neon(const tran_low_t *coeff_ptr, tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, const int32x4_t zbin, + const int32x4_t round, const int32x4_t quant, + const int32x4_t quant_shift, const int32x4_t dequant) { + int32x4_t qcoeff_0, qcoeff_1, dqcoeff_0, dqcoeff_1; + + // Load coeffs as 2 vectors of 4 x 32-bit ints each, take sign and abs values + const int32x4_t coeff_0 = vld1q_s32(coeff_ptr); + const int32x4_t coeff_1 = vld1q_s32(coeff_ptr + 4); + highbd_quantize_8_neon(coeff_0, coeff_1, zbin, round, quant, quant_shift, + &qcoeff_0, &qcoeff_1); + + // Store the 32-bit qcoeffs + vst1q_s32(qcoeff_ptr, qcoeff_0); + vst1q_s32(qcoeff_ptr + 4, qcoeff_1); + + // Calculate and store the dqcoeffs + dqcoeff_0 = vmulq_s32(qcoeff_0, dequant); + dqcoeff_1 = vmulq_s32(qcoeff_1, vdupq_lane_s32(vget_low_s32(dequant), 1)); + + highbd_calculate_dqcoeff_and_store(dqcoeff_0, dqcoeff_1, dqcoeff_ptr); + + return vcombine_s16(vmovn_s32(qcoeff_0), vmovn_s32(qcoeff_1)); +} + +void vpx_highbd_quantize_b_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + const int16x8_t neg_one = vdupq_n_s16(-1); + uint16x8_t eob_max; + const int16_t *iscan = scan_order->iscan; + + // Only the first element of each vector is DC. + // High half has identical elements, but we can reconstruct it from the low + // half by duplicating the 2nd element. So we only need to pass a 4x32-bit + // vector + int32x4_t zbin = vmovl_s16(vld1_s16(mb_plane->zbin)); + int32x4_t round = vmovl_s16(vld1_s16(mb_plane->round)); + // Extend the quant, quant_shift vectors to ones of 32-bit elements + // scale to high-half, so we can use vqdmulhq_s32 + int32x4_t quant = vshlq_n_s32(vmovl_s16(vld1_s16(mb_plane->quant)), 15); + int32x4_t quant_shift = + vshlq_n_s32(vmovl_s16(vld1_s16(mb_plane->quant_shift)), 15); + int32x4_t dequant = vmovl_s16(vld1_s16(dequant_ptr)); + + // Process first 8 values which include a dc component. + { + const uint16x8_t v_iscan = vreinterpretq_u16_s16(vld1q_s16(iscan)); + + const int16x8_t qcoeff = + highbd_quantize_b_neon(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, zbin, round, + quant, quant_shift, dequant); + + // Set non-zero elements to -1 and use that to extract values for eob. + eob_max = vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan); + + __builtin_prefetch(coeff_ptr + 64); + + coeff_ptr += 8; + iscan += 8; + qcoeff_ptr += 8; + dqcoeff_ptr += 8; + } + + n_coeffs -= 8; + + { + zbin = vdupq_lane_s32(vget_low_s32(zbin), 1); + round = vdupq_lane_s32(vget_low_s32(round), 1); + quant = vdupq_lane_s32(vget_low_s32(quant), 1); + quant_shift = vdupq_lane_s32(vget_low_s32(quant_shift), 1); + dequant = vdupq_lane_s32(vget_low_s32(dequant), 1); + + do { + const uint16x8_t v_iscan = vreinterpretq_u16_s16(vld1q_s16(iscan)); + + const int16x8_t qcoeff = + highbd_quantize_b_neon(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, zbin, + round, quant, quant_shift, dequant); + + // Set non-zero elements to -1 and use that to extract values for eob. + eob_max = + vmaxq_u16(eob_max, vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan)); + + __builtin_prefetch(coeff_ptr + 64); + coeff_ptr += 8; + iscan += 8; + qcoeff_ptr += 8; + dqcoeff_ptr += 8; + n_coeffs -= 8; + } while (n_coeffs > 0); + } + +#if VPX_ARCH_AARCH64 + *eob_ptr = vmaxvq_u16(eob_max); +#else + { + const uint16x4_t eob_max_0 = + vmax_u16(vget_low_u16(eob_max), vget_high_u16(eob_max)); + const uint16x4_t eob_max_1 = vpmax_u16(eob_max_0, eob_max_0); + const uint16x4_t eob_max_2 = vpmax_u16(eob_max_1, eob_max_1); + vst1_lane_u16(eob_ptr, eob_max_2, 0); + } +#endif // VPX_ARCH_AARCH64 +} + +static VPX_FORCE_INLINE int32x4_t extract_sign_bit(int32x4_t a) { + return vreinterpretq_s32_u32(vshrq_n_u32(vreinterpretq_u32_s32(a), 31)); +} + +static VPX_FORCE_INLINE void highbd_calculate_dqcoeff_and_store_32x32( + int32x4_t dqcoeff_0, int32x4_t dqcoeff_1, tran_low_t *dqcoeff_ptr) { + // Add 1 if negative to round towards zero because the C uses division. + dqcoeff_0 = vaddq_s32(dqcoeff_0, extract_sign_bit(dqcoeff_0)); + dqcoeff_1 = vaddq_s32(dqcoeff_1, extract_sign_bit(dqcoeff_1)); + + dqcoeff_0 = vshrq_n_s32(dqcoeff_0, 1); + dqcoeff_1 = vshrq_n_s32(dqcoeff_1, 1); + vst1q_s32(dqcoeff_ptr, dqcoeff_0); + vst1q_s32(dqcoeff_ptr + 4, dqcoeff_1); +} + +static VPX_FORCE_INLINE int16x8_t highbd_quantize_b_32x32_neon( + const tran_low_t *coeff_ptr, tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, const int32x4_t zbin, const int32x4_t round, + const int32x4_t quant, const int32x4_t quant_shift, + const int32x4_t dequant) { + int32x4_t qcoeff_0, qcoeff_1, dqcoeff_0, dqcoeff_1; + + // Load coeffs as 2 vectors of 4 x 32-bit ints each, take sign and abs values + const int32x4_t coeff_0 = vld1q_s32(coeff_ptr); + const int32x4_t coeff_1 = vld1q_s32(coeff_ptr + 4); + highbd_quantize_8_neon(coeff_0, coeff_1, zbin, round, quant, quant_shift, + &qcoeff_0, &qcoeff_1); + + // Store the 32-bit qcoeffs + vst1q_s32(qcoeff_ptr, qcoeff_0); + vst1q_s32(qcoeff_ptr + 4, qcoeff_1); + + // Calculate and store the dqcoeffs + dqcoeff_0 = vmulq_s32(qcoeff_0, dequant); + dqcoeff_1 = vmulq_s32(qcoeff_1, vdupq_lane_s32(vget_low_s32(dequant), 1)); + + highbd_calculate_dqcoeff_and_store_32x32(dqcoeff_0, dqcoeff_1, dqcoeff_ptr); + + return vcombine_s16(vmovn_s32(qcoeff_0), vmovn_s32(qcoeff_1)); +} + +void vpx_highbd_quantize_b_32x32_neon( + const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, + uint16_t *eob_ptr, const struct ScanOrder *const scan_order) { + const int16x8_t neg_one = vdupq_n_s16(-1); + uint16x8_t eob_max; + int i; + const int16_t *iscan = scan_order->iscan; + + // Only the first element of each vector is DC. + // High half has identical elements, but we can reconstruct it from the low + // half by duplicating the 2nd element. So we only need to pass a 4x32-bit + // vector + int32x4_t zbin = vrshrq_n_s32(vmovl_s16(vld1_s16(mb_plane->zbin)), 1); + int32x4_t round = vrshrq_n_s32(vmovl_s16(vld1_s16(mb_plane->round)), 1); + // Extend the quant, quant_shift vectors to ones of 32-bit elements + // scale to high-half, so we can use vqdmulhq_s32 + int32x4_t quant = vshlq_n_s32(vmovl_s16(vld1_s16(mb_plane->quant)), 15); + int32x4_t quant_shift = + vshlq_n_s32(vmovl_s16(vld1_s16(mb_plane->quant_shift)), 16); + int32x4_t dequant = vmovl_s16(vld1_s16(dequant_ptr)); + + // Process first 8 values which include a dc component. + { + const uint16x8_t v_iscan = vreinterpretq_u16_s16(vld1q_s16(iscan)); + + const int16x8_t qcoeff = + highbd_quantize_b_32x32_neon(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, zbin, + round, quant, quant_shift, dequant); + + // Set non-zero elements to -1 and use that to extract values for eob. + eob_max = vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan); + + __builtin_prefetch(coeff_ptr + 64); + coeff_ptr += 8; + iscan += 8; + qcoeff_ptr += 8; + dqcoeff_ptr += 8; + } + + { + zbin = vdupq_lane_s32(vget_low_s32(zbin), 1); + round = vdupq_lane_s32(vget_low_s32(round), 1); + quant = vdupq_lane_s32(vget_low_s32(quant), 1); + quant_shift = vdupq_lane_s32(vget_low_s32(quant_shift), 1); + dequant = vdupq_lane_s32(vget_low_s32(dequant), 1); + + for (i = 1; i < 32 * 32 / 8; ++i) { + const uint16x8_t v_iscan = vreinterpretq_u16_s16(vld1q_s16(iscan)); + + const int16x8_t qcoeff = + highbd_quantize_b_32x32_neon(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, zbin, + round, quant, quant_shift, dequant); + + // Set non-zero elements to -1 and use that to extract values for eob. + eob_max = + vmaxq_u16(eob_max, vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan)); + + __builtin_prefetch(coeff_ptr + 64); + coeff_ptr += 8; + iscan += 8; + qcoeff_ptr += 8; + dqcoeff_ptr += 8; + } + } + +#if VPX_ARCH_AARCH64 + *eob_ptr = vmaxvq_u16(eob_max); +#else + { + const uint16x4_t eob_max_0 = + vmax_u16(vget_low_u16(eob_max), vget_high_u16(eob_max)); + const uint16x4_t eob_max_1 = vpmax_u16(eob_max_0, eob_max_0); + const uint16x4_t eob_max_2 = vpmax_u16(eob_max_1, eob_max_1); + vst1_lane_u16(eob_ptr, eob_max_2, 0); + } +#endif // VPX_ARCH_AARCH64 +} diff --git a/libs/libvpx/vpx_dsp/arm/highbd_sad4d_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_sad4d_neon.c new file mode 100644 index 0000000000..6e64618c9f --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_sad4d_neon.c @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" + +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" + +static INLINE void highbd_sad4xhx4d_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *const ref_ptr[4], + int ref_stride, uint32_t res[4], + int h) { + const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr); + const uint16_t *ref16_ptr0 = CONVERT_TO_SHORTPTR(ref_ptr[0]); + const uint16_t *ref16_ptr1 = CONVERT_TO_SHORTPTR(ref_ptr[1]); + const uint16_t *ref16_ptr2 = CONVERT_TO_SHORTPTR(ref_ptr[2]); + const uint16_t *ref16_ptr3 = CONVERT_TO_SHORTPTR(ref_ptr[3]); + + uint32x4_t sum[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), + vdupq_n_u32(0) }; + + int i = 0; + do { + uint16x4_t s = vld1_u16(src16_ptr + i * src_stride); + uint16x4_t r0 = vld1_u16(ref16_ptr0 + i * ref_stride); + uint16x4_t r1 = vld1_u16(ref16_ptr1 + i * ref_stride); + uint16x4_t r2 = vld1_u16(ref16_ptr2 + i * ref_stride); + uint16x4_t r3 = vld1_u16(ref16_ptr3 + i * ref_stride); + + sum[0] = vabal_u16(sum[0], s, r0); + sum[1] = vabal_u16(sum[1], s, r1); + sum[2] = vabal_u16(sum[2], s, r2); + sum[3] = vabal_u16(sum[3], s, r3); + + } while (++i < h); + + vst1q_u32(res, horizontal_add_4d_uint32x4(sum)); +} + +static INLINE void highbd_sad8xhx4d_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *const ref_ptr[4], + int ref_stride, uint32_t res[4], + int h) { + const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr); + const uint16_t *ref16_ptr0 = CONVERT_TO_SHORTPTR(ref_ptr[0]); + const uint16_t *ref16_ptr1 = CONVERT_TO_SHORTPTR(ref_ptr[1]); + const uint16_t *ref16_ptr2 = CONVERT_TO_SHORTPTR(ref_ptr[2]); + const uint16_t *ref16_ptr3 = CONVERT_TO_SHORTPTR(ref_ptr[3]); + + uint16x8_t sum[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), + vdupq_n_u16(0) }; + assert(h <= 16); + + int i = 0; + do { + uint16x8_t s = vld1q_u16(src16_ptr + i * src_stride); + + sum[0] = vabaq_u16(sum[0], s, vld1q_u16(ref16_ptr0 + i * ref_stride)); + sum[1] = vabaq_u16(sum[1], s, vld1q_u16(ref16_ptr1 + i * ref_stride)); + sum[2] = vabaq_u16(sum[2], s, vld1q_u16(ref16_ptr2 + i * ref_stride)); + sum[3] = vabaq_u16(sum[3], s, vld1q_u16(ref16_ptr3 + i * ref_stride)); + + } while (++i < h); + + uint32x4_t sum_u32[4]; + sum_u32[0] = vpaddlq_u16(sum[0]); + sum_u32[1] = vpaddlq_u16(sum[1]); + sum_u32[2] = vpaddlq_u16(sum[2]); + sum_u32[3] = vpaddlq_u16(sum[3]); + vst1q_u32(res, horizontal_add_4d_uint32x4(sum_u32)); +} + +static INLINE void highbd_sadwxhx4d_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *const ref_ptr[4], + int ref_stride, uint32_t res[4], int w, + int h, const int h_overflow) { + const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr); + const uint16_t *ref16_ptr0 = CONVERT_TO_SHORTPTR(ref_ptr[0]); + const uint16_t *ref16_ptr1 = CONVERT_TO_SHORTPTR(ref_ptr[1]); + const uint16_t *ref16_ptr2 = CONVERT_TO_SHORTPTR(ref_ptr[2]); + const uint16_t *ref16_ptr3 = CONVERT_TO_SHORTPTR(ref_ptr[3]); + + uint32x4_t sum_u32[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), + vdupq_n_u32(0) }; + + const int h_limit = h < h_overflow ? h : h_overflow; + assert(h % h_limit == 0); + + do { + uint16x8_t sum_u16[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), + vdupq_n_u16(0) }; + int i = h_limit; + do { + int j = 0; + do { + uint16x8_t s0 = vld1q_u16(src16_ptr + j); + sum_u16[0] = vabaq_u16(sum_u16[0], s0, vld1q_u16(ref16_ptr0 + j)); + sum_u16[1] = vabaq_u16(sum_u16[1], s0, vld1q_u16(ref16_ptr1 + j)); + sum_u16[2] = vabaq_u16(sum_u16[2], s0, vld1q_u16(ref16_ptr2 + j)); + sum_u16[3] = vabaq_u16(sum_u16[3], s0, vld1q_u16(ref16_ptr3 + j)); + + uint16x8_t s1 = vld1q_u16(src16_ptr + j + 8); + sum_u16[0] = vabaq_u16(sum_u16[0], s1, vld1q_u16(ref16_ptr0 + j + 8)); + sum_u16[1] = vabaq_u16(sum_u16[1], s1, vld1q_u16(ref16_ptr1 + j + 8)); + sum_u16[2] = vabaq_u16(sum_u16[2], s1, vld1q_u16(ref16_ptr2 + j + 8)); + sum_u16[3] = vabaq_u16(sum_u16[3], s1, vld1q_u16(ref16_ptr3 + j + 8)); + + j += 16; + } while (j < w); + + src16_ptr += src_stride; + ref16_ptr0 += ref_stride; + ref16_ptr1 += ref_stride; + ref16_ptr2 += ref_stride; + ref16_ptr3 += ref_stride; + } while (--i != 0); + + sum_u32[0] = vpadalq_u16(sum_u32[0], sum_u16[0]); + sum_u32[1] = vpadalq_u16(sum_u32[1], sum_u16[1]); + sum_u32[2] = vpadalq_u16(sum_u32[2], sum_u16[2]); + sum_u32[3] = vpadalq_u16(sum_u32[3], sum_u16[3]); + + h -= h_limit; + } while (h != 0); + + vst1q_u32(res, horizontal_add_4d_uint32x4(sum_u32)); +} + +static INLINE void highbd_sad16xhx4d_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *const ref_ptr[4], + int ref_stride, uint32_t res[4], + int h) { + // 'h_overflow' is the number of 16-wide rows we can process before 16-bit + // accumulators overflow. After hitting this limit accumulate into 32-bit + // elements. 65535 / 4095 ~= 16, so 8 16-wide rows. + const int h_overflow = 8; + highbd_sadwxhx4d_neon(src_ptr, src_stride, ref_ptr, ref_stride, res, 16, h, + h_overflow); +} + +static INLINE void highbd_sad32xhx4d_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *const ref_ptr[4], + int ref_stride, uint32_t res[4], + int h) { + // 'h_overflow' is the number of 32-wide rows we can process before 16-bit + // accumulators overflow. After hitting this limit accumulate into 32-bit + // elements. 65535 / 4095 ~= 16, so 4 32-wide rows. + const int h_overflow = 4; + highbd_sadwxhx4d_neon(src_ptr, src_stride, ref_ptr, ref_stride, res, 32, h, + h_overflow); +} + +static INLINE void highbd_sad64xhx4d_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *const ref_ptr[4], + int ref_stride, uint32_t res[4], + int h) { + // 'h_overflow' is the number of 64-wide rows we can process before 16-bit + // accumulators overflow. After hitting this limit accumulate into 32-bit + // elements. 65535 / 4095 ~= 16, so 2 64-wide rows. + const int h_overflow = 2; + highbd_sadwxhx4d_neon(src_ptr, src_stride, ref_ptr, ref_stride, res, 64, h, + h_overflow); +} + +#define HBD_SAD_WXH_4D_NEON(w, h) \ + void vpx_highbd_sad##w##x##h##x4d_neon( \ + const uint8_t *src, int src_stride, const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + highbd_sad##w##xhx4d_neon(src, src_stride, ref_array, ref_stride, \ + sad_array, (h)); \ + } + +HBD_SAD_WXH_4D_NEON(4, 4) +HBD_SAD_WXH_4D_NEON(4, 8) + +HBD_SAD_WXH_4D_NEON(8, 4) +HBD_SAD_WXH_4D_NEON(8, 8) +HBD_SAD_WXH_4D_NEON(8, 16) + +HBD_SAD_WXH_4D_NEON(16, 8) +HBD_SAD_WXH_4D_NEON(16, 16) +HBD_SAD_WXH_4D_NEON(16, 32) + +HBD_SAD_WXH_4D_NEON(32, 16) +HBD_SAD_WXH_4D_NEON(32, 32) +HBD_SAD_WXH_4D_NEON(32, 64) + +HBD_SAD_WXH_4D_NEON(64, 32) +HBD_SAD_WXH_4D_NEON(64, 64) + +#undef HBD_SAD_WXH_4D_NEON + +#define HBD_SAD_SKIP_WXH_4D_NEON(w, h) \ + void vpx_highbd_sad_skip_##w##x##h##x4d_neon( \ + const uint8_t *src, int src_stride, const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + highbd_sad##w##xhx4d_neon(src, 2 * src_stride, ref_array, 2 * ref_stride, \ + sad_array, ((h) >> 1)); \ + sad_array[0] <<= 1; \ + sad_array[1] <<= 1; \ + sad_array[2] <<= 1; \ + sad_array[3] <<= 1; \ + } + +HBD_SAD_SKIP_WXH_4D_NEON(4, 4) +HBD_SAD_SKIP_WXH_4D_NEON(4, 8) + +HBD_SAD_SKIP_WXH_4D_NEON(8, 4) +HBD_SAD_SKIP_WXH_4D_NEON(8, 8) +HBD_SAD_SKIP_WXH_4D_NEON(8, 16) + +HBD_SAD_SKIP_WXH_4D_NEON(16, 8) +HBD_SAD_SKIP_WXH_4D_NEON(16, 16) +HBD_SAD_SKIP_WXH_4D_NEON(16, 32) + +HBD_SAD_SKIP_WXH_4D_NEON(32, 16) +HBD_SAD_SKIP_WXH_4D_NEON(32, 32) +HBD_SAD_SKIP_WXH_4D_NEON(32, 64) + +HBD_SAD_SKIP_WXH_4D_NEON(64, 32) +HBD_SAD_SKIP_WXH_4D_NEON(64, 64) + +#undef HBD_SAD_SKIP_WXH_4D_NEON \ No newline at end of file diff --git a/libs/libvpx/vpx_dsp/arm/highbd_sad_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_sad_neon.c new file mode 100644 index 0000000000..af36431036 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_sad_neon.c @@ -0,0 +1,452 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" + +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" + +static INLINE uint32_t highbd_sad4xh_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h) { + const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr); + const uint16_t *ref16_ptr = CONVERT_TO_SHORTPTR(ref_ptr); + uint32x4_t sum = vdupq_n_u32(0); + + do { + uint16x4_t s = vld1_u16(src16_ptr); + uint16x4_t r = vld1_u16(ref16_ptr); + sum = vabal_u16(sum, s, r); + + src16_ptr += src_stride; + ref16_ptr += ref_stride; + } while (--h != 0); + + return horizontal_add_uint32x4(sum); +} + +static INLINE uint32_t highbd_sad8xh_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h) { + const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr); + const uint16_t *ref16_ptr = CONVERT_TO_SHORTPTR(ref_ptr); + uint16x8_t sum = vdupq_n_u16(0); + assert(h <= 16); + + do { + uint16x8_t s = vld1q_u16(src16_ptr); + uint16x8_t r = vld1q_u16(ref16_ptr); + sum = vabaq_u16(sum, s, r); + + src16_ptr += src_stride; + ref16_ptr += ref_stride; + } while (--h != 0); + + return horizontal_add_uint16x8(sum); +} + +static INLINE uint32_t highbd_sad16xh_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h) { + const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr); + const uint16_t *ref16_ptr = CONVERT_TO_SHORTPTR(ref_ptr); + uint32x4_t sum_u32 = vdupq_n_u32(0); + + // 'h_overflow' is the number of 16-wide rows we can process before 16-bit + // accumulators overflow. After hitting this limit accumulate into 32-bit + // elements. 65535 / 4095 ~= 16, so 16 16-wide rows using two accumulators. + const int h_overflow = 16; + // If block height 'h' is smaller than this limit, use 'h' instead. + const int h_limit = h < h_overflow ? h : h_overflow; + assert(h % h_limit == 0); + + do { + uint16x8_t sum_u16[2] = { vdupq_n_u16(0), vdupq_n_u16(0) }; + int i = h_limit; + do { + uint16x8_t s0, s1, r0, r1; + + s0 = vld1q_u16(src16_ptr); + r0 = vld1q_u16(ref16_ptr); + sum_u16[0] = vabaq_u16(sum_u16[0], s0, r0); + + s1 = vld1q_u16(src16_ptr + 8); + r1 = vld1q_u16(ref16_ptr + 8); + sum_u16[1] = vabaq_u16(sum_u16[1], s1, r1); + + src16_ptr += src_stride; + ref16_ptr += ref_stride; + } while (--i != 0); + + sum_u32 = vpadalq_u16(sum_u32, sum_u16[0]); + sum_u32 = vpadalq_u16(sum_u32, sum_u16[1]); + h -= h_limit; + } while (h != 0); + return horizontal_add_uint32x4(sum_u32); +} + +static INLINE uint32_t highbd_sadwxh_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int w, int h, + const int h_overflow) { + const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr); + const uint16_t *ref16_ptr = CONVERT_TO_SHORTPTR(ref_ptr); + uint32x4_t sum_u32 = vdupq_n_u32(0); + const int h_limit = h < h_overflow ? h : h_overflow; + assert(h % h_limit == 0); + + do { + uint16x8_t sum_u16[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), + vdupq_n_u16(0) }; + int i = 0; + do { + int j = 0; + do { + uint16x8_t s0, s1, s2, s3, r0, r1, r2, r3; + + s0 = vld1q_u16(src16_ptr + j); + r0 = vld1q_u16(ref16_ptr + j); + sum_u16[0] = vabaq_u16(sum_u16[0], s0, r0); + + s1 = vld1q_u16(src16_ptr + j + 8); + r1 = vld1q_u16(ref16_ptr + j + 8); + sum_u16[1] = vabaq_u16(sum_u16[1], s1, r1); + + s2 = vld1q_u16(src16_ptr + j + 16); + r2 = vld1q_u16(ref16_ptr + j + 16); + sum_u16[2] = vabaq_u16(sum_u16[2], s2, r2); + + s3 = vld1q_u16(src16_ptr + j + 24); + r3 = vld1q_u16(ref16_ptr + j + 24); + sum_u16[3] = vabaq_u16(sum_u16[3], s3, r3); + + j += 32; + } while (j < w); + src16_ptr += src_stride; + ref16_ptr += ref_stride; + } while (++i != h_limit); + + sum_u32 = vpadalq_u16(sum_u32, sum_u16[0]); + sum_u32 = vpadalq_u16(sum_u32, sum_u16[1]); + sum_u32 = vpadalq_u16(sum_u32, sum_u16[2]); + sum_u32 = vpadalq_u16(sum_u32, sum_u16[3]); + h -= h_limit; + } while (h != 0); + return horizontal_add_uint32x4(sum_u32); +} + +static INLINE uint32_t highbd_sad32xh_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h) { + // 'h_overflow' is the number of 32-wide rows we can process before 16-bit + // accumulators overflow. After hitting this limit accumulate into 32-bit + // elements. 65535 / 4095 ~= 16, so 16 32-wide rows using four accumulators. + const int h_overflow = 16; + return highbd_sadwxh_neon(src_ptr, src_stride, ref_ptr, ref_stride, 32, h, + h_overflow); +} + +static INLINE uint32_t highbd_sad64xh_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h) { + // 'h_overflow' is the number of 64-wide rows we can process before 16-bit + // accumulators overflow. After hitting this limit accumulate into 32-bit + // elements. 65535 / 4095 ~= 16, so 8 64-wide rows using four accumulators. + const int h_overflow = 8; + return highbd_sadwxh_neon(src_ptr, src_stride, ref_ptr, ref_stride, 64, h, + h_overflow); +} + +#define HBD_SAD_WXH_NEON(w, h) \ + unsigned int vpx_highbd_sad##w##x##h##_neon( \ + const uint8_t *src, int src_stride, const uint8_t *ref, \ + int ref_stride) { \ + return highbd_sad##w##xh_neon(src, src_stride, ref, ref_stride, (h)); \ + } + +HBD_SAD_WXH_NEON(4, 4) +HBD_SAD_WXH_NEON(4, 8) + +HBD_SAD_WXH_NEON(8, 4) +HBD_SAD_WXH_NEON(8, 8) +HBD_SAD_WXH_NEON(8, 16) + +HBD_SAD_WXH_NEON(16, 8) +HBD_SAD_WXH_NEON(16, 16) +HBD_SAD_WXH_NEON(16, 32) + +HBD_SAD_WXH_NEON(32, 16) +HBD_SAD_WXH_NEON(32, 32) +HBD_SAD_WXH_NEON(32, 64) + +HBD_SAD_WXH_NEON(64, 32) +HBD_SAD_WXH_NEON(64, 64) + +#undef HBD_SAD_WXH_NEON + +#define HBD_SAD_SKIP_WXH_NEON(w, h) \ + unsigned int vpx_highbd_sad_skip_##w##x##h##_neon( \ + const uint8_t *src, int src_stride, const uint8_t *ref, \ + int ref_stride) { \ + return 2 * highbd_sad##w##xh_neon(src, 2 * src_stride, ref, \ + 2 * ref_stride, (h) / 2); \ + } + +HBD_SAD_SKIP_WXH_NEON(4, 4) +HBD_SAD_SKIP_WXH_NEON(4, 8) + +HBD_SAD_SKIP_WXH_NEON(8, 4) +HBD_SAD_SKIP_WXH_NEON(8, 8) +HBD_SAD_SKIP_WXH_NEON(8, 16) + +HBD_SAD_SKIP_WXH_NEON(16, 8) +HBD_SAD_SKIP_WXH_NEON(16, 16) +HBD_SAD_SKIP_WXH_NEON(16, 32) + +HBD_SAD_SKIP_WXH_NEON(32, 16) +HBD_SAD_SKIP_WXH_NEON(32, 32) +HBD_SAD_SKIP_WXH_NEON(32, 64) + +HBD_SAD_SKIP_WXH_NEON(64, 32) +HBD_SAD_SKIP_WXH_NEON(64, 64) + +#undef HBD_SAD_SKIP_WXH_NEON + +static INLINE uint32_t highbd_sad4xh_avg_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + const uint8_t *second_pred) { + const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr); + const uint16_t *ref16_ptr = CONVERT_TO_SHORTPTR(ref_ptr); + const uint16_t *pred16_ptr = CONVERT_TO_SHORTPTR(second_pred); + uint32x4_t sum = vdupq_n_u32(0); + + do { + uint16x4_t s = vld1_u16(src16_ptr); + uint16x4_t r = vld1_u16(ref16_ptr); + uint16x4_t p = vld1_u16(pred16_ptr); + + uint16x4_t avg = vrhadd_u16(r, p); + sum = vabal_u16(sum, s, avg); + + src16_ptr += src_stride; + ref16_ptr += ref_stride; + pred16_ptr += 4; + } while (--h != 0); + + return horizontal_add_uint32x4(sum); +} + +static INLINE uint32_t highbd_sad8xh_avg_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + const uint8_t *second_pred) { + const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr); + const uint16_t *ref16_ptr = CONVERT_TO_SHORTPTR(ref_ptr); + const uint16_t *pred16_ptr = CONVERT_TO_SHORTPTR(second_pred); + uint16x8_t sum = vdupq_n_u16(0); + assert(h <= 16); + + do { + uint16x8_t s = vld1q_u16(src16_ptr); + uint16x8_t r = vld1q_u16(ref16_ptr); + uint16x8_t p = vld1q_u16(pred16_ptr); + + uint16x8_t avg = vrhaddq_u16(r, p); + sum = vabaq_u16(sum, s, avg); + + src16_ptr += src_stride; + ref16_ptr += ref_stride; + pred16_ptr += 8; + } while (--h != 0); + + return horizontal_add_uint16x8(sum); +} + +static INLINE uint32_t highbd_sad16xh_avg_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + const uint8_t *second_pred) { + const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr); + const uint16_t *ref16_ptr = CONVERT_TO_SHORTPTR(ref_ptr); + const uint16_t *pred16_ptr = CONVERT_TO_SHORTPTR(second_pred); + uint32x4_t sum_u32 = vdupq_n_u32(0); + + // 'h_overflow' is the number of 16-wide rows we can process before 16-bit + // accumulators overflow. After hitting this limit accumulate into 32-bit + // elements. 65535 / 4095 ~= 16, so 16 16-wide rows using two accumulators. + const int h_overflow = 16; + // If block height 'h' is smaller than this limit, use 'h' instead. + const int h_limit = h < h_overflow ? h : h_overflow; + assert(h % h_limit == 0); + + do { + uint16x8_t sum_u16[2] = { vdupq_n_u16(0), vdupq_n_u16(0) }; + int i = h_limit; + do { + uint16x8_t s0, s1, r0, r1, p0, p1; + uint16x8_t avg0, avg1; + + s0 = vld1q_u16(src16_ptr); + r0 = vld1q_u16(ref16_ptr); + p0 = vld1q_u16(pred16_ptr); + avg0 = vrhaddq_u16(r0, p0); + sum_u16[0] = vabaq_u16(sum_u16[0], s0, avg0); + + s1 = vld1q_u16(src16_ptr + 8); + r1 = vld1q_u16(ref16_ptr + 8); + p1 = vld1q_u16(pred16_ptr + 8); + avg1 = vrhaddq_u16(r1, p1); + sum_u16[1] = vabaq_u16(sum_u16[1], s1, avg1); + + src16_ptr += src_stride; + ref16_ptr += ref_stride; + pred16_ptr += 16; + } while (--i != 0); + + sum_u32 = vpadalq_u16(sum_u32, sum_u16[0]); + sum_u32 = vpadalq_u16(sum_u32, sum_u16[1]); + h -= h_limit; + } while (h != 0); + return horizontal_add_uint32x4(sum_u32); +} + +static INLINE uint32_t highbd_sadwxh_avg_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int w, int h, + const uint8_t *second_pred, + const int h_overflow) { + const uint16_t *src16_ptr = CONVERT_TO_SHORTPTR(src_ptr); + const uint16_t *ref16_ptr = CONVERT_TO_SHORTPTR(ref_ptr); + const uint16_t *pred16_ptr = CONVERT_TO_SHORTPTR(second_pred); + uint32x4_t sum_u32 = vdupq_n_u32(0); + const int h_limit = h < h_overflow ? h : h_overflow; + assert(h % h_limit == 0); + + do { + uint16x8_t sum_u16[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), + vdupq_n_u16(0) }; + + int i = h_limit; + do { + int j = 0; + do { + uint16x8_t s0, s1, s2, s3, r0, r1, r2, r3, p0, p1, p2, p3; + uint16x8_t avg0, avg1, avg2, avg3; + + s0 = vld1q_u16(src16_ptr + j); + r0 = vld1q_u16(ref16_ptr + j); + p0 = vld1q_u16(pred16_ptr + j); + avg0 = vrhaddq_u16(r0, p0); + sum_u16[0] = vabaq_u16(sum_u16[0], s0, avg0); + + s1 = vld1q_u16(src16_ptr + j + 8); + r1 = vld1q_u16(ref16_ptr + j + 8); + p1 = vld1q_u16(pred16_ptr + j + 8); + avg1 = vrhaddq_u16(r1, p1); + sum_u16[1] = vabaq_u16(sum_u16[1], s1, avg1); + + s2 = vld1q_u16(src16_ptr + j + 16); + r2 = vld1q_u16(ref16_ptr + j + 16); + p2 = vld1q_u16(pred16_ptr + j + 16); + avg2 = vrhaddq_u16(r2, p2); + sum_u16[2] = vabaq_u16(sum_u16[2], s2, avg2); + + s3 = vld1q_u16(src16_ptr + j + 24); + r3 = vld1q_u16(ref16_ptr + j + 24); + p3 = vld1q_u16(pred16_ptr + j + 24); + avg3 = vrhaddq_u16(r3, p3); + sum_u16[3] = vabaq_u16(sum_u16[3], s3, avg3); + + j += 32; + } while (j < w); + + src16_ptr += src_stride; + ref16_ptr += ref_stride; + pred16_ptr += w; + } while (--i != 0); + + sum_u32 = vpadalq_u16(sum_u32, sum_u16[0]); + sum_u32 = vpadalq_u16(sum_u32, sum_u16[1]); + sum_u32 = vpadalq_u16(sum_u32, sum_u16[2]); + sum_u32 = vpadalq_u16(sum_u32, sum_u16[3]); + h -= h_limit; + } while (h != 0); + return horizontal_add_uint32x4(sum_u32); +} + +static INLINE uint32_t highbd_sad32xh_avg_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + const uint8_t *second_pred) { + // 'h_overflow' is the number of 32-wide rows we can process before 16-bit + // accumulators overflow. After hitting this limit accumulate into 32-bit + // elements. 65535 / 4095 ~= 16, so 16 32-wide rows using four accumulators. + const int h_overflow = 16; + return highbd_sadwxh_avg_neon(src_ptr, src_stride, ref_ptr, ref_stride, 32, h, + second_pred, h_overflow); +} + +static INLINE uint32_t highbd_sad64xh_avg_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + const uint8_t *second_pred) { + // 'h_overflow' is the number of 64-wide rows we can process before 16-bit + // accumulators overflow. After hitting this limit accumulate into 32-bit + // elements. 65535 / 4095 ~= 16, so 8 64-wide rows using four accumulators. + const int h_overflow = 8; + return highbd_sadwxh_avg_neon(src_ptr, src_stride, ref_ptr, ref_stride, 64, h, + second_pred, h_overflow); +} + +#define HBD_SAD_WXH_AVG_NEON(w, h) \ + unsigned int vpx_highbd_sad##w##x##h##_avg_neon( \ + const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \ + const uint8_t *second_pred) { \ + return highbd_sad##w##xh_avg_neon(src, src_stride, ref, ref_stride, (h), \ + second_pred); \ + } + +HBD_SAD_WXH_AVG_NEON(4, 4) +HBD_SAD_WXH_AVG_NEON(4, 8) + +HBD_SAD_WXH_AVG_NEON(8, 4) +HBD_SAD_WXH_AVG_NEON(8, 8) +HBD_SAD_WXH_AVG_NEON(8, 16) + +HBD_SAD_WXH_AVG_NEON(16, 8) +HBD_SAD_WXH_AVG_NEON(16, 16) +HBD_SAD_WXH_AVG_NEON(16, 32) + +HBD_SAD_WXH_AVG_NEON(32, 16) +HBD_SAD_WXH_AVG_NEON(32, 32) +HBD_SAD_WXH_AVG_NEON(32, 64) + +HBD_SAD_WXH_AVG_NEON(64, 32) +HBD_SAD_WXH_AVG_NEON(64, 64) + +#undef HBD_SAD_WXH_AVG_NEON diff --git a/libs/libvpx/vpx_dsp/arm/highbd_sse_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_sse_neon.c new file mode 100644 index 0000000000..91dfebf900 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_sse_neon.c @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_dsp_rtcd.h" +#include "vpx_dsp/arm/sum_neon.h" + +static INLINE void highbd_sse_8x1_init_neon(const uint16_t *src, + const uint16_t *ref, + uint32x4_t *sse_acc0, + uint32x4_t *sse_acc1) { + uint16x8_t s = vld1q_u16(src); + uint16x8_t r = vld1q_u16(ref); + + uint16x8_t abs_diff = vabdq_u16(s, r); + uint16x4_t abs_diff_lo = vget_low_u16(abs_diff); + uint16x4_t abs_diff_hi = vget_high_u16(abs_diff); + + *sse_acc0 = vmull_u16(abs_diff_lo, abs_diff_lo); + *sse_acc1 = vmull_u16(abs_diff_hi, abs_diff_hi); +} + +static INLINE void highbd_sse_8x1_neon(const uint16_t *src, const uint16_t *ref, + uint32x4_t *sse_acc0, + uint32x4_t *sse_acc1) { + uint16x8_t s = vld1q_u16(src); + uint16x8_t r = vld1q_u16(ref); + + uint16x8_t abs_diff = vabdq_u16(s, r); + uint16x4_t abs_diff_lo = vget_low_u16(abs_diff); + uint16x4_t abs_diff_hi = vget_high_u16(abs_diff); + + *sse_acc0 = vmlal_u16(*sse_acc0, abs_diff_lo, abs_diff_lo); + *sse_acc1 = vmlal_u16(*sse_acc1, abs_diff_hi, abs_diff_hi); +} + +static INLINE int64_t highbd_sse_64xh_neon(const uint16_t *src, int src_stride, + const uint16_t *ref, int ref_stride, + int height) { + uint32x4_t sse[8]; + highbd_sse_8x1_init_neon(src + 0 * 8, ref + 0 * 8, &sse[0], &sse[1]); + highbd_sse_8x1_init_neon(src + 1 * 8, ref + 1 * 8, &sse[2], &sse[3]); + highbd_sse_8x1_init_neon(src + 2 * 8, ref + 2 * 8, &sse[4], &sse[5]); + highbd_sse_8x1_init_neon(src + 3 * 8, ref + 3 * 8, &sse[6], &sse[7]); + highbd_sse_8x1_neon(src + 4 * 8, ref + 4 * 8, &sse[0], &sse[1]); + highbd_sse_8x1_neon(src + 5 * 8, ref + 5 * 8, &sse[2], &sse[3]); + highbd_sse_8x1_neon(src + 6 * 8, ref + 6 * 8, &sse[4], &sse[5]); + highbd_sse_8x1_neon(src + 7 * 8, ref + 7 * 8, &sse[6], &sse[7]); + + src += src_stride; + ref += ref_stride; + + while (--height != 0) { + highbd_sse_8x1_neon(src + 0 * 8, ref + 0 * 8, &sse[0], &sse[1]); + highbd_sse_8x1_neon(src + 1 * 8, ref + 1 * 8, &sse[2], &sse[3]); + highbd_sse_8x1_neon(src + 2 * 8, ref + 2 * 8, &sse[4], &sse[5]); + highbd_sse_8x1_neon(src + 3 * 8, ref + 3 * 8, &sse[6], &sse[7]); + highbd_sse_8x1_neon(src + 4 * 8, ref + 4 * 8, &sse[0], &sse[1]); + highbd_sse_8x1_neon(src + 5 * 8, ref + 5 * 8, &sse[2], &sse[3]); + highbd_sse_8x1_neon(src + 6 * 8, ref + 6 * 8, &sse[4], &sse[5]); + highbd_sse_8x1_neon(src + 7 * 8, ref + 7 * 8, &sse[6], &sse[7]); + + src += src_stride; + ref += ref_stride; + } + + return horizontal_long_add_uint32x4_x8(sse); +} + +static INLINE int64_t highbd_sse_32xh_neon(const uint16_t *src, int src_stride, + const uint16_t *ref, int ref_stride, + int height) { + uint32x4_t sse[8]; + highbd_sse_8x1_init_neon(src + 0 * 8, ref + 0 * 8, &sse[0], &sse[1]); + highbd_sse_8x1_init_neon(src + 1 * 8, ref + 1 * 8, &sse[2], &sse[3]); + highbd_sse_8x1_init_neon(src + 2 * 8, ref + 2 * 8, &sse[4], &sse[5]); + highbd_sse_8x1_init_neon(src + 3 * 8, ref + 3 * 8, &sse[6], &sse[7]); + + src += src_stride; + ref += ref_stride; + + while (--height != 0) { + highbd_sse_8x1_neon(src + 0 * 8, ref + 0 * 8, &sse[0], &sse[1]); + highbd_sse_8x1_neon(src + 1 * 8, ref + 1 * 8, &sse[2], &sse[3]); + highbd_sse_8x1_neon(src + 2 * 8, ref + 2 * 8, &sse[4], &sse[5]); + highbd_sse_8x1_neon(src + 3 * 8, ref + 3 * 8, &sse[6], &sse[7]); + + src += src_stride; + ref += ref_stride; + } + + return horizontal_long_add_uint32x4_x8(sse); +} + +static INLINE int64_t highbd_sse_16xh_neon(const uint16_t *src, int src_stride, + const uint16_t *ref, int ref_stride, + int height) { + uint32x4_t sse[4]; + highbd_sse_8x1_init_neon(src + 0 * 8, ref + 0 * 8, &sse[0], &sse[1]); + highbd_sse_8x1_init_neon(src + 1 * 8, ref + 1 * 8, &sse[2], &sse[3]); + + src += src_stride; + ref += ref_stride; + + while (--height != 0) { + highbd_sse_8x1_neon(src + 0 * 8, ref + 0 * 8, &sse[0], &sse[1]); + highbd_sse_8x1_neon(src + 1 * 8, ref + 1 * 8, &sse[2], &sse[3]); + + src += src_stride; + ref += ref_stride; + } + + return horizontal_long_add_uint32x4_x4(sse); +} + +static INLINE int64_t highbd_sse_8xh_neon(const uint16_t *src, int src_stride, + const uint16_t *ref, int ref_stride, + int height) { + uint32x4_t sse[2]; + highbd_sse_8x1_init_neon(src, ref, &sse[0], &sse[1]); + + src += src_stride; + ref += ref_stride; + + while (--height != 0) { + highbd_sse_8x1_neon(src, ref, &sse[0], &sse[1]); + + src += src_stride; + ref += ref_stride; + } + + return horizontal_long_add_uint32x4_x2(sse); +} + +static INLINE int64_t highbd_sse_4xh_neon(const uint16_t *src, int src_stride, + const uint16_t *ref, int ref_stride, + int height) { + // Peel the first loop iteration. + uint16x4_t s = vld1_u16(src); + uint16x4_t r = vld1_u16(ref); + + uint16x4_t abs_diff = vabd_u16(s, r); + uint32x4_t sse = vmull_u16(abs_diff, abs_diff); + + src += src_stride; + ref += ref_stride; + + while (--height != 0) { + s = vld1_u16(src); + r = vld1_u16(ref); + + abs_diff = vabd_u16(s, r); + sse = vmlal_u16(sse, abs_diff, abs_diff); + + src += src_stride; + ref += ref_stride; + } + + return horizontal_long_add_uint32x4(sse); +} + +static INLINE int64_t highbd_sse_wxh_neon(const uint16_t *src, int src_stride, + const uint16_t *ref, int ref_stride, + int width, int height) { + // { 0, 1, 2, 3, 4, 5, 6, 7 } + uint16x8_t k01234567 = vmovl_u8(vcreate_u8(0x0706050403020100)); + uint16x8_t remainder_mask = vcltq_u16(k01234567, vdupq_n_u16(width & 7)); + uint64_t sse = 0; + + do { + int w = width; + int offset = 0; + + do { + uint16x8_t s = vld1q_u16(src + offset); + uint16x8_t r = vld1q_u16(ref + offset); + uint16x8_t abs_diff; + uint16x4_t abs_diff_lo; + uint16x4_t abs_diff_hi; + uint32x4_t sse_u32; + + if (w < 8) { + // Mask out-of-range elements. + s = vandq_u16(s, remainder_mask); + r = vandq_u16(r, remainder_mask); + } + + abs_diff = vabdq_u16(s, r); + abs_diff_lo = vget_low_u16(abs_diff); + abs_diff_hi = vget_high_u16(abs_diff); + + sse_u32 = vmull_u16(abs_diff_lo, abs_diff_lo); + sse_u32 = vmlal_u16(sse_u32, abs_diff_hi, abs_diff_hi); + + sse += horizontal_long_add_uint32x4(sse_u32); + + offset += 8; + w -= 8; + } while (w > 0); + + src += src_stride; + ref += ref_stride; + } while (--height != 0); + + return sse; +} + +int64_t vpx_highbd_sse_neon(const uint8_t *src8, int src_stride, + const uint8_t *ref8, int ref_stride, int width, + int height) { + uint16_t *src = CONVERT_TO_SHORTPTR(src8); + uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); + + switch (width) { + case 4: + return highbd_sse_4xh_neon(src, src_stride, ref, ref_stride, height); + case 8: + return highbd_sse_8xh_neon(src, src_stride, ref, ref_stride, height); + case 16: + return highbd_sse_16xh_neon(src, src_stride, ref, ref_stride, height); + case 32: + return highbd_sse_32xh_neon(src, src_stride, ref, ref_stride, height); + case 64: + return highbd_sse_64xh_neon(src, src_stride, ref, ref_stride, height); + default: + return highbd_sse_wxh_neon(src, src_stride, ref, ref_stride, width, + height); + } +} diff --git a/libs/libvpx/vpx_dsp/arm/highbd_subpel_variance_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_subpel_variance_neon.c new file mode 100644 index 0000000000..f8b94620d4 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_subpel_variance_neon.c @@ -0,0 +1,586 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_dsp_rtcd.h" +#include "./vpx_config.h" + +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" + +// The bilinear filters look like this: +// +// {{ 128, 0 }, { 112, 16 }, { 96, 32 }, { 80, 48 }, +// { 64, 64 }, { 48, 80 }, { 32, 96 }, { 16, 112 }} +// +// We can factor out the highest common multiple, such that the sum of both +// weights will be 8 instead of 128. The benefits of this are two-fold: +// +// 1) We can infer the filter values from the filter_offset parameter in the +// bilinear filter functions below - we don't have to actually load the values +// from memory: +// f0 = 8 - filter_offset +// f1 = filter_offset +// +// 2) Scaling the pixel values by 8, instead of 128 enables us to operate on +// 16-bit data types at all times, rather than widening out to 32-bit and +// requiring double the number of data processing instructions. (12-bit * 8 = +// 15-bit.) + +// Process a block exactly 4 wide and any height. +static void highbd_var_filter_block2d_bil_w4(const uint16_t *src_ptr, + uint16_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset) { + const uint16x4_t f0 = vdup_n_u16(8 - filter_offset); + const uint16x4_t f1 = vdup_n_u16(filter_offset); + + int i = dst_height; + do { + uint16x4_t s0 = load_unaligned_u16(src_ptr); + uint16x4_t s1 = load_unaligned_u16(src_ptr + pixel_step); + + uint16x4_t blend = vmul_u16(s0, f0); + blend = vmla_u16(blend, s1, f1); + blend = vrshr_n_u16(blend, 3); + + vst1_u16(dst_ptr, blend); + + src_ptr += src_stride; + dst_ptr += 4; + } while (--i != 0); +} + +// Process a block which is a multiple of 8 and any height. +static void highbd_var_filter_block2d_bil_large(const uint16_t *src_ptr, + uint16_t *dst_ptr, + int src_stride, int pixel_step, + int dst_width, int dst_height, + int filter_offset) { + const uint16x8_t f0 = vdupq_n_u16(8 - filter_offset); + const uint16x8_t f1 = vdupq_n_u16(filter_offset); + + int i = dst_height; + do { + int j = 0; + do { + uint16x8_t s0 = vld1q_u16(src_ptr + j); + uint16x8_t s1 = vld1q_u16(src_ptr + j + pixel_step); + + uint16x8_t blend = vmulq_u16(s0, f0); + blend = vmlaq_u16(blend, s1, f1); + blend = vrshrq_n_u16(blend, 3); + + vst1q_u16(dst_ptr + j, blend); + + j += 8; + } while (j < dst_width); + + src_ptr += src_stride; + dst_ptr += dst_width; + } while (--i != 0); +} + +static void highbd_var_filter_block2d_bil_w8(const uint16_t *src_ptr, + uint16_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset) { + highbd_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, pixel_step, + 8, dst_height, filter_offset); +} +static void highbd_var_filter_block2d_bil_w16(const uint16_t *src_ptr, + uint16_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset) { + highbd_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, pixel_step, + 16, dst_height, filter_offset); +} +static void highbd_var_filter_block2d_bil_w32(const uint16_t *src_ptr, + uint16_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset) { + highbd_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, pixel_step, + 32, dst_height, filter_offset); +} +static void highbd_var_filter_block2d_bil_w64(const uint16_t *src_ptr, + uint16_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset) { + highbd_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, pixel_step, + 64, dst_height, filter_offset); +} + +static void highbd_var_filter_block2d_avg(const uint16_t *src_ptr, + uint16_t *dst_ptr, int src_stride, + int pixel_step, int dst_width, + int dst_height) { + int i = dst_height; + + // We only specialize on the filter values for large block sizes (>= 16x16.) + assert(dst_width >= 16 && dst_width % 16 == 0); + + do { + int j = 0; + do { + uint16x8_t s0 = vld1q_u16(src_ptr + j); + uint16x8_t s1 = vld1q_u16(src_ptr + j + pixel_step); + uint16x8_t avg = vrhaddq_u16(s0, s1); + vst1q_u16(dst_ptr + j, avg); + + j += 8; + } while (j < dst_width); + + src_ptr += src_stride; + dst_ptr += dst_width; + } while (--i != 0); +} + +#define HBD_SUBPEL_VARIANCE_WXH_NEON(bitdepth, w, h) \ + unsigned int vpx_highbd_##bitdepth##_sub_pixel_variance##w##x##h##_neon( \ + const uint8_t *src, int src_stride, int xoffset, int yoffset, \ + const uint8_t *ref, int ref_stride, uint32_t *sse) { \ + uint16_t tmp0[w * (h + 1)]; \ + uint16_t tmp1[w * h]; \ + uint16_t *src_ptr = CONVERT_TO_SHORTPTR(src); \ + \ + highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, src_stride, 1, (h + 1), \ + xoffset); \ + highbd_var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset); \ + \ + return vpx_highbd_##bitdepth##_variance##w##x##h(CONVERT_TO_BYTEPTR(tmp1), \ + w, ref, ref_stride, sse); \ + } + +#define HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(bitdepth, w, h) \ + unsigned int vpx_highbd_##bitdepth##_sub_pixel_variance##w##x##h##_neon( \ + const uint8_t *src, int src_stride, int xoffset, int yoffset, \ + const uint8_t *ref, int ref_stride, unsigned int *sse) { \ + uint16_t *src_ptr = CONVERT_TO_SHORTPTR(src); \ + \ + if (xoffset == 0) { \ + if (yoffset == 0) { \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(src_ptr), src_stride, ref, ref_stride, sse); \ + } else if (yoffset == 4) { \ + uint16_t tmp[w * h]; \ + highbd_var_filter_block2d_avg(src_ptr, tmp, src_stride, src_stride, w, \ + h); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp), w, ref, ref_stride, sse); \ + } else { \ + uint16_t tmp[w * h]; \ + highbd_var_filter_block2d_bil_w##w(src_ptr, tmp, src_stride, \ + src_stride, h, yoffset); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp), w, ref, ref_stride, sse); \ + } \ + } else if (xoffset == 4) { \ + uint16_t tmp0[w * (h + 1)]; \ + if (yoffset == 0) { \ + highbd_var_filter_block2d_avg(src_ptr, tmp0, src_stride, 1, w, h); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp0), w, ref, ref_stride, sse); \ + } else if (yoffset == 4) { \ + uint16_t tmp1[w * (h + 1)]; \ + highbd_var_filter_block2d_avg(src_ptr, tmp0, src_stride, 1, w, \ + (h + 1)); \ + highbd_var_filter_block2d_avg(tmp0, tmp1, w, w, w, h); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse); \ + } else { \ + uint16_t tmp1[w * (h + 1)]; \ + highbd_var_filter_block2d_avg(src_ptr, tmp0, src_stride, 1, w, \ + (h + 1)); \ + highbd_var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse); \ + } \ + } else { \ + uint16_t tmp0[w * (h + 1)]; \ + if (yoffset == 0) { \ + highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, src_stride, 1, h, \ + xoffset); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp0), w, ref, ref_stride, sse); \ + } else if (yoffset == 4) { \ + uint16_t tmp1[w * h]; \ + highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, src_stride, 1, \ + (h + 1), xoffset); \ + highbd_var_filter_block2d_avg(tmp0, tmp1, w, w, w, h); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse); \ + } else { \ + uint16_t tmp1[w * h]; \ + highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, src_stride, 1, \ + (h + 1), xoffset); \ + highbd_var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse); \ + } \ + } \ + } + +// 8-bit +HBD_SUBPEL_VARIANCE_WXH_NEON(8, 4, 4) +HBD_SUBPEL_VARIANCE_WXH_NEON(8, 4, 8) + +HBD_SUBPEL_VARIANCE_WXH_NEON(8, 8, 4) +HBD_SUBPEL_VARIANCE_WXH_NEON(8, 8, 8) +HBD_SUBPEL_VARIANCE_WXH_NEON(8, 8, 16) + +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 16, 8) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 16, 16) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 16, 32) + +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 32, 16) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 32, 32) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 32, 64) + +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 64, 32) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(8, 64, 64) + +// 10-bit +HBD_SUBPEL_VARIANCE_WXH_NEON(10, 4, 4) +HBD_SUBPEL_VARIANCE_WXH_NEON(10, 4, 8) + +HBD_SUBPEL_VARIANCE_WXH_NEON(10, 8, 4) +HBD_SUBPEL_VARIANCE_WXH_NEON(10, 8, 8) +HBD_SUBPEL_VARIANCE_WXH_NEON(10, 8, 16) + +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 16, 8) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 16, 16) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 16, 32) + +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 32, 16) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 32, 32) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 32, 64) + +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 64, 32) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(10, 64, 64) + +// 12-bit +HBD_SUBPEL_VARIANCE_WXH_NEON(12, 4, 4) +HBD_SUBPEL_VARIANCE_WXH_NEON(12, 4, 8) + +HBD_SUBPEL_VARIANCE_WXH_NEON(12, 8, 4) +HBD_SUBPEL_VARIANCE_WXH_NEON(12, 8, 8) +HBD_SUBPEL_VARIANCE_WXH_NEON(12, 8, 16) + +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 16, 8) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 16, 16) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 16, 32) + +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 32, 16) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 32, 32) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 32, 64) + +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 64, 32) +HBD_SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(12, 64, 64) + +// Combine bilinear filter with vpx_highbd_comp_avg_pred for blocks having +// width 4. +static void highbd_avg_pred_var_filter_block2d_bil_w4( + const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step, + int dst_height, int filter_offset, const uint16_t *second_pred) { + const uint16x4_t f0 = vdup_n_u16(8 - filter_offset); + const uint16x4_t f1 = vdup_n_u16(filter_offset); + + int i = dst_height; + do { + uint16x4_t s0 = load_unaligned_u16(src_ptr); + uint16x4_t s1 = load_unaligned_u16(src_ptr + pixel_step); + uint16x4_t p = vld1_u16(second_pred); + + uint16x4_t blend = vmul_u16(s0, f0); + blend = vmla_u16(blend, s1, f1); + blend = vrshr_n_u16(blend, 3); + + vst1_u16(dst_ptr, vrhadd_u16(blend, p)); + + src_ptr += src_stride; + dst_ptr += 4; + second_pred += 4; + } while (--i != 0); +} + +// Combine bilinear filter with vpx_highbd_comp_avg_pred for large blocks. +static void highbd_avg_pred_var_filter_block2d_bil_large( + const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step, + int dst_width, int dst_height, int filter_offset, + const uint16_t *second_pred) { + const uint16x8_t f0 = vdupq_n_u16(8 - filter_offset); + const uint16x8_t f1 = vdupq_n_u16(filter_offset); + + int i = dst_height; + do { + int j = 0; + do { + uint16x8_t s0 = vld1q_u16(src_ptr + j); + uint16x8_t s1 = vld1q_u16(src_ptr + j + pixel_step); + uint16x8_t p = vld1q_u16(second_pred); + + uint16x8_t blend = vmulq_u16(s0, f0); + blend = vmlaq_u16(blend, s1, f1); + blend = vrshrq_n_u16(blend, 3); + + vst1q_u16(dst_ptr + j, vrhaddq_u16(blend, p)); + + j += 8; + second_pred += 8; + } while (j < dst_width); + + src_ptr += src_stride; + dst_ptr += dst_width; + } while (--i != 0); +} + +static void highbd_avg_pred_var_filter_block2d_bil_w8( + const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step, + int dst_height, int filter_offset, const uint16_t *second_pred) { + highbd_avg_pred_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, + pixel_step, 8, dst_height, + filter_offset, second_pred); +} +static void highbd_avg_pred_var_filter_block2d_bil_w16( + const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step, + int dst_height, int filter_offset, const uint16_t *second_pred) { + highbd_avg_pred_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, + pixel_step, 16, dst_height, + filter_offset, second_pred); +} +static void highbd_avg_pred_var_filter_block2d_bil_w32( + const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step, + int dst_height, int filter_offset, const uint16_t *second_pred) { + highbd_avg_pred_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, + pixel_step, 32, dst_height, + filter_offset, second_pred); +} +static void highbd_avg_pred_var_filter_block2d_bil_w64( + const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step, + int dst_height, int filter_offset, const uint16_t *second_pred) { + highbd_avg_pred_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, + pixel_step, 64, dst_height, + filter_offset, second_pred); +} + +// Combine averaging subpel filter with vpx_highbd_comp_avg_pred. +static void highbd_avg_pred_var_filter_block2d_avg( + const uint16_t *src_ptr, uint16_t *dst_ptr, int src_stride, int pixel_step, + int dst_width, int dst_height, const uint16_t *second_pred) { + int i = dst_height; + + // We only specialize on the filter values for large block sizes (>= 16x16.) + assert(dst_width >= 16 && dst_width % 16 == 0); + + do { + int j = 0; + do { + uint16x8_t s0 = vld1q_u16(src_ptr + j); + uint16x8_t s1 = vld1q_u16(src_ptr + j + pixel_step); + uint16x8_t avg = vrhaddq_u16(s0, s1); + + uint16x8_t p = vld1q_u16(second_pred); + avg = vrhaddq_u16(avg, p); + + vst1q_u16(dst_ptr + j, avg); + + j += 8; + second_pred += 8; + } while (j < dst_width); + + src_ptr += src_stride; + dst_ptr += dst_width; + } while (--i != 0); +} + +// Implementation of vpx_highbd_comp_avg_pred for blocks having width >= 16. +static void highbd_avg_pred(const uint16_t *src_ptr, uint16_t *dst_ptr, + int src_stride, int dst_width, int dst_height, + const uint16_t *second_pred) { + int i = dst_height; + + // We only specialize on the filter values for large block sizes (>= 16x16.) + assert(dst_width >= 16 && dst_width % 16 == 0); + + do { + int j = 0; + do { + uint16x8_t s = vld1q_u16(src_ptr + j); + uint16x8_t p = vld1q_u16(second_pred); + + uint16x8_t avg = vrhaddq_u16(s, p); + + vst1q_u16(dst_ptr + j, avg); + + j += 8; + second_pred += 8; + } while (j < dst_width); + + src_ptr += src_stride; + dst_ptr += dst_width; + } while (--i != 0); +} + +#define HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(bitdepth, w, h) \ + uint32_t vpx_highbd_##bitdepth##_sub_pixel_avg_variance##w##x##h##_neon( \ + const uint8_t *src, int src_stride, int xoffset, int yoffset, \ + const uint8_t *ref, int ref_stride, uint32_t *sse, \ + const uint8_t *second_pred) { \ + uint16_t tmp0[w * (h + 1)]; \ + uint16_t tmp1[w * h]; \ + uint16_t *src_ptr = CONVERT_TO_SHORTPTR(src); \ + \ + highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, src_stride, 1, (h + 1), \ + xoffset); \ + highbd_avg_pred_var_filter_block2d_bil_w##w( \ + tmp0, tmp1, w, w, h, yoffset, CONVERT_TO_SHORTPTR(second_pred)); \ + \ + return vpx_highbd_##bitdepth##_variance##w##x##h(CONVERT_TO_BYTEPTR(tmp1), \ + w, ref, ref_stride, sse); \ + } + +#define HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(bitdepth, w, h) \ + unsigned int vpx_highbd_##bitdepth##_sub_pixel_avg_variance##w##x##h##_neon( \ + const uint8_t *src, int source_stride, int xoffset, int yoffset, \ + const uint8_t *ref, int ref_stride, unsigned int *sse, \ + const uint8_t *second_pred) { \ + uint16_t *src_ptr = CONVERT_TO_SHORTPTR(src); \ + \ + if (xoffset == 0) { \ + uint16_t tmp[w * h]; \ + if (yoffset == 0) { \ + highbd_avg_pred(src_ptr, tmp, source_stride, w, h, \ + CONVERT_TO_SHORTPTR(second_pred)); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp), w, ref, ref_stride, sse); \ + } else if (yoffset == 4) { \ + highbd_avg_pred_var_filter_block2d_avg( \ + src_ptr, tmp, source_stride, source_stride, w, h, \ + CONVERT_TO_SHORTPTR(second_pred)); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp), w, ref, ref_stride, sse); \ + } else { \ + highbd_avg_pred_var_filter_block2d_bil_w##w( \ + src_ptr, tmp, source_stride, source_stride, h, yoffset, \ + CONVERT_TO_SHORTPTR(second_pred)); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp), w, ref, ref_stride, sse); \ + } \ + } else if (xoffset == 4) { \ + uint16_t tmp0[w * (h + 1)]; \ + if (yoffset == 0) { \ + highbd_avg_pred_var_filter_block2d_avg( \ + src_ptr, tmp0, source_stride, 1, w, h, \ + CONVERT_TO_SHORTPTR(second_pred)); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp0), w, ref, ref_stride, sse); \ + } else if (yoffset == 4) { \ + uint16_t tmp1[w * (h + 1)]; \ + highbd_var_filter_block2d_avg(src_ptr, tmp0, source_stride, 1, w, \ + (h + 1)); \ + highbd_avg_pred_var_filter_block2d_avg( \ + tmp0, tmp1, w, w, w, h, CONVERT_TO_SHORTPTR(second_pred)); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse); \ + } else { \ + uint16_t tmp1[w * (h + 1)]; \ + highbd_var_filter_block2d_avg(src_ptr, tmp0, source_stride, 1, w, \ + (h + 1)); \ + highbd_avg_pred_var_filter_block2d_bil_w##w( \ + tmp0, tmp1, w, w, h, yoffset, CONVERT_TO_SHORTPTR(second_pred)); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse); \ + } \ + } else { \ + uint16_t tmp0[w * (h + 1)]; \ + if (yoffset == 0) { \ + highbd_avg_pred_var_filter_block2d_bil_w##w( \ + src_ptr, tmp0, source_stride, 1, h, xoffset, \ + CONVERT_TO_SHORTPTR(second_pred)); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp0), w, ref, ref_stride, sse); \ + } else if (yoffset == 4) { \ + uint16_t tmp1[w * h]; \ + highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, source_stride, 1, \ + (h + 1), xoffset); \ + highbd_avg_pred_var_filter_block2d_avg( \ + tmp0, tmp1, w, w, w, h, CONVERT_TO_SHORTPTR(second_pred)); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse); \ + } else { \ + uint16_t tmp1[w * h]; \ + highbd_var_filter_block2d_bil_w##w(src_ptr, tmp0, source_stride, 1, \ + (h + 1), xoffset); \ + highbd_avg_pred_var_filter_block2d_bil_w##w( \ + tmp0, tmp1, w, w, h, yoffset, CONVERT_TO_SHORTPTR(second_pred)); \ + return vpx_highbd_##bitdepth##_variance##w##x##h( \ + CONVERT_TO_BYTEPTR(tmp1), w, ref, ref_stride, sse); \ + } \ + } \ + } + +// 8-bit +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 4, 4) +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 4, 8) + +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 8, 4) +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 8, 8) +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 8, 16) + +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 16, 8) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 16, 16) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 16, 32) + +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 32, 16) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 32, 32) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 32, 64) + +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 64, 32) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(8, 64, 64) + +// 10-bit +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 4, 4) +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 4, 8) + +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 8, 4) +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 8, 8) +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 8, 16) + +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 16, 8) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 16, 16) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 16, 32) + +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 32, 16) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 32, 32) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 32, 64) + +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 64, 32) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(10, 64, 64) + +// 12-bit +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 4, 4) +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 4, 8) + +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 8, 4) +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 8, 8) +HBD_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 8, 16) + +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 16, 8) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 16, 16) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 16, 32) + +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 32, 16) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 32, 32) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 32, 64) + +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 64, 32) +HBD_SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(12, 64, 64) diff --git a/libs/libvpx/vpx_dsp/arm/highbd_variance_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_variance_neon.c new file mode 100644 index 0000000000..309ae7fd35 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_variance_neon.c @@ -0,0 +1,436 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_dsp_rtcd.h" +#include "./vpx_config.h" + +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" +#include "vpx_ports/mem.h" + +// Process a block of width 4 two rows at a time. +static INLINE void highbd_variance_4xh_neon(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int h, + uint64_t *sse, int64_t *sum) { + int16x8_t sum_s16 = vdupq_n_s16(0); + int32x4_t sse_s32 = vdupq_n_s32(0); + + int i = h; + do { + const uint16x8_t s = load_unaligned_u16q(src_ptr, src_stride); + const uint16x8_t r = load_unaligned_u16q(ref_ptr, ref_stride); + + int16x8_t diff = vreinterpretq_s16_u16(vsubq_u16(s, r)); + sum_s16 = vaddq_s16(sum_s16, diff); + + sse_s32 = vmlal_s16(sse_s32, vget_low_s16(diff), vget_low_s16(diff)); + sse_s32 = vmlal_s16(sse_s32, vget_high_s16(diff), vget_high_s16(diff)); + + src_ptr += 2 * src_stride; + ref_ptr += 2 * ref_stride; + i -= 2; + } while (i != 0); + + *sum = horizontal_add_int16x8(sum_s16); + *sse = horizontal_add_int32x4(sse_s32); +} + +// For 8-bit and 10-bit data, since we're using two int32x4 accumulators, all +// block sizes can be processed in 32-bit elements (1023*1023*64*16 = 1071645696 +// for a 64x64 block). +static INLINE void highbd_variance_large_neon(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int w, int h, + uint64_t *sse, int64_t *sum) { + int32x4_t sum_s32 = vdupq_n_s32(0); + int32x4_t sse_s32[2] = { vdupq_n_s32(0), vdupq_n_s32(0) }; + + int i = h; + do { + int j = 0; + do { + const uint16x8_t s = vld1q_u16(src_ptr + j); + const uint16x8_t r = vld1q_u16(ref_ptr + j); + + const int16x8_t diff = vreinterpretq_s16_u16(vsubq_u16(s, r)); + sum_s32 = vpadalq_s16(sum_s32, diff); + + sse_s32[0] = + vmlal_s16(sse_s32[0], vget_low_s16(diff), vget_low_s16(diff)); + sse_s32[1] = + vmlal_s16(sse_s32[1], vget_high_s16(diff), vget_high_s16(diff)); + + j += 8; + } while (j < w); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--i != 0); + + *sum = horizontal_add_int32x4(sum_s32); + *sse = horizontal_long_add_uint32x4(vaddq_u32( + vreinterpretq_u32_s32(sse_s32[0]), vreinterpretq_u32_s32(sse_s32[1]))); +} + +static INLINE void highbd_variance_8xh_neon(const uint16_t *src, int src_stride, + const uint16_t *ref, int ref_stride, + int h, uint64_t *sse, + int64_t *sum) { + highbd_variance_large_neon(src, src_stride, ref, ref_stride, 8, h, sse, sum); +} + +static INLINE void highbd_variance_16xh_neon(const uint16_t *src, + int src_stride, + const uint16_t *ref, + int ref_stride, int h, + uint64_t *sse, int64_t *sum) { + highbd_variance_large_neon(src, src_stride, ref, ref_stride, 16, h, sse, sum); +} + +static INLINE void highbd_variance_32xh_neon(const uint16_t *src, + int src_stride, + const uint16_t *ref, + int ref_stride, int h, + uint64_t *sse, int64_t *sum) { + highbd_variance_large_neon(src, src_stride, ref, ref_stride, 32, h, sse, sum); +} + +static INLINE void highbd_variance_64xh_neon(const uint16_t *src, + int src_stride, + const uint16_t *ref, + int ref_stride, int h, + uint64_t *sse, int64_t *sum) { + highbd_variance_large_neon(src, src_stride, ref, ref_stride, 64, h, sse, sum); +} + +// For 12-bit data, we can only accumulate up to 128 elements in the sum of +// squares (4095*4095*128 = 2146435200), and because we're using two int32x4 +// accumulators, we can only process up to 32 32-element rows (32*32/8 = 128) +// or 16 64-element rows before we have to accumulate into 64-bit elements. +// Therefore blocks of size 32x64, 64x32 and 64x64 are processed in a different +// helper function. + +// Process a block of any size where the width is divisible by 8, with +// accumulation into 64-bit elements. +static INLINE void highbd_variance_xlarge_neon( + const uint16_t *src_ptr, int src_stride, const uint16_t *ref_ptr, + int ref_stride, int w, int h, int h_limit, uint64_t *sse, int64_t *sum) { + int32x4_t sum_s32 = vdupq_n_s32(0); + int64x2_t sse_s64 = vdupq_n_s64(0); + + // 'h_limit' is the number of 'w'-width rows we can process before our 32-bit + // accumulator overflows. After hitting this limit we accumulate into 64-bit + // elements. + int h_tmp = h > h_limit ? h_limit : h; + + int i = 0; + do { + int32x4_t sse_s32[2] = { vdupq_n_s32(0), vdupq_n_s32(0) }; + do { + int j = 0; + do { + const uint16x8_t s0 = vld1q_u16(src_ptr + j); + const uint16x8_t r0 = vld1q_u16(ref_ptr + j); + + const int16x8_t diff = vreinterpretq_s16_u16(vsubq_u16(s0, r0)); + sum_s32 = vpadalq_s16(sum_s32, diff); + + sse_s32[0] = + vmlal_s16(sse_s32[0], vget_low_s16(diff), vget_low_s16(diff)); + sse_s32[1] = + vmlal_s16(sse_s32[1], vget_high_s16(diff), vget_high_s16(diff)); + + j += 8; + } while (j < w); + + src_ptr += src_stride; + ref_ptr += ref_stride; + i++; + } while (i < h_tmp); + + sse_s64 = vpadalq_s32(sse_s64, sse_s32[0]); + sse_s64 = vpadalq_s32(sse_s64, sse_s32[1]); + h_tmp += h_limit; + } while (i < h); + + *sum = horizontal_add_int32x4(sum_s32); + *sse = (uint64_t)horizontal_add_int64x2(sse_s64); +} + +static INLINE void highbd_variance_32xh_xlarge_neon( + const uint16_t *src, int src_stride, const uint16_t *ref, int ref_stride, + int h, uint64_t *sse, int64_t *sum) { + highbd_variance_xlarge_neon(src, src_stride, ref, ref_stride, 32, h, 32, sse, + sum); +} + +static INLINE void highbd_variance_64xh_xlarge_neon( + const uint16_t *src, int src_stride, const uint16_t *ref, int ref_stride, + int h, uint64_t *sse, int64_t *sum) { + highbd_variance_xlarge_neon(src, src_stride, ref, ref_stride, 64, h, 16, sse, + sum); +} + +#define HBD_VARIANCE_WXH_8_NEON(w, h) \ + uint32_t vpx_highbd_8_variance##w##x##h##_neon( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + int sum; \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##w##xh_neon(src, src_stride, ref, ref_stride, h, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)sse_long; \ + sum = (int)sum_long; \ + return *sse - (uint32_t)(((int64_t)sum * sum) / (w * h)); \ + } + +#define HBD_VARIANCE_WXH_10_NEON(w, h) \ + uint32_t vpx_highbd_10_variance##w##x##h##_neon( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + int sum; \ + int64_t var; \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##w##xh_neon(src, src_stride, ref, ref_stride, h, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 4); \ + sum = (int)ROUND_POWER_OF_TWO(sum_long, 2); \ + var = (int64_t)(*sse) - (((int64_t)sum * sum) / (w * h)); \ + return (var >= 0) ? (uint32_t)var : 0; \ + } + +#define HBD_VARIANCE_WXH_12_NEON(w, h) \ + uint32_t vpx_highbd_12_variance##w##x##h##_neon( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + int sum; \ + int64_t var; \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##w##xh_neon(src, src_stride, ref, ref_stride, h, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 8); \ + sum = (int)ROUND_POWER_OF_TWO(sum_long, 4); \ + var = (int64_t)(*sse) - (((int64_t)sum * sum) / (w * h)); \ + return (var >= 0) ? (uint32_t)var : 0; \ + } + +#define HBD_VARIANCE_WXH_12_XLARGE_NEON(w, h) \ + uint32_t vpx_highbd_12_variance##w##x##h##_neon( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + int sum; \ + int64_t var; \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##w##xh_xlarge_neon(src, src_stride, ref, ref_stride, h, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 8); \ + sum = (int)ROUND_POWER_OF_TWO(sum_long, 4); \ + var = (int64_t)(*sse) - (((int64_t)sum * sum) / (w * h)); \ + return (var >= 0) ? (uint32_t)var : 0; \ + } + +// 8-bit +HBD_VARIANCE_WXH_8_NEON(4, 4) +HBD_VARIANCE_WXH_8_NEON(4, 8) + +HBD_VARIANCE_WXH_8_NEON(8, 4) +HBD_VARIANCE_WXH_8_NEON(8, 8) +HBD_VARIANCE_WXH_8_NEON(8, 16) + +HBD_VARIANCE_WXH_8_NEON(16, 8) +HBD_VARIANCE_WXH_8_NEON(16, 16) +HBD_VARIANCE_WXH_8_NEON(16, 32) + +HBD_VARIANCE_WXH_8_NEON(32, 16) +HBD_VARIANCE_WXH_8_NEON(32, 32) +HBD_VARIANCE_WXH_8_NEON(32, 64) + +HBD_VARIANCE_WXH_8_NEON(64, 32) +HBD_VARIANCE_WXH_8_NEON(64, 64) + +// 10-bit +HBD_VARIANCE_WXH_10_NEON(4, 4) +HBD_VARIANCE_WXH_10_NEON(4, 8) + +HBD_VARIANCE_WXH_10_NEON(8, 4) +HBD_VARIANCE_WXH_10_NEON(8, 8) +HBD_VARIANCE_WXH_10_NEON(8, 16) + +HBD_VARIANCE_WXH_10_NEON(16, 8) +HBD_VARIANCE_WXH_10_NEON(16, 16) +HBD_VARIANCE_WXH_10_NEON(16, 32) + +HBD_VARIANCE_WXH_10_NEON(32, 16) +HBD_VARIANCE_WXH_10_NEON(32, 32) +HBD_VARIANCE_WXH_10_NEON(32, 64) + +HBD_VARIANCE_WXH_10_NEON(64, 32) +HBD_VARIANCE_WXH_10_NEON(64, 64) + +// 12-bit +HBD_VARIANCE_WXH_12_NEON(4, 4) +HBD_VARIANCE_WXH_12_NEON(4, 8) + +HBD_VARIANCE_WXH_12_NEON(8, 4) +HBD_VARIANCE_WXH_12_NEON(8, 8) +HBD_VARIANCE_WXH_12_NEON(8, 16) + +HBD_VARIANCE_WXH_12_NEON(16, 8) +HBD_VARIANCE_WXH_12_NEON(16, 16) +HBD_VARIANCE_WXH_12_NEON(16, 32) + +HBD_VARIANCE_WXH_12_NEON(32, 16) +HBD_VARIANCE_WXH_12_NEON(32, 32) +HBD_VARIANCE_WXH_12_XLARGE_NEON(32, 64) + +HBD_VARIANCE_WXH_12_XLARGE_NEON(64, 32) +HBD_VARIANCE_WXH_12_XLARGE_NEON(64, 64) + +#define HIGHBD_GET_VAR(S) \ + void vpx_highbd_8_get##S##x##S##var_neon( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse, int *sum) { \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##S##xh_neon(src, src_stride, ref, ref_stride, S, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)sse_long; \ + *sum = (int)sum_long; \ + } \ + \ + void vpx_highbd_10_get##S##x##S##var_neon( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse, int *sum) { \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##S##xh_neon(src, src_stride, ref, ref_stride, S, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 4); \ + *sum = (int)ROUND_POWER_OF_TWO(sum_long, 2); \ + } \ + \ + void vpx_highbd_12_get##S##x##S##var_neon( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse, int *sum) { \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##S##xh_neon(src, src_stride, ref, ref_stride, S, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 8); \ + *sum = (int)ROUND_POWER_OF_TWO(sum_long, 4); \ + } + +HIGHBD_GET_VAR(8) +HIGHBD_GET_VAR(16) + +static INLINE uint32_t highbd_mse_wxh_neon(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int w, int h) { + uint32x4_t sse_u32[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + int i = h; + do { + int j = 0; + do { + uint16x8_t s = vld1q_u16(src_ptr + j); + uint16x8_t r = vld1q_u16(ref_ptr + j); + + uint16x8_t diff = vabdq_u16(s, r); + + sse_u32[0] = + vmlal_u16(sse_u32[0], vget_low_u16(diff), vget_low_u16(diff)); + sse_u32[1] = + vmlal_u16(sse_u32[1], vget_high_u16(diff), vget_high_u16(diff)); + + j += 8; + } while (j < w); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--i != 0); + + return horizontal_add_uint32x4(vaddq_u32(sse_u32[0], sse_u32[1])); +} + +static INLINE uint32_t highbd_mse8_8xh_neon(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int h) { + return highbd_mse_wxh_neon(src_ptr, src_stride, ref_ptr, ref_stride, 8, h); +} + +static INLINE uint32_t highbd_mse8_16xh_neon(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int h) { + return highbd_mse_wxh_neon(src_ptr, src_stride, ref_ptr, ref_stride, 16, h); +} + +#define HIGHBD_MSE_WXH_NEON(w, h) \ + uint32_t vpx_highbd_8_mse##w##x##h##_neon( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + *sse = highbd_mse8_##w##xh_neon(src, src_stride, ref, ref_stride, h); \ + return *sse; \ + } \ + \ + uint32_t vpx_highbd_10_mse##w##x##h##_neon( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + *sse = highbd_mse_wxh_neon(src, src_stride, ref, ref_stride, w, h); \ + *sse = ROUND_POWER_OF_TWO(*sse, 4); \ + return *sse; \ + } \ + \ + uint32_t vpx_highbd_12_mse##w##x##h##_neon( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + *sse = highbd_mse_wxh_neon(src, src_stride, ref, ref_stride, w, h); \ + *sse = ROUND_POWER_OF_TWO(*sse, 8); \ + return *sse; \ + } + +HIGHBD_MSE_WXH_NEON(16, 16) +HIGHBD_MSE_WXH_NEON(16, 8) +HIGHBD_MSE_WXH_NEON(8, 16) +HIGHBD_MSE_WXH_NEON(8, 8) + +#undef HIGHBD_MSE_WXH_NEON diff --git a/libs/libvpx/vpx_dsp/arm/highbd_variance_neon_dotprod.c b/libs/libvpx/vpx_dsp/arm/highbd_variance_neon_dotprod.c new file mode 100644 index 0000000000..1a88720172 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_variance_neon_dotprod.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_dsp_rtcd.h" +#include "./vpx_config.h" + +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" +#include "vpx_ports/mem.h" + +static INLINE uint32_t highbd_mse8_8xh_neon_dotprod(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int h) { + uint32x4_t sse_u32 = vdupq_n_u32(0); + + int i = h / 2; + do { + uint16x8_t s0, s1, r0, r1; + uint8x16_t s, r, diff; + + s0 = vld1q_u16(src_ptr); + src_ptr += src_stride; + s1 = vld1q_u16(src_ptr); + src_ptr += src_stride; + r0 = vld1q_u16(ref_ptr); + ref_ptr += ref_stride; + r1 = vld1q_u16(ref_ptr); + ref_ptr += ref_stride; + + s = vcombine_u8(vmovn_u16(s0), vmovn_u16(s1)); + r = vcombine_u8(vmovn_u16(r0), vmovn_u16(r1)); + + diff = vabdq_u8(s, r); + sse_u32 = vdotq_u32(sse_u32, diff, diff); + } while (--i != 0); + + return horizontal_add_uint32x4(sse_u32); +} + +static INLINE uint32_t highbd_mse8_16xh_neon_dotprod(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int h) { + uint32x4_t sse_u32 = vdupq_n_u32(0); + + int i = h; + do { + uint16x8_t s0, s1, r0, r1; + uint8x16_t s, r, diff; + + s0 = vld1q_u16(src_ptr); + s1 = vld1q_u16(src_ptr + 8); + r0 = vld1q_u16(ref_ptr); + r1 = vld1q_u16(ref_ptr + 8); + + s = vcombine_u8(vmovn_u16(s0), vmovn_u16(s1)); + r = vcombine_u8(vmovn_u16(r0), vmovn_u16(r1)); + + diff = vabdq_u8(s, r); + sse_u32 = vdotq_u32(sse_u32, diff, diff); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--i != 0); + + return horizontal_add_uint32x4(sse_u32); +} + +#define HIGHBD_MSE_WXH_NEON_DOTPROD(w, h) \ + uint32_t vpx_highbd_8_mse##w##x##h##_neon_dotprod( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + *sse = \ + highbd_mse8_##w##xh_neon_dotprod(src, src_stride, ref, ref_stride, h); \ + return *sse; \ + } + +HIGHBD_MSE_WXH_NEON_DOTPROD(16, 16) +HIGHBD_MSE_WXH_NEON_DOTPROD(16, 8) +HIGHBD_MSE_WXH_NEON_DOTPROD(8, 16) +HIGHBD_MSE_WXH_NEON_DOTPROD(8, 8) + +#undef HIGHBD_MSE_WXH_NEON_DOTPROD diff --git a/libs/libvpx/vpx_dsp/arm/highbd_variance_sve.c b/libs/libvpx/vpx_dsp/arm/highbd_variance_sve.c new file mode 100644 index 0000000000..cebe06b099 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_variance_sve.c @@ -0,0 +1,344 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_dsp_rtcd.h" +#include "./vpx_config.h" + +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" +#include "vpx_dsp/arm/vpx_neon_sve_bridge.h" +#include "vpx_ports/mem.h" + +static INLINE uint32_t highbd_mse_wxh_sve(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int w, int h) { + uint64x2_t sse = vdupq_n_u64(0); + + do { + int j = 0; + do { + uint16x8_t s = vld1q_u16(src_ptr + j); + uint16x8_t r = vld1q_u16(ref_ptr + j); + + uint16x8_t diff = vabdq_u16(s, r); + + sse = vpx_dotq_u16(sse, diff, diff); + + j += 8; + } while (j < w); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--h != 0); + + return (uint32_t)horizontal_add_uint64x2(sse); +} + +#define HIGHBD_MSE_WXH_SVE(w, h) \ + uint32_t vpx_highbd_10_mse##w##x##h##_sve( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + uint32_t sse_tmp = \ + highbd_mse_wxh_sve(src, src_stride, ref, ref_stride, w, h); \ + sse_tmp = ROUND_POWER_OF_TWO(sse_tmp, 4); \ + *sse = sse_tmp; \ + return sse_tmp; \ + } \ + \ + uint32_t vpx_highbd_12_mse##w##x##h##_sve( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + uint32_t sse_tmp = \ + highbd_mse_wxh_sve(src, src_stride, ref, ref_stride, w, h); \ + sse_tmp = ROUND_POWER_OF_TWO(sse_tmp, 8); \ + *sse = sse_tmp; \ + return sse_tmp; \ + } + +HIGHBD_MSE_WXH_SVE(16, 16) +HIGHBD_MSE_WXH_SVE(16, 8) +HIGHBD_MSE_WXH_SVE(8, 16) +HIGHBD_MSE_WXH_SVE(8, 8) + +#undef HIGHBD_MSE_WXH_SVE + +// Process a block of width 4 two rows at a time. +static INLINE void highbd_variance_4xh_sve(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int h, uint64_t *sse, + int64_t *sum) { + int16x8_t sum_s16 = vdupq_n_s16(0); + int64x2_t sse_s64 = vdupq_n_s64(0); + + do { + const uint16x8_t s = load_unaligned_u16q(src_ptr, src_stride); + const uint16x8_t r = load_unaligned_u16q(ref_ptr, ref_stride); + + int16x8_t diff = vreinterpretq_s16_u16(vsubq_u16(s, r)); + sum_s16 = vaddq_s16(sum_s16, diff); + sse_s64 = vpx_dotq_s16(sse_s64, diff, diff); + + src_ptr += 2 * src_stride; + ref_ptr += 2 * ref_stride; + h -= 2; + } while (h != 0); + + *sum = horizontal_add_int16x8(sum_s16); + *sse = horizontal_add_int64x2(sse_s64); +} + +static INLINE void highbd_variance_8xh_sve(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int h, uint64_t *sse, + int64_t *sum) { + int32x4_t sum_s32 = vdupq_n_s32(0); + int64x2_t sse_s64 = vdupq_n_s64(0); + + do { + const uint16x8_t s = vld1q_u16(src_ptr); + const uint16x8_t r = vld1q_u16(ref_ptr); + + const int16x8_t diff = vreinterpretq_s16_u16(vsubq_u16(s, r)); + sum_s32 = vpadalq_s16(sum_s32, diff); + sse_s64 = vpx_dotq_s16(sse_s64, diff, diff); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--h != 0); + + *sum = horizontal_add_int32x4(sum_s32); + *sse = horizontal_add_int64x2(sse_s64); +} + +static INLINE void highbd_variance_16xh_sve(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int h, + uint64_t *sse, int64_t *sum) { + int32x4_t sum_s32[2] = { vdupq_n_s32(0), vdupq_n_s32(0) }; + int64x2_t sse_s64[2] = { vdupq_n_s64(0), vdupq_n_s64(0) }; + + do { + const uint16x8_t s0 = vld1q_u16(src_ptr); + const uint16x8_t s1 = vld1q_u16(src_ptr + 8); + + const uint16x8_t r0 = vld1q_u16(ref_ptr); + const uint16x8_t r1 = vld1q_u16(ref_ptr + 8); + + const int16x8_t diff0 = vreinterpretq_s16_u16(vsubq_u16(s0, r0)); + const int16x8_t diff1 = vreinterpretq_s16_u16(vsubq_u16(s1, r1)); + + sum_s32[0] = vpadalq_s16(sum_s32[0], diff0); + sum_s32[1] = vpadalq_s16(sum_s32[1], diff1); + + sse_s64[0] = vpx_dotq_s16(sse_s64[0], diff0, diff0); + sse_s64[1] = vpx_dotq_s16(sse_s64[1], diff1, diff1); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--h != 0); + + sum_s32[0] = vaddq_s32(sum_s32[0], sum_s32[1]); + sse_s64[0] = vaddq_s64(sse_s64[0], sse_s64[1]); + + *sum = horizontal_add_int32x4(sum_s32[0]); + *sse = horizontal_add_int64x2(sse_s64[0]); +} + +static INLINE void highbd_variance_wxh_sve(const uint16_t *src_ptr, + int src_stride, + const uint16_t *ref_ptr, + int ref_stride, int w, int h, + uint64_t *sse, int64_t *sum) { + int32x4_t sum_s32[4] = { vdupq_n_s32(0), vdupq_n_s32(0), vdupq_n_s32(0), + vdupq_n_s32(0) }; + int64x2_t sse_s64[4] = { vdupq_n_s64(0), vdupq_n_s64(0), vdupq_n_s64(0), + vdupq_n_s64(0) }; + + do { + int i = 0; + do { + const uint16x8_t s0 = vld1q_u16(src_ptr + i); + const uint16x8_t s1 = vld1q_u16(src_ptr + i + 8); + const uint16x8_t s2 = vld1q_u16(src_ptr + i + 16); + const uint16x8_t s3 = vld1q_u16(src_ptr + i + 24); + + const uint16x8_t r0 = vld1q_u16(ref_ptr + i); + const uint16x8_t r1 = vld1q_u16(ref_ptr + i + 8); + const uint16x8_t r2 = vld1q_u16(ref_ptr + i + 16); + const uint16x8_t r3 = vld1q_u16(ref_ptr + i + 24); + + const int16x8_t diff0 = vreinterpretq_s16_u16(vsubq_u16(s0, r0)); + const int16x8_t diff1 = vreinterpretq_s16_u16(vsubq_u16(s1, r1)); + const int16x8_t diff2 = vreinterpretq_s16_u16(vsubq_u16(s2, r2)); + const int16x8_t diff3 = vreinterpretq_s16_u16(vsubq_u16(s3, r3)); + + sum_s32[0] = vpadalq_s16(sum_s32[0], diff0); + sum_s32[1] = vpadalq_s16(sum_s32[1], diff1); + sum_s32[2] = vpadalq_s16(sum_s32[2], diff2); + sum_s32[3] = vpadalq_s16(sum_s32[3], diff3); + + sse_s64[0] = vpx_dotq_s16(sse_s64[0], diff0, diff0); + sse_s64[1] = vpx_dotq_s16(sse_s64[1], diff1, diff1); + sse_s64[2] = vpx_dotq_s16(sse_s64[2], diff2, diff2); + sse_s64[3] = vpx_dotq_s16(sse_s64[3], diff3, diff3); + + i += 32; + } while (i < w); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--h != 0); + + sum_s32[0] = vaddq_s32(sum_s32[0], sum_s32[1]); + sum_s32[2] = vaddq_s32(sum_s32[2], sum_s32[3]); + sum_s32[0] = vaddq_s32(sum_s32[0], sum_s32[2]); + + sse_s64[0] = vaddq_s64(sse_s64[0], sse_s64[1]); + sse_s64[2] = vaddq_s64(sse_s64[2], sse_s64[3]); + sse_s64[0] = vaddq_s64(sse_s64[0], sse_s64[2]); + + *sum = horizontal_add_int32x4(sum_s32[0]); + *sse = horizontal_add_int64x2(sse_s64[0]); +} + +static INLINE void highbd_variance_32xh_sve(const uint16_t *src, int src_stride, + const uint16_t *ref, int ref_stride, + int h, uint64_t *sse, + int64_t *sum) { + highbd_variance_wxh_sve(src, src_stride, ref, ref_stride, 32, h, sse, sum); +} + +static INLINE void highbd_variance_64xh_sve(const uint16_t *src, int src_stride, + const uint16_t *ref, int ref_stride, + int h, uint64_t *sse, + int64_t *sum) { + highbd_variance_wxh_sve(src, src_stride, ref, ref_stride, 64, h, sse, sum); +} + +#define HBD_VARIANCE_WXH_SVE(w, h) \ + uint32_t vpx_highbd_8_variance##w##x##h##_sve( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + int sum; \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##w##xh_sve(src, src_stride, ref, ref_stride, h, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)sse_long; \ + sum = (int)sum_long; \ + return *sse - (uint32_t)(((int64_t)sum * sum) / (w * h)); \ + } \ + \ + uint32_t vpx_highbd_10_variance##w##x##h##_sve( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + int sum; \ + int64_t var; \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##w##xh_sve(src, src_stride, ref, ref_stride, h, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 4); \ + sum = (int)ROUND_POWER_OF_TWO(sum_long, 2); \ + var = (int64_t)(*sse) - (((int64_t)sum * sum) / (w * h)); \ + return (var >= 0) ? (uint32_t)var : 0; \ + } \ + \ + uint32_t vpx_highbd_12_variance##w##x##h##_sve( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse) { \ + int sum; \ + int64_t var; \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##w##xh_sve(src, src_stride, ref, ref_stride, h, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 8); \ + sum = (int)ROUND_POWER_OF_TWO(sum_long, 4); \ + var = (int64_t)(*sse) - (((int64_t)sum * sum) / (w * h)); \ + return (var >= 0) ? (uint32_t)var : 0; \ + } + +HBD_VARIANCE_WXH_SVE(4, 4) +HBD_VARIANCE_WXH_SVE(4, 8) + +HBD_VARIANCE_WXH_SVE(8, 4) +HBD_VARIANCE_WXH_SVE(8, 8) +HBD_VARIANCE_WXH_SVE(8, 16) + +HBD_VARIANCE_WXH_SVE(16, 8) +HBD_VARIANCE_WXH_SVE(16, 16) +HBD_VARIANCE_WXH_SVE(16, 32) + +HBD_VARIANCE_WXH_SVE(32, 16) +HBD_VARIANCE_WXH_SVE(32, 32) +HBD_VARIANCE_WXH_SVE(32, 64) + +HBD_VARIANCE_WXH_SVE(64, 32) +HBD_VARIANCE_WXH_SVE(64, 64) + +#define HIGHBD_GET_VAR_SVE(s) \ + void vpx_highbd_8_get##s##x##s##var_sve( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse, int *sum) { \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##s##xh_sve(src, src_stride, ref, ref_stride, s, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)sse_long; \ + *sum = (int)sum_long; \ + } \ + \ + void vpx_highbd_10_get##s##x##s##var_sve( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse, int *sum) { \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##s##xh_sve(src, src_stride, ref, ref_stride, s, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 4); \ + *sum = (int)ROUND_POWER_OF_TWO(sum_long, 2); \ + } \ + \ + void vpx_highbd_12_get##s##x##s##var_sve( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, uint32_t *sse, int *sum) { \ + uint64_t sse_long = 0; \ + int64_t sum_long = 0; \ + uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + highbd_variance_##s##xh_sve(src, src_stride, ref, ref_stride, s, \ + &sse_long, &sum_long); \ + *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 8); \ + *sum = (int)ROUND_POWER_OF_TWO(sum_long, 4); \ + } + +HIGHBD_GET_VAR_SVE(8) +HIGHBD_GET_VAR_SVE(16) diff --git a/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_neon.c index c46c016312..cc6307f923 100644 --- a/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_neon.c +++ b/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_neon.c @@ -14,86 +14,22 @@ #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" #include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/highbd_convolve8_neon.h" +#include "vpx_dsp/arm/mem_neon.h" #include "vpx_dsp/arm/transpose_neon.h" +#include "vpx_dsp/vpx_dsp_common.h" +#include "vpx_dsp/vpx_filter.h" #include "vpx_ports/mem.h" -static INLINE void load_4x4(const int16_t *s, const ptrdiff_t p, - int16x4_t *const s0, int16x4_t *const s1, - int16x4_t *const s2, int16x4_t *const s3) { - *s0 = vld1_s16(s); - s += p; - *s1 = vld1_s16(s); - s += p; - *s2 = vld1_s16(s); - s += p; - *s3 = vld1_s16(s); -} - -static INLINE void load_8x4(const uint16_t *s, const ptrdiff_t p, - uint16x8_t *const s0, uint16x8_t *const s1, - uint16x8_t *const s2, uint16x8_t *const s3) { - *s0 = vld1q_u16(s); - s += p; - *s1 = vld1q_u16(s); - s += p; - *s2 = vld1q_u16(s); - s += p; - *s3 = vld1q_u16(s); -} - -static INLINE void load_8x8(const int16_t *s, const ptrdiff_t p, - int16x8_t *const s0, int16x8_t *const s1, - int16x8_t *const s2, int16x8_t *const s3, - int16x8_t *const s4, int16x8_t *const s5, - int16x8_t *const s6, int16x8_t *const s7) { - *s0 = vld1q_s16(s); - s += p; - *s1 = vld1q_s16(s); - s += p; - *s2 = vld1q_s16(s); - s += p; - *s3 = vld1q_s16(s); - s += p; - *s4 = vld1q_s16(s); - s += p; - *s5 = vld1q_s16(s); - s += p; - *s6 = vld1q_s16(s); - s += p; - *s7 = vld1q_s16(s); -} - -static INLINE void store_8x8(uint16_t *s, const ptrdiff_t p, - const uint16x8_t s0, const uint16x8_t s1, - const uint16x8_t s2, const uint16x8_t s3, - const uint16x8_t s4, const uint16x8_t s5, - const uint16x8_t s6, const uint16x8_t s7) { - vst1q_u16(s, s0); - s += p; - vst1q_u16(s, s1); - s += p; - vst1q_u16(s, s2); - s += p; - vst1q_u16(s, s3); - s += p; - vst1q_u16(s, s4); - s += p; - vst1q_u16(s, s5); - s += p; - vst1q_u16(s, s6); - s += p; - vst1q_u16(s, s7); -} - -static INLINE int32x4_t highbd_convolve8_4( - const int16x4_t s0, const int16x4_t s1, const int16x4_t s2, - const int16x4_t s3, const int16x4_t s4, const int16x4_t s5, - const int16x4_t s6, const int16x4_t s7, const int16x8_t filters) { +static INLINE uint16x4_t +highbd_convolve8_4(const int16x4_t s0, const int16x4_t s1, const int16x4_t s2, + const int16x4_t s3, const int16x4_t s4, const int16x4_t s5, + const int16x4_t s6, const int16x4_t s7, + const int16x8_t filters, const uint16x4_t max) { const int16x4_t filters_lo = vget_low_s16(filters); const int16x4_t filters_hi = vget_high_s16(filters); - int32x4_t sum; - sum = vmull_lane_s16(s0, filters_lo, 0); + int32x4_t sum = vmull_lane_s16(s0, filters_lo, 0); sum = vmlal_lane_s16(sum, s1, filters_lo, 1); sum = vmlal_lane_s16(sum, s2, filters_lo, 2); sum = vmlal_lane_s16(sum, s3, filters_lo, 3); @@ -101,7 +37,9 @@ static INLINE int32x4_t highbd_convolve8_4( sum = vmlal_lane_s16(sum, s5, filters_hi, 1); sum = vmlal_lane_s16(sum, s6, filters_hi, 2); sum = vmlal_lane_s16(sum, s7, filters_hi, 3); - return sum; + + uint16x4_t res = vqrshrun_n_s32(sum, FILTER_BITS); + return vmin_u16(res, max); } static INLINE uint16x8_t @@ -111,10 +49,8 @@ highbd_convolve8_8(const int16x8_t s0, const int16x8_t s1, const int16x8_t s2, const int16x8_t filters, const uint16x8_t max) { const int16x4_t filters_lo = vget_low_s16(filters); const int16x4_t filters_hi = vget_high_s16(filters); - int32x4_t sum0, sum1; - uint16x8_t d; - sum0 = vmull_lane_s16(vget_low_s16(s0), filters_lo, 0); + int32x4_t sum0 = vmull_lane_s16(vget_low_s16(s0), filters_lo, 0); sum0 = vmlal_lane_s16(sum0, vget_low_s16(s1), filters_lo, 1); sum0 = vmlal_lane_s16(sum0, vget_low_s16(s2), filters_lo, 2); sum0 = vmlal_lane_s16(sum0, vget_low_s16(s3), filters_lo, 3); @@ -122,7 +58,8 @@ highbd_convolve8_8(const int16x8_t s0, const int16x8_t s1, const int16x8_t s2, sum0 = vmlal_lane_s16(sum0, vget_low_s16(s5), filters_hi, 1); sum0 = vmlal_lane_s16(sum0, vget_low_s16(s6), filters_hi, 2); sum0 = vmlal_lane_s16(sum0, vget_low_s16(s7), filters_hi, 3); - sum1 = vmull_lane_s16(vget_high_s16(s0), filters_lo, 0); + + int32x4_t sum1 = vmull_lane_s16(vget_high_s16(s0), filters_lo, 0); sum1 = vmlal_lane_s16(sum1, vget_high_s16(s1), filters_lo, 1); sum1 = vmlal_lane_s16(sum1, vget_high_s16(s2), filters_lo, 2); sum1 = vmlal_lane_s16(sum1, vget_high_s16(s3), filters_lo, 3); @@ -130,9 +67,152 @@ highbd_convolve8_8(const int16x8_t s0, const int16x8_t s1, const int16x8_t s2, sum1 = vmlal_lane_s16(sum1, vget_high_s16(s5), filters_hi, 1); sum1 = vmlal_lane_s16(sum1, vget_high_s16(s6), filters_hi, 2); sum1 = vmlal_lane_s16(sum1, vget_high_s16(s7), filters_hi, 3); - d = vcombine_u16(vqrshrun_n_s32(sum0, 7), vqrshrun_n_s32(sum1, 7)); - d = vminq_u16(d, max); - return d; + + uint16x8_t res = vcombine_u16(vqrshrun_n_s32(sum0, FILTER_BITS), + vqrshrun_n_s32(sum1, FILTER_BITS)); + return vminq_u16(res, max); +} + +static INLINE void highbd_convolve_4tap_horiz_neon( + const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, int w, int h, const int16x4_t filter, int bd) { + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + do { + int16x4_t s0[4], s1[4], s2[4], s3[4]; + load_s16_4x4(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3]); + load_s16_4x4(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3]); + load_s16_4x4(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3]); + load_s16_4x4(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3]); + + uint16x4_t d0 = + highbd_convolve4_4_neon(s0[0], s0[1], s0[2], s0[3], filter, max); + uint16x4_t d1 = + highbd_convolve4_4_neon(s1[0], s1[1], s1[2], s1[3], filter, max); + uint16x4_t d2 = + highbd_convolve4_4_neon(s2[0], s2[1], s2[2], s2[3], filter, max); + uint16x4_t d3 = + highbd_convolve4_4_neon(s3[0], s3[1], s3[2], s3[3], filter, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int width = w; + + do { + int16x8_t s0[4], s1[4], s2[4], s3[4]; + load_s16_8x4(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3]); + load_s16_8x4(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3]); + load_s16_8x4(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3]); + load_s16_8x4(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3]); + + uint16x8_t d0 = + highbd_convolve4_8_neon(s0[0], s0[1], s0[2], s0[3], filter, max); + uint16x8_t d1 = + highbd_convolve4_8_neon(s1[0], s1[1], s1[2], s1[3], filter, max); + uint16x8_t d2 = + highbd_convolve4_8_neon(s2[0], s2[1], s2[2], s2[3], filter, max); + uint16x8_t d3 = + highbd_convolve4_8_neon(s3[0], s3[1], s3[2], s3[3], filter, max); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } +} + +static INLINE void highbd_convolve_8tap_horiz_neon( + const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, int w, int h, const int16x8_t filter, int bd) { + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + do { + int16x4_t s0[8], s1[8], s2[8], s3[8]; + load_s16_4x8(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3], + &s0[4], &s0[5], &s0[6], &s0[7]); + load_s16_4x8(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3], + &s1[4], &s1[5], &s1[6], &s1[7]); + load_s16_4x8(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3], + &s2[4], &s2[5], &s2[6], &s2[7]); + load_s16_4x8(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3], + &s3[4], &s3[5], &s3[6], &s3[7]); + + uint16x4_t d0 = highbd_convolve8_4(s0[0], s0[1], s0[2], s0[3], s0[4], + s0[5], s0[6], s0[7], filter, max); + uint16x4_t d1 = highbd_convolve8_4(s1[0], s1[1], s1[2], s1[3], s1[4], + s1[5], s1[6], s1[7], filter, max); + uint16x4_t d2 = highbd_convolve8_4(s2[0], s2[1], s2[2], s2[3], s2[4], + s2[5], s2[6], s2[7], filter, max); + uint16x4_t d3 = highbd_convolve8_4(s3[0], s3[1], s3[2], s3[3], s3[4], + s3[5], s3[6], s3[7], filter, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int width = w; + + do { + int16x8_t s0[8], s1[8], s2[8], s3[8]; + load_s16_8x8(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3], + &s0[4], &s0[5], &s0[6], &s0[7]); + load_s16_8x8(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3], + &s1[4], &s1[5], &s1[6], &s1[7]); + load_s16_8x8(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3], + &s2[4], &s2[5], &s2[6], &s2[7]); + load_s16_8x8(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3], + &s3[4], &s3[5], &s3[6], &s3[7]); + + uint16x8_t d0 = highbd_convolve8_8(s0[0], s0[1], s0[2], s0[3], s0[4], + s0[5], s0[6], s0[7], filter, max); + uint16x8_t d1 = highbd_convolve8_8(s1[0], s1[1], s1[2], s1[3], s1[4], + s1[5], s1[6], s1[7], filter, max); + uint16x8_t d2 = highbd_convolve8_8(s2[0], s2[1], s2[2], s2[3], s2[4], + s2[5], s2[6], s2[7], filter, max); + uint16x8_t d3 = highbd_convolve8_8(s3[0], s3[1], s3[2], s3[3], s3[4], + s3[5], s3[6], s3[7], filter, max); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } } void vpx_highbd_convolve8_horiz_neon(const uint16_t *src, ptrdiff_t src_stride, @@ -143,202 +223,25 @@ void vpx_highbd_convolve8_horiz_neon(const uint16_t *src, ptrdiff_t src_stride, if (x_step_q4 != 16) { vpx_highbd_convolve8_horiz_c(src, src_stride, dst, dst_stride, filter, x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(x_step_q4 == 16); + + (void)x_step_q4; + (void)y0_q4; + (void)y_step_q4; + + if (vpx_get_filter_taps(filter[x0_q4]) <= 4) { + const int16x4_t x_filter_4tap = vld1_s16(filter[x0_q4] + 2); + highbd_convolve_4tap_horiz_neon(src - 1, src_stride, dst, dst_stride, w, h, + x_filter_4tap, bd); } else { - const int16x8_t filters = vld1q_s16(filter[x0_q4]); - const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); - uint16x8_t t0, t1, t2, t3; - - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); - - src -= 3; - - if (h == 4) { - int16x4_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - int32x4_t d0, d1, d2, d3; - uint16x8_t d01, d23; - - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - load_8x4(src, src_stride, &t0, &t1, &t2, &t3); - transpose_u16_8x4(&t0, &t1, &t2, &t3); - s0 = vreinterpret_s16_u16(vget_low_u16(t0)); - s1 = vreinterpret_s16_u16(vget_low_u16(t1)); - s2 = vreinterpret_s16_u16(vget_low_u16(t2)); - s3 = vreinterpret_s16_u16(vget_low_u16(t3)); - s4 = vreinterpret_s16_u16(vget_high_u16(t0)); - s5 = vreinterpret_s16_u16(vget_high_u16(t1)); - s6 = vreinterpret_s16_u16(vget_high_u16(t2)); - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - src += 7; - - do { - load_4x4((const int16_t *)src, src_stride, &s7, &s8, &s9, &s10); - transpose_s16_4x4d(&s7, &s8, &s9, &s10); - - d0 = highbd_convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filters); - d1 = highbd_convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filters); - d2 = highbd_convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filters); - d3 = highbd_convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filters); - - d01 = vcombine_u16(vqrshrun_n_s32(d0, 7), vqrshrun_n_s32(d1, 7)); - d23 = vcombine_u16(vqrshrun_n_s32(d2, 7), vqrshrun_n_s32(d3, 7)); - d01 = vminq_u16(d01, max); - d23 = vminq_u16(d23, max); - transpose_u16_4x4q(&d01, &d23); - - vst1_u16(dst + 0 * dst_stride, vget_low_u16(d01)); - vst1_u16(dst + 1 * dst_stride, vget_low_u16(d23)); - vst1_u16(dst + 2 * dst_stride, vget_high_u16(d01)); - vst1_u16(dst + 3 * dst_stride, vget_high_u16(d23)); - - s0 = s4; - s1 = s5; - s2 = s6; - s3 = s7; - s4 = s8; - s5 = s9; - s6 = s10; - src += 4; - dst += 4; - w -= 4; - } while (w > 0); - } else { - int16x8_t t4, t5, t6, t7; - int16x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - uint16x8_t d0, d1, d2, d3; - - if (w == 4) { - do { - load_8x8((const int16_t *)src, src_stride, &s0, &s1, &s2, &s3, &s4, - &s5, &s6, &s7); - transpose_s16_8x8(&s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7); - - load_8x8((const int16_t *)(src + 7), src_stride, &s7, &s8, &s9, &s10, - &t4, &t5, &t6, &t7); - src += 8 * src_stride; - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(dst + 4 * dst_stride); - __builtin_prefetch(dst + 5 * dst_stride); - __builtin_prefetch(dst + 6 * dst_stride); - __builtin_prefetch(dst + 7 * dst_stride); - transpose_s16_8x8(&s7, &s8, &s9, &s10, &t4, &t5, &t6, &t7); - - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - __builtin_prefetch(src + 7 * src_stride); - d0 = highbd_convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, max); - d1 = highbd_convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, max); - d2 = highbd_convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, max); - d3 = - highbd_convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, max); - - transpose_u16_8x4(&d0, &d1, &d2, &d3); - vst1_u16(dst, vget_low_u16(d0)); - dst += dst_stride; - vst1_u16(dst, vget_low_u16(d1)); - dst += dst_stride; - vst1_u16(dst, vget_low_u16(d2)); - dst += dst_stride; - vst1_u16(dst, vget_low_u16(d3)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d0)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d1)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d2)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d3)); - dst += dst_stride; - h -= 8; - } while (h > 0); - } else { - int width; - const uint16_t *s; - uint16_t *d; - int16x8_t s11, s12, s13, s14; - uint16x8_t d4, d5, d6, d7; - - do { - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - __builtin_prefetch(src + 7 * src_stride); - load_8x8((const int16_t *)src, src_stride, &s0, &s1, &s2, &s3, &s4, - &s5, &s6, &s7); - transpose_s16_8x8(&s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7); - - width = w; - s = src + 7; - d = dst; - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(dst + 4 * dst_stride); - __builtin_prefetch(dst + 5 * dst_stride); - __builtin_prefetch(dst + 6 * dst_stride); - __builtin_prefetch(dst + 7 * dst_stride); - - do { - load_8x8((const int16_t *)s, src_stride, &s7, &s8, &s9, &s10, &s11, - &s12, &s13, &s14); - transpose_s16_8x8(&s7, &s8, &s9, &s10, &s11, &s12, &s13, &s14); - - d0 = highbd_convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, - max); - d1 = highbd_convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, - max); - d2 = highbd_convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, - max); - d3 = highbd_convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, - max); - d4 = highbd_convolve8_8(s4, s5, s6, s7, s8, s9, s10, s11, filters, - max); - d5 = highbd_convolve8_8(s5, s6, s7, s8, s9, s10, s11, s12, filters, - max); - d6 = highbd_convolve8_8(s6, s7, s8, s9, s10, s11, s12, s13, filters, - max); - d7 = highbd_convolve8_8(s7, s8, s9, s10, s11, s12, s13, s14, - filters, max); - - transpose_u16_8x8(&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7); - store_8x8(d, dst_stride, d0, d1, d2, d3, d4, d5, d6, d7); - - s0 = s8; - s1 = s9; - s2 = s10; - s3 = s11; - s4 = s12; - s5 = s13; - s6 = s14; - s += 8; - d += 8; - width -= 8; - } while (width > 0); - src += 8 * src_stride; - dst += 8 * dst_stride; - h -= 8; - } while (h > 0); - } - } + const int16x8_t x_filter_8tap = vld1q_s16(filter[x0_q4]); + highbd_convolve_8tap_horiz_neon(src - 3, src_stride, dst, dst_stride, w, h, + x_filter_8tap, bd); } } @@ -352,66 +255,233 @@ void vpx_highbd_convolve8_avg_horiz_neon(const uint16_t *src, vpx_highbd_convolve8_avg_horiz_c(src, src_stride, dst, dst_stride, filter, x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + + const int16x8_t filters = vld1q_s16(filter[x0_q4]); + + src -= 3; + + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + do { + int16x4_t s0[8], s1[8], s2[8], s3[8]; + load_s16_4x8(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3], + &s0[4], &s0[5], &s0[6], &s0[7]); + load_s16_4x8(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3], + &s1[4], &s1[5], &s1[6], &s1[7]); + load_s16_4x8(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3], + &s2[4], &s2[5], &s2[6], &s2[7]); + load_s16_4x8(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3], + &s3[4], &s3[5], &s3[6], &s3[7]); + + uint16x4_t d0 = highbd_convolve8_4(s0[0], s0[1], s0[2], s0[3], s0[4], + s0[5], s0[6], s0[7], filters, max); + uint16x4_t d1 = highbd_convolve8_4(s1[0], s1[1], s1[2], s1[3], s1[4], + s1[5], s1[6], s1[7], filters, max); + uint16x4_t d2 = highbd_convolve8_4(s2[0], s2[1], s2[2], s2[3], s2[4], + s2[5], s2[6], s2[7], filters, max); + uint16x4_t d3 = highbd_convolve8_4(s3[0], s3[1], s3[2], s3[3], s3[4], + s3[5], s3[6], s3[7], filters, max); + + d0 = vrhadd_u16(d0, vld1_u16(d + 0 * dst_stride)); + d1 = vrhadd_u16(d1, vld1_u16(d + 1 * dst_stride)); + d2 = vrhadd_u16(d2, vld1_u16(d + 2 * dst_stride)); + d3 = vrhadd_u16(d3, vld1_u16(d + 3 * dst_stride)); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); } else { - const int16x8_t filters = vld1q_s16(filter[x0_q4]); const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); - uint16x8_t t0, t1, t2, t3; - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); - - src -= 3; - - if (h == 4) { - int16x4_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - int32x4_t d0, d1, d2, d3; - uint16x8_t d01, d23, t01, t23; - - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - load_8x4(src, src_stride, &t0, &t1, &t2, &t3); - transpose_u16_8x4(&t0, &t1, &t2, &t3); - s0 = vreinterpret_s16_u16(vget_low_u16(t0)); - s1 = vreinterpret_s16_u16(vget_low_u16(t1)); - s2 = vreinterpret_s16_u16(vget_low_u16(t2)); - s3 = vreinterpret_s16_u16(vget_low_u16(t3)); - s4 = vreinterpret_s16_u16(vget_high_u16(t0)); - s5 = vreinterpret_s16_u16(vget_high_u16(t1)); - s6 = vreinterpret_s16_u16(vget_high_u16(t2)); - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - src += 7; + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int width = w; do { - load_4x4((const int16_t *)src, src_stride, &s7, &s8, &s9, &s10); - transpose_s16_4x4d(&s7, &s8, &s9, &s10); + int16x8_t s0[8], s1[8], s2[8], s3[8]; + load_s16_8x8(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3], + &s0[4], &s0[5], &s0[6], &s0[7]); + load_s16_8x8(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3], + &s1[4], &s1[5], &s1[6], &s1[7]); + load_s16_8x8(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3], + &s2[4], &s2[5], &s2[6], &s2[7]); + load_s16_8x8(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3], + &s3[4], &s3[5], &s3[6], &s3[7]); - d0 = highbd_convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filters); - d1 = highbd_convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filters); - d2 = highbd_convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filters); - d3 = highbd_convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filters); + uint16x8_t d0 = highbd_convolve8_8(s0[0], s0[1], s0[2], s0[3], s0[4], + s0[5], s0[6], s0[7], filters, max); + uint16x8_t d1 = highbd_convolve8_8(s1[0], s1[1], s1[2], s1[3], s1[4], + s1[5], s1[6], s1[7], filters, max); + uint16x8_t d2 = highbd_convolve8_8(s2[0], s2[1], s2[2], s2[3], s2[4], + s2[5], s2[6], s2[7], filters, max); + uint16x8_t d3 = highbd_convolve8_8(s3[0], s3[1], s3[2], s3[3], s3[4], + s3[5], s3[6], s3[7], filters, max); - t01 = vcombine_u16(vqrshrun_n_s32(d0, 7), vqrshrun_n_s32(d1, 7)); - t23 = vcombine_u16(vqrshrun_n_s32(d2, 7), vqrshrun_n_s32(d3, 7)); - t01 = vminq_u16(t01, max); - t23 = vminq_u16(t23, max); - transpose_u16_4x4q(&t01, &t23); + d0 = vrhaddq_u16(d0, vld1q_u16(d + 0 * dst_stride)); + d1 = vrhaddq_u16(d1, vld1q_u16(d + 1 * dst_stride)); + d2 = vrhaddq_u16(d2, vld1q_u16(d + 2 * dst_stride)); + d3 = vrhaddq_u16(d3, vld1q_u16(d + 3 * dst_stride)); - d01 = vcombine_u16(vld1_u16(dst + 0 * dst_stride), - vld1_u16(dst + 2 * dst_stride)); - d23 = vcombine_u16(vld1_u16(dst + 1 * dst_stride), - vld1_u16(dst + 3 * dst_stride)); - d01 = vrhaddq_u16(d01, t01); - d23 = vrhaddq_u16(d23, t23); + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); - vst1_u16(dst + 0 * dst_stride, vget_low_u16(d01)); - vst1_u16(dst + 1 * dst_stride, vget_low_u16(d23)); - vst1_u16(dst + 2 * dst_stride, vget_high_u16(d01)); - vst1_u16(dst + 3 * dst_stride, vget_high_u16(d23)); + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } +} + +static INLINE void highbd_convolve_4tap_vert_neon( + const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, int w, int h, const int16x4_t filter, int bd) { + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + int16x4_t s0, s1, s2; + load_s16_4x3(s, src_stride, &s0, &s1, &s2); + + s += 3 * src_stride; + + do { + int16x4_t s3, s4, s5, s6; + load_s16_4x4(s, src_stride, &s3, &s4, &s5, &s6); + + uint16x4_t d0 = highbd_convolve4_4_neon(s0, s1, s2, s3, filter, max); + uint16x4_t d1 = highbd_convolve4_4_neon(s1, s2, s3, s4, filter, max); + uint16x4_t d2 = highbd_convolve4_4_neon(s2, s3, s4, s5, filter, max); + uint16x4_t d3 = highbd_convolve4_4_neon(s3, s4, s5, s6, filter, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s0 = s4; + s1 = s5; + s2 = s6; + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int height = h; + + int16x8_t s0, s1, s2; + load_s16_8x3(s, src_stride, &s0, &s1, &s2); + + s += 3 * src_stride; + + do { + int16x8_t s3, s4, s5, s6; + load_s16_8x4(s, src_stride, &s3, &s4, &s5, &s6); + + uint16x8_t d0 = highbd_convolve4_8_neon(s0, s1, s2, s3, filter, max); + uint16x8_t d1 = highbd_convolve4_8_neon(s1, s2, s3, s4, filter, max); + uint16x8_t d2 = highbd_convolve4_8_neon(s2, s3, s4, s5, filter, max); + uint16x8_t d3 = highbd_convolve4_8_neon(s3, s4, s5, s6, filter, max); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + s0 = s4; + s1 = s5; + s2 = s6; + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); + } +} + +static INLINE void highbd_convolve_8tap_vert_neon( + const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, int w, int h, const int16x8_t filter, int bd) { + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + int16x4_t s0, s1, s2, s3, s4, s5, s6; + load_s16_4x7(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6); + + s += 7 * src_stride; + + do { + int16x4_t s7, s8, s9, s10; + load_s16_4x4(s, src_stride, &s7, &s8, &s9, &s10); + + uint16x4_t d0 = + highbd_convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filter, max); + uint16x4_t d1 = + highbd_convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filter, max); + uint16x4_t d2 = + highbd_convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filter, max); + uint16x4_t d3 = + highbd_convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filter, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s0 = s4; + s1 = s5; + s2 = s6; + s3 = s7; + s4 = s8; + s5 = s9; + s6 = s10; + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int height = h; + + int16x8_t s0, s1, s2, s3, s4, s5, s6; + load_s16_8x7(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6); + + s += 7 * src_stride; + + do { + int16x8_t s7, s8, s9, s10; + load_s16_8x4(s, src_stride, &s7, &s8, &s9, &s10); + + uint16x8_t d0 = + highbd_convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filter, max); + uint16x8_t d1 = + highbd_convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filter, max); + uint16x8_t d2 = + highbd_convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filter, max); + uint16x8_t d3 = + highbd_convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filter, max); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); s0 = s4; s1 = s5; @@ -420,164 +490,14 @@ void vpx_highbd_convolve8_avg_horiz_neon(const uint16_t *src, s4 = s8; s5 = s9; s6 = s10; - src += 4; - dst += 4; - w -= 4; - } while (w > 0); - } else { - int16x8_t t4, t5, t6, t7; - int16x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - uint16x8_t d0, d1, d2, d3, t0, t1, t2, t3; - - if (w == 4) { - do { - load_8x8((const int16_t *)src, src_stride, &s0, &s1, &s2, &s3, &s4, - &s5, &s6, &s7); - transpose_s16_8x8(&s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7); - - load_8x8((const int16_t *)(src + 7), src_stride, &s7, &s8, &s9, &s10, - &t4, &t5, &t6, &t7); - src += 8 * src_stride; - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(dst + 4 * dst_stride); - __builtin_prefetch(dst + 5 * dst_stride); - __builtin_prefetch(dst + 6 * dst_stride); - __builtin_prefetch(dst + 7 * dst_stride); - transpose_s16_8x8(&s7, &s8, &s9, &s10, &t4, &t5, &t6, &t7); - - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - __builtin_prefetch(src + 7 * src_stride); - t0 = highbd_convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, max); - t1 = highbd_convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, max); - t2 = highbd_convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, max); - t3 = - highbd_convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, max); - transpose_u16_8x4(&t0, &t1, &t2, &t3); - - d0 = vcombine_u16(vld1_u16(dst + 0 * dst_stride), - vld1_u16(dst + 4 * dst_stride)); - d1 = vcombine_u16(vld1_u16(dst + 1 * dst_stride), - vld1_u16(dst + 5 * dst_stride)); - d2 = vcombine_u16(vld1_u16(dst + 2 * dst_stride), - vld1_u16(dst + 6 * dst_stride)); - d3 = vcombine_u16(vld1_u16(dst + 3 * dst_stride), - vld1_u16(dst + 7 * dst_stride)); - d0 = vrhaddq_u16(d0, t0); - d1 = vrhaddq_u16(d1, t1); - d2 = vrhaddq_u16(d2, t2); - d3 = vrhaddq_u16(d3, t3); - - vst1_u16(dst, vget_low_u16(d0)); - dst += dst_stride; - vst1_u16(dst, vget_low_u16(d1)); - dst += dst_stride; - vst1_u16(dst, vget_low_u16(d2)); - dst += dst_stride; - vst1_u16(dst, vget_low_u16(d3)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d0)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d1)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d2)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d3)); - dst += dst_stride; - h -= 8; - } while (h > 0); - } else { - int width; - const uint16_t *s; - uint16_t *d; - int16x8_t s11, s12, s13, s14; - uint16x8_t d4, d5, d6, d7; - - do { - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - __builtin_prefetch(src + 7 * src_stride); - load_8x8((const int16_t *)src, src_stride, &s0, &s1, &s2, &s3, &s4, - &s5, &s6, &s7); - transpose_s16_8x8(&s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7); - - width = w; - s = src + 7; - d = dst; - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(dst + 4 * dst_stride); - __builtin_prefetch(dst + 5 * dst_stride); - __builtin_prefetch(dst + 6 * dst_stride); - __builtin_prefetch(dst + 7 * dst_stride); - - do { - load_8x8((const int16_t *)s, src_stride, &s7, &s8, &s9, &s10, &s11, - &s12, &s13, &s14); - transpose_s16_8x8(&s7, &s8, &s9, &s10, &s11, &s12, &s13, &s14); - - d0 = highbd_convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, - max); - d1 = highbd_convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, - max); - d2 = highbd_convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, - max); - d3 = highbd_convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, - max); - d4 = highbd_convolve8_8(s4, s5, s6, s7, s8, s9, s10, s11, filters, - max); - d5 = highbd_convolve8_8(s5, s6, s7, s8, s9, s10, s11, s12, filters, - max); - d6 = highbd_convolve8_8(s6, s7, s8, s9, s10, s11, s12, s13, filters, - max); - d7 = highbd_convolve8_8(s7, s8, s9, s10, s11, s12, s13, s14, - filters, max); - - transpose_u16_8x8(&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7); - - d0 = vrhaddq_u16(d0, vld1q_u16(d + 0 * dst_stride)); - d1 = vrhaddq_u16(d1, vld1q_u16(d + 1 * dst_stride)); - d2 = vrhaddq_u16(d2, vld1q_u16(d + 2 * dst_stride)); - d3 = vrhaddq_u16(d3, vld1q_u16(d + 3 * dst_stride)); - d4 = vrhaddq_u16(d4, vld1q_u16(d + 4 * dst_stride)); - d5 = vrhaddq_u16(d5, vld1q_u16(d + 5 * dst_stride)); - d6 = vrhaddq_u16(d6, vld1q_u16(d + 6 * dst_stride)); - d7 = vrhaddq_u16(d7, vld1q_u16(d + 7 * dst_stride)); - - store_8x8(d, dst_stride, d0, d1, d2, d3, d4, d5, d6, d7); - - s0 = s8; - s1 = s9; - s2 = s10; - s3 = s11; - s4 = s12; - s5 = s13; - s6 = s14; - s += 8; - d += 8; - width -= 8; - } while (width > 0); - src += 8 * src_stride; - dst += 8 * dst_stride; - h -= 8; - } while (h > 0); - } - } + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); } } @@ -589,160 +509,25 @@ void vpx_highbd_convolve8_vert_neon(const uint16_t *src, ptrdiff_t src_stride, if (y_step_q4 != 16) { vpx_highbd_convolve8_vert_c(src, src_stride, dst, dst_stride, filter, x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(y_step_q4 == 16); + + (void)x_step_q4; + (void)y0_q4; + (void)y_step_q4; + + if (vpx_get_filter_taps(filter[y0_q4]) <= 4) { + const int16x4_t y_filter_4tap = vld1_s16(filter[y0_q4] + 2); + highbd_convolve_4tap_vert_neon(src - src_stride, src_stride, dst, + dst_stride, w, h, y_filter_4tap, bd); } else { - const int16x8_t filters = vld1q_s16(filter[y0_q4]); - const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); - - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); - - src -= 3 * src_stride; - - if (w == 4) { - int16x4_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - int32x4_t d0, d1, d2, d3; - uint16x8_t d01, d23; - - s0 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s1 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s2 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s3 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s4 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s5 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s6 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - - do { - s7 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s8 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s9 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s10 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - d0 = highbd_convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filters); - d1 = highbd_convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filters); - d2 = highbd_convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filters); - d3 = highbd_convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filters); - - d01 = vcombine_u16(vqrshrun_n_s32(d0, 7), vqrshrun_n_s32(d1, 7)); - d23 = vcombine_u16(vqrshrun_n_s32(d2, 7), vqrshrun_n_s32(d3, 7)); - d01 = vminq_u16(d01, max); - d23 = vminq_u16(d23, max); - vst1_u16(dst, vget_low_u16(d01)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d01)); - dst += dst_stride; - vst1_u16(dst, vget_low_u16(d23)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d23)); - dst += dst_stride; - - s0 = s4; - s1 = s5; - s2 = s6; - s3 = s7; - s4 = s8; - s5 = s9; - s6 = s10; - h -= 4; - } while (h > 0); - } else { - int height; - const uint16_t *s; - uint16_t *d; - int16x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - uint16x8_t d0, d1, d2, d3; - - do { - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - s = src; - s0 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s1 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s2 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s3 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s4 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s5 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s6 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - d = dst; - height = h; - - do { - s7 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s8 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s9 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s10 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - - __builtin_prefetch(d + 0 * dst_stride); - __builtin_prefetch(d + 1 * dst_stride); - __builtin_prefetch(d + 2 * dst_stride); - __builtin_prefetch(d + 3 * dst_stride); - __builtin_prefetch(s + 0 * src_stride); - __builtin_prefetch(s + 1 * src_stride); - __builtin_prefetch(s + 2 * src_stride); - __builtin_prefetch(s + 3 * src_stride); - d0 = highbd_convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, max); - d1 = highbd_convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, max); - d2 = highbd_convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, max); - d3 = - highbd_convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, max); - - vst1q_u16(d, d0); - d += dst_stride; - vst1q_u16(d, d1); - d += dst_stride; - vst1q_u16(d, d2); - d += dst_stride; - vst1q_u16(d, d3); - d += dst_stride; - - s0 = s4; - s1 = s5; - s2 = s6; - s3 = s7; - s4 = s8; - s5 = s9; - s6 = s10; - height -= 4; - } while (height > 0); - src += 8; - dst += 8; - w -= 8; - } while (w > 0); - } + const int16x8_t y_filter_8tap = vld1q_s16(filter[y0_q4]); + highbd_convolve_8tap_vert_neon(src - 3 * src_stride, src_stride, dst, + dst_stride, w, h, y_filter_8tap, bd); } } @@ -756,78 +541,89 @@ void vpx_highbd_convolve8_avg_vert_neon(const uint16_t *src, vpx_highbd_convolve8_avg_vert_c(src, src_stride, dst, dst_stride, filter, x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + + const int16x8_t filters = vld1q_s16(filter[y0_q4]); + + src -= 3 * src_stride; + + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + int16x4_t s0, s1, s2, s3, s4, s5, s6; + load_s16_4x7(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6); + + s += 7 * src_stride; + + do { + int16x4_t s7, s8, s9, s10; + load_s16_4x4(s, src_stride, &s7, &s8, &s9, &s10); + + uint16x4_t d0 = + highbd_convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filters, max); + uint16x4_t d1 = + highbd_convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filters, max); + uint16x4_t d2 = + highbd_convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filters, max); + uint16x4_t d3 = + highbd_convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filters, max); + + d0 = vrhadd_u16(d0, vld1_u16(d + 0 * dst_stride)); + d1 = vrhadd_u16(d1, vld1_u16(d + 1 * dst_stride)); + d2 = vrhadd_u16(d2, vld1_u16(d + 2 * dst_stride)); + d3 = vrhadd_u16(d3, vld1_u16(d + 3 * dst_stride)); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s0 = s4; + s1 = s5; + s2 = s6; + s3 = s7; + s4 = s8; + s5 = s9; + s6 = s10; + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); } else { - const int16x8_t filters = vld1q_s16(filter[y0_q4]); const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int height = h; - src -= 3 * src_stride; + int16x8_t s0, s1, s2, s3, s4, s5, s6; + load_s16_8x7(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6); - if (w == 4) { - int16x4_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - int32x4_t d0, d1, d2, d3; - uint16x8_t d01, d23, t01, t23; - - s0 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s1 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s2 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s3 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s4 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s5 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s6 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; + s += 7 * src_stride; do { - s7 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s8 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s9 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; - s10 = vreinterpret_s16_u16(vld1_u16(src)); - src += src_stride; + int16x8_t s7, s8, s9, s10; + load_s16_8x4(s, src_stride, &s7, &s8, &s9, &s10); - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - d0 = highbd_convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filters); - d1 = highbd_convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filters); - d2 = highbd_convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filters); - d3 = highbd_convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filters); + uint16x8_t d0 = + highbd_convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, max); + uint16x8_t d1 = + highbd_convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, max); + uint16x8_t d2 = + highbd_convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, max); + uint16x8_t d3 = + highbd_convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, max); - t01 = vcombine_u16(vqrshrun_n_s32(d0, 7), vqrshrun_n_s32(d1, 7)); - t23 = vcombine_u16(vqrshrun_n_s32(d2, 7), vqrshrun_n_s32(d3, 7)); - t01 = vminq_u16(t01, max); - t23 = vminq_u16(t23, max); + d0 = vrhaddq_u16(d0, vld1q_u16(d + 0 * dst_stride)); + d1 = vrhaddq_u16(d1, vld1q_u16(d + 1 * dst_stride)); + d2 = vrhaddq_u16(d2, vld1q_u16(d + 2 * dst_stride)); + d3 = vrhaddq_u16(d3, vld1q_u16(d + 3 * dst_stride)); - d01 = vcombine_u16(vld1_u16(dst + 0 * dst_stride), - vld1_u16(dst + 1 * dst_stride)); - d23 = vcombine_u16(vld1_u16(dst + 2 * dst_stride), - vld1_u16(dst + 3 * dst_stride)); - d01 = vrhaddq_u16(d01, t01); - d23 = vrhaddq_u16(d23, t23); - - vst1_u16(dst, vget_low_u16(d01)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d01)); - dst += dst_stride; - vst1_u16(dst, vget_low_u16(d23)); - dst += dst_stride; - vst1_u16(dst, vget_high_u16(d23)); - dst += dst_stride; + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); s0 = s4; s1 = s5; @@ -836,96 +632,600 @@ void vpx_highbd_convolve8_avg_vert_neon(const uint16_t *src, s4 = s8; s5 = s9; s6 = s10; - h -= 4; - } while (h > 0); - } else { - int height; - const uint16_t *s; - uint16_t *d; - int16x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - uint16x8_t d0, d1, d2, d3, t0, t1, t2, t3; - - do { - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - s = src; - s0 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s1 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s2 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s3 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s4 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s5 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s6 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - d = dst; - height = h; - - do { - s7 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s8 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s9 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - s10 = vreinterpretq_s16_u16(vld1q_u16(s)); - s += src_stride; - - __builtin_prefetch(d + 0 * dst_stride); - __builtin_prefetch(d + 1 * dst_stride); - __builtin_prefetch(d + 2 * dst_stride); - __builtin_prefetch(d + 3 * dst_stride); - __builtin_prefetch(s + 0 * src_stride); - __builtin_prefetch(s + 1 * src_stride); - __builtin_prefetch(s + 2 * src_stride); - __builtin_prefetch(s + 3 * src_stride); - t0 = highbd_convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, max); - t1 = highbd_convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, max); - t2 = highbd_convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, max); - t3 = - highbd_convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, max); - - d0 = vld1q_u16(d + 0 * dst_stride); - d1 = vld1q_u16(d + 1 * dst_stride); - d2 = vld1q_u16(d + 2 * dst_stride); - d3 = vld1q_u16(d + 3 * dst_stride); - d0 = vrhaddq_u16(d0, t0); - d1 = vrhaddq_u16(d1, t1); - d2 = vrhaddq_u16(d2, t2); - d3 = vrhaddq_u16(d3, t3); - - vst1q_u16(d, d0); - d += dst_stride; - vst1q_u16(d, d1); - d += dst_stride; - vst1q_u16(d, d2); - d += dst_stride; - vst1q_u16(d, d3); - d += dst_stride; - - s0 = s4; - s1 = s5; - s2 = s6; - s3 = s7; - s4 = s8; - s5 = s9; - s6 = s10; - height -= 4; - } while (height > 0); - src += 8; - dst += 8; - w -= 8; - } while (w > 0); - } + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); } } + +static INLINE void highbd_convolve_2d_4tap_neon( + const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, int w, int h, const int16x4_t x_filter, + const int16x4_t y_filter, int bd) { + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + int16x4_t h_s0[4], h_s1[4], h_s2[4]; + load_s16_4x4(s + 0 * src_stride, 1, &h_s0[0], &h_s0[1], &h_s0[2], &h_s0[3]); + load_s16_4x4(s + 1 * src_stride, 1, &h_s1[0], &h_s1[1], &h_s1[2], &h_s1[3]); + load_s16_4x4(s + 2 * src_stride, 1, &h_s2[0], &h_s2[1], &h_s2[2], &h_s2[3]); + + int16x4_t v_s0 = vreinterpret_s16_u16(highbd_convolve4_4_neon( + h_s0[0], h_s0[1], h_s0[2], h_s0[3], x_filter, max)); + int16x4_t v_s1 = vreinterpret_s16_u16(highbd_convolve4_4_neon( + h_s1[0], h_s1[1], h_s1[2], h_s1[3], x_filter, max)); + int16x4_t v_s2 = vreinterpret_s16_u16(highbd_convolve4_4_neon( + h_s2[0], h_s2[1], h_s2[2], h_s2[3], x_filter, max)); + + s += 3 * src_stride; + + do { + int16x4_t h_s3[4], h_s4[4], h_s5[4], h_s6[4]; + load_s16_4x4(s + 0 * src_stride, 1, &h_s3[0], &h_s3[1], &h_s3[2], + &h_s3[3]); + load_s16_4x4(s + 1 * src_stride, 1, &h_s4[0], &h_s4[1], &h_s4[2], + &h_s4[3]); + load_s16_4x4(s + 2 * src_stride, 1, &h_s5[0], &h_s5[1], &h_s5[2], + &h_s5[3]); + load_s16_4x4(s + 3 * src_stride, 1, &h_s6[0], &h_s6[1], &h_s6[2], + &h_s6[3]); + + int16x4_t v_s3 = vreinterpret_s16_u16(highbd_convolve4_4_neon( + h_s3[0], h_s3[1], h_s3[2], h_s3[3], x_filter, max)); + int16x4_t v_s4 = vreinterpret_s16_u16(highbd_convolve4_4_neon( + h_s4[0], h_s4[1], h_s4[2], h_s4[3], x_filter, max)); + int16x4_t v_s5 = vreinterpret_s16_u16(highbd_convolve4_4_neon( + h_s5[0], h_s5[1], h_s5[2], h_s5[3], x_filter, max)); + int16x4_t v_s6 = vreinterpret_s16_u16(highbd_convolve4_4_neon( + h_s6[0], h_s6[1], h_s6[2], h_s6[3], x_filter, max)); + + uint16x4_t d0 = + highbd_convolve4_4_neon(v_s0, v_s1, v_s2, v_s3, y_filter, max); + uint16x4_t d1 = + highbd_convolve4_4_neon(v_s1, v_s2, v_s3, v_s4, y_filter, max); + uint16x4_t d2 = + highbd_convolve4_4_neon(v_s2, v_s3, v_s4, v_s5, y_filter, max); + uint16x4_t d3 = + highbd_convolve4_4_neon(v_s3, v_s4, v_s5, v_s6, y_filter, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + v_s0 = v_s4; + v_s1 = v_s5; + v_s2 = v_s6; + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + + return; + } + + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int height = h; + + int16x8_t h_s0[4], h_s1[4], h_s2[4]; + load_s16_8x4(s + 0 * src_stride, 1, &h_s0[0], &h_s0[1], &h_s0[2], &h_s0[3]); + load_s16_8x4(s + 1 * src_stride, 1, &h_s1[0], &h_s1[1], &h_s1[2], &h_s1[3]); + load_s16_8x4(s + 2 * src_stride, 1, &h_s2[0], &h_s2[1], &h_s2[2], &h_s2[3]); + + int16x8_t v_s0 = vreinterpretq_s16_u16(highbd_convolve4_8_neon( + h_s0[0], h_s0[1], h_s0[2], h_s0[3], x_filter, max)); + int16x8_t v_s1 = vreinterpretq_s16_u16(highbd_convolve4_8_neon( + h_s1[0], h_s1[1], h_s1[2], h_s1[3], x_filter, max)); + int16x8_t v_s2 = vreinterpretq_s16_u16(highbd_convolve4_8_neon( + h_s2[0], h_s2[1], h_s2[2], h_s2[3], x_filter, max)); + + s += 3 * src_stride; + + do { + int16x8_t h_s3[4], h_s4[4], h_s5[4], h_s6[4]; + load_s16_8x4(s + 0 * src_stride, 1, &h_s3[0], &h_s3[1], &h_s3[2], + &h_s3[3]); + load_s16_8x4(s + 1 * src_stride, 1, &h_s4[0], &h_s4[1], &h_s4[2], + &h_s4[3]); + load_s16_8x4(s + 2 * src_stride, 1, &h_s5[0], &h_s5[1], &h_s5[2], + &h_s5[3]); + load_s16_8x4(s + 3 * src_stride, 1, &h_s6[0], &h_s6[1], &h_s6[2], + &h_s6[3]); + + int16x8_t v_s3 = vreinterpretq_s16_u16(highbd_convolve4_8_neon( + h_s3[0], h_s3[1], h_s3[2], h_s3[3], x_filter, max)); + int16x8_t v_s4 = vreinterpretq_s16_u16(highbd_convolve4_8_neon( + h_s4[0], h_s4[1], h_s4[2], h_s4[3], x_filter, max)); + int16x8_t v_s5 = vreinterpretq_s16_u16(highbd_convolve4_8_neon( + h_s5[0], h_s5[1], h_s5[2], h_s5[3], x_filter, max)); + int16x8_t v_s6 = vreinterpretq_s16_u16(highbd_convolve4_8_neon( + h_s6[0], h_s6[1], h_s6[2], h_s6[3], x_filter, max)); + + uint16x8_t d0 = + highbd_convolve4_8_neon(v_s0, v_s1, v_s2, v_s3, y_filter, max); + uint16x8_t d1 = + highbd_convolve4_8_neon(v_s1, v_s2, v_s3, v_s4, y_filter, max); + uint16x8_t d2 = + highbd_convolve4_8_neon(v_s2, v_s3, v_s4, v_s5, y_filter, max); + uint16x8_t d3 = + highbd_convolve4_8_neon(v_s3, v_s4, v_s5, v_s6, y_filter, max); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + v_s0 = v_s4; + v_s1 = v_s5; + v_s2 = v_s6; + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); +} + +static INLINE void highbd_convolve_2d_8tap_neon( + const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, int w, int h, const int16x8_t x_filter, + const int16x8_t y_filter, int bd) { + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + int16x4_t h_s0[8], h_s1[8], h_s2[8], h_s3[8], h_s4[8], h_s5[8], h_s6[8]; + load_s16_4x8(s + 0 * src_stride, 1, &h_s0[0], &h_s0[1], &h_s0[2], &h_s0[3], + &h_s0[4], &h_s0[5], &h_s0[6], &h_s0[7]); + load_s16_4x8(s + 1 * src_stride, 1, &h_s1[0], &h_s1[1], &h_s1[2], &h_s1[3], + &h_s1[4], &h_s1[5], &h_s1[6], &h_s1[7]); + load_s16_4x8(s + 2 * src_stride, 1, &h_s2[0], &h_s2[1], &h_s2[2], &h_s2[3], + &h_s2[4], &h_s2[5], &h_s2[6], &h_s2[7]); + load_s16_4x8(s + 3 * src_stride, 1, &h_s3[0], &h_s3[1], &h_s3[2], &h_s3[3], + &h_s3[4], &h_s3[5], &h_s3[6], &h_s3[7]); + load_s16_4x8(s + 4 * src_stride, 1, &h_s4[0], &h_s4[1], &h_s4[2], &h_s4[3], + &h_s4[4], &h_s4[5], &h_s4[6], &h_s4[7]); + load_s16_4x8(s + 5 * src_stride, 1, &h_s5[0], &h_s5[1], &h_s5[2], &h_s5[3], + &h_s5[4], &h_s5[5], &h_s5[6], &h_s5[7]); + load_s16_4x8(s + 6 * src_stride, 1, &h_s6[0], &h_s6[1], &h_s6[2], &h_s6[3], + &h_s6[4], &h_s6[5], &h_s6[6], &h_s6[7]); + + int16x4_t v_s0 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s0[0], h_s0[1], h_s0[2], h_s0[3], h_s0[4], h_s0[5], + h_s0[6], h_s0[7], x_filter, max)); + int16x4_t v_s1 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s1[0], h_s1[1], h_s1[2], h_s1[3], h_s1[4], h_s1[5], + h_s1[6], h_s1[7], x_filter, max)); + int16x4_t v_s2 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s2[0], h_s2[1], h_s2[2], h_s2[3], h_s2[4], h_s2[5], + h_s2[6], h_s2[7], x_filter, max)); + int16x4_t v_s3 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s3[0], h_s3[1], h_s3[2], h_s3[3], h_s3[4], h_s3[5], + h_s3[6], h_s3[7], x_filter, max)); + int16x4_t v_s4 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s4[0], h_s4[1], h_s4[2], h_s4[3], h_s4[4], h_s4[5], + h_s4[6], h_s4[7], x_filter, max)); + int16x4_t v_s5 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s5[0], h_s5[1], h_s5[2], h_s5[3], h_s5[4], h_s5[5], + h_s5[6], h_s5[7], x_filter, max)); + int16x4_t v_s6 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s6[0], h_s6[1], h_s6[2], h_s6[3], h_s6[4], h_s6[5], + h_s6[6], h_s6[7], x_filter, max)); + + s += 7 * src_stride; + + do { + int16x4_t h_s7[8], h_s8[8], h_s9[8], h_s10[8]; + load_s16_4x8(s + 0 * src_stride, 1, &h_s7[0], &h_s7[1], &h_s7[2], + &h_s7[3], &h_s7[4], &h_s7[5], &h_s7[6], &h_s7[7]); + load_s16_4x8(s + 1 * src_stride, 1, &h_s8[0], &h_s8[1], &h_s8[2], + &h_s8[3], &h_s8[4], &h_s8[5], &h_s8[6], &h_s8[7]); + load_s16_4x8(s + 2 * src_stride, 1, &h_s9[0], &h_s9[1], &h_s9[2], + &h_s9[3], &h_s9[4], &h_s9[5], &h_s9[6], &h_s9[7]); + load_s16_4x8(s + 3 * src_stride, 1, &h_s10[0], &h_s10[1], &h_s10[2], + &h_s10[3], &h_s10[4], &h_s10[5], &h_s10[6], &h_s10[7]); + + int16x4_t v_s7 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s7[0], h_s7[1], h_s7[2], h_s7[3], h_s7[4], + h_s7[5], h_s7[6], h_s7[7], x_filter, max)); + int16x4_t v_s8 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s8[0], h_s8[1], h_s8[2], h_s8[3], h_s8[4], + h_s8[5], h_s8[6], h_s8[7], x_filter, max)); + int16x4_t v_s9 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s9[0], h_s9[1], h_s9[2], h_s9[3], h_s9[4], + h_s9[5], h_s9[6], h_s9[7], x_filter, max)); + int16x4_t v_s10 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s10[0], h_s10[1], h_s10[2], h_s10[3], h_s10[4], + h_s10[5], h_s10[6], h_s10[7], x_filter, max)); + + uint16x4_t d0 = highbd_convolve8_4(v_s0, v_s1, v_s2, v_s3, v_s4, v_s5, + v_s6, v_s7, y_filter, max); + uint16x4_t d1 = highbd_convolve8_4(v_s1, v_s2, v_s3, v_s4, v_s5, v_s6, + v_s7, v_s8, y_filter, max); + uint16x4_t d2 = highbd_convolve8_4(v_s2, v_s3, v_s4, v_s5, v_s6, v_s7, + v_s8, v_s9, y_filter, max); + uint16x4_t d3 = highbd_convolve8_4(v_s3, v_s4, v_s5, v_s6, v_s7, v_s8, + v_s9, v_s10, y_filter, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + v_s0 = v_s4; + v_s1 = v_s5; + v_s2 = v_s6; + v_s3 = v_s7; + v_s4 = v_s8; + v_s5 = v_s9; + v_s6 = v_s10; + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + + return; + } + + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int height = h; + + int16x8_t h_s0[8], h_s1[8], h_s2[8], h_s3[8], h_s4[8], h_s5[8], h_s6[8]; + load_s16_8x8(s + 0 * src_stride, 1, &h_s0[0], &h_s0[1], &h_s0[2], &h_s0[3], + &h_s0[4], &h_s0[5], &h_s0[6], &h_s0[7]); + load_s16_8x8(s + 1 * src_stride, 1, &h_s1[0], &h_s1[1], &h_s1[2], &h_s1[3], + &h_s1[4], &h_s1[5], &h_s1[6], &h_s1[7]); + load_s16_8x8(s + 2 * src_stride, 1, &h_s2[0], &h_s2[1], &h_s2[2], &h_s2[3], + &h_s2[4], &h_s2[5], &h_s2[6], &h_s2[7]); + load_s16_8x8(s + 3 * src_stride, 1, &h_s3[0], &h_s3[1], &h_s3[2], &h_s3[3], + &h_s3[4], &h_s3[5], &h_s3[6], &h_s3[7]); + load_s16_8x8(s + 4 * src_stride, 1, &h_s4[0], &h_s4[1], &h_s4[2], &h_s4[3], + &h_s4[4], &h_s4[5], &h_s4[6], &h_s4[7]); + load_s16_8x8(s + 5 * src_stride, 1, &h_s5[0], &h_s5[1], &h_s5[2], &h_s5[3], + &h_s5[4], &h_s5[5], &h_s5[6], &h_s5[7]); + load_s16_8x8(s + 6 * src_stride, 1, &h_s6[0], &h_s6[1], &h_s6[2], &h_s6[3], + &h_s6[4], &h_s6[5], &h_s6[6], &h_s6[7]); + + int16x8_t v_s0 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s0[0], h_s0[1], h_s0[2], h_s0[3], h_s0[4], h_s0[5], + h_s0[6], h_s0[7], x_filter, max)); + int16x8_t v_s1 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s1[0], h_s1[1], h_s1[2], h_s1[3], h_s1[4], h_s1[5], + h_s1[6], h_s1[7], x_filter, max)); + int16x8_t v_s2 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s2[0], h_s2[1], h_s2[2], h_s2[3], h_s2[4], h_s2[5], + h_s2[6], h_s2[7], x_filter, max)); + int16x8_t v_s3 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s3[0], h_s3[1], h_s3[2], h_s3[3], h_s3[4], h_s3[5], + h_s3[6], h_s3[7], x_filter, max)); + int16x8_t v_s4 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s4[0], h_s4[1], h_s4[2], h_s4[3], h_s4[4], h_s4[5], + h_s4[6], h_s4[7], x_filter, max)); + int16x8_t v_s5 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s5[0], h_s5[1], h_s5[2], h_s5[3], h_s5[4], h_s5[5], + h_s5[6], h_s5[7], x_filter, max)); + int16x8_t v_s6 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s6[0], h_s6[1], h_s6[2], h_s6[3], h_s6[4], h_s6[5], + h_s6[6], h_s6[7], x_filter, max)); + + s += 7 * src_stride; + + do { + int16x8_t h_s7[8], h_s8[8], h_s9[8], h_s10[8]; + load_s16_8x8(s + 0 * src_stride, 1, &h_s7[0], &h_s7[1], &h_s7[2], + &h_s7[3], &h_s7[4], &h_s7[5], &h_s7[6], &h_s7[7]); + load_s16_8x8(s + 1 * src_stride, 1, &h_s8[0], &h_s8[1], &h_s8[2], + &h_s8[3], &h_s8[4], &h_s8[5], &h_s8[6], &h_s8[7]); + load_s16_8x8(s + 2 * src_stride, 1, &h_s9[0], &h_s9[1], &h_s9[2], + &h_s9[3], &h_s9[4], &h_s9[5], &h_s9[6], &h_s9[7]); + load_s16_8x8(s + 3 * src_stride, 1, &h_s10[0], &h_s10[1], &h_s10[2], + &h_s10[3], &h_s10[4], &h_s10[5], &h_s10[6], &h_s10[7]); + + int16x8_t v_s7 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s7[0], h_s7[1], h_s7[2], h_s7[3], h_s7[4], + h_s7[5], h_s7[6], h_s7[7], x_filter, max)); + int16x8_t v_s8 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s8[0], h_s8[1], h_s8[2], h_s8[3], h_s8[4], + h_s8[5], h_s8[6], h_s8[7], x_filter, max)); + int16x8_t v_s9 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s9[0], h_s9[1], h_s9[2], h_s9[3], h_s9[4], + h_s9[5], h_s9[6], h_s9[7], x_filter, max)); + int16x8_t v_s10 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s10[0], h_s10[1], h_s10[2], h_s10[3], h_s10[4], + h_s10[5], h_s10[6], h_s10[7], x_filter, max)); + + uint16x8_t d0 = highbd_convolve8_8(v_s0, v_s1, v_s2, v_s3, v_s4, v_s5, + v_s6, v_s7, y_filter, max); + uint16x8_t d1 = highbd_convolve8_8(v_s1, v_s2, v_s3, v_s4, v_s5, v_s6, + v_s7, v_s8, y_filter, max); + uint16x8_t d2 = highbd_convolve8_8(v_s2, v_s3, v_s4, v_s5, v_s6, v_s7, + v_s8, v_s9, y_filter, max); + uint16x8_t d3 = highbd_convolve8_8(v_s3, v_s4, v_s5, v_s6, v_s7, v_s8, + v_s9, v_s10, y_filter, max); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + v_s0 = v_s4; + v_s1 = v_s5; + v_s2 = v_s6; + v_s3 = v_s7; + v_s4 = v_s8; + v_s5 = v_s9; + v_s6 = v_s10; + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); +} + +void vpx_highbd_convolve8_neon(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h, int bd) { + if (x_step_q4 != 16 || y_step_q4 != 16) { + vpx_highbd_convolve8_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + const int x_filter_taps = vpx_get_filter_taps(filter[x0_q4]) <= 4 ? 4 : 8; + const int y_filter_taps = vpx_get_filter_taps(filter[y0_q4]) <= 4 ? 4 : 8; + // Account for needing filter_taps / 2 - 1 lines prior and filter_taps / 2 + // lines post both horizontally and vertically. + const ptrdiff_t horiz_offset = x_filter_taps / 2 - 1; + const ptrdiff_t vert_offset = (y_filter_taps / 2 - 1) * src_stride; + + if (x_filter_taps == 4 && y_filter_taps == 4) { + const int16x4_t x_filter = vld1_s16(filter[x0_q4] + 2); + const int16x4_t y_filter = vld1_s16(filter[y0_q4] + 2); + + highbd_convolve_2d_4tap_neon(src - horiz_offset - vert_offset, src_stride, + dst, dst_stride, w, h, x_filter, y_filter, bd); + return; + } + + const int16x8_t x_filter = vld1q_s16(filter[x0_q4]); + const int16x8_t y_filter = vld1q_s16(filter[y0_q4]); + + highbd_convolve_2d_8tap_neon(src - horiz_offset - vert_offset, src_stride, + dst, dst_stride, w, h, x_filter, y_filter, bd); +} + +void vpx_highbd_convolve8_avg_neon(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + if (x_step_q4 != 16 || y_step_q4 != 16) { + vpx_highbd_convolve8_avg_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + // Averaging convolution always uses an 8-tap filter. + const ptrdiff_t horiz_offset = SUBPEL_TAPS / 2 - 1; + const ptrdiff_t vert_offset = (SUBPEL_TAPS / 2 - 1) * src_stride; + // Account for needing SUBPEL_TAPS / 2 - 1 lines prior and SUBPEL_TAPS / 2 + // lines post both horizontally and vertically. + src = src - horiz_offset - vert_offset; + + const int16x8_t x_filter = vld1q_s16(filter[x0_q4]); + const int16x8_t y_filter = vld1q_s16(filter[y0_q4]); + + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + int16x4_t h_s0[8], h_s1[8], h_s2[8], h_s3[8], h_s4[8], h_s5[8], h_s6[8]; + load_s16_4x8(s + 0 * src_stride, 1, &h_s0[0], &h_s0[1], &h_s0[2], &h_s0[3], + &h_s0[4], &h_s0[5], &h_s0[6], &h_s0[7]); + load_s16_4x8(s + 1 * src_stride, 1, &h_s1[0], &h_s1[1], &h_s1[2], &h_s1[3], + &h_s1[4], &h_s1[5], &h_s1[6], &h_s1[7]); + load_s16_4x8(s + 2 * src_stride, 1, &h_s2[0], &h_s2[1], &h_s2[2], &h_s2[3], + &h_s2[4], &h_s2[5], &h_s2[6], &h_s2[7]); + load_s16_4x8(s + 3 * src_stride, 1, &h_s3[0], &h_s3[1], &h_s3[2], &h_s3[3], + &h_s3[4], &h_s3[5], &h_s3[6], &h_s3[7]); + load_s16_4x8(s + 4 * src_stride, 1, &h_s4[0], &h_s4[1], &h_s4[2], &h_s4[3], + &h_s4[4], &h_s4[5], &h_s4[6], &h_s4[7]); + load_s16_4x8(s + 5 * src_stride, 1, &h_s5[0], &h_s5[1], &h_s5[2], &h_s5[3], + &h_s5[4], &h_s5[5], &h_s5[6], &h_s5[7]); + load_s16_4x8(s + 6 * src_stride, 1, &h_s6[0], &h_s6[1], &h_s6[2], &h_s6[3], + &h_s6[4], &h_s6[5], &h_s6[6], &h_s6[7]); + + int16x4_t v_s0 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s0[0], h_s0[1], h_s0[2], h_s0[3], h_s0[4], h_s0[5], + h_s0[6], h_s0[7], x_filter, max)); + int16x4_t v_s1 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s1[0], h_s1[1], h_s1[2], h_s1[3], h_s1[4], h_s1[5], + h_s1[6], h_s1[7], x_filter, max)); + int16x4_t v_s2 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s2[0], h_s2[1], h_s2[2], h_s2[3], h_s2[4], h_s2[5], + h_s2[6], h_s2[7], x_filter, max)); + int16x4_t v_s3 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s3[0], h_s3[1], h_s3[2], h_s3[3], h_s3[4], h_s3[5], + h_s3[6], h_s3[7], x_filter, max)); + int16x4_t v_s4 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s4[0], h_s4[1], h_s4[2], h_s4[3], h_s4[4], h_s4[5], + h_s4[6], h_s4[7], x_filter, max)); + int16x4_t v_s5 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s5[0], h_s5[1], h_s5[2], h_s5[3], h_s5[4], h_s5[5], + h_s5[6], h_s5[7], x_filter, max)); + int16x4_t v_s6 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s6[0], h_s6[1], h_s6[2], h_s6[3], h_s6[4], h_s6[5], + h_s6[6], h_s6[7], x_filter, max)); + + s += 7 * src_stride; + + do { + int16x4_t h_s7[8], h_s8[8], h_s9[8], h_s10[8]; + load_s16_4x8(s + 0 * src_stride, 1, &h_s7[0], &h_s7[1], &h_s7[2], + &h_s7[3], &h_s7[4], &h_s7[5], &h_s7[6], &h_s7[7]); + load_s16_4x8(s + 1 * src_stride, 1, &h_s8[0], &h_s8[1], &h_s8[2], + &h_s8[3], &h_s8[4], &h_s8[5], &h_s8[6], &h_s8[7]); + load_s16_4x8(s + 2 * src_stride, 1, &h_s9[0], &h_s9[1], &h_s9[2], + &h_s9[3], &h_s9[4], &h_s9[5], &h_s9[6], &h_s9[7]); + load_s16_4x8(s + 3 * src_stride, 1, &h_s10[0], &h_s10[1], &h_s10[2], + &h_s10[3], &h_s10[4], &h_s10[5], &h_s10[6], &h_s10[7]); + + int16x4_t v_s7 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s7[0], h_s7[1], h_s7[2], h_s7[3], h_s7[4], + h_s7[5], h_s7[6], h_s7[7], x_filter, max)); + int16x4_t v_s8 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s8[0], h_s8[1], h_s8[2], h_s8[3], h_s8[4], + h_s8[5], h_s8[6], h_s8[7], x_filter, max)); + int16x4_t v_s9 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s9[0], h_s9[1], h_s9[2], h_s9[3], h_s9[4], + h_s9[5], h_s9[6], h_s9[7], x_filter, max)); + int16x4_t v_s10 = vreinterpret_s16_u16( + highbd_convolve8_4(h_s10[0], h_s10[1], h_s10[2], h_s10[3], h_s10[4], + h_s10[5], h_s10[6], h_s10[7], x_filter, max)); + + uint16x4_t d0 = highbd_convolve8_4(v_s0, v_s1, v_s2, v_s3, v_s4, v_s5, + v_s6, v_s7, y_filter, max); + uint16x4_t d1 = highbd_convolve8_4(v_s1, v_s2, v_s3, v_s4, v_s5, v_s6, + v_s7, v_s8, y_filter, max); + uint16x4_t d2 = highbd_convolve8_4(v_s2, v_s3, v_s4, v_s5, v_s6, v_s7, + v_s8, v_s9, y_filter, max); + uint16x4_t d3 = highbd_convolve8_4(v_s3, v_s4, v_s5, v_s6, v_s7, v_s8, + v_s9, v_s10, y_filter, max); + + d0 = vrhadd_u16(d0, vld1_u16(d + 0 * dst_stride)); + d1 = vrhadd_u16(d1, vld1_u16(d + 1 * dst_stride)); + d2 = vrhadd_u16(d2, vld1_u16(d + 2 * dst_stride)); + d3 = vrhadd_u16(d3, vld1_u16(d + 3 * dst_stride)); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + v_s0 = v_s4; + v_s1 = v_s5; + v_s2 = v_s6; + v_s3 = v_s7; + v_s4 = v_s8; + v_s5 = v_s9; + v_s6 = v_s10; + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + + return; + } + + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int height = h; + + int16x8_t h_s0[8], h_s1[8], h_s2[8], h_s3[8], h_s4[8], h_s5[8], h_s6[8]; + load_s16_8x8(s + 0 * src_stride, 1, &h_s0[0], &h_s0[1], &h_s0[2], &h_s0[3], + &h_s0[4], &h_s0[5], &h_s0[6], &h_s0[7]); + load_s16_8x8(s + 1 * src_stride, 1, &h_s1[0], &h_s1[1], &h_s1[2], &h_s1[3], + &h_s1[4], &h_s1[5], &h_s1[6], &h_s1[7]); + load_s16_8x8(s + 2 * src_stride, 1, &h_s2[0], &h_s2[1], &h_s2[2], &h_s2[3], + &h_s2[4], &h_s2[5], &h_s2[6], &h_s2[7]); + load_s16_8x8(s + 3 * src_stride, 1, &h_s3[0], &h_s3[1], &h_s3[2], &h_s3[3], + &h_s3[4], &h_s3[5], &h_s3[6], &h_s3[7]); + load_s16_8x8(s + 4 * src_stride, 1, &h_s4[0], &h_s4[1], &h_s4[2], &h_s4[3], + &h_s4[4], &h_s4[5], &h_s4[6], &h_s4[7]); + load_s16_8x8(s + 5 * src_stride, 1, &h_s5[0], &h_s5[1], &h_s5[2], &h_s5[3], + &h_s5[4], &h_s5[5], &h_s5[6], &h_s5[7]); + load_s16_8x8(s + 6 * src_stride, 1, &h_s6[0], &h_s6[1], &h_s6[2], &h_s6[3], + &h_s6[4], &h_s6[5], &h_s6[6], &h_s6[7]); + + int16x8_t v_s0 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s0[0], h_s0[1], h_s0[2], h_s0[3], h_s0[4], h_s0[5], + h_s0[6], h_s0[7], x_filter, max)); + int16x8_t v_s1 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s1[0], h_s1[1], h_s1[2], h_s1[3], h_s1[4], h_s1[5], + h_s1[6], h_s1[7], x_filter, max)); + int16x8_t v_s2 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s2[0], h_s2[1], h_s2[2], h_s2[3], h_s2[4], h_s2[5], + h_s2[6], h_s2[7], x_filter, max)); + int16x8_t v_s3 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s3[0], h_s3[1], h_s3[2], h_s3[3], h_s3[4], h_s3[5], + h_s3[6], h_s3[7], x_filter, max)); + int16x8_t v_s4 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s4[0], h_s4[1], h_s4[2], h_s4[3], h_s4[4], h_s4[5], + h_s4[6], h_s4[7], x_filter, max)); + int16x8_t v_s5 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s5[0], h_s5[1], h_s5[2], h_s5[3], h_s5[4], h_s5[5], + h_s5[6], h_s5[7], x_filter, max)); + int16x8_t v_s6 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s6[0], h_s6[1], h_s6[2], h_s6[3], h_s6[4], h_s6[5], + h_s6[6], h_s6[7], x_filter, max)); + + s += 7 * src_stride; + + do { + int16x8_t h_s7[8], h_s8[8], h_s9[8], h_s10[8]; + load_s16_8x8(s + 0 * src_stride, 1, &h_s7[0], &h_s7[1], &h_s7[2], + &h_s7[3], &h_s7[4], &h_s7[5], &h_s7[6], &h_s7[7]); + load_s16_8x8(s + 1 * src_stride, 1, &h_s8[0], &h_s8[1], &h_s8[2], + &h_s8[3], &h_s8[4], &h_s8[5], &h_s8[6], &h_s8[7]); + load_s16_8x8(s + 2 * src_stride, 1, &h_s9[0], &h_s9[1], &h_s9[2], + &h_s9[3], &h_s9[4], &h_s9[5], &h_s9[6], &h_s9[7]); + load_s16_8x8(s + 3 * src_stride, 1, &h_s10[0], &h_s10[1], &h_s10[2], + &h_s10[3], &h_s10[4], &h_s10[5], &h_s10[6], &h_s10[7]); + + int16x8_t v_s7 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s7[0], h_s7[1], h_s7[2], h_s7[3], h_s7[4], + h_s7[5], h_s7[6], h_s7[7], x_filter, max)); + int16x8_t v_s8 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s8[0], h_s8[1], h_s8[2], h_s8[3], h_s8[4], + h_s8[5], h_s8[6], h_s8[7], x_filter, max)); + int16x8_t v_s9 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s9[0], h_s9[1], h_s9[2], h_s9[3], h_s9[4], + h_s9[5], h_s9[6], h_s9[7], x_filter, max)); + int16x8_t v_s10 = vreinterpretq_s16_u16( + highbd_convolve8_8(h_s10[0], h_s10[1], h_s10[2], h_s10[3], h_s10[4], + h_s10[5], h_s10[6], h_s10[7], x_filter, max)); + + uint16x8_t d0 = highbd_convolve8_8(v_s0, v_s1, v_s2, v_s3, v_s4, v_s5, + v_s6, v_s7, y_filter, max); + uint16x8_t d1 = highbd_convolve8_8(v_s1, v_s2, v_s3, v_s4, v_s5, v_s6, + v_s7, v_s8, y_filter, max); + uint16x8_t d2 = highbd_convolve8_8(v_s2, v_s3, v_s4, v_s5, v_s6, v_s7, + v_s8, v_s9, y_filter, max); + uint16x8_t d3 = highbd_convolve8_8(v_s3, v_s4, v_s5, v_s6, v_s7, v_s8, + v_s9, v_s10, y_filter, max); + + d0 = vrhaddq_u16(d0, vld1q_u16(d + 0 * dst_stride)); + d1 = vrhaddq_u16(d1, vld1q_u16(d + 1 * dst_stride)); + d2 = vrhaddq_u16(d2, vld1q_u16(d + 2 * dst_stride)); + d3 = vrhaddq_u16(d3, vld1q_u16(d + 3 * dst_stride)); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + v_s0 = v_s4; + v_s1 = v_s5; + v_s2 = v_s6; + v_s3 = v_s7; + v_s4 = v_s8; + v_s5 = v_s9; + v_s6 = v_s10; + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); +} diff --git a/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_sve.c b/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_sve.c new file mode 100644 index 0000000000..f909e06a18 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_sve.c @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" + +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/highbd_convolve8_sve.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/transpose_neon.h" +#include "vpx_dsp/arm/vpx_neon_sve_bridge.h" + +DECLARE_ALIGNED(16, static const uint16_t, kTblConv4_8[8]) = { 0, 2, 4, 6, + 1, 3, 5, 7 }; + +static INLINE void highbd_convolve_4tap_horiz_sve( + const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, int w, int h, const int16x4_t filters, int bd) { + const int16x8_t filter = vcombine_s16(filters, vdup_n_s16(0)); + + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + do { + int16x4_t s0[4], s1[4], s2[4], s3[4]; + load_s16_4x4(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3]); + load_s16_4x4(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3]); + load_s16_4x4(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3]); + load_s16_4x4(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3]); + + uint16x4_t d0 = highbd_convolve4_4_sve(s0, filter, max); + uint16x4_t d1 = highbd_convolve4_4_sve(s1, filter, max); + uint16x4_t d2 = highbd_convolve4_4_sve(s2, filter, max); + uint16x4_t d3 = highbd_convolve4_4_sve(s3, filter, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + const uint16x8_t idx = vld1q_u16(kTblConv4_8); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int width = w; + + do { + int16x8_t s0[4], s1[4], s2[4], s3[4]; + load_s16_8x4(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3]); + load_s16_8x4(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3]); + load_s16_8x4(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3]); + load_s16_8x4(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3]); + + uint16x8_t d0 = highbd_convolve4_8_sve(s0, filter, max, idx); + uint16x8_t d1 = highbd_convolve4_8_sve(s1, filter, max, idx); + uint16x8_t d2 = highbd_convolve4_8_sve(s2, filter, max, idx); + uint16x8_t d3 = highbd_convolve4_8_sve(s3, filter, max, idx); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } +} + +static INLINE void highbd_convolve_8tap_horiz_sve( + const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, int w, int h, const int16x8_t filters, int bd) { + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + do { + int16x8_t s0[4], s1[4], s2[4], s3[4]; + load_s16_8x4(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3]); + load_s16_8x4(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3]); + load_s16_8x4(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3]); + load_s16_8x4(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3]); + + uint16x4_t d0 = highbd_convolve8_4(s0, filters, max); + uint16x4_t d1 = highbd_convolve8_4(s1, filters, max); + uint16x4_t d2 = highbd_convolve8_4(s2, filters, max); + uint16x4_t d3 = highbd_convolve8_4(s3, filters, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int width = w; + + do { + int16x8_t s0[8], s1[8], s2[8], s3[8]; + load_s16_8x8(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3], + &s0[4], &s0[5], &s0[6], &s0[7]); + load_s16_8x8(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3], + &s1[4], &s1[5], &s1[6], &s1[7]); + load_s16_8x8(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3], + &s2[4], &s2[5], &s2[6], &s2[7]); + load_s16_8x8(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3], + &s3[4], &s3[5], &s3[6], &s3[7]); + + uint16x8_t d0 = highbd_convolve8_8(s0, filters, max); + uint16x8_t d1 = highbd_convolve8_8(s1, filters, max); + uint16x8_t d2 = highbd_convolve8_8(s2, filters, max); + uint16x8_t d3 = highbd_convolve8_8(s3, filters, max); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } +} + +void vpx_highbd_convolve8_horiz_sve(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + if (x_step_q4 != 16) { + vpx_highbd_convolve8_horiz_c(src, src_stride, dst, dst_stride, filter, + x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(x_step_q4 == 16); + + (void)x_step_q4; + (void)y0_q4; + (void)y_step_q4; + + if (vpx_get_filter_taps(filter[x0_q4]) <= 4) { + const int16x4_t x_filter_4tap = vld1_s16(filter[x0_q4] + 2); + highbd_convolve_4tap_horiz_sve(src - 1, src_stride, dst, dst_stride, w, h, + x_filter_4tap, bd); + } else { + const int16x8_t x_filter_8tap = vld1q_s16(filter[x0_q4]); + highbd_convolve_8tap_horiz_sve(src - 3, src_stride, dst, dst_stride, w, h, + x_filter_8tap, bd); + } +} + +void vpx_highbd_convolve8_avg_horiz_sve(const uint16_t *src, + ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + if (x_step_q4 != 16) { + vpx_highbd_convolve8_avg_horiz_c(src, src_stride, dst, dst_stride, filter, + x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, + bd); + return; + } + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + + const int16x8_t filters = vld1q_s16(filter[x0_q4]); + + src -= 3; + + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + do { + int16x8_t s0[4], s1[4], s2[4], s3[4]; + load_s16_8x4(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3]); + load_s16_8x4(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3]); + load_s16_8x4(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3]); + load_s16_8x4(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3]); + + uint16x4_t d0 = highbd_convolve8_4(s0, filters, max); + uint16x4_t d1 = highbd_convolve8_4(s1, filters, max); + uint16x4_t d2 = highbd_convolve8_4(s2, filters, max); + uint16x4_t d3 = highbd_convolve8_4(s3, filters, max); + + d0 = vrhadd_u16(d0, vld1_u16(d + 0 * dst_stride)); + d1 = vrhadd_u16(d1, vld1_u16(d + 1 * dst_stride)); + d2 = vrhadd_u16(d2, vld1_u16(d + 2 * dst_stride)); + d3 = vrhadd_u16(d3, vld1_u16(d + 3 * dst_stride)); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int width = w; + + do { + int16x8_t s0[8], s1[8], s2[8], s3[8]; + load_s16_8x8(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3], + &s0[4], &s0[5], &s0[6], &s0[7]); + load_s16_8x8(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3], + &s1[4], &s1[5], &s1[6], &s1[7]); + load_s16_8x8(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3], + &s2[4], &s2[5], &s2[6], &s2[7]); + load_s16_8x8(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3], + &s3[4], &s3[5], &s3[6], &s3[7]); + + uint16x8_t d0 = highbd_convolve8_8(s0, filters, max); + uint16x8_t d1 = highbd_convolve8_8(s1, filters, max); + uint16x8_t d2 = highbd_convolve8_8(s2, filters, max); + uint16x8_t d3 = highbd_convolve8_8(s3, filters, max); + + d0 = vrhaddq_u16(d0, vld1q_u16(d + 0 * dst_stride)); + d1 = vrhaddq_u16(d1, vld1q_u16(d + 1 * dst_stride)); + d2 = vrhaddq_u16(d2, vld1q_u16(d + 2 * dst_stride)); + d3 = vrhaddq_u16(d3, vld1q_u16(d + 3 * dst_stride)); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } +} diff --git a/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_sve2.c b/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_sve2.c new file mode 100644 index 0000000000..8408f98f4a --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve8_sve2.c @@ -0,0 +1,660 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" + +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/highbd_convolve8_neon.h" +#include "vpx_dsp/arm/highbd_convolve8_sve.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/transpose_neon.h" +#include "vpx_dsp/arm/vpx_neon_sve_bridge.h" +#include "vpx_dsp/arm/vpx_neon_sve2_bridge.h" + +// clang-format off +DECLARE_ALIGNED(16, static const uint16_t, kDotProdMergeBlockTbl[24]) = { + // Shift left and insert new last column in transposed 4x4 block. + 1, 2, 3, 0, 5, 6, 7, 4, + // Shift left and insert two new columns in transposed 4x4 block. + 2, 3, 0, 1, 6, 7, 4, 5, + // Shift left and insert three new columns in transposed 4x4 block. + 3, 0, 1, 2, 7, 4, 5, 6, +}; +// clang-format on + +DECLARE_ALIGNED(16, static const uint16_t, kTblConv4_8[8]) = { 0, 2, 4, 6, + 1, 3, 5, 7 }; + +static INLINE uint16x4_t highbd_convolve8_4_v(int16x8_t s_lo[2], + int16x8_t s_hi[2], + int16x8_t filter, + uint16x4_t max) { + int64x2_t sum01 = vpx_dotq_lane_s16(vdupq_n_s64(0), s_lo[0], filter, 0); + sum01 = vpx_dotq_lane_s16(sum01, s_hi[0], filter, 1); + + int64x2_t sum23 = vpx_dotq_lane_s16(vdupq_n_s64(0), s_lo[1], filter, 0); + sum23 = vpx_dotq_lane_s16(sum23, s_hi[1], filter, 1); + + int32x4_t sum0123 = vcombine_s32(vmovn_s64(sum01), vmovn_s64(sum23)); + + uint16x4_t res = vqrshrun_n_s32(sum0123, FILTER_BITS); + return vmin_u16(res, max); +} + +static INLINE uint16x8_t highbd_convolve8_8_v(const int16x8_t s_lo[4], + const int16x8_t s_hi[4], + const int16x8_t filter, + const uint16x8_t max) { + int64x2_t sum01 = vpx_dotq_lane_s16(vdupq_n_s64(0), s_lo[0], filter, 0); + sum01 = vpx_dotq_lane_s16(sum01, s_hi[0], filter, 1); + + int64x2_t sum23 = vpx_dotq_lane_s16(vdupq_n_s64(0), s_lo[1], filter, 0); + sum23 = vpx_dotq_lane_s16(sum23, s_hi[1], filter, 1); + + int64x2_t sum45 = vpx_dotq_lane_s16(vdupq_n_s64(0), s_lo[2], filter, 0); + sum45 = vpx_dotq_lane_s16(sum45, s_hi[2], filter, 1); + + int64x2_t sum67 = vpx_dotq_lane_s16(vdupq_n_s64(0), s_lo[3], filter, 0); + sum67 = vpx_dotq_lane_s16(sum67, s_hi[3], filter, 1); + + int32x4_t sum0123 = vcombine_s32(vmovn_s64(sum01), vmovn_s64(sum23)); + int32x4_t sum4567 = vcombine_s32(vmovn_s64(sum45), vmovn_s64(sum67)); + + uint16x8_t res = vcombine_u16(vqrshrun_n_s32(sum0123, FILTER_BITS), + vqrshrun_n_s32(sum4567, FILTER_BITS)); + return vminq_u16(res, max); +} + +static INLINE void highbd_convolve8_8tap_vert_sve2( + const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, int w, int h, const int16x8_t filter, int bd) { + assert(w >= 4 && h >= 4); + + do { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int height = h; + + int16x4_t s0, s1, s2, s3, s4, s5, s6; + load_s16_4x7(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6); + s += 7 * src_stride; + + int16x8_t s0123[2], s1234[2], s2345[2], s3456[2]; + transpose_concat_s16_4x4(s0, s1, s2, s3, &s0123[0], &s0123[1]); + transpose_concat_s16_4x4(s1, s2, s3, s4, &s1234[0], &s1234[1]); + transpose_concat_s16_4x4(s2, s3, s4, s5, &s2345[0], &s2345[1]); + transpose_concat_s16_4x4(s3, s4, s5, s6, &s3456[0], &s3456[1]); + + do { + int16x4_t s7, s8, s9, sA; + + load_s16_4x4(s, src_stride, &s7, &s8, &s9, &sA); + + int16x8_t s4567[2], s5678[2], s6789[2], s789A[2]; + transpose_concat_s16_4x4(s4, s5, s6, s7, &s4567[0], &s4567[1]); + transpose_concat_s16_4x4(s5, s6, s7, s8, &s5678[0], &s5678[1]); + transpose_concat_s16_4x4(s6, s7, s8, s9, &s6789[0], &s6789[1]); + transpose_concat_s16_4x4(s7, s8, s9, sA, &s789A[0], &s789A[1]); + + uint16x4_t d0 = highbd_convolve8_4_v(s0123, s4567, filter, max); + uint16x4_t d1 = highbd_convolve8_4_v(s1234, s5678, filter, max); + uint16x4_t d2 = highbd_convolve8_4_v(s2345, s6789, filter, max); + uint16x4_t d3 = highbd_convolve8_4_v(s3456, s789A, filter, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s0123[0] = s4567[0]; + s0123[1] = s4567[1]; + s1234[0] = s5678[0]; + s1234[1] = s5678[1]; + s2345[0] = s6789[0]; + s2345[1] = s6789[1]; + s3456[0] = s789A[0]; + s3456[1] = s789A[1]; + + s4 = s8; + s5 = s9; + s6 = sA; + + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + + src += 4; + dst += 4; + w -= 4; + } while (w != 0); +} + +void vpx_highbd_convolve8_vert_sve2(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + if (y_step_q4 != 16) { + vpx_highbd_convolve8_vert_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(y_step_q4 == 16); + + (void)x_step_q4; + (void)y0_q4; + (void)y_step_q4; + + if (vpx_get_filter_taps(filter[y0_q4]) <= 4) { + vpx_highbd_convolve8_vert_neon(src, src_stride, dst, dst_stride, filter, + x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, + bd); + } else { + const int16x8_t y_filter_8tap = vld1q_s16(filter[y0_q4]); + highbd_convolve8_8tap_vert_sve2(src - 3 * src_stride, src_stride, dst, + dst_stride, w, h, y_filter_8tap, bd); + } +} + +void vpx_highbd_convolve8_avg_vert_sve2(const uint16_t *src, + ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + if (y_step_q4 != 16) { + vpx_highbd_convolve8_avg_vert_c(src, src_stride, dst, dst_stride, filter, + x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, + bd); + return; + } + + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + + const int16x8_t filters = vld1q_s16(filter[y0_q4]); + + src -= 3 * src_stride; + + uint16x8x3_t merge_tbl_idx = vld1q_u16_x3(kDotProdMergeBlockTbl); + + // Correct indices by the size of vector length. + merge_tbl_idx.val[0] = vaddq_u16( + merge_tbl_idx.val[0], + vreinterpretq_u16_u64(vdupq_n_u64(svcnth() * 0x0001000000000000ULL))); + merge_tbl_idx.val[1] = vaddq_u16( + merge_tbl_idx.val[1], + vreinterpretq_u16_u64(vdupq_n_u64(svcnth() * 0x0001000100000000ULL))); + merge_tbl_idx.val[2] = vaddq_u16( + merge_tbl_idx.val[2], + vreinterpretq_u16_u64(vdupq_n_u64(svcnth() * 0x0001000100010000ULL))); + + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + int16x4_t s0, s1, s2, s3, s4, s5, s6; + load_s16_4x7(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6); + s += 7 * src_stride; + + int16x8_t s0123[2], s1234[2], s2345[2], s3456[2]; + transpose_concat_s16_4x4(s0, s1, s2, s3, &s0123[0], &s0123[1]); + transpose_concat_s16_4x4(s1, s2, s3, s4, &s1234[0], &s1234[1]); + transpose_concat_s16_4x4(s2, s3, s4, s5, &s2345[0], &s2345[1]); + transpose_concat_s16_4x4(s3, s4, s5, s6, &s3456[0], &s3456[1]); + + do { + int16x4_t s7, s8, s9, sA; + + load_s16_4x4(s, src_stride, &s7, &s8, &s9, &sA); + + int16x8_t s4567[2], s5678[2], s6789[2], s789A[2]; + transpose_concat_s16_4x4(s7, s8, s9, sA, &s789A[0], &s789A[1]); + + vpx_tbl2x2_s16(s3456, s789A, s4567, merge_tbl_idx.val[0]); + vpx_tbl2x2_s16(s3456, s789A, s5678, merge_tbl_idx.val[1]); + vpx_tbl2x2_s16(s3456, s789A, s6789, merge_tbl_idx.val[2]); + + uint16x4_t d0 = highbd_convolve8_4_v(s0123, s4567, filters, max); + uint16x4_t d1 = highbd_convolve8_4_v(s1234, s5678, filters, max); + uint16x4_t d2 = highbd_convolve8_4_v(s2345, s6789, filters, max); + uint16x4_t d3 = highbd_convolve8_4_v(s3456, s789A, filters, max); + + d0 = vrhadd_u16(d0, vld1_u16(d + 0 * dst_stride)); + d1 = vrhadd_u16(d1, vld1_u16(d + 1 * dst_stride)); + d2 = vrhadd_u16(d2, vld1_u16(d + 2 * dst_stride)); + d3 = vrhadd_u16(d3, vld1_u16(d + 3 * dst_stride)); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s0123[0] = s4567[0]; + s0123[1] = s4567[1]; + s1234[0] = s5678[0]; + s1234[1] = s5678[1]; + s2345[0] = s6789[0]; + s2345[1] = s6789[1]; + s3456[0] = s789A[0]; + s3456[1] = s789A[1]; + + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int height = h; + + int16x8_t s0, s1, s2, s3, s4, s5, s6; + load_s16_8x7(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6); + s += 7 * src_stride; + + int16x8_t s0123[4], s1234[4], s2345[4], s3456[4]; + transpose_concat_s16_8x4(s0, s1, s2, s3, &s0123[0], &s0123[1], &s0123[2], + &s0123[3]); + transpose_concat_s16_8x4(s1, s2, s3, s4, &s1234[0], &s1234[1], &s1234[2], + &s1234[3]); + transpose_concat_s16_8x4(s2, s3, s4, s5, &s2345[0], &s2345[1], &s2345[2], + &s2345[3]); + transpose_concat_s16_8x4(s3, s4, s5, s6, &s3456[0], &s3456[1], &s3456[2], + &s3456[3]); + + do { + int16x8_t s7, s8, s9, sA; + load_s16_8x4(s, src_stride, &s7, &s8, &s9, &sA); + + int16x8_t s4567[4], s5678[5], s6789[4], s789A[4]; + transpose_concat_s16_8x4(s7, s8, s9, sA, &s789A[0], &s789A[1], + &s789A[2], &s789A[3]); + + vpx_tbl2x4_s16(s3456, s789A, s4567, merge_tbl_idx.val[0]); + vpx_tbl2x4_s16(s3456, s789A, s5678, merge_tbl_idx.val[1]); + vpx_tbl2x4_s16(s3456, s789A, s6789, merge_tbl_idx.val[2]); + + uint16x8_t d0 = highbd_convolve8_8_v(s0123, s4567, filters, max); + uint16x8_t d1 = highbd_convolve8_8_v(s1234, s5678, filters, max); + uint16x8_t d2 = highbd_convolve8_8_v(s2345, s6789, filters, max); + uint16x8_t d3 = highbd_convolve8_8_v(s3456, s789A, filters, max); + + d0 = vrhaddq_u16(d0, vld1q_u16(d + 0 * dst_stride)); + d1 = vrhaddq_u16(d1, vld1q_u16(d + 1 * dst_stride)); + d2 = vrhaddq_u16(d2, vld1q_u16(d + 2 * dst_stride)); + d3 = vrhaddq_u16(d3, vld1q_u16(d + 3 * dst_stride)); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + s0123[0] = s4567[0]; + s0123[1] = s4567[1]; + s0123[2] = s4567[2]; + s0123[3] = s4567[3]; + s1234[0] = s5678[0]; + s1234[1] = s5678[1]; + s1234[2] = s5678[2]; + s1234[3] = s5678[3]; + s2345[0] = s6789[0]; + s2345[1] = s6789[1]; + s2345[2] = s6789[2]; + s2345[3] = s6789[3]; + s3456[0] = s789A[0]; + s3456[1] = s789A[1]; + s3456[2] = s789A[2]; + s3456[3] = s789A[3]; + + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); + } +} + +static INLINE void highbd_convolve_2d_4tap_sve2( + const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, int w, int h, const int16x4_t x_filters, + const int16x4_t y_filters, int bd) { + const int16x8_t x_filter = vcombine_s16(x_filters, vdup_n_s16(0)); + + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + int16x4_t h_s0[4], h_s1[4], h_s2[4]; + load_s16_4x4(s + 0 * src_stride, 1, &h_s0[0], &h_s0[1], &h_s0[2], &h_s0[3]); + load_s16_4x4(s + 1 * src_stride, 1, &h_s1[0], &h_s1[1], &h_s1[2], &h_s1[3]); + load_s16_4x4(s + 2 * src_stride, 1, &h_s2[0], &h_s2[1], &h_s2[2], &h_s2[3]); + + int16x4_t v_s0 = + vreinterpret_s16_u16(highbd_convolve4_4_sve(h_s0, x_filter, max)); + int16x4_t v_s1 = + vreinterpret_s16_u16(highbd_convolve4_4_sve(h_s1, x_filter, max)); + int16x4_t v_s2 = + vreinterpret_s16_u16(highbd_convolve4_4_sve(h_s2, x_filter, max)); + + s += 3 * src_stride; + + do { + int16x4_t h_s3[4], h_s4[4], h_s5[4], h_s6[4]; + load_s16_4x4(s + 0 * src_stride, 1, &h_s3[0], &h_s3[1], &h_s3[2], + &h_s3[3]); + load_s16_4x4(s + 1 * src_stride, 1, &h_s4[0], &h_s4[1], &h_s4[2], + &h_s4[3]); + load_s16_4x4(s + 2 * src_stride, 1, &h_s5[0], &h_s5[1], &h_s5[2], + &h_s5[3]); + load_s16_4x4(s + 3 * src_stride, 1, &h_s6[0], &h_s6[1], &h_s6[2], + &h_s6[3]); + + int16x4_t v_s3 = + vreinterpret_s16_u16(highbd_convolve4_4_sve(h_s3, x_filter, max)); + int16x4_t v_s4 = + vreinterpret_s16_u16(highbd_convolve4_4_sve(h_s4, x_filter, max)); + int16x4_t v_s5 = + vreinterpret_s16_u16(highbd_convolve4_4_sve(h_s5, x_filter, max)); + int16x4_t v_s6 = + vreinterpret_s16_u16(highbd_convolve4_4_sve(h_s6, x_filter, max)); + + uint16x4_t d0 = + highbd_convolve4_4_neon(v_s0, v_s1, v_s2, v_s3, y_filters, max); + uint16x4_t d1 = + highbd_convolve4_4_neon(v_s1, v_s2, v_s3, v_s4, y_filters, max); + uint16x4_t d2 = + highbd_convolve4_4_neon(v_s2, v_s3, v_s4, v_s5, y_filters, max); + uint16x4_t d3 = + highbd_convolve4_4_neon(v_s3, v_s4, v_s5, v_s6, y_filters, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + v_s0 = v_s4; + v_s1 = v_s5; + v_s2 = v_s6; + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 0); + + } else { + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + const uint16x8_t idx = vld1q_u16(kTblConv4_8); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int height = h; + + int16x8_t h_s0[4], h_s1[4], h_s2[4]; + load_s16_8x4(s + 0 * src_stride, 1, &h_s0[0], &h_s0[1], &h_s0[2], + &h_s0[3]); + load_s16_8x4(s + 1 * src_stride, 1, &h_s1[0], &h_s1[1], &h_s1[2], + &h_s1[3]); + load_s16_8x4(s + 2 * src_stride, 1, &h_s2[0], &h_s2[1], &h_s2[2], + &h_s2[3]); + + int16x8_t v_s0 = vreinterpretq_s16_u16( + highbd_convolve4_8_sve(h_s0, x_filter, max, idx)); + int16x8_t v_s1 = vreinterpretq_s16_u16( + highbd_convolve4_8_sve(h_s1, x_filter, max, idx)); + int16x8_t v_s2 = vreinterpretq_s16_u16( + highbd_convolve4_8_sve(h_s2, x_filter, max, idx)); + + s += 3 * src_stride; + + do { + int16x8_t h_s3[4], h_s4[4], h_s5[4], h_s6[4]; + load_s16_8x4(s + 0 * src_stride, 1, &h_s3[0], &h_s3[1], &h_s3[2], + &h_s3[3]); + load_s16_8x4(s + 1 * src_stride, 1, &h_s4[0], &h_s4[1], &h_s4[2], + &h_s4[3]); + load_s16_8x4(s + 2 * src_stride, 1, &h_s5[0], &h_s5[1], &h_s5[2], + &h_s5[3]); + load_s16_8x4(s + 3 * src_stride, 1, &h_s6[0], &h_s6[1], &h_s6[2], + &h_s6[3]); + + int16x8_t v_s3 = vreinterpretq_s16_u16( + highbd_convolve4_8_sve(h_s3, x_filter, max, idx)); + int16x8_t v_s4 = vreinterpretq_s16_u16( + highbd_convolve4_8_sve(h_s4, x_filter, max, idx)); + int16x8_t v_s5 = vreinterpretq_s16_u16( + highbd_convolve4_8_sve(h_s5, x_filter, max, idx)); + int16x8_t v_s6 = vreinterpretq_s16_u16( + highbd_convolve4_8_sve(h_s6, x_filter, max, idx)); + + uint16x8_t d0 = + highbd_convolve4_8_neon(v_s0, v_s1, v_s2, v_s3, y_filters, max); + uint16x8_t d1 = + highbd_convolve4_8_neon(v_s1, v_s2, v_s3, v_s4, y_filters, max); + uint16x8_t d2 = + highbd_convolve4_8_neon(v_s2, v_s3, v_s4, v_s5, y_filters, max); + uint16x8_t d3 = + highbd_convolve4_8_neon(v_s3, v_s4, v_s5, v_s6, y_filters, max); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + v_s0 = v_s4; + v_s1 = v_s5; + v_s2 = v_s6; + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); + } +} + +static INLINE void highbd_convolve8_2d_horiz_sve2( + const uint16_t *src, ptrdiff_t src_stride, uint16_t *dst, + ptrdiff_t dst_stride, const InterpKernel *filter, int x0_q4, int x_step_q4, + int y0_q4, int y_step_q4, int w, int h, int bd) { + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(x_step_q4 == 16); + assert(h % 4 == 3 && h >= 7); + + (void)x_step_q4; + (void)y0_q4; + (void)y_step_q4; + + const int16x8_t filters = vld1q_s16(filter[x0_q4]); + + src -= 3; + + if (w == 4) { + const uint16x4_t max = vdup_n_u16((1 << bd) - 1); + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + + do { + int16x8_t s0[4], s1[4], s2[4], s3[4]; + load_s16_8x4(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3]); + load_s16_8x4(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3]); + load_s16_8x4(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3]); + load_s16_8x4(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3]); + + uint16x4_t d0 = highbd_convolve8_4(s0, filters, max); + uint16x4_t d1 = highbd_convolve8_4(s1, filters, max); + uint16x4_t d2 = highbd_convolve8_4(s2, filters, max); + uint16x4_t d3 = highbd_convolve8_4(s3, filters, max); + + store_u16_4x4(d, dst_stride, d0, d1, d2, d3); + + s += 4 * src_stride; + d += 4 * dst_stride; + h -= 4; + } while (h != 3); + + // Process final three rows (h % 4 == 3). + int16x8_t s0[4], s1[4], s2[4]; + load_s16_8x4(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3]); + load_s16_8x4(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3]); + load_s16_8x4(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3]); + + uint16x4_t d0 = highbd_convolve8_4(s0, filters, max); + uint16x4_t d1 = highbd_convolve8_4(s1, filters, max); + uint16x4_t d2 = highbd_convolve8_4(s2, filters, max); + + store_u16_4x3(d, dst_stride, d0, d1, d2); + } else { + const uint16x8_t max = vdupq_n_u16((1 << bd) - 1); + + do { + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int width = w; + + do { + int16x8_t s0[8], s1[8], s2[8], s3[8]; + load_s16_8x8(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3], + &s0[4], &s0[5], &s0[6], &s0[7]); + load_s16_8x8(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3], + &s1[4], &s1[5], &s1[6], &s1[7]); + load_s16_8x8(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3], + &s2[4], &s2[5], &s2[6], &s2[7]); + load_s16_8x8(s + 3 * src_stride, 1, &s3[0], &s3[1], &s3[2], &s3[3], + &s3[4], &s3[5], &s3[6], &s3[7]); + + uint16x8_t d0 = highbd_convolve8_8(s0, filters, max); + uint16x8_t d1 = highbd_convolve8_8(s1, filters, max); + uint16x8_t d2 = highbd_convolve8_8(s2, filters, max); + uint16x8_t d3 = highbd_convolve8_8(s3, filters, max); + + store_u16_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 3); + + // Process final three rows (h % 4 == 3). + const int16_t *s = (const int16_t *)src; + uint16_t *d = dst; + int width = w; + + do { + int16x8_t s0[8], s1[8], s2[8]; + load_s16_8x8(s + 0 * src_stride, 1, &s0[0], &s0[1], &s0[2], &s0[3], + &s0[4], &s0[5], &s0[6], &s0[7]); + load_s16_8x8(s + 1 * src_stride, 1, &s1[0], &s1[1], &s1[2], &s1[3], + &s1[4], &s1[5], &s1[6], &s1[7]); + load_s16_8x8(s + 2 * src_stride, 1, &s2[0], &s2[1], &s2[2], &s2[3], + &s2[4], &s2[5], &s2[6], &s2[7]); + + uint16x8_t d0 = highbd_convolve8_8(s0, filters, max); + uint16x8_t d1 = highbd_convolve8_8(s1, filters, max); + uint16x8_t d2 = highbd_convolve8_8(s2, filters, max); + + store_u16_8x3(d, dst_stride, d0, d1, d2); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + } +} + +void vpx_highbd_convolve8_sve2(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h, int bd) { + if (x_step_q4 != 16 || y_step_q4 != 16) { + vpx_highbd_convolve8_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert(y_step_q4 == 16); + assert(x_step_q4 == 16); + + const int horiz_filter_taps = vpx_get_filter_taps(filter[x0_q4]) <= 4 ? 4 : 8; + const int vert_filter_taps = vpx_get_filter_taps(filter[y0_q4]) <= 4 ? 4 : 8; + + if (horiz_filter_taps == 4 || vert_filter_taps == 4) { + const ptrdiff_t horiz_offset = horiz_filter_taps / 2 - 1; + const ptrdiff_t vert_offset = (vert_filter_taps / 2 - 1) * src_stride; + const int16x4_t x_filter = vld1_s16(filter[x0_q4] + 2); + const int16x4_t y_filter = vld1_s16(filter[y0_q4] + 2); + + highbd_convolve_2d_4tap_sve2(src - horiz_offset - vert_offset, src_stride, + dst, dst_stride, w, h, x_filter, y_filter, bd); + return; + } + + // Given our constraints: w <= 64, h <= 64, taps <= 8 we can reduce the + // maximum buffer size to 64 * (64 + 7). + DECLARE_ALIGNED(32, uint16_t, im_block[64 * 71]); + const int im_stride = 64; + + // Account for the vertical phase needing SUBPEL_TAPS / 2 - 1 lines prior + // and SUBPEL_TAPS / 2 lines post. + const int im_height = h + SUBPEL_TAPS - 1; + const ptrdiff_t border_offset = SUBPEL_TAPS / 2 - 1; + + highbd_convolve8_2d_horiz_sve2(src - src_stride * border_offset, src_stride, + im_block, im_stride, filter, x0_q4, x_step_q4, + y0_q4, y_step_q4, w, im_height, bd); + + // Step into the temporary buffer border_offset rows to get actual frame data. + vpx_highbd_convolve8_vert_sve2(im_block + im_stride * border_offset, + im_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); +} + +void vpx_highbd_convolve8_avg_sve2(const uint16_t *src, ptrdiff_t src_stride, + uint16_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h, int bd) { + if (x_step_q4 != 16 || y_step_q4 != 16) { + vpx_highbd_convolve8_avg_c(src, src_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); + return; + } + + assert(y_step_q4 == 16); + assert(x_step_q4 == 16); + + // Given our constraints: w <= 64, h <= 64, taps <= 8 we can reduce the + // maximum buffer size to 64 * (64 + 7). + DECLARE_ALIGNED(32, uint16_t, im_block[64 * 71]); + const int im_stride = 64; + + // Account for the vertical phase needing SUBPEL_TAPS / 2 - 1 lines prior + // and SUBPEL_TAPS / 2 lines post. + const int im_height = h + SUBPEL_TAPS - 1; + const ptrdiff_t border_offset = SUBPEL_TAPS / 2 - 1; + + highbd_convolve8_2d_horiz_sve2(src - src_stride * border_offset, src_stride, + im_block, im_stride, filter, x0_q4, x_step_q4, + y0_q4, y_step_q4, w, im_height, bd); + + // Step into the temporary buffer border_offset rows to get actual frame data. + vpx_highbd_convolve8_avg_vert_sve2(im_block + im_stride * border_offset, + im_stride, dst, dst_stride, filter, x0_q4, + x_step_q4, y0_q4, y_step_q4, w, h, bd); +} diff --git a/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve_copy_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve_copy_neon.c index 9d2752e097..7751082083 100644 --- a/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve_copy_neon.c +++ b/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve_copy_neon.c @@ -26,76 +26,88 @@ void vpx_highbd_convolve_copy_neon(const uint16_t *src, ptrdiff_t src_stride, (void)bd; if (w < 8) { // copy4 + uint16x4_t s0, s1; do { - vst1_u16(dst, vld1_u16(src)); + s0 = vld1_u16(src); src += src_stride; + s1 = vld1_u16(src); + src += src_stride; + + vst1_u16(dst, s0); dst += dst_stride; - vst1_u16(dst, vld1_u16(src)); - src += src_stride; + vst1_u16(dst, s1); dst += dst_stride; h -= 2; - } while (h > 0); + } while (h != 0); } else if (w == 8) { // copy8 + uint16x8_t s0, s1; do { - vst1q_u16(dst, vld1q_u16(src)); + s0 = vld1q_u16(src); src += src_stride; + s1 = vld1q_u16(src); + src += src_stride; + + vst1q_u16(dst, s0); dst += dst_stride; - vst1q_u16(dst, vld1q_u16(src)); - src += src_stride; + vst1q_u16(dst, s1); dst += dst_stride; h -= 2; - } while (h > 0); + } while (h != 0); } else if (w < 32) { // copy16 + uint16x8_t s0, s1, s2, s3; do { - vst2q_u16(dst, vld2q_u16(src)); + s0 = vld1q_u16(src); + s1 = vld1q_u16(src + 8); src += src_stride; - dst += dst_stride; - vst2q_u16(dst, vld2q_u16(src)); + s2 = vld1q_u16(src); + s3 = vld1q_u16(src + 8); src += src_stride; + + vst1q_u16(dst, s0); + vst1q_u16(dst + 8, s1); dst += dst_stride; - vst2q_u16(dst, vld2q_u16(src)); - src += src_stride; + vst1q_u16(dst, s2); + vst1q_u16(dst + 8, s3); dst += dst_stride; - vst2q_u16(dst, vld2q_u16(src)); - src += src_stride; - dst += dst_stride; - h -= 4; - } while (h > 0); + h -= 2; + } while (h != 0); } else if (w == 32) { // copy32 + uint16x8_t s0, s1, s2, s3; do { - vst4q_u16(dst, vld4q_u16(src)); + s0 = vld1q_u16(src); + s1 = vld1q_u16(src + 8); + s2 = vld1q_u16(src + 16); + s3 = vld1q_u16(src + 24); src += src_stride; + + vst1q_u16(dst, s0); + vst1q_u16(dst + 8, s1); + vst1q_u16(dst + 16, s2); + vst1q_u16(dst + 24, s3); dst += dst_stride; - vst4q_u16(dst, vld4q_u16(src)); - src += src_stride; - dst += dst_stride; - vst4q_u16(dst, vld4q_u16(src)); - src += src_stride; - dst += dst_stride; - vst4q_u16(dst, vld4q_u16(src)); - src += src_stride; - dst += dst_stride; - h -= 4; - } while (h > 0); + } while (--h != 0); } else { // copy64 + uint16x8_t s0, s1, s2, s3, s4, s5, s6, s7; do { - vst4q_u16(dst, vld4q_u16(src)); - vst4q_u16(dst + 32, vld4q_u16(src + 32)); + s0 = vld1q_u16(src); + s1 = vld1q_u16(src + 8); + s2 = vld1q_u16(src + 16); + s3 = vld1q_u16(src + 24); + s4 = vld1q_u16(src + 32); + s5 = vld1q_u16(src + 40); + s6 = vld1q_u16(src + 48); + s7 = vld1q_u16(src + 56); src += src_stride; + + vst1q_u16(dst, s0); + vst1q_u16(dst + 8, s1); + vst1q_u16(dst + 16, s2); + vst1q_u16(dst + 24, s3); + vst1q_u16(dst + 32, s4); + vst1q_u16(dst + 40, s5); + vst1q_u16(dst + 48, s6); + vst1q_u16(dst + 56, s7); dst += dst_stride; - vst4q_u16(dst, vld4q_u16(src)); - vst4q_u16(dst + 32, vld4q_u16(src + 32)); - src += src_stride; - dst += dst_stride; - vst4q_u16(dst, vld4q_u16(src)); - vst4q_u16(dst + 32, vld4q_u16(src + 32)); - src += src_stride; - dst += dst_stride; - vst4q_u16(dst, vld4q_u16(src)); - vst4q_u16(dst + 32, vld4q_u16(src + 32)); - src += src_stride; - dst += dst_stride; - h -= 4; - } while (h > 0); + } while (--h != 0); } } diff --git a/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve_neon.c b/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve_neon.c deleted file mode 100644 index 414ade3530..0000000000 --- a/libs/libvpx/vpx_dsp/arm/highbd_vpx_convolve_neon.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2016 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "./vpx_dsp_rtcd.h" -#include "vpx_dsp/vpx_dsp_common.h" -#include "vpx_dsp/vpx_filter.h" -#include "vpx_ports/mem.h" - -void vpx_highbd_convolve8_neon(const uint16_t *src, ptrdiff_t src_stride, - uint16_t *dst, ptrdiff_t dst_stride, - const InterpKernel *filter, int x0_q4, - int x_step_q4, int y0_q4, int y_step_q4, int w, - int h, int bd) { - // + 1 to make it divisible by 4 - uint16_t temp[64 * 136]; - const int intermediate_height = - (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + SUBPEL_TAPS; - - /* Filter starting 3 lines back. The neon implementation will ignore the given - * height and filter a multiple of 4 lines. Since this goes in to the temp - * buffer which has lots of extra room and is subsequently discarded this is - * safe if somewhat less than ideal. */ - vpx_highbd_convolve8_horiz_neon(src - src_stride * 3, src_stride, temp, w, - filter, x0_q4, x_step_q4, y0_q4, y_step_q4, w, - intermediate_height, bd); - - /* Step into the temp buffer 3 lines to get the actual frame data */ - vpx_highbd_convolve8_vert_neon(temp + w * 3, w, dst, dst_stride, filter, - x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, bd); -} - -void vpx_highbd_convolve8_avg_neon(const uint16_t *src, ptrdiff_t src_stride, - uint16_t *dst, ptrdiff_t dst_stride, - const InterpKernel *filter, int x0_q4, - int x_step_q4, int y0_q4, int y_step_q4, - int w, int h, int bd) { - // + 1 to make it divisible by 4 - uint16_t temp[64 * 136]; - const int intermediate_height = - (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + SUBPEL_TAPS; - - /* This implementation has the same issues as above. In addition, we only want - * to average the values after both passes. - */ - vpx_highbd_convolve8_horiz_neon(src - src_stride * 3, src_stride, temp, w, - filter, x0_q4, x_step_q4, y0_q4, y_step_q4, w, - intermediate_height, bd); - vpx_highbd_convolve8_avg_vert_neon(temp + w * 3, w, dst, dst_stride, filter, - x0_q4, x_step_q4, y0_q4, y_step_q4, w, h, - bd); -} diff --git a/libs/libvpx/vpx_dsp/arm/intrapred_neon.c b/libs/libvpx/vpx_dsp/arm/intrapred_neon.c index 38e275834b..5432f06058 100644 --- a/libs/libvpx/vpx_dsp/arm/intrapred_neon.c +++ b/libs/libvpx/vpx_dsp/arm/intrapred_neon.c @@ -12,51 +12,47 @@ #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" +#include "mem_neon.h" +#include "sum_neon.h" #include "vpx/vpx_integer.h" //------------------------------------------------------------------------------ // DC 4x4 -static INLINE uint16x4_t dc_sum_4(const uint8_t *ref) { - const uint8x8_t ref_u8 = vld1_u8(ref); - const uint16x4_t p0 = vpaddl_u8(ref_u8); - return vpadd_u16(p0, p0); +static INLINE uint16_t dc_sum_4(const uint8_t *ref) { + return horizontal_add_uint8x4(load_unaligned_u8_4x1(ref)); } static INLINE void dc_store_4x4(uint8_t *dst, ptrdiff_t stride, const uint8x8_t dc) { - const uint8x8_t dc_dup = vdup_lane_u8(dc, 0); int i; for (i = 0; i < 4; ++i, dst += stride) { - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(dc_dup), 0); + vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(dc), 0); } } void vpx_dc_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint8x8_t a = vld1_u8(above); - const uint8x8_t l = vld1_u8(left); - const uint16x8_t al = vaddl_u8(a, l); - uint16x4_t sum; - uint8x8_t dc; - sum = vpadd_u16(vget_low_u16(al), vget_low_u16(al)); - sum = vpadd_u16(sum, sum); - dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 3)); + const uint8x8_t a = load_unaligned_u8_4x1(above); + const uint8x8_t l = load_unaligned_u8_4x1(left); + const uint16x4_t al = vget_low_u16(vaddl_u8(a, l)); + const uint16_t sum = horizontal_add_uint16x4(al); + const uint8x8_t dc = vrshrn_n_u16(vdupq_n_u16(sum), 3); dc_store_4x4(dst, stride, dc); } void vpx_dc_left_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint16x4_t sum = dc_sum_4(left); - const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 2)); + const uint16_t sum = dc_sum_4(left); + const uint8x8_t dc = vrshrn_n_u16(vdupq_n_u16(sum), 2); (void)above; dc_store_4x4(dst, stride, dc); } void vpx_dc_top_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint16x4_t sum = dc_sum_4(above); - const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 2)); + const uint16_t sum = dc_sum_4(above); + const uint8x8_t dc = vrshrn_n_u16(vdupq_n_u16(sum), 2); (void)left; dc_store_4x4(dst, stride, dc); } @@ -72,19 +68,15 @@ void vpx_dc_128_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, //------------------------------------------------------------------------------ // DC 8x8 -static INLINE uint16x4_t dc_sum_8(const uint8_t *ref) { - const uint8x8_t ref_u8 = vld1_u8(ref); - uint16x4_t sum = vpaddl_u8(ref_u8); - sum = vpadd_u16(sum, sum); - return vpadd_u16(sum, sum); +static INLINE uint16_t dc_sum_8(const uint8_t *ref) { + return horizontal_add_uint8x8(vld1_u8(ref)); } static INLINE void dc_store_8x8(uint8_t *dst, ptrdiff_t stride, const uint8x8_t dc) { - const uint8x8_t dc_dup = vdup_lane_u8(dc, 0); int i; for (i = 0; i < 8; ++i, dst += stride) { - vst1_u8(dst, dc_dup); + vst1_u8(dst, dc); } } @@ -92,28 +84,24 @@ void vpx_dc_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { const uint8x8_t above_u8 = vld1_u8(above); const uint8x8_t left_u8 = vld1_u8(left); - const uint8x16_t above_and_left = vcombine_u8(above_u8, left_u8); - const uint16x8_t p0 = vpaddlq_u8(above_and_left); - uint16x4_t sum = vadd_u16(vget_low_u16(p0), vget_high_u16(p0)); - uint8x8_t dc; - sum = vpadd_u16(sum, sum); - sum = vpadd_u16(sum, sum); - dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 4)); + const uint16x8_t al = vaddl_u8(above_u8, left_u8); + const uint16_t sum = horizontal_add_uint16x8(al); + const uint8x8_t dc = vrshrn_n_u16(vdupq_n_u16(sum), 4); dc_store_8x8(dst, stride, dc); } void vpx_dc_left_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint16x4_t sum = dc_sum_8(left); - const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 3)); + const uint16_t sum = dc_sum_8(left); + const uint8x8_t dc = vrshrn_n_u16(vdupq_n_u16(sum), 3); (void)above; dc_store_8x8(dst, stride, dc); } void vpx_dc_top_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint16x4_t sum = dc_sum_8(above); - const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 3)); + const uint16_t sum = dc_sum_8(above); + const uint8x8_t dc = vrshrn_n_u16(vdupq_n_u16(sum), 3); (void)left; dc_store_8x8(dst, stride, dc); } @@ -129,20 +117,15 @@ void vpx_dc_128_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, //------------------------------------------------------------------------------ // DC 16x16 -static INLINE uint16x4_t dc_sum_16(const uint8_t *ref) { - const uint8x16_t ref_u8 = vld1q_u8(ref); - const uint16x8_t p0 = vpaddlq_u8(ref_u8); - uint16x4_t sum = vadd_u16(vget_low_u16(p0), vget_high_u16(p0)); - sum = vpadd_u16(sum, sum); - return vpadd_u16(sum, sum); +static INLINE uint16_t dc_sum_16(const uint8_t *ref) { + return horizontal_add_uint8x16(vld1q_u8(ref)); } static INLINE void dc_store_16x16(uint8_t *dst, ptrdiff_t stride, - const uint8x8_t dc) { - const uint8x16_t dc_dup = vdupq_lane_u8(dc, 0); + const uint8x16_t dc) { int i; for (i = 0; i < 16; ++i, dst += stride) { - vst1q_u8(dst, dc_dup); + vst1q_u8(dst + 0, dc); } } @@ -150,22 +133,19 @@ void vpx_dc_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { const uint8x16_t ref0 = vld1q_u8(above); const uint8x16_t ref1 = vld1q_u8(left); - const uint16x8_t p0 = vpaddlq_u8(ref0); - const uint16x8_t p1 = vpaddlq_u8(ref1); - const uint16x8_t p2 = vaddq_u16(p0, p1); - uint16x4_t sum = vadd_u16(vget_low_u16(p2), vget_high_u16(p2)); - uint8x8_t dc; - sum = vpadd_u16(sum, sum); - sum = vpadd_u16(sum, sum); - dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 5)); + const uint16x8_t a = vpaddlq_u8(ref0); + const uint16x8_t l = vpaddlq_u8(ref1); + const uint16x8_t al = vaddq_u16(a, l); + const uint16_t sum = horizontal_add_uint16x8(al); + const uint8x16_t dc = vdupq_lane_u8(vrshrn_n_u16(vdupq_n_u16(sum), 5), 0); dc_store_16x16(dst, stride, dc); } void vpx_dc_left_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint16x4_t sum = dc_sum_16(left); - const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 4)); + const uint16_t sum = dc_sum_16(left); + const uint8x16_t dc = vdupq_lane_u8(vrshrn_n_u16(vdupq_n_u16(sum), 4), 0); (void)above; dc_store_16x16(dst, stride, dc); } @@ -173,8 +153,8 @@ void vpx_dc_left_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, void vpx_dc_top_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint16x4_t sum = dc_sum_16(above); - const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 4)); + const uint16_t sum = dc_sum_16(above); + const uint8x16_t dc = vdupq_lane_u8(vrshrn_n_u16(vdupq_n_u16(sum), 4), 0); (void)left; dc_store_16x16(dst, stride, dc); } @@ -182,7 +162,7 @@ void vpx_dc_top_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, void vpx_dc_128_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint8x8_t dc = vdup_n_u8(0x80); + const uint8x16_t dc = vdupq_n_u8(0x80); (void)above; (void)left; dc_store_16x16(dst, stride, dc); @@ -191,51 +171,41 @@ void vpx_dc_128_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, //------------------------------------------------------------------------------ // DC 32x32 -static INLINE uint16x4_t dc_sum_32(const uint8_t *ref) { - const uint8x16x2_t r = vld2q_u8(ref); - const uint16x8_t p0 = vpaddlq_u8(r.val[0]); - const uint16x8_t p1 = vpaddlq_u8(r.val[1]); - const uint16x8_t p2 = vaddq_u16(p0, p1); - uint16x4_t sum = vadd_u16(vget_low_u16(p2), vget_high_u16(p2)); - sum = vpadd_u16(sum, sum); - return vpadd_u16(sum, sum); +static INLINE uint16_t dc_sum_32(const uint8_t *ref) { + const uint8x16_t r0 = vld1q_u8(ref + 0); + const uint8x16_t r1 = vld1q_u8(ref + 16); + const uint16x8_t r01 = vaddq_u16(vpaddlq_u8(r0), vpaddlq_u8(r1)); + return horizontal_add_uint16x8(r01); } static INLINE void dc_store_32x32(uint8_t *dst, ptrdiff_t stride, - const uint8x8_t dc) { - uint8x16x2_t dc_dup; + const uint8x16_t dc) { int i; - dc_dup.val[0] = dc_dup.val[1] = vdupq_lane_u8(dc, 0); - for (i = 0; i < 32; ++i, dst += stride) { - vst2q_u8(dst, dc_dup); + vst1q_u8(dst + 0, dc); + vst1q_u8(dst + 16, dc); } } void vpx_dc_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint8x16x2_t a = vld2q_u8(above); - const uint8x16x2_t l = vld2q_u8(left); - const uint16x8_t pa0 = vpaddlq_u8(a.val[0]); - const uint16x8_t pl0 = vpaddlq_u8(l.val[0]); - const uint16x8_t pa1 = vpaddlq_u8(a.val[1]); - const uint16x8_t pl1 = vpaddlq_u8(l.val[1]); - const uint16x8_t pa = vaddq_u16(pa0, pa1); - const uint16x8_t pl = vaddq_u16(pl0, pl1); - const uint16x8_t pal = vaddq_u16(pa, pl); - uint16x4_t sum = vadd_u16(vget_low_u16(pal), vget_high_u16(pal)); - uint8x8_t dc; - sum = vpadd_u16(sum, sum); - sum = vpadd_u16(sum, sum); - dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 6)); + const uint8x16_t a0 = vld1q_u8(above + 0); + const uint8x16_t a1 = vld1q_u8(above + 16); + const uint8x16_t l0 = vld1q_u8(left + 0); + const uint8x16_t l1 = vld1q_u8(left + 16); + const uint16x8_t a01 = vaddq_u16(vpaddlq_u8(a0), vpaddlq_u8(a1)); + const uint16x8_t l01 = vaddq_u16(vpaddlq_u8(l0), vpaddlq_u8(l1)); + const uint16x8_t al = vaddq_u16(a01, l01); + const uint16_t sum = horizontal_add_uint16x8(al); + const uint8x16_t dc = vdupq_lane_u8(vrshrn_n_u16(vdupq_n_u16(sum), 6), 0); dc_store_32x32(dst, stride, dc); } void vpx_dc_left_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint16x4_t sum = dc_sum_32(left); - const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 5)); + const uint16_t sum = dc_sum_32(left); + const uint8x16_t dc = vdupq_lane_u8(vrshrn_n_u16(vdupq_n_u16(sum), 5), 0); (void)above; dc_store_32x32(dst, stride, dc); } @@ -243,8 +213,8 @@ void vpx_dc_left_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, void vpx_dc_top_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint16x4_t sum = dc_sum_32(above); - const uint8x8_t dc = vreinterpret_u8_u16(vrshr_n_u16(sum, 5)); + const uint16_t sum = dc_sum_32(above); + const uint8x16_t dc = vdupq_lane_u8(vrshrn_n_u16(vdupq_n_u16(sum), 5), 0); (void)left; dc_store_32x32(dst, stride, dc); } @@ -252,7 +222,7 @@ void vpx_dc_top_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, void vpx_dc_128_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint8x8_t dc = vdup_n_u8(0x80); + const uint8x16_t dc = vdupq_n_u8(0x80); (void)above; (void)left; dc_store_32x32(dst, stride, dc); @@ -262,123 +232,629 @@ void vpx_dc_128_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, void vpx_d45_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint8x8_t ABCDEFGH = vld1_u8(above); - const uint64x1_t A1 = vshr_n_u64(vreinterpret_u64_u8(ABCDEFGH), 8); - const uint64x1_t A2 = vshr_n_u64(vreinterpret_u64_u8(ABCDEFGH), 16); - const uint8x8_t BCDEFGH0 = vreinterpret_u8_u64(A1); - const uint8x8_t CDEFGH00 = vreinterpret_u8_u64(A2); - const uint8x8_t avg1 = vhadd_u8(ABCDEFGH, CDEFGH00); - const uint8x8_t avg2 = vrhadd_u8(avg1, BCDEFGH0); - const uint64x1_t avg2_u64 = vreinterpret_u64_u8(avg2); - const uint32x2_t r0 = vreinterpret_u32_u8(avg2); - const uint32x2_t r1 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 8)); - const uint32x2_t r2 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 16)); - const uint32x2_t r3 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 24)); + uint8x8_t a0, a1, a2, d0; + uint8_t a7; (void)left; - vst1_lane_u32((uint32_t *)(dst + 0 * stride), r0, 0); - vst1_lane_u32((uint32_t *)(dst + 1 * stride), r1, 0); - vst1_lane_u32((uint32_t *)(dst + 2 * stride), r2, 0); - vst1_lane_u32((uint32_t *)(dst + 3 * stride), r3, 0); - vst1_lane_u8(dst + 3 * stride + 3, ABCDEFGH, 7); -} -static INLINE void d45_store_8(uint8_t **dst, const ptrdiff_t stride, - const uint8x8_t above_right, uint8x8_t *row) { - *row = vext_u8(*row, above_right, 1); - vst1_u8(*dst, *row); - *dst += stride; + a0 = vld1_u8(above); + a7 = above[7]; + + // [ above[1], ..., above[6], x, x ] + a1 = vext_u8(a0, a0, 1); + // [ above[2], ..., above[7], x, x ] + a2 = vext_u8(a0, a0, 2); + + // d0[0] = AVG3(above[0], above[1], above[2]); + // ... + // d0[5] = AVG3(above[5], above[6], above[7]); + // d0[6] = x (don't care) + // d0[7] = x (don't care) + d0 = vrhadd_u8(vhadd_u8(a0, a2), a1); + + // We want: + // stride=0 [ d0[0], d0[1], d0[2], d0[3] ] + // stride=1 [ d0[1], d0[2], d0[3], d0[4] ] + // stride=2 [ d0[2], d0[3], d0[4], d0[5] ] + // stride=2 [ d0[3], d0[4], d0[5], above[7] ] + store_u8_4x1(dst + 0 * stride, d0); + store_u8_4x1(dst + 1 * stride, vext_u8(d0, d0, 1)); + store_u8_4x1(dst + 2 * stride, vext_u8(d0, d0, 2)); + store_u8_4x1(dst + 3 * stride, vext_u8(d0, d0, 3)); + + // We stored d0[6] above, so fixup into above[7]. + dst[3 * stride + 3] = a7; } void vpx_d45_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint8x8_t A0 = vld1_u8(above); - const uint8x8_t above_right = vdup_lane_u8(A0, 7); - const uint8x8_t A1 = vext_u8(A0, above_right, 1); - const uint8x8_t A2 = vext_u8(A0, above_right, 2); - const uint8x8_t avg1 = vhadd_u8(A0, A2); - uint8x8_t row = vrhadd_u8(avg1, A1); + uint8x8_t ax0, a0, a1, a7, d0; (void)left; - vst1_u8(dst, row); - dst += stride; - d45_store_8(&dst, stride, above_right, &row); - d45_store_8(&dst, stride, above_right, &row); - d45_store_8(&dst, stride, above_right, &row); - d45_store_8(&dst, stride, above_right, &row); - d45_store_8(&dst, stride, above_right, &row); - d45_store_8(&dst, stride, above_right, &row); - vst1_u8(dst, above_right); -} + a0 = vld1_u8(above + 0); + a1 = vld1_u8(above + 1); + a7 = vld1_dup_u8(above + 7); -static INLINE void d45_store_16(uint8_t **dst, const ptrdiff_t stride, - const uint8x16_t above_right, uint8x16_t *row) { - *row = vextq_u8(*row, above_right, 1); - vst1q_u8(*dst, *row); - *dst += stride; + // We want to calculate the AVG3 result in lanes 1-7 inclusive so we can + // shift in above[7] later, so shift a0 across by one to get the right + // inputs: + // [ x, above[0], ... , above[6] ] + ax0 = vext_u8(a0, a0, 7); + + // d0[0] = x (don't care) + // d0[1] = AVG3(above[0], above[1], above[2]); + // ... + // d0[7] = AVG3(above[6], above[7], above[8]); + d0 = vrhadd_u8(vhadd_u8(ax0, a1), a0); + + // Undo the earlier ext, incrementally shift in duplicates of above[7]. + vst1_u8(dst + 0 * stride, vext_u8(d0, a7, 1)); + vst1_u8(dst + 1 * stride, vext_u8(d0, a7, 2)); + vst1_u8(dst + 2 * stride, vext_u8(d0, a7, 3)); + vst1_u8(dst + 3 * stride, vext_u8(d0, a7, 4)); + vst1_u8(dst + 4 * stride, vext_u8(d0, a7, 5)); + vst1_u8(dst + 5 * stride, vext_u8(d0, a7, 6)); + vst1_u8(dst + 6 * stride, vext_u8(d0, a7, 7)); + vst1_u8(dst + 7 * stride, a7); } void vpx_d45_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint8x16_t A0 = vld1q_u8(above); - const uint8x16_t above_right = vdupq_lane_u8(vget_high_u8(A0), 7); - const uint8x16_t A1 = vextq_u8(A0, above_right, 1); - const uint8x16_t A2 = vextq_u8(A0, above_right, 2); - const uint8x16_t avg1 = vhaddq_u8(A0, A2); - uint8x16_t row = vrhaddq_u8(avg1, A1); + uint8x16_t ax0, a0, a1, a15, d0; (void)left; - vst1q_u8(dst, row); - dst += stride; - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - d45_store_16(&dst, stride, above_right, &row); - vst1q_u8(dst, above_right); + a0 = vld1q_u8(above + 0); + a1 = vld1q_u8(above + 1); + a15 = vld1q_dup_u8(above + 15); + + // We want to calculate the AVG3 result in lanes 1-15 inclusive so we can + // shift in above[15] later, so shift a0 across by one to get the right + // inputs: + // [ x, above[0], ... , above[14] ] + ax0 = vextq_u8(a0, a0, 15); + + // d0[0] = x (don't care) + // d0[1] = AVG3(above[0], above[1], above[2]); + // ... + // d0[15] = AVG3(above[14], above[15], above[16]); + d0 = vrhaddq_u8(vhaddq_u8(ax0, a1), a0); + + // Undo the earlier ext, incrementally shift in duplicates of above[15]. + vst1q_u8(dst + 0 * stride, vextq_u8(d0, a15, 1)); + vst1q_u8(dst + 1 * stride, vextq_u8(d0, a15, 2)); + vst1q_u8(dst + 2 * stride, vextq_u8(d0, a15, 3)); + vst1q_u8(dst + 3 * stride, vextq_u8(d0, a15, 4)); + vst1q_u8(dst + 4 * stride, vextq_u8(d0, a15, 5)); + vst1q_u8(dst + 5 * stride, vextq_u8(d0, a15, 6)); + vst1q_u8(dst + 6 * stride, vextq_u8(d0, a15, 7)); + vst1q_u8(dst + 7 * stride, vextq_u8(d0, a15, 8)); + vst1q_u8(dst + 8 * stride, vextq_u8(d0, a15, 9)); + vst1q_u8(dst + 9 * stride, vextq_u8(d0, a15, 10)); + vst1q_u8(dst + 10 * stride, vextq_u8(d0, a15, 11)); + vst1q_u8(dst + 11 * stride, vextq_u8(d0, a15, 12)); + vst1q_u8(dst + 12 * stride, vextq_u8(d0, a15, 13)); + vst1q_u8(dst + 13 * stride, vextq_u8(d0, a15, 14)); + vst1q_u8(dst + 14 * stride, vextq_u8(d0, a15, 15)); + vst1q_u8(dst + 15 * stride, a15); } void vpx_d45_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint8x16_t A0_0 = vld1q_u8(above); - const uint8x16_t A0_1 = vld1q_u8(above + 16); - const uint8x16_t above_right = vdupq_lane_u8(vget_high_u8(A0_1), 7); - const uint8x16_t A1_0 = vld1q_u8(above + 1); - const uint8x16_t A1_1 = vld1q_u8(above + 17); - const uint8x16_t A2_0 = vld1q_u8(above + 2); - const uint8x16_t A2_1 = vld1q_u8(above + 18); - const uint8x16_t avg_0 = vhaddq_u8(A0_0, A2_0); - const uint8x16_t avg_1 = vhaddq_u8(A0_1, A2_1); - uint8x16_t row_0 = vrhaddq_u8(avg_0, A1_0); - uint8x16_t row_1 = vrhaddq_u8(avg_1, A1_1); - int i; + uint8x16_t ax0, a0, a1, a15, a16, a17, a31, d0[2]; (void)left; - vst1q_u8(dst, row_0); - dst += 16; - vst1q_u8(dst, row_1); - dst += stride - 16; + a0 = vld1q_u8(above + 0); + a1 = vld1q_u8(above + 1); + a15 = vld1q_u8(above + 15); + a16 = vld1q_u8(above + 16); + a17 = vld1q_u8(above + 17); + a31 = vld1q_dup_u8(above + 31); - for (i = 0; i < 30; ++i) { - row_0 = vextq_u8(row_0, row_1, 1); - row_1 = vextq_u8(row_1, above_right, 1); - vst1q_u8(dst, row_0); - dst += 16; - vst1q_u8(dst, row_1); - dst += stride - 16; - } + // We want to calculate the AVG3 result in lanes 1-15 inclusive so we can + // shift in above[15] later, so shift a0 across by one to get the right + // inputs: + // [ x, above[0], ... , above[14] ] + ax0 = vextq_u8(a0, a0, 15); - vst1q_u8(dst, above_right); - dst += 16; - vst1q_u8(dst, row_1); + // d0[0] = x (don't care) + // d0[1] = AVG3(above[0], above[1], above[2]); + // ... + // d0[15] = AVG3(above[14], above[15], above[16]); + d0[0] = vrhaddq_u8(vhaddq_u8(ax0, a1), a0); + d0[1] = vrhaddq_u8(vhaddq_u8(a15, a17), a16); + + // Undo the earlier ext, incrementally shift in duplicates of above[15]. + vst1q_u8(dst + 0 * stride + 0, vextq_u8(d0[0], d0[1], 1)); + vst1q_u8(dst + 0 * stride + 16, vextq_u8(d0[1], a31, 1)); + vst1q_u8(dst + 1 * stride + 0, vextq_u8(d0[0], d0[1], 2)); + vst1q_u8(dst + 1 * stride + 16, vextq_u8(d0[1], a31, 2)); + vst1q_u8(dst + 2 * stride + 0, vextq_u8(d0[0], d0[1], 3)); + vst1q_u8(dst + 2 * stride + 16, vextq_u8(d0[1], a31, 3)); + vst1q_u8(dst + 3 * stride + 0, vextq_u8(d0[0], d0[1], 4)); + vst1q_u8(dst + 3 * stride + 16, vextq_u8(d0[1], a31, 4)); + vst1q_u8(dst + 4 * stride + 0, vextq_u8(d0[0], d0[1], 5)); + vst1q_u8(dst + 4 * stride + 16, vextq_u8(d0[1], a31, 5)); + vst1q_u8(dst + 5 * stride + 0, vextq_u8(d0[0], d0[1], 6)); + vst1q_u8(dst + 5 * stride + 16, vextq_u8(d0[1], a31, 6)); + vst1q_u8(dst + 6 * stride + 0, vextq_u8(d0[0], d0[1], 7)); + vst1q_u8(dst + 6 * stride + 16, vextq_u8(d0[1], a31, 7)); + vst1q_u8(dst + 7 * stride + 0, vextq_u8(d0[0], d0[1], 8)); + vst1q_u8(dst + 7 * stride + 16, vextq_u8(d0[1], a31, 8)); + vst1q_u8(dst + 8 * stride + 0, vextq_u8(d0[0], d0[1], 9)); + vst1q_u8(dst + 8 * stride + 16, vextq_u8(d0[1], a31, 9)); + vst1q_u8(dst + 9 * stride + 0, vextq_u8(d0[0], d0[1], 10)); + vst1q_u8(dst + 9 * stride + 16, vextq_u8(d0[1], a31, 10)); + vst1q_u8(dst + 10 * stride + 0, vextq_u8(d0[0], d0[1], 11)); + vst1q_u8(dst + 10 * stride + 16, vextq_u8(d0[1], a31, 11)); + vst1q_u8(dst + 11 * stride + 0, vextq_u8(d0[0], d0[1], 12)); + vst1q_u8(dst + 11 * stride + 16, vextq_u8(d0[1], a31, 12)); + vst1q_u8(dst + 12 * stride + 0, vextq_u8(d0[0], d0[1], 13)); + vst1q_u8(dst + 12 * stride + 16, vextq_u8(d0[1], a31, 13)); + vst1q_u8(dst + 13 * stride + 0, vextq_u8(d0[0], d0[1], 14)); + vst1q_u8(dst + 13 * stride + 16, vextq_u8(d0[1], a31, 14)); + vst1q_u8(dst + 14 * stride + 0, vextq_u8(d0[0], d0[1], 15)); + vst1q_u8(dst + 14 * stride + 16, vextq_u8(d0[1], a31, 15)); + vst1q_u8(dst + 15 * stride + 0, d0[1]); + vst1q_u8(dst + 15 * stride + 16, a31); + + vst1q_u8(dst + 16 * stride + 0, vextq_u8(d0[1], a31, 1)); + vst1q_u8(dst + 16 * stride + 16, a31); + vst1q_u8(dst + 17 * stride + 0, vextq_u8(d0[1], a31, 2)); + vst1q_u8(dst + 17 * stride + 16, a31); + vst1q_u8(dst + 18 * stride + 0, vextq_u8(d0[1], a31, 3)); + vst1q_u8(dst + 18 * stride + 16, a31); + vst1q_u8(dst + 19 * stride + 0, vextq_u8(d0[1], a31, 4)); + vst1q_u8(dst + 19 * stride + 16, a31); + vst1q_u8(dst + 20 * stride + 0, vextq_u8(d0[1], a31, 5)); + vst1q_u8(dst + 20 * stride + 16, a31); + vst1q_u8(dst + 21 * stride + 0, vextq_u8(d0[1], a31, 6)); + vst1q_u8(dst + 21 * stride + 16, a31); + vst1q_u8(dst + 22 * stride + 0, vextq_u8(d0[1], a31, 7)); + vst1q_u8(dst + 22 * stride + 16, a31); + vst1q_u8(dst + 23 * stride + 0, vextq_u8(d0[1], a31, 8)); + vst1q_u8(dst + 23 * stride + 16, a31); + vst1q_u8(dst + 24 * stride + 0, vextq_u8(d0[1], a31, 9)); + vst1q_u8(dst + 24 * stride + 16, a31); + vst1q_u8(dst + 25 * stride + 0, vextq_u8(d0[1], a31, 10)); + vst1q_u8(dst + 25 * stride + 16, a31); + vst1q_u8(dst + 26 * stride + 0, vextq_u8(d0[1], a31, 11)); + vst1q_u8(dst + 26 * stride + 16, a31); + vst1q_u8(dst + 27 * stride + 0, vextq_u8(d0[1], a31, 12)); + vst1q_u8(dst + 27 * stride + 16, a31); + vst1q_u8(dst + 28 * stride + 0, vextq_u8(d0[1], a31, 13)); + vst1q_u8(dst + 28 * stride + 16, a31); + vst1q_u8(dst + 29 * stride + 0, vextq_u8(d0[1], a31, 14)); + vst1q_u8(dst + 29 * stride + 16, a31); + vst1q_u8(dst + 30 * stride + 0, vextq_u8(d0[1], a31, 15)); + vst1q_u8(dst + 30 * stride + 16, a31); + vst1q_u8(dst + 31 * stride + 0, a31); + vst1q_u8(dst + 31 * stride + 16, a31); +} + +// ----------------------------------------------------------------------------- + +void vpx_d63_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + uint8x8_t a0, a1, a2, a3, d0, d1, d2, d3; + (void)left; + + a0 = load_unaligned_u8_4x1(above + 0); + a1 = load_unaligned_u8_4x1(above + 1); + a2 = load_unaligned_u8_4x1(above + 2); + a3 = load_unaligned_u8_4x1(above + 3); + + d0 = vrhadd_u8(a0, a1); + d1 = vrhadd_u8(vhadd_u8(a0, a2), a1); + d2 = vrhadd_u8(a1, a2); + d3 = vrhadd_u8(vhadd_u8(a1, a3), a2); + + store_u8_4x1(dst + 0 * stride, d0); + store_u8_4x1(dst + 1 * stride, d1); + store_u8_4x1(dst + 2 * stride, d2); + store_u8_4x1(dst + 3 * stride, d3); +} + +void vpx_d63_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + uint8x8_t a0, a1, a2, a7, d0, d1; + (void)left; + + a0 = vld1_u8(above + 0); + a1 = vld1_u8(above + 1); + a2 = vld1_u8(above + 2); + a7 = vld1_dup_u8(above + 7); + + d0 = vrhadd_u8(a0, a1); + d1 = vrhadd_u8(vhadd_u8(a0, a2), a1); + + vst1_u8(dst + 0 * stride, d0); + vst1_u8(dst + 1 * stride, d1); + + d0 = vext_u8(d0, d0, 7); + d1 = vext_u8(d1, d1, 7); + + vst1_u8(dst + 2 * stride, vext_u8(d0, a7, 2)); + vst1_u8(dst + 3 * stride, vext_u8(d1, a7, 2)); + vst1_u8(dst + 4 * stride, vext_u8(d0, a7, 3)); + vst1_u8(dst + 5 * stride, vext_u8(d1, a7, 3)); + vst1_u8(dst + 6 * stride, vext_u8(d0, a7, 4)); + vst1_u8(dst + 7 * stride, vext_u8(d1, a7, 4)); +} + +void vpx_d63_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + uint8x16_t a0, a1, a2, a15, d0, d1; + (void)left; + + a0 = vld1q_u8(above + 0); + a1 = vld1q_u8(above + 1); + a2 = vld1q_u8(above + 2); + a15 = vld1q_dup_u8(above + 15); + + d0 = vrhaddq_u8(a0, a1); + d1 = vrhaddq_u8(vhaddq_u8(a0, a2), a1); + + vst1q_u8(dst + 0 * stride, d0); + vst1q_u8(dst + 1 * stride, d1); + + d0 = vextq_u8(d0, d0, 15); + d1 = vextq_u8(d1, d1, 15); + + vst1q_u8(dst + 2 * stride, vextq_u8(d0, a15, 2)); + vst1q_u8(dst + 3 * stride, vextq_u8(d1, a15, 2)); + vst1q_u8(dst + 4 * stride, vextq_u8(d0, a15, 3)); + vst1q_u8(dst + 5 * stride, vextq_u8(d1, a15, 3)); + vst1q_u8(dst + 6 * stride, vextq_u8(d0, a15, 4)); + vst1q_u8(dst + 7 * stride, vextq_u8(d1, a15, 4)); + vst1q_u8(dst + 8 * stride, vextq_u8(d0, a15, 5)); + vst1q_u8(dst + 9 * stride, vextq_u8(d1, a15, 5)); + vst1q_u8(dst + 10 * stride, vextq_u8(d0, a15, 6)); + vst1q_u8(dst + 11 * stride, vextq_u8(d1, a15, 6)); + vst1q_u8(dst + 12 * stride, vextq_u8(d0, a15, 7)); + vst1q_u8(dst + 13 * stride, vextq_u8(d1, a15, 7)); + vst1q_u8(dst + 14 * stride, vextq_u8(d0, a15, 8)); + vst1q_u8(dst + 15 * stride, vextq_u8(d1, a15, 8)); +} + +void vpx_d63_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + uint8x16_t a0, a1, a2, a16, a17, a18, a31, d0_lo, d0_hi, d1_lo, d1_hi; + (void)left; + + a0 = vld1q_u8(above + 0); + a1 = vld1q_u8(above + 1); + a2 = vld1q_u8(above + 2); + a16 = vld1q_u8(above + 16); + a17 = vld1q_u8(above + 17); + a18 = vld1q_u8(above + 18); + a31 = vld1q_dup_u8(above + 31); + + d0_lo = vrhaddq_u8(a0, a1); + d0_hi = vrhaddq_u8(a16, a17); + d1_lo = vrhaddq_u8(vhaddq_u8(a0, a2), a1); + d1_hi = vrhaddq_u8(vhaddq_u8(a16, a18), a17); + + vst1q_u8(dst + 0 * stride + 0, d0_lo); + vst1q_u8(dst + 0 * stride + 16, d0_hi); + vst1q_u8(dst + 1 * stride + 0, d1_lo); + vst1q_u8(dst + 1 * stride + 16, d1_hi); + + d0_hi = vextq_u8(d0_lo, d0_hi, 15); + d0_lo = vextq_u8(d0_lo, d0_lo, 15); + d1_hi = vextq_u8(d1_lo, d1_hi, 15); + d1_lo = vextq_u8(d1_lo, d1_lo, 15); + + vst1q_u8(dst + 2 * stride + 0, vextq_u8(d0_lo, d0_hi, 2)); + vst1q_u8(dst + 2 * stride + 16, vextq_u8(d0_hi, a31, 2)); + vst1q_u8(dst + 3 * stride + 0, vextq_u8(d1_lo, d1_hi, 2)); + vst1q_u8(dst + 3 * stride + 16, vextq_u8(d1_hi, a31, 2)); + vst1q_u8(dst + 4 * stride + 0, vextq_u8(d0_lo, d0_hi, 3)); + vst1q_u8(dst + 4 * stride + 16, vextq_u8(d0_hi, a31, 3)); + vst1q_u8(dst + 5 * stride + 0, vextq_u8(d1_lo, d1_hi, 3)); + vst1q_u8(dst + 5 * stride + 16, vextq_u8(d1_hi, a31, 3)); + vst1q_u8(dst + 6 * stride + 0, vextq_u8(d0_lo, d0_hi, 4)); + vst1q_u8(dst + 6 * stride + 16, vextq_u8(d0_hi, a31, 4)); + vst1q_u8(dst + 7 * stride + 0, vextq_u8(d1_lo, d1_hi, 4)); + vst1q_u8(dst + 7 * stride + 16, vextq_u8(d1_hi, a31, 4)); + vst1q_u8(dst + 8 * stride + 0, vextq_u8(d0_lo, d0_hi, 5)); + vst1q_u8(dst + 8 * stride + 16, vextq_u8(d0_hi, a31, 5)); + vst1q_u8(dst + 9 * stride + 0, vextq_u8(d1_lo, d1_hi, 5)); + vst1q_u8(dst + 9 * stride + 16, vextq_u8(d1_hi, a31, 5)); + vst1q_u8(dst + 10 * stride + 0, vextq_u8(d0_lo, d0_hi, 6)); + vst1q_u8(dst + 10 * stride + 16, vextq_u8(d0_hi, a31, 6)); + vst1q_u8(dst + 11 * stride + 0, vextq_u8(d1_lo, d1_hi, 6)); + vst1q_u8(dst + 11 * stride + 16, vextq_u8(d1_hi, a31, 6)); + vst1q_u8(dst + 12 * stride + 0, vextq_u8(d0_lo, d0_hi, 7)); + vst1q_u8(dst + 12 * stride + 16, vextq_u8(d0_hi, a31, 7)); + vst1q_u8(dst + 13 * stride + 0, vextq_u8(d1_lo, d1_hi, 7)); + vst1q_u8(dst + 13 * stride + 16, vextq_u8(d1_hi, a31, 7)); + vst1q_u8(dst + 14 * stride + 0, vextq_u8(d0_lo, d0_hi, 8)); + vst1q_u8(dst + 14 * stride + 16, vextq_u8(d0_hi, a31, 8)); + vst1q_u8(dst + 15 * stride + 0, vextq_u8(d1_lo, d1_hi, 8)); + vst1q_u8(dst + 15 * stride + 16, vextq_u8(d1_hi, a31, 8)); + vst1q_u8(dst + 16 * stride + 0, vextq_u8(d0_lo, d0_hi, 9)); + vst1q_u8(dst + 16 * stride + 16, vextq_u8(d0_hi, a31, 9)); + vst1q_u8(dst + 17 * stride + 0, vextq_u8(d1_lo, d1_hi, 9)); + vst1q_u8(dst + 17 * stride + 16, vextq_u8(d1_hi, a31, 9)); + vst1q_u8(dst + 18 * stride + 0, vextq_u8(d0_lo, d0_hi, 10)); + vst1q_u8(dst + 18 * stride + 16, vextq_u8(d0_hi, a31, 10)); + vst1q_u8(dst + 19 * stride + 0, vextq_u8(d1_lo, d1_hi, 10)); + vst1q_u8(dst + 19 * stride + 16, vextq_u8(d1_hi, a31, 10)); + vst1q_u8(dst + 20 * stride + 0, vextq_u8(d0_lo, d0_hi, 11)); + vst1q_u8(dst + 20 * stride + 16, vextq_u8(d0_hi, a31, 11)); + vst1q_u8(dst + 21 * stride + 0, vextq_u8(d1_lo, d1_hi, 11)); + vst1q_u8(dst + 21 * stride + 16, vextq_u8(d1_hi, a31, 11)); + vst1q_u8(dst + 22 * stride + 0, vextq_u8(d0_lo, d0_hi, 12)); + vst1q_u8(dst + 22 * stride + 16, vextq_u8(d0_hi, a31, 12)); + vst1q_u8(dst + 23 * stride + 0, vextq_u8(d1_lo, d1_hi, 12)); + vst1q_u8(dst + 23 * stride + 16, vextq_u8(d1_hi, a31, 12)); + vst1q_u8(dst + 24 * stride + 0, vextq_u8(d0_lo, d0_hi, 13)); + vst1q_u8(dst + 24 * stride + 16, vextq_u8(d0_hi, a31, 13)); + vst1q_u8(dst + 25 * stride + 0, vextq_u8(d1_lo, d1_hi, 13)); + vst1q_u8(dst + 25 * stride + 16, vextq_u8(d1_hi, a31, 13)); + vst1q_u8(dst + 26 * stride + 0, vextq_u8(d0_lo, d0_hi, 14)); + vst1q_u8(dst + 26 * stride + 16, vextq_u8(d0_hi, a31, 14)); + vst1q_u8(dst + 27 * stride + 0, vextq_u8(d1_lo, d1_hi, 14)); + vst1q_u8(dst + 27 * stride + 16, vextq_u8(d1_hi, a31, 14)); + vst1q_u8(dst + 28 * stride + 0, vextq_u8(d0_lo, d0_hi, 15)); + vst1q_u8(dst + 28 * stride + 16, vextq_u8(d0_hi, a31, 15)); + vst1q_u8(dst + 29 * stride + 0, vextq_u8(d1_lo, d1_hi, 15)); + vst1q_u8(dst + 29 * stride + 16, vextq_u8(d1_hi, a31, 15)); + vst1q_u8(dst + 30 * stride + 0, d0_hi); + vst1q_u8(dst + 30 * stride + 16, a31); + vst1q_u8(dst + 31 * stride + 0, d1_hi); + vst1q_u8(dst + 31 * stride + 16, a31); +} + +// ----------------------------------------------------------------------------- + +void vpx_d117_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + // See vpx_d117_predictor_8x8_neon for more details on the implementation. + uint8x8_t az, a0, l0az, d0, d1, d2, d3, col0, col1; + + az = load_unaligned_u8_4x1(above - 1); + a0 = load_unaligned_u8_4x1(above + 0); + // [ left[0], above[-1], above[0], above[1], x, x, x, x ] + l0az = vext_u8(vld1_dup_u8(left), az, 7); + + col0 = vdup_n_u8((above[-1] + 2 * left[0] + left[1] + 2) >> 2); + col1 = vdup_n_u8((left[0] + 2 * left[1] + left[2] + 2) >> 2); + + d0 = vrhadd_u8(az, a0); + d1 = vrhadd_u8(vhadd_u8(l0az, a0), az); + d2 = vext_u8(col0, d0, 7); + d3 = vext_u8(col1, d1, 7); + + store_u8_4x1(dst + 0 * stride, d0); + store_u8_4x1(dst + 1 * stride, d1); + store_u8_4x1(dst + 2 * stride, d2); + store_u8_4x1(dst + 3 * stride, d3); +} + +void vpx_d117_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + uint8x8_t az, a0, l0az, d0, d1, l0, l1, azl0, col0, col0_even, col0_odd; + + az = vld1_u8(above - 1); + a0 = vld1_u8(above + 0); + // [ left[0], above[-1], ... , above[5] ] + l0az = vext_u8(vld1_dup_u8(left), az, 7); + + l0 = vld1_u8(left + 0); + // The last lane here is unused, reading left[8] could cause a buffer + // over-read, so just fill with a duplicate of left[0] to avoid needing to + // materialize a zero: + // [ left[1], ... , left[7], x ] + l1 = vext_u8(l0, l0, 1); + // [ above[-1], left[0], ... , left[6] ] + azl0 = vext_u8(vld1_dup_u8(above - 1), l0, 7); + + // d0[0] = AVG2(above[-1], above[0]) + // d0[1] = AVG2(above[0], above[1]) + // ... + // d0[7] = AVG2(above[6], above[7]) + d0 = vrhadd_u8(az, a0); + + // d1[0] = AVG3(left[0], above[-1], above[0]) + // d1[1] = AVG3(above[-1], above[0], above[1]) + // ... + // d1[7] = AVG3(above[5], above[6], above[7]) + d1 = vrhadd_u8(vhadd_u8(l0az, a0), az); + + // The ext instruction shifts elements in from the end of the vector rather + // than the start, so reverse the vector to put the elements to be shifted in + // at the end. The lowest two lanes here are unused: + // col0[7] = AVG3(above[-1], left[0], left[1]) + // col0[6] = AVG3(left[0], left[1], left[2]) + // ... + // col0[2] = AVG3(left[4], left[5], left[6]) + // col0[1] = x (don't care) + // col0[0] = x (don't care) + col0 = vrev64_u8(vrhadd_u8(vhadd_u8(azl0, l1), l0)); + + // We don't care about the first parameter to this uzp since we only ever use + // the high three elements, we just use col0 again since it is already + // available: + // col0_even = [ x, x, x, x, x, col0[3], col0[5], col0[7] ] + // col0_odd = [ x, x, x, x, x, col0[2], col0[4], col0[6] ] + col0_even = vuzp_u8(col0, col0).val[1]; + col0_odd = vuzp_u8(col0, col0).val[0]; + + // Incrementally shift more elements from col0 into d0/1: + // stride=0 [ d0[0], d0[1], d0[2], d0[3], d0[4], d0[5], d0[6], d0[7] ] + // stride=1 [ d1[0], d1[1], d1[2], d1[3], d1[4], d1[5], d1[6], d1[7] ] + // stride=2 [ col0[7], d0[0], d0[1], d0[2], d0[3], d0[4], d0[5], d0[6] ] + // stride=3 [ col0[6], d1[0], d1[1], d1[2], d1[3], d1[4], d1[5], d1[6] ] + // stride=4 [ col0[5], col0[7], d0[0], d0[1], d0[2], d0[3], d0[4], d0[5] ] + // stride=5 [ col0[4], col0[6], d1[0], d1[1], d1[2], d1[3], d1[4], d1[5] ] + // stride=6 [ col0[3], col0[5], col0[7], d0[0], d0[1], d0[2], d0[3], d0[4] ] + // stride=7 [ col0[2], col0[4], col0[6], d1[0], d1[1], d1[2], d1[3], d1[4] ] + vst1_u8(dst + 0 * stride, d0); + vst1_u8(dst + 1 * stride, d1); + vst1_u8(dst + 2 * stride, vext_u8(col0_even, d0, 7)); + vst1_u8(dst + 3 * stride, vext_u8(col0_odd, d1, 7)); + vst1_u8(dst + 4 * stride, vext_u8(col0_even, d0, 6)); + vst1_u8(dst + 5 * stride, vext_u8(col0_odd, d1, 6)); + vst1_u8(dst + 6 * stride, vext_u8(col0_even, d0, 5)); + vst1_u8(dst + 7 * stride, vext_u8(col0_odd, d1, 5)); +} + +void vpx_d117_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + // See vpx_d117_predictor_8x8_neon for more details on the implementation. + uint8x16_t az, a0, l0az, d0, d1, l0, l1, azl0, col0, col0_even, col0_odd; + + az = vld1q_u8(above - 1); + a0 = vld1q_u8(above + 0); + // [ left[0], above[-1], ... , above[13] ] + l0az = vextq_u8(vld1q_dup_u8(left), az, 15); + + l0 = vld1q_u8(left + 0); + // The last lane here is unused, reading left[16] could cause a buffer + // over-read, so just fill with a duplicate of left[0] to avoid needing to + // materialize a zero: + // [ left[1], ... , left[15], x ] + l1 = vextq_u8(l0, l0, 1); + // [ above[-1], left[0], ... , left[14] ] + azl0 = vextq_u8(vld1q_dup_u8(above - 1), l0, 15); + + d0 = vrhaddq_u8(az, a0); + d1 = vrhaddq_u8(vhaddq_u8(l0az, a0), az); + + col0 = vrhaddq_u8(vhaddq_u8(azl0, l1), l0); + col0 = vrev64q_u8(vextq_u8(col0, col0, 8)); + + // The low nine lanes here are unused so the first input to the uzp is + // unused, so just use a duplicate of col0 since we have it already. This + // also means that the lowest lane of col0 here is unused. + col0_even = vuzpq_u8(col0, col0).val[1]; + col0_odd = vuzpq_u8(col0, col0).val[0]; + + vst1q_u8(dst + 0 * stride, d0); + vst1q_u8(dst + 1 * stride, d1); + vst1q_u8(dst + 2 * stride, vextq_u8(col0_even, d0, 15)); + vst1q_u8(dst + 3 * stride, vextq_u8(col0_odd, d1, 15)); + vst1q_u8(dst + 4 * stride, vextq_u8(col0_even, d0, 14)); + vst1q_u8(dst + 5 * stride, vextq_u8(col0_odd, d1, 14)); + vst1q_u8(dst + 6 * stride, vextq_u8(col0_even, d0, 13)); + vst1q_u8(dst + 7 * stride, vextq_u8(col0_odd, d1, 13)); + vst1q_u8(dst + 8 * stride, vextq_u8(col0_even, d0, 12)); + vst1q_u8(dst + 9 * stride, vextq_u8(col0_odd, d1, 12)); + vst1q_u8(dst + 10 * stride, vextq_u8(col0_even, d0, 11)); + vst1q_u8(dst + 11 * stride, vextq_u8(col0_odd, d1, 11)); + vst1q_u8(dst + 12 * stride, vextq_u8(col0_even, d0, 10)); + vst1q_u8(dst + 13 * stride, vextq_u8(col0_odd, d1, 10)); + vst1q_u8(dst + 14 * stride, vextq_u8(col0_even, d0, 9)); + vst1q_u8(dst + 15 * stride, vextq_u8(col0_odd, d1, 9)); +} + +void vpx_d117_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + // See vpx_d117_predictor_8x8_neon for more details on the implementation. + uint8x16_t az, a0, a14, a15, a16, l0az, d0_lo, d0_hi, d1_lo, d1_hi, l0, l1, + l15, l16, l17, azl0, col0_lo, col0_hi, col0_even, col0_odd; + + az = vld1q_u8(above - 1); + a0 = vld1q_u8(above + 0); + a14 = vld1q_u8(above + 14); + a15 = vld1q_u8(above + 15); + a16 = vld1q_u8(above + 16); + // [ left[0], above[-1], ... , above[13] ] + l0az = vextq_u8(vld1q_dup_u8(left), az, 15); + + l0 = vld1q_u8(left + 0); + l1 = vld1q_u8(left + 1); + l15 = vld1q_u8(left + 15); + l16 = vld1q_u8(left + 16); + // The last lane here is unused, reading left[32] would cause a buffer + // over-read (observed as an address-sanitizer failure), so just fill with a + // duplicate of left[16] to avoid needing to materialize a zero: + // [ left[17], ... , left[31], x ] + l17 = vextq_u8(l16, l16, 1); + // [ above[-1], left[0], ... , left[14] ] + azl0 = vextq_u8(vld1q_dup_u8(above - 1), l0, 15); + + d0_lo = vrhaddq_u8(az, a0); + d0_hi = vrhaddq_u8(a15, a16); + d1_lo = vrhaddq_u8(vhaddq_u8(l0az, a0), az); + d1_hi = vrhaddq_u8(vhaddq_u8(a14, a16), a15); + + // The last lane of col0_hi is unused here. + col0_lo = vrhaddq_u8(vhaddq_u8(azl0, l1), l0); + col0_hi = vrhaddq_u8(vhaddq_u8(l15, l17), l16); + + col0_lo = vrev64q_u8(vextq_u8(col0_lo, col0_lo, 8)); + col0_hi = vrev64q_u8(vextq_u8(col0_hi, col0_hi, 8)); + + // The first lane of these are unused since they are only ever called as + // ext(col0, _, i) where i >= 1. + col0_even = vuzpq_u8(col0_hi, col0_lo).val[1]; + col0_odd = vuzpq_u8(col0_hi, col0_lo).val[0]; + + vst1q_u8(dst + 0 * stride + 0, d0_lo); + vst1q_u8(dst + 0 * stride + 16, d0_hi); + vst1q_u8(dst + 1 * stride + 0, d1_lo); + vst1q_u8(dst + 1 * stride + 16, d1_hi); + vst1q_u8(dst + 2 * stride + 0, vextq_u8(col0_even, d0_lo, 15)); + vst1q_u8(dst + 2 * stride + 16, vextq_u8(d0_lo, d0_hi, 15)); + vst1q_u8(dst + 3 * stride + 0, vextq_u8(col0_odd, d1_lo, 15)); + vst1q_u8(dst + 3 * stride + 16, vextq_u8(d1_lo, d1_hi, 15)); + vst1q_u8(dst + 4 * stride + 0, vextq_u8(col0_even, d0_lo, 14)); + vst1q_u8(dst + 4 * stride + 16, vextq_u8(d0_lo, d0_hi, 14)); + vst1q_u8(dst + 5 * stride + 0, vextq_u8(col0_odd, d1_lo, 14)); + vst1q_u8(dst + 5 * stride + 16, vextq_u8(d1_lo, d1_hi, 14)); + vst1q_u8(dst + 6 * stride + 0, vextq_u8(col0_even, d0_lo, 13)); + vst1q_u8(dst + 6 * stride + 16, vextq_u8(d0_lo, d0_hi, 13)); + vst1q_u8(dst + 7 * stride + 0, vextq_u8(col0_odd, d1_lo, 13)); + vst1q_u8(dst + 7 * stride + 16, vextq_u8(d1_lo, d1_hi, 13)); + vst1q_u8(dst + 8 * stride + 0, vextq_u8(col0_even, d0_lo, 12)); + vst1q_u8(dst + 8 * stride + 16, vextq_u8(d0_lo, d0_hi, 12)); + vst1q_u8(dst + 9 * stride + 0, vextq_u8(col0_odd, d1_lo, 12)); + vst1q_u8(dst + 9 * stride + 16, vextq_u8(d1_lo, d1_hi, 12)); + vst1q_u8(dst + 10 * stride + 0, vextq_u8(col0_even, d0_lo, 11)); + vst1q_u8(dst + 10 * stride + 16, vextq_u8(d0_lo, d0_hi, 11)); + vst1q_u8(dst + 11 * stride + 0, vextq_u8(col0_odd, d1_lo, 11)); + vst1q_u8(dst + 11 * stride + 16, vextq_u8(d1_lo, d1_hi, 11)); + vst1q_u8(dst + 12 * stride + 0, vextq_u8(col0_even, d0_lo, 10)); + vst1q_u8(dst + 12 * stride + 16, vextq_u8(d0_lo, d0_hi, 10)); + vst1q_u8(dst + 13 * stride + 0, vextq_u8(col0_odd, d1_lo, 10)); + vst1q_u8(dst + 13 * stride + 16, vextq_u8(d1_lo, d1_hi, 10)); + vst1q_u8(dst + 14 * stride + 0, vextq_u8(col0_even, d0_lo, 9)); + vst1q_u8(dst + 14 * stride + 16, vextq_u8(d0_lo, d0_hi, 9)); + vst1q_u8(dst + 15 * stride + 0, vextq_u8(col0_odd, d1_lo, 9)); + vst1q_u8(dst + 15 * stride + 16, vextq_u8(d1_lo, d1_hi, 9)); + vst1q_u8(dst + 16 * stride + 0, vextq_u8(col0_even, d0_lo, 8)); + vst1q_u8(dst + 16 * stride + 16, vextq_u8(d0_lo, d0_hi, 8)); + vst1q_u8(dst + 17 * stride + 0, vextq_u8(col0_odd, d1_lo, 8)); + vst1q_u8(dst + 17 * stride + 16, vextq_u8(d1_lo, d1_hi, 8)); + vst1q_u8(dst + 18 * stride + 0, vextq_u8(col0_even, d0_lo, 7)); + vst1q_u8(dst + 18 * stride + 16, vextq_u8(d0_lo, d0_hi, 7)); + vst1q_u8(dst + 19 * stride + 0, vextq_u8(col0_odd, d1_lo, 7)); + vst1q_u8(dst + 19 * stride + 16, vextq_u8(d1_lo, d1_hi, 7)); + vst1q_u8(dst + 20 * stride + 0, vextq_u8(col0_even, d0_lo, 6)); + vst1q_u8(dst + 20 * stride + 16, vextq_u8(d0_lo, d0_hi, 6)); + vst1q_u8(dst + 21 * stride + 0, vextq_u8(col0_odd, d1_lo, 6)); + vst1q_u8(dst + 21 * stride + 16, vextq_u8(d1_lo, d1_hi, 6)); + vst1q_u8(dst + 22 * stride + 0, vextq_u8(col0_even, d0_lo, 5)); + vst1q_u8(dst + 22 * stride + 16, vextq_u8(d0_lo, d0_hi, 5)); + vst1q_u8(dst + 23 * stride + 0, vextq_u8(col0_odd, d1_lo, 5)); + vst1q_u8(dst + 23 * stride + 16, vextq_u8(d1_lo, d1_hi, 5)); + vst1q_u8(dst + 24 * stride + 0, vextq_u8(col0_even, d0_lo, 4)); + vst1q_u8(dst + 24 * stride + 16, vextq_u8(d0_lo, d0_hi, 4)); + vst1q_u8(dst + 25 * stride + 0, vextq_u8(col0_odd, d1_lo, 4)); + vst1q_u8(dst + 25 * stride + 16, vextq_u8(d1_lo, d1_hi, 4)); + vst1q_u8(dst + 26 * stride + 0, vextq_u8(col0_even, d0_lo, 3)); + vst1q_u8(dst + 26 * stride + 16, vextq_u8(d0_lo, d0_hi, 3)); + vst1q_u8(dst + 27 * stride + 0, vextq_u8(col0_odd, d1_lo, 3)); + vst1q_u8(dst + 27 * stride + 16, vextq_u8(d1_lo, d1_hi, 3)); + vst1q_u8(dst + 28 * stride + 0, vextq_u8(col0_even, d0_lo, 2)); + vst1q_u8(dst + 28 * stride + 16, vextq_u8(d0_lo, d0_hi, 2)); + vst1q_u8(dst + 29 * stride + 0, vextq_u8(col0_odd, d1_lo, 2)); + vst1q_u8(dst + 29 * stride + 16, vextq_u8(d1_lo, d1_hi, 2)); + vst1q_u8(dst + 30 * stride + 0, vextq_u8(col0_even, d0_lo, 1)); + vst1q_u8(dst + 30 * stride + 16, vextq_u8(d0_lo, d0_hi, 1)); + vst1q_u8(dst + 31 * stride + 0, vextq_u8(col0_odd, d1_lo, 1)); + vst1q_u8(dst + 31 * stride + 16, vextq_u8(d1_lo, d1_hi, 1)); } // ----------------------------------------------------------------------------- @@ -390,22 +866,14 @@ void vpx_d135_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, const uint8x8_t L3210 = vrev64_u8(L0123); const uint8x8_t L3210XA012 = vext_u8(L3210, XA0123, 4); const uint8x8_t L210XA0123 = vext_u8(L3210, XA0123, 5); - const uint8x8_t L10XA0123_ = - vreinterpret_u8_u64(vshr_n_u64(vreinterpret_u64_u8(L210XA0123), 8)); + const uint8x8_t L10XA0123_ = vext_u8(L210XA0123, L210XA0123, 1); const uint8x8_t avg1 = vhadd_u8(L10XA0123_, L3210XA012); const uint8x8_t avg2 = vrhadd_u8(avg1, L210XA0123); - const uint64x1_t avg2_u64 = vreinterpret_u64_u8(avg2); - const uint32x2_t r3 = vreinterpret_u32_u8(avg2); - const uint32x2_t r2 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 8)); - const uint32x2_t r1 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 16)); - const uint32x2_t r0 = vreinterpret_u32_u64(vshr_n_u64(avg2_u64, 24)); - vst1_lane_u32((uint32_t *)dst, r0, 0); - dst += stride; - vst1_lane_u32((uint32_t *)dst, r1, 0); - dst += stride; - vst1_lane_u32((uint32_t *)dst, r2, 0); - dst += stride; - vst1_lane_u32((uint32_t *)dst, r3, 0); + + store_u8_4x1(dst + 0 * stride, vext_u8(avg2, avg2, 3)); + store_u8_4x1(dst + 1 * stride, vext_u8(avg2, avg2, 2)); + store_u8_4x1(dst + 2 * stride, vext_u8(avg2, avg2, 1)); + store_u8_4x1(dst + 3 * stride, avg2); } void vpx_d135_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, @@ -422,31 +890,15 @@ void vpx_d135_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, const uint8x16_t L543210XA01234567_ = vcombine_u8(L543210XA0, A1234567_); const uint8x16_t avg = vhaddq_u8(L76543210XA0123456, L543210XA01234567_); const uint8x16_t row = vrhaddq_u8(avg, L6543210XA01234567); - const uint8x8_t row_0 = vget_low_u8(row); - const uint8x8_t row_1 = vget_high_u8(row); - const uint8x8_t r0 = vext_u8(row_0, row_1, 7); - const uint8x8_t r1 = vext_u8(row_0, row_1, 6); - const uint8x8_t r2 = vext_u8(row_0, row_1, 5); - const uint8x8_t r3 = vext_u8(row_0, row_1, 4); - const uint8x8_t r4 = vext_u8(row_0, row_1, 3); - const uint8x8_t r5 = vext_u8(row_0, row_1, 2); - const uint8x8_t r6 = vext_u8(row_0, row_1, 1); - vst1_u8(dst, r0); - dst += stride; - vst1_u8(dst, r1); - dst += stride; - vst1_u8(dst, r2); - dst += stride; - vst1_u8(dst, r3); - dst += stride; - vst1_u8(dst, r4); - dst += stride; - vst1_u8(dst, r5); - dst += stride; - vst1_u8(dst, r6); - dst += stride; - vst1_u8(dst, row_0); + vst1_u8(dst + 0 * stride, vget_low_u8(vextq_u8(row, row, 7))); + vst1_u8(dst + 1 * stride, vget_low_u8(vextq_u8(row, row, 6))); + vst1_u8(dst + 2 * stride, vget_low_u8(vextq_u8(row, row, 5))); + vst1_u8(dst + 3 * stride, vget_low_u8(vextq_u8(row, row, 4))); + vst1_u8(dst + 4 * stride, vget_low_u8(vextq_u8(row, row, 3))); + vst1_u8(dst + 5 * stride, vget_low_u8(vextq_u8(row, row, 2))); + vst1_u8(dst + 6 * stride, vget_low_u8(vextq_u8(row, row, 1))); + vst1_u8(dst + 7 * stride, vget_low_u8(row)); } static INLINE void d135_store_16x8( @@ -489,6 +941,7 @@ void vpx_d135_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, const uint8x16_t avg_1 = vhaddq_u8(XA0123456789abcde, A123456789abcdef_); const uint8x16_t row_0 = vrhaddq_u8(avg_0, Ledcba9876543210X); const uint8x16_t row_1 = vrhaddq_u8(avg_1, A0123456789abcdef); + const uint8x16_t r_0 = vextq_u8(row_0, row_1, 15); const uint8x16_t r_1 = vextq_u8(row_0, row_1, 14); const uint8x16_t r_2 = vextq_u8(row_0, row_1, 13); @@ -496,7 +949,7 @@ void vpx_d135_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, const uint8x16_t r_4 = vextq_u8(row_0, row_1, 11); const uint8x16_t r_5 = vextq_u8(row_0, row_1, 10); const uint8x16_t r_6 = vextq_u8(row_0, row_1, 9); - const uint8x16_t r_7 = vcombine_u8(vget_high_u8(row_0), vget_low_u8(row_1)); + const uint8x16_t r_7 = vextq_u8(row_0, row_1, 8); const uint8x16_t r_8 = vextq_u8(row_0, row_1, 7); const uint8x16_t r_9 = vextq_u8(row_0, row_1, 6); const uint8x16_t r_a = vextq_u8(row_0, row_1, 5); @@ -667,6 +1120,454 @@ void vpx_d135_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, d135_store_32x2(&dst, stride, row_0, row_1, row_2); } +// ----------------------------------------------------------------------------- + +void vpx_d153_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + // See vpx_d153_predictor_8x8_neon for more details on the implementation. + uint8x8_t az, a0, l0az, l0, l1, azl0, d0, d1, d2, d02; + + az = load_unaligned_u8_4x1(above - 1); + a0 = load_unaligned_u8_4x1(above + 0); + // [ left[0], above[-1], above[0], above[1], x, x, x, x ] + l0az = vext_u8(vld1_dup_u8(left), az, 7); + + l0 = load_unaligned_u8_4x1(left + 0); + l1 = load_unaligned_u8_4x1(left + 1); + // [ above[-1], left[0], left[1], left[2], x, x, x, x ] + azl0 = vext_u8(vld1_dup_u8(above - 1), l0, 7); + + d0 = vrhadd_u8(azl0, l0); + d1 = vrhadd_u8(vhadd_u8(l0az, a0), az); + d2 = vrhadd_u8(vhadd_u8(azl0, l1), l0); + + d02 = vrev64_u8(vzip_u8(d0, d2).val[0]); + + store_u8_4x1(dst + 0 * stride, vext_u8(d02, d1, 7)); + store_u8_4x1(dst + 1 * stride, vext_u8(d02, d1, 5)); + store_u8_4x1(dst + 2 * stride, vext_u8(d02, d1, 3)); + store_u8_4x1(dst + 3 * stride, vext_u8(d02, d1, 1)); +} + +void vpx_d153_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + uint8x8_t az, a0, l0az, l0, l1, azl0, d0, d1, d2, d02_lo, d02_hi; + + az = vld1_u8(above - 1); + a0 = vld1_u8(above + 0); + // [ left[0], above[-1], ... , above[5] ] + l0az = vext_u8(vld1_dup_u8(left), az, 7); + + l0 = vld1_u8(left); + // The last lane here is unused, reading left[8] could cause a buffer + // over-read, so just fill with a duplicate of left[0] to avoid needing to + // materialize a zero: + // [ left[1], ... , left[7], x ] + l1 = vext_u8(l0, l0, 1); + // [ above[-1], left[0], ... , left[6] ] + azl0 = vext_u8(vld1_dup_u8(above - 1), l0, 7); + + // d0[0] = AVG2(above[-1], left[0]) + // d0[1] = AVG2(left[0], left[1]) + // ... + // d0[7] = AVG2(left[6], left[7]) + d0 = vrhadd_u8(azl0, l0); + + // d1[0] = AVG3(left[0], above[-1], above[0]) + // d1[1] = AVG3(above[-1], above[0], above[1]) + // ... + // d1[7] = AVG3(above[5], above[6], above[7]) + d1 = vrhadd_u8(vhadd_u8(l0az, a0), az); + + // d2[0] = AVG3(above[-1], left[0], left[1]) + // d2[1] = AVG3(left[0], left[1], left[2]) + // ... + // d2[6] = AVG3(left[5], left[6], left[7]) + // d2[7] = x (don't care) + d2 = vrhadd_u8(vhadd_u8(azl0, l1), l0); + + // The ext instruction shifts elements in from the end of the vector rather + // than the start, so reverse the vectors to put the elements to be shifted + // in at the end. The lowest lane of d02_lo is unused. + d02_lo = vzip_u8(vrev64_u8(d2), vrev64_u8(d0)).val[0]; + d02_hi = vzip_u8(vrev64_u8(d2), vrev64_u8(d0)).val[1]; + + // Incrementally shift more elements from d0/d2 reversed into d1: + // stride=0 [ d0[0], d1[0], d1[1], d1[2], d1[3], d1[4], d1[5], d1[6] ] + // stride=1 [ d0[1], d2[0], d0[0], d1[0], d1[1], d1[2], d1[3], d1[4] ] + // stride=2 [ d0[2], d2[1], d0[1], d2[0], d0[0], d1[0], d1[1], d1[2] ] + // stride=3 [ d0[3], d2[2], d0[2], d2[1], d0[1], d2[0], d0[0], d1[0] ] + // stride=4 [ d0[4], d2[3], d0[3], d2[2], d0[2], d2[1], d0[1], d2[0] ] + // stride=5 [ d0[5], d2[4], d0[4], d2[3], d0[3], d2[2], d0[2], d2[1] ] + // stride=6 [ d0[6], d2[5], d0[5], d2[4], d0[4], d2[3], d0[3], d2[2] ] + // stride=7 [ d0[7], d2[6], d0[6], d2[5], d0[5], d2[4], d0[4], d2[3] ] + vst1_u8(dst + 0 * stride, vext_u8(d02_hi, d1, 7)); + vst1_u8(dst + 1 * stride, vext_u8(d02_hi, d1, 5)); + vst1_u8(dst + 2 * stride, vext_u8(d02_hi, d1, 3)); + vst1_u8(dst + 3 * stride, vext_u8(d02_hi, d1, 1)); + vst1_u8(dst + 4 * stride, vext_u8(d02_lo, d02_hi, 7)); + vst1_u8(dst + 5 * stride, vext_u8(d02_lo, d02_hi, 5)); + vst1_u8(dst + 6 * stride, vext_u8(d02_lo, d02_hi, 3)); + vst1_u8(dst + 7 * stride, vext_u8(d02_lo, d02_hi, 1)); +} + +void vpx_d153_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + // See vpx_d153_predictor_8x8_neon for more details on the implementation. + uint8x16_t az, a0, l0az, l0, l1, azl0, d0, d1, d2, d02_lo, d02_hi; + + az = vld1q_u8(above - 1); + a0 = vld1q_u8(above + 0); + // [ left[0], above[-1], ... , above[13] ] + l0az = vextq_u8(vld1q_dup_u8(left), az, 15); + + l0 = vld1q_u8(left + 0); + // The last lane here is unused, reading left[16] could cause a buffer + // over-read, so just fill with a duplicate of left[0] to avoid needing to + // materialize a zero: + // [ left[1], ... , left[15], x ] + l1 = vextq_u8(l0, l0, 1); + // [ above[-1], left[0], ... , left[14] ] + azl0 = vextq_u8(vld1q_dup_u8(above - 1), l0, 15); + + d0 = vrhaddq_u8(azl0, l0); + d1 = vrhaddq_u8(vhaddq_u8(l0az, a0), az); + d2 = vrhaddq_u8(vhaddq_u8(azl0, l1), l0); + + d0 = vrev64q_u8(vextq_u8(d0, d0, 8)); + d2 = vrev64q_u8(vextq_u8(d2, d2, 8)); + + // The lowest lane of d02_lo is unused. + d02_lo = vzipq_u8(d2, d0).val[0]; + d02_hi = vzipq_u8(d2, d0).val[1]; + + vst1q_u8(dst + 0 * stride, vextq_u8(d02_hi, d1, 15)); + vst1q_u8(dst + 1 * stride, vextq_u8(d02_hi, d1, 13)); + vst1q_u8(dst + 2 * stride, vextq_u8(d02_hi, d1, 11)); + vst1q_u8(dst + 3 * stride, vextq_u8(d02_hi, d1, 9)); + vst1q_u8(dst + 4 * stride, vextq_u8(d02_hi, d1, 7)); + vst1q_u8(dst + 5 * stride, vextq_u8(d02_hi, d1, 5)); + vst1q_u8(dst + 6 * stride, vextq_u8(d02_hi, d1, 3)); + vst1q_u8(dst + 7 * stride, vextq_u8(d02_hi, d1, 1)); + vst1q_u8(dst + 8 * stride, vextq_u8(d02_lo, d02_hi, 15)); + vst1q_u8(dst + 9 * stride, vextq_u8(d02_lo, d02_hi, 13)); + vst1q_u8(dst + 10 * stride, vextq_u8(d02_lo, d02_hi, 11)); + vst1q_u8(dst + 11 * stride, vextq_u8(d02_lo, d02_hi, 9)); + vst1q_u8(dst + 12 * stride, vextq_u8(d02_lo, d02_hi, 7)); + vst1q_u8(dst + 13 * stride, vextq_u8(d02_lo, d02_hi, 5)); + vst1q_u8(dst + 14 * stride, vextq_u8(d02_lo, d02_hi, 3)); + vst1q_u8(dst + 15 * stride, vextq_u8(d02_lo, d02_hi, 1)); +} + +void vpx_d153_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + // See vpx_d153_predictor_8x8_neon for more details on the implementation. + uint8x16_t az, a0, a14, a15, a16, l0az, l0, l1, l15, l16, l17, azl0, d0_lo, + d0_hi, d1_lo, d1_hi, d2_lo, d2_hi; + uint8x16x2_t d02_hi, d02_lo; + + az = vld1q_u8(above - 1); + a0 = vld1q_u8(above + 0); + a14 = vld1q_u8(above + 14); + a15 = vld1q_u8(above + 15); + a16 = vld1q_u8(above + 16); + // [ left[0], above[-1], ... , above[13] ] + l0az = vextq_u8(vld1q_dup_u8(left), az, 15); + + l0 = vld1q_u8(left); + l1 = vld1q_u8(left + 1); + l15 = vld1q_u8(left + 15); + l16 = vld1q_u8(left + 16); + // The last lane here is unused, reading left[32] would cause a buffer + // over-read (observed as an address-sanitizer failure), so just fill with a + // duplicate of left[16] to avoid needing to materialize a zero: + // [ left[17], ... , left[31], x ] + l17 = vextq_u8(l16, l16, 1); + // [ above[-1], left[0], ... , left[14] ] + azl0 = vextq_u8(vld1q_dup_u8(above - 1), l0, 15); + + d0_lo = vrhaddq_u8(azl0, l0); + d0_hi = vrhaddq_u8(l15, l16); + + d1_lo = vrhaddq_u8(vhaddq_u8(l0az, a0), az); + d1_hi = vrhaddq_u8(vhaddq_u8(a14, a16), a15); + + // The highest lane of d2_hi is unused. + d2_lo = vrhaddq_u8(vhaddq_u8(azl0, l1), l0); + d2_hi = vrhaddq_u8(vhaddq_u8(l15, l17), l16); + + d0_lo = vrev64q_u8(vextq_u8(d0_lo, d0_lo, 8)); + d0_hi = vrev64q_u8(vextq_u8(d0_hi, d0_hi, 8)); + + d2_lo = vrev64q_u8(vextq_u8(d2_lo, d2_lo, 8)); + d2_hi = vrev64q_u8(vextq_u8(d2_hi, d2_hi, 8)); + + // d02_hi.val[0][0] is unused here. + d02_hi = vzipq_u8(d2_hi, d0_hi); + d02_lo = vzipq_u8(d2_lo, d0_lo); + + vst1q_u8(dst + 0 * stride + 0, vextq_u8(d02_lo.val[1], d1_lo, 15)); + vst1q_u8(dst + 0 * stride + 16, vextq_u8(d1_lo, d1_hi, 15)); + vst1q_u8(dst + 1 * stride + 0, vextq_u8(d02_lo.val[1], d1_lo, 13)); + vst1q_u8(dst + 1 * stride + 16, vextq_u8(d1_lo, d1_hi, 13)); + vst1q_u8(dst + 2 * stride + 0, vextq_u8(d02_lo.val[1], d1_lo, 11)); + vst1q_u8(dst + 2 * stride + 16, vextq_u8(d1_lo, d1_hi, 11)); + vst1q_u8(dst + 3 * stride + 0, vextq_u8(d02_lo.val[1], d1_lo, 9)); + vst1q_u8(dst + 3 * stride + 16, vextq_u8(d1_lo, d1_hi, 9)); + vst1q_u8(dst + 4 * stride + 0, vextq_u8(d02_lo.val[1], d1_lo, 7)); + vst1q_u8(dst + 4 * stride + 16, vextq_u8(d1_lo, d1_hi, 7)); + vst1q_u8(dst + 5 * stride + 0, vextq_u8(d02_lo.val[1], d1_lo, 5)); + vst1q_u8(dst + 5 * stride + 16, vextq_u8(d1_lo, d1_hi, 5)); + vst1q_u8(dst + 6 * stride + 0, vextq_u8(d02_lo.val[1], d1_lo, 3)); + vst1q_u8(dst + 6 * stride + 16, vextq_u8(d1_lo, d1_hi, 3)); + vst1q_u8(dst + 7 * stride + 0, vextq_u8(d02_lo.val[1], d1_lo, 1)); + vst1q_u8(dst + 7 * stride + 16, vextq_u8(d1_lo, d1_hi, 1)); + vst1q_u8(dst + 8 * stride + 0, vextq_u8(d02_lo.val[0], d02_lo.val[1], 15)); + vst1q_u8(dst + 8 * stride + 16, vextq_u8(d02_lo.val[1], d1_lo, 15)); + vst1q_u8(dst + 9 * stride + 0, vextq_u8(d02_lo.val[0], d02_lo.val[1], 13)); + vst1q_u8(dst + 9 * stride + 16, vextq_u8(d02_lo.val[1], d1_lo, 13)); + vst1q_u8(dst + 10 * stride + 0, vextq_u8(d02_lo.val[0], d02_lo.val[1], 11)); + vst1q_u8(dst + 10 * stride + 16, vextq_u8(d02_lo.val[1], d1_lo, 11)); + vst1q_u8(dst + 11 * stride + 0, vextq_u8(d02_lo.val[0], d02_lo.val[1], 9)); + vst1q_u8(dst + 11 * stride + 16, vextq_u8(d02_lo.val[1], d1_lo, 9)); + vst1q_u8(dst + 12 * stride + 0, vextq_u8(d02_lo.val[0], d02_lo.val[1], 7)); + vst1q_u8(dst + 12 * stride + 16, vextq_u8(d02_lo.val[1], d1_lo, 7)); + vst1q_u8(dst + 13 * stride + 0, vextq_u8(d02_lo.val[0], d02_lo.val[1], 5)); + vst1q_u8(dst + 13 * stride + 16, vextq_u8(d02_lo.val[1], d1_lo, 5)); + vst1q_u8(dst + 14 * stride + 0, vextq_u8(d02_lo.val[0], d02_lo.val[1], 3)); + vst1q_u8(dst + 14 * stride + 16, vextq_u8(d02_lo.val[1], d1_lo, 3)); + vst1q_u8(dst + 15 * stride + 0, vextq_u8(d02_lo.val[0], d02_lo.val[1], 1)); + vst1q_u8(dst + 15 * stride + 16, vextq_u8(d02_lo.val[1], d1_lo, 1)); + vst1q_u8(dst + 16 * stride + 0, vextq_u8(d02_hi.val[1], d02_lo.val[0], 15)); + vst1q_u8(dst + 16 * stride + 16, vextq_u8(d02_lo.val[0], d02_lo.val[1], 15)); + vst1q_u8(dst + 17 * stride + 0, vextq_u8(d02_hi.val[1], d02_lo.val[0], 13)); + vst1q_u8(dst + 17 * stride + 16, vextq_u8(d02_lo.val[0], d02_lo.val[1], 13)); + vst1q_u8(dst + 18 * stride + 0, vextq_u8(d02_hi.val[1], d02_lo.val[0], 11)); + vst1q_u8(dst + 18 * stride + 16, vextq_u8(d02_lo.val[0], d02_lo.val[1], 11)); + vst1q_u8(dst + 19 * stride + 0, vextq_u8(d02_hi.val[1], d02_lo.val[0], 9)); + vst1q_u8(dst + 19 * stride + 16, vextq_u8(d02_lo.val[0], d02_lo.val[1], 9)); + vst1q_u8(dst + 20 * stride + 0, vextq_u8(d02_hi.val[1], d02_lo.val[0], 7)); + vst1q_u8(dst + 20 * stride + 16, vextq_u8(d02_lo.val[0], d02_lo.val[1], 7)); + vst1q_u8(dst + 21 * stride + 0, vextq_u8(d02_hi.val[1], d02_lo.val[0], 5)); + vst1q_u8(dst + 21 * stride + 16, vextq_u8(d02_lo.val[0], d02_lo.val[1], 5)); + vst1q_u8(dst + 22 * stride + 0, vextq_u8(d02_hi.val[1], d02_lo.val[0], 3)); + vst1q_u8(dst + 22 * stride + 16, vextq_u8(d02_lo.val[0], d02_lo.val[1], 3)); + vst1q_u8(dst + 23 * stride + 0, vextq_u8(d02_hi.val[1], d02_lo.val[0], 1)); + vst1q_u8(dst + 23 * stride + 16, vextq_u8(d02_lo.val[0], d02_lo.val[1], 1)); + vst1q_u8(dst + 24 * stride + 0, vextq_u8(d02_hi.val[0], d02_hi.val[1], 15)); + vst1q_u8(dst + 24 * stride + 16, vextq_u8(d02_hi.val[1], d02_lo.val[0], 15)); + vst1q_u8(dst + 25 * stride + 0, vextq_u8(d02_hi.val[0], d02_hi.val[1], 13)); + vst1q_u8(dst + 25 * stride + 16, vextq_u8(d02_hi.val[1], d02_lo.val[0], 13)); + vst1q_u8(dst + 26 * stride + 0, vextq_u8(d02_hi.val[0], d02_hi.val[1], 11)); + vst1q_u8(dst + 26 * stride + 16, vextq_u8(d02_hi.val[1], d02_lo.val[0], 11)); + vst1q_u8(dst + 27 * stride + 0, vextq_u8(d02_hi.val[0], d02_hi.val[1], 9)); + vst1q_u8(dst + 27 * stride + 16, vextq_u8(d02_hi.val[1], d02_lo.val[0], 9)); + vst1q_u8(dst + 28 * stride + 0, vextq_u8(d02_hi.val[0], d02_hi.val[1], 7)); + vst1q_u8(dst + 28 * stride + 16, vextq_u8(d02_hi.val[1], d02_lo.val[0], 7)); + vst1q_u8(dst + 29 * stride + 0, vextq_u8(d02_hi.val[0], d02_hi.val[1], 5)); + vst1q_u8(dst + 29 * stride + 16, vextq_u8(d02_hi.val[1], d02_lo.val[0], 5)); + vst1q_u8(dst + 30 * stride + 0, vextq_u8(d02_hi.val[0], d02_hi.val[1], 3)); + vst1q_u8(dst + 30 * stride + 16, vextq_u8(d02_hi.val[1], d02_lo.val[0], 3)); + vst1q_u8(dst + 31 * stride + 0, vextq_u8(d02_hi.val[0], d02_hi.val[1], 1)); + vst1q_u8(dst + 31 * stride + 16, vextq_u8(d02_hi.val[1], d02_lo.val[0], 1)); +} + +// ----------------------------------------------------------------------------- + +void vpx_d207_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + uint8x8_t l0, l3, l1, l2, c0, c1, c01, d0, d1; + (void)above; + + // We need the low half lanes here for the c0/c1 arithmetic but the high half + // lanes for the ext: + // [ left[0], left[1], left[2], left[3], left[0], left[1], left[2], left[3] ] + l0 = load_replicate_u8_4x1(left + 0); + l3 = vld1_dup_u8(left + 3); + + // [ left[1], left[2], left[3], left[3], x, x, x, x ] + l1 = vext_u8(l0, l3, 5); + // [ left[2], left[3], left[3], left[3], x, x, x, x ] + l2 = vext_u8(l0, l3, 6); + + c0 = vrhadd_u8(l0, l1); + c1 = vrhadd_u8(vhadd_u8(l0, l2), l1); + + // [ c0[0], c1[0], c0[1], c1[1], c0[2], c1[2], c0[3], c1[3] ] + c01 = vzip_u8(c0, c1).val[0]; + + d0 = c01; + d1 = vext_u8(c01, l3, 2); + + // Store the high half of the vector for stride={2,3} to avoid needing + // additional ext instructions: + // stride=0 [ c0[0], c1[0], c0[1], c1[1] ] + // stride=1 [ c0[1], c1[1], c0[2], c1[2] ] + // stride=2 [ c0[2], c1[2], c0[3], c1[3] ] + // stride=3 [ c0[3], c1[3], left[3], left[3] ] + store_u8_4x1(dst + 0 * stride, d0); + store_u8_4x1(dst + 1 * stride, d1); + store_u8_4x1_high(dst + 2 * stride, d0); + store_u8_4x1_high(dst + 3 * stride, d1); +} + +void vpx_d207_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + uint8x8_t l7, l0, l1, l2, c0, c1, c01_lo, c01_hi; + (void)above; + + l0 = vld1_u8(left + 0); + l7 = vld1_dup_u8(left + 7); + + // [ left[1], left[2], left[3], left[4], left[5], left[6], left[7], left[7] ] + l1 = vext_u8(l0, l7, 1); + // [ left[2], left[3], left[4], left[5], left[6], left[7], left[7], left[7] ] + l2 = vext_u8(l0, l7, 2); + + c0 = vrhadd_u8(l0, l1); + c1 = vrhadd_u8(vhadd_u8(l0, l2), l1); + + c01_lo = vzip_u8(c0, c1).val[0]; + c01_hi = vzip_u8(c0, c1).val[1]; + + vst1_u8(dst + 0 * stride, c01_lo); + vst1_u8(dst + 1 * stride, vext_u8(c01_lo, c01_hi, 2)); + vst1_u8(dst + 2 * stride, vext_u8(c01_lo, c01_hi, 4)); + vst1_u8(dst + 3 * stride, vext_u8(c01_lo, c01_hi, 6)); + vst1_u8(dst + 4 * stride, c01_hi); + vst1_u8(dst + 5 * stride, vext_u8(c01_hi, l7, 2)); + vst1_u8(dst + 6 * stride, vext_u8(c01_hi, l7, 4)); + vst1_u8(dst + 7 * stride, vext_u8(c01_hi, l7, 6)); +} + +void vpx_d207_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + uint8x16_t l15, l0, l1, l2, c0, c1, c01_lo, c01_hi; + (void)above; + + l0 = vld1q_u8(left + 0); + l15 = vld1q_dup_u8(left + 15); + + l1 = vextq_u8(l0, l15, 1); + l2 = vextq_u8(l0, l15, 2); + + c0 = vrhaddq_u8(l0, l1); + c1 = vrhaddq_u8(vhaddq_u8(l0, l2), l1); + + c01_lo = vzipq_u8(c0, c1).val[0]; + c01_hi = vzipq_u8(c0, c1).val[1]; + + vst1q_u8(dst + 0 * stride, c01_lo); + vst1q_u8(dst + 1 * stride, vextq_u8(c01_lo, c01_hi, 2)); + vst1q_u8(dst + 2 * stride, vextq_u8(c01_lo, c01_hi, 4)); + vst1q_u8(dst + 3 * stride, vextq_u8(c01_lo, c01_hi, 6)); + vst1q_u8(dst + 4 * stride, vextq_u8(c01_lo, c01_hi, 8)); + vst1q_u8(dst + 5 * stride, vextq_u8(c01_lo, c01_hi, 10)); + vst1q_u8(dst + 6 * stride, vextq_u8(c01_lo, c01_hi, 12)); + vst1q_u8(dst + 7 * stride, vextq_u8(c01_lo, c01_hi, 14)); + vst1q_u8(dst + 8 * stride, c01_hi); + vst1q_u8(dst + 9 * stride, vextq_u8(c01_hi, l15, 2)); + vst1q_u8(dst + 10 * stride, vextq_u8(c01_hi, l15, 4)); + vst1q_u8(dst + 11 * stride, vextq_u8(c01_hi, l15, 6)); + vst1q_u8(dst + 12 * stride, vextq_u8(c01_hi, l15, 8)); + vst1q_u8(dst + 13 * stride, vextq_u8(c01_hi, l15, 10)); + vst1q_u8(dst + 14 * stride, vextq_u8(c01_hi, l15, 12)); + vst1q_u8(dst + 15 * stride, vextq_u8(c01_hi, l15, 14)); +} + +void vpx_d207_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, + const uint8_t *above, const uint8_t *left) { + uint8x16_t l0_lo, l0_hi, l1_lo, l1_hi, l2_lo, l2_hi, l31, c0_lo, c0_hi, c1_lo, + c1_hi, c01[4]; + (void)above; + + l0_lo = vld1q_u8(left + 0); + l0_hi = vld1q_u8(left + 16); + l31 = vld1q_dup_u8(left + 31); + + l1_lo = vextq_u8(l0_lo, l0_hi, 1); + l1_hi = vextq_u8(l0_hi, l31, 1); + l2_lo = vextq_u8(l0_lo, l0_hi, 2); + l2_hi = vextq_u8(l0_hi, l31, 2); + + c0_lo = vrhaddq_u8(l0_lo, l1_lo); + c0_hi = vrhaddq_u8(l0_hi, l1_hi); + c1_lo = vrhaddq_u8(vhaddq_u8(l0_lo, l2_lo), l1_lo); + c1_hi = vrhaddq_u8(vhaddq_u8(l0_hi, l2_hi), l1_hi); + + c01[0] = vzipq_u8(c0_lo, c1_lo).val[0]; + c01[1] = vzipq_u8(c0_lo, c1_lo).val[1]; + c01[2] = vzipq_u8(c0_hi, c1_hi).val[0]; + c01[3] = vzipq_u8(c0_hi, c1_hi).val[1]; + + vst1q_u8(dst + 0 * stride + 0, c01[0]); + vst1q_u8(dst + 0 * stride + 16, c01[1]); + vst1q_u8(dst + 1 * stride + 0, vextq_u8(c01[0], c01[1], 2)); + vst1q_u8(dst + 1 * stride + 16, vextq_u8(c01[1], c01[2], 2)); + vst1q_u8(dst + 2 * stride + 0, vextq_u8(c01[0], c01[1], 4)); + vst1q_u8(dst + 2 * stride + 16, vextq_u8(c01[1], c01[2], 4)); + vst1q_u8(dst + 3 * stride + 0, vextq_u8(c01[0], c01[1], 6)); + vst1q_u8(dst + 3 * stride + 16, vextq_u8(c01[1], c01[2], 6)); + vst1q_u8(dst + 4 * stride + 0, vextq_u8(c01[0], c01[1], 8)); + vst1q_u8(dst + 4 * stride + 16, vextq_u8(c01[1], c01[2], 8)); + vst1q_u8(dst + 5 * stride + 0, vextq_u8(c01[0], c01[1], 10)); + vst1q_u8(dst + 5 * stride + 16, vextq_u8(c01[1], c01[2], 10)); + vst1q_u8(dst + 6 * stride + 0, vextq_u8(c01[0], c01[1], 12)); + vst1q_u8(dst + 6 * stride + 16, vextq_u8(c01[1], c01[2], 12)); + vst1q_u8(dst + 7 * stride + 0, vextq_u8(c01[0], c01[1], 14)); + vst1q_u8(dst + 7 * stride + 16, vextq_u8(c01[1], c01[2], 14)); + vst1q_u8(dst + 8 * stride + 0, c01[1]); + vst1q_u8(dst + 8 * stride + 16, c01[2]); + vst1q_u8(dst + 9 * stride + 0, vextq_u8(c01[1], c01[2], 2)); + vst1q_u8(dst + 9 * stride + 16, vextq_u8(c01[2], c01[3], 2)); + vst1q_u8(dst + 10 * stride + 0, vextq_u8(c01[1], c01[2], 4)); + vst1q_u8(dst + 10 * stride + 16, vextq_u8(c01[2], c01[3], 4)); + vst1q_u8(dst + 11 * stride + 0, vextq_u8(c01[1], c01[2], 6)); + vst1q_u8(dst + 11 * stride + 16, vextq_u8(c01[2], c01[3], 6)); + vst1q_u8(dst + 12 * stride + 0, vextq_u8(c01[1], c01[2], 8)); + vst1q_u8(dst + 12 * stride + 16, vextq_u8(c01[2], c01[3], 8)); + vst1q_u8(dst + 13 * stride + 0, vextq_u8(c01[1], c01[2], 10)); + vst1q_u8(dst + 13 * stride + 16, vextq_u8(c01[2], c01[3], 10)); + vst1q_u8(dst + 14 * stride + 0, vextq_u8(c01[1], c01[2], 12)); + vst1q_u8(dst + 14 * stride + 16, vextq_u8(c01[2], c01[3], 12)); + vst1q_u8(dst + 15 * stride + 0, vextq_u8(c01[1], c01[2], 14)); + vst1q_u8(dst + 15 * stride + 16, vextq_u8(c01[2], c01[3], 14)); + vst1q_u8(dst + 16 * stride + 0, c01[2]); + vst1q_u8(dst + 16 * stride + 16, c01[3]); + vst1q_u8(dst + 17 * stride + 0, vextq_u8(c01[2], c01[3], 2)); + vst1q_u8(dst + 17 * stride + 16, vextq_u8(c01[3], l31, 2)); + vst1q_u8(dst + 18 * stride + 0, vextq_u8(c01[2], c01[3], 4)); + vst1q_u8(dst + 18 * stride + 16, vextq_u8(c01[3], l31, 4)); + vst1q_u8(dst + 19 * stride + 0, vextq_u8(c01[2], c01[3], 6)); + vst1q_u8(dst + 19 * stride + 16, vextq_u8(c01[3], l31, 6)); + vst1q_u8(dst + 20 * stride + 0, vextq_u8(c01[2], c01[3], 8)); + vst1q_u8(dst + 20 * stride + 16, vextq_u8(c01[3], l31, 8)); + vst1q_u8(dst + 21 * stride + 0, vextq_u8(c01[2], c01[3], 10)); + vst1q_u8(dst + 21 * stride + 16, vextq_u8(c01[3], l31, 10)); + vst1q_u8(dst + 22 * stride + 0, vextq_u8(c01[2], c01[3], 12)); + vst1q_u8(dst + 22 * stride + 16, vextq_u8(c01[3], l31, 12)); + vst1q_u8(dst + 23 * stride + 0, vextq_u8(c01[2], c01[3], 14)); + vst1q_u8(dst + 23 * stride + 16, vextq_u8(c01[3], l31, 14)); + vst1q_u8(dst + 24 * stride + 0, c01[3]); + vst1q_u8(dst + 24 * stride + 16, l31); + vst1q_u8(dst + 25 * stride + 0, vextq_u8(c01[3], l31, 2)); + vst1q_u8(dst + 25 * stride + 16, l31); + vst1q_u8(dst + 26 * stride + 0, vextq_u8(c01[3], l31, 4)); + vst1q_u8(dst + 26 * stride + 16, l31); + vst1q_u8(dst + 27 * stride + 0, vextq_u8(c01[3], l31, 6)); + vst1q_u8(dst + 27 * stride + 16, l31); + vst1q_u8(dst + 28 * stride + 0, vextq_u8(c01[3], l31, 8)); + vst1q_u8(dst + 28 * stride + 16, l31); + vst1q_u8(dst + 29 * stride + 0, vextq_u8(c01[3], l31, 10)); + vst1q_u8(dst + 29 * stride + 16, l31); + vst1q_u8(dst + 30 * stride + 0, vextq_u8(c01[3], l31, 12)); + vst1q_u8(dst + 30 * stride + 16, l31); + vst1q_u8(dst + 31 * stride + 0, vextq_u8(c01[3], l31, 14)); + vst1q_u8(dst + 31 * stride + 16, l31); +} + +// ----------------------------------------------------------------------------- + #if !HAVE_NEON_ASM void vpx_v_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, @@ -871,171 +1772,195 @@ void vpx_h_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, // ----------------------------------------------------------------------------- -static INLINE int16x8_t convert_u8_to_s16(uint8x8_t v) { - return vreinterpretq_s16_u16(vmovl_u8(v)); +// Expand the first four bytes to [a a a a b b b b c c c c d d d d]. +static INLINE uint8x16_t tm_pack_4x4_neon(const uint8x8_t pixels) { + const uint8x16_t a = vcombine_u8(pixels, vdup_n_u8(0)); + const uint8x16_t aa = vzipq_u8(a, a).val[0]; + return vzipq_u8(aa, aa).val[0]; } void vpx_tm_predictor_4x4_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint8x8_t top_left = vld1_dup_u8(above - 1); - const uint8x8_t left_u8 = vld1_u8(left); - const uint8x8_t above_u8 = vld1_u8(above); - const int16x4_t left_s16 = vget_low_s16(convert_u8_to_s16(left_u8)); - int16x8_t sub, sum; - uint32x2_t d; + const uint8x16_t top_left_u8 = vld1q_dup_u8(above - 1); + const uint8x8_t above_u8 = load_unaligned_u8_4x1(above); + const uint8x8_t left_u8 = load_unaligned_u8_4x1(left); - sub = vreinterpretq_s16_u16(vsubl_u8(above_u8, top_left)); - // Avoid vcombine_s16() which generates lots of redundant code with clang-3.8. - sub = vreinterpretq_s16_s64( - vdupq_lane_s64(vreinterpret_s64_s16(vget_low_s16(sub)), 0)); + // Pack all four rows, repeating the above row and each left pixel four times. + const uint8x16_t above_dup = + vreinterpretq_u8_u32(vdupq_lane_u32(vreinterpret_u32_u8(above_u8), 0)); + const uint8x16_t left_dup = tm_pack_4x4_neon(left_u8); - sum = vcombine_s16(vdup_lane_s16(left_s16, 0), vdup_lane_s16(left_s16, 1)); - sum = vaddq_s16(sum, sub); - d = vreinterpret_u32_u8(vqmovun_s16(sum)); - vst1_lane_u32((uint32_t *)dst, d, 0); - dst += stride; - vst1_lane_u32((uint32_t *)dst, d, 1); - dst += stride; + const uint8x16_t positive = vqsubq_u8(above_dup, top_left_u8); + const uint8x16_t negative = vqsubq_u8(top_left_u8, above_dup); + const uint8x16_t result = vqsubq_u8(vqaddq_u8(left_dup, positive), negative); - sum = vcombine_s16(vdup_lane_s16(left_s16, 2), vdup_lane_s16(left_s16, 3)); - sum = vaddq_s16(sum, sub); - d = vreinterpret_u32_u8(vqmovun_s16(sum)); - vst1_lane_u32((uint32_t *)dst, d, 0); - dst += stride; - vst1_lane_u32((uint32_t *)dst, d, 1); + store_unaligned_u8q(dst, stride, result); } static INLINE void tm_8_kernel(uint8_t **dst, const ptrdiff_t stride, - const int16x8_t left_dup, const int16x8_t sub) { - const int16x8_t sum = vaddq_s16(left_dup, sub); - const uint8x8_t d = vqmovun_s16(sum); - vst1_u8(*dst, d); + const uint8x8_t left_dup, const uint8x8_t above, + const uint8x8_t top_left) { + const uint8x8_t positive = vqsub_u8(above, top_left); + const uint8x8_t negative = vqsub_u8(top_left, above); + const uint8x8_t result = vqsub_u8(vqadd_u8(left_dup, positive), negative); + vst1_u8(*dst, result); *dst += stride; } void vpx_tm_predictor_8x8_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint8x8_t top_left = vld1_dup_u8(above - 1); + const uint8x8_t top_left_u8 = vld1_dup_u8(above - 1); const uint8x8_t above_u8 = vld1_u8(above); const uint8x8_t left_u8 = vld1_u8(left); - const int16x8_t left_s16q = convert_u8_to_s16(left_u8); - const int16x8_t sub = vreinterpretq_s16_u16(vsubl_u8(above_u8, top_left)); - int16x4_t left_s16d = vget_low_s16(left_s16q); - int i; + uint8x8_t left_dup; - for (i = 0; i < 2; i++, left_s16d = vget_high_s16(left_s16q)) { - int16x8_t left_dup; - - left_dup = vdupq_lane_s16(left_s16d, 0); - tm_8_kernel(&dst, stride, left_dup, sub); - left_dup = vdupq_lane_s16(left_s16d, 1); - tm_8_kernel(&dst, stride, left_dup, sub); - left_dup = vdupq_lane_s16(left_s16d, 2); - tm_8_kernel(&dst, stride, left_dup, sub); - left_dup = vdupq_lane_s16(left_s16d, 3); - tm_8_kernel(&dst, stride, left_dup, sub); - } + left_dup = vdup_lane_u8(left_u8, 0); + tm_8_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = vdup_lane_u8(left_u8, 1); + tm_8_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = vdup_lane_u8(left_u8, 2); + tm_8_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = vdup_lane_u8(left_u8, 3); + tm_8_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = vdup_lane_u8(left_u8, 4); + tm_8_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = vdup_lane_u8(left_u8, 5); + tm_8_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = vdup_lane_u8(left_u8, 6); + tm_8_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = vdup_lane_u8(left_u8, 7); + tm_8_kernel(&dst, stride, left_dup, above_u8, top_left_u8); } +// The lane must be a compile-time constant in [0, 15]. +#if VPX_ARCH_AARCH64 +#define DUPQ_LANEQ_U8(v, lane) vdupq_laneq_u8((v), (lane)) +#else +#define DUPQ_LANEQ_U8(v, lane) \ + vdupq_lane_u8((lane) < 8 ? vget_low_u8((v)) : vget_high_u8((v)), (lane) & 7) +#endif + static INLINE void tm_16_kernel(uint8_t **dst, const ptrdiff_t stride, - const int16x8_t left_dup, const int16x8_t sub0, - const int16x8_t sub1) { - const int16x8_t sum0 = vaddq_s16(left_dup, sub0); - const int16x8_t sum1 = vaddq_s16(left_dup, sub1); - const uint8x8_t d0 = vqmovun_s16(sum0); - const uint8x8_t d1 = vqmovun_s16(sum1); - vst1_u8(*dst, d0); - *dst += 8; - vst1_u8(*dst, d1); - *dst += stride - 8; + const uint8x16_t left_dup, + const uint8x16_t above, + const uint8x16_t top_left) { + const uint8x16_t positive = vqsubq_u8(above, top_left); + const uint8x16_t negative = vqsubq_u8(top_left, above); + const uint8x16_t result = vqsubq_u8(vqaddq_u8(left_dup, positive), negative); + vst1q_u8(*dst, result); + *dst += stride; } void vpx_tm_predictor_16x16_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { - const uint8x16_t top_left = vld1q_dup_u8(above - 1); + const uint8x16_t top_left_u8 = vld1q_dup_u8(above - 1); const uint8x16_t above_u8 = vld1q_u8(above); - const int16x8_t sub0 = vreinterpretq_s16_u16( - vsubl_u8(vget_low_u8(above_u8), vget_low_u8(top_left))); - const int16x8_t sub1 = vreinterpretq_s16_u16( - vsubl_u8(vget_high_u8(above_u8), vget_high_u8(top_left))); - int16x8_t left_dup; - int i; + const uint8x16_t left_u8 = vld1q_u8(left); + uint8x16_t left_dup; - for (i = 0; i < 2; i++, left += 8) { - const uint8x8_t left_u8 = vld1_u8(left); - const int16x8_t left_s16q = convert_u8_to_s16(left_u8); - const int16x4_t left_low = vget_low_s16(left_s16q); - const int16x4_t left_high = vget_high_s16(left_s16q); + left_dup = DUPQ_LANEQ_U8(left_u8, 0); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 1); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 2); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 3); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 4); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 5); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 6); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 7); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); - left_dup = vdupq_lane_s16(left_low, 0); - tm_16_kernel(&dst, stride, left_dup, sub0, sub1); - left_dup = vdupq_lane_s16(left_low, 1); - tm_16_kernel(&dst, stride, left_dup, sub0, sub1); - left_dup = vdupq_lane_s16(left_low, 2); - tm_16_kernel(&dst, stride, left_dup, sub0, sub1); - left_dup = vdupq_lane_s16(left_low, 3); - tm_16_kernel(&dst, stride, left_dup, sub0, sub1); - - left_dup = vdupq_lane_s16(left_high, 0); - tm_16_kernel(&dst, stride, left_dup, sub0, sub1); - left_dup = vdupq_lane_s16(left_high, 1); - tm_16_kernel(&dst, stride, left_dup, sub0, sub1); - left_dup = vdupq_lane_s16(left_high, 2); - tm_16_kernel(&dst, stride, left_dup, sub0, sub1); - left_dup = vdupq_lane_s16(left_high, 3); - tm_16_kernel(&dst, stride, left_dup, sub0, sub1); - } + left_dup = DUPQ_LANEQ_U8(left_u8, 8); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 9); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 10); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 11); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 12); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 13); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 14); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); + left_dup = DUPQ_LANEQ_U8(left_u8, 15); + tm_16_kernel(&dst, stride, left_dup, above_u8, top_left_u8); } static INLINE void tm_32_kernel(uint8_t **dst, const ptrdiff_t stride, - const int16x8_t left_dup, const int16x8_t sub0, - const int16x8_t sub1, const int16x8_t sub2, - const int16x8_t sub3) { - const int16x8_t sum0 = vaddq_s16(left_dup, sub0); - const int16x8_t sum1 = vaddq_s16(left_dup, sub1); - const int16x8_t sum2 = vaddq_s16(left_dup, sub2); - const int16x8_t sum3 = vaddq_s16(left_dup, sub3); - const uint8x8_t d0 = vqmovun_s16(sum0); - const uint8x8_t d1 = vqmovun_s16(sum1); - const uint8x8_t d2 = vqmovun_s16(sum2); - const uint8x8_t d3 = vqmovun_s16(sum3); + const uint8x16_t left_dup, + const uint8x16_t above_lo, + const uint8x16_t above_hi, + const uint8x16_t top_left) { + const uint8x16_t positive_lo = vqsubq_u8(above_lo, top_left); + const uint8x16_t negative_lo = vqsubq_u8(top_left, above_lo); + const uint8x16_t result_lo = + vqsubq_u8(vqaddq_u8(left_dup, positive_lo), negative_lo); - vst1q_u8(*dst, vcombine_u8(d0, d1)); + const uint8x16_t positive_hi = vqsubq_u8(above_hi, top_left); + const uint8x16_t negative_hi = vqsubq_u8(top_left, above_hi); + const uint8x16_t result_hi = + vqsubq_u8(vqaddq_u8(left_dup, positive_hi), negative_hi); + + vst1q_u8(*dst, result_lo); *dst += 16; - vst1q_u8(*dst, vcombine_u8(d2, d3)); + + vst1q_u8(*dst, result_hi); *dst += stride - 16; } void vpx_tm_predictor_32x32_neon(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left) { const uint8x16_t top_left = vld1q_dup_u8(above - 1); - const uint8x16_t above_low = vld1q_u8(above); - const uint8x16_t above_high = vld1q_u8(above + 16); - const int16x8_t sub0 = vreinterpretq_s16_u16( - vsubl_u8(vget_low_u8(above_low), vget_low_u8(top_left))); - const int16x8_t sub1 = vreinterpretq_s16_u16( - vsubl_u8(vget_high_u8(above_low), vget_high_u8(top_left))); - const int16x8_t sub2 = vreinterpretq_s16_u16( - vsubl_u8(vget_low_u8(above_high), vget_low_u8(top_left))); - const int16x8_t sub3 = vreinterpretq_s16_u16( - vsubl_u8(vget_high_u8(above_high), vget_high_u8(top_left))); - int16x8_t left_dup; - int i, j; + const uint8x16_t above_lo = vld1q_u8(above); + const uint8x16_t above_hi = vld1q_u8(above + 16); + int i; - for (j = 0; j < 4; j++, left += 8) { - const uint8x8_t left_u8 = vld1_u8(left); - const int16x8_t left_s16q = convert_u8_to_s16(left_u8); - int16x4_t left_s16d = vget_low_s16(left_s16q); - for (i = 0; i < 2; i++, left_s16d = vget_high_s16(left_s16q)) { - left_dup = vdupq_lane_s16(left_s16d, 0); - tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3); - left_dup = vdupq_lane_s16(left_s16d, 1); - tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3); - left_dup = vdupq_lane_s16(left_s16d, 2); - tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3); - left_dup = vdupq_lane_s16(left_s16d, 3); - tm_32_kernel(&dst, stride, left_dup, sub0, sub1, sub2, sub3); - } + for (i = 0; i < 2; i++, left += 16) { + const uint8x16_t left_u8 = vld1q_u8(left); + uint8x16_t left_dup; + + left_dup = DUPQ_LANEQ_U8(left_u8, 0); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 1); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 2); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 3); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 4); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 5); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 6); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 7); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + + left_dup = DUPQ_LANEQ_U8(left_u8, 8); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 9); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 10); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 11); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 12); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 13); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 14); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); + left_dup = DUPQ_LANEQ_U8(left_u8, 15); + tm_32_kernel(&dst, stride, left_dup, above_lo, above_hi, top_left); } } +#undef DUPQ_LANEQ_U8 + #endif // !HAVE_NEON_ASM diff --git a/libs/libvpx/vpx_dsp/arm/loopfilter_neon.c b/libs/libvpx/vpx_dsp/arm/loopfilter_neon.c index c54e588239..579096d78a 100644 --- a/libs/libvpx/vpx_dsp/arm/loopfilter_neon.c +++ b/libs/libvpx/vpx_dsp/arm/loopfilter_neon.c @@ -162,7 +162,7 @@ FUN_FLIP_SIGN(16, q_) // flip_sign_16 #define FUN_FLIP_SIGN_BACK(w, r) \ static INLINE uint8x##w##_t flip_sign_back_##w(const int8x##w##_t v) { \ - const int8x##w##_t sign_bit = vdup##r##n_s8(0x80); \ + const int8x##w##_t sign_bit = vdup##r##n_s8((int8_t)0x80); \ return vreinterpret##r##u8_s8(veor##r##s8(v, sign_bit)); \ } diff --git a/libs/libvpx/vpx_dsp/arm/mem_neon.h b/libs/libvpx/vpx_dsp/arm/mem_neon.h index 50aaa94fe0..a0ef2c8a12 100644 --- a/libs/libvpx/vpx_dsp/arm/mem_neon.h +++ b/libs/libvpx/vpx_dsp/arm/mem_neon.h @@ -40,11 +40,11 @@ static INLINE uint8x16x3_t vld1q_u8_x3(uint8_t const *ptr) { static INLINE int16x4_t create_s16x4_neon(const int16_t c0, const int16_t c1, const int16_t c2, const int16_t c3) { return vcreate_s16((uint16_t)c0 | ((uint32_t)c1 << 16) | - ((int64_t)(uint16_t)c2 << 32) | ((int64_t)c3 << 48)); + ((uint64_t)(uint16_t)c2 << 32) | ((uint64_t)c3 << 48)); } static INLINE int32x2_t create_s32x2_neon(const int32_t c0, const int32_t c1) { - return vcreate_s32((uint32_t)c0 | ((int64_t)(uint32_t)c1 << 32)); + return vcreate_s32((uint32_t)c0 | ((uint64_t)(uint32_t)c1 << 32)); } static INLINE int32x4_t create_s32x4_neon(const int32_t c0, const int32_t c1, @@ -102,6 +102,16 @@ static INLINE void store_s16q_to_tran_low(tran_low_t *buf, const int16x8_t a) { #endif } +#if CONFIG_VP9_HIGHBITDEPTH +static INLINE void store_s32q_to_tran_low(tran_low_t *buf, const int32x4_t a) { + vst1q_s32(buf, a); +} + +static INLINE int32x4_t load_tran_low_to_s32q(const tran_low_t *buf) { + return vld1q_s32(buf); +} +#endif + // Propagate type information to the compiler. Without this the compiler may // assume the required alignment of uint32_t (4 bytes) and add alignment hints // to the memory access. @@ -112,12 +122,39 @@ static INLINE void uint32_to_mem(uint8_t *buf, uint32_t a) { memcpy(buf, &a, 4); } +// Load 4 contiguous bytes when alignment is not guaranteed. +static INLINE uint8x8_t load_unaligned_u8_4x1(const uint8_t *buf) { + uint32_t a; + uint32x2_t a_u32; + memcpy(&a, buf, 4); + a_u32 = vdup_n_u32(0); + a_u32 = vset_lane_u32(a, a_u32, 0); + return vreinterpret_u8_u32(a_u32); +} + +// Load 4 contiguous bytes and replicate across a vector when alignment is not +// guaranteed. +static INLINE uint8x8_t load_replicate_u8_4x1(const uint8_t *buf) { + uint32_t a; + memcpy(&a, buf, 4); + return vreinterpret_u8_u32(vdup_n_u32(a)); +} + +// Store 4 contiguous bytes from the low half of an 8x8 vector. +static INLINE void store_u8_4x1(uint8_t *buf, uint8x8_t a) { + vst1_lane_u32((uint32_t *)buf, vreinterpret_u32_u8(a), 0); +} + +// Store 4 contiguous bytes from the high half of an 8x8 vector. +static INLINE void store_u8_4x1_high(uint8_t *buf, uint8x8_t a) { + vst1_lane_u32((uint32_t *)buf, vreinterpret_u32_u8(a), 1); +} + // Load 2 sets of 4 bytes when alignment is not guaranteed. static INLINE uint8x8_t load_unaligned_u8(const uint8_t *buf, ptrdiff_t stride) { uint32_t a; uint32x2_t a_u32 = vdup_n_u32(0); - if (stride == 4) return vld1_u8(buf); memcpy(&a, buf, 4); buf += stride; a_u32 = vset_lane_u32(a, a_u32, 0); @@ -126,14 +163,32 @@ static INLINE uint8x8_t load_unaligned_u8(const uint8_t *buf, return vreinterpret_u8_u32(a_u32); } +// Load 8 bytes when alignment is not guaranteed. +static INLINE uint16x4_t load_unaligned_u16(const uint16_t *buf) { + uint64_t a; + uint64x1_t a_u64 = vdup_n_u64(0); + memcpy(&a, buf, 8); + a_u64 = vset_lane_u64(a, a_u64, 0); + return vreinterpret_u16_u64(a_u64); +} + +// Load 2 sets of 8 bytes when alignment is not guaranteed. +static INLINE uint16x8_t load_unaligned_u16q(const uint16_t *buf, + ptrdiff_t stride) { + uint64_t a; + uint64x2_t a_u64 = vdupq_n_u64(0); + memcpy(&a, buf, 8); + buf += stride; + a_u64 = vsetq_lane_u64(a, a_u64, 0); + memcpy(&a, buf, 8); + a_u64 = vsetq_lane_u64(a, a_u64, 1); + return vreinterpretq_u16_u64(a_u64); +} + // Store 2 sets of 4 bytes when alignment is not guaranteed. static INLINE void store_unaligned_u8(uint8_t *buf, ptrdiff_t stride, const uint8x8_t a) { const uint32x2_t a_u32 = vreinterpret_u32_u8(a); - if (stride == 4) { - vst1_u8(buf, a); - return; - } uint32_to_mem(buf, vget_lane_u32(a_u32, 0)); buf += stride; uint32_to_mem(buf, vget_lane_u32(a_u32, 1)); @@ -144,7 +199,6 @@ static INLINE uint8x16_t load_unaligned_u8q(const uint8_t *buf, ptrdiff_t stride) { uint32_t a; uint32x4_t a_u32 = vdupq_n_u32(0); - if (stride == 4) return vld1q_u8(buf); memcpy(&a, buf, 4); buf += stride; a_u32 = vsetq_lane_u32(a, a_u32, 0); @@ -164,10 +218,6 @@ static INLINE uint8x16_t load_unaligned_u8q(const uint8_t *buf, static INLINE void store_unaligned_u8q(uint8_t *buf, ptrdiff_t stride, const uint8x16_t a) { const uint32x4_t a_u32 = vreinterpretq_u32_u8(a); - if (stride == 4) { - vst1q_u8(buf, a); - return; - } uint32_to_mem(buf, vgetq_lane_u32(a_u32, 0)); buf += stride; uint32_to_mem(buf, vgetq_lane_u32(a_u32, 1)); @@ -201,4 +251,511 @@ static INLINE void store_u8(uint8_t *buf, ptrdiff_t stride, const uint8x8_t a) { buf += stride; vst1_lane_u32((uint32_t *)buf, a_u32, 1); } + +static INLINE void store_u8_8x3(uint8_t *s, const ptrdiff_t p, + const uint8x8_t s0, const uint8x8_t s1, + const uint8x8_t s2) { + vst1_u8(s, s0); + s += p; + vst1_u8(s, s1); + s += p; + vst1_u8(s, s2); +} + +static INLINE uint8x16_t load_u8_8x2(const uint8_t *s, ptrdiff_t p) { + return vcombine_u8(vld1_u8(s), vld1_u8(s + p)); +} + +static INLINE void load_u8_8x3(const uint8_t *s, const ptrdiff_t p, + uint8x8_t *const s0, uint8x8_t *const s1, + uint8x8_t *const s2) { + *s0 = vld1_u8(s); + s += p; + *s1 = vld1_u8(s); + s += p; + *s2 = vld1_u8(s); +} + +static INLINE void load_u8_8x4(const uint8_t *s, const ptrdiff_t p, + uint8x8_t *const s0, uint8x8_t *const s1, + uint8x8_t *const s2, uint8x8_t *const s3) { + *s0 = vld1_u8(s); + s += p; + *s1 = vld1_u8(s); + s += p; + *s2 = vld1_u8(s); + s += p; + *s3 = vld1_u8(s); +} + +static INLINE void store_u8_8x4(uint8_t *s, const ptrdiff_t p, + const uint8x8_t s0, const uint8x8_t s1, + const uint8x8_t s2, const uint8x8_t s3) { + vst1_u8(s, s0); + s += p; + vst1_u8(s, s1); + s += p; + vst1_u8(s, s2); + s += p; + vst1_u8(s, s3); +} + +static INLINE void load_u8_16x3(const uint8_t *s, const ptrdiff_t p, + uint8x16_t *const s0, uint8x16_t *const s1, + uint8x16_t *const s2) { + *s0 = vld1q_u8(s); + s += p; + *s1 = vld1q_u8(s); + s += p; + *s2 = vld1q_u8(s); +} + +static INLINE void load_u8_16x4(const uint8_t *s, const ptrdiff_t p, + uint8x16_t *const s0, uint8x16_t *const s1, + uint8x16_t *const s2, uint8x16_t *const s3) { + *s0 = vld1q_u8(s); + s += p; + *s1 = vld1q_u8(s); + s += p; + *s2 = vld1q_u8(s); + s += p; + *s3 = vld1q_u8(s); +} + +static INLINE void store_u8_16x4(uint8_t *s, const ptrdiff_t p, + const uint8x16_t s0, const uint8x16_t s1, + const uint8x16_t s2, const uint8x16_t s3) { + vst1q_u8(s, s0); + s += p; + vst1q_u8(s, s1); + s += p; + vst1q_u8(s, s2); + s += p; + vst1q_u8(s, s3); +} + +static INLINE void load_u8_8x7(const uint8_t *s, const ptrdiff_t p, + uint8x8_t *const s0, uint8x8_t *const s1, + uint8x8_t *const s2, uint8x8_t *const s3, + uint8x8_t *const s4, uint8x8_t *const s5, + uint8x8_t *const s6) { + *s0 = vld1_u8(s); + s += p; + *s1 = vld1_u8(s); + s += p; + *s2 = vld1_u8(s); + s += p; + *s3 = vld1_u8(s); + s += p; + *s4 = vld1_u8(s); + s += p; + *s5 = vld1_u8(s); + s += p; + *s6 = vld1_u8(s); +} + +static INLINE void load_u8_8x8(const uint8_t *s, const ptrdiff_t p, + uint8x8_t *const s0, uint8x8_t *const s1, + uint8x8_t *const s2, uint8x8_t *const s3, + uint8x8_t *const s4, uint8x8_t *const s5, + uint8x8_t *const s6, uint8x8_t *const s7) { + *s0 = vld1_u8(s); + s += p; + *s1 = vld1_u8(s); + s += p; + *s2 = vld1_u8(s); + s += p; + *s3 = vld1_u8(s); + s += p; + *s4 = vld1_u8(s); + s += p; + *s5 = vld1_u8(s); + s += p; + *s6 = vld1_u8(s); + s += p; + *s7 = vld1_u8(s); +} + +static INLINE void load_u8_8x11(const uint8_t *s, ptrdiff_t p, + uint8x8_t *const s0, uint8x8_t *const s1, + uint8x8_t *const s2, uint8x8_t *const s3, + uint8x8_t *const s4, uint8x8_t *const s5, + uint8x8_t *const s6, uint8x8_t *const s7, + uint8x8_t *const s8, uint8x8_t *const s9, + uint8x8_t *const s10) { + *s0 = vld1_u8(s); + s += p; + *s1 = vld1_u8(s); + s += p; + *s2 = vld1_u8(s); + s += p; + *s3 = vld1_u8(s); + s += p; + *s4 = vld1_u8(s); + s += p; + *s5 = vld1_u8(s); + s += p; + *s6 = vld1_u8(s); + s += p; + *s7 = vld1_u8(s); + s += p; + *s8 = vld1_u8(s); + s += p; + *s9 = vld1_u8(s); + s += p; + *s10 = vld1_u8(s); +} + +static INLINE void store_u8_8x8(uint8_t *s, const ptrdiff_t p, + const uint8x8_t s0, const uint8x8_t s1, + const uint8x8_t s2, const uint8x8_t s3, + const uint8x8_t s4, const uint8x8_t s5, + const uint8x8_t s6, const uint8x8_t s7) { + vst1_u8(s, s0); + s += p; + vst1_u8(s, s1); + s += p; + vst1_u8(s, s2); + s += p; + vst1_u8(s, s3); + s += p; + vst1_u8(s, s4); + s += p; + vst1_u8(s, s5); + s += p; + vst1_u8(s, s6); + s += p; + vst1_u8(s, s7); +} + +static INLINE void load_u8_16x8(const uint8_t *s, const ptrdiff_t p, + uint8x16_t *const s0, uint8x16_t *const s1, + uint8x16_t *const s2, uint8x16_t *const s3, + uint8x16_t *const s4, uint8x16_t *const s5, + uint8x16_t *const s6, uint8x16_t *const s7) { + *s0 = vld1q_u8(s); + s += p; + *s1 = vld1q_u8(s); + s += p; + *s2 = vld1q_u8(s); + s += p; + *s3 = vld1q_u8(s); + s += p; + *s4 = vld1q_u8(s); + s += p; + *s5 = vld1q_u8(s); + s += p; + *s6 = vld1q_u8(s); + s += p; + *s7 = vld1q_u8(s); +} + +static INLINE void store_u8_16x8(uint8_t *s, const ptrdiff_t p, + const uint8x16_t s0, const uint8x16_t s1, + const uint8x16_t s2, const uint8x16_t s3, + const uint8x16_t s4, const uint8x16_t s5, + const uint8x16_t s6, const uint8x16_t s7) { + vst1q_u8(s, s0); + s += p; + vst1q_u8(s, s1); + s += p; + vst1q_u8(s, s2); + s += p; + vst1q_u8(s, s3); + s += p; + vst1q_u8(s, s4); + s += p; + vst1q_u8(s, s5); + s += p; + vst1q_u8(s, s6); + s += p; + vst1q_u8(s, s7); +} + +static INLINE void store_u16_4x3(uint16_t *s, const ptrdiff_t p, + const uint16x4_t s0, const uint16x4_t s1, + const uint16x4_t s2) { + vst1_u16(s, s0); + s += p; + vst1_u16(s, s1); + s += p; + vst1_u16(s, s2); +} + +static INLINE void load_s16_4x3(const int16_t *s, const ptrdiff_t p, + int16x4_t *s0, int16x4_t *s1, int16x4_t *s2) { + *s0 = vld1_s16(s); + s += p; + *s1 = vld1_s16(s); + s += p; + *s2 = vld1_s16(s); +} + +static INLINE void load_s16_4x4(const int16_t *s, const ptrdiff_t p, + int16x4_t *s0, int16x4_t *s1, int16x4_t *s2, + int16x4_t *s3) { + *s0 = vld1_s16(s); + s += p; + *s1 = vld1_s16(s); + s += p; + *s2 = vld1_s16(s); + s += p; + *s3 = vld1_s16(s); +} + +static INLINE void load_s16_4x11(const int16_t *s, const ptrdiff_t p, + int16x4_t *s0, int16x4_t *s1, int16x4_t *s2, + int16x4_t *s3, int16x4_t *s4, int16x4_t *s5, + int16x4_t *s6, int16x4_t *s7, int16x4_t *s8, + int16x4_t *s9, int16x4_t *s10) { + *s0 = vld1_s16(s); + s += p; + *s1 = vld1_s16(s); + s += p; + *s2 = vld1_s16(s); + s += p; + *s3 = vld1_s16(s); + s += p; + *s4 = vld1_s16(s); + s += p; + *s5 = vld1_s16(s); + s += p; + *s6 = vld1_s16(s); + s += p; + *s7 = vld1_s16(s); + s += p; + *s8 = vld1_s16(s); + s += p; + *s9 = vld1_s16(s); + s += p; + *s10 = vld1_s16(s); +} + +static INLINE void store_u16_4x4(uint16_t *s, const ptrdiff_t p, + const uint16x4_t s0, const uint16x4_t s1, + const uint16x4_t s2, const uint16x4_t s3) { + vst1_u16(s, s0); + s += p; + vst1_u16(s, s1); + s += p; + vst1_u16(s, s2); + s += p; + vst1_u16(s, s3); +} + +static INLINE void load_s16_4x7(const int16_t *s, const ptrdiff_t p, + int16x4_t *s0, int16x4_t *s1, int16x4_t *s2, + int16x4_t *s3, int16x4_t *s4, int16x4_t *s5, + int16x4_t *s6) { + *s0 = vld1_s16(s); + s += p; + *s1 = vld1_s16(s); + s += p; + *s2 = vld1_s16(s); + s += p; + *s3 = vld1_s16(s); + s += p; + *s4 = vld1_s16(s); + s += p; + *s5 = vld1_s16(s); + s += p; + *s6 = vld1_s16(s); +} + +static INLINE void load_s16_8x3(const int16_t *s, const ptrdiff_t p, + int16x8_t *s0, int16x8_t *s1, int16x8_t *s2) { + *s0 = vld1q_s16(s); + s += p; + *s1 = vld1q_s16(s); + s += p; + *s2 = vld1q_s16(s); +} + +static INLINE void load_s16_8x4(const int16_t *s, const ptrdiff_t p, + int16x8_t *s0, int16x8_t *s1, int16x8_t *s2, + int16x8_t *s3) { + *s0 = vld1q_s16(s); + s += p; + *s1 = vld1q_s16(s); + s += p; + *s2 = vld1q_s16(s); + s += p; + *s3 = vld1q_s16(s); +} + +static INLINE void load_u16_8x4(const uint16_t *s, const ptrdiff_t p, + uint16x8_t *s0, uint16x8_t *s1, uint16x8_t *s2, + uint16x8_t *s3) { + *s0 = vld1q_u16(s); + s += p; + *s1 = vld1q_u16(s); + s += p; + *s2 = vld1q_u16(s); + s += p; + *s3 = vld1q_u16(s); +} + +static INLINE void store_u16_8x4(uint16_t *s, const ptrdiff_t p, + const uint16x8_t s0, const uint16x8_t s1, + const uint16x8_t s2, const uint16x8_t s3) { + vst1q_u16(s, s0); + s += p; + vst1q_u16(s, s1); + s += p; + vst1q_u16(s, s2); + s += p; + vst1q_u16(s, s3); +} + +static INLINE void store_u16_8x3(uint16_t *s, const ptrdiff_t p, + const uint16x8_t s0, const uint16x8_t s1, + const uint16x8_t s2) { + vst1q_u16(s, s0); + s += p; + vst1q_u16(s, s1); + s += p; + vst1q_u16(s, s2); +} + +static INLINE void load_s16_8x7(const int16_t *s, const ptrdiff_t p, + int16x8_t *s0, int16x8_t *s1, int16x8_t *s2, + int16x8_t *s3, int16x8_t *s4, int16x8_t *s5, + int16x8_t *s6) { + *s0 = vld1q_s16(s); + s += p; + *s1 = vld1q_s16(s); + s += p; + *s2 = vld1q_s16(s); + s += p; + *s3 = vld1q_s16(s); + s += p; + *s4 = vld1q_s16(s); + s += p; + *s5 = vld1q_s16(s); + s += p; + *s6 = vld1q_s16(s); +} + +static INLINE void load_u16_8x8(const uint16_t *s, const ptrdiff_t p, + uint16x8_t *s0, uint16x8_t *s1, uint16x8_t *s2, + uint16x8_t *s3, uint16x8_t *s4, uint16x8_t *s5, + uint16x8_t *s6, uint16x8_t *s7) { + *s0 = vld1q_u16(s); + s += p; + *s1 = vld1q_u16(s); + s += p; + *s2 = vld1q_u16(s); + s += p; + *s3 = vld1q_u16(s); + s += p; + *s4 = vld1q_u16(s); + s += p; + *s5 = vld1q_u16(s); + s += p; + *s6 = vld1q_u16(s); + s += p; + *s7 = vld1q_u16(s); +} + +static INLINE void load_s16_4x8(const int16_t *s, const ptrdiff_t p, + int16x4_t *s0, int16x4_t *s1, int16x4_t *s2, + int16x4_t *s3, int16x4_t *s4, int16x4_t *s5, + int16x4_t *s6, int16x4_t *s7) { + *s0 = vld1_s16(s); + s += p; + *s1 = vld1_s16(s); + s += p; + *s2 = vld1_s16(s); + s += p; + *s3 = vld1_s16(s); + s += p; + *s4 = vld1_s16(s); + s += p; + *s5 = vld1_s16(s); + s += p; + *s6 = vld1_s16(s); + s += p; + *s7 = vld1_s16(s); +} + +static INLINE void load_s16_8x11(const int16_t *s, const ptrdiff_t p, + int16x8_t *s0, int16x8_t *s1, int16x8_t *s2, + int16x8_t *s3, int16x8_t *s4, int16x8_t *s5, + int16x8_t *s6, int16x8_t *s7, int16x8_t *s8, + int16x8_t *s9, int16x8_t *s10) { + *s0 = vld1q_s16(s); + s += p; + *s1 = vld1q_s16(s); + s += p; + *s2 = vld1q_s16(s); + s += p; + *s3 = vld1q_s16(s); + s += p; + *s4 = vld1q_s16(s); + s += p; + *s5 = vld1q_s16(s); + s += p; + *s6 = vld1q_s16(s); + s += p; + *s7 = vld1q_s16(s); + s += p; + *s8 = vld1q_s16(s); + s += p; + *s9 = vld1q_s16(s); + s += p; + *s10 = vld1q_s16(s); +} + +static INLINE void load_s16_8x12(const int16_t *s, const ptrdiff_t p, + int16x8_t *s0, int16x8_t *s1, int16x8_t *s2, + int16x8_t *s3, int16x8_t *s4, int16x8_t *s5, + int16x8_t *s6, int16x8_t *s7, int16x8_t *s8, + int16x8_t *s9, int16x8_t *s10, + int16x8_t *s11) { + *s0 = vld1q_s16(s); + s += p; + *s1 = vld1q_s16(s); + s += p; + *s2 = vld1q_s16(s); + s += p; + *s3 = vld1q_s16(s); + s += p; + *s4 = vld1q_s16(s); + s += p; + *s5 = vld1q_s16(s); + s += p; + *s6 = vld1q_s16(s); + s += p; + *s7 = vld1q_s16(s); + s += p; + *s8 = vld1q_s16(s); + s += p; + *s9 = vld1q_s16(s); + s += p; + *s10 = vld1q_s16(s); + s += p; + *s11 = vld1q_s16(s); +} + +static INLINE void load_s16_8x8(const int16_t *s, const ptrdiff_t p, + int16x8_t *s0, int16x8_t *s1, int16x8_t *s2, + int16x8_t *s3, int16x8_t *s4, int16x8_t *s5, + int16x8_t *s6, int16x8_t *s7) { + *s0 = vld1q_s16(s); + s += p; + *s1 = vld1q_s16(s); + s += p; + *s2 = vld1q_s16(s); + s += p; + *s3 = vld1q_s16(s); + s += p; + *s4 = vld1q_s16(s); + s += p; + *s5 = vld1q_s16(s); + s += p; + *s6 = vld1q_s16(s); + s += p; + *s7 = vld1q_s16(s); +} + #endif // VPX_VPX_DSP_ARM_MEM_NEON_H_ diff --git a/libs/libvpx/vpx_dsp/arm/quantize_neon.c b/libs/libvpx/vpx_dsp/arm/quantize_neon.c index bd7818a074..e2351fa2cc 100644 --- a/libs/libvpx/vpx_dsp/arm/quantize_neon.c +++ b/libs/libvpx/vpx_dsp/arm/quantize_neon.c @@ -14,138 +14,126 @@ #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" #include "vpx_dsp/arm/mem_neon.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" static INLINE void calculate_dqcoeff_and_store(const int16x8_t qcoeff, const int16x8_t dequant, - tran_low_t *dqcoeff) { + tran_low_t *dqcoeff_ptr) { +#if CONFIG_VP9_HIGHBITDEPTH const int32x4_t dqcoeff_0 = vmull_s16(vget_low_s16(qcoeff), vget_low_s16(dequant)); const int32x4_t dqcoeff_1 = vmull_s16(vget_high_s16(qcoeff), vget_high_s16(dequant)); -#if CONFIG_VP9_HIGHBITDEPTH - vst1q_s32(dqcoeff, dqcoeff_0); - vst1q_s32(dqcoeff + 4, dqcoeff_1); + vst1q_s32(dqcoeff_ptr, dqcoeff_0); + vst1q_s32(dqcoeff_ptr + 4, dqcoeff_1); #else - vst1q_s16(dqcoeff, vcombine_s16(vmovn_s32(dqcoeff_0), vmovn_s32(dqcoeff_1))); + vst1q_s16(dqcoeff_ptr, vmulq_s16(qcoeff, dequant)); #endif // CONFIG_VP9_HIGHBITDEPTH } +static INLINE int16x8_t +quantize_b_neon(const tran_low_t *coeff_ptr, tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, const int16x8_t zbin, + const int16x8_t round, const int16x8_t quant, + const int16x8_t quant_shift, const int16x8_t dequant) { + // Load coeffs as 8 x 16-bit ints, take sign and abs values + const int16x8_t coeff = load_tran_low_to_s16q(coeff_ptr); + const int16x8_t coeff_sign = vshrq_n_s16(coeff, 15); + const int16x8_t coeff_abs = vabsq_s16(coeff); + + // Calculate mask of elements outside the bin + const int16x8_t zbin_mask = vreinterpretq_s16_u16(vcgeq_s16(coeff_abs, zbin)); + + // Get the rounded values + const int16x8_t rounded = vqaddq_s16(coeff_abs, round); + + // (round * quant * 2) >> 16 >> 1 == (round * quant) >> 16 + int16x8_t qcoeff = vshrq_n_s16(vqdmulhq_s16(rounded, quant), 1); + + qcoeff = vaddq_s16(qcoeff, rounded); + + // (qcoeff * quant_shift * 2) >> 16 >> 1 == (qcoeff * quant_shift) >> 16 + qcoeff = vshrq_n_s16(vqdmulhq_s16(qcoeff, quant_shift), 1); + + // Restore the sign bit. + qcoeff = veorq_s16(qcoeff, coeff_sign); + qcoeff = vsubq_s16(qcoeff, coeff_sign); + + // Only keep the relevant coeffs + qcoeff = vandq_s16(qcoeff, zbin_mask); + store_s16q_to_tran_low(qcoeff_ptr, qcoeff); + + calculate_dqcoeff_and_store(qcoeff, dequant, dqcoeff_ptr); + + return qcoeff; +} + void vpx_quantize_b_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, - tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, - uint16_t *eob_ptr, const int16_t *scan, - const int16_t *iscan) { - const int16x8_t one = vdupq_n_s16(1); + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { const int16x8_t neg_one = vdupq_n_s16(-1); uint16x8_t eob_max; - (void)scan; + int16_t const *iscan = scan_order->iscan; + + // Only the first element of each vector is DC. + int16x8_t zbin = vld1q_s16(mb_plane->zbin); + int16x8_t round = vld1q_s16(mb_plane->round); + int16x8_t quant = vld1q_s16(mb_plane->quant); + int16x8_t quant_shift = vld1q_s16(mb_plane->quant_shift); + int16x8_t dequant = vld1q_s16(dequant_ptr); // Process first 8 values which include a dc component. { - // Only the first element of each vector is DC. - const int16x8_t zbin = vld1q_s16(zbin_ptr); - const int16x8_t round = vld1q_s16(round_ptr); - const int16x8_t quant = vld1q_s16(quant_ptr); - const int16x8_t quant_shift = vld1q_s16(quant_shift_ptr); - const int16x8_t dequant = vld1q_s16(dequant_ptr); - // Add one because the eob does not index from 0. - const uint16x8_t v_iscan = - vreinterpretq_u16_s16(vaddq_s16(vld1q_s16(iscan), one)); + const uint16x8_t v_iscan = vreinterpretq_u16_s16(vld1q_s16(iscan)); - const int16x8_t coeff = load_tran_low_to_s16q(coeff_ptr); - const int16x8_t coeff_sign = vshrq_n_s16(coeff, 15); - const int16x8_t coeff_abs = vabsq_s16(coeff); - - const int16x8_t zbin_mask = - vreinterpretq_s16_u16(vcgeq_s16(coeff_abs, zbin)); - - const int16x8_t rounded = vqaddq_s16(coeff_abs, round); - - // (round * quant * 2) >> 16 >> 1 == (round * quant) >> 16 - int16x8_t qcoeff = vshrq_n_s16(vqdmulhq_s16(rounded, quant), 1); - - qcoeff = vaddq_s16(qcoeff, rounded); - - // (qcoeff * quant_shift * 2) >> 16 >> 1 == (qcoeff * quant_shift) >> 16 - qcoeff = vshrq_n_s16(vqdmulhq_s16(qcoeff, quant_shift), 1); - - // Restore the sign bit. - qcoeff = veorq_s16(qcoeff, coeff_sign); - qcoeff = vsubq_s16(qcoeff, coeff_sign); - - qcoeff = vandq_s16(qcoeff, zbin_mask); + const int16x8_t qcoeff = + quantize_b_neon(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, zbin, round, quant, + quant_shift, dequant); // Set non-zero elements to -1 and use that to extract values for eob. eob_max = vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan); + __builtin_prefetch(coeff_ptr + 64); coeff_ptr += 8; iscan += 8; - - store_s16q_to_tran_low(qcoeff_ptr, qcoeff); qcoeff_ptr += 8; - - calculate_dqcoeff_and_store(qcoeff, dequant, dqcoeff_ptr); dqcoeff_ptr += 8; } n_coeffs -= 8; { - const int16x8_t zbin = vdupq_n_s16(zbin_ptr[1]); - const int16x8_t round = vdupq_n_s16(round_ptr[1]); - const int16x8_t quant = vdupq_n_s16(quant_ptr[1]); - const int16x8_t quant_shift = vdupq_n_s16(quant_shift_ptr[1]); - const int16x8_t dequant = vdupq_n_s16(dequant_ptr[1]); + zbin = vdupq_lane_s16(vget_low_s16(zbin), 1); + round = vdupq_lane_s16(vget_low_s16(round), 1); + quant = vdupq_lane_s16(vget_low_s16(quant), 1); + quant_shift = vdupq_lane_s16(vget_low_s16(quant_shift), 1); + dequant = vdupq_lane_s16(vget_low_s16(dequant), 1); do { - // Add one because the eob is not its index. - const uint16x8_t v_iscan = - vreinterpretq_u16_s16(vaddq_s16(vld1q_s16(iscan), one)); + const uint16x8_t v_iscan = vreinterpretq_u16_s16(vld1q_s16(iscan)); - const int16x8_t coeff = load_tran_low_to_s16q(coeff_ptr); - const int16x8_t coeff_sign = vshrq_n_s16(coeff, 15); - const int16x8_t coeff_abs = vabsq_s16(coeff); - - const int16x8_t zbin_mask = - vreinterpretq_s16_u16(vcgeq_s16(coeff_abs, zbin)); - - const int16x8_t rounded = vqaddq_s16(coeff_abs, round); - - // (round * quant * 2) >> 16 >> 1 == (round * quant) >> 16 - int16x8_t qcoeff = vshrq_n_s16(vqdmulhq_s16(rounded, quant), 1); - - qcoeff = vaddq_s16(qcoeff, rounded); - - // (qcoeff * quant_shift * 2) >> 16 >> 1 == (qcoeff * quant_shift) >> 16 - qcoeff = vshrq_n_s16(vqdmulhq_s16(qcoeff, quant_shift), 1); - - // Restore the sign bit. - qcoeff = veorq_s16(qcoeff, coeff_sign); - qcoeff = vsubq_s16(qcoeff, coeff_sign); - - qcoeff = vandq_s16(qcoeff, zbin_mask); + const int16x8_t qcoeff = + quantize_b_neon(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, zbin, round, + quant, quant_shift, dequant); // Set non-zero elements to -1 and use that to extract values for eob. eob_max = vmaxq_u16(eob_max, vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan)); + __builtin_prefetch(coeff_ptr + 64); coeff_ptr += 8; iscan += 8; - - store_s16q_to_tran_low(qcoeff_ptr, qcoeff); qcoeff_ptr += 8; - - calculate_dqcoeff_and_store(qcoeff, dequant, dqcoeff_ptr); dqcoeff_ptr += 8; - n_coeffs -= 8; } while (n_coeffs > 0); } -#ifdef __aarch64__ +#if VPX_ARCH_AARCH64 *eob_ptr = vmaxvq_u16(eob_max); #else { @@ -155,7 +143,7 @@ void vpx_quantize_b_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const uint16x4_t eob_max_2 = vpmax_u16(eob_max_1, eob_max_1); vst1_lane_u16(eob_ptr, eob_max_2, 0); } -#endif // __aarch64__ +#endif // VPX_ARCH_AARCH64 } static INLINE int32x4_t extract_sign_bit(int32x4_t a) { @@ -164,7 +152,7 @@ static INLINE int32x4_t extract_sign_bit(int32x4_t a) { static INLINE void calculate_dqcoeff_and_store_32x32(const int16x8_t qcoeff, const int16x8_t dequant, - tran_low_t *dqcoeff) { + tran_low_t *dqcoeff_ptr) { int32x4_t dqcoeff_0 = vmull_s16(vget_low_s16(qcoeff), vget_low_s16(dequant)); int32x4_t dqcoeff_1 = vmull_s16(vget_high_s16(qcoeff), vget_high_s16(dequant)); @@ -176,130 +164,115 @@ static INLINE void calculate_dqcoeff_and_store_32x32(const int16x8_t qcoeff, #if CONFIG_VP9_HIGHBITDEPTH dqcoeff_0 = vshrq_n_s32(dqcoeff_0, 1); dqcoeff_1 = vshrq_n_s32(dqcoeff_1, 1); - vst1q_s32(dqcoeff, dqcoeff_0); - vst1q_s32(dqcoeff + 4, dqcoeff_1); + vst1q_s32(dqcoeff_ptr, dqcoeff_0); + vst1q_s32(dqcoeff_ptr + 4, dqcoeff_1); #else - vst1q_s16(dqcoeff, + vst1q_s16(dqcoeff_ptr, vcombine_s16(vshrn_n_s32(dqcoeff_0, 1), vshrn_n_s32(dqcoeff_1, 1))); #endif // CONFIG_VP9_HIGHBITDEPTH } +static INLINE int16x8_t +quantize_b_32x32_neon(const tran_low_t *coeff_ptr, tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, const int16x8_t zbin, + const int16x8_t round, const int16x8_t quant, + const int16x8_t quant_shift, const int16x8_t dequant) { + // Load coeffs as 8 x 16-bit ints, take sign and abs values + const int16x8_t coeff = load_tran_low_to_s16q(coeff_ptr); + const int16x8_t coeff_sign = vshrq_n_s16(coeff, 15); + const int16x8_t coeff_abs = vabsq_s16(coeff); + + // Calculate mask of elements outside the bin + const int16x8_t zbin_mask = vreinterpretq_s16_u16(vcgeq_s16(coeff_abs, zbin)); + + // Get the rounded values + const int16x8_t rounded = vqaddq_s16(coeff_abs, round); + + // (round * quant * 2) >> 16 >> 1 == (round * quant) >> 16 + int16x8_t qcoeff = vshrq_n_s16(vqdmulhq_s16(rounded, quant), 1); + + qcoeff = vaddq_s16(qcoeff, rounded); + + // (qcoeff * quant_shift * 2) >> 16 == (qcoeff * quant_shift) >> 15 + qcoeff = vqdmulhq_s16(qcoeff, quant_shift); + + // Restore the sign bit. + qcoeff = veorq_s16(qcoeff, coeff_sign); + qcoeff = vsubq_s16(qcoeff, coeff_sign); + + // Only keep the relevant coeffs + qcoeff = vandq_s16(qcoeff, zbin_mask); + store_s16q_to_tran_low(qcoeff_ptr, qcoeff); + + calculate_dqcoeff_and_store_32x32(qcoeff, dequant, dqcoeff_ptr); + + return qcoeff; +} + // Main difference is that zbin values are halved before comparison and dqcoeff // values are divided by 2. zbin is rounded but dqcoeff is not. -void vpx_quantize_b_32x32_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, - const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, +void vpx_quantize_b_32x32_neon(const tran_low_t *coeff_ptr, + const struct macroblock_plane *mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { - const int16x8_t one = vdupq_n_s16(1); + const struct ScanOrder *const scan_order) { const int16x8_t neg_one = vdupq_n_s16(-1); uint16x8_t eob_max; int i; - (void)scan; - (void)n_coeffs; // Because we will always calculate 32*32. + const int16_t *iscan = scan_order->iscan; + + // Only the first element of each vector is DC. + int16x8_t zbin = vrshrq_n_s16(vld1q_s16(mb_plane->zbin), 1); + int16x8_t round = vrshrq_n_s16(vld1q_s16(mb_plane->round), 1); + int16x8_t quant = vld1q_s16(mb_plane->quant); + int16x8_t quant_shift = vld1q_s16(mb_plane->quant_shift); + int16x8_t dequant = vld1q_s16(dequant_ptr); // Process first 8 values which include a dc component. { - // Only the first element of each vector is DC. - const int16x8_t zbin = vrshrq_n_s16(vld1q_s16(zbin_ptr), 1); - const int16x8_t round = vrshrq_n_s16(vld1q_s16(round_ptr), 1); - const int16x8_t quant = vld1q_s16(quant_ptr); - const int16x8_t quant_shift = vld1q_s16(quant_shift_ptr); - const int16x8_t dequant = vld1q_s16(dequant_ptr); - // Add one because the eob does not index from 0. - const uint16x8_t v_iscan = - vreinterpretq_u16_s16(vaddq_s16(vld1q_s16(iscan), one)); + const uint16x8_t v_iscan = vreinterpretq_u16_s16(vld1q_s16(iscan)); - const int16x8_t coeff = load_tran_low_to_s16q(coeff_ptr); - const int16x8_t coeff_sign = vshrq_n_s16(coeff, 15); - const int16x8_t coeff_abs = vabsq_s16(coeff); - - const int16x8_t zbin_mask = - vreinterpretq_s16_u16(vcgeq_s16(coeff_abs, zbin)); - - const int16x8_t rounded = vqaddq_s16(coeff_abs, round); - - // (round * quant * 2) >> 16 >> 1 == (round * quant) >> 16 - int16x8_t qcoeff = vshrq_n_s16(vqdmulhq_s16(rounded, quant), 1); - - qcoeff = vaddq_s16(qcoeff, rounded); - - // (qcoeff * quant_shift * 2) >> 16 == (qcoeff * quant_shift) >> 15 - qcoeff = vqdmulhq_s16(qcoeff, quant_shift); - - // Restore the sign bit. - qcoeff = veorq_s16(qcoeff, coeff_sign); - qcoeff = vsubq_s16(qcoeff, coeff_sign); - - qcoeff = vandq_s16(qcoeff, zbin_mask); + const int16x8_t qcoeff = + quantize_b_32x32_neon(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, zbin, round, + quant, quant_shift, dequant); // Set non-zero elements to -1 and use that to extract values for eob. eob_max = vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan); + __builtin_prefetch(coeff_ptr + 64); coeff_ptr += 8; iscan += 8; - - store_s16q_to_tran_low(qcoeff_ptr, qcoeff); qcoeff_ptr += 8; - - calculate_dqcoeff_and_store_32x32(qcoeff, dequant, dqcoeff_ptr); dqcoeff_ptr += 8; } { - const int16x8_t zbin = vrshrq_n_s16(vdupq_n_s16(zbin_ptr[1]), 1); - const int16x8_t round = vrshrq_n_s16(vdupq_n_s16(round_ptr[1]), 1); - const int16x8_t quant = vdupq_n_s16(quant_ptr[1]); - const int16x8_t quant_shift = vdupq_n_s16(quant_shift_ptr[1]); - const int16x8_t dequant = vdupq_n_s16(dequant_ptr[1]); + zbin = vdupq_lane_s16(vget_low_s16(zbin), 1); + round = vdupq_lane_s16(vget_low_s16(round), 1); + quant = vdupq_lane_s16(vget_low_s16(quant), 1); + quant_shift = vdupq_lane_s16(vget_low_s16(quant_shift), 1); + dequant = vdupq_lane_s16(vget_low_s16(dequant), 1); for (i = 1; i < 32 * 32 / 8; ++i) { - // Add one because the eob is not its index. - const uint16x8_t v_iscan = - vreinterpretq_u16_s16(vaddq_s16(vld1q_s16(iscan), one)); + const uint16x8_t v_iscan = vreinterpretq_u16_s16(vld1q_s16(iscan)); - const int16x8_t coeff = load_tran_low_to_s16q(coeff_ptr); - const int16x8_t coeff_sign = vshrq_n_s16(coeff, 15); - const int16x8_t coeff_abs = vabsq_s16(coeff); - - const int16x8_t zbin_mask = - vreinterpretq_s16_u16(vcgeq_s16(coeff_abs, zbin)); - - const int16x8_t rounded = vqaddq_s16(coeff_abs, round); - - // (round * quant * 2) >> 16 >> 1 == (round * quant) >> 16 - int16x8_t qcoeff = vshrq_n_s16(vqdmulhq_s16(rounded, quant), 1); - - qcoeff = vaddq_s16(qcoeff, rounded); - - // (qcoeff * quant_shift * 2) >> 16 == (qcoeff * quant_shift) >> 15 - qcoeff = vqdmulhq_s16(qcoeff, quant_shift); - - // Restore the sign bit. - qcoeff = veorq_s16(qcoeff, coeff_sign); - qcoeff = vsubq_s16(qcoeff, coeff_sign); - - qcoeff = vandq_s16(qcoeff, zbin_mask); + const int16x8_t qcoeff = + quantize_b_32x32_neon(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, zbin, round, + quant, quant_shift, dequant); // Set non-zero elements to -1 and use that to extract values for eob. eob_max = vmaxq_u16(eob_max, vandq_u16(vtstq_s16(qcoeff, neg_one), v_iscan)); + __builtin_prefetch(coeff_ptr + 64); coeff_ptr += 8; iscan += 8; - - store_s16q_to_tran_low(qcoeff_ptr, qcoeff); qcoeff_ptr += 8; - - calculate_dqcoeff_and_store_32x32(qcoeff, dequant, dqcoeff_ptr); dqcoeff_ptr += 8; } } -#ifdef __aarch64__ +#if VPX_ARCH_AARCH64 *eob_ptr = vmaxvq_u16(eob_max); #else { @@ -309,5 +282,5 @@ void vpx_quantize_b_32x32_neon(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const uint16x4_t eob_max_2 = vpmax_u16(eob_max_1, eob_max_1); vst1_lane_u16(eob_ptr, eob_max_2, 0); } -#endif // __aarch64__ +#endif // VPX_ARCH_AARCH64 } diff --git a/libs/libvpx/vpx_dsp/arm/sad4d_neon.c b/libs/libvpx/vpx_dsp/arm/sad4d_neon.c index 03f716c3d5..713eec7a92 100644 --- a/libs/libvpx/vpx_dsp/arm/sad4d_neon.c +++ b/libs/libvpx/vpx_dsp/arm/sad4d_neon.c @@ -17,636 +17,212 @@ #include "vpx_dsp/arm/mem_neon.h" #include "vpx_dsp/arm/sum_neon.h" -static INLINE uint8x8_t load_unaligned_2_buffers(const void *const buf0, - const void *const buf1) { - uint32_t a; - uint32x2_t aa = vdup_n_u32(0); - memcpy(&a, buf0, 4); - aa = vset_lane_u32(a, aa, 0); - memcpy(&a, buf1, 4); - aa = vset_lane_u32(a, aa, 1); - return vreinterpret_u8_u32(aa); +static INLINE void sad16_neon(uint8x16_t src, uint8x16_t ref, + uint16x8_t *const sad_sum) { + uint8x16_t abs_diff = vabdq_u8(src, ref); + *sad_sum = vpadalq_u8(*sad_sum, abs_diff); } -static INLINE void sad4x_4d(const uint8_t *const src_ptr, const int src_stride, - const uint8_t *const ref_array[4], - const int ref_stride, const int height, - uint32_t sad_array[4]) { - int i; - uint16x8_t abs[2] = { vdupq_n_u16(0), vdupq_n_u16(0) }; -#if !defined(__aarch64__) - uint16x4_t a[2]; -#endif - uint32x4_t r; +static INLINE void sad64xhx4d_neon(const uint8_t *src, int src_stride, + const uint8_t *const ref[4], int ref_stride, + uint32_t res[4], int h) { + uint16x8_t sum_lo[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), + vdupq_n_u16(0) }; + uint16x8_t sum_hi[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), + vdupq_n_u16(0) }; - assert(!((intptr_t)src_ptr % sizeof(uint32_t))); - assert(!(src_stride % sizeof(uint32_t))); + int i = 0; + do { + uint8x16_t s0, s1, s2, s3; - for (i = 0; i < height; ++i) { - const uint8x8_t s = vreinterpret_u8_u32( - vld1_dup_u32((const uint32_t *)(src_ptr + i * src_stride))); - const uint8x8_t ref01 = load_unaligned_2_buffers( - ref_array[0] + i * ref_stride, ref_array[1] + i * ref_stride); - const uint8x8_t ref23 = load_unaligned_2_buffers( - ref_array[2] + i * ref_stride, ref_array[3] + i * ref_stride); - abs[0] = vabal_u8(abs[0], s, ref01); - abs[1] = vabal_u8(abs[1], s, ref23); - } + s0 = vld1q_u8(src + i * src_stride); + sad16_neon(s0, vld1q_u8(ref[0] + i * ref_stride), &sum_lo[0]); + sad16_neon(s0, vld1q_u8(ref[1] + i * ref_stride), &sum_lo[1]); + sad16_neon(s0, vld1q_u8(ref[2] + i * ref_stride), &sum_lo[2]); + sad16_neon(s0, vld1q_u8(ref[3] + i * ref_stride), &sum_lo[3]); -#if defined(__aarch64__) - abs[0] = vpaddq_u16(abs[0], abs[1]); - r = vpaddlq_u16(abs[0]); -#else - a[0] = vpadd_u16(vget_low_u16(abs[0]), vget_high_u16(abs[0])); - a[1] = vpadd_u16(vget_low_u16(abs[1]), vget_high_u16(abs[1])); - r = vpaddlq_u16(vcombine_u16(a[0], a[1])); -#endif - vst1q_u32(sad_array, r); + s1 = vld1q_u8(src + i * src_stride + 16); + sad16_neon(s1, vld1q_u8(ref[0] + i * ref_stride + 16), &sum_hi[0]); + sad16_neon(s1, vld1q_u8(ref[1] + i * ref_stride + 16), &sum_hi[1]); + sad16_neon(s1, vld1q_u8(ref[2] + i * ref_stride + 16), &sum_hi[2]); + sad16_neon(s1, vld1q_u8(ref[3] + i * ref_stride + 16), &sum_hi[3]); + + s2 = vld1q_u8(src + i * src_stride + 32); + sad16_neon(s2, vld1q_u8(ref[0] + i * ref_stride + 32), &sum_lo[0]); + sad16_neon(s2, vld1q_u8(ref[1] + i * ref_stride + 32), &sum_lo[1]); + sad16_neon(s2, vld1q_u8(ref[2] + i * ref_stride + 32), &sum_lo[2]); + sad16_neon(s2, vld1q_u8(ref[3] + i * ref_stride + 32), &sum_lo[3]); + + s3 = vld1q_u8(src + i * src_stride + 48); + sad16_neon(s3, vld1q_u8(ref[0] + i * ref_stride + 48), &sum_hi[0]); + sad16_neon(s3, vld1q_u8(ref[1] + i * ref_stride + 48), &sum_hi[1]); + sad16_neon(s3, vld1q_u8(ref[2] + i * ref_stride + 48), &sum_hi[2]); + sad16_neon(s3, vld1q_u8(ref[3] + i * ref_stride + 48), &sum_hi[3]); + + i++; + } while (i < h); + + vst1q_u32(res, horizontal_long_add_4d_uint16x8(sum_lo, sum_hi)); } -void vpx_sad4x4x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - sad4x_4d(src_ptr, src_stride, ref_array, ref_stride, 4, sad_array); +static INLINE void sad32xhx4d_neon(const uint8_t *src, int src_stride, + const uint8_t *const ref[4], int ref_stride, + uint32_t res[4], int h) { + uint16x8_t sum_lo[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), + vdupq_n_u16(0) }; + uint16x8_t sum_hi[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), + vdupq_n_u16(0) }; + + int i = 0; + do { + uint8x16_t s0, s1; + + s0 = vld1q_u8(src + i * src_stride); + sad16_neon(s0, vld1q_u8(ref[0] + i * ref_stride), &sum_lo[0]); + sad16_neon(s0, vld1q_u8(ref[1] + i * ref_stride), &sum_lo[1]); + sad16_neon(s0, vld1q_u8(ref[2] + i * ref_stride), &sum_lo[2]); + sad16_neon(s0, vld1q_u8(ref[3] + i * ref_stride), &sum_lo[3]); + + s1 = vld1q_u8(src + i * src_stride + 16); + sad16_neon(s1, vld1q_u8(ref[0] + i * ref_stride + 16), &sum_hi[0]); + sad16_neon(s1, vld1q_u8(ref[1] + i * ref_stride + 16), &sum_hi[1]); + sad16_neon(s1, vld1q_u8(ref[2] + i * ref_stride + 16), &sum_hi[2]); + sad16_neon(s1, vld1q_u8(ref[3] + i * ref_stride + 16), &sum_hi[3]); + + i++; + } while (i < h); + + vst1q_u32(res, horizontal_long_add_4d_uint16x8(sum_lo, sum_hi)); } -void vpx_sad4x8x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - sad4x_4d(src_ptr, src_stride, ref_array, ref_stride, 8, sad_array); -} - -//////////////////////////////////////////////////////////////////////////////// - -// Can handle 512 pixels' sad sum (such as 16x32 or 32x16) -static INLINE void sad_512_pel_final_neon(const uint16x8_t sum[4], - uint32_t sad_array[4]) { -#if defined(__aarch64__) - const uint16x8_t a0 = vpaddq_u16(sum[0], sum[1]); - const uint16x8_t a1 = vpaddq_u16(sum[2], sum[3]); - const uint16x8_t b0 = vpaddq_u16(a0, a1); - const uint32x4_t r = vpaddlq_u16(b0); -#else - const uint16x4_t a0 = vadd_u16(vget_low_u16(sum[0]), vget_high_u16(sum[0])); - const uint16x4_t a1 = vadd_u16(vget_low_u16(sum[1]), vget_high_u16(sum[1])); - const uint16x4_t a2 = vadd_u16(vget_low_u16(sum[2]), vget_high_u16(sum[2])); - const uint16x4_t a3 = vadd_u16(vget_low_u16(sum[3]), vget_high_u16(sum[3])); - const uint16x4_t b0 = vpadd_u16(a0, a1); - const uint16x4_t b1 = vpadd_u16(a2, a3); - const uint32x4_t r = vpaddlq_u16(vcombine_u16(b0, b1)); -#endif - vst1q_u32(sad_array, r); -} - -#if defined(__arm__) || !defined(__ARM_FEATURE_DOTPROD) - -// Can handle 1024 pixels' sad sum (such as 32x32) -static INLINE void sad_1024_pel_final_neon(const uint16x8_t sum[4], - uint32_t sad_array[4]) { -#if defined(__aarch64__) - const uint16x8_t a0 = vpaddq_u16(sum[0], sum[1]); - const uint16x8_t a1 = vpaddq_u16(sum[2], sum[3]); - const uint32x4_t b0 = vpaddlq_u16(a0); - const uint32x4_t b1 = vpaddlq_u16(a1); - const uint32x4_t r = vpaddq_u32(b0, b1); - vst1q_u32(sad_array, r); -#else - const uint16x4_t a0 = vpadd_u16(vget_low_u16(sum[0]), vget_high_u16(sum[0])); - const uint16x4_t a1 = vpadd_u16(vget_low_u16(sum[1]), vget_high_u16(sum[1])); - const uint16x4_t a2 = vpadd_u16(vget_low_u16(sum[2]), vget_high_u16(sum[2])); - const uint16x4_t a3 = vpadd_u16(vget_low_u16(sum[3]), vget_high_u16(sum[3])); - const uint32x4_t b0 = vpaddlq_u16(vcombine_u16(a0, a1)); - const uint32x4_t b1 = vpaddlq_u16(vcombine_u16(a2, a3)); - const uint32x2_t c0 = vpadd_u32(vget_low_u32(b0), vget_high_u32(b0)); - const uint32x2_t c1 = vpadd_u32(vget_low_u32(b1), vget_high_u32(b1)); - vst1q_u32(sad_array, vcombine_u32(c0, c1)); -#endif -} - -// Can handle 2048 pixels' sad sum (such as 32x64 or 64x32) -static INLINE void sad_2048_pel_final_neon(const uint16x8_t sum[4], - uint32_t sad_array[4]) { -#if defined(__aarch64__) - const uint32x4_t a0 = vpaddlq_u16(sum[0]); - const uint32x4_t a1 = vpaddlq_u16(sum[1]); - const uint32x4_t a2 = vpaddlq_u16(sum[2]); - const uint32x4_t a3 = vpaddlq_u16(sum[3]); - const uint32x4_t b0 = vpaddq_u32(a0, a1); - const uint32x4_t b1 = vpaddq_u32(a2, a3); - const uint32x4_t r = vpaddq_u32(b0, b1); - vst1q_u32(sad_array, r); -#else - const uint32x4_t a0 = vpaddlq_u16(sum[0]); - const uint32x4_t a1 = vpaddlq_u16(sum[1]); - const uint32x4_t a2 = vpaddlq_u16(sum[2]); - const uint32x4_t a3 = vpaddlq_u16(sum[3]); - const uint32x2_t b0 = vadd_u32(vget_low_u32(a0), vget_high_u32(a0)); - const uint32x2_t b1 = vadd_u32(vget_low_u32(a1), vget_high_u32(a1)); - const uint32x2_t b2 = vadd_u32(vget_low_u32(a2), vget_high_u32(a2)); - const uint32x2_t b3 = vadd_u32(vget_low_u32(a3), vget_high_u32(a3)); - const uint32x2_t c0 = vpadd_u32(b0, b1); - const uint32x2_t c1 = vpadd_u32(b2, b3); - vst1q_u32(sad_array, vcombine_u32(c0, c1)); -#endif -} - -// Can handle 4096 pixels' sad sum (such as 64x64) -static INLINE void sad_4096_pel_final_neon(const uint16x8_t sum[8], - uint32_t sad_array[4]) { -#if defined(__aarch64__) - const uint32x4_t a0 = vpaddlq_u16(sum[0]); - const uint32x4_t a1 = vpaddlq_u16(sum[1]); - const uint32x4_t a2 = vpaddlq_u16(sum[2]); - const uint32x4_t a3 = vpaddlq_u16(sum[3]); - const uint32x4_t a4 = vpaddlq_u16(sum[4]); - const uint32x4_t a5 = vpaddlq_u16(sum[5]); - const uint32x4_t a6 = vpaddlq_u16(sum[6]); - const uint32x4_t a7 = vpaddlq_u16(sum[7]); - const uint32x4_t b0 = vaddq_u32(a0, a1); - const uint32x4_t b1 = vaddq_u32(a2, a3); - const uint32x4_t b2 = vaddq_u32(a4, a5); - const uint32x4_t b3 = vaddq_u32(a6, a7); - const uint32x4_t c0 = vpaddq_u32(b0, b1); - const uint32x4_t c1 = vpaddq_u32(b2, b3); - const uint32x4_t r = vpaddq_u32(c0, c1); - vst1q_u32(sad_array, r); -#else - const uint32x4_t a0 = vpaddlq_u16(sum[0]); - const uint32x4_t a1 = vpaddlq_u16(sum[1]); - const uint32x4_t a2 = vpaddlq_u16(sum[2]); - const uint32x4_t a3 = vpaddlq_u16(sum[3]); - const uint32x4_t a4 = vpaddlq_u16(sum[4]); - const uint32x4_t a5 = vpaddlq_u16(sum[5]); - const uint32x4_t a6 = vpaddlq_u16(sum[6]); - const uint32x4_t a7 = vpaddlq_u16(sum[7]); - const uint32x4_t b0 = vaddq_u32(a0, a1); - const uint32x4_t b1 = vaddq_u32(a2, a3); - const uint32x4_t b2 = vaddq_u32(a4, a5); - const uint32x4_t b3 = vaddq_u32(a6, a7); - const uint32x2_t c0 = vadd_u32(vget_low_u32(b0), vget_high_u32(b0)); - const uint32x2_t c1 = vadd_u32(vget_low_u32(b1), vget_high_u32(b1)); - const uint32x2_t c2 = vadd_u32(vget_low_u32(b2), vget_high_u32(b2)); - const uint32x2_t c3 = vadd_u32(vget_low_u32(b3), vget_high_u32(b3)); - const uint32x2_t d0 = vpadd_u32(c0, c1); - const uint32x2_t d1 = vpadd_u32(c2, c3); - vst1q_u32(sad_array, vcombine_u32(d0, d1)); -#endif -} - -#endif - -static INLINE void sad8x_4d(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4], const int height) { - int i, j; - const uint8_t *ref_loop[4] = { ref_array[0], ref_array[1], ref_array[2], - ref_array[3] }; +static INLINE void sad16xhx4d_neon(const uint8_t *src, int src_stride, + const uint8_t *const ref[4], int ref_stride, + uint32_t res[4], int h) { uint16x8_t sum[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0) }; - for (i = 0; i < height; ++i) { - const uint8x8_t s = vld1_u8(src_ptr); - src_ptr += src_stride; - for (j = 0; j < 4; ++j) { - const uint8x8_t b_u8 = vld1_u8(ref_loop[j]); - ref_loop[j] += ref_stride; - sum[j] = vabal_u8(sum[j], s, b_u8); - } - } + int i = 0; + do { + const uint8x16_t s = vld1q_u8(src + i * src_stride); + sad16_neon(s, vld1q_u8(ref[0] + i * ref_stride), &sum[0]); + sad16_neon(s, vld1q_u8(ref[1] + i * ref_stride), &sum[1]); + sad16_neon(s, vld1q_u8(ref[2] + i * ref_stride), &sum[2]); + sad16_neon(s, vld1q_u8(ref[3] + i * ref_stride), &sum[3]); - sad_512_pel_final_neon(sum, sad_array); + i++; + } while (i < h); + + vst1q_u32(res, horizontal_add_4d_uint16x8(sum)); } -void vpx_sad8x4x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - sad8x_4d(src_ptr, src_stride, ref_array, ref_stride, sad_array, 4); +static INLINE void sad8_neon(uint8x8_t src, uint8x8_t ref, + uint16x8_t *const sad_sum) { + uint8x8_t abs_diff = vabd_u8(src, ref); + *sad_sum = vaddw_u8(*sad_sum, abs_diff); } -void vpx_sad8x8x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - sad8x_4d(src_ptr, src_stride, ref_array, ref_stride, sad_array, 8); -} - -void vpx_sad8x16x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - sad8x_4d(src_ptr, src_stride, ref_array, ref_stride, sad_array, 16); -} - -//////////////////////////////////////////////////////////////////////////////// - -#if defined(__aarch64__) && defined(__ARM_FEATURE_DOTPROD) && \ - (__ARM_FEATURE_DOTPROD == 1) - -static INLINE void sad16_neon(const uint8_t *ref_ptr, const uint8x16_t src_ptr, - uint32x4_t *const sum) { - const uint8x16_t r = vld1q_u8(ref_ptr); - const uint8x16_t diff = vabdq_u8(src_ptr, r); - *sum = vdotq_u32(*sum, diff, vdupq_n_u8(1)); -} - -static INLINE void sad16x_4d(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4], const int height) { - int i; - uint32x4_t r0, r1; - const uint8_t *ref_loop[4] = { ref_array[0], ref_array[1], ref_array[2], - ref_array[3] }; - uint32x4_t sum[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), - vdupq_n_u32(0) }; - - for (i = 0; i < height; ++i) { - const uint8x16_t s = vld1q_u8(src_ptr + i * src_stride); - sad16_neon(ref_loop[0] + i * ref_stride, s, &sum[0]); - sad16_neon(ref_loop[1] + i * ref_stride, s, &sum[1]); - sad16_neon(ref_loop[2] + i * ref_stride, s, &sum[2]); - sad16_neon(ref_loop[3] + i * ref_stride, s, &sum[3]); - } - - r0 = vpaddq_u32(sum[0], sum[1]); - r1 = vpaddq_u32(sum[2], sum[3]); - vst1q_u32(sad_array, vpaddq_u32(r0, r1)); -} - -#else - -static INLINE void sad16_neon(const uint8_t *ref_ptr, const uint8x16_t src_ptr, - uint16x8_t *const sum) { - const uint8x16_t r = vld1q_u8(ref_ptr); - *sum = vabal_u8(*sum, vget_low_u8(src_ptr), vget_low_u8(r)); - *sum = vabal_u8(*sum, vget_high_u8(src_ptr), vget_high_u8(r)); -} - -static INLINE void sad16x_4d(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4], const int height) { - int i; - const uint8_t *ref_loop[4] = { ref_array[0], ref_array[1], ref_array[2], - ref_array[3] }; +static INLINE void sad8xhx4d_neon(const uint8_t *src, int src_stride, + const uint8_t *const ref[4], int ref_stride, + uint32_t res[4], int h) { uint16x8_t sum[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0) }; - for (i = 0; i < height; ++i) { - const uint8x16_t s = vld1q_u8(src_ptr); - src_ptr += src_stride; - /* Manual unrolling here stops the compiler from getting confused. */ - sad16_neon(ref_loop[0], s, &sum[0]); - ref_loop[0] += ref_stride; - sad16_neon(ref_loop[1], s, &sum[1]); - ref_loop[1] += ref_stride; - sad16_neon(ref_loop[2], s, &sum[2]); - ref_loop[2] += ref_stride; - sad16_neon(ref_loop[3], s, &sum[3]); - ref_loop[3] += ref_stride; - } + int i = 0; + do { + const uint8x8_t s = vld1_u8(src + i * src_stride); + sad8_neon(s, vld1_u8(ref[0] + i * ref_stride), &sum[0]); + sad8_neon(s, vld1_u8(ref[1] + i * ref_stride), &sum[1]); + sad8_neon(s, vld1_u8(ref[2] + i * ref_stride), &sum[2]); + sad8_neon(s, vld1_u8(ref[3] + i * ref_stride), &sum[3]); - sad_512_pel_final_neon(sum, sad_array); + i++; + } while (i < h); + + vst1q_u32(res, horizontal_add_4d_uint16x8(sum)); } -#endif - -void vpx_sad16x8x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - sad16x_4d(src_ptr, src_stride, ref_array, ref_stride, sad_array, 8); -} - -void vpx_sad16x16x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - sad16x_4d(src_ptr, src_stride, ref_array, ref_stride, sad_array, 16); -} - -void vpx_sad16x32x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - sad16x_4d(src_ptr, src_stride, ref_array, ref_stride, sad_array, 32); -} - -//////////////////////////////////////////////////////////////////////////////// - -#if defined(__aarch64__) && defined(__ARM_FEATURE_DOTPROD) && \ - (__ARM_FEATURE_DOTPROD == 1) - -static INLINE void sad32x_4d(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4], const int height) { - int i; - uint32x4_t r0, r1; - const uint8_t *ref_loop[4] = { ref_array[0], ref_array[1], ref_array[2], - ref_array[3] }; - - uint32x4_t sum[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), - vdupq_n_u32(0) }; - - for (i = 0; i < height; ++i) { - uint8x16_t s; - - s = vld1q_u8(src_ptr + 0 * 16); - sad16_neon(ref_loop[0] + 0 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 0 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 0 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 0 * 16, s, &sum[3]); - - s = vld1q_u8(src_ptr + 1 * 16); - sad16_neon(ref_loop[0] + 1 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 1 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 1 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 1 * 16, s, &sum[3]); - - src_ptr += src_stride; - ref_loop[0] += ref_stride; - ref_loop[1] += ref_stride; - ref_loop[2] += ref_stride; - ref_loop[3] += ref_stride; - } - - r0 = vpaddq_u32(sum[0], sum[1]); - r1 = vpaddq_u32(sum[2], sum[3]); - vst1q_u32(sad_array, vpaddq_u32(r0, r1)); -} - -void vpx_sad32x16x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - sad32x_4d(src_ptr, src_stride, ref_array, ref_stride, sad_array, 16); -} - -void vpx_sad32x32x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - sad32x_4d(src_ptr, src_stride, ref_array, ref_stride, sad_array, 32); -} - -void vpx_sad32x64x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - sad32x_4d(src_ptr, src_stride, ref_array, ref_stride, sad_array, 64); -} - -#else - -static INLINE void sad32x_4d(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - const int height, uint16x8_t *const sum) { - int i; - const uint8_t *ref_loop[4] = { ref_array[0], ref_array[1], ref_array[2], - ref_array[3] }; - - sum[0] = sum[1] = sum[2] = sum[3] = vdupq_n_u16(0); - - for (i = 0; i < height; ++i) { - uint8x16_t s; - - s = vld1q_u8(src_ptr + 0 * 16); - sad16_neon(ref_loop[0] + 0 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 0 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 0 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 0 * 16, s, &sum[3]); - - s = vld1q_u8(src_ptr + 1 * 16); - sad16_neon(ref_loop[0] + 1 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 1 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 1 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 1 * 16, s, &sum[3]); - - src_ptr += src_stride; - ref_loop[0] += ref_stride; - ref_loop[1] += ref_stride; - ref_loop[2] += ref_stride; - ref_loop[3] += ref_stride; - } -} - -void vpx_sad32x16x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - uint16x8_t sum[4]; - sad32x_4d(src_ptr, src_stride, ref_array, ref_stride, 16, sum); - sad_512_pel_final_neon(sum, sad_array); -} - -void vpx_sad32x32x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - uint16x8_t sum[4]; - sad32x_4d(src_ptr, src_stride, ref_array, ref_stride, 32, sum); - sad_1024_pel_final_neon(sum, sad_array); -} - -void vpx_sad32x64x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - uint16x8_t sum[4]; - sad32x_4d(src_ptr, src_stride, ref_array, ref_stride, 64, sum); - sad_2048_pel_final_neon(sum, sad_array); -} - -#endif - -//////////////////////////////////////////////////////////////////////////////// - -#if defined(__aarch64__) && defined(__ARM_FEATURE_DOTPROD) && \ - (__ARM_FEATURE_DOTPROD == 1) - -void vpx_sad64x32x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - int i; - uint32x4_t r0, r1; - const uint8_t *ref_loop[4] = { ref_array[0], ref_array[1], ref_array[2], - ref_array[3] }; - uint32x4_t sum[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), - vdupq_n_u32(0) }; - - for (i = 0; i < 32; ++i) { - uint8x16_t s; - - s = vld1q_u8(src_ptr + 0 * 16); - sad16_neon(ref_loop[0] + 0 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 0 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 0 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 0 * 16, s, &sum[3]); - - s = vld1q_u8(src_ptr + 1 * 16); - sad16_neon(ref_loop[0] + 1 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 1 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 1 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 1 * 16, s, &sum[3]); - - s = vld1q_u8(src_ptr + 2 * 16); - sad16_neon(ref_loop[0] + 2 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 2 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 2 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 2 * 16, s, &sum[3]); - - s = vld1q_u8(src_ptr + 3 * 16); - sad16_neon(ref_loop[0] + 3 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 3 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 3 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 3 * 16, s, &sum[3]); - - src_ptr += src_stride; - ref_loop[0] += ref_stride; - ref_loop[1] += ref_stride; - ref_loop[2] += ref_stride; - ref_loop[3] += ref_stride; - } - - r0 = vpaddq_u32(sum[0], sum[1]); - r1 = vpaddq_u32(sum[2], sum[3]); - vst1q_u32(sad_array, vpaddq_u32(r0, r1)); -} - -void vpx_sad64x64x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - int i; - uint32x4_t r0, r1, r2, r3; - const uint8_t *ref_loop[4] = { ref_array[0], ref_array[1], ref_array[2], - ref_array[3] }; - uint32x4_t sum[8] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), - vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), - vdupq_n_u32(0), vdupq_n_u32(0) }; - - for (i = 0; i < 64; ++i) { - uint8x16_t s; - - s = vld1q_u8(src_ptr + 0 * 16); - sad16_neon(ref_loop[0] + 0 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 0 * 16, s, &sum[2]); - sad16_neon(ref_loop[2] + 0 * 16, s, &sum[4]); - sad16_neon(ref_loop[3] + 0 * 16, s, &sum[6]); - - s = vld1q_u8(src_ptr + 1 * 16); - sad16_neon(ref_loop[0] + 1 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 1 * 16, s, &sum[2]); - sad16_neon(ref_loop[2] + 1 * 16, s, &sum[4]); - sad16_neon(ref_loop[3] + 1 * 16, s, &sum[6]); - - s = vld1q_u8(src_ptr + 2 * 16); - sad16_neon(ref_loop[0] + 2 * 16, s, &sum[1]); - sad16_neon(ref_loop[1] + 2 * 16, s, &sum[3]); - sad16_neon(ref_loop[2] + 2 * 16, s, &sum[5]); - sad16_neon(ref_loop[3] + 2 * 16, s, &sum[7]); - - s = vld1q_u8(src_ptr + 3 * 16); - sad16_neon(ref_loop[0] + 3 * 16, s, &sum[1]); - sad16_neon(ref_loop[1] + 3 * 16, s, &sum[3]); - sad16_neon(ref_loop[2] + 3 * 16, s, &sum[5]); - sad16_neon(ref_loop[3] + 3 * 16, s, &sum[7]); - - src_ptr += src_stride; - ref_loop[0] += ref_stride; - ref_loop[1] += ref_stride; - ref_loop[2] += ref_stride; - ref_loop[3] += ref_stride; - } - - r0 = vpaddq_u32(sum[0], sum[1]); - r1 = vpaddq_u32(sum[2], sum[3]); - r2 = vpaddq_u32(sum[4], sum[5]); - r3 = vpaddq_u32(sum[6], sum[7]); - r0 = vpaddq_u32(r0, r1); - r1 = vpaddq_u32(r2, r3); - vst1q_u32(sad_array, vpaddq_u32(r0, r1)); -} - -#else - -void vpx_sad64x32x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - int i; - const uint8_t *ref_loop[4] = { ref_array[0], ref_array[1], ref_array[2], - ref_array[3] }; +static INLINE void sad4xhx4d_neon(const uint8_t *src, int src_stride, + const uint8_t *const ref[4], int ref_stride, + uint32_t res[4], int h) { uint16x8_t sum[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0) }; - for (i = 0; i < 32; ++i) { - uint8x16_t s; + int i = 0; + do { + uint8x8_t s = load_unaligned_u8(src + i * src_stride, src_stride); + uint8x8_t r0 = load_unaligned_u8(ref[0] + i * ref_stride, ref_stride); + uint8x8_t r1 = load_unaligned_u8(ref[1] + i * ref_stride, ref_stride); + uint8x8_t r2 = load_unaligned_u8(ref[2] + i * ref_stride, ref_stride); + uint8x8_t r3 = load_unaligned_u8(ref[3] + i * ref_stride, ref_stride); - s = vld1q_u8(src_ptr + 0 * 16); - sad16_neon(ref_loop[0] + 0 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 0 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 0 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 0 * 16, s, &sum[3]); + sad8_neon(s, r0, &sum[0]); + sad8_neon(s, r1, &sum[1]); + sad8_neon(s, r2, &sum[2]); + sad8_neon(s, r3, &sum[3]); - s = vld1q_u8(src_ptr + 1 * 16); - sad16_neon(ref_loop[0] + 1 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 1 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 1 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 1 * 16, s, &sum[3]); + i += 2; + } while (i < h); - s = vld1q_u8(src_ptr + 2 * 16); - sad16_neon(ref_loop[0] + 2 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 2 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 2 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 2 * 16, s, &sum[3]); - - s = vld1q_u8(src_ptr + 3 * 16); - sad16_neon(ref_loop[0] + 3 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 3 * 16, s, &sum[1]); - sad16_neon(ref_loop[2] + 3 * 16, s, &sum[2]); - sad16_neon(ref_loop[3] + 3 * 16, s, &sum[3]); - - src_ptr += src_stride; - ref_loop[0] += ref_stride; - ref_loop[1] += ref_stride; - ref_loop[2] += ref_stride; - ref_loop[3] += ref_stride; - } - - sad_2048_pel_final_neon(sum, sad_array); + vst1q_u32(res, horizontal_add_4d_uint16x8(sum)); } -void vpx_sad64x64x4d_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { - int i; - const uint8_t *ref_loop[4] = { ref_array[0], ref_array[1], ref_array[2], - ref_array[3] }; - uint16x8_t sum[8] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), - vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), - vdupq_n_u16(0), vdupq_n_u16(0) }; - - for (i = 0; i < 64; ++i) { - uint8x16_t s; - - s = vld1q_u8(src_ptr + 0 * 16); - sad16_neon(ref_loop[0] + 0 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 0 * 16, s, &sum[2]); - sad16_neon(ref_loop[2] + 0 * 16, s, &sum[4]); - sad16_neon(ref_loop[3] + 0 * 16, s, &sum[6]); - - s = vld1q_u8(src_ptr + 1 * 16); - sad16_neon(ref_loop[0] + 1 * 16, s, &sum[0]); - sad16_neon(ref_loop[1] + 1 * 16, s, &sum[2]); - sad16_neon(ref_loop[2] + 1 * 16, s, &sum[4]); - sad16_neon(ref_loop[3] + 1 * 16, s, &sum[6]); - - s = vld1q_u8(src_ptr + 2 * 16); - sad16_neon(ref_loop[0] + 2 * 16, s, &sum[1]); - sad16_neon(ref_loop[1] + 2 * 16, s, &sum[3]); - sad16_neon(ref_loop[2] + 2 * 16, s, &sum[5]); - sad16_neon(ref_loop[3] + 2 * 16, s, &sum[7]); - - s = vld1q_u8(src_ptr + 3 * 16); - sad16_neon(ref_loop[0] + 3 * 16, s, &sum[1]); - sad16_neon(ref_loop[1] + 3 * 16, s, &sum[3]); - sad16_neon(ref_loop[2] + 3 * 16, s, &sum[5]); - sad16_neon(ref_loop[3] + 3 * 16, s, &sum[7]); - - src_ptr += src_stride; - ref_loop[0] += ref_stride; - ref_loop[1] += ref_stride; - ref_loop[2] += ref_stride; - ref_loop[3] += ref_stride; +#define SAD_WXH_4D_NEON(w, h) \ + void vpx_sad##w##x##h##x4d_neon(const uint8_t *src_ptr, int src_stride, \ + const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + sad##w##xhx4d_neon(src_ptr, src_stride, ref_array, ref_stride, sad_array, \ + (h)); \ } - sad_4096_pel_final_neon(sum, sad_array); -} +SAD_WXH_4D_NEON(4, 4) +SAD_WXH_4D_NEON(4, 8) -#endif +SAD_WXH_4D_NEON(8, 4) +SAD_WXH_4D_NEON(8, 8) +SAD_WXH_4D_NEON(8, 16) + +SAD_WXH_4D_NEON(16, 8) +SAD_WXH_4D_NEON(16, 16) +SAD_WXH_4D_NEON(16, 32) + +SAD_WXH_4D_NEON(32, 16) +SAD_WXH_4D_NEON(32, 32) +SAD_WXH_4D_NEON(32, 64) + +SAD_WXH_4D_NEON(64, 32) +SAD_WXH_4D_NEON(64, 64) + +#undef SAD_WXH_4D_NEON + +#define SAD_SKIP_WXH_4D_NEON(w, h) \ + void vpx_sad_skip_##w##x##h##x4d_neon( \ + const uint8_t *src_ptr, int src_stride, \ + const uint8_t *const ref_array[4], int ref_stride, \ + uint32_t sad_array[4]) { \ + sad##w##xhx4d_neon(src_ptr, 2 * src_stride, ref_array, 2 * ref_stride, \ + sad_array, ((h) >> 1)); \ + sad_array[0] <<= 1; \ + sad_array[1] <<= 1; \ + sad_array[2] <<= 1; \ + sad_array[3] <<= 1; \ + } + +SAD_SKIP_WXH_4D_NEON(4, 4) +SAD_SKIP_WXH_4D_NEON(4, 8) + +SAD_SKIP_WXH_4D_NEON(8, 4) +SAD_SKIP_WXH_4D_NEON(8, 8) +SAD_SKIP_WXH_4D_NEON(8, 16) + +SAD_SKIP_WXH_4D_NEON(16, 8) +SAD_SKIP_WXH_4D_NEON(16, 16) +SAD_SKIP_WXH_4D_NEON(16, 32) + +SAD_SKIP_WXH_4D_NEON(32, 16) +SAD_SKIP_WXH_4D_NEON(32, 32) +SAD_SKIP_WXH_4D_NEON(32, 64) + +SAD_SKIP_WXH_4D_NEON(64, 32) +SAD_SKIP_WXH_4D_NEON(64, 64) + +#undef SAD_SKIP_WXH_4D_NEON diff --git a/libs/libvpx/vpx_dsp/arm/sad4d_neon_dotprod.c b/libs/libvpx/vpx_dsp/arm/sad4d_neon_dotprod.c new file mode 100644 index 0000000000..b587122a36 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/sad4d_neon_dotprod.c @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2021 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" + +static INLINE void sad16_neon(uint8x16_t src, uint8x16_t ref, + uint32x4_t *const sad_sum) { + uint8x16_t abs_diff = vabdq_u8(src, ref); + *sad_sum = vdotq_u32(*sad_sum, abs_diff, vdupq_n_u8(1)); +} + +static INLINE void sad64xhx4d_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *const ref[4], + int ref_stride, uint32_t res[4], + int h) { + uint32x4_t sum_lo[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), + vdupq_n_u32(0) }; + uint32x4_t sum_hi[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), + vdupq_n_u32(0) }; + uint32x4_t sum[4]; + + int i = 0; + do { + uint8x16_t s0, s1, s2, s3; + + s0 = vld1q_u8(src + i * src_stride); + sad16_neon(s0, vld1q_u8(ref[0] + i * ref_stride), &sum_lo[0]); + sad16_neon(s0, vld1q_u8(ref[1] + i * ref_stride), &sum_lo[1]); + sad16_neon(s0, vld1q_u8(ref[2] + i * ref_stride), &sum_lo[2]); + sad16_neon(s0, vld1q_u8(ref[3] + i * ref_stride), &sum_lo[3]); + + s1 = vld1q_u8(src + i * src_stride + 16); + sad16_neon(s1, vld1q_u8(ref[0] + i * ref_stride + 16), &sum_hi[0]); + sad16_neon(s1, vld1q_u8(ref[1] + i * ref_stride + 16), &sum_hi[1]); + sad16_neon(s1, vld1q_u8(ref[2] + i * ref_stride + 16), &sum_hi[2]); + sad16_neon(s1, vld1q_u8(ref[3] + i * ref_stride + 16), &sum_hi[3]); + + s2 = vld1q_u8(src + i * src_stride + 32); + sad16_neon(s2, vld1q_u8(ref[0] + i * ref_stride + 32), &sum_lo[0]); + sad16_neon(s2, vld1q_u8(ref[1] + i * ref_stride + 32), &sum_lo[1]); + sad16_neon(s2, vld1q_u8(ref[2] + i * ref_stride + 32), &sum_lo[2]); + sad16_neon(s2, vld1q_u8(ref[3] + i * ref_stride + 32), &sum_lo[3]); + + s3 = vld1q_u8(src + i * src_stride + 48); + sad16_neon(s3, vld1q_u8(ref[0] + i * ref_stride + 48), &sum_hi[0]); + sad16_neon(s3, vld1q_u8(ref[1] + i * ref_stride + 48), &sum_hi[1]); + sad16_neon(s3, vld1q_u8(ref[2] + i * ref_stride + 48), &sum_hi[2]); + sad16_neon(s3, vld1q_u8(ref[3] + i * ref_stride + 48), &sum_hi[3]); + + } while (++i < h); + + sum[0] = vaddq_u32(sum_lo[0], sum_hi[0]); + sum[1] = vaddq_u32(sum_lo[1], sum_hi[1]); + sum[2] = vaddq_u32(sum_lo[2], sum_hi[2]); + sum[3] = vaddq_u32(sum_lo[3], sum_hi[3]); + + vst1q_u32(res, horizontal_add_4d_uint32x4(sum)); +} + +static INLINE void sad32xhx4d_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *const ref[4], + int ref_stride, uint32_t res[4], + int h) { + uint32x4_t sum_lo[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), + vdupq_n_u32(0) }; + uint32x4_t sum_hi[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), + vdupq_n_u32(0) }; + uint32x4_t sum[4]; + + int i = 0; + do { + uint8x16_t s0, s1; + + s0 = vld1q_u8(src + i * src_stride); + sad16_neon(s0, vld1q_u8(ref[0] + i * ref_stride), &sum_lo[0]); + sad16_neon(s0, vld1q_u8(ref[1] + i * ref_stride), &sum_lo[1]); + sad16_neon(s0, vld1q_u8(ref[2] + i * ref_stride), &sum_lo[2]); + sad16_neon(s0, vld1q_u8(ref[3] + i * ref_stride), &sum_lo[3]); + + s1 = vld1q_u8(src + i * src_stride + 16); + sad16_neon(s1, vld1q_u8(ref[0] + i * ref_stride + 16), &sum_hi[0]); + sad16_neon(s1, vld1q_u8(ref[1] + i * ref_stride + 16), &sum_hi[1]); + sad16_neon(s1, vld1q_u8(ref[2] + i * ref_stride + 16), &sum_hi[2]); + sad16_neon(s1, vld1q_u8(ref[3] + i * ref_stride + 16), &sum_hi[3]); + + } while (++i < h); + + sum[0] = vaddq_u32(sum_lo[0], sum_hi[0]); + sum[1] = vaddq_u32(sum_lo[1], sum_hi[1]); + sum[2] = vaddq_u32(sum_lo[2], sum_hi[2]); + sum[3] = vaddq_u32(sum_lo[3], sum_hi[3]); + + vst1q_u32(res, horizontal_add_4d_uint32x4(sum)); +} + +static INLINE void sad16xhx4d_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *const ref[4], + int ref_stride, uint32_t res[4], + int h) { + uint32x4_t sum[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), + vdupq_n_u32(0) }; + + int i = 0; + // Balance loop overhead and register pressure in the short SAD kernels. +#if VPX_ARCH_AARCH64 && defined(__GNUC__) && !defined(__clang__) && \ + __GNUC__ >= 8 +#pragma GCC unroll 2 +#endif + do { + const uint8x16_t s = vld1q_u8(src + i * src_stride); + sad16_neon(s, vld1q_u8(ref[0] + i * ref_stride), &sum[0]); + sad16_neon(s, vld1q_u8(ref[1] + i * ref_stride), &sum[1]); + sad16_neon(s, vld1q_u8(ref[2] + i * ref_stride), &sum[2]); + sad16_neon(s, vld1q_u8(ref[3] + i * ref_stride), &sum[3]); + + } while (++i < h); + + vst1q_u32(res, horizontal_add_4d_uint32x4(sum)); +} + +#define SAD_WXH_4D_NEON_DOTPROD(w, h) \ + void vpx_sad##w##x##h##x4d_neon_dotprod( \ + const uint8_t *src_ptr, int src_stride, \ + const uint8_t *const ref_array[4], int ref_stride, \ + uint32_t sad_array[4]) { \ + sad##w##xhx4d_neon_dotprod(src_ptr, src_stride, ref_array, ref_stride, \ + sad_array, (h)); \ + } + +SAD_WXH_4D_NEON_DOTPROD(16, 8) +SAD_WXH_4D_NEON_DOTPROD(16, 16) +SAD_WXH_4D_NEON_DOTPROD(16, 32) + +SAD_WXH_4D_NEON_DOTPROD(32, 16) +SAD_WXH_4D_NEON_DOTPROD(32, 32) +SAD_WXH_4D_NEON_DOTPROD(32, 64) + +SAD_WXH_4D_NEON_DOTPROD(64, 32) +SAD_WXH_4D_NEON_DOTPROD(64, 64) + +#undef SAD_WXH_4D_NEON_DOTPROD + +#define SAD_SKIP_WXH_4D_NEON_DOTPROD(w, h) \ + void vpx_sad_skip_##w##x##h##x4d_neon_dotprod( \ + const uint8_t *src_ptr, int src_stride, \ + const uint8_t *const ref_array[4], int ref_stride, \ + uint32_t sad_array[4]) { \ + sad##w##xhx4d_neon_dotprod(src_ptr, 2 * src_stride, ref_array, \ + 2 * ref_stride, sad_array, ((h) >> 1)); \ + sad_array[0] <<= 1; \ + sad_array[1] <<= 1; \ + sad_array[2] <<= 1; \ + sad_array[3] <<= 1; \ + } + +SAD_SKIP_WXH_4D_NEON_DOTPROD(16, 8) +SAD_SKIP_WXH_4D_NEON_DOTPROD(16, 16) +SAD_SKIP_WXH_4D_NEON_DOTPROD(16, 32) + +SAD_SKIP_WXH_4D_NEON_DOTPROD(32, 16) +SAD_SKIP_WXH_4D_NEON_DOTPROD(32, 32) +SAD_SKIP_WXH_4D_NEON_DOTPROD(32, 64) + +SAD_SKIP_WXH_4D_NEON_DOTPROD(64, 32) +SAD_SKIP_WXH_4D_NEON_DOTPROD(64, 64) + +#undef SAD_SKIP_WXH_4D_NEON_DOTPROD diff --git a/libs/libvpx/vpx_dsp/arm/sad_neon.c b/libs/libvpx/vpx_dsp/arm/sad_neon.c index b1509d883a..d7013bdaaf 100644 --- a/libs/libvpx/vpx_dsp/arm/sad_neon.c +++ b/libs/libvpx/vpx_dsp/arm/sad_neon.c @@ -17,337 +17,385 @@ #include "vpx_dsp/arm/mem_neon.h" #include "vpx_dsp/arm/sum_neon.h" -uint32_t vpx_sad4x4_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride) { - const uint8x16_t src_u8 = load_unaligned_u8q(src_ptr, src_stride); - const uint8x16_t ref_u8 = load_unaligned_u8q(ref_ptr, ref_stride); - uint16x8_t abs = vabdl_u8(vget_low_u8(src_u8), vget_low_u8(ref_u8)); - abs = vabal_u8(abs, vget_high_u8(src_u8), vget_high_u8(ref_u8)); - return horizontal_add_uint16x8(abs); -} +static INLINE unsigned int sad64xh_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + int h) { + uint16x8_t sum[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), + vdupq_n_u16(0) }; + uint32x4_t sum_u32; -uint32_t vpx_sad4x4_avg_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - const uint8_t *second_pred) { - const uint8x16_t src_u8 = load_unaligned_u8q(src_ptr, src_stride); - const uint8x16_t ref_u8 = load_unaligned_u8q(ref_ptr, ref_stride); - const uint8x16_t second_pred_u8 = vld1q_u8(second_pred); - const uint8x16_t avg = vrhaddq_u8(ref_u8, second_pred_u8); - uint16x8_t abs = vabdl_u8(vget_low_u8(src_u8), vget_low_u8(avg)); - abs = vabal_u8(abs, vget_high_u8(src_u8), vget_high_u8(avg)); - return horizontal_add_uint16x8(abs); -} + int i = h; + do { + uint8x16_t s0, s1, s2, s3, r0, r1, r2, r3; + uint8x16_t diff0, diff1, diff2, diff3; -uint32_t vpx_sad4x8_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride) { - int i; - uint16x8_t abs = vdupq_n_u16(0); - for (i = 0; i < 8; i += 4) { - const uint8x16_t src_u8 = load_unaligned_u8q(src_ptr, src_stride); - const uint8x16_t ref_u8 = load_unaligned_u8q(ref_ptr, ref_stride); - src_ptr += 4 * src_stride; - ref_ptr += 4 * ref_stride; - abs = vabal_u8(abs, vget_low_u8(src_u8), vget_low_u8(ref_u8)); - abs = vabal_u8(abs, vget_high_u8(src_u8), vget_high_u8(ref_u8)); - } + s0 = vld1q_u8(src_ptr); + r0 = vld1q_u8(ref_ptr); + diff0 = vabdq_u8(s0, r0); + sum[0] = vpadalq_u8(sum[0], diff0); - return horizontal_add_uint16x8(abs); -} + s1 = vld1q_u8(src_ptr + 16); + r1 = vld1q_u8(ref_ptr + 16); + diff1 = vabdq_u8(s1, r1); + sum[1] = vpadalq_u8(sum[1], diff1); -uint32_t vpx_sad4x8_avg_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - const uint8_t *second_pred) { - int i; - uint16x8_t abs = vdupq_n_u16(0); - for (i = 0; i < 8; i += 4) { - const uint8x16_t src_u8 = load_unaligned_u8q(src_ptr, src_stride); - const uint8x16_t ref_u8 = load_unaligned_u8q(ref_ptr, ref_stride); - const uint8x16_t second_pred_u8 = vld1q_u8(second_pred); - const uint8x16_t avg = vrhaddq_u8(ref_u8, second_pred_u8); - src_ptr += 4 * src_stride; - ref_ptr += 4 * ref_stride; - second_pred += 16; - abs = vabal_u8(abs, vget_low_u8(src_u8), vget_low_u8(avg)); - abs = vabal_u8(abs, vget_high_u8(src_u8), vget_high_u8(avg)); - } + s2 = vld1q_u8(src_ptr + 32); + r2 = vld1q_u8(ref_ptr + 32); + diff2 = vabdq_u8(s2, r2); + sum[2] = vpadalq_u8(sum[2], diff2); - return horizontal_add_uint16x8(abs); -} + s3 = vld1q_u8(src_ptr + 48); + r3 = vld1q_u8(ref_ptr + 48); + diff3 = vabdq_u8(s3, r3); + sum[3] = vpadalq_u8(sum[3], diff3); -static INLINE uint16x8_t sad8x(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - const int height) { - int i; - uint16x8_t abs = vdupq_n_u16(0); - - for (i = 0; i < height; ++i) { - const uint8x8_t a_u8 = vld1_u8(src_ptr); - const uint8x8_t b_u8 = vld1_u8(ref_ptr); src_ptr += src_stride; ref_ptr += ref_stride; - abs = vabal_u8(abs, a_u8, b_u8); - } - return abs; + } while (--i != 0); + + sum_u32 = vpaddlq_u16(sum[0]); + sum_u32 = vpadalq_u16(sum_u32, sum[1]); + sum_u32 = vpadalq_u16(sum_u32, sum[2]); + sum_u32 = vpadalq_u16(sum_u32, sum[3]); + + return horizontal_add_uint32x4(sum_u32); } -static INLINE uint16x8_t sad8x_avg(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - const uint8_t *second_pred, - const int height) { - int i; - uint16x8_t abs = vdupq_n_u16(0); +static INLINE unsigned int sad32xh_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + int h) { + uint32x4_t sum = vdupq_n_u32(0); + + int i = h; + do { + uint8x16_t s0 = vld1q_u8(src_ptr); + uint8x16_t r0 = vld1q_u8(ref_ptr); + uint8x16_t diff0 = vabdq_u8(s0, r0); + uint16x8_t sum0 = vpaddlq_u8(diff0); + + uint8x16_t s1 = vld1q_u8(src_ptr + 16); + uint8x16_t r1 = vld1q_u8(ref_ptr + 16); + uint8x16_t diff1 = vabdq_u8(s1, r1); + uint16x8_t sum1 = vpaddlq_u8(diff1); + + sum = vpadalq_u16(sum, sum0); + sum = vpadalq_u16(sum, sum1); - for (i = 0; i < height; ++i) { - const uint8x8_t a_u8 = vld1_u8(src_ptr); - const uint8x8_t b_u8 = vld1_u8(ref_ptr); - const uint8x8_t c_u8 = vld1_u8(second_pred); - const uint8x8_t avg = vrhadd_u8(b_u8, c_u8); src_ptr += src_stride; ref_ptr += ref_stride; - second_pred += 8; - abs = vabal_u8(abs, a_u8, avg); - } - return abs; + } while (--i != 0); + + return horizontal_add_uint32x4(sum); } -#define SAD8XN(n) \ - uint32_t vpx_sad8x##n##_neon(const uint8_t *src_ptr, int src_stride, \ - const uint8_t *ref_ptr, int ref_stride) { \ - const uint16x8_t abs = sad8x(src_ptr, src_stride, ref_ptr, ref_stride, n); \ - return horizontal_add_uint16x8(abs); \ - } \ - \ - uint32_t vpx_sad8x##n##_avg_neon(const uint8_t *src_ptr, int src_stride, \ - const uint8_t *ref_ptr, int ref_stride, \ - const uint8_t *second_pred) { \ - const uint16x8_t abs = \ - sad8x_avg(src_ptr, src_stride, ref_ptr, ref_stride, second_pred, n); \ - return horizontal_add_uint16x8(abs); \ - } +static INLINE unsigned int sad16xh_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + int h) { + uint16x8_t sum = vdupq_n_u16(0); -SAD8XN(4) -SAD8XN(8) -SAD8XN(16) + int i = h; + do { + uint8x16_t s = vld1q_u8(src_ptr); + uint8x16_t r = vld1q_u8(ref_ptr); -static INLINE uint16x8_t sad16x(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - const int height) { - int i; - uint16x8_t abs = vdupq_n_u16(0); + uint8x16_t diff = vabdq_u8(s, r); + sum = vpadalq_u8(sum, diff); - for (i = 0; i < height; ++i) { - const uint8x16_t a_u8 = vld1q_u8(src_ptr); - const uint8x16_t b_u8 = vld1q_u8(ref_ptr); src_ptr += src_stride; ref_ptr += ref_stride; - abs = vabal_u8(abs, vget_low_u8(a_u8), vget_low_u8(b_u8)); - abs = vabal_u8(abs, vget_high_u8(a_u8), vget_high_u8(b_u8)); - } - return abs; + } while (--i != 0); + + return horizontal_add_uint16x8(sum); } -static INLINE uint16x8_t sad16x_avg(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - const uint8_t *second_pred, - const int height) { - int i; - uint16x8_t abs = vdupq_n_u16(0); +#if CONFIG_ENCODERS +static INLINE unsigned int sad8xh_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + int h) { + uint16x8_t sum = vdupq_n_u16(0); + + int i = h; + do { + uint8x8_t s = vld1_u8(src_ptr); + uint8x8_t r = vld1_u8(ref_ptr); + + sum = vabal_u8(sum, s, r); - for (i = 0; i < height; ++i) { - const uint8x16_t a_u8 = vld1q_u8(src_ptr); - const uint8x16_t b_u8 = vld1q_u8(ref_ptr); - const uint8x16_t c_u8 = vld1q_u8(second_pred); - const uint8x16_t avg = vrhaddq_u8(b_u8, c_u8); src_ptr += src_stride; ref_ptr += ref_stride; - second_pred += 16; - abs = vabal_u8(abs, vget_low_u8(a_u8), vget_low_u8(avg)); - abs = vabal_u8(abs, vget_high_u8(a_u8), vget_high_u8(avg)); - } - return abs; + } while (--i != 0); + + return horizontal_add_uint16x8(sum); } -#define SAD16XN(n) \ - uint32_t vpx_sad16x##n##_neon(const uint8_t *src_ptr, int src_stride, \ - const uint8_t *ref_ptr, int ref_stride) { \ - const uint16x8_t abs = \ - sad16x(src_ptr, src_stride, ref_ptr, ref_stride, n); \ - return horizontal_add_uint16x8(abs); \ - } \ - \ - uint32_t vpx_sad16x##n##_avg_neon(const uint8_t *src_ptr, int src_stride, \ - const uint8_t *ref_ptr, int ref_stride, \ - const uint8_t *second_pred) { \ - const uint16x8_t abs = \ - sad16x_avg(src_ptr, src_stride, ref_ptr, ref_stride, second_pred, n); \ - return horizontal_add_uint16x8(abs); \ - } +static INLINE unsigned int sad4xh_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + int h) { + uint16x8_t sum = vdupq_n_u16(0); -SAD16XN(8) -SAD16XN(16) -SAD16XN(32) + int i = h / 2; + do { + uint8x8_t s = load_unaligned_u8(src_ptr, src_stride); + uint8x8_t r = load_unaligned_u8(ref_ptr, ref_stride); -static INLINE uint16x8_t sad32x(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - const int height) { - int i; - uint16x8_t abs = vdupq_n_u16(0); + sum = vabal_u8(sum, s, r); - for (i = 0; i < height; ++i) { - const uint8x16_t a_lo = vld1q_u8(src_ptr); - const uint8x16_t a_hi = vld1q_u8(src_ptr + 16); - const uint8x16_t b_lo = vld1q_u8(ref_ptr); - const uint8x16_t b_hi = vld1q_u8(ref_ptr + 16); - src_ptr += src_stride; - ref_ptr += ref_stride; - abs = vabal_u8(abs, vget_low_u8(a_lo), vget_low_u8(b_lo)); - abs = vabal_u8(abs, vget_high_u8(a_lo), vget_high_u8(b_lo)); - abs = vabal_u8(abs, vget_low_u8(a_hi), vget_low_u8(b_hi)); - abs = vabal_u8(abs, vget_high_u8(a_hi), vget_high_u8(b_hi)); - } - return abs; + src_ptr += 2 * src_stride; + ref_ptr += 2 * ref_stride; + } while (--i != 0); + + return horizontal_add_uint16x8(sum); } +#endif // CONFIG_ENCODERS -static INLINE uint16x8_t sad32x_avg(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - const uint8_t *second_pred, - const int height) { - int i; - uint16x8_t abs = vdupq_n_u16(0); - - for (i = 0; i < height; ++i) { - const uint8x16_t a_lo = vld1q_u8(src_ptr); - const uint8x16_t a_hi = vld1q_u8(src_ptr + 16); - const uint8x16_t b_lo = vld1q_u8(ref_ptr); - const uint8x16_t b_hi = vld1q_u8(ref_ptr + 16); - const uint8x16_t c_lo = vld1q_u8(second_pred); - const uint8x16_t c_hi = vld1q_u8(second_pred + 16); - const uint8x16_t avg_lo = vrhaddq_u8(b_lo, c_lo); - const uint8x16_t avg_hi = vrhaddq_u8(b_hi, c_hi); - src_ptr += src_stride; - ref_ptr += ref_stride; - second_pred += 32; - abs = vabal_u8(abs, vget_low_u8(a_lo), vget_low_u8(avg_lo)); - abs = vabal_u8(abs, vget_high_u8(a_lo), vget_high_u8(avg_lo)); - abs = vabal_u8(abs, vget_low_u8(a_hi), vget_low_u8(avg_hi)); - abs = vabal_u8(abs, vget_high_u8(a_hi), vget_high_u8(avg_hi)); - } - return abs; -} - -#define SAD32XN(n) \ - uint32_t vpx_sad32x##n##_neon(const uint8_t *src_ptr, int src_stride, \ - const uint8_t *ref_ptr, int ref_stride) { \ - const uint16x8_t abs = \ - sad32x(src_ptr, src_stride, ref_ptr, ref_stride, n); \ - return horizontal_add_uint16x8(abs); \ - } \ - \ - uint32_t vpx_sad32x##n##_avg_neon(const uint8_t *src_ptr, int src_stride, \ - const uint8_t *ref_ptr, int ref_stride, \ - const uint8_t *second_pred) { \ - const uint16x8_t abs = \ - sad32x_avg(src_ptr, src_stride, ref_ptr, ref_stride, second_pred, n); \ - return horizontal_add_uint16x8(abs); \ +#define SAD_WXH_NEON(w, h) \ + unsigned int vpx_sad##w##x##h##_neon(const uint8_t *src, int src_stride, \ + const uint8_t *ref, int ref_stride) { \ + return sad##w##xh_neon(src, src_stride, ref, ref_stride, (h)); \ } -SAD32XN(16) -SAD32XN(32) -SAD32XN(64) +#if CONFIG_ENCODERS +SAD_WXH_NEON(4, 4) +SAD_WXH_NEON(4, 8) -static INLINE uint32x4_t sad64x(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - const int height) { - int i; - uint16x8_t abs_0 = vdupq_n_u16(0); - uint16x8_t abs_1 = vdupq_n_u16(0); +SAD_WXH_NEON(8, 4) +SAD_WXH_NEON(8, 8) +SAD_WXH_NEON(8, 16) - for (i = 0; i < height; ++i) { - const uint8x16_t a_0 = vld1q_u8(src_ptr); - const uint8x16_t a_1 = vld1q_u8(src_ptr + 16); - const uint8x16_t a_2 = vld1q_u8(src_ptr + 32); - const uint8x16_t a_3 = vld1q_u8(src_ptr + 48); - const uint8x16_t b_0 = vld1q_u8(ref_ptr); - const uint8x16_t b_1 = vld1q_u8(ref_ptr + 16); - const uint8x16_t b_2 = vld1q_u8(ref_ptr + 32); - const uint8x16_t b_3 = vld1q_u8(ref_ptr + 48); - src_ptr += src_stride; - ref_ptr += ref_stride; - abs_0 = vabal_u8(abs_0, vget_low_u8(a_0), vget_low_u8(b_0)); - abs_0 = vabal_u8(abs_0, vget_high_u8(a_0), vget_high_u8(b_0)); - abs_0 = vabal_u8(abs_0, vget_low_u8(a_1), vget_low_u8(b_1)); - abs_0 = vabal_u8(abs_0, vget_high_u8(a_1), vget_high_u8(b_1)); - abs_1 = vabal_u8(abs_1, vget_low_u8(a_2), vget_low_u8(b_2)); - abs_1 = vabal_u8(abs_1, vget_high_u8(a_2), vget_high_u8(b_2)); - abs_1 = vabal_u8(abs_1, vget_low_u8(a_3), vget_low_u8(b_3)); - abs_1 = vabal_u8(abs_1, vget_high_u8(a_3), vget_high_u8(b_3)); +SAD_WXH_NEON(16, 8) +SAD_WXH_NEON(16, 16) +SAD_WXH_NEON(16, 32) + +SAD_WXH_NEON(32, 16) +SAD_WXH_NEON(32, 32) +SAD_WXH_NEON(32, 64) + +SAD_WXH_NEON(64, 32) +SAD_WXH_NEON(64, 64) +#else // !CONFIG_ENCODERS +SAD_WXH_NEON(16, 16) +SAD_WXH_NEON(32, 32) +SAD_WXH_NEON(64, 64) +#endif // CONFIG_ENCODERS + +#undef SAD_WXH_NEON + +#if CONFIG_ENCODERS +#define SAD_SKIP_WXH_NEON(w, h) \ + unsigned int vpx_sad_skip_##w##x##h##_neon( \ + const uint8_t *src, int src_stride, const uint8_t *ref, \ + int ref_stride) { \ + return 2 * \ + sad##w##xh_neon(src, 2 * src_stride, ref, 2 * ref_stride, (h) / 2); \ } - { - const uint32x4_t sum = vpaddlq_u16(abs_0); - return vpadalq_u16(sum, abs_1); - } -} +SAD_SKIP_WXH_NEON(4, 4) +SAD_SKIP_WXH_NEON(4, 8) -static INLINE uint32x4_t sad64x_avg(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - const uint8_t *second_pred, - const int height) { - int i; - uint16x8_t abs_0 = vdupq_n_u16(0); - uint16x8_t abs_1 = vdupq_n_u16(0); +SAD_SKIP_WXH_NEON(8, 4) +SAD_SKIP_WXH_NEON(8, 8) +SAD_SKIP_WXH_NEON(8, 16) + +SAD_SKIP_WXH_NEON(16, 8) +SAD_SKIP_WXH_NEON(16, 16) +SAD_SKIP_WXH_NEON(16, 32) + +SAD_SKIP_WXH_NEON(32, 16) +SAD_SKIP_WXH_NEON(32, 32) +SAD_SKIP_WXH_NEON(32, 64) + +SAD_SKIP_WXH_NEON(64, 32) +SAD_SKIP_WXH_NEON(64, 64) + +#undef SAD_SKIP_WXH_NEON + +static INLINE unsigned int sad64xh_avg_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + const uint8_t *second_pred) { + uint16x8_t sum[4] = { vdupq_n_u16(0), vdupq_n_u16(0), vdupq_n_u16(0), + vdupq_n_u16(0) }; + uint32x4_t sum_u32; + + int i = h; + do { + uint8x16_t s0, s1, s2, s3, r0, r1, r2, r3, p0, p1, p2, p3; + uint8x16_t avg0, avg1, avg2, avg3, diff0, diff1, diff2, diff3; + + s0 = vld1q_u8(src_ptr); + r0 = vld1q_u8(ref_ptr); + p0 = vld1q_u8(second_pred); + avg0 = vrhaddq_u8(r0, p0); + diff0 = vabdq_u8(s0, avg0); + sum[0] = vpadalq_u8(sum[0], diff0); + + s1 = vld1q_u8(src_ptr + 16); + r1 = vld1q_u8(ref_ptr + 16); + p1 = vld1q_u8(second_pred + 16); + avg1 = vrhaddq_u8(r1, p1); + diff1 = vabdq_u8(s1, avg1); + sum[1] = vpadalq_u8(sum[1], diff1); + + s2 = vld1q_u8(src_ptr + 32); + r2 = vld1q_u8(ref_ptr + 32); + p2 = vld1q_u8(second_pred + 32); + avg2 = vrhaddq_u8(r2, p2); + diff2 = vabdq_u8(s2, avg2); + sum[2] = vpadalq_u8(sum[2], diff2); + + s3 = vld1q_u8(src_ptr + 48); + r3 = vld1q_u8(ref_ptr + 48); + p3 = vld1q_u8(second_pred + 48); + avg3 = vrhaddq_u8(r3, p3); + diff3 = vabdq_u8(s3, avg3); + sum[3] = vpadalq_u8(sum[3], diff3); - for (i = 0; i < height; ++i) { - const uint8x16_t a_0 = vld1q_u8(src_ptr); - const uint8x16_t a_1 = vld1q_u8(src_ptr + 16); - const uint8x16_t a_2 = vld1q_u8(src_ptr + 32); - const uint8x16_t a_3 = vld1q_u8(src_ptr + 48); - const uint8x16_t b_0 = vld1q_u8(ref_ptr); - const uint8x16_t b_1 = vld1q_u8(ref_ptr + 16); - const uint8x16_t b_2 = vld1q_u8(ref_ptr + 32); - const uint8x16_t b_3 = vld1q_u8(ref_ptr + 48); - const uint8x16_t c_0 = vld1q_u8(second_pred); - const uint8x16_t c_1 = vld1q_u8(second_pred + 16); - const uint8x16_t c_2 = vld1q_u8(second_pred + 32); - const uint8x16_t c_3 = vld1q_u8(second_pred + 48); - const uint8x16_t avg_0 = vrhaddq_u8(b_0, c_0); - const uint8x16_t avg_1 = vrhaddq_u8(b_1, c_1); - const uint8x16_t avg_2 = vrhaddq_u8(b_2, c_2); - const uint8x16_t avg_3 = vrhaddq_u8(b_3, c_3); src_ptr += src_stride; ref_ptr += ref_stride; second_pred += 64; - abs_0 = vabal_u8(abs_0, vget_low_u8(a_0), vget_low_u8(avg_0)); - abs_0 = vabal_u8(abs_0, vget_high_u8(a_0), vget_high_u8(avg_0)); - abs_0 = vabal_u8(abs_0, vget_low_u8(a_1), vget_low_u8(avg_1)); - abs_0 = vabal_u8(abs_0, vget_high_u8(a_1), vget_high_u8(avg_1)); - abs_1 = vabal_u8(abs_1, vget_low_u8(a_2), vget_low_u8(avg_2)); - abs_1 = vabal_u8(abs_1, vget_high_u8(a_2), vget_high_u8(avg_2)); - abs_1 = vabal_u8(abs_1, vget_low_u8(a_3), vget_low_u8(avg_3)); - abs_1 = vabal_u8(abs_1, vget_high_u8(a_3), vget_high_u8(avg_3)); - } + } while (--i != 0); - { - const uint32x4_t sum = vpaddlq_u16(abs_0); - return vpadalq_u16(sum, abs_1); - } + sum_u32 = vpaddlq_u16(sum[0]); + sum_u32 = vpadalq_u16(sum_u32, sum[1]); + sum_u32 = vpadalq_u16(sum_u32, sum[2]); + sum_u32 = vpadalq_u16(sum_u32, sum[3]); + + return horizontal_add_uint32x4(sum_u32); } -#define SAD64XN(n) \ - uint32_t vpx_sad64x##n##_neon(const uint8_t *src_ptr, int src_stride, \ - const uint8_t *ref_ptr, int ref_stride) { \ - const uint32x4_t abs = \ - sad64x(src_ptr, src_stride, ref_ptr, ref_stride, n); \ - return horizontal_add_uint32x4(abs); \ - } \ - \ - uint32_t vpx_sad64x##n##_avg_neon(const uint8_t *src_ptr, int src_stride, \ - const uint8_t *ref_ptr, int ref_stride, \ - const uint8_t *second_pred) { \ - const uint32x4_t abs = \ - sad64x_avg(src_ptr, src_stride, ref_ptr, ref_stride, second_pred, n); \ - return horizontal_add_uint32x4(abs); \ +static INLINE unsigned int sad32xh_avg_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + const uint8_t *second_pred) { + uint32x4_t sum = vdupq_n_u32(0); + + int i = h; + do { + uint8x16_t s0 = vld1q_u8(src_ptr); + uint8x16_t r0 = vld1q_u8(ref_ptr); + uint8x16_t p0 = vld1q_u8(second_pred); + uint8x16_t avg0 = vrhaddq_u8(r0, p0); + uint8x16_t diff0 = vabdq_u8(s0, avg0); + uint16x8_t sum0 = vpaddlq_u8(diff0); + + uint8x16_t s1 = vld1q_u8(src_ptr + 16); + uint8x16_t r1 = vld1q_u8(ref_ptr + 16); + uint8x16_t p1 = vld1q_u8(second_pred + 16); + uint8x16_t avg1 = vrhaddq_u8(r1, p1); + uint8x16_t diff1 = vabdq_u8(s1, avg1); + uint16x8_t sum1 = vpaddlq_u8(diff1); + + sum = vpadalq_u16(sum, sum0); + sum = vpadalq_u16(sum, sum1); + + src_ptr += src_stride; + ref_ptr += ref_stride; + second_pred += 32; + } while (--i != 0); + + return horizontal_add_uint32x4(sum); +} + +static INLINE unsigned int sad16xh_avg_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + const uint8_t *second_pred) { + uint16x8_t sum = vdupq_n_u16(0); + + int i = h; + do { + uint8x16_t s = vld1q_u8(src_ptr); + uint8x16_t r = vld1q_u8(ref_ptr); + uint8x16_t p = vld1q_u8(second_pred); + + uint8x16_t avg = vrhaddq_u8(r, p); + uint8x16_t diff = vabdq_u8(s, avg); + sum = vpadalq_u8(sum, diff); + + src_ptr += src_stride; + ref_ptr += ref_stride; + second_pred += 16; + } while (--i != 0); + + return horizontal_add_uint16x8(sum); +} + +static INLINE unsigned int sad8xh_avg_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + const uint8_t *second_pred) { + uint16x8_t sum = vdupq_n_u16(0); + + int i = h; + do { + uint8x8_t s = vld1_u8(src_ptr); + uint8x8_t r = vld1_u8(ref_ptr); + uint8x8_t p = vld1_u8(second_pred); + + uint8x8_t avg = vrhadd_u8(r, p); + sum = vabal_u8(sum, s, avg); + + src_ptr += src_stride; + ref_ptr += ref_stride; + second_pred += 8; + } while (--i != 0); + + return horizontal_add_uint16x8(sum); +} + +static INLINE unsigned int sad4xh_avg_neon(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + const uint8_t *second_pred) { + uint16x8_t sum = vdupq_n_u16(0); + + int i = h / 2; + do { + uint8x8_t s = load_unaligned_u8(src_ptr, src_stride); + uint8x8_t r = load_unaligned_u8(ref_ptr, ref_stride); + uint8x8_t p = vld1_u8(second_pred); + + uint8x8_t avg = vrhadd_u8(r, p); + sum = vabal_u8(sum, s, avg); + + src_ptr += 2 * src_stride; + ref_ptr += 2 * ref_stride; + second_pred += 8; + } while (--i != 0); + + return horizontal_add_uint16x8(sum); +} + +#define SAD_WXH_AVG_NEON(w, h) \ + uint32_t vpx_sad##w##x##h##_avg_neon(const uint8_t *src, int src_stride, \ + const uint8_t *ref, int ref_stride, \ + const uint8_t *second_pred) { \ + return sad##w##xh_avg_neon(src, src_stride, ref, ref_stride, (h), \ + second_pred); \ } -SAD64XN(32) -SAD64XN(64) +SAD_WXH_AVG_NEON(4, 4) +SAD_WXH_AVG_NEON(4, 8) + +SAD_WXH_AVG_NEON(8, 4) +SAD_WXH_AVG_NEON(8, 8) +SAD_WXH_AVG_NEON(8, 16) + +SAD_WXH_AVG_NEON(16, 8) +SAD_WXH_AVG_NEON(16, 16) +SAD_WXH_AVG_NEON(16, 32) + +SAD_WXH_AVG_NEON(32, 16) +SAD_WXH_AVG_NEON(32, 32) +SAD_WXH_AVG_NEON(32, 64) + +SAD_WXH_AVG_NEON(64, 32) +SAD_WXH_AVG_NEON(64, 64) + +#undef SAD_WXH_AVG_NEON +#endif // CONFIG_ENCODERS diff --git a/libs/libvpx/vpx_dsp/arm/sad_neon_dotprod.c b/libs/libvpx/vpx_dsp/arm/sad_neon_dotprod.c new file mode 100644 index 0000000000..567d6f8c18 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/sad_neon_dotprod.c @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2021 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" + +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" + +static INLINE unsigned int sadwxh_neon_dotprod(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int w, int h) { + // Only two accumulators are required for optimal instruction throughput of + // the ABD, UDOT sequence on CPUs with either 2 or 4 Neon pipes. + uint32x4_t sum[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + int i = h; + do { + int j = 0; + do { + uint8x16_t s0, s1, r0, r1, diff0, diff1; + + s0 = vld1q_u8(src_ptr + j); + r0 = vld1q_u8(ref_ptr + j); + diff0 = vabdq_u8(s0, r0); + sum[0] = vdotq_u32(sum[0], diff0, vdupq_n_u8(1)); + + s1 = vld1q_u8(src_ptr + j + 16); + r1 = vld1q_u8(ref_ptr + j + 16); + diff1 = vabdq_u8(s1, r1); + sum[1] = vdotq_u32(sum[1], diff1, vdupq_n_u8(1)); + + j += 32; + } while (j < w); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--i != 0); + + return horizontal_add_uint32x4(vaddq_u32(sum[0], sum[1])); +} + +static INLINE unsigned int sad64xh_neon_dotprod(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h) { + return sadwxh_neon_dotprod(src_ptr, src_stride, ref_ptr, ref_stride, 64, h); +} + +static INLINE unsigned int sad32xh_neon_dotprod(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h) { + return sadwxh_neon_dotprod(src_ptr, src_stride, ref_ptr, ref_stride, 32, h); +} + +static INLINE unsigned int sad16xh_neon_dotprod(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h) { + uint32x4_t sum[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + int i = h / 2; + do { + uint8x16_t s0, s1, r0, r1, diff0, diff1; + + s0 = vld1q_u8(src_ptr); + r0 = vld1q_u8(ref_ptr); + diff0 = vabdq_u8(s0, r0); + sum[0] = vdotq_u32(sum[0], diff0, vdupq_n_u8(1)); + + src_ptr += src_stride; + ref_ptr += ref_stride; + + s1 = vld1q_u8(src_ptr); + r1 = vld1q_u8(ref_ptr); + diff1 = vabdq_u8(s1, r1); + sum[1] = vdotq_u32(sum[1], diff1, vdupq_n_u8(1)); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--i != 0); + + return horizontal_add_uint32x4(vaddq_u32(sum[0], sum[1])); +} + +#define SAD_WXH_NEON_DOTPROD(w, h) \ + unsigned int vpx_sad##w##x##h##_neon_dotprod( \ + const uint8_t *src, int src_stride, const uint8_t *ref, \ + int ref_stride) { \ + return sad##w##xh_neon_dotprod(src, src_stride, ref, ref_stride, (h)); \ + } + +#if CONFIG_ENCODERS +SAD_WXH_NEON_DOTPROD(16, 8) +SAD_WXH_NEON_DOTPROD(16, 16) +SAD_WXH_NEON_DOTPROD(16, 32) + +SAD_WXH_NEON_DOTPROD(32, 16) +SAD_WXH_NEON_DOTPROD(32, 32) +SAD_WXH_NEON_DOTPROD(32, 64) + +SAD_WXH_NEON_DOTPROD(64, 32) +SAD_WXH_NEON_DOTPROD(64, 64) +#else // !CONFIG_ENCODERS +SAD_WXH_NEON_DOTPROD(16, 16) +SAD_WXH_NEON_DOTPROD(32, 32) +SAD_WXH_NEON_DOTPROD(64, 64) +#endif // CONFIG_ENCODERS + +#undef SAD_WXH_NEON_DOTPROD + +#if CONFIG_ENCODERS +#define SAD_SKIP_WXH_NEON_DOTPROD(w, h) \ + unsigned int vpx_sad_skip_##w##x##h##_neon_dotprod( \ + const uint8_t *src, int src_stride, const uint8_t *ref, \ + int ref_stride) { \ + return 2 * sad##w##xh_neon_dotprod(src, 2 * src_stride, ref, \ + 2 * ref_stride, (h) / 2); \ + } + +SAD_SKIP_WXH_NEON_DOTPROD(16, 8) +SAD_SKIP_WXH_NEON_DOTPROD(16, 16) +SAD_SKIP_WXH_NEON_DOTPROD(16, 32) + +SAD_SKIP_WXH_NEON_DOTPROD(32, 16) +SAD_SKIP_WXH_NEON_DOTPROD(32, 32) +SAD_SKIP_WXH_NEON_DOTPROD(32, 64) + +SAD_SKIP_WXH_NEON_DOTPROD(64, 32) +SAD_SKIP_WXH_NEON_DOTPROD(64, 64) + +#undef SAD_SKIP_WXH_NEON_DOTPROD + +static INLINE unsigned int sadwxh_avg_neon_dotprod(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int w, int h, + const uint8_t *second_pred) { + // Only two accumulators are required for optimal instruction throughput of + // the ABD, UDOT sequence on CPUs with either 2 or 4 Neon pipes. + uint32x4_t sum[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + int i = h; + do { + int j = 0; + do { + uint8x16_t s0, s1, r0, r1, p0, p1, avg0, avg1, diff0, diff1; + + s0 = vld1q_u8(src_ptr + j); + r0 = vld1q_u8(ref_ptr + j); + p0 = vld1q_u8(second_pred); + avg0 = vrhaddq_u8(r0, p0); + diff0 = vabdq_u8(s0, avg0); + sum[0] = vdotq_u32(sum[0], diff0, vdupq_n_u8(1)); + + s1 = vld1q_u8(src_ptr + j + 16); + r1 = vld1q_u8(ref_ptr + j + 16); + p1 = vld1q_u8(second_pred + 16); + avg1 = vrhaddq_u8(r1, p1); + diff1 = vabdq_u8(s1, avg1); + sum[1] = vdotq_u32(sum[1], diff1, vdupq_n_u8(1)); + + j += 32; + second_pred += 32; + } while (j < w); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--i != 0); + + return horizontal_add_uint32x4(vaddq_u32(sum[0], sum[1])); +} + +static INLINE unsigned int sad64xh_avg_neon_dotprod( + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, + int ref_stride, int h, const uint8_t *second_pred) { + return sadwxh_avg_neon_dotprod(src_ptr, src_stride, ref_ptr, ref_stride, 64, + h, second_pred); +} + +static INLINE unsigned int sad32xh_avg_neon_dotprod( + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, + int ref_stride, int h, const uint8_t *second_pred) { + return sadwxh_avg_neon_dotprod(src_ptr, src_stride, ref_ptr, ref_stride, 32, + h, second_pred); +} + +static INLINE unsigned int sad16xh_avg_neon_dotprod( + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, + int ref_stride, int h, const uint8_t *second_pred) { + uint32x4_t sum[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + int i = h / 2; + do { + uint8x16_t s0, s1, r0, r1, p0, p1, avg0, avg1, diff0, diff1; + + s0 = vld1q_u8(src_ptr); + r0 = vld1q_u8(ref_ptr); + p0 = vld1q_u8(second_pred); + avg0 = vrhaddq_u8(r0, p0); + diff0 = vabdq_u8(s0, avg0); + sum[0] = vdotq_u32(sum[0], diff0, vdupq_n_u8(1)); + + src_ptr += src_stride; + ref_ptr += ref_stride; + second_pred += 16; + + s1 = vld1q_u8(src_ptr); + r1 = vld1q_u8(ref_ptr); + p1 = vld1q_u8(second_pred); + avg1 = vrhaddq_u8(r1, p1); + diff1 = vabdq_u8(s1, avg1); + sum[1] = vdotq_u32(sum[1], diff1, vdupq_n_u8(1)); + + src_ptr += src_stride; + ref_ptr += ref_stride; + second_pred += 16; + } while (--i != 0); + + return horizontal_add_uint32x4(vaddq_u32(sum[0], sum[1])); +} + +#define SAD_WXH_AVG_NEON_DOTPROD(w, h) \ + uint32_t vpx_sad##w##x##h##_avg_neon_dotprod( \ + const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \ + const uint8_t *second_pred) { \ + return sad##w##xh_avg_neon_dotprod(src, src_stride, ref, ref_stride, (h), \ + second_pred); \ + } + +SAD_WXH_AVG_NEON_DOTPROD(16, 8) +SAD_WXH_AVG_NEON_DOTPROD(16, 16) +SAD_WXH_AVG_NEON_DOTPROD(16, 32) + +SAD_WXH_AVG_NEON_DOTPROD(32, 16) +SAD_WXH_AVG_NEON_DOTPROD(32, 32) +SAD_WXH_AVG_NEON_DOTPROD(32, 64) + +SAD_WXH_AVG_NEON_DOTPROD(64, 32) +SAD_WXH_AVG_NEON_DOTPROD(64, 64) + +#undef SAD_WXH_AVG_NEON_DOTPROD +#endif // CONFIG_ENCODERS diff --git a/libs/libvpx/vpx_dsp/arm/sse_neon.c b/libs/libvpx/vpx_dsp/arm/sse_neon.c new file mode 100644 index 0000000000..2dd57e596c --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/sse_neon.c @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" + +static INLINE void sse_16x1_neon(const uint8_t *src, const uint8_t *ref, + uint32x4_t *sse) { + uint8x16_t s = vld1q_u8(src); + uint8x16_t r = vld1q_u8(ref); + + uint8x16_t abs_diff = vabdq_u8(s, r); + uint8x8_t abs_diff_lo = vget_low_u8(abs_diff); + uint8x8_t abs_diff_hi = vget_high_u8(abs_diff); + + *sse = vpadalq_u16(*sse, vmull_u8(abs_diff_lo, abs_diff_lo)); + *sse = vpadalq_u16(*sse, vmull_u8(abs_diff_hi, abs_diff_hi)); +} + +static INLINE void sse_8x1_neon(const uint8_t *src, const uint8_t *ref, + uint32x4_t *sse) { + uint8x8_t s = vld1_u8(src); + uint8x8_t r = vld1_u8(ref); + + uint8x8_t abs_diff = vabd_u8(s, r); + + *sse = vpadalq_u16(*sse, vmull_u8(abs_diff, abs_diff)); +} + +static INLINE void sse_4x2_neon(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + uint32x4_t *sse) { + uint8x8_t s = load_unaligned_u8(src, src_stride); + uint8x8_t r = load_unaligned_u8(ref, ref_stride); + + uint8x8_t abs_diff = vabd_u8(s, r); + + *sse = vpadalq_u16(*sse, vmull_u8(abs_diff, abs_diff)); +} + +static INLINE uint32_t sse_wxh_neon(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int width, int height) { + uint32x4_t sse = vdupq_n_u32(0); + + if ((width & 0x07) && ((width & 0x07) < 5)) { + int i = height; + do { + int j = 0; + do { + sse_8x1_neon(src + j, ref + j, &sse); + sse_8x1_neon(src + j + src_stride, ref + j + ref_stride, &sse); + j += 8; + } while (j + 4 < width); + + sse_4x2_neon(src + j, src_stride, ref + j, ref_stride, &sse); + src += 2 * src_stride; + ref += 2 * ref_stride; + i -= 2; + } while (i != 0); + } else { + int i = height; + do { + int j = 0; + do { + sse_8x1_neon(src + j, ref + j, &sse); + j += 8; + } while (j < width); + + src += src_stride; + ref += ref_stride; + } while (--i != 0); + } + return horizontal_add_uint32x4(sse); +} + +static INLINE uint32_t sse_64xh_neon(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int height) { + uint32x4_t sse[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + int i = height; + do { + sse_16x1_neon(src, ref, &sse[0]); + sse_16x1_neon(src + 16, ref + 16, &sse[1]); + sse_16x1_neon(src + 32, ref + 32, &sse[0]); + sse_16x1_neon(src + 48, ref + 48, &sse[1]); + + src += src_stride; + ref += ref_stride; + } while (--i != 0); + + return horizontal_add_uint32x4(vaddq_u32(sse[0], sse[1])); +} + +static INLINE uint32_t sse_32xh_neon(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int height) { + uint32x4_t sse[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + int i = height; + do { + sse_16x1_neon(src, ref, &sse[0]); + sse_16x1_neon(src + 16, ref + 16, &sse[1]); + + src += src_stride; + ref += ref_stride; + } while (--i != 0); + + return horizontal_add_uint32x4(vaddq_u32(sse[0], sse[1])); +} + +static INLINE uint32_t sse_16xh_neon(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int height) { + uint32x4_t sse[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + int i = height; + do { + sse_16x1_neon(src, ref, &sse[0]); + src += src_stride; + ref += ref_stride; + sse_16x1_neon(src, ref, &sse[1]); + src += src_stride; + ref += ref_stride; + i -= 2; + } while (i != 0); + + return horizontal_add_uint32x4(vaddq_u32(sse[0], sse[1])); +} + +static INLINE uint32_t sse_8xh_neon(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int height) { + uint32x4_t sse = vdupq_n_u32(0); + + int i = height; + do { + sse_8x1_neon(src, ref, &sse); + + src += src_stride; + ref += ref_stride; + } while (--i != 0); + + return horizontal_add_uint32x4(sse); +} + +static INLINE uint32_t sse_4xh_neon(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int height) { + uint32x4_t sse = vdupq_n_u32(0); + + int i = height; + do { + sse_4x2_neon(src, src_stride, ref, ref_stride, &sse); + + src += 2 * src_stride; + ref += 2 * ref_stride; + i -= 2; + } while (i != 0); + + return horizontal_add_uint32x4(sse); +} + +int64_t vpx_sse_neon(const uint8_t *src, int src_stride, const uint8_t *ref, + int ref_stride, int width, int height) { + switch (width) { + case 4: return sse_4xh_neon(src, src_stride, ref, ref_stride, height); + case 8: return sse_8xh_neon(src, src_stride, ref, ref_stride, height); + case 16: return sse_16xh_neon(src, src_stride, ref, ref_stride, height); + case 32: return sse_32xh_neon(src, src_stride, ref, ref_stride, height); + case 64: return sse_64xh_neon(src, src_stride, ref, ref_stride, height); + default: + return sse_wxh_neon(src, src_stride, ref, ref_stride, width, height); + } +} diff --git a/libs/libvpx/vpx_dsp/arm/sse_neon_dotprod.c b/libs/libvpx/vpx_dsp/arm/sse_neon_dotprod.c new file mode 100644 index 0000000000..8777773918 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/sse_neon_dotprod.c @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_dsp_rtcd.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" + +static INLINE void sse_16x1_neon_dotprod(const uint8_t *src, const uint8_t *ref, + uint32x4_t *sse) { + uint8x16_t s = vld1q_u8(src); + uint8x16_t r = vld1q_u8(ref); + + uint8x16_t abs_diff = vabdq_u8(s, r); + + *sse = vdotq_u32(*sse, abs_diff, abs_diff); +} + +static INLINE void sse_8x1_neon_dotprod(const uint8_t *src, const uint8_t *ref, + uint32x2_t *sse) { + uint8x8_t s = vld1_u8(src); + uint8x8_t r = vld1_u8(ref); + + uint8x8_t abs_diff = vabd_u8(s, r); + + *sse = vdot_u32(*sse, abs_diff, abs_diff); +} + +static INLINE void sse_4x2_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + uint32x2_t *sse) { + uint8x8_t s = load_unaligned_u8(src, src_stride); + uint8x8_t r = load_unaligned_u8(ref, ref_stride); + + uint8x8_t abs_diff = vabd_u8(s, r); + + *sse = vdot_u32(*sse, abs_diff, abs_diff); +} + +static INLINE uint32_t sse_wxh_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int width, int height) { + uint32x2_t sse[2] = { vdup_n_u32(0), vdup_n_u32(0) }; + + if ((width & 0x07) && ((width & 0x07) < 5)) { + int i = height; + do { + int j = 0; + do { + sse_8x1_neon_dotprod(src + j, ref + j, &sse[0]); + sse_8x1_neon_dotprod(src + j + src_stride, ref + j + ref_stride, + &sse[1]); + j += 8; + } while (j + 4 < width); + + sse_4x2_neon_dotprod(src + j, src_stride, ref + j, ref_stride, &sse[0]); + src += 2 * src_stride; + ref += 2 * ref_stride; + i -= 2; + } while (i != 0); + } else { + int i = height; + do { + int j = 0; + do { + sse_8x1_neon_dotprod(src + j, ref + j, &sse[0]); + sse_8x1_neon_dotprod(src + j + src_stride, ref + j + ref_stride, + &sse[1]); + j += 8; + } while (j < width); + + src += 2 * src_stride; + ref += 2 * ref_stride; + i -= 2; + } while (i != 0); + } + return horizontal_add_uint32x4(vcombine_u32(sse[0], sse[1])); +} + +static INLINE uint32_t sse_64xh_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int height) { + uint32x4_t sse[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + int i = height; + do { + sse_16x1_neon_dotprod(src, ref, &sse[0]); + sse_16x1_neon_dotprod(src + 16, ref + 16, &sse[1]); + sse_16x1_neon_dotprod(src + 32, ref + 32, &sse[0]); + sse_16x1_neon_dotprod(src + 48, ref + 48, &sse[1]); + + src += src_stride; + ref += ref_stride; + } while (--i != 0); + + return horizontal_add_uint32x4(vaddq_u32(sse[0], sse[1])); +} + +static INLINE uint32_t sse_32xh_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int height) { + uint32x4_t sse[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + int i = height; + do { + sse_16x1_neon_dotprod(src, ref, &sse[0]); + sse_16x1_neon_dotprod(src + 16, ref + 16, &sse[1]); + + src += src_stride; + ref += ref_stride; + } while (--i != 0); + + return horizontal_add_uint32x4(vaddq_u32(sse[0], sse[1])); +} + +static INLINE uint32_t sse_16xh_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int height) { + uint32x4_t sse[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + int i = height; + do { + sse_16x1_neon_dotprod(src, ref, &sse[0]); + src += src_stride; + ref += ref_stride; + sse_16x1_neon_dotprod(src, ref, &sse[1]); + src += src_stride; + ref += ref_stride; + i -= 2; + } while (i != 0); + + return horizontal_add_uint32x4(vaddq_u32(sse[0], sse[1])); +} + +static INLINE uint32_t sse_8xh_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int height) { + uint32x2_t sse[2] = { vdup_n_u32(0), vdup_n_u32(0) }; + + int i = height; + do { + sse_8x1_neon_dotprod(src, ref, &sse[0]); + src += src_stride; + ref += ref_stride; + sse_8x1_neon_dotprod(src, ref, &sse[1]); + src += src_stride; + ref += ref_stride; + i -= 2; + } while (i != 0); + + return horizontal_add_uint32x4(vcombine_u32(sse[0], sse[1])); +} + +static INLINE uint32_t sse_4xh_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int height) { + uint32x2_t sse = vdup_n_u32(0); + + int i = height; + do { + sse_4x2_neon_dotprod(src, src_stride, ref, ref_stride, &sse); + + src += 2 * src_stride; + ref += 2 * ref_stride; + i -= 2; + } while (i != 0); + + return horizontal_add_uint32x2(sse); +} + +int64_t vpx_sse_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, int width, + int height) { + switch (width) { + case 4: + return sse_4xh_neon_dotprod(src, src_stride, ref, ref_stride, height); + case 8: + return sse_8xh_neon_dotprod(src, src_stride, ref, ref_stride, height); + case 16: + return sse_16xh_neon_dotprod(src, src_stride, ref, ref_stride, height); + case 32: + return sse_32xh_neon_dotprod(src, src_stride, ref, ref_stride, height); + case 64: + return sse_64xh_neon_dotprod(src, src_stride, ref, ref_stride, height); + default: + return sse_wxh_neon_dotprod(src, src_stride, ref, ref_stride, width, + height); + } +} diff --git a/libs/libvpx/vpx_dsp/arm/subpel_variance_neon.c b/libs/libvpx/vpx_dsp/arm/subpel_variance_neon.c index a3befdc348..61ce5a8910 100644 --- a/libs/libvpx/vpx_dsp/arm/subpel_variance_neon.c +++ b/libs/libvpx/vpx_dsp/arm/subpel_variance_neon.c @@ -16,169 +16,362 @@ #include "vpx_dsp/variance.h" #include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/subpel_variance_neon.h" -static const uint8_t bilinear_filters[8][2] = { - { 128, 0 }, { 112, 16 }, { 96, 32 }, { 80, 48 }, - { 64, 64 }, { 48, 80 }, { 32, 96 }, { 16, 112 }, -}; - -// Process a block exactly 4 wide and a multiple of 2 high. -static void var_filter_block2d_bil_w4(const uint8_t *src_ptr, - uint8_t *output_ptr, - unsigned int src_pixels_per_line, - int pixel_step, - unsigned int output_height, - const uint8_t *filter) { - const uint8x8_t f0 = vdup_n_u8(filter[0]); - const uint8x8_t f1 = vdup_n_u8(filter[1]); - unsigned int i; - for (i = 0; i < output_height; i += 2) { - const uint8x8_t src_0 = load_unaligned_u8(src_ptr, src_pixels_per_line); - const uint8x8_t src_1 = - load_unaligned_u8(src_ptr + pixel_step, src_pixels_per_line); - const uint16x8_t a = vmull_u8(src_0, f0); - const uint16x8_t b = vmlal_u8(a, src_1, f1); - const uint8x8_t out = vrshrn_n_u16(b, FILTER_BITS); - vst1_u8(output_ptr, out); - src_ptr += 2 * src_pixels_per_line; - output_ptr += 8; +#define SUBPEL_VARIANCE_WXH_NEON(w, h, padding) \ + unsigned int vpx_sub_pixel_variance##w##x##h##_neon( \ + const uint8_t *src, int src_stride, int xoffset, int yoffset, \ + const uint8_t *ref, int ref_stride, uint32_t *sse) { \ + uint8_t tmp0[w * (h + padding)]; \ + uint8_t tmp1[w * h]; \ + var_filter_block2d_bil_w##w(src, tmp0, src_stride, 1, (h + padding), \ + xoffset); \ + var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset); \ + return vpx_variance##w##x##h##_neon(tmp1, w, ref, ref_stride, sse); \ } + +#define SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(w, h, padding) \ + unsigned int vpx_sub_pixel_variance##w##x##h##_neon( \ + const uint8_t *src, int src_stride, int xoffset, int yoffset, \ + const uint8_t *ref, int ref_stride, unsigned int *sse) { \ + if (xoffset == 0) { \ + if (yoffset == 0) { \ + return vpx_variance##w##x##h##_neon(src, src_stride, ref, ref_stride, \ + sse); \ + } else if (yoffset == 4) { \ + uint8_t tmp[w * h]; \ + var_filter_block2d_avg(src, tmp, src_stride, src_stride, w, h); \ + return vpx_variance##w##x##h##_neon(tmp, w, ref, ref_stride, sse); \ + } else { \ + uint8_t tmp[w * h]; \ + var_filter_block2d_bil_w##w(src, tmp, src_stride, src_stride, h, \ + yoffset); \ + return vpx_variance##w##x##h##_neon(tmp, w, ref, ref_stride, sse); \ + } \ + } else if (xoffset == 4) { \ + uint8_t tmp0[w * (h + padding)]; \ + if (yoffset == 0) { \ + var_filter_block2d_avg(src, tmp0, src_stride, 1, w, h); \ + return vpx_variance##w##x##h##_neon(tmp0, w, ref, ref_stride, sse); \ + } else if (yoffset == 4) { \ + uint8_t tmp1[w * (h + padding)]; \ + var_filter_block2d_avg(src, tmp0, src_stride, 1, w, (h + padding)); \ + var_filter_block2d_avg(tmp0, tmp1, w, w, w, h); \ + return vpx_variance##w##x##h##_neon(tmp1, w, ref, ref_stride, sse); \ + } else { \ + uint8_t tmp1[w * (h + padding)]; \ + var_filter_block2d_avg(src, tmp0, src_stride, 1, w, (h + padding)); \ + var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset); \ + return vpx_variance##w##x##h##_neon(tmp1, w, ref, ref_stride, sse); \ + } \ + } else { \ + uint8_t tmp0[w * (h + padding)]; \ + if (yoffset == 0) { \ + var_filter_block2d_bil_w##w(src, tmp0, src_stride, 1, h, xoffset); \ + return vpx_variance##w##x##h##_neon(tmp0, w, ref, ref_stride, sse); \ + } else if (yoffset == 4) { \ + uint8_t tmp1[w * h]; \ + var_filter_block2d_bil_w##w(src, tmp0, src_stride, 1, (h + padding), \ + xoffset); \ + var_filter_block2d_avg(tmp0, tmp1, w, w, w, h); \ + return vpx_variance##w##x##h##_neon(tmp1, w, ref, ref_stride, sse); \ + } else { \ + uint8_t tmp1[w * h]; \ + var_filter_block2d_bil_w##w(src, tmp0, src_stride, 1, (h + padding), \ + xoffset); \ + var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset); \ + return vpx_variance##w##x##h##_neon(tmp1, w, ref, ref_stride, sse); \ + } \ + } \ + } + +// 4x blocks are processed two rows at a time, so require an extra row of +// padding. +SUBPEL_VARIANCE_WXH_NEON(4, 4, 2) +SUBPEL_VARIANCE_WXH_NEON(4, 8, 2) + +SUBPEL_VARIANCE_WXH_NEON(8, 4, 1) +SUBPEL_VARIANCE_WXH_NEON(8, 8, 1) +SUBPEL_VARIANCE_WXH_NEON(8, 16, 1) + +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(16, 8, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(16, 16, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(16, 32, 1) + +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(32, 16, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(32, 32, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(32, 64, 1) + +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(64, 32, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON(64, 64, 1) + +// Combine bilinear filter with vpx_comp_avg_pred for blocks having width 4. +static void avg_pred_var_filter_block2d_bil_w4(const uint8_t *src_ptr, + uint8_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset, + const uint8_t *second_pred) { + const uint8x8_t f0 = vdup_n_u8(8 - filter_offset); + const uint8x8_t f1 = vdup_n_u8(filter_offset); + + int i = dst_height; + do { + uint8x8_t s0 = load_unaligned_u8(src_ptr, src_stride); + uint8x8_t s1 = load_unaligned_u8(src_ptr + pixel_step, src_stride); + uint16x8_t blend = vmlal_u8(vmull_u8(s0, f0), s1, f1); + uint8x8_t blend_u8 = vrshrn_n_u16(blend, 3); + + uint8x8_t p = vld1_u8(second_pred); + uint8x8_t avg = vrhadd_u8(blend_u8, p); + + vst1_u8(dst_ptr, avg); + + src_ptr += 2 * src_stride; + dst_ptr += 2 * 4; + second_pred += 2 * 4; + i -= 2; + } while (i != 0); } -// Process a block exactly 8 wide and any height. -static void var_filter_block2d_bil_w8(const uint8_t *src_ptr, - uint8_t *output_ptr, - unsigned int src_pixels_per_line, - int pixel_step, - unsigned int output_height, - const uint8_t *filter) { - const uint8x8_t f0 = vdup_n_u8(filter[0]); - const uint8x8_t f1 = vdup_n_u8(filter[1]); - unsigned int i; - for (i = 0; i < output_height; ++i) { - const uint8x8_t src_0 = vld1_u8(&src_ptr[0]); - const uint8x8_t src_1 = vld1_u8(&src_ptr[pixel_step]); - const uint16x8_t a = vmull_u8(src_0, f0); - const uint16x8_t b = vmlal_u8(a, src_1, f1); - const uint8x8_t out = vrshrn_n_u16(b, FILTER_BITS); - vst1_u8(output_ptr, out); - src_ptr += src_pixels_per_line; - output_ptr += 8; - } +// Combine bilinear filter with vpx_comp_avg_pred for blocks having width 8. +static void avg_pred_var_filter_block2d_bil_w8(const uint8_t *src_ptr, + uint8_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset, + const uint8_t *second_pred) { + const uint8x8_t f0 = vdup_n_u8(8 - filter_offset); + const uint8x8_t f1 = vdup_n_u8(filter_offset); + + int i = dst_height; + do { + uint8x8_t s0 = vld1_u8(src_ptr); + uint8x8_t s1 = vld1_u8(src_ptr + pixel_step); + uint16x8_t blend = vmlal_u8(vmull_u8(s0, f0), s1, f1); + uint8x8_t blend_u8 = vrshrn_n_u16(blend, 3); + + uint8x8_t p = vld1_u8(second_pred); + uint8x8_t avg = vrhadd_u8(blend_u8, p); + + vst1_u8(dst_ptr, avg); + + src_ptr += src_stride; + dst_ptr += 8; + second_pred += 8; + } while (--i > 0); } -// Process a block which is a mutiple of 16 wide and any height. -static void var_filter_block2d_bil_w16(const uint8_t *src_ptr, - uint8_t *output_ptr, - unsigned int src_pixels_per_line, - int pixel_step, - unsigned int output_height, - unsigned int output_width, - const uint8_t *filter) { - const uint8x8_t f0 = vdup_n_u8(filter[0]); - const uint8x8_t f1 = vdup_n_u8(filter[1]); - unsigned int i, j; - for (i = 0; i < output_height; ++i) { - for (j = 0; j < output_width; j += 16) { - const uint8x16_t src_0 = vld1q_u8(&src_ptr[j]); - const uint8x16_t src_1 = vld1q_u8(&src_ptr[j + pixel_step]); - const uint16x8_t a = vmull_u8(vget_low_u8(src_0), f0); - const uint16x8_t b = vmlal_u8(a, vget_low_u8(src_1), f1); - const uint8x8_t out_lo = vrshrn_n_u16(b, FILTER_BITS); - const uint16x8_t c = vmull_u8(vget_high_u8(src_0), f0); - const uint16x8_t d = vmlal_u8(c, vget_high_u8(src_1), f1); - const uint8x8_t out_hi = vrshrn_n_u16(d, FILTER_BITS); - vst1q_u8(output_ptr + j, vcombine_u8(out_lo, out_hi)); - } - src_ptr += src_pixels_per_line; - output_ptr += output_width; - } +// Combine bilinear filter with vpx_comp_avg_pred for large blocks. +static void avg_pred_var_filter_block2d_bil_large( + const uint8_t *src_ptr, uint8_t *dst_ptr, int src_stride, int pixel_step, + int dst_width, int dst_height, int filter_offset, + const uint8_t *second_pred) { + const uint8x8_t f0 = vdup_n_u8(8 - filter_offset); + const uint8x8_t f1 = vdup_n_u8(filter_offset); + + int i = dst_height; + do { + int j = 0; + do { + uint8x16_t s0 = vld1q_u8(src_ptr + j); + uint8x16_t s1 = vld1q_u8(src_ptr + j + pixel_step); + uint16x8_t blend_l = + vmlal_u8(vmull_u8(vget_low_u8(s0), f0), vget_low_u8(s1), f1); + uint16x8_t blend_h = + vmlal_u8(vmull_u8(vget_high_u8(s0), f0), vget_high_u8(s1), f1); + uint8x16_t blend_u8 = + vcombine_u8(vrshrn_n_u16(blend_l, 3), vrshrn_n_u16(blend_h, 3)); + + uint8x16_t p = vld1q_u8(second_pred); + uint8x16_t avg = vrhaddq_u8(blend_u8, p); + + vst1q_u8(dst_ptr + j, avg); + + j += 16; + second_pred += 16; + } while (j < dst_width); + + src_ptr += src_stride; + dst_ptr += dst_width; + } while (--i != 0); } -// 4xM filter writes an extra row to fdata because it processes two rows at a -// time. -#define SUB_PIXEL_VARIANCENXM(n, m) \ - uint32_t vpx_sub_pixel_variance##n##x##m##_neon( \ - const uint8_t *src_ptr, int src_stride, int x_offset, int y_offset, \ - const uint8_t *ref_ptr, int ref_stride, uint32_t *sse) { \ - uint8_t temp0[n * (m + (n == 4 ? 2 : 1))]; \ - uint8_t temp1[n * m]; \ - \ - if (n == 4) { \ - var_filter_block2d_bil_w4(src_ptr, temp0, src_stride, 1, (m + 2), \ - bilinear_filters[x_offset]); \ - var_filter_block2d_bil_w4(temp0, temp1, n, n, m, \ - bilinear_filters[y_offset]); \ - } else if (n == 8) { \ - var_filter_block2d_bil_w8(src_ptr, temp0, src_stride, 1, (m + 1), \ - bilinear_filters[x_offset]); \ - var_filter_block2d_bil_w8(temp0, temp1, n, n, m, \ - bilinear_filters[y_offset]); \ - } else { \ - var_filter_block2d_bil_w16(src_ptr, temp0, src_stride, 1, (m + 1), n, \ - bilinear_filters[x_offset]); \ - var_filter_block2d_bil_w16(temp0, temp1, n, n, m, n, \ - bilinear_filters[y_offset]); \ - } \ - return vpx_variance##n##x##m(temp1, n, ref_ptr, ref_stride, sse); \ - } +// Combine bilinear filter with vpx_comp_avg_pred for blocks having width 16. +static void avg_pred_var_filter_block2d_bil_w16( + const uint8_t *src_ptr, uint8_t *dst_ptr, int src_stride, int pixel_step, + int dst_height, int filter_offset, const uint8_t *second_pred) { + avg_pred_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, + pixel_step, 16, dst_height, + filter_offset, second_pred); +} -SUB_PIXEL_VARIANCENXM(4, 4) -SUB_PIXEL_VARIANCENXM(4, 8) -SUB_PIXEL_VARIANCENXM(8, 4) -SUB_PIXEL_VARIANCENXM(8, 8) -SUB_PIXEL_VARIANCENXM(8, 16) -SUB_PIXEL_VARIANCENXM(16, 8) -SUB_PIXEL_VARIANCENXM(16, 16) -SUB_PIXEL_VARIANCENXM(16, 32) -SUB_PIXEL_VARIANCENXM(32, 16) -SUB_PIXEL_VARIANCENXM(32, 32) -SUB_PIXEL_VARIANCENXM(32, 64) -SUB_PIXEL_VARIANCENXM(64, 32) -SUB_PIXEL_VARIANCENXM(64, 64) +// Combine bilinear filter with vpx_comp_avg_pred for blocks having width 32. +static void avg_pred_var_filter_block2d_bil_w32( + const uint8_t *src_ptr, uint8_t *dst_ptr, int src_stride, int pixel_step, + int dst_height, int filter_offset, const uint8_t *second_pred) { + avg_pred_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, + pixel_step, 32, dst_height, + filter_offset, second_pred); +} -// 4xM filter writes an extra row to fdata because it processes two rows at a -// time. -#define SUB_PIXEL_AVG_VARIANCENXM(n, m) \ - uint32_t vpx_sub_pixel_avg_variance##n##x##m##_neon( \ - const uint8_t *src_ptr, int src_stride, int x_offset, int y_offset, \ - const uint8_t *ref_ptr, int ref_stride, uint32_t *sse, \ +// Combine bilinear filter with vpx_comp_avg_pred for blocks having width 64. +static void avg_pred_var_filter_block2d_bil_w64( + const uint8_t *src_ptr, uint8_t *dst_ptr, int src_stride, int pixel_step, + int dst_height, int filter_offset, const uint8_t *second_pred) { + avg_pred_var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, + pixel_step, 64, dst_height, + filter_offset, second_pred); +} + +// Combine averaging subpel filter with vpx_comp_avg_pred. +static void avg_pred_var_filter_block2d_avg(const uint8_t *src_ptr, + uint8_t *dst_ptr, int src_stride, + int pixel_step, int dst_width, + int dst_height, + const uint8_t *second_pred) { + int i = dst_height; + + // We only specialize on the filter values for large block sizes (>= 16x16.) + assert(dst_width >= 16 && dst_width % 16 == 0); + + do { + int j = 0; + do { + uint8x16_t s0 = vld1q_u8(src_ptr + j); + uint8x16_t s1 = vld1q_u8(src_ptr + j + pixel_step); + uint8x16_t avg = vrhaddq_u8(s0, s1); + + uint8x16_t p = vld1q_u8(second_pred); + avg = vrhaddq_u8(avg, p); + + vst1q_u8(dst_ptr + j, avg); + + j += 16; + second_pred += 16; + } while (j < dst_width); + + src_ptr += src_stride; + dst_ptr += dst_width; + } while (--i != 0); +} + +// Implementation of vpx_comp_avg_pred for blocks having width >= 16. +static void avg_pred(const uint8_t *src_ptr, uint8_t *dst_ptr, int src_stride, + int dst_width, int dst_height, + const uint8_t *second_pred) { + int i = dst_height; + + // We only specialize on the filter values for large block sizes (>= 16x16.) + assert(dst_width >= 16 && dst_width % 16 == 0); + + do { + int j = 0; + do { + uint8x16_t s = vld1q_u8(src_ptr + j); + uint8x16_t p = vld1q_u8(second_pred); + + uint8x16_t avg = vrhaddq_u8(s, p); + + vst1q_u8(dst_ptr + j, avg); + + j += 16; + second_pred += 16; + } while (j < dst_width); + + src_ptr += src_stride; + dst_ptr += dst_width; + } while (--i != 0); +} + +#define SUBPEL_AVG_VARIANCE_WXH_NEON(w, h, padding) \ + unsigned int vpx_sub_pixel_avg_variance##w##x##h##_neon( \ + const uint8_t *src, int source_stride, int xoffset, int yoffset, \ + const uint8_t *ref, int ref_stride, uint32_t *sse, \ const uint8_t *second_pred) { \ - uint8_t temp0[n * (m + (n == 4 ? 2 : 1))]; \ - uint8_t temp1[n * m]; \ - \ - if (n == 4) { \ - var_filter_block2d_bil_w4(src_ptr, temp0, src_stride, 1, (m + 2), \ - bilinear_filters[x_offset]); \ - var_filter_block2d_bil_w4(temp0, temp1, n, n, m, \ - bilinear_filters[y_offset]); \ - } else if (n == 8) { \ - var_filter_block2d_bil_w8(src_ptr, temp0, src_stride, 1, (m + 1), \ - bilinear_filters[x_offset]); \ - var_filter_block2d_bil_w8(temp0, temp1, n, n, m, \ - bilinear_filters[y_offset]); \ - } else { \ - var_filter_block2d_bil_w16(src_ptr, temp0, src_stride, 1, (m + 1), n, \ - bilinear_filters[x_offset]); \ - var_filter_block2d_bil_w16(temp0, temp1, n, n, m, n, \ - bilinear_filters[y_offset]); \ - } \ - \ - vpx_comp_avg_pred(temp0, second_pred, n, m, temp1, n); \ - \ - return vpx_variance##n##x##m(temp0, n, ref_ptr, ref_stride, sse); \ + uint8_t tmp0[w * (h + padding)]; \ + uint8_t tmp1[w * h]; \ + var_filter_block2d_bil_w##w(src, tmp0, source_stride, 1, (h + padding), \ + xoffset); \ + avg_pred_var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset, \ + second_pred); \ + return vpx_variance##w##x##h(tmp1, w, ref, ref_stride, sse); \ } -SUB_PIXEL_AVG_VARIANCENXM(4, 4) -SUB_PIXEL_AVG_VARIANCENXM(4, 8) -SUB_PIXEL_AVG_VARIANCENXM(8, 4) -SUB_PIXEL_AVG_VARIANCENXM(8, 8) -SUB_PIXEL_AVG_VARIANCENXM(8, 16) -SUB_PIXEL_AVG_VARIANCENXM(16, 8) -SUB_PIXEL_AVG_VARIANCENXM(16, 16) -SUB_PIXEL_AVG_VARIANCENXM(16, 32) -SUB_PIXEL_AVG_VARIANCENXM(32, 16) -SUB_PIXEL_AVG_VARIANCENXM(32, 32) -SUB_PIXEL_AVG_VARIANCENXM(32, 64) -SUB_PIXEL_AVG_VARIANCENXM(64, 32) -SUB_PIXEL_AVG_VARIANCENXM(64, 64) +#define SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(w, h, padding) \ + unsigned int vpx_sub_pixel_avg_variance##w##x##h##_neon( \ + const uint8_t *src, int source_stride, int xoffset, int yoffset, \ + const uint8_t *ref, int ref_stride, unsigned int *sse, \ + const uint8_t *second_pred) { \ + if (xoffset == 0) { \ + uint8_t tmp[w * h]; \ + if (yoffset == 0) { \ + avg_pred(src, tmp, source_stride, w, h, second_pred); \ + return vpx_variance##w##x##h(tmp, w, ref, ref_stride, sse); \ + } else if (yoffset == 4) { \ + avg_pred_var_filter_block2d_avg(src, tmp, source_stride, \ + source_stride, w, h, second_pred); \ + return vpx_variance##w##x##h(tmp, w, ref, ref_stride, sse); \ + } else { \ + avg_pred_var_filter_block2d_bil_w##w( \ + src, tmp, source_stride, source_stride, h, yoffset, second_pred); \ + return vpx_variance##w##x##h(tmp, w, ref, ref_stride, sse); \ + } \ + } else if (xoffset == 4) { \ + uint8_t tmp0[w * (h + padding)]; \ + if (yoffset == 0) { \ + avg_pred_var_filter_block2d_avg(src, tmp0, source_stride, 1, w, h, \ + second_pred); \ + return vpx_variance##w##x##h(tmp0, w, ref, ref_stride, sse); \ + } else if (yoffset == 4) { \ + uint8_t tmp1[w * (h + padding)]; \ + var_filter_block2d_avg(src, tmp0, source_stride, 1, w, (h + padding)); \ + avg_pred_var_filter_block2d_avg(tmp0, tmp1, w, w, w, h, second_pred); \ + return vpx_variance##w##x##h(tmp1, w, ref, ref_stride, sse); \ + } else { \ + uint8_t tmp1[w * (h + padding)]; \ + var_filter_block2d_avg(src, tmp0, source_stride, 1, w, (h + padding)); \ + avg_pred_var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset, \ + second_pred); \ + return vpx_variance##w##x##h(tmp1, w, ref, ref_stride, sse); \ + } \ + } else { \ + uint8_t tmp0[w * (h + padding)]; \ + if (yoffset == 0) { \ + avg_pred_var_filter_block2d_bil_w##w(src, tmp0, source_stride, 1, h, \ + xoffset, second_pred); \ + return vpx_variance##w##x##h(tmp0, w, ref, ref_stride, sse); \ + } else if (yoffset == 4) { \ + uint8_t tmp1[w * h]; \ + var_filter_block2d_bil_w##w(src, tmp0, source_stride, 1, \ + (h + padding), xoffset); \ + avg_pred_var_filter_block2d_avg(tmp0, tmp1, w, w, w, h, second_pred); \ + return vpx_variance##w##x##h(tmp1, w, ref, ref_stride, sse); \ + } else { \ + uint8_t tmp1[w * h]; \ + var_filter_block2d_bil_w##w(src, tmp0, source_stride, 1, \ + (h + padding), xoffset); \ + avg_pred_var_filter_block2d_bil_w##w(tmp0, tmp1, w, w, h, yoffset, \ + second_pred); \ + return vpx_variance##w##x##h(tmp1, w, ref, ref_stride, sse); \ + } \ + } \ + } + +// 4x blocks are processed two rows at a time, so require an extra row of +// padding. +SUBPEL_AVG_VARIANCE_WXH_NEON(4, 4, 2) +SUBPEL_AVG_VARIANCE_WXH_NEON(4, 8, 2) + +SUBPEL_AVG_VARIANCE_WXH_NEON(8, 4, 1) +SUBPEL_AVG_VARIANCE_WXH_NEON(8, 8, 1) +SUBPEL_AVG_VARIANCE_WXH_NEON(8, 16, 1) + +SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(16, 8, 1) +SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(16, 16, 1) +SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(16, 32, 1) + +SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(32, 16, 1) +SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(32, 32, 1) +SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(32, 64, 1) + +SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(64, 32, 1) +SPECIALIZED_SUBPEL_AVG_VARIANCE_WXH_NEON(64, 64, 1) diff --git a/libs/libvpx/vpx_dsp/arm/subpel_variance_neon.h b/libs/libvpx/vpx_dsp/arm/subpel_variance_neon.h new file mode 100644 index 0000000000..10ca56bd3e --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/subpel_variance_neon.h @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2026 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VPX_DSP_ARM_SUBPEL_VARIANCE_NEON_H_ +#define VPX_VPX_DSP_ARM_SUBPEL_VARIANCE_NEON_H_ + +#include "vpx_config.h" +#include "vpx_dsp/arm/mem_neon.h" + +// Process a block exactly 4 wide and a multiple of 2 high. +static INLINE void var_filter_block2d_bil_w4(const uint8_t *src_ptr, + uint8_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset) { + const uint8x8_t f0 = vdup_n_u8(8 - filter_offset); + const uint8x8_t f1 = vdup_n_u8(filter_offset); + + int i = dst_height; + do { + uint8x8_t s0 = load_unaligned_u8(src_ptr, src_stride); + uint8x8_t s1 = load_unaligned_u8(src_ptr + pixel_step, src_stride); + uint16x8_t blend = vmlal_u8(vmull_u8(s0, f0), s1, f1); + uint8x8_t blend_u8 = vrshrn_n_u16(blend, 3); + vst1_u8(dst_ptr, blend_u8); + + src_ptr += 2 * src_stride; + dst_ptr += 2 * 4; + i -= 2; + } while (i != 0); +} + +// Process a block exactly 8 wide and any height. +static INLINE void var_filter_block2d_bil_w8(const uint8_t *src_ptr, + uint8_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset) { + const uint8x8_t f0 = vdup_n_u8(8 - filter_offset); + const uint8x8_t f1 = vdup_n_u8(filter_offset); + + int i = dst_height; + do { + uint8x8_t s0 = vld1_u8(src_ptr); + uint8x8_t s1 = vld1_u8(src_ptr + pixel_step); + uint16x8_t blend = vmlal_u8(vmull_u8(s0, f0), s1, f1); + uint8x8_t blend_u8 = vrshrn_n_u16(blend, 3); + vst1_u8(dst_ptr, blend_u8); + + src_ptr += src_stride; + dst_ptr += 8; + } while (--i != 0); +} + +// Process a block which is a multiple of 16 wide and any height. +static INLINE void var_filter_block2d_bil_large(const uint8_t *src_ptr, + uint8_t *dst_ptr, + int src_stride, int pixel_step, + int dst_width, int dst_height, + int filter_offset) { + const uint8x8_t f0 = vdup_n_u8(8 - filter_offset); + const uint8x8_t f1 = vdup_n_u8(filter_offset); + + int i = dst_height; + do { + int j = 0; + do { + uint8x16_t s0 = vld1q_u8(src_ptr + j); + uint8x16_t s1 = vld1q_u8(src_ptr + j + pixel_step); + uint16x8_t blend_l = + vmlal_u8(vmull_u8(vget_low_u8(s0), f0), vget_low_u8(s1), f1); + uint16x8_t blend_h = + vmlal_u8(vmull_u8(vget_high_u8(s0), f0), vget_high_u8(s1), f1); + uint8x8_t out_lo = vrshrn_n_u16(blend_l, 3); + uint8x8_t out_hi = vrshrn_n_u16(blend_h, 3); + vst1q_u8(dst_ptr + j, vcombine_u8(out_lo, out_hi)); + + j += 16; + } while (j < dst_width); + + src_ptr += src_stride; + dst_ptr += dst_width; + } while (--i != 0); +} + +static INLINE void var_filter_block2d_bil_w16(const uint8_t *src_ptr, + uint8_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset) { + var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, pixel_step, 16, + dst_height, filter_offset); +} +static INLINE void var_filter_block2d_bil_w32(const uint8_t *src_ptr, + uint8_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset) { + var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, pixel_step, 32, + dst_height, filter_offset); +} +static INLINE void var_filter_block2d_bil_w64(const uint8_t *src_ptr, + uint8_t *dst_ptr, int src_stride, + int pixel_step, int dst_height, + int filter_offset) { + var_filter_block2d_bil_large(src_ptr, dst_ptr, src_stride, pixel_step, 64, + dst_height, filter_offset); +} + +static INLINE void var_filter_block2d_avg(const uint8_t *src_ptr, + uint8_t *dst_ptr, int src_stride, + int pixel_step, int dst_width, + int dst_height) { + int i = dst_height; + + // We only specialize on the filter values for large block sizes (>= 16x16.) + assert(dst_width >= 16 && dst_width % 16 == 0); + + do { + int j = 0; + do { + uint8x16_t s0 = vld1q_u8(src_ptr + j); + uint8x16_t s1 = vld1q_u8(src_ptr + j + pixel_step); + uint8x16_t avg = vrhaddq_u8(s0, s1); + vst1q_u8(dst_ptr + j, avg); + + j += 16; + } while (j < dst_width); + + src_ptr += src_stride; + dst_ptr += dst_width; + } while (--i != 0); +} + +#endif // VPX_VPX_DSP_ARM_SUBPEL_VARIANCE_NEON_H_ diff --git a/libs/libvpx/vpx_dsp/arm/subpel_variance_neon_dotprod.c b/libs/libvpx/vpx_dsp/arm/subpel_variance_neon_dotprod.c new file mode 100644 index 0000000000..02d4216c64 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/subpel_variance_neon_dotprod.c @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2026 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include "./vpx_dsp_rtcd.h" + +#include "vpx_dsp/arm/subpel_variance_neon.h" + +static inline void bil_variance_8xh_neon_dotprod( + const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, + int pixel_step, int h, uint32_t *sse, int *sum, int filter_offset) { + const uint8x8_t f0 = vdup_n_u8(8 - filter_offset); + const uint8x8_t f1 = vdup_n_u8(filter_offset); + + uint32x4_t src_sum = vdupq_n_u32(0); + uint32x4_t ref_sum = vdupq_n_u32(0); + uint32x4_t sse_u32 = vdupq_n_u32(0); + + do { + uint8x8_t s0_lo = vld1_u8(src); + uint8x8_t s1_lo = vld1_u8(src + pixel_step); + uint16x8_t blend_l = vmull_u8(s0_lo, f0); + blend_l = vmlal_u8(blend_l, s1_lo, f1); + uint8x8_t s0_hi = vld1_u8(src + src_stride); + uint8x8_t s1_hi = vld1_u8(src + src_stride + pixel_step); + uint16x8_t blend_h = vmull_u8(s0_hi, f0); + blend_h = vmlal_u8(blend_h, s1_hi, f1); + uint8x16_t s = + vcombine_u8(vrshrn_n_u16(blend_l, 3), vrshrn_n_u16(blend_h, 3)); + uint8x16_t r = load_u8_8x2(ref, ref_stride); + + src_sum = vdotq_u32(src_sum, s, vdupq_n_u8(1)); + ref_sum = vdotq_u32(ref_sum, r, vdupq_n_u8(1)); + + uint8x16_t abs_diff = vabdq_u8(s, r); + sse_u32 = vdotq_u32(sse_u32, abs_diff, abs_diff); + + src += 2 * src_stride; + ref += 2 * ref_stride; + h -= 2; + } while (h != 0); + + int32x4_t sum_diff = + vsubq_s32(vreinterpretq_s32_u32(src_sum), vreinterpretq_s32_u32(ref_sum)); + *sum = vaddvq_s32(sum_diff); + *sse = vaddvq_u32(sse_u32); +} + +static inline void bil_variance_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int pixel_step, int w, int h, + uint32_t *sse, int *sum, + int filter_offset) { + assert(w != 4); + + if (w == 8) { + bil_variance_8xh_neon_dotprod(src, src_stride, ref, ref_stride, pixel_step, + h, sse, sum, filter_offset); + return; + } + + const uint8x8_t f0 = vdup_n_u8(8 - filter_offset); + const uint8x8_t f1 = vdup_n_u8(filter_offset); + + uint32x4_t src_sum = vdupq_n_u32(0); + uint32x4_t ref_sum = vdupq_n_u32(0); + uint32x4_t sse_u32 = vdupq_n_u32(0); + + do { + int i = 0; + do { + uint8x16_t s0 = vld1q_u8(src + i); + uint8x16_t s1 = vld1q_u8(src + i + pixel_step); + uint16x8_t blend_l = vmull_u8(vget_low_u8(s0), f0); + blend_l = vmlal_u8(blend_l, vget_low_u8(s1), f1); + uint16x8_t blend_h = vmull_u8(vget_high_u8(s0), f0); + blend_h = vmlal_u8(blend_h, vget_high_u8(s1), f1); + uint8x16_t s = + vcombine_u8(vrshrn_n_u16(blend_l, 3), vrshrn_n_u16(blend_h, 3)); + uint8x16_t r = vld1q_u8(ref + i); + + src_sum = vdotq_u32(src_sum, s, vdupq_n_u8(1)); + ref_sum = vdotq_u32(ref_sum, r, vdupq_n_u8(1)); + + uint8x16_t abs_diff = vabdq_u8(s, r); + sse_u32 = vdotq_u32(sse_u32, abs_diff, abs_diff); + + i += 16; + } while (i < w); + + src += src_stride; + ref += ref_stride; + } while (--h != 0); + + int32x4_t sum_diff = + vsubq_s32(vreinterpretq_s32_u32(src_sum), vreinterpretq_s32_u32(ref_sum)); + *sum = vaddvq_s32(sum_diff); + *sse = vaddvq_u32(sse_u32); +} + +static inline void avg_variance_neon_dotprod(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, + int pixel_step, int w, int h, + uint32_t *sse, int *sum) { + assert(w >= 16 && w % 16 == 0); + uint32x4_t src_sum = vdupq_n_u32(0); + uint32x4_t ref_sum = vdupq_n_u32(0); + uint32x4_t sse_u32 = vdupq_n_u32(0); + + do { + int i = 0; + do { + uint8x16_t s0 = vld1q_u8(src + i); + uint8x16_t s1 = vld1q_u8(src + i + pixel_step); + uint8x16_t s = vrhaddq_u8(s0, s1); + uint8x16_t r = vld1q_u8(ref + i); + + src_sum = vdotq_u32(src_sum, s, vdupq_n_u8(1)); + ref_sum = vdotq_u32(ref_sum, r, vdupq_n_u8(1)); + + uint8x16_t abs_diff = vabdq_u8(s, r); + sse_u32 = vdotq_u32(sse_u32, abs_diff, abs_diff); + + i += 16; + } while (i < w); + + src += src_stride; + ref += ref_stride; + } while (--h != 0); + + int32x4_t sum_diff = + vsubq_s32(vreinterpretq_s32_u32(src_sum), vreinterpretq_s32_u32(ref_sum)); + *sum = vaddvq_s32(sum_diff); + *sse = vaddvq_u32(sse_u32); +} + +#define SUBPEL_VARIANCE_4XH_NEON_DOTPROD(h, padding) \ + unsigned int vpx_sub_pixel_variance4x##h##_neon_dotprod( \ + const uint8_t *src, int src_stride, int xoffset, int yoffset, \ + const uint8_t *ref, int ref_stride, uint32_t *sse) { \ + uint8_t tmp0[4 * (h + padding)]; \ + uint8_t tmp1[4 * h]; \ + var_filter_block2d_bil_w4(src, tmp0, src_stride, 1, (h + padding), \ + xoffset); \ + var_filter_block2d_bil_w4(tmp0, tmp1, 4, 4, h, yoffset); \ + return vpx_variance4x##h##_neon_dotprod(tmp1, 4, ref, ref_stride, sse); \ + } + +#define SUBPEL_VARIANCE_WXH_NEON_DOTPROD(w, h, shift, padding) \ + unsigned int vpx_sub_pixel_variance##w##x##h##_neon_dotprod( \ + const uint8_t *src, int src_stride, int xoffset, int yoffset, \ + const uint8_t *ref, int ref_stride, unsigned int *sse) { \ + uint8_t tmp[w * (h + padding)]; \ + int sum; \ + var_filter_block2d_bil_w##w(src, tmp, src_stride, 1, h + padding, \ + xoffset); \ + bil_variance_neon_dotprod(tmp, w, ref, ref_stride, w, w, h, sse, &sum, \ + yoffset); \ + return *sse - (uint32_t)(((int64_t)sum * sum) >> shift); \ + } + +#define SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON_DOTPROD(w, h, shift, padding) \ + unsigned int vpx_sub_pixel_variance##w##x##h##_neon_dotprod( \ + const uint8_t *src, int src_stride, int xoffset, int yoffset, \ + const uint8_t *ref, int ref_stride, unsigned int *sse) { \ + int sum; \ + if (xoffset == 0) { \ + if (yoffset == 0) { \ + return vpx_variance##w##x##h##_neon_dotprod(src, src_stride, ref, \ + ref_stride, sse); \ + } else if (yoffset == 4) { \ + avg_variance_neon_dotprod(src, src_stride, ref, ref_stride, \ + src_stride, w, h, sse, &sum); \ + } else { \ + bil_variance_neon_dotprod(src, src_stride, ref, ref_stride, \ + src_stride, w, h, sse, &sum, yoffset); \ + } \ + } else if (xoffset == 4) { \ + uint8_t tmp[w * (h + padding)]; \ + if (yoffset == 0) { \ + avg_variance_neon_dotprod(src, src_stride, ref, ref_stride, 1, w, h, \ + sse, &sum); \ + } else if (yoffset == 4) { \ + var_filter_block2d_avg(src, tmp, src_stride, 1, w, h + padding); \ + avg_variance_neon_dotprod(tmp, w, ref, ref_stride, w, w, h, sse, \ + &sum); \ + } else { \ + var_filter_block2d_avg(src, tmp, src_stride, 1, w, h + padding); \ + bil_variance_neon_dotprod(tmp, w, ref, ref_stride, w, w, h, sse, &sum, \ + yoffset); \ + } \ + } else { \ + uint8_t tmp[w * (h + padding)]; \ + if (yoffset == 0) { \ + bil_variance_neon_dotprod(src, src_stride, ref, ref_stride, 1, w, h, \ + sse, &sum, xoffset); \ + } else if (yoffset == 4) { \ + var_filter_block2d_bil_w##w(src, tmp, src_stride, 1, h + padding, \ + xoffset); \ + avg_variance_neon_dotprod(tmp, w, ref, ref_stride, w, w, h, sse, \ + &sum); \ + } else { \ + var_filter_block2d_bil_w##w(src, tmp, src_stride, 1, h + padding, \ + xoffset); \ + bil_variance_neon_dotprod(tmp, w, ref, ref_stride, w, w, h, sse, &sum, \ + yoffset); \ + } \ + } \ + return *sse - (uint32_t)(((int64_t)sum * sum) >> shift); \ + } + +SUBPEL_VARIANCE_4XH_NEON_DOTPROD(8, 2) +SUBPEL_VARIANCE_WXH_NEON_DOTPROD(8, 4, 5, 1) +SUBPEL_VARIANCE_WXH_NEON_DOTPROD(8, 8, 6, 1) +SUBPEL_VARIANCE_WXH_NEON_DOTPROD(8, 16, 7, 1) +SUBPEL_VARIANCE_WXH_NEON_DOTPROD(16, 8, 7, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON_DOTPROD(16, 16, 8, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON_DOTPROD(16, 32, 9, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON_DOTPROD(32, 16, 9, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON_DOTPROD(32, 32, 10, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON_DOTPROD(32, 64, 11, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON_DOTPROD(64, 32, 11, 1) +SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON_DOTPROD(64, 64, 12, 1) + +#undef SUBPEL_VARIANCE_WXH_NEON_DOTPROD +#undef SPECIALIZED_SUBPEL_VARIANCE_WXH_NEON_DOTPROD diff --git a/libs/libvpx/vpx_dsp/arm/subtract_neon.c b/libs/libvpx/vpx_dsp/arm/subtract_neon.c index 612897e247..3b98df93ea 100644 --- a/libs/libvpx/vpx_dsp/arm/subtract_neon.c +++ b/libs/libvpx/vpx_dsp/arm/subtract_neon.c @@ -16,6 +16,13 @@ #include "vpx/vpx_integer.h" #include "vpx_dsp/arm/mem_neon.h" +// Prefer the explicit high-half operation to preserve full-width loads in GCC. +#if VPX_ARCH_AARCH64 +#define VSUBL_HIGH_U8(a, b) vsubl_high_u8((a), (b)) +#else +#define VSUBL_HIGH_U8(a, b) vsubl_u8(vget_high_u8((a)), vget_high_u8((b))) +#endif + void vpx_subtract_block_neon(int rows, int cols, int16_t *diff, ptrdiff_t diff_stride, const uint8_t *src, ptrdiff_t src_stride, const uint8_t *pred, @@ -30,9 +37,9 @@ void vpx_subtract_block_neon(int rows, int cols, int16_t *diff, const uint8x16_t p0 = vld1q_u8(&pred[c + 0]); const uint8x16_t p1 = vld1q_u8(&pred[c + 16]); const uint16x8_t d0 = vsubl_u8(vget_low_u8(s0), vget_low_u8(p0)); - const uint16x8_t d1 = vsubl_u8(vget_high_u8(s0), vget_high_u8(p0)); + const uint16x8_t d1 = VSUBL_HIGH_U8(s0, p0); const uint16x8_t d2 = vsubl_u8(vget_low_u8(s1), vget_low_u8(p1)); - const uint16x8_t d3 = vsubl_u8(vget_high_u8(s1), vget_high_u8(p1)); + const uint16x8_t d3 = VSUBL_HIGH_U8(s1, p1); vst1q_s16(&diff[c + 0], vreinterpretq_s16_u16(d0)); vst1q_s16(&diff[c + 8], vreinterpretq_s16_u16(d1)); vst1q_s16(&diff[c + 16], vreinterpretq_s16_u16(d2)); @@ -47,7 +54,7 @@ void vpx_subtract_block_neon(int rows, int cols, int16_t *diff, const uint8x16_t s = vld1q_u8(&src[0]); const uint8x16_t p = vld1q_u8(&pred[0]); const uint16x8_t d0 = vsubl_u8(vget_low_u8(s), vget_low_u8(p)); - const uint16x8_t d1 = vsubl_u8(vget_high_u8(s), vget_high_u8(p)); + const uint16x8_t d1 = VSUBL_HIGH_U8(s, p); vst1q_s16(&diff[0], vreinterpretq_s16_u16(d0)); vst1q_s16(&diff[8], vreinterpretq_s16_u16(d1)); diff += diff_stride; @@ -79,3 +86,61 @@ void vpx_subtract_block_neon(int rows, int cols, int16_t *diff, } while (r); } } + +#undef VSUBL_HIGH_U8 + +#if CONFIG_VP9_HIGHBITDEPTH +void vpx_highbd_subtract_block_neon(int rows, int cols, int16_t *diff_ptr, + ptrdiff_t diff_stride, + const uint8_t *src8_ptr, + ptrdiff_t src_stride, + const uint8_t *pred8_ptr, + ptrdiff_t pred_stride, int bd) { + int r = rows, c; + uint16_t *src = CONVERT_TO_SHORTPTR(src8_ptr); + uint16_t *pred = CONVERT_TO_SHORTPTR(pred8_ptr); + (void)bd; + + if (cols >= 16) { + do { + for (c = 0; c < cols; c += 16) { + const uint16x8_t s0 = vld1q_u16(&src[c + 0]); + const uint16x8_t s1 = vld1q_u16(&src[c + 8]); + const uint16x8_t p0 = vld1q_u16(&pred[c + 0]); + const uint16x8_t p1 = vld1q_u16(&pred[c + 8]); + const uint16x8_t d0 = vsubq_u16(s0, p0); + const uint16x8_t d1 = vsubq_u16(s1, p1); + vst1q_s16(&diff_ptr[c + 0], vreinterpretq_s16_u16(d0)); + vst1q_s16(&diff_ptr[c + 8], vreinterpretq_s16_u16(d1)); + } + diff_ptr += diff_stride; + pred += pred_stride; + src += src_stride; + } while (--r); + } else if (cols >= 8) { + do { + for (c = 0; c < cols; c += 8) { + const uint16x8_t s = vld1q_u16(&src[c]); + const uint16x8_t p = vld1q_u16(&pred[c]); + const uint16x8_t d0 = vsubq_u16(s, p); + vst1q_s16(&diff_ptr[c], vreinterpretq_s16_u16(d0)); + } + diff_ptr += diff_stride; + pred += pred_stride; + src += src_stride; + } while (--r); + } else if (cols >= 4) { + do { + for (c = 0; c < cols; c += 4) { + const uint16x4_t s = vld1_u16(&src[c]); + const uint16x4_t p = vld1_u16(&pred[c]); + const uint16x4_t v_diff = vsub_u16(s, p); + vst1_s16(&diff_ptr[c], vreinterpret_s16_u16(v_diff)); + } + diff_ptr += diff_stride; + pred += pred_stride; + src += src_stride; + } while (--r); + } +} +#endif // CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vpx_dsp/arm/sum_neon.h b/libs/libvpx/vpx_dsp/arm/sum_neon.h index 9a7c424e8e..11821dc10e 100644 --- a/libs/libvpx/vpx_dsp/arm/sum_neon.h +++ b/libs/libvpx/vpx_dsp/arm/sum_neon.h @@ -16,8 +16,51 @@ #include "./vpx_config.h" #include "vpx/vpx_integer.h" +static INLINE uint16_t horizontal_add_uint8x4(const uint8x8_t a) { +#if VPX_ARCH_AARCH64 + return vaddlv_u8(a); +#else + const uint16x4_t b = vpaddl_u8(a); + const uint16x4_t c = vpadd_u16(b, b); + return vget_lane_u16(c, 0); +#endif +} + +static INLINE uint16_t horizontal_add_uint8x8(const uint8x8_t a) { +#if VPX_ARCH_AARCH64 + return vaddlv_u8(a); +#else + const uint16x4_t b = vpaddl_u8(a); + const uint16x4_t c = vpadd_u16(b, b); + const uint16x4_t d = vpadd_u16(c, c); + return vget_lane_u16(d, 0); +#endif +} + +static INLINE uint16_t horizontal_add_uint8x16(const uint8x16_t a) { +#if VPX_ARCH_AARCH64 + return vaddlvq_u8(a); +#else + const uint16x8_t b = vpaddlq_u8(a); + const uint16x4_t c = vadd_u16(vget_low_u16(b), vget_high_u16(b)); + const uint16x4_t d = vpadd_u16(c, c); + const uint16x4_t e = vpadd_u16(d, d); + return vget_lane_u16(e, 0); +#endif +} + +static INLINE uint16_t horizontal_add_uint16x4(const uint16x4_t a) { +#if VPX_ARCH_AARCH64 + return vaddv_u16(a); +#else + const uint16x4_t b = vpadd_u16(a, a); + const uint16x4_t c = vpadd_u16(b, b); + return vget_lane_u16(c, 0); +#endif +} + static INLINE int32_t horizontal_add_int16x8(const int16x8_t a) { -#if defined(__aarch64__) +#if VPX_ARCH_AARCH64 return vaddlvq_s16(a); #else const int32x4_t b = vpaddlq_s16(a); @@ -29,7 +72,7 @@ static INLINE int32_t horizontal_add_int16x8(const int16x8_t a) { } static INLINE uint32_t horizontal_add_uint16x8(const uint16x8_t a) { -#if defined(__aarch64__) +#if VPX_ARCH_AARCH64 return vaddlvq_u16(a); #else const uint32x4_t b = vpaddlq_u16(a); @@ -40,8 +83,67 @@ static INLINE uint32_t horizontal_add_uint16x8(const uint16x8_t a) { #endif } +static INLINE uint32x4_t horizontal_add_4d_uint16x8(const uint16x8_t sum[4]) { +#if VPX_ARCH_AARCH64 + const uint16x8_t a0 = vpaddq_u16(sum[0], sum[1]); + const uint16x8_t a1 = vpaddq_u16(sum[2], sum[3]); + const uint16x8_t b0 = vpaddq_u16(a0, a1); + return vpaddlq_u16(b0); +#else + const uint16x4_t a0 = vadd_u16(vget_low_u16(sum[0]), vget_high_u16(sum[0])); + const uint16x4_t a1 = vadd_u16(vget_low_u16(sum[1]), vget_high_u16(sum[1])); + const uint16x4_t a2 = vadd_u16(vget_low_u16(sum[2]), vget_high_u16(sum[2])); + const uint16x4_t a3 = vadd_u16(vget_low_u16(sum[3]), vget_high_u16(sum[3])); + const uint16x4_t b0 = vpadd_u16(a0, a1); + const uint16x4_t b1 = vpadd_u16(a2, a3); + return vpaddlq_u16(vcombine_u16(b0, b1)); +#endif +} + +static INLINE uint32_t horizontal_long_add_uint16x8(const uint16x8_t vec_lo, + const uint16x8_t vec_hi) { +#if VPX_ARCH_AARCH64 + return vaddlvq_u16(vec_lo) + vaddlvq_u16(vec_hi); +#else + const uint32x4_t vec_l_lo = + vaddl_u16(vget_low_u16(vec_lo), vget_high_u16(vec_lo)); + const uint32x4_t vec_l_hi = + vaddl_u16(vget_low_u16(vec_hi), vget_high_u16(vec_hi)); + const uint32x4_t a = vaddq_u32(vec_l_lo, vec_l_hi); + const uint64x2_t b = vpaddlq_u32(a); + const uint32x2_t c = vadd_u32(vreinterpret_u32_u64(vget_low_u64(b)), + vreinterpret_u32_u64(vget_high_u64(b))); + return vget_lane_u32(c, 0); +#endif +} + +static INLINE uint32x4_t horizontal_long_add_4d_uint16x8( + const uint16x8_t sum_lo[4], const uint16x8_t sum_hi[4]) { + const uint32x4_t a0 = vpaddlq_u16(sum_lo[0]); + const uint32x4_t a1 = vpaddlq_u16(sum_lo[1]); + const uint32x4_t a2 = vpaddlq_u16(sum_lo[2]); + const uint32x4_t a3 = vpaddlq_u16(sum_lo[3]); + const uint32x4_t b0 = vpadalq_u16(a0, sum_hi[0]); + const uint32x4_t b1 = vpadalq_u16(a1, sum_hi[1]); + const uint32x4_t b2 = vpadalq_u16(a2, sum_hi[2]); + const uint32x4_t b3 = vpadalq_u16(a3, sum_hi[3]); +#if VPX_ARCH_AARCH64 + const uint32x4_t c0 = vpaddq_u32(b0, b1); + const uint32x4_t c1 = vpaddq_u32(b2, b3); + return vpaddq_u32(c0, c1); +#else + const uint32x2_t c0 = vadd_u32(vget_low_u32(b0), vget_high_u32(b0)); + const uint32x2_t c1 = vadd_u32(vget_low_u32(b1), vget_high_u32(b1)); + const uint32x2_t c2 = vadd_u32(vget_low_u32(b2), vget_high_u32(b2)); + const uint32x2_t c3 = vadd_u32(vget_low_u32(b3), vget_high_u32(b3)); + const uint32x2_t d0 = vpadd_u32(c0, c1); + const uint32x2_t d1 = vpadd_u32(c2, c3); + return vcombine_u32(d0, d1); +#endif +} + static INLINE int32_t horizontal_add_int32x2(const int32x2_t a) { -#if defined(__aarch64__) +#if VPX_ARCH_AARCH64 return vaddv_s32(a); #else return vget_lane_s32(a, 0) + vget_lane_s32(a, 1); @@ -49,15 +151,16 @@ static INLINE int32_t horizontal_add_int32x2(const int32x2_t a) { } static INLINE uint32_t horizontal_add_uint32x2(const uint32x2_t a) { -#if defined(__aarch64__) +#if VPX_ARCH_AARCH64 return vaddv_u32(a); #else - return vget_lane_u32(a, 0) + vget_lane_u32(a, 1); + const uint64x1_t b = vpaddl_u32(a); + return vget_lane_u32(vreinterpret_u32_u64(b), 0); #endif } static INLINE int32_t horizontal_add_int32x4(const int32x4_t a) { -#if defined(__aarch64__) +#if VPX_ARCH_AARCH64 return vaddvq_s32(a); #else const int64x2_t b = vpaddlq_s32(a); @@ -68,7 +171,7 @@ static INLINE int32_t horizontal_add_int32x4(const int32x4_t a) { } static INLINE uint32_t horizontal_add_uint32x4(const uint32x4_t a) { -#if defined(__aarch64__) +#if VPX_ARCH_AARCH64 return vaddvq_u32(a); #else const uint64x2_t b = vpaddlq_u32(a); @@ -77,4 +180,96 @@ static INLINE uint32_t horizontal_add_uint32x4(const uint32x4_t a) { return vget_lane_u32(c, 0); #endif } + +static INLINE uint32x4_t horizontal_add_4d_uint32x4(const uint32x4_t sum[4]) { +#if VPX_ARCH_AARCH64 + uint32x4_t res01 = vpaddq_u32(sum[0], sum[1]); + uint32x4_t res23 = vpaddq_u32(sum[2], sum[3]); + return vpaddq_u32(res01, res23); +#else + uint32x4_t res = vdupq_n_u32(0); + res = vsetq_lane_u32(horizontal_add_uint32x4(sum[0]), res, 0); + res = vsetq_lane_u32(horizontal_add_uint32x4(sum[1]), res, 1); + res = vsetq_lane_u32(horizontal_add_uint32x4(sum[2]), res, 2); + res = vsetq_lane_u32(horizontal_add_uint32x4(sum[3]), res, 3); + return res; +#endif +} + +static INLINE uint64_t horizontal_long_add_uint32x4(const uint32x4_t a) { +#if VPX_ARCH_AARCH64 + return vaddlvq_u32(a); +#else + const uint64x2_t b = vpaddlq_u32(a); + return vgetq_lane_u64(b, 0) + vgetq_lane_u64(b, 1); +#endif +} + +static INLINE int64_t horizontal_add_int64x2(const int64x2_t a) { +#if VPX_ARCH_AARCH64 + return vaddvq_s64(a); +#else + return vgetq_lane_s64(a, 0) + vgetq_lane_s64(a, 1); +#endif +} + +static INLINE uint64_t horizontal_add_uint64x2(const uint64x2_t a) { +#if VPX_ARCH_AARCH64 + return vaddvq_u64(a); +#else + return vgetq_lane_u64(a, 0) + vgetq_lane_u64(a, 1); +#endif +} + +static INLINE uint64_t horizontal_long_add_uint32x4_x2(const uint32x4_t a[2]) { + return horizontal_long_add_uint32x4(a[0]) + + horizontal_long_add_uint32x4(a[1]); +} + +static INLINE uint64_t horizontal_long_add_uint32x4_x4(const uint32x4_t a[4]) { + uint64x2_t sum = vpaddlq_u32(a[0]); + sum = vpadalq_u32(sum, a[1]); + sum = vpadalq_u32(sum, a[2]); + sum = vpadalq_u32(sum, a[3]); + + return horizontal_add_uint64x2(sum); +} + +static INLINE uint64_t horizontal_long_add_uint32x4_x8(const uint32x4_t a[8]) { + uint64x2_t sum[2]; + sum[0] = vpaddlq_u32(a[0]); + sum[1] = vpaddlq_u32(a[1]); + sum[0] = vpadalq_u32(sum[0], a[2]); + sum[1] = vpadalq_u32(sum[1], a[3]); + sum[0] = vpadalq_u32(sum[0], a[4]); + sum[1] = vpadalq_u32(sum[1], a[5]); + sum[0] = vpadalq_u32(sum[0], a[6]); + sum[1] = vpadalq_u32(sum[1], a[7]); + + return horizontal_add_uint64x2(vaddq_u64(sum[0], sum[1])); +} + +static INLINE uint64_t +horizontal_long_add_uint32x4_x16(const uint32x4_t a[16]) { + uint64x2_t sum[2]; + sum[0] = vpaddlq_u32(a[0]); + sum[1] = vpaddlq_u32(a[1]); + sum[0] = vpadalq_u32(sum[0], a[2]); + sum[1] = vpadalq_u32(sum[1], a[3]); + sum[0] = vpadalq_u32(sum[0], a[4]); + sum[1] = vpadalq_u32(sum[1], a[5]); + sum[0] = vpadalq_u32(sum[0], a[6]); + sum[1] = vpadalq_u32(sum[1], a[7]); + sum[0] = vpadalq_u32(sum[0], a[8]); + sum[1] = vpadalq_u32(sum[1], a[9]); + sum[0] = vpadalq_u32(sum[0], a[10]); + sum[1] = vpadalq_u32(sum[1], a[11]); + sum[0] = vpadalq_u32(sum[0], a[12]); + sum[1] = vpadalq_u32(sum[1], a[13]); + sum[0] = vpadalq_u32(sum[0], a[14]); + sum[1] = vpadalq_u32(sum[1], a[15]); + + return horizontal_add_uint64x2(vaddq_u64(sum[0], sum[1])); +} + #endif // VPX_VPX_DSP_ARM_SUM_NEON_H_ diff --git a/libs/libvpx/vpx_dsp/arm/sum_squares_neon.c b/libs/libvpx/vpx_dsp/arm/sum_squares_neon.c index cfefad9938..3fdfa83d2a 100644 --- a/libs/libvpx/vpx_dsp/arm/sum_squares_neon.c +++ b/libs/libvpx/vpx_dsp/arm/sum_squares_neon.c @@ -9,77 +9,132 @@ */ #include - #include + #include "./vpx_dsp_rtcd.h" +#include "vpx_dsp/arm/sum_neon.h" uint64_t vpx_sum_squares_2d_i16_neon(const int16_t *src, int stride, int size) { - uint64x1_t s2; - if (size == 4) { int16x4_t s[4]; - int32x4_t s0; - uint32x2_t s1; + int32x4_t sum_s32; s[0] = vld1_s16(src + 0 * stride); s[1] = vld1_s16(src + 1 * stride); s[2] = vld1_s16(src + 2 * stride); s[3] = vld1_s16(src + 3 * stride); - s0 = vmull_s16(s[0], s[0]); - s0 = vmlal_s16(s0, s[1], s[1]); - s0 = vmlal_s16(s0, s[2], s[2]); - s0 = vmlal_s16(s0, s[3], s[3]); - s1 = vpadd_u32(vget_low_u32(vreinterpretq_u32_s32(s0)), - vget_high_u32(vreinterpretq_u32_s32(s0))); - s2 = vpaddl_u32(s1); + + sum_s32 = vmull_s16(s[0], s[0]); + sum_s32 = vmlal_s16(sum_s32, s[1], s[1]); + sum_s32 = vmlal_s16(sum_s32, s[2], s[2]); + sum_s32 = vmlal_s16(sum_s32, s[3], s[3]); + + return horizontal_long_add_uint32x4(vreinterpretq_u32_s32(sum_s32)); } else { - int r = size; - uint64x2_t s1 = vdupq_n_u64(0); + uint64x2_t sum_u64 = vdupq_n_u64(0); + int rows = size; do { - int c = size; - int32x4_t s0 = vdupq_n_s32(0); - const int16_t *src_t = src; + const int16_t *src_ptr = src; +#if VPX_ARCH_AARCH64 + int32x4_t sum_s32[4] = { vdupq_n_s32(0), vdupq_n_s32(0), vdupq_n_s32(0), + vdupq_n_s32(0) }; +#else + int32x4_t sum_s32[2] = { vdupq_n_s32(0), vdupq_n_s32(0) }; +#endif + int cols = size; do { int16x8_t s[8]; - s[0] = vld1q_s16(src_t + 0 * stride); - s[1] = vld1q_s16(src_t + 1 * stride); - s[2] = vld1q_s16(src_t + 2 * stride); - s[3] = vld1q_s16(src_t + 3 * stride); - s[4] = vld1q_s16(src_t + 4 * stride); - s[5] = vld1q_s16(src_t + 5 * stride); - s[6] = vld1q_s16(src_t + 6 * stride); - s[7] = vld1q_s16(src_t + 7 * stride); - s0 = vmlal_s16(s0, vget_low_s16(s[0]), vget_low_s16(s[0])); - s0 = vmlal_s16(s0, vget_low_s16(s[1]), vget_low_s16(s[1])); - s0 = vmlal_s16(s0, vget_low_s16(s[2]), vget_low_s16(s[2])); - s0 = vmlal_s16(s0, vget_low_s16(s[3]), vget_low_s16(s[3])); - s0 = vmlal_s16(s0, vget_low_s16(s[4]), vget_low_s16(s[4])); - s0 = vmlal_s16(s0, vget_low_s16(s[5]), vget_low_s16(s[5])); - s0 = vmlal_s16(s0, vget_low_s16(s[6]), vget_low_s16(s[6])); - s0 = vmlal_s16(s0, vget_low_s16(s[7]), vget_low_s16(s[7])); - s0 = vmlal_s16(s0, vget_high_s16(s[0]), vget_high_s16(s[0])); - s0 = vmlal_s16(s0, vget_high_s16(s[1]), vget_high_s16(s[1])); - s0 = vmlal_s16(s0, vget_high_s16(s[2]), vget_high_s16(s[2])); - s0 = vmlal_s16(s0, vget_high_s16(s[3]), vget_high_s16(s[3])); - s0 = vmlal_s16(s0, vget_high_s16(s[4]), vget_high_s16(s[4])); - s0 = vmlal_s16(s0, vget_high_s16(s[5]), vget_high_s16(s[5])); - s0 = vmlal_s16(s0, vget_high_s16(s[6]), vget_high_s16(s[6])); - s0 = vmlal_s16(s0, vget_high_s16(s[7]), vget_high_s16(s[7])); - src_t += 8; - c -= 8; - } while (c); + s[0] = vld1q_s16(src_ptr + 0 * stride); + s[1] = vld1q_s16(src_ptr + 1 * stride); + s[2] = vld1q_s16(src_ptr + 2 * stride); + s[3] = vld1q_s16(src_ptr + 3 * stride); + s[4] = vld1q_s16(src_ptr + 4 * stride); + s[5] = vld1q_s16(src_ptr + 5 * stride); + s[6] = vld1q_s16(src_ptr + 6 * stride); + s[7] = vld1q_s16(src_ptr + 7 * stride); - s1 = vaddw_u32(s1, vget_low_u32(vreinterpretq_u32_s32(s0))); - s1 = vaddw_u32(s1, vget_high_u32(vreinterpretq_u32_s32(s0))); +#if VPX_ARCH_AARCH64 + // Group each accumulator chain, low halves before high halves. + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[0]), vget_low_s16(s[0])); + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[2]), vget_low_s16(s[2])); + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[4]), vget_low_s16(s[4])); + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[6]), vget_low_s16(s[6])); + + sum_s32[2] = + vmlal_s16(sum_s32[2], vget_low_s16(s[1]), vget_low_s16(s[1])); + sum_s32[2] = + vmlal_s16(sum_s32[2], vget_low_s16(s[3]), vget_low_s16(s[3])); + sum_s32[2] = + vmlal_s16(sum_s32[2], vget_low_s16(s[5]), vget_low_s16(s[5])); + sum_s32[2] = + vmlal_s16(sum_s32[2], vget_low_s16(s[7]), vget_low_s16(s[7])); + + sum_s32[1] = vmlal_high_s16(sum_s32[1], s[0], s[0]); + sum_s32[1] = vmlal_high_s16(sum_s32[1], s[2], s[2]); + sum_s32[1] = vmlal_high_s16(sum_s32[1], s[4], s[4]); + sum_s32[1] = vmlal_high_s16(sum_s32[1], s[6], s[6]); + + sum_s32[3] = vmlal_high_s16(sum_s32[3], s[1], s[1]); + sum_s32[3] = vmlal_high_s16(sum_s32[3], s[3], s[3]); + sum_s32[3] = vmlal_high_s16(sum_s32[3], s[5], s[5]); + sum_s32[3] = vmlal_high_s16(sum_s32[3], s[7], s[7]); +#else + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[0]), vget_low_s16(s[0])); + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[1]), vget_low_s16(s[1])); + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[2]), vget_low_s16(s[2])); + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[3]), vget_low_s16(s[3])); + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[4]), vget_low_s16(s[4])); + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[5]), vget_low_s16(s[5])); + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[6]), vget_low_s16(s[6])); + sum_s32[0] = + vmlal_s16(sum_s32[0], vget_low_s16(s[7]), vget_low_s16(s[7])); + + sum_s32[1] = + vmlal_s16(sum_s32[1], vget_high_s16(s[0]), vget_high_s16(s[0])); + sum_s32[1] = + vmlal_s16(sum_s32[1], vget_high_s16(s[1]), vget_high_s16(s[1])); + sum_s32[1] = + vmlal_s16(sum_s32[1], vget_high_s16(s[2]), vget_high_s16(s[2])); + sum_s32[1] = + vmlal_s16(sum_s32[1], vget_high_s16(s[3]), vget_high_s16(s[3])); + sum_s32[1] = + vmlal_s16(sum_s32[1], vget_high_s16(s[4]), vget_high_s16(s[4])); + sum_s32[1] = + vmlal_s16(sum_s32[1], vget_high_s16(s[5]), vget_high_s16(s[5])); + sum_s32[1] = + vmlal_s16(sum_s32[1], vget_high_s16(s[6]), vget_high_s16(s[6])); + sum_s32[1] = + vmlal_s16(sum_s32[1], vget_high_s16(s[7]), vget_high_s16(s[7])); +#endif + + src_ptr += 8; + cols -= 8; + } while (cols); + +#if VPX_ARCH_AARCH64 + sum_s32[0] = vaddq_s32(sum_s32[0], sum_s32[2]); + sum_s32[1] = vaddq_s32(sum_s32[1], sum_s32[3]); +#endif + sum_u64 = vpadalq_u32(sum_u64, vreinterpretq_u32_s32(sum_s32[0])); + sum_u64 = vpadalq_u32(sum_u64, vreinterpretq_u32_s32(sum_s32[1])); src += 8 * stride; - r -= 8; - } while (r); + rows -= 8; + } while (rows); - s2 = vadd_u64(vget_low_u64(s1), vget_high_u64(s1)); + return horizontal_add_uint64x2(sum_u64); } - - return vget_lane_u64(s2, 0); } diff --git a/libs/libvpx/vpx_dsp/arm/sum_squares_sve.c b/libs/libvpx/vpx_dsp/arm/sum_squares_sve.c new file mode 100644 index 0000000000..a18cbbd736 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/sum_squares_sve.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_dsp_rtcd.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" +#include "vpx_dsp/arm/vpx_neon_sve_bridge.h" + +uint64_t vpx_sum_squares_2d_i16_sve(const int16_t *src, int stride, int size) { + if (size == 4) { + int16x4_t s[4]; + int64x2_t sum = vdupq_n_s64(0); + + s[0] = vld1_s16(src + 0 * stride); + s[1] = vld1_s16(src + 1 * stride); + s[2] = vld1_s16(src + 2 * stride); + s[3] = vld1_s16(src + 3 * stride); + + int16x8_t s01 = vcombine_s16(s[0], s[1]); + int16x8_t s23 = vcombine_s16(s[2], s[3]); + + sum = vpx_dotq_s16(sum, s01, s01); + sum = vpx_dotq_s16(sum, s23, s23); + + return horizontal_add_uint64x2(vreinterpretq_u64_s64(sum)); + } else { + int rows = size; + int64x2_t sum[4] = { vdupq_n_s64(0), vdupq_n_s64(0), vdupq_n_s64(0), + vdupq_n_s64(0) }; + + do { + const int16_t *src_ptr = src; + int cols = size; + + do { + int16x8_t s[8]; + load_s16_8x8(src_ptr, stride, &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], + &s[6], &s[7]); + + sum[0] = vpx_dotq_s16(sum[0], s[0], s[0]); + sum[1] = vpx_dotq_s16(sum[1], s[1], s[1]); + sum[2] = vpx_dotq_s16(sum[2], s[2], s[2]); + sum[3] = vpx_dotq_s16(sum[3], s[3], s[3]); + sum[0] = vpx_dotq_s16(sum[0], s[4], s[4]); + sum[1] = vpx_dotq_s16(sum[1], s[5], s[5]); + sum[2] = vpx_dotq_s16(sum[2], s[6], s[6]); + sum[3] = vpx_dotq_s16(sum[3], s[7], s[7]); + + src_ptr += 8; + cols -= 8; + } while (cols); + + src += 8 * stride; + rows -= 8; + } while (rows); + + sum[0] = vaddq_s64(sum[0], sum[1]); + sum[2] = vaddq_s64(sum[2], sum[3]); + sum[0] = vaddq_s64(sum[0], sum[2]); + + return horizontal_add_uint64x2(vreinterpretq_u64_s64(sum[0])); + } +} diff --git a/libs/libvpx/vpx_dsp/arm/transpose_neon.h b/libs/libvpx/vpx_dsp/arm/transpose_neon.h index c098ad31b6..b6b46fc47e 100644 --- a/libs/libvpx/vpx_dsp/arm/transpose_neon.h +++ b/libs/libvpx/vpx_dsp/arm/transpose_neon.h @@ -23,44 +23,77 @@ // b0.val[1]: 04 05 06 07 20 21 22 23 static INLINE int16x8x2_t vpx_vtrnq_s64_to_s16(int32x4_t a0, int32x4_t a1) { int16x8x2_t b0; +#if VPX_ARCH_AARCH64 + b0.val[0] = vreinterpretq_s16_s64( + vtrn1q_s64(vreinterpretq_s64_s32(a0), vreinterpretq_s64_s32(a1))); + b0.val[1] = vreinterpretq_s16_s64( + vtrn2q_s64(vreinterpretq_s64_s32(a0), vreinterpretq_s64_s32(a1))); +#else b0.val[0] = vcombine_s16(vreinterpret_s16_s32(vget_low_s32(a0)), vreinterpret_s16_s32(vget_low_s32(a1))); b0.val[1] = vcombine_s16(vreinterpret_s16_s32(vget_high_s32(a0)), vreinterpret_s16_s32(vget_high_s32(a1))); +#endif return b0; } static INLINE int32x4x2_t vpx_vtrnq_s64_to_s32(int32x4_t a0, int32x4_t a1) { int32x4x2_t b0; +#if VPX_ARCH_AARCH64 + b0.val[0] = vreinterpretq_s32_s64( + vtrn1q_s64(vreinterpretq_s64_s32(a0), vreinterpretq_s64_s32(a1))); + b0.val[1] = vreinterpretq_s32_s64( + vtrn2q_s64(vreinterpretq_s64_s32(a0), vreinterpretq_s64_s32(a1))); +#else b0.val[0] = vcombine_s32(vget_low_s32(a0), vget_low_s32(a1)); b0.val[1] = vcombine_s32(vget_high_s32(a0), vget_high_s32(a1)); +#endif return b0; } static INLINE int64x2x2_t vpx_vtrnq_s64(int32x4_t a0, int32x4_t a1) { int64x2x2_t b0; +#if VPX_ARCH_AARCH64 + b0.val[0] = vtrn1q_s64(vreinterpretq_s64_s32(a0), vreinterpretq_s64_s32(a1)); + b0.val[1] = vtrn2q_s64(vreinterpretq_s64_s32(a0), vreinterpretq_s64_s32(a1)); +#else b0.val[0] = vcombine_s64(vreinterpret_s64_s32(vget_low_s32(a0)), vreinterpret_s64_s32(vget_low_s32(a1))); b0.val[1] = vcombine_s64(vreinterpret_s64_s32(vget_high_s32(a0)), vreinterpret_s64_s32(vget_high_s32(a1))); +#endif return b0; } static INLINE uint8x16x2_t vpx_vtrnq_u64_to_u8(uint32x4_t a0, uint32x4_t a1) { uint8x16x2_t b0; +#if VPX_ARCH_AARCH64 + b0.val[0] = vreinterpretq_u8_u64( + vtrn1q_u64(vreinterpretq_u64_u32(a0), vreinterpretq_u64_u32(a1))); + b0.val[1] = vreinterpretq_u8_u64( + vtrn2q_u64(vreinterpretq_u64_u32(a0), vreinterpretq_u64_u32(a1))); +#else b0.val[0] = vcombine_u8(vreinterpret_u8_u32(vget_low_u32(a0)), vreinterpret_u8_u32(vget_low_u32(a1))); b0.val[1] = vcombine_u8(vreinterpret_u8_u32(vget_high_u32(a0)), vreinterpret_u8_u32(vget_high_u32(a1))); +#endif return b0; } static INLINE uint16x8x2_t vpx_vtrnq_u64_to_u16(uint32x4_t a0, uint32x4_t a1) { uint16x8x2_t b0; +#if VPX_ARCH_AARCH64 + b0.val[0] = vreinterpretq_u16_u64( + vtrn1q_u64(vreinterpretq_u64_u32(a0), vreinterpretq_u64_u32(a1))); + b0.val[1] = vreinterpretq_u16_u64( + vtrn2q_u64(vreinterpretq_u64_u32(a0), vreinterpretq_u64_u32(a1))); +#else b0.val[0] = vcombine_u16(vreinterpret_u16_u32(vget_low_u32(a0)), vreinterpret_u16_u32(vget_low_u32(a1))); b0.val[1] = vcombine_u16(vreinterpret_u16_u32(vget_high_u32(a0)), vreinterpret_u16_u32(vget_high_u32(a1))); +#endif return b0; } @@ -141,17 +174,13 @@ static INLINE void transpose_s16_4x4q(int16x8_t *a0, int16x8_t *a1) { // c0: 00 01 20 21 02 03 22 23 // c1: 10 11 30 31 12 13 32 33 - const int32x4_t c0 = - vcombine_s32(vget_low_s32(b0.val[0]), vget_low_s32(b0.val[1])); - const int32x4_t c1 = - vcombine_s32(vget_high_s32(b0.val[0]), vget_high_s32(b0.val[1])); + const int16x8x2_t c0 = vpx_vtrnq_s64_to_s16(b0.val[0], b0.val[1]); // Swap 16 bit elements resulting in: // d0.val[0]: 00 10 20 30 02 12 22 32 // d0.val[1]: 01 11 21 31 03 13 23 33 - const int16x8x2_t d0 = - vtrnq_s16(vreinterpretq_s16_s32(c0), vreinterpretq_s16_s32(c1)); + const int16x8x2_t d0 = vtrnq_s16(c0.val[0], c0.val[1]); *a0 = d0.val[0]; *a1 = d0.val[1]; @@ -172,17 +201,13 @@ static INLINE void transpose_u16_4x4q(uint16x8_t *a0, uint16x8_t *a1) { // c0: 00 01 20 21 02 03 22 23 // c1: 10 11 30 31 12 13 32 33 - const uint32x4_t c0 = - vcombine_u32(vget_low_u32(b0.val[0]), vget_low_u32(b0.val[1])); - const uint32x4_t c1 = - vcombine_u32(vget_high_u32(b0.val[0]), vget_high_u32(b0.val[1])); + const uint16x8x2_t c0 = vpx_vtrnq_u64_to_u16(b0.val[0], b0.val[1]); // Swap 16 bit elements resulting in: // d0.val[0]: 00 10 20 30 02 12 22 32 // d0.val[1]: 01 11 21 31 03 13 23 33 - const uint16x8x2_t d0 = - vtrnq_u16(vreinterpretq_u16_u32(c0), vreinterpretq_u16_u32(c1)); + const uint16x8x2_t d0 = vtrnq_u16(c0.val[0], c0.val[1]); *a0 = d0.val[0]; *a1 = d0.val[1]; @@ -281,7 +306,7 @@ static INLINE void transpose_s16_4x8(const int16x4_t a0, const int16x4_t a1, const int16x4_t a6, const int16x4_t a7, int16x8_t *const o0, int16x8_t *const o1, int16x8_t *const o2, int16x8_t *const o3) { - // Swap 16 bit elements. Goes from: + // Combine rows. Goes from: // a0: 00 01 02 03 // a1: 10 11 12 13 // a2: 20 21 22 23 @@ -291,53 +316,40 @@ static INLINE void transpose_s16_4x8(const int16x4_t a0, const int16x4_t a1, // a6: 60 61 62 63 // a7: 70 71 72 73 // to: - // b0.val[0]: 00 10 02 12 - // b0.val[1]: 01 11 03 13 - // b1.val[0]: 20 30 22 32 - // b1.val[1]: 21 31 23 33 - // b2.val[0]: 40 50 42 52 - // b2.val[1]: 41 51 43 53 - // b3.val[0]: 60 70 62 72 - // b3.val[1]: 61 71 63 73 + // b0: 00 01 02 03 40 41 42 43 + // b1: 10 11 12 13 50 51 52 53 + // b2: 20 21 22 23 60 61 62 63 + // b3: 30 31 32 33 70 71 72 73 - const int16x4x2_t b0 = vtrn_s16(a0, a1); - const int16x4x2_t b1 = vtrn_s16(a2, a3); - const int16x4x2_t b2 = vtrn_s16(a4, a5); - const int16x4x2_t b3 = vtrn_s16(a6, a7); + const int16x8_t b0 = vcombine_s16(a0, a4); + const int16x8_t b1 = vcombine_s16(a1, a5); + const int16x8_t b2 = vcombine_s16(a2, a6); + const int16x8_t b3 = vcombine_s16(a3, a7); + + // Swap 16 bit elements resulting in: + // c0.val[0]: 00 10 02 12 40 50 42 52 + // c0.val[1]: 01 11 03 13 41 51 43 53 + // c1.val[0]: 20 30 22 32 60 70 62 72 + // c1.val[1]: 21 31 23 33 61 71 63 73 + + const int16x8x2_t c0 = vtrnq_s16(b0, b1); + const int16x8x2_t c1 = vtrnq_s16(b2, b3); // Swap 32 bit elements resulting in: - // c0.val[0]: 00 10 20 30 - // c0.val[1]: 02 12 22 32 - // c1.val[0]: 01 11 21 31 - // c1.val[1]: 03 13 23 33 - // c2.val[0]: 40 50 60 70 - // c2.val[1]: 42 52 62 72 - // c3.val[0]: 41 51 61 71 - // c3.val[1]: 43 53 63 73 + // d0.val[0]: 00 10 20 30 40 50 60 70 + // d0.val[1]: 02 12 22 32 42 52 62 72 + // d1.val[0]: 01 11 21 31 41 51 61 71 + // d1.val[1]: 03 13 23 33 43 53 63 73 - const int32x2x2_t c0 = vtrn_s32(vreinterpret_s32_s16(b0.val[0]), - vreinterpret_s32_s16(b1.val[0])); - const int32x2x2_t c1 = vtrn_s32(vreinterpret_s32_s16(b0.val[1]), - vreinterpret_s32_s16(b1.val[1])); - const int32x2x2_t c2 = vtrn_s32(vreinterpret_s32_s16(b2.val[0]), - vreinterpret_s32_s16(b3.val[0])); - const int32x2x2_t c3 = vtrn_s32(vreinterpret_s32_s16(b2.val[1]), - vreinterpret_s32_s16(b3.val[1])); + const int32x4x2_t d0 = vtrnq_s32(vreinterpretq_s32_s16(c0.val[0]), + vreinterpretq_s32_s16(c1.val[0])); + const int32x4x2_t d1 = vtrnq_s32(vreinterpretq_s32_s16(c0.val[1]), + vreinterpretq_s32_s16(c1.val[1])); - // Swap 64 bit elements resulting in: - // o0: 00 10 20 30 40 50 60 70 - // o1: 01 11 21 31 41 51 61 71 - // o2: 02 12 22 32 42 52 62 72 - // o3: 03 13 23 33 43 53 63 73 - - *o0 = vcombine_s16(vreinterpret_s16_s32(c0.val[0]), - vreinterpret_s16_s32(c2.val[0])); - *o1 = vcombine_s16(vreinterpret_s16_s32(c1.val[0]), - vreinterpret_s16_s32(c3.val[0])); - *o2 = vcombine_s16(vreinterpret_s16_s32(c0.val[1]), - vreinterpret_s16_s32(c2.val[1])); - *o3 = vcombine_s16(vreinterpret_s16_s32(c1.val[1]), - vreinterpret_s16_s32(c3.val[1])); + *o0 = vreinterpretq_s16_s32(d0.val[0]); + *o1 = vreinterpretq_s16_s32(d1.val[0]); + *o2 = vreinterpretq_s16_s32(d0.val[1]); + *o3 = vreinterpretq_s16_s32(d1.val[1]); } static INLINE void transpose_s32_4x8(int32x4_t *const a0, int32x4_t *const a1, @@ -512,12 +524,20 @@ static INLINE void transpose_s32_8x4(int32x4_t *const a0, int32x4_t *const a1, *a7 = vreinterpretq_s32_s64(c3.val[1]); } -// Note: Using 'd' registers or 'q' registers has almost identical speed. We use -// 'q' registers here to save some instructions. static INLINE void transpose_u8_8x8(uint8x8_t *a0, uint8x8_t *a1, uint8x8_t *a2, uint8x8_t *a3, uint8x8_t *a4, uint8x8_t *a5, uint8x8_t *a6, uint8x8_t *a7) { - // Swap 8 bit elements. Goes from: + // Widen to 128-bit registers (usually a no-op once inlined.) + const uint8x16_t a0q = vcombine_u8(*a0, vdup_n_u8(0)); + const uint8x16_t a1q = vcombine_u8(*a1, vdup_n_u8(0)); + const uint8x16_t a2q = vcombine_u8(*a2, vdup_n_u8(0)); + const uint8x16_t a3q = vcombine_u8(*a3, vdup_n_u8(0)); + const uint8x16_t a4q = vcombine_u8(*a4, vdup_n_u8(0)); + const uint8x16_t a5q = vcombine_u8(*a5, vdup_n_u8(0)); + const uint8x16_t a6q = vcombine_u8(*a6, vdup_n_u8(0)); + const uint8x16_t a7q = vcombine_u8(*a7, vdup_n_u8(0)); + + // Zip 8 bit elements. Goes from: // a0: 00 01 02 03 04 05 06 07 // a1: 10 11 12 13 14 15 16 17 // a2: 20 21 22 23 24 25 26 27 @@ -527,47 +547,115 @@ static INLINE void transpose_u8_8x8(uint8x8_t *a0, uint8x8_t *a1, uint8x8_t *a2, // a6: 60 61 62 63 64 65 66 67 // a7: 70 71 72 73 74 75 76 77 // to: - // b0.val[0]: 00 10 02 12 04 14 06 16 40 50 42 52 44 54 46 56 - // b0.val[1]: 01 11 03 13 05 15 07 17 41 51 43 53 45 55 47 57 - // b1.val[0]: 20 30 22 32 24 34 26 36 60 70 62 72 64 74 66 76 - // b1.val[1]: 21 31 23 33 25 35 27 37 61 71 63 73 65 75 67 77 + // b0: 00 10 01 11 02 12 03 13 04 14 05 15 06 16 07 17 + // b1: 20 30 21 31 22 32 23 33 24 34 25 35 26 36 27 37 + // b2: 40 50 41 51 42 52 43 53 44 54 45 55 46 56 47 57 + // b3: 60 70 61 71 62 72 63 73 64 74 65 75 66 76 67 77 + const uint8x16_t b0 = vzipq_u8(a0q, a1q).val[0]; + const uint8x16_t b1 = vzipq_u8(a2q, a3q).val[0]; + const uint8x16_t b2 = vzipq_u8(a4q, a5q).val[0]; + const uint8x16_t b3 = vzipq_u8(a6q, a7q).val[0]; - const uint8x16x2_t b0 = - vtrnq_u8(vcombine_u8(*a0, *a4), vcombine_u8(*a1, *a5)); - const uint8x16x2_t b1 = - vtrnq_u8(vcombine_u8(*a2, *a6), vcombine_u8(*a3, *a7)); + // Zip 16 bit elements resulting in: + // c0.val[0]: 00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33 + // c0.val[1]: 04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37 + // c1.val[0]: 40 50 60 70 41 51 61 71 42 52 62 72 43 53 63 73 + // c1.val[1]: 44 54 64 74 45 55 65 75 46 66 56 76 47 67 57 77 + const uint16x8x2_t c0 = + vzipq_u16(vreinterpretq_u16_u8(b0), vreinterpretq_u16_u8(b1)); + const uint16x8x2_t c1 = + vzipq_u16(vreinterpretq_u16_u8(b2), vreinterpretq_u16_u8(b3)); - // Swap 16 bit elements resulting in: - // c0.val[0]: 00 10 20 30 04 14 24 34 40 50 60 70 44 54 64 74 - // c0.val[1]: 02 12 22 32 06 16 26 36 42 52 62 72 46 56 66 76 - // c1.val[0]: 01 11 21 31 05 15 25 35 41 51 61 71 45 55 65 75 - // c1.val[1]: 03 13 23 33 07 17 27 37 43 53 63 73 47 57 67 77 - - const uint16x8x2_t c0 = vtrnq_u16(vreinterpretq_u16_u8(b0.val[0]), - vreinterpretq_u16_u8(b1.val[0])); - const uint16x8x2_t c1 = vtrnq_u16(vreinterpretq_u16_u8(b0.val[1]), - vreinterpretq_u16_u8(b1.val[1])); - - // Unzip 32 bit elements resulting in: + // Zip 32 bit elements resulting in: // d0.val[0]: 00 10 20 30 40 50 60 70 01 11 21 31 41 51 61 71 - // d0.val[1]: 04 14 24 34 44 54 64 74 05 15 25 35 45 55 65 75 - // d1.val[0]: 02 12 22 32 42 52 62 72 03 13 23 33 43 53 63 73 + // d0.val[1]: 02 12 22 32 42 52 62 72 03 13 23 33 43 53 63 73 + // d1.val[0]: 04 14 24 34 44 54 64 74 05 15 25 35 45 55 65 75 // d1.val[1]: 06 16 26 36 46 56 66 76 07 17 27 37 47 57 67 77 - const uint32x4x2_t d0 = vuzpq_u32(vreinterpretq_u32_u16(c0.val[0]), + const uint32x4x2_t d0 = vzipq_u32(vreinterpretq_u32_u16(c0.val[0]), vreinterpretq_u32_u16(c1.val[0])); - const uint32x4x2_t d1 = vuzpq_u32(vreinterpretq_u32_u16(c0.val[1]), + const uint32x4x2_t d1 = vzipq_u32(vreinterpretq_u32_u16(c0.val[1]), vreinterpretq_u32_u16(c1.val[1])); *a0 = vreinterpret_u8_u32(vget_low_u32(d0.val[0])); *a1 = vreinterpret_u8_u32(vget_high_u32(d0.val[0])); - *a2 = vreinterpret_u8_u32(vget_low_u32(d1.val[0])); - *a3 = vreinterpret_u8_u32(vget_high_u32(d1.val[0])); - *a4 = vreinterpret_u8_u32(vget_low_u32(d0.val[1])); - *a5 = vreinterpret_u8_u32(vget_high_u32(d0.val[1])); + *a2 = vreinterpret_u8_u32(vget_low_u32(d0.val[1])); + *a3 = vreinterpret_u8_u32(vget_high_u32(d0.val[1])); + *a4 = vreinterpret_u8_u32(vget_low_u32(d1.val[0])); + *a5 = vreinterpret_u8_u32(vget_high_u32(d1.val[0])); *a6 = vreinterpret_u8_u32(vget_low_u32(d1.val[1])); *a7 = vreinterpret_u8_u32(vget_high_u32(d1.val[1])); } +// Transpose 8x8 to a new location. +static INLINE void transpose_s16_8x8q(int16x8_t *a, int16x8_t *out) { + // Swap 16 bit elements. Goes from: + // a0: 00 01 02 03 04 05 06 07 + // a1: 10 11 12 13 14 15 16 17 + // a2: 20 21 22 23 24 25 26 27 + // a3: 30 31 32 33 34 35 36 37 + // a4: 40 41 42 43 44 45 46 47 + // a5: 50 51 52 53 54 55 56 57 + // a6: 60 61 62 63 64 65 66 67 + // a7: 70 71 72 73 74 75 76 77 + // to: + // b0.val[0]: 00 10 02 12 04 14 06 16 + // b0.val[1]: 01 11 03 13 05 15 07 17 + // b1.val[0]: 20 30 22 32 24 34 26 36 + // b1.val[1]: 21 31 23 33 25 35 27 37 + // b2.val[0]: 40 50 42 52 44 54 46 56 + // b2.val[1]: 41 51 43 53 45 55 47 57 + // b3.val[0]: 60 70 62 72 64 74 66 76 + // b3.val[1]: 61 71 63 73 65 75 67 77 + + const int16x8x2_t b0 = vtrnq_s16(a[0], a[1]); + const int16x8x2_t b1 = vtrnq_s16(a[2], a[3]); + const int16x8x2_t b2 = vtrnq_s16(a[4], a[5]); + const int16x8x2_t b3 = vtrnq_s16(a[6], a[7]); + + // Swap 32 bit elements resulting in: + // c0.val[0]: 00 10 20 30 04 14 24 34 + // c0.val[1]: 02 12 22 32 06 16 26 36 + // c1.val[0]: 01 11 21 31 05 15 25 35 + // c1.val[1]: 03 13 23 33 07 17 27 37 + // c2.val[0]: 40 50 60 70 44 54 64 74 + // c2.val[1]: 42 52 62 72 46 56 66 76 + // c3.val[0]: 41 51 61 71 45 55 65 75 + // c3.val[1]: 43 53 63 73 47 57 67 77 + + const int32x4x2_t c0 = vtrnq_s32(vreinterpretq_s32_s16(b0.val[0]), + vreinterpretq_s32_s16(b1.val[0])); + const int32x4x2_t c1 = vtrnq_s32(vreinterpretq_s32_s16(b0.val[1]), + vreinterpretq_s32_s16(b1.val[1])); + const int32x4x2_t c2 = vtrnq_s32(vreinterpretq_s32_s16(b2.val[0]), + vreinterpretq_s32_s16(b3.val[0])); + const int32x4x2_t c3 = vtrnq_s32(vreinterpretq_s32_s16(b2.val[1]), + vreinterpretq_s32_s16(b3.val[1])); + + // Swap 64 bit elements resulting in: + // d0.val[0]: 00 10 20 30 40 50 60 70 + // d0.val[1]: 04 14 24 34 44 54 64 74 + // d1.val[0]: 01 11 21 31 41 51 61 71 + // d1.val[1]: 05 15 25 35 45 55 65 75 + // d2.val[0]: 02 12 22 32 42 52 62 72 + // d2.val[1]: 06 16 26 36 46 56 66 76 + // d3.val[0]: 03 13 23 33 43 53 63 73 + // d3.val[1]: 07 17 27 37 47 57 67 77 + + const int16x8x2_t d0 = vpx_vtrnq_s64_to_s16(c0.val[0], c2.val[0]); + const int16x8x2_t d1 = vpx_vtrnq_s64_to_s16(c1.val[0], c3.val[0]); + const int16x8x2_t d2 = vpx_vtrnq_s64_to_s16(c0.val[1], c2.val[1]); + const int16x8x2_t d3 = vpx_vtrnq_s64_to_s16(c1.val[1], c3.val[1]); + + out[0] = d0.val[0]; + out[1] = d1.val[0]; + out[2] = d2.val[0]; + out[3] = d3.val[0]; + out[4] = d0.val[1]; + out[5] = d1.val[1]; + out[6] = d2.val[1]; + out[7] = d3.val[1]; +} + static INLINE void transpose_s16_8x8(int16x8_t *a0, int16x8_t *a1, int16x8_t *a2, int16x8_t *a3, int16x8_t *a4, int16x8_t *a5, @@ -624,6 +712,7 @@ static INLINE void transpose_s16_8x8(int16x8_t *a0, int16x8_t *a1, // d2.val[1]: 06 16 26 36 46 56 66 76 // d3.val[0]: 03 13 23 33 43 53 63 73 // d3.val[1]: 07 17 27 37 47 57 67 77 + const int16x8x2_t d0 = vpx_vtrnq_s64_to_s16(c0.val[0], c2.val[0]); const int16x8x2_t d1 = vpx_vtrnq_s64_to_s16(c1.val[0], c3.val[0]); const int16x8x2_t d2 = vpx_vtrnq_s64_to_s16(c0.val[1], c2.val[1]); @@ -695,6 +784,7 @@ static INLINE void transpose_u16_8x8(uint16x8_t *a0, uint16x8_t *a1, // d2.val[1]: 06 16 26 36 46 56 66 76 // d3.val[0]: 03 13 23 33 43 53 63 73 // d3.val[1]: 07 17 27 37 47 57 67 77 + const uint16x8x2_t d0 = vpx_vtrnq_u64_to_u16(c0.val[0], c2.val[0]); const uint16x8x2_t d1 = vpx_vtrnq_u64_to_u16(c1.val[0], c3.val[0]); const uint16x8x2_t d2 = vpx_vtrnq_u64_to_u16(c0.val[1], c2.val[1]); @@ -787,6 +877,113 @@ static INLINE void transpose_s32_8x8(int32x4x2_t *a0, int32x4x2_t *a1, a7->val[1] = c7.val[1]; } +// Helper transpose function for highbd FDCT variants +static INLINE void transpose_s32_8x8_2(int32x4_t *left /*[8]*/, + int32x4_t *right /*[8]*/, + int32x4_t *out_left /*[8]*/, + int32x4_t *out_right /*[8]*/) { + int32x4x2_t out[8]; + + out[0].val[0] = left[0]; + out[0].val[1] = right[0]; + out[1].val[0] = left[1]; + out[1].val[1] = right[1]; + out[2].val[0] = left[2]; + out[2].val[1] = right[2]; + out[3].val[0] = left[3]; + out[3].val[1] = right[3]; + out[4].val[0] = left[4]; + out[4].val[1] = right[4]; + out[5].val[0] = left[5]; + out[5].val[1] = right[5]; + out[6].val[0] = left[6]; + out[6].val[1] = right[6]; + out[7].val[0] = left[7]; + out[7].val[1] = right[7]; + + transpose_s32_8x8(&out[0], &out[1], &out[2], &out[3], &out[4], &out[5], + &out[6], &out[7]); + + out_left[0] = out[0].val[0]; + out_left[1] = out[1].val[0]; + out_left[2] = out[2].val[0]; + out_left[3] = out[3].val[0]; + out_left[4] = out[4].val[0]; + out_left[5] = out[5].val[0]; + out_left[6] = out[6].val[0]; + out_left[7] = out[7].val[0]; + out_right[0] = out[0].val[1]; + out_right[1] = out[1].val[1]; + out_right[2] = out[2].val[1]; + out_right[3] = out[3].val[1]; + out_right[4] = out[4].val[1]; + out_right[5] = out[5].val[1]; + out_right[6] = out[6].val[1]; + out_right[7] = out[7].val[1]; +} + +static INLINE void transpose_s32_16x16(int32x4_t *left1, int32x4_t *right1, + int32x4_t *left2, int32x4_t *right2) { + int32x4_t tl[16], tr[16]; + + // transpose the 4 8x8 quadrants separately but first swap quadrants 2 and 3. + tl[0] = left1[8]; + tl[1] = left1[9]; + tl[2] = left1[10]; + tl[3] = left1[11]; + tl[4] = left1[12]; + tl[5] = left1[13]; + tl[6] = left1[14]; + tl[7] = left1[15]; + tr[0] = right1[8]; + tr[1] = right1[9]; + tr[2] = right1[10]; + tr[3] = right1[11]; + tr[4] = right1[12]; + tr[5] = right1[13]; + tr[6] = right1[14]; + tr[7] = right1[15]; + + left1[8] = left2[0]; + left1[9] = left2[1]; + left1[10] = left2[2]; + left1[11] = left2[3]; + left1[12] = left2[4]; + left1[13] = left2[5]; + left1[14] = left2[6]; + left1[15] = left2[7]; + right1[8] = right2[0]; + right1[9] = right2[1]; + right1[10] = right2[2]; + right1[11] = right2[3]; + right1[12] = right2[4]; + right1[13] = right2[5]; + right1[14] = right2[6]; + right1[15] = right2[7]; + + left2[0] = tl[0]; + left2[1] = tl[1]; + left2[2] = tl[2]; + left2[3] = tl[3]; + left2[4] = tl[4]; + left2[5] = tl[5]; + left2[6] = tl[6]; + left2[7] = tl[7]; + right2[0] = tr[0]; + right2[1] = tr[1]; + right2[2] = tr[2]; + right2[3] = tr[3]; + right2[4] = tr[4]; + right2[5] = tr[5]; + right2[6] = tr[6]; + right2[7] = tr[7]; + + transpose_s32_8x8_2(left1, right1, left1, right1); + transpose_s32_8x8_2(left2, right2, left2, right2); + transpose_s32_8x8_2(left1 + 8, right1 + 8, left1 + 8, right1 + 8); + transpose_s32_8x8_2(left2 + 8, right2 + 8, left2 + 8, right2 + 8); +} + static INLINE void transpose_u8_16x8( const uint8x16_t i0, const uint8x16_t i1, const uint8x16_t i2, const uint8x16_t i3, const uint8x16_t i4, const uint8x16_t i5, @@ -1352,4 +1549,158 @@ static INLINE void load_and_transpose_s32_8x8( transpose_s32_8x8(a0, a1, a2, a3, a4, a5, a6, a7); } + +static INLINE void transpose_concat_s16_4x4(const int16x4_t a0, + const int16x4_t a1, + const int16x4_t a2, + const int16x4_t a3, int16x8_t *b0, + int16x8_t *b1) { + // Transpose 16-bit elements: + // a0: 00, 01, 02, 03 + // a1: 10, 11, 12, 13 + // a2: 20, 21, 22, 23 + // a3: 30, 31, 32, 33 + // + // b0: 00 10 20 30 01 11 21 31 + // b1: 02 12 22 32 03 13 23 33 + + int16x8_t a0q = vcombine_s16(a0, vdup_n_s16(0)); + int16x8_t a1q = vcombine_s16(a1, vdup_n_s16(0)); + int16x8_t a2q = vcombine_s16(a2, vdup_n_s16(0)); + int16x8_t a3q = vcombine_s16(a3, vdup_n_s16(0)); + + int16x8_t a02 = vzipq_s16(a0q, a2q).val[0]; + int16x8_t a13 = vzipq_s16(a1q, a3q).val[0]; + + int16x8x2_t a0123 = vzipq_s16(a02, a13); + + *b0 = a0123.val[0]; + *b1 = a0123.val[1]; +} + +static INLINE void transpose_concat_s16_8x4(const int16x8_t a0, + const int16x8_t a1, + const int16x8_t a2, + const int16x8_t a3, int16x8_t *b0, + int16x8_t *b1, int16x8_t *b2, + int16x8_t *b3) { + // Transpose 16-bit elements: + // a0: 00, 01, 02, 03, 04, 05, 06, 07 + // a1: 10, 11, 12, 13, 14, 15, 16, 17 + // a2: 20, 21, 22, 23, 24, 25, 26, 27 + // a3: 30, 31, 32, 33, 34, 35, 36, 37 + // + // b0: 00 10 20 30 01 11 21 31 + // b1: 02 12 22 32 03 13 23 33 + // b2: 04 14 24 34 05 15 25 35 + // b3: 06 16 26 36 07 17 27 37 + + int16x8x2_t a02 = vzipq_s16(a0, a2); + int16x8x2_t a13 = vzipq_s16(a1, a3); + + int16x8x2_t a0123_lo = vzipq_s16(a02.val[0], a13.val[0]); + int16x8x2_t a0123_hi = vzipq_s16(a02.val[1], a13.val[1]); + + *b0 = a0123_lo.val[0]; + *b1 = a0123_lo.val[1]; + *b2 = a0123_hi.val[0]; + *b3 = a0123_hi.val[1]; +} + +static INLINE void transpose_concat_s8_8x4(int8x8_t a0, int8x8_t a1, + int8x8_t a2, int8x8_t a3, + int8x16_t *b0, int8x16_t *b1) { + // Transpose 8-bit elements and concatenate result rows as follows: + // a0: 00, 01, 02, 03, 04, 05, 06, 07 + // a1: 10, 11, 12, 13, 14, 15, 16, 17 + // a2: 20, 21, 22, 23, 24, 25, 26, 27 + // a3: 30, 31, 32, 33, 34, 35, 36, 37 + // + // b0: 00, 10, 20, 30, 01, 11, 21, 31, 02, 12, 22, 32, 03, 13, 23, 33 + // b1: 04, 14, 24, 34, 05, 15, 25, 35, 06, 16, 26, 36, 07, 17, 27, 37 + + int8x16_t a0q = vcombine_s8(a0, vdup_n_s8(0)); + int8x16_t a1q = vcombine_s8(a1, vdup_n_s8(0)); + int8x16_t a2q = vcombine_s8(a2, vdup_n_s8(0)); + int8x16_t a3q = vcombine_s8(a3, vdup_n_s8(0)); + + int8x16_t a02 = vzipq_s8(a0q, a2q).val[0]; + int8x16_t a13 = vzipq_s8(a1q, a3q).val[0]; + + int8x16x2_t a0123 = vzipq_s8(a02, a13); + + *b0 = a0123.val[0]; + *b1 = a0123.val[1]; +} + +static INLINE void transpose_concat_u8_8x4(uint8x8_t a0, uint8x8_t a1, + uint8x8_t a2, uint8x8_t a3, + uint8x16_t *b0, uint8x16_t *b1) { + // Transpose 8-bit elements and concatenate result rows as follows: + // a0: 00, 01, 02, 03, 04, 05, 06, 07 + // a1: 10, 11, 12, 13, 14, 15, 16, 17 + // a2: 20, 21, 22, 23, 24, 25, 26, 27 + // a3: 30, 31, 32, 33, 34, 35, 36, 37 + // + // b0: 00, 10, 20, 30, 01, 11, 21, 31, 02, 12, 22, 32, 03, 13, 23, 33 + // b1: 04, 14, 24, 34, 05, 15, 25, 35, 06, 16, 26, 36, 07, 17, 27, 37 + + uint8x16_t a0q = vcombine_u8(a0, vdup_n_u8(0)); + uint8x16_t a1q = vcombine_u8(a1, vdup_n_u8(0)); + uint8x16_t a2q = vcombine_u8(a2, vdup_n_u8(0)); + uint8x16_t a3q = vcombine_u8(a3, vdup_n_u8(0)); + + uint8x16_t a02 = vzipq_u8(a0q, a2q).val[0]; + uint8x16_t a13 = vzipq_u8(a1q, a3q).val[0]; + + uint8x16x2_t a0123 = vzipq_u8(a02, a13); + + *b0 = a0123.val[0]; + *b1 = a0123.val[1]; +} + +static INLINE void transpose_concat_s8_4x4(int8x8_t a0, int8x8_t a1, + int8x8_t a2, int8x8_t a3, + int8x16_t *b) { + // Transpose 8-bit elements and concatenate result rows as follows: + // a0: 00, 01, 02, 03, XX, XX, XX, XX + // a1: 10, 11, 12, 13, XX, XX, XX, XX + // a2: 20, 21, 22, 23, XX, XX, XX, XX + // a3: 30, 31, 32, 33, XX, XX, XX, XX + // + // b: 00, 10, 20, 30, 01, 11, 21, 31, 02, 12, 22, 32, 03, 13, 23, 33 + + int8x16_t a0q = vcombine_s8(a0, vdup_n_s8(0)); + int8x16_t a1q = vcombine_s8(a1, vdup_n_s8(0)); + int8x16_t a2q = vcombine_s8(a2, vdup_n_s8(0)); + int8x16_t a3q = vcombine_s8(a3, vdup_n_s8(0)); + + int8x16_t a02 = vzipq_s8(a0q, a2q).val[0]; + int8x16_t a13 = vzipq_s8(a1q, a3q).val[0]; + + *b = vzipq_s8(a02, a13).val[0]; +} + +static INLINE void transpose_concat_u8_4x4(uint8x8_t a0, uint8x8_t a1, + uint8x8_t a2, uint8x8_t a3, + uint8x16_t *b) { + // Transpose 8-bit elements and concatenate result rows as follows: + // a0: 00, 01, 02, 03, XX, XX, XX, XX + // a1: 10, 11, 12, 13, XX, XX, XX, XX + // a2: 20, 21, 22, 23, XX, XX, XX, XX + // a3: 30, 31, 32, 33, XX, XX, XX, XX + // + // b: 00, 10, 20, 30, 01, 11, 21, 31, 02, 12, 22, 32, 03, 13, 23, 33 + + uint8x16_t a0q = vcombine_u8(a0, vdup_n_u8(0)); + uint8x16_t a1q = vcombine_u8(a1, vdup_n_u8(0)); + uint8x16_t a2q = vcombine_u8(a2, vdup_n_u8(0)); + uint8x16_t a3q = vcombine_u8(a3, vdup_n_u8(0)); + + uint8x16_t a02 = vzipq_u8(a0q, a2q).val[0]; + uint8x16_t a13 = vzipq_u8(a1q, a3q).val[0]; + + *b = vzipq_u8(a02, a13).val[0]; +} + #endif // VPX_VPX_DSP_ARM_TRANSPOSE_NEON_H_ diff --git a/libs/libvpx/vpx_dsp/arm/variance_neon.c b/libs/libvpx/vpx_dsp/arm/variance_neon.c index 7b93f142b1..ad1e91abb4 100644 --- a/libs/libvpx/vpx_dsp/arm/variance_neon.c +++ b/libs/libvpx/vpx_dsp/arm/variance_neon.c @@ -19,503 +19,310 @@ #include "vpx_dsp/arm/sum_neon.h" #include "vpx_ports/mem.h" -#if defined(__ARM_FEATURE_DOTPROD) && (__ARM_FEATURE_DOTPROD == 1) - -// Process a block of width 4 four rows at a time. -static void variance_neon_w4x4(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, int h, - uint32_t *sse, int *sum) { - int i; - uint32x4_t sum_a = vdupq_n_u32(0); - uint32x4_t sum_b = vdupq_n_u32(0); - uint32x4_t sse_u32 = vdupq_n_u32(0); - - for (i = 0; i < h; i += 4) { - const uint8x16_t a = load_unaligned_u8q(src_ptr, src_stride); - const uint8x16_t b = load_unaligned_u8q(ref_ptr, ref_stride); - - const uint8x16_t abs_diff = vabdq_u8(a, b); - sse_u32 = vdotq_u32(sse_u32, abs_diff, abs_diff); - - sum_a = vdotq_u32(sum_a, a, vdupq_n_u8(1)); - sum_b = vdotq_u32(sum_b, b, vdupq_n_u8(1)); - - src_ptr += 4 * src_stride; - ref_ptr += 4 * ref_stride; - } - - *sum = horizontal_add_int32x4(vreinterpretq_s32_u32(vsubq_u32(sum_a, sum_b))); - *sse = horizontal_add_uint32x4(sse_u32); -} - -// Process a block of any size where the width is divisible by 16. -static void variance_neon_w16(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, int w, - int h, uint32_t *sse, int *sum) { - int i, j; - uint32x4_t sum_a = vdupq_n_u32(0); - uint32x4_t sum_b = vdupq_n_u32(0); - uint32x4_t sse_u32 = vdupq_n_u32(0); - - for (i = 0; i < h; ++i) { - for (j = 0; j < w; j += 16) { - const uint8x16_t a = vld1q_u8(src_ptr + j); - const uint8x16_t b = vld1q_u8(ref_ptr + j); - - const uint8x16_t abs_diff = vabdq_u8(a, b); - sse_u32 = vdotq_u32(sse_u32, abs_diff, abs_diff); - - sum_a = vdotq_u32(sum_a, a, vdupq_n_u8(1)); - sum_b = vdotq_u32(sum_b, b, vdupq_n_u8(1)); - } - src_ptr += src_stride; - ref_ptr += ref_stride; - } - - *sum = horizontal_add_int32x4(vreinterpretq_s32_u32(vsubq_u32(sum_a, sum_b))); - *sse = horizontal_add_uint32x4(sse_u32); -} - -// Process a block of width 8 two rows at a time. -static void variance_neon_w8x2(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, int h, - uint32_t *sse, int *sum) { - int i = 0; - uint32x2_t sum_a = vdup_n_u32(0); - uint32x2_t sum_b = vdup_n_u32(0); - uint32x2_t sse_lo_u32 = vdup_n_u32(0); - uint32x2_t sse_hi_u32 = vdup_n_u32(0); - - do { - const uint8x8_t a_0 = vld1_u8(src_ptr); - const uint8x8_t a_1 = vld1_u8(src_ptr + src_stride); - const uint8x8_t b_0 = vld1_u8(ref_ptr); - const uint8x8_t b_1 = vld1_u8(ref_ptr + ref_stride); - - const uint8x8_t abs_diff_0 = vabd_u8(a_0, b_0); - const uint8x8_t abs_diff_1 = vabd_u8(a_1, b_1); - sse_lo_u32 = vdot_u32(sse_lo_u32, abs_diff_0, abs_diff_0); - sse_hi_u32 = vdot_u32(sse_hi_u32, abs_diff_1, abs_diff_1); - - sum_a = vdot_u32(sum_a, a_0, vdup_n_u8(1)); - sum_b = vdot_u32(sum_b, b_0, vdup_n_u8(1)); - sum_a = vdot_u32(sum_a, a_1, vdup_n_u8(1)); - sum_b = vdot_u32(sum_b, b_1, vdup_n_u8(1)); - - src_ptr += src_stride + src_stride; - ref_ptr += ref_stride + ref_stride; - i += 2; - } while (i < h); - - *sum = horizontal_add_int32x2(vreinterpret_s32_u32(vsub_u32(sum_a, sum_b))); - *sse = horizontal_add_uint32x2(vadd_u32(sse_lo_u32, sse_hi_u32)); -} - -#else - -// The variance helper functions use int16_t for sum. 8 values are accumulated -// and then added (at which point they expand up to int32_t). To avoid overflow, -// there can be no more than 32767 / 255 ~= 128 values accumulated in each -// column. For a 32x32 buffer, this results in 32 / 8 = 4 values per row * 32 -// rows = 128. Asserts have been added to each function to warn against reaching -// this limit. - -// Process a block of width 4 four rows at a time. -static void variance_neon_w4x4(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, int h, - uint32_t *sse, int *sum) { - int i; +// Process a block of width 4 two rows at a time. +static INLINE void variance_4xh_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + int h, uint32_t *sse, int *sum) { int16x8_t sum_s16 = vdupq_n_s16(0); - int32x4_t sse_lo_s32 = vdupq_n_s32(0); - int32x4_t sse_hi_s32 = vdupq_n_s32(0); + int32x4_t sse_s32 = vdupq_n_s32(0); - // Since width is only 4, sum_s16 only loads a half row per loop. + // Number of rows we can process before 'sum_s16' overflows: + // 32767 / 255 ~= 128, but we use an 8-wide accumulator; so 256 4-wide rows. assert(h <= 256); - for (i = 0; i < h; i += 4) { - const uint8x16_t a_u8 = load_unaligned_u8q(src_ptr, src_stride); - const uint8x16_t b_u8 = load_unaligned_u8q(ref_ptr, ref_stride); - const uint16x8_t diff_lo_u16 = - vsubl_u8(vget_low_u8(a_u8), vget_low_u8(b_u8)); - const uint16x8_t diff_hi_u16 = - vsubl_u8(vget_high_u8(a_u8), vget_high_u8(b_u8)); + do { + const uint8x8_t s = load_unaligned_u8(src_ptr, src_stride); + const uint8x8_t r = load_unaligned_u8(ref_ptr, ref_stride); + const int16x8_t diff = vreinterpretq_s16_u16(vsubl_u8(s, r)); - const int16x8_t diff_lo_s16 = vreinterpretq_s16_u16(diff_lo_u16); - const int16x8_t diff_hi_s16 = vreinterpretq_s16_u16(diff_hi_u16); + sum_s16 = vaddq_s16(sum_s16, diff); - sum_s16 = vaddq_s16(sum_s16, diff_lo_s16); - sum_s16 = vaddq_s16(sum_s16, diff_hi_s16); + sse_s32 = vmlal_s16(sse_s32, vget_low_s16(diff), vget_low_s16(diff)); + sse_s32 = vmlal_s16(sse_s32, vget_high_s16(diff), vget_high_s16(diff)); - sse_lo_s32 = vmlal_s16(sse_lo_s32, vget_low_s16(diff_lo_s16), - vget_low_s16(diff_lo_s16)); - sse_lo_s32 = vmlal_s16(sse_lo_s32, vget_high_s16(diff_lo_s16), - vget_high_s16(diff_lo_s16)); - - sse_hi_s32 = vmlal_s16(sse_hi_s32, vget_low_s16(diff_hi_s16), - vget_low_s16(diff_hi_s16)); - sse_hi_s32 = vmlal_s16(sse_hi_s32, vget_high_s16(diff_hi_s16), - vget_high_s16(diff_hi_s16)); - - src_ptr += 4 * src_stride; - ref_ptr += 4 * ref_stride; - } + src_ptr += 2 * src_stride; + ref_ptr += 2 * ref_stride; + h -= 2; + } while (h != 0); *sum = horizontal_add_int16x8(sum_s16); - *sse = horizontal_add_uint32x4( - vreinterpretq_u32_s32(vaddq_s32(sse_lo_s32, sse_hi_s32))); + *sse = (uint32_t)horizontal_add_int32x4(sse_s32); } -// Process a block of any size where the width is divisible by 16. -static void variance_neon_w16(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, int w, - int h, uint32_t *sse, int *sum) { - int i, j; +// Process a block of width 8 one row at a time. +static INLINE void variance_8xh_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + int h, uint32_t *sse, int *sum) { int16x8_t sum_s16 = vdupq_n_s16(0); - int32x4_t sse_lo_s32 = vdupq_n_s32(0); - int32x4_t sse_hi_s32 = vdupq_n_s32(0); + int32x4_t sse_s32[2] = { vdupq_n_s32(0), vdupq_n_s32(0) }; - // The loop loads 16 values at a time but doubles them up when accumulating - // into sum_s16. - assert(w / 8 * h <= 128); - - for (i = 0; i < h; ++i) { - for (j = 0; j < w; j += 16) { - const uint8x16_t a_u8 = vld1q_u8(src_ptr + j); - const uint8x16_t b_u8 = vld1q_u8(ref_ptr + j); - - const uint16x8_t diff_lo_u16 = - vsubl_u8(vget_low_u8(a_u8), vget_low_u8(b_u8)); - const uint16x8_t diff_hi_u16 = - vsubl_u8(vget_high_u8(a_u8), vget_high_u8(b_u8)); - - const int16x8_t diff_lo_s16 = vreinterpretq_s16_u16(diff_lo_u16); - const int16x8_t diff_hi_s16 = vreinterpretq_s16_u16(diff_hi_u16); - - sum_s16 = vaddq_s16(sum_s16, diff_lo_s16); - sum_s16 = vaddq_s16(sum_s16, diff_hi_s16); - - sse_lo_s32 = vmlal_s16(sse_lo_s32, vget_low_s16(diff_lo_s16), - vget_low_s16(diff_lo_s16)); - sse_lo_s32 = vmlal_s16(sse_lo_s32, vget_high_s16(diff_lo_s16), - vget_high_s16(diff_lo_s16)); - - sse_hi_s32 = vmlal_s16(sse_hi_s32, vget_low_s16(diff_hi_s16), - vget_low_s16(diff_hi_s16)); - sse_hi_s32 = vmlal_s16(sse_hi_s32, vget_high_s16(diff_hi_s16), - vget_high_s16(diff_hi_s16)); - } - src_ptr += src_stride; - ref_ptr += ref_stride; - } - - *sum = horizontal_add_int16x8(sum_s16); - *sse = horizontal_add_uint32x4( - vreinterpretq_u32_s32(vaddq_s32(sse_lo_s32, sse_hi_s32))); -} - -// Process a block of width 8 two rows at a time. -static void variance_neon_w8x2(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, int h, - uint32_t *sse, int *sum) { - int i = 0; - int16x8_t sum_s16 = vdupq_n_s16(0); - int32x4_t sse_lo_s32 = vdupq_n_s32(0); - int32x4_t sse_hi_s32 = vdupq_n_s32(0); - - // Each column has it's own accumulator entry in sum_s16. + // Number of rows we can process before 'sum_s16' overflows: + // 32767 / 255 ~= 128 assert(h <= 128); do { - const uint8x8_t a_0_u8 = vld1_u8(src_ptr); - const uint8x8_t a_1_u8 = vld1_u8(src_ptr + src_stride); - const uint8x8_t b_0_u8 = vld1_u8(ref_ptr); - const uint8x8_t b_1_u8 = vld1_u8(ref_ptr + ref_stride); - const uint16x8_t diff_0_u16 = vsubl_u8(a_0_u8, b_0_u8); - const uint16x8_t diff_1_u16 = vsubl_u8(a_1_u8, b_1_u8); - const int16x8_t diff_0_s16 = vreinterpretq_s16_u16(diff_0_u16); - const int16x8_t diff_1_s16 = vreinterpretq_s16_u16(diff_1_u16); - sum_s16 = vaddq_s16(sum_s16, diff_0_s16); - sum_s16 = vaddq_s16(sum_s16, diff_1_s16); - sse_lo_s32 = vmlal_s16(sse_lo_s32, vget_low_s16(diff_0_s16), - vget_low_s16(diff_0_s16)); - sse_lo_s32 = vmlal_s16(sse_lo_s32, vget_low_s16(diff_1_s16), - vget_low_s16(diff_1_s16)); - sse_hi_s32 = vmlal_s16(sse_hi_s32, vget_high_s16(diff_0_s16), - vget_high_s16(diff_0_s16)); - sse_hi_s32 = vmlal_s16(sse_hi_s32, vget_high_s16(diff_1_s16), - vget_high_s16(diff_1_s16)); - src_ptr += src_stride + src_stride; - ref_ptr += ref_stride + ref_stride; - i += 2; - } while (i < h); + const uint8x8_t s = vld1_u8(src_ptr); + const uint8x8_t r = vld1_u8(ref_ptr); + const int16x8_t diff = vreinterpretq_s16_u16(vsubl_u8(s, r)); + + sum_s16 = vaddq_s16(sum_s16, diff); + + sse_s32[0] = vmlal_s16(sse_s32[0], vget_low_s16(diff), vget_low_s16(diff)); + sse_s32[1] = + vmlal_s16(sse_s32[1], vget_high_s16(diff), vget_high_s16(diff)); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--h != 0); *sum = horizontal_add_int16x8(sum_s16); - *sse = horizontal_add_uint32x4( - vreinterpretq_u32_s32(vaddq_s32(sse_lo_s32, sse_hi_s32))); + *sse = (uint32_t)horizontal_add_int32x4(vaddq_s32(sse_s32[0], sse_s32[1])); } -#endif +// Process a block of width 16 one row at a time. +static INLINE void variance_16xh_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + int h, uint32_t *sse, int *sum) { + int16x8_t sum_s16[2] = { vdupq_n_s16(0), vdupq_n_s16(0) }; + int32x4_t sse_s32[2] = { vdupq_n_s32(0), vdupq_n_s32(0) }; + + // Number of rows we can process before 'sum_s16' accumulators overflow: + // 32767 / 255 ~= 128, so 128 16-wide rows. + assert(h <= 128); + + do { + const uint8x16_t s = vld1q_u8(src_ptr); + const uint8x16_t r = vld1q_u8(ref_ptr); + + const int16x8_t diff_l = + vreinterpretq_s16_u16(vsubl_u8(vget_low_u8(s), vget_low_u8(r))); + const int16x8_t diff_h = + vreinterpretq_s16_u16(vsubl_u8(vget_high_u8(s), vget_high_u8(r))); + + sum_s16[0] = vaddq_s16(sum_s16[0], diff_l); + sum_s16[1] = vaddq_s16(sum_s16[1], diff_h); + + sse_s32[0] = + vmlal_s16(sse_s32[0], vget_low_s16(diff_l), vget_low_s16(diff_l)); + sse_s32[1] = + vmlal_s16(sse_s32[1], vget_high_s16(diff_l), vget_high_s16(diff_l)); + sse_s32[0] = + vmlal_s16(sse_s32[0], vget_low_s16(diff_h), vget_low_s16(diff_h)); + sse_s32[1] = + vmlal_s16(sse_s32[1], vget_high_s16(diff_h), vget_high_s16(diff_h)); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--h != 0); + + *sum = horizontal_add_int16x8(vaddq_s16(sum_s16[0], sum_s16[1])); + *sse = (uint32_t)horizontal_add_int32x4(vaddq_s32(sse_s32[0], sse_s32[1])); +} + +// Process a block of any size where the width is divisible by 16. +static INLINE void variance_large_neon(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + int w, int h, int h_limit, + unsigned int *sse, int *sum) { + int32x4_t sum_s32 = vdupq_n_s32(0); + int32x4_t sse_s32[2] = { vdupq_n_s32(0), vdupq_n_s32(0) }; + + // 'h_limit' is the number of 'w'-width rows we can process before our 16-bit + // accumulator overflows. After hitting this limit we accumulate into 32-bit + // elements. + int h_tmp = h > h_limit ? h_limit : h; + + int i = 0; + do { + int16x8_t sum_s16[2] = { vdupq_n_s16(0), vdupq_n_s16(0) }; + do { + int j = 0; + do { + const uint8x16_t s = vld1q_u8(src_ptr + j); + const uint8x16_t r = vld1q_u8(ref_ptr + j); + + const int16x8_t diff_l = + vreinterpretq_s16_u16(vsubl_u8(vget_low_u8(s), vget_low_u8(r))); + const int16x8_t diff_h = + vreinterpretq_s16_u16(vsubl_u8(vget_high_u8(s), vget_high_u8(r))); + + sum_s16[0] = vaddq_s16(sum_s16[0], diff_l); + sum_s16[1] = vaddq_s16(sum_s16[1], diff_h); + + sse_s32[0] = + vmlal_s16(sse_s32[0], vget_low_s16(diff_l), vget_low_s16(diff_l)); + sse_s32[1] = + vmlal_s16(sse_s32[1], vget_high_s16(diff_l), vget_high_s16(diff_l)); + sse_s32[0] = + vmlal_s16(sse_s32[0], vget_low_s16(diff_h), vget_low_s16(diff_h)); + sse_s32[1] = + vmlal_s16(sse_s32[1], vget_high_s16(diff_h), vget_high_s16(diff_h)); + + j += 16; + } while (j < w); + + src_ptr += src_stride; + ref_ptr += ref_stride; + i++; + } while (i < h_tmp); + + sum_s32 = vpadalq_s16(sum_s32, sum_s16[0]); + sum_s32 = vpadalq_s16(sum_s32, sum_s16[1]); + + h_tmp += h_limit; + } while (i < h); + + *sum = horizontal_add_int32x4(sum_s32); + *sse = (uint32_t)horizontal_add_int32x4(vaddq_s32(sse_s32[0], sse_s32[1])); +} + +static INLINE void variance_32xh_neon(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, int h, + uint32_t *sse, int *sum) { + variance_large_neon(src, src_stride, ref, ref_stride, 32, h, 64, sse, sum); +} + +static INLINE void variance_64xh_neon(const uint8_t *src, int src_stride, + const uint8_t *ref, int ref_stride, int h, + uint32_t *sse, int *sum) { + variance_large_neon(src, src_stride, ref, ref_stride, 64, h, 32, sse, sum); +} void vpx_get8x8var_neon(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse, int *sum) { - variance_neon_w8x2(src_ptr, src_stride, ref_ptr, ref_stride, 8, sse, sum); + variance_8xh_neon(src_ptr, src_stride, ref_ptr, ref_stride, 8, sse, sum); } void vpx_get16x16var_neon(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse, int *sum) { - variance_neon_w16(src_ptr, src_stride, ref_ptr, ref_stride, 16, 16, sse, sum); + variance_16xh_neon(src_ptr, src_stride, ref_ptr, ref_stride, 16, sse, sum); } -#define VARIANCENXM(n, m, shift) \ - unsigned int vpx_variance##n##x##m##_neon( \ - const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ - int ref_stride, unsigned int *sse) { \ - int sum; \ - if (n == 4) \ - variance_neon_w4x4(src_ptr, src_stride, ref_ptr, ref_stride, m, sse, \ - &sum); \ - else if (n == 8) \ - variance_neon_w8x2(src_ptr, src_stride, ref_ptr, ref_stride, m, sse, \ - &sum); \ - else \ - variance_neon_w16(src_ptr, src_stride, ref_ptr, ref_stride, n, m, sse, \ - &sum); \ - if (n * m < 16 * 16) \ - return *sse - ((sum * sum) >> shift); \ - else \ - return *sse - (uint32_t)(((int64_t)sum * sum) >> shift); \ +#define VARIANCE_WXH_NEON(w, h, shift) \ + unsigned int vpx_variance##w##x##h##_neon( \ + const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \ + unsigned int *sse) { \ + int sum; \ + variance_##w##xh_neon(src, src_stride, ref, ref_stride, h, sse, &sum); \ + return *sse - (uint32_t)(((int64_t)sum * sum) >> shift); \ } -VARIANCENXM(4, 4, 4) -VARIANCENXM(4, 8, 5) -VARIANCENXM(8, 4, 5) -VARIANCENXM(8, 8, 6) -VARIANCENXM(8, 16, 7) -VARIANCENXM(16, 8, 7) -VARIANCENXM(16, 16, 8) -VARIANCENXM(16, 32, 9) -VARIANCENXM(32, 16, 9) -VARIANCENXM(32, 32, 10) +VARIANCE_WXH_NEON(4, 4, 4) +VARIANCE_WXH_NEON(4, 8, 5) -unsigned int vpx_variance32x64_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - unsigned int *sse) { - int sum1, sum2; - uint32_t sse1, sse2; - variance_neon_w16(src_ptr, src_stride, ref_ptr, ref_stride, 32, 32, &sse1, - &sum1); - variance_neon_w16(src_ptr + (32 * src_stride), src_stride, - ref_ptr + (32 * ref_stride), ref_stride, 32, 32, &sse2, - &sum2); - *sse = sse1 + sse2; - sum1 += sum2; - return *sse - (unsigned int)(((int64_t)sum1 * sum1) >> 11); -} +VARIANCE_WXH_NEON(8, 4, 5) +VARIANCE_WXH_NEON(8, 8, 6) +VARIANCE_WXH_NEON(8, 16, 7) -unsigned int vpx_variance64x32_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - unsigned int *sse) { - int sum1, sum2; - uint32_t sse1, sse2; - variance_neon_w16(src_ptr, src_stride, ref_ptr, ref_stride, 64, 16, &sse1, - &sum1); - variance_neon_w16(src_ptr + (16 * src_stride), src_stride, - ref_ptr + (16 * ref_stride), ref_stride, 64, 16, &sse2, - &sum2); - *sse = sse1 + sse2; - sum1 += sum2; - return *sse - (unsigned int)(((int64_t)sum1 * sum1) >> 11); -} +VARIANCE_WXH_NEON(16, 8, 7) +VARIANCE_WXH_NEON(16, 16, 8) +VARIANCE_WXH_NEON(16, 32, 9) -unsigned int vpx_variance64x64_neon(const uint8_t *src_ptr, int src_stride, - const uint8_t *ref_ptr, int ref_stride, - unsigned int *sse) { - int sum1, sum2; - uint32_t sse1, sse2; +VARIANCE_WXH_NEON(32, 16, 9) +VARIANCE_WXH_NEON(32, 32, 10) +VARIANCE_WXH_NEON(32, 64, 11) - variance_neon_w16(src_ptr, src_stride, ref_ptr, ref_stride, 64, 16, &sse1, - &sum1); - variance_neon_w16(src_ptr + (16 * src_stride), src_stride, - ref_ptr + (16 * ref_stride), ref_stride, 64, 16, &sse2, - &sum2); - sse1 += sse2; - sum1 += sum2; +VARIANCE_WXH_NEON(64, 32, 11) +VARIANCE_WXH_NEON(64, 64, 12) - variance_neon_w16(src_ptr + (16 * 2 * src_stride), src_stride, - ref_ptr + (16 * 2 * ref_stride), ref_stride, 64, 16, &sse2, - &sum2); - sse1 += sse2; - sum1 += sum2; +#undef VARIANCE_WXH_NEON - variance_neon_w16(src_ptr + (16 * 3 * src_stride), src_stride, - ref_ptr + (16 * 3 * ref_stride), ref_stride, 64, 16, &sse2, - &sum2); - *sse = sse1 + sse2; - sum1 += sum2; - return *sse - (unsigned int)(((int64_t)sum1 * sum1) >> 12); -} +static INLINE unsigned int vpx_mse8xh_neon(const unsigned char *src_ptr, + int src_stride, + const unsigned char *ref_ptr, + int ref_stride, int h) { + uint32x4_t sse_u32[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; -#if defined(__ARM_FEATURE_DOTPROD) && (__ARM_FEATURE_DOTPROD == 1) + do { + uint8x8_t s0, s1, r0, r1, diff0, diff1; + uint16x8_t sse0, sse1; -unsigned int vpx_mse16x16_neon(const unsigned char *src_ptr, int src_stride, - const unsigned char *ref_ptr, int ref_stride, - unsigned int *sse) { - int i; - uint8x16_t a[2], b[2], abs_diff[2]; - uint32x4_t sse_vec[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; - - for (i = 0; i < 8; i++) { - a[0] = vld1q_u8(src_ptr); + s0 = vld1_u8(src_ptr); src_ptr += src_stride; - a[1] = vld1q_u8(src_ptr); + s1 = vld1_u8(src_ptr); src_ptr += src_stride; - b[0] = vld1q_u8(ref_ptr); + r0 = vld1_u8(ref_ptr); ref_ptr += ref_stride; - b[1] = vld1q_u8(ref_ptr); + r1 = vld1_u8(ref_ptr); ref_ptr += ref_stride; - abs_diff[0] = vabdq_u8(a[0], b[0]); - abs_diff[1] = vabdq_u8(a[1], b[1]); + diff0 = vabd_u8(s0, r0); + diff1 = vabd_u8(s1, r1); - sse_vec[0] = vdotq_u32(sse_vec[0], abs_diff[0], abs_diff[0]); - sse_vec[1] = vdotq_u32(sse_vec[1], abs_diff[1], abs_diff[1]); - } + sse0 = vmull_u8(diff0, diff0); + sse_u32[0] = vpadalq_u16(sse_u32[0], sse0); + sse1 = vmull_u8(diff1, diff1); + sse_u32[1] = vpadalq_u16(sse_u32[1], sse1); + h -= 2; + } while (h != 0); - *sse = horizontal_add_uint32x4(vaddq_u32(sse_vec[0], sse_vec[1])); - return horizontal_add_uint32x4(vaddq_u32(sse_vec[0], sse_vec[1])); + return horizontal_add_uint32x4(vaddq_u32(sse_u32[0], sse_u32[1])); +} + +static INLINE unsigned int vpx_mse16xh_neon(const unsigned char *src_ptr, + int src_stride, + const unsigned char *ref_ptr, + int ref_stride, int h) { + uint32x4_t sse_u32[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + do { + uint8x16_t s, r, diff; + uint16x8_t sse0, sse1; + + s = vld1q_u8(src_ptr); + src_ptr += src_stride; + r = vld1q_u8(ref_ptr); + ref_ptr += ref_stride; + + diff = vabdq_u8(s, r); + + sse0 = vmull_u8(vget_low_u8(diff), vget_low_u8(diff)); + sse_u32[0] = vpadalq_u16(sse_u32[0], sse0); + sse1 = vmull_u8(vget_high_u8(diff), vget_high_u8(diff)); + sse_u32[1] = vpadalq_u16(sse_u32[1], sse1); + } while (--h != 0); + + return horizontal_add_uint32x4(vaddq_u32(sse_u32[0], sse_u32[1])); } unsigned int vpx_get4x4sse_cs_neon(const unsigned char *src_ptr, int src_stride, const unsigned char *ref_ptr, int ref_stride) { - uint8x8_t a[4], b[4], abs_diff[4]; - uint32x2_t sse = vdup_n_u32(0); + uint8x8_t s[2], r[2]; + uint16x8_t abs_diff[2]; + uint32x4_t sse; - a[0] = vld1_u8(src_ptr); - src_ptr += src_stride; - b[0] = vld1_u8(ref_ptr); - ref_ptr += ref_stride; - a[1] = vld1_u8(src_ptr); - src_ptr += src_stride; - b[1] = vld1_u8(ref_ptr); - ref_ptr += ref_stride; - a[2] = vld1_u8(src_ptr); - src_ptr += src_stride; - b[2] = vld1_u8(ref_ptr); - ref_ptr += ref_stride; - a[3] = vld1_u8(src_ptr); - b[3] = vld1_u8(ref_ptr); + s[0] = load_u8(src_ptr, src_stride); + r[0] = load_u8(ref_ptr, ref_stride); + src_ptr += 2 * src_stride; + ref_ptr += 2 * ref_stride; + s[1] = load_u8(src_ptr, src_stride); + r[1] = load_u8(ref_ptr, ref_stride); - abs_diff[0] = vabd_u8(a[0], b[0]); - abs_diff[1] = vabd_u8(a[1], b[1]); - abs_diff[2] = vabd_u8(a[2], b[2]); - abs_diff[3] = vabd_u8(a[3], b[3]); + abs_diff[0] = vabdl_u8(s[0], r[0]); + abs_diff[1] = vabdl_u8(s[1], r[1]); - sse = vdot_u32(sse, abs_diff[0], abs_diff[0]); - sse = vdot_u32(sse, abs_diff[1], abs_diff[1]); - sse = vdot_u32(sse, abs_diff[2], abs_diff[2]); - sse = vdot_u32(sse, abs_diff[3], abs_diff[3]); + sse = vmull_u16(vget_low_u16(abs_diff[0]), vget_low_u16(abs_diff[0])); + sse = vmlal_u16(sse, vget_high_u16(abs_diff[0]), vget_high_u16(abs_diff[0])); + sse = vmlal_u16(sse, vget_low_u16(abs_diff[1]), vget_low_u16(abs_diff[1])); + sse = vmlal_u16(sse, vget_high_u16(abs_diff[1]), vget_high_u16(abs_diff[1])); - return vget_lane_u32(sse, 0); + return horizontal_add_uint32x4(sse); } -#else - -unsigned int vpx_mse16x16_neon(const unsigned char *src_ptr, int src_stride, - const unsigned char *ref_ptr, int ref_stride, - unsigned int *sse) { - int i; - uint8x16_t a[2], b[2]; - int16x4_t diff_lo[4], diff_hi[4]; - uint16x8_t diff[4]; - int32x4_t sse_vec[4] = { vdupq_n_s32(0), vdupq_n_s32(0), vdupq_n_s32(0), - vdupq_n_s32(0) }; - - for (i = 0; i < 8; i++) { - a[0] = vld1q_u8(src_ptr); - src_ptr += src_stride; - a[1] = vld1q_u8(src_ptr); - src_ptr += src_stride; - b[0] = vld1q_u8(ref_ptr); - ref_ptr += ref_stride; - b[1] = vld1q_u8(ref_ptr); - ref_ptr += ref_stride; - - diff[0] = vsubl_u8(vget_low_u8(a[0]), vget_low_u8(b[0])); - diff[1] = vsubl_u8(vget_high_u8(a[0]), vget_high_u8(b[0])); - diff[2] = vsubl_u8(vget_low_u8(a[1]), vget_low_u8(b[1])); - diff[3] = vsubl_u8(vget_high_u8(a[1]), vget_high_u8(b[1])); - - diff_lo[0] = vreinterpret_s16_u16(vget_low_u16(diff[0])); - diff_lo[1] = vreinterpret_s16_u16(vget_low_u16(diff[1])); - sse_vec[0] = vmlal_s16(sse_vec[0], diff_lo[0], diff_lo[0]); - sse_vec[1] = vmlal_s16(sse_vec[1], diff_lo[1], diff_lo[1]); - - diff_lo[2] = vreinterpret_s16_u16(vget_low_u16(diff[2])); - diff_lo[3] = vreinterpret_s16_u16(vget_low_u16(diff[3])); - sse_vec[2] = vmlal_s16(sse_vec[2], diff_lo[2], diff_lo[2]); - sse_vec[3] = vmlal_s16(sse_vec[3], diff_lo[3], diff_lo[3]); - - diff_hi[0] = vreinterpret_s16_u16(vget_high_u16(diff[0])); - diff_hi[1] = vreinterpret_s16_u16(vget_high_u16(diff[1])); - sse_vec[0] = vmlal_s16(sse_vec[0], diff_hi[0], diff_hi[0]); - sse_vec[1] = vmlal_s16(sse_vec[1], diff_hi[1], diff_hi[1]); - - diff_hi[2] = vreinterpret_s16_u16(vget_high_u16(diff[2])); - diff_hi[3] = vreinterpret_s16_u16(vget_high_u16(diff[3])); - sse_vec[2] = vmlal_s16(sse_vec[2], diff_hi[2], diff_hi[2]); - sse_vec[3] = vmlal_s16(sse_vec[3], diff_hi[3], diff_hi[3]); +#define VPX_MSE_WXH_NEON(w, h) \ + unsigned int vpx_mse##w##x##h##_neon( \ + const unsigned char *src_ptr, int src_stride, \ + const unsigned char *ref_ptr, int ref_stride, unsigned int *sse) { \ + *sse = vpx_mse##w##xh_neon(src_ptr, src_stride, ref_ptr, ref_stride, h); \ + return *sse; \ } - sse_vec[0] = vaddq_s32(sse_vec[0], sse_vec[1]); - sse_vec[2] = vaddq_s32(sse_vec[2], sse_vec[3]); - sse_vec[0] = vaddq_s32(sse_vec[0], sse_vec[2]); +VPX_MSE_WXH_NEON(8, 8) +VPX_MSE_WXH_NEON(8, 16) +VPX_MSE_WXH_NEON(16, 8) +VPX_MSE_WXH_NEON(16, 16) - *sse = horizontal_add_uint32x4(vreinterpretq_u32_s32(sse_vec[0])); - return horizontal_add_uint32x4(vreinterpretq_u32_s32(sse_vec[0])); -} - -unsigned int vpx_get4x4sse_cs_neon(const unsigned char *src_ptr, int src_stride, - const unsigned char *ref_ptr, - int ref_stride) { - uint8x8_t a[4], b[4]; - int16x4_t diff_lo[4]; - uint16x8_t diff[4]; - int32x4_t sse; - - a[0] = vld1_u8(src_ptr); - src_ptr += src_stride; - b[0] = vld1_u8(ref_ptr); - ref_ptr += ref_stride; - a[1] = vld1_u8(src_ptr); - src_ptr += src_stride; - b[1] = vld1_u8(ref_ptr); - ref_ptr += ref_stride; - a[2] = vld1_u8(src_ptr); - src_ptr += src_stride; - b[2] = vld1_u8(ref_ptr); - ref_ptr += ref_stride; - a[3] = vld1_u8(src_ptr); - b[3] = vld1_u8(ref_ptr); - - diff[0] = vsubl_u8(a[0], b[0]); - diff[1] = vsubl_u8(a[1], b[1]); - diff[2] = vsubl_u8(a[2], b[2]); - diff[3] = vsubl_u8(a[3], b[3]); - - diff_lo[0] = vget_low_s16(vreinterpretq_s16_u16(diff[0])); - diff_lo[1] = vget_low_s16(vreinterpretq_s16_u16(diff[1])); - diff_lo[2] = vget_low_s16(vreinterpretq_s16_u16(diff[2])); - diff_lo[3] = vget_low_s16(vreinterpretq_s16_u16(diff[3])); - - sse = vmull_s16(diff_lo[0], diff_lo[0]); - sse = vmlal_s16(sse, diff_lo[1], diff_lo[1]); - sse = vmlal_s16(sse, diff_lo[2], diff_lo[2]); - sse = vmlal_s16(sse, diff_lo[3], diff_lo[3]); - - return horizontal_add_uint32x4(vreinterpretq_u32_s32(sse)); -} - -#endif +#undef VPX_MSE_WXH_NEON diff --git a/libs/libvpx/vpx_dsp/arm/variance_neon_dotprod.c b/libs/libvpx/vpx_dsp/arm/variance_neon_dotprod.c new file mode 100644 index 0000000000..8810af7915 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/variance_neon_dotprod.c @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2021 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_dsp_rtcd.h" +#include "./vpx_config.h" + +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/sum_neon.h" +#include "vpx_ports/mem.h" + +// Process a block of width 4 four rows at a time. +static INLINE void variance_4xh_neon_dotprod(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + uint32_t *sse, int *sum) { + uint32x4_t src_sum = vdupq_n_u32(0); + uint32x4_t ref_sum = vdupq_n_u32(0); + uint32x4_t sse_u32 = vdupq_n_u32(0); + + do { + const uint8x16_t s = load_unaligned_u8q(src_ptr, src_stride); + const uint8x16_t r = load_unaligned_u8q(ref_ptr, ref_stride); + + const uint8x16_t abs_diff = vabdq_u8(s, r); + sse_u32 = vdotq_u32(sse_u32, abs_diff, abs_diff); + + src_sum = vdotq_u32(src_sum, s, vdupq_n_u8(1)); + ref_sum = vdotq_u32(ref_sum, r, vdupq_n_u8(1)); + + src_ptr += 4 * src_stride; + ref_ptr += 4 * ref_stride; + h -= 4; + } while (h != 0); + + *sum = horizontal_add_int32x4( + vreinterpretq_s32_u32(vsubq_u32(src_sum, ref_sum))); + *sse = horizontal_add_uint32x4(sse_u32); +} + +// Process a block of width 8 two rows at a time. +static INLINE void variance_8xh_neon_dotprod(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + uint32_t *sse, int *sum) { + uint32x4_t src_sum = vdupq_n_u32(0); + uint32x4_t ref_sum = vdupq_n_u32(0); + uint32x4_t sse_u32 = vdupq_n_u32(0); + + do { + const uint8x16_t s = + vcombine_u8(vld1_u8(src_ptr), vld1_u8(src_ptr + src_stride)); + const uint8x16_t r = + vcombine_u8(vld1_u8(ref_ptr), vld1_u8(ref_ptr + ref_stride)); + + const uint8x16_t abs_diff = vabdq_u8(s, r); + sse_u32 = vdotq_u32(sse_u32, abs_diff, abs_diff); + + src_sum = vdotq_u32(src_sum, s, vdupq_n_u8(1)); + ref_sum = vdotq_u32(ref_sum, r, vdupq_n_u8(1)); + + src_ptr += 2 * src_stride; + ref_ptr += 2 * ref_stride; + h -= 2; + } while (h != 0); + + *sum = horizontal_add_int32x4( + vreinterpretq_s32_u32(vsubq_u32(src_sum, ref_sum))); + *sse = horizontal_add_uint32x4(sse_u32); +} + +// Process a block of width 16 one row at a time. +static INLINE void variance_16xh_neon_dotprod(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + uint32_t *sse, int *sum) { + uint32x4_t src_sum = vdupq_n_u32(0); + uint32x4_t ref_sum = vdupq_n_u32(0); + uint32x4_t sse_u32 = vdupq_n_u32(0); + + do { + const uint8x16_t s = vld1q_u8(src_ptr); + const uint8x16_t r = vld1q_u8(ref_ptr); + + const uint8x16_t abs_diff = vabdq_u8(s, r); + sse_u32 = vdotq_u32(sse_u32, abs_diff, abs_diff); + + src_sum = vdotq_u32(src_sum, s, vdupq_n_u8(1)); + ref_sum = vdotq_u32(ref_sum, r, vdupq_n_u8(1)); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--h != 0); + + *sum = horizontal_add_int32x4( + vreinterpretq_s32_u32(vsubq_u32(src_sum, ref_sum))); + *sse = horizontal_add_uint32x4(sse_u32); +} + +// Process a block of width 32 one row at a time. +static INLINE void variance_32xh_neon_dotprod(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + uint32_t *sse, int *sum) { + uint32x4_t src_sum[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + uint32x4_t ref_sum[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + uint32x4_t sse_u32[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + do { + const uint8x16_t s0 = vld1q_u8(src_ptr); + const uint8x16_t r0 = vld1q_u8(ref_ptr); + + const uint8x16_t abs_diff0 = vabdq_u8(s0, r0); + sse_u32[0] = vdotq_u32(sse_u32[0], abs_diff0, abs_diff0); + + src_sum[0] = vdotq_u32(src_sum[0], s0, vdupq_n_u8(1)); + ref_sum[0] = vdotq_u32(ref_sum[0], r0, vdupq_n_u8(1)); + + const uint8x16_t s1 = vld1q_u8(src_ptr + 16); + const uint8x16_t r1 = vld1q_u8(ref_ptr + 16); + + const uint8x16_t abs_diff1 = vabdq_u8(s1, r1); + sse_u32[1] = vdotq_u32(sse_u32[1], abs_diff1, abs_diff1); + + src_sum[1] = vdotq_u32(src_sum[1], s1, vdupq_n_u8(1)); + ref_sum[1] = vdotq_u32(ref_sum[1], r1, vdupq_n_u8(1)); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--h != 0); + + src_sum[0] = vaddq_u32(src_sum[0], src_sum[1]); + ref_sum[0] = vaddq_u32(ref_sum[0], ref_sum[1]); + *sum = horizontal_add_int32x4( + vreinterpretq_s32_u32(vsubq_u32(src_sum[0], ref_sum[0]))); + *sse = horizontal_add_uint32x4(vaddq_u32(sse_u32[0], sse_u32[1])); +} + +// Process a block of width 64 one row at a time. +static INLINE void variance_64xh_neon_dotprod(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h, + uint32_t *sse, int *sum) { + uint32x4_t src_sum[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), + vdupq_n_u32(0) }; + uint32x4_t ref_sum[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), + vdupq_n_u32(0) }; + uint32x4_t sse_u32[4] = { vdupq_n_u32(0), vdupq_n_u32(0), vdupq_n_u32(0), + vdupq_n_u32(0) }; + + do { + const uint8x16_t s0 = vld1q_u8(src_ptr); + const uint8x16_t r0 = vld1q_u8(ref_ptr); + + const uint8x16_t abs_diff0 = vabdq_u8(s0, r0); + sse_u32[0] = vdotq_u32(sse_u32[0], abs_diff0, abs_diff0); + + src_sum[0] = vdotq_u32(src_sum[0], s0, vdupq_n_u8(1)); + ref_sum[0] = vdotq_u32(ref_sum[0], r0, vdupq_n_u8(1)); + + const uint8x16_t s1 = vld1q_u8(src_ptr + 16); + const uint8x16_t r1 = vld1q_u8(ref_ptr + 16); + + const uint8x16_t abs_diff1 = vabdq_u8(s1, r1); + sse_u32[1] = vdotq_u32(sse_u32[1], abs_diff1, abs_diff1); + + src_sum[1] = vdotq_u32(src_sum[1], s1, vdupq_n_u8(1)); + ref_sum[1] = vdotq_u32(ref_sum[1], r1, vdupq_n_u8(1)); + + const uint8x16_t s2 = vld1q_u8(src_ptr + 32); + const uint8x16_t r2 = vld1q_u8(ref_ptr + 32); + + const uint8x16_t abs_diff2 = vabdq_u8(s2, r2); + sse_u32[2] = vdotq_u32(sse_u32[2], abs_diff2, abs_diff2); + + src_sum[2] = vdotq_u32(src_sum[2], s2, vdupq_n_u8(1)); + ref_sum[2] = vdotq_u32(ref_sum[2], r2, vdupq_n_u8(1)); + + const uint8x16_t s3 = vld1q_u8(src_ptr + 48); + const uint8x16_t r3 = vld1q_u8(ref_ptr + 48); + + const uint8x16_t abs_diff3 = vabdq_u8(s3, r3); + sse_u32[3] = vdotq_u32(sse_u32[3], abs_diff3, abs_diff3); + + src_sum[3] = vdotq_u32(src_sum[3], s3, vdupq_n_u8(1)); + ref_sum[3] = vdotq_u32(ref_sum[3], r3, vdupq_n_u8(1)); + + src_ptr += src_stride; + ref_ptr += ref_stride; + } while (--h != 0); + + src_sum[0] = horizontal_add_4d_uint32x4(src_sum); + ref_sum[0] = horizontal_add_4d_uint32x4(ref_sum); + *sum = horizontal_add_int32x4( + vreinterpretq_s32_u32(vsubq_u32(src_sum[0], ref_sum[0]))); + *sse = horizontal_add_uint32x4(horizontal_add_4d_uint32x4(sse_u32)); +} + +void vpx_get8x8var_neon_dotprod(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + unsigned int *sse, int *sum) { + variance_8xh_neon_dotprod(src_ptr, src_stride, ref_ptr, ref_stride, 8, sse, + sum); +} + +void vpx_get16x16var_neon_dotprod(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + unsigned int *sse, int *sum) { + variance_16xh_neon_dotprod(src_ptr, src_stride, ref_ptr, ref_stride, 16, sse, + sum); +} + +#define VARIANCE_WXH_NEON_DOTPROD(w, h, shift) \ + unsigned int vpx_variance##w##x##h##_neon_dotprod( \ + const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \ + unsigned int *sse) { \ + int sum; \ + variance_##w##xh_neon_dotprod(src, src_stride, ref, ref_stride, h, sse, \ + &sum); \ + return *sse - (uint32_t)(((int64_t)sum * sum) >> shift); \ + } + +// The Armv8.0 Neon implementation is faster than Neon DotProd for 4x4. +VARIANCE_WXH_NEON_DOTPROD(4, 8, 5) + +VARIANCE_WXH_NEON_DOTPROD(8, 4, 5) +VARIANCE_WXH_NEON_DOTPROD(8, 8, 6) +VARIANCE_WXH_NEON_DOTPROD(8, 16, 7) + +VARIANCE_WXH_NEON_DOTPROD(16, 8, 7) +VARIANCE_WXH_NEON_DOTPROD(16, 16, 8) +VARIANCE_WXH_NEON_DOTPROD(16, 32, 9) + +VARIANCE_WXH_NEON_DOTPROD(32, 16, 9) +VARIANCE_WXH_NEON_DOTPROD(32, 32, 10) +VARIANCE_WXH_NEON_DOTPROD(32, 64, 11) + +VARIANCE_WXH_NEON_DOTPROD(64, 32, 11) +VARIANCE_WXH_NEON_DOTPROD(64, 64, 12) + +#undef VARIANCE_WXH_NEON_DOTPROD + +static INLINE unsigned int vpx_mse8xh_neon_dotprod(const unsigned char *src_ptr, + int src_stride, + const unsigned char *ref_ptr, + int ref_stride, int h) { + uint32x2_t sse_u32[2] = { vdup_n_u32(0), vdup_n_u32(0) }; + + do { + uint8x8_t s0, s1, r0, r1, diff0, diff1; + + s0 = vld1_u8(src_ptr); + src_ptr += src_stride; + s1 = vld1_u8(src_ptr); + src_ptr += src_stride; + r0 = vld1_u8(ref_ptr); + ref_ptr += ref_stride; + r1 = vld1_u8(ref_ptr); + ref_ptr += ref_stride; + + diff0 = vabd_u8(s0, r0); + diff1 = vabd_u8(s1, r1); + + sse_u32[0] = vdot_u32(sse_u32[0], diff0, diff0); + sse_u32[1] = vdot_u32(sse_u32[1], diff1, diff1); + h -= 2; + } while (h != 0); + + return horizontal_add_uint32x2(vadd_u32(sse_u32[0], sse_u32[1])); +} + +static INLINE unsigned int vpx_mse16xh_neon_dotprod( + const unsigned char *src_ptr, int src_stride, const unsigned char *ref_ptr, + int ref_stride, int h) { + uint32x4_t sse_u32[2] = { vdupq_n_u32(0), vdupq_n_u32(0) }; + + do { + uint8x16_t s0, s1, r0, r1, diff0, diff1; + + s0 = vld1q_u8(src_ptr); + src_ptr += src_stride; + s1 = vld1q_u8(src_ptr); + src_ptr += src_stride; + r0 = vld1q_u8(ref_ptr); + ref_ptr += ref_stride; + r1 = vld1q_u8(ref_ptr); + ref_ptr += ref_stride; + + diff0 = vabdq_u8(s0, r0); + diff1 = vabdq_u8(s1, r1); + + sse_u32[0] = vdotq_u32(sse_u32[0], diff0, diff0); + sse_u32[1] = vdotq_u32(sse_u32[1], diff1, diff1); + h -= 2; + } while (h != 0); + + return horizontal_add_uint32x4(vaddq_u32(sse_u32[0], sse_u32[1])); +} + +unsigned int vpx_get4x4sse_cs_neon_dotprod(const unsigned char *src_ptr, + int src_stride, + const unsigned char *ref_ptr, + int ref_stride) { + uint8x16_t s = load_unaligned_u8q(src_ptr, src_stride); + uint8x16_t r = load_unaligned_u8q(ref_ptr, ref_stride); + + uint8x16_t abs_diff = vabdq_u8(s, r); + + uint32x4_t sse = vdotq_u32(vdupq_n_u32(0), abs_diff, abs_diff); + + return horizontal_add_uint32x4(sse); +} + +#define VPX_MSE_WXH_NEON_DOTPROD(w, h) \ + unsigned int vpx_mse##w##x##h##_neon_dotprod( \ + const unsigned char *src_ptr, int src_stride, \ + const unsigned char *ref_ptr, int ref_stride, unsigned int *sse) { \ + *sse = vpx_mse##w##xh_neon_dotprod(src_ptr, src_stride, ref_ptr, \ + ref_stride, h); \ + return *sse; \ + } + +VPX_MSE_WXH_NEON_DOTPROD(8, 8) +VPX_MSE_WXH_NEON_DOTPROD(8, 16) +VPX_MSE_WXH_NEON_DOTPROD(16, 8) +VPX_MSE_WXH_NEON_DOTPROD(16, 16) + +#undef VPX_MSE_WXH_NEON_DOTPROD diff --git a/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon.c b/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon.c index 06b58c438f..037ea1142d 100644 --- a/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon.c +++ b/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon.c @@ -17,859 +17,119 @@ #include "vpx_dsp/arm/mem_neon.h" #include "vpx_dsp/arm/transpose_neon.h" #include "vpx_dsp/arm/vpx_convolve8_neon.h" +#include "vpx_dsp/vpx_filter.h" #include "vpx_ports/mem.h" -// Note: -// 1. src is not always 32-bit aligned, so don't call vld1_lane_u32(src). -// 2. After refactoring the shared code in kernel loops with inline functions, -// the decoder speed dropped a lot when using gcc compiler. Therefore there is -// no refactoring for those parts by now. -// 3. For horizontal convolve, there is an alternative optimization that -// convolves a single row in each loop. For each row, 8 sample banks with 4 or 8 -// samples in each are read from memory: src, (src+1), (src+2), (src+3), -// (src+4), (src+5), (src+6), (src+7), or prepared by vector extract -// instructions. This optimization is much faster in speed unit test, but slowed -// down the whole decoder by 5%. +static INLINE void convolve_4tap_horiz_neon(const uint8_t *src, + ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, int w, int h, + const int16x8_t filter) { + // 4-tap and bilinear filter values are even, so halve them to reduce + // intermediate precision requirements. + const uint8x8_t x_filter = + vshrn_n_u16(vreinterpretq_u16_s16(vabsq_s16(filter)), 1); -#if defined(__aarch64__) && defined(__ARM_FEATURE_DOTPROD) && \ - (__ARM_FEATURE_DOTPROD == 1) -DECLARE_ALIGNED(16, static const uint8_t, dot_prod_permute_tbl[48]) = { - 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, - 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, - 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14 -}; - -DECLARE_ALIGNED(16, static const uint8_t, dot_prod_tran_concat_tbl[32]) = { - 0, 8, 16, 24, 1, 9, 17, 25, 2, 10, 18, 26, 3, 11, 19, 27, - 4, 12, 20, 28, 5, 13, 21, 29, 6, 14, 22, 30, 7, 15, 23, 31 -}; - -DECLARE_ALIGNED(16, static const uint8_t, dot_prod_merge_block_tbl[48]) = { - /* Shift left and insert new last column in transposed 4x4 block. */ - 1, 2, 3, 16, 5, 6, 7, 20, 9, 10, 11, 24, 13, 14, 15, 28, - /* Shift left and insert two new columns in transposed 4x4 block. */ - 2, 3, 16, 17, 6, 7, 20, 21, 10, 11, 24, 25, 14, 15, 28, 29, - /* Shift left and insert three new columns in transposed 4x4 block. */ - 3, 16, 17, 18, 7, 20, 21, 22, 11, 24, 25, 26, 15, 28, 29, 30 -}; - -static INLINE void transpose_concat_4x4(int8x8_t *a0, int8x8_t *a1, - int8x8_t *a2, int8x8_t *a3, - int8x16_t *b, - const uint8x16_t permute_tbl) { - /* Transpose 8-bit elements and concatenate result rows as follows: - * a0: 00, 01, 02, 03, XX, XX, XX, XX - * a1: 10, 11, 12, 13, XX, XX, XX, XX - * a2: 20, 21, 22, 23, XX, XX, XX, XX - * a3: 30, 31, 32, 33, XX, XX, XX, XX - * - * b: 00, 10, 20, 30, 01, 11, 21, 31, 02, 12, 22, 32, 03, 13, 23, 33 - * - * The 'permute_tbl' is always 'dot_prod_tran_concat_tbl' above. Passing it - * as an argument is preferable to loading it directly from memory as this - * inline helper is called many times from the same parent function. - */ - - int8x16x2_t samples = { { vcombine_s8(*a0, *a1), vcombine_s8(*a2, *a3) } }; - *b = vqtbl2q_s8(samples, permute_tbl); -} - -static INLINE void transpose_concat_8x4(int8x8_t *a0, int8x8_t *a1, - int8x8_t *a2, int8x8_t *a3, - int8x16_t *b0, int8x16_t *b1, - const uint8x16x2_t permute_tbl) { - /* Transpose 8-bit elements and concatenate result rows as follows: - * a0: 00, 01, 02, 03, 04, 05, 06, 07 - * a1: 10, 11, 12, 13, 14, 15, 16, 17 - * a2: 20, 21, 22, 23, 24, 25, 26, 27 - * a3: 30, 31, 32, 33, 34, 35, 36, 37 - * - * b0: 00, 10, 20, 30, 01, 11, 21, 31, 02, 12, 22, 32, 03, 13, 23, 33 - * b1: 04, 14, 24, 34, 05, 15, 25, 35, 06, 16, 26, 36, 07, 17, 27, 37 - * - * The 'permute_tbl' is always 'dot_prod_tran_concat_tbl' above. Passing it - * as an argument is preferable to loading it directly from memory as this - * inline helper is called many times from the same parent function. - */ - - int8x16x2_t samples = { { vcombine_s8(*a0, *a1), vcombine_s8(*a2, *a3) } }; - *b0 = vqtbl2q_s8(samples, permute_tbl.val[0]); - *b1 = vqtbl2q_s8(samples, permute_tbl.val[1]); -} - -void vpx_convolve8_horiz_neon(const uint8_t *src, ptrdiff_t src_stride, - uint8_t *dst, ptrdiff_t dst_stride, - const InterpKernel *filter, int x0_q4, - int x_step_q4, int y0_q4, int y_step_q4, int w, - int h) { - const int8x8_t filters = vmovn_s16(vld1q_s16(filter[x0_q4])); - const int16x8_t correct_tmp = vmulq_n_s16(vld1q_s16(filter[x0_q4]), 128); - const int32x4_t correction = vdupq_n_s32((int32_t)vaddvq_s16(correct_tmp)); - const uint8x16_t range_limit = vdupq_n_u8(128); - uint8x16_t s0, s1, s2, s3; - - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); - assert(x_step_q4 == 16); - - (void)x_step_q4; - (void)y0_q4; - (void)y_step_q4; - - src -= 3; + // Neon does not have lane-referencing multiply or multiply-accumulate + // instructions that operate on vectors of 8-bit elements. This means we have + // to duplicate filter taps into a whole vector and use standard multiply / + // multiply-accumulate instructions. + const uint8x8_t filter_taps[4] = { vdup_lane_u8(x_filter, 2), + vdup_lane_u8(x_filter, 3), + vdup_lane_u8(x_filter, 4), + vdup_lane_u8(x_filter, 5) }; if (w == 4) { - const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); do { - int32x4_t t0, t1, t2, t3; - int16x8_t t01, t23; - uint8x8_t d01, d23; + uint8x8_t s01[4]; - s0 = vld1q_u8(src); - src += src_stride; - s1 = vld1q_u8(src); - src += src_stride; - s2 = vld1q_u8(src); - src += src_stride; - s3 = vld1q_u8(src); - src += src_stride; + s01[0] = load_unaligned_u8(src + 0, src_stride); + s01[1] = load_unaligned_u8(src + 1, src_stride); + s01[2] = load_unaligned_u8(src + 2, src_stride); + s01[3] = load_unaligned_u8(src + 3, src_stride); - t0 = convolve8_4_dot(s0, filters, correction, range_limit, permute_tbl); - t1 = convolve8_4_dot(s1, filters, correction, range_limit, permute_tbl); - t2 = convolve8_4_dot(s2, filters, correction, range_limit, permute_tbl); - t3 = convolve8_4_dot(s3, filters, correction, range_limit, permute_tbl); + uint8x8_t d01 = convolve4_8(s01[0], s01[1], s01[2], s01[3], filter_taps); - t01 = vcombine_s16(vqmovn_s32(t0), vqmovn_s32(t1)); - t23 = vcombine_s16(vqmovn_s32(t2), vqmovn_s32(t3)); - d01 = vqrshrun_n_s16(t01, 7); - d23 = vqrshrun_n_s16(t23, 7); + store_unaligned_u8(dst, dst_stride, d01); - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d01), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d01), 1); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d23), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d23), 1); - dst += dst_stride; - h -= 4; + src += 2 * src_stride; + dst += 2 * dst_stride; + h -= 2; } while (h > 0); } else { - const uint8x16x3_t permute_tbl = vld1q_u8_x3(dot_prod_permute_tbl); - const uint8_t *s; - uint8_t *d; - int width; - uint8x8_t d0, d1, d2, d3; - do { - width = w; - s = src; - d = dst; + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + do { - s0 = vld1q_u8(s + 0 * src_stride); - s1 = vld1q_u8(s + 1 * src_stride); - s2 = vld1q_u8(s + 2 * src_stride); - s3 = vld1q_u8(s + 3 * src_stride); + uint8x8_t s0[4], s1[4]; - d0 = convolve8_8_dot(s0, filters, correction, range_limit, permute_tbl); - d1 = convolve8_8_dot(s1, filters, correction, range_limit, permute_tbl); - d2 = convolve8_8_dot(s2, filters, correction, range_limit, permute_tbl); - d3 = convolve8_8_dot(s3, filters, correction, range_limit, permute_tbl); + s0[0] = vld1_u8(s + 0); + s0[1] = vld1_u8(s + 1); + s0[2] = vld1_u8(s + 2); + s0[3] = vld1_u8(s + 3); - vst1_u8(d + 0 * dst_stride, d0); - vst1_u8(d + 1 * dst_stride, d1); - vst1_u8(d + 2 * dst_stride, d2); - vst1_u8(d + 3 * dst_stride, d3); + s1[0] = vld1_u8(s + src_stride + 0); + s1[1] = vld1_u8(s + src_stride + 1); + s1[2] = vld1_u8(s + src_stride + 2); + s1[3] = vld1_u8(s + src_stride + 3); + uint8x8_t d0 = convolve4_8(s0[0], s0[1], s0[2], s0[3], filter_taps); + uint8x8_t d1 = convolve4_8(s1[0], s1[1], s1[2], s1[3], filter_taps); + + vst1_u8(d, d0); + vst1_u8(d + dst_stride, d1); s += 8; d += 8; width -= 8; - } while (width > 0); - src += 4 * src_stride; - dst += 4 * dst_stride; - h -= 4; + } while (width != 0); + src += 2 * src_stride; + dst += 2 * dst_stride; + h -= 2; } while (h > 0); } } -void vpx_convolve8_avg_horiz_neon(const uint8_t *src, ptrdiff_t src_stride, - uint8_t *dst, ptrdiff_t dst_stride, - const InterpKernel *filter, int x0_q4, - int x_step_q4, int y0_q4, int y_step_q4, - int w, int h) { - const int8x8_t filters = vmovn_s16(vld1q_s16(filter[x0_q4])); - const int16x8_t correct_tmp = vmulq_n_s16(vld1q_s16(filter[x0_q4]), 128); - const int32x4_t correction = vdupq_n_s32((int32_t)vaddvq_s16(correct_tmp)); - const uint8x16_t range_limit = vdupq_n_u8(128); - uint8x16_t s0, s1, s2, s3; - - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); - assert(x_step_q4 == 16); - - (void)x_step_q4; - (void)y0_q4; - (void)y_step_q4; - - src -= 3; - - if (w == 4) { - const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); - do { - int32x4_t t0, t1, t2, t3; - int16x8_t t01, t23; - uint8x8_t d01, d23, dd01, dd23; - dd01 = vdup_n_u8(0); - dd23 = vdup_n_u8(0); - - s0 = vld1q_u8(src); - src += src_stride; - s1 = vld1q_u8(src); - src += src_stride; - s2 = vld1q_u8(src); - src += src_stride; - s3 = vld1q_u8(src); - src += src_stride; - - t0 = convolve8_4_dot(s0, filters, correction, range_limit, permute_tbl); - t1 = convolve8_4_dot(s1, filters, correction, range_limit, permute_tbl); - t2 = convolve8_4_dot(s2, filters, correction, range_limit, permute_tbl); - t3 = convolve8_4_dot(s3, filters, correction, range_limit, permute_tbl); - - t01 = vcombine_s16(vqmovn_s32(t0), vqmovn_s32(t1)); - t23 = vcombine_s16(vqmovn_s32(t2), vqmovn_s32(t3)); - d01 = vqrshrun_n_s16(t01, 7); - d23 = vqrshrun_n_s16(t23, 7); - - dd01 = load_u8(dst + 0 * dst_stride, dst_stride); - dd23 = load_u8(dst + 2 * dst_stride, dst_stride); - d01 = vrhadd_u8(d01, dd01); - d23 = vrhadd_u8(d23, dd23); - - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d01), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d01), 1); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d23), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d23), 1); - dst += dst_stride; - h -= 4; - } while (h > 0); - } else { - const uint8x16x3_t permute_tbl = vld1q_u8_x3(dot_prod_permute_tbl); - const uint8_t *s; - uint8_t *d; - int width; - uint8x8_t d0, d1, d2, d3, dd0, dd1, dd2, dd3; - - do { - width = w; - s = src; - d = dst; - do { - s0 = vld1q_u8(s + 0 * src_stride); - s1 = vld1q_u8(s + 1 * src_stride); - s2 = vld1q_u8(s + 2 * src_stride); - s3 = vld1q_u8(s + 3 * src_stride); - - d0 = convolve8_8_dot(s0, filters, correction, range_limit, permute_tbl); - d1 = convolve8_8_dot(s1, filters, correction, range_limit, permute_tbl); - d2 = convolve8_8_dot(s2, filters, correction, range_limit, permute_tbl); - d3 = convolve8_8_dot(s3, filters, correction, range_limit, permute_tbl); - - dd0 = vld1_u8(d + 0 * dst_stride); - dd1 = vld1_u8(d + 1 * dst_stride); - dd2 = vld1_u8(d + 2 * dst_stride); - dd3 = vld1_u8(d + 3 * dst_stride); - d0 = vrhadd_u8(d0, dd0); - d1 = vrhadd_u8(d1, dd1); - d2 = vrhadd_u8(d2, dd2); - d3 = vrhadd_u8(d3, dd3); - - vst1_u8(d + 0 * dst_stride, d0); - vst1_u8(d + 1 * dst_stride, d1); - vst1_u8(d + 2 * dst_stride, d2); - vst1_u8(d + 3 * dst_stride, d3); - - s += 8; - d += 8; - width -= 8; - } while (width > 0); - src += 4 * src_stride; - dst += 4 * dst_stride; - h -= 4; - } while (h > 0); - } -} - -void vpx_convolve8_vert_neon(const uint8_t *src, ptrdiff_t src_stride, - uint8_t *dst, ptrdiff_t dst_stride, - const InterpKernel *filter, int x0_q4, - int x_step_q4, int y0_q4, int y_step_q4, int w, - int h) { - const int8x8_t filters = vmovn_s16(vld1q_s16(filter[y0_q4])); - const int16x8_t correct_tmp = vmulq_n_s16(vld1q_s16(filter[y0_q4]), 128); - const int32x4_t correction = vdupq_n_s32((int32_t)vaddvq_s16(correct_tmp)); - const uint8x8_t range_limit = vdup_n_u8(128); - const uint8x16x3_t merge_block_tbl = vld1q_u8_x3(dot_prod_merge_block_tbl); - uint8x8_t t0, t1, t2, t3, t4, t5, t6; - int8x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - int8x16x2_t samples_LUT; - - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); - assert(y_step_q4 == 16); - - (void)x0_q4; - (void)x_step_q4; - (void)y_step_q4; - - src -= 3 * src_stride; - - if (w == 4) { - const uint8x16_t tran_concat_tbl = vld1q_u8(dot_prod_tran_concat_tbl); - int8x16_t s0123, s1234, s2345, s3456, s4567, s5678, s6789, s78910; - int32x4_t d0, d1, d2, d3; - uint8x8_t d01, d23; - - load_u8_8x4(src, src_stride, &t0, &t1, &t2, &t3); - src += 4 * src_stride; - t4 = vld1_u8(src); - src += src_stride; - t5 = vld1_u8(src); - src += src_stride; - t6 = vld1_u8(src); - src += src_stride; - - /* Clamp sample range to [-128, 127] for 8-bit signed dot product. */ - s0 = vreinterpret_s8_u8(vsub_u8(t0, range_limit)); - s1 = vreinterpret_s8_u8(vsub_u8(t1, range_limit)); - s2 = vreinterpret_s8_u8(vsub_u8(t2, range_limit)); - s3 = vreinterpret_s8_u8(vsub_u8(t3, range_limit)); - s4 = vreinterpret_s8_u8(vsub_u8(t4, range_limit)); - s5 = vreinterpret_s8_u8(vsub_u8(t5, range_limit)); - s6 = vreinterpret_s8_u8(vsub_u8(t6, range_limit)); - s7 = vdup_n_s8(0); - s8 = vdup_n_s8(0); - s9 = vdup_n_s8(0); - - /* This operation combines a conventional transpose and the sample permute - * (see horizontal case) required before computing the dot product. - */ - transpose_concat_4x4(&s0, &s1, &s2, &s3, &s0123, tran_concat_tbl); - transpose_concat_4x4(&s1, &s2, &s3, &s4, &s1234, tran_concat_tbl); - transpose_concat_4x4(&s2, &s3, &s4, &s5, &s2345, tran_concat_tbl); - transpose_concat_4x4(&s3, &s4, &s5, &s6, &s3456, tran_concat_tbl); - transpose_concat_4x4(&s4, &s5, &s6, &s7, &s4567, tran_concat_tbl); - transpose_concat_4x4(&s5, &s6, &s7, &s8, &s5678, tran_concat_tbl); - transpose_concat_4x4(&s6, &s7, &s8, &s9, &s6789, tran_concat_tbl); - - do { - uint8x8_t t7, t8, t9, t10; - - load_u8_8x4(src, src_stride, &t7, &t8, &t9, &t10); - - s7 = vreinterpret_s8_u8(vsub_u8(t7, range_limit)); - s8 = vreinterpret_s8_u8(vsub_u8(t8, range_limit)); - s9 = vreinterpret_s8_u8(vsub_u8(t9, range_limit)); - s10 = vreinterpret_s8_u8(vsub_u8(t10, range_limit)); - - transpose_concat_4x4(&s7, &s8, &s9, &s10, &s78910, tran_concat_tbl); - - /* Merge new data into block from previous iteration. */ - samples_LUT.val[0] = s3456; - samples_LUT.val[1] = s78910; - s4567 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); - s5678 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); - s6789 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); - - d0 = convolve8_4_dot_partial(s0123, s4567, correction, filters); - d1 = convolve8_4_dot_partial(s1234, s5678, correction, filters); - d2 = convolve8_4_dot_partial(s2345, s6789, correction, filters); - d3 = convolve8_4_dot_partial(s3456, s78910, correction, filters); - - d01 = vqrshrun_n_s16(vcombine_s16(vqmovn_s32(d0), vqmovn_s32(d1)), 7); - d23 = vqrshrun_n_s16(vcombine_s16(vqmovn_s32(d2), vqmovn_s32(d3)), 7); - - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d01), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d01), 1); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d23), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d23), 1); - dst += dst_stride; - - /* Prepare block for next iteration - re-using as much as possible. */ - /* Shuffle everything up four rows. */ - s0123 = s4567; - s1234 = s5678; - s2345 = s6789; - s3456 = s78910; - - src += 4 * src_stride; - h -= 4; - } while (h > 0); - } else { - const uint8x16x2_t tran_concat_tbl = vld1q_u8_x2(dot_prod_tran_concat_tbl); - int8x16_t s0123_lo, s0123_hi, s1234_lo, s1234_hi, s2345_lo, s2345_hi, - s3456_lo, s3456_hi, s4567_lo, s4567_hi, s5678_lo, s5678_hi, s6789_lo, - s6789_hi, s78910_lo, s78910_hi; - uint8x8_t d0, d1, d2, d3; - const uint8_t *s; - uint8_t *d; - int height; - - do { - height = h; - s = src; - d = dst; - - load_u8_8x4(s, src_stride, &t0, &t1, &t2, &t3); - s += 4 * src_stride; - t4 = vld1_u8(s); - s += src_stride; - t5 = vld1_u8(s); - s += src_stride; - t6 = vld1_u8(s); - s += src_stride; - - /* Clamp sample range to [-128, 127] for 8-bit signed dot product. */ - s0 = vreinterpret_s8_u8(vsub_u8(t0, range_limit)); - s1 = vreinterpret_s8_u8(vsub_u8(t1, range_limit)); - s2 = vreinterpret_s8_u8(vsub_u8(t2, range_limit)); - s3 = vreinterpret_s8_u8(vsub_u8(t3, range_limit)); - s4 = vreinterpret_s8_u8(vsub_u8(t4, range_limit)); - s5 = vreinterpret_s8_u8(vsub_u8(t5, range_limit)); - s6 = vreinterpret_s8_u8(vsub_u8(t6, range_limit)); - s7 = vdup_n_s8(0); - s8 = vdup_n_s8(0); - s9 = vdup_n_s8(0); - - /* This operation combines a conventional transpose and the sample permute - * (see horizontal case) required before computing the dot product. - */ - transpose_concat_8x4(&s0, &s1, &s2, &s3, &s0123_lo, &s0123_hi, - tran_concat_tbl); - transpose_concat_8x4(&s1, &s2, &s3, &s4, &s1234_lo, &s1234_hi, - tran_concat_tbl); - transpose_concat_8x4(&s2, &s3, &s4, &s5, &s2345_lo, &s2345_hi, - tran_concat_tbl); - transpose_concat_8x4(&s3, &s4, &s5, &s6, &s3456_lo, &s3456_hi, - tran_concat_tbl); - transpose_concat_8x4(&s4, &s5, &s6, &s7, &s4567_lo, &s4567_hi, - tran_concat_tbl); - transpose_concat_8x4(&s5, &s6, &s7, &s8, &s5678_lo, &s5678_hi, - tran_concat_tbl); - transpose_concat_8x4(&s6, &s7, &s8, &s9, &s6789_lo, &s6789_hi, - tran_concat_tbl); - - do { - uint8x8_t t7, t8, t9, t10; - - load_u8_8x4(s, src_stride, &t7, &t8, &t9, &t10); - - s7 = vreinterpret_s8_u8(vsub_u8(t7, range_limit)); - s8 = vreinterpret_s8_u8(vsub_u8(t8, range_limit)); - s9 = vreinterpret_s8_u8(vsub_u8(t9, range_limit)); - s10 = vreinterpret_s8_u8(vsub_u8(t10, range_limit)); - - transpose_concat_8x4(&s7, &s8, &s9, &s10, &s78910_lo, &s78910_hi, - tran_concat_tbl); - - /* Merge new data into block from previous iteration. */ - samples_LUT.val[0] = s3456_lo; - samples_LUT.val[1] = s78910_lo; - s4567_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); - s5678_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); - s6789_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); - - samples_LUT.val[0] = s3456_hi; - samples_LUT.val[1] = s78910_hi; - s4567_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); - s5678_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); - s6789_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); - - d0 = convolve8_8_dot_partial(s0123_lo, s4567_lo, s0123_hi, s4567_hi, - correction, filters); - d1 = convolve8_8_dot_partial(s1234_lo, s5678_lo, s1234_hi, s5678_hi, - correction, filters); - d2 = convolve8_8_dot_partial(s2345_lo, s6789_lo, s2345_hi, s6789_hi, - correction, filters); - d3 = convolve8_8_dot_partial(s3456_lo, s78910_lo, s3456_hi, s78910_hi, - correction, filters); - vst1_u8(d + 0 * dst_stride, d0); - vst1_u8(d + 1 * dst_stride, d1); - vst1_u8(d + 2 * dst_stride, d2); - vst1_u8(d + 3 * dst_stride, d3); - - /* Prepare block for next iteration - re-using as much as possible. */ - /* Shuffle everything up four rows. */ - s0123_lo = s4567_lo; - s0123_hi = s4567_hi; - s1234_lo = s5678_lo; - s1234_hi = s5678_hi; - s2345_lo = s6789_lo; - s2345_hi = s6789_hi; - s3456_lo = s78910_lo; - s3456_hi = s78910_hi; - - s += 4 * src_stride; - d += 4 * dst_stride; - height -= 4; - } while (height > 0); - src += 8; - dst += 8; - w -= 8; - } while (w > 0); - } -} - -void vpx_convolve8_avg_vert_neon(const uint8_t *src, ptrdiff_t src_stride, - uint8_t *dst, ptrdiff_t dst_stride, - const InterpKernel *filter, int x0_q4, - int x_step_q4, int y0_q4, int y_step_q4, int w, - int h) { - const int8x8_t filters = vmovn_s16(vld1q_s16(filter[y0_q4])); - const int16x8_t correct_tmp = vmulq_n_s16(vld1q_s16(filter[y0_q4]), 128); - const int32x4_t correction = vdupq_n_s32((int32_t)vaddvq_s16(correct_tmp)); - const uint8x8_t range_limit = vdup_n_u8(128); - const uint8x16x3_t merge_block_tbl = vld1q_u8_x3(dot_prod_merge_block_tbl); - uint8x8_t t0, t1, t2, t3, t4, t5, t6; - int8x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - int8x16x2_t samples_LUT; - - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); - assert(y_step_q4 == 16); - - (void)x0_q4; - (void)x_step_q4; - (void)y_step_q4; - - src -= 3 * src_stride; - - if (w == 4) { - const uint8x16_t tran_concat_tbl = vld1q_u8(dot_prod_tran_concat_tbl); - int8x16_t s0123, s1234, s2345, s3456, s4567, s5678, s6789, s78910; - int32x4_t d0, d1, d2, d3; - uint8x8_t d01, d23, dd01, dd23; - - load_u8_8x4(src, src_stride, &t0, &t1, &t2, &t3); - src += 4 * src_stride; - t4 = vld1_u8(src); - src += src_stride; - t5 = vld1_u8(src); - src += src_stride; - t6 = vld1_u8(src); - src += src_stride; - - /* Clamp sample range to [-128, 127] for 8-bit signed dot product. */ - s0 = vreinterpret_s8_u8(vsub_u8(t0, range_limit)); - s1 = vreinterpret_s8_u8(vsub_u8(t1, range_limit)); - s2 = vreinterpret_s8_u8(vsub_u8(t2, range_limit)); - s3 = vreinterpret_s8_u8(vsub_u8(t3, range_limit)); - s4 = vreinterpret_s8_u8(vsub_u8(t4, range_limit)); - s5 = vreinterpret_s8_u8(vsub_u8(t5, range_limit)); - s6 = vreinterpret_s8_u8(vsub_u8(t6, range_limit)); - s7 = vdup_n_s8(0); - s8 = vdup_n_s8(0); - s9 = vdup_n_s8(0); - - /* This operation combines a conventional transpose and the sample permute - * (see horizontal case) required before computing the dot product. - */ - transpose_concat_4x4(&s0, &s1, &s2, &s3, &s0123, tran_concat_tbl); - transpose_concat_4x4(&s1, &s2, &s3, &s4, &s1234, tran_concat_tbl); - transpose_concat_4x4(&s2, &s3, &s4, &s5, &s2345, tran_concat_tbl); - transpose_concat_4x4(&s3, &s4, &s5, &s6, &s3456, tran_concat_tbl); - transpose_concat_4x4(&s4, &s5, &s6, &s7, &s4567, tran_concat_tbl); - transpose_concat_4x4(&s5, &s6, &s7, &s8, &s5678, tran_concat_tbl); - transpose_concat_4x4(&s6, &s7, &s8, &s9, &s6789, tran_concat_tbl); - - do { - uint8x8_t t7, t8, t9, t10; - - load_u8_8x4(src, src_stride, &t7, &t8, &t9, &t10); - - s7 = vreinterpret_s8_u8(vsub_u8(t7, range_limit)); - s8 = vreinterpret_s8_u8(vsub_u8(t8, range_limit)); - s9 = vreinterpret_s8_u8(vsub_u8(t9, range_limit)); - s10 = vreinterpret_s8_u8(vsub_u8(t10, range_limit)); - - transpose_concat_4x4(&s7, &s8, &s9, &s10, &s78910, tran_concat_tbl); - - /* Merge new data into block from previous iteration. */ - samples_LUT.val[0] = s3456; - samples_LUT.val[1] = s78910; - s4567 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); - s5678 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); - s6789 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); - - d0 = convolve8_4_dot_partial(s0123, s4567, correction, filters); - d1 = convolve8_4_dot_partial(s1234, s5678, correction, filters); - d2 = convolve8_4_dot_partial(s2345, s6789, correction, filters); - d3 = convolve8_4_dot_partial(s3456, s78910, correction, filters); - - d01 = vqrshrun_n_s16(vcombine_s16(vqmovn_s32(d0), vqmovn_s32(d1)), 7); - d23 = vqrshrun_n_s16(vcombine_s16(vqmovn_s32(d2), vqmovn_s32(d3)), 7); - - dd01 = load_u8(dst + 0 * dst_stride, dst_stride); - dd23 = load_u8(dst + 2 * dst_stride, dst_stride); - d01 = vrhadd_u8(d01, dd01); - d23 = vrhadd_u8(d23, dd23); - - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d01), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d01), 1); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d23), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d23), 1); - dst += dst_stride; - - /* Prepare block for next iteration - re-using as much as possible. */ - /* Shuffle everything up four rows. */ - s0123 = s4567; - s1234 = s5678; - s2345 = s6789; - s3456 = s78910; - - src += 4 * src_stride; - h -= 4; - } while (h > 0); - } else { - const uint8x16x2_t tran_concat_tbl = vld1q_u8_x2(dot_prod_tran_concat_tbl); - int8x16_t s0123_lo, s0123_hi, s1234_lo, s1234_hi, s2345_lo, s2345_hi, - s3456_lo, s3456_hi, s4567_lo, s4567_hi, s5678_lo, s5678_hi, s6789_lo, - s6789_hi, s78910_lo, s78910_hi; - uint8x8_t d0, d1, d2, d3, dd0, dd1, dd2, dd3; - const uint8_t *s; - uint8_t *d; - int height; - - do { - height = h; - s = src; - d = dst; - - load_u8_8x4(s, src_stride, &t0, &t1, &t2, &t3); - s += 4 * src_stride; - t4 = vld1_u8(s); - s += src_stride; - t5 = vld1_u8(s); - s += src_stride; - t6 = vld1_u8(s); - s += src_stride; - - /* Clamp sample range to [-128, 127] for 8-bit signed dot product. */ - s0 = vreinterpret_s8_u8(vsub_u8(t0, range_limit)); - s1 = vreinterpret_s8_u8(vsub_u8(t1, range_limit)); - s2 = vreinterpret_s8_u8(vsub_u8(t2, range_limit)); - s3 = vreinterpret_s8_u8(vsub_u8(t3, range_limit)); - s4 = vreinterpret_s8_u8(vsub_u8(t4, range_limit)); - s5 = vreinterpret_s8_u8(vsub_u8(t5, range_limit)); - s6 = vreinterpret_s8_u8(vsub_u8(t6, range_limit)); - s7 = vdup_n_s8(0); - s8 = vdup_n_s8(0); - s9 = vdup_n_s8(0); - - /* This operation combines a conventional transpose and the sample permute - * (see horizontal case) required before computing the dot product. - */ - transpose_concat_8x4(&s0, &s1, &s2, &s3, &s0123_lo, &s0123_hi, - tran_concat_tbl); - transpose_concat_8x4(&s1, &s2, &s3, &s4, &s1234_lo, &s1234_hi, - tran_concat_tbl); - transpose_concat_8x4(&s2, &s3, &s4, &s5, &s2345_lo, &s2345_hi, - tran_concat_tbl); - transpose_concat_8x4(&s3, &s4, &s5, &s6, &s3456_lo, &s3456_hi, - tran_concat_tbl); - transpose_concat_8x4(&s4, &s5, &s6, &s7, &s4567_lo, &s4567_hi, - tran_concat_tbl); - transpose_concat_8x4(&s5, &s6, &s7, &s8, &s5678_lo, &s5678_hi, - tran_concat_tbl); - transpose_concat_8x4(&s6, &s7, &s8, &s9, &s6789_lo, &s6789_hi, - tran_concat_tbl); - - do { - uint8x8_t t7, t8, t9, t10; - - load_u8_8x4(s, src_stride, &t7, &t8, &t9, &t10); - - s7 = vreinterpret_s8_u8(vsub_u8(t7, range_limit)); - s8 = vreinterpret_s8_u8(vsub_u8(t8, range_limit)); - s9 = vreinterpret_s8_u8(vsub_u8(t9, range_limit)); - s10 = vreinterpret_s8_u8(vsub_u8(t10, range_limit)); - - transpose_concat_8x4(&s7, &s8, &s9, &s10, &s78910_lo, &s78910_hi, - tran_concat_tbl); - - /* Merge new data into block from previous iteration. */ - samples_LUT.val[0] = s3456_lo; - samples_LUT.val[1] = s78910_lo; - s4567_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); - s5678_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); - s6789_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); - - samples_LUT.val[0] = s3456_hi; - samples_LUT.val[1] = s78910_hi; - s4567_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); - s5678_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); - s6789_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); - - d0 = convolve8_8_dot_partial(s0123_lo, s4567_lo, s0123_hi, s4567_hi, - correction, filters); - d1 = convolve8_8_dot_partial(s1234_lo, s5678_lo, s1234_hi, s5678_hi, - correction, filters); - d2 = convolve8_8_dot_partial(s2345_lo, s6789_lo, s2345_hi, s6789_hi, - correction, filters); - d3 = convolve8_8_dot_partial(s3456_lo, s78910_lo, s3456_hi, s78910_hi, - correction, filters); - - dd0 = vld1_u8(d + 0 * dst_stride); - dd1 = vld1_u8(d + 1 * dst_stride); - dd2 = vld1_u8(d + 2 * dst_stride); - dd3 = vld1_u8(d + 3 * dst_stride); - d0 = vrhadd_u8(d0, dd0); - d1 = vrhadd_u8(d1, dd1); - d2 = vrhadd_u8(d2, dd2); - d3 = vrhadd_u8(d3, dd3); - - vst1_u8(d + 0 * dst_stride, d0); - vst1_u8(d + 1 * dst_stride, d1); - vst1_u8(d + 2 * dst_stride, d2); - vst1_u8(d + 3 * dst_stride, d3); - - /* Prepare block for next iteration - re-using as much as possible. */ - /* Shuffle everything up four rows. */ - s0123_lo = s4567_lo; - s0123_hi = s4567_hi; - s1234_lo = s5678_lo; - s1234_hi = s5678_hi; - s2345_lo = s6789_lo; - s2345_hi = s6789_hi; - s3456_lo = s78910_lo; - s3456_hi = s78910_hi; - - s += 4 * src_stride; - d += 4 * dst_stride; - height -= 4; - } while (height > 0); - src += 8; - dst += 8; - w -= 8; - } while (w > 0); - } -} - -#else - -static INLINE void store_u8_8x8(uint8_t *s, const ptrdiff_t p, - const uint8x8_t s0, const uint8x8_t s1, - const uint8x8_t s2, const uint8x8_t s3, - const uint8x8_t s4, const uint8x8_t s5, - const uint8x8_t s6, const uint8x8_t s7) { - vst1_u8(s, s0); - s += p; - vst1_u8(s, s1); - s += p; - vst1_u8(s, s2); - s += p; - vst1_u8(s, s3); - s += p; - vst1_u8(s, s4); - s += p; - vst1_u8(s, s5); - s += p; - vst1_u8(s, s6); - s += p; - vst1_u8(s, s7); -} - -void vpx_convolve8_horiz_neon(const uint8_t *src, ptrdiff_t src_stride, - uint8_t *dst, ptrdiff_t dst_stride, - const InterpKernel *filter, int x0_q4, - int x_step_q4, int y0_q4, int y_step_q4, int w, - int h) { - const int16x8_t filters = vld1q_s16(filter[x0_q4]); - uint8x8_t t0, t1, t2, t3; - - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); - assert(x_step_q4 == 16); - - (void)x_step_q4; - (void)y0_q4; - (void)y_step_q4; - - src -= 3; - +static INLINE void convolve_8tap_horiz_neon(const uint8_t *src, + ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, int w, int h, + const int16x8_t filter) { if (h == 4) { - uint8x8_t d01, d23; - int16x4_t filter3, filter4, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, d0, - d1, d2, d3; - int16x8_t tt0, tt1, tt2, tt3; - - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - filter3 = vdup_lane_s16(vget_low_s16(filters), 3); - filter4 = vdup_lane_s16(vget_high_s16(filters), 0); + uint8x8_t t0, t1, t2, t3; load_u8_8x4(src, src_stride, &t0, &t1, &t2, &t3); + transpose_u8_8x4(&t0, &t1, &t2, &t3); - tt0 = vreinterpretq_s16_u16(vmovl_u8(t0)); - tt1 = vreinterpretq_s16_u16(vmovl_u8(t1)); - tt2 = vreinterpretq_s16_u16(vmovl_u8(t2)); - tt3 = vreinterpretq_s16_u16(vmovl_u8(t3)); - s0 = vget_low_s16(tt0); - s1 = vget_low_s16(tt1); - s2 = vget_low_s16(tt2); - s3 = vget_low_s16(tt3); - s4 = vget_high_s16(tt0); - s5 = vget_high_s16(tt1); - s6 = vget_high_s16(tt2); - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); + int16x4_t s0 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t0))); + int16x4_t s1 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t1))); + int16x4_t s2 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t2))); + int16x4_t s3 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t3))); + int16x4_t s4 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t0))); + int16x4_t s5 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t1))); + int16x4_t s6 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t2))); + src += 7; do { - load_u8_8x4(src, src_stride, &t0, &t1, &t2, &t3); - transpose_u8_8x4(&t0, &t1, &t2, &t3); - tt0 = vreinterpretq_s16_u16(vmovl_u8(t0)); - tt1 = vreinterpretq_s16_u16(vmovl_u8(t1)); - tt2 = vreinterpretq_s16_u16(vmovl_u8(t2)); - tt3 = vreinterpretq_s16_u16(vmovl_u8(t3)); - s7 = vget_low_s16(tt0); - s8 = vget_low_s16(tt1); - s9 = vget_low_s16(tt2); - s10 = vget_low_s16(tt3); + uint8x8_t t7, t8, t9, t10; + load_u8_8x4(src, src_stride, &t7, &t8, &t9, &t10); - d0 = convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filters, filter3, - filter4); - d1 = convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filters, filter3, - filter4); - d2 = convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filters, filter3, - filter4); - d3 = convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filters, filter3, - filter4); + transpose_u8_8x4(&t7, &t8, &t9, &t10); + int16x4_t s7 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t7))); + int16x4_t s8 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t8))); + int16x4_t s9 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t9))); + int16x4_t s10 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t10))); + + int16x4_t d0 = convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filter); + int16x4_t d1 = convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filter); + int16x4_t d2 = convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filter); + int16x4_t d3 = convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filter); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), FILTER_BITS); - d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), 7); - d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), 7); transpose_u8_4x4(&d01, &d23); - vst1_lane_u32((uint32_t *)(dst + 0 * dst_stride), - vreinterpret_u32_u8(d01), 0); - vst1_lane_u32((uint32_t *)(dst + 1 * dst_stride), - vreinterpret_u32_u8(d23), 0); - vst1_lane_u32((uint32_t *)(dst + 2 * dst_stride), - vreinterpret_u32_u8(d01), 1); - vst1_lane_u32((uint32_t *)(dst + 3 * dst_stride), - vreinterpret_u32_u8(d23), 1); + store_u8(dst + 0 * dst_stride, 2 * dst_stride, d01); + store_u8(dst + 1 * dst_stride, 2 * dst_stride, d23); s0 = s4; s1 = s5; @@ -883,144 +143,92 @@ void vpx_convolve8_horiz_neon(const uint8_t *src, ptrdiff_t src_stride, w -= 4; } while (w != 0); } else { - const int16x8_t filter3 = vdupq_lane_s16(vget_low_s16(filters), 3); - const int16x8_t filter4 = vdupq_lane_s16(vget_high_s16(filters), 0); - int width; - const uint8_t *s; - uint8x8_t t4, t5, t6, t7; - int16x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - if (w == 4) { do { + uint8x8_t t0, t1, t2, t3, t4, t5, t6, t7; load_u8_8x8(src, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); + transpose_u8_8x8(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); - s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); - s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); - s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); - s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); - s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); - s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); + int16x8_t s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); + int16x8_t s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); + int16x8_t s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); + int16x8_t s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); + int16x8_t s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); + int16x8_t s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); + int16x8_t s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); load_u8_8x8(src + 7, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - src += 8 * src_stride; - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(dst + 4 * dst_stride); - __builtin_prefetch(dst + 5 * dst_stride); - __builtin_prefetch(dst + 6 * dst_stride); - __builtin_prefetch(dst + 7 * dst_stride); + transpose_u8_4x8(&t0, &t1, &t2, &t3, t4, t5, t6, t7); - s7 = vreinterpretq_s16_u16(vmovl_u8(t0)); - s8 = vreinterpretq_s16_u16(vmovl_u8(t1)); - s9 = vreinterpretq_s16_u16(vmovl_u8(t2)); - s10 = vreinterpretq_s16_u16(vmovl_u8(t3)); + int16x8_t s7 = vreinterpretq_s16_u16(vmovl_u8(t0)); + int16x8_t s8 = vreinterpretq_s16_u16(vmovl_u8(t1)); + int16x8_t s9 = vreinterpretq_s16_u16(vmovl_u8(t2)); + int16x8_t s10 = vreinterpretq_s16_u16(vmovl_u8(t3)); - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - __builtin_prefetch(src + 7 * src_stride); - t0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, filter3, - filter4); - t1 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, filter3, - filter4); - t2 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, filter3, - filter4); - t3 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, filter3, - filter4); + uint8x8_t d04 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filter); + uint8x8_t d15 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filter); + uint8x8_t d26 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filter); + uint8x8_t d37 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filter); - transpose_u8_8x4(&t0, &t1, &t2, &t3); - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(t0), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(t1), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(t2), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(t3), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(t0), 1); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(t1), 1); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(t2), 1); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(t3), 1); - dst += dst_stride; + transpose_u8_8x4(&d04, &d15, &d26, &d37); + + store_u8(dst + 0 * dst_stride, 4 * dst_stride, d04); + store_u8(dst + 1 * dst_stride, 4 * dst_stride, d15); + store_u8(dst + 2 * dst_stride, 4 * dst_stride, d26); + store_u8(dst + 3 * dst_stride, 4 * dst_stride, d37); + + src += 8 * src_stride; + dst += 8 * dst_stride; h -= 8; } while (h > 0); } else { - uint8_t *d; - int16x8_t s11, s12, s13, s14; - do { - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - __builtin_prefetch(src + 7 * src_stride); + uint8x8_t t0, t1, t2, t3, t4, t5, t6, t7; load_u8_8x8(src, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - transpose_u8_8x8(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); - s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); - s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); - s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); - s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); - s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); - s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); - width = w; - s = src + 7; - d = dst; - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(dst + 4 * dst_stride); - __builtin_prefetch(dst + 5 * dst_stride); - __builtin_prefetch(dst + 6 * dst_stride); - __builtin_prefetch(dst + 7 * dst_stride); + transpose_u8_8x8(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); + int16x8_t s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); + int16x8_t s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); + int16x8_t s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); + int16x8_t s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); + int16x8_t s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); + int16x8_t s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); + int16x8_t s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); + + const uint8_t *s = src + 7; + uint8_t *d = dst; + int width = w; do { - load_u8_8x8(s, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - transpose_u8_8x8(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - s7 = vreinterpretq_s16_u16(vmovl_u8(t0)); - s8 = vreinterpretq_s16_u16(vmovl_u8(t1)); - s9 = vreinterpretq_s16_u16(vmovl_u8(t2)); - s10 = vreinterpretq_s16_u16(vmovl_u8(t3)); - s11 = vreinterpretq_s16_u16(vmovl_u8(t4)); - s12 = vreinterpretq_s16_u16(vmovl_u8(t5)); - s13 = vreinterpretq_s16_u16(vmovl_u8(t6)); - s14 = vreinterpretq_s16_u16(vmovl_u8(t7)); + uint8x8_t t8, t9, t10, t11, t12, t13, t14, t15; + load_u8_8x8(s, src_stride, &t8, &t9, &t10, &t11, &t12, &t13, &t14, + &t15); - t0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, filter3, - filter4); - t1 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, filter3, - filter4); - t2 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, filter3, - filter4); - t3 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, filter3, - filter4); - t4 = convolve8_8(s4, s5, s6, s7, s8, s9, s10, s11, filters, filter3, - filter4); - t5 = convolve8_8(s5, s6, s7, s8, s9, s10, s11, s12, filters, filter3, - filter4); - t6 = convolve8_8(s6, s7, s8, s9, s10, s11, s12, s13, filters, filter3, - filter4); - t7 = convolve8_8(s7, s8, s9, s10, s11, s12, s13, s14, filters, - filter3, filter4); + transpose_u8_8x8(&t8, &t9, &t10, &t11, &t12, &t13, &t14, &t15); + int16x8_t s7 = vreinterpretq_s16_u16(vmovl_u8(t8)); + int16x8_t s8 = vreinterpretq_s16_u16(vmovl_u8(t9)); + int16x8_t s9 = vreinterpretq_s16_u16(vmovl_u8(t10)); + int16x8_t s10 = vreinterpretq_s16_u16(vmovl_u8(t11)); + int16x8_t s11 = vreinterpretq_s16_u16(vmovl_u8(t12)); + int16x8_t s12 = vreinterpretq_s16_u16(vmovl_u8(t13)); + int16x8_t s13 = vreinterpretq_s16_u16(vmovl_u8(t14)); + int16x8_t s14 = vreinterpretq_s16_u16(vmovl_u8(t15)); - transpose_u8_8x8(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - store_u8_8x8(d, dst_stride, t0, t1, t2, t3, t4, t5, t6, t7); + uint8x8_t d0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filter); + uint8x8_t d1 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filter); + uint8x8_t d2 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filter); + uint8x8_t d3 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filter); + uint8x8_t d4 = convolve8_8(s4, s5, s6, s7, s8, s9, s10, s11, filter); + uint8x8_t d5 = convolve8_8(s5, s6, s7, s8, s9, s10, s11, s12, filter); + uint8x8_t d6 = + convolve8_8(s6, s7, s8, s9, s10, s11, s12, s13, filter); + uint8x8_t d7 = + convolve8_8(s7, s8, s9, s10, s11, s12, s13, s14, filter); + + transpose_u8_8x8(&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7); + + store_u8_8x8(d, dst_stride, d0, d1, d2, d3, d4, d5, d6, d7); s0 = s8; s1 = s9; @@ -1041,16 +249,39 @@ void vpx_convolve8_horiz_neon(const uint8_t *src, ptrdiff_t src_stride, } } +void vpx_convolve8_horiz_neon(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(x_step_q4 == 16); + + (void)x_step_q4; + (void)y0_q4; + (void)y_step_q4; + + const int16x8_t x_filter = vld1q_s16(filter[x0_q4]); + + if (vpx_get_filter_taps(filter[x0_q4]) <= 4) { + convolve_4tap_horiz_neon(src - 1, src_stride, dst, dst_stride, w, h, + x_filter); + } else { + convolve_8tap_horiz_neon(src - 3, src_stride, dst, dst_stride, w, h, + x_filter); + } +} + void vpx_convolve8_avg_horiz_neon(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h) { const int16x8_t filters = vld1q_s16(filter[x0_q4]); - uint8x8_t t0, t1, t2, t3; - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); assert(x_step_q4 == 16); (void)x_step_q4; @@ -1060,73 +291,47 @@ void vpx_convolve8_avg_horiz_neon(const uint8_t *src, ptrdiff_t src_stride, src -= 3; if (h == 4) { - uint8x8_t d01, d23; - int16x4_t filter3, filter4, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, d0, - d1, d2, d3; - int16x8_t tt0, tt1, tt2, tt3; - uint32x4_t d0123 = vdupq_n_u32(0); - - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - filter3 = vdup_lane_s16(vget_low_s16(filters), 3); - filter4 = vdup_lane_s16(vget_high_s16(filters), 0); + uint8x8_t t0, t1, t2, t3; load_u8_8x4(src, src_stride, &t0, &t1, &t2, &t3); + transpose_u8_8x4(&t0, &t1, &t2, &t3); - tt0 = vreinterpretq_s16_u16(vmovl_u8(t0)); - tt1 = vreinterpretq_s16_u16(vmovl_u8(t1)); - tt2 = vreinterpretq_s16_u16(vmovl_u8(t2)); - tt3 = vreinterpretq_s16_u16(vmovl_u8(t3)); - s0 = vget_low_s16(tt0); - s1 = vget_low_s16(tt1); - s2 = vget_low_s16(tt2); - s3 = vget_low_s16(tt3); - s4 = vget_high_s16(tt0); - s5 = vget_high_s16(tt1); - s6 = vget_high_s16(tt2); - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); + int16x4_t s0 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t0))); + int16x4_t s1 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t1))); + int16x4_t s2 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t2))); + int16x4_t s3 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t3))); + int16x4_t s4 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t0))); + int16x4_t s5 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t1))); + int16x4_t s6 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t2))); + src += 7; do { - load_u8_8x4(src, src_stride, &t0, &t1, &t2, &t3); - transpose_u8_8x4(&t0, &t1, &t2, &t3); - tt0 = vreinterpretq_s16_u16(vmovl_u8(t0)); - tt1 = vreinterpretq_s16_u16(vmovl_u8(t1)); - tt2 = vreinterpretq_s16_u16(vmovl_u8(t2)); - tt3 = vreinterpretq_s16_u16(vmovl_u8(t3)); - s7 = vget_low_s16(tt0); - s8 = vget_low_s16(tt1); - s9 = vget_low_s16(tt2); - s10 = vget_low_s16(tt3); + uint8x8_t t7, t8, t9, t10; + load_u8_8x4(src, src_stride, &t7, &t8, &t9, &t10); - d0 = convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filters, filter3, - filter4); - d1 = convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filters, filter3, - filter4); - d2 = convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filters, filter3, - filter4); - d3 = convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filters, filter3, - filter4); + transpose_u8_8x4(&t7, &t8, &t9, &t10); + int16x4_t s7 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t7))); + int16x4_t s8 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t8))); + int16x4_t s9 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t9))); + int16x4_t s10 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t10))); + + int16x4_t d0 = convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filters); + int16x4_t d1 = convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filters); + int16x4_t d2 = convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filters); + int16x4_t d3 = convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filters); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), FILTER_BITS); - d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), 7); - d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), 7); transpose_u8_4x4(&d01, &d23); - d0123 = vld1q_lane_u32((uint32_t *)(dst + 0 * dst_stride), d0123, 0); - d0123 = vld1q_lane_u32((uint32_t *)(dst + 1 * dst_stride), d0123, 2); - d0123 = vld1q_lane_u32((uint32_t *)(dst + 2 * dst_stride), d0123, 1); - d0123 = vld1q_lane_u32((uint32_t *)(dst + 3 * dst_stride), d0123, 3); - d0123 = vreinterpretq_u32_u8( - vrhaddq_u8(vreinterpretq_u8_u32(d0123), vcombine_u8(d01, d23))); + uint8x8_t dd01 = load_u8(dst + 0 * dst_stride, 2 * dst_stride); + uint8x8_t dd23 = load_u8(dst + 1 * dst_stride, 2 * dst_stride); - vst1q_lane_u32((uint32_t *)(dst + 0 * dst_stride), d0123, 0); - vst1q_lane_u32((uint32_t *)(dst + 1 * dst_stride), d0123, 2); - vst1q_lane_u32((uint32_t *)(dst + 2 * dst_stride), d0123, 1); - vst1q_lane_u32((uint32_t *)(dst + 3 * dst_stride), d0123, 3); + d01 = vrhadd_u8(d01, dd01); + d23 = vrhadd_u8(d23, dd23); + + store_u8(dst + 0 * dst_stride, 2 * dst_stride, d01); + store_u8(dst + 1 * dst_stride, 2 * dst_stride, d23); s0 = s4; s1 = s5; @@ -1140,177 +345,112 @@ void vpx_convolve8_avg_horiz_neon(const uint8_t *src, ptrdiff_t src_stride, w -= 4; } while (w != 0); } else { - const int16x8_t filter3 = vdupq_lane_s16(vget_low_s16(filters), 3); - const int16x8_t filter4 = vdupq_lane_s16(vget_high_s16(filters), 0); - int width; - const uint8_t *s; - uint8x8_t t4, t5, t6, t7; - int16x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - if (w == 4) { - uint32x4_t d0415 = vdupq_n_u32(0); - uint32x4_t d2637 = vdupq_n_u32(0); do { + uint8x8_t t0, t1, t2, t3, t4, t5, t6, t7; load_u8_8x8(src, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); + transpose_u8_8x8(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); - s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); - s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); - s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); - s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); - s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); - s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); + int16x8_t s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); + int16x8_t s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); + int16x8_t s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); + int16x8_t s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); + int16x8_t s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); + int16x8_t s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); + int16x8_t s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); load_u8_8x8(src + 7, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - src += 8 * src_stride; - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(dst + 4 * dst_stride); - __builtin_prefetch(dst + 5 * dst_stride); - __builtin_prefetch(dst + 6 * dst_stride); - __builtin_prefetch(dst + 7 * dst_stride); + transpose_u8_4x8(&t0, &t1, &t2, &t3, t4, t5, t6, t7); - s7 = vreinterpretq_s16_u16(vmovl_u8(t0)); - s8 = vreinterpretq_s16_u16(vmovl_u8(t1)); - s9 = vreinterpretq_s16_u16(vmovl_u8(t2)); - s10 = vreinterpretq_s16_u16(vmovl_u8(t3)); + int16x8_t s7 = vreinterpretq_s16_u16(vmovl_u8(t0)); + int16x8_t s8 = vreinterpretq_s16_u16(vmovl_u8(t1)); + int16x8_t s9 = vreinterpretq_s16_u16(vmovl_u8(t2)); + int16x8_t s10 = vreinterpretq_s16_u16(vmovl_u8(t3)); - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - __builtin_prefetch(src + 7 * src_stride); - t0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, filter3, - filter4); - t1 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, filter3, - filter4); - t2 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, filter3, - filter4); - t3 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, filter3, - filter4); + uint8x8_t d04 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters); + uint8x8_t d15 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters); + uint8x8_t d26 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters); + uint8x8_t d37 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters); - transpose_u8_8x4(&t0, &t1, &t2, &t3); + transpose_u8_8x4(&d04, &d15, &d26, &d37); - d0415 = vld1q_lane_u32((uint32_t *)(dst + 0 * dst_stride), d0415, 0); - d0415 = vld1q_lane_u32((uint32_t *)(dst + 1 * dst_stride), d0415, 2); - d2637 = vld1q_lane_u32((uint32_t *)(dst + 2 * dst_stride), d2637, 0); - d2637 = vld1q_lane_u32((uint32_t *)(dst + 3 * dst_stride), d2637, 2); - d0415 = vld1q_lane_u32((uint32_t *)(dst + 4 * dst_stride), d0415, 1); - d0415 = vld1q_lane_u32((uint32_t *)(dst + 5 * dst_stride), d0415, 3); - d2637 = vld1q_lane_u32((uint32_t *)(dst + 6 * dst_stride), d2637, 1); - d2637 = vld1q_lane_u32((uint32_t *)(dst + 7 * dst_stride), d2637, 3); - d0415 = vreinterpretq_u32_u8( - vrhaddq_u8(vreinterpretq_u8_u32(d0415), vcombine_u8(t0, t1))); - d2637 = vreinterpretq_u32_u8( - vrhaddq_u8(vreinterpretq_u8_u32(d2637), vcombine_u8(t2, t3))); + uint8x8_t dd04 = load_u8(dst + 0 * dst_stride, 4 * dst_stride); + uint8x8_t dd15 = load_u8(dst + 1 * dst_stride, 4 * dst_stride); + uint8x8_t dd26 = load_u8(dst + 2 * dst_stride, 4 * dst_stride); + uint8x8_t dd37 = load_u8(dst + 3 * dst_stride, 4 * dst_stride); - vst1q_lane_u32((uint32_t *)dst, d0415, 0); - dst += dst_stride; - vst1q_lane_u32((uint32_t *)dst, d0415, 2); - dst += dst_stride; - vst1q_lane_u32((uint32_t *)dst, d2637, 0); - dst += dst_stride; - vst1q_lane_u32((uint32_t *)dst, d2637, 2); - dst += dst_stride; - vst1q_lane_u32((uint32_t *)dst, d0415, 1); - dst += dst_stride; - vst1q_lane_u32((uint32_t *)dst, d0415, 3); - dst += dst_stride; - vst1q_lane_u32((uint32_t *)dst, d2637, 1); - dst += dst_stride; - vst1q_lane_u32((uint32_t *)dst, d2637, 3); - dst += dst_stride; + d04 = vrhadd_u8(d04, dd04); + d15 = vrhadd_u8(d15, dd15); + d26 = vrhadd_u8(d26, dd26); + d37 = vrhadd_u8(d37, dd37); + + store_u8(dst + 0 * dst_stride, 4 * dst_stride, d04); + store_u8(dst + 1 * dst_stride, 4 * dst_stride, d15); + store_u8(dst + 2 * dst_stride, 4 * dst_stride, d26); + store_u8(dst + 3 * dst_stride, 4 * dst_stride, d37); + + src += 8 * src_stride; + dst += 8 * dst_stride; h -= 8; - } while (h > 0); + } while (h != 0); } else { - uint8_t *d; - int16x8_t s11, s12, s13, s14; - uint8x16_t d01, d23, d45, d67; - do { - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - __builtin_prefetch(src + 7 * src_stride); + uint8x8_t t0, t1, t2, t3, t4, t5, t6, t7; load_u8_8x8(src, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - transpose_u8_8x8(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); - s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); - s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); - s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); - s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); - s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); - s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); - width = w; - s = src + 7; - d = dst; - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(dst + 4 * dst_stride); - __builtin_prefetch(dst + 5 * dst_stride); - __builtin_prefetch(dst + 6 * dst_stride); - __builtin_prefetch(dst + 7 * dst_stride); + transpose_u8_8x8(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); + int16x8_t s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); + int16x8_t s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); + int16x8_t s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); + int16x8_t s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); + int16x8_t s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); + int16x8_t s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); + int16x8_t s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); + + const uint8_t *s = src + 7; + uint8_t *d = dst; + int width = w; do { - load_u8_8x8(s, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - transpose_u8_8x8(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); - s7 = vreinterpretq_s16_u16(vmovl_u8(t0)); - s8 = vreinterpretq_s16_u16(vmovl_u8(t1)); - s9 = vreinterpretq_s16_u16(vmovl_u8(t2)); - s10 = vreinterpretq_s16_u16(vmovl_u8(t3)); - s11 = vreinterpretq_s16_u16(vmovl_u8(t4)); - s12 = vreinterpretq_s16_u16(vmovl_u8(t5)); - s13 = vreinterpretq_s16_u16(vmovl_u8(t6)); - s14 = vreinterpretq_s16_u16(vmovl_u8(t7)); + uint8x8_t t8, t9, t10, t11, t12, t13, t14, t15; + load_u8_8x8(s, src_stride, &t8, &t9, &t10, &t11, &t12, &t13, &t14, + &t15); - t0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, filter3, - filter4); - t1 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, filter3, - filter4); - t2 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, filter3, - filter4); - t3 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, filter3, - filter4); - t4 = convolve8_8(s4, s5, s6, s7, s8, s9, s10, s11, filters, filter3, - filter4); - t5 = convolve8_8(s5, s6, s7, s8, s9, s10, s11, s12, filters, filter3, - filter4); - t6 = convolve8_8(s6, s7, s8, s9, s10, s11, s12, s13, filters, filter3, - filter4); - t7 = convolve8_8(s7, s8, s9, s10, s11, s12, s13, s14, filters, - filter3, filter4); + transpose_u8_8x8(&t8, &t9, &t10, &t11, &t12, &t13, &t14, &t15); + int16x8_t s7 = vreinterpretq_s16_u16(vmovl_u8(t8)); + int16x8_t s8 = vreinterpretq_s16_u16(vmovl_u8(t9)); + int16x8_t s9 = vreinterpretq_s16_u16(vmovl_u8(t10)); + int16x8_t s10 = vreinterpretq_s16_u16(vmovl_u8(t11)); + int16x8_t s11 = vreinterpretq_s16_u16(vmovl_u8(t12)); + int16x8_t s12 = vreinterpretq_s16_u16(vmovl_u8(t13)); + int16x8_t s13 = vreinterpretq_s16_u16(vmovl_u8(t14)); + int16x8_t s14 = vreinterpretq_s16_u16(vmovl_u8(t15)); - transpose_u8_8x8(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); + uint8x8_t d0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters); + uint8x8_t d1 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters); + uint8x8_t d2 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters); + uint8x8_t d3 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters); + uint8x8_t d4 = convolve8_8(s4, s5, s6, s7, s8, s9, s10, s11, filters); + uint8x8_t d5 = + convolve8_8(s5, s6, s7, s8, s9, s10, s11, s12, filters); + uint8x8_t d6 = + convolve8_8(s6, s7, s8, s9, s10, s11, s12, s13, filters); + uint8x8_t d7 = + convolve8_8(s7, s8, s9, s10, s11, s12, s13, s14, filters); - d01 = vcombine_u8(vld1_u8(d + 0 * dst_stride), - vld1_u8(d + 1 * dst_stride)); - d23 = vcombine_u8(vld1_u8(d + 2 * dst_stride), - vld1_u8(d + 3 * dst_stride)); - d45 = vcombine_u8(vld1_u8(d + 4 * dst_stride), - vld1_u8(d + 5 * dst_stride)); - d67 = vcombine_u8(vld1_u8(d + 6 * dst_stride), - vld1_u8(d + 7 * dst_stride)); - d01 = vrhaddq_u8(d01, vcombine_u8(t0, t1)); - d23 = vrhaddq_u8(d23, vcombine_u8(t2, t3)); - d45 = vrhaddq_u8(d45, vcombine_u8(t4, t5)); - d67 = vrhaddq_u8(d67, vcombine_u8(t6, t7)); + transpose_u8_8x8(&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7); - store_u8_8x8(d, dst_stride, vget_low_u8(d01), vget_high_u8(d01), - vget_low_u8(d23), vget_high_u8(d23), vget_low_u8(d45), - vget_high_u8(d45), vget_low_u8(d67), vget_high_u8(d67)); + d0 = vrhadd_u8(d0, vld1_u8(d + 0 * dst_stride)); + d1 = vrhadd_u8(d1, vld1_u8(d + 1 * dst_stride)); + d2 = vrhadd_u8(d2, vld1_u8(d + 2 * dst_stride)); + d3 = vrhadd_u8(d3, vld1_u8(d + 3 * dst_stride)); + d4 = vrhadd_u8(d4, vld1_u8(d + 4 * dst_stride)); + d5 = vrhadd_u8(d5, vld1_u8(d + 5 * dst_stride)); + d6 = vrhadd_u8(d6, vld1_u8(d + 6 * dst_stride)); + d7 = vrhadd_u8(d7, vld1_u8(d + 7 * dst_stride)); + + store_u8_8x8(d, dst_stride, d0, d1, d2, d3, d4, d5, d6, d7); s0 = s8; s1 = s9; @@ -1326,86 +466,45 @@ void vpx_convolve8_avg_horiz_neon(const uint8_t *src, ptrdiff_t src_stride, src += 8 * src_stride; dst += 8 * dst_stride; h -= 8; - } while (h > 0); + } while (h != 0); } } } -void vpx_convolve8_vert_neon(const uint8_t *src, ptrdiff_t src_stride, - uint8_t *dst, ptrdiff_t dst_stride, - const InterpKernel *filter, int x0_q4, - int x_step_q4, int y0_q4, int y_step_q4, int w, - int h) { - const int16x8_t filters = vld1q_s16(filter[y0_q4]); - - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); - assert(y_step_q4 == 16); - - (void)x0_q4; - (void)x_step_q4; - (void)y_step_q4; - - src -= 3 * src_stride; - +static INLINE void convolve_8tap_vert_neon(const uint8_t *src, + ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, int w, int h, + const int16x8_t filter) { if (w == 4) { - const int16x4_t filter3 = vdup_lane_s16(vget_low_s16(filters), 3); - const int16x4_t filter4 = vdup_lane_s16(vget_high_s16(filters), 0); - uint8x8_t d01, d23; - int16x4_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, d0, d1, d2, d3; + uint8x8_t t0, t1, t2, t3, t4, t5, t6; + load_u8_8x7(src, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6); + int16x4_t s0 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t0))); + int16x4_t s1 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t1))); + int16x4_t s2 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t2))); + int16x4_t s3 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t3))); + int16x4_t s4 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t4))); + int16x4_t s5 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t5))); + int16x4_t s6 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t6))); - s0 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s1 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s2 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s3 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s4 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s5 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s6 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; + src += 7 * src_stride; do { - s7 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s8 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s9 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s10 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; + uint8x8_t t7, t8, t9, t10; + load_u8_8x4(src, src_stride, &t7, &t8, &t9, &t10); + int16x4_t s7 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t7))); + int16x4_t s8 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t8))); + int16x4_t s9 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t9))); + int16x4_t s10 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t10))); - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - d0 = convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filters, filter3, - filter4); - d1 = convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filters, filter3, - filter4); - d2 = convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filters, filter3, - filter4); - d3 = convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filters, filter3, - filter4); + int16x4_t d0 = convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filter); + int16x4_t d1 = convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filter); + int16x4_t d2 = convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filter); + int16x4_t d3 = convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filter); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), FILTER_BITS); - d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), 7); - d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), 7); - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d01), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d01), 1); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d23), 0); - dst += dst_stride; - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d23), 1); - dst += dst_stride; + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); s0 = s4; s1 = s5; @@ -1414,78 +513,40 @@ void vpx_convolve8_vert_neon(const uint8_t *src, ptrdiff_t src_stride, s4 = s8; s5 = s9; s6 = s10; + src += 4 * src_stride; + dst += 4 * dst_stride; h -= 4; } while (h != 0); } else { - const int16x8_t filter3 = vdupq_lane_s16(vget_low_s16(filters), 3); - const int16x8_t filter4 = vdupq_lane_s16(vget_high_s16(filters), 0); - int height; - const uint8_t *s; - uint8_t *d; - uint8x8_t t0, t1, t2, t3; - int16x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - do { - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - s = src; - s0 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s1 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s2 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s3 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s4 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s5 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s6 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - d = dst; - height = h; + uint8x8_t t0, t1, t2, t3, t4, t5, t6; + load_u8_8x7(src, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6); + int16x8_t s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); + int16x8_t s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); + int16x8_t s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); + int16x8_t s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); + int16x8_t s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); + int16x8_t s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); + int16x8_t s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); + + const uint8_t *s = src + 7 * src_stride; + uint8_t *d = dst; + int height = h; do { - s7 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s8 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s9 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s10 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; + uint8x8_t t7, t8, t9, t10; + load_u8_8x4(s, src_stride, &t7, &t8, &t9, &t10); + int16x8_t s7 = vreinterpretq_s16_u16(vmovl_u8(t7)); + int16x8_t s8 = vreinterpretq_s16_u16(vmovl_u8(t8)); + int16x8_t s9 = vreinterpretq_s16_u16(vmovl_u8(t9)); + int16x8_t s10 = vreinterpretq_s16_u16(vmovl_u8(t10)); - __builtin_prefetch(d + 0 * dst_stride); - __builtin_prefetch(d + 1 * dst_stride); - __builtin_prefetch(d + 2 * dst_stride); - __builtin_prefetch(d + 3 * dst_stride); - __builtin_prefetch(s + 0 * src_stride); - __builtin_prefetch(s + 1 * src_stride); - __builtin_prefetch(s + 2 * src_stride); - __builtin_prefetch(s + 3 * src_stride); - t0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, filter3, - filter4); - t1 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, filter3, - filter4); - t2 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, filter3, - filter4); - t3 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, filter3, - filter4); + uint8x8_t d0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filter); + uint8x8_t d1 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filter); + uint8x8_t d2 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filter); + uint8x8_t d3 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filter); - vst1_u8(d, t0); - d += dst_stride; - vst1_u8(d, t1); - d += dst_stride; - vst1_u8(d, t2); - d += dst_stride; - vst1_u8(d, t3); - d += dst_stride; + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); s0 = s4; s1 = s5; @@ -1494,6 +555,8 @@ void vpx_convolve8_vert_neon(const uint8_t *src, ptrdiff_t src_stride, s4 = s8; s5 = s9; s6 = s10; + s += 4 * src_stride; + d += 4 * dst_stride; height -= 4; } while (height != 0); src += 8; @@ -1503,6 +566,30 @@ void vpx_convolve8_vert_neon(const uint8_t *src, ptrdiff_t src_stride, } } +void vpx_convolve8_vert_neon(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(y_step_q4 == 16); + + (void)x0_q4; + (void)x_step_q4; + (void)y_step_q4; + + const int16x8_t y_filter = vld1q_s16(filter[y0_q4]); + + if (vpx_get_filter_taps(filter[y0_q4]) <= 4) { + convolve_4tap_vert_neon(src - src_stride, src_stride, dst, dst_stride, w, h, + y_filter); + } else { + convolve_8tap_vert_neon(src - 3 * src_stride, src_stride, dst, dst_stride, + w, h, y_filter); + } +} + void vpx_convolve8_avg_vert_neon(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel *filter, int x0_q4, @@ -1510,8 +597,8 @@ void vpx_convolve8_avg_vert_neon(const uint8_t *src, ptrdiff_t src_stride, int h) { const int16x8_t filters = vld1q_s16(filter[y0_q4]); - assert(!((intptr_t)dst & 3)); - assert(!(dst_stride & 3)); + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); assert(y_step_q4 == 16); (void)x0_q4; @@ -1521,72 +608,41 @@ void vpx_convolve8_avg_vert_neon(const uint8_t *src, ptrdiff_t src_stride, src -= 3 * src_stride; if (w == 4) { - const int16x4_t filter3 = vdup_lane_s16(vget_low_s16(filters), 3); - const int16x4_t filter4 = vdup_lane_s16(vget_high_s16(filters), 0); - uint8x8_t d01, d23; - int16x4_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, d0, d1, d2, d3; - uint32x4_t d0123 = vdupq_n_u32(0); + uint8x8_t t0, t1, t2, t3, t4, t5, t6; + load_u8_8x7(src, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6); + int16x4_t s0 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t0))); + int16x4_t s1 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t1))); + int16x4_t s2 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t2))); + int16x4_t s3 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t3))); + int16x4_t s4 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t4))); + int16x4_t s5 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t5))); + int16x4_t s6 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t6))); - s0 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s1 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s2 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s3 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s4 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s5 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s6 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; + src += 7 * src_stride; do { - s7 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s8 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s9 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; - s10 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(vld1_u8(src)))); - src += src_stride; + uint8x8_t t7, t8, t9, t10; + load_u8_8x4(src, src_stride, &t7, &t8, &t9, &t10); + int16x4_t s7 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t7))); + int16x4_t s8 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t8))); + int16x4_t s9 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t9))); + int16x4_t s10 = vreinterpret_s16_u16(vget_low_u16(vmovl_u8(t10))); - __builtin_prefetch(dst + 0 * dst_stride); - __builtin_prefetch(dst + 1 * dst_stride); - __builtin_prefetch(dst + 2 * dst_stride); - __builtin_prefetch(dst + 3 * dst_stride); - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - d0 = convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filters, filter3, - filter4); - d1 = convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filters, filter3, - filter4); - d2 = convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filters, filter3, - filter4); - d3 = convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filters, filter3, - filter4); + int16x4_t d0 = convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filters); + int16x4_t d1 = convolve8_4(s1, s2, s3, s4, s5, s6, s7, s8, filters); + int16x4_t d2 = convolve8_4(s2, s3, s4, s5, s6, s7, s8, s9, filters); + int16x4_t d3 = convolve8_4(s3, s4, s5, s6, s7, s8, s9, s10, filters); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), FILTER_BITS); - d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), 7); - d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), 7); + uint8x8_t dd01 = load_u8(dst + 0 * dst_stride, dst_stride); + uint8x8_t dd23 = load_u8(dst + 2 * dst_stride, dst_stride); - d0123 = vld1q_lane_u32((uint32_t *)(dst + 0 * dst_stride), d0123, 0); - d0123 = vld1q_lane_u32((uint32_t *)(dst + 1 * dst_stride), d0123, 1); - d0123 = vld1q_lane_u32((uint32_t *)(dst + 2 * dst_stride), d0123, 2); - d0123 = vld1q_lane_u32((uint32_t *)(dst + 3 * dst_stride), d0123, 3); - d0123 = vreinterpretq_u32_u8( - vrhaddq_u8(vreinterpretq_u8_u32(d0123), vcombine_u8(d01, d23))); + d01 = vrhadd_u8(d01, dd01); + d23 = vrhadd_u8(d23, dd23); - vst1q_lane_u32((uint32_t *)dst, d0123, 0); - dst += dst_stride; - vst1q_lane_u32((uint32_t *)dst, d0123, 1); - dst += dst_stride; - vst1q_lane_u32((uint32_t *)dst, d0123, 2); - dst += dst_stride; - vst1q_lane_u32((uint32_t *)dst, d0123, 3); - dst += dst_stride; + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); s0 = s4; s1 = s5; @@ -1595,88 +651,45 @@ void vpx_convolve8_avg_vert_neon(const uint8_t *src, ptrdiff_t src_stride, s4 = s8; s5 = s9; s6 = s10; + src += 4 * src_stride; + dst += 4 * dst_stride; h -= 4; } while (h != 0); } else { - const int16x8_t filter3 = vdupq_lane_s16(vget_low_s16(filters), 3); - const int16x8_t filter4 = vdupq_lane_s16(vget_high_s16(filters), 0); - int height; - const uint8_t *s; - uint8_t *d; - uint8x8_t t0, t1, t2, t3; - uint8x16_t d01, d23, dd01, dd23; - int16x8_t s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; - do { - __builtin_prefetch(src + 0 * src_stride); - __builtin_prefetch(src + 1 * src_stride); - __builtin_prefetch(src + 2 * src_stride); - __builtin_prefetch(src + 3 * src_stride); - __builtin_prefetch(src + 4 * src_stride); - __builtin_prefetch(src + 5 * src_stride); - __builtin_prefetch(src + 6 * src_stride); - s = src; - s0 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s1 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s2 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s3 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s4 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s5 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s6 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - d = dst; - height = h; + uint8x8_t t0, t1, t2, t3, t4, t5, t6; + load_u8_8x7(src, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6); + int16x8_t s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); + int16x8_t s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); + int16x8_t s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); + int16x8_t s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); + int16x8_t s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); + int16x8_t s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); + int16x8_t s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); + + const uint8_t *s = src + 7 * src_stride; + uint8_t *d = dst; + int height = h; do { - s7 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s8 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s9 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; - s10 = vreinterpretq_s16_u16(vmovl_u8(vld1_u8(s))); - s += src_stride; + uint8x8_t t7, t8, t9, t10; + load_u8_8x4(s, src_stride, &t7, &t8, &t9, &t10); + int16x8_t s7 = vreinterpretq_s16_u16(vmovl_u8(t7)); + int16x8_t s8 = vreinterpretq_s16_u16(vmovl_u8(t8)); + int16x8_t s9 = vreinterpretq_s16_u16(vmovl_u8(t9)); + int16x8_t s10 = vreinterpretq_s16_u16(vmovl_u8(t10)); - __builtin_prefetch(d + 0 * dst_stride); - __builtin_prefetch(d + 1 * dst_stride); - __builtin_prefetch(d + 2 * dst_stride); - __builtin_prefetch(d + 3 * dst_stride); - __builtin_prefetch(s + 0 * src_stride); - __builtin_prefetch(s + 1 * src_stride); - __builtin_prefetch(s + 2 * src_stride); - __builtin_prefetch(s + 3 * src_stride); - t0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters, filter3, - filter4); - t1 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters, filter3, - filter4); - t2 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters, filter3, - filter4); - t3 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters, filter3, - filter4); + uint8x8_t d0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filters); + uint8x8_t d1 = convolve8_8(s1, s2, s3, s4, s5, s6, s7, s8, filters); + uint8x8_t d2 = convolve8_8(s2, s3, s4, s5, s6, s7, s8, s9, filters); + uint8x8_t d3 = convolve8_8(s3, s4, s5, s6, s7, s8, s9, s10, filters); - d01 = vcombine_u8(t0, t1); - d23 = vcombine_u8(t2, t3); - dd01 = vcombine_u8(vld1_u8(d + 0 * dst_stride), - vld1_u8(d + 1 * dst_stride)); - dd23 = vcombine_u8(vld1_u8(d + 2 * dst_stride), - vld1_u8(d + 3 * dst_stride)); - dd01 = vrhaddq_u8(dd01, d01); - dd23 = vrhaddq_u8(dd23, d23); + d0 = vrhadd_u8(d0, vld1_u8(d + 0 * dst_stride)); + d1 = vrhadd_u8(d1, vld1_u8(d + 1 * dst_stride)); + d2 = vrhadd_u8(d2, vld1_u8(d + 2 * dst_stride)); + d3 = vrhadd_u8(d3, vld1_u8(d + 3 * dst_stride)); - vst1_u8(d, vget_low_u8(dd01)); - d += dst_stride; - vst1_u8(d, vget_high_u8(dd01)); - d += dst_stride; - vst1_u8(d, vget_low_u8(dd23)); - d += dst_stride; - vst1_u8(d, vget_high_u8(dd23)); - d += dst_stride; + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); s0 = s4; s1 = s5; @@ -1686,6 +699,8 @@ void vpx_convolve8_avg_vert_neon(const uint8_t *src, ptrdiff_t src_stride, s5 = s9; s6 = s10; height -= 4; + s += 4 * src_stride; + d += 4 * dst_stride; } while (height != 0); src += 8; dst += 8; @@ -1693,5 +708,3 @@ void vpx_convolve8_avg_vert_neon(const uint8_t *src, ptrdiff_t src_stride, } while (w != 0); } } - -#endif diff --git a/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon.h b/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon.h index 857b6d54e2..10cc761ccd 100644 --- a/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon.h +++ b/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon.h @@ -15,171 +15,13 @@ #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" - -static INLINE void load_u8_8x4(const uint8_t *s, const ptrdiff_t p, - uint8x8_t *const s0, uint8x8_t *const s1, - uint8x8_t *const s2, uint8x8_t *const s3) { - *s0 = vld1_u8(s); - s += p; - *s1 = vld1_u8(s); - s += p; - *s2 = vld1_u8(s); - s += p; - *s3 = vld1_u8(s); -} - -static INLINE void load_u8_8x8(const uint8_t *s, const ptrdiff_t p, - uint8x8_t *const s0, uint8x8_t *const s1, - uint8x8_t *const s2, uint8x8_t *const s3, - uint8x8_t *const s4, uint8x8_t *const s5, - uint8x8_t *const s6, uint8x8_t *const s7) { - *s0 = vld1_u8(s); - s += p; - *s1 = vld1_u8(s); - s += p; - *s2 = vld1_u8(s); - s += p; - *s3 = vld1_u8(s); - s += p; - *s4 = vld1_u8(s); - s += p; - *s5 = vld1_u8(s); - s += p; - *s6 = vld1_u8(s); - s += p; - *s7 = vld1_u8(s); -} - -static INLINE void load_u8_16x8(const uint8_t *s, const ptrdiff_t p, - uint8x16_t *const s0, uint8x16_t *const s1, - uint8x16_t *const s2, uint8x16_t *const s3, - uint8x16_t *const s4, uint8x16_t *const s5, - uint8x16_t *const s6, uint8x16_t *const s7) { - *s0 = vld1q_u8(s); - s += p; - *s1 = vld1q_u8(s); - s += p; - *s2 = vld1q_u8(s); - s += p; - *s3 = vld1q_u8(s); - s += p; - *s4 = vld1q_u8(s); - s += p; - *s5 = vld1q_u8(s); - s += p; - *s6 = vld1q_u8(s); - s += p; - *s7 = vld1q_u8(s); -} - -#if defined(__aarch64__) && defined(__ARM_FEATURE_DOTPROD) && \ - (__ARM_FEATURE_DOTPROD == 1) - -static INLINE int32x4_t convolve8_4_dot_partial(const int8x16_t samples_lo, - const int8x16_t samples_hi, - const int32x4_t correction, - const int8x8_t filters) { - /* Sample range-clamping and permutation are performed by the caller. */ - int32x4_t sum; - - /* Accumulate dot product into 'correction' to account for range clamp. */ - sum = vdotq_lane_s32(correction, samples_lo, filters, 0); - sum = vdotq_lane_s32(sum, samples_hi, filters, 1); - - /* Narrowing and packing is performed by the caller. */ - return sum; -} - -static INLINE int32x4_t convolve8_4_dot(uint8x16_t samples, - const int8x8_t filters, - const int32x4_t correction, - const uint8x16_t range_limit, - const uint8x16x2_t permute_tbl) { - int8x16_t clamped_samples, permuted_samples[2]; - int32x4_t sum; - - /* Clamp sample range to [-128, 127] for 8-bit signed dot product. */ - clamped_samples = vreinterpretq_s8_u8(vsubq_u8(samples, range_limit)); - - /* Permute samples ready for dot product. */ - /* { 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6 } */ - permuted_samples[0] = vqtbl1q_s8(clamped_samples, permute_tbl.val[0]); - /* { 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10 } */ - permuted_samples[1] = vqtbl1q_s8(clamped_samples, permute_tbl.val[1]); - - /* Accumulate dot product into 'correction' to account for range clamp. */ - sum = vdotq_lane_s32(correction, permuted_samples[0], filters, 0); - sum = vdotq_lane_s32(sum, permuted_samples[1], filters, 1); - - /* Narrowing and packing is performed by the caller. */ - return sum; -} - -static INLINE uint8x8_t convolve8_8_dot_partial(const int8x16_t samples0_lo, - const int8x16_t samples0_hi, - const int8x16_t samples1_lo, - const int8x16_t samples1_hi, - const int32x4_t correction, - const int8x8_t filters) { - /* Sample range-clamping and permutation are performed by the caller. */ - int32x4_t sum0, sum1; - int16x8_t sum; - - /* Accumulate dot product into 'correction' to account for range clamp. */ - /* First 4 output values. */ - sum0 = vdotq_lane_s32(correction, samples0_lo, filters, 0); - sum0 = vdotq_lane_s32(sum0, samples0_hi, filters, 1); - /* Second 4 output values. */ - sum1 = vdotq_lane_s32(correction, samples1_lo, filters, 0); - sum1 = vdotq_lane_s32(sum1, samples1_hi, filters, 1); - - /* Narrow and re-pack. */ - sum = vcombine_s16(vqmovn_s32(sum0), vqmovn_s32(sum1)); - return vqrshrun_n_s16(sum, 7); -} - -static INLINE uint8x8_t convolve8_8_dot(uint8x16_t samples, - const int8x8_t filters, - const int32x4_t correction, - const uint8x16_t range_limit, - const uint8x16x3_t permute_tbl) { - int8x16_t clamped_samples, permuted_samples[3]; - int32x4_t sum0, sum1; - int16x8_t sum; - - /* Clamp sample range to [-128, 127] for 8-bit signed dot product. */ - clamped_samples = vreinterpretq_s8_u8(vsubq_u8(samples, range_limit)); - - /* Permute samples ready for dot product. */ - /* { 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6 } */ - permuted_samples[0] = vqtbl1q_s8(clamped_samples, permute_tbl.val[0]); - /* { 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10 } */ - permuted_samples[1] = vqtbl1q_s8(clamped_samples, permute_tbl.val[1]); - /* { 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14 } */ - permuted_samples[2] = vqtbl1q_s8(clamped_samples, permute_tbl.val[2]); - - /* Accumulate dot product into 'correction' to account for range clamp. */ - /* First 4 output values. */ - sum0 = vdotq_lane_s32(correction, permuted_samples[0], filters, 0); - sum0 = vdotq_lane_s32(sum0, permuted_samples[1], filters, 1); - /* Second 4 output values. */ - sum1 = vdotq_lane_s32(correction, permuted_samples[1], filters, 0); - sum1 = vdotq_lane_s32(sum1, permuted_samples[2], filters, 1); - - /* Narrow and re-pack. */ - sum = vcombine_s16(vqmovn_s32(sum0), vqmovn_s32(sum1)); - return vqrshrun_n_s16(sum, 7); -} - -#endif +#include "vpx_dsp/vpx_filter.h" static INLINE int16x4_t convolve8_4(const int16x4_t s0, const int16x4_t s1, const int16x4_t s2, const int16x4_t s3, const int16x4_t s4, const int16x4_t s5, const int16x4_t s6, const int16x4_t s7, - const int16x8_t filters, - const int16x4_t filter3, - const int16x4_t filter4) { + const int16x8_t filters) { const int16x4_t filters_lo = vget_low_s16(filters); const int16x4_t filters_hi = vget_high_s16(filters); int16x4_t sum; @@ -190,8 +32,8 @@ static INLINE int16x4_t convolve8_4(const int16x4_t s0, const int16x4_t s1, sum = vmla_lane_s16(sum, s5, filters_hi, 1); sum = vmla_lane_s16(sum, s6, filters_hi, 2); sum = vmla_lane_s16(sum, s7, filters_hi, 3); - sum = vqadd_s16(sum, vmul_s16(s3, filter3)); - sum = vqadd_s16(sum, vmul_s16(s4, filter4)); + sum = vqadd_s16(sum, vmul_lane_s16(s3, filters_lo, 3)); + sum = vqadd_s16(sum, vmul_lane_s16(s4, filters_hi, 0)); return sum; } @@ -199,9 +41,7 @@ static INLINE uint8x8_t convolve8_8(const int16x8_t s0, const int16x8_t s1, const int16x8_t s2, const int16x8_t s3, const int16x8_t s4, const int16x8_t s5, const int16x8_t s6, const int16x8_t s7, - const int16x8_t filters, - const int16x8_t filter3, - const int16x8_t filter4) { + const int16x8_t filters) { const int16x4_t filters_lo = vget_low_s16(filters); const int16x4_t filters_hi = vget_high_s16(filters); int16x8_t sum; @@ -212,15 +52,13 @@ static INLINE uint8x8_t convolve8_8(const int16x8_t s0, const int16x8_t s1, sum = vmlaq_lane_s16(sum, s5, filters_hi, 1); sum = vmlaq_lane_s16(sum, s6, filters_hi, 2); sum = vmlaq_lane_s16(sum, s7, filters_hi, 3); - sum = vqaddq_s16(sum, vmulq_s16(s3, filter3)); - sum = vqaddq_s16(sum, vmulq_s16(s4, filter4)); - return vqrshrun_n_s16(sum, 7); + sum = vqaddq_s16(sum, vmulq_lane_s16(s3, filters_lo, 3)); + sum = vqaddq_s16(sum, vmulq_lane_s16(s4, filters_hi, 0)); + return vqrshrun_n_s16(sum, FILTER_BITS); } static INLINE uint8x8_t scale_filter_8(const uint8x8_t *const s, const int16x8_t filters) { - const int16x8_t filter3 = vdupq_lane_s16(vget_low_s16(filters), 3); - const int16x8_t filter4 = vdupq_lane_s16(vget_high_s16(filters), 0); int16x8_t ss[8]; ss[0] = vreinterpretq_s16_u16(vmovl_u8(s[0])); @@ -233,7 +71,102 @@ static INLINE uint8x8_t scale_filter_8(const uint8x8_t *const s, ss[7] = vreinterpretq_s16_u16(vmovl_u8(s[7])); return convolve8_8(ss[0], ss[1], ss[2], ss[3], ss[4], ss[5], ss[6], ss[7], - filters, filter3, filter4); + filters); +} + +// 2-tap (bilinear) filter values are always positive, but 4-tap filter values +// are negative on the outer edges (taps 0 and 3), with taps 1 and 2 having much +// greater positive values to compensate. To use instructions that operate on +// 8-bit types we also need the types to be unsigned. Subtracting the products +// of taps 0 and 3 from the products of taps 1 and 2 always works given that +// 2-tap filters are 0-padded. +static INLINE uint8x8_t convolve4_8(const uint8x8_t s0, const uint8x8_t s1, + const uint8x8_t s2, const uint8x8_t s3, + const uint8x8_t filter_taps[4]) { + uint16x8_t sum = vmull_u8(s1, filter_taps[1]); + sum = vmlal_u8(sum, s2, filter_taps[2]); + sum = vmlsl_u8(sum, s0, filter_taps[0]); + sum = vmlsl_u8(sum, s3, filter_taps[3]); + // We halved the filter values so -1 from right shift. + return vqrshrun_n_s16(vreinterpretq_s16_u16(sum), FILTER_BITS - 1); +} + +static INLINE void convolve_4tap_vert_neon(const uint8_t *src, + ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, int w, int h, + const int16x8_t filter) { + // 4-tap and bilinear filter values are even, so halve them to reduce + // intermediate precision requirements. + const uint8x8_t y_filter = + vshrn_n_u16(vreinterpretq_u16_s16(vabsq_s16(filter)), 1); + + // Neon does not have lane-referencing multiply or multiply-accumulate + // instructions that operate on vectors of 8-bit elements. This means we have + // to duplicate filter taps into a whole vector and use standard multiply / + // multiply-accumulate instructions. + const uint8x8_t filter_taps[4] = { vdup_lane_u8(y_filter, 2), + vdup_lane_u8(y_filter, 3), + vdup_lane_u8(y_filter, 4), + vdup_lane_u8(y_filter, 5) }; + + if (w == 4) { + uint8x8_t s01 = load_unaligned_u8(src + 0 * src_stride, src_stride); + uint8x8_t s12 = load_unaligned_u8(src + 1 * src_stride, src_stride); + + src += 2 * src_stride; + + do { + uint8x8_t s23 = load_unaligned_u8(src + 0 * src_stride, src_stride); + uint8x8_t s34 = load_unaligned_u8(src + 1 * src_stride, src_stride); + uint8x8_t s45 = load_unaligned_u8(src + 2 * src_stride, src_stride); + uint8x8_t s56 = load_unaligned_u8(src + 3 * src_stride, src_stride); + + uint8x8_t d01 = convolve4_8(s01, s12, s23, s34, filter_taps); + uint8x8_t d23 = convolve4_8(s23, s34, s45, s56, filter_taps); + + store_unaligned_u8(dst + 0 * dst_stride, dst_stride, d01); + store_unaligned_u8(dst + 2 * dst_stride, dst_stride, d23); + + s01 = s45; + s12 = s56; + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + do { + const uint8_t *s = src; + uint8_t *d = dst; + int height = h; + + uint8x8_t s0, s1, s2; + load_u8_8x3(s, src_stride, &s0, &s1, &s2); + + s += 3 * src_stride; + + do { + uint8x8_t s3, s4, s5, s6; + load_u8_8x4(s, src_stride, &s3, &s4, &s5, &s6); + + uint8x8_t d0 = convolve4_8(s0, s1, s2, s3, filter_taps); + uint8x8_t d1 = convolve4_8(s1, s2, s3, s4, filter_taps); + uint8x8_t d2 = convolve4_8(s2, s3, s4, s5, filter_taps); + uint8x8_t d3 = convolve4_8(s3, s4, s5, s6, filter_taps); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s0 = s4; + s1 = s5; + s2 = s6; + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); + } } #endif // VPX_VPX_DSP_ARM_VPX_CONVOLVE8_NEON_H_ diff --git a/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon_dotprod.c b/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon_dotprod.c new file mode 100644 index 0000000000..b919843de6 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon_dotprod.c @@ -0,0 +1,1024 @@ +/* + * Copyright (c) 2021 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/transpose_neon.h" +#include "vpx_dsp/arm/vpx_convolve8_neon.h" +#include "vpx_dsp/vpx_filter.h" +#include "vpx_ports/mem.h" + +// Filter values always sum to 128. +#define FILTER_SUM 128 + +DECLARE_ALIGNED(16, static const uint8_t, dot_prod_permute_tbl[48]) = { + 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, + 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, + 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14 +}; + +DECLARE_ALIGNED(16, static const uint8_t, dot_prod_merge_block_tbl[48]) = { + // Shift left and insert new last column in transposed 4x4 block. + 1, 2, 3, 16, 5, 6, 7, 20, 9, 10, 11, 24, 13, 14, 15, 28, + // Shift left and insert two new columns in transposed 4x4 block. + 2, 3, 16, 17, 6, 7, 20, 21, 10, 11, 24, 25, 14, 15, 28, 29, + // Shift left and insert three new columns in transposed 4x4 block. + 3, 16, 17, 18, 7, 20, 21, 22, 11, 24, 25, 26, 15, 28, 29, 30 +}; + +static INLINE int16x4_t convolve4_4_h(const uint8x16_t samples, + const int8x8_t filters, + const uint8x16_t permute_tbl) { + // Transform sample range to [-128, 127] for 8-bit signed dot product. + int8x16_t samples_128 = + vreinterpretq_s8_u8(vsubq_u8(samples, vdupq_n_u8(128))); + + // Permute samples ready for dot product. + // { 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6 } + int8x16_t perm_samples = vqtbl1q_s8(samples_128, permute_tbl); + + // Accumulate into 128 * FILTER_SUM to account for range transform. (Divide + // by 2 since we halved the filter values.) + int32x4_t acc = vdupq_n_s32(128 * FILTER_SUM / 2); + int32x4_t sum = vdotq_lane_s32(acc, perm_samples, filters, 0); + + // Further narrowing and packing is performed by the caller. + return vmovn_s32(sum); +} + +static INLINE uint8x8_t convolve4_8_h(const uint8x16_t samples, + const int8x8_t filters, + const uint8x16x2_t permute_tbl) { + // Transform sample range to [-128, 127] for 8-bit signed dot product. + int8x16_t samples_128 = + vreinterpretq_s8_u8(vsubq_u8(samples, vdupq_n_u8(128))); + + // Permute samples ready for dot product. + // { 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6 } + // { 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10 } + int8x16_t perm_samples[2] = { vqtbl1q_s8(samples_128, permute_tbl.val[0]), + vqtbl1q_s8(samples_128, permute_tbl.val[1]) }; + + // Accumulate into 128 * FILTER_SUM to account for range transform. (Divide + // by 2 since we halved the filter values.) + int32x4_t acc = vdupq_n_s32(128 * FILTER_SUM / 2); + // First 4 output values. + int32x4_t sum0 = vdotq_lane_s32(acc, perm_samples[0], filters, 0); + // Second 4 output values. + int32x4_t sum1 = vdotq_lane_s32(acc, perm_samples[1], filters, 0); + + // Narrow and re-pack. + int16x8_t sum = vcombine_s16(vmovn_s32(sum0), vmovn_s32(sum1)); + // We halved the filter values so -1 from right shift. + return vqrshrun_n_s16(sum, FILTER_BITS - 1); +} + +static INLINE int16x4_t convolve8_4_h(const uint8x16_t samples, + const int8x8_t filters, + const uint8x16x2_t permute_tbl) { + // Transform sample range to [-128, 127] for 8-bit signed dot product. + int8x16_t samples_128 = + vreinterpretq_s8_u8(vsubq_u8(samples, vdupq_n_u8(128))); + + // Permute samples ready for dot product. + // { 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6 } + // { 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10 } + int8x16_t perm_samples[2] = { vqtbl1q_s8(samples_128, permute_tbl.val[0]), + vqtbl1q_s8(samples_128, permute_tbl.val[1]) }; + + // Accumulate into 128 * FILTER_SUM to account for range transform. + int32x4_t acc = vdupq_n_s32(128 * FILTER_SUM); + int32x4_t sum = vdotq_lane_s32(acc, perm_samples[0], filters, 0); + sum = vdotq_lane_s32(sum, perm_samples[1], filters, 1); + + // Further narrowing and packing is performed by the caller. + return vshrn_n_s32(sum, 1); +} + +static INLINE uint8x8_t convolve8_8_h(const uint8x16_t samples, + const int8x8_t filters, + const uint8x16x3_t permute_tbl) { + // Transform sample range to [-128, 127] for 8-bit signed dot product. + int8x16_t samples_128 = + vreinterpretq_s8_u8(vsubq_u8(samples, vdupq_n_u8(128))); + + // Permute samples ready for dot product. + // { 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6 } + // { 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10 } + // { 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14 } + int8x16_t perm_samples[3] = { vqtbl1q_s8(samples_128, permute_tbl.val[0]), + vqtbl1q_s8(samples_128, permute_tbl.val[1]), + vqtbl1q_s8(samples_128, permute_tbl.val[2]) }; + + // Accumulate into 128 * FILTER_SUM to account for range transform. + int32x4_t acc = vdupq_n_s32(128 * FILTER_SUM); + // First 4 output values. + int32x4_t sum0 = vdotq_lane_s32(acc, perm_samples[0], filters, 0); + sum0 = vdotq_lane_s32(sum0, perm_samples[1], filters, 1); + // Second 4 output values. + int32x4_t sum1 = vdotq_lane_s32(acc, perm_samples[1], filters, 0); + sum1 = vdotq_lane_s32(sum1, perm_samples[2], filters, 1); + + // Narrow and re-pack. + int16x8_t sum = vcombine_s16(vshrn_n_s32(sum0, 1), vshrn_n_s32(sum1, 1)); + return vqrshrun_n_s16(sum, FILTER_BITS - 1); +} + +static INLINE void convolve_4tap_horiz_neon_dotprod( + const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, int w, int h, const int8x8_t filter) { + if (w == 4) { + const uint8x16_t permute_tbl = vld1q_u8(dot_prod_permute_tbl); + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(src, src_stride, &s0, &s1, &s2, &s3); + + int16x4_t t0 = convolve4_4_h(s0, filter, permute_tbl); + int16x4_t t1 = convolve4_4_h(s1, filter, permute_tbl); + int16x4_t t2 = convolve4_4_h(s2, filter, permute_tbl); + int16x4_t t3 = convolve4_4_h(s3, filter, permute_tbl); + // We halved the filter values so -1 from right shift. + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(t0, t1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(t2, t3), FILTER_BITS - 1); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(s, src_stride, &s0, &s1, &s2, &s3); + + uint8x8_t d0 = convolve4_8_h(s0, filter, permute_tbl); + uint8x8_t d1 = convolve4_8_h(s1, filter, permute_tbl); + uint8x8_t d2 = convolve4_8_h(s2, filter, permute_tbl); + uint8x8_t d3 = convolve4_8_h(s3, filter, permute_tbl); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } +} + +static INLINE void convolve_8tap_horiz_neon_dotprod( + const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, int w, int h, const int8x8_t filter) { + if (w == 4) { + const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(src, src_stride, &s0, &s1, &s2, &s3); + + int16x4_t t0 = convolve8_4_h(s0, filter, permute_tbl); + int16x4_t t1 = convolve8_4_h(s1, filter, permute_tbl); + int16x4_t t2 = convolve8_4_h(s2, filter, permute_tbl); + int16x4_t t3 = convolve8_4_h(s3, filter, permute_tbl); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(t0, t1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(t2, t3), FILTER_BITS - 1); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint8x16x3_t permute_tbl = vld1q_u8_x3(dot_prod_permute_tbl); + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(s, src_stride, &s0, &s1, &s2, &s3); + + uint8x8_t d0 = convolve8_8_h(s0, filter, permute_tbl); + uint8x8_t d1 = convolve8_8_h(s1, filter, permute_tbl); + uint8x8_t d2 = convolve8_8_h(s2, filter, permute_tbl); + uint8x8_t d3 = convolve8_8_h(s3, filter, permute_tbl); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } +} + +void vpx_convolve8_horiz_neon_dotprod(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(x_step_q4 == 16); + + (void)x_step_q4; + (void)y0_q4; + (void)y_step_q4; + + if (vpx_get_filter_taps(filter[x0_q4]) <= 4) { + // Load 4-tap filter into first 4 elements of the vector. + // All 4-tap and bilinear filter values are even, so halve them to reduce + // intermediate precision requirements. + const int16x4_t x_filter = vld1_s16(filter[x0_q4] + 2); + const int8x8_t x_filter_4tap = + vshrn_n_s16(vcombine_s16(x_filter, vdup_n_s16(0)), 1); + + convolve_4tap_horiz_neon_dotprod(src - 1, src_stride, dst, dst_stride, w, h, + x_filter_4tap); + + } else { + const int8x8_t x_filter_8tap = vmovn_s16(vld1q_s16(filter[x0_q4])); + + convolve_8tap_horiz_neon_dotprod(src - 3, src_stride, dst, dst_stride, w, h, + x_filter_8tap); + } +} + +void vpx_convolve8_avg_horiz_neon_dotprod(const uint8_t *src, + ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, + int y_step_q4, int w, int h) { + const int8x8_t filters = vmovn_s16(vld1q_s16(filter[x0_q4])); + + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(x_step_q4 == 16); + + (void)x_step_q4; + (void)y0_q4; + (void)y_step_q4; + + src -= 3; + + if (w == 4) { + const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(src, src_stride, &s0, &s1, &s2, &s3); + + int16x4_t t0 = convolve8_4_h(s0, filters, permute_tbl); + int16x4_t t1 = convolve8_4_h(s1, filters, permute_tbl); + int16x4_t t2 = convolve8_4_h(s2, filters, permute_tbl); + int16x4_t t3 = convolve8_4_h(s3, filters, permute_tbl); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(t0, t1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(t2, t3), FILTER_BITS - 1); + + uint8x8_t dd01 = load_u8(dst + 0 * dst_stride, dst_stride); + uint8x8_t dd23 = load_u8(dst + 2 * dst_stride, dst_stride); + + d01 = vrhadd_u8(d01, dd01); + d23 = vrhadd_u8(d23, dd23); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint8x16x3_t permute_tbl = vld1q_u8_x3(dot_prod_permute_tbl); + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(s, src_stride, &s0, &s1, &s2, &s3); + + uint8x8_t d0 = convolve8_8_h(s0, filters, permute_tbl); + uint8x8_t d1 = convolve8_8_h(s1, filters, permute_tbl); + uint8x8_t d2 = convolve8_8_h(s2, filters, permute_tbl); + uint8x8_t d3 = convolve8_8_h(s3, filters, permute_tbl); + + uint8x8_t dd0, dd1, dd2, dd3; + load_u8_8x4(d, dst_stride, &dd0, &dd1, &dd2, &dd3); + + d0 = vrhadd_u8(d0, dd0); + d1 = vrhadd_u8(d1, dd1); + d2 = vrhadd_u8(d2, dd2); + d3 = vrhadd_u8(d3, dd3); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } +} + +static INLINE int16x4_t convolve8_4_v(const int8x16_t samples_lo, + const int8x16_t samples_hi, + const int8x8_t filters) { + // The sample range transform and permutation are performed by the caller. + + // Accumulate into 128 * FILTER_SUM to account for range transform. + int32x4_t acc = vdupq_n_s32(128 * FILTER_SUM); + int32x4_t sum = vdotq_lane_s32(acc, samples_lo, filters, 0); + sum = vdotq_lane_s32(sum, samples_hi, filters, 1); + + // Further narrowing and packing is performed by the caller. + return vshrn_n_s32(sum, 1); +} + +static INLINE uint8x8_t convolve8_8_v(const int8x16_t samples0_lo, + const int8x16_t samples0_hi, + const int8x16_t samples1_lo, + const int8x16_t samples1_hi, + const int8x8_t filters) { + // The sample range transform and permutation are performed by the caller. + + // Accumulate into 128 * FILTER_SUM to account for range transform. + int32x4_t acc = vdupq_n_s32(128 * FILTER_SUM); + // First 4 output values. + int32x4_t sum0 = vdotq_lane_s32(acc, samples0_lo, filters, 0); + sum0 = vdotq_lane_s32(sum0, samples0_hi, filters, 1); + // Second 4 output values. + int32x4_t sum1 = vdotq_lane_s32(acc, samples1_lo, filters, 0); + sum1 = vdotq_lane_s32(sum1, samples1_hi, filters, 1); + + // Narrow and re-pack. + int16x8_t sum = vcombine_s16(vshrn_n_s32(sum0, 1), vshrn_n_s32(sum1, 1)); + return vqrshrun_n_s16(sum, FILTER_BITS - 1); +} + +static INLINE void convolve_8tap_vert_neon_dotprod( + const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, int w, int h, const int8x8_t filter) { + const uint8x16x3_t merge_block_tbl = vld1q_u8_x3(dot_prod_merge_block_tbl); + + if (w == 4) { + uint8x8_t t0, t1, t2, t3, t4, t5, t6; + load_u8_8x7(src, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6); + src += 7 * src_stride; + + // Transform sample range to [-128, 127] for 8-bit signed dot product. + int8x8_t s0 = vreinterpret_s8_u8(vsub_u8(t0, vdup_n_u8(128))); + int8x8_t s1 = vreinterpret_s8_u8(vsub_u8(t1, vdup_n_u8(128))); + int8x8_t s2 = vreinterpret_s8_u8(vsub_u8(t2, vdup_n_u8(128))); + int8x8_t s3 = vreinterpret_s8_u8(vsub_u8(t3, vdup_n_u8(128))); + int8x8_t s4 = vreinterpret_s8_u8(vsub_u8(t4, vdup_n_u8(128))); + int8x8_t s5 = vreinterpret_s8_u8(vsub_u8(t5, vdup_n_u8(128))); + int8x8_t s6 = vreinterpret_s8_u8(vsub_u8(t6, vdup_n_u8(128))); + + // This operation combines a conventional transpose and the sample permute + // (see horizontal case) required before computing the dot product. + int8x16_t s0123, s1234, s2345, s3456; + transpose_concat_s8_4x4(s0, s1, s2, s3, &s0123); + transpose_concat_s8_4x4(s1, s2, s3, s4, &s1234); + transpose_concat_s8_4x4(s2, s3, s4, s5, &s2345); + transpose_concat_s8_4x4(s3, s4, s5, s6, &s3456); + + do { + uint8x8_t t7, t8, t9, t10; + load_u8_8x4(src, src_stride, &t7, &t8, &t9, &t10); + + int8x8_t s7 = vreinterpret_s8_u8(vsub_u8(t7, vdup_n_u8(128))); + int8x8_t s8 = vreinterpret_s8_u8(vsub_u8(t8, vdup_n_u8(128))); + int8x8_t s9 = vreinterpret_s8_u8(vsub_u8(t9, vdup_n_u8(128))); + int8x8_t s10 = vreinterpret_s8_u8(vsub_u8(t10, vdup_n_u8(128))); + + int8x16_t s78910; + transpose_concat_s8_4x4(s7, s8, s9, s10, &s78910); + + // Merge new data into block from previous iteration. + int8x16x2_t samples_LUT = { { s3456, s78910 } }; + int8x16_t s4567 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); + int8x16_t s5678 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); + int8x16_t s6789 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); + + int16x4_t d0 = convolve8_4_v(s0123, s4567, filter); + int16x4_t d1 = convolve8_4_v(s1234, s5678, filter); + int16x4_t d2 = convolve8_4_v(s2345, s6789, filter); + int16x4_t d3 = convolve8_4_v(s3456, s78910, filter); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), FILTER_BITS - 1); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + /* Prepare block for next iteration - re-using as much as possible. */ + /* Shuffle everything up four rows. */ + s0123 = s4567; + s1234 = s5678; + s2345 = s6789; + s3456 = s78910; + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + do { + const uint8_t *s = src; + uint8_t *d = dst; + int height = h; + + uint8x8_t t0, t1, t2, t3, t4, t5, t6; + load_u8_8x7(s, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6); + s += 7 * src_stride; + + // Transform sample range to [-128, 127] for 8-bit signed dot product. + int8x8_t s0 = vreinterpret_s8_u8(vsub_u8(t0, vdup_n_u8(128))); + int8x8_t s1 = vreinterpret_s8_u8(vsub_u8(t1, vdup_n_u8(128))); + int8x8_t s2 = vreinterpret_s8_u8(vsub_u8(t2, vdup_n_u8(128))); + int8x8_t s3 = vreinterpret_s8_u8(vsub_u8(t3, vdup_n_u8(128))); + int8x8_t s4 = vreinterpret_s8_u8(vsub_u8(t4, vdup_n_u8(128))); + int8x8_t s5 = vreinterpret_s8_u8(vsub_u8(t5, vdup_n_u8(128))); + int8x8_t s6 = vreinterpret_s8_u8(vsub_u8(t6, vdup_n_u8(128))); + + // This operation combines a conventional transpose and the sample permute + // (see horizontal case) required before computing the dot product. + int8x16_t s0123_lo, s0123_hi, s1234_lo, s1234_hi, s2345_lo, s2345_hi, + s3456_lo, s3456_hi; + transpose_concat_s8_8x4(s0, s1, s2, s3, &s0123_lo, &s0123_hi); + transpose_concat_s8_8x4(s1, s2, s3, s4, &s1234_lo, &s1234_hi); + transpose_concat_s8_8x4(s2, s3, s4, s5, &s2345_lo, &s2345_hi); + transpose_concat_s8_8x4(s3, s4, s5, s6, &s3456_lo, &s3456_hi); + + do { + uint8x8_t t7, t8, t9, t10; + load_u8_8x4(s, src_stride, &t7, &t8, &t9, &t10); + + int8x8_t s7 = vreinterpret_s8_u8(vsub_u8(t7, vdup_n_u8(128))); + int8x8_t s8 = vreinterpret_s8_u8(vsub_u8(t8, vdup_n_u8(128))); + int8x8_t s9 = vreinterpret_s8_u8(vsub_u8(t9, vdup_n_u8(128))); + int8x8_t s10 = vreinterpret_s8_u8(vsub_u8(t10, vdup_n_u8(128))); + + int8x16_t s78910_lo, s78910_hi; + transpose_concat_s8_8x4(s7, s8, s9, s10, &s78910_lo, &s78910_hi); + + // Merge new data into block from previous iteration. + int8x16x2_t samples_LUT = { { s3456_lo, s78910_lo } }; + int8x16_t s4567_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); + int8x16_t s5678_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); + int8x16_t s6789_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); + + samples_LUT.val[0] = s3456_hi; + samples_LUT.val[1] = s78910_hi; + int8x16_t s4567_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); + int8x16_t s5678_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); + int8x16_t s6789_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); + + uint8x8_t d0 = + convolve8_8_v(s0123_lo, s4567_lo, s0123_hi, s4567_hi, filter); + uint8x8_t d1 = + convolve8_8_v(s1234_lo, s5678_lo, s1234_hi, s5678_hi, filter); + uint8x8_t d2 = + convolve8_8_v(s2345_lo, s6789_lo, s2345_hi, s6789_hi, filter); + uint8x8_t d3 = + convolve8_8_v(s3456_lo, s78910_lo, s3456_hi, s78910_hi, filter); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + // Prepare block for next iteration - re-using as much as possible. + // Shuffle everything up four rows. + s0123_lo = s4567_lo; + s0123_hi = s4567_hi; + s1234_lo = s5678_lo; + s1234_hi = s5678_hi; + s2345_lo = s6789_lo; + s2345_hi = s6789_hi; + s3456_lo = s78910_lo; + s3456_hi = s78910_hi; + + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); + } +} + +void vpx_convolve8_vert_neon_dotprod(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(y_step_q4 == 16); + + (void)x0_q4; + (void)x_step_q4; + (void)y_step_q4; + + if (vpx_get_filter_taps(filter[y0_q4]) <= 4) { + const int16x8_t y_filter = vld1q_s16(filter[y0_q4]); + + convolve_4tap_vert_neon(src - src_stride, src_stride, dst, dst_stride, w, h, + y_filter); + } else { + const int8x8_t y_filter = vmovn_s16(vld1q_s16(filter[y0_q4])); + + convolve_8tap_vert_neon_dotprod(src - 3 * src_stride, src_stride, dst, + dst_stride, w, h, y_filter); + } +} + +void vpx_convolve8_avg_vert_neon_dotprod(const uint8_t *src, + ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, + int y_step_q4, int w, int h) { + const int8x8_t filters = vmovn_s16(vld1q_s16(filter[y0_q4])); + const uint8x16x3_t merge_block_tbl = vld1q_u8_x3(dot_prod_merge_block_tbl); + + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(y_step_q4 == 16); + + (void)x0_q4; + (void)x_step_q4; + (void)y_step_q4; + + src -= 3 * src_stride; + + if (w == 4) { + uint8x8_t t0, t1, t2, t3, t4, t5, t6; + load_u8_8x7(src, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6); + src += 7 * src_stride; + + // Transform sample range to [-128, 127] for 8-bit signed dot product. + int8x8_t s0 = vreinterpret_s8_u8(vsub_u8(t0, vdup_n_u8(128))); + int8x8_t s1 = vreinterpret_s8_u8(vsub_u8(t1, vdup_n_u8(128))); + int8x8_t s2 = vreinterpret_s8_u8(vsub_u8(t2, vdup_n_u8(128))); + int8x8_t s3 = vreinterpret_s8_u8(vsub_u8(t3, vdup_n_u8(128))); + int8x8_t s4 = vreinterpret_s8_u8(vsub_u8(t4, vdup_n_u8(128))); + int8x8_t s5 = vreinterpret_s8_u8(vsub_u8(t5, vdup_n_u8(128))); + int8x8_t s6 = vreinterpret_s8_u8(vsub_u8(t6, vdup_n_u8(128))); + + // This operation combines a conventional transpose and the sample permute + // (see horizontal case) required before computing the dot product. + int8x16_t s0123, s1234, s2345, s3456; + transpose_concat_s8_4x4(s0, s1, s2, s3, &s0123); + transpose_concat_s8_4x4(s1, s2, s3, s4, &s1234); + transpose_concat_s8_4x4(s2, s3, s4, s5, &s2345); + transpose_concat_s8_4x4(s3, s4, s5, s6, &s3456); + + do { + uint8x8_t t7, t8, t9, t10; + load_u8_8x4(src, src_stride, &t7, &t8, &t9, &t10); + + int8x8_t s7 = vreinterpret_s8_u8(vsub_u8(t7, vdup_n_u8(128))); + int8x8_t s8 = vreinterpret_s8_u8(vsub_u8(t8, vdup_n_u8(128))); + int8x8_t s9 = vreinterpret_s8_u8(vsub_u8(t9, vdup_n_u8(128))); + int8x8_t s10 = vreinterpret_s8_u8(vsub_u8(t10, vdup_n_u8(128))); + + int8x16_t s78910; + transpose_concat_s8_4x4(s7, s8, s9, s10, &s78910); + + // Merge new data into block from previous iteration. + int8x16x2_t samples_LUT = { { s3456, s78910 } }; + int8x16_t s4567 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); + int8x16_t s5678 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); + int8x16_t s6789 = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); + + int16x4_t d0 = convolve8_4_v(s0123, s4567, filters); + int16x4_t d1 = convolve8_4_v(s1234, s5678, filters); + int16x4_t d2 = convolve8_4_v(s2345, s6789, filters); + int16x4_t d3 = convolve8_4_v(s3456, s78910, filters); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), FILTER_BITS - 1); + + uint8x8_t dd01 = load_u8(dst + 0 * dst_stride, dst_stride); + uint8x8_t dd23 = load_u8(dst + 2 * dst_stride, dst_stride); + + d01 = vrhadd_u8(d01, dd01); + d23 = vrhadd_u8(d23, dd23); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + // Prepare block for next iteration - re-using as much as possible. + // Shuffle everything up four rows. + s0123 = s4567; + s1234 = s5678; + s2345 = s6789; + s3456 = s78910; + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + do { + const uint8_t *s = src; + uint8_t *d = dst; + int height = h; + + uint8x8_t t0, t1, t2, t3, t4, t5, t6; + load_u8_8x7(s, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6); + s += 7 * src_stride; + + // Transform sample range to [-128, 127] for 8-bit signed dot product. + int8x8_t s0 = vreinterpret_s8_u8(vsub_u8(t0, vdup_n_u8(128))); + int8x8_t s1 = vreinterpret_s8_u8(vsub_u8(t1, vdup_n_u8(128))); + int8x8_t s2 = vreinterpret_s8_u8(vsub_u8(t2, vdup_n_u8(128))); + int8x8_t s3 = vreinterpret_s8_u8(vsub_u8(t3, vdup_n_u8(128))); + int8x8_t s4 = vreinterpret_s8_u8(vsub_u8(t4, vdup_n_u8(128))); + int8x8_t s5 = vreinterpret_s8_u8(vsub_u8(t5, vdup_n_u8(128))); + int8x8_t s6 = vreinterpret_s8_u8(vsub_u8(t6, vdup_n_u8(128))); + + // This operation combines a conventional transpose and the sample permute + // (see horizontal case) required before computing the dot product. + int8x16_t s0123_lo, s0123_hi, s1234_lo, s1234_hi, s2345_lo, s2345_hi, + s3456_lo, s3456_hi; + transpose_concat_s8_8x4(s0, s1, s2, s3, &s0123_lo, &s0123_hi); + transpose_concat_s8_8x4(s1, s2, s3, s4, &s1234_lo, &s1234_hi); + transpose_concat_s8_8x4(s2, s3, s4, s5, &s2345_lo, &s2345_hi); + transpose_concat_s8_8x4(s3, s4, s5, s6, &s3456_lo, &s3456_hi); + + do { + uint8x8_t t7, t8, t9, t10; + load_u8_8x4(s, src_stride, &t7, &t8, &t9, &t10); + + int8x8_t s7 = vreinterpret_s8_u8(vsub_u8(t7, vdup_n_u8(128))); + int8x8_t s8 = vreinterpret_s8_u8(vsub_u8(t8, vdup_n_u8(128))); + int8x8_t s9 = vreinterpret_s8_u8(vsub_u8(t9, vdup_n_u8(128))); + int8x8_t s10 = vreinterpret_s8_u8(vsub_u8(t10, vdup_n_u8(128))); + + int8x16_t s78910_lo, s78910_hi; + transpose_concat_s8_8x4(s7, s8, s9, s10, &s78910_lo, &s78910_hi); + + // Merge new data into block from previous iteration. + int8x16x2_t samples_LUT = { { s3456_lo, s78910_lo } }; + int8x16_t s4567_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); + int8x16_t s5678_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); + int8x16_t s6789_lo = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); + + samples_LUT.val[0] = s3456_hi; + samples_LUT.val[1] = s78910_hi; + int8x16_t s4567_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[0]); + int8x16_t s5678_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[1]); + int8x16_t s6789_hi = vqtbl2q_s8(samples_LUT, merge_block_tbl.val[2]); + + uint8x8_t d0 = + convolve8_8_v(s0123_lo, s4567_lo, s0123_hi, s4567_hi, filters); + uint8x8_t d1 = + convolve8_8_v(s1234_lo, s5678_lo, s1234_hi, s5678_hi, filters); + uint8x8_t d2 = + convolve8_8_v(s2345_lo, s6789_lo, s2345_hi, s6789_hi, filters); + uint8x8_t d3 = + convolve8_8_v(s3456_lo, s78910_lo, s3456_hi, s78910_hi, filters); + + uint8x8_t dd0, dd1, dd2, dd3; + load_u8_8x4(d, dst_stride, &dd0, &dd1, &dd2, &dd3); + + d0 = vrhadd_u8(d0, dd0); + d1 = vrhadd_u8(d1, dd1); + d2 = vrhadd_u8(d2, dd2); + d3 = vrhadd_u8(d3, dd3); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + // Prepare block for next iteration - re-using as much as possible. + // Shuffle everything up four rows. + s0123_lo = s4567_lo; + s0123_hi = s4567_hi; + s1234_lo = s5678_lo; + s1234_hi = s5678_hi; + s2345_lo = s6789_lo; + s2345_hi = s6789_hi; + s3456_lo = s78910_lo; + s3456_hi = s78910_hi; + + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); + } +} + +static INLINE void convolve_4tap_2d_neon_dotprod(const uint8_t *src, + ptrdiff_t src_stride, + uint8_t *dst, + ptrdiff_t dst_stride, int w, + int h, const int8x8_t x_filter, + const uint8x8_t y_filter) { + // Neon does not have lane-referencing multiply or multiply-accumulate + // instructions that operate on vectors of 8-bit elements. This means we have + // to duplicate filter taps into a whole vector and use standard multiply / + // multiply-accumulate instructions. + const uint8x8_t y_filter_taps[4] = { vdup_lane_u8(y_filter, 2), + vdup_lane_u8(y_filter, 3), + vdup_lane_u8(y_filter, 4), + vdup_lane_u8(y_filter, 5) }; + + if (w == 4) { + const uint8x16_t permute_tbl = vld1q_u8(dot_prod_permute_tbl); + + uint8x16_t h_s0, h_s1, h_s2; + load_u8_16x3(src, src_stride, &h_s0, &h_s1, &h_s2); + + int16x4_t t0 = convolve4_4_h(h_s0, x_filter, permute_tbl); + int16x4_t t1 = convolve4_4_h(h_s1, x_filter, permute_tbl); + int16x4_t t2 = convolve4_4_h(h_s2, x_filter, permute_tbl); + // We halved the filter values so -1 from right shift. + uint8x8_t v_s01 = vqrshrun_n_s16(vcombine_s16(t0, t1), FILTER_BITS - 1); + uint8x8_t v_s12 = vqrshrun_n_s16(vcombine_s16(t1, t2), FILTER_BITS - 1); + + src += 3 * src_stride; + + do { + uint8x16_t h_s3, h_s4, h_s5, h_s6; + load_u8_16x4(src, src_stride, &h_s3, &h_s4, &h_s5, &h_s6); + + int16x4_t t3 = convolve4_4_h(h_s3, x_filter, permute_tbl); + int16x4_t t4 = convolve4_4_h(h_s4, x_filter, permute_tbl); + int16x4_t t5 = convolve4_4_h(h_s5, x_filter, permute_tbl); + int16x4_t t6 = convolve4_4_h(h_s6, x_filter, permute_tbl); + // We halved the filter values so -1 from right shift. + uint8x8_t v_s34 = vqrshrun_n_s16(vcombine_s16(t3, t4), FILTER_BITS - 1); + uint8x8_t v_s56 = vqrshrun_n_s16(vcombine_s16(t5, t6), FILTER_BITS - 1); + uint8x8_t v_s23 = vext_u8(v_s12, v_s34, 4); + uint8x8_t v_s45 = vext_u8(v_s34, v_s56, 4); + + uint8x8_t d01 = convolve4_8(v_s01, v_s12, v_s23, v_s34, y_filter_taps); + uint8x8_t d23 = convolve4_8(v_s23, v_s34, v_s45, v_s56, y_filter_taps); + + store_unaligned_u8(dst + 0 * dst_stride, dst_stride, d01); + store_unaligned_u8(dst + 2 * dst_stride, dst_stride, d23); + + v_s01 = v_s45; + v_s12 = v_s56; + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int height = h; + + uint8x16_t h_s0, h_s1, h_s2; + load_u8_16x3(s, src_stride, &h_s0, &h_s1, &h_s2); + + uint8x8_t v_s0 = convolve4_8_h(h_s0, x_filter, permute_tbl); + uint8x8_t v_s1 = convolve4_8_h(h_s1, x_filter, permute_tbl); + uint8x8_t v_s2 = convolve4_8_h(h_s2, x_filter, permute_tbl); + + s += 3 * src_stride; + + do { + uint8x16_t h_s3, h_s4, h_s5, h_s6; + load_u8_16x4(s, src_stride, &h_s3, &h_s4, &h_s5, &h_s6); + + uint8x8_t v_s3 = convolve4_8_h(h_s3, x_filter, permute_tbl); + uint8x8_t v_s4 = convolve4_8_h(h_s4, x_filter, permute_tbl); + uint8x8_t v_s5 = convolve4_8_h(h_s5, x_filter, permute_tbl); + uint8x8_t v_s6 = convolve4_8_h(h_s6, x_filter, permute_tbl); + + uint8x8_t d0 = convolve4_8(v_s0, v_s1, v_s2, v_s3, y_filter_taps); + uint8x8_t d1 = convolve4_8(v_s1, v_s2, v_s3, v_s4, y_filter_taps); + uint8x8_t d2 = convolve4_8(v_s2, v_s3, v_s4, v_s5, y_filter_taps); + uint8x8_t d3 = convolve4_8(v_s3, v_s4, v_s5, v_s6, y_filter_taps); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + v_s0 = v_s4; + v_s1 = v_s5; + v_s2 = v_s6; + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); + } +} + +static INLINE void convolve_8tap_2d_horiz_neon_dotprod( + const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, int w, int h, const int8x8_t filter) { + if (w == 4) { + const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(src, src_stride, &s0, &s1, &s2, &s3); + + int16x4_t d0 = convolve8_4_h(s0, filter, permute_tbl); + int16x4_t d1 = convolve8_4_h(s1, filter, permute_tbl); + int16x4_t d2 = convolve8_4_h(s2, filter, permute_tbl); + int16x4_t d3 = convolve8_4_h(s3, filter, permute_tbl); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), FILTER_BITS - 1); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h > 3); + + // Process final three rows (h % 4 == 3). See vpx_convolve_neon_i8mm() + // below for further details on possible values of block height. + uint8x16_t s0, s1, s2; + load_u8_16x3(src, src_stride, &s0, &s1, &s2); + + int16x4_t d0 = convolve8_4_h(s0, filter, permute_tbl); + int16x4_t d1 = convolve8_4_h(s1, filter, permute_tbl); + int16x4_t d2 = convolve8_4_h(s2, filter, permute_tbl); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS - 1); + uint8x8_t d23 = + vqrshrun_n_s16(vcombine_s16(d2, vdup_n_s16(0)), FILTER_BITS - 1); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8_4x1(dst + 2 * dst_stride, d23); + } else { + const uint8x16x3_t permute_tbl = vld1q_u8_x3(dot_prod_permute_tbl); + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(s, src_stride, &s0, &s1, &s2, &s3); + + uint8x8_t d0 = convolve8_8_h(s0, filter, permute_tbl); + uint8x8_t d1 = convolve8_8_h(s1, filter, permute_tbl); + uint8x8_t d2 = convolve8_8_h(s2, filter, permute_tbl); + uint8x8_t d3 = convolve8_8_h(s3, filter, permute_tbl); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width > 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h > 3); + + // Process final three rows (h % 4 == 3). See vpx_convolve_neon_i8mm() + // below for further details on possible values of block height. + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0, s1, s2; + load_u8_16x3(s, src_stride, &s0, &s1, &s2); + + uint8x8_t d0 = convolve8_8_h(s0, filter, permute_tbl); + uint8x8_t d1 = convolve8_8_h(s1, filter, permute_tbl); + uint8x8_t d2 = convolve8_8_h(s2, filter, permute_tbl); + + store_u8_8x3(d, dst_stride, d0, d1, d2); + + s += 8; + d += 8; + width -= 8; + } while (width > 0); + } +} + +void vpx_convolve8_neon_dotprod(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + assert(x_step_q4 == 16); + assert(y_step_q4 == 16); + + (void)x_step_q4; + (void)y_step_q4; + + const int x_filter_taps = vpx_get_filter_taps(filter[x0_q4]) <= 4 ? 4 : 8; + const int y_filter_taps = vpx_get_filter_taps(filter[y0_q4]) <= 4 ? 4 : 8; + // Account for needing filter_taps / 2 - 1 lines prior and filter_taps / 2 + // lines post both horizontally and vertically. + const ptrdiff_t horiz_offset = x_filter_taps / 2 - 1; + const ptrdiff_t vert_offset = (y_filter_taps / 2 - 1) * src_stride; + + if (x_filter_taps == 4 && y_filter_taps == 4) { + const int16x4_t x_filter = vld1_s16(filter[x0_q4] + 2); + const int16x8_t y_filter = vld1q_s16(filter[y0_q4]); + + // 4-tap and bilinear filter values are even, so halve them to reduce + // intermediate precision requirements. + const int8x8_t x_filter_4tap = + vshrn_n_s16(vcombine_s16(x_filter, vdup_n_s16(0)), 1); + const uint8x8_t y_filter_4tap = + vshrn_n_u16(vreinterpretq_u16_s16(vabsq_s16(y_filter)), 1); + + convolve_4tap_2d_neon_dotprod(src - horiz_offset - vert_offset, src_stride, + dst, dst_stride, w, h, x_filter_4tap, + y_filter_4tap); + return; + } + + // Given our constraints: w <= 64, h <= 64, taps <= 8 we can reduce the + // maximum buffer size to 64 * (64 + 7). + DECLARE_ALIGNED(32, uint8_t, im_block[64 * 71]); + const int im_stride = 64; + const int im_height = h + SUBPEL_TAPS - 1; + + const int8x8_t x_filter_8tap = vmovn_s16(vld1q_s16(filter[x0_q4])); + const int8x8_t y_filter_8tap = vmovn_s16(vld1q_s16(filter[y0_q4])); + + convolve_8tap_2d_horiz_neon_dotprod(src - horiz_offset - vert_offset, + src_stride, im_block, im_stride, w, + im_height, x_filter_8tap); + + convolve_8tap_vert_neon_dotprod(im_block, im_stride, dst, dst_stride, w, h, + y_filter_8tap); +} + +void vpx_convolve8_avg_neon_dotprod(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + DECLARE_ALIGNED(32, uint8_t, im_block[64 * 71]); + const int im_stride = 64; + + // Averaging convolution always uses an 8-tap filter. + // Account for the vertical phase needing 3 lines prior and 4 lines post. + const int im_height = h + SUBPEL_TAPS - 1; + const ptrdiff_t offset = SUBPEL_TAPS / 2 - 1; + + assert(y_step_q4 == 16); + assert(x_step_q4 == 16); + + const int8x8_t x_filter_8tap = vmovn_s16(vld1q_s16(filter[x0_q4])); + + convolve_8tap_2d_horiz_neon_dotprod(src - offset - offset * src_stride, + src_stride, im_block, im_stride, w, + im_height, x_filter_8tap); + + vpx_convolve8_avg_vert_neon_dotprod(im_block + offset * im_stride, im_stride, + dst, dst_stride, filter, x0_q4, x_step_q4, + y0_q4, y_step_q4, w, h); +} diff --git a/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon_i8mm.c b/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon_i8mm.c new file mode 100644 index 0000000000..b9d88bcfb1 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/vpx_convolve8_neon_i8mm.c @@ -0,0 +1,943 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" +#include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" +#include "vpx_dsp/arm/transpose_neon.h" +#include "vpx_dsp/arm/vpx_convolve8_neon.h" +#include "vpx_dsp/vpx_filter.h" +#include "vpx_ports/mem.h" + +DECLARE_ALIGNED(16, static const uint8_t, dot_prod_permute_tbl[48]) = { + 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, + 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, + 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14 +}; + +DECLARE_ALIGNED(16, static const uint8_t, dot_prod_merge_block_tbl[48]) = { + // Shift left and insert new last column in transposed 4x4 block. + 1, 2, 3, 16, 5, 6, 7, 20, 9, 10, 11, 24, 13, 14, 15, 28, + // Shift left and insert two new columns in transposed 4x4 block. + 2, 3, 16, 17, 6, 7, 20, 21, 10, 11, 24, 25, 14, 15, 28, 29, + // Shift left and insert three new columns in transposed 4x4 block. + 3, 16, 17, 18, 7, 20, 21, 22, 11, 24, 25, 26, 15, 28, 29, 30 +}; + +static INLINE int16x4_t convolve4_4_h(const uint8x16_t samples, + const int8x8_t filters, + const uint8x16_t permute_tbl) { + // Permute samples ready for dot product. + // { 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6 } + uint8x16_t permuted_samples = vqtbl1q_u8(samples, permute_tbl); + + int32x4_t sum = + vusdotq_lane_s32(vdupq_n_s32(0), permuted_samples, filters, 0); + + // Further narrowing and packing is performed by the caller. + return vmovn_s32(sum); +} + +static INLINE uint8x8_t convolve4_8_h(const uint8x16_t samples, + const int8x8_t filters, + const uint8x16x2_t permute_tbl) { + // Permute samples ready for dot product. + // { 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6 } + // { 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10 } + uint8x16_t permuted_samples[2] = { vqtbl1q_u8(samples, permute_tbl.val[0]), + vqtbl1q_u8(samples, permute_tbl.val[1]) }; + + // First 4 output values. + int32x4_t sum0 = + vusdotq_lane_s32(vdupq_n_s32(0), permuted_samples[0], filters, 0); + // Second 4 output values. + int32x4_t sum1 = + vusdotq_lane_s32(vdupq_n_s32(0), permuted_samples[1], filters, 0); + + // Narrow and re-pack. + int16x8_t sum = vcombine_s16(vmovn_s32(sum0), vmovn_s32(sum1)); + // We halved the filter values so -1 from right shift. + return vqrshrun_n_s16(sum, FILTER_BITS - 1); +} + +static INLINE int16x4_t convolve8_4_h(const uint8x16_t samples, + const int8x8_t filters, + const uint8x16x2_t permute_tbl) { + // Permute samples ready for dot product. + // { 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6 } + // { 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10 } + uint8x16_t permuted_samples[2] = { vqtbl1q_u8(samples, permute_tbl.val[0]), + vqtbl1q_u8(samples, permute_tbl.val[1]) }; + + int32x4_t sum = + vusdotq_lane_s32(vdupq_n_s32(0), permuted_samples[0], filters, 0); + sum = vusdotq_lane_s32(sum, permuted_samples[1], filters, 1); + + // Further narrowing and packing is performed by the caller. + return vshrn_n_s32(sum, 1); +} + +static INLINE uint8x8_t convolve8_8_h(const uint8x16_t samples, + const int8x8_t filters, + const uint8x16x3_t permute_tbl) { + // Permute samples ready for dot product. + // { 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6 } + // { 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10 } + // { 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14 } + uint8x16_t permuted_samples[3] = { vqtbl1q_u8(samples, permute_tbl.val[0]), + vqtbl1q_u8(samples, permute_tbl.val[1]), + vqtbl1q_u8(samples, permute_tbl.val[2]) }; + + // First 4 output values. + int32x4_t sum0 = + vusdotq_lane_s32(vdupq_n_s32(0), permuted_samples[0], filters, 0); + sum0 = vusdotq_lane_s32(sum0, permuted_samples[1], filters, 1); + // Second 4 output values. + int32x4_t sum1 = + vusdotq_lane_s32(vdupq_n_s32(0), permuted_samples[1], filters, 0); + sum1 = vusdotq_lane_s32(sum1, permuted_samples[2], filters, 1); + + // Narrow and re-pack. + int16x8_t sum = vcombine_s16(vshrn_n_s32(sum0, 1), vshrn_n_s32(sum1, 1)); + return vqrshrun_n_s16(sum, FILTER_BITS - 1); +} + +static INLINE void convolve_4tap_horiz_neon_i8mm(const uint8_t *src, + ptrdiff_t src_stride, + uint8_t *dst, + ptrdiff_t dst_stride, int w, + int h, const int8x8_t filter) { + if (w == 4) { + const uint8x16_t permute_tbl = vld1q_u8(dot_prod_permute_tbl); + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(src, src_stride, &s0, &s1, &s2, &s3); + + int16x4_t t0 = convolve4_4_h(s0, filter, permute_tbl); + int16x4_t t1 = convolve4_4_h(s1, filter, permute_tbl); + int16x4_t t2 = convolve4_4_h(s2, filter, permute_tbl); + int16x4_t t3 = convolve4_4_h(s3, filter, permute_tbl); + // We halved the filter values so -1 from right shift. + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(t0, t1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(t2, t3), FILTER_BITS - 1); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(s, src_stride, &s0, &s1, &s2, &s3); + + uint8x8_t d0 = convolve4_8_h(s0, filter, permute_tbl); + uint8x8_t d1 = convolve4_8_h(s1, filter, permute_tbl); + uint8x8_t d2 = convolve4_8_h(s2, filter, permute_tbl); + uint8x8_t d3 = convolve4_8_h(s3, filter, permute_tbl); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } +} + +static INLINE void convolve_8tap_horiz_neon_i8mm(const uint8_t *src, + ptrdiff_t src_stride, + uint8_t *dst, + ptrdiff_t dst_stride, int w, + int h, const int8x8_t filter) { + if (w == 4) { + const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(src, src_stride, &s0, &s1, &s2, &s3); + + int16x4_t t0 = convolve8_4_h(s0, filter, permute_tbl); + int16x4_t t1 = convolve8_4_h(s1, filter, permute_tbl); + int16x4_t t2 = convolve8_4_h(s2, filter, permute_tbl); + int16x4_t t3 = convolve8_4_h(s3, filter, permute_tbl); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(t0, t1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(t2, t3), FILTER_BITS - 1); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint8x16x3_t permute_tbl = vld1q_u8_x3(dot_prod_permute_tbl); + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(s, src_stride, &s0, &s1, &s2, &s3); + + uint8x8_t d0 = convolve8_8_h(s0, filter, permute_tbl); + uint8x8_t d1 = convolve8_8_h(s1, filter, permute_tbl); + uint8x8_t d2 = convolve8_8_h(s2, filter, permute_tbl); + uint8x8_t d3 = convolve8_8_h(s3, filter, permute_tbl); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } +} + +void vpx_convolve8_horiz_neon_i8mm(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(x_step_q4 == 16); + + (void)x_step_q4; + (void)y0_q4; + (void)y_step_q4; + + if (vpx_get_filter_taps(filter[x0_q4]) <= 4) { + // Load 4-tap filter into first 4 elements of the vector. + // All 4-tap and bilinear filter values are even, so halve them to reduce + // intermediate precision requirements. + const int16x4_t x_filter = vld1_s16(filter[x0_q4] + 2); + const int8x8_t x_filter_4tap = + vshrn_n_s16(vcombine_s16(x_filter, vdup_n_s16(0)), 1); + + convolve_4tap_horiz_neon_i8mm(src - 1, src_stride, dst, dst_stride, w, h, + x_filter_4tap); + + } else { + const int8x8_t x_filter_8tap = vmovn_s16(vld1q_s16(filter[x0_q4])); + + convolve_8tap_horiz_neon_i8mm(src - 3, src_stride, dst, dst_stride, w, h, + x_filter_8tap); + } +} + +void vpx_convolve8_avg_horiz_neon_i8mm(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + const int8x8_t filters = vmovn_s16(vld1q_s16(filter[x0_q4])); + + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(x_step_q4 == 16); + + (void)x_step_q4; + (void)y0_q4; + (void)y_step_q4; + + src -= 3; + + if (w == 4) { + const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(src, src_stride, &s0, &s1, &s2, &s3); + + int16x4_t t0 = convolve8_4_h(s0, filters, permute_tbl); + int16x4_t t1 = convolve8_4_h(s1, filters, permute_tbl); + int16x4_t t2 = convolve8_4_h(s2, filters, permute_tbl); + int16x4_t t3 = convolve8_4_h(s3, filters, permute_tbl); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(t0, t1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(t2, t3), FILTER_BITS - 1); + + uint8x8_t dd01 = load_u8(dst + 0 * dst_stride, dst_stride); + uint8x8_t dd23 = load_u8(dst + 2 * dst_stride, dst_stride); + + d01 = vrhadd_u8(d01, dd01); + d23 = vrhadd_u8(d23, dd23); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint8x16x3_t permute_tbl = vld1q_u8_x3(dot_prod_permute_tbl); + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(s, src_stride, &s0, &s1, &s2, &s3); + + uint8x8_t d0 = convolve8_8_h(s0, filters, permute_tbl); + uint8x8_t d1 = convolve8_8_h(s1, filters, permute_tbl); + uint8x8_t d2 = convolve8_8_h(s2, filters, permute_tbl); + uint8x8_t d3 = convolve8_8_h(s3, filters, permute_tbl); + + uint8x8_t dd0, dd1, dd2, dd3; + load_u8_8x4(d, dst_stride, &dd0, &dd1, &dd2, &dd3); + + d0 = vrhadd_u8(d0, dd0); + d1 = vrhadd_u8(d1, dd1); + d2 = vrhadd_u8(d2, dd2); + d3 = vrhadd_u8(d3, dd3); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width != 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } +} + +static INLINE int16x4_t convolve8_4_v(const uint8x16_t samples_lo, + const uint8x16_t samples_hi, + const int8x8_t filters) { + // Sample permutation is performed by the caller. + int32x4_t sum = vusdotq_lane_s32(vdupq_n_s32(0), samples_lo, filters, 0); + sum = vusdotq_lane_s32(sum, samples_hi, filters, 1); + + // Further narrowing and packing is performed by the caller. + return vshrn_n_s32(sum, 1); +} + +static INLINE uint8x8_t convolve8_8_v(const uint8x16_t samples0_lo, + const uint8x16_t samples0_hi, + const uint8x16_t samples1_lo, + const uint8x16_t samples1_hi, + const int8x8_t filters) { + // Sample permutation is performed by the caller. + + // First 4 output values. + int32x4_t sum0 = vusdotq_lane_s32(vdupq_n_s32(0), samples0_lo, filters, 0); + sum0 = vusdotq_lane_s32(sum0, samples0_hi, filters, 1); + // Second 4 output values. + int32x4_t sum1 = vusdotq_lane_s32(vdupq_n_s32(0), samples1_lo, filters, 0); + sum1 = vusdotq_lane_s32(sum1, samples1_hi, filters, 1); + + // Narrow and re-pack. + int16x8_t sum = vcombine_s16(vshrn_n_s32(sum0, 1), vshrn_n_s32(sum1, 1)); + return vqrshrun_n_s16(sum, FILTER_BITS - 1); +} + +static INLINE void convolve_8tap_vert_neon_i8mm(const uint8_t *src, + ptrdiff_t src_stride, + uint8_t *dst, + ptrdiff_t dst_stride, int w, + int h, const int8x8_t filter) { + const uint8x16x3_t merge_block_tbl = vld1q_u8_x3(dot_prod_merge_block_tbl); + if (w == 4) { + uint8x8_t s0, s1, s2, s3, s4, s5, s6; + load_u8_8x7(src, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6); + src += 7 * src_stride; + + // This operation combines a conventional transpose and the sample permute + // (see horizontal case) required before computing the dot product. + uint8x16_t s0123, s1234, s2345, s3456; + transpose_concat_u8_4x4(s0, s1, s2, s3, &s0123); + transpose_concat_u8_4x4(s1, s2, s3, s4, &s1234); + transpose_concat_u8_4x4(s2, s3, s4, s5, &s2345); + transpose_concat_u8_4x4(s3, s4, s5, s6, &s3456); + + do { + uint8x8_t s7, s8, s9, s10; + load_u8_8x4(src, src_stride, &s7, &s8, &s9, &s10); + + uint8x16_t s78910; + transpose_concat_u8_4x4(s7, s8, s9, s10, &s78910); + + // Merge new data into block from previous iteration. + uint8x16x2_t samples_LUT = { { s3456, s78910 } }; + uint8x16_t s4567 = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[0]); + uint8x16_t s5678 = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[1]); + uint8x16_t s6789 = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[2]); + + int16x4_t d0 = convolve8_4_v(s0123, s4567, filter); + int16x4_t d1 = convolve8_4_v(s1234, s5678, filter); + int16x4_t d2 = convolve8_4_v(s2345, s6789, filter); + int16x4_t d3 = convolve8_4_v(s3456, s78910, filter); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), FILTER_BITS - 1); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + // Prepare block for next iteration - re-using as much as possible. + // Shuffle everything up four rows. + s0123 = s4567; + s1234 = s5678; + s2345 = s6789; + s3456 = s78910; + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + do { + const uint8_t *s = src; + uint8_t *d = dst; + int height = h; + + uint8x8_t s0, s1, s2, s3, s4, s5, s6; + load_u8_8x7(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6); + s += 7 * src_stride; + + // This operation combines a conventional transpose and the sample permute + // (see horizontal case) required before computing the dot product. + uint8x16_t s0123_lo, s0123_hi, s1234_lo, s1234_hi, s2345_lo, s2345_hi, + s3456_lo, s3456_hi; + transpose_concat_u8_8x4(s0, s1, s2, s3, &s0123_lo, &s0123_hi); + transpose_concat_u8_8x4(s1, s2, s3, s4, &s1234_lo, &s1234_hi); + transpose_concat_u8_8x4(s2, s3, s4, s5, &s2345_lo, &s2345_hi); + transpose_concat_u8_8x4(s3, s4, s5, s6, &s3456_lo, &s3456_hi); + + do { + uint8x8_t s7, s8, s9, s10; + load_u8_8x4(s, src_stride, &s7, &s8, &s9, &s10); + + uint8x16_t s78910_lo, s78910_hi; + transpose_concat_u8_8x4(s7, s8, s9, s10, &s78910_lo, &s78910_hi); + + // Merge new data into block from previous iteration. + uint8x16x2_t samples_LUT = { { s3456_lo, s78910_lo } }; + uint8x16_t s4567_lo = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[0]); + uint8x16_t s5678_lo = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[1]); + uint8x16_t s6789_lo = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[2]); + + samples_LUT.val[0] = s3456_hi; + samples_LUT.val[1] = s78910_hi; + uint8x16_t s4567_hi = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[0]); + uint8x16_t s5678_hi = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[1]); + uint8x16_t s6789_hi = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[2]); + + uint8x8_t d0 = + convolve8_8_v(s0123_lo, s4567_lo, s0123_hi, s4567_hi, filter); + uint8x8_t d1 = + convolve8_8_v(s1234_lo, s5678_lo, s1234_hi, s5678_hi, filter); + uint8x8_t d2 = + convolve8_8_v(s2345_lo, s6789_lo, s2345_hi, s6789_hi, filter); + uint8x8_t d3 = + convolve8_8_v(s3456_lo, s78910_lo, s3456_hi, s78910_hi, filter); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + // Prepare block for next iteration - re-using as much as possible. + // Shuffle everything up four rows. + s0123_lo = s4567_lo; + s0123_hi = s4567_hi; + s1234_lo = s5678_lo; + s1234_hi = s5678_hi; + s2345_lo = s6789_lo; + s2345_hi = s6789_hi; + s3456_lo = s78910_lo; + s3456_hi = s78910_hi; + + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); + } +} + +void vpx_convolve8_vert_neon_i8mm(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(y_step_q4 == 16); + + (void)x0_q4; + (void)x_step_q4; + (void)y_step_q4; + + if (vpx_get_filter_taps(filter[y0_q4]) <= 4) { + const int16x8_t y_filter = vld1q_s16(filter[y0_q4]); + + convolve_4tap_vert_neon(src - src_stride, src_stride, dst, dst_stride, w, h, + y_filter); + } else { + const int8x8_t y_filter = vmovn_s16(vld1q_s16(filter[y0_q4])); + + convolve_8tap_vert_neon_i8mm(src - 3 * src_stride, src_stride, dst, + dst_stride, w, h, y_filter); + } +} + +void vpx_convolve8_avg_vert_neon_i8mm(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, + int w, int h) { + const int8x8_t filters = vmovn_s16(vld1q_s16(filter[y0_q4])); + const uint8x16x3_t merge_block_tbl = vld1q_u8_x3(dot_prod_merge_block_tbl); + + assert((intptr_t)dst % 4 == 0); + assert(dst_stride % 4 == 0); + assert(y_step_q4 == 16); + + (void)x0_q4; + (void)x_step_q4; + (void)y_step_q4; + + src -= 3 * src_stride; + + if (w == 4) { + uint8x8_t s0, s1, s2, s3, s4, s5, s6; + load_u8_8x7(src, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6); + src += 7 * src_stride; + + // This operation combines a conventional transpose and the sample permute + // (see horizontal case) required before computing the dot product. + uint8x16_t s0123, s1234, s2345, s3456; + transpose_concat_u8_4x4(s0, s1, s2, s3, &s0123); + transpose_concat_u8_4x4(s1, s2, s3, s4, &s1234); + transpose_concat_u8_4x4(s2, s3, s4, s5, &s2345); + transpose_concat_u8_4x4(s3, s4, s5, s6, &s3456); + + do { + uint8x8_t s7, s8, s9, s10; + load_u8_8x4(src, src_stride, &s7, &s8, &s9, &s10); + + uint8x16_t s78910; + transpose_concat_u8_4x4(s7, s8, s9, s10, &s78910); + + // Merge new data into block from previous iteration. + uint8x16x2_t samples_LUT = { { s3456, s78910 } }; + uint8x16_t s4567 = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[0]); + uint8x16_t s5678 = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[1]); + uint8x16_t s6789 = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[2]); + + int16x4_t d0 = convolve8_4_v(s0123, s4567, filters); + int16x4_t d1 = convolve8_4_v(s1234, s5678, filters); + int16x4_t d2 = convolve8_4_v(s2345, s6789, filters); + int16x4_t d3 = convolve8_4_v(s3456, s78910, filters); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), FILTER_BITS - 1); + + uint8x8_t dd01 = load_u8(dst + 0 * dst_stride, dst_stride); + uint8x8_t dd23 = load_u8(dst + 2 * dst_stride, dst_stride); + + d01 = vrhadd_u8(d01, dd01); + d23 = vrhadd_u8(d23, dd23); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + // Prepare block for next iteration - re-using as much as possible. + // Shuffle everything up four rows. + s0123 = s4567; + s1234 = s5678; + s2345 = s6789; + s3456 = s78910; + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + do { + const uint8_t *s = src; + uint8_t *d = dst; + int height = h; + + uint8x8_t s0, s1, s2, s3, s4, s5, s6; + load_u8_8x7(s, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6); + s += 7 * src_stride; + + // This operation combines a conventional transpose and the sample permute + // (see horizontal case) required before computing the dot product. + uint8x16_t s0123_lo, s0123_hi, s1234_lo, s1234_hi, s2345_lo, s2345_hi, + s3456_lo, s3456_hi; + transpose_concat_u8_8x4(s0, s1, s2, s3, &s0123_lo, &s0123_hi); + transpose_concat_u8_8x4(s1, s2, s3, s4, &s1234_lo, &s1234_hi); + transpose_concat_u8_8x4(s2, s3, s4, s5, &s2345_lo, &s2345_hi); + transpose_concat_u8_8x4(s3, s4, s5, s6, &s3456_lo, &s3456_hi); + + do { + uint8x8_t s7, s8, s9, s10; + load_u8_8x4(s, src_stride, &s7, &s8, &s9, &s10); + + uint8x16_t s78910_lo, s78910_hi; + transpose_concat_u8_8x4(s7, s8, s9, s10, &s78910_lo, &s78910_hi); + + // Merge new data into block from previous iteration. + uint8x16x2_t samples_LUT = { { s3456_lo, s78910_lo } }; + uint8x16_t s4567_lo = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[0]); + uint8x16_t s5678_lo = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[1]); + uint8x16_t s6789_lo = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[2]); + + samples_LUT.val[0] = s3456_hi; + samples_LUT.val[1] = s78910_hi; + uint8x16_t s4567_hi = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[0]); + uint8x16_t s5678_hi = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[1]); + uint8x16_t s6789_hi = vqtbl2q_u8(samples_LUT, merge_block_tbl.val[2]); + + uint8x8_t d0 = + convolve8_8_v(s0123_lo, s4567_lo, s0123_hi, s4567_hi, filters); + uint8x8_t d1 = + convolve8_8_v(s1234_lo, s5678_lo, s1234_hi, s5678_hi, filters); + uint8x8_t d2 = + convolve8_8_v(s2345_lo, s6789_lo, s2345_hi, s6789_hi, filters); + uint8x8_t d3 = + convolve8_8_v(s3456_lo, s78910_lo, s3456_hi, s78910_hi, filters); + + uint8x8_t dd0, dd1, dd2, dd3; + load_u8_8x4(d, dst_stride, &dd0, &dd1, &dd2, &dd3); + + d0 = vrhadd_u8(d0, dd0); + d1 = vrhadd_u8(d1, dd1); + d2 = vrhadd_u8(d2, dd2); + d3 = vrhadd_u8(d3, dd3); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + /* Prepare block for next iteration - re-using as much as possible. */ + /* Shuffle everything up four rows. */ + s0123_lo = s4567_lo; + s0123_hi = s4567_hi; + s1234_lo = s5678_lo; + s1234_hi = s5678_hi; + s2345_lo = s6789_lo; + s2345_hi = s6789_hi; + s3456_lo = s78910_lo; + s3456_hi = s78910_hi; + + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); + } +} + +static INLINE void convolve_4tap_2d_neon_i8mm(const uint8_t *src, + ptrdiff_t src_stride, + uint8_t *dst, + ptrdiff_t dst_stride, int w, + int h, const int8x8_t x_filter, + const uint8x8_t y_filter) { + // Neon does not have lane-referencing multiply or multiply-accumulate + // instructions that operate on vectors of 8-bit elements. This means we have + // to duplicate filter taps into a whole vector and use standard multiply / + // multiply-accumulate instructions. + const uint8x8_t y_filter_taps[4] = { vdup_lane_u8(y_filter, 2), + vdup_lane_u8(y_filter, 3), + vdup_lane_u8(y_filter, 4), + vdup_lane_u8(y_filter, 5) }; + + if (w == 4) { + const uint8x16_t permute_tbl = vld1q_u8(dot_prod_permute_tbl); + + uint8x16_t h_s0, h_s1, h_s2; + load_u8_16x3(src, src_stride, &h_s0, &h_s1, &h_s2); + + int16x4_t t0 = convolve4_4_h(h_s0, x_filter, permute_tbl); + int16x4_t t1 = convolve4_4_h(h_s1, x_filter, permute_tbl); + int16x4_t t2 = convolve4_4_h(h_s2, x_filter, permute_tbl); + // We halved the filter values so -1 from right shift. + uint8x8_t v_s01 = vqrshrun_n_s16(vcombine_s16(t0, t1), FILTER_BITS - 1); + uint8x8_t v_s12 = vqrshrun_n_s16(vcombine_s16(t1, t2), FILTER_BITS - 1); + + src += 3 * src_stride; + + do { + uint8x16_t h_s3, h_s4, h_s5, h_s6; + load_u8_16x4(src, src_stride, &h_s3, &h_s4, &h_s5, &h_s6); + + int16x4_t t3 = convolve4_4_h(h_s3, x_filter, permute_tbl); + int16x4_t t4 = convolve4_4_h(h_s4, x_filter, permute_tbl); + int16x4_t t5 = convolve4_4_h(h_s5, x_filter, permute_tbl); + int16x4_t t6 = convolve4_4_h(h_s6, x_filter, permute_tbl); + // We halved the filter values so -1 from right shift. + uint8x8_t v_s34 = vqrshrun_n_s16(vcombine_s16(t3, t4), FILTER_BITS - 1); + uint8x8_t v_s56 = vqrshrun_n_s16(vcombine_s16(t5, t6), FILTER_BITS - 1); + uint8x8_t v_s23 = vext_u8(v_s12, v_s34, 4); + uint8x8_t v_s45 = vext_u8(v_s34, v_s56, 4); + + uint8x8_t d01 = convolve4_8(v_s01, v_s12, v_s23, v_s34, y_filter_taps); + uint8x8_t d23 = convolve4_8(v_s23, v_s34, v_s45, v_s56, y_filter_taps); + + store_unaligned_u8(dst + 0 * dst_stride, dst_stride, d01); + store_unaligned_u8(dst + 2 * dst_stride, dst_stride, d23); + + v_s01 = v_s45; + v_s12 = v_s56; + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h != 0); + } else { + const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int height = h; + + uint8x16_t h_s0, h_s1, h_s2; + load_u8_16x3(s, src_stride, &h_s0, &h_s1, &h_s2); + + uint8x8_t v_s0 = convolve4_8_h(h_s0, x_filter, permute_tbl); + uint8x8_t v_s1 = convolve4_8_h(h_s1, x_filter, permute_tbl); + uint8x8_t v_s2 = convolve4_8_h(h_s2, x_filter, permute_tbl); + + s += 3 * src_stride; + + do { + uint8x16_t h_s3, h_s4, h_s5, h_s6; + load_u8_16x4(s, src_stride, &h_s3, &h_s4, &h_s5, &h_s6); + + uint8x8_t v_s3 = convolve4_8_h(h_s3, x_filter, permute_tbl); + uint8x8_t v_s4 = convolve4_8_h(h_s4, x_filter, permute_tbl); + uint8x8_t v_s5 = convolve4_8_h(h_s5, x_filter, permute_tbl); + uint8x8_t v_s6 = convolve4_8_h(h_s6, x_filter, permute_tbl); + + uint8x8_t d0 = convolve4_8(v_s0, v_s1, v_s2, v_s3, y_filter_taps); + uint8x8_t d1 = convolve4_8(v_s1, v_s2, v_s3, v_s4, y_filter_taps); + uint8x8_t d2 = convolve4_8(v_s2, v_s3, v_s4, v_s5, y_filter_taps); + uint8x8_t d3 = convolve4_8(v_s3, v_s4, v_s5, v_s6, y_filter_taps); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + v_s0 = v_s4; + v_s1 = v_s5; + v_s2 = v_s6; + s += 4 * src_stride; + d += 4 * dst_stride; + height -= 4; + } while (height != 0); + src += 8; + dst += 8; + w -= 8; + } while (w != 0); + } +} + +static INLINE void convolve_8tap_2d_horiz_neon_i8mm( + const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, + ptrdiff_t dst_stride, int w, int h, const int8x8_t filter) { + if (w == 4) { + const uint8x16x2_t permute_tbl = vld1q_u8_x2(dot_prod_permute_tbl); + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(src, src_stride, &s0, &s1, &s2, &s3); + + int16x4_t d0 = convolve8_4_h(s0, filter, permute_tbl); + int16x4_t d1 = convolve8_4_h(s1, filter, permute_tbl); + int16x4_t d2 = convolve8_4_h(s2, filter, permute_tbl); + int16x4_t d3 = convolve8_4_h(s3, filter, permute_tbl); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS - 1); + uint8x8_t d23 = vqrshrun_n_s16(vcombine_s16(d2, d3), FILTER_BITS - 1); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8(dst + 2 * dst_stride, dst_stride, d23); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h > 3); + + // Process final three rows (h % 4 == 3). See vpx_convolve_neon_i8mm() + // below for further details on possible values of block height. + uint8x16_t s0, s1, s2; + load_u8_16x3(src, src_stride, &s0, &s1, &s2); + + int16x4_t d0 = convolve8_4_h(s0, filter, permute_tbl); + int16x4_t d1 = convolve8_4_h(s1, filter, permute_tbl); + int16x4_t d2 = convolve8_4_h(s2, filter, permute_tbl); + uint8x8_t d01 = vqrshrun_n_s16(vcombine_s16(d0, d1), FILTER_BITS - 1); + uint8x8_t d23 = + vqrshrun_n_s16(vcombine_s16(d2, vdup_n_s16(0)), FILTER_BITS - 1); + + store_u8(dst + 0 * dst_stride, dst_stride, d01); + store_u8_4x1(dst + 2 * dst_stride, d23); + } else { + const uint8x16x3_t permute_tbl = vld1q_u8_x3(dot_prod_permute_tbl); + + do { + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0, s1, s2, s3; + load_u8_16x4(s, src_stride, &s0, &s1, &s2, &s3); + + uint8x8_t d0 = convolve8_8_h(s0, filter, permute_tbl); + uint8x8_t d1 = convolve8_8_h(s1, filter, permute_tbl); + uint8x8_t d2 = convolve8_8_h(s2, filter, permute_tbl); + uint8x8_t d3 = convolve8_8_h(s3, filter, permute_tbl); + + store_u8_8x4(d, dst_stride, d0, d1, d2, d3); + + s += 8; + d += 8; + width -= 8; + } while (width > 0); + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h > 3); + + // Process final three rows (h % 4 == 3). See vpx_convolve_neon_i8mm() + // below for further details on possible values of block height. + const uint8_t *s = src; + uint8_t *d = dst; + int width = w; + + do { + uint8x16_t s0, s1, s2; + load_u8_16x3(s, src_stride, &s0, &s1, &s2); + + uint8x8_t d0 = convolve8_8_h(s0, filter, permute_tbl); + uint8x8_t d1 = convolve8_8_h(s1, filter, permute_tbl); + uint8x8_t d2 = convolve8_8_h(s2, filter, permute_tbl); + + store_u8_8x3(d, dst_stride, d0, d1, d2); + + s += 8; + d += 8; + width -= 8; + } while (width > 0); + } +} + +void vpx_convolve8_neon_i8mm(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + assert(x_step_q4 == 16); + assert(y_step_q4 == 16); + + (void)x_step_q4; + (void)y_step_q4; + + const int x_filter_taps = vpx_get_filter_taps(filter[x0_q4]) <= 4 ? 4 : 8; + const int y_filter_taps = vpx_get_filter_taps(filter[y0_q4]) <= 4 ? 4 : 8; + // Account for needing filter_taps / 2 - 1 lines prior and filter_taps / 2 + // lines post both horizontally and vertically. + const ptrdiff_t horiz_offset = x_filter_taps / 2 - 1; + const ptrdiff_t vert_offset = (y_filter_taps / 2 - 1) * src_stride; + + if (x_filter_taps == 4 && y_filter_taps == 4) { + const int16x4_t x_filter = vld1_s16(filter[x0_q4] + 2); + const int16x8_t y_filter = vld1q_s16(filter[y0_q4]); + + // 4-tap and bilinear filter values are even, so halve them to reduce + // intermediate precision requirements. + const int8x8_t x_filter_4tap = + vshrn_n_s16(vcombine_s16(x_filter, vdup_n_s16(0)), 1); + const uint8x8_t y_filter_4tap = + vshrn_n_u16(vreinterpretq_u16_s16(vabsq_s16(y_filter)), 1); + + convolve_4tap_2d_neon_i8mm(src - horiz_offset - vert_offset, src_stride, + dst, dst_stride, w, h, x_filter_4tap, + y_filter_4tap); + return; + } + + // Given our constraints: w <= 64, h <= 64, taps <= 8 we can reduce the + // maximum buffer size to 64 * (64 + 7). + DECLARE_ALIGNED(32, uint8_t, im_block[64 * 71]); + const int im_stride = 64; + const int im_height = h + SUBPEL_TAPS - 1; + + const int8x8_t x_filter_8tap = vmovn_s16(vld1q_s16(filter[x0_q4])); + const int8x8_t y_filter_8tap = vmovn_s16(vld1q_s16(filter[y0_q4])); + + convolve_8tap_2d_horiz_neon_i8mm(src - horiz_offset - vert_offset, src_stride, + im_block, im_stride, w, im_height, + x_filter_8tap); + + convolve_8tap_vert_neon_i8mm(im_block, im_stride, dst, dst_stride, w, h, + y_filter_8tap); +} + +void vpx_convolve8_avg_neon_i8mm(const uint8_t *src, ptrdiff_t src_stride, + uint8_t *dst, ptrdiff_t dst_stride, + const InterpKernel *filter, int x0_q4, + int x_step_q4, int y0_q4, int y_step_q4, int w, + int h) { + DECLARE_ALIGNED(32, uint8_t, im_block[64 * 71]); + const int im_stride = 64; + + // Averaging convolution always uses an 8-tap filter. + // Account for the vertical phase needing 3 lines prior and 4 lines post. + const int im_height = h + SUBPEL_TAPS - 1; + const ptrdiff_t offset = SUBPEL_TAPS / 2 - 1; + + assert(y_step_q4 == 16); + assert(x_step_q4 == 16); + + const int8x8_t x_filter_8tap = vmovn_s16(vld1q_s16(filter[x0_q4])); + + convolve_8tap_2d_horiz_neon_i8mm(src - offset - offset * src_stride, + src_stride, im_block, im_stride, w, + im_height, x_filter_8tap); + + vpx_convolve8_avg_vert_neon_i8mm(im_block + offset * im_stride, im_stride, + dst, dst_stride, filter, x0_q4, x_step_q4, + y0_q4, y_step_q4, w, h); +} diff --git a/libs/libvpx/vpx_dsp/arm/vpx_convolve_copy_neon.c b/libs/libvpx/vpx_dsp/arm/vpx_convolve_copy_neon.c index 361ec8a806..bea7c98437 100644 --- a/libs/libvpx/vpx_dsp/arm/vpx_convolve_copy_neon.c +++ b/libs/libvpx/vpx_dsp/arm/vpx_convolve_copy_neon.c @@ -9,6 +9,7 @@ */ #include +#include #include "./vpx_dsp_rtcd.h" #include "vpx/vpx_integer.h" @@ -26,10 +27,10 @@ void vpx_convolve_copy_neon(const uint8_t *src, ptrdiff_t src_stride, if (w < 8) { // copy4 do { - *(uint32_t *)dst = *(const uint32_t *)src; + memcpy(dst, src, 4); src += src_stride; dst += dst_stride; - *(uint32_t *)dst = *(const uint32_t *)src; + memcpy(dst, src, 4); src += src_stride; dst += dst_stride; h -= 2; diff --git a/libs/libvpx/vpx_dsp/arm/vpx_convolve_neon.c b/libs/libvpx/vpx_dsp/arm/vpx_convolve_neon.c index 830f3176d7..de5fa29471 100644 --- a/libs/libvpx/vpx_dsp/arm/vpx_convolve_neon.c +++ b/libs/libvpx/vpx_dsp/arm/vpx_convolve_neon.c @@ -12,35 +12,39 @@ #include "./vpx_dsp_rtcd.h" #include "vpx_dsp/vpx_dsp_common.h" +#include "vpx_dsp/vpx_filter.h" #include "vpx_ports/mem.h" void vpx_convolve8_neon(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h) { - /* Given our constraints: w <= 64, h <= 64, taps == 8 we can reduce the - * maximum buffer size to 64 * 64 + 7 (+ 1 to make it divisible by 4). - */ - uint8_t temp[64 * 72]; + // Given our constraints: w <= 64, h <= 64, taps <= 8 we can reduce the + // maximum buffer size to 64 * (64 + 7) (+1 row to make it divisible by 4). + DECLARE_ALIGNED(32, uint8_t, im_block[64 * 72]); + const int im_stride = 64; - // Account for the vertical phase needing 3 lines prior and 4 lines post - // (+ 1 to make it divisible by 4). - const int intermediate_height = h + 8; + const int vert_filter_taps = vpx_get_filter_taps(filter[y0_q4]) <= 4 ? 4 : 8; + // Account for the vertical phase needing vert_filter_taps / 2 - 1 lines prior + // and vert_filter_taps / 2 lines post. (+1 to make total divisible by 4.) + const int im_height = h + vert_filter_taps; + const ptrdiff_t border_offset = vert_filter_taps / 2 - 1; assert(y_step_q4 == 16); assert(x_step_q4 == 16); - /* Filter starting 3 lines back. The neon implementation will ignore the given - * height and filter a multiple of 4 lines. Since this goes in to the temp - * buffer which has lots of extra room and is subsequently discarded this is - * safe if somewhat less than ideal. */ - vpx_convolve8_horiz_neon(src - src_stride * 3, src_stride, temp, w, filter, - x0_q4, x_step_q4, y0_q4, y_step_q4, w, - intermediate_height); + // Filter starting border_offset rows back. The Neon implementation will + // ignore the given height and filter a multiple of 4 lines. Since this goes + // into the temporary buffer which has lots of extra room and is subsequently + // discarded this is safe if somewhat less than ideal. + vpx_convolve8_horiz_neon(src - src_stride * border_offset, src_stride, + im_block, im_stride, filter, x0_q4, x_step_q4, y0_q4, + y_step_q4, w, im_height); - /* Step into the temp buffer 3 lines to get the actual frame data */ - vpx_convolve8_vert_neon(temp + w * 3, w, dst, dst_stride, filter, x0_q4, - x_step_q4, y0_q4, y_step_q4, w, h); + // Step into the temporary buffer border_offset rows to get actual frame data. + vpx_convolve8_vert_neon(im_block + im_stride * border_offset, im_stride, dst, + dst_stride, filter, x0_q4, x_step_q4, y0_q4, + y_step_q4, w, h); } void vpx_convolve8_avg_neon(const uint8_t *src, ptrdiff_t src_stride, @@ -48,18 +52,21 @@ void vpx_convolve8_avg_neon(const uint8_t *src, ptrdiff_t src_stride, const InterpKernel *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h) { - uint8_t temp[64 * 72]; - const int intermediate_height = h + 8; + DECLARE_ALIGNED(32, uint8_t, im_block[64 * 72]); + const int im_stride = 64; + const int im_height = h + SUBPEL_TAPS; + const ptrdiff_t border_offset = SUBPEL_TAPS / 2 - 1; assert(y_step_q4 == 16); assert(x_step_q4 == 16); - /* This implementation has the same issues as above. In addition, we only want - * to average the values after both passes. - */ - vpx_convolve8_horiz_neon(src - src_stride * 3, src_stride, temp, w, filter, - x0_q4, x_step_q4, y0_q4, y_step_q4, w, - intermediate_height); - vpx_convolve8_avg_vert_neon(temp + w * 3, w, dst, dst_stride, filter, x0_q4, - x_step_q4, y0_q4, y_step_q4, w, h); + // This implementation has the same issues as above. In addition, we only want + // to average the values after both passes. + vpx_convolve8_horiz_neon(src - src_stride * border_offset, src_stride, + im_block, im_stride, filter, x0_q4, x_step_q4, y0_q4, + y_step_q4, w, im_height); + + vpx_convolve8_avg_vert_neon(im_block + im_stride * border_offset, im_stride, + dst, dst_stride, filter, x0_q4, x_step_q4, y0_q4, + y_step_q4, w, h); } diff --git a/libs/libvpx/vpx_dsp/arm/vpx_neon_sve2_bridge.h b/libs/libvpx/vpx_dsp/arm/vpx_neon_sve2_bridge.h new file mode 100644 index 0000000000..f30143e3e3 --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/vpx_neon_sve2_bridge.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VPX_DSP_ARM_VPX_NEON_SVE2_BRIDGE_H_ +#define VPX_VPX_DSP_ARM_VPX_NEON_SVE2_BRIDGE_H_ + +#include +#include +#include + +// Some very useful instructions are exclusive to the SVE2 instruction set. +// However, we can access these instructions from a predominantly Neon context +// by making use of the Neon-SVE bridge intrinsics to reinterpret Neon vectors +// as SVE vectors - with the high part of the SVE vector (if it's longer than +// 128 bits) being "don't care". + +static INLINE int16x8_t vpx_tbl2_s16(int16x8_t s0, int16x8_t s1, + uint16x8_t tbl) { + svint16x2_t samples = svcreate2_s16(svset_neonq_s16(svundef_s16(), s0), + svset_neonq_s16(svundef_s16(), s1)); + return svget_neonq_s16( + svtbl2_s16(samples, svset_neonq_u16(svundef_u16(), tbl))); +} + +static INLINE void vpx_tbl2x4_s16(int16x8_t s0[4], int16x8_t s1[4], + int16x8_t res[4], uint16x8_t idx) { + res[0] = vpx_tbl2_s16(s0[0], s1[0], idx); + res[1] = vpx_tbl2_s16(s0[1], s1[1], idx); + res[2] = vpx_tbl2_s16(s0[2], s1[2], idx); + res[3] = vpx_tbl2_s16(s0[3], s1[3], idx); +} + +static INLINE void vpx_tbl2x2_s16(int16x8_t s0[2], int16x8_t s1[2], + int16x8_t res[2], uint16x8_t idx) { + res[0] = vpx_tbl2_s16(s0[0], s1[0], idx); + res[1] = vpx_tbl2_s16(s0[1], s1[1], idx); +} + +#endif // VPX_VPX_DSP_ARM_VPX_NEON_SVE2_BRIDGE_H_ diff --git a/libs/libvpx/vpx_dsp/arm/vpx_neon_sve_bridge.h b/libs/libvpx/vpx_dsp/arm/vpx_neon_sve_bridge.h new file mode 100644 index 0000000000..2a2d89f42a --- /dev/null +++ b/libs/libvpx/vpx_dsp/arm/vpx_neon_sve_bridge.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VPX_DSP_ARM_VPX_NEON_SVE_BRIDGE_H_ +#define VPX_VPX_DSP_ARM_VPX_NEON_SVE_BRIDGE_H_ + +#include +#include +#include + +// Dot product instructions operating on 16-bit input elements are exclusive to +// the SVE instruction set. However, we can access these instructions from a +// predominantly Neon context by making use of the Neon-SVE bridge intrinsics +// to reinterpret Neon vectors as SVE vectors - with the high part of the SVE +// vector (if it's longer than 128 bits) being "don't care". + +// While sub-optimal on machines that have SVE vector length > 128-bit - as the +// remainder of the vector is unused - this approach is still beneficial when +// compared to a Neon-only solution. + +static INLINE uint64x2_t vpx_dotq_u16(uint64x2_t acc, uint16x8_t x, + uint16x8_t y) { + return svget_neonq_u64(svdot_u64(svset_neonq_u64(svundef_u64(), acc), + svset_neonq_u16(svundef_u16(), x), + svset_neonq_u16(svundef_u16(), y))); +} + +static INLINE int64x2_t vpx_dotq_s16(int64x2_t acc, int16x8_t x, int16x8_t y) { + return svget_neonq_s64(svdot_s64(svset_neonq_s64(svundef_s64(), acc), + svset_neonq_s16(svundef_s16(), x), + svset_neonq_s16(svundef_s16(), y))); +} + +#define vpx_dotq_lane_s16(acc, x, y, lane) \ + svget_neonq_s64(svdot_lane_s64(svset_neonq_s64(svundef_s64(), acc), \ + svset_neonq_s16(svundef_s16(), x), \ + svset_neonq_s16(svundef_s16(), y), lane)) + +static INLINE uint16x8_t vpx_tbl_u16(uint16x8_t data, uint16x8_t indices) { + return svget_neonq_u16(svtbl_u16(svset_neonq_u16(svundef_u16(), data), + svset_neonq_u16(svundef_u16(), indices))); +} + +static INLINE int16x8_t vpx_tbl_s16(int16x8_t data, uint16x8_t indices) { + return svget_neonq_s16(svtbl_s16(svset_neonq_s16(svundef_s16(), data), + svset_neonq_u16(svundef_u16(), indices))); +} + +#endif // VPX_VPX_DSP_ARM_VPX_NEON_SVE_BRIDGE_H_ diff --git a/libs/libvpx/vpx_dsp/arm/vpx_scaled_convolve8_neon.c b/libs/libvpx/vpx_dsp/arm/vpx_scaled_convolve8_neon.c index 8edf8a66e6..f40b6a907f 100644 --- a/libs/libvpx/vpx_dsp/arm/vpx_scaled_convolve8_neon.c +++ b/libs/libvpx/vpx_dsp/arm/vpx_scaled_convolve8_neon.c @@ -15,272 +15,277 @@ #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" #include "vpx/vpx_integer.h" +#include "vpx_dsp/arm/mem_neon.h" #include "vpx_dsp/arm/transpose_neon.h" #include "vpx_dsp/arm/vpx_convolve8_neon.h" +#include "vpx_dsp/vpx_filter.h" #include "vpx_ports/mem.h" -static INLINE void scaledconvolve_horiz_w4( +static INLINE void scaledconvolve_horiz_neon( const uint8_t *src, const ptrdiff_t src_stride, uint8_t *dst, - const ptrdiff_t dst_stride, const InterpKernel *const x_filters, - const int x0_q4, const int x_step_q4, const int w, const int h) { - DECLARE_ALIGNED(16, uint8_t, temp[4 * 4]); - int x, y, z; - - src -= SUBPEL_TAPS / 2 - 1; - - y = h; - do { - int x_q4 = x0_q4; - x = 0; - do { - // process 4 src_x steps - for (z = 0; z < 4; ++z) { - const uint8_t *const src_x = &src[x_q4 >> SUBPEL_BITS]; - if (x_q4 & SUBPEL_MASK) { - const int16x8_t filters = vld1q_s16(x_filters[x_q4 & SUBPEL_MASK]); - const int16x4_t filter3 = vdup_lane_s16(vget_low_s16(filters), 3); - const int16x4_t filter4 = vdup_lane_s16(vget_high_s16(filters), 0); - uint8x8_t s[8], d; - int16x8_t ss[4]; - int16x4_t t[8], tt; - - load_u8_8x4(src_x, src_stride, &s[0], &s[1], &s[2], &s[3]); - transpose_u8_8x4(&s[0], &s[1], &s[2], &s[3]); - - ss[0] = vreinterpretq_s16_u16(vmovl_u8(s[0])); - ss[1] = vreinterpretq_s16_u16(vmovl_u8(s[1])); - ss[2] = vreinterpretq_s16_u16(vmovl_u8(s[2])); - ss[3] = vreinterpretq_s16_u16(vmovl_u8(s[3])); - t[0] = vget_low_s16(ss[0]); - t[1] = vget_low_s16(ss[1]); - t[2] = vget_low_s16(ss[2]); - t[3] = vget_low_s16(ss[3]); - t[4] = vget_high_s16(ss[0]); - t[5] = vget_high_s16(ss[1]); - t[6] = vget_high_s16(ss[2]); - t[7] = vget_high_s16(ss[3]); - - tt = convolve8_4(t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], - filters, filter3, filter4); - d = vqrshrun_n_s16(vcombine_s16(tt, tt), 7); - vst1_lane_u32((uint32_t *)&temp[4 * z], vreinterpret_u32_u8(d), 0); - } else { - int i; - for (i = 0; i < 4; ++i) { - temp[z * 4 + i] = src_x[i * src_stride + 3]; - } - } - x_q4 += x_step_q4; - } - - // transpose the 4x4 filters values back to dst - { - const uint8x8x4_t d4 = vld4_u8(temp); - vst1_lane_u32((uint32_t *)&dst[x + 0 * dst_stride], - vreinterpret_u32_u8(d4.val[0]), 0); - vst1_lane_u32((uint32_t *)&dst[x + 1 * dst_stride], - vreinterpret_u32_u8(d4.val[1]), 0); - vst1_lane_u32((uint32_t *)&dst[x + 2 * dst_stride], - vreinterpret_u32_u8(d4.val[2]), 0); - vst1_lane_u32((uint32_t *)&dst[x + 3 * dst_stride], - vreinterpret_u32_u8(d4.val[3]), 0); - } - x += 4; - } while (x < w); - - src += src_stride * 4; - dst += dst_stride * 4; - y -= 4; - } while (y > 0); -} - -static INLINE void scaledconvolve_horiz_w8( - const uint8_t *src, const ptrdiff_t src_stride, uint8_t *dst, - const ptrdiff_t dst_stride, const InterpKernel *const x_filters, - const int x0_q4, const int x_step_q4, const int w, const int h) { + const ptrdiff_t dst_stride, const InterpKernel *const x_filter, + const int x0_q4, const int x_step_q4, int w, int h) { DECLARE_ALIGNED(16, uint8_t, temp[8 * 8]); - int x, y, z; + src -= SUBPEL_TAPS / 2 - 1; - // This function processes 8x8 areas. The intermediate height is not always - // a multiple of 8, so force it to be a multiple of 8 here. - y = (h + 7) & ~7; - - do { - int x_q4 = x0_q4; - x = 0; + if (w == 4) { do { - uint8x8_t d[8]; - // process 8 src_x steps - for (z = 0; z < 8; ++z) { - const uint8_t *const src_x = &src[x_q4 >> SUBPEL_BITS]; + int x_q4 = x0_q4; + + // Process a 4x4 tile. + for (int r = 0; r < 4; ++r) { + const uint8_t *s = &src[x_q4 >> SUBPEL_BITS]; if (x_q4 & SUBPEL_MASK) { - const int16x8_t filters = vld1q_s16(x_filters[x_q4 & SUBPEL_MASK]); - uint8x8_t s[8]; - load_u8_8x8(src_x, src_stride, &s[0], &s[1], &s[2], &s[3], &s[4], - &s[5], &s[6], &s[7]); - transpose_u8_8x8(&s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], - &s[7]); - d[0] = scale_filter_8(s, filters); - vst1_u8(&temp[8 * z], d[0]); + const int16x8_t filter = vld1q_s16(x_filter[x_q4 & SUBPEL_MASK]); + + uint8x8_t t0, t1, t2, t3; + load_u8_8x4(s, src_stride, &t0, &t1, &t2, &t3); + transpose_u8_8x4(&t0, &t1, &t2, &t3); + + int16x4_t s0 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t0))); + int16x4_t s1 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t1))); + int16x4_t s2 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t2))); + int16x4_t s3 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t3))); + int16x4_t s4 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t0))); + int16x4_t s5 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t1))); + int16x4_t s6 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t2))); + int16x4_t s7 = vget_high_s16(vreinterpretq_s16_u16(vmovl_u8(t3))); + + int16x4_t dd0 = convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filter); + uint8x8_t d0 = + vqrshrun_n_s16(vcombine_s16(dd0, vdup_n_s16(0)), FILTER_BITS); + + store_u8_4x1(&temp[4 * r], d0); } else { - int i; - for (i = 0; i < 8; ++i) { - temp[z * 8 + i] = src_x[i * src_stride + 3]; + // Memcpy for non-subpel locations. + s += SUBPEL_TAPS / 2 - 1; + + for (int c = 0; c < 4; ++c) { + temp[r * 4 + c] = s[c * src_stride]; } } x_q4 += x_step_q4; } - // transpose the 8x8 filters values back to dst - load_u8_8x8(temp, 8, &d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], - &d[7]); - transpose_u8_8x8(&d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7]); - vst1_u8(&dst[x + 0 * dst_stride], d[0]); - vst1_u8(&dst[x + 1 * dst_stride], d[1]); - vst1_u8(&dst[x + 2 * dst_stride], d[2]); - vst1_u8(&dst[x + 3 * dst_stride], d[3]); - vst1_u8(&dst[x + 4 * dst_stride], d[4]); - vst1_u8(&dst[x + 5 * dst_stride], d[5]); - vst1_u8(&dst[x + 6 * dst_stride], d[6]); - vst1_u8(&dst[x + 7 * dst_stride], d[7]); - x += 8; - } while (x < w); + // Transpose the 4x4 result tile and store. + uint8x8_t d01 = vld1_u8(temp + 0); + uint8x8_t d23 = vld1_u8(temp + 8); - src += src_stride * 8; - dst += dst_stride * 8; - } while (y -= 8); + transpose_u8_4x4(&d01, &d23); + + store_u8_4x1(dst + 0 * dst_stride, d01); + store_u8_4x1(dst + 1 * dst_stride, d23); + store_u8_4x1_high(dst + 2 * dst_stride, d01); + store_u8_4x1_high(dst + 3 * dst_stride, d23); + + src += 4 * src_stride; + dst += 4 * dst_stride; + h -= 4; + } while (h > 0); + return; + } + + do { + int x_q4 = x0_q4; + uint8_t *d = dst; + int width = w; + + do { + // Process an 8x8 tile. + for (int r = 0; r < 8; ++r) { + const uint8_t *s = &src[x_q4 >> SUBPEL_BITS]; + + if (x_q4 & SUBPEL_MASK) { + const int16x8_t filter = vld1q_s16(x_filter[x_q4 & SUBPEL_MASK]); + + uint8x8_t t0, t1, t2, t3, t4, t5, t6, t7; + load_u8_8x8(s, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); + + transpose_u8_8x8(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); + int16x8_t s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); + int16x8_t s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); + int16x8_t s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); + int16x8_t s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); + int16x8_t s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); + int16x8_t s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); + int16x8_t s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); + int16x8_t s7 = vreinterpretq_s16_u16(vmovl_u8(t7)); + + uint8x8_t d0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filter); + + vst1_u8(&temp[r * 8], d0); + } else { + // Memcpy for non-subpel locations. + s += SUBPEL_TAPS / 2 - 1; + + for (int c = 0; c < 8; ++c) { + temp[r * 8 + c] = s[c * src_stride]; + } + } + x_q4 += x_step_q4; + } + + // Transpose the 8x8 result tile and store. + uint8x8_t d0, d1, d2, d3, d4, d5, d6, d7; + load_u8_8x8(temp, 8, &d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7); + + transpose_u8_8x8(&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7); + + store_u8_8x8(d, dst_stride, d0, d1, d2, d3, d4, d5, d6, d7); + + d += 8; + width -= 8; + } while (width != 0); + + src += 8 * src_stride; + dst += 8 * dst_stride; + h -= 8; + } while (h > 0); } -static INLINE void scaledconvolve_vert_w4( +static INLINE void scaledconvolve_vert_neon( const uint8_t *src, const ptrdiff_t src_stride, uint8_t *dst, - const ptrdiff_t dst_stride, const InterpKernel *const y_filters, - const int y0_q4, const int y_step_q4, const int w, const int h) { - int y; + const ptrdiff_t dst_stride, const InterpKernel *const y_filter, + const int y0_q4, const int y_step_q4, int w, int h) { int y_q4 = y0_q4; - src -= src_stride * (SUBPEL_TAPS / 2 - 1); - y = h; + if (w == 4) { + do { + const uint8_t *s = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; + + if (y_q4 & SUBPEL_MASK) { + const int16x8_t filter = vld1q_s16(y_filter[y_q4 & SUBPEL_MASK]); + + uint8x8_t t0, t1, t2, t3, t4, t5, t6, t7; + load_u8_8x8(s, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); + int16x4_t s0 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t0))); + int16x4_t s1 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t1))); + int16x4_t s2 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t2))); + int16x4_t s3 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t3))); + int16x4_t s4 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t4))); + int16x4_t s5 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t5))); + int16x4_t s6 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t6))); + int16x4_t s7 = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(t7))); + + int16x4_t dd0 = convolve8_4(s0, s1, s2, s3, s4, s5, s6, s7, filter); + uint8x8_t d0 = + vqrshrun_n_s16(vcombine_s16(dd0, vdup_n_s16(0)), FILTER_BITS); + + store_u8_4x1(dst, d0); + } else { + // Memcpy for non-subpel locations. + memcpy(dst, &s[(SUBPEL_TAPS / 2 - 1) * src_stride], 4); + } + + y_q4 += y_step_q4; + dst += dst_stride; + } while (--h != 0); + return; + } + + if (w == 8) { + do { + const uint8_t *s = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; + + if (y_q4 & SUBPEL_MASK) { + const int16x8_t filter = vld1q_s16(y_filter[y_q4 & SUBPEL_MASK]); + + uint8x8_t t0, t1, t2, t3, t4, t5, t6, t7; + load_u8_8x8(s, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); + int16x8_t s0 = vreinterpretq_s16_u16(vmovl_u8(t0)); + int16x8_t s1 = vreinterpretq_s16_u16(vmovl_u8(t1)); + int16x8_t s2 = vreinterpretq_s16_u16(vmovl_u8(t2)); + int16x8_t s3 = vreinterpretq_s16_u16(vmovl_u8(t3)); + int16x8_t s4 = vreinterpretq_s16_u16(vmovl_u8(t4)); + int16x8_t s5 = vreinterpretq_s16_u16(vmovl_u8(t5)); + int16x8_t s6 = vreinterpretq_s16_u16(vmovl_u8(t6)); + int16x8_t s7 = vreinterpretq_s16_u16(vmovl_u8(t7)); + + uint8x8_t d0 = convolve8_8(s0, s1, s2, s3, s4, s5, s6, s7, filter); + + vst1_u8(dst, d0); + } else { + // Memcpy for non-subpel locations. + memcpy(dst, &s[(SUBPEL_TAPS / 2 - 1) * src_stride], 8); + } + + y_q4 += y_step_q4; + dst += dst_stride; + } while (--h != 0); + return; + } + do { - const unsigned char *src_y = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; + const uint8_t *s = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; + uint8_t *d = dst; + int width = w; if (y_q4 & SUBPEL_MASK) { - const int16x8_t filters = vld1q_s16(y_filters[y_q4 & SUBPEL_MASK]); - const int16x4_t filter3 = vdup_lane_s16(vget_low_s16(filters), 3); - const int16x4_t filter4 = vdup_lane_s16(vget_high_s16(filters), 0); - uint8x8_t s[8], d; - int16x4_t t[8], tt; - - load_u8_8x8(src_y, src_stride, &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], - &s[6], &s[7]); - t[0] = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(s[0]))); - t[1] = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(s[1]))); - t[2] = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(s[2]))); - t[3] = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(s[3]))); - t[4] = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(s[4]))); - t[5] = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(s[5]))); - t[6] = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(s[6]))); - t[7] = vget_low_s16(vreinterpretq_s16_u16(vmovl_u8(s[7]))); - - tt = convolve8_4(t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], filters, - filter3, filter4); - d = vqrshrun_n_s16(vcombine_s16(tt, tt), 7); - vst1_lane_u32((uint32_t *)dst, vreinterpret_u32_u8(d), 0); - } else { - memcpy(dst, &src_y[3 * src_stride], w); - } - - dst += dst_stride; - y_q4 += y_step_q4; - } while (--y); -} - -static INLINE void scaledconvolve_vert_w8( - const uint8_t *src, const ptrdiff_t src_stride, uint8_t *dst, - const ptrdiff_t dst_stride, const InterpKernel *const y_filters, - const int y0_q4, const int y_step_q4, const int w, const int h) { - int y; - int y_q4 = y0_q4; - - src -= src_stride * (SUBPEL_TAPS / 2 - 1); - y = h; - do { - const unsigned char *src_y = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; - if (y_q4 & SUBPEL_MASK) { - const int16x8_t filters = vld1q_s16(y_filters[y_q4 & SUBPEL_MASK]); - uint8x8_t s[8], d; - load_u8_8x8(src_y, src_stride, &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], - &s[6], &s[7]); - d = scale_filter_8(s, filters); - vst1_u8(dst, d); - } else { - memcpy(dst, &src_y[3 * src_stride], w); - } - dst += dst_stride; - y_q4 += y_step_q4; - } while (--y); -} - -static INLINE void scaledconvolve_vert_w16( - const uint8_t *src, const ptrdiff_t src_stride, uint8_t *dst, - const ptrdiff_t dst_stride, const InterpKernel *const y_filters, - const int y0_q4, const int y_step_q4, const int w, const int h) { - int x, y; - int y_q4 = y0_q4; - - src -= src_stride * (SUBPEL_TAPS / 2 - 1); - y = h; - do { - const unsigned char *src_y = &src[(y_q4 >> SUBPEL_BITS) * src_stride]; - if (y_q4 & SUBPEL_MASK) { - x = 0; do { - const int16x8_t filters = vld1q_s16(y_filters[y_q4 & SUBPEL_MASK]); - uint8x16_t ss[8]; - uint8x8_t s[8], d[2]; - load_u8_16x8(src_y, src_stride, &ss[0], &ss[1], &ss[2], &ss[3], &ss[4], - &ss[5], &ss[6], &ss[7]); - s[0] = vget_low_u8(ss[0]); - s[1] = vget_low_u8(ss[1]); - s[2] = vget_low_u8(ss[2]); - s[3] = vget_low_u8(ss[3]); - s[4] = vget_low_u8(ss[4]); - s[5] = vget_low_u8(ss[5]); - s[6] = vget_low_u8(ss[6]); - s[7] = vget_low_u8(ss[7]); - d[0] = scale_filter_8(s, filters); + const int16x8_t filter = vld1q_s16(y_filter[y_q4 & SUBPEL_MASK]); - s[0] = vget_high_u8(ss[0]); - s[1] = vget_high_u8(ss[1]); - s[2] = vget_high_u8(ss[2]); - s[3] = vget_high_u8(ss[3]); - s[4] = vget_high_u8(ss[4]); - s[5] = vget_high_u8(ss[5]); - s[6] = vget_high_u8(ss[6]); - s[7] = vget_high_u8(ss[7]); - d[1] = scale_filter_8(s, filters); - vst1q_u8(&dst[x], vcombine_u8(d[0], d[1])); - src_y += 16; - x += 16; - } while (x < w); + uint8x16_t t0, t1, t2, t3, t4, t5, t6, t7; + load_u8_16x8(s, src_stride, &t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7); + + int16x8_t s0[2], s1[2], s2[2], s3[2], s4[2], s5[2], s6[2], s7[2]; + s0[0] = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(t0))); + s1[0] = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(t1))); + s2[0] = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(t2))); + s3[0] = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(t3))); + s4[0] = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(t4))); + s5[0] = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(t5))); + s6[0] = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(t6))); + s7[0] = vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(t7))); + + s0[1] = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(t0))); + s1[1] = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(t1))); + s2[1] = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(t2))); + s3[1] = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(t3))); + s4[1] = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(t4))); + s5[1] = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(t5))); + s6[1] = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(t6))); + s7[1] = vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(t7))); + + uint8x8_t d0 = convolve8_8(s0[0], s1[0], s2[0], s3[0], s4[0], s5[0], + s6[0], s7[0], filter); + uint8x8_t d1 = convolve8_8(s0[1], s1[1], s2[1], s3[1], s4[1], s5[1], + s6[1], s7[1], filter); + + vst1q_u8(d, vcombine_u8(d0, d1)); + + s += 16; + d += 16; + width -= 16; + } while (width != 0); } else { - memcpy(dst, &src_y[3 * src_stride], w); + // Memcpy for non-subpel locations. + s += (SUBPEL_TAPS / 2 - 1) * src_stride; + + do { + uint8x16_t s0 = vld1q_u8(s); + vst1q_u8(d, s0); + s += 16; + d += 16; + width -= 16; + } while (width != 0); } - dst += dst_stride; + y_q4 += y_step_q4; - } while (--y); + dst += dst_stride; + } while (--h != 0); } void vpx_scaled_2d_neon(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h) { - // Note: Fixed size intermediate buffer, temp, places limits on parameters. + // Fixed size intermediate buffer, im_block, places limits on parameters. // 2d filtering proceeds in 2 steps: // (1) Interpolate horizontally into an intermediate buffer, temp. // (2) Interpolate temp vertically to derive the sub-pixel result. - // Deriving the maximum number of rows in the temp buffer (135): + // Deriving the maximum number of rows in the im_block buffer (135): // --Smallest scaling factor is x1/2 ==> y_step_q4 = 32 (Normative). // --Largest block size is 64x64 pixels. // --64 rows in the downscaled frame span a distance of (64 - 1) * 32 in the @@ -292,33 +297,20 @@ void vpx_scaled_2d_neon(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, // When calling in frame scaling function, the smallest scaling factor is x1/4 // ==> y_step_q4 = 64. Since w and h are at most 16, the temp buffer is still // big enough. - DECLARE_ALIGNED(16, uint8_t, temp[(135 + 8) * 64]); - const int intermediate_height = + DECLARE_ALIGNED(16, uint8_t, im_block[(135 + 8) * 64]); + const int im_height = (((h - 1) * y_step_q4 + y0_q4) >> SUBPEL_BITS) + SUBPEL_TAPS; + const ptrdiff_t im_stride = 64; assert(w <= 64); assert(h <= 64); assert(y_step_q4 <= 32 || (y_step_q4 <= 64 && h <= 32)); assert(x_step_q4 <= 64); - if (w >= 8) { - scaledconvolve_horiz_w8(src - src_stride * (SUBPEL_TAPS / 2 - 1), - src_stride, temp, 64, filter, x0_q4, x_step_q4, w, - intermediate_height); - } else { - scaledconvolve_horiz_w4(src - src_stride * (SUBPEL_TAPS / 2 - 1), - src_stride, temp, 64, filter, x0_q4, x_step_q4, w, - intermediate_height); - } + scaledconvolve_horiz_neon(src - src_stride * (SUBPEL_TAPS / 2 - 1), + src_stride, im_block, im_stride, filter, x0_q4, + x_step_q4, w, im_height); - if (w >= 16) { - scaledconvolve_vert_w16(temp + 64 * (SUBPEL_TAPS / 2 - 1), 64, dst, - dst_stride, filter, y0_q4, y_step_q4, w, h); - } else if (w == 8) { - scaledconvolve_vert_w8(temp + 64 * (SUBPEL_TAPS / 2 - 1), 64, dst, - dst_stride, filter, y0_q4, y_step_q4, w, h); - } else { - scaledconvolve_vert_w4(temp + 64 * (SUBPEL_TAPS / 2 - 1), 64, dst, - dst_stride, filter, y0_q4, y_step_q4, w, h); - } + scaledconvolve_vert_neon(im_block, im_stride, dst, dst_stride, filter, y0_q4, + y_step_q4, w, h); } diff --git a/libs/libvpx/vpx_dsp/avg.c b/libs/libvpx/vpx_dsp/avg.c index 576d683fef..a8dcab7dae 100644 --- a/libs/libvpx/vpx_dsp/avg.c +++ b/libs/libvpx/vpx_dsp/avg.c @@ -7,6 +7,8 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ + +#include #include #include "./vpx_dsp_rtcd.h" @@ -293,19 +295,19 @@ void vpx_hadamard_32x32_c(const int16_t *src_diff, ptrdiff_t src_stride, vpx_hadamard_16x16_c(src_ptr, src_stride, coeff + idx * 256); } - // coeff: 15 bit, dynamic range [-16320, 16320] + // coeff: 16 bit, dynamic range [-32768, 32767] for (idx = 0; idx < 256; ++idx) { tran_low_t a0 = coeff[0]; tran_low_t a1 = coeff[256]; tran_low_t a2 = coeff[512]; tran_low_t a3 = coeff[768]; - tran_low_t b0 = (a0 + a1) >> 2; // (a0 + a1): 16 bit, [-32640, 32640] + tran_low_t b0 = (a0 + a1) >> 2; // (a0 + a1): 17 bit, [-65536, 65535] tran_low_t b1 = (a0 - a1) >> 2; // b0-b3: 15 bit, dynamic range - tran_low_t b2 = (a2 + a3) >> 2; // [-16320, 16320] + tran_low_t b2 = (a2 + a3) >> 2; // [-16384, 16383] tran_low_t b3 = (a2 - a3) >> 2; - coeff[0] = b0 + b2; // 16 bit, [-32640, 32640] + coeff[0] = b0 + b2; // 16 bit, [-32768, 32767] coeff[256] = b1 + b3; coeff[512] = b0 - b2; coeff[768] = b1 - b3; @@ -344,7 +346,7 @@ void vpx_int_pro_row_c(int16_t hbuf[16], const uint8_t *ref, const int ref_stride, const int height) { int idx; const int norm_factor = height >> 1; - if (height == 1) return; + assert(height >= 2); for (idx = 0; idx < 16; ++idx) { int i; hbuf[idx] = 0; @@ -426,7 +428,7 @@ void vpx_highbd_minmax_8x8_c(const uint8_t *s8, int p, const uint8_t *d8, int i, j; const uint16_t *s = CONVERT_TO_SHORTPTR(s8); const uint16_t *d = CONVERT_TO_SHORTPTR(d8); - *min = 255; + *min = 65535; *max = 0; for (i = 0; i < 8; ++i, s += p, d += dp) { for (j = 0; j < 8; ++j) { diff --git a/libs/libvpx/vpx_dsp/bitwriter.c b/libs/libvpx/vpx_dsp/bitwriter.c index 5b41aa54dd..d3ef9bd89a 100644 --- a/libs/libvpx/vpx_dsp/bitwriter.c +++ b/libs/libvpx/vpx_dsp/bitwriter.c @@ -9,6 +9,7 @@ */ #include +#include #include "./bitwriter.h" @@ -16,16 +17,20 @@ #include "vpx_util/vpx_debug_util.h" #endif -void vpx_start_encode(vpx_writer *br, uint8_t *source) { +void vpx_start_encode(vpx_writer *br, uint8_t *source, size_t size) { br->lowvalue = 0; br->range = 255; br->count = -24; - br->buffer = source; + br->error = 0; br->pos = 0; + // Make sure it is safe to cast br->pos to int in vpx_write(). + if (size > INT_MAX) size = INT_MAX; + br->size = (unsigned int)size; + br->buffer = source; vpx_write_bit(br, 0); } -void vpx_stop_encode(vpx_writer *br) { +int vpx_stop_encode(vpx_writer *br) { int i; #if CONFIG_BITSTREAM_DEBUG @@ -34,9 +39,17 @@ void vpx_stop_encode(vpx_writer *br) { for (i = 0; i < 32; i++) vpx_write_bit(br, 0); // Ensure there's no ambigous collision with any index marker bytes - if ((br->buffer[br->pos - 1] & 0xe0) == 0xc0) br->buffer[br->pos++] = 0; + if (!br->error && (br->buffer[br->pos - 1] & 0xe0) == 0xc0) { + if (br->pos < br->size) { + br->buffer[br->pos++] = 0; + } else { + br->error = 1; + } + } #if CONFIG_BITSTREAM_DEBUG bitstream_queue_set_skip_write(0); #endif + + return br->error ? -1 : 0; } diff --git a/libs/libvpx/vpx_dsp/bitwriter.h b/libs/libvpx/vpx_dsp/bitwriter.h index 04084af8f2..daff331daf 100644 --- a/libs/libvpx/vpx_dsp/bitwriter.h +++ b/libs/libvpx/vpx_dsp/bitwriter.h @@ -13,6 +13,7 @@ #include +#include "vpx_ports/compiler_attributes.h" #include "vpx_ports/mem.h" #include "vpx_dsp/prob.h" @@ -28,14 +29,23 @@ typedef struct vpx_writer { unsigned int lowvalue; unsigned int range; int count; + // Whether there has been an error. + int error; + // We maintain the invariant that pos <= size, i.e., we never write beyond + // the end of the buffer. If pos would be incremented to be greater than + // size, leave pos unchanged and set error to 1. unsigned int pos; + unsigned int size; uint8_t *buffer; } vpx_writer; -void vpx_start_encode(vpx_writer *br, uint8_t *source); -void vpx_stop_encode(vpx_writer *br); +void vpx_start_encode(vpx_writer *br, uint8_t *source, size_t size); +// Returns 0 on success and returns -1 in case of error. +int vpx_stop_encode(vpx_writer *br); -static INLINE void vpx_write(vpx_writer *br, int bit, int probability) { +static INLINE VPX_NO_UNSIGNED_SHIFT_CHECK void vpx_write(vpx_writer *br, + int bit, + int probability) { unsigned int split; int count = br->count; unsigned int range = br->range; @@ -74,18 +84,25 @@ static INLINE void vpx_write(vpx_writer *br, int bit, int probability) { if (count >= 0) { int offset = shift - count; - if ((lowvalue << (offset - 1)) & 0x80000000) { - int x = br->pos - 1; + if (!br->error) { + if ((lowvalue << (offset - 1)) & 0x80000000) { + int x = (int)br->pos - 1; - while (x >= 0 && br->buffer[x] == 0xff) { - br->buffer[x] = 0; - x--; + while (x >= 0 && br->buffer[x] == 0xff) { + br->buffer[x] = 0; + x--; + } + + // TODO(wtc): How to prove x >= 0? + br->buffer[x] += 1; } - br->buffer[x] += 1; + if (br->pos < br->size) { + br->buffer[br->pos++] = (lowvalue >> (24 - offset)) & 0xff; + } else { + br->error = 1; + } } - - br->buffer[br->pos++] = (lowvalue >> (24 - offset)) & 0xff; lowvalue <<= offset; shift = count; lowvalue &= 0xffffff; diff --git a/libs/libvpx/vpx_dsp/bitwriter_buffer.c b/libs/libvpx/vpx_dsp/bitwriter_buffer.c index 7a7e96f02e..b3a2490f2c 100644 --- a/libs/libvpx/vpx_dsp/bitwriter_buffer.c +++ b/libs/libvpx/vpx_dsp/bitwriter_buffer.c @@ -8,24 +8,43 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include #include #include #include "./vpx_config.h" #include "./bitwriter_buffer.h" +void vpx_wb_init(struct vpx_write_bit_buffer *wb, uint8_t *bit_buffer, + size_t size) { + wb->error = 0; + wb->bit_offset = 0; + wb->size = size; + wb->bit_buffer = bit_buffer; +} + +int vpx_wb_has_error(const struct vpx_write_bit_buffer *wb) { + return wb->error; +} + size_t vpx_wb_bytes_written(const struct vpx_write_bit_buffer *wb) { + assert(!wb->error); return wb->bit_offset / CHAR_BIT + (wb->bit_offset % CHAR_BIT > 0); } void vpx_wb_write_bit(struct vpx_write_bit_buffer *wb, int bit) { + if (wb->error) return; const int off = (int)wb->bit_offset; const int p = off / CHAR_BIT; const int q = CHAR_BIT - 1 - off % CHAR_BIT; + if ((size_t)p >= wb->size) { + wb->error = 1; + return; + } if (q == CHAR_BIT - 1) { wb->bit_buffer[p] = bit << q; } else { - wb->bit_buffer[p] &= ~(1 << q); + assert((wb->bit_buffer[p] & (1 << q)) == 0); wb->bit_buffer[p] |= bit << q; } wb->bit_offset = off + 1; diff --git a/libs/libvpx/vpx_dsp/bitwriter_buffer.h b/libs/libvpx/vpx_dsp/bitwriter_buffer.h index 3662cb64df..3ee0e9658b 100644 --- a/libs/libvpx/vpx_dsp/bitwriter_buffer.h +++ b/libs/libvpx/vpx_dsp/bitwriter_buffer.h @@ -18,10 +18,24 @@ extern "C" { #endif struct vpx_write_bit_buffer { - uint8_t *bit_buffer; + // Whether there has been an error. + int error; + // We maintain the invariant that bit_offset <= size * CHAR_BIT, i.e., we + // never write beyond the end of bit_buffer. If bit_offset would be + // incremented to be greater than size * CHAR_BIT, leave bit_offset unchanged + // and set error to 1. size_t bit_offset; + // Size of bit_buffer in bytes. + size_t size; + uint8_t *bit_buffer; }; +void vpx_wb_init(struct vpx_write_bit_buffer *wb, uint8_t *bit_buffer, + size_t size); + +int vpx_wb_has_error(const struct vpx_write_bit_buffer *wb); + +// Must not be called if vpx_wb_has_error(wb) returns true. size_t vpx_wb_bytes_written(const struct vpx_write_bit_buffer *wb); void vpx_wb_write_bit(struct vpx_write_bit_buffer *wb, int bit); diff --git a/libs/libvpx/vpx_dsp/deblock.c b/libs/libvpx/vpx_dsp/deblock.c index cc437af66c..455b73bbce 100644 --- a/libs/libvpx/vpx_dsp/deblock.c +++ b/libs/libvpx/vpx_dsp/deblock.c @@ -52,11 +52,6 @@ void vpx_post_proc_down_and_across_mb_row_c(unsigned char *src, assert(size >= 8); assert(cols >= 8); -#ifdef __clang_analyzer__ - /* older clang analyzer doesnt understand asserts, insert this until we ugrade analyzer */ - if (cols < 8) return; -#endif - for (row = 0; row < size; row++) { /* post_proc_down for one row */ p_src = src; diff --git a/libs/libvpx/vpx_dsp/intrapred.c b/libs/libvpx/vpx_dsp/intrapred.c index 400e632e98..4b37deef0e 100644 --- a/libs/libvpx/vpx_dsp/intrapred.c +++ b/libs/libvpx/vpx_dsp/intrapred.c @@ -14,7 +14,7 @@ #include "vpx_dsp/vpx_dsp_common.h" #include "vpx_mem/vpx_mem.h" -#define DST(x, y) dst[(x) + (y)*stride] +#define DST(x, y) dst[(x) + (y) * stride] #define AVG3(a, b, c) (((a) + 2 * (b) + (c) + 2) >> 2) #define AVG2(a, b) (((a) + (b) + 1) >> 1) diff --git a/libs/libvpx/vpx_dsp/loongarch/quantize_lsx.c b/libs/libvpx/vpx_dsp/loongarch/quantize_lsx.c index 2fc33b06b7..1299e75e9a 100644 --- a/libs/libvpx/vpx_dsp/loongarch/quantize_lsx.c +++ b/libs/libvpx/vpx_dsp/loongarch/quantize_lsx.c @@ -11,6 +11,8 @@ #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" #include "vpx_util/loongson_intrinsics.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" static INLINE __m128i calculate_qcoeff(__m128i coeff, __m128i coeff_abs, __m128i round, __m128i quant, @@ -59,7 +61,6 @@ static INLINE void calculate_dqcoeff_and_store_32x32(__m128i qcoeff, } static INLINE __m128i scan_for_eob(__m128i coeff0, __m128i coeff1, - __m128i zbin_mask0, __m128i zbin_mask1, const int16_t *scan, int index, __m128i zero) { const __m128i zero_coeff0 = __lsx_vseq_h(coeff0, zero); @@ -68,8 +69,6 @@ static INLINE __m128i scan_for_eob(__m128i coeff0, __m128i coeff1, __m128i scan1 = __lsx_vld(scan + index + 8, 0); __m128i eob0, eob1; - scan0 = __lsx_vsub_h(scan0, zbin_mask0); - scan1 = __lsx_vsub_h(scan1, zbin_mask1); eob0 = __lsx_vandn_v(zero_coeff0, scan0); eob1 = __lsx_vandn_v(zero_coeff1, scan1); return __lsx_vmax_h(eob0, eob1); @@ -91,15 +90,15 @@ static INLINE int16_t accumulate_eob(__m128i eob) { } #if !CONFIG_VP9_HIGHBITDEPTH -void vpx_quantize_b_lsx(const int16_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, int16_t *qcoeff_ptr, - int16_t *dqcoeff_ptr, const int16_t *dequant_ptr, - uint16_t *eob_ptr, const int16_t *scan, - const int16_t *iscan) { + +void vpx_quantize_b_lsx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { __m128i zero = __lsx_vldi(0); int index = 16; + const int16_t *iscan = scan_order->iscan; __m128i zbin, round, quant, dequant, quant_shift; __m128i coeff0, coeff1; @@ -107,13 +106,11 @@ void vpx_quantize_b_lsx(const int16_t *coeff_ptr, intptr_t n_coeffs, __m128i cmp_mask0, cmp_mask1; __m128i eob, eob0; - (void)scan; - - zbin = __lsx_vld(zbin_ptr, 0); - round = __lsx_vld(round_ptr, 0); - quant = __lsx_vld(quant_ptr, 0); + zbin = __lsx_vld(mb_plane->zbin, 0); + round = __lsx_vld(mb_plane->round, 0); + quant = __lsx_vld(mb_plane->quant, 0); dequant = __lsx_vld(dequant_ptr, 0); - quant_shift = __lsx_vld(quant_shift_ptr, 0); + quant_shift = __lsx_vld(mb_plane->quant_shift, 0); // Handle one DC and first 15 AC. DUP2_ARG2(__lsx_vld, coeff_ptr, 0, coeff_ptr, 16, coeff0, coeff1); qcoeff0 = __lsx_vabsd_h(coeff0, zero); @@ -138,7 +135,7 @@ void vpx_quantize_b_lsx(const int16_t *coeff_ptr, intptr_t n_coeffs, dequant = __lsx_vilvh_d(dequant, dequant); calculate_dqcoeff_and_store(qcoeff1, dequant, dqcoeff_ptr + 8); - eob = scan_for_eob(qcoeff0, qcoeff1, cmp_mask0, cmp_mask1, iscan, 0, zero); + eob = scan_for_eob(qcoeff0, qcoeff1, iscan, 0, zero); // AC only loop. while (index < n_coeffs) { coeff0 = __lsx_vld(coeff_ptr + index, 0); @@ -161,8 +158,7 @@ void vpx_quantize_b_lsx(const int16_t *coeff_ptr, intptr_t n_coeffs, calculate_dqcoeff_and_store(qcoeff0, dequant, dqcoeff_ptr + index); calculate_dqcoeff_and_store(qcoeff1, dequant, dqcoeff_ptr + index + 8); - eob0 = scan_for_eob(qcoeff0, qcoeff1, cmp_mask0, cmp_mask1, iscan, index, - zero); + eob0 = scan_for_eob(qcoeff0, qcoeff1, iscan, index, zero); eob = __lsx_vmax_h(eob, eob0); index += 16; @@ -171,31 +167,27 @@ void vpx_quantize_b_lsx(const int16_t *coeff_ptr, intptr_t n_coeffs, *eob_ptr = accumulate_eob(eob); } -void vpx_quantize_b_32x32_lsx(const int16_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, - int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, +void vpx_quantize_b_32x32_lsx(const tran_low_t *coeff_ptr, + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { + const struct ScanOrder *const scan_order) { __m128i zero = __lsx_vldi(0); int index; + const int16_t *iscan = scan_order->iscan; __m128i zbin, round, quant, dequant, quant_shift; __m128i coeff0, coeff1, qcoeff0, qcoeff1, cmp_mask0, cmp_mask1; __m128i eob = zero, eob0; - (void)scan; - (void)n_coeffs; - - zbin = __lsx_vld(zbin_ptr, 0); + zbin = __lsx_vld(mb_plane->zbin, 0); zbin = __lsx_vsrari_h(zbin, 1); - round = __lsx_vld(round_ptr, 0); + round = __lsx_vld(mb_plane->round, 0); round = __lsx_vsrari_h(round, 1); - quant = __lsx_vld(quant_ptr, 0); + quant = __lsx_vld(mb_plane->quant, 0); dequant = __lsx_vld(dequant_ptr, 0); - quant_shift = __lsx_vld(quant_shift_ptr, 0); + quant_shift = __lsx_vld(mb_plane->quant_shift, 0); quant_shift = __lsx_vslli_h(quant_shift, 1); // Handle one DC and first 15 AC. DUP2_ARG2(__lsx_vld, coeff_ptr, 0, coeff_ptr, 16, coeff0, coeff1); @@ -221,7 +213,7 @@ void vpx_quantize_b_32x32_lsx(const int16_t *coeff_ptr, intptr_t n_coeffs, calculate_dqcoeff_and_store_32x32(qcoeff0, dequant, dqcoeff_ptr); dequant = __lsx_vilvh_d(dequant, dequant); calculate_dqcoeff_and_store_32x32(qcoeff1, dequant, dqcoeff_ptr + 8); - eob = scan_for_eob(qcoeff0, qcoeff1, cmp_mask0, cmp_mask1, iscan, 0, zero); + eob = scan_for_eob(qcoeff0, qcoeff1, iscan, 0, zero); // AC only loop. for (index = 16; index < 32 * 32; index += 16) { coeff0 = __lsx_vld(coeff_ptr + index, 0); @@ -243,8 +235,7 @@ void vpx_quantize_b_32x32_lsx(const int16_t *coeff_ptr, intptr_t n_coeffs, calculate_dqcoeff_and_store_32x32(qcoeff0, dequant, dqcoeff_ptr + index); calculate_dqcoeff_and_store_32x32(qcoeff1, dequant, dqcoeff_ptr + 8 + index); - eob0 = scan_for_eob(qcoeff0, qcoeff1, cmp_mask0, cmp_mask1, iscan, index, - zero); + eob0 = scan_for_eob(qcoeff0, qcoeff1, iscan, index, zero); eob = __lsx_vmax_h(eob, eob0); } diff --git a/libs/libvpx/vpx_dsp/loopfilter.c b/libs/libvpx/vpx_dsp/loopfilter.c index 9956028317..d6504aab1f 100644 --- a/libs/libvpx/vpx_dsp/loopfilter.c +++ b/libs/libvpx/vpx_dsp/loopfilter.c @@ -159,7 +159,7 @@ void vpx_lpf_vertical_4_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0, vpx_lpf_vertical_4_c(s + 8 * pitch, pitch, blimit1, limit1, thresh1); } -static INLINE void filter8(int8_t mask, uint8_t thresh, uint8_t flat, +static INLINE void filter8(int8_t mask, uint8_t thresh, int8_t flat, uint8_t *op3, uint8_t *op2, uint8_t *op1, uint8_t *op0, uint8_t *oq0, uint8_t *oq1, uint8_t *oq2, uint8_t *oq3) { @@ -232,8 +232,8 @@ void vpx_lpf_vertical_8_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0, vpx_lpf_vertical_8_c(s + 8 * pitch, pitch, blimit1, limit1, thresh1); } -static INLINE void filter16(int8_t mask, uint8_t thresh, uint8_t flat, - uint8_t flat2, uint8_t *op7, uint8_t *op6, +static INLINE void filter16(int8_t mask, uint8_t thresh, int8_t flat, + int8_t flat2, uint8_t *op7, uint8_t *op6, uint8_t *op5, uint8_t *op4, uint8_t *op3, uint8_t *op2, uint8_t *op1, uint8_t *op0, uint8_t *oq0, uint8_t *oq1, uint8_t *oq2, @@ -505,7 +505,7 @@ void vpx_highbd_lpf_vertical_4_dual_c( bd); } -static INLINE void highbd_filter8(int8_t mask, uint8_t thresh, uint8_t flat, +static INLINE void highbd_filter8(int8_t mask, uint8_t thresh, int8_t flat, uint16_t *op3, uint16_t *op2, uint16_t *op1, uint16_t *op0, uint16_t *oq0, uint16_t *oq1, uint16_t *oq2, uint16_t *oq3, int bd) { @@ -584,8 +584,8 @@ void vpx_highbd_lpf_vertical_8_dual_c( bd); } -static INLINE void highbd_filter16(int8_t mask, uint8_t thresh, uint8_t flat, - uint8_t flat2, uint16_t *op7, uint16_t *op6, +static INLINE void highbd_filter16(int8_t mask, uint8_t thresh, int8_t flat, + int8_t flat2, uint16_t *op7, uint16_t *op6, uint16_t *op5, uint16_t *op4, uint16_t *op3, uint16_t *op2, uint16_t *op1, uint16_t *op0, uint16_t *oq0, uint16_t *oq1, uint16_t *oq2, diff --git a/libs/libvpx/vpx_dsp/mips/add_noise_msa.c b/libs/libvpx/vpx_dsp/mips/add_noise_msa.c index 97541411e4..b11890f599 100644 --- a/libs/libvpx/vpx_dsp/mips/add_noise_msa.c +++ b/libs/libvpx/vpx_dsp/mips/add_noise_msa.c @@ -13,6 +13,17 @@ #include "./vpx_dsp_rtcd.h" #include "vpx_dsp/mips/macros_msa.h" +static INLINE void add_noise(uint8_t *pos, const int8_t *ref, int blackclamp, + int whiteclamp, int bothclamp) { + int v = *pos; + + v = clamp(v - blackclamp, 0, 255); + v = clamp(v + bothclamp, 0, 255); + v = clamp(v - whiteclamp, 0, 255); + + *pos = v + *ref; +} + void vpx_plane_add_noise_msa(uint8_t *start_ptr, const int8_t *noise, int blackclamp, int whiteclamp, int width, int height, int32_t pitch) { @@ -50,5 +61,20 @@ void vpx_plane_add_noise_msa(uint8_t *start_ptr, const int8_t *noise, ref0_ptr += 16; ref1_ptr += 16; } + + const int tail_width = width & 15; + if (tail_width) { + const int bothclamp = blackclamp + whiteclamp; + int k = 0; + do { + add_noise(pos0_ptr, ref0_ptr, blackclamp, whiteclamp, bothclamp); + ++pos0_ptr; + ++ref0_ptr; + + add_noise(pos1_ptr, ref1_ptr, blackclamp, whiteclamp, bothclamp); + ++pos1_ptr; + ++ref1_ptr; + } while (++k != tail_width); + } } } diff --git a/libs/libvpx/vpx_dsp/mips/deblock_msa.c b/libs/libvpx/vpx_dsp/mips/deblock_msa.c index 4e93ff594d..1be9e58c35 100644 --- a/libs/libvpx/vpx_dsp/mips/deblock_msa.c +++ b/libs/libvpx/vpx_dsp/mips/deblock_msa.c @@ -8,6 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include #include #include "./vpx_dsp_rtcd.h" @@ -141,6 +142,19 @@ extern const int16_t vpx_rv[]; in11 = (v16u8)__msa_ilvl_d((v2i64)temp7, (v2i64)temp7); \ } +static INLINE unsigned char filter_scalar( + unsigned char v, unsigned char p_above2, unsigned char p_above1, + unsigned char p_below1, unsigned char p_below2, unsigned char flimit) { + if ((abs(v - p_above2) < flimit) && (abs(v - p_above1) < flimit) && + (abs(v - p_below1) < flimit) && (abs(v - p_below2) < flimit)) { + const unsigned char k1 = (p_above2 + p_above1 + 1) >> 1; + const unsigned char k2 = (p_below2 + p_below1 + 1) >> 1; + const unsigned char k3 = (k1 + k2 + 1) >> 1; + return (k3 + v + 1) >> 1; + } + return v; +} + static void postproc_down_across_chroma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, int32_t src_stride, int32_t dst_stride, int32_t cols, @@ -150,12 +164,15 @@ static void postproc_down_across_chroma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, uint8_t *f_orig = f; uint8_t *p_dst_st = dst_ptr; uint16_t col; + int32_t r; uint64_t out0, out1, out2, out3; v16u8 above2, above1, below2, below1, src, ref, ref_temp; v16u8 inter0, inter1, inter2, inter3, inter4, inter5; v16u8 inter6, inter7, inter8, inter9, inter10, inter11; + const int32_t aligned_16 = cols & ~15; + const int32_t aligned_8 = cols & ~7; - for (col = (cols / 16); col--;) { + for (col = aligned_16 / 16; col--;) { ref = LD_UB(f); LD_UB2(p_src - 2 * src_stride, src_stride, above2, above1); src = LD_UB(p_src); @@ -183,7 +200,7 @@ static void postproc_down_across_chroma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, f += 16; } - if (0 != (cols / 16)) { + if (cols & 8) { ref = LD_UB(f); LD_UB2(p_src - 2 * src_stride, src_stride, above2, above1); src = LD_UB(p_src); @@ -216,12 +233,33 @@ static void postproc_down_across_chroma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, SD4(out0, out1, out2, out3, p_dst + 4 * dst_stride, dst_stride); } + for (col = aligned_8; col < cols; col++) { + for (r = 0; r < 8; r++) { + const uint8_t *s = src_ptr + r * src_stride; + uint8_t *d = dst_ptr + r * dst_stride; + const uint8_t p_above2 = s[col - 2 * src_stride]; + const uint8_t p_above1 = s[col - src_stride]; + const uint8_t p_below1 = s[col + src_stride]; + const uint8_t p_below2 = s[col + 2 * src_stride]; + const uint8_t v = s[col]; + d[col] = + filter_scalar(v, p_above2, p_above1, p_below1, p_below2, f_orig[col]); + } + } + + for (r = 0; r < 8; r++) { + uint8_t *d = dst_ptr + r * dst_stride; + d[-2] = d[-1] = d[0]; + d[cols] = d[cols + 1] = d[cols - 1]; + } + f = f_orig; p_dst = dst_ptr - 2; LD_UB8(p_dst, dst_stride, inter0, inter1, inter2, inter3, inter4, inter5, inter6, inter7); - for (col = 0; col < (cols / 8); ++col) { + for (col = 0; col < aligned_8 / 8; ++col) { + const int is_last_block = col == aligned_8 / 8 - 1 && cols == aligned_8; ref = LD_UB(f); f += 8; VPX_TRANSPOSE12x8_UB_UB(inter0, inter1, inter2, inter3, inter4, inter5, @@ -253,14 +291,14 @@ static void postproc_down_across_chroma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, below2 = inter9; ref_temp = (v16u8)__msa_splati_b((v16i8)ref, 5); VPX_AVER_IF_RETAIN(above2, above1, src, below1, below2, ref_temp, inter7); - if (col == (cols / 8 - 1)) { + if (is_last_block) { above2 = inter9; } else { above2 = inter10; } ref_temp = (v16u8)__msa_splati_b((v16i8)ref, 6); VPX_AVER_IF_RETAIN(above1, src, below1, below2, above2, ref_temp, inter8); - if (col == (cols / 8 - 1)) { + if (is_last_block) { above1 = inter9; } else { above1 = inter11; @@ -285,6 +323,38 @@ static void postproc_down_across_chroma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, ST8x1_UB(inter9, (p_dst_st + 7 * dst_stride)); p_dst_st += 8; } + + for (r = 0; r < 8; r++) { + uint8_t *dst_row = dst_ptr + r * dst_stride; + const uint8_t prev_p2 = + aligned_8 >= 2 ? dst_row[aligned_8 - 2] : dst_row[0]; + const uint8_t prev_p1 = + aligned_8 >= 1 ? dst_row[aligned_8 - 1] : dst_row[0]; + uint8_t d[4] = { 0 }; + + for (col = aligned_8; col < cols; col++) { + const uint8_t p_left2 = + col == aligned_8 + ? prev_p2 + : (col == aligned_8 + 1 ? prev_p1 : dst_row[col - 2]); + const uint8_t p_left1 = col == aligned_8 ? prev_p1 : dst_row[col - 1]; + const uint8_t p_right1 = dst_row[col + 1]; + const uint8_t p_right2 = dst_row[col + 2]; + const uint8_t v = dst_row[col]; + + d[col & 3] = + filter_scalar(v, p_left2, p_left1, p_right1, p_right2, f_orig[col]); + + if (col >= aligned_8 + 2) dst_row[col - 2] = d[(col - 2) & 3]; + } + + if (cols - aligned_8 >= 2) { + dst_row[cols - 2] = d[(cols - 2) & 3]; + dst_row[cols - 1] = d[(cols - 1) & 3]; + } else if (cols - aligned_8 == 1) { + dst_row[cols - 1] = d[(cols - 1) & 3]; + } + } } static void postproc_down_across_luma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, @@ -296,14 +366,17 @@ static void postproc_down_across_luma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, uint8_t *p_dst_st = dst_ptr; uint8_t *f_orig = f; uint16_t col; + int32_t r; uint64_t out0, out1, out2, out3; v16u8 above2, above1, below2, below1; v16u8 src, ref, ref_temp; v16u8 inter0, inter1, inter2, inter3, inter4, inter5, inter6; v16u8 inter7, inter8, inter9, inter10, inter11; v16u8 inter12, inter13, inter14, inter15; + const int32_t aligned_16 = cols & ~15; + const int32_t aligned_8 = cols & ~7; - for (col = (cols / 16); col--;) { + for (col = aligned_16 / 16; col--;) { ref = LD_UB(f); LD_UB2(p_src - 2 * src_stride, src_stride, above2, above1); src = LD_UB(p_src); @@ -348,7 +421,7 @@ static void postproc_down_across_luma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, f += 16; } - if (0 != (cols / 16)) { + if (cols & 8) { ref = LD_UB(f); LD_UB2(p_src - 2 * src_stride, src_stride, above2, above1); src = LD_UB(p_src); @@ -409,6 +482,26 @@ static void postproc_down_across_luma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, SD4(out0, out1, out2, out3, p_dst + 12 * dst_stride, dst_stride); } + for (col = aligned_8; col < cols; col++) { + for (r = 0; r < 16; r++) { + const uint8_t *s = src_ptr + r * src_stride; + uint8_t *d = dst_ptr + r * dst_stride; + const uint8_t p_above2 = s[col - 2 * src_stride]; + const uint8_t p_above1 = s[col - src_stride]; + const uint8_t p_below1 = s[col + src_stride]; + const uint8_t p_below2 = s[col + 2 * src_stride]; + const uint8_t v = s[col]; + d[col] = + filter_scalar(v, p_above2, p_above1, p_below1, p_below2, f_orig[col]); + } + } + + for (r = 0; r < 16; r++) { + uint8_t *d = dst_ptr + r * dst_stride; + d[-2] = d[-1] = d[0]; + d[cols] = d[cols + 1] = d[cols - 1]; + } + f = f_orig; p_dst = dst_ptr - 2; LD_UB8(p_dst, dst_stride, inter0, inter1, inter2, inter3, inter4, inter5, @@ -416,7 +509,8 @@ static void postproc_down_across_luma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, LD_UB8(p_dst + 8 * dst_stride, dst_stride, inter8, inter9, inter10, inter11, inter12, inter13, inter14, inter15); - for (col = 0; col < cols / 8; ++col) { + for (col = 0; col < aligned_8 / 8; ++col) { + const int is_last_block = col == aligned_8 / 8 - 1 && cols == aligned_8; ref = LD_UB(f); f += 8; TRANSPOSE12x16_B(inter0, inter1, inter2, inter3, inter4, inter5, inter6, @@ -450,14 +544,14 @@ static void postproc_down_across_luma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, below2 = inter9; ref_temp = (v16u8)__msa_splati_b((v16i8)ref, 5); VPX_AVER_IF_RETAIN(above2, above1, src, below1, below2, ref_temp, inter7); - if (col == (cols / 8 - 1)) { + if (is_last_block) { above2 = inter9; } else { above2 = inter10; } ref_temp = (v16u8)__msa_splati_b((v16i8)ref, 6); VPX_AVER_IF_RETAIN(above1, src, below1, below2, above2, ref_temp, inter8); - if (col == (cols / 8 - 1)) { + if (is_last_block) { above1 = inter9; } else { above1 = inter11; @@ -496,15 +590,48 @@ static void postproc_down_across_luma_msa(uint8_t *src_ptr, uint8_t *dst_ptr, ST8x1_UB(above1, (p_dst_st + 15 * dst_stride)); p_dst_st += 8; } + + for (r = 0; r < 16; r++) { + uint8_t *dst_row = dst_ptr + r * dst_stride; + const uint8_t prev_p2 = + aligned_8 >= 2 ? dst_row[aligned_8 - 2] : dst_row[0]; + const uint8_t prev_p1 = + aligned_8 >= 1 ? dst_row[aligned_8 - 1] : dst_row[0]; + uint8_t d[4] = { 0 }; + + for (col = aligned_8; col < cols; col++) { + const uint8_t p_left2 = + col == aligned_8 + ? prev_p2 + : (col == aligned_8 + 1 ? prev_p1 : dst_row[col - 2]); + const uint8_t p_left1 = col == aligned_8 ? prev_p1 : dst_row[col - 1]; + const uint8_t p_right1 = dst_row[col + 1]; + const uint8_t p_right2 = dst_row[col + 2]; + const uint8_t v = dst_row[col]; + + d[col & 3] = + filter_scalar(v, p_left2, p_left1, p_right1, p_right2, f_orig[col]); + + if (col >= aligned_8 + 2) dst_row[col - 2] = d[(col - 2) & 3]; + } + + if (cols - aligned_8 >= 2) { + dst_row[cols - 2] = d[(cols - 2) & 3]; + dst_row[cols - 1] = d[(cols - 1) & 3]; + } else if (cols - aligned_8 == 1) { + dst_row[cols - 1] = d[(cols - 1) & 3]; + } + } } void vpx_post_proc_down_and_across_mb_row_msa(uint8_t *src, uint8_t *dst, int32_t src_stride, int32_t dst_stride, int32_t cols, uint8_t *f, int32_t size) { + assert(size == 8 || size == 16); if (8 == size) { postproc_down_across_chroma_msa(src, dst, src_stride, dst_stride, cols, f); - } else if (16 == size) { + } else { postproc_down_across_luma_msa(src, dst, src_stride, dst_stride, cols, f); } } diff --git a/libs/libvpx/vpx_dsp/mips/macros_msa.h b/libs/libvpx/vpx_dsp/mips/macros_msa.h index 3c2f50c790..da79b40a7a 100644 --- a/libs/libvpx/vpx_dsp/mips/macros_msa.h +++ b/libs/libvpx/vpx_dsp/mips/macros_msa.h @@ -83,31 +83,33 @@ val_lh_m; \ }) -#define LW(psrc) \ - ({ \ - const uint8_t *psrc_lw_m = (const uint8_t *)(psrc); \ - uint32_t val_lw_m; \ - \ - __asm__ __volatile__("lwr %[val_lw_m], 0(%[psrc_lw_m]) \n\t" \ - "lwl %[val_lw_m], 3(%[psrc_lw_m]) \n\t" \ - : [val_lw_m] "=&r"(val_lw_m) \ - : [psrc_lw_m] "r"(psrc_lw_m)); \ - \ - val_lw_m; \ +#define LW(psrc) \ + ({ \ + const uint8_t *psrc_lw_m = (const uint8_t *)(psrc); \ + uint32_t val_lw_m; \ + \ + __asm__ __volatile__( \ + "lwr %[val_lw_m], 0(%[psrc_lw_m]) \n\t" \ + "lwl %[val_lw_m], 3(%[psrc_lw_m]) \n\t" \ + : [val_lw_m] "=&r"(val_lw_m) \ + : [psrc_lw_m] "r"(psrc_lw_m)); \ + \ + val_lw_m; \ }) #if (__mips == 64) -#define LD(psrc) \ - ({ \ - const uint8_t *psrc_ld_m = (const uint8_t *)(psrc); \ - uint64_t val_ld_m = 0; \ - \ - __asm__ __volatile__("ldr %[val_ld_m], 0(%[psrc_ld_m]) \n\t" \ - "ldl %[val_ld_m], 7(%[psrc_ld_m]) \n\t" \ - : [val_ld_m] "=&r"(val_ld_m) \ - : [psrc_ld_m] "r"(psrc_ld_m)); \ - \ - val_ld_m; \ +#define LD(psrc) \ + ({ \ + const uint8_t *psrc_ld_m = (const uint8_t *)(psrc); \ + uint64_t val_ld_m = 0; \ + \ + __asm__ __volatile__( \ + "ldr %[val_ld_m], 0(%[psrc_ld_m]) \n\t" \ + "ldl %[val_ld_m], 7(%[psrc_ld_m]) \n\t" \ + : [val_ld_m] "=&r"(val_ld_m) \ + : [psrc_ld_m] "r"(psrc_ld_m)); \ + \ + val_ld_m; \ }) #else // !(__mips == 64) #define LD(psrc) \ @@ -154,7 +156,7 @@ uint8_t *pdst_sd_m = (uint8_t *)(pdst); \ uint32_t val0_sd_m, val1_sd_m; \ \ - val0_sd_m = (uint32_t)((val)&0x00000000FFFFFFFF); \ + val0_sd_m = (uint32_t)((val) & 0x00000000FFFFFFFF); \ val1_sd_m = (uint32_t)(((val) >> 32) & 0x00000000FFFFFFFF); \ \ SW(val0_sd_m, pdst_sd_m); \ @@ -479,17 +481,17 @@ with rounding is calculated and written to 'out0' */ #define AVER_UB2(RTYPE, in0, in1, in2, in3, out0, out1) \ - { \ + do { \ out0 = (RTYPE)__msa_aver_u_b((v16u8)in0, (v16u8)in1); \ out1 = (RTYPE)__msa_aver_u_b((v16u8)in2, (v16u8)in3); \ - } + } while (0) #define AVER_UB2_UB(...) AVER_UB2(v16u8, __VA_ARGS__) #define AVER_UB4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, out0, out1, \ out2, out3) \ { \ - AVER_UB2(RTYPE, in0, in1, in2, in3, out0, out1) \ - AVER_UB2(RTYPE, in4, in5, in6, in7, out2, out3) \ + AVER_UB2(RTYPE, in0, in1, in2, in3, out0, out1); \ + AVER_UB2(RTYPE, in4, in5, in6, in7, out2, out3); \ } #define AVER_UB4_UB(...) AVER_UB4(v16u8, __VA_ARGS__) @@ -772,16 +774,16 @@ Details : 4 signed word elements of 'in' vector are added together and the resulting integer sum is returned */ -#define HADD_SW_S32(in) \ - ({ \ - v2i64 res0_m, res1_m; \ - int32_t sum_m; \ - \ - res0_m = __msa_hadd_s_d((v4i32)in, (v4i32)in); \ - res1_m = __msa_splati_d(res0_m, 1); \ - res0_m = res0_m + res1_m; \ - sum_m = __msa_copy_s_w((v4i32)res0_m, 0); \ - sum_m; \ +#define HADD_SW_S32(in) \ + ({ \ + v2i64 hadd_sw_s32_res0_m, hadd_sw_s32_res1_m; \ + int32_t hadd_sw_s32_sum_m; \ + \ + hadd_sw_s32_res0_m = __msa_hadd_s_d((v4i32)in, (v4i32)in); \ + hadd_sw_s32_res1_m = __msa_splati_d(hadd_sw_s32_res0_m, 1); \ + hadd_sw_s32_res0_m = hadd_sw_s32_res0_m + hadd_sw_s32_res1_m; \ + hadd_sw_s32_sum_m = __msa_copy_s_w((v4i32)hadd_sw_s32_res0_m, 0); \ + hadd_sw_s32_sum_m; \ }) /* Description : Horizontal addition of 4 unsigned word elements @@ -791,16 +793,16 @@ Details : 4 unsigned word elements of 'in' vector are added together and the resulting integer sum is returned */ -#define HADD_UW_U32(in) \ - ({ \ - v2u64 res0_m, res1_m; \ - uint32_t sum_m; \ - \ - res0_m = __msa_hadd_u_d((v4u32)in, (v4u32)in); \ - res1_m = (v2u64)__msa_splati_d((v2i64)res0_m, 1); \ - res0_m += res1_m; \ - sum_m = __msa_copy_u_w((v4i32)res0_m, 0); \ - sum_m; \ +#define HADD_UW_U32(in) \ + ({ \ + v2u64 hadd_uw_u32_res0_m, hadd_uw_u32_res1_m; \ + uint32_t hadd_uw_u32_sum_m; \ + \ + hadd_uw_u32_res0_m = __msa_hadd_u_d((v4u32)in, (v4u32)in); \ + hadd_uw_u32_res1_m = (v2u64)__msa_splati_d((v2i64)hadd_uw_u32_res0_m, 1); \ + hadd_uw_u32_res0_m += hadd_uw_u32_res1_m; \ + hadd_uw_u32_sum_m = __msa_copy_u_w((v4i32)hadd_uw_u32_res0_m, 0); \ + hadd_uw_u32_sum_m; \ }) /* Description : Horizontal addition of 8 unsigned halfword elements @@ -810,14 +812,14 @@ Details : 8 unsigned halfword elements of 'in' vector are added together and the resulting integer sum is returned */ -#define HADD_UH_U32(in) \ - ({ \ - v4u32 res_m; \ - uint32_t sum_m; \ - \ - res_m = __msa_hadd_u_w((v8u16)in, (v8u16)in); \ - sum_m = HADD_UW_U32(res_m); \ - sum_m; \ +#define HADD_UH_U32(in) \ + ({ \ + v4u32 hadd_uh_u32_res_m; \ + uint32_t hadd_uh_u32_sum_m; \ + \ + hadd_uh_u32_res_m = __msa_hadd_u_w((v8u16)in, (v8u16)in); \ + hadd_uh_u32_sum_m = HADD_UW_U32(hadd_uh_u32_res_m); \ + hadd_uh_u32_sum_m; \ }) /* Description : Horizontal addition of unsigned byte vector elements @@ -1461,15 +1463,15 @@ 'shift' is a vector. */ #define SRAR_W2(RTYPE, in0, in1, shift) \ - { \ + do { \ in0 = (RTYPE)__msa_srar_w((v4i32)in0, (v4i32)shift); \ in1 = (RTYPE)__msa_srar_w((v4i32)in1, (v4i32)shift); \ - } + } while (0) #define SRAR_W4(RTYPE, in0, in1, in2, in3, shift) \ { \ - SRAR_W2(RTYPE, in0, in1, shift) \ - SRAR_W2(RTYPE, in2, in3, shift) \ + SRAR_W2(RTYPE, in0, in1, shift); \ + SRAR_W2(RTYPE, in2, in3, shift); \ } #define SRAR_W4_SW(...) SRAR_W4(v4i32, __VA_ARGS__) diff --git a/libs/libvpx/vpx_dsp/mips/sad_mmi.c b/libs/libvpx/vpx_dsp/mips/sad_mmi.c index 7f5882bca3..7a7c927950 100644 --- a/libs/libvpx/vpx_dsp/mips/sad_mmi.c +++ b/libs/libvpx/vpx_dsp/mips/sad_mmi.c @@ -383,6 +383,7 @@ static inline unsigned int vpx_sad64x(const uint8_t *src, int src_stride, } vpx_sad64xN(64); +#if CONFIG_ENCODERS vpx_sad64xN(32); sadMxNx4D_mmi(64, 64); sadMxNx4D_mmi(64, 32); @@ -434,6 +435,7 @@ static inline unsigned int vpx_sad_avg64x(const uint8_t *src, int src_stride, vpx_sad_avg64xN(64); vpx_sad_avg64xN(32); +#endif // CONFIG_ENCODERS static inline unsigned int vpx_sad32x(const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, @@ -473,8 +475,9 @@ static inline unsigned int vpx_sad32x(const uint8_t *src, int src_stride, return vpx_sad32x(src, src_stride, ref, ref_stride, H); \ } -vpx_sad32xN(64); vpx_sad32xN(32); +#if CONFIG_ENCODERS +vpx_sad32xN(64); vpx_sad32xN(16); sadMxNx4D_mmi(32, 64); sadMxNx4D_mmi(32, 32); @@ -528,6 +531,7 @@ static inline unsigned int vpx_sad_avg32x(const uint8_t *src, int src_stride, vpx_sad_avg32xN(64); vpx_sad_avg32xN(32); vpx_sad_avg32xN(16); +#endif // CONFIG_ENCODERS static inline unsigned int vpx_sad16x(const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, @@ -567,8 +571,9 @@ static inline unsigned int vpx_sad16x(const uint8_t *src, int src_stride, return vpx_sad16x(src, src_stride, ref, ref_stride, H); \ } -vpx_sad16xN(32); vpx_sad16xN(16); +#if CONFIG_ENCODERS +vpx_sad16xN(32); vpx_sad16xN(8); sadMxNx4D_mmi(16, 32); sadMxNx4D_mmi(16, 16); @@ -805,3 +810,4 @@ static inline unsigned int vpx_sad_avg4x(const uint8_t *src, int src_stride, vpx_sad_avg4xN(8); vpx_sad_avg4xN(4); +#endif // CONFIG_ENCODERS diff --git a/libs/libvpx/vpx_dsp/mips/sad_msa.c b/libs/libvpx/vpx_dsp/mips/sad_msa.c index b0f8ff1fd9..ec23c548fb 100644 --- a/libs/libvpx/vpx_dsp/mips/sad_msa.c +++ b/libs/libvpx/vpx_dsp/mips/sad_msa.c @@ -20,6 +20,7 @@ } #define SAD_INSVE_W4_UB(...) SAD_INSVE_W4(v16u8, __VA_ARGS__) +#if CONFIG_ENCODERS static uint32_t sad_4width_msa(const uint8_t *src_ptr, int32_t src_stride, const uint8_t *ref_ptr, int32_t ref_stride, int32_t height) { @@ -66,6 +67,7 @@ static uint32_t sad_8width_msa(const uint8_t *src, int32_t src_stride, return HADD_UH_U32(sad); } +#endif // CONFIG_ENCODERS static uint32_t sad_16width_msa(const uint8_t *src, int32_t src_stride, const uint8_t *ref, int32_t ref_stride, @@ -159,6 +161,7 @@ static uint32_t sad_64width_msa(const uint8_t *src, int32_t src_stride, return sad; } +#if CONFIG_ENCODERS static void sad_4width_x4d_msa(const uint8_t *src_ptr, int32_t src_stride, const uint8_t *const aref_ptr[], int32_t ref_stride, int32_t height, @@ -632,6 +635,7 @@ static uint32_t avgsad_64width_msa(const uint8_t *src, int32_t src_stride, return HADD_SW_S32(sad); } +#endif // CONFIG_ENCODERS #define VPX_SAD_4xHEIGHT_MSA(height) \ uint32_t vpx_sad4x##height##_msa(const uint8_t *src, int32_t src_stride, \ @@ -738,6 +742,7 @@ static uint32_t avgsad_64width_msa(const uint8_t *src, int32_t src_stride, second_pred); \ } +#if CONFIG_ENCODERS // 64x64 VPX_SAD_64xHEIGHT_MSA(64); VPX_SAD_64xHEIGHTx4D_MSA(64); @@ -802,3 +807,13 @@ VPX_AVGSAD_4xHEIGHT_MSA(8); VPX_SAD_4xHEIGHT_MSA(4); VPX_SAD_4xHEIGHTx4D_MSA(4); VPX_AVGSAD_4xHEIGHT_MSA(4); +#else // !CONFIG_ENCODERS +// 64x64 +VPX_SAD_64xHEIGHT_MSA(64); + +// 32x32 +VPX_SAD_32xHEIGHT_MSA(32); + +// 16x16 +VPX_SAD_16xHEIGHT_MSA(16); +#endif // CONFIG_ENCODERS diff --git a/libs/libvpx/vpx_dsp/mips/variance_mmi.c b/libs/libvpx/vpx_dsp/mips/variance_mmi.c index c2adcfa018..6428bc7006 100644 --- a/libs/libvpx/vpx_dsp/mips/variance_mmi.c +++ b/libs/libvpx/vpx_dsp/mips/variance_mmi.c @@ -1120,7 +1120,7 @@ static inline void var_filter_block2d_bil_16x(const uint8_t *src_ptr, const uint8_t *ref_ptr, int ref_stride, uint32_t *sse) { \ uint8_t temp2[16 * (H)]; \ var_filter_block2d_bil_16x(src_ptr, src_stride, x_offset, y_offset, temp2, \ - ((H)-2) / 2); \ + ((H) - 2) / 2); \ \ return vpx_variance16x##H##_mmi(temp2, 16, ref_ptr, ref_stride, sse); \ } @@ -1219,7 +1219,7 @@ static inline void var_filter_block2d_bil_8x(const uint8_t *src_ptr, const uint8_t *ref_ptr, int ref_stride, uint32_t *sse) { \ uint8_t temp2[8 * (H)]; \ var_filter_block2d_bil_8x(src_ptr, src_stride, x_offset, y_offset, temp2, \ - ((H)-2) / 2); \ + ((H) - 2) / 2); \ \ return vpx_variance8x##H##_mmi(temp2, 8, ref_ptr, ref_stride, sse); \ } @@ -1315,7 +1315,7 @@ static inline void var_filter_block2d_bil_4x(const uint8_t *src_ptr, const uint8_t *ref_ptr, int ref_stride, uint32_t *sse) { \ uint8_t temp2[4 * (H)]; \ var_filter_block2d_bil_4x(src_ptr, src_stride, x_offset, y_offset, temp2, \ - ((H)-2) / 2); \ + ((H) - 2) / 2); \ \ return vpx_variance4x##H##_mmi(temp2, 4, ref_ptr, ref_stride, sse); \ } diff --git a/libs/libvpx/vpx_dsp/ppc/inv_txfm_vsx.c b/libs/libvpx/vpx_dsp/ppc/inv_txfm_vsx.c index e99412ecab..8c4e603dda 100644 --- a/libs/libvpx/vpx_dsp/ppc/inv_txfm_vsx.c +++ b/libs/libvpx/vpx_dsp/ppc/inv_txfm_vsx.c @@ -1060,19 +1060,19 @@ void vpx_idct16x16_256_add_vsx(const tran_low_t *input, uint8_t *dest, in[3][6], in[3][7], out[3][0], out[3][1], out[3][2], out[3][3], \ out[3][4], out[3][5], out[3][6], out[3][7]); -#define PIXEL_ADD_STORE32(in0, in1, in2, in3, step) \ - dst = vec_vsx_ld((step)*stride, dest); \ - d_uh = (int16x8_t)vec_mergeh(dst, zerov); \ - d_ul = (int16x8_t)vec_mergel(dst, zerov); \ - PIXEL_ADD(in0, d_uh, add, shift6); \ - PIXEL_ADD(in1, d_ul, add, shift6); \ - vec_vsx_st(vec_packsu(d_uh, d_ul), (step)*stride, dest); \ - dst = vec_vsx_ld((step)*stride + 16, dest); \ - d_uh = (int16x8_t)vec_mergeh(dst, zerov); \ - d_ul = (int16x8_t)vec_mergel(dst, zerov); \ - PIXEL_ADD(in2, d_uh, add, shift6); \ - PIXEL_ADD(in3, d_ul, add, shift6); \ - vec_vsx_st(vec_packsu(d_uh, d_ul), (step)*stride + 16, dest); +#define PIXEL_ADD_STORE32(in0, in1, in2, in3, step) \ + dst = vec_vsx_ld((step) * stride, dest); \ + d_uh = (int16x8_t)vec_mergeh(dst, zerov); \ + d_ul = (int16x8_t)vec_mergel(dst, zerov); \ + PIXEL_ADD(in0, d_uh, add, shift6); \ + PIXEL_ADD(in1, d_ul, add, shift6); \ + vec_vsx_st(vec_packsu(d_uh, d_ul), (step) * stride, dest); \ + dst = vec_vsx_ld((step) * stride + 16, dest); \ + d_uh = (int16x8_t)vec_mergeh(dst, zerov); \ + d_ul = (int16x8_t)vec_mergel(dst, zerov); \ + PIXEL_ADD(in2, d_uh, add, shift6); \ + PIXEL_ADD(in3, d_ul, add, shift6); \ + vec_vsx_st(vec_packsu(d_uh, d_ul), (step) * stride + 16, dest); #define ADD_STORE_BLOCK(in, offset) \ PIXEL_ADD_STORE32(in[0][0], in[1][0], in[2][0], in[3][0], (offset) + 0); \ diff --git a/libs/libvpx/vpx_dsp/ppc/quantize_vsx.c b/libs/libvpx/vpx_dsp/ppc/quantize_vsx.c index 7cdcbeb405..ab71f6e235 100644 --- a/libs/libvpx/vpx_dsp/ppc/quantize_vsx.c +++ b/libs/libvpx/vpx_dsp/ppc/quantize_vsx.c @@ -78,11 +78,10 @@ static INLINE int16x8_t dequantize_coeff_32(int16x8_t qcoeff, return (int16x8_t)vec_perm(dqcoeffe, dqcoeffo, vec_perm_odd_even_pack); } -static INLINE int16x8_t nonzero_scanindex(int16x8_t qcoeff, bool16x8_t mask, +static INLINE int16x8_t nonzero_scanindex(int16x8_t qcoeff, const int16_t *iscan_ptr, int index) { int16x8_t scan = vec_vsx_ld(index, iscan_ptr); bool16x8_t zero_coeff = vec_cmpeq(qcoeff, vec_zeros_s16); - scan = vec_sub(scan, mask); return vec_andc(scan, zero_coeff); } @@ -139,8 +138,8 @@ void vpx_quantize_b_vsx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, dqcoeff1 = vec_mladd(qcoeff1, dequant, vec_zeros_s16); vec_vsx_st(dqcoeff1, 16, dqcoeff_ptr); - eob = vec_max(nonzero_scanindex(qcoeff0, zero_mask0, iscan_ptr, 0), - nonzero_scanindex(qcoeff1, zero_mask1, iscan_ptr, 16)); + eob = vec_max(nonzero_scanindex(qcoeff0, iscan_ptr, 0), + nonzero_scanindex(qcoeff1, iscan_ptr, 16)); if (n_coeffs > 16) { int index = 16; @@ -177,10 +176,9 @@ void vpx_quantize_b_vsx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, vec_vsx_st(dqcoeff1, off1, dqcoeff_ptr); vec_vsx_st(dqcoeff2, off2, dqcoeff_ptr); - eob = - vec_max(eob, nonzero_scanindex(qcoeff0, zero_mask0, iscan_ptr, off0)); - eob2 = vec_max(nonzero_scanindex(qcoeff1, zero_mask1, iscan_ptr, off1), - nonzero_scanindex(qcoeff2, zero_mask2, iscan_ptr, off2)); + eob = vec_max(eob, nonzero_scanindex(qcoeff0, iscan_ptr, off0)); + eob2 = vec_max(nonzero_scanindex(qcoeff1, iscan_ptr, off1), + nonzero_scanindex(qcoeff2, iscan_ptr, off2)); eob = vec_max(eob, eob2); index += 24; @@ -252,8 +250,8 @@ void vpx_quantize_b_32x32_vsx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, dequant = vec_splat(dequant, 1); // remove DC from dequant vec_vsx_st(dequantize_coeff_32(qcoeff1, dequant), 16, dqcoeff_ptr); - eob = vec_max(nonzero_scanindex(qcoeff0, zero_mask0, iscan_ptr, 0), - nonzero_scanindex(qcoeff1, zero_mask1, iscan_ptr, 16)); + eob = vec_max(nonzero_scanindex(qcoeff0, iscan_ptr, 0), + nonzero_scanindex(qcoeff1, iscan_ptr, 16)); do { int16x8_t coeff2, coeff2_abs, qcoeff2, eob2; @@ -286,9 +284,9 @@ void vpx_quantize_b_32x32_vsx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, vec_vsx_st(dequantize_coeff_32(qcoeff1, dequant), off1, dqcoeff_ptr); vec_vsx_st(dequantize_coeff_32(qcoeff2, dequant), off2, dqcoeff_ptr); - eob = vec_max(eob, nonzero_scanindex(qcoeff0, zero_mask0, iscan_ptr, off0)); - eob2 = vec_max(nonzero_scanindex(qcoeff1, zero_mask1, iscan_ptr, off1), - nonzero_scanindex(qcoeff2, zero_mask2, iscan_ptr, off2)); + eob = vec_max(eob, nonzero_scanindex(qcoeff0, iscan_ptr, off0)); + eob2 = vec_max(nonzero_scanindex(qcoeff1, iscan_ptr, off1), + nonzero_scanindex(qcoeff2, iscan_ptr, off2)); eob = vec_max(eob, eob2); // 24 int16_t is 48 bytes diff --git a/libs/libvpx/vpx_dsp/ppc/sad_vsx.c b/libs/libvpx/vpx_dsp/ppc/sad_vsx.c index a08ae12413..64ca502190 100644 --- a/libs/libvpx/vpx_dsp/ppc/sad_vsx.c +++ b/libs/libvpx/vpx_dsp/ppc/sad_vsx.c @@ -181,10 +181,10 @@ SAD64AVG(64); for (i = 0; i < 4; i++) sad_array[i] = 0; \ \ for (y = 0; y < height; y++) { \ - UNPACK_SRC(y *src_stride, v_ah, v_al); \ + UNPACK_SRC(y * src_stride, v_ah, v_al); \ for (i = 0; i < 4; i++) { \ int32x4_t v_sad = vec_splat_s32(0); \ - PROCESS16_4D(y *ref_stride, ref_array[i], v_ah, v_al); \ + PROCESS16_4D(y * ref_stride, ref_array[i], v_ah, v_al); \ \ vec_vsx_st((uint32x4_t)v_sad, 0, sad); \ sad_array[i] += (sad[3] + sad[2] + sad[1] + sad[0]); \ @@ -206,12 +206,12 @@ SAD64AVG(64); for (i = 0; i < 4; i++) sad_array[i] = 0; \ \ for (y = 0; y < height; y++) { \ - UNPACK_SRC(y *src_stride, v_ah1, v_al1); \ - UNPACK_SRC(y *src_stride + 16, v_ah2, v_al2); \ + UNPACK_SRC(y * src_stride, v_ah1, v_al1); \ + UNPACK_SRC(y * src_stride + 16, v_ah2, v_al2); \ for (i = 0; i < 4; i++) { \ int32x4_t v_sad = vec_splat_s32(0); \ - PROCESS16_4D(y *ref_stride, ref_array[i], v_ah1, v_al1); \ - PROCESS16_4D(y *ref_stride + 16, ref_array[i], v_ah2, v_al2); \ + PROCESS16_4D(y * ref_stride, ref_array[i], v_ah1, v_al1); \ + PROCESS16_4D(y * ref_stride + 16, ref_array[i], v_ah2, v_al2); \ \ vec_vsx_st((uint32x4_t)v_sad, 0, sad); \ sad_array[i] += (sad[3] + sad[2] + sad[1] + sad[0]); \ @@ -234,16 +234,16 @@ SAD64AVG(64); for (i = 0; i < 4; i++) sad_array[i] = 0; \ \ for (y = 0; y < height; y++) { \ - UNPACK_SRC(y *src_stride, v_ah1, v_al1); \ - UNPACK_SRC(y *src_stride + 16, v_ah2, v_al2); \ - UNPACK_SRC(y *src_stride + 32, v_ah3, v_al3); \ - UNPACK_SRC(y *src_stride + 48, v_ah4, v_al4); \ + UNPACK_SRC(y * src_stride, v_ah1, v_al1); \ + UNPACK_SRC(y * src_stride + 16, v_ah2, v_al2); \ + UNPACK_SRC(y * src_stride + 32, v_ah3, v_al3); \ + UNPACK_SRC(y * src_stride + 48, v_ah4, v_al4); \ for (i = 0; i < 4; i++) { \ int32x4_t v_sad = vec_splat_s32(0); \ - PROCESS16_4D(y *ref_stride, ref_array[i], v_ah1, v_al1); \ - PROCESS16_4D(y *ref_stride + 16, ref_array[i], v_ah2, v_al2); \ - PROCESS16_4D(y *ref_stride + 32, ref_array[i], v_ah3, v_al3); \ - PROCESS16_4D(y *ref_stride + 48, ref_array[i], v_ah4, v_al4); \ + PROCESS16_4D(y * ref_stride, ref_array[i], v_ah1, v_al1); \ + PROCESS16_4D(y * ref_stride + 16, ref_array[i], v_ah2, v_al2); \ + PROCESS16_4D(y * ref_stride + 32, ref_array[i], v_ah3, v_al3); \ + PROCESS16_4D(y * ref_stride + 48, ref_array[i], v_ah4, v_al4); \ \ vec_vsx_st((uint32x4_t)v_sad, 0, sad); \ sad_array[i] += (sad[3] + sad[2] + sad[1] + sad[0]); \ diff --git a/libs/libvpx/vpx_dsp/ppc/types_vsx.h b/libs/libvpx/vpx_dsp/ppc/types_vsx.h index b891169245..9806b81cd0 100644 --- a/libs/libvpx/vpx_dsp/ppc/types_vsx.h +++ b/libs/libvpx/vpx_dsp/ppc/types_vsx.h @@ -64,7 +64,7 @@ static const uint8x16_t xxpermdi3_perm = { 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, #define unpack_to_s16_l(v) \ (int16x8_t) vec_mergel((uint8x16_t)v, vec_splat_u8(0)) #ifndef xxpermdi -#define xxpermdi(a, b, c) vec_xxpermdi(b, a, (((c) >> 1) | ((c)&1) << 1) ^ 3) +#define xxpermdi(a, b, c) vec_xxpermdi(b, a, (((c) >> 1) | ((c) & 1) << 1) ^ 3) #endif #endif diff --git a/libs/libvpx/vpx_dsp/ppc/variance_vsx.c b/libs/libvpx/vpx_dsp/ppc/variance_vsx.c index be9614a358..6c6bc9a301 100644 --- a/libs/libvpx/vpx_dsp/ppc/variance_vsx.c +++ b/libs/libvpx/vpx_dsp/ppc/variance_vsx.c @@ -225,7 +225,7 @@ static INLINE void variance(const uint8_t *src_ptr, int src_stride, } /* Identical to the variance call except it does not calculate the - * sse - sum^2 / w*h and returns sse in addtion to modifying the passed in + * sse - sum^2 / w*h and returns sse in addition to modifying the passed in * variable. */ #define MSE(W, H) \ diff --git a/libs/libvpx/vpx_dsp/prob.h b/libs/libvpx/vpx_dsp/prob.h index 7a71c0041f..a1c7de1674 100644 --- a/libs/libvpx/vpx_dsp/prob.h +++ b/libs/libvpx/vpx_dsp/prob.h @@ -30,7 +30,7 @@ typedef uint8_t vpx_prob; typedef int8_t vpx_tree_index; -#define TREE_SIZE(leaf_count) (2 * (leaf_count)-2) +#define TREE_SIZE(leaf_count) (2 * (leaf_count) - 2) #define vpx_complement(x) (255 - (x)) diff --git a/libs/libvpx/vpx_dsp/psnr.c b/libs/libvpx/vpx_dsp/psnr.c index 48bac04508..af1e638604 100644 --- a/libs/libvpx/vpx_dsp/psnr.c +++ b/libs/libvpx/vpx_dsp/psnr.c @@ -26,57 +26,44 @@ double vpx_sse_to_psnr(double samples, double peak, double sse) { /* TODO(yaowu): The block_variance calls the unoptimized versions of variance() * and highbd_8_variance(). It should not. */ -static void encoder_variance(const uint8_t *a, int a_stride, const uint8_t *b, - int b_stride, int w, int h, unsigned int *sse, - int *sum) { +static int64_t encoder_sse(const uint8_t *a, int a_stride, const uint8_t *b, + int b_stride, int w, int h) { int i, j; - - *sum = 0; - *sse = 0; + int64_t sse = 0; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { const int diff = a[j] - b[j]; - *sum += diff; - *sse += diff * diff; + sse += diff * diff; } a += a_stride; b += b_stride; } + + return sse; } #if CONFIG_VP9_HIGHBITDEPTH -static void encoder_highbd_variance64(const uint8_t *a8, int a_stride, - const uint8_t *b8, int b_stride, int w, - int h, uint64_t *sse, int64_t *sum) { +static int64_t encoder_highbd_sse(const uint8_t *a8, int a_stride, + const uint8_t *b8, int b_stride, int w, + int h) { int i, j; + int64_t sse = 0; - uint16_t *a = CONVERT_TO_SHORTPTR(a8); - uint16_t *b = CONVERT_TO_SHORTPTR(b8); - *sum = 0; - *sse = 0; + const uint16_t *a = CONVERT_TO_SHORTPTR(a8); + const uint16_t *b = CONVERT_TO_SHORTPTR(b8); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { const int diff = a[j] - b[j]; - *sum += diff; - *sse += diff * diff; + sse += diff * diff; } a += a_stride; b += b_stride; } -} -static void encoder_highbd_8_variance(const uint8_t *a8, int a_stride, - const uint8_t *b8, int b_stride, int w, - int h, unsigned int *sse, int *sum) { - uint64_t sse_long = 0; - int64_t sum_long = 0; - encoder_highbd_variance64(a8, a_stride, b8, b_stride, w, h, &sse_long, - &sum_long); - *sse = (unsigned int)sse_long; - *sum = (int)sum_long; + return sse; } #endif // CONFIG_VP9_HIGHBITDEPTH @@ -85,29 +72,24 @@ static int64_t get_sse(const uint8_t *a, int a_stride, const uint8_t *b, const int dw = width % 16; const int dh = height % 16; int64_t total_sse = 0; - unsigned int sse = 0; - int sum = 0; int x, y; if (dw > 0) { - encoder_variance(&a[width - dw], a_stride, &b[width - dw], b_stride, dw, - height, &sse, &sum); - total_sse += sse; + total_sse += encoder_sse(&a[width - dw], a_stride, &b[width - dw], b_stride, + dw, height); } if (dh > 0) { - encoder_variance(&a[(height - dh) * a_stride], a_stride, - &b[(height - dh) * b_stride], b_stride, width - dw, dh, - &sse, &sum); - total_sse += sse; + total_sse += + encoder_sse(&a[(height - dh) * a_stride], a_stride, + &b[(height - dh) * b_stride], b_stride, width - dw, dh); } for (y = 0; y < height / 16; ++y) { const uint8_t *pa = a; const uint8_t *pb = b; for (x = 0; x < width / 16; ++x) { - vpx_mse16x16(pa, a_stride, pb, b_stride, &sse); - total_sse += sse; + total_sse += vpx_sse(pa, a_stride, pb, b_stride, 16, 16); pa += 16; pb += 16; @@ -146,25 +128,20 @@ static int64_t highbd_get_sse(const uint8_t *a, int a_stride, const uint8_t *b, int x, y; const int dw = width % 16; const int dh = height % 16; - unsigned int sse = 0; - int sum = 0; if (dw > 0) { - encoder_highbd_8_variance(&a[width - dw], a_stride, &b[width - dw], - b_stride, dw, height, &sse, &sum); - total_sse += sse; + total_sse += encoder_highbd_sse(&a[width - dw], a_stride, &b[width - dw], + b_stride, dw, height); } if (dh > 0) { - encoder_highbd_8_variance(&a[(height - dh) * a_stride], a_stride, - &b[(height - dh) * b_stride], b_stride, - width - dw, dh, &sse, &sum); - total_sse += sse; + total_sse += encoder_highbd_sse(&a[(height - dh) * a_stride], a_stride, + &b[(height - dh) * b_stride], b_stride, + width - dw, dh); } for (y = 0; y < height / 16; ++y) { const uint8_t *pa = a; const uint8_t *pb = b; for (x = 0; x < width / 16; ++x) { - vpx_highbd_8_mse16x16(pa, a_stride, pb, b_stride, &sse); - total_sse += sse; + total_sse += vpx_highbd_sse(pa, a_stride, pb, b_stride, 16, 16); pa += 16; pb += 16; } @@ -200,7 +177,8 @@ int64_t vpx_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a, #if CONFIG_VP9_HIGHBITDEPTH void vpx_calc_highbd_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, PSNR_STATS *psnr, - uint32_t bit_depth, uint32_t in_bit_depth) { + uint32_t bit_depth, uint32_t in_bit_depth, + int spatial_layer_id) { const int widths[3] = { a->y_crop_width, a->uv_crop_width, a->uv_crop_width }; const int heights[3] = { a->y_crop_height, a->uv_crop_height, a->uv_crop_height }; @@ -242,12 +220,13 @@ void vpx_calc_highbd_psnr(const YV12_BUFFER_CONFIG *a, psnr->samples[0] = total_samples; psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, peak, (double)total_sse); + psnr->spatial_layer_id = spatial_layer_id; } #endif // !CONFIG_VP9_HIGHBITDEPTH void vpx_calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, - PSNR_STATS *psnr) { + PSNR_STATS *psnr, int spatial_layer_id) { static const double peak = 255.0; const int widths[3] = { a->y_crop_width, a->uv_crop_width, a->uv_crop_width }; const int heights[3] = { a->y_crop_height, a->uv_crop_height, @@ -278,4 +257,5 @@ void vpx_calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, psnr->samples[0] = total_samples; psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, peak, (double)total_sse); + psnr->spatial_layer_id = spatial_layer_id; } diff --git a/libs/libvpx/vpx_dsp/psnr.h b/libs/libvpx/vpx_dsp/psnr.h index 9ebb64dd52..88fde5bb7e 100644 --- a/libs/libvpx/vpx_dsp/psnr.h +++ b/libs/libvpx/vpx_dsp/psnr.h @@ -26,7 +26,7 @@ typedef struct vpx_psnr_pkt PSNR_STATS; /*!\brief Converts SSE to PSNR * - * Converts sum of squared errros (SSE) to peak signal-to-noise ratio (PNSR). + * Converts sum of squared errros (SSE) to peak signal-to-noise ratio (PSNR). * * \param[in] samples Number of samples * \param[in] peak Max sample value @@ -39,10 +39,11 @@ int64_t vpx_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b); void vpx_calc_highbd_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, PSNR_STATS *psnr, - unsigned int bit_depth, unsigned int in_bit_depth); + unsigned int bit_depth, unsigned int in_bit_depth, + int spatial_layer_id); #endif void vpx_calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, - PSNR_STATS *psnr); + PSNR_STATS *psnr, int spatial_layer_id); double vpx_psnrhvs(const YV12_BUFFER_CONFIG *source, const YV12_BUFFER_CONFIG *dest, double *phvs_y, diff --git a/libs/libvpx/vpx_dsp/quantize.c b/libs/libvpx/vpx_dsp/quantize.c index 5d6ba64a8a..fac9136f8c 100644 --- a/libs/libvpx/vpx_dsp/quantize.c +++ b/libs/libvpx/vpx_dsp/quantize.c @@ -14,6 +14,8 @@ #include "vpx_dsp/quantize.h" #include "vpx_dsp/vpx_dsp_common.h" #include "vpx_mem/vpx_mem.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" void vpx_quantize_dc(const tran_low_t *coeff_ptr, int n_coeffs, const int16_t *round_ptr, const int16_t quant, @@ -114,15 +116,17 @@ void vpx_highbd_quantize_dc_32x32(const tran_low_t *coeff_ptr, #endif void vpx_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, const int16_t *round_ptr, - const int16_t *quant_ptr, const int16_t *quant_shift_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { + const struct ScanOrder *const scan_order) { int i, non_zero_count = (int)n_coeffs, eob = -1; - const int zbins[2] = { zbin_ptr[0], zbin_ptr[1] }; + const int zbins[2] = { mb_plane->zbin[0], mb_plane->zbin[1] }; const int nzbins[2] = { zbins[0] * -1, zbins[1] * -1 }; - (void)iscan; + const int16_t *round_ptr = mb_plane->round; + const int16_t *quant_ptr = mb_plane->quant; + const int16_t *quant_shift_ptr = mb_plane->quant_shift; + const int16_t *scan = scan_order->scan; memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); @@ -162,16 +166,17 @@ void vpx_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, #if CONFIG_VP9_HIGHBITDEPTH void vpx_highbd_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { + const struct ScanOrder *const scan_order) { int i, non_zero_count = (int)n_coeffs, eob = -1; - const int zbins[2] = { zbin_ptr[0], zbin_ptr[1] }; + const int zbins[2] = { mb_plane->zbin[0], mb_plane->zbin[1] }; const int nzbins[2] = { zbins[0] * -1, zbins[1] * -1 }; - (void)iscan; + const int16_t *round_ptr = mb_plane->round; + const int16_t *quant_ptr = mb_plane->quant; + const int16_t *quant_shift_ptr = mb_plane->quant_shift; + const int16_t *scan = scan_order->scan; memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); @@ -208,21 +213,23 @@ void vpx_highbd_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, } #endif -void vpx_quantize_b_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, +void vpx_quantize_b_32x32_c(const tran_low_t *coeff_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { - const int zbins[2] = { ROUND_POWER_OF_TWO(zbin_ptr[0], 1), - ROUND_POWER_OF_TWO(zbin_ptr[1], 1) }; + const struct ScanOrder *const scan_order) { + const int n_coeffs = 32 * 32; + const int zbins[2] = { ROUND_POWER_OF_TWO(mb_plane->zbin[0], 1), + ROUND_POWER_OF_TWO(mb_plane->zbin[1], 1) }; const int nzbins[2] = { zbins[0] * -1, zbins[1] * -1 }; + const int16_t *round_ptr = mb_plane->round; + const int16_t *quant_ptr = mb_plane->quant; + const int16_t *quant_shift_ptr = mb_plane->quant_shift; + const int16_t *scan = scan_order->scan; int idx = 0; - int idx_arr[1024]; + int idx_arr[32 * 32 /* n_coeffs */]; int i, eob = -1; - (void)iscan; memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); @@ -269,19 +276,21 @@ void vpx_quantize_b_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, #if CONFIG_VP9_HIGHBITDEPTH void vpx_highbd_quantize_b_32x32_c( - const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, - const int16_t *round_ptr, const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, - tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { - const int zbins[2] = { ROUND_POWER_OF_TWO(zbin_ptr[0], 1), - ROUND_POWER_OF_TWO(zbin_ptr[1], 1) }; + const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, + uint16_t *eob_ptr, const struct ScanOrder *const scan_order) { + const intptr_t n_coeffs = 32 * 32; + const int zbins[2] = { ROUND_POWER_OF_TWO(mb_plane->zbin[0], 1), + ROUND_POWER_OF_TWO(mb_plane->zbin[1], 1) }; const int nzbins[2] = { zbins[0] * -1, zbins[1] * -1 }; + const int16_t *round_ptr = mb_plane->round; + const int16_t *quant_ptr = mb_plane->quant; + const int16_t *quant_shift_ptr = mb_plane->quant_shift; + const int16_t *scan = scan_order->scan; int idx = 0; int idx_arr[1024]; int i, eob = -1; - (void)iscan; memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); diff --git a/libs/libvpx/vpx_dsp/sad.c b/libs/libvpx/vpx_dsp/sad.c index b47c43430d..ae360507cc 100644 --- a/libs/libvpx/vpx_dsp/sad.c +++ b/libs/libvpx/vpx_dsp/sad.c @@ -32,6 +32,8 @@ static INLINE unsigned int sad(const uint8_t *src_ptr, int src_stride, return sad; } +#if CONFIG_ENCODERS + #define sadMxN(m, n) \ unsigned int vpx_sad##m##x##n##_c(const uint8_t *src_ptr, int src_stride, \ const uint8_t *ref_ptr, int ref_stride) { \ @@ -40,9 +42,15 @@ static INLINE unsigned int sad(const uint8_t *src_ptr, int src_stride, unsigned int vpx_sad##m##x##n##_avg_c( \ const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ int ref_stride, const uint8_t *second_pred) { \ - DECLARE_ALIGNED(16, uint8_t, comp_pred[m * n]); \ + DECLARE_ALIGNED(32, uint8_t, comp_pred[m * n]); \ vpx_comp_avg_pred_c(comp_pred, second_pred, m, n, ref_ptr, ref_stride); \ return sad(src_ptr, src_stride, comp_pred, m, m, n); \ + } \ + unsigned int vpx_sad_skip_##m##x##n##_c( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride) { \ + return 2 * sad(src_ptr, 2 * src_stride, ref_ptr, 2 * ref_stride, (m), \ + (n / 2)); \ } // Compare |src_ptr| to 4 distinct references in |ref_array[4]| @@ -54,13 +62,40 @@ static INLINE unsigned int sad(const uint8_t *src_ptr, int src_stride, for (i = 0; i < 4; ++i) \ sad_array[i] = \ vpx_sad##m##x##n##_c(src_ptr, src_stride, ref_array[i], ref_stride); \ + } \ + void vpx_sad_skip_##m##x##n##x4d_c(const uint8_t *src_ptr, int src_stride, \ + const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + int i; \ + for (i = 0; i < 4; ++i) { \ + sad_array[i] = 2 * sad(src_ptr, 2 * src_stride, ref_array[i], \ + 2 * ref_stride, (m), (n / 2)); \ + } \ } +#else // !CONFIG_ENCODERS +#define sadMxN(m, n) \ + unsigned int vpx_sad##m##x##n##_c(const uint8_t *src_ptr, int src_stride, \ + const uint8_t *ref_ptr, int ref_stride) { \ + return sad(src_ptr, src_stride, ref_ptr, ref_stride, m, n); \ + } + +#define sadMxNx4D(m, n) +#endif // CONFIG_ENCODERS /* clang-format off */ // 64x64 sadMxN(64, 64) sadMxNx4D(64, 64) +// 32x32 +sadMxN(32, 32) +sadMxNx4D(32, 32) + +// 16x16 +sadMxN(16, 16) +sadMxNx4D(16, 16) + +#if CONFIG_ENCODERS // 64x32 sadMxN(64, 32) sadMxNx4D(64, 32) @@ -69,10 +104,6 @@ sadMxNx4D(64, 32) sadMxN(32, 64) sadMxNx4D(32, 64) -// 32x32 -sadMxN(32, 32) -sadMxNx4D(32, 32) - // 32x16 sadMxN(32, 16) sadMxNx4D(32, 16) @@ -81,10 +112,6 @@ sadMxNx4D(32, 16) sadMxN(16, 32) sadMxNx4D(16, 32) -// 16x16 -sadMxN(16, 16) -sadMxNx4D(16, 16) - // 16x8 sadMxN(16, 8) sadMxNx4D(16, 8) @@ -108,9 +135,10 @@ sadMxNx4D(4, 8) // 4x4 sadMxN(4, 4) sadMxNx4D(4, 4) +#endif // CONFIG_ENCODERS /* clang-format on */ -#if CONFIG_VP9_HIGHBITDEPTH +#if CONFIG_VP9_HIGHBITDEPTH && CONFIG_ENCODERS static INLINE unsigned int highbd_sad(const uint8_t *src8_ptr, int src_stride, const uint8_t *ref8_ptr, int ref_stride, int width, @@ -156,6 +184,12 @@ static INLINE unsigned int highbd_sadb(const uint8_t *src8_ptr, int src_stride, vpx_highbd_comp_avg_pred_c(comp_pred, CONVERT_TO_SHORTPTR(second_pred), m, \ n, CONVERT_TO_SHORTPTR(ref_ptr), ref_stride); \ return highbd_sadb(src_ptr, src_stride, comp_pred, m, m, n); \ + } \ + unsigned int vpx_highbd_sad_skip_##m##x##n##_c( \ + const uint8_t *src, int src_stride, const uint8_t *ref, \ + int ref_stride) { \ + return 2 * \ + highbd_sad(src, 2 * src_stride, ref, 2 * ref_stride, (m), (n / 2)); \ } #define highbd_sadMxNx4D(m, n) \ @@ -167,6 +201,15 @@ static INLINE unsigned int highbd_sadb(const uint8_t *src8_ptr, int src_stride, sad_array[i] = vpx_highbd_sad##m##x##n##_c(src_ptr, src_stride, \ ref_array[i], ref_stride); \ } \ + } \ + void vpx_highbd_sad_skip_##m##x##n##x4d_c( \ + const uint8_t *src, int src_stride, const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + int i; \ + for (i = 0; i < 4; ++i) { \ + sad_array[i] = vpx_highbd_sad_skip_##m##x##n##_c( \ + src, src_stride, ref_array[i], ref_stride); \ + } \ } /* clang-format off */ @@ -223,4 +266,4 @@ highbd_sadMxN(4, 4) highbd_sadMxNx4D(4, 4) /* clang-format on */ -#endif // CONFIG_VP9_HIGHBITDEPTH +#endif // CONFIG_VP9_HIGHBITDEPTH && CONFIG_ENCODERS diff --git a/libs/libvpx/vpx_dsp/sse.c b/libs/libvpx/vpx_dsp/sse.c new file mode 100644 index 0000000000..c9d751859d --- /dev/null +++ b/libs/libvpx/vpx_dsp/sse.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +/* + * Sum the square of the difference between every corresponding element of the + * buffers. + */ + +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" + +#include "vpx/vpx_integer.h" +#include "vpx_ports/mem.h" + +int64_t vpx_sse_c(const uint8_t *a, int a_stride, const uint8_t *b, + int b_stride, int width, int height) { + int y, x; + int64_t sse = 0; + + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + const int32_t diff = abs(a[x] - b[x]); + sse += diff * diff; + } + + a += a_stride; + b += b_stride; + } + return sse; +} + +#if CONFIG_VP9_HIGHBITDEPTH +int64_t vpx_highbd_sse_c(const uint8_t *a8, int a_stride, const uint8_t *b8, + int b_stride, int width, int height) { + int y, x; + int64_t sse = 0; + uint16_t *a = CONVERT_TO_SHORTPTR(a8); + uint16_t *b = CONVERT_TO_SHORTPTR(b8); + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + const int32_t diff = (int32_t)(a[x]) - (int32_t)(b[x]); + sse += diff * diff; + } + + a += a_stride; + b += b_stride; + } + return sse; +} +#endif diff --git a/libs/libvpx/vpx_dsp/ssim.c b/libs/libvpx/vpx_dsp/ssim.c index 7c3c31bad8..4a31f3d223 100644 --- a/libs/libvpx/vpx_dsp/ssim.c +++ b/libs/libvpx/vpx_dsp/ssim.c @@ -15,21 +15,6 @@ #include "vpx_ports/mem.h" #include "vpx_ports/system_state.h" -void vpx_ssim_parms_16x16_c(const uint8_t *s, int sp, const uint8_t *r, int rp, - uint32_t *sum_s, uint32_t *sum_r, - uint32_t *sum_sq_s, uint32_t *sum_sq_r, - uint32_t *sum_sxr) { - int i, j; - for (i = 0; i < 16; i++, s += sp, r += rp) { - for (j = 0; j < 16; j++) { - *sum_s += s[j]; - *sum_r += r[j]; - *sum_sq_s += s[j] * s[j]; - *sum_sq_r += r[j] * r[j]; - *sum_sxr += s[j] * r[j]; - } - } -} void vpx_ssim_parms_8x8_c(const uint8_t *s, int sp, const uint8_t *r, int rp, uint32_t *sum_s, uint32_t *sum_r, uint32_t *sum_sq_s, uint32_t *sum_sq_r, uint32_t *sum_sxr) { diff --git a/libs/libvpx/vpx_dsp/ssim.h b/libs/libvpx/vpx_dsp/ssim.h index c382237fc6..8ee1581d81 100644 --- a/libs/libvpx/vpx_dsp/ssim.h +++ b/libs/libvpx/vpx_dsp/ssim.h @@ -11,7 +11,7 @@ #ifndef VPX_VPX_DSP_SSIM_H_ #define VPX_VPX_DSP_SSIM_H_ -#define MAX_SSIM_DB 100.0; +#define MAX_SSIM_DB 100.0 #ifdef __cplusplus extern "C" { diff --git a/libs/libvpx/vpx_dsp/variance.c b/libs/libvpx/vpx_dsp/variance.c index 30b55dcb40..d9976339d4 100644 --- a/libs/libvpx/vpx_dsp/variance.c +++ b/libs/libvpx/vpx_dsp/variance.c @@ -7,10 +7,14 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include +#include +#include #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" +#include "vpx_ports/compiler_attributes.h" #include "vpx_ports/mem.h" #include "vpx/vpx_integer.h" @@ -156,7 +160,7 @@ static void var_filter_block2d_bil_second_pass( const uint8_t *second_pred) { \ uint16_t fdata3[(H + 1) * W]; \ uint8_t temp2[H * W]; \ - DECLARE_ALIGNED(16, uint8_t, temp3[H * W]); \ + DECLARE_ALIGNED(32, uint8_t, temp3[H * W]); \ \ var_filter_block2d_bil_first_pass(src_ptr, fdata3, src_stride, 1, H + 1, \ W, bilinear_filters[x_offset]); \ @@ -180,7 +184,7 @@ static void var_filter_block2d_bil_second_pass( } /* Identical to the variance call except it does not calculate the - * sse - sum^2 / w*h and returns sse in addtion to modifying the passed in + * sse - sum^2 / w*h and returns sse in addition to modifying the passed in * variable. */ #define MSE(W, H) \ @@ -236,6 +240,20 @@ void vpx_comp_avg_pred_c(uint8_t *comp_pred, const uint8_t *pred, int width, } #if CONFIG_VP9_HIGHBITDEPTH +// Note this function uses unsigned integer math in calculating the sum squared +// error to avoid reports of signed integer overflow should a (fuzzing) test +// use input values that are outside of the valid range for 12-bit content. The +// additional annotation is necessary as an overflow will still be reported +// with the integer/unsigned-integer-overflow (not undefined) sanitizer. +// This function assumes `abs(value) <= UINT16_MAX`, as the only overflow +// that's expected is from casting negative signed integer values to unsigned +// and squaring the result. +static VPX_NO_UNSIGNED_OVERFLOW_CHECK uint32_t square_value(int value) { + assert(abs(value) <= UINT16_MAX); + const uint32_t unsigned_value = (uint32_t)value; + return unsigned_value * unsigned_value; +} + static void highbd_variance64(const uint8_t *src8_ptr, int src_stride, const uint8_t *ref8_ptr, int ref_stride, int w, int h, uint64_t *sse, int64_t *sum) { @@ -250,7 +268,7 @@ static void highbd_variance64(const uint8_t *src8_ptr, int src_stride, for (j = 0; j < w; ++j) { const int diff = src_ptr[j] - ref_ptr[j]; *sum += diff; - *sse += diff * diff; + *sse += square_value(diff); } src_ptr += src_stride; ref_ptr += ref_stride; @@ -549,9 +567,9 @@ HIGHBD_MSE(16, 8) HIGHBD_MSE(8, 16) HIGHBD_MSE(8, 8) -void vpx_highbd_comp_avg_pred(uint16_t *comp_pred, const uint16_t *pred, - int width, int height, const uint16_t *ref, - int ref_stride) { +void vpx_highbd_comp_avg_pred_c(uint16_t *comp_pred, const uint16_t *pred, + int width, int height, const uint16_t *ref, + int ref_stride) { int i, j; for (i = 0; i < height; ++i) { for (j = 0; j < width; ++j) { diff --git a/libs/libvpx/vpx_dsp/variance.h b/libs/libvpx/vpx_dsp/variance.h index 755cb907d2..ccdb2f90ba 100644 --- a/libs/libvpx/vpx_dsp/variance.h +++ b/libs/libvpx/vpx_dsp/variance.h @@ -69,11 +69,15 @@ typedef struct variance_vtable { #if CONFIG_VP9 typedef struct vp9_variance_vtable { vpx_sad_fn_t sdf; + // Same as normal sad, but downsample the rows by a factor of 2. + vpx_sad_fn_t sdsf; vpx_sad_avg_fn_t sdaf; vpx_variance_fn_t vf; vpx_subpixvariance_fn_t svf; vpx_subp_avg_variance_fn_t svaf; vpx_sad_multi_d_fn_t sdx4df; + // Same as sadx4, but downsample the rows by a factor of 2. + vpx_sad_multi_d_fn_t sdsx4df; } vp9_variance_fn_ptr_t; #endif // CONFIG_VP9 diff --git a/libs/libvpx/vpx_dsp/vpx_dsp.mk b/libs/libvpx/vpx_dsp/vpx_dsp.mk index 13999af04d..61c1a3d8ec 100644 --- a/libs/libvpx/vpx_dsp/vpx_dsp.mk +++ b/libs/libvpx/vpx_dsp/vpx_dsp.mk @@ -31,10 +31,15 @@ DSP_SRCS-yes += bitwriter_buffer.c DSP_SRCS-yes += bitwriter_buffer.h DSP_SRCS-yes += psnr.c DSP_SRCS-yes += psnr.h +DSP_SRCS-yes += sse.c DSP_SRCS-$(CONFIG_INTERNAL_STATS) += ssim.c DSP_SRCS-$(CONFIG_INTERNAL_STATS) += ssim.h DSP_SRCS-$(CONFIG_INTERNAL_STATS) += psnrhvs.c DSP_SRCS-$(CONFIG_INTERNAL_STATS) += fastssim.c +DSP_SRCS-$(HAVE_NEON) += arm/sse_neon.c +DSP_SRCS-$(HAVE_NEON_DOTPROD) += arm/sse_neon_dotprod.c +DSP_SRCS-$(HAVE_SSE4_1) += x86/sse_sse4.c +DSP_SRCS-$(HAVE_AVX2) += x86/sse_avx2.c endif ifeq ($(CONFIG_DECODERS),yes) @@ -47,14 +52,20 @@ endif # intra predictions DSP_SRCS-yes += intrapred.c +ifeq ($(HAVE_X86_ASM),yes) DSP_SRCS-$(HAVE_SSE2) += x86/intrapred_sse2.asm DSP_SRCS-$(HAVE_SSSE3) += x86/intrapred_ssse3.asm +endif DSP_SRCS-$(HAVE_VSX) += ppc/intrapred_vsx.c ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes) +ifeq ($(HAVE_X86_ASM),yes) DSP_SRCS-$(HAVE_SSE2) += x86/highbd_intrapred_sse2.asm +endif DSP_SRCS-$(HAVE_SSE2) += x86/highbd_intrapred_intrin_sse2.c DSP_SRCS-$(HAVE_SSSE3) += x86/highbd_intrapred_intrin_ssse3.c +DSP_SRCS-$(HAVE_AVX2) += x86/highbd_intrapred_intrin_avx2.c +DSP_SRCS-$(HAVE_AVX512) += x86/highbd_intrapred_intrin_avx512.c DSP_SRCS-$(HAVE_NEON) += arm/highbd_intrapred_neon.c endif # CONFIG_VP9_HIGHBITDEPTH @@ -65,9 +76,10 @@ DSP_SRCS-yes += postproc.h DSP_SRCS-$(HAVE_MSA) += mips/add_noise_msa.c DSP_SRCS-$(HAVE_MSA) += mips/deblock_msa.c DSP_SRCS-$(HAVE_NEON) += arm/deblock_neon.c +ifeq ($(HAVE_X86_ASM),yes) DSP_SRCS-$(HAVE_SSE2) += x86/add_noise_sse2.asm -DSP_SRCS-$(HAVE_SSE2) += x86/deblock_sse2.asm -DSP_SRCS-$(HAVE_SSE2) += x86/post_proc_sse2.c +endif +DSP_SRCS-$(HAVE_SSE2) += x86/deblock_sse2.c DSP_SRCS-$(HAVE_VSX) += ppc/deblock_vsx.c endif # CONFIG_POSTPROC @@ -93,6 +105,8 @@ DSP_SRCS-$(VPX_ARCH_X86)$(VPX_ARCH_X86_64) += x86/convolve.h DSP_SRCS-$(HAVE_SSE2) += x86/convolve_sse2.h DSP_SRCS-$(HAVE_SSSE3) += x86/convolve_ssse3.h DSP_SRCS-$(HAVE_AVX2) += x86/convolve_avx2.h +ifeq ($(HAVE_X86_ASM),yes) +DSP_SRCS-$(HAVE_SSE2) += x86/vpx_convolve_copy_sse2.asm DSP_SRCS-$(HAVE_SSE2) += x86/vpx_subpixel_8t_sse2.asm DSP_SRCS-$(HAVE_SSE2) += x86/vpx_subpixel_4t_intrin_sse2.c DSP_SRCS-$(HAVE_SSE2) += x86/vpx_subpixel_bilinear_sse2.asm @@ -100,17 +114,20 @@ DSP_SRCS-$(HAVE_SSSE3) += x86/vpx_subpixel_8t_ssse3.asm DSP_SRCS-$(HAVE_SSSE3) += x86/vpx_subpixel_bilinear_ssse3.asm DSP_SRCS-$(HAVE_AVX2) += x86/vpx_subpixel_8t_intrin_avx2.c DSP_SRCS-$(HAVE_SSSE3) += x86/vpx_subpixel_8t_intrin_ssse3.c +endif ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes) +ifeq ($(HAVE_X86_ASM),yes) DSP_SRCS-$(HAVE_SSE2) += x86/vpx_high_subpixel_8t_sse2.asm DSP_SRCS-$(HAVE_SSE2) += x86/vpx_high_subpixel_bilinear_sse2.asm +endif DSP_SRCS-$(HAVE_AVX2) += x86/highbd_convolve_avx2.c DSP_SRCS-$(HAVE_NEON) += arm/highbd_vpx_convolve_copy_neon.c DSP_SRCS-$(HAVE_NEON) += arm/highbd_vpx_convolve_avg_neon.c DSP_SRCS-$(HAVE_NEON) += arm/highbd_vpx_convolve8_neon.c -DSP_SRCS-$(HAVE_NEON) += arm/highbd_vpx_convolve_neon.c +DSP_SRCS-$(HAVE_SVE) += arm/highbd_vpx_convolve8_sve.c +DSP_SRCS-$(HAVE_SVE2) += arm/highbd_vpx_convolve8_sve2.c endif -DSP_SRCS-$(HAVE_SSE2) += x86/vpx_convolve_copy_sse2.asm DSP_SRCS-$(HAVE_NEON) += arm/vpx_scaled_convolve8_neon.c ifeq ($(HAVE_NEON_ASM),yes) @@ -133,6 +150,8 @@ DSP_SRCS-yes += arm/vpx_convolve_copy_neon.c DSP_SRCS-yes += arm/vpx_convolve8_neon.c DSP_SRCS-yes += arm/vpx_convolve_avg_neon.c DSP_SRCS-yes += arm/vpx_convolve_neon.c +DSP_SRCS-$(HAVE_NEON_DOTPROD) += arm/vpx_convolve8_neon_dotprod.c +DSP_SRCS-$(HAVE_NEON_I8MM) += arm/vpx_convolve8_neon_i8mm.c endif # HAVE_NEON endif # HAVE_NEON_ASM @@ -223,22 +242,22 @@ DSP_SRCS-$(HAVE_SSE2) += x86/fwd_txfm_sse2.h DSP_SRCS-$(HAVE_SSE2) += x86/fwd_txfm_sse2.c DSP_SRCS-$(HAVE_SSE2) += x86/fwd_txfm_impl_sse2.h DSP_SRCS-$(HAVE_SSE2) += x86/fwd_dct32x32_impl_sse2.h -ifeq ($(VPX_ARCH_X86_64),yes) +ifeq ($(VPX_ARCH_X86_64)$(HAVE_X86_ASM),yesyes) DSP_SRCS-$(HAVE_SSSE3) += x86/fwd_txfm_ssse3_x86_64.asm endif -DSP_SRCS-$(HAVE_AVX2) += x86/fwd_txfm_avx2.c DSP_SRCS-$(HAVE_AVX2) += x86/fwd_dct32x32_impl_avx2.h -DSP_SRCS-$(HAVE_NEON) += arm/fdct_neon.c +DSP_SRCS-$(HAVE_NEON) += arm/fdct4x4_neon.c +DSP_SRCS-$(HAVE_NEON) += arm/fdct8x8_neon.c DSP_SRCS-$(HAVE_NEON) += arm/fdct16x16_neon.c DSP_SRCS-$(HAVE_NEON) += arm/fdct32x32_neon.c DSP_SRCS-$(HAVE_NEON) += arm/fdct_partial_neon.c -DSP_SRCS-$(HAVE_NEON) += arm/fwd_txfm_neon.c DSP_SRCS-$(HAVE_MSA) += mips/fwd_txfm_msa.h DSP_SRCS-$(HAVE_MSA) += mips/fwd_txfm_msa.c DSP_SRCS-$(HAVE_LSX) += loongarch/fwd_txfm_lsx.h DSP_SRCS-$(HAVE_LSX) += loongarch/fwd_txfm_lsx.c ifneq ($(CONFIG_VP9_HIGHBITDEPTH),yes) +DSP_SRCS-$(HAVE_AVX2) += x86/fwd_txfm_avx2.c DSP_SRCS-$(HAVE_MSA) += mips/fwd_dct32x32_msa.c DSP_SRCS-$(HAVE_LSX) += loongarch/fwd_dct32x32_lsx.c endif # !CONFIG_VP9_HIGHBITDEPTH @@ -252,7 +271,10 @@ DSP_SRCS-yes += inv_txfm.h DSP_SRCS-yes += inv_txfm.c DSP_SRCS-$(HAVE_SSE2) += x86/inv_txfm_sse2.h DSP_SRCS-$(HAVE_SSE2) += x86/inv_txfm_sse2.c +DSP_SRCS-$(HAVE_AVX2) += x86/inv_txfm_avx2.c +ifeq ($(HAVE_X86_ASM),yes) DSP_SRCS-$(HAVE_SSE2) += x86/inv_wht_sse2.asm +endif DSP_SRCS-$(HAVE_SSSE3) += x86/inv_txfm_ssse3.h DSP_SRCS-$(HAVE_SSSE3) += x86/inv_txfm_ssse3.c @@ -326,11 +348,14 @@ DSP_SRCS-$(HAVE_SSE2) += x86/quantize_sse2.h DSP_SRCS-$(HAVE_SSSE3) += x86/quantize_ssse3.c DSP_SRCS-$(HAVE_SSSE3) += x86/quantize_ssse3.h DSP_SRCS-$(HAVE_AVX) += x86/quantize_avx.c +DSP_SRCS-$(HAVE_AVX2) += x86/quantize_avx2.c DSP_SRCS-$(HAVE_NEON) += arm/quantize_neon.c DSP_SRCS-$(HAVE_VSX) += ppc/quantize_vsx.c DSP_SRCS-$(HAVE_LSX) += loongarch/quantize_lsx.c ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes) DSP_SRCS-$(HAVE_SSE2) += x86/highbd_quantize_intrin_sse2.c +DSP_SRCS-$(HAVE_AVX2) += x86/highbd_quantize_intrin_avx2.c +DSP_SRCS-$(HAVE_NEON) += arm/highbd_quantize_neon.c endif # avg @@ -339,9 +364,13 @@ DSP_SRCS-$(HAVE_SSE2) += x86/avg_intrin_sse2.c DSP_SRCS-$(HAVE_AVX2) += x86/avg_intrin_avx2.c DSP_SRCS-$(HAVE_NEON) += arm/avg_neon.c DSP_SRCS-$(HAVE_NEON) += arm/hadamard_neon.c +ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes) +DSP_SRCS-$(HAVE_NEON) += arm/highbd_hadamard_neon.c +DSP_SRCS-$(HAVE_NEON) += arm/highbd_avg_neon.c +endif DSP_SRCS-$(HAVE_MSA) += mips/avg_msa.c DSP_SRCS-$(HAVE_LSX) += loongarch/avg_lsx.c -ifeq ($(VPX_ARCH_X86_64),yes) +ifeq ($(VPX_ARCH_X86_64)$(HAVE_X86_ASM),yesyes) DSP_SRCS-$(HAVE_SSSE3) += x86/avg_ssse3_x86_64.asm endif DSP_SRCS-$(HAVE_VSX) += ppc/hadamard_vsx.c @@ -353,32 +382,32 @@ DSP_SRCS-yes += skin_detection.h DSP_SRCS-yes += skin_detection.c ifeq ($(CONFIG_ENCODERS),yes) -DSP_SRCS-yes += sad.c DSP_SRCS-yes += subtract.c DSP_SRCS-yes += sum_squares.c DSP_SRCS-$(HAVE_NEON) += arm/sum_squares_neon.c +DSP_SRCS-$(HAVE_SVE) += arm/sum_squares_sve.c DSP_SRCS-$(HAVE_SSE2) += x86/sum_squares_sse2.c DSP_SRCS-$(HAVE_MSA) += mips/sum_squares_msa.c DSP_SRCS-$(HAVE_NEON) += arm/sad4d_neon.c -DSP_SRCS-$(HAVE_NEON) += arm/sad_neon.c +DSP_SRCS-$(HAVE_NEON_DOTPROD) += arm/sad4d_neon_dotprod.c DSP_SRCS-$(HAVE_NEON) += arm/subtract_neon.c -DSP_SRCS-$(HAVE_MSA) += mips/sad_msa.c DSP_SRCS-$(HAVE_MSA) += mips/subtract_msa.c DSP_SRCS-$(HAVE_LSX) += loongarch/sad_lsx.c -DSP_SRCS-$(HAVE_MMI) += mips/sad_mmi.c DSP_SRCS-$(HAVE_MMI) += mips/subtract_mmi.c DSP_SRCS-$(HAVE_AVX2) += x86/sad4d_avx2.c -DSP_SRCS-$(HAVE_AVX2) += x86/sad_avx2.c +DSP_SRCS-$(HAVE_AVX2) += x86/subtract_avx2.c DSP_SRCS-$(HAVE_AVX512) += x86/sad4d_avx512.c +ifeq ($(HAVE_X86_ASM),yes) DSP_SRCS-$(HAVE_SSE2) += x86/sad4d_sse2.asm DSP_SRCS-$(HAVE_SSE2) += x86/sad_sse2.asm DSP_SRCS-$(HAVE_SSE2) += x86/subtract_sse2.asm +endif DSP_SRCS-$(HAVE_VSX) += ppc/sad_vsx.c DSP_SRCS-$(HAVE_VSX) += ppc/subtract_vsx.c @@ -386,20 +415,32 @@ DSP_SRCS-$(HAVE_VSX) += ppc/subtract_vsx.c DSP_SRCS-$(HAVE_LSX) += loongarch/subtract_lsx.c ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes) +ifeq ($(HAVE_X86_ASM),yes) DSP_SRCS-$(HAVE_SSE2) += x86/highbd_sad4d_sse2.asm DSP_SRCS-$(HAVE_SSE2) += x86/highbd_sad_sse2.asm +endif +DSP_SRCS-$(HAVE_NEON) += arm/highbd_sad4d_neon.c +DSP_SRCS-$(HAVE_NEON) += arm/highbd_sad_neon.c +DSP_SRCS-$(HAVE_AVX2) += x86/highbd_sad4d_avx2.c +DSP_SRCS-$(HAVE_AVX2) += x86/highbd_sad_avx2.c endif # CONFIG_VP9_HIGHBITDEPTH endif # CONFIG_ENCODERS ifneq ($(filter yes,$(CONFIG_ENCODERS) $(CONFIG_POSTPROC) $(CONFIG_VP9_POSTPROC)),) +DSP_SRCS-yes += sad.c DSP_SRCS-yes += variance.c DSP_SRCS-yes += variance.h DSP_SRCS-$(HAVE_NEON) += arm/avg_pred_neon.c +DSP_SRCS-$(HAVE_NEON) += arm/sad_neon.c +DSP_SRCS-$(HAVE_NEON_DOTPROD) += arm/sad_neon_dotprod.c DSP_SRCS-$(HAVE_NEON) += arm/subpel_variance_neon.c +DSP_SRCS-$(HAVE_NEON_DOTPROD) += arm/subpel_variance_neon_dotprod.c DSP_SRCS-$(HAVE_NEON) += arm/variance_neon.c +DSP_SRCS-$(HAVE_NEON_DOTPROD) += arm/variance_neon_dotprod.c +DSP_SRCS-$(HAVE_MSA) += mips/sad_msa.c DSP_SRCS-$(HAVE_MSA) += mips/variance_msa.c DSP_SRCS-$(HAVE_MSA) += mips/sub_pixel_variance_msa.c @@ -408,23 +449,40 @@ DSP_SRCS-$(HAVE_LSX) += loongarch/variance_lsx.c DSP_SRCS-$(HAVE_LSX) += loongarch/sub_pixel_variance_lsx.c DSP_SRCS-$(HAVE_LSX) += loongarch/avg_pred_lsx.c +DSP_SRCS-$(HAVE_MMI) += mips/sad_mmi.c DSP_SRCS-$(HAVE_MMI) += mips/variance_mmi.c DSP_SRCS-$(HAVE_SSE2) += x86/avg_pred_sse2.c +DSP_SRCS-$(HAVE_AVX2) += x86/avg_pred_avx2.c +DSP_SRCS-$(HAVE_AVX2) += x86/sad_avx2.c +DSP_SRCS-$(HAVE_AVX512) += x86/sad_avx512.c DSP_SRCS-$(HAVE_SSE2) += x86/variance_sse2.c # Contains SSE2 and SSSE3 DSP_SRCS-$(HAVE_AVX2) += x86/variance_avx2.c DSP_SRCS-$(HAVE_VSX) += ppc/variance_vsx.c -ifeq ($(VPX_ARCH_X86_64),yes) +ifeq ($(VPX_ARCH_X86_64)$(HAVE_X86_ASM),yesyes) DSP_SRCS-$(HAVE_SSE2) += x86/ssim_opt_x86_64.asm endif # VPX_ARCH_X86_64 +ifeq ($(HAVE_X86_ASM),yes) +DSP_SRCS-$(HAVE_SSE2) += x86/sad_sse2.asm DSP_SRCS-$(HAVE_SSE2) += x86/subpel_variance_sse2.asm # Contains SSE2 and SSSE3 +endif ifeq ($(CONFIG_VP9_HIGHBITDEPTH),yes) DSP_SRCS-$(HAVE_SSE2) += x86/highbd_variance_sse2.c +ifeq ($(HAVE_X86_ASM),yes) DSP_SRCS-$(HAVE_SSE2) += x86/highbd_variance_impl_sse2.asm DSP_SRCS-$(HAVE_SSE2) += x86/highbd_subpel_variance_impl_sse2.asm +endif +DSP_SRCS-$(HAVE_NEON) += arm/highbd_avg_pred_neon.c +ifeq ($(CONFIG_ENCODERS),yes) +DSP_SRCS-$(HAVE_NEON) += arm/highbd_sse_neon.c +endif +DSP_SRCS-$(HAVE_NEON) += arm/highbd_variance_neon.c +DSP_SRCS-$(HAVE_NEON_DOTPROD) += arm/highbd_variance_neon_dotprod.c +DSP_SRCS-$(HAVE_SVE) += arm/highbd_variance_sve.c +DSP_SRCS-$(HAVE_NEON) += arm/highbd_subpel_variance_neon.c endif # CONFIG_VP9_HIGHBITDEPTH endif # CONFIG_ENCODERS || CONFIG_POSTPROC || CONFIG_VP9_POSTPROC diff --git a/libs/libvpx/vpx_dsp/vpx_dsp_common.h b/libs/libvpx/vpx_dsp/vpx_dsp_common.h index 2de4495465..9d2668277a 100644 --- a/libs/libvpx/vpx_dsp/vpx_dsp_common.h +++ b/libs/libvpx/vpx_dsp/vpx_dsp_common.h @@ -11,6 +11,8 @@ #ifndef VPX_VPX_DSP_VPX_DSP_COMMON_H_ #define VPX_VPX_DSP_VPX_DSP_COMMON_H_ +#include + #include "./vpx_config.h" #include "vpx/vpx_integer.h" #include "vpx_ports/mem.h" @@ -45,9 +47,20 @@ typedef int16_t tran_low_t; typedef int16_t tran_coef_t; +// Visual Studio 2022 (cl.exe) < 17.7 targeting AArch64 with optimizations +// enabled produces invalid code for clip_pixel() when the return type is +// uint8_t. See: +// https://developercommunity.visualstudio.com/t/Misoptimization-for-ARM64-in-VS-2022-17/10363361 +#if defined(_MSC_VER) && _MSC_VER < 1937 && defined(_M_ARM64) && \ + !defined(__clang__) +static INLINE int clip_pixel(int val) { + return (val > 255) ? 255 : (val < 0) ? 0 : val; +} +#else static INLINE uint8_t clip_pixel(int val) { return (val > 255) ? 255 : (val < 0) ? 0 : val; } +#endif static INLINE int clamp(int value, int low, int high) { return value < low ? low : (value > high ? high : value); @@ -70,6 +83,12 @@ static INLINE uint16_t clip_pixel_highbd(int val, int bd) { } } +// Returns the saturating cast of a double value to int. +static INLINE int saturate_cast_double_to_int(double d) { + if (d > INT_MAX) return INT_MAX; + return (int)d; +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/libs/libvpx/vpx_dsp/vpx_dsp_rtcd.c b/libs/libvpx/vpx_dsp/vpx_dsp_rtcd.c index 030c456d39..2b8c656afb 100644 --- a/libs/libvpx/vpx_dsp/vpx_dsp_rtcd.c +++ b/libs/libvpx/vpx_dsp/vpx_dsp_rtcd.c @@ -12,4 +12,4 @@ #include "./vpx_dsp_rtcd.h" #include "vpx_ports/vpx_once.h" -void vpx_dsp_rtcd() { once(setup_rtcd_internal); } +void vpx_dsp_rtcd(void) { once(setup_rtcd_internal); } diff --git a/libs/libvpx/vpx_dsp/vpx_dsp_rtcd_defs.pl b/libs/libvpx/vpx_dsp/vpx_dsp_rtcd_defs.pl index d3c668f9ae..dc771ec4f1 100644 --- a/libs/libvpx/vpx_dsp/vpx_dsp_rtcd_defs.pl +++ b/libs/libvpx/vpx_dsp/vpx_dsp_rtcd_defs.pl @@ -17,6 +17,10 @@ print <> 6; } @@ -275,8 +283,7 @@ static INLINE void hadamard_8x8_sse2(const int16_t *src_diff, src[4] = _mm_load_si128((const __m128i *)(src_diff += src_stride)); src[5] = _mm_load_si128((const __m128i *)(src_diff += src_stride)); src[6] = _mm_load_si128((const __m128i *)(src_diff += src_stride)); - src[7] = _mm_load_si128((const __m128i *)(src_diff += src_stride)); - (void)src_diff; + src[7] = _mm_load_si128((const __m128i *)(src_diff + src_stride)); hadamard_col8_sse2(src, 0); hadamard_col8_sse2(src, 1); @@ -401,6 +408,12 @@ void vpx_hadamard_32x32_sse2(const int16_t *src_diff, ptrdiff_t src_stride, int16_t *t_coeff = coeff; #endif int idx; + __m128i coeff0_lo, coeff1_lo, coeff2_lo, coeff3_lo, b0_lo, b1_lo, b2_lo, + b3_lo; + __m128i coeff0_hi, coeff1_hi, coeff2_hi, coeff3_hi, b0_hi, b1_hi, b2_hi, + b3_hi; + __m128i b0, b1, b2, b3; + const __m128i zero = _mm_setzero_si128(); for (idx = 0; idx < 4; ++idx) { const int16_t *src_ptr = src_diff + (idx >> 1) * 16 * src_stride + (idx & 0x01) * 16; @@ -414,15 +427,38 @@ void vpx_hadamard_32x32_sse2(const int16_t *src_diff, ptrdiff_t src_stride, __m128i coeff2 = _mm_load_si128((const __m128i *)(t_coeff + 512)); __m128i coeff3 = _mm_load_si128((const __m128i *)(t_coeff + 768)); - __m128i b0 = _mm_add_epi16(coeff0, coeff1); - __m128i b1 = _mm_sub_epi16(coeff0, coeff1); - __m128i b2 = _mm_add_epi16(coeff2, coeff3); - __m128i b3 = _mm_sub_epi16(coeff2, coeff3); + // Sign extend 16 bit to 32 bit. + sign_extend_16bit_to_32bit_sse2(coeff0, zero, &coeff0_lo, &coeff0_hi); + sign_extend_16bit_to_32bit_sse2(coeff1, zero, &coeff1_lo, &coeff1_hi); + sign_extend_16bit_to_32bit_sse2(coeff2, zero, &coeff2_lo, &coeff2_hi); + sign_extend_16bit_to_32bit_sse2(coeff3, zero, &coeff3_lo, &coeff3_hi); - b0 = _mm_srai_epi16(b0, 2); - b1 = _mm_srai_epi16(b1, 2); - b2 = _mm_srai_epi16(b2, 2); - b3 = _mm_srai_epi16(b3, 2); + b0_lo = _mm_add_epi32(coeff0_lo, coeff1_lo); + b0_hi = _mm_add_epi32(coeff0_hi, coeff1_hi); + + b1_lo = _mm_sub_epi32(coeff0_lo, coeff1_lo); + b1_hi = _mm_sub_epi32(coeff0_hi, coeff1_hi); + + b2_lo = _mm_add_epi32(coeff2_lo, coeff3_lo); + b2_hi = _mm_add_epi32(coeff2_hi, coeff3_hi); + + b3_lo = _mm_sub_epi32(coeff2_lo, coeff3_lo); + b3_hi = _mm_sub_epi32(coeff2_hi, coeff3_hi); + + b0_lo = _mm_srai_epi32(b0_lo, 2); + b1_lo = _mm_srai_epi32(b1_lo, 2); + b2_lo = _mm_srai_epi32(b2_lo, 2); + b3_lo = _mm_srai_epi32(b3_lo, 2); + + b0_hi = _mm_srai_epi32(b0_hi, 2); + b1_hi = _mm_srai_epi32(b1_hi, 2); + b2_hi = _mm_srai_epi32(b2_hi, 2); + b3_hi = _mm_srai_epi32(b3_hi, 2); + + b0 = _mm_packs_epi32(b0_lo, b0_hi); + b1 = _mm_packs_epi32(b1_lo, b1_hi); + b2 = _mm_packs_epi32(b2_lo, b2_hi); + b3 = _mm_packs_epi32(b3_lo, b3_hi); coeff0 = _mm_add_epi16(b0, b2); coeff1 = _mm_add_epi16(b1, b3); diff --git a/libs/libvpx/vpx_dsp/x86/avg_pred_avx2.c b/libs/libvpx/vpx_dsp/x86/avg_pred_avx2.c new file mode 100644 index 0000000000..f4357998c9 --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/avg_pred_avx2.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_dsp_rtcd.h" + +void vpx_comp_avg_pred_avx2(uint8_t *comp_pred, const uint8_t *pred, int width, + int height, const uint8_t *ref, int ref_stride) { + int row = 0; + // comp_pred and pred must be 32 byte aligned. + assert(((intptr_t)comp_pred % 32) == 0); + assert(((intptr_t)pred % 32) == 0); + + if (width == 8) { + assert(height % 4 == 0); + do { + const __m256i p = _mm256_load_si256((const __m256i *)pred); + const __m128i r_0 = _mm_loadl_epi64((const __m128i *)ref); + const __m128i r_1 = + _mm_loadl_epi64((const __m128i *)(ref + 2 * ref_stride)); + + const __m128i r1 = _mm_castps_si128(_mm_loadh_pi( + _mm_castsi128_ps(r_0), (const __m64 *)(ref + ref_stride))); + const __m128i r2 = _mm_castps_si128(_mm_loadh_pi( + _mm_castsi128_ps(r_1), (const __m64 *)(ref + 3 * ref_stride))); + + const __m256i ref_0123 = + _mm256_inserti128_si256(_mm256_castsi128_si256(r1), r2, 1); + const __m256i avg = _mm256_avg_epu8(p, ref_0123); + + _mm256_store_si256((__m256i *)comp_pred, avg); + + row += 4; + pred += 32; + comp_pred += 32; + ref += 4 * ref_stride; + } while (row < height); + } else if (width == 16) { + assert(height % 4 == 0); + do { + const __m256i pred_0 = _mm256_load_si256((const __m256i *)pred); + const __m256i pred_1 = _mm256_load_si256((const __m256i *)(pred + 32)); + const __m256i tmp0 = + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i *)ref)); + const __m256i ref_0 = _mm256_inserti128_si256( + tmp0, _mm_loadu_si128((const __m128i *)(ref + ref_stride)), 1); + const __m256i tmp1 = _mm256_castsi128_si256( + _mm_loadu_si128((const __m128i *)(ref + 2 * ref_stride))); + const __m256i ref_1 = _mm256_inserti128_si256( + tmp1, _mm_loadu_si128((const __m128i *)(ref + 3 * ref_stride)), 1); + const __m256i average_0 = _mm256_avg_epu8(pred_0, ref_0); + const __m256i average_1 = _mm256_avg_epu8(pred_1, ref_1); + _mm256_store_si256((__m256i *)comp_pred, average_0); + _mm256_store_si256((__m256i *)(comp_pred + 32), average_1); + + row += 4; + pred += 64; + comp_pred += 64; + ref += 4 * ref_stride; + } while (row < height); + } else if (width == 32) { + assert(height % 2 == 0); + do { + const __m256i pred_0 = _mm256_load_si256((const __m256i *)pred); + const __m256i pred_1 = _mm256_load_si256((const __m256i *)(pred + 32)); + const __m256i ref_0 = _mm256_loadu_si256((const __m256i *)ref); + const __m256i ref_1 = + _mm256_loadu_si256((const __m256i *)(ref + ref_stride)); + const __m256i average_0 = _mm256_avg_epu8(pred_0, ref_0); + const __m256i average_1 = _mm256_avg_epu8(pred_1, ref_1); + _mm256_store_si256((__m256i *)comp_pred, average_0); + _mm256_store_si256((__m256i *)(comp_pred + 32), average_1); + + row += 2; + pred += 64; + comp_pred += 64; + ref += 2 * ref_stride; + } while (row < height); + } else if (width % 64 == 0) { + do { + int x; + for (x = 0; x < width; x += 64) { + const __m256i pred_0 = _mm256_load_si256((const __m256i *)(pred + x)); + const __m256i pred_1 = + _mm256_load_si256((const __m256i *)(pred + x + 32)); + const __m256i ref_0 = _mm256_loadu_si256((const __m256i *)(ref + x)); + const __m256i ref_1 = + _mm256_loadu_si256((const __m256i *)(ref + x + 32)); + const __m256i average_0 = _mm256_avg_epu8(pred_0, ref_0); + const __m256i average_1 = _mm256_avg_epu8(pred_1, ref_1); + _mm256_store_si256((__m256i *)(comp_pred + x), average_0); + _mm256_store_si256((__m256i *)(comp_pred + x + 32), average_1); + } + row++; + pred += width; + comp_pred += width; + ref += ref_stride; + } while (row < height); + } else { + vpx_comp_avg_pred_sse2(comp_pred, pred, width, height, ref, ref_stride); + } +} diff --git a/libs/libvpx/vpx_dsp/x86/convolve_avx2.h b/libs/libvpx/vpx_dsp/x86/convolve_avx2.h index 99bc9637fc..ebee964b18 100644 --- a/libs/libvpx/vpx_dsp/x86/convolve_avx2.h +++ b/libs/libvpx/vpx_dsp/x86/convolve_avx2.h @@ -129,9 +129,8 @@ static INLINE void mm256_storeu2_epi64(__m128i *const dst_ptr_1, static INLINE void mm256_storeu2_epi32(__m128i *const dst_ptr_1, __m128i *const dst_ptr_2, const __m256i *const src) { - *((uint32_t *)(dst_ptr_1)) = _mm_cvtsi128_si32(_mm256_castsi256_si128(*src)); - *((uint32_t *)(dst_ptr_2)) = - _mm_cvtsi128_si32(_mm256_extractf128_si256(*src, 1)); + *((int *)(dst_ptr_1)) = _mm_cvtsi128_si32(_mm256_castsi256_si128(*src)); + *((int *)(dst_ptr_2)) = _mm_cvtsi128_si32(_mm256_extractf128_si256(*src, 1)); } static INLINE __m256i mm256_round_epi32(const __m256i *const src, diff --git a/libs/libvpx/vpx_dsp/x86/deblock_sse2.asm b/libs/libvpx/vpx_dsp/x86/deblock_sse2.asm deleted file mode 100644 index b3af677d2e..0000000000 --- a/libs/libvpx/vpx_dsp/x86/deblock_sse2.asm +++ /dev/null @@ -1,432 +0,0 @@ -; -; Copyright (c) 2010 The WebM project authors. All Rights Reserved. -; -; Use of this source code is governed by a BSD-style license -; that can be found in the LICENSE file in the root of the source -; tree. An additional intellectual property rights grant can be found -; in the file PATENTS. All contributing project authors may -; be found in the AUTHORS file in the root of the source tree. -; - - -%include "vpx_ports/x86_abi_support.asm" - -;macro in deblock functions -%macro FIRST_2_ROWS 0 - movdqa xmm4, xmm0 - movdqa xmm6, xmm0 - movdqa xmm5, xmm1 - pavgb xmm5, xmm3 - - ;calculate absolute value - psubusb xmm4, xmm1 - psubusb xmm1, xmm0 - psubusb xmm6, xmm3 - psubusb xmm3, xmm0 - paddusb xmm4, xmm1 - paddusb xmm6, xmm3 - - ;get threshold - movdqa xmm2, flimit - pxor xmm1, xmm1 - movdqa xmm7, xmm2 - - ;get mask - psubusb xmm2, xmm4 - psubusb xmm7, xmm6 - pcmpeqb xmm2, xmm1 - pcmpeqb xmm7, xmm1 - por xmm7, xmm2 -%endmacro - -%macro SECOND_2_ROWS 0 - movdqa xmm6, xmm0 - movdqa xmm4, xmm0 - movdqa xmm2, xmm1 - pavgb xmm1, xmm3 - - ;calculate absolute value - psubusb xmm6, xmm2 - psubusb xmm2, xmm0 - psubusb xmm4, xmm3 - psubusb xmm3, xmm0 - paddusb xmm6, xmm2 - paddusb xmm4, xmm3 - - pavgb xmm5, xmm1 - - ;get threshold - movdqa xmm2, flimit - pxor xmm1, xmm1 - movdqa xmm3, xmm2 - - ;get mask - psubusb xmm2, xmm6 - psubusb xmm3, xmm4 - pcmpeqb xmm2, xmm1 - pcmpeqb xmm3, xmm1 - - por xmm7, xmm2 - por xmm7, xmm3 - - pavgb xmm5, xmm0 - - ;decide if or not to use filtered value - pand xmm0, xmm7 - pandn xmm7, xmm5 - paddusb xmm0, xmm7 -%endmacro - -%macro UPDATE_FLIMIT 0 - movdqu xmm2, XMMWORD PTR [rbx] - movdqu [rsp], xmm2 - add rbx, 16 -%endmacro - -SECTION .text - -;void vpx_post_proc_down_and_across_mb_row_sse2 -;( -; unsigned char *src_ptr, -; unsigned char *dst_ptr, -; int src_pixels_per_line, -; int dst_pixels_per_line, -; int cols, -; int *flimits, -; int size -;) -globalsym(vpx_post_proc_down_and_across_mb_row_sse2) -sym(vpx_post_proc_down_and_across_mb_row_sse2): - push rbp - mov rbp, rsp - SHADOW_ARGS_TO_STACK 7 - SAVE_XMM 7 - push rbx - push rsi - push rdi - ; end prolog - ALIGN_STACK 16, rax - sub rsp, 16 - - ; put flimit on stack - mov rbx, arg(5) ;flimits ptr - UPDATE_FLIMIT - -%define flimit [rsp] - - mov rsi, arg(0) ;src_ptr - mov rdi, arg(1) ;dst_ptr - - movsxd rax, DWORD PTR arg(2) ;src_pixels_per_line - movsxd rcx, DWORD PTR arg(6) ;rows in a macroblock -.nextrow: - xor rdx, rdx ;col -.nextcol: - ;load current and next 2 rows - movdqu xmm0, XMMWORD PTR [rsi] - movdqu xmm1, XMMWORD PTR [rsi + rax] - movdqu xmm3, XMMWORD PTR [rsi + 2*rax] - - FIRST_2_ROWS - - ;load above 2 rows - neg rax - movdqu xmm1, XMMWORD PTR [rsi + 2*rax] - movdqu xmm3, XMMWORD PTR [rsi + rax] - - SECOND_2_ROWS - - movdqu XMMWORD PTR [rdi], xmm0 - - neg rax ; positive stride - add rsi, 16 - add rdi, 16 - - add rdx, 16 - cmp edx, dword arg(4) ;cols - jge .downdone - UPDATE_FLIMIT - jmp .nextcol - -.downdone: - ; done with the all cols, start the across filtering in place - sub rsi, rdx - sub rdi, rdx - - mov rbx, arg(5) ; flimits - UPDATE_FLIMIT - - ; dup the first byte into the left border 8 times - movq mm1, [rdi] - punpcklbw mm1, mm1 - punpcklwd mm1, mm1 - punpckldq mm1, mm1 - mov rdx, -8 - movq [rdi+rdx], mm1 - - ; dup the last byte into the right border - movsxd rdx, dword arg(4) - movq mm1, [rdi + rdx + -1] - punpcklbw mm1, mm1 - punpcklwd mm1, mm1 - punpckldq mm1, mm1 - movq [rdi+rdx], mm1 - - xor rdx, rdx - movq mm0, QWORD PTR [rdi-16]; - movq mm1, QWORD PTR [rdi-8]; - -.acrossnextcol: - movdqu xmm0, XMMWORD PTR [rdi + rdx] - movdqu xmm1, XMMWORD PTR [rdi + rdx -2] - movdqu xmm3, XMMWORD PTR [rdi + rdx -1] - - FIRST_2_ROWS - - movdqu xmm1, XMMWORD PTR [rdi + rdx +1] - movdqu xmm3, XMMWORD PTR [rdi + rdx +2] - - SECOND_2_ROWS - - movq QWORD PTR [rdi+rdx-16], mm0 ; store previous 8 bytes - movq QWORD PTR [rdi+rdx-8], mm1 ; store previous 8 bytes - movdq2q mm0, xmm0 - psrldq xmm0, 8 - movdq2q mm1, xmm0 - - add rdx, 16 - cmp edx, dword arg(4) ;cols - jge .acrossdone - UPDATE_FLIMIT - jmp .acrossnextcol - -.acrossdone: - ; last 16 pixels - movq QWORD PTR [rdi+rdx-16], mm0 - - cmp edx, dword arg(4) - jne .throw_last_8 - movq QWORD PTR [rdi+rdx-8], mm1 -.throw_last_8: - ; done with this rwo - add rsi,rax ;next src line - mov eax, dword arg(3) ;dst_pixels_per_line - add rdi,rax ;next destination - mov eax, dword arg(2) ;src_pixels_per_line - - mov rbx, arg(5) ;flimits - UPDATE_FLIMIT - - dec rcx ;decrement count - jnz .nextrow ;next row - - add rsp, 16 - pop rsp - ; begin epilog - pop rdi - pop rsi - pop rbx - RESTORE_XMM - UNSHADOW_ARGS - pop rbp - ret -%undef flimit - - -;void vpx_mbpost_proc_across_ip_sse2(unsigned char *src, -; int pitch, int rows, int cols,int flimit) -globalsym(vpx_mbpost_proc_across_ip_sse2) -sym(vpx_mbpost_proc_across_ip_sse2): - push rbp - mov rbp, rsp - SHADOW_ARGS_TO_STACK 5 - SAVE_XMM 7 - GET_GOT rbx - push rsi - push rdi - ; end prolog - - ALIGN_STACK 16, rax - sub rsp, 16 - - ; create flimit4 at [rsp] - mov eax, dword ptr arg(4) ;flimit - mov [rsp], eax - mov [rsp+4], eax - mov [rsp+8], eax - mov [rsp+12], eax -%define flimit4 [rsp] - - - ;for(r=0;r +#include +#include + +#include "./vpx_dsp_rtcd.h" +#include "vpx/vpx_integer.h" +#include "vpx_dsp/x86/mem_sse2.h" + +extern const int16_t vpx_rv[]; + +static INLINE __m128i filter_16_sse2(__m128i v, __m128i p_above2, + __m128i p_above1, __m128i p_below1, + __m128i p_below2, __m128i flimit, + __m128i zero) { + const __m128i k1 = _mm_avg_epu8(p_above2, p_above1); + const __m128i k2 = _mm_avg_epu8(p_below2, p_below1); + const __m128i k3 = _mm_avg_epu8(k1, k2); + const __m128i filtered = _mm_avg_epu8(k3, v); + + const __m128i diff_b1 = + _mm_or_si128(_mm_subs_epu8(v, p_below1), _mm_subs_epu8(p_below1, v)); + const __m128i diff_b2 = + _mm_or_si128(_mm_subs_epu8(v, p_below2), _mm_subs_epu8(p_below2, v)); + const __m128i diff_a1 = + _mm_or_si128(_mm_subs_epu8(v, p_above1), _mm_subs_epu8(p_above1, v)); + const __m128i diff_a2 = + _mm_or_si128(_mm_subs_epu8(v, p_above2), _mm_subs_epu8(p_above2, v)); + + const __m128i mask_b1 = _mm_cmpeq_epi8(_mm_subs_epu8(flimit, diff_b1), zero); + const __m128i mask_b2 = _mm_cmpeq_epi8(_mm_subs_epu8(flimit, diff_b2), zero); + const __m128i mask_a1 = _mm_cmpeq_epi8(_mm_subs_epu8(flimit, diff_a1), zero); + const __m128i mask_a2 = _mm_cmpeq_epi8(_mm_subs_epu8(flimit, diff_a2), zero); + + const __m128i fail_mask = _mm_or_si128(_mm_or_si128(mask_b1, mask_b2), + _mm_or_si128(mask_a1, mask_a2)); + + return _mm_or_si128(_mm_and_si128(fail_mask, v), + _mm_andnot_si128(fail_mask, filtered)); +} + +static INLINE unsigned char filter_scalar( + unsigned char v, unsigned char p_above2, unsigned char p_above1, + unsigned char p_below1, unsigned char p_below2, unsigned char flimit) { + if ((abs(v - p_above2) < flimit) && (abs(v - p_above1) < flimit) && + (abs(v - p_below1) < flimit) && (abs(v - p_below2) < flimit)) { + const unsigned char k1 = (p_above2 + p_above1 + 1) >> 1; + const unsigned char k2 = (p_below2 + p_below1 + 1) >> 1; + const unsigned char k3 = (k1 + k2 + 1) >> 1; + return (k3 + v + 1) >> 1; + } + return v; +} + +void vpx_post_proc_down_and_across_mb_row_sse2(unsigned char *src, + unsigned char *dst, + int src_pitch, int dst_pitch, + int cols, unsigned char *flimits, + int size) { + int row, col; + const __m128i zero = _mm_setzero_si128(); + + for (row = 0; row < size; row++) { + const int aligned_cols = cols & ~15; + for (col = 0; col < aligned_cols; col += 16) { + const __m128i v = _mm_loadu_si128((const __m128i *)(src + col)); + const __m128i p_below1 = + _mm_loadu_si128((const __m128i *)(src + src_pitch + col)); + const __m128i p_below2 = + _mm_loadu_si128((const __m128i *)(src + 2 * src_pitch + col)); + const __m128i p_above1 = + _mm_loadu_si128((const __m128i *)(src - src_pitch + col)); + const __m128i p_above2 = + _mm_loadu_si128((const __m128i *)(src - 2 * src_pitch + col)); + const __m128i f = _mm_loadu_si128((const __m128i *)(flimits + col)); + + const __m128i out = + filter_16_sse2(v, p_above2, p_above1, p_below1, p_below2, f, zero); + _mm_storeu_si128((__m128i *)(dst + col), out); + } + + for (; col < cols; col++) { + const unsigned char p_above2 = src[col - 2 * src_pitch]; + const unsigned char p_above1 = src[col - src_pitch]; + const unsigned char p_below1 = src[col + src_pitch]; + const unsigned char p_below2 = src[col + 2 * src_pitch]; + const unsigned char v = src[col]; + + dst[col] = filter_scalar(v, p_above2, p_above1, p_below1, p_below2, + flimits[col]); + } + + dst[-2] = dst[-1] = dst[0]; + dst[cols] = dst[cols + 1] = dst[cols - 1]; + + __m128i prev_out = _mm_setzero_si128(); + for (col = 0; col < aligned_cols; col += 16) { + const __m128i v = _mm_loadu_si128((const __m128i *)(dst + col)); + const __m128i p_left2 = _mm_loadu_si128((const __m128i *)(dst + col - 2)); + const __m128i p_left1 = _mm_loadu_si128((const __m128i *)(dst + col - 1)); + const __m128i p_right1 = + _mm_loadu_si128((const __m128i *)(dst + col + 1)); + const __m128i p_right2 = + _mm_loadu_si128((const __m128i *)(dst + col + 2)); + const __m128i f = _mm_loadu_si128((const __m128i *)(flimits + col)); + + if (col > 0) { + _mm_storeu_si128((__m128i *)(dst + col - 16), prev_out); + } + prev_out = + filter_16_sse2(v, p_left2, p_left1, p_right1, p_right2, f, zero); + } + + const int last_sse_col = col; + const unsigned char prev_p2 = dst[col - 2]; + const unsigned char prev_p1 = dst[col - 1]; + unsigned char d[4] = { 0 }; + + if (col > 0) { + _mm_storeu_si128((__m128i *)(dst + col - 16), prev_out); + } + + for (; col < cols; col++) { + const unsigned char p_left2 = + (col == last_sse_col) + ? prev_p2 + : ((col == last_sse_col + 1) ? prev_p1 : dst[col - 2]); + const unsigned char p_left1 = + (col == last_sse_col) ? prev_p1 : dst[col - 1]; + const unsigned char p_right1 = dst[col + 1]; + const unsigned char p_right2 = dst[col + 2]; + const unsigned char v = dst[col]; + + d[col & 3] = + filter_scalar(v, p_left2, p_left1, p_right1, p_right2, flimits[col]); + + if (col >= last_sse_col + 2) dst[col - 2] = d[(col - 2) & 3]; + } + + if (cols - last_sse_col >= 2) { + dst[cols - 2] = d[(cols - 2) & 3]; + dst[cols - 1] = d[(cols - 1) & 3]; + } else if (cols - last_sse_col == 1) { + dst[cols - 1] = d[(cols - 1) & 3]; + } + + src += src_pitch; + dst += dst_pitch; + } +} + +static INLINE __m128i filter_4_across(const uint8_t *s_c, __m128i left4_u8, + __m128i right4_u8, int *sum, int *sumsq, + __m128i f_vec, __m128i eight, + __m128i zero) { + const __m128i left16 = _mm_unpacklo_epi8(left4_u8, zero); + const __m128i right16 = _mm_unpacklo_epi8(right4_u8, zero); + + const __m128i x16 = _mm_sub_epi16(right16, left16); + const __m128i y16 = _mm_add_epi16(right16, left16); + + const __m128i d_sum = _mm_srai_epi32(_mm_unpacklo_epi16(zero, x16), 16); + + const __m128i xy_lo = _mm_mullo_epi16(x16, y16); + const __m128i xy_hi = _mm_mulhi_epi16(x16, y16); + const __m128i d_sumsq = _mm_unpacklo_epi16(xy_lo, xy_hi); + + const __m128i t1 = _mm_slli_si128(d_sum, 4); + const __m128i s1 = _mm_add_epi32(d_sum, t1); + const __m128i t2 = _mm_slli_si128(s1, 8); + const __m128i pref_sum = _mm_add_epi32(s1, t2); + const __m128i sum_vec = _mm_add_epi32(pref_sum, _mm_set1_epi32(*sum)); + + const __m128i u1 = _mm_slli_si128(d_sumsq, 4); + const __m128i q1 = _mm_add_epi32(d_sumsq, u1); + const __m128i u2 = _mm_slli_si128(q1, 8); + const __m128i pref_sumsq = _mm_add_epi32(q1, u2); + const __m128i sumsq_vec = _mm_add_epi32(pref_sumsq, _mm_set1_epi32(*sumsq)); + + *sum = _mm_cvtsi128_si32(_mm_shuffle_epi32(sum_vec, 3)); + *sumsq = _mm_cvtsi128_si32(_mm_shuffle_epi32(sumsq_vec, 3)); + + const __m128i sumsq15 = + _mm_sub_epi32(_mm_slli_epi32(sumsq_vec, 4), sumsq_vec); + const __m128i sum_sq = _mm_madd_epi16(sum_vec, sum_vec); + const __m128i diff = _mm_sub_epi32(_mm_sub_epi32(sumsq15, sum_sq), f_vec); + const __m128i mask32 = _mm_srai_epi32(diff, 31); + + const __m128i sc4 = load_unaligned_u32(s_c); + const __m128i sc16 = _mm_unpacklo_epi8(sc4, zero); + const __m128i sc32 = _mm_unpacklo_epi16(sc16, zero); + + const __m128i filt32 = + _mm_srai_epi32(_mm_add_epi32(_mm_add_epi32(sum_vec, sc32), eight), 4); + return _mm_or_si128(_mm_and_si128(mask32, filt32), + _mm_andnot_si128(mask32, sc32)); +} + +void vpx_mbpost_proc_across_ip_sse2(unsigned char *src, int pitch, int rows, + int cols, int flimit) { + int r, c, i; + const __m128i zero = _mm_setzero_si128(); + const __m128i f_vec = _mm_set1_epi32(flimit); + const __m128i eight = _mm_set1_epi32(8); + + if (cols < 8 || (cols & 7)) { + vpx_mbpost_proc_across_ip_c(src, pitch, rows, cols, flimit); + return; + } + + for (r = 0; r < rows; r++) { + unsigned char *s = src + r * pitch; + int sumsq = 16; + int sum = 0; + + for (i = -8; i < 0; i++) s[i] = s[0]; + for (i = 0; i < 17; i++) s[i + cols] = s[cols - 1]; + + for (i = -8; i <= 6; i++) { + sumsq += s[i] * s[i]; + sum += s[i]; + } + + __m128i prev_out = _mm_setzero_si128(); + for (c = 0; c < cols + 8; c += 8) { + __m128i res8 = _mm_setzero_si128(); + if (c < cols) { + const __m128i left_lo = load_unaligned_u32(s + c - 8); + const __m128i right_lo = load_unaligned_u32(s + c + 7); + const __m128i res32_lo = filter_4_across(s + c, left_lo, right_lo, &sum, + &sumsq, f_vec, eight, zero); + + const __m128i left_hi = load_unaligned_u32(s + c - 4); + const __m128i right_hi = load_unaligned_u32(s + c + 11); + const __m128i res32_hi = filter_4_across( + s + c + 4, left_hi, right_hi, &sum, &sumsq, f_vec, eight, zero); + + const __m128i res16 = _mm_packs_epi32(res32_lo, res32_hi); + res8 = _mm_packus_epi16(res16, zero); + } + + if (c >= 8) { + _mm_storel_epi64((__m128i *)(s + c - 8), prev_out); + } + prev_out = res8; + } + } +} + +void vpx_mbpost_proc_down_sse2(unsigned char *dst, int pitch, int rows, + int cols, int flimit) { + int col; + const __m128i zero = _mm_setzero_si128(); + const __m128i f = _mm_set1_epi32(flimit); + DECLARE_ALIGNED(16, int16_t, above_context[8 * 8]); + + // 8 columns are processed at a time. + // If rows is less than 8 the bottom border extension fails. + assert(cols % 8 == 0); + assert(rows >= 8); + + for (col = 0; col < cols; col += 8) { + int row, i; + __m128i s = _mm_loadl_epi64((__m128i *)dst); + __m128i sum, sumsq_0, sumsq_1; + __m128i tmp_0, tmp_1; + __m128i below_context = _mm_setzero_si128(); + + s = _mm_unpacklo_epi8(s, zero); + + for (i = 0; i < 8; ++i) { + _mm_store_si128((__m128i *)above_context + i, s); + } + + // sum *= 9 + sum = _mm_slli_epi16(s, 3); + sum = _mm_add_epi16(s, sum); + + // sum^2 * 9 == (sum * 9) * sum + tmp_0 = _mm_mullo_epi16(sum, s); + tmp_1 = _mm_mulhi_epi16(sum, s); + + sumsq_0 = _mm_unpacklo_epi16(tmp_0, tmp_1); + sumsq_1 = _mm_unpackhi_epi16(tmp_0, tmp_1); + + // Prime sum/sumsq + for (i = 1; i <= 6; ++i) { + __m128i a = _mm_loadl_epi64((__m128i *)(dst + i * pitch)); + a = _mm_unpacklo_epi8(a, zero); + sum = _mm_add_epi16(sum, a); + a = _mm_mullo_epi16(a, a); + sumsq_0 = _mm_add_epi32(sumsq_0, _mm_unpacklo_epi16(a, zero)); + sumsq_1 = _mm_add_epi32(sumsq_1, _mm_unpackhi_epi16(a, zero)); + } + + for (row = 0; row < rows + 8; row++) { + const __m128i above = + _mm_load_si128((__m128i *)above_context + (row & 7)); + __m128i this_row = _mm_loadl_epi64((__m128i *)(dst + row * pitch)); + __m128i above_sq, below_sq; + __m128i mask_0, mask_1; + __m128i multmp_0, multmp_1; + __m128i rv; + __m128i out; + + this_row = _mm_unpacklo_epi8(this_row, zero); + + if (row + 7 < rows) { + // Instead of copying the end context we just stop loading when we get + // to the last one. + below_context = _mm_loadl_epi64((__m128i *)(dst + (row + 7) * pitch)); + below_context = _mm_unpacklo_epi8(below_context, zero); + } + + sum = _mm_sub_epi16(sum, above); + sum = _mm_add_epi16(sum, below_context); + + // context^2 fits in 16 bits. Don't need to mulhi and combine. Just zero + // extend. Unfortunately we can't do below_sq - above_sq in 16 bits + // because x86 does not have unpack with sign extension. + above_sq = _mm_mullo_epi16(above, above); + sumsq_0 = _mm_sub_epi32(sumsq_0, _mm_unpacklo_epi16(above_sq, zero)); + sumsq_1 = _mm_sub_epi32(sumsq_1, _mm_unpackhi_epi16(above_sq, zero)); + + below_sq = _mm_mullo_epi16(below_context, below_context); + sumsq_0 = _mm_add_epi32(sumsq_0, _mm_unpacklo_epi16(below_sq, zero)); + sumsq_1 = _mm_add_epi32(sumsq_1, _mm_unpackhi_epi16(below_sq, zero)); + + // sumsq * 16 - sumsq == sumsq * 15 + mask_0 = _mm_slli_epi32(sumsq_0, 4); + mask_0 = _mm_sub_epi32(mask_0, sumsq_0); + mask_1 = _mm_slli_epi32(sumsq_1, 4); + mask_1 = _mm_sub_epi32(mask_1, sumsq_1); + + multmp_0 = _mm_mullo_epi16(sum, sum); + multmp_1 = _mm_mulhi_epi16(sum, sum); + + mask_0 = _mm_sub_epi32(mask_0, _mm_unpacklo_epi16(multmp_0, multmp_1)); + mask_1 = _mm_sub_epi32(mask_1, _mm_unpackhi_epi16(multmp_0, multmp_1)); + + // mask - f gives a negative value when mask < f + mask_0 = _mm_sub_epi32(mask_0, f); + mask_1 = _mm_sub_epi32(mask_1, f); + + // Shift the sign bit down to create a mask + mask_0 = _mm_srai_epi32(mask_0, 31); + mask_1 = _mm_srai_epi32(mask_1, 31); + + mask_0 = _mm_packs_epi32(mask_0, mask_1); + + rv = _mm_loadu_si128((__m128i const *)(vpx_rv + (row & 127))); + + mask_1 = _mm_add_epi16(rv, sum); + mask_1 = _mm_add_epi16(mask_1, this_row); + mask_1 = _mm_srai_epi16(mask_1, 4); + + mask_1 = _mm_and_si128(mask_0, mask_1); + mask_0 = _mm_andnot_si128(mask_0, this_row); + out = _mm_or_si128(mask_1, mask_0); + + _mm_storel_epi64((__m128i *)(dst + row * pitch), + _mm_packus_epi16(out, zero)); + + _mm_store_si128((__m128i *)above_context + ((row + 8) & 7), this_row); + } + + dst += 8; + } +} diff --git a/libs/libvpx/vpx_dsp/x86/fwd_dct32x32_impl_avx2.h b/libs/libvpx/vpx_dsp/x86/fwd_dct32x32_impl_avx2.h index 3f158b5e4e..f3a8020292 100644 --- a/libs/libvpx/vpx_dsp/x86/fwd_dct32x32_impl_avx2.h +++ b/libs/libvpx/vpx_dsp/x86/fwd_dct32x32_impl_avx2.h @@ -89,7 +89,7 @@ void FDCT32x32_2D_AVX2(const int16_t *input, int16_t *output_org, int stride) { const __m256i k__cospi_m21_p11 = pair256_set_epi16(-cospi_21_64, cospi_11_64); const __m256i k__cospi_m05_p27 = pair256_set_epi16(-cospi_5_64, cospi_27_64); const __m256i k__DCT_CONST_ROUNDING = _mm256_set1_epi32(DCT_CONST_ROUNDING); - const __m256i kZero = _mm256_set1_epi16(0); + const __m256i kZero = _mm256_setzero_si256(); const __m256i kOne = _mm256_set1_epi16(1); // Do the two transform/transpose passes int pass; diff --git a/libs/libvpx/vpx_dsp/x86/fwd_dct32x32_impl_sse2.h b/libs/libvpx/vpx_dsp/x86/fwd_dct32x32_impl_sse2.h index ac1246faa5..bf350b6da0 100644 --- a/libs/libvpx/vpx_dsp/x86/fwd_dct32x32_impl_sse2.h +++ b/libs/libvpx/vpx_dsp/x86/fwd_dct32x32_impl_sse2.h @@ -100,7 +100,7 @@ void FDCT32x32_2D(const int16_t *input, tran_low_t *output_org, int stride) { const __m128i k__cospi_m21_p11 = pair_set_epi16(-cospi_21_64, cospi_11_64); const __m128i k__cospi_m05_p27 = pair_set_epi16(-cospi_5_64, cospi_27_64); const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING); - const __m128i kZero = _mm_set1_epi16(0); + const __m128i kZero = _mm_setzero_si128(); const __m128i kOne = _mm_set1_epi16(1); // Do the two transform/transpose passes diff --git a/libs/libvpx/vpx_dsp/x86/fwd_txfm_avx2.c b/libs/libvpx/vpx_dsp/x86/fwd_txfm_avx2.c index a2ed420e37..1eb6f41166 100644 --- a/libs/libvpx/vpx_dsp/x86/fwd_txfm_avx2.c +++ b/libs/libvpx/vpx_dsp/x86/fwd_txfm_avx2.c @@ -8,9 +8,383 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include // AVX2 #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" +#include "vpx_dsp/txfm_common.h" +#define ADD256_EPI16 _mm256_add_epi16 +#define SUB256_EPI16 _mm256_sub_epi16 + +static INLINE void load_buffer_16bit_to_16bit_avx2(const int16_t *in, + int stride, __m256i *out, + int out_size, int pass) { + int i; + const __m256i kOne = _mm256_set1_epi16(1); + if (pass == 0) { + for (i = 0; i < out_size; i++) { + out[i] = _mm256_loadu_si256((const __m256i *)(in + i * stride)); + // x = x << 2 + out[i] = _mm256_slli_epi16(out[i], 2); + } + } else { + for (i = 0; i < out_size; i++) { + out[i] = _mm256_loadu_si256((const __m256i *)(in + i * 16)); + // x = (x + 1) >> 2 + out[i] = _mm256_add_epi16(out[i], kOne); + out[i] = _mm256_srai_epi16(out[i], 2); + } + } +} + +static INLINE void transpose2_8x8_avx2(const __m256i *const in, + __m256i *const out) { + int i; + __m256i t[16], u[16]; + // (1st, 2nd) ==> (lo, hi) + // (0, 1) ==> (0, 1) + // (2, 3) ==> (2, 3) + // (4, 5) ==> (4, 5) + // (6, 7) ==> (6, 7) + for (i = 0; i < 4; i++) { + t[2 * i] = _mm256_unpacklo_epi16(in[2 * i], in[2 * i + 1]); + t[2 * i + 1] = _mm256_unpackhi_epi16(in[2 * i], in[2 * i + 1]); + } + + // (1st, 2nd) ==> (lo, hi) + // (0, 2) ==> (0, 2) + // (1, 3) ==> (1, 3) + // (4, 6) ==> (4, 6) + // (5, 7) ==> (5, 7) + for (i = 0; i < 2; i++) { + u[i] = _mm256_unpacklo_epi32(t[i], t[i + 2]); + u[i + 2] = _mm256_unpackhi_epi32(t[i], t[i + 2]); + + u[i + 4] = _mm256_unpacklo_epi32(t[i + 4], t[i + 6]); + u[i + 6] = _mm256_unpackhi_epi32(t[i + 4], t[i + 6]); + } + + // (1st, 2nd) ==> (lo, hi) + // (0, 4) ==> (0, 1) + // (1, 5) ==> (4, 5) + // (2, 6) ==> (2, 3) + // (3, 7) ==> (6, 7) + for (i = 0; i < 2; i++) { + out[2 * i] = _mm256_unpacklo_epi64(u[2 * i], u[2 * i + 4]); + out[2 * i + 1] = _mm256_unpackhi_epi64(u[2 * i], u[2 * i + 4]); + + out[2 * i + 4] = _mm256_unpacklo_epi64(u[2 * i + 1], u[2 * i + 5]); + out[2 * i + 5] = _mm256_unpackhi_epi64(u[2 * i + 1], u[2 * i + 5]); + } +} + +static INLINE void transpose_16bit_16x16_avx2(const __m256i *const in, + __m256i *const out) { + __m256i t[16]; + +#define LOADL(idx) \ + t[idx] = _mm256_castsi128_si256(_mm_load_si128((__m128i const *)&in[idx])); \ + t[idx] = _mm256_inserti128_si256( \ + t[idx], _mm_load_si128((__m128i const *)&in[idx + 8]), 1); + +#define LOADR(idx) \ + t[8 + idx] = \ + _mm256_castsi128_si256(_mm_load_si128((__m128i const *)&in[idx] + 1)); \ + t[8 + idx] = _mm256_inserti128_si256( \ + t[8 + idx], _mm_load_si128((__m128i const *)&in[idx + 8] + 1), 1); + + // load left 8x16 + LOADL(0) + LOADL(1) + LOADL(2) + LOADL(3) + LOADL(4) + LOADL(5) + LOADL(6) + LOADL(7) + + // load right 8x16 + LOADR(0) + LOADR(1) + LOADR(2) + LOADR(3) + LOADR(4) + LOADR(5) + LOADR(6) + LOADR(7) + + // get the top 16x8 result + transpose2_8x8_avx2(t, out); + // get the bottom 16x8 result + transpose2_8x8_avx2(&t[8], &out[8]); +} + +// Store 8 16-bit values. Sign extend the values. +static INLINE void store_buffer_16bit_to_32bit_w16_avx2(const __m256i *const in, + tran_low_t *out, + const int stride, + const int out_size) { + int i; + for (i = 0; i < out_size; ++i) { + _mm256_storeu_si256((__m256i *)(out), in[i]); + out += stride; + } +} + +#define PAIR256_SET_EPI16(a, b) \ + _mm256_set_epi16((int16_t)(b), (int16_t)(a), (int16_t)(b), (int16_t)(a), \ + (int16_t)(b), (int16_t)(a), (int16_t)(b), (int16_t)(a), \ + (int16_t)(b), (int16_t)(a), (int16_t)(b), (int16_t)(a), \ + (int16_t)(b), (int16_t)(a), (int16_t)(b), (int16_t)(a)) + +static INLINE __m256i mult256_round_shift(const __m256i *pin0, + const __m256i *pin1, + const __m256i *pmultiplier, + const __m256i *prounding, + const int shift) { + const __m256i u0 = _mm256_madd_epi16(*pin0, *pmultiplier); + const __m256i u1 = _mm256_madd_epi16(*pin1, *pmultiplier); + const __m256i v0 = _mm256_add_epi32(u0, *prounding); + const __m256i v1 = _mm256_add_epi32(u1, *prounding); + const __m256i w0 = _mm256_srai_epi32(v0, shift); + const __m256i w1 = _mm256_srai_epi32(v1, shift); + return _mm256_packs_epi32(w0, w1); +} + +static INLINE void fdct16x16_1D_avx2(__m256i *input, __m256i *output) { + int i; + __m256i step2[4]; + __m256i in[8]; + __m256i step1[8]; + __m256i step3[8]; + + const __m256i k__cospi_p16_p16 = _mm256_set1_epi16(cospi_16_64); + const __m256i k__cospi_p16_m16 = PAIR256_SET_EPI16(cospi_16_64, -cospi_16_64); + const __m256i k__cospi_p24_p08 = PAIR256_SET_EPI16(cospi_24_64, cospi_8_64); + const __m256i k__cospi_p08_m24 = PAIR256_SET_EPI16(cospi_8_64, -cospi_24_64); + const __m256i k__cospi_m08_p24 = PAIR256_SET_EPI16(-cospi_8_64, cospi_24_64); + const __m256i k__cospi_p28_p04 = PAIR256_SET_EPI16(cospi_28_64, cospi_4_64); + const __m256i k__cospi_m04_p28 = PAIR256_SET_EPI16(-cospi_4_64, cospi_28_64); + const __m256i k__cospi_p12_p20 = PAIR256_SET_EPI16(cospi_12_64, cospi_20_64); + const __m256i k__cospi_m20_p12 = PAIR256_SET_EPI16(-cospi_20_64, cospi_12_64); + const __m256i k__cospi_p30_p02 = PAIR256_SET_EPI16(cospi_30_64, cospi_2_64); + const __m256i k__cospi_p14_p18 = PAIR256_SET_EPI16(cospi_14_64, cospi_18_64); + const __m256i k__cospi_m02_p30 = PAIR256_SET_EPI16(-cospi_2_64, cospi_30_64); + const __m256i k__cospi_m18_p14 = PAIR256_SET_EPI16(-cospi_18_64, cospi_14_64); + const __m256i k__cospi_p22_p10 = PAIR256_SET_EPI16(cospi_22_64, cospi_10_64); + const __m256i k__cospi_p06_p26 = PAIR256_SET_EPI16(cospi_6_64, cospi_26_64); + const __m256i k__cospi_m10_p22 = PAIR256_SET_EPI16(-cospi_10_64, cospi_22_64); + const __m256i k__cospi_m26_p06 = PAIR256_SET_EPI16(-cospi_26_64, cospi_6_64); + const __m256i k__DCT_CONST_ROUNDING = _mm256_set1_epi32(DCT_CONST_ROUNDING); + + // Calculate input for the first 8 results. + for (i = 0; i < 8; i++) { + in[i] = ADD256_EPI16(input[i], input[15 - i]); + } + + // Calculate input for the next 8 results. + for (i = 0; i < 8; i++) { + step1[i] = SUB256_EPI16(input[7 - i], input[8 + i]); + } + + // Work on the first eight values; fdct8(input, even_results); + { + // Add/subtract + const __m256i q0 = ADD256_EPI16(in[0], in[7]); + const __m256i q1 = ADD256_EPI16(in[1], in[6]); + const __m256i q2 = ADD256_EPI16(in[2], in[5]); + const __m256i q3 = ADD256_EPI16(in[3], in[4]); + const __m256i q4 = SUB256_EPI16(in[3], in[4]); + const __m256i q5 = SUB256_EPI16(in[2], in[5]); + const __m256i q6 = SUB256_EPI16(in[1], in[6]); + const __m256i q7 = SUB256_EPI16(in[0], in[7]); + + // Work on first four results + { + // Add/subtract + const __m256i r0 = ADD256_EPI16(q0, q3); + const __m256i r1 = ADD256_EPI16(q1, q2); + const __m256i r2 = SUB256_EPI16(q1, q2); + const __m256i r3 = SUB256_EPI16(q0, q3); + + // Interleave to do the multiply by constants which gets us + // into 32 bits. + { + const __m256i t0 = _mm256_unpacklo_epi16(r0, r1); + const __m256i t1 = _mm256_unpackhi_epi16(r0, r1); + const __m256i t2 = _mm256_unpacklo_epi16(r2, r3); + const __m256i t3 = _mm256_unpackhi_epi16(r2, r3); + + output[0] = mult256_round_shift(&t0, &t1, &k__cospi_p16_p16, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[8] = mult256_round_shift(&t0, &t1, &k__cospi_p16_m16, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[4] = mult256_round_shift(&t2, &t3, &k__cospi_p24_p08, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[12] = + mult256_round_shift(&t2, &t3, &k__cospi_m08_p24, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + } + } + + // Work on next four results + { + // Interleave to do the multiply by constants which gets us + // into 32 bits. + const __m256i d0 = _mm256_unpacklo_epi16(q6, q5); + const __m256i d1 = _mm256_unpackhi_epi16(q6, q5); + const __m256i r0 = mult256_round_shift( + &d0, &d1, &k__cospi_p16_m16, &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + const __m256i r1 = mult256_round_shift( + &d0, &d1, &k__cospi_p16_p16, &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + + { + // Add/subtract + const __m256i x0 = ADD256_EPI16(q4, r0); + const __m256i x1 = SUB256_EPI16(q4, r0); + const __m256i x2 = SUB256_EPI16(q7, r1); + const __m256i x3 = ADD256_EPI16(q7, r1); + + // Interleave to do the multiply by constants which gets us + // into 32 bits. + { + const __m256i t0 = _mm256_unpacklo_epi16(x0, x3); + const __m256i t1 = _mm256_unpackhi_epi16(x0, x3); + const __m256i t2 = _mm256_unpacklo_epi16(x1, x2); + const __m256i t3 = _mm256_unpackhi_epi16(x1, x2); + output[2] = + mult256_round_shift(&t0, &t1, &k__cospi_p28_p04, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[14] = + mult256_round_shift(&t0, &t1, &k__cospi_m04_p28, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[10] = + mult256_round_shift(&t2, &t3, &k__cospi_p12_p20, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[6] = + mult256_round_shift(&t2, &t3, &k__cospi_m20_p12, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + } + } + } + } + // Work on the next eight values; step1 -> odd_results + { // step 2 + { + const __m256i t0 = _mm256_unpacklo_epi16(step1[5], step1[2]); + const __m256i t1 = _mm256_unpackhi_epi16(step1[5], step1[2]); + const __m256i t2 = _mm256_unpacklo_epi16(step1[4], step1[3]); + const __m256i t3 = _mm256_unpackhi_epi16(step1[4], step1[3]); + step2[0] = mult256_round_shift(&t0, &t1, &k__cospi_p16_m16, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + step2[1] = mult256_round_shift(&t2, &t3, &k__cospi_p16_m16, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + step2[2] = mult256_round_shift(&t0, &t1, &k__cospi_p16_p16, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + step2[3] = mult256_round_shift(&t2, &t3, &k__cospi_p16_p16, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + } + // step 3 + { + step3[0] = ADD256_EPI16(step1[0], step2[1]); + step3[1] = ADD256_EPI16(step1[1], step2[0]); + step3[2] = SUB256_EPI16(step1[1], step2[0]); + step3[3] = SUB256_EPI16(step1[0], step2[1]); + step3[4] = SUB256_EPI16(step1[7], step2[3]); + step3[5] = SUB256_EPI16(step1[6], step2[2]); + step3[6] = ADD256_EPI16(step1[6], step2[2]); + step3[7] = ADD256_EPI16(step1[7], step2[3]); + } + // step 4 + { + const __m256i t0 = _mm256_unpacklo_epi16(step3[1], step3[6]); + const __m256i t1 = _mm256_unpackhi_epi16(step3[1], step3[6]); + const __m256i t2 = _mm256_unpacklo_epi16(step3[2], step3[5]); + const __m256i t3 = _mm256_unpackhi_epi16(step3[2], step3[5]); + step2[0] = mult256_round_shift(&t0, &t1, &k__cospi_m08_p24, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + step2[1] = mult256_round_shift(&t2, &t3, &k__cospi_p24_p08, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + step2[2] = mult256_round_shift(&t0, &t1, &k__cospi_p24_p08, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + step2[3] = mult256_round_shift(&t2, &t3, &k__cospi_p08_m24, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + } + // step 5 + { + step1[0] = ADD256_EPI16(step3[0], step2[0]); + step1[1] = SUB256_EPI16(step3[0], step2[0]); + step1[2] = ADD256_EPI16(step3[3], step2[1]); + step1[3] = SUB256_EPI16(step3[3], step2[1]); + step1[4] = SUB256_EPI16(step3[4], step2[3]); + step1[5] = ADD256_EPI16(step3[4], step2[3]); + step1[6] = SUB256_EPI16(step3[7], step2[2]); + step1[7] = ADD256_EPI16(step3[7], step2[2]); + } + // step 6 + { + const __m256i t0 = _mm256_unpacklo_epi16(step1[0], step1[7]); + const __m256i t1 = _mm256_unpackhi_epi16(step1[0], step1[7]); + const __m256i t2 = _mm256_unpacklo_epi16(step1[1], step1[6]); + const __m256i t3 = _mm256_unpackhi_epi16(step1[1], step1[6]); + output[1] = mult256_round_shift(&t0, &t1, &k__cospi_p30_p02, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[9] = mult256_round_shift(&t2, &t3, &k__cospi_p14_p18, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[15] = mult256_round_shift(&t0, &t1, &k__cospi_m02_p30, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[7] = mult256_round_shift(&t2, &t3, &k__cospi_m18_p14, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + } + { + const __m256i t0 = _mm256_unpacklo_epi16(step1[2], step1[5]); + const __m256i t1 = _mm256_unpackhi_epi16(step1[2], step1[5]); + const __m256i t2 = _mm256_unpacklo_epi16(step1[3], step1[4]); + const __m256i t3 = _mm256_unpackhi_epi16(step1[3], step1[4]); + output[5] = mult256_round_shift(&t0, &t1, &k__cospi_p22_p10, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[13] = mult256_round_shift(&t2, &t3, &k__cospi_p06_p26, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[11] = mult256_round_shift(&t0, &t1, &k__cospi_m10_p22, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + output[3] = mult256_round_shift(&t2, &t3, &k__cospi_m26_p06, + &k__DCT_CONST_ROUNDING, DCT_CONST_BITS); + } + } +} + +void vpx_fdct16x16_avx2(const int16_t *input, tran_low_t *output, int stride) { + int pass; + DECLARE_ALIGNED(32, int16_t, intermediate[256]); + int16_t *out0 = intermediate; + tran_low_t *out1 = output; + const int width = 16; + const int height = 16; + __m256i buf0[16], buf1[16]; + + // Two transform and transpose passes + // Process 16 columns (transposed rows in second pass) at a time. + for (pass = 0; pass < 2; ++pass) { + // Load and pre-condition input. + load_buffer_16bit_to_16bit_avx2(input, stride, buf1, height, pass); + + // Calculate dct for 16x16 values + fdct16x16_1D_avx2(buf1, buf0); + + // Transpose the results. + transpose_16bit_16x16_avx2(buf0, buf1); + + if (pass == 0) { + store_buffer_16bit_to_32bit_w16_avx2(buf1, (tran_low_t *)out0, width, + height); + } else { + store_buffer_16bit_to_32bit_w16_avx2(buf1, out1, width, height); + } + // Setup in/out for next pass. + input = intermediate; + } +} + #if !CONFIG_VP9_HIGHBITDEPTH #define FDCT32x32_2D_AVX2 vpx_fdct32x32_rd_avx2 #define FDCT32x32_HIGH_PRECISION 0 diff --git a/libs/libvpx/vpx_dsp/x86/highbd_convolve_avx2.c b/libs/libvpx/vpx_dsp/x86/highbd_convolve_avx2.c index 01a52ec8bf..80cb0a2070 100644 --- a/libs/libvpx/vpx_dsp/x86/highbd_convolve_avx2.c +++ b/libs/libvpx/vpx_dsp/x86/highbd_convolve_avx2.c @@ -189,6 +189,7 @@ void vpx_highbd_convolve_avg_avx2(const uint16_t *src, ptrdiff_t src_stride, } } +#if HAVE_X86_ASM // ----------------------------------------------------------------------------- // Horizontal and vertical filtering @@ -1493,3 +1494,4 @@ HIGH_FUN_CONV_1D(avg_vert, y0_q4, y_step_q4, v, HIGH_FUN_CONV_2D(avg_, avx2, 1) #undef HIGHBD_FUNC +#endif // HAVE_X86_ASM diff --git a/libs/libvpx/vpx_dsp/x86/highbd_intrapred_intrin_avx2.c b/libs/libvpx/vpx_dsp/x86/highbd_intrapred_intrin_avx2.c new file mode 100644 index 0000000000..dd63c6f544 --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/highbd_intrapred_intrin_avx2.c @@ -0,0 +1,288 @@ +/* + * Copyright (c) 2025 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" +#include "vpx/vpx_integer.h" + +static INLINE __m256i avg3_epu16_avx2(const __m256i *x, const __m256i *y, + const __m256i *z) { + const __m256i one = _mm256_set1_epi16(1); + const __m256i a = _mm256_avg_epu16(*x, *z); + const __m256i b = + _mm256_subs_epu16(a, _mm256_and_si256(_mm256_xor_si256(*x, *z), one)); + return _mm256_avg_epu16(b, *y); +} + +/* + palignr in AVX2 operates in-lane + hi: hi_hi | hi_lo + mid hi_lo | lo_hi + lo: lo_hi | lo_lo +*/ +#define ALIGNR_256(res, hi, lo, i) \ + do { \ + __m256i _mid = _mm256_permute2x128_si256(hi, lo, 3); \ + res = _mm256_alignr_epi8(_mid, lo, (i)); \ + } while (0) + +#define ALIGNR_256_HI(res, hi, lo, i) \ + do { \ + __m256i _mid = _mm256_permute2x128_si256(hi, lo, 3); \ + res = _mm256_alignr_epi8(hi, _mid, (i)); \ + } while (0) + +void vpx_highbd_d63_predictor_16x16_avx2(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + const __m256i A = _mm256_loadu_si256((const __m256i *)above); + // Replicate above[15] for right-edge extension + const __m256i AR = + _mm256_permute4x64_epi64(_mm256_shufflehi_epi16(A, 0xff), 0xff); + + __m256i B; + ALIGNR_256(B, AR, A, 2); + __m256i C; + ALIGNR_256(C, AR, A, 4); + + __m256i avg2 = _mm256_avg_epu16(A, B); + __m256i avg3 = avg3_epu16_avx2(&A, &B, &C); + + int i; + (void)left; + (void)bd; + for (i = 0; i < 14; i += 2) { + _mm256_storeu_si256((__m256i *)dst, avg2); + dst += stride; + + _mm256_storeu_si256((__m256i *)dst, avg3); + dst += stride; + + ALIGNR_256(avg2, AR, avg2, 2); + ALIGNR_256(avg3, AR, avg3, 2); + } + _mm256_storeu_si256((__m256i *)dst, avg2); + dst += stride; + + _mm256_storeu_si256((__m256i *)dst, avg3); +} + +void vpx_highbd_d63_predictor_32x32_avx2(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + (void)left; + (void)bd; + + const __m256i A0 = _mm256_loadu_si256((const __m256i *)(above)); // 0..15 + const __m256i A1 = + _mm256_loadu_si256((const __m256i *)(above + 16)); // 16..31 + + // Replicate above[31] for right-edge extension + const __m256i AR = + _mm256_permute4x64_epi64(_mm256_shufflehi_epi16(A1, 0xff), 0xff); + + __m256i B0; + ALIGNR_256(B0, A1, A0, 2); + __m256i B1; + ALIGNR_256(B1, AR, A1, 2); + + __m256i C0; + ALIGNR_256(C0, A1, A0, 4); + __m256i C1; + ALIGNR_256(C1, AR, A1, 4); + + __m256i avg2_0 = _mm256_avg_epu16(A0, B0); + __m256i avg2_1 = _mm256_avg_epu16(A1, B1); + __m256i avg3_0 = avg3_epu16_avx2(&A0, &B0, &C0); + __m256i avg3_1 = avg3_epu16_avx2(&A1, &B1, &C1); + + for (int i = 0; i < 30; i += 2) { + _mm256_storeu_si256((__m256i *)dst, avg2_0); + _mm256_storeu_si256((__m256i *)(dst + 16), avg2_1); + dst += stride; + + _mm256_storeu_si256((__m256i *)dst, avg3_0); + _mm256_storeu_si256((__m256i *)(dst + 16), avg3_1); + dst += stride; + + ALIGNR_256(avg2_0, avg2_1, avg2_0, 2); + ALIGNR_256(avg2_1, AR, avg2_1, 2); + ALIGNR_256(avg3_0, avg3_1, avg3_0, 2); + ALIGNR_256(avg3_1, AR, avg3_1, 2); + } + + _mm256_storeu_si256((__m256i *)dst, avg2_0); + _mm256_storeu_si256((__m256i *)(dst + 16), avg2_1); + dst += stride; + + _mm256_storeu_si256((__m256i *)dst, avg3_0); + _mm256_storeu_si256((__m256i *)(dst + 16), avg3_1); +} + +static INLINE void d207_store_8x16_avx2(uint16_t **dst, const ptrdiff_t stride, + const __m256i *ab, const __m256i *cd) { + _mm256_storeu_si256((__m256i *)*dst, *ab); + *dst += stride; + + __m256i shift; + ALIGNR_256(shift, *cd, *ab, 4); + _mm256_storeu_si256((__m256i *)*dst, shift); + *dst += stride; + + ALIGNR_256(shift, *cd, *ab, 8); + _mm256_storeu_si256((__m256i *)*dst, shift); + *dst += stride; + + ALIGNR_256(shift, *cd, *ab, 12); + _mm256_storeu_si256((__m256i *)*dst, shift); + *dst += stride; + + shift = _mm256_permute2x128_si256(*cd, *ab, 3); + _mm256_storeu_si256((__m256i *)*dst, shift); + *dst += stride; + + ALIGNR_256_HI(shift, *cd, *ab, 4); + _mm256_storeu_si256((__m256i *)*dst, shift); + *dst += stride; + + ALIGNR_256_HI(shift, *cd, *ab, 8); + _mm256_storeu_si256((__m256i *)*dst, shift); + *dst += stride; + + ALIGNR_256_HI(shift, *cd, *ab, 12); + _mm256_storeu_si256((__m256i *)*dst, shift); + *dst += stride; +} + +void vpx_highbd_d207_predictor_16x16_avx2(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + const __m256i A = _mm256_loadu_si256((const __m256i *)left); + const __m256i LR = + _mm256_permute4x64_epi64(_mm256_shufflehi_epi16(A, 0xff), 0xff); + + __m256i B; + ALIGNR_256(B, LR, A, 2); + __m256i C; + ALIGNR_256(C, LR, A, 4); + + const __m256i avg2 = _mm256_avg_epu16(A, B); + const __m256i avg3 = avg3_epu16_avx2(&A, &B, &C); + + const __m256i out_ac = _mm256_unpacklo_epi16(avg2, avg3); + const __m256i out_bd = _mm256_unpackhi_epi16(avg2, avg3); + + __m256i out_ab = _mm256_permute2x128_si256(out_ac, out_bd, 0x20); + __m256i out_cd = _mm256_permute2x128_si256(out_ac, out_bd, 0x31); + + (void)above; + (void)bd; + + d207_store_8x16_avx2(&dst, stride, &out_ab, &out_cd); + d207_store_8x16_avx2(&dst, stride, &out_cd, &LR); +} + +static INLINE void d207_store_8x32_avx2(uint16_t **dst, const ptrdiff_t stride, + const __m256i *ab, const __m256i *cd, + const __m256i *ef) { + _mm256_storeu_si256((__m256i *)*dst, *ab); + _mm256_storeu_si256((__m256i *)(*dst + 16), *cd); + *dst += stride; + + __m256i ab_shift; + __m256i cd_shift; + + ALIGNR_256(ab_shift, *cd, *ab, 4); + ALIGNR_256(cd_shift, *ef, *cd, 4); + _mm256_storeu_si256((__m256i *)*dst, ab_shift); + _mm256_storeu_si256((__m256i *)(*dst + 16), cd_shift); + *dst += stride; + + ALIGNR_256(ab_shift, *cd, *ab, 8); + ALIGNR_256(cd_shift, *ef, *cd, 8); + _mm256_storeu_si256((__m256i *)*dst, ab_shift); + _mm256_storeu_si256((__m256i *)(*dst + 16), cd_shift); + *dst += stride; + + ALIGNR_256(ab_shift, *cd, *ab, 12); + ALIGNR_256(cd_shift, *ef, *cd, 12); + _mm256_storeu_si256((__m256i *)*dst, ab_shift); + _mm256_storeu_si256((__m256i *)(*dst + 16), cd_shift); + *dst += stride; + + ab_shift = _mm256_permute2x128_si256(*cd, *ab, 3); + cd_shift = _mm256_permute2x128_si256(*ef, *cd, 3); + _mm256_storeu_si256((__m256i *)*dst, ab_shift); + _mm256_storeu_si256((__m256i *)(*dst + 16), cd_shift); + *dst += stride; + + ALIGNR_256_HI(ab_shift, *cd, *ab, 4); + ALIGNR_256_HI(cd_shift, *ef, *cd, 4); + _mm256_storeu_si256((__m256i *)*dst, ab_shift); + _mm256_storeu_si256((__m256i *)(*dst + 16), cd_shift); + *dst += stride; + + ALIGNR_256_HI(ab_shift, *cd, *ab, 8); + ALIGNR_256_HI(cd_shift, *ef, *cd, 8); + _mm256_storeu_si256((__m256i *)*dst, ab_shift); + _mm256_storeu_si256((__m256i *)(*dst + 16), cd_shift); + *dst += stride; + + ALIGNR_256_HI(ab_shift, *cd, *ab, 12); + ALIGNR_256_HI(cd_shift, *ef, *cd, 12); + _mm256_storeu_si256((__m256i *)*dst, ab_shift); + _mm256_storeu_si256((__m256i *)(*dst + 16), cd_shift); + *dst += stride; +} + +void vpx_highbd_d207_predictor_32x32_avx2(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + (void)above; + (void)bd; + + const __m256i A0 = _mm256_loadu_si256((const __m256i *)left); // 0..15 + const __m256i A1 = + _mm256_loadu_si256((const __m256i *)(left + 16)); // 16..31 + + const __m256i AR = + _mm256_permute4x64_epi64(_mm256_shufflehi_epi16(A1, 0xff), 0xff); + + __m256i B0; + ALIGNR_256(B0, A1, A0, 2); + __m256i B1; + ALIGNR_256(B1, AR, A1, 2); + __m256i C0; + ALIGNR_256(C0, A1, A0, 4); + __m256i C1; + ALIGNR_256(C1, AR, A1, 4); + + __m256i avg2_0 = _mm256_avg_epu16(A0, B0); + __m256i avg2_1 = _mm256_avg_epu16(A1, B1); + __m256i avg3_0 = avg3_epu16_avx2(&A0, &B0, &C0); + __m256i avg3_1 = avg3_epu16_avx2(&A1, &B1, &C1); + + __m256i out_ac = _mm256_unpacklo_epi16(avg2_0, avg3_0); + __m256i out_bd = _mm256_unpackhi_epi16(avg2_0, avg3_0); + __m256i out_eg = _mm256_unpacklo_epi16(avg2_1, avg3_1); + __m256i out_fh = _mm256_unpackhi_epi16(avg2_1, avg3_1); + + __m256i out_ab = _mm256_permute2x128_si256(out_ac, out_bd, 0x20); + __m256i out_cd = _mm256_permute2x128_si256(out_ac, out_bd, 0x31); + __m256i out_ef = _mm256_permute2x128_si256(out_eg, out_fh, 0x20); + __m256i out_gh = _mm256_permute2x128_si256(out_eg, out_fh, 0x31); + + d207_store_8x32_avx2(&dst, stride, &out_ab, &out_cd, &out_ef); + d207_store_8x32_avx2(&dst, stride, &out_cd, &out_ef, &out_gh); + d207_store_8x32_avx2(&dst, stride, &out_ef, &out_gh, &AR); + d207_store_8x32_avx2(&dst, stride, &out_gh, &AR, &AR); +} diff --git a/libs/libvpx/vpx_dsp/x86/highbd_intrapred_intrin_avx512.c b/libs/libvpx/vpx_dsp/x86/highbd_intrapred_intrin_avx512.c new file mode 100644 index 0000000000..d2a4494ed1 --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/highbd_intrapred_intrin_avx512.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2025 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" +#include "vpx/vpx_integer.h" + +DECLARE_ALIGNED(64, static const uint16_t, + rshift_1w[32]) = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 31 }; +DECLARE_ALIGNED(64, static const uint16_t, + rshift_2w[32]) = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 31, 31 }; + +static INLINE __m512i avg3_epu16_avx512(const __m512i *x, const __m512i *y, + const __m512i *z) { + const __m512i one = _mm512_set1_epi16(1); + const __m512i a = _mm512_avg_epu16(*x, *z); + const __m512i b = + _mm512_subs_epu16(a, _mm512_and_si512(_mm512_xor_si512(*x, *z), one)); + return _mm512_avg_epu16(b, *y); +} + +void vpx_highbd_d63_predictor_32x32_avx512(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + (void)left; + (void)bd; + + const __m512i A = _mm512_loadu_si512((const __m512i *)above); + + // B = shift by 1 (2 bytes) + const __m512i B = _mm512_permutexvar_epi16(*(const __m512i *)rshift_1w, A); + + // C = shift by 2 (4 bytes) + const __m512i C = _mm512_permutexvar_epi16(*(const __m512i *)rshift_2w, A); + + __m512i avg2 = _mm512_avg_epu16(A, B); + __m512i avg3 = avg3_epu16_avx512(&A, &B, &C); + + for (int i = 0; i < 30; i += 2) { + _mm512_storeu_si512((__m512i *)dst, avg2); + dst += stride; + + _mm512_storeu_si512((__m512i *)dst, avg3); + dst += stride; + + avg2 = _mm512_permutexvar_epi16(*(const __m512i *)rshift_1w, avg2); + avg3 = _mm512_permutexvar_epi16(*(const __m512i *)rshift_1w, avg3); + } + + _mm512_storeu_si512((__m512i *)dst, avg2); + dst += stride; + + _mm512_storeu_si512((__m512i *)dst, avg3); +} + +static INLINE void d207_store_16x32_avx512(uint16_t **dst, + const ptrdiff_t stride, + const __m512i *abcd, + const __m512i *efgh) { + _mm512_storeu_si512((__m512i *)*dst, *abcd); + *dst += stride; + + __m512i shift = _mm512_alignr_epi32(*efgh, *abcd, 1); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 2); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 3); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 4); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 5); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 6); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 7); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 8); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 9); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 10); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 11); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 12); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 13); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 14); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; + + shift = _mm512_alignr_epi32(*efgh, *abcd, 15); + _mm512_storeu_si512((__m512i *)*dst, shift); + *dst += stride; +} + +void vpx_highbd_d207_predictor_32x32_avx512(uint16_t *dst, ptrdiff_t stride, + const uint16_t *above, + const uint16_t *left, int bd) { + (void)above; + (void)bd; + + const __m512i A = _mm512_loadu_si512((const __m512i *)left); + const __m512i AR = _mm512_set1_epi16(left[31]); + + // B = shift by 1 (2 bytes) + __m512i B = _mm512_permutexvar_epi16(*(const __m512i *)rshift_1w, A); + // C = shift by 2 (4 bytes) + __m512i C = _mm512_alignr_epi32(AR, A, 1); + + __m512i avg2 = _mm512_avg_epu16(A, B); + __m512i avg3 = avg3_epu16_avx512(&A, &B, &C); + + __m512i out_aceg = _mm512_unpacklo_epi16(avg2, avg3); + __m512i out_bdfh = _mm512_unpackhi_epi16(avg2, avg3); + + __m512i out_abcd = _mm512_permutex2var_epi64( + out_aceg, _mm512_set_epi64(11, 10, 3, 2, 9, 8, 1, 0), out_bdfh); + __m512i out_efgh = _mm512_permutex2var_epi64( + out_aceg, _mm512_set_epi64(15, 14, 7, 6, 13, 12, 5, 4), out_bdfh); + + d207_store_16x32_avx512(&dst, stride, &out_abcd, &out_efgh); + d207_store_16x32_avx512(&dst, stride, &out_efgh, &AR); +} diff --git a/libs/libvpx/vpx_dsp/x86/highbd_intrapred_sse2.asm b/libs/libvpx/vpx_dsp/x86/highbd_intrapred_sse2.asm index caf506ac07..8217ef4920 100644 --- a/libs/libvpx/vpx_dsp/x86/highbd_intrapred_sse2.asm +++ b/libs/libvpx/vpx_dsp/x86/highbd_intrapred_sse2.asm @@ -280,7 +280,7 @@ cglobal highbd_tm_predictor_4x4, 5, 5, 6, dst, stride, above, left, bd pmaxsw m2, m4 ;Store the values movq [dstq ], m2 - movhpd [dstq+strideq*2], m2 + movhps [dstq+strideq*2], m2 lea dstq, [dstq+strideq*4] pshuflw m2, m1, 0xaa pshuflw m5, m1, 0xff @@ -291,7 +291,7 @@ cglobal highbd_tm_predictor_4x4, 5, 5, 6, dst, stride, above, left, bd pmaxsw m2, m4 ;Store the values movq [dstq ], m2 - movhpd [dstq+strideq*2], m2 + movhps [dstq+strideq*2], m2 RET INIT_XMM sse2 diff --git a/libs/libvpx/vpx_dsp/x86/highbd_inv_txfm_sse2.h b/libs/libvpx/vpx_dsp/x86/highbd_inv_txfm_sse2.h index 78cf9111d9..1d07391b02 100644 --- a/libs/libvpx/vpx_dsp/x86/highbd_inv_txfm_sse2.h +++ b/libs/libvpx/vpx_dsp/x86/highbd_inv_txfm_sse2.h @@ -249,7 +249,7 @@ static INLINE void highbd_idct16_4col_stage7(const __m128i *const in, static INLINE __m128i add_clamp(const __m128i in0, const __m128i in1, const int bd) { - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); // Faster than _mm_set1_epi16((1 << bd) - 1). const __m128i one = _mm_set1_epi16(1); const __m128i max = _mm_sub_epi16(_mm_slli_epi16(one, bd), one); diff --git a/libs/libvpx/vpx_dsp/x86/highbd_loopfilter_sse2.c b/libs/libvpx/vpx_dsp/x86/highbd_loopfilter_sse2.c index d265fc1a92..9f45623dee 100644 --- a/libs/libvpx/vpx_dsp/x86/highbd_loopfilter_sse2.c +++ b/libs/libvpx/vpx_dsp/x86/highbd_loopfilter_sse2.c @@ -18,7 +18,7 @@ static INLINE __m128i signed_char_clamp_bd_sse2(__m128i value, int bd) { __m128i lbounded; __m128i retval; - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); const __m128i one = _mm_set1_epi16(1); __m128i t80, max, min; @@ -51,7 +51,7 @@ void vpx_highbd_lpf_horizontal_16_sse2(uint16_t *s, int pitch, const uint8_t *blimit, const uint8_t *limit, const uint8_t *thresh, int bd) { - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); const __m128i one = _mm_set1_epi16(1); __m128i blimit_v, limit_v, thresh_v; __m128i q7, p7, q6, p6, q5, p5, q4, p4, q3, p3, q2, p2, q1, p1, q0, p0; @@ -492,7 +492,7 @@ void vpx_highbd_lpf_horizontal_8_sse2(uint16_t *s, int pitch, DECLARE_ALIGNED(16, uint16_t, flat_oq2[16]); DECLARE_ALIGNED(16, uint16_t, flat_oq1[16]); DECLARE_ALIGNED(16, uint16_t, flat_oq0[16]); - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); __m128i blimit_v, limit_v, thresh_v; __m128i mask, hev, flat; __m128i p3 = _mm_load_si128((__m128i *)(s - 4 * pitch)); @@ -720,7 +720,7 @@ void vpx_highbd_lpf_horizontal_4_sse2(uint16_t *s, int pitch, const uint8_t *blimit, const uint8_t *limit, const uint8_t *thresh, int bd) { - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); __m128i blimit_v, limit_v, thresh_v; __m128i mask, hev, flat; __m128i p3 = _mm_loadu_si128((__m128i *)(s - 4 * pitch)); diff --git a/libs/libvpx/vpx_dsp/x86/highbd_quantize_intrin_avx2.c b/libs/libvpx/vpx_dsp/x86/highbd_quantize_intrin_avx2.c new file mode 100644 index 0000000000..35ca554049 --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/highbd_quantize_intrin_avx2.c @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "./vpx_dsp_rtcd.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" + +static VPX_FORCE_INLINE void init_one_qp(const __m128i *p, __m256i *qp) { + const __m128i sign = _mm_srai_epi16(*p, 15); + const __m128i dc = _mm_unpacklo_epi16(*p, sign); + const __m128i ac = _mm_unpackhi_epi16(*p, sign); + *qp = _mm256_insertf128_si256(_mm256_castsi128_si256(dc), ac, 1); +} + +static VPX_FORCE_INLINE void update_qp(__m256i *qp) { + int i; + for (i = 0; i < 5; ++i) { + qp[i] = _mm256_permute2x128_si256(qp[i], qp[i], 0x11); + } +} + +static VPX_FORCE_INLINE void init_qp( + const struct macroblock_plane *const mb_plane, const int16_t *dequant_ptr, + __m256i *qp, int log_scale) { + const __m128i zbin = _mm_loadu_si128((const __m128i *)mb_plane->zbin); + const __m128i round = _mm_loadu_si128((const __m128i *)mb_plane->round); + const __m128i quant = _mm_loadu_si128((const __m128i *)mb_plane->quant); + const __m128i dequant = _mm_loadu_si128((const __m128i *)dequant_ptr); + const __m128i quant_shift = + _mm_loadu_si128((const __m128i *)mb_plane->quant_shift); + init_one_qp(&zbin, &qp[0]); + init_one_qp(&round, &qp[1]); + init_one_qp(&quant, &qp[2]); + init_one_qp(&dequant, &qp[3]); + init_one_qp(&quant_shift, &qp[4]); + if (log_scale > 0) { + const __m256i rnd = _mm256_set1_epi32((int16_t)(1 << (log_scale - 1))); + qp[0] = _mm256_add_epi32(qp[0], rnd); + qp[0] = _mm256_srai_epi32(qp[0], log_scale); + + qp[1] = _mm256_add_epi32(qp[1], rnd); + qp[1] = _mm256_srai_epi32(qp[1], log_scale); + } + // Subtracting 1 here eliminates a _mm256_cmpeq_epi32() instruction when + // calculating the zbin mask. + qp[0] = _mm256_sub_epi32(qp[0], _mm256_set1_epi32(1)); +} + +// Note: +// *x is vector multiplied by *y which is 16 int32_t parallel multiplication +// and right shift 16. The output, 16 int32_t is save in *p. +static VPX_FORCE_INLINE __m256i mm256_mul_shift_epi32(const __m256i *x, + const __m256i *y) { + __m256i prod_lo = _mm256_mul_epi32(*x, *y); + __m256i prod_hi = _mm256_srli_epi64(*x, 32); + const __m256i mult_hi = _mm256_srli_epi64(*y, 32); + const __m256i mask = _mm256_set_epi32(0, -1, 0, -1, 0, -1, 0, -1); + prod_hi = _mm256_mul_epi32(prod_hi, mult_hi); + prod_lo = _mm256_srli_epi64(prod_lo, 16); + prod_lo = _mm256_and_si256(prod_lo, mask); + prod_hi = _mm256_srli_epi64(prod_hi, 16); + prod_hi = _mm256_slli_epi64(prod_hi, 32); + return _mm256_or_si256(prod_lo, prod_hi); +} + +static VPX_FORCE_INLINE __m256i get_max_lane_eob(const int16_t *iscan_ptr, + __m256i eobmax, + __m256i nz_mask) { + const __m256i packed_nz_mask = _mm256_packs_epi32(nz_mask, nz_mask); + const __m256i packed_nz_mask_perm = + _mm256_permute4x64_epi64(packed_nz_mask, 0xD8); + const __m256i iscan = + _mm256_castsi128_si256(_mm_loadu_si128((const __m128i *)iscan_ptr)); + const __m256i nz_iscan = _mm256_and_si256(iscan, packed_nz_mask_perm); + return _mm256_max_epi16(eobmax, nz_iscan); +} + +// Get the max eob from the lower 128 bits. +static VPX_FORCE_INLINE uint16_t get_max_eob(__m256i eob) { + __m256i eob_s; + eob_s = _mm256_shuffle_epi32(eob, 0xe); + eob = _mm256_max_epi16(eob, eob_s); + eob_s = _mm256_shufflelo_epi16(eob, 0xe); + eob = _mm256_max_epi16(eob, eob_s); + eob_s = _mm256_shufflelo_epi16(eob, 1); + eob = _mm256_max_epi16(eob, eob_s); +#if defined(_MSC_VER) && (_MSC_VER < 1910) + return _mm_cvtsi128_si32(_mm256_extracti128_si256(eob, 0)) & 0xffff; +#else + return (uint16_t)_mm256_extract_epi16(eob, 0); +#endif +} + +static VPX_FORCE_INLINE void quantize(const __m256i *qp, + const tran_low_t *coeff_ptr, + const int16_t *iscan_ptr, + tran_low_t *qcoeff, tran_low_t *dqcoeff, + __m256i *eob) { + const __m256i coeff = _mm256_loadu_si256((const __m256i *)coeff_ptr); + const __m256i abs_coeff = _mm256_abs_epi32(coeff); + const __m256i zbin_mask = _mm256_cmpgt_epi32(abs_coeff, qp[0]); + + if (_mm256_movemask_epi8(zbin_mask) == 0) { + const __m256i zero = _mm256_setzero_si256(); + _mm256_storeu_si256((__m256i *)qcoeff, zero); + _mm256_storeu_si256((__m256i *)dqcoeff, zero); + return; + } + { + const __m256i tmp_rnd = + _mm256_and_si256(_mm256_add_epi32(abs_coeff, qp[1]), zbin_mask); + const __m256i tmp = mm256_mul_shift_epi32(&tmp_rnd, &qp[2]); + const __m256i tmp2 = _mm256_add_epi32(tmp, tmp_rnd); + const __m256i abs_q = mm256_mul_shift_epi32(&tmp2, &qp[4]); + const __m256i abs_dq = _mm256_mullo_epi32(abs_q, qp[3]); + const __m256i nz_mask = _mm256_cmpgt_epi32(abs_q, _mm256_setzero_si256()); + const __m256i q = _mm256_sign_epi32(abs_q, coeff); + const __m256i dq = _mm256_sign_epi32(abs_dq, coeff); + + _mm256_storeu_si256((__m256i *)qcoeff, q); + _mm256_storeu_si256((__m256i *)dqcoeff, dq); + + *eob = get_max_lane_eob(iscan_ptr, *eob, nz_mask); + } +} + +void vpx_highbd_quantize_b_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + const int step = 8; + __m256i eob = _mm256_setzero_si256(); + __m256i qp[5]; + const int16_t *iscan = scan_order->iscan; + + init_qp(mb_plane, dequant_ptr, qp, 0); + + quantize(qp, coeff_ptr, iscan, qcoeff_ptr, dqcoeff_ptr, &eob); + + coeff_ptr += step; + qcoeff_ptr += step; + dqcoeff_ptr += step; + iscan += step; + n_coeffs -= step; + + update_qp(qp); + + while (n_coeffs > 0) { + quantize(qp, coeff_ptr, iscan, qcoeff_ptr, dqcoeff_ptr, &eob); + + coeff_ptr += step; + qcoeff_ptr += step; + dqcoeff_ptr += step; + iscan += step; + n_coeffs -= step; + } + + *eob_ptr = get_max_eob(eob); +} + +static VPX_FORCE_INLINE __m256i mm256_mul_shift_epi32_logscale(const __m256i *x, + const __m256i *y, + int log_scale) { + __m256i prod_lo = _mm256_mul_epi32(*x, *y); + __m256i prod_hi = _mm256_srli_epi64(*x, 32); + const __m256i mult_hi = _mm256_srli_epi64(*y, 32); + const __m256i mask = _mm256_set_epi32(0, -1, 0, -1, 0, -1, 0, -1); + prod_hi = _mm256_mul_epi32(prod_hi, mult_hi); + prod_lo = _mm256_srli_epi64(prod_lo, 16 - log_scale); + prod_lo = _mm256_and_si256(prod_lo, mask); + prod_hi = _mm256_srli_epi64(prod_hi, 16 - log_scale); + prod_hi = _mm256_slli_epi64(prod_hi, 32); + return _mm256_or_si256(prod_lo, prod_hi); +} + +static VPX_FORCE_INLINE void quantize_b_32x32( + const __m256i *qp, const tran_low_t *coeff_ptr, const int16_t *iscan_ptr, + tran_low_t *qcoeff, tran_low_t *dqcoeff, __m256i *eob) { + const __m256i coeff = _mm256_loadu_si256((const __m256i *)coeff_ptr); + const __m256i abs_coeff = _mm256_abs_epi32(coeff); + const __m256i zbin_mask = _mm256_cmpgt_epi32(abs_coeff, qp[0]); + + if (_mm256_movemask_epi8(zbin_mask) == 0) { + const __m256i zero = _mm256_setzero_si256(); + _mm256_storeu_si256((__m256i *)qcoeff, zero); + _mm256_storeu_si256((__m256i *)dqcoeff, zero); + return; + } + + { + const __m256i tmp_rnd = + _mm256_and_si256(_mm256_add_epi32(abs_coeff, qp[1]), zbin_mask); + // const int64_t tmp2 = ((tmpw * quant_ptr[rc != 0]) >> 16) + tmpw; + const __m256i tmp = mm256_mul_shift_epi32_logscale(&tmp_rnd, &qp[2], 0); + const __m256i tmp2 = _mm256_add_epi32(tmp, tmp_rnd); + // const int abs_qcoeff = (int)((tmp2 * quant_shift_ptr[rc != 0]) >> 15); + const __m256i abs_q = mm256_mul_shift_epi32_logscale(&tmp2, &qp[4], 1); + const __m256i abs_dq = + _mm256_srli_epi32(_mm256_mullo_epi32(abs_q, qp[3]), 1); + const __m256i nz_mask = _mm256_cmpgt_epi32(abs_q, _mm256_setzero_si256()); + const __m256i q = _mm256_sign_epi32(abs_q, coeff); + const __m256i dq = _mm256_sign_epi32(abs_dq, coeff); + + _mm256_storeu_si256((__m256i *)qcoeff, q); + _mm256_storeu_si256((__m256i *)dqcoeff, dq); + + *eob = get_max_lane_eob(iscan_ptr, *eob, nz_mask); + } +} + +void vpx_highbd_quantize_b_32x32_avx2( + const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, + uint16_t *eob_ptr, const struct ScanOrder *const scan_order) { + const unsigned int step = 8; + intptr_t n_coeffs = 32 * 32; + const int16_t *iscan = scan_order->iscan; + __m256i eob = _mm256_setzero_si256(); + __m256i qp[5]; + + init_qp(mb_plane, dequant_ptr, qp, 1); + + quantize_b_32x32(qp, coeff_ptr, iscan, qcoeff_ptr, dqcoeff_ptr, &eob); + + coeff_ptr += step; + qcoeff_ptr += step; + dqcoeff_ptr += step; + iscan += step; + n_coeffs -= step; + + update_qp(qp); + + while (n_coeffs > 0) { + quantize_b_32x32(qp, coeff_ptr, iscan, qcoeff_ptr, dqcoeff_ptr, &eob); + + coeff_ptr += step; + qcoeff_ptr += step; + dqcoeff_ptr += step; + iscan += step; + n_coeffs -= step; + } + + *eob_ptr = get_max_eob(eob); +} diff --git a/libs/libvpx/vpx_dsp/x86/highbd_quantize_intrin_sse2.c b/libs/libvpx/vpx_dsp/x86/highbd_quantize_intrin_sse2.c index 4535a0f7a2..5348676134 100644 --- a/libs/libvpx/vpx_dsp/x86/highbd_quantize_intrin_sse2.c +++ b/libs/libvpx/vpx_dsp/x86/highbd_quantize_intrin_sse2.c @@ -15,19 +15,22 @@ #include "vpx_dsp/vpx_dsp_common.h" #include "vpx_mem/vpx_mem.h" #include "vpx_ports/mem.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" -#if CONFIG_VP9_HIGHBITDEPTH void vpx_highbd_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t count, - const int16_t *zbin_ptr, - const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { - int i, j, non_zero_regs = (int)count / 4, eob_i = -1; + const struct ScanOrder *const scan_order) { + int i, j, non_zero_regs = (int)count / 4, eob_i = 0; __m128i zbins[2]; __m128i nzbins[2]; + const int16_t *iscan = scan_order->iscan; + const int16_t *zbin_ptr = mb_plane->zbin; + const int16_t *round_ptr = mb_plane->round; + const int16_t *quant_ptr = mb_plane->quant; + const int16_t *quant_shift_ptr = mb_plane->quant_shift; zbins[0] = _mm_set_epi32((int)zbin_ptr[1], (int)zbin_ptr[1], (int)zbin_ptr[1], (int)zbin_ptr[0]); @@ -38,8 +41,6 @@ void vpx_highbd_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t count, nzbins[0] = _mm_sub_epi32(nzbins[0], zbins[0]); nzbins[1] = _mm_sub_epi32(nzbins[1], zbins[1]); - (void)scan; - memset(qcoeff_ptr, 0, count * sizeof(*qcoeff_ptr)); memset(dqcoeff_ptr, 0, count * sizeof(*dqcoeff_ptr)); @@ -82,29 +83,29 @@ void vpx_highbd_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t count, const int64_t tmp4 = ((tmp3 * quant_ptr[k != 0]) >> 16) + tmp3; const uint32_t abs_qcoeff = (uint32_t)((tmp4 * quant_shift_ptr[k != 0]) >> 16); - qcoeff_ptr[k] = (int)(abs_qcoeff ^ coeff_sign[j]) - coeff_sign[j]; + qcoeff_ptr[k] = + (int)(abs_qcoeff ^ (uint32_t)coeff_sign[j]) - coeff_sign[j]; dqcoeff_ptr[k] = qcoeff_ptr[k] * dequant_ptr[k != 0]; if (abs_qcoeff) eob_i = iscan[k] > eob_i ? iscan[k] : eob_i; } } } - *eob_ptr = eob_i + 1; + *eob_ptr = eob_i; } void vpx_highbd_quantize_b_32x32_sse2( - const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, - const int16_t *round_ptr, const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, - tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { + const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, + uint16_t *eob_ptr, const struct ScanOrder *const scan_order) { __m128i zbins[2]; __m128i nzbins[2]; int idx = 0; int idx_arr[1024]; - int i, eob = -1; - const int zbin0_tmp = ROUND_POWER_OF_TWO(zbin_ptr[0], 1); - const int zbin1_tmp = ROUND_POWER_OF_TWO(zbin_ptr[1], 1); - (void)scan; + int i, eob = 0; + const intptr_t n_coeffs = 32 * 32; + const int16_t *iscan = scan_order->iscan; + const int zbin0_tmp = ROUND_POWER_OF_TWO(mb_plane->zbin[0], 1); + const int zbin1_tmp = ROUND_POWER_OF_TWO(mb_plane->zbin[1], 1); zbins[0] = _mm_set_epi32(zbin1_tmp, zbin1_tmp, zbin1_tmp, zbin0_tmp); zbins[1] = _mm_set1_epi32(zbin1_tmp); @@ -139,14 +140,14 @@ void vpx_highbd_quantize_b_32x32_sse2( const int coeff = coeff_ptr[rc]; const int coeff_sign = (coeff >> 31); const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; - const int64_t tmp1 = abs_coeff + ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1); - const int64_t tmp2 = ((tmp1 * quant_ptr[rc != 0]) >> 16) + tmp1; + const int64_t tmp1 = + abs_coeff + ROUND_POWER_OF_TWO(mb_plane->round[rc != 0], 1); + const int64_t tmp2 = ((tmp1 * mb_plane->quant[rc != 0]) >> 16) + tmp1; const uint32_t abs_qcoeff = - (uint32_t)((tmp2 * quant_shift_ptr[rc != 0]) >> 15); - qcoeff_ptr[rc] = (int)(abs_qcoeff ^ coeff_sign) - coeff_sign; + (uint32_t)((tmp2 * mb_plane->quant_shift[rc != 0]) >> 15); + qcoeff_ptr[rc] = (int)(abs_qcoeff ^ (uint32_t)coeff_sign) - coeff_sign; dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2; if (abs_qcoeff) eob = iscan[idx_arr[i]] > eob ? iscan[idx_arr[i]] : eob; } - *eob_ptr = eob + 1; + *eob_ptr = eob; } -#endif diff --git a/libs/libvpx/vpx_dsp/x86/highbd_sad4d_avx2.c b/libs/libvpx/vpx_dsp/x86/highbd_sad4d_avx2.c new file mode 100644 index 0000000000..e483fdce73 --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/highbd_sad4d_avx2.c @@ -0,0 +1,462 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#include // AVX2 +#include "./vpx_dsp_rtcd.h" +#include "vpx/vpx_integer.h" + +static VPX_FORCE_INLINE void calc_final_4(const __m256i *const sums /*[4]*/, + uint32_t sad_array[4]) { + const __m256i t0 = _mm256_hadd_epi32(sums[0], sums[1]); + const __m256i t1 = _mm256_hadd_epi32(sums[2], sums[3]); + const __m256i t2 = _mm256_hadd_epi32(t0, t1); + const __m128i sum = _mm_add_epi32(_mm256_castsi256_si128(t2), + _mm256_extractf128_si256(t2, 1)); + _mm_storeu_si128((__m128i *)sad_array, sum); +} + +static VPX_FORCE_INLINE void highbd_sad64xHx4d(__m256i *sums_16 /*[4]*/, + const uint16_t *src, + int src_stride, + uint16_t *refs[4], + int ref_stride, int height) { + int i; + for (i = 0; i < height; ++i) { + // load src and all ref[] + const __m256i s0 = _mm256_load_si256((const __m256i *)src); + const __m256i s1 = _mm256_load_si256((const __m256i *)(src + 16)); + const __m256i s2 = _mm256_load_si256((const __m256i *)(src + 32)); + const __m256i s3 = _mm256_load_si256((const __m256i *)(src + 48)); + int x; + + for (x = 0; x < 4; ++x) { + __m256i r[4]; + r[0] = _mm256_loadu_si256((const __m256i *)refs[x]); + r[1] = _mm256_loadu_si256((const __m256i *)(refs[x] + 16)); + r[2] = _mm256_loadu_si256((const __m256i *)(refs[x] + 32)); + r[3] = _mm256_loadu_si256((const __m256i *)(refs[x] + 48)); + + // absolute differences between every ref[] to src + r[0] = _mm256_abs_epi16(_mm256_sub_epi16(r[0], s0)); + r[1] = _mm256_abs_epi16(_mm256_sub_epi16(r[1], s1)); + r[2] = _mm256_abs_epi16(_mm256_sub_epi16(r[2], s2)); + r[3] = _mm256_abs_epi16(_mm256_sub_epi16(r[3], s3)); + + // sum every abs diff + sums_16[x] = _mm256_add_epi16(sums_16[x], _mm256_add_epi16(r[0], r[1])); + sums_16[x] = _mm256_add_epi16(sums_16[x], _mm256_add_epi16(r[2], r[3])); + } + + src += src_stride; + refs[0] += ref_stride; + refs[1] += ref_stride; + refs[2] += ref_stride; + refs[3] += ref_stride; + } +} + +static VPX_FORCE_INLINE void highbd_sad64xNx4d_avx2( + const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], + int ref_stride, uint32_t sad_array[4], int n) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *refs[4]; + __m256i sums_16[4]; + __m256i sums_32[4]; + int i; + + refs[0] = CONVERT_TO_SHORTPTR(ref_array[0]); + refs[1] = CONVERT_TO_SHORTPTR(ref_array[1]); + refs[2] = CONVERT_TO_SHORTPTR(ref_array[2]); + refs[3] = CONVERT_TO_SHORTPTR(ref_array[3]); + sums_32[0] = _mm256_setzero_si256(); + sums_32[1] = _mm256_setzero_si256(); + sums_32[2] = _mm256_setzero_si256(); + sums_32[3] = _mm256_setzero_si256(); + + for (i = 0; i < (n / 2); ++i) { + sums_16[0] = _mm256_setzero_si256(); + sums_16[1] = _mm256_setzero_si256(); + sums_16[2] = _mm256_setzero_si256(); + sums_16[3] = _mm256_setzero_si256(); + + highbd_sad64xHx4d(sums_16, src, src_stride, refs, ref_stride, 2); + + /* sums_16 will outrange after 2 rows, so add current sums_16 to + * sums_32*/ + sums_32[0] = _mm256_add_epi32( + sums_32[0], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[0])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[0], 1)))); + sums_32[1] = _mm256_add_epi32( + sums_32[1], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[1])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[1], 1)))); + sums_32[2] = _mm256_add_epi32( + sums_32[2], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[2])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[2], 1)))); + sums_32[3] = _mm256_add_epi32( + sums_32[3], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[3])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[3], 1)))); + + src += src_stride << 1; + } + calc_final_4(sums_32, sad_array); +} + +#define HIGHBD_SAD64XNX4D(n) \ + void vpx_highbd_sad64x##n##x4d_avx2(const uint8_t *src, int src_stride, \ + const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + highbd_sad64xNx4d_avx2(src, src_stride, ref_array, ref_stride, sad_array, \ + n); \ + } + +#define HIGHBD_SADSKIP64XNx4D(n) \ + void vpx_highbd_sad_skip_64x##n##x4d_avx2( \ + const uint8_t *src, int src_stride, const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + highbd_sad64xNx4d_avx2(src, 2 * src_stride, ref_array, 2 * ref_stride, \ + sad_array, n / 2); \ + sad_array[0] <<= 1; \ + sad_array[1] <<= 1; \ + sad_array[2] <<= 1; \ + sad_array[3] <<= 1; \ + } + +static VPX_FORCE_INLINE void highbd_sad32xHx4d(__m256i *sums_16 /*[4]*/, + const uint16_t *src, + int src_stride, + uint16_t *refs[4], + int ref_stride, int height) { + int i; + for (i = 0; i < height; i++) { + __m256i r[8]; + + // load src and all ref[] + const __m256i s = _mm256_load_si256((const __m256i *)src); + const __m256i s2 = _mm256_load_si256((const __m256i *)(src + 16)); + r[0] = _mm256_loadu_si256((const __m256i *)refs[0]); + r[1] = _mm256_loadu_si256((const __m256i *)(refs[0] + 16)); + r[2] = _mm256_loadu_si256((const __m256i *)refs[1]); + r[3] = _mm256_loadu_si256((const __m256i *)(refs[1] + 16)); + r[4] = _mm256_loadu_si256((const __m256i *)refs[2]); + r[5] = _mm256_loadu_si256((const __m256i *)(refs[2] + 16)); + r[6] = _mm256_loadu_si256((const __m256i *)refs[3]); + r[7] = _mm256_loadu_si256((const __m256i *)(refs[3] + 16)); + + // absolute differences between every ref[] to src + r[0] = _mm256_abs_epi16(_mm256_sub_epi16(r[0], s)); + r[1] = _mm256_abs_epi16(_mm256_sub_epi16(r[1], s2)); + r[2] = _mm256_abs_epi16(_mm256_sub_epi16(r[2], s)); + r[3] = _mm256_abs_epi16(_mm256_sub_epi16(r[3], s2)); + r[4] = _mm256_abs_epi16(_mm256_sub_epi16(r[4], s)); + r[5] = _mm256_abs_epi16(_mm256_sub_epi16(r[5], s2)); + r[6] = _mm256_abs_epi16(_mm256_sub_epi16(r[6], s)); + r[7] = _mm256_abs_epi16(_mm256_sub_epi16(r[7], s2)); + + // sum every abs diff + sums_16[0] = _mm256_add_epi16(sums_16[0], _mm256_add_epi16(r[0], r[1])); + sums_16[1] = _mm256_add_epi16(sums_16[1], _mm256_add_epi16(r[2], r[3])); + sums_16[2] = _mm256_add_epi16(sums_16[2], _mm256_add_epi16(r[4], r[5])); + sums_16[3] = _mm256_add_epi16(sums_16[3], _mm256_add_epi16(r[6], r[7])); + + src += src_stride; + refs[0] += ref_stride; + refs[1] += ref_stride; + refs[2] += ref_stride; + refs[3] += ref_stride; + } +} + +static VPX_FORCE_INLINE void highbd_sad32xNx4d_avx2( + const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], + int ref_stride, uint32_t sad_array[4], int n) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *refs[4]; + __m256i sums_16[4]; + __m256i sums_32[4]; + int i; + + refs[0] = CONVERT_TO_SHORTPTR(ref_array[0]); + refs[1] = CONVERT_TO_SHORTPTR(ref_array[1]); + refs[2] = CONVERT_TO_SHORTPTR(ref_array[2]); + refs[3] = CONVERT_TO_SHORTPTR(ref_array[3]); + sums_32[0] = _mm256_setzero_si256(); + sums_32[1] = _mm256_setzero_si256(); + sums_32[2] = _mm256_setzero_si256(); + sums_32[3] = _mm256_setzero_si256(); + + for (i = 0; i < (n / 8); ++i) { + sums_16[0] = _mm256_setzero_si256(); + sums_16[1] = _mm256_setzero_si256(); + sums_16[2] = _mm256_setzero_si256(); + sums_16[3] = _mm256_setzero_si256(); + + highbd_sad32xHx4d(sums_16, src, src_stride, refs, ref_stride, 8); + + /* sums_16 will outrange after 8 rows, so add current sums_16 to + * sums_32*/ + sums_32[0] = _mm256_add_epi32( + sums_32[0], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[0])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[0], 1)))); + sums_32[1] = _mm256_add_epi32( + sums_32[1], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[1])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[1], 1)))); + sums_32[2] = _mm256_add_epi32( + sums_32[2], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[2])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[2], 1)))); + sums_32[3] = _mm256_add_epi32( + sums_32[3], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[3])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[3], 1)))); + + src += src_stride << 3; + } + calc_final_4(sums_32, sad_array); +} + +#define HIGHBD_SAD32XNX4D(n) \ + void vpx_highbd_sad32x##n##x4d_avx2(const uint8_t *src, int src_stride, \ + const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + highbd_sad32xNx4d_avx2(src, src_stride, ref_array, ref_stride, sad_array, \ + n); \ + } + +#define HIGHBD_SADSKIP32XNx4D(n) \ + void vpx_highbd_sad_skip_32x##n##x4d_avx2( \ + const uint8_t *src, int src_stride, const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + highbd_sad32xNx4d_avx2(src, 2 * src_stride, ref_array, 2 * ref_stride, \ + sad_array, n / 2); \ + sad_array[0] <<= 1; \ + sad_array[1] <<= 1; \ + sad_array[2] <<= 1; \ + sad_array[3] <<= 1; \ + } + +static VPX_FORCE_INLINE void highbd_sad16xHx4d(__m256i *sums_16 /*[4]*/, + const uint16_t *src, + int src_stride, + uint16_t *refs[4], + int ref_stride, int height) { + int i; + for (i = 0; i < height; i++) { + __m256i r[4]; + + // load src and all ref[] + const __m256i s = _mm256_load_si256((const __m256i *)src); + r[0] = _mm256_loadu_si256((const __m256i *)refs[0]); + r[1] = _mm256_loadu_si256((const __m256i *)refs[1]); + r[2] = _mm256_loadu_si256((const __m256i *)refs[2]); + r[3] = _mm256_loadu_si256((const __m256i *)refs[3]); + + // absolute differences between every ref[] to src + r[0] = _mm256_abs_epi16(_mm256_sub_epi16(r[0], s)); + r[1] = _mm256_abs_epi16(_mm256_sub_epi16(r[1], s)); + r[2] = _mm256_abs_epi16(_mm256_sub_epi16(r[2], s)); + r[3] = _mm256_abs_epi16(_mm256_sub_epi16(r[3], s)); + + // sum every abs diff + sums_16[0] = _mm256_add_epi16(sums_16[0], r[0]); + sums_16[1] = _mm256_add_epi16(sums_16[1], r[1]); + sums_16[2] = _mm256_add_epi16(sums_16[2], r[2]); + sums_16[3] = _mm256_add_epi16(sums_16[3], r[3]); + + src += src_stride; + refs[0] += ref_stride; + refs[1] += ref_stride; + refs[2] += ref_stride; + refs[3] += ref_stride; + } +} + +static VPX_FORCE_INLINE void highbd_sad16xNx4d_avx2( + const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], + int ref_stride, uint32_t sad_array[4], int n) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *refs[4]; + __m256i sums_16[4]; + __m256i sums_32[4]; + const int height = VPXMIN(16, n); + const int num_iters = n / height; + int i; + + refs[0] = CONVERT_TO_SHORTPTR(ref_array[0]); + refs[1] = CONVERT_TO_SHORTPTR(ref_array[1]); + refs[2] = CONVERT_TO_SHORTPTR(ref_array[2]); + refs[3] = CONVERT_TO_SHORTPTR(ref_array[3]); + sums_32[0] = _mm256_setzero_si256(); + sums_32[1] = _mm256_setzero_si256(); + sums_32[2] = _mm256_setzero_si256(); + sums_32[3] = _mm256_setzero_si256(); + + for (i = 0; i < num_iters; ++i) { + sums_16[0] = _mm256_setzero_si256(); + sums_16[1] = _mm256_setzero_si256(); + sums_16[2] = _mm256_setzero_si256(); + sums_16[3] = _mm256_setzero_si256(); + + highbd_sad16xHx4d(sums_16, src, src_stride, refs, ref_stride, height); + + // sums_16 will outrange after 16 rows, so add current sums_16 to sums_32 + sums_32[0] = _mm256_add_epi32( + sums_32[0], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[0])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[0], 1)))); + sums_32[1] = _mm256_add_epi32( + sums_32[1], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[1])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[1], 1)))); + sums_32[2] = _mm256_add_epi32( + sums_32[2], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[2])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[2], 1)))); + sums_32[3] = _mm256_add_epi32( + sums_32[3], + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[3])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[3], 1)))); + + src += src_stride << 4; + } + calc_final_4(sums_32, sad_array); +} + +#define HIGHBD_SAD16XNX4D(n) \ + void vpx_highbd_sad16x##n##x4d_avx2(const uint8_t *src, int src_stride, \ + const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + highbd_sad16xNx4d_avx2(src, src_stride, ref_array, ref_stride, sad_array, \ + n); \ + } + +#define HIGHBD_SADSKIP16XNx4D(n) \ + void vpx_highbd_sad_skip_16x##n##x4d_avx2( \ + const uint8_t *src, int src_stride, const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + highbd_sad16xNx4d_avx2(src, 2 * src_stride, ref_array, 2 * ref_stride, \ + sad_array, n / 2); \ + sad_array[0] <<= 1; \ + sad_array[1] <<= 1; \ + sad_array[2] <<= 1; \ + sad_array[3] <<= 1; \ + } + +void vpx_highbd_sad16x16x4d_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *const ref_array[4], + int ref_stride, uint32_t sad_array[4]) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *refs[4]; + __m256i sums_16[4]; + + refs[0] = CONVERT_TO_SHORTPTR(ref_array[0]); + refs[1] = CONVERT_TO_SHORTPTR(ref_array[1]); + refs[2] = CONVERT_TO_SHORTPTR(ref_array[2]); + refs[3] = CONVERT_TO_SHORTPTR(ref_array[3]); + sums_16[0] = _mm256_setzero_si256(); + sums_16[1] = _mm256_setzero_si256(); + sums_16[2] = _mm256_setzero_si256(); + sums_16[3] = _mm256_setzero_si256(); + + highbd_sad16xHx4d(sums_16, src, src_stride, refs, ref_stride, 16); + + { + __m256i sums_32[4]; + sums_32[0] = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[0])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[0], 1))); + sums_32[1] = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[1])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[1], 1))); + sums_32[2] = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[2])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[2], 1))); + sums_32[3] = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[3])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[3], 1))); + calc_final_4(sums_32, sad_array); + } +} + +void vpx_highbd_sad16x8x4d_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *const ref_array[4], + int ref_stride, uint32_t sad_array[4]) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *refs[4]; + __m256i sums_16[4]; + + refs[0] = CONVERT_TO_SHORTPTR(ref_array[0]); + refs[1] = CONVERT_TO_SHORTPTR(ref_array[1]); + refs[2] = CONVERT_TO_SHORTPTR(ref_array[2]); + refs[3] = CONVERT_TO_SHORTPTR(ref_array[3]); + sums_16[0] = _mm256_setzero_si256(); + sums_16[1] = _mm256_setzero_si256(); + sums_16[2] = _mm256_setzero_si256(); + sums_16[3] = _mm256_setzero_si256(); + + highbd_sad16xHx4d(sums_16, src, src_stride, refs, ref_stride, 8); + + { + __m256i sums_32[4]; + sums_32[0] = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[0])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[0], 1))); + sums_32[1] = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[1])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[1], 1))); + sums_32[2] = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[2])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[2], 1))); + sums_32[3] = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16[3])), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16[3], 1))); + calc_final_4(sums_32, sad_array); + } +} + +// clang-format off +HIGHBD_SAD64XNX4D(64) +HIGHBD_SADSKIP64XNx4D(64) + +HIGHBD_SAD64XNX4D(32) +HIGHBD_SADSKIP64XNx4D(32) + +HIGHBD_SAD32XNX4D(64) +HIGHBD_SADSKIP32XNx4D(64) + +HIGHBD_SAD32XNX4D(32) +HIGHBD_SADSKIP32XNx4D(32) + +HIGHBD_SAD32XNX4D(16) +HIGHBD_SADSKIP32XNx4D(16) + +HIGHBD_SAD16XNX4D(32) +HIGHBD_SADSKIP16XNx4D(32) + +HIGHBD_SADSKIP16XNx4D(16) + +HIGHBD_SADSKIP16XNx4D(8) + // clang-format on diff --git a/libs/libvpx/vpx_dsp/x86/highbd_sad4d_sse2.asm b/libs/libvpx/vpx_dsp/x86/highbd_sad4d_sse2.asm index 6c2a61e019..a07892d811 100644 --- a/libs/libvpx/vpx_dsp/x86/highbd_sad4d_sse2.asm +++ b/libs/libvpx/vpx_dsp/x86/highbd_sad4d_sse2.asm @@ -213,7 +213,12 @@ SECTION .text ; uint8_t *ref[4], int ref_stride, ; uint32_t res[4]); ; where NxN = 64x64, 32x32, 16x16, 16x8, 8x16 or 8x8 -%macro HIGH_SADNXN4D 2 +; Macro Arguments: +; 1: Width +; 2: Height +; 3: If 0, then normal sad, if 2, then skip every other row +%macro HIGH_SADNXN4D 2-3 0 +%if %3 == 0 ; normal sad %if UNIX64 cglobal highbd_sad%1x%2x4d, 5, 8, 8, src, src_stride, ref1, ref_stride, \ res, ref2, ref3, ref4 @@ -221,6 +226,15 @@ cglobal highbd_sad%1x%2x4d, 5, 8, 8, src, src_stride, ref1, ref_stride, \ cglobal highbd_sad%1x%2x4d, 4, 7, 8, src, src_stride, ref1, ref_stride, \ ref2, ref3, ref4 %endif +%else ; %3 == 2, downsample +%if UNIX64 +cglobal highbd_sad_skip_%1x%2x4d, 5, 8, 8, src, src_stride, ref1, ref_stride, \ + res, ref2, ref3, ref4 +%else +cglobal highbd_sad_skip_%1x%2x4d, 4, 7, 8, src, src_stride, ref1, ref_stride, \ + ref2, ref3, ref4 +%endif ; +%endif ; sad/avg/skip ; set m1 push srcq @@ -229,6 +243,10 @@ cglobal highbd_sad%1x%2x4d, 4, 7, 8, src, src_stride, ref1, ref_stride, \ pshufd m1, m1, 0x0 pop srcq +%if %3 == 2 ; skip rows + lea src_strided, [2*src_strided] + lea ref_strided, [2*ref_strided] +%endif ; skip rows movsxdifnidn src_strideq, src_strided movsxdifnidn ref_strideq, ref_strided mov ref2q, [ref1q+gprsize*1] @@ -244,9 +262,15 @@ cglobal highbd_sad%1x%2x4d, 4, 7, 8, src, src_stride, ref1, ref_stride, \ shl ref1q, 1 HIGH_PROCESS_%1x2x4 1, 0, 0, src_strideq, ref_strideq, 1 -%rep (%2-4)/2 +%if %3 == 2 ; Downsampling by two +%define num_rep (%2-8)/4 +%else +%define num_rep (%2-4)/2 +%endif +%rep num_rep HIGH_PROCESS_%1x2x4 0, 0, 0, src_strideq, ref_strideq, 1 %endrep +%undef rep HIGH_PROCESS_%1x2x4 0, 0, 0, src_strideq, ref_strideq, 0 ; N.B. HIGH_PROCESS outputs dwords (32 bits) ; so in high bit depth even the smallest width (4) needs 128bits i.e. XMM @@ -265,6 +289,9 @@ cglobal highbd_sad%1x%2x4d, 4, 7, 8, src, src_stride, ref1, ref_stride, \ paddd m4, m0 paddd m6, m1 punpcklqdq m4, m6 +%if %3 == 2 ; skip rows + pslld m4, 1 +%endif movifnidn r4, r4mp movu [r4], m4 RET @@ -285,3 +312,15 @@ HIGH_SADNXN4D 8, 8 HIGH_SADNXN4D 8, 4 HIGH_SADNXN4D 4, 8 HIGH_SADNXN4D 4, 4 + +HIGH_SADNXN4D 64, 64, 2 +HIGH_SADNXN4D 64, 32, 2 +HIGH_SADNXN4D 32, 64, 2 +HIGH_SADNXN4D 32, 32, 2 +HIGH_SADNXN4D 32, 16, 2 +HIGH_SADNXN4D 16, 32, 2 +HIGH_SADNXN4D 16, 16, 2 +HIGH_SADNXN4D 16, 8, 2 +HIGH_SADNXN4D 8, 16, 2 +HIGH_SADNXN4D 8, 8, 2 +HIGH_SADNXN4D 4, 8, 2 diff --git a/libs/libvpx/vpx_dsp/x86/highbd_sad_avx2.c b/libs/libvpx/vpx_dsp/x86/highbd_sad_avx2.c new file mode 100644 index 0000000000..78f8eb8bfa --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/highbd_sad_avx2.c @@ -0,0 +1,522 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#include +#include "./vpx_dsp_rtcd.h" +#include "vpx/vpx_integer.h" + +static VPX_FORCE_INLINE unsigned int calc_final(const __m256i sums_32) { + const __m256i t0 = _mm256_add_epi32(sums_32, _mm256_srli_si256(sums_32, 8)); + const __m256i t1 = _mm256_add_epi32(t0, _mm256_srli_si256(t0, 4)); + const __m128i sum = _mm_add_epi32(_mm256_castsi256_si128(t1), + _mm256_extractf128_si256(t1, 1)); + return (unsigned int)_mm_cvtsi128_si32(sum); +} + +static VPX_FORCE_INLINE void highbd_sad64xH(__m256i *sums_16, + const uint16_t *src, int src_stride, + uint16_t *ref, int ref_stride, + int height) { + int i; + for (i = 0; i < height; ++i) { + // load src and all ref[] + const __m256i s0 = _mm256_load_si256((const __m256i *)src); + const __m256i s1 = _mm256_load_si256((const __m256i *)(src + 16)); + const __m256i s2 = _mm256_load_si256((const __m256i *)(src + 32)); + const __m256i s3 = _mm256_load_si256((const __m256i *)(src + 48)); + const __m256i r0 = _mm256_loadu_si256((const __m256i *)ref); + const __m256i r1 = _mm256_loadu_si256((const __m256i *)(ref + 16)); + const __m256i r2 = _mm256_loadu_si256((const __m256i *)(ref + 32)); + const __m256i r3 = _mm256_loadu_si256((const __m256i *)(ref + 48)); + // absolute differences between every ref[] to src + const __m256i abs_diff0 = _mm256_abs_epi16(_mm256_sub_epi16(r0, s0)); + const __m256i abs_diff1 = _mm256_abs_epi16(_mm256_sub_epi16(r1, s1)); + const __m256i abs_diff2 = _mm256_abs_epi16(_mm256_sub_epi16(r2, s2)); + const __m256i abs_diff3 = _mm256_abs_epi16(_mm256_sub_epi16(r3, s3)); + // sum every abs diff + *sums_16 = + _mm256_add_epi16(*sums_16, _mm256_add_epi16(abs_diff0, abs_diff1)); + *sums_16 = + _mm256_add_epi16(*sums_16, _mm256_add_epi16(abs_diff2, abs_diff3)); + + src += src_stride; + ref += ref_stride; + } +} + +static VPX_FORCE_INLINE unsigned int highbd_sad64xN_avx2(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, + int n) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); + __m256i sums_32 = _mm256_setzero_si256(); + int i; + + for (i = 0; i < (n / 2); ++i) { + __m256i sums_16 = _mm256_setzero_si256(); + + highbd_sad64xH(&sums_16, src, src_stride, ref, ref_stride, 2); + + /* sums_16 will outrange after 2 rows, so add current sums_16 to + * sums_32*/ + sums_32 = _mm256_add_epi32( + sums_32, + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16)), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16, 1)))); + + src += src_stride << 1; + ref += ref_stride << 1; + } + return calc_final(sums_32); +} + +#define HIGHBD_SAD64XN(n) \ + unsigned int vpx_highbd_sad64x##n##_avx2(const uint8_t *src, int src_stride, \ + const uint8_t *ref, \ + int ref_stride) { \ + return highbd_sad64xN_avx2(src, src_stride, ref, ref_stride, n); \ + } + +#define HIGHBD_SADSKIP64xN(n) \ + unsigned int vpx_highbd_sad_skip_64x##n##_avx2( \ + const uint8_t *src, int src_stride, const uint8_t *ref, \ + int ref_stride) { \ + return 2 * highbd_sad64xN_avx2(src, 2 * src_stride, ref, 2 * ref_stride, \ + n / 2); \ + } + +static VPX_FORCE_INLINE void highbd_sad32xH(__m256i *sums_16, + const uint16_t *src, int src_stride, + uint16_t *ref, int ref_stride, + int height) { + int i; + for (i = 0; i < height; ++i) { + // load src and all ref[] + const __m256i s0 = _mm256_load_si256((const __m256i *)src); + const __m256i s1 = _mm256_load_si256((const __m256i *)(src + 16)); + const __m256i r0 = _mm256_loadu_si256((const __m256i *)ref); + const __m256i r1 = _mm256_loadu_si256((const __m256i *)(ref + 16)); + // absolute differences between every ref[] to src + const __m256i abs_diff0 = _mm256_abs_epi16(_mm256_sub_epi16(r0, s0)); + const __m256i abs_diff1 = _mm256_abs_epi16(_mm256_sub_epi16(r1, s1)); + // sum every abs diff + *sums_16 = _mm256_add_epi16(*sums_16, abs_diff0); + *sums_16 = _mm256_add_epi16(*sums_16, abs_diff1); + + src += src_stride; + ref += ref_stride; + } +} + +static VPX_FORCE_INLINE unsigned int highbd_sad32xN_avx2(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, + int n) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); + __m256i sums_32 = _mm256_setzero_si256(); + int i; + + for (i = 0; i < (n / 8); ++i) { + __m256i sums_16 = _mm256_setzero_si256(); + + highbd_sad32xH(&sums_16, src, src_stride, ref, ref_stride, 8); + + /* sums_16 will outrange after 8 rows, so add current sums_16 to + * sums_32*/ + sums_32 = _mm256_add_epi32( + sums_32, + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16)), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16, 1)))); + + src += src_stride << 3; + ref += ref_stride << 3; + } + return calc_final(sums_32); +} + +#define HIGHBD_SAD32XN(n) \ + unsigned int vpx_highbd_sad32x##n##_avx2(const uint8_t *src, int src_stride, \ + const uint8_t *ref, \ + int ref_stride) { \ + return highbd_sad32xN_avx2(src, src_stride, ref, ref_stride, n); \ + } + +#define HIGHBD_SADSKIP32xN(n) \ + unsigned int vpx_highbd_sad_skip_32x##n##_avx2( \ + const uint8_t *src, int src_stride, const uint8_t *ref, \ + int ref_stride) { \ + return 2 * highbd_sad32xN_avx2(src, 2 * src_stride, ref, 2 * ref_stride, \ + n / 2); \ + } + +static VPX_FORCE_INLINE void highbd_sad16xH(__m256i *sums_16, + const uint16_t *src, int src_stride, + uint16_t *ref, int ref_stride, + int height) { + int i; + for (i = 0; i < height; i += 2) { + // load src and all ref[] + const __m256i s0 = _mm256_load_si256((const __m256i *)src); + const __m256i s1 = _mm256_load_si256((const __m256i *)(src + src_stride)); + const __m256i r0 = _mm256_loadu_si256((const __m256i *)ref); + const __m256i r1 = _mm256_loadu_si256((const __m256i *)(ref + ref_stride)); + // absolute differences between every ref[] to src + const __m256i abs_diff0 = _mm256_abs_epi16(_mm256_sub_epi16(r0, s0)); + const __m256i abs_diff1 = _mm256_abs_epi16(_mm256_sub_epi16(r1, s1)); + // sum every abs diff + *sums_16 = _mm256_add_epi16(*sums_16, abs_diff0); + *sums_16 = _mm256_add_epi16(*sums_16, abs_diff1); + + src += src_stride << 1; + ref += ref_stride << 1; + } +} + +static VPX_FORCE_INLINE unsigned int highbd_sad16xN_avx2(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, + int n) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); + __m256i sums_32 = _mm256_setzero_si256(); + const int height = VPXMIN(16, n); + const int num_iters = n / height; + int i; + + for (i = 0; i < num_iters; ++i) { + __m256i sums_16 = _mm256_setzero_si256(); + + highbd_sad16xH(&sums_16, src, src_stride, ref, ref_stride, height); + + // sums_16 will outrange after 16 rows, so add current sums_16 to sums_32 + sums_32 = _mm256_add_epi32( + sums_32, + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16)), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16, 1)))); + + src += src_stride << 4; + ref += ref_stride << 4; + } + return calc_final(sums_32); +} + +#define HIGHBD_SAD16XN(n) \ + unsigned int vpx_highbd_sad16x##n##_avx2(const uint8_t *src, int src_stride, \ + const uint8_t *ref, \ + int ref_stride) { \ + return highbd_sad16xN_avx2(src, src_stride, ref, ref_stride, n); \ + } + +#define HIGHBD_SADSKIP16xN(n) \ + unsigned int vpx_highbd_sad_skip_16x##n##_avx2( \ + const uint8_t *src, int src_stride, const uint8_t *ref, \ + int ref_stride) { \ + return 2 * highbd_sad16xN_avx2(src, 2 * src_stride, ref, 2 * ref_stride, \ + n / 2); \ + } + +unsigned int vpx_highbd_sad16x16_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); + __m256i sums_16 = _mm256_setzero_si256(); + + highbd_sad16xH(&sums_16, src, src_stride, ref, ref_stride, 16); + + { + const __m256i sums_32 = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16)), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16, 1))); + return calc_final(sums_32); + } +} + +unsigned int vpx_highbd_sad16x8_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); + __m256i sums_16 = _mm256_setzero_si256(); + + highbd_sad16xH(&sums_16, src, src_stride, ref, ref_stride, 8); + + { + const __m256i sums_32 = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16)), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16, 1))); + return calc_final(sums_32); + } +} + +// clang-format off +HIGHBD_SAD64XN(64) +HIGHBD_SADSKIP64xN(64) +HIGHBD_SAD64XN(32) +HIGHBD_SADSKIP64xN(32) +HIGHBD_SAD32XN(64) +HIGHBD_SADSKIP32xN(64) +HIGHBD_SAD32XN(32) +HIGHBD_SADSKIP32xN(32) +HIGHBD_SAD32XN(16) +HIGHBD_SADSKIP32xN(16) +HIGHBD_SAD16XN(32) +HIGHBD_SADSKIP16xN(32) +HIGHBD_SADSKIP16xN(16) +HIGHBD_SADSKIP16xN(8) +//clang-format on + +// AVG ------------------------------------------------------------------------- +static VPX_FORCE_INLINE void highbd_sad64xH_avg(__m256i *sums_16, + const uint16_t *src, + int src_stride, uint16_t *ref, + int ref_stride, uint16_t *sec, + int height) { + int i; + for (i = 0; i < height; ++i) { + // load src and all ref[] + const __m256i s0 = _mm256_load_si256((const __m256i *)src); + const __m256i s1 = _mm256_load_si256((const __m256i *)(src + 16)); + const __m256i s2 = _mm256_load_si256((const __m256i *)(src + 32)); + const __m256i s3 = _mm256_load_si256((const __m256i *)(src + 48)); + const __m256i r0 = _mm256_loadu_si256((const __m256i *)ref); + const __m256i r1 = _mm256_loadu_si256((const __m256i *)(ref + 16)); + const __m256i r2 = _mm256_loadu_si256((const __m256i *)(ref + 32)); + const __m256i r3 = _mm256_loadu_si256((const __m256i *)(ref + 48)); + const __m256i x0 = _mm256_loadu_si256((const __m256i *)sec); + const __m256i x1 = _mm256_loadu_si256((const __m256i *)(sec + 16)); + const __m256i x2 = _mm256_loadu_si256((const __m256i *)(sec + 32)); + const __m256i x3 = _mm256_loadu_si256((const __m256i *)(sec + 48)); + const __m256i avg0 = _mm256_avg_epu16(r0, x0); + const __m256i avg1 = _mm256_avg_epu16(r1, x1); + const __m256i avg2 = _mm256_avg_epu16(r2, x2); + const __m256i avg3 = _mm256_avg_epu16(r3, x3); + // absolute differences between every ref/pred avg to src + const __m256i abs_diff0 = _mm256_abs_epi16(_mm256_sub_epi16(avg0, s0)); + const __m256i abs_diff1 = _mm256_abs_epi16(_mm256_sub_epi16(avg1, s1)); + const __m256i abs_diff2 = _mm256_abs_epi16(_mm256_sub_epi16(avg2, s2)); + const __m256i abs_diff3 = _mm256_abs_epi16(_mm256_sub_epi16(avg3, s3)); + // sum every abs diff + *sums_16 = + _mm256_add_epi16(*sums_16, _mm256_add_epi16(abs_diff0, abs_diff1)); + *sums_16 = + _mm256_add_epi16(*sums_16, _mm256_add_epi16(abs_diff2, abs_diff3)); + + src += src_stride; + ref += ref_stride; + sec += 64; + } +} + +#define HIGHBD_SAD64XN_AVG(n) \ + unsigned int vpx_highbd_sad64x##n##_avg_avx2( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, const uint8_t *second_pred) { \ + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + uint16_t *sec = CONVERT_TO_SHORTPTR(second_pred); \ + __m256i sums_32 = _mm256_setzero_si256(); \ + int i; \ + \ + for (i = 0; i < (n / 2); ++i) { \ + __m256i sums_16 = _mm256_setzero_si256(); \ + \ + highbd_sad64xH_avg(&sums_16, src, src_stride, ref, ref_stride, sec, 2); \ + \ + /* sums_16 will outrange after 2 rows, so add current sums_16 to \ + * sums_32*/ \ + sums_32 = _mm256_add_epi32( \ + sums_32, \ + _mm256_add_epi32( \ + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16)), \ + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16, 1)))); \ + \ + src += src_stride << 1; \ + ref += ref_stride << 1; \ + sec += 64 << 1; \ + } \ + return calc_final(sums_32); \ + } + +// 64x64 +HIGHBD_SAD64XN_AVG(64) + +// 64x32 +HIGHBD_SAD64XN_AVG(32) + +static VPX_FORCE_INLINE void highbd_sad32xH_avg(__m256i *sums_16, + const uint16_t *src, + int src_stride, uint16_t *ref, + int ref_stride, uint16_t *sec, + int height) { + int i; + for (i = 0; i < height; ++i) { + // load src and all ref[] + const __m256i s0 = _mm256_load_si256((const __m256i *)src); + const __m256i s1 = _mm256_load_si256((const __m256i *)(src + 16)); + const __m256i r0 = _mm256_loadu_si256((const __m256i *)ref); + const __m256i r1 = _mm256_loadu_si256((const __m256i *)(ref + 16)); + const __m256i x0 = _mm256_loadu_si256((const __m256i *)sec); + const __m256i x1 = _mm256_loadu_si256((const __m256i *)(sec + 16)); + const __m256i avg0 = _mm256_avg_epu16(r0, x0); + const __m256i avg1 = _mm256_avg_epu16(r1, x1); + // absolute differences between every ref/pred avg to src + const __m256i abs_diff0 = _mm256_abs_epi16(_mm256_sub_epi16(avg0, s0)); + const __m256i abs_diff1 = _mm256_abs_epi16(_mm256_sub_epi16(avg1, s1)); + // sum every abs diff + *sums_16 = _mm256_add_epi16(*sums_16, abs_diff0); + *sums_16 = _mm256_add_epi16(*sums_16, abs_diff1); + + src += src_stride; + ref += ref_stride; + sec += 32; + } +} + +#define HIGHBD_SAD32XN_AVG(n) \ + unsigned int vpx_highbd_sad32x##n##_avg_avx2( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, const uint8_t *second_pred) { \ + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); \ + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); \ + uint16_t *sec = CONVERT_TO_SHORTPTR(second_pred); \ + __m256i sums_32 = _mm256_setzero_si256(); \ + int i; \ + \ + for (i = 0; i < (n / 8); ++i) { \ + __m256i sums_16 = _mm256_setzero_si256(); \ + \ + highbd_sad32xH_avg(&sums_16, src, src_stride, ref, ref_stride, sec, 8); \ + \ + /* sums_16 will outrange after 8 rows, so add current sums_16 to \ + * sums_32*/ \ + sums_32 = _mm256_add_epi32( \ + sums_32, \ + _mm256_add_epi32( \ + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16)), \ + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16, 1)))); \ + \ + src += src_stride << 3; \ + ref += ref_stride << 3; \ + sec += 32 << 3; \ + } \ + return calc_final(sums_32); \ + } + +// 32x64 +HIGHBD_SAD32XN_AVG(64) + +// 32x32 +HIGHBD_SAD32XN_AVG(32) + +// 32x16 +HIGHBD_SAD32XN_AVG(16) + +static VPX_FORCE_INLINE void highbd_sad16xH_avg(__m256i *sums_16, + const uint16_t *src, + int src_stride, uint16_t *ref, + int ref_stride, uint16_t *sec, + int height) { + int i; + for (i = 0; i < height; i += 2) { + // load src and all ref[] + const __m256i s0 = _mm256_load_si256((const __m256i *)src); + const __m256i s1 = _mm256_load_si256((const __m256i *)(src + src_stride)); + const __m256i r0 = _mm256_loadu_si256((const __m256i *)ref); + const __m256i r1 = _mm256_loadu_si256((const __m256i *)(ref + ref_stride)); + const __m256i x0 = _mm256_loadu_si256((const __m256i *)sec); + const __m256i x1 = _mm256_loadu_si256((const __m256i *)(sec + 16)); + const __m256i avg0 = _mm256_avg_epu16(r0, x0); + const __m256i avg1 = _mm256_avg_epu16(r1, x1); + // absolute differences between every ref[] to src + const __m256i abs_diff0 = _mm256_abs_epi16(_mm256_sub_epi16(avg0, s0)); + const __m256i abs_diff1 = _mm256_abs_epi16(_mm256_sub_epi16(avg1, s1)); + // sum every abs diff + *sums_16 = _mm256_add_epi16(*sums_16, abs_diff0); + *sums_16 = _mm256_add_epi16(*sums_16, abs_diff1); + + src += src_stride << 1; + ref += ref_stride << 1; + sec += 32; + } +} + +unsigned int vpx_highbd_sad16x32_avg_avx2(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, + const uint8_t *second_pred) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); + uint16_t *sec = CONVERT_TO_SHORTPTR(second_pred); + __m256i sums_32 = _mm256_setzero_si256(); + int i; + + for (i = 0; i < 2; ++i) { + __m256i sums_16 = _mm256_setzero_si256(); + + highbd_sad16xH_avg(&sums_16, src, src_stride, ref, ref_stride, sec, 16); + + // sums_16 will outrange after 16 rows, so add current sums_16 to sums_32 + sums_32 = _mm256_add_epi32( + sums_32, + _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16)), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16, 1)))); + + src += src_stride << 4; + ref += ref_stride << 4; + sec += 16 << 4; + } + return calc_final(sums_32); +} + +unsigned int vpx_highbd_sad16x16_avg_avx2(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, + const uint8_t *second_pred) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); + uint16_t *sec = CONVERT_TO_SHORTPTR(second_pred); + __m256i sums_16 = _mm256_setzero_si256(); + + highbd_sad16xH_avg(&sums_16, src, src_stride, ref, ref_stride, sec, 16); + + { + const __m256i sums_32 = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16)), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16, 1))); + return calc_final(sums_32); + } +} + +unsigned int vpx_highbd_sad16x8_avg_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + const uint8_t *second_pred) { + const uint16_t *src = CONVERT_TO_SHORTPTR(src_ptr); + uint16_t *ref = CONVERT_TO_SHORTPTR(ref_ptr); + uint16_t *sec = CONVERT_TO_SHORTPTR(second_pred); + __m256i sums_16 = _mm256_setzero_si256(); + + highbd_sad16xH_avg(&sums_16, src, src_stride, ref, ref_stride, sec, 8); + + { + const __m256i sums_32 = _mm256_add_epi32( + _mm256_cvtepu16_epi32(_mm256_castsi256_si128(sums_16)), + _mm256_cvtepu16_epi32(_mm256_extractf128_si256(sums_16, 1))); + return calc_final(sums_32); + } +} diff --git a/libs/libvpx/vpx_dsp/x86/highbd_sad_sse2.asm b/libs/libvpx/vpx_dsp/x86/highbd_sad_sse2.asm index 6a1a6f3d62..62ad2237ff 100644 --- a/libs/libvpx/vpx_dsp/x86/highbd_sad_sse2.asm +++ b/libs/libvpx/vpx_dsp/x86/highbd_sad_sse2.asm @@ -12,6 +12,11 @@ SECTION .text +; Macro Arguments +; Arg 1: Width +; Arg 2: Height +; Arg 3: Number of general purpose registers +; Arg 4: Type of function: if 0, normal sad; if 1, avg; if 2, skip rows %macro HIGH_SAD_FN 4 %if %4 == 0 %if %3 == 5 @@ -20,7 +25,7 @@ cglobal highbd_sad%1x%2, 4, %3, 7, src, src_stride, ref, ref_stride, n_rows cglobal highbd_sad%1x%2, 4, %3, 7, src, src_stride, ref, ref_stride, \ src_stride3, ref_stride3, n_rows %endif ; %3 == 5/7 -%else ; avg +%elif %4 == 1 ; avg %if %3 == 5 cglobal highbd_sad%1x%2_avg, 5, 1 + %3, 7, src, src_stride, ref, ref_stride, \ second_pred, n_rows @@ -35,7 +40,18 @@ cglobal highbd_sad%1x%2_avg, 5, VPX_ARCH_X86_64 + %3, 7, src, src_stride, \ %define n_rowsd dword r0m %endif ; x86-32/64 %endif ; %3 == 5/7 -%endif ; avg/sad +%else ; %4 == 2, skip rows +%if %3 == 5 +cglobal highbd_sad_skip_%1x%2, 4, %3, 7, src, src_stride, ref, ref_stride, n_rows +%else ; %3 == 7 +cglobal highbd_sad_skip_%1x%2, 4, %3, 7, src, src_stride, ref, ref_stride, \ + src_stride3, ref_stride3, n_rows +%endif ; %3 == 5/7 +%endif ; sad/avg/skip +%if %4 == 2 ; double the stride if we are skipping rows + lea src_strided, [src_strided*2] + lea ref_strided, [ref_strided*2] +%endif movsxdifnidn src_strideq, src_strided movsxdifnidn ref_strideq, ref_strided %if %3 == 7 @@ -54,7 +70,11 @@ cglobal highbd_sad%1x%2_avg, 5, VPX_ARCH_X86_64 + %3, 7, src, src_stride, \ ; uint8_t *ref, int ref_stride); %macro HIGH_SAD64XN 1-2 0 HIGH_SAD_FN 64, %1, 5, %2 +%if %2 == 2 ; skip rows, so divide number of rows by 2 + mov n_rowsd, %1/2 +%else mov n_rowsd, %1 +%endif pxor m0, m0 pxor m6, m6 @@ -146,6 +166,9 @@ cglobal highbd_sad%1x%2_avg, 5, VPX_ARCH_X86_64 + %3, 7, src, src_stride, \ punpckldq m0, m6 movhlps m1, m0 paddd m0, m1 +%if %2 == 2 ; we skipped rows, so we need to double the sad + pslld m0, 1 +%endif movd eax, m0 RET %endmacro @@ -155,13 +178,19 @@ HIGH_SAD64XN 64 ; highbd_sad64x64_sse2 HIGH_SAD64XN 32 ; highbd_sad64x32_sse2 HIGH_SAD64XN 64, 1 ; highbd_sad64x64_avg_sse2 HIGH_SAD64XN 32, 1 ; highbd_sad64x32_avg_sse2 +HIGH_SAD64XN 64, 2 ; highbd_sad_skip_64x64_sse2 +HIGH_SAD64XN 32, 2 ; highbd_sad_skip_64x32_sse2 ; unsigned int vpx_highbd_sad32x{16,32,64}_sse2(uint8_t *src, int src_stride, ; uint8_t *ref, int ref_stride); %macro HIGH_SAD32XN 1-2 0 HIGH_SAD_FN 32, %1, 5, %2 +%if %2 == 2 ; skip rows, so divide number of rows by 2 + mov n_rowsd, %1/2 +%else mov n_rowsd, %1 +%endif pxor m0, m0 pxor m6, m6 @@ -213,6 +242,9 @@ HIGH_SAD64XN 32, 1 ; highbd_sad64x32_avg_sse2 punpckldq m0, m6 movhlps m1, m0 paddd m0, m1 +%if %2 == 2 ; we skipped rows, so we need to double the sad + pslld m0, 1 +%endif movd eax, m0 RET %endmacro @@ -224,12 +256,19 @@ HIGH_SAD32XN 16 ; highbd_sad32x16_sse2 HIGH_SAD32XN 64, 1 ; highbd_sad32x64_avg_sse2 HIGH_SAD32XN 32, 1 ; highbd_sad32x32_avg_sse2 HIGH_SAD32XN 16, 1 ; highbd_sad32x16_avg_sse2 +HIGH_SAD32XN 64, 2 ; highbd_sad_skip_32x64_sse2 +HIGH_SAD32XN 32, 2 ; highbd_sad_skip_32x32_sse2 +HIGH_SAD32XN 16, 2 ; highbd_sad_skip_32x16_sse2 ; unsigned int vpx_highbd_sad16x{8,16,32}_sse2(uint8_t *src, int src_stride, ; uint8_t *ref, int ref_stride); %macro HIGH_SAD16XN 1-2 0 HIGH_SAD_FN 16, %1, 5, %2 +%if %2 == 2 ; skip rows, so divide number of rows by 2 + mov n_rowsd, %1/4 +%else mov n_rowsd, %1/2 +%endif pxor m0, m0 pxor m6, m6 @@ -281,6 +320,9 @@ HIGH_SAD32XN 16, 1 ; highbd_sad32x16_avg_sse2 punpckldq m0, m6 movhlps m1, m0 paddd m0, m1 +%if %2 == 2 ; we skipped rows, so we need to double the sad + pslld m0, 1 +%endif movd eax, m0 RET %endmacro @@ -292,13 +334,19 @@ HIGH_SAD16XN 8 ; highbd_sad16x8_sse2 HIGH_SAD16XN 32, 1 ; highbd_sad16x32_avg_sse2 HIGH_SAD16XN 16, 1 ; highbd_sad16x16_avg_sse2 HIGH_SAD16XN 8, 1 ; highbd_sad16x8_avg_sse2 - +HIGH_SAD16XN 32, 2 ; highbd_sad_skip_16x32_sse2 +HIGH_SAD16XN 16, 2 ; highbd_sad_skip_16x16_sse2 +HIGH_SAD16XN 8, 2 ; highbd_sad_skip_16x8_sse2 ; unsigned int vpx_highbd_sad8x{4,8,16}_sse2(uint8_t *src, int src_stride, ; uint8_t *ref, int ref_stride); %macro HIGH_SAD8XN 1-2 0 HIGH_SAD_FN 8, %1, 7, %2 +%if %2 == 2 ; skip rows, so divide number of rows by 2 + mov n_rowsd, %1/8 +%else mov n_rowsd, %1/4 +%endif pxor m0, m0 pxor m6, m6 @@ -350,6 +398,9 @@ HIGH_SAD16XN 8, 1 ; highbd_sad16x8_avg_sse2 punpckldq m0, m6 movhlps m1, m0 paddd m0, m1 +%if %2 == 2 ; we skipped rows, so we need to double the sad + pslld m0, 1 +%endif movd eax, m0 RET %endmacro @@ -361,3 +412,5 @@ HIGH_SAD8XN 4 ; highbd_sad8x4_sse2 HIGH_SAD8XN 16, 1 ; highbd_sad8x16_avg_sse2 HIGH_SAD8XN 8, 1 ; highbd_sad8x8_avg_sse2 HIGH_SAD8XN 4, 1 ; highbd_sad8x4_avg_sse2 +HIGH_SAD8XN 16, 2 ; highbd_sad_skip_8x16_sse2 +HIGH_SAD8XN 8, 2 ; highbd_sad_skip_8x8_sse2 diff --git a/libs/libvpx/vpx_dsp/x86/highbd_variance_sse2.c b/libs/libvpx/vpx_dsp/x86/highbd_variance_sse2.c index 7c8d79b09e..3062bf86ff 100644 --- a/libs/libvpx/vpx_dsp/x86/highbd_variance_sse2.c +++ b/libs/libvpx/vpx_dsp/x86/highbd_variance_sse2.c @@ -7,11 +7,13 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include // SSE2 #include "./vpx_config.h" #include "./vpx_dsp_rtcd.h" #include "vpx_ports/mem.h" +#if HAVE_X86_ASM typedef uint32_t (*high_variance_fn_t)(const uint16_t *src, int src_stride, const uint16_t *ref, int ref_stride, uint32_t *sse, int *sum); @@ -559,3 +561,50 @@ FNS(sse2) #undef FNS #undef FN +#endif // HAVE_X86_ASM + +void vpx_highbd_comp_avg_pred_sse2(uint16_t *comp_pred, const uint16_t *pred, + int width, int height, const uint16_t *ref, + int ref_stride) { + int i, j; + if (width > 8) { + for (i = 0; i < height; ++i) { + for (j = 0; j < width; j += 16) { + const __m128i p0 = _mm_loadu_si128((const __m128i *)&pred[j]); + const __m128i p1 = _mm_loadu_si128((const __m128i *)&pred[j + 8]); + const __m128i r0 = _mm_loadu_si128((const __m128i *)&ref[j]); + const __m128i r1 = _mm_loadu_si128((const __m128i *)&ref[j + 8]); + _mm_storeu_si128((__m128i *)&comp_pred[j], _mm_avg_epu16(p0, r0)); + _mm_storeu_si128((__m128i *)&comp_pred[j + 8], _mm_avg_epu16(p1, r1)); + } + comp_pred += width; + pred += width; + ref += ref_stride; + } + } else if (width == 8) { + for (i = 0; i < height; i += 2) { + const __m128i p0 = _mm_loadu_si128((const __m128i *)&pred[0]); + const __m128i p1 = _mm_loadu_si128((const __m128i *)&pred[8]); + const __m128i r0 = _mm_loadu_si128((const __m128i *)&ref[0]); + const __m128i r1 = _mm_loadu_si128((const __m128i *)&ref[ref_stride]); + _mm_storeu_si128((__m128i *)&comp_pred[0], _mm_avg_epu16(p0, r0)); + _mm_storeu_si128((__m128i *)&comp_pred[8], _mm_avg_epu16(p1, r1)); + comp_pred += 8 << 1; + pred += 8 << 1; + ref += ref_stride << 1; + } + } else { + assert(width == 4); + for (i = 0; i < height; i += 2) { + const __m128i p0 = _mm_loadl_epi64((const __m128i *)&pred[0]); + const __m128i p1 = _mm_loadl_epi64((const __m128i *)&pred[4]); + const __m128i r0 = _mm_loadl_epi64((const __m128i *)&ref[0]); + const __m128i r1 = _mm_loadl_epi64((const __m128i *)&ref[ref_stride]); + _mm_storel_epi64((__m128i *)&comp_pred[0], _mm_avg_epu16(p0, r0)); + _mm_storel_epi64((__m128i *)&comp_pred[4], _mm_avg_epu16(p1, r1)); + comp_pred += 4 << 1; + pred += 4 << 1; + ref += ref_stride << 1; + } + } +} diff --git a/libs/libvpx/vpx_dsp/x86/inv_txfm_avx2.c b/libs/libvpx/vpx_dsp/x86/inv_txfm_avx2.c new file mode 100644 index 0000000000..752435d240 --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/inv_txfm_avx2.c @@ -0,0 +1,626 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include // AVX2 + +#include "./vpx_dsp_rtcd.h" +#include "vpx_dsp/txfm_common.h" + +#define PAIR256_SET_EPI16(a, b) \ + _mm256_set_epi16((int16_t)(b), (int16_t)(a), (int16_t)(b), (int16_t)(a), \ + (int16_t)(b), (int16_t)(a), (int16_t)(b), (int16_t)(a), \ + (int16_t)(b), (int16_t)(a), (int16_t)(b), (int16_t)(a), \ + (int16_t)(b), (int16_t)(a), (int16_t)(b), (int16_t)(a)) + +static INLINE void idct_load16x16(const tran_low_t *input, __m256i *in, + int stride) { + int i; + // Load 16x16 values + for (i = 0; i < 16; i++) { +#if CONFIG_VP9_HIGHBITDEPTH + const __m128i in0 = _mm_loadu_si128((const __m128i *)(input + i * stride)); + const __m128i in1 = + _mm_loadu_si128((const __m128i *)((input + i * stride) + 4)); + const __m128i in2 = + _mm_loadu_si128((const __m128i *)((input + i * stride) + 8)); + const __m128i in3 = + _mm_loadu_si128((const __m128i *)((input + i * stride) + 12)); + const __m128i ls = _mm_packs_epi32(in0, in1); + const __m128i rs = _mm_packs_epi32(in2, in3); + in[i] = _mm256_inserti128_si256(_mm256_castsi128_si256(ls), rs, 1); +#else + in[i] = _mm256_load_si256((const __m256i *)(input + i * stride)); +#endif + } +} + +static INLINE __m256i dct_round_shift_avx2(__m256i in) { + const __m256i t = _mm256_add_epi32(in, _mm256_set1_epi32(DCT_CONST_ROUNDING)); + return _mm256_srai_epi32(t, DCT_CONST_BITS); +} + +static INLINE __m256i idct_madd_round_shift_avx2(__m256i *in, __m256i *cospi) { + const __m256i t = _mm256_madd_epi16(*in, *cospi); + return dct_round_shift_avx2(t); +} + +// Calculate the dot product between in0/1 and x and wrap to short. +static INLINE __m256i idct_calc_wraplow_avx2(__m256i *in0, __m256i *in1, + __m256i *x) { + const __m256i t0 = idct_madd_round_shift_avx2(in0, x); + const __m256i t1 = idct_madd_round_shift_avx2(in1, x); + return _mm256_packs_epi32(t0, t1); +} + +// Multiply elements by constants and add them together. +static INLINE void butterfly16(__m256i in0, __m256i in1, int c0, int c1, + __m256i *out0, __m256i *out1) { + __m256i cst0 = PAIR256_SET_EPI16(c0, -c1); + __m256i cst1 = PAIR256_SET_EPI16(c1, c0); + __m256i lo = _mm256_unpacklo_epi16(in0, in1); + __m256i hi = _mm256_unpackhi_epi16(in0, in1); + *out0 = idct_calc_wraplow_avx2(&lo, &hi, &cst0); + *out1 = idct_calc_wraplow_avx2(&lo, &hi, &cst1); +} + +static INLINE void idct16_16col(__m256i *in, __m256i *out) { + __m256i step1[16], step2[16]; + + // stage 2 + butterfly16(in[1], in[15], cospi_30_64, cospi_2_64, &step2[8], &step2[15]); + butterfly16(in[9], in[7], cospi_14_64, cospi_18_64, &step2[9], &step2[14]); + butterfly16(in[5], in[11], cospi_22_64, cospi_10_64, &step2[10], &step2[13]); + butterfly16(in[13], in[3], cospi_6_64, cospi_26_64, &step2[11], &step2[12]); + + // stage 3 + butterfly16(in[2], in[14], cospi_28_64, cospi_4_64, &step1[4], &step1[7]); + butterfly16(in[10], in[6], cospi_12_64, cospi_20_64, &step1[5], &step1[6]); + step1[8] = _mm256_add_epi16(step2[8], step2[9]); + step1[9] = _mm256_sub_epi16(step2[8], step2[9]); + step1[10] = _mm256_sub_epi16(step2[11], step2[10]); + step1[11] = _mm256_add_epi16(step2[10], step2[11]); + step1[12] = _mm256_add_epi16(step2[12], step2[13]); + step1[13] = _mm256_sub_epi16(step2[12], step2[13]); + step1[14] = _mm256_sub_epi16(step2[15], step2[14]); + step1[15] = _mm256_add_epi16(step2[14], step2[15]); + + // stage 4 + butterfly16(in[0], in[8], cospi_16_64, cospi_16_64, &step2[1], &step2[0]); + butterfly16(in[4], in[12], cospi_24_64, cospi_8_64, &step2[2], &step2[3]); + butterfly16(step1[14], step1[9], cospi_24_64, cospi_8_64, &step2[9], + &step2[14]); + butterfly16(step1[10], step1[13], -cospi_8_64, -cospi_24_64, &step2[13], + &step2[10]); + step2[5] = _mm256_sub_epi16(step1[4], step1[5]); + step1[4] = _mm256_add_epi16(step1[4], step1[5]); + step2[6] = _mm256_sub_epi16(step1[7], step1[6]); + step1[7] = _mm256_add_epi16(step1[6], step1[7]); + step2[8] = step1[8]; + step2[11] = step1[11]; + step2[12] = step1[12]; + step2[15] = step1[15]; + + // stage 5 + step1[0] = _mm256_add_epi16(step2[0], step2[3]); + step1[1] = _mm256_add_epi16(step2[1], step2[2]); + step1[2] = _mm256_sub_epi16(step2[1], step2[2]); + step1[3] = _mm256_sub_epi16(step2[0], step2[3]); + butterfly16(step2[6], step2[5], cospi_16_64, cospi_16_64, &step1[5], + &step1[6]); + step1[8] = _mm256_add_epi16(step2[8], step2[11]); + step1[9] = _mm256_add_epi16(step2[9], step2[10]); + step1[10] = _mm256_sub_epi16(step2[9], step2[10]); + step1[11] = _mm256_sub_epi16(step2[8], step2[11]); + step1[12] = _mm256_sub_epi16(step2[15], step2[12]); + step1[13] = _mm256_sub_epi16(step2[14], step2[13]); + step1[14] = _mm256_add_epi16(step2[14], step2[13]); + step1[15] = _mm256_add_epi16(step2[15], step2[12]); + + // stage 6 + step2[0] = _mm256_add_epi16(step1[0], step1[7]); + step2[1] = _mm256_add_epi16(step1[1], step1[6]); + step2[2] = _mm256_add_epi16(step1[2], step1[5]); + step2[3] = _mm256_add_epi16(step1[3], step1[4]); + step2[4] = _mm256_sub_epi16(step1[3], step1[4]); + step2[5] = _mm256_sub_epi16(step1[2], step1[5]); + step2[6] = _mm256_sub_epi16(step1[1], step1[6]); + step2[7] = _mm256_sub_epi16(step1[0], step1[7]); + butterfly16(step1[13], step1[10], cospi_16_64, cospi_16_64, &step2[10], + &step2[13]); + butterfly16(step1[12], step1[11], cospi_16_64, cospi_16_64, &step2[11], + &step2[12]); + + // stage 7 + out[0] = _mm256_add_epi16(step2[0], step1[15]); + out[1] = _mm256_add_epi16(step2[1], step1[14]); + out[2] = _mm256_add_epi16(step2[2], step2[13]); + out[3] = _mm256_add_epi16(step2[3], step2[12]); + out[4] = _mm256_add_epi16(step2[4], step2[11]); + out[5] = _mm256_add_epi16(step2[5], step2[10]); + out[6] = _mm256_add_epi16(step2[6], step1[9]); + out[7] = _mm256_add_epi16(step2[7], step1[8]); + out[8] = _mm256_sub_epi16(step2[7], step1[8]); + out[9] = _mm256_sub_epi16(step2[6], step1[9]); + out[10] = _mm256_sub_epi16(step2[5], step2[10]); + out[11] = _mm256_sub_epi16(step2[4], step2[11]); + out[12] = _mm256_sub_epi16(step2[3], step2[12]); + out[13] = _mm256_sub_epi16(step2[2], step2[13]); + out[14] = _mm256_sub_epi16(step2[1], step1[14]); + out[15] = _mm256_sub_epi16(step2[0], step1[15]); +} + +static INLINE void recon_and_store16(uint8_t *dest, __m256i in_x) { + const __m256i zero = _mm256_setzero_si256(); + __m256i d0 = _mm256_castsi128_si256(_mm_loadu_si128((__m128i *)(dest))); + d0 = _mm256_permute4x64_epi64(d0, 0xd8); + d0 = _mm256_unpacklo_epi8(d0, zero); + d0 = _mm256_add_epi16(in_x, d0); + d0 = _mm256_packus_epi16( + d0, _mm256_castsi128_si256(_mm256_extractf128_si256(d0, 1))); + + _mm_storeu_si128((__m128i *)dest, _mm256_castsi256_si128(d0)); +} + +static INLINE void write_buffer_16x1(uint8_t *dest, __m256i in) { + const __m256i final_rounding = _mm256_set1_epi16(1 << 5); + __m256i out; + out = _mm256_adds_epi16(in, final_rounding); + out = _mm256_srai_epi16(out, 6); + recon_and_store16(dest, out); +} + +static INLINE void store_buffer_16x32(__m256i *in, uint8_t *dst, int stride) { + const __m256i final_rounding = _mm256_set1_epi16(1 << 5); + int j = 0; + while (j < 32) { + in[j] = _mm256_adds_epi16(in[j], final_rounding); + in[j + 1] = _mm256_adds_epi16(in[j + 1], final_rounding); + + in[j] = _mm256_srai_epi16(in[j], 6); + in[j + 1] = _mm256_srai_epi16(in[j + 1], 6); + + recon_and_store16(dst, in[j]); + dst += stride; + recon_and_store16(dst, in[j + 1]); + dst += stride; + j += 2; + } +} + +static INLINE void transpose2_8x8_avx2(__m256i *in, __m256i *out) { + int i; + __m256i t[16], u[16]; + // (1st, 2nd) ==> (lo, hi) + // (0, 1) ==> (0, 1) + // (2, 3) ==> (2, 3) + // (4, 5) ==> (4, 5) + // (6, 7) ==> (6, 7) + for (i = 0; i < 4; i++) { + t[2 * i] = _mm256_unpacklo_epi16(in[2 * i], in[2 * i + 1]); + t[2 * i + 1] = _mm256_unpackhi_epi16(in[2 * i], in[2 * i + 1]); + } + + // (1st, 2nd) ==> (lo, hi) + // (0, 2) ==> (0, 2) + // (1, 3) ==> (1, 3) + // (4, 6) ==> (4, 6) + // (5, 7) ==> (5, 7) + for (i = 0; i < 2; i++) { + u[i] = _mm256_unpacklo_epi32(t[i], t[i + 2]); + u[i + 2] = _mm256_unpackhi_epi32(t[i], t[i + 2]); + + u[i + 4] = _mm256_unpacklo_epi32(t[i + 4], t[i + 6]); + u[i + 6] = _mm256_unpackhi_epi32(t[i + 4], t[i + 6]); + } + + // (1st, 2nd) ==> (lo, hi) + // (0, 4) ==> (0, 1) + // (1, 5) ==> (4, 5) + // (2, 6) ==> (2, 3) + // (3, 7) ==> (6, 7) + for (i = 0; i < 2; i++) { + out[2 * i] = _mm256_unpacklo_epi64(u[2 * i], u[2 * i + 4]); + out[2 * i + 1] = _mm256_unpackhi_epi64(u[2 * i], u[2 * i + 4]); + + out[2 * i + 4] = _mm256_unpacklo_epi64(u[2 * i + 1], u[2 * i + 5]); + out[2 * i + 5] = _mm256_unpackhi_epi64(u[2 * i + 1], u[2 * i + 5]); + } +} + +static INLINE void transpose_16bit_16x16_avx2(__m256i *in, __m256i *out) { + __m256i t[16]; + +#define LOADL(idx) \ + t[idx] = _mm256_castsi128_si256(_mm_load_si128((__m128i const *)&in[idx])); \ + t[idx] = _mm256_inserti128_si256( \ + t[idx], _mm_load_si128((__m128i const *)&in[(idx) + 8]), 1); + +#define LOADR(idx) \ + t[8 + (idx)] = \ + _mm256_castsi128_si256(_mm_load_si128((__m128i const *)&in[idx] + 1)); \ + t[8 + (idx)] = _mm256_inserti128_si256( \ + t[8 + (idx)], _mm_load_si128((__m128i const *)&in[(idx) + 8] + 1), 1); + + // load left 8x16 + LOADL(0) + LOADL(1) + LOADL(2) + LOADL(3) + LOADL(4) + LOADL(5) + LOADL(6) + LOADL(7) + + // load right 8x16 + LOADR(0) + LOADR(1) + LOADR(2) + LOADR(3) + LOADR(4) + LOADR(5) + LOADR(6) + LOADR(7) + + // get the top 16x8 result + transpose2_8x8_avx2(t, out); + // get the bottom 16x8 result + transpose2_8x8_avx2(&t[8], &out[8]); +} + +void vpx_idct16x16_256_add_avx2(const tran_low_t *input, uint8_t *dest, + int stride) { + int i; + __m256i in[16]; + + // Load 16x16 values + idct_load16x16(input, in, 16); + + transpose_16bit_16x16_avx2(in, in); + idct16_16col(in, in); + + transpose_16bit_16x16_avx2(in, in); + idct16_16col(in, in); + + for (i = 0; i < 16; ++i) { + write_buffer_16x1(dest + i * stride, in[i]); + } +} + +// Only do addition and subtraction butterfly, size = 16, 32 +static INLINE void add_sub_butterfly_avx2(__m256i *in, __m256i *out, int size) { + int i = 0; + const int num = size >> 1; + const int bound = size - 1; + while (i < num) { + out[i] = _mm256_add_epi16(in[i], in[bound - i]); + out[bound - i] = _mm256_sub_epi16(in[i], in[bound - i]); + i++; + } +} + +// For each 16x32 block __m256i in[32], +// Input with index, 0, 4, 8, 12, 16, 20, 24, 28 +// output pixels: 0-7 in __m256i out[32] +static INLINE void idct32_1024_16x32_quarter_1(__m256i *in, __m256i *out) { + __m256i step1[8], step2[8]; + + // stage 3 + butterfly16(in[4], in[28], cospi_28_64, cospi_4_64, &step1[4], &step1[7]); + butterfly16(in[20], in[12], cospi_12_64, cospi_20_64, &step1[5], &step1[6]); + + // stage 4 + butterfly16(in[0], in[16], cospi_16_64, cospi_16_64, &step2[1], &step2[0]); + butterfly16(in[8], in[24], cospi_24_64, cospi_8_64, &step2[2], &step2[3]); + step2[4] = _mm256_add_epi16(step1[4], step1[5]); + step2[5] = _mm256_sub_epi16(step1[4], step1[5]); + step2[6] = _mm256_sub_epi16(step1[7], step1[6]); + step2[7] = _mm256_add_epi16(step1[7], step1[6]); + + // stage 5 + step1[0] = _mm256_add_epi16(step2[0], step2[3]); + step1[1] = _mm256_add_epi16(step2[1], step2[2]); + step1[2] = _mm256_sub_epi16(step2[1], step2[2]); + step1[3] = _mm256_sub_epi16(step2[0], step2[3]); + step1[4] = step2[4]; + butterfly16(step2[6], step2[5], cospi_16_64, cospi_16_64, &step1[5], + &step1[6]); + step1[7] = step2[7]; + + // stage 6 + out[0] = _mm256_add_epi16(step1[0], step1[7]); + out[1] = _mm256_add_epi16(step1[1], step1[6]); + out[2] = _mm256_add_epi16(step1[2], step1[5]); + out[3] = _mm256_add_epi16(step1[3], step1[4]); + out[4] = _mm256_sub_epi16(step1[3], step1[4]); + out[5] = _mm256_sub_epi16(step1[2], step1[5]); + out[6] = _mm256_sub_epi16(step1[1], step1[6]); + out[7] = _mm256_sub_epi16(step1[0], step1[7]); +} + +static INLINE void idct32_16x32_quarter_2_stage_4_to_6(__m256i *step1, + __m256i *out) { + __m256i step2[32]; + + // stage 4 + step2[8] = step1[8]; + step2[15] = step1[15]; + butterfly16(step1[14], step1[9], cospi_24_64, cospi_8_64, &step2[9], + &step2[14]); + butterfly16(step1[13], step1[10], -cospi_8_64, cospi_24_64, &step2[10], + &step2[13]); + step2[11] = step1[11]; + step2[12] = step1[12]; + + // stage 5 + step1[8] = _mm256_add_epi16(step2[8], step2[11]); + step1[9] = _mm256_add_epi16(step2[9], step2[10]); + step1[10] = _mm256_sub_epi16(step2[9], step2[10]); + step1[11] = _mm256_sub_epi16(step2[8], step2[11]); + step1[12] = _mm256_sub_epi16(step2[15], step2[12]); + step1[13] = _mm256_sub_epi16(step2[14], step2[13]); + step1[14] = _mm256_add_epi16(step2[14], step2[13]); + step1[15] = _mm256_add_epi16(step2[15], step2[12]); + + // stage 6 + out[8] = step1[8]; + out[9] = step1[9]; + butterfly16(step1[13], step1[10], cospi_16_64, cospi_16_64, &out[10], + &out[13]); + butterfly16(step1[12], step1[11], cospi_16_64, cospi_16_64, &out[11], + &out[12]); + out[14] = step1[14]; + out[15] = step1[15]; +} + +// For each 16x32 block __m256i in[32], +// Input with index, 2, 6, 10, 14, 18, 22, 26, 30 +// output pixels: 8-15 in __m256i out[32] +static INLINE void idct32_1024_16x32_quarter_2(__m256i *in, __m256i *out) { + __m256i step1[16], step2[16]; + + // stage 2 + butterfly16(in[2], in[30], cospi_30_64, cospi_2_64, &step2[8], &step2[15]); + butterfly16(in[18], in[14], cospi_14_64, cospi_18_64, &step2[9], &step2[14]); + butterfly16(in[10], in[22], cospi_22_64, cospi_10_64, &step2[10], &step2[13]); + butterfly16(in[26], in[6], cospi_6_64, cospi_26_64, &step2[11], &step2[12]); + + // stage 3 + step1[8] = _mm256_add_epi16(step2[8], step2[9]); + step1[9] = _mm256_sub_epi16(step2[8], step2[9]); + step1[10] = _mm256_sub_epi16(step2[11], step2[10]); + step1[11] = _mm256_add_epi16(step2[11], step2[10]); + step1[12] = _mm256_add_epi16(step2[12], step2[13]); + step1[13] = _mm256_sub_epi16(step2[12], step2[13]); + step1[14] = _mm256_sub_epi16(step2[15], step2[14]); + step1[15] = _mm256_add_epi16(step2[15], step2[14]); + + idct32_16x32_quarter_2_stage_4_to_6(step1, out); +} + +static INLINE void idct32_16x32_quarter_3_4_stage_4_to_7(__m256i *step1, + __m256i *out) { + __m256i step2[32]; + + // stage 4 + step2[16] = _mm256_add_epi16(step1[16], step1[19]); + step2[17] = _mm256_add_epi16(step1[17], step1[18]); + step2[18] = _mm256_sub_epi16(step1[17], step1[18]); + step2[19] = _mm256_sub_epi16(step1[16], step1[19]); + step2[20] = _mm256_sub_epi16(step1[23], step1[20]); + step2[21] = _mm256_sub_epi16(step1[22], step1[21]); + step2[22] = _mm256_add_epi16(step1[22], step1[21]); + step2[23] = _mm256_add_epi16(step1[23], step1[20]); + + step2[24] = _mm256_add_epi16(step1[24], step1[27]); + step2[25] = _mm256_add_epi16(step1[25], step1[26]); + step2[26] = _mm256_sub_epi16(step1[25], step1[26]); + step2[27] = _mm256_sub_epi16(step1[24], step1[27]); + step2[28] = _mm256_sub_epi16(step1[31], step1[28]); + step2[29] = _mm256_sub_epi16(step1[30], step1[29]); + step2[30] = _mm256_add_epi16(step1[29], step1[30]); + step2[31] = _mm256_add_epi16(step1[28], step1[31]); + + // stage 5 + step1[16] = step2[16]; + step1[17] = step2[17]; + butterfly16(step2[29], step2[18], cospi_24_64, cospi_8_64, &step1[18], + &step1[29]); + butterfly16(step2[28], step2[19], cospi_24_64, cospi_8_64, &step1[19], + &step1[28]); + butterfly16(step2[27], step2[20], -cospi_8_64, cospi_24_64, &step1[20], + &step1[27]); + butterfly16(step2[26], step2[21], -cospi_8_64, cospi_24_64, &step1[21], + &step1[26]); + step1[22] = step2[22]; + step1[23] = step2[23]; + step1[24] = step2[24]; + step1[25] = step2[25]; + step1[30] = step2[30]; + step1[31] = step2[31]; + + // stage 6 + out[16] = _mm256_add_epi16(step1[16], step1[23]); + out[17] = _mm256_add_epi16(step1[17], step1[22]); + out[18] = _mm256_add_epi16(step1[18], step1[21]); + out[19] = _mm256_add_epi16(step1[19], step1[20]); + step2[20] = _mm256_sub_epi16(step1[19], step1[20]); + step2[21] = _mm256_sub_epi16(step1[18], step1[21]); + step2[22] = _mm256_sub_epi16(step1[17], step1[22]); + step2[23] = _mm256_sub_epi16(step1[16], step1[23]); + + step2[24] = _mm256_sub_epi16(step1[31], step1[24]); + step2[25] = _mm256_sub_epi16(step1[30], step1[25]); + step2[26] = _mm256_sub_epi16(step1[29], step1[26]); + step2[27] = _mm256_sub_epi16(step1[28], step1[27]); + out[28] = _mm256_add_epi16(step1[27], step1[28]); + out[29] = _mm256_add_epi16(step1[26], step1[29]); + out[30] = _mm256_add_epi16(step1[25], step1[30]); + out[31] = _mm256_add_epi16(step1[24], step1[31]); + + // stage 7 + butterfly16(step2[27], step2[20], cospi_16_64, cospi_16_64, &out[20], + &out[27]); + butterfly16(step2[26], step2[21], cospi_16_64, cospi_16_64, &out[21], + &out[26]); + butterfly16(step2[25], step2[22], cospi_16_64, cospi_16_64, &out[22], + &out[25]); + butterfly16(step2[24], step2[23], cospi_16_64, cospi_16_64, &out[23], + &out[24]); +} + +static INLINE void idct32_1024_16x32_quarter_1_2(__m256i *in, __m256i *out) { + __m256i temp[16]; + + // For each 16x32 block __m256i in[32], + // Input with index, 0, 4, 8, 12, 16, 20, 24, 28 + // output pixels: 0-7 in __m256i out[32] + idct32_1024_16x32_quarter_1(in, temp); + + // Input with index, 2, 6, 10, 14, 18, 22, 26, 30 + // output pixels: 8-15 in __m256i out[32] + idct32_1024_16x32_quarter_2(in, temp); + + // stage 7 + add_sub_butterfly_avx2(temp, out, 16); +} + +// For each 16x32 block __m256i in[32], +// Input with odd index, +// 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31 +// output pixels: 16-23, 24-31 in __m256i out[32] +static INLINE void idct32_1024_16x32_quarter_3_4(__m256i *in, __m256i *out) { + __m256i step1[32], step2[32]; + + // stage 1 + butterfly16(in[1], in[31], cospi_31_64, cospi_1_64, &step1[16], &step1[31]); + butterfly16(in[17], in[15], cospi_15_64, cospi_17_64, &step1[17], &step1[30]); + butterfly16(in[9], in[23], cospi_23_64, cospi_9_64, &step1[18], &step1[29]); + butterfly16(in[25], in[7], cospi_7_64, cospi_25_64, &step1[19], &step1[28]); + + butterfly16(in[5], in[27], cospi_27_64, cospi_5_64, &step1[20], &step1[27]); + butterfly16(in[21], in[11], cospi_11_64, cospi_21_64, &step1[21], &step1[26]); + + butterfly16(in[13], in[19], cospi_19_64, cospi_13_64, &step1[22], &step1[25]); + butterfly16(in[29], in[3], cospi_3_64, cospi_29_64, &step1[23], &step1[24]); + + // stage 2 + step2[16] = _mm256_add_epi16(step1[16], step1[17]); + step2[17] = _mm256_sub_epi16(step1[16], step1[17]); + step2[18] = _mm256_sub_epi16(step1[19], step1[18]); + step2[19] = _mm256_add_epi16(step1[19], step1[18]); + step2[20] = _mm256_add_epi16(step1[20], step1[21]); + step2[21] = _mm256_sub_epi16(step1[20], step1[21]); + step2[22] = _mm256_sub_epi16(step1[23], step1[22]); + step2[23] = _mm256_add_epi16(step1[23], step1[22]); + + step2[24] = _mm256_add_epi16(step1[24], step1[25]); + step2[25] = _mm256_sub_epi16(step1[24], step1[25]); + step2[26] = _mm256_sub_epi16(step1[27], step1[26]); + step2[27] = _mm256_add_epi16(step1[27], step1[26]); + step2[28] = _mm256_add_epi16(step1[28], step1[29]); + step2[29] = _mm256_sub_epi16(step1[28], step1[29]); + step2[30] = _mm256_sub_epi16(step1[31], step1[30]); + step2[31] = _mm256_add_epi16(step1[31], step1[30]); + + // stage 3 + step1[16] = step2[16]; + step1[31] = step2[31]; + butterfly16(step2[30], step2[17], cospi_28_64, cospi_4_64, &step1[17], + &step1[30]); + butterfly16(step2[29], step2[18], -cospi_4_64, cospi_28_64, &step1[18], + &step1[29]); + step1[19] = step2[19]; + step1[20] = step2[20]; + butterfly16(step2[26], step2[21], cospi_12_64, cospi_20_64, &step1[21], + &step1[26]); + butterfly16(step2[25], step2[22], -cospi_20_64, cospi_12_64, &step1[22], + &step1[25]); + step1[23] = step2[23]; + step1[24] = step2[24]; + step1[27] = step2[27]; + step1[28] = step2[28]; + + idct32_16x32_quarter_3_4_stage_4_to_7(step1, out); +} + +static INLINE void idct32_1024_16x32(__m256i *in, __m256i *out) { + __m256i temp[32]; + + // For each 16x32 block __m256i in[32], + // Input with index, 0, 4, 8, 12, 16, 20, 24, 28 + // output pixels: 0-7 in __m256i out[32] + // AND + // Input with index, 2, 6, 10, 14, 18, 22, 26, 30 + // output pixels: 8-15 in __m256i out[32] + idct32_1024_16x32_quarter_1_2(in, temp); + + // For each 16x32 block __m256i in[32], + // Input with odd index, + // 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31 + // output pixels: 16-23, 24-31 in __m256i out[32] + idct32_1024_16x32_quarter_3_4(in, temp); + + // final stage + add_sub_butterfly_avx2(temp, out, 32); +} + +void vpx_idct32x32_1024_add_avx2(const tran_low_t *input, uint8_t *dest, + int stride) { + __m256i l[32], r[32], out[32], *in; + int i; + + in = l; + + for (i = 0; i < 2; i++) { + idct_load16x16(input, in, 32); + transpose_16bit_16x16_avx2(in, in); + + idct_load16x16(input + 16, in + 16, 32); + transpose_16bit_16x16_avx2(in + 16, in + 16); + idct32_1024_16x32(in, in); + + in = r; + input += 32 << 4; + } + + for (i = 0; i < 32; i += 16) { + transpose_16bit_16x16_avx2(l + i, out); + transpose_16bit_16x16_avx2(r + i, out + 16); + idct32_1024_16x32(out, out); + + store_buffer_16x32(out, dest, stride); + dest += 16; + } +} + +// Case when only upper-left 16x16 has non-zero coeff +void vpx_idct32x32_135_add_avx2(const tran_low_t *input, uint8_t *dest, + int stride) { + __m256i in[32], io[32], out[32]; + int i; + + for (i = 16; i < 32; i++) { + in[i] = _mm256_setzero_si256(); + } + + // rows + idct_load16x16(input, in, 32); + transpose_16bit_16x16_avx2(in, in); + idct32_1024_16x32(in, io); + + // columns + for (i = 0; i < 32; i += 16) { + transpose_16bit_16x16_avx2(io + i, in); + idct32_1024_16x32(in, out); + + store_buffer_16x32(out, dest, stride); + dest += 16; + } +} diff --git a/libs/libvpx/vpx_dsp/x86/inv_txfm_sse2.c b/libs/libvpx/vpx_dsp/x86/inv_txfm_sse2.c index 4b02da9666..f42b3df849 100644 --- a/libs/libvpx/vpx_dsp/x86/inv_txfm_sse2.c +++ b/libs/libvpx/vpx_dsp/x86/inv_txfm_sse2.c @@ -243,7 +243,7 @@ void iadst8_sse2(__m128i *const in) { const __m128i k__cospi_m24_p08 = pair_set_epi16(-cospi_24_64, cospi_8_64); const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64); const __m128i k__cospi_p16_p16 = _mm_set1_epi16(cospi_16_64); - const __m128i kZero = _mm_set1_epi16(0); + const __m128i kZero = _mm_setzero_si128(); __m128i s[8], u[16], v[8], w[16]; // transpose @@ -546,7 +546,7 @@ void vpx_iadst16_8col_sse2(__m128i *const in) { const __m128i k__cospi_p16_p16 = _mm_set1_epi16(cospi_16_64); const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64); const __m128i k__cospi_m16_p16 = pair_set_epi16(-cospi_16_64, cospi_16_64); - const __m128i kZero = _mm_set1_epi16(0); + const __m128i kZero = _mm_setzero_si128(); u[0] = _mm_unpacklo_epi16(in[15], in[0]); u[1] = _mm_unpackhi_epi16(in[15], in[0]); diff --git a/libs/libvpx/vpx_dsp/x86/loopfilter_avx2.c b/libs/libvpx/vpx_dsp/x86/loopfilter_avx2.c index be391992af..a58fb65539 100644 --- a/libs/libvpx/vpx_dsp/x86/loopfilter_avx2.c +++ b/libs/libvpx/vpx_dsp/x86/loopfilter_avx2.c @@ -18,7 +18,7 @@ void vpx_lpf_horizontal_16_avx2(unsigned char *s, int pitch, const unsigned char *limit, const unsigned char *thresh) { __m128i mask, hev, flat, flat2; - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); const __m128i one = _mm_set1_epi8(1); __m128i q7p7, q6p6, q5p5, q4p4, q3p3, q2p2, q1p1, q0p0, p0q0, p1q1; __m128i abs_p1p0; @@ -372,7 +372,7 @@ void vpx_lpf_horizontal_16_dual_avx2(unsigned char *s, int pitch, const unsigned char *limit, const unsigned char *thresh) { __m128i mask, hev, flat, flat2; - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); const __m128i one = _mm_set1_epi8(1); __m128i p7, p6, p5; __m128i p4, p3, p2, p1, p0, q0, q1, q2, q3, q4; diff --git a/libs/libvpx/vpx_dsp/x86/loopfilter_sse2.c b/libs/libvpx/vpx_dsp/x86/loopfilter_sse2.c index 347c9fdbe9..6ea34cdd16 100644 --- a/libs/libvpx/vpx_dsp/x86/loopfilter_sse2.c +++ b/libs/libvpx/vpx_dsp/x86/loopfilter_sse2.c @@ -106,7 +106,7 @@ static INLINE __m128i abs_diff(__m128i a, __m128i b) { void vpx_lpf_horizontal_4_sse2(uint8_t *s, int pitch, const uint8_t *blimit, const uint8_t *limit, const uint8_t *thresh) { - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); const __m128i limit_v = _mm_unpacklo_epi64(_mm_loadl_epi64((const __m128i *)blimit), _mm_loadl_epi64((const __m128i *)limit)); @@ -140,7 +140,7 @@ void vpx_lpf_horizontal_4_sse2(uint8_t *s, int pitch, const uint8_t *blimit, void vpx_lpf_vertical_4_sse2(uint8_t *s, int pitch, const uint8_t *blimit, const uint8_t *limit, const uint8_t *thresh) { - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); const __m128i limit_v = _mm_unpacklo_epi64(_mm_loadl_epi64((const __m128i *)blimit), _mm_loadl_epi64((const __m128i *)limit)); @@ -232,7 +232,7 @@ void vpx_lpf_horizontal_16_sse2(unsigned char *s, int pitch, const unsigned char *blimit, const unsigned char *limit, const unsigned char *thresh) { - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); const __m128i one = _mm_set1_epi8(1); const __m128i blimit_v = _mm_load_si128((const __m128i *)blimit); const __m128i limit_v = _mm_load_si128((const __m128i *)limit); @@ -594,7 +594,7 @@ void vpx_lpf_horizontal_16_dual_sse2(unsigned char *s, int pitch, const unsigned char *blimit, const unsigned char *limit, const unsigned char *thresh) { - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); const __m128i one = _mm_set1_epi8(1); const __m128i blimit_v = _mm_load_si128((const __m128i *)blimit); const __m128i limit_v = _mm_load_si128((const __m128i *)limit); @@ -932,7 +932,7 @@ void vpx_lpf_horizontal_8_sse2(unsigned char *s, int pitch, DECLARE_ALIGNED(16, unsigned char, flat_oq2[16]); DECLARE_ALIGNED(16, unsigned char, flat_oq1[16]); DECLARE_ALIGNED(16, unsigned char, flat_oq0[16]); - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); const __m128i blimit_v = _mm_load_si128((const __m128i *)blimit); const __m128i limit_v = _mm_load_si128((const __m128i *)limit); const __m128i thresh_v = _mm_load_si128((const __m128i *)thresh); @@ -1152,7 +1152,7 @@ void vpx_lpf_horizontal_8_dual_sse2( DECLARE_ALIGNED(16, unsigned char, flat_oq2[16]); DECLARE_ALIGNED(16, unsigned char, flat_oq1[16]); DECLARE_ALIGNED(16, unsigned char, flat_oq0[16]); - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); const __m128i blimit = _mm_unpacklo_epi64(_mm_load_si128((const __m128i *)blimit0), _mm_load_si128((const __m128i *)blimit1)); @@ -1406,7 +1406,7 @@ void vpx_lpf_horizontal_4_dual_sse2(unsigned char *s, int pitch, const __m128i thresh = _mm_unpacklo_epi64(_mm_load_si128((const __m128i *)thresh0), _mm_load_si128((const __m128i *)thresh1)); - const __m128i zero = _mm_set1_epi16(0); + const __m128i zero = _mm_setzero_si128(); __m128i p3, p2, p1, p0, q0, q1, q2, q3; __m128i mask, hev, flat; diff --git a/libs/libvpx/vpx_dsp/x86/mem_sse2.h b/libs/libvpx/vpx_dsp/x86/mem_sse2.h index 8b6d4d1dd4..031f361a41 100644 --- a/libs/libvpx/vpx_dsp/x86/mem_sse2.h +++ b/libs/libvpx/vpx_dsp/x86/mem_sse2.h @@ -27,13 +27,13 @@ static INLINE int32_t loadu_int32(const void *src) { } static INLINE __m128i load_unaligned_u32(const void *a) { - uint32_t val; + int val; memcpy(&val, a, sizeof(val)); return _mm_cvtsi32_si128(val); } static INLINE void store_unaligned_u32(void *const a, const __m128i v) { - const uint32_t val = _mm_cvtsi128_si32(v); + const int val = _mm_cvtsi128_si32(v); memcpy(a, &val, sizeof(val)); } diff --git a/libs/libvpx/vpx_dsp/x86/post_proc_sse2.c b/libs/libvpx/vpx_dsp/x86/post_proc_sse2.c deleted file mode 100644 index d1029afc4f..0000000000 --- a/libs/libvpx/vpx_dsp/x86/post_proc_sse2.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2018 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include -#include - -#include - -#include "./vpx_dsp_rtcd.h" -#include "vpx/vpx_integer.h" -#include "vpx_dsp/x86/mem_sse2.h" - -extern const int16_t vpx_rv[]; - -void vpx_mbpost_proc_down_sse2(unsigned char *dst, int pitch, int rows, - int cols, int flimit) { - int col; - const __m128i zero = _mm_setzero_si128(); - const __m128i f = _mm_set1_epi32(flimit); - DECLARE_ALIGNED(16, int16_t, above_context[8 * 8]); - - // 8 columns are processed at a time. - // If rows is less than 8 the bottom border extension fails. - assert(cols % 8 == 0); - assert(rows >= 8); - - for (col = 0; col < cols; col += 8) { - int row, i; - __m128i s = _mm_loadl_epi64((__m128i *)dst); - __m128i sum, sumsq_0, sumsq_1; - __m128i tmp_0, tmp_1; - __m128i below_context; - - s = _mm_unpacklo_epi8(s, zero); - - for (i = 0; i < 8; ++i) { - _mm_store_si128((__m128i *)above_context + i, s); - } - - // sum *= 9 - sum = _mm_slli_epi16(s, 3); - sum = _mm_add_epi16(s, sum); - - // sum^2 * 9 == (sum * 9) * sum - tmp_0 = _mm_mullo_epi16(sum, s); - tmp_1 = _mm_mulhi_epi16(sum, s); - - sumsq_0 = _mm_unpacklo_epi16(tmp_0, tmp_1); - sumsq_1 = _mm_unpackhi_epi16(tmp_0, tmp_1); - - // Prime sum/sumsq - for (i = 1; i <= 6; ++i) { - __m128i a = _mm_loadl_epi64((__m128i *)(dst + i * pitch)); - a = _mm_unpacklo_epi8(a, zero); - sum = _mm_add_epi16(sum, a); - a = _mm_mullo_epi16(a, a); - sumsq_0 = _mm_add_epi32(sumsq_0, _mm_unpacklo_epi16(a, zero)); - sumsq_1 = _mm_add_epi32(sumsq_1, _mm_unpackhi_epi16(a, zero)); - } - - for (row = 0; row < rows + 8; row++) { - const __m128i above = - _mm_load_si128((__m128i *)above_context + (row & 7)); - __m128i this_row = _mm_loadl_epi64((__m128i *)(dst + row * pitch)); - __m128i above_sq, below_sq; - __m128i mask_0, mask_1; - __m128i multmp_0, multmp_1; - __m128i rv; - __m128i out; - - this_row = _mm_unpacklo_epi8(this_row, zero); - - if (row + 7 < rows) { - // Instead of copying the end context we just stop loading when we get - // to the last one. - below_context = _mm_loadl_epi64((__m128i *)(dst + (row + 7) * pitch)); - below_context = _mm_unpacklo_epi8(below_context, zero); - } - - sum = _mm_sub_epi16(sum, above); - sum = _mm_add_epi16(sum, below_context); - - // context^2 fits in 16 bits. Don't need to mulhi and combine. Just zero - // extend. Unfortunately we can't do below_sq - above_sq in 16 bits - // because x86 does not have unpack with sign extension. - above_sq = _mm_mullo_epi16(above, above); - sumsq_0 = _mm_sub_epi32(sumsq_0, _mm_unpacklo_epi16(above_sq, zero)); - sumsq_1 = _mm_sub_epi32(sumsq_1, _mm_unpackhi_epi16(above_sq, zero)); - - below_sq = _mm_mullo_epi16(below_context, below_context); - sumsq_0 = _mm_add_epi32(sumsq_0, _mm_unpacklo_epi16(below_sq, zero)); - sumsq_1 = _mm_add_epi32(sumsq_1, _mm_unpackhi_epi16(below_sq, zero)); - - // sumsq * 16 - sumsq == sumsq * 15 - mask_0 = _mm_slli_epi32(sumsq_0, 4); - mask_0 = _mm_sub_epi32(mask_0, sumsq_0); - mask_1 = _mm_slli_epi32(sumsq_1, 4); - mask_1 = _mm_sub_epi32(mask_1, sumsq_1); - - multmp_0 = _mm_mullo_epi16(sum, sum); - multmp_1 = _mm_mulhi_epi16(sum, sum); - - mask_0 = _mm_sub_epi32(mask_0, _mm_unpacklo_epi16(multmp_0, multmp_1)); - mask_1 = _mm_sub_epi32(mask_1, _mm_unpackhi_epi16(multmp_0, multmp_1)); - - // mask - f gives a negative value when mask < f - mask_0 = _mm_sub_epi32(mask_0, f); - mask_1 = _mm_sub_epi32(mask_1, f); - - // Shift the sign bit down to create a mask - mask_0 = _mm_srai_epi32(mask_0, 31); - mask_1 = _mm_srai_epi32(mask_1, 31); - - mask_0 = _mm_packs_epi32(mask_0, mask_1); - - rv = _mm_loadu_si128((__m128i const *)(vpx_rv + (row & 127))); - - mask_1 = _mm_add_epi16(rv, sum); - mask_1 = _mm_add_epi16(mask_1, this_row); - mask_1 = _mm_srai_epi16(mask_1, 4); - - mask_1 = _mm_and_si128(mask_0, mask_1); - mask_0 = _mm_andnot_si128(mask_0, this_row); - out = _mm_or_si128(mask_1, mask_0); - - _mm_storel_epi64((__m128i *)(dst + row * pitch), - _mm_packus_epi16(out, zero)); - - _mm_store_si128((__m128i *)above_context + ((row + 8) & 7), this_row); - } - - dst += 8; - } -} diff --git a/libs/libvpx/vpx_dsp/x86/quantize_avx.c b/libs/libvpx/vpx_dsp/x86/quantize_avx.c index 706e4e6413..5ff5abc110 100644 --- a/libs/libvpx/vpx_dsp/x86/quantize_avx.c +++ b/libs/libvpx/vpx_dsp/x86/quantize_avx.c @@ -19,17 +19,18 @@ #include "vpx_dsp/x86/bitdepth_conversion_sse2.h" #include "vpx_dsp/x86/quantize_sse2.h" #include "vpx_dsp/x86/quantize_ssse3.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" void vpx_quantize_b_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, - tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, - uint16_t *eob_ptr, const int16_t *scan, - const int16_t *iscan) { + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { const __m128i zero = _mm_setzero_si128(); const __m256i big_zero = _mm256_setzero_si256(); int index; + const int16_t *iscan = scan_order->iscan; __m128i zbin, round, quant, dequant, shift; __m128i coeff0, coeff1; @@ -38,12 +39,9 @@ void vpx_quantize_b_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, __m128i all_zero; __m128i eob = zero, eob0; - (void)scan; - *eob_ptr = 0; - load_b_values(zbin_ptr, &zbin, round_ptr, &round, quant_ptr, &quant, - dequant_ptr, &dequant, quant_shift_ptr, &shift); + load_b_values(mb_plane, &zbin, &round, &quant, dequant_ptr, &dequant, &shift); // Do DC and first 15 AC. coeff0 = load_tran_low(coeff_ptr); @@ -93,8 +91,7 @@ void vpx_quantize_b_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, dequant = _mm_unpackhi_epi64(dequant, dequant); calculate_dqcoeff_and_store(qcoeff1, dequant, dqcoeff_ptr + 8); - eob = - scan_for_eob(&qcoeff0, &qcoeff1, cmp_mask0, cmp_mask1, iscan, 0, zero); + eob = scan_for_eob(&qcoeff0, &qcoeff1, iscan, 0, zero); } // AC only loop. @@ -134,25 +131,22 @@ void vpx_quantize_b_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, calculate_dqcoeff_and_store(qcoeff0, dequant, dqcoeff_ptr + index); calculate_dqcoeff_and_store(qcoeff1, dequant, dqcoeff_ptr + index + 8); - eob0 = scan_for_eob(&qcoeff0, &qcoeff1, cmp_mask0, cmp_mask1, iscan, index, - zero); + eob0 = scan_for_eob(&qcoeff0, &qcoeff1, iscan, index, zero); eob = _mm_max_epi16(eob, eob0); } *eob_ptr = accumulate_eob(eob); } -void vpx_quantize_b_32x32_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, +void vpx_quantize_b_32x32_avx(const tran_low_t *coeff_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { + const struct ScanOrder *const scan_order) { const __m128i zero = _mm_setzero_si128(); - const __m128i one = _mm_set1_epi16(1); const __m256i big_zero = _mm256_setzero_si256(); int index; + const int16_t *iscan = scan_order->iscan; __m128i zbin, round, quant, dequant, shift; __m128i coeff0, coeff1; @@ -161,27 +155,8 @@ void vpx_quantize_b_32x32_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, __m128i all_zero; __m128i eob = zero, eob0; - (void)scan; - (void)n_coeffs; - - // Setup global values. - // The 32x32 halves zbin and round. - zbin = _mm_load_si128((const __m128i *)zbin_ptr); - // Shift with rounding. - zbin = _mm_add_epi16(zbin, one); - zbin = _mm_srli_epi16(zbin, 1); - // x86 has no "greater *or equal*" comparison. Subtract 1 from zbin so - // it is a strict "greater" comparison. - zbin = _mm_sub_epi16(zbin, one); - - round = _mm_load_si128((const __m128i *)round_ptr); - round = _mm_add_epi16(round, one); - round = _mm_srli_epi16(round, 1); - - quant = _mm_load_si128((const __m128i *)quant_ptr); - dequant = _mm_load_si128((const __m128i *)dequant_ptr); - shift = _mm_load_si128((const __m128i *)quant_shift_ptr); - shift = _mm_slli_epi16(shift, 1); + load_b_values32x32(mb_plane, &zbin, &round, &quant, dequant_ptr, &dequant, + &shift); // Do DC and first 15 AC. coeff0 = load_tran_low(coeff_ptr); @@ -229,8 +204,7 @@ void vpx_quantize_b_32x32_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, dequant = _mm_unpackhi_epi64(dequant, dequant); calculate_dqcoeff_and_store_32x32(qcoeff1, dequant, zero, dqcoeff_ptr + 8); - eob = - scan_for_eob(&qcoeff0, &qcoeff1, cmp_mask0, cmp_mask1, iscan, 0, zero); + eob = scan_for_eob(&qcoeff0, &qcoeff1, iscan, 0, zero); } // AC only loop. @@ -272,8 +246,7 @@ void vpx_quantize_b_32x32_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, calculate_dqcoeff_and_store_32x32(qcoeff1, dequant, zero, dqcoeff_ptr + index + 8); - eob0 = scan_for_eob(&qcoeff0, &qcoeff1, cmp_mask0, cmp_mask1, iscan, index, - zero); + eob0 = scan_for_eob(&qcoeff0, &qcoeff1, iscan, index, zero); eob = _mm_max_epi16(eob, eob0); } diff --git a/libs/libvpx/vpx_dsp/x86/quantize_avx2.c b/libs/libvpx/vpx_dsp/x86/quantize_avx2.c new file mode 100644 index 0000000000..d4872f6bca --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/quantize_avx2.c @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_dsp_rtcd.h" +#include "vpx/vpx_integer.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" + +static VPX_FORCE_INLINE void load_b_values_avx2( + const struct macroblock_plane *mb_plane, __m256i *zbin, __m256i *round, + __m256i *quant, const int16_t *dequant_ptr, __m256i *dequant, + __m256i *shift, int log_scale) { + *zbin = + _mm256_castsi128_si256(_mm_load_si128((const __m128i *)mb_plane->zbin)); + *zbin = _mm256_permute4x64_epi64(*zbin, 0x54); + if (log_scale > 0) { + const __m256i rnd = _mm256_set1_epi16((int16_t)(1 << (log_scale - 1))); + *zbin = _mm256_add_epi16(*zbin, rnd); + *zbin = _mm256_srai_epi16(*zbin, log_scale); + } + // Subtracting 1 here eliminates a _mm256_cmpeq_epi16() instruction when + // calculating the zbin mask. (See quantize_b_logscale{0,1,2}_16) + *zbin = _mm256_sub_epi16(*zbin, _mm256_set1_epi16(1)); + + *round = + _mm256_castsi128_si256(_mm_load_si128((const __m128i *)mb_plane->round)); + *round = _mm256_permute4x64_epi64(*round, 0x54); + if (log_scale > 0) { + const __m256i rnd = _mm256_set1_epi16((int16_t)(1 << (log_scale - 1))); + *round = _mm256_add_epi16(*round, rnd); + *round = _mm256_srai_epi16(*round, log_scale); + } + + *quant = + _mm256_castsi128_si256(_mm_load_si128((const __m128i *)mb_plane->quant)); + *quant = _mm256_permute4x64_epi64(*quant, 0x54); + *dequant = + _mm256_castsi128_si256(_mm_load_si128((const __m128i *)dequant_ptr)); + *dequant = _mm256_permute4x64_epi64(*dequant, 0x54); + *shift = _mm256_castsi128_si256( + _mm_load_si128((const __m128i *)mb_plane->quant_shift)); + *shift = _mm256_permute4x64_epi64(*shift, 0x54); +} + +static VPX_FORCE_INLINE __m256i +load_coefficients_avx2(const tran_low_t *coeff_ptr) { +#if CONFIG_VP9_HIGHBITDEPTH + // typedef int32_t tran_low_t; + const __m256i coeff1 = _mm256_loadu_si256((const __m256i *)coeff_ptr); + const __m256i coeff2 = _mm256_loadu_si256((const __m256i *)(coeff_ptr + 8)); + return _mm256_packs_epi32(coeff1, coeff2); +#else + // typedef int16_t tran_low_t; + return _mm256_loadu_si256((const __m256i *)coeff_ptr); +#endif +} + +static VPX_FORCE_INLINE void store_coefficients_avx2(__m256i coeff_vals, + tran_low_t *coeff_ptr) { +#if CONFIG_VP9_HIGHBITDEPTH + // typedef int32_t tran_low_t; + __m256i coeff_sign = _mm256_srai_epi16(coeff_vals, 15); + __m256i coeff_vals_lo = _mm256_unpacklo_epi16(coeff_vals, coeff_sign); + __m256i coeff_vals_hi = _mm256_unpackhi_epi16(coeff_vals, coeff_sign); + _mm256_storeu_si256((__m256i *)coeff_ptr, coeff_vals_lo); + _mm256_storeu_si256((__m256i *)(coeff_ptr + 8), coeff_vals_hi); +#else + // typedef int16_t tran_low_t; + _mm256_storeu_si256((__m256i *)coeff_ptr, coeff_vals); +#endif +} + +static VPX_FORCE_INLINE __m256i +quantize_b_16(const tran_low_t *coeff_ptr, tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, __m256i *v_quant, __m256i *v_dequant, + __m256i *v_round, __m256i *v_zbin, __m256i *v_quant_shift) { + const __m256i v_coeff = load_coefficients_avx2(coeff_ptr); + const __m256i v_abs_coeff = _mm256_abs_epi16(v_coeff); + const __m256i v_zbin_mask = _mm256_cmpgt_epi16(v_abs_coeff, *v_zbin); + + if (_mm256_movemask_epi8(v_zbin_mask) == 0) { + _mm256_storeu_si256((__m256i *)qcoeff_ptr, _mm256_setzero_si256()); + _mm256_storeu_si256((__m256i *)dqcoeff_ptr, _mm256_setzero_si256()); +#if CONFIG_VP9_HIGHBITDEPTH + _mm256_store_si256((__m256i *)(qcoeff_ptr + 8), _mm256_setzero_si256()); + _mm256_store_si256((__m256i *)(dqcoeff_ptr + 8), _mm256_setzero_si256()); +#endif // CONFIG_VP9_HIGHBITDEPTH + return _mm256_setzero_si256(); + } + { + // tmp = v_zbin_mask ? (int64_t)abs_coeff + log_scaled_round : 0 + const __m256i v_tmp_rnd = + _mm256_and_si256(_mm256_adds_epi16(v_abs_coeff, *v_round), v_zbin_mask); + + const __m256i v_tmp32_a = _mm256_mulhi_epi16(v_tmp_rnd, *v_quant); + const __m256i v_tmp32_b = _mm256_add_epi16(v_tmp32_a, v_tmp_rnd); + const __m256i v_tmp32 = _mm256_mulhi_epi16(v_tmp32_b, *v_quant_shift); + const __m256i v_nz_mask = + _mm256_cmpgt_epi16(v_tmp32, _mm256_setzero_si256()); + const __m256i v_qcoeff = _mm256_sign_epi16(v_tmp32, v_coeff); +#if CONFIG_VP9_HIGHBITDEPTH + const __m256i low = _mm256_mullo_epi16(v_qcoeff, *v_dequant); + const __m256i high = _mm256_mulhi_epi16(v_qcoeff, *v_dequant); + + const __m256i v_dqcoeff_lo = _mm256_unpacklo_epi16(low, high); + const __m256i v_dqcoeff_hi = _mm256_unpackhi_epi16(low, high); +#else + const __m256i v_dqcoeff = _mm256_mullo_epi16(v_qcoeff, *v_dequant); +#endif + + store_coefficients_avx2(v_qcoeff, qcoeff_ptr); +#if CONFIG_VP9_HIGHBITDEPTH + _mm256_storeu_si256((__m256i *)(dqcoeff_ptr), v_dqcoeff_lo); + _mm256_storeu_si256((__m256i *)(dqcoeff_ptr + 8), v_dqcoeff_hi); +#else + store_coefficients_avx2(v_dqcoeff, dqcoeff_ptr); +#endif + return v_nz_mask; + } +} + +static VPX_FORCE_INLINE __m256i get_max_lane_eob(const int16_t *iscan, + __m256i v_eobmax, + __m256i v_mask) { +#if CONFIG_VP9_HIGHBITDEPTH + const __m256i v_iscan = _mm256_permute4x64_epi64( + _mm256_loadu_si256((const __m256i *)iscan), 0xD8); +#else + const __m256i v_iscan = _mm256_loadu_si256((const __m256i *)iscan); +#endif + const __m256i v_nz_iscan = _mm256_and_si256(v_iscan, v_mask); + return _mm256_max_epi16(v_eobmax, v_nz_iscan); +} + +static VPX_FORCE_INLINE int16_t accumulate_eob256(__m256i eob256) { + const __m128i eob_lo = _mm256_castsi256_si128(eob256); + const __m128i eob_hi = _mm256_extractf128_si256(eob256, 1); + __m128i eob = _mm_max_epi16(eob_lo, eob_hi); + __m128i eob_shuffled = _mm_shuffle_epi32(eob, 0xe); + eob = _mm_max_epi16(eob, eob_shuffled); + eob_shuffled = _mm_shufflelo_epi16(eob, 0xe); + eob = _mm_max_epi16(eob, eob_shuffled); + eob_shuffled = _mm_shufflelo_epi16(eob, 0x1); + eob = _mm_max_epi16(eob, eob_shuffled); + return _mm_extract_epi16(eob, 1); +} + +void vpx_quantize_b_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + __m256i v_zbin, v_round, v_quant, v_dequant, v_quant_shift, v_nz_mask; + __m256i v_eobmax = _mm256_setzero_si256(); + intptr_t count; + const int16_t *iscan = scan_order->iscan; + + load_b_values_avx2(mb_plane, &v_zbin, &v_round, &v_quant, dequant_ptr, + &v_dequant, &v_quant_shift, 0); + // Do DC and first 15 AC. + v_nz_mask = quantize_b_16(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, &v_quant, + &v_dequant, &v_round, &v_zbin, &v_quant_shift); + + v_eobmax = get_max_lane_eob(iscan, v_eobmax, v_nz_mask); + + v_round = _mm256_unpackhi_epi64(v_round, v_round); + v_quant = _mm256_unpackhi_epi64(v_quant, v_quant); + v_dequant = _mm256_unpackhi_epi64(v_dequant, v_dequant); + v_quant_shift = _mm256_unpackhi_epi64(v_quant_shift, v_quant_shift); + v_zbin = _mm256_unpackhi_epi64(v_zbin, v_zbin); + + for (count = n_coeffs - 16; count > 0; count -= 16) { + coeff_ptr += 16; + qcoeff_ptr += 16; + dqcoeff_ptr += 16; + iscan += 16; + v_nz_mask = quantize_b_16(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, &v_quant, + &v_dequant, &v_round, &v_zbin, &v_quant_shift); + + v_eobmax = get_max_lane_eob(iscan, v_eobmax, v_nz_mask); + } + + *eob_ptr = accumulate_eob256(v_eobmax); +} + +static VPX_FORCE_INLINE __m256i quantize_b_32x32_16( + const tran_low_t *coeff_ptr, tran_low_t *qcoeff_ptr, + tran_low_t *dqcoeff_ptr, const int16_t *iscan, __m256i *v_quant, + __m256i *v_dequant, __m256i *v_round, __m256i *v_zbin, + __m256i *v_quant_shift, __m256i *v_eobmax) { + const __m256i v_coeff = load_coefficients_avx2(coeff_ptr); + const __m256i v_abs_coeff = _mm256_abs_epi16(v_coeff); + const __m256i v_zbin_mask = _mm256_cmpgt_epi16(v_abs_coeff, *v_zbin); + + if (_mm256_movemask_epi8(v_zbin_mask) == 0) { + _mm256_store_si256((__m256i *)qcoeff_ptr, _mm256_setzero_si256()); + _mm256_store_si256((__m256i *)dqcoeff_ptr, _mm256_setzero_si256()); +#if CONFIG_VP9_HIGHBITDEPTH + _mm256_store_si256((__m256i *)(qcoeff_ptr + 8), _mm256_setzero_si256()); + _mm256_store_si256((__m256i *)(dqcoeff_ptr + 8), _mm256_setzero_si256()); +#endif + return *v_eobmax; + } + { + // tmp = v_zbin_mask ? (int64_t)abs_coeff + round : 0 + const __m256i v_tmp_rnd = + _mm256_and_si256(_mm256_adds_epi16(v_abs_coeff, *v_round), v_zbin_mask); + // tmp32 = (int)(((((tmp * quant_ptr[rc != 0]) >> 16) + tmp) * + // quant_shift_ptr[rc != 0]) >> 15); + const __m256i v_tmp32_a = _mm256_mulhi_epi16(v_tmp_rnd, *v_quant); + const __m256i v_tmp32_b = _mm256_add_epi16(v_tmp32_a, v_tmp_rnd); + const __m256i v_tmp32_hi = + _mm256_slli_epi16(_mm256_mulhi_epi16(v_tmp32_b, *v_quant_shift), 1); + const __m256i v_tmp32_lo = + _mm256_srli_epi16(_mm256_mullo_epi16(v_tmp32_b, *v_quant_shift), 15); + const __m256i v_tmp32 = _mm256_or_si256(v_tmp32_hi, v_tmp32_lo); + const __m256i v_qcoeff = _mm256_sign_epi16(v_tmp32, v_coeff); + const __m256i v_sign_lo = + _mm256_unpacklo_epi16(_mm256_setzero_si256(), v_coeff); + const __m256i v_sign_hi = + _mm256_unpackhi_epi16(_mm256_setzero_si256(), v_coeff); + const __m256i low = _mm256_mullo_epi16(v_tmp32, *v_dequant); + const __m256i high = _mm256_mulhi_epi16(v_tmp32, *v_dequant); + const __m256i v_dqcoeff_lo = _mm256_sign_epi32( + _mm256_srli_epi32(_mm256_unpacklo_epi16(low, high), 1), v_sign_lo); + const __m256i v_dqcoeff_hi = _mm256_sign_epi32( + _mm256_srli_epi32(_mm256_unpackhi_epi16(low, high), 1), v_sign_hi); + const __m256i v_nz_mask = + _mm256_cmpgt_epi16(v_tmp32, _mm256_setzero_si256()); + + store_coefficients_avx2(v_qcoeff, qcoeff_ptr); + +#if CONFIG_VP9_HIGHBITDEPTH + _mm256_storeu_si256((__m256i *)(dqcoeff_ptr), v_dqcoeff_lo); + _mm256_storeu_si256((__m256i *)(dqcoeff_ptr + 8), v_dqcoeff_hi); +#else + store_coefficients_avx2(_mm256_packs_epi32(v_dqcoeff_lo, v_dqcoeff_hi), + dqcoeff_ptr); +#endif + + return get_max_lane_eob(iscan, *v_eobmax, v_nz_mask); + } +} + +void vpx_quantize_b_32x32_avx2(const tran_low_t *coeff_ptr, + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { + __m256i v_zbin, v_round, v_quant, v_dequant, v_quant_shift; + __m256i v_eobmax = _mm256_setzero_si256(); + intptr_t count; + const int16_t *iscan = scan_order->iscan; + + load_b_values_avx2(mb_plane, &v_zbin, &v_round, &v_quant, dequant_ptr, + &v_dequant, &v_quant_shift, 1); + + // Do DC and first 15 AC. + v_eobmax = quantize_b_32x32_16(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, iscan, + &v_quant, &v_dequant, &v_round, &v_zbin, + &v_quant_shift, &v_eobmax); + + v_round = _mm256_unpackhi_epi64(v_round, v_round); + v_quant = _mm256_unpackhi_epi64(v_quant, v_quant); + v_dequant = _mm256_unpackhi_epi64(v_dequant, v_dequant); + v_quant_shift = _mm256_unpackhi_epi64(v_quant_shift, v_quant_shift); + v_zbin = _mm256_unpackhi_epi64(v_zbin, v_zbin); + + for (count = (32 * 32) - 16; count > 0; count -= 16) { + coeff_ptr += 16; + qcoeff_ptr += 16; + dqcoeff_ptr += 16; + iscan += 16; + v_eobmax = quantize_b_32x32_16(coeff_ptr, qcoeff_ptr, dqcoeff_ptr, iscan, + &v_quant, &v_dequant, &v_round, &v_zbin, + &v_quant_shift, &v_eobmax); + } + + *eob_ptr = accumulate_eob256(v_eobmax); +} diff --git a/libs/libvpx/vpx_dsp/x86/quantize_sse2.c b/libs/libvpx/vpx_dsp/x86/quantize_sse2.c index 459d95f28b..64838eaa7d 100644 --- a/libs/libvpx/vpx_dsp/x86/quantize_sse2.c +++ b/libs/libvpx/vpx_dsp/x86/quantize_sse2.c @@ -16,16 +16,16 @@ #include "vpx/vpx_integer.h" #include "vpx_dsp/x86/bitdepth_conversion_sse2.h" #include "vpx_dsp/x86/quantize_sse2.h" +#include "vp9/common/vp9_scan.h" void vpx_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, - tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, - uint16_t *eob_ptr, const int16_t *scan, - const int16_t *iscan) { + const struct macroblock_plane *const mb_plane, + tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, + const int16_t *dequant_ptr, uint16_t *eob_ptr, + const struct ScanOrder *const scan_order) { const __m128i zero = _mm_setzero_si128(); int index = 16; + const int16_t *iscan = scan_order->iscan; __m128i zbin, round, quant, dequant, shift; __m128i coeff0, coeff1, coeff0_sign, coeff1_sign; @@ -33,11 +33,8 @@ void vpx_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, __m128i cmp_mask0, cmp_mask1; __m128i eob, eob0; - (void)scan; - // Setup global values. - load_b_values(zbin_ptr, &zbin, round_ptr, &round, quant_ptr, &quant, - dequant_ptr, &dequant, quant_shift_ptr, &shift); + load_b_values(mb_plane, &zbin, &round, &quant, dequant_ptr, &dequant, &shift); // Do DC and first 15 AC. coeff0 = load_tran_low(coeff_ptr); @@ -76,7 +73,7 @@ void vpx_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, dequant = _mm_unpackhi_epi64(dequant, dequant); calculate_dqcoeff_and_store(qcoeff1, dequant, dqcoeff_ptr + 8); - eob = scan_for_eob(&qcoeff0, &qcoeff1, cmp_mask0, cmp_mask1, iscan, 0, zero); + eob = scan_for_eob(&qcoeff0, &qcoeff1, iscan, 0, zero); // AC only loop. while (index < n_coeffs) { @@ -106,8 +103,7 @@ void vpx_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, calculate_dqcoeff_and_store(qcoeff0, dequant, dqcoeff_ptr + index); calculate_dqcoeff_and_store(qcoeff1, dequant, dqcoeff_ptr + index + 8); - eob0 = scan_for_eob(&qcoeff0, &qcoeff1, cmp_mask0, cmp_mask1, iscan, index, - zero); + eob0 = scan_for_eob(&qcoeff0, &qcoeff1, iscan, index, zero); eob = _mm_max_epi16(eob, eob0); index += 16; diff --git a/libs/libvpx/vpx_dsp/x86/quantize_sse2.h b/libs/libvpx/vpx_dsp/x86/quantize_sse2.h index afe2f924b3..82c755a0cf 100644 --- a/libs/libvpx/vpx_dsp/x86/quantize_sse2.h +++ b/libs/libvpx/vpx_dsp/x86/quantize_sse2.h @@ -15,18 +15,54 @@ #include "./vpx_config.h" #include "vpx/vpx_integer.h" +#include "vp9/encoder/vp9_block.h" -static INLINE void load_b_values(const int16_t *zbin_ptr, __m128i *zbin, - const int16_t *round_ptr, __m128i *round, - const int16_t *quant_ptr, __m128i *quant, +static INLINE void load_b_values(const struct macroblock_plane *const mb_plane, + __m128i *zbin, __m128i *round, __m128i *quant, const int16_t *dequant_ptr, __m128i *dequant, - const int16_t *shift_ptr, __m128i *shift) { - *zbin = _mm_load_si128((const __m128i *)zbin_ptr); - *round = _mm_load_si128((const __m128i *)round_ptr); - *quant = _mm_load_si128((const __m128i *)quant_ptr); + __m128i *shift) { + *zbin = _mm_load_si128((const __m128i *)mb_plane->zbin); + *round = _mm_load_si128((const __m128i *)mb_plane->round); + *quant = _mm_load_si128((const __m128i *)mb_plane->quant); *zbin = _mm_sub_epi16(*zbin, _mm_set1_epi16(1)); *dequant = _mm_load_si128((const __m128i *)dequant_ptr); - *shift = _mm_load_si128((const __m128i *)shift_ptr); + *shift = _mm_load_si128((const __m128i *)mb_plane->quant_shift); +} + +static INLINE void load_b_values32x32( + const struct macroblock_plane *const mb_plane, __m128i *zbin, + __m128i *round, __m128i *quant, const int16_t *dequant_ptr, + __m128i *dequant, __m128i *shift) { + const __m128i one = _mm_set1_epi16(1); + // The 32x32 halves zbin and round. + *zbin = _mm_load_si128((const __m128i *)mb_plane->zbin); + // Shift with rounding. + *zbin = _mm_add_epi16(*zbin, one); + *zbin = _mm_srli_epi16(*zbin, 1); + // x86 has no "greater *or equal*" comparison. Subtract 1 from zbin so + // it is a strict "greater" comparison. + *zbin = _mm_sub_epi16(*zbin, one); + + *round = _mm_load_si128((const __m128i *)mb_plane->round); + *round = _mm_add_epi16(*round, one); + *round = _mm_srli_epi16(*round, 1); + + *quant = _mm_load_si128((const __m128i *)mb_plane->quant); + *dequant = _mm_load_si128((const __m128i *)dequant_ptr); + *shift = _mm_load_si128((const __m128i *)mb_plane->quant_shift); + // I suspect this is not technically OK because quant_shift can be up + // to 1 << 16 and shifting up again will outrange that, but the test is not + // comprehensive enough to catch that and "it's been that way forever" + *shift = _mm_slli_epi16(*shift, 1); +} + +static INLINE void load_fp_values(const struct macroblock_plane *mb_plane, + __m128i *round, __m128i *quant, + const int16_t *dequant_ptr, + __m128i *dequant) { + *round = _mm_load_si128((const __m128i *)mb_plane->round_fp); + *quant = _mm_load_si128((const __m128i *)mb_plane->quant_fp); + *dequant = _mm_load_si128((const __m128i *)dequant_ptr); } // With ssse3 and later abs() and sign() are preferred. @@ -62,11 +98,8 @@ static INLINE void calculate_dqcoeff_and_store(__m128i qcoeff, __m128i dequant, #endif // CONFIG_VP9_HIGHBITDEPTH } -// Scan 16 values for eob reference in scan. Use masks (-1) from comparing to -// zbin to add 1 to the index in 'scan'. +// Scan 16 values for eob reference in scan. static INLINE __m128i scan_for_eob(__m128i *coeff0, __m128i *coeff1, - const __m128i zbin_mask0, - const __m128i zbin_mask1, const int16_t *scan, const int index, const __m128i zero) { const __m128i zero_coeff0 = _mm_cmpeq_epi16(*coeff0, zero); @@ -74,9 +107,6 @@ static INLINE __m128i scan_for_eob(__m128i *coeff0, __m128i *coeff1, __m128i scan0 = _mm_load_si128((const __m128i *)(scan + index)); __m128i scan1 = _mm_load_si128((const __m128i *)(scan + index + 8)); __m128i eob0, eob1; - // Add one to convert from indices to counts - scan0 = _mm_sub_epi16(scan0, zbin_mask0); - scan1 = _mm_sub_epi16(scan1, zbin_mask1); eob0 = _mm_andnot_si128(zero_coeff0, scan0); eob1 = _mm_andnot_si128(zero_coeff1, scan1); return _mm_max_epi16(eob0, eob1); diff --git a/libs/libvpx/vpx_dsp/x86/quantize_ssse3.c b/libs/libvpx/vpx_dsp/x86/quantize_ssse3.c index 9d2a88b7bc..2c6d851a16 100644 --- a/libs/libvpx/vpx_dsp/x86/quantize_ssse3.c +++ b/libs/libvpx/vpx_dsp/x86/quantize_ssse3.c @@ -16,16 +16,17 @@ #include "vpx_dsp/x86/bitdepth_conversion_sse2.h" #include "vpx_dsp/x86/quantize_sse2.h" #include "vpx_dsp/x86/quantize_ssse3.h" +#include "vp9/common/vp9_scan.h" +#include "vp9/encoder/vp9_block.h" void vpx_quantize_b_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { + const struct ScanOrder *const scan_order) { const __m128i zero = _mm_setzero_si128(); int index = 16; + const int16_t *iscan = scan_order->iscan; __m128i zbin, round, quant, dequant, shift; __m128i coeff0, coeff1; @@ -33,10 +34,7 @@ void vpx_quantize_b_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, __m128i cmp_mask0, cmp_mask1; __m128i eob, eob0; - (void)scan; - - load_b_values(zbin_ptr, &zbin, round_ptr, &round, quant_ptr, &quant, - dequant_ptr, &dequant, quant_shift_ptr, &shift); + load_b_values(mb_plane, &zbin, &round, &quant, dequant_ptr, &dequant, &shift); // Do DC and first 15 AC. coeff0 = load_tran_low(coeff_ptr); @@ -70,7 +68,7 @@ void vpx_quantize_b_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, dequant = _mm_unpackhi_epi64(dequant, dequant); calculate_dqcoeff_and_store(qcoeff1, dequant, dqcoeff_ptr + 8); - eob = scan_for_eob(&qcoeff0, &qcoeff1, cmp_mask0, cmp_mask1, iscan, 0, zero); + eob = scan_for_eob(&qcoeff0, &qcoeff1, iscan, 0, zero); // AC only loop. while (index < n_coeffs) { @@ -98,8 +96,7 @@ void vpx_quantize_b_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, calculate_dqcoeff_and_store(qcoeff0, dequant, dqcoeff_ptr + index); calculate_dqcoeff_and_store(qcoeff1, dequant, dqcoeff_ptr + index + 8); - eob0 = scan_for_eob(&qcoeff0, &qcoeff1, cmp_mask0, cmp_mask1, iscan, index, - zero); + eob0 = scan_for_eob(&qcoeff0, &qcoeff1, iscan, index, zero); eob = _mm_max_epi16(eob, eob0); index += 16; @@ -108,17 +105,14 @@ void vpx_quantize_b_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, *eob_ptr = accumulate_eob(eob); } -void vpx_quantize_b_32x32_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, - const int16_t *zbin_ptr, - const int16_t *round_ptr, - const int16_t *quant_ptr, - const int16_t *quant_shift_ptr, +void vpx_quantize_b_32x32_ssse3(const tran_low_t *coeff_ptr, + const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, - const int16_t *scan, const int16_t *iscan) { + const struct ScanOrder *const scan_order) { const __m128i zero = _mm_setzero_si128(); - const __m128i one = _mm_set1_epi16(1); int index; + const int16_t *iscan = scan_order->iscan; __m128i zbin, round, quant, dequant, shift; __m128i coeff0, coeff1; @@ -127,30 +121,8 @@ void vpx_quantize_b_32x32_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, __m128i all_zero; __m128i eob = zero, eob0; - (void)scan; - (void)n_coeffs; - - // Setup global values. - // The 32x32 halves zbin and round. - zbin = _mm_load_si128((const __m128i *)zbin_ptr); - // Shift with rounding. - zbin = _mm_add_epi16(zbin, one); - zbin = _mm_srli_epi16(zbin, 1); - // x86 has no "greater *or equal*" comparison. Subtract 1 from zbin so - // it is a strict "greater" comparison. - zbin = _mm_sub_epi16(zbin, one); - - round = _mm_load_si128((const __m128i *)round_ptr); - round = _mm_add_epi16(round, one); - round = _mm_srli_epi16(round, 1); - - quant = _mm_load_si128((const __m128i *)quant_ptr); - dequant = _mm_load_si128((const __m128i *)dequant_ptr); - shift = _mm_load_si128((const __m128i *)quant_shift_ptr); - // I suspect this is not technically OK because quant_shift can be up - // to 1 << 16 and shifting up again will outrange that, but the test is not - // comprehensive enough to catch that and "it's been that way forever" - shift = _mm_slli_epi16(shift, 1); + load_b_values32x32(mb_plane, &zbin, &round, &quant, dequant_ptr, &dequant, + &shift); // Do DC and first 15 AC. coeff0 = load_tran_low(coeff_ptr); @@ -202,8 +174,7 @@ void vpx_quantize_b_32x32_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, dequant = _mm_unpackhi_epi64(dequant, dequant); calculate_dqcoeff_and_store_32x32(qcoeff1, dequant, zero, dqcoeff_ptr + 8); - eob = - scan_for_eob(&qcoeff0, &qcoeff1, cmp_mask0, cmp_mask1, iscan, 0, zero); + eob = scan_for_eob(&qcoeff0, &qcoeff1, iscan, 0, zero); } // AC only loop. @@ -249,8 +220,7 @@ void vpx_quantize_b_32x32_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, calculate_dqcoeff_and_store_32x32(qcoeff1, dequant, zero, dqcoeff_ptr + 8 + index); - eob0 = scan_for_eob(&qcoeff0, &qcoeff1, cmp_mask0, cmp_mask1, iscan, index, - zero); + eob0 = scan_for_eob(&qcoeff0, &qcoeff1, iscan, index, zero); eob = _mm_max_epi16(eob, eob0); } diff --git a/libs/libvpx/vpx_dsp/x86/sad4d_avx2.c b/libs/libvpx/vpx_dsp/x86/sad4d_avx2.c index 399b67b3fb..cf7111983b 100644 --- a/libs/libvpx/vpx_dsp/x86/sad4d_avx2.c +++ b/libs/libvpx/vpx_dsp/x86/sad4d_avx2.c @@ -25,9 +25,10 @@ static INLINE void calc_final_4(const __m256i *const sums /*[4]*/, _mm_storeu_si128((__m128i *)sad_array, sum); } -void vpx_sad32x32x4d_avx2(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { +static INLINE void sad32xhx4d_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *const ref_array[4], + int ref_stride, int h, + uint32_t sad_array[4]) { int i; const uint8_t *refs[4]; __m256i sums[4]; @@ -41,7 +42,7 @@ void vpx_sad32x32x4d_avx2(const uint8_t *src_ptr, int src_stride, sums[2] = _mm256_setzero_si256(); sums[3] = _mm256_setzero_si256(); - for (i = 0; i < 32; i++) { + for (i = 0; i < h; i++) { __m256i r[4]; // load src and all ref[] @@ -73,9 +74,10 @@ void vpx_sad32x32x4d_avx2(const uint8_t *src_ptr, int src_stride, calc_final_4(sums, sad_array); } -void vpx_sad64x64x4d_avx2(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { +static INLINE void sad64xhx4d_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *const ref_array[4], + int ref_stride, int h, + uint32_t sad_array[4]) { __m256i sums[4]; int i; const uint8_t *refs[4]; @@ -89,7 +91,7 @@ void vpx_sad64x64x4d_avx2(const uint8_t *src_ptr, int src_stride, sums[2] = _mm256_setzero_si256(); sums[3] = _mm256_setzero_si256(); - for (i = 0; i < 64; i++) { + for (i = 0; i < h; i++) { __m256i r_lo[4], r_hi[4]; // load 64 bytes from src and all ref[] const __m256i s_lo = _mm256_load_si256((const __m256i *)src_ptr); @@ -132,3 +134,51 @@ void vpx_sad64x64x4d_avx2(const uint8_t *src_ptr, int src_stride, calc_final_4(sums, sad_array); } + +#define SAD64_H(h) \ + void vpx_sad64x##h##x4d_avx2(const uint8_t *src, int src_stride, \ + const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + sad64xhx4d_avx2(src, src_stride, ref_array, ref_stride, h, sad_array); \ + } + +#define SAD32_H(h) \ + void vpx_sad32x##h##x4d_avx2(const uint8_t *src, int src_stride, \ + const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + sad32xhx4d_avx2(src, src_stride, ref_array, ref_stride, h, sad_array); \ + } + +SAD64_H(64) +SAD32_H(32) + +#define SADS64_H(h) \ + void vpx_sad_skip_64x##h##x4d_avx2(const uint8_t *src, int src_stride, \ + const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + sad64xhx4d_avx2(src, 2 * src_stride, ref_array, 2 * ref_stride, \ + ((h) >> 1), sad_array); \ + sad_array[0] <<= 1; \ + sad_array[1] <<= 1; \ + sad_array[2] <<= 1; \ + sad_array[3] <<= 1; \ + } + +#define SADS32_H(h) \ + void vpx_sad_skip_32x##h##x4d_avx2(const uint8_t *src, int src_stride, \ + const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + sad32xhx4d_avx2(src, 2 * src_stride, ref_array, 2 * ref_stride, \ + ((h) >> 1), sad_array); \ + sad_array[0] <<= 1; \ + sad_array[1] <<= 1; \ + sad_array[2] <<= 1; \ + sad_array[3] <<= 1; \ + } + +SADS64_H(64) +SADS64_H(32) + +SADS32_H(64) +SADS32_H(32) +SADS32_H(16) diff --git a/libs/libvpx/vpx_dsp/x86/sad4d_avx512.c b/libs/libvpx/vpx_dsp/x86/sad4d_avx512.c index cfd23fedd9..cc36cae611 100644 --- a/libs/libvpx/vpx_dsp/x86/sad4d_avx512.c +++ b/libs/libvpx/vpx_dsp/x86/sad4d_avx512.c @@ -11,9 +11,10 @@ #include "./vpx_dsp_rtcd.h" #include "vpx/vpx_integer.h" -void vpx_sad64x64x4d_avx512(const uint8_t *src_ptr, int src_stride, - const uint8_t *const ref_array[4], int ref_stride, - uint32_t sad_array[4]) { +static INLINE void sad64xhx4d_avx512(const uint8_t *src_ptr, int src_stride, + const uint8_t *const ref_array[4], + int ref_stride, int h, + uint32_t sad_array[4]) { __m512i src_reg, ref0_reg, ref1_reg, ref2_reg, ref3_reg; __m512i sum_ref0, sum_ref1, sum_ref2, sum_ref3; __m512i sum_mlow, sum_mhigh; @@ -28,7 +29,7 @@ void vpx_sad64x64x4d_avx512(const uint8_t *src_ptr, int src_stride, sum_ref1 = _mm512_set1_epi16(0); sum_ref2 = _mm512_set1_epi16(0); sum_ref3 = _mm512_set1_epi16(0); - for (i = 0; i < 64; i++) { + for (i = 0; i < h; i++) { // load src and all ref[] src_reg = _mm512_loadu_si512((const __m512i *)src_ptr); ref0_reg = _mm512_loadu_si512((const __m512i *)ref0); @@ -81,3 +82,24 @@ void vpx_sad64x64x4d_avx512(const uint8_t *src_ptr, int src_stride, _mm_storeu_si128((__m128i *)(sad_array), sum128); } } + +void vpx_sad64x64x4d_avx512(const uint8_t *src, int src_stride, + const uint8_t *const ref_array[4], int ref_stride, + uint32_t sad_array[4]) { + sad64xhx4d_avx512(src, src_stride, ref_array, ref_stride, 64, sad_array); +} + +#define SADS64_H(h) \ + void vpx_sad_skip_64x##h##x4d_avx512( \ + const uint8_t *src, int src_stride, const uint8_t *const ref_array[4], \ + int ref_stride, uint32_t sad_array[4]) { \ + sad64xhx4d_avx512(src, 2 * src_stride, ref_array, 2 * ref_stride, \ + ((h) >> 1), sad_array); \ + sad_array[0] <<= 1; \ + sad_array[1] <<= 1; \ + sad_array[2] <<= 1; \ + sad_array[3] <<= 1; \ + } + +SADS64_H(64) +SADS64_H(32) diff --git a/libs/libvpx/vpx_dsp/x86/sad4d_sse2.asm b/libs/libvpx/vpx_dsp/x86/sad4d_sse2.asm index 3f6e55ce9a..ed4ea3ef9b 100644 --- a/libs/libvpx/vpx_dsp/x86/sad4d_sse2.asm +++ b/libs/libvpx/vpx_dsp/x86/sad4d_sse2.asm @@ -179,13 +179,27 @@ SECTION .text ; uint8_t *ref[4], int ref_stride, ; uint32_t res[4]); ; where NxN = 64x64, 32x32, 16x16, 16x8, 8x16, 8x8, 8x4, 4x8 and 4x4 -%macro SADNXN4D 2 +%macro SADNXN4D 2-3 0 +%if %3 == 1 ; skip rows +%if UNIX64 +cglobal sad_skip_%1x%2x4d, 5, 8, 8, src, src_stride, ref1, ref_stride, \ + res, ref2, ref3, ref4 +%else +cglobal sad_skip_%1x%2x4d, 4, 7, 8, src, src_stride, ref1, ref_stride, \ + ref2, ref3, ref4 +%endif +%else ; normal sad %if UNIX64 cglobal sad%1x%2x4d, 5, 8, 8, src, src_stride, ref1, ref_stride, \ res, ref2, ref3, ref4 %else cglobal sad%1x%2x4d, 4, 7, 8, src, src_stride, ref1, ref_stride, \ ref2, ref3, ref4 +%endif +%endif +%if %3 == 1 + lea src_strided, [2*src_strided] + lea ref_strided, [2*ref_strided] %endif movsxdifnidn src_strideq, src_strided movsxdifnidn ref_strideq, ref_strided @@ -195,9 +209,15 @@ cglobal sad%1x%2x4d, 4, 7, 8, src, src_stride, ref1, ref_stride, \ mov ref1q, [ref1q+gprsize*0] PROCESS_%1x2x4 1, 0, 0, src_strideq, ref_strideq, 1 -%rep (%2-4)/2 +%if %3 == 1 ; downsample number of rows by 2 +%define num_rep (%2-8)/4 +%else +%define num_rep (%2-4)/2 +%endif +%rep num_rep PROCESS_%1x2x4 0, 0, 0, src_strideq, ref_strideq, 1 %endrep +%undef num_rep PROCESS_%1x2x4 0, 0, 0, src_strideq, ref_strideq, 0 %if %1 > 4 @@ -211,12 +231,19 @@ cglobal sad%1x%2x4d, 4, 7, 8, src, src_stride, ref1, ref_stride, \ punpckhqdq m5, m7 movifnidn r4, r4mp paddd m4, m5 +%if %3 == 1 + pslld m4, 1 +%endif movu [r4], m4 RET %else movifnidn r4, r4mp pshufd m6, m6, 0x08 pshufd m7, m7, 0x08 +%if %3 == 1 + pslld m6, 1 + pslld m7, 1 +%endif movq [r4+0], m6 movq [r4+8], m7 RET @@ -237,3 +264,15 @@ SADNXN4D 8, 8 SADNXN4D 8, 4 SADNXN4D 4, 8 SADNXN4D 4, 4 + +SADNXN4D 64, 64, 1 +SADNXN4D 64, 32, 1 +SADNXN4D 32, 64, 1 +SADNXN4D 32, 32, 1 +SADNXN4D 32, 16, 1 +SADNXN4D 16, 32, 1 +SADNXN4D 16, 16, 1 +SADNXN4D 16, 8, 1 +SADNXN4D 8, 16, 1 +SADNXN4D 8, 8, 1 +SADNXN4D 4, 8, 1 diff --git a/libs/libvpx/vpx_dsp/x86/sad_avx2.c b/libs/libvpx/vpx_dsp/x86/sad_avx2.c index 3b48acd510..70b851f67c 100644 --- a/libs/libvpx/vpx_dsp/x86/sad_avx2.c +++ b/libs/libvpx/vpx_dsp/x86/sad_avx2.c @@ -11,74 +11,109 @@ #include "./vpx_dsp_rtcd.h" #include "vpx_ports/mem.h" +static INLINE unsigned int sad64xh_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + int h) { + int i, res; + __m256i sad1_reg, sad2_reg, ref1_reg, ref2_reg; + __m256i sum_sad = _mm256_setzero_si256(); + __m256i sum_sad_h; + __m128i sum_sad128; + for (i = 0; i < h; i++) { + ref1_reg = _mm256_loadu_si256((__m256i const *)ref_ptr); + ref2_reg = _mm256_loadu_si256((__m256i const *)(ref_ptr + 32)); + sad1_reg = + _mm256_sad_epu8(ref1_reg, _mm256_loadu_si256((__m256i const *)src_ptr)); + sad2_reg = _mm256_sad_epu8( + ref2_reg, _mm256_loadu_si256((__m256i const *)(src_ptr + 32))); + sum_sad = _mm256_add_epi32(sum_sad, _mm256_add_epi32(sad1_reg, sad2_reg)); + ref_ptr += ref_stride; + src_ptr += src_stride; + } + sum_sad_h = _mm256_srli_si256(sum_sad, 8); + sum_sad = _mm256_add_epi32(sum_sad, sum_sad_h); + sum_sad128 = _mm256_extracti128_si256(sum_sad, 1); + sum_sad128 = _mm_add_epi32(_mm256_castsi256_si128(sum_sad), sum_sad128); + res = _mm_cvtsi128_si32(sum_sad128); + return res; +} + +static INLINE unsigned int sad32xh_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + int h) { + int i, res; + __m256i sad1_reg, sad2_reg, ref1_reg, ref2_reg; + __m256i sum_sad = _mm256_setzero_si256(); + __m256i sum_sad_h; + __m128i sum_sad128; + const int ref2_stride = ref_stride << 1; + const int src2_stride = src_stride << 1; + const int max = h >> 1; + for (i = 0; i < max; i++) { + ref1_reg = _mm256_loadu_si256((__m256i const *)ref_ptr); + ref2_reg = _mm256_loadu_si256((__m256i const *)(ref_ptr + ref_stride)); + sad1_reg = + _mm256_sad_epu8(ref1_reg, _mm256_loadu_si256((__m256i const *)src_ptr)); + sad2_reg = _mm256_sad_epu8( + ref2_reg, _mm256_loadu_si256((__m256i const *)(src_ptr + src_stride))); + sum_sad = _mm256_add_epi32(sum_sad, _mm256_add_epi32(sad1_reg, sad2_reg)); + ref_ptr += ref2_stride; + src_ptr += src2_stride; + } + sum_sad_h = _mm256_srli_si256(sum_sad, 8); + sum_sad = _mm256_add_epi32(sum_sad, sum_sad_h); + sum_sad128 = _mm256_extracti128_si256(sum_sad, 1); + sum_sad128 = _mm_add_epi32(_mm256_castsi256_si128(sum_sad), sum_sad128); + res = _mm_cvtsi128_si32(sum_sad128); + return res; +} + #define FSAD64_H(h) \ unsigned int vpx_sad64x##h##_avx2(const uint8_t *src_ptr, int src_stride, \ const uint8_t *ref_ptr, int ref_stride) { \ - int i, res; \ - __m256i sad1_reg, sad2_reg, ref1_reg, ref2_reg; \ - __m256i sum_sad = _mm256_setzero_si256(); \ - __m256i sum_sad_h; \ - __m128i sum_sad128; \ - for (i = 0; i < h; i++) { \ - ref1_reg = _mm256_loadu_si256((__m256i const *)ref_ptr); \ - ref2_reg = _mm256_loadu_si256((__m256i const *)(ref_ptr + 32)); \ - sad1_reg = _mm256_sad_epu8( \ - ref1_reg, _mm256_loadu_si256((__m256i const *)src_ptr)); \ - sad2_reg = _mm256_sad_epu8( \ - ref2_reg, _mm256_loadu_si256((__m256i const *)(src_ptr + 32))); \ - sum_sad = \ - _mm256_add_epi32(sum_sad, _mm256_add_epi32(sad1_reg, sad2_reg)); \ - ref_ptr += ref_stride; \ - src_ptr += src_stride; \ - } \ - sum_sad_h = _mm256_srli_si256(sum_sad, 8); \ - sum_sad = _mm256_add_epi32(sum_sad, sum_sad_h); \ - sum_sad128 = _mm256_extracti128_si256(sum_sad, 1); \ - sum_sad128 = _mm_add_epi32(_mm256_castsi256_si128(sum_sad), sum_sad128); \ - res = _mm_cvtsi128_si32(sum_sad128); \ - return res; \ + return sad64xh_avx2(src_ptr, src_stride, ref_ptr, ref_stride, h); \ + } + +#define FSADS64_H(h) \ + unsigned int vpx_sad_skip_64x##h##_avx2( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride) { \ + return 2 * sad64xh_avx2(src_ptr, src_stride * 2, ref_ptr, ref_stride * 2, \ + h / 2); \ } #define FSAD32_H(h) \ unsigned int vpx_sad32x##h##_avx2(const uint8_t *src_ptr, int src_stride, \ const uint8_t *ref_ptr, int ref_stride) { \ - int i, res; \ - __m256i sad1_reg, sad2_reg, ref1_reg, ref2_reg; \ - __m256i sum_sad = _mm256_setzero_si256(); \ - __m256i sum_sad_h; \ - __m128i sum_sad128; \ - int ref2_stride = ref_stride << 1; \ - int src2_stride = src_stride << 1; \ - int max = h >> 1; \ - for (i = 0; i < max; i++) { \ - ref1_reg = _mm256_loadu_si256((__m256i const *)ref_ptr); \ - ref2_reg = _mm256_loadu_si256((__m256i const *)(ref_ptr + ref_stride)); \ - sad1_reg = _mm256_sad_epu8( \ - ref1_reg, _mm256_loadu_si256((__m256i const *)src_ptr)); \ - sad2_reg = _mm256_sad_epu8( \ - ref2_reg, \ - _mm256_loadu_si256((__m256i const *)(src_ptr + src_stride))); \ - sum_sad = \ - _mm256_add_epi32(sum_sad, _mm256_add_epi32(sad1_reg, sad2_reg)); \ - ref_ptr += ref2_stride; \ - src_ptr += src2_stride; \ - } \ - sum_sad_h = _mm256_srli_si256(sum_sad, 8); \ - sum_sad = _mm256_add_epi32(sum_sad, sum_sad_h); \ - sum_sad128 = _mm256_extracti128_si256(sum_sad, 1); \ - sum_sad128 = _mm_add_epi32(_mm256_castsi256_si128(sum_sad), sum_sad128); \ - res = _mm_cvtsi128_si32(sum_sad128); \ - return res; \ + return sad32xh_avx2(src_ptr, src_stride, ref_ptr, ref_stride, h); \ } -#define FSAD64 \ - FSAD64_H(64) \ - FSAD64_H(32) +#define FSADS32_H(h) \ + unsigned int vpx_sad_skip_32x##h##_avx2( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride) { \ + return 2 * sad32xh_avx2(src_ptr, src_stride * 2, ref_ptr, ref_stride * 2, \ + h / 2); \ + } -#define FSAD32 \ - FSAD32_H(64) \ - FSAD32_H(32) \ - FSAD32_H(16) +#if CONFIG_ENCODERS +#define FSAD64 \ + FSAD64_H(64) \ + FSAD64_H(32) \ + FSADS64_H(64) \ + FSADS64_H(32) + +#define FSAD32 \ + FSAD32_H(64) \ + FSAD32_H(32) \ + FSAD32_H(16) \ + FSADS32_H(64) \ + FSADS32_H(32) \ + FSADS32_H(16) +#else // !CONFIG_ENCODERS +#define FSAD64 FSAD64_H(64) +#define FSAD32 FSAD32_H(32) +#endif // CONFIG_ENCODERS FSAD64 FSAD32 @@ -87,12 +122,15 @@ FSAD32 #undef FSAD32 #undef FSAD64_H #undef FSAD32_H +#undef FSADS64_H +#undef FSADS32_H +#if CONFIG_ENCODERS #define FSADAVG64_H(h) \ unsigned int vpx_sad64x##h##_avg_avx2( \ const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ int ref_stride, const uint8_t *second_pred) { \ - int i, res; \ + int i; \ __m256i sad1_reg, sad2_reg, ref1_reg, ref2_reg; \ __m256i sum_sad = _mm256_setzero_si256(); \ __m256i sum_sad_h; \ @@ -118,15 +156,14 @@ FSAD32 sum_sad = _mm256_add_epi32(sum_sad, sum_sad_h); \ sum_sad128 = _mm256_extracti128_si256(sum_sad, 1); \ sum_sad128 = _mm_add_epi32(_mm256_castsi256_si128(sum_sad), sum_sad128); \ - res = _mm_cvtsi128_si32(sum_sad128); \ - return res; \ + return (unsigned int)_mm_cvtsi128_si32(sum_sad128); \ } #define FSADAVG32_H(h) \ unsigned int vpx_sad32x##h##_avg_avx2( \ const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ int ref_stride, const uint8_t *second_pred) { \ - int i, res; \ + int i; \ __m256i sad1_reg, sad2_reg, ref1_reg, ref2_reg; \ __m256i sum_sad = _mm256_setzero_si256(); \ __m256i sum_sad_h; \ @@ -156,8 +193,7 @@ FSAD32 sum_sad = _mm256_add_epi32(sum_sad, sum_sad_h); \ sum_sad128 = _mm256_extracti128_si256(sum_sad, 1); \ sum_sad128 = _mm_add_epi32(_mm256_castsi256_si128(sum_sad), sum_sad128); \ - res = _mm_cvtsi128_si32(sum_sad128); \ - return res; \ + return (unsigned int)_mm_cvtsi128_si32(sum_sad128); \ } #define FSADAVG64 \ @@ -176,3 +212,5 @@ FSADAVG32 #undef FSADAVG32 #undef FSADAVG64_H #undef FSADAVG32_H + +#endif // CONFIG_ENCODERS diff --git a/libs/libvpx/vpx_dsp/x86/sad_avx512.c b/libs/libvpx/vpx_dsp/x86/sad_avx512.c new file mode 100644 index 0000000000..18c7955fef --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/sad_avx512.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2025 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#include +#include "./vpx_dsp_rtcd.h" +#include "vpx_ports/mem.h" + +static INLINE unsigned int sad64xh_avx512(const uint8_t *src_ptr, + int src_stride, + const uint8_t *ref_ptr, + int ref_stride, int h) { + int i, res; + __m512i sad_reg, ref_reg; + __m512i sum_sad = _mm512_setzero_si512(); + for (i = 0; i < h; i++) { + ref_reg = _mm512_loadu_si512((const __m512i *)ref_ptr); + sad_reg = + _mm512_sad_epu8(ref_reg, _mm512_loadu_si512((__m512 const *)src_ptr)); + sum_sad = _mm512_add_epi32(sum_sad, sad_reg); + ref_ptr += ref_stride; + src_ptr += src_stride; + } + res = _mm512_reduce_add_epi32(sum_sad); + return res; +} + +#define FSAD64_H(h) \ + unsigned int vpx_sad64x##h##_avx512(const uint8_t *src_ptr, int src_stride, \ + const uint8_t *ref_ptr, \ + int ref_stride) { \ + return sad64xh_avx512(src_ptr, src_stride, ref_ptr, ref_stride, h); \ + } + +#define FSADS64_H(h) \ + unsigned int vpx_sad_skip_64x##h##_avx512( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride) { \ + return 2 * sad64xh_avx512(src_ptr, src_stride * 2, ref_ptr, \ + ref_stride * 2, h / 2); \ + } + +#if CONFIG_ENCODERS +#define FSAD64 \ + FSAD64_H(64) \ + FSAD64_H(32) \ + FSADS64_H(64) \ + FSADS64_H(32) +#else +#define FSAD64 FSAD64_H(64) +#endif // CONFIG_ENCODERS + +FSAD64 + +#undef FSAD64 +#undef FSAD64_H +#undef FSADS64_H + +#if CONFIG_ENCODERS + +#define FSADAVG64_H(h) \ + unsigned int vpx_sad64x##h##_avg_avx512( \ + const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, \ + int ref_stride, const uint8_t *second_pred) { \ + int i; \ + __m512i sad_reg, ref_reg; \ + __m512i sum_sad = _mm512_setzero_si512(); \ + for (i = 0; i < h; i++) { \ + ref_reg = _mm512_loadu_si512((const __m512i *)ref_ptr); \ + ref_reg = _mm512_avg_epu8( \ + ref_reg, _mm512_loadu_si512((const __m512i *)second_pred)); \ + sad_reg = _mm512_sad_epu8(ref_reg, \ + _mm512_loadu_si512((const __m512i *)src_ptr)); \ + sum_sad = _mm512_add_epi32(sum_sad, sad_reg); \ + ref_ptr += ref_stride; \ + src_ptr += src_stride; \ + second_pred += 64; \ + } \ + return (unsigned int)_mm512_reduce_add_epi32(sum_sad); \ + } + +#define FSADAVG64 \ + FSADAVG64_H(64) \ + FSADAVG64_H(32) + +FSADAVG64 + +#undef FSADAVG64 +#undef FSADAVG64_H + +#endif // CONFIG_ENCODERS diff --git a/libs/libvpx/vpx_dsp/x86/sad_sse2.asm b/libs/libvpx/vpx_dsp/x86/sad_sse2.asm index e4e1bc3e98..390adaeae0 100644 --- a/libs/libvpx/vpx_dsp/x86/sad_sse2.asm +++ b/libs/libvpx/vpx_dsp/x86/sad_sse2.asm @@ -12,15 +12,29 @@ SECTION .text +; Macro Arguments +; Arg 1: Width +; Arg 2: Height +; Arg 3: Number of general purpose registers +; Arg 4: Type of function: if 0, normal sad; if 1, avg; if 2, skip rows %macro SAD_FN 4 -%if %4 == 0 +%if %4 == 0 ; normal sad %if %3 == 5 cglobal sad%1x%2, 4, %3, 5, src, src_stride, ref, ref_stride, n_rows %else ; %3 == 7 cglobal sad%1x%2, 4, %3, 6, src, src_stride, ref, ref_stride, \ src_stride3, ref_stride3, n_rows %endif ; %3 == 5/7 -%else ; avg + +%elif %4 == 2 ; skip +%if %3 == 5 +cglobal sad_skip_%1x%2, 4, %3, 5, src, src_stride, ref, ref_stride, n_rows +%else ; %3 == 7 +cglobal sad_skip_%1x%2, 4, %3, 6, src, src_stride, ref, ref_stride, \ + src_stride3, ref_stride3, n_rows +%endif ; %3 == 5/7 + +%else %if %3 == 5 cglobal sad%1x%2_avg, 5, 1 + %3, 5, src, src_stride, ref, ref_stride, \ second_pred, n_rows @@ -35,7 +49,11 @@ cglobal sad%1x%2_avg, 5, VPX_ARCH_X86_64 + %3, 6, src, src_stride, \ %define n_rowsd dword r0m %endif ; x86-32/64 %endif ; %3 == 5/7 -%endif ; avg/sad +%endif ; sad/avg/skip +%if %4 == 2; skip rows so double the stride +lea src_strided, [src_strided*2] +lea ref_strided, [ref_strided*2] +%endif ; %4 skip movsxdifnidn src_strideq, src_strided movsxdifnidn ref_strideq, ref_strided %if %3 == 7 @@ -48,7 +66,11 @@ cglobal sad%1x%2_avg, 5, VPX_ARCH_X86_64 + %3, 6, src, src_stride, \ ; uint8_t *ref, int ref_stride); %macro SAD64XN 1-2 0 SAD_FN 64, %1, 5, %2 +%if %2 == 2 + mov n_rowsd, %1/2 +%else mov n_rowsd, %1 +%endif pxor m0, m0 .loop: movu m1, [refq] @@ -77,21 +99,32 @@ cglobal sad%1x%2_avg, 5, VPX_ARCH_X86_64 + %3, 6, src, src_stride, \ movhlps m1, m0 paddd m0, m1 +%if %2 == 2 ; we skipped rows, so now we need to double the sad + pslld m0, 1 +%endif movd eax, m0 RET %endmacro INIT_XMM sse2 SAD64XN 64 ; sad64x64_sse2 +%if CONFIG_ENCODERS SAD64XN 32 ; sad64x32_sse2 SAD64XN 64, 1 ; sad64x64_avg_sse2 SAD64XN 32, 1 ; sad64x32_avg_sse2 +SAD64XN 64, 2 ; sad64x64_skip_sse2 +SAD64XN 32, 2 ; sad64x32_skip_sse2 +%endif ; CONFIG_ENCODERS ; unsigned int vpx_sad32x32_sse2(uint8_t *src, int src_stride, ; uint8_t *ref, int ref_stride); %macro SAD32XN 1-2 0 SAD_FN 32, %1, 5, %2 +%if %2 == 2 + mov n_rowsd, %1/4 +%else mov n_rowsd, %1/2 +%endif pxor m0, m0 .loop: movu m1, [refq] @@ -120,23 +153,35 @@ SAD64XN 32, 1 ; sad64x32_avg_sse2 movhlps m1, m0 paddd m0, m1 +%if %2 == 2 ; we skipped rows, so now we need to double the sad + pslld m0, 1 +%endif movd eax, m0 RET %endmacro INIT_XMM sse2 -SAD32XN 64 ; sad32x64_sse2 SAD32XN 32 ; sad32x32_sse2 +%if CONFIG_ENCODERS +SAD32XN 64 ; sad32x64_sse2 SAD32XN 16 ; sad32x16_sse2 SAD32XN 64, 1 ; sad32x64_avg_sse2 SAD32XN 32, 1 ; sad32x32_avg_sse2 SAD32XN 16, 1 ; sad32x16_avg_sse2 +SAD32XN 64, 2 ; sad32x64_skip_sse2 +SAD32XN 32, 2 ; sad32x32_skip_sse2 +SAD32XN 16, 2 ; sad32x16_skip_sse2 +%endif ; CONFIG_ENCODERS ; unsigned int vpx_sad16x{8,16}_sse2(uint8_t *src, int src_stride, ; uint8_t *ref, int ref_stride); %macro SAD16XN 1-2 0 SAD_FN 16, %1, 7, %2 +%if %2 == 2 + mov n_rowsd, %1/8 +%else mov n_rowsd, %1/4 +%endif pxor m0, m0 .loop: @@ -166,23 +211,34 @@ SAD32XN 16, 1 ; sad32x16_avg_sse2 movhlps m1, m0 paddd m0, m1 +%if %2 == 2 ; we skipped rows, so now we need to double the sad + pslld m0, 1 +%endif movd eax, m0 RET %endmacro INIT_XMM sse2 -SAD16XN 32 ; sad16x32_sse2 SAD16XN 16 ; sad16x16_sse2 +%if CONFIG_ENCODERS +SAD16XN 32 ; sad16x32_sse2 SAD16XN 8 ; sad16x8_sse2 SAD16XN 32, 1 ; sad16x32_avg_sse2 SAD16XN 16, 1 ; sad16x16_avg_sse2 SAD16XN 8, 1 ; sad16x8_avg_sse2 +SAD16XN 32, 2 ; sad16x32_skip_sse2 +SAD16XN 16, 2 ; sad16x16_skip_sse2 +SAD16XN 8, 2 ; sad16x8_skip_sse2 ; unsigned int vpx_sad8x{8,16}_sse2(uint8_t *src, int src_stride, ; uint8_t *ref, int ref_stride); %macro SAD8XN 1-2 0 SAD_FN 8, %1, 7, %2 +%if %2 == 2 + mov n_rowsd, %1/8 +%else mov n_rowsd, %1/4 +%endif pxor m0, m0 .loop: @@ -210,6 +266,9 @@ SAD16XN 8, 1 ; sad16x8_avg_sse2 movhlps m1, m0 paddd m0, m1 +%if %2 == 2 ; we skipped rows, so now we need to double the sad + pslld m0, 1 +%endif movd eax, m0 RET %endmacro @@ -221,12 +280,18 @@ SAD8XN 4 ; sad8x4_sse2 SAD8XN 16, 1 ; sad8x16_avg_sse2 SAD8XN 8, 1 ; sad8x8_avg_sse2 SAD8XN 4, 1 ; sad8x4_avg_sse2 +SAD8XN 16, 2 ; sad8x16_skip_sse2 +SAD8XN 8, 2 ; sad8x8_skip_sse2 ; unsigned int vpx_sad4x{4, 8}_sse2(uint8_t *src, int src_stride, ; uint8_t *ref, int ref_stride); %macro SAD4XN 1-2 0 SAD_FN 4, %1, 7, %2 +%if %2 == 2 + mov n_rowsd, %1/8 +%else mov n_rowsd, %1/4 +%endif pxor m0, m0 .loop: @@ -257,6 +322,9 @@ SAD8XN 4, 1 ; sad8x4_avg_sse2 movhlps m1, m0 paddd m0, m1 +%if %2 == 2 ; we skipped rows, so now we need to double the sad + pslld m0, 1 +%endif movd eax, m0 RET %endmacro @@ -266,3 +334,6 @@ SAD4XN 8 ; sad4x8_sse SAD4XN 4 ; sad4x4_sse SAD4XN 8, 1 ; sad4x8_avg_sse SAD4XN 4, 1 ; sad4x4_avg_sse +SAD4XN 8, 2 ; sad4x8_skip_sse + +%endif ; CONFIG_ENCODERS diff --git a/libs/libvpx/vpx_dsp/x86/sse_avx2.c b/libs/libvpx/vpx_dsp/x86/sse_avx2.c new file mode 100644 index 0000000000..dfe45b6115 --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/sse_avx2.c @@ -0,0 +1,368 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" + +#include "vpx_ports/mem.h" +#include "vpx_dsp/x86/mem_sse2.h" + +static INLINE void sse_w32_avx2(__m256i *sum, const uint8_t *a, + const uint8_t *b) { + const __m256i v_a0 = _mm256_loadu_si256((const __m256i *)a); + const __m256i v_b0 = _mm256_loadu_si256((const __m256i *)b); + const __m256i zero = _mm256_setzero_si256(); + const __m256i v_a00_w = _mm256_unpacklo_epi8(v_a0, zero); + const __m256i v_a01_w = _mm256_unpackhi_epi8(v_a0, zero); + const __m256i v_b00_w = _mm256_unpacklo_epi8(v_b0, zero); + const __m256i v_b01_w = _mm256_unpackhi_epi8(v_b0, zero); + const __m256i v_d00_w = _mm256_sub_epi16(v_a00_w, v_b00_w); + const __m256i v_d01_w = _mm256_sub_epi16(v_a01_w, v_b01_w); + *sum = _mm256_add_epi32(*sum, _mm256_madd_epi16(v_d00_w, v_d00_w)); + *sum = _mm256_add_epi32(*sum, _mm256_madd_epi16(v_d01_w, v_d01_w)); +} + +static INLINE int64_t summary_all_avx2(const __m256i *sum_all) { + int64_t sum; + __m256i zero = _mm256_setzero_si256(); + const __m256i sum0_4x64 = _mm256_unpacklo_epi32(*sum_all, zero); + const __m256i sum1_4x64 = _mm256_unpackhi_epi32(*sum_all, zero); + const __m256i sum_4x64 = _mm256_add_epi64(sum0_4x64, sum1_4x64); + const __m128i sum_2x64 = _mm_add_epi64(_mm256_castsi256_si128(sum_4x64), + _mm256_extracti128_si256(sum_4x64, 1)); + const __m128i sum_1x64 = _mm_add_epi64(sum_2x64, _mm_srli_si128(sum_2x64, 8)); + _mm_storel_epi64((__m128i *)&sum, sum_1x64); + return sum; +} + +#if CONFIG_VP9_HIGHBITDEPTH +static INLINE void summary_32_avx2(const __m256i *sum32, __m256i *sum) { + const __m256i sum0_4x64 = + _mm256_cvtepu32_epi64(_mm256_castsi256_si128(*sum32)); + const __m256i sum1_4x64 = + _mm256_cvtepu32_epi64(_mm256_extracti128_si256(*sum32, 1)); + const __m256i sum_4x64 = _mm256_add_epi64(sum0_4x64, sum1_4x64); + *sum = _mm256_add_epi64(*sum, sum_4x64); +} + +static INLINE int64_t summary_4x64_avx2(const __m256i sum_4x64) { + int64_t sum; + const __m128i sum_2x64 = _mm_add_epi64(_mm256_castsi256_si128(sum_4x64), + _mm256_extracti128_si256(sum_4x64, 1)); + const __m128i sum_1x64 = _mm_add_epi64(sum_2x64, _mm_srli_si128(sum_2x64, 8)); + + _mm_storel_epi64((__m128i *)&sum, sum_1x64); + return sum; +} +#endif + +static INLINE void sse_w4x4_avx2(const uint8_t *a, int a_stride, + const uint8_t *b, int b_stride, __m256i *sum) { + const __m128i v_a0 = load_unaligned_u32(a); + const __m128i v_a1 = load_unaligned_u32(a + a_stride); + const __m128i v_a2 = load_unaligned_u32(a + a_stride * 2); + const __m128i v_a3 = load_unaligned_u32(a + a_stride * 3); + const __m128i v_b0 = load_unaligned_u32(b); + const __m128i v_b1 = load_unaligned_u32(b + b_stride); + const __m128i v_b2 = load_unaligned_u32(b + b_stride * 2); + const __m128i v_b3 = load_unaligned_u32(b + b_stride * 3); + const __m128i v_a0123 = _mm_unpacklo_epi64(_mm_unpacklo_epi32(v_a0, v_a1), + _mm_unpacklo_epi32(v_a2, v_a3)); + const __m128i v_b0123 = _mm_unpacklo_epi64(_mm_unpacklo_epi32(v_b0, v_b1), + _mm_unpacklo_epi32(v_b2, v_b3)); + const __m256i v_a_w = _mm256_cvtepu8_epi16(v_a0123); + const __m256i v_b_w = _mm256_cvtepu8_epi16(v_b0123); + const __m256i v_d_w = _mm256_sub_epi16(v_a_w, v_b_w); + *sum = _mm256_add_epi32(*sum, _mm256_madd_epi16(v_d_w, v_d_w)); +} + +static INLINE void sse_w8x2_avx2(const uint8_t *a, int a_stride, + const uint8_t *b, int b_stride, __m256i *sum) { + const __m128i v_a0 = _mm_loadl_epi64((const __m128i *)a); + const __m128i v_a1 = _mm_loadl_epi64((const __m128i *)(a + a_stride)); + const __m128i v_b0 = _mm_loadl_epi64((const __m128i *)b); + const __m128i v_b1 = _mm_loadl_epi64((const __m128i *)(b + b_stride)); + const __m256i v_a_w = _mm256_cvtepu8_epi16(_mm_unpacklo_epi64(v_a0, v_a1)); + const __m256i v_b_w = _mm256_cvtepu8_epi16(_mm_unpacklo_epi64(v_b0, v_b1)); + const __m256i v_d_w = _mm256_sub_epi16(v_a_w, v_b_w); + *sum = _mm256_add_epi32(*sum, _mm256_madd_epi16(v_d_w, v_d_w)); +} + +int64_t vpx_sse_avx2(const uint8_t *a, int a_stride, const uint8_t *b, + int b_stride, int width, int height) { + int32_t y = 0; + int64_t sse = 0; + __m256i sum = _mm256_setzero_si256(); + __m256i zero = _mm256_setzero_si256(); + switch (width) { + case 4: + do { + sse_w4x4_avx2(a, a_stride, b, b_stride, &sum); + a += a_stride << 2; + b += b_stride << 2; + y += 4; + } while (y < height); + sse = summary_all_avx2(&sum); + break; + case 8: + do { + sse_w8x2_avx2(a, a_stride, b, b_stride, &sum); + a += a_stride << 1; + b += b_stride << 1; + y += 2; + } while (y < height); + sse = summary_all_avx2(&sum); + break; + case 16: + do { + const __m128i v_a0 = _mm_loadu_si128((const __m128i *)a); + const __m128i v_a1 = _mm_loadu_si128((const __m128i *)(a + a_stride)); + const __m128i v_b0 = _mm_loadu_si128((const __m128i *)b); + const __m128i v_b1 = _mm_loadu_si128((const __m128i *)(b + b_stride)); + const __m256i v_a = + _mm256_insertf128_si256(_mm256_castsi128_si256(v_a0), v_a1, 0x01); + const __m256i v_b = + _mm256_insertf128_si256(_mm256_castsi128_si256(v_b0), v_b1, 0x01); + const __m256i v_al = _mm256_unpacklo_epi8(v_a, zero); + const __m256i v_au = _mm256_unpackhi_epi8(v_a, zero); + const __m256i v_bl = _mm256_unpacklo_epi8(v_b, zero); + const __m256i v_bu = _mm256_unpackhi_epi8(v_b, zero); + const __m256i v_asub = _mm256_sub_epi16(v_al, v_bl); + const __m256i v_bsub = _mm256_sub_epi16(v_au, v_bu); + const __m256i temp = + _mm256_add_epi32(_mm256_madd_epi16(v_asub, v_asub), + _mm256_madd_epi16(v_bsub, v_bsub)); + sum = _mm256_add_epi32(sum, temp); + a += a_stride << 1; + b += b_stride << 1; + y += 2; + } while (y < height); + sse = summary_all_avx2(&sum); + break; + case 32: + do { + sse_w32_avx2(&sum, a, b); + a += a_stride; + b += b_stride; + y += 1; + } while (y < height); + sse = summary_all_avx2(&sum); + break; + case 64: + do { + sse_w32_avx2(&sum, a, b); + sse_w32_avx2(&sum, a + 32, b + 32); + a += a_stride; + b += b_stride; + y += 1; + } while (y < height); + sse = summary_all_avx2(&sum); + break; + default: + if ((width & 0x07) == 0) { + do { + int i = 0; + do { + sse_w8x2_avx2(a + i, a_stride, b + i, b_stride, &sum); + i += 8; + } while (i < width); + a += a_stride << 1; + b += b_stride << 1; + y += 2; + } while (y < height); + } else { + do { + int i = 0; + do { + const uint8_t *a2; + const uint8_t *b2; + sse_w8x2_avx2(a + i, a_stride, b + i, b_stride, &sum); + a2 = a + i + (a_stride << 1); + b2 = b + i + (b_stride << 1); + sse_w8x2_avx2(a2, a_stride, b2, b_stride, &sum); + i += 8; + } while (i + 4 < width); + sse_w4x4_avx2(a + i, a_stride, b + i, b_stride, &sum); + a += a_stride << 2; + b += b_stride << 2; + y += 4; + } while (y < height); + } + sse = summary_all_avx2(&sum); + break; + } + + return sse; +} + +#if CONFIG_VP9_HIGHBITDEPTH +static INLINE void highbd_sse_w16_avx2(__m256i *sum, const uint16_t *a, + const uint16_t *b) { + const __m256i v_a_w = _mm256_loadu_si256((const __m256i *)a); + const __m256i v_b_w = _mm256_loadu_si256((const __m256i *)b); + const __m256i v_d_w = _mm256_sub_epi16(v_a_w, v_b_w); + *sum = _mm256_add_epi32(*sum, _mm256_madd_epi16(v_d_w, v_d_w)); +} + +static INLINE void highbd_sse_w4x4_avx2(__m256i *sum, const uint16_t *a, + int a_stride, const uint16_t *b, + int b_stride) { + const __m128i v_a0 = _mm_loadl_epi64((const __m128i *)a); + const __m128i v_a1 = _mm_loadl_epi64((const __m128i *)(a + a_stride)); + const __m128i v_a2 = _mm_loadl_epi64((const __m128i *)(a + a_stride * 2)); + const __m128i v_a3 = _mm_loadl_epi64((const __m128i *)(a + a_stride * 3)); + const __m128i v_b0 = _mm_loadl_epi64((const __m128i *)b); + const __m128i v_b1 = _mm_loadl_epi64((const __m128i *)(b + b_stride)); + const __m128i v_b2 = _mm_loadl_epi64((const __m128i *)(b + b_stride * 2)); + const __m128i v_b3 = _mm_loadl_epi64((const __m128i *)(b + b_stride * 3)); + const __m128i v_a_hi = _mm_unpacklo_epi64(v_a0, v_a1); + const __m128i v_a_lo = _mm_unpacklo_epi64(v_a2, v_a3); + const __m256i v_a_w = + _mm256_insertf128_si256(_mm256_castsi128_si256(v_a_lo), v_a_hi, 1); + const __m128i v_b_hi = _mm_unpacklo_epi64(v_b0, v_b1); + const __m128i v_b_lo = _mm_unpacklo_epi64(v_b2, v_b3); + const __m256i v_b_w = + _mm256_insertf128_si256(_mm256_castsi128_si256(v_b_lo), v_b_hi, 1); + const __m256i v_d_w = _mm256_sub_epi16(v_a_w, v_b_w); + *sum = _mm256_add_epi32(*sum, _mm256_madd_epi16(v_d_w, v_d_w)); +} + +static INLINE void highbd_sse_w8x2_avx2(__m256i *sum, const uint16_t *a, + int a_stride, const uint16_t *b, + int b_stride) { + const __m128i v_a_hi = _mm_loadu_si128((const __m128i *)(a + a_stride)); + const __m128i v_a_lo = _mm_loadu_si128((const __m128i *)a); + const __m256i v_a_w = + _mm256_insertf128_si256(_mm256_castsi128_si256(v_a_lo), v_a_hi, 1); + const __m128i v_b_hi = _mm_loadu_si128((const __m128i *)(b + b_stride)); + const __m128i v_b_lo = _mm_loadu_si128((const __m128i *)b); + const __m256i v_b_w = + _mm256_insertf128_si256(_mm256_castsi128_si256(v_b_lo), v_b_hi, 1); + const __m256i v_d_w = _mm256_sub_epi16(v_a_w, v_b_w); + *sum = _mm256_add_epi32(*sum, _mm256_madd_epi16(v_d_w, v_d_w)); +} + +int64_t vpx_highbd_sse_avx2(const uint8_t *a8, int a_stride, const uint8_t *b8, + int b_stride, int width, int height) { + int32_t y = 0; + int64_t sse = 0; + uint16_t *a = CONVERT_TO_SHORTPTR(a8); + uint16_t *b = CONVERT_TO_SHORTPTR(b8); + __m256i sum = _mm256_setzero_si256(); + switch (width) { + case 4: + do { + highbd_sse_w4x4_avx2(&sum, a, a_stride, b, b_stride); + a += a_stride << 2; + b += b_stride << 2; + y += 4; + } while (y < height); + sse = summary_all_avx2(&sum); + break; + case 8: + do { + highbd_sse_w8x2_avx2(&sum, a, a_stride, b, b_stride); + a += a_stride << 1; + b += b_stride << 1; + y += 2; + } while (y < height); + sse = summary_all_avx2(&sum); + break; + case 16: + do { + highbd_sse_w16_avx2(&sum, a, b); + a += a_stride; + b += b_stride; + y += 1; + } while (y < height); + sse = summary_all_avx2(&sum); + break; + case 32: + do { + int l = 0; + __m256i sum32 = _mm256_setzero_si256(); + do { + highbd_sse_w16_avx2(&sum32, a, b); + highbd_sse_w16_avx2(&sum32, a + 16, b + 16); + a += a_stride; + b += b_stride; + l += 1; + } while (l < 64 && l < (height - y)); + summary_32_avx2(&sum32, &sum); + y += 64; + } while (y < height); + sse = summary_4x64_avx2(sum); + break; + case 64: + do { + int l = 0; + __m256i sum32 = _mm256_setzero_si256(); + do { + highbd_sse_w16_avx2(&sum32, a, b); + highbd_sse_w16_avx2(&sum32, a + 16 * 1, b + 16 * 1); + highbd_sse_w16_avx2(&sum32, a + 16 * 2, b + 16 * 2); + highbd_sse_w16_avx2(&sum32, a + 16 * 3, b + 16 * 3); + a += a_stride; + b += b_stride; + l += 1; + } while (l < 32 && l < (height - y)); + summary_32_avx2(&sum32, &sum); + y += 32; + } while (y < height); + sse = summary_4x64_avx2(sum); + break; + default: + if (width & 0x7) { + do { + int i = 0; + __m256i sum32 = _mm256_setzero_si256(); + do { + const uint16_t *a2; + const uint16_t *b2; + highbd_sse_w8x2_avx2(&sum32, a + i, a_stride, b + i, b_stride); + a2 = a + i + (a_stride << 1); + b2 = b + i + (b_stride << 1); + highbd_sse_w8x2_avx2(&sum32, a2, a_stride, b2, b_stride); + i += 8; + } while (i + 4 < width); + highbd_sse_w4x4_avx2(&sum32, a + i, a_stride, b + i, b_stride); + summary_32_avx2(&sum32, &sum); + a += a_stride << 2; + b += b_stride << 2; + y += 4; + } while (y < height); + } else { + do { + int l = 0; + __m256i sum32 = _mm256_setzero_si256(); + do { + int i = 0; + do { + highbd_sse_w8x2_avx2(&sum32, a + i, a_stride, b + i, b_stride); + i += 8; + } while (i < width); + a += a_stride << 1; + b += b_stride << 1; + l += 2; + } while (l < 8 && l < (height - y)); + summary_32_avx2(&sum32, &sum); + y += 8; + } while (y < height); + } + sse = summary_4x64_avx2(sum); + break; + } + return sse; +} +#endif // CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vpx_dsp/x86/sse_sse4.c b/libs/libvpx/vpx_dsp/x86/sse_sse4.c new file mode 100644 index 0000000000..4a7585c57e --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/sse_sse4.c @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_config.h" +#include "./vpx_dsp_rtcd.h" + +#include "vpx_ports/mem.h" +#include "vpx/vpx_integer.h" +#include "vpx_dsp/x86/mem_sse2.h" + +static INLINE int64_t summary_all_sse4(const __m128i *sum_all) { + int64_t sum; + const __m128i sum0 = _mm_cvtepu32_epi64(*sum_all); + const __m128i sum1 = _mm_cvtepu32_epi64(_mm_srli_si128(*sum_all, 8)); + const __m128i sum_2x64 = _mm_add_epi64(sum0, sum1); + const __m128i sum_1x64 = _mm_add_epi64(sum_2x64, _mm_srli_si128(sum_2x64, 8)); + _mm_storel_epi64((__m128i *)&sum, sum_1x64); + return sum; +} + +#if CONFIG_VP9_HIGHBITDEPTH +static INLINE void summary_32_sse4(const __m128i *sum32, __m128i *sum64) { + const __m128i sum0 = _mm_cvtepu32_epi64(*sum32); + const __m128i sum1 = _mm_cvtepu32_epi64(_mm_srli_si128(*sum32, 8)); + *sum64 = _mm_add_epi64(sum0, *sum64); + *sum64 = _mm_add_epi64(sum1, *sum64); +} +#endif + +static INLINE void sse_w16_sse4_1(__m128i *sum, const uint8_t *a, + const uint8_t *b) { + const __m128i v_a0 = _mm_loadu_si128((const __m128i *)a); + const __m128i v_b0 = _mm_loadu_si128((const __m128i *)b); + const __m128i v_a00_w = _mm_cvtepu8_epi16(v_a0); + const __m128i v_a01_w = _mm_cvtepu8_epi16(_mm_srli_si128(v_a0, 8)); + const __m128i v_b00_w = _mm_cvtepu8_epi16(v_b0); + const __m128i v_b01_w = _mm_cvtepu8_epi16(_mm_srli_si128(v_b0, 8)); + const __m128i v_d00_w = _mm_sub_epi16(v_a00_w, v_b00_w); + const __m128i v_d01_w = _mm_sub_epi16(v_a01_w, v_b01_w); + *sum = _mm_add_epi32(*sum, _mm_madd_epi16(v_d00_w, v_d00_w)); + *sum = _mm_add_epi32(*sum, _mm_madd_epi16(v_d01_w, v_d01_w)); +} + +static INLINE void sse4x2_sse4_1(const uint8_t *a, int a_stride, + const uint8_t *b, int b_stride, __m128i *sum) { + const __m128i v_a0 = load_unaligned_u32(a); + const __m128i v_a1 = load_unaligned_u32(a + a_stride); + const __m128i v_b0 = load_unaligned_u32(b); + const __m128i v_b1 = load_unaligned_u32(b + b_stride); + const __m128i v_a_w = _mm_cvtepu8_epi16(_mm_unpacklo_epi32(v_a0, v_a1)); + const __m128i v_b_w = _mm_cvtepu8_epi16(_mm_unpacklo_epi32(v_b0, v_b1)); + const __m128i v_d_w = _mm_sub_epi16(v_a_w, v_b_w); + *sum = _mm_add_epi32(*sum, _mm_madd_epi16(v_d_w, v_d_w)); +} + +static INLINE void sse8_sse4_1(const uint8_t *a, const uint8_t *b, + __m128i *sum) { + const __m128i v_a0 = _mm_loadl_epi64((const __m128i *)a); + const __m128i v_b0 = _mm_loadl_epi64((const __m128i *)b); + const __m128i v_a_w = _mm_cvtepu8_epi16(v_a0); + const __m128i v_b_w = _mm_cvtepu8_epi16(v_b0); + const __m128i v_d_w = _mm_sub_epi16(v_a_w, v_b_w); + *sum = _mm_add_epi32(*sum, _mm_madd_epi16(v_d_w, v_d_w)); +} + +int64_t vpx_sse_sse4_1(const uint8_t *a, int a_stride, const uint8_t *b, + int b_stride, int width, int height) { + int y = 0; + int64_t sse = 0; + __m128i sum = _mm_setzero_si128(); + switch (width) { + case 4: + do { + sse4x2_sse4_1(a, a_stride, b, b_stride, &sum); + a += a_stride << 1; + b += b_stride << 1; + y += 2; + } while (y < height); + sse = summary_all_sse4(&sum); + break; + case 8: + do { + sse8_sse4_1(a, b, &sum); + a += a_stride; + b += b_stride; + y += 1; + } while (y < height); + sse = summary_all_sse4(&sum); + break; + case 16: + do { + sse_w16_sse4_1(&sum, a, b); + a += a_stride; + b += b_stride; + y += 1; + } while (y < height); + sse = summary_all_sse4(&sum); + break; + case 32: + do { + sse_w16_sse4_1(&sum, a, b); + sse_w16_sse4_1(&sum, a + 16, b + 16); + a += a_stride; + b += b_stride; + y += 1; + } while (y < height); + sse = summary_all_sse4(&sum); + break; + case 64: + do { + sse_w16_sse4_1(&sum, a, b); + sse_w16_sse4_1(&sum, a + 16 * 1, b + 16 * 1); + sse_w16_sse4_1(&sum, a + 16 * 2, b + 16 * 2); + sse_w16_sse4_1(&sum, a + 16 * 3, b + 16 * 3); + a += a_stride; + b += b_stride; + y += 1; + } while (y < height); + sse = summary_all_sse4(&sum); + break; + default: + if (width & 0x07) { + do { + int i = 0; + do { + sse8_sse4_1(a + i, b + i, &sum); + sse8_sse4_1(a + i + a_stride, b + i + b_stride, &sum); + i += 8; + } while (i + 4 < width); + sse4x2_sse4_1(a + i, a_stride, b + i, b_stride, &sum); + a += (a_stride << 1); + b += (b_stride << 1); + y += 2; + } while (y < height); + } else { + do { + int i = 0; + do { + sse8_sse4_1(a + i, b + i, &sum); + i += 8; + } while (i < width); + a += a_stride; + b += b_stride; + y += 1; + } while (y < height); + } + sse = summary_all_sse4(&sum); + break; + } + + return sse; +} + +#if CONFIG_VP9_HIGHBITDEPTH +static INLINE void highbd_sse_w4x2_sse4_1(__m128i *sum, const uint16_t *a, + int a_stride, const uint16_t *b, + int b_stride) { + const __m128i v_a0 = _mm_loadl_epi64((const __m128i *)a); + const __m128i v_a1 = _mm_loadl_epi64((const __m128i *)(a + a_stride)); + const __m128i v_b0 = _mm_loadl_epi64((const __m128i *)b); + const __m128i v_b1 = _mm_loadl_epi64((const __m128i *)(b + b_stride)); + const __m128i v_a_w = _mm_unpacklo_epi64(v_a0, v_a1); + const __m128i v_b_w = _mm_unpacklo_epi64(v_b0, v_b1); + const __m128i v_d_w = _mm_sub_epi16(v_a_w, v_b_w); + *sum = _mm_add_epi32(*sum, _mm_madd_epi16(v_d_w, v_d_w)); +} + +static INLINE void highbd_sse_w8_sse4_1(__m128i *sum, const uint16_t *a, + const uint16_t *b) { + const __m128i v_a_w = _mm_loadu_si128((const __m128i *)a); + const __m128i v_b_w = _mm_loadu_si128((const __m128i *)b); + const __m128i v_d_w = _mm_sub_epi16(v_a_w, v_b_w); + *sum = _mm_add_epi32(*sum, _mm_madd_epi16(v_d_w, v_d_w)); +} + +int64_t vpx_highbd_sse_sse4_1(const uint8_t *a8, int a_stride, + const uint8_t *b8, int b_stride, int width, + int height) { + int32_t y = 0; + int64_t sse = 0; + uint16_t *a = CONVERT_TO_SHORTPTR(a8); + uint16_t *b = CONVERT_TO_SHORTPTR(b8); + __m128i sum = _mm_setzero_si128(); + switch (width) { + case 4: + do { + highbd_sse_w4x2_sse4_1(&sum, a, a_stride, b, b_stride); + a += a_stride << 1; + b += b_stride << 1; + y += 2; + } while (y < height); + sse = summary_all_sse4(&sum); + break; + case 8: + do { + highbd_sse_w8_sse4_1(&sum, a, b); + a += a_stride; + b += b_stride; + y += 1; + } while (y < height); + sse = summary_all_sse4(&sum); + break; + case 16: + do { + int l = 0; + __m128i sum32 = _mm_setzero_si128(); + do { + highbd_sse_w8_sse4_1(&sum32, a, b); + highbd_sse_w8_sse4_1(&sum32, a + 8, b + 8); + a += a_stride; + b += b_stride; + l += 1; + } while (l < 64 && l < (height - y)); + summary_32_sse4(&sum32, &sum); + y += 64; + } while (y < height); + _mm_storel_epi64((__m128i *)&sse, + _mm_add_epi64(sum, _mm_srli_si128(sum, 8))); + break; + case 32: + do { + int l = 0; + __m128i sum32 = _mm_setzero_si128(); + do { + highbd_sse_w8_sse4_1(&sum32, a, b); + highbd_sse_w8_sse4_1(&sum32, a + 8 * 1, b + 8 * 1); + highbd_sse_w8_sse4_1(&sum32, a + 8 * 2, b + 8 * 2); + highbd_sse_w8_sse4_1(&sum32, a + 8 * 3, b + 8 * 3); + a += a_stride; + b += b_stride; + l += 1; + } while (l < 32 && l < (height - y)); + summary_32_sse4(&sum32, &sum); + y += 32; + } while (y < height); + _mm_storel_epi64((__m128i *)&sse, + _mm_add_epi64(sum, _mm_srli_si128(sum, 8))); + break; + case 64: + do { + int l = 0; + __m128i sum32 = _mm_setzero_si128(); + do { + highbd_sse_w8_sse4_1(&sum32, a, b); + highbd_sse_w8_sse4_1(&sum32, a + 8 * 1, b + 8 * 1); + highbd_sse_w8_sse4_1(&sum32, a + 8 * 2, b + 8 * 2); + highbd_sse_w8_sse4_1(&sum32, a + 8 * 3, b + 8 * 3); + highbd_sse_w8_sse4_1(&sum32, a + 8 * 4, b + 8 * 4); + highbd_sse_w8_sse4_1(&sum32, a + 8 * 5, b + 8 * 5); + highbd_sse_w8_sse4_1(&sum32, a + 8 * 6, b + 8 * 6); + highbd_sse_w8_sse4_1(&sum32, a + 8 * 7, b + 8 * 7); + a += a_stride; + b += b_stride; + l += 1; + } while (l < 16 && l < (height - y)); + summary_32_sse4(&sum32, &sum); + y += 16; + } while (y < height); + _mm_storel_epi64((__m128i *)&sse, + _mm_add_epi64(sum, _mm_srli_si128(sum, 8))); + break; + default: + if (width & 0x7) { + do { + __m128i sum32 = _mm_setzero_si128(); + int i = 0; + do { + highbd_sse_w8_sse4_1(&sum32, a + i, b + i); + highbd_sse_w8_sse4_1(&sum32, a + i + a_stride, b + i + b_stride); + i += 8; + } while (i + 4 < width); + highbd_sse_w4x2_sse4_1(&sum32, a + i, a_stride, b + i, b_stride); + a += (a_stride << 1); + b += (b_stride << 1); + y += 2; + summary_32_sse4(&sum32, &sum); + } while (y < height); + } else { + do { + int l = 0; + __m128i sum32 = _mm_setzero_si128(); + do { + int i = 0; + do { + highbd_sse_w8_sse4_1(&sum32, a + i, b + i); + i += 8; + } while (i < width); + a += a_stride; + b += b_stride; + l += 1; + } while (l < 8 && l < (height - y)); + summary_32_sse4(&sum32, &sum); + y += 8; + } while (y < height); + } + _mm_storel_epi64((__m128i *)&sse, + _mm_add_epi64(sum, _mm_srli_si128(sum, 8))); + break; + } + return sse; +} +#endif // CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vpx_dsp/x86/ssim_opt_x86_64.asm b/libs/libvpx/vpx_dsp/x86/ssim_opt_x86_64.asm index 41ffbb07e6..1ad3b88c8d 100644 --- a/libs/libvpx/vpx_dsp/x86/ssim_opt_x86_64.asm +++ b/libs/libvpx/vpx_dsp/x86/ssim_opt_x86_64.asm @@ -47,97 +47,7 @@ SECTION .text -;void ssim_parms_sse2( -; unsigned char *s, -; int sp, -; unsigned char *r, -; int rp -; uint32_t *sum_s, -; uint32_t *sum_r, -; uint32_t *sum_sq_s, -; uint32_t *sum_sq_r, -; uint32_t *sum_sxr); -; -; TODO: Use parm passing through structure, probably don't need the pxors -; ( calling app will initialize to 0 ) could easily fit everything in sse2 -; without too much hastle, and can probably do better estimates with psadw -; or pavgb At this point this is just meant to be first pass for calculating -; all the parms needed for 16x16 ssim so we can play with dssim as distortion -; in mode selection code. -globalsym(vpx_ssim_parms_16x16_sse2) -sym(vpx_ssim_parms_16x16_sse2): - push rbp - mov rbp, rsp - SHADOW_ARGS_TO_STACK 9 - SAVE_XMM 15 - push rsi - push rdi - ; end prolog - - mov rsi, arg(0) ;s - mov rcx, arg(1) ;sp - mov rdi, arg(2) ;r - mov rax, arg(3) ;rp - - pxor xmm0, xmm0 - pxor xmm15,xmm15 ;sum_s - pxor xmm14,xmm14 ;sum_r - pxor xmm13,xmm13 ;sum_sq_s - pxor xmm12,xmm12 ;sum_sq_r - pxor xmm11,xmm11 ;sum_sxr - - mov rdx, 16 ;row counter -.NextRow: - - ;grab source and reference pixels - movdqu xmm5, [rsi] - movdqu xmm6, [rdi] - movdqa xmm3, xmm5 - movdqa xmm4, xmm6 - punpckhbw xmm3, xmm0 ; high_s - punpckhbw xmm4, xmm0 ; high_r - - TABULATE_SSIM - - movdqa xmm3, xmm5 - movdqa xmm4, xmm6 - punpcklbw xmm3, xmm0 ; low_s - punpcklbw xmm4, xmm0 ; low_r - - TABULATE_SSIM - - add rsi, rcx ; next s row - add rdi, rax ; next r row - - dec rdx ; counter - jnz .NextRow - - SUM_ACROSS_W xmm15 - SUM_ACROSS_W xmm14 - SUM_ACROSS_Q xmm13 - SUM_ACROSS_Q xmm12 - SUM_ACROSS_Q xmm11 - - mov rdi,arg(4) - movd [rdi], xmm15; - mov rdi,arg(5) - movd [rdi], xmm14; - mov rdi,arg(6) - movd [rdi], xmm13; - mov rdi,arg(7) - movd [rdi], xmm12; - mov rdi,arg(8) - movd [rdi], xmm11; - - ; begin epilog - pop rdi - pop rsi - RESTORE_XMM - UNSHADOW_ARGS - pop rbp - ret - -;void ssim_parms_sse2( +;void vpx_ssim_parms_8x8_sse2( ; unsigned char *s, ; int sp, ; unsigned char *r, diff --git a/libs/libvpx/vpx_dsp/x86/subtract_avx2.c b/libs/libvpx/vpx_dsp/x86/subtract_avx2.c new file mode 100644 index 0000000000..ff690dc380 --- /dev/null +++ b/libs/libvpx/vpx_dsp/x86/subtract_avx2.c @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2022 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "./vpx_dsp_rtcd.h" +#include "vpx/vpx_integer.h" + +static VPX_FORCE_INLINE void subtract32_avx2(int16_t *diff_ptr, + const uint8_t *src_ptr, + const uint8_t *pred_ptr) { + const __m256i s = _mm256_lddqu_si256((const __m256i *)src_ptr); + const __m256i p = _mm256_lddqu_si256((const __m256i *)pred_ptr); + const __m256i s_0 = _mm256_cvtepu8_epi16(_mm256_castsi256_si128(s)); + const __m256i s_1 = _mm256_cvtepu8_epi16(_mm256_extracti128_si256(s, 1)); + const __m256i p_0 = _mm256_cvtepu8_epi16(_mm256_castsi256_si128(p)); + const __m256i p_1 = _mm256_cvtepu8_epi16(_mm256_extracti128_si256(p, 1)); + const __m256i d_0 = _mm256_sub_epi16(s_0, p_0); + const __m256i d_1 = _mm256_sub_epi16(s_1, p_1); + _mm256_storeu_si256((__m256i *)diff_ptr, d_0); + _mm256_storeu_si256((__m256i *)(diff_ptr + 16), d_1); +} + +static VPX_FORCE_INLINE void subtract_block_16xn_avx2( + int rows, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, + ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride) { + int j; + for (j = 0; j < rows; ++j) { + const __m128i s = _mm_lddqu_si128((const __m128i *)src_ptr); + const __m128i p = _mm_lddqu_si128((const __m128i *)pred_ptr); + const __m256i s_0 = _mm256_cvtepu8_epi16(s); + const __m256i p_0 = _mm256_cvtepu8_epi16(p); + const __m256i d_0 = _mm256_sub_epi16(s_0, p_0); + _mm256_storeu_si256((__m256i *)diff_ptr, d_0); + src_ptr += src_stride; + pred_ptr += pred_stride; + diff_ptr += diff_stride; + } +} + +static VPX_FORCE_INLINE void subtract_block_32xn_avx2( + int rows, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, + ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride) { + int j; + for (j = 0; j < rows; ++j) { + subtract32_avx2(diff_ptr, src_ptr, pred_ptr); + src_ptr += src_stride; + pred_ptr += pred_stride; + diff_ptr += diff_stride; + } +} + +static VPX_FORCE_INLINE void subtract_block_64xn_avx2( + int rows, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, + ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride) { + int j; + for (j = 0; j < rows; ++j) { + subtract32_avx2(diff_ptr, src_ptr, pred_ptr); + subtract32_avx2(diff_ptr + 32, src_ptr + 32, pred_ptr + 32); + src_ptr += src_stride; + pred_ptr += pred_stride; + diff_ptr += diff_stride; + } +} + +void vpx_subtract_block_avx2(int rows, int cols, int16_t *diff_ptr, + ptrdiff_t diff_stride, const uint8_t *src_ptr, + ptrdiff_t src_stride, const uint8_t *pred_ptr, + ptrdiff_t pred_stride) { + switch (cols) { + case 16: + subtract_block_16xn_avx2(rows, diff_ptr, diff_stride, src_ptr, src_stride, + pred_ptr, pred_stride); + break; + case 32: + subtract_block_32xn_avx2(rows, diff_ptr, diff_stride, src_ptr, src_stride, + pred_ptr, pred_stride); + break; + case 64: + subtract_block_64xn_avx2(rows, diff_ptr, diff_stride, src_ptr, src_stride, + pred_ptr, pred_stride); + break; + default: +#if HAVE_X86_ASM + vpx_subtract_block_sse2(rows, cols, diff_ptr, diff_stride, src_ptr, + src_stride, pred_ptr, pred_stride); +#else + vpx_subtract_block_c(rows, cols, diff_ptr, diff_stride, src_ptr, + src_stride, pred_ptr, pred_stride); +#endif + break; + } +} + +#if CONFIG_VP9_HIGHBITDEPTH +void vpx_highbd_subtract_block_avx2(int rows, int cols, int16_t *diff_ptr, + ptrdiff_t diff_stride, + const uint8_t *src8_ptr, + ptrdiff_t src_stride, + const uint8_t *pred8_ptr, + ptrdiff_t pred_stride, int bd) { + uint16_t *src_ptr = CONVERT_TO_SHORTPTR(src8_ptr); + uint16_t *pred_ptr = CONVERT_TO_SHORTPTR(pred8_ptr); + (void)bd; + if (cols == 64) { + int j = rows; + do { + const __m256i s0 = _mm256_lddqu_si256((const __m256i *)src_ptr); + const __m256i s1 = _mm256_lddqu_si256((const __m256i *)(src_ptr + 16)); + const __m256i s2 = _mm256_lddqu_si256((const __m256i *)(src_ptr + 32)); + const __m256i s3 = _mm256_lddqu_si256((const __m256i *)(src_ptr + 48)); + const __m256i p0 = _mm256_lddqu_si256((const __m256i *)pred_ptr); + const __m256i p1 = _mm256_lddqu_si256((const __m256i *)(pred_ptr + 16)); + const __m256i p2 = _mm256_lddqu_si256((const __m256i *)(pred_ptr + 32)); + const __m256i p3 = _mm256_lddqu_si256((const __m256i *)(pred_ptr + 48)); + const __m256i d0 = _mm256_sub_epi16(s0, p0); + const __m256i d1 = _mm256_sub_epi16(s1, p1); + const __m256i d2 = _mm256_sub_epi16(s2, p2); + const __m256i d3 = _mm256_sub_epi16(s3, p3); + _mm256_storeu_si256((__m256i *)diff_ptr, d0); + _mm256_storeu_si256((__m256i *)(diff_ptr + 16), d1); + _mm256_storeu_si256((__m256i *)(diff_ptr + 32), d2); + _mm256_storeu_si256((__m256i *)(diff_ptr + 48), d3); + src_ptr += src_stride; + pred_ptr += pred_stride; + diff_ptr += diff_stride; + } while (--j != 0); + } else if (cols == 32) { + int j = rows; + do { + const __m256i s0 = _mm256_lddqu_si256((const __m256i *)src_ptr); + const __m256i s1 = _mm256_lddqu_si256((const __m256i *)(src_ptr + 16)); + const __m256i p0 = _mm256_lddqu_si256((const __m256i *)pred_ptr); + const __m256i p1 = _mm256_lddqu_si256((const __m256i *)(pred_ptr + 16)); + const __m256i d0 = _mm256_sub_epi16(s0, p0); + const __m256i d1 = _mm256_sub_epi16(s1, p1); + _mm256_storeu_si256((__m256i *)diff_ptr, d0); + _mm256_storeu_si256((__m256i *)(diff_ptr + 16), d1); + src_ptr += src_stride; + pred_ptr += pred_stride; + diff_ptr += diff_stride; + } while (--j != 0); + } else if (cols == 16) { + int j = rows; + do { + const __m256i s0 = _mm256_lddqu_si256((const __m256i *)src_ptr); + const __m256i s1 = + _mm256_lddqu_si256((const __m256i *)(src_ptr + src_stride)); + const __m256i p0 = _mm256_lddqu_si256((const __m256i *)pred_ptr); + const __m256i p1 = + _mm256_lddqu_si256((const __m256i *)(pred_ptr + pred_stride)); + const __m256i d0 = _mm256_sub_epi16(s0, p0); + const __m256i d1 = _mm256_sub_epi16(s1, p1); + _mm256_storeu_si256((__m256i *)diff_ptr, d0); + _mm256_storeu_si256((__m256i *)(diff_ptr + diff_stride), d1); + src_ptr += src_stride << 1; + pred_ptr += pred_stride << 1; + diff_ptr += diff_stride << 1; + j -= 2; + } while (j != 0); + } else if (cols == 8) { + int j = rows; + do { + const __m128i s0 = _mm_lddqu_si128((const __m128i *)src_ptr); + const __m128i s1 = + _mm_lddqu_si128((const __m128i *)(src_ptr + src_stride)); + const __m128i p0 = _mm_lddqu_si128((const __m128i *)pred_ptr); + const __m128i p1 = + _mm_lddqu_si128((const __m128i *)(pred_ptr + pred_stride)); + const __m128i d0 = _mm_sub_epi16(s0, p0); + const __m128i d1 = _mm_sub_epi16(s1, p1); + _mm_storeu_si128((__m128i *)diff_ptr, d0); + _mm_storeu_si128((__m128i *)(diff_ptr + diff_stride), d1); + src_ptr += src_stride << 1; + pred_ptr += pred_stride << 1; + diff_ptr += diff_stride << 1; + j -= 2; + } while (j != 0); + } else { + int j = rows; + assert(cols == 4); + do { + const __m128i s0 = _mm_loadl_epi64((const __m128i *)src_ptr); + const __m128i s1 = + _mm_loadl_epi64((const __m128i *)(src_ptr + src_stride)); + const __m128i p0 = _mm_loadl_epi64((const __m128i *)pred_ptr); + const __m128i p1 = + _mm_loadl_epi64((const __m128i *)(pred_ptr + pred_stride)); + const __m128i d0 = _mm_sub_epi16(s0, p0); + const __m128i d1 = _mm_sub_epi16(s1, p1); + _mm_storel_epi64((__m128i *)diff_ptr, d0); + _mm_storel_epi64((__m128i *)(diff_ptr + diff_stride), d1); + src_ptr += src_stride << 1; + pred_ptr += pred_stride << 1; + diff_ptr += diff_stride << 1; + j -= 2; + } while (j != 0); + } +} +#endif // CONFIG_VP9_HIGHBITDEPTH diff --git a/libs/libvpx/vpx_dsp/x86/subtract_sse2.asm b/libs/libvpx/vpx_dsp/x86/subtract_sse2.asm index 4273efb854..e3055ab292 100644 --- a/libs/libvpx/vpx_dsp/x86/subtract_sse2.asm +++ b/libs/libvpx/vpx_dsp/x86/subtract_sse2.asm @@ -124,4 +124,5 @@ INIT_MMX lea predq, [predq+pred_str*2] sub rowsd, 2 jg .loop_4 + emms RET diff --git a/libs/libvpx/vpx_dsp/x86/sum_squares_sse2.c b/libs/libvpx/vpx_dsp/x86/sum_squares_sse2.c index 14f3b35c01..df6514b2c4 100644 --- a/libs/libvpx/vpx_dsp/x86/sum_squares_sse2.c +++ b/libs/libvpx/vpx_dsp/x86/sum_squares_sse2.c @@ -33,7 +33,7 @@ uint64_t vpx_sum_squares_2d_i16_sse2(const int16_t *src, int stride, int size) { } else { // Generic case int r = size; - const __m128i v_zext_mask_q = _mm_set_epi32(0, 0xffffffff, 0, 0xffffffff); + const __m128i v_zext_mask_q = _mm_set_epi32(0, -1, 0, -1); __m128i v_acc_q = _mm_setzero_si128(); assert(size % 8 == 0); diff --git a/libs/libvpx/vpx_dsp/x86/variance_avx2.c b/libs/libvpx/vpx_dsp/x86/variance_avx2.c index 9232acbfbb..8305b9f20f 100644 --- a/libs/libvpx/vpx_dsp/x86/variance_avx2.c +++ b/libs/libvpx/vpx_dsp/x86/variance_avx2.c @@ -98,6 +98,41 @@ static INLINE __m256i sum_to_32bit_avx2(const __m256i sum) { return _mm256_add_epi32(sum_lo, sum_hi); } +static INLINE void variance8_kernel_avx2( + const uint8_t *const src, const int src_stride, const uint8_t *const ref, + const int ref_stride, __m256i *const sse, __m256i *const sum) { + __m128i src0, src1, ref0, ref1; + __m256i ss, rr, diff; + + // 0 0 0.... 0 s07 s06 s05 s04 s03 s02 s01 s00 + src0 = _mm_loadl_epi64((const __m128i *)(src + 0 * src_stride)); + + // 0 0 0.... 0 s17 s16 s15 s14 s13 s12 s11 s10 + src1 = _mm_loadl_epi64((const __m128i *)(src + 1 * src_stride)); + + // s17 s16...s11 s10 s07 s06...s01 s00 (8bit) + src0 = _mm_unpacklo_epi64(src0, src1); + + // s17 s16...s11 s10 s07 s06...s01 s00 (16 bit) + ss = _mm256_cvtepu8_epi16(src0); + + // 0 0 0.... 0 r07 r06 r05 r04 r03 r02 r01 r00 + ref0 = _mm_loadl_epi64((const __m128i *)(ref + 0 * ref_stride)); + + // 0 0 0.... 0 r17 r16 0 r15 0 r14 0 r13 0 r12 0 r11 0 r10 + ref1 = _mm_loadl_epi64((const __m128i *)(ref + 1 * ref_stride)); + + // r17 r16...r11 r10 r07 r06...r01 r00 (8 bit) + ref0 = _mm_unpacklo_epi64(ref0, ref1); + + // r17 r16...r11 r10 r07 r06...r01 r00 (16 bit) + rr = _mm256_cvtepu8_epi16(ref0); + + diff = _mm256_sub_epi16(ss, rr); + *sse = _mm256_add_epi32(*sse, _mm256_madd_epi16(diff, diff)); + *sum = _mm256_add_epi16(*sum, diff); +} + static INLINE void variance16_kernel_avx2( const uint8_t *const src, const int src_stride, const uint8_t *const ref, const int ref_stride, __m256i *const sse, __m256i *const sum) { @@ -119,6 +154,21 @@ static INLINE void variance32_kernel_avx2(const uint8_t *const src, variance_kernel_avx2(s, r, sse, sum); } +static INLINE void variance8_avx2(const uint8_t *src, const int src_stride, + const uint8_t *ref, const int ref_stride, + const int h, __m256i *const vsse, + __m256i *const vsum) { + int i; + *vsum = _mm256_setzero_si256(); + *vsse = _mm256_setzero_si256(); + + for (i = 0; i < h; i += 2) { + variance8_kernel_avx2(src, src_stride, ref, ref_stride, vsse, vsum); + src += 2 * src_stride; + ref += 2 * ref_stride; + } +} + static INLINE void variance16_avx2(const uint8_t *src, const int src_stride, const uint8_t *ref, const int ref_stride, const int h, __m256i *const vsse, @@ -590,17 +640,20 @@ static INLINE int sub_pix_var32xh(const uint8_t *src, int src_stride, return sum; } -static unsigned int sub_pixel_variance32xh_avx2( - const uint8_t *src, int src_stride, int x_offset, int y_offset, - const uint8_t *dst, int dst_stride, int height, unsigned int *sse) { +static int sub_pixel_variance32xh_avx2(const uint8_t *src, int src_stride, + int x_offset, int y_offset, + const uint8_t *dst, int dst_stride, + int height, unsigned int *sse) { return sub_pix_var32xh(src, src_stride, x_offset, y_offset, dst, dst_stride, NULL, 0, 0, height, sse); } -static unsigned int sub_pixel_avg_variance32xh_avx2( - const uint8_t *src, int src_stride, int x_offset, int y_offset, - const uint8_t *dst, int dst_stride, const uint8_t *second_pred, - int second_stride, int height, unsigned int *sse) { +static int sub_pixel_avg_variance32xh_avx2(const uint8_t *src, int src_stride, + int x_offset, int y_offset, + const uint8_t *dst, int dst_stride, + const uint8_t *second_pred, + int second_stride, int height, + unsigned int *sse) { return sub_pix_var32xh(src, src_stride, x_offset, y_offset, dst, dst_stride, second_pred, second_stride, 1, height, sse); } @@ -609,6 +662,36 @@ typedef void (*get_var_avx2)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse, int *sum); +unsigned int vpx_variance8x4_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + unsigned int *sse) { + __m256i vsse, vsum; + int sum; + variance8_avx2(src_ptr, src_stride, ref_ptr, ref_stride, 4, &vsse, &vsum); + variance_final_from_16bit_sum_avx2(vsse, vsum, sse, &sum); + return *sse - ((sum * sum) >> 5); +} + +unsigned int vpx_variance8x8_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + unsigned int *sse) { + __m256i vsse, vsum; + int sum; + variance8_avx2(src_ptr, src_stride, ref_ptr, ref_stride, 8, &vsse, &vsum); + variance_final_from_16bit_sum_avx2(vsse, vsum, sse, &sum); + return *sse - ((sum * sum) >> 6); +} + +unsigned int vpx_variance8x16_avx2(const uint8_t *src_ptr, int src_stride, + const uint8_t *ref_ptr, int ref_stride, + unsigned int *sse) { + __m256i vsse, vsum; + int sum; + variance8_avx2(src_ptr, src_stride, ref_ptr, ref_stride, 16, &vsse, &vsum); + variance_final_from_16bit_sum_avx2(vsse, vsum, sse, &sum); + return *sse - ((sum * sum) >> 7); +} + unsigned int vpx_variance16x8_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse) { diff --git a/libs/libvpx/vpx_dsp/x86/variance_sse2.c b/libs/libvpx/vpx_dsp/x86/variance_sse2.c index a67c92aadb..8a7052aba8 100644 --- a/libs/libvpx/vpx_dsp/x86/variance_sse2.c +++ b/libs/libvpx/vpx_dsp/x86/variance_sse2.c @@ -19,7 +19,7 @@ static INLINE unsigned int add32x4_sse2(__m128i val) { val = _mm_add_epi32(val, _mm_srli_si128(val, 8)); val = _mm_add_epi32(val, _mm_srli_si128(val, 4)); - return _mm_cvtsi128_si32(val); + return (unsigned int)_mm_cvtsi128_si32(val); } unsigned int vpx_get_mb_ss_sse2(const int16_t *src_ptr) { @@ -85,7 +85,7 @@ static INLINE void variance_final_512_pel_sse2(__m128i vsse, __m128i vsum, vsum = _mm_add_epi16(vsum, _mm_srli_si128(vsum, 8)); vsum = _mm_unpacklo_epi16(vsum, vsum); vsum = _mm_srai_epi32(vsum, 16); - *sum = add32x4_sse2(vsum); + *sum = (int)add32x4_sse2(vsum); } static INLINE __m128i sum_to_32bit_sse2(const __m128i sum) { @@ -97,7 +97,7 @@ static INLINE __m128i sum_to_32bit_sse2(const __m128i sum) { // Can handle 1024 pixels' diff sum (such as 32x32) static INLINE int sum_final_sse2(const __m128i sum) { const __m128i t = sum_to_32bit_sse2(sum); - return add32x4_sse2(t); + return (int)add32x4_sse2(t); } static INLINE void variance4_sse2(const uint8_t *src_ptr, const int src_stride, @@ -349,7 +349,7 @@ unsigned int vpx_variance32x64_sse2(const uint8_t *src_ptr, int src_stride, vsum = _mm_add_epi32(vsum, sum_to_32bit_sse2(vsum16)); } *sse = add32x4_sse2(vsse); - sum = add32x4_sse2(vsum); + sum = (int)add32x4_sse2(vsum); return *sse - (unsigned int)(((int64_t)sum * sum) >> 11); } @@ -369,7 +369,7 @@ unsigned int vpx_variance64x32_sse2(const uint8_t *src_ptr, int src_stride, vsum = _mm_add_epi32(vsum, sum_to_32bit_sse2(vsum16)); } *sse = add32x4_sse2(vsse); - sum = add32x4_sse2(vsum); + sum = (int)add32x4_sse2(vsum); return *sse - (unsigned int)(((int64_t)sum * sum) >> 11); } @@ -389,7 +389,7 @@ unsigned int vpx_variance64x64_sse2(const uint8_t *src_ptr, int src_stride, vsum = _mm_add_epi32(vsum, sum_to_32bit_sse2(vsum16)); } *sse = add32x4_sse2(vsse); - sum = add32x4_sse2(vsum); + sum = (int)add32x4_sse2(vsum); return *sse - (unsigned int)(((int64_t)sum * sum) >> 12); } @@ -421,6 +421,7 @@ unsigned int vpx_mse16x16_sse2(const uint8_t *src_ptr, int src_stride, return *sse; } +#if HAVE_X86_ASM // The 2 unused parameters are place holders for PIC enabled build. // These definitions are for functions defined in subpel_variance.asm #define DECL(w, opt) \ @@ -563,3 +564,4 @@ FNS(ssse3, ssse3) #undef FNS #undef FN +#endif // HAVE_X86_ASM diff --git a/libs/libvpx/vpx_dsp/x86/vpx_subpixel_4t_intrin_sse2.c b/libs/libvpx/vpx_dsp/x86/vpx_subpixel_4t_intrin_sse2.c index 0cbd151dc3..21a35ae3c3 100644 --- a/libs/libvpx/vpx_dsp/x86/vpx_subpixel_4t_intrin_sse2.c +++ b/libs/libvpx/vpx_dsp/x86/vpx_subpixel_4t_intrin_sse2.c @@ -485,7 +485,7 @@ static void vpx_filter_block1d4_h4_sse2(const uint8_t *src_ptr, // Saturate and convert to 8-bit words dst_first = _mm_packus_epi16(dst_first, _mm_setzero_si128()); - *((uint32_t *)(dst_ptr)) = _mm_cvtsi128_si32(dst_first); + *((int *)(dst_ptr)) = _mm_cvtsi128_si32(dst_first); src_ptr += src_stride; dst_ptr += dst_stride; @@ -589,8 +589,8 @@ static void vpx_filter_block1d4_v4_sse2(const uint8_t *src_ptr, res_reg_0123 = _mm_packus_epi16(res_reg_0123_lo, reg_zero); // Save only half of the register (8 words) - *((uint32_t *)(dst_ptr)) = _mm_cvtsi128_si32(res_reg_m1012); - *((uint32_t *)(dst_ptr + dst_stride)) = _mm_cvtsi128_si32(res_reg_0123); + *((int *)(dst_ptr)) = _mm_cvtsi128_si32(res_reg_m1012); + *((int *)(dst_ptr + dst_stride)) = _mm_cvtsi128_si32(res_reg_0123); // Update the source by two rows src_ptr += src_stride_unrolled; diff --git a/libs/libvpx/vpx_dsp/x86/vpx_subpixel_8t_intrin_avx2.c b/libs/libvpx/vpx_dsp/x86/vpx_subpixel_8t_intrin_avx2.c index 6f2983a4b5..526c283823 100644 --- a/libs/libvpx/vpx_dsp/x86/vpx_subpixel_8t_intrin_avx2.c +++ b/libs/libvpx/vpx_dsp/x86/vpx_subpixel_8t_intrin_avx2.c @@ -15,6 +15,7 @@ #include "vpx_dsp/x86/convolve.h" #include "vpx_dsp/x86/convolve_avx2.h" #include "vpx_dsp/x86/convolve_sse2.h" +#include "vpx_dsp/x86/convolve_ssse3.h" #include "vpx_ports/mem.h" // filters for 16_h8 @@ -38,6 +39,27 @@ DECLARE_ALIGNED(32, static const uint8_t, filt4_global_avx2[32]) = { 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14 }; +DECLARE_ALIGNED(32, static const uint8_t, filt_d4_global_avx2[64]) = { + 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, 0, 1, 2, 3, 1, 2, + 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, + 7, 8, 9, 10, 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, +}; + +#define CALC_CONVOLVE8_HORZ_ROW \ + srcReg = mm256_loadu2_si128(src_ptr - 3, src_ptr - 3 + src_pitch); \ + s1[0] = _mm256_shuffle_epi8(srcReg, filt[0]); \ + s1[1] = _mm256_shuffle_epi8(srcReg, filt[1]); \ + s1[2] = _mm256_shuffle_epi8(srcReg, filt[2]); \ + s1[3] = _mm256_shuffle_epi8(srcReg, filt[3]); \ + s1[0] = convolve8_16_avx2(s1, f1); \ + s1[0] = _mm256_packus_epi16(s1[0], s1[0]); \ + src_ptr += src_stride; \ + _mm_storel_epi64((__m128i *)&output_ptr[0], _mm256_castsi256_si128(s1[0])); \ + output_ptr += output_pitch; \ + _mm_storel_epi64((__m128i *)&output_ptr[0], \ + _mm256_extractf128_si256(s1[0], 1)); \ + output_ptr += output_pitch; + static INLINE void vpx_filter_block1d16_h8_x_avx2( const uint8_t *src_ptr, ptrdiff_t src_pixels_per_line, uint8_t *output_ptr, ptrdiff_t output_pitch, uint32_t output_height, const int16_t *filter, @@ -61,12 +83,7 @@ static INLINE void vpx_filter_block1d16_h8_x_avx2( __m256i srcReg; // load the 2 strides of source - srcReg = - _mm256_castsi128_si256(_mm_loadu_si128((const __m128i *)(src_ptr - 3))); - srcReg = _mm256_inserti128_si256( - srcReg, - _mm_loadu_si128((const __m128i *)(src_ptr + src_pixels_per_line - 3)), - 1); + srcReg = mm256_loadu2_si128(src_ptr - 3, src_ptr + src_pixels_per_line - 3); // filter the source buffer s[0] = _mm256_shuffle_epi8(srcReg, filt[0]); @@ -77,12 +94,7 @@ static INLINE void vpx_filter_block1d16_h8_x_avx2( // reading 2 strides of the next 16 bytes // (part of it was being read by earlier read) - srcReg = - _mm256_castsi128_si256(_mm_loadu_si128((const __m128i *)(src_ptr + 5))); - srcReg = _mm256_inserti128_si256( - srcReg, - _mm_loadu_si128((const __m128i *)(src_ptr + src_pixels_per_line + 5)), - 1); + srcReg = mm256_loadu2_si128(src_ptr + 5, src_ptr + src_pixels_per_line + 5); // filter the source buffer s[0] = _mm256_shuffle_epi8(srcReg, filt[0]); @@ -97,60 +109,37 @@ static INLINE void vpx_filter_block1d16_h8_x_avx2( src_ptr += src_stride; - // average if necessary - outReg1 = _mm256_castsi256_si128(outReg32b1); - outReg2 = _mm256_extractf128_si256(outReg32b1, 1); if (avg) { - outReg1 = _mm_avg_epu8(outReg1, _mm_load_si128((__m128i *)output_ptr)); - outReg2 = _mm_avg_epu8( - outReg2, _mm_load_si128((__m128i *)(output_ptr + output_pitch))); + const __m256i outReg = mm256_loadu2_si128( + (__m128i *)output_ptr, (__m128i *)(output_ptr + output_pitch)); + outReg32b1 = _mm256_avg_epu8(outReg32b1, outReg); } - - // save 16 bytes - _mm_store_si128((__m128i *)output_ptr, outReg1); - - // save the next 16 bits - _mm_store_si128((__m128i *)(output_ptr + output_pitch), outReg2); - + mm256_store2_si128((__m128i *)output_ptr, + (__m128i *)(output_ptr + output_pitch), &outReg32b1); output_ptr += dst_stride; } // if the number of strides is odd. // process only 16 bytes if (i > 0) { - __m128i srcReg; - - // load the first 16 bytes of the last row - srcReg = _mm_loadu_si128((const __m128i *)(src_ptr - 3)); + const __m128i srcReg1 = _mm_loadu_si128((const __m128i *)(src_ptr - 3)); + const __m128i srcReg2 = _mm_loadu_si128((const __m128i *)(src_ptr + 5)); + const __m256i srcReg = + _mm256_inserti128_si256(_mm256_castsi128_si256(srcReg1), srcReg2, 1); // filter the source buffer - s[0] = _mm256_castsi128_si256( - _mm_shuffle_epi8(srcReg, _mm256_castsi256_si128(filt[0]))); - s[1] = _mm256_castsi128_si256( - _mm_shuffle_epi8(srcReg, _mm256_castsi256_si128(filt[1]))); - s[2] = _mm256_castsi128_si256( - _mm_shuffle_epi8(srcReg, _mm256_castsi256_si128(filt[2]))); - s[3] = _mm256_castsi128_si256( - _mm_shuffle_epi8(srcReg, _mm256_castsi256_si128(filt[3]))); - outReg1 = convolve8_8_avx2(s, f); + s[0] = _mm256_shuffle_epi8(srcReg, filt[0]); + s[1] = _mm256_shuffle_epi8(srcReg, filt[1]); + s[2] = _mm256_shuffle_epi8(srcReg, filt[2]); + s[3] = _mm256_shuffle_epi8(srcReg, filt[3]); - // reading the next 16 bytes - // (part of it was being read by earlier read) - srcReg = _mm_loadu_si128((const __m128i *)(src_ptr + 5)); + // The low and high 128-bits of each lane contain the first and second + // convolve result respectively + outReg32b1 = convolve8_16_avx2(s, f); + outReg1 = _mm256_castsi256_si128(outReg32b1); + outReg2 = _mm256_extractf128_si256(outReg32b1, 1); - // filter the source buffer - s[0] = _mm256_castsi128_si256( - _mm_shuffle_epi8(srcReg, _mm256_castsi256_si128(filt[0]))); - s[1] = _mm256_castsi128_si256( - _mm_shuffle_epi8(srcReg, _mm256_castsi256_si128(filt[1]))); - s[2] = _mm256_castsi128_si256( - _mm_shuffle_epi8(srcReg, _mm256_castsi256_si128(filt[2]))); - s[3] = _mm256_castsi128_si256( - _mm_shuffle_epi8(srcReg, _mm256_castsi256_si128(filt[3]))); - outReg2 = convolve8_8_avx2(s, f); - - // shrink to 8 bit each 16 bits, the low and high 64-bits of each lane - // contain the first and second convolve result respectively + // shrink to 8 bit each 16 bits outReg1 = _mm_packus_epi16(outReg1, outReg2); // average if necessary @@ -177,11 +166,63 @@ static void vpx_filter_block1d16_h8_avg_avx2( output_height, filter, 1); } +static void vpx_filter_block1d8_h8_avx2( + const uint8_t *src_ptr, ptrdiff_t src_pitch, uint8_t *output_ptr, + ptrdiff_t output_pitch, uint32_t output_height, const int16_t *filter) { + __m256i filt[4], f1[4], s1[4], srcReg; + __m128i f[4], s[4]; + int y = output_height; + + // Multiply the size of the source stride by two + const ptrdiff_t src_stride = src_pitch << 1; + + shuffle_filter_avx2(filter, f1); + filt[0] = _mm256_load_si256((__m256i const *)filt1_global_avx2); + filt[1] = _mm256_load_si256((__m256i const *)filt2_global_avx2); + filt[2] = _mm256_load_si256((__m256i const *)filt3_global_avx2); + filt[3] = _mm256_load_si256((__m256i const *)filt4_global_avx2); + + // Process next 4 rows + while (y > 3) { + CALC_CONVOLVE8_HORZ_ROW + CALC_CONVOLVE8_HORZ_ROW + y -= 4; + } + + // If remaining, then process 2 rows at a time + while (y > 1) { + CALC_CONVOLVE8_HORZ_ROW + y -= 2; + } + + // For the remaining height. + if (y > 0) { + const __m128i src_reg_128 = _mm_loadu_si128((const __m128i *)(src_ptr - 3)); + + f[0] = _mm256_castsi256_si128(f1[0]); + f[1] = _mm256_castsi256_si128(f1[1]); + f[2] = _mm256_castsi256_si128(f1[2]); + f[3] = _mm256_castsi256_si128(f1[3]); + + // filter the source buffer + s[0] = _mm_shuffle_epi8(src_reg_128, _mm256_castsi256_si128(filt[0])); + s[1] = _mm_shuffle_epi8(src_reg_128, _mm256_castsi256_si128(filt[1])); + s[2] = _mm_shuffle_epi8(src_reg_128, _mm256_castsi256_si128(filt[2])); + s[3] = _mm_shuffle_epi8(src_reg_128, _mm256_castsi256_si128(filt[3])); + s[0] = convolve8_8_ssse3(s, f); + + // Saturate 16bit value to 8bit. + s[0] = _mm_packus_epi16(s[0], s[0]); + + // Save only 8 bytes + _mm_storel_epi64((__m128i *)&output_ptr[0], s[0]); + } +} + static INLINE void vpx_filter_block1d16_v8_x_avx2( const uint8_t *src_ptr, ptrdiff_t src_pitch, uint8_t *output_ptr, ptrdiff_t out_pitch, uint32_t output_height, const int16_t *filter, const int avg) { - __m128i outReg1, outReg2; __m256i srcRegHead1; unsigned int i; ptrdiff_t src_stride, dst_stride; @@ -227,6 +268,9 @@ static INLINE void vpx_filter_block1d16_v8_x_avx2( s2[2] = _mm256_unpackhi_epi8(s32b[4], s32b[5]); } + // The output_height is always a multiple of two. + assert(!(output_height & 1)); + for (i = output_height; i > 1; i -= 2) { __m256i srcRegHead2, srcRegHead3; @@ -257,19 +301,14 @@ static INLINE void vpx_filter_block1d16_v8_x_avx2( src_ptr += src_stride; // average if necessary - outReg1 = _mm256_castsi256_si128(s1[0]); - outReg2 = _mm256_extractf128_si256(s1[0], 1); if (avg) { - outReg1 = _mm_avg_epu8(outReg1, _mm_load_si128((__m128i *)output_ptr)); - outReg2 = _mm_avg_epu8( - outReg2, _mm_load_si128((__m128i *)(output_ptr + out_pitch))); + const __m256i outReg = mm256_loadu2_si128( + (__m128i *)output_ptr, (__m128i *)(output_ptr + out_pitch)); + s1[0] = _mm256_avg_epu8(s1[0], outReg); } - // save 16 bytes - _mm_store_si128((__m128i *)output_ptr, outReg1); - - // save the next 16 bits - _mm_store_si128((__m128i *)(output_ptr + out_pitch), outReg2); + mm256_store2_si128((__m128i *)output_ptr, + (__m128i *)(output_ptr + out_pitch), s1); output_ptr += dst_stride; @@ -282,35 +321,6 @@ static INLINE void vpx_filter_block1d16_v8_x_avx2( s2[2] = s2[3]; srcRegHead1 = srcRegHead3; } - - // if the number of strides is odd. - // process only 16 bytes - if (i > 0) { - // load the last 16 bytes - const __m128i srcRegHead2 = - _mm_loadu_si128((const __m128i *)(src_ptr + src_pitch * 7)); - - // merge the last 2 results together - s1[0] = _mm256_castsi128_si256( - _mm_unpacklo_epi8(_mm256_castsi256_si128(srcRegHead1), srcRegHead2)); - s2[0] = _mm256_castsi128_si256( - _mm_unpackhi_epi8(_mm256_castsi256_si128(srcRegHead1), srcRegHead2)); - - outReg1 = convolve8_8_avx2(s1, f); - outReg2 = convolve8_8_avx2(s2, f); - - // shrink to 8 bit each 16 bits, the low and high 64-bits of each lane - // contain the first and second convolve result respectively - outReg1 = _mm_packus_epi16(outReg1, outReg2); - - // average if necessary - if (avg) { - outReg1 = _mm_avg_epu8(outReg1, _mm_load_si128((__m128i *)output_ptr)); - } - - // save 16 bytes - _mm_store_si128((__m128i *)output_ptr, outReg1); - } } static void vpx_filter_block1d16_v8_avx2(const uint8_t *src_ptr, @@ -560,9 +570,6 @@ static void vpx_filter_block1d8_h4_avx2(const uint8_t *src_ptr, const ptrdiff_t unrolled_dst_stride = dst_stride << 1; int h; - __m256i src_reg, src_reg_shift_0, src_reg_shift_2; - __m256i dst_reg; - __m256i tmp_0, tmp_1; __m256i idx_shift_0 = _mm256_setr_epi8(0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8); @@ -583,9 +590,11 @@ static void vpx_filter_block1d8_h4_avx2(const uint8_t *src_ptr, for (h = height; h >= 2; h -= 2) { // Load the source - src_reg = mm256_loadu2_si128(src_ptr, src_ptr + src_stride); - src_reg_shift_0 = _mm256_shuffle_epi8(src_reg, idx_shift_0); - src_reg_shift_2 = _mm256_shuffle_epi8(src_reg, idx_shift_2); + const __m256i src_reg = mm256_loadu2_si128(src_ptr, src_ptr + src_stride); + __m256i dst_reg; + __m256i tmp_0, tmp_1; + const __m256i src_reg_shift_0 = _mm256_shuffle_epi8(src_reg, idx_shift_0); + const __m256i src_reg_shift_2 = _mm256_shuffle_epi8(src_reg, idx_shift_2); // Get the output tmp_0 = _mm256_maddubs_epi16(src_reg_shift_0, kernel_reg_23); @@ -606,9 +615,9 @@ static void vpx_filter_block1d8_h4_avx2(const uint8_t *src_ptr, // Repeat for the last row if needed if (h > 0) { - __m128i src_reg = _mm_loadu_si128((const __m128i *)src_ptr); + const __m128i src_reg = _mm_loadu_si128((const __m128i *)src_ptr); __m128i dst_reg; - const __m128i reg_32 = _mm_set1_epi16(32); // Used for rounding + const __m128i reg_32_128 = _mm_set1_epi16(32); // Used for rounding __m128i tmp_0, tmp_1; __m128i src_reg_shift_0 = @@ -622,7 +631,7 @@ static void vpx_filter_block1d8_h4_avx2(const uint8_t *src_ptr, _mm256_castsi256_si128(kernel_reg_45)); dst_reg = _mm_adds_epi16(tmp_0, tmp_1); - dst_reg = mm_round_epi16_sse2(&dst_reg, ®_32, 6); + dst_reg = mm_round_epi16_sse2(&dst_reg, ®_32_128, 6); dst_reg = _mm_packus_epi16(dst_reg, _mm_setzero_si128()); @@ -741,8 +750,6 @@ static void vpx_filter_block1d4_h4_avx2(const uint8_t *src_ptr, const ptrdiff_t unrolled_src_stride = src_stride << 1; const ptrdiff_t unrolled_dst_stride = dst_stride << 1; - __m256i src_reg, src_reg_shuf; - __m256i dst; __m256i shuf_idx = _mm256_setr_epi8(0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6); @@ -759,12 +766,12 @@ static void vpx_filter_block1d4_h4_avx2(const uint8_t *src_ptr, for (h = height; h > 1; h -= 2) { // Load the source - src_reg = mm256_loadu2_epi64((const __m128i *)src_ptr, - (const __m128i *)(src_ptr + src_stride)); - src_reg_shuf = _mm256_shuffle_epi8(src_reg, shuf_idx); + const __m256i src_reg = mm256_loadu2_epi64( + (const __m128i *)src_ptr, (const __m128i *)(src_ptr + src_stride)); + const __m256i src_reg_shuf = _mm256_shuffle_epi8(src_reg, shuf_idx); // Get the result - dst = _mm256_maddubs_epi16(src_reg_shuf, kernel_reg); + __m256i dst = _mm256_maddubs_epi16(src_reg_shuf, kernel_reg); dst = _mm256_hadds_epi16(dst, _mm256_setzero_si256()); // Round result @@ -783,7 +790,7 @@ static void vpx_filter_block1d4_h4_avx2(const uint8_t *src_ptr, if (h > 0) { // Load the source - const __m128i reg_32 = _mm_set1_epi16(32); // Used for rounding + const __m128i reg_32_128 = _mm_set1_epi16(32); // Used for rounding __m128i src_reg = _mm_loadl_epi64((const __m128i *)src_ptr); __m128i src_reg_shuf = _mm_shuffle_epi8(src_reg, _mm256_castsi256_si128(shuf_idx)); @@ -794,11 +801,11 @@ static void vpx_filter_block1d4_h4_avx2(const uint8_t *src_ptr, dst = _mm_hadds_epi16(dst, _mm_setzero_si128()); // Round result - dst = mm_round_epi16_sse2(&dst, ®_32, 6); + dst = mm_round_epi16_sse2(&dst, ®_32_128, 6); // Pack to 8-bits dst = _mm_packus_epi16(dst, _mm_setzero_si128()); - *((uint32_t *)(dst_ptr)) = _mm_cvtsi128_si32(dst); + *((int *)(dst_ptr)) = _mm_cvtsi128_si32(dst); } } @@ -892,22 +899,399 @@ static void vpx_filter_block1d4_v4_avx2(const uint8_t *src_ptr, } } +static void vpx_filter_block1d8_v8_avx2( + const uint8_t *src_ptr, ptrdiff_t src_pitch, uint8_t *output_ptr, + ptrdiff_t out_pitch, uint32_t output_height, const int16_t *filter) { + __m256i f[4], ss[4]; + __m256i r[8]; + __m128i s[9]; + + unsigned int y = output_height; + // Multiply the size of the source stride by two + const ptrdiff_t src_stride = src_pitch << 1; + + // The output_height is always a multiple of two. + assert(!(output_height & 1)); + + shuffle_filter_avx2(filter, f); + s[0] = _mm_loadl_epi64((const __m128i *)(src_ptr + 0 * src_pitch)); + s[1] = _mm_loadl_epi64((const __m128i *)(src_ptr + 1 * src_pitch)); + s[2] = _mm_loadl_epi64((const __m128i *)(src_ptr + 2 * src_pitch)); + s[3] = _mm_loadl_epi64((const __m128i *)(src_ptr + 3 * src_pitch)); + s[4] = _mm_loadl_epi64((const __m128i *)(src_ptr + 4 * src_pitch)); + s[5] = _mm_loadl_epi64((const __m128i *)(src_ptr + 5 * src_pitch)); + s[6] = _mm_loadl_epi64((const __m128i *)(src_ptr + 6 * src_pitch)); + + // merge the result together + // r[0]: 0 0 0 0 0 0 0 0 r17 r16 r15 r14 r13 r12 r11 r10 | 0 0 0 0 0 0 0 0 + // r07 r06 r05 r04 r03 r02 r01 r00 + r[0] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[0]), s[1], 1); + + // r[1]: 0 0 0 0 0 0 0 0 r27 r26 r25 r24 r23 r22 r21 r20 | 0 0 0 0 0 0 0 0 + // r17 r16 r15 r14 r13 r12 r11 r10 + r[1] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[1]), s[2], 1); + + // r[2]: 0 0 0 0 0 0 0 0 r37 r36 r35 r34 r33 r32 r31 r30 | 0 0 0 0 0 0 0 0 + // r27 r26 r25 r24 r23 r22 r21 r20 + r[2] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[2]), s[3], 1); + + // r[3]: 0 0 0 0 0 0 0 0 r47 r46 r45 r44 r43 r42 r41 r40 | 0 0 0 0 0 0 0 0 + // r37 r36 r35 r34 r33 r32 r31 r30 + r[3] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[3]), s[4], 1); + + // r[4]: 0 0 0 0 0 0 0 0 r57 r56 r55 r54 r53 r52 r51 r50 | 0 0 0 0 0 0 0 0 + // r47 r46 r45 r44 r43 r42 r41 r40 + r[4] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[4]), s[5], 1); + + // r[5]: 0 0 0 0 0 0 0 0 r67 r66 r65 r64 r63 r62 r61 r60 | 0 0 0 0 0 0 0 0 + // r57 r56 r55 r54 r53 r52 r51 r50 + r[5] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[5]), s[6], 1); + + // Merge together + // ss[0]: |r27 r17|.......|r21 r11|r20 r10 || r17 r07|.....|r12 r02|r11 + // r01|r10 r00| + ss[0] = _mm256_unpacklo_epi8(r[0], r[1]); + + // ss[0]: |r47 r37|.......|r41 r31|r40 r30 || r37 r27|.....|r32 r22|r31 + // r21|r30 r20| + ss[1] = _mm256_unpacklo_epi8(r[2], r[3]); + + // ss[2]: |r67 r57|.......|r61 r51|r60 r50 || r57 r47|.....|r52 r42|r51 + // r41|r50 r40| + ss[2] = _mm256_unpacklo_epi8(r[4], r[5]); + + // Process 2 rows at a time + do { + s[7] = _mm_loadl_epi64((const __m128i *)(src_ptr + 7 * src_pitch)); + s[8] = _mm_loadl_epi64((const __m128i *)(src_ptr + 8 * src_pitch)); + + // r[6]: 0 0 0 0 0 0 0 0 r77 r76 r75 r74 r73 r72 r71 r70 | 0 0 0 0 0 0 0 + // 0 r67 r66 r65 r64 r63 r62 r61 r60 + r[6] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[6]), s[7], 1); + // r[7]: 0 0 0 0 0 0 0 0 r87 r86 r85 r84 r83 r82 r81 r80 | 0 0 0 0 0 0 0 + // 0 r77 r76 r75 r74 r73 r72 r71 r70 + r[7] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[7]), s[8], 1); + + // ss[3] : | r87 r77 | .......| r81 r71 | r80 r70 || r77 r67 | .....| r72 + // r62 | r71 r61|r70 r60| + ss[3] = _mm256_unpacklo_epi8(r[6], r[7]); + ss[0] = convolve8_16_avx2(ss, f); + ss[0] = _mm256_packus_epi16(ss[0], ss[0]); + src_ptr += src_stride; + + /* shift down two rows */ + s[6] = s[8]; + _mm_storel_epi64((__m128i *)&output_ptr[0], _mm256_castsi256_si128(ss[0])); + output_ptr += out_pitch; + _mm_storel_epi64((__m128i *)&output_ptr[0], + _mm256_extractf128_si256(ss[0], 1)); + output_ptr += out_pitch; + ss[0] = ss[1]; + ss[1] = ss[2]; + ss[2] = ss[3]; + y -= 2; + } while (y > 1); +} + +static void vpx_filter_block1d4_h8_avx2( + const uint8_t *src_ptr, ptrdiff_t src_pitch, uint8_t *output_ptr, + ptrdiff_t output_pitch, uint32_t output_height, const int16_t *filter) { + __m128i filtersReg; + __m256i addFilterReg64_256bit; + unsigned int y = output_height; + + assert(output_height > 1); + + addFilterReg64_256bit = _mm256_set1_epi16(32); + + // f7 f6 f5 f4 f3 f2 f1 f0 (16 bit) + filtersReg = _mm_loadu_si128((const __m128i *)filter); + + // converting the 16 bit (short) to 8 bit (byte) and have the same data + // in both lanes of 128 bit register. + // f7 f6 f5 f4 f3 f2 f1 f0 || f7 f6 f5 f4 f3 f2 f1 f0 (8 bit each) + filtersReg = _mm_packs_epi16(filtersReg, filtersReg); + + { + ptrdiff_t src_stride; + __m256i filt1Reg, filt2Reg, firstFilters, secondFilters; + // have the same data in both lanes of a 256 bit register + // f7 f6 f5 f4 f3 f2 f1 f0 f7 f6 f5 f4 f3 f2 f1 f0 | f7 f6 f5 f4 f3 f2 f1 f0 + // f7 f6 f5 f4 f3 f2 f1 f0 (8bit each) + const __m256i filtersReg32 = _mm256_broadcastsi128_si256(filtersReg); + + // duplicate only the first 32 bits + // f3 f2 f1 f0|f3 f2 f1 f0|f3 f2 f1 f0|f3 f2 f1 f0 | f3 f2 f1 f0|f3 f2 f1 + // f0|f3 f2 f1 f0|f3 f2 f1 f0 + firstFilters = _mm256_shuffle_epi32(filtersReg32, 0); + // duplicate only the second 32 bits + // f7 f6 f5 f4|f7 f6 f5 f4|f7 f6 f5 f4|f7 f6 f5 f4 | f7 f6 f5 f4|f7 f6 f5 + // f4|f7 f6 f5 f4|f7 f6 f5 f4 + secondFilters = _mm256_shuffle_epi32(filtersReg32, 0x55); + + // s6 s5 s4 s3 s5 s4 s3 s2 s4 s3 s2 s1 s3 s2 s1 s0 | s6 s5 s4 s3 s5 s4 s3 + // s2 s4 s3 s2 s1 s3 s2 s1 s0 + filt1Reg = _mm256_load_si256((__m256i const *)filt_d4_global_avx2); + + // s10 s9 s8 s7 s9 s8 s7 s6 s8 s7 s6 s5 s7 s6 s5 s4 | s10 s9 s8 s7 s9 s8 s7 + // s6 s8 s7 s6 s5 s7 s6 s5 s4 + filt2Reg = _mm256_load_si256((__m256i const *)(filt_d4_global_avx2 + 32)); + + // multiple the size of the source and destination stride by two + src_stride = src_pitch << 1; + + do { + __m256i srcRegFilt32b1_1, srcRegFilt32b2, srcReg32b1; + // load the 2 strides of source + // r115 r114 ...... r15 r14 r13 r12 r11 r10 | r015 r014 r013 ...... r07 + // r06 r05 r04 r03 r02 r01 r00 + srcReg32b1 = mm256_loadu2_si128(src_ptr - 3, src_ptr - 3 + src_pitch); + + // filter the source buffer + // r16 r15 r14 r13 r15 r14 r13 r12 r14 r13 r12 r11 r13 r12 r11 r10 | r06 + // r05 r04 r03 r05 r04 r03 r02 r04 r03 r02 r01 r03 r02 r01 r00 + srcRegFilt32b1_1 = _mm256_shuffle_epi8(srcReg32b1, filt1Reg); + + // multiply 4 adjacent elements with the filter and add the result + // ...|f3*r14+f2*r13|f1*r13+f0*r12|f3*r13+f2*r12|f1*r11+f0*r10||... + // |f1*r03+f0*r02|f3*r04+f2*r03|f1*r02+f0*r01|f3*r03+f2*r02|f1*r01+f0*r00 + srcRegFilt32b1_1 = _mm256_maddubs_epi16(srcRegFilt32b1_1, firstFilters); + + // filter the source buffer + // r110 r19 r18 r17|r19 r18 r17 r16|r18 r17 r16 r15|r17 r16 r15 r14||r010 + // r09 r08 r07|r09 r08 r07 r06|r08 r07 r06 r05|r07 r06 r05 r04 + srcRegFilt32b2 = _mm256_shuffle_epi8(srcReg32b1, filt2Reg); + + // multiply 4 adjacent elements with the filter and add the result + // r010 r09 r08 r07|r9 r08 r07 r06|r08 r07 r06 r05|r07 r06 r05 r04||r010 + // r09 r08 r07|r9 r08 r07 r06|r08 r07 r06 r05|r07 r06 r05 r04 + srcRegFilt32b2 = _mm256_maddubs_epi16(srcRegFilt32b2, secondFilters); + + srcRegFilt32b1_1 = + _mm256_add_epi16(srcRegFilt32b1_1, addFilterReg64_256bit); + srcRegFilt32b1_1 = _mm256_adds_epi16(srcRegFilt32b1_1, srcRegFilt32b2); + + srcRegFilt32b1_1 = + _mm256_hadds_epi16(srcRegFilt32b1_1, _mm256_setzero_si256()); + + // 0 0 0 0 R13 R12 R11 R10 || 0 0 0 0 R03 R02 R01 R00 (16bit) + srcRegFilt32b1_1 = _mm256_srai_epi16(srcRegFilt32b1_1, 7); + + // 8zeros 0 0 0 0 R13 R12 R11 R10 || 8zeros 0 0 0 0 R03 R02 R01 R00 (8bit) + srcRegFilt32b1_1 = + _mm256_packus_epi16(srcRegFilt32b1_1, _mm256_setzero_si256()); + + src_ptr += src_stride; + // save first row 4 values + *((int *)&output_ptr[0]) = + _mm_cvtsi128_si32(_mm256_castsi256_si128(srcRegFilt32b1_1)); + output_ptr += output_pitch; + + // save second row 4 values + *((int *)&output_ptr[0]) = + _mm_cvtsi128_si32(_mm256_extractf128_si256(srcRegFilt32b1_1, 1)); + output_ptr += output_pitch; + + y = y - 2; + } while (y > 1); + + // For remaining height + if (y > 0) { + __m128i srcReg1, srcRegFilt1_1, addFilterReg64; + __m128i srcRegFilt2; + + addFilterReg64 = _mm_set1_epi32((int)0x0400040u); + + srcReg1 = _mm_loadu_si128((const __m128i *)(src_ptr - 3)); + + // filter the source buffer + srcRegFilt1_1 = + _mm_shuffle_epi8(srcReg1, _mm256_castsi256_si128(filt1Reg)); + + // multiply 4 adjacent elements with the filter and add the result + srcRegFilt1_1 = _mm_maddubs_epi16(srcRegFilt1_1, + _mm256_castsi256_si128(firstFilters)); + + // filter the source buffer + srcRegFilt2 = _mm_shuffle_epi8(srcReg1, _mm256_castsi256_si128(filt2Reg)); + + // multiply 4 adjacent elements with the filter and add the result + srcRegFilt2 = + _mm_maddubs_epi16(srcRegFilt2, _mm256_castsi256_si128(secondFilters)); + + srcRegFilt1_1 = _mm_adds_epi16(srcRegFilt1_1, srcRegFilt2); + srcRegFilt1_1 = _mm_hadds_epi16(srcRegFilt1_1, _mm_setzero_si128()); + // shift by 6 bit each 16 bit + srcRegFilt1_1 = _mm_adds_epi16(srcRegFilt1_1, addFilterReg64); + srcRegFilt1_1 = _mm_srai_epi16(srcRegFilt1_1, 7); + + // shrink to 8 bit each 16 bits, the first lane contain the first + // convolve result and the second lane contain the second convolve result + srcRegFilt1_1 = _mm_packus_epi16(srcRegFilt1_1, _mm_setzero_si128()); + + // save 4 bytes + *((int *)(output_ptr)) = _mm_cvtsi128_si32(srcRegFilt1_1); + } + } +} + +static void vpx_filter_block1d4_v8_avx2( + const uint8_t *src_ptr, ptrdiff_t src_pitch, uint8_t *output_ptr, + ptrdiff_t out_pitch, uint32_t output_height, const int16_t *filter) { + __m256i f[4], ss[4]; + __m256i r[9], rr[2]; + __m128i s[11]; + + unsigned int y = output_height; + // Multiply the size of the source stride by four + const ptrdiff_t src_stride = src_pitch << 2; + const ptrdiff_t out_stride = out_pitch << 2; + + // The output_height is always a multiple of two. + assert(!(output_height & 0x01)); + + shuffle_filter_avx2(filter, f); + + s[0] = _mm_loadl_epi64((const __m128i *)(src_ptr + 0 * src_pitch)); + s[1] = _mm_loadl_epi64((const __m128i *)(src_ptr + 1 * src_pitch)); + s[2] = _mm_loadl_epi64((const __m128i *)(src_ptr + 2 * src_pitch)); + s[3] = _mm_loadl_epi64((const __m128i *)(src_ptr + 3 * src_pitch)); + s[4] = _mm_loadl_epi64((const __m128i *)(src_ptr + 4 * src_pitch)); + s[5] = _mm_loadl_epi64((const __m128i *)(src_ptr + 5 * src_pitch)); + s[6] = _mm_loadl_epi64((const __m128i *)(src_ptr + 6 * src_pitch)); + + r[0] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[0]), s[2], 1); + r[1] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[1]), s[3], 1); + r[2] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[2]), s[4], 1); + r[3] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[3]), s[5], 1); + r[4] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[4]), s[6], 1); + + // r37.....r24..r33..r31 r30 r23 r22 r21 r20|r17....r14 r07..r05 r04 r13 r12 + // r11 r10 r03 r02 r01 r00 + rr[0] = _mm256_unpacklo_epi32(r[0], r[1]); + + // r47.....r34..r43..r41 r40 r33 r32 r31 r30|r27....r24 r17..r15 r14 r23 r22 + // r21 r20 r13 r12 r11 r10 + rr[1] = _mm256_unpacklo_epi32(r[1], r[2]); + + // r43 r33....r40 r30|r33 r23....r30 r20||r23 r13....r20 r10|r13 r03....r10 + // r00| + ss[0] = _mm256_unpacklo_epi8(rr[0], rr[1]); + + // r37.....r24..r33..r31 r30 r23 r22 r21 r20||r17....r14 r07..r05 r04 r13 r12 + // r11 r10 r03 r02 r01 r00 + rr[0] = _mm256_unpacklo_epi32(r[2], r[3]); + + // r47.....r34..r43..r41 r40 r33 r32 r31 r30|r27....r24 r17..r15 r14 r23 r22 + // r21 r20 r13 r12 r11 r10 + rr[1] = _mm256_unpacklo_epi32(r[3], r[4]); + + // r63 r53....r60 r50|r53 r43....r50 r40||r43 r33....r40 r30|r33 r23....r30 + // r20| + ss[1] = _mm256_unpacklo_epi8(rr[0], rr[1]); + // Process 4 rows at a time + while (y >= 4) { + s[7] = _mm_loadl_epi64((const __m128i *)(src_ptr + 7 * src_pitch)); + s[8] = _mm_loadl_epi64((const __m128i *)(src_ptr + 8 * src_pitch)); + s[9] = _mm_loadl_epi64((const __m128i *)(src_ptr + 9 * src_pitch)); + s[10] = _mm_loadl_epi64((const __m128i *)(src_ptr + 10 * src_pitch)); + + r[5] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[5]), s[7], 1); + r[6] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[6]), s[8], 1); + rr[0] = _mm256_unpacklo_epi32(r[4], r[5]); + rr[1] = _mm256_unpacklo_epi32(r[5], r[6]); + ss[2] = _mm256_unpacklo_epi8(rr[0], rr[1]); + + r[7] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[7]), s[9], 1); + r[8] = _mm256_inserti128_si256(_mm256_castsi128_si256(s[8]), s[10], 1); + rr[0] = _mm256_unpacklo_epi32(r[6], r[7]); + rr[1] = _mm256_unpacklo_epi32(r[7], r[8]); + ss[3] = _mm256_unpacklo_epi8(rr[0], rr[1]); + + ss[0] = convolve8_16_avx2(ss, f); + + // r3 r2 r3 r2 r1 r0 r1 r0 + ss[0] = _mm256_packus_epi16(ss[0], ss[0]); + src_ptr += src_stride; + + mm256_storeu2_epi32((__m128i *const)output_ptr, + (__m128i *const)(output_ptr + (2 * out_pitch)), ss); + + ss[0] = _mm256_srli_si256(ss[0], 4); + + mm256_storeu2_epi32((__m128i *const)(output_ptr + (1 * out_pitch)), + (__m128i *const)(output_ptr + (3 * out_pitch)), ss); + + output_ptr += out_stride; + + ss[0] = ss[2]; + ss[1] = ss[3]; + + s[6] = s[10]; + s[5] = s[9]; + + r[4] = r[8]; + y -= 4; + } + + // Process 2 rows + if (y == 2) { + __m128i ss1[4], f1[4], r1[4]; + + s[4] = _mm_loadl_epi64((const __m128i *)(src_ptr + 4 * src_pitch)); + s[7] = _mm_loadl_epi64((const __m128i *)(src_ptr + 7 * src_pitch)); + s[8] = _mm_loadl_epi64((const __m128i *)(src_ptr + 8 * src_pitch)); + + f1[0] = _mm256_castsi256_si128(f[0]); + f1[1] = _mm256_castsi256_si128(f[1]); + f1[2] = _mm256_castsi256_si128(f[2]); + f1[3] = _mm256_castsi256_si128(f[3]); + + r1[0] = _mm_unpacklo_epi32(s[4], s[5]); + r1[1] = _mm_unpacklo_epi32(s[5], s[6]); + + // R7-6 xxxx .. . . x| r73 r72 r71 r70 r63 r62 r61 r60 + r1[2] = _mm_unpacklo_epi32(s[6], s[7]); + + // R8-7 xxxx .. . . x| r83 r82 r81 r80 r73 r72 r71 r70 + r1[3] = _mm_unpacklo_epi32(s[7], s[8]); + + // r23 r13....r20 r10|r13 r03....r10 r00 + ss1[0] = _mm256_castsi256_si128(ss[0]); + + // r43 r33....r40 r30|r33 r23....r30 r20 + ss1[1] = _mm256_castsi256_si128(ss[1]); + + // r63 r53....r60 r50|r53 r43....r50 r40 + ss1[2] = _mm_unpacklo_epi8(r1[0], r1[1]); + + // r83 r73....r80 r70|r73 r63....r70 r60 + ss1[3] = _mm_unpacklo_epi8(r1[2], r1[3]); + + ss1[0] = convolve8_8_ssse3(ss1, f1); + + // r1 r0 r1 r0 + ss1[0] = _mm_packus_epi16(ss1[0], ss1[0]); + + // Save first row 4 values + *((int *)&output_ptr[0]) = _mm_cvtsi128_si32(ss1[0]); + output_ptr += out_pitch; + + ss1[0] = _mm_srli_si128(ss1[0], 4); + // Save second row 4 values + *((int *)&output_ptr[0]) = _mm_cvtsi128_si32(ss1[0]); + } +} + #if HAVE_AVX2 && HAVE_SSSE3 -filter8_1dfunction vpx_filter_block1d4_v8_ssse3; #if VPX_ARCH_X86_64 filter8_1dfunction vpx_filter_block1d8_v8_intrin_ssse3; filter8_1dfunction vpx_filter_block1d8_h8_intrin_ssse3; filter8_1dfunction vpx_filter_block1d4_h8_intrin_ssse3; -#define vpx_filter_block1d8_v8_avx2 vpx_filter_block1d8_v8_intrin_ssse3 -#define vpx_filter_block1d8_h8_avx2 vpx_filter_block1d8_h8_intrin_ssse3 -#define vpx_filter_block1d4_h8_avx2 vpx_filter_block1d4_h8_intrin_ssse3 -#else // VPX_ARCH_X86 +#else // VPX_ARCH_X86 filter8_1dfunction vpx_filter_block1d8_v8_ssse3; filter8_1dfunction vpx_filter_block1d8_h8_ssse3; filter8_1dfunction vpx_filter_block1d4_h8_ssse3; -#define vpx_filter_block1d8_v8_avx2 vpx_filter_block1d8_v8_ssse3 -#define vpx_filter_block1d8_h8_avx2 vpx_filter_block1d8_h8_ssse3 -#define vpx_filter_block1d4_h8_avx2 vpx_filter_block1d4_h8_ssse3 #endif // VPX_ARCH_X86_64 filter8_1dfunction vpx_filter_block1d8_v8_avg_ssse3; filter8_1dfunction vpx_filter_block1d8_h8_avg_ssse3; @@ -923,7 +1307,6 @@ filter8_1dfunction vpx_filter_block1d8_v2_ssse3; filter8_1dfunction vpx_filter_block1d8_h2_ssse3; filter8_1dfunction vpx_filter_block1d4_v2_ssse3; filter8_1dfunction vpx_filter_block1d4_h2_ssse3; -#define vpx_filter_block1d4_v8_avx2 vpx_filter_block1d4_v8_ssse3 #define vpx_filter_block1d16_v2_avx2 vpx_filter_block1d16_v2_ssse3 #define vpx_filter_block1d16_h2_avx2 vpx_filter_block1d16_h2_ssse3 #define vpx_filter_block1d8_v2_avx2 vpx_filter_block1d8_v2_ssse3 diff --git a/libs/libvpx/vpx_dsp/x86/vpx_subpixel_8t_intrin_ssse3.c b/libs/libvpx/vpx_dsp/x86/vpx_subpixel_8t_intrin_ssse3.c index ed46d6245d..4ea2752d38 100644 --- a/libs/libvpx/vpx_dsp/x86/vpx_subpixel_8t_intrin_ssse3.c +++ b/libs/libvpx/vpx_dsp/x86/vpx_subpixel_8t_intrin_ssse3.c @@ -580,7 +580,7 @@ static void vpx_filter_block1d4_h4_ssse3(const uint8_t *src_ptr, // Pack to 8-bits dst_first = _mm_packus_epi16(dst_first, _mm_setzero_si128()); - *((uint32_t *)(dst_ptr)) = _mm_cvtsi128_si32(dst_first); + *((int *)(dst_ptr)) = _mm_cvtsi128_si32(dst_first); src_ptr += src_stride; dst_ptr += dst_stride; @@ -666,8 +666,8 @@ static void vpx_filter_block1d4_v4_ssse3(const uint8_t *src_ptr, reg_1 = _mm_packus_epi16(reg_1, reg_1); // Save the result - *((uint32_t *)(dst_ptr)) = _mm_cvtsi128_si32(reg_0); - *((uint32_t *)(dst_ptr + dst_stride)) = _mm_cvtsi128_si32(reg_1); + *((int *)(dst_ptr)) = _mm_cvtsi128_si32(reg_0); + *((int *)(dst_ptr + dst_stride)) = _mm_cvtsi128_si32(reg_1); // Update the source by two rows src_ptr += src_stride_unrolled; diff --git a/libs/libvpx/vpx_mem/include/vpx_mem_intrnl.h b/libs/libvpx/vpx_mem/include/vpx_mem_intrnl.h index 5631130243..fb75d0c808 100644 --- a/libs/libvpx/vpx_mem/include/vpx_mem_intrnl.h +++ b/libs/libvpx/vpx_mem/include/vpx_mem_intrnl.h @@ -26,6 +26,6 @@ /*returns an addr aligned to the byte boundary specified by align*/ #define align_addr(addr, align) \ - (void *)(((size_t)(addr) + ((align)-1)) & ~(size_t)((align)-1)) + (void *)(((size_t)(addr) + ((align) - 1)) & ~(size_t)((align) - 1)) #endif // VPX_VPX_MEM_INCLUDE_VPX_MEM_INTRNL_H_ diff --git a/libs/libvpx/vpx_ports/aarch32_cpudetect.c b/libs/libvpx/vpx_ports/aarch32_cpudetect.c new file mode 100644 index 0000000000..20f688e179 --- /dev/null +++ b/libs/libvpx/vpx_ports/aarch32_cpudetect.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +// Feature detection code for Armv7-A / AArch32. + +#include "./vpx_config.h" +#include "arm_cpudetect.h" + +#if !CONFIG_RUNTIME_CPU_DETECT + +static int arm_get_cpu_caps(void) { + // This function should actually be a no-op. There is no way to adjust any of + // these because the RTCD tables do not exist: the functions are called + // statically. + int flags = 0; +#if HAVE_NEON + flags |= HAS_NEON; +#endif // HAVE_NEON + return flags; +} + +#elif defined(_MSC_VER) // end !CONFIG_RUNTIME_CPU_DETECT + +static int arm_get_cpu_caps(void) { + int flags = 0; +#if HAVE_NEON || HAVE_NEON_ASM + // MSVC has no inline __asm support for Arm, but it does let you __emit + // instructions via their assembled hex code. + // All of these instructions should be essentially nops. + __try { + // VORR q0,q0,q0 + __emit(0xF2200150); + flags |= HAS_NEON; + } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) { + // Ignore exception. + } +#endif // HAVE_NEON || HAVE_NEON_ASM + return flags; +} + +#elif defined(VPX_USE_ANDROID_CPU_FEATURES) + +static int arm_get_cpu_caps(void) { + int flags = 0; +#if HAVE_NEON || HAVE_NEON_ASM + uint64_t features = android_getCpuFeatures(); + if (features & ANDROID_CPU_ARM_FEATURE_NEON) { + flags |= HAS_NEON; + } +#endif // HAVE_NEON || HAVE_NEON_ASM + return flags; +} + +#elif defined(__linux__) // end defined(VPX_USE_ANDROID_CPU_FEATURES) + +#include + +// Define hwcap values ourselves: building with an old auxv header where these +// hwcap values are not defined should not prevent features from being enabled. +#define VPX_AARCH32_HWCAP_NEON (1 << 12) + +static int arm_get_cpu_caps(void) { + int flags = 0; + unsigned long hwcap = getauxval(AT_HWCAP); +#if HAVE_NEON || HAVE_NEON_ASM + if (hwcap & VPX_AARCH32_HWCAP_NEON) { + flags |= HAS_NEON; + } +#endif // HAVE_NEON || HAVE_NEON_ASM + return flags; +} +#else // end __linux__ +#error \ + "Runtime CPU detection selected, but no CPU detection method available" \ +"for your platform. Rerun configure with --disable-runtime-cpu-detect." +#endif + +int arm_cpu_caps(void) { + int flags = 0; + if (arm_cpu_env_flags(&flags)) { + return flags; + } + return arm_get_cpu_caps() & arm_cpu_env_mask(); +} diff --git a/libs/libvpx/vpx_ports/aarch64_cpudetect.c b/libs/libvpx/vpx_ports/aarch64_cpudetect.c new file mode 100644 index 0000000000..df8e1e244d --- /dev/null +++ b/libs/libvpx/vpx_ports/aarch64_cpudetect.c @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "./vpx_config.h" +#include "vpx_ports/arm.h" +#include "vpx_ports/arm_cpudetect.h" + +#if defined(__APPLE__) +#include +#endif + +#if !CONFIG_RUNTIME_CPU_DETECT + +static int arm_get_cpu_caps(void) { + // This function should actually be a no-op. There is no way to adjust any of + // these because the RTCD tables do not exist: the functions are called + // statically. + int flags = 0; +#if HAVE_NEON + flags |= HAS_NEON; +#endif // HAVE_NEON + return flags; +} + +#elif defined(__APPLE__) // end !CONFIG_RUNTIME_CPU_DETECT + +// sysctlbyname() parameter documentation for instruction set characteristics: +// https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics +static INLINE int64_t have_feature(const char *feature) { + int64_t feature_present = 0; + size_t size = sizeof(feature_present); + if (sysctlbyname(feature, &feature_present, &size, NULL, 0) != 0) { + return 0; + } + return feature_present; +} + +static int arm_get_cpu_caps(void) { + int flags = 0; +#if HAVE_NEON + flags |= HAS_NEON; +#endif // HAVE_NEON +#if HAVE_NEON_DOTPROD + if (have_feature("hw.optional.arm.FEAT_DotProd")) { + flags |= HAS_NEON_DOTPROD; + } +#endif // HAVE_NEON_DOTPROD +#if HAVE_NEON_I8MM + if (have_feature("hw.optional.arm.FEAT_I8MM")) { + flags |= HAS_NEON_I8MM; + } +#endif // HAVE_NEON_I8MM + return flags; +} + +#elif defined(_WIN32) // end __APPLE__ + +static int arm_get_cpu_caps(void) { + int flags = 0; +// IsProcessorFeaturePresent() parameter documentation: +// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent#parameters +#if HAVE_NEON + flags |= HAS_NEON; // Neon is mandatory in Armv8.0-A. +#endif // HAVE_NEON +#if HAVE_NEON_DOTPROD +// Support for PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE was added in Windows SDK +// 20348, supported by Windows 11 and Windows Server 2022. +#if defined(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE) + if (IsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE)) { + flags |= HAS_NEON_DOTPROD; + } +#endif // defined(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE) +#endif // HAVE_NEON_DOTPROD +#if HAVE_NEON_I8MM +// Support for PF_ARM_SVE_I8MM_INSTRUCTIONS_AVAILABLE was added in Windows SDK +// 26100. +#if defined(PF_ARM_SVE_I8MM_INSTRUCTIONS_AVAILABLE) + // There's no PF_* flag that indicates whether plain I8MM is available + // or not. But if SVE_I8MM is available, that also implies that + // regular I8MM is available. + if (IsProcessorFeaturePresent(PF_ARM_SVE_I8MM_INSTRUCTIONS_AVAILABLE)) { + flags |= HAS_NEON_I8MM; + } +#endif // defined(PF_ARM_SVE_I8MM_INSTRUCTIONS_AVAILABLE) +#endif // HAVE_NEON_I8MM +#if HAVE_SVE +// Support for PF_ARM_SVE_INSTRUCTIONS_AVAILABLE was added in Windows SDK 26100. +#if defined(PF_ARM_SVE_INSTRUCTIONS_AVAILABLE) + if (IsProcessorFeaturePresent(PF_ARM_SVE_INSTRUCTIONS_AVAILABLE)) { + flags |= HAS_SVE; + } +#endif // defined(PF_ARM_SVE_INSTRUCTIONS_AVAILABLE) +#endif // HAVE_SVE +#if HAVE_SVE2 +// Support for PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE was added in Windows SDK +// 26100. +#if defined(PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE) + if (IsProcessorFeaturePresent(PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE)) { + flags |= HAS_SVE2; + } +#endif // defined(PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE) +#endif // HAVE_SVE2 + return flags; +} + +#elif defined(VPX_USE_ANDROID_CPU_FEATURES) + +static int arm_get_cpu_caps(void) { + int flags = 0; +#if HAVE_NEON + flags |= HAS_NEON; // Neon is mandatory in Armv8.0-A. +#endif // HAVE_NEON + return flags; +} + +#elif defined(__linux__) // end defined(VPX_USE_ANDROID_CPU_FEATURES) + +#include + +// Define hwcap values ourselves: building with an old auxv header where these +// hwcap values are not defined should not prevent features from being enabled. +#define VPX_AARCH64_HWCAP_ASIMDDP (1 << 20) +#define VPX_AARCH64_HWCAP_SVE (1 << 22) +#define VPX_AARCH64_HWCAP2_SVE2 (1 << 1) +#define VPX_AARCH64_HWCAP2_I8MM (1 << 13) + +static int arm_get_cpu_caps(void) { + int flags = 0; +#if HAVE_NEON_DOTPROD || HAVE_SVE + unsigned long hwcap = getauxval(AT_HWCAP); +#endif // HAVE_NEON_DOTPROD || HAVE_SVE +#if HAVE_NEON_I8MM || HAVE_SVE2 + unsigned long hwcap2 = getauxval(AT_HWCAP2); +#endif // HAVE_NEON_I8MM || HAVE_SVE2 +#if HAVE_NEON + flags |= HAS_NEON; // Neon is mandatory in Armv8.0-A. +#endif // HAVE_NEON +#if HAVE_NEON_DOTPROD + if (hwcap & VPX_AARCH64_HWCAP_ASIMDDP) { + flags |= HAS_NEON_DOTPROD; + } +#endif // HAVE_NEON_DOTPROD +#if HAVE_NEON_I8MM + if (hwcap2 & VPX_AARCH64_HWCAP2_I8MM) { + flags |= HAS_NEON_I8MM; + } +#endif // HAVE_NEON_I8MM +#if HAVE_SVE + if (hwcap & VPX_AARCH64_HWCAP_SVE) { + flags |= HAS_SVE; + } +#endif // HAVE_SVE +#if HAVE_SVE2 + if (hwcap2 & VPX_AARCH64_HWCAP2_SVE2) { + flags |= HAS_SVE2; + } +#endif // HAVE_SVE2 + return flags; +} + +#elif defined(__Fuchsia__) // end __linux__ + +#include +#include + +// Added in https://fuchsia-review.googlesource.com/c/fuchsia/+/894282. +#ifndef ZX_ARM64_FEATURE_ISA_I8MM +#define ZX_ARM64_FEATURE_ISA_I8MM ((uint32_t)(1u << 19)) +#endif +// Added in https://fuchsia-review.googlesource.com/c/fuchsia/+/895083. +#ifndef ZX_ARM64_FEATURE_ISA_SVE +#define ZX_ARM64_FEATURE_ISA_SVE ((uint32_t)(1u << 20)) +#endif + +static int arm_get_cpu_caps(void) { + int flags = 0; +#if HAVE_NEON + flags |= HAS_NEON; // Neon is mandatory in Armv8.0-A. +#endif // HAVE_NEON + uint32_t features; + zx_status_t status = zx_system_get_features(ZX_FEATURE_KIND_CPU, &features); + if (status != ZX_OK) { + return flags; + } +#if HAVE_NEON_DOTPROD + if (features & ZX_ARM64_FEATURE_ISA_DP) { + flags |= HAS_NEON_DOTPROD; + } +#endif // HAVE_NEON_DOTPROD +#if HAVE_NEON_I8MM + if (features & ZX_ARM64_FEATURE_ISA_I8MM) { + flags |= HAS_NEON_I8MM; + } +#endif // HAVE_NEON_I8MM +#if HAVE_SVE + if (features & ZX_ARM64_FEATURE_ISA_SVE) { + flags |= HAS_SVE; + } +#endif // HAVE_SVE + return flags; +} + +#else // end __Fuchsia__ +#error \ + "Runtime CPU detection selected, but no CPU detection method available" \ +"for your platform. Rerun configure with --disable-runtime-cpu-detect." +#endif + +int arm_cpu_caps(void) { + int flags = 0; + if (!arm_cpu_env_flags(&flags)) { + flags = arm_get_cpu_caps() & arm_cpu_env_mask(); + } + + // Restrict flags: FEAT_I8MM assumes that FEAT_DotProd is available. + if (!(flags & HAS_NEON_DOTPROD)) { + flags &= ~HAS_NEON_I8MM; + } + + // Restrict flags: FEAT_SVE assumes that FEAT_{DotProd,I8MM} are available. + if (!(flags & HAS_NEON_DOTPROD)) { + flags &= ~HAS_SVE; + } + if (!(flags & HAS_NEON_I8MM)) { + flags &= ~HAS_SVE; + } + + // Restrict flags: FEAT_SVE2 assumes that FEAT_SVE is available. + if (!(flags & HAS_SVE)) { + flags &= ~HAS_SVE2; + } + + return flags; +} diff --git a/libs/libvpx/vpx_ports/arm.h b/libs/libvpx/vpx_ports/arm.h index 6458a2c5b0..814c3cc408 100644 --- a/libs/libvpx/vpx_ports/arm.h +++ b/libs/libvpx/vpx_ports/arm.h @@ -17,12 +17,16 @@ extern "C" { #endif -/*ARMv5TE "Enhanced DSP" instructions.*/ -#define HAS_EDSP 0x01 -/*ARMv6 "Parallel" or "Media" instructions.*/ -#define HAS_MEDIA 0x02 -/*ARMv7 optional NEON instructions.*/ -#define HAS_NEON 0x04 +// Armv7-A optional Neon instructions, mandatory from Armv8.0-A. +#define HAS_NEON (1 << 0) +// Armv8.2-A optional Neon dot-product instructions, mandatory from Armv8.4-A. +#define HAS_NEON_DOTPROD (1 << 1) +// Armv8.2-A optional Neon i8mm instructions, mandatory from Armv8.6-A. +#define HAS_NEON_I8MM (1 << 2) +// Armv8.2-A optional SVE instructions, mandatory from Armv9.0-A. +#define HAS_SVE (1 << 3) +// Armv9.0-A SVE2 instructions. +#define HAS_SVE2 (1 << 4) int arm_cpu_caps(void); diff --git a/libs/libvpx/vpx_ports/arm_cpudetect.c b/libs/libvpx/vpx_ports/arm_cpudetect.c deleted file mode 100644 index 4f9d480ade..0000000000 --- a/libs/libvpx/vpx_ports/arm_cpudetect.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2010 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include -#include - -#include "./vpx_config.h" -#include "vpx_ports/arm.h" - -#ifdef WINAPI_FAMILY -#include -#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -#define getenv(x) NULL -#endif -#endif - -static int arm_cpu_env_flags(int *flags) { - char *env; - env = getenv("VPX_SIMD_CAPS"); - if (env && *env) { - *flags = (int)strtol(env, NULL, 0); - return 0; - } - *flags = 0; - return -1; -} - -static int arm_cpu_env_mask(void) { - char *env; - env = getenv("VPX_SIMD_CAPS_MASK"); - return env && *env ? (int)strtol(env, NULL, 0) : ~0; -} - -#if !CONFIG_RUNTIME_CPU_DETECT - -int arm_cpu_caps(void) { - /* This function should actually be a no-op. There is no way to adjust any of - * these because the RTCD tables do not exist: the functions are called - * statically */ - int flags; - int mask; - if (!arm_cpu_env_flags(&flags)) { - return flags; - } - mask = arm_cpu_env_mask(); -#if HAVE_NEON || HAVE_NEON_ASM - flags |= HAS_NEON; -#endif /* HAVE_NEON || HAVE_NEON_ASM */ - return flags & mask; -} - -#elif defined(_MSC_VER) /* end !CONFIG_RUNTIME_CPU_DETECT */ -/*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/ -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#ifndef WIN32_EXTRA_LEAN -#define WIN32_EXTRA_LEAN -#endif -#include - -int arm_cpu_caps(void) { - int flags; - int mask; - if (!arm_cpu_env_flags(&flags)) { - return flags; - } - mask = arm_cpu_env_mask(); -/* MSVC has no inline __asm support for ARM, but it does let you __emit - * instructions via their assembled hex code. - * All of these instructions should be essentially nops. - */ -#if HAVE_NEON || HAVE_NEON_ASM - if (mask & HAS_NEON) { - __try { - /*VORR q0,q0,q0*/ - __emit(0xF2200150); - flags |= HAS_NEON; - } __except (GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION) { - /*Ignore exception.*/ - } - } -#endif /* HAVE_NEON || HAVE_NEON_ASM */ - return flags & mask; -} - -#elif defined(__ANDROID__) /* end _MSC_VER */ -#include - -int arm_cpu_caps(void) { - int flags; - int mask; - uint64_t features; - if (!arm_cpu_env_flags(&flags)) { - return flags; - } - mask = arm_cpu_env_mask(); - features = android_getCpuFeatures(); - -#if HAVE_NEON || HAVE_NEON_ASM - if (features & ANDROID_CPU_ARM_FEATURE_NEON) flags |= HAS_NEON; -#endif /* HAVE_NEON || HAVE_NEON_ASM */ - return flags & mask; -} - -#elif defined(__linux__) /* end __ANDROID__ */ - -#include - -int arm_cpu_caps(void) { - FILE *fin; - int flags; - int mask; - if (!arm_cpu_env_flags(&flags)) { - return flags; - } - mask = arm_cpu_env_mask(); - /* Reading /proc/self/auxv would be easier, but that doesn't work reliably - * on Android. - * This also means that detection will fail in Scratchbox. - */ - fin = fopen("/proc/cpuinfo", "r"); - if (fin != NULL) { - /* 512 should be enough for anybody (it's even enough for all the flags - * that x86 has accumulated... so far). - */ - char buf[512]; - while (fgets(buf, 511, fin) != NULL) { -#if HAVE_NEON || HAVE_NEON_ASM - if (memcmp(buf, "Features", 8) == 0) { - char *p; - p = strstr(buf, " neon"); - if (p != NULL && (p[5] == ' ' || p[5] == '\n')) { - flags |= HAS_NEON; - } - } -#endif /* HAVE_NEON || HAVE_NEON_ASM */ - } - fclose(fin); - } - return flags & mask; -} -#else /* end __linux__ */ -#error \ - "--enable-runtime-cpu-detect selected, but no CPU detection method " \ -"available for your platform. Reconfigure with --disable-runtime-cpu-detect." -#endif diff --git a/libs/libvpx/vpx_ports/arm_cpudetect.h b/libs/libvpx/vpx_ports/arm_cpudetect.h new file mode 100644 index 0000000000..9b64a1fa2d --- /dev/null +++ b/libs/libvpx/vpx_ports/arm_cpudetect.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "vpx_config.h" +#include "vpx_ports/arm.h" + +#if defined(_WIN32) +#undef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#undef WIN32_EXTRA_LEAN +#define WIN32_EXTRA_LEAN +#include +#endif + +#ifdef WINAPI_FAMILY +#include +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +#define getenv(x) NULL +#endif +#endif + +#if defined(__ANDROID__) && (__ANDROID_API__ < 18) +#define VPX_USE_ANDROID_CPU_FEATURES 1 +// Use getauxval() when targeting (64-bit) Android with API level >= 18. +// getauxval() is supported since Android API level 18 (Android 4.3.) +// First Android version with 64-bit support was Android 5.x (API level 21). +#include +#endif + +static INLINE int arm_cpu_env_flags(int *flags) { + const char *env = getenv("VPX_SIMD_CAPS"); + if (env && *env) { + *flags = (int)strtol(env, NULL, 0); + return 1; + } + return 0; +} + +static INLINE int arm_cpu_env_mask(void) { + const char *env = getenv("VPX_SIMD_CAPS_MASK"); + return env && *env ? (int)strtol(env, NULL, 0) : ~0; +} diff --git a/libs/libvpx/vpx_ports/bitops.h b/libs/libvpx/vpx_ports/bitops.h index 1b5cdaa6dd..e92c972f50 100644 --- a/libs/libvpx/vpx_ports/bitops.h +++ b/libs/libvpx/vpx_ports/bitops.h @@ -13,8 +13,6 @@ #include -#include "vpx_ports/msvc.h" - #ifdef _MSC_VER #if defined(_M_X64) || defined(_M_IX86) #include diff --git a/libs/libvpx/vpx_ports/compiler_attributes.h b/libs/libvpx/vpx_ports/compiler_attributes.h index 354352016c..4b468749b8 100644 --- a/libs/libvpx/vpx_ports/compiler_attributes.h +++ b/libs/libvpx/vpx_ports/compiler_attributes.h @@ -29,13 +29,23 @@ #endif // __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) #if defined(__clang__) && __has_attribute(no_sanitize) +// Both of these have defined behavior and are used in certain operations or +// optimizations thereof. There are cases where an overflow may be unintended, +// however, so use of these attributes should be done with care. #define VPX_NO_UNSIGNED_OVERFLOW_CHECK \ __attribute__((no_sanitize("unsigned-integer-overflow"))) -#endif +#if __clang_major__ >= 12 +#define VPX_NO_UNSIGNED_SHIFT_CHECK \ + __attribute__((no_sanitize("unsigned-shift-base"))) +#endif // __clang__ >= 12 +#endif // __clang__ #ifndef VPX_NO_UNSIGNED_OVERFLOW_CHECK #define VPX_NO_UNSIGNED_OVERFLOW_CHECK #endif +#ifndef VPX_NO_UNSIGNED_SHIFT_CHECK +#define VPX_NO_UNSIGNED_SHIFT_CHECK +#endif //------------------------------------------------------------------------------ // Variable attributes. diff --git a/libs/libvpx/vpx_ports/emms_mmx.c b/libs/libvpx/vpx_ports/emms_mmx.c index f1036b98ed..79b98a75f1 100644 --- a/libs/libvpx/vpx_ports/emms_mmx.c +++ b/libs/libvpx/vpx_ports/emms_mmx.c @@ -12,4 +12,4 @@ #include "vpx_ports/system_state.h" -void vpx_clear_system_state() { _mm_empty(); } +void vpx_clear_system_state(void) { _mm_empty(); } diff --git a/libs/libvpx/vpx_ports/mem.h b/libs/libvpx/vpx_ports/mem.h index 5eccfe8f50..5165b676ac 100644 --- a/libs/libvpx/vpx_ports/mem.h +++ b/libs/libvpx/vpx_ports/mem.h @@ -14,7 +14,7 @@ #include "vpx_config.h" #include "vpx/vpx_integer.h" -#if (defined(__GNUC__) && __GNUC__) || defined(__SUNPRO_C) +#if defined(__GNUC__) || defined(__SUNPRO_C) #define DECLARE_ALIGNED(n, typ, val) typ val __attribute__((aligned(n))) #elif defined(_MSC_VER) #define DECLARE_ALIGNED(n, typ, val) __declspec(align(n)) typ val @@ -23,13 +23,19 @@ #define DECLARE_ALIGNED(n, typ, val) typ val #endif -#if HAVE_NEON && defined(_MSC_VER) +#if defined(__has_builtin) +#define VPX_HAS_BUILTIN(x) __has_builtin(x) +#else +#define VPX_HAS_BUILTIN(x) 0 +#endif + +#if !VPX_HAS_BUILTIN(__builtin_prefetch) && !defined(__GNUC__) #define __builtin_prefetch(x) #endif /* Shift down with rounding */ -#define ROUND_POWER_OF_TWO(value, n) (((value) + (1 << ((n)-1))) >> (n)) -#define ROUND64_POWER_OF_TWO(value, n) (((value) + (1ULL << ((n)-1))) >> (n)) +#define ROUND_POWER_OF_TWO(value, n) (((value) + (1 << ((n) - 1))) >> (n)) +#define ROUND64_POWER_OF_TWO(value, n) (((value) + (1ULL << ((n) - 1))) >> (n)) #define ALIGN_POWER_OF_TWO(value, n) \ (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1)) diff --git a/libs/libvpx/vpx_ports/msvc.h b/libs/libvpx/vpx_ports/msvc.h deleted file mode 100644 index d58de3535a..0000000000 --- a/libs/libvpx/vpx_ports/msvc.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2015 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef VPX_VPX_PORTS_MSVC_H_ -#define VPX_VPX_PORTS_MSVC_H_ -#ifdef _MSC_VER - -#include "./vpx_config.h" - -#if _MSC_VER < 1900 // VS2015 provides snprintf -#define snprintf _snprintf -#endif // _MSC_VER < 1900 - -#if _MSC_VER < 1800 // VS2013 provides round -#include -static INLINE double round(double x) { - if (x < 0) - return ceil(x - 0.5); - else - return floor(x + 0.5); -} -#endif // _MSC_VER < 1800 - -#endif // _MSC_VER -#endif // VPX_VPX_PORTS_MSVC_H_ diff --git a/libs/libvpx/vpx_ports/vpx_once.h b/libs/libvpx/vpx_ports/vpx_once.h index d8a8ed89fe..d33eff4397 100644 --- a/libs/libvpx/vpx_ports/vpx_once.h +++ b/libs/libvpx/vpx_ports/vpx_once.h @@ -91,29 +91,6 @@ static void once(void (*func)(void)) { return; } -#elif CONFIG_MULTITHREAD && defined(__OS2__) -#define INCL_DOS -#include -static void once(void (*func)(void)) { - static volatile int done; - - /* If the initialization is complete, return early. */ - if (done) return; - - /* Causes all other threads in the process to block themselves - * and give up their time slice. - */ - DosEnterCritSec(); - - if (!done) { - func(); - done = 1; - } - - /* Restores normal thread dispatching for the current process. */ - DosExitCritSec(); -} - #elif CONFIG_MULTITHREAD && HAVE_PTHREAD_H #include static void once(void (*func)(void)) { diff --git a/libs/libvpx/vpx_ports/vpx_ports.mk b/libs/libvpx/vpx_ports/vpx_ports.mk index e30e87cefb..b0ad210f60 100644 --- a/libs/libvpx/vpx_ports/vpx_ports.mk +++ b/libs/libvpx/vpx_ports/vpx_ports.mk @@ -14,7 +14,6 @@ PORTS_SRCS-yes += vpx_ports.mk PORTS_SRCS-yes += bitops.h PORTS_SRCS-yes += compiler_attributes.h PORTS_SRCS-yes += mem.h -PORTS_SRCS-yes += msvc.h PORTS_SRCS-yes += static_assert.h PORTS_SRCS-yes += system_state.h PORTS_SRCS-yes += vpx_timer.h @@ -36,7 +35,12 @@ PORTS_SRCS-yes += x86.h PORTS_SRCS-yes += x86_abi_support.asm endif -PORTS_SRCS-$(VPX_ARCH_ARM) += arm_cpudetect.c +ifeq ($(VPX_ARCH_AARCH64),yes) +PORTS_SRCS-yes += aarch64_cpudetect.c +else +PORTS_SRCS-$(VPX_ARCH_ARM) += aarch32_cpudetect.c +endif +PORTS_SRCS-$(VPX_ARCH_ARM) += arm_cpudetect.h PORTS_SRCS-$(VPX_ARCH_ARM) += arm.h PORTS_SRCS-$(VPX_ARCH_PPC) += ppc_cpudetect.c diff --git a/libs/libvpx/vpx_ports/vpx_timer.h b/libs/libvpx/vpx_ports/vpx_timer.h index 4934d5296a..55e7891e19 100644 --- a/libs/libvpx/vpx_ports/vpx_timer.h +++ b/libs/libvpx/vpx_ports/vpx_timer.h @@ -31,17 +31,17 @@ /* * POSIX specific includes */ -#include +#include /* timersub is not provided by msys at this time. */ -#ifndef timersub -#define timersub(a, b, result) \ +#ifndef timersub_ns +#define timersub_ns(a, b, result) \ do { \ (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - if ((result)->tv_usec < 0) { \ + (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \ + if ((result)->tv_nsec < 0) { \ --(result)->tv_sec; \ - (result)->tv_usec += 1000000; \ + (result)->tv_nsec += 1000000000; \ } \ } while (0) #endif @@ -51,23 +51,27 @@ struct vpx_usec_timer { #if defined(_WIN32) LARGE_INTEGER begin, end; #else - struct timeval begin, end; + struct timespec begin, end; #endif }; static INLINE void vpx_usec_timer_start(struct vpx_usec_timer *t) { #if defined(_WIN32) QueryPerformanceCounter(&t->begin); +#elif defined(CLOCK_MONOTONIC_RAW) + clock_gettime(CLOCK_MONOTONIC_RAW, &t->begin); #else - gettimeofday(&t->begin, NULL); + clock_gettime(CLOCK_MONOTONIC, &t->begin); #endif } static INLINE void vpx_usec_timer_mark(struct vpx_usec_timer *t) { #if defined(_WIN32) QueryPerformanceCounter(&t->end); +#elif defined(CLOCK_MONOTONIC_RAW) + clock_gettime(CLOCK_MONOTONIC_RAW, &t->end); #else - gettimeofday(&t->end, NULL); + clock_gettime(CLOCK_MONOTONIC, &t->end); #endif } @@ -80,18 +84,18 @@ static INLINE int64_t vpx_usec_timer_elapsed(struct vpx_usec_timer *t) { QueryPerformanceFrequency(&freq); return diff.QuadPart * 1000000 / freq.QuadPart; #else - struct timeval diff; + struct timespec diff; - timersub(&t->end, &t->begin, &diff); - return (int64_t)diff.tv_sec * 1000000 + diff.tv_usec; + timersub_ns(&t->end, &t->begin, &diff); + return (int64_t)diff.tv_sec * 1000000 + diff.tv_nsec / 1000; #endif } #else /* CONFIG_OS_SUPPORT = 0*/ /* Empty timer functions if CONFIG_OS_SUPPORT = 0 */ -#ifndef timersub -#define timersub(a, b, result) +#ifndef timersub_ns +#define timersub_ns(a, b, result) #endif struct vpx_usec_timer { diff --git a/libs/libvpx/vpx_ports/x86.h b/libs/libvpx/vpx_ports/x86.h index 795fb2923f..4f68bb1327 100644 --- a/libs/libvpx/vpx_ports/x86.h +++ b/libs/libvpx/vpx_ports/x86.h @@ -42,7 +42,7 @@ typedef enum { VPX_CPU_LAST } vpx_cpu_t; -#if defined(__GNUC__) && __GNUC__ || defined(__ANDROID__) +#if defined(__GNUC__) || defined(__ANDROID__) #if VPX_ARCH_X86_64 #define cpuid(func, func2, ax, bx, cx, dx) \ __asm__ __volatile__("cpuid \n\t" \ @@ -164,6 +164,27 @@ static INLINE uint64_t xgetbv(void) { #define BIT(n) (1u << (n)) #endif +#define MMX_BITS BIT(23) +#define SSE_BITS BIT(25) +#define SSE2_BITS BIT(26) +#define SSE3_BITS BIT(0) +#define SSSE3_BITS BIT(9) +#define SSE4_1_BITS BIT(19) +// Bits 27 (OSXSAVE) & 28 (256-bit AVX) +#define AVX_BITS (BIT(27) | BIT(28)) +#define AVX2_BITS BIT(5) +// Bits 16 (AVX-512F) & 17 (AVX-512DQ) & 28 (AVX-512CD) & 30 (AVX-512BW) +// & 31 (AVX-512VL) +#define AVX512_BITS (BIT(16) | BIT(17) | BIT(28) | BIT(30) | BIT(31)) +// Bits 1 (AVX512-VBMI) & 6 (AVX512-VBMI2) & 8 (AVX512-GFNI) & 9 (AVX512-VAES) & +// 10 (AVX512-VPCLMULQDQ) & 11 (AVX512-VNNI) & 12 (AVX512-BITALG) & +// 14 (AVX512-POPCNTDQ) +#define AVX512_DL_BITS \ + (BIT(1) | BIT(6) | BIT(8) | BIT(9) | BIT(10) | BIT(11) | BIT(12) | BIT(14)) + +#define FEATURE_SET(reg, feature) \ + (((reg) & (feature##_BITS)) == (feature##_BITS)) + static INLINE int x86_simd_caps(void) { unsigned int flags = 0; unsigned int mask = ~0u; @@ -173,58 +194,45 @@ static INLINE int x86_simd_caps(void) { /* See if the CPU capabilities are being overridden by the environment */ env = getenv("VPX_SIMD_CAPS"); - if (env && *env) return (int)strtol(env, NULL, 0); env = getenv("VPX_SIMD_CAPS_MASK"); - if (env && *env) mask = (unsigned int)strtoul(env, NULL, 0); /* Ensure that the CPUID instruction supports extended features */ cpuid(0, 0, max_cpuid_val, reg_ebx, reg_ecx, reg_edx); - if (max_cpuid_val < 1) return 0; /* Get the standard feature flags */ cpuid(1, 0, reg_eax, reg_ebx, reg_ecx, reg_edx); - if (reg_edx & BIT(23)) flags |= HAS_MMX; + flags |= FEATURE_SET(reg_edx, MMX) ? HAS_MMX : 0; + flags |= FEATURE_SET(reg_edx, SSE) ? HAS_SSE : 0; + flags |= FEATURE_SET(reg_edx, SSE2) ? HAS_SSE2 : 0; + flags |= FEATURE_SET(reg_ecx, SSE3) ? HAS_SSE3 : 0; + flags |= FEATURE_SET(reg_ecx, SSSE3) ? HAS_SSSE3 : 0; + flags |= FEATURE_SET(reg_ecx, SSE4_1) ? HAS_SSE4_1 : 0; - if (reg_edx & BIT(25)) flags |= HAS_SSE; /* aka xmm */ - - if (reg_edx & BIT(26)) flags |= HAS_SSE2; /* aka wmt */ - - if (reg_ecx & BIT(0)) flags |= HAS_SSE3; - - if (reg_ecx & BIT(9)) flags |= HAS_SSSE3; - - if (reg_ecx & BIT(19)) flags |= HAS_SSE4_1; - - // bits 27 (OSXSAVE) & 28 (256-bit AVX) - if ((reg_ecx & (BIT(27) | BIT(28))) == (BIT(27) | BIT(28))) { + if (FEATURE_SET(reg_ecx, AVX)) { // Check for OS-support of YMM state. Necessary for AVX and AVX2. if ((xgetbv() & 0x6) == 0x6) { flags |= HAS_AVX; - if (max_cpuid_val >= 7) { /* Get the leaf 7 feature flags. Needed to check for AVX2 support */ cpuid(7, 0, reg_eax, reg_ebx, reg_ecx, reg_edx); - - if (reg_ebx & BIT(5)) flags |= HAS_AVX2; - - // bits 16 (AVX-512F) & 17 (AVX-512DQ) & 28 (AVX-512CD) & - // 30 (AVX-512BW) & 32 (AVX-512VL) - if ((reg_ebx & (BIT(16) | BIT(17) | BIT(28) | BIT(30) | BIT(31))) == - (BIT(16) | BIT(17) | BIT(28) | BIT(30) | BIT(31))) { + flags |= FEATURE_SET(reg_ebx, AVX2) ? HAS_AVX2 : 0; + if (FEATURE_SET(reg_ebx, AVX512)) { // Check for OS-support of ZMM and YMM state. Necessary for AVX-512. - if ((xgetbv() & 0xe6) == 0xe6) flags |= HAS_AVX512; + if ((xgetbv() & 0xe6) == 0xe6) { + // Older AVX512 implementations (such as Skylake) have turbo curves + // that are currently problematic for mixed AVX512/AVX2 code + flags |= FEATURE_SET(reg_ecx, AVX512_DL) ? HAS_AVX512 : 0; + } } } } } - (void)reg_eax; // Avoid compiler warning on unused-but-set variable. - return flags & mask; } @@ -249,13 +257,13 @@ static INLINE int x86_simd_caps(void) { // x86_readtsc64 to read the timestamp counter in a 64-bit integer. The // out-of-order leakage that can occur is minimal compared to total runtime. static INLINE unsigned int x86_readtsc(void) { -#if defined(__GNUC__) && __GNUC__ +#if defined(__GNUC__) unsigned int tsc; - __asm__ __volatile__("rdtsc\n\t" : "=a"(tsc) :); + __asm__ __volatile__("rdtsc\n\t" : "=a"(tsc) : : "edx"); return tsc; #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) unsigned int tsc; - asm volatile("rdtsc\n\t" : "=a"(tsc) :); + asm volatile("rdtsc\n\t" : "=a"(tsc) : : "edx"); return tsc; #else #if VPX_ARCH_X86_64 @@ -267,7 +275,7 @@ static INLINE unsigned int x86_readtsc(void) { } // 64-bit CPU cycle counter static INLINE uint64_t x86_readtsc64(void) { -#if defined(__GNUC__) && __GNUC__ +#if defined(__GNUC__) uint32_t hi, lo; __asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi)); return ((uint64_t)hi << 32) | lo; @@ -286,13 +294,13 @@ static INLINE uint64_t x86_readtsc64(void) { // 32-bit CPU cycle counter with a partial fence against out-of-order execution. static INLINE unsigned int x86_readtscp(void) { -#if defined(__GNUC__) && __GNUC__ +#if defined(__GNUC__) unsigned int tscp; - __asm__ __volatile__("rdtscp\n\t" : "=a"(tscp) :); + __asm__ __volatile__("rdtscp\n\t" : "=a"(tscp) : : "edx"); return tscp; #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) unsigned int tscp; - asm volatile("rdtscp\n\t" : "=a"(tscp) :); + asm volatile("rdtscp\n\t" : "=a"(tscp) : : "edx"); return tscp; #elif defined(_MSC_VER) unsigned int ui; @@ -331,7 +339,7 @@ static INLINE unsigned int x86_tsc_end(void) { return v; } -#if defined(__GNUC__) && __GNUC__ +#if defined(__GNUC__) #define x86_pause_hint() __asm__ __volatile__("pause \n\t") #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) #define x86_pause_hint() asm volatile("pause \n\t") @@ -343,7 +351,7 @@ static INLINE unsigned int x86_tsc_end(void) { #endif #endif -#if defined(__GNUC__) && __GNUC__ +#if defined(__GNUC__) static void x87_set_control_word(unsigned short mode) { __asm__ __volatile__("fldcw %0" : : "m"(*&mode)); } diff --git a/libs/libvpx/vpx_ports/x86_abi_support.asm b/libs/libvpx/vpx_ports/x86_abi_support.asm index 6b2d6b9684..aece83283d 100644 --- a/libs/libvpx/vpx_ports/x86_abi_support.asm +++ b/libs/libvpx/vpx_ports/x86_abi_support.asm @@ -395,6 +395,10 @@ section .text %endmacro %elifidn __OUTPUT_FORMAT__,aout %define SECTION_RODATA section .data +%elifidn __OUTPUT_FORMAT__,win32 +%define SECTION_RODATA section .rdata +%elif LIBVPX_YASM_WIN64 +%define SECTION_RODATA section .rdata %else %define SECTION_RODATA section .rodata %endif diff --git a/libs/libvpx/vpx_scale/generic/vpx_scale.c b/libs/libvpx/vpx_scale/generic/vpx_scale.c index e20905e9ce..36d6d3628a 100644 --- a/libs/libvpx/vpx_scale/generic/vpx_scale.c +++ b/libs/libvpx/vpx_scale/generic/vpx_scale.c @@ -19,6 +19,8 @@ /**************************************************************************** * Header Files ****************************************************************************/ +#include + #include "./vpx_scale_rtcd.h" #include "vpx_mem/vpx_mem.h" #include "vpx_scale/vpx_scale.h" @@ -167,13 +169,12 @@ static void scale1d_c(const unsigned char *source, int source_step, (void)source_length; - assert(dest_scale); - /* These asserts are needed if there are boundary issues... */ /*assert ( dest_scale > source_scale );*/ /*assert ( (source_length-1) * dest_scale >= (dest_length-1) * source_scale * );*/ + assert(dest_scale != 0); for (i = 0; i < dest_length * dest_step; i += dest_step) { dest[i] = (char)((left_modifier * left_pixel + right_modifier * right_pixel + round_value) / diff --git a/libs/libvpx/vpx_scale/generic/yv12config.c b/libs/libvpx/vpx_scale/generic/yv12config.c index c52dab0588..07deeb2016 100644 --- a/libs/libvpx/vpx_scale/generic/yv12config.c +++ b/libs/libvpx/vpx_scale/generic/yv12config.c @@ -10,6 +10,7 @@ #include #include +#include #include "vpx_scale/yv12config.h" #include "vpx_mem/vpx_mem.h" @@ -26,7 +27,7 @@ * ****************************************************************************/ #define yv12_align_addr(addr, align) \ - (void *)(((size_t)(addr) + ((align)-1)) & (size_t) - (align)) + (void *)(((size_t)(addr) + ((align) - 1)) & (size_t)-(align)) int vp8_yv12_de_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf) { if (ybf) { @@ -199,11 +200,13 @@ int vpx_realloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height, if (frame_size > VPX_MAX_ALLOCABLE_MEMORY / REF_FRAMES) return -1; #endif // VPX_MAX_ALLOCABLE_MEMORY +#if UINT64_MAX > SIZE_MAX // frame_size is stored in buffer_alloc_sz, which is a size_t. If it won't // fit, fail early. if (frame_size > SIZE_MAX) { return -1; } +#endif if (cb != NULL) { const int align_addr_extra_size = 31; diff --git a/libs/libvpx/vpx_scale/vpx_scale.h b/libs/libvpx/vpx_scale/vpx_scale.h index 96edb7af20..fd5ba7ccdc 100644 --- a/libs/libvpx/vpx_scale/vpx_scale.h +++ b/libs/libvpx/vpx_scale/vpx_scale.h @@ -11,8 +11,6 @@ #ifndef VPX_VPX_SCALE_VPX_SCALE_H_ #define VPX_VPX_SCALE_VPX_SCALE_H_ -#include - #include "vpx_scale/yv12config.h" extern void vpx_scale_frame(YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst, diff --git a/libs/libvpx/vpx_scale/vpx_scale_rtcd.c b/libs/libvpx/vpx_scale/vpx_scale_rtcd.c index dc4d9593a8..706b0770c8 100644 --- a/libs/libvpx/vpx_scale/vpx_scale_rtcd.c +++ b/libs/libvpx/vpx_scale/vpx_scale_rtcd.c @@ -12,4 +12,4 @@ #include "./vpx_scale_rtcd.h" #include "vpx_ports/vpx_once.h" -void vpx_scale_rtcd() { once(setup_rtcd_internal); } +void vpx_scale_rtcd(void) { once(setup_rtcd_internal); } diff --git a/libs/libvpx/vpx_util/vpx_atomics.h b/libs/libvpx/vpx_util/vpx_atomics.h index 23ad566851..13c1fc11f6 100644 --- a/libs/libvpx/vpx_util/vpx_atomics.h +++ b/libs/libvpx/vpx_util/vpx_atomics.h @@ -72,8 +72,7 @@ typedef struct vpx_atomic_int { volatile int value; } vpx_atomic_int; -#define VPX_ATOMIC_INIT(num) \ - { num } +#define VPX_ATOMIC_INIT(num) { num } // Initialization of an atomic int, not thread safe. static INLINE void vpx_atomic_init(vpx_atomic_int *atomic, int value) { diff --git a/libs/libvpx/vpx_util/vpx_pthread.h b/libs/libvpx/vpx_util/vpx_pthread.h new file mode 100644 index 0000000000..8bb94df73f --- /dev/null +++ b/libs/libvpx/vpx_util/vpx_pthread.h @@ -0,0 +1,154 @@ +// Copyright 2024 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +// pthread.h wrapper + +#ifndef VPX_VPX_UTIL_VPX_PTHREAD_H_ +#define VPX_VPX_UTIL_VPX_PTHREAD_H_ + +#include "./vpx_config.h" + +#if CONFIG_MULTITHREAD + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) && !HAVE_PTHREAD_H +// Prevent leaking max/min macros. +#undef NOMINMAX +#define NOMINMAX +#undef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#include // NOLINT +#include // NOLINT +#include // NOLINT +typedef HANDLE pthread_t; +typedef SRWLOCK pthread_mutex_t; + +#if _WIN32_WINNT < 0x0600 +#error _WIN32_WINNT must target Windows Vista / Server 2008 or newer. +#endif +typedef CONDITION_VARIABLE pthread_cond_t; + +#ifndef WINAPI_FAMILY_PARTITION +#define WINAPI_PARTITION_DESKTOP 1 +#define WINAPI_FAMILY_PARTITION(x) x +#endif + +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +#define USE_CREATE_THREAD +#endif + +//------------------------------------------------------------------------------ +// simplistic pthread emulation layer + +// _beginthreadex requires __stdcall +#if defined(__GNUC__) && \ + (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) +#define THREADFN __attribute__((force_align_arg_pointer)) unsigned int __stdcall +#else +#define THREADFN unsigned int __stdcall +#endif +#define THREAD_EXIT_SUCCESS 0 + +static INLINE int pthread_create(pthread_t *const thread, const void *attr, + unsigned int(__stdcall *start)(void *), + void *arg) { + (void)attr; +#ifdef USE_CREATE_THREAD + *thread = CreateThread(NULL, /* lpThreadAttributes */ + 0, /* dwStackSize */ + start, arg, 0, /* dwStackSize */ + NULL); /* lpThreadId */ +#else + *thread = (pthread_t)_beginthreadex(NULL, /* void *security */ + 0, /* unsigned stack_size */ + start, arg, 0, /* unsigned initflag */ + NULL); /* unsigned *thrdaddr */ +#endif + if (*thread == NULL) return 1; + SetThreadPriority(*thread, THREAD_PRIORITY_ABOVE_NORMAL); + return 0; +} + +static INLINE int pthread_join(pthread_t thread, void **value_ptr) { + (void)value_ptr; + return (WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0 || + CloseHandle(thread) == 0); +} + +// Mutex +static INLINE int pthread_mutex_init(pthread_mutex_t *const mutex, + void *mutexattr) { + (void)mutexattr; + InitializeSRWLock(mutex); + return 0; +} + +static INLINE int pthread_mutex_trylock(pthread_mutex_t *const mutex) { + return TryAcquireSRWLockExclusive(mutex) ? 0 : EBUSY; +} + +static INLINE int pthread_mutex_lock(pthread_mutex_t *const mutex) { + AcquireSRWLockExclusive(mutex); + return 0; +} + +static INLINE int pthread_mutex_unlock(pthread_mutex_t *const mutex) { + ReleaseSRWLockExclusive(mutex); + return 0; +} + +static INLINE int pthread_mutex_destroy(pthread_mutex_t *const mutex) { + (void)mutex; + return 0; +} + +// Condition +static INLINE int pthread_cond_destroy(pthread_cond_t *const condition) { + (void)condition; + return 0; +} + +static INLINE int pthread_cond_init(pthread_cond_t *const condition, + void *cond_attr) { + (void)cond_attr; + InitializeConditionVariable(condition); + return 0; +} + +static INLINE int pthread_cond_signal(pthread_cond_t *const condition) { + WakeConditionVariable(condition); + return 0; +} + +static INLINE int pthread_cond_broadcast(pthread_cond_t *const condition) { + WakeAllConditionVariable(condition); + return 0; +} + +static INLINE int pthread_cond_wait(pthread_cond_t *const condition, + pthread_mutex_t *const mutex) { + const int ok = SleepConditionVariableSRW(condition, mutex, INFINITE, 0); + return !ok; +} +#else // _WIN32 +#include // NOLINT +#define THREADFN void * +#define THREAD_EXIT_SUCCESS NULL +#endif + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // CONFIG_MULTITHREAD + +#endif // VPX_VPX_UTIL_VPX_PTHREAD_H_ diff --git a/libs/libvpx/vpx_util/vpx_thread.c b/libs/libvpx/vpx_util/vpx_thread.c index 04c5fb6f26..fe703c2dca 100644 --- a/libs/libvpx/vpx_util/vpx_thread.c +++ b/libs/libvpx/vpx_util/vpx_thread.c @@ -12,10 +12,18 @@ // Original source: // https://chromium.googlesource.com/webm/libwebp +// Enable GNU extensions in glibc so that we can call pthread_setname_np(). +// This must be before any #include statements. +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + #include #include // for memset() +#include "./vpx_config.h" #include "./vpx_thread.h" #include "vpx_mem/vpx_mem.h" +#include "vpx_util/vpx_pthread.h" #if CONFIG_MULTITHREAD @@ -31,23 +39,56 @@ static void execute(VPxWorker *const worker); // Forward declaration. static THREADFN thread_loop(void *ptr) { VPxWorker *const worker = (VPxWorker *)ptr; - int done = 0; - while (!done) { - pthread_mutex_lock(&worker->impl_->mutex_); - while (worker->status_ == OK) { // wait in idling mode +#ifdef HAVE_PTHREAD_SETNAME_NP +#ifdef __APPLE__ + if (worker->thread_name != NULL) { + // Apple's version of pthread_setname_np takes one argument and operates on + // the current thread only. The maximum size of the thread_name buffer was + // noted in the Chromium source code and was confirmed by experiments. If + // thread_name is too long, pthread_setname_np returns -1 with errno + // ENAMETOOLONG (63). + char thread_name[64]; + strncpy(thread_name, worker->thread_name, sizeof(thread_name) - 1); + thread_name[sizeof(thread_name) - 1] = '\0'; + pthread_setname_np(thread_name); + } +#elif (defined(__GLIBC__) && !defined(__GNU__)) || defined(__BIONIC__) + if (worker->thread_name != NULL) { + // Linux and Android require names (with nul) fit in 16 chars, otherwise + // pthread_setname_np() returns ERANGE (34). + char thread_name[16]; + strncpy(thread_name, worker->thread_name, sizeof(thread_name) - 1); + thread_name[sizeof(thread_name) - 1] = '\0'; + pthread_setname_np(pthread_self(), thread_name); + } +#endif +#endif + pthread_mutex_lock(&worker->impl_->mutex_); + for (;;) { + while (worker->status_ == VPX_WORKER_STATUS_OK) { // wait in idling mode pthread_cond_wait(&worker->impl_->condition_, &worker->impl_->mutex_); } - if (worker->status_ == WORK) { + if (worker->status_ == VPX_WORKER_STATUS_WORKING) { + // When worker->status_ is VPX_WORKER_STATUS_WORKING, the main thread + // doesn't change worker->status_ and will wait until the worker changes + // worker->status_ to VPX_WORKER_STATUS_OK. See change_state(). So the + // worker can safely call execute() without holding worker->impl_->mutex_. + // When the worker reacquires worker->impl_->mutex_, worker->status_ must + // still be VPX_WORKER_STATUS_WORKING. + pthread_mutex_unlock(&worker->impl_->mutex_); execute(worker); - worker->status_ = OK; - } else if (worker->status_ == NOT_OK) { // finish the worker - done = 1; + pthread_mutex_lock(&worker->impl_->mutex_); + assert(worker->status_ == VPX_WORKER_STATUS_WORKING); + worker->status_ = VPX_WORKER_STATUS_OK; + // signal to the main thread that we're done (for sync()) + pthread_cond_signal(&worker->impl_->condition_); + } else { + assert(worker->status_ == VPX_WORKER_STATUS_NOT_OK); // finish the worker + break; } - // signal to the main thread that we're done (for sync()) - pthread_cond_signal(&worker->impl_->condition_); - pthread_mutex_unlock(&worker->impl_->mutex_); } - return THREAD_RETURN(NULL); // Thread is finished + pthread_mutex_unlock(&worker->impl_->mutex_); + return THREAD_EXIT_SUCCESS; // Thread is finished } // main thread state control @@ -58,13 +99,13 @@ static void change_state(VPxWorker *const worker, VPxWorkerStatus new_status) { if (worker->impl_ == NULL) return; pthread_mutex_lock(&worker->impl_->mutex_); - if (worker->status_ >= OK) { + if (worker->status_ >= VPX_WORKER_STATUS_OK) { // wait for the worker to finish - while (worker->status_ != OK) { + while (worker->status_ != VPX_WORKER_STATUS_OK) { pthread_cond_wait(&worker->impl_->condition_, &worker->impl_->mutex_); } // assign new status and release the working thread if needed - if (new_status != OK) { + if (new_status != VPX_WORKER_STATUS_OK) { worker->status_ = new_status; pthread_cond_signal(&worker->impl_->condition_); } @@ -78,21 +119,21 @@ static void change_state(VPxWorker *const worker, VPxWorkerStatus new_status) { static void init(VPxWorker *const worker) { memset(worker, 0, sizeof(*worker)); - worker->status_ = NOT_OK; + worker->status_ = VPX_WORKER_STATUS_NOT_OK; } static int sync(VPxWorker *const worker) { #if CONFIG_MULTITHREAD - change_state(worker, OK); + change_state(worker, VPX_WORKER_STATUS_OK); #endif - assert(worker->status_ <= OK); + assert(worker->status_ <= VPX_WORKER_STATUS_OK); return !worker->had_error; } static int reset(VPxWorker *const worker) { int ok = 1; worker->had_error = 0; - if (worker->status_ < OK) { + if (worker->status_ < VPX_WORKER_STATUS_OK) { #if CONFIG_MULTITHREAD worker->impl_ = (VPxWorkerImpl *)vpx_calloc(1, sizeof(*worker->impl_)); if (worker->impl_ == NULL) { @@ -107,7 +148,7 @@ static int reset(VPxWorker *const worker) { } pthread_mutex_lock(&worker->impl_->mutex_); ok = !pthread_create(&worker->impl_->thread_, NULL, thread_loop, worker); - if (ok) worker->status_ = OK; + if (ok) worker->status_ = VPX_WORKER_STATUS_OK; pthread_mutex_unlock(&worker->impl_->mutex_); if (!ok) { pthread_mutex_destroy(&worker->impl_->mutex_); @@ -118,12 +159,12 @@ static int reset(VPxWorker *const worker) { return 0; } #else - worker->status_ = OK; + worker->status_ = VPX_WORKER_STATUS_OK; #endif - } else if (worker->status_ > OK) { + } else if (worker->status_ > VPX_WORKER_STATUS_OK) { ok = sync(worker); } - assert(!ok || (worker->status_ == OK)); + assert(!ok || (worker->status_ == VPX_WORKER_STATUS_OK)); return ok; } @@ -135,7 +176,7 @@ static void execute(VPxWorker *const worker) { static void launch(VPxWorker *const worker) { #if CONFIG_MULTITHREAD - change_state(worker, WORK); + change_state(worker, VPX_WORKER_STATUS_WORKING); #else execute(worker); #endif @@ -144,7 +185,7 @@ static void launch(VPxWorker *const worker) { static void end(VPxWorker *const worker) { #if CONFIG_MULTITHREAD if (worker->impl_ != NULL) { - change_state(worker, NOT_OK); + change_state(worker, VPX_WORKER_STATUS_NOT_OK); pthread_join(worker->impl_->thread_, NULL); pthread_mutex_destroy(&worker->impl_->mutex_); pthread_cond_destroy(&worker->impl_->condition_); @@ -152,10 +193,10 @@ static void end(VPxWorker *const worker) { worker->impl_ = NULL; } #else - worker->status_ = NOT_OK; + worker->status_ = VPX_WORKER_STATUS_NOT_OK; assert(worker->impl_ == NULL); #endif - assert(worker->status_ == NOT_OK); + assert(worker->status_ == VPX_WORKER_STATUS_NOT_OK); } //------------------------------------------------------------------------------ diff --git a/libs/libvpx/vpx_util/vpx_thread.h b/libs/libvpx/vpx_util/vpx_thread.h index 6d308e949b..22051eae41 100644 --- a/libs/libvpx/vpx_util/vpx_thread.h +++ b/libs/libvpx/vpx_util/vpx_thread.h @@ -15,370 +15,20 @@ #ifndef VPX_VPX_UTIL_VPX_THREAD_H_ #define VPX_VPX_UTIL_VPX_THREAD_H_ -#include "./vpx_config.h" - #ifdef __cplusplus extern "C" { #endif -// Set maximum decode threads to be 8 due to the limit of frame buffers -// and not enough semaphores in the emulation layer on windows. -#define MAX_DECODE_THREADS 8 - -#if CONFIG_MULTITHREAD - -#if defined(_WIN32) && !HAVE_PTHREAD_H -#include // NOLINT -#include // NOLINT -#include // NOLINT -typedef HANDLE pthread_t; -typedef CRITICAL_SECTION pthread_mutex_t; - -#if _WIN32_WINNT >= 0x0600 // Windows Vista / Server 2008 or greater -#define USE_WINDOWS_CONDITION_VARIABLE -typedef CONDITION_VARIABLE pthread_cond_t; -#else -typedef struct { - HANDLE waiting_sem_; - HANDLE received_sem_; - HANDLE signal_event_; -} pthread_cond_t; -#endif // _WIN32_WINNT >= 0x600 - -#ifndef WINAPI_FAMILY_PARTITION -#define WINAPI_PARTITION_DESKTOP 1 -#define WINAPI_FAMILY_PARTITION(x) x -#endif - -#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -#define USE_CREATE_THREAD -#endif - -//------------------------------------------------------------------------------ -// simplistic pthread emulation layer - -// _beginthreadex requires __stdcall -#if defined(__GNUC__) && \ - (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) -#define THREADFN __attribute__((force_align_arg_pointer)) unsigned int __stdcall -#else -#define THREADFN unsigned int __stdcall -#endif -#define THREAD_RETURN(val) (unsigned int)((DWORD_PTR)val) - -#if _WIN32_WINNT >= 0x0501 // Windows XP or greater -#define WaitForSingleObject(obj, timeout) \ - WaitForSingleObjectEx(obj, timeout, FALSE /*bAlertable*/) -#endif - -static INLINE int pthread_create(pthread_t *const thread, const void *attr, - unsigned int(__stdcall *start)(void *), - void *arg) { - (void)attr; -#ifdef USE_CREATE_THREAD - *thread = CreateThread(NULL, /* lpThreadAttributes */ - 0, /* dwStackSize */ - start, arg, 0, /* dwStackSize */ - NULL); /* lpThreadId */ -#else - *thread = (pthread_t)_beginthreadex(NULL, /* void *security */ - 0, /* unsigned stack_size */ - start, arg, 0, /* unsigned initflag */ - NULL); /* unsigned *thrdaddr */ -#endif - if (*thread == NULL) return 1; - SetThreadPriority(*thread, THREAD_PRIORITY_ABOVE_NORMAL); - return 0; -} - -static INLINE int pthread_join(pthread_t thread, void **value_ptr) { - (void)value_ptr; - return (WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0 || - CloseHandle(thread) == 0); -} - -// Mutex -static INLINE int pthread_mutex_init(pthread_mutex_t *const mutex, - void *mutexattr) { - (void)mutexattr; -#if _WIN32_WINNT >= 0x0600 // Windows Vista / Server 2008 or greater - InitializeCriticalSectionEx(mutex, 0 /*dwSpinCount*/, 0 /*Flags*/); -#else - InitializeCriticalSection(mutex); -#endif - return 0; -} - -static INLINE int pthread_mutex_trylock(pthread_mutex_t *const mutex) { - return TryEnterCriticalSection(mutex) ? 0 : EBUSY; -} - -static INLINE int pthread_mutex_lock(pthread_mutex_t *const mutex) { - EnterCriticalSection(mutex); - return 0; -} - -static INLINE int pthread_mutex_unlock(pthread_mutex_t *const mutex) { - LeaveCriticalSection(mutex); - return 0; -} - -static INLINE int pthread_mutex_destroy(pthread_mutex_t *const mutex) { - DeleteCriticalSection(mutex); - return 0; -} - -// Condition -static INLINE int pthread_cond_destroy(pthread_cond_t *const condition) { - int ok = 1; -#ifdef USE_WINDOWS_CONDITION_VARIABLE - (void)condition; -#else - ok &= (CloseHandle(condition->waiting_sem_) != 0); - ok &= (CloseHandle(condition->received_sem_) != 0); - ok &= (CloseHandle(condition->signal_event_) != 0); -#endif - return !ok; -} - -static INLINE int pthread_cond_init(pthread_cond_t *const condition, - void *cond_attr) { - (void)cond_attr; -#ifdef USE_WINDOWS_CONDITION_VARIABLE - InitializeConditionVariable(condition); -#else - condition->waiting_sem_ = CreateSemaphore(NULL, 0, MAX_DECODE_THREADS, NULL); - condition->received_sem_ = CreateSemaphore(NULL, 0, MAX_DECODE_THREADS, NULL); - condition->signal_event_ = CreateEvent(NULL, FALSE, FALSE, NULL); - if (condition->waiting_sem_ == NULL || condition->received_sem_ == NULL || - condition->signal_event_ == NULL) { - pthread_cond_destroy(condition); - return 1; - } -#endif - return 0; -} - -static INLINE int pthread_cond_broadcast(pthread_cond_t *const condition) { - int ok = 1; -#ifdef USE_WINDOWS_CONDITION_VARIABLE - WakeAllConditionVariable(condition); -#else - while (WaitForSingleObject(condition->waiting_sem_, 0) == WAIT_OBJECT_0) { - // a thread is waiting in pthread_cond_wait: allow it to be notified - ok &= SetEvent(condition->signal_event_); - // wait until the event is consumed so the signaler cannot consume - // the event via its own pthread_cond_wait. - ok &= (WaitForSingleObject(condition->received_sem_, INFINITE) != - WAIT_OBJECT_0); - } -#endif - return !ok; -} - -static INLINE int pthread_cond_signal(pthread_cond_t *const condition) { - int ok = 1; -#ifdef USE_WINDOWS_CONDITION_VARIABLE - WakeConditionVariable(condition); -#else - if (WaitForSingleObject(condition->waiting_sem_, 0) == WAIT_OBJECT_0) { - // a thread is waiting in pthread_cond_wait: allow it to be notified - ok = SetEvent(condition->signal_event_); - // wait until the event is consumed so the signaler cannot consume - // the event via its own pthread_cond_wait. - ok &= (WaitForSingleObject(condition->received_sem_, INFINITE) != - WAIT_OBJECT_0); - } -#endif - return !ok; -} - -static INLINE int pthread_cond_wait(pthread_cond_t *const condition, - pthread_mutex_t *const mutex) { - int ok; -#ifdef USE_WINDOWS_CONDITION_VARIABLE - ok = SleepConditionVariableCS(condition, mutex, INFINITE); -#else - // note that there is a consumer available so the signal isn't dropped in - // pthread_cond_signal - if (!ReleaseSemaphore(condition->waiting_sem_, 1, NULL)) return 1; - // now unlock the mutex so pthread_cond_signal may be issued - pthread_mutex_unlock(mutex); - ok = (WaitForSingleObject(condition->signal_event_, INFINITE) == - WAIT_OBJECT_0); - ok &= ReleaseSemaphore(condition->received_sem_, 1, NULL); - pthread_mutex_lock(mutex); -#endif - return !ok; -} - -#elif defined(__OS2__) -#define INCL_DOS -#include // NOLINT - -#include // NOLINT -#include // NOLINT -#include // NOLINT - -#if defined(__STRICT_ANSI__) -// _beginthread() is not declared on __STRICT_ANSI__ mode. Declare here. -int _beginthread(void (*)(void *), void *, unsigned, void *); -#endif - -#define pthread_t TID -#define pthread_mutex_t HMTX - -typedef struct { - HEV event_sem_; - HEV ack_sem_; - volatile unsigned wait_count_; -} pthread_cond_t; - -//------------------------------------------------------------------------------ -// simplistic pthread emulation layer - -#define THREADFN void * -#define THREAD_RETURN(val) (val) - -typedef struct { - void *(*start_)(void *); - void *arg_; -} thread_arg; - -static void thread_start(void *arg) { - thread_arg targ = *(thread_arg *)arg; - free(arg); - - targ.start_(targ.arg_); -} - -static INLINE int pthread_create(pthread_t *const thread, const void *attr, - void *(*start)(void *), void *arg) { - int tid; - thread_arg *targ = (thread_arg *)malloc(sizeof(*targ)); - if (targ == NULL) return 1; - - (void)attr; - - targ->start_ = start; - targ->arg_ = arg; - tid = (pthread_t)_beginthread(thread_start, NULL, 1024 * 1024, targ); - if (tid == -1) { - free(targ); - return 1; - } - - *thread = tid; - return 0; -} - -static INLINE int pthread_join(pthread_t thread, void **value_ptr) { - (void)value_ptr; - return DosWaitThread(&thread, DCWW_WAIT) != 0; -} - -// Mutex -static INLINE int pthread_mutex_init(pthread_mutex_t *const mutex, - void *mutexattr) { - (void)mutexattr; - return DosCreateMutexSem(NULL, mutex, 0, FALSE) != 0; -} - -static INLINE int pthread_mutex_trylock(pthread_mutex_t *const mutex) { - return DosRequestMutexSem(*mutex, SEM_IMMEDIATE_RETURN) == 0 ? 0 : EBUSY; -} - -static INLINE int pthread_mutex_lock(pthread_mutex_t *const mutex) { - return DosRequestMutexSem(*mutex, SEM_INDEFINITE_WAIT) != 0; -} - -static INLINE int pthread_mutex_unlock(pthread_mutex_t *const mutex) { - return DosReleaseMutexSem(*mutex) != 0; -} - -static INLINE int pthread_mutex_destroy(pthread_mutex_t *const mutex) { - return DosCloseMutexSem(*mutex) != 0; -} - -// Condition -static INLINE int pthread_cond_destroy(pthread_cond_t *const condition) { - int ok = 1; - ok &= DosCloseEventSem(condition->event_sem_) == 0; - ok &= DosCloseEventSem(condition->ack_sem_) == 0; - return !ok; -} - -static INLINE int pthread_cond_init(pthread_cond_t *const condition, - void *cond_attr) { - int ok = 1; - (void)cond_attr; - - ok &= - DosCreateEventSem(NULL, &condition->event_sem_, DCE_POSTONE, FALSE) == 0; - ok &= DosCreateEventSem(NULL, &condition->ack_sem_, DCE_POSTONE, FALSE) == 0; - if (!ok) { - pthread_cond_destroy(condition); - return 1; - } - condition->wait_count_ = 0; - return 0; -} - -static INLINE int pthread_cond_signal(pthread_cond_t *const condition) { - int ok = 1; - - if (!__atomic_cmpxchg32(&condition->wait_count_, 0, 0)) { - ok &= DosPostEventSem(condition->event_sem_) == 0; - ok &= DosWaitEventSem(condition->ack_sem_, SEM_INDEFINITE_WAIT) == 0; - } - - return !ok; -} - -static INLINE int pthread_cond_broadcast(pthread_cond_t *const condition) { - int ok = 1; - - while (!__atomic_cmpxchg32(&condition->wait_count_, 0, 0)) - ok &= pthread_cond_signal(condition) == 0; - - return !ok; -} - -static INLINE int pthread_cond_wait(pthread_cond_t *const condition, - pthread_mutex_t *const mutex) { - int ok = 1; - - __atomic_increment(&condition->wait_count_); - - ok &= pthread_mutex_unlock(mutex) == 0; - - ok &= DosWaitEventSem(condition->event_sem_, SEM_INDEFINITE_WAIT) == 0; - - __atomic_decrement(&condition->wait_count_); - - ok &= DosPostEventSem(condition->ack_sem_) == 0; - - pthread_mutex_lock(mutex); - - return !ok; -} -#else // _WIN32 -#include // NOLINT -#define THREADFN void * -#define THREAD_RETURN(val) val -#endif - -#endif // CONFIG_MULTITHREAD - // State of the worker thread object typedef enum { - NOT_OK = 0, // object is unusable - OK, // ready to work - WORK // busy finishing the current task + VPX_WORKER_STATUS_NOT_OK = 0, // object is unusable + VPX_WORKER_STATUS_OK, // ready to work + VPX_WORKER_STATUS_WORKING // busy finishing the current task } VPxWorkerStatus; // Function to be called by the worker thread. Takes two opaque pointers as -// arguments (data1 and data2), and should return false in case of error. +// arguments (data1 and data2). Should return true on success and return false +// in case of error. typedef int (*VPxWorkerHook)(void *, void *); // Platform-dependent implementation details for the worker. @@ -388,10 +38,14 @@ typedef struct VPxWorkerImpl VPxWorkerImpl; typedef struct { VPxWorkerImpl *impl_; VPxWorkerStatus status_; + // Thread name for the debugger. If not NULL, must point to a string that + // outlives the worker thread. For portability, use a name <= 15 characters + // long (not including the terminating NUL character). + const char *thread_name; VPxWorkerHook hook; // hook to call void *data1; // first argument passed to 'hook' void *data2; // second argument passed to 'hook' - int had_error; // return value of the last call to 'hook' + int had_error; // true if a call to 'hook' returned false } VPxWorker; // The interface for all thread-worker related functions. All these functions diff --git a/libs/libvpx/vpx_util/vpx_util.mk b/libs/libvpx/vpx_util/vpx_util.mk index 1162714956..948e6d6f89 100644 --- a/libs/libvpx/vpx_util/vpx_util.mk +++ b/libs/libvpx/vpx_util/vpx_util.mk @@ -10,6 +10,7 @@ UTIL_SRCS-yes += vpx_atomics.h UTIL_SRCS-yes += vpx_util.mk +UTIL_SRCS-yes += vpx_pthread.h UTIL_SRCS-yes += vpx_thread.c UTIL_SRCS-yes += vpx_thread.h UTIL_SRCS-yes += endian_inl.h diff --git a/libs/libvpx/vpxdec.c b/libs/libvpx/vpxdec.c index 84cef7dfd4..4128498267 100644 --- a/libs/libvpx/vpxdec.c +++ b/libs/libvpx/vpxdec.c @@ -446,7 +446,7 @@ static void generate_filename(const char *pattern, char *out, size_t q_len, case '7': snprintf(q, q_len - 1, "%07d", frame_in); break; case '8': snprintf(q, q_len - 1, "%08d", frame_in); break; case '9': snprintf(q, q_len - 1, "%09d", frame_in); break; - default: die("Unrecognized pattern %%%c\n", p[1]); break; + default: die("Unrecognized pattern %%%c\n", p[1]); } pat_len = strlen(q); @@ -696,12 +696,6 @@ static int main_loop(int argc, const char **argv_) { fprintf(stderr, "No input file specified!\n"); usage_exit(); } - /* Open file */ - infile = strcmp(fn, "-") ? fopen(fn, "rb") : set_binary_mode(stdin); - - if (!infile) { - fatal("Failed to open input file '%s'", strcmp(fn, "-") ? fn : "stdin"); - } #if CONFIG_OS_SUPPORT /* Make sure we don't dump to the terminal, unless forced to with -o - */ if (!outfile_pattern && isatty(fileno(stdout)) && !do_md5 && !noblit) { @@ -711,6 +705,13 @@ static int main_loop(int argc, const char **argv_) { return EXIT_FAILURE; } #endif + + /* Open file */ + infile = strcmp(fn, "-") ? fopen(fn, "rb") : set_binary_mode(stdin); + + if (!infile) { + fatal("Failed to open input file '%s'", strcmp(fn, "-") ? fn : "stdin"); + } input.vpx_input_ctx->file = infile; if (file_is_ivf(input.vpx_input_ctx)) input.vpx_input_ctx->file_type = FILE_TYPE_IVF; @@ -746,7 +747,7 @@ static int main_loop(int argc, const char **argv_) { fprintf(stderr, "YUV4MPEG2 not supported with output patterns," " try --i420 or --yv12 or --rawvideo.\n"); - return EXIT_FAILURE; + goto fail2; } #if CONFIG_WEBM_IO @@ -755,7 +756,7 @@ static int main_loop(int argc, const char **argv_) { fprintf(stderr, "Failed to guess framerate -- error parsing " "webm file?\n"); - return EXIT_FAILURE; + goto fail2; } } #endif @@ -996,7 +997,7 @@ static int main_loop(int argc, const char **argv_) { if (single_file) { if (use_y4m) { - char buf[Y4M_BUFFER_SIZE] = { 0 }; + char y4m_buf[Y4M_BUFFER_SIZE] = { 0 }; size_t len = 0; if (img->fmt == VPX_IMG_FMT_I440 || img->fmt == VPX_IMG_FMT_I44016) { fprintf(stderr, "Cannot produce y4m output for 440 sampling.\n"); @@ -1005,21 +1006,22 @@ static int main_loop(int argc, const char **argv_) { if (frame_out == 1) { // Y4M file header len = y4m_write_file_header( - buf, sizeof(buf), vpx_input_ctx.width, vpx_input_ctx.height, - &vpx_input_ctx.framerate, img->fmt, img->bit_depth); + y4m_buf, sizeof(y4m_buf), vpx_input_ctx.width, + vpx_input_ctx.height, &vpx_input_ctx.framerate, img->fmt, + img->bit_depth); if (do_md5) { - MD5Update(&md5_ctx, (md5byte *)buf, (unsigned int)len); + MD5Update(&md5_ctx, (md5byte *)y4m_buf, (unsigned int)len); } else { - fputs(buf, outfile); + fputs(y4m_buf, outfile); } } // Y4M frame header - len = y4m_write_frame_header(buf, sizeof(buf)); + len = y4m_write_frame_header(y4m_buf, sizeof(y4m_buf)); if (do_md5) { - MD5Update(&md5_ctx, (md5byte *)buf, (unsigned int)len); + MD5Update(&md5_ctx, (md5byte *)y4m_buf, (unsigned int)len); } else { - fputs(buf, outfile); + fputs(y4m_buf, outfile); } } else { if (frame_out == 1) { diff --git a/libs/libvpx/vpxenc.c b/libs/libvpx/vpxenc.c index 7eff97b132..ee0a9991ab 100644 --- a/libs/libvpx/vpxenc.c +++ b/libs/libvpx/vpxenc.c @@ -444,6 +444,9 @@ static const arg_def_t tile_rows = static const arg_def_t enable_tpl_model = ARG_DEF(NULL, "enable-tpl", 1, "Enable temporal dependency model"); +static const arg_def_t enable_keyframe_filtering = + ARG_DEF(NULL, "enable-keyframe-filtering", 1, + "Enable key frame temporal filtering (0: off (default), 1: on)"); static const arg_def_t lossless = ARG_DEF(NULL, "lossless", 1, "Lossless mode (0: false (default), 1: true)"); @@ -494,7 +497,7 @@ static const arg_def_t bitdeptharg = ARG_DEF_ENUM( "Bit depth for codec (8 for version <=1, 10 or 12 for version 2)", bitdepth_enum); static const arg_def_t inbitdeptharg = - ARG_DEF(NULL, "input-bit-depth", 1, "Bit depth of input"); + ARG_DEF(NULL, "input-bit-depth", 1, "Actual bit depth of input source"); #endif static const struct arg_enum_list tune_content_enum[] = { @@ -524,10 +527,18 @@ static const arg_def_t row_mt = static const arg_def_t disable_loopfilter = ARG_DEF(NULL, "disable-loopfilter", 1, - "Control Loopfilter in VP9\n" + "Control Loopfilter in VP9:\n" + " " "0: Loopfilter on for all frames (default)\n" + " " "1: Loopfilter off for non reference frames\n" + " " "2: Loopfilter off for all frames"); +static const arg_def_t validate_hbd_input = + ARG_DEF(NULL, "validate-hbd-input", 1, + "Check that input samples are within the valid range " + "for the chosen bit depth with high bit depth encoding (0: " + "disabled, 1: enabled (default))"); #endif #if CONFIG_VP9_ENCODER @@ -538,6 +549,7 @@ static const arg_def_t *vp9_args[] = { &cpu_used_vp9, &tile_cols, &tile_rows, &enable_tpl_model, + &enable_keyframe_filtering, &arnr_maxframes, &arnr_strength, &arnr_type, @@ -559,6 +571,7 @@ static const arg_def_t *vp9_args[] = { &cpu_used_vp9, &target_level, &row_mt, &disable_loopfilter, + &validate_hbd_input, // NOTE: The entries above have a corresponding entry in vp9_arg_ctrl_map. The // entries below do not have a corresponding entry in vp9_arg_ctrl_map. They // must be listed at the end of vp9_args. @@ -574,6 +587,7 @@ static const int vp9_arg_ctrl_map[] = { VP8E_SET_CPUUSED, VP9E_SET_TILE_COLUMNS, VP9E_SET_TILE_ROWS, VP9E_SET_TPL, + VP9E_SET_KEY_FRAME_FILTERING, VP8E_SET_ARNR_MAXFRAMES, VP8E_SET_ARNR_STRENGTH, VP8E_SET_ARNR_TYPE, @@ -595,6 +609,7 @@ static const int vp9_arg_ctrl_map[] = { VP8E_SET_CPUUSED, VP9E_SET_TARGET_LEVEL, VP9E_SET_ROW_MT, VP9E_SET_DISABLE_LOOPFILTER, + VP9E_SET_VALIDATE_HBD_INPUT, 0 }; #endif @@ -711,7 +726,7 @@ static void validate_positive_rational(const char *msg, rat->den *= -1; } - if (rat->num < 0) die("Error: %s must be positive\n", msg); + if (rat->num <= 0) die("Error: %s must be positive\n", msg); if (!rat->den) die("Error: %s has zero denominator\n", msg); } @@ -844,7 +859,7 @@ static struct stream_state *new_stream(struct VpxEncoderConfig *global, } if (prev) { - memcpy(stream, prev, sizeof(*stream)); + *stream = *prev; stream->index++; prev->next = stream; } else { @@ -880,7 +895,7 @@ static struct stream_state *new_stream(struct VpxEncoderConfig *global, /* Default lag_in_frames is 0 in realtime mode CBR mode*/ if (global->deadline == VPX_DL_REALTIME && - stream->config.cfg.rc_end_usage == 1) + stream->config.cfg.rc_end_usage == VPX_CBR) stream->config.cfg.g_lag_in_frames = 0; } @@ -895,8 +910,8 @@ static int parse_stream_params(struct VpxEncoderConfig *global, struct stream_state *stream, char **argv) { char **argi, **argj; struct arg arg; - static const arg_def_t **ctrl_args = no_args; - static const int *ctrl_args_map = NULL; + const arg_def_t **ctrl_args = no_args; + const int *ctrl_args_map = NULL; struct stream_config *config = &stream->config; int eos_mark_found = 0; #if CONFIG_VP9_HIGHBITDEPTH @@ -1583,13 +1598,14 @@ static void test_decode(struct stream_state *stream, /* Get the internal reference frame */ if (strcmp(codec->name, "vp8") == 0) { struct vpx_ref_frame ref_enc, ref_dec; - int width, height; + unsigned int aligned_width = (stream->config.cfg.g_w + 15u) & ~15u; + unsigned int aligned_height = (stream->config.cfg.g_h + 15u) & ~15u; - width = (stream->config.cfg.g_w + 15) & ~15; - height = (stream->config.cfg.g_h + 15) & ~15; - vpx_img_alloc(&ref_enc.img, VPX_IMG_FMT_I420, width, height, 1); + vpx_img_alloc(&ref_enc.img, VPX_IMG_FMT_I420, aligned_width, aligned_height, + 1); enc_img = ref_enc.img; - vpx_img_alloc(&ref_dec.img, VPX_IMG_FMT_I420, width, height, 1); + vpx_img_alloc(&ref_dec.img, VPX_IMG_FMT_I420, aligned_width, aligned_height, + 1); dec_img = ref_dec.img; ref_enc.frame_type = VP8_LAST_FRAME; @@ -1966,10 +1982,9 @@ int main(int argc, const char **argv_) { } else { const int64_t input_pos = ftello(input.file); const int64_t input_pos_lagged = input_pos - lagged_count; - const int64_t limit = input.length; rate = cx_time ? input_pos_lagged * (int64_t)1000000 / cx_time : 0; - remaining = limit - input_pos + lagged_count; + remaining = input.length - input_pos + lagged_count; } average_rate = diff --git a/libs/libvpx/webmdec.cc b/libs/libvpx/webmdec.cc index f7671bb641..0576bb4978 100644 --- a/libs/libvpx/webmdec.cc +++ b/libs/libvpx/webmdec.cc @@ -179,7 +179,7 @@ int webm_read_frame(struct WebmInputContext *webm_ctx, uint8_t **buffer, block->GetFrame(webm_ctx->block_frame_index); ++webm_ctx->block_frame_index; if (frame.len > static_cast(*buffer_size)) { - delete[] * buffer; + delete[] *buffer; *buffer = new uint8_t[frame.len]; if (*buffer == nullptr) { return -1; diff --git a/libs/libvpx/webmdec.h b/libs/libvpx/webmdec.h index d8618b07d6..6ae7ee16d0 100644 --- a/libs/libvpx/webmdec.h +++ b/libs/libvpx/webmdec.h @@ -27,7 +27,7 @@ struct WebmInputContext { const void *block; int block_frame_index; int video_track_index; - uint64_t timestamp_ns; + int64_t timestamp_ns; int is_key_frame; int reached_eos; }; diff --git a/libs/libvpx/y4menc.c b/libs/libvpx/y4menc.c index 02b729e5bb..3940249cb9 100644 --- a/libs/libvpx/y4menc.c +++ b/libs/libvpx/y4menc.c @@ -9,6 +9,7 @@ */ #include +#include #include "./y4menc.h" int y4m_write_file_header(char *buf, size_t len, int width, int height, @@ -17,39 +18,34 @@ int y4m_write_file_header(char *buf, size_t len, int width, int height, const char *color; switch (bit_depth) { case 8: - color = fmt == VPX_IMG_FMT_I444 - ? "C444\n" - : fmt == VPX_IMG_FMT_I422 ? "C422\n" : "C420jpeg\n"; + color = fmt == VPX_IMG_FMT_I444 ? "C444\n" + : fmt == VPX_IMG_FMT_I422 ? "C422\n" + : "C420jpeg\n"; break; case 9: - color = fmt == VPX_IMG_FMT_I44416 - ? "C444p9 XYSCSS=444P9\n" - : fmt == VPX_IMG_FMT_I42216 ? "C422p9 XYSCSS=422P9\n" - : "C420p9 XYSCSS=420P9\n"; + color = fmt == VPX_IMG_FMT_I44416 ? "C444p9 XYSCSS=444P9\n" + : fmt == VPX_IMG_FMT_I42216 ? "C422p9 XYSCSS=422P9\n" + : "C420p9 XYSCSS=420P9\n"; break; case 10: - color = fmt == VPX_IMG_FMT_I44416 - ? "C444p10 XYSCSS=444P10\n" - : fmt == VPX_IMG_FMT_I42216 ? "C422p10 XYSCSS=422P10\n" - : "C420p10 XYSCSS=420P10\n"; + color = fmt == VPX_IMG_FMT_I44416 ? "C444p10 XYSCSS=444P10\n" + : fmt == VPX_IMG_FMT_I42216 ? "C422p10 XYSCSS=422P10\n" + : "C420p10 XYSCSS=420P10\n"; break; case 12: - color = fmt == VPX_IMG_FMT_I44416 - ? "C444p12 XYSCSS=444P12\n" - : fmt == VPX_IMG_FMT_I42216 ? "C422p12 XYSCSS=422P12\n" - : "C420p12 XYSCSS=420P12\n"; + color = fmt == VPX_IMG_FMT_I44416 ? "C444p12 XYSCSS=444P12\n" + : fmt == VPX_IMG_FMT_I42216 ? "C422p12 XYSCSS=422P12\n" + : "C420p12 XYSCSS=420P12\n"; break; case 14: - color = fmt == VPX_IMG_FMT_I44416 - ? "C444p14 XYSCSS=444P14\n" - : fmt == VPX_IMG_FMT_I42216 ? "C422p14 XYSCSS=422P14\n" - : "C420p14 XYSCSS=420P14\n"; + color = fmt == VPX_IMG_FMT_I44416 ? "C444p14 XYSCSS=444P14\n" + : fmt == VPX_IMG_FMT_I42216 ? "C422p14 XYSCSS=422P14\n" + : "C420p14 XYSCSS=420P14\n"; break; case 16: - color = fmt == VPX_IMG_FMT_I44416 - ? "C444p16 XYSCSS=444P16\n" - : fmt == VPX_IMG_FMT_I42216 ? "C422p16 XYSCSS=422P16\n" - : "C420p16 XYSCSS=420P16\n"; + color = fmt == VPX_IMG_FMT_I44416 ? "C444p16 XYSCSS=444P16\n" + : fmt == VPX_IMG_FMT_I42216 ? "C422p16 XYSCSS=422P16\n" + : "C420p16 XYSCSS=420P16\n"; break; default: color = NULL; assert(0); } diff --git a/libs/libvpx/y4minput.c b/libs/libvpx/y4minput.c index 7d3c03a7fc..76a27b2edf 100644 --- a/libs/libvpx/y4minput.c +++ b/libs/libvpx/y4minput.c @@ -12,6 +12,8 @@ */ #include #include +#include +#include #include #include @@ -21,12 +23,13 @@ // Reads 'size' bytes from 'file' into 'buf' with some fault tolerance. // Returns true on success. static int file_read(void *buf, size_t size, FILE *file) { - const int kMaxRetries = 5; - int retry_count = 0; - int file_error; + const int kMaxTries = 5; + int try_count = 0; + int file_error = 0; size_t len = 0; - do { + while (!feof(file) && len < size && try_count < kMaxTries) { const size_t n = fread((uint8_t *)buf + len, 1, size - len, file); + ++try_count; len += n; file_error = ferror(file); if (file_error) { @@ -39,13 +42,13 @@ static int file_read(void *buf, size_t size, FILE *file) { return 0; } } - } while (!feof(file) && len < size && ++retry_count < kMaxRetries); + } if (!feof(file) && len != size) { fprintf(stderr, "Error reading file: %u of %u bytes read," - " error: %d, retries: %d, %d: %s\n", - (uint32_t)len, (uint32_t)size, file_error, retry_count, errno, + " error: %d, tries: %d, %d: %s\n", + (uint32_t)len, (uint32_t)size, file_error, try_count, errno, strerror(errno)); } return len == size; @@ -66,10 +69,12 @@ static int y4m_parse_tags(y4m_input *_y4m, char *_tags) { switch (p[0]) { case 'W': { if (sscanf(p + 1, "%d", &_y4m->pic_w) != 1) return -1; + if (_y4m->pic_w <= 0) return -1; break; } case 'H': { if (sscanf(p + 1, "%d", &_y4m->pic_h) != 1) return -1; + if (_y4m->pic_h <= 0) return -1; break; } case 'F': { @@ -176,6 +181,14 @@ static int parse_tags(y4m_input *y4m_ctx, FILE *file) { fprintf(stderr, "FPS field missing\n"); return 0; } + /* Validate dimensions to prevent integer overflow in buffer size + calculations. The factor of 6 accounts for the most demanding buffer + formula: 2 * 3 * pic_w * pic_h (444 format at high bit-depth). */ + if ((int64_t)y4m_ctx->pic_w * y4m_ctx->pic_h > INT_MAX / 6) { + fprintf(stderr, "Y4M dimensions %dx%d are too large.\n", y4m_ctx->pic_w, + y4m_ctx->pic_h); + return 0; + } return 1; } @@ -1147,6 +1160,7 @@ int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, vpx_image_t *_img) { _img->fmt = _y4m->vpx_fmt; _img->w = _img->d_w = _y4m->pic_w; _img->h = _img->d_h = _y4m->pic_h; + _img->bit_depth = _y4m->bit_depth; _img->x_chroma_shift = _y4m->dst_c_dec_h >> 1; _img->y_chroma_shift = _y4m->dst_c_dec_v >> 1; _img->bps = _y4m->bps; @@ -1157,12 +1171,12 @@ int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, vpx_image_t *_img) { c_w *= bytes_per_sample; c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; c_sz = c_w * c_h; - _img->stride[VPX_PLANE_Y] = _img->stride[VPX_PLANE_ALPHA] = - _y4m->pic_w * bytes_per_sample; + _img->stride[VPX_PLANE_Y] = _y4m->pic_w * bytes_per_sample; _img->stride[VPX_PLANE_U] = _img->stride[VPX_PLANE_V] = c_w; + _img->stride[VPX_PLANE_ALPHA] = 0; _img->planes[VPX_PLANE_Y] = _y4m->dst_buf; _img->planes[VPX_PLANE_U] = _y4m->dst_buf + pic_sz; _img->planes[VPX_PLANE_V] = _y4m->dst_buf + pic_sz + c_sz; - _img->planes[VPX_PLANE_ALPHA] = _y4m->dst_buf + pic_sz + 2 * c_sz; + _img->planes[VPX_PLANE_ALPHA] = NULL; return 1; } diff --git a/libs/win32/libvpx/include_x64/vp8_rtcd.h b/libs/win32/libvpx/include_x64/vp8_rtcd.h index 25de852111..c2dcf5e3ef 100644 --- a/libs/win32/libvpx/include_x64/vp8_rtcd.h +++ b/libs/win32/libvpx/include_x64/vp8_rtcd.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2017 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + // This file is generated. Do not edit. #ifndef VP8_RTCD_H_ #define VP8_RTCD_H_ @@ -45,15 +55,6 @@ void vp8_bilinear_predict8x8_sse2(unsigned char *src_ptr, int src_pixels_per_lin void vp8_bilinear_predict8x8_ssse3(unsigned char *src_ptr, int src_pixels_per_line, int xoffset, int yoffset, unsigned char *dst_ptr, int dst_pitch); RTCD_EXTERN void (*vp8_bilinear_predict8x8)(unsigned char *src_ptr, int src_pixels_per_line, int xoffset, int yoffset, unsigned char *dst_ptr, int dst_pitch); -void vp8_blend_b_c(unsigned char *y, unsigned char *u, unsigned char *v, int y_1, int u_1, int v_1, int alpha, int stride); -#define vp8_blend_b vp8_blend_b_c - -void vp8_blend_mb_inner_c(unsigned char *y, unsigned char *u, unsigned char *v, int y_1, int u_1, int v_1, int alpha, int stride); -#define vp8_blend_mb_inner vp8_blend_mb_inner_c - -void vp8_blend_mb_outer_c(unsigned char *y, unsigned char *u, unsigned char *v, int y_1, int u_1, int v_1, int alpha, int stride); -#define vp8_blend_mb_outer vp8_blend_mb_outer_c - int vp8_block_error_c(short *coeff, short *dqcoeff); int vp8_block_error_sse2(short *coeff, short *dqcoeff); #define vp8_block_error vp8_block_error_sse2 @@ -254,4 +255,4 @@ static void setup_rtcd_internal(void) } // extern "C" #endif -#endif +#endif // VP8_RTCD_H_ diff --git a/libs/win32/libvpx/include_x64/vp9_rtcd.h b/libs/win32/libvpx/include_x64/vp9_rtcd.h index bd81bb1bc9..99b9036cdb 100644 --- a/libs/win32/libvpx/include_x64/vp9_rtcd.h +++ b/libs/win32/libvpx/include_x64/vp9_rtcd.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2017 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + // This file is generated. Do not edit. #ifndef VP9_RTCD_H_ #define VP9_RTCD_H_ @@ -16,12 +26,17 @@ #include "vp9/common/vp9_common.h" #include "vp9/common/vp9_enums.h" #include "vp9/common/vp9_filter.h" +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +#include "vp9/encoder/vp9_temporal_filter.h" +#endif struct macroblockd; /* Encoder forward decls */ struct macroblock; -struct vp9_variance_vtable; +struct macroblock_plane; +struct vp9_sad_table; +struct ScanOrder; struct search_site_config; struct mv; union int_mv; @@ -45,9 +60,8 @@ int64_t vp9_block_error_fp_sse2(const tran_low_t *coeff, const tran_low_t *dqcoe int64_t vp9_block_error_fp_avx2(const tran_low_t *coeff, const tran_low_t *dqcoeff, int block_size); RTCD_EXTERN int64_t (*vp9_block_error_fp)(const tran_low_t *coeff, const tran_low_t *dqcoeff, int block_size); -int vp9_diamond_search_sad_c(const struct macroblock *x, const struct search_site_config *cfg, struct mv *ref_mv, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, const struct vp9_variance_vtable *fn_ptr, const struct mv *center_mv); -int vp9_diamond_search_sad_avx(const struct macroblock *x, const struct search_site_config *cfg, struct mv *ref_mv, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, const struct vp9_variance_vtable *fn_ptr, const struct mv *center_mv); -RTCD_EXTERN int (*vp9_diamond_search_sad)(const struct macroblock *x, const struct search_site_config *cfg, struct mv *ref_mv, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, const struct vp9_variance_vtable *fn_ptr, const struct mv *center_mv); +int vp9_diamond_search_sad_c(const struct macroblock *x, const struct search_site_config *cfg, struct mv *ref_mv, uint32_t start_mv_sad, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, const struct vp9_sad_table *sad_fn_ptr, const struct mv *center_mv); +#define vp9_diamond_search_sad vp9_diamond_search_sad_c void vp9_fht16x16_c(const int16_t *input, tran_low_t *output, int stride, int tx_type); void vp9_fht16x16_sse2(const int16_t *input, tran_low_t *output, int stride, int tx_type); @@ -77,20 +91,36 @@ void vp9_iht8x8_64_add_c(const tran_low_t *input, uint8_t *dest, int stride, int void vp9_iht8x8_64_add_sse2(const tran_low_t *input, uint8_t *dest, int stride, int tx_type); #define vp9_iht8x8_64_add vp9_iht8x8_64_add_sse2 -void vp9_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vp9_quantize_fp_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vp9_quantize_fp_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vp9_quantize_fp_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -RTCD_EXTERN void (*vp9_quantize_fp)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); +void vp9_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vp9_quantize_fp_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vp9_quantize_fp_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vp9_quantize_fp_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +RTCD_EXTERN void (*vp9_quantize_fp)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); -void vp9_quantize_fp_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vp9_quantize_fp_32x32_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -RTCD_EXTERN void (*vp9_quantize_fp_32x32)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); +void vp9_quantize_fp_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vp9_quantize_fp_32x32_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vp9_quantize_fp_32x32_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +RTCD_EXTERN void (*vp9_quantize_fp_32x32)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); void vp9_scale_and_extend_frame_c(const struct yv12_buffer_config *src, struct yv12_buffer_config *dst, INTERP_FILTER filter_type, int phase_scaler); void vp9_scale_and_extend_frame_ssse3(const struct yv12_buffer_config *src, struct yv12_buffer_config *dst, INTERP_FILTER filter_type, int phase_scaler); RTCD_EXTERN void (*vp9_scale_and_extend_frame)(const struct yv12_buffer_config *src, struct yv12_buffer_config *dst, INTERP_FILTER filter_type, int phase_scaler); +void vpx_convolve12_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_ssse3(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_avx2(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +RTCD_EXTERN void (*vpx_convolve12)(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); + +void vpx_convolve12_horiz_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_horiz_ssse3(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_horiz_avx2(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +RTCD_EXTERN void (*vpx_convolve12_horiz)(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); + +void vpx_convolve12_vert_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_vert_ssse3(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_vert_avx2(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +RTCD_EXTERN void (*vpx_convolve12_vert)(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); + void vp9_rtcd(void); #ifdef RTCD_C @@ -107,15 +137,23 @@ static void setup_rtcd_internal(void) if (flags & HAS_AVX2) vp9_block_error = vp9_block_error_avx2; vp9_block_error_fp = vp9_block_error_fp_sse2; if (flags & HAS_AVX2) vp9_block_error_fp = vp9_block_error_fp_avx2; - vp9_diamond_search_sad = vp9_diamond_search_sad_c; - if (flags & HAS_AVX) vp9_diamond_search_sad = vp9_diamond_search_sad_avx; vp9_quantize_fp = vp9_quantize_fp_sse2; if (flags & HAS_SSSE3) vp9_quantize_fp = vp9_quantize_fp_ssse3; if (flags & HAS_AVX2) vp9_quantize_fp = vp9_quantize_fp_avx2; vp9_quantize_fp_32x32 = vp9_quantize_fp_32x32_c; if (flags & HAS_SSSE3) vp9_quantize_fp_32x32 = vp9_quantize_fp_32x32_ssse3; + if (flags & HAS_AVX2) vp9_quantize_fp_32x32 = vp9_quantize_fp_32x32_avx2; vp9_scale_and_extend_frame = vp9_scale_and_extend_frame_c; if (flags & HAS_SSSE3) vp9_scale_and_extend_frame = vp9_scale_and_extend_frame_ssse3; + vpx_convolve12 = vpx_convolve12_c; + if (flags & HAS_SSSE3) vpx_convolve12 = vpx_convolve12_ssse3; + if (flags & HAS_AVX2) vpx_convolve12 = vpx_convolve12_avx2; + vpx_convolve12_horiz = vpx_convolve12_horiz_c; + if (flags & HAS_SSSE3) vpx_convolve12_horiz = vpx_convolve12_horiz_ssse3; + if (flags & HAS_AVX2) vpx_convolve12_horiz = vpx_convolve12_horiz_avx2; + vpx_convolve12_vert = vpx_convolve12_vert_c; + if (flags & HAS_SSSE3) vpx_convolve12_vert = vpx_convolve12_vert_ssse3; + if (flags & HAS_AVX2) vpx_convolve12_vert = vpx_convolve12_vert_avx2; } #endif @@ -123,4 +161,4 @@ static void setup_rtcd_internal(void) } // extern "C" #endif -#endif +#endif // VP9_RTCD_H_ diff --git a/libs/win32/libvpx/include_x64/vpx/vpx_config.h b/libs/win32/libvpx/include_x64/vpx/vpx_config.h index ebb1134735..0e101d13ba 100644 --- a/libs/win32/libvpx/include_x64/vpx/vpx_config.h +++ b/libs/win32/libvpx/include_x64/vpx/vpx_config.h @@ -11,17 +11,23 @@ #define RESTRICT #define INLINE __inline #define VPX_ARCH_ARM 0 +#define VPX_ARCH_AARCH64 0 #define VPX_ARCH_MIPS 0 #define VPX_ARCH_X86 0 #define VPX_ARCH_X86_64 1 #define VPX_ARCH_PPC 0 #define VPX_ARCH_LOONGARCH 0 -#define HAVE_NEON 0 #define HAVE_NEON_ASM 0 +#define HAVE_NEON 0 +#define HAVE_NEON_DOTPROD 0 +#define HAVE_NEON_I8MM 0 +#define HAVE_SVE 0 +#define HAVE_SVE2 0 #define HAVE_MIPS32 0 #define HAVE_DSPR2 0 #define HAVE_MSA 0 #define HAVE_MIPS64 0 +#define HAVE_X86_ASM 1 #define HAVE_MMX 1 #define HAVE_SSE 1 #define HAVE_SSE2 1 @@ -37,6 +43,7 @@ #define HAVE_LASX 0 #define HAVE_VPX_PORTS 1 #define HAVE_PTHREAD_H 0 +#define HAVE_PTHREAD_SETNAME_NP 0 #define HAVE_UNISTD_H 0 #define CONFIG_DEPENDENCY_TRACKING 1 #define CONFIG_EXTERNAL_BUILD 1 @@ -87,7 +94,6 @@ #define CONFIG_MULTI_RES_ENCODING 0 #define CONFIG_TEMPORAL_DENOISING 1 #define CONFIG_VP9_TEMPORAL_DENOISING 0 -#define CONFIG_CONSISTENT_RECODE 0 #define CONFIG_COEFFICIENT_RANGE_CHECKING 0 #define CONFIG_VP9_HIGHBITDEPTH 0 #define CONFIG_BETTER_HW_COMPATIBILITY 0 @@ -99,7 +105,7 @@ #define CONFIG_FP_MB_STATS 0 #define CONFIG_EMULATE_HARDWARE 0 #define CONFIG_NON_GREEDY_MV 0 -#define CONFIG_RATE_CTRL 0 +#define CONFIG_COLLECT_COMPONENT_TIMING 0 #define DECODE_WIDTH_LIMIT 16384 #define DECODE_HEIGHT_LIMIT 16384 #endif /* VPX_CONFIG_H */ diff --git a/libs/win32/libvpx/include_x64/vpx_config.asm b/libs/win32/libvpx/include_x64/vpx_config.asm index 8a07b3d7aa..7b3a41e308 100644 --- a/libs/win32/libvpx/include_x64/vpx_config.asm +++ b/libs/win32/libvpx/include_x64/vpx_config.asm @@ -1,15 +1,21 @@ VPX_ARCH_ARM equ 0 +VPX_ARCH_AARCH64 equ 0 VPX_ARCH_MIPS equ 0 VPX_ARCH_X86 equ 0 VPX_ARCH_X86_64 equ 1 VPX_ARCH_PPC equ 0 VPX_ARCH_LOONGARCH equ 0 -HAVE_NEON equ 0 HAVE_NEON_ASM equ 0 +HAVE_NEON equ 0 +HAVE_NEON_DOTPROD equ 0 +HAVE_NEON_I8MM equ 0 +HAVE_SVE equ 0 +HAVE_SVE2 equ 0 HAVE_MIPS32 equ 0 HAVE_DSPR2 equ 0 HAVE_MSA equ 0 HAVE_MIPS64 equ 0 +HAVE_X86_ASM equ 1 HAVE_MMX equ 1 HAVE_SSE equ 1 HAVE_SSE2 equ 1 @@ -25,6 +31,7 @@ HAVE_LSX equ 0 HAVE_LASX equ 0 HAVE_VPX_PORTS equ 1 HAVE_PTHREAD_H equ 0 +HAVE_PTHREAD_SETNAME_NP equ 0 HAVE_UNISTD_H equ 0 CONFIG_DEPENDENCY_TRACKING equ 1 CONFIG_EXTERNAL_BUILD equ 1 @@ -75,7 +82,6 @@ CONFIG_ENCODE_PERF_TESTS equ 0 CONFIG_MULTI_RES_ENCODING equ 0 CONFIG_TEMPORAL_DENOISING equ 1 CONFIG_VP9_TEMPORAL_DENOISING equ 0 -CONFIG_CONSISTENT_RECODE equ 0 CONFIG_COEFFICIENT_RANGE_CHECKING equ 0 CONFIG_VP9_HIGHBITDEPTH equ 0 CONFIG_BETTER_HW_COMPATIBILITY equ 0 @@ -87,6 +93,6 @@ CONFIG_MISMATCH_DEBUG equ 0 CONFIG_FP_MB_STATS equ 0 CONFIG_EMULATE_HARDWARE equ 0 CONFIG_NON_GREEDY_MV equ 0 -CONFIG_RATE_CTRL equ 0 +CONFIG_COLLECT_COMPONENT_TIMING equ 0 DECODE_WIDTH_LIMIT equ 16384 DECODE_HEIGHT_LIMIT equ 16384 diff --git a/libs/win32/libvpx/include_x64/vpx_config.h b/libs/win32/libvpx/include_x64/vpx_config.h index ebb1134735..0e101d13ba 100644 --- a/libs/win32/libvpx/include_x64/vpx_config.h +++ b/libs/win32/libvpx/include_x64/vpx_config.h @@ -11,17 +11,23 @@ #define RESTRICT #define INLINE __inline #define VPX_ARCH_ARM 0 +#define VPX_ARCH_AARCH64 0 #define VPX_ARCH_MIPS 0 #define VPX_ARCH_X86 0 #define VPX_ARCH_X86_64 1 #define VPX_ARCH_PPC 0 #define VPX_ARCH_LOONGARCH 0 -#define HAVE_NEON 0 #define HAVE_NEON_ASM 0 +#define HAVE_NEON 0 +#define HAVE_NEON_DOTPROD 0 +#define HAVE_NEON_I8MM 0 +#define HAVE_SVE 0 +#define HAVE_SVE2 0 #define HAVE_MIPS32 0 #define HAVE_DSPR2 0 #define HAVE_MSA 0 #define HAVE_MIPS64 0 +#define HAVE_X86_ASM 1 #define HAVE_MMX 1 #define HAVE_SSE 1 #define HAVE_SSE2 1 @@ -37,6 +43,7 @@ #define HAVE_LASX 0 #define HAVE_VPX_PORTS 1 #define HAVE_PTHREAD_H 0 +#define HAVE_PTHREAD_SETNAME_NP 0 #define HAVE_UNISTD_H 0 #define CONFIG_DEPENDENCY_TRACKING 1 #define CONFIG_EXTERNAL_BUILD 1 @@ -87,7 +94,6 @@ #define CONFIG_MULTI_RES_ENCODING 0 #define CONFIG_TEMPORAL_DENOISING 1 #define CONFIG_VP9_TEMPORAL_DENOISING 0 -#define CONFIG_CONSISTENT_RECODE 0 #define CONFIG_COEFFICIENT_RANGE_CHECKING 0 #define CONFIG_VP9_HIGHBITDEPTH 0 #define CONFIG_BETTER_HW_COMPATIBILITY 0 @@ -99,7 +105,7 @@ #define CONFIG_FP_MB_STATS 0 #define CONFIG_EMULATE_HARDWARE 0 #define CONFIG_NON_GREEDY_MV 0 -#define CONFIG_RATE_CTRL 0 +#define CONFIG_COLLECT_COMPONENT_TIMING 0 #define DECODE_WIDTH_LIMIT 16384 #define DECODE_HEIGHT_LIMIT 16384 #endif /* VPX_CONFIG_H */ diff --git a/libs/win32/libvpx/include_x64/vpx_dsp_rtcd.h b/libs/win32/libvpx/include_x64/vpx_dsp_rtcd.h index 51e02c5927..69996962ad 100644 --- a/libs/win32/libvpx/include_x64/vpx_dsp_rtcd.h +++ b/libs/win32/libvpx/include_x64/vpx_dsp_rtcd.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2017 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + // This file is generated. Do not edit. #ifndef VPX_DSP_RTCD_H_ #define VPX_DSP_RTCD_H_ @@ -15,6 +25,10 @@ #include "vpx/vpx_integer.h" #include "vpx_dsp/vpx_dsp_common.h" #include "vpx_dsp/vpx_filter.h" +#if CONFIG_VP9_ENCODER + struct macroblock_plane; + struct ScanOrder; +#endif #ifdef __cplusplus @@ -31,7 +45,8 @@ unsigned int vpx_avg_8x8_sse2(const uint8_t *, int p); void vpx_comp_avg_pred_c(uint8_t *comp_pred, const uint8_t *pred, int width, int height, const uint8_t *ref, int ref_stride); void vpx_comp_avg_pred_sse2(uint8_t *comp_pred, const uint8_t *pred, int width, int height, const uint8_t *ref, int ref_stride); -#define vpx_comp_avg_pred vpx_comp_avg_pred_sse2 +void vpx_comp_avg_pred_avx2(uint8_t *comp_pred, const uint8_t *pred, int width, int height, const uint8_t *ref, int ref_stride); +RTCD_EXTERN void (*vpx_comp_avg_pred)(uint8_t *comp_pred, const uint8_t *pred, int width, int height, const uint8_t *ref, int ref_stride); void vpx_convolve8_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); void vpx_convolve8_sse2(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); @@ -237,7 +252,8 @@ void vpx_dc_top_predictor_8x8_sse2(uint8_t *dst, ptrdiff_t stride, const uint8_t void vpx_fdct16x16_c(const int16_t *input, tran_low_t *output, int stride); void vpx_fdct16x16_sse2(const int16_t *input, tran_low_t *output, int stride); -#define vpx_fdct16x16 vpx_fdct16x16_sse2 +void vpx_fdct16x16_avx2(const int16_t *input, tran_low_t *output, int stride); +RTCD_EXTERN void (*vpx_fdct16x16)(const int16_t *input, tran_low_t *output, int stride); void vpx_fdct16x16_1_c(const int16_t *input, tran_low_t *output, int stride); void vpx_fdct16x16_1_sse2(const int16_t *input, tran_low_t *output, int stride); @@ -334,7 +350,8 @@ void vpx_idct16x16_1_add_sse2(const tran_low_t *input, uint8_t *dest, int stride void vpx_idct16x16_256_add_c(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct16x16_256_add_sse2(const tran_low_t *input, uint8_t *dest, int stride); -#define vpx_idct16x16_256_add vpx_idct16x16_256_add_sse2 +void vpx_idct16x16_256_add_avx2(const tran_low_t *input, uint8_t *dest, int stride); +RTCD_EXTERN void (*vpx_idct16x16_256_add)(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct16x16_38_add_c(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct16x16_38_add_sse2(const tran_low_t *input, uint8_t *dest, int stride); @@ -342,11 +359,13 @@ void vpx_idct16x16_38_add_sse2(const tran_low_t *input, uint8_t *dest, int strid void vpx_idct32x32_1024_add_c(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct32x32_1024_add_sse2(const tran_low_t *input, uint8_t *dest, int stride); -#define vpx_idct32x32_1024_add vpx_idct32x32_1024_add_sse2 +void vpx_idct32x32_1024_add_avx2(const tran_low_t *input, uint8_t *dest, int stride); +RTCD_EXTERN void (*vpx_idct32x32_1024_add)(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct32x32_135_add_c(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct32x32_135_add_sse2(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct32x32_135_add_ssse3(const tran_low_t *input, uint8_t *dest, int stride); +void vpx_idct32x32_135_add_avx2(const tran_low_t *input, uint8_t *dest, int stride); RTCD_EXTERN void (*vpx_idct32x32_135_add)(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct32x32_1_add_c(const tran_low_t *input, uint8_t *dest, int stride); @@ -482,16 +501,18 @@ void vpx_post_proc_down_and_across_mb_row_c(unsigned char *src, unsigned char *d void vpx_post_proc_down_and_across_mb_row_sse2(unsigned char *src, unsigned char *dst, int src_pitch, int dst_pitch, int cols, unsigned char *flimits, int size); #define vpx_post_proc_down_and_across_mb_row vpx_post_proc_down_and_across_mb_row_sse2 -void vpx_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vpx_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vpx_quantize_b_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vpx_quantize_b_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -RTCD_EXTERN void (*vpx_quantize_b)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); +void vpx_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +RTCD_EXTERN void (*vpx_quantize_b)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); -void vpx_quantize_b_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vpx_quantize_b_32x32_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vpx_quantize_b_32x32_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -RTCD_EXTERN void (*vpx_quantize_b_32x32)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); +void vpx_quantize_b_32x32_c(const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_32x32_ssse3(const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_32x32_avx(const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_32x32_avx2(const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +RTCD_EXTERN void (*vpx_quantize_b_32x32)(const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); unsigned int vpx_sad16x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad16x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -501,8 +522,8 @@ unsigned int vpx_sad16x16_avg_c(const uint8_t *src_ptr, int src_stride, const ui unsigned int vpx_sad16x16_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); #define vpx_sad16x16_avg vpx_sad16x16_avg_sse2 -void vpx_sad16x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad16x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); #define vpx_sad16x16x4d vpx_sad16x16x4d_sse2 unsigned int vpx_sad16x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -513,8 +534,8 @@ unsigned int vpx_sad16x32_avg_c(const uint8_t *src_ptr, int src_stride, const ui unsigned int vpx_sad16x32_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); #define vpx_sad16x32_avg vpx_sad16x32_avg_sse2 -void vpx_sad16x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad16x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); #define vpx_sad16x32x4d vpx_sad16x32x4d_sse2 unsigned int vpx_sad16x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -525,8 +546,8 @@ unsigned int vpx_sad16x8_avg_c(const uint8_t *src_ptr, int src_stride, const uin unsigned int vpx_sad16x8_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); #define vpx_sad16x8_avg vpx_sad16x8_avg_sse2 -void vpx_sad16x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad16x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); #define vpx_sad16x8x4d vpx_sad16x8x4d_sse2 unsigned int vpx_sad32x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -539,8 +560,8 @@ unsigned int vpx_sad32x16_avg_sse2(const uint8_t *src_ptr, int src_stride, const unsigned int vpx_sad32x16_avg_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad32x16_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad32x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad32x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); #define vpx_sad32x16x4d vpx_sad32x16x4d_sse2 unsigned int vpx_sad32x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -553,10 +574,10 @@ unsigned int vpx_sad32x32_avg_sse2(const uint8_t *src_ptr, int src_stride, const unsigned int vpx_sad32x32_avg_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad32x32_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad32x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad32x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad32x32x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad32x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x32x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad32x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad32x64_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad32x64_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -568,8 +589,8 @@ unsigned int vpx_sad32x64_avg_sse2(const uint8_t *src_ptr, int src_stride, const unsigned int vpx_sad32x64_avg_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad32x64_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad32x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad32x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); #define vpx_sad32x64x4d vpx_sad32x64x4d_sse2 unsigned int vpx_sad4x4_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -580,8 +601,8 @@ unsigned int vpx_sad4x4_avg_c(const uint8_t *src_ptr, int src_stride, const uint unsigned int vpx_sad4x4_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); #define vpx_sad4x4_avg vpx_sad4x4_avg_sse2 -void vpx_sad4x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad4x4x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad4x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad4x4x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); #define vpx_sad4x4x4d vpx_sad4x4x4d_sse2 unsigned int vpx_sad4x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -592,39 +613,43 @@ unsigned int vpx_sad4x8_avg_c(const uint8_t *src_ptr, int src_stride, const uint unsigned int vpx_sad4x8_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); #define vpx_sad4x8_avg vpx_sad4x8_avg_sse2 -void vpx_sad4x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad4x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad4x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad4x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); #define vpx_sad4x8x4d vpx_sad4x8x4d_sse2 unsigned int vpx_sad64x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x32_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x32_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad64x32_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); RTCD_EXTERN unsigned int (*vpx_sad64x32)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x32_avg_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); unsigned int vpx_sad64x32_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); unsigned int vpx_sad64x32_avg_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); +unsigned int vpx_sad64x32_avg_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad64x32_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad64x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad64x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); #define vpx_sad64x32x4d vpx_sad64x32x4d_sse2 unsigned int vpx_sad64x64_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x64_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x64_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad64x64_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); RTCD_EXTERN unsigned int (*vpx_sad64x64)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x64_avg_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); unsigned int vpx_sad64x64_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); unsigned int vpx_sad64x64_avg_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); +unsigned int vpx_sad64x64_avg_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad64x64_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad64x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad64x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad64x64x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad64x64x4d_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad64x64x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x64x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x64x4d_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad64x64x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad8x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad8x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -634,8 +659,8 @@ unsigned int vpx_sad8x16_avg_c(const uint8_t *src_ptr, int src_stride, const uin unsigned int vpx_sad8x16_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); #define vpx_sad8x16_avg vpx_sad8x16_avg_sse2 -void vpx_sad8x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad8x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); #define vpx_sad8x16x4d vpx_sad8x16x4d_sse2 unsigned int vpx_sad8x4_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -646,8 +671,8 @@ unsigned int vpx_sad8x4_avg_c(const uint8_t *src_ptr, int src_stride, const uint unsigned int vpx_sad8x4_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); #define vpx_sad8x4_avg vpx_sad8x4_avg_sse2 -void vpx_sad8x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad8x4x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x4x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); #define vpx_sad8x4x4d vpx_sad8x4x4d_sse2 unsigned int vpx_sad8x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -658,10 +683,124 @@ unsigned int vpx_sad8x8_avg_c(const uint8_t *src_ptr, int src_stride, const uint unsigned int vpx_sad8x8_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); #define vpx_sad8x8_avg vpx_sad8x8_avg_sse2 -void vpx_sad8x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad8x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); #define vpx_sad8x8x4d vpx_sad8x8x4d_sse2 +unsigned int vpx_sad_skip_16x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_16x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +#define vpx_sad_skip_16x16 vpx_sad_skip_16x16_sse2 + +void vpx_sad_skip_16x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_16x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +#define vpx_sad_skip_16x16x4d vpx_sad_skip_16x16x4d_sse2 + +unsigned int vpx_sad_skip_16x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_16x32_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +#define vpx_sad_skip_16x32 vpx_sad_skip_16x32_sse2 + +void vpx_sad_skip_16x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_16x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +#define vpx_sad_skip_16x32x4d vpx_sad_skip_16x32x4d_sse2 + +unsigned int vpx_sad_skip_16x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_16x8_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +#define vpx_sad_skip_16x8 vpx_sad_skip_16x8_sse2 + +void vpx_sad_skip_16x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_16x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +#define vpx_sad_skip_16x8x4d vpx_sad_skip_16x8x4d_sse2 + +unsigned int vpx_sad_skip_32x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x16_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_32x16)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_32x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x16x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_32x16x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_32x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x32_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x32_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_32x32)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_32x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x32x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_32x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_32x64_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x64_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x64_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_32x64)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_32x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x64x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_32x64x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_4x4_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +#define vpx_sad_skip_4x4 vpx_sad_skip_4x4_c + +void vpx_sad_skip_4x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +#define vpx_sad_skip_4x4x4d vpx_sad_skip_4x4x4d_c + +unsigned int vpx_sad_skip_4x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_4x8_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +#define vpx_sad_skip_4x8 vpx_sad_skip_4x8_sse2 + +void vpx_sad_skip_4x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_4x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +#define vpx_sad_skip_4x8x4d vpx_sad_skip_4x8x4d_sse2 + +unsigned int vpx_sad_skip_64x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x32_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x32_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x32_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_64x32)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_64x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x32x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x32x4d_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_64x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_64x64_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x64_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x64_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x64_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_64x64)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_64x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x64x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x64x4d_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_64x64x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_8x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_8x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +#define vpx_sad_skip_8x16 vpx_sad_skip_8x16_sse2 + +void vpx_sad_skip_8x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_8x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +#define vpx_sad_skip_8x16x4d vpx_sad_skip_8x16x4d_sse2 + +unsigned int vpx_sad_skip_8x4_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +#define vpx_sad_skip_8x4 vpx_sad_skip_8x4_c + +void vpx_sad_skip_8x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +#define vpx_sad_skip_8x4x4d vpx_sad_skip_8x4x4d_c + +unsigned int vpx_sad_skip_8x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_8x8_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +#define vpx_sad_skip_8x8 vpx_sad_skip_8x8_sse2 + +void vpx_sad_skip_8x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_8x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +#define vpx_sad_skip_8x8x4d vpx_sad_skip_8x8x4d_sse2 + int vpx_satd_c(const int16_t *coeff, int length); int vpx_satd_sse2(const int16_t *coeff, int length); int vpx_satd_avx2(const int16_t *coeff, int length); @@ -686,6 +825,11 @@ void vpx_scaled_horiz_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, void vpx_scaled_vert_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); #define vpx_scaled_vert vpx_scaled_vert_c +int64_t vpx_sse_c(const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, int width, int height); +int64_t vpx_sse_sse4_1(const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, int width, int height); +int64_t vpx_sse_avx2(const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, int width, int height); +RTCD_EXTERN int64_t (*vpx_sse)(const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, int width, int height); + uint32_t vpx_sub_pixel_avg_variance16x16_c(const uint8_t *src_ptr, int src_stride, int x_offset, int y_offset, const uint8_t *ref_ptr, int ref_stride, uint32_t *sse, const uint8_t *second_pred); uint32_t vpx_sub_pixel_avg_variance16x16_sse2(const uint8_t *src_ptr, int src_stride, int x_offset, int y_offset, const uint8_t *ref_ptr, int ref_stride, uint32_t *sse, const uint8_t *second_pred); uint32_t vpx_sub_pixel_avg_variance16x16_ssse3(const uint8_t *src_ptr, int src_stride, int x_offset, int y_offset, const uint8_t *ref_ptr, int ref_stride, uint32_t *sse, const uint8_t *second_pred); @@ -822,7 +966,8 @@ RTCD_EXTERN uint32_t (*vpx_sub_pixel_variance8x8)(const uint8_t *src_ptr, int sr void vpx_subtract_block_c(int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride); void vpx_subtract_block_sse2(int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride); -#define vpx_subtract_block vpx_subtract_block_sse2 +void vpx_subtract_block_avx2(int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride); +RTCD_EXTERN void (*vpx_subtract_block)(int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride); uint64_t vpx_sum_squares_2d_i16_c(const int16_t *src, int stride, int size); uint64_t vpx_sum_squares_2d_i16_sse2(const int16_t *src, int stride, int size); @@ -910,15 +1055,18 @@ RTCD_EXTERN unsigned int (*vpx_variance64x64)(const uint8_t *src_ptr, int src_st unsigned int vpx_variance8x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); unsigned int vpx_variance8x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); -#define vpx_variance8x16 vpx_variance8x16_sse2 +unsigned int vpx_variance8x16_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); +RTCD_EXTERN unsigned int (*vpx_variance8x16)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); unsigned int vpx_variance8x4_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); unsigned int vpx_variance8x4_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); -#define vpx_variance8x4 vpx_variance8x4_sse2 +unsigned int vpx_variance8x4_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); +RTCD_EXTERN unsigned int (*vpx_variance8x4)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); unsigned int vpx_variance8x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); unsigned int vpx_variance8x8_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); -#define vpx_variance8x8 vpx_variance8x8_sse2 +unsigned int vpx_variance8x8_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); +RTCD_EXTERN unsigned int (*vpx_variance8x8)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); void vpx_ve_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left); #define vpx_ve_predictor_4x4 vpx_ve_predictor_4x4_c @@ -937,6 +1085,8 @@ static void setup_rtcd_internal(void) (void)flags; + vpx_comp_avg_pred = vpx_comp_avg_pred_sse2; + if (flags & HAS_AVX2) vpx_comp_avg_pred = vpx_comp_avg_pred_avx2; vpx_convolve8 = vpx_convolve8_sse2; if (flags & HAS_SSSE3) vpx_convolve8 = vpx_convolve8_ssse3; if (flags & HAS_AVX2) vpx_convolve8 = vpx_convolve8_avx2; @@ -981,6 +1131,8 @@ static void setup_rtcd_internal(void) if (flags & HAS_SSSE3) vpx_d63_predictor_4x4 = vpx_d63_predictor_4x4_ssse3; vpx_d63_predictor_8x8 = vpx_d63_predictor_8x8_c; if (flags & HAS_SSSE3) vpx_d63_predictor_8x8 = vpx_d63_predictor_8x8_ssse3; + vpx_fdct16x16 = vpx_fdct16x16_sse2; + if (flags & HAS_AVX2) vpx_fdct16x16 = vpx_fdct16x16_avx2; vpx_fdct32x32 = vpx_fdct32x32_sse2; if (flags & HAS_AVX2) vpx_fdct32x32 = vpx_fdct32x32_avx2; vpx_fdct32x32_rd = vpx_fdct32x32_rd_sse2; @@ -995,8 +1147,13 @@ static void setup_rtcd_internal(void) if (flags & HAS_AVX2) vpx_hadamard_32x32 = vpx_hadamard_32x32_avx2; vpx_hadamard_8x8 = vpx_hadamard_8x8_sse2; if (flags & HAS_SSSE3) vpx_hadamard_8x8 = vpx_hadamard_8x8_ssse3; + vpx_idct16x16_256_add = vpx_idct16x16_256_add_sse2; + if (flags & HAS_AVX2) vpx_idct16x16_256_add = vpx_idct16x16_256_add_avx2; + vpx_idct32x32_1024_add = vpx_idct32x32_1024_add_sse2; + if (flags & HAS_AVX2) vpx_idct32x32_1024_add = vpx_idct32x32_1024_add_avx2; vpx_idct32x32_135_add = vpx_idct32x32_135_add_sse2; if (flags & HAS_SSSE3) vpx_idct32x32_135_add = vpx_idct32x32_135_add_ssse3; + if (flags & HAS_AVX2) vpx_idct32x32_135_add = vpx_idct32x32_135_add_avx2; vpx_idct32x32_34_add = vpx_idct32x32_34_add_sse2; if (flags & HAS_SSSE3) vpx_idct32x32_34_add = vpx_idct32x32_34_add_ssse3; vpx_idct8x8_12_add = vpx_idct8x8_12_add_sse2; @@ -1012,9 +1169,11 @@ static void setup_rtcd_internal(void) vpx_quantize_b = vpx_quantize_b_sse2; if (flags & HAS_SSSE3) vpx_quantize_b = vpx_quantize_b_ssse3; if (flags & HAS_AVX) vpx_quantize_b = vpx_quantize_b_avx; + if (flags & HAS_AVX2) vpx_quantize_b = vpx_quantize_b_avx2; vpx_quantize_b_32x32 = vpx_quantize_b_32x32_c; if (flags & HAS_SSSE3) vpx_quantize_b_32x32 = vpx_quantize_b_32x32_ssse3; if (flags & HAS_AVX) vpx_quantize_b_32x32 = vpx_quantize_b_32x32_avx; + if (flags & HAS_AVX2) vpx_quantize_b_32x32 = vpx_quantize_b_32x32_avx2; vpx_sad32x16 = vpx_sad32x16_sse2; if (flags & HAS_AVX2) vpx_sad32x16 = vpx_sad32x16_avx2; vpx_sad32x16_avg = vpx_sad32x16_avg_sse2; @@ -1031,19 +1190,50 @@ static void setup_rtcd_internal(void) if (flags & HAS_AVX2) vpx_sad32x64_avg = vpx_sad32x64_avg_avx2; vpx_sad64x32 = vpx_sad64x32_sse2; if (flags & HAS_AVX2) vpx_sad64x32 = vpx_sad64x32_avx2; + if (flags & HAS_AVX512) vpx_sad64x32 = vpx_sad64x32_avx512; vpx_sad64x32_avg = vpx_sad64x32_avg_sse2; if (flags & HAS_AVX2) vpx_sad64x32_avg = vpx_sad64x32_avg_avx2; + if (flags & HAS_AVX512) vpx_sad64x32_avg = vpx_sad64x32_avg_avx512; vpx_sad64x64 = vpx_sad64x64_sse2; if (flags & HAS_AVX2) vpx_sad64x64 = vpx_sad64x64_avx2; + if (flags & HAS_AVX512) vpx_sad64x64 = vpx_sad64x64_avx512; vpx_sad64x64_avg = vpx_sad64x64_avg_sse2; if (flags & HAS_AVX2) vpx_sad64x64_avg = vpx_sad64x64_avg_avx2; + if (flags & HAS_AVX512) vpx_sad64x64_avg = vpx_sad64x64_avg_avx512; vpx_sad64x64x4d = vpx_sad64x64x4d_sse2; if (flags & HAS_AVX2) vpx_sad64x64x4d = vpx_sad64x64x4d_avx2; if (flags & HAS_AVX512) vpx_sad64x64x4d = vpx_sad64x64x4d_avx512; + vpx_sad_skip_32x16 = vpx_sad_skip_32x16_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x16 = vpx_sad_skip_32x16_avx2; + vpx_sad_skip_32x16x4d = vpx_sad_skip_32x16x4d_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x16x4d = vpx_sad_skip_32x16x4d_avx2; + vpx_sad_skip_32x32 = vpx_sad_skip_32x32_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x32 = vpx_sad_skip_32x32_avx2; + vpx_sad_skip_32x32x4d = vpx_sad_skip_32x32x4d_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x32x4d = vpx_sad_skip_32x32x4d_avx2; + vpx_sad_skip_32x64 = vpx_sad_skip_32x64_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x64 = vpx_sad_skip_32x64_avx2; + vpx_sad_skip_32x64x4d = vpx_sad_skip_32x64x4d_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x64x4d = vpx_sad_skip_32x64x4d_avx2; + vpx_sad_skip_64x32 = vpx_sad_skip_64x32_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_64x32 = vpx_sad_skip_64x32_avx2; + if (flags & HAS_AVX512) vpx_sad_skip_64x32 = vpx_sad_skip_64x32_avx512; + vpx_sad_skip_64x32x4d = vpx_sad_skip_64x32x4d_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_64x32x4d = vpx_sad_skip_64x32x4d_avx2; + if (flags & HAS_AVX512) vpx_sad_skip_64x32x4d = vpx_sad_skip_64x32x4d_avx512; + vpx_sad_skip_64x64 = vpx_sad_skip_64x64_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_64x64 = vpx_sad_skip_64x64_avx2; + if (flags & HAS_AVX512) vpx_sad_skip_64x64 = vpx_sad_skip_64x64_avx512; + vpx_sad_skip_64x64x4d = vpx_sad_skip_64x64x4d_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_64x64x4d = vpx_sad_skip_64x64x4d_avx2; + if (flags & HAS_AVX512) vpx_sad_skip_64x64x4d = vpx_sad_skip_64x64x4d_avx512; vpx_satd = vpx_satd_sse2; if (flags & HAS_AVX2) vpx_satd = vpx_satd_avx2; vpx_scaled_2d = vpx_scaled_2d_c; if (flags & HAS_SSSE3) vpx_scaled_2d = vpx_scaled_2d_ssse3; + vpx_sse = vpx_sse_c; + if (flags & HAS_SSE4_1) vpx_sse = vpx_sse_sse4_1; + if (flags & HAS_AVX2) vpx_sse = vpx_sse_avx2; vpx_sub_pixel_avg_variance16x16 = vpx_sub_pixel_avg_variance16x16_sse2; if (flags & HAS_SSSE3) vpx_sub_pixel_avg_variance16x16 = vpx_sub_pixel_avg_variance16x16_ssse3; vpx_sub_pixel_avg_variance16x32 = vpx_sub_pixel_avg_variance16x32_sse2; @@ -1100,6 +1290,8 @@ static void setup_rtcd_internal(void) if (flags & HAS_SSSE3) vpx_sub_pixel_variance8x4 = vpx_sub_pixel_variance8x4_ssse3; vpx_sub_pixel_variance8x8 = vpx_sub_pixel_variance8x8_sse2; if (flags & HAS_SSSE3) vpx_sub_pixel_variance8x8 = vpx_sub_pixel_variance8x8_ssse3; + vpx_subtract_block = vpx_subtract_block_sse2; + if (flags & HAS_AVX2) vpx_subtract_block = vpx_subtract_block_avx2; vpx_variance16x16 = vpx_variance16x16_sse2; if (flags & HAS_AVX2) vpx_variance16x16 = vpx_variance16x16_avx2; vpx_variance16x32 = vpx_variance16x32_sse2; @@ -1116,6 +1308,12 @@ static void setup_rtcd_internal(void) if (flags & HAS_AVX2) vpx_variance64x32 = vpx_variance64x32_avx2; vpx_variance64x64 = vpx_variance64x64_sse2; if (flags & HAS_AVX2) vpx_variance64x64 = vpx_variance64x64_avx2; + vpx_variance8x16 = vpx_variance8x16_sse2; + if (flags & HAS_AVX2) vpx_variance8x16 = vpx_variance8x16_avx2; + vpx_variance8x4 = vpx_variance8x4_sse2; + if (flags & HAS_AVX2) vpx_variance8x4 = vpx_variance8x4_avx2; + vpx_variance8x8 = vpx_variance8x8_sse2; + if (flags & HAS_AVX2) vpx_variance8x8 = vpx_variance8x8_avx2; } #endif @@ -1123,4 +1321,4 @@ static void setup_rtcd_internal(void) } // extern "C" #endif -#endif +#endif // VPX_DSP_RTCD_H_ diff --git a/libs/win32/libvpx/include_x64/vpx_scale_rtcd.h b/libs/win32/libvpx/include_x64/vpx_scale_rtcd.h index 5f09104ea6..4244dd70e2 100644 --- a/libs/win32/libvpx/include_x64/vpx_scale_rtcd.h +++ b/libs/win32/libvpx/include_x64/vpx_scale_rtcd.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2017 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + // This file is generated. Do not edit. #ifndef VPX_SCALE_RTCD_H_ #define VPX_SCALE_RTCD_H_ @@ -70,4 +80,4 @@ static void setup_rtcd_internal(void) } // extern "C" #endif -#endif +#endif // VPX_SCALE_RTCD_H_ diff --git a/libs/win32/libvpx/include_x86/vp8_rtcd.h b/libs/win32/libvpx/include_x86/vp8_rtcd.h index 0b24f10bc1..57334ac719 100644 --- a/libs/win32/libvpx/include_x86/vp8_rtcd.h +++ b/libs/win32/libvpx/include_x86/vp8_rtcd.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2017 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + // This file is generated. Do not edit. #ifndef VP8_RTCD_H_ #define VP8_RTCD_H_ @@ -45,15 +55,6 @@ void vp8_bilinear_predict8x8_sse2(unsigned char *src_ptr, int src_pixels_per_lin void vp8_bilinear_predict8x8_ssse3(unsigned char *src_ptr, int src_pixels_per_line, int xoffset, int yoffset, unsigned char *dst_ptr, int dst_pitch); RTCD_EXTERN void (*vp8_bilinear_predict8x8)(unsigned char *src_ptr, int src_pixels_per_line, int xoffset, int yoffset, unsigned char *dst_ptr, int dst_pitch); -void vp8_blend_b_c(unsigned char *y, unsigned char *u, unsigned char *v, int y_1, int u_1, int v_1, int alpha, int stride); -#define vp8_blend_b vp8_blend_b_c - -void vp8_blend_mb_inner_c(unsigned char *y, unsigned char *u, unsigned char *v, int y_1, int u_1, int v_1, int alpha, int stride); -#define vp8_blend_mb_inner vp8_blend_mb_inner_c - -void vp8_blend_mb_outer_c(unsigned char *y, unsigned char *u, unsigned char *v, int y_1, int u_1, int v_1, int alpha, int stride); -#define vp8_blend_mb_outer vp8_blend_mb_outer_c - int vp8_block_error_c(short *coeff, short *dqcoeff); int vp8_block_error_sse2(short *coeff, short *dqcoeff); RTCD_EXTERN int (*vp8_block_error)(short *coeff, short *dqcoeff); @@ -329,4 +330,4 @@ static void setup_rtcd_internal(void) } // extern "C" #endif -#endif +#endif // VP8_RTCD_H_ diff --git a/libs/win32/libvpx/include_x86/vp9_rtcd.h b/libs/win32/libvpx/include_x86/vp9_rtcd.h index 3cdc8c1d78..5e528ef2ff 100644 --- a/libs/win32/libvpx/include_x86/vp9_rtcd.h +++ b/libs/win32/libvpx/include_x86/vp9_rtcd.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2017 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + // This file is generated. Do not edit. #ifndef VP9_RTCD_H_ #define VP9_RTCD_H_ @@ -16,12 +26,17 @@ #include "vp9/common/vp9_common.h" #include "vp9/common/vp9_enums.h" #include "vp9/common/vp9_filter.h" +#if !CONFIG_REALTIME_ONLY && CONFIG_VP9_ENCODER +#include "vp9/encoder/vp9_temporal_filter.h" +#endif struct macroblockd; /* Encoder forward decls */ struct macroblock; -struct vp9_variance_vtable; +struct macroblock_plane; +struct vp9_sad_table; +struct ScanOrder; struct search_site_config; struct mv; union int_mv; @@ -45,9 +60,8 @@ int64_t vp9_block_error_fp_sse2(const tran_low_t *coeff, const tran_low_t *dqcoe int64_t vp9_block_error_fp_avx2(const tran_low_t *coeff, const tran_low_t *dqcoeff, int block_size); RTCD_EXTERN int64_t (*vp9_block_error_fp)(const tran_low_t *coeff, const tran_low_t *dqcoeff, int block_size); -int vp9_diamond_search_sad_c(const struct macroblock *x, const struct search_site_config *cfg, struct mv *ref_mv, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, const struct vp9_variance_vtable *fn_ptr, const struct mv *center_mv); -int vp9_diamond_search_sad_avx(const struct macroblock *x, const struct search_site_config *cfg, struct mv *ref_mv, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, const struct vp9_variance_vtable *fn_ptr, const struct mv *center_mv); -RTCD_EXTERN int (*vp9_diamond_search_sad)(const struct macroblock *x, const struct search_site_config *cfg, struct mv *ref_mv, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, const struct vp9_variance_vtable *fn_ptr, const struct mv *center_mv); +int vp9_diamond_search_sad_c(const struct macroblock *x, const struct search_site_config *cfg, struct mv *ref_mv, uint32_t start_mv_sad, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, const struct vp9_sad_table *sad_fn_ptr, const struct mv *center_mv); +#define vp9_diamond_search_sad vp9_diamond_search_sad_c void vp9_fht16x16_c(const int16_t *input, tran_low_t *output, int stride, int tx_type); void vp9_fht16x16_sse2(const int16_t *input, tran_low_t *output, int stride, int tx_type); @@ -77,18 +91,36 @@ void vp9_iht8x8_64_add_c(const tran_low_t *input, uint8_t *dest, int stride, int void vp9_iht8x8_64_add_sse2(const tran_low_t *input, uint8_t *dest, int stride, int tx_type); RTCD_EXTERN void (*vp9_iht8x8_64_add)(const tran_low_t *input, uint8_t *dest, int stride, int tx_type); -void vp9_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vp9_quantize_fp_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vp9_quantize_fp_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -RTCD_EXTERN void (*vp9_quantize_fp)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); +void vp9_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vp9_quantize_fp_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vp9_quantize_fp_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vp9_quantize_fp_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +RTCD_EXTERN void (*vp9_quantize_fp)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); -void vp9_quantize_fp_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -#define vp9_quantize_fp_32x32 vp9_quantize_fp_32x32_c +void vp9_quantize_fp_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vp9_quantize_fp_32x32_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vp9_quantize_fp_32x32_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +RTCD_EXTERN void (*vp9_quantize_fp_32x32)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); void vp9_scale_and_extend_frame_c(const struct yv12_buffer_config *src, struct yv12_buffer_config *dst, INTERP_FILTER filter_type, int phase_scaler); void vp9_scale_and_extend_frame_ssse3(const struct yv12_buffer_config *src, struct yv12_buffer_config *dst, INTERP_FILTER filter_type, int phase_scaler); RTCD_EXTERN void (*vp9_scale_and_extend_frame)(const struct yv12_buffer_config *src, struct yv12_buffer_config *dst, INTERP_FILTER filter_type, int phase_scaler); +void vpx_convolve12_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_ssse3(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_avx2(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +RTCD_EXTERN void (*vpx_convolve12)(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); + +void vpx_convolve12_horiz_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_horiz_ssse3(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_horiz_avx2(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +RTCD_EXTERN void (*vpx_convolve12_horiz)(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); + +void vpx_convolve12_vert_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_vert_ssse3(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +void vpx_convolve12_vert_avx2(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); +RTCD_EXTERN void (*vpx_convolve12_vert)(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel12 *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); + void vp9_rtcd(void); #ifdef RTCD_C @@ -107,8 +139,6 @@ static void setup_rtcd_internal(void) vp9_block_error_fp = vp9_block_error_fp_c; if (flags & HAS_SSE2) vp9_block_error_fp = vp9_block_error_fp_sse2; if (flags & HAS_AVX2) vp9_block_error_fp = vp9_block_error_fp_avx2; - vp9_diamond_search_sad = vp9_diamond_search_sad_c; - if (flags & HAS_AVX) vp9_diamond_search_sad = vp9_diamond_search_sad_avx; vp9_fht16x16 = vp9_fht16x16_c; if (flags & HAS_SSE2) vp9_fht16x16 = vp9_fht16x16_sse2; vp9_fht4x4 = vp9_fht4x4_c; @@ -125,9 +155,22 @@ static void setup_rtcd_internal(void) if (flags & HAS_SSE2) vp9_iht8x8_64_add = vp9_iht8x8_64_add_sse2; vp9_quantize_fp = vp9_quantize_fp_c; if (flags & HAS_SSE2) vp9_quantize_fp = vp9_quantize_fp_sse2; + if (flags & HAS_SSSE3) vp9_quantize_fp = vp9_quantize_fp_ssse3; if (flags & HAS_AVX2) vp9_quantize_fp = vp9_quantize_fp_avx2; + vp9_quantize_fp_32x32 = vp9_quantize_fp_32x32_c; + if (flags & HAS_SSSE3) vp9_quantize_fp_32x32 = vp9_quantize_fp_32x32_ssse3; + if (flags & HAS_AVX2) vp9_quantize_fp_32x32 = vp9_quantize_fp_32x32_avx2; vp9_scale_and_extend_frame = vp9_scale_and_extend_frame_c; if (flags & HAS_SSSE3) vp9_scale_and_extend_frame = vp9_scale_and_extend_frame_ssse3; + vpx_convolve12 = vpx_convolve12_c; + if (flags & HAS_SSSE3) vpx_convolve12 = vpx_convolve12_ssse3; + if (flags & HAS_AVX2) vpx_convolve12 = vpx_convolve12_avx2; + vpx_convolve12_horiz = vpx_convolve12_horiz_c; + if (flags & HAS_SSSE3) vpx_convolve12_horiz = vpx_convolve12_horiz_ssse3; + if (flags & HAS_AVX2) vpx_convolve12_horiz = vpx_convolve12_horiz_avx2; + vpx_convolve12_vert = vpx_convolve12_vert_c; + if (flags & HAS_SSSE3) vpx_convolve12_vert = vpx_convolve12_vert_ssse3; + if (flags & HAS_AVX2) vpx_convolve12_vert = vpx_convolve12_vert_avx2; } #endif @@ -135,4 +178,4 @@ static void setup_rtcd_internal(void) } // extern "C" #endif -#endif +#endif // VP9_RTCD_H_ diff --git a/libs/win32/libvpx/include_x86/vpx/vpx_config.h b/libs/win32/libvpx/include_x86/vpx/vpx_config.h index 4749e162a2..648b214b09 100644 --- a/libs/win32/libvpx/include_x86/vpx/vpx_config.h +++ b/libs/win32/libvpx/include_x86/vpx/vpx_config.h @@ -11,17 +11,23 @@ #define RESTRICT #define INLINE __inline #define VPX_ARCH_ARM 0 +#define VPX_ARCH_AARCH64 0 #define VPX_ARCH_MIPS 0 #define VPX_ARCH_X86 1 #define VPX_ARCH_X86_64 0 #define VPX_ARCH_PPC 0 #define VPX_ARCH_LOONGARCH 0 -#define HAVE_NEON 0 #define HAVE_NEON_ASM 0 +#define HAVE_NEON 0 +#define HAVE_NEON_DOTPROD 0 +#define HAVE_NEON_I8MM 0 +#define HAVE_SVE 0 +#define HAVE_SVE2 0 #define HAVE_MIPS32 0 #define HAVE_DSPR2 0 #define HAVE_MSA 0 #define HAVE_MIPS64 0 +#define HAVE_X86_ASM 1 #define HAVE_MMX 1 #define HAVE_SSE 1 #define HAVE_SSE2 1 @@ -37,6 +43,7 @@ #define HAVE_LASX 0 #define HAVE_VPX_PORTS 1 #define HAVE_PTHREAD_H 0 +#define HAVE_PTHREAD_SETNAME_NP 0 #define HAVE_UNISTD_H 0 #define CONFIG_DEPENDENCY_TRACKING 1 #define CONFIG_EXTERNAL_BUILD 1 @@ -87,7 +94,6 @@ #define CONFIG_MULTI_RES_ENCODING 0 #define CONFIG_TEMPORAL_DENOISING 1 #define CONFIG_VP9_TEMPORAL_DENOISING 0 -#define CONFIG_CONSISTENT_RECODE 0 #define CONFIG_COEFFICIENT_RANGE_CHECKING 0 #define CONFIG_VP9_HIGHBITDEPTH 0 #define CONFIG_BETTER_HW_COMPATIBILITY 0 @@ -99,7 +105,7 @@ #define CONFIG_FP_MB_STATS 0 #define CONFIG_EMULATE_HARDWARE 0 #define CONFIG_NON_GREEDY_MV 0 -#define CONFIG_RATE_CTRL 0 +#define CONFIG_COLLECT_COMPONENT_TIMING 0 #define DECODE_WIDTH_LIMIT 16384 #define DECODE_HEIGHT_LIMIT 16384 #endif /* VPX_CONFIG_H */ diff --git a/libs/win32/libvpx/include_x86/vpx_config.asm b/libs/win32/libvpx/include_x86/vpx_config.asm index bdb76db1a6..517b13b9e2 100644 --- a/libs/win32/libvpx/include_x86/vpx_config.asm +++ b/libs/win32/libvpx/include_x86/vpx_config.asm @@ -1,15 +1,21 @@ VPX_ARCH_ARM equ 0 +VPX_ARCH_AARCH64 equ 0 VPX_ARCH_MIPS equ 0 VPX_ARCH_X86 equ 1 VPX_ARCH_X86_64 equ 0 VPX_ARCH_PPC equ 0 VPX_ARCH_LOONGARCH equ 0 -HAVE_NEON equ 0 HAVE_NEON_ASM equ 0 +HAVE_NEON equ 0 +HAVE_NEON_DOTPROD equ 0 +HAVE_NEON_I8MM equ 0 +HAVE_SVE equ 0 +HAVE_SVE2 equ 0 HAVE_MIPS32 equ 0 HAVE_DSPR2 equ 0 HAVE_MSA equ 0 HAVE_MIPS64 equ 0 +HAVE_X86_ASM equ 1 HAVE_MMX equ 1 HAVE_SSE equ 1 HAVE_SSE2 equ 1 @@ -25,6 +31,7 @@ HAVE_LSX equ 0 HAVE_LASX equ 0 HAVE_VPX_PORTS equ 1 HAVE_PTHREAD_H equ 0 +HAVE_PTHREAD_SETNAME_NP equ 0 HAVE_UNISTD_H equ 0 CONFIG_DEPENDENCY_TRACKING equ 1 CONFIG_EXTERNAL_BUILD equ 1 @@ -75,7 +82,6 @@ CONFIG_ENCODE_PERF_TESTS equ 0 CONFIG_MULTI_RES_ENCODING equ 0 CONFIG_TEMPORAL_DENOISING equ 1 CONFIG_VP9_TEMPORAL_DENOISING equ 0 -CONFIG_CONSISTENT_RECODE equ 0 CONFIG_COEFFICIENT_RANGE_CHECKING equ 0 CONFIG_VP9_HIGHBITDEPTH equ 0 CONFIG_BETTER_HW_COMPATIBILITY equ 0 @@ -87,6 +93,6 @@ CONFIG_MISMATCH_DEBUG equ 0 CONFIG_FP_MB_STATS equ 0 CONFIG_EMULATE_HARDWARE equ 0 CONFIG_NON_GREEDY_MV equ 0 -CONFIG_RATE_CTRL equ 0 +CONFIG_COLLECT_COMPONENT_TIMING equ 0 DECODE_WIDTH_LIMIT equ 16384 DECODE_HEIGHT_LIMIT equ 16384 diff --git a/libs/win32/libvpx/include_x86/vpx_config.h b/libs/win32/libvpx/include_x86/vpx_config.h index 4749e162a2..648b214b09 100644 --- a/libs/win32/libvpx/include_x86/vpx_config.h +++ b/libs/win32/libvpx/include_x86/vpx_config.h @@ -11,17 +11,23 @@ #define RESTRICT #define INLINE __inline #define VPX_ARCH_ARM 0 +#define VPX_ARCH_AARCH64 0 #define VPX_ARCH_MIPS 0 #define VPX_ARCH_X86 1 #define VPX_ARCH_X86_64 0 #define VPX_ARCH_PPC 0 #define VPX_ARCH_LOONGARCH 0 -#define HAVE_NEON 0 #define HAVE_NEON_ASM 0 +#define HAVE_NEON 0 +#define HAVE_NEON_DOTPROD 0 +#define HAVE_NEON_I8MM 0 +#define HAVE_SVE 0 +#define HAVE_SVE2 0 #define HAVE_MIPS32 0 #define HAVE_DSPR2 0 #define HAVE_MSA 0 #define HAVE_MIPS64 0 +#define HAVE_X86_ASM 1 #define HAVE_MMX 1 #define HAVE_SSE 1 #define HAVE_SSE2 1 @@ -37,6 +43,7 @@ #define HAVE_LASX 0 #define HAVE_VPX_PORTS 1 #define HAVE_PTHREAD_H 0 +#define HAVE_PTHREAD_SETNAME_NP 0 #define HAVE_UNISTD_H 0 #define CONFIG_DEPENDENCY_TRACKING 1 #define CONFIG_EXTERNAL_BUILD 1 @@ -87,7 +94,6 @@ #define CONFIG_MULTI_RES_ENCODING 0 #define CONFIG_TEMPORAL_DENOISING 1 #define CONFIG_VP9_TEMPORAL_DENOISING 0 -#define CONFIG_CONSISTENT_RECODE 0 #define CONFIG_COEFFICIENT_RANGE_CHECKING 0 #define CONFIG_VP9_HIGHBITDEPTH 0 #define CONFIG_BETTER_HW_COMPATIBILITY 0 @@ -99,7 +105,7 @@ #define CONFIG_FP_MB_STATS 0 #define CONFIG_EMULATE_HARDWARE 0 #define CONFIG_NON_GREEDY_MV 0 -#define CONFIG_RATE_CTRL 0 +#define CONFIG_COLLECT_COMPONENT_TIMING 0 #define DECODE_WIDTH_LIMIT 16384 #define DECODE_HEIGHT_LIMIT 16384 #endif /* VPX_CONFIG_H */ diff --git a/libs/win32/libvpx/include_x86/vpx_dsp_rtcd.h b/libs/win32/libvpx/include_x86/vpx_dsp_rtcd.h index 8090993c30..0c298df669 100644 --- a/libs/win32/libvpx/include_x86/vpx_dsp_rtcd.h +++ b/libs/win32/libvpx/include_x86/vpx_dsp_rtcd.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2017 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + // This file is generated. Do not edit. #ifndef VPX_DSP_RTCD_H_ #define VPX_DSP_RTCD_H_ @@ -15,6 +25,10 @@ #include "vpx/vpx_integer.h" #include "vpx_dsp/vpx_dsp_common.h" #include "vpx_dsp/vpx_filter.h" +#if CONFIG_VP9_ENCODER + struct macroblock_plane; + struct ScanOrder; +#endif #ifdef __cplusplus @@ -31,6 +45,7 @@ RTCD_EXTERN unsigned int (*vpx_avg_8x8)(const uint8_t *, int p); void vpx_comp_avg_pred_c(uint8_t *comp_pred, const uint8_t *pred, int width, int height, const uint8_t *ref, int ref_stride); void vpx_comp_avg_pred_sse2(uint8_t *comp_pred, const uint8_t *pred, int width, int height, const uint8_t *ref, int ref_stride); +void vpx_comp_avg_pred_avx2(uint8_t *comp_pred, const uint8_t *pred, int width, int height, const uint8_t *ref, int ref_stride); RTCD_EXTERN void (*vpx_comp_avg_pred)(uint8_t *comp_pred, const uint8_t *pred, int width, int height, const uint8_t *ref, int ref_stride); void vpx_convolve8_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); @@ -237,6 +252,7 @@ RTCD_EXTERN void (*vpx_dc_top_predictor_8x8)(uint8_t *dst, ptrdiff_t stride, con void vpx_fdct16x16_c(const int16_t *input, tran_low_t *output, int stride); void vpx_fdct16x16_sse2(const int16_t *input, tran_low_t *output, int stride); +void vpx_fdct16x16_avx2(const int16_t *input, tran_low_t *output, int stride); RTCD_EXTERN void (*vpx_fdct16x16)(const int16_t *input, tran_low_t *output, int stride); void vpx_fdct16x16_1_c(const int16_t *input, tran_low_t *output, int stride); @@ -332,6 +348,7 @@ RTCD_EXTERN void (*vpx_idct16x16_1_add)(const tran_low_t *input, uint8_t *dest, void vpx_idct16x16_256_add_c(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct16x16_256_add_sse2(const tran_low_t *input, uint8_t *dest, int stride); +void vpx_idct16x16_256_add_avx2(const tran_low_t *input, uint8_t *dest, int stride); RTCD_EXTERN void (*vpx_idct16x16_256_add)(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct16x16_38_add_c(const tran_low_t *input, uint8_t *dest, int stride); @@ -340,11 +357,13 @@ RTCD_EXTERN void (*vpx_idct16x16_38_add)(const tran_low_t *input, uint8_t *dest, void vpx_idct32x32_1024_add_c(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct32x32_1024_add_sse2(const tran_low_t *input, uint8_t *dest, int stride); +void vpx_idct32x32_1024_add_avx2(const tran_low_t *input, uint8_t *dest, int stride); RTCD_EXTERN void (*vpx_idct32x32_1024_add)(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct32x32_135_add_c(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct32x32_135_add_sse2(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct32x32_135_add_ssse3(const tran_low_t *input, uint8_t *dest, int stride); +void vpx_idct32x32_135_add_avx2(const tran_low_t *input, uint8_t *dest, int stride); RTCD_EXTERN void (*vpx_idct32x32_135_add)(const tran_low_t *input, uint8_t *dest, int stride); void vpx_idct32x32_1_add_c(const tran_low_t *input, uint8_t *dest, int stride); @@ -480,16 +499,18 @@ void vpx_post_proc_down_and_across_mb_row_c(unsigned char *src, unsigned char *d void vpx_post_proc_down_and_across_mb_row_sse2(unsigned char *src, unsigned char *dst, int src_pitch, int dst_pitch, int cols, unsigned char *flimits, int size); RTCD_EXTERN void (*vpx_post_proc_down_and_across_mb_row)(unsigned char *src, unsigned char *dst, int src_pitch, int dst_pitch, int cols, unsigned char *flimits, int size); -void vpx_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vpx_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vpx_quantize_b_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vpx_quantize_b_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -RTCD_EXTERN void (*vpx_quantize_b)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); +void vpx_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_sse2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_avx2(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +RTCD_EXTERN void (*vpx_quantize_b)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); -void vpx_quantize_b_32x32_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vpx_quantize_b_32x32_ssse3(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -void vpx_quantize_b_32x32_avx(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); -RTCD_EXTERN void (*vpx_quantize_b_32x32)(const tran_low_t *coeff_ptr, intptr_t n_coeffs, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan); +void vpx_quantize_b_32x32_c(const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_32x32_ssse3(const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_32x32_avx(const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +void vpx_quantize_b_32x32_avx2(const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); +RTCD_EXTERN void (*vpx_quantize_b_32x32)(const tran_low_t *coeff_ptr, const struct macroblock_plane *const mb_plane, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const struct ScanOrder *const scan_order); unsigned int vpx_sad16x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad16x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -499,9 +520,9 @@ unsigned int vpx_sad16x16_avg_c(const uint8_t *src_ptr, int src_stride, const ui unsigned int vpx_sad16x16_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad16x16_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad16x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad16x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad16x16x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad16x16x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad16x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad16x32_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -511,9 +532,9 @@ unsigned int vpx_sad16x32_avg_c(const uint8_t *src_ptr, int src_stride, const ui unsigned int vpx_sad16x32_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad16x32_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad16x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad16x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad16x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad16x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad16x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad16x8_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -523,9 +544,9 @@ unsigned int vpx_sad16x8_avg_c(const uint8_t *src_ptr, int src_stride, const uin unsigned int vpx_sad16x8_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad16x8_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad16x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad16x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad16x8x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad16x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad16x8x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad32x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad32x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -537,9 +558,9 @@ unsigned int vpx_sad32x16_avg_sse2(const uint8_t *src_ptr, int src_stride, const unsigned int vpx_sad32x16_avg_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad32x16_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad32x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad32x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad32x16x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad32x16x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad32x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad32x32_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -551,10 +572,10 @@ unsigned int vpx_sad32x32_avg_sse2(const uint8_t *src_ptr, int src_stride, const unsigned int vpx_sad32x32_avg_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad32x32_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad32x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad32x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad32x32x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad32x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x32x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad32x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad32x64_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad32x64_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -566,9 +587,9 @@ unsigned int vpx_sad32x64_avg_sse2(const uint8_t *src_ptr, int src_stride, const unsigned int vpx_sad32x64_avg_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad32x64_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad32x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad32x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad32x64x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad32x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad32x64x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad4x4_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad4x4_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -578,9 +599,9 @@ unsigned int vpx_sad4x4_avg_c(const uint8_t *src_ptr, int src_stride, const uint unsigned int vpx_sad4x4_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad4x4_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad4x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad4x4x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad4x4x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad4x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad4x4x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad4x4x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad4x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad4x8_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -590,39 +611,43 @@ unsigned int vpx_sad4x8_avg_c(const uint8_t *src_ptr, int src_stride, const uint unsigned int vpx_sad4x8_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad4x8_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad4x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad4x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad4x8x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad4x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad4x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad4x8x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad64x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x32_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x32_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad64x32_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); RTCD_EXTERN unsigned int (*vpx_sad64x32)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x32_avg_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); unsigned int vpx_sad64x32_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); unsigned int vpx_sad64x32_avg_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); +unsigned int vpx_sad64x32_avg_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad64x32_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad64x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad64x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad64x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad64x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad64x64_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x64_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x64_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad64x64_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); RTCD_EXTERN unsigned int (*vpx_sad64x64)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad64x64_avg_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); unsigned int vpx_sad64x64_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); unsigned int vpx_sad64x64_avg_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); +unsigned int vpx_sad64x64_avg_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad64x64_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad64x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad64x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad64x64x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad64x64x4d_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad64x64x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x64x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad64x64x4d_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad64x64x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad8x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad8x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -632,9 +657,9 @@ unsigned int vpx_sad8x16_avg_c(const uint8_t *src_ptr, int src_stride, const uin unsigned int vpx_sad8x16_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad8x16_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad8x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad8x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad8x16x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad8x16x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad8x4_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad8x4_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -644,9 +669,9 @@ unsigned int vpx_sad8x4_avg_c(const uint8_t *src_ptr, int src_stride, const uint unsigned int vpx_sad8x4_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad8x4_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad8x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad8x4x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad8x4x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x4x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad8x4x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); unsigned int vpx_sad8x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); unsigned int vpx_sad8x8_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); @@ -656,9 +681,123 @@ unsigned int vpx_sad8x8_avg_c(const uint8_t *src_ptr, int src_stride, const uint unsigned int vpx_sad8x8_avg_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); RTCD_EXTERN unsigned int (*vpx_sad8x8_avg)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, const uint8_t *second_pred); -void vpx_sad8x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -void vpx_sad8x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); -RTCD_EXTERN void (*vpx_sad8x8x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t * const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad8x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad8x8x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_16x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_16x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_16x16)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_16x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_16x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_16x16x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_16x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_16x32_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_16x32)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_16x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_16x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_16x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_16x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_16x8_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_16x8)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_16x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_16x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_16x8x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_32x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x16_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_32x16)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_32x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x16x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_32x16x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_32x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x32_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x32_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_32x32)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_32x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x32x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_32x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_32x64_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x64_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_32x64_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_32x64)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_32x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_32x64x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_32x64x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_4x4_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +#define vpx_sad_skip_4x4 vpx_sad_skip_4x4_c + +void vpx_sad_skip_4x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +#define vpx_sad_skip_4x4x4d vpx_sad_skip_4x4x4d_c + +unsigned int vpx_sad_skip_4x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_4x8_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_4x8)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_4x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_4x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_4x8x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_64x32_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x32_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x32_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x32_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_64x32)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_64x32x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x32x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x32x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x32x4d_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_64x32x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_64x64_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x64_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x64_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_64x64_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_64x64)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_64x64x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x64x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x64x4d_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_64x64x4d_avx512(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_64x64x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_8x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_8x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_8x16)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_8x16x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_8x16x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_8x16x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); + +unsigned int vpx_sad_skip_8x4_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +#define vpx_sad_skip_8x4 vpx_sad_skip_8x4_c + +void vpx_sad_skip_8x4x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +#define vpx_sad_skip_8x4x4d vpx_sad_skip_8x4x4d_c + +unsigned int vpx_sad_skip_8x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +unsigned int vpx_sad_skip_8x8_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); +RTCD_EXTERN unsigned int (*vpx_sad_skip_8x8)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride); + +void vpx_sad_skip_8x8x4d_c(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +void vpx_sad_skip_8x8x4d_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); +RTCD_EXTERN void (*vpx_sad_skip_8x8x4d)(const uint8_t *src_ptr, int src_stride, const uint8_t *const ref_array[4], int ref_stride, uint32_t sad_array[4]); int vpx_satd_c(const int16_t *coeff, int length); int vpx_satd_sse2(const int16_t *coeff, int length); @@ -684,6 +823,11 @@ void vpx_scaled_horiz_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, void vpx_scaled_vert_c(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, ptrdiff_t dst_stride, const InterpKernel *filter, int x0_q4, int x_step_q4, int y0_q4, int y_step_q4, int w, int h); #define vpx_scaled_vert vpx_scaled_vert_c +int64_t vpx_sse_c(const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, int width, int height); +int64_t vpx_sse_sse4_1(const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, int width, int height); +int64_t vpx_sse_avx2(const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, int width, int height); +RTCD_EXTERN int64_t (*vpx_sse)(const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, int width, int height); + uint32_t vpx_sub_pixel_avg_variance16x16_c(const uint8_t *src_ptr, int src_stride, int x_offset, int y_offset, const uint8_t *ref_ptr, int ref_stride, uint32_t *sse, const uint8_t *second_pred); uint32_t vpx_sub_pixel_avg_variance16x16_sse2(const uint8_t *src_ptr, int src_stride, int x_offset, int y_offset, const uint8_t *ref_ptr, int ref_stride, uint32_t *sse, const uint8_t *second_pred); uint32_t vpx_sub_pixel_avg_variance16x16_ssse3(const uint8_t *src_ptr, int src_stride, int x_offset, int y_offset, const uint8_t *ref_ptr, int ref_stride, uint32_t *sse, const uint8_t *second_pred); @@ -820,6 +964,7 @@ RTCD_EXTERN uint32_t (*vpx_sub_pixel_variance8x8)(const uint8_t *src_ptr, int sr void vpx_subtract_block_c(int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride); void vpx_subtract_block_sse2(int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride); +void vpx_subtract_block_avx2(int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride); RTCD_EXTERN void (*vpx_subtract_block)(int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride); uint64_t vpx_sum_squares_2d_i16_c(const int16_t *src, int stride, int size); @@ -908,14 +1053,17 @@ RTCD_EXTERN unsigned int (*vpx_variance64x64)(const uint8_t *src_ptr, int src_st unsigned int vpx_variance8x16_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); unsigned int vpx_variance8x16_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); +unsigned int vpx_variance8x16_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); RTCD_EXTERN unsigned int (*vpx_variance8x16)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); unsigned int vpx_variance8x4_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); unsigned int vpx_variance8x4_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); +unsigned int vpx_variance8x4_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); RTCD_EXTERN unsigned int (*vpx_variance8x4)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); unsigned int vpx_variance8x8_c(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); unsigned int vpx_variance8x8_sse2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); +unsigned int vpx_variance8x8_avx2(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); RTCD_EXTERN unsigned int (*vpx_variance8x8)(const uint8_t *src_ptr, int src_stride, const uint8_t *ref_ptr, int ref_stride, unsigned int *sse); void vpx_ve_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left); @@ -941,6 +1089,7 @@ static void setup_rtcd_internal(void) if (flags & HAS_SSE2) vpx_avg_8x8 = vpx_avg_8x8_sse2; vpx_comp_avg_pred = vpx_comp_avg_pred_c; if (flags & HAS_SSE2) vpx_comp_avg_pred = vpx_comp_avg_pred_sse2; + if (flags & HAS_AVX2) vpx_comp_avg_pred = vpx_comp_avg_pred_avx2; vpx_convolve8 = vpx_convolve8_c; if (flags & HAS_SSE2) vpx_convolve8 = vpx_convolve8_sse2; if (flags & HAS_SSSE3) vpx_convolve8 = vpx_convolve8_ssse3; @@ -1035,6 +1184,7 @@ static void setup_rtcd_internal(void) if (flags & HAS_SSE2) vpx_dc_top_predictor_8x8 = vpx_dc_top_predictor_8x8_sse2; vpx_fdct16x16 = vpx_fdct16x16_c; if (flags & HAS_SSE2) vpx_fdct16x16 = vpx_fdct16x16_sse2; + if (flags & HAS_AVX2) vpx_fdct16x16 = vpx_fdct16x16_avx2; vpx_fdct16x16_1 = vpx_fdct16x16_1_c; if (flags & HAS_SSE2) vpx_fdct16x16_1 = vpx_fdct16x16_1_sse2; vpx_fdct32x32 = vpx_fdct32x32_c; @@ -1082,13 +1232,16 @@ static void setup_rtcd_internal(void) if (flags & HAS_SSE2) vpx_idct16x16_1_add = vpx_idct16x16_1_add_sse2; vpx_idct16x16_256_add = vpx_idct16x16_256_add_c; if (flags & HAS_SSE2) vpx_idct16x16_256_add = vpx_idct16x16_256_add_sse2; + if (flags & HAS_AVX2) vpx_idct16x16_256_add = vpx_idct16x16_256_add_avx2; vpx_idct16x16_38_add = vpx_idct16x16_38_add_c; if (flags & HAS_SSE2) vpx_idct16x16_38_add = vpx_idct16x16_38_add_sse2; vpx_idct32x32_1024_add = vpx_idct32x32_1024_add_c; if (flags & HAS_SSE2) vpx_idct32x32_1024_add = vpx_idct32x32_1024_add_sse2; + if (flags & HAS_AVX2) vpx_idct32x32_1024_add = vpx_idct32x32_1024_add_avx2; vpx_idct32x32_135_add = vpx_idct32x32_135_add_c; if (flags & HAS_SSE2) vpx_idct32x32_135_add = vpx_idct32x32_135_add_sse2; if (flags & HAS_SSSE3) vpx_idct32x32_135_add = vpx_idct32x32_135_add_ssse3; + if (flags & HAS_AVX2) vpx_idct32x32_135_add = vpx_idct32x32_135_add_avx2; vpx_idct32x32_1_add = vpx_idct32x32_1_add_c; if (flags & HAS_SSE2) vpx_idct32x32_1_add = vpx_idct32x32_1_add_sse2; vpx_idct32x32_34_add = vpx_idct32x32_34_add_c; @@ -1161,9 +1314,11 @@ static void setup_rtcd_internal(void) if (flags & HAS_SSE2) vpx_quantize_b = vpx_quantize_b_sse2; if (flags & HAS_SSSE3) vpx_quantize_b = vpx_quantize_b_ssse3; if (flags & HAS_AVX) vpx_quantize_b = vpx_quantize_b_avx; + if (flags & HAS_AVX2) vpx_quantize_b = vpx_quantize_b_avx2; vpx_quantize_b_32x32 = vpx_quantize_b_32x32_c; if (flags & HAS_SSSE3) vpx_quantize_b_32x32 = vpx_quantize_b_32x32_ssse3; if (flags & HAS_AVX) vpx_quantize_b_32x32 = vpx_quantize_b_32x32_avx; + if (flags & HAS_AVX2) vpx_quantize_b_32x32 = vpx_quantize_b_32x32_avx2; vpx_sad16x16 = vpx_sad16x16_c; if (flags & HAS_SSE2) vpx_sad16x16 = vpx_sad16x16_sse2; vpx_sad16x16_avg = vpx_sad16x16_avg_c; @@ -1222,17 +1377,21 @@ static void setup_rtcd_internal(void) vpx_sad64x32 = vpx_sad64x32_c; if (flags & HAS_SSE2) vpx_sad64x32 = vpx_sad64x32_sse2; if (flags & HAS_AVX2) vpx_sad64x32 = vpx_sad64x32_avx2; + if (flags & HAS_AVX512) vpx_sad64x32 = vpx_sad64x32_avx512; vpx_sad64x32_avg = vpx_sad64x32_avg_c; if (flags & HAS_SSE2) vpx_sad64x32_avg = vpx_sad64x32_avg_sse2; if (flags & HAS_AVX2) vpx_sad64x32_avg = vpx_sad64x32_avg_avx2; + if (flags & HAS_AVX512) vpx_sad64x32_avg = vpx_sad64x32_avg_avx512; vpx_sad64x32x4d = vpx_sad64x32x4d_c; if (flags & HAS_SSE2) vpx_sad64x32x4d = vpx_sad64x32x4d_sse2; vpx_sad64x64 = vpx_sad64x64_c; if (flags & HAS_SSE2) vpx_sad64x64 = vpx_sad64x64_sse2; if (flags & HAS_AVX2) vpx_sad64x64 = vpx_sad64x64_avx2; + if (flags & HAS_AVX512) vpx_sad64x64 = vpx_sad64x64_avx512; vpx_sad64x64_avg = vpx_sad64x64_avg_c; if (flags & HAS_SSE2) vpx_sad64x64_avg = vpx_sad64x64_avg_sse2; if (flags & HAS_AVX2) vpx_sad64x64_avg = vpx_sad64x64_avg_avx2; + if (flags & HAS_AVX512) vpx_sad64x64_avg = vpx_sad64x64_avg_avx512; vpx_sad64x64x4d = vpx_sad64x64x4d_c; if (flags & HAS_SSE2) vpx_sad64x64x4d = vpx_sad64x64x4d_sse2; if (flags & HAS_AVX2) vpx_sad64x64x4d = vpx_sad64x64x4d_avx2; @@ -1255,11 +1414,72 @@ static void setup_rtcd_internal(void) if (flags & HAS_SSE2) vpx_sad8x8_avg = vpx_sad8x8_avg_sse2; vpx_sad8x8x4d = vpx_sad8x8x4d_c; if (flags & HAS_SSE2) vpx_sad8x8x4d = vpx_sad8x8x4d_sse2; + vpx_sad_skip_16x16 = vpx_sad_skip_16x16_c; + if (flags & HAS_SSE2) vpx_sad_skip_16x16 = vpx_sad_skip_16x16_sse2; + vpx_sad_skip_16x16x4d = vpx_sad_skip_16x16x4d_c; + if (flags & HAS_SSE2) vpx_sad_skip_16x16x4d = vpx_sad_skip_16x16x4d_sse2; + vpx_sad_skip_16x32 = vpx_sad_skip_16x32_c; + if (flags & HAS_SSE2) vpx_sad_skip_16x32 = vpx_sad_skip_16x32_sse2; + vpx_sad_skip_16x32x4d = vpx_sad_skip_16x32x4d_c; + if (flags & HAS_SSE2) vpx_sad_skip_16x32x4d = vpx_sad_skip_16x32x4d_sse2; + vpx_sad_skip_16x8 = vpx_sad_skip_16x8_c; + if (flags & HAS_SSE2) vpx_sad_skip_16x8 = vpx_sad_skip_16x8_sse2; + vpx_sad_skip_16x8x4d = vpx_sad_skip_16x8x4d_c; + if (flags & HAS_SSE2) vpx_sad_skip_16x8x4d = vpx_sad_skip_16x8x4d_sse2; + vpx_sad_skip_32x16 = vpx_sad_skip_32x16_c; + if (flags & HAS_SSE2) vpx_sad_skip_32x16 = vpx_sad_skip_32x16_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x16 = vpx_sad_skip_32x16_avx2; + vpx_sad_skip_32x16x4d = vpx_sad_skip_32x16x4d_c; + if (flags & HAS_SSE2) vpx_sad_skip_32x16x4d = vpx_sad_skip_32x16x4d_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x16x4d = vpx_sad_skip_32x16x4d_avx2; + vpx_sad_skip_32x32 = vpx_sad_skip_32x32_c; + if (flags & HAS_SSE2) vpx_sad_skip_32x32 = vpx_sad_skip_32x32_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x32 = vpx_sad_skip_32x32_avx2; + vpx_sad_skip_32x32x4d = vpx_sad_skip_32x32x4d_c; + if (flags & HAS_SSE2) vpx_sad_skip_32x32x4d = vpx_sad_skip_32x32x4d_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x32x4d = vpx_sad_skip_32x32x4d_avx2; + vpx_sad_skip_32x64 = vpx_sad_skip_32x64_c; + if (flags & HAS_SSE2) vpx_sad_skip_32x64 = vpx_sad_skip_32x64_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x64 = vpx_sad_skip_32x64_avx2; + vpx_sad_skip_32x64x4d = vpx_sad_skip_32x64x4d_c; + if (flags & HAS_SSE2) vpx_sad_skip_32x64x4d = vpx_sad_skip_32x64x4d_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_32x64x4d = vpx_sad_skip_32x64x4d_avx2; + vpx_sad_skip_4x8 = vpx_sad_skip_4x8_c; + if (flags & HAS_SSE2) vpx_sad_skip_4x8 = vpx_sad_skip_4x8_sse2; + vpx_sad_skip_4x8x4d = vpx_sad_skip_4x8x4d_c; + if (flags & HAS_SSE2) vpx_sad_skip_4x8x4d = vpx_sad_skip_4x8x4d_sse2; + vpx_sad_skip_64x32 = vpx_sad_skip_64x32_c; + if (flags & HAS_SSE2) vpx_sad_skip_64x32 = vpx_sad_skip_64x32_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_64x32 = vpx_sad_skip_64x32_avx2; + if (flags & HAS_AVX512) vpx_sad_skip_64x32 = vpx_sad_skip_64x32_avx512; + vpx_sad_skip_64x32x4d = vpx_sad_skip_64x32x4d_c; + if (flags & HAS_SSE2) vpx_sad_skip_64x32x4d = vpx_sad_skip_64x32x4d_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_64x32x4d = vpx_sad_skip_64x32x4d_avx2; + if (flags & HAS_AVX512) vpx_sad_skip_64x32x4d = vpx_sad_skip_64x32x4d_avx512; + vpx_sad_skip_64x64 = vpx_sad_skip_64x64_c; + if (flags & HAS_SSE2) vpx_sad_skip_64x64 = vpx_sad_skip_64x64_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_64x64 = vpx_sad_skip_64x64_avx2; + if (flags & HAS_AVX512) vpx_sad_skip_64x64 = vpx_sad_skip_64x64_avx512; + vpx_sad_skip_64x64x4d = vpx_sad_skip_64x64x4d_c; + if (flags & HAS_SSE2) vpx_sad_skip_64x64x4d = vpx_sad_skip_64x64x4d_sse2; + if (flags & HAS_AVX2) vpx_sad_skip_64x64x4d = vpx_sad_skip_64x64x4d_avx2; + if (flags & HAS_AVX512) vpx_sad_skip_64x64x4d = vpx_sad_skip_64x64x4d_avx512; + vpx_sad_skip_8x16 = vpx_sad_skip_8x16_c; + if (flags & HAS_SSE2) vpx_sad_skip_8x16 = vpx_sad_skip_8x16_sse2; + vpx_sad_skip_8x16x4d = vpx_sad_skip_8x16x4d_c; + if (flags & HAS_SSE2) vpx_sad_skip_8x16x4d = vpx_sad_skip_8x16x4d_sse2; + vpx_sad_skip_8x8 = vpx_sad_skip_8x8_c; + if (flags & HAS_SSE2) vpx_sad_skip_8x8 = vpx_sad_skip_8x8_sse2; + vpx_sad_skip_8x8x4d = vpx_sad_skip_8x8x4d_c; + if (flags & HAS_SSE2) vpx_sad_skip_8x8x4d = vpx_sad_skip_8x8x4d_sse2; vpx_satd = vpx_satd_c; if (flags & HAS_SSE2) vpx_satd = vpx_satd_sse2; if (flags & HAS_AVX2) vpx_satd = vpx_satd_avx2; vpx_scaled_2d = vpx_scaled_2d_c; if (flags & HAS_SSSE3) vpx_scaled_2d = vpx_scaled_2d_ssse3; + vpx_sse = vpx_sse_c; + if (flags & HAS_SSE4_1) vpx_sse = vpx_sse_sse4_1; + if (flags & HAS_AVX2) vpx_sse = vpx_sse_avx2; vpx_sub_pixel_avg_variance16x16 = vpx_sub_pixel_avg_variance16x16_c; if (flags & HAS_SSE2) vpx_sub_pixel_avg_variance16x16 = vpx_sub_pixel_avg_variance16x16_sse2; if (flags & HAS_SSSE3) vpx_sub_pixel_avg_variance16x16 = vpx_sub_pixel_avg_variance16x16_ssse3; @@ -1344,6 +1564,7 @@ static void setup_rtcd_internal(void) if (flags & HAS_SSSE3) vpx_sub_pixel_variance8x8 = vpx_sub_pixel_variance8x8_ssse3; vpx_subtract_block = vpx_subtract_block_c; if (flags & HAS_SSE2) vpx_subtract_block = vpx_subtract_block_sse2; + if (flags & HAS_AVX2) vpx_subtract_block = vpx_subtract_block_avx2; vpx_sum_squares_2d_i16 = vpx_sum_squares_2d_i16_c; if (flags & HAS_SSE2) vpx_sum_squares_2d_i16 = vpx_sum_squares_2d_i16_sse2; vpx_tm_predictor_16x16 = vpx_tm_predictor_16x16_c; @@ -1392,10 +1613,13 @@ static void setup_rtcd_internal(void) if (flags & HAS_AVX2) vpx_variance64x64 = vpx_variance64x64_avx2; vpx_variance8x16 = vpx_variance8x16_c; if (flags & HAS_SSE2) vpx_variance8x16 = vpx_variance8x16_sse2; + if (flags & HAS_AVX2) vpx_variance8x16 = vpx_variance8x16_avx2; vpx_variance8x4 = vpx_variance8x4_c; if (flags & HAS_SSE2) vpx_variance8x4 = vpx_variance8x4_sse2; + if (flags & HAS_AVX2) vpx_variance8x4 = vpx_variance8x4_avx2; vpx_variance8x8 = vpx_variance8x8_c; if (flags & HAS_SSE2) vpx_variance8x8 = vpx_variance8x8_sse2; + if (flags & HAS_AVX2) vpx_variance8x8 = vpx_variance8x8_avx2; vpx_vector_var = vpx_vector_var_c; if (flags & HAS_SSE2) vpx_vector_var = vpx_vector_var_sse2; } @@ -1405,4 +1629,4 @@ static void setup_rtcd_internal(void) } // extern "C" #endif -#endif +#endif // VPX_DSP_RTCD_H_ diff --git a/libs/win32/libvpx/include_x86/vpx_scale_rtcd.h b/libs/win32/libvpx/include_x86/vpx_scale_rtcd.h index 5f09104ea6..4244dd70e2 100644 --- a/libs/win32/libvpx/include_x86/vpx_scale_rtcd.h +++ b/libs/win32/libvpx/include_x86/vpx_scale_rtcd.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2017 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + // This file is generated. Do not edit. #ifndef VPX_SCALE_RTCD_H_ #define VPX_SCALE_RTCD_H_ @@ -70,4 +80,4 @@ static void setup_rtcd_internal(void) } // extern "C" #endif -#endif +#endif // VPX_SCALE_RTCD_H_ diff --git a/libs/win32/libvpx/libvpx.2017.vcxproj b/libs/win32/libvpx/libvpx.2017.vcxproj index f609ac7a31..1e75e119a5 100644 --- a/libs/win32/libvpx/libvpx.2017.vcxproj +++ b/libs/win32/libvpx/libvpx.2017.vcxproj @@ -190,6 +190,16 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + /arch:AVX + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -250,24 +260,10 @@ nasm -Xvc -f win64 -I"./include_x64" -I"../../libvpx" "%(FullPath)" -o $(IntDir)vpx_dsp_x86_add_noise_sse2_asm.obj $(IntDir)vpx_dsp_x86_add_noise_sse2_asm.obj - - Assembling %(Filename)%(Extension) - nasm -Xvc -gcv8 -f win32 -I".\include_x86" -I"..\..\libvpx" "%(FullPath)" -o $(IntDir)vpx_dsp_x86_deblock_sse2_asm.obj - $(IntDir)vpx_dsp_x86_deblock_sse2_asm.obj - Assembling %(Filename)%(Extension) - nasm -Xvc -f win32 -I".\include_x86" -I"..\..\libvpx" "%(FullPath)" -o $(IntDir)vpx_dsp_x86_deblock_sse2_asm.obj - $(IntDir)vpx_dsp_x86_deblock_sse2_asm.obj - Assembling %(Filename)%(Extension) - nasm -Xvc -gcv8 -f win64 -I"./include_x64" -I"../../libvpx" "%(FullPath)" -o $(IntDir)vpx_dsp_x86_deblock_sse2_asm.obj - $(IntDir)vpx_dsp_x86_deblock_sse2_asm.obj - Assembling %(Filename)%(Extension) - nasm -Xvc -f win64 -I"./include_x64" -I"../../libvpx" "%(FullPath)" -o $(IntDir)vpx_dsp_x86_deblock_sse2_asm.obj - $(IntDir)vpx_dsp_x86_deblock_sse2_asm.obj - - - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -393,6 +389,10 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + /arch:AVX + Assembling %(Filename)%(Extension) @@ -425,6 +425,10 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ /arch:AVX + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + /arch:AVX + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -464,10 +468,18 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ /arch:AVX + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + /arch:AVX + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ /arch:AVX + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + /arch:AVX + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ /arch:AVX @@ -522,6 +534,10 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + /arch:AVX + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1214,20 +1230,29 @@ $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ - - + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ /arch:AVX - + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ + + $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ /arch:AVX @@ -1260,14 +1285,6 @@ nasm -Xvc -f win64 -I"./include_x64" -I"../../libvpx" "%(FullPath)" -o $(IntDir)vp9_encoder_x86_vp9_error_sse2_asm.obj $(IntDir)vp9_encoder_x86_vp9_error_sse2_asm.obj - - Assembling %(Filename)%(Extension) - nasm -Xvc -gcv8 -f win64 -I"./include_x64" -I"../../libvpx" "%(FullPath)" -o $(IntDir)vp9_encoder_x86_vp9_quantize_ssse3_x86_64_asm.obj - $(IntDir)vp9_encoder_x86_vp9_quantize_ssse3_x86_64_asm.obj - Assembling %(Filename)%(Extension) - nasm -Xvc -f win64 -I"./include_x64" -I"../../libvpx" "%(FullPath)" -o $(IntDir)vp9_encoder_x86_vp9_quantize_ssse3_x86_64_asm.obj - $(IntDir)vp9_encoder_x86_vp9_quantize_ssse3_x86_64_asm.obj - $(IntDir)$([System.String]::Copy(%(RelativeDir)).Replace('\','_'))\ @@ -1322,6 +1339,7 @@ + @@ -1329,7 +1347,6 @@ - @@ -1368,6 +1385,7 @@ + @@ -1473,6 +1491,7 @@ + @@ -1501,8 +1520,9 @@ + - + diff --git a/libs/win32/libvpx/vpx_version.h b/libs/win32/libvpx/vpx_version.h index a90ab60d9f..9b49754b1c 100644 --- a/libs/win32/libvpx/vpx_version.h +++ b/libs/win32/libvpx/vpx_version.h @@ -1,8 +1,11 @@ // This file is generated. Do not edit. +#ifndef VPX_VERSION_H_ +#define VPX_VERSION_H_ #define VERSION_MAJOR 1 -#define VERSION_MINOR 12 +#define VERSION_MINOR 17 #define VERSION_PATCH 0 #define VERSION_EXTRA "" #define VERSION_PACKED ((VERSION_MAJOR<<16)|(VERSION_MINOR<<8)|(VERSION_PATCH)) -#define VERSION_STRING_NOSP "v1.12.0" -#define VERSION_STRING " v1.12.0" +#define VERSION_STRING_NOSP "v1.17.0" +#define VERSION_STRING " v1.17.0" +#endif // VPX_VERSION_H_ From 0b3e4644f28b480c2e30185df0b8914225d613a5 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 12 Feb 2020 21:44:29 +0400 Subject: [PATCH 57/88] [libvpx] Fix pthread configure checks: "Null pointer passed as an argument to a 'nonnull' parameter" --- libs/libvpx/build/make/configure.sh | 4 +++- libs/libvpx/configure | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/libvpx/build/make/configure.sh b/libs/libvpx/build/make/configure.sh index b37b9986fa..5d9d0dfd91 100644 --- a/libs/libvpx/build/make/configure.sh +++ b/libs/libvpx/build/make/configure.sh @@ -1631,7 +1631,9 @@ EOF check_header pthread.h && check_lib -lpthread < #include -int main(void) { return pthread_create(NULL, NULL, NULL, NULL); } +void *thread_check (void *); +void *thread_check (void *obj){ return obj;}; +int main(void) { pthread_t thread_id; return pthread_create(&thread_id, NULL, thread_check, NULL); } EOF enabled pthread_h && check_lib -lpthread < #include -int main(void) { return pthread_create(NULL, NULL, NULL, NULL); } +void *thread_check (void *); +void *thread_check (void *obj){ return obj;}; +int main(void) { pthread_t thread_id; return pthread_create(&thread_id, NULL, thread_check, NULL); } EOF check_header unistd.h # for sysconf(3) and friends. From 2baece4a5e09271a7488cd16b32a55c98dc00f4f Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 11 Aug 2022 01:19:09 +0300 Subject: [PATCH 58/88] [libvpx] Fix threading. --- libs/libvpx/vp8/common/threading.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/libvpx/vp8/common/threading.h b/libs/libvpx/vp8/common/threading.h index 0de75cfde3..96e83e2068 100644 --- a/libs/libvpx/vp8/common/threading.h +++ b/libs/libvpx/vp8/common/threading.h @@ -74,12 +74,12 @@ static INLINE int vp8_sem_wait(vp8_sem_t *sem) { /* Not Windows. Assume pthreads */ /* thread_sleep implementation: yield unless Linux/Unix. */ +#include +#include #if defined(__unix__) || defined(__APPLE__) -#define thread_sleep(nms) -/* {struct timespec ts;ts.tv_sec=0; - ts.tv_nsec = 1000*nms;nanosleep(&ts, NULL);} */ +#define thread_sleep(nms) { struct timespec ts;ts.tv_sec=0; ts.tv_nsec = 1000*nms;sched_yield();nanosleep(&ts, NULL);} #else -#define thread_sleep(nms) sched_yield(); +#define thread_sleep(nms) {struct timespec ts;ts.tv_sec=0; ts.tv_nsec = 1000*nms;sched_yield();clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);} #endif /* __unix__ || __APPLE__ */ #endif @@ -97,7 +97,7 @@ static INLINE void vp8_atomic_spin_wait( const int nsync) { while (mb_col > (vpx_atomic_load_acquire(last_row_current_mb_col) - nsync)) { x86_pause_hint(); - thread_sleep(0); + thread_sleep(1000); } } From f7ec023dc1a1694f34cd72ee6e670197abf136e6 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 17 Nov 2026 00:21:54 +0300 Subject: [PATCH 59/88] Merge pull request #3291 from signalwire/libnatpmp-dev [Core] Remove in-tree libnatpmp: use libnatpmp-dev on Linux and the windows-deps package on Windows --- .github/workflows/macos.yml | 1 + .gitignore | 2 + LICENSE | 4 - Makefile.am | 4 +- build/Makefile.centos6 | 4 +- configure.ac | 5 + debian/bootstrap.sh | 1 + debian/copyright | 4 - docs/Doxygen.conf | 2 +- freeswitch.spec | 2 + libs/libnatpmp/Changelog.txt | 43 -- libs/libnatpmp/LICENCE | 26 -- libs/libnatpmp/Makefile | 75 ---- libs/libnatpmp/build.bat | 17 - libs/libnatpmp/declspec.h | 15 - libs/libnatpmp/getgateway.c | 425 ------------------ libs/libnatpmp/getgateway.h | 35 -- libs/libnatpmp/natpmp.c | 371 --------------- libs/libnatpmp/natpmp.def | 11 - libs/libnatpmp/natpmp.h | 194 -------- libs/libnatpmp/natpmpc.c | 202 --------- libs/libnatpmp/testgetgateway.c | 42 -- libs/libnatpmp/wingettimeofday.c | 0 .../FreeSWITCH-debian-raspbian-installer.sh | 2 +- scripts/debian_min_build.sh | 2 +- src/switch_nat.c | 8 +- .../FreeSwitchCore.2010.vcxproj.filters | 6 - w32/Library/FreeSwitchCore.2017.vcxproj | 53 +-- w32/libnatpmp-version.props | 21 + w32/libnatpmp.props | 60 +++ 30 files changed, 107 insertions(+), 1530 deletions(-) delete mode 100644 libs/libnatpmp/Changelog.txt delete mode 100644 libs/libnatpmp/LICENCE delete mode 100644 libs/libnatpmp/Makefile delete mode 100644 libs/libnatpmp/build.bat delete mode 100644 libs/libnatpmp/declspec.h delete mode 100644 libs/libnatpmp/getgateway.c delete mode 100644 libs/libnatpmp/getgateway.h delete mode 100644 libs/libnatpmp/natpmp.c delete mode 100644 libs/libnatpmp/natpmp.def delete mode 100644 libs/libnatpmp/natpmp.h delete mode 100644 libs/libnatpmp/natpmpc.c delete mode 100644 libs/libnatpmp/testgetgateway.c delete mode 100644 libs/libnatpmp/wingettimeofday.c create mode 100644 w32/libnatpmp-version.props create mode 100644 w32/libnatpmp.props diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index ec3ad6525f..7f01f9d4a8 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -39,6 +39,7 @@ jobs: jpeg \ ldns \ libks \ + libnatpmp \ libpq@18 \ libsndfile \ libtool \ diff --git a/.gitignore b/.gitignore index d7e1801528..49c133c20b 100644 --- a/.gitignore +++ b/.gitignore @@ -297,6 +297,8 @@ libs/freetype-*/ libs/freetype-*.zip libs/miniupnpc-*/ libs/miniupnpc-*.zip +libs/libnatpmp-*/ +libs/libnatpmp-*.zip libs/SharpZipLib.*/ libs/SharpZipLib.*.nupkg libs/nasm-*/ diff --git a/LICENSE b/LICENSE index 72dfbe3062..8a2c76cd95 100644 --- a/LICENSE +++ b/LICENSE @@ -1554,10 +1554,6 @@ Files: libs/libtpl-1.5/src/tpl.[ch] Copyright: 2005-2010, Troy D. Hanson License: BSD-2-clause -Files: libs/libnatpmp/* -Copyright: 2007-2008, Thomas BERNARD -License: ISC - Files: libs/libwebsockets/* Copyright: 2010-2011 Andy Green License: LGPL diff --git a/Makefile.am b/Makefile.am index c6fa430dda..d5abe51a80 100644 --- a/Makefile.am +++ b/Makefile.am @@ -279,7 +279,7 @@ endif lib_LTLIBRARIES = libfreeswitch.la libfreeswitch_la_CFLAGS = $(CORE_CFLAGS) $(SQLITE_CFLAGS) $(GUMBO_CFLAGS) $(FVAD_CFLAGS) $(FREETYPE_CFLAGS) $(CURL_CFLAGS) $(PCRE2_CFLAGS) $(SPEEX_CFLAGS) $(MINIUPNPC_CFLAGS) $(LIBEDIT_CFLAGS) $(openssl_CFLAGS) $(SOFIA_SIP_CFLAGS) $(AM_CFLAGS) $(TPL_CFLAGS) libfreeswitch_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) $(PLATFORM_CORE_LDFLAGS) -no-undefined -libfreeswitch_la_LIBADD = $(CORE_LIBS) $(APR_LIBS) $(SQLITE_LIBS) $(GUMBO_LIBS) $(FVAD_LIBS) $(FREETYPE_LIBS) $(CURL_LIBS) $(PCRE2_LIBS) $(SPEEX_LIBS) $(MINIUPNPC_LIBS) $(LIBEDIT_LIBS) $(SYSTEMD_LIBS) $(openssl_LIBS) $(PLATFORM_CORE_LIBS) $(TPL_LIBS) $(SPANDSP_LIBS) $(SOFIA_SIP_LIBS) +libfreeswitch_la_LIBADD = $(CORE_LIBS) $(APR_LIBS) $(SQLITE_LIBS) $(GUMBO_LIBS) $(FVAD_LIBS) $(FREETYPE_LIBS) $(CURL_LIBS) $(PCRE2_LIBS) $(SPEEX_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(LIBEDIT_LIBS) $(SYSTEMD_LIBS) $(openssl_LIBS) $(PLATFORM_CORE_LIBS) $(TPL_LIBS) $(SPANDSP_LIBS) $(SOFIA_SIP_LIBS) libfreeswitch_la_DEPENDENCIES = $(BUILT_SOURCES) if HAVE_PNG @@ -430,8 +430,6 @@ libfreeswitch_la_SOURCES = \ src/switch_vpx.c \ libs/libteletone/src/libteletone_detect.c \ libs/libteletone/src/libteletone_generate.c \ - libs/libnatpmp/natpmp.c \ - libs/libnatpmp/getgateway.c \ src/switch_uuidv7.c if ENABLE_CPP diff --git a/build/Makefile.centos6 b/build/Makefile.centos6 index 062384a5f5..197803eabf 100644 --- a/build/Makefile.centos6 +++ b/build/Makefile.centos6 @@ -6,8 +6,8 @@ # in that same directory. # # -RPMS=git gcc-c++ autoconf automake libtool wget ncurses-devel zlib-devel libjpeg-devel openssl-devel e2fsprogs-devel sqlite-devel libcurl-devel pcre2-devel speex-devel miniupnpc-devel ldns-devel libedit-devel -DEBS=git build-essential automake autoconf 'libtool-bin|libtool' wget uuid-dev zlib1g-dev 'libjpeg8-dev|libjpeg62-turbo-dev' libncurses5-dev libssl-dev libpcre2-dev libcurl4-openssl-dev libldns-dev libedit-dev libspeexdsp-dev libspeexdsp-dev libsqlite3-dev libminiupnpc-dev perl libgdbm-dev libdb-dev bison libvlc-dev pkg-config +RPMS=git gcc-c++ autoconf automake libtool wget ncurses-devel zlib-devel libjpeg-devel openssl-devel e2fsprogs-devel sqlite-devel libcurl-devel pcre2-devel speex-devel miniupnpc-devel libnatpmp-devel ldns-devel libedit-devel +DEBS=git build-essential automake autoconf 'libtool-bin|libtool' wget uuid-dev zlib1g-dev 'libjpeg8-dev|libjpeg62-turbo-dev' libncurses5-dev libssl-dev libpcre2-dev libcurl4-openssl-dev libldns-dev libedit-dev libspeexdsp-dev libspeexdsp-dev libsqlite3-dev libminiupnpc-dev libnatpmp-dev perl libgdbm-dev libdb-dev bison libvlc-dev pkg-config freeswitch: deps has-git freeswitch.git/Makefile cd freeswitch.git && make diff --git a/configure.ac b/configure.ac index 92179dd23a..d43f1ee306 100644 --- a/configure.ac +++ b/configure.ac @@ -1347,6 +1347,11 @@ PKG_CHECK_MODULES([CURL], [libcurl >= 7.19]) PKG_CHECK_MODULES([PCRE2], [libpcre2-8 >= 10.00]) PKG_CHECK_MODULES([SPEEX], [speex >= 1.2rc1 speexdsp >= 1.2rc1]) PKG_CHECK_MODULES([MINIUPNPC], [miniupnpc >= 2.1]) + +AC_CHECK_HEADER([natpmp.h], [], [AC_MSG_ERROR([no usable libnatpmp; please install libnatpmp devel package or equivalent])]) +AC_CHECK_LIB([natpmp], [initnatpmp], [NATPMP_LIBS=-lnatpmp], [AC_MSG_ERROR([no usable libnatpmp; please install libnatpmp devel package or equivalent])]) +AC_SUBST([NATPMP_LIBS]) + PKG_CHECK_MODULES([LDNS], [libldns-fs >= 1.6.6],[ AM_CONDITIONAL([HAVE_LDNS],[true])],[ PKG_CHECK_MODULES([LDNS], [libldns >= 1.6.6],[ diff --git a/debian/bootstrap.sh b/debian/bootstrap.sh index 6d562a0652..9d10c7e86c 100755 --- a/debian/bootstrap.sh +++ b/debian/bootstrap.sh @@ -304,6 +304,7 @@ Build-Depends: libsqlite3-dev, libtiff5-dev, libminiupnpc-dev (>= 2.1), + libnatpmp-dev, wget, pkg-config, yasm, # core codecs diff --git a/debian/copyright b/debian/copyright index 3a9d364f5c..75f1ea8997 100755 --- a/debian/copyright +++ b/debian/copyright @@ -1549,10 +1549,6 @@ Files: libs/libtpl-1.5/src/tpl.[ch] Copyright: 2005-2010, Troy D. Hanson License: BSD-2-clause -Files: libs/libnatpmp/* -Copyright: 2007-2008, Thomas BERNARD -License: ISC - Files: libs/libwebsockets/* Copyright: 2010-2011 Andy Green License: LGPL diff --git a/docs/Doxygen.conf b/docs/Doxygen.conf index 8db1f0dbfb..0946185baf 100644 --- a/docs/Doxygen.conf +++ b/docs/Doxygen.conf @@ -1240,7 +1240,7 @@ SEARCH_INCLUDES = YES # contain include files that are not input files but should be processed by # the preprocessor. -INCLUDE_PATH =../libs/apr ../libs/apr-util ../libs/libnatpmp \ +INCLUDE_PATH =../libs/apr ../libs/apr-util \ ../libs/sofia-sip ../libs/spandsp \ ../libs/srtp ../libs/win32 ../libs/xmlrpc-c diff --git a/freeswitch.spec b/freeswitch.spec index 7a0887df79..1ed513ba0a 100755 --- a/freeswitch.spec +++ b/freeswitch.spec @@ -136,6 +136,7 @@ BuildRequires: spandsp4-devel >= 3.1.1 BuildRequires: pcre2-devel BuildRequires: speex-devel BuildRequires: miniupnpc-devel >= 2.1 +BuildRequires: libnatpmp-devel BuildRequires: sqlite-devel >= 3.6.20 BuildRequires: libtiff-devel BuildRequires: libedit-devel @@ -151,6 +152,7 @@ Requires: curl >= 7.19 Requires: pcre2 Requires: speex Requires: miniupnpc >= 2.1 +Requires: libnatpmp Requires: sqlite >= 3.6.20 Requires: libtiff Requires: libedit diff --git a/libs/libnatpmp/Changelog.txt b/libs/libnatpmp/Changelog.txt deleted file mode 100644 index b1237e0c4e..0000000000 --- a/libs/libnatpmp/Changelog.txt +++ /dev/null @@ -1,43 +0,0 @@ -$Id: Changelog.txt,v 1.14 2009/03/10 10:15:30 nanard Exp $ - -2009/03/10: - Trying to have windows get gateway working if not using DHCP - -2009/02/27: - dont include declspec.h if not under WIN32. - -2009/01/23: - Prefixed the libraries name with lib - -2008/10/06: - Fixed a memory leak in getdefaultgateway() (USE_SYSCTL_NET_ROUTE) - -2008/07/03: - Adding WIN32 code from Robbie Hanson - -2008/06/30: - added a Solaris implementation for getgateway(). - added a LICENCE file to the distribution - -2008/05/29: - Anonymous unions are forbidden in ANSI C. That was causing problems with - non-GCC compilers. - -2008/04/28: - introduced strnatpmperr() - improved natpmpc.c sample - make install now install the binary - -2007/12/13: - Fixed getgateway.c for working under OS X ;) - Fixed values for NATPMP_PROTOCOL_TCP and NATPMP_PROTOCOL_UDP - -2007/12/11: - Fixed getgateway.c for compilation under Mac OS X - -2007/12/01: - added some comments in .h - -2007/11/30: - implemented almost everything - diff --git a/libs/libnatpmp/LICENCE b/libs/libnatpmp/LICENCE deleted file mode 100644 index 222a8847b8..0000000000 --- a/libs/libnatpmp/LICENCE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2007-2008, Thomas BERNARD -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - diff --git a/libs/libnatpmp/Makefile b/libs/libnatpmp/Makefile deleted file mode 100644 index ec9dc63091..0000000000 --- a/libs/libnatpmp/Makefile +++ /dev/null @@ -1,75 +0,0 @@ -# $Id: Makefile,v 1.7 2009/01/23 19:05:04 nanard Exp $ -# This Makefile is designed for use with GNU make -# libnatpmp -# (c) 2007-2009 Thomas Bernard -# http://miniupnp.free.fr/libnatpmp.html - -CC = gcc -INSTALL = install - -# APIVERSION is used in soname -APIVERSION = 0 -CFLAGS = -O -fPIC -Wall -DENABLE_STRNATPMPERR - -LIBOBJS = natpmp.o getgateway.o - -OBJS = $(LIBOBJS) testgetgateway.o natpmpc.o - -STATICLIB = libnatpmp.a -SHAREDLIB = libnatpmp.so -SONAME = $(SHAREDLIB).$(APIVERSION) - -HEADERS = natpmp.h - -EXECUTABLES = testgetgateway natpmpc-shared natpmpc-static - -INSTALLPREFIX ?= $(PREFIX)/usr -INSTALLDIRINC = $(INSTALLPREFIX)/include -INSTALLDIRLIB = $(INSTALLPREFIX)/lib -INSTALLDIRBIN = $(INSTALLPREFIX)/bin - -.PHONY: all clean depend install cleaninstall - -all: $(STATICLIB) $(SHAREDLIB) $(EXECUTABLES) - -clean: - $(RM) $(OBJS) $(EXECUTABLES) $(STATICLIB) $(SHAREDLIB) - -depend: - makedepend -f$(MAKEFILE_LIST) -Y $(OBJS:.o=.c) 2>/dev/null - -install: $(HEADERS) $(STATICLIB) $(SHAREDLIB) - $(INSTALL) -d $(INSTALLDIRINC) - $(INSTALL) --mode=644 $(HEADERS) $(INSTALLDIRINC) - $(INSTALL) -d $(INSTALLDIRLIB) - $(INSTALL) --mode=644 $(STATICLIB) $(INSTALLDIRLIB) - $(INSTALL) --mode=644 $(SHAREDLIB) $(INSTALLDIRLIB)/$(SONAME) - $(INSTALL) --mode=755 natpmpc-shared $(INSTALLDIRBIN)/natpmpc - ln --symbolic --force $(SONAME) $(INSTALLDIRLIB)/$(SHAREDLIB) - -cleaninstall: - $(RM) $(addprefix $(INSTALLDIRINC), $(HEADERS)) - $(RM) $(INSTALLDIRLIB)/$(SONAME) - $(RM) $(INSTALLDIRLIB)/$(SHAREDLIB) - $(RM) $(INSTALLDIRLIB)/$(STATICLIB) - -testgetgateway: testgetgateway.o getgateway.o - -natpmpc-static: natpmpc.o $(STATICLIB) - $(CC) -o $@ $^ - -natpmpc-shared: natpmpc.o $(SHAREDLIB) - $(CC) -o $@ $^ - -$(STATICLIB): $(LIBOBJS) - $(AR) crs $@ $? - -$(SHAREDLIB): $(LIBOBJS) - $(CC) -shared -Wl,-soname,$(SONAME) -o $@ $^ - -# DO NOT DELETE - -natpmp.o: natpmp.h getgateway.h -getgateway.o: getgateway.h -testgetgateway.o: getgateway.h -natpmpc.o: natpmp.h diff --git a/libs/libnatpmp/build.bat b/libs/libnatpmp/build.bat deleted file mode 100644 index a376193ac0..0000000000 --- a/libs/libnatpmp/build.bat +++ /dev/null @@ -1,17 +0,0 @@ -@echo Compile getgateway -gcc -c -Wall -Os -DWIN32 -DSTATICLIB -DENABLE_STRNATPMPERR getgateway.c -gcc -c -Wall -Os -DWIN32 -DSTATICLIB -DENABLE_STRNATPMPERR testgetgateway.c -gcc -o testgetgateway getgateway.o testgetgateway.o -lws2_32 - -@echo Compile natpmp: -gcc -c -Wall -Os -DWIN32 -DSTATICLIB -DENABLE_STRNATPMPERR getgateway.c -gcc -c -Wall -Os -DWIN32 -DSTATICLIB -DENABLE_STRNATPMPERR natpmp.c -gcc -c -Wall -Os -DWIN32 -DSTATICLIB -DENABLE_STRNATPMPERR natpmpc.c -gcc -c -Wall -Os -DWIN32 wingettimeofday.c -gcc -o natpmpc getgateway.o natpmp.o natpmpc.o wingettimeofday.o -lws2_32 - -@echo Create natpmp.dll: -gcc -c -Wall -Os -DWIN32 -DENABLE_STRNATPMPERR -DNATPMP_EXPORTS getgateway.c -gcc -c -Wall -Os -DWIN32 -DENABLE_STRNATPMPERR -DNATPMP_EXPORTS natpmp.c -dllwrap -k --driver-name gcc --def natpmp.def --output-def natpmp.dll.def --implib natpmp.lib -o natpmp.dll getgateway.o natpmp.o wingettimeofday.o -lws2_32 - diff --git a/libs/libnatpmp/declspec.h b/libs/libnatpmp/declspec.h deleted file mode 100644 index ea479d1e6c..0000000000 --- a/libs/libnatpmp/declspec.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __DECLSPEC_H__ -#define __DECLSPEC_H__ - -#if defined(WIN32) && !defined(STATICLIB) - #ifdef NATPMP_EXPORTS - #define LIBSPEC __declspec(dllexport) - #else - #define LIBSPEC __declspec(dllimport) - #endif -#else - #define LIBSPEC -#endif - -#endif - diff --git a/libs/libnatpmp/getgateway.c b/libs/libnatpmp/getgateway.c deleted file mode 100644 index e1f5536a50..0000000000 --- a/libs/libnatpmp/getgateway.c +++ /dev/null @@ -1,425 +0,0 @@ -/* $Id: getgateway.c,v 1.13 2009/03/10 10:15:31 nanard Exp $ */ -/* libnatpmp - * Copyright (c) 2007-2008, Thomas BERNARD - * - * 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 -#include -#ifndef WIN32 -#include -#endif -#ifndef _MSC_VER -#include -#endif -/* There is no portable method to get the default route gateway. - * So below are three differents functions implementing this. - * Parsing /proc/net/route is for linux. - * sysctl is the way to access such informations on BSD systems. - * Many systems should provide route information through raw PF_ROUTE - * sockets. */ -#ifdef __linux__ -#define USE_PROC_NET_ROUTE -#undef USE_SOCKET_ROUTE -#undef USE_SYSCTL_NET_ROUTE -#endif - -#ifdef BSD -#undef USE_PROC_NET_ROUTE -#define USE_SOCKET_ROUTE -#undef USE_SYSCTL_NET_ROUTE -#endif - -#ifdef __APPLE__ -#undef USE_PROC_NET_ROUTE -#undef USE_SOCKET_ROUTE -#define USE_SYSCTL_NET_ROUTE -#endif - -#if ((defined(sun) || defined(__sun)) && defined(__SVR4)) -#undef USE_PROC_NET_ROUTE -#define USE_SOCKET_ROUTE -#undef USE_SYSCTL_NET_ROUTE -#endif - -#ifdef WIN32 -#undef USE_PROC_NET_ROUTE -#undef USE_SOCKET_ROUTE -#undef USE_SYSCTL_NET_ROUTE -#define USE_WIN32_CODE -#endif - -#ifdef USE_SYSCTL_NET_ROUTE -#include -#include -#include -#include -#endif -#ifdef USE_SOCKET_ROUTE -#include -#include -#include -#include -#include -#endif -#ifdef WIN32 -#include -#include -#define MAX_KEY_LENGTH 255 -#define MAX_VALUE_LENGTH 16383 -#endif -#include "getgateway.h" - -#ifndef WIN32 -#define SUCCESS (0) -#define FAILED (-1) -#endif - -#ifdef USE_PROC_NET_ROUTE -int getdefaultgateway(in_addr_t * addr) -{ - unsigned long d, g; - char buf[256]; - int line = 0; - FILE * f; - char * p; - f = fopen("/proc/net/route", "r"); - if(!f) - return FAILED; - while(fgets(buf, sizeof(buf), f)) { - if(line > 0) { - p = buf; - while(*p && !isspace(*p)) - p++; - while(*p && isspace(*p)) - p++; - if(sscanf(p, "%lx%lx", &d, &g)==2) { - if(d == 0) { /* default */ - *addr = g; - fclose(f); - return SUCCESS; - } - } - } - line++; - } - /* default route not found ! */ - if(f) - fclose(f); - return FAILED; -} -#endif /* #ifdef USE_PROC_NET_ROUTE */ - - -#ifdef USE_SYSCTL_NET_ROUTE - -#define ROUNDUP(a) \ - ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) - -int getdefaultgateway(in_addr_t * addr) -{ -#if 0 - /* net.route.0.inet.dump.0.0 ? */ - int mib[] = {CTL_NET, PF_ROUTE, 0, AF_INET, - NET_RT_DUMP, 0, 0/*tableid*/}; -#endif - /* net.route.0.inet.flags.gateway */ - int mib[] = {CTL_NET, PF_ROUTE, 0, AF_INET, - NET_RT_FLAGS, RTF_GATEWAY}; - size_t l; - char * buf, * p; - struct rt_msghdr * rt; - struct sockaddr * sa; - struct sockaddr * sa_tab[RTAX_MAX]; - int i; - int r = FAILED; - if(sysctl(mib, sizeof(mib)/sizeof(int), 0, &l, 0, 0) < 0) { - return FAILED; - } - if(l>0) { - buf = malloc(l); - if(sysctl(mib, sizeof(mib)/sizeof(int), buf, &l, 0, 0) < 0) { - free(buf); - return FAILED; - } - for(p=buf; prtm_msglen) { - rt = (struct rt_msghdr *)p; - sa = (struct sockaddr *)(rt + 1); - for(i=0; irtm_addrs & (1 << i)) { - sa_tab[i] = sa; - sa = (struct sockaddr *)((char *)sa + ROUNDUP(sa->sa_len)); - } else { - sa_tab[i] = NULL; - } - } - if( ((rt->rtm_addrs & (RTA_DST|RTA_GATEWAY)) == (RTA_DST|RTA_GATEWAY)) - && sa_tab[RTAX_DST]->sa_family == AF_INET - && sa_tab[RTAX_GATEWAY]->sa_family == AF_INET) { - if(((struct sockaddr_in *)sa_tab[RTAX_DST])->sin_addr.s_addr == 0) { - *addr = ((struct sockaddr_in *)(sa_tab[RTAX_GATEWAY]))->sin_addr.s_addr; - r = SUCCESS; - } - } - } - free(buf); - } - return r; -} -#endif /* #ifdef USE_SYSCTL_NET_ROUTE */ - - -#ifdef USE_SOCKET_ROUTE -/* Thanks to Darren Kenny for this code */ -#define NEXTADDR(w, u) \ - if (rtm_addrs & (w)) {\ - l = sizeof(struct sockaddr); memmove(cp, &(u), l); cp += l;\ - } - -#define rtm m_rtmsg.m_rtm - -struct { - struct rt_msghdr m_rtm; - char m_space[512]; -} m_rtmsg; - -int getdefaultgateway(in_addr_t *addr) -{ - int s, seq, l, rtm_addrs, i; - pid_t pid; - struct sockaddr so_dst, so_mask; - char *cp = m_rtmsg.m_space; - struct sockaddr *gate = NULL, *sa; - struct rt_msghdr *msg_hdr; - - pid = getpid(); - seq = 0; - rtm_addrs = RTA_DST | RTA_NETMASK; - - memset(&so_dst, 0, sizeof(so_dst)); - memset(&so_mask, 0, sizeof(so_mask)); - memset(&rtm, 0, sizeof(struct rt_msghdr)); - - rtm.rtm_type = RTM_GET; - rtm.rtm_flags = RTF_UP | RTF_GATEWAY; - rtm.rtm_version = RTM_VERSION; - rtm.rtm_seq = ++seq; - rtm.rtm_addrs = rtm_addrs; - - so_dst.sa_family = AF_INET; - so_mask.sa_family = AF_INET; - - NEXTADDR(RTA_DST, so_dst); - NEXTADDR(RTA_NETMASK, so_mask); - - rtm.rtm_msglen = l = cp - (char *)&m_rtmsg; - - s = socket(PF_ROUTE, SOCK_RAW, 0); - - if (write(s, (char *)&m_rtmsg, l) < 0) { - close(s); - return FAILED; - } - - do { - l = read(s, (char *)&m_rtmsg, sizeof(m_rtmsg)); - } while (l > 0 && (rtm.rtm_seq != seq || rtm.rtm_pid != pid)); - - close(s); - - msg_hdr = &rtm; - - cp = ((char *)(msg_hdr + 1)); - if (msg_hdr->rtm_addrs) { - for (i = 1; i; i <<= 1) - if (i & msg_hdr->rtm_addrs) { - sa = (struct sockaddr *)cp; - if (i == RTA_GATEWAY ) - gate = sa; - - cp += sizeof(struct sockaddr); - } - } else { - return FAILED; - } - - - if (gate != NULL ) { - *addr = ((struct sockaddr_in *)gate)->sin_addr.s_addr; - return SUCCESS; - } else { - return FAILED; - } -} -#endif /* #ifdef USE_SOCKET_ROUTE */ - -#ifdef USE_WIN32_CODE -int getdefaultgateway(in_addr_t * addr) -{ - HKEY networkCardsKey; - HKEY networkCardKey; - HKEY interfacesKey; - HKEY interfaceKey; - DWORD i = 0; - DWORD numSubKeys = 0; - TCHAR keyName[MAX_KEY_LENGTH]; - DWORD keyNameLength = MAX_KEY_LENGTH; - BYTE keyValue[MAX_VALUE_LENGTH]; - DWORD keyValueLength = MAX_VALUE_LENGTH; - DWORD keyValueType = REG_SZ; - BYTE gatewayValue[MAX_VALUE_LENGTH]; - DWORD gatewayValueLength = MAX_VALUE_LENGTH; - DWORD gatewayValueType = REG_MULTI_SZ; - int done = 0; - - char networkCardsPath[] = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards"; - char interfacesPath[] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces"; - - // The windows registry lists its primary network devices in the following location: - // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards - // - // Each network device has its own subfolder, named with an index, with various properties: - // -NetworkCards - // -5 - // -Description = Broadcom 802.11n Network Adapter - // -ServiceName = {E35A72F8-5065-4097-8DFE-C7790774EE4D} - // -8 - // -Description = Marvell Yukon 88E8058 PCI-E Gigabit Ethernet Controller - // -ServiceName = {86226414-5545-4335-A9D1-5BD7120119AD} - // - // The above service name is the name of a subfolder within: - // HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces - // - // There may be more subfolders in this interfaces path than listed in the network cards path above: - // -Interfaces - // -{3a539854-6a70-11db-887c-806e6f6e6963} - // -DhcpIPAddress = 0.0.0.0 - // -[more] - // -{E35A72F8-5065-4097-8DFE-C7790774EE4D} - // -DhcpIPAddress = 10.0.1.4 - // -DhcpDefaultGateway = 10.0.1.1 - // -[more] - // -{86226414-5545-4335-A9D1-5BD7120119AD} - // -DhcpIpAddress = 10.0.1.5 - // -DhcpDefaultGateay = 10.0.1.1 - // -[more] - // - // In order to extract this information, we enumerate each network card, and extract the ServiceName value. - // This is then used to open the interface subfolder, and attempt to extract a DhcpDefaultGateway value. - // Once one is found, we're done. - // - // It may be possible to simply enumerate the interface folders until we find one with a DhcpDefaultGateway value. - // However, the technique used is the technique most cited on the web, and we assume it to be more correct. - - if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, // Open registry key or predifined key - networkCardsPath, // Name of registry subkey to open - 0, // Reserved - must be zero - KEY_READ, // Mask - desired access rights - &networkCardsKey)) // Pointer to output key - { - // Unable to open network cards keys - return -1; - } - - if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, // Open registry key or predefined key - interfacesPath, // Name of registry subkey to open - 0, // Reserved - must be zero - KEY_READ, // Mask - desired access rights - &interfacesKey)) // Pointer to output key - { - // Unable to open interfaces key - RegCloseKey(networkCardsKey); - return -1; - } - - // Figure out how many subfolders are within the NetworkCards folder - RegQueryInfoKey(networkCardsKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - - //printf( "Number of subkeys: %u\n", (unsigned int)numSubKeys); - - // Enumrate through each subfolder within the NetworkCards folder - for(i = 0; i < numSubKeys && !done; i++) - { - keyNameLength = MAX_KEY_LENGTH; - if(ERROR_SUCCESS == RegEnumKeyEx(networkCardsKey, // Open registry key - i, // Index of subkey to retrieve - keyName, // Buffer that receives the name of the subkey - &keyNameLength, // Variable that receives the size of the above buffer - NULL, // Reserved - must be NULL - NULL, // Buffer that receives the class string - NULL, // Variable that receives the size of the above buffer - NULL)) // Variable that receives the last write time of subkey - { - if(RegOpenKeyEx(networkCardsKey, keyName, 0, KEY_READ, &networkCardKey) == ERROR_SUCCESS) - { - keyValueLength = MAX_VALUE_LENGTH; - if(ERROR_SUCCESS == RegQueryValueEx(networkCardKey, // Open registry key - "ServiceName", // Name of key to query - NULL, // Reserved - must be NULL - &keyValueType, // Receives value type - keyValue, // Receives value - &keyValueLength)) // Receives value length in bytes - { - //printf("keyValue: %s\n", keyValue); - - if(RegOpenKeyEx(interfacesKey, (char *)keyValue, 0, KEY_READ, &interfaceKey) == ERROR_SUCCESS) - { - gatewayValueLength = MAX_VALUE_LENGTH; - if(ERROR_SUCCESS == RegQueryValueEx(interfaceKey, // Open registry key - "DhcpDefaultGateway", // Name of key to query - NULL, // Reserved - must be NULL - &gatewayValueType, // Receives value type - gatewayValue, // Receives value - &gatewayValueLength)) // Receives value length in bytes - { - // Check to make sure it's a string - if(gatewayValueType == REG_MULTI_SZ || gatewayValueType == REG_SZ) - { - //printf("gatewayValue: %s\n", gatewayValue); - done = 1; - } - } - else if(ERROR_SUCCESS == RegQueryValueEx(interfaceKey, // Open registry key - "DefaultGateway", // Name of key to query - NULL, // Reserved - must be NULL - &gatewayValueType, // Receives value type - gatewayValue, // Receives value - &gatewayValueLength)) // Receives value length in bytes - { - // Check to make sure it's a string - if(gatewayValueType == REG_MULTI_SZ || gatewayValueType == REG_SZ) - { - //printf("gatewayValue: %s\n", gatewayValue); - done = 1; - } - } - RegCloseKey(interfaceKey); - } - } - RegCloseKey(networkCardKey); - } - } - } - - RegCloseKey(interfacesKey); - RegCloseKey(networkCardsKey); - - if(done) - { - *addr = inet_addr((char *)gatewayValue); - return 0; - } - - return -1; -} -#endif /* #ifdef USE_WIN32_CODE */ - diff --git a/libs/libnatpmp/getgateway.h b/libs/libnatpmp/getgateway.h deleted file mode 100644 index a08b02a6d1..0000000000 --- a/libs/libnatpmp/getgateway.h +++ /dev/null @@ -1,35 +0,0 @@ -/* $Id: getgateway.h,v 1.3 2008/07/02 22:33:06 nanard Exp $ */ -/* libnatpmp - * Copyright (c) 2007, Thomas BERNARD - * - * 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. */ -#ifndef __GETGATEWAY_H__ -#define __GETGATEWAY_H__ - -#ifdef WIN32 -#ifdef _MSC_VER -typedef unsigned __int32 uint32_t; -#else -#include -#endif -#define in_addr_t uint32_t -#endif -#include "declspec.h" - -/* getdefaultgateway() : - * return value : - * 0 : success - * -1 : failure */ -LIBSPEC int getdefaultgateway(in_addr_t * addr); - -#endif diff --git a/libs/libnatpmp/natpmp.c b/libs/libnatpmp/natpmp.c deleted file mode 100644 index 0e2c4ea0b4..0000000000 --- a/libs/libnatpmp/natpmp.c +++ /dev/null @@ -1,371 +0,0 @@ -/* $Id: natpmp.c,v 1.8 2008/07/02 22:33:06 nanard Exp $ */ -/* libnatpmp - * Copyright (c) 2007-2008, Thomas BERNARD - * http://miniupnp.free.fr/libnatpmp.html - * - * 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. */ -#ifdef __linux__ -#ifndef _DEFAULT_SOURCE -#define _DEFAULT_SOURCE -#endif -#define _BSD_SOURCE 1 -#endif -#include -#include -#ifndef _MSC_VER -#include -#endif -#ifdef WIN32 -#include -#include -#include -#ifndef EWOULDBLOCK -#define EWOULDBLOCK WSAEWOULDBLOCK -#endif -#ifndef ECONNREFUSED -#define ECONNREFUSED WSAECONNREFUSED -#endif - -static int gettimeofday(struct timeval* p, void* tz /* IGNORED */) { - union { - long long ns100; /*time since 1 Jan 1601 in 100ns units */ - FILETIME ft; - } _now; - - GetSystemTimeAsFileTime( &(_now.ft) ); - p->tv_usec=(long)((_now.ns100 / 10LL) % 1000000LL ); - p->tv_sec= (long)((_now.ns100-(116444736000000000LL))/10000000LL); - return 0; -} - -#else -#include -#include -#include -#include -#include -#define closesocket close -#endif -#include "natpmp.h" -#include "getgateway.h" - -int initnatpmp(natpmp_t * p) -{ -#ifdef WIN32 - u_long ioctlArg = 1; -#else - int flags; -#endif - struct sockaddr_in addr; - if(!p) - return NATPMP_ERR_INVALIDARGS; - memset(p, 0, sizeof(natpmp_t)); - p->s = socket(PF_INET, SOCK_DGRAM, 0); - if(p->s < 0) - return NATPMP_ERR_SOCKETERROR; -#ifdef WIN32 - if(ioctlsocket(p->s, FIONBIO, &ioctlArg) == SOCKET_ERROR) - return NATPMP_ERR_FCNTLERROR; -#else - if((flags = fcntl(p->s, F_GETFL, 0)) < 0) - return NATPMP_ERR_FCNTLERROR; - if(fcntl(p->s, F_SETFL, flags | O_NONBLOCK) < 0) - return NATPMP_ERR_FCNTLERROR; -#endif - - if(getdefaultgateway(&(p->gateway)) < 0) - return NATPMP_ERR_CANNOTGETGATEWAY; - - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(NATPMP_PORT); - addr.sin_addr.s_addr = p->gateway; - if(connect(p->s, (struct sockaddr *)&addr, sizeof(addr)) < 0) - return NATPMP_ERR_CONNECTERR; - return 0; -} - -int closenatpmp(natpmp_t * p) -{ - if(!p) - return NATPMP_ERR_INVALIDARGS; - if(closesocket(p->s) < 0) - return NATPMP_ERR_CLOSEERR; - return 0; -} - -int sendpendingrequest(natpmp_t * p) -{ - int r; -/* struct sockaddr_in addr;*/ - if(!p) - return NATPMP_ERR_INVALIDARGS; -/* memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(NATPMP_PORT); - addr.sin_addr.s_addr = p->gateway; - r = (int)sendto(p->s, p->pending_request, p->pending_request_len, 0, - (struct sockaddr *)&addr, sizeof(addr));*/ - r = (int)send(p->s, p->pending_request, p->pending_request_len, 0); - return (r<0) ? NATPMP_ERR_SENDERR : r; -} - -int sendnatpmprequest(natpmp_t * p) -{ - int n; - if(!p) - return NATPMP_ERR_INVALIDARGS; - /* TODO : check if no request is allready pending */ - p->has_pending_request = 1; - p->try_number = 1; - n = sendpendingrequest(p); - gettimeofday(&p->retry_time, NULL); // check errors ! - p->retry_time.tv_usec += 250000; /* add 250ms */ - if(p->retry_time.tv_usec >= 1000000) { - p->retry_time.tv_usec -= 1000000; - p->retry_time.tv_sec++; - } - return n; -} - -int getnatpmprequesttimeout(natpmp_t * p, struct timeval * timeout) -{ - struct timeval now; - if(!p || !timeout) - return NATPMP_ERR_INVALIDARGS; - if(!p->has_pending_request) - return NATPMP_ERR_NOPENDINGREQ; - if(gettimeofday(&now, NULL) < 0) - return NATPMP_ERR_GETTIMEOFDAYERR; - timeout->tv_sec = p->retry_time.tv_sec - now.tv_sec; - timeout->tv_usec = p->retry_time.tv_usec - now.tv_usec; - if(timeout->tv_usec < 0) { - timeout->tv_usec += 1000000; - timeout->tv_sec--; - } - return 0; -} - -int sendpublicaddressrequest(natpmp_t * p) -{ - if(!p) - return NATPMP_ERR_INVALIDARGS; - //static const unsigned char request[] = { 0, 0 }; - p->pending_request[0] = 0; - p->pending_request[1] = 0; - p->pending_request_len = 2; - // TODO: return 0 instead of sizeof(request) ?? - return sendnatpmprequest(p); -} - -int sendnewportmappingrequest(natpmp_t * p, int protocol, - uint16_t privateport, uint16_t publicport, - uint32_t lifetime) -{ - uint16_t *n; - uint32_t *m; - - if(!p || (protocol!=NATPMP_PROTOCOL_TCP && protocol!=NATPMP_PROTOCOL_UDP)) - return NATPMP_ERR_INVALIDARGS; - p->pending_request[0] = 0; - p->pending_request[1] = (char)protocol; - p->pending_request[2] = 0; - p->pending_request[3] = 0; - n = (uint16_t *)(p->pending_request + 4); *n = htons(privateport); - n = (uint16_t *)(p->pending_request + 6); *n = htons(publicport); - m = (uint32_t *)(p->pending_request + 8); *m = htonl(lifetime); - - //*((uint16_t *)(p->pending_request + 4)) = htons(privateport); - //*((uint16_t *)(p->pending_request + 6)) = htons(publicport); - //*((uint32_t *)(p->pending_request + 8)) = htonl(lifetime); - p->pending_request_len = 12; - return sendnatpmprequest(p); -} - -int readnatpmpresponse(natpmp_t * p, natpmpresp_t * response) -{ - unsigned char buf[16]; - struct sockaddr_in addr = {0}; - socklen_t addrlen = sizeof(addr); - int n; - if(!p) - return NATPMP_ERR_INVALIDARGS; - n = recvfrom(p->s, (char *)buf, sizeof(buf), 0, - (struct sockaddr *)&addr, &addrlen); - if(n<0) - switch(errno) { - /*case EAGAIN:*/ - case EWOULDBLOCK: - n = NATPMP_TRYAGAIN; - break; - case ECONNREFUSED: - n = NATPMP_ERR_NOGATEWAYSUPPORT; - break; - default: - n = NATPMP_ERR_RECVFROM; - } - /* check that addr is correct (= gateway) */ - else if(addr.sin_addr.s_addr != p->gateway) - n = NATPMP_ERR_WRONGPACKETSOURCE; - else { - response->resultcode = ntohs(*((uint16_t *)(buf + 2))); - response->epoch = ntohl(*((uint32_t *)(buf + 4))); - if(buf[0] != 0) - n = NATPMP_ERR_UNSUPPORTEDVERSION; - else if(buf[1] < 128 || buf[1] > 130) - n = NATPMP_ERR_UNSUPPORTEDOPCODE; - else if(response->resultcode != 0) { - switch(response->resultcode) { - case 1: - n = NATPMP_ERR_UNSUPPORTEDVERSION; - break; - case 2: - n = NATPMP_ERR_NOTAUTHORIZED; - break; - case 3: - n = NATPMP_ERR_NETWORKFAILURE; - break; - case 4: - n = NATPMP_ERR_OUTOFRESOURCES; - break; - case 5: - n = NATPMP_ERR_UNSUPPORTEDOPCODE; - break; - default: - n = NATPMP_ERR_UNDEFINEDERROR; - } - } else { - response->type = buf[1] & 0x7f; - if(buf[1] == 128) - //response->publicaddress.addr = *((uint32_t *)(buf + 8)); - response->pnu.publicaddress.addr.s_addr = *((uint32_t *)(buf + 8)); - else { - response->pnu.newportmapping.privateport = ntohs(*((uint16_t *)(buf + 8))); - response->pnu.newportmapping.mappedpublicport = ntohs(*((uint16_t *)(buf + 10))); - response->pnu.newportmapping.lifetime = ntohl(*((uint32_t *)(buf + 12))); - } - n = 0; - } - } - return n; -} - -int readnatpmpresponseorretry(natpmp_t * p, natpmpresp_t * response) -{ - int n; - if(!p || !response) - return NATPMP_ERR_INVALIDARGS; - if(!p->has_pending_request) - return NATPMP_ERR_NOPENDINGREQ; - n = readnatpmpresponse(p, response); - if(n<0) { - if(n==NATPMP_TRYAGAIN) { - struct timeval now; - gettimeofday(&now, NULL); // check errors ! - if(timercmp(&now, &p->retry_time, >=)) { - int delay, r; - if(p->try_number >= 9) { - return NATPMP_ERR_NOGATEWAYSUPPORT; - } - /*printf("retry! %d\n", p->try_number);*/ - delay = 250 * (1<try_number); // ms - /*for(i=0; itry_number; i++) - delay += delay;*/ - p->retry_time.tv_sec += (delay / 1000); - p->retry_time.tv_usec += (delay % 1000) * 1000; - if(p->retry_time.tv_usec >= 1000000) { - p->retry_time.tv_usec -= 1000000; - p->retry_time.tv_sec++; - } - p->try_number++; - r = sendpendingrequest(p); - if(r<0) - return r; - } - } - } else { - p->has_pending_request = 0; - } - return n; -} - -#ifdef ENABLE_STRNATPMPERR -const char * strnatpmperr(int r) -{ - const char * s; - switch(r) { - case NATPMP_ERR_INVALIDARGS: - s = "invalid arguments"; - break; - case NATPMP_ERR_SOCKETERROR: - s = "socket() failed"; - break; - case NATPMP_ERR_CANNOTGETGATEWAY: - s = "cannot get default gateway ip address"; - break; - case NATPMP_ERR_CLOSEERR: -#ifdef WIN32 - s = "closesocket() failed"; -#else - s = "close() failed"; -#endif - break; - case NATPMP_ERR_RECVFROM: - s = "recvfrom() failed"; - break; - case NATPMP_ERR_NOPENDINGREQ: - s = "no pending request"; - break; - case NATPMP_ERR_NOGATEWAYSUPPORT: - s = "the gateway does not support nat-pmp"; - break; - case NATPMP_ERR_CONNECTERR: - s = "connect() failed"; - break; - case NATPMP_ERR_WRONGPACKETSOURCE: - s = "packet not received from the default gateway"; - break; - case NATPMP_ERR_SENDERR: - s = "send() failed"; - break; - case NATPMP_ERR_FCNTLERROR: - s = "fcntl() failed"; - break; - case NATPMP_ERR_GETTIMEOFDAYERR: - s = "gettimeofday() failed"; - break; - case NATPMP_ERR_UNSUPPORTEDVERSION: - s = "unsupported nat-pmp version error from server"; - break; - case NATPMP_ERR_UNSUPPORTEDOPCODE: - s = "unsupported nat-pmp opcode error from server"; - break; - case NATPMP_ERR_UNDEFINEDERROR: - s = "undefined nat-pmp server error"; - break; - case NATPMP_ERR_NOTAUTHORIZED: - s = "not authorized"; - break; - case NATPMP_ERR_NETWORKFAILURE: - s = "network failure"; - break; - case NATPMP_ERR_OUTOFRESOURCES: - s = "nat-pmp server out of resources"; - break; - default: - s = "Unknown libnatpmp error"; - } - return s; -} -#endif - diff --git a/libs/libnatpmp/natpmp.def b/libs/libnatpmp/natpmp.def deleted file mode 100644 index cd110033fa..0000000000 --- a/libs/libnatpmp/natpmp.def +++ /dev/null @@ -1,11 +0,0 @@ -LIBRARY -; libnatpmp library - -EXPORTS - initnatpmp - closenatpmp - sendpublicaddressrequest - sendnewportmappingrequest - getnatpmprequesttimeout - readnatpmpresponseorretry - strnatpmperr diff --git a/libs/libnatpmp/natpmp.h b/libs/libnatpmp/natpmp.h deleted file mode 100644 index 0ff41b081a..0000000000 --- a/libs/libnatpmp/natpmp.h +++ /dev/null @@ -1,194 +0,0 @@ -/* $Id: natpmp.h,v 1.11 2009/02/27 22:38:05 nanard Exp $ */ -/* libnatpmp - * Copyright (c) 2007-2008, Thomas BERNARD - * http://miniupnp.free.fr/libnatpmp.html - * - * 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. */ -#ifndef __NATPMP_H__ -#define __NATPMP_H__ - -/* NAT-PMP Port as defined by the NAT-PMP draft */ -#define NATPMP_PORT (5351) - -#include -#ifndef _MSC_VER -#include -#endif -#ifdef WIN32 -#include -#ifdef _MSC_VER -typedef unsigned __int32 uint32_t; -typedef unsigned __int16 uint16_t; -#else -#include -#endif -#define in_addr_t uint32_t -#include "declspec.h" -#else -#define LIBSPEC -#include -#endif - -typedef struct { - int s; /* socket */ - in_addr_t gateway; /* default gateway (IPv4) */ - int has_pending_request; - char pending_request[12]; - int pending_request_len; - int try_number; - struct timeval retry_time; -} natpmp_t; - -typedef struct { - uint16_t type; /* NATPMP_RESPTYPE_* */ - uint16_t resultcode; /* NAT-PMP response code */ - uint32_t epoch; /* Seconds since start of epoch */ - union { - struct { - //in_addr_t addr; - struct in_addr addr; - } publicaddress; - struct { - uint16_t privateport; - uint16_t mappedpublicport; - uint32_t lifetime; - } newportmapping; - } pnu; -} natpmpresp_t; - -/* possible values for type field of natpmpresp_t */ -#define NATPMP_RESPTYPE_PUBLICADDRESS (0) -#define NATPMP_RESPTYPE_UDPPORTMAPPING (1) -#define NATPMP_RESPTYPE_TCPPORTMAPPING (2) - -/* Values to pass to sendnewportmappingrequest() */ -#define NATPMP_PROTOCOL_UDP (1) -#define NATPMP_PROTOCOL_TCP (2) - -/* return values */ -/* NATPMP_ERR_INVALIDARGS : invalid arguments passed to the function */ -#define NATPMP_ERR_INVALIDARGS (-1) -/* NATPMP_ERR_SOCKETERROR : socket() failed. check errno for details */ -#define NATPMP_ERR_SOCKETERROR (-2) -/* NATPMP_ERR_CANNOTGETGATEWAY : can't get default gateway IP */ -#define NATPMP_ERR_CANNOTGETGATEWAY (-3) -/* NATPMP_ERR_CLOSEERR : close() failed. check errno for details */ -#define NATPMP_ERR_CLOSEERR (-4) -/* NATPMP_ERR_RECVFROM : recvfrom() failed. check errno for details */ -#define NATPMP_ERR_RECVFROM (-5) -/* NATPMP_ERR_NOPENDINGREQ : readnatpmpresponseorretry() called while - * no NAT-PMP request was pending */ -#define NATPMP_ERR_NOPENDINGREQ (-6) -/* NATPMP_ERR_NOGATEWAYSUPPORT : the gateway does not support NAT-PMP */ -#define NATPMP_ERR_NOGATEWAYSUPPORT (-7) -/* NATPMP_ERR_CONNECTERR : connect() failed. check errno for details */ -#define NATPMP_ERR_CONNECTERR (-8) -/* NATPMP_ERR_WRONGPACKETSOURCE : packet not received from the network gateway */ -#define NATPMP_ERR_WRONGPACKETSOURCE (-9) -/* NATPMP_ERR_SENDERR : send() failed. check errno for details */ -#define NATPMP_ERR_SENDERR (-10) -/* NATPMP_ERR_FCNTLERROR : fcntl() failed. check errno for details */ -#define NATPMP_ERR_FCNTLERROR (-11) -/* NATPMP_ERR_GETTIMEOFDAYERR : gettimeofday() failed. check errno for details */ -#define NATPMP_ERR_GETTIMEOFDAYERR (-12) - -/* */ -#define NATPMP_ERR_UNSUPPORTEDVERSION (-14) -#define NATPMP_ERR_UNSUPPORTEDOPCODE (-15) - -/* Errors from the server : */ -#define NATPMP_ERR_UNDEFINEDERROR (-49) -#define NATPMP_ERR_NOTAUTHORIZED (-51) -#define NATPMP_ERR_NETWORKFAILURE (-52) -#define NATPMP_ERR_OUTOFRESOURCES (-53) - -/* NATPMP_TRYAGAIN : no data available for the moment. try again later */ -#define NATPMP_TRYAGAIN (-100) - -/* initnatpmp() - * initialize a natpmp_t object - * Return values : - * 0 = OK - * NATPMP_ERR_INVALIDARGS - * NATPMP_ERR_SOCKETERROR - * NATPMP_ERR_FCNTLERROR - * NATPMP_ERR_CANNOTGETGATEWAY - * NATPMP_ERR_CONNECTERR */ -LIBSPEC int initnatpmp(natpmp_t * p); - -/* closenatpmp() - * close resources associated with a natpmp_t object - * Return values : - * 0 = OK - * NATPMP_ERR_INVALIDARGS - * NATPMP_ERR_CLOSEERR */ -LIBSPEC int closenatpmp(natpmp_t * p); - -/* sendpublicaddressrequest() - * send a public address NAT-PMP request to the network gateway - * Return values : - * 2 = OK (size of the request) - * NATPMP_ERR_INVALIDARGS - * NATPMP_ERR_SENDERR */ -LIBSPEC int sendpublicaddressrequest(natpmp_t * p); - -/* sendnewportmappingrequest() - * send a new port mapping NAT-PMP request to the network gateway - * Arguments : - * protocol is either NATPMP_PROTOCOL_TCP or NATPMP_PROTOCOL_UDP, - * lifetime is in seconds. - * To remove a port mapping, set lifetime to zero. - * To remove all port mappings to the host, set lifetime and both ports - * to zero. - * Return values : - * 12 = OK (size of the request) - * NATPMP_ERR_INVALIDARGS - * NATPMP_ERR_SENDERR */ -LIBSPEC int sendnewportmappingrequest(natpmp_t * p, int protocol, - uint16_t privateport, uint16_t publicport, - uint32_t lifetime); - -/* getnatpmprequesttimeout() - * fills the timeval structure with the timeout duration of the - * currently pending NAT-PMP request. - * Return values : - * 0 = OK - * NATPMP_ERR_INVALIDARGS - * NATPMP_ERR_GETTIMEOFDAYERR - * NATPMP_ERR_NOPENDINGREQ */ -LIBSPEC int getnatpmprequesttimeout(natpmp_t * p, struct timeval * timeout); - -/* readnatpmpresponseorretry() - * fills the natpmpresp_t structure if possible - * Return values : - * 0 = OK - * NATPMP_TRYAGAIN - * NATPMP_ERR_INVALIDARGS - * NATPMP_ERR_NOPENDINGREQ - * NATPMP_ERR_NOGATEWAYSUPPORT - * NATPMP_ERR_RECVFROM - * NATPMP_ERR_WRONGPACKETSOURCE - * NATPMP_ERR_UNSUPPORTEDVERSION - * NATPMP_ERR_UNSUPPORTEDOPCODE - * NATPMP_ERR_NOTAUTHORIZED - * NATPMP_ERR_NETWORKFAILURE - * NATPMP_ERR_OUTOFRESOURCES - * NATPMP_ERR_UNSUPPORTEDOPCODE - * NATPMP_ERR_UNDEFINEDERROR */ -LIBSPEC int readnatpmpresponseorretry(natpmp_t * p, natpmpresp_t * response); - -#ifdef ENABLE_STRNATPMPERR -LIBSPEC const char * strnatpmperr(int t); -#endif - -#endif diff --git a/libs/libnatpmp/natpmpc.c b/libs/libnatpmp/natpmpc.c deleted file mode 100644 index a393508ede..0000000000 --- a/libs/libnatpmp/natpmpc.c +++ /dev/null @@ -1,202 +0,0 @@ -/* $Id: natpmpc.c,v 1.6 2008/07/02 22:33:06 nanard Exp $ */ -/* libnatpmp - * Copyright (c) 2007-2008, Thomas BERNARD - * http://miniupnp.free.fr/libnatpmp.html - * - * 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 -#include -#include -#include -#ifdef WIN32 -#include -#else -#include -#include -#endif -#include "natpmp.h" - -void usage(FILE * out, const char * argv0) -{ - fprintf(out, "Usage :\n"); - fprintf(out, " %s\n", argv0); - fprintf(out, "\tdisplay the public IP address.\n"); - fprintf(out, " %s -h\n", argv0); - fprintf(out, "\tdisplay this help screen.\n"); - fprintf(out, " %s -a [lifetime]\n", argv0); - fprintf(out, "\tadd a port mapping.\n"); - fprintf(out, "\n In order to remove a mapping, set it with a lifetime of 0 seconds.\n"); - fprintf(out, " To remove all mappings for your machine, use 0 as private port and lifetime.\n"); -} - -/* sample code for using libnatpmp */ -int main(int argc, char * * argv) -{ - natpmp_t natpmp; - natpmpresp_t response; - int r; - int sav_errno; - struct timeval timeout; - fd_set fds; - int i; - int protocol = 0; - uint16_t privateport = 0; - uint16_t publicport = 0; - uint32_t lifetime = 3600; - int command = 0; - -#ifdef WIN32 - WSADATA wsaData; - int nResult = WSAStartup(MAKEWORD(2,2), &wsaData); - if(nResult != NO_ERROR) - { - fprintf(stderr, "WSAStartup() failed.\n"); - return -1; - } -#endif - - /* argument parsing */ - for(i=1; i= i) { - i++; - if(1 != sscanf(argv[i], "%u", &lifetime)) { - fprintf(stderr, "%s is not a correct 32bits unsigned integer\n", argv[i]); - } - } - break; - default: - fprintf(stderr, "Unknown option %s\n", argv[i]); - usage(stderr, argv[0]); - return 1; - } - } else { - fprintf(stderr, "Unknown option %s\n", argv[i]); - usage(stderr, argv[0]); - return 1; - } - } - - /* initnatpmp() */ - r = initnatpmp(&natpmp); - printf("initnatpmp() returned %d (%s)\n", r, r?"FAILED":"SUCCESS"); - if(r<0) - return 1; - - /* sendpublicaddressrequest() */ - r = sendpublicaddressrequest(&natpmp); - printf("sendpublicaddressrequest returned %d (%s)\n", - r, r==2?"SUCCESS":"FAILED"); - if(r<0) - return 1; - - do { - FD_ZERO(&fds); - FD_SET(natpmp.s, &fds); - getnatpmprequesttimeout(&natpmp, &timeout); - select(FD_SETSIZE, &fds, NULL, NULL, &timeout); - r = readnatpmpresponseorretry(&natpmp, &response); - sav_errno = errno; - printf("readnatpmpresponseorretry returned %d (%s)\n", - r, r==0?"OK":(r==NATPMP_TRYAGAIN?"TRY AGAIN":"FAILED")); - if(r<0 && r!=NATPMP_TRYAGAIN) { -#ifdef ENABLE_STRNATPMPERR - fprintf(stderr, "readnatpmpresponseorretry() failed : %s\n", - strnatpmperr(r)); -#endif - fprintf(stderr, " errno=%d '%s'\n", - sav_errno, strerror(sav_errno)); - } - } while(r==NATPMP_TRYAGAIN); - if(r<0) - return 1; - - /* TODO : check that response.type == 0 */ - printf("Public IP address : %s\n", inet_ntoa(response.pnu.publicaddress.addr)); - printf("epoch = %u\n", response.epoch); - - if(command == 'a') { - /* sendnewportmappingrequest() */ - r = sendnewportmappingrequest(&natpmp, protocol, - privateport, publicport, - lifetime); - printf("sendnewportmappingrequest returned %d (%s)\n", - r, r==12?"SUCCESS":"FAILED"); - if(r < 0) - return 1; - - do { - FD_ZERO(&fds); - FD_SET(natpmp.s, &fds); - getnatpmprequesttimeout(&natpmp, &timeout); - select(FD_SETSIZE, &fds, NULL, NULL, &timeout); - r = readnatpmpresponseorretry(&natpmp, &response); - printf("readnatpmpresponseorretry returned %d (%s)\n", - r, r==0?"OK":(r==NATPMP_TRYAGAIN?"TRY AGAIN":"FAILED")); - } while(r==NATPMP_TRYAGAIN); - if(r<0) { -#ifdef ENABLE_STRNATPMPERR - fprintf(stderr, "readnatpmpresponseorretry() failed : %s\n", - strnatpmperr(r)); -#endif - return 1; - } - - printf("Mapped public port %hu protocol %s to local port %hu " - "liftime %u\n", - response.pnu.newportmapping.mappedpublicport, - response.type == NATPMP_RESPTYPE_UDPPORTMAPPING ? "UDP" : - (response.type == NATPMP_RESPTYPE_TCPPORTMAPPING ? "TCP" : - "UNKNOWN"), - response.pnu.newportmapping.privateport, - response.pnu.newportmapping.lifetime); - printf("epoch = %u\n", response.epoch); - } - - r = closenatpmp(&natpmp); - printf("closenatpmp() returned %d (%s)\n", r, r==0?"SUCCESS":"FAILED"); - if(r<0) - return 1; - - return 0; -} - diff --git a/libs/libnatpmp/testgetgateway.c b/libs/libnatpmp/testgetgateway.c deleted file mode 100644 index d559683a65..0000000000 --- a/libs/libnatpmp/testgetgateway.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $Id: testgetgateway.c,v 1.4 2008/07/02 22:33:06 nanard Exp $ */ -/* libnatpmp - * Copyright (c) 2007, Thomas BERNARD - * - * 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 -#ifdef WIN32 -#include -#else -#include -#include -#endif -#include "getgateway.h" - -int main(int argc, char * * argv) -{ - struct in_addr gatewayaddr; - int r; -#ifdef WIN32 - uint32_t temp = 0; - r = getdefaultgateway(&temp); - gatewayaddr.S_un.S_addr = temp; -#else - r = getdefaultgateway(&(gatewayaddr.s_addr)); -#endif - if(r>=0) - printf("default gateway : %s\n", inet_ntoa(gatewayaddr)); - else - fprintf(stderr, "getdefaultgateway() failed\n"); - return 0; -} - diff --git a/libs/libnatpmp/wingettimeofday.c b/libs/libnatpmp/wingettimeofday.c deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/scripts/FreeSWITCH-debian-raspbian-installer.sh b/scripts/FreeSWITCH-debian-raspbian-installer.sh index ac97ab44d5..4decc77242 100755 --- a/scripts/FreeSWITCH-debian-raspbian-installer.sh +++ b/scripts/FreeSWITCH-debian-raspbian-installer.sh @@ -249,7 +249,7 @@ freeswitch_debian_source() { freeswitch_raspbian_source() { apt-get install -o Dpkg::Progress=1 -y autoconf automake devscripts gawk libjpeg-dev libncurses5-dev libtool-bin \ libtiff5-dev libperl-dev libgdbm-dev libdb-dev gettext libssl-dev libcurl4-openssl-dev libpcre3-dev libspeex-dev \ - libspeexdsp-dev libsqlite3-dev libminiupnpc-dev libedit-dev libldns-dev libpq-dev libsndfile-dev libopus-dev liblua5.1-0-dev 2>&1 | \ + libspeexdsp-dev libsqlite3-dev libminiupnpc-dev libnatpmp-dev libedit-dev libldns-dev libpq-dev libsndfile-dev libopus-dev liblua5.1-0-dev 2>&1 | \ awk -W interactive '/Progress/ { print }'| sed -u 's/[^0-9]//g' | dialog --gauge "Please wait.\n Installing Build Requirements..." 10 70 0 build_fs diff --git a/scripts/debian_min_build.sh b/scripts/debian_min_build.sh index ba0e92449d..d7dddc977b 100755 --- a/scripts/debian_min_build.sh +++ b/scripts/debian_min_build.sh @@ -8,7 +8,7 @@ wget -O - https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list -apt-get update && apt-get install -y libtool libjpeg62-turbo-dev ntpdate libfreetype6-dev git-buildpackage doxygen yasm gdb git build-essential automake autoconf wget uuid-dev zlib1g-dev libncurses5-dev libssl-dev libpcre3-dev libcurl4-openssl-dev libldns-dev libedit-dev libspeexdsp-dev libsqlite3-dev libminiupnpc-dev perl libgdbm-dev libdb-dev bison pkg-config ccache libpng16-dev libpng12-dev libopenal-dev libbroadvoice-dev libcodec2-dev libflite-dev libg7221-dev libilbc-dev libsilk-dev liblua5.2-dev libopus-dev libsndfile-dev libavformat-dev libavcodec-extra libswscale-dev libx264-dev libperl-dev unixodbc-dev libpq-dev libsctp-dev +apt-get update && apt-get install -y libtool libjpeg62-turbo-dev ntpdate libfreetype6-dev git-buildpackage doxygen yasm gdb git build-essential automake autoconf wget uuid-dev zlib1g-dev libncurses5-dev libssl-dev libpcre3-dev libcurl4-openssl-dev libldns-dev libedit-dev libspeexdsp-dev libsqlite3-dev libminiupnpc-dev libnatpmp-dev perl libgdbm-dev libdb-dev bison pkg-config ccache libpng16-dev libpng12-dev libopenal-dev libbroadvoice-dev libcodec2-dev libflite-dev libg7221-dev libilbc-dev libsilk-dev liblua5.2-dev libopus-dev libsndfile-dev libavformat-dev libavcodec-extra libswscale-dev libx264-dev libperl-dev unixodbc-dev libpq-dev libsctp-dev cd /usr/src diff --git a/src/switch_nat.c b/src/switch_nat.c index 7a730a80ad..d88123925a 100644 --- a/src/switch_nat.c +++ b/src/switch_nat.c @@ -36,7 +36,7 @@ #include #include #include -#include "../libs/libnatpmp/natpmp.h" +#include #define MULTICAST_BUFFSIZE 65536 #define IP_LEN 16 @@ -170,7 +170,7 @@ static int get_pmp_pubaddr(char *pub_addr) const char *err = NULL; int pflags; - if ((r = initnatpmp(&natpmp)) < 0) { + if ((r = initnatpmp(&natpmp, 0, 0)) < 0) { err = "init failed"; goto end; } @@ -465,7 +465,7 @@ static switch_status_t switch_nat_add_mapping_pmp(switch_port_t port, switch_nat int r; natpmp_t natpmp; - initnatpmp(&natpmp); + initnatpmp(&natpmp, 0, 0); if (proto == SWITCH_NAT_TCP) { sendnewportmappingrequest(&natpmp, NATPMP_PROTOCOL_TCP, port, port, 31104000); @@ -537,7 +537,7 @@ static switch_status_t switch_nat_del_mapping_pmp(switch_port_t port, switch_nat int r; natpmp_t natpmp; - initnatpmp(&natpmp); + initnatpmp(&natpmp, 0, 0); if (proto == SWITCH_NAT_TCP) { sendnewportmappingrequest(&natpmp, NATPMP_PROTOCOL_TCP, port, port, 0); diff --git a/w32/Library/FreeSwitchCore.2010.vcxproj.filters b/w32/Library/FreeSwitchCore.2010.vcxproj.filters index cb623ec125..a1a6f27ee3 100644 --- a/w32/Library/FreeSwitchCore.2010.vcxproj.filters +++ b/w32/Library/FreeSwitchCore.2010.vcxproj.filters @@ -7,15 +7,9 @@ Source Files - - Source Files - Source Files - - Source Files - Source Files diff --git a/w32/Library/FreeSwitchCore.2017.vcxproj b/w32/Library/FreeSwitchCore.2017.vcxproj index 7074a1b7d3..7bf48f31b7 100644 --- a/w32/Library/FreeSwitchCore.2017.vcxproj +++ b/w32/Library/FreeSwitchCore.2017.vcxproj @@ -57,6 +57,7 @@ + @@ -135,7 +136,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" Disabled ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) - CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) + CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) true EnableFastChecks MultiThreadedDebugDLL @@ -185,7 +186,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" Disabled ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) - CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) + CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) true EnableFastChecks MultiThreadedDebugDLL @@ -226,7 +227,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" MaxSpeed ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x86;%(AdditionalIncludeDirectories) - CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) + CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) MultiThreadedDLL Create switch.h @@ -264,7 +265,7 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" MaxSpeed ..\..\src\include;..\..\libs\include;..\..\libs\srtp\include;..\..\libs\srtp\crypto\include;..\..\libs\libteletone\src;..\..\libs\spandsp\src\msvc;..\..\libs\spandsp\src;..\..\libs\libtpl-1.5\src;..\..\libs\libtpl-1.5\src\win;..\..\libs\sofia-sip\libsofia-sip-ua\sdp;..\..\libs\sofia-sip\libsofia-sip-ua\su;..\..\libs\sofia-sip\win32;..\..\libs\libyuv\include;..\..\libs\libvpx;..\..\libs\win32\libvpx\include_x64;%(AdditionalIncludeDirectories) - CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;STATICLIB;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) + CJSON_EXPORT_SYMBOLS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;FREESWITCHCORE_EXPORTS;CRASH_PROT;TPL_NOLIB;LIBSOFIA_SIP_UA_STATIC;SWITCH_HAVE_YUV;SWITCH_HAVE_VPX;SWITCH_HAVE_PNG;SWITCH_HAVE_FREETYPE;%(PreprocessorDefinitions) MultiThreadedDLL Create switch.h @@ -426,50 +427,6 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\" - - - - - - - - 4100;%(DisableSpecificWarnings) - - - 4100;%(DisableSpecificWarnings) - - - - - - - 4100;%(DisableSpecificWarnings) - - - 4100;%(DisableSpecificWarnings) - - - - - - - - - 4100;%(DisableSpecificWarnings) - - - 4100;%(DisableSpecificWarnings) - - - - - - - 4100;%(DisableSpecificWarnings) - - - 4100;%(DisableSpecificWarnings) - diff --git a/w32/libnatpmp-version.props b/w32/libnatpmp-version.props new file mode 100644 index 0000000000..1501de45e9 --- /dev/null +++ b/w32/libnatpmp-version.props @@ -0,0 +1,21 @@ + + + + + 20230423 + 1 + + + true + + + + + + $(libnatpmpVersion) + + + $(libnatpmpBuildNumber) + + + diff --git a/w32/libnatpmp.props b/w32/libnatpmp.props new file mode 100644 index 0000000000..5984b31665 --- /dev/null +++ b/w32/libnatpmp.props @@ -0,0 +1,60 @@ + + + + + + + + $(BaseDir)libs\libnatpmp-$(libnatpmpVersion)_$(libnatpmpBuildNumber) + + + + + + + + + + + + + + $(libnatpmpLibDir)\include;%(AdditionalIncludeDirectories) + NATPMP_STATICLIB;%(PreprocessorDefinitions) + + + $(libnatpmpLibDir)\binaries\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + natpmp.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies) + + + From 1af2909bb6772aa606f1deb4bde2d858e279f4c4 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 17 Nov 2026 15:35:58 +0300 Subject: [PATCH 60/88] [mod_dialplan_xml] Fix $N substitution of captures (#3293) Keep the subject string of a saved match alive and substitute only when a regex matched. Add unit-tests. --- .../mod_dialplan_xml/mod_dialplan_xml.c | 21 ++- tests/unit/conf/freeswitch.xml | 59 +++++++ tests/unit/switch_ivr_originate.c | 158 ++++++++++++++++++ 3 files changed, 232 insertions(+), 6 deletions(-) diff --git a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c index cab522887c..4c9687d4ab 100644 --- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c +++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c @@ -339,7 +339,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * if (all) break; } - if (field && strchr(expression, '(')) { + if (field && match_data && strchr(expression, '(')) { char var[256]; switch_snprintf(var, sizeof(var), "DP_REGEX_MATCH_%d", total); @@ -352,7 +352,14 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * switch_regex_safe_free(save_re); save_expression = strdup(expression); - save_field_data = strdup(field_data); + /* match_data points into the subject string it matched, so field_expanded moves with it */ + if (field_expanded) { + save_field_data = field_expanded; + field_expanded = NULL; + } else { + save_field_data = strdup(field_data); + } + save_re = re; save_match_data = match_data; save_proceed = proceed; @@ -379,9 +386,8 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * } } - switch_safe_free(field_expanded); - if (expression == expression_expanded) expression = NULL; - switch_safe_free(expression_expanded); + /* field_expanded and expression_expanded stay allocated: after a break out of the loop, + * re and match_data still refer to them. The next condition or done frees them. */ } else { if ((xexpression = switch_xml_child(xcond, "expression"))) { expression = switch_str_nil(xexpression->txt); @@ -449,6 +455,9 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * } if (save_re) { + switch_safe_free(field_expanded); + switch_safe_free(expression_expanded); + re = save_re; match_data = save_match_data; save_re = NULL; @@ -532,7 +541,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * data = (char *) switch_xml_attr_soft(xaction, "data"); } - if (field && expression && strchr(expression, '(')) { + if (field && expression && match_data && strchr(expression, '(')) { len = (uint32_t) (strlen(data) + strlen(field_data) + 10) * proceed; if (!(substituted = malloc(len))) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Memory Error!\n"); diff --git a/tests/unit/conf/freeswitch.xml b/tests/unit/conf/freeswitch.xml index e7c185531c..7997d765cb 100644 --- a/tests/unit/conf/freeswitch.xml +++ b/tests/unit/conf/freeswitch.xml @@ -73,5 +73,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/unit/switch_ivr_originate.c b/tests/unit/switch_ivr_originate.c index 5603e18f0e..85c8429a82 100644 --- a/tests/unit/switch_ivr_originate.c +++ b/tests/unit/switch_ivr_originate.c @@ -95,6 +95,25 @@ static void loopback_group_confirm_event_handler(switch_event_t *event) // gener } } +/* Runs the XML dialplan in the given context of tests/unit/conf/freeswitch.xml */ +static switch_caller_extension_t *dialplan_regex_hunt(switch_core_session_t *session, const char *context) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_caller_profile_t *caller_profile = switch_caller_profile_clone(session, switch_channel_get_caller_profile(channel)); + switch_dialplan_interface_t *dialplan_interface = switch_loadable_module_get_dialplan_interface("XML"); + switch_caller_extension_t *extension = NULL; + + if (dialplan_interface) { + switch_channel_set_variable(channel, "regex_test_uri", "sip:15551234567@example.com"); + switch_channel_set_variable(channel, "regex_test_prefix", "1"); + caller_profile->context = switch_core_session_strdup(session, context); + extension = dialplan_interface->hunt_function(session, NULL, caller_profile); + UNPROTECT_INTERFACE(dialplan_interface); + } + + return extension; +} + FST_CORE_BEGIN("./conf") { FST_SUITE_BEGIN(switch_ivr_originate) @@ -113,6 +132,145 @@ FST_CORE_BEGIN("./conf") } FST_TEARDOWN_END() + /* regex="all" where the last regex has a ${var} field and a capture group: $1 is the captured digits */ + FST_TEST_BEGIN(dialplan_regex_all_expanded_field_capture) + { + switch_core_session_t *session = NULL; + switch_caller_extension_t *extension = NULL; + switch_call_cause_t cause = SWITCH_CAUSE_NONE; + switch_status_t status; + const char *expected[] = { "set", "captured=5551234567", NULL }; + + status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(session != NULL); + + if (session) { + extension = dialplan_regex_hunt(session, "regex_all_capture"); + fst_check_extension_apps(expected, extension); + + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(session); + } + } + FST_TEST_END() + + /* regex="all" where a ${var} field fails after a capture: the anti-action runs */ + FST_TEST_BEGIN(dialplan_regex_all_expanded_field_fail_after_capture) + { + switch_core_session_t *session = NULL; + switch_caller_extension_t *extension = NULL; + switch_call_cause_t cause = SWITCH_CAUSE_NONE; + switch_status_t status; + const char *expected[] = { "set", "captured=none", NULL }; + + status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(session != NULL); + + if (session) { + extension = dialplan_regex_hunt(session, "regex_all_fail_after_capture"); + fst_check_extension_apps(expected, extension); + + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(session); + } + } + FST_TEST_END() + + /* regex="any" where the first regex has a ${var} field and a capture group: $1 is the captured digits */ + FST_TEST_BEGIN(dialplan_regex_any_expanded_field_capture) + { + switch_core_session_t *session = NULL; + switch_caller_extension_t *extension = NULL; + switch_call_cause_t cause = SWITCH_CAUSE_NONE; + switch_status_t status; + const char *expected[] = { "set", "captured=5551234567", NULL }; + + status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(session != NULL); + + if (session) { + extension = dialplan_regex_hunt(session, "regex_any_capture"); + fst_check_extension_apps(expected, extension); + + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(session); + } + } + FST_TEST_END() + + /* regex="any" where the expression has a ${var} and a capture group: $1 is the captured digits */ + FST_TEST_BEGIN(dialplan_regex_any_expanded_expression_capture) + { + switch_core_session_t *session = NULL; + switch_caller_extension_t *extension = NULL; + switch_call_cause_t cause = SWITCH_CAUSE_NONE; + switch_status_t status; + const char *expected[] = { "set", "captured=5551234567", NULL }; + + status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(session != NULL); + + if (session) { + extension = dialplan_regex_hunt(session, "regex_any_expanded_expression_capture"); + fst_check_extension_apps(expected, extension); + + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(session); + } + } + FST_TEST_END() + + /* regex="xor" where the first regex captures and the second one, also with a group, fails: $1 is the captured digits */ + FST_TEST_BEGIN(dialplan_regex_xor_capture_then_fail) + { + switch_core_session_t *session = NULL; + switch_caller_extension_t *extension = NULL; + switch_call_cause_t cause = SWITCH_CAUSE_NONE; + switch_status_t status; + const char *expected[] = { "set", "captured=5551234567", NULL }; + + status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(session != NULL); + + if (session) { + extension = dialplan_regex_hunt(session, "regex_xor_capture_then_fail"); + fst_check_extension_apps(expected, extension); + + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(session); + } + } + FST_TEST_END() + + /* regex="xor" where the first regex has no group and matches, and the second one, with a group, fails: + * the action data stays as written */ + FST_TEST_BEGIN(dialplan_regex_xor_no_capture_then_fail) + { + switch_core_session_t *session = NULL; + switch_caller_extension_t *extension = NULL; + switch_call_cause_t cause = SWITCH_CAUSE_NONE; + switch_status_t status; + const char *expected[] = { "set", "captured=$1", NULL }; + + status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(session != NULL); + + if (session) { + extension = dialplan_regex_hunt(session, "regex_xor_no_capture_then_fail"); + fst_check_extension_apps(expected, extension); + + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(session); + } + } + FST_TEST_END() + FST_TEST_BEGIN(originate_test_external_id) { switch_core_session_t *session = NULL; From 222d8959548afbd15d1caae0413bac48c64e036a Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 17 Nov 2026 21:08:00 +0300 Subject: [PATCH 61/88] [Build-System] Windows: Upgrade sqlite to v3.54.1_1 (#3294) --- w32/sqlite-version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/w32/sqlite-version.props b/w32/sqlite-version.props index 1b1c583062..57861763f0 100644 --- a/w32/sqlite-version.props +++ b/w32/sqlite-version.props @@ -2,7 +2,7 @@ - 3.53.4 + 3.54.1 1 From 1fa330cafde1b0dff80455ad09f903d681e09738 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Tue, 17 Nov 2026 23:14:38 +0300 Subject: [PATCH 62/88] [Core] RTP: stop using the libsrtp private API (#3292) Use switch_rtp_hdr_t instead of srtp_hdr_t from srtp_priv.h, and srtp_shutdown() instead of srtp_crypto_kernel_shutdown(). Drop the rtp_hdr_t alias and add a compile-time check that switch_rtp_hdr_t is 12 bytes. --- src/switch_rtp.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 12436e4211..34567e4620 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -46,7 +46,6 @@ #undef PACKAGE #undef inline #include -#include #include #include @@ -94,7 +93,7 @@ static switch_port_t END_PORT = RTP_END_PORT; static switch_mutex_t *port_lock = NULL; static switch_size_t do_flush(switch_rtp_t *rtp_session, int force, switch_size_t bytes_in); -typedef srtp_hdr_t rtp_hdr_t; +typedef char switch_rtp_hdr_size_check_t[sizeof(switch_rtp_hdr_t) == 12 ? 1 : -1]; #ifdef _MSC_VER @@ -109,7 +108,7 @@ typedef srtp_hdr_t rtp_hdr_t; static switch_hash_t *alloc_hash = NULL; typedef struct { - srtp_hdr_t header; + switch_rtp_hdr_t header; char body[SWITCH_RTP_MAX_BUF_LEN+4+sizeof(char *)]; switch_rtp_hdr_ext_t *ext; char *ebody; @@ -419,7 +418,7 @@ struct switch_rtp { switch_dtls_t *dtls; switch_dtls_t *rtcp_dtls; - rtp_hdr_t last_rtp_hdr; + switch_rtp_hdr_t last_rtp_hdr; uint16_t seq; uint32_t ssrc; @@ -1886,7 +1885,7 @@ static void rtcp_generate_sender_info(switch_rtp_t *rtp_session, struct switch_r sr->ts = htonl(rtp_session->last_write_ts); sr->pc = htonl(rtp_session->stats.outbound.packet_count); - sr->oc = htonl(rtp_session->stats.outbound.raw_bytes - rtp_session->stats.outbound.packet_count * sizeof(srtp_hdr_t)); + sr->oc = htonl(rtp_session->stats.outbound.raw_bytes - rtp_session->stats.outbound.packet_count * sizeof(switch_rtp_hdr_t)); switch_time_exp_gmt(&now_hr,now); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG10,"Sending an RTCP packet[%04d-%02d-%02d %02d:%02d:%02d.%d] lsr[%u] msw[%u] lsw[%u] stats_ssrc[%u] packet_count[%u] OC[%u]\n", @@ -1981,7 +1980,7 @@ static void rtcp_generate_report_block(switch_rtp_t *rtp_session, struct switch_ static void rtcp_stats_init(switch_rtp_t *rtp_session) { switch_rtcp_numbers_t * stats = &rtp_session->stats.rtcp; - srtp_hdr_t * hdr = &rtp_session->last_rtp_hdr; + switch_rtp_hdr_t * hdr = &rtp_session->last_rtp_hdr; switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session"); stats->ssrc = ntohl(hdr->ssrc); stats->last_rpt_ts = rtp_session->write_timer.samplecount; @@ -2032,7 +2031,7 @@ static void rtcp_stats_init(switch_rtp_t *rtp_session) static int rtcp_stats(switch_rtp_t *rtp_session) { switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session"); - srtp_hdr_t * hdr = &rtp_session->last_rtp_hdr; + switch_rtp_hdr_t * hdr = &rtp_session->last_rtp_hdr; switch_rtcp_numbers_t * stats = &rtp_session->stats.rtcp; uint32_t packet_spacing_diff = 0, pkt_tsdiff, pkt_extended_seq; uint16_t pkt_seq, seq_diff, max_seq; @@ -2653,7 +2652,7 @@ SWITCH_DECLARE(void) switch_rtp_shutdown(void) switch_mutex_unlock(port_lock); #ifdef ENABLE_SRTP - srtp_crypto_kernel_shutdown(); + srtp_shutdown(); #endif switch_rtp_dtls_destroy(); } @@ -9345,7 +9344,7 @@ SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_fra uint32_t len, ts = 0; switch_payload_t payload = 0; rtp_msg_t *send_msg = NULL; - srtp_hdr_t local_header; + switch_rtp_hdr_t local_header; int r = 0; switch_status_t status; From fd911220bedb73d5351d60c1af7fc75d2f85a165 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 22:18:00 +0500 Subject: [PATCH 63/88] Merge commit from fork On a profile with `extended-info-parsing` set, an inbound SIP INFO whose content type is `freeswitch/api-request` puts an FSAPI command in the request body and gets its output back in the 200 OK. The branch needs no dialog, and no `mod_sofia` authentication or ACL setting covers an out-of-dialog INFO. That same param also enables the in-dialog `session-event` half, so there is no way to keep one and not the other. The new per-profile `enable-info-api-request` param gates the api-request branch alone and is off unless set, leaving `session-event` reachable under `extended-info-parsing` as before. An INFO selecting the branch on a profile without the new param is answered 403 and logged with the source and the requested command; a permitted one is logged too, since the source address appears in no event the API path fires. Both lines print the body's first line, capped, rather than the whole body. --- conf/testing/sip_profiles/internal.xml | 4 ++ conf/vanilla/sip_profiles/internal.xml | 4 ++ .../endpoints/mod_sofia/conf/sofia.conf.xml | 5 +++ src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 40 ++++++++++++++++++- 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/conf/testing/sip_profiles/internal.xml b/conf/testing/sip_profiles/internal.xml index 62f52af63f..c4efa30876 100644 --- a/conf/testing/sip_profiles/internal.xml +++ b/conf/testing/sip_profiles/internal.xml @@ -107,6 +107,10 @@ + + + + + + diff --git a/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml b/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml index 4732ae6fbf..c3253ed0b8 100644 --- a/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml +++ b/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml @@ -148,6 +148,11 @@ + + + diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 81d0517d78..433fff5c9b 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -312,6 +312,7 @@ typedef enum { PFLAG_AUTH_CALLS_ACL_ONLY, PFLAG_USE_PORT_FOR_ACL_CHECK, PFLAG_ENABLE_CHAT_API_PROTO, + PFLAG_ENABLE_INFO_API_REQUEST, /* No new flags below this line */ PFLAG_MAX diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 93583895c7..1a142761d9 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -5612,6 +5612,12 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) } else { sofia_clear_pflag(profile, PFLAG_EXTENDED_INFO_PARSING); } + } else if (!strcasecmp(var, "enable-info-api-request")) { + if (switch_true(val)) { + sofia_set_pflag(profile, PFLAG_ENABLE_INFO_API_REQUEST); + } else { + sofia_clear_pflag(profile, PFLAG_ENABLE_INFO_API_REQUEST); + } } else if (!strcasecmp(var, "nonce-ttl") && !zstr(val)) { profile->nonce_ttl = atoi(val); } else if (!strcasecmp(var, "max-auth-validity") && !zstr(val)) { @@ -9952,10 +9958,42 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t return; } else if (!strcasecmp(sip->sip_content_type->c_subtype, "api-request")) { - char *cmd = strdup(sip->sip_payload->pl_data); + char *cmd; char *arg; + char network_ip[80] = ""; + int network_port = 0; + size_t log_len; switch_stream_handle_t stream = { 0 }; + /* leaves the buffer empty when the message carries no address info */ + sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), &network_port); + + /* Both log lines below print the body's first line only, capped: the body comes + from the request, has no length bound, and may hold line breaks. */ + log_len = strcspn(sip->sip_payload->pl_data, "\r\n"); + if (log_len > 256) { + log_len = 256; + } + + if (!sofia_test_pflag(profile, PFLAG_ENABLE_INFO_API_REQUEST)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "Profile [%s] rejected an INFO from %s:%d requesting a FreeSWITCH API command [%.*s]. " + "Set enable-info-api-request=true on the profile to permit it.\n", + profile->name, network_ip, network_port, (int) log_len, sip->sip_payload->pl_data); + + nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS_MSG(de->data->e_msg), + TAG_IF(!zstr(session_id_header), SIPTAG_HEADER_STR(session_id_header)), + TAG_END()); + + return; + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, + "Profile [%s] running a FreeSWITCH API command requested by an INFO from %s:%d [%.*s]\n", + profile->name, network_ip, network_port, (int) log_len, sip->sip_payload->pl_data); + + cmd = strdup(sip->sip_payload->pl_data); + switch_assert(cmd); SWITCH_STANDARD_STREAM(stream); switch_assert(stream.data); From 0dcf2d75726415b5e46b49263c4a1c3b35f8b927 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 22:19:42 +0500 Subject: [PATCH 64/88] Merge commit from fork `skinny_read_packet()` checked the declared length as `length + 8 > 2048` on a `uint32_t`, which wraps for lengths of `0xFFFFFFF8` and above, and `skinny_check_data_length()` in the handlers only enforces a minimum. Compare the length against the constant side instead, and advance `ptr` on every read so a length field that arrives in pieces is stored contiguously instead of being overwritten by later bytes. - The message buffer gets one spare zero byte, so fixed-width string fields of a full-size message terminate inside the allocation. - The data and extended data handlers check `data_length` against the bytes left after their header, with no addition on the wire value. - Those two handlers and `skinny_handle_xml_alarm()` build the event body with `%.*s` instead of an unchecked `malloc` copy. - `skinny_handle_extended_data_message()` takes the body from the `extended_data` member instead of `data`, so the event body no longer starts with 20 bytes of header fields. - `skinny_handle_updatecapabilities()` rejects an empty audio capability list, as `skinny_handle_capabilities_response()` already does. --- .../endpoints/mod_skinny/skinny_protocol.c | 9 +-- src/mod/endpoints/mod_skinny/skinny_server.c | 56 +++++++++---------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/mod/endpoints/mod_skinny/skinny_protocol.c b/src/mod/endpoints/mod_skinny/skinny_protocol.c index e345f00930..d25d1dc629 100644 --- a/src/mod/endpoints/mod_skinny/skinny_protocol.c +++ b/src/mod/endpoints/mod_skinny/skinny_protocol.c @@ -110,7 +110,8 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) char *ptr; switch_status_t status = SWITCH_STATUS_SUCCESS; - request = calloc(1,SKINNY_MESSAGE_MAXSIZE); + /* One zero byte past the largest message, so fixed-width string fields always terminate inside the allocation */ + request = calloc(1, SKINNY_MESSAGE_MAXSIZE + 1); if (!request) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to allocate memory.\n"); @@ -152,10 +153,10 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) if(mlen) { bytes += mlen; + ptr += mlen; if(bytes >= SKINNY_MESSAGE_FIELD_SIZE) { do_sleep = 0; - ptr += mlen; memcpy(request, mbuf, bytes); #ifdef SKINNY_MEGA_DEBUG switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, @@ -169,9 +170,9 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) switch_safe_free(request); return SWITCH_STATUS_FALSE; } - if(request->length + 2*SKINNY_MESSAGE_FIELD_SIZE > SKINNY_MESSAGE_MAXSIZE) { + if(request->length > SKINNY_MESSAGE_MAXSIZE - 2*SKINNY_MESSAGE_FIELD_SIZE) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, - "Skinny client sent too huge data. Got %d which is above threshold %d.\n", + "Skinny client sent too huge data. Got %u which is above threshold %d.\n", request->length, SKINNY_MESSAGE_MAXSIZE - 2*SKINNY_MESSAGE_FIELD_SIZE); switch_safe_free(request); return SWITCH_STATUS_FALSE; diff --git a/src/mod/endpoints/mod_skinny/skinny_server.c b/src/mod/endpoints/mod_skinny/skinny_server.c index af7702a363..87633b7616 100644 --- a/src/mod/endpoints/mod_skinny/skinny_server.c +++ b/src/mod/endpoints/mod_skinny/skinny_server.c @@ -2375,9 +2375,16 @@ switch_status_t skinny_handle_register_available_lines_message(listener_t *liste switch_status_t skinny_handle_data_message(listener_t *listener, skinny_message_t *request) { switch_event_t *event = NULL; - char *tmp = NULL; + skinny_check_data_length(request, sizeof(request->data.data)); - skinny_check_data_length(request, sizeof(request->data.data) + request->data.data.data_length - 1); + + if (request->data.data.data_length > request->length - 4 - offsetof(struct data_message, data)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + "Received Skinny Message %s (type=%x,length=%u) with data length %u past its end.\n", + skinny_message_type2str(request->type), request->type, request->length, request->data.data.data_length); + + return SWITCH_STATUS_FALSE; + } /* skinny::device_to_user event */ skinny_device_event(listener, &event, SWITCH_EVENT_CUSTOM, SKINNY_EVENT_DEVICE_TO_USER); @@ -2388,15 +2395,7 @@ switch_status_t skinny_handle_data_message(listener_t *listener, skinny_message_ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-DeviceToUser-Call-Id", "%d", request->data.data.call_id); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-DeviceToUser-Transaction-Id", "%d", request->data.data.transaction_id); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-DeviceToUser-Data-Length", "%d", request->data.data.data_length); - - tmp = malloc(request->data.data.data_length + 1); - memcpy(tmp, request->data.data.data, request->data.data.data_length); - - /* Ensure that the body is null-terminated */ - tmp[request->data.data.data_length] = '\0'; - switch_event_add_body(event, "%s", tmp); - - switch_safe_free(tmp); + switch_event_add_body(event, "%.*s", (int)request->data.data.data_length, request->data.data.data); switch_event_fire(&event); @@ -2446,9 +2445,16 @@ switch_status_t skinny_handle_feature_stat_request(listener_t *listener, skinny_ switch_status_t skinny_handle_extended_data_message(listener_t *listener, skinny_message_t *request) { switch_event_t *event = NULL; - char *tmp = NULL; + skinny_check_data_length(request, sizeof(request->data.extended_data)); - skinny_check_data_length(request, sizeof(request->data.extended_data)+request->data.extended_data.data_length-1); + + if (request->data.extended_data.data_length > request->length - 4 - offsetof(struct extended_data_message, data)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + "Received Skinny Message %s (type=%x,length=%u) with data length %u past its end.\n", + skinny_message_type2str(request->type), request->type, request->length, request->data.extended_data.data_length); + + return SWITCH_STATUS_FALSE; + } /* skinny::device_to_user event */ skinny_device_event(listener, &event, SWITCH_EVENT_CUSTOM, SKINNY_EVENT_DEVICE_TO_USER); @@ -2464,15 +2470,8 @@ switch_status_t skinny_handle_extended_data_message(listener_t *listener, skinny switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-DeviceToUser-Conference-Id", "%d", request->data.extended_data.conference_id); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-DeviceToUser-App-Instance-Id", "%d", request->data.extended_data.app_instance_id); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-DeviceToUser-Routing-Id", "%d", request->data.extended_data.routing_id); + switch_event_add_body(event, "%.*s", (int)request->data.extended_data.data_length, request->data.extended_data.data); - tmp = malloc(request->data.data.data_length + 1); - memcpy(tmp, request->data.data.data, request->data.data.data_length); - - /* Ensure that the body is null-terminated */ - tmp[request->data.data.data_length] = '\0'; - switch_event_add_body(event, "%s", tmp); - - switch_safe_free(tmp); switch_event_fire(&event); return SWITCH_STATUS_SUCCESS; @@ -2569,6 +2568,11 @@ switch_status_t skinny_handle_updatecapabilities(listener_t *listener, skinny_me skinny_check_data_length(request, sizeof(request->data.upd_cap.audio_cap_count)); n = request->data.upd_cap.audio_cap_count; + if (n == 0) { + skinny_log_l_msg(listener, SWITCH_LOG_ERROR, "Device sent no audio capabilities.\n"); + + return SWITCH_STATUS_FALSE; + } if (n > SKINNY_MAX_CAPABILITIES) { n = SKINNY_MAX_CAPABILITIES; } @@ -2626,17 +2630,11 @@ switch_status_t skinny_handle_server_req_message(listener_t *listener, skinny_me switch_status_t skinny_handle_xml_alarm(listener_t *listener, skinny_message_t *request) { switch_event_t *event = NULL; - char *tmp = NULL; - skinny_log_l(listener, SWITCH_LOG_DEBUG, "Received XML alarm (length=%d).\n", request->length); + skinny_log_l(listener, SWITCH_LOG_DEBUG, "Received XML alarm (length=%u).\n", request->length); /* skinny::xml_alarm event */ skinny_device_event(listener, &event, SWITCH_EVENT_CUSTOM, SKINNY_EVENT_XML_ALARM); - /* Ensure that the body is null-terminated */ - tmp = malloc(request->length - 4 + 1); - memcpy(tmp, request->data.as_char, request->length - 4); - tmp[request->length - 4] = '\0'; - switch_event_add_body(event, "%s", tmp); - switch_safe_free(tmp); + switch_event_add_body(event, "%.*s", (int)(request->length - 4), request->data.as_char); switch_event_fire(&event); return SWITCH_STATUS_SUCCESS; From 82adc771cbff8cfb1cc663f292f357386f3ea32b Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 22:20:32 +0500 Subject: [PATCH 65/88] Merge commit from fork `enum_app_function()` and `enum_api()` advanced their write cursor and decremented the remaining space by `strlen(rp->route) + 1` rather than by the bytes `switch_snprintf()` reported writing, so once a route no longer fit the unsigned counter wrapped and the next iteration wrote past the end of `rbuf` with no effective bound. Both loops now share a `pack_routes()` helper that writes each route's separator in front of it. Nothing points back into the buffer, so the trailing-separator strip and its `rbuf[-1]` write are gone, along with the write through a `char *` aimed at a string literal. A route that does not fit whole, or that is empty, is skipped rather than clipped or ending the loop. `enum_app_function()` applies the same test when exporting `enum_route_N`, so `enum_route_count` and the packed count describe the same routes: an empty value would delete the variable rather than set it, leaving a gap in the numbering. It also warns when the dial string ends up holding fewer routes than were resolved, and `cnt`'s conversions are `%u` to match its type. --- src/mod/applications/mod_enum/mod_enum.c | 112 +++++++++++++++-------- 1 file changed, 72 insertions(+), 40 deletions(-) diff --git a/src/mod/applications/mod_enum/mod_enum.c b/src/mod/applications/mod_enum/mod_enum.c index 08c0d709f7..e7fbfe236e 100644 --- a/src/mod/applications/mod_enum/mod_enum.c +++ b/src/mod/applications/mod_enum/mod_enum.c @@ -674,6 +674,57 @@ SWITCH_STANDARD_DIALPLAN(enum_dialplan_hunt) return extension; } +/* Pack the supported routes into buf as a dial string, NUL-terminated. Routes of equal + NAPTR order and preference are joined with ',', the rest with '|'. Every element of + that string is dialed as a peer, so routes go in whole; one that does not fit is + skipped and the others are packed. Returns how many were packed. */ +static switch_size_t pack_routes(char *buf, switch_size_t buflen, enum_record_t *results) +{ + enum_record_t *rp; + char *bp = buf; + switch_size_t bl = buflen; + switch_size_t packed = 0; + int last_order = 0, last_pref = 0; + + if (!buflen) { + return 0; + } + + *buf = '\0'; + + for (rp = results; rp; rp = rp->next) { + const char *sep = ""; + int written; + + /* An empty route would contribute a separator and no peer. */ + if (!rp->supported || zstr(rp->route)) { + continue; + } + + /* Compared with the last route packed rather than the previous list entry, + so one left out for space does not split two alternatives. */ + if (packed) { + sep = (rp->order == last_order && rp->preference == last_pref) ? "," : "|"; + } + + if (strlen(rp->route) + strlen(sep) + 1 > bl) { + continue; + } + + /* switch_snprintf() returns the bytes it wrote, clamped to bl - 1, where + C99 snprintf would return the untruncated length. The check above leaves + room for both parts and the terminator, so nothing is clipped. */ + written = switch_snprintf(bp, bl, "%s%s", sep, rp->route); + bp += written; + bl -= written; + last_order = rp->order; + last_pref = rp->preference; + packed++; + } + + return packed; +} + SWITCH_STANDARD_APP(enum_app_function) { char *argv[4] = { 0 }; @@ -682,12 +733,8 @@ SWITCH_STANDARD_APP(enum_app_function) enum_record_t *results, *rp; char rbuf[1024] = ""; char vbuf[1024] = ""; - char *rbp = rbuf; - switch_size_t l = 0, rbl = sizeof(rbuf); uint32_t cnt = 1; switch_channel_t *channel = switch_core_session_get_channel(session); - int last_order = -1, last_pref = -2; - char *last_delim = "|"; if (!(mydata = switch_core_session_strdup(session, data))) { return; @@ -698,6 +745,7 @@ SWITCH_STANDARD_APP(enum_app_function) root = argv[1]; if (enum_lookup(root, dest, &results, channel, session) == SWITCH_STATUS_SUCCESS) { switch_event_t *vars; + switch_size_t packed; if (switch_channel_get_variables(channel, &vars) == SWITCH_STATUS_SUCCESS) { switch_event_header_t *hi; @@ -710,28 +758,32 @@ SWITCH_STANDARD_APP(enum_app_function) switch_event_destroy(&vars); } + /* Same test as pack_routes() applies, so enum_route_count and the packed + count describe the same set of routes. An empty value would delete the + variable rather than set it, leaving a gap in the numbering. */ for (rp = results; rp; rp = rp->next) { - if (!rp->supported) { + if (!rp->supported || zstr(rp->route)) { continue; } - switch_snprintf(vbuf, sizeof(vbuf), "enum_route_%d", cnt++); + switch_snprintf(vbuf, sizeof(vbuf), "enum_route_%u", cnt++); switch_channel_set_variable_var_check(channel, vbuf, rp->route, SWITCH_FALSE); - if (rp->preference == last_pref && rp->order == last_order) { - *last_delim = ','; - } - switch_snprintf(rbp, rbl, "%s|", rp->route); - last_delim = end_of_p(rbp); - last_order = rp->order; - last_pref = rp->preference; - l = strlen(rp->route) + 1; - rbp += l; - rbl -= l; } - switch_snprintf(vbuf, sizeof(vbuf), "%d", cnt - 1); + packed = pack_routes(rbuf, sizeof(rbuf), results); + + switch_snprintf(vbuf, sizeof(vbuf), "%u", cnt - 1); switch_channel_set_variable_var_check(channel, "enum_route_count", vbuf, SWITCH_FALSE); - *(rbuf + strlen(rbuf) - 1) = '\0'; switch_channel_set_variable_var_check(channel, "enum_auto_route", rbuf, SWITCH_FALSE); + + if (!packed && cnt > 1) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, + "No ENUM route fits the dial string, so enum_auto_route is unset; all %u are in enum_route_N\n", + cnt - 1); + } else if (packed < cnt - 1) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, + "ENUM dial string holds %u of %u routes; the rest are in enum_route_N\n", + (unsigned) packed, cnt - 1); + } free_results(&results); } } @@ -742,12 +794,8 @@ SWITCH_STANDARD_API(enum_api) char *argv[4] = { 0 }; char *mydata = NULL; char *dest = NULL, *root = NULL; - enum_record_t *results, *rp; + enum_record_t *results; char rbuf[1024] = ""; - char *rbp = rbuf; - switch_size_t l = 0, rbl = sizeof(rbuf); - int last_order = -1, last_pref = -2; - char *last_delim = "|"; int ok = 0; if (zstr(cmd)) { @@ -764,23 +812,7 @@ SWITCH_STANDARD_API(enum_api) root = argv[1]; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Looking up %s@%s\n", dest, root); if (enum_lookup(root, dest, &results, NULL, session) == SWITCH_STATUS_SUCCESS) { - for (rp = results; rp; rp = rp->next) { - if (!rp->supported) { - continue; - } - if (rp->preference == last_pref && rp->order == last_order) { - *last_delim = ','; - } - switch_snprintf(rbp, rbl, "%s|", rp->route); - last_delim = end_of_p(rbp); - last_order = rp->order; - last_pref = rp->preference; - l = strlen(rp->route) + 1; - rbp += l; - rbl -= l; - - } - *(rbuf + strlen(rbuf) - 1) = '\0'; + pack_routes(rbuf, sizeof(rbuf), results); stream->write_function(stream, "%s", rbuf); free_results(&results); ok++; From dec8abf635a07999188447a58950db7f00528e3d Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 22:22:48 +0500 Subject: [PATCH 66/88] Merge commit from fork `get_rtt_red_seq()` stored one entry per RFC 2198 redundancy header in the fixed `pt[]` and `len[]` arrays without checking the count against `MAX_RED_FRAMES`, so a packet with more headers wrote past them. Reject the packet once the count reaches `MAX_RED_FRAMES`, and reject a frame index at or above it, which a sequence number wrap can produce. --- src/switch_core_media.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 6a8e06342c..f8825aab74 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -2651,7 +2651,7 @@ static int get_rtt_red_seq(int want_seq, void *data, switch_size_t datalen, int *(buf + datalen) = '\0'; while (*buf & 0x80) { - if (buf + 3 > e) { + if (buf + 3 > e || count >= MAX_RED_FRAMES) { *new_datalen = 0; return 0; } @@ -2666,7 +2666,7 @@ static int get_rtt_red_seq(int want_seq, void *data, switch_size_t datalen, int idx = count - (seq - want_seq); - if (idx < 0) { + if (idx < 0 || idx >= MAX_RED_FRAMES) { *new_datalen = 0; return 0; } From 512443322af0405e41bd9e2aa9df27855aca3995 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 22:23:56 +0500 Subject: [PATCH 67/88] Merge commit from fork `switch_rtp_add_crypto_key()` allocated each MKI id buffer with `sizeof(key_material->mki_size)`, a constant 4 bytes, then copied `mki_size` bytes into it. That length comes from the remote `a=crypto` attribute and was only checked against a lower bound. The same copy read `mki_size` bytes starting at the 4-byte `mki_id` field. Reject an MKI length outside 1..`SRTP_MAX_MKI_LEN`, allocate the id buffer at that length, and copy no more than the width of `mki_id`, leaving the remaining bytes zero. MKI lengths of 1 to 4 keep the bytes they carry today. --- src/switch_rtp.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 34567e4620..24fcc7db13 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -4398,8 +4398,10 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess while (key_material && (mki_idx < *key_material_n)) { - if (key_material->mki_size < 1) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "MKI bad key size at MKI %d\n", mki_idx); + if (key_material->mki_size < 1 || key_material->mki_size > SRTP_MAX_MKI_LEN) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "MKI bad key size %u at MKI %d (allowed 1..%d)\n", + key_material->mki_size, mki_idx, SRTP_MAX_MKI_LEN); + return SWITCH_STATUS_FALSE; } @@ -4409,7 +4411,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess } /* Setup MKI. */ - mki->mki_id = switch_core_alloc(rtp_session->pool, sizeof(key_material->mki_size)); + mki->mki_id = switch_core_alloc(rtp_session->pool, key_material->mki_size); if (!mki->mki_id) { return SWITCH_STATUS_FALSE; } @@ -4419,7 +4421,9 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess return SWITCH_STATUS_FALSE; } - memcpy(mki->mki_id, &key_material->mki_id, key_material->mki_size); + /* The id lives in an unsigned int: copy no more than its width, bytes past it stay zero. */ + memcpy(mki->mki_id, &key_material->mki_id, + key_material->mki_size < sizeof(key_material->mki_id) ? key_material->mki_size : sizeof(key_material->mki_id)); mki->mki_size = key_material->mki_size; memcpy(mki->key, key_material->raw_key, keysalt_len); From 9606e32c553fc637fdea53a4ba67f54a8f9711b7 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 22:25:41 +0500 Subject: [PATCH 68/88] Merge commit from fork Run the display name and number through the same `switch_clean_string()` and `switch_var_clean_string()` pass that `profile_dup_clean()` applies when the profile is built from the initial request, so a `${` in either is stored as `%{` whichever message carried it. --- src/mod/endpoints/mod_sofia/sofia.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 1a142761d9..877d574d28 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1332,8 +1332,8 @@ void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *pro name_dup = strdup(name); number_dup = strdup(number); switch_assert(name_dup && number_dup); - name = switch_sanitize_number(name_dup); - number = switch_sanitize_number(number_dup); + name = switch_var_clean_string(switch_clean_string(switch_sanitize_number(name_dup))); + number = switch_var_clean_string(switch_clean_string(switch_sanitize_number(number_dup))); if (switch_channel_inbound_display(channel)) { From 382c669c935279ae776feccbd21752558b769cbf Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 22:30:30 +0500 Subject: [PATCH 69/88] Merge commit from fork `conference_event_adv_la()` gave every live array member's `event_channel_cookie` permission on the conference moderator channel, the same as the live array, chat and info channels. On mod_verto that permission is what lets a client broadcast to `conference-mod.*` and run conference commands through `conference_event_mod_channel_handler()`. Grant and revoke it only for members with `MFLAG_MOD`, which does not change during membership, so a participant call leaving does not strip it from a moderator call on the same WebSocket. Adds three `test_member` cases covering the participant, moderator and shared-cookie grants on a new `livearray` test profile. --- .../mod_conference/conference_event.c | 7 +- .../mod_conference/test/conf/freeswitch.xml | 4 + .../mod_conference/test/test_member.c | 191 ++++++++++++++++++ 3 files changed, 201 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_conference/conference_event.c b/src/mod/applications/mod_conference/conference_event.c index ec3c9b4799..bd3757758a 100644 --- a/src/mod/applications/mod_conference/conference_event.c +++ b/src/mod/applications/mod_conference/conference_event.c @@ -684,7 +684,12 @@ void conference_event_adv_la(conference_obj_t *conference, conference_member_t * if (cookie) { switch_event_channel_permission_modify(cookie, conference->la_event_channel, join); - switch_event_channel_permission_modify(cookie, conference->mod_event_channel, join); + + /* Grant on join and revoke on part for moderators only; MFLAG_MOD is fixed for the whole membership. */ + if (conference_utils_member_test_flag(member, MFLAG_MOD)) { + switch_event_channel_permission_modify(cookie, conference->mod_event_channel, join); + } + switch_event_channel_permission_modify(cookie, conference->chat_event_channel, join); switch_event_channel_permission_modify(cookie, conference->info_event_channel, join); } diff --git a/src/mod/applications/mod_conference/test/conf/freeswitch.xml b/src/mod/applications/mod_conference/test/conf/freeswitch.xml index 8fd583d4e6..a541d72c63 100644 --- a/src/mod/applications/mod_conference/test/conf/freeswitch.xml +++ b/src/mod/applications/mod_conference/test/conf/freeswitch.xml @@ -28,6 +28,10 @@ + + + + diff --git a/src/mod/applications/mod_conference/test/test_member.c b/src/mod/applications/mod_conference/test/test_member.c index 1df2b850a0..08dfeac439 100644 --- a/src/mod/applications/mod_conference/test/test_member.c +++ b/src/mod/applications/mod_conference/test/test_member.c @@ -36,6 +36,71 @@ #include +/* Check whether the conference API lists the member with this uuid. */ +static switch_bool_t conference_lists_member(const char *conference_name, const char *member_uuid) +{ + switch_stream_handle_t stream = { 0 }; + char *args = switch_mprintf("%s json_list", conference_name); + cJSON *conferences = NULL, *members = NULL, *member = NULL; + switch_bool_t found = SWITCH_FALSE; + + SWITCH_STANDARD_STREAM(stream); + switch_api_execute("conference", args, NULL, &stream); + + if (stream.data && strncmp((char *)stream.data, "-ERR", 4) && (conferences = cJSON_Parse((char *)stream.data))) { + if ((members = cJSON_GetObjectItem(cJSON_GetArrayItem(conferences, 0), "members"))) { + for (member = members->child; member; member = member->next) { + if (!strcmp(switch_str_nil(cJSON_GetObjectCstr(member, "uuid")), member_uuid)) { + found = SWITCH_TRUE; + break; + } + } + } + + cJSON_Delete(conferences); + } + + switch_safe_free(stream.data); + switch_safe_free(args); + + return found; +} + +/* Wait until the conference lists the member. A member is listed only after its event channel + permissions are set, so a listed member has its final permissions. */ +static switch_bool_t wait_for_conference_member(const char *conference_name, const char *member_uuid, int timeout_ms) +{ + int waited_ms = 0; + + while (!conference_lists_member(conference_name, member_uuid)) { + if (waited_ms >= timeout_ms) { + return SWITCH_FALSE; + } + + switch_yield(10000); + waited_ms += 10; + } + + return SWITCH_TRUE; +} + +/* Wait until the cookie's permission on the event channel matches the expected value. */ +static switch_bool_t wait_for_event_channel_permission(const char *cookie, const char *event_channel, switch_bool_t expected, int timeout_ms) +{ + int waited_ms = 0; + + while (switch_event_channel_permission_verify(cookie, event_channel) != expected) { + if (waited_ms >= timeout_ms) { + return SWITCH_FALSE; + } + + switch_yield(10000); + waited_ms += 10; + } + + return SWITCH_TRUE; +} + FST_CORE_BEGIN("./conf") { FST_SUITE_BEGIN(switch_ivr_originate) @@ -92,6 +157,132 @@ FST_CORE_BEGIN("./conf") } FST_TEST_END() + /* A live array member's event channel cookie gets the live array channel, but not the moderator channel. */ + FST_SESSION_BEGIN(livearray_participant_no_mod_channel) + { + switch_channel_t *channel = switch_core_session_get_channel(fst_session); + const char *conference_name = switch_core_session_get_uuid(fst_session); + const char *cookie = "livearray-participant-cookie"; + /* the "livearray" test profile sets livearray-sync and the domain the channel names end with */ + const char *la_channel = switch_core_sprintf(fst_pool, "conference-liveArray.%s@livearray.test", conference_name); + const char *mod_channel = switch_core_sprintf(fst_pool, "conference-mod.%s@livearray.test", conference_name); + + switch_channel_set_variable(channel, "event_channel_cookie", cookie); + fst_session_park(fst_session); + + switch_core_session_execute_application_async(fst_session, "conference", switch_core_sprintf(fst_pool, "%s@livearray", conference_name)); + + if (!wait_for_conference_member(conference_name, switch_core_session_get_uuid(fst_session), 3000)) { + fst_fail("Expect the participant to join the conference"); + goto livearray_participant_end; + } + + fst_xcheck(switch_event_channel_permission_verify(cookie, la_channel), "Expect a participant to be granted the live array channel"); + fst_xcheck(!switch_event_channel_permission_verify(cookie, mod_channel), "Expect a participant not to be granted the moderator channel"); + + livearray_participant_end: + switch_event_channel_permission_clear(cookie); + } + FST_SESSION_END() + + /* A live array moderator's event channel cookie gets the moderator channel, and loses it on leaving. */ + FST_SESSION_BEGIN(livearray_moderator_mod_channel) + { + switch_channel_t *channel = switch_core_session_get_channel(fst_session); + const char *conference_name = switch_core_session_get_uuid(fst_session); + const char *cookie = "livearray-moderator-cookie"; + /* the "livearray" test profile sets livearray-sync and the domain the channel name ends with */ + const char *mod_channel = switch_core_sprintf(fst_pool, "conference-mod.%s@livearray.test", conference_name); + + switch_channel_set_variable(channel, "event_channel_cookie", cookie); + switch_channel_set_variable(channel, "conference_member_flags", "moderator"); + fst_session_park(fst_session); + + switch_core_session_execute_application_async(fst_session, "conference", switch_core_sprintf(fst_pool, "%s@livearray", conference_name)); + + if (!wait_for_conference_member(conference_name, switch_core_session_get_uuid(fst_session), 3000)) { + fst_fail("Expect the moderator to join the conference"); + goto livearray_moderator_end; + } + + fst_xcheck(switch_event_channel_permission_verify(cookie, mod_channel), "Expect a moderator to be granted the moderator channel"); + + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + + fst_xcheck(wait_for_event_channel_permission(cookie, mod_channel, SWITCH_FALSE, 3000), + "Expect the moderator channel to be revoked when the member leaves"); + + livearray_moderator_end: + switch_event_channel_permission_clear(cookie); + } + FST_SESSION_END() + + /* Calls sharing an event channel cookie: a participant call leaving keeps the moderator channel granted to the moderator call. */ + FST_SESSION_BEGIN(livearray_participant_part_keeps_mod_channel) + { + switch_channel_t *channel = switch_core_session_get_channel(fst_session); + const char *conference_name = switch_core_session_get_uuid(fst_session); + const char *conference_args = switch_core_sprintf(fst_pool, "%s@livearray", conference_name); + const char *cookie = "livearray-shared-cookie"; + const char *mod_channel = switch_core_sprintf(fst_pool, "conference-mod.%s@livearray.test", conference_name); + /* part revokes the info channel last, after deciding on the moderator channel */ + const char *info_channel = switch_core_sprintf(fst_pool, "conference-info.%s@livearray.test", conference_name); + switch_core_session_t *participant_session = NULL; + switch_channel_t *participant_channel = NULL; + switch_call_cause_t cause = SWITCH_CAUSE_NONE; + + switch_channel_set_variable(channel, "event_channel_cookie", cookie); + switch_channel_set_variable(channel, "conference_member_flags", "moderator"); + fst_session_park(fst_session); + + switch_core_session_execute_application_async(fst_session, "conference", conference_args); + + if (!wait_for_conference_member(conference_name, switch_core_session_get_uuid(fst_session), 3000)) { + fst_fail("Expect the moderator to join the conference"); + goto livearray_shared_cookie_end; + } + + if (switch_ivr_originate(NULL, &participant_session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL) != SWITCH_STATUS_SUCCESS || !participant_session) { + fst_fail("Expect the participant session to be created"); + goto livearray_shared_cookie_end; + } + + participant_channel = switch_core_session_get_channel(participant_session); + switch_channel_set_state(participant_channel, CS_SOFT_EXECUTE); + switch_channel_wait_for_state(participant_channel, NULL, CS_SOFT_EXECUTE); + switch_channel_set_variable(participant_channel, "send_silence_when_idle", "-1"); + switch_channel_set_variable(participant_channel, "event_channel_cookie", cookie); + fst_session_park(participant_session); + + switch_core_session_execute_application_async(participant_session, "conference", conference_args); + + if (!wait_for_conference_member(conference_name, switch_core_session_get_uuid(participant_session), 3000)) { + fst_fail("Expect the participant to join the conference"); + goto livearray_shared_cookie_end; + } + + fst_xcheck(switch_event_channel_permission_verify(cookie, mod_channel), "Expect the moderator call to hold the moderator channel"); + + switch_channel_hangup(participant_channel, SWITCH_CAUSE_NORMAL_CLEARING); + + if (!wait_for_event_channel_permission(cookie, info_channel, SWITCH_FALSE, 3000)) { + fst_fail("Expect the participant leaving to revoke the info channel"); + goto livearray_shared_cookie_end; + } + + fst_xcheck(switch_event_channel_permission_verify(cookie, mod_channel), + "Expect the moderator channel to stay granted when a participant on the same cookie leaves"); + + livearray_shared_cookie_end: + if (participant_session) { + switch_channel_hangup(participant_channel, SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(participant_session); + } + + switch_event_channel_permission_clear(cookie); + } + FST_SESSION_END() + } FST_SUITE_END() } From 2582f5cebda2d908f5fb45dfd388dd0c10e4c626 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 22:31:50 +0500 Subject: [PATCH 70/88] Merge commit from fork A REFER with no call behind it is published as a `CALL_SETUP_REQ` event whose `Request-Target` is `sofia//`, and `mod_conference` hands that string to `switch_ivr_originate()` for `rfc-4579` conferences. The URI was copied in unchanged, so a `,`, `|` or `:_:` in it split the dial string into extra peers or legs, each of which can start with its own `[...]` channel variables. Answer such a REFER with `400 Bad Refer-To` before anything is published. Both the serialized Refer-To and its user part are checked; the user part is published separately as `Request-Target-Extension`, which an `outcall-templ` expands. A Refer-To without these characters is handled as before. Also frees the subscription contact string an accepted REFER of this kind allocated and never released. --- src/mod/endpoints/mod_sofia/sofia.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 877d574d28..a6757ce22c 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1469,7 +1469,12 @@ static void sofia_handle_sip_r_refer(nua_t *nua, sofia_profile_t *profile, nua_h } } - +/* Whether s holds anything switch_ivr_originate() splits a dial string on: ',' between peers, + '|' between failover groups, ':_:' between enterprise legs. */ +static switch_bool_t sofia_has_dial_separator(const char *s) +{ + return !zstr(s) && (strpbrk(s, ",|") || strstr(s, SWITCH_ENT_ORIGINATE_DELIM)) ? SWITCH_TRUE : SWITCH_FALSE; +} //sofia_dispatch_event_t *de @@ -1922,6 +1927,16 @@ static void our_sofia_event_callback(nua_event_t event, } + /* The target and its user part are published below as a dial string and a part of one */ + if (sofia_has_dial_separator(refer_to) || sofia_has_dial_separator(ref_to_user)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "Profile [%s] rejected a REFER whose Refer-To [%s] holds a dial string separator\n", profile->name, switch_str_nil(refer_to)); + nua_respond(nh, 400, "Bad Refer-To", NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END()); + switch_safe_free(method); + switch_safe_free(full_url); + break; + } + if (!method) { method = strdup("INVITE"); switch_assert(method); @@ -2041,6 +2056,7 @@ static void our_sofia_event_callback(nua_event_t event, sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); + switch_safe_free(contact_str); sip_to_tag(nua_handle_get_home(nh), sip->sip_to, to_tag); } From e4325bc8c16545e28ba9658a5e0deb93d2555a70 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 22:33:41 +0500 Subject: [PATCH 71/88] Merge commit from fork `amf0_data_read()` dispatched on the type byte into `amf0_object_read()`, `amf0_associative_array_read()` and `amf0_array_read()`, each of which called back into it for every contained element with nothing tracking nesting depth. Chunk assembly admits up to `AMF_MAX_SIZE` bytes and a nested object costs three of them per level, so one message can recurse far deeper than `SWITCH_THREAD_STACKSIZE` holds. Thread the depth through the dispatcher every arm funnels back into, so one check covers any mix of them. A value past the cap is dropped, which an object or ECMA array takes as its end and a strict array, having declared an element count, takes as a failure. `amf0_data_read()` keeps its signature and becomes a wrapper starting at depth 0. A cap of 32 sits far above real traffic, where a `connect` command object nests two to four levels. --- src/mod/endpoints/mod_rtmp/libamf/src/amf0.c | 47 +++++++++++++++----- src/mod/endpoints/mod_rtmp/libamf/src/amf0.h | 8 ++++ 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/mod/endpoints/mod_rtmp/libamf/src/amf0.c b/src/mod/endpoints/mod_rtmp/libamf/src/amf0.c index 7e86847cb0..cd88c03aca 100644 --- a/src/mod/endpoints/mod_rtmp/libamf/src/amf0.c +++ b/src/mod/endpoints/mod_rtmp/libamf/src/amf0.c @@ -5,6 +5,13 @@ #include "io.h" #include "types.h" +/* + The container readers below are mutually recursive, and the trees they build + are also walked recursively to free, size, write and clone them, so bounding + depth at read time is what keeps all of those paths off an unbounded stack. +*/ +static amf0_data * amf0_data_read_depth(read_proc_t read_proc, void * user_data, unsigned int depth); + /* function common to all array types */ static void amf0_list_init(amf0_list * list) { if (list != NULL) { @@ -231,7 +238,7 @@ static amf0_data * amf0_string_read(read_proc_t read_proc, void * user_data) { } /* read an object */ -static amf0_data * amf0_object_read(read_proc_t read_proc, void * user_data) { +static amf0_data * amf0_object_read(read_proc_t read_proc, void * user_data, unsigned int depth) { amf0_data * data = amf0_object_new(); if (data != NULL) { amf0_data * name; @@ -239,7 +246,7 @@ static amf0_data * amf0_object_read(read_proc_t read_proc, void * user_data) { while (1) { name = amf0_string_read(read_proc, user_data); if (name != NULL) { - element = amf0_data_read(read_proc, user_data); + element = amf0_data_read_depth(read_proc, user_data, depth + 1); if (element != NULL) { if (amf0_object_add(data, (char *)amf0_string_get_uint8_ts(name), element) == NULL) { amf0_data_free(name); @@ -266,7 +273,7 @@ static amf0_data * amf0_object_read(read_proc_t read_proc, void * user_data) { } /* read an associative array */ -static amf0_data * amf0_associative_array_read(read_proc_t read_proc, void * user_data) { +static amf0_data * amf0_associative_array_read(read_proc_t read_proc, void * user_data, unsigned int depth) { amf0_data * data = amf0_associative_array_new(); if (data != NULL) { amf0_data * name; @@ -277,7 +284,7 @@ static amf0_data * amf0_associative_array_read(read_proc_t read_proc, void * use while(1) { name = amf0_string_read(read_proc, user_data); if (name != NULL) { - element = amf0_data_read(read_proc, user_data); + element = amf0_data_read_depth(read_proc, user_data, depth + 1); if (element != NULL) { if (amf0_associative_array_add(data, (char *)amf0_string_get_uint8_ts(name), element) == NULL) { amf0_data_free(name); @@ -309,7 +316,7 @@ static amf0_data * amf0_associative_array_read(read_proc_t read_proc, void * use } /* read an array */ -static amf0_data * amf0_array_read(read_proc_t read_proc, void * user_data) { +static amf0_data * amf0_array_read(read_proc_t read_proc, void * user_data, unsigned int depth) { size_t i; amf0_data * element; amf0_data * data = amf0_array_new(); @@ -319,7 +326,7 @@ static amf0_data * amf0_array_read(read_proc_t read_proc, void * user_data) { array_size = swap_uint32(array_size); for (i = 0; i < array_size; ++i) { - element = amf0_data_read(read_proc, user_data); + element = amf0_data_read_depth(read_proc, user_data, depth + 1); if (element != NULL) { if (amf0_array_push(data, element) == NULL) { @@ -355,10 +362,23 @@ static amf0_data * amf0_date_read(read_proc_t read_proc, void * user_data) { } } -/* load AMF data from stream */ -amf0_data * amf0_data_read(read_proc_t read_proc, void * user_data) { +/* + Read one value nested inside `depth` enclosing containers. Every recursion arm + funnels back through here, so one check covers any mix of them. +*/ +static amf0_data * amf0_data_read_depth(read_proc_t read_proc, void * user_data, unsigned int depth) { uint8_t type; + if (read_proc(&type, sizeof(uint8_t), user_data) == sizeof(uint8_t)) { + /* + Consume the marker before refusing, so a message nested exactly to the + cap still reads cleanly: what gets dropped there is the innermost + container's terminator, and leaving its byte in the stream would + misalign everything after it. + */ + if (depth >= AMF0_MAX_NESTING_DEPTH) { + return NULL; + } switch (type) { case AMF0_TYPE_NUMBER: return amf0_number_read(read_proc, user_data); @@ -367,16 +387,16 @@ amf0_data * amf0_data_read(read_proc_t read_proc, void * user_data) { case AMF0_TYPE_STRING: return amf0_string_read(read_proc, user_data); case AMF0_TYPE_OBJECT: - return amf0_object_read(read_proc, user_data); + return amf0_object_read(read_proc, user_data, depth); case AMF0_TYPE_NULL: return amf0_null_new(); case AMF0_TYPE_UNDEFINED: return amf0_undefined_new(); /*case AMF0_TYPE_REFERENCE:*/ case AMF0_TYPE_ECMA_ARRAY: - return amf0_associative_array_read(read_proc, user_data); + return amf0_associative_array_read(read_proc, user_data, depth); case AMF0_TYPE_STRICT_ARRAY: - return amf0_array_read(read_proc, user_data); + return amf0_array_read(read_proc, user_data, depth); case AMF0_TYPE_DATE: return amf0_date_read(read_proc, user_data); /*case AMF0_TYPE_SIMPLEOBJECT:*/ @@ -391,6 +411,11 @@ amf0_data * amf0_data_read(read_proc_t read_proc, void * user_data) { return NULL; } +/* load AMF data from stream */ +amf0_data * amf0_data_read(read_proc_t read_proc, void * user_data) { + return amf0_data_read_depth(read_proc, user_data, 0); +} + /* determines the size of the given AMF data */ size_t amf0_data_size(amf0_data * data) { size_t s = 0; diff --git a/src/mod/endpoints/mod_rtmp/libamf/src/amf0.h b/src/mod/endpoints/mod_rtmp/libamf/src/amf0.h index 2fa6bb99c3..50354513de 100644 --- a/src/mod/endpoints/mod_rtmp/libamf/src/amf0.h +++ b/src/mod/endpoints/mod_rtmp/libamf/src/amf0.h @@ -25,6 +25,14 @@ #define AMF0_TYPE_XML_DOCUMENT 0x0F #define AMF0_TYPE_TYPED_OBJECT 0x10 +/* + Deepest chain of nested containers (object / ECMA array / strict array) the + reader will build. A value past it is dropped, which an object or ECMA array + takes as its end and a strict array, having declared an element count, takes + as a failure. Real AMF0 command objects nest a handful of levels. +*/ +#define AMF0_MAX_NESTING_DEPTH 32 + typedef struct __amf0_node * p_amf0_node; /* string type */ From bffffa40a11ad84cdb005644b1198287fa9a3e2e Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 22:34:52 +0500 Subject: [PATCH 72/88] Merge commit from fork Co-authored-by: Andrey Volk --- src/mod/applications/mod_av/avformat.c | 23 +++- .../applications/mod_av/test/test_avformat.c | 130 ++++++++++++++++++ 2 files changed, 149 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index 92ec9ed9cf..315b578959 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -1602,6 +1602,7 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h if (context->has_audio) { AVCodecContext *c[2] = { NULL }; + int in_channels; if (!(c[0] = av_get_codec_context(&context->audio_st[0]))) { switch_goto_status(SWITCH_STATUS_FALSE, err); @@ -1634,7 +1635,14 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h context->audio_st[0].sample_rate = handle->samplerate; context->audio_st[1].sample_rate = handle->samplerate; - if (c[0]->sample_fmt != AV_SAMPLE_FMT_S16 || c[0]->sample_rate != handle->samplerate) { +#if (LIBAVCODEC_VERSION_MAJOR < LIBAVFORMAT_V) + in_channels = c[0]->channels; +#else + in_channels = c[0]->ch_layout.nb_channels; +#endif + + /* The read thread sizes its buffers by audio_st[0].channels, so a channel count mismatch must go through the resampler too */ + if (c[0]->sample_fmt != AV_SAMPLE_FMT_S16 || c[0]->sample_rate != handle->samplerate || in_channels != context->audio_st[0].channels) { int x; for (x = 0; x < context->has_audio && x < 2 && c[x]; x++) { @@ -1653,15 +1661,22 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h av_opt_set_int(resample_ctx, "in_sample_fmt", c[x]->sample_fmt, 0); av_opt_set_int(resample_ctx, "in_channel_layout", (c[x]->channel_layout == 0 && c[x]->channels == 2) ? AV_CH_LAYOUT_STEREO : c[x]->channel_layout, 0); - av_opt_set_int(resample_ctx, "out_channel_count", handle->channels, 0); + av_opt_set_int(resample_ctx, "out_channel_count", context->audio_st[x].channels, 0); #else av_opt_set_sample_fmt(resample_ctx, "in_sample_fmt", c[x]->sample_fmt, 0); - av_opt_set_chlayout(resample_ctx, "out_chlayout", &c[x]->ch_layout, 0); + { + /* Output must match the channel count the read thread allocates for (capped at 2), not the source layout */ + AVChannelLayout out_ch_layout; + + av_channel_layout_default(&out_ch_layout, context->audio_st[x].channels); + av_opt_set_chlayout(resample_ctx, "out_chlayout", &out_ch_layout, 0); + av_channel_layout_uninit(&out_ch_layout); + } #endif av_opt_set_int(resample_ctx, "out_sample_rate", handle->samplerate,0); #if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59,27,100)) av_opt_set_int(resample_ctx, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); - av_opt_set_int(resample_ctx, "out_channel_layout", handle->channels == 2 ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO, 0); + av_opt_set_int(resample_ctx, "out_channel_layout", context->audio_st[x].channels == 2 ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO, 0); #else av_opt_set_sample_fmt(resample_ctx, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); #endif diff --git a/src/mod/applications/mod_av/test/test_avformat.c b/src/mod/applications/mod_av/test/test_avformat.c index 5a0043e6cc..43a722b68b 100644 --- a/src/mod/applications/mod_av/test/test_avformat.c +++ b/src/mod/applications/mod_av/test/test_avformat.c @@ -32,6 +32,69 @@ #define SAMPLES 160 +#define SURROUND_CHANNELS 6 + +static void put_le16(FILE *f, uint16_t v) +{ + fputc(v & 0xff, f); + fputc((v >> 8) & 0xff, f); +} + +static void put_le32(FILE *f, uint32_t v) +{ + put_le16(f, v & 0xffff); + put_le16(f, (v >> 16) & 0xffff); +} + +/* Write a 5.1 (channel mask 0x3f) 16-bit PCM WAVE_FORMAT_EXTENSIBLE file with a + * square wave on FL/FR and silence on FC/LFE/BL/BR, so that reading the 6-channel + * frames as if they were stereo leaves two of every three output frames silent. */ +static switch_status_t write_surround_wav(const char *path, int rate, int seconds) +{ + static const uint8_t pcm_guid[16] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }; + uint32_t frames = rate * seconds; + uint32_t data_len = frames * SURROUND_CHANNELS * 2; + uint32_t i; + int ch; + FILE *f; + + if (!(f = fopen(path, "wb"))) { + return SWITCH_STATUS_FALSE; + } + + fwrite("RIFF", 1, 4, f); + put_le32(f, 4 + (8 + 40) + (8 + data_len)); + fwrite("WAVE", 1, 4, f); + + fwrite("fmt ", 1, 4, f); + put_le32(f, 40); + put_le16(f, 0xfffe); /* WAVE_FORMAT_EXTENSIBLE */ + put_le16(f, SURROUND_CHANNELS); + put_le32(f, rate); + put_le32(f, rate * SURROUND_CHANNELS * 2); /* byte rate */ + put_le16(f, SURROUND_CHANNELS * 2); /* block align */ + put_le16(f, 16); /* bits per sample */ + put_le16(f, 22); /* extension size */ + put_le16(f, 16); /* valid bits per sample */ + put_le32(f, 0x3f); /* FL FR FC LFE BL BR */ + fwrite(pcm_guid, 1, sizeof(pcm_guid), f); + + fwrite("data", 1, 4, f); + put_le32(f, data_len); + + for (i = 0; i < frames; i++) { + uint16_t s = ((i / 20) % 2) ? (uint16_t)8000 : (uint16_t)-8000; + + for (ch = 0; ch < SURROUND_CHANNELS; ch++) { + put_le16(f, ch < 2 ? s : 0); + } + } + + fclose(f); + + return SWITCH_STATUS_SUCCESS; +} + FST_CORE_BEGIN("conf") { FST_MODULE_BEGIN(mod_av, mod_av_test) @@ -250,6 +313,73 @@ FST_CORE_BEGIN("conf") } FST_TEST_END() + /* A >2 channel source must be resampled down to the (capped) playback + * channel count. The resampler used to keep the 5.1 source layout and + * write 6 channels into a buffer sized for 2 (heap overflow, caught by ASan). + * Without ASan the old code still fails here: the read thread took the + * 6-channel frames as stereo, so about 2/3 of the output was silence. + * 16kHz starts the resampler for the rate change; 8kHz (the open rate) + * starts it only for the channel count mismatch. */ + FST_TEST_BEGIN(avformat_test_play_surround_51) + { + int rates[] = { 16000, 8000 }; + int r; + + for (r = 0; r < 2; r++) { + char wav[1024]; + char path[1024]; + switch_status_t status; + switch_file_handle_t fh = { 0 }; + int16_t data[SAMPLES * 2] = { 0 }; + switch_size_t len; + switch_size_t total = 0, nonzero = 0, n; + int i; + + switch_snprintf(wav, sizeof(wav), "%s%savformat_test_surround_51_%d.wav", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, rates[r]); + status = write_surround_wav(wav, rates[r], 1); + fst_check(status == SWITCH_STATUS_SUCCESS); + if (status != SWITCH_STATUS_SUCCESS) { + continue; + } + + switch_snprintf(path, sizeof(path), "av://%s", wav); + status = switch_core_file_open(&fh, path, 1, 8000, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, fst_pool); + fst_check(status == SWITCH_STATUS_SUCCESS); + if (status != SWITCH_STATUS_SUCCESS) { + switch_file_remove(wav, fst_pool); + continue; + } + + fst_check(switch_test_flag(&fh, SWITCH_FILE_OPEN)); + fst_check(fh.real_channels <= 2); + + /* 1s of audio at 8kHz; read at real-time pace, bounded at ~4s */ + for (i = 0; i < 200; i++) { + len = SAMPLES; + status = switch_core_file_read(&fh, data, &len); + if (status != SWITCH_STATUS_SUCCESS) { + break; + } + + total += len; + + for (n = 0; n < len; n++) { + if (data[n]) { + nonzero++; + } + } + + switch_yield(20000); + } + + switch_core_file_close(&fh); + switch_file_remove(wav, fst_pool); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "5.1 wav at %dHz read %d samples, %d non-silent\n", rates[r], (int)total, (int)nonzero); + fst_xcheck(nonzero >= 4000, "Expected at least 0.5s of decoded audio from a 5.1 source"); + } + } + FST_TEST_END() + FST_TEARDOWN_BEGIN() { //const char *err = NULL; From 68b340f5f5d4f086a5ba25276312d13f2fb357b5 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 4 Nov 2026 19:21:51 +0500 Subject: [PATCH 73/88] [core] Confine MSRP remote file-selector name to the receive directory Without an explicit path, `msrp_recv_file_function()` joined the `sip_msrp_file_name` channel variable, taken from the remote SDP `a=file-selector` name, onto the base directory unchanged, so a name with directory components opened a file outside it. Reduce the name to its last path component with `switch_cut_path()` and reject an empty name, `.` and `..`. `test_switch_cut_path_strips_directory_components` covers the path reduction the receive path relies on. --- src/switch_msrp.c | 17 ++++++++++++++--- tests/unit/switch_utils.c | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/switch_msrp.c b/src/switch_msrp.c index f1a2d75cf2..8ea5ef80a8 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -1701,14 +1701,25 @@ SWITCH_STANDARD_APP(msrp_recv_file_function) switch_channel_answer(channel); if (zstr(data)) { - filename = switch_channel_get_variable(channel, "sip_msrp_file_name"); + const char *sip_file_name = switch_channel_get_variable(channel, "sip_msrp_file_name"); + const char *safe_name; - if (zstr(filename)) { + if (zstr(sip_file_name)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No file specified.\n"); + return; } - filename = switch_core_session_sprintf(session, "%s%s%s", SWITCH_GLOBAL_dirs.base_dir, SWITCH_PATH_SEPARATOR, filename); + /* The name is taken from the remote SDP file-selector. Reduce it to its final + path component so the opened file always stays inside the receive directory. */ + safe_name = switch_cut_path(sip_file_name); + if (zstr(safe_name) || !strcmp(safe_name, ".") || !strcmp(safe_name, "..")) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Rejecting remote file name '%s'\n", sip_file_name); + + return; + } + + filename = switch_core_session_sprintf(session, "%s%s%s", SWITCH_GLOBAL_dirs.base_dir, SWITCH_PATH_SEPARATOR, safe_name); } if (!(msrp_session = switch_core_media_get_msrp_session(session))) { diff --git a/tests/unit/switch_utils.c b/tests/unit/switch_utils.c index 07657141d5..c4ff2e3818 100644 --- a/tests/unit/switch_utils.c +++ b/tests/unit/switch_utils.c @@ -488,6 +488,28 @@ FST_TEST_BEGIN(test_switch_http_parse_header) } FST_TEST_END() +FST_TEST_BEGIN(test_switch_cut_path_strips_directory_components) +{ + size_t i; + struct { + const char *in; + const char *want; + } cases[] = { + { "plain.txt", "plain.txt" }, /* no separator: returned unchanged */ + { "../escape/x.txt", "x.txt" }, /* relative components dropped */ + { "/etc/passwd", "passwd" }, /* leading absolute path dropped */ + { "a/../../x", "x" }, /* embedded .. dropped with the rest of the path */ + { "dir\\sub\\f.txt", "f.txt" }, /* backslash is also a separator */ + { "trailing/", "" }, /* nothing follows the final separator */ + { "..", ".." }, /* no separator: caller must reject this residue */ + }; + + for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + fst_check_string_equals(switch_cut_path(cases[i].in), cases[i].want); + } +} +FST_TEST_END() + FST_SUITE_END() FST_MINCORE_END() From b3871f4066374e1df81b30a560c70cca01cb2e70 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 4 Nov 2026 19:26:28 +0500 Subject: [PATCH 74/88] [core] Bound MSRP reply and report to their buffer `msrp_reply()` and `msrp_report()` formatted the To-Path, From-Path, Message-ID and delimiter of the received request into a 2048-byte stack buffer with an unbounded `sprintf()`. Use `snprintf()` and send nothing when the result does not fit, since a truncated reply would lack its end-line. --- src/switch_msrp.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/switch_msrp.c b/src/switch_msrp.c index 8ea5ef80a8..9149f39c7a 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -1013,13 +1013,22 @@ switch_status_t msrp_reply(switch_msrp_client_socket_t *csock, switch_msrp_msg_t { char buf[2048]; switch_size_t len; - sprintf(buf, "MSRP %s 200 OK\r\nTo-Path: %s\r\nFrom-Path: %s\r\n" + int ret; + + ret = snprintf(buf, sizeof(buf), "MSRP %s 200 OK\r\nTo-Path: %s\r\nFrom-Path: %s\r\n" "%s$\r\n", msrp_msg->transaction_id, switch_str_nil(switch_msrp_msg_get_header(msrp_msg, MSRP_H_FROM_PATH)), switch_str_nil(switch_msrp_msg_get_header(msrp_msg, MSRP_H_TO_PATH)), msrp_msg->delimiter); - len = strlen(buf); + + if (ret < 0 || (switch_size_t)ret >= sizeof(buf)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "MSRP reply does not fit %" SWITCH_SIZE_T_FMT " bytes, not sent\n", sizeof(buf)); + + return SWITCH_STATUS_FALSE; + } + + len = ret; return msrp_socket_send(csock, buf, &len); } @@ -1028,7 +1037,9 @@ switch_status_t msrp_report(switch_msrp_client_socket_t *csock, switch_msrp_msg_ { char buf[2048]; switch_size_t len; - sprintf(buf, "MSRP %s REPORT\r\nTo-Path: %s\r\nFrom-Path: %s\r\nMessage-ID: %s\r\n" + int ret; + + ret = snprintf(buf, sizeof(buf), "MSRP %s REPORT\r\nTo-Path: %s\r\nFrom-Path: %s\r\nMessage-ID: %s\r\n" "Status: 000 %s\r\nByte-Range: 1-%" SWITCH_SIZE_T_FMT "/%" SWITCH_SIZE_T_FMT "\r\n%s$\r\n", msrp_msg->transaction_id, @@ -1039,7 +1050,14 @@ switch_status_t msrp_report(switch_msrp_client_socket_t *csock, switch_msrp_msg_ msrp_msg->accumulated_bytes ? msrp_msg->accumulated_bytes : msrp_msg->byte_end, msrp_msg->bytes, msrp_msg->delimiter); - len = strlen(buf); + + if (ret < 0 || (switch_size_t)ret >= sizeof(buf)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "MSRP report does not fit %" SWITCH_SIZE_T_FMT " bytes, not sent\n", sizeof(buf)); + + return SWITCH_STATUS_FALSE; + } + + len = ret; if (globals.debug) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "report: %" SWITCH_SIZE_T_FMT " bytes [\n%s]\n", len, buf); From 108e7f12661a4fe2342034139e27ba11d84f0a56 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 4 Nov 2026 19:30:57 +0500 Subject: [PATCH 75/88] [core] Treat received MSRP header values as data, not a format `msrp_parse_header()` and `msrp_parse_headers()` passed the received header value as the format argument of `switch_msrp_msg_add_header()`, so `%` sequences in it were interpreted. Pass it through `"%s"`; header values containing `%` are now stored unchanged. --- src/switch_msrp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/switch_msrp.c b/src/switch_msrp.c index 9149f39c7a..9d64036f9e 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -697,7 +697,7 @@ static char *msrp_parse_header(char *start, int skip, const char *end, switch_ms if (q > p) { if (*(q-1) == '\r') *(q-1) = '\0'; *q = '\0'; - switch_msrp_msg_add_header(msrp_msg, htype, p); + switch_msrp_msg_add_header(msrp_msg, htype, "%s", p); return q + 1; } return start; @@ -718,7 +718,7 @@ static switch_msrp_msg_t *msrp_parse_headers(char *start, int len, switch_msrp_m if (q > p) { *q = '\0'; - switch_msrp_msg_add_header(msrp_msg, MSRP_H_TRASACTION_ID, p); + switch_msrp_msg_add_header(msrp_msg, MSRP_H_TRASACTION_ID, "%s", p); switch_msrp_msg_add_header(msrp_msg, MSRP_H_DELIMITER, "-------%s", p); msrp_msg->state = MSRP_ST_PARSE_HEADER; } @@ -748,7 +748,7 @@ static switch_msrp_msg_t *msrp_parse_headers(char *start, int len, switch_msrp_m if (q > p) { if (*(q-1) == '\r') *(q-1) = '\0'; *q = '\0'; - switch_msrp_msg_add_header(msrp_msg, MSRP_H_CODE_DESCRIPTION, p); + switch_msrp_msg_add_header(msrp_msg, MSRP_H_CODE_DESCRIPTION, "%s", p); p = ++q; } } From 93fe4cc929a23c55d783940be7245638d46aee72 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 4 Nov 2026 19:39:46 +0500 Subject: [PATCH 76/88] [core] Treat the MSRP To-Path as data in msrp_find_uuid() `msrp_find_uuid()` passed the tail of the received To-Path as the format argument of `switch_snprintf()`. Pass it through `"%s"`. --- src/switch_msrp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/switch_msrp.c b/src/switch_msrp.c index 9d64036f9e..5c8578be50 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -1077,7 +1077,7 @@ static switch_bool_t msrp_find_uuid(char *uuid, const char *to_path) } if (slash_count < 3) return SWITCH_FALSE; if (len - i++ < 36) return SWITCH_FALSE; - switch_snprintf(uuid, 37, to_path + i); + switch_snprintf(uuid, 37, "%s", to_path + i); return SWITCH_TRUE; } From eff3cc6f5e8035eb6a5c9af19a990e307bd207d9 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 4 Nov 2026 19:42:01 +0500 Subject: [PATCH 77/88] [core] Check for a missing To-Path before msrp_find_uuid() reads it `msrp_find_uuid()` called `strlen()` on the To-Path before asserting it was set, and a first SEND without a To-Path header passes NULL. Return `SWITCH_FALSE` for it, so the worker handles it like any To-Path that names no session. --- src/switch_msrp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/switch_msrp.c b/src/switch_msrp.c index 5c8578be50..4bac62e283 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -1066,10 +1066,15 @@ switch_status_t msrp_report(switch_msrp_client_socket_t *csock, switch_msrp_msg_ static switch_bool_t msrp_find_uuid(char *uuid, const char *to_path) { - int len = strlen(to_path); + int len; int i; int slash_count = 0; - switch_assert(to_path); + + if (!to_path) { + return SWITCH_FALSE; + } + + len = strlen(to_path); for(i=0; i Date: Wed, 4 Nov 2026 19:43:13 +0500 Subject: [PATCH 78/88] [core] Remove the MSRP Byte-Range start assert `msrp_parse_headers()` asserted that the received Byte-Range start was above zero, so a range starting at 0 aborted the process. The payload length derived from it is already checked against the declared total and against the received data. --- src/switch_msrp.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/switch_msrp.c b/src/switch_msrp.c index 4bac62e283..68652fc6ad 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -793,7 +793,6 @@ static switch_msrp_msg_t *msrp_parse_headers(char *start, int len, switch_msrp_m if (q > p) { *q = '\0'; msrp_msg->byte_start = atoi(p); - switch_assert(msrp_msg->byte_start > 0); p = ++q; if (*p && *p == '*') { msrp_msg->range_star = 1; From 44b8010ba59831747be61e55973f9331ef3e3113 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 4 Nov 2026 19:49:28 +0500 Subject: [PATCH 79/88] [core] Bound the MSRP SEND request built in switch_msrp_do_send() The request line and headers, the CRLF after the payload and the end-line were written into the fixed stack buffer with `sprintf()`; only the payload copy was checked, and the To-Path can be as long as the remote SDP `a=path`. Build each part with `snprintf()` or a checked copy, advance the length by what was written, and drop a message that does not fit with an error log. --- src/switch_msrp.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/switch_msrp.c b/src/switch_msrp.c index 68652fc6ad..6b1c5bc982 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -1564,6 +1564,8 @@ static switch_status_t switch_msrp_do_send(switch_msrp_session_t *ms, switch_msr const char *to_path = msrp_h_to_path ? msrp_h_to_path : ms->remote_path; const char *from_path = msrp_h_from_path ? msrp_h_from_path: ms->local_path; const char *content_type = switch_msrp_msg_get_header(msrp_msg, MSRP_H_CONTENT_TYPE); + switch_size_t room; + int ret; if (msrp_msg->payload_bytes == 2 && msrp_msg->payload && !strncmp(msrp_msg->payload, "\r\n", 2)) { // discard \r\n appended in uuid_send_text @@ -1582,7 +1584,7 @@ static switch_status_t switch_msrp_do_send(switch_msrp_session_t *ms, switch_msr random_string(transaction_id, MSRP_TRANS_ID_LEN); switch_uuid_str(message_id, sizeof(message_id)); - sprintf(buf, "MSRP %s SEND\r\nTo-Path: %s\r\nFrom-Path: %s\r\n" + ret = snprintf(buf, sizeof(buf), "MSRP %s SEND\r\nTo-Path: %s\r\nFrom-Path: %s\r\n" "Message-ID: %s\r\n" "Byte-Range: 1-%" SWITCH_SIZE_T_FMT "/%" SWITCH_SIZE_T_FMT "\r\n" "%s%s%s", @@ -1596,25 +1598,43 @@ static switch_status_t switch_msrp_do_send(switch_msrp_session_t *ms, switch_msr msrp_msg->payload ? content_type : "", msrp_msg->payload ? "\r\n\r\n" : ""); - len = strlen(buf); + if (ret < 0 || (switch_size_t)ret >= sizeof(buf)) { + goto too_large; + } + + len = ret; if (msrp_msg->payload) { - if (len + msrp_msg->payload_bytes >= MSRP_BUFF_SIZE) { - switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, ms->call_id, SWITCH_LOG_ERROR, "payload too large! %" SWITCH_SIZE_T_FMT "\n", len + msrp_msg->payload_bytes); - return SWITCH_STATUS_FALSE; + /* at least one byte is left after the header */ + room = sizeof(buf) - len; + + /* the payload and its CRLF, leaving room for the end-line */ + if (msrp_msg->payload_bytes + 2 >= room) { + goto too_large; } + memcpy(buf + len, msrp_msg->payload, msrp_msg->payload_bytes); len += msrp_msg->payload_bytes; - sprintf(buf + len, "\r\n"); + memcpy(buf + len, "\r\n", 2); len += 2; } - sprintf(buf + len, "-------%s$\r\n", transaction_id); - len += (10 + strlen(transaction_id)); + ret = snprintf(buf + len, sizeof(buf) - len, "-------%s$\r\n", transaction_id); + + if (ret < 0 || (switch_size_t)ret >= sizeof(buf) - len) { + goto too_large; + } + + len += ret; if (globals.debug) dump_buffer(buf, len, __LINE__, 1); return ms->csock ? msrp_socket_send(ms->csock, buf, &len) : SWITCH_STATUS_FALSE; + +too_large: + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, ms->call_id, SWITCH_LOG_ERROR, "MSRP message does not fit %" SWITCH_SIZE_T_FMT " bytes, not sent\n", sizeof(buf)); + + return SWITCH_STATUS_FALSE; } SWITCH_DECLARE (switch_status_t) switch_msrp_perform_send(switch_msrp_session_t *ms, switch_msrp_msg_t *msrp_msg, const char *file, const char *func, int line) From 1dc4fd7df0eebf394ff1bf9787f39d33a1f24a21 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 4 Nov 2026 23:22:36 +0500 Subject: [PATCH 80/88] [core] Fix MSRP leaks and error handling in the worker - Free MSRP messages and their headers on every path that drops them, including `uuid_msrp_send` and `mod_sofia`'s filtered text frames. - Handle a failed `SSL_new()` and a call without an MSRP session by closing the connection instead of asserting. - Treat a zero-length TLS read as the peer closing the connection. --- src/mod/endpoints/mod_sofia/mod_sofia.c | 3 ++ src/switch_msrp.c | 37 +++++++++++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 209c7ca4bc..16d22fa14e 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1084,6 +1084,9 @@ static switch_status_t sofia_read_text_frame(switch_core_session_t *session, swi switch_msrp_msg_destroy(&msrp_msg); status = SWITCH_STATUS_SUCCESS; } else { + if (msrp_msg) { + switch_msrp_msg_destroy(&msrp_msg); + } rframe->datalen = 2; rframe->flags = SFF_CNG; *frame = rframe; diff --git a/src/switch_msrp.c b/src/switch_msrp.c index 6b1c5bc982..3dc72a9936 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -679,6 +679,8 @@ SWITCH_DECLARE(switch_status_t) switch_msrp_msg_add_header(switch_msrp_msg_t *ms default: break; } + switch_safe_free(data); + return status; } @@ -1183,7 +1185,11 @@ static void *SWITCH_THREAD_FUNC msrp_worker(switch_thread_t *thread, void *obj) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "MSRP setup TLS %s\n", msrp_session->call_id); ssl = SSL_new(globals.ssl_client_ctx); - assert(ssl); + if (!ssl) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MSRP %s cannot create a TLS client session\n", msrp_session->call_id); + goto end; + } + csock->ssl = ssl; SSL_set_fd(ssl, sockdes); @@ -1241,7 +1247,11 @@ static void *SWITCH_THREAD_FUNC msrp_worker(switch_thread_t *thread, void *obj) switch_assert(sockdes != SWITCH_SOCK_INVALID); ssl = SSL_new(globals.ssl_ctx); - assert(ssl); + if (!ssl) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MSRP cannot create a TLS server session\n"); + goto end; + } + csock->ssl = ssl; SSL_set_fd(ssl, sockdes); @@ -1322,7 +1332,12 @@ static void *SWITCH_THREAD_FUNC msrp_worker(switch_thread_t *thread, void *obj) } msrp_session = switch_core_media_get_msrp_session(session); - switch_assert(msrp_session); + if (!msrp_session) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Session %s has no MSRP session\n", uuid); + switch_core_session_rwunlock(session); + goto end; + } + msrp_session->csock = csock; msrp_session->running = 1; @@ -1339,8 +1354,9 @@ static void *SWITCH_THREAD_FUNC msrp_worker(switch_thread_t *thread, void *obj) // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "read bytes: %" SWITCH_SIZE_T_FMT "\n", len); if (len == 0) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "read bytes: %" SWITCH_SIZE_T_FMT "\n", len); - continue; + /* only a TLS read reports success with no data, and only once the peer has closed */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "MSRP connection closed by peer\n"); + break; } if (helper->debug) dump_buffer(buf, (p - buf) + len, __LINE__, 0); @@ -1454,6 +1470,10 @@ end: if (msrp_session) msrp_session->running = 0; + if (msrp_msg) { + switch_msrp_msg_destroy(&msrp_msg); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "MSRP worker down %s\n", msrp_session ? msrp_session->call_id : "!"); return NULL; @@ -1725,6 +1745,7 @@ SWITCH_DECLARE(void) switch_msrp_msg_destroy(switch_msrp_msg_t **msg) } switch_safe_free(msrp_msg->payload); + switch_safe_free(*msg); *msg = NULL; } @@ -1794,7 +1815,7 @@ SWITCH_STANDARD_APP(msrp_recv_file_function) } } - switch_safe_free(msrp_msg); + switch_msrp_msg_destroy(&msrp_msg); } switch_file_close(fd); @@ -1890,12 +1911,14 @@ SWITCH_STANDARD_API(uuid_msrp_send_function) if (!(msession = switch_core_session_locate(argv[0]))) { stream->write_function(stream, "-ERR Usage: cannot locate session.\n"); + switch_safe_free(mycmd); return SWITCH_STATUS_SUCCESS; } if (!(msrp_session = switch_core_media_get_msrp_session(msession))) { stream->write_function(stream, "-ERR No msrp_session.\n"); switch_core_session_rwunlock(msession); + switch_safe_free(mycmd); return SWITCH_STATUS_SUCCESS; } @@ -1906,10 +1929,12 @@ SWITCH_STANDARD_API(uuid_msrp_send_function) switch_msrp_msg_destroy(&msrp_msg); stream->write_function(stream, "+OK message sent\n"); switch_core_session_rwunlock(msession); + switch_safe_free(mycmd); return SWITCH_STATUS_SUCCESS; error: stream->write_function(stream, "-ERR Usage: uuid_msrp_send msg\n"); + switch_safe_free(mycmd); return SWITCH_STATUS_SUCCESS; } From 8721a8f6547aefee6a29d805b7ad5b8babd69794 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 4 Nov 2026 23:23:38 +0500 Subject: [PATCH 81/88] [core] Harden MSRP message parsing and sending - Reject a request with an empty transaction id, and a body that has no end-line delimiter to frame it. - Keep the receive buffer NUL-terminated after every read. - Free the setup message when an outbound connection fails before sending it. - Refuse to send a message without a To-Path. --- src/switch_msrp.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/switch_msrp.c b/src/switch_msrp.c index 3dc72a9936..17d8a25edf 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -718,6 +718,12 @@ static switch_msrp_msg_t *msrp_parse_headers(char *start, int len, switch_msrp_m while(*q && q < end && *q != ' ') q++; + if (q == p && q < end) { + /* empty transaction id: there is no end-line delimiter to frame the body */ + msrp_msg->state = MSRP_ST_ERROR; + goto done; + } + if (q > p) { *q = '\0'; switch_msrp_msg_add_header(msrp_msg, MSRP_H_TRASACTION_ID, "%s", p); @@ -910,13 +916,19 @@ static switch_msrp_msg_t *msrp_parse_buffer(char *buf, int len, switch_msrp_msg_ return msrp_msg; } + if (zstr(msrp_msg->delimiter)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MSRP body without a delimiter\n"); + msrp_msg->state = MSRP_ST_ERROR; + + return msrp_msg; + } + if (msrp_msg->range_star) { /* the * case */ /*hope we can find the delimiter at the end*/ int dlen; char *delim_pos = NULL; switch_size_t payload_bytes; - switch_assert(msrp_msg->delimiter); dlen = strlen(msrp_msg->delimiter); /* Need room for the trailing delimiter framing; a shorter @@ -1092,12 +1104,13 @@ static void *SWITCH_THREAD_FUNC msrp_worker(switch_thread_t *thread, void *obj) worker_helper_t *helper = (worker_helper_t *) obj; switch_msrp_client_socket_t *csock = &helper->csock; switch_memory_pool_t *pool = helper->pool; - char buf[MSRP_BUFF_SIZE]; + char buf[MSRP_BUFF_SIZE + 1]; /* received data is NUL-terminated in the extra byte */ char *p; char *last_p; switch_size_t len = MSRP_BUFF_SIZE; switch_status_t status; switch_msrp_msg_t *msrp_msg = NULL; + switch_msrp_msg_t *setup_msg = NULL; char uuid[128] = { 0 }; switch_msrp_session_t *msrp_session = NULL; int sanity = 10; @@ -1106,12 +1119,12 @@ static void *SWITCH_THREAD_FUNC msrp_worker(switch_thread_t *thread, void *obj) if (client_mode) { switch_sockaddr_t *sa = NULL; - switch_msrp_msg_t *setup_msg = switch_msrp_msg_create(); const char *remote_ip = NULL; switch_port_t remote_port = 0; char *dup = NULL; char *p = NULL; + setup_msg = switch_msrp_msg_create(); switch_assert(setup_msg); switch_assert(helper->msrp_session); msrp_session = helper->msrp_session; @@ -1287,6 +1300,7 @@ static void *SWITCH_THREAD_FUNC msrp_worker(switch_thread_t *thread, void *obj) } if (status == SWITCH_STATUS_SUCCESS) { + buf[len] = '\0'; msrp_msg = msrp_parse_buffer(buf, len, NULL, pool); switch_assert(msrp_msg); } else { @@ -1362,6 +1376,8 @@ static void *SWITCH_THREAD_FUNC msrp_worker(switch_thread_t *thread, void *obj) if (helper->debug) dump_buffer(buf, (p - buf) + len, __LINE__, 0); again: + /* p + len is the end of the received data on every path that reaches here */ + p[len] = '\0'; msrp_msg = msrp_parse_buffer(last_p, p - last_p + len, msrp_msg, pool); switch_assert(msrp_msg); @@ -1474,6 +1490,11 @@ end: switch_msrp_msg_destroy(&msrp_msg); } + /* set only when a client connection failed before its setup SEND */ + if (setup_msg) { + switch_msrp_msg_destroy(&setup_msg); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "MSRP worker down %s\n", msrp_session ? msrp_session->call_id : "!"); return NULL; @@ -1597,6 +1618,12 @@ static switch_status_t switch_msrp_do_send(switch_msrp_session_t *ms, switch_msr return SWITCH_STATUS_SUCCESS; } + if (!to_path) { + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, ms->call_id, SWITCH_LOG_WARNING, "NO TO PATH\n"); + + return SWITCH_STATUS_FALSE; + } + if (zstr(content_type)) { content_type = "text/plain"; } From 74f63975fdb94bde3a05ec75001ae9ae055b511c Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Tue, 17 Nov 2026 17:48:10 +0500 Subject: [PATCH 82/88] [core] Do not start an MSRP client without a remote path When the remote side offers `a=setup:passive`, negotiation started the MSRP client whether or not the offer carried an `a=path`, and the client then asserted on the missing `remote_path`. Start the client only when a path was negotiated. In `msrp_worker()`, also stop with an error instead of asserting when there is no path, and when the path gives no host or port. --- src/switch_core_media.c | 6 +++++- src/switch_msrp.c | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index f8825aab74..760bb41c13 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -5101,7 +5101,11 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s smh->msrp_session->secure ? "s" : "", ip, smh->msrp_session->local_port, smh->msrp_session->call_id); - switch_msrp_start_client(smh->msrp_session); + if (zstr(smh->msrp_session->remote_path)) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "MSRP remote is passive but sent no path, not connecting\n"); + } else { + switch_msrp_start_client(smh->msrp_session); + } } switch_core_session_start_text_thread(session); diff --git a/src/switch_msrp.c b/src/switch_msrp.c index 17d8a25edf..90028ae539 100644 --- a/src/switch_msrp.c +++ b/src/switch_msrp.c @@ -1130,7 +1130,11 @@ static void *SWITCH_THREAD_FUNC msrp_worker(switch_thread_t *thread, void *obj) msrp_session = helper->msrp_session; msrp_session->running = 1; - switch_assert(msrp_session->remote_path); + if (zstr(msrp_session->remote_path)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MSRP %s has no remote path to connect to\n", msrp_session->call_id); + goto end; + } + dup = switch_core_strdup(pool, msrp_session->remote_path); switch_assert(dup); @@ -1155,8 +1159,9 @@ static void *SWITCH_THREAD_FUNC msrp_worker(switch_thread_t *thread, void *obj) } } - if (!remote_ip || remote_port <= 0) { + if (zstr(remote_ip) || remote_port <= 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error get remote MSRP ip:port from path: [%s]\n", msrp_session->remote_path); + goto end; } if (switch_sockaddr_info_get(&sa, remote_ip, SWITCH_UNSPEC, remote_port, 0, pool) != SWITCH_STATUS_SUCCESS) { From b5336ca3f9d13ec0c41ca2ae0c328bf5c922b425 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 23:42:36 +0500 Subject: [PATCH 83/88] [core] Cut switch_cut_path() at the last separator of either kind (#3298) `switch_cut_path()` scanned for `/`, then restarted from the start of the string for `\`, so whenever the last `\` came before the last `/` the result still held `/`-separated components. Search for the last `/` first, then for the last `\` in what follows it, so the result is always what comes after the final separator, as documented. Adds mixed-separator cases to `test_switch_cut_path_strips_directory_components`. --- src/switch_utils.c | 23 ++++++++++++----------- tests/unit/switch_utils.c | 8 ++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/switch_utils.c b/src/switch_utils.c index f3c6521e99..7e94105422 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -2895,20 +2895,21 @@ SWITCH_DECLARE(unsigned int) switch_separate_string(char *buf, char delim, char SWITCH_DECLARE(const char *) switch_cut_path(const char *in) { const char *p, *ret = in; - const char delims[] = "/\\"; - const char *i; - if (in) { - for (i = delims; *i; i++) { - p = in; - while ((p = strchr(p, *i)) != 0) { - ret = ++p; - } - } - return ret; - } else { + if (!in) { return NULL; } + + /* The second search only sees what follows the last '/', so the last separator of either kind wins. */ + if ((p = strrchr(ret, '/'))) { + ret = p + 1; + } + + if ((p = strrchr(ret, '\\'))) { + ret = p + 1; + } + + return ret; } SWITCH_DECLARE(switch_status_t) switch_string_match(const char *string, size_t string_len, const char *search, size_t search_len) diff --git a/tests/unit/switch_utils.c b/tests/unit/switch_utils.c index c4ff2e3818..b566e70c59 100644 --- a/tests/unit/switch_utils.c +++ b/tests/unit/switch_utils.c @@ -500,10 +500,18 @@ FST_TEST_BEGIN(test_switch_cut_path_strips_directory_components) { "/etc/passwd", "passwd" }, /* leading absolute path dropped */ { "a/../../x", "x" }, /* embedded .. dropped with the rest of the path */ { "dir\\sub\\f.txt", "f.txt" }, /* backslash is also a separator */ + { "\\../../x", "x" }, /* mixed: a backslash before slash-separated components */ + { "a/b\\c/d", "d" }, /* mixed: the last separator wins whichever kind it is */ + { "a\\b/c\\d", "d" }, /* mixed: backslash last */ { "trailing/", "" }, /* nothing follows the final separator */ + { "trailing\\", "" }, + { "/", "" }, /* separator only */ + { "\\", "" }, { "..", ".." }, /* no separator: caller must reject this residue */ }; + fst_xcheck(switch_cut_path(NULL) == NULL, "a NULL path yields NULL"); + for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { fst_check_string_equals(switch_cut_path(cases[i].in), cases[i].want); } From bc63ad6f89d3be4b942b786c2a305ae4677abdf7 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Thu, 19 Nov 2026 00:07:00 +0500 Subject: [PATCH 84/88] [mod_verto] Release POST body and request state on HTTP error paths (#3299) `http_run()` left the form-urlencoded POST body buffer allocated when `kws_raw_read()` failed or the peer closed mid-body, up to `HTTP_POST_MAX_BODY` per connection. Free it there, and clear `keepalive` so the unread rest of the body is not parsed as the next request. The `err:` exit also freed neither `request` nor `stream.param_event`: a header parse failure leaked the event, and a non-Basic `Authorization` header leaked both. It now releases both, which makes `request_err:` redundant, so its two users jump to `err:` instead. --- src/mod/endpoints/mod_verto/mod_verto.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index 5a625954a4..e95d63f96a 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -1868,7 +1868,7 @@ new_req: } if (!(buffer = malloc(request->content_length + 1))) { - goto request_err; + goto err; } while(bytes < (switch_ssize_t)request->content_length) { @@ -1878,6 +1878,8 @@ new_req: if ((len = kws_raw_read(jsock->ws, buffer + bytes, len, WS_BLOCK)) <= 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read error %" SWITCH_SSIZE_T_FMT"\n", len); + free(buffer); + request->keepalive = 0; goto done; } @@ -1945,7 +1947,7 @@ new_req: } if (!(params = cJSON_CreateObject())) { - goto request_err; + goto err; } cJSON_AddItemToObject(params, "login", cJSON_CreateString(auth_user)); @@ -2036,13 +2038,14 @@ done: return; -request_err: - kws_request_free(&request); - err: err = "HTTP/1.1 500 Internal Server Error\r\n" "Content-Length: 0\r\n\r\n"; kws_raw_write(jsock->ws, err, strlen(err)); + kws_request_free(&request); + if (stream.param_event) { + switch_event_destroy(&stream.param_event); + } error: return; From 898de5d1dd30bb7f6ec7fcd962abf1419f6b562a Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 19:40:18 +0500 Subject: [PATCH 85/88] [mod_verto] Skip unnamed elements when reading client JSON members `check_auth()` and `parse_user_vars()` copy the members of `loginParams` and `userVariables` into events and channel variables, but validated the member name on the string-value branch only. Check it once at the top of each loop so every value type is handled the same way. --- src/mod/endpoints/mod_verto/mod_verto.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index e95d63f96a..fe935bcd0f 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -1077,11 +1077,16 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char * cJSON * i; for(i = json_ptr->child; i; i = i->next) { + /* Skip empty names, and the NULL ones cJSON gives array elements. */ + if (zstr(i->string)) { + continue; + } + if (i->type == cJSON_True) { switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, i->string, "true"); } else if (i->type == cJSON_False) { switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, i->string, "false"); - } else if (!zstr(i->string) && !zstr(i->valuestring)) { + } else if (!zstr(i->valuestring)) { switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, i->string, i->valuestring); } } @@ -1153,11 +1158,16 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char * switch_mutex_lock(jsock->flag_mutex); for (i = json_ptr->child; i; i = i->next) { + /* Skip empty names, and the NULL ones cJSON gives array elements. */ + if (zstr(i->string)) { + continue; + } + if (i->type == cJSON_True) { switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, "true"); } else if (i->type == cJSON_False) { switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, "false"); - } else if (!zstr(i->string) && !zstr(i->valuestring)) { + } else if (!zstr(i->valuestring)) { switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, i->valuestring); } } @@ -3811,13 +3821,20 @@ static void parse_user_vars(cJSON *obj, switch_core_session_t *session) cJSON * i; for(i = json_ptr->child; i; i = i->next) { - char *varname = switch_core_session_sprintf(session, "verto_dvar_%s", i->string); + char *varname; + + /* Skip empty names, and the NULL ones cJSON gives array elements. */ + if (zstr(i->string)) { + continue; + } + + varname = switch_core_session_sprintf(session, "verto_dvar_%s", i->string); if (i->type == cJSON_True) { switch_channel_set_variable(channel, varname, "true"); } else if (i->type == cJSON_False) { switch_channel_set_variable(channel, varname, "false"); - } else if (!zstr(i->string) && !zstr(i->valuestring)) { + } else if (!zstr(i->valuestring)) { switch_channel_set_variable(channel, varname, i->valuestring); } } From 39f5977a47d89445bcc58adfe35a58ed60580e9f Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Wed, 18 Nov 2026 19:53:41 +0500 Subject: [PATCH 86/88] [mod_verto] Prefix login userVariables with verto_uvar_ Store `userVariables` sent in a `login` with a `verto_uvar_` prefix, matching the `verto_dvar_` prefix per-call `dialogParams` userVariables already carry, so the two scopes stay separate. Variables from the user's directory `` block keep their names. Dialplan that reads login variables by their unprefixed names needs updating. The new per-profile `enable-uservars-namespace` turns the prefix off for deployments that cannot do that yet; it defaults on. --- conf/vanilla/autoload_configs/verto.conf.xml | 7 +++++ src/mod/endpoints/mod_verto/mod_verto.c | 29 ++++++++++++++++---- src/mod/endpoints/mod_verto/mod_verto.h | 1 + 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/conf/vanilla/autoload_configs/verto.conf.xml b/conf/vanilla/autoload_configs/verto.conf.xml index b65430471e..3afd470f7b 100644 --- a/conf/vanilla/autoload_configs/verto.conf.xml +++ b/conf/vanilla/autoload_configs/verto.conf.xml @@ -26,6 +26,12 @@ Prefer the fsapi method with jsonrpc-allowed-fsapi, which allow-lists commands per user. This param is here for clients that already use api+. --> + + @@ -52,6 +58,7 @@ + diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index fe935bcd0f..bf2a0f4190 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -1158,18 +1158,30 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char * switch_mutex_lock(jsock->flag_mutex); for (i = json_ptr->child; i; i = i->next) { + char *prefixed = NULL; + const char *name = i->string; + /* Skip empty names, and the NULL ones cJSON gives array elements. */ if (zstr(i->string)) { continue; } - if (i->type == cJSON_True) { - switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, "true"); - } else if (i->type == cJSON_False) { - switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, "false"); - } else if (!zstr(i->valuestring)) { - switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, i->valuestring); + if (jsock->profile->enable_uservars_namespace) { + if (!(prefixed = switch_mprintf("verto_uvar_%s", i->string))) { + continue; + } + name = prefixed; } + + if (i->type == cJSON_True) { + switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, name, "true"); + } else if (i->type == cJSON_False) { + switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, name, "false"); + } else if (!zstr(i->valuestring)) { + switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, name, i->valuestring); + } + + switch_safe_free(prefixed); } switch_mutex_unlock(jsock->flag_mutex); } @@ -5338,6 +5350,7 @@ static switch_status_t parse_config(const char *cf) profile->mcast_sub.sock = KS_SOCK_INVALID; profile->mcast_pub.sock = KS_SOCK_INVALID; profile->chop_domain = SWITCH_TRUE; + profile->enable_uservars_namespace = SWITCH_TRUE; for (param = switch_xml_child(xprofile, "param"); param; param = param->next) { char *var = NULL; @@ -5379,6 +5392,10 @@ static switch_status_t parse_config(const char *cf) profile->blind_reg = switch_true(val); } else if (!strcasecmp(var, "enable-chat-api-proto") && !zstr(val)) { profile->enable_chat_api_proto = switch_true(val); + } else if (!strcasecmp(var, "enable-uservars-namespace") && !zstr(val)) { + /* Only a recognised negative turns this off, so a value + * neither side spells correctly keeps the prefix. */ + profile->enable_uservars_namespace = !switch_false(val); } else if (!strcasecmp(var, "userauth") && !zstr(val)) { profile->userauth = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "chop-domain") && !zstr(val)) { diff --git a/src/mod/endpoints/mod_verto/mod_verto.h b/src/mod/endpoints/mod_verto/mod_verto.h index e565447e7b..7d035ff6db 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.h +++ b/src/mod/endpoints/mod_verto/mod_verto.h @@ -248,6 +248,7 @@ struct verto_profile_s { int in_thread; int blind_reg; int enable_chat_api_proto; + int enable_uservars_namespace; char *userauth; char *root_passwd; From 1da5eadf70ffc8aee88f1636fb9ad1fcd3d3bcd2 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Thu, 19 Nov 2026 01:12:22 +0500 Subject: [PATCH 87/88] [mod_av, mod_openh264] Validate H.264 FU-A and H.263 packet lengths before depacketizing, add decoder unit tests (#3301) --- src/mod/applications/mod_av/avcodec.c | 63 +++- .../applications/mod_av/test/test_mod_av.c | 285 +++++++++++++++++- src/mod/codecs/mod_openh264/mod_openh264.cpp | 29 +- .../mod_openh264/test/test_mod_openh264.cpp | 126 +++++++- 4 files changed, 479 insertions(+), 24 deletions(-) diff --git a/src/mod/applications/mod_av/avcodec.c b/src/mod/applications/mod_av/avcodec.c index 20f9abe719..3966122a32 100644 --- a/src/mod/applications/mod_av/avcodec.c +++ b/src/mod/applications/mod_av/avcodec.c @@ -552,10 +552,15 @@ static switch_status_t buffer_h264_nalu(h264_codec_context_t *context, switch_fr { uint8_t nalu_type = 0; uint8_t *data = frame->data; - uint8_t nalu_hdr = *data; + uint8_t nalu_hdr; uint8_t sync_bytes[] = {0, 0, 0, 1}; switch_buffer_t *buffer = context->nalu_buffer; + if (!frame->datalen) { /* one byte NAL unit header */ + return SWITCH_STATUS_RESTART; + } + + nalu_hdr = *data; nalu_type = nalu_hdr & 0x1f; //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "nalu=%02x mark=%d seq=%d ts=%d len=%d\n", nalu_hdr, frame->m, frame->seq, frame->timestamp, frame->datalen); @@ -575,8 +580,14 @@ static switch_status_t buffer_h264_nalu(h264_codec_context_t *context, switch_fr if ((nalu_type == 7 || nalu_type == 8) && frame->m) frame->m = SWITCH_FALSE; if (nalu_type == 28) { // 0x1c FU-A - int start = *(data + 1) & 0x80; - int end = *(data + 1) & 0x40; + int start, end; + + if (frame->datalen < 2) { /* FU indicator + FU header, the payload may be empty */ + return SWITCH_STATUS_RESTART; + } + + start = *(data + 1) & 0x80; + end = *(data + 1) & 0x40; nalu_type = *(data + 1) & 0x1f; @@ -588,6 +599,11 @@ static switch_status_t buffer_h264_nalu(h264_codec_context_t *context, switch_fr switch_buffer_zero(buffer); } } else if (end) { + if (!context->nalu_28_start) { + /* the start fragment was lost, this tail is undecodable */ + return SWITCH_STATUS_RESTART; + } + context->nalu_28_start = 0; } else if (!context->nalu_28_start) { return SWITCH_STATUS_RESTART; @@ -662,6 +678,11 @@ static switch_status_t buffer_h263_packets(h264_codec_context_t *context, switch h263_payload_header_t *h = (h263_payload_header_t *)data; int delta = 0; + if (frame->datalen < 4) { /* Mode A header */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID PACKET\n"); + return SWITCH_STATUS_FALSE; + } + if (h->f) { if (h->p) { header_len = 12; // Mode C @@ -741,7 +762,7 @@ static switch_status_t buffer_h263_packets(h264_codec_context_t *context, switch static switch_status_t buffer_h263_rfc4629_packets(h264_codec_context_t *context, switch_frame_t *frame) { uint8_t *data = frame->data; - uint16_t header = ntohs(*((uint16_t *)frame->data)); + uint16_t header; int startcode, vrc, picture_header; int len = frame->datalen; @@ -749,6 +770,8 @@ static switch_status_t buffer_h263_rfc4629_packets(h264_codec_context_t *context return SWITCH_STATUS_FALSE; } + header = ntohs(*((uint16_t *)frame->data)); + startcode = (header & 0x0400) >> 9; vrc = header & 0x0200; picture_header = (header & 0x01f8) >> 3; @@ -1713,6 +1736,10 @@ static switch_status_t switch_h264_decode(switch_codec_t *codec, switch_frame_t // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "len: %d ts: %u mark:%d\n", frame->datalen, ntohl(frame->timestamp), frame->m); + if (!frame->data) { + return SWITCH_STATUS_FALSE; + } + //if (context->last_received_timestamp && context->last_received_timestamp != frame->timestamp && // (!frame->m) && (!context->last_received_complete_picture)) { // possible packet loss @@ -1723,19 +1750,23 @@ static switch_status_t switch_h264_decode(switch_codec_t *codec, switch_frame_t context->last_received_timestamp = frame->timestamp; context->last_received_complete_picture = frame->m ? SWITCH_TRUE : SWITCH_FALSE; - if (context->av_codec_id == AV_CODEC_ID_H263) { - status = buffer_h263_packets(context, frame); - } else if (context->av_codec_id == AV_CODEC_ID_H263P) { - status = buffer_h263_rfc4629_packets(context, frame); - } else { - status = buffer_h264_nalu(context, frame); - } + /* an empty packet adds nothing, but its marker bit still closes the picture below */ + if (frame->datalen > 0) { + if (context->av_codec_id == AV_CODEC_ID_H263) { + status = buffer_h263_packets(context, frame); + } else if (context->av_codec_id == AV_CODEC_ID_H263P) { + status = buffer_h263_rfc4629_packets(context, frame); + } else { + status = buffer_h264_nalu(context, frame); + } - if (status == SWITCH_STATUS_RESTART) { - switch_set_flag(frame, SFF_WAIT_KEY_FRAME); - switch_buffer_zero(context->nalu_buffer); - context->nalu_28_start = 0; - return SWITCH_STATUS_MORE_DATA; + if (status == SWITCH_STATUS_RESTART) { + switch_set_flag(frame, SFF_WAIT_KEY_FRAME); + switch_buffer_zero(context->nalu_buffer); + context->nalu_28_start = 0; + + return SWITCH_STATUS_MORE_DATA; + } } if (frame->m) { diff --git a/src/mod/applications/mod_av/test/test_mod_av.c b/src/mod/applications/mod_av/test/test_mod_av.c index 69468dbda2..502f5ccfd9 100644 --- a/src/mod/applications/mod_av/test/test_mod_av.c +++ b/src/mod/applications/mod_av/test/test_mod_av.c @@ -48,6 +48,29 @@ static fctcl_init_t my_cl_options[] = { FCTCL_INIT_NULL /* Sentinel */ }; +/* payload bytes per FU-A fragment when the round-trip test re-fragments a NAL unit */ +#define FU_A_TEST_PAYLOAD 32 + +/* Feed one RTP payload to the decoder the way the media layer does: a fresh frame per packet, + * the marker on the last packet of a picture and the timestamp advancing per picture. */ +static switch_status_t decode_rtp_payload(switch_codec_t *codec, switch_frame_t *frame, void *data, uint32_t datalen, switch_bool_t m) +{ + switch_status_t status; + + frame->data = data; + frame->datalen = datalen; + frame->m = m; + frame->flags = 0; + frame->img = NULL; + frame->seq++; + + status = switch_core_codec_decode_video(codec, frame); + + if (m) frame->timestamp += 3000; + + return status; +} + FST_CORE_BEGIN("conf") { const char *loop_; @@ -153,11 +176,269 @@ FST_CORE_BEGIN("conf") } FST_TEST_END() + /* RTP payloads shorter than the headers their NAL type implies are rejected by the depacketizer, + * while FU-A fragments with an empty payload, which RFC 6184 allows, are accepted */ + FST_TEST_BEGIN(decoder_short_packet_test) + { + switch_status_t status; + switch_codec_t codec = { 0 }; + switch_codec_settings_t codec_settings = {{ 0 }}; + switch_frame_t frame = { 0 }; + /* each packet buffer is exactly the length it claims */ + uint8_t fu_a_indicator_only[] = { 0x7c }; + uint8_t fu_a_start_empty[] = { 0x7c, 0x85 }; + uint8_t fu_a_middle_empty[] = { 0x7c, 0x05 }; + uint8_t fu_a_end_empty[] = { 0x7c, 0x45 }; + uint8_t fu_a_start[] = { 0x7c, 0x85, 0x01, 0x02 }; + uint8_t fu_a_end[] = { 0x7c, 0x45, 0x03, 0x04 }; + uint8_t stap_a_indicator_only[] = { 0x78 }; + uint8_t stap_a_half_size[] = { 0x78, 0x00 }; + uint8_t single_nalu_header_only[] = { 0x65 }; + int i; + + switch_set_string(codec_settings.video.config_profile_name, "conference"); + + status = switch_core_codec_init(&codec, + "H264", + NULL, + NULL, + 0, + 0, + 1, SWITCH_CODEC_FLAG_DECODE, + &codec_settings, fst_pool); + fst_check(status == SWITCH_STATUS_SUCCESS); + + frame.payload = 96; + frame.timestamp = 3000; + + /* an empty payload adds nothing */ + status = decode_rtp_payload(&codec, &frame, fu_a_indicator_only, 0, SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(frame.img == NULL); + + /* an FU-A without the FU header is dropped and a key frame requested, an FU-A with an empty payload is accepted */ + for (i = 0; i < 2; i++) { + switch_bool_t m = i ? SWITCH_TRUE : SWITCH_FALSE; + + status = decode_rtp_payload(&codec, &frame, fu_a_indicator_only, sizeof(fu_a_indicator_only), m); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(switch_test_flag(&frame, SFF_WAIT_KEY_FRAME)); + fst_check(frame.img == NULL); + + status = decode_rtp_payload(&codec, &frame, fu_a_start_empty, sizeof(fu_a_start_empty), m); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(frame.img == NULL); + } + + /* the same packets in the middle of a fragment being reassembled, then empty middle and end fragments completing it */ + status = decode_rtp_payload(&codec, &frame, fu_a_start, sizeof(fu_a_start), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_SUCCESS); + status = decode_rtp_payload(&codec, &frame, fu_a_indicator_only, sizeof(fu_a_indicator_only), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + status = decode_rtp_payload(&codec, &frame, fu_a_start, sizeof(fu_a_start), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_SUCCESS); + status = decode_rtp_payload(&codec, &frame, fu_a_middle_empty, sizeof(fu_a_middle_empty), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_SUCCESS); + status = decode_rtp_payload(&codec, &frame, fu_a_end_empty, sizeof(fu_a_end_empty), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(frame.img == NULL); + + /* an end fragment whose start fragment was lost is dropped */ + status = decode_rtp_payload(&codec, &frame, fu_a_end, sizeof(fu_a_end), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(switch_test_flag(&frame, SFF_WAIT_KEY_FRAME)); + fst_check(frame.img == NULL); + + /* an empty packet carrying the marker closes the picture: the fragment started before it is + * handed to the decoder, so a later end fragment has no start to attach to */ + status = decode_rtp_payload(&codec, &frame, fu_a_start, sizeof(fu_a_start), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_SUCCESS); + status = decode_rtp_payload(&codec, &frame, fu_a_indicator_only, 0, SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(frame.img == NULL); + status = decode_rtp_payload(&codec, &frame, fu_a_end, sizeof(fu_a_end), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(switch_test_flag(&frame, SFF_WAIT_KEY_FRAME)); + + /* a STAP-A with no room for a NALU size, and a single NALU of only a header, are accepted */ + status = decode_rtp_payload(&codec, &frame, stap_a_indicator_only, sizeof(stap_a_indicator_only), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_SUCCESS); + status = decode_rtp_payload(&codec, &frame, stap_a_half_size, sizeof(stap_a_half_size), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_SUCCESS); + status = decode_rtp_payload(&codec, &frame, single_nalu_header_only, sizeof(single_nalu_header_only), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(frame.img == NULL); + + switch_core_codec_destroy(&codec); + } + FST_TEST_END() + + /* Encode a few pictures, re-fragment every NAL unit into FU-A packets and make sure the + * depacketizer reassembles them into pictures */ + FST_TEST_BEGIN(decoder_fu_a_roundtrip_test) + { + switch_status_t status; + switch_codec_t codec = { 0 }; + switch_codec_settings_t codec_settings = {{ 0 }}; + switch_image_t *img; + uint8_t buf[SWITCH_DEFAULT_VIDEO_SIZE + 12]; + uint8_t fragment[FU_A_TEST_PAYLOAD + 2]; + switch_frame_t enc_frame = { 0 }; + switch_frame_t dec_frame = { 0 }; + int pictures; + int encoded = 0; + int split_fragments = 0; + int decoded = 0; + + switch_set_string(codec_settings.video.config_profile_name, "conference"); + + if (!fctcl_is("--disable-hw")) { + codec_settings.video.try_hardware_encoder = 1; + } + + status = switch_core_codec_init(&codec, + "H264", + NULL, + NULL, + 0, + 0, + 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + &codec_settings, fst_pool); + fst_check(status == SWITCH_STATUS_SUCCESS); + + img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, 320, 240, 1); + fst_check(img != NULL); + + enc_frame.packet = buf; + enc_frame.packetlen = sizeof(buf); + enc_frame.data = buf + 12; + enc_frame.payload = 96; + enc_frame.img = img; + + dec_frame.payload = 96; + dec_frame.timestamp = 3000; + + for (pictures = 0; pictures < 10; pictures++) { + switch_status_t encode_status; + + do { + uint8_t *nalu = buf + 12; + uint8_t nalu_type; + + enc_frame.datalen = SWITCH_DEFAULT_VIDEO_SIZE; + encode_status = switch_core_codec_encode_video(&codec, &enc_frame); + + if (encode_status != SWITCH_STATUS_SUCCESS && encode_status != SWITCH_STATUS_MORE_DATA) break; + if (enc_frame.datalen == 0) break; + if (enc_frame.m) encoded++; + + nalu_type = nalu[0] & 0x1f; + + if (nalu_type >= 1 && nalu_type <= 23 && enc_frame.datalen > FU_A_TEST_PAYLOAD) { + /* a single NAL unit packet: split it into FU-A fragments as RFC 6184 section 5.8 describes */ + uint32_t offset = 1; /* the NAL header travels in the FU indicator and FU header instead */ + + while (offset < enc_frame.datalen) { + uint32_t chunk = enc_frame.datalen - offset; + switch_bool_t last; + + if (chunk > FU_A_TEST_PAYLOAD) chunk = FU_A_TEST_PAYLOAD; + last = (offset + chunk == enc_frame.datalen) ? SWITCH_TRUE : SWITCH_FALSE; + + fragment[0] = (nalu[0] & 0xe0) | 28; + fragment[1] = (nalu[0] & 0x1f) | (offset == 1 ? 0x80 : 0) | (last ? 0x40 : 0); + memcpy(fragment + 2, nalu + offset, chunk); + offset += chunk; + + status = decode_rtp_payload(&codec, &dec_frame, fragment, chunk + 2, (last && enc_frame.m) ? SWITCH_TRUE : SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_MORE_DATA); + split_fragments++; + + if (dec_frame.img) { + fst_check(dec_frame.img->d_w == 320 && dec_frame.img->d_h == 240); + decoded++; + } + } + } else { + status = decode_rtp_payload(&codec, &dec_frame, nalu, enc_frame.datalen, enc_frame.m); + fst_check(status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_MORE_DATA); + + if (dec_frame.img) { + fst_check(dec_frame.img->d_w == 320 && dec_frame.img->d_h == 240); + decoded++; + } + } + } while (encode_status == SWITCH_STATUS_MORE_DATA); + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%d pictures encoded, %d FU-A fragments made by the test, %d pictures decoded\n", encoded, split_fragments, decoded); + fst_check(encoded > 0); + fst_check(split_fragments > 0); + fst_check(decoded > 0); + fst_check(decoded + 2 >= encoded); + + switch_core_codec_destroy(&codec); + switch_img_free(&img); + } + FST_TEST_END() + + /* H.263 payload headers are checked against the packet length before they are read. The decoder + * reports success for a packet its depacketizer rejected, so these only make sure nothing is + * read past a short packet and no picture comes out of it. */ + FST_TEST_BEGIN(decoder_h263_short_packet_test) + { + const char *names[] = { "H263", "H263-1998" }; + int c; + + for (c = 0; c < 2; c++) { + switch_status_t status; + switch_codec_t codec = { 0 }; + switch_codec_settings_t codec_settings = {{ 0 }}; + switch_frame_t frame = { 0 }; + /* each packet buffer is exactly the length it claims */ + uint8_t one[] = { 0x00 }; + uint8_t two[] = { 0x00, 0x00 }; + uint8_t three[] = { 0x00, 0x00, 0x00 }; + int i; + + switch_set_string(codec_settings.video.config_profile_name, "conference"); + + status = switch_core_codec_init(&codec, + names[c], + NULL, + NULL, + 0, + 0, + 1, SWITCH_CODEC_FLAG_DECODE, + &codec_settings, fst_pool); + fst_check(status == SWITCH_STATUS_SUCCESS); + + frame.payload = 96; + frame.timestamp = 3000; + + for (i = 0; i < 2; i++) { + switch_bool_t m = i ? SWITCH_TRUE : SWITCH_FALSE; + + status = decode_rtp_payload(&codec, &frame, one, 0, m); + fst_check(status == SWITCH_STATUS_SUCCESS); + status = decode_rtp_payload(&codec, &frame, one, sizeof(one), m); + fst_check(status == SWITCH_STATUS_SUCCESS); + status = decode_rtp_payload(&codec, &frame, two, sizeof(two), m); + fst_check(status == SWITCH_STATUS_SUCCESS); + status = decode_rtp_payload(&codec, &frame, three, sizeof(three), m); + fst_check(status == SWITCH_STATUS_SUCCESS); + fst_check(frame.img == NULL); + } + + switch_core_codec_destroy(&codec); + } + } + FST_TEST_END() + FST_TEARDOWN_BEGIN() { - const char *err = NULL; + /* the module stays loaded across the tests, FST_MODULE_END unloads it after the last one */ switch_sleep(1000000); - fst_check(switch_loadable_module_unload_module(SWITCH_GLOBAL_dirs.mod_dir, (char *)"mod_av", SWITCH_TRUE, &err) == SWITCH_STATUS_SUCCESS); } FST_TEARDOWN_END() } diff --git a/src/mod/codecs/mod_openh264/mod_openh264.cpp b/src/mod/codecs/mod_openh264/mod_openh264.cpp index be92f63b7f..8d9c225ac6 100644 --- a/src/mod/codecs/mod_openh264/mod_openh264.cpp +++ b/src/mod/codecs/mod_openh264/mod_openh264.cpp @@ -186,13 +186,18 @@ static switch_size_t buffer_h264_nalu(h264_codec_context_t *context, switch_fram uint8_t nalu_idc = 0; uint8_t nalu_type = 0; uint8_t *data = (uint8_t *)frame->data; - uint8_t nalu_hdr = *data; + uint8_t nalu_hdr; uint8_t sync_bytes[] = {0, 0, 0, 1}; switch_buffer_t *buffer = context->nalu_buffer; switch_size_t size = switch_buffer_inuse(buffer); switch_assert(frame); + if (!frame->datalen) { /* one byte NAL unit header */ + return 1; + } + + nalu_hdr = *data; nalu_idc = (nalu_hdr & 0x60) >> 5; nalu_type = nalu_hdr & 0x1f; @@ -219,8 +224,14 @@ static switch_size_t buffer_h264_nalu(h264_codec_context_t *context, switch_fram if ((nalu_type == 7 || nalu_type == 8) && frame->m) frame->m = SWITCH_FALSE; if (nalu_type == 28) { // 0x1c FU-A - int start = *(data + 1) & 0x80; - int end = *(data + 1) & 0x40; + int start, end; + + if (frame->datalen < 2) { /* FU indicator + FU header, the payload may be empty */ + return 1; + } + + start = *(data + 1) & 0x80; + end = *(data + 1) & 0x40; nalu_type = *(data + 1) & 0x1f; @@ -236,6 +247,11 @@ static switch_size_t buffer_h264_nalu(h264_codec_context_t *context, switch_fram switch_buffer_zero(buffer); } } else if (end) { + if (!context->nalu_28_start) { + /* the start fragment was lost, this tail is undecodable */ + return 1; + } + context->nalu_28_start = 0; } else if (!context->nalu_28_start) { return 0; @@ -612,6 +628,10 @@ static switch_status_t switch_h264_decode(switch_codec_t *codec, switch_frame_t uint32_t error_code; switch_status_t status = SWITCH_STATUS_SUCCESS; + if (!frame->data) { + return SWITCH_STATUS_FALSE; + } + #ifdef DEBUG_H264 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "len: %d seq: %u ts: %u mark:%d nalu:0x%x\n", frame->datalen, frame->seq, frame->timestamp, frame->m, *(uint8_t *)frame->data); #endif @@ -629,7 +649,8 @@ static switch_status_t switch_h264_decode(switch_codec_t *codec, switch_frame_t context->last_received_timestamp = frame->timestamp; context->last_received_complete_picture = frame->m ? SWITCH_TRUE : SWITCH_FALSE; - size = buffer_h264_nalu(context, frame); + /* an empty packet adds nothing, but its marker bit still closes the picture below */ + size = frame->datalen > 0 ? buffer_h264_nalu(context, frame) : switch_buffer_inuse(context->nalu_buffer); #ifdef DEBUG_H264 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "READ buf:%ld got_key:%d st:%d m:%d size:%" SWITCH_SIZE_T_FMT "\n", size, context->got_sps, status, frame->m, size); diff --git a/src/mod/codecs/mod_openh264/test/test_mod_openh264.cpp b/src/mod/codecs/mod_openh264/test/test_mod_openh264.cpp index 729f77be84..03aea99ed0 100644 --- a/src/mod/codecs/mod_openh264/test/test_mod_openh264.cpp +++ b/src/mod/codecs/mod_openh264/test/test_mod_openh264.cpp @@ -43,6 +43,26 @@ static fctcl_init_t my_cl_options[] = { FCTCL_INIT_NULL /* Sentinel */ }; +/* Feed one RTP payload to the decoder the way the media layer does: a fresh frame per packet, + * the marker on the last packet of a picture and the timestamp advancing per picture. */ +static switch_status_t decode_rtp_payload(switch_codec_t *codec, switch_frame_t *frame, void *data, uint32_t datalen, switch_bool_t m) +{ + switch_status_t status; + + frame->data = data; + frame->datalen = datalen; + frame->m = m; + frame->flags = 0; + frame->img = NULL; + frame->seq++; + + status = switch_core_codec_decode_video(codec, frame); + + if (m) frame->timestamp += 3000; + + return status; +} + FST_CORE_BEGIN("conf") { fctcl_install(my_cl_options); @@ -207,11 +227,113 @@ FST_CORE_BEGIN("conf") FST_TEST_END() + /* RTP payloads shorter than the headers their NAL type implies are rejected by the depacketizer, + * while FU-A fragments with an empty payload, which RFC 6184 allows, are accepted. Without a + * picture to return the decoder reports SWITCH_STATUS_MORE_DATA, so a dropped packet shows as + * the key frame request it raises. */ + FST_TEST_BEGIN(decoder_short_packet_test) + { + switch_status_t status; + switch_codec_t codec = { 0 }; + switch_codec_settings_t codec_settings = {{ 0 }}; + switch_frame_t frame = { 0 }; + /* each packet buffer is exactly the length it claims */ + uint8_t fu_a_indicator_only[] = { 0x7c }; + uint8_t fu_a_start_empty[] = { 0x7c, 0x85 }; + uint8_t fu_a_middle_empty[] = { 0x7c, 0x05 }; + uint8_t fu_a_end_empty[] = { 0x7c, 0x45 }; + uint8_t fu_a_start[] = { 0x7c, 0x85, 0x01, 0x02 }; + uint8_t fu_a_end[] = { 0x7c, 0x45, 0x03, 0x04 }; + uint8_t stap_a_indicator_only[] = { 0x78 }; + uint8_t stap_a_half_size[] = { 0x78, 0x00 }; + uint8_t single_nalu_header_only[] = { 0x65 }; + + switch_set_string(codec_settings.video.config_profile_name, "test-decoder-1"); + + status = switch_core_codec_init(&codec, + "H264", + NULL, + NULL, + 0, + 0, + 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + &codec_settings, fst_pool); + fst_check(status == SWITCH_STATUS_SUCCESS); + + frame.payload = 96; + frame.timestamp = 3000; + + /* an empty payload adds nothing */ + status = decode_rtp_payload(&codec, &frame, fu_a_indicator_only, 0, SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(frame.img == NULL); + + /* an FU-A without the FU header is dropped and a key frame requested */ + status = decode_rtp_payload(&codec, &frame, fu_a_indicator_only, sizeof(fu_a_indicator_only), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(switch_test_flag(&frame, SFF_WAIT_KEY_FRAME)); + fst_check(frame.img == NULL); + status = decode_rtp_payload(&codec, &frame, fu_a_indicator_only, sizeof(fu_a_indicator_only), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(switch_test_flag(&frame, SFF_WAIT_KEY_FRAME)); + fst_check(frame.img == NULL); + + /* an FU-A start fragment with an empty payload is accepted */ + status = decode_rtp_payload(&codec, &frame, fu_a_start_empty, sizeof(fu_a_start_empty), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(!switch_test_flag(&frame, SFF_WAIT_KEY_FRAME)); + fst_check(frame.img == NULL); + + /* a fragment without the FU header in the middle of a reassembly is dropped, then empty middle and end fragments complete one */ + status = decode_rtp_payload(&codec, &frame, fu_a_start, sizeof(fu_a_start), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + status = decode_rtp_payload(&codec, &frame, fu_a_indicator_only, sizeof(fu_a_indicator_only), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(switch_test_flag(&frame, SFF_WAIT_KEY_FRAME)); + status = decode_rtp_payload(&codec, &frame, fu_a_start, sizeof(fu_a_start), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(!switch_test_flag(&frame, SFF_WAIT_KEY_FRAME)); + status = decode_rtp_payload(&codec, &frame, fu_a_middle_empty, sizeof(fu_a_middle_empty), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(!switch_test_flag(&frame, SFF_WAIT_KEY_FRAME)); + status = decode_rtp_payload(&codec, &frame, fu_a_end_empty, sizeof(fu_a_end_empty), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(frame.img == NULL); + + /* an end fragment whose start fragment was lost is dropped */ + status = decode_rtp_payload(&codec, &frame, fu_a_end, sizeof(fu_a_end), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(switch_test_flag(&frame, SFF_WAIT_KEY_FRAME)); + fst_check(frame.img == NULL); + + /* an empty packet carrying the marker closes the picture: the fragment started before it is + * handed to the decoder, so a later end fragment has no start to attach to */ + status = decode_rtp_payload(&codec, &frame, fu_a_start, sizeof(fu_a_start), SWITCH_FALSE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + status = decode_rtp_payload(&codec, &frame, fu_a_indicator_only, 0, SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(frame.img == NULL); + status = decode_rtp_payload(&codec, &frame, fu_a_end, sizeof(fu_a_end), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(switch_test_flag(&frame, SFF_WAIT_KEY_FRAME)); + + /* a STAP-A with no room for a NALU size, and a single NALU of only a header, are accepted */ + status = decode_rtp_payload(&codec, &frame, stap_a_indicator_only, sizeof(stap_a_indicator_only), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + status = decode_rtp_payload(&codec, &frame, stap_a_half_size, sizeof(stap_a_half_size), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + status = decode_rtp_payload(&codec, &frame, single_nalu_header_only, sizeof(single_nalu_header_only), SWITCH_TRUE); + fst_check(status == SWITCH_STATUS_MORE_DATA); + fst_check(frame.img == NULL); + + switch_core_codec_destroy(&codec); + } + FST_TEST_END() + FST_TEARDOWN_BEGIN() { - const char *err = NULL; + /* the module stays loaded across the tests, FST_MODULE_END unloads it after the last one */ switch_sleep(1000000); - fst_check(switch_loadable_module_unload_module(SWITCH_GLOBAL_dirs.mod_dir, (char *)"mod_openh264", SWITCH_TRUE, &err) == SWITCH_STATUS_SUCCESS); } FST_TEARDOWN_END() } From 0b4ff451e3debc8efb0ba0c469dac3159370d047 Mon Sep 17 00:00:00 2001 From: Dmitry Verenitsin Date: Thu, 19 Nov 2026 01:35:18 +0500 Subject: [PATCH 88/88] [mod_sofia] Pass deflect targets with a URI scheme through unchanged (#3210) The deflect handler prefixed `sip:` and appended the profile address to any target not starting with `sip:`. `tel:`, `sips:` and other URIs went out as `sip:tel:...@`. A name-addr target, as a proxied `Refer-To` or `${sip_refer_to}` passes it, went out as `sip:@`, or was not sent at all when it carried a display name, URI params or `?Replaces=`. `sofia_deflect_build_refer_to()` now builds the `Refer-To`: - a target that has a URI scheme or contains `<` goes out as given - `user@host`, with or without a host port, only gains the `sip:` scheme - a bare user or number is addressed at the profile, as before - an empty or `NULL` target, which the `deflect` app passes when run without data, is rejected; the handler logs it and sends no REFER Adds `test_sofia_deflect_build_refer_to` to `test_sofia_funcs`: rejected targets, bare users with IPv4 and IPv6 profile addresses, `user@host` forms, URIs with a scheme, name-addr forms, the known limitations and truncation. --- src/mod/endpoints/mod_sofia/mod_sofia.c | 64 ++++++++++++++--- .../mod_sofia/test/test_sofia_funcs.c | 72 +++++++++++++++++++ 2 files changed, 128 insertions(+), 8 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 16d22fa14e..b15eb5c74b 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1355,6 +1355,53 @@ static switch_status_t sofia_send_dtmf(switch_core_session_t *session, const swi return SWITCH_STATUS_SUCCESS; } +/* True when the deflect target already carries a URI scheme or is a name-addr */ +static switch_bool_t sofia_deflect_target_is_uri(const char *target) +{ + const char *p = target; + + if (strchr(target, '<')) { + return SWITCH_TRUE; + } + + /* A scheme is a letter followed by letters, digits, '+', '-' or '.', terminated by ':' */ + if (!isalpha((unsigned char)*p)) { + return SWITCH_FALSE; + } + + for (p++; *p; p++) { + if (*p == ':') { + return SWITCH_TRUE; + } + + if (!isalnum((unsigned char)*p) && *p != '+' && *p != '-' && *p != '.') { + break; + } + } + + return SWITCH_FALSE; +} + +/* Builds the Refer-To for a deflect target; fails for an empty target */ +switch_status_t sofia_deflect_build_refer_to(const char *target, const char *sipip, char *buf, switch_size_t buflen) +{ + if (zstr(target)) { + return SWITCH_STATUS_FALSE; + } + + if (sofia_deflect_target_is_uri(target)) { + switch_copy_string(buf, target, buflen); + } else if (strchr(target, '@')) { + switch_snprintf(buf, buflen, "sip:%s", target); + } else { + const char *format = strchr(sipip, ':') ? "sip:%s@[%s]" : "sip:%s@%s"; + + switch_snprintf(buf, buflen, format, target, sipip); + } + + return SWITCH_STATUS_SUCCESS; +} + static switch_status_t sofia_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) { switch_channel_t *channel = switch_core_session_get_channel(session); @@ -1566,19 +1613,20 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi case SWITCH_MESSAGE_INDICATE_DEFLECT: { - char *extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_HEADER_PREFIX); + char *extra_headers; char ref_to[1024] = ""; const char *var; - const char *session_id_header = sofia_glue_session_id_header(session, tech_pvt->profile); + const char *session_id_header; - if (strncasecmp(msg->string_arg, "sip:", 4)) { - const char *format = strchr(tech_pvt->profile->sipip, ':') ? "sip:%s@[%s]" : "sip:%s@%s"; - - switch_snprintf(ref_to, sizeof(ref_to), format, msg->string_arg, tech_pvt->profile->sipip); - } else { - switch_set_string(ref_to, msg->string_arg); + if (sofia_deflect_build_refer_to(msg->string_arg, tech_pvt->profile->sipip, ref_to, sizeof(ref_to)) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Deflect requires a target\n"); + msg->string_reply = "no target"; + break; } + extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_HEADER_PREFIX); + session_id_header = sofia_glue_session_id_header(session, tech_pvt->profile); + nua_refer(tech_pvt->nh, SIPTAG_REFER_TO_STR(ref_to), SIPTAG_REFERRED_BY_STR(tech_pvt->contact_url), TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_IF(!zstr(session_id_header), SIPTAG_HEADER_STR(session_id_header)), diff --git a/src/mod/endpoints/mod_sofia/test/test_sofia_funcs.c b/src/mod/endpoints/mod_sofia/test/test_sofia_funcs.c index 1806a8b7eb..d5696cceed 100644 --- a/src/mod/endpoints/mod_sofia/test/test_sofia_funcs.c +++ b/src/mod/endpoints/mod_sofia/test/test_sofia_funcs.c @@ -33,6 +33,7 @@ #include int protect_dest_uri(switch_caller_profile_t *cp); +switch_status_t sofia_deflect_build_refer_to(const char *target, const char *sipip, char *buf, switch_size_t buflen); static int timeout_sec = 10; static switch_interval_time_t delay_start_ms = 5000; @@ -122,6 +123,77 @@ FST_TEST_BEGIN(originate_test) } FST_TEST_END() +FST_TEST_BEGIN(test_sofia_deflect_build_refer_to) +{ + char ref_to[1024]; + char short_buf[12]; + size_t i; + const char *sipip = "203.0.113.5"; + /* expect NULL means the target is rejected */ + struct { + const char *target; + const char *expect; + } cases[] = { + { NULL, NULL }, + { "", NULL }, + /* a bare user or number is addressed at the profile */ + { "1234", switch_core_sprintf(fst_pool, "sip:1234@%s", sipip) }, + { "+15551234567", switch_core_sprintf(fst_pool, "sip:+15551234567@%s", sipip) }, + /* user@host only gains the scheme, including a host port or an IPv6 literal */ + { "bob@example.com", "sip:bob@example.com" }, + { "bob@198.51.100.7:2222", "sip:bob@198.51.100.7:2222" }, + { "bob@[2001:db8::7]", "sip:bob@[2001:db8::7]" }, + /* a URI with a scheme goes out as given */ + { "sip:bob@example.com", "sip:bob@example.com" }, + { "sips:bob@example.com", "sips:bob@example.com" }, + { "SIPS:bob@example.com", "SIPS:bob@example.com" }, + { "sip:bob@198.51.100.7:2222", "sip:bob@198.51.100.7:2222" }, + { "tel:+15551234567", "tel:+15551234567" }, + { "urn:service:sos", "urn:service:sos" }, + /* a name-addr goes out as given */ + { "", "" }, + { "", "" }, + { "\"Bob\" ", "\"Bob\" " }, + { "", "" }, + { ";x-leg=b", ";x-leg=b" }, + /* Known limitations: a host:port without a user, or a user:password, reads as a scheme or is + * addressed at the profile, and none of these is a valid Refer-To */ + { "pbx.example.com:5060", "pbx.example.com:5060" }, + { "198.51.100.7:5060", switch_core_sprintf(fst_pool, "sip:198.51.100.7:5060@%s", sipip) }, + { "bob:secret@example.com", "bob:secret@example.com" }, + }; + + for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + switch_status_t status; + + ref_to[0] = '\0'; + status = sofia_deflect_build_refer_to(cases[i].target, sipip, ref_to, sizeof(ref_to)); + + if (!cases[i].expect) { + fst_xcheck(status == SWITCH_STATUS_FALSE, "an empty deflect target must be rejected"); + continue; + } + + fst_xcheck(status == SWITCH_STATUS_SUCCESS, cases[i].target); + fst_check_string_equals(ref_to, cases[i].expect); + } + + /* An IPv6 profile address is bracketed */ + sofia_deflect_build_refer_to("1234", "2001:db8:cafe::5", ref_to, sizeof(ref_to)); + fst_check_string_equals(ref_to, "sip:1234@[2001:db8:cafe::5]"); + + /* The result is truncated to buflen on every branch */ + sofia_deflect_build_refer_to("1234567", sipip, short_buf, sizeof(short_buf)); + fst_check_string_equals(short_buf, "sip:1234567"); + + sofia_deflect_build_refer_to("bob@example.com", sipip, short_buf, sizeof(short_buf)); + fst_check_string_equals(short_buf, "sip:bob@exa"); + + sofia_deflect_build_refer_to("sip:bob@example.com", sipip, short_buf, sizeof(short_buf)); + fst_check_string_equals(short_buf, "sip:bob@exa"); +} +FST_TEST_END() + #if HAVE_STIRSHAKEN FST_TEST_BEGIN(sofia_verify_identity_test_no_identity) {